@fastnear/utils 0.6.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 +47 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +3228 -0
- package/dist/esm/index.d.ts +3228 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/umd/browser.global.js +3636 -0
- package/dist/umd/browser.global.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,3636 @@
|
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR Utils - IIFE/UMD (@fastnear/utils version 0.6.0) */
|
|
2
|
+
/* https://www.npmjs.com/package/@fastnear/utils/v/0.6.0 */
|
|
3
|
+
var NearUtils = (() => {
|
|
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 __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
12
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
13
|
+
}) : x)(function(x) {
|
|
14
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
15
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
16
|
+
});
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
35
|
+
mod2
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
var src_exports2 = {};
|
|
41
|
+
__export(src_exports2, {
|
|
42
|
+
SCHEMA: () => SCHEMA,
|
|
43
|
+
canSignWithLAK: () => canSignWithLAK,
|
|
44
|
+
convertUnit: () => convertUnit,
|
|
45
|
+
deepCopy: () => deepCopy,
|
|
46
|
+
fromBase58: () => base58_to_binary_default,
|
|
47
|
+
fromBase64: () => fromBase64,
|
|
48
|
+
keyFromString: () => keyFromString,
|
|
49
|
+
keyToString: () => keyToString,
|
|
50
|
+
lsGet: () => lsGet,
|
|
51
|
+
lsSet: () => lsSet,
|
|
52
|
+
mapAction: () => mapAction,
|
|
53
|
+
mapTransaction: () => mapTransaction,
|
|
54
|
+
parseJsonFromBytes: () => parseJsonFromBytes,
|
|
55
|
+
privateKeyFromRandom: () => privateKeyFromRandom,
|
|
56
|
+
publicKeyFromPrivate: () => publicKeyFromPrivate,
|
|
57
|
+
reExportBorshSchema: () => src_exports,
|
|
58
|
+
serializeSignedTransaction: () => serializeSignedTransaction,
|
|
59
|
+
serializeTransaction: () => serializeTransaction,
|
|
60
|
+
sha256: () => sha256,
|
|
61
|
+
signBytes: () => signBytes,
|
|
62
|
+
signHash: () => signHash,
|
|
63
|
+
toBase58: () => binary_to_base58_default,
|
|
64
|
+
toBase64: () => toBase64,
|
|
65
|
+
tryParseJson: () => tryParseJson
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/_assert.js
|
|
69
|
+
function isBytes(a) {
|
|
70
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
71
|
+
}
|
|
72
|
+
__name(isBytes, "isBytes");
|
|
73
|
+
function abytes(b, ...lengths) {
|
|
74
|
+
if (!isBytes(b))
|
|
75
|
+
throw new Error("Uint8Array expected");
|
|
76
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
77
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
78
|
+
}
|
|
79
|
+
__name(abytes, "abytes");
|
|
80
|
+
function aexists(instance, checkFinished = true) {
|
|
81
|
+
if (instance.destroyed)
|
|
82
|
+
throw new Error("Hash instance has been destroyed");
|
|
83
|
+
if (checkFinished && instance.finished)
|
|
84
|
+
throw new Error("Hash#digest() has already been called");
|
|
85
|
+
}
|
|
86
|
+
__name(aexists, "aexists");
|
|
87
|
+
function aoutput(out, instance) {
|
|
88
|
+
abytes(out);
|
|
89
|
+
const min = instance.outputLen;
|
|
90
|
+
if (out.length < min) {
|
|
91
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
__name(aoutput, "aoutput");
|
|
95
|
+
|
|
96
|
+
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/cryptoNode.js
|
|
97
|
+
var nc = __toESM(__require("node:crypto"), 1);
|
|
98
|
+
var crypto2 = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
|
|
99
|
+
|
|
100
|
+
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/utils.js
|
|
101
|
+
var createView = /* @__PURE__ */ __name((arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength), "createView");
|
|
102
|
+
function utf8ToBytes(str) {
|
|
103
|
+
if (typeof str !== "string")
|
|
104
|
+
throw new Error("utf8ToBytes expected string, got " + typeof str);
|
|
105
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
106
|
+
}
|
|
107
|
+
__name(utf8ToBytes, "utf8ToBytes");
|
|
108
|
+
function toBytes(data) {
|
|
109
|
+
if (typeof data === "string")
|
|
110
|
+
data = utf8ToBytes(data);
|
|
111
|
+
abytes(data);
|
|
112
|
+
return data;
|
|
113
|
+
}
|
|
114
|
+
__name(toBytes, "toBytes");
|
|
115
|
+
var Hash = class {
|
|
116
|
+
static {
|
|
117
|
+
__name(this, "Hash");
|
|
118
|
+
}
|
|
119
|
+
// Safe version that clones internal state
|
|
120
|
+
clone() {
|
|
121
|
+
return this._cloneInto();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
function wrapConstructor(hashCons) {
|
|
125
|
+
const hashC = /* @__PURE__ */ __name((msg) => hashCons().update(toBytes(msg)).digest(), "hashC");
|
|
126
|
+
const tmp = hashCons();
|
|
127
|
+
hashC.outputLen = tmp.outputLen;
|
|
128
|
+
hashC.blockLen = tmp.blockLen;
|
|
129
|
+
hashC.create = () => hashCons();
|
|
130
|
+
return hashC;
|
|
131
|
+
}
|
|
132
|
+
__name(wrapConstructor, "wrapConstructor");
|
|
133
|
+
function randomBytes(bytesLength = 32) {
|
|
134
|
+
if (crypto2 && typeof crypto2.getRandomValues === "function") {
|
|
135
|
+
return crypto2.getRandomValues(new Uint8Array(bytesLength));
|
|
136
|
+
}
|
|
137
|
+
if (crypto2 && typeof crypto2.randomBytes === "function") {
|
|
138
|
+
return crypto2.randomBytes(bytesLength);
|
|
139
|
+
}
|
|
140
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
141
|
+
}
|
|
142
|
+
__name(randomBytes, "randomBytes");
|
|
143
|
+
|
|
144
|
+
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/_md.js
|
|
145
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
146
|
+
if (typeof view.setBigUint64 === "function")
|
|
147
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
148
|
+
const _32n2 = BigInt(32);
|
|
149
|
+
const _u32_max = BigInt(4294967295);
|
|
150
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
151
|
+
const wl = Number(value & _u32_max);
|
|
152
|
+
const h = isLE ? 4 : 0;
|
|
153
|
+
const l = isLE ? 0 : 4;
|
|
154
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
155
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
156
|
+
}
|
|
157
|
+
__name(setBigUint64, "setBigUint64");
|
|
158
|
+
var HashMD = class extends Hash {
|
|
159
|
+
static {
|
|
160
|
+
__name(this, "HashMD");
|
|
161
|
+
}
|
|
162
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
163
|
+
super();
|
|
164
|
+
this.blockLen = blockLen;
|
|
165
|
+
this.outputLen = outputLen;
|
|
166
|
+
this.padOffset = padOffset;
|
|
167
|
+
this.isLE = isLE;
|
|
168
|
+
this.finished = false;
|
|
169
|
+
this.length = 0;
|
|
170
|
+
this.pos = 0;
|
|
171
|
+
this.destroyed = false;
|
|
172
|
+
this.buffer = new Uint8Array(blockLen);
|
|
173
|
+
this.view = createView(this.buffer);
|
|
174
|
+
}
|
|
175
|
+
update(data) {
|
|
176
|
+
aexists(this);
|
|
177
|
+
const { view, buffer, blockLen } = this;
|
|
178
|
+
data = toBytes(data);
|
|
179
|
+
const len = data.length;
|
|
180
|
+
for (let pos = 0; pos < len; ) {
|
|
181
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
182
|
+
if (take === blockLen) {
|
|
183
|
+
const dataView = createView(data);
|
|
184
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
185
|
+
this.process(dataView, pos);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
189
|
+
this.pos += take;
|
|
190
|
+
pos += take;
|
|
191
|
+
if (this.pos === blockLen) {
|
|
192
|
+
this.process(view, 0);
|
|
193
|
+
this.pos = 0;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
this.length += data.length;
|
|
197
|
+
this.roundClean();
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
digestInto(out) {
|
|
201
|
+
aexists(this);
|
|
202
|
+
aoutput(out, this);
|
|
203
|
+
this.finished = true;
|
|
204
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
205
|
+
let { pos } = this;
|
|
206
|
+
buffer[pos++] = 128;
|
|
207
|
+
this.buffer.subarray(pos).fill(0);
|
|
208
|
+
if (this.padOffset > blockLen - pos) {
|
|
209
|
+
this.process(view, 0);
|
|
210
|
+
pos = 0;
|
|
211
|
+
}
|
|
212
|
+
for (let i = pos; i < blockLen; i++)
|
|
213
|
+
buffer[i] = 0;
|
|
214
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
215
|
+
this.process(view, 0);
|
|
216
|
+
const oview = createView(out);
|
|
217
|
+
const len = this.outputLen;
|
|
218
|
+
if (len % 4)
|
|
219
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
220
|
+
const outLen = len / 4;
|
|
221
|
+
const state = this.get();
|
|
222
|
+
if (outLen > state.length)
|
|
223
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
224
|
+
for (let i = 0; i < outLen; i++)
|
|
225
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
226
|
+
}
|
|
227
|
+
digest() {
|
|
228
|
+
const { buffer, outputLen } = this;
|
|
229
|
+
this.digestInto(buffer);
|
|
230
|
+
const res = buffer.slice(0, outputLen);
|
|
231
|
+
this.destroy();
|
|
232
|
+
return res;
|
|
233
|
+
}
|
|
234
|
+
_cloneInto(to) {
|
|
235
|
+
to || (to = new this.constructor());
|
|
236
|
+
to.set(...this.get());
|
|
237
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
238
|
+
to.length = length;
|
|
239
|
+
to.pos = pos;
|
|
240
|
+
to.finished = finished;
|
|
241
|
+
to.destroyed = destroyed;
|
|
242
|
+
if (length % blockLen)
|
|
243
|
+
to.buffer.set(buffer);
|
|
244
|
+
return to;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/_u64.js
|
|
249
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
250
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
251
|
+
function fromBig(n, le = false) {
|
|
252
|
+
if (le)
|
|
253
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
254
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
255
|
+
}
|
|
256
|
+
__name(fromBig, "fromBig");
|
|
257
|
+
function split(lst, le = false) {
|
|
258
|
+
let Ah = new Uint32Array(lst.length);
|
|
259
|
+
let Al = new Uint32Array(lst.length);
|
|
260
|
+
for (let i = 0; i < lst.length; i++) {
|
|
261
|
+
const { h, l } = fromBig(lst[i], le);
|
|
262
|
+
[Ah[i], Al[i]] = [h, l];
|
|
263
|
+
}
|
|
264
|
+
return [Ah, Al];
|
|
265
|
+
}
|
|
266
|
+
__name(split, "split");
|
|
267
|
+
var toBig = /* @__PURE__ */ __name((h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0), "toBig");
|
|
268
|
+
var shrSH = /* @__PURE__ */ __name((h, _l, s) => h >>> s, "shrSH");
|
|
269
|
+
var shrSL = /* @__PURE__ */ __name((h, l, s) => h << 32 - s | l >>> s, "shrSL");
|
|
270
|
+
var rotrSH = /* @__PURE__ */ __name((h, l, s) => h >>> s | l << 32 - s, "rotrSH");
|
|
271
|
+
var rotrSL = /* @__PURE__ */ __name((h, l, s) => h << 32 - s | l >>> s, "rotrSL");
|
|
272
|
+
var rotrBH = /* @__PURE__ */ __name((h, l, s) => h << 64 - s | l >>> s - 32, "rotrBH");
|
|
273
|
+
var rotrBL = /* @__PURE__ */ __name((h, l, s) => h >>> s - 32 | l << 64 - s, "rotrBL");
|
|
274
|
+
var rotr32H = /* @__PURE__ */ __name((_h, l) => l, "rotr32H");
|
|
275
|
+
var rotr32L = /* @__PURE__ */ __name((h, _l) => h, "rotr32L");
|
|
276
|
+
var rotlSH = /* @__PURE__ */ __name((h, l, s) => h << s | l >>> 32 - s, "rotlSH");
|
|
277
|
+
var rotlSL = /* @__PURE__ */ __name((h, l, s) => l << s | h >>> 32 - s, "rotlSL");
|
|
278
|
+
var rotlBH = /* @__PURE__ */ __name((h, l, s) => l << s - 32 | h >>> 64 - s, "rotlBH");
|
|
279
|
+
var rotlBL = /* @__PURE__ */ __name((h, l, s) => h << s - 32 | l >>> 64 - s, "rotlBL");
|
|
280
|
+
function add(Ah, Al, Bh, Bl) {
|
|
281
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
282
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
283
|
+
}
|
|
284
|
+
__name(add, "add");
|
|
285
|
+
var add3L = /* @__PURE__ */ __name((Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0), "add3L");
|
|
286
|
+
var add3H = /* @__PURE__ */ __name((low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0, "add3H");
|
|
287
|
+
var add4L = /* @__PURE__ */ __name((Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0), "add4L");
|
|
288
|
+
var add4H = /* @__PURE__ */ __name((low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0, "add4H");
|
|
289
|
+
var add5L = /* @__PURE__ */ __name((Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0), "add5L");
|
|
290
|
+
var add5H = /* @__PURE__ */ __name((low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0, "add5H");
|
|
291
|
+
var u64 = {
|
|
292
|
+
fromBig,
|
|
293
|
+
split,
|
|
294
|
+
toBig,
|
|
295
|
+
shrSH,
|
|
296
|
+
shrSL,
|
|
297
|
+
rotrSH,
|
|
298
|
+
rotrSL,
|
|
299
|
+
rotrBH,
|
|
300
|
+
rotrBL,
|
|
301
|
+
rotr32H,
|
|
302
|
+
rotr32L,
|
|
303
|
+
rotlSH,
|
|
304
|
+
rotlSL,
|
|
305
|
+
rotlBH,
|
|
306
|
+
rotlBL,
|
|
307
|
+
add,
|
|
308
|
+
add3L,
|
|
309
|
+
add3H,
|
|
310
|
+
add4L,
|
|
311
|
+
add4H,
|
|
312
|
+
add5H,
|
|
313
|
+
add5L
|
|
314
|
+
};
|
|
315
|
+
var u64_default = u64;
|
|
316
|
+
|
|
317
|
+
// ../../node_modules/@noble/curves/node_modules/@noble/hashes/esm/sha512.js
|
|
318
|
+
var [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64_default.split([
|
|
319
|
+
"0x428a2f98d728ae22",
|
|
320
|
+
"0x7137449123ef65cd",
|
|
321
|
+
"0xb5c0fbcfec4d3b2f",
|
|
322
|
+
"0xe9b5dba58189dbbc",
|
|
323
|
+
"0x3956c25bf348b538",
|
|
324
|
+
"0x59f111f1b605d019",
|
|
325
|
+
"0x923f82a4af194f9b",
|
|
326
|
+
"0xab1c5ed5da6d8118",
|
|
327
|
+
"0xd807aa98a3030242",
|
|
328
|
+
"0x12835b0145706fbe",
|
|
329
|
+
"0x243185be4ee4b28c",
|
|
330
|
+
"0x550c7dc3d5ffb4e2",
|
|
331
|
+
"0x72be5d74f27b896f",
|
|
332
|
+
"0x80deb1fe3b1696b1",
|
|
333
|
+
"0x9bdc06a725c71235",
|
|
334
|
+
"0xc19bf174cf692694",
|
|
335
|
+
"0xe49b69c19ef14ad2",
|
|
336
|
+
"0xefbe4786384f25e3",
|
|
337
|
+
"0x0fc19dc68b8cd5b5",
|
|
338
|
+
"0x240ca1cc77ac9c65",
|
|
339
|
+
"0x2de92c6f592b0275",
|
|
340
|
+
"0x4a7484aa6ea6e483",
|
|
341
|
+
"0x5cb0a9dcbd41fbd4",
|
|
342
|
+
"0x76f988da831153b5",
|
|
343
|
+
"0x983e5152ee66dfab",
|
|
344
|
+
"0xa831c66d2db43210",
|
|
345
|
+
"0xb00327c898fb213f",
|
|
346
|
+
"0xbf597fc7beef0ee4",
|
|
347
|
+
"0xc6e00bf33da88fc2",
|
|
348
|
+
"0xd5a79147930aa725",
|
|
349
|
+
"0x06ca6351e003826f",
|
|
350
|
+
"0x142929670a0e6e70",
|
|
351
|
+
"0x27b70a8546d22ffc",
|
|
352
|
+
"0x2e1b21385c26c926",
|
|
353
|
+
"0x4d2c6dfc5ac42aed",
|
|
354
|
+
"0x53380d139d95b3df",
|
|
355
|
+
"0x650a73548baf63de",
|
|
356
|
+
"0x766a0abb3c77b2a8",
|
|
357
|
+
"0x81c2c92e47edaee6",
|
|
358
|
+
"0x92722c851482353b",
|
|
359
|
+
"0xa2bfe8a14cf10364",
|
|
360
|
+
"0xa81a664bbc423001",
|
|
361
|
+
"0xc24b8b70d0f89791",
|
|
362
|
+
"0xc76c51a30654be30",
|
|
363
|
+
"0xd192e819d6ef5218",
|
|
364
|
+
"0xd69906245565a910",
|
|
365
|
+
"0xf40e35855771202a",
|
|
366
|
+
"0x106aa07032bbd1b8",
|
|
367
|
+
"0x19a4c116b8d2d0c8",
|
|
368
|
+
"0x1e376c085141ab53",
|
|
369
|
+
"0x2748774cdf8eeb99",
|
|
370
|
+
"0x34b0bcb5e19b48a8",
|
|
371
|
+
"0x391c0cb3c5c95a63",
|
|
372
|
+
"0x4ed8aa4ae3418acb",
|
|
373
|
+
"0x5b9cca4f7763e373",
|
|
374
|
+
"0x682e6ff3d6b2b8a3",
|
|
375
|
+
"0x748f82ee5defb2fc",
|
|
376
|
+
"0x78a5636f43172f60",
|
|
377
|
+
"0x84c87814a1f0ab72",
|
|
378
|
+
"0x8cc702081a6439ec",
|
|
379
|
+
"0x90befffa23631e28",
|
|
380
|
+
"0xa4506cebde82bde9",
|
|
381
|
+
"0xbef9a3f7b2c67915",
|
|
382
|
+
"0xc67178f2e372532b",
|
|
383
|
+
"0xca273eceea26619c",
|
|
384
|
+
"0xd186b8c721c0c207",
|
|
385
|
+
"0xeada7dd6cde0eb1e",
|
|
386
|
+
"0xf57d4f7fee6ed178",
|
|
387
|
+
"0x06f067aa72176fba",
|
|
388
|
+
"0x0a637dc5a2c898a6",
|
|
389
|
+
"0x113f9804bef90dae",
|
|
390
|
+
"0x1b710b35131c471b",
|
|
391
|
+
"0x28db77f523047d84",
|
|
392
|
+
"0x32caab7b40c72493",
|
|
393
|
+
"0x3c9ebe0a15c9bebc",
|
|
394
|
+
"0x431d67c49c100d4c",
|
|
395
|
+
"0x4cc5d4becb3e42b6",
|
|
396
|
+
"0x597f299cfc657e2a",
|
|
397
|
+
"0x5fcb6fab3ad6faec",
|
|
398
|
+
"0x6c44198c4a475817"
|
|
399
|
+
].map((n) => BigInt(n))))();
|
|
400
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
401
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
402
|
+
var SHA512 = class extends HashMD {
|
|
403
|
+
static {
|
|
404
|
+
__name(this, "SHA512");
|
|
405
|
+
}
|
|
406
|
+
constructor() {
|
|
407
|
+
super(128, 64, 16, false);
|
|
408
|
+
this.Ah = 1779033703 | 0;
|
|
409
|
+
this.Al = 4089235720 | 0;
|
|
410
|
+
this.Bh = 3144134277 | 0;
|
|
411
|
+
this.Bl = 2227873595 | 0;
|
|
412
|
+
this.Ch = 1013904242 | 0;
|
|
413
|
+
this.Cl = 4271175723 | 0;
|
|
414
|
+
this.Dh = 2773480762 | 0;
|
|
415
|
+
this.Dl = 1595750129 | 0;
|
|
416
|
+
this.Eh = 1359893119 | 0;
|
|
417
|
+
this.El = 2917565137 | 0;
|
|
418
|
+
this.Fh = 2600822924 | 0;
|
|
419
|
+
this.Fl = 725511199 | 0;
|
|
420
|
+
this.Gh = 528734635 | 0;
|
|
421
|
+
this.Gl = 4215389547 | 0;
|
|
422
|
+
this.Hh = 1541459225 | 0;
|
|
423
|
+
this.Hl = 327033209 | 0;
|
|
424
|
+
}
|
|
425
|
+
// prettier-ignore
|
|
426
|
+
get() {
|
|
427
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
428
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
429
|
+
}
|
|
430
|
+
// prettier-ignore
|
|
431
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
432
|
+
this.Ah = Ah | 0;
|
|
433
|
+
this.Al = Al | 0;
|
|
434
|
+
this.Bh = Bh | 0;
|
|
435
|
+
this.Bl = Bl | 0;
|
|
436
|
+
this.Ch = Ch | 0;
|
|
437
|
+
this.Cl = Cl | 0;
|
|
438
|
+
this.Dh = Dh | 0;
|
|
439
|
+
this.Dl = Dl | 0;
|
|
440
|
+
this.Eh = Eh | 0;
|
|
441
|
+
this.El = El | 0;
|
|
442
|
+
this.Fh = Fh | 0;
|
|
443
|
+
this.Fl = Fl | 0;
|
|
444
|
+
this.Gh = Gh | 0;
|
|
445
|
+
this.Gl = Gl | 0;
|
|
446
|
+
this.Hh = Hh | 0;
|
|
447
|
+
this.Hl = Hl | 0;
|
|
448
|
+
}
|
|
449
|
+
process(view, offset) {
|
|
450
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
451
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
452
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
453
|
+
}
|
|
454
|
+
for (let i = 16; i < 80; i++) {
|
|
455
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
456
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
457
|
+
const s0h = u64_default.rotrSH(W15h, W15l, 1) ^ u64_default.rotrSH(W15h, W15l, 8) ^ u64_default.shrSH(W15h, W15l, 7);
|
|
458
|
+
const s0l = u64_default.rotrSL(W15h, W15l, 1) ^ u64_default.rotrSL(W15h, W15l, 8) ^ u64_default.shrSL(W15h, W15l, 7);
|
|
459
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
460
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
461
|
+
const s1h = u64_default.rotrSH(W2h, W2l, 19) ^ u64_default.rotrBH(W2h, W2l, 61) ^ u64_default.shrSH(W2h, W2l, 6);
|
|
462
|
+
const s1l = u64_default.rotrSL(W2h, W2l, 19) ^ u64_default.rotrBL(W2h, W2l, 61) ^ u64_default.shrSL(W2h, W2l, 6);
|
|
463
|
+
const SUMl = u64_default.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
464
|
+
const SUMh = u64_default.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
465
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
466
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
467
|
+
}
|
|
468
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
469
|
+
for (let i = 0; i < 80; i++) {
|
|
470
|
+
const sigma1h = u64_default.rotrSH(Eh, El, 14) ^ u64_default.rotrSH(Eh, El, 18) ^ u64_default.rotrBH(Eh, El, 41);
|
|
471
|
+
const sigma1l = u64_default.rotrSL(Eh, El, 14) ^ u64_default.rotrSL(Eh, El, 18) ^ u64_default.rotrBL(Eh, El, 41);
|
|
472
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
473
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
474
|
+
const T1ll = u64_default.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
475
|
+
const T1h = u64_default.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
476
|
+
const T1l = T1ll | 0;
|
|
477
|
+
const sigma0h = u64_default.rotrSH(Ah, Al, 28) ^ u64_default.rotrBH(Ah, Al, 34) ^ u64_default.rotrBH(Ah, Al, 39);
|
|
478
|
+
const sigma0l = u64_default.rotrSL(Ah, Al, 28) ^ u64_default.rotrBL(Ah, Al, 34) ^ u64_default.rotrBL(Ah, Al, 39);
|
|
479
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
480
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
481
|
+
Hh = Gh | 0;
|
|
482
|
+
Hl = Gl | 0;
|
|
483
|
+
Gh = Fh | 0;
|
|
484
|
+
Gl = Fl | 0;
|
|
485
|
+
Fh = Eh | 0;
|
|
486
|
+
Fl = El | 0;
|
|
487
|
+
({ h: Eh, l: El } = u64_default.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
488
|
+
Dh = Ch | 0;
|
|
489
|
+
Dl = Cl | 0;
|
|
490
|
+
Ch = Bh | 0;
|
|
491
|
+
Cl = Bl | 0;
|
|
492
|
+
Bh = Ah | 0;
|
|
493
|
+
Bl = Al | 0;
|
|
494
|
+
const All = u64_default.add3L(T1l, sigma0l, MAJl);
|
|
495
|
+
Ah = u64_default.add3H(All, T1h, sigma0h, MAJh);
|
|
496
|
+
Al = All | 0;
|
|
497
|
+
}
|
|
498
|
+
({ h: Ah, l: Al } = u64_default.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
499
|
+
({ h: Bh, l: Bl } = u64_default.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
500
|
+
({ h: Ch, l: Cl } = u64_default.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
501
|
+
({ h: Dh, l: Dl } = u64_default.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
502
|
+
({ h: Eh, l: El } = u64_default.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
503
|
+
({ h: Fh, l: Fl } = u64_default.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
504
|
+
({ h: Gh, l: Gl } = u64_default.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
505
|
+
({ h: Hh, l: Hl } = u64_default.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
506
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
507
|
+
}
|
|
508
|
+
roundClean() {
|
|
509
|
+
SHA512_W_H.fill(0);
|
|
510
|
+
SHA512_W_L.fill(0);
|
|
511
|
+
}
|
|
512
|
+
destroy() {
|
|
513
|
+
this.buffer.fill(0);
|
|
514
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
var sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA512());
|
|
518
|
+
|
|
519
|
+
// ../../node_modules/@noble/curves/esm/abstract/utils.js
|
|
520
|
+
var _0n = /* @__PURE__ */ BigInt(0);
|
|
521
|
+
var _1n = /* @__PURE__ */ BigInt(1);
|
|
522
|
+
var _2n = /* @__PURE__ */ BigInt(2);
|
|
523
|
+
function isBytes2(a) {
|
|
524
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
525
|
+
}
|
|
526
|
+
__name(isBytes2, "isBytes");
|
|
527
|
+
function abytes2(item) {
|
|
528
|
+
if (!isBytes2(item))
|
|
529
|
+
throw new Error("Uint8Array expected");
|
|
530
|
+
}
|
|
531
|
+
__name(abytes2, "abytes");
|
|
532
|
+
function abool(title, value) {
|
|
533
|
+
if (typeof value !== "boolean")
|
|
534
|
+
throw new Error(title + " boolean expected, got " + value);
|
|
535
|
+
}
|
|
536
|
+
__name(abool, "abool");
|
|
537
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
538
|
+
function bytesToHex(bytes) {
|
|
539
|
+
abytes2(bytes);
|
|
540
|
+
let hex = "";
|
|
541
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
542
|
+
hex += hexes[bytes[i]];
|
|
543
|
+
}
|
|
544
|
+
return hex;
|
|
545
|
+
}
|
|
546
|
+
__name(bytesToHex, "bytesToHex");
|
|
547
|
+
function hexToNumber(hex) {
|
|
548
|
+
if (typeof hex !== "string")
|
|
549
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
550
|
+
return hex === "" ? _0n : BigInt("0x" + hex);
|
|
551
|
+
}
|
|
552
|
+
__name(hexToNumber, "hexToNumber");
|
|
553
|
+
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
554
|
+
function asciiToBase16(ch) {
|
|
555
|
+
if (ch >= asciis._0 && ch <= asciis._9)
|
|
556
|
+
return ch - asciis._0;
|
|
557
|
+
if (ch >= asciis.A && ch <= asciis.F)
|
|
558
|
+
return ch - (asciis.A - 10);
|
|
559
|
+
if (ch >= asciis.a && ch <= asciis.f)
|
|
560
|
+
return ch - (asciis.a - 10);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
__name(asciiToBase16, "asciiToBase16");
|
|
564
|
+
function hexToBytes(hex) {
|
|
565
|
+
if (typeof hex !== "string")
|
|
566
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
567
|
+
const hl = hex.length;
|
|
568
|
+
const al = hl / 2;
|
|
569
|
+
if (hl % 2)
|
|
570
|
+
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
571
|
+
const array = new Uint8Array(al);
|
|
572
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
573
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
574
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
575
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
576
|
+
const char = hex[hi] + hex[hi + 1];
|
|
577
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
578
|
+
}
|
|
579
|
+
array[ai] = n1 * 16 + n2;
|
|
580
|
+
}
|
|
581
|
+
return array;
|
|
582
|
+
}
|
|
583
|
+
__name(hexToBytes, "hexToBytes");
|
|
584
|
+
function bytesToNumberBE(bytes) {
|
|
585
|
+
return hexToNumber(bytesToHex(bytes));
|
|
586
|
+
}
|
|
587
|
+
__name(bytesToNumberBE, "bytesToNumberBE");
|
|
588
|
+
function bytesToNumberLE(bytes) {
|
|
589
|
+
abytes2(bytes);
|
|
590
|
+
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
591
|
+
}
|
|
592
|
+
__name(bytesToNumberLE, "bytesToNumberLE");
|
|
593
|
+
function numberToBytesBE(n, len) {
|
|
594
|
+
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
595
|
+
}
|
|
596
|
+
__name(numberToBytesBE, "numberToBytesBE");
|
|
597
|
+
function numberToBytesLE(n, len) {
|
|
598
|
+
return numberToBytesBE(n, len).reverse();
|
|
599
|
+
}
|
|
600
|
+
__name(numberToBytesLE, "numberToBytesLE");
|
|
601
|
+
function ensureBytes(title, hex, expectedLength) {
|
|
602
|
+
let res;
|
|
603
|
+
if (typeof hex === "string") {
|
|
604
|
+
try {
|
|
605
|
+
res = hexToBytes(hex);
|
|
606
|
+
} catch (e) {
|
|
607
|
+
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
608
|
+
}
|
|
609
|
+
} else if (isBytes2(hex)) {
|
|
610
|
+
res = Uint8Array.from(hex);
|
|
611
|
+
} else {
|
|
612
|
+
throw new Error(title + " must be hex string or Uint8Array");
|
|
613
|
+
}
|
|
614
|
+
const len = res.length;
|
|
615
|
+
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
616
|
+
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
617
|
+
return res;
|
|
618
|
+
}
|
|
619
|
+
__name(ensureBytes, "ensureBytes");
|
|
620
|
+
function concatBytes(...arrays) {
|
|
621
|
+
let sum = 0;
|
|
622
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
623
|
+
const a = arrays[i];
|
|
624
|
+
abytes2(a);
|
|
625
|
+
sum += a.length;
|
|
626
|
+
}
|
|
627
|
+
const res = new Uint8Array(sum);
|
|
628
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
629
|
+
const a = arrays[i];
|
|
630
|
+
res.set(a, pad);
|
|
631
|
+
pad += a.length;
|
|
632
|
+
}
|
|
633
|
+
return res;
|
|
634
|
+
}
|
|
635
|
+
__name(concatBytes, "concatBytes");
|
|
636
|
+
var isPosBig = /* @__PURE__ */ __name((n) => typeof n === "bigint" && _0n <= n, "isPosBig");
|
|
637
|
+
function inRange(n, min, max) {
|
|
638
|
+
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
639
|
+
}
|
|
640
|
+
__name(inRange, "inRange");
|
|
641
|
+
function aInRange(title, n, min, max) {
|
|
642
|
+
if (!inRange(n, min, max))
|
|
643
|
+
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
644
|
+
}
|
|
645
|
+
__name(aInRange, "aInRange");
|
|
646
|
+
function bitLen(n) {
|
|
647
|
+
let len;
|
|
648
|
+
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
649
|
+
;
|
|
650
|
+
return len;
|
|
651
|
+
}
|
|
652
|
+
__name(bitLen, "bitLen");
|
|
653
|
+
var bitMask = /* @__PURE__ */ __name((n) => (_2n << BigInt(n - 1)) - _1n, "bitMask");
|
|
654
|
+
var validatorFns = {
|
|
655
|
+
bigint: /* @__PURE__ */ __name((val) => typeof val === "bigint", "bigint"),
|
|
656
|
+
function: /* @__PURE__ */ __name((val) => typeof val === "function", "function"),
|
|
657
|
+
boolean: /* @__PURE__ */ __name((val) => typeof val === "boolean", "boolean"),
|
|
658
|
+
string: /* @__PURE__ */ __name((val) => typeof val === "string", "string"),
|
|
659
|
+
stringOrUint8Array: /* @__PURE__ */ __name((val) => typeof val === "string" || isBytes2(val), "stringOrUint8Array"),
|
|
660
|
+
isSafeInteger: /* @__PURE__ */ __name((val) => Number.isSafeInteger(val), "isSafeInteger"),
|
|
661
|
+
array: /* @__PURE__ */ __name((val) => Array.isArray(val), "array"),
|
|
662
|
+
field: /* @__PURE__ */ __name((val, object) => object.Fp.isValid(val), "field"),
|
|
663
|
+
hash: /* @__PURE__ */ __name((val) => typeof val === "function" && Number.isSafeInteger(val.outputLen), "hash")
|
|
664
|
+
};
|
|
665
|
+
function validateObject(object, validators, optValidators = {}) {
|
|
666
|
+
const checkField = /* @__PURE__ */ __name((fieldName, type, isOptional) => {
|
|
667
|
+
const checkVal = validatorFns[type];
|
|
668
|
+
if (typeof checkVal !== "function")
|
|
669
|
+
throw new Error("invalid validator function");
|
|
670
|
+
const val = object[fieldName];
|
|
671
|
+
if (isOptional && val === void 0)
|
|
672
|
+
return;
|
|
673
|
+
if (!checkVal(val, object)) {
|
|
674
|
+
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
675
|
+
}
|
|
676
|
+
}, "checkField");
|
|
677
|
+
for (const [fieldName, type] of Object.entries(validators))
|
|
678
|
+
checkField(fieldName, type, false);
|
|
679
|
+
for (const [fieldName, type] of Object.entries(optValidators))
|
|
680
|
+
checkField(fieldName, type, true);
|
|
681
|
+
return object;
|
|
682
|
+
}
|
|
683
|
+
__name(validateObject, "validateObject");
|
|
684
|
+
function memoized(fn) {
|
|
685
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
686
|
+
return (arg, ...args) => {
|
|
687
|
+
const val = map.get(arg);
|
|
688
|
+
if (val !== void 0)
|
|
689
|
+
return val;
|
|
690
|
+
const computed = fn(arg, ...args);
|
|
691
|
+
map.set(arg, computed);
|
|
692
|
+
return computed;
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
__name(memoized, "memoized");
|
|
696
|
+
|
|
697
|
+
// ../../node_modules/@noble/curves/esm/abstract/modular.js
|
|
698
|
+
var _0n2 = BigInt(0);
|
|
699
|
+
var _1n2 = BigInt(1);
|
|
700
|
+
var _2n2 = /* @__PURE__ */ BigInt(2);
|
|
701
|
+
var _3n = /* @__PURE__ */ BigInt(3);
|
|
702
|
+
var _4n = /* @__PURE__ */ BigInt(4);
|
|
703
|
+
var _5n = /* @__PURE__ */ BigInt(5);
|
|
704
|
+
var _8n = /* @__PURE__ */ BigInt(8);
|
|
705
|
+
var _9n = /* @__PURE__ */ BigInt(9);
|
|
706
|
+
var _16n = /* @__PURE__ */ BigInt(16);
|
|
707
|
+
function mod(a, b) {
|
|
708
|
+
const result = a % b;
|
|
709
|
+
return result >= _0n2 ? result : b + result;
|
|
710
|
+
}
|
|
711
|
+
__name(mod, "mod");
|
|
712
|
+
function pow(num, power, modulo) {
|
|
713
|
+
if (power < _0n2)
|
|
714
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
715
|
+
if (modulo <= _0n2)
|
|
716
|
+
throw new Error("invalid modulus");
|
|
717
|
+
if (modulo === _1n2)
|
|
718
|
+
return _0n2;
|
|
719
|
+
let res = _1n2;
|
|
720
|
+
while (power > _0n2) {
|
|
721
|
+
if (power & _1n2)
|
|
722
|
+
res = res * num % modulo;
|
|
723
|
+
num = num * num % modulo;
|
|
724
|
+
power >>= _1n2;
|
|
725
|
+
}
|
|
726
|
+
return res;
|
|
727
|
+
}
|
|
728
|
+
__name(pow, "pow");
|
|
729
|
+
function pow2(x, power, modulo) {
|
|
730
|
+
let res = x;
|
|
731
|
+
while (power-- > _0n2) {
|
|
732
|
+
res *= res;
|
|
733
|
+
res %= modulo;
|
|
734
|
+
}
|
|
735
|
+
return res;
|
|
736
|
+
}
|
|
737
|
+
__name(pow2, "pow2");
|
|
738
|
+
function invert(number, modulo) {
|
|
739
|
+
if (number === _0n2)
|
|
740
|
+
throw new Error("invert: expected non-zero number");
|
|
741
|
+
if (modulo <= _0n2)
|
|
742
|
+
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
743
|
+
let a = mod(number, modulo);
|
|
744
|
+
let b = modulo;
|
|
745
|
+
let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
|
|
746
|
+
while (a !== _0n2) {
|
|
747
|
+
const q = b / a;
|
|
748
|
+
const r = b % a;
|
|
749
|
+
const m = x - u * q;
|
|
750
|
+
const n = y - v * q;
|
|
751
|
+
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
752
|
+
}
|
|
753
|
+
const gcd = b;
|
|
754
|
+
if (gcd !== _1n2)
|
|
755
|
+
throw new Error("invert: does not exist");
|
|
756
|
+
return mod(x, modulo);
|
|
757
|
+
}
|
|
758
|
+
__name(invert, "invert");
|
|
759
|
+
function tonelliShanks(P2) {
|
|
760
|
+
const legendreC = (P2 - _1n2) / _2n2;
|
|
761
|
+
let Q, S, Z;
|
|
762
|
+
for (Q = P2 - _1n2, S = 0; Q % _2n2 === _0n2; Q /= _2n2, S++)
|
|
763
|
+
;
|
|
764
|
+
for (Z = _2n2; Z < P2 && pow(Z, legendreC, P2) !== P2 - _1n2; Z++) {
|
|
765
|
+
if (Z > 1e3)
|
|
766
|
+
throw new Error("Cannot find square root: likely non-prime P");
|
|
767
|
+
}
|
|
768
|
+
if (S === 1) {
|
|
769
|
+
const p1div4 = (P2 + _1n2) / _4n;
|
|
770
|
+
return /* @__PURE__ */ __name(function tonelliFast(Fp2, n) {
|
|
771
|
+
const root = Fp2.pow(n, p1div4);
|
|
772
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
|
773
|
+
throw new Error("Cannot find square root");
|
|
774
|
+
return root;
|
|
775
|
+
}, "tonelliFast");
|
|
776
|
+
}
|
|
777
|
+
const Q1div2 = (Q + _1n2) / _2n2;
|
|
778
|
+
return /* @__PURE__ */ __name(function tonelliSlow(Fp2, n) {
|
|
779
|
+
if (Fp2.pow(n, legendreC) === Fp2.neg(Fp2.ONE))
|
|
780
|
+
throw new Error("Cannot find square root");
|
|
781
|
+
let r = S;
|
|
782
|
+
let g = Fp2.pow(Fp2.mul(Fp2.ONE, Z), Q);
|
|
783
|
+
let x = Fp2.pow(n, Q1div2);
|
|
784
|
+
let b = Fp2.pow(n, Q);
|
|
785
|
+
while (!Fp2.eql(b, Fp2.ONE)) {
|
|
786
|
+
if (Fp2.eql(b, Fp2.ZERO))
|
|
787
|
+
return Fp2.ZERO;
|
|
788
|
+
let m = 1;
|
|
789
|
+
for (let t2 = Fp2.sqr(b); m < r; m++) {
|
|
790
|
+
if (Fp2.eql(t2, Fp2.ONE))
|
|
791
|
+
break;
|
|
792
|
+
t2 = Fp2.sqr(t2);
|
|
793
|
+
}
|
|
794
|
+
const ge = Fp2.pow(g, _1n2 << BigInt(r - m - 1));
|
|
795
|
+
g = Fp2.sqr(ge);
|
|
796
|
+
x = Fp2.mul(x, ge);
|
|
797
|
+
b = Fp2.mul(b, g);
|
|
798
|
+
r = m;
|
|
799
|
+
}
|
|
800
|
+
return x;
|
|
801
|
+
}, "tonelliSlow");
|
|
802
|
+
}
|
|
803
|
+
__name(tonelliShanks, "tonelliShanks");
|
|
804
|
+
function FpSqrt(P2) {
|
|
805
|
+
if (P2 % _4n === _3n) {
|
|
806
|
+
const p1div4 = (P2 + _1n2) / _4n;
|
|
807
|
+
return /* @__PURE__ */ __name(function sqrt3mod4(Fp2, n) {
|
|
808
|
+
const root = Fp2.pow(n, p1div4);
|
|
809
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
|
810
|
+
throw new Error("Cannot find square root");
|
|
811
|
+
return root;
|
|
812
|
+
}, "sqrt3mod4");
|
|
813
|
+
}
|
|
814
|
+
if (P2 % _8n === _5n) {
|
|
815
|
+
const c1 = (P2 - _5n) / _8n;
|
|
816
|
+
return /* @__PURE__ */ __name(function sqrt5mod8(Fp2, n) {
|
|
817
|
+
const n2 = Fp2.mul(n, _2n2);
|
|
818
|
+
const v = Fp2.pow(n2, c1);
|
|
819
|
+
const nv = Fp2.mul(n, v);
|
|
820
|
+
const i = Fp2.mul(Fp2.mul(nv, _2n2), v);
|
|
821
|
+
const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
|
|
822
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
|
823
|
+
throw new Error("Cannot find square root");
|
|
824
|
+
return root;
|
|
825
|
+
}, "sqrt5mod8");
|
|
826
|
+
}
|
|
827
|
+
if (P2 % _16n === _9n) {
|
|
828
|
+
}
|
|
829
|
+
return tonelliShanks(P2);
|
|
830
|
+
}
|
|
831
|
+
__name(FpSqrt, "FpSqrt");
|
|
832
|
+
var isNegativeLE = /* @__PURE__ */ __name((num, modulo) => (mod(num, modulo) & _1n2) === _1n2, "isNegativeLE");
|
|
833
|
+
var FIELD_FIELDS = [
|
|
834
|
+
"create",
|
|
835
|
+
"isValid",
|
|
836
|
+
"is0",
|
|
837
|
+
"neg",
|
|
838
|
+
"inv",
|
|
839
|
+
"sqrt",
|
|
840
|
+
"sqr",
|
|
841
|
+
"eql",
|
|
842
|
+
"add",
|
|
843
|
+
"sub",
|
|
844
|
+
"mul",
|
|
845
|
+
"pow",
|
|
846
|
+
"div",
|
|
847
|
+
"addN",
|
|
848
|
+
"subN",
|
|
849
|
+
"mulN",
|
|
850
|
+
"sqrN"
|
|
851
|
+
];
|
|
852
|
+
function validateField(field) {
|
|
853
|
+
const initial = {
|
|
854
|
+
ORDER: "bigint",
|
|
855
|
+
MASK: "bigint",
|
|
856
|
+
BYTES: "isSafeInteger",
|
|
857
|
+
BITS: "isSafeInteger"
|
|
858
|
+
};
|
|
859
|
+
const opts = FIELD_FIELDS.reduce((map, val) => {
|
|
860
|
+
map[val] = "function";
|
|
861
|
+
return map;
|
|
862
|
+
}, initial);
|
|
863
|
+
return validateObject(field, opts);
|
|
864
|
+
}
|
|
865
|
+
__name(validateField, "validateField");
|
|
866
|
+
function FpPow(f, num, power) {
|
|
867
|
+
if (power < _0n2)
|
|
868
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
869
|
+
if (power === _0n2)
|
|
870
|
+
return f.ONE;
|
|
871
|
+
if (power === _1n2)
|
|
872
|
+
return num;
|
|
873
|
+
let p = f.ONE;
|
|
874
|
+
let d = num;
|
|
875
|
+
while (power > _0n2) {
|
|
876
|
+
if (power & _1n2)
|
|
877
|
+
p = f.mul(p, d);
|
|
878
|
+
d = f.sqr(d);
|
|
879
|
+
power >>= _1n2;
|
|
880
|
+
}
|
|
881
|
+
return p;
|
|
882
|
+
}
|
|
883
|
+
__name(FpPow, "FpPow");
|
|
884
|
+
function FpInvertBatch(f, nums) {
|
|
885
|
+
const tmp = new Array(nums.length);
|
|
886
|
+
const lastMultiplied = nums.reduce((acc, num, i) => {
|
|
887
|
+
if (f.is0(num))
|
|
888
|
+
return acc;
|
|
889
|
+
tmp[i] = acc;
|
|
890
|
+
return f.mul(acc, num);
|
|
891
|
+
}, f.ONE);
|
|
892
|
+
const inverted = f.inv(lastMultiplied);
|
|
893
|
+
nums.reduceRight((acc, num, i) => {
|
|
894
|
+
if (f.is0(num))
|
|
895
|
+
return acc;
|
|
896
|
+
tmp[i] = f.mul(acc, tmp[i]);
|
|
897
|
+
return f.mul(acc, num);
|
|
898
|
+
}, inverted);
|
|
899
|
+
return tmp;
|
|
900
|
+
}
|
|
901
|
+
__name(FpInvertBatch, "FpInvertBatch");
|
|
902
|
+
function nLength(n, nBitLength) {
|
|
903
|
+
const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
|
|
904
|
+
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
905
|
+
return { nBitLength: _nBitLength, nByteLength };
|
|
906
|
+
}
|
|
907
|
+
__name(nLength, "nLength");
|
|
908
|
+
function Field(ORDER, bitLen2, isLE = false, redef = {}) {
|
|
909
|
+
if (ORDER <= _0n2)
|
|
910
|
+
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
911
|
+
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
|
912
|
+
if (BYTES > 2048)
|
|
913
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
914
|
+
let sqrtP;
|
|
915
|
+
const f = Object.freeze({
|
|
916
|
+
ORDER,
|
|
917
|
+
BITS,
|
|
918
|
+
BYTES,
|
|
919
|
+
MASK: bitMask(BITS),
|
|
920
|
+
ZERO: _0n2,
|
|
921
|
+
ONE: _1n2,
|
|
922
|
+
create: /* @__PURE__ */ __name((num) => mod(num, ORDER), "create"),
|
|
923
|
+
isValid: /* @__PURE__ */ __name((num) => {
|
|
924
|
+
if (typeof num !== "bigint")
|
|
925
|
+
throw new Error("invalid field element: expected bigint, got " + typeof num);
|
|
926
|
+
return _0n2 <= num && num < ORDER;
|
|
927
|
+
}, "isValid"),
|
|
928
|
+
is0: /* @__PURE__ */ __name((num) => num === _0n2, "is0"),
|
|
929
|
+
isOdd: /* @__PURE__ */ __name((num) => (num & _1n2) === _1n2, "isOdd"),
|
|
930
|
+
neg: /* @__PURE__ */ __name((num) => mod(-num, ORDER), "neg"),
|
|
931
|
+
eql: /* @__PURE__ */ __name((lhs, rhs) => lhs === rhs, "eql"),
|
|
932
|
+
sqr: /* @__PURE__ */ __name((num) => mod(num * num, ORDER), "sqr"),
|
|
933
|
+
add: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs + rhs, ORDER), "add"),
|
|
934
|
+
sub: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs - rhs, ORDER), "sub"),
|
|
935
|
+
mul: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs * rhs, ORDER), "mul"),
|
|
936
|
+
pow: /* @__PURE__ */ __name((num, power) => FpPow(f, num, power), "pow"),
|
|
937
|
+
div: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER), "div"),
|
|
938
|
+
// Same as above, but doesn't normalize
|
|
939
|
+
sqrN: /* @__PURE__ */ __name((num) => num * num, "sqrN"),
|
|
940
|
+
addN: /* @__PURE__ */ __name((lhs, rhs) => lhs + rhs, "addN"),
|
|
941
|
+
subN: /* @__PURE__ */ __name((lhs, rhs) => lhs - rhs, "subN"),
|
|
942
|
+
mulN: /* @__PURE__ */ __name((lhs, rhs) => lhs * rhs, "mulN"),
|
|
943
|
+
inv: /* @__PURE__ */ __name((num) => invert(num, ORDER), "inv"),
|
|
944
|
+
sqrt: redef.sqrt || ((n) => {
|
|
945
|
+
if (!sqrtP)
|
|
946
|
+
sqrtP = FpSqrt(ORDER);
|
|
947
|
+
return sqrtP(f, n);
|
|
948
|
+
}),
|
|
949
|
+
invertBatch: /* @__PURE__ */ __name((lst) => FpInvertBatch(f, lst), "invertBatch"),
|
|
950
|
+
// TODO: do we really need constant cmov?
|
|
951
|
+
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
952
|
+
cmov: /* @__PURE__ */ __name((a, b, c) => c ? b : a, "cmov"),
|
|
953
|
+
toBytes: /* @__PURE__ */ __name((num) => isLE ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES), "toBytes"),
|
|
954
|
+
fromBytes: /* @__PURE__ */ __name((bytes) => {
|
|
955
|
+
if (bytes.length !== BYTES)
|
|
956
|
+
throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
|
|
957
|
+
return isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
|
|
958
|
+
}, "fromBytes")
|
|
959
|
+
});
|
|
960
|
+
return Object.freeze(f);
|
|
961
|
+
}
|
|
962
|
+
__name(Field, "Field");
|
|
963
|
+
|
|
964
|
+
// ../../node_modules/@noble/curves/esm/abstract/curve.js
|
|
965
|
+
var _0n3 = BigInt(0);
|
|
966
|
+
var _1n3 = BigInt(1);
|
|
967
|
+
function constTimeNegate(condition, item) {
|
|
968
|
+
const neg = item.negate();
|
|
969
|
+
return condition ? neg : item;
|
|
970
|
+
}
|
|
971
|
+
__name(constTimeNegate, "constTimeNegate");
|
|
972
|
+
function validateW(W, bits) {
|
|
973
|
+
if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
|
|
974
|
+
throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
|
|
975
|
+
}
|
|
976
|
+
__name(validateW, "validateW");
|
|
977
|
+
function calcWOpts(W, bits) {
|
|
978
|
+
validateW(W, bits);
|
|
979
|
+
const windows = Math.ceil(bits / W) + 1;
|
|
980
|
+
const windowSize = 2 ** (W - 1);
|
|
981
|
+
return { windows, windowSize };
|
|
982
|
+
}
|
|
983
|
+
__name(calcWOpts, "calcWOpts");
|
|
984
|
+
function validateMSMPoints(points, c) {
|
|
985
|
+
if (!Array.isArray(points))
|
|
986
|
+
throw new Error("array expected");
|
|
987
|
+
points.forEach((p, i) => {
|
|
988
|
+
if (!(p instanceof c))
|
|
989
|
+
throw new Error("invalid point at index " + i);
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
__name(validateMSMPoints, "validateMSMPoints");
|
|
993
|
+
function validateMSMScalars(scalars, field) {
|
|
994
|
+
if (!Array.isArray(scalars))
|
|
995
|
+
throw new Error("array of scalars expected");
|
|
996
|
+
scalars.forEach((s, i) => {
|
|
997
|
+
if (!field.isValid(s))
|
|
998
|
+
throw new Error("invalid scalar at index " + i);
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
__name(validateMSMScalars, "validateMSMScalars");
|
|
1002
|
+
var pointPrecomputes = /* @__PURE__ */ new WeakMap();
|
|
1003
|
+
var pointWindowSizes = /* @__PURE__ */ new WeakMap();
|
|
1004
|
+
function getW(P2) {
|
|
1005
|
+
return pointWindowSizes.get(P2) || 1;
|
|
1006
|
+
}
|
|
1007
|
+
__name(getW, "getW");
|
|
1008
|
+
function wNAF(c, bits) {
|
|
1009
|
+
return {
|
|
1010
|
+
constTimeNegate,
|
|
1011
|
+
hasPrecomputes(elm) {
|
|
1012
|
+
return getW(elm) !== 1;
|
|
1013
|
+
},
|
|
1014
|
+
// non-const time multiplication ladder
|
|
1015
|
+
unsafeLadder(elm, n, p = c.ZERO) {
|
|
1016
|
+
let d = elm;
|
|
1017
|
+
while (n > _0n3) {
|
|
1018
|
+
if (n & _1n3)
|
|
1019
|
+
p = p.add(d);
|
|
1020
|
+
d = d.double();
|
|
1021
|
+
n >>= _1n3;
|
|
1022
|
+
}
|
|
1023
|
+
return p;
|
|
1024
|
+
},
|
|
1025
|
+
/**
|
|
1026
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
1027
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
1028
|
+
* Number of precomputed points depends on the curve size:
|
|
1029
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
1030
|
+
* - 𝑊 is the window size
|
|
1031
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
1032
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
1033
|
+
* @param elm Point instance
|
|
1034
|
+
* @param W window size
|
|
1035
|
+
* @returns precomputed point tables flattened to a single array
|
|
1036
|
+
*/
|
|
1037
|
+
precomputeWindow(elm, W) {
|
|
1038
|
+
const { windows, windowSize } = calcWOpts(W, bits);
|
|
1039
|
+
const points = [];
|
|
1040
|
+
let p = elm;
|
|
1041
|
+
let base = p;
|
|
1042
|
+
for (let window = 0; window < windows; window++) {
|
|
1043
|
+
base = p;
|
|
1044
|
+
points.push(base);
|
|
1045
|
+
for (let i = 1; i < windowSize; i++) {
|
|
1046
|
+
base = base.add(p);
|
|
1047
|
+
points.push(base);
|
|
1048
|
+
}
|
|
1049
|
+
p = base.double();
|
|
1050
|
+
}
|
|
1051
|
+
return points;
|
|
1052
|
+
},
|
|
1053
|
+
/**
|
|
1054
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1055
|
+
* @param W window size
|
|
1056
|
+
* @param precomputes precomputed tables
|
|
1057
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
1058
|
+
* @returns real and fake (for const-time) points
|
|
1059
|
+
*/
|
|
1060
|
+
wNAF(W, precomputes, n) {
|
|
1061
|
+
const { windows, windowSize } = calcWOpts(W, bits);
|
|
1062
|
+
let p = c.ZERO;
|
|
1063
|
+
let f = c.BASE;
|
|
1064
|
+
const mask = BigInt(2 ** W - 1);
|
|
1065
|
+
const maxNumber = 2 ** W;
|
|
1066
|
+
const shiftBy = BigInt(W);
|
|
1067
|
+
for (let window = 0; window < windows; window++) {
|
|
1068
|
+
const offset = window * windowSize;
|
|
1069
|
+
let wbits = Number(n & mask);
|
|
1070
|
+
n >>= shiftBy;
|
|
1071
|
+
if (wbits > windowSize) {
|
|
1072
|
+
wbits -= maxNumber;
|
|
1073
|
+
n += _1n3;
|
|
1074
|
+
}
|
|
1075
|
+
const offset1 = offset;
|
|
1076
|
+
const offset2 = offset + Math.abs(wbits) - 1;
|
|
1077
|
+
const cond1 = window % 2 !== 0;
|
|
1078
|
+
const cond2 = wbits < 0;
|
|
1079
|
+
if (wbits === 0) {
|
|
1080
|
+
f = f.add(constTimeNegate(cond1, precomputes[offset1]));
|
|
1081
|
+
} else {
|
|
1082
|
+
p = p.add(constTimeNegate(cond2, precomputes[offset2]));
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return { p, f };
|
|
1086
|
+
},
|
|
1087
|
+
/**
|
|
1088
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1089
|
+
* @param W window size
|
|
1090
|
+
* @param precomputes precomputed tables
|
|
1091
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
1092
|
+
* @param acc accumulator point to add result of multiplication
|
|
1093
|
+
* @returns point
|
|
1094
|
+
*/
|
|
1095
|
+
wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
|
|
1096
|
+
const { windows, windowSize } = calcWOpts(W, bits);
|
|
1097
|
+
const mask = BigInt(2 ** W - 1);
|
|
1098
|
+
const maxNumber = 2 ** W;
|
|
1099
|
+
const shiftBy = BigInt(W);
|
|
1100
|
+
for (let window = 0; window < windows; window++) {
|
|
1101
|
+
const offset = window * windowSize;
|
|
1102
|
+
if (n === _0n3)
|
|
1103
|
+
break;
|
|
1104
|
+
let wbits = Number(n & mask);
|
|
1105
|
+
n >>= shiftBy;
|
|
1106
|
+
if (wbits > windowSize) {
|
|
1107
|
+
wbits -= maxNumber;
|
|
1108
|
+
n += _1n3;
|
|
1109
|
+
}
|
|
1110
|
+
if (wbits === 0)
|
|
1111
|
+
continue;
|
|
1112
|
+
let curr = precomputes[offset + Math.abs(wbits) - 1];
|
|
1113
|
+
if (wbits < 0)
|
|
1114
|
+
curr = curr.negate();
|
|
1115
|
+
acc = acc.add(curr);
|
|
1116
|
+
}
|
|
1117
|
+
return acc;
|
|
1118
|
+
},
|
|
1119
|
+
getPrecomputes(W, P2, transform) {
|
|
1120
|
+
let comp = pointPrecomputes.get(P2);
|
|
1121
|
+
if (!comp) {
|
|
1122
|
+
comp = this.precomputeWindow(P2, W);
|
|
1123
|
+
if (W !== 1)
|
|
1124
|
+
pointPrecomputes.set(P2, transform(comp));
|
|
1125
|
+
}
|
|
1126
|
+
return comp;
|
|
1127
|
+
},
|
|
1128
|
+
wNAFCached(P2, n, transform) {
|
|
1129
|
+
const W = getW(P2);
|
|
1130
|
+
return this.wNAF(W, this.getPrecomputes(W, P2, transform), n);
|
|
1131
|
+
},
|
|
1132
|
+
wNAFCachedUnsafe(P2, n, transform, prev) {
|
|
1133
|
+
const W = getW(P2);
|
|
1134
|
+
if (W === 1)
|
|
1135
|
+
return this.unsafeLadder(P2, n, prev);
|
|
1136
|
+
return this.wNAFUnsafe(W, this.getPrecomputes(W, P2, transform), n, prev);
|
|
1137
|
+
},
|
|
1138
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
1139
|
+
// using windowed method. This specifies window size and
|
|
1140
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
1141
|
+
setWindowSize(P2, W) {
|
|
1142
|
+
validateW(W, bits);
|
|
1143
|
+
pointWindowSizes.set(P2, W);
|
|
1144
|
+
pointPrecomputes.delete(P2);
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
__name(wNAF, "wNAF");
|
|
1149
|
+
function pippenger(c, fieldN, points, scalars) {
|
|
1150
|
+
validateMSMPoints(points, c);
|
|
1151
|
+
validateMSMScalars(scalars, fieldN);
|
|
1152
|
+
if (points.length !== scalars.length)
|
|
1153
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
1154
|
+
const zero = c.ZERO;
|
|
1155
|
+
const wbits = bitLen(BigInt(points.length));
|
|
1156
|
+
const windowSize = wbits > 12 ? wbits - 3 : wbits > 4 ? wbits - 2 : wbits ? 2 : 1;
|
|
1157
|
+
const MASK = (1 << windowSize) - 1;
|
|
1158
|
+
const buckets = new Array(MASK + 1).fill(zero);
|
|
1159
|
+
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
1160
|
+
let sum = zero;
|
|
1161
|
+
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
1162
|
+
buckets.fill(zero);
|
|
1163
|
+
for (let j = 0; j < scalars.length; j++) {
|
|
1164
|
+
const scalar = scalars[j];
|
|
1165
|
+
const wbits2 = Number(scalar >> BigInt(i) & BigInt(MASK));
|
|
1166
|
+
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
1167
|
+
}
|
|
1168
|
+
let resI = zero;
|
|
1169
|
+
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
1170
|
+
sumI = sumI.add(buckets[j]);
|
|
1171
|
+
resI = resI.add(sumI);
|
|
1172
|
+
}
|
|
1173
|
+
sum = sum.add(resI);
|
|
1174
|
+
if (i !== 0)
|
|
1175
|
+
for (let j = 0; j < windowSize; j++)
|
|
1176
|
+
sum = sum.double();
|
|
1177
|
+
}
|
|
1178
|
+
return sum;
|
|
1179
|
+
}
|
|
1180
|
+
__name(pippenger, "pippenger");
|
|
1181
|
+
function validateBasic(curve) {
|
|
1182
|
+
validateField(curve.Fp);
|
|
1183
|
+
validateObject(curve, {
|
|
1184
|
+
n: "bigint",
|
|
1185
|
+
h: "bigint",
|
|
1186
|
+
Gx: "field",
|
|
1187
|
+
Gy: "field"
|
|
1188
|
+
}, {
|
|
1189
|
+
nBitLength: "isSafeInteger",
|
|
1190
|
+
nByteLength: "isSafeInteger"
|
|
1191
|
+
});
|
|
1192
|
+
return Object.freeze({
|
|
1193
|
+
...nLength(curve.n, curve.nBitLength),
|
|
1194
|
+
...curve,
|
|
1195
|
+
...{ p: curve.Fp.ORDER }
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
__name(validateBasic, "validateBasic");
|
|
1199
|
+
|
|
1200
|
+
// ../../node_modules/@noble/curves/esm/abstract/edwards.js
|
|
1201
|
+
var _0n4 = BigInt(0);
|
|
1202
|
+
var _1n4 = BigInt(1);
|
|
1203
|
+
var _2n3 = BigInt(2);
|
|
1204
|
+
var _8n2 = BigInt(8);
|
|
1205
|
+
var VERIFY_DEFAULT = { zip215: true };
|
|
1206
|
+
function validateOpts(curve) {
|
|
1207
|
+
const opts = validateBasic(curve);
|
|
1208
|
+
validateObject(curve, {
|
|
1209
|
+
hash: "function",
|
|
1210
|
+
a: "bigint",
|
|
1211
|
+
d: "bigint",
|
|
1212
|
+
randomBytes: "function"
|
|
1213
|
+
}, {
|
|
1214
|
+
adjustScalarBytes: "function",
|
|
1215
|
+
domain: "function",
|
|
1216
|
+
uvRatio: "function",
|
|
1217
|
+
mapToCurve: "function"
|
|
1218
|
+
});
|
|
1219
|
+
return Object.freeze({ ...opts });
|
|
1220
|
+
}
|
|
1221
|
+
__name(validateOpts, "validateOpts");
|
|
1222
|
+
function twistedEdwards(curveDef) {
|
|
1223
|
+
const CURVE = validateOpts(curveDef);
|
|
1224
|
+
const { Fp: Fp2, n: CURVE_ORDER, prehash, hash: cHash, randomBytes: randomBytes2, nByteLength, h: cofactor } = CURVE;
|
|
1225
|
+
const MASK = _2n3 << BigInt(nByteLength * 8) - _1n4;
|
|
1226
|
+
const modP = Fp2.create;
|
|
1227
|
+
const Fn = Field(CURVE.n, CURVE.nBitLength);
|
|
1228
|
+
const uvRatio2 = CURVE.uvRatio || ((u, v) => {
|
|
1229
|
+
try {
|
|
1230
|
+
return { isValid: true, value: Fp2.sqrt(u * Fp2.inv(v)) };
|
|
1231
|
+
} catch (e) {
|
|
1232
|
+
return { isValid: false, value: _0n4 };
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
const adjustScalarBytes2 = CURVE.adjustScalarBytes || ((bytes) => bytes);
|
|
1236
|
+
const domain = CURVE.domain || ((data, ctx, phflag) => {
|
|
1237
|
+
abool("phflag", phflag);
|
|
1238
|
+
if (ctx.length || phflag)
|
|
1239
|
+
throw new Error("Contexts/pre-hash are not supported");
|
|
1240
|
+
return data;
|
|
1241
|
+
});
|
|
1242
|
+
function aCoordinate(title, n) {
|
|
1243
|
+
aInRange("coordinate " + title, n, _0n4, MASK);
|
|
1244
|
+
}
|
|
1245
|
+
__name(aCoordinate, "aCoordinate");
|
|
1246
|
+
function assertPoint(other) {
|
|
1247
|
+
if (!(other instanceof Point))
|
|
1248
|
+
throw new Error("ExtendedPoint expected");
|
|
1249
|
+
}
|
|
1250
|
+
__name(assertPoint, "assertPoint");
|
|
1251
|
+
const toAffineMemo = memoized((p, iz) => {
|
|
1252
|
+
const { ex: x, ey: y, ez: z } = p;
|
|
1253
|
+
const is0 = p.is0();
|
|
1254
|
+
if (iz == null)
|
|
1255
|
+
iz = is0 ? _8n2 : Fp2.inv(z);
|
|
1256
|
+
const ax = modP(x * iz);
|
|
1257
|
+
const ay = modP(y * iz);
|
|
1258
|
+
const zz = modP(z * iz);
|
|
1259
|
+
if (is0)
|
|
1260
|
+
return { x: _0n4, y: _1n4 };
|
|
1261
|
+
if (zz !== _1n4)
|
|
1262
|
+
throw new Error("invZ was invalid");
|
|
1263
|
+
return { x: ax, y: ay };
|
|
1264
|
+
});
|
|
1265
|
+
const assertValidMemo = memoized((p) => {
|
|
1266
|
+
const { a, d } = CURVE;
|
|
1267
|
+
if (p.is0())
|
|
1268
|
+
throw new Error("bad point: ZERO");
|
|
1269
|
+
const { ex: X, ey: Y, ez: Z, et: T } = p;
|
|
1270
|
+
const X2 = modP(X * X);
|
|
1271
|
+
const Y2 = modP(Y * Y);
|
|
1272
|
+
const Z2 = modP(Z * Z);
|
|
1273
|
+
const Z4 = modP(Z2 * Z2);
|
|
1274
|
+
const aX2 = modP(X2 * a);
|
|
1275
|
+
const left = modP(Z2 * modP(aX2 + Y2));
|
|
1276
|
+
const right = modP(Z4 + modP(d * modP(X2 * Y2)));
|
|
1277
|
+
if (left !== right)
|
|
1278
|
+
throw new Error("bad point: equation left != right (1)");
|
|
1279
|
+
const XY = modP(X * Y);
|
|
1280
|
+
const ZT = modP(Z * T);
|
|
1281
|
+
if (XY !== ZT)
|
|
1282
|
+
throw new Error("bad point: equation left != right (2)");
|
|
1283
|
+
return true;
|
|
1284
|
+
});
|
|
1285
|
+
class Point {
|
|
1286
|
+
static {
|
|
1287
|
+
__name(this, "Point");
|
|
1288
|
+
}
|
|
1289
|
+
constructor(ex, ey, ez, et) {
|
|
1290
|
+
this.ex = ex;
|
|
1291
|
+
this.ey = ey;
|
|
1292
|
+
this.ez = ez;
|
|
1293
|
+
this.et = et;
|
|
1294
|
+
aCoordinate("x", ex);
|
|
1295
|
+
aCoordinate("y", ey);
|
|
1296
|
+
aCoordinate("z", ez);
|
|
1297
|
+
aCoordinate("t", et);
|
|
1298
|
+
Object.freeze(this);
|
|
1299
|
+
}
|
|
1300
|
+
get x() {
|
|
1301
|
+
return this.toAffine().x;
|
|
1302
|
+
}
|
|
1303
|
+
get y() {
|
|
1304
|
+
return this.toAffine().y;
|
|
1305
|
+
}
|
|
1306
|
+
static fromAffine(p) {
|
|
1307
|
+
if (p instanceof Point)
|
|
1308
|
+
throw new Error("extended point not allowed");
|
|
1309
|
+
const { x, y } = p || {};
|
|
1310
|
+
aCoordinate("x", x);
|
|
1311
|
+
aCoordinate("y", y);
|
|
1312
|
+
return new Point(x, y, _1n4, modP(x * y));
|
|
1313
|
+
}
|
|
1314
|
+
static normalizeZ(points) {
|
|
1315
|
+
const toInv = Fp2.invertBatch(points.map((p) => p.ez));
|
|
1316
|
+
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
1317
|
+
}
|
|
1318
|
+
// Multiscalar Multiplication
|
|
1319
|
+
static msm(points, scalars) {
|
|
1320
|
+
return pippenger(Point, Fn, points, scalars);
|
|
1321
|
+
}
|
|
1322
|
+
// "Private method", don't use it directly
|
|
1323
|
+
_setWindowSize(windowSize) {
|
|
1324
|
+
wnaf.setWindowSize(this, windowSize);
|
|
1325
|
+
}
|
|
1326
|
+
// Not required for fromHex(), which always creates valid points.
|
|
1327
|
+
// Could be useful for fromAffine().
|
|
1328
|
+
assertValidity() {
|
|
1329
|
+
assertValidMemo(this);
|
|
1330
|
+
}
|
|
1331
|
+
// Compare one point to another.
|
|
1332
|
+
equals(other) {
|
|
1333
|
+
assertPoint(other);
|
|
1334
|
+
const { ex: X1, ey: Y1, ez: Z1 } = this;
|
|
1335
|
+
const { ex: X2, ey: Y2, ez: Z2 } = other;
|
|
1336
|
+
const X1Z2 = modP(X1 * Z2);
|
|
1337
|
+
const X2Z1 = modP(X2 * Z1);
|
|
1338
|
+
const Y1Z2 = modP(Y1 * Z2);
|
|
1339
|
+
const Y2Z1 = modP(Y2 * Z1);
|
|
1340
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
1341
|
+
}
|
|
1342
|
+
is0() {
|
|
1343
|
+
return this.equals(Point.ZERO);
|
|
1344
|
+
}
|
|
1345
|
+
negate() {
|
|
1346
|
+
return new Point(modP(-this.ex), this.ey, this.ez, modP(-this.et));
|
|
1347
|
+
}
|
|
1348
|
+
// Fast algo for doubling Extended Point.
|
|
1349
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
1350
|
+
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
1351
|
+
double() {
|
|
1352
|
+
const { a } = CURVE;
|
|
1353
|
+
const { ex: X1, ey: Y1, ez: Z1 } = this;
|
|
1354
|
+
const A = modP(X1 * X1);
|
|
1355
|
+
const B = modP(Y1 * Y1);
|
|
1356
|
+
const C = modP(_2n3 * modP(Z1 * Z1));
|
|
1357
|
+
const D = modP(a * A);
|
|
1358
|
+
const x1y1 = X1 + Y1;
|
|
1359
|
+
const E = modP(modP(x1y1 * x1y1) - A - B);
|
|
1360
|
+
const G2 = D + B;
|
|
1361
|
+
const F = G2 - C;
|
|
1362
|
+
const H = D - B;
|
|
1363
|
+
const X3 = modP(E * F);
|
|
1364
|
+
const Y3 = modP(G2 * H);
|
|
1365
|
+
const T3 = modP(E * H);
|
|
1366
|
+
const Z3 = modP(F * G2);
|
|
1367
|
+
return new Point(X3, Y3, Z3, T3);
|
|
1368
|
+
}
|
|
1369
|
+
// Fast algo for adding 2 Extended Points.
|
|
1370
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
1371
|
+
// Cost: 9M + 1*a + 1*d + 7add.
|
|
1372
|
+
add(other) {
|
|
1373
|
+
assertPoint(other);
|
|
1374
|
+
const { a, d } = CURVE;
|
|
1375
|
+
const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this;
|
|
1376
|
+
const { ex: X2, ey: Y2, ez: Z2, et: T2 } = other;
|
|
1377
|
+
if (a === BigInt(-1)) {
|
|
1378
|
+
const A2 = modP((Y1 - X1) * (Y2 + X2));
|
|
1379
|
+
const B2 = modP((Y1 + X1) * (Y2 - X2));
|
|
1380
|
+
const F2 = modP(B2 - A2);
|
|
1381
|
+
if (F2 === _0n4)
|
|
1382
|
+
return this.double();
|
|
1383
|
+
const C2 = modP(Z1 * _2n3 * T2);
|
|
1384
|
+
const D2 = modP(T1 * _2n3 * Z2);
|
|
1385
|
+
const E2 = D2 + C2;
|
|
1386
|
+
const G3 = B2 + A2;
|
|
1387
|
+
const H2 = D2 - C2;
|
|
1388
|
+
const X32 = modP(E2 * F2);
|
|
1389
|
+
const Y32 = modP(G3 * H2);
|
|
1390
|
+
const T32 = modP(E2 * H2);
|
|
1391
|
+
const Z32 = modP(F2 * G3);
|
|
1392
|
+
return new Point(X32, Y32, Z32, T32);
|
|
1393
|
+
}
|
|
1394
|
+
const A = modP(X1 * X2);
|
|
1395
|
+
const B = modP(Y1 * Y2);
|
|
1396
|
+
const C = modP(T1 * d * T2);
|
|
1397
|
+
const D = modP(Z1 * Z2);
|
|
1398
|
+
const E = modP((X1 + Y1) * (X2 + Y2) - A - B);
|
|
1399
|
+
const F = D - C;
|
|
1400
|
+
const G2 = D + C;
|
|
1401
|
+
const H = modP(B - a * A);
|
|
1402
|
+
const X3 = modP(E * F);
|
|
1403
|
+
const Y3 = modP(G2 * H);
|
|
1404
|
+
const T3 = modP(E * H);
|
|
1405
|
+
const Z3 = modP(F * G2);
|
|
1406
|
+
return new Point(X3, Y3, Z3, T3);
|
|
1407
|
+
}
|
|
1408
|
+
subtract(other) {
|
|
1409
|
+
return this.add(other.negate());
|
|
1410
|
+
}
|
|
1411
|
+
wNAF(n) {
|
|
1412
|
+
return wnaf.wNAFCached(this, n, Point.normalizeZ);
|
|
1413
|
+
}
|
|
1414
|
+
// Constant-time multiplication.
|
|
1415
|
+
multiply(scalar) {
|
|
1416
|
+
const n = scalar;
|
|
1417
|
+
aInRange("scalar", n, _1n4, CURVE_ORDER);
|
|
1418
|
+
const { p, f } = this.wNAF(n);
|
|
1419
|
+
return Point.normalizeZ([p, f])[0];
|
|
1420
|
+
}
|
|
1421
|
+
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1422
|
+
// It's faster, but should only be used when you don't care about
|
|
1423
|
+
// an exposed private key e.g. sig verification.
|
|
1424
|
+
// Does NOT allow scalars higher than CURVE.n.
|
|
1425
|
+
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
1426
|
+
multiplyUnsafe(scalar, acc = Point.ZERO) {
|
|
1427
|
+
const n = scalar;
|
|
1428
|
+
aInRange("scalar", n, _0n4, CURVE_ORDER);
|
|
1429
|
+
if (n === _0n4)
|
|
1430
|
+
return I;
|
|
1431
|
+
if (this.is0() || n === _1n4)
|
|
1432
|
+
return this;
|
|
1433
|
+
return wnaf.wNAFCachedUnsafe(this, n, Point.normalizeZ, acc);
|
|
1434
|
+
}
|
|
1435
|
+
// Checks if point is of small order.
|
|
1436
|
+
// If you add something to small order point, you will have "dirty"
|
|
1437
|
+
// point with torsion component.
|
|
1438
|
+
// Multiplies point by cofactor and checks if the result is 0.
|
|
1439
|
+
isSmallOrder() {
|
|
1440
|
+
return this.multiplyUnsafe(cofactor).is0();
|
|
1441
|
+
}
|
|
1442
|
+
// Multiplies point by curve order and checks if the result is 0.
|
|
1443
|
+
// Returns `false` is the point is dirty.
|
|
1444
|
+
isTorsionFree() {
|
|
1445
|
+
return wnaf.unsafeLadder(this, CURVE_ORDER).is0();
|
|
1446
|
+
}
|
|
1447
|
+
// Converts Extended point to default (x, y) coordinates.
|
|
1448
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
1449
|
+
toAffine(iz) {
|
|
1450
|
+
return toAffineMemo(this, iz);
|
|
1451
|
+
}
|
|
1452
|
+
clearCofactor() {
|
|
1453
|
+
const { h: cofactor2 } = CURVE;
|
|
1454
|
+
if (cofactor2 === _1n4)
|
|
1455
|
+
return this;
|
|
1456
|
+
return this.multiplyUnsafe(cofactor2);
|
|
1457
|
+
}
|
|
1458
|
+
// Converts hash string or Uint8Array to Point.
|
|
1459
|
+
// Uses algo from RFC8032 5.1.3.
|
|
1460
|
+
static fromHex(hex, zip215 = false) {
|
|
1461
|
+
const { d, a } = CURVE;
|
|
1462
|
+
const len = Fp2.BYTES;
|
|
1463
|
+
hex = ensureBytes("pointHex", hex, len);
|
|
1464
|
+
abool("zip215", zip215);
|
|
1465
|
+
const normed = hex.slice();
|
|
1466
|
+
const lastByte = hex[len - 1];
|
|
1467
|
+
normed[len - 1] = lastByte & ~128;
|
|
1468
|
+
const y = bytesToNumberLE(normed);
|
|
1469
|
+
const max = zip215 ? MASK : Fp2.ORDER;
|
|
1470
|
+
aInRange("pointHex.y", y, _0n4, max);
|
|
1471
|
+
const y2 = modP(y * y);
|
|
1472
|
+
const u = modP(y2 - _1n4);
|
|
1473
|
+
const v = modP(d * y2 - a);
|
|
1474
|
+
let { isValid, value: x } = uvRatio2(u, v);
|
|
1475
|
+
if (!isValid)
|
|
1476
|
+
throw new Error("Point.fromHex: invalid y coordinate");
|
|
1477
|
+
const isXOdd = (x & _1n4) === _1n4;
|
|
1478
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
1479
|
+
if (!zip215 && x === _0n4 && isLastByteOdd)
|
|
1480
|
+
throw new Error("Point.fromHex: x=0 and x_0=1");
|
|
1481
|
+
if (isLastByteOdd !== isXOdd)
|
|
1482
|
+
x = modP(-x);
|
|
1483
|
+
return Point.fromAffine({ x, y });
|
|
1484
|
+
}
|
|
1485
|
+
static fromPrivateKey(privKey) {
|
|
1486
|
+
return getExtendedPublicKey(privKey).point;
|
|
1487
|
+
}
|
|
1488
|
+
toRawBytes() {
|
|
1489
|
+
const { x, y } = this.toAffine();
|
|
1490
|
+
const bytes = numberToBytesLE(y, Fp2.BYTES);
|
|
1491
|
+
bytes[bytes.length - 1] |= x & _1n4 ? 128 : 0;
|
|
1492
|
+
return bytes;
|
|
1493
|
+
}
|
|
1494
|
+
toHex() {
|
|
1495
|
+
return bytesToHex(this.toRawBytes());
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
Point.BASE = new Point(CURVE.Gx, CURVE.Gy, _1n4, modP(CURVE.Gx * CURVE.Gy));
|
|
1499
|
+
Point.ZERO = new Point(_0n4, _1n4, _1n4, _0n4);
|
|
1500
|
+
const { BASE: G, ZERO: I } = Point;
|
|
1501
|
+
const wnaf = wNAF(Point, nByteLength * 8);
|
|
1502
|
+
function modN(a) {
|
|
1503
|
+
return mod(a, CURVE_ORDER);
|
|
1504
|
+
}
|
|
1505
|
+
__name(modN, "modN");
|
|
1506
|
+
function modN_LE(hash) {
|
|
1507
|
+
return modN(bytesToNumberLE(hash));
|
|
1508
|
+
}
|
|
1509
|
+
__name(modN_LE, "modN_LE");
|
|
1510
|
+
function getExtendedPublicKey(key) {
|
|
1511
|
+
const len = Fp2.BYTES;
|
|
1512
|
+
key = ensureBytes("private key", key, len);
|
|
1513
|
+
const hashed = ensureBytes("hashed private key", cHash(key), 2 * len);
|
|
1514
|
+
const head = adjustScalarBytes2(hashed.slice(0, len));
|
|
1515
|
+
const prefix = hashed.slice(len, 2 * len);
|
|
1516
|
+
const scalar = modN_LE(head);
|
|
1517
|
+
const point = G.multiply(scalar);
|
|
1518
|
+
const pointBytes = point.toRawBytes();
|
|
1519
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
1520
|
+
}
|
|
1521
|
+
__name(getExtendedPublicKey, "getExtendedPublicKey");
|
|
1522
|
+
function getPublicKey(privKey) {
|
|
1523
|
+
return getExtendedPublicKey(privKey).pointBytes;
|
|
1524
|
+
}
|
|
1525
|
+
__name(getPublicKey, "getPublicKey");
|
|
1526
|
+
function hashDomainToScalar(context = new Uint8Array(), ...msgs) {
|
|
1527
|
+
const msg = concatBytes(...msgs);
|
|
1528
|
+
return modN_LE(cHash(domain(msg, ensureBytes("context", context), !!prehash)));
|
|
1529
|
+
}
|
|
1530
|
+
__name(hashDomainToScalar, "hashDomainToScalar");
|
|
1531
|
+
function sign(msg, privKey, options = {}) {
|
|
1532
|
+
msg = ensureBytes("message", msg);
|
|
1533
|
+
if (prehash)
|
|
1534
|
+
msg = prehash(msg);
|
|
1535
|
+
const { prefix, scalar, pointBytes } = getExtendedPublicKey(privKey);
|
|
1536
|
+
const r = hashDomainToScalar(options.context, prefix, msg);
|
|
1537
|
+
const R = G.multiply(r).toRawBytes();
|
|
1538
|
+
const k = hashDomainToScalar(options.context, R, pointBytes, msg);
|
|
1539
|
+
const s = modN(r + k * scalar);
|
|
1540
|
+
aInRange("signature.s", s, _0n4, CURVE_ORDER);
|
|
1541
|
+
const res = concatBytes(R, numberToBytesLE(s, Fp2.BYTES));
|
|
1542
|
+
return ensureBytes("result", res, Fp2.BYTES * 2);
|
|
1543
|
+
}
|
|
1544
|
+
__name(sign, "sign");
|
|
1545
|
+
const verifyOpts = VERIFY_DEFAULT;
|
|
1546
|
+
function verify(sig, msg, publicKey, options = verifyOpts) {
|
|
1547
|
+
const { context, zip215 } = options;
|
|
1548
|
+
const len = Fp2.BYTES;
|
|
1549
|
+
sig = ensureBytes("signature", sig, 2 * len);
|
|
1550
|
+
msg = ensureBytes("message", msg);
|
|
1551
|
+
publicKey = ensureBytes("publicKey", publicKey, len);
|
|
1552
|
+
if (zip215 !== void 0)
|
|
1553
|
+
abool("zip215", zip215);
|
|
1554
|
+
if (prehash)
|
|
1555
|
+
msg = prehash(msg);
|
|
1556
|
+
const s = bytesToNumberLE(sig.slice(len, 2 * len));
|
|
1557
|
+
let A, R, SB;
|
|
1558
|
+
try {
|
|
1559
|
+
A = Point.fromHex(publicKey, zip215);
|
|
1560
|
+
R = Point.fromHex(sig.slice(0, len), zip215);
|
|
1561
|
+
SB = G.multiplyUnsafe(s);
|
|
1562
|
+
} catch (error) {
|
|
1563
|
+
return false;
|
|
1564
|
+
}
|
|
1565
|
+
if (!zip215 && A.isSmallOrder())
|
|
1566
|
+
return false;
|
|
1567
|
+
const k = hashDomainToScalar(context, R.toRawBytes(), A.toRawBytes(), msg);
|
|
1568
|
+
const RkA = R.add(A.multiplyUnsafe(k));
|
|
1569
|
+
return RkA.subtract(SB).clearCofactor().equals(Point.ZERO);
|
|
1570
|
+
}
|
|
1571
|
+
__name(verify, "verify");
|
|
1572
|
+
G._setWindowSize(8);
|
|
1573
|
+
const utils = {
|
|
1574
|
+
getExtendedPublicKey,
|
|
1575
|
+
// ed25519 private keys are uniform 32b. No need to check for modulo bias, like in secp256k1.
|
|
1576
|
+
randomPrivateKey: /* @__PURE__ */ __name(() => randomBytes2(Fp2.BYTES), "randomPrivateKey"),
|
|
1577
|
+
/**
|
|
1578
|
+
* We're doing scalar multiplication (used in getPublicKey etc) with precomputed BASE_POINT
|
|
1579
|
+
* values. This slows down first getPublicKey() by milliseconds (see Speed section),
|
|
1580
|
+
* but allows to speed-up subsequent getPublicKey() calls up to 20x.
|
|
1581
|
+
* @param windowSize 2, 4, 8, 16
|
|
1582
|
+
*/
|
|
1583
|
+
precompute(windowSize = 8, point = Point.BASE) {
|
|
1584
|
+
point._setWindowSize(windowSize);
|
|
1585
|
+
point.multiply(BigInt(3));
|
|
1586
|
+
return point;
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
return {
|
|
1590
|
+
CURVE,
|
|
1591
|
+
getPublicKey,
|
|
1592
|
+
sign,
|
|
1593
|
+
verify,
|
|
1594
|
+
ExtendedPoint: Point,
|
|
1595
|
+
utils
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
__name(twistedEdwards, "twistedEdwards");
|
|
1599
|
+
|
|
1600
|
+
// ../../node_modules/@noble/curves/esm/ed25519.js
|
|
1601
|
+
var ED25519_P = BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949");
|
|
1602
|
+
var ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
1603
|
+
var _0n5 = BigInt(0);
|
|
1604
|
+
var _1n5 = BigInt(1);
|
|
1605
|
+
var _2n4 = BigInt(2);
|
|
1606
|
+
var _3n2 = BigInt(3);
|
|
1607
|
+
var _5n2 = BigInt(5);
|
|
1608
|
+
var _8n3 = BigInt(8);
|
|
1609
|
+
function ed25519_pow_2_252_3(x) {
|
|
1610
|
+
const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
|
|
1611
|
+
const P2 = ED25519_P;
|
|
1612
|
+
const x2 = x * x % P2;
|
|
1613
|
+
const b2 = x2 * x % P2;
|
|
1614
|
+
const b4 = pow2(b2, _2n4, P2) * b2 % P2;
|
|
1615
|
+
const b5 = pow2(b4, _1n5, P2) * x % P2;
|
|
1616
|
+
const b10 = pow2(b5, _5n2, P2) * b5 % P2;
|
|
1617
|
+
const b20 = pow2(b10, _10n, P2) * b10 % P2;
|
|
1618
|
+
const b40 = pow2(b20, _20n, P2) * b20 % P2;
|
|
1619
|
+
const b80 = pow2(b40, _40n, P2) * b40 % P2;
|
|
1620
|
+
const b160 = pow2(b80, _80n, P2) * b80 % P2;
|
|
1621
|
+
const b240 = pow2(b160, _80n, P2) * b80 % P2;
|
|
1622
|
+
const b250 = pow2(b240, _10n, P2) * b10 % P2;
|
|
1623
|
+
const pow_p_5_8 = pow2(b250, _2n4, P2) * x % P2;
|
|
1624
|
+
return { pow_p_5_8, b2 };
|
|
1625
|
+
}
|
|
1626
|
+
__name(ed25519_pow_2_252_3, "ed25519_pow_2_252_3");
|
|
1627
|
+
function adjustScalarBytes(bytes) {
|
|
1628
|
+
bytes[0] &= 248;
|
|
1629
|
+
bytes[31] &= 127;
|
|
1630
|
+
bytes[31] |= 64;
|
|
1631
|
+
return bytes;
|
|
1632
|
+
}
|
|
1633
|
+
__name(adjustScalarBytes, "adjustScalarBytes");
|
|
1634
|
+
function uvRatio(u, v) {
|
|
1635
|
+
const P2 = ED25519_P;
|
|
1636
|
+
const v3 = mod(v * v * v, P2);
|
|
1637
|
+
const v7 = mod(v3 * v3 * v, P2);
|
|
1638
|
+
const pow3 = ed25519_pow_2_252_3(u * v7).pow_p_5_8;
|
|
1639
|
+
let x = mod(u * v3 * pow3, P2);
|
|
1640
|
+
const vx2 = mod(v * x * x, P2);
|
|
1641
|
+
const root1 = x;
|
|
1642
|
+
const root2 = mod(x * ED25519_SQRT_M1, P2);
|
|
1643
|
+
const useRoot1 = vx2 === u;
|
|
1644
|
+
const useRoot2 = vx2 === mod(-u, P2);
|
|
1645
|
+
const noRoot = vx2 === mod(-u * ED25519_SQRT_M1, P2);
|
|
1646
|
+
if (useRoot1)
|
|
1647
|
+
x = root1;
|
|
1648
|
+
if (useRoot2 || noRoot)
|
|
1649
|
+
x = root2;
|
|
1650
|
+
if (isNegativeLE(x, P2))
|
|
1651
|
+
x = mod(-x, P2);
|
|
1652
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
1653
|
+
}
|
|
1654
|
+
__name(uvRatio, "uvRatio");
|
|
1655
|
+
var Fp = /* @__PURE__ */ (() => Field(ED25519_P, void 0, true))();
|
|
1656
|
+
var ed25519Defaults = /* @__PURE__ */ (() => ({
|
|
1657
|
+
// Param: a
|
|
1658
|
+
a: BigInt(-1),
|
|
1659
|
+
// Fp.create(-1) is proper; our way still works and is faster
|
|
1660
|
+
// d is equal to -121665/121666 over finite field.
|
|
1661
|
+
// Negative number is P - number, and division is invert(number, P)
|
|
1662
|
+
d: BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),
|
|
1663
|
+
// Finite field 𝔽p over which we'll do calculations; 2n**255n - 19n
|
|
1664
|
+
Fp,
|
|
1665
|
+
// Subgroup order: how many points curve has
|
|
1666
|
+
// 2n**252n + 27742317777372353535851937790883648493n;
|
|
1667
|
+
n: BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),
|
|
1668
|
+
// Cofactor
|
|
1669
|
+
h: _8n3,
|
|
1670
|
+
// Base point (x, y) aka generator point
|
|
1671
|
+
Gx: BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),
|
|
1672
|
+
Gy: BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),
|
|
1673
|
+
hash: sha512,
|
|
1674
|
+
randomBytes,
|
|
1675
|
+
adjustScalarBytes,
|
|
1676
|
+
// dom2
|
|
1677
|
+
// Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
|
|
1678
|
+
// Constant-time, u/√v
|
|
1679
|
+
uvRatio
|
|
1680
|
+
}))();
|
|
1681
|
+
var ed25519 = /* @__PURE__ */ (() => twistedEdwards(ed25519Defaults))();
|
|
1682
|
+
|
|
1683
|
+
// ../../node_modules/@noble/hashes/esm/_assert.js
|
|
1684
|
+
function isBytes3(a) {
|
|
1685
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1686
|
+
}
|
|
1687
|
+
__name(isBytes3, "isBytes");
|
|
1688
|
+
function abytes3(b, ...lengths) {
|
|
1689
|
+
if (!isBytes3(b))
|
|
1690
|
+
throw new Error("Uint8Array expected");
|
|
1691
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
1692
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
1693
|
+
}
|
|
1694
|
+
__name(abytes3, "abytes");
|
|
1695
|
+
function aexists2(instance, checkFinished = true) {
|
|
1696
|
+
if (instance.destroyed)
|
|
1697
|
+
throw new Error("Hash instance has been destroyed");
|
|
1698
|
+
if (checkFinished && instance.finished)
|
|
1699
|
+
throw new Error("Hash#digest() has already been called");
|
|
1700
|
+
}
|
|
1701
|
+
__name(aexists2, "aexists");
|
|
1702
|
+
function aoutput2(out, instance) {
|
|
1703
|
+
abytes3(out);
|
|
1704
|
+
const min = instance.outputLen;
|
|
1705
|
+
if (out.length < min) {
|
|
1706
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
__name(aoutput2, "aoutput");
|
|
1710
|
+
|
|
1711
|
+
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
1712
|
+
var createView2 = /* @__PURE__ */ __name((arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength), "createView");
|
|
1713
|
+
var rotr = /* @__PURE__ */ __name((word, shift) => word << 32 - shift | word >>> shift, "rotr");
|
|
1714
|
+
function utf8ToBytes2(str) {
|
|
1715
|
+
if (typeof str !== "string")
|
|
1716
|
+
throw new Error("utf8ToBytes expected string, got " + typeof str);
|
|
1717
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
1718
|
+
}
|
|
1719
|
+
__name(utf8ToBytes2, "utf8ToBytes");
|
|
1720
|
+
function toBytes2(data) {
|
|
1721
|
+
if (typeof data === "string")
|
|
1722
|
+
data = utf8ToBytes2(data);
|
|
1723
|
+
abytes3(data);
|
|
1724
|
+
return data;
|
|
1725
|
+
}
|
|
1726
|
+
__name(toBytes2, "toBytes");
|
|
1727
|
+
var Hash2 = class {
|
|
1728
|
+
static {
|
|
1729
|
+
__name(this, "Hash");
|
|
1730
|
+
}
|
|
1731
|
+
// Safe version that clones internal state
|
|
1732
|
+
clone() {
|
|
1733
|
+
return this._cloneInto();
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
function wrapConstructor2(hashCons) {
|
|
1737
|
+
const hashC = /* @__PURE__ */ __name((msg) => hashCons().update(toBytes2(msg)).digest(), "hashC");
|
|
1738
|
+
const tmp = hashCons();
|
|
1739
|
+
hashC.outputLen = tmp.outputLen;
|
|
1740
|
+
hashC.blockLen = tmp.blockLen;
|
|
1741
|
+
hashC.create = () => hashCons();
|
|
1742
|
+
return hashC;
|
|
1743
|
+
}
|
|
1744
|
+
__name(wrapConstructor2, "wrapConstructor");
|
|
1745
|
+
|
|
1746
|
+
// ../../node_modules/@noble/hashes/esm/_md.js
|
|
1747
|
+
function setBigUint642(view, byteOffset, value, isLE) {
|
|
1748
|
+
if (typeof view.setBigUint64 === "function")
|
|
1749
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
1750
|
+
const _32n2 = BigInt(32);
|
|
1751
|
+
const _u32_max = BigInt(4294967295);
|
|
1752
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
1753
|
+
const wl = Number(value & _u32_max);
|
|
1754
|
+
const h = isLE ? 4 : 0;
|
|
1755
|
+
const l = isLE ? 0 : 4;
|
|
1756
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
1757
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
1758
|
+
}
|
|
1759
|
+
__name(setBigUint642, "setBigUint64");
|
|
1760
|
+
var Chi = /* @__PURE__ */ __name((a, b, c) => a & b ^ ~a & c, "Chi");
|
|
1761
|
+
var Maj = /* @__PURE__ */ __name((a, b, c) => a & b ^ a & c ^ b & c, "Maj");
|
|
1762
|
+
var HashMD2 = class extends Hash2 {
|
|
1763
|
+
static {
|
|
1764
|
+
__name(this, "HashMD");
|
|
1765
|
+
}
|
|
1766
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
1767
|
+
super();
|
|
1768
|
+
this.blockLen = blockLen;
|
|
1769
|
+
this.outputLen = outputLen;
|
|
1770
|
+
this.padOffset = padOffset;
|
|
1771
|
+
this.isLE = isLE;
|
|
1772
|
+
this.finished = false;
|
|
1773
|
+
this.length = 0;
|
|
1774
|
+
this.pos = 0;
|
|
1775
|
+
this.destroyed = false;
|
|
1776
|
+
this.buffer = new Uint8Array(blockLen);
|
|
1777
|
+
this.view = createView2(this.buffer);
|
|
1778
|
+
}
|
|
1779
|
+
update(data) {
|
|
1780
|
+
aexists2(this);
|
|
1781
|
+
const { view, buffer, blockLen } = this;
|
|
1782
|
+
data = toBytes2(data);
|
|
1783
|
+
const len = data.length;
|
|
1784
|
+
for (let pos = 0; pos < len; ) {
|
|
1785
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1786
|
+
if (take === blockLen) {
|
|
1787
|
+
const dataView = createView2(data);
|
|
1788
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
1789
|
+
this.process(dataView, pos);
|
|
1790
|
+
continue;
|
|
1791
|
+
}
|
|
1792
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
1793
|
+
this.pos += take;
|
|
1794
|
+
pos += take;
|
|
1795
|
+
if (this.pos === blockLen) {
|
|
1796
|
+
this.process(view, 0);
|
|
1797
|
+
this.pos = 0;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
this.length += data.length;
|
|
1801
|
+
this.roundClean();
|
|
1802
|
+
return this;
|
|
1803
|
+
}
|
|
1804
|
+
digestInto(out) {
|
|
1805
|
+
aexists2(this);
|
|
1806
|
+
aoutput2(out, this);
|
|
1807
|
+
this.finished = true;
|
|
1808
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
1809
|
+
let { pos } = this;
|
|
1810
|
+
buffer[pos++] = 128;
|
|
1811
|
+
this.buffer.subarray(pos).fill(0);
|
|
1812
|
+
if (this.padOffset > blockLen - pos) {
|
|
1813
|
+
this.process(view, 0);
|
|
1814
|
+
pos = 0;
|
|
1815
|
+
}
|
|
1816
|
+
for (let i = pos; i < blockLen; i++)
|
|
1817
|
+
buffer[i] = 0;
|
|
1818
|
+
setBigUint642(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
1819
|
+
this.process(view, 0);
|
|
1820
|
+
const oview = createView2(out);
|
|
1821
|
+
const len = this.outputLen;
|
|
1822
|
+
if (len % 4)
|
|
1823
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1824
|
+
const outLen = len / 4;
|
|
1825
|
+
const state = this.get();
|
|
1826
|
+
if (outLen > state.length)
|
|
1827
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
1828
|
+
for (let i = 0; i < outLen; i++)
|
|
1829
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
1830
|
+
}
|
|
1831
|
+
digest() {
|
|
1832
|
+
const { buffer, outputLen } = this;
|
|
1833
|
+
this.digestInto(buffer);
|
|
1834
|
+
const res = buffer.slice(0, outputLen);
|
|
1835
|
+
this.destroy();
|
|
1836
|
+
return res;
|
|
1837
|
+
}
|
|
1838
|
+
_cloneInto(to) {
|
|
1839
|
+
to || (to = new this.constructor());
|
|
1840
|
+
to.set(...this.get());
|
|
1841
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
1842
|
+
to.length = length;
|
|
1843
|
+
to.pos = pos;
|
|
1844
|
+
to.finished = finished;
|
|
1845
|
+
to.destroyed = destroyed;
|
|
1846
|
+
if (length % blockLen)
|
|
1847
|
+
to.buffer.set(buffer);
|
|
1848
|
+
return to;
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
|
|
1852
|
+
// ../../node_modules/@noble/hashes/esm/sha256.js
|
|
1853
|
+
var SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
1854
|
+
1116352408,
|
|
1855
|
+
1899447441,
|
|
1856
|
+
3049323471,
|
|
1857
|
+
3921009573,
|
|
1858
|
+
961987163,
|
|
1859
|
+
1508970993,
|
|
1860
|
+
2453635748,
|
|
1861
|
+
2870763221,
|
|
1862
|
+
3624381080,
|
|
1863
|
+
310598401,
|
|
1864
|
+
607225278,
|
|
1865
|
+
1426881987,
|
|
1866
|
+
1925078388,
|
|
1867
|
+
2162078206,
|
|
1868
|
+
2614888103,
|
|
1869
|
+
3248222580,
|
|
1870
|
+
3835390401,
|
|
1871
|
+
4022224774,
|
|
1872
|
+
264347078,
|
|
1873
|
+
604807628,
|
|
1874
|
+
770255983,
|
|
1875
|
+
1249150122,
|
|
1876
|
+
1555081692,
|
|
1877
|
+
1996064986,
|
|
1878
|
+
2554220882,
|
|
1879
|
+
2821834349,
|
|
1880
|
+
2952996808,
|
|
1881
|
+
3210313671,
|
|
1882
|
+
3336571891,
|
|
1883
|
+
3584528711,
|
|
1884
|
+
113926993,
|
|
1885
|
+
338241895,
|
|
1886
|
+
666307205,
|
|
1887
|
+
773529912,
|
|
1888
|
+
1294757372,
|
|
1889
|
+
1396182291,
|
|
1890
|
+
1695183700,
|
|
1891
|
+
1986661051,
|
|
1892
|
+
2177026350,
|
|
1893
|
+
2456956037,
|
|
1894
|
+
2730485921,
|
|
1895
|
+
2820302411,
|
|
1896
|
+
3259730800,
|
|
1897
|
+
3345764771,
|
|
1898
|
+
3516065817,
|
|
1899
|
+
3600352804,
|
|
1900
|
+
4094571909,
|
|
1901
|
+
275423344,
|
|
1902
|
+
430227734,
|
|
1903
|
+
506948616,
|
|
1904
|
+
659060556,
|
|
1905
|
+
883997877,
|
|
1906
|
+
958139571,
|
|
1907
|
+
1322822218,
|
|
1908
|
+
1537002063,
|
|
1909
|
+
1747873779,
|
|
1910
|
+
1955562222,
|
|
1911
|
+
2024104815,
|
|
1912
|
+
2227730452,
|
|
1913
|
+
2361852424,
|
|
1914
|
+
2428436474,
|
|
1915
|
+
2756734187,
|
|
1916
|
+
3204031479,
|
|
1917
|
+
3329325298
|
|
1918
|
+
]);
|
|
1919
|
+
var SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
|
1920
|
+
1779033703,
|
|
1921
|
+
3144134277,
|
|
1922
|
+
1013904242,
|
|
1923
|
+
2773480762,
|
|
1924
|
+
1359893119,
|
|
1925
|
+
2600822924,
|
|
1926
|
+
528734635,
|
|
1927
|
+
1541459225
|
|
1928
|
+
]);
|
|
1929
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
1930
|
+
var SHA256 = class extends HashMD2 {
|
|
1931
|
+
static {
|
|
1932
|
+
__name(this, "SHA256");
|
|
1933
|
+
}
|
|
1934
|
+
constructor() {
|
|
1935
|
+
super(64, 32, 8, false);
|
|
1936
|
+
this.A = SHA256_IV[0] | 0;
|
|
1937
|
+
this.B = SHA256_IV[1] | 0;
|
|
1938
|
+
this.C = SHA256_IV[2] | 0;
|
|
1939
|
+
this.D = SHA256_IV[3] | 0;
|
|
1940
|
+
this.E = SHA256_IV[4] | 0;
|
|
1941
|
+
this.F = SHA256_IV[5] | 0;
|
|
1942
|
+
this.G = SHA256_IV[6] | 0;
|
|
1943
|
+
this.H = SHA256_IV[7] | 0;
|
|
1944
|
+
}
|
|
1945
|
+
get() {
|
|
1946
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
1947
|
+
return [A, B, C, D, E, F, G, H];
|
|
1948
|
+
}
|
|
1949
|
+
// prettier-ignore
|
|
1950
|
+
set(A, B, C, D, E, F, G, H) {
|
|
1951
|
+
this.A = A | 0;
|
|
1952
|
+
this.B = B | 0;
|
|
1953
|
+
this.C = C | 0;
|
|
1954
|
+
this.D = D | 0;
|
|
1955
|
+
this.E = E | 0;
|
|
1956
|
+
this.F = F | 0;
|
|
1957
|
+
this.G = G | 0;
|
|
1958
|
+
this.H = H | 0;
|
|
1959
|
+
}
|
|
1960
|
+
process(view, offset) {
|
|
1961
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
1962
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
1963
|
+
for (let i = 16; i < 64; i++) {
|
|
1964
|
+
const W15 = SHA256_W[i - 15];
|
|
1965
|
+
const W2 = SHA256_W[i - 2];
|
|
1966
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
1967
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
1968
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
1969
|
+
}
|
|
1970
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
1971
|
+
for (let i = 0; i < 64; i++) {
|
|
1972
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
1973
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
1974
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
1975
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
1976
|
+
H = G;
|
|
1977
|
+
G = F;
|
|
1978
|
+
F = E;
|
|
1979
|
+
E = D + T1 | 0;
|
|
1980
|
+
D = C;
|
|
1981
|
+
C = B;
|
|
1982
|
+
B = A;
|
|
1983
|
+
A = T1 + T2 | 0;
|
|
1984
|
+
}
|
|
1985
|
+
A = A + this.A | 0;
|
|
1986
|
+
B = B + this.B | 0;
|
|
1987
|
+
C = C + this.C | 0;
|
|
1988
|
+
D = D + this.D | 0;
|
|
1989
|
+
E = E + this.E | 0;
|
|
1990
|
+
F = F + this.F | 0;
|
|
1991
|
+
G = G + this.G | 0;
|
|
1992
|
+
H = H + this.H | 0;
|
|
1993
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
1994
|
+
}
|
|
1995
|
+
roundClean() {
|
|
1996
|
+
SHA256_W.fill(0);
|
|
1997
|
+
}
|
|
1998
|
+
destroy() {
|
|
1999
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
2000
|
+
this.buffer.fill(0);
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
var sha256 = /* @__PURE__ */ wrapConstructor2(() => new SHA256());
|
|
2004
|
+
|
|
2005
|
+
// ../../node_modules/base58-js/base58_chars.mjs
|
|
2006
|
+
var base58_chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2007
|
+
var base58_chars_default = base58_chars;
|
|
2008
|
+
|
|
2009
|
+
// ../../node_modules/base58-js/base58_to_binary.mjs
|
|
2010
|
+
function base58_to_binary(base58String) {
|
|
2011
|
+
if (!base58String || typeof base58String !== "string")
|
|
2012
|
+
throw new Error(`Expected base58 string but got \u201C${base58String}\u201D`);
|
|
2013
|
+
if (base58String.match(/[IOl0]/gmu))
|
|
2014
|
+
throw new Error(
|
|
2015
|
+
`Invalid base58 character \u201C${base58String.match(/[IOl0]/gmu)}\u201D`
|
|
2016
|
+
);
|
|
2017
|
+
const lz = base58String.match(/^1+/gmu);
|
|
2018
|
+
const psz = lz ? lz[0].length : 0;
|
|
2019
|
+
const size = (base58String.length - psz) * (Math.log(58) / Math.log(256)) + 1 >>> 0;
|
|
2020
|
+
return new Uint8Array([
|
|
2021
|
+
...new Uint8Array(psz),
|
|
2022
|
+
...base58String.match(/.{1}/gmu).map((i) => base58_chars_default.indexOf(i)).reduce((acc, i) => {
|
|
2023
|
+
acc = acc.map((j) => {
|
|
2024
|
+
const x = j * 58 + i;
|
|
2025
|
+
i = x >> 8;
|
|
2026
|
+
return x;
|
|
2027
|
+
});
|
|
2028
|
+
return acc;
|
|
2029
|
+
}, new Uint8Array(size)).reverse().filter(
|
|
2030
|
+
/* @__PURE__ */ ((lastValue) => (value) => (
|
|
2031
|
+
// @ts-ignore
|
|
2032
|
+
lastValue = lastValue || value
|
|
2033
|
+
))(false)
|
|
2034
|
+
)
|
|
2035
|
+
]);
|
|
2036
|
+
}
|
|
2037
|
+
__name(base58_to_binary, "base58_to_binary");
|
|
2038
|
+
var base58_to_binary_default = base58_to_binary;
|
|
2039
|
+
|
|
2040
|
+
// ../../node_modules/base58-js/create_base58_map.mjs
|
|
2041
|
+
var create_base58_map = /* @__PURE__ */ __name(() => {
|
|
2042
|
+
const base58M = Array(256).fill(-1);
|
|
2043
|
+
for (let i = 0; i < base58_chars_default.length; ++i)
|
|
2044
|
+
base58M[base58_chars_default.charCodeAt(i)] = i;
|
|
2045
|
+
return base58M;
|
|
2046
|
+
}, "create_base58_map");
|
|
2047
|
+
var create_base58_map_default = create_base58_map;
|
|
2048
|
+
|
|
2049
|
+
// ../../node_modules/base58-js/binary_to_base58.mjs
|
|
2050
|
+
var base58Map = create_base58_map_default();
|
|
2051
|
+
function binary_to_base58(uint8array) {
|
|
2052
|
+
const result = [];
|
|
2053
|
+
for (const byte of uint8array) {
|
|
2054
|
+
let carry = byte;
|
|
2055
|
+
for (let j = 0; j < result.length; ++j) {
|
|
2056
|
+
const x = (base58Map[result[j]] << 8) + carry;
|
|
2057
|
+
result[j] = base58_chars_default.charCodeAt(x % 58);
|
|
2058
|
+
carry = x / 58 | 0;
|
|
2059
|
+
}
|
|
2060
|
+
while (carry) {
|
|
2061
|
+
result.push(base58_chars_default.charCodeAt(carry % 58));
|
|
2062
|
+
carry = carry / 58 | 0;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
for (const byte of uint8array)
|
|
2066
|
+
if (byte) break;
|
|
2067
|
+
else result.push("1".charCodeAt(0));
|
|
2068
|
+
result.reverse();
|
|
2069
|
+
return String.fromCharCode(...result);
|
|
2070
|
+
}
|
|
2071
|
+
__name(binary_to_base58, "binary_to_base58");
|
|
2072
|
+
var binary_to_base58_default = binary_to_base58;
|
|
2073
|
+
|
|
2074
|
+
// ../../node_modules/big.js/big.mjs
|
|
2075
|
+
var DP = 20;
|
|
2076
|
+
var RM = 1;
|
|
2077
|
+
var MAX_DP = 1e6;
|
|
2078
|
+
var MAX_POWER = 1e6;
|
|
2079
|
+
var NE = -7;
|
|
2080
|
+
var PE = 21;
|
|
2081
|
+
var STRICT = false;
|
|
2082
|
+
var NAME = "[big.js] ";
|
|
2083
|
+
var INVALID = NAME + "Invalid ";
|
|
2084
|
+
var INVALID_DP = INVALID + "decimal places";
|
|
2085
|
+
var INVALID_RM = INVALID + "rounding mode";
|
|
2086
|
+
var DIV_BY_ZERO = NAME + "Division by zero";
|
|
2087
|
+
var P = {};
|
|
2088
|
+
var UNDEFINED = void 0;
|
|
2089
|
+
var NUMERIC = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
2090
|
+
function _Big_() {
|
|
2091
|
+
function Big2(n) {
|
|
2092
|
+
var x = this;
|
|
2093
|
+
if (!(x instanceof Big2)) return n === UNDEFINED ? _Big_() : new Big2(n);
|
|
2094
|
+
if (n instanceof Big2) {
|
|
2095
|
+
x.s = n.s;
|
|
2096
|
+
x.e = n.e;
|
|
2097
|
+
x.c = n.c.slice();
|
|
2098
|
+
} else {
|
|
2099
|
+
if (typeof n !== "string") {
|
|
2100
|
+
if (Big2.strict === true && typeof n !== "bigint") {
|
|
2101
|
+
throw TypeError(INVALID + "value");
|
|
2102
|
+
}
|
|
2103
|
+
n = n === 0 && 1 / n < 0 ? "-0" : String(n);
|
|
2104
|
+
}
|
|
2105
|
+
parse(x, n);
|
|
2106
|
+
}
|
|
2107
|
+
x.constructor = Big2;
|
|
2108
|
+
}
|
|
2109
|
+
__name(Big2, "Big");
|
|
2110
|
+
Big2.prototype = P;
|
|
2111
|
+
Big2.DP = DP;
|
|
2112
|
+
Big2.RM = RM;
|
|
2113
|
+
Big2.NE = NE;
|
|
2114
|
+
Big2.PE = PE;
|
|
2115
|
+
Big2.strict = STRICT;
|
|
2116
|
+
Big2.roundDown = 0;
|
|
2117
|
+
Big2.roundHalfUp = 1;
|
|
2118
|
+
Big2.roundHalfEven = 2;
|
|
2119
|
+
Big2.roundUp = 3;
|
|
2120
|
+
return Big2;
|
|
2121
|
+
}
|
|
2122
|
+
__name(_Big_, "_Big_");
|
|
2123
|
+
function parse(x, n) {
|
|
2124
|
+
var e, i, nl;
|
|
2125
|
+
if (!NUMERIC.test(n)) {
|
|
2126
|
+
throw Error(INVALID + "number");
|
|
2127
|
+
}
|
|
2128
|
+
x.s = n.charAt(0) == "-" ? (n = n.slice(1), -1) : 1;
|
|
2129
|
+
if ((e = n.indexOf(".")) > -1) n = n.replace(".", "");
|
|
2130
|
+
if ((i = n.search(/e/i)) > 0) {
|
|
2131
|
+
if (e < 0) e = i;
|
|
2132
|
+
e += +n.slice(i + 1);
|
|
2133
|
+
n = n.substring(0, i);
|
|
2134
|
+
} else if (e < 0) {
|
|
2135
|
+
e = n.length;
|
|
2136
|
+
}
|
|
2137
|
+
nl = n.length;
|
|
2138
|
+
for (i = 0; i < nl && n.charAt(i) == "0"; ) ++i;
|
|
2139
|
+
if (i == nl) {
|
|
2140
|
+
x.c = [x.e = 0];
|
|
2141
|
+
} else {
|
|
2142
|
+
for (; nl > 0 && n.charAt(--nl) == "0"; ) ;
|
|
2143
|
+
x.e = e - i - 1;
|
|
2144
|
+
x.c = [];
|
|
2145
|
+
for (e = 0; i <= nl; ) x.c[e++] = +n.charAt(i++);
|
|
2146
|
+
}
|
|
2147
|
+
return x;
|
|
2148
|
+
}
|
|
2149
|
+
__name(parse, "parse");
|
|
2150
|
+
function round(x, sd, rm, more) {
|
|
2151
|
+
var xc = x.c;
|
|
2152
|
+
if (rm === UNDEFINED) rm = x.constructor.RM;
|
|
2153
|
+
if (rm !== 0 && rm !== 1 && rm !== 2 && rm !== 3) {
|
|
2154
|
+
throw Error(INVALID_RM);
|
|
2155
|
+
}
|
|
2156
|
+
if (sd < 1) {
|
|
2157
|
+
more = rm === 3 && (more || !!xc[0]) || sd === 0 && (rm === 1 && xc[0] >= 5 || rm === 2 && (xc[0] > 5 || xc[0] === 5 && (more || xc[1] !== UNDEFINED)));
|
|
2158
|
+
xc.length = 1;
|
|
2159
|
+
if (more) {
|
|
2160
|
+
x.e = x.e - sd + 1;
|
|
2161
|
+
xc[0] = 1;
|
|
2162
|
+
} else {
|
|
2163
|
+
xc[0] = x.e = 0;
|
|
2164
|
+
}
|
|
2165
|
+
} else if (sd < xc.length) {
|
|
2166
|
+
more = rm === 1 && xc[sd] >= 5 || rm === 2 && (xc[sd] > 5 || xc[sd] === 5 && (more || xc[sd + 1] !== UNDEFINED || xc[sd - 1] & 1)) || rm === 3 && (more || !!xc[0]);
|
|
2167
|
+
xc.length = sd;
|
|
2168
|
+
if (more) {
|
|
2169
|
+
for (; ++xc[--sd] > 9; ) {
|
|
2170
|
+
xc[sd] = 0;
|
|
2171
|
+
if (sd === 0) {
|
|
2172
|
+
++x.e;
|
|
2173
|
+
xc.unshift(1);
|
|
2174
|
+
break;
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
for (sd = xc.length; !xc[--sd]; ) xc.pop();
|
|
2179
|
+
}
|
|
2180
|
+
return x;
|
|
2181
|
+
}
|
|
2182
|
+
__name(round, "round");
|
|
2183
|
+
function stringify(x, doExponential, isNonzero) {
|
|
2184
|
+
var e = x.e, s = x.c.join(""), n = s.length;
|
|
2185
|
+
if (doExponential) {
|
|
2186
|
+
s = s.charAt(0) + (n > 1 ? "." + s.slice(1) : "") + (e < 0 ? "e" : "e+") + e;
|
|
2187
|
+
} else if (e < 0) {
|
|
2188
|
+
for (; ++e; ) s = "0" + s;
|
|
2189
|
+
s = "0." + s;
|
|
2190
|
+
} else if (e > 0) {
|
|
2191
|
+
if (++e > n) {
|
|
2192
|
+
for (e -= n; e--; ) s += "0";
|
|
2193
|
+
} else if (e < n) {
|
|
2194
|
+
s = s.slice(0, e) + "." + s.slice(e);
|
|
2195
|
+
}
|
|
2196
|
+
} else if (n > 1) {
|
|
2197
|
+
s = s.charAt(0) + "." + s.slice(1);
|
|
2198
|
+
}
|
|
2199
|
+
return x.s < 0 && isNonzero ? "-" + s : s;
|
|
2200
|
+
}
|
|
2201
|
+
__name(stringify, "stringify");
|
|
2202
|
+
P.abs = function() {
|
|
2203
|
+
var x = new this.constructor(this);
|
|
2204
|
+
x.s = 1;
|
|
2205
|
+
return x;
|
|
2206
|
+
};
|
|
2207
|
+
P.cmp = function(y) {
|
|
2208
|
+
var isneg, x = this, xc = x.c, yc = (y = new x.constructor(y)).c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
2209
|
+
if (!xc[0] || !yc[0]) return !xc[0] ? !yc[0] ? 0 : -j : i;
|
|
2210
|
+
if (i != j) return i;
|
|
2211
|
+
isneg = i < 0;
|
|
2212
|
+
if (k != l) return k > l ^ isneg ? 1 : -1;
|
|
2213
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
2214
|
+
for (i = -1; ++i < j; ) {
|
|
2215
|
+
if (xc[i] != yc[i]) return xc[i] > yc[i] ^ isneg ? 1 : -1;
|
|
2216
|
+
}
|
|
2217
|
+
return k == l ? 0 : k > l ^ isneg ? 1 : -1;
|
|
2218
|
+
};
|
|
2219
|
+
P.div = function(y) {
|
|
2220
|
+
var x = this, Big2 = x.constructor, a = x.c, b = (y = new Big2(y)).c, k = x.s == y.s ? 1 : -1, dp = Big2.DP;
|
|
2221
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
2222
|
+
throw Error(INVALID_DP);
|
|
2223
|
+
}
|
|
2224
|
+
if (!b[0]) {
|
|
2225
|
+
throw Error(DIV_BY_ZERO);
|
|
2226
|
+
}
|
|
2227
|
+
if (!a[0]) {
|
|
2228
|
+
y.s = k;
|
|
2229
|
+
y.c = [y.e = 0];
|
|
2230
|
+
return y;
|
|
2231
|
+
}
|
|
2232
|
+
var bl, bt, n, cmp, ri, bz = b.slice(), ai = bl = b.length, al = a.length, r = a.slice(0, bl), rl = r.length, q = y, qc = q.c = [], qi = 0, p = dp + (q.e = x.e - y.e) + 1;
|
|
2233
|
+
q.s = k;
|
|
2234
|
+
k = p < 0 ? 0 : p;
|
|
2235
|
+
bz.unshift(0);
|
|
2236
|
+
for (; rl++ < bl; ) r.push(0);
|
|
2237
|
+
do {
|
|
2238
|
+
for (n = 0; n < 10; n++) {
|
|
2239
|
+
if (bl != (rl = r.length)) {
|
|
2240
|
+
cmp = bl > rl ? 1 : -1;
|
|
2241
|
+
} else {
|
|
2242
|
+
for (ri = -1, cmp = 0; ++ri < bl; ) {
|
|
2243
|
+
if (b[ri] != r[ri]) {
|
|
2244
|
+
cmp = b[ri] > r[ri] ? 1 : -1;
|
|
2245
|
+
break;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
if (cmp < 0) {
|
|
2250
|
+
for (bt = rl == bl ? b : bz; rl; ) {
|
|
2251
|
+
if (r[--rl] < bt[rl]) {
|
|
2252
|
+
ri = rl;
|
|
2253
|
+
for (; ri && !r[--ri]; ) r[ri] = 9;
|
|
2254
|
+
--r[ri];
|
|
2255
|
+
r[rl] += 10;
|
|
2256
|
+
}
|
|
2257
|
+
r[rl] -= bt[rl];
|
|
2258
|
+
}
|
|
2259
|
+
for (; !r[0]; ) r.shift();
|
|
2260
|
+
} else {
|
|
2261
|
+
break;
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
qc[qi++] = cmp ? n : ++n;
|
|
2265
|
+
if (r[0] && cmp) r[rl] = a[ai] || 0;
|
|
2266
|
+
else r = [a[ai]];
|
|
2267
|
+
} while ((ai++ < al || r[0] !== UNDEFINED) && k--);
|
|
2268
|
+
if (!qc[0] && qi != 1) {
|
|
2269
|
+
qc.shift();
|
|
2270
|
+
q.e--;
|
|
2271
|
+
p--;
|
|
2272
|
+
}
|
|
2273
|
+
if (qi > p) round(q, p, Big2.RM, r[0] !== UNDEFINED);
|
|
2274
|
+
return q;
|
|
2275
|
+
};
|
|
2276
|
+
P.eq = function(y) {
|
|
2277
|
+
return this.cmp(y) === 0;
|
|
2278
|
+
};
|
|
2279
|
+
P.gt = function(y) {
|
|
2280
|
+
return this.cmp(y) > 0;
|
|
2281
|
+
};
|
|
2282
|
+
P.gte = function(y) {
|
|
2283
|
+
return this.cmp(y) > -1;
|
|
2284
|
+
};
|
|
2285
|
+
P.lt = function(y) {
|
|
2286
|
+
return this.cmp(y) < 0;
|
|
2287
|
+
};
|
|
2288
|
+
P.lte = function(y) {
|
|
2289
|
+
return this.cmp(y) < 1;
|
|
2290
|
+
};
|
|
2291
|
+
P.minus = P.sub = function(y) {
|
|
2292
|
+
var i, j, t, xlty, x = this, Big2 = x.constructor, a = x.s, b = (y = new Big2(y)).s;
|
|
2293
|
+
if (a != b) {
|
|
2294
|
+
y.s = -b;
|
|
2295
|
+
return x.plus(y);
|
|
2296
|
+
}
|
|
2297
|
+
var xc = x.c.slice(), xe = x.e, yc = y.c, ye = y.e;
|
|
2298
|
+
if (!xc[0] || !yc[0]) {
|
|
2299
|
+
if (yc[0]) {
|
|
2300
|
+
y.s = -b;
|
|
2301
|
+
} else if (xc[0]) {
|
|
2302
|
+
y = new Big2(x);
|
|
2303
|
+
} else {
|
|
2304
|
+
y.s = 1;
|
|
2305
|
+
}
|
|
2306
|
+
return y;
|
|
2307
|
+
}
|
|
2308
|
+
if (a = xe - ye) {
|
|
2309
|
+
if (xlty = a < 0) {
|
|
2310
|
+
a = -a;
|
|
2311
|
+
t = xc;
|
|
2312
|
+
} else {
|
|
2313
|
+
ye = xe;
|
|
2314
|
+
t = yc;
|
|
2315
|
+
}
|
|
2316
|
+
t.reverse();
|
|
2317
|
+
for (b = a; b--; ) t.push(0);
|
|
2318
|
+
t.reverse();
|
|
2319
|
+
} else {
|
|
2320
|
+
j = ((xlty = xc.length < yc.length) ? xc : yc).length;
|
|
2321
|
+
for (a = b = 0; b < j; b++) {
|
|
2322
|
+
if (xc[b] != yc[b]) {
|
|
2323
|
+
xlty = xc[b] < yc[b];
|
|
2324
|
+
break;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
if (xlty) {
|
|
2329
|
+
t = xc;
|
|
2330
|
+
xc = yc;
|
|
2331
|
+
yc = t;
|
|
2332
|
+
y.s = -y.s;
|
|
2333
|
+
}
|
|
2334
|
+
if ((b = (j = yc.length) - (i = xc.length)) > 0) for (; b--; ) xc[i++] = 0;
|
|
2335
|
+
for (b = i; j > a; ) {
|
|
2336
|
+
if (xc[--j] < yc[j]) {
|
|
2337
|
+
for (i = j; i && !xc[--i]; ) xc[i] = 9;
|
|
2338
|
+
--xc[i];
|
|
2339
|
+
xc[j] += 10;
|
|
2340
|
+
}
|
|
2341
|
+
xc[j] -= yc[j];
|
|
2342
|
+
}
|
|
2343
|
+
for (; xc[--b] === 0; ) xc.pop();
|
|
2344
|
+
for (; xc[0] === 0; ) {
|
|
2345
|
+
xc.shift();
|
|
2346
|
+
--ye;
|
|
2347
|
+
}
|
|
2348
|
+
if (!xc[0]) {
|
|
2349
|
+
y.s = 1;
|
|
2350
|
+
xc = [ye = 0];
|
|
2351
|
+
}
|
|
2352
|
+
y.c = xc;
|
|
2353
|
+
y.e = ye;
|
|
2354
|
+
return y;
|
|
2355
|
+
};
|
|
2356
|
+
P.mod = function(y) {
|
|
2357
|
+
var ygtx, x = this, Big2 = x.constructor, a = x.s, b = (y = new Big2(y)).s;
|
|
2358
|
+
if (!y.c[0]) {
|
|
2359
|
+
throw Error(DIV_BY_ZERO);
|
|
2360
|
+
}
|
|
2361
|
+
x.s = y.s = 1;
|
|
2362
|
+
ygtx = y.cmp(x) == 1;
|
|
2363
|
+
x.s = a;
|
|
2364
|
+
y.s = b;
|
|
2365
|
+
if (ygtx) return new Big2(x);
|
|
2366
|
+
a = Big2.DP;
|
|
2367
|
+
b = Big2.RM;
|
|
2368
|
+
Big2.DP = Big2.RM = 0;
|
|
2369
|
+
x = x.div(y);
|
|
2370
|
+
Big2.DP = a;
|
|
2371
|
+
Big2.RM = b;
|
|
2372
|
+
return this.minus(x.times(y));
|
|
2373
|
+
};
|
|
2374
|
+
P.neg = function() {
|
|
2375
|
+
var x = new this.constructor(this);
|
|
2376
|
+
x.s = -x.s;
|
|
2377
|
+
return x;
|
|
2378
|
+
};
|
|
2379
|
+
P.plus = P.add = function(y) {
|
|
2380
|
+
var e, k, t, x = this, Big2 = x.constructor;
|
|
2381
|
+
y = new Big2(y);
|
|
2382
|
+
if (x.s != y.s) {
|
|
2383
|
+
y.s = -y.s;
|
|
2384
|
+
return x.minus(y);
|
|
2385
|
+
}
|
|
2386
|
+
var xe = x.e, xc = x.c, ye = y.e, yc = y.c;
|
|
2387
|
+
if (!xc[0] || !yc[0]) {
|
|
2388
|
+
if (!yc[0]) {
|
|
2389
|
+
if (xc[0]) {
|
|
2390
|
+
y = new Big2(x);
|
|
2391
|
+
} else {
|
|
2392
|
+
y.s = x.s;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
return y;
|
|
2396
|
+
}
|
|
2397
|
+
xc = xc.slice();
|
|
2398
|
+
if (e = xe - ye) {
|
|
2399
|
+
if (e > 0) {
|
|
2400
|
+
ye = xe;
|
|
2401
|
+
t = yc;
|
|
2402
|
+
} else {
|
|
2403
|
+
e = -e;
|
|
2404
|
+
t = xc;
|
|
2405
|
+
}
|
|
2406
|
+
t.reverse();
|
|
2407
|
+
for (; e--; ) t.push(0);
|
|
2408
|
+
t.reverse();
|
|
2409
|
+
}
|
|
2410
|
+
if (xc.length - yc.length < 0) {
|
|
2411
|
+
t = yc;
|
|
2412
|
+
yc = xc;
|
|
2413
|
+
xc = t;
|
|
2414
|
+
}
|
|
2415
|
+
e = yc.length;
|
|
2416
|
+
for (k = 0; e; xc[e] %= 10) k = (xc[--e] = xc[e] + yc[e] + k) / 10 | 0;
|
|
2417
|
+
if (k) {
|
|
2418
|
+
xc.unshift(k);
|
|
2419
|
+
++ye;
|
|
2420
|
+
}
|
|
2421
|
+
for (e = xc.length; xc[--e] === 0; ) xc.pop();
|
|
2422
|
+
y.c = xc;
|
|
2423
|
+
y.e = ye;
|
|
2424
|
+
return y;
|
|
2425
|
+
};
|
|
2426
|
+
P.pow = function(n) {
|
|
2427
|
+
var x = this, one = new x.constructor("1"), y = one, isneg = n < 0;
|
|
2428
|
+
if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) {
|
|
2429
|
+
throw Error(INVALID + "exponent");
|
|
2430
|
+
}
|
|
2431
|
+
if (isneg) n = -n;
|
|
2432
|
+
for (; ; ) {
|
|
2433
|
+
if (n & 1) y = y.times(x);
|
|
2434
|
+
n >>= 1;
|
|
2435
|
+
if (!n) break;
|
|
2436
|
+
x = x.times(x);
|
|
2437
|
+
}
|
|
2438
|
+
return isneg ? one.div(y) : y;
|
|
2439
|
+
};
|
|
2440
|
+
P.prec = function(sd, rm) {
|
|
2441
|
+
if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
|
|
2442
|
+
throw Error(INVALID + "precision");
|
|
2443
|
+
}
|
|
2444
|
+
return round(new this.constructor(this), sd, rm);
|
|
2445
|
+
};
|
|
2446
|
+
P.round = function(dp, rm) {
|
|
2447
|
+
if (dp === UNDEFINED) dp = 0;
|
|
2448
|
+
else if (dp !== ~~dp || dp < -MAX_DP || dp > MAX_DP) {
|
|
2449
|
+
throw Error(INVALID_DP);
|
|
2450
|
+
}
|
|
2451
|
+
return round(new this.constructor(this), dp + this.e + 1, rm);
|
|
2452
|
+
};
|
|
2453
|
+
P.sqrt = function() {
|
|
2454
|
+
var r, c, t, x = this, Big2 = x.constructor, s = x.s, e = x.e, half = new Big2("0.5");
|
|
2455
|
+
if (!x.c[0]) return new Big2(x);
|
|
2456
|
+
if (s < 0) {
|
|
2457
|
+
throw Error(NAME + "No square root");
|
|
2458
|
+
}
|
|
2459
|
+
s = Math.sqrt(+stringify(x, true, true));
|
|
2460
|
+
if (s === 0 || s === 1 / 0) {
|
|
2461
|
+
c = x.c.join("");
|
|
2462
|
+
if (!(c.length + e & 1)) c += "0";
|
|
2463
|
+
s = Math.sqrt(c);
|
|
2464
|
+
e = ((e + 1) / 2 | 0) - (e < 0 || e & 1);
|
|
2465
|
+
r = new Big2((s == 1 / 0 ? "5e" : (s = s.toExponential()).slice(0, s.indexOf("e") + 1)) + e);
|
|
2466
|
+
} else {
|
|
2467
|
+
r = new Big2(s + "");
|
|
2468
|
+
}
|
|
2469
|
+
e = r.e + (Big2.DP += 4);
|
|
2470
|
+
do {
|
|
2471
|
+
t = r;
|
|
2472
|
+
r = half.times(t.plus(x.div(t)));
|
|
2473
|
+
} while (t.c.slice(0, e).join("") !== r.c.slice(0, e).join(""));
|
|
2474
|
+
return round(r, (Big2.DP -= 4) + r.e + 1, Big2.RM);
|
|
2475
|
+
};
|
|
2476
|
+
P.times = P.mul = function(y) {
|
|
2477
|
+
var c, x = this, Big2 = x.constructor, xc = x.c, yc = (y = new Big2(y)).c, a = xc.length, b = yc.length, i = x.e, j = y.e;
|
|
2478
|
+
y.s = x.s == y.s ? 1 : -1;
|
|
2479
|
+
if (!xc[0] || !yc[0]) {
|
|
2480
|
+
y.c = [y.e = 0];
|
|
2481
|
+
return y;
|
|
2482
|
+
}
|
|
2483
|
+
y.e = i + j;
|
|
2484
|
+
if (a < b) {
|
|
2485
|
+
c = xc;
|
|
2486
|
+
xc = yc;
|
|
2487
|
+
yc = c;
|
|
2488
|
+
j = a;
|
|
2489
|
+
a = b;
|
|
2490
|
+
b = j;
|
|
2491
|
+
}
|
|
2492
|
+
for (c = new Array(j = a + b); j--; ) c[j] = 0;
|
|
2493
|
+
for (i = b; i--; ) {
|
|
2494
|
+
b = 0;
|
|
2495
|
+
for (j = a + i; j > i; ) {
|
|
2496
|
+
b = c[j] + yc[i] * xc[j - i - 1] + b;
|
|
2497
|
+
c[j--] = b % 10;
|
|
2498
|
+
b = b / 10 | 0;
|
|
2499
|
+
}
|
|
2500
|
+
c[j] = b;
|
|
2501
|
+
}
|
|
2502
|
+
if (b) ++y.e;
|
|
2503
|
+
else c.shift();
|
|
2504
|
+
for (i = c.length; !c[--i]; ) c.pop();
|
|
2505
|
+
y.c = c;
|
|
2506
|
+
return y;
|
|
2507
|
+
};
|
|
2508
|
+
P.toExponential = function(dp, rm) {
|
|
2509
|
+
var x = this, n = x.c[0];
|
|
2510
|
+
if (dp !== UNDEFINED) {
|
|
2511
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
2512
|
+
throw Error(INVALID_DP);
|
|
2513
|
+
}
|
|
2514
|
+
x = round(new x.constructor(x), ++dp, rm);
|
|
2515
|
+
for (; x.c.length < dp; ) x.c.push(0);
|
|
2516
|
+
}
|
|
2517
|
+
return stringify(x, true, !!n);
|
|
2518
|
+
};
|
|
2519
|
+
P.toFixed = function(dp, rm) {
|
|
2520
|
+
var x = this, n = x.c[0];
|
|
2521
|
+
if (dp !== UNDEFINED) {
|
|
2522
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
2523
|
+
throw Error(INVALID_DP);
|
|
2524
|
+
}
|
|
2525
|
+
x = round(new x.constructor(x), dp + x.e + 1, rm);
|
|
2526
|
+
for (dp = dp + x.e + 1; x.c.length < dp; ) x.c.push(0);
|
|
2527
|
+
}
|
|
2528
|
+
return stringify(x, false, !!n);
|
|
2529
|
+
};
|
|
2530
|
+
P[Symbol.for("nodejs.util.inspect.custom")] = P.toJSON = P.toString = function() {
|
|
2531
|
+
var x = this, Big2 = x.constructor;
|
|
2532
|
+
return stringify(x, x.e <= Big2.NE || x.e >= Big2.PE, !!x.c[0]);
|
|
2533
|
+
};
|
|
2534
|
+
P.toNumber = function() {
|
|
2535
|
+
var n = +stringify(this, true, true);
|
|
2536
|
+
if (this.constructor.strict === true && !this.eq(n.toString())) {
|
|
2537
|
+
throw Error(NAME + "Imprecise conversion");
|
|
2538
|
+
}
|
|
2539
|
+
return n;
|
|
2540
|
+
};
|
|
2541
|
+
P.toPrecision = function(sd, rm) {
|
|
2542
|
+
var x = this, Big2 = x.constructor, n = x.c[0];
|
|
2543
|
+
if (sd !== UNDEFINED) {
|
|
2544
|
+
if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
|
|
2545
|
+
throw Error(INVALID + "precision");
|
|
2546
|
+
}
|
|
2547
|
+
x = round(new Big2(x), sd, rm);
|
|
2548
|
+
for (; x.c.length < sd; ) x.c.push(0);
|
|
2549
|
+
}
|
|
2550
|
+
return stringify(x, sd <= x.e || x.e <= Big2.NE || x.e >= Big2.PE, !!n);
|
|
2551
|
+
};
|
|
2552
|
+
P.valueOf = function() {
|
|
2553
|
+
var x = this, Big2 = x.constructor;
|
|
2554
|
+
if (Big2.strict === true) {
|
|
2555
|
+
throw Error(NAME + "valueOf disallowed");
|
|
2556
|
+
}
|
|
2557
|
+
return stringify(x, x.e <= Big2.NE || x.e >= Big2.PE, true);
|
|
2558
|
+
};
|
|
2559
|
+
var Big = _Big_();
|
|
2560
|
+
var big_default = Big;
|
|
2561
|
+
|
|
2562
|
+
// ../../node_modules/js-base64/base64.mjs
|
|
2563
|
+
var _hasBuffer = typeof Buffer === "function";
|
|
2564
|
+
var _TD = typeof TextDecoder === "function" ? new TextDecoder() : void 0;
|
|
2565
|
+
var _TE = typeof TextEncoder === "function" ? new TextEncoder() : void 0;
|
|
2566
|
+
var b64ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
2567
|
+
var b64chs = Array.prototype.slice.call(b64ch);
|
|
2568
|
+
var b64tab = ((a) => {
|
|
2569
|
+
let tab = {};
|
|
2570
|
+
a.forEach((c, i) => tab[c] = i);
|
|
2571
|
+
return tab;
|
|
2572
|
+
})(b64chs);
|
|
2573
|
+
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
2574
|
+
var _fromCC = String.fromCharCode.bind(String);
|
|
2575
|
+
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it) => new Uint8Array(Array.prototype.slice.call(it, 0));
|
|
2576
|
+
var _mkUriSafe = /* @__PURE__ */ __name((src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 == "+" ? "-" : "_"), "_mkUriSafe");
|
|
2577
|
+
var _tidyB64 = /* @__PURE__ */ __name((s) => s.replace(/[^A-Za-z0-9\+\/]/g, ""), "_tidyB64");
|
|
2578
|
+
var btoaPolyfill = /* @__PURE__ */ __name((bin) => {
|
|
2579
|
+
let u32, c0, c1, c2, asc = "";
|
|
2580
|
+
const pad = bin.length % 3;
|
|
2581
|
+
for (let i = 0; i < bin.length; ) {
|
|
2582
|
+
if ((c0 = bin.charCodeAt(i++)) > 255 || (c1 = bin.charCodeAt(i++)) > 255 || (c2 = bin.charCodeAt(i++)) > 255)
|
|
2583
|
+
throw new TypeError("invalid character found");
|
|
2584
|
+
u32 = c0 << 16 | c1 << 8 | c2;
|
|
2585
|
+
asc += b64chs[u32 >> 18 & 63] + b64chs[u32 >> 12 & 63] + b64chs[u32 >> 6 & 63] + b64chs[u32 & 63];
|
|
2586
|
+
}
|
|
2587
|
+
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
|
2588
|
+
}, "btoaPolyfill");
|
|
2589
|
+
var _btoa = typeof btoa === "function" ? (bin) => btoa(bin) : _hasBuffer ? (bin) => Buffer.from(bin, "binary").toString("base64") : btoaPolyfill;
|
|
2590
|
+
var _fromUint8Array = _hasBuffer ? (u8a) => Buffer.from(u8a).toString("base64") : (u8a) => {
|
|
2591
|
+
const maxargs = 4096;
|
|
2592
|
+
let strs = [];
|
|
2593
|
+
for (let i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
2594
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
2595
|
+
}
|
|
2596
|
+
return _btoa(strs.join(""));
|
|
2597
|
+
};
|
|
2598
|
+
var cb_utob = /* @__PURE__ */ __name((c) => {
|
|
2599
|
+
if (c.length < 2) {
|
|
2600
|
+
var cc = c.charCodeAt(0);
|
|
2601
|
+
return cc < 128 ? c : cc < 2048 ? _fromCC(192 | cc >>> 6) + _fromCC(128 | cc & 63) : _fromCC(224 | cc >>> 12 & 15) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
|
|
2602
|
+
} else {
|
|
2603
|
+
var cc = 65536 + (c.charCodeAt(0) - 55296) * 1024 + (c.charCodeAt(1) - 56320);
|
|
2604
|
+
return _fromCC(240 | cc >>> 18 & 7) + _fromCC(128 | cc >>> 12 & 63) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
|
|
2605
|
+
}
|
|
2606
|
+
}, "cb_utob");
|
|
2607
|
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
2608
|
+
var utob = /* @__PURE__ */ __name((u) => u.replace(re_utob, cb_utob), "utob");
|
|
2609
|
+
var _encode = _hasBuffer ? (s) => Buffer.from(s, "utf8").toString("base64") : _TE ? (s) => _fromUint8Array(_TE.encode(s)) : (s) => _btoa(utob(s));
|
|
2610
|
+
var encode = /* @__PURE__ */ __name((src, urlsafe = false) => urlsafe ? _mkUriSafe(_encode(src)) : _encode(src), "encode");
|
|
2611
|
+
var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
|
2612
|
+
var cb_btou = /* @__PURE__ */ __name((cccc) => {
|
|
2613
|
+
switch (cccc.length) {
|
|
2614
|
+
case 4:
|
|
2615
|
+
var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
|
|
2616
|
+
return _fromCC((offset >>> 10) + 55296) + _fromCC((offset & 1023) + 56320);
|
|
2617
|
+
case 3:
|
|
2618
|
+
return _fromCC((15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2));
|
|
2619
|
+
default:
|
|
2620
|
+
return _fromCC((31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1));
|
|
2621
|
+
}
|
|
2622
|
+
}, "cb_btou");
|
|
2623
|
+
var btou = /* @__PURE__ */ __name((b) => b.replace(re_btou, cb_btou), "btou");
|
|
2624
|
+
var atobPolyfill = /* @__PURE__ */ __name((asc) => {
|
|
2625
|
+
asc = asc.replace(/\s+/g, "");
|
|
2626
|
+
if (!b64re.test(asc))
|
|
2627
|
+
throw new TypeError("malformed base64.");
|
|
2628
|
+
asc += "==".slice(2 - (asc.length & 3));
|
|
2629
|
+
let u24, bin = "", r1, r2;
|
|
2630
|
+
for (let i = 0; i < asc.length; ) {
|
|
2631
|
+
u24 = b64tab[asc.charAt(i++)] << 18 | b64tab[asc.charAt(i++)] << 12 | (r1 = b64tab[asc.charAt(i++)]) << 6 | (r2 = b64tab[asc.charAt(i++)]);
|
|
2632
|
+
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255) : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255) : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
|
|
2633
|
+
}
|
|
2634
|
+
return bin;
|
|
2635
|
+
}, "atobPolyfill");
|
|
2636
|
+
var _atob = typeof atob === "function" ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
|
|
2637
|
+
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a).split("").map((c) => c.charCodeAt(0)));
|
|
2638
|
+
var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
|
|
2639
|
+
var _unURI = /* @__PURE__ */ __name((a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/")), "_unURI");
|
|
2640
|
+
var decode = /* @__PURE__ */ __name((src) => _decode(_unURI(src)), "decode");
|
|
2641
|
+
|
|
2642
|
+
// src/misc.ts
|
|
2643
|
+
var LsPrefix = "__fastnear_";
|
|
2644
|
+
function toBase64(data) {
|
|
2645
|
+
if (typeof data === "string") {
|
|
2646
|
+
return encode(data);
|
|
2647
|
+
} else {
|
|
2648
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
2649
|
+
const str = String.fromCharCode(...bytes);
|
|
2650
|
+
return encode(str);
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
__name(toBase64, "toBase64");
|
|
2654
|
+
function fromBase64(str) {
|
|
2655
|
+
const binaryString = decode(str);
|
|
2656
|
+
const len = binaryString.length;
|
|
2657
|
+
const bytes = new Uint8Array(len);
|
|
2658
|
+
for (let i = 0; i < len; i++) {
|
|
2659
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
2660
|
+
}
|
|
2661
|
+
return bytes;
|
|
2662
|
+
}
|
|
2663
|
+
__name(fromBase64, "fromBase64");
|
|
2664
|
+
function convertUnit(s, ...args) {
|
|
2665
|
+
if (Array.isArray(s)) {
|
|
2666
|
+
s = s.reduce((acc, part, i) => {
|
|
2667
|
+
return acc + (args[i - 1] ?? "") + part;
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
if (typeof s == "string") {
|
|
2671
|
+
const match = s.match(/([0-9.,_]+)\s*([a-zA-Z]+)?/);
|
|
2672
|
+
if (match) {
|
|
2673
|
+
const amount = match[1].replace(/[_,]/g, "");
|
|
2674
|
+
const unitPart = match[2];
|
|
2675
|
+
if (unitPart) {
|
|
2676
|
+
switch (unitPart.toLowerCase()) {
|
|
2677
|
+
case "near":
|
|
2678
|
+
return big_default(amount).mul(big_default(10).pow(24)).toFixed(0);
|
|
2679
|
+
case "tgas":
|
|
2680
|
+
return big_default(amount).mul(big_default(10).pow(12)).toFixed(0);
|
|
2681
|
+
case "ggas":
|
|
2682
|
+
return big_default(amount).mul(big_default(10).pow(9)).toFixed(0);
|
|
2683
|
+
case "gas":
|
|
2684
|
+
case "yoctonear":
|
|
2685
|
+
return big_default(amount).toFixed(0);
|
|
2686
|
+
default:
|
|
2687
|
+
throw new Error(`Unknown unit: ${unitPart}`);
|
|
2688
|
+
}
|
|
2689
|
+
} else {
|
|
2690
|
+
return big_default(amount).toFixed(0);
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
return big_default(s).toFixed(0);
|
|
2695
|
+
}
|
|
2696
|
+
__name(convertUnit, "convertUnit");
|
|
2697
|
+
function lsSet(key, value) {
|
|
2698
|
+
if (value === null || value === void 0) {
|
|
2699
|
+
localStorage.removeItem(LsPrefix + key);
|
|
2700
|
+
} else {
|
|
2701
|
+
localStorage.setItem(LsPrefix + key, JSON.stringify(value));
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
__name(lsSet, "lsSet");
|
|
2705
|
+
function lsGet(key) {
|
|
2706
|
+
const value = localStorage.getItem(LsPrefix + key);
|
|
2707
|
+
return tryParseJson(value, null);
|
|
2708
|
+
}
|
|
2709
|
+
__name(lsGet, "lsGet");
|
|
2710
|
+
function deepCopy(obj) {
|
|
2711
|
+
return JSON.parse(JSON.stringify(obj));
|
|
2712
|
+
}
|
|
2713
|
+
__name(deepCopy, "deepCopy");
|
|
2714
|
+
function tryParseJson(...args) {
|
|
2715
|
+
try {
|
|
2716
|
+
return JSON.parse(args[0]);
|
|
2717
|
+
} catch {
|
|
2718
|
+
if (args.length > 1) {
|
|
2719
|
+
return args[1];
|
|
2720
|
+
}
|
|
2721
|
+
return args[0];
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
__name(tryParseJson, "tryParseJson");
|
|
2725
|
+
function parseJsonFromBytes(bytes) {
|
|
2726
|
+
try {
|
|
2727
|
+
const decoder = new TextDecoder();
|
|
2728
|
+
return JSON.parse(
|
|
2729
|
+
decoder.decode(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes))
|
|
2730
|
+
);
|
|
2731
|
+
} catch (e) {
|
|
2732
|
+
try {
|
|
2733
|
+
return bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
2734
|
+
} catch (e2) {
|
|
2735
|
+
return bytes;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
__name(parseJsonFromBytes, "parseJsonFromBytes");
|
|
2740
|
+
function canSignWithLAK(actions) {
|
|
2741
|
+
return actions.length === 1 && actions[0].type === "FunctionCall" && big_default(actions[0]?.deposit ?? "0").eq(0);
|
|
2742
|
+
}
|
|
2743
|
+
__name(canSignWithLAK, "canSignWithLAK");
|
|
2744
|
+
|
|
2745
|
+
// src/crypto.ts
|
|
2746
|
+
var keyFromString = /* @__PURE__ */ __name((key) => base58_to_binary_default(
|
|
2747
|
+
key.includes(":") ? (() => {
|
|
2748
|
+
const [curve, keyPart] = key.split(":");
|
|
2749
|
+
if (curve !== "ed25519") {
|
|
2750
|
+
throw new Error(`Unsupported curve: ${curve}`);
|
|
2751
|
+
}
|
|
2752
|
+
return keyPart;
|
|
2753
|
+
})() : key
|
|
2754
|
+
), "keyFromString");
|
|
2755
|
+
var keyToString = /* @__PURE__ */ __name((key) => `ed25519:${binary_to_base58_default(key)}`, "keyToString");
|
|
2756
|
+
function publicKeyFromPrivate(privateKey) {
|
|
2757
|
+
privateKey = keyFromString(privateKey).slice(0, 32);
|
|
2758
|
+
const publicKey = ed25519.getPublicKey(privateKey);
|
|
2759
|
+
return keyToString(publicKey);
|
|
2760
|
+
}
|
|
2761
|
+
__name(publicKeyFromPrivate, "publicKeyFromPrivate");
|
|
2762
|
+
function privateKeyFromRandom() {
|
|
2763
|
+
const privateKey = crypto.getRandomValues(new Uint8Array(64));
|
|
2764
|
+
return keyToString(privateKey);
|
|
2765
|
+
}
|
|
2766
|
+
__name(privateKeyFromRandom, "privateKeyFromRandom");
|
|
2767
|
+
function signHash(hash, privateKey) {
|
|
2768
|
+
privateKey = keyFromString(privateKey).slice(0, 32);
|
|
2769
|
+
const signature = ed25519.sign(base58_to_binary_default(hash), privateKey);
|
|
2770
|
+
return binary_to_base58_default(signature);
|
|
2771
|
+
}
|
|
2772
|
+
__name(signHash, "signHash");
|
|
2773
|
+
function signBytes(bytes, privateKey) {
|
|
2774
|
+
const hash = sha256(bytes);
|
|
2775
|
+
return signHash(binary_to_base58_default(hash), privateKey);
|
|
2776
|
+
}
|
|
2777
|
+
__name(signBytes, "signBytes");
|
|
2778
|
+
|
|
2779
|
+
// ../../node_modules/borsh/lib/esm/types.js
|
|
2780
|
+
var integers = ["u8", "u16", "u32", "u64", "u128", "i8", "i16", "i32", "i64", "i128", "f32", "f64"];
|
|
2781
|
+
|
|
2782
|
+
// ../../node_modules/borsh/lib/esm/buffer.js
|
|
2783
|
+
var EncodeBuffer = (
|
|
2784
|
+
/** @class */
|
|
2785
|
+
function() {
|
|
2786
|
+
function EncodeBuffer2() {
|
|
2787
|
+
this.offset = 0;
|
|
2788
|
+
this.buffer_size = 256;
|
|
2789
|
+
this.buffer = new ArrayBuffer(this.buffer_size);
|
|
2790
|
+
this.view = new DataView(this.buffer);
|
|
2791
|
+
}
|
|
2792
|
+
__name(EncodeBuffer2, "EncodeBuffer");
|
|
2793
|
+
EncodeBuffer2.prototype.resize_if_necessary = function(needed_space) {
|
|
2794
|
+
if (this.buffer_size - this.offset < needed_space) {
|
|
2795
|
+
this.buffer_size = Math.max(this.buffer_size * 2, this.buffer_size + needed_space);
|
|
2796
|
+
var new_buffer = new ArrayBuffer(this.buffer_size);
|
|
2797
|
+
new Uint8Array(new_buffer).set(new Uint8Array(this.buffer));
|
|
2798
|
+
this.buffer = new_buffer;
|
|
2799
|
+
this.view = new DataView(new_buffer);
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
EncodeBuffer2.prototype.get_used_buffer = function() {
|
|
2803
|
+
return new Uint8Array(this.buffer).slice(0, this.offset);
|
|
2804
|
+
};
|
|
2805
|
+
EncodeBuffer2.prototype.store_value = function(value, type) {
|
|
2806
|
+
var bSize = type.substring(1);
|
|
2807
|
+
var size = parseInt(bSize) / 8;
|
|
2808
|
+
this.resize_if_necessary(size);
|
|
2809
|
+
var toCall = type[0] === "f" ? "setFloat".concat(bSize) : type[0] === "i" ? "setInt".concat(bSize) : "setUint".concat(bSize);
|
|
2810
|
+
this.view[toCall](this.offset, value, true);
|
|
2811
|
+
this.offset += size;
|
|
2812
|
+
};
|
|
2813
|
+
EncodeBuffer2.prototype.store_bytes = function(from) {
|
|
2814
|
+
this.resize_if_necessary(from.length);
|
|
2815
|
+
new Uint8Array(this.buffer).set(new Uint8Array(from), this.offset);
|
|
2816
|
+
this.offset += from.length;
|
|
2817
|
+
};
|
|
2818
|
+
return EncodeBuffer2;
|
|
2819
|
+
}()
|
|
2820
|
+
);
|
|
2821
|
+
var DecodeBuffer = (
|
|
2822
|
+
/** @class */
|
|
2823
|
+
function() {
|
|
2824
|
+
function DecodeBuffer2(buf) {
|
|
2825
|
+
this.offset = 0;
|
|
2826
|
+
this.buffer_size = buf.length;
|
|
2827
|
+
this.buffer = new ArrayBuffer(buf.length);
|
|
2828
|
+
new Uint8Array(this.buffer).set(buf);
|
|
2829
|
+
this.view = new DataView(this.buffer);
|
|
2830
|
+
}
|
|
2831
|
+
__name(DecodeBuffer2, "DecodeBuffer");
|
|
2832
|
+
DecodeBuffer2.prototype.assert_enough_buffer = function(size) {
|
|
2833
|
+
if (this.offset + size > this.buffer.byteLength) {
|
|
2834
|
+
throw new Error("Error in schema, the buffer is smaller than expected");
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
DecodeBuffer2.prototype.consume_value = function(type) {
|
|
2838
|
+
var bSize = type.substring(1);
|
|
2839
|
+
var size = parseInt(bSize) / 8;
|
|
2840
|
+
this.assert_enough_buffer(size);
|
|
2841
|
+
var toCall = type[0] === "f" ? "getFloat".concat(bSize) : type[0] === "i" ? "getInt".concat(bSize) : "getUint".concat(bSize);
|
|
2842
|
+
var ret = this.view[toCall](this.offset, true);
|
|
2843
|
+
this.offset += size;
|
|
2844
|
+
return ret;
|
|
2845
|
+
};
|
|
2846
|
+
DecodeBuffer2.prototype.consume_bytes = function(size) {
|
|
2847
|
+
this.assert_enough_buffer(size);
|
|
2848
|
+
var ret = this.buffer.slice(this.offset, this.offset + size);
|
|
2849
|
+
this.offset += size;
|
|
2850
|
+
return ret;
|
|
2851
|
+
};
|
|
2852
|
+
return DecodeBuffer2;
|
|
2853
|
+
}()
|
|
2854
|
+
);
|
|
2855
|
+
|
|
2856
|
+
// ../../node_modules/borsh/lib/esm/utils.js
|
|
2857
|
+
var __extends = /* @__PURE__ */ function() {
|
|
2858
|
+
var extendStatics = /* @__PURE__ */ __name(function(d, b) {
|
|
2859
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
2860
|
+
d2.__proto__ = b2;
|
|
2861
|
+
} || function(d2, b2) {
|
|
2862
|
+
for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
|
|
2863
|
+
};
|
|
2864
|
+
return extendStatics(d, b);
|
|
2865
|
+
}, "extendStatics");
|
|
2866
|
+
return function(d, b) {
|
|
2867
|
+
if (typeof b !== "function" && b !== null)
|
|
2868
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
2869
|
+
extendStatics(d, b);
|
|
2870
|
+
function __() {
|
|
2871
|
+
this.constructor = d;
|
|
2872
|
+
}
|
|
2873
|
+
__name(__, "__");
|
|
2874
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2875
|
+
};
|
|
2876
|
+
}();
|
|
2877
|
+
function isArrayLike(value) {
|
|
2878
|
+
return Array.isArray(value) || !!value && typeof value === "object" && "length" in value && typeof value.length === "number" && (value.length === 0 || value.length > 0 && value.length - 1 in value);
|
|
2879
|
+
}
|
|
2880
|
+
__name(isArrayLike, "isArrayLike");
|
|
2881
|
+
function expect_type(value, type, fieldPath) {
|
|
2882
|
+
if (typeof value !== type) {
|
|
2883
|
+
throw new Error("Expected ".concat(type, " not ").concat(typeof value, "(").concat(value, ") at ").concat(fieldPath.join(".")));
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
__name(expect_type, "expect_type");
|
|
2887
|
+
function expect_bigint(value, fieldPath) {
|
|
2888
|
+
var basicType = ["number", "string", "bigint", "boolean"].includes(typeof value);
|
|
2889
|
+
var strObject = typeof value === "object" && value !== null && "toString" in value;
|
|
2890
|
+
if (!basicType && !strObject) {
|
|
2891
|
+
throw new Error("Expected bigint, number, boolean or string not ".concat(typeof value, "(").concat(value, ") at ").concat(fieldPath.join(".")));
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
__name(expect_bigint, "expect_bigint");
|
|
2895
|
+
function expect_same_size(length, expected, fieldPath) {
|
|
2896
|
+
if (length !== expected) {
|
|
2897
|
+
throw new Error("Array length ".concat(length, " does not match schema length ").concat(expected, " at ").concat(fieldPath.join(".")));
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
__name(expect_same_size, "expect_same_size");
|
|
2901
|
+
function expect_enum(value, fieldPath) {
|
|
2902
|
+
if (typeof value !== "object" || value === null) {
|
|
2903
|
+
throw new Error("Expected object not ".concat(typeof value, "(").concat(value, ") at ").concat(fieldPath.join(".")));
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
__name(expect_enum, "expect_enum");
|
|
2907
|
+
var VALID_STRING_TYPES = integers.concat(["bool", "string"]);
|
|
2908
|
+
var VALID_OBJECT_KEYS = ["option", "enum", "array", "set", "map", "struct"];
|
|
2909
|
+
var ErrorSchema = (
|
|
2910
|
+
/** @class */
|
|
2911
|
+
function(_super) {
|
|
2912
|
+
__extends(ErrorSchema2, _super);
|
|
2913
|
+
function ErrorSchema2(schema, expected) {
|
|
2914
|
+
var message = "Invalid schema: ".concat(JSON.stringify(schema), " expected ").concat(expected);
|
|
2915
|
+
return _super.call(this, message) || this;
|
|
2916
|
+
}
|
|
2917
|
+
__name(ErrorSchema2, "ErrorSchema");
|
|
2918
|
+
return ErrorSchema2;
|
|
2919
|
+
}(Error)
|
|
2920
|
+
);
|
|
2921
|
+
function validate_schema(schema) {
|
|
2922
|
+
if (typeof schema === "string" && VALID_STRING_TYPES.includes(schema)) {
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
if (schema && typeof schema === "object") {
|
|
2926
|
+
var keys = Object.keys(schema);
|
|
2927
|
+
if (keys.length === 1 && VALID_OBJECT_KEYS.includes(keys[0])) {
|
|
2928
|
+
var key = keys[0];
|
|
2929
|
+
if (key === "option")
|
|
2930
|
+
return validate_schema(schema[key]);
|
|
2931
|
+
if (key === "enum")
|
|
2932
|
+
return validate_enum_schema(schema[key]);
|
|
2933
|
+
if (key === "array")
|
|
2934
|
+
return validate_array_schema(schema[key]);
|
|
2935
|
+
if (key === "set")
|
|
2936
|
+
return validate_schema(schema[key]);
|
|
2937
|
+
if (key === "map")
|
|
2938
|
+
return validate_map_schema(schema[key]);
|
|
2939
|
+
if (key === "struct")
|
|
2940
|
+
return validate_struct_schema(schema[key]);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
throw new ErrorSchema(schema, VALID_OBJECT_KEYS.join(", ") + " or " + VALID_STRING_TYPES.join(", "));
|
|
2944
|
+
}
|
|
2945
|
+
__name(validate_schema, "validate_schema");
|
|
2946
|
+
function validate_enum_schema(schema) {
|
|
2947
|
+
if (!Array.isArray(schema))
|
|
2948
|
+
throw new ErrorSchema(schema, "Array");
|
|
2949
|
+
for (var _i = 0, schema_1 = schema; _i < schema_1.length; _i++) {
|
|
2950
|
+
var sch = schema_1[_i];
|
|
2951
|
+
if (typeof sch !== "object" || !("struct" in sch)) {
|
|
2952
|
+
throw new Error('Missing "struct" key in enum schema');
|
|
2953
|
+
}
|
|
2954
|
+
if (typeof sch.struct !== "object" || Object.keys(sch.struct).length !== 1) {
|
|
2955
|
+
throw new Error('The "struct" in each enum must have a single key');
|
|
2956
|
+
}
|
|
2957
|
+
validate_schema({ struct: sch.struct });
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
__name(validate_enum_schema, "validate_enum_schema");
|
|
2961
|
+
function validate_array_schema(schema) {
|
|
2962
|
+
if (typeof schema !== "object")
|
|
2963
|
+
throw new ErrorSchema(schema, "{ type, len? }");
|
|
2964
|
+
if (schema.len && typeof schema.len !== "number") {
|
|
2965
|
+
throw new Error("Invalid schema: ".concat(schema));
|
|
2966
|
+
}
|
|
2967
|
+
if ("type" in schema)
|
|
2968
|
+
return validate_schema(schema.type);
|
|
2969
|
+
throw new ErrorSchema(schema, "{ type, len? }");
|
|
2970
|
+
}
|
|
2971
|
+
__name(validate_array_schema, "validate_array_schema");
|
|
2972
|
+
function validate_map_schema(schema) {
|
|
2973
|
+
if (typeof schema === "object" && "key" in schema && "value" in schema) {
|
|
2974
|
+
validate_schema(schema.key);
|
|
2975
|
+
validate_schema(schema.value);
|
|
2976
|
+
} else {
|
|
2977
|
+
throw new ErrorSchema(schema, "{ key, value }");
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
__name(validate_map_schema, "validate_map_schema");
|
|
2981
|
+
function validate_struct_schema(schema) {
|
|
2982
|
+
if (typeof schema !== "object")
|
|
2983
|
+
throw new ErrorSchema(schema, "object");
|
|
2984
|
+
for (var key in schema) {
|
|
2985
|
+
validate_schema(schema[key]);
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
__name(validate_struct_schema, "validate_struct_schema");
|
|
2989
|
+
|
|
2990
|
+
// ../../node_modules/borsh/lib/esm/serialize.js
|
|
2991
|
+
var BorshSerializer = (
|
|
2992
|
+
/** @class */
|
|
2993
|
+
function() {
|
|
2994
|
+
function BorshSerializer2(checkTypes) {
|
|
2995
|
+
this.encoded = new EncodeBuffer();
|
|
2996
|
+
this.fieldPath = ["value"];
|
|
2997
|
+
this.checkTypes = checkTypes;
|
|
2998
|
+
}
|
|
2999
|
+
__name(BorshSerializer2, "BorshSerializer");
|
|
3000
|
+
BorshSerializer2.prototype.encode = function(value, schema) {
|
|
3001
|
+
this.encode_value(value, schema);
|
|
3002
|
+
return this.encoded.get_used_buffer();
|
|
3003
|
+
};
|
|
3004
|
+
BorshSerializer2.prototype.encode_value = function(value, schema) {
|
|
3005
|
+
if (typeof schema === "string") {
|
|
3006
|
+
if (integers.includes(schema))
|
|
3007
|
+
return this.encode_integer(value, schema);
|
|
3008
|
+
if (schema === "string")
|
|
3009
|
+
return this.encode_string(value);
|
|
3010
|
+
if (schema === "bool")
|
|
3011
|
+
return this.encode_boolean(value);
|
|
3012
|
+
}
|
|
3013
|
+
if (typeof schema === "object") {
|
|
3014
|
+
if ("option" in schema)
|
|
3015
|
+
return this.encode_option(value, schema);
|
|
3016
|
+
if ("enum" in schema)
|
|
3017
|
+
return this.encode_enum(value, schema);
|
|
3018
|
+
if ("array" in schema)
|
|
3019
|
+
return this.encode_array(value, schema);
|
|
3020
|
+
if ("set" in schema)
|
|
3021
|
+
return this.encode_set(value, schema);
|
|
3022
|
+
if ("map" in schema)
|
|
3023
|
+
return this.encode_map(value, schema);
|
|
3024
|
+
if ("struct" in schema)
|
|
3025
|
+
return this.encode_struct(value, schema);
|
|
3026
|
+
}
|
|
3027
|
+
};
|
|
3028
|
+
BorshSerializer2.prototype.encode_integer = function(value, schema) {
|
|
3029
|
+
var size = parseInt(schema.substring(1));
|
|
3030
|
+
if (size <= 32 || schema == "f64") {
|
|
3031
|
+
this.checkTypes && expect_type(value, "number", this.fieldPath);
|
|
3032
|
+
this.encoded.store_value(value, schema);
|
|
3033
|
+
} else {
|
|
3034
|
+
this.checkTypes && expect_bigint(value, this.fieldPath);
|
|
3035
|
+
this.encode_bigint(BigInt(value), size);
|
|
3036
|
+
}
|
|
3037
|
+
};
|
|
3038
|
+
BorshSerializer2.prototype.encode_bigint = function(value, size) {
|
|
3039
|
+
var buffer_len = size / 8;
|
|
3040
|
+
var buffer = new Uint8Array(buffer_len);
|
|
3041
|
+
for (var i = 0; i < buffer_len; i++) {
|
|
3042
|
+
buffer[i] = Number(value & BigInt(255));
|
|
3043
|
+
value = value >> BigInt(8);
|
|
3044
|
+
}
|
|
3045
|
+
this.encoded.store_bytes(new Uint8Array(buffer));
|
|
3046
|
+
};
|
|
3047
|
+
BorshSerializer2.prototype.encode_string = function(value) {
|
|
3048
|
+
this.checkTypes && expect_type(value, "string", this.fieldPath);
|
|
3049
|
+
var _value = value;
|
|
3050
|
+
var utf8Bytes = [];
|
|
3051
|
+
for (var i = 0; i < _value.length; i++) {
|
|
3052
|
+
var charCode = _value.charCodeAt(i);
|
|
3053
|
+
if (charCode < 128) {
|
|
3054
|
+
utf8Bytes.push(charCode);
|
|
3055
|
+
} else if (charCode < 2048) {
|
|
3056
|
+
utf8Bytes.push(192 | charCode >> 6, 128 | charCode & 63);
|
|
3057
|
+
} else if (charCode < 55296 || charCode >= 57344) {
|
|
3058
|
+
utf8Bytes.push(224 | charCode >> 12, 128 | charCode >> 6 & 63, 128 | charCode & 63);
|
|
3059
|
+
} else {
|
|
3060
|
+
i++;
|
|
3061
|
+
charCode = 65536 + ((charCode & 1023) << 10 | _value.charCodeAt(i) & 1023);
|
|
3062
|
+
utf8Bytes.push(240 | charCode >> 18, 128 | charCode >> 12 & 63, 128 | charCode >> 6 & 63, 128 | charCode & 63);
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
this.encoded.store_value(utf8Bytes.length, "u32");
|
|
3066
|
+
this.encoded.store_bytes(new Uint8Array(utf8Bytes));
|
|
3067
|
+
};
|
|
3068
|
+
BorshSerializer2.prototype.encode_boolean = function(value) {
|
|
3069
|
+
this.checkTypes && expect_type(value, "boolean", this.fieldPath);
|
|
3070
|
+
this.encoded.store_value(value ? 1 : 0, "u8");
|
|
3071
|
+
};
|
|
3072
|
+
BorshSerializer2.prototype.encode_option = function(value, schema) {
|
|
3073
|
+
if (value === null || value === void 0) {
|
|
3074
|
+
this.encoded.store_value(0, "u8");
|
|
3075
|
+
} else {
|
|
3076
|
+
this.encoded.store_value(1, "u8");
|
|
3077
|
+
this.encode_value(value, schema.option);
|
|
3078
|
+
}
|
|
3079
|
+
};
|
|
3080
|
+
BorshSerializer2.prototype.encode_enum = function(value, schema) {
|
|
3081
|
+
this.checkTypes && expect_enum(value, this.fieldPath);
|
|
3082
|
+
var valueKey = Object.keys(value)[0];
|
|
3083
|
+
for (var i = 0; i < schema["enum"].length; i++) {
|
|
3084
|
+
var valueSchema = schema["enum"][i];
|
|
3085
|
+
if (valueKey === Object.keys(valueSchema.struct)[0]) {
|
|
3086
|
+
this.encoded.store_value(i, "u8");
|
|
3087
|
+
return this.encode_struct(value, valueSchema);
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
throw new Error("Enum key (".concat(valueKey, ") not found in enum schema: ").concat(JSON.stringify(schema), " at ").concat(this.fieldPath.join(".")));
|
|
3091
|
+
};
|
|
3092
|
+
BorshSerializer2.prototype.encode_array = function(value, schema) {
|
|
3093
|
+
if (isArrayLike(value))
|
|
3094
|
+
return this.encode_arraylike(value, schema);
|
|
3095
|
+
if (value instanceof ArrayBuffer)
|
|
3096
|
+
return this.encode_buffer(value, schema);
|
|
3097
|
+
throw new Error("Expected Array-like not ".concat(typeof value, "(").concat(value, ") at ").concat(this.fieldPath.join(".")));
|
|
3098
|
+
};
|
|
3099
|
+
BorshSerializer2.prototype.encode_arraylike = function(value, schema) {
|
|
3100
|
+
if (schema.array.len) {
|
|
3101
|
+
expect_same_size(value.length, schema.array.len, this.fieldPath);
|
|
3102
|
+
} else {
|
|
3103
|
+
this.encoded.store_value(value.length, "u32");
|
|
3104
|
+
}
|
|
3105
|
+
for (var i = 0; i < value.length; i++) {
|
|
3106
|
+
this.encode_value(value[i], schema.array.type);
|
|
3107
|
+
}
|
|
3108
|
+
};
|
|
3109
|
+
BorshSerializer2.prototype.encode_buffer = function(value, schema) {
|
|
3110
|
+
if (schema.array.len) {
|
|
3111
|
+
expect_same_size(value.byteLength, schema.array.len, this.fieldPath);
|
|
3112
|
+
} else {
|
|
3113
|
+
this.encoded.store_value(value.byteLength, "u32");
|
|
3114
|
+
}
|
|
3115
|
+
this.encoded.store_bytes(new Uint8Array(value));
|
|
3116
|
+
};
|
|
3117
|
+
BorshSerializer2.prototype.encode_set = function(value, schema) {
|
|
3118
|
+
this.checkTypes && expect_type(value, "object", this.fieldPath);
|
|
3119
|
+
var isSet = value instanceof Set;
|
|
3120
|
+
var values = isSet ? Array.from(value.values()) : Object.values(value);
|
|
3121
|
+
this.encoded.store_value(values.length, "u32");
|
|
3122
|
+
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
3123
|
+
var value_1 = values_1[_i];
|
|
3124
|
+
this.encode_value(value_1, schema.set);
|
|
3125
|
+
}
|
|
3126
|
+
};
|
|
3127
|
+
BorshSerializer2.prototype.encode_map = function(value, schema) {
|
|
3128
|
+
this.checkTypes && expect_type(value, "object", this.fieldPath);
|
|
3129
|
+
var isMap = value instanceof Map;
|
|
3130
|
+
var keys = isMap ? Array.from(value.keys()) : Object.keys(value);
|
|
3131
|
+
this.encoded.store_value(keys.length, "u32");
|
|
3132
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
3133
|
+
var key = keys_1[_i];
|
|
3134
|
+
this.encode_value(key, schema.map.key);
|
|
3135
|
+
this.encode_value(isMap ? value.get(key) : value[key], schema.map.value);
|
|
3136
|
+
}
|
|
3137
|
+
};
|
|
3138
|
+
BorshSerializer2.prototype.encode_struct = function(value, schema) {
|
|
3139
|
+
this.checkTypes && expect_type(value, "object", this.fieldPath);
|
|
3140
|
+
for (var _i = 0, _a = Object.keys(schema.struct); _i < _a.length; _i++) {
|
|
3141
|
+
var key = _a[_i];
|
|
3142
|
+
this.fieldPath.push(key);
|
|
3143
|
+
this.encode_value(value[key], schema.struct[key]);
|
|
3144
|
+
this.fieldPath.pop();
|
|
3145
|
+
}
|
|
3146
|
+
};
|
|
3147
|
+
return BorshSerializer2;
|
|
3148
|
+
}()
|
|
3149
|
+
);
|
|
3150
|
+
|
|
3151
|
+
// ../../node_modules/borsh/lib/esm/deserialize.js
|
|
3152
|
+
var BorshDeserializer = (
|
|
3153
|
+
/** @class */
|
|
3154
|
+
function() {
|
|
3155
|
+
function BorshDeserializer2(bufferArray) {
|
|
3156
|
+
this.buffer = new DecodeBuffer(bufferArray);
|
|
3157
|
+
}
|
|
3158
|
+
__name(BorshDeserializer2, "BorshDeserializer");
|
|
3159
|
+
BorshDeserializer2.prototype.decode = function(schema) {
|
|
3160
|
+
return this.decode_value(schema);
|
|
3161
|
+
};
|
|
3162
|
+
BorshDeserializer2.prototype.decode_value = function(schema) {
|
|
3163
|
+
if (typeof schema === "string") {
|
|
3164
|
+
if (integers.includes(schema))
|
|
3165
|
+
return this.decode_integer(schema);
|
|
3166
|
+
if (schema === "string")
|
|
3167
|
+
return this.decode_string();
|
|
3168
|
+
if (schema === "bool")
|
|
3169
|
+
return this.decode_boolean();
|
|
3170
|
+
}
|
|
3171
|
+
if (typeof schema === "object") {
|
|
3172
|
+
if ("option" in schema)
|
|
3173
|
+
return this.decode_option(schema);
|
|
3174
|
+
if ("enum" in schema)
|
|
3175
|
+
return this.decode_enum(schema);
|
|
3176
|
+
if ("array" in schema)
|
|
3177
|
+
return this.decode_array(schema);
|
|
3178
|
+
if ("set" in schema)
|
|
3179
|
+
return this.decode_set(schema);
|
|
3180
|
+
if ("map" in schema)
|
|
3181
|
+
return this.decode_map(schema);
|
|
3182
|
+
if ("struct" in schema)
|
|
3183
|
+
return this.decode_struct(schema);
|
|
3184
|
+
}
|
|
3185
|
+
throw new Error("Unsupported type: ".concat(schema));
|
|
3186
|
+
};
|
|
3187
|
+
BorshDeserializer2.prototype.decode_integer = function(schema) {
|
|
3188
|
+
var size = parseInt(schema.substring(1));
|
|
3189
|
+
if (size <= 32 || schema == "f64") {
|
|
3190
|
+
return this.buffer.consume_value(schema);
|
|
3191
|
+
}
|
|
3192
|
+
return this.decode_bigint(size, schema.startsWith("i"));
|
|
3193
|
+
};
|
|
3194
|
+
BorshDeserializer2.prototype.decode_bigint = function(size, signed) {
|
|
3195
|
+
if (signed === void 0) {
|
|
3196
|
+
signed = false;
|
|
3197
|
+
}
|
|
3198
|
+
var buffer_len = size / 8;
|
|
3199
|
+
var buffer = new Uint8Array(this.buffer.consume_bytes(buffer_len));
|
|
3200
|
+
var bits = buffer.reduceRight(function(r, x) {
|
|
3201
|
+
return r + x.toString(16).padStart(2, "0");
|
|
3202
|
+
}, "");
|
|
3203
|
+
if (signed && buffer[buffer_len - 1]) {
|
|
3204
|
+
return BigInt.asIntN(size, BigInt("0x".concat(bits)));
|
|
3205
|
+
}
|
|
3206
|
+
return BigInt("0x".concat(bits));
|
|
3207
|
+
};
|
|
3208
|
+
BorshDeserializer2.prototype.decode_string = function() {
|
|
3209
|
+
var len = this.decode_integer("u32");
|
|
3210
|
+
var buffer = new Uint8Array(this.buffer.consume_bytes(len));
|
|
3211
|
+
var codePoints = [];
|
|
3212
|
+
for (var i = 0; i < len; ++i) {
|
|
3213
|
+
var byte = buffer[i];
|
|
3214
|
+
if (byte < 128) {
|
|
3215
|
+
codePoints.push(byte);
|
|
3216
|
+
} else if (byte < 224) {
|
|
3217
|
+
codePoints.push((byte & 31) << 6 | buffer[++i] & 63);
|
|
3218
|
+
} else if (byte < 240) {
|
|
3219
|
+
codePoints.push((byte & 15) << 12 | (buffer[++i] & 63) << 6 | buffer[++i] & 63);
|
|
3220
|
+
} else {
|
|
3221
|
+
var codePoint = (byte & 7) << 18 | (buffer[++i] & 63) << 12 | (buffer[++i] & 63) << 6 | buffer[++i] & 63;
|
|
3222
|
+
codePoints.push(codePoint);
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
return String.fromCodePoint.apply(String, codePoints);
|
|
3226
|
+
};
|
|
3227
|
+
BorshDeserializer2.prototype.decode_boolean = function() {
|
|
3228
|
+
return this.buffer.consume_value("u8") > 0;
|
|
3229
|
+
};
|
|
3230
|
+
BorshDeserializer2.prototype.decode_option = function(schema) {
|
|
3231
|
+
var option = this.buffer.consume_value("u8");
|
|
3232
|
+
if (option === 1) {
|
|
3233
|
+
return this.decode_value(schema.option);
|
|
3234
|
+
}
|
|
3235
|
+
if (option !== 0) {
|
|
3236
|
+
throw new Error("Invalid option ".concat(option));
|
|
3237
|
+
}
|
|
3238
|
+
return null;
|
|
3239
|
+
};
|
|
3240
|
+
BorshDeserializer2.prototype.decode_enum = function(schema) {
|
|
3241
|
+
var _a;
|
|
3242
|
+
var valueIndex = this.buffer.consume_value("u8");
|
|
3243
|
+
if (valueIndex > schema["enum"].length) {
|
|
3244
|
+
throw new Error("Enum option ".concat(valueIndex, " is not available"));
|
|
3245
|
+
}
|
|
3246
|
+
var struct = schema["enum"][valueIndex].struct;
|
|
3247
|
+
var key = Object.keys(struct)[0];
|
|
3248
|
+
return _a = {}, _a[key] = this.decode_value(struct[key]), _a;
|
|
3249
|
+
};
|
|
3250
|
+
BorshDeserializer2.prototype.decode_array = function(schema) {
|
|
3251
|
+
var result = [];
|
|
3252
|
+
var len = schema.array.len ? schema.array.len : this.decode_integer("u32");
|
|
3253
|
+
for (var i = 0; i < len; ++i) {
|
|
3254
|
+
result.push(this.decode_value(schema.array.type));
|
|
3255
|
+
}
|
|
3256
|
+
return result;
|
|
3257
|
+
};
|
|
3258
|
+
BorshDeserializer2.prototype.decode_set = function(schema) {
|
|
3259
|
+
var len = this.decode_integer("u32");
|
|
3260
|
+
var result = /* @__PURE__ */ new Set();
|
|
3261
|
+
for (var i = 0; i < len; ++i) {
|
|
3262
|
+
result.add(this.decode_value(schema.set));
|
|
3263
|
+
}
|
|
3264
|
+
return result;
|
|
3265
|
+
};
|
|
3266
|
+
BorshDeserializer2.prototype.decode_map = function(schema) {
|
|
3267
|
+
var len = this.decode_integer("u32");
|
|
3268
|
+
var result = /* @__PURE__ */ new Map();
|
|
3269
|
+
for (var i = 0; i < len; ++i) {
|
|
3270
|
+
var key = this.decode_value(schema.map.key);
|
|
3271
|
+
var value = this.decode_value(schema.map.value);
|
|
3272
|
+
result.set(key, value);
|
|
3273
|
+
}
|
|
3274
|
+
return result;
|
|
3275
|
+
};
|
|
3276
|
+
BorshDeserializer2.prototype.decode_struct = function(schema) {
|
|
3277
|
+
var result = {};
|
|
3278
|
+
for (var key in schema.struct) {
|
|
3279
|
+
result[key] = this.decode_value(schema.struct[key]);
|
|
3280
|
+
}
|
|
3281
|
+
return result;
|
|
3282
|
+
};
|
|
3283
|
+
return BorshDeserializer2;
|
|
3284
|
+
}()
|
|
3285
|
+
);
|
|
3286
|
+
|
|
3287
|
+
// ../../node_modules/borsh/lib/esm/index.js
|
|
3288
|
+
function serialize(schema, value, validate) {
|
|
3289
|
+
if (validate === void 0) {
|
|
3290
|
+
validate = true;
|
|
3291
|
+
}
|
|
3292
|
+
if (validate)
|
|
3293
|
+
validate_schema(schema);
|
|
3294
|
+
var serializer = new BorshSerializer(validate);
|
|
3295
|
+
return serializer.encode(value, schema);
|
|
3296
|
+
}
|
|
3297
|
+
__name(serialize, "serialize");
|
|
3298
|
+
|
|
3299
|
+
// ../borsh-schema/src/index.ts
|
|
3300
|
+
var src_exports = {};
|
|
3301
|
+
__export(src_exports, {
|
|
3302
|
+
getBorshSchema: () => getBorshSchema
|
|
3303
|
+
});
|
|
3304
|
+
var getBorshSchema = (() => {
|
|
3305
|
+
class BorshSchema {
|
|
3306
|
+
static {
|
|
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
|
+
};
|
|
3463
|
+
}
|
|
3464
|
+
return new BorshSchema();
|
|
3465
|
+
})();
|
|
3466
|
+
|
|
3467
|
+
// src/transaction.ts
|
|
3468
|
+
function mapTransaction(jsonTransaction) {
|
|
3469
|
+
return {
|
|
3470
|
+
signerId: jsonTransaction.signerId,
|
|
3471
|
+
publicKey: {
|
|
3472
|
+
ed25519Key: {
|
|
3473
|
+
data: keyFromString(jsonTransaction.publicKey)
|
|
3474
|
+
}
|
|
3475
|
+
},
|
|
3476
|
+
nonce: BigInt(jsonTransaction.nonce),
|
|
3477
|
+
receiverId: jsonTransaction.receiverId,
|
|
3478
|
+
blockHash: base58_to_binary_default(jsonTransaction.blockHash),
|
|
3479
|
+
actions: jsonTransaction.actions.map(mapAction)
|
|
3480
|
+
};
|
|
3481
|
+
}
|
|
3482
|
+
__name(mapTransaction, "mapTransaction");
|
|
3483
|
+
function serializeTransaction(jsonTransaction) {
|
|
3484
|
+
const transaction = mapTransaction(jsonTransaction);
|
|
3485
|
+
return serialize(SCHEMA.Transaction, transaction);
|
|
3486
|
+
}
|
|
3487
|
+
__name(serializeTransaction, "serializeTransaction");
|
|
3488
|
+
function serializeSignedTransaction(jsonTransaction, signature) {
|
|
3489
|
+
const signedTransaction = {
|
|
3490
|
+
transaction: mapTransaction(jsonTransaction),
|
|
3491
|
+
signature: {
|
|
3492
|
+
ed25519Signature: {
|
|
3493
|
+
data: base58_to_binary_default(signature)
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
};
|
|
3497
|
+
return serialize(SCHEMA.SignedTransaction, signedTransaction);
|
|
3498
|
+
}
|
|
3499
|
+
__name(serializeSignedTransaction, "serializeSignedTransaction");
|
|
3500
|
+
function mapAction(action) {
|
|
3501
|
+
switch (action.type) {
|
|
3502
|
+
case "CreateAccount": {
|
|
3503
|
+
return {
|
|
3504
|
+
createAccount: {}
|
|
3505
|
+
};
|
|
3506
|
+
}
|
|
3507
|
+
case "DeployContract": {
|
|
3508
|
+
return {
|
|
3509
|
+
deployContract: {
|
|
3510
|
+
code: fromBase64(action.codeBase64)
|
|
3511
|
+
}
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
case "FunctionCall": {
|
|
3515
|
+
return {
|
|
3516
|
+
functionCall: {
|
|
3517
|
+
methodName: action.methodName,
|
|
3518
|
+
args: action.argsBase64 ? fromBase64(action.argsBase64) : new TextEncoder().encode(JSON.stringify(action.args)),
|
|
3519
|
+
gas: BigInt(action.gas),
|
|
3520
|
+
deposit: BigInt(action.deposit)
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
}
|
|
3524
|
+
case "Transfer": {
|
|
3525
|
+
return {
|
|
3526
|
+
transfer: {
|
|
3527
|
+
deposit: BigInt(action.deposit)
|
|
3528
|
+
}
|
|
3529
|
+
};
|
|
3530
|
+
}
|
|
3531
|
+
case "Stake": {
|
|
3532
|
+
return {
|
|
3533
|
+
stake: {
|
|
3534
|
+
stake: BigInt(action.stake),
|
|
3535
|
+
publicKey: {
|
|
3536
|
+
ed25519Key: {
|
|
3537
|
+
data: keyFromString(action.publicKey)
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
};
|
|
3542
|
+
}
|
|
3543
|
+
case "AddKey": {
|
|
3544
|
+
return {
|
|
3545
|
+
addKey: {
|
|
3546
|
+
publicKey: {
|
|
3547
|
+
ed25519Key: {
|
|
3548
|
+
data: keyFromString(action.publicKey)
|
|
3549
|
+
}
|
|
3550
|
+
},
|
|
3551
|
+
accessKey: {
|
|
3552
|
+
nonce: BigInt(action.accessKey.nonce),
|
|
3553
|
+
permission: action.accessKey.permission === "FullAccess" ? { fullAccess: {} } : {
|
|
3554
|
+
functionCall: {
|
|
3555
|
+
allowance: action.accessKey.allowance ? BigInt(action.accessKey.allowance) : null,
|
|
3556
|
+
receiverId: action.accessKey.receiverId,
|
|
3557
|
+
methodNames: action.accessKey.methodNames
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
};
|
|
3563
|
+
}
|
|
3564
|
+
case "DeleteKey": {
|
|
3565
|
+
return {
|
|
3566
|
+
deleteKey: {
|
|
3567
|
+
publicKey: {
|
|
3568
|
+
ed25519Key: {
|
|
3569
|
+
data: keyFromString(action.publicKey)
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
}
|
|
3575
|
+
case "DeleteAccount": {
|
|
3576
|
+
return {
|
|
3577
|
+
deleteAccount: {
|
|
3578
|
+
beneficiaryId: action.beneficiaryId
|
|
3579
|
+
}
|
|
3580
|
+
};
|
|
3581
|
+
}
|
|
3582
|
+
case "SignedDelegate": {
|
|
3583
|
+
return {
|
|
3584
|
+
signedDelegate: {
|
|
3585
|
+
delegateAction: mapAction(action.delegateAction),
|
|
3586
|
+
signature: {
|
|
3587
|
+
ed25519Signature: base58_to_binary_default(action.signature)
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
};
|
|
3591
|
+
}
|
|
3592
|
+
default: {
|
|
3593
|
+
throw new Error("Not implemented action: " + action.type);
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
__name(mapAction, "mapAction");
|
|
3598
|
+
var SCHEMA = getBorshSchema;
|
|
3599
|
+
return __toCommonJS(src_exports2);
|
|
3600
|
+
})();
|
|
3601
|
+
/*! Bundled license information:
|
|
3602
|
+
|
|
3603
|
+
@noble/hashes/esm/utils.js:
|
|
3604
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3605
|
+
|
|
3606
|
+
@noble/curves/esm/abstract/utils.js:
|
|
3607
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3608
|
+
|
|
3609
|
+
@noble/curves/esm/abstract/modular.js:
|
|
3610
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3611
|
+
|
|
3612
|
+
@noble/curves/esm/abstract/curve.js:
|
|
3613
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3614
|
+
|
|
3615
|
+
@noble/curves/esm/abstract/edwards.js:
|
|
3616
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3617
|
+
|
|
3618
|
+
@noble/curves/esm/ed25519.js:
|
|
3619
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3620
|
+
|
|
3621
|
+
@noble/hashes/esm/utils.js:
|
|
3622
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3623
|
+
*/
|
|
3624
|
+
|
|
3625
|
+
if (typeof globalThis.NearUtils === 'undefined') {
|
|
3626
|
+
console.warn('No globalThis.NearUtils');
|
|
3627
|
+
} else {
|
|
3628
|
+
Object.defineProperty(globalThis, 'NearUtils', {
|
|
3629
|
+
value: globalThis.NearUtils,
|
|
3630
|
+
writable: false,
|
|
3631
|
+
enumerable: true,
|
|
3632
|
+
configurable: false,
|
|
3633
|
+
});
|
|
3634
|
+
}
|
|
3635
|
+
|
|
3636
|
+
//# sourceMappingURL=browser.global.js.map
|