Skip to content

Commit 29a39cb

Browse files
authored
Merge pull request #882 from LIT-Protocol/feature/jss-86-bugnaga-fix-webauthn-cbor-issue-due-to-missing-pub-key
[Bug] fix(webauthn): to include scopes in the API
2 parents 422000c + 7741913 commit 29a39cb

File tree

21 files changed

+91
-127
lines changed

21 files changed

+91
-127
lines changed

packages/auth-services/src/auth-server/src/routes/pkp/mint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { ElysiaInstance } from '../../types/ElysiaInstance.type';
22
import { addJob } from '../../../../queue-manager/src/bullmqSetup';
33
import { resp } from '../../response-helpers/response-helpers';
44
import { mintPkpDoc } from '../../../../queue-manager/src/handlers/pkpMint/pkpMint.doc';
5-
import { AuthServiceMintRequestRaw } from '../../schemas/AuthServiceMintRequestSchema';
5+
import { MintPKPRequest } from '@lit-protocol/schemas';
66

77
export const mint = (app: ElysiaInstance) => {
88
app.post(
99
'/mint',
10-
async ({ body }: { body: AuthServiceMintRequestRaw }) => {
10+
async ({ body }: { body: MintPKPRequest }) => {
1111
try {
1212
const job = await addJob('pkpMint', { requestBody: body });
1313
return resp.QUEUED(job.id, 'PKP minting request queued successfully.');

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
import { AuthData } from '@lit-protocol/schemas';
1+
import {
2+
AuthData,
3+
MintPKPRequest,
4+
MintPKPRequestSchema,
5+
} from '@lit-protocol/schemas';
26
import { Optional } from '@lit-protocol/types';
3-
import { Hex } from 'viem';
47

58
/**
69
* Handles PKP minting tasks.
710
* @param jobData The data for the job, expected to contain `requestBody`.
811
* @returns The result of the PKP minting process.
912
*/
1013
export async function handlePkpMintTask(jobData: {
11-
requestBody: {
12-
authMethodType: string;
13-
authMethodId: Hex;
14-
pubkey: Hex;
15-
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
16-
};
14+
requestBody: MintPKPRequest;
15+
reqId?: string;
1716
}): Promise<any> {
18-
const userAuthData: Optional<AuthData, 'accessToken'> = {
19-
authMethodId: jobData.requestBody.authMethodId,
20-
authMethodType: Number(jobData.requestBody.authMethodType),
21-
publicKey: jobData.requestBody.pubkey,
22-
};
2317

2418
const result = await globalThis.systemContext.litClient.mintWithAuth({
2519
account: globalThis.systemContext.account,
26-
authData: userAuthData,
27-
scopes: jobData.requestBody.scopes || [],
20+
authData: {
21+
authMethodId: jobData.requestBody.authMethodId,
22+
authMethodType: jobData.requestBody.authMethodType,
23+
publicKey: jobData.requestBody.pubkey,
24+
},
25+
scopes: jobData.requestBody.scopes,
2826
});
2927

3028
console.log(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import {
1414
} from '@lit-protocol/constants';
1515
import { AuthMethod, AuthServerTx, Hex } from '@lit-protocol/types';
1616

17-
import { AuthData, PKPData } from '@lit-protocol/schemas';
17+
import { AuthData, PKPData, ScopeStringSchema } from '@lit-protocol/schemas';
1818
import { getRPIdFromOrigin, parseAuthenticatorData } from '../helper/utils';
1919

2020
import { EthBlockhashInfo } from '@lit-protocol/types';
2121
import { pollResponse } from '../helper/pollResponse';
2222
import { JobStatusResponse } from '../types';
23+
import { z } from 'zod';
2324

2425
const fetchBlockchainData = async () => {
2526
try {
@@ -149,6 +150,7 @@ export class WebAuthnAuthenticator {
149150
public static async registerAndMintPKP(params: {
150151
username?: string;
151152
authServiceBaseUrl: string;
153+
scopes?: z.infer<typeof ScopeStringSchema>[];
152154
}): Promise<{
153155
pkpInfo: PKPData;
154156

@@ -183,6 +185,7 @@ export class WebAuthnAuthenticator {
183185
authMethodType: AUTH_METHOD_TYPE.WebAuthn,
184186
authMethodId: authMethodId,
185187
pubkey: authMethodPubkey,
188+
scopes: params.scopes,
186189
};
187190

188191
// 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
@@ -358,7 +358,8 @@ export const _createNagaLitClient = async (
358358
return await networkModule.api.signCustomSessionKey.handleResponse(
359359
result as any,
360360
params.requestBody.pkpPublicKey,
361-
jitContext
361+
jitContext,
362+
requestId
362363
);
363364
}
364365

packages/lit-client/src/lib/LitClient/schemas/MintWithCustomAuthSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthData } from '@lit-protocol/schemas';
1+
import { AuthData, CustomAuthDataSchema } from '@lit-protocol/schemas';
22
import { Optional } from '@lit-protocol/types';
33
import { z } from 'zod';
44

@@ -9,7 +9,7 @@ const BaseMintWithCustomAuthSchema = z.object({
99
// Account information - this will be passed from the calling context
1010
account: z.any(), // Account type varies by network
1111
// Authentication data for the user
12-
authData: z.custom<Optional<AuthData, 'accessToken'>>(),
12+
authData: CustomAuthDataSchema,
1313
scope: z.enum(['no-permissions', 'sign-anything', 'personal-sign']),
1414
// Optional overrides
1515
addPkpEthAddressAsPermittedAddress: z.boolean().default(false),

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CustomAuthData, CustomAuthDataSchema } from '@lit-protocol/schemas';
12
import { hexToBigInt, keccak256, toBytes } from 'viem';
23

34
export const utils = {
@@ -56,12 +57,14 @@ export const utils = {
5657
uniqueDappName: string;
5758
uniqueAuthMethodType: bigint;
5859
userId: string;
59-
}) => {
60+
}): CustomAuthData => {
6061
const uniqueUserId = `${uniqueDappName}-${userId}`;
6162

62-
return {
63+
const customAuthData = CustomAuthDataSchema.parse({
6364
authMethodType: uniqueAuthMethodType,
6465
authMethodId: keccak256(toBytes(uniqueUserId)),
65-
};
66+
});
67+
68+
return customAuthData;
6669
},
6770
};

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { DEV_PRIVATE_KEY, version } from '@lit-protocol/constants';
22
import { verifyAndDecryptWithSignatureShares } from '@lit-protocol/crypto';
33
import {
44
AuthData,
5+
AuthDataInput,
56
EncryptedVersion1Schema,
67
GenericEncryptedPayloadSchema,
78
GenericResultBuilder,
89
HexPrefixedSchema,
910
JsonSignCustomSessionKeyRequestForPkpReturnSchema,
1011
JsonSignSessionKeyRequestForPkpReturnSchema,
12+
ScopeStringSchema,
1113
} from '@lit-protocol/schemas';
1214
import { Hex, hexToBytes, stringToBytes, bytesToHex } from 'viem';
1315
import { z } from 'zod';
@@ -377,8 +379,8 @@ export function createBaseModule<T, M>(config: BaseModuleConfig<T, M>) {
377379

378380
mintWithAuth: async (params: {
379381
account: ExpectedAccountOrWalletClient;
380-
authData: Optional<AuthData, 'accessToken'>;
381-
scopes: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
382+
authData: Optional<AuthDataInput, 'accessToken'>;
383+
scopes: z.infer<typeof ScopeStringSchema>[];
382384
}): Promise<GenericTxRes<LitTxRes<PKPData>, PKPData>> => {
383385
const chainManager = createChainManager(params.account);
384386
const res = await chainManager.api.mintPKP({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import type { PKPStorageProvider } from '../../../../../../../../storage/types';
5757
import { logger } from '../../../../../../../shared/logger';
5858
import { DefaultNetworkConfig } from '../../../../../../shared/interfaces/NetworkContext';
5959
import { ExpectedAccountOrWalletClient } from '../../../../contract-manager/createContractsManager';
60-
import { ScopeString } from '../../../schemas/shared/ScopeSchema';
60+
import { ScopeString } from '@lit-protocol/schemas';
6161
import { AuthMethod } from '../../rawContractApis/permissions/read/getPermittedAuthMethods';
6262
import { LitTxVoid } from '../../types';
6363

packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedActionByIdentifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DefaultNetworkConfig } from '../../../../../../../shared/interfaces/NetworkContext';
22
import { isIpfsCidV0 } from '../../../../../../../../shared/utils/z-validate';
33
import { z } from 'zod';
4-
import { ScopeStringSchema } from '../../../../schemas/shared/ScopeSchema';
4+
import { ScopeStringSchema } from '@lit-protocol/schemas';
55
import {
66
PkpIdentifierRaw,
77
resolvePkpTokenId,

0 commit comments

Comments
 (0)