Aere Proof of Software 1.4.0: an attestation of what was built, from what, by whom and when, verifiable without trusting Aere Network
Every artifact's SHA-256 and size, the SBOM's digest, the git commit and tree of the source, a hybrid signature (classical + ML-DSA, both required) and, when notarized, a first-seen time on Aere Network covered by the validators' post-quantum certificate. verify recomputes everything from the files; --rebuild-from repeats an npm pack build from a clone the verifier chose; the SBOM is re-derived from the committed package-lock.json or, new in 1.4.0, from the committed go.mod and go.sum; --signer requires the signing keys you expect (1.4.0); a developer credential binds the keys to a person, judged against a trust root you choose. The builder's declared date can only accuse, never acquit (1.4.0). Includes the GitHub Action and the hybrid signature library it uses. Laid out as in the development repository (tools/proof-of-software/, sdk-pq-sign/, sdk/) so that nothing is rewritten for publication. Tests and negative controls measured on 2026-09-29 are listed in README.md.
This commit is contained in:
commit
065f84e34a
35 files changed
+3511
No files matched your search
@@ -0,0 +1,15 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Aere Network
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
||||
@@ -0,0 +1,88 @@
|
||||
# @aere/pq-sign
|
||||
|
||||
Hybrid signatures for documents, payloads, receipts and API calls: a classical scheme (**secp256k1** or **Ed25519**) and a
|
||||
NIST post-quantum scheme (**ML-DSA-44 / 65 / 87**, FIPS 204) sign the same digest, and a signature is valid only when
|
||||
**both** halves verify. Keys are generated and used only on your side; nothing is sent anywhere. The post-quantum half
|
||||
can be re-verified independently by the Aere Network chain precompile, so a third party does not have to trust this
|
||||
library, or you, to check it.
|
||||
|
||||
```
|
||||
npm install @aere/pq-sign
|
||||
```
|
||||
|
||||
Pure JavaScript (the audited noble libraries; no native code): Node 18+, and any bundler for the browser.
|
||||
|
||||
## Why hybrid
|
||||
|
||||
A signature made with two independent schemes stays unforgeable while **either** scheme holds. If large quantum
|
||||
computers break secp256k1 and Ed25519, the ML-DSA half still binds the signer; if a flaw is found in the young lattice
|
||||
scheme, the classical half still does. This is the migration shape recommended by NIST, the German BSI and the French
|
||||
ANSSI for the transition years: not "replace", but "add, and require both".
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import { generateKeyPair, sign, verify, serialize, parse, envelopeHash } from '@aere/pq-sign';
|
||||
|
||||
const keys = generateKeyPair({ alg: 'secp256k1+ml-dsa-65' }); // or 'ed25519+ml-dsa-65', '...+ml-dsa-44', '...+ml-dsa-87'
|
||||
const envelope = sign('release notes of myapp 1.4.2', keys); // string or Uint8Array
|
||||
const r = verify('release notes of myapp 1.4.2', envelope);
|
||||
// r = { valid: true, classical: true, pq: true, messageHashMatches: true, toSignMatches: true, reason: null }
|
||||
|
||||
const text = serialize(envelope); // JSON, all byte fields 0x-hex; parse(text) gives it back
|
||||
```
|
||||
|
||||
Keep `keys.classical.secretKey` and `keys.pq.secretKey` where you keep secrets. Publish `keys.classical.publicKey` and
|
||||
`keys.pq.publicKey`; they travel inside every envelope anyway. `generateKeyPair({ seed })` makes the ML-DSA key
|
||||
deterministic (32-byte seed) for test vectors; classical keys are always fresh unless `classicalSecretKey` is given.
|
||||
|
||||
## What exactly is signed
|
||||
|
||||
```
|
||||
messageHash = sha256(message)
|
||||
toSign = sha256("aere-hybrid-signature-v1" || alg || messageHash)
|
||||
```
|
||||
|
||||
Both schemes sign the 32 bytes of `toSign`: secp256k1 as a digest (RFC 6979, compact 64-byte signature, compressed
|
||||
33-byte key), Ed25519 as a message (64-byte signature, 32-byte key), ML-DSA in the pure FIPS 204 interface with an
|
||||
empty context. The domain string and the algorithm label are under the hash, so an envelope cannot be replayed as a
|
||||
different algorithm pair or for another message. The envelope:
|
||||
|
||||
```json
|
||||
{ "v": 1, "kind": "aere-hybrid-signature", "alg": "secp256k1+ml-dsa-65", "hash": "sha256",
|
||||
"messageHash": "0x…", "toSign": "0x…",
|
||||
"classicalPublicKey": "0x…", "classicalSignature": "0x…",
|
||||
"pqPublicKey": "0x…", "pqSignature": "0x…" }
|
||||
```
|
||||
|
||||
Sizes: ML-DSA-44 key 1,312 B, signature 2,420 B; ML-DSA-65 1,952 / 3,309 B; ML-DSA-87 2,592 / 4,627 B.
|
||||
|
||||
## Independent verification on chain
|
||||
|
||||
The Aere Network chain (2800) runs the NIST post-quantum verifiers as native precompiles. With an
|
||||
[Aere Cloud](https://aere.network/cloud.html) key, the ML-DSA half of any envelope can be judged by the chain itself:
|
||||
|
||||
```js
|
||||
import { AereCloud } from '@aere/cloud';
|
||||
import { verifyOnChain } from '@aere/pq-sign';
|
||||
const r = await verifyOnChain(envelope, new AereCloud({ apiKey }));
|
||||
// r = { pqValidOnChain: true, precompile: '0x…0ae3', block: 19018096, chainId: 2800 }
|
||||
```
|
||||
|
||||
That answer does not depend on this library's code. One FIPS 204 detail, measured on chain 2800 on 2026-09-17: the
|
||||
ML-DSA precompile implements the internal verify (Algorithm 8), and a standard external signature is made over
|
||||
`M' = 0x00 || len(ctx) || ctx || M`; `verifyOnChain` asks the gateway for the external interface (`interface:
|
||||
"external"`), which builds `M'` for an empty context. Callers of the precompile directly should pass
|
||||
`precompileMessage(envelope)` as the message. And if you want a first-seen time for the signature that cannot be
|
||||
backdated and is covered by the validators' post-quantum certificate, notarize `envelopeHash(envelope)` with
|
||||
`POST /v1/notarize` and read `GET /v1/proof/{hash}`: first appearance, covering anchor, finality, verification steps.
|
||||
|
||||
## Tests
|
||||
|
||||
`npm test` runs every claim with its negative pair (a flipped bit in either half, another message, another key, a
|
||||
foreign envelope). With `AERE_CHEIE` (or `AERE_CHEIE_FISIER`) in the environment it also asks the chain precompile to
|
||||
confirm a fresh post-quantum signature and to refuse a corrupted one.
|
||||
|
||||
## License
|
||||
|
||||
MIT. Aere Network, 2026.
|
||||
@@ -0,0 +1,174 @@
|
||||
// @aere/pq-sign: hybrid signatures, classical + post-quantum, with keys that never leave the caller.
|
||||
//
|
||||
// Why hybrid: a signature made with two independent schemes stays unforgeable while EITHER scheme holds. If
|
||||
// large-scale quantum computers break secp256k1 / Ed25519, the ML-DSA half still binds the signer; if a flaw is
|
||||
// found in the young lattice scheme, the classical half still does. Verification requires BOTH halves to verify
|
||||
// over the SAME digest: a hybrid signature with one broken half is invalid, never "half valid".
|
||||
//
|
||||
// What is signed: toSign = sha256("aere-hybrid-signature-v1" || alg || sha256(message)). Both schemes sign
|
||||
// exactly those 32 bytes, so the post-quantum half can also be verified by the Aere Network chain precompile
|
||||
// (POST https://cloud.aere.network/v1/pq/verify with scheme, publicKey, signature = pqSignature, message = toSign),
|
||||
// which gives an independent, on-chain answer about the ML-DSA half.
|
||||
//
|
||||
// Envelope (JSON, all byte fields 0x-hex):
|
||||
// { v: 1, kind: "aere-hybrid-signature", alg: "secp256k1+ml-dsa-65", hash: "sha256", messageHash, toSign,
|
||||
// classicalPublicKey, classicalSignature, pqPublicKey, pqSignature }
|
||||
//
|
||||
// Pure JavaScript (noble libraries, audited, no native code): Node 18+ and any bundler for the browser.
|
||||
import { ml_dsa44, ml_dsa65, ml_dsa87 } from '@noble/post-quantum/ml-dsa.js';
|
||||
import { secp256k1 } from '@noble/curves/secp256k1';
|
||||
import { ed25519 } from '@noble/curves/ed25519';
|
||||
import { sha256 } from '@noble/hashes/sha256';
|
||||
import { randomBytes } from '@noble/hashes/utils';
|
||||
|
||||
export const VERSION = 1;
|
||||
export const KIND = 'aere-hybrid-signature';
|
||||
const DOMAIN = new TextEncoder().encode('aere-hybrid-signature-v1');
|
||||
|
||||
// ML-DSA parameter sets (FIPS 204). `id` is the AIP-20 algorithm id and the chain precompile scheme name is `chainScheme`.
|
||||
export const PQ_SCHEMES = Object.freeze({
|
||||
'ml-dsa-44': Object.freeze({ id: 1, impl: ml_dsa44, publicKeyBytes: 1312, secretKeyBytes: 2560, signatureBytes: 2420, chainScheme: 'ml-dsa-44' }),
|
||||
'ml-dsa-65': Object.freeze({ id: 2, impl: ml_dsa65, publicKeyBytes: 1952, secretKeyBytes: 4032, signatureBytes: 3309, chainScheme: 'ml-dsa-65' }),
|
||||
'ml-dsa-87': Object.freeze({ id: 3, impl: ml_dsa87, publicKeyBytes: 2592, secretKeyBytes: 4896, signatureBytes: 4627, chainScheme: 'ml-dsa-87' }),
|
||||
});
|
||||
|
||||
// Classical schemes. secp256k1 signs the 32-byte digest (compact 64-byte signature, compressed 33-byte key);
|
||||
// Ed25519 signs the same 32 bytes as a message (64-byte signature, 32-byte key).
|
||||
export const CLASSICAL_SCHEMES = Object.freeze({
|
||||
secp256k1: Object.freeze({
|
||||
publicKeyBytes: 33, secretKeyBytes: 32, signatureBytes: 64,
|
||||
generate: () => secp256k1.utils.randomPrivateKey(),
|
||||
publicKey: (sk) => secp256k1.getPublicKey(sk, true),
|
||||
sign: (digest, sk) => secp256k1.sign(digest, sk).toCompactRawBytes(),
|
||||
verify: (sig, digest, pk) => { try { return secp256k1.verify(sig, digest, pk); } catch { return false; } },
|
||||
}),
|
||||
ed25519: Object.freeze({
|
||||
publicKeyBytes: 32, secretKeyBytes: 32, signatureBytes: 64,
|
||||
generate: () => ed25519.utils.randomPrivateKey(),
|
||||
publicKey: (sk) => ed25519.getPublicKey(sk),
|
||||
sign: (digest, sk) => ed25519.sign(digest, sk),
|
||||
verify: (sig, digest, pk) => { try { return ed25519.verify(sig, digest, pk); } catch { return false; } },
|
||||
}),
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- bytes
|
||||
export const toHex = (u8) => '0x' + Array.from(u8, (b) => b.toString(16).padStart(2, '0')).join('');
|
||||
export function fromHex(h) {
|
||||
if (typeof h !== 'string') throw new TypeError('expected a 0x-hex string');
|
||||
const s = h.startsWith('0x') || h.startsWith('0X') ? h.slice(2) : h;
|
||||
if (s.length % 2 || /[^0-9a-fA-F]/.test(s)) throw new TypeError('malformed hex');
|
||||
const out = new Uint8Array(s.length / 2);
|
||||
for (let i = 0; i < out.length; i++) out[i] = parseInt(s.slice(2 * i, 2 * i + 2), 16);
|
||||
return out;
|
||||
}
|
||||
const asBytes = (m) => (m instanceof Uint8Array ? m : typeof m === 'string' ? new TextEncoder().encode(m) : (() => { throw new TypeError('message must be a Uint8Array or a string'); })());
|
||||
function concat(...parts) {
|
||||
const n = parts.reduce((a, p) => a + p.length, 0); const out = new Uint8Array(n); let o = 0;
|
||||
for (const p of parts) { out.set(p, o); o += p.length; } return out;
|
||||
}
|
||||
function equal(a, b) { if (a.length !== b.length) return false; let d = 0; for (let i = 0; i < a.length; i++) d |= a[i] ^ b[i]; return d === 0; }
|
||||
|
||||
// ---------------------------------------------------------------- algorithms
|
||||
export function parseAlg(alg) {
|
||||
const m = /^([a-z0-9]+)\+([a-z0-9-]+)$/.exec(String(alg || ''));
|
||||
if (!m || !CLASSICAL_SCHEMES[m[1]] || !PQ_SCHEMES[m[2]]) {
|
||||
throw new Error(`unknown alg "${alg}"; expected <${Object.keys(CLASSICAL_SCHEMES).join('|')}>+<${Object.keys(PQ_SCHEMES).join('|')}>`);
|
||||
}
|
||||
return { alg: `${m[1]}+${m[2]}`, classical: m[1], pq: m[2], C: CLASSICAL_SCHEMES[m[1]], P: PQ_SCHEMES[m[2]] };
|
||||
}
|
||||
|
||||
// The 32 bytes both schemes sign: domain, algorithm label and the message digest, so a signature cannot be
|
||||
// replayed under another algorithm pair or another message.
|
||||
export function messageHash(message) { return sha256(asBytes(message)); }
|
||||
export function toSign(alg, msgHash) {
|
||||
const { alg: a } = parseAlg(alg);
|
||||
return sha256(concat(DOMAIN, new TextEncoder().encode(a), msgHash));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- keys
|
||||
// Generates both key pairs locally. `seed` (32 bytes) makes the ML-DSA key deterministic (for tests and vectors);
|
||||
// classical keys are always fresh random unless `classicalSecretKey` is supplied.
|
||||
export function generateKeyPair({ alg = 'secp256k1+ml-dsa-65', seed, classicalSecretKey } = {}) {
|
||||
const A = parseAlg(alg);
|
||||
const csk = classicalSecretKey ? fromHex(classicalSecretKey) : A.C.generate();
|
||||
if (csk.length !== A.C.secretKeyBytes) throw new Error(`classical secret key must be ${A.C.secretKeyBytes} bytes`);
|
||||
const s = seed ? fromHex(seed) : randomBytes(32);
|
||||
if (s.length !== 32) throw new Error('seed must be 32 bytes');
|
||||
const k = A.P.impl.keygen(s);
|
||||
return {
|
||||
alg: A.alg,
|
||||
classical: { scheme: A.classical, publicKey: toHex(A.C.publicKey(csk)), secretKey: toHex(csk) },
|
||||
pq: { scheme: A.pq, publicKey: toHex(k.publicKey), secretKey: toHex(k.secretKey), seed: toHex(s) },
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- sign / verify
|
||||
export function sign(message, keys) {
|
||||
const A = parseAlg(keys.alg);
|
||||
const mh = messageHash(message);
|
||||
const ts = toSign(A.alg, mh);
|
||||
const csk = fromHex(keys.classical.secretKey), psk = fromHex(keys.pq.secretKey);
|
||||
const cpk = fromHex(keys.classical.publicKey), ppk = fromHex(keys.pq.publicKey);
|
||||
if (!equal(A.C.publicKey(csk), cpk)) throw new Error('classical public key does not match the secret key');
|
||||
const csig = A.C.sign(ts, csk);
|
||||
const psig = A.P.impl.sign(ts, psk);
|
||||
// a fresh signature that does not verify is a library defect, never something to hand out
|
||||
if (!A.C.verify(csig, ts, cpk) || !A.P.impl.verify(psig, ts, ppk)) throw new Error('fresh hybrid signature does not verify');
|
||||
return {
|
||||
v: VERSION, kind: KIND, alg: A.alg, hash: 'sha256',
|
||||
messageHash: toHex(mh), toSign: toHex(ts),
|
||||
classicalPublicKey: toHex(cpk), classicalSignature: toHex(csig),
|
||||
pqPublicKey: toHex(ppk), pqSignature: toHex(psig),
|
||||
};
|
||||
}
|
||||
|
||||
// Verifies BOTH halves over the recomputed digest of `message`. `valid` is true only when every check holds.
|
||||
export function verify(message, envelope) {
|
||||
const out = { valid: false, classical: false, pq: false, messageHashMatches: false, toSignMatches: false, reason: null };
|
||||
let A;
|
||||
try {
|
||||
if (!envelope || envelope.v !== VERSION || envelope.kind !== KIND || envelope.hash !== 'sha256') { out.reason = 'unknown envelope'; return out; }
|
||||
A = parseAlg(envelope.alg);
|
||||
const mh = messageHash(message), ts = toSign(A.alg, mh);
|
||||
out.messageHashMatches = equal(mh, fromHex(envelope.messageHash));
|
||||
out.toSignMatches = equal(ts, fromHex(envelope.toSign));
|
||||
const cpk = fromHex(envelope.classicalPublicKey), ppk = fromHex(envelope.pqPublicKey);
|
||||
const csig = fromHex(envelope.classicalSignature), psig = fromHex(envelope.pqSignature);
|
||||
if (cpk.length !== A.C.publicKeyBytes || csig.length !== A.C.signatureBytes) { out.reason = 'classical key or signature has the wrong size'; return out; }
|
||||
if (ppk.length !== A.P.publicKeyBytes || psig.length !== A.P.signatureBytes) { out.reason = 'post-quantum key or signature has the wrong size'; return out; }
|
||||
out.classical = A.C.verify(csig, ts, cpk);
|
||||
try { out.pq = A.P.impl.verify(psig, ts, ppk); } catch { out.pq = false; }
|
||||
out.valid = out.classical && out.pq && out.messageHashMatches && out.toSignMatches;
|
||||
if (!out.valid) out.reason = !out.messageHashMatches ? 'message differs from the signed one' : !out.classical && !out.pq ? 'neither half verifies' : !out.classical ? 'classical half does not verify' : !out.pq ? 'post-quantum half does not verify' : 'toSign mismatch';
|
||||
return out;
|
||||
} catch (e) { out.reason = 'malformed envelope: ' + (e.message || e); return out; }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- envelope text forms
|
||||
export function serialize(envelope) { return JSON.stringify(envelope); }
|
||||
export function parse(text) {
|
||||
const e = JSON.parse(text);
|
||||
if (!e || e.kind !== KIND) throw new Error('not an aere-hybrid-signature envelope');
|
||||
return e;
|
||||
}
|
||||
// the digest to notarize when you want an on-chain, post-quantum-anchored first-seen time for this signature
|
||||
// (POST /v1/notarize with this hash; GET /v1/proof/{hash} afterwards)
|
||||
export function envelopeHash(envelope) { return toHex(sha256(new TextEncoder().encode(serialize(envelope)))); }
|
||||
|
||||
// ---------------------------------------------------------------- independent on-chain check of the post-quantum half
|
||||
// `cloud` is an @aere/cloud client (or anything with pqVerify(body)); the chain precompile verifies the ML-DSA
|
||||
// signature over toSign and answers with the block it was computed at. Independent of this library's code.
|
||||
//
|
||||
// FIPS 204 detail, measured on chain 2800 on 2026-09-17: the ML-DSA precompile implements the INTERNAL verify
|
||||
// (Algorithm 8). A standard external signature (this library, Bouncy Castle, AIP-20) is made over
|
||||
// M' = 0x00 || len(ctx) || ctx || M, so the precompile must be handed M' (here: 0x00 0x00 || toSign, empty context).
|
||||
// The gateway does that when asked for the external interface; the raw encoding is exported for other callers.
|
||||
export function precompileMessage(envelope, context = new Uint8Array(0)) {
|
||||
if (context.length > 255) throw new Error('context is at most 255 bytes');
|
||||
return toHex(concat(new Uint8Array([0x00, context.length]), context, fromHex(envelope.toSign)));
|
||||
}
|
||||
export async function verifyOnChain(envelope, cloud) {
|
||||
const A = parseAlg(envelope.alg);
|
||||
const r = await cloud.pqVerify({ scheme: A.P.chainScheme, interface: 'external', publicKey: envelope.pqPublicKey, signature: envelope.pqSignature, message: envelope.toSign });
|
||||
return { pqValidOnChain: r && r.valid === true, precompile: r && r.precompile, block: r && r.block, chainId: r && r.chainId };
|
||||
}
|
||||
Generated
+104
@@ -0,0 +1,104 @@
|
||||
{
|
||||
"name": "@aere/pq-sign",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@aere/pq-sign",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/curves": "^1.2.0",
|
||||
"@noble/hashes": "^1.3.2",
|
||||
"@noble/post-quantum": "^0.6.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/ciphers": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-2.2.0.tgz",
|
||||
"integrity": "sha512-Z6pjIZ/8IJcCGzb2S/0Px5J81yij85xASuk1teLNeg75bfT07MV3a/O2Mtn1I2se43k3lkVEcFaR10N4cgQcZA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 20.19.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/curves": {
|
||||
"version": "1.9.7",
|
||||
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.9.7.tgz",
|
||||
"integrity": "sha512-gbKGcRUYIjA3/zCCNaWDciTMFI0dCkvou3TL8Zmy5Nc7sJ47a0jtOeZoTaMxkuqRo9cRhjOdZJXegxYE5FN/xw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/hashes": "1.8.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.21.3 || >=16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/hashes": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz",
|
||||
"integrity": "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^14.21.3 || >=16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/post-quantum": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@noble/post-quantum/-/post-quantum-0.6.1.tgz",
|
||||
"integrity": "sha512-+pormrDZwjRw05U8ADK4JpHejo87+gBd+muRBB/ozztH5yhDLMDF4jHQWN3NQQAsu1zBNPWTG0ZwVI0CR29H0A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/ciphers": "~2.2.0",
|
||||
"@noble/curves": "~2.2.0",
|
||||
"@noble/hashes": "~2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20.19.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/post-quantum/node_modules/@noble/curves": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-2.2.0.tgz",
|
||||
"integrity": "sha512-T/BoHgFXirb0ENSPBquzX0rcjXeM6Lo892a2jlYJkqk83LqZx0l1Of7DzlKJ6jkpvMrkHSnAcgb5JegL8SeIkQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/hashes": "2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20.19.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/post-quantum/node_modules/@noble/hashes": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.2.0.tgz",
|
||||
"integrity": "sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 20.19.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@aere/pq-sign",
|
||||
"version": "1.0.0",
|
||||
"description": "Hybrid signatures for documents, payloads and API calls: a classical scheme (secp256k1 or Ed25519) and a NIST post-quantum scheme (ML-DSA-44/65/87) over the same digest, verified together. Keys are generated and used only on your side; the ML-DSA half can be re-verified independently by the Aere Network chain precompile.",
|
||||
"type": "module",
|
||||
"main": "index.mjs",
|
||||
"exports": { ".": "./index.mjs" },
|
||||
"files": ["index.mjs", "README.md", "LICENSE"],
|
||||
"scripts": { "test": "node test/pq-sign.test.mjs" },
|
||||
"keywords": ["post-quantum", "ml-dsa", "dilithium", "hybrid-signature", "secp256k1", "ed25519", "aere", "fips-204"],
|
||||
"license": "MIT",
|
||||
"homepage": "https://aere.network/cloud.html",
|
||||
"repository": { "type": "git", "url": "https://git.aere.network/aere-network/aere-pq-sign" },
|
||||
"engines": { "node": ">=18" },
|
||||
"dependencies": {
|
||||
"@noble/curves": "^1.2.0",
|
||||
"@noble/hashes": "^1.3.2",
|
||||
"@noble/post-quantum": "^0.6.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// Probele @aere/pq-sign: fiecare afirmatie cu perechea ei negativa. Offline; cu AERE_CHEIE in mediu ruleaza si
|
||||
// verificarea INDEPENDENTA pe lant a jumatatii post-cuantice (precompila 2800), in ambele sensuri.
|
||||
import assert from 'node:assert';
|
||||
import { generateKeyPair, sign, verify, serialize, parse, envelopeHash, toSign, messageHash, fromHex, toHex, PQ_SCHEMES, CLASSICAL_SCHEMES, verifyOnChain } from '../index.mjs';
|
||||
|
||||
let treceri = 0; const esecuri = [];
|
||||
async function test(nume, fn) {
|
||||
try { await fn(); treceri++; console.log(' OK ' + nume); }
|
||||
catch (e) { esecuri.push(nume); console.log(' ESEC ' + nume + ' — ' + (e.message || e)); }
|
||||
}
|
||||
const flip = (hex, i = -1) => { const b = fromHex(hex); const k = i < 0 ? b.length - 1 : i; b[k] ^= 0x01; return toHex(b); };
|
||||
|
||||
const MSG = 'Invoice 2026-0917: 12,400 EUR payable to Aere Foundation';
|
||||
|
||||
for (const alg of ['secp256k1+ml-dsa-65', 'ed25519+ml-dsa-65', 'secp256k1+ml-dsa-44', 'ed25519+ml-dsa-87']) {
|
||||
const keys = generateKeyPair({ alg });
|
||||
const env = sign(MSG, keys);
|
||||
await test(`${alg}: sign then verify is valid, both halves`, () => {
|
||||
const r = verify(MSG, env);
|
||||
assert.strictEqual(r.valid, true, JSON.stringify(r));
|
||||
assert.strictEqual(r.classical, true); assert.strictEqual(r.pq, true);
|
||||
});
|
||||
await test(`${alg}: sizes are the scheme's (key ${PQ_SCHEMES[alg.split('+')[1]].publicKeyBytes} B, signature ${PQ_SCHEMES[alg.split('+')[1]].signatureBytes} B)`, () => {
|
||||
const P = PQ_SCHEMES[alg.split('+')[1]], C = CLASSICAL_SCHEMES[alg.split('+')[0]];
|
||||
assert.strictEqual(fromHex(env.pqPublicKey).length, P.publicKeyBytes);
|
||||
assert.strictEqual(fromHex(env.pqSignature).length, P.signatureBytes);
|
||||
assert.strictEqual(fromHex(env.classicalSignature).length, C.signatureBytes);
|
||||
assert.strictEqual(fromHex(env.classicalPublicKey).length, C.publicKeyBytes);
|
||||
});
|
||||
await test(`${alg}: one flipped bit in the post-quantum half invalidates the hybrid (classical alone is not enough)`, () => {
|
||||
const r = verify(MSG, { ...env, pqSignature: flip(env.pqSignature) });
|
||||
assert.strictEqual(r.valid, false); assert.strictEqual(r.classical, true); assert.strictEqual(r.pq, false);
|
||||
assert.match(r.reason, /post-quantum half/);
|
||||
});
|
||||
await test(`${alg}: one flipped bit in the classical half invalidates the hybrid (post-quantum alone is not enough)`, () => {
|
||||
const r = verify(MSG, { ...env, classicalSignature: flip(env.classicalSignature, 10) });
|
||||
assert.strictEqual(r.valid, false); assert.strictEqual(r.pq, true); assert.strictEqual(r.classical, false);
|
||||
assert.match(r.reason, /classical half/);
|
||||
});
|
||||
await test(`${alg}: another message is refused by both halves`, () => {
|
||||
const r = verify(MSG + '.', env);
|
||||
assert.strictEqual(r.valid, false); assert.strictEqual(r.messageHashMatches, false);
|
||||
assert.strictEqual(r.classical, false); assert.strictEqual(r.pq, false);
|
||||
});
|
||||
await test(`${alg}: another post-quantum public key is refused`, () => {
|
||||
const alta = generateKeyPair({ alg });
|
||||
const r = verify(MSG, { ...env, pqPublicKey: alta.pq.publicKey });
|
||||
assert.strictEqual(r.valid, false); assert.strictEqual(r.pq, false);
|
||||
});
|
||||
await test(`${alg}: the envelope survives JSON and its digest is stable`, () => {
|
||||
const back = parse(serialize(env));
|
||||
assert.deepStrictEqual(back, env);
|
||||
assert.strictEqual(verify(MSG, back).valid, true);
|
||||
assert.strictEqual(envelopeHash(back), envelopeHash(env));
|
||||
assert.match(envelopeHash(env), /^0x[0-9a-f]{64}$/);
|
||||
});
|
||||
}
|
||||
|
||||
await test('the signed digest binds domain, algorithm and message: same message under another alg has another toSign', () => {
|
||||
const mh = messageHash(MSG);
|
||||
assert.notStrictEqual(toHex(toSign('secp256k1+ml-dsa-65', mh)), toHex(toSign('ed25519+ml-dsa-65', mh)));
|
||||
assert.strictEqual(toHex(toSign('secp256k1+ml-dsa-65', mh)), toHex(toSign('secp256k1+ml-dsa-65', mh)));
|
||||
});
|
||||
await test('a deterministic seed gives the same post-quantum key (vectors), classical keys stay fresh', () => {
|
||||
const seed = '0x' + '11'.repeat(32);
|
||||
const a = generateKeyPair({ seed }), b = generateKeyPair({ seed });
|
||||
assert.strictEqual(a.pq.publicKey, b.pq.publicKey);
|
||||
assert.notStrictEqual(a.classical.publicKey, b.classical.publicKey);
|
||||
});
|
||||
await test('a mismatched classical key pair is refused at signing time', () => {
|
||||
const k = generateKeyPair(); const alt = generateKeyPair();
|
||||
assert.throws(() => sign(MSG, { ...k, classical: { ...k.classical, publicKey: alt.classical.publicKey } }), /does not match/);
|
||||
});
|
||||
await test('an unknown algorithm pair is refused', () => {
|
||||
assert.throws(() => generateKeyPair({ alg: 'rsa+ml-dsa-65' }), /unknown alg/);
|
||||
const r = verify(MSG, { v: 1, kind: 'aere-hybrid-signature', hash: 'sha256', alg: 'secp256k1+sphincs' });
|
||||
assert.strictEqual(r.valid, false); assert.match(r.reason, /malformed|unknown/);
|
||||
});
|
||||
await test('a foreign envelope is refused without throwing', () => {
|
||||
const r = verify(MSG, { v: 2, kind: 'jws' });
|
||||
assert.strictEqual(r.valid, false); assert.strictEqual(r.reason, 'unknown envelope');
|
||||
});
|
||||
await test('binary messages sign and verify like text', () => {
|
||||
const k = generateKeyPair(); const m = new Uint8Array([0, 255, 1, 2, 3, 254]);
|
||||
assert.strictEqual(verify(m, sign(m, k)).valid, true);
|
||||
assert.strictEqual(verify(new Uint8Array([0, 255, 1, 2, 3, 253]), sign(m, k)).valid, false);
|
||||
});
|
||||
|
||||
// optional: the chain precompile judges the ML-DSA half, independently of this code, in both directions.
|
||||
// The key comes from AERE_CHEIE or is read by this process from the file named in AERE_CHEIE_FISIER (never echoed).
|
||||
const CHEIE = process.env.AERE_CHEIE || (process.env.AERE_CHEIE_FISIER ? (await import('node:fs')).readFileSync(process.env.AERE_CHEIE_FISIER, 'utf8').trim() : '');
|
||||
if (CHEIE) {
|
||||
const { AereCloud } = await import('../../aere-cloud-sdk/index.mjs');
|
||||
const cloud = new AereCloud({ apiKey: CHEIE });
|
||||
const keys = generateKeyPair({ alg: 'secp256k1+ml-dsa-44' });
|
||||
const env = sign(MSG, keys);
|
||||
await test('on chain (precompile 0x...0ae3): the post-quantum half of a fresh hybrid signature verifies', async () => {
|
||||
const r = await verifyOnChain(env, cloud);
|
||||
assert.strictEqual(r.pqValidOnChain, true, JSON.stringify(r)); assert.ok(r.block > 0);
|
||||
});
|
||||
await test('on chain: one flipped bit in the post-quantum half is refused by the precompile', async () => {
|
||||
const r = await verifyOnChain({ ...env, pqSignature: flip(env.pqSignature) }, cloud);
|
||||
assert.strictEqual(r.pqValidOnChain, false, JSON.stringify(r));
|
||||
});
|
||||
} else console.log(' (sarit) verificarea pe lant a jumatatii ML-DSA: pune AERE_CHEIE in mediu');
|
||||
|
||||
console.log(`\n${treceri} treceri, ${esecuri.length} esecuri`);
|
||||
if (esecuri.length) process.exitCode = 1;
|
||||
Reference in new issue
Block a user