near-kit 0.0.0 → 0.1.0
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/LICENSE +21 -0
- package/README.md +371 -2
- package/dist/contracts/contract.d.ts +63 -0
- package/dist/contracts/contract.d.ts.map +1 -0
- package/dist/contracts/contract.js +42 -0
- package/dist/contracts/contract.js.map +1 -0
- package/dist/contracts/index.d.ts +5 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +5 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/core/actions.d.ts +193 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +195 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/config-schemas.d.ts +179 -0
- package/dist/core/config-schemas.d.ts.map +1 -0
- package/dist/core/config-schemas.js +169 -0
- package/dist/core/config-schemas.js.map +1 -0
- package/dist/core/constants.d.ts +43 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +49 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/near.d.ts +301 -0
- package/dist/core/near.d.ts.map +1 -0
- package/dist/core/near.js +504 -0
- package/dist/core/near.js.map +1 -0
- package/dist/core/nonce-manager.d.ts +39 -0
- package/dist/core/nonce-manager.d.ts.map +1 -0
- package/dist/core/nonce-manager.js +73 -0
- package/dist/core/nonce-manager.js.map +1 -0
- package/dist/core/rpc/rpc-error-handler.d.ts +60 -0
- package/dist/core/rpc/rpc-error-handler.d.ts.map +1 -0
- package/dist/core/rpc/rpc-error-handler.js +324 -0
- package/dist/core/rpc/rpc-error-handler.js.map +1 -0
- package/dist/core/rpc/rpc-schemas.d.ts +1812 -0
- package/dist/core/rpc/rpc-schemas.d.ts.map +1 -0
- package/dist/core/rpc/rpc-schemas.js +424 -0
- package/dist/core/rpc/rpc-schemas.js.map +1 -0
- package/dist/core/rpc/rpc.d.ts +117 -0
- package/dist/core/rpc/rpc.d.ts.map +1 -0
- package/dist/core/rpc/rpc.js +325 -0
- package/dist/core/rpc/rpc.js.map +1 -0
- package/dist/core/schema.d.ts +1188 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +396 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/transaction.d.ts +390 -0
- package/dist/core/transaction.d.ts.map +1 -0
- package/dist/core/transaction.js +649 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/core/types.d.ts +271 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +9 -0
- package/dist/core/types.js.map +1 -0
- package/dist/errors/index.d.ts +226 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +366 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/credential-schemas.d.ts +98 -0
- package/dist/keys/credential-schemas.d.ts.map +1 -0
- package/dist/keys/credential-schemas.js +128 -0
- package/dist/keys/credential-schemas.js.map +1 -0
- package/dist/keys/file-keystore.d.ts +130 -0
- package/dist/keys/file-keystore.d.ts.map +1 -0
- package/dist/keys/file-keystore.js +266 -0
- package/dist/keys/file-keystore.js.map +1 -0
- package/dist/keys/in-memory-keystore.d.ts +71 -0
- package/dist/keys/in-memory-keystore.d.ts.map +1 -0
- package/dist/keys/in-memory-keystore.js +85 -0
- package/dist/keys/in-memory-keystore.js.map +1 -0
- package/dist/keys/index.d.ts +12 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +18 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/keys/native-keystore.d.ts +111 -0
- package/dist/keys/native-keystore.d.ts.map +1 -0
- package/dist/keys/native-keystore.js +167 -0
- package/dist/keys/native-keystore.js.map +1 -0
- package/dist/sandbox/index.d.ts +6 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/sandbox.d.ts +55 -0
- package/dist/sandbox/sandbox.d.ts.map +1 -0
- package/dist/sandbox/sandbox.js +341 -0
- package/dist/sandbox/sandbox.js.map +1 -0
- package/dist/utils/amount.d.ts +76 -0
- package/dist/utils/amount.d.ts.map +1 -0
- package/dist/utils/amount.js +137 -0
- package/dist/utils/amount.js.map +1 -0
- package/dist/utils/gas.d.ts +69 -0
- package/dist/utils/gas.d.ts.map +1 -0
- package/dist/utils/gas.js +92 -0
- package/dist/utils/gas.js.map +1 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/key.d.ts +117 -0
- package/dist/utils/key.d.ts.map +1 -0
- package/dist/utils/key.js +270 -0
- package/dist/utils/key.js.map +1 -0
- package/dist/utils/nep413.d.ts +97 -0
- package/dist/utils/nep413.d.ts.map +1 -0
- package/dist/utils/nep413.js +154 -0
- package/dist/utils/nep413.js.map +1 -0
- package/dist/utils/validation.d.ts +114 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +150 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/wallets/adapters.d.ts +119 -0
- package/dist/wallets/adapters.d.ts.map +1 -0
- package/dist/wallets/adapters.js +267 -0
- package/dist/wallets/adapters.js.map +1 -0
- package/dist/wallets/index.d.ts +11 -0
- package/dist/wallets/index.d.ts.map +1 -0
- package/dist/wallets/index.js +2 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/wallets/types.d.ts +99 -0
- package/dist/wallets/types.d.ts.map +1 -0
- package/dist/wallets/types.js +10 -0
- package/dist/wallets/types.js.map +1 -0
- package/package.json +78 -7
- package/index.js +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for NEAR client configuration.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These schemas validate network, call options, and {@link NearConfig} input.
|
|
6
|
+
* Most applications should use the higher-level {@link Near} API and treat
|
|
7
|
+
* these schemas as an implementation detail.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { PrivateKeySchema } from "../utils/validation.js";
|
|
11
|
+
import { NETWORK_PRESETS } from "./constants.js";
|
|
12
|
+
// ==================== Network Config Schema ====================
|
|
13
|
+
/**
|
|
14
|
+
* Schema for network presets (mainnet, testnet, localnet)
|
|
15
|
+
*/
|
|
16
|
+
export const NetworkPresetSchema = z.enum(["mainnet", "testnet", "localnet"]);
|
|
17
|
+
/**
|
|
18
|
+
* Schema for custom network configuration
|
|
19
|
+
*/
|
|
20
|
+
export const CustomNetworkConfigSchema = z.object({
|
|
21
|
+
rpcUrl: z.string().url("RPC URL must be a valid URL"),
|
|
22
|
+
networkId: z.string().min(1, "Network ID is required"),
|
|
23
|
+
nodeUrl: z.string().url("Node URL must be a valid URL").optional(),
|
|
24
|
+
walletUrl: z.string().url("Wallet URL must be a valid URL").optional(),
|
|
25
|
+
helperUrl: z.string().url("Helper URL must be a valid URL").optional(),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Schema for network configuration (preset or custom)
|
|
29
|
+
*/
|
|
30
|
+
export const NetworkConfigSchema = z.union([
|
|
31
|
+
NetworkPresetSchema,
|
|
32
|
+
CustomNetworkConfigSchema,
|
|
33
|
+
]);
|
|
34
|
+
// ==================== Transaction Execution Status Schema ====================
|
|
35
|
+
/**
|
|
36
|
+
* Schema for transaction execution status
|
|
37
|
+
*/
|
|
38
|
+
export const TxExecutionStatusSchema = z.enum([
|
|
39
|
+
"NONE",
|
|
40
|
+
"INCLUDED",
|
|
41
|
+
"EXECUTED_OPTIMISTIC",
|
|
42
|
+
"INCLUDED_FINAL",
|
|
43
|
+
"EXECUTED",
|
|
44
|
+
"FINAL",
|
|
45
|
+
]);
|
|
46
|
+
// ==================== Call Options Schema ====================
|
|
47
|
+
/**
|
|
48
|
+
* Schema for function call options
|
|
49
|
+
*/
|
|
50
|
+
export const CallOptionsSchema = z.object({
|
|
51
|
+
gas: z.string().optional(),
|
|
52
|
+
attachedDeposit: z.union([z.string(), z.bigint()]).optional(),
|
|
53
|
+
signerId: z.string().optional(),
|
|
54
|
+
waitUntil: TxExecutionStatusSchema.optional(),
|
|
55
|
+
});
|
|
56
|
+
// ==================== Block Reference Schema ====================
|
|
57
|
+
/**
|
|
58
|
+
* Block reference for RPC queries
|
|
59
|
+
*
|
|
60
|
+
* Specify either `finality` OR `blockId` (not both).
|
|
61
|
+
* If both are provided, `blockId` takes precedence.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Query at final block (default)
|
|
66
|
+
* await near.view('contract.near', 'get_value')
|
|
67
|
+
*
|
|
68
|
+
* // Query at optimistic for latest state
|
|
69
|
+
* await near.view('contract.near', 'get_value', {}, {
|
|
70
|
+
* finality: 'optimistic'
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* // Query at specific block height
|
|
74
|
+
* await near.view('contract.near', 'get_value', {}, {
|
|
75
|
+
* blockId: 27912554
|
|
76
|
+
* })
|
|
77
|
+
*
|
|
78
|
+
* // Query at specific block hash
|
|
79
|
+
* await near.view('contract.near', 'get_value', {}, {
|
|
80
|
+
* blockId: '3Xz2wM9rigMXzA2c5vgCP8wTgFBaePucgUmVYPkMqhRL'
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export const BlockReferenceSchema = z.object({
|
|
85
|
+
/**
|
|
86
|
+
* Finality level for the query
|
|
87
|
+
*
|
|
88
|
+
* - `optimistic`: Block that might be skipped (~1s after submission). Use for latest state.
|
|
89
|
+
* - `near-final`: Irreversible unless a validator is slashed (~2s after submission)
|
|
90
|
+
* - `final`: Fully finalized and irreversible (~3s after submission). DEFAULT for view calls.
|
|
91
|
+
*
|
|
92
|
+
* @default "final" for view calls, "optimistic" for account/key queries
|
|
93
|
+
* @see https://docs.near.org/api/rpc/setup#using-finality-param
|
|
94
|
+
*/
|
|
95
|
+
finality: z.enum(["optimistic", "near-final", "final"]).optional(),
|
|
96
|
+
/**
|
|
97
|
+
* Block ID to query at - can be block number or block hash
|
|
98
|
+
*
|
|
99
|
+
* Use block number (e.g., `27912554`) or block hash
|
|
100
|
+
* (e.g., `'3Xz2wM9rigMXzA2c5vgCP8wTgFBaePucgUmVYPkMqhRL'`) to query
|
|
101
|
+
* historical state.
|
|
102
|
+
*
|
|
103
|
+
* Mutually exclusive with `finality`. If both are provided, `blockId` takes precedence.
|
|
104
|
+
*/
|
|
105
|
+
blockId: z.union([z.number(), z.string()]).optional(),
|
|
106
|
+
});
|
|
107
|
+
// ==================== Near Config Schema ====================
|
|
108
|
+
/**
|
|
109
|
+
* Schema for key store configuration
|
|
110
|
+
*/
|
|
111
|
+
export const KeyStoreConfigSchema = z.union([
|
|
112
|
+
z.string(), // File path
|
|
113
|
+
z.record(z.string(), z.string()), // { accountId: privateKey }
|
|
114
|
+
z.any(), // KeyStore interface - too complex for Zod validation
|
|
115
|
+
]);
|
|
116
|
+
/**
|
|
117
|
+
* Schema for signer function
|
|
118
|
+
*/
|
|
119
|
+
export const SignerSchema = z.any(); // Function schema validation - simplified
|
|
120
|
+
/**
|
|
121
|
+
* Schema for RPC retry configuration
|
|
122
|
+
*/
|
|
123
|
+
export const RpcRetryConfigSchema = z
|
|
124
|
+
.object({
|
|
125
|
+
maxRetries: z.number().int().min(0),
|
|
126
|
+
initialDelayMs: z.number().int().min(0),
|
|
127
|
+
})
|
|
128
|
+
.partial();
|
|
129
|
+
/**
|
|
130
|
+
* Schema for NEAR client configuration
|
|
131
|
+
*/
|
|
132
|
+
export const NearConfigSchema = z.object({
|
|
133
|
+
network: NetworkConfigSchema.optional(),
|
|
134
|
+
rpcUrl: z.string().url("RPC URL must be a valid URL").optional(),
|
|
135
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
136
|
+
keyStore: KeyStoreConfigSchema.optional(),
|
|
137
|
+
signer: SignerSchema.optional(),
|
|
138
|
+
privateKey: z.union([PrivateKeySchema, z.instanceof(Uint8Array)]).optional(),
|
|
139
|
+
wallet: z.any().optional(), // WalletConnection interface
|
|
140
|
+
defaultSignerId: z.string().optional(),
|
|
141
|
+
defaultWaitUntil: TxExecutionStatusSchema.optional(),
|
|
142
|
+
retryConfig: RpcRetryConfigSchema.optional(),
|
|
143
|
+
});
|
|
144
|
+
// ==================== Helper Functions ====================
|
|
145
|
+
/**
|
|
146
|
+
* Resolve network configuration with validation
|
|
147
|
+
*/
|
|
148
|
+
export function resolveNetworkConfig(network) {
|
|
149
|
+
// Default to mainnet
|
|
150
|
+
if (!network) {
|
|
151
|
+
const envNetwork = typeof process !== "undefined" ? process.env["NEAR_NETWORK"] : undefined;
|
|
152
|
+
if (envNetwork &&
|
|
153
|
+
(envNetwork === "mainnet" ||
|
|
154
|
+
envNetwork === "testnet" ||
|
|
155
|
+
envNetwork === "localnet")) {
|
|
156
|
+
return NETWORK_PRESETS[envNetwork];
|
|
157
|
+
}
|
|
158
|
+
return NETWORK_PRESETS.mainnet;
|
|
159
|
+
}
|
|
160
|
+
// Validate and parse network config
|
|
161
|
+
const validated = NetworkConfigSchema.parse(network);
|
|
162
|
+
// Network preset
|
|
163
|
+
if (typeof validated === "string") {
|
|
164
|
+
return NETWORK_PRESETS[validated];
|
|
165
|
+
}
|
|
166
|
+
// Custom network config (already validated)
|
|
167
|
+
return validated;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=config-schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-schemas.js","sourceRoot":"","sources":["../../src/core/config-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAmB,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AA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e,CAAC,UAA2B,CAAC,CAAA;QACrD,CAAC;QACD,OAAO,eAAe,CAAC,OAAO,CAAA;IAChC,CAAC;IAED,oCAAoC;IACpC,MAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAEpD,iBAAiB;IACjB,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,eAAe,CAAC,SAA0B,CAAC,CAAA;IACpD,CAAC;IAED,4CAA4C;IAC5C,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for NEAR Protocol
|
|
3
|
+
*/
|
|
4
|
+
export declare const NETWORK_PRESETS: {
|
|
5
|
+
readonly mainnet: {
|
|
6
|
+
readonly rpcUrl: "https://free.rpc.fastnear.com";
|
|
7
|
+
readonly networkId: "mainnet";
|
|
8
|
+
readonly walletUrl: "https://wallet.near.org";
|
|
9
|
+
readonly helperUrl: "https://helper.mainnet.near.org";
|
|
10
|
+
};
|
|
11
|
+
readonly testnet: {
|
|
12
|
+
readonly rpcUrl: "https://rpc.testnet.fastnear.com";
|
|
13
|
+
readonly networkId: "testnet";
|
|
14
|
+
readonly walletUrl: "https://wallet.testnet.near.org";
|
|
15
|
+
readonly helperUrl: "https://helper.testnet.near.org";
|
|
16
|
+
};
|
|
17
|
+
readonly localnet: {
|
|
18
|
+
readonly rpcUrl: "http://localhost:3030";
|
|
19
|
+
readonly networkId: "localnet";
|
|
20
|
+
readonly walletUrl: "http://localhost:1234";
|
|
21
|
+
readonly helperUrl: "http://localhost:3000";
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare const YOCTO_PER_NEAR: bigint;
|
|
25
|
+
export declare const GAS_PER_TGAS: bigint;
|
|
26
|
+
export declare const DEFAULT_FUNCTION_CALL_GAS = "30000000000000";
|
|
27
|
+
export declare const ACCOUNT_ID_REGEX: RegExp;
|
|
28
|
+
export declare const MIN_ACCOUNT_ID_LENGTH = 2;
|
|
29
|
+
export declare const MAX_ACCOUNT_ID_LENGTH = 64;
|
|
30
|
+
export declare const ED25519_KEY_PREFIX = "ed25519:";
|
|
31
|
+
export declare const SECP256K1_KEY_PREFIX = "secp256k1:";
|
|
32
|
+
export declare const RPC_METHODS: {
|
|
33
|
+
readonly QUERY: "query";
|
|
34
|
+
readonly BROADCAST_TX_COMMIT: "broadcast_tx_commit";
|
|
35
|
+
readonly BROADCAST_TX_ASYNC: "broadcast_tx_async";
|
|
36
|
+
readonly TX_STATUS: "tx";
|
|
37
|
+
readonly BLOCK: "block";
|
|
38
|
+
readonly CHUNK: "chunk";
|
|
39
|
+
readonly VALIDATORS: "validators";
|
|
40
|
+
readonly GAS_PRICE: "gas_price";
|
|
41
|
+
readonly STATUS: "status";
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;CAmBlB,CAAA;AAIV,eAAO,MAAM,cAAc,QAAsC,CAAA;AACjE,eAAO,MAAM,YAAY,QAA0B,CAAA;AAInD,eAAO,MAAM,yBAAyB,mBAAmB,CAAA;AAIzD,eAAO,MAAM,gBAAgB,QAC4B,CAAA;AACzD,eAAO,MAAM,qBAAqB,IAAI,CAAA;AACtC,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAIvC,eAAO,MAAM,kBAAkB,aAAa,CAAA;AAC5C,eAAO,MAAM,oBAAoB,eAAe,CAAA;AAIhD,eAAO,MAAM,WAAW;;;;;;;;;;CAUd,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for NEAR Protocol
|
|
3
|
+
*/
|
|
4
|
+
// ==================== Network Endpoints ====================
|
|
5
|
+
export const NETWORK_PRESETS = {
|
|
6
|
+
mainnet: {
|
|
7
|
+
rpcUrl: "https://free.rpc.fastnear.com",
|
|
8
|
+
networkId: "mainnet",
|
|
9
|
+
walletUrl: "https://wallet.near.org",
|
|
10
|
+
helperUrl: "https://helper.mainnet.near.org",
|
|
11
|
+
},
|
|
12
|
+
testnet: {
|
|
13
|
+
rpcUrl: "https://rpc.testnet.fastnear.com",
|
|
14
|
+
networkId: "testnet",
|
|
15
|
+
walletUrl: "https://wallet.testnet.near.org",
|
|
16
|
+
helperUrl: "https://helper.testnet.near.org",
|
|
17
|
+
},
|
|
18
|
+
localnet: {
|
|
19
|
+
rpcUrl: "http://localhost:3030",
|
|
20
|
+
networkId: "localnet",
|
|
21
|
+
walletUrl: "http://localhost:1234",
|
|
22
|
+
helperUrl: "http://localhost:3000",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
// ==================== Units ====================
|
|
26
|
+
export const YOCTO_PER_NEAR = BigInt("1000000000000000000000000");
|
|
27
|
+
export const GAS_PER_TGAS = BigInt("1000000000000");
|
|
28
|
+
// ==================== Gas Defaults ====================
|
|
29
|
+
export const DEFAULT_FUNCTION_CALL_GAS = "30000000000000"; // 30 TGas
|
|
30
|
+
// ==================== Account ID Validation ====================
|
|
31
|
+
export const ACCOUNT_ID_REGEX = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
32
|
+
export const MIN_ACCOUNT_ID_LENGTH = 2;
|
|
33
|
+
export const MAX_ACCOUNT_ID_LENGTH = 64;
|
|
34
|
+
// ==================== Key Formats ====================
|
|
35
|
+
export const ED25519_KEY_PREFIX = "ed25519:";
|
|
36
|
+
export const SECP256K1_KEY_PREFIX = "secp256k1:";
|
|
37
|
+
// ==================== RPC Methods ====================
|
|
38
|
+
export const RPC_METHODS = {
|
|
39
|
+
QUERY: "query",
|
|
40
|
+
BROADCAST_TX_COMMIT: "broadcast_tx_commit",
|
|
41
|
+
BROADCAST_TX_ASYNC: "broadcast_tx_async",
|
|
42
|
+
TX_STATUS: "tx",
|
|
43
|
+
BLOCK: "block",
|
|
44
|
+
CHUNK: "chunk",
|
|
45
|
+
VALIDATORS: "validators",
|
|
46
|
+
GAS_PRICE: "gas_price",
|
|
47
|
+
STATUS: "status",
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,8DAA8D;AAE9D,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,OAAO,EAAE;QACP,MAAM,EAAE,+BAA+B;QACvC,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,yBAAyB;QACpC,SAAS,EAAE,iCAAiC;KAC7C;IACD,OAAO,EAAE;QACP,MAAM,EAAE,kCAAkC;QAC1C,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,iCAAiC;QAC5C,SAAS,EAAE,iCAAiC;KAC7C;IACD,QAAQ,EAAE;QACR,MAAM,EAAE,uBAAuB;QAC/B,SAAS,EAAE,UAAU;QACrB,SAAS,EAAE,uBAAuB;QAClC,SAAS,EAAE,uBAAuB;KACnC;CACO,CAAA;AAEV,kDAAkD;AAElD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAA;AACjE,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;AAEnD,yDAAyD;AAEzD,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAA,CAAC,UAAU;AAEpE,kEAAkE;AAElE,MAAM,CAAC,MAAM,gBAAgB,GAC3B,uDAAuD,CAAA;AACzD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAA;AACtC,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEvC,wDAAwD;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAA;AAC5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAA;AAEhD,wDAAwD;AAExD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,OAAO;IACd,mBAAmB,EAAE,qBAAqB;IAC1C,kBAAkB,EAAE,oBAAoB;IACxC,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;CACR,CAAA"}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main NEAR client class
|
|
3
|
+
*/
|
|
4
|
+
import type { ContractMethods } from "../contracts/contract.js";
|
|
5
|
+
import type { Amount } from "../utils/validation.js";
|
|
6
|
+
import { type BlockReference, type NearConfig } from "./config-schemas.js";
|
|
7
|
+
import type { FinalExecutionOutcome, FinalExecutionOutcomeWithReceiptsMap } from "./rpc/rpc-schemas.js";
|
|
8
|
+
import { TransactionBuilder } from "./transaction.js";
|
|
9
|
+
import type { CallOptions, SignedMessage, SignMessageParams } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Main client for interacting with the NEAR blockchain.
|
|
12
|
+
*
|
|
13
|
+
* Wraps RPC access, key management, wallet integrations, and the fluent
|
|
14
|
+
* transaction builder. Most applications create one `Near` instance per
|
|
15
|
+
* network and reuse it for all operations.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Configure the client with {@link NearConfig} to choose networks, key stores,
|
|
19
|
+
* wallets, and retry behavior. For a guided overview see
|
|
20
|
+
* `docs/01-getting-started.md` and `docs/02-core-concepts.md`.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Near {
|
|
23
|
+
private rpc;
|
|
24
|
+
private keyStore;
|
|
25
|
+
private signer?;
|
|
26
|
+
private wallet?;
|
|
27
|
+
private defaultSignerId?;
|
|
28
|
+
private defaultWaitUntil;
|
|
29
|
+
private pendingKeyStoreInit?;
|
|
30
|
+
constructor(config?: NearConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Initialize RPC client from configuration
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
private _initializeRpc;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve and initialize keystore from configuration
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
private _resolveKeyStore;
|
|
41
|
+
/**
|
|
42
|
+
* Resolve and initialize signer from configuration
|
|
43
|
+
* Handles privateKey, custom signer, and sandbox root key auto-detection
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
private _resolveSigner;
|
|
47
|
+
/**
|
|
48
|
+
* Ensure any pending keystore initialization is complete
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
private ensureKeyStoreReady;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve key store from config input
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
private resolveKeyStore;
|
|
57
|
+
/**
|
|
58
|
+
* Get signer ID from options, default, or wallet
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
private getSignerId;
|
|
62
|
+
/**
|
|
63
|
+
* Call a view function on a contract (read-only, no gas).
|
|
64
|
+
*
|
|
65
|
+
* @param contractId - Target contract account ID.
|
|
66
|
+
* @param methodName - Name of the view method to call.
|
|
67
|
+
* @param args - Arguments object or raw bytes; defaults to `{}`.
|
|
68
|
+
* @param options - Optional {@link BlockReference} to specify finality or block.
|
|
69
|
+
*
|
|
70
|
+
* @returns Parsed JSON result when the contract returns JSON, otherwise the
|
|
71
|
+
* raw string value typed as `T`.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* - View calls are free and do not require a signer or gas.
|
|
75
|
+
* - Errors thrown by the contract surface as {@link ContractExecutionError}.
|
|
76
|
+
*
|
|
77
|
+
* @see NearConfig.defaultWaitUntil
|
|
78
|
+
*/
|
|
79
|
+
view<T = unknown>(contractId: string, methodName: string, args?: object | Uint8Array, options?: BlockReference): Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* Call a change function on a contract (requires signature and gas).
|
|
82
|
+
*
|
|
83
|
+
* Uses the connected wallet when available, otherwise falls back to the
|
|
84
|
+
* configured signer / private key / key store.
|
|
85
|
+
*
|
|
86
|
+
* @param contractId - Target contract account ID.
|
|
87
|
+
* @param methodName - Name of the change method to call.
|
|
88
|
+
* @param args - Arguments object or raw bytes; defaults to `{}`.
|
|
89
|
+
* @param options - Call options such as gas, attached deposit, signerId and wait level.
|
|
90
|
+
*
|
|
91
|
+
* @returns The decoded contract return value typed as `T`.
|
|
92
|
+
*
|
|
93
|
+
* @throws {NearError} If no signer can be resolved.
|
|
94
|
+
* @throws {FunctionCallError} If the contract panics or returns an error.
|
|
95
|
+
* @throws {InvalidTransactionError} If the transaction itself is invalid.
|
|
96
|
+
* @throws {NetworkError} If the RPC request fails after retries.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* await near.call(
|
|
101
|
+
* "contract.near",
|
|
102
|
+
* "increment",
|
|
103
|
+
* { by: 1 },
|
|
104
|
+
* { attachedDeposit: "1 yocto", gas: "30 Tgas" },
|
|
105
|
+
* )
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
call<T = FinalExecutionOutcome>(contractId: string, methodName: string, args?: object | Uint8Array, options?: CallOptions): Promise<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Send NEAR tokens to an account.
|
|
111
|
+
*
|
|
112
|
+
* @param receiverId - Account ID that will receive the tokens.
|
|
113
|
+
* @param amount - Amount to send, expressed as {@link Amount} (e.g. `"10 NEAR"` or `"1 yocto"`).
|
|
114
|
+
*
|
|
115
|
+
* @returns The final transaction outcome from the wallet or RPC.
|
|
116
|
+
*
|
|
117
|
+
* @throws {NearError} If no signer can be resolved.
|
|
118
|
+
* @throws {InvalidTransactionError} If the transfer transaction is invalid.
|
|
119
|
+
* @throws {NetworkError} If the RPC request fails after retries.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* This is a convenience wrapper over {@link Near.transaction} with a single
|
|
123
|
+
* `transfer` action.
|
|
124
|
+
*/
|
|
125
|
+
send(receiverId: string, amount: Amount): Promise<FinalExecutionOutcome>;
|
|
126
|
+
/**
|
|
127
|
+
* Sign a message using NEP-413 standard.
|
|
128
|
+
*
|
|
129
|
+
* NEP-413 enables off-chain message signing for authentication and ownership verification
|
|
130
|
+
* without gas fees or blockchain transactions. Useful for:
|
|
131
|
+
* - Login/authentication flows
|
|
132
|
+
* - Proving account ownership
|
|
133
|
+
* - Signing intents for meta-transactions
|
|
134
|
+
* - Off-chain authorization
|
|
135
|
+
*
|
|
136
|
+
* @param params - Message signing parameters
|
|
137
|
+
* @param options - Optional signer ID (defaults to first account)
|
|
138
|
+
* @returns Signed message with account ID, public key, and signature
|
|
139
|
+
*
|
|
140
|
+
* @throws {NearError} If no wallet or keystore is configured
|
|
141
|
+
* @throws {NearError} If the key doesn't support NEP-413 signing
|
|
142
|
+
*
|
|
143
|
+
* @see https://github.com/near/NEPs/blob/master/neps/nep-0413.md
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // Sign a message for authentication
|
|
148
|
+
* const signedMessage = await near.signMessage({
|
|
149
|
+
* message: "Login to MyApp",
|
|
150
|
+
* recipient: "myapp.near",
|
|
151
|
+
* nonce: crypto.getRandomValues(new Uint8Array(32)),
|
|
152
|
+
* })
|
|
153
|
+
*
|
|
154
|
+
* // Send to backend for verification
|
|
155
|
+
* await fetch("/api/auth", {
|
|
156
|
+
* method: "POST",
|
|
157
|
+
* body: JSON.stringify(signedMessage),
|
|
158
|
+
* })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
signMessage(params: SignMessageParams | Omit<SignMessageParams, "nonce">, options?: {
|
|
162
|
+
signerId?: string;
|
|
163
|
+
}): Promise<SignedMessage>;
|
|
164
|
+
/**
|
|
165
|
+
* Get account balance in NEAR.
|
|
166
|
+
*
|
|
167
|
+
* @param accountId - Account ID to query.
|
|
168
|
+
* @param options - Optional {@link BlockReference} to control finality or block.
|
|
169
|
+
*
|
|
170
|
+
* @returns Balance formatted as `"X.YY NEAR"`.
|
|
171
|
+
*
|
|
172
|
+
* @throws {AccountDoesNotExistError} If the account does not exist.
|
|
173
|
+
* @throws {NetworkError} If the RPC request fails.
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* This is a convenience helper over {@link RpcClient.getAccount}. For more
|
|
177
|
+
* detailed information (storage, locked balance, etc.) call `rpc.getAccount`
|
|
178
|
+
* directly.
|
|
179
|
+
*/
|
|
180
|
+
getBalance(accountId: string, options?: BlockReference): Promise<string>;
|
|
181
|
+
/**
|
|
182
|
+
* Check if an account exists.
|
|
183
|
+
*
|
|
184
|
+
* @param accountId - Account ID to check.
|
|
185
|
+
* @param options - Optional {@link BlockReference} to control finality or block.
|
|
186
|
+
*
|
|
187
|
+
* @returns `true` if the account exists, `false` otherwise.
|
|
188
|
+
*
|
|
189
|
+
* @remarks
|
|
190
|
+
* This method swallows all errors and returns `false` on failure. Use
|
|
191
|
+
* {@link RpcClient.getAccount} if you need to distinguish error causes.
|
|
192
|
+
*/
|
|
193
|
+
accountExists(accountId: string, options?: BlockReference): Promise<boolean>;
|
|
194
|
+
/**
|
|
195
|
+
* Get transaction status with detailed receipt information
|
|
196
|
+
*
|
|
197
|
+
* Queries the status of a transaction by hash using the EXPERIMENTAL_tx_status RPC method,
|
|
198
|
+
* returning the final transaction result with detailed receipt information.
|
|
199
|
+
*
|
|
200
|
+
* @param txHash - Transaction hash to query
|
|
201
|
+
* @param senderAccountId - Account ID that sent the transaction (used to determine shard)
|
|
202
|
+
* @param waitUntil - Optional execution level to wait for (default: "EXECUTED_OPTIMISTIC")
|
|
203
|
+
*
|
|
204
|
+
* @returns Transaction status with receipts, typed based on waitUntil parameter
|
|
205
|
+
*
|
|
206
|
+
* @throws {InvalidTransactionError} If transaction execution failed
|
|
207
|
+
* @throws {NetworkError} If network request failed
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Get transaction status with default wait level
|
|
212
|
+
* const status = await near.getTransactionStatus(
|
|
213
|
+
* '7AfonAhbK4ZbdBU9VPcQdrTZVZBXE25HmZAMEABs9To1',
|
|
214
|
+
* 'alice.near'
|
|
215
|
+
* )
|
|
216
|
+
*
|
|
217
|
+
* // Wait for full finality
|
|
218
|
+
* const finalStatus = await near.getTransactionStatus(
|
|
219
|
+
* '7AfonAhbK4ZbdBU9VPcQdrTZVZBXE25HmZAMEABs9To1',
|
|
220
|
+
* 'alice.near',
|
|
221
|
+
* 'FINAL'
|
|
222
|
+
* )
|
|
223
|
+
*
|
|
224
|
+
* // Access receipt details
|
|
225
|
+
* console.log('Receipts:', finalStatus.receipts)
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @see {@link https://docs.near.org/api/rpc/transactions#transaction-status-with-receipts NEAR RPC Documentation}
|
|
229
|
+
*/
|
|
230
|
+
getTransactionStatus<W extends "NONE" | "INCLUDED" | "EXECUTED_OPTIMISTIC" | "INCLUDED_FINAL" | "EXECUTED" | "FINAL" = "EXECUTED_OPTIMISTIC">(txHash: string, senderAccountId: string, waitUntil?: W): Promise<W extends keyof FinalExecutionOutcomeWithReceiptsMap ? FinalExecutionOutcomeWithReceiptsMap[W] : never>;
|
|
231
|
+
/**
|
|
232
|
+
* Get basic network status information.
|
|
233
|
+
*
|
|
234
|
+
* @returns An object containing `chainId`, `latestBlockHeight`, and `syncing` flag.
|
|
235
|
+
*/
|
|
236
|
+
getStatus(): Promise<{
|
|
237
|
+
chainId: string;
|
|
238
|
+
latestBlockHeight: number;
|
|
239
|
+
syncing: boolean;
|
|
240
|
+
}>;
|
|
241
|
+
/**
|
|
242
|
+
* Batch multiple read operations.
|
|
243
|
+
*
|
|
244
|
+
* @param promises - Promises to execute in parallel.
|
|
245
|
+
*
|
|
246
|
+
* @returns A tuple of resolved values preserving the input order.
|
|
247
|
+
*
|
|
248
|
+
* @remarks
|
|
249
|
+
* This is a thin wrapper over `Promise.all` with a tuple-friendly signature.
|
|
250
|
+
* It does not perform any RPC-level batching.
|
|
251
|
+
*/
|
|
252
|
+
batch<T extends unknown[]>(...promises: Array<Promise<T[number]>>): Promise<T>;
|
|
253
|
+
/**
|
|
254
|
+
* Create a transaction builder for the specified signer account.
|
|
255
|
+
*
|
|
256
|
+
* The `signerId` determines which account will sign and send this transaction.
|
|
257
|
+
* This account must have keys available in the configured keyStore, privateKey,
|
|
258
|
+
* custom signer, or be connected via wallet.
|
|
259
|
+
*
|
|
260
|
+
* @param signerId - The account ID that will sign and pay for this transaction
|
|
261
|
+
*
|
|
262
|
+
* @returns A transaction builder for chaining actions
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* // Alice sends NEAR to Bob
|
|
267
|
+
* await near.transaction('alice.near')
|
|
268
|
+
* .transfer('bob.near', '10 NEAR')
|
|
269
|
+
* .send()
|
|
270
|
+
*
|
|
271
|
+
* // Alice calls a contract and creates a new account
|
|
272
|
+
* await near.transaction('alice.near')
|
|
273
|
+
* .functionCall('market.near', 'buy', { id: 123 })
|
|
274
|
+
* .createAccount('sub.alice.near')
|
|
275
|
+
* .transfer('sub.alice.near', '5 NEAR')
|
|
276
|
+
* .send()
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @see {@link TransactionBuilder} for available actions
|
|
280
|
+
*/
|
|
281
|
+
transaction(signerId: string): TransactionBuilder;
|
|
282
|
+
/**
|
|
283
|
+
* Create a type-safe contract interface.
|
|
284
|
+
*
|
|
285
|
+
* @param contractId - Account ID of the target contract.
|
|
286
|
+
*
|
|
287
|
+
* @returns A proxy implementing your {@link ContractMethods} interface.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* type Counter = Contract<{
|
|
292
|
+
* view: { get_count: () => Promise<number> }
|
|
293
|
+
* call: { increment: () => Promise<void> }
|
|
294
|
+
* }>
|
|
295
|
+
*
|
|
296
|
+
* const counter = near.contract<Counter>("counter.near")
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
contract<T extends ContractMethods>(contractId: string): T;
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=near.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"near.d.ts","sourceRoot":"","sources":["../../src/core/near.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAM/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAGpD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,UAAU,EAGhB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,KAAK,EACV,qBAAqB,EACrB,oCAAoC,EACrC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EAEb,iBAAiB,EAGlB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;GAWG;AACH,qBAAa,IAAI;IACf,OAAO,CAAC,GAAG,CAAY;IACvB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAC,CAAQ;IACvB,OAAO,CAAC,MAAM,CAAC,CAAkB;IACjC,OAAO,CAAC,eAAe,CAAC,CAAQ;IAChC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,mBAAmB,CAAC,CAAe;gBAE/B,MAAM,GAAE,UAAe;IAenC;;;OAGG;IACH,OAAO,CAAC,cAAc;IAYtB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAMxB;;;;OAIG;IACH,OAAO,CAAC,cAAc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