@obolnetwork/obol-sdk 1.0.4 → 1.0.6

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
@@ -115,8 +115,8 @@ var FORK_MAPPING;
115
115
  FORK_MAPPING[FORK_MAPPING["0x80000069"] = 3] = "0x80000069";
116
116
  })(FORK_MAPPING || (FORK_MAPPING = {}));
117
117
  const dkg_algorithm = "default";
118
- const config_version = "v1.5.0";
119
- const SDK_VERSION = "1.0.0";
118
+ const config_version = "v1.7.0";
119
+ const SDK_VERSION = "1.0.3"; //should we read it from package.json?
120
120
  const DEFAULT_BASE_URL = "https://api.obol.tech";
121
121
  const DEFAULT_CHAIN_ID = 5;
122
122
 
@@ -388,14 +388,7 @@ function output(out, instance) {
388
388
  }
389
389
  }
390
390
  _assert.output = output;
391
- const assert = {
392
- number,
393
- bool,
394
- bytes,
395
- hash,
396
- exists,
397
- output,
398
- };
391
+ const assert = { number, bool, bytes, hash, exists, output };
399
392
  _assert.default = assert;
400
393
 
401
394
  var utils = {};
@@ -434,7 +427,7 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
434
427
  exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
435
428
  if (!exports.isLE)
436
429
  throw new Error('Non little-endian hardware is not supported');
437
- const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
430
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
438
431
  /**
439
432
  * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
440
433
  */
@@ -534,10 +527,9 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
534
527
  }
535
528
  }
536
529
  exports.Hash = Hash;
