@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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/* ⋈ 🏃🏻💨 FastNEAR API - IIFE/UMD (@fastnear/api version 0.6.
|
|
2
|
-
/* https://www.npmjs.com/package/@fastnear/api/v/0.6.
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR API - IIFE/UMD (@fastnear/api version 0.6.3) */
|
|
2
|
+
/* https://www.npmjs.com/package/@fastnear/api/v/0.6.3 */
|
|
3
|
+
"use strict";
|
|
3
4
|
var near = (() => {
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,24 +24,46 @@ var near = (() => {
|
|
|
23
24
|
// src/index.ts
|
|
24
25
|
var src_exports3 = {};
|
|
25
26
|
__export(src_exports3, {
|
|
27
|
+
DEFAULT_NETWORK_ID: () => DEFAULT_NETWORK_ID,
|
|
26
28
|
MaxBlockDelayMs: () => MaxBlockDelayMs,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
NETWORKS: () => NETWORKS,
|
|
30
|
+
WIDGET_URL: () => WIDGET_URL,
|
|
31
|
+
_adapter: () => _adapter,
|
|
32
|
+
_config: () => _config,
|
|
33
|
+
_eventListeners: () => _eventListeners,
|
|
34
|
+
_state: () => _state,
|
|
35
|
+
_txHistory: () => _txHistory,
|
|
36
|
+
_unbroadcastedEvents: () => _unbroadcastedEvents,
|
|
29
37
|
accountId: () => accountId,
|
|
30
38
|
actions: () => actions,
|
|
31
39
|
afterTxSent: () => afterTxSent,
|
|
32
40
|
authStatus: () => authStatus,
|
|
33
|
-
block: () => block,
|
|
34
41
|
config: () => config,
|
|
42
|
+
exp: () => exp2,
|
|
43
|
+
generateTxId: () => generateTxId,
|
|
44
|
+
getConfig: () => getConfig,
|
|
45
|
+
getTxHistory: () => getTxHistory,
|
|
46
|
+
getWalletAdapterState: () => getWalletAdapterState,
|
|
35
47
|
localTxHistory: () => localTxHistory,
|
|
48
|
+
notifyAccountListeners: () => notifyAccountListeners,
|
|
49
|
+
notifyTxListeners: () => notifyTxListeners,
|
|
50
|
+
onAccount: () => onAccount,
|
|
51
|
+
onAdapterStateUpdate: () => onAdapterStateUpdate,
|
|
52
|
+
onTx: () => onTx,
|
|
36
53
|
publicKey: () => publicKey,
|
|
54
|
+
queryAccessKey: () => queryAccessKey,
|
|
55
|
+
queryAccount: () => queryAccount,
|
|
56
|
+
queryBlock: () => queryBlock,
|
|
37
57
|
queryRpc: () => queryRpc,
|
|
38
|
-
|
|
58
|
+
queryTx: () => queryTx,
|
|
39
59
|
requestSignIn: () => requestSignIn,
|
|
60
|
+
resetTxHistory: () => resetTxHistory,
|
|
40
61
|
sendTx: () => sendTx,
|
|
41
62
|
sendTxToRpc: () => sendTxToRpc,
|
|
63
|
+
setConfig: () => setConfig,
|
|
42
64
|
signOut: () => signOut,
|
|
43
|
-
|
|
65
|
+
updateState: () => updateState,
|
|
66
|
+
updateTxHistory: () => updateTxHistory,
|
|
44
67
|
utils: () => utils,
|
|
45
68
|
view: () => view,
|
|
46
69
|
withBlockId: () => withBlockId
|
|
@@ -49,30 +72,40 @@ var near = (() => {
|
|
|
49
72
|
// ../utils/src/index.ts
|
|
50
73
|
var src_exports2 = {};
|
|
51
74
|
__export(src_exports2, {
|
|
75
|
+
LsPrefix: () => LsPrefix,
|
|
52
76
|
SCHEMA: () => SCHEMA,
|
|
77
|
+
base64ToBytes: () => base64ToBytes,
|
|
78
|
+
bytesToBase64: () => bytesToBase64,
|
|
53
79
|
canSignWithLAK: () => canSignWithLAK,
|
|
54
80
|
convertUnit: () => convertUnit,
|
|
81
|
+
createDefaultStorage: () => createDefaultStorage,
|
|
55
82
|
deepCopy: () => deepCopy,
|
|
83
|
+
exp: () => exp,
|
|
56
84
|
fromBase58: () => base58_to_binary_default,
|
|
57
85
|
fromBase64: () => fromBase64,
|
|
86
|
+
fromHex: () => fromHex,
|
|
58
87
|
keyFromString: () => keyFromString,
|
|
59
88
|
keyToString: () => keyToString,
|
|
60
89
|
lsGet: () => lsGet,
|
|
61
90
|
lsSet: () => lsSet,
|
|
62
91
|
mapAction: () => mapAction,
|
|
63
92
|
mapTransaction: () => mapTransaction,
|
|
93
|
+
memoryStore: () => memoryStore,
|
|
64
94
|
parseJsonFromBytes: () => parseJsonFromBytes,
|
|
65
95
|
privateKeyFromRandom: () => privateKeyFromRandom,
|
|
66
96
|
publicKeyFromPrivate: () => publicKeyFromPrivate,
|
|
67
|
-
reExportBorshSchema: () => src_exports,
|
|
68
97
|
serializeSignedTransaction: () => serializeSignedTransaction,
|
|
69
98
|
serializeTransaction: () => serializeTransaction,
|
|
70
99
|
sha256: () => sha256,
|
|
71
100
|
signBytes: () => signBytes,
|
|
72
101
|
signHash: () => signHash,
|
|
102
|
+
storage: () => storage,
|
|
73
103
|
toBase58: () => binary_to_base58_default,
|
|
74
104
|
toBase64: () => toBase64,
|
|
75
|
-
|
|
105
|
+
toHex: () => toHex,
|
|
106
|
+
tryParseJson: () => tryParseJson,
|
|
107
|
+
txToJson: () => txToJson,
|
|
108
|
+
txToJsonStringified: () => txToJsonStringified
|
|
76
109
|
});
|
|
77
110
|
|
|
78
111
|
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/_assert.js
|
|
@@ -2604,6 +2637,7 @@ var near = (() => {
|
|
|
2604
2637
|
}
|
|
2605
2638
|
return _btoa(strs.join(""));
|
|
2606
2639
|
};
|
|
2640
|
+
var fromUint8Array = /* @__PURE__ */ __name((u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a), "fromUint8Array");
|
|
2607
2641
|
var cb_utob = /* @__PURE__ */ __name((c) => {
|
|
2608
2642
|
if (c.length < 2) {
|
|
2609
2643
|
var cc = c.charCodeAt(0);
|
|
@@ -2644,30 +2678,83 @@ var near = (() => {
|
|
|
2644
2678
|
}, "atobPolyfill");
|
|
2645
2679
|
var _atob = typeof atob === "function" ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
|
|
2646
2680
|
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a).split("").map((c) => c.charCodeAt(0)));
|
|
2681
|
+
var toUint8Array = /* @__PURE__ */ __name((a) => _toUint8Array(_unURI(a)), "toUint8Array");
|
|
2647
2682
|
var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
|
|
2648
2683
|
var _unURI = /* @__PURE__ */ __name((a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/")), "_unURI");
|
|
2649
2684
|
var decode = /* @__PURE__ */ __name((src) => _decode(_unURI(src)), "decode");
|
|
2650
2685
|
|
|
2651
|
-
// ../utils/src/
|
|
2686
|
+
// ../utils/src/storage.ts
|
|
2652
2687
|
var LsPrefix = "__fastnear_";
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2688
|
+
var createDefaultStorage = /* @__PURE__ */ __name(() => typeof localStorage !== "undefined" ? localStorage : {
|
|
2689
|
+
getItem: /* @__PURE__ */ __name((key) => memoryStore.get(key) || null, "getItem"),
|
|
2690
|
+
setItem: /* @__PURE__ */ __name((key, value) => memoryStore.set(key, value), "setItem"),
|
|
2691
|
+
removeItem: /* @__PURE__ */ __name((key) => memoryStore.delete(key), "removeItem"),
|
|
2692
|
+
clear: /* @__PURE__ */ __name(() => memoryStore.clear(), "clear")
|
|
2693
|
+
}, "createDefaultStorage");
|
|
2694
|
+
var memoryStore = /* @__PURE__ */ new Map();
|
|
2695
|
+
var storageBackend = createDefaultStorage();
|
|
2696
|
+
var storage = {
|
|
2697
|
+
setBackend: /* @__PURE__ */ __name((customBackend) => {
|
|
2698
|
+
storageBackend = customBackend;
|
|
2699
|
+
}, "setBackend"),
|
|
2700
|
+
set: /* @__PURE__ */ __name((key, value) => {
|
|
2701
|
+
if (value === null || value === void 0) {
|
|
2702
|
+
storageBackend.removeItem(LsPrefix + key);
|
|
2703
|
+
} else {
|
|
2704
|
+
storageBackend.setItem(LsPrefix + key, JSON.stringify(value));
|
|
2705
|
+
}
|
|
2706
|
+
}, "set"),
|
|
2707
|
+
get: /* @__PURE__ */ __name((key) => {
|
|
2708
|
+
const value = storageBackend.getItem(LsPrefix + key);
|
|
2709
|
+
if (value === null) return null;
|
|
2710
|
+
try {
|
|
2711
|
+
return JSON.parse(value);
|
|
2712
|
+
} catch {
|
|
2713
|
+
return value;
|
|
2714
|
+
}
|
|
2715
|
+
}, "get"),
|
|
2716
|
+
remove: /* @__PURE__ */ __name((key) => storageBackend.removeItem(key), "remove"),
|
|
2717
|
+
clear: /* @__PURE__ */ __name(() => storageBackend.clear(), "clear")
|
|
2718
|
+
};
|
|
2719
|
+
|
|
2720
|
+
// ../utils/src/misc.ts
|
|
2721
|
+
function toHex(data) {
|
|
2722
|
+
return Array.from(data).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2723
|
+
}
|
|
2724
|
+
__name(toHex, "toHex");
|
|
2725
|
+
function fromHex(hex) {
|
|
2726
|
+
if (hex.length % 2) throw new Error("Hex string must be even length");
|
|
2727
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
2728
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
2729
|
+
bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
2730
|
+
}
|
|
2731
|
+
return bytes;
|
|
2732
|
+
}
|
|
2733
|
+
__name(fromHex, "fromHex");
|
|
2734
|
+
function base64ToBytes(b64Val) {
|
|
2735
|
+
return toUint8Array(b64Val);
|
|
2736
|
+
}
|
|
2737
|
+
__name(base64ToBytes, "base64ToBytes");
|
|
2738
|
+
function bytesToBase64(bytesArr) {
|
|
2739
|
+
return fromUint8Array(bytesArr);
|
|
2740
|
+
}
|
|
2741
|
+
__name(bytesToBase64, "bytesToBase64");
|
|
2742
|
+
function toBase64(strVal) {
|
|
2743
|
+
try {
|
|
2744
|
+
return encode(strVal);
|
|
2745
|
+
} catch (e) {
|
|
2746
|
+
console.error("Issue base64 encoding", e);
|
|
2747
|
+
return null;
|
|
2660
2748
|
}
|
|
2661
2749
|
}
|
|
2662
2750
|
__name(toBase64, "toBase64");
|
|
2663
|
-
function fromBase64(
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2751
|
+
function fromBase64(strVal) {
|
|
2752
|
+
try {
|
|
2753
|
+
return decode(strVal);
|
|
2754
|
+
} catch (e) {
|
|
2755
|
+
console.error("Issue base64 decoding", e);
|
|
2756
|
+
return null;
|
|
2669
2757
|
}
|
|
2670
|
-
return bytes;
|
|
2671
2758
|
}
|
|
2672
2759
|
__name(fromBase64, "fromBase64");
|
|
2673
2760
|
function convertUnit(s, ...args) {
|
|
@@ -2700,20 +2787,15 @@ var near = (() => {
|
|
|
2700
2787
|
}
|
|
2701
2788
|
}
|
|
2702
2789
|
}
|
|
2703
|
-
return big_default(s).toFixed(0);
|
|
2790
|
+
return big_default(`${s}`).toFixed(0);
|
|
2704
2791
|
}
|
|
2705
2792
|
__name(convertUnit, "convertUnit");
|
|
2706
2793
|
function lsSet(key, value) {
|
|
2707
|
-
|
|
2708
|
-
localStorage.removeItem(LsPrefix + key);
|
|
2709
|
-
} else {
|
|
2710
|
-
localStorage.setItem(LsPrefix + key, JSON.stringify(value));
|
|
2711
|
-
}
|
|
2794
|
+
storage.set(key, value);
|
|
2712
2795
|
}
|
|
2713
2796
|
__name(lsSet, "lsSet");
|
|
2714
2797
|
function lsGet(key) {
|
|
2715
|
-
|
|
2716
|
-
return tryParseJson(value, null);
|
|
2798
|
+
return storage.get(key);
|
|
2717
2799
|
}
|
|
2718
2800
|
__name(lsGet, "lsGet");
|
|
2719
2801
|
function deepCopy(obj) {
|
|
@@ -2763,8 +2845,8 @@ var near = (() => {
|
|
|
2763
2845
|
), "keyFromString");
|
|
2764
2846
|
var keyToString = /* @__PURE__ */ __name((key) => `ed25519:${binary_to_base58_default(key)}`, "keyToString");
|
|
2765
2847
|
function publicKeyFromPrivate(privateKey) {
|
|
2766
|
-
|
|
2767
|
-
const publicKey2 = ed25519.getPublicKey(
|
|
2848
|
+
const secret = keyFromString(privateKey).slice(0, 32);
|
|
2849
|
+
const publicKey2 = ed25519.getPublicKey(secret);
|
|
2768
2850
|
return keyToString(publicKey2);
|
|
2769
2851
|
}
|
|
2770
2852
|
__name(publicKeyFromPrivate, "publicKeyFromPrivate");
|
|
@@ -2773,15 +2855,18 @@ var near = (() => {
|
|
|
2773
2855
|
return keyToString(privateKey);
|
|
2774
2856
|
}
|
|
2775
2857
|
__name(privateKeyFromRandom, "privateKeyFromRandom");
|
|
2776
|
-
function signHash(
|
|
2777
|
-
|
|
2778
|
-
const signature = ed25519.sign(
|
|
2779
|
-
|
|
2858
|
+
function signHash(hashBytes, privateKey, opts) {
|
|
2859
|
+
const secret = keyFromString(privateKey).slice(0, 32);
|
|
2860
|
+
const signature = ed25519.sign(hashBytes, secret);
|
|
2861
|
+
if (opts?.returnBase58) {
|
|
2862
|
+
return binary_to_base58_default(signature);
|
|
2863
|
+
}
|
|
2864
|
+
return signature;
|
|
2780
2865
|
}
|
|
2781
2866
|
__name(signHash, "signHash");
|
|
2782
2867
|
function signBytes(bytes, privateKey) {
|
|
2783
2868
|
const hash = sha256(bytes);
|
|
2784
|
-
return signHash(
|
|
2869
|
+
return signHash(hash, privateKey);
|
|
2785
2870
|
}
|
|
2786
2871
|
__name(signBytes, "signBytes");
|
|
2787
2872
|
|
|
@@ -3304,176 +3389,194 @@ var near = (() => {
|
|
|
3304
3389
|
return serializer.encode(value, schema);
|
|
3305
3390
|
}
|
|
3306
3391
|
__name(serialize, "serialize");
|
|
3392
|
+
function deserialize(schema, buffer, validate) {
|
|
3393
|
+
if (validate === void 0) {
|
|
3394
|
+
validate = true;
|
|
3395
|
+
}
|
|
3396
|
+
if (validate)
|
|
3397
|
+
validate_schema(schema);
|
|
3398
|
+
var deserializer = new BorshDeserializer(buffer);
|
|
3399
|
+
return deserializer.decode(schema);
|
|
3400
|
+
}
|
|
3401
|
+
__name(deserialize, "deserialize");
|
|
3307
3402
|
|
|
3308
3403
|
// ../borsh-schema/src/index.ts
|
|
3309
3404
|
var src_exports = {};
|
|
3310
3405
|
__export(src_exports, {
|
|
3311
|
-
getBorshSchema: () => getBorshSchema
|
|
3406
|
+
getBorshSchema: () => getBorshSchema,
|
|
3407
|
+
nearChainSchema: () => nearChainSchema
|
|
3312
3408
|
});
|
|
3313
|
-
var
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
__name(this, "BorshSchema");
|
|
3317
|
-
}
|
|
3318
|
-
Ed25519Signature = {
|
|
3319
|
-
struct: {
|
|
3320
|
-
data: { array: { type: "u8", len: 64 } }
|
|
3321
|
-
}
|
|
3322
|
-
};
|
|
3323
|
-
Secp256k1Signature = {
|
|
3324
|
-
struct: {
|
|
3325
|
-
data: { array: { type: "u8", len: 65 } }
|
|
3326
|
-
}
|
|
3327
|
-
};
|
|
3328
|
-
Signature = {
|
|
3329
|
-
enum: [
|
|
3330
|
-
{ struct: { ed25519Signature: this.Ed25519Signature } },
|
|
3331
|
-
{ struct: { secp256k1Signature: this.Secp256k1Signature } }
|
|
3332
|
-
]
|
|
3333
|
-
};
|
|
3334
|
-
Ed25519Data = {
|
|
3335
|
-
struct: {
|
|
3336
|
-
data: { array: { type: "u8", len: 32 } }
|
|
3337
|
-
}
|
|
3338
|
-
};
|
|
3339
|
-
Secp256k1Data = {
|
|
3340
|
-
struct: {
|
|
3341
|
-
data: { array: { type: "u8", len: 64 } }
|
|
3342
|
-
}
|
|
3343
|
-
};
|
|
3344
|
-
PublicKey = {
|
|
3345
|
-
enum: [
|
|
3346
|
-
{ struct: { ed25519Key: this.Ed25519Data } },
|
|
3347
|
-
{ struct: { secp256k1Key: this.Secp256k1Data } }
|
|
3348
|
-
]
|
|
3349
|
-
};
|
|
3350
|
-
FunctionCallPermission = {
|
|
3351
|
-
struct: {
|
|
3352
|
-
allowance: { option: "u128" },
|
|
3353
|
-
receiverId: "string",
|
|
3354
|
-
methodNames: { array: { type: "string" } }
|
|
3355
|
-
}
|
|
3356
|
-
};
|
|
3357
|
-
FullAccessPermission = {
|
|
3358
|
-
struct: {}
|
|
3359
|
-
};
|
|
3360
|
-
AccessKeyPermission = {
|
|
3361
|
-
enum: [
|
|
3362
|
-
{ struct: { functionCall: this.FunctionCallPermission } },
|
|
3363
|
-
{ struct: { fullAccess: this.FullAccessPermission } }
|
|
3364
|
-
]
|
|
3365
|
-
};
|
|
3366
|
-
AccessKey = {
|
|
3367
|
-
struct: {
|
|
3368
|
-
nonce: "u64",
|
|
3369
|
-
permission: this.AccessKeyPermission
|
|
3370
|
-
}
|
|
3371
|
-
};
|
|
3372
|
-
CreateAccount = {
|
|
3373
|
-
struct: {}
|
|
3374
|
-
};
|
|
3375
|
-
DeployContract = {
|
|
3376
|
-
struct: {
|
|
3377
|
-
code: { array: { type: "u8" } }
|
|
3378
|
-
}
|
|
3379
|
-
};
|
|
3380
|
-
FunctionCall = {
|
|
3381
|
-
struct: {
|
|
3382
|
-
methodName: "string",
|
|
3383
|
-
args: { array: { type: "u8" } },
|
|
3384
|
-
gas: "u64",
|
|
3385
|
-
deposit: "u128"
|
|
3386
|
-
}
|
|
3387
|
-
};
|
|
3388
|
-
Transfer = {
|
|
3389
|
-
struct: {
|
|
3390
|
-
deposit: "u128"
|
|
3391
|
-
}
|
|
3392
|
-
};
|
|
3393
|
-
Stake = {
|
|
3394
|
-
struct: {
|
|
3395
|
-
stake: "u128",
|
|
3396
|
-
publicKey: this.PublicKey
|
|
3397
|
-
}
|
|
3398
|
-
};
|
|
3399
|
-
AddKey = {
|
|
3400
|
-
struct: {
|
|
3401
|
-
publicKey: this.PublicKey,
|
|
3402
|
-
accessKey: this.AccessKey
|
|
3403
|
-
}
|
|
3404
|
-
};
|
|
3405
|
-
DeleteKey = {
|
|
3406
|
-
struct: {
|
|
3407
|
-
publicKey: this.PublicKey
|
|
3408
|
-
}
|
|
3409
|
-
};
|
|
3410
|
-
DeleteAccount = {
|
|
3411
|
-
struct: {
|
|
3412
|
-
beneficiaryId: "string"
|
|
3413
|
-
}
|
|
3414
|
-
};
|
|
3415
|
-
ClassicAction = {
|
|
3416
|
-
enum: [
|
|
3417
|
-
{ struct: { createAccount: this.CreateAccount } },
|
|
3418
|
-
{ struct: { deployContract: this.DeployContract } },
|
|
3419
|
-
{ struct: { functionCall: this.FunctionCall } },
|
|
3420
|
-
{ struct: { transfer: this.Transfer } },
|
|
3421
|
-
{ struct: { stake: this.Stake } },
|
|
3422
|
-
{ struct: { addKey: this.AddKey } },
|
|
3423
|
-
{ struct: { deleteKey: this.DeleteKey } },
|
|
3424
|
-
{ struct: { deleteAccount: this.DeleteAccount } }
|
|
3425
|
-
]
|
|
3426
|
-
};
|
|
3427
|
-
DelegateAction = {
|
|
3428
|
-
struct: {
|
|
3429
|
-
senderId: "string",
|
|
3430
|
-
receiverId: "string",
|
|
3431
|
-
actions: { array: { type: this.ClassicAction } },
|
|
3432
|
-
nonce: "u64",
|
|
3433
|
-
maxBlockHeight: "u64",
|
|
3434
|
-
publicKey: this.PublicKey
|
|
3435
|
-
}
|
|
3436
|
-
};
|
|
3437
|
-
SignedDelegate = {
|
|
3438
|
-
struct: {
|
|
3439
|
-
delegateAction: this.DelegateAction,
|
|
3440
|
-
signature: this.Signature
|
|
3441
|
-
}
|
|
3442
|
-
};
|
|
3443
|
-
Action = {
|
|
3444
|
-
enum: [
|
|
3445
|
-
{ struct: { createAccount: this.CreateAccount } },
|
|
3446
|
-
{ struct: { deployContract: this.DeployContract } },
|
|
3447
|
-
{ struct: { functionCall: this.FunctionCall } },
|
|
3448
|
-
{ struct: { transfer: this.Transfer } },
|
|
3449
|
-
{ struct: { stake: this.Stake } },
|
|
3450
|
-
{ struct: { addKey: this.AddKey } },
|
|
3451
|
-
{ struct: { deleteKey: this.DeleteKey } },
|
|
3452
|
-
{ struct: { deleteAccount: this.DeleteAccount } },
|
|
3453
|
-
{ struct: { signedDelegate: this.SignedDelegate } }
|
|
3454
|
-
]
|
|
3455
|
-
};
|
|
3456
|
-
Transaction = {
|
|
3457
|
-
struct: {
|
|
3458
|
-
signerId: "string",
|
|
3459
|
-
publicKey: this.PublicKey,
|
|
3460
|
-
nonce: "u64",
|
|
3461
|
-
receiverId: "string",
|
|
3462
|
-
blockHash: { array: { type: "u8", len: 32 } },
|
|
3463
|
-
actions: { array: { type: this.Action } }
|
|
3464
|
-
}
|
|
3465
|
-
};
|
|
3466
|
-
SignedTransaction = {
|
|
3467
|
-
struct: {
|
|
3468
|
-
transaction: this.Transaction,
|
|
3469
|
-
signature: this.Signature
|
|
3470
|
-
}
|
|
3471
|
-
};
|
|
3409
|
+
var nearChainSchema = new class BorshSchema {
|
|
3410
|
+
static {
|
|
3411
|
+
__name(this, "BorshSchema");
|
|
3472
3412
|
}
|
|
3473
|
-
|
|
3474
|
-
|
|
3413
|
+
Ed25519Signature = {
|
|
3414
|
+
struct: {
|
|
3415
|
+
data: { array: { type: "u8", len: 64 } }
|
|
3416
|
+
}
|
|
3417
|
+
};
|
|
3418
|
+
Secp256k1Signature = {
|
|
3419
|
+
struct: {
|
|
3420
|
+
data: { array: { type: "u8", len: 65 } }
|
|
3421
|
+
}
|
|
3422
|
+
};
|
|
3423
|
+
Signature = {
|
|
3424
|
+
enum: [
|
|
3425
|
+
{ struct: { ed25519Signature: this.Ed25519Signature } },
|
|
3426
|
+
{ struct: { secp256k1Signature: this.Secp256k1Signature } }
|
|
3427
|
+
]
|
|
3428
|
+
};
|
|
3429
|
+
Ed25519Data = {
|
|
3430
|
+
struct: {
|
|
3431
|
+
data: { array: { type: "u8", len: 32 } }
|
|
3432
|
+
}
|
|
3433
|
+
};
|
|
3434
|
+
Secp256k1Data = {
|
|
3435
|
+
struct: {
|
|
3436
|
+
data: { array: { type: "u8", len: 64 } }
|
|
3437
|
+
}
|
|
3438
|
+
};
|
|
3439
|
+
PublicKey = {
|
|
3440
|
+
enum: [
|
|
3441
|
+
{ struct: { ed25519Key: this.Ed25519Data } },
|
|
3442
|
+
{ struct: { secp256k1Key: this.Secp256k1Data } }
|
|
3443
|
+
]
|
|
3444
|
+
};
|
|
3445
|
+
FunctionCallPermission = {
|
|
3446
|
+
struct: {
|
|
3447
|
+
allowance: { option: "u128" },
|
|
3448
|
+
receiverId: "string",
|
|
3449
|
+
methodNames: { array: { type: "string" } }
|
|
3450
|
+
}
|
|
3451
|
+
};
|
|
3452
|
+
FullAccessPermission = {
|
|
3453
|
+
struct: {}
|
|
3454
|
+
};
|
|
3455
|
+
AccessKeyPermission = {
|
|
3456
|
+
enum: [
|
|
3457
|
+
{ struct: { functionCall: this.FunctionCallPermission } },
|
|
3458
|
+
{ struct: { fullAccess: this.FullAccessPermission } }
|
|
3459
|
+
]
|
|
3460
|
+
};
|
|
3461
|
+
AccessKey = {
|
|
3462
|
+
struct: {
|
|
3463
|
+
nonce: "u64",
|
|
3464
|
+
permission: this.AccessKeyPermission
|
|
3465
|
+
}
|
|
3466
|
+
};
|
|
3467
|
+
CreateAccount = {
|
|
3468
|
+
struct: {}
|
|
3469
|
+
};
|
|
3470
|
+
DeployContract = {
|
|
3471
|
+
struct: {
|
|
3472
|
+
code: { array: { type: "u8" } }
|
|
3473
|
+
}
|
|
3474
|
+
};
|
|
3475
|
+
FunctionCall = {
|
|
3476
|
+
struct: {
|
|
3477
|
+
methodName: "string",
|
|
3478
|
+
args: { array: { type: "u8" } },
|
|
3479
|
+
gas: "u64",
|
|
3480
|
+
deposit: "u128"
|
|
3481
|
+
}
|
|
3482
|
+
};
|
|
3483
|
+
Transfer = {
|
|
3484
|
+
struct: {
|
|
3485
|
+
deposit: "u128"
|
|
3486
|
+
}
|
|
3487
|
+
};
|
|
3488
|
+
Stake = {
|
|
3489
|
+
struct: {
|
|
3490
|
+
stake: "u128",
|
|
3491
|
+
publicKey: this.PublicKey
|
|
3492
|
+
}
|
|
3493
|
+
};
|
|
3494
|
+
AddKey = {
|
|
3495
|
+
struct: {
|
|
3496
|
+
publicKey: this.PublicKey,
|
|
3497
|
+
accessKey: this.AccessKey
|
|
3498
|
+
}
|
|
3499
|
+
};
|
|
3500
|
+
DeleteKey = {
|
|
3501
|
+
struct: {
|
|
3502
|
+
publicKey: this.PublicKey
|
|
3503
|
+
}
|
|
3504
|
+
};
|
|
3505
|
+
DeleteAccount = {
|
|
3506
|
+
struct: {
|
|
3507
|
+
beneficiaryId: "string"
|
|
3508
|
+
}
|
|
3509
|
+
};
|
|
3510
|
+
ClassicAction = {
|
|
3511
|
+
enum: [
|
|
3512
|
+
{ struct: { createAccount: this.CreateAccount } },
|
|
3513
|
+
{ struct: { deployContract: this.DeployContract } },
|
|
3514
|
+
{ struct: { functionCall: this.FunctionCall } },
|
|
3515
|
+
{ struct: { transfer: this.Transfer } },
|
|
3516
|
+
{ struct: { stake: this.Stake } },
|
|
3517
|
+
{ struct: { addKey: this.AddKey } },
|
|
3518
|
+
{ struct: { deleteKey: this.DeleteKey } },
|
|
3519
|
+
{ struct: { deleteAccount: this.DeleteAccount } }
|
|
3520
|
+
]
|
|
3521
|
+
};
|
|
3522
|
+
DelegateAction = {
|
|
3523
|
+
struct: {
|
|
3524
|
+
senderId: "string",
|
|
3525
|
+
receiverId: "string",
|
|
3526
|
+
actions: { array: { type: this.ClassicAction } },
|
|
3527
|
+
nonce: "u64",
|
|
3528
|
+
maxBlockHeight: "u64",
|
|
3529
|
+
publicKey: this.PublicKey
|
|
3530
|
+
}
|
|
3531
|
+
};
|
|
3532
|
+
SignedDelegate = {
|
|
3533
|
+
struct: {
|
|
3534
|
+
delegateAction: this.DelegateAction,
|
|
3535
|
+
signature: this.Signature
|
|
3536
|
+
}
|
|
3537
|
+
};
|
|
3538
|
+
Action = {
|
|
3539
|
+
enum: [
|
|
3540
|
+
{ struct: { createAccount: this.CreateAccount } },
|
|
3541
|
+
{ struct: { deployContract: this.DeployContract } },
|
|
3542
|
+
{ struct: { functionCall: this.FunctionCall } },
|
|
3543
|
+
{ struct: { transfer: this.Transfer } },
|
|
3544
|
+
{ struct: { stake: this.Stake } },
|
|
3545
|
+
{ struct: { addKey: this.AddKey } },
|
|
3546
|
+
{ struct: { deleteKey: this.DeleteKey } },
|
|
3547
|
+
{ struct: { deleteAccount: this.DeleteAccount } },
|
|
3548
|
+
{ struct: { signedDelegate: this.SignedDelegate } }
|
|
3549
|
+
]
|
|
3550
|
+
};
|
|
3551
|
+
Transaction = {
|
|
3552
|
+
struct: {
|
|
3553
|
+
signerId: "string",
|
|
3554
|
+
publicKey: this.PublicKey,
|
|
3555
|
+
nonce: "u64",
|
|
3556
|
+
receiverId: "string",
|
|
3557
|
+
blockHash: { array: { type: "u8", len: 32 } },
|
|
3558
|
+
actions: { array: { type: this.Action } }
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3561
|
+
SignedTransaction = {
|
|
3562
|
+
struct: {
|
|
3563
|
+
transaction: this.Transaction,
|
|
3564
|
+
signature: this.Signature
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3567
|
+
}();
|
|
3568
|
+
var getBorshSchema = /* @__PURE__ */ __name(() => nearChainSchema, "getBorshSchema");
|
|
3475
3569
|
|
|
3476
3570
|
// ../utils/src/transaction.ts
|
|
3571
|
+
var txToJson = /* @__PURE__ */ __name((tx) => {
|
|
3572
|
+
return JSON.parse(JSON.stringify(
|
|
3573
|
+
tx,
|
|
3574
|
+
(key, value) => typeof value === "bigint" ? value.toString() : value
|
|
3575
|
+
));
|
|
3576
|
+
}, "txToJson");
|
|
3577
|
+
var txToJsonStringified = /* @__PURE__ */ __name((tx) => {
|
|
3578
|
+
return JSON.stringify(txToJson(tx));
|
|
3579
|
+
}, "txToJsonStringified");
|
|
3477
3580
|
function mapTransaction(jsonTransaction) {
|
|
3478
3581
|
return {
|
|
3479
3582
|
signerId: jsonTransaction.signerId,
|
|
@@ -3490,20 +3593,29 @@ var near = (() => {
|
|
|
3490
3593
|
}
|
|
3491
3594
|
__name(mapTransaction, "mapTransaction");
|
|
3492
3595
|
function serializeTransaction(jsonTransaction) {
|
|
3596
|
+
console.log("fastnear: serializing transaction");
|
|
3493
3597
|
const transaction = mapTransaction(jsonTransaction);
|
|
3598
|
+
console.log("fastnear: mapped transaction for borsh:", transaction);
|
|
3494
3599
|
return serialize(SCHEMA.Transaction, transaction);
|
|
3495
3600
|
}
|
|
3496
3601
|
__name(serializeTransaction, "serializeTransaction");
|
|
3497
3602
|
function serializeSignedTransaction(jsonTransaction, signature) {
|
|
3498
|
-
|
|
3499
|
-
|
|
3603
|
+
console.log("fastnear: Serializing Signed Transaction", jsonTransaction);
|
|
3604
|
+
console.log("fastnear: signature", signature);
|
|
3605
|
+
console.log("fastnear: signature length", base58_to_binary_default(signature).length);
|
|
3606
|
+
const mappedSignedTx = mapTransaction(jsonTransaction);
|
|
3607
|
+
console.log("fastnear: mapped (for borsh schema) signed transaction", mappedSignedTx);
|
|
3608
|
+
const plainSignedTransaction = {
|
|
3609
|
+
transaction: mappedSignedTx,
|
|
3500
3610
|
signature: {
|
|
3501
3611
|
ed25519Signature: {
|
|
3502
3612
|
data: base58_to_binary_default(signature)
|
|
3503
3613
|
}
|
|
3504
3614
|
}
|
|
3505
3615
|
};
|
|
3506
|
-
|
|
3616
|
+
const borshSignedTx = serialize(SCHEMA.SignedTransaction, plainSignedTransaction, true);
|
|
3617
|
+
console.log("fastnear: borsh-serialized signed transaction:", borshSignedTx);
|
|
3618
|
+
return borshSignedTx;
|
|
3507
3619
|
}
|
|
3508
3620
|
__name(serializeSignedTransaction, "serializeSignedTransaction");
|
|
3509
3621
|
function mapAction(action) {
|
|
@@ -3521,10 +3633,12 @@ var near = (() => {
|
|
|
3521
3633
|
};
|
|
3522
3634
|
}
|
|
3523
3635
|
case "FunctionCall": {
|
|
3636
|
+
const argsAsString = JSON.stringify(action.args);
|
|
3637
|
+
const argsEncoded = new TextEncoder().encode(argsAsString);
|
|
3524
3638
|
return {
|
|
3525
3639
|
functionCall: {
|
|
3526
3640
|
methodName: action.methodName,
|
|
3527
|
-
args:
|
|
3641
|
+
args: argsEncoded,
|
|
3528
3642
|
gas: BigInt(action.gas),
|
|
3529
3643
|
deposit: BigInt(action.deposit)
|
|
3530
3644
|
}
|
|
@@ -3604,7 +3718,16 @@ var near = (() => {
|
|
|
3604
3718
|
}
|
|
3605
3719
|
}
|
|
3606
3720
|
__name(mapAction, "mapAction");
|
|
3607
|
-
var SCHEMA = getBorshSchema;
|
|
3721
|
+
var SCHEMA = getBorshSchema();
|
|
3722
|
+
|
|
3723
|
+
// ../utils/src/index.ts
|
|
3724
|
+
var exp = {
|
|
3725
|
+
borsh: {
|
|
3726
|
+
serialize,
|
|
3727
|
+
deserialize
|
|
3728
|
+
},
|
|
3729
|
+
borshSchema: src_exports
|
|
3730
|
+
};
|
|
3608
3731
|
|
|
3609
3732
|
// ../wallet-adapter/src/index.ts
|
|
3610
3733
|
var WalletAdapter = class _WalletAdapter {
|
|
@@ -3654,7 +3777,6 @@ var near = (() => {
|
|
|
3654
3777
|
this.#iframe.remove();
|
|
3655
3778
|
}
|
|
3656
3779
|
const url = new URL(path, this.#widgetUrl);
|
|
3657
|
-
console.log("aloha wa url", url);
|
|
3658
3780
|
const iframe = document.createElement("iframe");
|
|
3659
3781
|
iframe.src = url.toString();
|
|
3660
3782
|
iframe.allow = "usb";
|
|
@@ -3743,10 +3865,12 @@ var near = (() => {
|
|
|
3743
3865
|
/**
|
|
3744
3866
|
* Sign in with a NEAR wallet
|
|
3745
3867
|
* @param {SignInConfig} config
|
|
3746
|
-
* @returns {Promise<
|
|
3868
|
+
* @returns {Promise<any>}
|
|
3869
|
+
*
|
|
3870
|
+
* Should be returning SignInResult
|
|
3747
3871
|
*/
|
|
3748
3872
|
async signIn(config2) {
|
|
3749
|
-
return this.#sendMessage("/
|
|
3873
|
+
return this.#sendMessage("/login.html", "signIn", config2);
|
|
3750
3874
|
}
|
|
3751
3875
|
/**
|
|
3752
3876
|
* Send a transaction using connected wallet
|
|
@@ -3754,7 +3878,7 @@ var near = (() => {
|
|
|
3754
3878
|
* @returns {Promise<TransactionResult>}
|
|
3755
3879
|
*/
|
|
3756
3880
|
async sendTransactions(config2) {
|
|
3757
|
-
return this.#sendMessage("/
|
|
3881
|
+
return this.#sendMessage("/send.html", "sendTransactions", config2);
|
|
3758
3882
|
}
|
|
3759
3883
|
/**
|
|
3760
3884
|
* Clean up adapter resources
|
|
@@ -3783,6 +3907,23 @@ var near = (() => {
|
|
|
3783
3907
|
...NETWORKS[DEFAULT_NETWORK_ID]
|
|
3784
3908
|
};
|
|
3785
3909
|
var _state = lsGet("state") || {};
|
|
3910
|
+
var onAdapterStateUpdate = /* @__PURE__ */ __name((state) => {
|
|
3911
|
+
console.log("Adapter state update:", state);
|
|
3912
|
+
const { accountId: accountId2, lastWalletId, privateKey } = state;
|
|
3913
|
+
updateState({
|
|
3914
|
+
accountId: accountId2 || void 0,
|
|
3915
|
+
lastWalletId: lastWalletId || void 0,
|
|
3916
|
+
...privateKey ? { privateKey } : {}
|
|
3917
|
+
});
|
|
3918
|
+
}, "onAdapterStateUpdate");
|
|
3919
|
+
var getWalletAdapterState = /* @__PURE__ */ __name(() => {
|
|
3920
|
+
return {
|
|
3921
|
+
publicKey: _state.publicKey,
|
|
3922
|
+
accountId: _state.accountId,
|
|
3923
|
+
lastWalletId: _state.lastWalletId,
|
|
3924
|
+
networkId: DEFAULT_NETWORK_ID
|
|
3925
|
+
};
|
|
3926
|
+
}, "getWalletAdapterState");
|
|
3786
3927
|
var _adapter = new WalletAdapter({
|
|
3787
3928
|
onStateUpdate: onAdapterStateUpdate,
|
|
3788
3929
|
lastState: getWalletAdapterState(),
|
|
@@ -3804,16 +3945,7 @@ var near = (() => {
|
|
|
3804
3945
|
account: [],
|
|
3805
3946
|
tx: []
|
|
3806
3947
|
};
|
|
3807
|
-
|
|
3808
|
-
return {
|
|
3809
|
-
publicKey: _state.publicKey,
|
|
3810
|
-
accountId: _state.accountId,
|
|
3811
|
-
lastWalletId: _state.lastWalletId,
|
|
3812
|
-
networkId: DEFAULT_NETWORK_ID
|
|
3813
|
-
};
|
|
3814
|
-
}
|
|
3815
|
-
__name(getWalletAdapterState, "getWalletAdapterState");
|
|
3816
|
-
function updateState(newState) {
|
|
3948
|
+
var updateState = /* @__PURE__ */ __name((newState) => {
|
|
3817
3949
|
const oldState = _state;
|
|
3818
3950
|
_state = { ..._state, ...newState };
|
|
3819
3951
|
lsSet("state", {
|
|
@@ -3832,9 +3964,8 @@ var near = (() => {
|
|
|
3832
3964
|
if (newState.hasOwnProperty("lastWalletId") && newState.lastWalletId !== oldState.lastWalletId || newState.hasOwnProperty("accountId") && newState.accountId !== oldState.accountId || newState.hasOwnProperty("privateKey") && newState.privateKey !== oldState.privateKey) {
|
|
3833
3965
|
_adapter.setState(getWalletAdapterState());
|
|
3834
3966
|
}
|
|
3835
|
-
}
|
|
3836
|
-
__name(
|
|
3837
|
-
function updateTxHistory(txStatus) {
|
|
3967
|
+
}, "updateState");
|
|
3968
|
+
var updateTxHistory = /* @__PURE__ */ __name((txStatus) => {
|
|
3838
3969
|
const txId = txStatus.txId;
|
|
3839
3970
|
_txHistory[txId] = {
|
|
3840
3971
|
..._txHistory[txId] || {},
|
|
@@ -3843,19 +3974,8 @@ var near = (() => {
|
|
|
3843
3974
|
};
|
|
3844
3975
|
lsSet("txHistory", _txHistory);
|
|
3845
3976
|
notifyTxListeners(_txHistory[txId]);
|
|
3846
|
-
}
|
|
3847
|
-
__name(
|
|
3848
|
-
function onAdapterStateUpdate(state) {
|
|
3849
|
-
console.log("Adapter state update:", state);
|
|
3850
|
-
const { accountId: accountId2, lastWalletId, privateKey } = state;
|
|
3851
|
-
updateState({
|
|
3852
|
-
accountId: accountId2 || void 0,
|
|
3853
|
-
lastWalletId: lastWalletId || void 0,
|
|
3854
|
-
...privateKey ? { privateKey } : {}
|
|
3855
|
-
});
|
|
3856
|
-
}
|
|
3857
|
-
__name(onAdapterStateUpdate, "onAdapterStateUpdate");
|
|
3858
|
-
function notifyAccountListeners(accountId2) {
|
|
3977
|
+
}, "updateTxHistory");
|
|
3978
|
+
var notifyAccountListeners = /* @__PURE__ */ __name((accountId2) => {
|
|
3859
3979
|
if (_eventListeners.account.size === 0) {
|
|
3860
3980
|
_unbroadcastedEvents.account.push(accountId2);
|
|
3861
3981
|
return;
|
|
@@ -3867,50 +3987,67 @@ var near = (() => {
|
|
|
3867
3987
|
console.error(e);
|
|
3868
3988
|
}
|
|
3869
3989
|
});
|
|
3870
|
-
}
|
|
3871
|
-
__name(
|
|
3872
|
-
function notifyTxListeners(tx2) {
|
|
3990
|
+
}, "notifyAccountListeners");
|
|
3991
|
+
var notifyTxListeners = /* @__PURE__ */ __name((tx) => {
|
|
3873
3992
|
if (_eventListeners.tx.size === 0) {
|
|
3874
|
-
_unbroadcastedEvents.tx.push(
|
|
3993
|
+
_unbroadcastedEvents.tx.push(tx);
|
|
3875
3994
|
return;
|
|
3876
3995
|
}
|
|
3877
3996
|
_eventListeners.tx.forEach((callback) => {
|
|
3878
3997
|
try {
|
|
3879
|
-
callback(
|
|
3998
|
+
callback(tx);
|
|
3880
3999
|
} catch (e) {
|
|
3881
4000
|
console.error(e);
|
|
3882
4001
|
}
|
|
3883
4002
|
});
|
|
3884
|
-
}
|
|
3885
|
-
__name(
|
|
3886
|
-
|
|
4003
|
+
}, "notifyTxListeners");
|
|
4004
|
+
var onAccount = /* @__PURE__ */ __name((callback) => {
|
|
4005
|
+
_eventListeners.account.add(callback);
|
|
4006
|
+
if (_unbroadcastedEvents.account.length > 0) {
|
|
4007
|
+
const events = _unbroadcastedEvents.account;
|
|
4008
|
+
_unbroadcastedEvents.account = [];
|
|
4009
|
+
events.forEach(notifyAccountListeners);
|
|
4010
|
+
}
|
|
4011
|
+
}, "onAccount");
|
|
4012
|
+
var onTx = /* @__PURE__ */ __name((callback) => {
|
|
4013
|
+
_eventListeners.tx.add(callback);
|
|
4014
|
+
if (_unbroadcastedEvents.tx.length > 0) {
|
|
4015
|
+
const events = _unbroadcastedEvents.tx;
|
|
4016
|
+
_unbroadcastedEvents.tx = [];
|
|
4017
|
+
events.forEach(notifyTxListeners);
|
|
4018
|
+
}
|
|
4019
|
+
}, "onTx");
|
|
4020
|
+
var getConfig = /* @__PURE__ */ __name(() => {
|
|
3887
4021
|
return _config;
|
|
3888
|
-
}
|
|
3889
|
-
__name(
|
|
3890
|
-
function getTxHistory() {
|
|
4022
|
+
}, "getConfig");
|
|
4023
|
+
var getTxHistory = /* @__PURE__ */ __name(() => {
|
|
3891
4024
|
return _txHistory;
|
|
3892
|
-
}
|
|
3893
|
-
__name(
|
|
3894
|
-
|
|
3895
|
-
_config
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
__name(setConfig, "setConfig");
|
|
3899
|
-
function resetTxHistory() {
|
|
4025
|
+
}, "getTxHistory");
|
|
4026
|
+
var setConfig = /* @__PURE__ */ __name((newConf) => {
|
|
4027
|
+
_config = { ...NETWORKS[newConf.networkId], ...newConf };
|
|
4028
|
+
lsSet("config", _config);
|
|
4029
|
+
}, "setConfig");
|
|
4030
|
+
var resetTxHistory = /* @__PURE__ */ __name(() => {
|
|
3900
4031
|
_txHistory = {};
|
|
3901
4032
|
lsSet("txHistory", _txHistory);
|
|
3902
|
-
}
|
|
3903
|
-
__name(resetTxHistory, "resetTxHistory");
|
|
4033
|
+
}, "resetTxHistory");
|
|
3904
4034
|
|
|
3905
4035
|
// src/near.ts
|
|
3906
4036
|
big_default.DP = 27;
|
|
3907
4037
|
var MaxBlockDelayMs = 1e3 * 60 * 60 * 6;
|
|
3908
4038
|
function withBlockId(params, blockId) {
|
|
3909
|
-
|
|
4039
|
+
if (blockId === "final" || blockId === "optimistic") {
|
|
4040
|
+
return { ...params, finality: blockId };
|
|
4041
|
+
}
|
|
4042
|
+
return blockId ? { ...params, block_id: blockId } : { ...params, finality: "optimistic" };
|
|
3910
4043
|
}
|
|
3911
4044
|
__name(withBlockId, "withBlockId");
|
|
3912
4045
|
async function queryRpc(method, params) {
|
|
3913
|
-
const
|
|
4046
|
+
const config2 = getConfig();
|
|
4047
|
+
if (!config2?.nodeUrl) {
|
|
4048
|
+
throw new Error("fastnear: getConfig() returned invalid config: missing nodeUrl.");
|
|
4049
|
+
}
|
|
4050
|
+
const response = await fetch(config2.nodeUrl, {
|
|
3914
4051
|
method: "POST",
|
|
3915
4052
|
headers: { "Content-Type": "application/json" },
|
|
3916
4053
|
body: JSON.stringify({
|
|
@@ -3930,8 +4067,8 @@ var near = (() => {
|
|
|
3930
4067
|
function afterTxSent(txId) {
|
|
3931
4068
|
const txHistory = getTxHistory();
|
|
3932
4069
|
queryRpc("tx", {
|
|
3933
|
-
tx_hash: txHistory[txId]
|
|
3934
|
-
sender_account_id: txHistory[txId]
|
|
4070
|
+
tx_hash: txHistory[txId]?.txHash,
|
|
4071
|
+
sender_account_id: txHistory[txId]?.tx?.signerId,
|
|
3935
4072
|
wait_until: "EXECUTED_OPTIMISTIC"
|
|
3936
4073
|
}).then((result) => {
|
|
3937
4074
|
const successValue = result?.status?.SuccessValue;
|
|
@@ -3946,57 +4083,51 @@ var near = (() => {
|
|
|
3946
4083
|
updateTxHistory({
|
|
3947
4084
|
txId,
|
|
3948
4085
|
status: "ErrorAfterIncluded",
|
|
3949
|
-
error: tryParseJson(error.message),
|
|
4086
|
+
error: tryParseJson(error.message) ?? error.message,
|
|
3950
4087
|
finalState: true
|
|
3951
4088
|
});
|
|
3952
4089
|
});
|
|
3953
4090
|
}
|
|
3954
4091
|
__name(afterTxSent, "afterTxSent");
|
|
3955
|
-
function sendTxToRpc(signedTxBase64, waitUntil, txId) {
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
updateTxHistory({
|
|
3962
|
-
txId,
|
|
3963
|
-
status: "Included",
|
|
3964
|
-
finalState: false
|
|
4092
|
+
async function sendTxToRpc(signedTxBase64, waitUntil, txId) {
|
|
4093
|
+
waitUntil = waitUntil || "INCLUDED";
|
|
4094
|
+
try {
|
|
4095
|
+
const sendTxRes = await queryRpc("send_tx", {
|
|
4096
|
+
signed_tx_base64: signedTxBase64,
|
|
4097
|
+
wait_until: waitUntil
|
|
3965
4098
|
});
|
|
4099
|
+
updateTxHistory({ txId, status: "Included", finalState: false });
|
|
3966
4100
|
afterTxSent(txId);
|
|
3967
|
-
|
|
4101
|
+
return sendTxRes;
|
|
4102
|
+
} catch (error) {
|
|
4103
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
3968
4104
|
updateTxHistory({
|
|
3969
4105
|
txId,
|
|
3970
4106
|
status: "Error",
|
|
3971
|
-
error: tryParseJson(
|
|
4107
|
+
error: tryParseJson(errorMessage) ?? errorMessage,
|
|
3972
4108
|
finalState: false
|
|
3973
4109
|
});
|
|
3974
|
-
|
|
4110
|
+
throw new Error(errorMessage);
|
|
4111
|
+
}
|
|
3975
4112
|
}
|
|
3976
4113
|
__name(sendTxToRpc, "sendTxToRpc");
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4114
|
+
function generateTxId() {
|
|
4115
|
+
const randomPart = crypto.getRandomValues(new Uint32Array(2)).join("");
|
|
4116
|
+
return `tx-${Date.now()}-${parseInt(randomPart, 10).toString(36)}`;
|
|
4117
|
+
}
|
|
4118
|
+
__name(generateTxId, "generateTxId");
|
|
4119
|
+
var accountId = /* @__PURE__ */ __name(() => _state.accountId, "accountId");
|
|
4120
|
+
var publicKey = /* @__PURE__ */ __name(() => _state.publicKey, "publicKey");
|
|
3983
4121
|
var config = /* @__PURE__ */ __name((newConfig) => {
|
|
3984
4122
|
const current = getConfig();
|
|
3985
4123
|
if (newConfig) {
|
|
3986
4124
|
if (newConfig.networkId && current.networkId !== newConfig.networkId) {
|
|
3987
4125
|
setConfig(newConfig.networkId);
|
|
3988
|
-
updateState({
|
|
3989
|
-
accountId: null,
|
|
3990
|
-
privateKey: null,
|
|
3991
|
-
lastWalletId: null
|
|
3992
|
-
});
|
|
4126
|
+
updateState({ accountId: null, privateKey: null, lastWalletId: null });
|
|
3993
4127
|
lsSet("block", null);
|
|
3994
4128
|
resetTxHistory();
|
|
3995
4129
|
}
|
|
3996
|
-
setConfig({
|
|
3997
|
-
...getConfig(),
|
|
3998
|
-
...newConfig
|
|
3999
|
-
});
|
|
4130
|
+
setConfig({ ...getConfig(), ...newConfig });
|
|
4000
4131
|
}
|
|
4001
4132
|
return getConfig();
|
|
4002
4133
|
}, "config");
|
|
@@ -4004,17 +4135,30 @@ var near = (() => {
|
|
|
4004
4135
|
if (!_state.accountId) {
|
|
4005
4136
|
return "SignedOut";
|
|
4006
4137
|
}
|
|
4007
|
-
const accessKey2 = _state.publicKey;
|
|
4008
|
-
const contractId = _state.accessKeyContractId;
|
|
4009
|
-
if (accessKey2 && contractId && _state.privateKey) {
|
|
4010
|
-
return {
|
|
4011
|
-
type: "SignedInWithLimitedAccessKey",
|
|
4012
|
-
accessKey: accessKey2,
|
|
4013
|
-
contractId
|
|
4014
|
-
};
|
|
4015
|
-
}
|
|
4016
4138
|
return "SignedIn";
|
|
4017
4139
|
}, "authStatus");
|
|
4140
|
+
var requestSignIn = /* @__PURE__ */ __name(async ({ contractId }) => {
|
|
4141
|
+
const privateKey = privateKeyFromRandom();
|
|
4142
|
+
updateState({ accessKeyContractId: contractId, accountId: null, privateKey });
|
|
4143
|
+
const pubKey = publicKeyFromPrivate(privateKey);
|
|
4144
|
+
const result = await _adapter.signIn({
|
|
4145
|
+
networkId: getConfig().networkId,
|
|
4146
|
+
contractId,
|
|
4147
|
+
publicKey: pubKey
|
|
4148
|
+
});
|
|
4149
|
+
if (result.error) {
|
|
4150
|
+
throw new Error(`Wallet error: ${result.error}`);
|
|
4151
|
+
}
|
|
4152
|
+
if (result.url) {
|
|
4153
|
+
if (typeof window !== "undefined") {
|
|
4154
|
+
setTimeout(() => {
|
|
4155
|
+
window.location.href = result.url;
|
|
4156
|
+
}, 100);
|
|
4157
|
+
}
|
|
4158
|
+
} else if (result.accountId) {
|
|
4159
|
+
updateState({ accountId: result.accountId });
|
|
4160
|
+
}
|
|
4161
|
+
}, "requestSignIn");
|
|
4018
4162
|
var view = /* @__PURE__ */ __name(async ({
|
|
4019
4163
|
contractId,
|
|
4020
4164
|
methodName,
|
|
@@ -4037,25 +4181,19 @@ var near = (() => {
|
|
|
4037
4181
|
);
|
|
4038
4182
|
return parseJsonFromBytes(result.result);
|
|
4039
4183
|
}, "view");
|
|
4040
|
-
var
|
|
4184
|
+
var queryAccount = /* @__PURE__ */ __name(async ({
|
|
4041
4185
|
accountId: accountId2,
|
|
4042
4186
|
blockId
|
|
4043
4187
|
}) => {
|
|
4044
4188
|
return queryRpc(
|
|
4045
4189
|
"query",
|
|
4046
|
-
withBlockId(
|
|
4047
|
-
{
|
|
4048
|
-
request_type: "view_account",
|
|
4049
|
-
account_id: accountId2
|
|
4050
|
-
},
|
|
4051
|
-
blockId
|
|
4052
|
-
)
|
|
4190
|
+
withBlockId({ request_type: "view_account", account_id: accountId2 }, blockId)
|
|
4053
4191
|
);
|
|
4054
|
-
}, "
|
|
4055
|
-
var
|
|
4192
|
+
}, "queryAccount");
|
|
4193
|
+
var queryBlock = /* @__PURE__ */ __name(async ({ blockId }) => {
|
|
4056
4194
|
return queryRpc("block", withBlockId({}, blockId));
|
|
4057
|
-
}, "
|
|
4058
|
-
var
|
|
4195
|
+
}, "queryBlock");
|
|
4196
|
+
var queryAccessKey = /* @__PURE__ */ __name(async ({
|
|
4059
4197
|
accountId: accountId2,
|
|
4060
4198
|
publicKey: publicKey2,
|
|
4061
4199
|
blockId
|
|
@@ -4063,78 +4201,59 @@ var near = (() => {
|
|
|
4063
4201
|
return queryRpc(
|
|
4064
4202
|
"query",
|
|
4065
4203
|
withBlockId(
|
|
4066
|
-
{
|
|
4067
|
-
request_type: "view_access_key",
|
|
4068
|
-
account_id: accountId2,
|
|
4069
|
-
public_key: publicKey2
|
|
4070
|
-
},
|
|
4204
|
+
{ request_type: "view_access_key", account_id: accountId2, public_key: publicKey2 },
|
|
4071
4205
|
blockId
|
|
4072
4206
|
)
|
|
4073
4207
|
);
|
|
4074
|
-
}, "
|
|
4075
|
-
var
|
|
4076
|
-
txHash,
|
|
4077
|
-
accountId: accountId2
|
|
4078
|
-
}) => {
|
|
4208
|
+
}, "queryAccessKey");
|
|
4209
|
+
var queryTx = /* @__PURE__ */ __name(async ({ txHash, accountId: accountId2 }) => {
|
|
4079
4210
|
return queryRpc("tx", [txHash, accountId2]);
|
|
4080
|
-
}, "
|
|
4211
|
+
}, "queryTx");
|
|
4081
4212
|
var localTxHistory = /* @__PURE__ */ __name(() => {
|
|
4082
4213
|
return getTxHistory();
|
|
4083
4214
|
}, "localTxHistory");
|
|
4215
|
+
var signOut = /* @__PURE__ */ __name(() => {
|
|
4216
|
+
updateState({ accountId: null, privateKey: null, contractId: null });
|
|
4217
|
+
setConfig(NETWORKS[DEFAULT_NETWORK_ID]);
|
|
4218
|
+
}, "signOut");
|
|
4084
4219
|
var sendTx = /* @__PURE__ */ __name(async ({
|
|
4085
4220
|
receiverId,
|
|
4086
4221
|
actions: actions2,
|
|
4087
4222
|
waitUntil
|
|
4088
4223
|
}) => {
|
|
4089
4224
|
const signerId = _state.accountId;
|
|
4090
|
-
if (!signerId)
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
const
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
const jsonTransaction2 = {
|
|
4098
|
-
signerId,
|
|
4099
|
-
receiverId,
|
|
4100
|
-
actions: actions2
|
|
4101
|
-
};
|
|
4102
|
-
updateTxHistory({
|
|
4103
|
-
status: "Pending",
|
|
4104
|
-
txId,
|
|
4105
|
-
tx: jsonTransaction2,
|
|
4106
|
-
finalState: false
|
|
4107
|
-
});
|
|
4225
|
+
if (!signerId) throw new Error("Must sign in");
|
|
4226
|
+
const publicKey2 = _state.publicKey ?? "";
|
|
4227
|
+
const privKey = _state.privateKey;
|
|
4228
|
+
const txId = generateTxId();
|
|
4229
|
+
if (!privKey || receiverId !== _state.accessKeyContractId || !canSignWithLAK(actions2)) {
|
|
4230
|
+
const jsonTx = { signerId, receiverId, actions: actions2 };
|
|
4231
|
+
updateTxHistory({ status: "Pending", txId, tx: jsonTx, finalState: false });
|
|
4108
4232
|
const url = new URL(typeof window !== "undefined" ? window.location.href : "");
|
|
4109
4233
|
url.searchParams.set("txIds", txId);
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4234
|
+
try {
|
|
4235
|
+
const result = await _adapter.sendTransactions({
|
|
4236
|
+
transactions: [jsonTx],
|
|
4237
|
+
callbackUrl: url.toString()
|
|
4238
|
+
});
|
|
4115
4239
|
if (result.url) {
|
|
4116
|
-
console.log("Redirecting to wallet:", result.url);
|
|
4117
4240
|
if (typeof window !== "undefined") {
|
|
4118
4241
|
setTimeout(() => {
|
|
4119
4242
|
window.location.href = result.url;
|
|
4120
4243
|
}, 100);
|
|
4121
4244
|
}
|
|
4122
|
-
} else if (result.outcomes) {
|
|
4123
|
-
result.outcomes.forEach(
|
|
4124
|
-
updateTxHistory({
|
|
4245
|
+
} else if (result.outcomes?.length) {
|
|
4246
|
+
result.outcomes.forEach(
|
|
4247
|
+
(r) => updateTxHistory({
|
|
4125
4248
|
txId,
|
|
4126
4249
|
status: "Executed",
|
|
4127
4250
|
result: r,
|
|
4128
4251
|
txHash: r.transaction.hash,
|
|
4129
4252
|
finalState: true
|
|
4130
|
-
})
|
|
4131
|
-
|
|
4253
|
+
})
|
|
4254
|
+
);
|
|
4132
4255
|
} else if (result.rejected) {
|
|
4133
|
-
updateTxHistory({
|
|
4134
|
-
txId,
|
|
4135
|
-
status: "RejectedByUser",
|
|
4136
|
-
finalState: true
|
|
4137
|
-
});
|
|
4256
|
+
updateTxHistory({ txId, status: "RejectedByUser", finalState: true });
|
|
4138
4257
|
} else if (result.error) {
|
|
4139
4258
|
updateTxHistory({
|
|
4140
4259
|
txId,
|
|
@@ -4143,121 +4262,132 @@ var near = (() => {
|
|
|
4143
4262
|
finalState: true
|
|
4144
4263
|
});
|
|
4145
4264
|
}
|
|
4146
|
-
|
|
4265
|
+
return result;
|
|
4266
|
+
} catch (err) {
|
|
4267
|
+
console.error("fastnear: error sending tx using adapter:", err);
|
|
4147
4268
|
updateTxHistory({
|
|
4148
4269
|
txId,
|
|
4149
4270
|
status: "Error",
|
|
4150
|
-
error: tryParseJson(
|
|
4271
|
+
error: tryParseJson(err.message),
|
|
4151
4272
|
finalState: true
|
|
4152
4273
|
});
|
|
4153
|
-
|
|
4154
|
-
|
|
4274
|
+
return Promise.reject(err);
|
|
4275
|
+
}
|
|
4155
4276
|
}
|
|
4156
4277
|
let nonce = lsGet("nonce");
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
toDoPromises.block = block2({ blockId: "final" }).then((b) => {
|
|
4173
|
-
const newBlock = {
|
|
4174
|
-
header: {
|
|
4175
|
-
prev_hash: b.header.prev_hash,
|
|
4176
|
-
timestamp_nanosec: b.header.timestamp_nanosec
|
|
4177
|
-
}
|
|
4178
|
-
};
|
|
4179
|
-
lsSet("block", newBlock);
|
|
4180
|
-
return newBlock;
|
|
4181
|
-
});
|
|
4182
|
-
}
|
|
4183
|
-
if (Object.keys(toDoPromises).length > 0) {
|
|
4184
|
-
const results = await Promise.all(Object.values(toDoPromises));
|
|
4185
|
-
const keys = Object.keys(toDoPromises);
|
|
4186
|
-
results.forEach((res, i) => {
|
|
4187
|
-
if (keys[i] === "nonce") {
|
|
4188
|
-
nonce = res;
|
|
4189
|
-
} else if (keys[i] === "block") {
|
|
4190
|
-
block2 = res;
|
|
4278
|
+
if (nonce == null) {
|
|
4279
|
+
const accessKey = await queryAccessKey({ accountId: signerId, publicKey: publicKey2 });
|
|
4280
|
+
if (accessKey.error) {
|
|
4281
|
+
throw new Error(`Access key error: ${accessKey.error} when attempting to get nonce for ${signerId} for public key ${publicKey2}`);
|
|
4282
|
+
}
|
|
4283
|
+
nonce = accessKey.nonce;
|
|
4284
|
+
lsSet("nonce", nonce);
|
|
4285
|
+
}
|
|
4286
|
+
let lastKnownBlock = lsGet("block");
|
|
4287
|
+
if (!lastKnownBlock || parseFloat(lastKnownBlock.header.timestamp_nanosec) / 1e6 + MaxBlockDelayMs < Date.now()) {
|
|
4288
|
+
const latestBlock = await queryBlock({ blockId: "final" });
|
|
4289
|
+
lastKnownBlock = {
|
|
4290
|
+
header: {
|
|
4291
|
+
prev_hash: latestBlock.header.prev_hash,
|
|
4292
|
+
timestamp_nanosec: latestBlock.header.timestamp_nanosec
|
|
4191
4293
|
}
|
|
4192
|
-
}
|
|
4294
|
+
};
|
|
4295
|
+
lsSet("block", lastKnownBlock);
|
|
4193
4296
|
}
|
|
4194
|
-
|
|
4195
|
-
lsSet("nonce",
|
|
4196
|
-
const blockHash =
|
|
4197
|
-
const
|
|
4297
|
+
nonce += 1;
|
|
4298
|
+
lsSet("nonce", nonce);
|
|
4299
|
+
const blockHash = lastKnownBlock.header.prev_hash;
|
|
4300
|
+
const plainTransactionObj = {
|
|
4198
4301
|
signerId,
|
|
4199
4302
|
publicKey: publicKey2,
|
|
4200
|
-
nonce
|
|
4303
|
+
nonce,
|
|
4201
4304
|
receiverId,
|
|
4202
4305
|
blockHash,
|
|
4203
4306
|
actions: actions2
|
|
4204
4307
|
};
|
|
4205
|
-
|
|
4206
|
-
const
|
|
4207
|
-
const
|
|
4208
|
-
const
|
|
4209
|
-
const
|
|
4210
|
-
const signedTxBase64 =
|
|
4308
|
+
const txBytes = serializeTransaction(plainTransactionObj);
|
|
4309
|
+
const txHashBytes = sha256(txBytes);
|
|
4310
|
+
const txHash58 = binary_to_base58_default(txHashBytes);
|
|
4311
|
+
const signatureBase58 = signHash(txHashBytes, privKey, { returnBase58: true });
|
|
4312
|
+
const signedTransactionBytes = serializeSignedTransaction(plainTransactionObj, signatureBase58);
|
|
4313
|
+
const signedTxBase64 = bytesToBase64(signedTransactionBytes);
|
|
4211
4314
|
updateTxHistory({
|
|
4212
4315
|
status: "Pending",
|
|
4213
4316
|
txId,
|
|
4214
|
-
tx:
|
|
4215
|
-
signature,
|
|
4317
|
+
tx: plainTransactionObj,
|
|
4318
|
+
signature: signatureBase58,
|
|
4216
4319
|
signedTxBase64,
|
|
4217
|
-
txHash,
|
|
4320
|
+
txHash: txHash58,
|
|
4218
4321
|
finalState: false
|
|
4219
4322
|
});
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
const privateKey = privateKeyFromRandom();
|
|
4225
|
-
updateState({
|
|
4226
|
-
accessKeyContractId: contractId,
|
|
4227
|
-
accountId: null,
|
|
4228
|
-
privateKey
|
|
4229
|
-
});
|
|
4230
|
-
const publicKey2 = publicKeyFromPrivate(privateKey);
|
|
4231
|
-
const result = await _adapter.signIn({
|
|
4232
|
-
networkId: getConfig().networkId,
|
|
4233
|
-
// (C) replaced _config.networkId
|
|
4234
|
-
contractId,
|
|
4235
|
-
publicKey: publicKey2
|
|
4236
|
-
});
|
|
4237
|
-
console.log("Sign in result:", result);
|
|
4238
|
-
if (result.error) {
|
|
4239
|
-
throw new Error(`Wallet error: ${result.error}`);
|
|
4323
|
+
try {
|
|
4324
|
+
return await sendTxToRpc(signedTxBase64, waitUntil, txId);
|
|
4325
|
+
} catch (error) {
|
|
4326
|
+
console.error("Error Sending Transaction:", error, plainTransactionObj, signedTxBase64);
|
|
4240
4327
|
}
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4328
|
+
}, "sendTx");
|
|
4329
|
+
var exp2 = {
|
|
4330
|
+
utils: {},
|
|
4331
|
+
// we will map this in a moment, giving keys, for IDE hints
|
|
4332
|
+
borsh: exp.borsh,
|
|
4333
|
+
borshSchema: exp.borshSchema.getBorshSchema()
|
|
4334
|
+
};
|
|
4335
|
+
for (const key in src_exports2) {
|
|
4336
|
+
exp2.utils[key] = src_exports2[key];
|
|
4337
|
+
}
|
|
4338
|
+
var utils = exp2.utils;
|
|
4339
|
+
try {
|
|
4340
|
+
if (typeof window !== "undefined") {
|
|
4341
|
+
const url = new URL(window.location.href);
|
|
4342
|
+
const accId = url.searchParams.get("account_id");
|
|
4343
|
+
const pubKey = url.searchParams.get("public_key");
|
|
4344
|
+
const errCode = url.searchParams.get("errorCode");
|
|
4345
|
+
const errMsg = url.searchParams.get("errorMessage");
|
|
4346
|
+
const txHashes = url.searchParams.get("transactionHashes");
|
|
4347
|
+
const txIds = url.searchParams.get("txIds");
|
|
4348
|
+
if (errCode || errMsg) {
|
|
4349
|
+
console.warn(new Error(`Wallet error: ${errCode} ${errMsg}`));
|
|
4247
4350
|
}
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4351
|
+
if (accId && pubKey) {
|
|
4352
|
+
if (pubKey === _state.publicKey) {
|
|
4353
|
+
updateState({ accountId: accId });
|
|
4354
|
+
} else {
|
|
4355
|
+
console.error(new Error("Public key mismatch from wallet redirect"), pubKey, _state.publicKey);
|
|
4356
|
+
}
|
|
4357
|
+
}
|
|
4358
|
+
if (txHashes || txIds) {
|
|
4359
|
+
const hashArr = txHashes ? txHashes.split(",") : [];
|
|
4360
|
+
const idArr = txIds ? txIds.split(",") : [];
|
|
4361
|
+
if (idArr.length > hashArr.length) {
|
|
4362
|
+
idArr.forEach((id) => {
|
|
4363
|
+
updateTxHistory({ txId: id, status: "RejectedByUser", finalState: true });
|
|
4364
|
+
});
|
|
4365
|
+
} else if (idArr.length === hashArr.length) {
|
|
4366
|
+
idArr.forEach((id, i) => {
|
|
4367
|
+
updateTxHistory({
|
|
4368
|
+
txId: id,
|
|
4369
|
+
status: "PendingGotTxHash",
|
|
4370
|
+
txHash: hashArr[i],
|
|
4371
|
+
finalState: false
|
|
4372
|
+
});
|
|
4373
|
+
afterTxSent(id);
|
|
4374
|
+
});
|
|
4375
|
+
} else {
|
|
4376
|
+
console.error(new Error("Transaction hash mismatch from wallet redirect"), idArr, hashArr);
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
url.searchParams.delete("account_id");
|
|
4380
|
+
url.searchParams.delete("public_key");
|
|
4381
|
+
url.searchParams.delete("errorCode");
|
|
4382
|
+
url.searchParams.delete("errorMessage");
|
|
4383
|
+
url.searchParams.delete("all_keys");
|
|
4384
|
+
url.searchParams.delete("transactionHashes");
|
|
4385
|
+
url.searchParams.delete("txIds");
|
|
4386
|
+
window.history.replaceState({}, "", url.toString());
|
|
4252
4387
|
}
|
|
4253
|
-
}
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
accountId: null,
|
|
4257
|
-
privateKey: null,
|
|
4258
|
-
contractId: null
|
|
4259
|
-
});
|
|
4260
|
-
}, "signOut");
|
|
4388
|
+
} catch (e) {
|
|
4389
|
+
console.error("Error handling wallet redirect:", e);
|
|
4390
|
+
}
|
|
4261
4391
|
var actions = {
|
|
4262
4392
|
functionCall: /* @__PURE__ */ __name(({
|
|
4263
4393
|
methodName,
|
|
@@ -4318,82 +4448,6 @@ var near = (() => {
|
|
|
4318
4448
|
codeBase64
|
|
4319
4449
|
}), "deployContract")
|
|
4320
4450
|
};
|
|
4321
|
-
var reExports = {
|
|
4322
|
-
utils: src_exports2,
|
|
4323
|
-
borshSchema: src_exports
|
|
4324
|
-
};
|
|
4325
|
-
var utils = reExports.utils;
|
|
4326
|
-
try {
|
|
4327
|
-
if (typeof window !== "undefined") {
|
|
4328
|
-
const url = new URL(window.location.href);
|
|
4329
|
-
const accountId2 = url.searchParams.get("account_id");
|
|
4330
|
-
const publicKey2 = url.searchParams.get("public_key");
|
|
4331
|
-
const errorCode = url.searchParams.get("errorCode");
|
|
4332
|
-
const errorMessage = url.searchParams.get("errorMessage");
|
|
4333
|
-
const transactionHashes = url.searchParams.get("transactionHashes");
|
|
4334
|
-
const txIds = url.searchParams.get("txIds");
|
|
4335
|
-
if (errorCode || errorMessage) {
|
|
4336
|
-
console.warn(new Error(`Wallet error: ${errorCode} ${errorMessage}`));
|
|
4337
|
-
}
|
|
4338
|
-
if (accountId2 && publicKey2) {
|
|
4339
|
-
if (publicKey2 === _state.publicKey) {
|
|
4340
|
-
updateState({
|
|
4341
|
-
accountId: accountId2
|
|
4342
|
-
});
|
|
4343
|
-
} else {
|
|
4344
|
-
console.error(
|
|
4345
|
-
new Error("Public key mismatch from wallet redirect"),
|
|
4346
|
-
publicKey2,
|
|
4347
|
-
_state.publicKey
|
|
4348
|
-
);
|
|
4349
|
-
}
|
|
4350
|
-
}
|
|
4351
|
-
if (transactionHashes || txIds) {
|
|
4352
|
-
const txHashes = transactionHashes ? transactionHashes.split(",") : [];
|
|
4353
|
-
const txIdsArray = txIds ? txIds.split(",") : [];
|
|
4354
|
-
if (txIdsArray.length > txHashes.length) {
|
|
4355
|
-
txIdsArray.forEach((txId, i) => {
|
|
4356
|
-
updateTxHistory({
|
|
4357
|
-
txId,
|
|
4358
|
-
status: "RejectedByUser",
|
|
4359
|
-
finalState: true
|
|
4360
|
-
});
|
|
4361
|
-
});
|
|
4362
|
-
} else if (txIdsArray.length === txHashes.length) {
|
|
4363
|
-
txIdsArray.forEach((txId, i) => {
|
|
4364
|
-
updateTxHistory({
|
|
4365
|
-
txId,
|
|
4366
|
-
status: "PendingGotTxHash",
|
|
4367
|
-
txHash: txHashes[i],
|
|
4368
|
-
finalState: false
|
|
4369
|
-
});
|
|
4370
|
-
afterTxSent(txId);
|
|
4371
|
-
});
|
|
4372
|
-
} else {
|
|
4373
|
-
console.error(
|
|
4374
|
-
new Error("Transaction hash mismatch from wallet redirect"),
|
|
4375
|
-
txIdsArray,
|
|
4376
|
-
txHashes
|
|
4377
|
-
);
|
|
4378
|
-
}
|
|
4379
|
-
}
|
|
4380
|
-
url.searchParams.delete("account_id");
|
|
4381
|
-
url.searchParams.delete("public_key");
|
|
4382
|
-
url.searchParams.delete("errorCode");
|
|
4383
|
-
url.searchParams.delete("errorMessage");
|
|
4384
|
-
url.searchParams.delete("all_keys");
|
|
4385
|
-
url.searchParams.delete("transactionHashes");
|
|
4386
|
-
url.searchParams.delete("txIds");
|
|
4387
|
-
window.history.replaceState({}, "", url.toString());
|
|
4388
|
-
}
|
|
4389
|
-
} catch (e) {
|
|
4390
|
-
console.error("Error handling wallet redirect:", e);
|
|
4391
|
-
}
|
|
4392
|
-
|
|
4393
|
-
// src/index.ts
|
|
4394
|
-
if (typeof window !== "undefined") {
|
|
4395
|
-
window.$$ = convertUnit;
|
|
4396
|
-
}
|
|
4397
4451
|
return __toCommonJS(src_exports3);
|
|
4398
4452
|
})();
|
|
4399
4453
|
/*! Bundled license information:
|
|
@@ -4420,15 +4474,17 @@ var near = (() => {
|
|
|
4420
4474
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
4421
4475
|
*/
|
|
4422
4476
|
|
|
4423
|
-
|
|
4424
|
-
console.warn('No globalThis.near');
|
|
4425
|
-
} else {
|
|
4477
|
+
try {
|
|
4426
4478
|
Object.defineProperty(globalThis, 'near', {
|
|
4427
|
-
value:
|
|
4428
|
-
writable: false,
|
|
4479
|
+
value: near,
|
|
4429
4480
|
enumerable: true,
|
|
4430
4481
|
configurable: false,
|
|
4431
4482
|
});
|
|
4483
|
+
} catch (error) {
|
|
4484
|
+
console.error('Could not define global "near" object', error);
|
|
4485
|
+
throw error;
|
|
4432
4486
|
}
|
|
4433
4487
|
|
|
4488
|
+
window.$$ = near.utils.convertUnit;
|
|
4489
|
+
|
|
4434
4490
|
//# sourceMappingURL=browser.global.js.map
|