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