@settlemint/sdk-viem 2.5.6-pr2dbc0c80 → 2.5.6-pr38be1f68
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/README.md +8 -8
- package/dist/browser/viem.d.ts +522 -501
- package/dist/browser/viem.js +102 -9
- package/dist/browser/viem.js.map +1 -1
- package/dist/viem.cjs +102 -9
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.d.cts +522 -501
- package/dist/viem.d.ts +522 -501
- package/dist/viem.js +102 -9
- package/dist/viem.js.map +1 -1
- package/package.json +2 -2
package/dist/browser/viem.js
CHANGED
|
@@ -144,6 +144,62 @@ let OTPAlgorithm = /* @__PURE__ */ function(OTPAlgorithm$1) {
|
|
|
144
144
|
|
|
145
145
|
//#endregion
|
|
146
146
|
//#region src/viem.ts
|
|
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);
|
|
178
|
+
function createCacheKey(options) {
|
|
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
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return JSON.stringify(keyObject, Object.keys(keyObject).sort());
|
|
193
|
+
}
|
|
194
|
+
function buildHeaders(baseHeaders, authHeaders) {
|
|
195
|
+
const filteredHeaders = {};
|
|
196
|
+
for (const [key, value] of Object.entries(authHeaders)) {
|
|
197
|
+
if (value !== undefined && value !== "") {
|
|
198
|
+
filteredHeaders[key] = value;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return appendHeaders(baseHeaders, filteredHeaders);
|
|
202
|
+
}
|
|
147
203
|
/**
|
|
148
204
|
* Schema for the viem client options.
|
|
149
205
|
*/
|
|
@@ -177,22 +233,31 @@ const ClientOptionsSchema = z.object({
|
|
|
177
233
|
const getPublicClient = (options) => {
|
|
178
234
|
ensureServer();
|
|
179
235
|
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
180
|
-
|
|
236
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
237
|
+
const cachedClient = publicClientCache.get(cacheKey);
|
|
238
|
+
if (cachedClient) {
|
|
239
|
+
return cachedClient;
|
|
240
|
+
}
|
|
241
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
242
|
+
const client = createPublicClient({
|
|
181
243
|
chain: getChain({
|
|
182
244
|
chainId: validatedOptions.chainId,
|
|
183
245
|
chainName: validatedOptions.chainName,
|
|
184
246
|
rpcUrl: validatedOptions.rpcUrl
|
|
185
247
|
}),
|
|
248
|
+
pollingInterval: 500,
|
|
186
249
|
transport: http(validatedOptions.rpcUrl, {
|
|
187
250
|
batch: true,
|
|
188
251
|
timeout: 6e4,
|
|
189
252
|
...validatedOptions.httpTransportConfig,
|
|
190
253
|
fetchOptions: {
|
|
191
254
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
192
|
-
headers
|
|
255
|
+
headers
|
|
193
256
|
}
|
|
194
257
|
})
|
|
195
258
|
});
|
|
259
|
+
publicClientCache.set(cacheKey, client);
|
|
260
|
+
return client;
|
|
196
261
|
};
|
|
197
262
|
/**
|
|
198
263
|
* Get a wallet client. Use this if you need to write to the blockchain.
|
|
@@ -228,27 +293,35 @@ const getPublicClient = (options) => {
|
|
|
228
293
|
const getWalletClient = (options) => {
|
|
229
294
|
ensureServer();
|
|
230
295
|
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
296
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
297
|
+
const cachedFactory = walletClientFactoryCache.get(cacheKey);
|
|
298
|
+
if (cachedFactory) {
|
|
299
|
+
return cachedFactory;
|
|
300
|
+
}
|
|
231
301
|
const chain = getChain({
|
|
232
302
|
chainId: validatedOptions.chainId,
|
|
233
303
|
chainName: validatedOptions.chainName,
|
|
234
304
|
rpcUrl: validatedOptions.rpcUrl
|
|
235
305
|
});
|
|
236
|
-
|
|
306
|
+
const walletClientFactory = (verificationOptions) => createWalletClient({
|
|
237
307
|
chain,
|
|
308
|
+
pollingInterval: 500,
|
|
238
309
|
transport: http(validatedOptions.rpcUrl, {
|
|
239
310
|
batch: true,
|
|
240
311
|
timeout: 6e4,
|
|
241
312
|
...validatedOptions.httpTransportConfig,
|
|
242
313
|
fetchOptions: {
|
|
243
314
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
244
|
-
headers:
|
|
315
|
+
headers: buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {
|
|
245
316
|
"x-auth-token": validatedOptions.accessToken,
|
|
246
|
-
"x-auth-challenge-response": verificationOptions?.challengeResponse
|
|
247
|
-
"x-auth-verification-id": verificationOptions?.verificationId
|
|
317
|
+
"x-auth-challenge-response": verificationOptions?.challengeResponse,
|
|
318
|
+
"x-auth-verification-id": verificationOptions?.verificationId
|
|
248
319
|
})
|
|
249
320
|
}
|
|
250
321
|
})
|
|
251
322
|
}).extend(publicActions).extend(createWallet).extend(getWalletVerifications).extend(createWalletVerification).extend(deleteWalletVerification).extend(createWalletVerificationChallenges).extend(verifyWalletVerificationChallenge);
|
|
323
|
+
walletClientFactoryCache.set(cacheKey, walletClientFactory);
|
|
324
|
+
return walletClientFactory;
|
|
252
325
|
};
|
|
253
326
|
/**
|
|
254
327
|
* Schema for the viem client options.
|
|
@@ -276,18 +349,36 @@ const GetChainIdOptionsSchema = z.object({
|
|
|
276
349
|
async function getChainId(options) {
|
|
277
350
|
ensureServer();
|
|
278
351
|
const validatedOptions = validate(GetChainIdOptionsSchema, options);
|
|
352
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
279
353
|
const client = createPublicClient({ transport: http(validatedOptions.rpcUrl, {
|
|
280
354
|
...validatedOptions.httpTransportConfig,
|
|
281
355
|
fetchOptions: {
|
|
282
356
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
283
|
-
headers
|
|
357
|
+
headers
|
|
284
358
|
}
|
|
285
359
|
}) });
|
|
286
360
|
return client.getChainId();
|
|
287
361
|
}
|
|
362
|
+
const knownChainsMap = new Map(Object.values(chains).map((chain) => [chain.id.toString(), chain]));
|
|
288
363
|
function getChain({ chainId, chainName, rpcUrl }) {
|
|
289
|
-
const knownChain =
|
|
290
|
-
|
|
364
|
+
const knownChain = knownChainsMap.get(chainId);
|
|
365
|
+
if (knownChain) {
|
|
366
|
+
return knownChain;
|
|
367
|
+
}
|
|
368
|
+
const cacheKey = JSON.stringify({
|
|
369
|
+
chainId,
|
|
370
|
+
chainName,
|
|
371
|
+
rpcUrl
|
|
372
|
+
}, [
|
|
373
|
+
"chainId",
|
|
374
|
+
"chainName",
|
|
375
|
+
"rpcUrl"
|
|
376
|
+
]);
|
|
377
|
+
const cachedChain = chainCache.get(cacheKey);
|
|
378
|
+
if (cachedChain) {
|
|
379
|
+
return cachedChain;
|
|
380
|
+
}
|
|
381
|
+
const customChain = defineChain({
|
|
291
382
|
id: Number(chainId),
|
|
292
383
|
name: chainName,
|
|
293
384
|
rpcUrls: { default: { http: [rpcUrl] } },
|
|
@@ -297,6 +388,8 @@ function getChain({ chainId, chainName, rpcUrl }) {
|
|
|
297
388
|
symbol: "ETH"
|
|
298
389
|
}
|
|
299
390
|
});
|
|
391
|
+
chainCache.set(cacheKey, customChain);
|
|
392
|
+
return customChain;
|
|
300
393
|
}
|
|
301
394
|
|
|
302
395
|
//#endregion
|
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: 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} 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/**\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 return createPublicClient({\n chain: getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n }),\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers: appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n }),\n },\n }),\n });\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 const chain = getChain({\n chainId: validatedOptions.chainId,\n chainName: validatedOptions.chainName,\n rpcUrl: validatedOptions.rpcUrl,\n });\n return (verificationOptions?: WalletVerificationOptions) =>\n createWalletClient({\n chain: chain,\n transport: http(validatedOptions.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n 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 }),\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/**\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 const client = createPublicClient({\n transport: http(validatedOptions.rpcUrl, {\n ...validatedOptions.httpTransportConfig,\n fetchOptions: {\n ...validatedOptions?.httpTransportConfig?.fetchOptions,\n headers: appendHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {\n \"x-auth-token\": validatedOptions.accessToken,\n }),\n },\n }),\n });\n\n return client.getChainId();\n}\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n const knownChain = Object.values(chains).find((chain) => chain.id.toString() === chainId);\n return (\n knownChain ??\n 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}\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,uB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SAAS,EACP,SAAS,EACP,MAAM,CAAC,MAAO,EACf,EACF;EACD,gBAAgB;GACd,UAAU;GACV,MAAM;GACN,QAAQ;EACT;CACF,EAAC;AAEL"}
|
|
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 | undefined>","filteredHeaders: 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\n// Type will be inferred from usage\nconst walletClientFactoryCache = new LRUCache<string, any>(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(\n baseHeaders: HeadersInit | undefined,\n authHeaders: Record<string, string | undefined>,\n): HeadersInit {\n // Filter out undefined values to avoid sending empty string headers\n const filteredHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(authHeaders)) {\n if (value !== undefined && value !== \"\") {\n filteredHeaders[key] = value;\n }\n }\n return appendHeaders(baseHeaders, filteredHeaders);\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 and cache the factory function\n // Using the same pattern as the original to preserve type inference\n const walletClientFactory = (verificationOptions?: WalletVerificationOptions) =>\n 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: 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 }),\n })\n .extend(publicActions)\n .extend(createWallet)\n .extend(getWalletVerifications)\n .extend(createWalletVerification)\n .extend(deleteWalletVerification)\n .extend(createWalletVerificationChallenges)\n .extend(verifyWalletVerificationChallenge);\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 // First check for known chains - O(1) lookup\n // Known chains ignore chainName and rpcUrl, so no need to cache them separately\n const knownChain = knownChainsMap.get(chainId);\n if (knownChain) {\n return knownChain;\n }\n\n // For custom chains, create a cache key using all parameters\n const cacheKey = JSON.stringify({ chainId, chainName, rpcUrl }, [\"chainId\", \"chainName\", \"rpcUrl\"]);\n\n // Check if custom chain is already cached\n const cachedChain = chainCache.get(cacheKey);\n if (cachedChain) {\n return cachedChain;\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 only custom chains\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,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,MAAM;GACN,QAAQ;EACT;CACF,EAAC;CAGF,WAAW,IAAI,UAAU,YAAY;AACrC,QAAO;AACR"}
|
package/dist/viem.cjs
CHANGED
|
@@ -167,6 +167,62 @@ let OTPAlgorithm = /* @__PURE__ */ function(OTPAlgorithm$1) {
|
|
|
167
167
|
|
|
168
168
|
//#endregion
|
|
169
169
|
//#region src/viem.ts
|
|
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);
|
|
201
|
+
function createCacheKey(options) {
|
|
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
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return JSON.stringify(keyObject, Object.keys(keyObject).sort());
|
|
216
|
+
}
|
|
217
|
+
function buildHeaders(baseHeaders, authHeaders) {
|
|
218
|
+
const filteredHeaders = {};
|
|
219
|
+
for (const [key, value] of Object.entries(authHeaders)) {
|
|
220
|
+
if (value !== undefined && value !== "") {
|
|
221
|
+
filteredHeaders[key] = value;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return (0, __settlemint_sdk_utils_http.appendHeaders)(baseHeaders, filteredHeaders);
|
|
225
|
+
}
|
|
170
226
|
/**
|
|
171
227
|
* Schema for the viem client options.
|
|
172
228
|
*/
|
|
@@ -200,22 +256,31 @@ const ClientOptionsSchema = zod.z.object({
|
|
|
200
256
|
const getPublicClient = (options) => {
|
|
201
257
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
202
258
|
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
203
|
-
|
|
259
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
260
|
+
const cachedClient = publicClientCache.get(cacheKey);
|
|
261
|
+
if (cachedClient) {
|
|
262
|
+
return cachedClient;
|
|
263
|
+
}
|
|
264
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
265
|
+
const client = (0, viem.createPublicClient)({
|
|
204
266
|
chain: getChain({
|
|
205
267
|
chainId: validatedOptions.chainId,
|
|
206
268
|
chainName: validatedOptions.chainName,
|
|
207
269
|
rpcUrl: validatedOptions.rpcUrl
|
|
208
270
|
}),
|
|
271
|
+
pollingInterval: 500,
|
|
209
272
|
transport: (0, viem.http)(validatedOptions.rpcUrl, {
|
|
210
273
|
batch: true,
|
|
211
274
|
timeout: 6e4,
|
|
212
275
|
...validatedOptions.httpTransportConfig,
|
|
213
276
|
fetchOptions: {
|
|
214
277
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
215
|
-
headers
|
|
278
|
+
headers
|
|
216
279
|
}
|
|
217
280
|
})
|
|
218
281
|
});
|
|
282
|
+
publicClientCache.set(cacheKey, client);
|
|
283
|
+
return client;
|
|
219
284
|
};
|
|
220
285
|
/**
|
|
221
286
|
* Get a wallet client. Use this if you need to write to the blockchain.
|
|
@@ -251,27 +316,35 @@ const getPublicClient = (options) => {
|
|
|
251
316
|
const getWalletClient = (options) => {
|
|
252
317
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
253
318
|
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
319
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
320
|
+
const cachedFactory = walletClientFactoryCache.get(cacheKey);
|
|
321
|
+
if (cachedFactory) {
|
|
322
|
+
return cachedFactory;
|
|
323
|
+
}
|
|
254
324
|
const chain = getChain({
|
|
255
325
|
chainId: validatedOptions.chainId,
|
|
256
326
|
chainName: validatedOptions.chainName,
|
|
257
327
|
rpcUrl: validatedOptions.rpcUrl
|
|
258
328
|
});
|
|
259
|
-
|
|
329
|
+
const walletClientFactory = (verificationOptions) => (0, viem.createWalletClient)({
|
|
260
330
|
chain,
|
|
331
|
+
pollingInterval: 500,
|
|
261
332
|
transport: (0, viem.http)(validatedOptions.rpcUrl, {
|
|
262
333
|
batch: true,
|
|
263
334
|
timeout: 6e4,
|
|
264
335
|
...validatedOptions.httpTransportConfig,
|
|
265
336
|
fetchOptions: {
|
|
266
337
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
267
|
-
headers: (
|
|
338
|
+
headers: buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {
|
|
268
339
|
"x-auth-token": validatedOptions.accessToken,
|
|
269
|
-
"x-auth-challenge-response": verificationOptions?.challengeResponse
|
|
270
|
-
"x-auth-verification-id": verificationOptions?.verificationId
|
|
340
|
+
"x-auth-challenge-response": verificationOptions?.challengeResponse,
|
|
341
|
+
"x-auth-verification-id": verificationOptions?.verificationId
|
|
271
342
|
})
|
|
272
343
|
}
|
|
273
344
|
})
|
|
274
345
|
}).extend(viem.publicActions).extend(createWallet).extend(getWalletVerifications).extend(createWalletVerification).extend(deleteWalletVerification).extend(createWalletVerificationChallenges).extend(verifyWalletVerificationChallenge);
|
|
346
|
+
walletClientFactoryCache.set(cacheKey, walletClientFactory);
|
|
347
|
+
return walletClientFactory;
|
|
275
348
|
};
|
|
276
349
|
/**
|
|
277
350
|
* Schema for the viem client options.
|
|
@@ -299,18 +372,36 @@ const GetChainIdOptionsSchema = zod.z.object({
|
|
|
299
372
|
async function getChainId(options) {
|
|
300
373
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
301
374
|
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(GetChainIdOptionsSchema, options);
|
|
375
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
302
376
|
const client = (0, viem.createPublicClient)({ transport: (0, viem.http)(validatedOptions.rpcUrl, {
|
|
303
377
|
...validatedOptions.httpTransportConfig,
|
|
304
378
|
fetchOptions: {
|
|
305
379
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
306
|
-
headers
|
|
380
|
+
headers
|
|
307
381
|
}
|
|
308
382
|
}) });
|
|
309
383
|
return client.getChainId();
|
|
310
384
|
}
|
|
385
|
+
const knownChainsMap = new Map(Object.values(viem_chains).map((chain) => [chain.id.toString(), chain]));
|
|
311
386
|
function getChain({ chainId, chainName, rpcUrl }) {
|
|
312
|
-
const knownChain =
|
|
313
|
-
|
|
387
|
+
const knownChain = knownChainsMap.get(chainId);
|
|
388
|
+
if (knownChain) {
|
|
389
|
+
return knownChain;
|
|
390
|
+
}
|
|
391
|
+
const cacheKey = JSON.stringify({
|
|
392
|
+
chainId,
|
|
393
|
+
chainName,
|
|
394
|
+
rpcUrl
|
|
395
|
+
}, [
|
|
396
|
+
"chainId",
|
|
397
|
+
"chainName",
|
|
398
|
+
"rpcUrl"
|
|
399
|
+
]);
|
|
400
|
+
const cachedChain = chainCache.get(cacheKey);
|
|
401
|
+
if (cachedChain) {
|
|
402
|
+
return cachedChain;
|
|
403
|
+
}
|
|
404
|
+
const customChain = (0, viem.defineChain)({
|
|
314
405
|
id: Number(chainId),
|
|
315
406
|
name: chainName,
|
|
316
407
|
rpcUrls: { default: { http: [rpcUrl] } },
|
|
@@ -320,6 +411,8 @@ function getChain({ chainId, chainName, rpcUrl }) {
|
|
|
320
411
|
symbol: "ETH"
|
|
321
412
|
}
|
|
322
413
|
});
|
|
414
|
+
chainCache.set(cacheKey, customChain);
|
|
415
|
+
return customChain;
|
|
323
416
|
}
|
|
324
417
|
|
|
325
418
|
//#endregion
|