-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authenticate via the Identity canister (#5471)
- Loading branch information
Showing
8 changed files
with
199 additions
and
115 deletions.
There are no files selected for viewing
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
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,27 @@ | ||
import { type Delegation, DelegationChain, DelegationIdentity } from "@dfinity/identity"; | ||
import { type DerEncodedPublicKey, type Signature, SignIdentity } from "@dfinity/agent"; | ||
|
||
export function buildDelegationIdentity( | ||
userKey: Uint8Array, | ||
sessionKey: SignIdentity, | ||
delegation: Delegation, | ||
signature: Signature, | ||
): DelegationIdentity { | ||
const delegations = [ | ||
{ | ||
delegation, | ||
signature, | ||
}, | ||
]; | ||
|
||
const delegationChain = DelegationChain.fromDelegations( | ||
delegations, | ||
userKey.buffer as DerEncodedPublicKey, | ||
); | ||
|
||
return DelegationIdentity.fromDelegation(sessionKey, delegationChain); | ||
} | ||
|
||
export function toDer(key: SignIdentity): Uint8Array { | ||
return new Uint8Array(key.getPublicKey().toDer() as ArrayBuffer); | ||
} |
Oops, something went wrong.