@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.es.js CHANGED
@@ -88,8 +88,8 @@ var FORK_MAPPING;
88
88
  FORK_MAPPING[FORK_MAPPING["0x80000069"] = 3] = "0x80000069";
89
89
  })(FORK_MAPPING || (FORK_MAPPING = {}));
90
90
  const dkg_algorithm = "default";
91
- const config_version = "v1.5.0";
92
- const SDK_VERSION = "1.0.0";
91
+ const config_version = "v1.7.0";
92
+ const SDK_VERSION = "1.0.3"; //should we read it from package.json?
93
93
  const DEFAULT_BASE_URL = "https://api.obol.tech";
94
94
  const DEFAULT_CHAIN_ID = 5;
95
95
 
@@ -361,14 +361,7 @@ function output(out, instance) {
361
361
  }
362
362
  }
363
363
  _assert.output = output;
364
- const assert = {
365
- number,
366
- bool,
367
- bytes,
368
- hash,
369
- exists,
370
- output,
371
- };
364
+ const assert = { number, bool, bytes, hash, exists, output };
372
365
  _assert.default = assert;
373
366
 
374
367
  var utils = {};
@@ -407,7 +400,7 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
407
400
  exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
408
401
  if (!exports.isLE)
409
402
  throw new Error('Non little-endian hardware is not supported');
410
- const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
403
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
411
404
  /**
412
405
  * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
413
406
  */
@@ -507,10 +500,9 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
507
500
  }
508
501
  }
509
502
  exports.Hash = Hash;
