@fastnear/utils 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/crypto.cjs +81 -0
- package/dist/cjs/crypto.cjs.map +1 -0
- package/dist/cjs/index.cjs +17 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +89 -3208
- package/dist/cjs/misc.cjs +187 -0
- package/dist/cjs/misc.cjs.map +1 -0
- package/dist/cjs/storage.cjs +69 -0
- package/dist/cjs/storage.cjs.map +1 -0
- package/dist/cjs/transaction.cjs +198 -0
- package/dist/cjs/transaction.cjs.map +1 -0
- package/dist/esm/crypto.js +52 -0
- package/dist/esm/crypto.js.map +1 -0
- package/dist/esm/index.d.ts +89 -3208
- package/dist/esm/index.js +13 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/misc.js +148 -0
- package/dist/esm/misc.js.map +1 -0
- package/dist/esm/storage.js +43 -0
- package/dist/esm/storage.js.map +1 -0
- package/dist/esm/transaction.js +169 -0
- package/dist/esm/transaction.js.map +1 -0
- package/dist/umd/browser.global.js +307 -211
- package/dist/umd/browser.global.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/* ⋈ 🏃🏻💨 FastNEAR Utils - IIFE/UMD (@fastnear/utils version 0.6.
|
|
2
|
-
/* https://www.npmjs.com/package/@fastnear/utils/v/0.6.
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR Utils - IIFE/UMD (@fastnear/utils version 0.6.3) */
|
|
2
|
+
/* https://www.npmjs.com/package/@fastnear/utils/v/0.6.3 */
|
|
3
|
+
"use strict";
|
|
3
4
|
var NearUtils = (() => {
|
|
4
5
|
var __create = Object.create;
|
|
5
6
|
var __defProp = Object.defineProperty;
|
|
@@ -39,30 +40,40 @@ var NearUtils = (() => {
|
|
|
39
40
|
// src/index.ts
|
|
40
41
|
var src_exports2 = {};
|
|
41
42
|
__export(src_exports2, {
|
|
43
|
+
LsPrefix: () => LsPrefix,
|
|
42
44
|
SCHEMA: () => SCHEMA,
|
|
45
|
+
base64ToBytes: () => base64ToBytes,
|
|
46
|
+
bytesToBase64: () => bytesToBase64,
|
|
43
47
|
canSignWithLAK: () => canSignWithLAK,
|
|
44
48
|
convertUnit: () => convertUnit,
|
|
49
|
+
createDefaultStorage: () => createDefaultStorage,
|
|
45
50
|
deepCopy: () => deepCopy,
|
|
51
|
+
exp: () => exp,
|
|
46
52
|
fromBase58: () => base58_to_binary_default,
|
|
47
53
|
fromBase64: () => fromBase64,
|
|
54
|
+
fromHex: () => fromHex,
|
|
48
55
|
keyFromString: () => keyFromString,
|
|
49
56
|
keyToString: () => keyToString,
|
|
50
57
|
lsGet: () => lsGet,
|
|
51
58
|
lsSet: () => lsSet,
|
|
52
59
|
mapAction: () => mapAction,
|
|
53
60
|
mapTransaction: () => mapTransaction,
|
|
61
|
+
memoryStore: () => memoryStore,
|
|
54
62
|
parseJsonFromBytes: () => parseJsonFromBytes,
|
|
55
63
|
privateKeyFromRandom: () => privateKeyFromRandom,
|
|
56
64
|
publicKeyFromPrivate: () => publicKeyFromPrivate,
|
|
57
|
-
reExportBorshSchema: () => src_exports,
|
|
58
65
|
serializeSignedTransaction: () => serializeSignedTransaction,
|
|
59
66
|
serializeTransaction: () => serializeTransaction,
|
|
60
67
|
sha256: () => sha256,
|
|
61
68
|
signBytes: () => signBytes,
|
|
62
69
|
signHash: () => signHash,
|
|
70
|
+
storage: () => storage,
|
|
63
71
|
toBase58: () => binary_to_base58_default,
|
|
64
72
|
toBase64: () => toBase64,
|
|
65
|
-
|
|
73
|
+
toHex: () => toHex,
|
|
74
|
+
tryParseJson: () => tryParseJson,
|
|
75
|
+
txToJson: () => txToJson,
|
|
76
|
+
txToJsonStringified: () => txToJsonStringified
|
|
66
77
|
});
|
|
67
78
|
|
|
68
79
|
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/_assert.js
|
|
@@ -2595,6 +2606,7 @@ var NearUtils = (() => {
|
|
|
2595
2606
|
}
|
|
2596
2607
|
return _btoa(strs.join(""));
|
|
2597
2608
|
};
|
|
2609
|
+
var fromUint8Array = /* @__PURE__ */ __name((u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a), "fromUint8Array");
|
|
2598
2610
|
var cb_utob = /* @__PURE__ */ __name((c) => {
|
|
2599
2611
|
if (c.length < 2) {
|
|
2600
2612
|
var cc = c.charCodeAt(0);
|
|
@@ -2635,30 +2647,83 @@ var NearUtils = (() => {
|
|
|
2635
2647
|
}, "atobPolyfill");
|
|
2636
2648
|
var _atob = typeof atob === "function" ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
|
|
2637
2649
|
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a).split("").map((c) => c.charCodeAt(0)));
|
|
2650
|
+
var toUint8Array = /* @__PURE__ */ __name((a) => _toUint8Array(_unURI(a)), "toUint8Array");
|
|
2638
2651
|
var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
|
|
2639
2652
|
var _unURI = /* @__PURE__ */ __name((a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/")), "_unURI");
|
|
2640
2653
|
var decode = /* @__PURE__ */ __name((src) => _decode(_unURI(src)), "decode");
|
|
2641
2654
|
|
|
2642
|
-
// src/
|
|
2655
|
+
// src/storage.ts
|
|
2643
2656
|
var LsPrefix = "__fastnear_";
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2657
|
+
var createDefaultStorage = /* @__PURE__ */ __name(() => typeof localStorage !== "undefined" ? localStorage : {
|
|
2658
|
+
getItem: /* @__PURE__ */ __name((key) => memoryStore.get(key) || null, "getItem"),
|
|
2659
|
+
setItem: /* @__PURE__ */ __name((key, value) => memoryStore.set(key, value), "setItem"),
|
|
2660
|
+
removeItem: /* @__PURE__ */ __name((key) => memoryStore.delete(key), "removeItem"),
|
|
2661
|
+
clear: /* @__PURE__ */ __name(() => memoryStore.clear(), "clear")
|
|
2662
|
+
}, "createDefaultStorage");
|
|
2663
|
+
var memoryStore = /* @__PURE__ */ new Map();
|
|
2664
|
+
var storageBackend = createDefaultStorage();
|
|
2665
|
+
var storage = {
|
|
2666
|
+
setBackend: /* @__PURE__ */ __name((customBackend) => {
|
|
2667
|
+
storageBackend = customBackend;
|
|
2668
|
+
}, "setBackend"),
|
|
2669
|
+
set: /* @__PURE__ */ __name((key, value) => {
|
|
2670
|
+
if (value === null || value === void 0) {
|
|
2671
|
+
storageBackend.removeItem(LsPrefix + key);
|
|
2672
|
+
} else {
|
|
2673
|
+
storageBackend.setItem(LsPrefix + key, JSON.stringify(value));
|
|
2674
|
+
}
|
|
2675
|
+
}, "set"),
|
|
2676
|
+
get: /* @__PURE__ */ __name((key) => {
|
|
2677
|
+
const value = storageBackend.getItem(LsPrefix + key);
|
|
2678
|
+
if (value === null) return null;
|
|
2679
|
+
try {
|
|
2680
|
+
return JSON.parse(value);
|
|
2681
|
+
} catch {
|
|
2682
|
+
return value;
|
|
2683
|
+
}
|
|
2684
|
+
}, "get"),
|
|
2685
|
+
remove: /* @__PURE__ */ __name((key) => storageBackend.removeItem(key), "remove"),
|
|
2686
|
+
clear: /* @__PURE__ */ __name(() => storageBackend.clear(), "clear")
|
|
2687
|
+
};
|
|
2688
|
+
|
|
2689
|
+
// src/misc.ts
|
|
2690
|
+
function toHex(data) {
|
|
2691
|
+
return Array.from(data).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2692
|
+
}
|
|
2693
|
+
__name(toHex, "toHex");
|
|
2694
|
+
function fromHex(hex) {
|
|
2695
|
+
if (hex.length % 2) throw new Error("Hex string must be even length");
|
|
2696
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
2697
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
2698
|
+
bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
2699
|
+
}
|
|
2700
|
+
return bytes;
|
|
2701
|
+
}
|
|
2702
|
+
__name(fromHex, "fromHex");
|
|
2703
|
+
function base64ToBytes(b64Val) {
|
|
2704
|
+
return toUint8Array(b64Val);
|
|
2705
|
+
}
|
|
2706
|
+
__name(base64ToBytes, "base64ToBytes");
|
|
2707
|
+
function bytesToBase64(bytesArr) {
|
|
2708
|
+
return fromUint8Array(bytesArr);
|
|
2709
|
+
}
|
|
2710
|
+
__name(bytesToBase64, "bytesToBase64");
|
|
2711
|
+
function toBase64(strVal) {
|
|
2712
|
+
try {
|
|
2713
|
+
return encode(strVal);
|
|
2714
|
+
} catch (e) {
|
|
2715
|
+
console.error("Issue base64 encoding", e);
|
|
2716
|
+
return null;
|
|
2651
2717
|
}
|
|
2652
2718
|
}
|
|
2653
2719
|
__name(toBase64, "toBase64");
|
|
2654
|
-
function fromBase64(
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2720
|
+
function fromBase64(strVal) {
|
|
2721
|
+
try {
|
|
2722
|
+
return decode(strVal);
|
|
2723
|
+
} catch (e) {
|
|
2724
|
+
console.error("Issue base64 decoding", e);
|
|
2725
|
+
return null;
|
|
2660
2726
|
}
|
|
2661
|
-
return bytes;
|
|
2662
2727
|
}
|
|
2663
2728
|
__name(fromBase64, "fromBase64");
|
|
2664
2729
|
function convertUnit(s, ...args) {
|
|
@@ -2691,20 +2756,15 @@ var NearUtils = (() => {
|
|
|
2691
2756
|
}
|
|
2692
2757
|
}
|
|
2693
2758
|
}
|
|
2694
|
-
return big_default(s).toFixed(0);
|
|
2759
|
+
return big_default(`${s}`).toFixed(0);
|
|
2695
2760
|
}
|
|
2696
2761
|
__name(convertUnit, "convertUnit");
|
|
2697
2762
|
function lsSet(key, value) {
|
|
2698
|
-
|
|
2699
|
-
localStorage.removeItem(LsPrefix + key);
|
|
2700
|
-
} else {
|
|
2701
|
-
localStorage.setItem(LsPrefix + key, JSON.stringify(value));
|
|
2702
|
-
}
|
|
2763
|
+
storage.set(key, value);
|
|
2703
2764
|
}
|
|
2704
2765
|
__name(lsSet, "lsSet");
|
|
2705
2766
|
function lsGet(key) {
|
|
2706
|
-
|
|
2707
|
-
return tryParseJson(value, null);
|
|
2767
|
+
return storage.get(key);
|
|
2708
2768
|
}
|
|
2709
2769
|
__name(lsGet, "lsGet");
|
|
2710
2770
|
function deepCopy(obj) {
|
|
@@ -2754,8 +2814,8 @@ var NearUtils = (() => {
|
|
|
2754
2814
|
), "keyFromString");
|
|
2755
2815
|
var keyToString = /* @__PURE__ */ __name((key) => `ed25519:${binary_to_base58_default(key)}`, "keyToString");
|
|
2756
2816
|
function publicKeyFromPrivate(privateKey) {
|
|
2757
|
-
|
|
2758
|
-
const publicKey = ed25519.getPublicKey(
|
|
2817
|
+
const secret = keyFromString(privateKey).slice(0, 32);
|
|
2818
|
+
const publicKey = ed25519.getPublicKey(secret);
|
|
2759
2819
|
return keyToString(publicKey);
|
|
2760
2820
|
}
|
|
2761
2821
|
__name(publicKeyFromPrivate, "publicKeyFromPrivate");
|
|
@@ -2764,15 +2824,18 @@ var NearUtils = (() => {
|
|
|
2764
2824
|
return keyToString(privateKey);
|
|
2765
2825
|
}
|
|
2766
2826
|
__name(privateKeyFromRandom, "privateKeyFromRandom");
|
|
2767
|
-
function signHash(
|
|
2768
|
-
|
|
2769
|
-
const signature = ed25519.sign(
|
|
2770
|
-
|
|
2827
|
+
function signHash(hashBytes, privateKey, opts) {
|
|
2828
|
+
const secret = keyFromString(privateKey).slice(0, 32);
|
|
2829
|
+
const signature = ed25519.sign(hashBytes, secret);
|
|
2830
|
+
if (opts?.returnBase58) {
|
|
2831
|
+
return binary_to_base58_default(signature);
|
|
2832
|
+
}
|
|
2833
|
+
return signature;
|
|
2771
2834
|
}
|
|
2772
2835
|
__name(signHash, "signHash");
|
|
2773
2836
|
function signBytes(bytes, privateKey) {
|
|
2774
2837
|
const hash = sha256(bytes);
|
|
2775
|
-
return signHash(
|
|
2838
|
+
return signHash(hash, privateKey);
|
|
2776
2839
|
}
|
|
2777
2840
|
__name(signBytes, "signBytes");
|
|
2778
2841
|
|
|
@@ -3295,176 +3358,194 @@ var NearUtils = (() => {
|
|
|
3295
3358
|
return serializer.encode(value, schema);
|
|
3296
3359
|
}
|
|
3297
3360
|
__name(serialize, "serialize");
|
|
3361
|
+
function deserialize(schema, buffer, validate) {
|
|
3362
|
+
if (validate === void 0) {
|
|
3363
|
+
validate = true;
|
|
3364
|
+
}
|
|
3365
|
+
if (validate)
|
|
3366
|
+
validate_schema(schema);
|
|
3367
|
+
var deserializer = new BorshDeserializer(buffer);
|
|
3368
|
+
return deserializer.decode(schema);
|
|
3369
|
+
}
|
|
3370
|
+
__name(deserialize, "deserialize");
|
|
3298
3371
|
|
|
3299
3372
|
// ../borsh-schema/src/index.ts
|
|
3300
3373
|
var src_exports = {};
|
|
3301
3374
|
__export(src_exports, {
|
|
3302
|
-
getBorshSchema: () => getBorshSchema
|
|
3375
|
+
getBorshSchema: () => getBorshSchema,
|
|
3376
|
+
nearChainSchema: () => nearChainSchema
|
|
3303
3377
|
});
|
|
3304
|
-
var
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
__name(this, "BorshSchema");
|
|
3308
|
-
}
|
|
3309
|
-
Ed25519Signature = {
|
|
3310
|
-
struct: {
|
|
3311
|
-
data: { array: { type: "u8", len: 64 } }
|
|
3312
|
-
}
|
|
3313
|
-
};
|
|
3314
|
-
Secp256k1Signature = {
|
|
3315
|
-
struct: {
|
|
3316
|
-
data: { array: { type: "u8", len: 65 } }
|
|
3317
|
-
}
|
|
3318
|
-
};
|
|
3319
|
-
Signature = {
|
|
3320
|
-
enum: [
|
|
3321
|
-
{ struct: { ed25519Signature: this.Ed25519Signature } },
|
|
3322
|
-
{ struct: { secp256k1Signature: this.Secp256k1Signature } }
|
|
3323
|
-
]
|
|
3324
|
-
};
|
|
3325
|
-
Ed25519Data = {
|
|
3326
|
-
struct: {
|
|
3327
|
-
data: { array: { type: "u8", len: 32 } }
|
|
3328
|
-
}
|
|
3329
|
-
};
|
|
3330
|
-
Secp256k1Data = {
|
|
3331
|
-
struct: {
|
|
3332
|
-
data: { array: { type: "u8", len: 64 } }
|
|
3333
|
-
}
|
|
3334
|
-
};
|
|
3335
|
-
PublicKey = {
|
|
3336
|
-
enum: [
|
|
3337
|
-
{ struct: { ed25519Key: this.Ed25519Data } },
|
|
3338
|
-
{ struct: { secp256k1Key: this.Secp256k1Data } }
|
|
3339
|
-
]
|
|
3340
|
-
};
|
|
3341
|
-
FunctionCallPermission = {
|
|
3342
|
-
struct: {
|
|
3343
|
-
allowance: { option: "u128" },
|
|
3344
|
-
receiverId: "string",
|
|
3345
|
-
methodNames: { array: { type: "string" } }
|
|
3346
|
-
}
|
|
3347
|
-
};
|
|
3348
|
-
FullAccessPermission = {
|
|
3349
|
-
struct: {}
|
|
3350
|
-
};
|
|
3351
|
-
AccessKeyPermission = {
|
|
3352
|
-
enum: [
|
|
3353
|
-
{ struct: { functionCall: this.FunctionCallPermission } },
|
|
3354
|
-
{ struct: { fullAccess: this.FullAccessPermission } }
|
|
3355
|
-
]
|
|
3356
|
-
};
|
|
3357
|
-
AccessKey = {
|
|
3358
|
-
struct: {
|
|
3359
|
-
nonce: "u64",
|
|
3360
|
-
permission: this.AccessKeyPermission
|
|
3361
|
-
}
|
|
3362
|
-
};
|
|
3363
|
-
CreateAccount = {
|
|
3364
|
-
struct: {}
|
|
3365
|
-
};
|
|
3366
|
-
DeployContract = {
|
|
3367
|
-
struct: {
|
|
3368
|
-
code: { array: { type: "u8" } }
|
|
3369
|
-
}
|
|
3370
|
-
};
|
|
3371
|
-
FunctionCall = {
|
|
3372
|
-
struct: {
|
|
3373
|
-
methodName: "string",
|
|
3374
|
-
args: { array: { type: "u8" } },
|
|
3375
|
-
gas: "u64",
|
|
3376
|
-
deposit: "u128"
|
|
3377
|
-
}
|
|
3378
|
-
};
|
|
3379
|
-
Transfer = {
|
|
3380
|
-
struct: {
|
|
3381
|
-
deposit: "u128"
|
|
3382
|
-
}
|
|
3383
|
-
};
|
|
3384
|
-
Stake = {
|
|
3385
|
-
struct: {
|
|
3386
|
-
stake: "u128",
|
|
3387
|
-
publicKey: this.PublicKey
|
|
3388
|
-
}
|
|
3389
|
-
};
|
|
3390
|
-
AddKey = {
|
|
3391
|
-
struct: {
|
|
3392
|
-
publicKey: this.PublicKey,
|
|
3393
|
-
accessKey: this.AccessKey
|
|
3394
|
-
}
|
|
3395
|
-
};
|
|
3396
|
-
DeleteKey = {
|
|
3397
|
-
struct: {
|
|
3398
|
-
publicKey: this.PublicKey
|
|
3399
|
-
}
|
|
3400
|
-
};
|
|
3401
|
-
DeleteAccount = {
|
|
3402
|
-
struct: {
|
|
3403
|
-
beneficiaryId: "string"
|
|
3404
|
-
}
|
|
3405
|
-
};
|
|
3406
|
-
ClassicAction = {
|
|
3407
|
-
enum: [
|
|
3408
|
-
{ struct: { createAccount: this.CreateAccount } },
|
|
3409
|
-
{ struct: { deployContract: this.DeployContract } },
|
|
3410
|
-
{ struct: { functionCall: this.FunctionCall } },
|
|
3411
|
-
{ struct: { transfer: this.Transfer } },
|
|
3412
|
-
{ struct: { stake: this.Stake } },
|
|
3413
|
-
{ struct: { addKey: this.AddKey } },
|
|
3414
|
-
{ struct: { deleteKey: this.DeleteKey } },
|
|
3415
|
-
{ struct: { deleteAccount: this.DeleteAccount } }
|
|
3416
|
-
]
|
|
3417
|
-
};
|
|
3418
|
-
DelegateAction = {
|
|
3419
|
-
struct: {
|
|
3420
|
-
senderId: "string",
|
|
3421
|
-
receiverId: "string",
|
|
3422
|
-
actions: { array: { type: this.ClassicAction } },
|
|
3423
|
-
nonce: "u64",
|
|
3424
|
-
maxBlockHeight: "u64",
|
|
3425
|
-
publicKey: this.PublicKey
|
|
3426
|
-
}
|
|
3427
|
-
};
|
|
3428
|
-
SignedDelegate = {
|
|
3429
|
-
struct: {
|
|
3430
|
-
delegateAction: this.DelegateAction,
|
|
3431
|
-
signature: this.Signature
|
|
3432
|
-
}
|
|
3433
|
-
};
|
|
3434
|
-
Action = {
|
|
3435
|
-
enum: [
|
|
3436
|
-
{ struct: { createAccount: this.CreateAccount } },
|
|
3437
|
-
{ struct: { deployContract: this.DeployContract } },
|
|
3438
|
-
{ struct: { functionCall: this.FunctionCall } },
|
|
3439
|
-
{ struct: { transfer: this.Transfer } },
|
|
3440
|
-
{ struct: { stake: this.Stake } },
|
|
3441
|
-
{ struct: { addKey: this.AddKey } },
|
|
3442
|
-
{ struct: { deleteKey: this.DeleteKey } },
|
|
3443
|
-
{ struct: { deleteAccount: this.DeleteAccount } },
|
|
3444
|
-
{ struct: { signedDelegate: this.SignedDelegate } }
|
|
3445
|
-
]
|
|
3446
|
-
};
|
|
3447
|
-
Transaction = {
|
|
3448
|
-
struct: {
|
|
3449
|
-
signerId: "string",
|
|
3450
|
-
publicKey: this.PublicKey,
|
|
3451
|
-
nonce: "u64",
|
|
3452
|
-
receiverId: "string",
|
|
3453
|
-
blockHash: { array: { type: "u8", len: 32 } },
|
|
3454
|
-
actions: { array: { type: this.Action } }
|
|
3455
|
-
}
|
|
3456
|
-
};
|
|
3457
|
-
SignedTransaction = {
|
|
3458
|
-
struct: {
|
|
3459
|
-
transaction: this.Transaction,
|
|
3460
|
-
signature: this.Signature
|
|
3461
|
-
}
|
|
3462
|
-
};
|
|
3378
|
+
var nearChainSchema = new class BorshSchema {
|
|
3379
|
+
static {
|
|
3380
|
+
__name(this, "BorshSchema");
|
|
3463
3381
|
}
|
|
3464
|
-
|
|
3465
|
-
|
|
3382
|
+
Ed25519Signature = {
|
|
3383
|
+
struct: {
|
|
3384
|
+
data: { array: { type: "u8", len: 64 } }
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
Secp256k1Signature = {
|
|
3388
|
+
struct: {
|
|
3389
|
+
data: { array: { type: "u8", len: 65 } }
|
|
3390
|
+
}
|
|
3391
|
+
};
|
|
3392
|
+
Signature = {
|
|
3393
|
+
enum: [
|
|
3394
|
+
{ struct: { ed25519Signature: this.Ed25519Signature } },
|
|
3395
|
+
{ struct: { secp256k1Signature: this.Secp256k1Signature } }
|
|
3396
|
+
]
|
|
3397
|
+
};
|
|
3398
|
+
Ed25519Data = {
|
|
3399
|
+
struct: {
|
|
3400
|
+
data: { array: { type: "u8", len: 32 } }
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
Secp256k1Data = {
|
|
3404
|
+
struct: {
|
|
3405
|
+
data: { array: { type: "u8", len: 64 } }
|
|
3406
|
+
}
|
|
3407
|
+
};
|
|
3408
|
+
PublicKey = {
|
|
3409
|
+
enum: [
|
|
3410
|
+
{ struct: { ed25519Key: this.Ed25519Data } },
|
|
3411
|
+
{ struct: { secp256k1Key: this.Secp256k1Data } }
|
|
3412
|
+
]
|
|
3413
|
+
};
|
|
3414
|
+
FunctionCallPermission = {
|
|
3415
|
+
struct: {
|
|
3416
|
+
allowance: { option: "u128" },
|
|
3417
|
+
receiverId: "string",
|
|
3418
|
+
methodNames: { array: { type: "string" } }
|
|
3419
|
+
}
|
|
3420
|
+
};
|
|
3421
|
+
FullAccessPermission = {
|
|
3422
|
+
struct: {}
|
|
3423
|
+
};
|
|
3424
|
+
AccessKeyPermission = {
|
|
3425
|
+
enum: [
|
|
3426
|
+
{ struct: { functionCall: this.FunctionCallPermission } },
|
|
3427
|
+
{ struct: { fullAccess: this.FullAccessPermission } }
|
|
3428
|
+
]
|
|
3429
|
+
};
|
|
3430
|
+
AccessKey = {
|
|
3431
|
+
struct: {
|
|
3432
|
+
nonce: "u64",
|
|
3433
|
+
permission: this.AccessKeyPermission
|
|
3434
|
+
}
|
|
3435
|
+
};
|
|
3436
|
+
CreateAccount = {
|
|
3437
|
+
struct: {}
|
|
3438
|
+
};
|
|
3439
|
+
DeployContract = {
|
|
3440
|
+
struct: {
|
|
3441
|
+
code: { array: { type: "u8" } }
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
FunctionCall = {
|
|
3445
|
+
struct: {
|
|
3446
|
+
methodName: "string",
|
|
3447
|
+
args: { array: { type: "u8" } },
|
|
3448
|
+
gas: "u64",
|
|
3449
|
+
deposit: "u128"
|
|
3450
|
+
}
|
|
3451
|
+
};
|
|
3452
|
+
Transfer = {
|
|
3453
|
+
struct: {
|
|
3454
|
+
deposit: "u128"
|
|
3455
|
+
}
|
|
3456
|
+
};
|
|
3457
|
+
Stake = {
|
|
3458
|
+
struct: {
|
|
3459
|
+
stake: "u128",
|
|
3460
|
+
publicKey: this.PublicKey
|
|
3461
|
+
}
|
|
3462
|
+
};
|
|
3463
|
+
AddKey = {
|
|
3464
|
+
struct: {
|
|
3465
|
+
publicKey: this.PublicKey,
|
|
3466
|
+
accessKey: this.AccessKey
|
|
3467
|
+
}
|
|
3468
|
+
};
|
|
3469
|
+
DeleteKey = {
|
|
3470
|
+
struct: {
|
|
3471
|
+
publicKey: this.PublicKey
|
|
3472
|
+
}
|
|
3473
|
+
};
|
|
3474
|
+
DeleteAccount = {
|
|
3475
|
+
struct: {
|
|
3476
|
+
beneficiaryId: "string"
|
|
3477
|
+
}
|
|
3478
|
+
};
|
|
3479
|
+
ClassicAction = {
|
|
3480
|
+
enum: [
|
|
3481
|
+
{ struct: { createAccount: this.CreateAccount } },
|
|
3482
|
+
{ struct: { deployContract: this.DeployContract } },
|
|
3483
|
+
{ struct: { functionCall: this.FunctionCall } },
|
|
3484
|
+
{ struct: { transfer: this.Transfer } },
|
|
3485
|
+
{ struct: { stake: this.Stake } },
|
|
3486
|
+
{ struct: { addKey: this.AddKey } },
|
|
3487
|
+
{ struct: { deleteKey: this.DeleteKey } },
|
|
3488
|
+
{ struct: { deleteAccount: this.DeleteAccount } }
|
|
3489
|
+
]
|
|
3490
|
+
};
|
|
3491
|
+
DelegateAction = {
|
|
3492
|
+
struct: {
|
|
3493
|
+
senderId: "string",
|
|
3494
|
+
receiverId: "string",
|
|
3495
|
+
actions: { array: { type: this.ClassicAction } },
|
|
3496
|
+
nonce: "u64",
|
|
3497
|
+
maxBlockHeight: "u64",
|
|
3498
|
+
publicKey: this.PublicKey
|
|
3499
|
+
}
|
|
3500
|
+
};
|
|
3501
|
+
SignedDelegate = {
|
|
3502
|
+
struct: {
|
|
3503
|
+
delegateAction: this.DelegateAction,
|
|
3504
|
+
signature: this.Signature
|
|
3505
|
+
}
|
|
3506
|
+
};
|
|
3507
|
+
Action = {
|
|
3508
|
+
enum: [
|
|
3509
|
+
{ struct: { createAccount: this.CreateAccount } },
|
|
3510
|
+
{ struct: { deployContract: this.DeployContract } },
|
|
3511
|
+
{ struct: { functionCall: this.FunctionCall } },
|
|
3512
|
+
{ struct: { transfer: this.Transfer } },
|
|
3513
|
+
{ struct: { stake: this.Stake } },
|
|
3514
|
+
{ struct: { addKey: this.AddKey } },
|
|
3515
|
+
{ struct: { deleteKey: this.DeleteKey } },
|
|
3516
|
+
{ struct: { deleteAccount: this.DeleteAccount } },
|
|
3517
|
+
{ struct: { signedDelegate: this.SignedDelegate } }
|
|
3518
|
+
]
|
|
3519
|
+
};
|
|
3520
|
+
Transaction = {
|
|
3521
|
+
struct: {
|
|
3522
|
+
signerId: "string",
|
|
3523
|
+
publicKey: this.PublicKey,
|
|
3524
|
+
nonce: "u64",
|
|
3525
|
+
receiverId: "string",
|
|
3526
|
+
blockHash: { array: { type: "u8", len: 32 } },
|
|
3527
|
+
actions: { array: { type: this.Action } }
|
|
3528
|
+
}
|
|
3529
|
+
};
|
|
3530
|
+
SignedTransaction = {
|
|
3531
|
+
struct: {
|
|
3532
|
+
transaction: this.Transaction,
|
|
3533
|
+
signature: this.Signature
|
|
3534
|
+
}
|
|
3535
|
+
};
|
|
3536
|
+
}();
|
|
3537
|
+
var getBorshSchema = /* @__PURE__ */ __name(() => nearChainSchema, "getBorshSchema");
|
|
3466
3538
|
|
|
3467
3539
|
// src/transaction.ts
|
|
3540
|
+
var txToJson = /* @__PURE__ */ __name((tx) => {
|
|
3541
|
+
return JSON.parse(JSON.stringify(
|
|
3542
|
+
tx,
|
|
3543
|
+
(key, value) => typeof value === "bigint" ? value.toString() : value
|
|
3544
|
+
));
|
|
3545
|
+
}, "txToJson");
|
|
3546
|
+
var txToJsonStringified = /* @__PURE__ */ __name((tx) => {
|
|
3547
|
+
return JSON.stringify(txToJson(tx));
|
|
3548
|
+
}, "txToJsonStringified");
|
|
3468
3549
|
function mapTransaction(jsonTransaction) {
|
|
3469
3550
|
return {
|
|
3470
3551
|
signerId: jsonTransaction.signerId,
|
|
@@ -3481,20 +3562,29 @@ var NearUtils = (() => {
|
|
|
3481
3562
|
}
|
|
3482
3563
|
__name(mapTransaction, "mapTransaction");
|
|
3483
3564
|
function serializeTransaction(jsonTransaction) {
|
|
3565
|
+
console.log("fastnear: serializing transaction");
|
|
3484
3566
|
const transaction = mapTransaction(jsonTransaction);
|
|
3567
|
+
console.log("fastnear: mapped transaction for borsh:", transaction);
|
|
3485
3568
|
return serialize(SCHEMA.Transaction, transaction);
|
|
3486
3569
|
}
|
|
3487
3570
|
__name(serializeTransaction, "serializeTransaction");
|
|
3488
3571
|
function serializeSignedTransaction(jsonTransaction, signature) {
|
|
3489
|
-
|
|
3490
|
-
|
|
3572
|
+
console.log("fastnear: Serializing Signed Transaction", jsonTransaction);
|
|
3573
|
+
console.log("fastnear: signature", signature);
|
|
3574
|
+
console.log("fastnear: signature length", base58_to_binary_default(signature).length);
|
|
3575
|
+
const mappedSignedTx = mapTransaction(jsonTransaction);
|
|
3576
|
+
console.log("fastnear: mapped (for borsh schema) signed transaction", mappedSignedTx);
|
|
3577
|
+
const plainSignedTransaction = {
|
|
3578
|
+
transaction: mappedSignedTx,
|
|
3491
3579
|
signature: {
|
|
3492
3580
|
ed25519Signature: {
|
|
3493
3581
|
data: base58_to_binary_default(signature)
|
|
3494
3582
|
}
|
|
3495
3583
|
}
|
|
3496
3584
|
};
|
|
3497
|
-
|
|
3585
|
+
const borshSignedTx = serialize(SCHEMA.SignedTransaction, plainSignedTransaction, true);
|
|
3586
|
+
console.log("fastnear: borsh-serialized signed transaction:", borshSignedTx);
|
|
3587
|
+
return borshSignedTx;
|
|
3498
3588
|
}
|
|
3499
3589
|
__name(serializeSignedTransaction, "serializeSignedTransaction");
|
|
3500
3590
|
function mapAction(action) {
|
|
@@ -3512,10 +3602,12 @@ var NearUtils = (() => {
|
|
|
3512
3602
|
};
|
|
3513
3603
|
}
|
|
3514
3604
|
case "FunctionCall": {
|
|
3605
|
+
const argsAsString = JSON.stringify(action.args);
|
|
3606
|
+
const argsEncoded = new TextEncoder().encode(argsAsString);
|
|
3515
3607
|
return {
|
|
3516
3608
|
functionCall: {
|
|
3517
3609
|
methodName: action.methodName,
|
|
3518
|
-
args:
|
|
3610
|
+
args: argsEncoded,
|
|
3519
3611
|
gas: BigInt(action.gas),
|
|
3520
3612
|
deposit: BigInt(action.deposit)
|
|
3521
3613
|
}
|
|
@@ -3595,7 +3687,16 @@ var NearUtils = (() => {
|
|
|
3595
3687
|
}
|
|
3596
3688
|
}
|
|
3597
3689
|
__name(mapAction, "mapAction");
|
|
3598
|
-
var SCHEMA = getBorshSchema;
|
|
3690
|
+
var SCHEMA = getBorshSchema();
|
|
3691
|
+
|
|
3692
|
+
// src/index.ts
|
|
3693
|
+
var exp = {
|
|
3694
|
+
borsh: {
|
|
3695
|
+
serialize,
|
|
3696
|
+
deserialize
|
|
3697
|
+
},
|
|
3698
|
+
borshSchema: src_exports
|
|
3699
|
+
};
|
|
3599
3700
|
return __toCommonJS(src_exports2);
|
|
3600
3701
|
})();
|
|
3601
3702
|
/*! Bundled license information:
|
|
@@ -3622,15 +3723,10 @@ var NearUtils = (() => {
|
|
|
3622
3723
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3623
3724
|
*/
|
|
3624
3725
|
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
writable: false,
|
|
3631
|
-
enumerable: true,
|
|
3632
|
-
configurable: false,
|
|
3633
|
-
});
|
|
3634
|
-
}
|
|
3726
|
+
Object.defineProperty(globalThis, 'NearUtils', {
|
|
3727
|
+
value: NearUtils,
|
|
3728
|
+
enumerable: true,
|
|
3729
|
+
configurable: false,
|
|
3730
|
+
});
|
|
3635
3731
|
|
|
3636
3732
|
//# sourceMappingURL=browser.global.js.map
|