capjs-core 0.1.6 → 0.1.7

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/src/rsw.js CHANGED
@@ -81,7 +81,6 @@ function hexOf(bi, byteLen) {
81
81
  return s;
82
82
  }
83
83
 
84
- // generation is expensive (~700 ms for 2048-bit on a modern CPU); persist the result.
85
84
  export function generateRswKeypair(bits = 2048) {
86
85
  if (bits % 2 !== 0) throw new Error("rsw bits must be even");
87
86
  const p = randomPrime(bits >> 1);
@@ -92,15 +91,23 @@ export function generateRswKeypair(bits = 2048) {
92
91
  }
93
92
 
94
93
  export function serializeRswKeypair(kp) {
95
- return { N: kp.N.toString(), p: kp.p.toString(), q: kp.q.toString(), bits: kp.bits ?? null };
94
+ return {
95
+ N: kp.N.toString(),
96
+ p: kp.p.toString(),
97
+ q: kp.q.toString(),
98
+ bits: kp.bits ?? null,
99
+ };
96
100
  }
97
101
  export function deserializeRswKeypair(s) {
98
- if (!s || typeof s !== "object") throw new Error("invalid serialized rsw keypair");
102
+ if (!s || typeof s !== "object")
103
+ throw new Error("invalid serialized rsw keypair");
99
104
  const N = typeof s.N === "string" ? BigInt(s.N) : s.N;
100
105
  const p = typeof s.p === "string" ? BigInt(s.p) : s.p;
101
106
  const q = typeof s.q === "string" ? BigInt(s.q) : s.q;
102
107
  if (typeof N !== "bigint" || typeof p !== "bigint" || typeof q !== "bigint") {
103
- throw new Error("rsw keypair fields must be bigint or string-encoded bigint");
108
+ throw new Error(
109
+ "rsw keypair fields must be bigint or string-encoded bigint",
110
+ );
104
111
  }
105
112
  return { N, p, q, bits: s.bits ?? N.toString(2).length };
106
113
  }
@@ -161,7 +168,8 @@ export function buildRswMinter({ N, p, q, t, g }, opts = {}) {
161
168
  }
162
169
 
163
170
  export function verifyRswSolution(expectedYHex, claimedYHex) {
164
- if (typeof claimedYHex !== "string" || typeof expectedYHex !== "string") return false;
171
+ if (typeof claimedYHex !== "string" || typeof expectedYHex !== "string")
172
+ return false;
165
173
  const norm = (s) => s.replace(/^0x/, "").toLowerCase().replace(/^0+/, "");
166
174
  return norm(expectedYHex) === norm(claimedYHex);
167
175
  }