-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
12,573 additions
and
3,701 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "ic-use-siwe-identity", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "React hook and context provider for easy frontend integration with SIWE enabled Internet Computer canisters.", | ||
"author": "Kristofer Lund <[email protected]>", | ||
"repository": { | ||
|
@@ -33,11 +33,12 @@ | |
}, | ||
"peerDependencies": { | ||
"react": ">=18.0.0", | ||
"viem": ">=1.19.8", | ||
"wagmi": ">=1.4.7", | ||
"viem": ">=2.8.4", | ||
"wagmi": ">=2.5.7", | ||
"@dfinity/agent": ">=1.0.1", | ||
"@dfinity/candid": ">=1.0.1", | ||
"@dfinity/identity": ">=1.0.1" | ||
"@dfinity/identity": ">=1.0.1", | ||
"@tanstack/react-query": ">=5.28.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.10.6", | ||
|
@@ -52,7 +53,8 @@ | |
"npm-run-all": "^4.1.5", | ||
"react": "^18.2.0", | ||
"typescript": "^5.2.2", | ||
"viem": "^1.19.8", | ||
"wagmi": "^1.4.7" | ||
"viem": "^2.8.4", | ||
"wagmi": "^2.5.7", | ||
"@tanstack/react-query": "^5.28.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { DerEncodedPublicKey, Signature } from "@dfinity/agent"; | ||
import type { PublicKey } from "./service.interface"; | ||
import { Principal } from "@dfinity/principal"; | ||
import { Delegation } from "@dfinity/identity"; | ||
import { DelegationChain, type SignedDelegation } from "@dfinity/identity"; | ||
import type { SignedDelegation as ServiceSignedDelegation } from "./service.interface"; | ||
|
||
/** | ||
* Converts a Uint8Array or number array to a Signature object. | ||
*/ | ||
export function asSignature(signature: Uint8Array | number[]): Signature { | ||
const arrayBuffer: ArrayBuffer = (signature as Uint8Array).buffer; | ||
const s: Signature = arrayBuffer as Signature; | ||
s.__signature__ = undefined; | ||
return s; | ||
} | ||
|
||
/** | ||
* Converts a Uint8Array or number array to a DerEncodedPublicKey object. | ||
*/ | ||
export function asDerEncodedPublicKey( | ||
publicKey: Uint8Array | number[] | ||
): DerEncodedPublicKey { | ||
const arrayBuffer: ArrayBuffer = (publicKey as Uint8Array).buffer; | ||
const pk: DerEncodedPublicKey = arrayBuffer as DerEncodedPublicKey; | ||
pk.__derEncodedPublicKey__ = undefined; | ||
return pk; | ||
} | ||
|
||
export function createDelegationChain( | ||
signedDelegation: ServiceSignedDelegation, | ||
publicKey: PublicKey | ||
) { | ||
const delegations: SignedDelegation[] = [ | ||
{ | ||
delegation: new Delegation( | ||
(signedDelegation.delegation.pubkey as Uint8Array).buffer, | ||
signedDelegation.delegation.expiration, | ||
signedDelegation.delegation.targets[0] as Principal[] | ||
), | ||
signature: asSignature(signedDelegation.signature), | ||
}, | ||
]; | ||
return DelegationChain.fromDelegations( | ||
delegations, | ||
asDerEncodedPublicKey(publicKey) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function normalizeError(error: Error | unknown): Error { | ||
return error instanceof Error | ||
? error | ||
: new Error("An unknown error occurred."); | ||
} |
Oops, something went wrong.