@btc-vision/transaction
Version:
OPNet transaction library allows you to create and sign transactions for the OPNet network.
1,634 lines • 66.2 kB
JavaScript
import { n as Bt, r as je } from "./rolldown-runtime.js";
function Kt(t) {
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
}
function xt(t, e = "") {
if (!Number.isSafeInteger(t) || t < 0) {
const r = e && `"${e}" `;
throw new Error(`${r}expected integer >= 0, got ${t}`);
}
}
function C(t, e, r = "") {
const n = Kt(t), o = t?.length, s = e !== void 0;
if (!n || s && o !== e) {
const i = r && `"${r}" `, c = s ? ` of length ${e}` : "", f = n ? `length=${o}` : `type=${typeof t}`;
throw new Error(i + "expected Uint8Array" + c + ", got " + f);
}
return t;
}
function Ye(t) {
if (typeof t != "function" || typeof t.create != "function") throw new Error("Hash must wrapped by utils.createHasher");
xt(t.outputLen), xt(t.blockLen);
}
function Vt(t, e = !0) {
if (t.destroyed) throw new Error("Hash instance has been destroyed");
if (e && t.finished) throw new Error("Hash#digest() has already been called");
}
function Rn(t, e) {
C(t, void 0, "digestInto() output");
const r = e.outputLen;
if (t.length < r) throw new Error('"digestInto() output" expected to be of length >=' + r);
}
function Hr(t) {
return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
}
function At(...t) {
for (let e = 0; e < t.length; e++) t[e].fill(0);
}
function ee(t) {
return new DataView(t.buffer, t.byteOffset, t.byteLength);
}
function st(t, e) {
return t << 32 - e | t >>> e;
}
function Ir(t, e) {
return t << e | t >>> 32 - e >>> 0;
}
function On(t) {
return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
}
function Hn(t) {
for (let e = 0; e < t.length; e++) t[e] = On(t[e]);
return t;
}
function Xt(t) {
if (C(t), pe) return t.toHex();
let e = "";
for (let r = 0; r < t.length; r++) e += Ke[t[r]];
return e;
}
function Oe(t) {
if (t >= it._0 && t <= it._9) return t - it._0;
if (t >= it.A && t <= it.F) return t - (it.A - 10);
if (t >= it.a && t <= it.f) return t - (it.a - 10);
}
function Mt(t) {
if (typeof t != "string") throw new Error("hex string expected, got " + typeof t);
if (pe) return Uint8Array.fromHex(t);
const e = t.length, r = e / 2;
if (e % 2) throw new Error("hex string expected, got unpadded hex of length " + e);
const n = new Uint8Array(r);
for (let o = 0, s = 0; o < r; o++, s += 2) {
const i = Oe(t.charCodeAt(s)), c = Oe(t.charCodeAt(s + 1));
if (i === void 0 || c === void 0) {
const f = t[s] + t[s + 1];
throw new Error('hex string expected, got non-hex character "' + f + '" at index ' + s);
}
n[o] = i * 16 + c;
}
return n;
}
function P(...t) {
let e = 0;
for (let n = 0; n < t.length; n++) {
const o = t[n];
C(o), e += o.length;
}
const r = new Uint8Array(e);
for (let n = 0, o = 0; n < t.length; n++) {
const s = t[n];
r.set(s, o), o += s.length;
}
return r;
}
function _t(t, e = {}) {
const r = (o, s) => t(s).update(o).digest(), n = t(void 0);
return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.create = (o) => t(o), Object.assign(r, e), Object.freeze(r);
}
function Ge(t = 32) {
const e = typeof globalThis == "object" ? globalThis.crypto : null;
if (typeof e?.getRandomValues != "function") throw new Error("crypto.getRandomValues must be defined");
return e.getRandomValues(new Uint8Array(t));
}
var He, In, pe, Ke, it, mt, Nt = Bt((() => {
He = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, In = He ? (t) => t : Hn, pe = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ke = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0")), it = {
_0: 48,
_9: 57,
A: 65,
F: 70,
a: 97,
f: 102
}, mt = (t) => ({ oid: Uint8Array.from([
6,
9,
96,
134,
72,
1,
101,
3,
4,
2,
t
]) });
})), Lr = /* @__PURE__ */ je({
_HMAC: () => kt,
hmac: () => $t
}), kt, $t, Ln = Bt((() => {
Nt(), kt = class {
oHash;
iHash;
blockLen;
outputLen;
finished = !1;
destroyed = !1;
constructor(t, e) {
if (Ye(t), C(e, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function") throw new Error("Expected instance of class which extends utils.Hash");
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
const r = this.blockLen, n = new Uint8Array(r);
n.set(e.length > r ? t.create().update(e).digest() : e);
for (let o = 0; o < n.length; o++) n[o] ^= 54;
this.iHash.update(n), this.oHash = t.create();
for (let o = 0; o < n.length; o++) n[o] ^= 106;
this.oHash.update(n), At(n);
}
update(t) {
return Vt(this), this.iHash.update(t), this;
}
digestInto(t) {
Vt(this), C(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
}
digest() {
const t = new Uint8Array(this.oHash.outputLen);
return this.digestInto(t), t;
}
_cloneInto(t) {
t ||= Object.create(Object.getPrototypeOf(this), {});
const { oHash: e, iHash: r, finished: n, destroyed: o, blockLen: s, outputLen: i } = this;
return t = t, t.finished = n, t.destroyed = o, t.blockLen = s, t.outputLen = i, t.oHash = e._cloneInto(t.oHash), t.iHash = r._cloneInto(t.iHash), t;
}
clone() {
return this._cloneInto();
}
destroy() {
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
}
}, $t = (t, e, r) => new kt(t, e).update(r).digest(), $t.create = (t, e) => new kt(t, e);
}));
function qn(t, e, r) {
return t & e ^ ~t & r;
}
function Un(t, e, r) {
return t & e ^ t & r ^ e & r;
}
var ae, dt, ht, K, X, Nn = Bt((() => {
Nt(), ae = class {
blockLen;
outputLen;
padOffset;
isLE;
buffer;
view;
finished = !1;
length = 0;
pos = 0;
destroyed = !1;
constructor(t, e, r, n) {
this.blockLen = t, this.outputLen = e, this.padOffset = r, this.isLE = n, this.buffer = new Uint8Array(t), this.view = ee(this.buffer);
}
update(t) {
Vt(this), C(t);
const { view: e, buffer: r, blockLen: n } = this, o = t.length;
for (let s = 0; s < o; ) {
const i = Math.min(n - this.pos, o - s);
if (i === n) {
const c = ee(t);
for (; n <= o - s; s += n) this.process(c, s);
continue;
}
r.set(t.subarray(s, s + i), this.pos), this.pos += i, s += i, this.pos === n && (this.process(e, 0), this.pos = 0);
}
return this.length += t.length, this.roundClean(), this;
}
digestInto(t) {
Vt(this), Rn(t, this), this.finished = !0;
const { buffer: e, view: r, blockLen: n, isLE: o } = this;
let { pos: s } = this;
e[s++] = 128, At(this.buffer.subarray(s)), this.padOffset > n - s && (this.process(r, 0), s = 0);
for (let a = s; a < n; a++) e[a] = 0;
r.setBigUint64(n - 8, BigInt(this.length * 8), o), this.process(r, 0);
const i = ee(t), c = this.outputLen;
if (c % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
const f = c / 4, l = this.get();
if (f > l.length) throw new Error("_sha2: outputLen bigger than state");
for (let a = 0; a < f; a++) i.setUint32(4 * a, l[a], o);
}
digest() {
const { buffer: t, outputLen: e } = this;
this.digestInto(t);
const r = t.slice(0, e);
return this.destroy(), r;
}
_cloneInto(t) {
t ||= new this.constructor(), t.set(...this.get());
const { blockLen: e, buffer: r, length: n, finished: o, destroyed: s, pos: i } = this;
return t.destroyed = s, t.finished = o, t.length = n, t.pos = i, n % e && t.buffer.set(r), t;
}
clone() {
return this._cloneInto();
}
}, dt = /* @__PURE__ */ Uint32Array.from([
1779033703,
3144134277,
1013904242,
2773480762,
1359893119,
2600822924,
528734635,
1541459225
]), ht = /* @__PURE__ */ Uint32Array.from([
3238371032,
914150663,
812702999,
4144912697,
4290775857,
1750603025,
1694076839,
3204075428
]), K = /* @__PURE__ */ Uint32Array.from([
3418070365,
3238371032,
1654270250,
914150663,
2438529370,
812702999,
355462360,
4144912697,
1731405415,
4290775857,
2394180231,
1750603025,
3675008525,
1694076839,
1203062813,
3204075428
]), X = /* @__PURE__ */ Uint32Array.from([
1779033703,
4089235720,
3144134277,
2227873595,
1013904242,
4271175723,
2773480762,
1595750129,
1359893119,
2917565137,
2600822924,
725511199,
528734635,
4215389547,
1541459225,
327033209
]);
}));
function Dn(t, e = !1) {
return e ? {
h: Number(t & It),
l: Number(t >> le & It)
} : {
h: Number(t >> le & It) | 0,
l: Number(t & It) | 0
};
}
function Cn(t, e = !1) {
const r = t.length;
let n = new Uint32Array(r), o = new Uint32Array(r);
for (let s = 0; s < r; s++) {
const { h: i, l: c } = Dn(t[s], e);
[n[s], o[s]] = [i, c];
}
return [n, o];
}
function ft(t, e, r, n) {
const o = (e >>> 0) + (n >>> 0);
return {
h: t + r + (o / 2 ** 32 | 0) | 0,
l: o | 0
};
}
var It, le, ue, de, yt, Et, Lt, qt, Zn, kn, Tn, Vn, Xe, ze, We, Qe, Je, Pe, Mn = Bt((() => {
It = /* @__PURE__ */ BigInt(2 ** 32 - 1), le = /* @__PURE__ */ BigInt(32), ue = (t, e, r) => t >>> r, de = (t, e, r) => t << 32 - r | e >>> r, yt = (t, e, r) => t >>> r | e << 32 - r, Et = (t, e, r) => t << 32 - r | e >>> r, Lt = (t, e, r) => t << 64 - r | e >>> r - 32, qt = (t, e, r) => t >>> r - 32 | e << 64 - r, Zn = (t, e, r) => t << r | e >>> 32 - r, kn = (t, e, r) => e << r | t >>> 32 - r, Tn = (t, e, r) => e << r - 32 | t >>> 64 - r, Vn = (t, e, r) => t << r - 32 | e >>> 64 - r, Xe = (t, e, r) => (t >>> 0) + (e >>> 0) + (r >>> 0), ze = (t, e, r, n) => e + r + n + (t / 2 ** 32 | 0) | 0, We = (t, e, r, n) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (n >>> 0), Qe = (t, e, r, n, o) => e + r + n + o + (t / 2 ** 32 | 0) | 0, Je = (t, e, r, n, o) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (n >>> 0) + (o >>> 0), Pe = (t, e, r, n, o, s) => e + r + n + o + s + (t / 2 ** 32 | 0) | 0;
})), qr = /* @__PURE__ */ je({
_SHA224: () => be,
_SHA256: () => he,
_SHA384: () => ge,
_SHA512: () => we,
_SHA512_224: () => me,
_SHA512_256: () => ye,
sha224: () => Fe,
sha256: () => zt,
sha384: () => en,
sha512: () => tn,
sha512_224: () => rn,
sha512_256: () => nn
}), Ie, at, ne, he, be, re, Le, qe, lt, ut, Ht, we, ge, Y, G, me, ye, zt, Fe, tn, en, nn, rn, $n = Bt((() => {
Nn(), Mn(), Nt(), Ie = /* @__PURE__ */ Uint32Array.from([
1116352408,
1899447441,
3049323471,
3921009573,
961987163,
1508970993,
2453635748,
2870763221,
3624381080,
310598401,
607225278,
1426881987,
1925078388,
2162078206,
2614888103,
3248222580,
3835390401,
4022224774,
264347078,
604807628,
770255983,
1249150122,
1555081692,
1996064986,
2554220882,
2821834349,
2952996808,
3210313671,
3336571891,
3584528711,
113926993,
338241895,
666307205,
773529912,
1294757372,
1396182291,
1695183700,
1986661051,
2177026350,
2456956037,
2730485921,
2820302411,
3259730800,
3345764771,
3516065817,
3600352804,
4094571909,
275423344,
430227734,
506948616,
659060556,
883997877,
958139571,
1322822218,
1537002063,
1747873779,
1955562222,
2024104815,
2227730452,
2361852424,
2428436474,
2756734187,
3204031479,
3329325298
]), at = /* @__PURE__ */ new Uint32Array(64), ne = class extends ae {
constructor(t) {
super(64, t, 8, !1);
}
get() {
const { A: t, B: e, C: r, D: n, E: o, F: s, G: i, H: c } = this;
return [
t,
e,
r,
n,
o,
s,
i,
c
];
}
set(t, e, r, n, o, s, i, c) {
this.A = t | 0, this.B = e | 0, this.C = r | 0, this.D = n | 0, this.E = o | 0, this.F = s | 0, this.G = i | 0, this.H = c | 0;
}
process(t, e) {
for (let a = 0; a < 16; a++, e += 4) at[a] = t.getUint32(e, !1);
for (let a = 16; a < 64; a++) {
const g = at[a - 15], b = at[a - 2], w = st(g, 7) ^ st(g, 18) ^ g >>> 3;
at[a] = (st(b, 17) ^ st(b, 19) ^ b >>> 10) + at[a - 7] + w + at[a - 16] | 0;
}
let { A: r, B: n, C: o, D: s, E: i, F: c, G: f, H: l } = this;
for (let a = 0; a < 64; a++) {
const g = st(i, 6) ^ st(i, 11) ^ st(i, 25), b = l + g + qn(i, c, f) + Ie[a] + at[a] | 0, w = (st(r, 2) ^ st(r, 13) ^ st(r, 22)) + Un(r, n, o) | 0;
l = f, f = c, c = i, i = s + b | 0, s = o, o = n, n = r, r = b + w | 0;
}
r = r + this.A | 0, n = n + this.B | 0, o = o + this.C | 0, s = s + this.D | 0, i = i + this.E | 0, c = c + this.F | 0, f = f + this.G | 0, l = l + this.H | 0, this.set(r, n, o, s, i, c, f, l);
}
roundClean() {
At(at);
}
destroy() {
this.set(0, 0, 0, 0, 0, 0, 0, 0), At(this.buffer);
}
}, he = class extends ne {
A = dt[0] | 0;
B = dt[1] | 0;
C = dt[2] | 0;
D = dt[3] | 0;
E = dt[4] | 0;
F = dt[5] | 0;
G = dt[6] | 0;
H = dt[7] | 0;
constructor() {
super(32);
}
}, be = class extends ne {
A = ht[0] | 0;
B = ht[1] | 0;
C = ht[2] | 0;
D = ht[3] | 0;
E = ht[4] | 0;
F = ht[5] | 0;
G = ht[6] | 0;
H = ht[7] | 0;
constructor() {
super(28);
}
}, re = Cn([
"0x428a2f98d728ae22",
"0x7137449123ef65cd",
"0xb5c0fbcfec4d3b2f",
"0xe9b5dba58189dbbc",
"0x3956c25bf348b538",
"0x59f111f1b605d019",
"0x923f82a4af194f9b",
"0xab1c5ed5da6d8118",
"0xd807aa98a3030242",
"0x12835b0145706fbe",
"0x243185be4ee4b28c",
"0x550c7dc3d5ffb4e2",
"0x72be5d74f27b896f",
"0x80deb1fe3b1696b1",
"0x9bdc06a725c71235",
"0xc19bf174cf692694",
"0xe49b69c19ef14ad2",
"0xefbe4786384f25e3",
"0x0fc19dc68b8cd5b5",
"0x240ca1cc77ac9c65",
"0x2de92c6f592b0275",
"0x4a7484aa6ea6e483",
"0x5cb0a9dcbd41fbd4",
"0x76f988da831153b5",
"0x983e5152ee66dfab",
"0xa831c66d2db43210",
"0xb00327c898fb213f",
"0xbf597fc7beef0ee4",
"0xc6e00bf33da88fc2",
"0xd5a79147930aa725",
"0x06ca6351e003826f",
"0x142929670a0e6e70",
"0x27b70a8546d22ffc",
"0x2e1b21385c26c926",
"0x4d2c6dfc5ac42aed",
"0x53380d139d95b3df",
"0x650a73548baf63de",
"0x766a0abb3c77b2a8",
"0x81c2c92e47edaee6",
"0x92722c851482353b",
"0xa2bfe8a14cf10364",
"0xa81a664bbc423001",
"0xc24b8b70d0f89791",
"0xc76c51a30654be30",
"0xd192e819d6ef5218",
"0xd69906245565a910",
"0xf40e35855771202a",
"0x106aa07032bbd1b8",
"0x19a4c116b8d2d0c8",
"0x1e376c085141ab53",
"0x2748774cdf8eeb99",
"0x34b0bcb5e19b48a8",
"0x391c0cb3c5c95a63",
"0x4ed8aa4ae3418acb",
"0x5b9cca4f7763e373",
"0x682e6ff3d6b2b8a3",
"0x748f82ee5defb2fc",
"0x78a5636f43172f60",
"0x84c87814a1f0ab72",
"0x8cc702081a6439ec",
"0x90befffa23631e28",
"0xa4506cebde82bde9",
"0xbef9a3f7b2c67915",
"0xc67178f2e372532b",
"0xca273eceea26619c",
"0xd186b8c721c0c207",
"0xeada7dd6cde0eb1e",
"0xf57d4f7fee6ed178",
"0x06f067aa72176fba",
"0x0a637dc5a2c898a6",
"0x113f9804bef90dae",
"0x1b710b35131c471b",
"0x28db77f523047d84",
"0x32caab7b40c72493",
"0x3c9ebe0a15c9bebc",
"0x431d67c49c100d4c",
"0x4cc5d4becb3e42b6",
"0x597f299cfc657e2a",
"0x5fcb6fab3ad6faec",
"0x6c44198c4a475817"
].map((t) => BigInt(t))), Le = re[0], qe = re[1], lt = /* @__PURE__ */ new Uint32Array(80), ut = /* @__PURE__ */ new Uint32Array(80), Ht = class extends ae {
constructor(t) {
super(128, t, 16, !1);
}
get() {
const { Ah: t, Al: e, Bh: r, Bl: n, Ch: o, Cl: s, Dh: i, Dl: c, Eh: f, El: l, Fh: a, Fl: g, Gh: b, Gl: w, Hh: m, Hl: x } = this;
return [
t,
e,
r,
n,
o,
s,
i,
c,
f,
l,
a,
g,
b,
w,
m,
x
];
}
set(t, e, r, n, o, s, i, c, f, l, a, g, b, w, m, x) {
this.Ah = t | 0, this.Al = e | 0, this.Bh = r | 0, this.Bl = n | 0, this.Ch = o | 0, this.Cl = s | 0, this.Dh = i | 0, this.Dl = c | 0, this.Eh = f | 0, this.El = l | 0, this.Fh = a | 0, this.Fl = g | 0, this.Gh = b | 0, this.Gl = w | 0, this.Hh = m | 0, this.Hl = x | 0;
}
process(t, e) {
for (let E = 0; E < 16; E++, e += 4)
lt[E] = t.getUint32(e), ut[E] = t.getUint32(e += 4);
for (let E = 16; E < 80; E++) {
const L = lt[E - 15] | 0, I = ut[E - 15] | 0, V = yt(L, I, 1) ^ yt(L, I, 8) ^ ue(L, I, 7), M = Et(L, I, 1) ^ Et(L, I, 8) ^ de(L, I, 7), D = lt[E - 2] | 0, N = ut[E - 2] | 0, O = yt(D, N, 19) ^ Lt(D, N, 61) ^ ue(D, N, 6), nt = Et(D, N, 19) ^ qt(D, N, 61) ^ de(D, N, 6), F = We(M, nt, ut[E - 7], ut[E - 16]);
lt[E] = Qe(F, V, O, lt[E - 7], lt[E - 16]) | 0, ut[E] = F | 0;
}
let { Ah: r, Al: n, Bh: o, Bl: s, Ch: i, Cl: c, Dh: f, Dl: l, Eh: a, El: g, Fh: b, Fl: w, Gh: m, Gl: x, Hh: v, Hl: B } = this;
for (let E = 0; E < 80; E++) {
const L = yt(a, g, 14) ^ yt(a, g, 18) ^ Lt(a, g, 41), I = Et(a, g, 14) ^ Et(a, g, 18) ^ qt(a, g, 41), V = a & b ^ ~a & m, M = g & w ^ ~g & x, D = Je(B, I, M, qe[E], ut[E]), N = Pe(D, v, L, V, Le[E], lt[E]), O = D | 0, nt = yt(r, n, 28) ^ Lt(r, n, 34) ^ Lt(r, n, 39), F = Et(r, n, 28) ^ qt(r, n, 34) ^ qt(r, n, 39), U = r & o ^ r & i ^ o & i, h = n & s ^ n & c ^ s & c;
v = m | 0, B = x | 0, m = b | 0, x = w | 0, b = a | 0, w = g | 0, { h: a, l: g } = ft(f | 0, l | 0, N | 0, O | 0), f = i | 0, l = c | 0, i = o | 0, c = s | 0, o = r | 0, s = n | 0;
const d = Xe(O, F, h);
r = ze(d, N, nt, U), n = d | 0;
}
({ h: r, l: n } = ft(this.Ah | 0, this.Al | 0, r | 0, n | 0)), { h: o, l: s } = ft(this.Bh | 0, this.Bl | 0, o | 0, s | 0), { h: i, l: c } = ft(this.Ch | 0, this.Cl | 0, i | 0, c | 0), { h: f, l } = ft(this.Dh | 0, this.Dl | 0, f | 0, l | 0), { h: a, l: g } = ft(this.Eh | 0, this.El | 0, a | 0, g | 0), { h: b, l: w } = ft(this.Fh | 0, this.Fl | 0, b | 0, w | 0), { h: m, l: x } = ft(this.Gh | 0, this.Gl | 0, m | 0, x | 0), { h: v, l: B } = ft(this.Hh | 0, this.Hl | 0, v | 0, B | 0), this.set(r, n, o, s, i, c, f, l, a, g, b, w, m, x, v, B);
}
roundClean() {
At(lt, ut);
}
destroy() {
At(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
}, we = class extends Ht {
Ah = X[0] | 0;
Al = X[1] | 0;
Bh = X[2] | 0;
Bl = X[3] | 0;
Ch = X[4] | 0;
Cl = X[5] | 0;
Dh = X[6] | 0;
Dl = X[7] | 0;
Eh = X[8] | 0;
El = X[9] | 0;
Fh = X[10] | 0;
Fl = X[11] | 0;
Gh = X[12] | 0;
Gl = X[13] | 0;
Hh = X[14] | 0;
Hl = X[15] | 0;
constructor() {
super(64);
}
}, ge = class extends Ht {
Ah = K[0] | 0;
Al = K[1] | 0;
Bh = K[2] | 0;
Bl = K[3] | 0;
Ch = K[4] | 0;
Cl = K[5] | 0;
Dh = K[6] | 0;
Dl = K[7] | 0;
Eh = K[8] | 0;
El = K[9] | 0;
Fh = K[10] | 0;
Fl = K[11] | 0;
Gh = K[12] | 0;
Gl = K[13] | 0;
Hh = K[14] | 0;
Hl = K[15] | 0;
constructor() {
super(48);
}
}, Y = /* @__PURE__ */ Uint32Array.from([
2352822216,
424955298,
1944164710,
2312950998,
502970286,
855612546,
1738396948,
1479516111,
258812777,
2077511080,
2011393907,
79989058,
1067287976,
1780299464,
286451373,
2446758561
]), G = /* @__PURE__ */ Uint32Array.from([
573645204,
4230739756,
2673172387,
3360449730,
596883563,
1867755857,
2520282905,
1497426621,
2519219938,
2827943907,
3193839141,
1401305490,
721525244,
746961066,
246885852,
2177182882
]), me = class extends Ht {
Ah = Y[0] | 0;
Al = Y[1] | 0;
Bh = Y[2] | 0;
Bl = Y[3] | 0;
Ch = Y[4] | 0;
Cl = Y[5] | 0;
Dh = Y[6] | 0;
Dl = Y[7] | 0;
Eh = Y[8] | 0;
El = Y[9] | 0;
Fh = Y[10] | 0;
Fl = Y[11] | 0;
Gh = Y[12] | 0;
Gl = Y[13] | 0;
Hh = Y[14] | 0;
Hl = Y[15] | 0;
constructor() {
super(28);
}
}, ye = class extends Ht {
Ah = G[0] | 0;
Al = G[1] | 0;
Bh = G[2] | 0;
Bl = G[3] | 0;
Ch = G[4] | 0;
Cl = G[5] | 0;
Dh = G[6] | 0;
Dl = G[7] | 0;
Eh = G[8] | 0;
El = G[9] | 0;
Fh = G[10] | 0;
Fl = G[11] | 0;
Gh = G[12] | 0;
Gl = G[13] | 0;
Hh = G[14] | 0;
Hl = G[15] | 0;
constructor() {
super(32);
}
}, zt = /* @__PURE__ */ _t(() => new he(), /* @__PURE__ */ mt(1)), Fe = /* @__PURE__ */ _t(() => new be(), /* @__PURE__ */ mt(4)), tn = /* @__PURE__ */ _t(() => new we(), /* @__PURE__ */ mt(3)), en = /* @__PURE__ */ _t(() => new ge(), /* @__PURE__ */ mt(2)), nn = /* @__PURE__ */ _t(() => new ye(), /* @__PURE__ */ mt(6)), rn = /* @__PURE__ */ _t(() => new me(), /* @__PURE__ */ mt(5));
}));
function jt(t, e = "") {
if (typeof t != "boolean") {
const r = e && `"${e}" `;
throw new Error(r + "expected boolean, got type=" + typeof t);
}
return t;
}
function on(t) {
if (typeof t == "bigint") {
if (!Ut(t)) throw new Error("positive bigint expected, got " + t);
} else xt(t);
return t;
}
function Rt(t, e = "") {
if (!Number.isSafeInteger(t)) {
const r = e && `"${e}" `;
throw new Error(r + "expected safe integer, got type=" + typeof t);
}
}
function Zt(t) {
const e = on(t).toString(16);
return e.length & 1 ? "0" + e : e;
}
function sn(t) {
if (typeof t != "string") throw new Error("hex string expected, got " + typeof t);
return t === "" ? Yt : BigInt("0x" + t);
}
function Dt(t) {
return sn(Xt(t));
}
function cn(t) {
return sn(Xt(jn(C(t)).reverse()));
}
function xe(t, e) {
xt(e), t = on(t);
const r = Mt(t.toString(16).padStart(e * 2, "0"));
if (r.length !== e) throw new Error("number too large");
return r;
}
function fn(t, e) {
return xe(t, e).reverse();
}
function jn(t) {
return Uint8Array.from(t);
}
function Wt(t) {
return Uint8Array.from(t, (e, r) => {
const n = e.charCodeAt(0);
if (e.length !== 1 || n > 127) throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);
return n;
});
}
function Yn(t, e, r) {
return Ut(t) && Ut(e) && Ut(r) && e <= t && t < r;
}
function Gn(t, e, r, n) {
if (!Yn(e, r, n)) throw new Error("expected valid " + t + ": " + r + " <= n < " + n + ", got " + e);
}
function Kn(t) {
let e;
for (e = 0; t > Yt; t >>= Tt, e += 1) ;
return e;
}
function Xn(t, e, r) {
if (xt(t, "hashLen"), xt(e, "qByteLen"), typeof r != "function") throw new Error("hmacFn must be a function");
const n = (v) => new Uint8Array(v), o = Uint8Array.of(), s = Uint8Array.of(0), i = Uint8Array.of(1), c = 1e3;
let f = n(t), l = n(t), a = 0;
const g = () => {
f.fill(1), l.fill(0), a = 0;
}, b = (...v) => r(l, P(f, ...v)), w = (v = o) => {
l = b(s, v), f = b(), v.length !== 0 && (l = b(i, v), f = b());
}, m = () => {
if (a++ >= c) throw new Error("drbg: tried max amount of iterations");
let v = 0;
const B = [];
for (; v < e; ) {
f = b();
const E = f.slice();
B.push(E), v += f.length;
}
return P(...B);
};
return (v, B) => {
g(), w(v);
let E;
for (; !(E = B(m())); ) w();
return g(), E;
};
}
function Qt(t, e = {}, r = {}) {
if (!t || typeof t != "object") throw new Error("expected valid options object");
function n(s, i, c) {
const f = t[s];
if (c && f === void 0) return;
const l = typeof f;
if (l !== i || f === null) throw new Error(`param "${s}" is invalid: expected ${i}, got ${l}`);
}
const o = (s, i) => Object.entries(s).forEach(([c, f]) => n(c, f, i));
o(e, !1), o(r, !0);
}
function Ue(t) {
const e = /* @__PURE__ */ new WeakMap();
return (r, ...n) => {
const o = e.get(r);
if (o !== void 0) return o;
const s = t(r, ...n);
return e.set(r, s), s;
};
}
var Yt, Tt, Ut, Jt, Pt = Bt((() => {
Nt(), Yt = /* @__PURE__ */ BigInt(0), Tt = /* @__PURE__ */ BigInt(1), Ut = (t) => typeof t == "bigint" && Yt <= t, Jt = (t) => (Tt << BigInt(t)) - Tt;
}));
function Be(t) {
if (!Number.isSafeInteger(t) || t < 0 || t > 4294967295) throw new Error("wrong u32 integer:" + t);
return t;
}
function an(t) {
return Be(t), (t & t - 1) === 0 && t !== 0;
}
function zn(t, e) {
Be(t);
let r = 0;
for (let n = 0; n < e; n++, t >>>= 1) r = r << 1 | t & 1;
return r;
}
function ln(t) {
return Be(t), 31 - Math.clz32(t);
}
function Ne(t) {
const e = t.length;
if (e < 2 || !an(e)) throw new Error("n must be a power of 2 and greater than 1. Got " + e);
const r = ln(e);
for (let n = 0; n < e; n++) {
const o = zn(n, r);
if (n < o) {
const s = t[n];
t[n] = t[o], t[o] = s;
}
}
return t;
}
var Wn, Ur = Bt((() => {
Wn = (t, e) => {
const { N: r, roots: n, dit: o, invertButterflies: s = !1, skipStages: i = 0, brp: c = !0 } = e, f = ln(r);
if (!an(r)) throw new Error("FFT: Polynomial size should be power of two");
const l = o !== s;
return (a) => {
if (a.length !== r) throw new Error("FFT: wrong Polynomial length");
o && c && Ne(a);
for (let g = 0, b = 1; g < f - i; g++) {
const w = o ? g + 1 + i : f - g, m = 1 << w, x = m >> 1, v = r >> w;
for (let B = 0; B < r; B += m) for (let E = 0, L = b++; E < x; E++) {
const I = s ? o ? r - L : L : E * v, V = B + E, M = B + E + x, D = n[I], N = a[M], O = a[V];
if (l) {
const nt = t.mul(N, D);
a[V] = t.add(O, nt), a[M] = t.sub(O, nt);
} else s ? (a[V] = t.add(N, O), a[M] = t.mul(t.sub(N, O), D)) : (a[V] = t.add(O, N), a[M] = t.mul(t.sub(O, N), D));
}
}
return !o && c && Ne(a), a;
};
};
}));
Pt();
var J = /* @__PURE__ */ BigInt(0), W = /* @__PURE__ */ BigInt(1), vt = /* @__PURE__ */ BigInt(2), un = /* @__PURE__ */ BigInt(3), dn = /* @__PURE__ */ BigInt(4), hn = /* @__PURE__ */ BigInt(5), Qn = /* @__PURE__ */ BigInt(7), bn = /* @__PURE__ */ BigInt(8), Jn = /* @__PURE__ */ BigInt(9), wn = /* @__PURE__ */ BigInt(16);
function et(t, e) {
const r = t % e;
return r >= J ? r : e + r;
}
function tt(t, e, r) {
let n = t;
for (; e-- > J; )
n *= n, n %= r;
return n;
}
function De(t, e) {
if (t === J) throw new Error("invert: expected non-zero number");
if (e <= J) throw new Error("invert: expected positive modulus, got " + e);
let r = et(t, e), n = e, o = J, s = W, i = W, c = J;
for (; r !== J; ) {
const f = n / r, l = n % r, a = o - i * f, g = s - c * f;
n = r, r = l, o = i, s = c, i = a, c = g;
}
if (n !== W) throw new Error("invert: does not exist");
return et(o, e);
}
function _e(t, e, r) {
if (!t.eql(t.sqr(e), r)) throw new Error("Cannot find square root");
}
function gn(t, e) {
const r = (t.ORDER + W) / dn, n = t.pow(e, r);
return _e(t, n, e), n;
}
function Pn(t, e) {
const r = (t.ORDER - hn) / bn, n = t.mul(e, vt), o = t.pow(n, r), s = t.mul(e, o), i = t.mul(t.mul(s, vt), o), c = t.mul(s, t.sub(i, t.ONE));
return _e(t, c, e), c;
}
function Fn(t) {
const e = te(t), r = mn(t), n = r(e, e.neg(e.ONE)), o = r(e, n), s = r(e, e.neg(n)), i = (t + Qn) / wn;
return (c, f) => {
let l = c.pow(f, i), a = c.mul(l, n);
const g = c.mul(l, o), b = c.mul(l, s), w = c.eql(c.sqr(a), f), m = c.eql(c.sqr(g), f);
l = c.cmov(l, a, w), a = c.cmov(b, g, m);
const x = c.eql(c.sqr(a), f), v = c.cmov(l, a, x);
return _e(c, v, f), v;
};
}
function mn(t) {
if (t < un) throw new Error("sqrt is not defined for small field");
let e = t - W, r = 0;
for (; e % vt === J; )
e /= vt, r++;
let n = vt;
const o = te(t);
for (; Ce(o, n) === 1; ) if (n++ > 1e3) throw new Error("Cannot find square root: probably non-prime P");
if (r === 1) return gn;
let s = o.pow(n, e);
const i = (e + W) / vt;
return function(f, l) {
if (f.is0(l)) return l;
if (Ce(f, l) !== 1) throw new Error("Cannot find square root");
let a = r, g = f.mul(f.ONE, s), b = f.pow(l, e), w = f.pow(l, i);
for (; !f.eql(b, f.ONE); ) {
if (f.is0(b)) return f.ZERO;
let m = 1, x = f.sqr(b);
for (; !f.eql(x, f.ONE); )
if (m++, x = f.sqr(x), m === a) throw new Error("Cannot find square root");
const v = W << BigInt(a - m - 1), B = f.pow(g, v);
a = m, g = f.sqr(B), b = f.mul(b, g), w = f.mul(w, B);
}
return w;
};
}
function tr(t) {
return t % dn === un ? gn : t % bn === hn ? Pn : t % wn === Jn ? Fn(t) : mn(t);
}
var er = [
"create",
"isValid",
"is0",
"neg",
"inv",
"sqrt",
"sqr",
"eql",
"add",
"sub",
"mul",
"pow",
"div",
"addN",
"subN",
"mulN",
"sqrN"
];
function yn(t) {
return Qt(t, er.reduce((e, r) => (e[r] = "function", e), {
ORDER: "bigint",
BYTES: "number",
BITS: "number"
})), t;
}
function nr(t, e, r) {
if (r < J) throw new Error("invalid exponent, negatives unsupported");
if (r === J) return t.ONE;
if (r === W) return e;
let n = t.ONE, o = e;
for (; r > J; )
r & W && (n = t.mul(n, o)), o = t.sqr(o), r >>= W;
return n;
}
function Ft(t, e, r = !1) {
const n = new Array(e.length).fill(r ? t.ZERO : void 0), o = e.reduce((i, c, f) => t.is0(c) ? i : (n[f] = i, t.mul(i, c)), t.ONE), s = t.inv(o);
return e.reduceRight((i, c, f) => t.is0(c) ? i : (n[f] = t.mul(i, n[f]), t.mul(i, c)), s), n;
}
function Ce(t, e) {
const r = (t.ORDER - W) / vt, n = t.pow(e, r), o = t.eql(n, t.ONE), s = t.eql(n, t.ZERO), i = t.eql(n, t.neg(t.ONE));
if (!o && !s && !i) throw new Error("invalid Legendre symbol result");
return o ? 1 : s ? 0 : -1;
}
function rr(t, e) {
e !== void 0 && xt(e);
const r = e !== void 0 ? e : t.toString(2).length;
return {
nBitLength: r,
nByteLength: Math.ceil(r / 8)
};
}
var or = class {
ORDER;
BITS;
BYTES;
isLE;
ZERO = J;
ONE = W;
_lengths;
_sqrt;
_mod;
constructor(t, e = {}) {
if (t <= J) throw new Error("invalid field: expected ORDER > 0, got " + t);
let r;
this.isLE = !1, e != null && typeof e == "object" && (typeof e.BITS == "number" && (r = e.BITS), typeof e.sqrt == "function" && (this.sqrt = e.sqrt), typeof e.isLE == "boolean" && (this.isLE = e.isLE), e.allowedLengths && (this._lengths = e.allowedLengths?.slice()), typeof e.modFromBytes == "boolean" && (this._mod = e.modFromBytes));
const { nBitLength: n, nByteLength: o } = rr(t, r);
if (o > 2048) throw new Error("invalid field: expected ORDER of <= 2048 bytes");
this.ORDER = t, this.BITS = n, this.BYTES = o, this._sqrt = void 0, Object.preventExtensions(this);
}
create(t) {
return et(t, this.ORDER);
}
isValid(t) {
if (typeof t != "bigint") throw new Error("invalid field element: expected bigint, got " + typeof t);
return J <= t && t < this.ORDER;
}
is0(t) {
return t === J;
}
isValidNot0(t) {
return !this.is0(t) && this.isValid(t);
}
isOdd(t) {
return (t & W) === W;
}
neg(t) {
return et(-t, this.ORDER);
}
eql(t, e) {
return t === e;
}
sqr(t) {
return et(t * t, this.ORDER);
}
add(t, e) {
return et(t + e, this.ORDER);
}
sub(t, e) {
return et(t - e, this.ORDER);
}
mul(t, e) {
return et(t * e, this.ORDER);
}
pow(t, e) {
return nr(this, t, e);
}
div(t, e) {
return et(t * De(e, this.ORDER), this.ORDER);
}
sqrN(t) {
return t * t;
}
addN(t, e) {
return t + e;
}
subN(t, e) {
return t - e;
}
mulN(t, e) {
return t * e;
}
inv(t) {
return De(t, this.ORDER);
}
sqrt(t) {
return this._sqrt || (this._sqrt = tr(this.ORDER)), this._sqrt(this, t);
}
toBytes(t) {
return this.isLE ? fn(t, this.BYTES) : xe(t, this.BYTES);
}
fromBytes(t, e = !1) {
C(t);
const { _lengths: r, BYTES: n, isLE: o, ORDER: s, _mod: i } = this;
if (r) {
if (!r.includes(t.length) || t.length > n) throw new Error("Field.fromBytes: expected " + r + " bytes, got " + t.length);
const f = new Uint8Array(n);
f.set(t, o ? 0 : f.length - t.length), t = f;
}
if (t.length !== n) throw new Error("Field.fromBytes: expected " + n + " bytes, got " + t.length);
let c = o ? cn(t) : Dt(t);
if (i && (c = et(c, s)), !e && !this.isValid(c))
throw new Error("invalid field element: outside of range 0..ORDER");
return c;
}
invertBatch(t) {
return Ft(this, t);
}
cmov(t, e, r) {
return r ? e : t;
}
};
function te(t, e = {}) {
return new or(t, e);
}
function En(t) {
if (typeof t != "bigint") throw new Error("field order must be bigint");
const e = t.toString(2).length;
return Math.ceil(e / 8);
}
function vn(t) {
const e = En(t);
return e + Math.ceil(e / 2);
}
function sr(t, e, r = !1) {
C(t);
const n = t.length, o = En(e), s = vn(e);
if (n < 16 || n < s || n > 1024) throw new Error("expected " + s + "-1024 bytes of input, got " + n);
const i = et(r ? cn(t) : Dt(t), e - W) + W;
return r ? fn(i, o) : xe(i, o);
}
Pt();
var Ot = /* @__PURE__ */ BigInt(0), pt = /* @__PURE__ */ BigInt(1);
function Gt(t, e) {
const r = e.negate();
return t ? r : e;
}
function Ze(t, e) {
const r = Ft(t.Fp, e.map((n) => n.Z));
return e.map((n, o) => t.fromAffine(n.toAffine(r[o])));
}
function pn(t, e) {
if (!Number.isSafeInteger(t) || t <= 0 || t > e) throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
}
function oe(t, e) {
pn(t, e);
const r = Math.ceil(e / t) + 1, n = 2 ** (t - 1), o = 2 ** t;
return {
windows: r,
windowSize: n,
mask: Jt(t),
maxNumber: o,
shiftBy: BigInt(t)
};
}
function ke(t, e, r) {
const { windowSize: n, mask: o, maxNumber: s, shiftBy: i } = r;
let c = Number(t & o), f = t >> i;
c > n && (c -= s, f += pt);
const l = e * n, a = l + Math.abs(c) - 1, g = c === 0, b = c < 0, w = e % 2 !== 0;
return {
nextN: f,
offset: a,
isZero: g,
isNeg: b,
isNegF: w,
offsetF: l
};
}
var se = /* @__PURE__ */ new WeakMap(), xn = /* @__PURE__ */ new WeakMap();
function ie(t) {
return xn.get(t) || 1;
}
function Te(t) {
if (t !== Ot) throw new Error("invalid wNAF");
}
var ir = class {
BASE;
ZERO;
Fn;
bits;
constructor(t, e) {
this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = e;
}
_unsafeLadder(t, e, r = this.ZERO) {
let n = t;
for (; e > Ot; )
e & pt && (r = r.add(n)), n = n.double(), e >>= pt;
return r;
}
precomputeWindow(t, e) {
const { windows: r, windowSize: n } = oe(e, this.bits), o = [];
let s = t, i = s;
for (let c = 0; c < r; c++) {
i = s, o.push(i);
for (let f = 1; f < n; f++)
i = i.add(s), o.push(i);
s = i.double();
}
return o;
}
wNAF(t, e, r) {
if (!this.Fn.isValid(r)) throw new Error("invalid scalar");
let n = this.ZERO, o = this.BASE;
const s = oe(t, this.bits);
for (let i = 0; i < s.windows; i++) {
const { nextN: c, offset: f, isZero: l, isNeg: a, isNegF: g, offsetF: b } = ke(r, i, s);
r = c, l ? o = o.add(Gt(g, e[b])) : n = n.add(Gt(a, e[f]));
}
return Te(r), {
p: n,
f: o
};
}
wNAFUnsafe(t, e, r, n = this.ZERO) {
const o = oe(t, this.bits);
for (let s = 0; s < o.windows && r !== Ot; s++) {
const { nextN: i, offset: c, isZero: f, isNeg: l } = ke(r, s, o);
if (r = i, !f) {
const a = e[c];
n = n.add(l ? a.negate() : a);
}
}
return Te(r), n;
}
getPrecomputes(t, e, r) {
let n = se.get(e);
return n || (n = this.precomputeWindow(e, t), t !== 1 && (typeof r == "function" && (n = r(n)), se.set(e, n))), n;
}
cached(t, e, r) {
const n = ie(t);
return this.wNAF(n, this.getPrecomputes(n, t, r), e);
}
unsafe(t, e, r, n) {
const o = ie(t);
return o === 1 ? this._unsafeLadder(t, e, n) : this.wNAFUnsafe(o, this.getPrecomputes(o, t, r), e, n);
}
createCache(t, e) {
pn(e, this.bits), xn.set(t, e), se.delete(t);
}
hasCache(t) {
return ie(t) !== 1;
}
};
function cr(t, e, r, n) {
let o = e, s = t.ZERO, i = t.ZERO;
for (; r > Ot || n > Ot; )
r & pt && (s = s.add(o)), n & pt && (i = i.add(o)), o = o.double(), r >>= pt, n >>= pt;
return {
p1: s,
p2: i
};
}
function Ve(t, e, r) {
if (e) {
if (e.ORDER !== t) throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
return yn(e), e;
} else return te(t, { isLE: r });
}
function fr(t, e, r = {}, n) {
if (n === void 0 && (n = t === "edwards"), !e || typeof e != "object") throw new Error(`expected valid ${t} CURVE object`);
for (const c of [
"p",
"n",
"h"
]) {
const f = e[c];
if (!(typeof f == "bigint" && f > Ot)) throw new Error(`CURVE.${c} must be positive bigint`);
}
const o = Ve(e.p, r.Fp, n), s = Ve(e.n, r.Fn, n), i = [
"Gx",
"Gy",
"a",
t === "weierstrass" ? "b" : "d"
];
for (const c of i) if (!o.isValid(e[c])) throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);
return e = Object.freeze(Object.assign({}, e)), {
CURVE: e,
Fp: o,
Fn: s
};
}
function ar(t, e) {
return function(n) {
const o = t(n);
return {
secretKey: o,
publicKey: e(o)
};
};
}
Pt();
var lr = Dt;
function bt(t, e) {
if (Rt(t), Rt(e), t < 0 || t >= 1 << 8 * e) throw new Error("invalid I2OSP input: " + t);
const r = Array.from({ length: e }).fill(0);
for (let n = e - 1; n >= 0; n--)
r[n] = t & 255, t >>>= 8;
return new Uint8Array(r);
}
function ur(t, e) {
const r = new Uint8Array(t.length);
for (let n = 0; n < t.length; n++) r[n] = t[n] ^ e[n];
return r;
}
function Bn(t) {
if (!Kt(t) && typeof t != "string") throw new Error("DST must be Uint8Array or ascii string");
return typeof t == "string" ? Wt(t) : t;
}
function dr(t, e, r, n) {
C(t), Rt(r), e = Bn(e), e.length > 255 && (e = n(P(Wt("H2C-OVERSIZE-DST-"), e)));
const { outputLen: o, blockLen: s } = n, i = Math.ceil(r / o);
if (r > 65535 || i > 255) throw new Error("expand_message_xmd: invalid lenInBytes");
const c = P(e, bt(e.length, 1)), f = bt(0, s), l = bt(r, 2), a = new Array(i), g = n(P(f, t, l, bt(0, 1), c));
a[0] = n(P(g, bt(1, 1), c));
for (let b = 1; b <= i; b++) a[b] = n(P(ur(g, a[b - 1]), bt(b + 1, 1), c));
return P(...a).slice(0, r);
}
function hr(t, e, r, n, o) {
if (C(t), Rt(r), e = Bn(e), e.length > 255) {
const s = Math.ceil(2 * n / 8);
e = o.create({ dkLen: s }).update(Wt("H2C-OVERSIZE-DST-")).update(e).digest();
}
if (r > 65535 || e.length > 255) throw new Error("expand_message_xof: invalid lenInBytes");
return o.create({ dkLen: r }).update(t).update(bt(r, 2)).update(e).update(bt(e.length, 1)).digest();
}
function ce(t, e, r) {
Qt(r, {
p: "bigint",
m: "number",
k: "number",
hash: "function"
});
const { p: n, k: o, m: s, hash: i, expand: c, DST: f } = r;
Rt(i.outputLen, "valid hash"), C(t), Rt(e);
const l = n.toString(2).length, a = Math.ceil((l + o) / 8), g = e * s * a;
let b;
if (c === "xmd") b = dr(t, f, g, i);
else if (c === "xof") b = hr(t, f, g, o, i);
else if (c === "_internal_pass") b = t;
else throw new Error('expand must be "xmd" or "xof"');
const w = new Array(e);
for (let m = 0; m < e; m++) {
const x = new Array(s);
for (let v = 0; v < s; v++) {
const B = a * (v + m * s);
x[v] = et(lr(b.subarray(B, B + a)), n);
}
w[m] = x;
}
return w;
}
function br(t, e) {
const r = e.map((n) => Array.from(n).reverse());
return (n, o) => {
const [s, i, c, f] = r.map((g) => g.reduce((b, w) => t.add(t.mul(b, n), w))), [l, a] = Ft(t, [i, f], !0);
return n = t.mul(s, l), o = t.mul(o, t.mul(c, a)), {
x: n,
y: o
};
};
}
var wr = Wt("HashToScalar-");
function gr(t, e, r) {
if (typeof e != "function") throw new Error("mapToCurve() must be defined");
function n(s) {
return t.fromAffine(e(s));
}
function o(s) {
const i = s.clearCofactor();
return i.equals(t.ZERO) ? t.ZERO : (i.assertValidity(), i);
}
return {
defaults: Object.freeze(r),
Point: t,
hashToCurve(s, i) {
const c = ce(s, 2, Object.assign({}, r, i)), f = n(c[0]), l = n(c[1]);
return o(f.add(l));
},
encodeToCurve(s, i) {
const c = r.encodeDST ? { DST: r.encodeDST } : {};
return o(n(ce(s, 1, Object.assign({}, r, c, i))[0]));
},
mapToCurve(s) {
if (r.m === 1) {
if (typeof s != "bigint") throw new Error("expected bigint (m=1)");
return o(n([s]));
}
if (!Array.isArray(s)) throw new Error("expected array of bigints");
for (const i of s) if (typeof i != "bigint") throw new Error("expected array of bigints");
return o(n(s));
},
hashToScalar(s, i) {
const c = t.Fn.ORDER;
return ce(s, 1, Object.assign({}, r, {
p: c,
m: 1,
DST: wr
}, i))[0][0];
}
};
}
Ln();
Nt();
Pt();
var Me = (t, e) => (t + (t >= 0 ? e : -e) / ct) / e;
function mr(t, e, r) {
const [[n, o], [s, i]] = e, c = Me(i * t, r), f = Me(-o * t, r);
let l = t - c * n - f * s, a = -c * o - f * i;
const g = l < rt, b = a < rt;
g && (l = -l), b && (a = -a);
const w = Jt(Math.ceil(Kn(r) / 2)) + z;
if (l < rt || l >= w || a < rt || a >= w) throw new Error("splitScalar (endomorphism): failed, k=" + t);
return {
k1neg: g,
k1: l,
k2neg: b,
k2: a
};
}
function Ee(t) {
if (![
"compact",
"recovered",
"der"
].includes(t)) throw new Error('Signature format must be "compact", "recovered", or "der"');
return t;
}
function fe(t, e) {
const r = {};
for (let n of Object.keys(e)) r[n] = t[n] === void 0 ? e[n] : t[n];
return jt(r.lowS, "lowS"), jt(r.prehash, "prehash"), r.format !== void 0 && Ee(r.format), r;
}
var yr = class extends Error {
constructor(t = "") {
super(t);
}
}, wt = {
Err: yr,
_tlv: {
encode: (t, e) => {
const { Err: r } = wt;
if (t < 0 || t > 256) throw new r("tlv.encode: wrong tag");
if (e.length & 1) throw new r("tlv.encode: unpadded data");
const n = e.length / 2, o = Zt(n);
if (o.length / 2 & 128) throw new r("tlv.encode: long form length too big");
const s = n > 127 ? Zt(o.length / 2 | 128) : "";
return Zt(t) + s + o + e;
},
decode(t, e) {
const { Err: r } = wt;
let n = 0;
if (t < 0 || t > 256) throw new r("tlv.encode: wrong tag");
if (e.length < 2 || e[n++] !== t) throw new r("tlv.decode: wrong tlv");
const o = e[n++], s = !!(o & 128);
let i = 0;
if (!s) i = o;
else {
const f = o & 127;
if (!f) throw new r("tlv.decode(long): indefinite length not supported");
if (f > 4) throw new r("tlv.decode(long): byte length is too big");
const l = e.subarray(n, n + f);
if (l.length !== f) throw new r("tlv.decode: length bytes not complete");
if (l[0] === 0) throw new r("tlv.decode(long): zero leftmost byte");
for (const a of l) i = i << 8 | a;
if (n += f, i < 128) throw new r("tlv.decode(long): not minimal encoding");
}
const c = e.subarray(n, n + i);
if (c.length !== i) throw new r("tlv.decode: wrong value length");
return {
v: c,
l: e.subarray(n + i)
};
}
},
_int: {
encode(t) {
const { Err: e } = wt;
if (t < rt) throw new e("integer: negative integers are not allowed");
let r = Zt(t);
if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1) throw new e("unexpected DER parsing assertion: unpadded hex");
return r;
},
decode(t) {
const { Err: e } = wt;
if (t[0] & 128) throw new e("invalid signature integer: negative");
if (t[0] === 0 && !(t[1] & 128)) throw new e("invalid signature integer: unnecessary leading zero");
return Dt(t);
}
},
toSig(t) {
const { Err: e, _int: r, _tlv: n } = wt, o = C(t, void 0, "signature"), { v: s, l: i } = n.decode(48, o);
if (i.length) throw new e("invalid signature: left bytes after parsing");
const { v: c, l: f } = n.decode(2, s), { v: l, l: a } = n.decode(2, f);
if (a.length) throw new e("invalid signature: left bytes after parsing");
return {
r: r.decode(c),
s: r.decode(l)
};
},
hexFromSig(t) {
const { _tlv: e, _int: r } = wt, n = e.encode(2, r.encode(t.r)) + e.encode(2, r.encode(t.s));
return e.encode(48, n);
}
}, rt = BigInt(0), z = BigInt(1), ct = BigInt(2), St = BigInt(3), ve = BigInt(4);
function Er(t, e = {}) {
const r = fr("weierstrass", t, e), { Fp: n, Fn: o } = r;
let s = r.CURVE;
const { h: i, n: c } = s;
Qt(e, {}, {
allowInfinityPoint: "boolean",
clearCofactor: "function",
isTorsionFree: "function",
fromBytes: "function",
toBytes: "function",
endo: "object"
});
const { endo: f } = e;
if (f && (!n.is0(s.a) || typeof f.beta != "bigint" || !Array.isArray(f.basises)))
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
const l = An(n, o);
function a() {
if (!n.isOdd) throw new Error("compression is not supported: Field does not have .isOdd()");
}
function g(U, h, d) {
const { x: u, y } = h.toAffine(), _ = n.toBytes(u);
return jt(d, "isCompressed"), d ? (a(), P(_n(!n.isOdd(y)), _)) : P(Uint8Array.of(4), _, n.toBytes(y));
}
function b(U) {
C(U, void 0, "Point");
const { publicKey: h, publicKeyUncompressed: d } = l, u = U.length, y = U[0], _ = U.subarray(1);
if (u === h && (y === 2 || y === 3)) {
const S = n.fromBytes(_);
if (!n.isValid(S)) throw new Error("bad point: is not on curve, wrong x");
const A = x(S);
let p;
try {
p = n.sqrt(A);
} catch (H) {
const $ = H instanceof Error ? ": " + H.message : "";
throw new Error("bad point: is not on curve, sqrt error" + $);
}
a();
const R = n.isOdd(p);
return (y & 1) === 1 !== R && (p = n.neg(p)), {
x: S,
y: p
};
} else if (u === d && y === 4) {
const S = n.BYTES, A = n.fromBytes(_.subarray(0, S)), p = n.fromBytes(_.subarray(S, S * 2));
if (!v(A, p)) throw new Error("bad point: is not on curve");
return {
x: A,
y: p
};
} else throw new Error(`bad point: got length ${u}, expected compressed=${h} or uncompressed=${d}`);
}
const w = e.toBytes || g, m = e.fromBytes || b;
function x(U) {
const h = n.sqr(U), d = n.mul(h, U);
return n.add(n.add(d, n.mul(U, s.a)), s.b);
}
function v(U, h) {
const d = n.sqr(h), u = x(U);
return n.eql(d, u);
}
if (!v(s.Gx, s.Gy)) throw new Error("bad curve params: generator point");
const B = n.mul(n.pow(s.a, St), ve), E = n.mul(n.sqr(s.b), BigInt(27));
if (n.is0(n.add(B, E))) throw new Error("bad curve params: a or b");
function L(U, h, d = !1) {
if (!n.isValid(h) || d && n.is0(h)) throw new Error(`bad point coordinate ${U}`);
return h;
}
function I(U) {
if (!(U instanceof O)) throw new Error("Weierstrass Point expected");
}
function V(U) {
if (!f || !f.basises) throw new Error("no endo");
return mr(U, f.basises, o.ORDER);
}
const M = Ue((U, h) => {
const { X: d, Y: u, Z: y } = U;
if (n.eql(y, n.ONE)) return {
x: d,
y: u
};
const _ = U.is0();
h == null && (h = _ ? n.ONE : n.inv(y));
const S = n.mul(d, h), A = n.mul(u, h), p = n.mul(y, h);
if (_) return {
x: n.ZERO,
y: n.ZERO
};
if (!n.eql(p, n.ONE)) throw new Error("invZ was invalid");
return {
x: S,
y: A
};
}), D = Ue((U) => {
if (U.is0()) {
if (e.allowInfinityPoint && !n.is0(U.Y)) return;
throw new Error("bad point: ZERO");
}
const { x: h, y: d } = U.toAffine();
if (!n.isValid(h) || !n.isValid(d)) throw new Error("bad point: x or y not field elements");
if (!v(h, d)) throw new Error("bad point: equation left != right");
if (!U.isTorsionFree()) throw new Error("bad point: not in prime-order subgroup");
return !0;
});
function N(U, h, d, u, y) {
return d = new O(n.mul(d.X, U), d.Y, d.Z), h = Gt(u, h), d = Gt(y, d), h.add(d);
}
class O {
static BASE = new O(s.Gx, s.Gy, n.ONE);
static ZERO = new O(n.ZERO, n.ONE, n.ZERO);
static Fp = n;
static Fn = o;
X;
Y;
Z;
constructor(h, d, u) {
this.X = L("x", h), this.Y = L("y", d, !0), this.Z = L("z", u), Object.freeze(this);
}
static CURVE() {
return s;
}
static fromAffine(h) {
const { x: d, y: u } = h || {};
if (!h || !n.isValid(d) || !n.isValid(u)) throw new Error("invalid affine point");
if (h instanceof O) throw new Error("projective point not allowed");
return n.is0(d) && n.is0(u) ? O.ZERO : new O(d, u, n.ONE);
}
static fromBytes(h) {
const d = O.fromAffine(m(C(h, void 0, "point")));
return d.assertValidity(), d;
}
static fromHex(h) {
return O.fromBytes(Mt(h));
}
get x() {
return this.toAffine().x;
}
get y() {
return this.toAffine().y;
}
precompute(h = 8, d = !0) {
return F.createCache(this, h), d || this.multiply(St), this;
}
assertValidity() {
D(this);
}
hasEvenY() {
const { y: h } = this.toAffine();
if (!n.isOdd) throw new Error("Field doesn't support isOdd");
return !n.isOdd(h);
}
equals(h) {
I(h);
const { X: d, Y: u, Z: y } = this, { X: _, Y: S, Z: A } = h, p = n.eql(n.mul(d, A), n.mul(_, y)), R = n.eql(n.mul(u, A), n.mul(S, y));