@d9-network/spec 1.1.0 → 1.2.2
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/.papi/descriptors/.gitignore +3 -0
- package/.papi/descriptors/package.json +24 -0
- package/dist/index.cjs +2546 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2545 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -2,16 +2,15 @@ import { t as __export } from "./chunk-7P6ASYW6-kh065yQz.mjs";
|
|
|
2
2
|
import { _Enum } from "polkadot-api";
|
|
3
3
|
import { generateMnemonic as generateMnemonic$1, mnemonicToMiniSecret as mnemonicToMiniSecret$1, ss58Decode, ss58Encode, validateMnemonic as validateMnemonic$1 } from "@polkadot-labs/hdkd-helpers";
|
|
4
4
|
import { sr25519CreateDerive, withNetworkAccount } from "@polkadot-labs/hdkd";
|
|
5
|
-
import { getPolkadotSigner } from "@polkadot-api/signer";
|
|
6
5
|
|
|
7
6
|
//#region ../../node_modules/.bun/@polkadot-api+descriptors@file+packages+spec+.papi+descriptors+ec2463ed5a666297/node_modules/@polkadot-api/descriptors/dist/index.mjs
|
|
8
7
|
var table = new Uint8Array(128);
|
|
9
8
|
for (let i = 0; i < 64; i++) table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
10
|
-
var toBinary = (base64) => {
|
|
11
|
-
const n = base64.length, bytes = new Uint8Array((n - Number(base64[n - 1] === "=") - Number(base64[n - 2] === "=")) * 3 / 4 | 0);
|
|
9
|
+
var toBinary = (base64$1) => {
|
|
10
|
+
const n = base64$1.length, bytes = new Uint8Array((n - Number(base64$1[n - 1] === "=") - Number(base64$1[n - 2] === "=")) * 3 / 4 | 0);
|
|
12
11
|
for (let i2 = 0, j = 0; i2 < n;) {
|
|
13
|
-
const c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
14
|
-
const c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
12
|
+
const c0 = table[base64$1.charCodeAt(i2++)], c1 = table[base64$1.charCodeAt(i2++)];
|
|
13
|
+
const c2 = table[base64$1.charCodeAt(i2++)], c3 = table[base64$1.charCodeAt(i2++)];
|
|
15
14
|
bytes[j++] = c0 << 2 | c1 >> 4;
|
|
16
15
|
bytes[j++] = c1 << 4 | c2 >> 2;
|
|
17
16
|
bytes[j++] = c2 << 6 | c3;
|
|
@@ -7645,17 +7644,17 @@ function isHexString(input) {
|
|
|
7645
7644
|
const s = input.slice(2);
|
|
7646
7645
|
return s.length % 2 === 0 && /^[0-9a-fA-F]+$/.test(s);
|
|
7647
7646
|
}
|
|
7648
|
-
function hexToBytes(hex) {
|
|
7649
|
-
if (!isHexString(hex)) throw new Error("Invalid hex string");
|
|
7650
|
-
const s = hex.slice(2);
|
|
7647
|
+
function hexToBytes(hex$1) {
|
|
7648
|
+
if (!isHexString(hex$1)) throw new Error("Invalid hex string");
|
|
7649
|
+
const s = hex$1.slice(2);
|
|
7651
7650
|
const out = new Uint8Array(s.length / 2);
|
|
7652
7651
|
for (let i = 0; i < out.length; i++) out[i] = Number.parseInt(s.slice(i * 2, i * 2 + 2), 16);
|
|
7653
7652
|
return out;
|
|
7654
7653
|
}
|
|
7655
7654
|
function bytesToHex(bytes) {
|
|
7656
|
-
let hex = "";
|
|
7657
|
-
for (let i = 0; i < bytes.length; i++) hex += bytes[i].toString(16).padStart(2, "0");
|
|
7658
|
-
return `0x${hex}`;
|
|
7655
|
+
let hex$1 = "";
|
|
7656
|
+
for (let i = 0; i < bytes.length; i++) hex$1 += bytes[i].toString(16).padStart(2, "0");
|
|
7657
|
+
return `0x${hex$1}`;
|
|
7659
7658
|
}
|
|
7660
7659
|
|
|
7661
7660
|
//#endregion
|
|
@@ -7698,6 +7697,2535 @@ function sr25519AddressFromSecretKeyHex(secretKeyHex, ss58Format) {
|
|
|
7698
7697
|
return sr25519AddressFromKeypair(sr25519KeypairFromMiniSecret(secretKey), ss58Format);
|
|
7699
7698
|
}
|
|
7700
7699
|
|
|
7700
|
+
//#endregion
|
|
7701
|
+
//#region ../../node_modules/.bun/@polkadot-api+utils@0.2.0/node_modules/@polkadot-api/utils/dist/esm/hex.mjs
|
|
7702
|
+
const HEX_STR = "0123456789abcdef";
|
|
7703
|
+
function toHex(bytes) {
|
|
7704
|
+
const result = new Array(bytes.length + 1);
|
|
7705
|
+
result[0] = "0x";
|
|
7706
|
+
for (let i = 0; i < bytes.length;) {
|
|
7707
|
+
const b = bytes[i++];
|
|
7708
|
+
result[i] = HEX_STR[b >> 4] + HEX_STR[b & 15];
|
|
7709
|
+
}
|
|
7710
|
+
return result.join("");
|
|
7711
|
+
}
|
|
7712
|
+
const HEX_MAP$1 = {
|
|
7713
|
+
0: 0,
|
|
7714
|
+
1: 1,
|
|
7715
|
+
2: 2,
|
|
7716
|
+
3: 3,
|
|
7717
|
+
4: 4,
|
|
7718
|
+
5: 5,
|
|
7719
|
+
6: 6,
|
|
7720
|
+
7: 7,
|
|
7721
|
+
8: 8,
|
|
7722
|
+
9: 9,
|
|
7723
|
+
a: 10,
|
|
7724
|
+
b: 11,
|
|
7725
|
+
c: 12,
|
|
7726
|
+
d: 13,
|
|
7727
|
+
e: 14,
|
|
7728
|
+
f: 15,
|
|
7729
|
+
A: 10,
|
|
7730
|
+
B: 11,
|
|
7731
|
+
C: 12,
|
|
7732
|
+
D: 13,
|
|
7733
|
+
E: 14,
|
|
7734
|
+
F: 15
|
|
7735
|
+
};
|
|
7736
|
+
function fromHex$1(hexString) {
|
|
7737
|
+
const isOdd = hexString.length % 2;
|
|
7738
|
+
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
|
7739
|
+
const nBytes = (hexString.length - base) / 2 + isOdd;
|
|
7740
|
+
const bytes = new Uint8Array(nBytes);
|
|
7741
|
+
if (isOdd) bytes[0] = 0 | HEX_MAP$1[hexString[2]];
|
|
7742
|
+
for (let i = 0; i < nBytes;) {
|
|
7743
|
+
const idx = base + i * 2;
|
|
7744
|
+
const a = HEX_MAP$1[hexString[idx]];
|
|
7745
|
+
const b = HEX_MAP$1[hexString[idx + 1]];
|
|
7746
|
+
bytes[isOdd + i++] = a << 4 | b;
|
|
7747
|
+
}
|
|
7748
|
+
return bytes;
|
|
7749
|
+
}
|
|
7750
|
+
|
|
7751
|
+
//#endregion
|
|
7752
|
+
//#region ../../node_modules/.bun/@polkadot-api+utils@0.2.0/node_modules/@polkadot-api/utils/dist/esm/mergeUint8.mjs
|
|
7753
|
+
const mergeUint8$1 = (...i) => {
|
|
7754
|
+
const inputs = Array.isArray(i[0]) ? i[0] : i;
|
|
7755
|
+
const totalLen = inputs.reduce((acc, a) => acc + a.byteLength, 0);
|
|
7756
|
+
const result = new Uint8Array(totalLen);
|
|
7757
|
+
for (let idx = 0, at = 0; idx < inputs.length; idx++) {
|
|
7758
|
+
const current = inputs[idx];
|
|
7759
|
+
result.set(current, at);
|
|
7760
|
+
at += current.byteLength;
|
|
7761
|
+
}
|
|
7762
|
+
return result;
|
|
7763
|
+
};
|
|
7764
|
+
|
|
7765
|
+
//#endregion
|
|
7766
|
+
//#region ../../node_modules/.bun/scale-ts@1.6.1/node_modules/scale-ts/dist/scale-ts.js
|
|
7767
|
+
var __defProp$1 = Object.defineProperty;
|
|
7768
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
7769
|
+
enumerable: true,
|
|
7770
|
+
configurable: true,
|
|
7771
|
+
writable: true,
|
|
7772
|
+
value
|
|
7773
|
+
}) : obj[key] = value;
|
|
7774
|
+
var __publicField$1 = (obj, key, value) => {
|
|
7775
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7776
|
+
return value;
|
|
7777
|
+
};
|
|
7778
|
+
var HEX_MAP = {
|
|
7779
|
+
0: 0,
|
|
7780
|
+
1: 1,
|
|
7781
|
+
2: 2,
|
|
7782
|
+
3: 3,
|
|
7783
|
+
4: 4,
|
|
7784
|
+
5: 5,
|
|
7785
|
+
6: 6,
|
|
7786
|
+
7: 7,
|
|
7787
|
+
8: 8,
|
|
7788
|
+
9: 9,
|
|
7789
|
+
a: 10,
|
|
7790
|
+
b: 11,
|
|
7791
|
+
c: 12,
|
|
7792
|
+
d: 13,
|
|
7793
|
+
e: 14,
|
|
7794
|
+
f: 15,
|
|
7795
|
+
A: 10,
|
|
7796
|
+
B: 11,
|
|
7797
|
+
C: 12,
|
|
7798
|
+
D: 13,
|
|
7799
|
+
E: 14,
|
|
7800
|
+
F: 15
|
|
7801
|
+
};
|
|
7802
|
+
function fromHex(hexString) {
|
|
7803
|
+
const isOdd = hexString.length % 2;
|
|
7804
|
+
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
|
7805
|
+
const nBytes = (hexString.length - base) / 2 + isOdd;
|
|
7806
|
+
const bytes = new Uint8Array(nBytes);
|
|
7807
|
+
if (isOdd) bytes[0] = 0 | HEX_MAP[hexString[2]];
|
|
7808
|
+
for (let i = 0; i < nBytes;) {
|
|
7809
|
+
const idx = base + i * 2;
|
|
7810
|
+
const a = HEX_MAP[hexString[idx]];
|
|
7811
|
+
const b = HEX_MAP[hexString[idx + 1]];
|
|
7812
|
+
bytes[isOdd + i++] = a << 4 | b;
|
|
7813
|
+
}
|
|
7814
|
+
return bytes;
|
|
7815
|
+
}
|
|
7816
|
+
var InternalUint8Array = class extends Uint8Array {
|
|
7817
|
+
constructor(buffer) {
|
|
7818
|
+
super(buffer);
|
|
7819
|
+
__publicField$1(this, "i", 0);
|
|
7820
|
+
__publicField$1(this, "v");
|
|
7821
|
+
this.v = new DataView(buffer);
|
|
7822
|
+
}
|
|
7823
|
+
};
|
|
7824
|
+
var toInternalBytes = (fn) => (buffer) => fn(buffer instanceof InternalUint8Array ? buffer : new InternalUint8Array(buffer instanceof Uint8Array ? buffer.buffer : typeof buffer === "string" ? fromHex(buffer).buffer : buffer));
|
|
7825
|
+
var mergeUint8 = (inputs) => {
|
|
7826
|
+
const len = inputs.length;
|
|
7827
|
+
let totalLen = 0;
|
|
7828
|
+
for (let i = 0; i < len; i++) totalLen += inputs[i].length;
|
|
7829
|
+
const result = new Uint8Array(totalLen);
|
|
7830
|
+
for (let idx = 0, at = 0; idx < len; idx++) {
|
|
7831
|
+
const current = inputs[idx];
|
|
7832
|
+
result.set(current, at);
|
|
7833
|
+
at += current.byteLength;
|
|
7834
|
+
}
|
|
7835
|
+
return result;
|
|
7836
|
+
};
|
|
7837
|
+
function mapObject(input, mapper) {
|
|
7838
|
+
const keys = Object.keys(input);
|
|
7839
|
+
const len = keys.length;
|
|
7840
|
+
const result = {};
|
|
7841
|
+
for (let i = 0; i < len; i++) {
|
|
7842
|
+
const key = keys[i];
|
|
7843
|
+
result[key] = mapper(input[key], key);
|
|
7844
|
+
}
|
|
7845
|
+
return result;
|
|
7846
|
+
}
|
|
7847
|
+
var createCodec = (encoder, decoder) => {
|
|
7848
|
+
const result = [encoder, decoder];
|
|
7849
|
+
result.enc = encoder;
|
|
7850
|
+
result.dec = decoder;
|
|
7851
|
+
return result;
|
|
7852
|
+
};
|
|
7853
|
+
var enhanceEncoder = (encoder, mapper) => (value) => encoder(mapper(value));
|
|
7854
|
+
var enhanceDecoder = (decoder, mapper) => (value) => mapper(decoder(value));
|
|
7855
|
+
var enhanceCodec = ([encoder, decoder], toFrom, fromTo) => createCodec(enhanceEncoder(encoder, toFrom), enhanceDecoder(decoder, fromTo));
|
|
7856
|
+
function decodeInt(nBytes, getter) {
|
|
7857
|
+
return toInternalBytes((bytes) => {
|
|
7858
|
+
const result = bytes.v[getter](bytes.i, true);
|
|
7859
|
+
bytes.i += nBytes;
|
|
7860
|
+
return result;
|
|
7861
|
+
});
|
|
7862
|
+
}
|
|
7863
|
+
function encodeInt(nBytes, setter) {
|
|
7864
|
+
return (input) => {
|
|
7865
|
+
const result = new Uint8Array(nBytes);
|
|
7866
|
+
new DataView(result.buffer)[setter](0, input, true);
|
|
7867
|
+
return result;
|
|
7868
|
+
};
|
|
7869
|
+
}
|
|
7870
|
+
function intCodec(nBytes, getter, setter) {
|
|
7871
|
+
return createCodec(encodeInt(nBytes, setter), decodeInt(nBytes, getter));
|
|
7872
|
+
}
|
|
7873
|
+
var u8 = intCodec(1, "getUint8", "setUint8");
|
|
7874
|
+
var u16 = intCodec(2, "getUint16", "setUint16");
|
|
7875
|
+
var u32$1 = intCodec(4, "getUint32", "setUint32");
|
|
7876
|
+
var u64 = intCodec(8, "getBigUint64", "setBigUint64");
|
|
7877
|
+
var i8 = intCodec(1, "getInt8", "setInt8");
|
|
7878
|
+
var i16 = intCodec(2, "getInt16", "setInt16");
|
|
7879
|
+
var i32 = intCodec(4, "getInt32", "setInt32");
|
|
7880
|
+
var i64 = intCodec(8, "getBigInt64", "setBigInt64");
|
|
7881
|
+
var x128Enc = (value) => {
|
|
7882
|
+
const result = new Uint8Array(16);
|
|
7883
|
+
const dv = new DataView(result.buffer);
|
|
7884
|
+
dv.setBigInt64(0, value, true);
|
|
7885
|
+
dv.setBigInt64(8, value >> 64n, true);
|
|
7886
|
+
return result;
|
|
7887
|
+
};
|
|
7888
|
+
var create128Dec = (method) => toInternalBytes((input) => {
|
|
7889
|
+
const { v, i } = input;
|
|
7890
|
+
const right = v.getBigUint64(i, true);
|
|
7891
|
+
const left = v[method](i + 8, true);
|
|
7892
|
+
input.i += 16;
|
|
7893
|
+
return left << 64n | right;
|
|
7894
|
+
});
|
|
7895
|
+
var u128 = createCodec(x128Enc, create128Dec("getBigUint64"));
|
|
7896
|
+
var i128 = createCodec(x128Enc, create128Dec("getBigInt64"));
|
|
7897
|
+
var x256Enc = (value) => {
|
|
7898
|
+
const result = new Uint8Array(32);
|
|
7899
|
+
const dv = new DataView(result.buffer);
|
|
7900
|
+
dv.setBigInt64(0, value, true);
|
|
7901
|
+
dv.setBigInt64(8, value >> 64n, true);
|
|
7902
|
+
dv.setBigInt64(16, value >> 128n, true);
|
|
7903
|
+
dv.setBigInt64(24, value >> 192n, true);
|
|
7904
|
+
return result;
|
|
7905
|
+
};
|
|
7906
|
+
var create256Dec = (method) => toInternalBytes((input) => {
|
|
7907
|
+
let result = input.v.getBigUint64(input.i, true);
|
|
7908
|
+
input.i += 8;
|
|
7909
|
+
result |= input.v.getBigUint64(input.i, true) << 64n;
|
|
7910
|
+
input.i += 8;
|
|
7911
|
+
result |= input.v.getBigUint64(input.i, true) << 128n;
|
|
7912
|
+
input.i += 8;
|
|
7913
|
+
result |= input.v[method](input.i, true) << 192n;
|
|
7914
|
+
input.i += 8;
|
|
7915
|
+
return result;
|
|
7916
|
+
});
|
|
7917
|
+
var u256 = createCodec(x256Enc, create256Dec("getBigUint64"));
|
|
7918
|
+
var i256 = createCodec(x256Enc, create256Dec("getBigInt64"));
|
|
7919
|
+
var bool = enhanceCodec(u8, (value) => value ? 1 : 0, Boolean);
|
|
7920
|
+
var decoders = [
|
|
7921
|
+
u8[1],
|
|
7922
|
+
u16[1],
|
|
7923
|
+
u32$1[1]
|
|
7924
|
+
];
|
|
7925
|
+
var compactDec = toInternalBytes((bytes) => {
|
|
7926
|
+
const init = bytes[bytes.i];
|
|
7927
|
+
const kind = init & 3;
|
|
7928
|
+
if (kind < 3) return decoders[kind](bytes) >>> 2;
|
|
7929
|
+
const nBytes = (init >>> 2) + 4;
|
|
7930
|
+
bytes.i++;
|
|
7931
|
+
let result = 0n;
|
|
7932
|
+
const nU64 = nBytes / 8 | 0;
|
|
7933
|
+
let shift = 0n;
|
|
7934
|
+
for (let i = 0; i < nU64; i++) {
|
|
7935
|
+
result = u64[1](bytes) << shift | result;
|
|
7936
|
+
shift += 64n;
|
|
7937
|
+
}
|
|
7938
|
+
let nReminders = nBytes % 8;
|
|
7939
|
+
if (nReminders > 3) {
|
|
7940
|
+
result = BigInt(u32$1[1](bytes)) << shift | result;
|
|
7941
|
+
shift += 32n;
|
|
7942
|
+
nReminders -= 4;
|
|
7943
|
+
}
|
|
7944
|
+
if (nReminders > 1) {
|
|
7945
|
+
result = BigInt(u16[1](bytes)) << shift | result;
|
|
7946
|
+
shift += 16n;
|
|
7947
|
+
nReminders -= 2;
|
|
7948
|
+
}
|
|
7949
|
+
if (nReminders) result = BigInt(u8[1](bytes)) << shift | result;
|
|
7950
|
+
return result;
|
|
7951
|
+
});
|
|
7952
|
+
var MIN_U64 = 1n << 56n;
|
|
7953
|
+
var MIN_U32 = 1 << 24;
|
|
7954
|
+
var MIN_U16 = 256;
|
|
7955
|
+
var U32_MASK = 4294967295n;
|
|
7956
|
+
var SINGLE_BYTE_MODE_LIMIT = 64;
|
|
7957
|
+
var TWO_BYTE_MODE_LIMIT = 16384;
|
|
7958
|
+
var FOUR_BYTE_MODE_LIMIT = 1 << 30;
|
|
7959
|
+
var compactEnc = (input) => {
|
|
7960
|
+
if (input < 0) throw new Error(`Wrong compact input (${input})`);
|
|
7961
|
+
const nInput = Number(input) << 2;
|
|
7962
|
+
if (input < SINGLE_BYTE_MODE_LIMIT) return u8[0](nInput);
|
|
7963
|
+
if (input < TWO_BYTE_MODE_LIMIT) return u16[0](nInput | 1);
|
|
7964
|
+
if (input < FOUR_BYTE_MODE_LIMIT) return u32$1[0](nInput | 2);
|
|
7965
|
+
let buffers = [new Uint8Array(1)];
|
|
7966
|
+
let bigValue = BigInt(input);
|
|
7967
|
+
while (bigValue >= MIN_U64) {
|
|
7968
|
+
buffers.push(u64[0](bigValue));
|
|
7969
|
+
bigValue >>= 64n;
|
|
7970
|
+
}
|
|
7971
|
+
if (bigValue >= MIN_U32) {
|
|
7972
|
+
buffers.push(u32$1[0](Number(bigValue & U32_MASK)));
|
|
7973
|
+
bigValue >>= 32n;
|
|
7974
|
+
}
|
|
7975
|
+
let smValue = Number(bigValue);
|
|
7976
|
+
if (smValue >= MIN_U16) {
|
|
7977
|
+
buffers.push(u16[0](smValue));
|
|
7978
|
+
smValue >>= 16;
|
|
7979
|
+
}
|
|
7980
|
+
smValue && buffers.push(u8[0](smValue));
|
|
7981
|
+
const result = mergeUint8(buffers);
|
|
7982
|
+
result[0] = result.length - 5 << 2 | 3;
|
|
7983
|
+
return result;
|
|
7984
|
+
};
|
|
7985
|
+
var compact = createCodec(compactEnc, compactDec);
|
|
7986
|
+
var textEncoder = new TextEncoder();
|
|
7987
|
+
var strEnc = (str2) => {
|
|
7988
|
+
const val = textEncoder.encode(str2);
|
|
7989
|
+
return mergeUint8([compact.enc(val.length), val]);
|
|
7990
|
+
};
|
|
7991
|
+
var textDecoder = new TextDecoder();
|
|
7992
|
+
var str = createCodec(strEnc, toInternalBytes((bytes) => {
|
|
7993
|
+
let nElements = compact.dec(bytes);
|
|
7994
|
+
const dv = new DataView(bytes.buffer, bytes.i, nElements);
|
|
7995
|
+
bytes.i += nElements;
|
|
7996
|
+
return textDecoder.decode(dv);
|
|
7997
|
+
}));
|
|
7998
|
+
var noop = () => {};
|
|
7999
|
+
var emptyArr = new Uint8Array(0);
|
|
8000
|
+
var _void$1 = createCodec(() => emptyArr, noop);
|
|
8001
|
+
var BytesEnc = (nBytes) => nBytes === void 0 ? (bytes) => mergeUint8([compact.enc(bytes.length), bytes]) : (bytes) => bytes.length === nBytes ? bytes : bytes.slice(0, nBytes);
|
|
8002
|
+
var BytesDec = (nBytes) => toInternalBytes((bytes) => {
|
|
8003
|
+
const len = nBytes === void 0 ? compact.dec(bytes) : nBytes !== Infinity ? nBytes : bytes.byteLength - bytes.i;
|
|
8004
|
+
const result = new Uint8Array(bytes.buffer.slice(bytes.i, bytes.i + len));
|
|
8005
|
+
bytes.i += len;
|
|
8006
|
+
return result;
|
|
8007
|
+
});
|
|
8008
|
+
var Bytes = (nBytes) => createCodec(BytesEnc(nBytes), BytesDec(nBytes));
|
|
8009
|
+
Bytes.enc = BytesEnc;
|
|
8010
|
+
Bytes.dec = BytesDec;
|
|
8011
|
+
var enumEnc = (inner, x) => {
|
|
8012
|
+
const keys = Object.keys(inner);
|
|
8013
|
+
const mappedKeys = new Map(x?.map((actualIdx, idx) => [keys[idx], actualIdx]) ?? keys.map((key, idx) => [key, idx]));
|
|
8014
|
+
const getKey = (key) => mappedKeys.get(key);
|
|
8015
|
+
return ({ tag, value }) => mergeUint8([u8.enc(getKey(tag)), inner[tag](value)]);
|
|
8016
|
+
};
|
|
8017
|
+
var enumDec = (inner, x) => {
|
|
8018
|
+
const keys = Object.keys(inner);
|
|
8019
|
+
const mappedKeys = new Map(x?.map((actualIdx, idx) => [actualIdx, keys[idx]]) ?? keys.map((key, idx) => [idx, key]));
|
|
8020
|
+
return toInternalBytes((bytes) => {
|
|
8021
|
+
const idx = u8.dec(bytes);
|
|
8022
|
+
const tag = mappedKeys.get(idx);
|
|
8023
|
+
const innerDecoder = inner[tag];
|
|
8024
|
+
return {
|
|
8025
|
+
tag,
|
|
8026
|
+
value: innerDecoder(bytes)
|
|
8027
|
+
};
|
|
8028
|
+
});
|
|
8029
|
+
};
|
|
8030
|
+
var Enum$1 = (inner, ...args) => createCodec(enumEnc(mapObject(inner, ([encoder]) => encoder), ...args), enumDec(mapObject(inner, ([, decoder]) => decoder), ...args));
|
|
8031
|
+
Enum$1.enc = enumEnc;
|
|
8032
|
+
Enum$1.dec = enumDec;
|
|
8033
|
+
var OptionDec = (inner) => toInternalBytes((bytes) => u8[1](bytes) > 0 ? inner(bytes) : void 0);
|
|
8034
|
+
var OptionEnc = (inner) => (value) => {
|
|
8035
|
+
const result = new Uint8Array(1);
|
|
8036
|
+
if (value === void 0) return result;
|
|
8037
|
+
result[0] = 1;
|
|
8038
|
+
return mergeUint8([result, inner(value)]);
|
|
8039
|
+
};
|
|
8040
|
+
var Option = (inner) => createCodec(OptionEnc(inner[0]), OptionDec(inner[1]));
|
|
8041
|
+
Option.enc = OptionEnc;
|
|
8042
|
+
Option.dec = OptionDec;
|
|
8043
|
+
var ResultDec = (okDecoder, koDecoder) => toInternalBytes((bytes) => {
|
|
8044
|
+
const success = u8[1](bytes) === 0;
|
|
8045
|
+
return {
|
|
8046
|
+
success,
|
|
8047
|
+
value: (success ? okDecoder : koDecoder)(bytes)
|
|
8048
|
+
};
|
|
8049
|
+
});
|
|
8050
|
+
var ResultEnc = (okEncoder, koEncoder) => ({ success, value }) => mergeUint8([u8[0](success ? 0 : 1), (success ? okEncoder : koEncoder)(value)]);
|
|
8051
|
+
var Result = (okCodec, koCodec) => createCodec(ResultEnc(okCodec[0], koCodec[0]), ResultDec(okCodec[1], koCodec[1]));
|
|
8052
|
+
Result.dec = ResultDec;
|
|
8053
|
+
Result.enc = ResultEnc;
|
|
8054
|
+
var TupleDec = (...decoders2) => toInternalBytes((bytes) => decoders2.map((decoder) => decoder(bytes)));
|
|
8055
|
+
var TupleEnc = (...encoders) => (values) => mergeUint8(encoders.map((enc, idx) => enc(values[idx])));
|
|
8056
|
+
var Tuple = (...codecs) => createCodec(TupleEnc(...codecs.map(([encoder]) => encoder)), TupleDec(...codecs.map(([, decoder]) => decoder)));
|
|
8057
|
+
Tuple.enc = TupleEnc;
|
|
8058
|
+
Tuple.dec = TupleDec;
|
|
8059
|
+
var StructEnc = (encoders) => {
|
|
8060
|
+
const keys = Object.keys(encoders);
|
|
8061
|
+
return enhanceEncoder(Tuple.enc(...Object.values(encoders)), (input) => keys.map((k) => input[k]));
|
|
8062
|
+
};
|
|
8063
|
+
var StructDec = (decoders2) => {
|
|
8064
|
+
const keys = Object.keys(decoders2);
|
|
8065
|
+
return enhanceDecoder(Tuple.dec(...Object.values(decoders2)), (tuple) => Object.fromEntries(tuple.map((value, idx) => [keys[idx], value])));
|
|
8066
|
+
};
|
|
8067
|
+
var Struct = (codecs) => createCodec(StructEnc(mapObject(codecs, (x) => x[0])), StructDec(mapObject(codecs, (x) => x[1])));
|
|
8068
|
+
Struct.enc = StructEnc;
|
|
8069
|
+
Struct.dec = StructDec;
|
|
8070
|
+
var VectorEnc = (inner, size) => size >= 0 ? (value) => mergeUint8(value.map(inner)) : (value) => mergeUint8([compact.enc(value.length), mergeUint8(value.map(inner))]);
|
|
8071
|
+
var VectorDec = (getter, size) => toInternalBytes((bytes) => {
|
|
8072
|
+
const nElements = size >= 0 ? size : compact.dec(bytes);
|
|
8073
|
+
const result = new Array(nElements);
|
|
8074
|
+
for (let i = 0; i < nElements; i++) result[i] = getter(bytes);
|
|
8075
|
+
return result;
|
|
8076
|
+
});
|
|
8077
|
+
var Vector = (inner, size) => createCodec(VectorEnc(inner[0], size), VectorDec(inner[1], size));
|
|
8078
|
+
Vector.enc = VectorEnc;
|
|
8079
|
+
Vector.dec = VectorDec;
|
|
8080
|
+
|
|
8081
|
+
//#endregion
|
|
8082
|
+
//#region ../../node_modules/.bun/@scure+base@2.0.0/node_modules/@scure/base/index.js
|
|
8083
|
+
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8084
|
+
function isBytes$2(a) {
|
|
8085
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
8086
|
+
}
|
|
8087
|
+
/** Asserts something is Uint8Array. */
|
|
8088
|
+
function abytes$1(b) {
|
|
8089
|
+
if (!isBytes$2(b)) throw new Error("Uint8Array expected");
|
|
8090
|
+
}
|
|
8091
|
+
function isArrayOf(isString, arr$1) {
|
|
8092
|
+
if (!Array.isArray(arr$1)) return false;
|
|
8093
|
+
if (arr$1.length === 0) return true;
|
|
8094
|
+
if (isString) return arr$1.every((item) => typeof item === "string");
|
|
8095
|
+
else return arr$1.every((item) => Number.isSafeInteger(item));
|
|
8096
|
+
}
|
|
8097
|
+
function afn(input) {
|
|
8098
|
+
if (typeof input !== "function") throw new Error("function expected");
|
|
8099
|
+
return true;
|
|
8100
|
+
}
|
|
8101
|
+
function astr(label, input) {
|
|
8102
|
+
if (typeof input !== "string") throw new Error(`${label}: string expected`);
|
|
8103
|
+
return true;
|
|
8104
|
+
}
|
|
8105
|
+
function anumber$1(n) {
|
|
8106
|
+
if (!Number.isSafeInteger(n)) throw new Error(`invalid integer: ${n}`);
|
|
8107
|
+
}
|
|
8108
|
+
function aArr(input) {
|
|
8109
|
+
if (!Array.isArray(input)) throw new Error("array expected");
|
|
8110
|
+
}
|
|
8111
|
+
function astrArr(label, input) {
|
|
8112
|
+
if (!isArrayOf(true, input)) throw new Error(`${label}: array of strings expected`);
|
|
8113
|
+
}
|
|
8114
|
+
function anumArr(label, input) {
|
|
8115
|
+
if (!isArrayOf(false, input)) throw new Error(`${label}: array of numbers expected`);
|
|
8116
|
+
}
|
|
8117
|
+
/**
|
|
8118
|
+
* @__NO_SIDE_EFFECTS__
|
|
8119
|
+
*/
|
|
8120
|
+
function chain(...args) {
|
|
8121
|
+
const id = (a) => a;
|
|
8122
|
+
const wrap = (a, b) => (c) => a(b(c));
|
|
8123
|
+
return {
|
|
8124
|
+
encode: args.map((x) => x.encode).reduceRight(wrap, id),
|
|
8125
|
+
decode: args.map((x) => x.decode).reduce(wrap, id)
|
|
8126
|
+
};
|
|
8127
|
+
}
|
|
8128
|
+
/**
|
|
8129
|
+
* Encodes integer radix representation to array of strings using alphabet and back.
|
|
8130
|
+
* Could also be array of strings.
|
|
8131
|
+
* @__NO_SIDE_EFFECTS__
|
|
8132
|
+
*/
|
|
8133
|
+
function alphabet(letters) {
|
|
8134
|
+
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
8135
|
+
const len = lettersA.length;
|
|
8136
|
+
astrArr("alphabet", lettersA);
|
|
8137
|
+
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
8138
|
+
return {
|
|
8139
|
+
encode: (digits) => {
|
|
8140
|
+
aArr(digits);
|
|
8141
|
+
return digits.map((i) => {
|
|
8142
|
+
if (!Number.isSafeInteger(i) || i < 0 || i >= len) throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
8143
|
+
return lettersA[i];
|
|
8144
|
+
});
|
|
8145
|
+
},
|
|
8146
|
+
decode: (input) => {
|
|
8147
|
+
aArr(input);
|
|
8148
|
+
return input.map((letter) => {
|
|
8149
|
+
astr("alphabet.decode", letter);
|
|
8150
|
+
const i = indexes.get(letter);
|
|
8151
|
+
if (i === void 0) throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
8152
|
+
return i;
|
|
8153
|
+
});
|
|
8154
|
+
}
|
|
8155
|
+
};
|
|
8156
|
+
}
|
|
8157
|
+
/**
|
|
8158
|
+
* @__NO_SIDE_EFFECTS__
|
|
8159
|
+
*/
|
|
8160
|
+
function join(separator = "") {
|
|
8161
|
+
astr("join", separator);
|
|
8162
|
+
return {
|
|
8163
|
+
encode: (from) => {
|
|
8164
|
+
astrArr("join.decode", from);
|
|
8165
|
+
return from.join(separator);
|
|
8166
|
+
},
|
|
8167
|
+
decode: (to) => {
|
|
8168
|
+
astr("join.decode", to);
|
|
8169
|
+
return to.split(separator);
|
|
8170
|
+
}
|
|
8171
|
+
};
|
|
8172
|
+
}
|
|
8173
|
+
/**
|
|
8174
|
+
* Pad strings array so it has integer number of bits
|
|
8175
|
+
* @__NO_SIDE_EFFECTS__
|
|
8176
|
+
*/
|
|
8177
|
+
function padding(bits, chr = "=") {
|
|
8178
|
+
anumber$1(bits);
|
|
8179
|
+
astr("padding", chr);
|
|
8180
|
+
return {
|
|
8181
|
+
encode(data) {
|
|
8182
|
+
astrArr("padding.encode", data);
|
|
8183
|
+
while (data.length * bits % 8) data.push(chr);
|
|
8184
|
+
return data;
|
|
8185
|
+
},
|
|
8186
|
+
decode(input) {
|
|
8187
|
+
astrArr("padding.decode", input);
|
|
8188
|
+
let end = input.length;
|
|
8189
|
+
if (end * bits % 8) throw new Error("padding: invalid, string should have whole number of bytes");
|
|
8190
|
+
for (; end > 0 && input[end - 1] === chr; end--) if ((end - 1) * bits % 8 === 0) throw new Error("padding: invalid, string has too much padding");
|
|
8191
|
+
return input.slice(0, end);
|
|
8192
|
+
}
|
|
8193
|
+
};
|
|
8194
|
+
}
|
|
8195
|
+
/**
|
|
8196
|
+
* @__NO_SIDE_EFFECTS__
|
|
8197
|
+
*/
|
|
8198
|
+
function normalize(fn) {
|
|
8199
|
+
afn(fn);
|
|
8200
|
+
return {
|
|
8201
|
+
encode: (from) => from,
|
|
8202
|
+
decode: (to) => fn(to)
|
|
8203
|
+
};
|
|
8204
|
+
}
|
|
8205
|
+
/**
|
|
8206
|
+
* Slow: O(n^2) time complexity
|
|
8207
|
+
*/
|
|
8208
|
+
function convertRadix(data, from, to) {
|
|
8209
|
+
if (from < 2) throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
8210
|
+
if (to < 2) throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
8211
|
+
aArr(data);
|
|
8212
|
+
if (!data.length) return [];
|
|
8213
|
+
let pos = 0;
|
|
8214
|
+
const res = [];
|
|
8215
|
+
const digits = Array.from(data, (d) => {
|
|
8216
|
+
anumber$1(d);
|
|
8217
|
+
if (d < 0 || d >= from) throw new Error(`invalid integer: ${d}`);
|
|
8218
|
+
return d;
|
|
8219
|
+
});
|
|
8220
|
+
const dlen = digits.length;
|
|
8221
|
+
while (true) {
|
|
8222
|
+
let carry = 0;
|
|
8223
|
+
let done = true;
|
|
8224
|
+
for (let i = pos; i < dlen; i++) {
|
|
8225
|
+
const digit = digits[i];
|
|
8226
|
+
const fromCarry = from * carry;
|
|
8227
|
+
const digitBase = fromCarry + digit;
|
|
8228
|
+
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) throw new Error("convertRadix: carry overflow");
|
|
8229
|
+
const div = digitBase / to;
|
|
8230
|
+
carry = digitBase % to;
|
|
8231
|
+
const rounded = Math.floor(div);
|
|
8232
|
+
digits[i] = rounded;
|
|
8233
|
+
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase) throw new Error("convertRadix: carry overflow");
|
|
8234
|
+
if (!done) continue;
|
|
8235
|
+
else if (!rounded) pos = i;
|
|
8236
|
+
else done = false;
|
|
8237
|
+
}
|
|
8238
|
+
res.push(carry);
|
|
8239
|
+
if (done) break;
|
|
8240
|
+
}
|
|
8241
|
+
for (let i = 0; i < data.length - 1 && data[i] === 0; i++) res.push(0);
|
|
8242
|
+
return res.reverse();
|
|
8243
|
+
}
|
|
8244
|
+
const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
8245
|
+
const radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
8246
|
+
const powers = /* @__PURE__ */ (() => {
|
|
8247
|
+
let res = [];
|
|
8248
|
+
for (let i = 0; i < 40; i++) res.push(2 ** i);
|
|
8249
|
+
return res;
|
|
8250
|
+
})();
|
|
8251
|
+
/**
|
|
8252
|
+
* Implemented with numbers, because BigInt is 5x slower
|
|
8253
|
+
*/
|
|
8254
|
+
function convertRadix2(data, from, to, padding$1) {
|
|
8255
|
+
aArr(data);
|
|
8256
|
+
if (from <= 0 || from > 32) throw new Error(`convertRadix2: wrong from=${from}`);
|
|
8257
|
+
if (to <= 0 || to > 32) throw new Error(`convertRadix2: wrong to=${to}`);
|
|
8258
|
+
if (/* @__PURE__ */ radix2carry(from, to) > 32) throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
|
8259
|
+
let carry = 0;
|
|
8260
|
+
let pos = 0;
|
|
8261
|
+
const max = powers[from];
|
|
8262
|
+
const mask = powers[to] - 1;
|
|
8263
|
+
const res = [];
|
|
8264
|
+
for (const n of data) {
|
|
8265
|
+
anumber$1(n);
|
|
8266
|
+
if (n >= max) throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
8267
|
+
carry = carry << from | n;
|
|
8268
|
+
if (pos + from > 32) throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
|
8269
|
+
pos += from;
|
|
8270
|
+
for (; pos >= to; pos -= to) res.push((carry >> pos - to & mask) >>> 0);
|
|
8271
|
+
const pow = powers[pos];
|
|
8272
|
+
if (pow === void 0) throw new Error("invalid carry");
|
|
8273
|
+
carry &= pow - 1;
|
|
8274
|
+
}
|
|
8275
|
+
carry = carry << to - pos & mask;
|
|
8276
|
+
if (!padding$1 && pos >= from) throw new Error("Excess padding");
|
|
8277
|
+
if (!padding$1 && carry > 0) throw new Error(`Non-zero padding: ${carry}`);
|
|
8278
|
+
if (padding$1 && pos > 0) res.push(carry >>> 0);
|
|
8279
|
+
return res;
|
|
8280
|
+
}
|
|
8281
|
+
/**
|
|
8282
|
+
* @__NO_SIDE_EFFECTS__
|
|
8283
|
+
*/
|
|
8284
|
+
function radix(num) {
|
|
8285
|
+
anumber$1(num);
|
|
8286
|
+
const _256 = 2 ** 8;
|
|
8287
|
+
return {
|
|
8288
|
+
encode: (bytes) => {
|
|
8289
|
+
if (!isBytes$2(bytes)) throw new Error("radix.encode input should be Uint8Array");
|
|
8290
|
+
return convertRadix(Array.from(bytes), _256, num);
|
|
8291
|
+
},
|
|
8292
|
+
decode: (digits) => {
|
|
8293
|
+
anumArr("radix.decode", digits);
|
|
8294
|
+
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
8295
|
+
}
|
|
8296
|
+
};
|
|
8297
|
+
}
|
|
8298
|
+
/**
|
|
8299
|
+
* If both bases are power of same number (like `2**8 <-> 2**64`),
|
|
8300
|
+
* there is a linear algorithm. For now we have implementation for power-of-two bases only.
|
|
8301
|
+
* @__NO_SIDE_EFFECTS__
|
|
8302
|
+
*/
|
|
8303
|
+
function radix2(bits, revPadding = false) {
|
|
8304
|
+
anumber$1(bits);
|
|
8305
|
+
if (bits <= 0 || bits > 32) throw new Error("radix2: bits should be in (0..32]");
|
|
8306
|
+
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32) throw new Error("radix2: carry overflow");
|
|
8307
|
+
return {
|
|
8308
|
+
encode: (bytes) => {
|
|
8309
|
+
if (!isBytes$2(bytes)) throw new Error("radix2.encode input should be Uint8Array");
|
|
8310
|
+
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
8311
|
+
},
|
|
8312
|
+
decode: (digits) => {
|
|
8313
|
+
anumArr("radix2.decode", digits);
|
|
8314
|
+
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
8315
|
+
}
|
|
8316
|
+
};
|
|
8317
|
+
}
|
|
8318
|
+
function unsafeWrapper(fn) {
|
|
8319
|
+
afn(fn);
|
|
8320
|
+
return function(...args) {
|
|
8321
|
+
try {
|
|
8322
|
+
return fn.apply(null, args);
|
|
8323
|
+
} catch (e) {}
|
|
8324
|
+
};
|
|
8325
|
+
}
|
|
8326
|
+
/**
|
|
8327
|
+
* base16 encoding from RFC 4648.
|
|
8328
|
+
* @example
|
|
8329
|
+
* ```js
|
|
8330
|
+
* base16.encode(Uint8Array.from([0x12, 0xab]));
|
|
8331
|
+
* // => '12AB'
|
|
8332
|
+
* ```
|
|
8333
|
+
*/
|
|
8334
|
+
const base16 = chain(radix2(4), alphabet("0123456789ABCDEF"), join(""));
|
|
8335
|
+
/**
|
|
8336
|
+
* base32 encoding from RFC 4648. Has padding.
|
|
8337
|
+
* Use `base32nopad` for unpadded version.
|
|
8338
|
+
* Also check out `base32hex`, `base32hexnopad`, `base32crockford`.
|
|
8339
|
+
* @example
|
|
8340
|
+
* ```js
|
|
8341
|
+
* base32.encode(Uint8Array.from([0x12, 0xab]));
|
|
8342
|
+
* // => 'CKVQ===='
|
|
8343
|
+
* base32.decode('CKVQ====');
|
|
8344
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8345
|
+
* ```
|
|
8346
|
+
*/
|
|
8347
|
+
const base32 = chain(radix2(5), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), padding(5), join(""));
|
|
8348
|
+
/**
|
|
8349
|
+
* base32 encoding from RFC 4648. No padding.
|
|
8350
|
+
* Use `base32` for padded version.
|
|
8351
|
+
* Also check out `base32hex`, `base32hexnopad`, `base32crockford`.
|
|
8352
|
+
* @example
|
|
8353
|
+
* ```js
|
|
8354
|
+
* base32nopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
8355
|
+
* // => 'CKVQ'
|
|
8356
|
+
* base32nopad.decode('CKVQ');
|
|
8357
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8358
|
+
* ```
|
|
8359
|
+
*/
|
|
8360
|
+
const base32nopad = chain(radix2(5), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), join(""));
|
|
8361
|
+
/**
|
|
8362
|
+
* base32 encoding from RFC 4648. Padded. Compared to ordinary `base32`, slightly different alphabet.
|
|
8363
|
+
* Use `base32hexnopad` for unpadded version.
|
|
8364
|
+
* @example
|
|
8365
|
+
* ```js
|
|
8366
|
+
* base32hex.encode(Uint8Array.from([0x12, 0xab]));
|
|
8367
|
+
* // => '2ALG===='
|
|
8368
|
+
* base32hex.decode('2ALG====');
|
|
8369
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8370
|
+
* ```
|
|
8371
|
+
*/
|
|
8372
|
+
const base32hex = chain(radix2(5), alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), padding(5), join(""));
|
|
8373
|
+
/**
|
|
8374
|
+
* base32 encoding from RFC 4648. No padding. Compared to ordinary `base32`, slightly different alphabet.
|
|
8375
|
+
* Use `base32hex` for padded version.
|
|
8376
|
+
* @example
|
|
8377
|
+
* ```js
|
|
8378
|
+
* base32hexnopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
8379
|
+
* // => '2ALG'
|
|
8380
|
+
* base32hexnopad.decode('2ALG');
|
|
8381
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8382
|
+
* ```
|
|
8383
|
+
*/
|
|
8384
|
+
const base32hexnopad = chain(radix2(5), alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), join(""));
|
|
8385
|
+
/**
|
|
8386
|
+
* base32 encoding from RFC 4648. Doug Crockford's version.
|
|
8387
|
+
* https://www.crockford.com/base32.html
|
|
8388
|
+
* @example
|
|
8389
|
+
* ```js
|
|
8390
|
+
* base32crockford.encode(Uint8Array.from([0x12, 0xab]));
|
|
8391
|
+
* // => '2ANG'
|
|
8392
|
+
* base32crockford.decode('2ANG');
|
|
8393
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8394
|
+
* ```
|
|
8395
|
+
*/
|
|
8396
|
+
const base32crockford = chain(radix2(5), alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), join(""), normalize((s) => s.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
8397
|
+
const hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
|
|
8398
|
+
const decodeBase64Builtin = (s, isUrl) => {
|
|
8399
|
+
astr("base64", s);
|
|
8400
|
+
const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
|
|
8401
|
+
const alphabet$1 = isUrl ? "base64url" : "base64";
|
|
8402
|
+
if (s.length > 0 && !re.test(s)) throw new Error("invalid base64");
|
|
8403
|
+
return Uint8Array.fromBase64(s, {
|
|
8404
|
+
alphabet: alphabet$1,
|
|
8405
|
+
lastChunkHandling: "strict"
|
|
8406
|
+
});
|
|
8407
|
+
};
|
|
8408
|
+
/**
|
|
8409
|
+
* base64 from RFC 4648. Padded.
|
|
8410
|
+
* Use `base64nopad` for unpadded version.
|
|
8411
|
+
* Also check out `base64url`, `base64urlnopad`.
|
|
8412
|
+
* Falls back to built-in function, when available.
|
|
8413
|
+
* @example
|
|
8414
|
+
* ```js
|
|
8415
|
+
* base64.encode(Uint8Array.from([0x12, 0xab]));
|
|
8416
|
+
* // => 'Eqs='
|
|
8417
|
+
* base64.decode('Eqs=');
|
|
8418
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8419
|
+
* ```
|
|
8420
|
+
*/
|
|
8421
|
+
const base64 = hasBase64Builtin ? {
|
|
8422
|
+
encode(b) {
|
|
8423
|
+
abytes$1(b);
|
|
8424
|
+
return b.toBase64();
|
|
8425
|
+
},
|
|
8426
|
+
decode(s) {
|
|
8427
|
+
return decodeBase64Builtin(s, false);
|
|
8428
|
+
}
|
|
8429
|
+
} : chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), padding(6), join(""));
|
|
8430
|
+
/**
|
|
8431
|
+
* base64 from RFC 4648. No padding.
|
|
8432
|
+
* Use `base64` for padded version.
|
|
8433
|
+
* @example
|
|
8434
|
+
* ```js
|
|
8435
|
+
* base64nopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
8436
|
+
* // => 'Eqs'
|
|
8437
|
+
* base64nopad.decode('Eqs');
|
|
8438
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8439
|
+
* ```
|
|
8440
|
+
*/
|
|
8441
|
+
const base64nopad = chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), join(""));
|
|
8442
|
+
/**
|
|
8443
|
+
* base64 from RFC 4648, using URL-safe alphabet. Padded.
|
|
8444
|
+
* Use `base64urlnopad` for unpadded version.
|
|
8445
|
+
* Falls back to built-in function, when available.
|
|
8446
|
+
* @example
|
|
8447
|
+
* ```js
|
|
8448
|
+
* base64url.encode(Uint8Array.from([0x12, 0xab]));
|
|
8449
|
+
* // => 'Eqs='
|
|
8450
|
+
* base64url.decode('Eqs=');
|
|
8451
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8452
|
+
* ```
|
|
8453
|
+
*/
|
|
8454
|
+
const base64url = hasBase64Builtin ? {
|
|
8455
|
+
encode(b) {
|
|
8456
|
+
abytes$1(b);
|
|
8457
|
+
return b.toBase64({ alphabet: "base64url" });
|
|
8458
|
+
},
|
|
8459
|
+
decode(s) {
|
|
8460
|
+
return decodeBase64Builtin(s, true);
|
|
8461
|
+
}
|
|
8462
|
+
} : chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), padding(6), join(""));
|
|
8463
|
+
/**
|
|
8464
|
+
* base64 from RFC 4648, using URL-safe alphabet. No padding.
|
|
8465
|
+
* Use `base64url` for padded version.
|
|
8466
|
+
* @example
|
|
8467
|
+
* ```js
|
|
8468
|
+
* base64urlnopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
8469
|
+
* // => 'Eqs'
|
|
8470
|
+
* base64urlnopad.decode('Eqs');
|
|
8471
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
8472
|
+
* ```
|
|
8473
|
+
*/
|
|
8474
|
+
const base64urlnopad = chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), join(""));
|
|
8475
|
+
const genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => chain(radix(58), alphabet(abc), join(""));
|
|
8476
|
+
/**
|
|
8477
|
+
* base58: base64 without ambigous characters +, /, 0, O, I, l.
|
|
8478
|
+
* Quadratic (O(n^2)) - so, can't be used on large inputs.
|
|
8479
|
+
* @example
|
|
8480
|
+
* ```js
|
|
8481
|
+
* base58.decode('01abcdef');
|
|
8482
|
+
* // => '3UhJW'
|
|
8483
|
+
* ```
|
|
8484
|
+
*/
|
|
8485
|
+
const base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
8486
|
+
const BECH_ALPHABET = chain(alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), join(""));
|
|
8487
|
+
const POLYMOD_GENERATORS = [
|
|
8488
|
+
996825010,
|
|
8489
|
+
642813549,
|
|
8490
|
+
513874426,
|
|
8491
|
+
1027748829,
|
|
8492
|
+
705979059
|
|
8493
|
+
];
|
|
8494
|
+
function bech32Polymod(pre) {
|
|
8495
|
+
const b = pre >> 25;
|
|
8496
|
+
let chk = (pre & 33554431) << 5;
|
|
8497
|
+
for (let i = 0; i < POLYMOD_GENERATORS.length; i++) if ((b >> i & 1) === 1) chk ^= POLYMOD_GENERATORS[i];
|
|
8498
|
+
return chk;
|
|
8499
|
+
}
|
|
8500
|
+
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
8501
|
+
const len = prefix.length;
|
|
8502
|
+
let chk = 1;
|
|
8503
|
+
for (let i = 0; i < len; i++) {
|
|
8504
|
+
const c = prefix.charCodeAt(i);
|
|
8505
|
+
if (c < 33 || c > 126) throw new Error(`Invalid prefix (${prefix})`);
|
|
8506
|
+
chk = bech32Polymod(chk) ^ c >> 5;
|
|
8507
|
+
}
|
|
8508
|
+
chk = bech32Polymod(chk);
|
|
8509
|
+
for (let i = 0; i < len; i++) chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
8510
|
+
for (let v of words) chk = bech32Polymod(chk) ^ v;
|
|
8511
|
+
for (let i = 0; i < 6; i++) chk = bech32Polymod(chk);
|
|
8512
|
+
chk ^= encodingConst;
|
|
8513
|
+
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
8514
|
+
}
|
|
8515
|
+
/**
|
|
8516
|
+
* @__NO_SIDE_EFFECTS__
|
|
8517
|
+
*/
|
|
8518
|
+
function genBech32(encoding) {
|
|
8519
|
+
const ENCODING_CONST = encoding === "bech32" ? 1 : 734539939;
|
|
8520
|
+
const _words = radix2(5);
|
|
8521
|
+
const fromWords = _words.decode;
|
|
8522
|
+
const toWords = _words.encode;
|
|
8523
|
+
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
8524
|
+
function encode(prefix, words, limit = 90) {
|
|
8525
|
+
astr("bech32.encode prefix", prefix);
|
|
8526
|
+
if (isBytes$2(words)) words = Array.from(words);
|
|
8527
|
+
anumArr("bech32.encode", words);
|
|
8528
|
+
const plen = prefix.length;
|
|
8529
|
+
if (plen === 0) throw new TypeError(`Invalid prefix length ${plen}`);
|
|
8530
|
+
const actualLength = plen + 7 + words.length;
|
|
8531
|
+
if (limit !== false && actualLength > limit) throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
8532
|
+
const lowered = prefix.toLowerCase();
|
|
8533
|
+
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
8534
|
+
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
8535
|
+
}
|
|
8536
|
+
function decode(str$1, limit = 90) {
|
|
8537
|
+
astr("bech32.decode input", str$1);
|
|
8538
|
+
const slen = str$1.length;
|
|
8539
|
+
if (slen < 8 || limit !== false && slen > limit) throw new TypeError(`invalid string length: ${slen} (${str$1}). Expected (8..${limit})`);
|
|
8540
|
+
const lowered = str$1.toLowerCase();
|
|
8541
|
+
if (str$1 !== lowered && str$1 !== str$1.toUpperCase()) throw new Error(`String must be lowercase or uppercase`);
|
|
8542
|
+
const sepIndex = lowered.lastIndexOf("1");
|
|
8543
|
+
if (sepIndex === 0 || sepIndex === -1) throw new Error(`Letter "1" must be present between prefix and data only`);
|
|
8544
|
+
const prefix = lowered.slice(0, sepIndex);
|
|
8545
|
+
const data = lowered.slice(sepIndex + 1);
|
|
8546
|
+
if (data.length < 6) throw new Error("Data must be at least 6 characters long");
|
|
8547
|
+
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
8548
|
+
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
8549
|
+
if (!data.endsWith(sum)) throw new Error(`Invalid checksum in ${str$1}: expected "${sum}"`);
|
|
8550
|
+
return {
|
|
8551
|
+
prefix,
|
|
8552
|
+
words
|
|
8553
|
+
};
|
|
8554
|
+
}
|
|
8555
|
+
const decodeUnsafe = unsafeWrapper(decode);
|
|
8556
|
+
function decodeToBytes(str$1) {
|
|
8557
|
+
const { prefix, words } = decode(str$1, false);
|
|
8558
|
+
return {
|
|
8559
|
+
prefix,
|
|
8560
|
+
words,
|
|
8561
|
+
bytes: fromWords(words)
|
|
8562
|
+
};
|
|
8563
|
+
}
|
|
8564
|
+
function encodeFromBytes(prefix, bytes) {
|
|
8565
|
+
return encode(prefix, toWords(bytes));
|
|
8566
|
+
}
|
|
8567
|
+
return {
|
|
8568
|
+
encode,
|
|
8569
|
+
decode,
|
|
8570
|
+
encodeFromBytes,
|
|
8571
|
+
decodeToBytes,
|
|
8572
|
+
decodeUnsafe,
|
|
8573
|
+
fromWords,
|
|
8574
|
+
fromWordsUnsafe,
|
|
8575
|
+
toWords
|
|
8576
|
+
};
|
|
8577
|
+
}
|
|
8578
|
+
/**
|
|
8579
|
+
* bech32 from BIP 173. Operates on words.
|
|
8580
|
+
* For high-level, check out scure-btc-signer:
|
|
8581
|
+
* https://github.com/paulmillr/scure-btc-signer.
|
|
8582
|
+
*/
|
|
8583
|
+
const bech32 = genBech32("bech32");
|
|
8584
|
+
/**
|
|
8585
|
+
* bech32m from BIP 350. Operates on words.
|
|
8586
|
+
* It was to mitigate `bech32` weaknesses.
|
|
8587
|
+
* For high-level, check out scure-btc-signer:
|
|
8588
|
+
* https://github.com/paulmillr/scure-btc-signer.
|
|
8589
|
+
*/
|
|
8590
|
+
const bech32m = genBech32("bech32m");
|
|
8591
|
+
const hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
|
|
8592
|
+
const hexBuiltin = {
|
|
8593
|
+
encode(data) {
|
|
8594
|
+
abytes$1(data);
|
|
8595
|
+
return data.toHex();
|
|
8596
|
+
},
|
|
8597
|
+
decode(s) {
|
|
8598
|
+
astr("hex", s);
|
|
8599
|
+
return Uint8Array.fromHex(s);
|
|
8600
|
+
}
|
|
8601
|
+
};
|
|
8602
|
+
/**
|
|
8603
|
+
* hex string decoder. Uses built-in function, when available.
|
|
8604
|
+
* @example
|
|
8605
|
+
* ```js
|
|
8606
|
+
* const b = hex.decode("0102ff"); // => new Uint8Array([ 1, 2, 255 ])
|
|
8607
|
+
* const str = hex.encode(b); // "0102ff"
|
|
8608
|
+
* ```
|
|
8609
|
+
*/
|
|
8610
|
+
const hex = hasHexBuiltin ? hexBuiltin : chain(radix2(4), alphabet("0123456789abcdef"), join(""), normalize((s) => {
|
|
8611
|
+
if (typeof s !== "string" || s.length % 2 !== 0) throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`);
|
|
8612
|
+
return s.toLowerCase();
|
|
8613
|
+
}));
|
|
8614
|
+
|
|
8615
|
+
//#endregion
|
|
8616
|
+
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
|
|
8617
|
+
/**
|
|
8618
|
+
* Utilities for hex, bytes, CSPRNG.
|
|
8619
|
+
* @module
|
|
8620
|
+
*/
|
|
8621
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8622
|
+
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
8623
|
+
function isBytes$1(a) {
|
|
8624
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
8625
|
+
}
|
|
8626
|
+
/** Asserts something is positive integer. */
|
|
8627
|
+
function anumber(n, title = "") {
|
|
8628
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
8629
|
+
const prefix = title && `"${title}" `;
|
|
8630
|
+
throw new Error(`${prefix}expected integer >= 0, got ${n}`);
|
|
8631
|
+
}
|
|
8632
|
+
}
|
|
8633
|
+
/** Asserts something is Uint8Array. */
|
|
8634
|
+
function abytes(value, length, title = "") {
|
|
8635
|
+
const bytes = isBytes$1(value);
|
|
8636
|
+
const len = value?.length;
|
|
8637
|
+
const needsLen = length !== void 0;
|
|
8638
|
+
if (!bytes || needsLen && len !== length) {
|
|
8639
|
+
const prefix = title && `"${title}" `;
|
|
8640
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
8641
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
8642
|
+
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
8643
|
+
}
|
|
8644
|
+
return value;
|
|
8645
|
+
}
|
|
8646
|
+
/** Asserts a hash instance has not been destroyed / finished */
|
|
8647
|
+
function aexists(instance, checkFinished = true) {
|
|
8648
|
+
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
8649
|
+
if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
|
|
8650
|
+
}
|
|
8651
|
+
/** Asserts output is properly-sized byte array */
|
|
8652
|
+
function aoutput(out, instance) {
|
|
8653
|
+
abytes(out, void 0, "digestInto() output");
|
|
8654
|
+
const min = instance.outputLen;
|
|
8655
|
+
if (out.length < min) throw new Error("\"digestInto() output\" expected to be of length >=" + min);
|
|
8656
|
+
}
|
|
8657
|
+
/** Cast u8 / u16 / u32 to u32. */
|
|
8658
|
+
function u32(arr$1) {
|
|
8659
|
+
return new Uint32Array(arr$1.buffer, arr$1.byteOffset, Math.floor(arr$1.byteLength / 4));
|
|
8660
|
+
}
|
|
8661
|
+
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
8662
|
+
function clean(...arrays) {
|
|
8663
|
+
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
8664
|
+
}
|
|
8665
|
+
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
8666
|
+
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
8667
|
+
/** The byte swap operation for uint32 */
|
|
8668
|
+
function byteSwap(word) {
|
|
8669
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
8670
|
+
}
|
|
8671
|
+
/** Conditionally byte swap if on a big-endian platform */
|
|
8672
|
+
const swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
|
|
8673
|
+
/** In place byte swap for Uint32Array */
|
|
8674
|
+
function byteSwap32(arr$1) {
|
|
8675
|
+
for (let i = 0; i < arr$1.length; i++) arr$1[i] = byteSwap(arr$1[i]);
|
|
8676
|
+
return arr$1;
|
|
8677
|
+
}
|
|
8678
|
+
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
8679
|
+
/** Creates function with outputLen, blockLen, create properties from a class constructor. */
|
|
8680
|
+
function createHasher(hashCons, info = {}) {
|
|
8681
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
8682
|
+
const tmp = hashCons(void 0);
|
|
8683
|
+
hashC.outputLen = tmp.outputLen;
|
|
8684
|
+
hashC.blockLen = tmp.blockLen;
|
|
8685
|
+
hashC.create = (opts) => hashCons(opts);
|
|
8686
|
+
Object.assign(hashC, info);
|
|
8687
|
+
return Object.freeze(hashC);
|
|
8688
|
+
}
|
|
8689
|
+
|
|
8690
|
+
//#endregion
|
|
8691
|
+
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/_blake.js
|
|
8692
|
+
/**
|
|
8693
|
+
* Internal blake variable.
|
|
8694
|
+
* For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].
|
|
8695
|
+
*/
|
|
8696
|
+
const BSIGMA = /* @__PURE__ */ Uint8Array.from([
|
|
8697
|
+
0,
|
|
8698
|
+
1,
|
|
8699
|
+
2,
|
|
8700
|
+
3,
|
|
8701
|
+
4,
|
|
8702
|
+
5,
|
|
8703
|
+
6,
|
|
8704
|
+
7,
|
|
8705
|
+
8,
|
|
8706
|
+
9,
|
|
8707
|
+
10,
|
|
8708
|
+
11,
|
|
8709
|
+
12,
|
|
8710
|
+
13,
|
|
8711
|
+
14,
|
|
8712
|
+
15,
|
|
8713
|
+
14,
|
|
8714
|
+
10,
|
|
8715
|
+
4,
|
|
8716
|
+
8,
|
|
8717
|
+
9,
|
|
8718
|
+
15,
|
|
8719
|
+
13,
|
|
8720
|
+
6,
|
|
8721
|
+
1,
|
|
8722
|
+
12,
|
|
8723
|
+
0,
|
|
8724
|
+
2,
|
|
8725
|
+
11,
|
|
8726
|
+
7,
|
|
8727
|
+
5,
|
|
8728
|
+
3,
|
|
8729
|
+
11,
|
|
8730
|
+
8,
|
|
8731
|
+
12,
|
|
8732
|
+
0,
|
|
8733
|
+
5,
|
|
8734
|
+
2,
|
|
8735
|
+
15,
|
|
8736
|
+
13,
|
|
8737
|
+
10,
|
|
8738
|
+
14,
|
|
8739
|
+
3,
|
|
8740
|
+
6,
|
|
8741
|
+
7,
|
|
8742
|
+
1,
|
|
8743
|
+
9,
|
|
8744
|
+
4,
|
|
8745
|
+
7,
|
|
8746
|
+
9,
|
|
8747
|
+
3,
|
|
8748
|
+
1,
|
|
8749
|
+
13,
|
|
8750
|
+
12,
|
|
8751
|
+
11,
|
|
8752
|
+
14,
|
|
8753
|
+
2,
|
|
8754
|
+
6,
|
|
8755
|
+
5,
|
|
8756
|
+
10,
|
|
8757
|
+
4,
|
|
8758
|
+
0,
|
|
8759
|
+
15,
|
|
8760
|
+
8,
|
|
8761
|
+
9,
|
|
8762
|
+
0,
|
|
8763
|
+
5,
|
|
8764
|
+
7,
|
|
8765
|
+
2,
|
|
8766
|
+
4,
|
|
8767
|
+
10,
|
|
8768
|
+
15,
|
|
8769
|
+
14,
|
|
8770
|
+
1,
|
|
8771
|
+
11,
|
|
8772
|
+
12,
|
|
8773
|
+
6,
|
|
8774
|
+
8,
|
|
8775
|
+
3,
|
|
8776
|
+
13,
|
|
8777
|
+
2,
|
|
8778
|
+
12,
|
|
8779
|
+
6,
|
|
8780
|
+
10,
|
|
8781
|
+
0,
|
|
8782
|
+
11,
|
|
8783
|
+
8,
|
|
8784
|
+
3,
|
|
8785
|
+
4,
|
|
8786
|
+
13,
|
|
8787
|
+
7,
|
|
8788
|
+
5,
|
|
8789
|
+
15,
|
|
8790
|
+
14,
|
|
8791
|
+
1,
|
|
8792
|
+
9,
|
|
8793
|
+
12,
|
|
8794
|
+
5,
|
|
8795
|
+
1,
|
|
8796
|
+
15,
|
|
8797
|
+
14,
|
|
8798
|
+
13,
|
|
8799
|
+
4,
|
|
8800
|
+
10,
|
|
8801
|
+
0,
|
|
8802
|
+
7,
|
|
8803
|
+
6,
|
|
8804
|
+
3,
|
|
8805
|
+
9,
|
|
8806
|
+
2,
|
|
8807
|
+
8,
|
|
8808
|
+
11,
|
|
8809
|
+
13,
|
|
8810
|
+
11,
|
|
8811
|
+
7,
|
|
8812
|
+
14,
|
|
8813
|
+
12,
|
|
8814
|
+
1,
|
|
8815
|
+
3,
|
|
8816
|
+
9,
|
|
8817
|
+
5,
|
|
8818
|
+
0,
|
|
8819
|
+
15,
|
|
8820
|
+
4,
|
|
8821
|
+
8,
|
|
8822
|
+
6,
|
|
8823
|
+
2,
|
|
8824
|
+
10,
|
|
8825
|
+
6,
|
|
8826
|
+
15,
|
|
8827
|
+
14,
|
|
8828
|
+
9,
|
|
8829
|
+
11,
|
|
8830
|
+
3,
|
|
8831
|
+
0,
|
|
8832
|
+
8,
|
|
8833
|
+
12,
|
|
8834
|
+
2,
|
|
8835
|
+
13,
|
|
8836
|
+
7,
|
|
8837
|
+
1,
|
|
8838
|
+
4,
|
|
8839
|
+
10,
|
|
8840
|
+
5,
|
|
8841
|
+
10,
|
|
8842
|
+
2,
|
|
8843
|
+
8,
|
|
8844
|
+
4,
|
|
8845
|
+
7,
|
|
8846
|
+
6,
|
|
8847
|
+
1,
|
|
8848
|
+
5,
|
|
8849
|
+
15,
|
|
8850
|
+
11,
|
|
8851
|
+
9,
|
|
8852
|
+
14,
|
|
8853
|
+
3,
|
|
8854
|
+
12,
|
|
8855
|
+
13,
|
|
8856
|
+
0,
|
|
8857
|
+
0,
|
|
8858
|
+
1,
|
|
8859
|
+
2,
|
|
8860
|
+
3,
|
|
8861
|
+
4,
|
|
8862
|
+
5,
|
|
8863
|
+
6,
|
|
8864
|
+
7,
|
|
8865
|
+
8,
|
|
8866
|
+
9,
|
|
8867
|
+
10,
|
|
8868
|
+
11,
|
|
8869
|
+
12,
|
|
8870
|
+
13,
|
|
8871
|
+
14,
|
|
8872
|
+
15,
|
|
8873
|
+
14,
|
|
8874
|
+
10,
|
|
8875
|
+
4,
|
|
8876
|
+
8,
|
|
8877
|
+
9,
|
|
8878
|
+
15,
|
|
8879
|
+
13,
|
|
8880
|
+
6,
|
|
8881
|
+
1,
|
|
8882
|
+
12,
|
|
8883
|
+
0,
|
|
8884
|
+
2,
|
|
8885
|
+
11,
|
|
8886
|
+
7,
|
|
8887
|
+
5,
|
|
8888
|
+
3,
|
|
8889
|
+
11,
|
|
8890
|
+
8,
|
|
8891
|
+
12,
|
|
8892
|
+
0,
|
|
8893
|
+
5,
|
|
8894
|
+
2,
|
|
8895
|
+
15,
|
|
8896
|
+
13,
|
|
8897
|
+
10,
|
|
8898
|
+
14,
|
|
8899
|
+
3,
|
|
8900
|
+
6,
|
|
8901
|
+
7,
|
|
8902
|
+
1,
|
|
8903
|
+
9,
|
|
8904
|
+
4,
|
|
8905
|
+
7,
|
|
8906
|
+
9,
|
|
8907
|
+
3,
|
|
8908
|
+
1,
|
|
8909
|
+
13,
|
|
8910
|
+
12,
|
|
8911
|
+
11,
|
|
8912
|
+
14,
|
|
8913
|
+
2,
|
|
8914
|
+
6,
|
|
8915
|
+
5,
|
|
8916
|
+
10,
|
|
8917
|
+
4,
|
|
8918
|
+
0,
|
|
8919
|
+
15,
|
|
8920
|
+
8,
|
|
8921
|
+
9,
|
|
8922
|
+
0,
|
|
8923
|
+
5,
|
|
8924
|
+
7,
|
|
8925
|
+
2,
|
|
8926
|
+
4,
|
|
8927
|
+
10,
|
|
8928
|
+
15,
|
|
8929
|
+
14,
|
|
8930
|
+
1,
|
|
8931
|
+
11,
|
|
8932
|
+
12,
|
|
8933
|
+
6,
|
|
8934
|
+
8,
|
|
8935
|
+
3,
|
|
8936
|
+
13,
|
|
8937
|
+
2,
|
|
8938
|
+
12,
|
|
8939
|
+
6,
|
|
8940
|
+
10,
|
|
8941
|
+
0,
|
|
8942
|
+
11,
|
|
8943
|
+
8,
|
|
8944
|
+
3,
|
|
8945
|
+
4,
|
|
8946
|
+
13,
|
|
8947
|
+
7,
|
|
8948
|
+
5,
|
|
8949
|
+
15,
|
|
8950
|
+
14,
|
|
8951
|
+
1,
|
|
8952
|
+
9
|
|
8953
|
+
]);
|
|
8954
|
+
|
|
8955
|
+
//#endregion
|
|
8956
|
+
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
|
|
8957
|
+
/**
|
|
8958
|
+
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
8959
|
+
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
8960
|
+
* @module
|
|
8961
|
+
*/
|
|
8962
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
8963
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
8964
|
+
function fromBig(n, le = false) {
|
|
8965
|
+
if (le) return {
|
|
8966
|
+
h: Number(n & U32_MASK64),
|
|
8967
|
+
l: Number(n >> _32n & U32_MASK64)
|
|
8968
|
+
};
|
|
8969
|
+
return {
|
|
8970
|
+
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
8971
|
+
l: Number(n & U32_MASK64) | 0
|
|
8972
|
+
};
|
|
8973
|
+
}
|
|
8974
|
+
const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
8975
|
+
const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
8976
|
+
const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
8977
|
+
const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
8978
|
+
const rotr32H = (_h, l) => l;
|
|
8979
|
+
const rotr32L = (h, _l) => h;
|
|
8980
|
+
function add(Ah, Al, Bh, Bl) {
|
|
8981
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
8982
|
+
return {
|
|
8983
|
+
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
8984
|
+
l: l | 0
|
|
8985
|
+
};
|
|
8986
|
+
}
|
|
8987
|
+
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
8988
|
+
const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
8989
|
+
|
|
8990
|
+
//#endregion
|
|
8991
|
+
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/blake2.js
|
|
8992
|
+
/**
|
|
8993
|
+
* blake2b (64-bit) & blake2s (8 to 32-bit) hash functions.
|
|
8994
|
+
* b could have been faster, but there is no fast u64 in js, so s is 1.5x faster.
|
|
8995
|
+
* @module
|
|
8996
|
+
*/
|
|
8997
|
+
const B2B_IV = /* @__PURE__ */ Uint32Array.from([
|
|
8998
|
+
4089235720,
|
|
8999
|
+
1779033703,
|
|
9000
|
+
2227873595,
|
|
9001
|
+
3144134277,
|
|
9002
|
+
4271175723,
|
|
9003
|
+
1013904242,
|
|
9004
|
+
1595750129,
|
|
9005
|
+
2773480762,
|
|
9006
|
+
2917565137,
|
|
9007
|
+
1359893119,
|
|
9008
|
+
725511199,
|
|
9009
|
+
2600822924,
|
|
9010
|
+
4215389547,
|
|
9011
|
+
528734635,
|
|
9012
|
+
327033209,
|
|
9013
|
+
1541459225
|
|
9014
|
+
]);
|
|
9015
|
+
const BBUF = /* @__PURE__ */ new Uint32Array(32);
|
|
9016
|
+
function G1b(a, b, c, d, msg, x) {
|
|
9017
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
9018
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
9019
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
9020
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
9021
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
9022
|
+
let ll = add3L(Al, Bl, Xl);
|
|
9023
|
+
Ah = add3H(ll, Ah, Bh, Xh);
|
|
9024
|
+
Al = ll | 0;
|
|
9025
|
+
({Dh, Dl} = {
|
|
9026
|
+
Dh: Dh ^ Ah,
|
|
9027
|
+
Dl: Dl ^ Al
|
|
9028
|
+
});
|
|
9029
|
+
({Dh, Dl} = {
|
|
9030
|
+
Dh: rotr32H(Dh, Dl),
|
|
9031
|
+
Dl: rotr32L(Dh, Dl)
|
|
9032
|
+
});
|
|
9033
|
+
({h: Ch, l: Cl} = add(Ch, Cl, Dh, Dl));
|
|
9034
|
+
({Bh, Bl} = {
|
|
9035
|
+
Bh: Bh ^ Ch,
|
|
9036
|
+
Bl: Bl ^ Cl
|
|
9037
|
+
});
|
|
9038
|
+
({Bh, Bl} = {
|
|
9039
|
+
Bh: rotrSH(Bh, Bl, 24),
|
|
9040
|
+
Bl: rotrSL(Bh, Bl, 24)
|
|
9041
|
+
});
|
|
9042
|
+
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
9043
|
+
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
9044
|
+
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
9045
|
+
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
9046
|
+
}
|
|
9047
|
+
function G2b(a, b, c, d, msg, x) {
|
|
9048
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
9049
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
9050
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
9051
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
9052
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
9053
|
+
let ll = add3L(Al, Bl, Xl);
|
|
9054
|
+
Ah = add3H(ll, Ah, Bh, Xh);
|
|
9055
|
+
Al = ll | 0;
|
|
9056
|
+
({Dh, Dl} = {
|
|
9057
|
+
Dh: Dh ^ Ah,
|
|
9058
|
+
Dl: Dl ^ Al
|
|
9059
|
+
});
|
|
9060
|
+
({Dh, Dl} = {
|
|
9061
|
+
Dh: rotrSH(Dh, Dl, 16),
|
|
9062
|
+
Dl: rotrSL(Dh, Dl, 16)
|
|
9063
|
+
});
|
|
9064
|
+
({h: Ch, l: Cl} = add(Ch, Cl, Dh, Dl));
|
|
9065
|
+
({Bh, Bl} = {
|
|
9066
|
+
Bh: Bh ^ Ch,
|
|
9067
|
+
Bl: Bl ^ Cl
|
|
9068
|
+
});
|
|
9069
|
+
({Bh, Bl} = {
|
|
9070
|
+
Bh: rotrBH(Bh, Bl, 63),
|
|
9071
|
+
Bl: rotrBL(Bh, Bl, 63)
|
|
9072
|
+
});
|
|
9073
|
+
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
9074
|
+
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
9075
|
+
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
9076
|
+
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
9077
|
+
}
|
|
9078
|
+
function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
|
|
9079
|
+
anumber(keyLen);
|
|
9080
|
+
if (outputLen < 0 || outputLen > keyLen) throw new Error("outputLen bigger than keyLen");
|
|
9081
|
+
const { key, salt, personalization } = opts;
|
|
9082
|
+
if (key !== void 0 && (key.length < 1 || key.length > keyLen)) throw new Error("\"key\" expected to be undefined or of length=1.." + keyLen);
|
|
9083
|
+
if (salt !== void 0) abytes(salt, saltLen, "salt");
|
|
9084
|
+
if (personalization !== void 0) abytes(personalization, persLen, "personalization");
|
|
9085
|
+
}
|
|
9086
|
+
/** Internal base class for BLAKE2. */
|
|
9087
|
+
var _BLAKE2 = class {
|
|
9088
|
+
buffer;
|
|
9089
|
+
buffer32;
|
|
9090
|
+
finished = false;
|
|
9091
|
+
destroyed = false;
|
|
9092
|
+
length = 0;
|
|
9093
|
+
pos = 0;
|
|
9094
|
+
blockLen;
|
|
9095
|
+
outputLen;
|
|
9096
|
+
constructor(blockLen, outputLen) {
|
|
9097
|
+
anumber(blockLen);
|
|
9098
|
+
anumber(outputLen);
|
|
9099
|
+
this.blockLen = blockLen;
|
|
9100
|
+
this.outputLen = outputLen;
|
|
9101
|
+
this.buffer = new Uint8Array(blockLen);
|
|
9102
|
+
this.buffer32 = u32(this.buffer);
|
|
9103
|
+
}
|
|
9104
|
+
update(data) {
|
|
9105
|
+
aexists(this);
|
|
9106
|
+
abytes(data);
|
|
9107
|
+
const { blockLen, buffer, buffer32 } = this;
|
|
9108
|
+
const len = data.length;
|
|
9109
|
+
const offset = data.byteOffset;
|
|
9110
|
+
const buf = data.buffer;
|
|
9111
|
+
for (let pos = 0; pos < len;) {
|
|
9112
|
+
if (this.pos === blockLen) {
|
|
9113
|
+
swap32IfBE(buffer32);
|
|
9114
|
+
this.compress(buffer32, 0, false);
|
|
9115
|
+
swap32IfBE(buffer32);
|
|
9116
|
+
this.pos = 0;
|
|
9117
|
+
}
|
|
9118
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
9119
|
+
const dataOffset = offset + pos;
|
|
9120
|
+
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
|
9121
|
+
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
|
9122
|
+
swap32IfBE(data32);
|
|
9123
|
+
for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
|
|
9124
|
+
this.length += blockLen;
|
|
9125
|
+
this.compress(data32, pos32, false);
|
|
9126
|
+
}
|
|
9127
|
+
swap32IfBE(data32);
|
|
9128
|
+
continue;
|
|
9129
|
+
}
|
|
9130
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
9131
|
+
this.pos += take;
|
|
9132
|
+
this.length += take;
|
|
9133
|
+
pos += take;
|
|
9134
|
+
}
|
|
9135
|
+
return this;
|
|
9136
|
+
}
|
|
9137
|
+
digestInto(out) {
|
|
9138
|
+
aexists(this);
|
|
9139
|
+
aoutput(out, this);
|
|
9140
|
+
const { pos, buffer32 } = this;
|
|
9141
|
+
this.finished = true;
|
|
9142
|
+
clean(this.buffer.subarray(pos));
|
|
9143
|
+
swap32IfBE(buffer32);
|
|
9144
|
+
this.compress(buffer32, 0, true);
|
|
9145
|
+
swap32IfBE(buffer32);
|
|
9146
|
+
const out32 = u32(out);
|
|
9147
|
+
this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
|
|
9148
|
+
}
|
|
9149
|
+
digest() {
|
|
9150
|
+
const { buffer, outputLen } = this;
|
|
9151
|
+
this.digestInto(buffer);
|
|
9152
|
+
const res = buffer.slice(0, outputLen);
|
|
9153
|
+
this.destroy();
|
|
9154
|
+
return res;
|
|
9155
|
+
}
|
|
9156
|
+
_cloneInto(to) {
|
|
9157
|
+
const { buffer, length, finished, destroyed, outputLen, pos } = this;
|
|
9158
|
+
to ||= new this.constructor({ dkLen: outputLen });
|
|
9159
|
+
to.set(...this.get());
|
|
9160
|
+
to.buffer.set(buffer);
|
|
9161
|
+
to.destroyed = destroyed;
|
|
9162
|
+
to.finished = finished;
|
|
9163
|
+
to.length = length;
|
|
9164
|
+
to.pos = pos;
|
|
9165
|
+
to.outputLen = outputLen;
|
|
9166
|
+
return to;
|
|
9167
|
+
}
|
|
9168
|
+
clone() {
|
|
9169
|
+
return this._cloneInto();
|
|
9170
|
+
}
|
|
9171
|
+
};
|
|
9172
|
+
/** Internal blake2b hash class. */
|
|
9173
|
+
var _BLAKE2b = class extends _BLAKE2 {
|
|
9174
|
+
v0l = B2B_IV[0] | 0;
|
|
9175
|
+
v0h = B2B_IV[1] | 0;
|
|
9176
|
+
v1l = B2B_IV[2] | 0;
|
|
9177
|
+
v1h = B2B_IV[3] | 0;
|
|
9178
|
+
v2l = B2B_IV[4] | 0;
|
|
9179
|
+
v2h = B2B_IV[5] | 0;
|
|
9180
|
+
v3l = B2B_IV[6] | 0;
|
|
9181
|
+
v3h = B2B_IV[7] | 0;
|
|
9182
|
+
v4l = B2B_IV[8] | 0;
|
|
9183
|
+
v4h = B2B_IV[9] | 0;
|
|
9184
|
+
v5l = B2B_IV[10] | 0;
|
|
9185
|
+
v5h = B2B_IV[11] | 0;
|
|
9186
|
+
v6l = B2B_IV[12] | 0;
|
|
9187
|
+
v6h = B2B_IV[13] | 0;
|
|
9188
|
+
v7l = B2B_IV[14] | 0;
|
|
9189
|
+
v7h = B2B_IV[15] | 0;
|
|
9190
|
+
constructor(opts = {}) {
|
|
9191
|
+
const olen = opts.dkLen === void 0 ? 64 : opts.dkLen;
|
|
9192
|
+
super(128, olen);
|
|
9193
|
+
checkBlake2Opts(olen, opts, 64, 16, 16);
|
|
9194
|
+
let { key, personalization, salt } = opts;
|
|
9195
|
+
let keyLength = 0;
|
|
9196
|
+
if (key !== void 0) {
|
|
9197
|
+
abytes(key, void 0, "key");
|
|
9198
|
+
keyLength = key.length;
|
|
9199
|
+
}
|
|
9200
|
+
this.v0l ^= this.outputLen | keyLength << 8 | 16842752;
|
|
9201
|
+
if (salt !== void 0) {
|
|
9202
|
+
abytes(salt, void 0, "salt");
|
|
9203
|
+
const slt = u32(salt);
|
|
9204
|
+
this.v4l ^= swap8IfBE(slt[0]);
|
|
9205
|
+
this.v4h ^= swap8IfBE(slt[1]);
|
|
9206
|
+
this.v5l ^= swap8IfBE(slt[2]);
|
|
9207
|
+
this.v5h ^= swap8IfBE(slt[3]);
|
|
9208
|
+
}
|
|
9209
|
+
if (personalization !== void 0) {
|
|
9210
|
+
abytes(personalization, void 0, "personalization");
|
|
9211
|
+
const pers = u32(personalization);
|
|
9212
|
+
this.v6l ^= swap8IfBE(pers[0]);
|
|
9213
|
+
this.v6h ^= swap8IfBE(pers[1]);
|
|
9214
|
+
this.v7l ^= swap8IfBE(pers[2]);
|
|
9215
|
+
this.v7h ^= swap8IfBE(pers[3]);
|
|
9216
|
+
}
|
|
9217
|
+
if (key !== void 0) {
|
|
9218
|
+
const tmp = new Uint8Array(this.blockLen);
|
|
9219
|
+
tmp.set(key);
|
|
9220
|
+
this.update(tmp);
|
|
9221
|
+
}
|
|
9222
|
+
}
|
|
9223
|
+
get() {
|
|
9224
|
+
let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
|
|
9225
|
+
return [
|
|
9226
|
+
v0l,
|
|
9227
|
+
v0h,
|
|
9228
|
+
v1l,
|
|
9229
|
+
v1h,
|
|
9230
|
+
v2l,
|
|
9231
|
+
v2h,
|
|
9232
|
+
v3l,
|
|
9233
|
+
v3h,
|
|
9234
|
+
v4l,
|
|
9235
|
+
v4h,
|
|
9236
|
+
v5l,
|
|
9237
|
+
v5h,
|
|
9238
|
+
v6l,
|
|
9239
|
+
v6h,
|
|
9240
|
+
v7l,
|
|
9241
|
+
v7h
|
|
9242
|
+
];
|
|
9243
|
+
}
|
|
9244
|
+
set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
|
|
9245
|
+
this.v0l = v0l | 0;
|
|
9246
|
+
this.v0h = v0h | 0;
|
|
9247
|
+
this.v1l = v1l | 0;
|
|
9248
|
+
this.v1h = v1h | 0;
|
|
9249
|
+
this.v2l = v2l | 0;
|
|
9250
|
+
this.v2h = v2h | 0;
|
|
9251
|
+
this.v3l = v3l | 0;
|
|
9252
|
+
this.v3h = v3h | 0;
|
|
9253
|
+
this.v4l = v4l | 0;
|
|
9254
|
+
this.v4h = v4h | 0;
|
|
9255
|
+
this.v5l = v5l | 0;
|
|
9256
|
+
this.v5h = v5h | 0;
|
|
9257
|
+
this.v6l = v6l | 0;
|
|
9258
|
+
this.v6h = v6h | 0;
|
|
9259
|
+
this.v7l = v7l | 0;
|
|
9260
|
+
this.v7h = v7h | 0;
|
|
9261
|
+
}
|
|
9262
|
+
compress(msg, offset, isLast) {
|
|
9263
|
+
this.get().forEach((v, i) => BBUF[i] = v);
|
|
9264
|
+
BBUF.set(B2B_IV, 16);
|
|
9265
|
+
let { h, l } = fromBig(BigInt(this.length));
|
|
9266
|
+
BBUF[24] = B2B_IV[8] ^ l;
|
|
9267
|
+
BBUF[25] = B2B_IV[9] ^ h;
|
|
9268
|
+
if (isLast) {
|
|
9269
|
+
BBUF[28] = ~BBUF[28];
|
|
9270
|
+
BBUF[29] = ~BBUF[29];
|
|
9271
|
+
}
|
|
9272
|
+
let j = 0;
|
|
9273
|
+
const s = BSIGMA;
|
|
9274
|
+
for (let i = 0; i < 12; i++) {
|
|
9275
|
+
G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
9276
|
+
G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
9277
|
+
G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
|
9278
|
+
G2b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
|
9279
|
+
G1b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
|
9280
|
+
G2b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
|
9281
|
+
G1b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
|
9282
|
+
G2b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
|
9283
|
+
G1b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
|
9284
|
+
G2b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
|
9285
|
+
G1b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
|
9286
|
+
G2b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
|
9287
|
+
G1b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
|
9288
|
+
G2b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
|
9289
|
+
G1b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
|
9290
|
+
G2b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
|
9291
|
+
}
|
|
9292
|
+
this.v0l ^= BBUF[0] ^ BBUF[16];
|
|
9293
|
+
this.v0h ^= BBUF[1] ^ BBUF[17];
|
|
9294
|
+
this.v1l ^= BBUF[2] ^ BBUF[18];
|
|
9295
|
+
this.v1h ^= BBUF[3] ^ BBUF[19];
|
|
9296
|
+
this.v2l ^= BBUF[4] ^ BBUF[20];
|
|
9297
|
+
this.v2h ^= BBUF[5] ^ BBUF[21];
|
|
9298
|
+
this.v3l ^= BBUF[6] ^ BBUF[22];
|
|
9299
|
+
this.v3h ^= BBUF[7] ^ BBUF[23];
|
|
9300
|
+
this.v4l ^= BBUF[8] ^ BBUF[24];
|
|
9301
|
+
this.v4h ^= BBUF[9] ^ BBUF[25];
|
|
9302
|
+
this.v5l ^= BBUF[10] ^ BBUF[26];
|
|
9303
|
+
this.v5h ^= BBUF[11] ^ BBUF[27];
|
|
9304
|
+
this.v6l ^= BBUF[12] ^ BBUF[28];
|
|
9305
|
+
this.v6h ^= BBUF[13] ^ BBUF[29];
|
|
9306
|
+
this.v7l ^= BBUF[14] ^ BBUF[30];
|
|
9307
|
+
this.v7h ^= BBUF[15] ^ BBUF[31];
|
|
9308
|
+
clean(BBUF);
|
|
9309
|
+
}
|
|
9310
|
+
destroy() {
|
|
9311
|
+
this.destroyed = true;
|
|
9312
|
+
clean(this.buffer32);
|
|
9313
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
9314
|
+
}
|
|
9315
|
+
};
|
|
9316
|
+
/**
|
|
9317
|
+
* Blake2b hash function. 64-bit. 1.5x slower than blake2s in JS.
|
|
9318
|
+
* @param msg - message that would be hashed
|
|
9319
|
+
* @param opts - dkLen output length, key for MAC mode, salt, personalization
|
|
9320
|
+
*/
|
|
9321
|
+
const blake2b = /* @__PURE__ */ createHasher((opts) => new _BLAKE2b(opts));
|
|
9322
|
+
|
|
9323
|
+
//#endregion
|
|
9324
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/utils/ss58-util.mjs
|
|
9325
|
+
const SS58_PREFIX = new TextEncoder().encode("SS58PRE");
|
|
9326
|
+
const CHECKSUM_LENGTH = 2;
|
|
9327
|
+
const getSs58AddressInfo = (address) => {
|
|
9328
|
+
try {
|
|
9329
|
+
const decoded = base58.decode(address);
|
|
9330
|
+
const prefixBytes = decoded.subarray(0, decoded[0] & 64 ? 2 : 1);
|
|
9331
|
+
const publicKey = decoded.subarray(prefixBytes.length, decoded.length - CHECKSUM_LENGTH);
|
|
9332
|
+
const checksum = decoded.subarray(prefixBytes.length + publicKey.length);
|
|
9333
|
+
const expectedChecksum = blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), { dkLen: 64 }).subarray(0, CHECKSUM_LENGTH);
|
|
9334
|
+
if (!(checksum[0] === expectedChecksum[0] && checksum[1] === expectedChecksum[1])) return { isValid: false };
|
|
9335
|
+
return {
|
|
9336
|
+
isValid: true,
|
|
9337
|
+
ss58Format: prefixBytesToNumber(prefixBytes),
|
|
9338
|
+
publicKey: publicKey.slice()
|
|
9339
|
+
};
|
|
9340
|
+
} catch (_) {
|
|
9341
|
+
return { isValid: false };
|
|
9342
|
+
}
|
|
9343
|
+
};
|
|
9344
|
+
const prefixBytesToNumber = (bytes) => {
|
|
9345
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
9346
|
+
return dv.byteLength === 1 ? dv.getUint8(0) : dv.getUint16(0);
|
|
9347
|
+
};
|
|
9348
|
+
const withSs58Cache = (fn) => {
|
|
9349
|
+
let cache = {};
|
|
9350
|
+
let activityCount = 0;
|
|
9351
|
+
let latestCount = 0;
|
|
9352
|
+
const checkActivity = () => {
|
|
9353
|
+
if (activityCount === latestCount) {
|
|
9354
|
+
cache = {};
|
|
9355
|
+
activityCount = latestCount = 0;
|
|
9356
|
+
} else {
|
|
9357
|
+
latestCount = activityCount;
|
|
9358
|
+
setTimeout(checkActivity, 0);
|
|
9359
|
+
}
|
|
9360
|
+
};
|
|
9361
|
+
return (publicKey) => {
|
|
9362
|
+
var _a, _b;
|
|
9363
|
+
if (++activityCount === 1) checkActivity();
|
|
9364
|
+
let entry = cache;
|
|
9365
|
+
const lastIdx = publicKey.length - 1;
|
|
9366
|
+
for (let i = 0; i <= lastIdx; i++) entry = entry[_a = publicKey[i]] || (entry[_a] = {});
|
|
9367
|
+
return entry[_b = publicKey[lastIdx]] || (entry[_b] = fn(publicKey));
|
|
9368
|
+
};
|
|
9369
|
+
};
|
|
9370
|
+
const fromBufferToBase58 = (ss58Format) => {
|
|
9371
|
+
const prefixBytes = ss58Format < 64 ? Uint8Array.of(ss58Format) : Uint8Array.of((ss58Format & 252) >> 2 | 64, ss58Format >> 8 | (ss58Format & 3) << 6);
|
|
9372
|
+
return withSs58Cache((publicKey) => {
|
|
9373
|
+
const checksum = blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), { dkLen: 64 }).subarray(0, CHECKSUM_LENGTH);
|
|
9374
|
+
return base58.encode(Uint8Array.of(...prefixBytes, ...publicKey, ...checksum));
|
|
9375
|
+
});
|
|
9376
|
+
};
|
|
9377
|
+
|
|
9378
|
+
//#endregion
|
|
9379
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/scale/AccountId.mjs
|
|
9380
|
+
function fromBase58ToBuffer(nBytes, _ss58Format) {
|
|
9381
|
+
return (address) => {
|
|
9382
|
+
const info = getSs58AddressInfo(address);
|
|
9383
|
+
if (!info.isValid) throw new Error("Invalid checksum");
|
|
9384
|
+
const { publicKey } = info;
|
|
9385
|
+
if (publicKey.length !== nBytes) throw new Error("Invalid public key length");
|
|
9386
|
+
return publicKey;
|
|
9387
|
+
};
|
|
9388
|
+
}
|
|
9389
|
+
const AccountId = (ss58Format = 42, nBytes = 32) => enhanceCodec(Bytes(nBytes), fromBase58ToBuffer(nBytes), fromBufferToBase58(ss58Format));
|
|
9390
|
+
|
|
9391
|
+
//#endregion
|
|
9392
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/scale/Binary.mjs
|
|
9393
|
+
var __defProp = Object.defineProperty;
|
|
9394
|
+
var __typeError = (msg) => {
|
|
9395
|
+
throw TypeError(msg);
|
|
9396
|
+
};
|
|
9397
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
9398
|
+
enumerable: true,
|
|
9399
|
+
configurable: true,
|
|
9400
|
+
writable: true,
|
|
9401
|
+
value
|
|
9402
|
+
}) : obj[key] = value;
|
|
9403
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9404
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
9405
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9406
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
9407
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
9408
|
+
var _bytes, _opaqueBytes, _hex, _opaqueHex, _str;
|
|
9409
|
+
const textEncoder$3 = new TextEncoder();
|
|
9410
|
+
const textDecoder$2 = new TextDecoder();
|
|
9411
|
+
const opaqueBytesDec = Tuple(compact, Bytes(Infinity))[1];
|
|
9412
|
+
var Binary$1 = class {
|
|
9413
|
+
constructor(data, opaque = false) {
|
|
9414
|
+
__privateAdd(this, _bytes);
|
|
9415
|
+
__privateAdd(this, _opaqueBytes, null);
|
|
9416
|
+
__privateAdd(this, _hex, null);
|
|
9417
|
+
__privateAdd(this, _opaqueHex, null);
|
|
9418
|
+
__privateAdd(this, _str, null);
|
|
9419
|
+
__publicField(this, "asText", () => __privateGet(this, _str) ?? __privateSet(this, _str, textDecoder$2.decode(__privateGet(this, _bytes))));
|
|
9420
|
+
__publicField(this, "asHex", () => __privateGet(this, _hex) ?? __privateSet(this, _hex, toHex(__privateGet(this, _bytes))));
|
|
9421
|
+
__publicField(this, "asOpaqueHex", () => __privateGet(this, _opaqueHex) ?? __privateSet(this, _opaqueHex, toHex(this.asOpaqueBytes())));
|
|
9422
|
+
__publicField(this, "asBytes", () => __privateGet(this, _bytes));
|
|
9423
|
+
__publicField(this, "asOpaqueBytes", () => __privateGet(this, _opaqueBytes) ?? __privateSet(this, _opaqueBytes, mergeUint8$1([compact[0](__privateGet(this, _bytes).length), __privateGet(this, _bytes)])));
|
|
9424
|
+
if (opaque) {
|
|
9425
|
+
try {
|
|
9426
|
+
const [len, bytes] = opaqueBytesDec(data);
|
|
9427
|
+
if (len === bytes.length) {
|
|
9428
|
+
__privateSet(this, _bytes, bytes);
|
|
9429
|
+
__privateSet(this, _opaqueBytes, data);
|
|
9430
|
+
return;
|
|
9431
|
+
}
|
|
9432
|
+
} catch (_) {}
|
|
9433
|
+
throw new Error("Invalid opaque bytes");
|
|
9434
|
+
} else __privateSet(this, _bytes, data);
|
|
9435
|
+
}
|
|
9436
|
+
static fromText(input) {
|
|
9437
|
+
return new this(textEncoder$3.encode(input));
|
|
9438
|
+
}
|
|
9439
|
+
static fromHex(input) {
|
|
9440
|
+
return new this(fromHex$1(input));
|
|
9441
|
+
}
|
|
9442
|
+
static fromOpaqueHex(input) {
|
|
9443
|
+
return new this(fromHex$1(input), true);
|
|
9444
|
+
}
|
|
9445
|
+
static fromBytes(input) {
|
|
9446
|
+
return new this(input);
|
|
9447
|
+
}
|
|
9448
|
+
static fromOpaqueBytes(input) {
|
|
9449
|
+
return new this(input, true);
|
|
9450
|
+
}
|
|
9451
|
+
};
|
|
9452
|
+
_bytes = /* @__PURE__ */ new WeakMap();
|
|
9453
|
+
_opaqueBytes = /* @__PURE__ */ new WeakMap();
|
|
9454
|
+
_hex = /* @__PURE__ */ new WeakMap();
|
|
9455
|
+
_opaqueHex = /* @__PURE__ */ new WeakMap();
|
|
9456
|
+
_str = /* @__PURE__ */ new WeakMap();
|
|
9457
|
+
const [accountIdEncoder] = AccountId();
|
|
9458
|
+
var FixedSizeBinary$1 = class extends Binary$1 {
|
|
9459
|
+
constructor(data) {
|
|
9460
|
+
super(data);
|
|
9461
|
+
}
|
|
9462
|
+
static fromArray(input) {
|
|
9463
|
+
return new this(new Uint8Array(input));
|
|
9464
|
+
}
|
|
9465
|
+
static fromAccountId32(input) {
|
|
9466
|
+
return new this(accountIdEncoder(input));
|
|
9467
|
+
}
|
|
9468
|
+
};
|
|
9469
|
+
const enc$2 = (nBytes) => {
|
|
9470
|
+
const _enc = Bytes.enc(nBytes);
|
|
9471
|
+
return (value) => _enc(value.asBytes());
|
|
9472
|
+
};
|
|
9473
|
+
const dec$2 = (nBytes) => {
|
|
9474
|
+
const _dec = Bytes.dec(nBytes);
|
|
9475
|
+
const Bin2 = nBytes == null ? Binary$1 : FixedSizeBinary$1;
|
|
9476
|
+
return (value) => Bin2.fromBytes(_dec(value));
|
|
9477
|
+
};
|
|
9478
|
+
const Bin = (nBytes) => createCodec(enc$2(nBytes), dec$2(nBytes));
|
|
9479
|
+
Bin.enc = enc$2;
|
|
9480
|
+
Bin.dec = dec$2;
|
|
9481
|
+
|
|
9482
|
+
//#endregion
|
|
9483
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/scale/compact.mjs
|
|
9484
|
+
const compactNumber = enhanceCodec(compact, (v) => v, Number);
|
|
9485
|
+
const compactBn = enhanceCodec(compact, (v) => v, BigInt);
|
|
9486
|
+
|
|
9487
|
+
//#endregion
|
|
9488
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/scale/Hex.mjs
|
|
9489
|
+
const enc$1 = (nBytes) => {
|
|
9490
|
+
const _enc = Bytes.enc(nBytes);
|
|
9491
|
+
return (value) => _enc(fromHex$1(value));
|
|
9492
|
+
};
|
|
9493
|
+
const dec$1 = (nBytes) => {
|
|
9494
|
+
const _dec = Bytes.dec(nBytes);
|
|
9495
|
+
return (value) => toHex(_dec(value));
|
|
9496
|
+
};
|
|
9497
|
+
const Hex = (nBytes) => createCodec(enc$1(nBytes), dec$1(nBytes));
|
|
9498
|
+
Hex.enc = enc$1;
|
|
9499
|
+
Hex.dec = dec$1;
|
|
9500
|
+
|
|
9501
|
+
//#endregion
|
|
9502
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/docs.mjs
|
|
9503
|
+
const docs = Vector(str);
|
|
9504
|
+
|
|
9505
|
+
//#endregion
|
|
9506
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/lookup.mjs
|
|
9507
|
+
const oStr = Option(str);
|
|
9508
|
+
const primitive = Enum$1({
|
|
9509
|
+
bool: _void$1,
|
|
9510
|
+
char: _void$1,
|
|
9511
|
+
str: _void$1,
|
|
9512
|
+
u8: _void$1,
|
|
9513
|
+
u16: _void$1,
|
|
9514
|
+
u32: _void$1,
|
|
9515
|
+
u64: _void$1,
|
|
9516
|
+
u128: _void$1,
|
|
9517
|
+
u256: _void$1,
|
|
9518
|
+
i8: _void$1,
|
|
9519
|
+
i16: _void$1,
|
|
9520
|
+
i32: _void$1,
|
|
9521
|
+
i64: _void$1,
|
|
9522
|
+
i128: _void$1,
|
|
9523
|
+
i256: _void$1
|
|
9524
|
+
});
|
|
9525
|
+
const fields = Vector(Struct({
|
|
9526
|
+
name: oStr,
|
|
9527
|
+
type: compactNumber,
|
|
9528
|
+
typeName: oStr,
|
|
9529
|
+
docs
|
|
9530
|
+
}));
|
|
9531
|
+
const arr = Struct({
|
|
9532
|
+
len: u32$1,
|
|
9533
|
+
type: compactNumber
|
|
9534
|
+
});
|
|
9535
|
+
const bitSequence = Struct({
|
|
9536
|
+
bitStoreType: compactNumber,
|
|
9537
|
+
bitOrderType: compactNumber
|
|
9538
|
+
});
|
|
9539
|
+
const def = Enum$1({
|
|
9540
|
+
composite: fields,
|
|
9541
|
+
variant: Vector(Struct({
|
|
9542
|
+
name: str,
|
|
9543
|
+
fields,
|
|
9544
|
+
index: u8,
|
|
9545
|
+
docs
|
|
9546
|
+
})),
|
|
9547
|
+
sequence: compactNumber,
|
|
9548
|
+
array: arr,
|
|
9549
|
+
tuple: Vector(compactNumber),
|
|
9550
|
+
primitive,
|
|
9551
|
+
compact: compactNumber,
|
|
9552
|
+
bitSequence
|
|
9553
|
+
});
|
|
9554
|
+
const lookup = Vector(Struct({
|
|
9555
|
+
id: compactNumber,
|
|
9556
|
+
path: docs,
|
|
9557
|
+
params: Vector(Struct({
|
|
9558
|
+
name: str,
|
|
9559
|
+
type: Option(compactNumber)
|
|
9560
|
+
})),
|
|
9561
|
+
def,
|
|
9562
|
+
docs
|
|
9563
|
+
}));
|
|
9564
|
+
|
|
9565
|
+
//#endregion
|
|
9566
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/deprecation.mjs
|
|
9567
|
+
const itemDeprecation = Enum$1({
|
|
9568
|
+
NotDeprecated: _void$1,
|
|
9569
|
+
DeprecatedWithoutNote: _void$1,
|
|
9570
|
+
Deprecated: Struct({
|
|
9571
|
+
note: str,
|
|
9572
|
+
since: Option(str)
|
|
9573
|
+
})
|
|
9574
|
+
});
|
|
9575
|
+
const variantDeprecation = Vector(Struct({
|
|
9576
|
+
index: u8,
|
|
9577
|
+
deprecation: Enum$1({
|
|
9578
|
+
DeprecatedWithoutNote: _void$1,
|
|
9579
|
+
Deprecated: Struct({
|
|
9580
|
+
note: str,
|
|
9581
|
+
since: Option(str)
|
|
9582
|
+
})
|
|
9583
|
+
}, [1, 2])
|
|
9584
|
+
}));
|
|
9585
|
+
|
|
9586
|
+
//#endregion
|
|
9587
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/runtime-api.mjs
|
|
9588
|
+
const runtimeApiMethod = {
|
|
9589
|
+
name: str,
|
|
9590
|
+
inputs: Vector(Struct({
|
|
9591
|
+
name: str,
|
|
9592
|
+
type: compactNumber
|
|
9593
|
+
})),
|
|
9594
|
+
output: compactNumber,
|
|
9595
|
+
docs
|
|
9596
|
+
};
|
|
9597
|
+
const runtimeApiV15 = Struct({
|
|
9598
|
+
name: str,
|
|
9599
|
+
methods: Vector(Struct(runtimeApiMethod)),
|
|
9600
|
+
docs
|
|
9601
|
+
});
|
|
9602
|
+
const runtimeApi = Struct({
|
|
9603
|
+
name: str,
|
|
9604
|
+
methods: Vector(Struct({
|
|
9605
|
+
...runtimeApiMethod,
|
|
9606
|
+
deprecationInfo: itemDeprecation
|
|
9607
|
+
})),
|
|
9608
|
+
docs,
|
|
9609
|
+
version: compactNumber,
|
|
9610
|
+
deprecationInfo: itemDeprecation
|
|
9611
|
+
});
|
|
9612
|
+
const viewFunction = Struct({
|
|
9613
|
+
id: Hex(32),
|
|
9614
|
+
...runtimeApiMethod,
|
|
9615
|
+
deprecationInfo: itemDeprecation
|
|
9616
|
+
});
|
|
9617
|
+
|
|
9618
|
+
//#endregion
|
|
9619
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/pallets.mjs
|
|
9620
|
+
const storageMap = Struct({
|
|
9621
|
+
hashers: Vector(Enum$1({
|
|
9622
|
+
Blake2128: _void$1,
|
|
9623
|
+
Blake2256: _void$1,
|
|
9624
|
+
Blake2128Concat: _void$1,
|
|
9625
|
+
Twox128: _void$1,
|
|
9626
|
+
Twox256: _void$1,
|
|
9627
|
+
Twox64Concat: _void$1,
|
|
9628
|
+
Identity: _void$1
|
|
9629
|
+
})),
|
|
9630
|
+
key: compactNumber,
|
|
9631
|
+
value: compactNumber
|
|
9632
|
+
});
|
|
9633
|
+
const storageItem = {
|
|
9634
|
+
name: str,
|
|
9635
|
+
modifier: u8,
|
|
9636
|
+
type: Enum$1({
|
|
9637
|
+
plain: compactNumber,
|
|
9638
|
+
map: storageMap
|
|
9639
|
+
}),
|
|
9640
|
+
fallback: Hex(),
|
|
9641
|
+
docs
|
|
9642
|
+
};
|
|
9643
|
+
const enumRefV14 = Option(compactNumber);
|
|
9644
|
+
const v14Pallet = {
|
|
9645
|
+
name: str,
|
|
9646
|
+
storage: Option(Struct({
|
|
9647
|
+
prefix: str,
|
|
9648
|
+
items: Vector(Struct(storageItem))
|
|
9649
|
+
})),
|
|
9650
|
+
calls: enumRefV14,
|
|
9651
|
+
events: enumRefV14,
|
|
9652
|
+
constants: Vector(Struct({
|
|
9653
|
+
name: str,
|
|
9654
|
+
type: compactNumber,
|
|
9655
|
+
value: Hex(),
|
|
9656
|
+
docs
|
|
9657
|
+
})),
|
|
9658
|
+
errors: enumRefV14,
|
|
9659
|
+
index: u8
|
|
9660
|
+
};
|
|
9661
|
+
const v15Pallet = {
|
|
9662
|
+
...v14Pallet,
|
|
9663
|
+
docs
|
|
9664
|
+
};
|
|
9665
|
+
const enumRef = Option(Struct({
|
|
9666
|
+
type: compactNumber,
|
|
9667
|
+
deprecationInfo: variantDeprecation
|
|
9668
|
+
}));
|
|
9669
|
+
const v16Pallet = {
|
|
9670
|
+
name: str,
|
|
9671
|
+
storage: Option(Struct({
|
|
9672
|
+
prefix: str,
|
|
9673
|
+
items: Vector(Struct({
|
|
9674
|
+
...storageItem,
|
|
9675
|
+
deprecationInfo: itemDeprecation
|
|
9676
|
+
}))
|
|
9677
|
+
})),
|
|
9678
|
+
calls: enumRef,
|
|
9679
|
+
events: enumRef,
|
|
9680
|
+
constants: Vector(Struct({
|
|
9681
|
+
name: str,
|
|
9682
|
+
type: compactNumber,
|
|
9683
|
+
value: Hex(),
|
|
9684
|
+
docs,
|
|
9685
|
+
deprecationInfo: itemDeprecation
|
|
9686
|
+
})),
|
|
9687
|
+
errors: enumRef,
|
|
9688
|
+
associatedTypes: Vector(Struct({
|
|
9689
|
+
name: str,
|
|
9690
|
+
type: compactNumber,
|
|
9691
|
+
docs
|
|
9692
|
+
})),
|
|
9693
|
+
viewFns: Vector(viewFunction),
|
|
9694
|
+
index: u8,
|
|
9695
|
+
docs,
|
|
9696
|
+
deprecationInfo: itemDeprecation
|
|
9697
|
+
};
|
|
9698
|
+
|
|
9699
|
+
//#endregion
|
|
9700
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/v14.mjs
|
|
9701
|
+
const empty = new Uint8Array();
|
|
9702
|
+
const Always = (value) => createCodec(() => empty, () => value);
|
|
9703
|
+
const extrinsic$2 = Struct({
|
|
9704
|
+
type: compactNumber,
|
|
9705
|
+
version: u8,
|
|
9706
|
+
signedExtensions: Vector(Struct({
|
|
9707
|
+
identifier: str,
|
|
9708
|
+
type: compactNumber,
|
|
9709
|
+
additionalSigned: compactNumber
|
|
9710
|
+
}))
|
|
9711
|
+
});
|
|
9712
|
+
const v14 = Struct({
|
|
9713
|
+
lookup,
|
|
9714
|
+
pallets: Vector(Struct({
|
|
9715
|
+
...v14Pallet,
|
|
9716
|
+
docs: Always([])
|
|
9717
|
+
})),
|
|
9718
|
+
extrinsic: extrinsic$2,
|
|
9719
|
+
type: compactNumber,
|
|
9720
|
+
apis: Always([])
|
|
9721
|
+
});
|
|
9722
|
+
|
|
9723
|
+
//#endregion
|
|
9724
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/v15.mjs
|
|
9725
|
+
const extrinsic$1 = Struct({
|
|
9726
|
+
version: u8,
|
|
9727
|
+
address: compactNumber,
|
|
9728
|
+
call: compactNumber,
|
|
9729
|
+
signature: compactNumber,
|
|
9730
|
+
extra: compactNumber,
|
|
9731
|
+
signedExtensions: Vector(Struct({
|
|
9732
|
+
identifier: str,
|
|
9733
|
+
type: compactNumber,
|
|
9734
|
+
additionalSigned: compactNumber
|
|
9735
|
+
}))
|
|
9736
|
+
});
|
|
9737
|
+
const v15 = Struct({
|
|
9738
|
+
lookup,
|
|
9739
|
+
pallets: Vector(Struct(v15Pallet)),
|
|
9740
|
+
extrinsic: extrinsic$1,
|
|
9741
|
+
type: compactNumber,
|
|
9742
|
+
apis: Vector(runtimeApiV15),
|
|
9743
|
+
outerEnums: Struct({
|
|
9744
|
+
call: compactNumber,
|
|
9745
|
+
event: compactNumber,
|
|
9746
|
+
error: compactNumber
|
|
9747
|
+
}),
|
|
9748
|
+
custom: Vector(Tuple(str, Struct({
|
|
9749
|
+
type: compactNumber,
|
|
9750
|
+
value: Hex()
|
|
9751
|
+
})))
|
|
9752
|
+
});
|
|
9753
|
+
|
|
9754
|
+
//#endregion
|
|
9755
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/v16.mjs
|
|
9756
|
+
const extrinsic = Struct({
|
|
9757
|
+
version: Vector(u8),
|
|
9758
|
+
address: compactNumber,
|
|
9759
|
+
call: compactNumber,
|
|
9760
|
+
signature: compactNumber,
|
|
9761
|
+
signedExtensionsByVersion: Vector(Tuple(u8, Vector(compactNumber))),
|
|
9762
|
+
signedExtensions: Vector(Struct({
|
|
9763
|
+
identifier: str,
|
|
9764
|
+
type: compactNumber,
|
|
9765
|
+
additionalSigned: compactNumber
|
|
9766
|
+
}))
|
|
9767
|
+
});
|
|
9768
|
+
const v16 = Struct({
|
|
9769
|
+
lookup,
|
|
9770
|
+
pallets: Vector(Struct(v16Pallet)),
|
|
9771
|
+
extrinsic,
|
|
9772
|
+
apis: Vector(runtimeApi),
|
|
9773
|
+
outerEnums: Struct({
|
|
9774
|
+
call: compactNumber,
|
|
9775
|
+
event: compactNumber,
|
|
9776
|
+
error: compactNumber
|
|
9777
|
+
}),
|
|
9778
|
+
custom: Vector(Tuple(str, Struct({
|
|
9779
|
+
type: compactNumber,
|
|
9780
|
+
value: Hex()
|
|
9781
|
+
})))
|
|
9782
|
+
});
|
|
9783
|
+
|
|
9784
|
+
//#endregion
|
|
9785
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/metadata.mjs
|
|
9786
|
+
const unsupportedFn = () => {
|
|
9787
|
+
throw new Error("Unsupported metadata version!");
|
|
9788
|
+
};
|
|
9789
|
+
const unsupported = createCodec(unsupportedFn, unsupportedFn);
|
|
9790
|
+
const metadata = Struct({
|
|
9791
|
+
magicNumber: u32$1,
|
|
9792
|
+
metadata: Enum$1({
|
|
9793
|
+
v0: unsupported,
|
|
9794
|
+
v1: unsupported,
|
|
9795
|
+
v2: unsupported,
|
|
9796
|
+
v3: unsupported,
|
|
9797
|
+
v4: unsupported,
|
|
9798
|
+
v5: unsupported,
|
|
9799
|
+
v6: unsupported,
|
|
9800
|
+
v7: unsupported,
|
|
9801
|
+
v8: unsupported,
|
|
9802
|
+
v9: unsupported,
|
|
9803
|
+
v10: unsupported,
|
|
9804
|
+
v11: unsupported,
|
|
9805
|
+
v12: unsupported,
|
|
9806
|
+
v13: unsupported,
|
|
9807
|
+
v14,
|
|
9808
|
+
v15,
|
|
9809
|
+
v16
|
|
9810
|
+
})
|
|
9811
|
+
});
|
|
9812
|
+
const opaqueBytes = Bytes();
|
|
9813
|
+
const optionOpaque = Option(opaqueBytes);
|
|
9814
|
+
const opaqueOpaqueBytes = Tuple(compact, opaqueBytes);
|
|
9815
|
+
const decAnyMetadata = (input) => {
|
|
9816
|
+
try {
|
|
9817
|
+
return metadata.dec(input);
|
|
9818
|
+
} catch (_) {}
|
|
9819
|
+
try {
|
|
9820
|
+
return metadata.dec(optionOpaque.dec(input));
|
|
9821
|
+
} catch (_) {}
|
|
9822
|
+
try {
|
|
9823
|
+
return metadata.dec(opaqueBytes.dec(input));
|
|
9824
|
+
} catch (_) {}
|
|
9825
|
+
try {
|
|
9826
|
+
return metadata.dec(opaqueOpaqueBytes.dec(input)[1]);
|
|
9827
|
+
} catch (_) {}
|
|
9828
|
+
throw null;
|
|
9829
|
+
};
|
|
9830
|
+
|
|
9831
|
+
//#endregion
|
|
9832
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/codecs/metadata/unified.mjs
|
|
9833
|
+
const unifyMetadata = (metadata$1) => {
|
|
9834
|
+
if ("magicNumber" in metadata$1) metadata$1 = metadata$1.metadata;
|
|
9835
|
+
if ("tag" in metadata$1) {
|
|
9836
|
+
if (metadata$1.tag !== "v14" && metadata$1.tag !== "v15" && metadata$1.tag !== "v16") throw new Error("Only metadata 14, 15, and 16 are supported");
|
|
9837
|
+
metadata$1 = metadata$1.value;
|
|
9838
|
+
}
|
|
9839
|
+
if ("signedExtensionsByVersion" in metadata$1.extrinsic) {
|
|
9840
|
+
const { extrinsic: { signedExtensions, signedExtensionsByVersion, ...restExtrinsic }, ...rest } = metadata$1;
|
|
9841
|
+
if (!signedExtensionsByVersion.some(([v]) => v === 0)) throw new Error("Extension version 0 not found");
|
|
9842
|
+
return {
|
|
9843
|
+
version: 16,
|
|
9844
|
+
extrinsic: {
|
|
9845
|
+
...restExtrinsic,
|
|
9846
|
+
signedExtensions: Object.fromEntries(signedExtensionsByVersion.map(([v, idxs]) => [v, idxs.map((extIdx) => signedExtensions[extIdx])]))
|
|
9847
|
+
},
|
|
9848
|
+
...rest
|
|
9849
|
+
};
|
|
9850
|
+
}
|
|
9851
|
+
if ("custom" in metadata$1) {
|
|
9852
|
+
const { lookup: lookup2, extrinsic: extrinsic2, custom, apis, pallets: pallets2, outerEnums } = metadata$1;
|
|
9853
|
+
return {
|
|
9854
|
+
version: 15,
|
|
9855
|
+
lookup: lookup2,
|
|
9856
|
+
pallets: pallets2.map((p) => ({
|
|
9857
|
+
...p,
|
|
9858
|
+
calls: p.calls != null ? { type: p.calls } : void 0,
|
|
9859
|
+
events: p.events != null ? { type: p.events } : void 0,
|
|
9860
|
+
errors: p.errors != null ? { type: p.errors } : void 0,
|
|
9861
|
+
viewFns: [],
|
|
9862
|
+
associatedTypes: []
|
|
9863
|
+
})),
|
|
9864
|
+
extrinsic: {
|
|
9865
|
+
...extrinsic2,
|
|
9866
|
+
signedExtensions: { 0: extrinsic2.signedExtensions },
|
|
9867
|
+
version: [extrinsic2.version]
|
|
9868
|
+
},
|
|
9869
|
+
apis,
|
|
9870
|
+
outerEnums,
|
|
9871
|
+
custom
|
|
9872
|
+
};
|
|
9873
|
+
}
|
|
9874
|
+
const { lookup: lookup$1, extrinsic: extrinsic$3, pallets } = metadata$1;
|
|
9875
|
+
return {
|
|
9876
|
+
version: 14,
|
|
9877
|
+
lookup: lookup$1,
|
|
9878
|
+
pallets: pallets.map((p) => ({
|
|
9879
|
+
...p,
|
|
9880
|
+
calls: p.calls != null ? { type: p.calls } : void 0,
|
|
9881
|
+
events: p.events != null ? { type: p.events } : void 0,
|
|
9882
|
+
errors: p.errors != null ? { type: p.errors } : void 0,
|
|
9883
|
+
viewFns: [],
|
|
9884
|
+
associatedTypes: []
|
|
9885
|
+
})),
|
|
9886
|
+
extrinsic: {
|
|
9887
|
+
...extrinsic$3,
|
|
9888
|
+
signedExtensions: { 0: extrinsic$3.signedExtensions },
|
|
9889
|
+
version: [extrinsic$3.version]
|
|
9890
|
+
},
|
|
9891
|
+
apis: []
|
|
9892
|
+
};
|
|
9893
|
+
};
|
|
9894
|
+
|
|
9895
|
+
//#endregion
|
|
9896
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/extrinsics/extrinsic-format.mjs
|
|
9897
|
+
const TYPES = {
|
|
9898
|
+
bare: 0,
|
|
9899
|
+
0: "bare",
|
|
9900
|
+
general: 1,
|
|
9901
|
+
1: "general",
|
|
9902
|
+
signed: 2,
|
|
9903
|
+
2: "signed"
|
|
9904
|
+
};
|
|
9905
|
+
const extrinsicFormat = enhanceCodec(u8, ({ version, type }) => version + (TYPES[type] << 6), (v) => {
|
|
9906
|
+
const version = v & 63;
|
|
9907
|
+
const type = v >> 6;
|
|
9908
|
+
if (version === 4 && (type === TYPES.bare || type === TYPES.signed)) return {
|
|
9909
|
+
version,
|
|
9910
|
+
type: TYPES[type]
|
|
9911
|
+
};
|
|
9912
|
+
if (version === 5 && (type === TYPES.bare || type === TYPES.general)) return {
|
|
9913
|
+
version,
|
|
9914
|
+
type: TYPES[type]
|
|
9915
|
+
};
|
|
9916
|
+
throw new Error(`ExtrinsicFormat ${v} not valid`);
|
|
9917
|
+
});
|
|
9918
|
+
|
|
9919
|
+
//#endregion
|
|
9920
|
+
//#region ../../node_modules/.bun/@polkadot-api+substrate-bindings@0.17.0/node_modules/@polkadot-api/substrate-bindings/dist/esm/hashes/blake2.mjs
|
|
9921
|
+
const len32$1 = { dkLen: 32 };
|
|
9922
|
+
const Blake2256 = (encoded) => blake2b(encoded, len32$1);
|
|
9923
|
+
|
|
9924
|
+
//#endregion
|
|
9925
|
+
//#region ../../node_modules/.bun/@polkadot-api+metadata-builders@0.13.9/node_modules/@polkadot-api/metadata-builders/dist/esm/lookups.mjs
|
|
9926
|
+
const isBytes = (value, nBytes) => value.type === "array" && value.len === nBytes && value.value.type === "primitive" && value.value.value === "u8";
|
|
9927
|
+
const _void = { type: "void" };
|
|
9928
|
+
const _denormalizeLookup = (lookupData, customMap = () => null) => {
|
|
9929
|
+
const lookups = /* @__PURE__ */ new Map();
|
|
9930
|
+
const from = /* @__PURE__ */ new Set();
|
|
9931
|
+
const withCache = (fn) => {
|
|
9932
|
+
return (id) => {
|
|
9933
|
+
let entry = lookups.get(id);
|
|
9934
|
+
if (entry) return entry;
|
|
9935
|
+
if (from.has(id)) {
|
|
9936
|
+
const entry2 = { id };
|
|
9937
|
+
lookups.set(id, entry2);
|
|
9938
|
+
return entry2;
|
|
9939
|
+
}
|
|
9940
|
+
from.add(id);
|
|
9941
|
+
const value = fn(id);
|
|
9942
|
+
entry = lookups.get(id);
|
|
9943
|
+
if (entry) Object.assign(entry, value);
|
|
9944
|
+
else {
|
|
9945
|
+
entry = {
|
|
9946
|
+
id,
|
|
9947
|
+
...value
|
|
9948
|
+
};
|
|
9949
|
+
lookups.set(id, entry);
|
|
9950
|
+
}
|
|
9951
|
+
from.delete(id);
|
|
9952
|
+
return entry;
|
|
9953
|
+
};
|
|
9954
|
+
};
|
|
9955
|
+
let isAccountId32SearchOn = true;
|
|
9956
|
+
let isAccountId20SearchOn = true;
|
|
9957
|
+
const getLookupEntryDef = withCache((id) => {
|
|
9958
|
+
const custom = customMap(lookupData[id]);
|
|
9959
|
+
if (custom) return custom;
|
|
9960
|
+
const { def: def$1, path, params } = lookupData[id];
|
|
9961
|
+
if (def$1.tag === "composite") {
|
|
9962
|
+
if (def$1.value.length === 0) return _void;
|
|
9963
|
+
if (def$1.value.length === 1) {
|
|
9964
|
+
const inner = getLookupEntryDef(def$1.value[0].type);
|
|
9965
|
+
if (isAccountId32SearchOn && path.at(-1) === "AccountId32" && isBytes(inner, 32)) {
|
|
9966
|
+
isAccountId32SearchOn = false;
|
|
9967
|
+
return { type: "AccountId32" };
|
|
9968
|
+
}
|
|
9969
|
+
if (isAccountId20SearchOn && path.at(-1) === "AccountId20" && isBytes(inner, 20)) {
|
|
9970
|
+
isAccountId20SearchOn = false;
|
|
9971
|
+
return { type: "AccountId20" };
|
|
9972
|
+
}
|
|
9973
|
+
return inner;
|
|
9974
|
+
}
|
|
9975
|
+
return getComplexVar(def$1.value);
|
|
9976
|
+
}
|
|
9977
|
+
if (def$1.tag === "variant") {
|
|
9978
|
+
if (path.length === 1 && path[0] === "Option" && params.length === 1 && params[0].name === "T") {
|
|
9979
|
+
const value = getLookupEntryDef(params[0].type);
|
|
9980
|
+
return value.type === "void" ? {
|
|
9981
|
+
type: "primitive",
|
|
9982
|
+
value: "bool"
|
|
9983
|
+
} : {
|
|
9984
|
+
type: "option",
|
|
9985
|
+
value
|
|
9986
|
+
};
|
|
9987
|
+
}
|
|
9988
|
+
if (path.length === 1 && path[0] === "Result" && params.length === 2 && params[0].name === "T" && params[1].name === "E") return {
|
|
9989
|
+
type: "result",
|
|
9990
|
+
value: {
|
|
9991
|
+
ok: getLookupEntryDef(params[0].type),
|
|
9992
|
+
ko: getLookupEntryDef(params[1].type)
|
|
9993
|
+
}
|
|
9994
|
+
};
|
|
9995
|
+
if (def$1.value.length === 0) return _void;
|
|
9996
|
+
const enumValue = {};
|
|
9997
|
+
const enumDocs = {};
|
|
9998
|
+
def$1.value.forEach((x) => {
|
|
9999
|
+
const key = x.name;
|
|
10000
|
+
enumDocs[key] = x.docs;
|
|
10001
|
+
if (x.fields.length === 0) {
|
|
10002
|
+
enumValue[key] = {
|
|
10003
|
+
..._void,
|
|
10004
|
+
idx: x.index
|
|
10005
|
+
};
|
|
10006
|
+
return;
|
|
10007
|
+
}
|
|
10008
|
+
if (x.fields.length === 1 && !x.fields[0].name) {
|
|
10009
|
+
enumValue[key] = {
|
|
10010
|
+
type: "lookupEntry",
|
|
10011
|
+
value: getLookupEntryDef(x.fields[0].type),
|
|
10012
|
+
idx: x.index
|
|
10013
|
+
};
|
|
10014
|
+
return;
|
|
10015
|
+
}
|
|
10016
|
+
enumValue[key] = {
|
|
10017
|
+
...getComplexVar(x.fields),
|
|
10018
|
+
idx: x.index
|
|
10019
|
+
};
|
|
10020
|
+
});
|
|
10021
|
+
return {
|
|
10022
|
+
type: "enum",
|
|
10023
|
+
value: enumValue,
|
|
10024
|
+
innerDocs: enumDocs
|
|
10025
|
+
};
|
|
10026
|
+
}
|
|
10027
|
+
if (def$1.tag === "sequence") return {
|
|
10028
|
+
type: "sequence",
|
|
10029
|
+
value: getLookupEntryDef(def$1.value)
|
|
10030
|
+
};
|
|
10031
|
+
if (def$1.tag === "array") {
|
|
10032
|
+
const { len } = def$1.value;
|
|
10033
|
+
const value = getLookupEntryDef(def$1.value.type);
|
|
10034
|
+
return !len || value.type === "void" ? _void : len > 1 ? {
|
|
10035
|
+
type: "array",
|
|
10036
|
+
value,
|
|
10037
|
+
len: def$1.value.len
|
|
10038
|
+
} : value;
|
|
10039
|
+
}
|
|
10040
|
+
if (def$1.tag === "tuple") {
|
|
10041
|
+
if (def$1.value.length === 0) return _void;
|
|
10042
|
+
return def$1.value.length > 1 ? getArrayOrTuple(def$1.value.map((x) => getLookupEntryDef(x)), def$1.value.map((x) => lookupData[x].docs)) : getLookupEntryDef(def$1.value[0]);
|
|
10043
|
+
}
|
|
10044
|
+
if (def$1.tag === "primitive") return {
|
|
10045
|
+
type: "primitive",
|
|
10046
|
+
value: def$1.value.tag
|
|
10047
|
+
};
|
|
10048
|
+
if (def$1.tag === "compact") {
|
|
10049
|
+
const translated = getLookupEntryDef(def$1.value);
|
|
10050
|
+
if (translated.type === "void") return _void;
|
|
10051
|
+
return {
|
|
10052
|
+
type: "compact",
|
|
10053
|
+
isBig: Number(translated.value.slice(1)) > 32,
|
|
10054
|
+
size: translated.value
|
|
10055
|
+
};
|
|
10056
|
+
}
|
|
10057
|
+
return {
|
|
10058
|
+
type: def$1.tag,
|
|
10059
|
+
isLSB: (lookupData[def$1.value.bitOrderType].path.at(-1) ?? "LSB").toUpperCase().startsWith("LSB")
|
|
10060
|
+
};
|
|
10061
|
+
});
|
|
10062
|
+
const getComplexVar = (input) => {
|
|
10063
|
+
let allKey = true;
|
|
10064
|
+
const values = {};
|
|
10065
|
+
const innerDocs = {};
|
|
10066
|
+
input.forEach((x, idx) => {
|
|
10067
|
+
allKey = allKey && !!x.name;
|
|
10068
|
+
const key = x.name || idx;
|
|
10069
|
+
const value = getLookupEntryDef(x.type);
|
|
10070
|
+
if (value.type !== "void") {
|
|
10071
|
+
values[key] = value;
|
|
10072
|
+
innerDocs[key] = x.docs;
|
|
10073
|
+
}
|
|
10074
|
+
});
|
|
10075
|
+
return allKey ? {
|
|
10076
|
+
type: "struct",
|
|
10077
|
+
value: values,
|
|
10078
|
+
innerDocs
|
|
10079
|
+
} : getArrayOrTuple(Object.values(values), Object.values(innerDocs));
|
|
10080
|
+
};
|
|
10081
|
+
const getArrayOrTuple = (values, innerDocs) => {
|
|
10082
|
+
if (values.every((v) => v.id === values[0].id) && innerDocs.every((doc) => !doc.length)) {
|
|
10083
|
+
const [value] = values;
|
|
10084
|
+
return value.type === "void" ? _void : {
|
|
10085
|
+
type: "array",
|
|
10086
|
+
value: values[0],
|
|
10087
|
+
len: values.length
|
|
10088
|
+
};
|
|
10089
|
+
}
|
|
10090
|
+
return {
|
|
10091
|
+
type: "tuple",
|
|
10092
|
+
value: values,
|
|
10093
|
+
innerDocs
|
|
10094
|
+
};
|
|
10095
|
+
};
|
|
10096
|
+
return getLookupEntryDef;
|
|
10097
|
+
};
|
|
10098
|
+
const getLookupFn = (metadata$1) => {
|
|
10099
|
+
const getLookupEntryDef = _denormalizeLookup(metadata$1.lookup, ({ def: def$1 }) => {
|
|
10100
|
+
if (def$1.tag === "composite") {
|
|
10101
|
+
const moduleErrorLength = getModuleErrorLength(def$1);
|
|
10102
|
+
if (moduleErrorLength) return {
|
|
10103
|
+
type: "enum",
|
|
10104
|
+
innerDocs: {},
|
|
10105
|
+
value: Object.fromEntries(metadata$1.pallets.map((p) => [p.name, p.errors == null ? {
|
|
10106
|
+
..._void,
|
|
10107
|
+
idx: p.index
|
|
10108
|
+
} : {
|
|
10109
|
+
type: "lookupEntry",
|
|
10110
|
+
value: getLookupEntryDef(p.errors.type),
|
|
10111
|
+
idx: p.index
|
|
10112
|
+
}])),
|
|
10113
|
+
byteLength: moduleErrorLength
|
|
10114
|
+
};
|
|
10115
|
+
}
|
|
10116
|
+
return null;
|
|
10117
|
+
});
|
|
10118
|
+
function getModuleErrorLength(def$1) {
|
|
10119
|
+
if (!(def$1.value.length === 2 && def$1.value[0].name === "index" && def$1.value[1].name === "error")) return null;
|
|
10120
|
+
const index = getLookupEntryDef(def$1.value[0].type);
|
|
10121
|
+
const error = getLookupEntryDef(def$1.value[1].type);
|
|
10122
|
+
return index.type === "primitive" && index.value === "u8" && error.type === "array" && error.value.type === "primitive" && error.value.value === "u8" ? 1 + error.len : null;
|
|
10123
|
+
}
|
|
10124
|
+
const getCall = () => {
|
|
10125
|
+
if ("call" in metadata$1.extrinsic) return metadata$1.extrinsic.call;
|
|
10126
|
+
return (metadata$1.lookup[metadata$1.extrinsic.type]?.params.find((p) => p.name === "Call"))?.type ?? null;
|
|
10127
|
+
};
|
|
10128
|
+
return Object.assign(getLookupEntryDef, {
|
|
10129
|
+
metadata: metadata$1,
|
|
10130
|
+
call: getCall()
|
|
10131
|
+
});
|
|
10132
|
+
};
|
|
10133
|
+
|
|
10134
|
+
//#endregion
|
|
10135
|
+
//#region ../../node_modules/.bun/@polkadot-api+signers-common@0.1.20/node_modules/@polkadot-api/signers-common/dist/esm/v4.mjs
|
|
10136
|
+
const unkownSignerType = () => /* @__PURE__ */ new Error("Unkown signer");
|
|
10137
|
+
const getSignerType = (metadata$1) => {
|
|
10138
|
+
const { extrinsic: extrinsic$3 } = metadata$1;
|
|
10139
|
+
const getLookup = getLookupFn(metadata$1);
|
|
10140
|
+
let address;
|
|
10141
|
+
let signature;
|
|
10142
|
+
if ("address" in extrinsic$3) {
|
|
10143
|
+
address = getLookup(extrinsic$3.address);
|
|
10144
|
+
signature = getLookup(extrinsic$3.signature);
|
|
10145
|
+
} else {
|
|
10146
|
+
const extProps = Object.fromEntries(metadata$1.lookup[extrinsic$3.type].params.filter((x) => x.type != null).map((x) => [x.name, getLookup(x.type)]));
|
|
10147
|
+
address = extProps["Address"];
|
|
10148
|
+
signature = extProps["Signature"];
|
|
10149
|
+
if (!address || !signature) throw unkownSignerType();
|
|
10150
|
+
}
|
|
10151
|
+
if (address.type === "AccountId20" && signature.type === "array" && signature.len === 65 && signature.value.type === "primitive" && signature.value.value === "u8") return [1, []];
|
|
10152
|
+
if (signature.type !== "enum" || [
|
|
10153
|
+
"Ecdsa",
|
|
10154
|
+
"Ed25519",
|
|
10155
|
+
"Sr25519"
|
|
10156
|
+
].some((x) => !(x in signature.value))) throw unkownSignerType();
|
|
10157
|
+
if (address.type === "enum") {
|
|
10158
|
+
const id = address.value["Id"];
|
|
10159
|
+
if (id.type === "lookupEntry" && id.value.type === "AccountId32") return [0, [id.idx]];
|
|
10160
|
+
} else if (address.type === "AccountId32") return [0, []];
|
|
10161
|
+
throw unkownSignerType();
|
|
10162
|
+
};
|
|
10163
|
+
const signingTypeId = {
|
|
10164
|
+
Ed25519: 0,
|
|
10165
|
+
Sr25519: 1,
|
|
10166
|
+
Ecdsa: 2
|
|
10167
|
+
};
|
|
10168
|
+
const createV4Tx = (metadata$1, publicKey, signed, extra, callData, signingType) => {
|
|
10169
|
+
const [signerType, addressPrefix] = getSignerType(metadata$1);
|
|
10170
|
+
const preResult = mergeUint8$1([
|
|
10171
|
+
extrinsicFormat.enc({
|
|
10172
|
+
version: 4,
|
|
10173
|
+
type: "signed"
|
|
10174
|
+
}),
|
|
10175
|
+
signerType === 1 ? publicKey : new Uint8Array([...addressPrefix, ...publicKey]),
|
|
10176
|
+
signerType === 1 || !signingType ? signed : new Uint8Array([signingTypeId[signingType], ...signed]),
|
|
10177
|
+
...extra,
|
|
10178
|
+
callData
|
|
10179
|
+
]);
|
|
10180
|
+
return mergeUint8$1([compact.enc(preResult.length), preResult]);
|
|
10181
|
+
};
|
|
10182
|
+
|
|
10183
|
+
//#endregion
|
|
10184
|
+
//#region ../../node_modules/.bun/@polkadot-api+signers-common@0.1.20/node_modules/@polkadot-api/signers-common/dist/esm/sign-bytes.mjs
|
|
10185
|
+
const [preBytes, postBytes] = ["<Bytes>", "</Bytes>"].map((str$1) => Binary$1.fromText(str$1).asBytes());
|
|
10186
|
+
const getSignBytes = (sign) => async (data) => {
|
|
10187
|
+
let isPadded = true;
|
|
10188
|
+
let i;
|
|
10189
|
+
for (i = 0; isPadded && i < preBytes.length; i++) isPadded = preBytes[i] === data[i];
|
|
10190
|
+
isPadded = isPadded && i === preBytes.length;
|
|
10191
|
+
const postDataStart = data.length - postBytes.length;
|
|
10192
|
+
for (i = 0; isPadded && i < postBytes.length; i++) isPadded = postBytes[i] === data[postDataStart + i];
|
|
10193
|
+
isPadded = isPadded && i === postBytes.length;
|
|
10194
|
+
return sign(isPadded ? data : mergeUint8$1([
|
|
10195
|
+
preBytes,
|
|
10196
|
+
data,
|
|
10197
|
+
postBytes
|
|
10198
|
+
]));
|
|
10199
|
+
};
|
|
10200
|
+
|
|
10201
|
+
//#endregion
|
|
10202
|
+
//#region ../../node_modules/.bun/@polkadot-api+signer@0.2.13/node_modules/@polkadot-api/signer/dist/esm/from-raw-signer.mjs
|
|
10203
|
+
function getPolkadotSigner(publicKey, signingType, sign) {
|
|
10204
|
+
const signTx = async (callData, signedExtensions, metadata$1, _, hasher = Blake2256) => {
|
|
10205
|
+
const decMeta = unifyMetadata(decAnyMetadata(metadata$1));
|
|
10206
|
+
const extra = [];
|
|
10207
|
+
const additionalSigned = [];
|
|
10208
|
+
decMeta.extrinsic.signedExtensions[0].map(({ identifier }) => {
|
|
10209
|
+
const signedExtension = signedExtensions[identifier];
|
|
10210
|
+
if (!signedExtension) throw new Error(`Missing ${identifier} signed extension`);
|
|
10211
|
+
extra.push(signedExtension.value);
|
|
10212
|
+
additionalSigned.push(signedExtension.additionalSigned);
|
|
10213
|
+
});
|
|
10214
|
+
const toSign = mergeUint8$1([
|
|
10215
|
+
callData,
|
|
10216
|
+
...extra,
|
|
10217
|
+
...additionalSigned
|
|
10218
|
+
]);
|
|
10219
|
+
return createV4Tx(decMeta, publicKey, await sign(toSign.length > 256 ? hasher(toSign) : toSign), extra, callData, signingType);
|
|
10220
|
+
};
|
|
10221
|
+
return {
|
|
10222
|
+
publicKey,
|
|
10223
|
+
signTx,
|
|
10224
|
+
signBytes: getSignBytes(sign)
|
|
10225
|
+
};
|
|
10226
|
+
}
|
|
10227
|
+
const oneU8 = Uint8Array.from([1]);
|
|
10228
|
+
|
|
7701
10229
|
//#endregion
|
|
7702
10230
|
//#region src/wallet/signer.ts
|
|
7703
10231
|
function createSr25519SignerFromKeypair(keypair) {
|
|
@@ -8117,12 +10645,12 @@ function formatBlockDuration(blocks, options = {}) {
|
|
|
8117
10645
|
* ```
|
|
8118
10646
|
*/
|
|
8119
10647
|
function concatBytes(...arrays) {
|
|
8120
|
-
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
10648
|
+
const totalLength = arrays.reduce((sum, arr$1) => sum + arr$1.length, 0);
|
|
8121
10649
|
const result = new Uint8Array(totalLength);
|
|
8122
10650
|
let offset = 0;
|
|
8123
|
-
for (const arr of arrays) {
|
|
8124
|
-
result.set(arr, offset);
|
|
8125
|
-
offset += arr.length;
|
|
10651
|
+
for (const arr$1 of arrays) {
|
|
10652
|
+
result.set(arr$1, offset);
|
|
10653
|
+
offset += arr$1.length;
|
|
8126
10654
|
}
|
|
8127
10655
|
return result;
|
|
8128
10656
|
}
|
|
@@ -8194,8 +10722,8 @@ function extractSelectorHex(callData) {
|
|
|
8194
10722
|
* @param hex - Hex string with or without 0x prefix
|
|
8195
10723
|
* @returns Normalized hex string with 0x prefix
|
|
8196
10724
|
*/
|
|
8197
|
-
function normalizeHex(hex) {
|
|
8198
|
-
return `0x${(hex.startsWith("0x") ? hex.slice(2) : hex).toLowerCase()}`;
|
|
10725
|
+
function normalizeHex(hex$1) {
|
|
10726
|
+
return `0x${(hex$1.startsWith("0x") ? hex$1.slice(2) : hex$1).toLowerCase()}`;
|
|
8199
10727
|
}
|
|
8200
10728
|
/**
|
|
8201
10729
|
* Convert a selector string (with or without 0x) to Uint8Array
|