@obolnetwork/obol-sdk 1.0.5 → 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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Signer } from 'ethers';
2
2
  import { Base } from './base';
3
- import { ClusterLock, ClusterPayload } from './types';
3
+ import { ClusterDefintion, ClusterLock, ClusterPayload } from './types';
4
4
  export * from "./types";
5
5
  /**
6
6
  * Obol sdk Client can be used for creating, managing and activating distributed validators.
@@ -26,16 +26,23 @@ export declare class Client extends Base {
26
26
  * @throws On duplicate entries, missing or wrong cluster keys.
27
27
  *
28
28
  * An example of how to use createClusterDefinition:
29
- * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L45)
29
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
30
30
  */
31
31
  createClusterDefinition(newCluster: ClusterPayload): Promise<string>;
32
32
  /**
33
- * @param configHash The config hash of the requested cluster
33
+ * @returns {Promise<ClusterDefintion>} The cluster definition for config hash
34
+ * @throws On not found config hash.
35
+ *
36
+ * An example of how to use getClusterDefinition:
37
+ * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
38
+ */
39
+ getClusterDefinition(configHash: string): Promise<ClusterDefintion>;
40
+ /**
34
41
  * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
35
42
  * @throws On not found cluster definition or lock.
36
43
  *
37
44
  * An example of how to use getClusterLock:
38
- * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L61)
45
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
39
46
  */
40
47
  getClusterLock(configHash: string): Promise<ClusterLock>;
41
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.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C1E;;;;;;OAMG;IACG,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IASzE;;;;;;OAMG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAQ/D"}
package/dist/index.es.js CHANGED
@@ -361,14 +361,7 @@ function output(out, instance) {
361
361
  }
362
362
  }
363
363
  _assert.output = output;
364
- const assert = {
365
- number,
366
- bool,
367
- bytes,
368
- hash,
369
- exists,
370
- output,
371
- };
364
+ const assert = { number, bool, bytes, hash, exists, output };
372
365
  _assert.default = assert;
373
366
 
374
367
  var utils = {};
@@ -407,7 +400,7 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
407
400
  exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
408
401
  if (!exports.isLE)
409
402
  throw new Error('Non little-endian hardware is not supported');
410
- const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
403
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
411
404
  /**
412
405
  * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
413
406
  */
@@ -507,10 +500,9 @@ crypto$1.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? glo
507
500
  }
508
501
  }
509
502
  exports.Hash = Hash;
