@settlemint/sdk-viem 2.5.6 → 2.5.7
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 +91 -101
- package/dist/browser/viem.d.ts +522 -501
- package/dist/browser/viem.js +106 -7
- package/dist/browser/viem.js.map +1 -1
- package/dist/viem.cjs +106 -7
- 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 +106 -7
- package/dist/viem.js.map +1 -1
- package/package.json +2 -2
package/dist/browser/viem.js
CHANGED
|
@@ -144,6 +144,68 @@ 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
|
+
if (options.httpTransportConfig) {
|
|
193
|
+
const { onFetchRequest, onFetchResponse,...serializableConfig } = options.httpTransportConfig;
|
|
194
|
+
if (Object.keys(serializableConfig).length > 0) {
|
|
195
|
+
keyObject.httpTransportConfig = serializableConfig;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return JSON.stringify(keyObject, Object.keys(keyObject).sort());
|
|
199
|
+
}
|
|
200
|
+
function buildHeaders(baseHeaders, authHeaders) {
|
|
201
|
+
const filteredHeaders = {};
|
|
202
|
+
for (const [key, value] of Object.entries(authHeaders)) {
|
|
203
|
+
if (value !== undefined) {
|
|
204
|
+
filteredHeaders[key] = value;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return appendHeaders(baseHeaders, filteredHeaders);
|
|
208
|
+
}
|
|
147
209
|
/**
|
|
148
210
|
* Schema for the viem client options.
|
|
149
211
|
*/
|
|
@@ -177,22 +239,31 @@ const ClientOptionsSchema = z.object({
|
|
|
177
239
|
const getPublicClient = (options) => {
|
|
178
240
|
ensureServer();
|
|
179
241
|
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
180
|
-
|
|
242
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
243
|
+
const cachedClient = publicClientCache.get(cacheKey);
|
|
244
|
+
if (cachedClient) {
|
|
245
|
+
return cachedClient;
|
|
246
|
+
}
|
|
247
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
248
|
+
const client = createPublicClient({
|
|
181
249
|
chain: getChain({
|
|
182
250
|
chainId: validatedOptions.chainId,
|
|
183
251
|
chainName: validatedOptions.chainName,
|
|
184
252
|
rpcUrl: validatedOptions.rpcUrl
|
|
185
253
|
}),
|
|
254
|
+
pollingInterval: 500,
|
|
186
255
|
transport: http(validatedOptions.rpcUrl, {
|
|
187
256
|
batch: true,
|
|
188
257
|
timeout: 6e4,
|
|
189
258
|
...validatedOptions.httpTransportConfig,
|
|
190
259
|
fetchOptions: {
|
|
191
260
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
192
|
-
headers
|
|
261
|
+
headers
|
|
193
262
|
}
|
|
194
263
|
})
|
|
195
264
|
});
|
|
265
|
+
publicClientCache.set(cacheKey, client);
|
|
266
|
+
return client;
|
|
196
267
|
};
|
|
197
268
|
/**
|
|
198
269
|
* Get a wallet client. Use this if you need to write to the blockchain.
|
|
@@ -228,20 +299,26 @@ const getPublicClient = (options) => {
|
|
|
228
299
|
const getWalletClient = (options) => {
|
|
229
300
|
ensureServer();
|
|
230
301
|
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
302
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
303
|
+
const cachedFactory = walletClientFactoryCache.get(cacheKey);
|
|
304
|
+
if (cachedFactory) {
|
|
305
|
+
return cachedFactory;
|
|
306
|
+
}
|
|
231
307
|
const chain = getChain({
|
|
232
308
|
chainId: validatedOptions.chainId,
|
|
233
309
|
chainName: validatedOptions.chainName,
|
|
234
310
|
rpcUrl: validatedOptions.rpcUrl
|
|
235
311
|
});
|
|
236
|
-
|
|
312
|
+
const walletClientFactory = (verificationOptions) => createWalletClient({
|
|
237
313
|
chain,
|
|
314
|
+
pollingInterval: 500,
|
|
238
315
|
transport: http(validatedOptions.rpcUrl, {
|
|
239
316
|
batch: true,
|
|
240
317
|
timeout: 6e4,
|
|
241
318
|
...validatedOptions.httpTransportConfig,
|
|
242
319
|
fetchOptions: {
|
|
243
320
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
244
|
-
headers:
|
|
321
|
+
headers: buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {
|
|
245
322
|
"x-auth-token": validatedOptions.accessToken,
|
|
246
323
|
"x-auth-challenge-response": verificationOptions?.challengeResponse ?? "",
|
|
247
324
|
"x-auth-verification-id": verificationOptions?.verificationId ?? ""
|
|
@@ -249,6 +326,8 @@ const getWalletClient = (options) => {
|
|
|
249
326
|
}
|
|
250
327
|
})
|
|
251
328
|
}).extend(publicActions).extend(createWallet).extend(getWalletVerifications).extend(createWalletVerification).extend(deleteWalletVerification).extend(createWalletVerificationChallenges).extend(verifyWalletVerificationChallenge);
|
|
329
|
+
walletClientFactoryCache.set(cacheKey, walletClientFactory);
|
|
330
|
+
return walletClientFactory;
|
|
252
331
|
};
|
|
253
332
|
/**
|
|
254
333
|
* Schema for the viem client options.
|
|
@@ -276,18 +355,36 @@ const GetChainIdOptionsSchema = z.object({
|
|
|
276
355
|
async function getChainId(options) {
|
|
277
356
|
ensureServer();
|
|
278
357
|
const validatedOptions = validate(GetChainIdOptionsSchema, options);
|
|
358
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
279
359
|
const client = createPublicClient({ transport: http(validatedOptions.rpcUrl, {
|
|
280
360
|
...validatedOptions.httpTransportConfig,
|
|
281
361
|
fetchOptions: {
|
|
282
362
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
283
|
-
headers
|
|
363
|
+
headers
|
|
284
364
|
}
|
|
285
365
|
}) });
|
|
286
366
|
return client.getChainId();
|
|
287
367
|
}
|
|
368
|
+
const knownChainsMap = new Map(Object.values(chains).map((chain) => [chain.id.toString(), chain]));
|
|
288
369
|
function getChain({ chainId, chainName, rpcUrl }) {
|
|
289
|
-
const knownChain =
|
|
290
|
-
|
|
370
|
+
const knownChain = knownChainsMap.get(chainId);
|
|
371
|
+
if (knownChain) {
|
|
372
|
+
return knownChain;
|
|
373
|
+
}
|
|
374
|
+
const cacheKey = JSON.stringify({
|
|
375
|
+
chainId,
|
|
376
|
+
chainName,
|
|
377
|
+
rpcUrl
|
|
378
|
+
}, [
|
|
379
|
+
"chainId",
|
|
380
|
+
"chainName",
|
|
381
|
+
"rpcUrl"
|
|
382
|
+
]);
|
|
383
|
+
const cachedChain = chainCache.get(cacheKey);
|
|
384
|
+
if (cachedChain) {
|
|
385
|
+
return cachedChain;
|
|
386
|
+
}
|
|
387
|
+
const customChain = defineChain({
|
|
291
388
|
id: Number(chainId),
|
|
292
389
|
name: chainName,
|
|
293
390
|
rpcUrls: { default: { http: [rpcUrl] } },
|
|
@@ -297,6 +394,8 @@ function getChain({ chainId, chainName, rpcUrl }) {
|
|
|
297
394
|
symbol: "ETH"
|
|
298
395
|
}
|
|
299
396
|
});
|
|
397
|
+
chainCache.set(cacheKey, customChain);
|
|
398
|
+
return customChain;
|
|
300
399
|
}
|
|
301
400
|
|
|
302
401
|
//#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,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AO,CAAC,KAAK,CAAC,UAAU,MAAM,GAAG,UAAU,KAAK,QAAQ;AACzF,QACE,cACA,YAAY;EACV,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;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 // Include serializable parts of httpTransportConfig if present\n if (options.httpTransportConfig) {\n const { onFetchRequest, onFetchResponse, ...serializableConfig } = options.httpTransportConfig;\n if (Object.keys(serializableConfig).length > 0) {\n keyObject.httpTransportConfig = serializableConfig;\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 // Only include headers with actual values\n const filteredHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(authHeaders)) {\n if (value !== undefined) {\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 VerifyWalletVerificationChallengeRes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AAU,EAAE,KAAM,EAAC;AAEpH,SAAS,SAAS,EAAE,SAAS,WAAW,QAAiE,EAAa;CAGpH,MAAM,aAAa,eAAe,IAAI,QAAQ;AAC9C,KAAI,YAAY;AACd,SAAO;CACR;CAGD,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,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,6 +167,68 @@ 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
|
+
if (options.httpTransportConfig) {
|
|
216
|
+
const { onFetchRequest, onFetchResponse,...serializableConfig } = options.httpTransportConfig;
|
|
217
|
+
if (Object.keys(serializableConfig).length > 0) {
|
|
218
|
+
keyObject.httpTransportConfig = serializableConfig;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return JSON.stringify(keyObject, Object.keys(keyObject).sort());
|
|
222
|
+
}
|
|
223
|
+
function buildHeaders(baseHeaders, authHeaders) {
|
|
224
|
+
const filteredHeaders = {};
|
|
225
|
+
for (const [key, value] of Object.entries(authHeaders)) {
|
|
226
|
+
if (value !== undefined) {
|
|
227
|
+
filteredHeaders[key] = value;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return (0, __settlemint_sdk_utils_http.appendHeaders)(baseHeaders, filteredHeaders);
|
|
231
|
+
}
|
|
170
232
|
/**
|
|
171
233
|
* Schema for the viem client options.
|
|
172
234
|
*/
|
|
@@ -200,22 +262,31 @@ const ClientOptionsSchema = zod.z.object({
|
|
|
200
262
|
const getPublicClient = (options) => {
|
|
201
263
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
202
264
|
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
203
|
-
|
|
265
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
266
|
+
const cachedClient = publicClientCache.get(cacheKey);
|
|
267
|
+
if (cachedClient) {
|
|
268
|
+
return cachedClient;
|
|
269
|
+
}
|
|
270
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
271
|
+
const client = (0, viem.createPublicClient)({
|
|
204
272
|
chain: getChain({
|
|
205
273
|
chainId: validatedOptions.chainId,
|
|
206
274
|
chainName: validatedOptions.chainName,
|
|
207
275
|
rpcUrl: validatedOptions.rpcUrl
|
|
208
276
|
}),
|
|
277
|
+
pollingInterval: 500,
|
|
209
278
|
transport: (0, viem.http)(validatedOptions.rpcUrl, {
|
|
210
279
|
batch: true,
|
|
211
280
|
timeout: 6e4,
|
|
212
281
|
...validatedOptions.httpTransportConfig,
|
|
213
282
|
fetchOptions: {
|
|
214
283
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
215
|
-
headers
|
|
284
|
+
headers
|
|
216
285
|
}
|
|
217
286
|
})
|
|
218
287
|
});
|
|
288
|
+
publicClientCache.set(cacheKey, client);
|
|
289
|
+
return client;
|
|
219
290
|
};
|
|
220
291
|
/**
|
|
221
292
|
* Get a wallet client. Use this if you need to write to the blockchain.
|
|
@@ -251,20 +322,26 @@ const getPublicClient = (options) => {
|
|
|
251
322
|
const getWalletClient = (options) => {
|
|
252
323
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
253
324
|
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
325
|
+
const cacheKey = createCacheKey(validatedOptions);
|
|
326
|
+
const cachedFactory = walletClientFactoryCache.get(cacheKey);
|
|
327
|
+
if (cachedFactory) {
|
|
328
|
+
return cachedFactory;
|
|
329
|
+
}
|
|
254
330
|
const chain = getChain({
|
|
255
331
|
chainId: validatedOptions.chainId,
|
|
256
332
|
chainName: validatedOptions.chainName,
|
|
257
333
|
rpcUrl: validatedOptions.rpcUrl
|
|
258
334
|
});
|
|
259
|
-
|
|
335
|
+
const walletClientFactory = (verificationOptions) => (0, viem.createWalletClient)({
|
|
260
336
|
chain,
|
|
337
|
+
pollingInterval: 500,
|
|
261
338
|
transport: (0, viem.http)(validatedOptions.rpcUrl, {
|
|
262
339
|
batch: true,
|
|
263
340
|
timeout: 6e4,
|
|
264
341
|
...validatedOptions.httpTransportConfig,
|
|
265
342
|
fetchOptions: {
|
|
266
343
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
267
|
-
headers: (
|
|
344
|
+
headers: buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, {
|
|
268
345
|
"x-auth-token": validatedOptions.accessToken,
|
|
269
346
|
"x-auth-challenge-response": verificationOptions?.challengeResponse ?? "",
|
|
270
347
|
"x-auth-verification-id": verificationOptions?.verificationId ?? ""
|
|
@@ -272,6 +349,8 @@ const getWalletClient = (options) => {
|
|
|
272
349
|
}
|
|
273
350
|
})
|
|
274
351
|
}).extend(viem.publicActions).extend(createWallet).extend(getWalletVerifications).extend(createWalletVerification).extend(deleteWalletVerification).extend(createWalletVerificationChallenges).extend(verifyWalletVerificationChallenge);
|
|
352
|
+
walletClientFactoryCache.set(cacheKey, walletClientFactory);
|
|
353
|
+
return walletClientFactory;
|
|
275
354
|
};
|
|
276
355
|
/**
|
|
277
356
|
* Schema for the viem client options.
|
|
@@ -299,18 +378,36 @@ const GetChainIdOptionsSchema = zod.z.object({
|
|
|
299
378
|
async function getChainId(options) {
|
|
300
379
|
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
301
380
|
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(GetChainIdOptionsSchema, options);
|
|
381
|
+
const headers = buildHeaders(validatedOptions?.httpTransportConfig?.fetchOptions?.headers, { "x-auth-token": validatedOptions.accessToken });
|
|
302
382
|
const client = (0, viem.createPublicClient)({ transport: (0, viem.http)(validatedOptions.rpcUrl, {
|
|
303
383
|
...validatedOptions.httpTransportConfig,
|
|
304
384
|
fetchOptions: {
|
|
305
385
|
...validatedOptions?.httpTransportConfig?.fetchOptions,
|
|
306
|
-
headers
|
|
386
|
+
headers
|
|
307
387
|
}
|
|
308
388
|
}) });
|
|
309
389
|
return client.getChainId();
|
|
310
390
|
}
|
|
391
|
+
const knownChainsMap = new Map(Object.values(viem_chains).map((chain) => [chain.id.toString(), chain]));
|
|
311
392
|
function getChain({ chainId, chainName, rpcUrl }) {
|
|
312
|
-
const knownChain =
|
|
313
|
-
|
|
393
|
+
const knownChain = knownChainsMap.get(chainId);
|
|
394
|
+
if (knownChain) {
|
|
395
|
+
return knownChain;
|
|
396
|
+
}
|
|
397
|
+
const cacheKey = JSON.stringify({
|
|
398
|
+
chainId,
|
|
399
|
+
chainName,
|
|
400
|
+
rpcUrl
|
|
401
|
+
}, [
|
|
402
|
+
"chainId",
|
|
403
|
+
"chainName",
|
|
404
|
+
"rpcUrl"
|
|
405
|
+
]);
|
|
406
|
+
const cachedChain = chainCache.get(cacheKey);
|
|
407
|
+
if (cachedChain) {
|
|
408
|
+
return cachedChain;
|
|
409
|
+
}
|
|
410
|
+
const customChain = (0, viem.defineChain)({
|
|
314
411
|
id: Number(chainId),
|
|
315
412
|
name: chainName,
|
|
316
413
|
rpcUrls: { default: { http: [rpcUrl] } },
|
|
@@ -320,6 +417,8 @@ function getChain({ chainId, chainName, rpcUrl }) {
|
|
|
320
417
|
symbol: "ETH"
|
|
321
418
|
}
|
|
322
419
|
});
|
|
420
|
+
chainCache.set(cacheKey, customChain);
|
|
421
|
+
return customChain;
|
|
323
422
|
}
|
|
324
423
|
|
|
325
424
|
//#endregion
|