From 994c31814c1a251ce9f62148b790b98fa636b44c Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 25 Jul 2024 17:47:02 +0800 Subject: [PATCH] [passkey] add more doc strings --- src/api/passkey.ts | 55 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/src/api/passkey.ts b/src/api/passkey.ts index fe7c5dbbd..07a04e618 100644 --- a/src/api/passkey.ts +++ b/src/api/passkey.ts @@ -28,19 +28,22 @@ export class Passkey { } /** - * Given a credentialId and a transaction, it prompts the client to sign the transaction + * Given a credentialId and a transaction, it prompts the client to sign the transaction then submits it. * * @param args.credentialId The credential ID of the passkey * @param args.publicKey The public key associated with the passkey * @param args.transaction The transaction to sign + * @param args.rpID The relying party ID + * @param args.timeout The timeout for the operation + * @param args.options The options for the operation * @returns The pending transaction response */ async signAndSubmitWithPasskey(args: { credentialId: string | Uint8Array; publicKey: PublicKey; transaction: AnyRawTransaction; - timeout?: number; rpID: string; + timeout?: number; options?: { allowCredentials?: AllowCredentialOption[]; }; @@ -48,12 +51,24 @@ export class Passkey { return signAndSubmitWithPasskey({ aptosConfig: this.config, ...args }); } + /** + * Given a credentialId and a transaction, it prompts the client to sign the transaction. + * + * @param args.credentialId The credential ID of the passkey + * @param args.publicKey The public key associated with the passkey + * @param args.transaction The transaction to sign + * @param args.rpID The relying party ID + * @param args.timeout The timeout for the operation + * @param args.options The options for the operation + * @returns The account authenticator + */ + async signWithPasskey(args: { credentialId: string | Uint8Array; publicKey: PublicKey; transaction: AnyRawTransaction; - timeout?: number; rpID: string; + timeout?: number; options?: { allowCredentials?: AllowCredentialOption[]; }; @@ -61,15 +76,35 @@ export class Passkey { return signWithPasskey({ ...args }); } + /** + * Given a public key, it returns the account address associated with the passkey. + * @param args.publicKey The public key associated with the passkey + * @returns The account address + */ + async getPasskeyAccountAddress(args: { publicKey: HexInput }): Promise { return getPasskeyAccountAddress(args); } + /** + * Generates registration options for a passkey. + * @param args.rpName The relying party name + * @param args.rpID The relying party ID + * @param args.userName The user name + * @param args.userID The user ID + * @param args.challenge The challenge + * @param args.userDisplayName The user display name + * @param args.timeout The timeout for the operation + * @param args.attestationType The attestation type + * @param args.authenticatorAttachment The authenticator attachment + * @returns The registration options + */ + async generateRegistrationOptions(args: { rpName: string; rpID: string; - userID?: Uint8Array; userName: string; + userID?: Uint8Array; challenge?: string | Uint8Array; userDisplayName?: string; timeout?: number; @@ -79,12 +114,24 @@ export class Passkey { return generateRegistrationOptions(args); } + /** + * Registers a credential for a passkey. + * @param creationOptionsJSON + * @returns The registration response + */ + async registerCredential( creationOptionsJSON: PublicKeyCredentialCreationOptionsJSON, ): Promise { return registerCredential(creationOptionsJSON); } + /** + * Parses the public key from a registration response. + * @param response The registration response + * @returns The public key + */ + parsePublicKey(response: RegistrationResponseJSON): PublicKey { return parsePublicKey(response); }