Skip to content

Commit f33af0e

Browse files
authored
feat: adding optional credentials parameter so passkey signing can skip passkey dialog (#183)
* feat(chore): adding optional credentials parameter so passkey signing can skip passkey dialog
1 parent 9640832 commit f33af0e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/sdk/src/client/passkey/actions/passkey.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { startAuthentication, startRegistration } from "@simplewebauthn/browser";
1+
import { type PublicKeyCredentialDescriptorJSON, startAuthentication, startRegistration } from "@simplewebauthn/browser";
22
import type { AuthenticationResponseJSON, GenerateAuthenticationOptionsOpts, GenerateRegistrationOptionsOpts, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON, RegistrationResponseJSON, VerifiedRegistrationResponse } from "@simplewebauthn/server";
33
import { generateAuthenticationOptions, generateRegistrationOptions, verifyAuthenticationResponse, verifyRegistrationResponse } from "@simplewebauthn/server";
44
import type { Account, Address, Chain, Client, Hash, Hex, TransactionReceipt, Transport } from "viem";
@@ -115,6 +115,7 @@ export const registerNewPasskey = async (args: RegisterNewPasskeyArgs): Promise<
115115
export type RequestPasskeyAuthenticationArgs = {
116116
challenge: Hash; // Transaction hash to sign
117117
credentialPublicKey: Uint8Array;
118+
credential?: PublicKeyCredentialDescriptorJSON;
118119
rpID?: string;
119120
origin?: string;
120121
};
@@ -127,7 +128,11 @@ export const requestPasskeyAuthentication = async (args: RequestPasskeyAuthentic
127128
challenge: toBytes(args.challenge),
128129
});
129130
const optionsJSON: PublicKeyCredentialRequestOptionsJSON = { ...passkeyAuthenticationOptions };
130-
const authenticationResponse: AuthenticationResponseJSON = await startAuthentication({ optionsJSON: optionsJSON });
131+
const authenticationResponse: AuthenticationResponseJSON = await startAuthentication({
132+
optionsJSON: args.credential
133+
? { ...optionsJSON, allowCredentials: [args.credential] }
134+
: { ...optionsJSON },
135+
});
131136

132137
let { rpID, origin } = identifyPasskeyParams();
133138
rpID = args.rpID || passkeyAuthenticationOptions.rpId || rpID;

packages/sdk/src/client/passkey/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type PublicKeyCredentialDescriptorJSON } from "@simplewebauthn/browser";
12
import { type Account, type Address, type Chain, type Client, createClient, getAddress, type Prettify, type PublicActions, publicActions, type PublicRpcSchema, type RpcSchema, type Transport, type WalletActions, walletActions, type WalletClientConfig, type WalletRpcSchema } from "viem";
23
import { erc7739Actions } from "viem/experimental";
34
import { eip712WalletActions } from "viem/zksync";
@@ -34,6 +35,7 @@ export function createZksyncPasskeyClient<
3435
const passkeySignature = await requestPasskeyAuthentication({
3536
challenge: hash,
3637
credentialPublicKey: parameters.credentialPublicKey,
38+
credential: parameters.credential,
3739
});
3840

3941
return passkeyHashSignatureResponseFormat(
@@ -114,6 +116,7 @@ export interface ZksyncSsoPasskeyClientConfig<
114116
userName: string;
115117
userDisplayName: string;
116118
contracts: PasskeyRequiredContracts;
119+
credential?: PublicKeyCredentialDescriptorJSON;
117120
key?: string;
118121
name?: string;
119122
}

0 commit comments

Comments
 (0)