Skip to content

Commit 825c2e4

Browse files
committed
fix(webauthn): to include scopes in the API
1 parent 9b94223 commit 825c2e4

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

packages/auth-services/src/auth-server/src/schemas/AuthServiceMintRequestSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type AuthServiceMintRequestTransformed = z.infer<
2828
export const tAuthServiceMintRequestSchema = t.Object({
2929
authMethodType: t.String(),
3030
authMethodId: t.String(),
31+
pubkey: t.Optional(t.String()),
3132
pubkey: t.Optional(t.String({ default: '0x' })),
3233
scopes: t.Optional(
3334
t.Array(

packages/auth-services/src/queue-manager/src/handlers/pkpMint/pkpMint.handler.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ export async function handlePkpMintTask(jobData: {
1414
pubkey: Hex;
1515
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
1616
};
17+
reqId?: string;
1718
}): Promise<any> {
19+
if (
20+
// AUTH_METHOD_TYPE.WebAuthn = 3 (without importing the constants package)
21+
Number(jobData.requestBody.authMethodType) === 3 &&
22+
(!jobData.requestBody.pubkey || jobData.requestBody.pubkey === '0x')
23+
) {
24+
throw new Error(
25+
`[PKP Mint][HANDLER] WebAuthn requires a non-empty COSE pubkey; got '${jobData.requestBody.pubkey}'. reqId=${jobData.reqId}`
26+
);
27+
}
28+
1829
const userAuthData: Optional<AuthData, 'accessToken'> = {
1930
authMethodId: jobData.requestBody.authMethodId,
2031
authMethodType: Number(jobData.requestBody.authMethodType),

packages/auth/src/lib/authenticators/native/WebAuthnAuthenticator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class WebAuthnAuthenticator {
149149
public static async registerAndMintPKP(params: {
150150
username?: string;
151151
authServiceBaseUrl: string;
152+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
152153
}): Promise<{
153154
pkpInfo: PKPData;
154155

@@ -183,6 +184,7 @@ export class WebAuthnAuthenticator {
183184
authMethodType: AUTH_METHOD_TYPE.WebAuthn,
184185
authMethodId: authMethodId,
185186
pubkey: authMethodPubkey,
187+
scopes: params.scopes,
186188
};
187189

188190
// Immediate mint a new PKP to associate with the auth method

packages/lit-client/src/lib/LitClient/createLitClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ export const _createNagaLitClient = async (
350350
return await networkModule.api.signCustomSessionKey.handleResponse(
351351
result as any,
352352
params.requestBody.pkpPublicKey,
353-
jitContext
353+
jitContext,
354+
requestId
354355
);
355356
}
356357

packages/networks/src/networks/vNaga/shared/factories/BaseModuleFactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,8 @@ export function createBaseModule<T, M>(config: BaseModuleConfig<T, M>) {
898898
handleResponse: async (
899899
result: z.infer<typeof GenericEncryptedPayloadSchema>,
900900
pkpPublicKey: Hex | string,
901-
jitContext: NagaJitContext
901+
jitContext: NagaJitContext,
902+
requestId?: string
902903
) => {
903904
if (!result.success) {
904905
E2EERequestManager.handleEncryptedError(

packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/MintPKPSchema.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ export const MintPKPSchema = z
1717

1818
// Determine pubkey based on the (potentially derived) authMethodType
1919
if (data.authMethodType === AUTH_METHOD_TYPE.WebAuthn) {
20-
if (!data.pubkey) {
21-
throw new Error('pubkey is required for WebAuthn');
20+
if (!data.pubkey || data.pubkey === '0x') {
21+
throw new Error(
22+
`pubkey is required for WebAuthn and cannot be 0x. Received pubkey: "${data.pubkey}" and authMethodType: ${data.authMethodType}`
23+
);
2224
}
2325
derivedPubkey = data.pubkey as Hex;
2426
} else {

0 commit comments

Comments
 (0)