From c279f61f091d9d424c4be1dd171931b0728a1eee Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 12:43:27 -0700 Subject: [PATCH 1/8] fix(codes): renumber the post-quantum codes to the reopened CESR PR The post-quantum rows added in WebOfTrust/signify-ts#413 followed trustoverip/kswg-cesr-specification#165, which was merged before review and then reverted. The work reopened as trustoverip/kswg-cesr-specification#185, which drops FN-DSA and renumbers the master table. That left this table assigning many codes to a different primitive than the reopened PR does: 1AAR was an FN-DSA-512 signature here and is the ML-DSA-87 verification key there, and 2AAA was the FN-DSA-1024 key here and is the ML-DSA-44 signature there. Anything emitted under the new codes would have been misframed. The 27 rows now match the reopened PR in code, description, full size and lead size. The six codes past its end (1AAc, 1AAd, 2AAL to 2AAO) are gone, and a test pins their absence so a stale row cannot keep accepting a code no draft defines. The codes stay provisional until that PR merges. The size tests now check every row against the FIPS 204 and FIPS 205 raw sizes rather than against Falcon's. The Falcon exhibit is replaced by an ML-DSA-44 receipt over the same inception: a real keypair and a signature over the receipted event's bytes, generated with @noble/post-quantum 0.7.1, whose key (3AAA) and signature (2AAA) exercise both lead-byte selectors. The indexed signature codes proposed in trustoverip/kswg-cesr-specification#186 are not added. Indexer's raw-size checks ignore the lead size, so no indexed code with lead bytes round-trips through it today; that needs a change to Indexer, not a table row. Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- src/keri/core/matter.ts | 59 ++++++-------- test/core/pq.test.ts | 170 +++++++++++++++++++++------------------- 2 files changed, 115 insertions(+), 114 deletions(-) diff --git a/src/keri/core/matter.ts b/src/keri/core/matter.ts index d367944b..47869f8b 100644 --- a/src/keri/core/matter.ts +++ b/src/keri/core/matter.ts @@ -165,40 +165,33 @@ export class Matter { '1AAH': new Sizage(4, 0, 100, 0), '1AAI': new Sizage(4, 0, 48, 0), '1AAJ': new Sizage(4, 0, 48, 0), - // CESR 1.1 post-quantum codes. Every post-quantum primitive is - // large — the smallest signature here is 666 B and the largest - // 29,792 B — so the spec requires them all in the four-character - // fixed tables rather than spending scarce one- and two-character - // entries. The selector fixes the lead size: 1 -> 0, 2 -> 1, 3 -> 2. - '1AAQ': new Sizage(4, 0, 1200, 0), // FN-DSA-512 public verification key, 897 B - '1AAR': new Sizage(4, 0, 892, 0), // FN-DSA-512 signature, 666 B - '1AAS': new Sizage(4, 0, 3460, 0), // ML-DSA-87 public verification key, 2592 B - '1AAT': new Sizage(4, 0, 4416, 0), // ML-DSA-65 signature, 3309 B + // Post-quantum codes, following trustoverip/kswg-cesr-specification + // #185 (provisional until it merges). Every post-quantum primitive + // sits in the four-character fixed tables, and the raw size mod 3 + // picks the selector: 1 -> no lead byte, 2 -> one, 3 -> two. + '1AAQ': new Sizage(4, 0, 4416, 0), // ML-DSA-65 signature, 3309 B + '1AAR': new Sizage(4, 0, 3460, 0), // ML-DSA-87 public verification key, 2592 B + '1AAS': new Sizage(4, 0, 68, 0), // Seed of SLH-DSA-SHA2-128s private key, 48 B + '1AAT': new Sizage(4, 0, 68, 0), // Seed of SLH-DSA-SHAKE-128s private key, 48 B '1AAU': new Sizage(4, 0, 68, 0), // SLH-DSA-SHA2-192s public verification key, 48 B - '1AAV': new Sizage(4, 0, 68, 0), // SLH-DSA-SHAKE-192s public verification key, 48 B - '1AAW': new Sizage(4, 0, 21636, 0), // SLH-DSA-SHA2-192s signature, 16224 B - '1AAX': new Sizage(4, 0, 21636, 0), // SLH-DSA-SHAKE-192s signature, 16224 B - '1AAY': new Sizage(4, 0, 68, 0), // Seed of SLH-DSA-SHA2-128s private key, 48 B - '1AAZ': new Sizage(4, 0, 68, 0), // Seed of SLH-DSA-SHAKE-128s private key, 48 B - '1AAa': new Sizage(4, 0, 100, 0), // Seed of SLH-DSA-SHA2-192s private key, 72 B - '1AAb': new Sizage(4, 0, 100, 0), // Seed of SLH-DSA-SHAKE-192s private key, 72 B - '1AAc': new Sizage(4, 0, 132, 0), // Seed of SLH-DSA-SHA2-256s private key, 96 B - '1AAd': new Sizage(4, 0, 132, 0), // Seed of SLH-DSA-SHAKE-256s private key, 96 B - '2AAA': new Sizage(4, 0, 2396, 1), // FN-DSA-1024 public verification key, 1793 B - '2AAB': new Sizage(4, 0, 1712, 1), // FN-DSA-1024 signature, 1280 B - '2AAC': new Sizage(4, 0, 48, 1), // Seed of FN-DSA-512 private key, 32 B - '2AAD': new Sizage(4, 0, 48, 1), // Seed of FN-DSA-1024 private key, 32 B - '2AAE': new Sizage(4, 0, 2608, 1), // ML-DSA-65 public verification key, 1952 B - '2AAF': new Sizage(4, 0, 3232, 1), // ML-DSA-44 signature, 2420 B - '2AAG': new Sizage(4, 0, 48, 1), // Seed of ML-DSA-44 private key, 32 B - '2AAH': new Sizage(4, 0, 48, 1), // Seed of ML-DSA-65 private key, 32 B - '2AAI': new Sizage(4, 0, 48, 1), // Seed of ML-DSA-87 private key, 32 B - '2AAJ': new Sizage(4, 0, 48, 1), // SLH-DSA-SHA2-128s public verification key, 32 B - '2AAK': new Sizage(4, 0, 48, 1), // SLH-DSA-SHAKE-128s public verification key, 32 B - '2AAL': new Sizage(4, 0, 10480, 1), // SLH-DSA-SHA2-128s signature, 7856 B - '2AAM': new Sizage(4, 0, 10480, 1), // SLH-DSA-SHAKE-128s signature, 7856 B - '2AAN': new Sizage(4, 0, 39728, 1), // SLH-DSA-SHA2-256s signature, 29792 B - '2AAO': new Sizage(4, 0, 39728, 1), // SLH-DSA-SHAKE-256s signature, 29792 B + '1AAV': new Sizage(4, 0, 21636, 0), // SLH-DSA-SHA2-192s signature, 16224 B + '1AAW': new Sizage(4, 0, 100, 0), // Seed of SLH-DSA-SHA2-192s private key, 72 B + '1AAX': new Sizage(4, 0, 68, 0), // SLH-DSA-SHAKE-192s public verification key, 48 B + '1AAY': new Sizage(4, 0, 21636, 0), // SLH-DSA-SHAKE-192s signature, 16224 B + '1AAZ': new Sizage(4, 0, 100, 0), // Seed of SLH-DSA-SHAKE-192s private key, 72 B + '1AAa': new Sizage(4, 0, 132, 0), // Seed of SLH-DSA-SHA2-256s private key, 96 B + '1AAb': new Sizage(4, 0, 132, 0), // Seed of SLH-DSA-SHAKE-256s private key, 96 B + '2AAA': new Sizage(4, 0, 3232, 1), // ML-DSA-44 signature, 2420 B + '2AAB': new Sizage(4, 0, 48, 1), // Seed of ML-DSA-44 private key, 32 B + '2AAC': new Sizage(4, 0, 2608, 1), // ML-DSA-65 public verification key, 1952 B + '2AAD': new Sizage(4, 0, 48, 1), // Seed of ML-DSA-65 private key, 32 B + '2AAE': new Sizage(4, 0, 48, 1), // Seed of ML-DSA-87 private key, 32 B + '2AAF': new Sizage(4, 0, 48, 1), // SLH-DSA-SHA2-128s public verification key, 32 B + '2AAG': new Sizage(4, 0, 10480, 1), // SLH-DSA-SHA2-128s signature, 7856 B + '2AAH': new Sizage(4, 0, 48, 1), // SLH-DSA-SHAKE-128s public verification key, 32 B + '2AAI': new Sizage(4, 0, 10480, 1), // SLH-DSA-SHAKE-128s signature, 7856 B + '2AAJ': new Sizage(4, 0, 39728, 1), // SLH-DSA-SHA2-256s signature, 29792 B + '2AAK': new Sizage(4, 0, 39728, 1), // SLH-DSA-SHAKE-256s signature, 29792 B '3AAA': new Sizage(4, 0, 1756, 2), // ML-DSA-44 public verification key, 1312 B '3AAB': new Sizage(4, 0, 6176, 2), // ML-DSA-87 signature, 4627 B '3AAC': new Sizage(4, 0, 92, 2), // SLH-DSA-SHA2-256s public verification key, 64 B diff --git a/test/core/pq.test.ts b/test/core/pq.test.ts index 1a8cc284..7d794805 100644 --- a/test/core/pq.test.ts +++ b/test/core/pq.test.ts @@ -6,51 +6,47 @@ import { type Primitive, } from '../../src/keri/core/parsing.ts'; -/* CESR 1.1 post-quantum codes. +/* Post-quantum codes, following trustoverip/kswg-cesr-specification #185. * - * The spec places all 33 post-quantum primitives in the four-character fixed - * tables, because every one of them is large — the smallest signature is 666 B - * and the largest 29,792 B — so a four-character code costs under half a - * percent of the encoding. These tests check the table against arithmetic the - * spec makes checkable, and then against real cryptography. */ + * #185 places all 27 ML-DSA and SLH-DSA primitives in the four-character fixed + * tables, because they are large: the smallest public key in them is 1,312 B + * and the largest signature 29,792 B, so a four-character code costs under a + * quarter of a percent of the encoding. These tests check the table against + * arithmetic the spec makes checkable, against the FIPS 204 and 205 parameter + * sets, and then against real cryptography. */ const bytesOf = (s: string) => new TextEncoder().encode(s); -/** Every post-quantum code, with its full size and its lead size. */ -const PQ: Array<[string, number, number]> = [ - ['1AAQ', 1200, 0], // FN-DSA-512 public verification key - ['1AAR', 892, 0], // FN-DSA-512 signature - ['1AAS', 3460, 0], // ML-DSA-87 public verification key - ['1AAT', 4416, 0], // ML-DSA-65 signature - ['1AAU', 68, 0], // SLH-DSA-SHA2-192s public verification key - ['1AAV', 68, 0], // SLH-DSA-SHAKE-192s public verification key - ['1AAW', 21636, 0], // SLH-DSA-SHA2-192s signature - ['1AAX', 21636, 0], // SLH-DSA-SHAKE-192s signature - ['1AAY', 68, 0], // Seed of SLH-DSA-SHA2-128s private key - ['1AAZ', 68, 0], // Seed of SLH-DSA-SHAKE-128s private key - ['1AAa', 100, 0], // Seed of SLH-DSA-SHA2-192s private key - ['1AAb', 100, 0], // Seed of SLH-DSA-SHAKE-192s private key - ['1AAc', 132, 0], // Seed of SLH-DSA-SHA2-256s private key - ['1AAd', 132, 0], // Seed of SLH-DSA-SHAKE-256s private key - ['2AAA', 2396, 1], // FN-DSA-1024 public verification key - ['2AAB', 1712, 1], // FN-DSA-1024 signature - ['2AAC', 48, 1], // Seed of FN-DSA-512 private key - ['2AAD', 48, 1], // Seed of FN-DSA-1024 private key - ['2AAE', 2608, 1], // ML-DSA-65 public verification key - ['2AAF', 3232, 1], // ML-DSA-44 signature - ['2AAG', 48, 1], // Seed of ML-DSA-44 private key - ['2AAH', 48, 1], // Seed of ML-DSA-65 private key - ['2AAI', 48, 1], // Seed of ML-DSA-87 private key - ['2AAJ', 48, 1], // SLH-DSA-SHA2-128s public verification key - ['2AAK', 48, 1], // SLH-DSA-SHAKE-128s public verification key - ['2AAL', 10480, 1], // SLH-DSA-SHA2-128s signature - ['2AAM', 10480, 1], // SLH-DSA-SHAKE-128s signature - ['2AAN', 39728, 1], // SLH-DSA-SHA2-256s signature - ['2AAO', 39728, 1], // SLH-DSA-SHAKE-256s signature - ['3AAA', 1756, 2], // ML-DSA-44 public verification key - ['3AAB', 6176, 2], // ML-DSA-87 signature - ['3AAC', 92, 2], // SLH-DSA-SHA2-256s public verification key - ['3AAD', 92, 2], // SLH-DSA-SHAKE-256s public verification key +/** Every post-quantum code, with its full size, its lead size, and the raw + * size FIPS 204 or FIPS 205 gives for that primitive. */ +const PQ: Array<[string, number, number, number]> = [ + ['1AAQ', 4416, 0, 3309], // ML-DSA-65 signature + ['1AAR', 3460, 0, 2592], // ML-DSA-87 public verification key + ['1AAS', 68, 0, 48], // Seed of SLH-DSA-SHA2-128s private key + ['1AAT', 68, 0, 48], // Seed of SLH-DSA-SHAKE-128s private key + ['1AAU', 68, 0, 48], // SLH-DSA-SHA2-192s public verification key + ['1AAV', 21636, 0, 16224], // SLH-DSA-SHA2-192s signature + ['1AAW', 100, 0, 72], // Seed of SLH-DSA-SHA2-192s private key + ['1AAX', 68, 0, 48], // SLH-DSA-SHAKE-192s public verification key + ['1AAY', 21636, 0, 16224], // SLH-DSA-SHAKE-192s signature + ['1AAZ', 100, 0, 72], // Seed of SLH-DSA-SHAKE-192s private key + ['1AAa', 132, 0, 96], // Seed of SLH-DSA-SHA2-256s private key + ['1AAb', 132, 0, 96], // Seed of SLH-DSA-SHAKE-256s private key + ['2AAA', 3232, 1, 2420], // ML-DSA-44 signature + ['2AAB', 48, 1, 32], // Seed of ML-DSA-44 private key + ['2AAC', 2608, 1, 1952], // ML-DSA-65 public verification key + ['2AAD', 48, 1, 32], // Seed of ML-DSA-65 private key + ['2AAE', 48, 1, 32], // Seed of ML-DSA-87 private key + ['2AAF', 48, 1, 32], // SLH-DSA-SHA2-128s public verification key + ['2AAG', 10480, 1, 7856], // SLH-DSA-SHA2-128s signature + ['2AAH', 48, 1, 32], // SLH-DSA-SHAKE-128s public verification key + ['2AAI', 10480, 1, 7856], // SLH-DSA-SHAKE-128s signature + ['2AAJ', 39728, 1, 29792], // SLH-DSA-SHA2-256s signature + ['2AAK', 39728, 1, 29792], // SLH-DSA-SHAKE-256s signature + ['3AAA', 1756, 2, 1312], // ML-DSA-44 public verification key + ['3AAB', 6176, 2, 4627], // ML-DSA-87 signature + ['3AAC', 92, 2, 64], // SLH-DSA-SHA2-256s public verification key + ['3AAD', 92, 2, 64], // SLH-DSA-SHAKE-256s public verification key ]; /** Every node in an attachment forest, groups and primitives alike. */ @@ -58,18 +54,30 @@ const nodes = (n: AttachmentNode): AttachmentNode[] => n.kind === 'group' ? [n, ...n.items.flatMap(nodes)] : [n]; /** A CESR-1 stream: an Ed25519 inception, then a receipt of it whose witness - * signs with post-quantum Falcon. Generated by cesrview's - * scripts/make-falcon-sample.mjs from @noble/post-quantum — the FN-DSA-512 - * keypair is real and the signature is over the receipted event's exact bytes, - * so it verifies. signify-ts cannot check that here (it ships no Falcon - * implementation), but it can FRAME it, which is what these codes are for. */ -const FALCON_RECEIPT = - '{"v":"KERI10JSON0000fd_","t":"icp","d":"ECkqcQR_6_BzwC89QNM4OJnSwi3FDC62lo9ALKobHDe8","i":"BDVHH3ix0_aawmzCf-IBLdRe2UiFGCxEdXFuiecqyLEy","s":"0","kt":"1","k":["BDVHH3ix0_aawmzCf-IBLdRe2UiFGCxEdXFuiecqyLEy"],"nt":"0","n":[],"bt":"0","b":[],"c":[],"a":[]}{"v":"KERI10JSON000091_","t":"rct","d":"ECkqcQR_6_BzwC89QNM4OJnSwi3FDC62lo9ALKobHDe8","i":"BDVHH3ix0_aawmzCf-IBLdRe2UiFGCxEdXFuiecqyLEy","s":"0"}-CAB1AAQCQSYetAzLotj4VXDBKrzaYHHEePl0m4ROnIUpZCmhBUqSwcAuCQ7ObSuo6dOAlvHlt0DBNV1W9ezH8IDsofPULNgODfTaC2n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IhAIhhVgaNEjOl0Zc41-1AAROX0FWKNW_m3Y1iRbg9hwfgdSjN10_hXmf58brBxXVClJ-mGCCfkAFHpN1KBKr0kYYR4ufwEKcTUO2PLftOwyVpawJONU5J6fjmY8GRopOpKVTRfzrsveMCvudZhMfMrjRMVl4XL8YgG4jCCRdsWkSF58ig6txHRUJU8lNyEEElPHUBiUbhzd9rDoFbeR1kqal3KK_C5W3ZounAx5zeZRKzlykYf2Uu8xDNuFe3e_mbQguld_m000cp01T0raLvQZLzpqciI5mZqbVu5mcNrU4Yz-SU0jJt7FxdlKbuXxRdVHwRB5NH2oY4kbD5EodFTyt-OrpEvFj23JbtMmS4GpNflrsw-ier5urUd5GkyIF4iAIlLk7c7Nmc3eEj2FJwKcurdKwShpoSe7d69EHZcampoR4lKPlctegPdXUv2yN62Y69PFZS5TXQKahF16OI-DhzBaVJruom2ONgeUlqF-KZNgsNf7yWlGQa3aNvY8SOkw2GzZV_FF3p6aD86rdpv5U4e49r3NSu0S5DnwNx2GRzLHL3Dt58yKsqrN0qhzYQE3PdSdqukj5HCWwTZUnRVba-J5ShZnQKcp22fJG5O1pmWHkGOw_3zyXufPBNhkUyixaq1I5Db8mluq5HeocWscHQJHyRtBF1qt0aw7cOYh5uOK-NfzrJQBKCZaF2zh_525a2nxpuiUDMTSsWZGtmqMTkWtpS09rgUVD_hBDqPfW1Nj7PcEdSldB3myaFAfhOSQXiotG1rOEC8KqP1dG01uGKBLj9ZeI2NiLj3X5HtwNMTX2NR-uLtp9TWSS5AchhJBKWYffXMfAKiJyyx4pGRtbcy3Wig8eyIhnWgfKYVq61ECOmkTJrPS6aZVmhGFafQ29AAAAAAAAAAA'; + * signs with ML-DSA-44. The inception and receipt bodies are the ones cesrview's + * scripts/make-falcon-sample.mjs produced; the couple was generated with + * @noble/post-quantum 0.7.1's ml_dsa44, so the keypair is real and the + * signature is over the receipted event's exact bytes and verifies. signify-ts + * cannot check that here (it ships no ML-DSA implementation), but it can FRAME + * it, which is what these codes are for. The key and signature also exercise + * both lead-byte selectors: the key is 3AAA, two lead bytes, and the signature + * 2AAA, one. */ +const MLDSA_RECEIPT = + '{"v":"KERI10JSON0000fd_","t":"icp","d":"ECkqcQR_6_BzwC89QNM4OJnSwi3FDC62lo9ALKobHDe8","i":"BDVHH3ix0_aawmzCf-IBLdRe2UiFGCxEdXFuiecqyLEy","s":"0","kt":"1","k":["BDVHH3ix0_aawmzCf-IBLdRe2UiFGCxEdXFuiecqyLEy"],"nt":"0","n":[],"bt":"0","b":[],"c":[],"a":[]}{"v":"KERI10JSON000091_","t":"rct","d":"ECkqcQR_6_BzwC89QNM4OJnSwi3FDC62lo9ALKobHDe8","i":"BDVHH3ix0_aawmzCf-IBLdRe2UiFGCxEdXFuiecqyLEy","s":"0"}-CAB3AAAAAD6rq6FUWGB_YG2a-wivDNooA4AfoSlxIrd826C7OaALeuynSuRZz1sBW3pdDw41XfYD5sG-hgI9RlANgY36uDlsvXPcD6E8gbLk9l8OdPkxKkdxNGZ3-hSbK7w04yMsSMbJ25G5qkR4bYjGdl8Dtju3eNbz8HjkhWHNB6Tf0zv8XcYKrszTGGS16opnxh42-XwYjxaYNs8yJ03AILTqexrN2mawiHcBv3BHFxzz5WYqPGmg0-8nj7xoPGcVbt6SKxbo6uxbfon02hZB5YdrpVdkQXWyC_bZegUxL8Cw2ZBqbeY9ahUTL2Z7s57dEtZghpcP43F8WsugPGuQzYT8t6q7ZJiBnLqgW74FOTuHEK13dGy6aCMh0301qN0cHiu_ymzCo9le4_2j0TECRFibNzUI91CSt1-gEOXTGVKHp4I7_6RvkWi90lzT-Uob5KkkbL_LWMbKiym0P3UC2jkxg02eHdDMO2k4N5lQ12-8i0rzX8T-5iICE_wYzTUgUMNJ7K4plDug3T8TCrqivHrEYBJEdkRnBQ28xTVuy0SMANZ5Uqm-JOVqeIlnUHCarMqXKADlXbg7CNYhnRi6gdciAKGBmTi5ZdMtetXIncblOo8z1OxwiaV0mZVNMlocdqVbYz1QzdR6sVqROJyLH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AAAAAAAAAAARIS4-'; describe('post-quantum codes — the table is arithmetically self-checking', () => { - it('carries the 33 codes CESR 1.1 defines', () => { + it('carries the 27 codes #185 defines', () => { const present = PQ.filter(([code]) => Matter.Sizes.has(code)); - assert.equal(present.length, 33); + assert.equal(present.length, 27); + }); + + it('drops the codes the reverted #165 table used past the end of #185', () => { + // #165 assigned FN-DSA codes and so ran to 1AAd and 2AAO; #185 has no + // FN-DSA and ends at 1AAb and 2AAK. A stale row left behind would + // accept a code no spec defines. + for (const code of ['1AAc', '1AAd', '2AAL', '2AAM', '2AAN', '2AAO']) { + assert.isFalse(Matter.Sizes.has(code), `${code}: still present`); + } }); it('sizes every code consistently with its selector and CESR encoding', () => { @@ -128,33 +136,32 @@ describe('post-quantum codes — the table is arithmetically self-checking', () } }); - it('sizes the Falcon codes to the FN-DSA parameter sets exactly', () => { - // Independent ground truth: FIPS 206 and the Falcon submission, not the + it('sizes every code to its FIPS 204 or FIPS 205 parameter set exactly', () => { + // Independent ground truth: the raw sizes in the FIPS standards, not the // CESR table this is checking. - const raw = (code: string) => { + for (const [code, , , bytes] of PQ) { const s = Matter.Sizes.get(code)!; - return ((s.fs! - 4) * 3) / 4 - s.ls!; - }; - assert.equal(raw('1AAQ'), 897); // FN-DSA-512 public key - assert.equal(raw('1AAR'), 666); // FN-DSA-512 signature, the PADDED variant - assert.equal(raw('2AAA'), 1793); // FN-DSA-1024 public key - assert.equal(raw('2AAB'), 1280); // FN-DSA-1024 signature + assert.equal( + ((s.fs! - 4) * 3) / 4 - s.ls!, + bytes, + `${code}: raw size differs from the FIPS parameter set` + ); + } }); - it('gives 2AAA and 3AAA their CESR 1.1 meanings, replacing two dead placeholders', () => { - // These rows previously held Sizage(4, 0, 8, 1) and Sizage(4, 0, 8, 2): - // vestigial test placeholders from a keripy that no longer exists — - // keripy has used 2___ and 3___ for that purpose at every version, and - // nothing in this codebase referenced them. Pinned here because it is - // the one change in this commit that alters an existing row. - assert.equal(Matter.Sizes.get('2AAA')!.fs, 2396); - assert.equal(Matter.Sizes.get('3AAA')!.fs, 1756); + it('gives 2AAA and 3AAA their post-quantum meanings, replacing two dead placeholders', () => { + // Before the post-quantum codes these rows held Sizage(4, 0, 8, 1) and + // Sizage(4, 0, 8, 2): vestigial test placeholders from a keripy that no + // longer exists, referenced nowhere in this codebase. Pinned here + // because these are the two rows whose meaning changed. + assert.equal(Matter.Sizes.get('2AAA')!.fs, 3232); // ML-DSA-44 signature + assert.equal(Matter.Sizes.get('3AAA')!.fs, 1756); // ML-DSA-44 public key }); }); -describe('post-quantum codes — parsing a real Falcon stream', () => { +describe('post-quantum codes — parsing a real ML-DSA stream', () => { it('frames the exhibit end to end with nothing left over', () => { - const bytes = bytesOf(FALCON_RECEIPT); + const bytes = bytesOf(MLDSA_RECEIPT); const { messages, errors, consumed } = parse(bytes); assert.deepStrictEqual(errors, []); assert.equal(consumed, bytes.length); // delta 0 @@ -164,28 +171,29 @@ describe('post-quantum codes — parsing a real Falcon stream', () => { ); }); - it('decomposes the receipt into a Falcon key and a Falcon signature', () => { - const { messages } = parse(bytesOf(FALCON_RECEIPT)); + it('decomposes the receipt into an ML-DSA-44 key and signature', () => { + const { messages } = parse(bytesOf(MLDSA_RECEIPT)); const group = messages[1].attachments[0]; assert.equal(group.code, '-C'); assert.equal(group.state, 'known'); const items = group.items as Primitive[]; assert.deepStrictEqual( items.map((p) => p.code), - ['1AAQ', '1AAR'] + ['3AAA', '2AAA'] ); // Byte-exact: the couple tiles the group with no gap and no overhang. - assert.equal(items[0].span.end - items[0].span.start, 1200); - assert.equal(items[1].span.end - items[1].span.start, 892); + assert.equal(items[0].span.end - items[0].span.start, 1756); + assert.equal(items[1].span.end - items[1].span.start, 3232); assert.equal(items[0].span.start, group.span.start + 4); // past the -C header assert.equal(items[1].span.end, group.span.end); }); it('never frames a post-quantum signature as an INDEXED signature', () => { - // CESR 1.1 defines no indexed post-quantum code, so no post-quantum - // primitive may ever resolve through the Indexer table. A comment would - // not fail if someone later added one. - const all = parse(bytesOf(FALCON_RECEIPT)).messages.flatMap((m) => + // signify-ts does not yet carry the indexed post-quantum codes that + // kswg-cesr-specification #186 proposes, so no post-quantum primitive + // may resolve through the Indexer table. A comment would not fail if + // someone later added one without the Indexer support it needs. + const all = parse(bytesOf(MLDSA_RECEIPT)).messages.flatMap((m) => m.attachments.flatMap(nodes) ); assert.deepStrictEqual( @@ -195,15 +203,15 @@ describe('post-quantum codes — parsing a real Falcon stream', () => { // The same rule at the framing layer: a -A group's members are Indexer // primitives, so a post-quantum code there must not resolve, however // well it would resolve as Matter. - const icp = FALCON_RECEIPT.slice(0, 253); + const icp = MLDSA_RECEIPT.slice(0, 253); const { errors } = parse( - bytesOf(icp + '-AAB' + '1AAR' + 'A'.repeat(888)) + bytesOf(icp + '-AAB' + '1AAQ' + 'A'.repeat(4412)) ); assert.equal(errors[0].code, 'unframable-group'); }); it('reports a truncated post-quantum primitive as incomplete, not malformed', () => { - const bytes = bytesOf(FALCON_RECEIPT); + const bytes = bytesOf(MLDSA_RECEIPT); const { messages, errors } = parse(bytes.slice(0, bytes.length - 40)); assert.equal(messages.length, 1); // the icp survives; the receipt waits assert.equal(errors[0].code, 'incomplete'); From 80197263c24d5064d03a285e4e89c372942957b3 Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 12:49:08 -0700 Subject: [PATCH 2/8] test(pq): claim only what the post-quantum tests check A hostile review (codex) found three comments in the post-quantum tests overstating them. The header said the smallest public key is 1,312 B, which holds for ML-DSA but not for the 32 to 64 B SLH-DSA keys; it said the tests check real cryptography, when they frame a real key and signature but cannot verify it; and the -A test said it would catch a future indexed code, when it only shows that a Matter code does not resolve as Indexer. Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- test/core/pq.test.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/core/pq.test.ts b/test/core/pq.test.ts index 7d794805..54f58e8a 100644 --- a/test/core/pq.test.ts +++ b/test/core/pq.test.ts @@ -9,11 +9,13 @@ import { /* Post-quantum codes, following trustoverip/kswg-cesr-specification #185. * * #185 places all 27 ML-DSA and SLH-DSA primitives in the four-character fixed - * tables, because they are large: the smallest public key in them is 1,312 B - * and the largest signature 29,792 B, so a four-character code costs under a - * quarter of a percent of the encoding. These tests check the table against - * arithmetic the spec makes checkable, against the FIPS 204 and 205 parameter - * sets, and then against real cryptography. */ + * tables. Its signatures and lattice-based public keys are large, from 1,312 B + * to 29,792 B, so a four-character code costs them under a quarter of a percent + * of the encoding; the small seeds and SLH-DSA keys go in the same tables so + * that each family is dispatched through one place. These tests check the + * table against arithmetic the spec makes checkable and against the FIPS 204 + * and 205 parameter sets, and then frame a stream carrying a real ML-DSA-44 + * key and signature. */ const bytesOf = (s: string) => new TextEncoder().encode(s); @@ -190,9 +192,8 @@ describe('post-quantum codes — parsing a real ML-DSA stream', () => { it('never frames a post-quantum signature as an INDEXED signature', () => { // signify-ts does not yet carry the indexed post-quantum codes that - // kswg-cesr-specification #186 proposes, so no post-quantum primitive - // may resolve through the Indexer table. A comment would not fail if - // someone later added one without the Indexer support it needs. + // kswg-cesr-specification #186 proposes, so a post-quantum signature + // in this stream must frame as Matter, never as Indexer. const all = parse(bytesOf(MLDSA_RECEIPT)).messages.flatMap((m) => m.attachments.flatMap(nodes) ); @@ -200,9 +201,11 @@ describe('post-quantum codes — parsing a real ML-DSA stream', () => { all.filter((n) => n.kind === 'primitive' && n.class === 'indexer'), [] ); - // The same rule at the framing layer: a -A group's members are Indexer - // primitives, so a post-quantum code there must not resolve, however - // well it would resolve as Matter. + // A -A group's members are Indexer primitives, so a post-quantum Matter + // code placed there must not resolve, however well it would resolve as + // Matter. This checks that the two tables stay separate; it says + // nothing about #186's own codes, which would use the 3, 8 and 9 + // selectors. const icp = MLDSA_RECEIPT.slice(0, 253); const { errors } = parse( bytesOf(icp + '-AAB' + '1AAQ' + 'A'.repeat(4412)) From 62679b02d471ff095288b7c1983cb9e620780e42 Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 14:15:43 -0700 Subject: [PATCH 3/8] fix(indexer): leave lead bytes out of the raw size Indexer computed a code's raw size as (fs - cs) * 3 / 4, which counts its lead bytes as raw. The constructor therefore demanded too many raw bytes and _exfil rejected a correctly encoded value as improperly qualified, so no indexed code with lead bytes could be built from raw or read back from qb64. The only such codes today are the 1z and 4z test codes, but the post-quantum indexed codes in trustoverip/kswg-cesr-specification#186 use the 8 and 9 selectors, which carry one and two lead bytes. Both checks now subtract the lead size, as Matter does. _rawSize had the parentheses in the wrong place, subtracting three quarters of the code size from the full size, and so was wrong for every code. Nothing in signify-ts calls it; it now uses the same formula as the constructor. Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- src/keri/core/indexer.ts | 10 ++++++--- test/core/indexer.test.ts | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/keri/core/indexer.ts b/src/keri/core/indexer.ts index 17e86059..c4f3c561 100644 --- a/src/keri/core/indexer.ts +++ b/src/keri/core/indexer.ts @@ -276,7 +276,7 @@ export class Indexer { // raise InvalidCodeSizeError(f"Non-zero other index size for " // f"variable length material. os={os}.") // fs = (index * 4) + cs - const rawsize = Math.floor(((fs - cs) * 3) / 4); + const rawsize = Math.floor(((fs - cs) * 3) / 4) - xizage.ls; // lead bytes are not raw raw = raw.slice(0, rawsize); if (raw.length != rawsize) { @@ -309,7 +309,8 @@ export class Indexer { public static _rawSize(code: string) { const xizage = Indexer.Sizes.get(code)!; - return Math.floor(xizage.fs! - ((xizage.hs + xizage.ss) * 3) / 4); + const cs = xizage.hs + xizage.ss; + return Math.floor(((xizage.fs! - cs) * 3) / 4) - xizage.ls; } get code(): string { @@ -495,7 +496,10 @@ export class Indexer { raw = paw.slice(xizage!.ls); } - if (raw.length != Math.floor(((qb64.length - cs) * 3) / 4)) { + if ( + raw.length != + Math.floor(((qb64.length - cs) * 3) / 4) - xizage.ls + ) { throw new Error(`Improperly qualified material = ${qb64}`); } diff --git a/test/core/indexer.test.ts b/test/core/indexer.test.ts index 72f183d6..a6b94f37 100644 --- a/test/core/indexer.test.ts +++ b/test/core/indexer.test.ts @@ -381,3 +381,47 @@ describe('Indexer', () => { }); }); }); + +describe('Indexer lead bytes and pad bits', () => { + /** The raw size a code implies: every character after the hard and soft + * code carries 6 bits, less any pad bits, and lead bytes are not raw. */ + const rawSizeOf = (code: string) => { + const x = Indexer.Sizes.get(code)!; + return Math.floor(((x.fs! - x.hs - x.ss) * 3) / 4) - x.ls; + }; + + it('computes _rawSize from the full size, the code size and the lead size', () => { + for (const [code, x] of Indexer.Sizes) { + if (x.fs == undefined) continue; + assert.equal(Indexer._rawSize(code), rawSizeOf(code), code); + } + assert.equal(Indexer._rawSize(IdrDex.Ed25519_Sig), 64); + assert.equal(Indexer._rawSize(IdrDex.Ed448_Big_Sig), 114); + }); + + it('round-trips a code that carries a lead byte', () => { + // 1z and 4z are keripy's test codes for indexed material with one + // lead byte. Before the lead size was subtracted from the expected raw + // size, neither could be built from raw or read back from qb64. + for (const code of ['1z', '4z']) { + const raw = new Uint8Array(rawSizeOf(code)).map((_, i) => i + 1); + const fs = Indexer.Sizes.get(code)!.fs!; + const indexer = new Indexer({ raw, code, index: 5, ondex: 5 }); + assert.equal(indexer.qb64.length, fs, code); + const back = new Indexer({ qb64: indexer.qb64 }); + assert.equal(back.code, code); + assert.equal(back.index, 5); + assert.deepStrictEqual(back.raw, raw); + assert.equal(back.qb64, indexer.qb64); + } + }); + + it('rejects a lead byte that is not zero', () => { + const raw = new Uint8Array(rawSizeOf('1z')).fill(7); + const qb64 = new Indexer({ raw, code: '1z', index: 1, ondex: 1 }).qb64; + // The two characters after the 4-character code hold the lead byte + // and the first 4 bits of raw; 'B' sets a bit inside the lead byte. + const bad = qb64.slice(0, 4) + 'B' + qb64.slice(5); + assert.throws(() => new Indexer({ qb64: bad }), /lead byte/); + }); +}); From e0ba398174a91584d3a465f70ab189bd2d7c37f6 Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 14:15:45 -0700 Subject: [PATCH 4/8] fix(indexer): check every pad bit _exfil computed the pad bit size as `2 * ps != 0 ? ps : ls`, which parses as `(2 * ps != 0) ? ps : ls` and yields ps rather than 2 * ps. A one-character code such as A, whose material carries 4 pad bits, was only checked for 2 of them, so a qb64 value with a set pad bit decoded without complaint. The expression now matches Matter's, 2 * (ps ? ps : ls). Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- src/keri/core/indexer.ts | 2 +- test/core/indexer.test.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/keri/core/indexer.ts b/src/keri/core/indexer.ts index c4f3c561..52cf8018 100644 --- a/src/keri/core/indexer.ts +++ b/src/keri/core/indexer.ts @@ -469,7 +469,7 @@ export class Indexer { qb64 = qb64.slice(0, xizage.fs); const ps = cs % 4; - const pbs = 2 * ps != 0 ? ps : xizage.ls; + const pbs = 2 * (ps != 0 ? ps : xizage.ls); // pad bit size, as in Matter let raw; if (ps != 0) { const base = new Array(ps + 1).join('A') + qb64.slice(cs); diff --git a/test/core/indexer.test.ts b/test/core/indexer.test.ts index a6b94f37..93f9951c 100644 --- a/test/core/indexer.test.ts +++ b/test/core/indexer.test.ts @@ -424,4 +424,20 @@ describe('Indexer lead bytes and pad bits', () => { const bad = qb64.slice(0, 4) + 'B' + qb64.slice(5); assert.throws(() => new Indexer({ qb64: bad }), /lead byte/); }); + + it('checks every pad bit, not half of them', () => { + // A one-character code pads its 64-byte Ed25519 signature with two + // bytes, so the first character of material carries 4 pad bits on top. + // 'Q' is 0b010000: its top 4 bits, all pad, read 0b0100. A mask of + // ps = 2 bits instead of 2 * ps = 4 bits missed that set bit. + const sig = new Uint8Array(64).fill(1); + const qb64 = new Indexer({ + raw: sig, + code: IdrDex.Ed25519_Sig, + index: 0, + }).qb64; + assert.ok('ABCD'.includes(qb64[2])); // a valid encoding has zero pad bits + const bad = qb64.slice(0, 2) + 'Q' + qb64.slice(3); + assert.throws(() => new Indexer({ qb64: bad }), /prepad bits/); + }); }); From c1acf579f3d71c7ee6d52ae6791e54cfcfb4a44f Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 14:16:01 -0700 Subject: [PATCH 5/8] feat(codes): add the indexed post-quantum signature codes trustoverip/kswg-cesr-specification#186 adds indexed signature codes for every ML-DSA and SLH-DSA signature in #185's master table, so a post-quantum key can sign as a controller or witness through a -A or -B group. They are eight-character codes with a three-character index and ondex, under the 3 selector for signatures needing no lead bytes and the new 8 and 9 selectors for one and two. Each scheme has a dual-indexed and a current-only code, as Ed448 does with 3A and 3B. This adds the 8 and 9 selectors to Indexer.Hards and all 18 rows to Indexer.Sizes, matching #186 in code and full size with the lead size its selector requires. Each code gets an IdrDex constant and its place in IdxSigDex and in IdxCrtSigDex or IdxBthSigDex. The ML-DSA names match keripy's feat/pq-signatures branch. keripy has no SLH-DSA indexed codes yet, so those names extend the same pattern and are new. The tests round-trip every code through qb64 at an index past what a two-character index holds, check each raw size against the FIPS 204 or FIPS 205 signature size, and frame a real controller signature: a self-addressing inception whose one key is an ML-DSA-44 key, signed by it under 8A, generated with @noble/post-quantum 0.7.1. The codes stay provisional until #186 merges. Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- src/keri/core/indexer.ts | 74 ++++++++++++++ test/core/pq-indexed.test.ts | 184 +++++++++++++++++++++++++++++++++++ test/core/pq.test.ts | 14 +-- 3 files changed, 265 insertions(+), 7 deletions(-) create mode 100644 test/core/pq-indexed.test.ts diff --git a/src/keri/core/indexer.ts b/src/keri/core/indexer.ts index 52cf8018..9154dada 100644 --- a/src/keri/core/indexer.ts +++ b/src/keri/core/indexer.ts @@ -19,6 +19,24 @@ export class IndexerCodex { ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only. Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists. Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only. + ML_DSA_65_Big_Sig: string = '3C'; // ML-DSA-65 sig appears in both lists. + ML_DSA_65_Big_Crt_Sig: string = '3D'; // ML-DSA-65 sig appears in current list only. + SLH_DSA_SHA2_192s_Big_Sig: string = '3E'; // SLH-DSA-SHA2-192s sig appears in both lists. + SLH_DSA_SHA2_192s_Big_Crt_Sig: string = '3F'; // SLH-DSA-SHA2-192s sig appears in current list only. + SLH_DSA_SHAKE_192s_Big_Sig: string = '3G'; // SLH-DSA-SHAKE-192s sig appears in both lists. + SLH_DSA_SHAKE_192s_Big_Crt_Sig: string = '3H'; // SLH-DSA-SHAKE-192s sig appears in current list only. + ML_DSA_44_Big_Sig: string = '8A'; // ML-DSA-44 sig appears in both lists, lead size 1. + ML_DSA_44_Big_Crt_Sig: string = '8B'; // ML-DSA-44 sig appears in current list only, lead size 1. + SLH_DSA_SHA2_128s_Big_Sig: string = '8C'; // SLH-DSA-SHA2-128s sig appears in both lists, lead size 1. + SLH_DSA_SHA2_128s_Big_Crt_Sig: string = '8D'; // SLH-DSA-SHA2-128s sig appears in current list only, lead size 1. + SLH_DSA_SHAKE_128s_Big_Sig: string = '8E'; // SLH-DSA-SHAKE-128s sig appears in both lists, lead size 1. + SLH_DSA_SHAKE_128s_Big_Crt_Sig: string = '8F'; // SLH-DSA-SHAKE-128s sig appears in current list only, lead size 1. + SLH_DSA_SHA2_256s_Big_Sig: string = '8G'; // SLH-DSA-SHA2-256s sig appears in both lists, lead size 1. + SLH_DSA_SHA2_256s_Big_Crt_Sig: string = '8H'; // SLH-DSA-SHA2-256s sig appears in current list only, lead size 1. + SLH_DSA_SHAKE_256s_Big_Sig: string = '8I'; // SLH-DSA-SHAKE-256s sig appears in both lists, lead size 1. + SLH_DSA_SHAKE_256s_Big_Crt_Sig: string = '8J'; // SLH-DSA-SHAKE-256s sig appears in current list only, lead size 1. + ML_DSA_87_Big_Sig: string = '9A'; // ML-DSA-87 sig appears in both lists, lead size 2. + ML_DSA_87_Big_Crt_Sig: string = '9B'; // ML-DSA-87 sig appears in current list only, lead size 2. } export const IdrDex = new IndexerCodex(); @@ -40,6 +58,24 @@ export class IndexedSigCodex { ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only. Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists. Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only. + ML_DSA_65_Big_Sig: string = '3C'; // ML-DSA-65 sig appears in both lists. + ML_DSA_65_Big_Crt_Sig: string = '3D'; // ML-DSA-65 sig appears in current list only. + SLH_DSA_SHA2_192s_Big_Sig: string = '3E'; // SLH-DSA-SHA2-192s sig appears in both lists. + SLH_DSA_SHA2_192s_Big_Crt_Sig: string = '3F'; // SLH-DSA-SHA2-192s sig appears in current list only. + SLH_DSA_SHAKE_192s_Big_Sig: string = '3G'; // SLH-DSA-SHAKE-192s sig appears in both lists. + SLH_DSA_SHAKE_192s_Big_Crt_Sig: string = '3H'; // SLH-DSA-SHAKE-192s sig appears in current list only. + ML_DSA_44_Big_Sig: string = '8A'; // ML-DSA-44 sig appears in both lists, lead size 1. + ML_DSA_44_Big_Crt_Sig: string = '8B'; // ML-DSA-44 sig appears in current list only, lead size 1. + SLH_DSA_SHA2_128s_Big_Sig: string = '8C'; // SLH-DSA-SHA2-128s sig appears in both lists, lead size 1. + SLH_DSA_SHA2_128s_Big_Crt_Sig: string = '8D'; // SLH-DSA-SHA2-128s sig appears in current list only, lead size 1. + SLH_DSA_SHAKE_128s_Big_Sig: string = '8E'; // SLH-DSA-SHAKE-128s sig appears in both lists, lead size 1. + SLH_DSA_SHAKE_128s_Big_Crt_Sig: string = '8F'; // SLH-DSA-SHAKE-128s sig appears in current list only, lead size 1. + SLH_DSA_SHA2_256s_Big_Sig: string = '8G'; // SLH-DSA-SHA2-256s sig appears in both lists, lead size 1. + SLH_DSA_SHA2_256s_Big_Crt_Sig: string = '8H'; // SLH-DSA-SHA2-256s sig appears in current list only, lead size 1. + SLH_DSA_SHAKE_256s_Big_Sig: string = '8I'; // SLH-DSA-SHAKE-256s sig appears in both lists, lead size 1. + SLH_DSA_SHAKE_256s_Big_Crt_Sig: string = '8J'; // SLH-DSA-SHAKE-256s sig appears in current list only, lead size 1. + ML_DSA_87_Big_Sig: string = '9A'; // ML-DSA-87 sig appears in both lists, lead size 2. + ML_DSA_87_Big_Crt_Sig: string = '9B'; // ML-DSA-87 sig appears in current list only, lead size 2. has(prop: string): boolean { const m = new Map( @@ -60,6 +96,15 @@ export class IndexedCurrentSigCodex { ECDSA_256k1_Big_Crt_Sig: string = '2D'; // ECDSA secp256k1 sig appears in current list only. ECDSA_256r1_Big_Crt_Sig: string = '2F'; // ECDSA secp256r1 sig appears in current list only. Ed448_Big_Crt_Sig: string = '3B'; // Ed448 signature appears in current list only. + ML_DSA_65_Big_Crt_Sig: string = '3D'; // ML-DSA-65 sig appears in current list only. + SLH_DSA_SHA2_192s_Big_Crt_Sig: string = '3F'; // SLH-DSA-SHA2-192s sig appears in current list only. + SLH_DSA_SHAKE_192s_Big_Crt_Sig: string = '3H'; // SLH-DSA-SHAKE-192s sig appears in current list only. + ML_DSA_44_Big_Crt_Sig: string = '8B'; // ML-DSA-44 sig appears in current list only, lead size 1. + SLH_DSA_SHA2_128s_Big_Crt_Sig: string = '8D'; // SLH-DSA-SHA2-128s sig appears in current list only, lead size 1. + SLH_DSA_SHAKE_128s_Big_Crt_Sig: string = '8F'; // SLH-DSA-SHAKE-128s sig appears in current list only, lead size 1. + SLH_DSA_SHA2_256s_Big_Crt_Sig: string = '8H'; // SLH-DSA-SHA2-256s sig appears in current list only, lead size 1. + SLH_DSA_SHAKE_256s_Big_Crt_Sig: string = '8J'; // SLH-DSA-SHAKE-256s sig appears in current list only, lead size 1. + ML_DSA_87_Big_Crt_Sig: string = '9B'; // ML-DSA-87 sig appears in current list only, lead size 2. has(prop: string): boolean { const m = new Map( @@ -78,6 +123,15 @@ export class IndexedBothSigCodex { Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both listsy. ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists. Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists. + ML_DSA_65_Big_Sig: string = '3C'; // ML-DSA-65 sig appears in both lists. + SLH_DSA_SHA2_192s_Big_Sig: string = '3E'; // SLH-DSA-SHA2-192s sig appears in both lists. + SLH_DSA_SHAKE_192s_Big_Sig: string = '3G'; // SLH-DSA-SHAKE-192s sig appears in both lists. + ML_DSA_44_Big_Sig: string = '8A'; // ML-DSA-44 sig appears in both lists, lead size 1. + SLH_DSA_SHA2_128s_Big_Sig: string = '8C'; // SLH-DSA-SHA2-128s sig appears in both lists, lead size 1. + SLH_DSA_SHAKE_128s_Big_Sig: string = '8E'; // SLH-DSA-SHAKE-128s sig appears in both lists, lead size 1. + SLH_DSA_SHA2_256s_Big_Sig: string = '8G'; // SLH-DSA-SHA2-256s sig appears in both lists, lead size 1. + SLH_DSA_SHAKE_256s_Big_Sig: string = '8I'; // SLH-DSA-SHAKE-256s sig appears in both lists, lead size 1. + ML_DSA_87_Big_Sig: string = '9A'; // ML-DSA-87 sig appears in both lists, lead size 2. has(prop: string): boolean { const m = new Map( @@ -176,6 +230,8 @@ export class Indexer { ['2', 2], ['3', 2], ['4', 2], + ['8', 2], + ['9', 2], ]); static Sizes = new Map( @@ -198,6 +254,24 @@ export class Indexer { '3A': new Xizage(2, 6, 3, 160, 0), '3B': new Xizage(2, 6, 3, 160, 0), + '3C': new Xizage(2, 6, 3, 4420, 0), + '3D': new Xizage(2, 6, 3, 4420, 0), + '3E': new Xizage(2, 6, 3, 21640, 0), + '3F': new Xizage(2, 6, 3, 21640, 0), + '3G': new Xizage(2, 6, 3, 21640, 0), + '3H': new Xizage(2, 6, 3, 21640, 0), + '8A': new Xizage(2, 6, 3, 3236, 1), + '8B': new Xizage(2, 6, 3, 3236, 1), + '8C': new Xizage(2, 6, 3, 10484, 1), + '8D': new Xizage(2, 6, 3, 10484, 1), + '8E': new Xizage(2, 6, 3, 10484, 1), + '8F': new Xizage(2, 6, 3, 10484, 1), + '8G': new Xizage(2, 6, 3, 39732, 1), + '8H': new Xizage(2, 6, 3, 39732, 1), + '8I': new Xizage(2, 6, 3, 39732, 1), + '8J': new Xizage(2, 6, 3, 39732, 1), + '9A': new Xizage(2, 6, 3, 6180, 2), + '9B': new Xizage(2, 6, 3, 6180, 2), '0z': new Xizage(2, 2, 0, undefined, 0), '1z': new Xizage(2, 2, 1, 76, 1), diff --git a/test/core/pq-indexed.test.ts b/test/core/pq-indexed.test.ts new file mode 100644 index 00000000..1b1cf3f8 --- /dev/null +++ b/test/core/pq-indexed.test.ts @@ -0,0 +1,184 @@ +import { assert, describe, it } from 'vitest'; +import { + IdrDex, + IdxBthSigDex, + IdxCrtSigDex, + IdxSigDex, + Indexer, +} from '../../src/keri/core/indexer.ts'; +import { Matter } from '../../src/keri/core/matter.ts'; +import { parse, type Primitive } from '../../src/keri/core/parsing.ts'; + +/* Indexed post-quantum signature codes, following + * trustoverip/kswg-cesr-specification #186. + * + * #186 adds eight-character indexed codes with three-character index and + * ondex for every ML-DSA and SLH-DSA signature. The raw size mod 3 picks the + * selector: 3 for no lead bytes, 8 for one, 9 for two. Each scheme has a + * dual-indexed code and a current-only code, as Ed448's 3A and 3B do. */ + +const bytesOf = (s: string) => new TextEncoder().encode(s); + +/** Every indexed post-quantum code: its name in IdrDex, full size, lead size, + * and the signature size FIPS 204 or FIPS 205 gives for its parameter set. */ +const PQX: Array<[string, string, number, number, number]> = [ + ['3C', 'ML_DSA_65_Big_Sig', 4420, 0, 3309], + ['3D', 'ML_DSA_65_Big_Crt_Sig', 4420, 0, 3309], + ['3E', 'SLH_DSA_SHA2_192s_Big_Sig', 21640, 0, 16224], + ['3F', 'SLH_DSA_SHA2_192s_Big_Crt_Sig', 21640, 0, 16224], + ['3G', 'SLH_DSA_SHAKE_192s_Big_Sig', 21640, 0, 16224], + ['3H', 'SLH_DSA_SHAKE_192s_Big_Crt_Sig', 21640, 0, 16224], + ['8A', 'ML_DSA_44_Big_Sig', 3236, 1, 2420], + ['8B', 'ML_DSA_44_Big_Crt_Sig', 3236, 1, 2420], + ['8C', 'SLH_DSA_SHA2_128s_Big_Sig', 10484, 1, 7856], + ['8D', 'SLH_DSA_SHA2_128s_Big_Crt_Sig', 10484, 1, 7856], + ['8E', 'SLH_DSA_SHAKE_128s_Big_Sig', 10484, 1, 7856], + ['8F', 'SLH_DSA_SHAKE_128s_Big_Crt_Sig', 10484, 1, 7856], + ['8G', 'SLH_DSA_SHA2_256s_Big_Sig', 39732, 1, 29792], + ['8H', 'SLH_DSA_SHA2_256s_Big_Crt_Sig', 39732, 1, 29792], + ['8I', 'SLH_DSA_SHAKE_256s_Big_Sig', 39732, 1, 29792], + ['8J', 'SLH_DSA_SHAKE_256s_Big_Crt_Sig', 39732, 1, 29792], + ['9A', 'ML_DSA_87_Big_Sig', 6180, 2, 4627], + ['9B', 'ML_DSA_87_Big_Crt_Sig', 6180, 2, 4627], +]; + +const isCurrentOnly = (name: string) => name.includes('_Crt_'); + +/** A self-addressing inception whose one signing key is an ML-DSA-44 public + * key (3AAA), followed by a -A controller signature group holding that key's + * 8A indexed signature at index 0. The keypair is real and the signature is + * over the event's exact bytes, generated with @noble/post-quantum 0.7.1's + * ml_dsa44, so it verifies; signify-ts ships no ML-DSA implementation and + * cannot check that here, but it can frame it. The prefix is a digest of the + * event rather than of the key, since no post-quantum key code may be a basic + * prefix. */ +const MLDSA_ICP = + '{"v":"KERI10JSON0007ad_","t":"icp","d":"ENu8rbtEWGV2gEbf2AJ_4ZT-GzFDEQSSUwOnfd7LN-Cy","i":"ENu8rbtEWGV2gEbf2AJ_4ZT-GzFDEQSSUwOnfd7LN-Cy","s":"0","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shuoq4mx7l2BZIBagEBzcuwuGD7GLdxuz5BpPRpzZZhuhcf833P3gjcEhOpsBC2-VYWFEL0B6FN2ZHSlIobLnwSAwcRDqmVry-fG43MH2u0m00iVj4tp3kJpECD7MPNHHwpYVTdRre1XObaKISmbk9i5OaCfs8uaL6X3ZdBf-OUpU6OiRT8fd_nRkxdKvSZZBb5j4LiurszgrcgH6Pl4M6rxaJLTZYL2xXsnUeF7vdYfsXrESK89sH6ItrODy4Tf5usGqcqbpcaBYjR80wudnrArXpdtRAI_X1IwG9qALPGfXEsWMHskWtXyYyx1bGtINsPmOuNlYgaDoir_u4zVDK2UYFABYGR_ysrjyorHNcihxHZs_CfMkd2g-50to3w0v0FoS0GxCmlKNlIZBvg8fA68F4CD4rRQ7_631Tj3rVXz_2qX19eYKO7F6kgQyCJaFkCvzEiVI1ciwb7WRahrO3-yzht_EwMUaW1L6UcGii5wKhQAthMjjjHwju__o4Qz0xqi7a37VbJIGVWSu_WEm0v-TEteusaotzffm84oZhVcY2GmbD3egHXWyNSp3K4SRFD1reAtAqvi22vC0J9WTcpoXVXUfeeKvetXUahyuh_FZjxAydATVBaYX2AgZWXmLS6xNn9HR5BTHB-kM7h9vgHCxYbKTpCSlJUV16Bk6-3CBkfOFSCl66vx-r6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASHS05'; +const ICP_LENGTH = 1965; + +describe('indexed post-quantum codes — the table', () => { + it('reads 8 and 9 as two-character hard codes', () => { + assert.equal(Indexer.Hards.get('8'), 2); + assert.equal(Indexer.Hards.get('9'), 2); + }); + + it('sizes every code consistently with its selector and its FIPS signature', () => { + for (const [code, , fs, ls, sigSize] of PQX) { + const x = Indexer.Sizes.get(code); + assert.ok(x, `${code}: missing from Indexer.Sizes`); + assert.equal(x.hs, 2, `${code}: hard size`); + assert.equal(x.ss, 6, `${code}: soft size`); + assert.equal(x.os, 3, `${code}: ondex size`); + assert.equal(x.fs, fs, `${code}: full size`); + assert.equal(x.ls, ls, `${code}: lead size`); + // The selector fixes the lead size: 3 -> 0, 8 -> 1, 9 -> 2. + assert.equal(ls, { '3': 0, '8': 1, '9': 2 }[code[0]], code); + assert.equal(Indexer._rawSize(code), sigSize, `${code}: raw size`); + // Signature plus lead bytes must fill whole 24-bit groups. + assert.equal((sigSize + ls) % 3, 0, `${code}: not 24-bit aligned`); + } + }); + + it('names every code and sorts it into the right signature sets', () => { + for (const [code, name] of PQX) { + assert.equal( + (IdrDex as unknown as Record)[name], + code, + name + ); + assert.ok(IdxSigDex.has(code), `${code}: not an indexed sig code`); + assert.equal(IdxCrtSigDex.has(code), isCurrentOnly(name), code); + assert.equal(IdxBthSigDex.has(code), !isCurrentOnly(name), code); + } + }); +}); + +describe('indexed post-quantum codes — encoding', () => { + it('round-trips a signature through qb64 at every code', () => { + for (const [code, name, fs, , sigSize] of PQX) { + const raw = new Uint8Array(sigSize).map( + (_, i) => (i * 7 + 1) % 256 + ); + const crt = isCurrentOnly(name); + const indexer = new Indexer({ + raw, + code, + index: 70_000, // past what a two-character index could hold + ondex: crt ? undefined : 3, + }); + assert.equal(indexer.qb64.length, fs, `${code}: encoded length`); + const back = new Indexer({ qb64: indexer.qb64 }); + assert.equal(back.code, code); + assert.equal(back.index, 70_000); + assert.equal(back.ondex, crt ? undefined : 3, `${code}: ondex`); + assert.deepStrictEqual(back.raw, raw, `${code}: raw`); + } + }); + + it('defaults a dual-indexed ondex to the index, and refuses one on a current-only code', () => { + const raw = new Uint8Array(2420); + assert.equal( + new Indexer({ raw, code: IdrDex.ML_DSA_44_Big_Sig, index: 9 }) + .ondex, + 9 + ); + assert.throws( + () => + new Indexer({ + raw, + code: IdrDex.ML_DSA_44_Big_Crt_Sig, + index: 9, + ondex: 9, + }) + ); + }); + + it('rejects a lead byte that is not zero', () => { + const qb64 = new Indexer({ + raw: new Uint8Array(4627), + code: IdrDex.ML_DSA_87_Big_Sig, + index: 0, + }).qb64; + // 9A carries two lead bytes, encoded in the characters after the + // 8-character code; 'B' sets a bit inside them. + const bad = qb64.slice(0, 8) + 'B' + qb64.slice(9); + assert.throws(() => new Indexer({ qb64: bad }), /lead bytes/); + }); +}); + +describe('indexed post-quantum codes — parsing a real ML-DSA controller signature', () => { + it('frames the inception and its signature with nothing left over', () => { + const bytes = bytesOf(MLDSA_ICP); + const { messages, errors, consumed } = parse(bytes); + assert.deepStrictEqual(errors, []); + assert.equal(consumed, bytes.length); + assert.equal(messages.length, 1); + assert.equal(messages[0].body.ilk, 'icp'); + }); + + it('reads the signature as an 8A indexed signature at index 0 over the ML-DSA-44 key', () => { + const { messages } = parse(bytesOf(MLDSA_ICP)); + const group = messages[0].attachments[0]; + assert.equal(group.code, '-A'); + assert.equal(group.state, 'known'); + const items = group.items as Primitive[]; + assert.equal(items.length, 1); + assert.equal(items[0].code, '8A'); + assert.equal(items[0].class, 'indexer'); + assert.equal(items[0].span.start, ICP_LENGTH + 4); // past the -A header + assert.equal(items[0].span.end - items[0].span.start, 3236); + + const siger = new Indexer({ + qb64: MLDSA_ICP.slice(items[0].span.start, items[0].span.end), + }); + assert.equal(siger.index, 0); + assert.equal(siger.ondex, 0); + assert.equal(siger.raw.length, 2420); + + const icp = JSON.parse(MLDSA_ICP.slice(0, ICP_LENGTH)); + assert.equal(icp.i, icp.d); // self-addressing + const verfer = new Matter({ qb64: icp.k[0] }); + assert.equal(verfer.code, '3AAA'); + assert.equal(verfer.raw.length, 1312); + }); +}); diff --git a/test/core/pq.test.ts b/test/core/pq.test.ts index 54f58e8a..98c782d8 100644 --- a/test/core/pq.test.ts +++ b/test/core/pq.test.ts @@ -190,10 +190,11 @@ describe('post-quantum codes — parsing a real ML-DSA stream', () => { assert.equal(items[1].span.end, group.span.end); }); - it('never frames a post-quantum signature as an INDEXED signature', () => { - // signify-ts does not yet carry the indexed post-quantum codes that - // kswg-cesr-specification #186 proposes, so a post-quantum signature - // in this stream must frame as Matter, never as Indexer. + it('frames the post-quantum signature in a receipt couple signature as Matter, not Indexer', () => { + // A -C couple carries an unindexed signature, so the ML-DSA-44 + // signature in this stream must frame through the Matter table even + // though the indexed codes from kswg-cesr-specification #186 exist + // (see pq-indexed.test.ts). const all = parse(bytesOf(MLDSA_RECEIPT)).messages.flatMap((m) => m.attachments.flatMap(nodes) ); @@ -203,9 +204,8 @@ describe('post-quantum codes — parsing a real ML-DSA stream', () => { ); // A -A group's members are Indexer primitives, so a post-quantum Matter // code placed there must not resolve, however well it would resolve as - // Matter. This checks that the two tables stay separate; it says - // nothing about #186's own codes, which would use the 3, 8 and 9 - // selectors. + // Matter. This checks that the two tables stay separate; #186's own + // indexed codes use the 3, 8 and 9 selectors instead. const icp = MLDSA_RECEIPT.slice(0, 253); const { errors } = parse( bytesOf(icp + '-AAB' + '1AAQ' + 'A'.repeat(4412)) From 1b9b2b0752a8c8fb20f62e362eaa862f37fbafcd Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 14:22:11 -0700 Subject: [PATCH 6/8] fix(indexer): treat E and 2E as dual-indexed IdxBthSigDex left out the ECDSA secp256r1 codes E and 2E, which keripy's IndexedBothSigCodex includes. The constructor uses that set to default a missing ondex to the index, so a 2E signature at index 5 built without an ondex encoded ondex 0, and an E signature carried no ondex at all until it was re-read from qb64. Nothing in signify-ts builds these signatures without an explicit ondex today. A hostile review (codex) of the post-quantum indexed codes found this. Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- src/keri/core/indexer.ts | 2 ++ test/core/indexer.test.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/keri/core/indexer.ts b/src/keri/core/indexer.ts index 9154dada..2097fde3 100644 --- a/src/keri/core/indexer.ts +++ b/src/keri/core/indexer.ts @@ -119,9 +119,11 @@ export const IdxCrtSigDex = new IndexedCurrentSigCodex(); export class IndexedBothSigCodex { Ed25519_Sig: string = 'A'; // Ed25519 sig appears same in both lists if any. ECDSA_256k1_Sig: string = 'C'; // ECDSA secp256k1 sig appears same in both lists if any. + ECDSA_256r1_Sig: string = 'E'; // ECDSA secp256r1 sig appears same in both lists if any. Ed448_Sig: string = '0A'; // Ed448 signature appears in both lists. Ed25519_Big_Sig: string = '2A'; // Ed25519 sig appears in both listsy. ECDSA_256k1_Big_Sig: string = '2C'; // ECDSA secp256k1 sig appears in both lists. + ECDSA_256r1_Big_Sig: string = '2E'; // ECDSA secp256r1 sig appears in both lists. Ed448_Big_Sig: string = '3A'; // Ed448 signature appears in both lists. ML_DSA_65_Big_Sig: string = '3C'; // ML-DSA-65 sig appears in both lists. SLH_DSA_SHA2_192s_Big_Sig: string = '3E'; // SLH-DSA-SHA2-192s sig appears in both lists. diff --git a/test/core/indexer.test.ts b/test/core/indexer.test.ts index 93f9951c..0a2f5c87 100644 --- a/test/core/indexer.test.ts +++ b/test/core/indexer.test.ts @@ -441,3 +441,20 @@ describe('Indexer lead bytes and pad bits', () => { assert.throws(() => new Indexer({ qb64: bad }), /prepad bits/); }); }); + +describe('Indexer dual-indexed ECDSA secp256r1 codes', () => { + it('defaults the ondex of E and 2E to the index, as for the other dual-indexed codes', () => { + // keripy lists E and 2E among the codes whose signature appears in + // both the current and prior next lists. Without them, a 2E signature + // at index 5 built with no ondex encoded ondex 0. + const sig = new Uint8Array(64).fill(1); + for (const code of [ + IdrDex.ECDSA_256r1_Sig, + IdrDex.ECDSA_256r1_Big_Sig, + ]) { + const indexer = new Indexer({ raw: sig, code, index: 5 }); + assert.equal(indexer.ondex, 5, code); + assert.equal(new Indexer({ qb64: indexer.qb64 }).ondex, 5, code); + } + }); +}); From a4a3b2bb66450c95bf4536b506ebc51daa16b563 Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 14:22:25 -0700 Subject: [PATCH 7/8] fix(indexer): require an integer ondex The constructor and _infil required the index to be an integer but only range-checked the ondex, so an ondex of 1.5 was accepted, stored, and encoded. keripy accepts only an int. A hostile review (codex) of the post-quantum indexed codes found this; it matters more now that three-character ondices are in use. Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- src/keri/core/indexer.ts | 12 ++++++++++-- test/core/indexer.test.ts | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/keri/core/indexer.ts b/src/keri/core/indexer.ts index 2097fde3..bfda4dcb 100644 --- a/src/keri/core/indexer.ts +++ b/src/keri/core/indexer.ts @@ -319,7 +319,11 @@ export class Indexer { if ( ondex != undefined && xizage.os != 0 && - !(ondex >= 0 && ondex <= 64 ** os - 1) + !( + Number.isInteger(ondex) && + ondex >= 0 && + ondex <= 64 ** os - 1 + ) ) { throw new Error(`Invalid ondex=${ondex} for code=${code}.`); } @@ -441,7 +445,11 @@ export class Indexer { if ( ondex != undefined && xizage.os != 0 && - !(ondex >= 0 && ondex <= 64 ** xizage.os - 1) + !( + Number.isInteger(ondex) && + ondex >= 0 && + ondex <= 64 ** xizage.os - 1 + ) ) { throw new Error( `Invalid ondex=${ondex} for os=${xizage.os} and code=${code}.` diff --git a/test/core/indexer.test.ts b/test/core/indexer.test.ts index 0a2f5c87..5e4e5ab4 100644 --- a/test/core/indexer.test.ts +++ b/test/core/indexer.test.ts @@ -458,3 +458,21 @@ describe('Indexer dual-indexed ECDSA secp256r1 codes', () => { } }); }); + +describe('Indexer ondex validation', () => { + it('rejects an ondex that is not an integer', () => { + // The index was already required to be an integer; the ondex was only + // range-checked, so 1.5 was stored and then encoded. + const sig = new Uint8Array(114); + assert.throws( + () => + new Indexer({ + raw: sig, + code: IdrDex.Ed448_Big_Sig, + index: 1, + ondex: 1.5, + }), + /ondex/ + ); + }); +}); From 7d1ecc1d6ec1b69ce173682325aa801221f40e70 Mon Sep 17 00:00:00 2001 From: Daniel Hardman Date: Thu, 12 Nov 2026 14:22:37 -0700 Subject: [PATCH 8/8] test(pq): say the indexed exhibit is checked for framing only The codex review pointed out that the comment's 'so it verifies' reads as something the tests check. They frame the signature and check its size; the verification happened once, when the vector was generated. Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA Signed-off-by: Daniel Hardman --- test/core/pq-indexed.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/core/pq-indexed.test.ts b/test/core/pq-indexed.test.ts index 1b1cf3f8..b9040e7a 100644 --- a/test/core/pq-indexed.test.ts +++ b/test/core/pq-indexed.test.ts @@ -48,8 +48,9 @@ const isCurrentOnly = (name: string) => name.includes('_Crt_'); * key (3AAA), followed by a -A controller signature group holding that key's * 8A indexed signature at index 0. The keypair is real and the signature is * over the event's exact bytes, generated with @noble/post-quantum 0.7.1's - * ml_dsa44, so it verifies; signify-ts ships no ML-DSA implementation and - * cannot check that here, but it can frame it. The prefix is a digest of the + * ml_dsa44, and it verified against the key when generated. signify-ts ships + * no ML-DSA implementation, so these tests check framing and sizes only. The + * prefix is a digest of the * event rather than of the key, since no post-quantum key code may be a basic * prefix. */ const MLDSA_ICP =