@zoralabs/protocol-deployments 0.2.0 → 0.2.2

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.
@@ -10,12 +10,12 @@ import {
10
10
  rotr,
11
11
  toBytes,
12
12
  wrapConstructor
13
- } from "./chunk-2FDPSBOH.js";
13
+ } from "./chunk-5JV63AHR.js";
14
14
  import {
15
15
  __export
16
16
  } from "./chunk-3EJPJMEH.js";
17
17
 
18
- // ../../node_modules/@noble/hashes/esm/_sha2.js
18
+ // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_md.js
19
19
  function setBigUint64(view, byteOffset, value, isLE) {
20
20
  if (typeof view.setBigUint64 === "function")
21
21
  return view.setBigUint64(byteOffset, value, isLE);
@@ -28,7 +28,9 @@ function setBigUint64(view, byteOffset, value, isLE) {
28
28
  view.setUint32(byteOffset + h, wh, isLE);
29
29
  view.setUint32(byteOffset + l, wl, isLE);
30
30
  }
31
- var SHA2 = class extends Hash {
31
+ var Chi = (a, b, c) => a & b ^ ~a & c;
32
+ var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
33
+ var HashMD = class extends Hash {
32
34
  constructor(blockLen, outputLen, padOffset, isLE) {
33
35
  super();
34
36
  this.blockLen = blockLen;
@@ -115,9 +117,7 @@ var SHA2 = class extends Hash {
115
117
  }
116
118
  };
117
119
 
118
- // ../../node_modules/@noble/hashes/esm/sha256.js
119
- var Chi = (a, b, c) => a & b ^ ~a & c;
120
- var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
120
+ // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/sha256.js
121
121
  var SHA256_K = /* @__PURE__ */ new Uint32Array([
122
122
  1116352408,
123
123
  1899447441,
@@ -184,7 +184,7 @@ var SHA256_K = /* @__PURE__ */ new Uint32Array([
184
184
  3204031479,
185
185
  3329325298
186
186
  ]);
187
- var IV = /* @__PURE__ */ new Uint32Array([
187
+ var SHA256_IV = /* @__PURE__ */ new Uint32Array([
188
188
  1779033703,
189
189
  3144134277,
190
190
  1013904242,
@@ -195,17 +195,17 @@ var IV = /* @__PURE__ */ new Uint32Array([
195
195
  1541459225
196
196
  ]);
197
197
  var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
198
- var SHA256 = class extends SHA2 {
198
+ var SHA256 = class extends HashMD {
199
199
  constructor() {
200
200
  super(64, 32, 8, false);
201
- this.A = IV[0] | 0;
202
- this.B = IV[1] | 0;
203
- this.C = IV[2] | 0;
204
- this.D = IV[3] | 0;
205
- this.E = IV[4] | 0;
206
- this.F = IV[5] | 0;
207
- this.G = IV[6] | 0;
208
- this.H = IV[7] | 0;
201
+ this.A = SHA256_IV[0] | 0;
202
+ this.B = SHA256_IV[1] | 0;
203
+ this.C = SHA256_IV[2] | 0;
204
+ this.D = SHA256_IV[3] | 0;
205
+ this.E = SHA256_IV[4] | 0;
206
+ this.F = SHA256_IV[5] | 0;
207
+ this.G = SHA256_IV[6] | 0;
208
+ this.H = SHA256_IV[7] | 0;
209
209
  }
210
210
  get() {
211
211
  const { A, B, C, D, E, F, G, H } = this;
@@ -267,9 +267,10 @@ var SHA256 = class extends SHA2 {
267
267
  };
268
268
  var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
269
269
 
270
- // ../../node_modules/@noble/curves/esm/abstract/utils.js
270
+ // ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/utils.js
271
271
  var utils_exports = {};
272
272
  __export(utils_exports, {
273
+ abytes: () => abytes,
273
274
  bitGet: () => bitGet,
274
275
  bitLen: () => bitLen,
275
276
  bitMask: () => bitMask,
@@ -283,6 +284,7 @@ __export(utils_exports, {
283
284
  equalBytes: () => equalBytes,
284
285
  hexToBytes: () => hexToBytes,
285
286
  hexToNumber: () => hexToNumber,
287
+ isBytes: () => isBytes,
286
288
  numberToBytesBE: () => numberToBytesBE,
287
289
  numberToBytesLE: () => numberToBytesLE,
288
290
  numberToHexUnpadded: () => numberToHexUnpadded,
@@ -293,11 +295,16 @@ __export(utils_exports, {
293
295
  var _0n = BigInt(0);
294
296
  var _1n = BigInt(1);
295
297
  var _2n = BigInt(2);
296
- var u8a = (a) => a instanceof Uint8Array;
298
+ function isBytes(a) {
299
+ return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
300
+ }
301
+ function abytes(item) {
302
+ if (!isBytes(item))
303
+ throw new Error("Uint8Array expected");
304
+ }
297
305
  var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
298
306
  function bytesToHex(bytes2) {
299
- if (!u8a(bytes2))
300
- throw new Error("Uint8Array expected");
307
+ abytes(bytes2);
301
308
  let hex = "";
302
309
  for (let i = 0; i < bytes2.length; i++) {
303
310
  hex += hexes[bytes2[i]];
@@ -313,20 +320,32 @@ function hexToNumber(hex) {
313
320
  throw new Error("hex string expected, got " + typeof hex);
314
321
  return BigInt(hex === "" ? "0" : `0x${hex}`);
315
322
  }
323
+ var asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
324
+ function asciiToBase16(char) {
325
+ if (char >= asciis._0 && char <= asciis._9)
326
+ return char - asciis._0;
327
+ if (char >= asciis._A && char <= asciis._F)
328
+ return char - (asciis._A - 10);
329
+ if (char >= asciis._a && char <= asciis._f)
330
+ return char - (asciis._a - 10);
331
+ return;
332
+ }
316
333
  function hexToBytes(hex) {
317
334
  if (typeof hex !== "string")
318
335
  throw new Error("hex string expected, got " + typeof hex);
319
- const len = hex.length;
320
- if (len % 2)
321
- throw new Error("padded hex string expected, got unpadded hex of length " + len);
322
- const array = new Uint8Array(len / 2);
323
- for (let i = 0; i < array.length; i++) {
324
- const j = i * 2;
325
- const hexByte = hex.slice(j, j + 2);
326
- const byte = Number.parseInt(hexByte, 16);
327
- if (Number.isNaN(byte) || byte < 0)
328
- throw new Error("Invalid byte sequence");
329
- array[i] = byte;
336
+ const hl = hex.length;
337
+ const al = hl / 2;
338
+ if (hl % 2)
339
+ throw new Error("padded hex string expected, got unpadded hex of length " + hl);
340
+ const array = new Uint8Array(al);
341
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
342
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
343
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
344
+ if (n1 === void 0 || n2 === void 0) {
345
+ const char = hex[hi] + hex[hi + 1];
346
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
347
+ }
348
+ array[ai] = n1 * 16 + n2;
330
349
  }
331
350
  return array;
332
351
  }
@@ -334,8 +353,7 @@ function bytesToNumberBE(bytes2) {
334
353
  return hexToNumber(bytesToHex(bytes2));
335
354
  }
336
355
  function bytesToNumberLE(bytes2) {
337
- if (!u8a(bytes2))
338
- throw new Error("Uint8Array expected");
356
+ abytes(bytes2);
339
357
  return hexToNumber(bytesToHex(Uint8Array.from(bytes2).reverse()));
340
358
  }
341
359
  function numberToBytesBE(n, len) {
@@ -355,7 +373,7 @@ function ensureBytes(title, hex, expectedLength) {
355
373
  } catch (e) {
356
374
  throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
357
375
  }
358
- } else if (u8a(hex)) {
376
+ } else if (isBytes(hex)) {
359
377
  res = Uint8Array.from(hex);
360
378
  } else {
361
379
  throw new Error(`${title} must be hex string or Uint8Array`);
@@ -366,23 +384,27 @@ function ensureBytes(title, hex, expectedLength) {
366
384
  return res;
367
385
  }
368
386
  function concatBytes2(...arrays) {
369
- const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
370
- let pad = 0;
371
- arrays.forEach((a) => {
372
- if (!u8a(a))
373
- throw new Error("Uint8Array expected");
374
- r.set(a, pad);
387
+ let sum = 0;
388
+ for (let i = 0; i < arrays.length; i++) {
389
+ const a = arrays[i];
390
+ abytes(a);
391
+ sum += a.length;
392
+ }
393
+ const res = new Uint8Array(sum);
394
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
395
+ const a = arrays[i];
396
+ res.set(a, pad);
375
397
  pad += a.length;
376
- });
377
- return r;
398
+ }
399
+ return res;
378
400
  }
379
- function equalBytes(b1, b2) {
380
- if (b1.length !== b2.length)
401
+ function equalBytes(a, b) {
402
+ if (a.length !== b.length)
381
403
  return false;
382
- for (let i = 0; i < b1.length; i++)
383
- if (b1[i] !== b2[i])
384
- return false;
385
- return true;
404
+ let diff = 0;
405
+ for (let i = 0; i < a.length; i++)
406
+ diff |= a[i] ^ b[i];
407
+ return diff === 0;
386
408
  }
387
409
  function utf8ToBytes(str) {
388
410
  if (typeof str !== "string")
@@ -398,9 +420,9 @@ function bitLen(n) {
398
420
  function bitGet(n, pos) {
399
421
  return n >> BigInt(pos) & _1n;
400
422
  }
401
- var bitSet = (n, pos, value) => {
423
+ function bitSet(n, pos, value) {
402
424
  return n | (value ? _1n : _0n) << BigInt(pos);
403
- };
425
+ }
404
426
  var bitMask = (n) => (_2n << BigInt(n - 1)) - _1n;
405
427
  var u8n = (data) => new Uint8Array(data);
406
428
  var u8fr = (arr) => Uint8Array.from(arr);
@@ -457,7 +479,7 @@ var validatorFns = {
457
479
  function: (val) => typeof val === "function",
458
480
  boolean: (val) => typeof val === "boolean",
459
481
  string: (val) => typeof val === "string",
460
- stringOrUint8Array: (val) => typeof val === "string" || val instanceof Uint8Array,
482
+ stringOrUint8Array: (val) => typeof val === "string" || isBytes(val),
461
483
  isSafeInteger: (val) => Number.isSafeInteger(val),
462
484
  array: (val) => Array.isArray(val),
463
485
  field: (val, object) => object.Fp.isValid(val),
@@ -482,7 +504,7 @@ function validateObject(object, validators, optValidators = {}) {
482
504
  return object;
483
505
  }
484
506
 
485
- // ../../node_modules/@noble/curves/esm/abstract/modular.js
507
+ // ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/modular.js
486
508
  var _0n2 = BigInt(0);
487
509
  var _1n2 = BigInt(1);
488
510
  var _2n2 = BigInt(2);
@@ -748,7 +770,7 @@ function mapHashToField(key, fieldOrder, isLE = false) {
748
770
  return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
749
771
  }
750
772
 
751
- // ../../node_modules/@noble/curves/esm/abstract/curve.js
773
+ // ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/curve.js
752
774
  var _0n3 = BigInt(0);
753
775
  var _1n3 = BigInt(1);
754
776
  function wNAF(c, bits) {
@@ -866,7 +888,7 @@ function validateBasic(curve) {
866
888
  });
867
889
  }
868
890
 
869
- // ../../node_modules/@noble/curves/esm/abstract/weierstrass.js
891
+ // ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/weierstrass.js
870
892
  function validatePointOpts(curve) {
871
893
  const opts = validateBasic(curve);
872
894
  validateObject(opts, {
@@ -917,8 +939,7 @@ var DER = {
917
939
  toSig(hex) {
918
940
  const { Err: E } = DER;
919
941
  const data = typeof hex === "string" ? h2b(hex) : hex;
920
- if (!(data instanceof Uint8Array))
921
- throw new Error("ui8a expected");
942
+ abytes(data);
922
943
  let l = data.length;
923
944
  if (l < 2 || data[0] != 48)
924
945
  throw new E("Invalid signature tag");
@@ -981,7 +1002,7 @@ function weierstrassPoints(opts) {
981
1002
  function normPrivateKeyToScalar(key) {
982
1003
  const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE;
983
1004
  if (lengths && typeof key !== "bigint") {
984
- if (key instanceof Uint8Array)
1005
+ if (isBytes(key))
985
1006
  key = bytesToHex(key);
986
1007
  if (typeof key !== "string" || !lengths.includes(key.length))
987
1008
  throw new Error("Invalid key");
@@ -1387,7 +1408,13 @@ function weierstrass(curveDef) {
1387
1408
  if (!isValidFieldElement(x))
1388
1409
  throw new Error("Point is not on curve");
1389
1410
  const y2 = weierstrassEquation(x);
1390
- let y = Fp2.sqrt(y2);
1411
+ let y;
1412
+ try {
1413
+ y = Fp2.sqrt(y2);
1414
+ } catch (sqrtError) {
1415
+ const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
1416
+ throw new Error("Point is not on curve" + suffix);
1417
+ }
1391
1418
  const isYOdd = (y & _1n4) === _1n4;
1392
1419
  const isHeadOdd = (head & 1) === 1;
1393
1420
  if (isHeadOdd !== isYOdd)
@@ -1516,7 +1543,7 @@ function weierstrass(curveDef) {
1516
1543
  return Point2.fromPrivateKey(privateKey).toRawBytes(isCompressed);
1517
1544
  }
1518
1545
  function isProbPub(item) {
1519
- const arr = item instanceof Uint8Array;
1546
+ const arr = isBytes(item);
1520
1547
  const str = typeof item === "string";
1521
1548
  const len = (arr || str) && item.length;
1522
1549
  if (arr)
@@ -1564,7 +1591,7 @@ function weierstrass(curveDef) {
1564
1591
  const h1int = bits2int_modN(msgHash);
1565
1592
  const d = normPrivateKeyToScalar(privateKey);
1566
1593
  const seedArgs = [int2octets(d), int2octets(h1int)];
1567
- if (ent != null) {
1594
+ if (ent != null && ent !== false) {
1568
1595
  const e = ent === true ? randomBytes2(Fp2.BYTES) : ent;
1569
1596
  seedArgs.push(ensureBytes("extraEntropy", e));
1570
1597
  }
@@ -1611,7 +1638,7 @@ function weierstrass(curveDef) {
1611
1638
  let _sig = void 0;
1612
1639
  let P;
1613
1640
  try {
1614
- if (typeof sg === "string" || sg instanceof Uint8Array) {
1641
+ if (typeof sg === "string" || isBytes(sg)) {
1615
1642
  try {
1616
1643
  _sig = Signature.fromDER(sg);
1617
1644
  } catch (derError) {
@@ -1757,14 +1784,7 @@ function mapToCurveSimpleSWU(Fp2, opts) {
1757
1784
  };
1758
1785
  }
1759
1786
 
1760
- // ../../node_modules/@noble/curves/esm/abstract/hash-to-curve.js
1761
- function validateDST(dst) {
1762
- if (dst instanceof Uint8Array)
1763
- return dst;
1764
- if (typeof dst === "string")
1765
- return utf8ToBytes(dst);
1766
- throw new Error("DST must be Uint8Array or string");
1767
- }
1787
+ // ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/hash-to-curve.js
1768
1788
  var os2ip = bytesToNumberBE;
1769
1789
  function i2osp(value, length) {
1770
1790
  if (value < 0 || value >= 1 << 8 * length) {
@@ -1784,18 +1804,14 @@ function strxor(a, b) {
1784
1804
  }
1785
1805
  return arr;
1786
1806
  }
1787
- function isBytes(item) {
1788
- if (!(item instanceof Uint8Array))
1789
- throw new Error("Uint8Array expected");
1790
- }
1791
- function isNum(item) {
1807
+ function anum(item) {
1792
1808
  if (!Number.isSafeInteger(item))
1793
1809
  throw new Error("number expected");
1794
1810
  }
1795
1811
  function expand_message_xmd(msg, DST, lenInBytes, H) {
1796
- isBytes(msg);
1797
- isBytes(DST);
1798
- isNum(lenInBytes);
1812
+ abytes(msg);
1813
+ abytes(DST);
1814
+ anum(lenInBytes);
1799
1815
  if (DST.length > 255)
1800
1816
  DST = H(concatBytes2(utf8ToBytes("H2C-OVERSIZE-DST-"), DST));
1801
1817
  const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
@@ -1816,9 +1832,9 @@ function expand_message_xmd(msg, DST, lenInBytes, H) {
1816
1832
  return pseudo_random_bytes.slice(0, lenInBytes);
1817
1833
  }
1818
1834
  function expand_message_xof(msg, DST, lenInBytes, k, H) {
1819
- isBytes(msg);
1820
- isBytes(DST);
1821
- isNum(lenInBytes);
1835
+ abytes(msg);
1836
+ abytes(DST);
1837
+ anum(lenInBytes);
1822
1838
  if (DST.length > 255) {
1823
1839
  const dkLen = Math.ceil(2 * k / 8);
1824
1840
  DST = H.create({ dkLen }).update(utf8ToBytes("H2C-OVERSIZE-DST-")).update(DST).digest();
@@ -1836,9 +1852,9 @@ function hash_to_field(msg, count, options) {
1836
1852
  hash: "hash"
1837
1853
  });
1838
1854
  const { p, k, m, hash: hash2, expand, DST: _DST } = options;
1839
- isBytes(msg);
1840
- isNum(count);
1841
- const DST = validateDST(_DST);
1855
+ abytes(msg);
1856
+ anum(count);
1857
+ const DST = typeof _DST === "string" ? utf8ToBytes(_DST) : _DST;
1842
1858
  const log2p = p.toString(2).length;
1843
1859
  const L = Math.ceil((log2p + k) / 8);
1844
1860
  const len_in_bytes = count * m * L;
@@ -1898,7 +1914,7 @@ function createHasher(Point2, mapToCurve, def) {
1898
1914
  };
1899
1915
  }
1900
1916
 
1901
- // ../../node_modules/@noble/hashes/esm/hmac.js
1917
+ // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/hmac.js
1902
1918
  var HMAC = class extends Hash {
1903
1919
  constructor(hash2, _key) {
1904
1920
  super();
@@ -1963,7 +1979,7 @@ var HMAC = class extends Hash {
1963
1979
  var hmac = (hash2, key, message) => new HMAC(hash2, key).update(message).digest();
1964
1980
  hmac.create = (hash2, key) => new HMAC(hash2, key);
1965
1981
 
1966
- // ../../node_modules/@noble/curves/esm/_shortw_utils.js
1982
+ // ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/_shortw_utils.js
1967
1983
  function getHash(hash2) {
1968
1984
  return {
1969
1985
  hash: hash2,
@@ -1976,7 +1992,7 @@ function createCurve(curveDef, defHash) {
1976
1992
  return Object.freeze({ ...create(defHash), create });
1977
1993
  }
1978
1994
 
1979
- // ../../node_modules/@noble/curves/esm/secp256k1.js
1995
+ // ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/secp256k1.js
1980
1996
  var secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
1981
1997
  var secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
1982
1998
  var _1n5 = BigInt(1);
@@ -2007,14 +2023,20 @@ function sqrtMod(y) {
2007
2023
  var Fp = Field(secp256k1P, void 0, void 0, { sqrt: sqrtMod });
2008
2024
  var secp256k1 = createCurve({
2009
2025
  a: BigInt(0),
2026
+ // equation params: a, b
2010
2027
  b: BigInt(7),
2028
+ // Seem to be rigid: bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
2011
2029
  Fp,
2030
+ // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
2012
2031
  n: secp256k1N,
2032
+ // Curve order, total count of valid points in the field
2013
2033
  // Base point (x, y) aka generator point
2014
2034
  Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
2015
2035
  Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
2016
2036
  h: BigInt(1),
2037
+ // Cofactor
2017
2038
  lowS: true,
2039
+ // Allow only low-S signatures by default in sign() and verify()
2018
2040
  /**
2019
2041
  * secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
2020
2042
  * Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
@@ -2219,4 +2241,4 @@ export {
2219
2241
  @noble/curves/esm/secp256k1.js:
2220
2242
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2221
2243
  */
2222
- //# sourceMappingURL=secp256k1-R7PEGLZR.js.map
2244
+ //# sourceMappingURL=secp256k1-5CEPNAX3.js.map