@settlemint/sdk-viem 2.5.6-pr47243248 → 2.5.6-pr4a06ef5a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/viem.js +63 -23
- package/dist/browser/viem.js.map +1 -1
- package/dist/viem.cjs +63 -23
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.js +63 -23
- package/dist/viem.js.map +1 -1
- package/package.json +2 -2
package/dist/browser/viem.js
CHANGED
|
@@ -144,23 +144,55 @@ let OTPAlgorithm = /* @__PURE__ */ function(OTPAlgorithm$1) {
|
|
|
144
144
|
|
|
145
145
|
//#endregion
|
|
146
146
|
//#region src/viem.ts
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
var LRUCache = class {
|
|
148
|
+
cache = new Map();
|
|
149
|
+
maxSize;
|
|
150
|
+
constructor(maxSize) {
|
|
151
|
+
this.maxSize = maxSize;
|
|
152
|
+
}
|
|
153
|
+
get(key) {
|
|
154
|
+
const value = this.cache.get(key);
|
|
155
|
+
if (value !== undefined) {
|
|
156
|
+
this.cache.delete(key);
|
|
157
|
+
this.cache.set(key, value);
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
set(key, value) {
|
|
162
|
+
this.cache.delete(key);
|
|
163
|
+
if (this.cache.size >= this.maxSize) {
|
|
164
|
+
const firstKey = this.cache.keys().next().value;
|
|
165
|
+
if (firstKey !== undefined) {
|
|
166
|
+
this.cache.delete(firstKey);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this.cache.set(key, value);
|
|
170
|
+
}
|
|
171
|
+
clear() {
|
|
172
|
+
this.cache.clear();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const chainCache = new LRUCache(100);
|
|
176
|
+
const publicClientCache = new LRUCache(50);
|
|
177
|
+
const walletClientFactoryCache = new LRUCache(50);
|
|
150
178
|
function createCacheKey(options) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
179
|
+
const keyObject = {};
|
|
180
|
+
const keys = [
|
|
181
|
+
"chainId",
|
|
182
|
+
"chainName",
|
|
183
|
+
"rpcUrl",
|
|
184
|
+
"accessToken"
|
|
185
|
+
];
|
|
186
|
+
for (const key of keys) {
|
|
187
|
+
const value = options[key];
|
|
188
|
+
if (value !== undefined) {
|
|
189
|
+
keyObject[key] = value;
|
|
190
|
+
}
|
|
162
191
|
}
|
|
163
|
-
return
|
|
192
|
+
return JSON.stringify(keyObject, Object.keys(keyObject).sort());
|
|
193
|
+
}
|
|
194
|
+
function buildHeaders(baseHeaders, authHeaders) {
|
|
195
|
+
return appendHeaders(baseHeaders, authHeaders);
|
|
164
196
|
}
|
|
165
197
|
/**
|
|
166
198
|
* Schema for the viem client options.
|
|
@@ -194,13 +226,13 @@ const ClientOptionsSchema = z.object({
|
|
|
194
226
|
*/
|
|
195
227
|
const getPublicClient = (options) => {
|
|
196
228
|
ensureServer();
|
|
197
|
-
const validatedOptions =
|
|
229
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
198
230
|
const cacheKey = createCacheKey(validatedOptions);
|
|
199
231
|
const cachedClient = publicClientCache.get(cacheKey);
|
|
200
232
|
if (cachedClient) {
|
|
201
233
|
return cachedClient;
|
|
202
234
|
}
|
|
203
|
-
const headers =
|
|
235
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken || "" });
|
|
204
236
|
const client = createPublicClient({
|
|
205
237
|
chain: getChain({
|
|
206
238
|
chainId: validatedOptions.chainId,
|
|
@@ -254,7 +286,7 @@ const getPublicClient = (options) => {
|
|
|
254
286
|
*/
|
|
255
287
|
const getWalletClient = (options) => {
|
|
256
288
|
ensureServer();
|
|
257
|
-
const validatedOptions =
|
|
289
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
258
290
|
const cacheKey = createCacheKey(validatedOptions);
|
|
259
291
|
const cachedFactory = walletClientFactoryCache.get(cacheKey);
|
|
260
292
|
if (cachedFactory) {
|
|
@@ -266,8 +298,8 @@ const getWalletClient = (options) => {
|
|
|
266
298
|
rpcUrl: validatedOptions.rpcUrl
|
|
267
299
|
});
|
|
268
300
|
const walletClientFactory = (verificationOptions) => {
|
|
269
|
-
const headers =
|
|
270
|
-
"x-auth-token": validatedOptions.accessToken,
|
|
301
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {
|
|
302
|
+
"x-auth-token": validatedOptions.accessToken || "",
|
|
271
303
|
"x-auth-challenge-response": verificationOptions?.challengeResponse ?? "",
|
|
272
304
|
"x-auth-verification-id": verificationOptions?.verificationId ?? ""
|
|
273
305
|
});
|
|
@@ -313,8 +345,8 @@ const GetChainIdOptionsSchema = z.object({
|
|
|
313
345
|
*/
|
|
314
346
|
async function getChainId(options) {
|
|
315
347
|
ensureServer();
|
|
316
|
-
const validatedOptions =
|
|
317
|
-
const headers =
|
|
348
|
+
const validatedOptions = validate(GetChainIdOptionsSchema, options);
|
|
349
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken || "" });
|
|
318
350
|
const client = createPublicClient({ transport: http(validatedOptions.rpcUrl, {
|
|
319
351
|
...validatedOptions.httpTransportConfig,
|
|
320
352
|
fetchOptions: {
|
|
@@ -326,7 +358,15 @@ async function getChainId(options) {
|
|
|
326
358
|
}
|
|
327
359
|
const knownChainsMap = new Map(Object.values(chains).map((chain) => [chain.id.toString(), chain]));
|
|
328
360
|
function getChain({ chainId, chainName, rpcUrl }) {
|
|
329
|
-
const cacheKey =
|
|
361
|
+
const cacheKey = JSON.stringify({
|
|
362
|
+
chainId,
|
|
363
|
+
chainName,
|
|
364
|
+
rpcUrl
|
|
365
|
+
}, [
|
|
366
|
+
"chainId",
|
|
367
|
+
"chainName",
|
|
368
|
+
"rpcUrl"
|
|
369
|
+
]);
|
|
330
370
|
const cachedChain = chainCache.get(cacheKey);
|
|
331
371
|
if (cachedChain) {
|
|
332
372
|
return cachedChain;
|
package/dist/browser/viem.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viem.js","names":["client: Client","args: CreateWalletParameters","client: Client","args: CreateWalletVerificationParameters","client: Client","args: CreateWalletVerificationChallengesParameters","client: Client","args: DeleteWalletVerificationParameters","client: Client","args: GetWalletVerificationsParameters","client: Client","args: VerifyWalletVerificationChallengeParameters","options: Partial<ClientOptions>","schema: z.ZodSchema<T>","options: unknown","options: ClientOptions","validatedOptions: ClientOptions","verificationOptions?: WalletVerificationOptions","options: GetChainIdOptions","validatedOptions: GetChainIdOptions"],"sources":["../../src/custom-actions/create-wallet.action.ts","../../src/custom-actions/create-wallet-verification.action.ts","../../src/custom-actions/create-wallet-verification-challenges.action.ts","../../src/custom-actions/delete-wallet-verification.action.ts","../../src/custom-actions/get-wallet-verifications.action.ts","../../src/custom-actions/verify-wallet-verification-challenge.action.ts","../../src/custom-actions/types/wallet-verification.enum.ts","../../src/viem.ts"],"sourcesContent":["import type { Client } from \"viem\";\n\n/**\n * Information about the wallet to be created.\n */\nexport interface WalletInfo {\n /** The name of the wallet. */\n name: string;\n}\n\n/**\n * Parameters for creating a wallet.\n */\nexport interface CreateWalletParameters {\n /** The unique name of the key vault where the wallet will be created. */\n keyVaultId: string;\n /** Information about the wallet to be created. */\n walletInfo: WalletInfo;\n}\n\n/**\n * Response from creating a wallet.\n */\nexport interface CreateWalletResponse {\n /** The unique identifier of the wallet. */\n id: string;\n /** The name of the wallet. */\n name: string;\n /** The blockchain address of the wallet. */\n address: string;\n /** The HD derivation path used to create the wallet. */\n derivationPath: string;\n}\n\n/**\n * RPC schema for wallet creation.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWallet\";\n Parameters: [keyVaultId: string, walletInfo: WalletInfo];\n ReturnType: CreateWalletResponse[];\n};\n\n/**\n * Creates a wallet action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWallet method.\n */\nexport function createWallet(client: Client) {\n return {\n /**\n * Creates a new wallet in the specified key vault.\n * @param args - The parameters for creating a wallet.\n * @returns A promise that resolves to an array of created wallet responses.\n */\n createWallet(args: CreateWalletParameters): Promise<CreateWalletResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWallet\",\n params: [args.keyVaultId, args.walletInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { OTPAlgorithm, WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Base interface for wallet verification information.\n */\ntype BaseWalletVerificationInfo = {\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n};\n\n/**\n * Information for PIN code verification.\n */\nexport interface WalletPincodeVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.PINCODE;\n /** The PIN code to use for verification. */\n pincode: string;\n}\n\n/**\n * Information for One-Time Password (OTP) verification.\n */\nexport interface WalletOTPVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.OTP;\n /** The hash algorithm to use for OTP generation. */\n algorithm?: OTPAlgorithm;\n /** The number of digits in the OTP code. */\n digits?: number;\n /** The time period in seconds for OTP validity. */\n period?: number;\n /** The issuer of the OTP. */\n issuer?: string;\n}\n\n/**\n * Information for secret recovery codes verification.\n */\nexport interface WalletSecretCodesVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.SECRET_CODES;\n}\n\n/**\n * Union type of all possible wallet verification information types.\n */\nexport type WalletVerificationInfo =\n | WalletPincodeVerificationInfo\n | WalletOTPVerificationInfo\n | WalletSecretCodesVerificationInfo;\n\n/**\n * Parameters for creating a wallet verification.\n */\nexport interface CreateWalletVerificationParameters {\n /** The wallet address for which to create the verification. */\n userWalletAddress: string;\n /** The verification information to create. */\n walletVerificationInfo: WalletVerificationInfo;\n}\n\n/**\n * Response from creating a wallet verification.\n */\nexport interface CreateWalletVerificationResponse {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n /** Additional parameters specific to the verification type. */\n parameters: Record<string, string>;\n}\n\n/**\n * RPC schema for creating a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerification\";\n Parameters: [userWalletAddress: string, walletVerificationInfo: WalletVerificationInfo];\n ReturnType: CreateWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerification method.\n */\nexport function createWalletVerification(client: Client) {\n return {\n /**\n * Creates a new wallet verification.\n * @param args - The parameters for creating the verification.\n * @returns A promise that resolves to an array of created wallet verification responses.\n */\n createWalletVerification(args: CreateWalletVerificationParameters): Promise<CreateWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerification\",\n params: [args.userWalletAddress, args.walletVerificationInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\nimport type { AddressOrObject } from \"./verify-wallet-verification-challenge.action.js\";\n\n/**\n * Parameters for creating wallet verification challenges.\n */\nexport interface CreateWalletVerificationChallengesParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n}\n\n/**\n * Represents a wallet verification challenge.\n */\nexport interface WalletVerificationChallenge {\n /** The unique identifier of the challenge. */\n id: string;\n /** The name of the challenge. */\n name: string;\n /** The type of verification required. */\n verificationType: WalletVerificationType;\n /** The challenge parameters specific to the verification type. */\n challenge: Record<string, string>;\n}\n\n/**\n * Response from creating wallet verification challenges.\n */\nexport type CreateWalletVerificationChallengesResponse = WalletVerificationChallenge[];\n\n/**\n * RPC schema for creating wallet verification challenges.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerificationChallenges\";\n Parameters: [addressOrObject: AddressOrObject];\n ReturnType: CreateWalletVerificationChallengesResponse;\n};\n\n/**\n * Creates a wallet verification challenges action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerificationChallenges method.\n */\nexport function createWalletVerificationChallenges(client: Client) {\n return {\n /**\n * Creates verification challenges for a wallet.\n * @param args - The parameters for creating the challenges.\n * @returns A promise that resolves to an array of wallet verification challenges.\n */\n createWalletVerificationChallenges(\n args: CreateWalletVerificationChallengesParameters,\n ): Promise<CreateWalletVerificationChallengesResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerificationChallenges\",\n params: [args.addressOrObject],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Parameters for deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationParameters {\n /** The wallet address for which to delete the verification. */\n userWalletAddress: string;\n /** The unique identifier of the verification to delete. */\n verificationId: string;\n}\n\n/**\n * Response from deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationResponse {\n /** Whether the deletion was successful. */\n success: boolean;\n}\n\n/**\n * RPC schema for deleting a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_deleteWalletVerification\";\n Parameters: [userWalletAddress: string, verificationId: string];\n ReturnType: DeleteWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification deletion action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a deleteWalletVerification method.\n */\nexport function deleteWalletVerification(client: Client) {\n return {\n /**\n * Deletes a wallet verification.\n * @param args - The parameters for deleting the verification.\n * @returns A promise that resolves to an array of deletion results.\n */\n deleteWalletVerification(args: DeleteWalletVerificationParameters): Promise<DeleteWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_deleteWalletVerification\",\n params: [args.userWalletAddress, args.verificationId],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Parameters for getting wallet verifications.\n */\nexport interface GetWalletVerificationsParameters {\n /** The wallet address for which to fetch verifications. */\n userWalletAddress: string;\n}\n\n/**\n * Represents a wallet verification.\n */\nexport interface WalletVerification {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n}\n\n/**\n * Response from getting wallet verifications.\n */\nexport type GetWalletVerificationsResponse = WalletVerification[];\n\n/**\n * RPC schema for getting wallet verifications.\n */\ntype WalletRpcSchema = {\n Method: \"user_walletVerifications\";\n Parameters: [userWalletAddress: string];\n ReturnType: GetWalletVerificationsResponse;\n};\n\n/**\n * Creates a wallet verifications retrieval action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a getWalletVerifications method.\n */\nexport function getWalletVerifications(client: Client) {\n return {\n /**\n * Gets all verifications for a wallet.\n * @param args - The parameters for getting the verifications.\n * @returns A promise that resolves to an array of wallet verifications.\n */\n getWalletVerifications(args: GetWalletVerificationsParameters): Promise<GetWalletVerificationsResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_walletVerifications\",\n params: [args.userWalletAddress],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Represents either a wallet address string or an object containing wallet address and optional verification ID.\n */\nexport type AddressOrObject =\n | string\n | {\n userWalletAddress: string;\n verificationId?: string;\n };\n\n/**\n * Parameters for verifying a wallet verification challenge.\n */\nexport interface VerifyWalletVerificationChallengeParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n /** The response to the verification challenge. */\n challengeResponse: string;\n}\n\n/**\n * Result of a wallet verification challenge.\n */\nexport interface VerificationResult {\n /** Whether the verification was successful. */\n verified: boolean;\n}\n\n/**\n * Response from verifying a wallet verification challenge.\n */\nexport type VerifyWalletVerificationChallengeResponse = VerificationResult[];\n\n/**\n * RPC schema for wallet verification challenge verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_verifyWalletVerificationChallenge\";\n Parameters: [addressOrObject: AddressOrObject, challengeResponse: string];\n ReturnType: VerifyWalletVerificationChallengeResponse;\n};\n\n/**\n * Creates a wallet verification challenge verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a verifyWalletVerificationChallenge method.\n */\nexport function verifyWalletVerificationChallenge(client: Client) {\n return {\n /**\n * Verifies a wallet verification challenge.\n * @param args - The parameters for verifying the challenge.\n * @returns A promise that resolves to an array of verification results.\n */\n verifyWalletVerificationChallenge(\n args: VerifyWalletVerificationChallengeParameters,\n ): Promise<VerifyWalletVerificationChallengeResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_verifyWalletVerificationChallenge\",\n params: [args.addressOrObject, args.challengeResponse],\n });\n },\n };\n}\n","/**\n * Types of wallet verification methods supported by the system.\n * Used to identify different verification mechanisms when creating or managing wallet verifications.\n */\nexport enum WalletVerificationType {\n /** PIN code verification method */\n PINCODE = \"PINCODE\",\n /** One-Time Password verification method */\n OTP = \"OTP\",\n /** Secret recovery codes verification method */\n SECRET_CODES = \"SECRET_CODES\",\n}\n\n/**\n * Supported hash algorithms for One-Time Password (OTP) verification.\n * These algorithms determine the cryptographic function used to generate OTP codes.\n */\nexport enum OTPAlgorithm {\n /** SHA-1 hash algorithm */\n SHA1 = \"SHA1\",\n /** SHA-224 hash algorithm */\n SHA224 = \"SHA224\",\n /** SHA-256 hash algorithm */\n SHA256 = \"SHA256\",\n /** SHA-384 hash algorithm */\n SHA384 = \"SHA384\",\n /** SHA-512 hash algorithm */\n SHA512 = \"SHA512\",\n /** SHA3-224 hash algorithm */\n SHA3_224 = \"SHA3-224\",\n /** SHA3-256 hash algorithm */\n SHA3_256 = \"SHA3-256\",\n /** SHA3-384 hash algorithm */\n SHA3_384 = \"SHA3-384\",\n /** SHA3-512 hash algorithm */\n SHA3_512 = \"SHA3-512\",\n}\n","import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport {\n createPublicClient,\n createWalletClient,\n defineChain,\n type HttpTransportConfig,\n http,\n publicActions,\n type Chain as ViemChain,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport * as chains from \"viem/chains\";\nimport { z } from \"zod\";\nimport { createWallet } from \"./custom-actions/create-wallet.action.js\";\nimport { createWalletVerification } from \"./custom-actions/create-wallet-verification.action.js\";\nimport { createWalletVerificationChallenges } from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nimport { deleteWalletVerification } from \"./custom-actions/delete-wallet-verification.action.js\";\nimport { getWalletVerifications } from \"./custom-actions/get-wallet-verifications.action.js\";\nimport { verifyWalletVerificationChallenge } from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n\n// Cache for chain definitions to avoid O(n) lookups and repeated chain creation\nconst chainCache = new Map<string, ViemChain>();\n\n// Cache for public clients to avoid repeated instantiation\nconst publicClientCache = new Map<string, PublicClient<Transport, ViemChain>>();\n\n// Cache for wallet client factories to avoid repeated instantiation\nconst walletClientFactoryCache = new Map<\n string,\n (verificationOptions?: WalletVerificationOptions) => ReturnType<typeof createWalletClient>\n>();\n\n// Helper to create cache key from options\nfunction createCacheKey(options: Partial<ClientOptions>): string {\n // Create a deterministic key from the options that affect client creation\n return JSON.stringify({\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n accessToken: options.accessToken,\n // Note: httpTransportConfig is excluded as it's rarely different and complex to serialize\n });\n}\n\n// Skip validation in production for performance\nconst isProduction = process.env.NODE_ENV === \"production\";\n\n// Helper for conditional validation\nfunction validateOptions<T>(schema: z.ZodSchema<T>, options: unknown): T {\n if (isProduction) {\n // In production, assume options are valid (trust the caller)\n return options as T;\n }\n return validate(schema, options);\n}\n\n/**\n * Schema for the viem client options.\n */\nexport const ClientOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The chain id\n */\n chainId: z.string(),\n /**\n * The chain name\n */\n chainName: z.string(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = Omit<z.infer<typeof ClientOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get a public client. Use this if you need to read from the blockchain.\n * @param options - The options for the public client.\n * @returns The public client. see {@link https://viem.sh/docs/clients/public}\n * @example\n * ```ts\n * import { getPublicClient } from '@settlemint/sdk-viem';\n *\n * const publicClient = getPublicClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the block number\n * const block = await publicClient.getBlockNumber();\n * console.log(block);\n * ```\n */\nexport const getPublicClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validateOptions(ClientOptionsSchema, options);\n\n // Check cache first\n const cacheKey = createCacheKey(validatedOptions);\n const cachedClient = publicClientCache.get(cacheKey);\n if (cachedClient) {\n return cachedClient;\n }\n\n // Pre-compute headers once\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n });\n\n // Create new client\n const client = createPublicClient({\n chain: getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n }),\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n // Cache the client\n publicClientCache.set(cacheKey, client);\n\n return client;\n};\n\n/**\n * The options for the wallet client.\n */\nexport interface WalletVerificationOptions {\n /**\n * The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications.\n */\n verificationId?: string;\n /**\n * The challenge response (used for HD wallets)\n */\n challengeResponse: string;\n}\n\n/**\n * Get a wallet client. Use this if you need to write to the blockchain.\n * @param options - The options for the wallet client.\n * @returns A function that returns a wallet client. The function can be called with verification options for HD wallets. see {@link https://viem.sh/docs/clients/wallet}\n * @example\n * ```ts\n * import { getWalletClient } from '@settlemint/sdk-viem';\n * import { parseAbi } from \"viem\";\n *\n * const walletClient = getWalletClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the chain id\n * const chainId = await walletClient().getChainId();\n * console.log(chainId);\n *\n * // write to the blockchain\n * const transactionHash = await walletClient().writeContract({\n * account: \"0x0000000000000000000000000000000000000000\",\n * address: \"0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2\",\n * abi: parseAbi([\"function mint(uint32 tokenId) nonpayable\"]),\n * functionName: \"mint\",\n * args: [69420],\n * });\n * console.log(transactionHash);\n * ```\n */\nexport const getWalletClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validateOptions(ClientOptionsSchema, options);\n\n // Check cache first for the factory function\n const cacheKey = createCacheKey(validatedOptions);\n const cachedFactory = walletClientFactoryCache.get(cacheKey);\n if (cachedFactory) {\n return cachedFactory;\n }\n\n // Get chain (will be cached internally)\n const chain = getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n });\n\n // Create the factory function\n const walletClientFactory = (verificationOptions?: WalletVerificationOptions) => {\n // Headers need to be computed per verification options\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n \"x-auth-challenge-response\": verificationOptions?.challengeResponse ?? \"\",\n \"x-auth-verification-id\": verificationOptions?.verificationId ?? \"\",\n });\n\n return createWalletClient({\n chain: chain,\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n })\n .extend(publicActions)\n .extend(createWallet)\n .extend(getWalletVerifications)\n .extend(createWalletVerification)\n .extend(deleteWalletVerification)\n .extend(createWalletVerificationChallenges)\n .extend(verifyWalletVerificationChallenge);\n };\n\n // Cache the factory\n walletClientFactoryCache.set(cacheKey, walletClientFactory);\n\n return walletClientFactory;\n};\n\n/**\n * Schema for the viem client options.\n */\nexport const GetChainIdOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated get chain id options.\n */\nexport type GetChainIdOptions = Omit<z.infer<typeof GetChainIdOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get the chain id of a blockchain network.\n * @param options - The options for the public client.\n * @returns The chain id.\n * @example\n * ```ts\n * import { getChainId } from '@settlemint/sdk-viem';\n *\n * const chainId = await getChainId({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n * console.log(chainId);\n * ```\n */\nexport async function getChainId(options: GetChainIdOptions): Promise<number> {\n ensureServer();\n const validatedOptions: GetChainIdOptions = validateOptions(GetChainIdOptionsSchema, options);\n\n // Pre-compute headers\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n });\n\n const client = createPublicClient({\n transport: http(validatedOptions.rpcUrl, {\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n return client.getChainId();\n}\n\n// Create a Map for O(1) chain lookups\nconst knownChainsMap = new Map<string, ViemChain>(Object.values(chains).map((chain) => [chain.id.toString(), chain]));\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n // Check if chain is already cached\n const cacheKey = `${chainId}-${chainName}-${rpcUrl}`;\n const cachedChain = chainCache.get(cacheKey);\n if (cachedChain) {\n return cachedChain;\n }\n\n // O(1) lookup for known chains\n const knownChain = knownChainsMap.get(chainId);\n if (knownChain) {\n chainCache.set(cacheKey, knownChain);\n return knownChain;\n }\n\n // Create custom chain definition\n const customChain = defineChain({\n id: Number(chainId),\n name: chainName,\n rpcUrls: {\n default: {\n http: [rpcUrl],\n },\n },\n nativeCurrency: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n });\n\n // Cache the custom chain\n chainCache.set(cacheKey, customChain);\n return customChain;\n}\n\nexport type {\n CreateWalletParameters,\n CreateWalletResponse,\n WalletInfo,\n} from \"./custom-actions/create-wallet.action.js\";\nexport type {\n CreateWalletVerificationParameters,\n CreateWalletVerificationResponse,\n WalletOTPVerificationInfo,\n WalletPincodeVerificationInfo,\n WalletSecretCodesVerificationInfo,\n WalletVerificationInfo,\n} from \"./custom-actions/create-wallet-verification.action.js\";\nexport type {\n CreateWalletVerificationChallengesParameters,\n CreateWalletVerificationChallengesResponse,\n WalletVerificationChallenge,\n} from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nexport type {\n DeleteWalletVerificationParameters,\n DeleteWalletVerificationResponse,\n} from \"./custom-actions/delete-wallet-verification.action.js\";\nexport type {\n GetWalletVerificationsParameters,\n GetWalletVerificationsResponse,\n WalletVerification,\n} from \"./custom-actions/get-wallet-verifications.action.js\";\nexport { OTPAlgorithm, WalletVerificationType } from \"./custom-actions/types/wallet-verification.enum.js\";\nexport type {\n AddressOrObject,\n VerificationResult,\n VerifyWalletVerificationChallengeParameters,\n VerifyWalletVerificationChallengeResponse,\n} from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n"],"mappings":";;;;;;;;;;;;;;AAgDA,SAAgB,aAAaA,QAAgB;AAC3C,QAAO,EAML,aAAaC,MAA+D;AAC1E,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,YAAY,KAAK,UAAW;EAC3C,EAAC;CACH,EACF;AACF;;;;;;;;;AC+BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,mBAAmB,KAAK,sBAAuB;EAC9D,EAAC;CACH,EACF;AACF;;;;;;;;;AC9DD,SAAgB,mCAAmCC,QAAgB;AACjE,QAAO,EAML,mCACEC,MACqD;AACrD,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,eAAgB;EAC/B,EAAC;CACH,EACF;AACF;;;;;;;;;AC3BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,mBAAmB,KAAK,cAAe;EACtD,EAAC;CACH,EACF;AACF;;;;;;;;;ACND,SAAgB,uBAAuBC,QAAgB;AACrD,QAAO,EAML,uBAAuBC,MAAiF;AACtG,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,K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O;CAI9C,aAAa,6BAA6B,UAAU;CAIpD,QAAQ;CAIR,qBAAqB,EAAE,KAAK,CAAC,UAAU;AACxC,EAAC;;;;;;;;;;;;;;;;AAwBF,eAAsB,WAAWC,SAA6C;CAC5E,cAAc;CACd,MAAMC,mBAAsC,gBAAgB,yBAAyB,QAAQ;CAG7F,MAAM,UAAU,cAAc,kBAAkB,qBAAqB,cAAc,SAAS,EAC1F,gBAAgB,iBAAiB,YAClC,EAAC;CAEF,MAAM,SAAS,mBAAmB,EAChC,WAAW,KAAK,iBAAiB,QAAQ;EACvC,GAAG,iBAAiB;EACpB,cAAc;GACZ,GAAG,kBAAkB,qBAAqB;GAC1C;EACD;CACF,EAAC,CACH,EAAC;AAEF,QAAO,OAAO,YAAY;AAC3B;AAGD,MAAM,iBAAiB,IAAI,IAAuB,OAAO,OAAO,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,UAAU,EAAE,KAAM,EAAC;AAEpH,SAAS,SAAS,EAAE,SAAS,WAAW,QAAiE,EAAa;CAEpH,MAAM,WAAW,GAAG,QAAQ,CAAC,EAAE,UAAU,CAAC,EAAE,QAAQ;CACpD,MAAM,cAAc,WAAW,IAAI,SAAS;AAC5C,KAAI,aAAa;AACf,SAAO;CACR;CAGD,MAAM,aAAa,eAAe,IAAI,QAAQ;AAC9C,KAAI,YAAY;EACd,WAAW,IAAI,UAAU,WAAW;AACpC,SAAO;CACR;CAGD,MAAM,cAAc,YAAY;EAC9B,IAAI,OAAO,QAAQ;EACnB,MAAM;EACN,SAAS,EACP,SAAS,EACP,MAAM,CAAC,MAAO,EACf,EACF;EACD,gBAAgB;GACd,UAAU;GACV,MAAM;GACN,QAAQ;EACT;CACF,EAAC;CAGF,WAAW,IAAI,UAAU,YAAY;AACrC,QAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"viem.js","names":["client: Client","args: CreateWalletParameters","client: Client","args: CreateWalletVerificationParameters","client: Client","args: CreateWalletVerificationChallengesParameters","client: Client","args: DeleteWalletVerificationParameters","client: Client","args: GetWalletVerificationsParameters","client: Client","args: VerifyWalletVerificationChallengeParameters","maxSize: number","key: K","value: V","options: Partial<ClientOptions>","keyObject: Record<string, unknown>","baseHeaders: HeadersInit | undefined","authHeaders: Record<string, string>","options: ClientOptions","validatedOptions: ClientOptions","verificationOptions?: WalletVerificationOptions","options: GetChainIdOptions","validatedOptions: GetChainIdOptions"],"sources":["../../src/custom-actions/create-wallet.action.ts","../../src/custom-actions/create-wallet-verification.action.ts","../../src/custom-actions/create-wallet-verification-challenges.action.ts","../../src/custom-actions/delete-wallet-verification.action.ts","../../src/custom-actions/get-wallet-verifications.action.ts","../../src/custom-actions/verify-wallet-verification-challenge.action.ts","../../src/custom-actions/types/wallet-verification.enum.ts","../../src/viem.ts"],"sourcesContent":["import type { Client } from \"viem\";\n\n/**\n * Information about the wallet to be created.\n */\nexport interface WalletInfo {\n /** The name of the wallet. */\n name: string;\n}\n\n/**\n * Parameters for creating a wallet.\n */\nexport interface CreateWalletParameters {\n /** The unique name of the key vault where the wallet will be created. */\n keyVaultId: string;\n /** Information about the wallet to be created. */\n walletInfo: WalletInfo;\n}\n\n/**\n * Response from creating a wallet.\n */\nexport interface CreateWalletResponse {\n /** The unique identifier of the wallet. */\n id: string;\n /** The name of the wallet. */\n name: string;\n /** The blockchain address of the wallet. */\n address: string;\n /** The HD derivation path used to create the wallet. */\n derivationPath: string;\n}\n\n/**\n * RPC schema for wallet creation.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWallet\";\n Parameters: [keyVaultId: string, walletInfo: WalletInfo];\n ReturnType: CreateWalletResponse[];\n};\n\n/**\n * Creates a wallet action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWallet method.\n */\nexport function createWallet(client: Client) {\n return {\n /**\n * Creates a new wallet in the specified key vault.\n * @param args - The parameters for creating a wallet.\n * @returns A promise that resolves to an array of created wallet responses.\n */\n createWallet(args: CreateWalletParameters): Promise<CreateWalletResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWallet\",\n params: [args.keyVaultId, args.walletInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { OTPAlgorithm, WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Base interface for wallet verification information.\n */\ntype BaseWalletVerificationInfo = {\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n};\n\n/**\n * Information for PIN code verification.\n */\nexport interface WalletPincodeVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.PINCODE;\n /** The PIN code to use for verification. */\n pincode: string;\n}\n\n/**\n * Information for One-Time Password (OTP) verification.\n */\nexport interface WalletOTPVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.OTP;\n /** The hash algorithm to use for OTP generation. */\n algorithm?: OTPAlgorithm;\n /** The number of digits in the OTP code. */\n digits?: number;\n /** The time period in seconds for OTP validity. */\n period?: number;\n /** The issuer of the OTP. */\n issuer?: string;\n}\n\n/**\n * Information for secret recovery codes verification.\n */\nexport interface WalletSecretCodesVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.SECRET_CODES;\n}\n\n/**\n * Union type of all possible wallet verification information types.\n */\nexport type WalletVerificationInfo =\n | WalletPincodeVerificationInfo\n | WalletOTPVerificationInfo\n | WalletSecretCodesVerificationInfo;\n\n/**\n * Parameters for creating a wallet verification.\n */\nexport interface CreateWalletVerificationParameters {\n /** The wallet address for which to create the verification. */\n userWalletAddress: string;\n /** The verification information to create. */\n walletVerificationInfo: WalletVerificationInfo;\n}\n\n/**\n * Response from creating a wallet verification.\n */\nexport interface CreateWalletVerificationResponse {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n /** Additional parameters specific to the verification type. */\n parameters: Record<string, string>;\n}\n\n/**\n * RPC schema for creating a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerification\";\n Parameters: [userWalletAddress: string, walletVerificationInfo: WalletVerificationInfo];\n ReturnType: CreateWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerification method.\n */\nexport function createWalletVerification(client: Client) {\n return {\n /**\n * Creates a new wallet verification.\n * @param args - The parameters for creating the verification.\n * @returns A promise that resolves to an array of created wallet verification responses.\n */\n createWalletVerification(args: CreateWalletVerificationParameters): Promise<CreateWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerification\",\n params: [args.userWalletAddress, args.walletVerificationInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\nimport type { AddressOrObject } from \"./verify-wallet-verification-challenge.action.js\";\n\n/**\n * Parameters for creating wallet verification challenges.\n */\nexport interface CreateWalletVerificationChallengesParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n}\n\n/**\n * Represents a wallet verification challenge.\n */\nexport interface WalletVerificationChallenge {\n /** The unique identifier of the challenge. */\n id: string;\n /** The name of the challenge. */\n name: string;\n /** The type of verification required. */\n verificationType: WalletVerificationType;\n /** The challenge parameters specific to the verification type. */\n challenge: Record<string, string>;\n}\n\n/**\n * Response from creating wallet verification challenges.\n */\nexport type CreateWalletVerificationChallengesResponse = WalletVerificationChallenge[];\n\n/**\n * RPC schema for creating wallet verification challenges.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerificationChallenges\";\n Parameters: [addressOrObject: AddressOrObject];\n ReturnType: CreateWalletVerificationChallengesResponse;\n};\n\n/**\n * Creates a wallet verification challenges action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerificationChallenges method.\n */\nexport function createWalletVerificationChallenges(client: Client) {\n return {\n /**\n * Creates verification challenges for a wallet.\n * @param args - The parameters for creating the challenges.\n * @returns A promise that resolves to an array of wallet verification challenges.\n */\n createWalletVerificationChallenges(\n args: CreateWalletVerificationChallengesParameters,\n ): Promise<CreateWalletVerificationChallengesResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerificationChallenges\",\n params: [args.addressOrObject],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Parameters for deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationParameters {\n /** The wallet address for which to delete the verification. */\n userWalletAddress: string;\n /** The unique identifier of the verification to delete. */\n verificationId: string;\n}\n\n/**\n * Response from deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationResponse {\n /** Whether the deletion was successful. */\n success: boolean;\n}\n\n/**\n * RPC schema for deleting a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_deleteWalletVerification\";\n Parameters: [userWalletAddress: string, verificationId: string];\n ReturnType: DeleteWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification deletion action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a deleteWalletVerification method.\n */\nexport function deleteWalletVerification(client: Client) {\n return {\n /**\n * Deletes a wallet verification.\n * @param args - The parameters for deleting the verification.\n * @returns A promise that resolves to an array of deletion results.\n */\n deleteWalletVerification(args: DeleteWalletVerificationParameters): Promise<DeleteWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_deleteWalletVerification\",\n params: [args.userWalletAddress, args.verificationId],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Parameters for getting wallet verifications.\n */\nexport interface GetWalletVerificationsParameters {\n /** The wallet address for which to fetch verifications. */\n userWalletAddress: string;\n}\n\n/**\n * Represents a wallet verification.\n */\nexport interface WalletVerification {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n}\n\n/**\n * Response from getting wallet verifications.\n */\nexport type GetWalletVerificationsResponse = WalletVerification[];\n\n/**\n * RPC schema for getting wallet verifications.\n */\ntype WalletRpcSchema = {\n Method: \"user_walletVerifications\";\n Parameters: [userWalletAddress: string];\n ReturnType: GetWalletVerificationsResponse;\n};\n\n/**\n * Creates a wallet verifications retrieval action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a getWalletVerifications method.\n */\nexport function getWalletVerifications(client: Client) {\n return {\n /**\n * Gets all verifications for a wallet.\n * @param args - The parameters for getting the verifications.\n * @returns A promise that resolves to an array of wallet verifications.\n */\n getWalletVerifications(args: GetWalletVerificationsParameters): Promise<GetWalletVerificationsResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_walletVerifications\",\n params: [args.userWalletAddress],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Represents either a wallet address string or an object containing wallet address and optional verification ID.\n */\nexport type AddressOrObject =\n | string\n | {\n userWalletAddress: string;\n verificationId?: string;\n };\n\n/**\n * Parameters for verifying a wallet verification challenge.\n */\nexport interface VerifyWalletVerificationChallengeParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n /** The response to the verification challenge. */\n challengeResponse: string;\n}\n\n/**\n * Result of a wallet verification challenge.\n */\nexport interface VerificationResult {\n /** Whether the verification was successful. */\n verified: boolean;\n}\n\n/**\n * Response from verifying a wallet verification challenge.\n */\nexport type VerifyWalletVerificationChallengeResponse = VerificationResult[];\n\n/**\n * RPC schema for wallet verification challenge verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_verifyWalletVerificationChallenge\";\n Parameters: [addressOrObject: AddressOrObject, challengeResponse: string];\n ReturnType: VerifyWalletVerificationChallengeResponse;\n};\n\n/**\n * Creates a wallet verification challenge verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a verifyWalletVerificationChallenge method.\n */\nexport function verifyWalletVerificationChallenge(client: Client) {\n return {\n /**\n * Verifies a wallet verification challenge.\n * @param args - The parameters for verifying the challenge.\n * @returns A promise that resolves to an array of verification results.\n */\n verifyWalletVerificationChallenge(\n args: VerifyWalletVerificationChallengeParameters,\n ): Promise<VerifyWalletVerificationChallengeResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_verifyWalletVerificationChallenge\",\n params: [args.addressOrObject, args.challengeResponse],\n });\n },\n };\n}\n","/**\n * Types of wallet verification methods supported by the system.\n * Used to identify different verification mechanisms when creating or managing wallet verifications.\n */\nexport enum WalletVerificationType {\n /** PIN code verification method */\n PINCODE = \"PINCODE\",\n /** One-Time Password verification method */\n OTP = \"OTP\",\n /** Secret recovery codes verification method */\n SECRET_CODES = \"SECRET_CODES\",\n}\n\n/**\n * Supported hash algorithms for One-Time Password (OTP) verification.\n * These algorithms determine the cryptographic function used to generate OTP codes.\n */\nexport enum OTPAlgorithm {\n /** SHA-1 hash algorithm */\n SHA1 = \"SHA1\",\n /** SHA-224 hash algorithm */\n SHA224 = \"SHA224\",\n /** SHA-256 hash algorithm */\n SHA256 = \"SHA256\",\n /** SHA-384 hash algorithm */\n SHA384 = \"SHA384\",\n /** SHA-512 hash algorithm */\n SHA512 = \"SHA512\",\n /** SHA3-224 hash algorithm */\n SHA3_224 = \"SHA3-224\",\n /** SHA3-256 hash algorithm */\n SHA3_256 = \"SHA3-256\",\n /** SHA3-384 hash algorithm */\n SHA3_384 = \"SHA3-384\",\n /** SHA3-512 hash algorithm */\n SHA3_512 = \"SHA3-512\",\n}\n","import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport {\n createPublicClient,\n createWalletClient,\n defineChain,\n type HttpTransportConfig,\n http,\n publicActions,\n type Chain as ViemChain,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport * as chains from \"viem/chains\";\nimport { z } from \"zod\";\nimport { createWallet } from \"./custom-actions/create-wallet.action.js\";\nimport { createWalletVerification } from \"./custom-actions/create-wallet-verification.action.js\";\nimport { createWalletVerificationChallenges } from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nimport { deleteWalletVerification } from \"./custom-actions/delete-wallet-verification.action.js\";\nimport { getWalletVerifications } from \"./custom-actions/get-wallet-verifications.action.js\";\nimport { verifyWalletVerificationChallenge } from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n\n// Simple LRU cache implementation\nclass LRUCache<K, V> {\n private cache = new Map<K, V>();\n private readonly maxSize: number;\n\n constructor(maxSize: number) {\n this.maxSize = maxSize;\n }\n\n get(key: K): V | undefined {\n const value = this.cache.get(key);\n if (value !== undefined) {\n // Move to end (most recently used)\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n set(key: K, value: V): void {\n // Remove key if it exists (to update position)\n this.cache.delete(key);\n\n // Check size limit\n if (this.cache.size >= this.maxSize) {\n // Remove least recently used (first item)\n const firstKey = this.cache.keys().next().value;\n if (firstKey !== undefined) {\n this.cache.delete(firstKey);\n }\n }\n\n this.cache.set(key, value);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n// Cache for chain definitions with size limit\nconst chainCache = new LRUCache<string, ViemChain>(100);\n\n// Cache for public clients with size limit\nconst publicClientCache = new LRUCache<string, PublicClient<Transport, ViemChain>>(50);\n\n// Cache for wallet client factories with size limit\nconst walletClientFactoryCache = new LRUCache<\n string,\n (verificationOptions?: WalletVerificationOptions) => ReturnType<typeof createWalletClient>\n>(50);\n\n// Helper to create robust cache key from options\nfunction createCacheKey(options: Partial<ClientOptions>): string {\n // Create a deterministic key by sorting properties\n const keyObject: Record<string, unknown> = {};\n\n // Add properties in sorted order to ensure consistency\n const keys = [\"chainId\", \"chainName\", \"rpcUrl\", \"accessToken\"] as const;\n for (const key of keys) {\n const value = options[key as keyof ClientOptions];\n // Only include defined values\n if (value !== undefined) {\n keyObject[key] = value;\n }\n }\n\n // Use sorted keys for consistent stringification\n return JSON.stringify(keyObject, Object.keys(keyObject).sort());\n}\n\n// Shared utility for building headers\nfunction buildHeaders(baseHeaders: HeadersInit | undefined, authHeaders: Record<string, string>): HeadersInit {\n return appendHeaders(baseHeaders, authHeaders);\n}\n\n/**\n * Schema for the viem client options.\n */\nexport const ClientOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The chain id\n */\n chainId: z.string(),\n /**\n * The chain name\n */\n chainName: z.string(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = Omit<z.infer<typeof ClientOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get a public client. Use this if you need to read from the blockchain.\n * @param options - The options for the public client.\n * @returns The public client. see {@link https://viem.sh/docs/clients/public}\n * @example\n * ```ts\n * import { getPublicClient } from '@settlemint/sdk-viem';\n *\n * const publicClient = getPublicClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the block number\n * const block = await publicClient.getBlockNumber();\n * console.log(block);\n * ```\n */\nexport const getPublicClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validate(ClientOptionsSchema, options);\n\n // Check cache first\n const cacheKey = createCacheKey(validatedOptions);\n const cachedClient = publicClientCache.get(cacheKey);\n if (cachedClient) {\n return cachedClient;\n }\n\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n });\n\n // Create new client\n const client = createPublicClient({\n chain: getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n }),\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n // Cache the client\n publicClientCache.set(cacheKey, client);\n\n return client;\n};\n\n/**\n * The options for the wallet client.\n */\nexport interface WalletVerificationOptions {\n /**\n * The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications.\n */\n verificationId?: string;\n /**\n * The challenge response (used for HD wallets)\n */\n challengeResponse: string;\n}\n\n/**\n * Get a wallet client. Use this if you need to write to the blockchain.\n * @param options - The options for the wallet client.\n * @returns A function that returns a wallet client. The function can be called with verification options for HD wallets. see {@link https://viem.sh/docs/clients/wallet}\n * @example\n * ```ts\n * import { getWalletClient } from '@settlemint/sdk-viem';\n * import { parseAbi } from \"viem\";\n *\n * const walletClient = getWalletClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the chain id\n * const chainId = await walletClient().getChainId();\n * console.log(chainId);\n *\n * // write to the blockchain\n * const transactionHash = await walletClient().writeContract({\n * account: \"0x0000000000000000000000000000000000000000\",\n * address: \"0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2\",\n * abi: parseAbi([\"function mint(uint32 tokenId) nonpayable\"]),\n * functionName: \"mint\",\n * args: [69420],\n * });\n * console.log(transactionHash);\n * ```\n */\nexport const getWalletClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validate(ClientOptionsSchema, options);\n\n // Check cache first for the factory function\n const cacheKey = createCacheKey(validatedOptions);\n const cachedFactory = walletClientFactoryCache.get(cacheKey);\n if (cachedFactory) {\n return cachedFactory;\n }\n\n // Get chain (will be cached internally)\n const chain = getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n });\n\n // Create the factory function\n const walletClientFactory = (verificationOptions?: WalletVerificationOptions) => {\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n \"x-auth-challenge-response\": verificationOptions?.challengeResponse ?? \"\",\n \"x-auth-verification-id\": verificationOptions?.verificationId ?? \"\",\n });\n\n return createWalletClient({\n chain: chain,\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n })\n .extend(publicActions)\n .extend(createWallet)\n .extend(getWalletVerifications)\n .extend(createWalletVerification)\n .extend(deleteWalletVerification)\n .extend(createWalletVerificationChallenges)\n .extend(verifyWalletVerificationChallenge);\n };\n\n // Cache the factory\n walletClientFactoryCache.set(cacheKey, walletClientFactory);\n\n return walletClientFactory;\n};\n\n/**\n * Schema for the viem client options.\n */\nexport const GetChainIdOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated get chain id options.\n */\nexport type GetChainIdOptions = Omit<z.infer<typeof GetChainIdOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get the chain id of a blockchain network.\n * @param options - The options for the public client.\n * @returns The chain id.\n * @example\n * ```ts\n * import { getChainId } from '@settlemint/sdk-viem';\n *\n * const chainId = await getChainId({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n * console.log(chainId);\n * ```\n */\nexport async function getChainId(options: GetChainIdOptions): Promise<number> {\n ensureServer();\n const validatedOptions: GetChainIdOptions = validate(GetChainIdOptionsSchema, options);\n\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n });\n\n const client = createPublicClient({\n transport: http(validatedOptions.rpcUrl, {\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n return client.getChainId();\n}\n\n// Create a Map for O(1) chain lookups\nconst knownChainsMap = new Map<string, ViemChain>(Object.values(chains).map((chain) => [chain.id.toString(), chain]));\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n // Create deterministic cache key\n const cacheKey = JSON.stringify({ chainId, chainName, rpcUrl }, [\"chainId\", \"chainName\", \"rpcUrl\"]);\n\n // Check if chain is already cached\n const cachedChain = chainCache.get(cacheKey);\n if (cachedChain) {\n return cachedChain;\n }\n\n // O(1) lookup for known chains\n const knownChain = knownChainsMap.get(chainId);\n if (knownChain) {\n chainCache.set(cacheKey, knownChain);\n return knownChain;\n }\n\n // Create custom chain definition\n const customChain = defineChain({\n id: Number(chainId),\n name: chainName,\n rpcUrls: {\n default: {\n http: [rpcUrl],\n },\n },\n nativeCurrency: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n });\n\n // Cache the custom chain\n chainCache.set(cacheKey, customChain);\n return customChain;\n}\n\nexport type {\n CreateWalletParameters,\n CreateWalletResponse,\n WalletInfo,\n} from \"./custom-actions/create-wallet.action.js\";\nexport type {\n CreateWalletVerificationParameters,\n CreateWalletVerificationResponse,\n WalletOTPVerificationInfo,\n WalletPincodeVerificationInfo,\n WalletSecretCodesVerificationInfo,\n WalletVerificationInfo,\n} from \"./custom-actions/create-wallet-verification.action.js\";\nexport type {\n CreateWalletVerificationChallengesParameters,\n CreateWalletVerificationChallengesResponse,\n WalletVerificationChallenge,\n} from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nexport type {\n DeleteWalletVerificationParameters,\n DeleteWalletVerificationResponse,\n} from \"./custom-actions/delete-wallet-verification.action.js\";\nexport type {\n GetWalletVerificationsParameters,\n GetWalletVerificationsResponse,\n WalletVerification,\n} from \"./custom-actions/get-wallet-verifications.action.js\";\nexport { OTPAlgorithm, WalletVerificationType } from \"./custom-actions/types/wallet-verification.enum.js\";\nexport type {\n AddressOrObject,\n VerificationResult,\n VerifyWalletVerificationChallengeParameters,\n VerifyWalletVerificationChallengeResponse,\n} from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n"],"mappings":";;;;;;;;;;;;;;AAgDA,SAAgB,aAAaA,QAAgB;AAC3C,QAAO,EAML,aAAaC,MAA+D;AAC1E,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,YAAY,KAAK,UAAW;EAC3C,EAAC;CACH,EACF;AACF;;;;;;;;;AC+BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,mBAAmB,KAAK,sBAAuB;EAC9D,EAAC;CACH,EACF;AACF;;;;;;;;;AC9DD,SAAgB,mCAAmCC,QAAgB;AACjE,QAAO,EAML,mCACEC,MACqD;AACrD,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,eAAgB;EAC/B,EAAC;CACH,EACF;AACF;;;;;;;;;AC3BD,SAAgB,yBAAyBC,QAAgB;AACv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ACzF,gBAAgB,iBAAiB,eAAe,GACjD,EAAC;CAEF,MAAM,SAAS,mBAAmB,EAChC,WAAW,KAAK,iBAAiB,QAAQ;EACvC,GAAG,iBAAiB;EACpB,cAAc;GACZ,GAAG,kBAAkB,qBAAqB;GAC1C;EACD;CACF,EAAC,CACH,EAAC;AAEF,QAAO,OAAO,YAAY;AAC3B;AAGD,MAAM,iBAAiB,IAAI,IAAuB,OAAO,OAAO,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,UAAU,EAAE,KAAM,EAAC;AAEpH,SAAS,SAAS,EAAE,SAAS,WAAW,QAAiE,EAAa;CAEpH,MAAM,WAAW,KAAK,UAAU;EAAE;EAAS;EAAW;CAAQ,GAAE;EAAC;EAAW;EAAa;CAAS,EAAC;CAGnG,MAAM,cAAc,WAAW,IAAI,SAAS;AAC5C,KAAI,aAAa;AACf,SAAO;CACR;CAGD,MAAM,aAAa,eAAe,IAAI,QAAQ;AAC9C,KAAI,YAAY;EACd,WAAW,IAAI,UAAU,WAAW;AACpC,SAAO;CACR;CAGD,MAAM,cAAc,YAAY;EAC9B,IAAI,OAAO,QAAQ;EACnB,MAAM;EACN,SAAS,EACP,SAAS,EACP,MAAM,CAAC,MAAO,EACf,EACF;EACD,gBAAgB;GACd,UAAU;GACV,MAAM;GACN,QAAQ;EACT;CACF,EAAC;CAGF,WAAW,IAAI,UAAU,YAAY;AACrC,QAAO;AACR"}
|
package/dist/viem.cjs
CHANGED
|
@@ -167,23 +167,55 @@ let OTPAlgorithm = /* @__PURE__ */ function(OTPAlgorithm$1) {
|
|
|
167
167
|
|
|
168
168
|
//#endregion
|
|
169
169
|
//#region src/viem.ts
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
var LRUCache = class {
|
|
171
|
+
cache = new Map();
|
|
172
|
+
maxSize;
|
|
173
|
+
constructor(maxSize) {
|
|
174
|
+
this.maxSize = maxSize;
|
|
175
|
+
}
|
|
176
|
+
get(key) {
|
|
177
|
+
const value = this.cache.get(key);
|
|
178
|
+
if (value !== undefined) {
|
|
179
|
+
this.cache.delete(key);
|
|
180
|
+
this.cache.set(key, value);
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
set(key, value) {
|
|
185
|
+
this.cache.delete(key);
|
|
186
|
+
if (this.cache.size >= this.maxSize) {
|
|
187
|
+
const firstKey = this.cache.keys().next().value;
|
|
188
|
+
if (firstKey !== undefined) {
|
|
189
|
+
this.cache.delete(firstKey);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
this.cache.set(key, value);
|
|
193
|
+
}
|
|
194
|
+
clear() {
|
|
195
|
+
this.cache.clear();
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const chainCache = new LRUCache(100);
|
|
199
|
+
const publicClientCache = new LRUCache(50);
|
|
200
|
+
const walletClientFactoryCache = new LRUCache(50);
|
|
173
201
|
function createCacheKey(options) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
202
|
+
const keyObject = {};
|
|
203
|
+
const keys = [
|
|
204
|
+
"chainId",
|
|
205
|
+
"chainName",
|
|
206
|
+
"rpcUrl",
|
|
207
|
+
"accessToken"
|
|
208
|
+
];
|
|
209
|
+
for (const key of keys) {
|
|
210
|
+
const value = options[key];
|
|
211
|
+
if (value !== undefined) {
|
|
212
|
+
keyObject[key] = value;
|
|
213
|
+
}
|
|
185
214
|
}
|
|
186
|
-
return (
|
|
215
|
+
return JSON.stringify(keyObject, Object.keys(keyObject).sort());
|
|
216
|
+
}
|
|
217
|
+
function buildHeaders(baseHeaders, authHeaders) {
|
|
218
|
+
return (0, __settlemint_sdk_utils_http.appendHeaders)(baseHeaders, authHeaders);
|
|
187
219
|
}
|
|
188
220
|
/**
|
|
189
221
|
* Schema for the viem client options.
|
|
@@ -217,13 +249,13 @@ const ClientOptionsSchema = zod.z.object({
|
|
|
217
249
|
*/
|
|
218
250
|
const getPublicClient = (options) => {
|
|
219
251
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
220
|
-
const validatedOptions =
|
|
252
|
+
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
221
253
|
const cacheKey = createCacheKey(validatedOptions);
|
|
222
254
|
const cachedClient = publicClientCache.get(cacheKey);
|
|
223
255
|
if (cachedClient) {
|
|
224
256
|
return cachedClient;
|
|
225
257
|
}
|
|
226
|
-
const headers = (
|
|
258
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken || "" });
|
|
227
259
|
const client = (0, viem.createPublicClient)({
|
|
228
260
|
chain: getChain({
|
|
229
261
|
chainId: validatedOptions.chainId,
|
|
@@ -277,7 +309,7 @@ const getPublicClient = (options) => {
|
|
|
277
309
|
*/
|
|
278
310
|
const getWalletClient = (options) => {
|
|
279
311
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
280
|
-
const validatedOptions =
|
|
312
|
+
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
281
313
|
const cacheKey = createCacheKey(validatedOptions);
|
|
282
314
|
const cachedFactory = walletClientFactoryCache.get(cacheKey);
|
|
283
315
|
if (cachedFactory) {
|
|
@@ -289,8 +321,8 @@ const getWalletClient = (options) => {
|
|
|
289
321
|
rpcUrl: validatedOptions.rpcUrl
|
|
290
322
|
});
|
|
291
323
|
const walletClientFactory = (verificationOptions) => {
|
|
292
|
-
const headers = (
|
|
293
|
-
"x-auth-token": validatedOptions.accessToken,
|
|
324
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {
|
|
325
|
+
"x-auth-token": validatedOptions.accessToken || "",
|
|
294
326
|
"x-auth-challenge-response": verificationOptions?.challengeResponse ?? "",
|
|
295
327
|
"x-auth-verification-id": verificationOptions?.verificationId ?? ""
|
|
296
328
|
});
|
|
@@ -336,8 +368,8 @@ const GetChainIdOptionsSchema = zod.z.object({
|
|
|
336
368
|
*/
|
|
337
369
|
async function getChainId(options) {
|
|
338
370
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
339
|
-
const validatedOptions =
|
|
340
|
-
const headers = (
|
|
371
|
+
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(GetChainIdOptionsSchema, options);
|
|
372
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken || "" });
|
|
341
373
|
const client = (0, viem.createPublicClient)({ transport: (0, viem.http)(validatedOptions.rpcUrl, {
|
|
342
374
|
...validatedOptions.httpTransportConfig,
|
|
343
375
|
fetchOptions: {
|
|
@@ -349,7 +381,15 @@ async function getChainId(options) {
|
|
|
349
381
|
}
|
|
350
382
|
const knownChainsMap = new Map(Object.values(viem_chains).map((chain) => [chain.id.toString(), chain]));
|
|
351
383
|
function getChain({ chainId, chainName, rpcUrl }) {
|
|
352
|
-
const cacheKey =
|
|
384
|
+
const cacheKey = JSON.stringify({
|
|
385
|
+
chainId,
|
|
386
|
+
chainName,
|
|
387
|
+
rpcUrl
|
|
388
|
+
}, [
|
|
389
|
+
"chainId",
|
|
390
|
+
"chainName",
|
|
391
|
+
"rpcUrl"
|
|
392
|
+
]);
|
|
353
393
|
const cachedChain = chainCache.get(cacheKey);
|
|
354
394
|
if (cachedChain) {
|
|
355
395
|
return cachedChain;
|
package/dist/viem.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viem.cjs","names":["client: Client","args: CreateWalletParameters","client: Client","args: CreateWalletVerificationParameters","client: Client","args: CreateWalletVerificationChallengesParameters","client: Client","args: DeleteWalletVerificationParameters","client: Client","args: GetWalletVerificationsParameters","client: Client","args: VerifyWalletVerificationChallengeParameters","options: Partial<ClientOptions>","schema: z.ZodSchema<T>","options: unknown","z","ApplicationAccessTokenSchema","UrlOrPathSchema","options: ClientOptions","validatedOptions: ClientOptions","verificationOptions?: WalletVerificationOptions","publicActions","options: GetChainIdOptions","validatedOptions: GetChainIdOptions","chains"],"sources":["../src/custom-actions/create-wallet.action.ts","../src/custom-actions/create-wallet-verification.action.ts","../src/custom-actions/create-wallet-verification-challenges.action.ts","../src/custom-actions/delete-wallet-verification.action.ts","../src/custom-actions/get-wallet-verifications.action.ts","../src/custom-actions/verify-wallet-verification-challenge.action.ts","../src/custom-actions/types/wallet-verification.enum.ts","../src/viem.ts"],"sourcesContent":["import type { Client } from \"viem\";\n\n/**\n * Information about the wallet to be created.\n */\nexport interface WalletInfo {\n /** The name of the wallet. */\n name: string;\n}\n\n/**\n * Parameters for creating a wallet.\n */\nexport interface CreateWalletParameters {\n /** The unique name of the key vault where the wallet will be created. */\n keyVaultId: string;\n /** Information about the wallet to be created. */\n walletInfo: WalletInfo;\n}\n\n/**\n * Response from creating a wallet.\n */\nexport interface CreateWalletResponse {\n /** The unique identifier of the wallet. */\n id: string;\n /** The name of the wallet. */\n name: string;\n /** The blockchain address of the wallet. */\n address: string;\n /** The HD derivation path used to create the wallet. */\n derivationPath: string;\n}\n\n/**\n * RPC schema for wallet creation.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWallet\";\n Parameters: [keyVaultId: string, walletInfo: WalletInfo];\n ReturnType: CreateWalletResponse[];\n};\n\n/**\n * Creates a wallet action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWallet method.\n */\nexport function createWallet(client: Client) {\n return {\n /**\n * Creates a new wallet in the specified key vault.\n * @param args - The parameters for creating a wallet.\n * @returns A promise that resolves to an array of created wallet responses.\n */\n createWallet(args: CreateWalletParameters): Promise<CreateWalletResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWallet\",\n params: [args.keyVaultId, args.walletInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { OTPAlgorithm, WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Base interface for wallet verification information.\n */\ntype BaseWalletVerificationInfo = {\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n};\n\n/**\n * Information for PIN code verification.\n */\nexport interface WalletPincodeVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.PINCODE;\n /** The PIN code to use for verification. */\n pincode: string;\n}\n\n/**\n * Information for One-Time Password (OTP) verification.\n */\nexport interface WalletOTPVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.OTP;\n /** The hash algorithm to use for OTP generation. */\n algorithm?: OTPAlgorithm;\n /** The number of digits in the OTP code. */\n digits?: number;\n /** The time period in seconds for OTP validity. */\n period?: number;\n /** The issuer of the OTP. */\n issuer?: string;\n}\n\n/**\n * Information for secret recovery codes verification.\n */\nexport interface WalletSecretCodesVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.SECRET_CODES;\n}\n\n/**\n * Union type of all possible wallet verification information types.\n */\nexport type WalletVerificationInfo =\n | WalletPincodeVerificationInfo\n | WalletOTPVerificationInfo\n | WalletSecretCodesVerificationInfo;\n\n/**\n * Parameters for creating a wallet verification.\n */\nexport interface CreateWalletVerificationParameters {\n /** The wallet address for which to create the verification. */\n userWalletAddress: string;\n /** The verification information to create. */\n walletVerificationInfo: WalletVerificationInfo;\n}\n\n/**\n * Response from creating a wallet verification.\n */\nexport interface CreateWalletVerificationResponse {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n /** Additional parameters specific to the verification type. */\n parameters: Record<string, string>;\n}\n\n/**\n * RPC schema for creating a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerification\";\n Parameters: [userWalletAddress: string, walletVerificationInfo: WalletVerificationInfo];\n ReturnType: CreateWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerification method.\n */\nexport function createWalletVerification(client: Client) {\n return {\n /**\n * Creates a new wallet verification.\n * @param args - The parameters for creating the verification.\n * @returns A promise that resolves to an array of created wallet verification responses.\n */\n createWalletVerification(args: CreateWalletVerificationParameters): Promise<CreateWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerification\",\n params: [args.userWalletAddress, args.walletVerificationInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\nimport type { AddressOrObject } from \"./verify-wallet-verification-challenge.action.js\";\n\n/**\n * Parameters for creating wallet verification challenges.\n */\nexport interface CreateWalletVerificationChallengesParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n}\n\n/**\n * Represents a wallet verification challenge.\n */\nexport interface WalletVerificationChallenge {\n /** The unique identifier of the challenge. */\n id: string;\n /** The name of the challenge. */\n name: string;\n /** The type of verification required. */\n verificationType: WalletVerificationType;\n /** The challenge parameters specific to the verification type. */\n challenge: Record<string, string>;\n}\n\n/**\n * Response from creating wallet verification challenges.\n */\nexport type CreateWalletVerificationChallengesResponse = WalletVerificationChallenge[];\n\n/**\n * RPC schema for creating wallet verification challenges.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerificationChallenges\";\n Parameters: [addressOrObject: AddressOrObject];\n ReturnType: CreateWalletVerificationChallengesResponse;\n};\n\n/**\n * Creates a wallet verification challenges action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerificationChallenges method.\n */\nexport function createWalletVerificationChallenges(client: Client) {\n return {\n /**\n * Creates verification challenges for a wallet.\n * @param args - The parameters for creating the challenges.\n * @returns A promise that resolves to an array of wallet verification challenges.\n */\n createWalletVerificationChallenges(\n args: CreateWalletVerificationChallengesParameters,\n ): Promise<CreateWalletVerificationChallengesResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerificationChallenges\",\n params: [args.addressOrObject],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Parameters for deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationParameters {\n /** The wallet address for which to delete the verification. */\n userWalletAddress: string;\n /** The unique identifier of the verification to delete. */\n verificationId: string;\n}\n\n/**\n * Response from deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationResponse {\n /** Whether the deletion was successful. */\n success: boolean;\n}\n\n/**\n * RPC schema for deleting a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_deleteWalletVerification\";\n Parameters: [userWalletAddress: string, verificationId: string];\n ReturnType: DeleteWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification deletion action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a deleteWalletVerification method.\n */\nexport function deleteWalletVerification(client: Client) {\n return {\n /**\n * Deletes a wallet verification.\n * @param args - The parameters for deleting the verification.\n * @returns A promise that resolves to an array of deletion results.\n */\n deleteWalletVerification(args: DeleteWalletVerificationParameters): Promise<DeleteWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_deleteWalletVerification\",\n params: [args.userWalletAddress, args.verificationId],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Parameters for getting wallet verifications.\n */\nexport interface GetWalletVerificationsParameters {\n /** The wallet address for which to fetch verifications. */\n userWalletAddress: string;\n}\n\n/**\n * Represents a wallet verification.\n */\nexport interface WalletVerification {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n}\n\n/**\n * Response from getting wallet verifications.\n */\nexport type GetWalletVerificationsResponse = WalletVerification[];\n\n/**\n * RPC schema for getting wallet verifications.\n */\ntype WalletRpcSchema = {\n Method: \"user_walletVerifications\";\n Parameters: [userWalletAddress: string];\n ReturnType: GetWalletVerificationsResponse;\n};\n\n/**\n * Creates a wallet verifications retrieval action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a getWalletVerifications method.\n */\nexport function getWalletVerifications(client: Client) {\n return {\n /**\n * Gets all verifications for a wallet.\n * @param args - The parameters for getting the verifications.\n * @returns A promise that resolves to an array of wallet verifications.\n */\n getWalletVerifications(args: GetWalletVerificationsParameters): Promise<GetWalletVerificationsResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_walletVerifications\",\n params: [args.userWalletAddress],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Represents either a wallet address string or an object containing wallet address and optional verification ID.\n */\nexport type AddressOrObject =\n | string\n | {\n userWalletAddress: string;\n verificationId?: string;\n };\n\n/**\n * Parameters for verifying a wallet verification challenge.\n */\nexport interface VerifyWalletVerificationChallengeParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n /** The response to the verification challenge. */\n challengeResponse: string;\n}\n\n/**\n * Result of a wallet verification challenge.\n */\nexport interface VerificationResult {\n /** Whether the verification was successful. */\n verified: boolean;\n}\n\n/**\n * Response from verifying a wallet verification challenge.\n */\nexport type VerifyWalletVerificationChallengeResponse = VerificationResult[];\n\n/**\n * RPC schema for wallet verification challenge verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_verifyWalletVerificationChallenge\";\n Parameters: [addressOrObject: AddressOrObject, challengeResponse: string];\n ReturnType: VerifyWalletVerificationChallengeResponse;\n};\n\n/**\n * Creates a wallet verification challenge verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a verifyWalletVerificationChallenge method.\n */\nexport function verifyWalletVerificationChallenge(client: Client) {\n return {\n /**\n * Verifies a wallet verification challenge.\n * @param args - The parameters for verifying the challenge.\n * @returns A promise that resolves to an array of verification results.\n */\n verifyWalletVerificationChallenge(\n args: VerifyWalletVerificationChallengeParameters,\n ): Promise<VerifyWalletVerificationChallengeResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_verifyWalletVerificationChallenge\",\n params: [args.addressOrObject, args.challengeResponse],\n });\n },\n };\n}\n","/**\n * Types of wallet verification methods supported by the system.\n * Used to identify different verification mechanisms when creating or managing wallet verifications.\n */\nexport enum WalletVerificationType {\n /** PIN code verification method */\n PINCODE = \"PINCODE\",\n /** One-Time Password verification method */\n OTP = \"OTP\",\n /** Secret recovery codes verification method */\n SECRET_CODES = \"SECRET_CODES\",\n}\n\n/**\n * Supported hash algorithms for One-Time Password (OTP) verification.\n * These algorithms determine the cryptographic function used to generate OTP codes.\n */\nexport enum OTPAlgorithm {\n /** SHA-1 hash algorithm */\n SHA1 = \"SHA1\",\n /** SHA-224 hash algorithm */\n SHA224 = \"SHA224\",\n /** SHA-256 hash algorithm */\n SHA256 = \"SHA256\",\n /** SHA-384 hash algorithm */\n SHA384 = \"SHA384\",\n /** SHA-512 hash algorithm */\n SHA512 = \"SHA512\",\n /** SHA3-224 hash algorithm */\n SHA3_224 = \"SHA3-224\",\n /** SHA3-256 hash algorithm */\n SHA3_256 = \"SHA3-256\",\n /** SHA3-384 hash algorithm */\n SHA3_384 = \"SHA3-384\",\n /** SHA3-512 hash algorithm */\n SHA3_512 = \"SHA3-512\",\n}\n","import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport {\n createPublicClient,\n createWalletClient,\n defineChain,\n type HttpTransportConfig,\n http,\n publicActions,\n type Chain as ViemChain,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport * as chains from \"viem/chains\";\nimport { z } from \"zod\";\nimport { createWallet } from \"./custom-actions/create-wallet.action.js\";\nimport { createWalletVerification } from \"./custom-actions/create-wallet-verification.action.js\";\nimport { createWalletVerificationChallenges } from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nimport { deleteWalletVerification } from \"./custom-actions/delete-wallet-verification.action.js\";\nimport { getWalletVerifications } from \"./custom-actions/get-wallet-verifications.action.js\";\nimport { verifyWalletVerificationChallenge } from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n\n// Cache for chain definitions to avoid O(n) lookups and repeated chain creation\nconst chainCache = new Map<string, ViemChain>();\n\n// Cache for public clients to avoid repeated instantiation\nconst publicClientCache = new Map<string, PublicClient<Transport, ViemChain>>();\n\n// Cache for wallet client factories to avoid repeated instantiation\nconst walletClientFactoryCache = new Map<\n string,\n (verificationOptions?: WalletVerificationOptions) => ReturnType<typeof createWalletClient>\n>();\n\n// Helper to create cache key from options\nfunction createCacheKey(options: Partial<ClientOptions>): string {\n // Create a deterministic key from the options that affect client creation\n return JSON.stringify({\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n accessToken: options.accessToken,\n // Note: httpTransportConfig is excluded as it's rarely different and complex to serialize\n });\n}\n\n// Skip validation in production for performance\nconst isProduction = process.env.NODE_ENV === \"production\";\n\n// Helper for conditional validation\nfunction validateOptions<T>(schema: z.ZodSchema<T>, options: unknown): T {\n if (isProduction) {\n // In production, assume options are valid (trust the caller)\n return options as T;\n }\n return validate(schema, options);\n}\n\n/**\n * Schema for the viem client options.\n */\nexport const ClientOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The chain id\n */\n chainId: z.string(),\n /**\n * The chain name\n */\n chainName: z.string(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = Omit<z.infer<typeof ClientOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get a public client. Use this if you need to read from the blockchain.\n * @param options - The options for the public client.\n * @returns The public client. see {@link https://viem.sh/docs/clients/public}\n * @example\n * ```ts\n * import { getPublicClient } from '@settlemint/sdk-viem';\n *\n * const publicClient = getPublicClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the block number\n * const block = await publicClient.getBlockNumber();\n * console.log(block);\n * ```\n */\nexport const getPublicClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validateOptions(ClientOptionsSchema, options);\n\n // Check cache first\n const cacheKey = createCacheKey(validatedOptions);\n const cachedClient = publicClientCache.get(cacheKey);\n if (cachedClient) {\n return cachedClient;\n }\n\n // Pre-compute headers once\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n });\n\n // Create new client\n const client = createPublicClient({\n chain: getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n }),\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n // Cache the client\n publicClientCache.set(cacheKey, client);\n\n return client;\n};\n\n/**\n * The options for the wallet client.\n */\nexport interface WalletVerificationOptions {\n /**\n * The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications.\n */\n verificationId?: string;\n /**\n * The challenge response (used for HD wallets)\n */\n challengeResponse: string;\n}\n\n/**\n * Get a wallet client. Use this if you need to write to the blockchain.\n * @param options - The options for the wallet client.\n * @returns A function that returns a wallet client. The function can be called with verification options for HD wallets. see {@link https://viem.sh/docs/clients/wallet}\n * @example\n * ```ts\n * import { getWalletClient } from '@settlemint/sdk-viem';\n * import { parseAbi } from \"viem\";\n *\n * const walletClient = getWalletClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the chain id\n * const chainId = await walletClient().getChainId();\n * console.log(chainId);\n *\n * // write to the blockchain\n * const transactionHash = await walletClient().writeContract({\n * account: \"0x0000000000000000000000000000000000000000\",\n * address: \"0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2\",\n * abi: parseAbi([\"function mint(uint32 tokenId) nonpayable\"]),\n * functionName: \"mint\",\n * args: [69420],\n * });\n * console.log(transactionHash);\n * ```\n */\nexport const getWalletClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validateOptions(ClientOptionsSchema, options);\n\n // Check cache first for the factory function\n const cacheKey = createCacheKey(validatedOptions);\n const cachedFactory = walletClientFactoryCache.get(cacheKey);\n if (cachedFactory) {\n return cachedFactory;\n }\n\n // Get chain (will be cached internally)\n const chain = getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n });\n\n // Create the factory function\n const walletClientFactory = (verificationOptions?: WalletVerificationOptions) => {\n // Headers need to be computed per verification options\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n \"x-auth-challenge-response\": verificationOptions?.challengeResponse ?? \"\",\n \"x-auth-verification-id\": verificationOptions?.verificationId ?? \"\",\n });\n\n return createWalletClient({\n chain: chain,\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n })\n .extend(publicActions)\n .extend(createWallet)\n .extend(getWalletVerifications)\n .extend(createWalletVerification)\n .extend(deleteWalletVerification)\n .extend(createWalletVerificationChallenges)\n .extend(verifyWalletVerificationChallenge);\n };\n\n // Cache the factory\n walletClientFactoryCache.set(cacheKey, walletClientFactory);\n\n return walletClientFactory;\n};\n\n/**\n * Schema for the viem client options.\n */\nexport const GetChainIdOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated get chain id options.\n */\nexport type GetChainIdOptions = Omit<z.infer<typeof GetChainIdOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get the chain id of a blockchain network.\n * @param options - The options for the public client.\n * @returns The chain id.\n * @example\n * ```ts\n * import { getChainId } from '@settlemint/sdk-viem';\n *\n * const chainId = await getChainId({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n * console.log(chainId);\n * ```\n */\nexport async function getChainId(options: GetChainIdOptions): Promise<number> {\n ensureServer();\n const validatedOptions: GetChainIdOptions = validateOptions(GetChainIdOptionsSchema, options);\n\n // Pre-compute headers\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n });\n\n const client = createPublicClient({\n transport: http(validatedOptions.rpcUrl, {\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n return client.getChainId();\n}\n\n// Create a Map for O(1) chain lookups\nconst knownChainsMap = new Map<string, ViemChain>(Object.values(chains).map((chain) => [chain.id.toString(), chain]));\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n // Check if chain is already cached\n const cacheKey = `${chainId}-${chainName}-${rpcUrl}`;\n const cachedChain = chainCache.get(cacheKey);\n if (cachedChain) {\n return cachedChain;\n }\n\n // O(1) lookup for known chains\n const knownChain = knownChainsMap.get(chainId);\n if (knownChain) {\n chainCache.set(cacheKey, knownChain);\n return knownChain;\n }\n\n // Create custom chain definition\n const customChain = defineChain({\n id: Number(chainId),\n name: chainName,\n rpcUrls: {\n default: {\n http: [rpcUrl],\n },\n },\n nativeCurrency: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n });\n\n // Cache the custom chain\n chainCache.set(cacheKey, customChain);\n return customChain;\n}\n\nexport type {\n CreateWalletParameters,\n CreateWalletResponse,\n WalletInfo,\n} from \"./custom-actions/create-wallet.action.js\";\nexport type {\n CreateWalletVerificationParameters,\n CreateWalletVerificationResponse,\n WalletOTPVerificationInfo,\n WalletPincodeVerificationInfo,\n WalletSecretCodesVerificationInfo,\n WalletVerificationInfo,\n} from \"./custom-actions/create-wallet-verification.action.js\";\nexport type {\n CreateWalletVerificationChallengesParameters,\n CreateWalletVerificationChallengesResponse,\n WalletVerificationChallenge,\n} from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nexport type {\n DeleteWalletVerificationParameters,\n DeleteWalletVerificationResponse,\n} from \"./custom-actions/delete-wallet-verification.action.js\";\nexport type {\n GetWalletVerificationsParameters,\n GetWalletVerificationsResponse,\n WalletVerification,\n} from \"./custom-actions/get-wallet-verifications.action.js\";\nexport { OTPAlgorithm, WalletVerificationType } from \"./custom-actions/types/wallet-verification.enum.js\";\nexport type {\n AddressOrObject,\n VerificationResult,\n VerifyWalletVerificationChallengeParameters,\n VerifyWalletVerificationChallengeResponse,\n} from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n"],"mappings":";;;;;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AAc;GACZ,GAAG,kBAAkB,qBAAqB;GAC1C;EACD;CACF,EAAC,CACH,EAAC;AAEF,QAAO,OAAO,YAAY;AAC3B;AAGD,MAAM,iBAAiB,IAAI,IAAuB,OAAO,OAAOC,YAAO,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,UAAU,EAAE,KAAM,EAAC;AAEpH,SAAS,SAAS,EAAE,SAAS,WAAW,QAAiE,EAAa;CAEpH,MAAM,WAAW,GAAG,QAAQ,CAAC,EAAE,UAAU,CAAC,EAAE,QAAQ;CACpD,MAAM,cAAc,WAAW,IAAI,SAAS;AAC5C,KAAI,aAAa;AACf,SAAO;CACR;CAGD,MAAM,aAAa,eAAe,IAAI,QAAQ;AAC9C,KAAI,YAAY;EACd,WAAW,IAAI,UAAU,WAAW;AACpC,SAAO;CACR;CAGD,MAAM,oCAA0B;EAC9B,IAAI,OAAO,QAAQ;EACnB,MAAM;EACN,SAAS,EACP,SAAS,EACP,MAAM,CAAC,MAAO,EACf,EACF;EACD,gBAAgB;GACd,UAAU;GACV,MAAM;GACN,QAAQ;EACT;CACF,EAAC;CAGF,WAAW,IAAI,UAAU,YAAY;AACrC,QAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"viem.cjs","names":["client: Client","args: CreateWalletParameters","client: Client","args: CreateWalletVerificationParameters","client: Client","args: CreateWalletVerificationChallengesParameters","client: Client","args: DeleteWalletVerificationParameters","client: Client","args: GetWalletVerificationsParameters","client: Client","args: VerifyWalletVerificationChallengeParameters","maxSize: number","key: K","value: V","options: Partial<ClientOptions>","keyObject: Record<string, unknown>","baseHeaders: HeadersInit | undefined","authHeaders: Record<string, string>","z","ApplicationAccessTokenSchema","UrlOrPathSchema","options: ClientOptions","validatedOptions: ClientOptions","verificationOptions?: WalletVerificationOptions","publicActions","options: GetChainIdOptions","validatedOptions: GetChainIdOptions","chains"],"sources":["../src/custom-actions/create-wallet.action.ts","../src/custom-actions/create-wallet-verification.action.ts","../src/custom-actions/create-wallet-verification-challenges.action.ts","../src/custom-actions/delete-wallet-verification.action.ts","../src/custom-actions/get-wallet-verifications.action.ts","../src/custom-actions/verify-wallet-verification-challenge.action.ts","../src/custom-actions/types/wallet-verification.enum.ts","../src/viem.ts"],"sourcesContent":["import type { Client } from \"viem\";\n\n/**\n * Information about the wallet to be created.\n */\nexport interface WalletInfo {\n /** The name of the wallet. */\n name: string;\n}\n\n/**\n * Parameters for creating a wallet.\n */\nexport interface CreateWalletParameters {\n /** The unique name of the key vault where the wallet will be created. */\n keyVaultId: string;\n /** Information about the wallet to be created. */\n walletInfo: WalletInfo;\n}\n\n/**\n * Response from creating a wallet.\n */\nexport interface CreateWalletResponse {\n /** The unique identifier of the wallet. */\n id: string;\n /** The name of the wallet. */\n name: string;\n /** The blockchain address of the wallet. */\n address: string;\n /** The HD derivation path used to create the wallet. */\n derivationPath: string;\n}\n\n/**\n * RPC schema for wallet creation.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWallet\";\n Parameters: [keyVaultId: string, walletInfo: WalletInfo];\n ReturnType: CreateWalletResponse[];\n};\n\n/**\n * Creates a wallet action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWallet method.\n */\nexport function createWallet(client: Client) {\n return {\n /**\n * Creates a new wallet in the specified key vault.\n * @param args - The parameters for creating a wallet.\n * @returns A promise that resolves to an array of created wallet responses.\n */\n createWallet(args: CreateWalletParameters): Promise<CreateWalletResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWallet\",\n params: [args.keyVaultId, args.walletInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { OTPAlgorithm, WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Base interface for wallet verification information.\n */\ntype BaseWalletVerificationInfo = {\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n};\n\n/**\n * Information for PIN code verification.\n */\nexport interface WalletPincodeVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.PINCODE;\n /** The PIN code to use for verification. */\n pincode: string;\n}\n\n/**\n * Information for One-Time Password (OTP) verification.\n */\nexport interface WalletOTPVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.OTP;\n /** The hash algorithm to use for OTP generation. */\n algorithm?: OTPAlgorithm;\n /** The number of digits in the OTP code. */\n digits?: number;\n /** The time period in seconds for OTP validity. */\n period?: number;\n /** The issuer of the OTP. */\n issuer?: string;\n}\n\n/**\n * Information for secret recovery codes verification.\n */\nexport interface WalletSecretCodesVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.SECRET_CODES;\n}\n\n/**\n * Union type of all possible wallet verification information types.\n */\nexport type WalletVerificationInfo =\n | WalletPincodeVerificationInfo\n | WalletOTPVerificationInfo\n | WalletSecretCodesVerificationInfo;\n\n/**\n * Parameters for creating a wallet verification.\n */\nexport interface CreateWalletVerificationParameters {\n /** The wallet address for which to create the verification. */\n userWalletAddress: string;\n /** The verification information to create. */\n walletVerificationInfo: WalletVerificationInfo;\n}\n\n/**\n * Response from creating a wallet verification.\n */\nexport interface CreateWalletVerificationResponse {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n /** Additional parameters specific to the verification type. */\n parameters: Record<string, string>;\n}\n\n/**\n * RPC schema for creating a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerification\";\n Parameters: [userWalletAddress: string, walletVerificationInfo: WalletVerificationInfo];\n ReturnType: CreateWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerification method.\n */\nexport function createWalletVerification(client: Client) {\n return {\n /**\n * Creates a new wallet verification.\n * @param args - The parameters for creating the verification.\n * @returns A promise that resolves to an array of created wallet verification responses.\n */\n createWalletVerification(args: CreateWalletVerificationParameters): Promise<CreateWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerification\",\n params: [args.userWalletAddress, args.walletVerificationInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\nimport type { AddressOrObject } from \"./verify-wallet-verification-challenge.action.js\";\n\n/**\n * Parameters for creating wallet verification challenges.\n */\nexport interface CreateWalletVerificationChallengesParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n}\n\n/**\n * Represents a wallet verification challenge.\n */\nexport interface WalletVerificationChallenge {\n /** The unique identifier of the challenge. */\n id: string;\n /** The name of the challenge. */\n name: string;\n /** The type of verification required. */\n verificationType: WalletVerificationType;\n /** The challenge parameters specific to the verification type. */\n challenge: Record<string, string>;\n}\n\n/**\n * Response from creating wallet verification challenges.\n */\nexport type CreateWalletVerificationChallengesResponse = WalletVerificationChallenge[];\n\n/**\n * RPC schema for creating wallet verification challenges.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerificationChallenges\";\n Parameters: [addressOrObject: AddressOrObject];\n ReturnType: CreateWalletVerificationChallengesResponse;\n};\n\n/**\n * Creates a wallet verification challenges action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerificationChallenges method.\n */\nexport function createWalletVerificationChallenges(client: Client) {\n return {\n /**\n * Creates verification challenges for a wallet.\n * @param args - The parameters for creating the challenges.\n * @returns A promise that resolves to an array of wallet verification challenges.\n */\n createWalletVerificationChallenges(\n args: CreateWalletVerificationChallengesParameters,\n ): Promise<CreateWalletVerificationChallengesResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerificationChallenges\",\n params: [args.addressOrObject],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Parameters for deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationParameters {\n /** The wallet address for which to delete the verification. */\n userWalletAddress: string;\n /** The unique identifier of the verification to delete. */\n verificationId: string;\n}\n\n/**\n * Response from deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationResponse {\n /** Whether the deletion was successful. */\n success: boolean;\n}\n\n/**\n * RPC schema for deleting a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_deleteWalletVerification\";\n Parameters: [userWalletAddress: string, verificationId: string];\n ReturnType: DeleteWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification deletion action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a deleteWalletVerification method.\n */\nexport function deleteWalletVerification(client: Client) {\n return {\n /**\n * Deletes a wallet verification.\n * @param args - The parameters for deleting the verification.\n * @returns A promise that resolves to an array of deletion results.\n */\n deleteWalletVerification(args: DeleteWalletVerificationParameters): Promise<DeleteWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_deleteWalletVerification\",\n params: [args.userWalletAddress, args.verificationId],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Parameters for getting wallet verifications.\n */\nexport interface GetWalletVerificationsParameters {\n /** The wallet address for which to fetch verifications. */\n userWalletAddress: string;\n}\n\n/**\n * Represents a wallet verification.\n */\nexport interface WalletVerification {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n}\n\n/**\n * Response from getting wallet verifications.\n */\nexport type GetWalletVerificationsResponse = WalletVerification[];\n\n/**\n * RPC schema for getting wallet verifications.\n */\ntype WalletRpcSchema = {\n Method: \"user_walletVerifications\";\n Parameters: [userWalletAddress: string];\n ReturnType: GetWalletVerificationsResponse;\n};\n\n/**\n * Creates a wallet verifications retrieval action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a getWalletVerifications method.\n */\nexport function getWalletVerifications(client: Client) {\n return {\n /**\n * Gets all verifications for a wallet.\n * @param args - The parameters for getting the verifications.\n * @returns A promise that resolves to an array of wallet verifications.\n */\n getWalletVerifications(args: GetWalletVerificationsParameters): Promise<GetWalletVerificationsResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_walletVerifications\",\n params: [args.userWalletAddress],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Represents either a wallet address string or an object containing wallet address and optional verification ID.\n */\nexport type AddressOrObject =\n | string\n | {\n userWalletAddress: string;\n verificationId?: string;\n };\n\n/**\n * Parameters for verifying a wallet verification challenge.\n */\nexport interface VerifyWalletVerificationChallengeParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n /** The response to the verification challenge. */\n challengeResponse: string;\n}\n\n/**\n * Result of a wallet verification challenge.\n */\nexport interface VerificationResult {\n /** Whether the verification was successful. */\n verified: boolean;\n}\n\n/**\n * Response from verifying a wallet verification challenge.\n */\nexport type VerifyWalletVerificationChallengeResponse = VerificationResult[];\n\n/**\n * RPC schema for wallet verification challenge verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_verifyWalletVerificationChallenge\";\n Parameters: [addressOrObject: AddressOrObject, challengeResponse: string];\n ReturnType: VerifyWalletVerificationChallengeResponse;\n};\n\n/**\n * Creates a wallet verification challenge verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a verifyWalletVerificationChallenge method.\n */\nexport function verifyWalletVerificationChallenge(client: Client) {\n return {\n /**\n * Verifies a wallet verification challenge.\n * @param args - The parameters for verifying the challenge.\n * @returns A promise that resolves to an array of verification results.\n */\n verifyWalletVerificationChallenge(\n args: VerifyWalletVerificationChallengeParameters,\n ): Promise<VerifyWalletVerificationChallengeResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_verifyWalletVerificationChallenge\",\n params: [args.addressOrObject, args.challengeResponse],\n });\n },\n };\n}\n","/**\n * Types of wallet verification methods supported by the system.\n * Used to identify different verification mechanisms when creating or managing wallet verifications.\n */\nexport enum WalletVerificationType {\n /** PIN code verification method */\n PINCODE = \"PINCODE\",\n /** One-Time Password verification method */\n OTP = \"OTP\",\n /** Secret recovery codes verification method */\n SECRET_CODES = \"SECRET_CODES\",\n}\n\n/**\n * Supported hash algorithms for One-Time Password (OTP) verification.\n * These algorithms determine the cryptographic function used to generate OTP codes.\n */\nexport enum OTPAlgorithm {\n /** SHA-1 hash algorithm */\n SHA1 = \"SHA1\",\n /** SHA-224 hash algorithm */\n SHA224 = \"SHA224\",\n /** SHA-256 hash algorithm */\n SHA256 = \"SHA256\",\n /** SHA-384 hash algorithm */\n SHA384 = \"SHA384\",\n /** SHA-512 hash algorithm */\n SHA512 = \"SHA512\",\n /** SHA3-224 hash algorithm */\n SHA3_224 = \"SHA3-224\",\n /** SHA3-256 hash algorithm */\n SHA3_256 = \"SHA3-256\",\n /** SHA3-384 hash algorithm */\n SHA3_384 = \"SHA3-384\",\n /** SHA3-512 hash algorithm */\n SHA3_512 = \"SHA3-512\",\n}\n","import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport {\n createPublicClient,\n createWalletClient,\n defineChain,\n type HttpTransportConfig,\n http,\n publicActions,\n type Chain as ViemChain,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport * as chains from \"viem/chains\";\nimport { z } from \"zod\";\nimport { createWallet } from \"./custom-actions/create-wallet.action.js\";\nimport { createWalletVerification } from \"./custom-actions/create-wallet-verification.action.js\";\nimport { createWalletVerificationChallenges } from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nimport { deleteWalletVerification } from \"./custom-actions/delete-wallet-verification.action.js\";\nimport { getWalletVerifications } from \"./custom-actions/get-wallet-verifications.action.js\";\nimport { verifyWalletVerificationChallenge } from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n\n// Simple LRU cache implementation\nclass LRUCache<K, V> {\n private cache = new Map<K, V>();\n private readonly maxSize: number;\n\n constructor(maxSize: number) {\n this.maxSize = maxSize;\n }\n\n get(key: K): V | undefined {\n const value = this.cache.get(key);\n if (value !== undefined) {\n // Move to end (most recently used)\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n set(key: K, value: V): void {\n // Remove key if it exists (to update position)\n this.cache.delete(key);\n\n // Check size limit\n if (this.cache.size >= this.maxSize) {\n // Remove least recently used (first item)\n const firstKey = this.cache.keys().next().value;\n if (firstKey !== undefined) {\n this.cache.delete(firstKey);\n }\n }\n\n this.cache.set(key, value);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n// Cache for chain definitions with size limit\nconst chainCache = new LRUCache<string, ViemChain>(100);\n\n// Cache for public clients with size limit\nconst publicClientCache = new LRUCache<string, PublicClient<Transport, ViemChain>>(50);\n\n// Cache for wallet client factories with size limit\nconst walletClientFactoryCache = new LRUCache<\n string,\n (verificationOptions?: WalletVerificationOptions) => ReturnType<typeof createWalletClient>\n>(50);\n\n// Helper to create robust cache key from options\nfunction createCacheKey(options: Partial<ClientOptions>): string {\n // Create a deterministic key by sorting properties\n const keyObject: Record<string, unknown> = {};\n\n // Add properties in sorted order to ensure consistency\n const keys = [\"chainId\", \"chainName\", \"rpcUrl\", \"accessToken\"] as const;\n for (const key of keys) {\n const value = options[key as keyof ClientOptions];\n // Only include defined values\n if (value !== undefined) {\n keyObject[key] = value;\n }\n }\n\n // Use sorted keys for consistent stringification\n return JSON.stringify(keyObject, Object.keys(keyObject).sort());\n}\n\n// Shared utility for building headers\nfunction buildHeaders(baseHeaders: HeadersInit | undefined, authHeaders: Record<string, string>): HeadersInit {\n return appendHeaders(baseHeaders, authHeaders);\n}\n\n/**\n * Schema for the viem client options.\n */\nexport const ClientOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The chain id\n */\n chainId: z.string(),\n /**\n * The chain name\n */\n chainName: z.string(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = Omit<z.infer<typeof ClientOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get a public client. Use this if you need to read from the blockchain.\n * @param options - The options for the public client.\n * @returns The public client. see {@link https://viem.sh/docs/clients/public}\n * @example\n * ```ts\n * import { getPublicClient } from '@settlemint/sdk-viem';\n *\n * const publicClient = getPublicClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the block number\n * const block = await publicClient.getBlockNumber();\n * console.log(block);\n * ```\n */\nexport const getPublicClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validate(ClientOptionsSchema, options);\n\n // Check cache first\n const cacheKey = createCacheKey(validatedOptions);\n const cachedClient = publicClientCache.get(cacheKey);\n if (cachedClient) {\n return cachedClient;\n }\n\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n });\n\n // Create new client\n const client = createPublicClient({\n chain: getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n }),\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n // Cache the client\n publicClientCache.set(cacheKey, client);\n\n return client;\n};\n\n/**\n * The options for the wallet client.\n */\nexport interface WalletVerificationOptions {\n /**\n * The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications.\n */\n verificationId?: string;\n /**\n * The challenge response (used for HD wallets)\n */\n challengeResponse: string;\n}\n\n/**\n * Get a wallet client. Use this if you need to write to the blockchain.\n * @param options - The options for the wallet client.\n * @returns A function that returns a wallet client. The function can be called with verification options for HD wallets. see {@link https://viem.sh/docs/clients/wallet}\n * @example\n * ```ts\n * import { getWalletClient } from '@settlemint/sdk-viem';\n * import { parseAbi } from \"viem\";\n *\n * const walletClient = getWalletClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the chain id\n * const chainId = await walletClient().getChainId();\n * console.log(chainId);\n *\n * // write to the blockchain\n * const transactionHash = await walletClient().writeContract({\n * account: \"0x0000000000000000000000000000000000000000\",\n * address: \"0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2\",\n * abi: parseAbi([\"function mint(uint32 tokenId) nonpayable\"]),\n * functionName: \"mint\",\n * args: [69420],\n * });\n * console.log(transactionHash);\n * ```\n */\nexport const getWalletClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validate(ClientOptionsSchema, options);\n\n // Check cache first for the factory function\n const cacheKey = createCacheKey(validatedOptions);\n const cachedFactory = walletClientFactoryCache.get(cacheKey);\n if (cachedFactory) {\n return cachedFactory;\n }\n\n // Get chain (will be cached internally)\n const chain = getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n });\n\n // Create the factory function\n const walletClientFactory = (verificationOptions?: WalletVerificationOptions) => {\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n \"x-auth-challenge-response\": verificationOptions?.challengeResponse ?? \"\",\n \"x-auth-verification-id\": verificationOptions?.verificationId ?? \"\",\n });\n\n return createWalletClient({\n chain: chain,\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n })\n .extend(publicActions)\n .extend(createWallet)\n .extend(getWalletVerifications)\n .extend(createWalletVerification)\n .extend(deleteWalletVerification)\n .extend(createWalletVerificationChallenges)\n .extend(verifyWalletVerificationChallenge);\n };\n\n // Cache the factory\n walletClientFactoryCache.set(cacheKey, walletClientFactory);\n\n return walletClientFactory;\n};\n\n/**\n * Schema for the viem client options.\n */\nexport const GetChainIdOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated get chain id options.\n */\nexport type GetChainIdOptions = Omit<z.infer<typeof GetChainIdOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get the chain id of a blockchain network.\n * @param options - The options for the public client.\n * @returns The chain id.\n * @example\n * ```ts\n * import { getChainId } from '@settlemint/sdk-viem';\n *\n * const chainId = await getChainId({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n * console.log(chainId);\n * ```\n */\nexport async function getChainId(options: GetChainIdOptions): Promise<number> {\n ensureServer();\n const validatedOptions: GetChainIdOptions = validate(GetChainIdOptionsSchema, options);\n\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n });\n\n const client = createPublicClient({\n transport: http(validatedOptions.rpcUrl, {\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n return client.getChainId();\n}\n\n// Create a Map for O(1) chain lookups\nconst knownChainsMap = new Map<string, ViemChain>(Object.values(chains).map((chain) => [chain.id.toString(), chain]));\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n // Create deterministic cache key\n const cacheKey = JSON.stringify({ chainId, chainName, rpcUrl }, [\"chainId\", \"chainName\", \"rpcUrl\"]);\n\n // Check if chain is already cached\n const cachedChain = chainCache.get(cacheKey);\n if (cachedChain) {\n return cachedChain;\n }\n\n // O(1) lookup for known chains\n const knownChain = knownChainsMap.get(chainId);\n if (knownChain) {\n chainCache.set(cacheKey, knownChain);\n return knownChain;\n }\n\n // Create custom chain definition\n const customChain = defineChain({\n id: Number(chainId),\n name: chainName,\n rpcUrls: {\n default: {\n http: [rpcUrl],\n },\n },\n nativeCurrency: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n });\n\n // Cache the custom chain\n chainCache.set(cacheKey, customChain);\n return customChain;\n}\n\nexport type {\n CreateWalletParameters,\n CreateWalletResponse,\n WalletInfo,\n} from \"./custom-actions/create-wallet.action.js\";\nexport type {\n CreateWalletVerificationParameters,\n CreateWalletVerificationResponse,\n WalletOTPVerificationInfo,\n WalletPincodeVerificationInfo,\n WalletSecretCodesVerificationInfo,\n WalletVerificationInfo,\n} from \"./custom-actions/create-wallet-verification.action.js\";\nexport type {\n CreateWalletVerificationChallengesParameters,\n CreateWalletVerificationChallengesResponse,\n WalletVerificationChallenge,\n} from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nexport type {\n DeleteWalletVerificationParameters,\n DeleteWalletVerificationResponse,\n} from \"./custom-actions/delete-wallet-verification.action.js\";\nexport type {\n GetWalletVerificationsParameters,\n GetWalletVerificationsResponse,\n WalletVerification,\n} from \"./custom-actions/get-wallet-verifications.action.js\";\nexport { OTPAlgorithm, WalletVerificationType } from \"./custom-actions/types/wallet-verification.enum.js\";\nexport type {\n AddressOrObject,\n VerificationResult,\n VerifyWalletVerificationChallengeParameters,\n VerifyWalletVerificationChallengeResponse,\n} from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,aAAaA,QAAgB;AAC3C,QAAO,EAML,aAAaC,MAA+D;AAC1E,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,YAAY,KAAK,UAAW;EAC3C,EAAC;CACH,EACF;AACF;;;;;;;;;AC+BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,mBAAmB,KAAK,sBAAuB;EAC9D,EAAC;CACH,EACF;AACF;;;;;;;;;AC9DD,SAAgB,mCAAmCC,QAAgB;AACjE,QAAO,EAML,mCACEC,MACqD;AACrD,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,eAAgB;EAC/B,EAAC;CACH,EACF;AACF;;;;;;;;;AC3BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,mBAAmB,KAAK,cAAe;EACtD,EAAC;CACH,EACF;AACF;;;;;;;;;ACND,SAAgB,uBAAuBC,QAAgB;AACrD,QAAO,EAML,uBAAuBC,MAAiF;AACtG,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,iBAAkB;EACjC,EAAC;CACH,EACF;AACF;;;;;;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E,SAAS,WAAW,QAAiE,EAAa;CAEpH,MAAM,WAAW,KAAK,UAAU;EAAE;EAAS;EAAW;CAAQ,GAAE;EAAC;EAAW;EAAa;CAAS,EAAC;CAGnG,MAAM,cAAc,WAAW,IAAI,SAAS;AAC5C,KAAI,aAAa;AACf,SAAO;CACR;CAGD,MAAM,aAAa,eAAe,IAAI,QAAQ;AAC9C,KAAI,YAAY;EACd,WAAW,IAAI,UAAU,WAAW;AACpC,SAAO;CACR;CAGD,MAAM,oCAA0B;EAC9B,IAAI,OAAO,QAAQ;EACnB,MAAM;EACN,SAAS,EACP,SAAS,EACP,MAAM,CAAC,MAAO,EACf,EACF;EACD,gBAAgB;GACd,UAAU;GACV,MAAM;GACN,QAAQ;EACT;CACF,EAAC;CAGF,WAAW,IAAI,UAAU,YAAY;AACrC,QAAO;AACR"}
|
package/dist/viem.js
CHANGED
|
@@ -144,23 +144,55 @@ let OTPAlgorithm = /* @__PURE__ */ function(OTPAlgorithm$1) {
|
|
|
144
144
|
|
|
145
145
|
//#endregion
|
|
146
146
|
//#region src/viem.ts
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
var LRUCache = class {
|
|
148
|
+
cache = new Map();
|
|
149
|
+
maxSize;
|
|
150
|
+
constructor(maxSize) {
|
|
151
|
+
this.maxSize = maxSize;
|
|
152
|
+
}
|
|
153
|
+
get(key) {
|
|
154
|
+
const value = this.cache.get(key);
|
|
155
|
+
if (value !== undefined) {
|
|
156
|
+
this.cache.delete(key);
|
|
157
|
+
this.cache.set(key, value);
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
set(key, value) {
|
|
162
|
+
this.cache.delete(key);
|
|
163
|
+
if (this.cache.size >= this.maxSize) {
|
|
164
|
+
const firstKey = this.cache.keys().next().value;
|
|
165
|
+
if (firstKey !== undefined) {
|
|
166
|
+
this.cache.delete(firstKey);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this.cache.set(key, value);
|
|
170
|
+
}
|
|
171
|
+
clear() {
|
|
172
|
+
this.cache.clear();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const chainCache = new LRUCache(100);
|
|
176
|
+
const publicClientCache = new LRUCache(50);
|
|
177
|
+
const walletClientFactoryCache = new LRUCache(50);
|
|
150
178
|
function createCacheKey(options) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
179
|
+
const keyObject = {};
|
|
180
|
+
const keys = [
|
|
181
|
+
"chainId",
|
|
182
|
+
"chainName",
|
|
183
|
+
"rpcUrl",
|
|
184
|
+
"accessToken"
|
|
185
|
+
];
|
|
186
|
+
for (const key of keys) {
|
|
187
|
+
const value = options[key];
|
|
188
|
+
if (value !== undefined) {
|
|
189
|
+
keyObject[key] = value;
|
|
190
|
+
}
|
|
162
191
|
}
|
|
163
|
-
return
|
|
192
|
+
return JSON.stringify(keyObject, Object.keys(keyObject).sort());
|
|
193
|
+
}
|
|
194
|
+
function buildHeaders(baseHeaders, authHeaders) {
|
|
195
|
+
return appendHeaders(baseHeaders, authHeaders);
|
|
164
196
|
}
|
|
165
197
|
/**
|
|
166
198
|
* Schema for the viem client options.
|
|
@@ -194,13 +226,13 @@ const ClientOptionsSchema = z.object({
|
|
|
194
226
|
*/
|
|
195
227
|
const getPublicClient = (options) => {
|
|
196
228
|
ensureServer();
|
|
197
|
-
const validatedOptions =
|
|
229
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
198
230
|
const cacheKey = createCacheKey(validatedOptions);
|
|
199
231
|
const cachedClient = publicClientCache.get(cacheKey);
|
|
200
232
|
if (cachedClient) {
|
|
201
233
|
return cachedClient;
|
|
202
234
|
}
|
|
203
|
-
const headers =
|
|
235
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken || "" });
|
|
204
236
|
const client = createPublicClient({
|
|
205
237
|
chain: getChain({
|
|
206
238
|
chainId: validatedOptions.chainId,
|
|
@@ -254,7 +286,7 @@ const getPublicClient = (options) => {
|
|
|
254
286
|
*/
|
|
255
287
|
const getWalletClient = (options) => {
|
|
256
288
|
ensureServer();
|
|
257
|
-
const validatedOptions =
|
|
289
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
258
290
|
const cacheKey = createCacheKey(validatedOptions);
|
|
259
291
|
const cachedFactory = walletClientFactoryCache.get(cacheKey);
|
|
260
292
|
if (cachedFactory) {
|
|
@@ -266,8 +298,8 @@ const getWalletClient = (options) => {
|
|
|
266
298
|
rpcUrl: validatedOptions.rpcUrl
|
|
267
299
|
});
|
|
268
300
|
const walletClientFactory = (verificationOptions) => {
|
|
269
|
-
const headers =
|
|
270
|
-
"x-auth-token": validatedOptions.accessToken,
|
|
301
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {
|
|
302
|
+
"x-auth-token": validatedOptions.accessToken || "",
|
|
271
303
|
"x-auth-challenge-response": verificationOptions?.challengeResponse ?? "",
|
|
272
304
|
"x-auth-verification-id": verificationOptions?.verificationId ?? ""
|
|
273
305
|
});
|
|
@@ -313,8 +345,8 @@ const GetChainIdOptionsSchema = z.object({
|
|
|
313
345
|
*/
|
|
314
346
|
async function getChainId(options) {
|
|
315
347
|
ensureServer();
|
|
316
|
-
const validatedOptions =
|
|
317
|
-
const headers =
|
|
348
|
+
const validatedOptions = validate(GetChainIdOptionsSchema, options);
|
|
349
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken || "" });
|
|
318
350
|
const client = createPublicClient({ transport: http(validatedOptions.rpcUrl, {
|
|
319
351
|
...validatedOptions.httpTransportConfig,
|
|
320
352
|
fetchOptions: {
|
|
@@ -326,7 +358,15 @@ async function getChainId(options) {
|
|
|
326
358
|
}
|
|
327
359
|
const knownChainsMap = new Map(Object.values(chains).map((chain) => [chain.id.toString(), chain]));
|
|
328
360
|
function getChain({ chainId, chainName, rpcUrl }) {
|
|
329
|
-
const cacheKey =
|
|
361
|
+
const cacheKey = JSON.stringify({
|
|
362
|
+
chainId,
|
|
363
|
+
chainName,
|
|
364
|
+
rpcUrl
|
|
365
|
+
}, [
|
|
366
|
+
"chainId",
|
|
367
|
+
"chainName",
|
|
368
|
+
"rpcUrl"
|
|
369
|
+
]);
|
|
330
370
|
const cachedChain = chainCache.get(cacheKey);
|
|
331
371
|
if (cachedChain) {
|
|
332
372
|
return cachedChain;
|
package/dist/viem.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viem.js","names":["client: Client","args: CreateWalletParameters","client: Client","args: CreateWalletVerificationParameters","client: Client","args: CreateWalletVerificationChallengesParameters","client: Client","args: DeleteWalletVerificationParameters","client: Client","args: GetWalletVerificationsParameters","client: Client","args: VerifyWalletVerificationChallengeParameters","options: Partial<ClientOptions>","schema: z.ZodSchema<T>","options: unknown","options: ClientOptions","validatedOptions: ClientOptions","verificationOptions?: WalletVerificationOptions","options: GetChainIdOptions","validatedOptions: GetChainIdOptions"],"sources":["../src/custom-actions/create-wallet.action.ts","../src/custom-actions/create-wallet-verification.action.ts","../src/custom-actions/create-wallet-verification-challenges.action.ts","../src/custom-actions/delete-wallet-verification.action.ts","../src/custom-actions/get-wallet-verifications.action.ts","../src/custom-actions/verify-wallet-verification-challenge.action.ts","../src/custom-actions/types/wallet-verification.enum.ts","../src/viem.ts"],"sourcesContent":["import type { Client } from \"viem\";\n\n/**\n * Information about the wallet to be created.\n */\nexport interface WalletInfo {\n /** The name of the wallet. */\n name: string;\n}\n\n/**\n * Parameters for creating a wallet.\n */\nexport interface CreateWalletParameters {\n /** The unique name of the key vault where the wallet will be created. */\n keyVaultId: string;\n /** Information about the wallet to be created. */\n walletInfo: WalletInfo;\n}\n\n/**\n * Response from creating a wallet.\n */\nexport interface CreateWalletResponse {\n /** The unique identifier of the wallet. */\n id: string;\n /** The name of the wallet. */\n name: string;\n /** The blockchain address of the wallet. */\n address: string;\n /** The HD derivation path used to create the wallet. */\n derivationPath: string;\n}\n\n/**\n * RPC schema for wallet creation.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWallet\";\n Parameters: [keyVaultId: string, walletInfo: WalletInfo];\n ReturnType: CreateWalletResponse[];\n};\n\n/**\n * Creates a wallet action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWallet method.\n */\nexport function createWallet(client: Client) {\n return {\n /**\n * Creates a new wallet in the specified key vault.\n * @param args - The parameters for creating a wallet.\n * @returns A promise that resolves to an array of created wallet responses.\n */\n createWallet(args: CreateWalletParameters): Promise<CreateWalletResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWallet\",\n params: [args.keyVaultId, args.walletInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { OTPAlgorithm, WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Base interface for wallet verification information.\n */\ntype BaseWalletVerificationInfo = {\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n};\n\n/**\n * Information for PIN code verification.\n */\nexport interface WalletPincodeVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.PINCODE;\n /** The PIN code to use for verification. */\n pincode: string;\n}\n\n/**\n * Information for One-Time Password (OTP) verification.\n */\nexport interface WalletOTPVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.OTP;\n /** The hash algorithm to use for OTP generation. */\n algorithm?: OTPAlgorithm;\n /** The number of digits in the OTP code. */\n digits?: number;\n /** The time period in seconds for OTP validity. */\n period?: number;\n /** The issuer of the OTP. */\n issuer?: string;\n}\n\n/**\n * Information for secret recovery codes verification.\n */\nexport interface WalletSecretCodesVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.SECRET_CODES;\n}\n\n/**\n * Union type of all possible wallet verification information types.\n */\nexport type WalletVerificationInfo =\n | WalletPincodeVerificationInfo\n | WalletOTPVerificationInfo\n | WalletSecretCodesVerificationInfo;\n\n/**\n * Parameters for creating a wallet verification.\n */\nexport interface CreateWalletVerificationParameters {\n /** The wallet address for which to create the verification. */\n userWalletAddress: string;\n /** The verification information to create. */\n walletVerificationInfo: WalletVerificationInfo;\n}\n\n/**\n * Response from creating a wallet verification.\n */\nexport interface CreateWalletVerificationResponse {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n /** Additional parameters specific to the verification type. */\n parameters: Record<string, string>;\n}\n\n/**\n * RPC schema for creating a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerification\";\n Parameters: [userWalletAddress: string, walletVerificationInfo: WalletVerificationInfo];\n ReturnType: CreateWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerification method.\n */\nexport function createWalletVerification(client: Client) {\n return {\n /**\n * Creates a new wallet verification.\n * @param args - The parameters for creating the verification.\n * @returns A promise that resolves to an array of created wallet verification responses.\n */\n createWalletVerification(args: CreateWalletVerificationParameters): Promise<CreateWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerification\",\n params: [args.userWalletAddress, args.walletVerificationInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\nimport type { AddressOrObject } from \"./verify-wallet-verification-challenge.action.js\";\n\n/**\n * Parameters for creating wallet verification challenges.\n */\nexport interface CreateWalletVerificationChallengesParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n}\n\n/**\n * Represents a wallet verification challenge.\n */\nexport interface WalletVerificationChallenge {\n /** The unique identifier of the challenge. */\n id: string;\n /** The name of the challenge. */\n name: string;\n /** The type of verification required. */\n verificationType: WalletVerificationType;\n /** The challenge parameters specific to the verification type. */\n challenge: Record<string, string>;\n}\n\n/**\n * Response from creating wallet verification challenges.\n */\nexport type CreateWalletVerificationChallengesResponse = WalletVerificationChallenge[];\n\n/**\n * RPC schema for creating wallet verification challenges.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerificationChallenges\";\n Parameters: [addressOrObject: AddressOrObject];\n ReturnType: CreateWalletVerificationChallengesResponse;\n};\n\n/**\n * Creates a wallet verification challenges action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerificationChallenges method.\n */\nexport function createWalletVerificationChallenges(client: Client) {\n return {\n /**\n * Creates verification challenges for a wallet.\n * @param args - The parameters for creating the challenges.\n * @returns A promise that resolves to an array of wallet verification challenges.\n */\n createWalletVerificationChallenges(\n args: CreateWalletVerificationChallengesParameters,\n ): Promise<CreateWalletVerificationChallengesResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerificationChallenges\",\n params: [args.addressOrObject],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Parameters for deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationParameters {\n /** The wallet address for which to delete the verification. */\n userWalletAddress: string;\n /** The unique identifier of the verification to delete. */\n verificationId: string;\n}\n\n/**\n * Response from deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationResponse {\n /** Whether the deletion was successful. */\n success: boolean;\n}\n\n/**\n * RPC schema for deleting a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_deleteWalletVerification\";\n Parameters: [userWalletAddress: string, verificationId: string];\n ReturnType: DeleteWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification deletion action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a deleteWalletVerification method.\n */\nexport function deleteWalletVerification(client: Client) {\n return {\n /**\n * Deletes a wallet verification.\n * @param args - The parameters for deleting the verification.\n * @returns A promise that resolves to an array of deletion results.\n */\n deleteWalletVerification(args: DeleteWalletVerificationParameters): Promise<DeleteWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_deleteWalletVerification\",\n params: [args.userWalletAddress, args.verificationId],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Parameters for getting wallet verifications.\n */\nexport interface GetWalletVerificationsParameters {\n /** The wallet address for which to fetch verifications. */\n userWalletAddress: string;\n}\n\n/**\n * Represents a wallet verification.\n */\nexport interface WalletVerification {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n}\n\n/**\n * Response from getting wallet verifications.\n */\nexport type GetWalletVerificationsResponse = WalletVerification[];\n\n/**\n * RPC schema for getting wallet verifications.\n */\ntype WalletRpcSchema = {\n Method: \"user_walletVerifications\";\n Parameters: [userWalletAddress: string];\n ReturnType: GetWalletVerificationsResponse;\n};\n\n/**\n * Creates a wallet verifications retrieval action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a getWalletVerifications method.\n */\nexport function getWalletVerifications(client: Client) {\n return {\n /**\n * Gets all verifications for a wallet.\n * @param args - The parameters for getting the verifications.\n * @returns A promise that resolves to an array of wallet verifications.\n */\n getWalletVerifications(args: GetWalletVerificationsParameters): Promise<GetWalletVerificationsResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_walletVerifications\",\n params: [args.userWalletAddress],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Represents either a wallet address string or an object containing wallet address and optional verification ID.\n */\nexport type AddressOrObject =\n | string\n | {\n userWalletAddress: string;\n verificationId?: string;\n };\n\n/**\n * Parameters for verifying a wallet verification challenge.\n */\nexport interface VerifyWalletVerificationChallengeParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n /** The response to the verification challenge. */\n challengeResponse: string;\n}\n\n/**\n * Result of a wallet verification challenge.\n */\nexport interface VerificationResult {\n /** Whether the verification was successful. */\n verified: boolean;\n}\n\n/**\n * Response from verifying a wallet verification challenge.\n */\nexport type VerifyWalletVerificationChallengeResponse = VerificationResult[];\n\n/**\n * RPC schema for wallet verification challenge verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_verifyWalletVerificationChallenge\";\n Parameters: [addressOrObject: AddressOrObject, challengeResponse: string];\n ReturnType: VerifyWalletVerificationChallengeResponse;\n};\n\n/**\n * Creates a wallet verification challenge verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a verifyWalletVerificationChallenge method.\n */\nexport function verifyWalletVerificationChallenge(client: Client) {\n return {\n /**\n * Verifies a wallet verification challenge.\n * @param args - The parameters for verifying the challenge.\n * @returns A promise that resolves to an array of verification results.\n */\n verifyWalletVerificationChallenge(\n args: VerifyWalletVerificationChallengeParameters,\n ): Promise<VerifyWalletVerificationChallengeResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_verifyWalletVerificationChallenge\",\n params: [args.addressOrObject, args.challengeResponse],\n });\n },\n };\n}\n","/**\n * Types of wallet verification methods supported by the system.\n * Used to identify different verification mechanisms when creating or managing wallet verifications.\n */\nexport enum WalletVerificationType {\n /** PIN code verification method */\n PINCODE = \"PINCODE\",\n /** One-Time Password verification method */\n OTP = \"OTP\",\n /** Secret recovery codes verification method */\n SECRET_CODES = \"SECRET_CODES\",\n}\n\n/**\n * Supported hash algorithms for One-Time Password (OTP) verification.\n * These algorithms determine the cryptographic function used to generate OTP codes.\n */\nexport enum OTPAlgorithm {\n /** SHA-1 hash algorithm */\n SHA1 = \"SHA1\",\n /** SHA-224 hash algorithm */\n SHA224 = \"SHA224\",\n /** SHA-256 hash algorithm */\n SHA256 = \"SHA256\",\n /** SHA-384 hash algorithm */\n SHA384 = \"SHA384\",\n /** SHA-512 hash algorithm */\n SHA512 = \"SHA512\",\n /** SHA3-224 hash algorithm */\n SHA3_224 = \"SHA3-224\",\n /** SHA3-256 hash algorithm */\n SHA3_256 = \"SHA3-256\",\n /** SHA3-384 hash algorithm */\n SHA3_384 = \"SHA3-384\",\n /** SHA3-512 hash algorithm */\n SHA3_512 = \"SHA3-512\",\n}\n","import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport {\n createPublicClient,\n createWalletClient,\n defineChain,\n type HttpTransportConfig,\n http,\n publicActions,\n type Chain as ViemChain,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport * as chains from \"viem/chains\";\nimport { z } from \"zod\";\nimport { createWallet } from \"./custom-actions/create-wallet.action.js\";\nimport { createWalletVerification } from \"./custom-actions/create-wallet-verification.action.js\";\nimport { createWalletVerificationChallenges } from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nimport { deleteWalletVerification } from \"./custom-actions/delete-wallet-verification.action.js\";\nimport { getWalletVerifications } from \"./custom-actions/get-wallet-verifications.action.js\";\nimport { verifyWalletVerificationChallenge } from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n\n// Cache for chain definitions to avoid O(n) lookups and repeated chain creation\nconst chainCache = new Map<string, ViemChain>();\n\n// Cache for public clients to avoid repeated instantiation\nconst publicClientCache = new Map<string, PublicClient<Transport, ViemChain>>();\n\n// Cache for wallet client factories to avoid repeated instantiation\nconst walletClientFactoryCache = new Map<\n string,\n (verificationOptions?: WalletVerificationOptions) => ReturnType<typeof createWalletClient>\n>();\n\n// Helper to create cache key from options\nfunction createCacheKey(options: Partial<ClientOptions>): string {\n // Create a deterministic key from the options that affect client creation\n return JSON.stringify({\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n accessToken: options.accessToken,\n // Note: httpTransportConfig is excluded as it's rarely different and complex to serialize\n });\n}\n\n// Skip validation in production for performance\nconst isProduction = process.env.NODE_ENV === \"production\";\n\n// Helper for conditional validation\nfunction validateOptions<T>(schema: z.ZodSchema<T>, options: unknown): T {\n if (isProduction) {\n // In production, assume options are valid (trust the caller)\n return options as T;\n }\n return validate(schema, options);\n}\n\n/**\n * Schema for the viem client options.\n */\nexport const ClientOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The chain id\n */\n chainId: z.string(),\n /**\n * The chain name\n */\n chainName: z.string(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = Omit<z.infer<typeof ClientOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get a public client. Use this if you need to read from the blockchain.\n * @param options - The options for the public client.\n * @returns The public client. see {@link https://viem.sh/docs/clients/public}\n * @example\n * ```ts\n * import { getPublicClient } from '@settlemint/sdk-viem';\n *\n * const publicClient = getPublicClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the block number\n * const block = await publicClient.getBlockNumber();\n * console.log(block);\n * ```\n */\nexport const getPublicClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validateOptions(ClientOptionsSchema, options);\n\n // Check cache first\n const cacheKey = createCacheKey(validatedOptions);\n const cachedClient = publicClientCache.get(cacheKey);\n if (cachedClient) {\n return cachedClient;\n }\n\n // Pre-compute headers once\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n });\n\n // Create new client\n const client = createPublicClient({\n chain: getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n }),\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n // Cache the client\n publicClientCache.set(cacheKey, client);\n\n return client;\n};\n\n/**\n * The options for the wallet client.\n */\nexport interface WalletVerificationOptions {\n /**\n * The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications.\n */\n verificationId?: string;\n /**\n * The challenge response (used for HD wallets)\n */\n challengeResponse: string;\n}\n\n/**\n * Get a wallet client. Use this if you need to write to the blockchain.\n * @param options - The options for the wallet client.\n * @returns A function that returns a wallet client. The function can be called with verification options for HD wallets. see {@link https://viem.sh/docs/clients/wallet}\n * @example\n * ```ts\n * import { getWalletClient } from '@settlemint/sdk-viem';\n * import { parseAbi } from \"viem\";\n *\n * const walletClient = getWalletClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the chain id\n * const chainId = await walletClient().getChainId();\n * console.log(chainId);\n *\n * // write to the blockchain\n * const transactionHash = await walletClient().writeContract({\n * account: \"0x0000000000000000000000000000000000000000\",\n * address: \"0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2\",\n * abi: parseAbi([\"function mint(uint32 tokenId) nonpayable\"]),\n * functionName: \"mint\",\n * args: [69420],\n * });\n * console.log(transactionHash);\n * ```\n */\nexport const getWalletClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validateOptions(ClientOptionsSchema, options);\n\n // Check cache first for the factory function\n const cacheKey = createCacheKey(validatedOptions);\n const cachedFactory = walletClientFactoryCache.get(cacheKey);\n if (cachedFactory) {\n return cachedFactory;\n }\n\n // Get chain (will be cached internally)\n const chain = getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n });\n\n // Create the factory function\n const walletClientFactory = (verificationOptions?: WalletVerificationOptions) => {\n // Headers need to be computed per verification options\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n \"x-auth-challenge-response\": verificationOptions?.challengeResponse ?? \"\",\n \"x-auth-verification-id\": verificationOptions?.verificationId ?? \"\",\n });\n\n return createWalletClient({\n chain: chain,\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n })\n .extend(publicActions)\n .extend(createWallet)\n .extend(getWalletVerifications)\n .extend(createWalletVerification)\n .extend(deleteWalletVerification)\n .extend(createWalletVerificationChallenges)\n .extend(verifyWalletVerificationChallenge);\n };\n\n // Cache the factory\n walletClientFactoryCache.set(cacheKey, walletClientFactory);\n\n return walletClientFactory;\n};\n\n/**\n * Schema for the viem client options.\n */\nexport const GetChainIdOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated get chain id options.\n */\nexport type GetChainIdOptions = Omit<z.infer<typeof GetChainIdOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get the chain id of a blockchain network.\n * @param options - The options for the public client.\n * @returns The chain id.\n * @example\n * ```ts\n * import { getChainId } from '@settlemint/sdk-viem';\n *\n * const chainId = await getChainId({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n * console.log(chainId);\n * ```\n */\nexport async function getChainId(options: GetChainIdOptions): Promise<number> {\n ensureServer();\n const validatedOptions: GetChainIdOptions = validateOptions(GetChainIdOptionsSchema, options);\n\n // Pre-compute headers\n const headers = appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n });\n\n const client = createPublicClient({\n transport: http(validatedOptions.rpcUrl, {\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n return client.getChainId();\n}\n\n// Create a Map for O(1) chain lookups\nconst knownChainsMap = new Map<string, ViemChain>(Object.values(chains).map((chain) => [chain.id.toString(), chain]));\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n // Check if chain is already cached\n const cacheKey = `${chainId}-${chainName}-${rpcUrl}`;\n const cachedChain = chainCache.get(cacheKey);\n if (cachedChain) {\n return cachedChain;\n }\n\n // O(1) lookup for known chains\n const knownChain = knownChainsMap.get(chainId);\n if (knownChain) {\n chainCache.set(cacheKey, knownChain);\n return knownChain;\n }\n\n // Create custom chain definition\n const customChain = defineChain({\n id: Number(chainId),\n name: chainName,\n rpcUrls: {\n default: {\n http: [rpcUrl],\n },\n },\n nativeCurrency: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n });\n\n // Cache the custom chain\n chainCache.set(cacheKey, customChain);\n return customChain;\n}\n\nexport type {\n CreateWalletParameters,\n CreateWalletResponse,\n WalletInfo,\n} from \"./custom-actions/create-wallet.action.js\";\nexport type {\n CreateWalletVerificationParameters,\n CreateWalletVerificationResponse,\n WalletOTPVerificationInfo,\n WalletPincodeVerificationInfo,\n WalletSecretCodesVerificationInfo,\n WalletVerificationInfo,\n} from \"./custom-actions/create-wallet-verification.action.js\";\nexport type {\n CreateWalletVerificationChallengesParameters,\n CreateWalletVerificationChallengesResponse,\n WalletVerificationChallenge,\n} from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nexport type {\n DeleteWalletVerificationParameters,\n DeleteWalletVerificationResponse,\n} from \"./custom-actions/delete-wallet-verification.action.js\";\nexport type {\n GetWalletVerificationsParameters,\n GetWalletVerificationsResponse,\n WalletVerification,\n} from \"./custom-actions/get-wallet-verifications.action.js\";\nexport { OTPAlgorithm, WalletVerificationType } from \"./custom-actions/types/wallet-verification.enum.js\";\nexport type {\n AddressOrObject,\n VerificationResult,\n VerifyWalletVerificationChallengeParameters,\n VerifyWalletVerificationChallengeResponse,\n} from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n"],"mappings":";;;;;;;;;;;;;;AAgDA,SAAgB,aAAaA,QAAgB;AAC3C,QAAO,EAML,aAAaC,MAA+D;AAC1E,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,YAAY,KAAK,UAAW;EAC3C,EAAC;CACH,EACF;AACF;;;;;;;;;AC+BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,mBAAmB,KAAK,sBAAuB;EAC9D,EAAC;CACH,EACF;AACF;;;;;;;;;AC9DD,SAAgB,mCAAmCC,QAAgB;AACjE,QAAO,EAML,mCACEC,MACqD;AACrD,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,eAAgB;EAC/B,EAAC;CACH,EACF;AACF;;;;;;;;;AC3BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,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,EACf,EACF;EACD,gBAAgB;GACd,UAAU;GACV,MAAM;GACN,QAAQ;EACT;CACF,EAAC;CAGF,WAAW,IAAI,UAAU,YAAY;AACrC,QAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"viem.js","names":["client: Client","args: CreateWalletParameters","client: Client","args: CreateWalletVerificationParameters","client: Client","args: CreateWalletVerificationChallengesParameters","client: Client","args: DeleteWalletVerificationParameters","client: Client","args: GetWalletVerificationsParameters","client: Client","args: VerifyWalletVerificationChallengeParameters","maxSize: number","key: K","value: V","options: Partial<ClientOptions>","keyObject: Record<string, unknown>","baseHeaders: HeadersInit | undefined","authHeaders: Record<string, string>","options: ClientOptions","validatedOptions: ClientOptions","verificationOptions?: WalletVerificationOptions","options: GetChainIdOptions","validatedOptions: GetChainIdOptions"],"sources":["../src/custom-actions/create-wallet.action.ts","../src/custom-actions/create-wallet-verification.action.ts","../src/custom-actions/create-wallet-verification-challenges.action.ts","../src/custom-actions/delete-wallet-verification.action.ts","../src/custom-actions/get-wallet-verifications.action.ts","../src/custom-actions/verify-wallet-verification-challenge.action.ts","../src/custom-actions/types/wallet-verification.enum.ts","../src/viem.ts"],"sourcesContent":["import type { Client } from \"viem\";\n\n/**\n * Information about the wallet to be created.\n */\nexport interface WalletInfo {\n /** The name of the wallet. */\n name: string;\n}\n\n/**\n * Parameters for creating a wallet.\n */\nexport interface CreateWalletParameters {\n /** The unique name of the key vault where the wallet will be created. */\n keyVaultId: string;\n /** Information about the wallet to be created. */\n walletInfo: WalletInfo;\n}\n\n/**\n * Response from creating a wallet.\n */\nexport interface CreateWalletResponse {\n /** The unique identifier of the wallet. */\n id: string;\n /** The name of the wallet. */\n name: string;\n /** The blockchain address of the wallet. */\n address: string;\n /** The HD derivation path used to create the wallet. */\n derivationPath: string;\n}\n\n/**\n * RPC schema for wallet creation.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWallet\";\n Parameters: [keyVaultId: string, walletInfo: WalletInfo];\n ReturnType: CreateWalletResponse[];\n};\n\n/**\n * Creates a wallet action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWallet method.\n */\nexport function createWallet(client: Client) {\n return {\n /**\n * Creates a new wallet in the specified key vault.\n * @param args - The parameters for creating a wallet.\n * @returns A promise that resolves to an array of created wallet responses.\n */\n createWallet(args: CreateWalletParameters): Promise<CreateWalletResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWallet\",\n params: [args.keyVaultId, args.walletInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { OTPAlgorithm, WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Base interface for wallet verification information.\n */\ntype BaseWalletVerificationInfo = {\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n};\n\n/**\n * Information for PIN code verification.\n */\nexport interface WalletPincodeVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.PINCODE;\n /** The PIN code to use for verification. */\n pincode: string;\n}\n\n/**\n * Information for One-Time Password (OTP) verification.\n */\nexport interface WalletOTPVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.OTP;\n /** The hash algorithm to use for OTP generation. */\n algorithm?: OTPAlgorithm;\n /** The number of digits in the OTP code. */\n digits?: number;\n /** The time period in seconds for OTP validity. */\n period?: number;\n /** The issuer of the OTP. */\n issuer?: string;\n}\n\n/**\n * Information for secret recovery codes verification.\n */\nexport interface WalletSecretCodesVerificationInfo extends BaseWalletVerificationInfo {\n /** The type of verification method. */\n verificationType: WalletVerificationType.SECRET_CODES;\n}\n\n/**\n * Union type of all possible wallet verification information types.\n */\nexport type WalletVerificationInfo =\n | WalletPincodeVerificationInfo\n | WalletOTPVerificationInfo\n | WalletSecretCodesVerificationInfo;\n\n/**\n * Parameters for creating a wallet verification.\n */\nexport interface CreateWalletVerificationParameters {\n /** The wallet address for which to create the verification. */\n userWalletAddress: string;\n /** The verification information to create. */\n walletVerificationInfo: WalletVerificationInfo;\n}\n\n/**\n * Response from creating a wallet verification.\n */\nexport interface CreateWalletVerificationResponse {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n /** Additional parameters specific to the verification type. */\n parameters: Record<string, string>;\n}\n\n/**\n * RPC schema for creating a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerification\";\n Parameters: [userWalletAddress: string, walletVerificationInfo: WalletVerificationInfo];\n ReturnType: CreateWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerification method.\n */\nexport function createWalletVerification(client: Client) {\n return {\n /**\n * Creates a new wallet verification.\n * @param args - The parameters for creating the verification.\n * @returns A promise that resolves to an array of created wallet verification responses.\n */\n createWalletVerification(args: CreateWalletVerificationParameters): Promise<CreateWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerification\",\n params: [args.userWalletAddress, args.walletVerificationInfo],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\nimport type { AddressOrObject } from \"./verify-wallet-verification-challenge.action.js\";\n\n/**\n * Parameters for creating wallet verification challenges.\n */\nexport interface CreateWalletVerificationChallengesParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n}\n\n/**\n * Represents a wallet verification challenge.\n */\nexport interface WalletVerificationChallenge {\n /** The unique identifier of the challenge. */\n id: string;\n /** The name of the challenge. */\n name: string;\n /** The type of verification required. */\n verificationType: WalletVerificationType;\n /** The challenge parameters specific to the verification type. */\n challenge: Record<string, string>;\n}\n\n/**\n * Response from creating wallet verification challenges.\n */\nexport type CreateWalletVerificationChallengesResponse = WalletVerificationChallenge[];\n\n/**\n * RPC schema for creating wallet verification challenges.\n */\ntype WalletRpcSchema = {\n Method: \"user_createWalletVerificationChallenges\";\n Parameters: [addressOrObject: AddressOrObject];\n ReturnType: CreateWalletVerificationChallengesResponse;\n};\n\n/**\n * Creates a wallet verification challenges action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a createWalletVerificationChallenges method.\n */\nexport function createWalletVerificationChallenges(client: Client) {\n return {\n /**\n * Creates verification challenges for a wallet.\n * @param args - The parameters for creating the challenges.\n * @returns A promise that resolves to an array of wallet verification challenges.\n */\n createWalletVerificationChallenges(\n args: CreateWalletVerificationChallengesParameters,\n ): Promise<CreateWalletVerificationChallengesResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_createWalletVerificationChallenges\",\n params: [args.addressOrObject],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Parameters for deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationParameters {\n /** The wallet address for which to delete the verification. */\n userWalletAddress: string;\n /** The unique identifier of the verification to delete. */\n verificationId: string;\n}\n\n/**\n * Response from deleting a wallet verification.\n */\nexport interface DeleteWalletVerificationResponse {\n /** Whether the deletion was successful. */\n success: boolean;\n}\n\n/**\n * RPC schema for deleting a wallet verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_deleteWalletVerification\";\n Parameters: [userWalletAddress: string, verificationId: string];\n ReturnType: DeleteWalletVerificationResponse[];\n};\n\n/**\n * Creates a wallet verification deletion action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a deleteWalletVerification method.\n */\nexport function deleteWalletVerification(client: Client) {\n return {\n /**\n * Deletes a wallet verification.\n * @param args - The parameters for deleting the verification.\n * @returns A promise that resolves to an array of deletion results.\n */\n deleteWalletVerification(args: DeleteWalletVerificationParameters): Promise<DeleteWalletVerificationResponse[]> {\n return client.request<WalletRpcSchema>({\n method: \"user_deleteWalletVerification\",\n params: [args.userWalletAddress, args.verificationId],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\nimport type { WalletVerificationType } from \"./types/wallet-verification.enum.js\";\n\n/**\n * Parameters for getting wallet verifications.\n */\nexport interface GetWalletVerificationsParameters {\n /** The wallet address for which to fetch verifications. */\n userWalletAddress: string;\n}\n\n/**\n * Represents a wallet verification.\n */\nexport interface WalletVerification {\n /** The unique identifier of the verification. */\n id: string;\n /** The name of the verification method. */\n name: string;\n /** The type of verification method. */\n verificationType: WalletVerificationType;\n}\n\n/**\n * Response from getting wallet verifications.\n */\nexport type GetWalletVerificationsResponse = WalletVerification[];\n\n/**\n * RPC schema for getting wallet verifications.\n */\ntype WalletRpcSchema = {\n Method: \"user_walletVerifications\";\n Parameters: [userWalletAddress: string];\n ReturnType: GetWalletVerificationsResponse;\n};\n\n/**\n * Creates a wallet verifications retrieval action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a getWalletVerifications method.\n */\nexport function getWalletVerifications(client: Client) {\n return {\n /**\n * Gets all verifications for a wallet.\n * @param args - The parameters for getting the verifications.\n * @returns A promise that resolves to an array of wallet verifications.\n */\n getWalletVerifications(args: GetWalletVerificationsParameters): Promise<GetWalletVerificationsResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_walletVerifications\",\n params: [args.userWalletAddress],\n });\n },\n };\n}\n","import type { Client } from \"viem\";\n\n/**\n * Represents either a wallet address string or an object containing wallet address and optional verification ID.\n */\nexport type AddressOrObject =\n | string\n | {\n userWalletAddress: string;\n verificationId?: string;\n };\n\n/**\n * Parameters for verifying a wallet verification challenge.\n */\nexport interface VerifyWalletVerificationChallengeParameters {\n /** The wallet address or object containing wallet address and optional verification ID. */\n addressOrObject: AddressOrObject;\n /** The response to the verification challenge. */\n challengeResponse: string;\n}\n\n/**\n * Result of a wallet verification challenge.\n */\nexport interface VerificationResult {\n /** Whether the verification was successful. */\n verified: boolean;\n}\n\n/**\n * Response from verifying a wallet verification challenge.\n */\nexport type VerifyWalletVerificationChallengeResponse = VerificationResult[];\n\n/**\n * RPC schema for wallet verification challenge verification.\n */\ntype WalletRpcSchema = {\n Method: \"user_verifyWalletVerificationChallenge\";\n Parameters: [addressOrObject: AddressOrObject, challengeResponse: string];\n ReturnType: VerifyWalletVerificationChallengeResponse;\n};\n\n/**\n * Creates a wallet verification challenge verification action for the given client.\n * @param client - The viem client to use for the request.\n * @returns An object with a verifyWalletVerificationChallenge method.\n */\nexport function verifyWalletVerificationChallenge(client: Client) {\n return {\n /**\n * Verifies a wallet verification challenge.\n * @param args - The parameters for verifying the challenge.\n * @returns A promise that resolves to an array of verification results.\n */\n verifyWalletVerificationChallenge(\n args: VerifyWalletVerificationChallengeParameters,\n ): Promise<VerifyWalletVerificationChallengeResponse> {\n return client.request<WalletRpcSchema>({\n method: \"user_verifyWalletVerificationChallenge\",\n params: [args.addressOrObject, args.challengeResponse],\n });\n },\n };\n}\n","/**\n * Types of wallet verification methods supported by the system.\n * Used to identify different verification mechanisms when creating or managing wallet verifications.\n */\nexport enum WalletVerificationType {\n /** PIN code verification method */\n PINCODE = \"PINCODE\",\n /** One-Time Password verification method */\n OTP = \"OTP\",\n /** Secret recovery codes verification method */\n SECRET_CODES = \"SECRET_CODES\",\n}\n\n/**\n * Supported hash algorithms for One-Time Password (OTP) verification.\n * These algorithms determine the cryptographic function used to generate OTP codes.\n */\nexport enum OTPAlgorithm {\n /** SHA-1 hash algorithm */\n SHA1 = \"SHA1\",\n /** SHA-224 hash algorithm */\n SHA224 = \"SHA224\",\n /** SHA-256 hash algorithm */\n SHA256 = \"SHA256\",\n /** SHA-384 hash algorithm */\n SHA384 = \"SHA384\",\n /** SHA-512 hash algorithm */\n SHA512 = \"SHA512\",\n /** SHA3-224 hash algorithm */\n SHA3_224 = \"SHA3-224\",\n /** SHA3-256 hash algorithm */\n SHA3_256 = \"SHA3-256\",\n /** SHA3-384 hash algorithm */\n SHA3_384 = \"SHA3-384\",\n /** SHA3-512 hash algorithm */\n SHA3_512 = \"SHA3-512\",\n}\n","import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport {\n createPublicClient,\n createWalletClient,\n defineChain,\n type HttpTransportConfig,\n http,\n publicActions,\n type Chain as ViemChain,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport * as chains from \"viem/chains\";\nimport { z } from \"zod\";\nimport { createWallet } from \"./custom-actions/create-wallet.action.js\";\nimport { createWalletVerification } from \"./custom-actions/create-wallet-verification.action.js\";\nimport { createWalletVerificationChallenges } from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nimport { deleteWalletVerification } from \"./custom-actions/delete-wallet-verification.action.js\";\nimport { getWalletVerifications } from \"./custom-actions/get-wallet-verifications.action.js\";\nimport { verifyWalletVerificationChallenge } from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n\n// Simple LRU cache implementation\nclass LRUCache<K, V> {\n private cache = new Map<K, V>();\n private readonly maxSize: number;\n\n constructor(maxSize: number) {\n this.maxSize = maxSize;\n }\n\n get(key: K): V | undefined {\n const value = this.cache.get(key);\n if (value !== undefined) {\n // Move to end (most recently used)\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n set(key: K, value: V): void {\n // Remove key if it exists (to update position)\n this.cache.delete(key);\n\n // Check size limit\n if (this.cache.size >= this.maxSize) {\n // Remove least recently used (first item)\n const firstKey = this.cache.keys().next().value;\n if (firstKey !== undefined) {\n this.cache.delete(firstKey);\n }\n }\n\n this.cache.set(key, value);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n// Cache for chain definitions with size limit\nconst chainCache = new LRUCache<string, ViemChain>(100);\n\n// Cache for public clients with size limit\nconst publicClientCache = new LRUCache<string, PublicClient<Transport, ViemChain>>(50);\n\n// Cache for wallet client factories with size limit\nconst walletClientFactoryCache = new LRUCache<\n string,\n (verificationOptions?: WalletVerificationOptions) => ReturnType<typeof createWalletClient>\n>(50);\n\n// Helper to create robust cache key from options\nfunction createCacheKey(options: Partial<ClientOptions>): string {\n // Create a deterministic key by sorting properties\n const keyObject: Record<string, unknown> = {};\n\n // Add properties in sorted order to ensure consistency\n const keys = [\"chainId\", \"chainName\", \"rpcUrl\", \"accessToken\"] as const;\n for (const key of keys) {\n const value = options[key as keyof ClientOptions];\n // Only include defined values\n if (value !== undefined) {\n keyObject[key] = value;\n }\n }\n\n // Use sorted keys for consistent stringification\n return JSON.stringify(keyObject, Object.keys(keyObject).sort());\n}\n\n// Shared utility for building headers\nfunction buildHeaders(baseHeaders: HeadersInit | undefined, authHeaders: Record<string, string>): HeadersInit {\n return appendHeaders(baseHeaders, authHeaders);\n}\n\n/**\n * Schema for the viem client options.\n */\nexport const ClientOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The chain id\n */\n chainId: z.string(),\n /**\n * The chain name\n */\n chainName: z.string(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = Omit<z.infer<typeof ClientOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get a public client. Use this if you need to read from the blockchain.\n * @param options - The options for the public client.\n * @returns The public client. see {@link https://viem.sh/docs/clients/public}\n * @example\n * ```ts\n * import { getPublicClient } from '@settlemint/sdk-viem';\n *\n * const publicClient = getPublicClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the block number\n * const block = await publicClient.getBlockNumber();\n * console.log(block);\n * ```\n */\nexport const getPublicClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validate(ClientOptionsSchema, options);\n\n // Check cache first\n const cacheKey = createCacheKey(validatedOptions);\n const cachedClient = publicClientCache.get(cacheKey);\n if (cachedClient) {\n return cachedClient;\n }\n\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n });\n\n // Create new client\n const client = createPublicClient({\n chain: getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n }),\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n // Cache the client\n publicClientCache.set(cacheKey, client);\n\n return client;\n};\n\n/**\n * The options for the wallet client.\n */\nexport interface WalletVerificationOptions {\n /**\n * The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications.\n */\n verificationId?: string;\n /**\n * The challenge response (used for HD wallets)\n */\n challengeResponse: string;\n}\n\n/**\n * Get a wallet client. Use this if you need to write to the blockchain.\n * @param options - The options for the wallet client.\n * @returns A function that returns a wallet client. The function can be called with verification options for HD wallets. see {@link https://viem.sh/docs/clients/wallet}\n * @example\n * ```ts\n * import { getWalletClient } from '@settlemint/sdk-viem';\n * import { parseAbi } from \"viem\";\n *\n * const walletClient = getWalletClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the chain id\n * const chainId = await walletClient().getChainId();\n * console.log(chainId);\n *\n * // write to the blockchain\n * const transactionHash = await walletClient().writeContract({\n * account: \"0x0000000000000000000000000000000000000000\",\n * address: \"0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2\",\n * abi: parseAbi([\"function mint(uint32 tokenId) nonpayable\"]),\n * functionName: \"mint\",\n * args: [69420],\n * });\n * console.log(transactionHash);\n * ```\n */\nexport const getWalletClient = (options: ClientOptions) => {\n ensureServer();\n const validatedOptions: ClientOptions = validate(ClientOptionsSchema, options);\n\n // Check cache first for the factory function\n const cacheKey = createCacheKey(validatedOptions);\n const cachedFactory = walletClientFactoryCache.get(cacheKey);\n if (cachedFactory) {\n return cachedFactory;\n }\n\n // Get chain (will be cached internally)\n const chain = getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n });\n\n // Create the factory function\n const walletClientFactory = (verificationOptions?: WalletVerificationOptions) => {\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n \"x-auth-challenge-response\": verificationOptions?.challengeResponse ?? \"\",\n \"x-auth-verification-id\": verificationOptions?.verificationId ?? \"\",\n });\n\n return createWalletClient({\n chain: chain,\n pollingInterval: 500,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n })\n .extend(publicActions)\n .extend(createWallet)\n .extend(getWalletVerifications)\n .extend(createWalletVerification)\n .extend(deleteWalletVerification)\n .extend(createWalletVerificationChallenges)\n .extend(verifyWalletVerificationChallenge);\n };\n\n // Cache the factory\n walletClientFactoryCache.set(cacheKey, walletClientFactory);\n\n return walletClientFactory;\n};\n\n/**\n * Schema for the viem client options.\n */\nexport const GetChainIdOptionsSchema = z.object({\n /**\n * The access token\n */\n accessToken: ApplicationAccessTokenSchema.optional(),\n /**\n * The json rpc url\n */\n rpcUrl: UrlOrPathSchema,\n /**\n * The http transport config\n */\n httpTransportConfig: z.any().optional(),\n});\n\n/**\n * Type representing the validated get chain id options.\n */\nexport type GetChainIdOptions = Omit<z.infer<typeof GetChainIdOptionsSchema>, \"httpTransportConfig\"> & {\n httpTransportConfig?: HttpTransportConfig;\n};\n\n/**\n * Get the chain id of a blockchain network.\n * @param options - The options for the public client.\n * @returns The chain id.\n * @example\n * ```ts\n * import { getChainId } from '@settlemint/sdk-viem';\n *\n * const chainId = await getChainId({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n * console.log(chainId);\n * ```\n */\nexport async function getChainId(options: GetChainIdOptions): Promise<number> {\n ensureServer();\n const validatedOptions: GetChainIdOptions = validate(GetChainIdOptionsSchema, options);\n\n // Build headers using shared utility\n const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken || \"\",\n });\n\n const client = createPublicClient({\n transport: http(validatedOptions.rpcUrl, {\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers,\n },\n }),\n });\n\n return client.getChainId();\n}\n\n// Create a Map for O(1) chain lookups\nconst knownChainsMap = new Map<string, ViemChain>(Object.values(chains).map((chain) => [chain.id.toString(), chain]));\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n // Create deterministic cache key\n const cacheKey = JSON.stringify({ chainId, chainName, rpcUrl }, [\"chainId\", \"chainName\", \"rpcUrl\"]);\n\n // Check if chain is already cached\n const cachedChain = chainCache.get(cacheKey);\n if (cachedChain) {\n return cachedChain;\n }\n\n // O(1) lookup for known chains\n const knownChain = knownChainsMap.get(chainId);\n if (knownChain) {\n chainCache.set(cacheKey, knownChain);\n return knownChain;\n }\n\n // Create custom chain definition\n const customChain = defineChain({\n id: Number(chainId),\n name: chainName,\n rpcUrls: {\n default: {\n http: [rpcUrl],\n },\n },\n nativeCurrency: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n });\n\n // Cache the custom chain\n chainCache.set(cacheKey, customChain);\n return customChain;\n}\n\nexport type {\n CreateWalletParameters,\n CreateWalletResponse,\n WalletInfo,\n} from \"./custom-actions/create-wallet.action.js\";\nexport type {\n CreateWalletVerificationParameters,\n CreateWalletVerificationResponse,\n WalletOTPVerificationInfo,\n WalletPincodeVerificationInfo,\n WalletSecretCodesVerificationInfo,\n WalletVerificationInfo,\n} from \"./custom-actions/create-wallet-verification.action.js\";\nexport type {\n CreateWalletVerificationChallengesParameters,\n CreateWalletVerificationChallengesResponse,\n WalletVerificationChallenge,\n} from \"./custom-actions/create-wallet-verification-challenges.action.js\";\nexport type {\n DeleteWalletVerificationParameters,\n DeleteWalletVerificationResponse,\n} from \"./custom-actions/delete-wallet-verification.action.js\";\nexport type {\n GetWalletVerificationsParameters,\n GetWalletVerificationsResponse,\n WalletVerification,\n} from \"./custom-actions/get-wallet-verifications.action.js\";\nexport { OTPAlgorithm, WalletVerificationType } from \"./custom-actions/types/wallet-verification.enum.js\";\nexport type {\n AddressOrObject,\n VerificationResult,\n VerifyWalletVerificationChallengeParameters,\n VerifyWalletVerificationChallengeResponse,\n} from \"./custom-actions/verify-wallet-verification-challenge.action.js\";\n"],"mappings":";;;;;;;;;;;;;;AAgDA,SAAgB,aAAaA,QAAgB;AAC3C,QAAO,EAML,aAAaC,MAA+D;AAC1E,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,YAAY,KAAK,UAAW;EAC3C,EAAC;CACH,EACF;AACF;;;;;;;;;AC+BD,SAAgB,yBAAyBC,QAAgB;AACvD,QAAO,EAML,yBAAyBC,MAAuF;AAC9G,SAAO,OAAO,QAAyB;GACrC,QAAQ;GACR,QAAQ,CAAC,KAAK,mBAAmB,KAAK,sBAAuB;EAC9D,EAAC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eScript Interface for Ethereum) module for SettleMint SDK",
|
|
4
|
-
"version": "2.5.6-
|
|
4
|
+
"version": "2.5.6-pr4a06ef5a",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@settlemint/sdk-utils": "2.5.6-
|
|
56
|
+
"@settlemint/sdk-utils": "2.5.6-pr4a06ef5a",
|
|
57
57
|
"viem": "^2",
|
|
58
58
|
"zod": "^4"
|
|
59
59
|
},
|