510
- // Check if object doens't have custom constructor (like Uint8Array/Array)
511
- const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
503
+ const toStr = {}.toString;
512
504
  function checkOpts(defaults, opts) {
513
- if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
505
+ if (opts !== undefined && toStr.call(opts) !== '[object Object]')
514
506
  throw new Error('Options should be object or undefined');
515
507
  const merged = Object.assign(defaults, opts);
516
508
  return merged;
@@ -589,7 +581,7 @@ class SHA2 extends utils_js_1$1.Hash {
589
581
  this.view = (0, utils_js_1$1.createView)(this.buffer);
590
582
  }
591
583
  update(data) {
592
- _assert_js_1.default.exists(this);
584
+ (0, _assert_js_1.exists)(this);
593
585
  const { view, buffer, blockLen } = this;
594
586
  data = (0, utils_js_1$1.toBytes)(data);
595
587
  const len = data.length;
@@ -615,8 +607,8 @@ class SHA2 extends utils_js_1$1.Hash {
615
607
  return this;
616
608
  }
617
609
  digestInto(out) {
618
- _assert_js_1.default.exists(this);
619
- _assert_js_1.default.output(out, this);
610
+ (0, _assert_js_1.exists)(this);
611
+ (0, _assert_js_1.output)(out, this);
620
612
  this.finished = true;
621
613
  // Padding
622
614
  // We can avoid allocation of buffer for padding completely if it
@@ -677,6 +669,8 @@ Object.defineProperty(sha256, "__esModule", { value: true });
677
669
  sha256.sha224 = sha256.sha256 = void 0;
678
670
  const _sha2_js_1 = _sha2;
679
671
  const utils_js_1 = utils;
672
+ // SHA2-256 need to try 2^128 hashes to execute birthday attack.
673
+ // BTC network is doing 2^67 hashes/sec as per early 2023.
680
674
  // Choice: a ? b : c
681
675
  const Chi = (a, b, c) => (a & b) ^ (~a & c);
682
676
  // Majority function, true if any two inpust is true
@@ -684,7 +678,7 @@ const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
684
678
  // Round constants:
685
679
  // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
686
680
  // prettier-ignore
687
- const SHA256_K = new Uint32Array([
681
+ const SHA256_K = /* @__PURE__ */ new Uint32Array([
688
682
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
689
683
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
690
684
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -696,12 +690,12 @@ const SHA256_K = new Uint32Array([
696
690
  ]);
697
691
  // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
698
692
  // prettier-ignore
699
- const IV = new Uint32Array([
693
+ const IV = /* @__PURE__ */ new Uint32Array([
700
694
  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
701
695
  ]);
702
696
  // Temporary buffer, not used to store anything between runs
703
697
  // Named this way because it matches specification.
704
- const SHA256_W = new Uint32Array(64);
698
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
705
699
  class SHA256 extends _sha2_js_1.SHA2 {
706
700
  constructor() {
707
701
  super(64, 32, 8, false);
@@ -24064,7 +24058,7 @@ class Client extends Base {
24064
24058
  * @throws On duplicate entries, missing or wrong cluster keys.
24065
24059
  *
24066
24060
  * An example of how to use createClusterDefinition:
24067
- * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L45)
24061
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24068
24062
  */
24069
24063
  async createClusterDefinition(newCluster) {
24070
24064
  const isValid = validateDefinition(newCluster);
@@ -24093,12 +24087,24 @@ class Client extends Base {
24093
24087
  }
24094
24088
  }
24095
24089
  /**
24096
- * @param configHash The config hash of the requested cluster
24090
+ * @returns {Promise<ClusterDefintion>} The cluster definition for config hash
24091
+ * @throws On not found config hash.
24092
+ *
24093
+ * An example of how to use getClusterDefinition:
24094
+ * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24095
+ */
24096
+ async getClusterDefinition(configHash) {
24097
+ const clusterDefinition = await this.request(`/dv/${configHash}`, {
24098
+ method: 'GET',
24099
+ });
24100
+ return clusterDefinition;
24101
+ }
24102
+ /**
24097
24103
  * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
24098
24104
  * @throws On not found cluster definition or lock.
24099
24105
  *
24100
24106
  * An example of how to use getClusterLock:
24101
- * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L61)
24107
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24102
24108
  */
24103
24109
  async getClusterLock(configHash) {
24104
24110
  const lock = await this.request(`/lock/configHash/${configHash}`, {
package/dist/index.js CHANGED
@@ -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 }, (v, i) => i.toString(16).padStart(2, '0'));
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
- // Check if object doens't have custom constructor (like Uint8Array/Array)
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 && (typeof opts !== 'object' || !isPlainObject(opts)))
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.default.exists(this);
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.default.exists(this);
646
- _assert_js_1.default.output(out, this);
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);
@@ -24091,7 +24085,7 @@ class Client extends Base {
24091
24085
  * @throws On duplicate entries, missing or wrong cluster keys.
24092
24086
  *
24093
24087
  * An example of how to use createClusterDefinition:
24094
- * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L45)
24088
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24095
24089
  */
24096
24090
  async createClusterDefinition(newCluster) {
24097
24091
  const isValid = validateDefinition(newCluster);
@@ -24120,12 +24114,24 @@ class Client extends Base {
24120
24114
  }
24121
24115
  }
24122
24116
  /**
24123
- * @param configHash The config hash of the requested cluster
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
+ /**
24124
24130
  * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
24125
24131
  * @throws On not found cluster definition or lock.
24126
24132
  *
24127
24133
  * An example of how to use getClusterLock:
24128
- * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L61)
24134
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
24129
24135
  */
24130
24136
  async getClusterLock(configHash) {
24131
24137
  const lock = await this.request(`/lock/configHash/${configHash}`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obolnetwork/obol-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A package for creating Distributed Validators using the Obol API.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -42,13 +42,13 @@
42
42
  "ajv": "^8.12.0",
43
43
  "cross-fetch": "^3.1.5",
44
44
  "ethers": "^6.4.0",
45
- "nock": "^13.3.1",
46
45
  "uuid": "^9.0.0"
47
46
  },
48
47
  "devDependencies": {
49
48
  "@types/jest": "^28.1.8",
50
49
  "@types/node": "^20.2.5",
51
50
  "@types/uuid": "^9.0.1",
51
+ "fetch-mock": "^9.11.0",
52
52
  "jest": "^28.1.3",
53
53
  "rollup-config": "*",
54
54
  "ts-jest": "^28.0.8",