Skip to content

Commit bcf526f

Browse files
committed
refactor(WebAuthnProvider): simplify PKP minting process by utilising verifyAndMintPKPThroughRelayerAndReturnAuthMethod
1 parent 553cc0b commit bcf526f

File tree

1 file changed

+5
-46
lines changed

1 file changed

+5
-46
lines changed

packages/lit-auth-client/src/lib/providers/WebAuthnProvider.ts

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -56,52 +56,11 @@ export default class WebAuthnProvider extends BaseProvider {
5656
options: PublicKeyCredentialCreationOptionsJSON,
5757
customArgs?: MintRequestBody
5858
): Promise<string> {
59-
// Submit registration options to the authenticator
60-
const { startRegistration } = await import('@simplewebauthn/browser');
61-
const attResp: RegistrationResponseJSON = await startRegistration(options);
62-
63-
// Get auth method id
64-
const authMethodId = await this.getAuthMethodId({
65-
authMethodType: AUTH_METHOD_TYPE.WebAuthn,
66-
accessToken: JSON.stringify(attResp),
67-
});
68-
69-
// Get auth method pub key
70-
const authMethodPubkey =
71-
WebAuthnProvider.getPublicKeyFromRegistration(attResp);
72-
73-
// Format args for relay server
74-
const defaultArgs = {
75-
keyType: 2,
76-
permittedAuthMethodTypes: [AUTH_METHOD_TYPE.WebAuthn],
77-
permittedAuthMethodIds: [authMethodId],
78-
permittedAuthMethodPubkeys: [authMethodPubkey],
79-
permittedAuthMethodScopes: [[ethers.BigNumber.from('1')]],
80-
addPkpEthAddressAsPermittedAddress: true,
81-
sendPkpToItself: true,
82-
};
83-
84-
const args = {
85-
...defaultArgs,
86-
...customArgs,
87-
};
88-
89-
const body = JSON.stringify(args);
90-
91-
// Mint PKP
92-
const mintRes = await this.relay.mintPKP(body);
93-
if (!mintRes || !mintRes.requestId) {
94-
throw new UnknownError(
95-
{
96-
info: {
97-
mintRes,
98-
},
99-
},
100-
'Missing mint response or request ID from relay server'
101-
);
102-
}
103-
104-
return mintRes.requestId;
59+
const result = await this.verifyAndMintPKPThroughRelayerAndReturnAuthMethod(
60+
options,
61+
customArgs
62+
);
63+
return result.requestId;
10564
}
10665

10766
/**

0 commit comments

Comments
 (0)