@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.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.
|
|
92
|
-
const SDK_VERSION = "1.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 =
|
|
7961
|
-
const val =
|
|
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
|
|
7965
|
-
const definitionType =
|
|
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
|
|
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
|
-
|
|
15472
|
-
|
|
15473
|
-
|
|
15474
|
-
return this.
|
|
15475
|
-
|
|
15476
|
-
|
|
15477
|
-
|
|
15478
|
-
|
|
15479
|
-
|
|
15480
|
-
|
|
15481
|
-
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15489
|
-
|
|
15490
|
-
|
|
15491
|
-
|
|
15492
|
-
|
|
15493
|
-
|
|
15494
|
-
|
|
15495
|
-
|
|
15496
|
-
|
|
15497
|
-
|
|
15498
|
-
|
|
15499
|
-
|
|
15500
|
-
|
|
15501
|
-
|
|
15502
|
-
|
|
15503
|
-
|
|
15504
|
-
|
|
15505
|
-
|
|
15506
|
-
}
|
|
15507
|
-
|
|
15508
|
-
|
|
15509
|
-
|
|
15510
|
-
|
|
15511
|
-
|
|
15512
|
-
|
|
15513
|
-
|
|
15514
|
-
|
|
15515
|
-
|
|
15516
|
-
|
|
15517
|
-
|
|
15518
|
-
|
|
15519
|
-
|
|
15520
|
-
|
|
15521
|
-
|
|
15522
|
-
|
|
15523
|
-
if (args[1]) {
|
|
15524
|
-
|
|
15525
|
-
}
|
|
15526
|
-
|
|
15527
|
-
|
|
15528
|
-
|
|
15529
|
-
|
|
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
|
-
|
|
15535
|
-
|
|
15536
|
-
|
|
15537
|
-
|
|
15538
|
-
|
|
15539
|
-
|
|
15540
|
-
|
|
15541
|
-
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
15546
|
-
|
|
15547
|
-
|
|
15548
|
-
|
|
15549
|
-
|
|
15550
|
-
|
|
15551
|
-
|
|
15552
|
-
}
|
|
15553
|
-
|
|
15554
|
-
|
|
15555
|
-
|
|
15556
|
-
|
|
15557
|
-
|
|
15558
|
-
|
|
15559
|
-
|
|
15560
|
-
|
|
15561
|
-
|
|
15562
|
-
|
|
15563
|
-
|
|
15564
|
-
|
|
15565
|
-
|
|
15566
|
-
|
|
15567
|
-
|
|
15568
|
-
|
|
15569
|
-
|
|
15570
|
-
|
|
15571
|
-
|
|
15572
|
-
|
|
15573
|
-
|
|
15574
|
-
|
|
15575
|
-
|
|
15576
|
-
|
|
15577
|
-
|
|
15578
|
-
static
|
|
15579
|
-
return typeof data ===
|
|
15580
|
-
&&
|
|
15581
|
-
}
|
|
15582
|
-
static
|
|
15583
|
-
return typeof data ===
|
|
15584
|
-
&&
|
|
15585
|
-
}
|
|
15586
|
-
static
|
|
15587
|
-
|
|
15588
|
-
|
|
15589
|
-
|
|
15590
|
-
|
|
15591
|
-
|
|
15592
|
-
|
|
15593
|
-
case "
|
|
15594
|
-
return this.
|
|
15595
|
-
case "
|
|
15596
|
-
return this.
|
|
15597
|
-
case "
|
|
15598
|
-
return this.
|
|
15599
|
-
case "
|
|
15600
|
-
return
|
|
15601
|
-
case "
|
|
15602
|
-
|
|
15603
|
-
|
|
15604
|
-
|
|
15605
|
-
|
|
15606
|
-
|
|
15607
|
-
|
|
15608
|
-
|
|
15609
|
-
|
|
15610
|
-
|
|
15611
|
-
|
|
15612
|
-
|
|
15613
|
-
|
|
15614
|
-
|
|
15615
|
-
|
|
15616
|
-
|
|
15617
|
-
case "
|
|
15618
|
-
return this.
|
|
15619
|
-
case "
|
|
15620
|
-
return this.
|
|
15621
|
-
case "
|
|
15622
|
-
return this.
|
|
15623
|
-
case "
|
|
15624
|
-
return
|
|
15625
|
-
case "
|
|
15626
|
-
|
|
15627
|
-
|
|
15628
|
-
|
|
15629
|
-
|
|
15630
|
-
|
|
15631
|
-
|
|
15632
|
-
|
|
15633
|
-
|
|
15634
|
-
|
|
15635
|
-
|
|
15636
|
-
|
|
15637
|
-
|
|
15638
|
-
|
|
15639
|
-
|
|
15640
|
-
|
|
15641
|
-
|
|
15642
|
-
|
|
15643
|
-
|
|
15644
|
-
|
|
15645
|
-
|
|
15646
|
-
|
|
15647
|
-
|
|
15648
|
-
|
|
15649
|
-
|
|
15650
|
-
|
|
15651
|
-
|
|
15652
|
-
|
|
15653
|
-
|
|
15654
|
-
|
|
15655
|
-
|
|
15656
|
-
|
|
15657
|
-
|
|
15658
|
-
|
|
15659
|
-
|
|
15660
|
-
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
|
|
15665
|
-
|
|
15666
|
-
|
|
15667
|
-
|
|
15668
|
-
|
|
15669
|
-
|
|
15670
|
-
|
|
15671
|
-
|
|
15672
|
-
|
|
15673
|
-
|
|
15674
|
-
|
|
15675
|
-
|
|
15676
|
-
case "
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
case "
|
|
15681
|
-
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
|
|
15686
|
-
|
|
15687
|
-
|
|
15688
|
-
|
|
15689
|
-
|
|
15690
|
-
|
|
15691
|
-
|
|
15692
|
-
case "
|
|
15693
|
-
|
|
15694
|
-
|
|
15695
|
-
|
|
15696
|
-
case "
|
|
15697
|
-
|
|
15698
|
-
|
|
15699
|
-
|
|
15700
|
-
|
|
15701
|
-
|
|
15702
|
-
|
|
15703
|
-
|
|
15704
|
-
|
|
15705
|
-
|
|
15706
|
-
|
|
15707
|
-
|
|
15708
|
-
|
|
15709
|
-
|
|
15710
|
-
|
|
15711
|
-
|
|
15712
|
-
|
|
15713
|
-
|
|
15714
|
-
|
|
15715
|
-
|
|
15716
|
-
|
|
15717
|
-
|
|
15718
|
-
|
|
15719
|
-
|
|
15720
|
-
|
|
15721
|
-
|
|
15722
|
-
|
|
15723
|
-
|
|
15724
|
-
|
|
15725
|
-
|
|
15726
|
-
|
|
15727
|
-
|
|
15728
|
-
|
|
15729
|
-
|
|
15730
|
-
|
|
15731
|
-
|
|
15732
|
-
|
|
15733
|
-
|
|
15734
|
-
|
|
15735
|
-
|
|
15736
|
-
|
|
15737
|
-
if (formatted
|
|
15738
|
-
|
|
15739
|
-
}
|
|
15740
|
-
|
|
15741
|
-
|
|
15742
|
-
|
|
15743
|
-
|
|
15744
|
-
|
|
15745
|
-
|
|
15746
|
-
|
|
15747
|
-
|
|
15748
|
-
|
|
15749
|
-
|
|
15750
|
-
|
|
15751
|
-
return
|
|
15752
|
-
}
|
|
15753
|
-
static
|
|
15754
|
-
|
|
15755
|
-
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
|
|
15759
|
-
|
|
15760
|
-
|
|
15761
|
-
|
|
15762
|
-
|
|
15763
|
-
|
|
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
|
-
*
|
|
24031
|
-
* @
|
|
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',
|