@layerzerolabs/lz-utilities 3.0.14 → 3.0.16
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/CHANGELOG.md +16 -0
- package/README.md +135 -0
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +299 -53
- package/dist/index.d.ts +299 -53
- package/dist/index.mjs +27 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -12
package/dist/index.d.ts
CHANGED
|
@@ -5,30 +5,136 @@ import { KeyPair } from '@ton/crypto';
|
|
|
5
5
|
import { WalletContractV4 } from '@ton/ton';
|
|
6
6
|
import { ChainType, EndpointVersion, Network, Chain, EndpointId } from '@layerzerolabs/lz-definitions';
|
|
7
7
|
import { ethers } from 'ethers';
|
|
8
|
+
import { Options } from 'memoizee';
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Interface representing an account mnemonic.
|
|
12
|
+
*/
|
|
9
13
|
interface AccountMnemonic {
|
|
14
|
+
/**
|
|
15
|
+
* The mnemonic phrase.
|
|
16
|
+
*/
|
|
10
17
|
mnemonic: string;
|
|
18
|
+
/**
|
|
19
|
+
* The derivation path.
|
|
20
|
+
*/
|
|
11
21
|
path: string;
|
|
22
|
+
/**
|
|
23
|
+
* The private key (optional).
|
|
24
|
+
*/
|
|
12
25
|
privateKey?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The address (optional).
|
|
28
|
+
*/
|
|
13
29
|
address?: string;
|
|
14
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the BIP-0044 derivation path for a given chain type.
|
|
33
|
+
*
|
|
34
|
+
* @param {ChainType} chainType - The chain type.
|
|
35
|
+
* @param {number} account - The account index.
|
|
36
|
+
* @param {number} change - The change index.
|
|
37
|
+
* @param {number} index - The address index.
|
|
38
|
+
* @returns {string} The BIP-0044 derivation path.
|
|
39
|
+
* @throws {Error} If the chain type is unsupported.
|
|
40
|
+
*/
|
|
15
41
|
declare function getBIP044Path(chainType: ChainType, account: number, change: number, index: number): string;
|
|
42
|
+
/**
|
|
43
|
+
* Gets an EVM account from a mnemonic phrase.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} mnemonic - The mnemonic phrase.
|
|
46
|
+
* @param {string} [path="m/44'/60'/0'/0/0"] - The derivation path.
|
|
47
|
+
* @returns {AccountMnemonic} The EVM account mnemonic.
|
|
48
|
+
*/
|
|
16
49
|
declare function getEvmAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic;
|
|
50
|
+
/**
|
|
51
|
+
* Gets an Aptos account from a mnemonic phrase.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} mnemonic - The mnemonic phrase.
|
|
54
|
+
* @param {string} [path="m/44'/637'/0'/0'/0'"] - The derivation path.
|
|
55
|
+
* @returns {AccountMnemonic} The Aptos account mnemonic.
|
|
56
|
+
* @throws {Error} If the derivation path is invalid.
|
|
57
|
+
*/
|
|
17
58
|
declare function getAptosAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic;
|
|
59
|
+
/**
|
|
60
|
+
* Gets an Initia account from a mnemonic phrase.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} mnemonic - The mnemonic phrase.
|
|
63
|
+
* @param {string} [path="m/44'/118'/0'/0/0"] - The derivation path.
|
|
64
|
+
* @returns {AccountMnemonic} The Initia account mnemonic.
|
|
65
|
+
*/
|
|
18
66
|
declare function getInitiaAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic;
|
|
67
|
+
/**
|
|
68
|
+
* Gets a Solana account from a mnemonic phrase.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} mnemonic - The mnemonic phrase.
|
|
71
|
+
* @param {string} [path="m/44'/501'/0'/0'"] - The derivation path.
|
|
72
|
+
* @returns {AccountMnemonic} The Solana account mnemonic.
|
|
73
|
+
*/
|
|
19
74
|
declare function getSolanaAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic;
|
|
75
|
+
/**
|
|
76
|
+
* Gets a TON account from a mnemonic phrase.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} mnemonic - The mnemonic phrase.
|
|
79
|
+
* @param {string} [path="m/44'/607'/0'/0'/0'"] - The derivation path.
|
|
80
|
+
* @param {number} [workchain=0] - The workChain ID.
|
|
81
|
+
* @returns {Promise<AccountMnemonic>} A promise that resolves to the TON account mnemonic.
|
|
82
|
+
*/
|
|
20
83
|
declare function getTonAccountFromMnemonic(mnemonic: string, path?: string, workchain?: number): Promise<AccountMnemonic>;
|
|
84
|
+
/**
|
|
85
|
+
* Gets a key pair from a mnemonic phrase for a given chain type.
|
|
86
|
+
*
|
|
87
|
+
* @param {ChainType} chainType - The chain type.
|
|
88
|
+
* @param {string} mnemonic - The mnemonic phrase.
|
|
89
|
+
* @param {string} [path] - The derivation path.
|
|
90
|
+
* @returns {Promise<AccountMnemonic>} A promise that resolves to the account mnemonic.
|
|
91
|
+
* @throws {Error} If the chain type is unsupported.
|
|
92
|
+
*/
|
|
21
93
|
declare function getKeypairFromMnemonic(chainType: ChainType, mnemonic: string, path?: string): Promise<AccountMnemonic>;
|
|
94
|
+
/**
|
|
95
|
+
* Gets a TON wallet from a mnemonic phrase.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} mnemonic - The mnemonic phrase.
|
|
98
|
+
* @param {string} [path="m/44'/607'/0'/0'/0'"] - The derivation path.
|
|
99
|
+
* @param {number} [workchain=0] - The workChain ID.
|
|
100
|
+
* @returns {Promise<{ wallet: WalletContractV4; keyPair: KeyPair }>} A promise that resolves to the TON wallet and key pair.
|
|
101
|
+
*/
|
|
22
102
|
declare function getTonWalletFromMnemonic(mnemonic: string, path?: string, workchain?: number): Promise<{
|
|
23
103
|
wallet: WalletContractV4;
|
|
24
104
|
keyPair: KeyPair;
|
|
25
105
|
}>;
|
|
26
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Creates a replacer function for handling circular references in JSON.stringify.
|
|
109
|
+
* details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
|
|
110
|
+
*
|
|
111
|
+
* @returns {(key: string, value: unknown) => unknown} The replacer function.
|
|
112
|
+
*/
|
|
27
113
|
declare function getCircularReplacer(): (key: string, value: unknown) => unknown;
|
|
114
|
+
/**
|
|
115
|
+
* Initializes the logger with the specified log level.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} level - The log level.
|
|
118
|
+
*/
|
|
28
119
|
declare function initLogger(level: string): void;
|
|
120
|
+
/**
|
|
121
|
+
* Creates a new logger with the specified log level.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} level - The log level.
|
|
124
|
+
* @returns {Logger} The created logger.
|
|
125
|
+
*/
|
|
29
126
|
declare function createLogger(level: string): Logger;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the current logger instance.
|
|
129
|
+
*
|
|
130
|
+
* @returns {Logger} The current logger instance.
|
|
131
|
+
* @throws {Error} If the logger is not initialized.
|
|
132
|
+
*/
|
|
30
133
|
declare function getLogger(): Logger;
|
|
31
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Interface representing a contract deployment.
|
|
137
|
+
*/
|
|
32
138
|
interface Deployment {
|
|
33
139
|
/** Name of the contract deployment. */
|
|
34
140
|
name: string;
|
|
@@ -46,12 +152,18 @@ interface Deployment {
|
|
|
46
152
|
bytecode?: string;
|
|
47
153
|
}
|
|
48
154
|
/**
|
|
49
|
-
*
|
|
155
|
+
* Finds the matching deployment based on the given options.
|
|
50
156
|
* @todo Use Partial<EndpointSpec> instead of options
|
|
51
|
-
*
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @
|
|
157
|
+
*
|
|
158
|
+
* @param {Deployment[]} deployments - List of deployments.
|
|
159
|
+
* @param {string} nameOrAddress - Contract name or address.
|
|
160
|
+
* @param {object} options - Options to match against.
|
|
161
|
+
* @param {Chain} [options.chain] - The chain to match.
|
|
162
|
+
* @param {string} [options.source] - The source to match.
|
|
163
|
+
* @param {Network} [options.network] - The network to match.
|
|
164
|
+
* @param {EndpointId} [options.endpointId] - The endpoint ID to match.
|
|
165
|
+
* @returns {Deployment} The matching deployment.
|
|
166
|
+
* @throws {Error} If the deployment is not found.
|
|
55
167
|
*/
|
|
56
168
|
declare function findDeployment(deployments: Deployment[], nameOrAddress: string, options: {
|
|
57
169
|
chain?: Chain;
|
|
@@ -59,13 +171,47 @@ declare function findDeployment(deployments: Deployment[], nameOrAddress: string
|
|
|
59
171
|
network?: Network;
|
|
60
172
|
endpointId?: EndpointId;
|
|
61
173
|
}): Deployment;
|
|
174
|
+
/**
|
|
175
|
+
* Tries to find the matching deployment based on the given options.
|
|
176
|
+
*
|
|
177
|
+
* @param {Deployment[]} deployments - List of deployments.
|
|
178
|
+
* @param {string} nameOrAddress - Contract name or address.
|
|
179
|
+
* @param {object} options - Options to match against.
|
|
180
|
+
* @param {Chain} [options.chain] - The chain to match.
|
|
181
|
+
* @param {string} [options.source] - The source to match.
|
|
182
|
+
* @param {Network} [options.network] - The network to match.
|
|
183
|
+
* @param {EndpointId} [options.endpointId] - The endpoint ID to match.
|
|
184
|
+
* @returns {Deployment | undefined} The matching deployment, or undefined if not found.
|
|
185
|
+
*/
|
|
62
186
|
declare function tryFindDeployment(deployments: Deployment[], nameOrAddress: string, options: {
|
|
63
187
|
chain?: Chain;
|
|
64
188
|
source?: string;
|
|
65
189
|
network?: Network;
|
|
66
190
|
endpointId?: EndpointId;
|
|
67
191
|
}): Deployment | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* Converts a deployment to an EVM contract.
|
|
194
|
+
*
|
|
195
|
+
* @param {Deployment} deployment - The deployment to convert.
|
|
196
|
+
* @param {ethers.providers.Provider} [provider] - The provider to use.
|
|
197
|
+
* @returns {T} The EVM contract.
|
|
198
|
+
* @throws {Error} If the deployment does not have ABI or bytecode.
|
|
199
|
+
*/
|
|
68
200
|
declare function deploymentToEvmContract<T extends ethers.Contract>(deployment: Deployment, provider?: ethers.providers.Provider): T;
|
|
201
|
+
/**
|
|
202
|
+
* Finds a contract based on the given options.
|
|
203
|
+
*
|
|
204
|
+
* @param {ethers.providers.Provider | undefined} provider - The provider to use.
|
|
205
|
+
* @param {Deployment[]} deployments - List of deployments.
|
|
206
|
+
* @param {string} nameOrAddress - Contract name or address.
|
|
207
|
+
* @param {object} options - Options to match against.
|
|
208
|
+
* @param {Chain} [options.chain] - The chain to match.
|
|
209
|
+
* @param {string} [options.source] - The source to match.
|
|
210
|
+
* @param {Network} [options.network] - The network to match.
|
|
211
|
+
* @param {EndpointId} [options.endpointId] - The endpoint ID to match.
|
|
212
|
+
* @returns {T} The matching contract.
|
|
213
|
+
* @throws {Error} If the deployment is not found.
|
|
214
|
+
*/
|
|
69
215
|
declare function findContract<T extends ethers.Contract>(provider: ethers.providers.Provider | undefined, deployments: Deployment[], nameOrAddress: string, options: {
|
|
70
216
|
chain?: Chain;
|
|
71
217
|
source?: string;
|
|
@@ -74,16 +220,18 @@ declare function findContract<T extends ethers.Contract>(provider: ethers.provid
|
|
|
74
220
|
}): T;
|
|
75
221
|
|
|
76
222
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @
|
|
223
|
+
* Returns the directory name of a path.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} path - The path to get the directory name from.
|
|
226
|
+
* @returns {string} The directory name of the path.
|
|
80
227
|
*/
|
|
81
228
|
declare function dirname(path: string): string;
|
|
82
229
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @param
|
|
86
|
-
* @
|
|
230
|
+
* Returns the root path of a package.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} packageName - The name of the package.
|
|
233
|
+
* @param {string} [relativeToPath] - The path to resolve the package root relative to.
|
|
234
|
+
* @returns {string} The root path of the package.
|
|
87
235
|
*/
|
|
88
236
|
declare function pkgroot(packageName: string, relativeToPath?: string): string;
|
|
89
237
|
|
|
@@ -177,32 +325,66 @@ declare function isHash(value: string): value is Hash;
|
|
|
177
325
|
*/
|
|
178
326
|
type Bytes = Uint8Array;
|
|
179
327
|
|
|
328
|
+
/**
|
|
329
|
+
* Asserts that a condition is true. If the condition is false, throws an error with the provided message.
|
|
330
|
+
*
|
|
331
|
+
* @param {boolean} condition - The condition to assert.
|
|
332
|
+
* @param {string} [message] - The error message to throw if the condition is false.
|
|
333
|
+
* @throws {Error} If the condition is false.
|
|
334
|
+
*/
|
|
180
335
|
declare function assert(condition: boolean, message?: string): asserts condition;
|
|
181
336
|
/**
|
|
182
|
-
*
|
|
337
|
+
* Asserts that a value is of a certain type, using a type guard function.
|
|
183
338
|
* assertType can be used to assert that a value is of a certain type, and without naming a new variable explicitly.
|
|
184
|
-
*
|
|
185
|
-
* @param
|
|
186
|
-
* @param
|
|
339
|
+
*
|
|
340
|
+
* @param {T} value - The value to assert the type of.
|
|
341
|
+
* @param {(v: unknown) => v is M} fn - The type guard function.
|
|
342
|
+
* @param {string} [message] - The error message to throw if the value is not of the expected type.
|
|
343
|
+
* @throws {Error} If the value is not of the expected type.
|
|
187
344
|
*/
|
|
188
345
|
declare function assertType<T, M>(value: T, fn: (v: unknown) => v is M, message?: string): asserts value is T & M;
|
|
346
|
+
/**
|
|
347
|
+
* Asserts that a value is defined (not undefined or null).
|
|
348
|
+
*
|
|
349
|
+
* @param {T} [value] - The value to assert is defined.
|
|
350
|
+
* @param {string} [message] - The error message to throw if the value is undefined or null.
|
|
351
|
+
* @throws {Error} If the value is undefined or null.
|
|
352
|
+
*/
|
|
189
353
|
declare function assertDefined<T>(value?: T, message?: string): asserts value is NonNullable<T>;
|
|
354
|
+
/**
|
|
355
|
+
* Asserts that a value is of a certain type, using a type guard function, and returns the value.
|
|
356
|
+
*
|
|
357
|
+
* @param {T} value - The value to assert the type of.
|
|
358
|
+
* @param {(v: unknown) => v is M} fn - The type guard function.
|
|
359
|
+
* @param {string} [message] - The error message to throw if the value is not of the expected type.
|
|
360
|
+
* @returns {M} The value, asserted to be of the expected type.
|
|
361
|
+
* @throws {Error} If the value is not of the expected type.
|
|
362
|
+
*/
|
|
190
363
|
declare function asType<T, M>(value: T, fn: (v: unknown) => v is M, message?: string): M;
|
|
364
|
+
/**
|
|
365
|
+
* Assumes that a value is of a certain type. This function does not perform any runtime checks.
|
|
366
|
+
*
|
|
367
|
+
* @param {unknown} value - The value to assume the type of.
|
|
368
|
+
*/
|
|
191
369
|
declare function assumeType<T>(value: unknown): asserts value is T;
|
|
192
370
|
|
|
193
371
|
/**
|
|
194
372
|
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
|
|
195
|
-
*
|
|
196
|
-
*
|
|
373
|
+
* If an error occurs during the execution of the callback function, the function returns the results up to that point and the error.
|
|
374
|
+
*
|
|
375
|
+
* @param {T[]} elements - The array to map over.
|
|
376
|
+
* @param {(item: T, index: number) => R} callbackfn - A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
|
|
377
|
+
* @returns {[R[], Error | undefined]} A tuple containing the array of results and an optional error.
|
|
197
378
|
*/
|
|
198
379
|
declare function safeMap<T, R>(elements: T[], callbackfn: (item: T, index: number) => R): [R[], Error | undefined];
|
|
199
380
|
|
|
200
381
|
/**
|
|
201
382
|
* Converts a string or number value to a corresponding enum value.
|
|
202
|
-
*
|
|
203
|
-
* @param
|
|
204
|
-
* @
|
|
205
|
-
* @
|
|
383
|
+
*
|
|
384
|
+
* @param {T} enumType - The enum object.
|
|
385
|
+
* @param {string | number} value - The value to convert.
|
|
386
|
+
* @returns {T[keyof T]} The converted enum value.
|
|
387
|
+
* @throws {Error} If the value is not a valid enum value.
|
|
206
388
|
* @example
|
|
207
389
|
* // Usage
|
|
208
390
|
* enum Color {
|
|
@@ -224,14 +406,32 @@ declare function safeMap<T, R>(elements: T[], callbackfn: (item: T, index: numbe
|
|
|
224
406
|
*/
|
|
225
407
|
declare function asEnum<T extends object>(enumType: T, value: string | number): T[keyof T];
|
|
226
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Interface representing the options for padding.
|
|
411
|
+
*/
|
|
227
412
|
interface PadOptions {
|
|
413
|
+
/**
|
|
414
|
+
* The direction of the padding. Defaults to undefined.
|
|
415
|
+
*/
|
|
228
416
|
dir?: 'left' | 'right' | undefined;
|
|
417
|
+
/**
|
|
418
|
+
* The size to pad to. Defaults to 32.
|
|
419
|
+
*/
|
|
229
420
|
size?: number | null | undefined;
|
|
230
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Type representing the return type of the padify function.
|
|
424
|
+
*/
|
|
231
425
|
type PadReturnType<value extends Bytes | Hex> = value extends Hex ? Hex : Bytes;
|
|
426
|
+
/**
|
|
427
|
+
* Type representing an error when the size exceeds the padding size.
|
|
428
|
+
*/
|
|
232
429
|
type SizeExceedsPaddingSizeErrorType = SizeExceedsPaddingSizeError & {
|
|
233
430
|
name: 'SizeExceedsPaddingSizeError';
|
|
234
431
|
};
|
|
432
|
+
/**
|
|
433
|
+
* Class representing an error when the size exceeds the padding size.
|
|
434
|
+
*/
|
|
235
435
|
declare class SizeExceedsPaddingSizeError extends Error {
|
|
236
436
|
name: string;
|
|
237
437
|
constructor({ size, targetSize, type }: {
|
|
@@ -243,55 +443,62 @@ declare class SizeExceedsPaddingSizeError extends Error {
|
|
|
243
443
|
/**
|
|
244
444
|
* Pads a hexadecimal string or byte array to a specified size.
|
|
245
445
|
*
|
|
246
|
-
* @param hexOrBytes - The hexadecimal string or byte array to pad.
|
|
247
|
-
* @param options - The padding options.
|
|
248
|
-
* @param options.dir - The direction of the padding. Defaults to undefined.
|
|
249
|
-
* @param options.size - The size to pad to. Defaults to 32.
|
|
250
|
-
* @returns The padded hexadecimal string or byte array.
|
|
446
|
+
* @param {Bytes | Hex} hexOrBytes - The hexadecimal string or byte array to pad.
|
|
447
|
+
* @param {PadOptions} [options] - The padding options.
|
|
448
|
+
* @param {'left' | 'right'} [options.dir] - The direction of the padding. Defaults to undefined.
|
|
449
|
+
* @param {number} [options.size=32] - The size to pad to. Defaults to 32.
|
|
450
|
+
* @returns {PadReturnType<Bytes | Hex>} The padded hexadecimal string or byte array.
|
|
451
|
+
* @throws {SizeExceedsPaddingSizeError} If the size exceeds the padding size.
|
|
251
452
|
*/
|
|
252
453
|
declare function padify<value extends Bytes | Hex>(hexOrBytes: value, { dir, size }?: PadOptions): PadReturnType<value>;
|
|
253
454
|
|
|
254
455
|
/**
|
|
255
|
-
* A function to convert Uint8Array to hex string
|
|
256
|
-
* @deprecated use `hexlify` instead
|
|
257
|
-
* @param bytes
|
|
258
|
-
* @returns
|
|
456
|
+
* A function to convert Uint8Array to hex string.
|
|
457
|
+
* @deprecated use `hexlify` instead.
|
|
458
|
+
* @param {Uint8Array} bytes - The bytes to convert.
|
|
459
|
+
* @returns {string} Hex string without 0x prefix, e.g., '0102030405'.
|
|
259
460
|
*/
|
|
260
461
|
declare function bytesToHex(bytes: Uint8Array): string;
|
|
261
462
|
/**
|
|
262
|
-
* A function to convert hex string to Uint8Array
|
|
263
|
-
* @deprecated use `arrayify` instead
|
|
264
|
-
* @param
|
|
265
|
-
* @returns Uint8Array
|
|
463
|
+
* A function to convert hex string to Uint8Array.
|
|
464
|
+
* @deprecated use `arrayify` instead.
|
|
465
|
+
* @param {string} hex - Hex string, e.g., '0x0102030405' or '0102030405'.
|
|
466
|
+
* @returns {Uint8Array} The converted Uint8Array.
|
|
266
467
|
*/
|
|
267
468
|
declare function hexToBytes(hex: string): Uint8Array;
|
|
268
469
|
/**
|
|
269
|
-
* A function to trim the prefix 0x from a hex string
|
|
270
|
-
* @param
|
|
271
|
-
* @returns
|
|
470
|
+
* A function to trim the prefix 0x from a hex string.
|
|
471
|
+
* @param {string} hex - Hex string.
|
|
472
|
+
* @returns {string} Hex string without 0x prefix.
|
|
272
473
|
*/
|
|
273
474
|
declare function trim0x(hex: string): string;
|
|
274
475
|
/**
|
|
275
|
-
* A function to ensure the prefix 0x from a hex string
|
|
276
|
-
* @param
|
|
277
|
-
* @returns
|
|
476
|
+
* A function to ensure the prefix 0x from a hex string.
|
|
477
|
+
* @param {string} hex - Hex string.
|
|
478
|
+
* @returns {Hex} Hex string with 0x prefix.
|
|
479
|
+
* @throws {Error} If the input is not a valid hex string.
|
|
278
480
|
*/
|
|
279
481
|
declare function ensure0x(hex: string): Hex;
|
|
280
482
|
/**
|
|
281
|
-
* A function to check if a string is a hex string
|
|
282
|
-
* @deprecated use `isHex` instead
|
|
283
|
-
* @param value
|
|
284
|
-
* @returns
|
|
483
|
+
* A function to check if a string is a hex string.
|
|
484
|
+
* @deprecated use `isHex` instead.
|
|
485
|
+
* @param {string} value - The string to check.
|
|
486
|
+
* @returns {boolean} True if the string is a hex string, false otherwise.
|
|
285
487
|
*/
|
|
286
488
|
declare function isHexString(value: string): boolean;
|
|
287
489
|
/**
|
|
288
|
-
* A function to convert a string|number|Uint8Array|Buffer|BigInt to Uint8Array
|
|
289
|
-
* @param value -
|
|
290
|
-
* @param size -
|
|
490
|
+
* A function to convert a string|number|Uint8Array|Buffer|BigInt to Uint8Array.
|
|
491
|
+
* @param {string | number | Uint8Array | Buffer | bigint} value - The value to convert.
|
|
492
|
+
* @param {number} [size] - The size of the Uint8Array to return, if not specified, the size of the input will be returned.
|
|
493
|
+
* @returns {Uint8Array} The converted Uint8Array.
|
|
494
|
+
* @throws {Error} If the input type is unsupported.
|
|
291
495
|
*/
|
|
292
496
|
declare function arrayify(value: string | number | Uint8Array | Buffer | bigint, size?: number): Uint8Array;
|
|
293
497
|
/**
|
|
294
|
-
* A function to convert a string|number|Uint8Array|Buffer|BigInt to hex string
|
|
498
|
+
* A function to convert a string|number|Uint8Array|Buffer|BigInt to hex string.
|
|
499
|
+
* @param {string | number | Uint8Array | Buffer | bigint} value - The value to convert.
|
|
500
|
+
* @returns {Hex} The converted hex string.
|
|
501
|
+
* @throws {Error} If the input type is unsupported.
|
|
295
502
|
*/
|
|
296
503
|
declare function hexlify(value: string | number | Uint8Array | Buffer | bigint): Hex;
|
|
297
504
|
|
|
@@ -431,9 +638,10 @@ type RequireAtLeastOne<T> = {
|
|
|
431
638
|
|
|
432
639
|
/**
|
|
433
640
|
* Finds files in the current directory and its parent directories.
|
|
434
|
-
*
|
|
435
|
-
* @param
|
|
436
|
-
* @
|
|
641
|
+
*
|
|
642
|
+
* @param {string} cwd - The current working directory.
|
|
643
|
+
* @param {string[]} expectations - The expected file names.
|
|
644
|
+
* @returns {string[]} An array of file paths that match the expectations.
|
|
437
645
|
*/
|
|
438
646
|
declare function findUp(cwd: string, expectations: string[]): string[];
|
|
439
647
|
|
|
@@ -467,15 +675,53 @@ declare function enableTS(relativeToPath: string): void;
|
|
|
467
675
|
*/
|
|
468
676
|
declare function loadJSorTS(fileName: string, relativeToPath: string): Promise<any>;
|
|
469
677
|
|
|
678
|
+
declare function Memoizee<F extends (...args: any[]) => any>(options?: Options<F>): MethodDecorator;
|
|
679
|
+
|
|
470
680
|
declare const logger: winston.Logger;
|
|
681
|
+
/**
|
|
682
|
+
* Sleeps for the specified timeout.
|
|
683
|
+
*
|
|
684
|
+
* @param {number} timeout - The timeout in milliseconds.
|
|
685
|
+
* @returns {Promise<void>} A promise that resolves after the timeout.
|
|
686
|
+
*/
|
|
471
687
|
declare function sleep(timeout: number): Promise<void>;
|
|
688
|
+
/**
|
|
689
|
+
* Gets the package manager used in the project.
|
|
690
|
+
*
|
|
691
|
+
* @param {string} [cwd] - The current working directory.
|
|
692
|
+
* @returns {'yarn' | 'npm' | 'pnpm'} The package manager used in the project.
|
|
693
|
+
* @throws {Error} If no package manager is found.
|
|
694
|
+
*/
|
|
472
695
|
declare function getProjectPackageManager(cwd?: string): 'yarn' | 'npm' | 'pnpm';
|
|
696
|
+
/**
|
|
697
|
+
* Gets the root directory of the project.
|
|
698
|
+
*
|
|
699
|
+
* @param {string} [cwd] - The current working directory.
|
|
700
|
+
* @returns {string} The root directory of the project.
|
|
701
|
+
* @throws {Error} If no root directory is found.
|
|
702
|
+
*/
|
|
473
703
|
declare function getProjectRootDir(cwd?: string): string;
|
|
704
|
+
/**
|
|
705
|
+
* Checks if an HTTP service is reachable.
|
|
706
|
+
*
|
|
707
|
+
* @param {string} host - The host of the HTTP service.
|
|
708
|
+
* @param {number} port - The port of the HTTP service.
|
|
709
|
+
* @param {number} timeout - The timeout in milliseconds.
|
|
710
|
+
* @param {string} [path] - The path to check.
|
|
711
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the service is reachable, false otherwise.
|
|
712
|
+
*/
|
|
474
713
|
declare function isHttpServiceReachable(host: string, port: number, timeout: number, path?: string): Promise<boolean>;
|
|
714
|
+
/**
|
|
715
|
+
* Extracts information from a URL.
|
|
716
|
+
*
|
|
717
|
+
* @param {string} url - The URL to extract information from.
|
|
718
|
+
* @returns {{ schema: 'http' | 'https'; host: string; port: string }} An object containing the schema, host, and port.
|
|
719
|
+
* @throws {Error} If the URL is invalid.
|
|
720
|
+
*/
|
|
475
721
|
declare function extractUrlInfo(url: string): {
|
|
476
722
|
schema: 'http' | 'https';
|
|
477
723
|
host: string;
|
|
478
724
|
port: string;
|
|
479
725
|
};
|
|
480
726
|
|
|
481
|
-
export { type AccountMnemonic, type AtLeast, type Bytes, type DeepPartial, type DeepRequired, type Deployment, type Factory, type Hash, type Hex, type NestedKeys, type NonPromise, type PadReturnType, type RequireAtLeastOne, type RequiredOnly, SizeExceedsPaddingSizeError, type SizeExceedsPaddingSizeErrorType, arrayify, asEnum, asType, assert, assertDefined, assertType, assumeType, bytesToHex, createLogger, deploymentToEvmContract, dirname, enableTS, ensure0x, extractUrlInfo, findContract, findDeployment, findUp, first, firstFactory, getAptosAccountFromMnemonic, getBIP044Path, getCircularReplacer, getEvmAccountFromMnemonic, getInitiaAccountFromMnemonic, getKeypairFromMnemonic, getLogger, getProjectPackageManager, getProjectRootDir, getSolanaAccountFromMnemonic, getTonAccountFromMnemonic, getTonWalletFromMnemonic, hasRequiredProperties, hexToBytes, hexlify, initLogger, isHash, isHex, isHexString, isHttpServiceReachable, loadJSorTS, logger, padify, parallel, pkgroot, safeMap, sequence, sleep, trim0x, tryFindDeployment };
|
|
727
|
+
export { type AccountMnemonic, type AtLeast, type Bytes, type DeepPartial, type DeepRequired, type Deployment, type Factory, type Hash, type Hex, Memoizee, type NestedKeys, type NonPromise, type PadReturnType, type RequireAtLeastOne, type RequiredOnly, SizeExceedsPaddingSizeError, type SizeExceedsPaddingSizeErrorType, arrayify, asEnum, asType, assert, assertDefined, assertType, assumeType, bytesToHex, createLogger, deploymentToEvmContract, dirname, enableTS, ensure0x, extractUrlInfo, findContract, findDeployment, findUp, first, firstFactory, getAptosAccountFromMnemonic, getBIP044Path, getCircularReplacer, getEvmAccountFromMnemonic, getInitiaAccountFromMnemonic, getKeypairFromMnemonic, getLogger, getProjectPackageManager, getProjectRootDir, getSolanaAccountFromMnemonic, getTonAccountFromMnemonic, getTonWalletFromMnemonic, hasRequiredProperties, hexToBytes, hexlify, initLogger, isHash, isHex, isHexString, isHttpServiceReachable, loadJSorTS, logger, padify, parallel, pkgroot, safeMap, sequence, sleep, trim0x, tryFindDeployment };
|
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { format } from 'winston';
|
|
|
15
15
|
export { Logger } from 'winston';
|
|
16
16
|
import { createRequire } from 'module';
|
|
17
17
|
import * as fs from 'fs';
|
|
18
|
+
import memoizee from 'memoizee';
|
|
18
19
|
import { sync } from 'find-up';
|
|
19
20
|
|
|
20
21
|
// src/index.ts
|
|
@@ -573,6 +574,31 @@ async function loadJSorTS(fileName, relativeToPath) {
|
|
|
573
574
|
throw new Error(`Unsupported file extension: ${fileName}`);
|
|
574
575
|
}
|
|
575
576
|
}
|
|
577
|
+
function Memoizee(options) {
|
|
578
|
+
return function(target, propertyKey, descriptor) {
|
|
579
|
+
const originalMethod = descriptor.value;
|
|
580
|
+
if (typeof originalMethod !== "function") {
|
|
581
|
+
throw new Error(`@Memoizee decorator can only be applied to methods.`);
|
|
582
|
+
}
|
|
583
|
+
const isAsyncFunction = originalMethod.constructor.name === "AsyncFunction";
|
|
584
|
+
const memoizeOptions = {
|
|
585
|
+
...options,
|
|
586
|
+
promise: options?.promise ?? isAsyncFunction
|
|
587
|
+
};
|
|
588
|
+
if (!isAsyncFunction) {
|
|
589
|
+
const originalMethodStr = originalMethod.toString();
|
|
590
|
+
if (originalMethodStr.includes("callback") || originalMethodStr.includes("cb")) {
|
|
591
|
+
memoizeOptions.async = true;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const memoizedFn = memoizee(originalMethod, memoizeOptions);
|
|
595
|
+
const fn = memoizedFn;
|
|
596
|
+
fn.clear = () => {
|
|
597
|
+
memoizedFn.clear();
|
|
598
|
+
};
|
|
599
|
+
descriptor.value = fn;
|
|
600
|
+
};
|
|
601
|
+
}
|
|
576
602
|
var logger2 = getLogger();
|
|
577
603
|
async function sleep(timeout) {
|
|
578
604
|
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
@@ -631,6 +657,6 @@ function extractUrlInfo(url) {
|
|
|
631
657
|
};
|
|
632
658
|
}
|
|
633
659
|
|
|
634
|
-
export { SizeExceedsPaddingSizeError, arrayify, asEnum, asType, assert, assertDefined, assertType, assumeType, bytesToHex, createLogger2 as createLogger, deploymentToEvmContract, dirname, enableTS, ensure0x, extractUrlInfo, findContract, findDeployment, findUp, first, firstFactory, getAptosAccountFromMnemonic, getBIP044Path, getCircularReplacer, getEvmAccountFromMnemonic, getInitiaAccountFromMnemonic, getKeypairFromMnemonic, getLogger, getProjectPackageManager, getProjectRootDir, getSolanaAccountFromMnemonic, getTonAccountFromMnemonic, getTonWalletFromMnemonic, hasRequiredProperties, hexToBytes, hexlify, initLogger, isHash, isHex, isHexString, isHttpServiceReachable, loadJSorTS, logger2 as logger, padify, parallel, pkgroot, safeMap, sequence, sleep, trim0x, tryFindDeployment };
|
|
660
|
+
export { Memoizee, SizeExceedsPaddingSizeError, arrayify, asEnum, asType, assert, assertDefined, assertType, assumeType, bytesToHex, createLogger2 as createLogger, deploymentToEvmContract, dirname, enableTS, ensure0x, extractUrlInfo, findContract, findDeployment, findUp, first, firstFactory, getAptosAccountFromMnemonic, getBIP044Path, getCircularReplacer, getEvmAccountFromMnemonic, getInitiaAccountFromMnemonic, getKeypairFromMnemonic, getLogger, getProjectPackageManager, getProjectRootDir, getSolanaAccountFromMnemonic, getTonAccountFromMnemonic, getTonWalletFromMnemonic, hasRequiredProperties, hexToBytes, hexlify, initLogger, isHash, isHex, isHexString, isHttpServiceReachable, loadJSorTS, logger2 as logger, padify, parallel, pkgroot, safeMap, sequence, sleep, trim0x, tryFindDeployment };
|
|
635
661
|
//# sourceMappingURL=out.js.map
|
|
636
662
|
//# sourceMappingURL=index.mjs.map
|