@obolnetwork/obol-sdk 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +35 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +392 -346
- package/dist/index.js +392 -346
- package/dist/types.d.ts +97 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
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
|
|
|
@@ -388,14 +388,7 @@ function output(out, instance) {
|
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
_assert.output = output;
|
|
391
|
-
const assert = {
|
|
392
|
-
number,
|
|
393
|
-
bool,
|
|
394
|
-
bytes,
|
|
395
|
-
hash,
|
|
396
|
-
exists,
|
|
397
|
-
output,
|
|
398
|
-
};
|
|
391
|
+
const assert = { number, bool, bytes, hash, exists, output };
|
|
399
392
|
_assert.default = assert;
|
|
400
393
|
|
|
401
394
|
var utils = {};
|
|
@@ -434,7 +427,7 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
|
|
|
434
427
|
exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
|
435
428
|
if (!exports.isLE)
|
|
436
429
|
throw new Error('Non little-endian hardware is not supported');
|
|
437
|
-
const hexes = Array.from({ length: 256 }, (
|
|
430
|
+
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
|
|
438
431
|
/**
|
|
439
432
|
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
440
433
|
*/
|
|
@@ -534,10 +527,9 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
|
|
|
534
527
|
}
|
|
535
528
|
}
|
|
536
529
|
exports.Hash = Hash;
|
|
537
|
-
|
|
538
|
-
const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
|
|
530
|
+
const toStr = {}.toString;
|
|
539
531
|
function checkOpts(defaults, opts) {
|
|
540
|
-
if (opts !== undefined && (
|
|
532
|
+
if (opts !== undefined && toStr.call(opts) !== '[object Object]')
|
|
541
533
|
throw new Error('Options should be object or undefined');
|
|
542
534
|
const merged = Object.assign(defaults, opts);
|
|
543
535
|
return merged;
|
|
@@ -616,7 +608,7 @@ class SHA2 extends utils_js_1$1.Hash {
|
|
|
616
608
|
this.view = (0, utils_js_1$1.createView)(this.buffer);
|
|
617
609
|
}
|
|
618
610
|
update(data) {
|
|
619
|
-
_assert_js_1.
|
|
611
|
+
(0, _assert_js_1.exists)(this);
|
|
620
612
|
const { view, buffer, blockLen } = this;
|
|
621
613
|
data = (0, utils_js_1$1.toBytes)(data);
|
|
622
614
|
const len = data.length;
|
|
@@ -642,8 +634,8 @@ class SHA2 extends utils_js_1$1.Hash {
|
|
|
642
634
|
return this;
|
|
643
635
|
}
|
|
644
636
|
digestInto(out) {
|
|
645
|
-
_assert_js_1.
|
|
646
|
-
_assert_js_1.
|
|
637
|
+
(0, _assert_js_1.exists)(this);
|
|
638
|
+
(0, _assert_js_1.output)(out, this);
|
|
647
639
|
this.finished = true;
|
|
648
640
|
// Padding
|
|
649
641
|
// We can avoid allocation of buffer for padding completely if it
|
|
@@ -704,6 +696,8 @@ Object.defineProperty(sha256, "__esModule", { value: true });
|
|
|
704
696
|
sha256.sha224 = sha256.sha256 = void 0;
|
|
705
697
|
const _sha2_js_1 = _sha2;
|
|
706
698
|
const utils_js_1 = utils;
|
|
699
|
+
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
|
|
700
|
+
// BTC network is doing 2^67 hashes/sec as per early 2023.
|
|
707
701
|
// Choice: a ? b : c
|
|
708
702
|
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
|
709
703
|
// Majority function, true if any two inpust is true
|
|
@@ -711,7 +705,7 @@ const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
|
711
705
|
// Round constants:
|
|
712
706
|
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
|
713
707
|
// prettier-ignore
|
|
714
|
-
const SHA256_K = new Uint32Array([
|
|
708
|
+
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
715
709
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
716
710
|
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
717
711
|
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
@@ -723,12 +717,12 @@ const SHA256_K = new Uint32Array([
|
|
|
723
717
|
]);
|
|
724
718
|
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
|
725
719
|
// prettier-ignore
|
|
726
|
-
const IV = new Uint32Array([
|
|
720
|
+
const IV = /* @__PURE__ */ new Uint32Array([
|
|
727
721
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
728
722
|
]);
|
|
729
723
|
// Temporary buffer, not used to store anything between runs
|
|
730
724
|
// Named this way because it matches specification.
|
|
731
|
-
const SHA256_W = new Uint32Array(64);
|
|
725
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
732
726
|
class SHA256 extends _sha2_js_1.SHA2 {
|
|
733
727
|
constructor() {
|
|
734
728
|
super(64, 32, 8, false);
|
|
@@ -7984,12 +7978,12 @@ vectorComposite.VectorCompositeType = VectorCompositeType;
|
|
|
7984
7978
|
* @returns The config hash or he definition hash in of the corresponding cluster definition
|
|
7985
7979
|
*/
|
|
7986
7980
|
const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
|
|
7987
|
-
const definitionType =
|
|
7988
|
-
const val =
|
|
7981
|
+
const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
|
|
7982
|
+
const val = hashClusterDefinitionV1X7(cluster, configOnly);
|
|
7989
7983
|
return ('0x' + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
|
|
7990
7984
|
};
|
|
7991
|
-
const
|
|
7992
|
-
const definitionType =
|
|
7985
|
+
const hashClusterDefinitionV1X7 = (cluster, configOnly) => {
|
|
7986
|
+
const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
|
|
7993
7987
|
const val = definitionType.defaultValue();
|
|
7994
7988
|
//order should be same as charon https://github.com/ObolNetwork/charon/blob/d00b31e6465a260a43ce40f15c47fb5a5b009042/cluster/ssz.go#L285
|
|
7995
7989
|
val.uuid = strToUint8Array(cluster.uuid);
|
|
@@ -8070,7 +8064,7 @@ const newOperatorContainerType = (configOnly) => {
|
|
|
8070
8064
|
* @param cluster ClusterDefinition to calculate the type from
|
|
8071
8065
|
* @returns SSZ Containerized type of cluster input
|
|
8072
8066
|
*/
|
|
8073
|
-
const
|
|
8067
|
+
const clusterDefinitionContainerTypeV1X7 = (configOnly) => {
|
|
8074
8068
|
let returnedContainerType = {
|
|
8075
8069
|
uuid: new lib$1.ByteListType(64),
|
|
8076
8070
|
name: new lib$1.ByteListType(256),
|
|
@@ -15483,324 +15477,344 @@ function validateDefinition(data) {
|
|
|
15483
15477
|
*
|
|
15484
15478
|
*/
|
|
15485
15479
|
|
|
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
|
-
|
|
15480
|
+
const ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
|
|
15481
|
+
class BufferSourceConverter {
|
|
15482
|
+
static isArrayBuffer(data) {
|
|
15483
|
+
return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
|
|
15484
|
+
}
|
|
15485
|
+
static toArrayBuffer(data) {
|
|
15486
|
+
if (this.isArrayBuffer(data)) {
|
|
15487
|
+
return data;
|
|
15488
|
+
}
|
|
15489
|
+
if (data.byteLength === data.buffer.byteLength) {
|
|
15490
|
+
return data.buffer;
|
|
15491
|
+
}
|
|
15492
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
15493
|
+
return data.buffer;
|
|
15494
|
+
}
|
|
15495
|
+
return this.toUint8Array(data.buffer)
|
|
15496
|
+
.slice(data.byteOffset, data.byteOffset + data.byteLength)
|
|
15497
|
+
.buffer;
|
|
15498
|
+
}
|
|
15499
|
+
static toUint8Array(data) {
|
|
15500
|
+
return this.toView(data, Uint8Array);
|
|
15501
|
+
}
|
|
15502
|
+
static toView(data, type) {
|
|
15503
|
+
if (data.constructor === type) {
|
|
15504
|
+
return data;
|
|
15505
|
+
}
|
|
15506
|
+
if (this.isArrayBuffer(data)) {
|
|
15507
|
+
return new type(data);
|
|
15508
|
+
}
|
|
15509
|
+
if (this.isArrayBufferView(data)) {
|
|
15510
|
+
return new type(data.buffer, data.byteOffset, data.byteLength);
|
|
15511
|
+
}
|
|
15512
|
+
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
|
|
15513
|
+
}
|
|
15514
|
+
static isBufferSource(data) {
|
|
15515
|
+
return this.isArrayBufferView(data)
|
|
15516
|
+
|| this.isArrayBuffer(data);
|
|
15517
|
+
}
|
|
15518
|
+
static isArrayBufferView(data) {
|
|
15519
|
+
return ArrayBuffer.isView(data)
|
|
15520
|
+
|| (data && this.isArrayBuffer(data.buffer));
|
|
15521
|
+
}
|
|
15522
|
+
static isEqual(a, b) {
|
|
15523
|
+
const aView = BufferSourceConverter.toUint8Array(a);
|
|
15524
|
+
const bView = BufferSourceConverter.toUint8Array(b);
|
|
15525
|
+
if (aView.length !== bView.byteLength) {
|
|
15526
|
+
return false;
|
|
15527
|
+
}
|
|
15528
|
+
for (let i = 0; i < aView.length; i++) {
|
|
15529
|
+
if (aView[i] !== bView[i]) {
|
|
15530
|
+
return false;
|
|
15531
|
+
}
|
|
15532
|
+
}
|
|
15533
|
+
return true;
|
|
15534
|
+
}
|
|
15535
|
+
static concat(...args) {
|
|
15536
|
+
let buffers;
|
|
15537
|
+
if (Array.isArray(args[0]) && !(args[1] instanceof Function)) {
|
|
15538
|
+
buffers = args[0];
|
|
15539
|
+
}
|
|
15540
|
+
else if (Array.isArray(args[0]) && args[1] instanceof Function) {
|
|
15541
|
+
buffers = args[0];
|
|
15542
|
+
}
|
|
15543
|
+
else {
|
|
15544
|
+
if (args[args.length - 1] instanceof Function) {
|
|
15545
|
+
buffers = args.slice(0, args.length - 1);
|
|
15546
|
+
}
|
|
15547
|
+
else {
|
|
15548
|
+
buffers = args;
|
|
15549
|
+
}
|
|
15550
|
+
}
|
|
15551
|
+
let size = 0;
|
|
15552
|
+
for (const buffer of buffers) {
|
|
15553
|
+
size += buffer.byteLength;
|
|
15554
|
+
}
|
|
15555
|
+
const res = new Uint8Array(size);
|
|
15556
|
+
let offset = 0;
|
|
15557
|
+
for (const buffer of buffers) {
|
|
15558
|
+
const view = this.toUint8Array(buffer);
|
|
15559
|
+
res.set(view, offset);
|
|
15560
|
+
offset += view.length;
|
|
15561
|
+
}
|
|
15562
|
+
if (args[args.length - 1] instanceof Function) {
|
|
15563
|
+
return this.toView(res, args[args.length - 1]);
|
|
15564
|
+
}
|
|
15565
|
+
return res.buffer;
|
|
15566
|
+
}
|
|
15559
15567
|
}
|
|
15560
15568
|
|
|
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
|
-
}
|
|
15569
|
+
const STRING_TYPE = "string";
|
|
15570
|
+
const HEX_REGEX = /^[0-9a-f]+$/i;
|
|
15571
|
+
const BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
15572
|
+
const BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;
|
|
15573
|
+
class Utf8Converter {
|
|
15574
|
+
static fromString(text) {
|
|
15575
|
+
const s = unescape(encodeURIComponent(text));
|
|
15576
|
+
const uintArray = new Uint8Array(s.length);
|
|
15577
|
+
for (let i = 0; i < s.length; i++) {
|
|
15578
|
+
uintArray[i] = s.charCodeAt(i);
|
|
15579
|
+
}
|
|
15580
|
+
return uintArray.buffer;
|
|
15581
|
+
}
|
|
15582
|
+
static toString(buffer) {
|
|
15583
|
+
const buf = BufferSourceConverter.toUint8Array(buffer);
|
|
15584
|
+
let encodedString = "";
|
|
15585
|
+
for (let i = 0; i < buf.length; i++) {
|
|
15586
|
+
encodedString += String.fromCharCode(buf[i]);
|
|
15587
|
+
}
|
|
15588
|
+
const decodedString = decodeURIComponent(escape(encodedString));
|
|
15589
|
+
return decodedString;
|
|
15590
|
+
}
|
|
15591
|
+
}
|
|
15592
|
+
class Utf16Converter {
|
|
15593
|
+
static toString(buffer, littleEndian = false) {
|
|
15594
|
+
const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
|
|
15595
|
+
const dataView = new DataView(arrayBuffer);
|
|
15596
|
+
let res = "";
|
|
15597
|
+
for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
|
|
15598
|
+
const code = dataView.getUint16(i, littleEndian);
|
|
15599
|
+
res += String.fromCharCode(code);
|
|
15600
|
+
}
|
|
15601
|
+
return res;
|
|
15602
|
+
}
|
|
15603
|
+
static fromString(text, littleEndian = false) {
|
|
15604
|
+
const res = new ArrayBuffer(text.length * 2);
|
|
15605
|
+
const dataView = new DataView(res);
|
|
15606
|
+
for (let i = 0; i < text.length; i++) {
|
|
15607
|
+
dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
|
|
15608
|
+
}
|
|
15609
|
+
return res;
|
|
15610
|
+
}
|
|
15611
|
+
}
|
|
15612
|
+
class Convert {
|
|
15613
|
+
static isHex(data) {
|
|
15614
|
+
return typeof data === STRING_TYPE
|
|
15615
|
+
&& HEX_REGEX.test(data);
|
|
15616
|
+
}
|
|
15617
|
+
static isBase64(data) {
|
|
15618
|
+
return typeof data === STRING_TYPE
|
|
15619
|
+
&& BASE64_REGEX.test(data);
|
|
15620
|
+
}
|
|
15621
|
+
static isBase64Url(data) {
|
|
15622
|
+
return typeof data === STRING_TYPE
|
|
15623
|
+
&& BASE64URL_REGEX.test(data);
|
|
15624
|
+
}
|
|
15625
|
+
static ToString(buffer, enc = "utf8") {
|
|
15626
|
+
const buf = BufferSourceConverter.toUint8Array(buffer);
|
|
15627
|
+
switch (enc.toLowerCase()) {
|
|
15628
|
+
case "utf8":
|
|
15629
|
+
return this.ToUtf8String(buf);
|
|
15630
|
+
case "binary":
|
|
15631
|
+
return this.ToBinary(buf);
|
|
15632
|
+
case "hex":
|
|
15633
|
+
return this.ToHex(buf);
|
|
15634
|
+
case "base64":
|
|
15635
|
+
return this.ToBase64(buf);
|
|
15636
|
+
case "base64url":
|
|
15637
|
+
return this.ToBase64Url(buf);
|
|
15638
|
+
case "utf16le":
|
|
15639
|
+
return Utf16Converter.toString(buf, true);
|
|
15640
|
+
case "utf16":
|
|
15641
|
+
case "utf16be":
|
|
15642
|
+
return Utf16Converter.toString(buf);
|
|
15643
|
+
default:
|
|
15644
|
+
throw new Error(`Unknown type of encoding '${enc}'`);
|
|
15645
|
+
}
|
|
15646
|
+
}
|
|
15647
|
+
static FromString(str, enc = "utf8") {
|
|
15648
|
+
if (!str) {
|
|
15649
|
+
return new ArrayBuffer(0);
|
|
15650
|
+
}
|
|
15651
|
+
switch (enc.toLowerCase()) {
|
|
15652
|
+
case "utf8":
|
|
15653
|
+
return this.FromUtf8String(str);
|
|
15654
|
+
case "binary":
|
|
15655
|
+
return this.FromBinary(str);
|
|
15656
|
+
case "hex":
|
|
15657
|
+
return this.FromHex(str);
|
|
15658
|
+
case "base64":
|
|
15659
|
+
return this.FromBase64(str);
|
|
15660
|
+
case "base64url":
|
|
15661
|
+
return this.FromBase64Url(str);
|
|
15662
|
+
case "utf16le":
|
|
15663
|
+
return Utf16Converter.fromString(str, true);
|
|
15664
|
+
case "utf16":
|
|
15665
|
+
case "utf16be":
|
|
15666
|
+
return Utf16Converter.fromString(str);
|
|
15667
|
+
default:
|
|
15668
|
+
throw new Error(`Unknown type of encoding '${enc}'`);
|
|
15669
|
+
}
|
|
15670
|
+
}
|
|
15671
|
+
static ToBase64(buffer) {
|
|
15672
|
+
const buf = BufferSourceConverter.toUint8Array(buffer);
|
|
15673
|
+
if (typeof btoa !== "undefined") {
|
|
15674
|
+
const binary = this.ToString(buf, "binary");
|
|
15675
|
+
return btoa(binary);
|
|
15676
|
+
}
|
|
15677
|
+
else {
|
|
15678
|
+
return Buffer.from(buf).toString("base64");
|
|
15679
|
+
}
|
|
15680
|
+
}
|
|
15681
|
+
static FromBase64(base64) {
|
|
15682
|
+
const formatted = this.formatString(base64);
|
|
15683
|
+
if (!formatted) {
|
|
15684
|
+
return new ArrayBuffer(0);
|
|
15685
|
+
}
|
|
15686
|
+
if (!Convert.isBase64(formatted)) {
|
|
15687
|
+
throw new TypeError("Argument 'base64Text' is not Base64 encoded");
|
|
15688
|
+
}
|
|
15689
|
+
if (typeof atob !== "undefined") {
|
|
15690
|
+
return this.FromBinary(atob(formatted));
|
|
15691
|
+
}
|
|
15692
|
+
else {
|
|
15693
|
+
return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
|
|
15694
|
+
}
|
|
15695
|
+
}
|
|
15696
|
+
static FromBase64Url(base64url) {
|
|
15697
|
+
const formatted = this.formatString(base64url);
|
|
15698
|
+
if (!formatted) {
|
|
15699
|
+
return new ArrayBuffer(0);
|
|
15700
|
+
}
|
|
15701
|
+
if (!Convert.isBase64Url(formatted)) {
|
|
15702
|
+
throw new TypeError("Argument 'base64url' is not Base64Url encoded");
|
|
15703
|
+
}
|
|
15704
|
+
return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
|
|
15705
|
+
}
|
|
15706
|
+
static ToBase64Url(data) {
|
|
15707
|
+
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
|
|
15708
|
+
}
|
|
15709
|
+
static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
|
|
15710
|
+
switch (encoding) {
|
|
15711
|
+
case "ascii":
|
|
15712
|
+
return this.FromBinary(text);
|
|
15713
|
+
case "utf8":
|
|
15714
|
+
return Utf8Converter.fromString(text);
|
|
15715
|
+
case "utf16":
|
|
15716
|
+
case "utf16be":
|
|
15717
|
+
return Utf16Converter.fromString(text);
|
|
15718
|
+
case "utf16le":
|
|
15719
|
+
case "usc2":
|
|
15720
|
+
return Utf16Converter.fromString(text, true);
|
|
15721
|
+
default:
|
|
15722
|
+
throw new Error(`Unknown type of encoding '${encoding}'`);
|
|
15723
|
+
}
|
|
15724
|
+
}
|
|
15725
|
+
static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
|
|
15726
|
+
switch (encoding) {
|
|
15727
|
+
case "ascii":
|
|
15728
|
+
return this.ToBinary(buffer);
|
|
15729
|
+
case "utf8":
|
|
15730
|
+
return Utf8Converter.toString(buffer);
|
|
15731
|
+
case "utf16":
|
|
15732
|
+
case "utf16be":
|
|
15733
|
+
return Utf16Converter.toString(buffer);
|
|
15734
|
+
case "utf16le":
|
|
15735
|
+
case "usc2":
|
|
15736
|
+
return Utf16Converter.toString(buffer, true);
|
|
15737
|
+
default:
|
|
15738
|
+
throw new Error(`Unknown type of encoding '${encoding}'`);
|
|
15739
|
+
}
|
|
15740
|
+
}
|
|
15741
|
+
static FromBinary(text) {
|
|
15742
|
+
const stringLength = text.length;
|
|
15743
|
+
const resultView = new Uint8Array(stringLength);
|
|
15744
|
+
for (let i = 0; i < stringLength; i++) {
|
|
15745
|
+
resultView[i] = text.charCodeAt(i);
|
|
15746
|
+
}
|
|
15747
|
+
return resultView.buffer;
|
|
15748
|
+
}
|
|
15749
|
+
static ToBinary(buffer) {
|
|
15750
|
+
const buf = BufferSourceConverter.toUint8Array(buffer);
|
|
15751
|
+
let res = "";
|
|
15752
|
+
for (let i = 0; i < buf.length; i++) {
|
|
15753
|
+
res += String.fromCharCode(buf[i]);
|
|
15754
|
+
}
|
|
15755
|
+
return res;
|
|
15756
|
+
}
|
|
15757
|
+
static ToHex(buffer) {
|
|
15758
|
+
const buf = BufferSourceConverter.toUint8Array(buffer);
|
|
15759
|
+
let result = "";
|
|
15760
|
+
const len = buf.length;
|
|
15761
|
+
for (let i = 0; i < len; i++) {
|
|
15762
|
+
const byte = buf[i];
|
|
15763
|
+
if (byte < 16) {
|
|
15764
|
+
result += "0";
|
|
15765
|
+
}
|
|
15766
|
+
result += byte.toString(16);
|
|
15767
|
+
}
|
|
15768
|
+
return result;
|
|
15769
|
+
}
|
|
15770
|
+
static FromHex(hexString) {
|
|
15771
|
+
let formatted = this.formatString(hexString);
|
|
15772
|
+
if (!formatted) {
|
|
15773
|
+
return new ArrayBuffer(0);
|
|
15774
|
+
}
|
|
15775
|
+
if (!Convert.isHex(formatted)) {
|
|
15776
|
+
throw new TypeError("Argument 'hexString' is not HEX encoded");
|
|
15777
|
+
}
|
|
15778
|
+
if (formatted.length % 2) {
|
|
15779
|
+
formatted = `0${formatted}`;
|
|
15780
|
+
}
|
|
15781
|
+
const res = new Uint8Array(formatted.length / 2);
|
|
15782
|
+
for (let i = 0; i < formatted.length; i = i + 2) {
|
|
15783
|
+
const c = formatted.slice(i, i + 2);
|
|
15784
|
+
res[i / 2] = parseInt(c, 16);
|
|
15785
|
+
}
|
|
15786
|
+
return res.buffer;
|
|
15787
|
+
}
|
|
15788
|
+
static ToUtf16String(buffer, littleEndian = false) {
|
|
15789
|
+
return Utf16Converter.toString(buffer, littleEndian);
|
|
15790
|
+
}
|
|
15791
|
+
static FromUtf16String(text, littleEndian = false) {
|
|
15792
|
+
return Utf16Converter.fromString(text, littleEndian);
|
|
15793
|
+
}
|
|
15794
|
+
static Base64Padding(base64) {
|
|
15795
|
+
const padCount = 4 - (base64.length % 4);
|
|
15796
|
+
if (padCount < 4) {
|
|
15797
|
+
for (let i = 0; i < padCount; i++) {
|
|
15798
|
+
base64 += "=";
|
|
15799
|
+
}
|
|
15800
|
+
}
|
|
15801
|
+
return base64;
|
|
15802
|
+
}
|
|
15803
|
+
static formatString(data) {
|
|
15804
|
+
return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
|
|
15805
|
+
}
|
|
15806
|
+
}
|
|
15793
15807
|
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;
|
|
15808
|
+
function combine(...buf) {
|
|
15809
|
+
const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur);
|
|
15810
|
+
const res = new Uint8Array(totalByteLength);
|
|
15811
|
+
let currentPos = 0;
|
|
15812
|
+
buf.map((item) => new Uint8Array(item)).forEach((arr) => {
|
|
15813
|
+
for (const item2 of arr) {
|
|
15814
|
+
res[currentPos++] = item2;
|
|
15815
|
+
}
|
|
15816
|
+
});
|
|
15817
|
+
return res.buffer;
|
|
15804
15818
|
}
|
|
15805
15819
|
|
|
15806
15820
|
/*!
|
|
@@ -24048,15 +24062,31 @@ class Crypto extends Crypto$1 {
|
|
|
24048
24062
|
if (typeof window === 'undefined') {
|
|
24049
24063
|
global.crypto = new Crypto();
|
|
24050
24064
|
}
|
|
24065
|
+
/**
|
|
24066
|
+
* Obol sdk Client can be used for creating, managing and activating distributed validators.
|
|
24067
|
+
*/
|
|
24051
24068
|
class Client extends Base {
|
|
24069
|
+
/**
|
|
24070
|
+
* @param config
|
|
24071
|
+
* @param signer ethersJS Signer
|
|
24072
|
+
* @returns Obol-SDK Client instance
|
|
24073
|
+
*
|
|
24074
|
+
* An example of how to instantiate obol-sdk Client:
|
|
24075
|
+
* [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
|
|
24076
|
+
*/
|
|
24052
24077
|
constructor(config, signer) {
|
|
24053
24078
|
super(config);
|
|
24054
24079
|
this.signer = signer;
|
|
24055
24080
|
}
|
|
24056
24081
|
/**
|
|
24057
|
-
*
|
|
24058
|
-
* @
|
|
24059
|
-
|
|
24082
|
+
* Creates a cluster definition which contains cluster configuration.
|
|
24083
|
+
* @param {ClusterPayload} newCluster - The new unique cluster.
|
|
24084
|
+
* @returns {Promise<string>} config_hash.
|
|
24085
|
+
* @throws On duplicate entries, missing or wrong cluster keys.
|
|
24086
|
+
*
|
|
24087
|
+
* An example of how to use createClusterDefinition:
|
|
24088
|
+
* [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
24089
|
+
*/
|
|
24060
24090
|
async createClusterDefinition(newCluster) {
|
|
24061
24091
|
const isValid = validateDefinition(newCluster);
|
|
24062
24092
|
if (isValid !== null)
|
|
@@ -24084,9 +24114,25 @@ class Client extends Base {
|
|
|
24084
24114
|
}
|
|
24085
24115
|
}
|
|
24086
24116
|
/**
|
|
24087
|
-
* @
|
|
24088
|
-
* @
|
|
24089
|
-
|
|
24117
|
+
* @returns {Promise<ClusterDefintion>} The cluster definition for config hash
|
|
24118
|
+
* @throws On not found config hash.
|
|
24119
|
+
*
|
|
24120
|
+
* An example of how to use getClusterDefinition:
|
|
24121
|
+
* [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
24122
|
+
*/
|
|
24123
|
+
async getClusterDefinition(configHash) {
|
|
24124
|
+
const clusterDefinition = await this.request(`/dv/${configHash}`, {
|
|
24125
|
+
method: 'GET',
|
|
24126
|
+
});
|
|
24127
|
+
return clusterDefinition;
|
|
24128
|
+
}
|
|
24129
|
+
/**
|
|
24130
|
+
* @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
|
|
24131
|
+
* @throws On not found cluster definition or lock.
|
|
24132
|
+
*
|
|
24133
|
+
* An example of how to use getClusterLock:
|
|
24134
|
+
* [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
24135
|
+
*/
|
|
24090
24136
|
async getClusterLock(configHash) {
|
|
24091
24137
|
const lock = await this.request(`/lock/configHash/${configHash}`, {
|
|
24092
24138
|
method: 'GET',
|