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
@@ -0,0 +1,47 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export const Direction = { LEFT: 'Left', RIGHT: 'Right' };
3
+ /**
4
+ * Different types of finality.
5
+ */
6
+ export const Finality = {
7
+ OPTIMISTIC: 'optimistic',
8
+ NEAR_FINAL: 'near-final',
9
+ FINAL: 'final',
10
+ };
11
+ export const GenesisConfigError = { NULL: null };
12
+ /**
13
+ * GenesisConfigRequest
14
+ */
15
+ export const GenesisConfigRequest = { NULL: null };
16
+ export const LogSummaryStyle = { PLAIN: 'plain', COLORED: 'colored' };
17
+ export const MethodResolveError = {
18
+ METHOD_EMPTY_NAME: 'MethodEmptyName',
19
+ METHOD_NOT_FOUND: 'MethodNotFound',
20
+ METHOD_INVALID_SIGNATURE: 'MethodInvalidSignature',
21
+ };
22
+ /**
23
+ * Configures whether the node checks the next or the next next epoch for network version compatibility.
24
+ */
25
+ export const ProtocolVersionCheckConfig = { NEXT: 'Next', NEXT_NEXT: 'NextNext' };
26
+ /**
27
+ * RpcClientConfigRequest
28
+ */
29
+ export const RpcClientConfigRequest = { NULL: null };
30
+ /**
31
+ * RpcHealthRequest
32
+ */
33
+ export const RpcHealthRequest = { NULL: null };
34
+ export const RpcHealthResponse = { NULL: null };
35
+ /**
36
+ * RpcNetworkInfoRequest
37
+ */
38
+ export const RpcNetworkInfoRequest = { NULL: null };
39
+ /**
40
+ * RpcStatusRequest
41
+ */
42
+ export const RpcStatusRequest = { NULL: null };
43
+ /**
44
+ * This enum represents if a storage_get call will be performed through flat storage or trie
45
+ */
46
+ export const StorageGetMode = { FLAT_STORAGE: 'FlatStorage', TRIE: 'Trie' };
47
+ export const SyncCheckpoint = { GENESIS: 'genesis', EARLIEST_AVAILABLE: 'earliest_available' };
@@ -1,4 +1,4 @@
1
- import { sha256 } from '@noble/hashes/sha256';
1
+ import { sha256 } from '@noble/hashes/sha2.js';
2
2
  import { KeyType } from '../crypto/index.js';
3
3
  import { serializeMessage } from '../nep413/schema.js';
4
4
  import { encodeDelegateAction, encodeTransaction, Signature, SignedDelegate, SignedTransaction, } from '../transactions/index.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { PublicKey } from '../crypto/index.js';
3
2
  import { AccessKey, Action, type GlobalContractDeployMode, type GlobalContractIdentifier } from './actions.js';
4
3
  import type { DelegateAction } from './delegate.js';
@@ -9,18 +9,18 @@ import type { Signature } from './signature.js';
9
9
  * signed delegate actions may never be identical to signed transactions with the same fields
10
10
  * @param delegateAction Delegate action to be signed by the meta transaction sender
11
11
  */
12
- export declare function encodeDelegateAction(delegateAction: DelegateAction): Uint8Array;
12
+ export declare function encodeDelegateAction(delegateAction: DelegateAction): Uint8Array<ArrayBuffer>;
13
13
  /**
14
14
  * Borsh-encode a signed delegate for validation and execution by a relayer
15
15
  * @param signedDelegate Signed delegate to be executed in a meta transaction
16
16
  */
17
- export declare function encodeSignedDelegate(signedDelegate: SignedDelegate): Uint8Array;
17
+ export declare function encodeSignedDelegate(signedDelegate: SignedDelegate): Uint8Array<ArrayBufferLike>;
18
18
  /**
19
19
  * Borsh-encode a transaction or signed transaction into a serialized form.
20
20
  * @param transaction The transaction or signed transaction object to be encoded.
21
21
  * @returns A serialized representation of the input transaction.
22
22
  */
