@obolnetwork/obol-sdk 1.0.4 → 1.0.5

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
 
@@ -7957,12 +7957,12 @@ vectorComposite.VectorCompositeType = VectorCompositeType;
7957
7957
  * @returns The config hash or he definition hash in of the corresponding cluster definition
7958
7958
  */
7959
7959
  const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
7960
- const definitionType = clusterDefinitionContainerTypeV1X5(configOnly);
7961
- const val = hashClusterDefinitionV1X5(cluster, configOnly);
7960
+ const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
7961
+ const val = hashClusterDefinitionV1X7(cluster, configOnly);
7962
7962
  return ('0x' + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
7963
7963
  };
7964
- const hashClusterDefinitionV1X5 = (cluster, configOnly) => {
7965
- const definitionType = clusterDefinitionContainerTypeV1X5(configOnly);
7964
+ const hashClusterDefinitionV1X7 = (cluster, configOnly) => {
7965
+ const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
7966
7966
  const val = definitionType.defaultValue();
7967
7967
  //order should be same as charon https://github.com/ObolNetwork/charon/blob/d00b31e6465a260a43ce40f15c47fb5a5b009042/cluster/ssz.go#L285
7968
7968
  val.uuid = strToUint8Array(cluster.uuid);
@@ -8043,7 +8043,7 @@ const newOperatorContainerType = (configOnly) => {
8043
8043
  * @param cluster ClusterDefinition to calculate the type from
8044
8044
  * @returns SSZ Containerized type of cluster input
8045
8045
  */
8046
- const clusterDefinitionContainerTypeV1X5 = (configOnly) => {
8046
+ const clusterDefinitionContainerTypeV1X7 = (configOnly) => {
8047
8047
  let returnedContainerType = {
8048
8048
  uuid: new lib$1.ByteListType(64),
8049
8049
  name: new lib$1.ByteListType(256),
@@ -15456,324 +15456,344 @@ function validateDefinition(data) {
15456
15456
  *
15457
15457
  */
15458
15458
 
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
- }
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
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
15472
+ return data.buffer;
15473
+ }
15474
+ return this.toUint8Array(data.buffer)
15475
+ .slice(data.byteOffset, data.byteOffset + data.byteLength)
15476
+ .buffer;
15477
+ }
15478
+ static toUint8Array(data) {
15479
+ return this.toView(data, Uint8Array);
15480
+ }
15481
+ static toView(data, type) {
15482
+ if (data.constructor === type) {
15483
+ return data;
15484
+ }
15485
+ if (this.isArrayBuffer(data)) {
15486
+ return new type(data);
15487
+ }
15488
+ if (this.isArrayBufferView(data)) {
15489
+ return new type(data.buffer, data.byteOffset, data.byteLength);
15490
+ }
15491
+ throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
15492
+ }
15493
+ static isBufferSource(data) {
15494
+ return this.isArrayBufferView(data)
15495
+ || this.isArrayBuffer(data);
15496
+ }
15497
+ static isArrayBufferView(data) {
15498
+ return ArrayBuffer.isView(data)
15499
+ || (data && this.isArrayBuffer(data.buffer));
15500
+ }
15501
+ static isEqual(a, b) {
15502
+ const aView = BufferSourceConverter.toUint8Array(a);
15503
+ const bView = BufferSourceConverter.toUint8Array(b);
15504
+ if (aView.length !== bView.byteLength) {
15505
+ return false;
15506
+ }
15507
+ for (let i = 0; i < aView.length; i++) {
15508
+ if (aView[i] !== bView[i]) {
15509
+ return false;
15510
+ }
15511
+ }
15512
+ return true;
15513
+ }
15514
+ static concat(...args) {
15515
+ let buffers;
15516
+ if (Array.isArray(args[0]) && !(args[1] instanceof Function)) {
15517
+ buffers = args[0];
15518
+ }
15519
+ else if (Array.isArray(args[0]) && args[1] instanceof Function) {
15520
+ buffers = args[0];
15521
+ }
15522
+ else {
15523
+ if (args[args.length - 1] instanceof Function) {
15524
+ buffers = args.slice(0, args.length - 1);
15525
+ }
15526
+ else {
15527
+ buffers = args;
15528
+ }
15529
+ }
15530
+ let size = 0;
15531
+ for (const buffer of buffers) {
15532
+ size += buffer.byteLength;
15533
+ }
15534
+ const res = new Uint8Array(size);
15535
+ let offset = 0;
15536
+ for (const buffer of buffers) {
15537
+ const view = this.toUint8Array(buffer);
15538
+ res.set(view, offset);
15539
+ offset += view.length;
15540
+ }
15541
+ if (args[args.length - 1] instanceof Function) {
15542
+ return this.toView(res, args[args.length - 1]);
15543
+ }
15544
+ return res.buffer;
15545
+ }
15532
15546
  }
15533
15547
 
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
- }
15548
+ const STRING_TYPE = "string";
15549
+ const HEX_REGEX = /^[0-9a-f]+$/i;
15550
+ const BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
15551
+ const BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;
15552
+ class Utf8Converter {
15553
+ static fromString(text) {
15554
+ const s = unescape(encodeURIComponent(text));
15555
+ const uintArray = new Uint8Array(s.length);
15556
+ for (let i = 0; i < s.length; i++) {
15557
+ uintArray[i] = s.charCodeAt(i);
15558
+ }
15559
+ return uintArray.buffer;
15560
+ }
15561
+ static toString(buffer) {
15562
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15563
+ let encodedString = "";
15564
+ for (let i = 0; i < buf.length; i++) {
15565
+ encodedString += String.fromCharCode(buf[i]);
15566
+ }
15567
+ const decodedString = decodeURIComponent(escape(encodedString));
15568
+ return decodedString;
15569
+ }
15570
+ }
15571
+ class Utf16Converter {
15572
+ static toString(buffer, littleEndian = false) {
15573
+ const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
15574
+ const dataView = new DataView(arrayBuffer);
15575
+ let res = "";
15576
+ for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
15577
+ const code = dataView.getUint16(i, littleEndian);
15578
+ res += String.fromCharCode(code);
15579
+ }
15580
+ return res;
15581
+ }
15582
+ static fromString(text, littleEndian = false) {
15583
+ const res = new ArrayBuffer(text.length * 2);
15584
+ const dataView = new DataView(res);
15585
+ for (let i = 0; i < text.length; i++) {
15586
+ dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
15587
+ }
15588
+ return res;
15589
+ }
15590
+ }
15591
+ class Convert {
15592
+ static isHex(data) {
15593
+ return typeof data === STRING_TYPE
15594
+ && HEX_REGEX.test(data);
15595
+ }
15596
+ static isBase64(data) {
15597
+ return typeof data === STRING_TYPE
15598
+ && BASE64_REGEX.test(data);
15599
+ }
15600
+ static isBase64Url(data) {
15601
+ return typeof data === STRING_TYPE
15602
+ && BASE64URL_REGEX.test(data);
15603
+ }
15604
+ static ToString(buffer, enc = "utf8") {
15605
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15606
+ switch (enc.toLowerCase()) {
15607
+ case "utf8":
15608
+ return this.ToUtf8String(buf);
15609
+ case "binary":
15610
+ return this.ToBinary(buf);
15611
+ case "hex":
15612
+ return this.ToHex(buf);
15613
+ case "base64":
15614
+ return this.ToBase64(buf);
15615
+ case "base64url":
15616
+ return this.ToBase64Url(buf);
15617
+ case "utf16le":
15618
+ return Utf16Converter.toString(buf, true);
15619
+ case "utf16":
15620
+ case "utf16be":
15621
+ return Utf16Converter.toString(buf);
15622
+ default:
15623
+ throw new Error(`Unknown type of encoding '${enc}'`);
15624
+ }
15625
+ }
15626
+ static FromString(str, enc = "utf8") {
15627
+ if (!str) {
15628
+ return new ArrayBuffer(0);
15629
+ }
15630
+ switch (enc.toLowerCase()) {
15631
+ case "utf8":
15632
+ return this.FromUtf8String(str);
15633
+ case "binary":
15634
+ return this.FromBinary(str);
15635
+ case "hex":
15636
+ return this.FromHex(str);
15637
+ case "base64":
15638
+ return this.FromBase64(str);
15639
+ case "base64url":
15640
+ return this.FromBase64Url(str);
15641
+ case "utf16le":
15642
+ return Utf16Converter.fromString(str, true);
15643
+ case "utf16":
15644
+ case "utf16be":
15645
+ return Utf16Converter.fromString(str);
15646
+ default:
15647
+ throw new Error(`Unknown type of encoding '${enc}'`);
15648
+ }
15649
+ }
15650
+ static ToBase64(buffer) {
15651
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15652
+ if (typeof btoa !== "undefined") {
15653
+ const binary = this.ToString(buf, "binary");
15654
+ return btoa(binary);
15655
+ }
15656
+ else {
15657
+ return Buffer.from(buf).toString("base64");
15658
+ }
15659
+ }
15660
+ static FromBase64(base64) {
15661
+ const formatted = this.formatString(base64);
15662
+ if (!formatted) {
15663
+ return new ArrayBuffer(0);
15664
+ }
15665
+ if (!Convert.isBase64(formatted)) {
15666
+ throw new TypeError("Argument 'base64Text' is not Base64 encoded");
15667
+ }
15668
+ if (typeof atob !== "undefined") {
15669
+ return this.FromBinary(atob(formatted));
15670
+ }
15671
+ else {
15672
+ return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
15673
+ }
15674
+ }
15675
+ static FromBase64Url(base64url) {
15676
+ const formatted = this.formatString(base64url);
15677
+ if (!formatted) {
15678
+ return new ArrayBuffer(0);
15679
+ }
15680
+ if (!Convert.isBase64Url(formatted)) {
15681
+ throw new TypeError("Argument 'base64url' is not Base64Url encoded");
15682
+ }
15683
+ return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
15684
+ }
15685
+ static ToBase64Url(data) {
15686
+ return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
15687
+ }
15688
+ static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15689
+ switch (encoding) {
15690
+ case "ascii":
15691
+ return this.FromBinary(text);
15692
+ case "utf8":
15693
+ return Utf8Converter.fromString(text);
15694
+ case "utf16":
15695
+ case "utf16be":
15696
+ return Utf16Converter.fromString(text);
15697
+ case "utf16le":
15698
+ case "usc2":
15699
+ return Utf16Converter.fromString(text, true);
15700
+ default:
15701
+ throw new Error(`Unknown type of encoding '${encoding}'`);
15702
+ }
15703
+ }
15704
+ static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
15705
+ switch (encoding) {
15706
+ case "ascii":
15707
+ return this.ToBinary(buffer);
15708
+ case "utf8":
15709
+ return Utf8Converter.toString(buffer);
15710
+ case "utf16":
15711
+ case "utf16be":
15712
+ return Utf16Converter.toString(buffer);
15713
+ case "utf16le":
15714
+ case "usc2":
15715
+ return Utf16Converter.toString(buffer, true);
15716
+ default:
15717
+ throw new Error(`Unknown type of encoding '${encoding}'`);
15718
+ }
15719
+ }
15720
+ static FromBinary(text) {
15721
+ const stringLength = text.length;
15722
+ const resultView = new Uint8Array(stringLength);
15723
+ for (let i = 0; i < stringLength; i++) {
15724
+ resultView[i] = text.charCodeAt(i);
15725
+ }
15726
+ return resultView.buffer;
15727
+ }
15728
+ static ToBinary(buffer) {
15729
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15730
+ let res = "";
15731
+ for (let i = 0; i < buf.length; i++) {
15732
+ res += String.fromCharCode(buf[i]);
15733
+ }
15734
+ return res;
15735
+ }
15736
+ static ToHex(buffer) {
15737
+ const buf = BufferSourceConverter.toUint8Array(buffer);
15738
+ let result = "";
15739
+ const len = buf.length;
15740
+ for (let i = 0; i < len; i++) {
15741
+ const byte = buf[i];
15742
+ if (byte < 16) {
15743
+ result += "0";
15744
+ }
15745
+ result += byte.toString(16);
15746
+ }
15747
+ return result;
15748
+ }
15749
+ static FromHex(hexString) {
15750
+ let formatted = this.formatString(hexString);
15751
+ if (!formatted) {
15752
+ return new ArrayBuffer(0);
15753
+ }
15754
+ if (!Convert.isHex(formatted)) {
15755
+ throw new TypeError("Argument 'hexString' is not HEX encoded");
15756
+ }
15757
+ if (formatted.length % 2) {
15758
+ formatted = `0${formatted}`;
15759
+ }
15760
+ const res = new Uint8Array(formatted.length / 2);
15761
+ for (let i = 0; i < formatted.length; i = i + 2) {
15762
+ const c = formatted.slice(i, i + 2);
15763
+ res[i / 2] = parseInt(c, 16);
15764
+ }
15765
+ return res.buffer;
15766
+ }
15767
+ static ToUtf16String(buffer, littleEndian = false) {
15768
+ return Utf16Converter.toString(buffer, littleEndian);
15769
+ }
15770
+ static FromUtf16String(text, littleEndian = false) {
15771
+ return Utf16Converter.fromString(text, littleEndian);
15772
+ }
15773
+ static Base64Padding(base64) {
15774
+ const padCount = 4 - (base64.length % 4);
15775
+ if (padCount < 4) {
15776
+ for (let i = 0; i < padCount; i++) {
15777
+ base64 += "=";
15778
+ }
15779
+ }
15780
+ return base64;
15781
+ }
15782
+ static formatString(data) {
15783
+ return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
15784
+ }
15785
+ }
15766
15786
  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;
