@fleet-sdk/blockchain-providers 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2,7 +2,508 @@ import { some, ensureDefaults, clearUndefined, isEmpty, BlockchainProviderError,
2
2
  import { ErgoAddress } from '@fleet-sdk/core';
3
3
 
4
4
  // src/ergo-graphql/ergoGraphQLProvider.ts
5
- new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
5
+
6
+ // ../../node_modules/.pnpm/@noble+hashes@1.7.2/node_modules/@noble/hashes/esm/_assert.js
7
+ function isBytes(a) {
8
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
9
+ }
10
+ function abytes(b, ...lengths) {
11
+ if (!isBytes(b))
12
+ throw new Error("Uint8Array expected");
13
+ if (lengths.length > 0 && !lengths.includes(b.length))
14
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
15
+ }
16
+ function aexists(instance, checkFinished = true) {
17
+ if (instance.destroyed)
18
+ throw new Error("Hash instance has been destroyed");
19
+ if (checkFinished && instance.finished)
20
+ throw new Error("Hash#digest() has already been called");
21
+ }
22
+ function aoutput(out, instance) {
23
+ abytes(out);
24
+ const min = instance.outputLen;
25
+ if (out.length < min) {
26
+ throw new Error("digestInto() expects output buffer of length at least " + min);
27
+ }
28
+ }
29
+
30
+ // ../../node_modules/.pnpm/@noble+hashes@1.7.2/node_modules/@noble/hashes/esm/utils.js
31
+ function createView(arr) {
32
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
33
+ }
34
+ function rotr(word, shift) {
35
+ return word << 32 - shift | word >>> shift;
36
+ }
37
+ (
38
+ // @ts-ignore
39
+ typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
40
+ );
41
+ function utf8ToBytes(str) {
42
+ if (typeof str !== "string")
43
+ throw new Error("utf8ToBytes expected string, got " + typeof str);
44
+ return new Uint8Array(new TextEncoder().encode(str));
45
+ }
46
+ function toBytes(data) {
47
+ if (typeof data === "string")
48
+ data = utf8ToBytes(data);
49
+ abytes(data);
50
+ return data;
51
+ }
52
+ var Hash = class {
53
+ // Safe version that clones internal state
54
+ clone() {
55
+ return this._cloneInto();
56
+ }
57
+ };
58
+ function wrapConstructor(hashCons) {
59
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
60
+ const tmp = hashCons();
61
+ hashC.outputLen = tmp.outputLen;
62
+ hashC.blockLen = tmp.blockLen;
63
+ hashC.create = () => hashCons();
64
+ return hashC;
65
+ }
66
+
67
+ // ../../node_modules/.pnpm/@noble+hashes@1.7.2/node_modules/@noble/hashes/esm/_md.js
68
+ function setBigUint64(view, byteOffset, value, isLE) {
69
+ if (typeof view.setBigUint64 === "function")
70
+ return view.setBigUint64(byteOffset, value, isLE);
71
+ const _32n = BigInt(32);
72
+ const _u32_max = BigInt(4294967295);
73
+ const wh = Number(value >> _32n & _u32_max);
74
+ const wl = Number(value & _u32_max);
75
+ const h = isLE ? 4 : 0;
76
+ const l = isLE ? 0 : 4;
77
+ view.setUint32(byteOffset + h, wh, isLE);
78
+ view.setUint32(byteOffset + l, wl, isLE);
79
+ }
80
+ function Chi(a, b, c) {
81
+ return a & b ^ ~a & c;
82
+ }
83
+ function Maj(a, b, c) {
84
+ return a & b ^ a & c ^ b & c;
85
+ }
86
+ var HashMD = class extends Hash {
87
+ constructor(blockLen, outputLen, padOffset, isLE) {
88
+ super();
89
+ this.finished = false;
90
+ this.length = 0;
91
+ this.pos = 0;
92
+ this.destroyed = false;
93
+ this.blockLen = blockLen;
94
+ this.outputLen = outputLen;
95
+ this.padOffset = padOffset;
96
+ this.isLE = isLE;
97
+ this.buffer = new Uint8Array(blockLen);
98
+ this.view = createView(this.buffer);
99
+ }
100
+ update(data) {
101
+ aexists(this);
102
+ const { view, buffer, blockLen } = this;
103
+ data = toBytes(data);
104
+ const len = data.length;
105
+ for (let pos = 0; pos < len; ) {
106
+ const take = Math.min(blockLen - this.pos, len - pos);
107
+ if (take === blockLen) {
108
+ const dataView = createView(data);
109
+ for (; blockLen <= len - pos; pos += blockLen)
110
+ this.process(dataView, pos);
111
+ continue;
112
+ }
113
+ buffer.set(data.subarray(pos, pos + take), this.pos);
114
+ this.pos += take;
115
+ pos += take;
116
+ if (this.pos === blockLen) {
117
+ this.process(view, 0);
118
+ this.pos = 0;
119
+ }
120
+ }
121
+ this.length += data.length;
122
+ this.roundClean();
123
+ return this;
124
+ }
125
+ digestInto(out) {
126
+ aexists(this);
127
+ aoutput(out, this);
128
+ this.finished = true;
129
+ const { buffer, view, blockLen, isLE } = this;
130
+ let { pos } = this;
131
+ buffer[pos++] = 128;
132
+ this.buffer.subarray(pos).fill(0);
133
+ if (this.padOffset > blockLen - pos) {
134
+ this.process(view, 0);
135
+ pos = 0;
136
+ }
137
+ for (let i = pos; i < blockLen; i++)
138
+ buffer[i] = 0;
139
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
140
+ this.process(view, 0);
141
+ const oview = createView(out);
142
+ const len = this.outputLen;
143
+ if (len % 4)
144
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
145
+ const outLen = len / 4;
146
+ const state = this.get();
147
+ if (outLen > state.length)
148
+ throw new Error("_sha2: outputLen bigger than state");
149
+ for (let i = 0; i < outLen; i++)
150
+ oview.setUint32(4 * i, state[i], isLE);
151
+ }
152
+ digest() {
153
+ const { buffer, outputLen } = this;
154
+ this.digestInto(buffer);
155
+ const res = buffer.slice(0, outputLen);
156
+ this.destroy();
157
+ return res;
158
+ }
159
+ _cloneInto(to) {
160
+ to || (to = new this.constructor());
161
+ to.set(...this.get());
162
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
163
+ to.length = length;
164
+ to.pos = pos;
165
+ to.finished = finished;
166
+ to.destroyed = destroyed;
167
+ if (length % blockLen)
168
+ to.buffer.set(buffer);
169
+ return to;
170
+ }
171
+ };
172
+
173
+ // ../../node_modules/.pnpm/@noble+hashes@1.7.2/node_modules/@noble/hashes/esm/sha256.js
174
+ var SHA256_K = /* @__PURE__ */ new Uint32Array([
175
+ 1116352408,
176
+ 1899447441,
177
+ 3049323471,
178
+ 3921009573,
179
+ 961987163,
180
+ 1508970993,
181
+ 2453635748,
182
+ 2870763221,
183
+ 3624381080,
184
+ 310598401,
185
+ 607225278,
186
+ 1426881987,
187
+ 1925078388,
188
+ 2162078206,
189
+ 2614888103,
190
+ 3248222580,
191
+ 3835390401,
192
+ 4022224774,
193
+ 264347078,
194
+ 604807628,
195
+ 770255983,
196
+ 1249150122,
197
+ 1555081692,
198
+ 1996064986,
199
+ 2554220882,
200
+ 2821834349,
201
+ 2952996808,
202
+ 3210313671,
203
+ 3336571891,
204
+ 3584528711,
205
+ 113926993,
206
+ 338241895,
207
+ 666307205,
208
+ 773529912,
209
+ 1294757372,
210
+ 1396182291,
211
+ 1695183700,
212
+ 1986661051,
213
+ 2177026350,
214
+ 2456956037,
215
+ 2730485921,
216
+ 2820302411,
217
+ 3259730800,
218
+ 3345764771,
219
+ 3516065817,
220
+ 3600352804,
221
+ 4094571909,
222
+ 275423344,
223
+ 430227734,
224
+ 506948616,
225
+ 659060556,
226
+ 883997877,
227
+ 958139571,
228
+ 1322822218,
229
+ 1537002063,
230
+ 1747873779,
231
+ 1955562222,
232
+ 2024104815,
233
+ 2227730452,
234
+ 2361852424,
235
+ 2428436474,
236
+ 2756734187,
237
+ 3204031479,
238
+ 3329325298
239
+ ]);
240
+ var SHA256_IV = /* @__PURE__ */ new Uint32Array([
241
+ 1779033703,
242
+ 3144134277,
243
+ 1013904242,
244
+ 2773480762,
245
+ 1359893119,
246
+ 2600822924,
247
+ 528734635,
248
+ 1541459225
249
+ ]);
250
+ var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
251
+ var SHA256 = class extends HashMD {
252
+ constructor(outputLen = 32) {
253
+ super(64, outputLen, 8, false);
254
+ this.A = SHA256_IV[0] | 0;
255
+ this.B = SHA256_IV[1] | 0;
256
+ this.C = SHA256_IV[2] | 0;
257
+ this.D = SHA256_IV[3] | 0;
258
+ this.E = SHA256_IV[4] | 0;
259
+ this.F = SHA256_IV[5] | 0;
260
+ this.G = SHA256_IV[6] | 0;
261
+ this.H = SHA256_IV[7] | 0;
262
+ }
263
+ get() {
264
+ const { A, B: B2, C, D, E, F, G, H } = this;
265
+ return [A, B2, C, D, E, F, G, H];
266
+ }
267
+ // prettier-ignore
268
+ set(A, B2, C, D, E, F, G, H) {
269
+ this.A = A | 0;
270
+ this.B = B2 | 0;
271
+ this.C = C | 0;
272
+ this.D = D | 0;
273
+ this.E = E | 0;
274
+ this.F = F | 0;
275
+ this.G = G | 0;
276
+ this.H = H | 0;
277
+ }
278
+ process(view, offset) {
279
+ for (let i = 0; i < 16; i++, offset += 4)
280
+ SHA256_W[i] = view.getUint32(offset, false);
281
+ for (let i = 16; i < 64; i++) {
282
+ const W15 = SHA256_W[i - 15];
283
+ const W2 = SHA256_W[i - 2];
284
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
285
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
286
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
287
+ }
288
+ let { A, B: B2, C, D, E, F, G, H } = this;
289
+ for (let i = 0; i < 64; i++) {
290
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
291
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
292
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
293
+ const T2 = sigma0 + Maj(A, B2, C) | 0;
294
+ H = G;
295
+ G = F;
296
+ F = E;
297
+ E = D + T1 | 0;
298
+ D = C;
299
+ C = B2;
300
+ B2 = A;
301
+ A = T1 + T2 | 0;
302
+ }
303
+ A = A + this.A | 0;
304
+ B2 = B2 + this.B | 0;
305
+ C = C + this.C | 0;
306
+ D = D + this.D | 0;
307
+ E = E + this.E | 0;
308
+ F = F + this.F | 0;
309
+ G = G + this.G | 0;
310
+ H = H + this.H | 0;
311
+ this.set(A, B2, C, D, E, F, G, H);
312
+ }
313
+ roundClean() {
314
+ SHA256_W.fill(0);
315
+ }
316
+ destroy() {
317
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
318
+ this.buffer.fill(0);
319
+ }
320
+ };
321
+ var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
322
+
323
+ // ../../node_modules/.pnpm/@scure+base@1.2.4/node_modules/@scure/base/lib/esm/index.js
324
+ function isBytes2(a) {
325
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
326
+ }
327
+ function isArrayOf(isString, arr) {
328
+ if (!Array.isArray(arr))
329
+ return false;
330
+ if (arr.length === 0)
331
+ return true;
332
+ if (isString) {
333
+ return arr.every((item) => typeof item === "string");
334
+ } else {
335
+ return arr.every((item) => Number.isSafeInteger(item));
336
+ }
337
+ }
338
+ function afn(input) {
339
+ if (typeof input !== "function")
340
+ throw new Error("function expected");
341
+ return true;
342
+ }
343
+ function astr(label, input) {
344
+ if (typeof input !== "string")
345
+ throw new Error(`${label}: string expected`);
346
+ return true;
347
+ }
348
+ function anumber(n) {
349
+ if (!Number.isSafeInteger(n))
350
+ throw new Error(`invalid integer: ${n}`);
351
+ }
352
+ function aArr(input) {
353
+ if (!Array.isArray(input))
354
+ throw new Error("array expected");
355
+ }
356
+ function astrArr(label, input) {
357
+ if (!isArrayOf(true, input))
358
+ throw new Error(`${label}: array of strings expected`);
359
+ }
360
+ function anumArr(label, input) {
361
+ if (!isArrayOf(false, input))
362
+ throw new Error(`${label}: array of numbers expected`);
363
+ }
364
+ // @__NO_SIDE_EFFECTS__
365
+ function chain(...args) {
366
+ const id = (a) => a;
367
+ const wrap = (a, b) => (c) => a(b(c));
368
+ const encode = args.map((x) => x.encode).reduceRight(wrap, id);
369
+ const decode = args.map((x) => x.decode).reduce(wrap, id);
370
+ return { encode, decode };
371
+ }
372
+ // @__NO_SIDE_EFFECTS__
373
+ function alphabet(letters) {
374
+ const lettersA = letters.split("") ;
375
+ const len = lettersA.length;
376
+ astrArr("alphabet", lettersA);
377
+ const indexes = new Map(lettersA.map((l, i) => [l, i]));
378
+ return {
379
+ encode: (digits) => {
380
+ aArr(digits);
381
+ return digits.map((i) => {
382
+ if (!Number.isSafeInteger(i) || i < 0 || i >= len)
383
+ throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
384
+ return lettersA[i];
385
+ });
386
+ },
387
+ decode: (input) => {
388
+ aArr(input);
389
+ return input.map((letter) => {
390
+ astr("alphabet.decode", letter);
391
+ const i = indexes.get(letter);
392
+ if (i === void 0)
393
+ throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
394
+ return i;
395
+ });
396
+ }
397
+ };
398
+ }
399
+ // @__NO_SIDE_EFFECTS__
400
+ function join(separator = "") {
401
+ astr("join", separator);
402
+ return {
403
+ encode: (from) => {
404
+ astrArr("join.decode", from);
405
+ return from.join(separator);
406
+ },
407
+ decode: (to) => {
408
+ astr("join.decode", to);
409
+ return to.split(separator);
410
+ }
411
+ };
412
+ }
413
+ function convertRadix(data, from, to) {
414
+ if (from < 2)
415
+ throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
416
+ if (to < 2)
417
+ throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
418
+ aArr(data);
419
+ if (!data.length)
420
+ return [];
421
+ let pos = 0;
422
+ const res = [];
423
+ const digits = Array.from(data, (d) => {
424
+ anumber(d);
425
+ if (d < 0 || d >= from)
426
+ throw new Error(`invalid integer: ${d}`);
427
+ return d;
428
+ });
429
+ const dlen = digits.length;
430
+ while (true) {
431
+ let carry = 0;
432
+ let done = true;
433
+ for (let i = pos; i < dlen; i++) {
434
+ const digit = digits[i];
435
+ const fromCarry = from * carry;
436
+ const digitBase = fromCarry + digit;
437
+ if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
438
+ throw new Error("convertRadix: carry overflow");
439
+ }
440
+ const div = digitBase / to;
441
+ carry = digitBase % to;
442
+ const rounded = Math.floor(div);
443
+ digits[i] = rounded;
444
+ if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
445
+ throw new Error("convertRadix: carry overflow");
446
+ if (!done)
447
+ continue;
448
+ else if (!rounded)
449
+ pos = i;
450
+ else
451
+ done = false;
452
+ }
453
+ res.push(carry);
454
+ if (done)
455
+ break;
456
+ }
457
+ for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
458
+ res.push(0);
459
+ return res.reverse();
460
+ }
461
+ // @__NO_SIDE_EFFECTS__
462
+ function radix(num) {
463
+ anumber(num);
464
+ const _256 = 2 ** 8;
465
+ return {
466
+ encode: (bytes) => {
467
+ if (!isBytes2(bytes))
468
+ throw new Error("radix.encode input should be Uint8Array");
469
+ return convertRadix(Array.from(bytes), _256, num);
470
+ },
471
+ decode: (digits) => {
472
+ anumArr("radix.decode", digits);
473
+ return Uint8Array.from(convertRadix(digits, num, _256));
474
+ }
475
+ };
476
+ }
477
+ function checksum(len, fn) {
478
+ anumber(len);
479
+ afn(fn);
480
+ return {
481
+ encode(data) {
482
+ if (!isBytes2(data))
483
+ throw new Error("checksum.encode: input should be Uint8Array");
484
+ const sum = fn(data).slice(0, len);
485
+ const res = new Uint8Array(data.length + len);
486
+ res.set(data);
487
+ res.set(sum, data.length);
488
+ return res;
489
+ },
490
+ decode(data) {
491
+ if (!isBytes2(data))
492
+ throw new Error("checksum.decode: input should be Uint8Array");
493
+ const payload = data.slice(0, -4);
494
+ const oldChecksum = data.slice(-4);
495
+ const newChecksum = fn(payload).slice(0, len);
496
+ for (let i = 0; i < len; i++)
497
+ if (newChecksum[i] !== oldChecksum[i])
498
+ throw new Error("Invalid checksum");
499
+ return payload;
500
+ }
501
+ };
502
+ }
503
+ var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
504
+ var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
505
+ var createBase58check = (sha2563) => /* @__PURE__ */ chain(checksum(4, (data) => sha2563(sha2563(data))), base58);
506
+ var base58check = createBase58check;
6
507
  var HEXES = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
