diff --git a/packages/auth-services/package.json b/packages/auth-services/package.json index 1cd3373acc..80dd770e71 100644 --- a/packages/auth-services/package.json +++ b/packages/auth-services/package.json @@ -20,7 +20,7 @@ "@elysiajs/cors": "^1.2.0", "@elysiajs/static": "^1.3.0", "@elysiajs/swagger": "^1.2.0", - "@lit-protocol/contracts": "^0.4.0", + "@lit-protocol/contracts": "^0.5.0", "@simplewebauthn/server": "6.2.1", "@simplewebauthn/typescript-types": "^8.3.4", "@t3-oss/env-core": "^0.12.0", diff --git a/packages/auth-services/src/auth-server/src/routes/pkp/mint.ts b/packages/auth-services/src/auth-server/src/routes/pkp/mint.ts index 24dd362b25..2fc0b82525 100644 --- a/packages/auth-services/src/auth-server/src/routes/pkp/mint.ts +++ b/packages/auth-services/src/auth-server/src/routes/pkp/mint.ts @@ -2,12 +2,12 @@ import { ElysiaInstance } from '../../types/ElysiaInstance.type'; import { addJob } from '../../../../queue-manager/src/bullmqSetup'; import { resp } from '../../response-helpers/response-helpers'; import { mintPkpDoc } from '../../../../queue-manager/src/handlers/pkpMint/pkpMint.doc'; -import { AuthServiceMintRequestRaw } from '../../schemas/AuthServiceMintRequestSchema'; +import { MintPKPRequest } from '@lit-protocol/schemas'; export const mint = (app: ElysiaInstance) => { app.post( '/mint', - async ({ body }: { body: AuthServiceMintRequestRaw }) => { + async ({ body }: { body: MintPKPRequest }) => { try { const job = await addJob('pkpMint', { requestBody: body }); return resp.QUEUED(job.id, 'PKP minting request queued successfully.'); diff --git a/packages/auth-services/src/auth-server/src/schemas/AuthServiceMintRequestSchema.ts b/packages/auth-services/src/auth-server/src/schemas/AuthServiceMintRequestSchema.ts deleted file mode 100644 index 9c02cf4396..0000000000 --- a/packages/auth-services/src/auth-server/src/schemas/AuthServiceMintRequestSchema.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { t } from 'elysia'; -import { z } from 'zod'; - -/** - * Schema for auth service PKP mint request - * This is a simplified version for minting with a single auth method - */ -export const AuthServiceMintRequestSchema = z.object({ - authMethodType: z.string(), - authMethodId: z.string(), - pubkey: z.string().optional().default('0x'), - scopes: z - .array(z.enum(['sign-anything', 'personal-sign', 'no-permissions'])) - .optional(), -}); - -// User Input Type - what the API accepts -export type AuthServiceMintRequestRaw = z.input< - typeof AuthServiceMintRequestSchema ->; - -// Transformed/Validated Type - after validation -export type AuthServiceMintRequestTransformed = z.infer< - typeof AuthServiceMintRequestSchema ->; - -// Elysia Schema for runtime validation -export const tAuthServiceMintRequestSchema = t.Object({ - authMethodType: t.String(), - authMethodId: t.String(), - pubkey: t.Optional(t.String({ default: '0x' })), - scopes: t.Optional( - t.Array( - t.Union([ - t.Literal('sign-anything'), - t.Literal('personal-sign'), - t.Literal('no-permissions'), - ]) - ) - ), -}); diff --git a/packages/auth-services/src/queue-manager/src/handlers/pkpMint/pkpMint.handler.ts b/packages/auth-services/src/queue-manager/src/handlers/pkpMint/pkpMint.handler.ts index 8601be4654..7e73afcfa2 100644 --- a/packages/auth-services/src/queue-manager/src/handlers/pkpMint/pkpMint.handler.ts +++ b/packages/auth-services/src/queue-manager/src/handlers/pkpMint/pkpMint.handler.ts @@ -1,6 +1,9 @@ -import { AuthData } from '@lit-protocol/schemas'; +import { + AuthData, + MintPKPRequest, + MintPKPRequestSchema, +} from '@lit-protocol/schemas'; import { Optional } from '@lit-protocol/types'; -import { Hex } from 'viem'; /** * Handles PKP minting tasks. @@ -8,23 +11,18 @@ import { Hex } from 'viem'; * @returns The result of the PKP minting process. */ export async function handlePkpMintTask(jobData: { - requestBody: { - authMethodType: string; - authMethodId: Hex; - pubkey: Hex; - scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[]; - }; + requestBody: MintPKPRequest; + reqId?: string; }): Promise { - const userAuthData: Optional = { - authMethodId: jobData.requestBody.authMethodId, - authMethodType: Number(jobData.requestBody.authMethodType), - publicKey: jobData.requestBody.pubkey, - }; const result = await globalThis.systemContext.litClient.mintWithAuth({ account: globalThis.systemContext.account, - authData: userAuthData, - scopes: jobData.requestBody.scopes || [], + authData: { + authMethodId: jobData.requestBody.authMethodId, + authMethodType: jobData.requestBody.authMethodType, + publicKey: jobData.requestBody.pubkey, + }, + scopes: jobData.requestBody.scopes, }); console.log( diff --git a/packages/auth/src/lib/authenticators/native/WebAuthnAuthenticator.ts b/packages/auth/src/lib/authenticators/native/WebAuthnAuthenticator.ts index 4e2fc0e08a..36389fa90e 100644 --- a/packages/auth/src/lib/authenticators/native/WebAuthnAuthenticator.ts +++ b/packages/auth/src/lib/authenticators/native/WebAuthnAuthenticator.ts @@ -14,12 +14,13 @@ import { } from '@lit-protocol/constants'; import { AuthMethod, AuthServerTx, Hex } from '@lit-protocol/types'; -import { AuthData, PKPData } from '@lit-protocol/schemas'; +import { AuthData, PKPData, ScopeStringSchema } from '@lit-protocol/schemas'; import { getRPIdFromOrigin, parseAuthenticatorData } from '../helper/utils'; import { EthBlockhashInfo } from '@lit-protocol/types'; import { pollResponse } from '../helper/pollResponse'; import { JobStatusResponse } from '../types'; +import { z } from 'zod'; const fetchBlockchainData = async () => { try { @@ -149,6 +150,7 @@ export class WebAuthnAuthenticator { public static async registerAndMintPKP(params: { username?: string; authServiceBaseUrl: string; + scopes?: z.infer[]; }): Promise<{ pkpInfo: PKPData; @@ -183,6 +185,7 @@ export class WebAuthnAuthenticator { authMethodType: AUTH_METHOD_TYPE.WebAuthn, authMethodId: authMethodId, pubkey: authMethodPubkey, + scopes: params.scopes, }; // Immediate mint a new PKP to associate with the auth method diff --git a/packages/lit-client/src/lib/LitClient/createLitClient.ts b/packages/lit-client/src/lib/LitClient/createLitClient.ts index 618759aef2..5e12db67b9 100644 --- a/packages/lit-client/src/lib/LitClient/createLitClient.ts +++ b/packages/lit-client/src/lib/LitClient/createLitClient.ts @@ -350,7 +350,8 @@ export const _createNagaLitClient = async ( return await networkModule.api.signCustomSessionKey.handleResponse( result as any, params.requestBody.pkpPublicKey, - jitContext + jitContext, + requestId ); } diff --git a/packages/lit-client/src/lib/LitClient/schemas/MintWithCustomAuthSchema.ts b/packages/lit-client/src/lib/LitClient/schemas/MintWithCustomAuthSchema.ts index ca2a6424e6..d1174a4ca7 100644 --- a/packages/lit-client/src/lib/LitClient/schemas/MintWithCustomAuthSchema.ts +++ b/packages/lit-client/src/lib/LitClient/schemas/MintWithCustomAuthSchema.ts @@ -1,4 +1,4 @@ -import { AuthData } from '@lit-protocol/schemas'; +import { AuthData, CustomAuthDataSchema } from '@lit-protocol/schemas'; import { Optional } from '@lit-protocol/types'; import { z } from 'zod'; @@ -9,7 +9,7 @@ const BaseMintWithCustomAuthSchema = z.object({ // Account information - this will be passed from the calling context account: z.any(), // Account type varies by network // Authentication data for the user - authData: z.custom>(), + authData: CustomAuthDataSchema, scope: z.enum(['no-permissions', 'sign-anything', 'personal-sign']), // Optional overrides addPkpEthAddressAsPermittedAddress: z.boolean().default(false), diff --git a/packages/lit-client/src/lib/LitClient/utils.ts b/packages/lit-client/src/lib/LitClient/utils.ts index 8602d5cf68..1766a6b92d 100644 --- a/packages/lit-client/src/lib/LitClient/utils.ts +++ b/packages/lit-client/src/lib/LitClient/utils.ts @@ -1,3 +1,4 @@ +import { CustomAuthData, CustomAuthDataSchema } from '@lit-protocol/schemas'; import { hexToBigInt, keccak256, toBytes } from 'viem'; export const utils = { @@ -56,12 +57,14 @@ export const utils = { uniqueDappName: string; uniqueAuthMethodType: bigint; userId: string; - }) => { + }): CustomAuthData => { const uniqueUserId = `${uniqueDappName}-${userId}`; - return { + const customAuthData = CustomAuthDataSchema.parse({ authMethodType: uniqueAuthMethodType, authMethodId: keccak256(toBytes(uniqueUserId)), - }; + }); + + return customAuthData; }, }; diff --git a/packages/networks/package.json b/packages/networks/package.json index fea67bdb99..b3fe6dea47 100644 --- a/packages/networks/package.json +++ b/packages/networks/package.json @@ -18,7 +18,7 @@ "directory": "../../dist/packages/networks" }, "dependencies": { - "@lit-protocol/contracts": "^0.4.0", + "@lit-protocol/contracts": "^0.5.0", "@lit-protocol/nacl": "7.1.1", "@noble/curves": "^1.8.1", "@wagmi/core": "^2.17.1", diff --git a/packages/networks/src/networks/vNaga/shared/factories/BaseModuleFactory.ts b/packages/networks/src/networks/vNaga/shared/factories/BaseModuleFactory.ts index a137525e72..fa3bb77475 100644 --- a/packages/networks/src/networks/vNaga/shared/factories/BaseModuleFactory.ts +++ b/packages/networks/src/networks/vNaga/shared/factories/BaseModuleFactory.ts @@ -2,12 +2,14 @@ import { DEV_PRIVATE_KEY, version } from '@lit-protocol/constants'; import { verifyAndDecryptWithSignatureShares } from '@lit-protocol/crypto'; import { AuthData, + AuthDataInput, EncryptedVersion1Schema, GenericEncryptedPayloadSchema, GenericResultBuilder, HexPrefixedSchema, JsonSignCustomSessionKeyRequestForPkpReturnSchema, JsonSignSessionKeyRequestForPkpReturnSchema, + ScopeStringSchema, } from '@lit-protocol/schemas'; import { Hex, hexToBytes, stringToBytes } from 'viem'; import { z } from 'zod'; @@ -375,8 +377,8 @@ export function createBaseModule(config: BaseModuleConfig) { mintWithAuth: async (params: { account: ExpectedAccountOrWalletClient; - authData: Optional; - scopes: ('sign-anything' | 'personal-sign' | 'no-permissions')[]; + authData: Optional; + scopes: z.infer[]; }): Promise, PKPData>> => { const chainManager = createChainManager(params.account); const res = await chainManager.api.mintPKP({ @@ -898,7 +900,8 @@ export function createBaseModule(config: BaseModuleConfig) { handleResponse: async ( result: z.infer, pkpPublicKey: Hex | string, - jitContext: NagaJitContext + jitContext: NagaJitContext, + requestId?: string ) => { if (!result.success) { E2EERequestManager.handleEncryptedError( diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/PKPPermissionsManager.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/PKPPermissionsManager.ts index b76d0b7512..1df579b9a1 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/PKPPermissionsManager.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/PKPPermissionsManager.ts @@ -57,7 +57,7 @@ import type { PKPStorageProvider } from '../../../../../../../../storage/types'; import { logger } from '../../../../../../../shared/logger'; import { DefaultNetworkConfig } from '../../../../../../shared/interfaces/NetworkContext'; import { ExpectedAccountOrWalletClient } from '../../../../contract-manager/createContractsManager'; -import { ScopeString } from '../../../schemas/shared/ScopeSchema'; +import { ScopeString } from '@lit-protocol/schemas'; import { AuthMethod } from '../../rawContractApis/permissions/read/getPermittedAuthMethods'; import { LitTxVoid } from '../../types'; diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedActionByIdentifier.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedActionByIdentifier.ts index 6ed1345fc9..5faf964ada 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedActionByIdentifier.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedActionByIdentifier.ts @@ -1,7 +1,7 @@ import { DefaultNetworkConfig } from '../../../../../../../shared/interfaces/NetworkContext'; import { isIpfsCidV0 } from '../../../../../../../../shared/utils/z-validate'; import { z } from 'zod'; -import { ScopeStringSchema } from '../../../../schemas/shared/ScopeSchema'; +import { ScopeStringSchema } from '@lit-protocol/schemas'; import { PkpIdentifierRaw, resolvePkpTokenId, diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAddressByIdentifier.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAddressByIdentifier.ts index 0fc8e3f499..3b0e7fa208 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAddressByIdentifier.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAddressByIdentifier.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; import { DefaultNetworkConfig } from '../../../../../../../shared/interfaces/NetworkContext'; -import { ScopeStringSchema } from '../../../../schemas/shared/ScopeSchema'; +import { ScopeStringSchema } from '@lit-protocol/schemas'; import { PkpIdentifierRaw, resolvePkpTokenId, diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAuthMethodByIdentifier.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAuthMethodByIdentifier.ts index f2ee701b78..e6d748aac8 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAuthMethodByIdentifier.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/addPermittedAuthMethodByIdentifier.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; import { DefaultNetworkConfig } from '../../../../../../../shared/interfaces/NetworkContext'; -import { ScopeStringSchema } from '../../../../schemas/shared/ScopeSchema'; +import { ScopeStringSchema } from '@lit-protocol/schemas'; import { PkpIdentifierRaw, resolvePkpTokenId, diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/MintPKPSchema.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/MintPKPSchema.ts deleted file mode 100644 index b983cd805a..0000000000 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/MintPKPSchema.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { AUTH_METHOD_TYPE } from '@lit-protocol/constants'; -import { HexPrefixedSchema } from '@lit-protocol/schemas'; -import { Hex } from 'viem'; -import { z } from 'zod'; -import { ScopeSchemaRaw } from '../../../schemas/shared/ScopeSchema'; - -export const MintPKPSchema = z - .object({ - // authMethod: AuthMethodSchema, - authMethodId: HexPrefixedSchema, - authMethodType: z.union([z.number(), z.bigint()]), - scopes: z.array(ScopeSchemaRaw), - pubkey: HexPrefixedSchema.optional(), - }) - .transform(async (data) => { - let derivedPubkey: Hex | undefined; - - // Determine pubkey based on the (potentially derived) authMethodType - if (data.authMethodType === AUTH_METHOD_TYPE.WebAuthn) { - if (!data.pubkey) { - throw new Error('pubkey is required for WebAuthn'); - } - derivedPubkey = data.pubkey as Hex; - } else { - derivedPubkey = '0x' as Hex; - } - - // Ensure pubkey is present (it should always be by this point) - if (typeof derivedPubkey === 'undefined') { - // This case should ideally not be reached if logic above is correct - throw new Error('pubkey could not be determined'); - } - - // Return data with resolved/derived values - return { - ...data, - authMethodId: data.authMethodId, - authMethodType: data.authMethodType, - pubkey: derivedPubkey, - }; - }); - -export type MintPKPRequest = z.input; diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintPKP.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintPKP.ts index 0c9eb2495d..60b3c2ed58 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintPKP.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintPKP.ts @@ -4,7 +4,7 @@ import { ExpectedAccountOrWalletClient } from '../../../../contract-manager/crea import { PKPData } from '../../../schemas/shared/PKPDataSchema'; import { mintNextAndAddAuthMethods } from '../../rawContractApis/pkp/write/mintNextAndAddAuthMethods'; import { LitTxRes } from '../../types'; -import { MintPKPRequest, MintPKPSchema } from './MintPKPSchema'; +import { MintPKPRequest, MintPKPRequestSchema } from '@lit-protocol/schemas'; /** * authMethod @@ -36,7 +36,7 @@ export const mintPKP = async ( networkConfig: DefaultNetworkConfig, accountOrWalletClient: ExpectedAccountOrWalletClient ): Promise> => { - const validatedRequest = await MintPKPSchema.parseAsync(request); + const validatedRequest = await MintPKPRequestSchema.parseAsync(request); logger.debug({ validatedRequest }); @@ -45,6 +45,7 @@ export const mintPKP = async ( const tx = await mintNextAndAddAuthMethods( { keyType: 2, + keySetId: 'naga-keyset1', permittedAuthMethodTypes: [validatedRequest.authMethodType], permittedAuthMethodIds: [validatedRequest.authMethodId], permittedAuthMethodPubkeys: [validatedRequest.pubkey], diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths.ts index 3dd4f026c3..c61bd06ed4 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths.ts @@ -6,7 +6,7 @@ import { logger } from '../../../../../../../shared/logger'; import { DefaultNetworkConfig } from '../../../../../../shared/interfaces/NetworkContext'; import { ExpectedAccountOrWalletClient } from '../../../../contract-manager/createContractsManager'; import { PKPData } from '../../../schemas/shared/PKPDataSchema'; -import { ScopeSchemaRaw } from '../../../schemas/shared/ScopeSchema'; +import { ScopeSchemaRaw } from '@lit-protocol/schemas'; import { mintNextAndAddAuthMethods } from '../../rawContractApis/pkp/write/mintNextAndAddAuthMethods'; import { LitTxRes } from '../../types'; @@ -115,6 +115,7 @@ export const mintWithMultiAuths = async ( const tx = await mintNextAndAddAuthMethods( { keyType: 2, + keySetId: 'naga-keyset1', permittedAuthMethodTypes: validatedRequest.authMethodTypes, permittedAuthMethodIds: validatedRequest.authMethodIds, permittedAuthMethodPubkeys: validatedRequest.pubkeys, diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAction.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAction.ts index 26873f5b34..20f72d6cd6 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAction.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAction.ts @@ -5,7 +5,7 @@ import { ipfsCidV0ToHex } from '../../../../../../../../shared/utils/transformer import { toBigInt } from '../../../../../../../../shared/utils/z-transformers'; import { isIpfsCidV0 } from '../../../../../../../../shared/utils/z-validate'; import { DefaultNetworkConfig } from '../../../../../../../shared/interfaces/NetworkContext'; -import { ScopeSchemaRaw } from '../../../../schemas/shared/ScopeSchema'; +import { ScopeSchemaRaw } from '@lit-protocol/schemas'; import { LitTxVoid } from '../../../types'; import { callWithAdjustedOverrides } from '../../../utils/callWithAdjustedOverrides'; import { diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAddress.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAddress.ts index bbf51b587f..7bab7c8453 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAddress.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAddress.ts @@ -7,7 +7,7 @@ import { createContractsManager, ExpectedAccountOrWalletClient, } from '../../../../../contract-manager/createContractsManager'; -import { ScopeSchemaRaw } from '../../../../schemas/shared/ScopeSchema'; +import { ScopeSchemaRaw } from '@lit-protocol/schemas'; import { LitTxVoid } from '../../../types'; import { callWithAdjustedOverrides } from '../../../utils/callWithAdjustedOverrides'; import { decodeLogs } from '../../../utils/decodeLogs'; diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAuthMethod.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAuthMethod.ts index d7e19fbb00..a574a794f6 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAuthMethod.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/permissions/write/addPermittedAuthMethod.ts @@ -13,7 +13,7 @@ import { createContractsManager, ExpectedAccountOrWalletClient, } from '../../../../../contract-manager/createContractsManager'; -import { ScopeSchemaRaw } from '../../../../schemas/shared/ScopeSchema'; +import { ScopeSchemaRaw } from '@lit-protocol/schemas'; import { LitTxVoid } from '../../../types'; import { callWithAdjustedOverrides } from '../../../utils/callWithAdjustedOverrides'; import { decodeLogs } from '../../../utils/decodeLogs'; diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNext.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNext.ts index 581f8e3f4d..8176c687e7 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNext.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNext.ts @@ -22,7 +22,7 @@ export async function mintNext( const hash = await callWithAdjustedOverrides( pkpNftContract, 'mintNext', - [2], + [2,'naga-keyset1'], { value: mintCost, } diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNextAndAddAuthMethods.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNextAndAddAuthMethods.ts index de9dbb881a..384e63f816 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNextAndAddAuthMethods.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/apis/rawContractApis/pkp/write/mintNextAndAddAuthMethods.ts @@ -69,6 +69,7 @@ export async function mintNextAndAddAuthMethods( 'mintNextAndAddAuthMethods', [ validatedRequest.keyType, + validatedRequest.keySetId, validatedRequest.permittedAuthMethodTypes, validatedRequest.permittedAuthMethodIds, validatedRequest.permittedAuthMethodPubkeys, diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/schemas/MintRequestSchema.ts b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/schemas/MintRequestSchema.ts index 77ce533822..313d06d947 100644 --- a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/schemas/MintRequestSchema.ts +++ b/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/schemas/MintRequestSchema.ts @@ -10,6 +10,7 @@ import { export const MintRequestSchema = z.object({ keyType: toBigInt, + keySetId: z.literal('naga-keyset1'), permittedAuthMethodTypes: toBigIntArray, permittedAuthMethodIds: toHexStringArray, permittedAuthMethodPubkeys: toHexStringArray, diff --git a/packages/schemas/src/index.ts b/packages/schemas/src/index.ts index 5975b6ad4c..863eaa0dbd 100644 --- a/packages/schemas/src/index.ts +++ b/packages/schemas/src/index.ts @@ -4,6 +4,7 @@ import { z } from 'zod'; import { LitResourceAbilityRequestSchema } from './lib/models'; import { AuthSigSchema } from './lib/schemas'; export * from './lib/auth/auth-schemas'; +export * from './lib/auth/ScopeSchema'; export * from './lib/encryption'; export * from './lib/models'; export * from './lib/schemas'; diff --git a/packages/networks/src/networks/vNaga/shared/managers/LitChainClient/schemas/shared/ScopeSchema.ts b/packages/schemas/src/lib/auth/ScopeSchema.ts similarity index 100% rename from packages/networks/src/networks/vNaga/shared/managers/LitChainClient/schemas/shared/ScopeSchema.ts rename to packages/schemas/src/lib/auth/ScopeSchema.ts diff --git a/packages/schemas/src/lib/auth/auth-schemas.ts b/packages/schemas/src/lib/auth/auth-schemas.ts index 6ee258b6f8..a6b264c5e6 100644 --- a/packages/schemas/src/lib/auth/auth-schemas.ts +++ b/packages/schemas/src/lib/auth/auth-schemas.ts @@ -1,4 +1,7 @@ -import { AUTH_METHOD_TYPE_VALUES } from '@lit-protocol/constants'; +import { + AUTH_METHOD_TYPE, + AUTH_METHOD_TYPE_VALUES, +} from '@lit-protocol/constants'; import { z } from 'zod'; import { AuthMethodSchema, @@ -6,14 +9,19 @@ import { NodeSetSchema, SessionKeyUriSchema, } from '../schemas'; +import { ScopeSchemaRaw } from './ScopeSchema'; + +export const CustomAuthDataSchema = z.object({ + authMethodId: HexPrefixedSchema, + // This will be a very big number, unlike our native auth + authMethodType: z.bigint(), +}); + +export type CustomAuthData = z.infer; export const AuthDataSchema = z.object({ authMethodId: HexPrefixedSchema, - authMethodType: z.union([ - AuthMethodSchema.shape.authMethodType, - z.number(), - z.bigint(), - ]), + authMethodType: z.coerce.number().pipe(z.nativeEnum(AUTH_METHOD_TYPE)), accessToken: AuthMethodSchema.shape.accessToken, publicKey: HexPrefixedSchema.optional(), @@ -22,7 +30,8 @@ export const AuthDataSchema = z.object({ metadata: z.any().optional(), }); -export type AuthData = z.infer; +export type AuthData = z.output; +export type AuthDataInput = z.input; /** * Return Object Schema @@ -64,3 +73,34 @@ export const JsonSignCustomSessionKeyRequestForPkpReturnSchema = z }), ]) ); + +/** + * Consolidated schema for PKP mint requests. + * This replaces the duplicated schemas across the codebase. + * Handles both string and number authMethodType inputs. + */ +export const MintPKPRequestSchema = z + .object({ + authMethodId: HexPrefixedSchema, + authMethodType: z.coerce.number().pipe(z.nativeEnum(AUTH_METHOD_TYPE)), + pubkey: HexPrefixedSchema.default('0x'), + scopes: z.array(ScopeSchemaRaw).optional().default([]), + }) + .refine( + (data) => { + // Validate pubkey is present for WebAuthn + // the default has been set to 0x, so we need to check when + // webauthn is used the pubkey should NOT be 0x + if (data.authMethodType === AUTH_METHOD_TYPE.WebAuthn) { + return data.pubkey && data.pubkey !== '0x'; + } + return true; + }, + { + message: 'pubkey is required for WebAuthn and cannot be 0x', + path: ['pubkey'], + } + ); + +export type MintPKPRequest = z.input; +export type MintPKPRequestTransformed = z.output; diff --git a/packages/wasm/rust/Cargo.lock b/packages/wasm/rust/Cargo.lock index 05e97f4319..79b8e9d6f5 100644 --- a/packages/wasm/rust/Cargo.lock +++ b/packages/wasm/rust/Cargo.lock @@ -239,9 +239,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29" [[package]] name = "bitvec" @@ -372,7 +372,7 @@ dependencies = [ "sha2", "sha3", "subtle", - "thiserror 2.0.14", + "thiserror 2.0.15", "uint-zigzag", "vsss-rs 5.1.0", "zeroize", @@ -401,7 +401,7 @@ checksum = "62f7e0e71f98d6c71bfe42b0a7a47d0f870ad808401fad2d44fa156ed5b0ae03" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -422,7 +422,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" dependencies = [ - "thiserror 2.0.14", + "thiserror 2.0.15", ] [[package]] @@ -540,7 +540,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -679,7 +679,7 @@ checksum = "8034092389675178f570469e6c3b0465d3d30b4505c294a6550db47f3c17ad18" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -701,7 +701,7 @@ checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -920,7 +920,7 @@ dependencies = [ "serde", "serdect 0.2.0", "subtle", - "thiserror 2.0.14", + "thiserror 2.0.15", "thiserror-nostd-notrait", "visibility", "zeroize", @@ -955,7 +955,7 @@ dependencies = [ "postcard", "rand_core", "serde", - "thiserror 2.0.14", + "thiserror 2.0.15", "vsss-rs 5.1.0", ] @@ -1134,7 +1134,7 @@ dependencies = [ "rand_chacha", "rand_core", "serde", - "thiserror 2.0.14", + "thiserror 2.0.15", "vsss-rs 5.1.0", ] @@ -1409,7 +1409,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "libc", ] @@ -1467,7 +1467,7 @@ dependencies = [ "serde_bare", "sha2", "subtle", - "thiserror 2.0.14", + "thiserror 2.0.15", "vsss-rs 5.1.0", "zeroize", ] @@ -1801,9 +1801,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.97" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] @@ -2045,7 +2045,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2056,7 +2056,7 @@ checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2214,9 +2214,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.105" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -2240,11 +2240,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.14" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b0949c3a6c842cbde3f1686d6eea5a010516deb7085f79db747562d4102f41e" +checksum = "80d76d3f064b981389ecb4b6b7f45a0bf9fdac1d5b9204c7bd6714fecc302850" dependencies = [ - "thiserror-impl 2.0.14", + "thiserror-impl 2.0.15", ] [[package]] @@ -2255,18 +2255,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] name = "thiserror-impl" -version = "2.0.14" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5b44b4ab9c2fdd0e0512e6bece8388e214c0749f5862b114cc5b7a25daf227" +checksum = "44d29feb33e986b6ea906bd9c3559a856983f92371b3eaa5e83782a351623de0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2306,7 +2306,7 @@ checksum = "585e5ef40a784ce60b49c67d762110688d211d395d39e096be204535cf64590e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2327,7 +2327,7 @@ checksum = "2d2e76690929402faae40aebdda620a2c0e25dd6d3b9afe48867dfd95991f4bd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2351,7 +2351,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2400,7 +2400,7 @@ checksum = "d674d135b4a8c1d7e813e2f8d1c9a58308aee4a680323066025e53132218bd91" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2469,7 +2469,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", "wasm-bindgen-shared", ] @@ -2491,7 +2491,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2609,7 +2609,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] [[package]] @@ -2629,5 +2629,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.105", + "syn 2.0.106", ] diff --git a/packages/wasm/rust/Cargo.toml b/packages/wasm/rust/Cargo.toml index b32a3adc05..19b45b6582 100644 --- a/packages/wasm/rust/Cargo.toml +++ b/packages/wasm/rust/Cargo.toml @@ -61,4 +61,7 @@ lto = true wasm-opt=['-Os'] [package.metadata.wasm-pack.profile.profiling] -wasm-opt = ['-g', '-O'] \ No newline at end of file +wasm-opt = ['-g', '-O'] + +[package.metadata.wasm-pack.profile.release] +wasm-opt = false \ No newline at end of file diff --git a/packages/wasm/rust/LICENSE b/packages/wasm/rust/LICENSE new file mode 100644 index 0000000000..b4e58d1164 --- /dev/null +++ b/packages/wasm/rust/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 WorkGraph, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.