near-api-ts 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 +38 -0
- package/dist/index.cjs +3222 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +838 -0
- package/dist/index.d.ts +838 -0
- package/dist/index.js +3169 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
- package/src/_common/configs/constants.ts +23 -0
- package/src/_common/schemas/borsh/actions/addKey.ts +44 -0
- package/src/_common/schemas/borsh/actions/createAccount.ts +7 -0
- package/src/_common/schemas/borsh/actions/deleteAccount.ts +9 -0
- package/src/_common/schemas/borsh/actions/deleteKey.ts +11 -0
- package/src/_common/schemas/borsh/actions/deployContract.ts +9 -0
- package/src/_common/schemas/borsh/actions/deployGlobalContract.ts +24 -0
- package/src/_common/schemas/borsh/actions/functionCall.ts +12 -0
- package/src/_common/schemas/borsh/actions/signedDelegate.ts +13 -0
- package/src/_common/schemas/borsh/actions/stake.ts +12 -0
- package/src/_common/schemas/borsh/actions/transfer.ts +9 -0
- package/src/_common/schemas/borsh/actions/useGlobalContract.ts +23 -0
- package/src/_common/schemas/borsh/delegateAction.ts +41 -0
- package/src/_common/schemas/borsh/index.ts +3 -0
- package/src/_common/schemas/borsh/publicKey.ts +25 -0
- package/src/_common/schemas/borsh/signature.ts +25 -0
- package/src/_common/schemas/borsh/signedTransaction.ts +10 -0
- package/src/_common/schemas/borsh/transaction.ts +42 -0
- package/src/_common/schemas/valibot/common.ts +12 -0
- package/src/_common/schemas/valibot/cryptoHash.ts +12 -0
- package/src/_common/schemas/valibot/curveString.ts +23 -0
- package/src/_common/schemas/valibot/privateKey.ts +38 -0
- package/src/_common/schemas/valibot/publicKey.ts +33 -0
- package/src/_common/schemas/valibot/transaction.ts +42 -0
- package/src/_common/schemas/zod/common.ts +29 -0
- package/src/_common/transformers/contract.ts +11 -0
- package/src/_common/transformers/curveString.ts +27 -0
- package/src/_common/transformers/toBorshBytes/signedTransaction.ts +20 -0
- package/src/_common/transformers/toBorshBytes/transaction.ts +12 -0
- package/src/_common/transformers/toNative/actions/addKey.ts +34 -0
- package/src/_common/transformers/toNative/actions/createAccount.ts +5 -0
- package/src/_common/transformers/toNative/actions/deleteAccount.ts +12 -0
- package/src/_common/transformers/toNative/actions/deleteKey.ts +13 -0
- package/src/_common/transformers/toNative/actions/deployContract.ts +17 -0
- package/src/_common/transformers/toNative/actions/functionCall.ts +22 -0
- package/src/_common/transformers/toNative/actions/transfer.ts +13 -0
- package/src/_common/transformers/toNative/blockReference.ts +30 -0
- package/src/_common/transformers/toNative/publicKey.ts +8 -0
- package/src/_common/transformers/toNative/signature.ts +8 -0
- package/src/_common/transformers/toNative/signedTransaction.ts +13 -0
- package/src/_common/transformers/toNative/transaction.ts +67 -0
- package/src/_common/utils/common.ts +22 -0
- package/src/_common/utils/createCircularQueue.ts +46 -0
- package/src/_common/utils/createLinkedList.ts +30 -0
- package/src/_common/utils/snakeToCamelCase.ts +26 -0
- package/src/_common/utils/tokenConverter/convertTokensToUnits.ts +65 -0
- package/src/_common/utils/tokenConverter/convertUnitsToTokens.ts +71 -0
- package/src/_common/utils/tokenConverter/helpers.ts +26 -0
- package/src/client/createClient/account/getAccountKey.ts +51 -0
- package/src/client/createClient/account/getAccountKeys.ts +47 -0
- package/src/client/createClient/account/getAccountState.ts +65 -0
- package/src/client/createClient/account/helpers/transformKey.ts +36 -0
- package/src/client/createClient/block/getBlock.ts +24 -0
- package/src/client/createClient/contract/callContractReadFunction.ts +66 -0
- package/src/client/createClient/contract/getContractState.ts +60 -0
- package/src/client/createClient/createClient.ts +34 -0
- package/src/client/createClient/createSendRequest.ts +29 -0
- package/src/client/createClient/protocol/getGasPrice.ts +51 -0
- package/src/client/createClient/protocol/getProtocolConfig.ts +39 -0
- package/src/client/createClient/transaction/sendSignedTransaction.ts +31 -0
- package/src/client/presets/networks.ts +21 -0
- package/src/helpers/actionCreators/addFullAccessKey.ts +14 -0
- package/src/helpers/actionCreators/addFunctionCallKey.ts +20 -0
- package/src/helpers/actionCreators/createAccount.ts +5 -0
- package/src/helpers/actionCreators/deleteAccount.ts +11 -0
- package/src/helpers/actionCreators/deleteKey.ts +9 -0
- package/src/helpers/actionCreators/deployContract.ts +13 -0
- package/src/helpers/actionCreators/functionCall.ts +12 -0
- package/src/helpers/actionCreators/transfer.ts +9 -0
- package/src/helpers/crypto/getPublicKey.ts +59 -0
- package/src/helpers/crypto/getRandomPrivateKey.ts +19 -0
- package/src/helpers/crypto/getTransactionHash.ts +21 -0
- package/src/helpers/crypto/sign.ts +69 -0
- package/src/helpers/gas.ts +25 -0
- package/src/helpers/near.ts +118 -0
- package/src/index.ts +19 -0
- package/src/keyServices/memoryKeyService/createFindPrivateKey.ts +11 -0
- package/src/keyServices/memoryKeyService/createMemoryKeyService.ts +23 -0
- package/src/keyServices/memoryKeyService/createSignTransaction.ts +24 -0
- package/src/keyServices/memoryKeyService/parseKeySources.ts +49 -0
- package/src/signers/memorySigner/createMemorySigner.ts +35 -0
- package/src/signers/memorySigner/executors/executeTransaction.ts +30 -0
- package/src/signers/memorySigner/executors/helpers/getSignedTransaction.ts +32 -0
- package/src/signers/memorySigner/executors/signTransaction.ts +26 -0
- package/src/signers/memorySigner/keyPool/createFindKeyForTask.ts +27 -0
- package/src/signers/memorySigner/keyPool/createIsKeyForTaskExist.ts +22 -0
- package/src/signers/memorySigner/keyPool/createKeyPool.ts +37 -0
- package/src/signers/memorySigner/keyPool/getFullAccessKeyList.ts +39 -0
- package/src/signers/memorySigner/keyPool/getFunctionCallKeyList.ts +43 -0
- package/src/signers/memorySigner/keyPool/helpers/keyUtils.ts +13 -0
- package/src/signers/memorySigner/matcher/createMatcher.ts +42 -0
- package/src/signers/memorySigner/resolver/createResolver.ts +21 -0
- package/src/signers/memorySigner/state/createState.ts +27 -0
- package/src/signers/memorySigner/taskQueue/addTask/executeMultipleTransactions.ts +29 -0
- package/src/signers/memorySigner/taskQueue/addTask/executeTransaction.ts +28 -0
- package/src/signers/memorySigner/taskQueue/addTask/helpers/getSigningKeyPriority.ts +39 -0
- package/src/signers/memorySigner/taskQueue/addTask/signMultipleTransactions.ts +26 -0
- package/src/signers/memorySigner/taskQueue/addTask/signTransaction.ts +23 -0
- package/src/signers/memorySigner/taskQueue/createFindTaskForKey.ts +22 -0
- package/src/signers/memorySigner/taskQueue/createTaskQueue.ts +45 -0
- package/types/accountKey.ts +24 -0
- package/types/actions/addKey.ts +48 -0
- package/types/actions/createAccount.ts +9 -0
- package/types/actions/deleteAccount.ts +18 -0
- package/types/actions/deleteKey.ts +18 -0
- package/types/actions/deployContract.ts +19 -0
- package/types/actions/functionCall.ts +32 -0
- package/types/actions/transfer.ts +18 -0
- package/types/client/account/getAccountKey.ts +30 -0
- package/types/client/account/getAccountKeys.ts +28 -0
- package/types/client/account/getAccountState.ts +40 -0
- package/types/client/block/getBlock.ts +13 -0
- package/types/client/client.ts +52 -0
- package/types/client/contract/callContractReadFunction.ts +98 -0
- package/types/client/contract/getContractState.ts +33 -0
- package/types/client/protocol/getGasPrice.ts +16 -0
- package/types/client/protocol/getProtocolConfig.ts +17 -0
- package/types/client/transaction/sendSignedTransaction.ts +19 -0
- package/types/common.ts +79 -0
- package/types/contract.ts +13 -0
- package/types/crypto.ts +25 -0
- package/types/delegateAction.ts +0 -0
- package/types/keyServices/memoryKeyService.ts +26 -0
- package/types/signedTransaction.ts +14 -0
- package/types/signers/memorySigner.ts +59 -0
- package/types/transaction.ts +107 -0
- package/types/utils.ts +44 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3169 @@
|
|
|
1
|
+
// src/client/createClient/createSendRequest.ts
|
|
2
|
+
var createSendRequest = (clientContext) => async ({ body }) => {
|
|
3
|
+
const rpc = clientContext.regularRpcQueue.next();
|
|
4
|
+
const response = await fetch(rpc.url, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
...rpc.headers
|
|
9
|
+
},
|
|
10
|
+
body: JSON.stringify({
|
|
11
|
+
jsonrpc: "2.0",
|
|
12
|
+
id: 0,
|
|
13
|
+
...body
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
const { result, error } = await response.json();
|
|
17
|
+
if (error) throw new Error(error, { cause: error });
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/client/createClient/account/getAccountState.ts
|
|
22
|
+
import * as z2 from "zod/mini";
|
|
23
|
+
|
|
24
|
+
// src/_common/transformers/toNative/blockReference.ts
|
|
25
|
+
var toNativeBlockReference = (blockReference, defaultBlockReference) => {
|
|
26
|
+
if (blockReference === "LatestOptimisticBlock")
|
|
27
|
+
return { finality: "optimistic" };
|
|
28
|
+
if (blockReference === "LatestNearFinalBlock")
|
|
29
|
+
return { finality: "near-final" };
|
|
30
|
+
if (blockReference === "LatestFinalBlock") return { finality: "final" };
|
|
31
|
+
if (blockReference === "EarliestAvailableBlock")
|
|
32
|
+
return { sync_checkpoint: "earliest_available" };
|
|
33
|
+
if (blockReference === "GenesisBlock") return { sync_checkpoint: "genesis" };
|
|
34
|
+
if (blockReference && "blockHash" in blockReference)
|
|
35
|
+
return { block_id: blockReference.blockHash };
|
|
36
|
+
if (blockReference && "blockHeight" in blockReference)
|
|
37
|
+
return { block_id: blockReference.blockHeight };
|
|
38
|
+
if (defaultBlockReference)
|
|
39
|
+
return toNativeBlockReference(defaultBlockReference);
|
|
40
|
+
return { finality: "near-final" };
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/.pnpm/@near-js+jsonrpc-types@1.3.4/node_modules/@near-js/jsonrpc-types/dist/index.mjs
|
|
44
|
+
import { z } from "zod/mini";
|
|
45
|
+
var AccessKeySchema = () => z.object({
|
|
46
|
+
nonce: z.number(),
|
|
47
|
+
permission: z.lazy(() => AccessKeyPermissionSchema())
|
|
48
|
+
});
|
|
49
|
+
var AccessKeyCreationConfigViewSchema = () => z.object({
|
|
50
|
+
fullAccessCost: z.lazy(() => FeeSchema()),
|
|
51
|
+
functionCallCost: z.lazy(() => FeeSchema()),
|
|
52
|
+
functionCallCostPerByte: z.lazy(() => FeeSchema())
|
|
53
|
+
});
|
|
54
|
+
var AccessKeyInfoViewSchema = () => z.object({
|
|
55
|
+
accessKey: z.lazy(() => AccessKeyViewSchema()),
|
|
56
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
57
|
+
});
|
|
58
|
+
var AccessKeyListSchema = () => z.object({
|
|
59
|
+
keys: z.array(z.lazy(() => AccessKeyInfoViewSchema()))
|
|
60
|
+
});
|
|
61
|
+
var AccessKeyPermissionSchema = () => z.union([
|
|
62
|
+
z.object({
|
|
63
|
+
FunctionCall: z.lazy(() => FunctionCallPermissionSchema())
|
|
64
|
+
}),
|
|
65
|
+
z.enum(["FullAccess"])
|
|
66
|
+
]);
|
|
67
|
+
var AccessKeyPermissionViewSchema = () => z.union([
|
|
68
|
+
z.enum(["FullAccess"]),
|
|
69
|
+
z.object({
|
|
70
|
+
FunctionCall: z.object({
|
|
71
|
+
allowance: z.optional(
|
|
72
|
+
z.union([z.union([z.string(), z.null()]), z.null()])
|
|
73
|
+
),
|
|
74
|
+
methodNames: z.array(z.string()),
|
|
75
|
+
receiverId: z.string()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
]);
|
|
79
|
+
var AccessKeyViewSchema = () => z.object({
|
|
80
|
+
nonce: z.number(),
|
|
81
|
+
permission: z.lazy(() => AccessKeyPermissionViewSchema())
|
|
82
|
+
});
|
|
83
|
+
var AccountCreationConfigViewSchema = () => z.object({
|
|
84
|
+
minAllowedTopLevelAccountLength: z.number(),
|
|
85
|
+
registrarAccountId: z.lazy(() => AccountIdSchema())
|
|
86
|
+
});
|
|
87
|
+
var AccountIdSchema = () => z.string();
|
|
88
|
+
var AccountIdValidityRulesVersionSchema = () => z.number();
|
|
89
|
+
var AccountViewSchema = () => z.object({
|
|
90
|
+
amount: z.string(),
|
|
91
|
+
codeHash: z.lazy(() => CryptoHashSchema()),
|
|
92
|
+
globalContractAccountId: z.optional(
|
|
93
|
+
z.union([z.lazy(() => AccountIdSchema()), z.null()])
|
|
94
|
+
),
|
|
95
|
+
globalContractHash: z.optional(
|
|
96
|
+
z.union([z.lazy(() => CryptoHashSchema()), z.null()])
|
|
97
|
+
),
|
|
98
|
+
locked: z.string(),
|
|
99
|
+
storagePaidAt: z.optional(z.number()),
|
|
100
|
+
storageUsage: z.number()
|
|
101
|
+
});
|
|
102
|
+
var ActionCreationConfigViewSchema = () => z.object({
|
|
103
|
+
addKeyCost: z.lazy(() => AccessKeyCreationConfigViewSchema()),
|
|
104
|
+
createAccountCost: z.lazy(() => FeeSchema()),
|
|
105
|
+
delegateCost: z.lazy(() => FeeSchema()),
|
|
106
|
+
deleteAccountCost: z.lazy(() => FeeSchema()),
|
|
107
|
+
deleteKeyCost: z.lazy(() => FeeSchema()),
|
|
108
|
+
deployContractCost: z.lazy(() => FeeSchema()),
|
|
109
|
+
deployContractCostPerByte: z.lazy(() => FeeSchema()),
|
|
110
|
+
functionCallCost: z.lazy(() => FeeSchema()),
|
|
111
|
+
functionCallCostPerByte: z.lazy(() => FeeSchema()),
|
|
112
|
+
stakeCost: z.lazy(() => FeeSchema()),
|
|
113
|
+
transferCost: z.lazy(() => FeeSchema())
|
|
114
|
+
});
|
|
115
|
+
var ActionErrorSchema = () => z.object({
|
|
116
|
+
index: z.optional(z.union([z.union([z.number(), z.null()]), z.null()])),
|
|
117
|
+
kind: z.lazy(() => ActionErrorKindSchema())
|
|
118
|
+
});
|
|
119
|
+
var ActionErrorKindSchema = () => z.union([
|
|
120
|
+
z.object({
|
|
121
|
+
AccountAlreadyExists: z.object({
|
|
122
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
123
|
+
})
|
|
124
|
+
}),
|
|
125
|
+
z.object({
|
|
126
|
+
AccountDoesNotExist: z.object({
|
|
127
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
128
|
+
})
|
|
129
|
+
}),
|
|
130
|
+
z.object({
|
|
131
|
+
CreateAccountOnlyByRegistrar: z.object({
|
|
132
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
133
|
+
predecessorId: z.lazy(() => AccountIdSchema()),
|
|
134
|
+
registrarAccountId: z.lazy(() => AccountIdSchema())
|
|
135
|
+
})
|
|
136
|
+
}),
|
|
137
|
+
z.object({
|
|
138
|
+
CreateAccountNotAllowed: z.object({
|
|
139
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
140
|
+
predecessorId: z.lazy(() => AccountIdSchema())
|
|
141
|
+
})
|
|
142
|
+
}),
|
|
143
|
+
z.object({
|
|
144
|
+
ActorNoPermission: z.object({
|
|
145
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
146
|
+
actorId: z.lazy(() => AccountIdSchema())
|
|
147
|
+
})
|
|
148
|
+
}),
|
|
149
|
+
z.object({
|
|
150
|
+
DeleteKeyDoesNotExist: z.object({
|
|
151
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
152
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
153
|
+
})
|
|
154
|
+
}),
|
|
155
|
+
z.object({
|
|
156
|
+
AddKeyAlreadyExists: z.object({
|
|
157
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
158
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
159
|
+
})
|
|
160
|
+
}),
|
|
161
|
+
z.object({
|
|
162
|
+
DeleteAccountStaking: z.object({
|
|
163
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
164
|
+
})
|
|
165
|
+
}),
|
|
166
|
+
z.object({
|
|
167
|
+
LackBalanceForState: z.object({
|
|
168
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
169
|
+
amount: z.string()
|
|
170
|
+
})
|
|
171
|
+
}),
|
|
172
|
+
z.object({
|
|
173
|
+
TriesToUnstake: z.object({
|
|
174
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
175
|
+
})
|
|
176
|
+
}),
|
|
177
|
+
z.object({
|
|
178
|
+
TriesToStake: z.object({
|
|
179
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
180
|
+
balance: z.string(),
|
|
181
|
+
locked: z.string(),
|
|
182
|
+
stake: z.string()
|
|
183
|
+
})
|
|
184
|
+
}),
|
|
185
|
+
z.object({
|
|
186
|
+
InsufficientStake: z.object({
|
|
187
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
188
|
+
minimumStake: z.string(),
|
|
189
|
+
stake: z.string()
|
|
190
|
+
})
|
|
191
|
+
}),
|
|
192
|
+
z.object({
|
|
193
|
+
FunctionCallError: z.lazy(() => FunctionCallErrorSchema())
|
|
194
|
+
}),
|
|
195
|
+
z.object({
|
|
196
|
+
NewReceiptValidationError: z.lazy(() => ReceiptValidationErrorSchema())
|
|
197
|
+
}),
|
|
198
|
+
z.object({
|
|
199
|
+
OnlyImplicitAccountCreationAllowed: z.object({
|
|
200
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
201
|
+
})
|
|
202
|
+
}),
|
|
203
|
+
z.object({
|
|
204
|
+
DeleteAccountWithLargeState: z.object({
|
|
205
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
206
|
+
})
|
|
207
|
+
}),
|
|
208
|
+
z.enum(["DelegateActionInvalidSignature"]),
|
|
209
|
+
z.object({
|
|
210
|
+
DelegateActionSenderDoesNotMatchTxReceiver: z.object({
|
|
211
|
+
receiverId: z.lazy(() => AccountIdSchema()),
|
|
212
|
+
senderId: z.lazy(() => AccountIdSchema())
|
|
213
|
+
})
|
|
214
|
+
}),
|
|
215
|
+
z.enum(["DelegateActionExpired"]),
|
|
216
|
+
z.object({
|
|
217
|
+
DelegateActionAccessKeyError: z.lazy(() => InvalidAccessKeyErrorSchema())
|
|
218
|
+
}),
|
|
219
|
+
z.object({
|
|
220
|
+
DelegateActionInvalidNonce: z.object({
|
|
221
|
+
akNonce: z.number(),
|
|
222
|
+
delegateNonce: z.number()
|
|
223
|
+
})
|
|
224
|
+
}),
|
|
225
|
+
z.object({
|
|
226
|
+
DelegateActionNonceTooLarge: z.object({
|
|
227
|
+
delegateNonce: z.number(),
|
|
228
|
+
upperBound: z.number()
|
|
229
|
+
})
|
|
230
|
+
}),
|
|
231
|
+
z.object({
|
|
232
|
+
GlobalContractDoesNotExist: z.object({
|
|
233
|
+
identifier: z.lazy(() => GlobalContractIdentifierSchema())
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
]);
|
|
237
|
+
var ActionViewSchema = () => z.union([
|
|
238
|
+
z.enum(["CreateAccount"]),
|
|
239
|
+
z.object({
|
|
240
|
+
DeployContract: z.object({
|
|
241
|
+
code: z.string()
|
|
242
|
+
})
|
|
243
|
+
}),
|
|
244
|
+
z.object({
|
|
245
|
+
FunctionCall: z.object({
|
|
246
|
+
args: z.lazy(() => FunctionArgsSchema()),
|
|
247
|
+
deposit: z.string(),
|
|
248
|
+
gas: z.number(),
|
|
249
|
+
methodName: z.string()
|
|
250
|
+
})
|
|
251
|
+
}),
|
|
252
|
+
z.object({
|
|
253
|
+
Transfer: z.object({
|
|
254
|
+
deposit: z.string()
|
|
255
|
+
})
|
|
256
|
+
}),
|
|
257
|
+
z.object({
|
|
258
|
+
Stake: z.object({
|
|
259
|
+
publicKey: z.lazy(() => PublicKeySchema()),
|
|
260
|
+
stake: z.string()
|
|
261
|
+
})
|
|
262
|
+
}),
|
|
263
|
+
z.object({
|
|
264
|
+
AddKey: z.object({
|
|
265
|
+
accessKey: z.lazy(() => AccessKeyViewSchema()),
|
|
266
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
267
|
+
})
|
|
268
|
+
}),
|
|
269
|
+
z.object({
|
|
270
|
+
DeleteKey: z.object({
|
|
271
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
272
|
+
})
|
|
273
|
+
}),
|
|
274
|
+
z.object({
|
|
275
|
+
DeleteAccount: z.object({
|
|
276
|
+
beneficiaryId: z.lazy(() => AccountIdSchema())
|
|
277
|
+
})
|
|
278
|
+
}),
|
|
279
|
+
z.object({
|
|
280
|
+
Delegate: z.object({
|
|
281
|
+
delegateAction: z.lazy(() => DelegateActionSchema()),
|
|
282
|
+
signature: z.lazy(() => SignatureSchema())
|
|
283
|
+
})
|
|
284
|
+
}),
|
|
285
|
+
z.object({
|
|
286
|
+
DeployGlobalContract: z.object({
|
|
287
|
+
code: z.string()
|
|
288
|
+
})
|
|
289
|
+
}),
|
|
290
|
+
z.object({
|
|
291
|
+
DeployGlobalContractByAccountId: z.object({
|
|
292
|
+
code: z.string()
|
|
293
|
+
})
|
|
294
|
+
}),
|
|
295
|
+
z.object({
|
|
296
|
+
UseGlobalContract: z.object({
|
|
297
|
+
codeHash: z.lazy(() => CryptoHashSchema())
|
|
298
|
+
})
|
|
299
|
+
}),
|
|
300
|
+
z.object({
|
|
301
|
+
UseGlobalContractByAccountId: z.object({
|
|
302
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
]);
|
|
306
|
+
var ActionsValidationErrorSchema = () => z.union([
|
|
307
|
+
z.enum(["DeleteActionMustBeFinal"]),
|
|
308
|
+
z.object({
|
|
309
|
+
TotalPrepaidGasExceeded: z.object({
|
|
310
|
+
limit: z.number(),
|
|
311
|
+
totalPrepaidGas: z.number()
|
|
312
|
+
})
|
|
313
|
+
}),
|
|
314
|
+
z.object({
|
|
315
|
+
TotalNumberOfActionsExceeded: z.object({
|
|
316
|
+
limit: z.number(),
|
|
317
|
+
totalNumberOfActions: z.number()
|
|
318
|
+
})
|
|
319
|
+
}),
|
|
320
|
+
z.object({
|
|
321
|
+
AddKeyMethodNamesNumberOfBytesExceeded: z.object({
|
|
322
|
+
limit: z.number(),
|
|
323
|
+
totalNumberOfBytes: z.number()
|
|
324
|
+
})
|
|
325
|
+
}),
|
|
326
|
+
z.object({
|
|
327
|
+
AddKeyMethodNameLengthExceeded: z.object({
|
|
328
|
+
length: z.number(),
|
|
329
|
+
limit: z.number()
|
|
330
|
+
})
|
|
331
|
+
}),
|
|
332
|
+
z.enum(["IntegerOverflow"]),
|
|
333
|
+
z.object({
|
|
334
|
+
InvalidAccountId: z.object({
|
|
335
|
+
accountId: z.string()
|
|
336
|
+
})
|
|
337
|
+
}),
|
|
338
|
+
z.object({
|
|
339
|
+
ContractSizeExceeded: z.object({
|
|
340
|
+
limit: z.number(),
|
|
341
|
+
size: z.number()
|
|
342
|
+
})
|
|
343
|
+
}),
|
|
344
|
+
z.object({
|
|
345
|
+
FunctionCallMethodNameLengthExceeded: z.object({
|
|
346
|
+
length: z.number(),
|
|
347
|
+
limit: z.number()
|
|
348
|
+
})
|
|
349
|
+
}),
|
|
350
|
+
z.object({
|
|
351
|
+
FunctionCallArgumentsLengthExceeded: z.object({
|
|
352
|
+
length: z.number(),
|
|
353
|
+
limit: z.number()
|
|
354
|
+
})
|
|
355
|
+
}),
|
|
356
|
+
z.object({
|
|
357
|
+
UnsuitableStakingKey: z.object({
|
|
358
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
359
|
+
})
|
|
360
|
+
}),
|
|
361
|
+
z.enum(["FunctionCallZeroAttachedGas"]),
|
|
362
|
+
z.enum(["DelegateActionMustBeOnlyOne"]),
|
|
363
|
+
z.object({
|
|
364
|
+
UnsupportedProtocolFeature: z.object({
|
|
365
|
+
protocolFeature: z.string(),
|
|
366
|
+
version: z.number()
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
]);
|
|
370
|
+
var AddKeyActionSchema = () => z.object({
|
|
371
|
+
accessKey: z.lazy(() => AccessKeySchema()),
|
|
372
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
373
|
+
});
|
|
374
|
+
var BandwidthRequestSchema = () => z.object({
|
|
375
|
+
requestedValuesBitmap: z.lazy(() => BandwidthRequestBitmapSchema()),
|
|
376
|
+
toShard: z.number()
|
|
377
|
+
});
|
|
378
|
+
var BandwidthRequestBitmapSchema = () => z.object({
|
|
379
|
+
data: z.array(z.number())
|
|
380
|
+
});
|
|
381
|
+
var BandwidthRequestsSchema = () => z.object({
|
|
382
|
+
V1: z.lazy(() => BandwidthRequestsV1Schema())
|
|
383
|
+
});
|
|
384
|
+
var BandwidthRequestsV1Schema = () => z.object({
|
|
385
|
+
requests: z.array(z.lazy(() => BandwidthRequestSchema()))
|
|
386
|
+
});
|
|
387
|
+
var BlockHeaderViewSchema = () => z.object({
|
|
388
|
+
approvals: z.array(z.union([z.lazy(() => SignatureSchema()), z.null()])),
|
|
389
|
+
blockBodyHash: z.optional(
|
|
390
|
+
z.union([z.lazy(() => CryptoHashSchema()), z.null()])
|
|
391
|
+
),
|
|
392
|
+
blockMerkleRoot: z.lazy(() => CryptoHashSchema()),
|
|
393
|
+
blockOrdinal: z.optional(
|
|
394
|
+
z.union([z.union([z.number(), z.null()]), z.null()])
|
|
395
|
+
),
|
|
396
|
+
challengesResult: z.array(z.lazy(() => SlashedValidatorSchema())),
|
|
397
|
+
challengesRoot: z.lazy(() => CryptoHashSchema()),
|
|
398
|
+
chunkEndorsements: z.optional(
|
|
399
|
+
z.union([z.union([z.array(z.array(z.number())), z.null()]), z.null()])
|
|
400
|
+
),
|
|
401
|
+
chunkHeadersRoot: z.lazy(() => CryptoHashSchema()),
|
|
402
|
+
chunkMask: z.array(z.boolean()),
|
|
403
|
+
chunkReceiptsRoot: z.lazy(() => CryptoHashSchema()),
|
|
404
|
+
chunkTxRoot: z.lazy(() => CryptoHashSchema()),
|
|
405
|
+
chunksIncluded: z.number(),
|
|
406
|
+
epochId: z.lazy(() => CryptoHashSchema()),
|
|
407
|
+
epochSyncDataHash: z.optional(
|
|
408
|
+
z.union([z.lazy(() => CryptoHashSchema()), z.null()])
|
|
409
|
+
),
|
|
410
|
+
gasPrice: z.string(),
|
|
411
|
+
hash: z.lazy(() => CryptoHashSchema()),
|
|
412
|
+
height: z.number(),
|
|
413
|
+
lastDsFinalBlock: z.lazy(() => CryptoHashSchema()),
|
|
414
|
+
lastFinalBlock: z.lazy(() => CryptoHashSchema()),
|
|
415
|
+
latestProtocolVersion: z.number(),
|
|
416
|
+
nextBpHash: z.lazy(() => CryptoHashSchema()),
|
|
417
|
+
nextEpochId: z.lazy(() => CryptoHashSchema()),
|
|
418
|
+
outcomeRoot: z.lazy(() => CryptoHashSchema()),
|
|
419
|
+
prevHash: z.lazy(() => CryptoHashSchema()),
|
|
420
|
+
prevHeight: z.optional(
|
|
421
|
+
z.union([z.union([z.number(), z.null()]), z.null()])
|
|
422
|
+
),
|
|
423
|
+
prevStateRoot: z.lazy(() => CryptoHashSchema()),
|
|
424
|
+
randomValue: z.lazy(() => CryptoHashSchema()),
|
|
425
|
+
rentPaid: z.string(),
|
|
426
|
+
signature: z.lazy(() => SignatureSchema()),
|
|
427
|
+
timestamp: z.number(),
|
|
428
|
+
timestampNanosec: z.string(),
|
|
429
|
+
totalSupply: z.string(),
|
|
430
|
+
validatorProposals: z.array(z.lazy(() => ValidatorStakeViewSchema())),
|
|
431
|
+
validatorReward: z.string()
|
|
432
|
+
});
|
|
433
|
+
var CallResultSchema = () => z.object({
|
|
434
|
+
logs: z.array(z.string()),
|
|
435
|
+
result: z.array(z.number())
|
|
436
|
+
});
|
|
437
|
+
var ChunkHeaderViewSchema = () => z.object({
|
|
438
|
+
balanceBurnt: z.string(),
|
|
439
|
+
bandwidthRequests: z.optional(
|
|
440
|
+
z.union([z.lazy(() => BandwidthRequestsSchema()), z.null()])
|
|
441
|
+
),
|
|
442
|
+
chunkHash: z.lazy(() => CryptoHashSchema()),
|
|
443
|
+
congestionInfo: z.optional(
|
|
444
|
+
z.union([z.lazy(() => CongestionInfoViewSchema()), z.null()])
|
|
445
|
+
),
|
|
446
|
+
encodedLength: z.number(),
|
|
447
|
+
encodedMerkleRoot: z.lazy(() => CryptoHashSchema()),
|
|
448
|
+
gasLimit: z.number(),
|
|
449
|
+
gasUsed: z.number(),
|
|
450
|
+
heightCreated: z.number(),
|
|
451
|
+
heightIncluded: z.number(),
|
|
452
|
+
outcomeRoot: z.lazy(() => CryptoHashSchema()),
|
|
453
|
+
outgoingReceiptsRoot: z.lazy(() => CryptoHashSchema()),
|
|
454
|
+
prevBlockHash: z.lazy(() => CryptoHashSchema()),
|
|
455
|
+
prevStateRoot: z.lazy(() => CryptoHashSchema()),
|
|
456
|
+
rentPaid: z.string(),
|
|
457
|
+
shardId: z.lazy(() => ShardIdSchema()),
|
|
458
|
+
signature: z.lazy(() => SignatureSchema()),
|
|
459
|
+
txRoot: z.lazy(() => CryptoHashSchema()),
|
|
460
|
+
validatorProposals: z.array(z.lazy(() => ValidatorStakeViewSchema())),
|
|
461
|
+
validatorReward: z.string()
|
|
462
|
+
});
|
|
463
|
+
var CompilationErrorSchema = () => z.union([
|
|
464
|
+
z.object({
|
|
465
|
+
CodeDoesNotExist: z.object({
|
|
466
|
+
accountId: z.lazy(() => AccountIdSchema())
|
|
467
|
+
})
|
|
468
|
+
}),
|
|
469
|
+
z.object({
|
|
470
|
+
PrepareError: z.lazy(() => PrepareErrorSchema())
|
|
471
|
+
}),
|
|
472
|
+
z.object({
|
|
473
|
+
WasmerCompileError: z.object({
|
|
474
|
+
msg: z.string()
|
|
475
|
+
})
|
|
476
|
+
})
|
|
477
|
+
]);
|
|
478
|
+
var CongestionControlConfigViewSchema = () => z.object({
|
|
479
|
+
allowedShardOutgoingGas: z.number(),
|
|
480
|
+
maxCongestionIncomingGas: z.number(),
|
|
481
|
+
maxCongestionMemoryConsumption: z.number(),
|
|
482
|
+
maxCongestionMissedChunks: z.number(),
|
|
483
|
+
maxCongestionOutgoingGas: z.number(),
|
|
484
|
+
maxOutgoingGas: z.number(),
|
|
485
|
+
maxTxGas: z.number(),
|
|
486
|
+
minOutgoingGas: z.number(),
|
|
487
|
+
minTxGas: z.number(),
|
|
488
|
+
outgoingReceiptsBigSizeLimit: z.number(),
|
|
489
|
+
outgoingReceiptsUsualSizeLimit: z.number(),
|
|
490
|
+
rejectTxCongestionThreshold: z.number()
|
|
491
|
+
});
|
|
492
|
+
var CongestionInfoViewSchema = () => z.object({
|
|
493
|
+
allowedShard: z.number(),
|
|
494
|
+
bufferedReceiptsGas: z.string(),
|
|
495
|
+
delayedReceiptsGas: z.string(),
|
|
496
|
+
receiptBytes: z.number()
|
|
497
|
+
});
|
|
498
|
+
var CostGasUsedSchema = () => z.object({
|
|
499
|
+
cost: z.string(),
|
|
500
|
+
costCategory: z.string(),
|
|
501
|
+
gasUsed: z.string()
|
|
502
|
+
});
|
|
503
|
+
var CreateAccountActionSchema = () => z.record(z.string(), z.unknown());
|
|
504
|
+
var CryptoHashSchema = () => z.string();
|
|
505
|
+
var DataReceiptCreationConfigViewSchema = () => z.object({
|
|
506
|
+
baseCost: z.lazy(() => FeeSchema()),
|
|
507
|
+
costPerByte: z.lazy(() => FeeSchema())
|
|
508
|
+
});
|
|
509
|
+
var DataReceiverViewSchema = () => z.object({
|
|
510
|
+
dataId: z.lazy(() => CryptoHashSchema()),
|
|
511
|
+
receiverId: z.lazy(() => AccountIdSchema())
|
|
512
|
+
});
|
|
513
|
+
var DelegateActionSchema = () => z.object({
|
|
514
|
+
actions: z.array(z.lazy(() => NonDelegateActionSchema())),
|
|
515
|
+
maxBlockHeight: z.number(),
|
|
516
|
+
nonce: z.number(),
|
|
517
|
+
publicKey: z.lazy(() => PublicKeySchema()),
|
|
518
|
+
receiverId: z.lazy(() => AccountIdSchema()),
|
|
519
|
+
senderId: z.lazy(() => AccountIdSchema())
|
|
520
|
+
});
|
|
521
|
+
var DeleteAccountActionSchema = () => z.object({
|
|
522
|
+
beneficiaryId: z.lazy(() => AccountIdSchema())
|
|
523
|
+
});
|
|
524
|
+
var DeleteKeyActionSchema = () => z.object({
|
|
525
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
526
|
+
});
|
|
527
|
+
var DeployContractActionSchema = () => z.object({
|
|
528
|
+
code: z.string()
|
|
529
|
+
});
|
|
530
|
+
var DeployGlobalContractActionSchema = () => z.object({
|
|
531
|
+
code: z.string(),
|
|
532
|
+
deployMode: z.lazy(() => GlobalContractDeployModeSchema())
|
|
533
|
+
});
|
|
534
|
+
var DirectionSchema = () => z.enum(["Left", "Right"]);
|
|
535
|
+
var ExecutionMetadataViewSchema = () => z.object({
|
|
536
|
+
gasProfile: z.optional(
|
|
537
|
+
z.union([
|
|
538
|
+
z.union([z.array(z.lazy(() => CostGasUsedSchema())), z.null()]),
|
|
539
|
+
z.null()
|
|
540
|
+
])
|
|
541
|
+
),
|
|
542
|
+
version: z.number()
|
|
543
|
+
});
|
|
544
|
+
var ExecutionOutcomeViewSchema = () => z.object({
|
|
545
|
+
executorId: z.lazy(() => AccountIdSchema()),
|
|
546
|
+
gasBurnt: z.number(),
|
|
547
|
+
logs: z.array(z.string()),
|
|
548
|
+
metadata: z.optional(z.lazy(() => ExecutionMetadataViewSchema())),
|
|
549
|
+
receiptIds: z.array(z.lazy(() => CryptoHashSchema())),
|
|
550
|
+
status: z.lazy(() => ExecutionStatusViewSchema()),
|
|
551
|
+
tokensBurnt: z.string()
|
|
552
|
+
});
|
|
553
|
+
var ExecutionOutcomeWithIdViewSchema = () => z.object({
|
|
554
|
+
blockHash: z.lazy(() => CryptoHashSchema()),
|
|
555
|
+
id: z.lazy(() => CryptoHashSchema()),
|
|
556
|
+
outcome: z.lazy(() => ExecutionOutcomeViewSchema()),
|
|
557
|
+
proof: z.array(z.lazy(() => MerklePathItemSchema()))
|
|
558
|
+
});
|
|
559
|
+
var ExecutionStatusViewSchema = () => z.union([
|
|
560
|
+
z.enum(["Unknown"]),
|
|
561
|
+
z.object({
|
|
562
|
+
Failure: z.lazy(() => TxExecutionErrorSchema())
|
|
563
|
+
}),
|
|
564
|
+
z.object({
|
|
565
|
+
SuccessValue: z.string()
|
|
566
|
+
}),
|
|
567
|
+
z.object({
|
|
568
|
+
SuccessReceiptId: z.lazy(() => CryptoHashSchema())
|
|
569
|
+
})
|
|
570
|
+
]);
|
|
571
|
+
var ExtCostsConfigViewSchema = () => z.object({
|
|
572
|
+
altBn128G1MultiexpBase: z.number(),
|
|
573
|
+
altBn128G1MultiexpElement: z.number(),
|
|
574
|
+
altBn128G1SumBase: z.number(),
|
|
575
|
+
altBn128G1SumElement: z.number(),
|
|
576
|
+
altBn128PairingCheckBase: z.number(),
|
|
577
|
+
altBn128PairingCheckElement: z.number(),
|
|
578
|
+
base: z.number(),
|
|
579
|
+
bls12381G1MultiexpBase: z.number(),
|
|
580
|
+
bls12381G1MultiexpElement: z.number(),
|
|
581
|
+
bls12381G2MultiexpBase: z.number(),
|
|
582
|
+
bls12381G2MultiexpElement: z.number(),
|
|
583
|
+
bls12381MapFp2ToG2Base: z.number(),
|
|
584
|
+
bls12381MapFp2ToG2Element: z.number(),
|
|
585
|
+
bls12381MapFpToG1Base: z.number(),
|
|
586
|
+
bls12381MapFpToG1Element: z.number(),
|
|
587
|
+
bls12381P1DecompressBase: z.number(),
|
|
588
|
+
bls12381P1DecompressElement: z.number(),
|
|
589
|
+
bls12381P1SumBase: z.number(),
|
|
590
|
+
bls12381P1SumElement: z.number(),
|
|
591
|
+
bls12381P2DecompressBase: z.number(),
|
|
592
|
+
bls12381P2DecompressElement: z.number(),
|
|
593
|
+
bls12381P2SumBase: z.number(),
|
|
594
|
+
bls12381P2SumElement: z.number(),
|
|
595
|
+
bls12381PairingBase: z.number(),
|
|
596
|
+
bls12381PairingElement: z.number(),
|
|
597
|
+
contractCompileBase: z.number(),
|
|
598
|
+
contractCompileBytes: z.number(),
|
|
599
|
+
contractLoadingBase: z.number(),
|
|
600
|
+
contractLoadingBytes: z.number(),
|
|
601
|
+
ecrecoverBase: z.number(),
|
|
602
|
+
ed25519VerifyBase: z.number(),
|
|
603
|
+
ed25519VerifyByte: z.number(),
|
|
604
|
+
keccak256Base: z.number(),
|
|
605
|
+
keccak256Byte: z.number(),
|
|
606
|
+
keccak512Base: z.number(),
|
|
607
|
+
keccak512Byte: z.number(),
|
|
608
|
+
logBase: z.number(),
|
|
609
|
+
logByte: z.number(),
|
|
610
|
+
promiseAndBase: z.number(),
|
|
611
|
+
promiseAndPerPromise: z.number(),
|
|
612
|
+
promiseReturn: z.number(),
|
|
613
|
+
readCachedTrieNode: z.number(),
|
|
614
|
+
readMemoryBase: z.number(),
|
|
615
|
+
readMemoryByte: z.number(),
|
|
616
|
+
readRegisterBase: z.number(),
|
|
617
|
+
readRegisterByte: z.number(),
|
|
618
|
+
ripemd160Base: z.number(),
|
|
619
|
+
ripemd160Block: z.number(),
|
|
620
|
+
sha256Base: z.number(),
|
|
621
|
+
sha256Byte: z.number(),
|
|
622
|
+
storageHasKeyBase: z.number(),
|
|
623
|
+
storageHasKeyByte: z.number(),
|
|
624
|
+
storageIterCreateFromByte: z.number(),
|
|
625
|
+
storageIterCreatePrefixBase: z.number(),
|
|
626
|
+
storageIterCreatePrefixByte: z.number(),
|
|
627
|
+
storageIterCreateRangeBase: z.number(),
|
|
628
|
+
storageIterCreateToByte: z.number(),
|
|
629
|
+
storageIterNextBase: z.number(),
|
|
630
|
+
storageIterNextKeyByte: z.number(),
|
|
631
|
+
storageIterNextValueByte: z.number(),
|
|
632
|
+
storageLargeReadOverheadBase: z.number(),
|
|
633
|
+
storageLargeReadOverheadByte: z.number(),
|
|
634
|
+
storageReadBase: z.number(),
|
|
635
|
+
storageReadKeyByte: z.number(),
|
|
636
|
+
storageReadValueByte: z.number(),
|
|
637
|
+
storageRemoveBase: z.number(),
|
|
638
|
+
storageRemoveKeyByte: z.number(),
|
|
639
|
+
storageRemoveRetValueByte: z.number(),
|
|
640
|
+
storageWriteBase: z.number(),
|
|
641
|
+
storageWriteEvictedByte: z.number(),
|
|
642
|
+
storageWriteKeyByte: z.number(),
|
|
643
|
+
storageWriteValueByte: z.number(),
|
|
644
|
+
touchingTrieNode: z.number(),
|
|
645
|
+
utf16DecodingBase: z.number(),
|
|
646
|
+
utf16DecodingByte: z.number(),
|
|
647
|
+
utf8DecodingBase: z.number(),
|
|
648
|
+
utf8DecodingByte: z.number(),
|
|
649
|
+
validatorStakeBase: z.number(),
|
|
650
|
+
validatorTotalStakeBase: z.number(),
|
|
651
|
+
writeMemoryBase: z.number(),
|
|
652
|
+
writeMemoryByte: z.number(),
|
|
653
|
+
writeRegisterBase: z.number(),
|
|
654
|
+
writeRegisterByte: z.number(),
|
|
655
|
+
yieldCreateBase: z.number(),
|
|
656
|
+
yieldCreateByte: z.number(),
|
|
657
|
+
yieldResumeBase: z.number(),
|
|
658
|
+
yieldResumeByte: z.number()
|
|
659
|
+
});
|
|
660
|
+
var FeeSchema = () => z.object({
|
|
661
|
+
execution: z.number(),
|
|
662
|
+
sendNotSir: z.number(),
|
|
663
|
+
sendSir: z.number()
|
|
664
|
+
});
|
|
665
|
+
var FinalExecutionOutcomeViewSchema = () => z.object({
|
|
666
|
+
receiptsOutcome: z.array(z.lazy(() => ExecutionOutcomeWithIdViewSchema())),
|
|
667
|
+
status: z.lazy(() => FinalExecutionStatusSchema()),
|
|
668
|
+
transaction: z.lazy(() => SignedTransactionViewSchema()),
|
|
669
|
+
transactionOutcome: z.lazy(() => ExecutionOutcomeWithIdViewSchema())
|
|
670
|
+
});
|
|
671
|
+
var FinalExecutionOutcomeWithReceiptViewSchema = () => z.object({
|
|
672
|
+
receipts: z.array(z.lazy(() => ReceiptViewSchema())),
|
|
673
|
+
receiptsOutcome: z.array(z.lazy(() => ExecutionOutcomeWithIdViewSchema())),
|
|
674
|
+
status: z.lazy(() => FinalExecutionStatusSchema()),
|
|
675
|
+
transaction: z.lazy(() => SignedTransactionViewSchema()),
|
|
676
|
+
transactionOutcome: z.lazy(() => ExecutionOutcomeWithIdViewSchema())
|
|
677
|
+
});
|
|
678
|
+
var FinalExecutionStatusSchema = () => z.union([
|
|
679
|
+
z.enum(["NotStarted"]),
|
|
680
|
+
z.enum(["Started"]),
|
|
681
|
+
z.object({
|
|
682
|
+
Failure: z.lazy(() => TxExecutionErrorSchema())
|
|
683
|
+
}),
|
|
684
|
+
z.object({
|
|
685
|
+
SuccessValue: z.string()
|
|
686
|
+
})
|
|
687
|
+
]);
|
|
688
|
+
var FunctionArgsSchema = () => z.string();
|
|
689
|
+
var FunctionCallActionSchema = () => z.object({
|
|
690
|
+
args: z.string(),
|
|
691
|
+
deposit: z.string(),
|
|
692
|
+
gas: z.number(),
|
|
693
|
+
methodName: z.string()
|
|
694
|
+
});
|
|
695
|
+
var FunctionCallErrorSchema = () => z.union([
|
|
696
|
+
z.enum(["WasmUnknownError", "_EVMError"]),
|
|
697
|
+
z.object({
|
|
698
|
+
CompilationError: z.lazy(() => CompilationErrorSchema())
|
|
699
|
+
}),
|
|
700
|
+
z.object({
|
|
701
|
+
LinkError: z.object({
|
|
702
|
+
msg: z.string()
|
|
703
|
+
})
|
|
704
|
+
}),
|
|
705
|
+
z.object({
|
|
706
|
+
MethodResolveError: z.lazy(() => MethodResolveErrorSchema())
|
|
707
|
+
}),
|
|
708
|
+
z.object({
|
|
709
|
+
WasmTrap: z.lazy(() => WasmTrapSchema())
|
|
710
|
+
}),
|
|
711
|
+
z.object({
|
|
712
|
+
HostError: z.lazy(() => HostErrorSchema())
|
|
713
|
+
}),
|
|
714
|
+
z.object({
|
|
715
|
+
ExecutionError: z.string()
|
|
716
|
+
})
|
|
717
|
+
]);
|
|
718
|
+
var FunctionCallPermissionSchema = () => z.object({
|
|
719
|
+
allowance: z.optional(z.union([z.union([z.string(), z.null()]), z.null()])),
|
|
720
|
+
methodNames: z.array(z.string()),
|
|
721
|
+
receiverId: z.string()
|
|
722
|
+
});
|
|
723
|
+
var GlobalContractDeployModeSchema = () => z.union([z.enum(["CodeHash"]), z.enum(["AccountId"])]);
|
|
724
|
+
var GlobalContractIdentifierSchema = () => z.union([
|
|
725
|
+
z.object({
|
|
726
|
+
CodeHash: z.lazy(() => CryptoHashSchema())
|
|
727
|
+
}),
|
|
728
|
+
z.object({
|
|
729
|
+
AccountId: z.lazy(() => AccountIdSchema())
|
|
730
|
+
})
|
|
731
|
+
]);
|
|
732
|
+
var HostErrorSchema = () => z.union([
|
|
733
|
+
z.enum(["BadUTF16"]),
|
|
734
|
+
z.enum(["BadUTF8"]),
|
|
735
|
+
z.enum(["GasExceeded"]),
|
|
736
|
+
z.enum(["GasLimitExceeded"]),
|
|
737
|
+
z.enum(["BalanceExceeded"]),
|
|
738
|
+
z.enum(["EmptyMethodName"]),
|
|
739
|
+
z.object({
|
|
740
|
+
GuestPanic: z.object({
|
|
741
|
+
panicMsg: z.string()
|
|
742
|
+
})
|
|
743
|
+
}),
|
|
744
|
+
z.enum(["IntegerOverflow"]),
|
|
745
|
+
z.object({
|
|
746
|
+
InvalidPromiseIndex: z.object({
|
|
747
|
+
promiseIdx: z.number()
|
|
748
|
+
})
|
|
749
|
+
}),
|
|
750
|
+
z.enum(["CannotAppendActionToJointPromise"]),
|
|
751
|
+
z.enum(["CannotReturnJointPromise"]),
|
|
752
|
+
z.object({
|
|
753
|
+
InvalidPromiseResultIndex: z.object({
|
|
754
|
+
resultIdx: z.number()
|
|
755
|
+
})
|
|
756
|
+
}),
|
|
757
|
+
z.object({
|
|
758
|
+
InvalidRegisterId: z.object({
|
|
759
|
+
registerId: z.number()
|
|
760
|
+
})
|
|
761
|
+
}),
|
|
762
|
+
z.object({
|
|
763
|
+
IteratorWasInvalidated: z.object({
|
|
764
|
+
iteratorIndex: z.number()
|
|
765
|
+
})
|
|
766
|
+
}),
|
|
767
|
+
z.enum(["MemoryAccessViolation"]),
|
|
768
|
+
z.object({
|
|
769
|
+
InvalidReceiptIndex: z.object({
|
|
770
|
+
receiptIndex: z.number()
|
|
771
|
+
})
|
|
772
|
+
}),
|
|
773
|
+
z.object({
|
|
774
|
+
InvalidIteratorIndex: z.object({
|
|
775
|
+
iteratorIndex: z.number()
|
|
776
|
+
})
|
|
777
|
+
}),
|
|
778
|
+
z.enum(["InvalidAccountId"]),
|
|
779
|
+
z.enum(["InvalidMethodName"]),
|
|
780
|
+
z.enum(["InvalidPublicKey"]),
|
|
781
|
+
z.object({
|
|
782
|
+
ProhibitedInView: z.object({
|
|
783
|
+
methodName: z.string()
|
|
784
|
+
})
|
|
785
|
+
}),
|
|
786
|
+
z.object({
|
|
787
|
+
NumberOfLogsExceeded: z.object({
|
|
788
|
+
limit: z.number()
|
|
789
|
+
})
|
|
790
|
+
}),
|
|
791
|
+
z.object({
|
|
792
|
+
KeyLengthExceeded: z.object({
|
|
793
|
+
length: z.number(),
|
|
794
|
+
limit: z.number()
|
|
795
|
+
})
|
|
796
|
+
}),
|
|
797
|
+
z.object({
|
|
798
|
+
ValueLengthExceeded: z.object({
|
|
799
|
+
length: z.number(),
|
|
800
|
+
limit: z.number()
|
|
801
|
+
})
|
|
802
|
+
}),
|
|
803
|
+
z.object({
|
|
804
|
+
TotalLogLengthExceeded: z.object({
|
|
805
|
+
length: z.number(),
|
|
806
|
+
limit: z.number()
|
|
807
|
+
})
|
|
808
|
+
}),
|
|
809
|
+
z.object({
|
|
810
|
+
NumberPromisesExceeded: z.object({
|
|
811
|
+
limit: z.number(),
|
|
812
|
+
numberOfPromises: z.number()
|
|
813
|
+
})
|
|
814
|
+
}),
|
|
815
|
+
z.object({
|
|
816
|
+
NumberInputDataDependenciesExceeded: z.object({
|
|
817
|
+
limit: z.number(),
|
|
818
|
+
numberOfInputDataDependencies: z.number()
|
|
819
|
+
})
|
|
820
|
+
}),
|
|
821
|
+
z.object({
|
|
822
|
+
ReturnedValueLengthExceeded: z.object({
|
|
823
|
+
length: z.number(),
|
|
824
|
+
limit: z.number()
|
|
825
|
+
})
|
|
826
|
+
}),
|
|
827
|
+
z.object({
|
|
828
|
+
ContractSizeExceeded: z.object({
|
|
829
|
+
limit: z.number(),
|
|
830
|
+
size: z.number()
|
|
831
|
+
})
|
|
832
|
+
}),
|
|
833
|
+
z.object({
|
|
834
|
+
Deprecated: z.object({
|
|
835
|
+
methodName: z.string()
|
|
836
|
+
})
|
|
837
|
+
}),
|
|
838
|
+
z.object({
|
|
839
|
+
ECRecoverError: z.object({
|
|
840
|
+
msg: z.string()
|
|
841
|
+
})
|
|
842
|
+
}),
|
|
843
|
+
z.object({
|
|
844
|
+
AltBn128InvalidInput: z.object({
|
|
845
|
+
msg: z.string()
|
|
846
|
+
})
|
|
847
|
+
}),
|
|
848
|
+
z.object({
|
|
849
|
+
Ed25519VerifyInvalidInput: z.object({
|
|
850
|
+
msg: z.string()
|
|
851
|
+
})
|
|
852
|
+
})
|
|
853
|
+
]);
|
|
854
|
+
var InvalidAccessKeyErrorSchema = () => z.union([
|
|
855
|
+
z.object({
|
|
856
|
+
AccessKeyNotFound: z.object({
|
|
857
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
858
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
859
|
+
})
|
|
860
|
+
}),
|
|
861
|
+
z.object({
|
|
862
|
+
ReceiverMismatch: z.object({
|
|
863
|
+
akReceiver: z.string(),
|
|
864
|
+
txReceiver: z.lazy(() => AccountIdSchema())
|
|
865
|
+
})
|
|
866
|
+
}),
|
|
867
|
+
z.object({
|
|
868
|
+
MethodNameMismatch: z.object({
|
|
869
|
+
methodName: z.string()
|
|
870
|
+
})
|
|
871
|
+
}),
|
|
872
|
+
z.enum(["RequiresFullAccess"]),
|
|
873
|
+
z.object({
|
|
874
|
+
NotEnoughAllowance: z.object({
|
|
875
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
876
|
+
allowance: z.string(),
|
|
877
|
+
cost: z.string(),
|
|
878
|
+
publicKey: z.lazy(() => PublicKeySchema())
|
|
879
|
+
})
|
|
880
|
+
}),
|
|
881
|
+
z.enum(["DepositWithFunctionCall"])
|
|
882
|
+
]);
|
|
883
|
+
var InvalidTxErrorSchema = () => z.union([
|
|
884
|
+
z.object({
|
|
885
|
+
InvalidAccessKeyError: z.lazy(() => InvalidAccessKeyErrorSchema())
|
|
886
|
+
}),
|
|
887
|
+
z.object({
|
|
888
|
+
InvalidSignerId: z.object({
|
|
889
|
+
signerId: z.string()
|
|
890
|
+
})
|
|
891
|
+
}),
|
|
892
|
+
z.object({
|
|
893
|
+
SignerDoesNotExist: z.object({
|
|
894
|
+
signerId: z.lazy(() => AccountIdSchema())
|
|
895
|
+
})
|
|
896
|
+
}),
|
|
897
|
+
z.object({
|
|
898
|
+
InvalidNonce: z.object({
|
|
899
|
+
akNonce: z.number(),
|
|
900
|
+
txNonce: z.number()
|
|
901
|
+
})
|
|
902
|
+
}),
|
|
903
|
+
z.object({
|
|
904
|
+
NonceTooLarge: z.object({
|
|
905
|
+
txNonce: z.number(),
|
|
906
|
+
upperBound: z.number()
|
|
907
|
+
})
|
|
908
|
+
}),
|
|
909
|
+
z.object({
|
|
910
|
+
InvalidReceiverId: z.object({
|
|
911
|
+
receiverId: z.string()
|
|
912
|
+
})
|
|
913
|
+
}),
|
|
914
|
+
z.enum(["InvalidSignature"]),
|
|
915
|
+
z.object({
|
|
916
|
+
NotEnoughBalance: z.object({
|
|
917
|
+
balance: z.string(),
|
|
918
|
+
cost: z.string(),
|
|
919
|
+
signerId: z.lazy(() => AccountIdSchema())
|
|
920
|
+
})
|
|
921
|
+
}),
|
|
922
|
+
z.object({
|
|
923
|
+
LackBalanceForState: z.object({
|
|
924
|
+
amount: z.string(),
|
|
925
|
+
signerId: z.lazy(() => AccountIdSchema())
|
|
926
|
+
})
|
|
927
|
+
}),
|
|
928
|
+
z.enum(["CostOverflow"]),
|
|
929
|
+
z.enum(["InvalidChain"]),
|
|
930
|
+
z.enum(["Expired"]),
|
|
931
|
+
z.object({
|
|
932
|
+
ActionsValidation: z.lazy(() => ActionsValidationErrorSchema())
|
|
933
|
+
}),
|
|
934
|
+
z.object({
|
|
935
|
+
TransactionSizeExceeded: z.object({
|
|
936
|
+
limit: z.number(),
|
|
937
|
+
size: z.number()
|
|
938
|
+
})
|
|
939
|
+
}),
|
|
940
|
+
z.enum(["InvalidTransactionVersion"]),
|
|
941
|
+
z.object({
|
|
942
|
+
StorageError: z.lazy(() => StorageErrorSchema())
|
|
943
|
+
}),
|
|
944
|
+
z.object({
|
|
945
|
+
ShardCongested: z.object({
|
|
946
|
+
congestionLevel: z.number(),
|
|
947
|
+
shardId: z.number()
|
|
948
|
+
})
|
|
949
|
+
}),
|
|
950
|
+
z.object({
|
|
951
|
+
ShardStuck: z.object({
|
|
952
|
+
missedChunks: z.number(),
|
|
953
|
+
shardId: z.number()
|
|
954
|
+
})
|
|
955
|
+
})
|
|
956
|
+
]);
|
|
957
|
+
var LimitConfigSchema = () => z.object({
|
|
958
|
+
accountIdValidityRulesVersion: z.optional(
|
|
959
|
+
z.lazy(() => AccountIdValidityRulesVersionSchema())
|
|
960
|
+
),
|
|
961
|
+
initialMemoryPages: z.number(),
|
|
962
|
+
maxActionsPerReceipt: z.number(),
|
|
963
|
+
maxArgumentsLength: z.number(),
|
|
964
|
+
maxContractSize: z.number(),
|
|
965
|
+
maxElementsPerContractTable: z.optional(
|
|
966
|
+
z.union([z.union([z.number(), z.null()]), z.null()])
|
|
967
|
+
),
|
|
968
|
+
maxFunctionsNumberPerContract: z.optional(
|
|
969
|
+
z.union([z.union([z.number(), z.null()]), z.null()])
|
|
970
|
+
),
|
|
971
|
+
maxGasBurnt: z.number(),
|
|
972
|
+
maxLengthMethodName: z.number(),
|
|
973
|
+
maxLengthReturnedData: z.number(),
|
|
974
|
+
maxLengthStorageKey: z.number(),
|
|
975
|
+
maxLengthStorageValue: z.number(),
|
|
976
|
+
maxLocalsPerContract: z.optional(
|
|
977
|
+
z.union([z.union([z.number(), z.null()]), z.null()])
|
|
978
|
+
),
|
|
979
|
+
maxMemoryPages: z.number(),
|
|
980
|
+
maxNumberBytesMethodNames: z.number(),
|
|
981
|
+
maxNumberInputDataDependencies: z.number(),
|
|
982
|
+
maxNumberLogs: z.number(),
|
|
983
|
+
maxNumberRegisters: z.number(),
|
|
984
|
+
maxPromisesPerFunctionCallAction: z.number(),
|
|
985
|
+
maxReceiptSize: z.number(),
|
|
986
|
+
maxRegisterSize: z.number(),
|
|
987
|
+
maxStackHeight: z.number(),
|
|
988
|
+
maxTablesPerContract: z.optional(
|
|
989
|
+
z.union([z.union([z.number(), z.null()]), z.null()])
|
|
990
|
+
),
|
|
991
|
+
maxTotalLogLength: z.number(),
|
|
992
|
+
maxTotalPrepaidGas: z.number(),
|
|
993
|
+
maxTransactionSize: z.number(),
|
|
994
|
+
maxYieldPayloadSize: z.number(),
|
|
995
|
+
perReceiptStorageProofSizeLimit: z.number(),
|
|
996
|
+
registersMemoryLimit: z.number(),
|
|
997
|
+
yieldTimeoutLengthInBlocks: z.number()
|
|
998
|
+
});
|
|
999
|
+
var MerklePathItemSchema = () => z.object({
|
|
1000
|
+
direction: z.lazy(() => DirectionSchema()),
|
|
1001
|
+
hash: z.lazy(() => CryptoHashSchema())
|
|
1002
|
+
});
|
|
1003
|
+
var MethodResolveErrorSchema = () => z.enum(["MethodEmptyName", "MethodNotFound", "MethodInvalidSignature"]);
|
|
1004
|
+
var MissingTrieValueSchema = () => z.object({
|
|
1005
|
+
context: z.lazy(() => MissingTrieValueContextSchema()),
|
|
1006
|
+
hash: z.lazy(() => CryptoHashSchema())
|
|
1007
|
+
});
|
|
1008
|
+
var MissingTrieValueContextSchema = () => z.union([
|
|
1009
|
+
z.enum(["TrieIterator"]),
|
|
1010
|
+
z.enum(["TriePrefetchingStorage"]),
|
|
1011
|
+
z.enum(["TrieMemoryPartialStorage"]),
|
|
1012
|
+
z.enum(["TrieStorage"])
|
|
1013
|
+
]);
|
|
1014
|
+
var NonDelegateActionSchema = () => z.union([
|
|
1015
|
+
z.object({
|
|
1016
|
+
CreateAccount: z.lazy(() => CreateAccountActionSchema())
|
|
1017
|
+
}),
|
|
1018
|
+
z.object({
|
|
1019
|
+
DeployContract: z.lazy(() => DeployContractActionSchema())
|
|
1020
|
+
}),
|
|
1021
|
+
z.object({
|
|
1022
|
+
FunctionCall: z.lazy(() => FunctionCallActionSchema())
|
|
1023
|
+
}),
|
|
1024
|
+
z.object({
|
|
1025
|
+
Transfer: z.lazy(() => TransferActionSchema())
|
|
1026
|
+
}),
|
|
1027
|
+
z.object({
|
|
1028
|
+
Stake: z.lazy(() => StakeActionSchema())
|
|
1029
|
+
}),
|
|
1030
|
+
z.object({
|
|
1031
|
+
AddKey: z.lazy(() => AddKeyActionSchema())
|
|
1032
|
+
}),
|
|
1033
|
+
z.object({
|
|
1034
|
+
DeleteKey: z.lazy(() => DeleteKeyActionSchema())
|
|
1035
|
+
}),
|
|
1036
|
+
z.object({
|
|
1037
|
+
DeleteAccount: z.lazy(() => DeleteAccountActionSchema())
|
|
1038
|
+
}),
|
|
1039
|
+
z.object({
|
|
1040
|
+
DeployGlobalContract: z.lazy(() => DeployGlobalContractActionSchema())
|
|
1041
|
+
}),
|
|
1042
|
+
z.object({
|
|
1043
|
+
UseGlobalContract: z.lazy(() => UseGlobalContractActionSchema())
|
|
1044
|
+
})
|
|
1045
|
+
]);
|
|
1046
|
+
var PrepareErrorSchema = () => z.union([
|
|
1047
|
+
z.enum(["Serialization"]),
|
|
1048
|
+
z.enum(["Deserialization"]),
|
|
1049
|
+
z.enum(["InternalMemoryDeclared"]),
|
|
1050
|
+
z.enum(["GasInstrumentation"]),
|
|
1051
|
+
z.enum(["StackHeightInstrumentation"]),
|
|
1052
|
+
z.enum(["Instantiate"]),
|
|
1053
|
+
z.enum(["Memory"]),
|
|
1054
|
+
z.enum(["TooManyFunctions"]),
|
|
1055
|
+
z.enum(["TooManyLocals"]),
|
|
1056
|
+
z.enum(["TooManyTables"]),
|
|
1057
|
+
z.enum(["TooManyTableElements"])
|
|
1058
|
+
]);
|
|
1059
|
+
var PublicKeySchema = () => z.string();
|
|
1060
|
+
var ReceiptEnumViewSchema = () => z.union([
|
|
1061
|
+
z.object({
|
|
1062
|
+
Action: z.object({
|
|
1063
|
+
actions: z.array(z.lazy(() => ActionViewSchema())),
|
|
1064
|
+
gasPrice: z.string(),
|
|
1065
|
+
inputDataIds: z.array(z.lazy(() => CryptoHashSchema())),
|
|
1066
|
+
isPromiseYield: z.optional(z.boolean()),
|
|
1067
|
+
outputDataReceivers: z.array(z.lazy(() => DataReceiverViewSchema())),
|
|
1068
|
+
signerId: z.lazy(() => AccountIdSchema()),
|
|
1069
|
+
signerPublicKey: z.lazy(() => PublicKeySchema())
|
|
1070
|
+
})
|
|
1071
|
+
}),
|
|
1072
|
+
z.object({
|
|
1073
|
+
Data: z.object({
|
|
1074
|
+
data: z.optional(z.union([z.union([z.string(), z.null()]), z.null()])),
|
|
1075
|
+
dataId: z.lazy(() => CryptoHashSchema()),
|
|
1076
|
+
isPromiseResume: z.optional(z.boolean())
|
|
1077
|
+
})
|
|
1078
|
+
}),
|
|
1079
|
+
z.object({
|
|
1080
|
+
GlobalContractDistribution: z.object({
|
|
1081
|
+
alreadyDeliveredShards: z.array(z.lazy(() => ShardIdSchema())),
|
|
1082
|
+
code: z.string(),
|
|
1083
|
+
id: z.lazy(() => GlobalContractIdentifierSchema()),
|
|
1084
|
+
targetShard: z.lazy(() => ShardIdSchema())
|
|
1085
|
+
})
|
|
1086
|
+
})
|
|
1087
|
+
]);
|
|
1088
|
+
var ReceiptValidationErrorSchema = () => z.union([
|
|
1089
|
+
z.object({
|
|
1090
|
+
InvalidPredecessorId: z.object({
|
|
1091
|
+
accountId: z.string()
|
|
1092
|
+
})
|
|
1093
|
+
}),
|
|
1094
|
+
z.object({
|
|
1095
|
+
InvalidReceiverId: z.object({
|
|
1096
|
+
accountId: z.string()
|
|
1097
|
+
})
|
|
1098
|
+
}),
|
|
1099
|
+
z.object({
|
|
1100
|
+
InvalidSignerId: z.object({
|
|
1101
|
+
accountId: z.string()
|
|
1102
|
+
})
|
|
1103
|
+
}),
|
|
1104
|
+
z.object({
|
|
1105
|
+
InvalidDataReceiverId: z.object({
|
|
1106
|
+
accountId: z.string()
|
|
1107
|
+
})
|
|
1108
|
+
}),
|
|
1109
|
+
z.object({
|
|
1110
|
+
ReturnedValueLengthExceeded: z.object({
|
|
1111
|
+
length: z.number(),
|
|
1112
|
+
limit: z.number()
|
|
1113
|
+
})
|
|
1114
|
+
}),
|
|
1115
|
+
z.object({
|
|
1116
|
+
NumberInputDataDependenciesExceeded: z.object({
|
|
1117
|
+
limit: z.number(),
|
|
1118
|
+
numberOfInputDataDependencies: z.number()
|
|
1119
|
+
})
|
|
1120
|
+
}),
|
|
1121
|
+
z.object({
|
|
1122
|
+
ActionsValidation: z.lazy(() => ActionsValidationErrorSchema())
|
|
1123
|
+
}),
|
|
1124
|
+
z.object({
|
|
1125
|
+
ReceiptSizeExceeded: z.object({
|
|
1126
|
+
limit: z.number(),
|
|
1127
|
+
size: z.number()
|
|
1128
|
+
})
|
|
1129
|
+
})
|
|
1130
|
+
]);
|
|
1131
|
+
var ReceiptViewSchema = () => z.object({
|
|
1132
|
+
predecessorId: z.lazy(() => AccountIdSchema()),
|
|
1133
|
+
priority: z.optional(z.number()),
|
|
1134
|
+
receipt: z.lazy(() => ReceiptEnumViewSchema()),
|
|
1135
|
+
receiptId: z.lazy(() => CryptoHashSchema()),
|
|
1136
|
+
receiverId: z.lazy(() => AccountIdSchema())
|
|
1137
|
+
});
|
|
1138
|
+
var RpcBlockResponseSchema = () => z.object({
|
|
1139
|
+
author: z.lazy(() => AccountIdSchema()),
|
|
1140
|
+
chunks: z.array(z.lazy(() => ChunkHeaderViewSchema())),
|
|
1141
|
+
header: z.lazy(() => BlockHeaderViewSchema())
|
|
1142
|
+
});
|
|
1143
|
+
var RpcGasPriceResponseSchema = () => z.object({
|
|
1144
|
+
gasPrice: z.string()
|
|
1145
|
+
});
|
|
1146
|
+
var RpcProtocolConfigResponseSchema = () => z.object({
|
|
1147
|
+
avgHiddenValidatorSeatsPerShard: z.array(z.number()),
|
|
1148
|
+
blockProducerKickoutThreshold: z.number(),
|
|
1149
|
+
chainId: z.string(),
|
|
1150
|
+
chunkProducerKickoutThreshold: z.number(),
|
|
1151
|
+
chunkValidatorOnlyKickoutThreshold: z.number(),
|
|
1152
|
+
dynamicResharding: z.boolean(),
|
|
1153
|
+
epochLength: z.number(),
|
|
1154
|
+
fishermenThreshold: z.string(),
|
|
1155
|
+
gasLimit: z.number(),
|
|
1156
|
+
gasPriceAdjustmentRate: z.array(z.number()),
|
|
1157
|
+
genesisHeight: z.number(),
|
|
1158
|
+
genesisTime: z.string(),
|
|
1159
|
+
maxGasPrice: z.string(),
|
|
1160
|
+
maxInflationRate: z.array(z.number()),
|
|
1161
|
+
maxKickoutStakePerc: z.number(),
|
|
1162
|
+
minGasPrice: z.string(),
|
|
1163
|
+
minimumStakeDivisor: z.number(),
|
|
1164
|
+
minimumStakeRatio: z.array(z.number()),
|
|
1165
|
+
minimumValidatorsPerShard: z.number(),
|
|
1166
|
+
numBlockProducerSeats: z.number(),
|
|
1167
|
+
numBlockProducerSeatsPerShard: z.array(z.number()),
|
|
1168
|
+
numBlocksPerYear: z.number(),
|
|
1169
|
+
onlineMaxThreshold: z.array(z.number()),
|
|
1170
|
+
onlineMinThreshold: z.array(z.number()),
|
|
1171
|
+
protocolRewardRate: z.array(z.number()),
|
|
1172
|
+
protocolTreasuryAccount: z.lazy(() => AccountIdSchema()),
|
|
1173
|
+
protocolUpgradeStakeThreshold: z.array(z.number()),
|
|
1174
|
+
protocolVersion: z.number(),
|
|
1175
|
+
runtimeConfig: z.lazy(() => RuntimeConfigViewSchema()),
|
|
1176
|
+
shardLayout: z.lazy(() => ShardLayoutSchema()),
|
|
1177
|
+
shuffleShardAssignmentForChunkProducers: z.boolean(),
|
|
1178
|
+
targetValidatorMandatesPerShard: z.number(),
|
|
1179
|
+
transactionValidityPeriod: z.number()
|
|
1180
|
+
});
|
|
1181
|
+
var RpcTransactionResponseSchema = () => z.intersection(
|
|
1182
|
+
z.union([
|
|
1183
|
+
z.lazy(() => FinalExecutionOutcomeWithReceiptViewSchema()),
|
|
1184
|
+
z.lazy(() => FinalExecutionOutcomeViewSchema())
|
|
1185
|
+
]),
|
|
1186
|
+
z.object({
|
|
1187
|
+
finalExecutionStatus: z.lazy(() => TxExecutionStatusSchema())
|
|
1188
|
+
})
|
|
1189
|
+
);
|
|
1190
|
+
var RuntimeConfigViewSchema = () => z.object({
|
|
1191
|
+
accountCreationConfig: z.lazy(() => AccountCreationConfigViewSchema()),
|
|
1192
|
+
congestionControlConfig: z.lazy(() => CongestionControlConfigViewSchema()),
|
|
1193
|
+
storageAmountPerByte: z.string(),
|
|
1194
|
+
transactionCosts: z.lazy(() => RuntimeFeesConfigViewSchema()),
|
|
1195
|
+
wasmConfig: z.lazy(() => VMConfigViewSchema()),
|
|
1196
|
+
witnessConfig: z.lazy(() => WitnessConfigViewSchema())
|
|
1197
|
+
});
|
|
1198
|
+
var RuntimeFeesConfigViewSchema = () => z.object({
|
|
1199
|
+
actionCreationConfig: z.lazy(() => ActionCreationConfigViewSchema()),
|
|
1200
|
+
actionReceiptCreationConfig: z.lazy(() => FeeSchema()),
|
|
1201
|
+
burntGasReward: z.array(z.number()),
|
|
1202
|
+
dataReceiptCreationConfig: z.lazy(
|
|
1203
|
+
() => DataReceiptCreationConfigViewSchema()
|
|
1204
|
+
),
|
|
1205
|
+
pessimisticGasPriceInflationRatio: z.array(z.number()),
|
|
1206
|
+
storageUsageConfig: z.lazy(() => StorageUsageConfigViewSchema())
|
|
1207
|
+
});
|
|
1208
|
+
var ShardIdSchema = () => z.number();
|
|
1209
|
+
var ShardLayoutSchema = () => z.union([
|
|
1210
|
+
z.object({
|
|
1211
|
+
V0: z.lazy(() => ShardLayoutV0Schema())
|
|
1212
|
+
}),
|
|
1213
|
+
z.object({
|
|
1214
|
+
V1: z.lazy(() => ShardLayoutV1Schema())
|
|
1215
|
+
}),
|
|
1216
|
+
z.object({
|
|
1217
|
+
V2: z.lazy(() => ShardLayoutV2Schema())
|
|
1218
|
+
})
|
|
1219
|
+
]);
|
|
1220
|
+
var ShardLayoutV0Schema = () => z.object({
|
|
1221
|
+
numShards: z.number(),
|
|
1222
|
+
version: z.number()
|
|
1223
|
+
});
|
|
1224
|
+
var ShardLayoutV1Schema = () => z.object({
|
|
1225
|
+
boundaryAccounts: z.array(z.lazy(() => AccountIdSchema())),
|
|
1226
|
+
shardsSplitMap: z.optional(
|
|
1227
|
+
z.union([
|
|
1228
|
+
z.union([z.array(z.array(z.lazy(() => ShardIdSchema()))), z.null()]),
|
|
1229
|
+
z.null()
|
|
1230
|
+
])
|
|
1231
|
+
),
|
|
1232
|
+
toParentShardMap: z.optional(
|
|
1233
|
+
z.union([
|
|
1234
|
+
z.union([z.array(z.lazy(() => ShardIdSchema())), z.null()]),
|
|
1235
|
+
z.null()
|
|
1236
|
+
])
|
|
1237
|
+
),
|
|
1238
|
+
version: z.number()
|
|
1239
|
+
});
|
|
1240
|
+
var ShardLayoutV2Schema = () => z.object({
|
|
1241
|
+
boundaryAccounts: z.array(z.lazy(() => AccountIdSchema())),
|
|
1242
|
+
idToIndexMap: z.record(z.string(), z.number()),
|
|
1243
|
+
indexToIdMap: z.record(
|
|
1244
|
+
z.string(),
|
|
1245
|
+
z.lazy(() => ShardIdSchema())
|
|
1246
|
+
),
|
|
1247
|
+
shardIds: z.array(z.lazy(() => ShardIdSchema())),
|
|
1248
|
+
shardsParentMap: z.optional(
|
|
1249
|
+
z.union([
|
|
1250
|
+
z.union([
|
|
1251
|
+
z.record(
|
|
1252
|
+
z.string(),
|
|
1253
|
+
z.lazy(() => ShardIdSchema())
|
|
1254
|
+
),
|
|
1255
|
+
z.null()
|
|
1256
|
+
]),
|
|
1257
|
+
z.null()
|
|
1258
|
+
])
|
|
1259
|
+
),
|
|
1260
|
+
shardsSplitMap: z.optional(
|
|
1261
|
+
z.union([
|
|
1262
|
+
z.union([
|
|
1263
|
+
z.record(z.string(), z.array(z.lazy(() => ShardIdSchema()))),
|
|
1264
|
+
z.null()
|
|
1265
|
+
]),
|
|
1266
|
+
z.null()
|
|
1267
|
+
])
|
|
1268
|
+
),
|
|
1269
|
+
version: z.number()
|
|
1270
|
+
});
|
|
1271
|
+
var SignatureSchema = () => z.string();
|
|
1272
|
+
var SignedTransactionViewSchema = () => z.object({
|
|
1273
|
+
actions: z.array(z.lazy(() => ActionViewSchema())),
|
|
1274
|
+
hash: z.lazy(() => CryptoHashSchema()),
|
|
1275
|
+
nonce: z.number(),
|
|
1276
|
+
priorityFee: z.optional(z.number()),
|
|
1277
|
+
publicKey: z.lazy(() => PublicKeySchema()),
|
|
1278
|
+
receiverId: z.lazy(() => AccountIdSchema()),
|
|
1279
|
+
signature: z.lazy(() => SignatureSchema()),
|
|
1280
|
+
signerId: z.lazy(() => AccountIdSchema())
|
|
1281
|
+
});
|
|
1282
|
+
var SlashedValidatorSchema = () => z.object({
|
|
1283
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
1284
|
+
isDoubleSign: z.boolean()
|
|
1285
|
+
});
|
|
1286
|
+
var StakeActionSchema = () => z.object({
|
|
1287
|
+
publicKey: z.lazy(() => PublicKeySchema()),
|
|
1288
|
+
stake: z.string()
|
|
1289
|
+
});
|
|
1290
|
+
var StateItemSchema = () => z.object({
|
|
1291
|
+
key: z.lazy(() => StoreKeySchema()),
|
|
1292
|
+
value: z.lazy(() => StoreValueSchema())
|
|
1293
|
+
});
|
|
1294
|
+
var StorageErrorSchema = () => z.union([
|
|
1295
|
+
z.enum(["StorageInternalError"]),
|
|
1296
|
+
z.object({
|
|
1297
|
+
MissingTrieValue: z.lazy(() => MissingTrieValueSchema())
|
|
1298
|
+
}),
|
|
1299
|
+
z.enum(["UnexpectedTrieValue"]),
|
|
1300
|
+
z.object({
|
|
1301
|
+
StorageInconsistentState: z.string()
|
|
1302
|
+
}),
|
|
1303
|
+
z.object({
|
|
1304
|
+
FlatStorageBlockNotSupported: z.string()
|
|
1305
|
+
}),
|
|
1306
|
+
z.object({
|
|
1307
|
+
MemTrieLoadingError: z.string()
|
|
1308
|
+
})
|
|
1309
|
+
]);
|
|
1310
|
+
var StorageGetModeSchema = () => z.enum(["FlatStorage", "Trie"]);
|
|
1311
|
+
var StorageUsageConfigViewSchema = () => z.object({
|
|
1312
|
+
numBytesAccount: z.number(),
|
|
1313
|
+
numExtraBytesRecord: z.number()
|
|
1314
|
+
});
|
|
1315
|
+
var StoreKeySchema = () => z.string();
|
|
1316
|
+
var StoreValueSchema = () => z.string();
|
|
1317
|
+
var TransferActionSchema = () => z.object({
|
|
1318
|
+
deposit: z.string()
|
|
1319
|
+
});
|
|
1320
|
+
var TxExecutionErrorSchema = () => z.union([
|
|
1321
|
+
z.object({
|
|
1322
|
+
ActionError: z.lazy(() => ActionErrorSchema())
|
|
1323
|
+
}),
|
|
1324
|
+
z.object({
|
|
1325
|
+
InvalidTxError: z.lazy(() => InvalidTxErrorSchema())
|
|
1326
|
+
})
|
|
1327
|
+
]);
|
|
1328
|
+
var TxExecutionStatusSchema = () => z.union([
|
|
1329
|
+
z.enum(["NONE"]),
|
|
1330
|
+
z.enum(["INCLUDED"]),
|
|
1331
|
+
z.enum(["EXECUTED_OPTIMISTIC"]),
|
|
1332
|
+
z.enum(["INCLUDED_FINAL"]),
|
|
1333
|
+
z.enum(["EXECUTED"]),
|
|
1334
|
+
z.enum(["FINAL"])
|
|
1335
|
+
]);
|
|
1336
|
+
var UseGlobalContractActionSchema = () => z.object({
|
|
1337
|
+
contractIdentifier: z.lazy(() => GlobalContractIdentifierSchema())
|
|
1338
|
+
});
|
|
1339
|
+
var VMConfigViewSchema = () => z.object({
|
|
1340
|
+
discardCustomSections: z.boolean(),
|
|
1341
|
+
ethImplicitAccounts: z.boolean(),
|
|
1342
|
+
extCosts: z.lazy(() => ExtCostsConfigViewSchema()),
|
|
1343
|
+
fixContractLoadingCost: z.boolean(),
|
|
1344
|
+
globalContractHostFns: z.boolean(),
|
|
1345
|
+
growMemCost: z.number(),
|
|
1346
|
+
implicitAccountCreation: z.boolean(),
|
|
1347
|
+
limitConfig: z.lazy(() => LimitConfigSchema()),
|
|
1348
|
+
reftypesBulkMemory: z.boolean(),
|
|
1349
|
+
regularOpCost: z.number(),
|
|
1350
|
+
saturatingFloatToInt: z.boolean(),
|
|
1351
|
+
storageGetMode: z.lazy(() => StorageGetModeSchema()),
|
|
1352
|
+
vmKind: z.lazy(() => VMKindSchema())
|
|
1353
|
+
});
|
|
1354
|
+
var VMKindSchema = () => z.union([
|
|
1355
|
+
z.enum(["Wasmer0"]),
|
|
1356
|
+
z.enum(["Wasmtime"]),
|
|
1357
|
+
z.enum(["Wasmer2"]),
|
|
1358
|
+
z.enum(["NearVm"]),
|
|
1359
|
+
z.enum(["NearVm2"])
|
|
1360
|
+
]);
|
|
1361
|
+
var ValidatorStakeViewSchema = () => z.lazy(() => ValidatorStakeViewV1Schema());
|
|
1362
|
+
var ValidatorStakeViewV1Schema = () => z.object({
|
|
1363
|
+
accountId: z.lazy(() => AccountIdSchema()),
|
|
1364
|
+
publicKey: z.lazy(() => PublicKeySchema()),
|
|
1365
|
+
stake: z.string()
|
|
1366
|
+
});
|
|
1367
|
+
var ViewStateResultSchema = () => z.object({
|
|
1368
|
+
proof: z.optional(z.array(z.string())),
|
|
1369
|
+
values: z.array(z.lazy(() => StateItemSchema()))
|
|
1370
|
+
});
|
|
1371
|
+
var WasmTrapSchema = () => z.union([
|
|
1372
|
+
z.enum(["Unreachable"]),
|
|
1373
|
+
z.enum(["IncorrectCallIndirectSignature"]),
|
|
1374
|
+
z.enum(["MemoryOutOfBounds"]),
|
|
1375
|
+
z.enum(["CallIndirectOOB"]),
|
|
1376
|
+
z.enum(["IllegalArithmetic"]),
|
|
1377
|
+
z.enum(["MisalignedAtomicAccess"]),
|
|
1378
|
+
z.enum(["IndirectCallToNull"]),
|
|
1379
|
+
z.enum(["StackOverflow"]),
|
|
1380
|
+
z.enum(["GenericTrap"])
|
|
1381
|
+
]);
|
|
1382
|
+
var WitnessConfigViewSchema = () => z.object({
|
|
1383
|
+
combinedTransactionsSizeLimit: z.number(),
|
|
1384
|
+
mainStorageProofSizeSoftLimit: z.number(),
|
|
1385
|
+
newTransactionsValidationStateSizeSoftLimit: z.number()
|
|
1386
|
+
});
|
|
1387
|
+
var PATH_TO_METHOD_MAP = {
|
|
1388
|
+
"/EXPERIMENTAL_changes": "EXPERIMENTAL_changes",
|
|
1389
|
+
"/EXPERIMENTAL_changes_in_block": "EXPERIMENTAL_changes_in_block",
|
|
1390
|
+
"/EXPERIMENTAL_congestion_level": "EXPERIMENTAL_congestion_level",
|
|
1391
|
+
"/EXPERIMENTAL_genesis_config": "EXPERIMENTAL_genesis_config",
|
|
1392
|
+
"/EXPERIMENTAL_light_client_block_proof": "EXPERIMENTAL_light_client_block_proof",
|
|
1393
|
+
"/EXPERIMENTAL_light_client_proof": "EXPERIMENTAL_light_client_proof",
|
|
1394
|
+
"/EXPERIMENTAL_maintenance_windows": "EXPERIMENTAL_maintenance_windows",
|
|
1395
|
+
"/EXPERIMENTAL_protocol_config": "EXPERIMENTAL_protocol_config",
|
|
1396
|
+
"/EXPERIMENTAL_receipt": "EXPERIMENTAL_receipt",
|
|
1397
|
+
"/EXPERIMENTAL_split_storage_info": "EXPERIMENTAL_split_storage_info",
|
|
1398
|
+
"/EXPERIMENTAL_tx_status": "EXPERIMENTAL_tx_status",
|
|
1399
|
+
"/EXPERIMENTAL_validators_ordered": "EXPERIMENTAL_validators_ordered",
|
|
1400
|
+
"/block": "block",
|
|
1401
|
+
"/block_effects": "block_effects",
|
|
1402
|
+
"/broadcast_tx_async": "broadcast_tx_async",
|
|
1403
|
+
"/broadcast_tx_commit": "broadcast_tx_commit",
|
|
1404
|
+
"/changes": "changes",
|
|
1405
|
+
"/chunk": "chunk",
|
|
1406
|
+
"/client_config": "client_config",
|
|
1407
|
+
"/gas_price": "gas_price",
|
|
1408
|
+
"/genesis_config": "genesis_config",
|
|
1409
|
+
"/health": "health",
|
|
1410
|
+
"/light_client_proof": "light_client_proof",
|
|
1411
|
+
"/maintenance_windows": "maintenance_windows",
|
|
1412
|
+
"/network_info": "network_info",
|
|
1413
|
+
"/next_light_client_block": "next_light_client_block",
|
|
1414
|
+
"/query": "query",
|
|
1415
|
+
"/send_tx": "send_tx",
|
|
1416
|
+
"/status": "status",
|
|
1417
|
+
"/tx": "tx",
|
|
1418
|
+
"/validators": "validators"
|
|
1419
|
+
};
|
|
1420
|
+
var METHOD_TO_PATH_MAP = {};
|
|
1421
|
+
Object.entries(PATH_TO_METHOD_MAP).forEach(([path, method]) => {
|
|
1422
|
+
METHOD_TO_PATH_MAP[method] = path;
|
|
1423
|
+
});
|
|
1424
|
+
var RPC_METHODS = Object.values(PATH_TO_METHOD_MAP);
|
|
1425
|
+
|
|
1426
|
+
// src/_common/utils/snakeToCamelCase.ts
|
|
1427
|
+
var snakeToCamelCase = (obj) => {
|
|
1428
|
+
if (obj === null || typeof obj !== "object") {
|
|
1429
|
+
return obj;
|
|
1430
|
+
}
|
|
1431
|
+
if (Array.isArray(obj)) {
|
|
1432
|
+
return obj.map((item) => snakeToCamelCase(item));
|
|
1433
|
+
}
|
|
1434
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
1435
|
+
const value = obj[key];
|
|
1436
|
+
const camelKey = key.replace(
|
|
1437
|
+
/(_\w)/g,
|
|
1438
|
+
(match) => match.charAt(1).toUpperCase()
|
|
1439
|
+
);
|
|
1440
|
+
if (value !== null && typeof value === "object") {
|
|
1441
|
+
acc[camelKey] = snakeToCamelCase(value);
|
|
1442
|
+
} else {
|
|
1443
|
+
acc[camelKey] = value;
|
|
1444
|
+
}
|
|
1445
|
+
return acc;
|
|
1446
|
+
}, {});
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
// src/_common/utils/tokenConverter/helpers.ts
|
|
1450
|
+
var POW10_CACHE = {};
|
|
1451
|
+
var pow10 = (decimals) => {
|
|
1452
|
+
const cached = POW10_CACHE[decimals];
|
|
1453
|
+
if (cached !== void 0) return cached;
|
|
1454
|
+
const value = 10n ** BigInt(decimals);
|
|
1455
|
+
POW10_CACHE[decimals] = value;
|
|
1456
|
+
return value;
|
|
1457
|
+
};
|
|
1458
|
+
var assertValidDecimals = (decimals) => {
|
|
1459
|
+
if (!Number.isInteger(decimals) || decimals < 1 || decimals > 100) {
|
|
1460
|
+
throw new Error("Decimals must be an integer in the range 1..100");
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1464
|
+
// src/_common/utils/tokenConverter/convertTokensToUnits.ts
|
|
1465
|
+
var assertValidTokens = (tokens, decimals) => {
|
|
1466
|
+
const decimalPattern = new RegExp(`^\\d+(?:\\.\\d{1,${decimals}})?$`);
|
|
1467
|
+
if (!decimalPattern.test(tokens)) {
|
|
1468
|
+
throw new Error(
|
|
1469
|
+
`Tokens must be a positive decimal with up to ${decimals} fractional digits`
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
var convertTokensToUnits = (tokens, decimals) => {
|
|
1474
|
+
assertValidDecimals(decimals);
|
|
1475
|
+
assertValidTokens(tokens, decimals);
|
|
1476
|
+
const [integerPartRaw, fractionalPartRaw = ""] = tokens.split(".");
|
|
1477
|
+
const scale = pow10(decimals);
|
|
1478
|
+
const integerUnits = BigInt(integerPartRaw) * scale;
|
|
1479
|
+
const fractionalUnits = fractionalPartRaw.length ? BigInt(fractionalPartRaw.padEnd(decimals, "0")) : 0n;
|
|
1480
|
+
return integerUnits + fractionalUnits;
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
// src/_common/utils/tokenConverter/convertUnitsToTokens.ts
|
|
1484
|
+
var assertValidUnits = (units) => {
|
|
1485
|
+
if (typeof units === "string" && !/^\d+$/.test(units)) {
|
|
1486
|
+
throw new Error("Units must be a positive integer string (digits only)");
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
var convertUnitsToTokens = (units, decimals) => {
|
|
1490
|
+
assertValidDecimals(decimals);
|
|
1491
|
+
assertValidUnits(units);
|
|
1492
|
+
const unitsBigInt = BigInt(units);
|
|
1493
|
+
const scale = pow10(decimals);
|
|
1494
|
+
const wholePart = unitsBigInt / scale;
|
|
1495
|
+
const fractionalRemainder = unitsBigInt % scale;
|
|
1496
|
+
if (fractionalRemainder === 0n) return wholePart.toString();
|
|
1497
|
+
const fractionalDigits = fractionalRemainder.toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
1498
|
+
if (fractionalDigits.length === 0) return wholePart.toString();
|
|
1499
|
+
return `${wholePart.toString()}.${fractionalDigits}`;
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1502
|
+
// src/_common/configs/constants.ts
|
|
1503
|
+
var BinaryCryptoKeyLengths = {
|
|
1504
|
+
Ed25519: {
|
|
1505
|
+
// SecretKey + PublicKey
|
|
1506
|
+
PrivateKey: 64,
|
|
1507
|
+
SecretKey: 32,
|
|
1508
|
+
PublicKey: 32
|
|
1509
|
+
},
|
|
1510
|
+
Secp256k1: {
|
|
1511
|
+
// SecretKey + PublicKey
|
|
1512
|
+
PrivateKey: 96,
|
|
1513
|
+
SecretKey: 32,
|
|
1514
|
+
PublicKey: 64
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
var NearDecimals = 24;
|
|
1518
|
+
var RefetchBlockHashInterval = 6e5;
|
|
1519
|
+
var SignerTaskTtlMs = 6e4;
|
|
1520
|
+
|
|
1521
|
+
// src/_common/utils/common.ts
|
|
1522
|
+
var oneLine = (msg) => msg.replace(/\s+/g, " ").trim();
|
|
1523
|
+
var isNodeJs = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
1524
|
+
var nodeInspectSymbol = isNodeJs ? Symbol.for("nodejs.util.inspect.custom") : void 0;
|
|
1525
|
+
var toJsonBytes = (value) => new TextEncoder().encode(JSON.stringify(value));
|
|
1526
|
+
var fromJsonBytes = (bytes) => {
|
|
1527
|
+
const u8 = Array.isArray(bytes) ? new Uint8Array(bytes) : bytes;
|
|
1528
|
+
return JSON.parse(new TextDecoder().decode(u8));
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
// src/helpers/near.ts
|
|
1532
|
+
var cache = {
|
|
1533
|
+
near: /* @__PURE__ */ new WeakMap(),
|
|
1534
|
+
yoctoNear: /* @__PURE__ */ new WeakMap()
|
|
1535
|
+
};
|
|
1536
|
+
var nearTokenProto = {
|
|
1537
|
+
// Lazy getter - calculate the 'near' value only after the first direct access;
|
|
1538
|
+
// save the result in the cache
|
|
1539
|
+
get near() {
|
|
1540
|
+
const maybeValue = cache.near.get(this);
|
|
1541
|
+
if (maybeValue) return maybeValue;
|
|
1542
|
+
const value = convertUnitsToTokens(this.yoctoNear, NearDecimals);
|
|
1543
|
+
cache.near.set(this, value);
|
|
1544
|
+
return value;
|
|
1545
|
+
},
|
|
1546
|
+
get yoctoNear() {
|
|
1547
|
+
const maybeValue = cache.yoctoNear.get(this);
|
|
1548
|
+
if (maybeValue) return maybeValue;
|
|
1549
|
+
const value = convertTokensToUnits(this.near, NearDecimals);
|
|
1550
|
+
cache.yoctoNear.set(this, value);
|
|
1551
|
+
return value;
|
|
1552
|
+
},
|
|
1553
|
+
// TODO add support for NearToken and avoid creating a new instance if x is NearToken
|
|
1554
|
+
add(x) {
|
|
1555
|
+
return yoctoNear(this.yoctoNear + fromNearOption(x).yoctoNear);
|
|
1556
|
+
},
|
|
1557
|
+
sub(x) {
|
|
1558
|
+
return yoctoNear(this.yoctoNear - fromNearOption(x).yoctoNear);
|
|
1559
|
+
},
|
|
1560
|
+
mul(x) {
|
|
1561
|
+
return yoctoNear(this.yoctoNear * fromNearOption(x).yoctoNear);
|
|
1562
|
+
},
|
|
1563
|
+
gt(x) {
|
|
1564
|
+
return this.yoctoNear > fromNearOption(x).yoctoNear;
|
|
1565
|
+
},
|
|
1566
|
+
lt(x) {
|
|
1567
|
+
return this.yoctoNear < fromNearOption(x).yoctoNear;
|
|
1568
|
+
},
|
|
1569
|
+
toString() {
|
|
1570
|
+
return JSON.stringify({
|
|
1571
|
+
near: this.near,
|
|
1572
|
+
yoctoNear: this.yoctoNear.toString()
|
|
1573
|
+
});
|
|
1574
|
+
},
|
|
1575
|
+
// In Node.js, this allows you to see the near/yoctoNear getter values,
|
|
1576
|
+
// which are not normally visible unless you access them directly.
|
|
1577
|
+
// This does not work in the browser — there you can only see a getter’s value
|
|
1578
|
+
// by explicitly expanding/clicking on it.
|
|
1579
|
+
...nodeInspectSymbol && {
|
|
1580
|
+
[nodeInspectSymbol](_depth, _opts) {
|
|
1581
|
+
return { near: this.near, yoctoNear: this.yoctoNear };
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
var yoctoNear = (units) => {
|
|
1586
|
+
const yoctoNear2 = BigInt(units);
|
|
1587
|
+
const obj = Object.create(nearTokenProto);
|
|
1588
|
+
Object.defineProperty(obj, "yoctoNear", {
|
|
1589
|
+
value: yoctoNear2,
|
|
1590
|
+
enumerable: true
|
|
1591
|
+
});
|
|
1592
|
+
return Object.freeze(obj);
|
|
1593
|
+
};
|
|
1594
|
+
var near = (tokens) => {
|
|
1595
|
+
const obj = Object.create(nearTokenProto);
|
|
1596
|
+
Object.defineProperty(obj, "near", {
|
|
1597
|
+
value: tokens,
|
|
1598
|
+
enumerable: true
|
|
1599
|
+
});
|
|
1600
|
+
return Object.freeze(obj);
|
|
1601
|
+
};
|
|
1602
|
+
var fromNearOption = (nearOption) => {
|
|
1603
|
+
if ("yoctoNear" in nearOption) return yoctoNear(nearOption.yoctoNear);
|
|
1604
|
+
if ("near" in nearOption) return near(nearOption.near);
|
|
1605
|
+
throw new Error("Invalid nearOption format");
|
|
1606
|
+
};
|
|
1607
|
+
|
|
1608
|
+
// src/client/createClient/account/getAccountState.ts
|
|
1609
|
+
var RpcQueryAccountViewResponseSchema = z2.object({
|
|
1610
|
+
...AccountViewSchema().shape,
|
|
1611
|
+
blockHash: CryptoHashSchema(),
|
|
1612
|
+
blockHeight: z2.number()
|
|
1613
|
+
});
|
|
1614
|
+
var transformResult = (result, args) => {
|
|
1615
|
+
const camelCased = snakeToCamelCase(result);
|
|
1616
|
+
const valid = RpcQueryAccountViewResponseSchema.parse(camelCased);
|
|
1617
|
+
const lockedBalance = yoctoNear(valid.locked);
|
|
1618
|
+
const totalBalance = yoctoNear(valid.amount).add(lockedBalance);
|
|
1619
|
+
const final = {
|
|
1620
|
+
blockHash: valid.blockHash,
|
|
1621
|
+
blockHeight: valid.blockHeight,
|
|
1622
|
+
accountId: args.accountId,
|
|
1623
|
+
accountState: {
|
|
1624
|
+
balance: {
|
|
1625
|
+
total: totalBalance,
|
|
1626
|
+
locked: lockedBalance
|
|
1627
|
+
},
|
|
1628
|
+
usedStorageBytes: valid.storageUsage,
|
|
1629
|
+
contractWasmHash: valid.codeHash
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
if (valid.globalContractAccountId)
|
|
1633
|
+
final.accountState.globalContractAccountId = valid.globalContractAccountId;
|
|
1634
|
+
if (valid.globalContractHash)
|
|
1635
|
+
final.accountState.globalContractHash = valid.globalContractHash;
|
|
1636
|
+
return final;
|
|
1637
|
+
};
|
|
1638
|
+
var createGetAccountState = ({ sendRequest }) => async (args) => {
|
|
1639
|
+
const result = await sendRequest({
|
|
1640
|
+
body: {
|
|
1641
|
+
method: "query",
|
|
1642
|
+
params: {
|
|
1643
|
+
request_type: "view_account",
|
|
1644
|
+
account_id: args.accountId,
|
|
1645
|
+
...toNativeBlockReference(args.atMomentOf)
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
return transformResult(result, args);
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
// src/client/createClient/account/getAccountKey.ts
|
|
1653
|
+
import * as z3 from "zod/mini";
|
|
1654
|
+
|
|
1655
|
+
// src/client/createClient/account/helpers/transformKey.ts
|
|
1656
|
+
var transformKey = (key) => {
|
|
1657
|
+
const publicKey = key.publicKey;
|
|
1658
|
+
const nonce = key.accessKey.nonce;
|
|
1659
|
+
if (key.accessKey.permission === "FullAccess")
|
|
1660
|
+
return {
|
|
1661
|
+
accessType: "FullAccess",
|
|
1662
|
+
publicKey,
|
|
1663
|
+
nonce
|
|
1664
|
+
};
|
|
1665
|
+
const { receiverId, methodNames, allowance } = key.accessKey.permission.FunctionCall;
|
|
1666
|
+
const functionCallKey = {
|
|
1667
|
+
accessType: "FunctionCall",
|
|
1668
|
+
publicKey,
|
|
1669
|
+
nonce,
|
|
1670
|
+
contractAccountId: receiverId
|
|
1671
|
+
};
|
|
1672
|
+
if (typeof allowance === "string") {
|
|
1673
|
+
functionCallKey.gasBudget = yoctoNear(allowance);
|
|
1674
|
+
}
|
|
1675
|
+
if (methodNames.length > 0) {
|
|
1676
|
+
functionCallKey.allowedFunctions = methodNames;
|
|
1677
|
+
}
|
|
1678
|
+
return functionCallKey;
|
|
1679
|
+
};
|
|
1680
|
+
|
|
1681
|
+
// src/client/createClient/account/getAccountKey.ts
|
|
1682
|
+
var RpcQueryAccessKeyViewResponseSchema = z3.object({
|
|
1683
|
+
...AccessKeyViewSchema().shape,
|
|
1684
|
+
blockHash: CryptoHashSchema(),
|
|
1685
|
+
blockHeight: z3.number()
|
|
1686
|
+
});
|
|
1687
|
+
var transformResult2 = (result, args) => {
|
|
1688
|
+
const camelCased = snakeToCamelCase(result);
|
|
1689
|
+
const valid = RpcQueryAccessKeyViewResponseSchema.parse(camelCased);
|
|
1690
|
+
return {
|
|
1691
|
+
blockHash: valid.blockHash,
|
|
1692
|
+
blockHeight: valid.blockHeight,
|
|
1693
|
+
accountId: args.accountId,
|
|
1694
|
+
accountKey: transformKey({
|
|
1695
|
+
accessKey: valid,
|
|
1696
|
+
publicKey: args.publicKey
|
|
1697
|
+
})
|
|
1698
|
+
};
|
|
1699
|
+
};
|
|
1700
|
+
var createGetAccountKey = ({ sendRequest }) => async (args) => {
|
|
1701
|
+
const result = await sendRequest({
|
|
1702
|
+
body: {
|
|
1703
|
+
method: "query",
|
|
1704
|
+
params: {
|
|
1705
|
+
request_type: "view_access_key",
|
|
1706
|
+
account_id: args.accountId,
|
|
1707
|
+
public_key: args.publicKey,
|
|
1708
|
+
...toNativeBlockReference(args.atMomentOf)
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
1712
|
+
return transformResult2(result, args);
|
|
1713
|
+
};
|
|
1714
|
+
|
|
1715
|
+
// src/client/createClient/account/getAccountKeys.ts
|
|
1716
|
+
import * as z4 from "zod/mini";
|
|
1717
|
+
var RpcQueryAccessKeyListResponseSchema = z4.object({
|
|
1718
|
+
...AccessKeyListSchema().shape,
|
|
1719
|
+
blockHash: CryptoHashSchema(),
|
|
1720
|
+
blockHeight: z4.number()
|
|
1721
|
+
});
|
|
1722
|
+
var transformResult3 = (result, args) => {
|
|
1723
|
+
const camelCased = snakeToCamelCase(result);
|
|
1724
|
+
const valid = RpcQueryAccessKeyListResponseSchema.parse(camelCased);
|
|
1725
|
+
return {
|
|
1726
|
+
blockHash: valid.blockHash,
|
|
1727
|
+
blockHeight: valid.blockHeight,
|
|
1728
|
+
accountId: args.accountId,
|
|
1729
|
+
accountKeys: valid.keys.map(transformKey)
|
|
1730
|
+
};
|
|
1731
|
+
};
|
|
1732
|
+
var createGetAccountKeys = ({ sendRequest }) => async (args) => {
|
|
1733
|
+
const result = await sendRequest({
|
|
1734
|
+
body: {
|
|
1735
|
+
method: "query",
|
|
1736
|
+
params: {
|
|
1737
|
+
request_type: "view_access_key_list",
|
|
1738
|
+
account_id: args.accountId,
|
|
1739
|
+
...toNativeBlockReference(args.atMomentOf)
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
return transformResult3(result, args);
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
// src/client/createClient/contract/getContractState.ts
|
|
1747
|
+
import * as z5 from "zod/mini";
|
|
1748
|
+
import { base64 } from "@scure/base";
|
|
1749
|
+
var RpcQueryViewStateResponseSchema = z5.object({
|
|
1750
|
+
...ViewStateResultSchema().shape,
|
|
1751
|
+
blockHash: CryptoHashSchema(),
|
|
1752
|
+
blockHeight: z5.number()
|
|
1753
|
+
});
|
|
1754
|
+
var transformResult4 = (result, args) => {
|
|
1755
|
+
const camelCased = snakeToCamelCase(result);
|
|
1756
|
+
const valid = RpcQueryViewStateResponseSchema.parse(camelCased);
|
|
1757
|
+
const final = {
|
|
1758
|
+
blockHash: valid.blockHash,
|
|
1759
|
+
blockHeight: valid.blockHeight,
|
|
1760
|
+
contractAccountId: args.contractAccountId,
|
|
1761
|
+
contractState: valid.values
|
|
1762
|
+
};
|
|
1763
|
+
if (valid.proof) final.proof = valid.proof;
|
|
1764
|
+
return final;
|
|
1765
|
+
};
|
|
1766
|
+
var createGetContractState = ({ sendRequest }) => async (args) => {
|
|
1767
|
+
const base64KeyPrefix = args.keyPrefix ? base64.encode(Uint8Array.from(args.keyPrefix)) : "";
|
|
1768
|
+
const result = await sendRequest({
|
|
1769
|
+
body: {
|
|
1770
|
+
method: "query",
|
|
1771
|
+
params: {
|
|
1772
|
+
request_type: "view_state",
|
|
1773
|
+
account_id: args.contractAccountId,
|
|
1774
|
+
prefix_base64: base64KeyPrefix,
|
|
1775
|
+
include_proof: args.includeProof,
|
|
1776
|
+
...toNativeBlockReference(args.atMomentOf)
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
return transformResult4(result, args);
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
// src/client/createClient/contract/callContractReadFunction.ts
|
|
1784
|
+
import { base64 as base642 } from "@scure/base";
|
|
1785
|
+
import * as z6 from "zod/mini";
|
|
1786
|
+
var baseDeserializeResul = ({ rawResult }) => fromJsonBytes(rawResult);
|
|
1787
|
+
var RpcCallFunctionResponseSchema = z6.object({
|
|
1788
|
+
...CallResultSchema().shape,
|
|
1789
|
+
blockHash: CryptoHashSchema(),
|
|
1790
|
+
blockHeight: z6.number()
|
|
1791
|
+
});
|
|
1792
|
+
var transformResult5 = (result, args) => {
|
|
1793
|
+
const camelCased = snakeToCamelCase(result);
|
|
1794
|
+
const valid = RpcCallFunctionResponseSchema.parse(camelCased);
|
|
1795
|
+
const transformer = args?.options?.deserializeResult ? args.options.deserializeResult : baseDeserializeResul;
|
|
1796
|
+
return {
|
|
1797
|
+
blockHash: valid.blockHash,
|
|
1798
|
+
blockHeight: valid.blockHeight,
|
|
1799
|
+
result: transformer({ rawResult: valid.result }),
|
|
1800
|
+
logs: valid.logs
|
|
1801
|
+
};
|
|
1802
|
+
};
|
|
1803
|
+
var serializeFunctionArgs = (args) => {
|
|
1804
|
+
if (args?.options?.serializeArgs)
|
|
1805
|
+
return args.options.serializeArgs({ functionArgs: args.functionArgs });
|
|
1806
|
+
if (args?.functionArgs) return toJsonBytes(args?.functionArgs);
|
|
1807
|
+
return new Uint8Array();
|
|
1808
|
+
};
|
|
1809
|
+
var createCallContractReadFunction = ({ sendRequest }) => async (args) => {
|
|
1810
|
+
const result = await sendRequest({
|
|
1811
|
+
body: {
|
|
1812
|
+
method: "query",
|
|
1813
|
+
params: {
|
|
1814
|
+
request_type: "call_function",
|
|
1815
|
+
account_id: args.contractAccountId,
|
|
1816
|
+
method_name: args.functionName,
|
|
1817
|
+
args_base64: base642.encode(serializeFunctionArgs(args)),
|
|
1818
|
+
...toNativeBlockReference(args.withStateAt)
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
return transformResult5(result, args);
|
|
1823
|
+
};
|
|
1824
|
+
|
|
1825
|
+
// src/client/createClient/block/getBlock.ts
|
|
1826
|
+
var transformResult6 = (result) => {
|
|
1827
|
+
const camelCased = snakeToCamelCase(result);
|
|
1828
|
+
return RpcBlockResponseSchema().parse(camelCased);
|
|
1829
|
+
};
|
|
1830
|
+
var createGetBlock = ({ sendRequest }) => async (args) => {
|
|
1831
|
+
const result = await sendRequest({
|
|
1832
|
+
body: {
|
|
1833
|
+
method: "block",
|
|
1834
|
+
params: toNativeBlockReference(args?.blockReference)
|
|
1835
|
+
}
|
|
1836
|
+
});
|
|
1837
|
+
return transformResult6(result);
|
|
1838
|
+
};
|
|
1839
|
+
|
|
1840
|
+
// src/client/createClient/protocol/getGasPrice.ts
|
|
1841
|
+
import * as z8 from "zod/mini";
|
|
1842
|
+
|
|
1843
|
+
// src/_common/schemas/zod/common.ts
|
|
1844
|
+
import * as z7 from "zod/mini";
|
|
1845
|
+
import { base58 } from "@scure/base";
|
|
1846
|
+
var Base58StringSchema = z7.string().check(
|
|
1847
|
+
z7.regex(
|
|
1848
|
+
/^[1-9A-HJ-NP-Za-km-z]+$/,
|
|
1849
|
+
oneLine(`Base58 string contains invalid characters. Allowed characters:
|
|
1850
|
+
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`)
|
|
1851
|
+
)
|
|
1852
|
+
);
|
|
1853
|
+
var CryptoHashSchema2 = Base58StringSchema.check(
|
|
1854
|
+
z7.refine(
|
|
1855
|
+
(val) => {
|
|
1856
|
+
try {
|
|
1857
|
+
const bytes = base58.decode(val);
|
|
1858
|
+
return bytes.length === 32;
|
|
1859
|
+
} catch {
|
|
1860
|
+
return false;
|
|
1861
|
+
}
|
|
1862
|
+
},
|
|
1863
|
+
{ error: "CryptoHash string must decode to 32 bytes" }
|
|
1864
|
+
)
|
|
1865
|
+
);
|
|
1866
|
+
var BlockHashSchema = CryptoHashSchema2;
|
|
1867
|
+
var BlockHeightSchema = z7.uint64();
|
|
1868
|
+
var BlockIdSchema = z7.union([BlockHeightSchema, BlockHashSchema]);
|
|
1869
|
+
|
|
1870
|
+
// src/client/createClient/protocol/getGasPrice.ts
|
|
1871
|
+
var transformResult7 = (result) => {
|
|
1872
|
+
const camelCased = snakeToCamelCase(result);
|
|
1873
|
+
const valid = RpcGasPriceResponseSchema().parse(camelCased);
|
|
1874
|
+
return {
|
|
1875
|
+
gasPrice: yoctoNear(valid.gasPrice)
|
|
1876
|
+
};
|
|
1877
|
+
};
|
|
1878
|
+
var GetGasPriceArgsSchema = z8.optional(
|
|
1879
|
+
z8.object({
|
|
1880
|
+
blockId: z8.optional(BlockIdSchema)
|
|
1881
|
+
})
|
|
1882
|
+
);
|
|
1883
|
+
var getBlockId = (atMomentOf) => {
|
|
1884
|
+
if (atMomentOf === "LatestOptimisticBlock") return null;
|
|
1885
|
+
if (atMomentOf && "blockHash" in atMomentOf) return atMomentOf.blockHash;
|
|
1886
|
+
if (atMomentOf && "blockHeight" in atMomentOf) return atMomentOf.blockHeight;
|
|
1887
|
+
return null;
|
|
1888
|
+
};
|
|
1889
|
+
var createGetGasPrice = ({ sendRequest }) => async (args) => {
|
|
1890
|
+
GetGasPriceArgsSchema.parse(args);
|
|
1891
|
+
const result = await sendRequest({
|
|
1892
|
+
body: {
|
|
1893
|
+
method: "gas_price",
|
|
1894
|
+
params: {
|
|
1895
|
+
block_id: getBlockId(args?.atMomentOf)
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
});
|
|
1899
|
+
return transformResult7(result);
|
|
1900
|
+
};
|
|
1901
|
+
|
|
1902
|
+
// src/client/createClient/protocol/getProtocolConfig.ts
|
|
1903
|
+
import * as z9 from "zod/mini";
|
|
1904
|
+
var TemporaryProtocolConfigShema = z9.object({
|
|
1905
|
+
...RpcProtocolConfigResponseSchema().shape,
|
|
1906
|
+
runtimeConfig: z9.object({
|
|
1907
|
+
...RuntimeConfigViewSchema().shape,
|
|
1908
|
+
wasmConfig: z9.omit(VMConfigViewSchema(), { reftypesBulkMemory: true })
|
|
1909
|
+
})
|
|
1910
|
+
});
|
|
1911
|
+
var transformResult8 = (result) => {
|
|
1912
|
+
const camelCased = snakeToCamelCase(result);
|
|
1913
|
+
return TemporaryProtocolConfigShema.parse(camelCased);
|
|
1914
|
+
};
|
|
1915
|
+
var createGetProtocolConfig = ({ sendRequest }) => async (args) => {
|
|
1916
|
+
const result = await sendRequest({
|
|
1917
|
+
body: {
|
|
1918
|
+
method: "EXPERIMENTAL_protocol_config",
|
|
1919
|
+
params: toNativeBlockReference(args?.atMomentOf)
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
return transformResult8(result);
|
|
1923
|
+
};
|
|
1924
|
+
|
|
1925
|
+
// src/client/createClient/transaction/sendSignedTransaction.ts
|
|
1926
|
+
import { base64 as base644 } from "@scure/base";
|
|
1927
|
+
|
|
1928
|
+
// src/_common/transformers/toBorshBytes/signedTransaction.ts
|
|
1929
|
+
import { serialize } from "borsh";
|
|
1930
|
+
|
|
1931
|
+
// src/_common/schemas/borsh/publicKey.ts
|
|
1932
|
+
var Ed25519PublicKeyBorshSchema = {
|
|
1933
|
+
struct: {
|
|
1934
|
+
ed25519Key: {
|
|
1935
|
+
struct: {
|
|
1936
|
+
data: { array: { type: "u8", len: 32 } }
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
};
|
|
1941
|
+
var Secp256k1PublicKeyBorshSchema = {
|
|
1942
|
+
struct: {
|
|
1943
|
+
secp256k1Key: {
|
|
1944
|
+
struct: {
|
|
1945
|
+
data: { array: { type: "u8", len: 64 } }
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
var publicKeyBorshSchema = {
|
|
1951
|
+
enum: [Ed25519PublicKeyBorshSchema, Secp256k1PublicKeyBorshSchema]
|
|
1952
|
+
};
|
|
1953
|
+
|
|
1954
|
+
// src/_common/schemas/borsh/actions/createAccount.ts
|
|
1955
|
+
var createAccountActionBorshSchema = {
|
|
1956
|
+
struct: {
|
|
1957
|
+
createAccount: {
|
|
1958
|
+
struct: {}
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
|
|
1963
|
+
// src/_common/schemas/borsh/actions/transfer.ts
|
|
1964
|
+
var transferActionBorshSchema = {
|
|
1965
|
+
struct: {
|
|
1966
|
+
transfer: {
|
|
1967
|
+
struct: {
|
|
1968
|
+
deposit: "u128"
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
// src/_common/schemas/borsh/actions/addKey.ts
|
|
1975
|
+
var fullAccessPermissionBorshSchema = {
|
|
1976
|
+
struct: {
|
|
1977
|
+
fullAccess: {
|
|
1978
|
+
struct: {}
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
var functionCallPermissionBorshSchema = {
|
|
1983
|
+
struct: {
|
|
1984
|
+
functionCall: {
|
|
1985
|
+
struct: {
|
|
1986
|
+
allowance: { option: "u128" },
|
|
1987
|
+
receiverId: "string",
|
|
1988
|
+
methodNames: { array: { type: "string" } }
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1993
|
+
var accessKeyBorshSchema = {
|
|
1994
|
+
struct: {
|
|
1995
|
+
nonce: "u64",
|
|
1996
|
+
permission: {
|
|
1997
|
+
enum: [
|
|
1998
|
+
functionCallPermissionBorshSchema,
|
|
1999
|
+
fullAccessPermissionBorshSchema
|
|
2000
|
+
]
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
};
|
|
2004
|
+
var addKeyActionBorshSchema = {
|
|
2005
|
+
struct: {
|
|
2006
|
+
addKey: {
|
|
2007
|
+
struct: {
|
|
2008
|
+
publicKey: publicKeyBorshSchema,
|
|
2009
|
+
accessKey: accessKeyBorshSchema
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
2014
|
+
|
|
2015
|
+
// src/_common/schemas/borsh/actions/deployContract.ts
|
|
2016
|
+
var deployContractActionBorshSchema = {
|
|
2017
|
+
struct: {
|
|
2018
|
+
deployContract: {
|
|
2019
|
+
struct: {
|
|
2020
|
+
code: { array: { type: "u8" } }
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
|
|
2026
|
+
// src/_common/schemas/borsh/actions/deployGlobalContract.ts
|
|
2027
|
+
var codeHashModeBorshSchema = {
|
|
2028
|
+
struct: {
|
|
2029
|
+
CodeHash: { struct: {} }
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
var accountIdModeBorshSchema = {
|
|
2033
|
+
struct: {
|
|
2034
|
+
AccountId: { struct: {} }
|
|
2035
|
+
}
|
|
2036
|
+
};
|
|
2037
|
+
var deployGlobalContractActionBorshSchema = {
|
|
2038
|
+
struct: {
|
|
2039
|
+
deployGlobalContract: {
|
|
2040
|
+
struct: {
|
|
2041
|
+
code: { array: { type: "u8" } },
|
|
2042
|
+
deployMode: {
|
|
2043
|
+
enum: [codeHashModeBorshSchema, accountIdModeBorshSchema]
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
2049
|
+
|
|
2050
|
+
// src/_common/schemas/borsh/actions/useGlobalContract.ts
|
|
2051
|
+
var codeHashIdentifierBorshSchema = {
|
|
2052
|
+
struct: {
|
|
2053
|
+
CodeHash: { array: { type: "u8", len: 32 } }
|
|
2054
|
+
}
|
|
2055
|
+
};
|
|
2056
|
+
var accountIdIdentifierBorshSchema = {
|
|
2057
|
+
struct: {
|
|
2058
|
+
AccountId: "string"
|
|
2059
|
+
}
|
|
2060
|
+
};
|
|
2061
|
+
var useGlobalContractActionBorshSchema = {
|
|
2062
|
+
struct: {
|
|
2063
|
+
useGlobalContract: {
|
|
2064
|
+
struct: {
|
|
2065
|
+
contractIdentifier: {
|
|
2066
|
+
enum: [codeHashIdentifierBorshSchema, accountIdIdentifierBorshSchema]
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
|
|
2073
|
+
// src/_common/schemas/borsh/actions/functionCall.ts
|
|
2074
|
+
var functionCallActionBorshSchema = {
|
|
2075
|
+
struct: {
|
|
2076
|
+
functionCall: {
|
|
2077
|
+
struct: {
|
|
2078
|
+
methodName: "string",
|
|
2079
|
+
args: { array: { type: "u8" } },
|
|
2080
|
+
gas: "u64",
|
|
2081
|
+
deposit: "u128"
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
|
|
2087
|
+
// src/_common/schemas/borsh/actions/stake.ts
|
|
2088
|
+
var stakeActionBorshSchema = {
|
|
2089
|
+
struct: {
|
|
2090
|
+
stake: {
|
|
2091
|
+
struct: {
|
|
2092
|
+
stake: "u128",
|
|
2093
|
+
publicKey: publicKeyBorshSchema
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
|
|
2099
|
+
// src/_common/schemas/borsh/actions/deleteKey.ts
|
|
2100
|
+
var deleteKeyActionBorshSchema = {
|
|
2101
|
+
struct: {
|
|
2102
|
+
deleteKey: {
|
|
2103
|
+
struct: {
|
|
2104
|
+
publicKey: publicKeyBorshSchema
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
|
|
2110
|
+
// src/_common/schemas/borsh/actions/deleteAccount.ts
|
|
2111
|
+
var deleteAccountActionBorshSchema = {
|
|
2112
|
+
struct: {
|
|
2113
|
+
deleteAccount: {
|
|
2114
|
+
struct: {
|
|
2115
|
+
beneficiaryId: "string"
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2121
|
+
// src/_common/schemas/borsh/delegateAction.ts
|
|
2122
|
+
var allowedActionBorshSchema = {
|
|
2123
|
+
enum: [
|
|
2124
|
+
createAccountActionBorshSchema,
|
|
2125
|
+
deployContractActionBorshSchema,
|
|
2126
|
+
functionCallActionBorshSchema,
|
|
2127
|
+
transferActionBorshSchema,
|
|
2128
|
+
stakeActionBorshSchema,
|
|
2129
|
+
addKeyActionBorshSchema,
|
|
2130
|
+
deleteKeyActionBorshSchema,
|
|
2131
|
+
deleteAccountActionBorshSchema,
|
|
2132
|
+
{ struct: { signedDelegate: "string" } },
|
|
2133
|
+
// TODO is it possible to rid this placeholder and keep enum order?
|
|
2134
|
+
deployGlobalContractActionBorshSchema,
|
|
2135
|
+
useGlobalContractActionBorshSchema
|
|
2136
|
+
]
|
|
2137
|
+
};
|
|
2138
|
+
var delegateActionBorshSchema = {
|
|
2139
|
+
struct: {
|
|
2140
|
+
senderId: "string",
|
|
2141
|
+
publicKey: publicKeyBorshSchema,
|
|
2142
|
+
actions: { array: { type: allowedActionBorshSchema } },
|
|
2143
|
+
receiverId: "string",
|
|
2144
|
+
nonce: "u64",
|
|
2145
|
+
maxBlockHeight: "u64"
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
|
|
2149
|
+
// src/_common/schemas/borsh/signature.ts
|
|
2150
|
+
var Ed25519SignatureBorshSchema = {
|
|
2151
|
+
struct: {
|
|
2152
|
+
ed25519Signature: {
|
|
2153
|
+
struct: {
|
|
2154
|
+
data: { array: { type: "u8", len: 64 } }
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
var Secp256k1SignatureBorshSchema = {
|
|
2160
|
+
struct: {
|
|
2161
|
+
secp256k1Signature: {
|
|
2162
|
+
struct: {
|
|
2163
|
+
data: { array: { type: "u8", len: 65 } }
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2168
|
+
var signatureBorshSchema = {
|
|
2169
|
+
enum: [Ed25519SignatureBorshSchema, Secp256k1SignatureBorshSchema]
|
|
2170
|
+
};
|
|
2171
|
+
|
|
2172
|
+
// src/_common/schemas/borsh/actions/signedDelegate.ts
|
|
2173
|
+
var signedDelegateActionBorshSchema = {
|
|
2174
|
+
struct: {
|
|
2175
|
+
signedDelegate: {
|
|
2176
|
+
struct: {
|
|
2177
|
+
delegateAction: delegateActionBorshSchema,
|
|
2178
|
+
signature: signatureBorshSchema
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
};
|
|
2183
|
+
|
|
2184
|
+
// src/_common/schemas/borsh/transaction.ts
|
|
2185
|
+
var actionBorshSchema = {
|
|
2186
|
+
enum: [
|
|
2187
|
+
createAccountActionBorshSchema,
|
|
2188
|
+
deployContractActionBorshSchema,
|
|
2189
|
+
functionCallActionBorshSchema,
|
|
2190
|
+
transferActionBorshSchema,
|
|
2191
|
+
stakeActionBorshSchema,
|
|
2192
|
+
addKeyActionBorshSchema,
|
|
2193
|
+
deleteKeyActionBorshSchema,
|
|
2194
|
+
deleteAccountActionBorshSchema,
|
|
2195
|
+
signedDelegateActionBorshSchema,
|
|
2196
|
+
deployGlobalContractActionBorshSchema,
|
|
2197
|
+
useGlobalContractActionBorshSchema
|
|
2198
|
+
]
|
|
2199
|
+
};
|
|
2200
|
+
var transactionBorshSchema = {
|
|
2201
|
+
struct: {
|
|
2202
|
+
signerId: "string",
|
|
2203
|
+
publicKey: publicKeyBorshSchema,
|
|
2204
|
+
nonce: "u64",
|
|
2205
|
+
receiverId: "string",
|
|
2206
|
+
blockHash: { array: { type: "u8", len: 32 } },
|
|
2207
|
+
actions: { array: { type: actionBorshSchema } }
|
|
2208
|
+
}
|
|
2209
|
+
};
|
|
2210
|
+
|
|
2211
|
+
// src/_common/schemas/borsh/signedTransaction.ts
|
|
2212
|
+
var signedTransactionBorshSchema = {
|
|
2213
|
+
struct: {
|
|
2214
|
+
transaction: transactionBorshSchema,
|
|
2215
|
+
signature: signatureBorshSchema
|
|
2216
|
+
}
|
|
2217
|
+
};
|
|
2218
|
+
|
|
2219
|
+
// src/_common/transformers/curveString.ts
|
|
2220
|
+
import { base58 as base582 } from "@scure/base";
|
|
2221
|
+
var toEd25519CurveString = (u8Data) => `ed25519:${base582.encode(u8Data)}`;
|
|
2222
|
+
var toSecp256k1CurveString = (u8Data) => `secp256k1:${base582.encode(u8Data)}`;
|
|
2223
|
+
var fromCurveString = (value) => {
|
|
2224
|
+
const [curve, base58String] = value.split(":");
|
|
2225
|
+
return {
|
|
2226
|
+
curve,
|
|
2227
|
+
u8Data: base582.decode(base58String)
|
|
2228
|
+
};
|
|
2229
|
+
};
|
|
2230
|
+
|
|
2231
|
+
// src/_common/transformers/toNative/signature.ts
|
|
2232
|
+
var toNativeSignature = (signature) => {
|
|
2233
|
+
const { curve, u8Data } = fromCurveString(signature);
|
|
2234
|
+
if (curve === "ed25519") return { ed25519Signature: { data: u8Data } };
|
|
2235
|
+
return { secp256k1Signature: { data: u8Data } };
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
// src/_common/transformers/toNative/transaction.ts
|
|
2239
|
+
import { base58 as base583 } from "@scure/base";
|
|
2240
|
+
|
|
2241
|
+
// src/_common/transformers/toNative/publicKey.ts
|
|
2242
|
+
var toNativePublicKey = (publicKey) => {
|
|
2243
|
+
const { curve, u8Data } = fromCurveString(publicKey);
|
|
2244
|
+
if (curve === "ed25519") return { ed25519Key: { data: u8Data } };
|
|
2245
|
+
return { secp256k1Key: { data: u8Data } };
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2248
|
+
// src/_common/transformers/toNative/actions/transfer.ts
|
|
2249
|
+
var toNativeTransferAction = (action) => ({
|
|
2250
|
+
transfer: {
|
|
2251
|
+
deposit: fromNearOption(action.params.amount).yoctoNear
|
|
2252
|
+
}
|
|
2253
|
+
});
|
|
2254
|
+
|
|
2255
|
+
// src/_common/transformers/toNative/actions/createAccount.ts
|
|
2256
|
+
var toNativeCreateAccountAction = () => ({
|
|
2257
|
+
createAccount: {}
|
|
2258
|
+
});
|
|
2259
|
+
|
|
2260
|
+
// src/_common/transformers/toNative/actions/addKey.ts
|
|
2261
|
+
var getPermission = (params) => {
|
|
2262
|
+
if (params.accessType === "FullAccess") return { fullAccess: {} };
|
|
2263
|
+
const { contractAccountId, gasBudget, allowedFunctions } = params;
|
|
2264
|
+
return {
|
|
2265
|
+
functionCall: {
|
|
2266
|
+
receiverId: contractAccountId,
|
|
2267
|
+
allowance: gasBudget && fromNearOption(gasBudget).yoctoNear,
|
|
2268
|
+
methodNames: allowedFunctions ?? []
|
|
2269
|
+
}
|
|
2270
|
+
};
|
|
2271
|
+
};
|
|
2272
|
+
var toNativeAddKeyAction = (action) => ({
|
|
2273
|
+
addKey: {
|
|
2274
|
+
publicKey: toNativePublicKey(action.params.publicKey),
|
|
2275
|
+
accessKey: {
|
|
2276
|
+
nonce: 0n,
|
|
2277
|
+
// Placeholder; It's not usable anymore: https://gov.near.org/t/issue-with-access-key-nonce/749
|
|
2278
|
+
permission: getPermission(action.params)
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
|
|
2283
|
+
// src/_common/transformers/toNative/actions/deployContract.ts
|
|
2284
|
+
import { base64 as base643 } from "@scure/base";
|
|
2285
|
+
var toNativeDeployContractAction = (action) => {
|
|
2286
|
+
const code = action.params.wasmBytes ? action.params.wasmBytes : base643.decode(action.params.wasmBase64);
|
|
2287
|
+
return {
|
|
2288
|
+
deployContract: { code }
|
|
2289
|
+
};
|
|
2290
|
+
};
|
|
2291
|
+
|
|
2292
|
+
// src/helpers/gas.ts
|
|
2293
|
+
var TeraCoefficient = 10n ** 12n;
|
|
2294
|
+
var gas = (gas2) => {
|
|
2295
|
+
return {
|
|
2296
|
+
gas: BigInt(gas2),
|
|
2297
|
+
teraGas: String(BigInt(gas2) / TeraCoefficient)
|
|
2298
|
+
// We don't keep decimals here
|
|
2299
|
+
};
|
|
2300
|
+
};
|
|
2301
|
+
var teraGas = (teraGas2) => {
|
|
2302
|
+
return {
|
|
2303
|
+
gas: BigInt(teraGas2) * TeraCoefficient,
|
|
2304
|
+
teraGas: teraGas2
|
|
2305
|
+
};
|
|
2306
|
+
};
|
|
2307
|
+
var fromGasOption = (gasOption) => {
|
|
2308
|
+
if ("teraGas" in gasOption) return teraGas(gasOption.teraGas);
|
|
2309
|
+
if ("gas" in gasOption) return gas(gasOption.gas);
|
|
2310
|
+
throw new Error("Invalid gas option");
|
|
2311
|
+
};
|
|
2312
|
+
|
|
2313
|
+
// src/_common/transformers/contract.ts
|
|
2314
|
+
var toContractFnArgsBytes = (args) => {
|
|
2315
|
+
if (args.fnArgsBytes) return args.fnArgsBytes;
|
|
2316
|
+
if (args.fnArgsJson) return toJsonBytes(args.fnArgsJson);
|
|
2317
|
+
return new Uint8Array();
|
|
2318
|
+
};
|
|
2319
|
+
|
|
2320
|
+
// src/_common/transformers/toNative/actions/functionCall.ts
|
|
2321
|
+
var toNativeFunctionCallAction = (action) => {
|
|
2322
|
+
const { functionName, attachedDeposit, gasLimit } = action.params;
|
|
2323
|
+
return {
|
|
2324
|
+
functionCall: {
|
|
2325
|
+
methodName: functionName,
|
|
2326
|
+
args: toContractFnArgsBytes(action.params),
|
|
2327
|
+
gas: fromGasOption(gasLimit).gas,
|
|
2328
|
+
deposit: attachedDeposit ? fromNearOption(attachedDeposit).yoctoNear : 0n
|
|
2329
|
+
}
|
|
2330
|
+
};
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2333
|
+
// src/_common/transformers/toNative/actions/deleteKey.ts
|
|
2334
|
+
var toNativeDeleteKeyAction = (action) => ({
|
|
2335
|
+
deleteKey: {
|
|
2336
|
+
publicKey: toNativePublicKey(action.params.publicKey)
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
|
|
2340
|
+
// src/_common/transformers/toNative/actions/deleteAccount.ts
|
|
2341
|
+
var toNativeDeleteAccountAction = (action) => ({
|
|
2342
|
+
deleteAccount: {
|
|
2343
|
+
beneficiaryId: action.params.beneficiaryAccountId
|
|
2344
|
+
}
|
|
2345
|
+
});
|
|
2346
|
+
|
|
2347
|
+
// src/_common/transformers/toNative/transaction.ts
|
|
2348
|
+
var toNativeAction = (action) => {
|
|
2349
|
+
if (action.actionType === "Transfer") return toNativeTransferAction(action);
|
|
2350
|
+
if (action.actionType === "CreateAccount")
|
|
2351
|
+
return toNativeCreateAccountAction();
|
|
2352
|
+
if (action.actionType === "AddKey") return toNativeAddKeyAction(action);
|
|
2353
|
+
if (action.actionType === "DeployContract")
|
|
2354
|
+
return toNativeDeployContractAction(action);
|
|
2355
|
+
if (action.actionType === "FunctionCall")
|
|
2356
|
+
return toNativeFunctionCallAction(action);
|
|
2357
|
+
if (action.actionType === "DeleteKey") return toNativeDeleteKeyAction(action);
|
|
2358
|
+
if (action.actionType === "DeleteAccount")
|
|
2359
|
+
return toNativeDeleteAccountAction(action);
|
|
2360
|
+
throw new Error("Invalid transaction action type");
|
|
2361
|
+
};
|
|
2362
|
+
var toNativeActions = (transaction) => {
|
|
2363
|
+
if (transaction.action) return [toNativeAction(transaction.action)];
|
|
2364
|
+
if (transaction.actions)
|
|
2365
|
+
return transaction.actions.map((action) => toNativeAction(action));
|
|
2366
|
+
return [];
|
|
2367
|
+
};
|
|
2368
|
+
var toNativeTransaction = (transaction) => ({
|
|
2369
|
+
signerId: transaction.signerAccountId,
|
|
2370
|
+
publicKey: toNativePublicKey(transaction.signerPublicKey),
|
|
2371
|
+
actions: toNativeActions(transaction),
|
|
2372
|
+
receiverId: transaction.receiverAccountId,
|
|
2373
|
+
nonce: BigInt(transaction.nonce),
|
|
2374
|
+
blockHash: base583.decode(transaction.blockHash)
|
|
2375
|
+
});
|
|
2376
|
+
var TransactionExecutionStatusMap = {
|
|
2377
|
+
None: "NONE",
|
|
2378
|
+
Included: "INCLUDED",
|
|
2379
|
+
ExecutedOptimistic: "EXECUTED_OPTIMISTIC",
|
|
2380
|
+
IncludedFinal: "INCLUDED_FINAL",
|
|
2381
|
+
Executed: "EXECUTED",
|
|
2382
|
+
Final: "FINAL"
|
|
2383
|
+
};
|
|
2384
|
+
var toNativeTransactionExecutionStatus = (status) => status ? TransactionExecutionStatusMap[status] : TransactionExecutionStatusMap.ExecutedOptimistic;
|
|
2385
|
+
|
|
2386
|
+
// src/_common/transformers/toNative/signedTransaction.ts
|
|
2387
|
+
var toNativeSignedTransaction = (signedTransaction) => ({
|
|
2388
|
+
transaction: toNativeTransaction(signedTransaction.transaction),
|
|
2389
|
+
signature: toNativeSignature(signedTransaction.signature)
|
|
2390
|
+
});
|
|
2391
|
+
|
|
2392
|
+
// src/_common/transformers/toBorshBytes/signedTransaction.ts
|
|
2393
|
+
var serializeNativeSignedTransaction = (nativeSignedTransaction) => serialize(signedTransactionBorshSchema, nativeSignedTransaction);
|
|
2394
|
+
var serializeSignedTransaction = (signedTransaction) => serializeNativeSignedTransaction(
|
|
2395
|
+
toNativeSignedTransaction(signedTransaction)
|
|
2396
|
+
);
|
|
2397
|
+
|
|
2398
|
+
// src/client/createClient/transaction/sendSignedTransaction.ts
|
|
2399
|
+
var transformResult9 = (result) => {
|
|
2400
|
+
const camelCased = snakeToCamelCase(result);
|
|
2401
|
+
return RpcTransactionResponseSchema().parse(camelCased);
|
|
2402
|
+
};
|
|
2403
|
+
var createSendSignedTransaction = ({ sendRequest }) => async (args) => {
|
|
2404
|
+
const result = await sendRequest({
|
|
2405
|
+
body: {
|
|
2406
|
+
method: "send_tx",
|
|
2407
|
+
params: {
|
|
2408
|
+
signed_tx_base64: base644.encode(
|
|
2409
|
+
serializeSignedTransaction(args.signedTransaction)
|
|
2410
|
+
),
|
|
2411
|
+
wait_until: toNativeTransactionExecutionStatus(args?.waitUntil)
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
});
|
|
2415
|
+
return transformResult9(result);
|
|
2416
|
+
};
|
|
2417
|
+
|
|
2418
|
+
// src/_common/utils/createCircularQueue.ts
|
|
2419
|
+
var createCircularQueue = (arr) => {
|
|
2420
|
+
const state = {
|
|
2421
|
+
items: [...arr],
|
|
2422
|
+
current: 0
|
|
2423
|
+
};
|
|
2424
|
+
const next = () => {
|
|
2425
|
+
const value = state.items[state.current];
|
|
2426
|
+
state.current = (state.current + 1) % state.items.length;
|
|
2427
|
+
return value;
|
|
2428
|
+
};
|
|
2429
|
+
const remove = (value) => {
|
|
2430
|
+
const idx = state.items.indexOf(value);
|
|
2431
|
+
if (idx === -1) return false;
|
|
2432
|
+
if (idx < state.current || idx === state.current && state.current === state.items.length - 1) {
|
|
2433
|
+
state.current = (state.current - 1 + state.items.length) % state.items.length;
|
|
2434
|
+
}
|
|
2435
|
+
state.items.splice(idx, 1);
|
|
2436
|
+
if (state.current >= state.items.length) state.current = 0;
|
|
2437
|
+
return true;
|
|
2438
|
+
};
|
|
2439
|
+
const getAll = () => [...state.items];
|
|
2440
|
+
return {
|
|
2441
|
+
next,
|
|
2442
|
+
remove,
|
|
2443
|
+
getAll,
|
|
2444
|
+
size: () => state.items.length
|
|
2445
|
+
};
|
|
2446
|
+
};
|
|
2447
|
+
|
|
2448
|
+
// src/client/createClient/createClient.ts
|
|
2449
|
+
var createClient = ({ network }) => {
|
|
2450
|
+
const context = {
|
|
2451
|
+
regularRpcQueue: createCircularQueue(network.rpcs.regular),
|
|
2452
|
+
archivalRpcQueue: createCircularQueue(network.rpcs.archival)
|
|
2453
|
+
};
|
|
2454
|
+
context.sendRequest = createSendRequest(context);
|
|
2455
|
+
return {
|
|
2456
|
+
getAccountState: createGetAccountState(context),
|
|
2457
|
+
getAccountKey: createGetAccountKey(context),
|
|
2458
|
+
getAccountKeys: createGetAccountKeys(context),
|
|
2459
|
+
getContractState: createGetContractState(context),
|
|
2460
|
+
callContractReadFunction: createCallContractReadFunction(context),
|
|
2461
|
+
getBlock: createGetBlock(context),
|
|
2462
|
+
getGasPrice: createGetGasPrice(context),
|
|
2463
|
+
getProtocolConfig: createGetProtocolConfig(context),
|
|
2464
|
+
sendSignedTransaction: createSendSignedTransaction(context)
|
|
2465
|
+
};
|
|
2466
|
+
};
|
|
2467
|
+
|
|
2468
|
+
// src/client/presets/networks.ts
|
|
2469
|
+
var mainnet = {
|
|
2470
|
+
rpcs: {
|
|
2471
|
+
regular: [
|
|
2472
|
+
{ url: "https://free.rpc.fastnear.com" },
|
|
2473
|
+
{ url: "https://near.blockpi.network/v1/rpc/public" }
|
|
2474
|
+
],
|
|
2475
|
+
archival: []
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
var testnet = {
|
|
2479
|
+
rpcs: {
|
|
2480
|
+
regular: [
|
|
2481
|
+
{ url: "https://rpc.testnet.near.org" },
|
|
2482
|
+
{ url: "https://test.rpc.fastnear.com" }
|
|
2483
|
+
],
|
|
2484
|
+
archival: []
|
|
2485
|
+
}
|
|
2486
|
+
};
|
|
2487
|
+
|
|
2488
|
+
// src/helpers/crypto/getTransactionHash.ts
|
|
2489
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
2490
|
+
import { base58 as base584 } from "@scure/base";
|
|
2491
|
+
|
|
2492
|
+
// src/_common/transformers/toBorshBytes/transaction.ts
|
|
2493
|
+
import { serialize as serialize2 } from "borsh";
|
|
2494
|
+
var serializeNativeTransaction = (nativeTransaction) => serialize2(transactionBorshSchema, nativeTransaction);
|
|
2495
|
+
var serializeTransaction = (transaction) => serializeNativeTransaction(toNativeTransaction(transaction));
|
|
2496
|
+
|
|
2497
|
+
// src/helpers/crypto/getTransactionHash.ts
|
|
2498
|
+
var getTransactionHash = (transaction) => {
|
|
2499
|
+
const transactionBorshBytes = serializeTransaction(transaction);
|
|
2500
|
+
const u8TransactionHash = sha256(transactionBorshBytes);
|
|
2501
|
+
return {
|
|
2502
|
+
transactionHash: base584.encode(u8TransactionHash),
|
|
2503
|
+
u8TransactionHash
|
|
2504
|
+
};
|
|
2505
|
+
};
|
|
2506
|
+
|
|
2507
|
+
// src/helpers/crypto/sign.ts
|
|
2508
|
+
import * as v2 from "valibot";
|
|
2509
|
+
import { ed25519 } from "@noble/curves/ed25519";
|
|
2510
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2511
|
+
|
|
2512
|
+
// src/_common/schemas/valibot/privateKey.ts
|
|
2513
|
+
import * as v from "valibot";
|
|
2514
|
+
var { Ed25519, Secp256k1 } = BinaryCryptoKeyLengths;
|
|
2515
|
+
var BinarySecp256k1PrivateKeySchema = v.pipe(
|
|
2516
|
+
v.instance(Uint8Array),
|
|
2517
|
+
v.length(
|
|
2518
|
+
Secp256k1.PrivateKey,
|
|
2519
|
+
`Length of binary secp256k1 private key should be ${Secp256k1.PrivateKey}`
|
|
2520
|
+
)
|
|
2521
|
+
);
|
|
2522
|
+
var BinaryEd25519PrivateKeySchema = v.pipe(
|
|
2523
|
+
v.instance(Uint8Array),
|
|
2524
|
+
v.length(
|
|
2525
|
+
Ed25519.PrivateKey,
|
|
2526
|
+
`Length of binary ed25519 private key should be ${Ed25519.PrivateKey}`
|
|
2527
|
+
)
|
|
2528
|
+
);
|
|
2529
|
+
|
|
2530
|
+
// src/helpers/crypto/sign.ts
|
|
2531
|
+
var { Ed25519: Ed255192, Secp256k1: Secp256k12 } = BinaryCryptoKeyLengths;
|
|
2532
|
+
var getBinaryEd25519SecretKey = (u8PrivateKey) => v2.parse(BinaryEd25519PrivateKeySchema, u8PrivateKey).slice(0, Ed255192.SecretKey);
|
|
2533
|
+
var signByEd25519Key = (message, u8PrivateKey) => {
|
|
2534
|
+
const u8SecretKey = getBinaryEd25519SecretKey(u8PrivateKey);
|
|
2535
|
+
const u8Signature = ed25519.sign(message, u8SecretKey);
|
|
2536
|
+
return {
|
|
2537
|
+
signature: toEd25519CurveString(u8Signature),
|
|
2538
|
+
u8Signature
|
|
2539
|
+
};
|
|
2540
|
+
};
|
|
2541
|
+
var getBinarySecp256k1SecretKey = (u8PrivateKey) => v2.parse(BinarySecp256k1PrivateKeySchema, u8PrivateKey).slice(0, Secp256k12.SecretKey);
|
|
2542
|
+
var signBySecp256k1Key = (message, u8PrivateKey) => {
|
|
2543
|
+
const u8SecretKey = getBinarySecp256k1SecretKey(u8PrivateKey);
|
|
2544
|
+
const signatureObj = secp256k1.sign(message, u8SecretKey);
|
|
2545
|
+
const u8Signature = new Uint8Array([
|
|
2546
|
+
...signatureObj.toBytes(),
|
|
2547
|
+
signatureObj.recovery
|
|
2548
|
+
]);
|
|
2549
|
+
return {
|
|
2550
|
+
signature: toSecp256k1CurveString(u8Signature),
|
|
2551
|
+
u8Signature
|
|
2552
|
+
};
|
|
2553
|
+
};
|
|
2554
|
+
var sign = ({ message, privateKey }) => {
|
|
2555
|
+
const { curve, u8Data: u8PrivateKey } = fromCurveString(privateKey);
|
|
2556
|
+
return curve === "ed25519" ? signByEd25519Key(message, u8PrivateKey) : signBySecp256k1Key(message, u8PrivateKey);
|
|
2557
|
+
};
|
|
2558
|
+
|
|
2559
|
+
// src/keyServices/memoryKeyService/createSignTransaction.ts
|
|
2560
|
+
var createSignTransaction = (context) => async (transaction) => {
|
|
2561
|
+
const privateKey = context.findPrivateKey(transaction.signerPublicKey);
|
|
2562
|
+
const { transactionHash, u8TransactionHash } = getTransactionHash(transaction);
|
|
2563
|
+
const { signature } = sign({ message: u8TransactionHash, privateKey });
|
|
2564
|
+
return {
|
|
2565
|
+
transaction,
|
|
2566
|
+
transactionHash,
|
|
2567
|
+
signature
|
|
2568
|
+
};
|
|
2569
|
+
};
|
|
2570
|
+
|
|
2571
|
+
// src/helpers/crypto/getPublicKey.ts
|
|
2572
|
+
import * as v3 from "valibot";
|
|
2573
|
+
var { Ed25519: Ed255193, Secp256k1: Secp256k13 } = BinaryCryptoKeyLengths;
|
|
2574
|
+
var getBinaryEd25519PublicKey = (u8Ed25519PrivateKey) => {
|
|
2575
|
+
const validEd25519PrivateKey = v3.parse(
|
|
2576
|
+
BinaryEd25519PrivateKeySchema,
|
|
2577
|
+
u8Ed25519PrivateKey
|
|
2578
|
+
);
|
|
2579
|
+
return validEd25519PrivateKey.slice(Ed255193.SecretKey);
|
|
2580
|
+
};
|
|
2581
|
+
var getEd25519PublicKey = (u8PrivateKey) => {
|
|
2582
|
+
const u8PublicKey = getBinaryEd25519PublicKey(u8PrivateKey);
|
|
2583
|
+
return toEd25519CurveString(u8PublicKey);
|
|
2584
|
+
};
|
|
2585
|
+
var getBinarySecp256k1PublicKey = (u8Secp256k1PrivateKey) => {
|
|
2586
|
+
const validU8PrivateKey = v3.parse(
|
|
2587
|
+
BinarySecp256k1PrivateKeySchema,
|
|
2588
|
+
u8Secp256k1PrivateKey
|
|
2589
|
+
);
|
|
2590
|
+
return validU8PrivateKey.slice(Secp256k13.SecretKey);
|
|
2591
|
+
};
|
|
2592
|
+
var getSecp256k1PublicKey = (u8Secp256k1PrivateKey) => {
|
|
2593
|
+
const u8PublicKey = getBinarySecp256k1PublicKey(u8Secp256k1PrivateKey);
|
|
2594
|
+
return toSecp256k1CurveString(u8PublicKey);
|
|
2595
|
+
};
|
|
2596
|
+
var getPublicKey = (privateKey) => {
|
|
2597
|
+
const { curve, u8Data: u8PrivateKey } = fromCurveString(privateKey);
|
|
2598
|
+
return curve === "ed25519" ? getEd25519PublicKey(u8PrivateKey) : getSecp256k1PublicKey(u8PrivateKey);
|
|
2599
|
+
};
|
|
2600
|
+
|
|
2601
|
+
// src/keyServices/memoryKeyService/parseKeySources.ts
|
|
2602
|
+
var parseKeySource = (keySource) => {
|
|
2603
|
+
if ("privateKey" in keySource) {
|
|
2604
|
+
return {
|
|
2605
|
+
publicKey: getPublicKey(keySource.privateKey),
|
|
2606
|
+
privateKey: keySource.privateKey
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
if ("seedPhrase" in keySource) {
|
|
2610
|
+
return {
|
|
2611
|
+
publicKey: "ed25519:213",
|
|
2612
|
+
privateKey: "ed25519:213"
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
throw new Error("Unknown keySource");
|
|
2616
|
+
};
|
|
2617
|
+
var parseKeySources = (params) => {
|
|
2618
|
+
if (params.keySource) {
|
|
2619
|
+
const { publicKey, privateKey } = parseKeySource(params.keySource);
|
|
2620
|
+
return { [publicKey]: privateKey };
|
|
2621
|
+
}
|
|
2622
|
+
if (params.keySources)
|
|
2623
|
+
return Object.fromEntries(
|
|
2624
|
+
params.keySources.map((keySource) => {
|
|
2625
|
+
const { publicKey, privateKey } = parseKeySource(keySource);
|
|
2626
|
+
return [publicKey, privateKey];
|
|
2627
|
+
})
|
|
2628
|
+
);
|
|
2629
|
+
throw new Error(
|
|
2630
|
+
"Cannot create MemoryKeyService - no private keys were found"
|
|
2631
|
+
);
|
|
2632
|
+
};
|
|
2633
|
+
|
|
2634
|
+
// src/keyServices/memoryKeyService/createFindPrivateKey.ts
|
|
2635
|
+
var createFindPrivateKey = (keyPairs) => (publicKey) => {
|
|
2636
|
+
const privateKey = keyPairs[publicKey];
|
|
2637
|
+
if (keyPairs[publicKey]) return privateKey;
|
|
2638
|
+
throw new Error(
|
|
2639
|
+
`Cannot find a corresponding private key for '${publicKey}'`
|
|
2640
|
+
);
|
|
2641
|
+
};
|
|
2642
|
+
|
|
2643
|
+
// src/keyServices/memoryKeyService/createMemoryKeyService.ts
|
|
2644
|
+
var createMemoryKeyService = async (params) => {
|
|
2645
|
+
const context = {
|
|
2646
|
+
keyPairs: parseKeySources(params)
|
|
2647
|
+
};
|
|
2648
|
+
context.findPrivateKey = createFindPrivateKey(context.keyPairs);
|
|
2649
|
+
return {
|
|
2650
|
+
signTransaction: createSignTransaction(context),
|
|
2651
|
+
getKeyPairs: () => context.keyPairs
|
|
2652
|
+
};
|
|
2653
|
+
};
|
|
2654
|
+
|
|
2655
|
+
// src/signers/memorySigner/keyPool/createFindKeyForTask.ts
|
|
2656
|
+
var findSigningKey = (keyPriority, keyList) => {
|
|
2657
|
+
if (keyPriority.type === "FullAccess") {
|
|
2658
|
+
return keyList.fullAccess.find((key) => !key.isLocked);
|
|
2659
|
+
}
|
|
2660
|
+
return keyList.functionCall.find((key) => {
|
|
2661
|
+
const isUnlocked = key.isLocked === false;
|
|
2662
|
+
const isContractIdMatch = key.contractAccountId === keyPriority.contractAccountId;
|
|
2663
|
+
const isFnCallAllowed = key.allowedFunctions === void 0 || key.allowedFunctions.includes(keyPriority.calledFnName);
|
|
2664
|
+
return isUnlocked && isContractIdMatch && isFnCallAllowed;
|
|
2665
|
+
});
|
|
2666
|
+
};
|
|
2667
|
+
var createFindKeyForTask = (keyList) => (task) => {
|
|
2668
|
+
for (const keyPriority of task.signingKeyPriority) {
|
|
2669
|
+
const key = findSigningKey(keyPriority, keyList);
|
|
2670
|
+
if (key) return key;
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
|
|
2674
|
+
// src/signers/memorySigner/keyPool/createIsKeyForTaskExist.ts
|
|
2675
|
+
var isKeyExist = (keyPriority, keyList) => {
|
|
2676
|
+
if (keyPriority.type === "FullAccess") return keyList.fullAccess.length > 0;
|
|
2677
|
+
return keyList.functionCall.find((key) => {
|
|
2678
|
+
const isContractIdMatch = key.contractAccountId === keyPriority.contractAccountId;
|
|
2679
|
+
const isFnCallAllowed = key.allowedFunctions === void 0 || key.allowedFunctions.includes(keyPriority.calledFnName);
|
|
2680
|
+
return isContractIdMatch && isFnCallAllowed;
|
|
2681
|
+
});
|
|
2682
|
+
};
|
|
2683
|
+
var createIsKeyForTaskExist = (keyList) => (task) => task.signingKeyPriority.some(
|
|
2684
|
+
(keyPriority) => isKeyExist(keyPriority, keyList)
|
|
2685
|
+
);
|
|
2686
|
+
|
|
2687
|
+
// src/signers/memorySigner/keyPool/helpers/keyUtils.ts
|
|
2688
|
+
var createLock = (key) => () => {
|
|
2689
|
+
key.isLocked = true;
|
|
2690
|
+
console.log("Key locked", key.publicKey);
|
|
2691
|
+
};
|
|
2692
|
+
var createUnlock = (key) => () => {
|
|
2693
|
+
key.isLocked = false;
|
|
2694
|
+
console.log("Key unlocked", key.publicKey);
|
|
2695
|
+
};
|
|
2696
|
+
var createIncrementNonce = (key) => () => {
|
|
2697
|
+
key.nonce = key.nonce + 1;
|
|
2698
|
+
};
|
|
2699
|
+
|
|
2700
|
+
// src/signers/memorySigner/keyPool/getFullAccessKeyList.ts
|
|
2701
|
+
var transformKey2 = (fullAccessKey, keyPairs) => {
|
|
2702
|
+
const { publicKey, nonce } = fullAccessKey;
|
|
2703
|
+
const key = {
|
|
2704
|
+
type: "FullAccess",
|
|
2705
|
+
publicKey,
|
|
2706
|
+
privateKey: keyPairs[publicKey],
|
|
2707
|
+
isLocked: false,
|
|
2708
|
+
nonce
|
|
2709
|
+
};
|
|
2710
|
+
key.lock = createLock(key);
|
|
2711
|
+
key.unlock = createUnlock(key);
|
|
2712
|
+
key.incrementNonce = createIncrementNonce(key);
|
|
2713
|
+
return key;
|
|
2714
|
+
};
|
|
2715
|
+
var getFullAccessKeyList = (accountKeys, signerContext) => {
|
|
2716
|
+
const keyPairs = signerContext.keyService.getKeyPairs();
|
|
2717
|
+
return accountKeys.filter(
|
|
2718
|
+
({ publicKey, accessType }) => Object.hasOwn(keyPairs, publicKey) && accessType === "FullAccess"
|
|
2719
|
+
).map((key) => transformKey2(key, keyPairs));
|
|
2720
|
+
};
|
|
2721
|
+
|
|
2722
|
+
// src/signers/memorySigner/keyPool/getFunctionCallKeyList.ts
|
|
2723
|
+
var transformKey3 = (functionCallKey, keyPairs) => {
|
|
2724
|
+
const { publicKey, nonce, contractAccountId, allowedFunctions } = functionCallKey;
|
|
2725
|
+
const key = {
|
|
2726
|
+
type: "FunctionCall",
|
|
2727
|
+
// TODO Rename to accessType
|
|
2728
|
+
publicKey,
|
|
2729
|
+
privateKey: keyPairs[publicKey],
|
|
2730
|
+
isLocked: false,
|
|
2731
|
+
nonce,
|
|
2732
|
+
contractAccountId,
|
|
2733
|
+
allowedFunctions
|
|
2734
|
+
};
|
|
2735
|
+
key.lock = createLock(key);
|
|
2736
|
+
key.unlock = createUnlock(key);
|
|
2737
|
+
key.incrementNonce = createIncrementNonce(key);
|
|
2738
|
+
return key;
|
|
2739
|
+
};
|
|
2740
|
+
var getFunctionCallKeyList = (accountKeys, signerContext) => {
|
|
2741
|
+
const keyPairs = signerContext.keyService.getKeyPairs();
|
|
2742
|
+
return accountKeys.filter(
|
|
2743
|
+
({ publicKey, accessType }) => Object.hasOwn(keyPairs, publicKey) && accessType === "FunctionCall"
|
|
2744
|
+
).map((key) => transformKey3(key, keyPairs));
|
|
2745
|
+
};
|
|
2746
|
+
|
|
2747
|
+
// src/signers/memorySigner/keyPool/createKeyPool.ts
|
|
2748
|
+
var getAllowedSigningKeys = (signerContext, accountKeys) => {
|
|
2749
|
+
if (!signerContext.signingKeys) return accountKeys;
|
|
2750
|
+
const set = new Set(signerContext.signingKeys);
|
|
2751
|
+
return accountKeys.filter((key) => set.has(key.publicKey));
|
|
2752
|
+
};
|
|
2753
|
+
var createKeyPool = async (signerContext) => {
|
|
2754
|
+
const { accountKeys } = await signerContext.client.getAccountKeys({
|
|
2755
|
+
accountId: signerContext.signerAccountId
|
|
2756
|
+
});
|
|
2757
|
+
const filteredKeys = getAllowedSigningKeys(signerContext, accountKeys);
|
|
2758
|
+
const keyList = {
|
|
2759
|
+
fullAccess: getFullAccessKeyList(filteredKeys, signerContext),
|
|
2760
|
+
functionCall: getFunctionCallKeyList(filteredKeys, signerContext)
|
|
2761
|
+
};
|
|
2762
|
+
if (keyList.fullAccess.length === 0 && keyList.functionCall.length === 0)
|
|
2763
|
+
throw new Error("Cannot create a signer with no account keys");
|
|
2764
|
+
return {
|
|
2765
|
+
findKeyForTask: createFindKeyForTask(keyList),
|
|
2766
|
+
isKeyForTaskExist: createIsKeyForTaskExist(keyList)
|
|
2767
|
+
};
|
|
2768
|
+
};
|
|
2769
|
+
|
|
2770
|
+
// src/signers/memorySigner/taskQueue/createFindTaskForKey.ts
|
|
2771
|
+
var checkIfKeyMatchRequirements = (keyPriority, key) => {
|
|
2772
|
+
if (key.type !== keyPriority.type) return false;
|
|
2773
|
+
if (key.type === "FullAccess") return true;
|
|
2774
|
+
const isContractIdMatch = key.contractAccountId === keyPriority.contractAccountId;
|
|
2775
|
+
const isFnCallAllowed = key.allowedFunctions === void 0 || key.allowedFunctions.includes(keyPriority.calledFnName);
|
|
2776
|
+
return isContractIdMatch && isFnCallAllowed;
|
|
2777
|
+
};
|
|
2778
|
+
var createFindTaskForKey = (context) => (key) => context.queue.find(
|
|
2779
|
+
(task) => task.signingKeyPriority.some(
|
|
2780
|
+
(keyPriority) => checkIfKeyMatchRequirements(keyPriority, key)
|
|
2781
|
+
)
|
|
2782
|
+
);
|
|
2783
|
+
|
|
2784
|
+
// src/signers/memorySigner/taskQueue/addTask/helpers/getSigningKeyPriority.ts
|
|
2785
|
+
var getPriorityForFunctionCallTransaction = (action, receiverAccountId) => [
|
|
2786
|
+
{ type: "FullAccess" },
|
|
2787
|
+
{
|
|
2788
|
+
type: "FunctionCall",
|
|
2789
|
+
contractAccountId: receiverAccountId,
|
|
2790
|
+
calledFnName: action.params.functionName
|
|
2791
|
+
}
|
|
2792
|
+
];
|
|
2793
|
+
var getSigningKeyPriority = ({
|
|
2794
|
+
action,
|
|
2795
|
+
actions,
|
|
2796
|
+
receiverAccountId
|
|
2797
|
+
}) => {
|
|
2798
|
+
if (action?.actionType === "FunctionCall")
|
|
2799
|
+
return getPriorityForFunctionCallTransaction(action, receiverAccountId);
|
|
2800
|
+
if (actions?.length === 1 && actions[0].actionType === "FunctionCall")
|
|
2801
|
+
return getPriorityForFunctionCallTransaction(actions[0], receiverAccountId);
|
|
2802
|
+
return [{ type: "FullAccess" }];
|
|
2803
|
+
};
|
|
2804
|
+
|
|
2805
|
+
// src/signers/memorySigner/taskQueue/addTask/signTransaction.ts
|
|
2806
|
+
var createSignTransaction2 = (context) => async (transactionIntent) => {
|
|
2807
|
+
const { matcher, resolver } = context.signerContext;
|
|
2808
|
+
const task = {
|
|
2809
|
+
type: "SignTransaction",
|
|
2810
|
+
taskId: crypto.randomUUID(),
|
|
2811
|
+
signingKeyPriority: getSigningKeyPriority(transactionIntent),
|
|
2812
|
+
transactionIntent
|
|
2813
|
+
};
|
|
2814
|
+
matcher.canHandleTaskInFuture(task);
|
|
2815
|
+
context.addTask(task);
|
|
2816
|
+
queueMicrotask(() => {
|
|
2817
|
+
matcher.handleAddTask(task);
|
|
2818
|
+
});
|
|
2819
|
+
return resolver.waitForTask(task.taskId);
|
|
2820
|
+
};
|
|
2821
|
+
|
|
2822
|
+
// src/signers/memorySigner/taskQueue/addTask/executeTransaction.ts
|
|
2823
|
+
var createExecuteTransaction = (context) => async (args) => {
|
|
2824
|
+
const { matcher, resolver } = context.signerContext;
|
|
2825
|
+
const transactionIntent = {
|
|
2826
|
+
receiverAccountId: args.receiverAccountId,
|
|
2827
|
+
action: args.action,
|
|
2828
|
+
actions: args.actions
|
|
2829
|
+
};
|
|
2830
|
+
const task = {
|
|
2831
|
+
type: "ExecuteTransaction",
|
|
2832
|
+
taskId: crypto.randomUUID(),
|
|
2833
|
+
signingKeyPriority: getSigningKeyPriority(transactionIntent),
|
|
2834
|
+
transactionIntent
|
|
2835
|
+
};
|
|
2836
|
+
matcher.canHandleTaskInFuture(task);
|
|
2837
|
+
context.addTask(task);
|
|
2838
|
+
queueMicrotask(() => {
|
|
2839
|
+
matcher.handleAddTask(task);
|
|
2840
|
+
});
|
|
2841
|
+
return resolver.waitForTask(task.taskId);
|
|
2842
|
+
};
|
|
2843
|
+
|
|
2844
|
+
// src/signers/memorySigner/taskQueue/addTask/signMultipleTransactions.ts
|
|
2845
|
+
var createSignMultipleTransactions = (context) => async (args) => {
|
|
2846
|
+
const { transactionIntents } = args;
|
|
2847
|
+
const { signTransaction: signTransaction2 } = context.signerContext.taskQueue;
|
|
2848
|
+
const output = [];
|
|
2849
|
+
let failed = false;
|
|
2850
|
+
for (const intent of transactionIntents) {
|
|
2851
|
+
if (failed) {
|
|
2852
|
+
output.push({ status: "Canceled" });
|
|
2853
|
+
continue;
|
|
2854
|
+
}
|
|
2855
|
+
try {
|
|
2856
|
+
output.push({
|
|
2857
|
+
status: "Success",
|
|
2858
|
+
result: await signTransaction2(intent)
|
|
2859
|
+
});
|
|
2860
|
+
} catch (error) {
|
|
2861
|
+
output.push({ status: "Error", error });
|
|
2862
|
+
failed = true;
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
return output;
|
|
2866
|
+
};
|
|
2867
|
+
|
|
2868
|
+
// src/signers/memorySigner/taskQueue/addTask/executeMultipleTransactions.ts
|
|
2869
|
+
var createExecuteMultipleTransactions = (context) => async (args) => {
|
|
2870
|
+
const { transactionIntents } = args;
|
|
2871
|
+
const { executeTransaction: executeTransaction2 } = context.signerContext.taskQueue;
|
|
2872
|
+
const output = [];
|
|
2873
|
+
let failed = false;
|
|
2874
|
+
for (const intent of transactionIntents) {
|
|
2875
|
+
if (failed) {
|
|
2876
|
+
output.push({ status: "Canceled" });
|
|
2877
|
+
continue;
|
|
2878
|
+
}
|
|
2879
|
+
try {
|
|
2880
|
+
output.push({
|
|
2881
|
+
status: "Success",
|
|
2882
|
+
result: await executeTransaction2({ ...intent })
|
|
2883
|
+
});
|
|
2884
|
+
} catch (error) {
|
|
2885
|
+
output.push({ status: "Error", error });
|
|
2886
|
+
failed = true;
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
return output;
|
|
2890
|
+
};
|
|
2891
|
+
|
|
2892
|
+
// src/signers/memorySigner/taskQueue/createTaskQueue.ts
|
|
2893
|
+
var createTaskQueue = (signerContext) => {
|
|
2894
|
+
const context = {
|
|
2895
|
+
queue: [],
|
|
2896
|
+
cleaners: {},
|
|
2897
|
+
signerContext
|
|
2898
|
+
};
|
|
2899
|
+
context.addTask = (task) => {
|
|
2900
|
+
context.queue.push(task);
|
|
2901
|
+
context.cleaners[task.taskId] = setTimeout(() => {
|
|
2902
|
+
context.queue = context.queue.filter(
|
|
2903
|
+
({ taskId }) => taskId !== task.taskId
|
|
2904
|
+
);
|
|
2905
|
+
delete context.cleaners[task.taskId];
|
|
2906
|
+
context.signerContext.resolver.completeTask(task.taskId, {
|
|
2907
|
+
error: "Task execution was rejected after timeout"
|
|
2908
|
+
});
|
|
2909
|
+
}, context.signerContext.taskTtlMs);
|
|
2910
|
+
};
|
|
2911
|
+
const removeTask = (taskId) => {
|
|
2912
|
+
context.queue = context.queue.filter((task) => task.taskId !== taskId);
|
|
2913
|
+
clearTimeout(context.cleaners[taskId]);
|
|
2914
|
+
delete context.cleaners[taskId];
|
|
2915
|
+
};
|
|
2916
|
+
return {
|
|
2917
|
+
signTransaction: createSignTransaction2(context),
|
|
2918
|
+
signMultipleTransactions: createSignMultipleTransactions(context),
|
|
2919
|
+
executeTransaction: createExecuteTransaction(context),
|
|
2920
|
+
executeeMultipleTransactions: createExecuteMultipleTransactions(context),
|
|
2921
|
+
findTaskForKey: createFindTaskForKey(context),
|
|
2922
|
+
removeTask
|
|
2923
|
+
};
|
|
2924
|
+
};
|
|
2925
|
+
|
|
2926
|
+
// src/signers/memorySigner/executors/helpers/getSignedTransaction.ts
|
|
2927
|
+
var getSignedTransaction = (signerContext, task, key, nextNonce) => {
|
|
2928
|
+
const transaction = {
|
|
2929
|
+
...task.transactionIntent,
|
|
2930
|
+
signerAccountId: signerContext.signerAccountId,
|
|
2931
|
+
signerPublicKey: key.publicKey,
|
|
2932
|
+
nonce: nextNonce,
|
|
2933
|
+
blockHash: signerContext.state.getBlockHash()
|
|
2934
|
+
};
|
|
2935
|
+
const { transactionHash, u8TransactionHash } = getTransactionHash(transaction);
|
|
2936
|
+
const { signature } = sign({
|
|
2937
|
+
message: u8TransactionHash,
|
|
2938
|
+
privateKey: key.privateKey
|
|
2939
|
+
});
|
|
2940
|
+
return {
|
|
2941
|
+
transaction,
|
|
2942
|
+
transactionHash,
|
|
2943
|
+
signature
|
|
2944
|
+
};
|
|
2945
|
+
};
|
|
2946
|
+
|
|
2947
|
+
// src/signers/memorySigner/executors/signTransaction.ts
|
|
2948
|
+
var signTransaction = async (signerContext, task, key) => {
|
|
2949
|
+
try {
|
|
2950
|
+
const nextNonce = key.nonce + 1;
|
|
2951
|
+
const signedTransaction = getSignedTransaction(
|
|
2952
|
+
signerContext,
|
|
2953
|
+
task,
|
|
2954
|
+
key,
|
|
2955
|
+
nextNonce
|
|
2956
|
+
);
|
|
2957
|
+
key.incrementNonce();
|
|
2958
|
+
signerContext.resolver.completeTask(task.taskId, {
|
|
2959
|
+
result: signedTransaction
|
|
2960
|
+
});
|
|
2961
|
+
} catch (e) {
|
|
2962
|
+
signerContext.resolver.completeTask(task.taskId, { error: e });
|
|
2963
|
+
}
|
|
2964
|
+
};
|
|
2965
|
+
|
|
2966
|
+
// src/signers/memorySigner/executors/executeTransaction.ts
|
|
2967
|
+
var executeTransaction = async (signerContext, task, key) => {
|
|
2968
|
+
try {
|
|
2969
|
+
const nextNonce = key.nonce + 1;
|
|
2970
|
+
const signedTransaction = getSignedTransaction(
|
|
2971
|
+
signerContext,
|
|
2972
|
+
task,
|
|
2973
|
+
key,
|
|
2974
|
+
nextNonce
|
|
2975
|
+
);
|
|
2976
|
+
const result = await signerContext.client.sendSignedTransaction({
|
|
2977
|
+
signedTransaction
|
|
2978
|
+
});
|
|
2979
|
+
key.incrementNonce();
|
|
2980
|
+
signerContext.resolver.completeTask(task.taskId, {
|
|
2981
|
+
result
|
|
2982
|
+
});
|
|
2983
|
+
} catch (e) {
|
|
2984
|
+
signerContext.resolver.completeTask(task.taskId, { error: e });
|
|
2985
|
+
}
|
|
2986
|
+
};
|
|
2987
|
+
|
|
2988
|
+
// src/signers/memorySigner/matcher/createMatcher.ts
|
|
2989
|
+
var execute = (task) => {
|
|
2990
|
+
if (task.type === "SignTransaction") return signTransaction;
|
|
2991
|
+
if (task.type === "ExecuteTransaction") return executeTransaction;
|
|
2992
|
+
throw new Error("Unsupported task type");
|
|
2993
|
+
};
|
|
2994
|
+
var executeTask = async (signerContext, task, key) => {
|
|
2995
|
+
key.lock();
|
|
2996
|
+
signerContext.taskQueue.removeTask(task.taskId);
|
|
2997
|
+
await execute(task)(signerContext, task, key);
|
|
2998
|
+
key.unlock();
|
|
2999
|
+
void signerContext.matcher.handleKeyUnlock(key);
|
|
3000
|
+
};
|
|
3001
|
+
var createMatcher = (signerContext) => {
|
|
3002
|
+
const handleAddTask = async (task) => {
|
|
3003
|
+
const key = signerContext.keyPool.findKeyForTask(task);
|
|
3004
|
+
if (key) void executeTask(signerContext, task, key);
|
|
3005
|
+
};
|
|
3006
|
+
const handleKeyUnlock = async (key) => {
|
|
3007
|
+
const task = signerContext.taskQueue.findTaskForKey(key);
|
|
3008
|
+
if (task) void executeTask(signerContext, task, key);
|
|
3009
|
+
};
|
|
3010
|
+
const canHandleTaskInFuture = (task) => {
|
|
3011
|
+
const canHandle = signerContext.keyPool.isKeyForTaskExist(task);
|
|
3012
|
+
if (canHandle) return true;
|
|
3013
|
+
throw new Error(`There is no key, which can sigh the task`);
|
|
3014
|
+
};
|
|
3015
|
+
return {
|
|
3016
|
+
handleAddTask,
|
|
3017
|
+
handleKeyUnlock,
|
|
3018
|
+
canHandleTaskInFuture
|
|
3019
|
+
};
|
|
3020
|
+
};
|
|
3021
|
+
|
|
3022
|
+
// src/signers/memorySigner/resolver/createResolver.ts
|
|
3023
|
+
var createResolver = () => {
|
|
3024
|
+
const activeTasks = {};
|
|
3025
|
+
const waitForTask = (taskId) => new Promise((resolve, reject) => {
|
|
3026
|
+
activeTasks[taskId] = ({ result, error }) => {
|
|
3027
|
+
typeof error === "undefined" ? resolve(result) : reject(error);
|
|
3028
|
+
delete activeTasks[taskId];
|
|
3029
|
+
};
|
|
3030
|
+
});
|
|
3031
|
+
const completeTask = (taskId, data) => {
|
|
3032
|
+
activeTasks[taskId](data);
|
|
3033
|
+
};
|
|
3034
|
+
return {
|
|
3035
|
+
waitForTask,
|
|
3036
|
+
completeTask
|
|
3037
|
+
};
|
|
3038
|
+
};
|
|
3039
|
+
|
|
3040
|
+
// src/signers/memorySigner/state/createState.ts
|
|
3041
|
+
var fetchBlockHash = async (signerContext) => {
|
|
3042
|
+
const block = await signerContext.client.getBlock();
|
|
3043
|
+
return block.header.hash;
|
|
3044
|
+
};
|
|
3045
|
+
var createState = async (signerContext) => {
|
|
3046
|
+
const blockHash = await fetchBlockHash(signerContext);
|
|
3047
|
+
const state = {
|
|
3048
|
+
blockHash
|
|
3049
|
+
};
|
|
3050
|
+
const refetchBlockHashIntervalId = setInterval(async () => {
|
|
3051
|
+
state.blockHash = await fetchBlockHash(signerContext);
|
|
3052
|
+
}, RefetchBlockHashInterval);
|
|
3053
|
+
const clearIntervals = () => {
|
|
3054
|
+
clearInterval(refetchBlockHashIntervalId);
|
|
3055
|
+
};
|
|
3056
|
+
return {
|
|
3057
|
+
getBlockHash: () => state.blockHash,
|
|
3058
|
+
clearIntervals
|
|
3059
|
+
};
|
|
3060
|
+
};
|
|
3061
|
+
|
|
3062
|
+
// src/signers/memorySigner/createMemorySigner.ts
|
|
3063
|
+
var createMemorySigner = async (args) => {
|
|
3064
|
+
const context = {
|
|
3065
|
+
signerAccountId: args.signerAccountId,
|
|
3066
|
+
client: args.client,
|
|
3067
|
+
keyService: args.keyService,
|
|
3068
|
+
signingKeys: args?.keyPool?.signingKeys,
|
|
3069
|
+
taskTtlMs: args?.queue?.taskTtlMs ?? SignerTaskTtlMs
|
|
3070
|
+
};
|
|
3071
|
+
const [keyPool, state] = await Promise.all([
|
|
3072
|
+
createKeyPool(context),
|
|
3073
|
+
createState(context)
|
|
3074
|
+
]);
|
|
3075
|
+
context.keyPool = keyPool;
|
|
3076
|
+
context.state = state;
|
|
3077
|
+
context.taskQueue = createTaskQueue(context);
|
|
3078
|
+
context.matcher = createMatcher(context);
|
|
3079
|
+
context.resolver = createResolver();
|
|
3080
|
+
return {
|
|
3081
|
+
executeTransaction: context.taskQueue.executeTransaction,
|
|
3082
|
+
executeMultipleTransactions: context.taskQueue.executeeMultipleTransactions,
|
|
3083
|
+
signTransaction: context.taskQueue.signTransaction,
|
|
3084
|
+
signMultipleTransactions: context.taskQueue.signMultipleTransactions
|
|
3085
|
+
};
|
|
3086
|
+
};
|
|
3087
|
+
|
|
3088
|
+
// src/helpers/actionCreators/transfer.ts
|
|
3089
|
+
var transfer = (params) => ({
|
|
3090
|
+
actionType: "Transfer",
|
|
3091
|
+
params
|
|
3092
|
+
});
|
|
3093
|
+
|
|
3094
|
+
// src/helpers/actionCreators/createAccount.ts
|
|
3095
|
+
var createAccount = () => ({
|
|
3096
|
+
actionType: "CreateAccount"
|
|
3097
|
+
});
|
|
3098
|
+
|
|
3099
|
+
// src/helpers/actionCreators/addFullAccessKey.ts
|
|
3100
|
+
var addFullAccessKey = ({
|
|
3101
|
+
publicKey
|
|
3102
|
+
}) => ({
|
|
3103
|
+
actionType: "AddKey",
|
|
3104
|
+
params: {
|
|
3105
|
+
accessType: "FullAccess",
|
|
3106
|
+
publicKey
|
|
3107
|
+
}
|
|
3108
|
+
});
|
|
3109
|
+
|
|
3110
|
+
// src/helpers/actionCreators/addFunctionCallKey.ts
|
|
3111
|
+
var addFunctionCallKey = ({
|
|
3112
|
+
publicKey,
|
|
3113
|
+
contractAccountId,
|
|
3114
|
+
gasBudget,
|
|
3115
|
+
allowedFunctions
|
|
3116
|
+
}) => ({
|
|
3117
|
+
actionType: "AddKey",
|
|
3118
|
+
params: {
|
|
3119
|
+
accessType: "FunctionCall",
|
|
3120
|
+
publicKey,
|
|
3121
|
+
contractAccountId,
|
|
3122
|
+
gasBudget,
|
|
3123
|
+
allowedFunctions
|
|
3124
|
+
}
|
|
3125
|
+
});
|
|
3126
|
+
|
|
3127
|
+
// src/helpers/actionCreators/functionCall.ts
|
|
3128
|
+
var functionCall = (params) => ({
|
|
3129
|
+
actionType: "FunctionCall",
|
|
3130
|
+
params
|
|
3131
|
+
});
|
|
3132
|
+
|
|
3133
|
+
// src/helpers/actionCreators/deleteKey.ts
|
|
3134
|
+
var deleteKey = (params) => ({
|
|
3135
|
+
actionType: "DeleteKey",
|
|
3136
|
+
params
|
|
3137
|
+
});
|
|
3138
|
+
|
|
3139
|
+
// src/helpers/actionCreators/deleteAccount.ts
|
|
3140
|
+
var deleteAccount = (params) => ({
|
|
3141
|
+
actionType: "DeleteAccount",
|
|
3142
|
+
params
|
|
3143
|
+
});
|
|
3144
|
+
|
|
3145
|
+
// src/helpers/actionCreators/deployContract.ts
|
|
3146
|
+
var deployContract = (params) => ({
|
|
3147
|
+
actionType: "DeployContract",
|
|
3148
|
+
params
|
|
3149
|
+
});
|
|
3150
|
+
export {
|
|
3151
|
+
addFullAccessKey,
|
|
3152
|
+
addFunctionCallKey,
|
|
3153
|
+
createAccount,
|
|
3154
|
+
createClient,
|
|
3155
|
+
createMemoryKeyService,
|
|
3156
|
+
createMemorySigner,
|
|
3157
|
+
deleteAccount,
|
|
3158
|
+
deleteKey,
|
|
3159
|
+
deployContract,
|
|
3160
|
+
functionCall,
|
|
3161
|
+
gas,
|
|
3162
|
+
mainnet,
|
|
3163
|
+
near,
|
|
3164
|
+
teraGas,
|
|
3165
|
+
testnet,
|
|
3166
|
+
transfer,
|
|
3167
|
+
yoctoNear
|
|
3168
|
+
};
|
|
3169
|
+
//# sourceMappingURL=index.js.map
|