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