Skip to content

Commit

Permalink
sdk: add passkey signer (#20443)
Browse files Browse the repository at this point in the history
## Description 

corresponding sui change:
https://github.com/MystenLabs/sui/blob/main/crates/sui-types/src/passkey_authenticator.rs

spec follows: 

https://github.com/sui-foundation/sips/blob/main/sips/sip-9.md#signature-encoding

https://github.com/sui-foundation/sips/blob/main/sips/sip-9.md#signature-verification

## Test plan 

unit tests
---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:

---------

Co-authored-by: hayes-mysten <135670682+hayes-mysten@users.noreply.github.com>
  • Loading branch information
joyqvq and hayes-mysten authored Dec 10, 2024
1 parent 3262677 commit 20af12d
Show file tree
Hide file tree
Showing 14 changed files with 789 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-kings-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui': minor
---

add passkey sdk
49 changes: 17 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ packages:
- '!sdk/signers/aws'
- '!sdk/signers/gcp'
- '!sdk/typescript/zklogin'
- '!sdk/typescript/keypairs/passkey'
6 changes: 6 additions & 0 deletions sdk/typescript/keypairs/passkey/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"import": "../../dist/esm/keypairs/passkey/index.js",
"main": "../../dist/cjs/keypairs/passkey/index.js",
"sideEffects": false
}
5 changes: 5 additions & 0 deletions sdk/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"import": "./dist/esm/keypairs/secp256r1/index.js",
"require": "./dist/cjs/keypairs/secp256r1/index.js"
},
"./keypairs/passkey": {
"import": "./dist/esm/keypairs/passkey/index.js",
"require": "./dist/cjs/keypairs/passkey/index.js"
},
"./multisig": {
"import": "./dist/esm/multisig/index.js",
"require": "./dist/cjs/multisig/index.js"
Expand Down Expand Up @@ -151,6 +155,7 @@
"@noble/hashes": "^1.4.0",
"@scure/bip32": "^1.4.0",
"@scure/bip39": "^1.3.0",
"@simplewebauthn/typescript-types": "^7.4.0",
"@suchipi/femver": "^1.0.0",
"bech32": "^2.0.0",
"gql.tada": "^1.8.2",
Expand Down
6 changes: 6 additions & 0 deletions sdk/typescript/src/bcs/bcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,9 @@ export const SenderSignedTransaction = bcs.struct('SenderSignedTransaction', {
export const SenderSignedData = bcs.vector(SenderSignedTransaction, {
name: 'SenderSignedData',
});

export const PasskeyAuthenticator = bcs.struct('PasskeyAuthenticator', {
authenticatorData: bcs.vector(bcs.u8()),
clientDataJson: bcs.string(),
userSignature: bcs.vector(bcs.u8()),
});
2 changes: 2 additions & 0 deletions sdk/typescript/src/bcs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
MultiSigPublicKey,
ObjectArg,
ObjectDigest,
PasskeyAuthenticator,
ProgrammableMoveCall,
ProgrammableTransaction,
PublicKey,
Expand Down Expand Up @@ -82,6 +83,7 @@ const suiBcs = {
TransactionKind,
TypeTag,
TransactionEffects,
PasskeyAuthenticator,
};

export { suiBcs as bcs };
10 changes: 9 additions & 1 deletion sdk/typescript/src/cryptography/signature-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const SIGNATURE_SCHEME_TO_FLAG = {
Secp256r1: 0x02,
MultiSig: 0x03,
ZkLogin: 0x05,
Passkey: 0x06,
} as const;

export const SIGNATURE_SCHEME_TO_SIZE = {
Expand All @@ -21,8 +22,15 @@ export const SIGNATURE_FLAG_TO_SCHEME = {
0x02: 'Secp256r1',
0x03: 'MultiSig',
0x05: 'ZkLogin',
0x06: 'Passkey',
} as const;

export type SignatureScheme = 'ED25519' | 'Secp256k1' | 'Secp256r1' | 'MultiSig' | 'ZkLogin';
export type SignatureScheme =
| 'ED25519'
| 'Secp256k1'
| 'Secp256r1'
| 'MultiSig'
| 'ZkLogin'
| 'Passkey';

export type SignatureFlag = keyof typeof SIGNATURE_FLAG_TO_SCHEME;
3 changes: 3 additions & 0 deletions sdk/typescript/src/cryptography/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { fromBase64, toBase64 } from '@mysten/bcs';

import { bcs } from '../bcs/index.js';
import { parseSerializedPasskeySignature } from '../keypairs/passkey/publickey.js';
import type { MultiSigStruct } from '../multisig/publickey.js';
import { parseSerializedZkLoginSignature } from '../zklogin/publickey.js';
import type { PublicKey } from './publickey.js';
Expand Down Expand Up @@ -55,6 +56,8 @@ export function parseSerializedSignature(serializedSignature: string) {
SIGNATURE_FLAG_TO_SCHEME[bytes[0] as keyof typeof SIGNATURE_FLAG_TO_SCHEME];

switch (signatureScheme) {
case 'Passkey':
return parseSerializedPasskeySignature(serializedSignature);
case 'MultiSig':
const multisig: MultiSigStruct = bcs.MultiSig.parse(bytes.slice(1));
return {
Expand Down
5 changes: 5 additions & 0 deletions sdk/typescript/src/keypairs/passkey/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
export { PasskeyKeypair, BrowserPasskeyProvider } from './keypair.js';
export type { PasskeyProvider, BrowserPasswordProviderOptions } from './keypair.js';
export { PasskeyPublicKey } from './publickey.js';
Loading

0 comments on commit 20af12d

Please sign in to comment.