Skip to content

Commit eff05d9

Browse files
committed
fix(auth-service): add scopes to pkpMint endpoint
1 parent 633f30c commit eff05d9

File tree

9 files changed

+91
-19
lines changed

9 files changed

+91
-19
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
@@ -1,13 +1,13 @@
1-
import { MintRequestRaw } from '@lit-protocol/networks';
21
import { ElysiaInstance } from '../../types/ElysiaInstance.type';
32
import { addJob } from '../../../../queue-manager/src/bullmqSetup';
43
import { resp } from '../../response-helpers/response-helpers';
54
import { mintPkpDoc } from '../../../../queue-manager/src/handlers/pkpMint/pkpMint.doc';
5+
import { AuthServiceMintRequestRaw } from '../../schemas/AuthServiceMintRequestSchema';
66

77
export const mint = (app: ElysiaInstance) => {
88
app.post(
99
'/mint',
10-
async ({ body }: { body: MintRequestRaw }) => {
10+
async ({ body }: { body: AuthServiceMintRequestRaw }) => {
1111
try {
1212
const job = await addJob('pkpMint', { requestBody: body });
1313
return resp.QUEUED(job.id, 'PKP minting request queued successfully.');
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { t } from 'elysia';
2+
import { z } from 'zod';
3+
4+
/**
5+
* Schema for auth service PKP mint request
6+
* This is a simplified version for minting with a single auth method
7+
*/
8+
export const AuthServiceMintRequestSchema = z.object({
9+
authMethodType: z.string(),
10+
authMethodId: z.string(),
11+
pubkey: z.string().optional().default('0x'),
12+
scopes: z
13+
.array(z.enum(['sign-anything', 'personal-sign', 'no-permissions']))
14+
.optional(),
15+
});
16+
17+
// User Input Type - what the API accepts
18+
export type AuthServiceMintRequestRaw = z.input<
19+
typeof AuthServiceMintRequestSchema
20+
>;
21+
22+
// Transformed/Validated Type - after validation
23+
export type AuthServiceMintRequestTransformed = z.infer<
24+
typeof AuthServiceMintRequestSchema
25+
>;
26+
27+
// Elysia Schema for runtime validation
28+
export const tAuthServiceMintRequestSchema = t.Object({
29+
authMethodType: t.String(),
30+
authMethodId: t.String(),
31+
pubkey: t.Optional(t.String({ default: '0x' })),
32+
scopes: t.Optional(
33+
t.Array(
34+
t.Union([
35+
t.Literal('sign-anything'),
36+
t.Literal('personal-sign'),
37+
t.Literal('no-permissions'),
38+
])
39+
)
40+
),
41+
});

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ export const mintPkpDoc = {
44
body: t.Object(
55
{
66
authMethodType: t.Required(
7-
t.Number({
7+
t.String({
88
description:
9-
'The numeric type of authentication method to use for the PKP. Supported types include:\n' +
10-
'- 1: EthWallet\n' +
11-
'- 2: LitAction\n' +
12-
'- 3: WebAuthn\n' +
13-
'- 4: Discord\n' +
14-
'- 5: Google\n' +
15-
'- 6: GoogleJwt\n' +
16-
'- 8: AppleJwt\n' +
17-
'- 9: StytchOtp\n' +
18-
'- 10: StytchEmailFactorOtp\n' +
19-
'- 11: StytchSmsFactorOtp\n' +
20-
'- 12: StytchWhatsAppFactorOtp\n' +
21-
'- 13: StytchTotpFactorOtp\n\n' +
22-
'Custom auth methods can also be used by providing their corresponding numeric ID.',
9+
'The type of authentication method to use for the PKP. Supported types include:\n' +
10+
'- "1": EthWallet\n' +
11+
'- "2": LitAction\n' +
12+
'- "3": WebAuthn\n' +
13+
'- "4": Discord\n' +
14+
'- "5": Google\n' +
15+
'- "6": GoogleJwt\n' +
16+
'- "8": AppleJwt\n' +
17+
'- "9": StytchOtp\n' +
18+
'- "10": StytchEmailFactorOtp\n' +
19+
'- "11": StytchSmsFactorOtp\n' +
20+
'- "12": StytchWhatsAppFactorOtp\n' +
21+
'- "13": StytchTotpFactorOtp\n\n' +
22+
'Custom auth methods can also be used by providing their corresponding string ID.',
2323
})
2424
),
2525
authMethodId: t.Required(
@@ -36,6 +36,22 @@ export const mintPkpDoc = {
3636
"Public key associated with the authentication method. This is primarily used for WebAuthn, where it should be the public key obtained from the WebAuthn registration process. For other authentication types, if this field is omitted or an empty string is provided, it will default to '0x'. If explicitly providing for non-WebAuthn, use '0x'.",
3737
})
3838
),
39+
scopes: t.Optional(
40+
t.Array(
41+
t.Union([
42+
t.Literal('sign-anything'),
43+
t.Literal('personal-sign'),
44+
t.Literal('no-permissions'),
45+
]),
46+
{
47+
description:
48+
'Array of permission scopes to grant to the PKP. If omitted, defaults to an empty array (no permissions). Available scopes:\n' +
49+
'- "sign-anything": Allows the PKP to sign any message\n' +
50+
'- "personal-sign": Allows the PKP to sign personal messages only\n' +
51+
'- "no-permissions": Explicitly sets no permissions',
52+
}
53+
)
54+
),
3955
},
4056
{
4157
description:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function handlePkpMintTask(jobData: {
1212
authMethodType: string;
1313
authMethodId: Hex;
1414
pubkey: Hex;
15+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
1516
};
1617
}): Promise<any> {
1718
const userAuthData: Optional<AuthData, 'accessToken'> = {
@@ -23,7 +24,7 @@ export async function handlePkpMintTask(jobData: {
2324
const result = await globalThis.systemContext.litClient.mintWithAuth({
2425
account: globalThis.systemContext.account,
2526
authData: userAuthData,
26-
scopes: ['sign-anything'],
27+
scopes: jobData.requestBody.scopes || [],
2728
});
2829

2930
console.log(

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,13 @@ export const _createNagaLitClient = async (
866866
});
867867
},
868868
authService: {
869-
mintWithAuth: networkModule.authService.pkpMint,
869+
mintWithAuth: async (params: {
870+
authData: AuthData;
871+
authServiceBaseUrl?: string;
872+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
873+
}) => {
874+
return networkModule.authService.pkpMint(params);
875+
},
870876
},
871877
executeJs: async (
872878
params: z.infer<typeof networkModule.api.executeJs.schemas.Input>

packages/networks/src/networks/vNaga/envs/naga-dev/naga-dev.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ const networkModuleObject = {
447447
pkpMint: async (params: {
448448
authData: AuthData;
449449
authServiceBaseUrl?: string;
450+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
450451
}) => {
451452
return await handleAuthServerRequest<PKPData>({
452453
jobName: 'PKP Minting',
@@ -458,6 +459,7 @@ const networkModuleObject = {
458459
authMethodType: params.authData.authMethodType,
459460
authMethodId: params.authData.authMethodId,
460461
pubkey: params.authData.publicKey,
462+
scopes: params.scopes,
461463
},
462464
});
463465
},

packages/networks/src/networks/vNaga/envs/naga-local/naga-local.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ const networkModuleObject = {
447447
pkpMint: async (params: {
448448
authData: AuthData;
449449
authServiceBaseUrl?: string;
450+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
450451
}) => {
451452
return await handleAuthServerRequest<PKPData>({
452453
jobName: 'PKP Minting',
@@ -458,6 +459,7 @@ const networkModuleObject = {
458459
authMethodType: params.authData.authMethodType,
459460
authMethodId: params.authData.authMethodId,
460461
pubkey: params.authData.publicKey,
462+
scopes: params.scopes,
461463
},
462464
});
463465
},

packages/networks/src/networks/vNaga/envs/naga-staging/naga-staging.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ const networkModuleObject = {
447447
pkpMint: async (params: {
448448
authData: AuthData;
449449
authServiceBaseUrl?: string;
450+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
450451
}) => {
451452
return await handleAuthServerRequest<PKPData>({
452453
jobName: 'PKP Minting',
@@ -458,6 +459,7 @@ const networkModuleObject = {
458459
authMethodType: params.authData.authMethodType,
459460
authMethodId: params.authData.authMethodId,
460461
pubkey: params.authData.publicKey,
462+
scopes: params.scopes,
461463
},
462464
});
463465
},

packages/networks/src/networks/vNaga/envs/naga-test/naga-test.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ const networkModuleObject = {
447447
pkpMint: async (params: {
448448
authData: AuthData;
449449
authServiceBaseUrl?: string;
450+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
450451
}) => {
451452
return await handleAuthServerRequest<PKPData>({
452453
jobName: 'PKP Minting',
@@ -458,6 +459,7 @@ const networkModuleObject = {
458459
authMethodType: params.authData.authMethodType,
459460
authMethodId: params.authData.authMethodId,
460461
pubkey: params.authData.publicKey,
462+
scopes: params.scopes,
461463
},
462464
});
463465
},

0 commit comments

Comments
 (0)