@vleap/warps-adapter-fastset 0.1.0-alpha.32 → 0.1.0-alpha.33

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
@@ -7,8 +7,8 @@ var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
9
  var __export = (target, all) => {
10
- for (var name2 in all)
11
- __defProp(target, name2, { get: all[name2], enumerable: true });
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
14
  if (from && typeof from === "object" || typeof from === "function") {
@@ -250,14 +250,16 @@ function toHex(bytes) {
250
250
 
251
251
  // ../../node_modules/@mysten/bcs/dist/esm/uleb.js
252
252
  function ulebEncode(num) {
253
+ let bigNum = BigInt(num);
253
254
  const arr = [];
254
255
  let len = 0;
255
- if (num === 0) {
256
+ if (bigNum === 0n) {
256
257
  return [0];
257
258
  }
258
- while (num > 0) {
259
- arr[len] = num & 127;
260
- if (num >>= 7) {
259
+ while (bigNum > 0) {
260
+ arr[len] = Number(bigNum & 0x7fn);
261
+ bigNum >>= 7n;
262
+ if (bigNum > 0n) {
261
263
  arr[len] |= 128;
262
264
  }
263
265
  len += 1;
@@ -265,20 +267,26 @@ function ulebEncode(num) {
265
267
  return arr;
266
268
  }
267
269
  function ulebDecode(arr) {
268
- let total = 0;
269
- let shift = 0;
270
+ let total = 0n;
271
+ let shift = 0n;
270
272
  let len = 0;
271
273
  while (true) {
274
+ if (len >= arr.length) {
275
+ throw new Error("ULEB decode error: buffer overflow");
276
+ }
272
277
  const byte = arr[len];
273
278
  len += 1;
274
- total |= (byte & 127) << shift;
279
+ total += BigInt(byte & 127) << shift;
275
280
  if ((byte & 128) === 0) {
276
281
  break;
277
282
  }
278
- shift += 7;
283
+ shift += 7n;
284
+ }
285
+ if (total > BigInt(Number.MAX_SAFE_INTEGER)) {
286
+ throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");
279
287
  }
280
288
  return {
281
- value: total,
289
+ value: Number(total),
282
290
  length: len
283
291
  };
284
292
  }
@@ -426,7 +434,10 @@ var BcsWriter = class {
426
434
  ensureSizeOrGrow(bytes) {
427
435
  const requiredSize = this.bytePosition + bytes;
428
436
  if (requiredSize > this.size) {
429
- const nextSize = Math.min(this.maxSize, this.size + this.allocateSize);
437
+ const nextSize = Math.min(
438
+ this.maxSize,
439
+ Math.max(this.size + requiredSize, this.size + this.allocateSize)
440
+ );
430
441
  if (requiredSize > nextSize) {
431
442
  throw new Error(
432
443
  `Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${requiredSize}`
@@ -458,6 +469,18 @@ var BcsWriter = class {
458
469
  this.dataView.setUint8(this.bytePosition, Number(value));
459
470
  return this.shift(1);
460
471
  }
472
+ /**
473
+ * Write a U8 value into a buffer and shift cursor position by 1.
474
+ * @param {Number} value Value to write.
475
+ * @returns {this}
476
+ */
477
+ writeBytes(bytes) {
478
+ this.ensureSizeOrGrow(bytes.length);
479
+ for (let i = 0; i < bytes.length; i++) {
480
+ this.dataView.setUint8(this.bytePosition + i, bytes[i]);
481
+ }
482
+ return this.shift(bytes.length);
483
+ }
461
484
  /**
462
485
  * Write a U16 value into a buffer and shift cursor position by 2.
463
486
  * @param {Number} value Value to write.
@@ -534,6 +557,7 @@ var BcsWriter = class {
534
557
  * Adds support for iterations over the object.
535
558
  * @returns {Uint8Array}
536
559
  */
560
+ // oxlint-disable-next-line require-yields
537
561
  *[Symbol.iterator]() {
538
562
  for (let i = 0; i < this.bytePosition; i++) {
539
563
  yield this.dataView.getUint8(i);
@@ -619,13 +643,13 @@ var _BcsType = class _BcsType2 {
619
643
  return this.parse(fromBase64(b64));
620
644
  }
621
645
  transform({
622
- name: name2,
646
+ name,
623
647
  input,
624
648
  output,
625
649
  validate
626
650
  }) {
627
651
  return new _BcsType2({
628
- name: name2 ?? this.name,
652
+ name: name ?? this.name,
629
653
  read: (reader) => output ? output(this.read(reader)) : this.read(reader),
630
654
  write: (value, writer) => __privateGet(this, _write).call(this, input ? input(value) : value, writer),
631
655
  serializedSize: (value) => this.serializedSize(input ? input(value) : value),
@@ -735,7 +759,7 @@ function dynamicSizeBcsType({
735
759
  return type;
736
760
  }
737
761
  function stringLikeBcsType({
738
- toBytes: toBytes2,
762
+ toBytes,
739
763
  fromBytes,
740
764
  ...options
741
765
  }) {
@@ -747,14 +771,14 @@ function stringLikeBcsType({
747
771
  return fromBytes(bytes);
748
772
  },
749
773
  write: (hex, writer) => {
750
- const bytes = toBytes2(hex);
774
+ const bytes = toBytes(hex);
751
775
  writer.writeULEB(bytes.length);
752
776
  for (let i = 0; i < bytes.length; i++) {
753
777
  writer.write8(bytes[i]);
754
778
  }
755
779
  },
756
780
  serialize: (value) => {
757
- const bytes = toBytes2(value);
781
+ const bytes = toBytes(value);
758
782
  const size = ulebEncode(bytes.length);
759
783
  const result = new Uint8Array(size.length + bytes.length);
760
784
  result.set(size, 0);
@@ -786,10 +810,10 @@ function lazyBcsType(cb) {
786
810
  });
787
811
  }
788
812
  var BcsStruct = class extends BcsType {
789
- constructor({ name: name2, fields, ...options }) {
813
+ constructor({ name, fields, ...options }) {
790
814
  const canonicalOrder = Object.entries(fields);
791
815
  super({
792
- name: name2,
816
+ name,
793
817
  serializedSize: (values) => {
794
818
  let total = 0;
795
819
  for (const [field, type] of canonicalOrder) {
@@ -831,7 +855,7 @@ var BcsEnum = class extends BcsType {
831
855
  const index = reader.readULEB();
832
856
  const enumEntry = canonicalOrder[index];
833
857
  if (!enumEntry) {
834
- throw new TypeError(`Unknown value ${index} for enum ${name}`);
858
+ throw new TypeError(`Unknown value ${index} for enum ${options.name}`);
835
859
  }
836
860
  const [kind, type] = enumEntry;
837
861
  return {
@@ -840,12 +864,12 @@ var BcsEnum = class extends BcsType {
840
864
  };
841
865
  },
842
866
  write: (value, writer) => {
843
- const [name2, val] = Object.entries(value).filter(
844
- ([name3]) => Object.hasOwn(fields, name3)
867
+ const [name, val] = Object.entries(value).filter(
868
+ ([name2]) => Object.hasOwn(fields, name2)
845
869
  )[0];
846
870
  for (let i = 0; i < canonicalOrder.length; i++) {
847
871
  const [optionName, optionType] = canonicalOrder[i];
848
- if (optionName === name2) {
872
+ if (optionName === name) {
849
873
  writer.writeULEB(i);
850
874
  optionType?.write(val, writer);
851
875
  return;
@@ -863,7 +887,7 @@ var BcsEnum = class extends BcsType {
863
887
  );
864
888
  if (keys.length !== 1) {
865
889
  throw new TypeError(
866
- `Expected object with one key, but found ${keys.length} for type ${name}}`
890
+ `Expected object with one key, but found ${keys.length} for type ${options.name}}`
867
891
  );
868
892
  }
869
893
  const [variant] = keys;
@@ -875,9 +899,9 @@ var BcsEnum = class extends BcsType {
875
899
  }
876
900
  };
877
901
  var BcsTuple = class extends BcsType {
878
- constructor({ fields, name: name2, ...options }) {
902
+ constructor({ fields, name, ...options }) {
879
903
  super({
880
- name: name2 ?? `(${fields.map((t) => t.name).join(", ")})`,
904
+ name: name ?? `(${fields.map((t) => t.name).join(", ")})`,
881
905
  serializedSize: (values) => {
882
906
  let total = 0;
883
907
  for (let i = 0; i < fields.length; i++) {
@@ -1140,10 +1164,7 @@ var bcs = {
1140
1164
  size,
1141
1165
  read: (reader) => reader.readBytes(size),
1142
1166
  write: (value, writer) => {
1143
- const array = new Uint8Array(value);
1144
- for (let i = 0; i < size; i++) {
1145
- writer.write8(array[i] ?? 0);
1146
- }
1167
+ writer.writeBytes(new Uint8Array(value));
1147
1168
  },
1148
1169
  ...options,
1149
1170
  name: options?.name ?? `bytes[${size}]`,
@@ -1173,9 +1194,7 @@ var bcs = {
1173
1194
  write: (value, writer) => {
1174
1195
  const array = new Uint8Array(value);
1175
1196
  writer.writeULEB(array.length);
1176
- for (let i = 0; i < array.length; i++) {
1177
- writer.write8(array[i] ?? 0);
1178
- }
1197
+ writer.writeBytes(array);
1179
1198
  },
1180
1199
  ...options,
1181
1200
  name: options?.name ?? "vector<u8>",
@@ -1254,9 +1273,9 @@ var bcs = {
1254
1273
  * })
1255
1274
  * struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
1256
1275
  */
1257
- struct(name2, fields, options) {
1276
+ struct(name, fields, options) {
1258
1277
  return new BcsStruct({
1259
- name: name2,
1278
+ name,
1260
1279
  fields,
1261
1280
  ...options
1262
1281
  });
@@ -1277,9 +1296,9 @@ var bcs = {
1277
1296
  * enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
1278
1297
  * enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
1279
1298
  */
1280
- enum(name2, fields, options) {
1299
+ enum(name, fields, options) {
1281
1300
  return new BcsEnum({
1282
- name: name2,
1301
+ name,
1283
1302
  fields,
1284
1303
  ...options
1285
1304
  });
@@ -2037,10 +2056,10 @@ var invert = (num, md) => {
2037
2056
  }
2038
2057
  return b === 1n ? M(x, md) : err("no inverse");
2039
2058
  };
2040
- var callHash = (name2) => {
2041
- const fn = hashes[name2];
2059
+ var callHash = (name) => {
2060
+ const fn = hashes[name];
2042
2061
  if (typeof fn !== "function")
2043
- err("hashes." + name2 + " not set");
2062
+ err("hashes." + name + " not set");
2044
2063
  return fn;
2045
2064
  };
2046
2065
  var hash = (msg) => callHash("sha512")(msg);
@@ -2455,15 +2474,21 @@ var wNAF = (n) => {
2455
2474
  return { p, f };
2456
2475
  };
2457
2476
 
2458
- // ../../node_modules/@noble/hashes/esm/utils.js
2477
+ // node_modules/@noble/hashes/utils.js
2459
2478
  function isBytes3(a) {
2460
2479
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
2461
2480
  }
2462
- function abytes2(b, ...lengths) {
2463
- if (!isBytes3(b))
2464
- throw new Error("Uint8Array expected");
2465
- if (lengths.length > 0 && !lengths.includes(b.length))
2466
- throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
2481
+ function abytes2(value, length, title = "") {
2482
+ const bytes = isBytes3(value);
2483
+ const len = value?.length;
2484
+ const needsLen = length !== void 0;
2485
+ if (!bytes || needsLen && len !== length) {
2486
+ const prefix = title && `"${title}" `;
2487
+ const ofLen = needsLen ? ` of length ${length}` : "";
2488
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
2489
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
2490
+ }
2491
+ return value;
2467
2492
  }
2468
2493
  function aexists(instance, checkFinished = true) {
2469
2494
  if (instance.destroyed)
@@ -2472,10 +2497,10 @@ function aexists(instance, checkFinished = true) {
2472
2497
  throw new Error("Hash#digest() has already been called");
2473
2498
  }
2474
2499
  function aoutput(out, instance) {
2475
- abytes2(out);
2500
+ abytes2(out, void 0, "digestInto() output");
2476
2501
  const min = instance.outputLen;
2477
2502
  if (out.length < min) {
2478
- throw new Error("digestInto() expects output buffer of length at least " + min);
2503
+ throw new Error('"digestInto() output" expected to be of length >=' + min);
2479
2504
  }
2480
2505
  }
2481
2506
  function clean(...arrays) {
@@ -2486,48 +2511,33 @@ function clean(...arrays) {
2486
2511
  function createView(arr) {
2487
2512
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2488
2513
  }
2489
- function utf8ToBytes(str) {
2490
- if (typeof str !== "string")
2491
- throw new Error("string expected");
2492
- return new Uint8Array(new TextEncoder().encode(str));
2493
- }
2494
- function toBytes(data) {
2495
- if (typeof data === "string")
2496
- data = utf8ToBytes(data);
2497
- abytes2(data);
2498
- return data;
2499
- }
2500
- var Hash = class {
2501
- };
2502
- function createHasher(hashCons) {
2503
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
2504
- const tmp = hashCons();
2514
+ function createHasher(hashCons, info = {}) {
2515
+ const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
2516
+ const tmp = hashCons(void 0);
2505
2517
  hashC.outputLen = tmp.outputLen;
2506
2518
  hashC.blockLen = tmp.blockLen;
2507
- hashC.create = () => hashCons();
2508
- return hashC;
2519
+ hashC.create = (opts) => hashCons(opts);
2520
+ Object.assign(hashC, info);
2521
+ return Object.freeze(hashC);
2509
2522
  }
2523
+ var oidNist = (suffix) => ({
2524
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
2525
+ });
2510
2526
 
2511
- // ../../node_modules/@noble/hashes/esm/_md.js
2512
- function setBigUint64(view, byteOffset, value, isLE) {
2513
- if (typeof view.setBigUint64 === "function")
2514
- return view.setBigUint64(byteOffset, value, isLE);
2515
- const _32n2 = BigInt(32);
2516
- const _u32_max = BigInt(4294967295);
2517
- const wh = Number(value >> _32n2 & _u32_max);
2518
- const wl = Number(value & _u32_max);
2519
- const h2 = isLE ? 4 : 0;
2520
- const l = isLE ? 0 : 4;
2521
- view.setUint32(byteOffset + h2, wh, isLE);
2522
- view.setUint32(byteOffset + l, wl, isLE);
2523
- }
2524
- var HashMD = class extends Hash {
2527
+ // node_modules/@noble/hashes/_md.js
2528
+ var HashMD = class {
2525
2529
  constructor(blockLen, outputLen, padOffset, isLE) {
2526
- super();
2527
- this.finished = false;
2528
- this.length = 0;
2529
- this.pos = 0;
2530
- this.destroyed = false;
2530
+ __publicField(this, "blockLen");
2531
+ __publicField(this, "outputLen");
2532
+ __publicField(this, "padOffset");
2533
+ __publicField(this, "isLE");
2534
+ // For partial updates less than block size
2535
+ __publicField(this, "buffer");
2536
+ __publicField(this, "view");
2537
+ __publicField(this, "finished", false);
2538
+ __publicField(this, "length", 0);
2539
+ __publicField(this, "pos", 0);
2540
+ __publicField(this, "destroyed", false);
2531
2541
  this.blockLen = blockLen;
2532
2542
  this.outputLen = outputLen;
2533
2543
  this.padOffset = padOffset;
@@ -2537,7 +2547,6 @@ var HashMD = class extends Hash {
2537
2547
  }
2538
2548
  update(data) {
2539
2549
  aexists(this);
2540
- data = toBytes(data);
2541
2550
  abytes2(data);
2542
2551
  const { view, buffer, blockLen } = this;
2543
2552
  const len = data.length;
@@ -2575,12 +2584,12 @@ var HashMD = class extends Hash {
2575
2584
  }
2576
2585
  for (let i = pos; i < blockLen; i++)
2577
2586
  buffer[i] = 0;
2578
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
2587
+ view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
2579
2588
  this.process(view, 0);
2580
2589
  const oview = createView(out);
2581
2590
  const len = this.outputLen;
2582
2591
  if (len % 4)
2583
- throw new Error("_sha2: outputLen should be aligned to 32bit");
2592
+ throw new Error("_sha2: outputLen must be aligned to 32bit");
2584
2593
  const outLen = len / 4;
2585
2594
  const state = this.get();
2586
2595
  if (outLen > state.length)
@@ -2630,7 +2639,7 @@ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
2630
2639
  327033209
2631
2640
  ]);
2632
2641
 
2633
- // ../../node_modules/@noble/hashes/esm/_u64.js
2642
+ // node_modules/@noble/hashes/_u64.js
2634
2643
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
2635
2644
  var _32n = /* @__PURE__ */ BigInt(32);
2636
2645
  function fromBig(n, le = false) {
@@ -2665,7 +2674,7 @@ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0
2665
2674
  var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
2666
2675
  var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
2667
2676
 
2668
- // ../../node_modules/@noble/hashes/esm/sha2.js
2677
+ // node_modules/@noble/hashes/sha2.js
2669
2678
  var K512 = /* @__PURE__ */ (() => split([
2670
2679
  "0x428a2f98d728ae22",
2671
2680
  "0x7137449123ef65cd",
@@ -2752,25 +2761,9 @@ var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
2752
2761
  var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
2753
2762
  var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
2754
2763
  var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
2755
- var SHA512 = class extends HashMD {
2756
- constructor(outputLen = 64) {
2764
+ var SHA2_64B = class extends HashMD {
2765
+ constructor(outputLen) {
2757
2766
  super(128, outputLen, 16, false);
2758
- this.Ah = SHA512_IV[0] | 0;
2759
- this.Al = SHA512_IV[1] | 0;
2760
- this.Bh = SHA512_IV[2] | 0;
2761
- this.Bl = SHA512_IV[3] | 0;
2762
- this.Ch = SHA512_IV[4] | 0;
2763
- this.Cl = SHA512_IV[5] | 0;
2764
- this.Dh = SHA512_IV[6] | 0;
2765
- this.Dl = SHA512_IV[7] | 0;
2766
- this.Eh = SHA512_IV[8] | 0;
2767
- this.El = SHA512_IV[9] | 0;
2768
- this.Fh = SHA512_IV[10] | 0;
2769
- this.Fl = SHA512_IV[11] | 0;
2770
- this.Gh = SHA512_IV[12] | 0;
2771
- this.Gl = SHA512_IV[13] | 0;
2772
- this.Hh = SHA512_IV[14] | 0;
2773
- this.Hl = SHA512_IV[15] | 0;
2774
2767
  }
2775
2768
  // prettier-ignore
2776
2769
  get() {
@@ -2863,13 +2856,34 @@ var SHA512 = class extends HashMD {
2863
2856
  this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2864
2857
  }
2865
2858
  };
2866
- var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
2867
-
2868
- // ../../node_modules/@noble/hashes/esm/sha512.js
2869
- var sha5122 = sha512;
2859
+ var _SHA512 = class extends SHA2_64B {
2860
+ constructor() {
2861
+ super(64);
2862
+ __publicField(this, "Ah", SHA512_IV[0] | 0);
2863
+ __publicField(this, "Al", SHA512_IV[1] | 0);
2864
+ __publicField(this, "Bh", SHA512_IV[2] | 0);
2865
+ __publicField(this, "Bl", SHA512_IV[3] | 0);
2866
+ __publicField(this, "Ch", SHA512_IV[4] | 0);
2867
+ __publicField(this, "Cl", SHA512_IV[5] | 0);
2868
+ __publicField(this, "Dh", SHA512_IV[6] | 0);
2869
+ __publicField(this, "Dl", SHA512_IV[7] | 0);
2870
+ __publicField(this, "Eh", SHA512_IV[8] | 0);
2871
+ __publicField(this, "El", SHA512_IV[9] | 0);
2872
+ __publicField(this, "Fh", SHA512_IV[10] | 0);
2873
+ __publicField(this, "Fl", SHA512_IV[11] | 0);
2874
+ __publicField(this, "Gh", SHA512_IV[12] | 0);
2875
+ __publicField(this, "Gl", SHA512_IV[13] | 0);
2876
+ __publicField(this, "Hh", SHA512_IV[14] | 0);
2877
+ __publicField(this, "Hl", SHA512_IV[15] | 0);
2878
+ }
2879
+ };
2880
+ var sha512 = /* @__PURE__ */ createHasher(
2881
+ () => new _SHA512(),
2882
+ /* @__PURE__ */ oidNist(3)
2883
+ );
2870
2884
 
2871
2885
  // src/sdk/ed25519-setup.ts
2872
- hashes.sha512 = sha5122;
2886
+ hashes.sha512 = sha512;
2873
2887
 
2874
2888
  // src/WarpFastsetWallet.ts
2875
2889
  var WarpFastsetWallet = class {
@@ -3006,7 +3020,7 @@ var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset
3006
3020
  @noble/ed25519/index.js:
3007
3021
  (*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
3008
3022
 
3009
- @noble/hashes/esm/utils.js:
3023
+ @noble/hashes/utils.js:
3010
3024
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
3011
3025
  */
3012
3026
  //# sourceMappingURL=index.js.map