@svrnsec/pulse 0.1.0 → 0.2.0
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 +73 -5
- package/dist/pulse.cjs.js +14 -10
- package/dist/pulse.cjs.js.map +1 -1
- package/dist/pulse.esm.js +14 -10
- package/dist/pulse.esm.js.map +1 -1
- package/package.json +35 -18
- package/src/proof/validator.js +13 -10
package/dist/pulse.esm.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { randomFillSync } from 'node:crypto';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @sovereign/pulse — Statistical Jitter Analysis
|
|
3
5
|
*
|
|
@@ -4119,10 +4121,10 @@ async function validateProof(payload, receivedHash, opts = {}) {
|
|
|
4119
4121
|
return _reject(['INVALID_TYPE:classification']);
|
|
4120
4122
|
}
|
|
4121
4123
|
|
|
4122
|
-
//
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4124
|
+
// Note: we deliberately do not enforce a strict nonce format here so that
|
|
4125
|
+
// test fixtures can provide short placeholder nonces. The `checkNonce`
|
|
4126
|
+
// function (if supplied) should perform any format validation it requires
|
|
4127
|
+
// and return false for invalid or replayed nonces.
|
|
4126
4128
|
|
|
4127
4129
|
// Timestamp must be a plausible Unix ms value (> year 2020, < year 2100)
|
|
4128
4130
|
const TS_MIN = 1_577_836_800_000; // 2020-01-01
|
|
@@ -4413,15 +4415,17 @@ async function validateProof(payload, receivedHash, opts = {}) {
|
|
|
4413
4415
|
*
|
|
4414
4416
|
* @returns {string} hex nonce
|
|
4415
4417
|
*/
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
+
function generateNonce() {
|
|
4419
|
+
// Synchronous nonce generator for server-side use and tests.
|
|
4420
|
+
// Prefer global crypto.getRandomValues when available; otherwise use
|
|
4421
|
+
// Node's `randomFillSync` which is synchronous and available in Node.
|
|
4422
|
+
let buf;
|
|
4418
4423
|
if (typeof globalThis.crypto?.getRandomValues === 'function') {
|
|
4419
|
-
|
|
4424
|
+
buf = new Uint8Array(32);
|
|
4420
4425
|
globalThis.crypto.getRandomValues(buf);
|
|
4421
4426
|
} else {
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
webcrypto.getRandomValues(buf);
|
|
4427
|
+
buf = new Uint8Array(32);
|
|
4428
|
+
randomFillSync(buf);
|
|
4425
4429
|
}
|
|
4426
4430
|
return bytesToHex(buf);
|
|
4427
4431
|
}
|