near-kit 0.0.0 → 0.2.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 +473 -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 +653 -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 +14 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +20 -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/keys/rotating-keystore.d.ts +207 -0
- package/dist/keys/rotating-keystore.d.ts.map +1 -0
- package/dist/keys/rotating-keystore.js +240 -0
- package/dist/keys/rotating-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,653 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent API for building and sending NEAR transactions.
|
|
3
|
+
*
|
|
4
|
+
* Allows chaining multiple actions (transfers, function calls, account creation, etc.)
|
|
5
|
+
* into a single atomic transaction. All actions either succeed together or fail together.
|
|
6
|
+
*
|
|
7
|
+
* The builder is created via {@link Near.transaction} with a signer account ID. This
|
|
8
|
+
* account must have signing credentials available (via keyStore, privateKey, custom
|
|
9
|
+
* signer, or wallet connection).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Single action
|
|
14
|
+
* await near.transaction('alice.near')
|
|
15
|
+
* .transfer('bob.near', '10 NEAR')
|
|
16
|
+
* .send()
|
|
17
|
+
*
|
|
18
|
+
* // Multiple actions (atomic)
|
|
19
|
+
* await near.transaction('alice.near')
|
|
20
|
+
* .createAccount('sub.alice.near')
|
|
21
|
+
* .transfer('sub.alice.near', '5 NEAR')
|
|
22
|
+
* .addKey(newKey, { type: 'fullAccess' })
|
|
23
|
+
* .send()
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - The `signerId` (set via `Near.transaction()`) is the account that signs and pays for gas
|
|
28
|
+
* - All actions execute in the order they are added
|
|
29
|
+
* - Transaction is only sent when `.send()` is called
|
|
30
|
+
* - Use `.build()` to get unsigned transaction
|
|
31
|
+
*/
|
|
32
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
33
|
+
import { base58 } from "@scure/base";
|
|
34
|
+
import { InvalidKeyError, InvalidNonceError, NearError, } from "../errors/index.js";
|
|
35
|
+
import { parseKey, parsePublicKey } from "../utils/key.js";
|
|
36
|
+
import { normalizeAmount, normalizeGas, } from "../utils/validation.js";
|
|
37
|
+
import * as actions from "./actions.js";
|
|
38
|
+
import { DEFAULT_FUNCTION_CALL_GAS } from "./constants.js";
|
|
39
|
+
import { NonceManager } from "./nonce-manager.js";
|
|
40
|
+
import { serializeDelegateAction, serializeSignedTransaction, serializeTransaction, } from "./schema.js";
|
|
41
|
+
/**
|
|
42
|
+
* Compare two public keys for byte-level equality.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
function publicKeysEqual(a, b) {
|
|
46
|
+
if (a.keyType !== b.keyType || a.data.length !== b.data.length) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
for (let i = 0; i < a.data.length; i += 1) {
|
|
50
|
+
if (a.data[i] !== b.data[i]) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Convert user-friendly permission format to Borsh format.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
function toAccessKeyPermissionBorsh(permission) {
|
|
61
|
+
if (permission.type === "fullAccess") {
|
|
62
|
+
return { fullAccess: {} };
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return {
|
|
66
|
+
functionCall: {
|
|
67
|
+
receiverId: permission.receiverId,
|
|
68
|
+
methodNames: permission.methodNames || [],
|
|
69
|
+
allowance: permission.allowance
|
|
70
|
+
? BigInt(normalizeAmount(permission.allowance))
|
|
71
|
+
: null,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fluent builder for constructing and sending NEAR transactions.
|
|
78
|
+
*
|
|
79
|
+
* Created via {@link Near.transaction}. Supports chaining multiple actions
|
|
80
|
+
* (transfers, function calls, key management, staking, delegate actions) into
|
|
81
|
+
* a single atomic transaction.
|
|
82
|
+
*/
|
|
83
|
+
export class TransactionBuilder {
|
|
84
|
+
constructor(signerId, rpc, keyStore, signer, defaultWaitUntil = "EXECUTED_OPTIMISTIC", wallet, ensureKeyStoreReady) {
|
|
85
|
+
this.signerId = signerId;
|
|
86
|
+
this.actions = [];
|
|
87
|
+
this.rpc = rpc;
|
|
88
|
+
this.keyStore = keyStore;
|
|
89
|
+
if (ensureKeyStoreReady !== undefined) {
|
|
90
|
+
this.ensureKeyStoreReady = ensureKeyStoreReady;
|
|
91
|
+
}
|
|
92
|
+
if (signer !== undefined) {
|
|
93
|
+
this.signer = signer;
|
|
94
|
+
}
|
|
95
|
+
this.defaultWaitUntil = defaultWaitUntil;
|
|
96
|
+
if (wallet !== undefined) {
|
|
97
|
+
this.wallet = wallet;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Invalidate cached signed transaction when builder state changes
|
|
102
|
+
*/
|
|
103
|
+
invalidateCache() {
|
|
104
|
+
delete this.cachedSignedTx;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Resolve the key pair for the current signer from either `signWith()` or keyStore.
|
|
109
|
+
*/
|
|
110
|
+
async resolveKeyPair() {
|
|
111
|
+
if (this.keyPair) {
|
|
112
|
+
return this.keyPair;
|
|
113
|
+
}
|
|
114
|
+
if (this.ensureKeyStoreReady) {
|
|
115
|
+
await this.ensureKeyStoreReady();
|
|
116
|
+
}
|
|
117
|
+
const keyPair = await this.keyStore.get(this.signerId);
|
|
118
|
+
if (!keyPair) {
|
|
119
|
+
throw new InvalidKeyError(`No key found for account: ${this.signerId}`);
|
|
120
|
+
}
|
|
121
|
+
// Cache the resolved key pair to ensure keyStore.get() is only called once
|
|
122
|
+
// per TransactionBuilder instance. This is critical for RotatingKeyStore
|
|
123
|
+
// which returns a different key on each get() call.
|
|
124
|
+
this.keyPair = keyPair;
|
|
125
|
+
return keyPair;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Add a token transfer action.
|
|
129
|
+
*
|
|
130
|
+
* @param receiverId - Account ID that will receive the tokens.
|
|
131
|
+
* @param amount - Amount to transfer, expressed as {@link Amount} (e.g. `"10 NEAR"`).
|
|
132
|
+
*
|
|
133
|
+
* @returns This builder instance for chaining.
|
|
134
|
+
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* If no receiver has been set yet, this also sets the transaction `receiverId`
|
|
137
|
+
* to `receiverId`.
|
|
138
|
+
*/
|
|
139
|
+
transfer(receiverId, amount) {
|
|
140
|
+
const amountYocto = normalizeAmount(amount);
|
|
141
|
+
this.actions.push(actions.transfer(BigInt(amountYocto)));
|
|
142
|
+
if (!this.receiverId) {
|
|
143
|
+
this.receiverId = receiverId;
|
|
144
|
+
}
|
|
145
|
+
return this.invalidateCache();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Add a function call action.
|
|
149
|
+
*
|
|
150
|
+
* @param contractId - Account ID of the target contract.
|
|
151
|
+
* @param methodName - Name of the change method to call.
|
|
152
|
+
* @param args - Arguments object or raw bytes; defaults to `{}`.
|
|
153
|
+
* @param options - Optional gas and attached deposit settings.
|
|
154
|
+
*
|
|
155
|
+
* @returns This builder instance for chaining.
|
|
156
|
+
*
|
|
157
|
+
* @remarks
|
|
158
|
+
* - `options.gas` accepts human-readable values such as `"30 Tgas"` or {@link Gas.Tgas}.
|
|
159
|
+
* - `options.attachedDeposit` uses {@link Amount} semantics (e.g. `"1 yocto"`).
|
|
160
|
+
* - If no receiver has been set yet, this also sets the transaction `receiverId`
|
|
161
|
+
* to `contractId`.
|
|
162
|
+
*/
|
|
163
|
+
functionCall(contractId, methodName, args = {}, options = {}) {
|
|
164
|
+
const argsBytes = args instanceof Uint8Array
|
|
165
|
+
? args
|
|
166
|
+
: new TextEncoder().encode(JSON.stringify(args));
|
|
167
|
+
const gas = options.gas
|
|
168
|
+
? normalizeGas(options.gas)
|
|
169
|
+
: DEFAULT_FUNCTION_CALL_GAS;
|
|
170
|
+
const deposit = options.attachedDeposit
|
|
171
|
+
? normalizeAmount(options.attachedDeposit)
|
|
172
|
+
: "0";
|
|
173
|
+
this.actions.push(actions.functionCall(methodName, argsBytes, BigInt(gas), BigInt(deposit)));
|
|
174
|
+
if (!this.receiverId) {
|
|
175
|
+
this.receiverId = contractId;
|
|
176
|
+
}
|
|
177
|
+
return this.invalidateCache();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Add a create account action
|
|
181
|
+
*/
|
|
182
|
+
createAccount(accountId) {
|
|
183
|
+
this.actions.push(actions.createAccount());
|
|
184
|
+
if (!this.receiverId) {
|
|
185
|
+
this.receiverId = accountId;
|
|
186
|
+
}
|
|
187
|
+
return this.invalidateCache();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Add a delete account action
|
|
191
|
+
*/
|
|
192
|
+
deleteAccount(beneficiaryId) {
|
|
193
|
+
this.actions.push(actions.deleteAccount(beneficiaryId));
|
|
194
|
+
// The account being deleted is the receiver of the transaction
|
|
195
|
+
if (!this.receiverId) {
|
|
196
|
+
this.receiverId = this.signerId;
|
|
197
|
+
}
|
|
198
|
+
return this.invalidateCache();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Add a deploy contract action
|
|
202
|
+
*/
|
|
203
|
+
deployContract(accountId, code) {
|
|
204
|
+
this.actions.push(actions.deployContract(code));
|
|
205
|
+
if (!this.receiverId) {
|
|
206
|
+
this.receiverId = accountId;
|
|
207
|
+
}
|
|
208
|
+
return this.invalidateCache();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Publish a global contract that can be reused by multiple accounts
|
|
212
|
+
*
|
|
213
|
+
* @param code - The compiled contract code bytes
|
|
214
|
+
* @param publisherId - Optional account ID. If provided, creates a mutable contract (can be updated).
|
|
215
|
+
* If omitted, creates an immutable contract (identified by code hash).
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* // Publish immutable contract (identified by code hash)
|
|
220
|
+
* await near.transaction(accountId)
|
|
221
|
+
* .publishContract(contractCode)
|
|
222
|
+
* .send()
|
|
223
|
+
*
|
|
224
|
+
* // Publish mutable contract (identified by account, can be updated)
|
|
225
|
+
* await near.transaction(accountId)
|
|
226
|
+
* .publishContract(contractCode, "my-publisher.near")
|
|
227
|
+
* .send()
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
publishContract(code, publisherId) {
|
|
231
|
+
this.actions.push(actions.publishContract(code, publisherId));
|
|
232
|
+
if (!this.receiverId) {
|
|
233
|
+
this.receiverId = this.signerId;
|
|
234
|
+
}
|
|
235
|
+
return this.invalidateCache();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Deploy a contract to this account from previously published code in the global registry
|
|
239
|
+
*
|
|
240
|
+
* @param reference - Reference to the published contract, either:
|
|
241
|
+
* - { codeHash: Uint8Array | string } - Reference by code hash (Uint8Array or base58 string)
|
|
242
|
+
* - { accountId: string } - Reference by the account that published it
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* // Deploy from code hash (Uint8Array)
|
|
247
|
+
* await near.transaction(accountId)
|
|
248
|
+
* .deployFromPublished({ codeHash: hashBytes })
|
|
249
|
+
* .send()
|
|
250
|
+
*
|
|
251
|
+
* // Deploy from code hash (base58 string)
|
|
252
|
+
* await near.transaction(accountId)
|
|
253
|
+
* .deployFromPublished({ codeHash: "5FzD8..." })
|
|
254
|
+
* .send()
|
|
255
|
+
*
|
|
256
|
+
* // Deploy from account ID
|
|
257
|
+
* await near.transaction(accountId)
|
|
258
|
+
* .deployFromPublished({ accountId: "contract-publisher.near" })
|
|
259
|
+
* .send()
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
deployFromPublished(reference) {
|
|
263
|
+
this.actions.push(actions.deployFromPublished(reference));
|
|
264
|
+
if (!this.receiverId) {
|
|
265
|
+
this.receiverId = this.signerId;
|
|
266
|
+
}
|
|
267
|
+
return this.invalidateCache();
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Add a stake action
|
|
271
|
+
*/
|
|
272
|
+
stake(publicKey, amount) {
|
|
273
|
+
const amountYocto = normalizeAmount(amount);
|
|
274
|
+
const pk = parsePublicKey(publicKey);
|
|
275
|
+
this.actions.push(actions.stake(BigInt(amountYocto), pk));
|
|
276
|
+
// The account being staked is the receiver of the transaction
|
|
277
|
+
if (!this.receiverId) {
|
|
278
|
+
this.receiverId = this.signerId;
|
|
279
|
+
}
|
|
280
|
+
return this.invalidateCache();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Add an add key action
|
|
284
|
+
*
|
|
285
|
+
* The key is added to the receiverId of the transaction.
|
|
286
|
+
* If receiverId is not set, it defaults to signerId.
|
|
287
|
+
*/
|
|
288
|
+
addKey(publicKey, permission) {
|
|
289
|
+
const pk = parsePublicKey(publicKey);
|
|
290
|
+
const borshPermission = toAccessKeyPermissionBorsh(permission);
|
|
291
|
+
this.actions.push(actions.addKey(pk, borshPermission));
|
|
292
|
+
// Set receiverId if not already set
|
|
293
|
+
if (!this.receiverId) {
|
|
294
|
+
this.receiverId = this.signerId;
|
|
295
|
+
}
|
|
296
|
+
return this.invalidateCache();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Add a delete key action
|
|
300
|
+
*/
|
|
301
|
+
deleteKey(accountId, publicKey) {
|
|
302
|
+
const pk = parsePublicKey(publicKey);
|
|
303
|
+
this.actions.push(actions.deleteKey(pk));
|
|
304
|
+
if (!this.receiverId) {
|
|
305
|
+
this.receiverId = accountId;
|
|
306
|
+
}
|
|
307
|
+
return this.invalidateCache();
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Build and sign a delegate action from the queued actions.
|
|
311
|
+
*
|
|
312
|
+
* @param options - Optional overrides for receiver, nonce, and expiration
|
|
313
|
+
*/
|
|
314
|
+
/**
|
|
315
|
+
* Add a signed delegate action to this transaction (for relayers).
|
|
316
|
+
*/
|
|
317
|
+
signedDelegateAction(signedDelegate) {
|
|
318
|
+
this.actions.push(signedDelegate);
|
|
319
|
+
this.receiverId = signedDelegate.signedDelegate.delegateAction.senderId;
|
|
320
|
+
return this.invalidateCache();
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Build and sign a delegate action from the queued actions.
|
|
324
|
+
*
|
|
325
|
+
* @returns Signed delegate action ready to be added to a relayer transaction
|
|
326
|
+
*/
|
|
327
|
+
async delegate(options = {}) {
|
|
328
|
+
if (this.actions.length === 0) {
|
|
329
|
+
throw new NearError("Delegate action requires at least one action to perform", "INVALID_TRANSACTION");
|
|
330
|
+
}
|
|
331
|
+
if (this.actions.some((action) => "signedDelegate" in action)) {
|
|
332
|
+
throw new NearError("Delegate actions cannot contain nested signed delegate actions", "INVALID_TRANSACTION");
|
|
333
|
+
}
|
|
334
|
+
const receiverId = options.receiverId ?? this.receiverId;
|
|
335
|
+
if (!receiverId) {
|
|
336
|
+
throw new NearError("Delegate action requires a receiver. Set receiverId via the first action or provide it explicitly.", "INVALID_TRANSACTION");
|
|
337
|
+
}
|
|
338
|
+
const keyPair = await this.resolveKeyPair();
|
|
339
|
+
let delegatePublicKey;
|
|
340
|
+
if (options.publicKey === undefined) {
|
|
341
|
+
delegatePublicKey = keyPair.publicKey;
|
|
342
|
+
}
|
|
343
|
+
else if (typeof options.publicKey === "string") {
|
|
344
|
+
delegatePublicKey = parsePublicKey(options.publicKey);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
delegatePublicKey = options.publicKey;
|
|
348
|
+
}
|
|
349
|
+
if (!publicKeysEqual(delegatePublicKey, keyPair.publicKey)) {
|
|
350
|
+
throw new InvalidKeyError("Delegate action public key must match the signer key. Use signWith() when you need a different key.");
|
|
351
|
+
}
|
|
352
|
+
let nonce;
|
|
353
|
+
if (options.nonce !== undefined) {
|
|
354
|
+
nonce = options.nonce;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
const accessKey = await this.rpc.getAccessKey(this.signerId, delegatePublicKey.toString());
|
|
358
|
+
nonce = BigInt(accessKey.nonce) + 1n;
|
|
359
|
+
}
|
|
360
|
+
let maxBlockHeight;
|
|
361
|
+
if (options.maxBlockHeight !== undefined) {
|
|
362
|
+
maxBlockHeight = options.maxBlockHeight;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
const status = await this.rpc.getStatus();
|
|
366
|
+
const offset = BigInt(options.blockHeightOffset ?? 200);
|
|
367
|
+
maxBlockHeight = BigInt(status.sync_info.latest_block_height) + offset;
|
|
368
|
+
}
|
|
369
|
+
const delegateActions = this.actions.map((action) => action);
|
|
370
|
+
const delegateAction = new actions.DelegateAction(this.signerId, receiverId, delegateActions, nonce, maxBlockHeight, delegatePublicKey);
|
|
371
|
+
const hash = sha256(serializeDelegateAction(delegateAction));
|
|
372
|
+
const signature = keyPair.sign(hash);
|
|
373
|
+
return actions.signedDelegate(delegateAction, signature);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Override the signing function for this specific transaction.
|
|
377
|
+
*
|
|
378
|
+
* Use this to sign with a different signer than the one configured in the
|
|
379
|
+
* Near client, while keeping the same signerId. Useful for:
|
|
380
|
+
*
|
|
381
|
+
* - Using a hardware wallet for a specific transaction
|
|
382
|
+
* - Testing with mock signers
|
|
383
|
+
* - Signing with a specific private key for the same account
|
|
384
|
+
* - One-off custom signing logic
|
|
385
|
+
*
|
|
386
|
+
* **Important:** This overrides HOW the transaction is signed, not WHO signs it.
|
|
387
|
+
* The signerId (set via `.transaction()`) remains the same. To sign as a different
|
|
388
|
+
* account, use `.transaction(otherAccountId)` instead.
|
|
389
|
+
*
|
|
390
|
+
* @param key - Either a custom signer function or a private key string
|
|
391
|
+
* (e.g., 'ed25519:...' or 'secp256k1:...')
|
|
392
|
+
* Type-safe: TypeScript will enforce the correct format at compile time
|
|
393
|
+
* @returns This builder instance for chaining
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```typescript
|
|
397
|
+
* // Override with different hardware wallet
|
|
398
|
+
* await near.transaction('alice.near')
|
|
399
|
+
* .signWith(aliceHardwareWallet)
|
|
400
|
+
* .transfer('bob.near', '5 NEAR')
|
|
401
|
+
* .send()
|
|
402
|
+
*
|
|
403
|
+
* // Sign with specific ed25519 private key (type-safe)
|
|
404
|
+
* await near.transaction('alice.near')
|
|
405
|
+
* .signWith('ed25519:...') // ✅ TypeScript ensures correct format
|
|
406
|
+
* .transfer('bob.near', '1 NEAR')
|
|
407
|
+
* .send()
|
|
408
|
+
*
|
|
409
|
+
* // Sign with specific secp256k1 private key
|
|
410
|
+
* await near.transaction('alice.near')
|
|
411
|
+
* .signWith('secp256k1:...') // ✅ TypeScript ensures correct format
|
|
412
|
+
* .transfer('bob.near', '1 NEAR')
|
|
413
|
+
* .send()
|
|
414
|
+
*
|
|
415
|
+
* // TypeScript will catch mistakes at compile time:
|
|
416
|
+
* await near.transaction('alice.near')
|
|
417
|
+
* .signWith('alice.near') // ❌ Type error: not a PrivateKey
|
|
418
|
+
*
|
|
419
|
+
* // Mock signer for testing
|
|
420
|
+
* const mockSigner: Signer = async (msg) => ({
|
|
421
|
+
* keyType: KeyType.ED25519,
|
|
422
|
+
* data: new Uint8Array(64)
|
|
423
|
+
* })
|
|
424
|
+
*
|
|
425
|
+
* await near.transaction('test.near')
|
|
426
|
+
* .signWith(mockSigner)
|
|
427
|
+
* .transfer('receiver.near', '1')
|
|
428
|
+
* .send()
|
|
429
|
+
* ```
|
|
430
|
+
*
|
|
431
|
+
* @remarks
|
|
432
|
+
* Supports both ed25519 and secp256k1 keys.
|
|
433
|
+
*/
|
|
434
|
+
signWith(key) {
|
|
435
|
+
if (typeof key === "string") {
|
|
436
|
+
// Parse key and create signer
|
|
437
|
+
// TypeScript ensures key is PrivateKey format, but we still validate at runtime
|
|
438
|
+
const keyPair = parseKey(key);
|
|
439
|
+
this.keyPair = keyPair; // Store for build() to use
|
|
440
|
+
this.signer = async (message) => keyPair.sign(message);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
// Clear cached keyPair when using custom signer to prevent stale public key
|
|
444
|
+
delete this.keyPair;
|
|
445
|
+
this.signer = key;
|
|
446
|
+
}
|
|
447
|
+
return this.invalidateCache();
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Build the unsigned transaction
|
|
451
|
+
*/
|
|
452
|
+
async build() {
|
|
453
|
+
if (!this.receiverId) {
|
|
454
|
+
throw new NearError("No receiver ID set for transaction", "INVALID_TRANSACTION");
|
|
455
|
+
}
|
|
456
|
+
// Resolve signer key pair (used for public key + nonce lookup)
|
|
457
|
+
const keyPair = await this.resolveKeyPair();
|
|
458
|
+
const publicKey = keyPair.publicKey;
|
|
459
|
+
// Use NonceManager to get next nonce (handles concurrent transactions)
|
|
460
|
+
const nonce = await TransactionBuilder.nonceManager.getNextNonce(this.signerId, publicKey.toString(), async () => {
|
|
461
|
+
const accessKey = await this.rpc.getAccessKey(this.signerId, publicKey.toString());
|
|
462
|
+
return BigInt(accessKey.nonce);
|
|
463
|
+
});
|
|
464
|
+
const status = await this.rpc.getStatus();
|
|
465
|
+
const blockHash = base58.decode(status.sync_info.latest_block_hash);
|
|
466
|
+
const transaction = {
|
|
467
|
+
signerId: this.signerId,
|
|
468
|
+
publicKey,
|
|
469
|
+
nonce,
|
|
470
|
+
receiverId: this.receiverId,
|
|
471
|
+
actions: this.actions,
|
|
472
|
+
blockHash,
|
|
473
|
+
};
|
|
474
|
+
return transaction;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Sign the transaction without sending it.
|
|
478
|
+
*
|
|
479
|
+
* This creates a signed transaction that can be:
|
|
480
|
+
* - Inspected via `getHash()`
|
|
481
|
+
* - Serialized via `serialize()`
|
|
482
|
+
* - Sent later via `send()`
|
|
483
|
+
*
|
|
484
|
+
* The signed transaction is cached internally. If you modify the transaction
|
|
485
|
+
* (add actions, change signer, etc.), the cache is automatically invalidated.
|
|
486
|
+
*
|
|
487
|
+
* @returns This builder instance (now in a signed state)
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* // Sign and inspect hash
|
|
492
|
+
* const tx = await near.transaction('alice.near')
|
|
493
|
+
* .transfer('bob.near', '1 NEAR')
|
|
494
|
+
* .sign()
|
|
495
|
+
*
|
|
496
|
+
* console.log('Transaction hash:', tx.getHash())
|
|
497
|
+
*
|
|
498
|
+
* // Serialize for offline use
|
|
499
|
+
* const bytes = tx.serialize()
|
|
500
|
+
*
|
|
501
|
+
* // Send when ready
|
|
502
|
+
* const result = await tx.send({ waitUntil: 'FINAL' })
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
async sign() {
|
|
506
|
+
if (this.cachedSignedTx) {
|
|
507
|
+
// Already signed, return this
|
|
508
|
+
return this;
|
|
509
|
+
}
|
|
510
|
+
if (!this.receiverId) {
|
|
511
|
+
throw new NearError("No receiver ID set for transaction", "INVALID_TRANSACTION");
|
|
512
|
+
}
|
|
513
|
+
// Build the transaction
|
|
514
|
+
const transaction = await this.build();
|
|
515
|
+
// Serialize transaction using Borsh
|
|
516
|
+
const serialized = serializeTransaction(transaction);
|
|
517
|
+
// NEAR protocol requires signing the SHA256 hash of the serialized transaction
|
|
518
|
+
const messageHash = (await crypto.subtle.digest("SHA-256", serialized));
|
|
519
|
+
const messageHashArray = new Uint8Array(messageHash);
|
|
520
|
+
// Compute transaction hash (base58 of SHA256)
|
|
521
|
+
const txHash = base58.encode(messageHashArray);
|
|
522
|
+
// Use custom signer if provided, otherwise fall back to keyStore
|
|
523
|
+
const signature = this.signer
|
|
524
|
+
? await this.signer(messageHashArray)
|
|
525
|
+
: (await this.resolveKeyPair()).sign(messageHashArray);
|
|
526
|
+
// Cache the signed transaction
|
|
527
|
+
this.cachedSignedTx = {
|
|
528
|
+
signedTx: {
|
|
529
|
+
transaction,
|
|
530
|
+
signature,
|
|
531
|
+
},
|
|
532
|
+
hash: txHash,
|
|
533
|
+
};
|
|
534
|
+
return this;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Get the transaction hash (only available after signing).
|
|
538
|
+
*
|
|
539
|
+
* @returns The base58-encoded transaction hash, or null if not yet signed
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```typescript
|
|
543
|
+
* const tx = await near.transaction('alice.near')
|
|
544
|
+
* .transfer('bob.near', '1 NEAR')
|
|
545
|
+
* .sign()
|
|
546
|
+
*
|
|
547
|
+
* console.log(tx.getHash()) // "8ZQ7..."
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
getHash() {
|
|
551
|
+
return this.cachedSignedTx?.hash ?? null;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Serialize the signed transaction to bytes.
|
|
555
|
+
*
|
|
556
|
+
* This is useful for:
|
|
557
|
+
* - Storing signed transactions for later broadcast
|
|
558
|
+
* - Sending transactions through external tools
|
|
559
|
+
* - Multi-sig workflows
|
|
560
|
+
*
|
|
561
|
+
* @returns Borsh-serialized signed transaction bytes
|
|
562
|
+
* @throws {NearError} If transaction has not been signed yet
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```typescript
|
|
566
|
+
* const tx = await near.transaction('alice.near')
|
|
567
|
+
* .transfer('bob.near', '1 NEAR')
|
|
568
|
+
* .sign()
|
|
569
|
+
*
|
|
570
|
+
* const bytes = tx.serialize()
|
|
571
|
+
* fs.writeFileSync('transaction.bin', bytes)
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
serialize() {
|
|
575
|
+
if (!this.cachedSignedTx) {
|
|
576
|
+
throw new NearError("Transaction must be signed before serializing. Call .sign() first.", "INVALID_STATE");
|
|
577
|
+
}
|
|
578
|
+
return serializeSignedTransaction(this.cachedSignedTx.signedTx);
|
|
579
|
+
}
|
|
580
|
+
async send(options) {
|
|
581
|
+
if (!this.receiverId) {
|
|
582
|
+
throw new NearError("No receiver ID set for transaction", "INVALID_TRANSACTION");
|
|
583
|
+
}
|
|
584
|
+
// Use wallet if available
|
|
585
|
+
if (this.wallet) {
|
|
586
|
+
const result = await this.wallet.signAndSendTransaction({
|
|
587
|
+
signerId: this.signerId,
|
|
588
|
+
receiverId: this.receiverId,
|
|
589
|
+
actions: this.actions,
|
|
590
|
+
});
|
|
591
|
+
// Wallet doesn't support waitUntil parameter, always returns executed result
|
|
592
|
+
// Cast to the expected type (this is safe because wallet always waits for execution)
|
|
593
|
+
return result;
|
|
594
|
+
}
|
|
595
|
+
// Determine waitUntil - use option if provided, otherwise use default
|
|
596
|
+
const waitUntil = (options?.waitUntil ?? this.defaultWaitUntil);
|
|
597
|
+
// Retry loop for InvalidNonceError
|
|
598
|
+
const MAX_NONCE_RETRIES = 3;
|
|
599
|
+
let lastError = null;
|
|
600
|
+
for (let attempt = 0; attempt < MAX_NONCE_RETRIES; attempt++) {
|
|
601
|
+
try {
|
|
602
|
+
// Sign if not already signed (or re-sign on retry for fresh nonce)
|
|
603
|
+
if (!this.cachedSignedTx || attempt > 0) {
|
|
604
|
+
// Clear cache on retry to get fresh nonce
|
|
605
|
+
delete this.cachedSignedTx;
|
|
606
|
+
await this.sign();
|
|
607
|
+
}
|
|
608
|
+
if (!this.cachedSignedTx) {
|
|
609
|
+
throw new NearError("Failed to sign transaction", "TRANSACTION_SIGNING_FAILED");
|
|
610
|
+
}
|
|
611
|
+
const { signedTx, hash } = this.cachedSignedTx;
|
|
612
|
+
// Serialize signed transaction using Borsh
|
|
613
|
+
const signedSerialized = serializeSignedTransaction(signedTx);
|
|
614
|
+
// Send to network
|
|
615
|
+
const result = await this.rpc.sendTransaction(signedSerialized, waitUntil);
|
|
616
|
+
// Inject minimal transaction fields if not present (for NONE/INCLUDED/INCLUDED_FINAL)
|
|
617
|
+
// This ensures transaction.hash is always available
|
|
618
|
+
if (!("transaction" in result) || !result.transaction) {
|
|
619
|
+
;
|
|
620
|
+
result["transaction"] = {
|
|
621
|
+
hash,
|
|
622
|
+
signer_id: signedTx.transaction.signerId,
|
|
623
|
+
receiver_id: this.receiverId,
|
|
624
|
+
nonce: Number(signedTx.transaction.nonce),
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
return result;
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
lastError = error;
|
|
631
|
+
// Check if it's an InvalidNonceError
|
|
632
|
+
if (error instanceof InvalidNonceError) {
|
|
633
|
+
// Invalidate cached nonce to force fresh fetch on retry
|
|
634
|
+
if (this.cachedSignedTx) {
|
|
635
|
+
TransactionBuilder.nonceManager.invalidate(this.signerId, this.cachedSignedTx.signedTx.transaction.publicKey.toString());
|
|
636
|
+
}
|
|
637
|
+
// If we have retries left, continue the loop to rebuild with fresh nonce
|
|
638
|
+
if (attempt < MAX_NONCE_RETRIES - 1) {
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
// Not an InvalidNonceError or out of retries - throw the error
|
|
643
|
+
throw error;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
// This should never be reached, but TypeScript needs it
|
|
647
|
+
throw (lastError ||
|
|
648
|
+
new NearError("Unknown error during transaction send", "UNKNOWN_TRANSACTION_ERROR"));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
// Shared nonce manager across all TransactionBuilder instances
|
|
652
|
+
TransactionBuilder.nonceManager = new NonceManager();
|
|
653
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,SAAS,GACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAGL,eAAe,EACf,YAAY,GAEb,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB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