sign every write as an MMUR2 claim (POST /api/claims); the guessed title is parsedTitle
Build and Push Docker Image / build (push) Successful in 47s

This commit is contained in:
Worph
2026-10-25 17:36:44 +00:00
parent 8194541f1c
commit ecb30e1633
7 changed files with 597 additions and 52 deletions
+50
View File
@@ -0,0 +1,50 @@
/**
* MMUR2 conformance of the shared meta-core-client.ts against meta-core's
* golden vectors (test/claim-vectors.json, canonical copy in meta-core
* internal/claim/testdata). Node signs with a random nonce, so our own
* signatures cannot equal sigHex — they must verify and be low-S instead.
*/
import { describe, it, expect } from 'vitest';
import { readFileSync } from 'fs';
import { signedBytes, verifyClaim, ClaimSigner, type ClaimValue } from '../src/meta-core-client.js';
const f = JSON.parse(readFileSync(new URL('./claim-vectors.json', import.meta.url), 'utf8'));
const HALF_N = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141') >> 1n;
const valueOf = (v: { value?: string | null; valueBytesHex?: string }): ClaimValue =>
v.valueBytesHex ? Buffer.from(v.valueBytesHex, 'hex') : (v.value ?? null);
describe('MMUR2 claim vectors', () => {
const signer = new ClaimSigner(f.privateKeyHex);
it('derives the vector uid from the test key', () => {
expect(signer.uid).toBe(f.uid);
});
for (const v of f.vectors) {
it(`${v.name}: canonical bytes, reference signature, own signature`, () => {
const value = valueOf(v);
expect(signedBytes(v.cid, v.uid, v.key, value, v.ts).toString('hex')).toBe(v.signedBytesHex);
expect(verifyClaim({ cid: v.cid, uid: v.uid, key: v.key, value, ts: v.ts, sig: Buffer.from(v.sigHex, 'hex') })).toBe(true);
const own = signer.sign(v.cid, v.key, value, v.ts);
expect(verifyClaim(own)).toBe(true);
expect(BigInt('0x' + Buffer.from(own.sig).subarray(32).toString('hex')) <= HALF_N).toBe(true);
});
}
it('refuses the high-S twin of a valid signature', () => {
const v = f.vectors.find((x: { name: string }) => x.name === f.highS.vector);
expect(verifyClaim({ cid: v.cid, uid: v.uid, key: v.key, value: valueOf(v), ts: v.ts, sig: Buffer.from(f.highS.sigHex, 'hex') })).toBe(false);
});
it('refuses a tampered value', () => {
const c = signer.sign('bafy', 'title', 'A');
expect(verifyClaim({ ...c, value: 'B' })).toBe(false);
});
it('issues strictly increasing ts', () => {
const a = signer.nextTs();
expect(signer.nextTs()).toBeGreaterThan(a);
});
});