537
- // Check if object doens't have custom constructor (like Uint8Array/Array)
538
- const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
530
+ const toStr = {}.toString;
539
531
  function checkOpts(defaults, opts) {
540
- if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
532
+ if (opts !== undefined && toStr.call(opts) !== '[object Object]')
541
533
  throw new Error('Options should be object or undefined');
542
534
  const merged = Object.assign(defaults, opts);
543
535
  return merged;
@@ -616,7 +608,7 @@ class SHA2 extends utils_js_1$1.Hash {
616
608
  this.view = (0, utils_js_1$1.createView)(this.buffer);
617
609
  }
618
610
  update(data) {
619
- _assert_js_1.default.exists(this);
611
+ (0, _assert_js_1.exists)(this);
620
612
  const { view, buffer, blockLen } = this;
621
613
  data = (0, utils_js_1$1.toBytes)(data);
622
614
  const len = data.length;
@@ -642,8 +634,8 @@ class SHA2 extends utils_js_1$1.Hash {
642
634
  return this;
643
635
  }
644
636
  digestInto(out) {
645
- _assert_js_1.default.exists(this);
646
- _assert_js_1.default.output(out, this);
637
+ (0, _assert_js_1.exists)(this);
638
+ (0, _assert_js_1.output)(out, this);
647
639
  this.finished = true;
648
640
  // Padding
649
641
  // We can avoid allocation of buffer for padding completely if it
@@ -704,6 +696,8 @@ Object.defineProperty(sha256, "__esModule", { value: true });
704
696
  sha256.sha224 = sha256.sha256 = void 0;
705
697
  const _sha2_js_1 = _sha2;
706
698
  const utils_js_1 = utils;
699
+ // SHA2-256 need to try 2^128 hashes to execute birthday attack.
700
+ // BTC network is doing 2^67 hashes/sec as per early 2023.
707
701
  // Choice: a ? b : c
708
702
  const Chi = (a, b, c) => (a & b) ^ (~a & c);
709
703
  // Majority function, true if any two inpust is true
@@ -711,7 +705,7 @@ const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
711
705
  // Round constants:
712
706
  // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
713
707
  // prettier-ignore
714
- const SHA256_K = new Uint32Array([
708
+ const SHA256_K = /* @__PURE__ */ new Uint32Array([
715
709
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
716
710
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
717
711
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -723,12 +717,12 @@ const SHA256_K = new Uint32Array([
723
717
  ]);
724
718
  // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
725
719
  // prettier-ignore
726
- const IV = new Uint32Array([
720
+ const IV = /* @__PURE__ */ new Uint32Array([
727
721
  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
728
722
  ]);
729
723
  // Temporary buffer, not used to store anything between runs
730
724
  // Named this way because it matches specification.
731
- const SHA256_W = new Uint32Array(64);
725
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
732
726
  class SHA256 extends _sha2_js_1.SHA2 {
733
727
  constructor() {
734
728
  super(64, 32, 8, false);
@@ -7984,12 +7978,12 @@ vectorComposite.VectorCompositeType = VectorCompositeType;
7984
7978
  * @returns The config hash or he definition hash in of the corresponding cluster definition
7985
7979
  */
7986
7980
  const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
7987
- const definitionType = clusterDefinitionContainerTypeV1X5(configOnly);
7988
- const val = hashClusterDefinitionV1X5(cluster, configOnly);
7981
+ const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
7982
+ const val = hashClusterDefinitionV1X7(cluster, configOnly);
7989
7983
  return ('0x' + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
7990
7984
  };
7991
- const hashClusterDefinitionV1X5 = (cluster, configOnly) => {
7992
- const definitionType = clusterDefinitionContainerTypeV1X5(configOnly);
7985
+ const hashClusterDefinitionV1X7 = (cluster, configOnly) => {
7986
+ const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
7993
7987
  const val = definitionType.defaultValue();
7994
7988
  //order should be same as charon https://github.com/ObolNetwork/charon/blob/d00b31e6465a260a43ce40f15c47fb5a5b009042/cluster/ssz.go#L285
7995
7989
  val.uuid = strToUint8Array(cluster.uuid);
@@ -8070,7 +8064,7 @@ const newOperatorContainerType = (configOnly) => {
8070
8064
  * @param cluster ClusterDefinition to calculate the type from
8071
8065
  * @returns SSZ Containerized type of cluster input
8072
8066
  */
8073
- const clusterDefinitionContainerTypeV1X5 = (configOnly) => {
8067
+ const clusterDefinitionContainerTypeV1X7 = (configOnly) => {
8074
8068
  let returnedContainerType = {
8075
8069
  uuid: new lib$1.ByteListType(64),
8076
8070
  name: new lib$1.ByteListType(256),
@@ -15483,324 +15477,344 @@ function validateDefinition(data) {
15483
15477
  *
15484
15478
  */
15485
15479
 
15486
- const ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
15487
- class BufferSourceConverter {
15488
- static isArrayBuffer(data) {
15489
- return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
15490
- }
15491
- static toArrayBuffer(data) {
15492
- if (this.isArrayBuffer(data)) {
15493
- return data;
15494
- }
15495
- if (data.byteLength === data.buffer.byteLength) {
15496
- return data.buffer;
15497
- }
15498
- return this.toUint8Array(data).slice().buffer;
15499
- }
15500
- static toUint8Array(data) {
15501
- return this.toView(data, Uint8Array);
15502
- }
15503
- static toView(data, type) {
15504
- if (data.constructor === type) {
15505
- return data;
15506
- }
15507
- if (this.isArrayBuffer(data)) {
15508
- return new type(data);
15509
- }
15510
- if (this.isArrayBufferView(data)) {
15511
- return new type(data.buffer, data.byteOffset, data.byteLength);
15512
- }
15513
- throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
15514
- }
15515
- static isBufferSource(data) {
15516
- return this.isArrayBufferView(data)
15517
- || this.isArrayBuffer(data);
15518
- }
15519
- static isArrayBufferView(data) {
15520
- return ArrayBuffer.isView(data)
15521
- || (data && this.isArrayBuffer(data.buffer));
15522
- }
15523
- static isEqual(a, b) {
15524
- const aView = BufferSourceConverter.toUint8Array(a);
15525
- const bView = BufferSourceConverter.toUint8Array(b);
15526
- if (aView.length !== bView.byteLength) {
15527
- return false;
15528
- }
15529
- for (let i = 0; i < aView.length; i++) {
15530
- if (aView[i] !== bView[i]) {
15531
- return false;
15532
- }
15533
- }
15534
- return true;
15535
- }
15536
- static concat(...args) {
15537
- if (Array.isArray(args[0])) {
15538
- const buffers = args[0];
15539
- let size = 0;
15540
- for (const buffer of buffers) {
15541
- size += buffer.byteLength;
15542
- }
15543
- const res = new Uint8Array(size);
15544
- let offset = 0;
15545
- for (const buffer of buffers) {
15546
- const view = this.toUint8Array(buffer);
15547
- res.set(view, offset);
15548
- offset += view.length;
15549
- }
15550
- if (args[1]) {
15551
- return this.toView(res, args[1]);
15552
- }
15553
- return res.buffer;
15554
- }
15555
- else {
15556
- return this.concat(args);
15557
- }
15558
- }
15480
+ const ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
15481
+ class BufferSourceConverter {
15482
+ static isArrayBuffer(data) {
15483
+ return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
15484
+ }
15485
+ static toArrayBuffer(data) {
15486
+ if (this.isArrayBuffer(data)) {
15487
+ return data;
15488
+ }
15489
+ if (data.byteLength === data.buffer.byteLength) {
15490
+ return data.buffer;
15491
+ }
15492
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
15493
+ return data.buffer;
15494
+ }
15495
+ return this.toUint8Array(data.buffer)
15496
+ .slice(data.byteOffset, data.byteOffset + data.byteLength)
15497
+ .buffer;
15498
+ }
15499
+ static toUint8Array(data) {
15500
+ return this.toView(data, Uint8Array);
15501
+ }
15502
+ static toView(data, type) {
15503
+ if (data.constructor === type) {
15504
+ return data;
15505
+ }
15506
+ if (this.isArrayBuffer(data)) {
15507
+ return new type(data);
15508
+ }
15509
+ if (this.isArrayBufferView(data)) {
15510
+ return new type(data.buffer, data.byteOffset, data.byteLength);
15511
+ }
15512
+ throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
15513
+ }
15514
+ static isBufferSource(data) {
15515
+ return this.isArrayBufferView(data)
15516
+ || this.isArrayBuffer(data);
15517
+ }
15518
+ static isArrayBufferView(data) {
15519
+ return ArrayBuffer.isView(data)
15520
+ || (data && this.isArrayBuffer(data.buffer));
15521
+ }
15522
+ static isEqual(a, b) {
15523
+ const aView = BufferSourceConverter.toUint8Array(a);
15524
+ const bView = BufferSourceConverter.toUint8Array(b);
15525
+ if (aView.length !== bView.byteLength) {
15526
+ return false;
15527
+ }
15528
+ for (let i = 0; i < aView.length; i++) {
15529
+ if (aView[i] !== bView[i]) {
15530
+ return false;
15531
+ }
15532
+ }
15533
+ return true;
15534
+ }
15535
+ static concat(...args) {
15536
+ let buffers;
15537
+ if (Array.isArray(args[0]) && !(args[1] instanceof Function)) {
15538
+ buffers = args[0];
15539
+ }
15540
+ else if (Array.isArray(args[0]) && args[1] instanceof Function) {
15541
+ buffers = args[0];
15542
+ }
15543
+ else {
15544
+ if (args[args.length - 1] instanceof Function) {
15545
+ buffers = args.slice(0, args.length - 1);
15546
+ }
15547
+ else {
15548
+ buffers = args;
15549
+ }
15550
+ }
15551
+ let size = 0;
15552
+ for (const buffer of buffers) {
15553
+ size += buffer.byteLength;
15554
+ }
15555
+ const res = new Uint8Array(size);
15556
+ let offset = 0;
15557
+ for (const buffer of buffers) {
15558
+ const view = this.toUint8Array(buffer);
15559
+ res.set(view, offset);
15560
+ offset += view.length;
15561
+ }
15562
+ if (args[args.length - 1] instanceof Function) {
15563
+ return this.toView(res, args[args.length - 1]);
15564
+ }
15565
+ return res.buffer;
15566
+ }
15559
15567
  }
15560
15568
 
15561
- class Utf8Converter {
15562
- static fromString(text) {
15563
- const s = unescape(encodeURIComponent(text));
15564
- const uintArray = new Uint8Array(s.length);
15565
- for (let i = 0; i < s.length; i++) {
15566
- uintArray[i] = s.charCodeAt(i);
15567
- }
15568
- return uintArray.buffer;
15569
- }
15570
- static toString(buffer) {
15571
- const buf = BufferSourceConverter.toUint8Array(buffer);
15572
- let encodedString = "";
15573
- for (let i = 0; i < buf.length; i++) {
15574
- encodedString += String.fromCharCode(buf[i]);
15575
- }
15576
- const decodedString = decodeURIComponent(escape(encodedString));
15577
- return decodedString;
15578
- }
15579
- }
15580
- class Utf16Converter {
15581
- static toString(buffer, littleEndian = false) {
15582
- const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
15583
- const dataView = new DataView(arrayBuffer);
15584
- let res = "";
15585
- for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
15586
- const code = dataView.getUint16(i, littleEndian);
15587
- res += String.fromCharCode(code);
15588
- }
15589
- return res;
15590
- }
15591
- static fromString(text, littleEndian = false) {
15592
- const res = new ArrayBuffer(text.length * 2);
15593
- const dataView = new DataView(res);
15594
- for (let i = 0; i < text.length; i++) {
15595
- dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
15596
- }
15597
- return res;
15598
- }
15599
- }
15600
- class Convert {
15601
- static isHex(data) {
15602
- return typeof data === "string"
15603
- && /^[a-z0-9]+$/i.test(data);
15604
- }
15605
- static isBase64(data) {
15606
- return typeof data === "string"
15607
- && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data);
15608
- }
15609
- static isBase64Url(data) {
15610
- return typeof data === "string"
15611
- && /^[a-zA-Z0-9-_]+$/i.test(data);
15612
- }
15613
- static ToString(buffer, enc = "utf8") {
15614
- const buf = BufferSourceConverter.toUint8Array(buffer);
15615
- switch (enc.toLowerCase()) {
15616
- case "utf8":
15617
- return this.ToUtf8String(buf);
15618
- case "binary":
15619
- return this.ToBinary(buf);
15620
- case "hex":
15621
- return this.ToHex(buf);
15622
- case "base64":
15623
- return this.ToBase64(buf);
15624
- case "base64url":
15625
- return this.ToBase64Url(buf);
15626
- case "utf16le":
15627
- return Utf16Converter.toString(buf, true);
15628
- case "utf16":
15629
- case "utf16be":
15630
- return Utf16Converter.toString(buf);
15631
- default:
15632
- throw new Error(`Unknown type of encoding '${enc}'`);
15633
- }
15634
- }
15635
- static FromString(str, enc = "utf8") {
15636
- if (!str) {
15637
- return new ArrayBuffer(0);
15638
- }
15639
- switch (enc.toLowerCase()) {
15640
- case "utf8":
15641
- return this.FromUtf8String(str);
15642
- case "binary":
15643
- return this.FromBinary(str);
15644
- case "hex":
15645
- return this.FromHex(str);
15646
- case "base64":
15647
- return this.FromBase64(str);
15648
- case "base64url":
15649
- return this.FromBase64Url(str);
15650
- case "utf16le":
15651
- return Utf16Converter.fromString(str, true);
15652
- case "utf16":
15653
- case "utf16be":
15654
- return Utf16Converter.fromString(str);
15655
- default:
15656
- throw new Error(`Unknown type of encoding '${enc}'`);
15657
- }
15658
- }
15659
- static ToBase64(buffer) {
15660
- const buf = BufferSourceConverter.toUint8Array(buffer);
15661
- if (typeof btoa !== "undefined") {
15662
- const binary = this.ToString(buf, "binary");
15663
- return btoa(binary);
15664
- }
15665
- else {
15666
- return Buffer.from(buf).toString("base64");
15667
- }
15668
- }
15669
- static FromBase64(base64) {
15670
- const formatted = this.formatString(base64);
15671
- if (!formatted) {
15672
- return new ArrayBuffer(0);
15673
- }
15674
- if (!Convert.isBase64(formatted)) {
15675
- throw new TypeError("Argument 'base64Text' is not Base64 encoded");
15676
- }
15677
- if (typeof atob !== "undefined") {
15678
- return this.FromBinary(atob(formatted));
15679
- }
15680
- else {
15681
- return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
15682
- }
15683
- }
15684
- static FromBase64Url(base64url) {
15685
- const formatted = this.formatString(base64url);
15686
- if (!formatted) {
15687
- return new ArrayBuffer(0);
15688
- }
15689
- if (!Convert.isBase64Url(formatted)) {
15690
- throw new TypeError("Argument 'base64url' is not Base64Url encoded");
15691
- }
15692
- return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
15693
- }
15694
- static ToBase64Url(data) {
15695
- return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
15696
- }
15697
- static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15698
- switch (encoding) {
15699
- case "ascii":
15700
- return this.FromBinary(text);
15701
- case "utf8":
15702
- return Utf8Converter.fromString(text);
15703
- case "utf16":
15704
- case "utf16be":
15705
- return Utf16Converter.fromString(text);
15706
- case "utf16le":
15707
- case "usc2":
15708
- return Utf16Converter.fromString(text, true);
15709
- default:
15710
- throw new Error(`Unknown type of encoding '${encoding}'`);
15711
- }
15712
- }
15713
- static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15714
- switch (encoding) {
15715
- case "ascii":
15716
- return this.ToBinary(buffer);
15717
- case "utf8":
15718
- return Utf8Converter.toString(buffer);
15719
- case "utf16":
15720
- case "utf16be":
15721
- return Utf16Converter.toString(buffer);
15722
- case "utf16le":
15723
- case "usc2":
15724
- return Utf16Converter.toString(buffer, true);
15725
- default:
15726
- throw new Error(`Unknown type of encoding '${encoding}'`);
15727
- }
15728
- }
15729
- static FromBinary(text) {
15730
- const stringLength = text.length;
15731
- const resultView = new Uint8Array(stringLength);
15732
- for (let i = 0; i < stringLength; i++) {
15733
- resultView[i] = text.charCodeAt(i);
15734
- }
15735
- return resultView.buffer;
15736
- }
15737
- static ToBinary(buffer) {
15738
- const buf = BufferSourceConverter.toUint8Array(buffer);
15739
- let res = "";
15740
- for (let i = 0; i < buf.length; i++) {
15741
- res += String.fromCharCode(buf[i]);
15742
- }
15743
- return res;
15744
- }
15745
- static ToHex(buffer) {
15746
- const buf = BufferSourceConverter.toUint8Array(buffer);
15747
- const splitter = "";
15748
- const res = [];
15749
- const len = buf.length;
15750
- for (let i = 0; i < len; i++) {
15751
- const char = buf[i].toString(16).padStart(2, "0");
15752
- res.push(char);
15753
- }
15754
- return res.join(splitter);
15755
- }
15756
- static FromHex(hexString) {
15757
- let formatted = this.formatString(hexString);
15758
- if (!formatted) {
15759
- return new ArrayBuffer(0);
15760
- }
15761
- if (!Convert.isHex(formatted)) {
15762
- throw new TypeError("Argument 'hexString' is not HEX encoded");
15763
- }
15764
- if (formatted.length % 2) {
15765
- formatted = `0${formatted}`;
15766
- }
15767
- const res = new Uint8Array(formatted.length / 2);
15768
- for (let i = 0; i < formatted.length; i = i + 2) {
15769
- const c = formatted.slice(i, i + 2);
15770
- res[i / 2] = parseInt(c, 16);
15771
- }
15772
- return res.buffer;
15773
- }
15774
- static ToUtf16String(buffer, littleEndian = false) {
15775
- return Utf16Converter.toString(buffer, littleEndian);
15776
- }
15777
- static FromUtf16String(text, littleEndian = false) {
15778
- return Utf16Converter.fromString(text, littleEndian);
15779
- }
15780
- static Base64Padding(base64) {
15781
- const padCount = 4 - (base64.length % 4);
15782
- if (padCount < 4) {
15783
- for (let i = 0; i < padCount; i++) {
15784
- base64 += "=";
15785
- }
15786
- }
15787
- return base64;
15788
- }
15789
- static formatString(data) {
15790
- return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
15791
- }
15792
- }
15569
+ const STRING_TYPE = "string";
15570
+ const HEX_REGEX = /^[0-9a-f]+$/i;
15571
+ const BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
15572
+ const BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;
15573
+ class Utf8Converter {
15574
+ static fromString(text) {
15575
+ const s = unescape(encodeURIComponent(text));
15576
+ const uintArray = new Uint8Array(s.length);
15577
+ for (let i = 0; i < s.length; i++) {
15578
+ uintArray[i] = s.charCodeAt(i);
15579
+ }
15580
+ return uintArray.buffer;
15581
+ }
15582
+ static toString(buffer) {
15583
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15584
+ let encodedString = "";
15585
+ for (let i = 0; i < buf.length; i++) {
15586
+ encodedString += String.fromCharCode(buf[i]);
15587
+ }
15588
+ const decodedString = decodeURIComponent(escape(encodedString));
15589
+ return decodedString;
15590
+ }
15591
+ }
15592
+ class Utf16Converter {
15593
+ static toString(buffer, littleEndian = false) {
15594
+ const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
15595
+ const dataView = new DataView(arrayBuffer);
15596
+ let res = "";
15597
+ for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
15598
+ const code = dataView.getUint16(i, littleEndian);
15599
+ res += String.fromCharCode(code);
15600
+ }
15601
+ return res;
15602
+ }
15603
+ static fromString(text, littleEndian = false) {
15604
+ const res = new ArrayBuffer(text.length * 2);
15605
+ const dataView = new DataView(res);
15606
+ for (let i = 0; i < text.length; i++) {
15607
+ dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
15608
+ }
15609
+ return res;
15610
+ }
15611
+ }
15612
+ class Convert {
15613
+ static isHex(data) {
15614
+ return typeof data === STRING_TYPE
15615
+ && HEX_REGEX.test(data);
15616
+ }
15617
+ static isBase64(data) {
15618
+ return typeof data === STRING_TYPE
15619
+ && BASE64_REGEX.test(data);
15620
+ }
15621
+ static isBase64Url(data) {
15622
+ return typeof data === STRING_TYPE
15623
+ && BASE64URL_REGEX.test(data);
15624
+ }
15625
+ static ToString(buffer, enc = "utf8") {
15626
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15627
+ switch (enc.toLowerCase()) {
15628
+ case "utf8":
15629
+ return this.ToUtf8String(buf);
15630
+ case "binary":
15631
+ return this.ToBinary(buf);
15632
+ case "hex":
15633
+ return this.ToHex(buf);
15634
+ case "base64":
15635
+ return this.ToBase64(buf);
15636
+ case "base64url":
15637
+ return this.ToBase64Url(buf);
15638
+ case "utf16le":
15639
+ return Utf16Converter.toString(buf, true);
15640
+ case "utf16":
15641
+ case "utf16be":
15642
+ return Utf16Converter.toString(buf);
15643
+ default:
15644
+ throw new Error(`Unknown type of encoding '${enc}'`);
15645
+ }
15646
+ }
15647
+ static FromString(str, enc = "utf8") {
15648
+ if (!str) {
15649
+ return new ArrayBuffer(0);
15650
+ }
15651
+ switch (enc.toLowerCase()) {
15652
+ case "utf8":
15653
+ return this.FromUtf8String(str);
15654
+ case "binary":
15655
+ return this.FromBinary(str);
15656
+ case "hex":
15657
+ return this.FromHex(str);
15658
+ case "base64":
15659
+ return this.FromBase64(str);
15660
+ case "base64url":
15661
+ return this.FromBase64Url(str);
15662
+ case "utf16le":
15663
+ return Utf16Converter.fromString(str, true);
15664
+ case "utf16":
15665
+ case "utf16be":
15666
+ return Utf16Converter.fromString(str);
15667
+ default:
15668
+ throw new Error(`Unknown type of encoding '${enc}'`);
15669
+ }
15670
+ }
15671
+ static ToBase64(buffer) {
15672
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15673
+ if (typeof btoa !== "undefined") {
15674
+ const binary = this.ToString(buf, "binary");
15675
+ return btoa(binary);
15676
+ }
15677
+ else {
15678
+ return Buffer.from(buf).toString("base64");
15679
+ }
15680
+ }
15681
+ static FromBase64(base64) {
15682
+ const formatted = this.formatString(base64);
15683
+ if (!formatted) {
15684
+ return new ArrayBuffer(0);
15685
+ }
15686
+ if (!Convert.isBase64(formatted)) {
15687
+ throw new TypeError("Argument 'base64Text' is not Base64 encoded");
15688
+ }
15689
+ if (typeof atob !== "undefined") {
15690
+ return this.FromBinary(atob(formatted));
15691
+ }
15692
+ else {
15693
+ return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
15694
+ }
15695
+ }
15696
+ static FromBase64Url(base64url) {
15697
+ const formatted = this.formatString(base64url);
15698
+ if (!formatted) {
15699
+ return new ArrayBuffer(0);
15700
+ }
15701
+ if (!Convert.isBase64Url(formatted)) {
15702
+ throw new TypeError("Argument 'base64url' is not Base64Url encoded");
15703
+ }
15704
+ return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
15705
+ }
15706
+ static ToBase64Url(data) {
15707
+ return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
15708
+ }
15709
+ static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15710
+ switch (encoding) {
15711
+ case "ascii":
15712
+ return this.FromBinary(text);
15713
+ case "utf8":
15714
+ return Utf8Converter.fromString(text);
15715
+ case "utf16":
15716
+ case "utf16be":
15717
+ return Utf16Converter.fromString(text);
15718
+ case "utf16le":
15719
+ case "usc2":
15720
+ return Utf16Converter.fromString(text, true);
15721
+ default:
15722
+ throw new Error(`Unknown type of encoding '${encoding}'`);
15723
+ }
15724
+ }
15725
+ static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15726
+ switch (encoding) {
15727
+ case "ascii":
15728
+ return this.ToBinary(buffer);
15729
+ case "utf8":
15730
+ return Utf8Converter.toString(buffer);
15731
+ case "utf16":
15732
+ case "utf16be":
15733
+ return Utf16Converter.toString(buffer);
15734
+ case "utf16le":
15735
+ case "usc2":
15736
+ return Utf16Converter.toString(buffer, true);
15737
+ default:
15738
+ throw new Error(`Unknown type of encoding '${encoding}'`);
15739
+ }
15740
+ }
15741
+ static FromBinary(text) {
15742
+ const stringLength = text.length;
15743
+ const resultView = new Uint8Array(stringLength);
15744
+ for (let i = 0; i < stringLength; i++) {
15745
+ resultView[i] = text.charCodeAt(i);
15746
+ }
15747
+ return resultView.buffer;
15748
+ }
15749
+ static ToBinary(buffer) {
15750
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15751
+ let res = "";
15752
+ for (let i = 0; i < buf.length; i++) {
15753
+ res += String.fromCharCode(buf[i]);
15754
+ }
15755
+ return res;
15756
+ }
15757
+ static ToHex(buffer) {
15758
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15759
+ let result = "";
15760
+ const len = buf.length;
15761
+ for (let i = 0; i < len; i++) {
15762
+ const byte = buf[i];
15763
+ if (byte < 16) {
15764
+ result += "0";
15765
+ }
15766
+ result += byte.toString(16);
15767
+ }
15768
+ return result;
15769
+ }
15770
+ static FromHex(hexString) {
15771
+ let formatted = this.formatString(hexString);
15772
+ if (!formatted) {
15773
+ return new ArrayBuffer(0);
15774
+ }
15775
+ if (!Convert.isHex(formatted)) {
15776
+ throw new TypeError("Argument 'hexString' is not HEX encoded");
15777
+ }
15778
+ if (formatted.length % 2) {
15779
+ formatted = `0${formatted}`;
15780
+ }
15781
+ const res = new Uint8Array(formatted.length / 2);
15782
+ for (let i = 0; i < formatted.length; i = i + 2) {
15783
+ const c = formatted.slice(i, i + 2);
15784
+ res[i / 2] = parseInt(c, 16);
15785
+ }
15786
+ return res.buffer;
15787
+ }
15788
+ static ToUtf16String(buffer, littleEndian = false) {
15789
+ return Utf16Converter.toString(buffer, littleEndian);
15790
+ }
15791
+ static FromUtf16String(text, littleEndian = false) {
15792
+ return Utf16Converter.fromString(text, littleEndian);
15793
+ }
15794
+ static Base64Padding(base64) {
15795
+ const padCount = 4 - (base64.length % 4);
15796
+ if (padCount < 4) {
15797
+ for (let i = 0; i < padCount; i++) {
15798
+ base64 += "=";
15799
+ }
15800
+ }
15801
+ return base64;
15802
+ }
15803
+ static formatString(data) {
15804
+ return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
15805
+ }
15806
+ }
15793
15807
  Convert.DEFAULT_UTF8_ENCODING = "utf8";
15794
- function combine(...buf) {
15795
- const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur);
15796
- const res = new Uint8Array(totalByteLength);
15797
- let currentPos = 0;
15798
- buf.map((item) => new Uint8Array(item)).forEach((arr) => {
15799
- for (const item2 of arr) {
15800
- res[currentPos++] = item2;
15801
- }
15802
- });
15803
- return res.buffer;
15808
+ function combine(...buf) {
15809
+ const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur);
15810
+ const res = new Uint8Array(totalByteLength);
15811
+ let currentPos = 0;
15812
+ buf.map((item) => new Uint8Array(item)).forEach((arr) => {
15813
+ for (const item2 of arr) {
15814
+ res[currentPos++] = item2;
15815
+ }
15816
+ });
15817
+ return res.buffer;
15804
15818
  }
15805
15819
 
15806
15820
  /*!
@@ -24048,15 +24062,31 @@ class Crypto extends Crypto$1 {
24048
24062
  if (typeof window === 'undefined') {
24049
24063
  global.crypto = new Crypto();
24050
24064
  }
24065
+ /**
24066
+ * Obol sdk Client can be used for creating, managing and activating distributed validators.
24067
+ */
24051
24068
  class Client extends Base {
24069
+ /**
24070
+ * @param config
24071
+ * @param signer ethersJS Signer
24072
+ * @returns Obol-SDK Client instance
24073
+ *
24074
+ * An example of how to instantiate obol-sdk Client:
24075
+ * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
24076
+ */
24052
24077
  constructor(config, signer) {
24053
24078
  super(config);
24054
24079
  this.signer = signer;
24055
24080
  }
24056
24081
  /**
24057
- * @param cluster The new unique cluster
24058
- * @returns Invite Link with config_hash
24059
- */
24082
+ * Creates a cluster definition which contains cluster configuration.
24083
+ * @param {ClusterPayload} newCluster - The new unique cluster.
24084
+ * @returns {Promise<string>} config_hash.
24085
+ * @throws On duplicate entries, missing or wrong cluster keys.
24086
+ *
24087
+ * An example of how to use createClusterDefinition:
24088
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24089
+ */
24060
24090
  async createClusterDefinition(newCluster) {
24061
24091
  const isValid = validateDefinition(newCluster);
24062
24092
  if (isValid !== null)
@@ -24084,9 +24114,25 @@ class Client extends Base {
24084
24114
  }
24085
24115
  }
24086
24116
  /**
24087
- * @param configHash The config hash of the requested cluster
24088
- * @returns The matched cluster details (lock) from DB
24089
- */
24117
+ * @returns {Promise<ClusterDefintion>} The cluster definition for config hash
24118
+ * @throws On not found config hash.
24119
+ *
24120
+ * An example of how to use getClusterDefinition:
24121
+ * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24122
+ */
24123
+ async getClusterDefinition(configHash) {
24124
+ const clusterDefinition = await this.request(`/dv/${configHash}`, {
24125
+ method: 'GET',
24126
+ });
24127
+ return clusterDefinition;
24128
+ }
24129
+ /**
24130
+ * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
24131
+ * @throws On not found cluster definition or lock.
24132
+ *
24133
+ * An example of how to use getClusterLock:
24134
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24135
+ */
24090
24136
  async getClusterLock(configHash) {
24091
24137
  const lock = await this.request(`/lock/configHash/${configHash}`, {
24092
24138
  method: 'GET',