@leofcoin/chain 1.10.9 → 1.10.11
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/exports/beacon-envelope.js +68 -0
- package/exports/beacon-epoch.js +117 -0
- package/exports/beacon-lifecycle.js +155 -0
- package/exports/beacon-round.js +77 -0
- package/exports/beacon-wire.js +98 -0
- package/exports/beacon.js +141 -0
- package/exports/browser/beacon-envelope.js +163 -0
- package/exports/browser/beacon-epoch.js +116 -0
- package/exports/browser/beacon-lifecycle.js +154 -0
- package/exports/browser/beacon-round.js +76 -0
- package/exports/browser/beacon-wire.js +99 -0
- package/exports/browser/beacon.js +1706 -0
- package/exports/browser/{browser-D-r0O9Qn-BZDYY6cg.js → browser-CWeoyGUw-BabtHowB.js} +4 -2
- package/exports/browser/{browser-_hiyXwPp-DYI1tyUr.js → browser-DvU1xNFS-sdlKNCJc.js} +4 -2
- package/exports/browser/chain.js +174 -5008
- package/exports/browser/{client-BVhUamQG-D-D1e_x8.js → client-B-jyclOB-CsNYfj4Z.js} +6 -4
- package/exports/browser/constants-Cv0p224A.js +130 -0
- package/exports/browser/hkdf-DhdhLAAv.js +147 -0
- package/exports/browser/{index-BD0Anx7_-Dg4_tCeN.js → index-Bxr5Iztg-C6xBk0rK.js} +4 -2
- package/exports/browser/index-CvKt4UDE.js +464 -0
- package/exports/browser/index-D7FUx7Dd.js +4996 -0
- package/exports/browser/{messages-UKnuelZ7-DJT-98q-.js → messages-FMRAS8QX-CvlZBzy5.js} +4 -2
- package/exports/browser/{node-browser-DlzZ5CP_.js → node-browser-xlqSBOaN.js} +12 -5
- package/exports/browser/node-browser.js +4 -2
- package/exports/browser/{constants-gMYZLHKp.js → proposal.proto-BcUgd885.js} +61 -620
- package/exports/browser/quorum-S_qdgiAY.js +8 -0
- package/exports/browser/weierstrass-C-jX_jly.js +2156 -0
- package/exports/browser/workers/block-worker.js +1 -1
- package/exports/browser/workers/machine-worker.js +7142 -72
- package/exports/browser/workers/{worker-CZqErLI7-BxofVJAn.js → worker-DMCj1e6z-CTYVa2yX.js} +30 -1
- package/exports/chain.js +158 -75
- package/exports/{constants-D6gWzJZg.js → constants-CMYKv-Rt.js} +1 -1
- package/exports/node.js +1 -1
- package/exports/quorum-S_qdgiAY.js +8 -0
- package/exports/workers/block-worker.js +1 -1
- package/exports/workers/machine-worker.js +7142 -72
- package/exports/workers/{worker-CZqErLI7-BxofVJAn.js → worker-DMCj1e6z-CTYVa2yX.js} +30 -1
- package/package.json +29 -2
- package/types/beacon-envelope.d.ts +27 -0
- package/types/beacon-epoch.d.ts +28 -0
- package/types/beacon-lifecycle.d.ts +40 -0
- package/types/beacon-round.d.ts +18 -0
- package/types/beacon-wire.d.ts +31 -0
- package/types/beacon.d.ts +24 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
// base-x encoding / decoding
|
|
2
|
+
// Copyright (c) 2018 base-x contributors
|
|
3
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
4
|
+
// Copyright (c) 2026 Vandeuren Glenn
|
|
5
|
+
// Distributed under the MIT software license, see the accompanying
|
|
6
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
7
|
+
const base = (ALPHABET, options = {}) => {
|
|
8
|
+
if (ALPHABET.length >= 255) {
|
|
9
|
+
throw new TypeError("Alphabet too long");
|
|
10
|
+
}
|
|
11
|
+
const BASE_MAP = new Uint8Array(256);
|
|
12
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
13
|
+
BASE_MAP[j] = 255;
|
|
14
|
+
}
|
|
15
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
16
|
+
const x = ALPHABET.charAt(i);
|
|
17
|
+
const xc = x.charCodeAt(0);
|
|
18
|
+
if (BASE_MAP[xc] !== 255) {
|
|
19
|
+
throw new TypeError(x + " is ambiguous");
|
|
20
|
+
}
|
|
21
|
+
BASE_MAP[xc] = i;
|
|
22
|
+
}
|
|
23
|
+
const BASE = ALPHABET.length;
|
|
24
|
+
const LEADER = ALPHABET.charAt(0);
|
|
25
|
+
const LEADER_CODE = ALPHABET.charCodeAt(0);
|
|
26
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
27
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
28
|
+
// Optimization: If BASE is a power of 2, we can use bitwise operations
|
|
29
|
+
// This is much faster than the generic algorithm (approx 10x-20x)
|
|
30
|
+
const isPowerOfTwo = (BASE & (BASE - 1)) === 0;
|
|
31
|
+
if (isPowerOfTwo) {
|
|
32
|
+
const k = Math.log2(BASE);
|
|
33
|
+
const mask = (1 << k) - 1;
|
|
34
|
+
if (options.rfc4648) {
|
|
35
|
+
// RFC 4648 Mode
|
|
36
|
+
const encode = (source) => {
|
|
37
|
+
if (source instanceof Uint8Array) ;
|
|
38
|
+
else if (ArrayBuffer.isView(source)) {
|
|
39
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
40
|
+
}
|
|
41
|
+
else if (Array.isArray(source)) {
|
|
42
|
+
source = Uint8Array.from(source);
|
|
43
|
+
}
|
|
44
|
+
if (!(source instanceof Uint8Array)) {
|
|
45
|
+
throw new TypeError("Expected Uint8Array");
|
|
46
|
+
}
|
|
47
|
+
if (source.length === 0) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
let str = "";
|
|
51
|
+
let currentValue = 0;
|
|
52
|
+
let currentBits = 0;
|
|
53
|
+
for (let i = 0; i < source.length; i++) {
|
|
54
|
+
currentValue = (currentValue << 8) | source[i];
|
|
55
|
+
currentBits += 8;
|
|
56
|
+
while (currentBits >= k) {
|
|
57
|
+
currentBits -= k;
|
|
58
|
+
str += ALPHABET.charAt((currentValue >>> currentBits) & mask);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Leftover bits (padding logic for the last character)
|
|
62
|
+
if (currentBits > 0) {
|
|
63
|
+
str += ALPHABET.charAt((currentValue << (k - currentBits)) & mask);
|
|
64
|
+
}
|
|
65
|
+
// Add padding chars '=' if required
|
|
66
|
+
while ((str.length * k) % 8 !== 0) {
|
|
67
|
+
str += "=";
|
|
68
|
+
}
|
|
69
|
+
return str;
|
|
70
|
+
};
|
|
71
|
+
const decodeUnsafe = (source) => {
|
|
72
|
+
if (typeof source !== "string") {
|
|
73
|
+
throw new TypeError("Expected String");
|
|
74
|
+
}
|
|
75
|
+
if (source.length === 0) {
|
|
76
|
+
return new Uint8Array();
|
|
77
|
+
}
|
|
78
|
+
// Strip padding
|
|
79
|
+
let end = source.length;
|
|
80
|
+
while (end > 0 && source[end - 1] === "=") {
|
|
81
|
+
end--;
|
|
82
|
+
}
|
|
83
|
+
source = source.substring(0, end);
|
|
84
|
+
let currentValue = 0;
|
|
85
|
+
let currentBits = 0;
|
|
86
|
+
// Estimate size: source.length * k / 8
|
|
87
|
+
const buffer = new Uint8Array((source.length * k) >>> 3);
|
|
88
|
+
let ptr = 0;
|
|
89
|
+
for (let i = 0; i < source.length; i++) {
|
|
90
|
+
const char = source.charCodeAt(i);
|
|
91
|
+
const val = BASE_MAP[char];
|
|
92
|
+
if (val === 255)
|
|
93
|
+
return undefined;
|
|
94
|
+
currentValue = (currentValue << k) | val;
|
|
95
|
+
currentBits += k;
|
|
96
|
+
if (currentBits >= 8) {
|
|
97
|
+
currentBits -= 8;
|
|
98
|
+
buffer[ptr++] = (currentValue >>> currentBits) & 0xff;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return buffer;
|
|
102
|
+
};
|
|
103
|
+
const decode = (string) => {
|
|
104
|
+
const buffer = decodeUnsafe(string);
|
|
105
|
+
if (buffer)
|
|
106
|
+
return buffer;
|
|
107
|
+
throw new Error("Non-base" + BASE + " character");
|
|
108
|
+
};
|
|
109
|
+
return { encode, decodeUnsafe, decode };
|
|
110
|
+
}
|
|
111
|
+
// Standard Mode (Bitwise)
|
|
112
|
+
const encode = (source) => {
|
|
113
|
+
if (source instanceof Uint8Array) ;
|
|
114
|
+
else if (ArrayBuffer.isView(source)) {
|
|
115
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
116
|
+
}
|
|
117
|
+
else if (Array.isArray(source)) {
|
|
118
|
+
source = Uint8Array.from(source);
|
|
119
|
+
}
|
|
120
|
+
if (!(source instanceof Uint8Array)) {
|
|
121
|
+
throw new TypeError("Expected Uint8Array");
|
|
122
|
+
}
|
|
123
|
+
if (source.length === 0) {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
let zeroes = 0;
|
|
127
|
+
let pbegin = 0;
|
|
128
|
+
const pend = source.length;
|
|
129
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
130
|
+
pbegin++;
|
|
131
|
+
zeroes++;
|
|
132
|
+
}
|
|
133
|
+
let str = LEADER.repeat(zeroes);
|
|
134
|
+
if (pbegin === pend)
|
|
135
|
+
return str;
|
|
136
|
+
// Bitwise conversion
|
|
137
|
+
let currentValue = 0;
|
|
138
|
+
let currentBits = 0;
|
|
139
|
+
const totalBits = (pend - pbegin) * 8;
|
|
140
|
+
let remainder = totalBits % k;
|
|
141
|
+
// Handling the initial alignment to the most significant bits
|
|
142
|
+
// If total bits isn't divisible by k, the first digit uses 'remainder' bits
|
|
143
|
+
if (remainder === 0)
|
|
144
|
+
remainder = k; // effectively divisible, treating first k bits normally
|
|
145
|
+
let seenNonZero = false;
|
|
146
|
+
let firstChunk = true;
|
|
147
|
+
for (let i = pbegin; i < pend; i++) {
|
|
148
|
+
currentValue = (currentValue << 8) | source[i];
|
|
149
|
+
currentBits += 8;
|
|
150
|
+
while (currentBits >= k || (firstChunk && currentBits >= remainder)) {
|
|
151
|
+
let bitsToExtract = k;
|
|
152
|
+
if (firstChunk) {
|
|
153
|
+
if (totalBits % k !== 0) {
|
|
154
|
+
bitsToExtract = totalBits % k;
|
|
155
|
+
}
|
|
156
|
+
firstChunk = false;
|
|
157
|
+
}
|
|
158
|
+
const shift = currentBits - bitsToExtract;
|
|
159
|
+
const digit = (currentValue >>> shift) & ((1 << bitsToExtract) - 1);
|
|
160
|
+
currentBits -= bitsToExtract;
|
|
161
|
+
if (seenNonZero || digit !== 0) {
|
|
162
|
+
str += ALPHABET.charAt(digit);
|
|
163
|
+
seenNonZero = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return str;
|
|
168
|
+
};
|
|
169
|
+
const decodeUnsafe = (source) => {
|
|
170
|
+
if (typeof source !== "string") {
|
|
171
|
+
throw new TypeError("Expected String");
|
|
172
|
+
}
|
|
173
|
+
if (source.length === 0) {
|
|
174
|
+
return new Uint8Array();
|
|
175
|
+
}
|
|
176
|
+
let psz = 0;
|
|
177
|
+
let zeroes = 0;
|
|
178
|
+
while (source.charCodeAt(psz) === LEADER_CODE) {
|
|
179
|
+
zeroes++;
|
|
180
|
+
psz++;
|
|
181
|
+
}
|
|
182
|
+
// Accumulate bits
|
|
183
|
+
// We must handle alignment.
|
|
184
|
+
const length = source.length - psz;
|
|
185
|
+
const totalBits = length * k;
|
|
186
|
+
let currentBits = (8 - (totalBits % 8)) % 8; // align to byte boundary
|
|
187
|
+
const result = new Uint8Array((totalBits + 7) >>> 3); // (totalBits + 7) / 8
|
|
188
|
+
let rIdx = 0;
|
|
189
|
+
let currentValue = 0;
|
|
190
|
+
for (let i = psz; i < source.length; i++) {
|
|
191
|
+
const char = source.charCodeAt(i);
|
|
192
|
+
const val = BASE_MAP[char];
|
|
193
|
+
if (val === 255)
|
|
194
|
+
return;
|
|
195
|
+
currentValue = (currentValue << k) | val;
|
|
196
|
+
currentBits += k;
|
|
197
|
+
if (currentBits >= 8) {
|
|
198
|
+
const shift = currentBits - 8;
|
|
199
|
+
result[rIdx++] = (currentValue >>> shift) & 0xff;
|
|
200
|
+
currentBits -= 8;
|
|
201
|
+
// Keep only the remaining bits to avoid overflow
|
|
202
|
+
currentValue &= (1 << currentBits) - 1;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Skip leading zeroes in result buffer
|
|
206
|
+
let skip = 0;
|
|
207
|
+
while (skip < rIdx && result[skip] === 0) {
|
|
208
|
+
skip++;
|
|
209
|
+
}
|
|
210
|
+
// Combine with zeroes
|
|
211
|
+
const final = new Uint8Array(zeroes + (rIdx - skip));
|
|
212
|
+
// zeroes are 0, so just copy result
|
|
213
|
+
final.set(result.subarray(skip, rIdx), zeroes);
|
|
214
|
+
return final;
|
|
215
|
+
};
|
|
216
|
+
const decode = (string) => {
|
|
217
|
+
const buffer = decodeUnsafe(string);
|
|
218
|
+
if (buffer)
|
|
219
|
+
return buffer;
|
|
220
|
+
throw new Error("Non-base" + BASE + " character");
|
|
221
|
+
};
|
|
222
|
+
return { encode, decodeUnsafe, decode };
|
|
223
|
+
}
|
|
224
|
+
const encode = (source) => {
|
|
225
|
+
if (source instanceof Uint8Array) ;
|
|
226
|
+
else if (ArrayBuffer.isView(source)) {
|
|
227
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
228
|
+
}
|
|
229
|
+
else if (Array.isArray(source)) {
|
|
230
|
+
source = Uint8Array.from(source);
|
|
231
|
+
}
|
|
232
|
+
if (!(source instanceof Uint8Array)) {
|
|
233
|
+
throw new TypeError("Expected Uint8Array");
|
|
234
|
+
}
|
|
235
|
+
if (source.length === 0) {
|
|
236
|
+
return "";
|
|
237
|
+
}
|
|
238
|
+
// Skip & count leading zeroes.
|
|
239
|
+
let zeroes = 0;
|
|
240
|
+
let length = 0;
|
|
241
|
+
let pbegin = 0;
|
|
242
|
+
const pend = source.length;
|
|
243
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
244
|
+
pbegin++;
|
|
245
|
+
zeroes++;
|
|
246
|
+
}
|
|
247
|
+
// Allocate enough space in big-endian base58 representation.
|
|
248
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
249
|
+
const b58 = new Uint8Array(size);
|
|
250
|
+
// Process the bytes.
|
|
251
|
+
while (pbegin !== pend) {
|
|
252
|
+
let carry = source[pbegin];
|
|
253
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
254
|
+
let i = 0;
|
|
255
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && it1 !== -1; it1--, i++) {
|
|
256
|
+
carry += (b58[it1] << 8) >>> 0;
|
|
257
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
258
|
+
carry = (carry / BASE) >>> 0;
|
|
259
|
+
}
|
|
260
|
+
if (carry !== 0) {
|
|
261
|
+
throw new Error("Non-zero carry");
|
|
262
|
+
}
|
|
263
|
+
length = i;
|
|
264
|
+
pbegin++;
|
|
265
|
+
}
|
|
266
|
+
// Skip leading zeroes in base58 result.
|
|
267
|
+
let it2 = size - length;
|
|
268
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
269
|
+
it2++;
|
|
270
|
+
}
|
|
271
|
+
// Translate the result into a string.
|
|
272
|
+
let str = LEADER.repeat(zeroes);
|
|
273
|
+
for (; it2 < size; ++it2) {
|
|
274
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
275
|
+
}
|
|
276
|
+
return str;
|
|
277
|
+
};
|
|
278
|
+
const decodeUnsafe = (source) => {
|
|
279
|
+
if (typeof source !== "string") {
|
|
280
|
+
throw new TypeError("Expected String");
|
|
281
|
+
}
|
|
282
|
+
if (source.length === 0) {
|
|
283
|
+
return new Uint8Array();
|
|
284
|
+
}
|
|
285
|
+
let psz = 0;
|
|
286
|
+
// Skip and count leading '1's.
|
|
287
|
+
let zeroes = 0;
|
|
288
|
+
let length = 0;
|
|
289
|
+
while (source.charCodeAt(psz) === LEADER_CODE) {
|
|
290
|
+
zeroes++;
|
|
291
|
+
psz++;
|
|
292
|
+
}
|
|
293
|
+
// Allocate enough space in big-endian base256 representation.
|
|
294
|
+
const size = ((source.length - psz) * FACTOR + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
295
|
+
let b256 = new Uint8Array(size);
|
|
296
|
+
// Process the characters.
|
|
297
|
+
for (; psz < source.length; psz++) {
|
|
298
|
+
// Decode character
|
|
299
|
+
let carry = BASE_MAP[source.charCodeAt(psz)];
|
|
300
|
+
// Invalid character
|
|
301
|
+
if (carry === 255) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
let i = 0;
|
|
305
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && it3 !== -1; it3--, i++) {
|
|
306
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
307
|
+
b256[it3] = (carry & 0xff) >>> 0;
|
|
308
|
+
carry = (carry >> 8) >>> 0;
|
|
309
|
+
}
|
|
310
|
+
if (carry !== 0) {
|
|
311
|
+
throw new Error("Non-zero carry");
|
|
312
|
+
}
|
|
313
|
+
length = i;
|
|
314
|
+
}
|
|
315
|
+
// Skip leading zeroes in b256.
|
|
316
|
+
let it4 = size - length;
|
|
317
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
318
|
+
it4++;
|
|
319
|
+
}
|
|
320
|
+
let vch = new Uint8Array(zeroes + (size - it4));
|
|
321
|
+
let j = zeroes;
|
|
322
|
+
while (it4 !== size) {
|
|
323
|
+
vch[j++] = b256[it4++];
|
|
324
|
+
}
|
|
325
|
+
return vch;
|
|
326
|
+
};
|
|
327
|
+
const decode = (string) => {
|
|
328
|
+
const buffer = decodeUnsafe(string);
|
|
329
|
+
if (buffer) {
|
|
330
|
+
return buffer;
|
|
331
|
+
}
|
|
332
|
+
throw new Error("Non-base" + BASE + " character");
|
|
333
|
+
};
|
|
334
|
+
return {
|
|
335
|
+
encode,
|
|
336
|
+
decodeUnsafe,
|
|
337
|
+
decode,
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const ALPHABET$3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
342
|
+
const ALPHABET_HEX$1 = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
343
|
+
const base32 = base(ALPHABET$3);
|
|
344
|
+
const base32Hex = base(ALPHABET_HEX$1);
|
|
345
|
+
const decode$1 = base32.decode;
|
|
346
|
+
const decodeHex$1 = base32Hex.decode;
|
|
347
|
+
const encode$1 = base32.encode;
|
|
348
|
+
const encodeHex$1 = base32Hex.encode;
|
|
349
|
+
const isBase32 = (string, hex = false) => {
|
|
350
|
+
try {
|
|
351
|
+
if (hex)
|
|
352
|
+
decodeHex$1(string);
|
|
353
|
+
else
|
|
354
|
+
decode$1(string);
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
catch (e) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
const isBase32Hex = (string) => {
|
|
362
|
+
return isBase32(string, true);
|
|
363
|
+
};
|
|
364
|
+
var index$1 = {
|
|
365
|
+
encode: encode$1,
|
|
366
|
+
decode: decode$1,
|
|
367
|
+
encodeHex: encodeHex$1,
|
|
368
|
+
decodeHex: decodeHex$1,
|
|
369
|
+
isBase32,
|
|
370
|
+
isBase32Hex,
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const ALPHABET$2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
374
|
+
const ALPHABET_HEX = "0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv";
|
|
375
|
+
const base58 = base(ALPHABET$2);
|
|
376
|
+
const base58Hex = base(ALPHABET_HEX);
|
|
377
|
+
const encode = base58.encode;
|
|
378
|
+
const decode = base58.decode;
|
|
379
|
+
const encodeHex = base58Hex.encode;
|
|
380
|
+
const decodeHex = base58Hex.decode;
|
|
381
|
+
const isBase58 = (string) => {
|
|
382
|
+
try {
|
|
383
|
+
decode(string);
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
catch (e) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
const isBase58Hex = (string) => {
|
|
391
|
+
try {
|
|
392
|
+
decodeHex(string);
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
catch (e) {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
const whatType = (string) => {
|
|
400
|
+
try {
|
|
401
|
+
decode(string);
|
|
402
|
+
return "base58";
|
|
403
|
+
}
|
|
404
|
+
catch (e) {
|
|
405
|
+
try {
|
|
406
|
+
decodeHex(string);
|
|
407
|
+
return "base58Hex";
|
|
408
|
+
}
|
|
409
|
+
catch {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
var base58$1 = {
|
|
415
|
+
encode,
|
|
416
|
+
decode,
|
|
417
|
+
isBase58,
|
|
418
|
+
isBase58Hex,
|
|
419
|
+
encodeHex,
|
|
420
|
+
decodeHex,
|
|
421
|
+
whatType,
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const ALPHABET$1 = '0123456789ABCDEF';
|
|
425
|
+
const base16 = base(ALPHABET$1);
|
|
426
|
+
base16.decode;
|
|
427
|
+
base16.encode;
|
|
428
|
+
|
|
429
|
+
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
430
|
+
const base64 = base(ALPHABET);
|
|
431
|
+
base64.decode;
|
|
432
|
+
base64.encode;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Returns a Uint8Array as String
|
|
436
|
+
* @param uint8Array Uint8Array to encode to String
|
|
437
|
+
* @returns String
|
|
438
|
+
*/
|
|
439
|
+
const toString = (uint8Array) => new TextDecoder().decode(uint8Array);
|
|
440
|
+
/**
|
|
441
|
+
* hexString -> uint8Array
|
|
442
|
+
* @param string hex encoded string
|
|
443
|
+
* @returns UintArray
|
|
444
|
+
*/
|
|
445
|
+
const fromHex = (string) => Uint8Array.from(string.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
446
|
+
/**
|
|
447
|
+
* uint8Array -> hexString
|
|
448
|
+
* @param bytes number[]
|
|
449
|
+
* @returns hexString
|
|
450
|
+
*/
|
|
451
|
+
const toHex = (bytes) => bytes.reduce((string, byte) => string + byte.toString(16).padStart(2, '0'), '');
|
|
452
|
+
/**
|
|
453
|
+
* number[] -> Uint8Array
|
|
454
|
+
* @param array number[]
|
|
455
|
+
* @returns Uint8Array
|
|
456
|
+
*/
|
|
457
|
+
const fromArrayLike = (array) => Uint8Array.from(array);
|
|
458
|
+
const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
|
|
459
|
+
const fromBase58 = (string) => base58$1.decode(string);
|
|
460
|
+
const toBase32 = (uint8Array) => index$1.encode(uint8Array);
|
|
461
|
+
var index = {
|
|
462
|
+
toString};
|
|
463
|
+
|
|
464
|
+
export { index as a, base58$1 as b, fromHex as c, fromArrayLike as d, toBase32 as e, fromBase58 as f, toHex as g, index$1 as i, toBase58 as t };
|