@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/README.md +1 -1
- package/dist/constants.d.ts +2 -2
- package/dist/fixtures.d.ts +17 -1
- package/dist/fixtures.d.ts.map +1 -1
- package/dist/hash.d.ts +4 -4
- package/dist/hash.d.ts.map +1 -1
- package/dist/index.d.ts +26 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +367 -327
- package/dist/index.js +367 -327
- package/dist/types.d.ts +97 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -1
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.
|
|
119
|
-
const SDK_VERSION = "1.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 =
|
|
7988
|
-
const val =
|
|
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
|
|
7992
|
-
const definitionType =
|
|
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
|
|
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
|
-
|
|
15499
|
-
|
|
15500
|
-
|
|
15501
|
-
return this.
|
|
15502
|
-
|
|
15503
|
-
|
|
15504
|
-
|
|
15505
|
-
|
|
15506
|
-
|
|
15507
|
-
|
|
15508
|
-
|
|
15509
|
-
|
|
15510
|
-
|
|
15511
|
-
|
|
15512
|
-
|
|
15513
|
-
|
|
15514
|
-
|
|
15515
|
-
|
|
15516
|
-
|
|
15517
|
-
|
|
15518
|
-
|
|
15519
|
-
|
|
15520
|
-
|
|
15521
|
-
|
|
15522
|
-
|
|
15523
|
-
|
|
15524
|
-
|
|
15525
|
-
|
|
15526
|
-
|
|
15527
|
-
|
|
15528
|
-
|
|
15529
|
-
|
|
15530
|
-
|
|
15531
|
-
|
|
15532
|
-
|
|
15533
|
-
}
|
|
15534
|
-
|
|
15535
|
-
|
|
15536
|
-
|
|
15537
|
-
|
|
15538
|
-
|
|
15539
|
-
|
|
15540
|
-
|
|
15541
|
-
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
15546
|
-
|
|
15547
|
-
|
|
15548
|
-
|
|
15549
|
-
|
|
15550
|
-
if (args[1]) {
|
|
15551
|
-
|
|
15552
|
-
}
|
|
15553
|
-
|
|
15554
|
-
|
|
15555
|
-
|
|
15556
|
-
|
|
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
|
-
|
|
15562
|
-
|
|
15563
|
-
|
|
15564
|
-
|
|
15565
|
-
|
|
15566
|
-
|
|
15567
|
-
|
|
15568
|
-
|
|
15569
|
-
|
|
15570
|
-
|
|
15571
|
-
|
|
15572
|
-
|
|
15573
|
-
|
|
15574
|
-
|
|
15575
|
-
|
|
15576
|
-
|
|
15577
|
-
|
|
15578
|
-
|
|
15579
|
-
}
|
|
15580
|
-
|
|
15581
|
-
|
|
15582
|
-
|
|
15583
|
-
|
|
15584
|
-
|
|
15585
|
-
|
|
15586
|
-
|
|
15587
|
-
|
|
15588
|
-
|
|
15589
|
-
|
|
15590
|
-
|
|
15591
|
-
|
|
15592
|
-
|
|
15593
|
-
|
|
15594
|
-
|
|
15595
|
-
|
|
15596
|
-
|
|
15597
|
-
|
|
15598
|
-
|
|
15599
|
-
|
|
15600
|
-
|
|
15601
|
-
|
|
15602
|
-
|
|
15603
|
-
|
|
15604
|
-
|
|
15605
|
-
static
|
|
15606
|
-
return typeof data ===
|
|
15607
|
-
&&
|
|
15608
|
-
}
|
|
15609
|
-
static
|
|
15610
|
-
return typeof data ===
|
|
15611
|
-
&&
|
|
15612
|
-
}
|
|
15613
|
-
static
|
|
15614
|
-
|
|
15615
|
-
|
|
15616
|
-
|
|
15617
|
-
|
|
15618
|
-
|
|
15619
|
-
|
|
15620
|
-
case "
|
|
15621
|
-
return this.
|
|
15622
|
-
case "
|
|
15623
|
-
return this.
|
|
15624
|
-
case "
|
|
15625
|
-
return this.
|
|
15626
|
-
case "
|
|
15627
|
-
return
|
|
15628
|
-
case "
|
|
15629
|
-
|
|
15630
|
-
|
|
15631
|
-
|
|
15632
|
-
|
|
15633
|
-
|
|
15634
|
-
|
|
15635
|
-
|
|
15636
|
-
|
|
15637
|
-
|
|
15638
|
-
|
|
15639
|
-
|
|
15640
|
-
|
|
15641
|
-
|
|
15642
|
-
|
|
15643
|
-
|
|
15644
|
-
case "
|
|
15645
|
-
return this.
|
|
15646
|
-
case "
|
|
15647
|
-
return this.
|
|
15648
|
-
case "
|
|
15649
|
-
return this.
|
|
15650
|
-
case "
|
|
15651
|
-
return
|
|
15652
|
-
case "
|
|
15653
|
-
|
|
15654
|
-
|
|
15655
|
-
|
|
15656
|
-
|
|
15657
|
-
|
|
15658
|
-
|
|
15659
|
-
|
|
15660
|
-
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
|
|
15665
|
-
|
|
15666
|
-
|
|
15667
|
-
|
|
15668
|
-
|
|
15669
|
-
|
|
15670
|
-
|
|
15671
|
-
|
|
15672
|
-
|
|
15673
|
-
|
|
15674
|
-
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
|
|
15681
|
-
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
|
|
15686
|
-
|
|
15687
|
-
|
|
15688
|
-
|
|
15689
|
-
|
|
15690
|
-
|
|
15691
|
-
|
|
15692
|
-
|
|
15693
|
-
|
|
15694
|
-
|
|
15695
|
-
|
|
15696
|
-
|
|
15697
|
-
|
|
15698
|
-
|
|
15699
|
-
|
|
15700
|
-
|
|
15701
|
-
|
|
15702
|
-
|
|
15703
|
-
case "
|
|
15704
|
-
|
|
15705
|
-
|
|
15706
|
-
|
|
15707
|
-
case "
|
|
15708
|
-
|
|
15709
|
-
|
|
15710
|
-
|
|
15711
|
-
|
|
15712
|
-
|
|
15713
|
-
|
|
15714
|
-
|
|
15715
|
-
|
|
15716
|
-
|
|
15717
|
-
|
|
15718
|
-
|
|
15719
|
-
case "
|
|
15720
|
-
|
|
15721
|
-
|
|
15722
|
-
|
|
15723
|
-
case "
|
|
15724
|
-
|
|
15725
|
-
|
|
15726
|
-
|
|
15727
|
-
|
|
15728
|
-
|
|
15729
|
-
|
|
15730
|
-
|
|
15731
|
-
|
|
15732
|
-
|
|
15733
|
-
|
|
15734
|
-
|
|
15735
|
-
|
|
15736
|
-
|
|
15737
|
-
|
|
15738
|
-
|
|
15739
|
-
|
|
15740
|
-
|
|
15741
|
-
|
|
15742
|
-
|
|
15743
|
-
|
|
15744
|
-
|
|
15745
|
-
|
|
15746
|
-
|
|
15747
|
-
|
|
15748
|
-
|
|
15749
|
-
|
|
15750
|
-
|
|
15751
|
-
|
|
15752
|
-
|
|
15753
|
-
|
|
15754
|
-
|
|
15755
|
-
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
|
|
15759
|
-
|
|
15760
|
-
|
|
15761
|
-
|
|
15762
|
-
|
|
15763
|
-
|
|
15764
|
-
if (formatted
|
|
15765
|
-
|
|
15766
|
-
}
|
|
15767
|
-
|
|
15768
|
-
|
|
15769
|
-
|
|
15770
|
-
|
|
15771
|
-
|
|
15772
|
-
|
|
15773
|
-
|
|
15774
|
-
|
|
15775
|
-
|
|
15776
|
-
|
|
15777
|
-
|
|
15778
|
-
return
|
|
15779
|
-
}
|
|
15780
|
-
static
|
|
15781
|
-
|
|
15782
|
-
|
|
15783
|
-
|
|
15784
|
-
|
|
15785
|
-
|
|
15786
|
-
|
|
15787
|
-
|
|
15788
|
-
|
|
15789
|
-
|
|
15790
|
-
|
|
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
|
-
*
|
|
24058
|
-
* @
|
|
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',
|