7
508
  var HexChar = {
8
509
  ZERO: 48,
@@ -18,11 +519,11 @@ var HexChar = {
18
519
  F_LO: 102
19
520
  // f
20
521
  };
21
- function bytesToHex(bytes2) {
22
- assertInstanceOf(bytes2, Uint8Array);
522
+ function bytesToHex(bytes) {
523
+ assertInstanceOf(bytes, Uint8Array);
23
524
  let hex3 = "";
24
- for (let i = 0, len = bytes2.length; i < len; i++) {
25
- hex3 += HEXES[bytes2[i]];
525
+ for (let i = 0, len = bytes.length; i < len; i++) {
526
+ hex3 += HEXES[bytes[i]];
26
527
  }
27
528
  return hex3;
28
529
  }
@@ -30,13 +531,13 @@ function hexToBytes(hex3) {
30
531
  assertTypeOf(hex3, "string");
31
532
  assert(hex3.length % 2 === 0, "Invalid hex padding.");
32
533
  const len = hex3.length / 2;
33
- const bytes2 = new Uint8Array(len);
534
+ const bytes = new Uint8Array(len);
34
535
  for (let i = 0, j = 0; i < len; i++) {
35
536
  const n1 = charCodeToBase16(hex3.charCodeAt(j++));
36
537
  const n2 = charCodeToBase16(hex3.charCodeAt(j++));
37
- bytes2[i] = n1 * 16 + n2;
538
+ bytes[i] = n1 * 16 + n2;
38
539
  }
39
- return bytes2;
540
+ return bytes;
40
541
  }
41
542
  function charCodeToBase16(char) {
42
543
  if (char >= HexChar.ZERO && char <= HexChar.NINE) return char - HexChar.ZERO;
@@ -48,6 +549,13 @@ var hex2 = {
48
549
  encode: bytesToHex,
49
550
  decode: hexToBytes
50
551
  };
552
+ base58check(sha2562);
553
+ function ensureBytes(input) {
554
+ return typeof input === "string" ? hex2.decode(input) : input;
555
+ }
556
+ function sha2562(message) {
557
+ return sha256(ensureBytes(message));
558
+ }
51
559
  var RETRY_STATUS_CODES = /* @__PURE__ */ new Set([
52
560
  408,
53
561
  // Request Timeout