23
- export declare function encodeTransaction(transaction: Transaction | SignedTransaction): Uint8Array;
23
+ export declare function encodeTransaction(transaction: Transaction | SignedTransaction): Uint8Array<ArrayBufferLike>;
24
24
  /**
25
25
  * Borsh-decode a Transaction instance from a buffer
26
26
  * @param bytes Uint8Array data to be decoded
@@ -90,7 +90,7 @@ export interface AccountView extends QueryResponseKind {
90
90
  locked: bigint;
91
91
  code_hash: string;
92
92
  storage_usage: number;
93
- storage_paid_at: BlockHeight;
93
+ storage_paid_at?: BlockHeight;
94
94
  }
95
95
  export interface AccountBalanceInfo {
96
96
  total: bigint;
@@ -137,7 +137,7 @@ export interface ContractCodeView extends QueryResponseKind {
137
137
  }
138
138
  export interface FunctionCallPermissionView {
139
139
  FunctionCall: {
140
- allowance: string;
140
+ allowance?: string | null;
141
141
  receiver_id: string;
142
142
  method_names: string[];
143
143
  };
@@ -0,0 +1,3 @@
1
+ import type { NumericString } from './types.js';
2
+ export declare function gigaToGas(giga: NumericString | number): bigint;
3
+ export declare function teraToGas(tera: NumericString | number): bigint;
@@ -0,0 +1,9 @@
1
+ import { toUnits } from './utils.js';
2
+ const GIGA_NOMINATION_EXP = 9;
3
+ const TERA_NOMINATION_EXP = 12;
4
+ export function gigaToGas(giga) {
5
+ return toUnits(giga, GIGA_NOMINATION_EXP);
6
+ }
7
+ export function teraToGas(tera) {
8
+ return toUnits(tera, TERA_NOMINATION_EXP);
9
+ }
@@ -0,0 +1,2 @@
1
+ export { gigaToGas, teraToGas } from './gas.js';
2
+ export { nearToYocto, yoctoToNear } from './near.js';
@@ -0,0 +1,2 @@
1
+ export { gigaToGas, teraToGas } from './gas.js';
2
+ export { nearToYocto, yoctoToNear } from './near.js';
@@ -0,0 +1,3 @@
1
+ import type { BigintString, NumericString } from './types.js';
2
+ export declare function nearToYocto(near: number | NumericString): bigint;
3
+ export declare function yoctoToNear(yocto: bigint | BigintString, decimals?: number): NumericString;
@@ -0,0 +1,22 @@
1
+ import { toUnits } from './utils.js';
2
+ const NEAR_NOMINATION_EXP = 24;
3
+ export function nearToYocto(near) {
4
+ return toUnits(near, NEAR_NOMINATION_EXP);
5
+ }
6
+ export function yoctoToNear(yocto, decimals = NEAR_NOMINATION_EXP) {
7
+ decimals = Math.floor(decimals);
8
+ if (decimals < 0 || decimals > NEAR_NOMINATION_EXP) {
9
+ throw new Error(`Decimal places argument must be between 0 and ${NEAR_NOMINATION_EXP}`);
10
+ }
11
+ // check if bigint is constructible
12
+ yocto = `${BigInt(yocto)}`;
13
+ const wholeStr = yocto.substring(0, yocto.length - NEAR_NOMINATION_EXP) || '0';
14
+ const fractionStr = yocto
15
+ .substring(yocto.length - NEAR_NOMINATION_EXP)
16
+ .padStart(NEAR_NOMINATION_EXP, '0')
17
+ .substring(0, decimals);
18
+ return trimTrailingZeroes(`${wholeStr}.${fractionStr}`);
19
+ }
20
+ function trimTrailingZeroes(value) {
21
+ return value.replace(/\.?0*$/, '');
22
+ }
@@ -0,0 +1,2 @@
1
+ export type NumericString = `${number}`;
2
+ export type BigintString = `${bigint}`;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { NumericString } from './types.js';
2
+ export declare function toUnits(amount: NumericString | number, exponent: number): bigint;
@@ -0,0 +1,23 @@
1
+ export function toUnits(amount, exponent) {
2
+ const cleanedAmount = cleanupAmount(`${amount}`);
3
+ if (!cleanedAmount) {
4
+ throw new Error('Amount cannot be empty');
5
+ }
6
+ const split = cleanedAmount.split('.');
7
+ const wholePart = split[0];
8
+ const fracPart = split[1] || '';
9
+ if (split.length > 2 || fracPart.length > exponent) {
10
+ throw new Error(`Cannot parse '${amount}'`);
11
+ }
12
+ return BigInt(trimLeadingZeroes(wholePart + fracPart.padEnd(exponent, '0')));
13
+ }
14
+ function cleanupAmount(amount) {
15
+ return amount.replace(/,/g, '').trim();
16
+ }
17
+ function trimLeadingZeroes(value) {
18
+ value = value.replace(/^0+/, '');
19
+ if (value === '') {
20
+ return '0';
21
+ }
22
+ return value;
23
+ }
@@ -8,6 +8,8 @@ export declare const NEAR_NOMINATION_EXP = 24;
8
8
  */
