@fastnear/api 0.6.2 → 0.7.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/dist/cjs/index.cjs +5 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +132 -26
- package/dist/cjs/near.cjs +504 -0
- package/dist/cjs/near.cjs.map +1 -0
- package/dist/cjs/state.cjs +213 -0
- package/dist/cjs/state.cjs.map +1 -0
- package/dist/esm/index.d.ts +132 -26
- package/dist/esm/index.js +3 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/near.js +477 -0
- package/dist/esm/near.js.map +1 -0
- package/dist/esm/state.js +174 -0
- package/dist/esm/state.js.map +1 -0
- package/dist/umd/browser.global.js +584 -528
- package/dist/umd/browser.global.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR API - CJS (@fastnear/api version 0.6.3) */
|
|
2
|
+
/* https://www.npmjs.com/package/@fastnear/api/v/0.6.3 */
|
|
3
|
+
"use strict";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
var near_exports = {};
|
|
33
|
+
__export(near_exports, {
|
|
34
|
+
MaxBlockDelayMs: () => MaxBlockDelayMs,
|
|
35
|
+
accountId: () => accountId,
|
|
36
|
+
actions: () => actions,
|
|
37
|
+
afterTxSent: () => afterTxSent,
|
|
38
|
+
authStatus: () => authStatus,
|
|
39
|
+
config: () => config,
|
|
40
|
+
exp: () => exp,
|
|
41
|
+
generateTxId: () => generateTxId,
|
|
42
|
+
localTxHistory: () => localTxHistory,
|
|
43
|
+
publicKey: () => publicKey,
|
|
44
|
+
queryAccessKey: () => queryAccessKey,
|
|
45
|
+
queryAccount: () => queryAccount,
|
|
46
|
+
queryBlock: () => queryBlock,
|
|
47
|
+
queryRpc: () => queryRpc,
|
|
48
|
+
queryTx: () => queryTx,
|
|
49
|
+
requestSignIn: () => requestSignIn,
|
|
50
|
+
sendTx: () => sendTx,
|
|
51
|
+
sendTxToRpc: () => sendTxToRpc,
|
|
52
|
+
signOut: () => signOut,
|
|
53
|
+
utils: () => utils,
|
|
54
|
+
view: () => view,
|
|
55
|
+
withBlockId: () => withBlockId
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(near_exports);
|
|
58
|
+
var import_big = __toESM(require("big.js"), 1);
|
|
59
|
+
var import_utils = require("@fastnear/utils");
|
|
60
|
+
var import_state = require("./state.js");
|
|
61
|
+
var import_state2 = require("./state.js");
|
|
62
|
+
var import_sha2 = require("@noble/hashes/sha2");
|
|
63
|
+
var reExportAllUtils = __toESM(require("@fastnear/utils"), 1);
|
|
64
|
+
import_big.default.DP = 27;
|
|
65
|
+
const MaxBlockDelayMs = 1e3 * 60 * 60 * 6;
|
|
66
|
+
function withBlockId(params, blockId) {
|
|
67
|
+
if (blockId === "final" || blockId === "optimistic") {
|
|
68
|
+
return { ...params, finality: blockId };
|
|
69
|
+
}
|
|
70
|
+
return blockId ? { ...params, block_id: blockId } : { ...params, finality: "optimistic" };
|
|
71
|
+
}
|
|
72
|
+
__name(withBlockId, "withBlockId");
|
|
73
|
+
async function queryRpc(method, params) {
|
|
74
|
+
const config2 = (0, import_state2.getConfig)();
|
|
75
|
+
if (!config2?.nodeUrl) {
|
|
76
|
+
throw new Error("fastnear: getConfig() returned invalid config: missing nodeUrl.");
|
|
77
|
+
}
|
|
78
|
+
const response = await fetch(config2.nodeUrl, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: { "Content-Type": "application/json" },
|
|
81
|
+
body: JSON.stringify({
|
|
82
|
+
jsonrpc: "2.0",
|
|
83
|
+
id: `fastnear-${Date.now()}`,
|
|
84
|
+
method,
|
|
85
|
+
params
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
const result = await response.json();
|
|
89
|
+
if (result.error) {
|
|
90
|
+
throw new Error(JSON.stringify(result.error));
|
|
91
|
+
}
|
|
92
|
+
return result.result;
|
|
93
|
+
}
|
|
94
|
+
__name(queryRpc, "queryRpc");
|
|
95
|
+
function afterTxSent(txId) {
|
|
96
|
+
const txHistory = (0, import_state.getTxHistory)();
|
|
97
|
+
queryRpc("tx", {
|
|
98
|
+
tx_hash: txHistory[txId]?.txHash,
|
|
99
|
+
sender_account_id: txHistory[txId]?.tx?.signerId,
|
|
100
|
+
wait_until: "EXECUTED_OPTIMISTIC"
|
|
101
|
+
}).then((result) => {
|
|
102
|
+
const successValue = result?.status?.SuccessValue;
|
|
103
|
+
(0, import_state.updateTxHistory)({
|
|
104
|
+
txId,
|
|
105
|
+
status: "Executed",
|
|
106
|
+
result,
|
|
107
|
+
successValue: successValue ? (0, import_utils.tryParseJson)((0, import_utils.fromBase64)(successValue)) : void 0,
|
|
108
|
+
finalState: true
|
|
109
|
+
});
|
|
110
|
+
}).catch((error) => {
|
|
111
|
+
(0, import_state.updateTxHistory)({
|
|
112
|
+
txId,
|
|
113
|
+
status: "ErrorAfterIncluded",
|
|
114
|
+
error: (0, import_utils.tryParseJson)(error.message) ?? error.message,
|
|
115
|
+
finalState: true
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
__name(afterTxSent, "afterTxSent");
|
|
120
|
+
async function sendTxToRpc(signedTxBase64, waitUntil, txId) {
|
|
121
|
+
waitUntil = waitUntil || "INCLUDED";
|
|
122
|
+
try {
|
|
123
|
+
const sendTxRes = await queryRpc("send_tx", {
|
|
124
|
+
signed_tx_base64: signedTxBase64,
|
|
125
|
+
wait_until: waitUntil
|
|
126
|
+
});
|
|
127
|
+
(0, import_state.updateTxHistory)({ txId, status: "Included", finalState: false });
|
|
128
|
+
afterTxSent(txId);
|
|
129
|
+
return sendTxRes;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
132
|
+
(0, import_state.updateTxHistory)({
|
|
133
|
+
txId,
|
|
134
|
+
status: "Error",
|
|
135
|
+
error: (0, import_utils.tryParseJson)(errorMessage) ?? errorMessage,
|
|
136
|
+
finalState: false
|
|
137
|
+
});
|
|
138
|
+
throw new Error(errorMessage);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
__name(sendTxToRpc, "sendTxToRpc");
|
|
142
|
+
function generateTxId() {
|
|
143
|
+
const randomPart = crypto.getRandomValues(new Uint32Array(2)).join("");
|
|
144
|
+
return `tx-${Date.now()}-${parseInt(randomPart, 10).toString(36)}`;
|
|
145
|
+
}
|
|
146
|
+
__name(generateTxId, "generateTxId");
|
|
147
|
+
const accountId = /* @__PURE__ */ __name(() => import_state._state.accountId, "accountId");
|
|
148
|
+
const publicKey = /* @__PURE__ */ __name(() => import_state._state.publicKey, "publicKey");
|
|
149
|
+
const config = /* @__PURE__ */ __name((newConfig) => {
|
|
150
|
+
const current = (0, import_state2.getConfig)();
|
|
151
|
+
if (newConfig) {
|
|
152
|
+
if (newConfig.networkId && current.networkId !== newConfig.networkId) {
|
|
153
|
+
(0, import_state2.setConfig)(newConfig.networkId);
|
|
154
|
+
(0, import_state.updateState)({ accountId: null, privateKey: null, lastWalletId: null });
|
|
155
|
+
(0, import_utils.lsSet)("block", null);
|
|
156
|
+
(0, import_state2.resetTxHistory)();
|
|
157
|
+
}
|
|
158
|
+
(0, import_state2.setConfig)({ ...(0, import_state2.getConfig)(), ...newConfig });
|
|
159
|
+
}
|
|
160
|
+
return (0, import_state2.getConfig)();
|
|
161
|
+
}, "config");
|
|
162
|
+
const authStatus = /* @__PURE__ */ __name(() => {
|
|
163
|
+
if (!import_state._state.accountId) {
|
|
164
|
+
return "SignedOut";
|
|
165
|
+
}
|
|
166
|
+
return "SignedIn";
|
|
167
|
+
}, "authStatus");
|
|
168
|
+
const requestSignIn = /* @__PURE__ */ __name(async ({ contractId }) => {
|
|
169
|
+
const privateKey = (0, import_utils.privateKeyFromRandom)();
|
|
170
|
+
(0, import_state.updateState)({ accessKeyContractId: contractId, accountId: null, privateKey });
|
|
171
|
+
const pubKey = (0, import_utils.publicKeyFromPrivate)(privateKey);
|
|
172
|
+
const result = await import_state._adapter.signIn({
|
|
173
|
+
networkId: (0, import_state2.getConfig)().networkId,
|
|
174
|
+
contractId,
|
|
175
|
+
publicKey: pubKey
|
|
176
|
+
});
|
|
177
|
+
if (result.error) {
|
|
178
|
+
throw new Error(`Wallet error: ${result.error}`);
|
|
179
|
+
}
|
|
180
|
+
if (result.url) {
|
|
181
|
+
if (typeof window !== "undefined") {
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
window.location.href = result.url;
|
|
184
|
+
}, 100);
|
|
185
|
+
}
|
|
186
|
+
} else if (result.accountId) {
|
|
187
|
+
(0, import_state.updateState)({ accountId: result.accountId });
|
|
188
|
+
}
|
|
189
|
+
}, "requestSignIn");
|
|
190
|
+
const view = /* @__PURE__ */ __name(async ({
|
|
191
|
+
contractId,
|
|
192
|
+
methodName,
|
|
193
|
+
args,
|
|
194
|
+
argsBase64,
|
|
195
|
+
blockId
|
|
196
|
+
}) => {
|
|
197
|
+
const encodedArgs = argsBase64 || (args ? (0, import_utils.toBase64)(JSON.stringify(args)) : "");
|
|
198
|
+
const result = await queryRpc(
|
|
199
|
+
"query",
|
|
200
|
+
withBlockId(
|
|
201
|
+
{
|
|
202
|
+
request_type: "call_function",
|
|
203
|
+
account_id: contractId,
|
|
204
|
+
method_name: methodName,
|
|
205
|
+
args_base64: encodedArgs
|
|
206
|
+
},
|
|
207
|
+
blockId
|
|
208
|
+
)
|
|
209
|
+
);
|
|
210
|
+
return (0, import_utils.parseJsonFromBytes)(result.result);
|
|
211
|
+
}, "view");
|
|
212
|
+
const queryAccount = /* @__PURE__ */ __name(async ({
|
|
213
|
+
accountId: accountId2,
|
|
214
|
+
blockId
|
|
215
|
+
}) => {
|
|
216
|
+
return queryRpc(
|
|
217
|
+
"query",
|
|
218
|
+
withBlockId({ request_type: "view_account", account_id: accountId2 }, blockId)
|
|
219
|
+
);
|
|
220
|
+
}, "queryAccount");
|
|
221
|
+
const queryBlock = /* @__PURE__ */ __name(async ({ blockId }) => {
|
|
222
|
+
return queryRpc("block", withBlockId({}, blockId));
|
|
223
|
+
}, "queryBlock");
|
|
224
|
+
const queryAccessKey = /* @__PURE__ */ __name(async ({
|
|
225
|
+
accountId: accountId2,
|
|
226
|
+
publicKey: publicKey2,
|
|
227
|
+
blockId
|
|
228
|
+
}) => {
|
|
229
|
+
return queryRpc(
|
|
230
|
+
"query",
|
|
231
|
+
withBlockId(
|
|
232
|
+
{ request_type: "view_access_key", account_id: accountId2, public_key: publicKey2 },
|
|
233
|
+
blockId
|
|
234
|
+
)
|
|
235
|
+
);
|
|
236
|
+
}, "queryAccessKey");
|
|
237
|
+
const queryTx = /* @__PURE__ */ __name(async ({ txHash, accountId: accountId2 }) => {
|
|
238
|
+
return queryRpc("tx", [txHash, accountId2]);
|
|
239
|
+
}, "queryTx");
|
|
240
|
+
const localTxHistory = /* @__PURE__ */ __name(() => {
|
|
241
|
+
return (0, import_state.getTxHistory)();
|
|
242
|
+
}, "localTxHistory");
|
|
243
|
+
const signOut = /* @__PURE__ */ __name(() => {
|
|
244
|
+
(0, import_state.updateState)({ accountId: null, privateKey: null, contractId: null });
|
|
245
|
+
(0, import_state2.setConfig)(import_state.NETWORKS[import_state.DEFAULT_NETWORK_ID]);
|
|
246
|
+
}, "signOut");
|
|
247
|
+
const sendTx = /* @__PURE__ */ __name(async ({
|
|
248
|
+
receiverId,
|
|
249
|
+
actions: actions2,
|
|
250
|
+
waitUntil
|
|
251
|
+
}) => {
|
|
252
|
+
const signerId = import_state._state.accountId;
|
|
253
|
+
if (!signerId) throw new Error("Must sign in");
|
|
254
|
+
const publicKey2 = import_state._state.publicKey ?? "";
|
|
255
|
+
const privKey = import_state._state.privateKey;
|
|
256
|
+
const txId = generateTxId();
|
|
257
|
+
if (!privKey || receiverId !== import_state._state.accessKeyContractId || !(0, import_utils.canSignWithLAK)(actions2)) {
|
|
258
|
+
const jsonTx = { signerId, receiverId, actions: actions2 };
|
|
259
|
+
(0, import_state.updateTxHistory)({ status: "Pending", txId, tx: jsonTx, finalState: false });
|
|
260
|
+
const url = new URL(typeof window !== "undefined" ? window.location.href : "");
|
|
261
|
+
url.searchParams.set("txIds", txId);
|
|
262
|
+
try {
|
|
263
|
+
const result = await import_state._adapter.sendTransactions({
|
|
264
|
+
transactions: [jsonTx],
|
|
265
|
+
callbackUrl: url.toString()
|
|
266
|
+
});
|
|
267
|
+
if (result.url) {
|
|
268
|
+
if (typeof window !== "undefined") {
|
|
269
|
+
setTimeout(() => {
|
|
270
|
+
window.location.href = result.url;
|
|
271
|
+
}, 100);
|
|
272
|
+
}
|
|
273
|
+
} else if (result.outcomes?.length) {
|
|
274
|
+
result.outcomes.forEach(
|
|
275
|
+
(r) => (0, import_state.updateTxHistory)({
|
|
276
|
+
txId,
|
|
277
|
+
status: "Executed",
|
|
278
|
+
result: r,
|
|
279
|
+
txHash: r.transaction.hash,
|
|
280
|
+
finalState: true
|
|
281
|
+
})
|
|
282
|
+
);
|
|
283
|
+
} else if (result.rejected) {
|
|
284
|
+
(0, import_state.updateTxHistory)({ txId, status: "RejectedByUser", finalState: true });
|
|
285
|
+
} else if (result.error) {
|
|
286
|
+
(0, import_state.updateTxHistory)({
|
|
287
|
+
txId,
|
|
288
|
+
status: "Error",
|
|
289
|
+
error: (0, import_utils.tryParseJson)(result.error),
|
|
290
|
+
finalState: true
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return result;
|
|
294
|
+
} catch (err) {
|
|
295
|
+
console.error("fastnear: error sending tx using adapter:", err);
|
|
296
|
+
(0, import_state.updateTxHistory)({
|
|
297
|
+
txId,
|
|
298
|
+
status: "Error",
|
|
299
|
+
error: (0, import_utils.tryParseJson)(err.message),
|
|
300
|
+
finalState: true
|
|
301
|
+
});
|
|
302
|
+
return Promise.reject(err);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
let nonce = (0, import_utils.lsGet)("nonce");
|
|
306
|
+
if (nonce == null) {
|
|
307
|
+
const accessKey = await queryAccessKey({ accountId: signerId, publicKey: publicKey2 });
|
|
308
|
+
if (accessKey.error) {
|
|
309
|
+
throw new Error(`Access key error: ${accessKey.error} when attempting to get nonce for ${signerId} for public key ${publicKey2}`);
|
|
310
|
+
}
|
|
311
|
+
nonce = accessKey.nonce;
|
|
312
|
+
(0, import_utils.lsSet)("nonce", nonce);
|
|
313
|
+
}
|
|
314
|
+
let lastKnownBlock = (0, import_utils.lsGet)("block");
|
|
315
|
+
if (!lastKnownBlock || parseFloat(lastKnownBlock.header.timestamp_nanosec) / 1e6 + MaxBlockDelayMs < Date.now()) {
|
|
316
|
+
const latestBlock = await queryBlock({ blockId: "final" });
|
|
317
|
+
lastKnownBlock = {
|
|
318
|
+
header: {
|
|
319
|
+
prev_hash: latestBlock.header.prev_hash,
|
|
320
|
+
timestamp_nanosec: latestBlock.header.timestamp_nanosec
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
(0, import_utils.lsSet)("block", lastKnownBlock);
|
|
324
|
+
}
|
|
325
|
+
nonce += 1;
|
|
326
|
+
(0, import_utils.lsSet)("nonce", nonce);
|
|
327
|
+
const blockHash = lastKnownBlock.header.prev_hash;
|
|
328
|
+
const plainTransactionObj = {
|
|
329
|
+
signerId,
|
|
330
|
+
publicKey: publicKey2,
|
|
331
|
+
nonce,
|
|
332
|
+
receiverId,
|
|
333
|
+
blockHash,
|
|
334
|
+
actions: actions2
|
|
335
|
+
};
|
|
336
|
+
const txBytes = (0, import_utils.serializeTransaction)(plainTransactionObj);
|
|
337
|
+
const txHashBytes = (0, import_sha2.sha256)(txBytes);
|
|
338
|
+
const txHash58 = (0, import_utils.toBase58)(txHashBytes);
|
|
339
|
+
const signatureBase58 = (0, import_utils.signHash)(txHashBytes, privKey, { returnBase58: true });
|
|
340
|
+
const signedTransactionBytes = (0, import_utils.serializeSignedTransaction)(plainTransactionObj, signatureBase58);
|
|
341
|
+
const signedTxBase64 = (0, import_utils.bytesToBase64)(signedTransactionBytes);
|
|
342
|
+
(0, import_state.updateTxHistory)({
|
|
343
|
+
status: "Pending",
|
|
344
|
+
txId,
|
|
345
|
+
tx: plainTransactionObj,
|
|
346
|
+
signature: signatureBase58,
|
|
347
|
+
signedTxBase64,
|
|
348
|
+
txHash: txHash58,
|
|
349
|
+
finalState: false
|
|
350
|
+
});
|
|
351
|
+
try {
|
|
352
|
+
return await sendTxToRpc(signedTxBase64, waitUntil, txId);
|
|
353
|
+
} catch (error) {
|
|
354
|
+
console.error("Error Sending Transaction:", error, plainTransactionObj, signedTxBase64);
|
|
355
|
+
}
|
|
356
|
+
}, "sendTx");
|
|
357
|
+
const exp = {
|
|
358
|
+
utils: {},
|
|
359
|
+
// we will map this in a moment, giving keys, for IDE hints
|
|
360
|
+
borsh: reExportAllUtils.exp.borsh,
|
|
361
|
+
borshSchema: reExportAllUtils.exp.borshSchema.getBorshSchema()
|
|
362
|
+
};
|
|
363
|
+
for (const key in reExportAllUtils) {
|
|
364
|
+
exp.utils[key] = reExportAllUtils[key];
|
|
365
|
+
}
|
|
366
|
+
const utils = exp.utils;
|
|
367
|
+
try {
|
|
368
|
+
if (typeof window !== "undefined") {
|
|
369
|
+
const url = new URL(window.location.href);
|
|
370
|
+
const accId = url.searchParams.get("account_id");
|
|
371
|
+
const pubKey = url.searchParams.get("public_key");
|
|
372
|
+
const errCode = url.searchParams.get("errorCode");
|
|
373
|
+
const errMsg = url.searchParams.get("errorMessage");
|
|
374
|
+
const txHashes = url.searchParams.get("transactionHashes");
|
|
375
|
+
const txIds = url.searchParams.get("txIds");
|
|
376
|
+
if (errCode || errMsg) {
|
|
377
|
+
console.warn(new Error(`Wallet error: ${errCode} ${errMsg}`));
|
|
378
|
+
}
|
|
379
|
+
if (accId && pubKey) {
|
|
380
|
+
if (pubKey === import_state._state.publicKey) {
|
|
381
|
+
(0, import_state.updateState)({ accountId: accId });
|
|
382
|
+
} else {
|
|
383
|
+
console.error(new Error("Public key mismatch from wallet redirect"), pubKey, import_state._state.publicKey);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (txHashes || txIds) {
|
|
387
|
+
const hashArr = txHashes ? txHashes.split(",") : [];
|
|
388
|
+
const idArr = txIds ? txIds.split(",") : [];
|
|
389
|
+
if (idArr.length > hashArr.length) {
|
|
390
|
+
idArr.forEach((id) => {
|
|
391
|
+
(0, import_state.updateTxHistory)({ txId: id, status: "RejectedByUser", finalState: true });
|
|
392
|
+
});
|
|
393
|
+
} else if (idArr.length === hashArr.length) {
|
|
394
|
+
idArr.forEach((id, i) => {
|
|
395
|
+
(0, import_state.updateTxHistory)({
|
|
396
|
+
txId: id,
|
|
397
|
+
status: "PendingGotTxHash",
|
|
398
|
+
txHash: hashArr[i],
|
|
399
|
+
finalState: false
|
|
400
|
+
});
|
|
401
|
+
afterTxSent(id);
|
|
402
|
+
});
|
|
403
|
+
} else {
|
|
404
|
+
console.error(new Error("Transaction hash mismatch from wallet redirect"), idArr, hashArr);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
url.searchParams.delete("account_id");
|
|
408
|
+
url.searchParams.delete("public_key");
|
|
409
|
+
url.searchParams.delete("errorCode");
|
|
410
|
+
url.searchParams.delete("errorMessage");
|
|
411
|
+
url.searchParams.delete("all_keys");
|
|
412
|
+
url.searchParams.delete("transactionHashes");
|
|
413
|
+
url.searchParams.delete("txIds");
|
|
414
|
+
window.history.replaceState({}, "", url.toString());
|
|
415
|
+
}
|
|
416
|
+
} catch (e) {
|
|
417
|
+
console.error("Error handling wallet redirect:", e);
|
|
418
|
+
}
|
|
419
|
+
const actions = {
|
|
420
|
+
functionCall: /* @__PURE__ */ __name(({
|
|
421
|
+
methodName,
|
|
422
|
+
gas,
|
|
423
|
+
deposit,
|
|
424
|
+
args,
|
|
425
|
+
argsBase64
|
|
426
|
+
}) => ({
|
|
427
|
+
type: "FunctionCall",
|
|
428
|
+
methodName,
|
|
429
|
+
args,
|
|
430
|
+
argsBase64,
|
|
431
|
+
gas,
|
|
432
|
+
deposit
|
|
433
|
+
}), "functionCall"),
|
|
434
|
+
transfer: /* @__PURE__ */ __name((yoctoAmount) => ({
|
|
435
|
+
type: "Transfer",
|
|
436
|
+
deposit: yoctoAmount
|
|
437
|
+
}), "transfer"),
|
|
438
|
+
stakeNEAR: /* @__PURE__ */ __name(({ amount, publicKey: publicKey2 }) => ({
|
|
439
|
+
type: "Stake",
|
|
440
|
+
stake: amount,
|
|
441
|
+
publicKey: publicKey2
|
|
442
|
+
}), "stakeNEAR"),
|
|
443
|
+
addFullAccessKey: /* @__PURE__ */ __name(({ publicKey: publicKey2 }) => ({
|
|
444
|
+
type: "AddKey",
|
|
445
|
+
publicKey: publicKey2,
|
|
446
|
+
accessKey: { permission: "FullAccess" }
|
|
447
|
+
}), "addFullAccessKey"),
|
|
448
|
+
addLimitedAccessKey: /* @__PURE__ */ __name(({
|
|
449
|
+
publicKey: publicKey2,
|
|
450
|
+
allowance,
|
|
451
|
+
accountId: accountId2,
|
|
452
|
+
methodNames
|
|
453
|
+
}) => ({
|
|
454
|
+
type: "AddKey",
|
|
455
|
+
publicKey: publicKey2,
|
|
456
|
+
accessKey: {
|
|
457
|
+
permission: "FunctionCall",
|
|
458
|
+
allowance,
|
|
459
|
+
receiverId: accountId2,
|
|
460
|
+
methodNames
|
|
461
|
+
}
|
|
462
|
+
}), "addLimitedAccessKey"),
|
|
463
|
+
deleteKey: /* @__PURE__ */ __name(({ publicKey: publicKey2 }) => ({
|
|
464
|
+
type: "DeleteKey",
|
|
465
|
+
publicKey: publicKey2
|
|
466
|
+
}), "deleteKey"),
|
|
467
|
+
deleteAccount: /* @__PURE__ */ __name(({ beneficiaryId }) => ({
|
|
468
|
+
type: "DeleteAccount",
|
|
469
|
+
beneficiaryId
|
|
470
|
+
}), "deleteAccount"),
|
|
471
|
+
createAccount: /* @__PURE__ */ __name(() => ({
|
|
472
|
+
type: "CreateAccount"
|
|
473
|
+
}), "createAccount"),
|
|
474
|
+
deployContract: /* @__PURE__ */ __name(({ codeBase64 }) => ({
|
|
475
|
+
type: "DeployContract",
|
|
476
|
+
codeBase64
|
|
477
|
+
}), "deployContract")
|
|
478
|
+
};
|
|
479
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
480
|
+
0 && (module.exports = {
|
|
481
|
+
MaxBlockDelayMs,
|
|
482
|
+
accountId,
|
|
483
|
+
actions,
|
|
484
|
+
afterTxSent,
|
|
485
|
+
authStatus,
|
|
486
|
+
config,
|
|
487
|
+
exp,
|
|
488
|
+
generateTxId,
|
|
489
|
+
localTxHistory,
|
|
490
|
+
publicKey,
|
|
491
|
+
queryAccessKey,
|
|
492
|
+
queryAccount,
|
|
493
|
+
queryBlock,
|
|
494
|
+
queryRpc,
|
|
495
|
+
queryTx,
|
|
496
|
+
requestSignIn,
|
|
497
|
+
sendTx,
|
|
498
|
+
sendTxToRpc,
|
|
499
|
+
signOut,
|
|
500
|
+
utils,
|
|
501
|
+
view,
|
|
502
|
+
withBlockId
|
|
503
|
+
});
|
|
504
|
+
//# sourceMappingURL=near.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/near.ts"],"sourcesContent":["import Big from \"big.js\";\nimport {\n lsSet,\n lsGet,\n tryParseJson,\n fromBase64,\n toBase64,\n canSignWithLAK,\n toBase58,\n parseJsonFromBytes,\n signHash,\n publicKeyFromPrivate,\n privateKeyFromRandom,\n serializeTransaction,\n serializeSignedTransaction, bytesToBase64, PlainTransaction,\n} from \"@fastnear/utils\";\n\nimport {\n _adapter,\n _state,\n DEFAULT_NETWORK_ID,\n NETWORKS,\n getTxHistory,\n updateState,\n updateTxHistory,\n} from \"./state.js\";\n\nimport {\n getConfig,\n setConfig,\n resetTxHistory,\n} from \"./state.js\";\n\nimport { sha256 } from \"@noble/hashes/sha2\";\nimport * as reExportAllUtils from \"@fastnear/utils\";\n\nBig.DP = 27;\nexport const MaxBlockDelayMs = 1000 * 60 * 60 * 6; // 6 hours\n\ninterface AccessKeyWithError {\n nonce: number;\n permission?: any;\n error?: string;\n}\n\ninterface WalletTxResult {\n url?: string;\n outcomes?: Array<{ transaction: { hash: string } }>;\n rejected?: boolean;\n error?: string;\n}\n\ninterface BlockView {\n header: {\n prev_hash: string;\n timestamp_nanosec: string;\n };\n}\n\nexport function withBlockId(params: Record<string, any>, blockId?: string) {\n if (blockId === \"final\" || blockId === \"optimistic\") {\n return { ...params, finality: blockId };\n }\n return blockId ? { ...params, block_id: blockId } : { ...params, finality: \"optimistic\" };\n}\n\nexport async function queryRpc(method: string, params: Record<string, any> | any[]) {\n const config = getConfig();\n if (!config?.nodeUrl) {\n throw new Error(\"fastnear: getConfig() returned invalid config: missing nodeUrl.\");\n }\n const response = await fetch(config.nodeUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: `fastnear-${Date.now()}`,\n method,\n params,\n }),\n });\n const result = await response.json();\n if (result.error) {\n throw new Error(JSON.stringify(result.error));\n }\n return result.result;\n}\n\nexport function afterTxSent(txId: string) {\n const txHistory = getTxHistory();\n queryRpc(\"tx\", {\n tx_hash: txHistory[txId]?.txHash,\n sender_account_id: txHistory[txId]?.tx?.signerId,\n wait_until: \"EXECUTED_OPTIMISTIC\",\n })\n .then((result) => {\n const successValue = result?.status?.SuccessValue;\n updateTxHistory({\n txId,\n status: \"Executed\",\n result,\n successValue: successValue ? tryParseJson(fromBase64(successValue)) : undefined,\n finalState: true,\n });\n })\n .catch((error) => {\n updateTxHistory({\n txId,\n status: \"ErrorAfterIncluded\",\n error: tryParseJson(error.message) ?? error.message,\n finalState: true,\n });\n });\n}\n\nexport async function sendTxToRpc(signedTxBase64: string, waitUntil: string | undefined, txId: string) {\n // default to \"INCLUDED\"\n // see options: https://docs.near.org/api/rpc/transactions#tx-status-result\n waitUntil = waitUntil || \"INCLUDED\";\n\n try {\n const sendTxRes = await queryRpc(\"send_tx\", {\n signed_tx_base64: signedTxBase64,\n wait_until: waitUntil,\n });\n\n updateTxHistory({ txId, status: \"Included\", finalState: false });\n afterTxSent(txId);\n\n return sendTxRes;\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n updateTxHistory({\n txId,\n status: \"Error\",\n error: tryParseJson(errorMessage) ?? errorMessage,\n finalState: false,\n });\n throw new Error(errorMessage);\n }\n}\n\nexport interface AccessKeyView {\n nonce: number;\n permission: any;\n}\n\n/**\n * Generates a mock transaction ID.\n *\n * This function creates a pseudo-unique transaction ID for testing or\n * non-production use. It combines the current timestamp with a\n * random component for uniqueness.\n *\n * **Note:** This is not cryptographically secure and should not be used\n * for actual transaction processing.\n *\n * @returns {string} A mock transaction ID in the format `tx-{timestamp}-{random}`\n */\nexport function generateTxId(): string {\n const randomPart = crypto.getRandomValues(new Uint32Array(2)).join(\"\");\n return `tx-${Date.now()}-${parseInt(randomPart, 10).toString(36)}`;\n}\n\nexport const accountId = () => _state.accountId;\nexport const publicKey = () => _state.publicKey;\n\nexport const config = (newConfig?: Record<string, any>) => {\n const current = getConfig();\n if (newConfig) {\n if (newConfig.networkId && current.networkId !== newConfig.networkId) {\n setConfig(newConfig.networkId);\n updateState({ accountId: null, privateKey: null, lastWalletId: null });\n lsSet(\"block\", null);\n resetTxHistory();\n }\n setConfig({ ...getConfig(), ...newConfig });\n }\n return getConfig();\n};\n\nexport const authStatus = (): string | Record<string, any> => {\n if (!_state.accountId) {\n return \"SignedOut\";\n }\n return \"SignedIn\";\n};\n\nexport const requestSignIn = async ({ contractId }: { contractId: string }) => {\n const privateKey = privateKeyFromRandom();\n updateState({ accessKeyContractId: contractId, accountId: null, privateKey });\n const pubKey = publicKeyFromPrivate(privateKey);\n\n const result = await _adapter.signIn({\n networkId: getConfig().networkId,\n contractId,\n publicKey: pubKey,\n });\n\n if (result.error) {\n throw new Error(`Wallet error: ${result.error}`);\n }\n if (result.url) {\n if (typeof window !== \"undefined\") {\n setTimeout(() => {\n window.location.href = result.url;\n }, 100);\n }\n } else if (result.accountId) {\n updateState({ accountId: result.accountId });\n }\n};\n\nexport const view = async ({\n contractId,\n methodName,\n args,\n argsBase64,\n blockId,\n }: {\n contractId: string;\n methodName: string;\n args?: any;\n argsBase64?: string;\n blockId?: string;\n}) => {\n const encodedArgs = argsBase64 || (args ? toBase64(JSON.stringify(args)) : \"\");\n const result = await queryRpc(\n \"query\",\n withBlockId(\n {\n request_type: \"call_function\",\n account_id: contractId,\n method_name: methodName,\n args_base64: encodedArgs,\n },\n blockId\n )\n );\n return parseJsonFromBytes(result.result);\n};\n\nexport const queryAccount = async ({\n accountId,\n blockId,\n }: {\n accountId: string;\n blockId?: string;\n}) => {\n return queryRpc(\n \"query\",\n withBlockId({ request_type: \"view_account\", account_id: accountId }, blockId)\n );\n};\n\nexport const queryBlock = async ({ blockId }: { blockId?: string }): Promise<BlockView> => {\n return queryRpc(\"block\", withBlockId({}, blockId));\n};\n\nexport const queryAccessKey = async ({\n accountId,\n publicKey,\n blockId,\n }: {\n accountId: string;\n publicKey: string;\n blockId?: string;\n}): Promise<AccessKeyWithError> => {\n return queryRpc(\n \"query\",\n withBlockId(\n { request_type: \"view_access_key\", account_id: accountId, public_key: publicKey },\n blockId\n )\n );\n};\n\nexport const queryTx = async ({ txHash, accountId }: { txHash: string; accountId: string }) => {\n return queryRpc(\"tx\", [txHash, accountId]);\n};\n\nexport const localTxHistory = () => {\n return getTxHistory();\n};\n\nexport const signOut = () => {\n updateState({ accountId: null, privateKey: null, contractId: null });\n setConfig(NETWORKS[DEFAULT_NETWORK_ID]);\n};\n\nexport const sendTx = async ({\n receiverId,\n actions,\n waitUntil,\n }: {\n receiverId: string;\n actions: any[];\n waitUntil?: string;\n}) => {\n const signerId = _state.accountId;\n if (!signerId) throw new Error(\"Must sign in\");\n\n const publicKey = _state.publicKey ?? \"\";\n const privKey = _state.privateKey;\n // this generates a mock transaction ID so we can keep track of each tx\n const txId = generateTxId();\n\n if (!privKey || receiverId !== _state.accessKeyContractId || !canSignWithLAK(actions)) {\n const jsonTx = { signerId, receiverId, actions };\n updateTxHistory({ status: \"Pending\", txId, tx: jsonTx, finalState: false });\n\n const url = new URL(typeof window !== \"undefined\" ? window.location.href : \"\");\n url.searchParams.set(\"txIds\", txId);\n\n try {\n const result: WalletTxResult = await _adapter.sendTransactions({\n transactions: [jsonTx],\n callbackUrl: url.toString(),\n });\n\n if (result.url) {\n if (typeof window !== \"undefined\") {\n setTimeout(() => {\n window.location.href = result.url!;\n }, 100);\n }\n } else if (result.outcomes?.length) {\n result.outcomes.forEach((r) =>\n updateTxHistory({\n txId,\n status: \"Executed\",\n result: r,\n txHash: r.transaction.hash,\n finalState: true,\n })\n );\n } else if (result.rejected) {\n updateTxHistory({ txId, status: \"RejectedByUser\", finalState: true });\n } else if (result.error) {\n updateTxHistory({\n txId,\n status: \"Error\",\n error: tryParseJson(result.error),\n finalState: true,\n });\n }\n\n return result;\n } catch (err) {\n console.error('fastnear: error sending tx using adapter:', err)\n updateTxHistory({\n txId,\n status: \"Error\",\n error: tryParseJson((err as Error).message),\n finalState: true,\n });\n\n return Promise.reject(err);\n }\n }\n\n //\n let nonce = lsGet(\"nonce\") as number | null;\n if (nonce == null) {\n const accessKey = await queryAccessKey({ accountId: signerId, publicKey: publicKey });\n if (accessKey.error) {\n throw new Error(`Access key error: ${accessKey.error} when attempting to get nonce for ${signerId} for public key ${publicKey}`);\n }\n nonce = accessKey.nonce;\n lsSet(\"nonce\", nonce);\n }\n\n let lastKnownBlock = lsGet(\"block\") as BlockView | null;\n if (\n !lastKnownBlock ||\n parseFloat(lastKnownBlock.header.timestamp_nanosec) / 1e6 + MaxBlockDelayMs < Date.now()\n ) {\n const latestBlock = await queryBlock({ blockId: \"final\" });\n lastKnownBlock = {\n header: {\n prev_hash: latestBlock.header.prev_hash,\n timestamp_nanosec: latestBlock.header.timestamp_nanosec,\n },\n };\n lsSet(\"block\", lastKnownBlock);\n }\n\n nonce += 1;\n lsSet(\"nonce\", nonce);\n\n const blockHash = lastKnownBlock.header.prev_hash;\n\n const plainTransactionObj: PlainTransaction = {\n signerId,\n publicKey,\n nonce,\n receiverId,\n blockHash,\n actions,\n };\n\n const txBytes = serializeTransaction(plainTransactionObj);\n const txHashBytes = sha256(txBytes);\n const txHash58 = toBase58(txHashBytes);\n\n const signatureBase58 = signHash(txHashBytes, privKey, { returnBase58: true });\n const signedTransactionBytes = serializeSignedTransaction(plainTransactionObj, signatureBase58);\n const signedTxBase64 = bytesToBase64(signedTransactionBytes);\n\n updateTxHistory({\n status: \"Pending\",\n txId,\n tx: plainTransactionObj,\n signature: signatureBase58,\n signedTxBase64,\n txHash: txHash58,\n finalState: false,\n });\n\n try {\n return await sendTxToRpc(signedTxBase64, waitUntil, txId);\n } catch (error) {\n console.error(\"Error Sending Transaction:\", error, plainTransactionObj, signedTxBase64);\n }\n};\n\n// exports\nexport const exp = {\n utils: {}, // we will map this in a moment, giving keys, for IDE hints\n borsh: reExportAllUtils.exp.borsh,\n borshSchema: reExportAllUtils.exp.borshSchema.getBorshSchema(),\n};\n\nfor (const key in reExportAllUtils) {\n exp.utils[key] = reExportAllUtils[key];\n}\n\nexport const utils = exp.utils;\n\n// Wallet redirect handling\ntry {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const accId = url.searchParams.get(\"account_id\");\n const pubKey = url.searchParams.get(\"public_key\");\n const errCode = url.searchParams.get(\"errorCode\");\n const errMsg = url.searchParams.get(\"errorMessage\");\n const txHashes = url.searchParams.get(\"transactionHashes\");\n const txIds = url.searchParams.get(\"txIds\");\n\n if (errCode || errMsg) {\n console.warn(new Error(`Wallet error: ${errCode} ${errMsg}`));\n }\n\n if (accId && pubKey) {\n if (pubKey === _state.publicKey) {\n updateState({ accountId: accId });\n } else {\n console.error(new Error(\"Public key mismatch from wallet redirect\"), pubKey, _state.publicKey);\n }\n }\n\n if (txHashes || txIds) {\n const hashArr = txHashes ? txHashes.split(\",\") : [];\n const idArr = txIds ? txIds.split(\",\") : [];\n if (idArr.length > hashArr.length) {\n idArr.forEach((id) => {\n updateTxHistory({ txId: id, status: \"RejectedByUser\", finalState: true });\n });\n } else if (idArr.length === hashArr.length) {\n idArr.forEach((id, i) => {\n updateTxHistory({\n txId: id,\n status: \"PendingGotTxHash\",\n txHash: hashArr[i],\n finalState: false,\n });\n afterTxSent(id);\n });\n } else {\n console.error(new Error(\"Transaction hash mismatch from wallet redirect\"), idArr, hashArr);\n }\n }\n\n url.searchParams.delete(\"account_id\");\n url.searchParams.delete(\"public_key\");\n url.searchParams.delete(\"errorCode\");\n url.searchParams.delete(\"errorMessage\");\n url.searchParams.delete(\"all_keys\");\n url.searchParams.delete(\"transactionHashes\");\n url.searchParams.delete(\"txIds\");\n window.history.replaceState({}, \"\", url.toString());\n }\n} catch (e) {\n console.error(\"Error handling wallet redirect:\", e);\n}\n\n// action helpers\nexport const actions = {\n functionCall: ({\n methodName,\n gas,\n deposit,\n args,\n argsBase64,\n }: {\n methodName: string;\n gas?: string;\n deposit?: string;\n args?: Record<string, any>;\n argsBase64?: string;\n }) => ({\n type: \"FunctionCall\",\n methodName,\n args,\n argsBase64,\n gas,\n deposit,\n }),\n\n transfer: (yoctoAmount: string) => ({\n type: \"Transfer\",\n deposit: yoctoAmount,\n }),\n\n stakeNEAR: ({amount, publicKey}: { amount: string; publicKey: string }) => ({\n type: \"Stake\",\n stake: amount,\n publicKey,\n }),\n\n addFullAccessKey: ({publicKey}: { publicKey: string }) => ({\n type: \"AddKey\",\n publicKey: publicKey,\n accessKey: {permission: \"FullAccess\"},\n }),\n\n addLimitedAccessKey: ({\n publicKey,\n allowance,\n accountId,\n methodNames,\n }: {\n publicKey: string;\n allowance: string;\n accountId: string;\n methodNames: string[];\n }) => ({\n type: \"AddKey\",\n publicKey: publicKey,\n accessKey: {\n permission: \"FunctionCall\",\n allowance,\n receiverId: accountId,\n methodNames,\n },\n }),\n\n deleteKey: ({publicKey}: { publicKey: string }) => ({\n type: \"DeleteKey\",\n publicKey,\n }),\n\n deleteAccount: ({beneficiaryId}: { beneficiaryId: string }) => ({\n type: \"DeleteAccount\",\n beneficiaryId,\n }),\n\n createAccount: () => ({\n type: \"CreateAccount\",\n }),\n\n deployContract: ({codeBase64}: { codeBase64: string }) => ({\n type: \"DeployContract\",\n codeBase64,\n }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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