near-api-js 7.0.0-rc.0 → 7.0.0-rc.2

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.
Files changed (54) hide show
  1. package/lib/accounts/account.d.ts +27 -22
  2. package/lib/accounts/account.js +67 -29
  3. package/lib/accounts/nonce-manager.d.ts +9 -0
  4. package/lib/accounts/nonce-manager.js +43 -0
  5. package/lib/crypto/key_pair_ed25519.js +2 -2
  6. package/lib/crypto/key_pair_secp256k1.js +1 -1
  7. package/lib/crypto/public_key.js +1 -1
  8. package/lib/index.d.ts +1 -0
  9. package/lib/index.js +1 -0
  10. package/lib/nep413/schema.js +1 -1
  11. package/lib/providers/errors/contract_execution.d.ts +152 -0
  12. package/lib/providers/errors/contract_execution.js +230 -0
  13. package/lib/providers/errors/handler.d.ts +121 -0
  14. package/lib/providers/errors/handler.js +182 -0
  15. package/lib/providers/errors/parse.d.ts +11 -0
  16. package/lib/providers/errors/parse.js +607 -0
  17. package/lib/providers/errors/request_validation.d.ts +9 -0
  18. package/lib/providers/errors/request_validation.js +11 -0
  19. package/lib/providers/errors/rpc.d.ts +5 -0
  20. package/lib/providers/errors/rpc.js +8 -0
  21. package/lib/providers/errors/transaction_execution.d.ts +306 -0
  22. package/lib/providers/errors/transaction_execution.js +457 -0
  23. package/lib/providers/failover-rpc-provider.d.ts +44 -38
  24. package/lib/providers/failover-rpc-provider.js +10 -11
  25. package/lib/providers/fetch_json.d.ts +2 -8
  26. package/lib/providers/fetch_json.js +0 -3
  27. package/lib/providers/json-rpc-provider.d.ts +75 -37
  28. package/lib/providers/json-rpc-provider.js +123 -60
  29. package/lib/providers/methods.d.ts +163 -0
  30. package/lib/providers/methods.js +1 -0
  31. package/lib/providers/provider.d.ts +49 -29
  32. package/lib/rpc/index.d.ts +1 -0
  33. package/lib/rpc/index.js +2 -0
  34. package/lib/rpc/types.gen.d.ts +6120 -0
  35. package/lib/rpc/types.gen.js +47 -0
  36. package/lib/signers/signer.js +1 -1
  37. package/lib/transactions/action_creators.d.ts +0 -1
  38. package/lib/transactions/schema.d.ts +3 -3
  39. package/lib/types/provider/response.d.ts +2 -2
  40. package/lib/units/gas.d.ts +3 -0
  41. package/lib/units/gas.js +9 -0
  42. package/lib/units/index.d.ts +2 -0
  43. package/lib/units/index.js +2 -0
  44. package/lib/units/near.d.ts +3 -0
  45. package/lib/units/near.js +22 -0
  46. package/lib/units/types.d.ts +2 -0
  47. package/lib/units/types.js +1 -0
  48. package/lib/units/utils.d.ts +2 -0
  49. package/lib/units/utils.js +23 -0
  50. package/lib/utils/format.d.ts +4 -0
  51. package/lib/utils/format.js +4 -0
  52. package/lib/utils/provider.d.ts +2 -1
  53. package/lib/utils/provider.js +4 -1
  54. package/package.json +25 -22
@@ -1,10 +1,10 @@
1
1
  import { type KeyPairString, PublicKey } from '../crypto/index.js';
2
- import type { Provider } from '../providers/index.js';
2
+ import { type Provider } from '../providers/index.js';
3
3
  import { type SignedMessage, type Signer } from '../signers/index.js';
4
4
  import type { SignDelegateActionReturn } from '../signers/signer.js';
5
5
  import type { FungibleToken, NativeToken } from '../tokens/index.js';
6
6
  import { type Action, type DelegateAction, type SignedTransaction } from '../transactions/index.js';
7
- import type { AccessKeyList, AccessKeyView, ContractCodeView, ContractStateView, FinalExecutionOutcome, SerializedReturnValue, TxExecutionStatus } from '../types/index.js';
7
+ import type { FinalExecutionOutcome, SerializedReturnValue, TxExecutionStatus } from '../types/index.js';
8
8
  export declare const DEFAULT_WAIT_STATUS: TxExecutionStatus;
