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