15787
+ function combine(...buf) {
15788
+ const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur);
15789
+ const res = new Uint8Array(totalByteLength);
15790
+ let currentPos = 0;
15791
+ buf.map((item) => new Uint8Array(item)).forEach((arr) => {
15792
+ for (const item2 of arr) {
15793
+ res[currentPos++] = item2;
15794
+ }
15795
+ });
15796
+ return res.buffer;
15777
15797
  }
15778
15798
 
15779
15799
  /*!
@@ -24021,15 +24041,31 @@ class Crypto extends Crypto$1 {
24021
24041
  if (typeof window === 'undefined') {
24022
24042
  global.crypto = new Crypto();
24023
24043
  }
24044
+ /**
24045
+ * Obol sdk Client can be used for creating, managing and activating distributed validators.
24046
+ */
24024
24047
  class Client extends Base {
24048
+ /**
24049
+ * @param config
24050
+ * @param signer ethersJS Signer
24051
+ * @returns Obol-SDK Client instance
24052
+ *
24053
+ * An example of how to instantiate obol-sdk Client:
24054
+ * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
24055
+ */
24025
24056
  constructor(config, signer) {
24026
24057
  super(config);
24027
24058
  this.signer = signer;
24028
24059
  }
24029
24060
  /**
24030
- * @param cluster The new unique cluster
24031
- * @returns Invite Link with config_hash
24032
- */
24061
+ * Creates a cluster definition which contains cluster configuration.
24062
+ * @param {ClusterPayload} newCluster - The new unique cluster.
24063
+ * @returns {Promise<string>} config_hash.
24064
+ * @throws On duplicate entries, missing or wrong cluster keys.
24065
+ *
24066
+ * An example of how to use createClusterDefinition:
24067
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L45)
24068
+ */
24033
24069
  async createClusterDefinition(newCluster) {
24034
24070
  const isValid = validateDefinition(newCluster);
24035
24071
  if (isValid !== null)
@@ -24058,8 +24094,12 @@ class Client extends Base {
24058
24094
  }
24059
24095
  /**
24060
24096
  * @param configHash The config hash of the requested cluster
24061
- * @returns The matched cluster details (lock) from DB
24062
- */
24097
+ * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
24098
+ * @throws On not found cluster definition or lock.
24099
+ *
24100
+ * An example of how to use getClusterLock:
24101
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L61)
24102
+ */
24063
24103
  async getClusterLock(configHash) {
24064
24104
  const lock = await this.request(`/lock/configHash/${configHash}`, {
24065
24105
  method: 'GET',