9
9
  export declare const NEAR_NOMINATION: bigint;
10
10
  /**
11
+ * @deprecated use {@link yoctoToNear} instead.
12
+ *
11
13
  * Convert account balance value from internal indivisible units to NEAR. 1 NEAR is defined by {@link NEAR_NOMINATION}.
12
14
  * Effectively this divides given amount by {@link NEAR_NOMINATION}.
13
15
  *
@@ -17,6 +19,8 @@ export declare const NEAR_NOMINATION: bigint;
17
19
  */
18
20
  export declare function formatNearAmount(balance: string | number | bigint, fracDigits?: number): string;
19
21
  /**
22
+ * @deprecated use {@link nearToYocto} instead.
23
+ *
20
24
  * Convert human readable NEAR amount to internal indivisible units.
21
25
  * Effectively this multiplies given amount by {@link NEAR_NOMINATION}.
22
26
  *
@@ -14,6 +14,8 @@ for (let i = 0, offset = 5n; i < NEAR_NOMINATION_EXP; i++, offset = offset * BN1
14
14
  ROUNDING_OFFSETS[i] = offset;
15
15
  }
16
16
  /**
17
+ * @deprecated use {@link yoctoToNear} instead.
18
+ *
17
19
  * Convert account balance value from internal indivisible units to NEAR. 1 NEAR is defined by {@link NEAR_NOMINATION}.
18
20
  * Effectively this divides given amount by {@link NEAR_NOMINATION}.
19
21
  *
@@ -39,6 +41,8 @@ export function formatNearAmount(balance, fracDigits = NEAR_NOMINATION_EXP) {
39
41
  return trimTrailingZeroes(`${formatWithCommas(wholeStr)}.${fractionStr}`);
40
42
  }
41
43
  /**
44
+ * @deprecated use {@link nearToYocto} instead.
45
+ *
42
46
  * Convert human readable NEAR amount to internal indivisible units.
43
47
  * Effectively this multiplies given amount by {@link NEAR_NOMINATION}.
44
48
  *
@@ -1,3 +1,4 @@
1
+ import type { RpcTransactionResponse } from '../rpc/types.gen.js';
1
2
  import type { FinalExecutionOutcome } from '../types/index.js';
2
3
  /** @hidden */
3
- export declare function getTransactionLastResult(txResult: FinalExecutionOutcome): Exclude<object | string | number | null, Function>;
4
+ export declare function getTransactionLastResult(txResult: FinalExecutionOutcome | RpcTransactionResponse): Exclude<object | string | number | null, Function>;
@@ -1,7 +1,10 @@
1
1
  /** @hidden */
2
2
  // eslint-disable-next-line @typescript-eslint/ban-types