510
- // Check if object doens't have custom constructor (like Uint8Array/Array)
511
- const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
503
+ const toStr = {}.toString;
512
504
  function checkOpts(defaults, opts) {
513
- if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
505
+ if (opts !== undefined && toStr.call(opts) !== '[object Object]')
514
506
  throw new Error('Options should be object or undefined');
515
507
  const merged = Object.assign(defaults, opts);
516
508
  return merged;
@@ -589,7 +581,7 @@ class SHA2 extends utils_js_1$1.Hash {
589
581
  this.view = (0, utils_js_1$1.createView)(this.buffer);
590
582
  }
591
583
  update(data) {
592
- _assert_js_1.default.exists(this);
584
+ (0, _assert_js_1.exists)(this);
593
585
  const { view, buffer, blockLen } = this;
594
586
  data = (0, utils_js_1$1.toBytes)(data);
595
587
  const len = data.length;
@@ -615,8 +607,8 @@ class SHA2 extends utils_js_1$1.Hash {
615
607
  return this;
616
608
  }
617
609
  digestInto(out) {
618
- _assert_js_1.default.exists(this);
619
- _assert_js_1.default.output(out, this);
610
+ (0, _assert_js_1.exists)(this);
611
+ (0, _assert_js_1.output)(out, this);
620
612
  this.finished = true;
621
613
  // Padding
622
614
  // We can avoid allocation of buffer for padding completely if it
@@ -677,6 +669,8 @@ Object.defineProperty(sha256, "__esModule", { value: true });
677
669
  sha256.sha224 = sha256.sha256 = void 0;
678
670
  const _sha2_js_1 = _sha2;
679
671
  const utils_js_1 = utils;
672
+ // SHA2-256 need to try 2^128 hashes to execute birthday attack.
673
+ // BTC network is doing 2^67 hashes/sec as per early 2023.
680
674
  // Choice: a ? b : c
681
675
  const Chi = (a, b, c) => (a & b) ^ (~a & c);
682
676
  // Majority function, true if any two inpust is true
@@ -684,7 +678,7 @@ const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
684
678
  // Round constants:
685
679
  // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
686
680
  // prettier-ignore
687
- const SHA256_K = new Uint32Array([
681
+ const SHA256_K = /* @__PURE__ */ new Uint32Array([
688
682
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
689
683
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
690
684
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -696,12 +690,12 @@ const SHA256_K = new Uint32Array([
696
690
  ]);
697
691
  // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
698
692
  // prettier-ignore
699
- const IV = new Uint32Array([
693
+ const IV = /* @__PURE__ */ new Uint32Array([
700
694
  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
701
695
  ]);
702
696
  // Temporary buffer, not used to store anything between runs
703
697
  // Named this way because it matches specification.
704
- const SHA256_W = new Uint32Array(64);
698
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
705
699
  class SHA256 extends _sha2_js_1.SHA2 {
706
700
  constructor() {
707
701
  super(64, 32, 8, false);
@@ -7957,12 +7951,12 @@ vectorComposite.VectorCompositeType = VectorCompositeType;
7957
7951
  * @returns The config hash or he definition hash in of the corresponding cluster definition
7958
7952
  */
7959
7953
  const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
7960
- const definitionType = clusterDefinitionContainerTypeV1X5(configOnly);
7961
- const val = hashClusterDefinitionV1X5(cluster, configOnly);
7954
+ const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
7955
+ const val = hashClusterDefinitionV1X7(cluster, configOnly);
7962
7956
  return ('0x' + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
7963
7957
  };
7964
- const hashClusterDefinitionV1X5 = (cluster, configOnly) => {
7965
- const definitionType = clusterDefinitionContainerTypeV1X5(configOnly);
7958
+ const hashClusterDefinitionV1X7 = (cluster, configOnly) => {
7959
+ const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
7966
7960
  const val = definitionType.defaultValue();
7967
7961
  //order should be same as charon https://github.com/ObolNetwork/charon/blob/d00b31e6465a260a43ce40f15c47fb5a5b009042/cluster/ssz.go#L285
7968
7962
  val.uuid = strToUint8Array(cluster.uuid);
@@ -8043,7 +8037,7 @@ const newOperatorContainerType = (configOnly) => {
8043
8037
  * @param cluster ClusterDefinition to calculate the type from
8044
8038
  * @returns SSZ Containerized type of cluster input
8045
8039
  */
8046
- const clusterDefinitionContainerTypeV1X5 = (configOnly) => {
8040
+ const clusterDefinitionContainerTypeV1X7 = (configOnly) => {
8047
8041
  let returnedContainerType = {
8048
8042
  uuid: new lib$1.ByteListType(64),
8049
8043
  name: new lib$1.ByteListType(256),
@@ -15456,324 +15450,344 @@ function validateDefinition(data) {
15456
15450
  *
15457
15451
  */
15458
15452
 
15459
- const ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
15460
- class BufferSourceConverter {
15461
- static isArrayBuffer(data) {
15462
- return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
15463
- }
15464
- static toArrayBuffer(data) {
15465
- if (this.isArrayBuffer(data)) {
15466
- return data;
15467
- }
15468
- if (data.byteLength === data.buffer.byteLength) {
15469
- return data.buffer;
15470
- }
15471
- return this.toUint8Array(data).slice().buffer;
15472
- }
15473
- static toUint8Array(data) {
15474
- return this.toView(data, Uint8Array);
15475
- }
15476
- static toView(data, type) {
15477
- if (data.constructor === type) {
15478
- return data;
15479
- }
15480
- if (this.isArrayBuffer(data)) {
15481
- return new type(data);
15482
- }
15483
- if (this.isArrayBufferView(data)) {
15484
- return new type(data.buffer, data.byteOffset, data.byteLength);
15485
- }
15486
- throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
15487
- }
15488
- static isBufferSource(data) {
15489
- return this.isArrayBufferView(data)
15490
- || this.isArrayBuffer(data);
15491
- }
15492
- static isArrayBufferView(data) {
15493
- return ArrayBuffer.isView(data)
15494
- || (data && this.isArrayBuffer(data.buffer));
15495
- }
15496
- static isEqual(a, b) {
15497
- const aView = BufferSourceConverter.toUint8Array(a);
15498
- const bView = BufferSourceConverter.toUint8Array(b);
15499
- if (aView.length !== bView.byteLength) {
15500
- return false;
15501
- }
15502
- for (let i = 0; i < aView.length; i++) {
15503
- if (aView[i] !== bView[i]) {
15504
- return false;
15505
- }
15506
- }
15507
- return true;
15508
- }
15509
- static concat(...args) {
15510
- if (Array.isArray(args[0])) {
15511
- const buffers = args[0];
15512
- let size = 0;
15513
- for (const buffer of buffers) {
15514
- size += buffer.byteLength;
15515
- }
15516
- const res = new Uint8Array(size);
15517
- let offset = 0;
15518
- for (const buffer of buffers) {
15519
- const view = this.toUint8Array(buffer);
15520
- res.set(view, offset);
15521
- offset += view.length;
15522
- }
15523
- if (args[1]) {
15524
- return this.toView(res, args[1]);
15525
- }
15526
- return res.buffer;
15527
- }
15528
- else {
15529
- return this.concat(args);
15530
- }
15531
- }
15453
+ const ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
15454
+ class BufferSourceConverter {
15455
+ static isArrayBuffer(data) {
15456
+ return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
15457
+ }
15458
+ static toArrayBuffer(data) {
15459
+ if (this.isArrayBuffer(data)) {
15460
+ return data;
15461
+ }
15462
+ if (data.byteLength === data.buffer.byteLength) {
15463
+ return data.buffer;
15464
+ }
15465
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
15466
+ return data.buffer;
15467
+ }
15468
+ return this.toUint8Array(data.buffer)
15469
+ .slice(data.byteOffset, data.byteOffset + data.byteLength)
15470
+ .buffer;
15471
+ }
15472
+ static toUint8Array(data) {
15473
+ return this.toView(data, Uint8Array);
15474
+ }
15475
+ static toView(data, type) {
15476
+ if (data.constructor === type) {
15477
+ return data;
15478
+ }
15479
+ if (this.isArrayBuffer(data)) {
15480
+ return new type(data);
15481
+ }
15482
+ if (this.isArrayBufferView(data)) {
15483
+ return new type(data.buffer, data.byteOffset, data.byteLength);
15484
+ }
15485
+ throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
15486
+ }
15487
+ static isBufferSource(data) {
15488
+ return this.isArrayBufferView(data)
15489
+ || this.isArrayBuffer(data);
15490
+ }
15491
+ static isArrayBufferView(data) {
15492
+ return ArrayBuffer.isView(data)
15493
+ || (data && this.isArrayBuffer(data.buffer));
15494
+ }
15495
+ static isEqual(a, b) {
15496
+ const aView = BufferSourceConverter.toUint8Array(a);
15497
+ const bView = BufferSourceConverter.toUint8Array(b);
15498
+ if (aView.length !== bView.byteLength) {
15499
+ return false;
15500
+ }
15501
+ for (let i = 0; i < aView.length; i++) {
15502
+ if (aView[i] !== bView[i]) {
15503
+ return false;
15504
+ }
15505
+ }
15506
+ return true;
15507
+ }
15508
+ static concat(...args) {
15509
+ let buffers;
15510
+ if (Array.isArray(args[0]) && !(args[1] instanceof Function)) {
15511
+ buffers = args[0];
15512
+ }
15513
+ else if (Array.isArray(args[0]) && args[1] instanceof Function) {
15514
+ buffers = args[0];
15515
+ }
15516
+ else {
15517
+ if (args[args.length - 1] instanceof Function) {
15518
+ buffers = args.slice(0, args.length - 1);
15519
+ }
15520
+ else {
15521
+ buffers = args;
15522
+ }
15523
+ }
15524
+ let size = 0;
15525
+ for (const buffer of buffers) {
15526
+ size += buffer.byteLength;
15527
+ }
15528
+ const res = new Uint8Array(size);
15529
+ let offset = 0;
15530
+ for (const buffer of buffers) {
15531
+ const view = this.toUint8Array(buffer);
15532
+ res.set(view, offset);
15533
+ offset += view.length;
15534
+ }
15535
+ if (args[args.length - 1] instanceof Function) {
15536
+ return this.toView(res, args[args.length - 1]);
15537
+ }
15538
+ return res.buffer;
15539
+ }
15532
15540
  }
15533
15541
 
15534
- class Utf8Converter {
15535
- static fromString(text) {
15536
- const s = unescape(encodeURIComponent(text));
15537
- const uintArray = new Uint8Array(s.length);
15538
- for (let i = 0; i < s.length; i++) {
15539
- uintArray[i] = s.charCodeAt(i);
15540
- }
15541
- return uintArray.buffer;
15542
- }
15543
- static toString(buffer) {
15544
- const buf = BufferSourceConverter.toUint8Array(buffer);
15545
- let encodedString = "";
15546
- for (let i = 0; i < buf.length; i++) {
15547
- encodedString += String.fromCharCode(buf[i]);
15548
- }
15549
- const decodedString = decodeURIComponent(escape(encodedString));
15550
- return decodedString;
15551
- }
15552
- }
15553
- class Utf16Converter {
15554
- static toString(buffer, littleEndian = false) {
15555
- const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
15556
- const dataView = new DataView(arrayBuffer);
15557
- let res = "";
15558
- for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
15559
- const code = dataView.getUint16(i, littleEndian);
15560
- res += String.fromCharCode(code);
15561
- }
15562
- return res;
15563
- }
15564
- static fromString(text, littleEndian = false) {
15565
- const res = new ArrayBuffer(text.length * 2);
15566
- const dataView = new DataView(res);
15567
- for (let i = 0; i < text.length; i++) {
15568
- dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
15569
- }
15570
- return res;
15571
- }
15572
- }
15573
- class Convert {
15574
- static isHex(data) {
15575
- return typeof data === "string"
15576
- && /^[a-z0-9]+$/i.test(data);
15577
- }
15578
- static isBase64(data) {
15579
- return typeof data === "string"
15580
- && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data);
15581
- }
15582
- static isBase64Url(data) {
15583
- return typeof data === "string"
15584
- && /^[a-zA-Z0-9-_]+$/i.test(data);
15585
- }
15586
- static ToString(buffer, enc = "utf8") {
15587
- const buf = BufferSourceConverter.toUint8Array(buffer);
15588
- switch (enc.toLowerCase()) {
15589
- case "utf8":
15590
- return this.ToUtf8String(buf);
15591
- case "binary":
15592
- return this.ToBinary(buf);
15593
- case "hex":
15594
- return this.ToHex(buf);
15595
- case "base64":
15596
- return this.ToBase64(buf);
15597
- case "base64url":
15598
- return this.ToBase64Url(buf);
15599
- case "utf16le":
15600
- return Utf16Converter.toString(buf, true);
15601
- case "utf16":
15602
- case "utf16be":
15603
- return Utf16Converter.toString(buf);
15604
- default:
15605
- throw new Error(`Unknown type of encoding '${enc}'`);
15606
- }
15607
- }
15608
- static FromString(str, enc = "utf8") {
15609
- if (!str) {
15610
- return new ArrayBuffer(0);
15611
- }
15612
- switch (enc.toLowerCase()) {
15613
- case "utf8":
15614
- return this.FromUtf8String(str);
15615
- case "binary":
15616
- return this.FromBinary(str);
15617
- case "hex":
15618
- return this.FromHex(str);
15619
- case "base64":
15620
- return this.FromBase64(str);
15621
- case "base64url":
15622
- return this.FromBase64Url(str);
15623
- case "utf16le":
15624
- return Utf16Converter.fromString(str, true);
15625
- case "utf16":
15626
- case "utf16be":
15627
- return Utf16Converter.fromString(str);
15628
- default:
15629
- throw new Error(`Unknown type of encoding '${enc}'`);
15630
- }
15631
- }
15632
- static ToBase64(buffer) {
15633
- const buf = BufferSourceConverter.toUint8Array(buffer);
15634
- if (typeof btoa !== "undefined") {
15635
- const binary = this.ToString(buf, "binary");
15636
- return btoa(binary);
15637
- }
15638
- else {
15639
- return Buffer.from(buf).toString("base64");
15640
- }
15641
- }
15642
- static FromBase64(base64) {
15643
- const formatted = this.formatString(base64);
15644
- if (!formatted) {
15645
- return new ArrayBuffer(0);
15646
- }
15647
- if (!Convert.isBase64(formatted)) {
15648
- throw new TypeError("Argument 'base64Text' is not Base64 encoded");
15649
- }
15650
- if (typeof atob !== "undefined") {
15651
- return this.FromBinary(atob(formatted));
15652
- }
15653
- else {
15654
- return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
15655
- }
15656
- }
15657
- static FromBase64Url(base64url) {
15658
- const formatted = this.formatString(base64url);
15659
- if (!formatted) {
15660
- return new ArrayBuffer(0);
15661
- }
15662
- if (!Convert.isBase64Url(formatted)) {
15663
- throw new TypeError("Argument 'base64url' is not Base64Url encoded");
15664
- }
15665
- return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
15666
- }
15667
- static ToBase64Url(data) {
15668
- return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
15669
- }
15670
- static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15671
- switch (encoding) {
15672
- case "ascii":
15673
- return this.FromBinary(text);
15674
- case "utf8":
15675
- return Utf8Converter.fromString(text);
15676
- case "utf16":
15677
- case "utf16be":
15678
- return Utf16Converter.fromString(text);
15679
- case "utf16le":
15680
- case "usc2":
15681
- return Utf16Converter.fromString(text, true);
15682
- default:
15683
- throw new Error(`Unknown type of encoding '${encoding}'`);
15684
- }
15685
- }
15686
- static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15687
- switch (encoding) {
15688
- case "ascii":
15689
- return this.ToBinary(buffer);
15690
- case "utf8":
15691
- return Utf8Converter.toString(buffer);
15692
- case "utf16":
15693
- case "utf16be":
15694
- return Utf16Converter.toString(buffer);
15695
- case "utf16le":
15696
- case "usc2":
15697
- return Utf16Converter.toString(buffer, true);
15698
- default:
15699
- throw new Error(`Unknown type of encoding '${encoding}'`);
15700
- }
15701
- }
15702
- static FromBinary(text) {
15703
- const stringLength = text.length;
15704
- const resultView = new Uint8Array(stringLength);
15705
- for (let i = 0; i < stringLength; i++) {
15706
- resultView[i] = text.charCodeAt(i);
15707
- }
15708
- return resultView.buffer;
15709
- }
15710
- static ToBinary(buffer) {
15711
- const buf = BufferSourceConverter.toUint8Array(buffer);
15712
- let res = "";
15713
- for (let i = 0; i < buf.length; i++) {
15714
- res += String.fromCharCode(buf[i]);
15715
- }
15716
- return res;
15717
- }
15718
- static ToHex(buffer) {
15719
- const buf = BufferSourceConverter.toUint8Array(buffer);
15720
- const splitter = "";
15721
- const res = [];
15722
- const len = buf.length;
15723
- for (let i = 0; i < len; i++) {
15724
- const char = buf[i].toString(16).padStart(2, "0");
15725
- res.push(char);
15726
- }
15727
- return res.join(splitter);
15728
- }
15729
- static FromHex(hexString) {
15730
- let formatted = this.formatString(hexString);
15731
- if (!formatted) {
15732
- return new ArrayBuffer(0);
15733
- }
15734
- if (!Convert.isHex(formatted)) {
15735
- throw new TypeError("Argument 'hexString' is not HEX encoded");
15736
- }
15737
- if (formatted.length % 2) {
15738
- formatted = `0${formatted}`;
15739
- }
15740
- const res = new Uint8Array(formatted.length / 2);
15741
- for (let i = 0; i < formatted.length; i = i + 2) {
15742
- const c = formatted.slice(i, i + 2);
15743
- res[i / 2] = parseInt(c, 16);
15744
- }
15745
- return res.buffer;
15746
- }
15747
- static ToUtf16String(buffer, littleEndian = false) {
15748
- return Utf16Converter.toString(buffer, littleEndian);
15749
- }
15750
- static FromUtf16String(text, littleEndian = false) {
15751
- return Utf16Converter.fromString(text, littleEndian);
15752
- }
15753
- static Base64Padding(base64) {
15754
- const padCount = 4 - (base64.length % 4);
15755
- if (padCount < 4) {
15756
- for (let i = 0; i < padCount; i++) {
15757
- base64 += "=";
15758
- }
15759
- }
15760
- return base64;
15761
- }
15762
- static formatString(data) {
15763
- return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
15764
- }
15765
- }
15542
+ const STRING_TYPE = "string";
15543
+ const HEX_REGEX = /^[0-9a-f]+$/i;
15544
+ const BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
15545
+ const BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;
15546
+ class Utf8Converter {
15547
+ static fromString(text) {
15548
+ const s = unescape(encodeURIComponent(text));
15549
+ const uintArray = new Uint8Array(s.length);
15550
+ for (let i = 0; i < s.length; i++) {
15551
+ uintArray[i] = s.charCodeAt(i);
15552
+ }
15553
+ return uintArray.buffer;
15554
+ }
15555
+ static toString(buffer) {
15556
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15557
+ let encodedString = "";
15558
+ for (let i = 0; i < buf.length; i++) {
15559
+ encodedString += String.fromCharCode(buf[i]);
15560
+ }
15561
+ const decodedString = decodeURIComponent(escape(encodedString));
15562
+ return decodedString;
15563
+ }
15564
+ }
15565
+ class Utf16Converter {
15566
+ static toString(buffer, littleEndian = false) {
15567
+ const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
15568
+ const dataView = new DataView(arrayBuffer);
15569
+ let res = "";
15570
+ for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
15571
+ const code = dataView.getUint16(i, littleEndian);
15572
+ res += String.fromCharCode(code);
15573
+ }
15574
+ return res;
15575
+ }
15576
+ static fromString(text, littleEndian = false) {
15577
+ const res = new ArrayBuffer(text.length * 2);
15578
+ const dataView = new DataView(res);
15579
+ for (let i = 0; i < text.length; i++) {
15580
+ dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
15581
+ }
15582
+ return res;
15583
+ }
15584
+ }
15585
+ class Convert {
15586
+ static isHex(data) {
15587
+ return typeof data === STRING_TYPE
15588
+ && HEX_REGEX.test(data);
15589
+ }
15590
+ static isBase64(data) {
15591
+ return typeof data === STRING_TYPE
15592
+ && BASE64_REGEX.test(data);
15593
+ }
15594
+ static isBase64Url(data) {
15595
+ return typeof data === STRING_TYPE
15596
+ && BASE64URL_REGEX.test(data);
15597
+ }
15598
+ static ToString(buffer, enc = "utf8") {
15599
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15600
+ switch (enc.toLowerCase()) {
15601
+ case "utf8":
15602
+ return this.ToUtf8String(buf);
15603
+ case "binary":
15604
+ return this.ToBinary(buf);
15605
+ case "hex":
15606
+ return this.ToHex(buf);
15607
+ case "base64":
15608
+ return this.ToBase64(buf);
15609
+ case "base64url":
15610
+ return this.ToBase64Url(buf);
15611
+ case "utf16le":
15612
+ return Utf16Converter.toString(buf, true);
15613
+ case "utf16":
15614
+ case "utf16be":
15615
+ return Utf16Converter.toString(buf);
15616
+ default:
15617
+ throw new Error(`Unknown type of encoding '${enc}'`);
15618
+ }
15619
+ }
15620
+ static FromString(str, enc = "utf8") {
15621
+ if (!str) {
15622
+ return new ArrayBuffer(0);
15623
+ }
15624
+ switch (enc.toLowerCase()) {
15625
+ case "utf8":
15626
+ return this.FromUtf8String(str);
15627
+ case "binary":
15628
+ return this.FromBinary(str);
15629
+ case "hex":
15630
+ return this.FromHex(str);
15631
+ case "base64":
15632
+ return this.FromBase64(str);
15633
+ case "base64url":
15634
+ return this.FromBase64Url(str);
15635
+ case "utf16le":
15636
+ return Utf16Converter.fromString(str, true);
15637
+ case "utf16":
15638
+ case "utf16be":
15639
+ return Utf16Converter.fromString(str);
15640
+ default:
15641
+ throw new Error(`Unknown type of encoding '${enc}'`);
15642
+ }
15643
+ }
15644
+ static ToBase64(buffer) {
15645
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15646
+ if (typeof btoa !== "undefined") {
15647
+ const binary = this.ToString(buf, "binary");
15648
+ return btoa(binary);
15649
+ }
15650
+ else {
15651
+ return Buffer.from(buf).toString("base64");
15652
+ }
15653
+ }
15654
+ static FromBase64(base64) {
15655
+ const formatted = this.formatString(base64);
15656
+ if (!formatted) {
15657
+ return new ArrayBuffer(0);
15658
+ }
15659
+ if (!Convert.isBase64(formatted)) {
15660
+ throw new TypeError("Argument 'base64Text' is not Base64 encoded");
15661
+ }
15662
+ if (typeof atob !== "undefined") {
15663
+ return this.FromBinary(atob(formatted));
15664
+ }
15665
+ else {
15666
+ return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
15667
+ }
15668
+ }
15669
+ static FromBase64Url(base64url) {
15670
+ const formatted = this.formatString(base64url);
15671
+ if (!formatted) {
15672
+ return new ArrayBuffer(0);
15673
+ }
15674
+ if (!Convert.isBase64Url(formatted)) {
15675
+ throw new TypeError("Argument 'base64url' is not Base64Url encoded");
15676
+ }
15677
+ return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
15678
+ }
15679
+ static ToBase64Url(data) {
15680
+ return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
15681
+ }
15682
+ static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15683
+ switch (encoding) {
15684
+ case "ascii":
15685
+ return this.FromBinary(text);
15686
+ case "utf8":
15687
+ return Utf8Converter.fromString(text);
15688
+ case "utf16":
15689
+ case "utf16be":
15690
+ return Utf16Converter.fromString(text);
15691
+ case "utf16le":
15692
+ case "usc2":
15693
+ return Utf16Converter.fromString(text, true);
15694
+ default:
15695
+ throw new Error(`Unknown type of encoding '${encoding}'`);
15696
+ }
15697
+ }
15698
+ static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15699
+ switch (encoding) {
15700
+ case "ascii":
15701
+ return this.ToBinary(buffer);
15702
+ case "utf8":
15703
+ return Utf8Converter.toString(buffer);
15704
+ case "utf16":
15705
+ case "utf16be":
15706
+ return Utf16Converter.toString(buffer);
15707
+ case "utf16le":
15708
+ case "usc2":
15709
+ return Utf16Converter.toString(buffer, true);
15710
+ default:
15711
+ throw new Error(`Unknown type of encoding '${encoding}'`);
15712
+ }
15713
+ }
15714
+ static FromBinary(text) {
15715
+ const stringLength = text.length;
15716
+ const resultView = new Uint8Array(stringLength);
15717
+ for (let i = 0; i < stringLength; i++) {
15718
+ resultView[i] = text.charCodeAt(i);
15719
+ }
15720
+ return resultView.buffer;
15721
+ }
15722
+ static ToBinary(buffer) {
15723
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15724
+ let res = "";
15725
+ for (let i = 0; i < buf.length; i++) {
15726
+ res += String.fromCharCode(buf[i]);
15727
+ }
15728
+ return res;
15729
+ }
15730
+ static ToHex(buffer) {
15731
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15732
+ let result = "";
15733
+ const len = buf.length;
15734
+ for (let i = 0; i < len; i++) {
15735
+ const byte = buf[i];
15736
+ if (byte < 16) {
15737
+ result += "0";
15738
+ }
15739
+ result += byte.toString(16);
15740
+ }
15741
+ return result;
15742
+ }
15743
+ static FromHex(hexString) {
15744
+ let formatted = this.formatString(hexString);
15745
+ if (!formatted) {
15746
+ return new ArrayBuffer(0);
15747
+ }
15748
+ if (!Convert.isHex(formatted)) {
15749
+ throw new TypeError("Argument 'hexString' is not HEX encoded");
15750
+ }
15751
+ if (formatted.length % 2) {
15752
+ formatted = `0${formatted}`;
15753
+ }
15754
+ const res = new Uint8Array(formatted.length / 2);
15755
+ for (let i = 0; i < formatted.length; i = i + 2) {
15756
+ const c = formatted.slice(i, i + 2);
15757
+ res[i / 2] = parseInt(c, 16);
15758
+ }
15759
+ return res.buffer;
15760
+ }
15761
+ static ToUtf16String(buffer, littleEndian = false) {
15762
+ return Utf16Converter.toString(buffer, littleEndian);
15763
+ }
15764
+ static FromUtf16String(text, littleEndian = false) {
15765
+ return Utf16Converter.fromString(text, littleEndian);
15766
+ }
15767
+ static Base64Padding(base64) {
15768
+ const padCount = 4 - (base64.length % 4);
15769
+ if (padCount < 4) {
15770
+ for (let i = 0; i < padCount; i++) {
15771
+ base64 += "=";
15772
+ }
15773
+ }
15774
+ return base64;
15775
+ }
15776
+ static formatString(data) {
15777
+ return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
15778
+ }
15779
+ }
15766
15780
  Convert.DEFAULT_UTF8_ENCODING = "utf8";
15767
- function combine(...buf) {
15768
- const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur);
15769
- const res = new Uint8Array(totalByteLength);
15770
- let currentPos = 0;
15771
- buf.map((item) => new Uint8Array(item)).forEach((arr) => {
15772
- for (const item2 of arr) {
15773
- res[currentPos++] = item2;
15774
- }
15775
- });
15776
- return res.buffer;
15781
+ function combine(...buf) {
15782
+ const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur);
15783
+ const res = new Uint8Array(totalByteLength);
15784
+ let currentPos = 0;
15785
+ buf.map((item) => new Uint8Array(item)).forEach((arr) => {
15786
+ for (const item2 of arr) {
15787
+ res[currentPos++] = item2;
15788
+ }
15789
+ });
15790
+ return res.buffer;
15777
15791
  }
15778
15792
 
15779
15793
  /*!
@@ -24021,15 +24035,31 @@ class Crypto extends Crypto$1 {
24021
24035
  if (typeof window === 'undefined') {
24022
24036
  global.crypto = new Crypto();
24023
24037
  }
24038
+ /**
24039
+ * Obol sdk Client can be used for creating, managing and activating distributed validators.
24040
+ */
24024
24041
  class Client extends Base {
24042
+ /**
24043
+ * @param config
24044
+ * @param signer ethersJS Signer
24045
+ * @returns Obol-SDK Client instance
24046
+ *
24047
+ * An example of how to instantiate obol-sdk Client:
24048
+ * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
24049
+ */
24025
24050
  constructor(config, signer) {
24026
24051
  super(config);
24027
24052
  this.signer = signer;
24028
24053
  }
24029
24054
  /**
24030
- * @param cluster The new unique cluster
24031
- * @returns Invite Link with config_hash
24032
- */
24055
+ * Creates a cluster definition which contains cluster configuration.
24056
+ * @param {ClusterPayload} newCluster - The new unique cluster.
24057
+ * @returns {Promise<string>} config_hash.
24058
+ * @throws On duplicate entries, missing or wrong cluster keys.
24059
+ *
24060
+ * An example of how to use createClusterDefinition:
24061
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24062
+ */
24033
24063
  async createClusterDefinition(newCluster) {
24034
24064
  const isValid = validateDefinition(newCluster);
24035
24065
  if (isValid !== null)
@@ -24057,9 +24087,25 @@ class Client extends Base {
24057
24087
  }
24058
24088
  }
24059
24089
  /**
24060
- * @param configHash The config hash of the requested cluster
24061
- * @returns The matched cluster details (lock) from DB
24062
- */
24090
+ * @returns {Promise<ClusterDefintion>} The cluster definition for config hash
24091
+ * @throws On not found config hash.
24092
+ *
24093
+ * An example of how to use getClusterDefinition:
24094
+ * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24095
+ */
24096
+ async getClusterDefinition(configHash) {
24097
+ const clusterDefinition = await this.request(`/dv/${configHash}`, {
24098
+ method: 'GET',
24099
+ });
24100
+ return clusterDefinition;
24101
+ }
24102
+ /**
24103
+ * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
24104
+ * @throws On not found cluster definition or lock.
24105
+ *
24106
+ * An example of how to use getClusterLock:
24107
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24108
+ */
24063
24109
  async getClusterLock(configHash) {
24064
24110
  const lock = await this.request(`/lock/configHash/${configHash}`, {
24065
24111
  method: 'GET',