9
9
  export interface AccountState {
10
10
  balance: {
@@ -44,6 +44,7 @@ export interface SignAndSendTransactionArgs {
44
44
  waitUntil?: TxExecutionStatus;
45
45
  throwOnFailure?: boolean;
46
46
  signer?: Signer;
47
+ retries?: number;
47
48
  }
48
49
  export interface SignAndSendTransactionsArgs {
49
50
  transactions: Array<{
@@ -99,7 +100,8 @@ export declare class Account {
99
100
  readonly accountId: string;
100
101
  readonly provider: Provider;
101
102
  private signer?;
102
- constructor(accountId: string, provider: Provider, signer?: Signer | KeyPairString);
103
+ private readonly nonceManager;
104
+ constructor(accountId: string, provider: Provider | string, signer?: Signer | KeyPairString);
103
105
  /**
104
106
  * Allows to set the signer used to control the account
105
107
  *
@@ -116,21 +118,27 @@ export declare class Account {
116
118
  * Calls {@link Provider.viewAccessKey} to retrieve information for a
117
119
  * specific key in the account
118
120
  */
119
- getAccessKey(publicKey: PublicKey | string): Promise<AccessKeyView>;
121
+ getAccessKey(publicKey: PublicKey | string): Promise<import("../types/index.js").AccessKeyView>;
120
122
  /**
121
123
  * Calls {@link Provider.viewAccessKeyList} to retrieve the account's keys
122
124
  */
123
- getAccessKeyList(): Promise<AccessKeyList>;
125
+ getAccessKeyList(): Promise<import("../rpc/types.gen.js").AccessKeyList & {
126
+ block_hash: import("../rpc/types.gen.js").CryptoHash;
127
+ block_height: number;
128
+ }>;
124
129
  /**
125
130
  * Calls {@link Provider.viewContractCode} to retrieve the account's
126
131
  * contract code and its hash
127
132
  */
128
- getContractCode(): Promise<ContractCodeView>;
133
+ getContractCode(): Promise<import("../types/index.js").ContractCodeView>;
129
134
  /**
130
135
  * Calls {@link Provider.viewContractState} to retrieve the keys and values
131
136
  * stored on the account's contract
132
137
  */
133
- getContractState(prefix?: string): Promise<ContractStateView>;
138
+ getContractState(prefix?: string): Promise<import("../rpc/types.gen.js").ViewStateResult & {
139
+ block_hash: import("../rpc/types.gen.js").CryptoHash;
140
+ block_height: number;
141
+ }>;
134
142
  /**
135
143
  * Create a transaction that can be later signed with a {@link Signer}
136
144
  *
@@ -168,8 +176,8 @@ export declare class Account {
168
176
  * @returns {Promise<FinalExecutionOutcome>} A promise that resolves to the final execution outcome of the transaction.
169
177
  *
170
178
  */
171
- signAndSendTransaction({ receiverId, actions, waitUntil, throwOnFailure, signer, }: SignAndSendTransactionArgs): Promise<FinalExecutionOutcome>;
172
- signAndSendTransactions({ transactions, waitUntil, throwOnFailure, signer, }: SignAndSendTransactionsArgs): Promise<FinalExecutionOutcome[]>;
179
+ signAndSendTransaction({ receiverId, actions, waitUntil, throwOnFailure, signer, retries, }: SignAndSendTransactionArgs): any;
180
+ signAndSendTransactions({ transactions, waitUntil, throwOnFailure, signer, }: SignAndSendTransactionsArgs): Promise<any[]>;
173
181
  /**
174
182
  * Creates a new NEAR account with a given ID and public key.
175
183
  *
@@ -186,7 +194,7 @@ export declare class Account {
186
194
  * @param nearToTransfer how much NEAR to transfer to the account in yoctoNEAR (default: 0)
187
195
  *
188
196
  */
189
- createAccount({ newAccountId, publicKey, nearToTransfer, }: CreateAccountArgs): Promise<FinalExecutionOutcome>;
197
+ createAccount({ newAccountId, publicKey, nearToTransfer }: CreateAccountArgs): Promise<any>;
190
198
  /**
191
199
  * Creates a sub account of this account. For example, if the account is
192
200
  * ana.near, you can create sub.ana.near.
@@ -196,7 +204,7 @@ export declare class Account {
196
204
  * @param nearToTransfer how much NEAR to transfer to the account (default: 0)
197
205
  *
198
206
  */
199
- createSubAccount({ accountOrPrefix, publicKey, nearToTransfer, }: CreateSubAccountArgs): Promise<FinalExecutionOutcome>;
207
+ createSubAccount({ accountOrPrefix, publicKey, nearToTransfer }: CreateSubAccountArgs): Promise<any>;
200
208
  /**
201
209
  * Deletes the account, transferring all remaining NEAR to a beneficiary
202
210
  * account
@@ -205,20 +213,20 @@ export declare class Account {
205
213
  *
206
214
  * @param beneficiaryId Will receive the account's remaining balance
207
215
  */
208
- deleteAccount(beneficiaryId: string): Promise<FinalExecutionOutcome>;
216
+ deleteAccount(beneficiaryId: string): Promise<any>;
209
217
  /**
210
218
  * Deploy a smart contract in the account
211
219
  *
212
220
  * @param code The compiled contract code bytes
213
221
  */
214
- deployContract(code: Uint8Array): Promise<FinalExecutionOutcome>;
222
+ deployContract(code: Uint8Array): Promise<any>;
215
223
  /**
216
224
  * Deploy a global contract that can be reused by multiple accounts
217
225
  *
218
226
  * @param code The compiled contract code bytes
219
227
  * @param deployMode Deploy mode - "codeHash" for immutable contracts, "accountId" for updateable contracts
220
228
  */
221
- deployGlobalContract(code: Uint8Array, deployMode: 'codeHash' | 'accountId'): Promise<FinalExecutionOutcome>;
229
+ deployGlobalContract(code: Uint8Array, deployMode: 'codeHash' | 'accountId'): Promise<any>;
222
230
  /**
223
231
  * Use a previously deployed global contract on this account
224
232
  *
@@ -228,7 +236,7 @@ export declare class Account {
228
236
  accountId: string;
229
237
  } | {
230
238
  codeHash: string | Uint8Array;
231
- }): Promise<FinalExecutionOutcome>;
239
+ }): Promise<any>;
232
240
  /**
233
241
  *
234
242
  * @param options
@@ -238,19 +246,17 @@ export declare class Account {
238
246
  * @param options.allowance The amount of NEAR this key can expend in gas
239
247
  * @returns
240
248
  */
241
- addFunctionCallAccessKey({ publicKey, contractId, methodNames, allowance, }: AddFunctionAccessKeyArgs): Promise<FinalExecutionOutcome>;
249
+ addFunctionCallAccessKey({ publicKey, contractId, methodNames, allowance, }: AddFunctionAccessKeyArgs): Promise<any>;
242
250
  /**
243
251
  * Add a full access key to the account
244
252
  *
245
253
  * @param publicKey The public key to be added
246
- * @returns {Promise<FinalExecutionOutcome>}
247
254
  */
248
- addFullAccessKey(publicKey: PublicKey | string): Promise<FinalExecutionOutcome>;
255
+ addFullAccessKey(publicKey: PublicKey | string): Promise<any>;
249
256
  /**
250
257
  * @param publicKey The public key to be deleted
251
- * @returns {Promise<FinalExecutionOutcome>}
252
258
  */
253
- deleteKey(publicKey: PublicKey | string): Promise<FinalExecutionOutcome>;
259
+ deleteKey(publicKey: PublicKey | string): Promise<any>;
254
260
  /**
255
261
  * Call a function on a smart contract and return parsed transaction result
256
262
  *
@@ -274,9 +280,8 @@ export declare class Account {
274
280
  * @param options.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
275
281
  * @param options.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
276
282
  * @param options.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
277
- * @returns {FinalExecutionOutcome}
278
283
  */
279
- callFunctionRaw({ contractId, methodName, args, deposit, gas, waitUntil, }: CallFunctionArgs): Promise<FinalExecutionOutcome>;
284
+ callFunctionRaw({ contractId, methodName, args, deposit, gas, waitUntil, }: CallFunctionArgs): Promise<any>;
280
285
  /**
281
286
  * This function simply calls the `signNep413Message` method of the Signer
282
287
  *
@@ -1,8 +1,12 @@
1
1
  import { PublicKey } from '../crypto/index.js';
2
+ import { parseTransactionExecutionError } from '../providers/errors/parse.js';
3
+ import { InvalidNonceError } from '../providers/errors/transaction_execution.js';
4
+ import { JsonRpcProvider } from '../providers/index.js';
2
5
  import { KeyPairSigner } from '../signers/index.js';
3
6
  import { NEAR } from '../tokens/index.js';
4
7
  import { actionCreators, buildDelegateAction, createTransaction, GlobalContractDeployMode, GlobalContractIdentifier, } from '../transactions/index.js';
5
- import { baseDecode, getTransactionLastResult, parseResultError } from '../utils/index.js';
8
+ import { baseDecode, getTransactionLastResult } from '../utils/index.js';
9
+ import { NonceManager } from './nonce-manager.js';
6
10
  const { addKey, createAccount, deleteAccount, deleteKey, deployContract, deployGlobalContract, fullAccessKey, functionCall, functionCallAccessKey, transfer, useGlobalContract, } = actionCreators;
7
11
  const DEFAULT_FINALITY = 'optimistic';
8
12
  export const DEFAULT_WAIT_STATUS = 'EXECUTED_OPTIMISTIC';
@@ -16,13 +20,19 @@ const DEFAULT_FUNCTION_CALL_GAS = 30000000000000n; // 30 TGas
16
20
  export class Account {
17
21
  constructor(accountId, provider, signer) {
18
22
  this.accountId = accountId;
19
- this.provider = provider;
23
+ if (typeof provider === 'string') {
24
+ this.provider = new JsonRpcProvider({ url: provider });
25
+ }
26
+ else {
27
+ this.provider = provider;
28
+ }
20
29
  if (typeof signer === 'string') {
21
30
  this.signer = KeyPairSigner.fromSecretKey(signer);
22
31
  }
23
32
  else {
24
33
  this.signer = signer;
25
34
  }
35
+ this.nonceManager = new NonceManager();
26
36
  }
27
37
  /**
28
38
  * Allows to set the signer used to control the account
@@ -40,15 +50,21 @@ export class Account {
40
50
  * balance, storage usage, and code hash
41
51
  */
42
52
  async getState() {
43
- const protocolConfig = await this.provider.experimental_protocolConfig({
44
- finality: DEFAULT_FINALITY,
45
- });
46
- const state = await this.provider.viewAccount({
47
- accountId: this.accountId,
48
- blockQuery: {
53
+ const [protocolConfig, state] = await Promise.all([
54
+ this.provider.experimental_protocolConfig({
49
55
  finality: DEFAULT_FINALITY,
50
- },
51
- });
56
+ }),
57
+ this.provider.viewAccount({
58
+ accountId: this.accountId,
59
+ blockQuery: {
60
+ finality: DEFAULT_FINALITY,
61
+ },
62
+ }),
63
+ ]);
64
+ if (typeof protocolConfig.runtime_config !== 'object' || protocolConfig.runtime_config === null)
65
+ throw new Error('runtime_config is not defined in protocol config');
66
+ if (typeof protocolConfig.runtime_config.storage_amount_per_byte === 'undefined')
67
+ throw new Error('runtime_config.storage_amount_per_byte is not defined in protocol config');
52
68
  const costPerByte = BigInt(protocolConfig.runtime_config.storage_amount_per_byte);
53
69
  const usedOnStorage = BigInt(state.storage_usage) * costPerByte;
54
70
  const locked = BigInt(state.locked);
@@ -125,13 +141,14 @@ export class Account {
125
141
  if (!publicKey)
126
142
  throw new Error('Please provide a public key');
127
143
  const pk = PublicKey.from(publicKey);
128
- const accessKey = await this.getAccessKey(pk);
129
- const block = await this.provider.viewBlock({
130
- finality: DEFAULT_FINALITY,
131
- });
144
+ const [nonce, block] = await Promise.all([
145
+ this.nonceManager.resolveNextNonce(pk, this.accountId, this.provider),
146
+ this.provider.viewBlock({
147
+ finality: DEFAULT_FINALITY,
148
+ }),
149
+ ]);
132
150
  const recentBlockHash = block.header.hash;
133
- const nonce = BigInt(accessKey.nonce) + 1n;
134
- return createTransaction(this.accountId, pk, receiverId, nonce + 1n, actions, baseDecode(recentBlockHash));
151
+ return createTransaction(this.accountId, pk, receiverId, nonce, actions, baseDecode(recentBlockHash));
135
152
  }
136
153
  /**
137
154
  * Create a signed transaction ready to be broadcast by a {@link Provider}
@@ -158,12 +175,14 @@ export class Account {
158
175
  if (!publicKey)
159
176
  throw new Error('Please provide a public key');
160
177
  const pk = PublicKey.from(publicKey);
161
- const accessKey = await this.getAccessKey(pk);
178
+ const [accessKey, block] = await Promise.all([
179
+ this.getAccessKey(pk),
180
+ this.provider.viewBlock({
181
+ finality: DEFAULT_FINALITY,
182
+ }),
183
+ ]);
162
184
  const nonce = BigInt(accessKey.nonce) + 1n;
163
- const { header } = await this.provider.viewBlock({
164
- finality: DEFAULT_FINALITY,
165
- });
166
- const maxBlockHeight = BigInt(header.height) + BigInt(blockHeightTtl);
185
+ const maxBlockHeight = BigInt(block.header.height) + BigInt(blockHeightTtl);
167
186
  return buildDelegateAction({
168
187
  receiverId,
169
188
  senderId: this.accountId,
@@ -200,18 +219,40 @@ export class Account {
200
219
  * @returns {Promise<FinalExecutionOutcome>} A promise that resolves to the final execution outcome of the transaction.
201
220
  *
202
221
  */
203
- async signAndSendTransaction({ receiverId, actions, waitUntil = DEFAULT_WAIT_STATUS, throwOnFailure = true, signer = this.signer, }) {
222
+ async signAndSendTransaction({ receiverId, actions, waitUntil = DEFAULT_WAIT_STATUS, throwOnFailure = true, signer = this.signer, retries = 3, }) {
204
223
  const signedTx = await this.createSignedTransaction({
205
224
  receiverId,
206
225
  actions,
207
226
  signer,
208
227
  });
209
- const result = await this.provider.sendTransactionUntil(signedTx, waitUntil);
228
+ let result;
229
+ try {
230
+ result = await this.provider.sendTransactionUntil(signedTx, waitUntil);
231
+ }
232
+ catch (error) {
233
+ if (error instanceof InvalidNonceError) {
234
+ // invalidate nonce cache so we don't send another transaction with stale nonce
235
+ await this.nonceManager.invalidate(signedTx.transaction.publicKey);
236
+ if (retries > 0) {
237
+ return this.signAndSendTransaction({
238
+ receiverId,
239
+ actions,
240
+ waitUntil,
241
+ throwOnFailure,
242
+ signer,
243
+ retries: retries - 1,
244
+ });
245
+ }
246
+ }
247
+ throw error;
248
+ }
210
249
  if (throwOnFailure &&
211
250
  typeof result.status === 'object' &&
251
+ result.status !== null &&
252
+ 'Failure' in result.status &&
212
253
  typeof result.status.Failure === 'object' &&
213
254
  result.status.Failure !== null) {
214
- throw parseResultError(result);
255
+ throw parseTransactionExecutionError(result.status.Failure, result.transaction_outcome.id, result.transaction_outcome.block_hash);
215
256
  }
216
257
  return result;
217
258
  }
@@ -245,7 +286,7 @@ export class Account {
245
286
  * @param nearToTransfer how much NEAR to transfer to the account in yoctoNEAR (default: 0)
246
287
  *
247
288
  */
248
- async createAccount({ newAccountId, publicKey, nearToTransfer = 0n, }) {
289
+ async createAccount({ newAccountId, publicKey, nearToTransfer = 0n }) {
249
290
  if (newAccountId.endsWith(this.accountId)) {
250
291
  return this.createSubAccount({ accountOrPrefix: newAccountId, publicKey, nearToTransfer });
251
292
  }
@@ -273,7 +314,7 @@ export class Account {
273
314
  * @param nearToTransfer how much NEAR to transfer to the account (default: 0)
274
315
  *
275
316
  */
276
- async createSubAccount({ accountOrPrefix, publicKey, nearToTransfer = 0n, }) {
317
+ async createSubAccount({ accountOrPrefix, publicKey, nearToTransfer = 0n }) {
277
318
  if (!this.signer)
278
319
  throw new Error('Please set a signer');
279
320
  const newAccountId = accountOrPrefix.includes('.') ? accountOrPrefix : `${accountOrPrefix}.${this.accountId}`;
@@ -374,7 +415,6 @@ export class Account {
374
415
  * Add a full access key to the account
375
416
  *
376
417
  * @param publicKey The public key to be added
377
- * @returns {Promise<FinalExecutionOutcome>}
378
418
  */
379
419
  async addFullAccessKey(publicKey) {
380
420
  return this.signAndSendTransaction({
@@ -384,7 +424,6 @@ export class Account {
384
424
  }
385
425
  /**
386
426
  * @param publicKey The public key to be deleted
387
- * @returns {Promise<FinalExecutionOutcome>}
388
427
  */
389
428
  async deleteKey(publicKey) {
390
429
  return this.signAndSendTransaction({
@@ -418,7 +457,6 @@ export class Account {
418
457
  * @param options.deposit (optional) Amount of NEAR Tokens to attach to the call (default 0)
419
458
  * @param options.gas (optional) Amount of GAS to use attach to the call (default 30TGas)
420
459
  * @param options.waitUntil (optional) Transaction finality to wait for (default INCLUDED_FINAL)
421
- * @returns {FinalExecutionOutcome}
422
460
  */
423
461
  async callFunctionRaw({ contractId, methodName, args = {}, deposit = 0n, gas = DEFAULT_FUNCTION_CALL_GAS, waitUntil = DEFAULT_WAIT_STATUS, }) {
424
462
  return await this.signAndSendTransaction({
@@ -0,0 +1,9 @@
1
+ import type { PublicKey } from '../crypto/public_key.js';
2
+ import type { Provider } from '../providers/provider.js';
3
+ export declare class NonceManager {
4
+ private nonces;
5
+ private locks;
6
+ constructor();
7
+ resolveNextNonce(pk: PublicKey, accountId: string, provider: Provider): Promise<bigint>;
8
+ invalidate(pk: PublicKey): Promise<void>;
9
+ }
@@ -0,0 +1,43 @@
1
+ export class NonceManager {
2
+ constructor() {
3
+ this.nonces = {};
4
+ this.locks = {};
5
+ }
6
+ async resolveNextNonce(pk, accountId, provider) {
7
+ const key = pk.toString();
8
+ // wait until unlocked
9
+ const lock = this.locks[key];
10
+ if (lock)
11
+ await lock;
12
+ if (typeof this.nonces[key] === 'bigint') {
13
+ this.nonces[key] = this.nonces[key] + 1n;
14
+ return this.nonces[key];
15
+ }
16
+ // biome-ignore lint/suspicious/noEmptyBlockStatements: unlock is immediately overwritten
17
+ let unlock = () => { };
18
+ const newLock = new Promise((resolve) => {
19
+ unlock = resolve;
20
+ });
21
+ this.locks[key] = newLock;
22
+ try {
23
+ const accessKey = await provider.viewAccessKey({
24
+ accountId,
25
+ publicKey: pk,
26
+ finalityQuery: { finality: 'optimistic' },
27
+ });
28
+ this.nonces[key] = accessKey.nonce + 1n;
29
+ return this.nonces[key];
30
+ }
31
+ finally {
32
+ unlock();
33
+ }
34
+ }
35
+ async invalidate(pk) {
36
+ const key = pk.toString();
37
+ // make sure to wait until unlocked
38
+ const lock = this.locks[key];
39
+ if (lock)
40
+ await lock;
41
+ delete this.nonces[key];
42
+ }
43
+ }
@@ -1,5 +1,5 @@
1
- import { ed25519 } from '@noble/curves/ed25519';
2
- import { randomBytes } from '@noble/hashes/utils';
1
+ import { ed25519 } from '@noble/curves/ed25519.js';
2
+ import { randomBytes } from '@noble/hashes/utils.js';
3
3
  import { baseDecode, baseEncode } from '../utils/index.js';
4
4
  import { KeySize, KeyType } from './constants.js';
5
5
  import { KeyPairBase } from './key_pair_base.js';
@@ -1,4 +1,4 @@
1
- import { randomBytes } from '@noble/hashes/utils';
1
+ import { randomBytes } from '@noble/hashes/utils.js';
2
2
  import secp256k1 from 'secp256k1';
3
3
  import { baseDecode, baseEncode } from '../utils/index.js';
4
4
  import { KeySize, KeyType } from './constants.js';
@@ -1,4 +1,4 @@
1
- import { ed25519 } from '@noble/curves/ed25519';
1
+ import { ed25519 } from '@noble/curves/ed25519.js';
2
2
  import secp256k1 from 'secp256k1';
3
3
  import { baseDecode, baseEncode } from '../utils/index.js';
4
4
  import { KeySize, KeyType } from './constants.js';
package/lib/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export * from './providers/index.js';
5
5
  export * from './signers/index.js';
6
6
  export * from './transactions/index.js';
7
7
  export * from './types/index.js';
8
+ export { gigaToGas, nearToYocto, teraToGas, yoctoToNear } from './units/index.js';
8
9
  export * from './utils/index.js';
package/lib/index.js CHANGED
@@ -22,6 +22,7 @@ export * from './signers/index.js';
22
22
  // ============================================================================
23
23
  export * from './transactions/index.js';
24
24
  export * from './types/index.js';
25
+ export { gigaToGas, nearToYocto, teraToGas, yoctoToNear } from './units/index.js';
25
26
  // ============================================================================
26
27
  // Utilities
27
28
  // ============================================================================
@@ -1,4 +1,4 @@
1
- import { sha256 } from '@noble/hashes/sha256';
1
+ import { sha256 } from '@noble/hashes/sha2.js';
2
2
  import { serialize } from 'borsh';
3
3
  export const Nep413MessageSchema = {
4
4
  struct: {
@@ -0,0 +1,152 @@
1
+ import type { PrepareError, WasmTrap } from '../../rpc/types.gen.js';
2
+ import type { BlockHash } from '../../types/index.js';
3
+ import { HandlerError } from './handler.js';
4
+ export declare class ContractExecutionError extends HandlerError {
5
+ readonly blockHash: BlockHash;
6
+ readonly blockHeight: number;
7
+ constructor(message: string, blockHash: BlockHash, blockHeight: number);
8
+ }
9
+ export declare class WasmTrapError extends ContractExecutionError {
10
+ readonly reason: WasmTrap;
11
+ constructor(reason: WasmTrap, blockHash: BlockHash, blockHeight: number);
12
+ }
13
+ export declare class ContractCodeDoesNotExistError extends ContractExecutionError {
14
+ readonly contractId: string;
15
+ constructor(contractId: string, blockHash: BlockHash, blockHeight: number);
16
+ }
17
+ export declare class ContractMethodNotFoundError extends ContractExecutionError {
18
+ constructor(blockHash: BlockHash, blockHeight: number);
19
+ }
20
+ export declare class ContractMethodNameEmptyError extends ContractExecutionError {
21
+ constructor(blockHash: BlockHash, blockHeight: number);
22
+ }
23
+ export declare class ContractMethodInvalidSignatureError extends ContractExecutionError {
24
+ constructor(blockHash: BlockHash, blockHeight: number);
25
+ }
26
+ export declare class PrepareWasmError extends ContractExecutionError {
27
+ readonly reason: PrepareError;
28
+ constructor(reason: PrepareError, blockHash: BlockHash, blockHeight: number);
29
+ }
30
+ export declare class HostBadUtf16Error extends ContractExecutionError {
31
+ constructor(blockHash: BlockHash, blockHeight: number);
32
+ }
33
+ export declare class HostBadUtf8Error extends ContractExecutionError {
34
+ constructor(blockHash: BlockHash, blockHeight: number);
35
+ }
36
+ export declare class HostGasExceededError extends ContractExecutionError {
37
+ constructor(blockHash: BlockHash, blockHeight: number);
38
+ }
39
+ export declare class HostGasLimitExceededError extends ContractExecutionError {
40
+ constructor(blockHash: BlockHash, blockHeight: number);
41
+ }
42
+ export declare class HostBalanceExceededError extends ContractExecutionError {
43
+ constructor(blockHash: BlockHash, blockHeight: number);
44
+ }
45
+ export declare class HostEmptyMethodNameError extends ContractExecutionError {
46
+ constructor(blockHash: BlockHash, blockHeight: number);
47
+ }
48
+ export declare class HostGuestPanicError extends ContractExecutionError {
49
+ readonly panicMessage: string;
50
+ constructor(panicMessage: string, blockHash: BlockHash, blockHeight: number);
51
+ }
52
+ export declare class HostIntegerOverflowError extends ContractExecutionError {
53
+ constructor(blockHash: BlockHash, blockHeight: number);
54
+ }
55
+ export declare class HostInvalidPromiseIndexError extends ContractExecutionError {
56
+ readonly promiseIndex: number;
57
+ constructor(promiseIndex: number, blockHash: BlockHash, blockHeight: number);
58
+ }
59
+ export declare class HostCannotAppendActionToJointPromiseError extends ContractExecutionError {
60
+ constructor(blockHash: BlockHash, blockHeight: number);
61
+ }
62
+ export declare class HostCannotReturnJointPromiseError extends ContractExecutionError {
63
+ constructor(blockHash: BlockHash, blockHeight: number);
64
+ }
65
+ export declare class HostInvalidPromiseResultIndexError extends ContractExecutionError {
66
+ readonly resultIndex: number;
67
+ constructor(resultIndex: number, blockHash: BlockHash, blockHeight: number);
68
+ }
69
+ export declare class HostInvalidRegisterIdError extends ContractExecutionError {
70
+ readonly registerId: number;
71
+ constructor(registerId: number, blockHash: BlockHash, blockHeight: number);
72
+ }
73
+ export declare class HostIteratorWasInvalidatedError extends ContractExecutionError {
74
+ readonly iteratorIndex: number;
75
+ constructor(iteratorIndex: number, blockHash: BlockHash, blockHeight: number);
76
+ }
77
+ export declare class HostMemoryAccessViolationError extends ContractExecutionError {
78
+ constructor(blockHash: BlockHash, blockHeight: number);
79
+ }
80
+ export declare class HostInvalidReceiptIndexError extends ContractExecutionError {
81
+ readonly receiptIndex: number;
82
+ constructor(receiptIndex: number, blockHash: BlockHash, blockHeight: number);
83
+ }
84
+ export declare class HostInvalidIteratorIndexError extends ContractExecutionError {
85
+ readonly iteratorIndex: number;
86
+ constructor(iteratorIndex: number, blockHash: BlockHash, blockHeight: number);
87
+ }
88
+ export declare class HostInvalidAccountIdError extends ContractExecutionError {
89
+ constructor(blockHash: BlockHash, blockHeight: number);
90
+ }
91
+ export declare class HostInvalidMethodNameError extends ContractExecutionError {
92
+ constructor(blockHash: BlockHash, blockHeight: number);
93
+ }
94
+ export declare class HostInvalidPublicKeyError extends ContractExecutionError {
95
+ constructor(blockHash: BlockHash, blockHeight: number);
96
+ }
97
+ export declare class HostProhibitedInViewError extends ContractExecutionError {
98
+ readonly methodName: string;
99
+ constructor(methodName: string, blockHash: BlockHash, blockHeight: number);
100
+ }
101
+ export declare class HostNumberOfLogsExceededError extends ContractExecutionError {
102
+ readonly limit: number;
103
+ constructor(limit: number, blockHash: BlockHash, blockHeight: number);
104
+ }
105
+ export declare class HostKeyLengthExceededError extends ContractExecutionError {
106
+ readonly length: number;
107
+ readonly limit: number;
108
+ constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
109
+ }
110
+ export declare class HostValueLengthExceededError extends ContractExecutionError {
111
+ readonly length: number;
112
+ readonly limit: number;
113
+ constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
114
+ }
115
+ export declare class HostTotalLogLengthExceededError extends ContractExecutionError {
116
+ readonly length: number;
117
+ readonly limit: number;
118
+ constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
119
+ }
120
+ export declare class HostNumberPromisesExceededError extends ContractExecutionError {
121
+ readonly limit: number;
122
+ readonly numberOfPromises: number;
123
+ constructor(limit: number, numberOfPromises: number, blockHash: BlockHash, blockHeight: number);
124
+ }
125
+ export declare class HostNumberInputDataDependenciesExceededError extends ContractExecutionError {
126
+ readonly limit: number;
127
+ readonly numberOfInputDataDependencies: number;
128
+ constructor(limit: number, numberOfInputDataDependencies: number, blockHash: BlockHash, blockHeight: number);
129
+ }
130
+ export declare class HostReturnedValueLengthExceededError extends ContractExecutionError {
131
+ readonly length: number;
132
+ readonly limit: number;
133
+ constructor(length: number, limit: number, blockHash: BlockHash, blockHeight: number);
134
+ }
135
+ export declare class HostSizeExceededError extends ContractExecutionError {
136
+ readonly size: number;
137
+ readonly limit: number;
138
+ constructor(size: number, limit: number, blockHash: BlockHash, blockHeight: number);
139
+ }
140
+ export declare class HostDeprecatedError extends ContractExecutionError {
141
+ readonly methodName: string;
142
+ constructor(methodName: string, blockHash: BlockHash, blockHeight: number);
143
+ }
144
+ export declare class HostECRecoverError extends ContractExecutionError {
145
+ constructor(message: string, blockHash: BlockHash, blockHeight: number);
146
+ }
147
+ export declare class HostAltBn128InvalidInputError extends ContractExecutionError {
148
+ constructor(message: string, blockHash: BlockHash, blockHeight: number);
149
+ }
150
+ export declare class HostEd25519VerifyInvalidInputError extends ContractExecutionError {
151
+ constructor(message: string, blockHash: BlockHash, blockHeight: number);
152
+ }