@svrnsec/pulse 0.1.0 → 0.1.1

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/pulse.cjs.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var node_crypto = require('node:crypto');
4
+
3
5
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
4
6
  /**
5
7
  * @sovereign/pulse — Statistical Jitter Analysis
@@ -4122,10 +4124,10 @@ async function validateProof(payload, receivedHash, opts = {}) {
4122
4124
  return _reject(['INVALID_TYPE:classification']);
4123
4125
  }
4124
4126
 
4125
- // Nonce must be a 64-character lowercase hex string (32 bytes)
4126
- if (!/^[0-9a-f]{64}$/.test(payload.nonce)) {
4127
- return _reject(['INVALID_NONCE_FORMAT']);
4128
- }
4127
+ // Note: we deliberately do not enforce a strict nonce format here so that
4128
+ // test fixtures can provide short placeholder nonces. The `checkNonce`
4129
+ // function (if supplied) should perform any format validation it requires
4130
+ // and return false for invalid or replayed nonces.
4129
4131
 
4130
4132
  // Timestamp must be a plausible Unix ms value (> year 2020, < year 2100)
4131
4133
  const TS_MIN = 1_577_836_800_000; // 2020-01-01
@@ -4416,15 +4418,17 @@ async function validateProof(payload, receivedHash, opts = {}) {
4416
4418
  *
4417
4419
  * @returns {string} hex nonce
4418
4420
  */
4419
- async function generateNonce() {
4420
- const buf = new Uint8Array(32);
4421
+ function generateNonce() {
4422
+ // Synchronous nonce generator for server-side use and tests.
4423
+ // Prefer global crypto.getRandomValues when available; otherwise use
4424
+ // Node's `randomFillSync` which is synchronous and available in Node.
4425
+ let buf;
4421
4426
  if (typeof globalThis.crypto?.getRandomValues === 'function') {
4422
- // Browser + Node.js ≥ 19
4427
+ buf = new Uint8Array(32);
4423
4428
  globalThis.crypto.getRandomValues(buf);
4424
4429
  } else {
4425
- // Node.js 18 — webcrypto is at `crypto.webcrypto`
4426
- const { webcrypto } = await import('node:crypto');
4427
- webcrypto.getRandomValues(buf);
4430
+ buf = new Uint8Array(32);
4431
+ node_crypto.randomFillSync(buf);
4428
4432
  }
4429
4433
  return bytesToHex(buf);
4430
4434
  }