3
3
  export function getTransactionLastResult(txResult) {
4
- if (typeof txResult.status === 'object' && typeof txResult.status.SuccessValue === 'string') {
4
+ if (typeof txResult.status === 'object' &&
5
+ txResult.status !== null &&
6
+ 'SuccessValue' in txResult.status &&
7
+ typeof txResult.status.SuccessValue === 'string') {
5
8
  const value = Buffer.from(txResult.status.SuccessValue, 'base64').toString();
6
9
  try {
7
10
  return JSON.parse(value);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "near-api-js",
3
3
  "description": "JavaScript library to interact with NEAR Protocol via RPC API",
4
- "version": "7.0.0-rc.0",
4
+ "version": "7.0.0-rc.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/near/near-api-js.git"
@@ -35,36 +35,37 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@noble/curves": "1.8.1",
39
- "@noble/hashes": "1.7.1",
40
- "@scure/base": "1.2.4",
41
- "borsh": "1.0.0",
38
+ "@noble/curves": "2.0.1",
39
+ "@noble/hashes": "2.0.1",
40
+ "@scure/base": "2.0.0",
41
+ "borsh": "2.0.0",
42
42
  "depd": "2.0.0",
43
- "exponential-backoff": "3.1.2",
43
+ "exponential-backoff": "3.1.3",
44
44
  "is-my-json-valid": "2.20.6",
45
- "mustache": "4.0.0",
45
+ "mustache": "4.2.0",
46
46
  "secp256k1": "5.0.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@arethetypeswrong/cli": "0.18.2",
50
- "@biomejs/biome": "^2.3.6",
51
- "@changesets/changelog-github": "0.5.1",
52
- "@changesets/cli": "2.29.7",
53
- "@commitlint/cli": "19.3.0",
54
- "@commitlint/config-conventional": "19.7.1",
55
- "@types/node": "20.0.0",
56
- "@vitest/coverage-v8": "4.0.10",
57
- "@vitest/ui": "4.0.10",
58
- "commitlint": "19.7.1",
50
+ "@biomejs/biome": "^2.3.8",
51
+ "@changesets/changelog-github": "0.5.2",
52
+ "@changesets/cli": "2.29.8",
53
+ "@commitlint/cli": "20.2.0",
54
+ "@commitlint/config-conventional": "20.2.0",
55
+ "@hey-api/openapi-ts": "^0.89.0",
56
+ "@types/node": "24.10.2",
57
+ "@vitest/coverage-v8": "4.0.15",
58
+ "@vitest/ui": "4.0.15",
59
+ "commitlint": "20.2.0",
59
60
  "husky": "9.1.7",
60
61
  "near-hello": "0.5.1",
61
62
  "near-workspaces": "5.0.0",
62
- "rimraf": "6.0.1",
63
- "semver": "7.7.1",
63
+ "rimraf": "6.1.2",
64
+ "semver": "7.7.3",
64
65
  "ts-node": "10.9.2",
65
- "typedoc": "0.27.9",
66
- "typescript": "5.4.5",
67
- "vitest": "4.0.10"
66
+ "typedoc": "0.28.15",
67
+ "typescript": "5.9.3",
68
+ "vitest": "4.0.15"
68
69
  },
69
70
  "keywords": [],
70
71
  "license": "(MIT AND Apache-2.0)",
@@ -91,6 +92,8 @@
91
92
  "check-exports": "attw --pack . --ignore-rules cjs-resolves-to-esm no-resolution",
92
93
  "docs:generate": "typedoc",
93
94
  "autoclave": "rimraf lib && rimraf node_modules && rimraf coverage && rimraf node_modules && rimraf e2e/node_modules && rimraf e2e/coverage && rimraf e2e/tests/node_modules",
94
- "release": "changeset publish"
95
+ "release": "changeset publish",
96
+ "rpc:generate": "pnpm openapi-ts",
97
+ "postrpc:generate": "biome check --fix"
95
98
  }
96
99
  }