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/README.md +5 -2
- package/package.json +5 -2
- package/src/agents.js +700 -0
- package/src/behavior.js +437 -0
- package/src/detect.js +189 -8
- package/src/hashwx-wasm.js +1 -5
- package/src/index.d.ts +198 -43
- package/src/index.js +298 -67
- package/src/instrumentation.js +742 -116
- package/src/rsw.js +13 -5
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 {
|
|
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")
|
|
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(
|
|
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")
|
|
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
|
}
|