commit 46f3c1dbb4c8fea6ddc964c76cf573e874dc7ef8
parent c846c7b325eaa870480f6bcf61b1cf7b701a89fc
Author: triesap <tyson@radroots.org>
Date: Sun, 11 Oct 2026 14:10:49 +0000
test: qualify inner Message and independent wire vectors (HCP-130)
- Bind separate browser Message recipes to actual pinned Rust 1.99 parity.
- Verify published NIP-17 outer vectors with retained keyless provenance.
- Preserve exact pair, reply and ciphertext publication behavior.
- Keep independent-client receive and reply qualification pending.
Diffstat:
5 files changed, 690 insertions(+), 17 deletions(-)
diff --git a/web/tests/conformance/message-qualified-matrix.test.ts b/web/tests/conformance/message-qualified-matrix.test.ts
@@ -0,0 +1,191 @@
+import assert from 'node:assert/strict';
+import { createHash } from 'node:crypto';
+import { readFileSync } from 'node:fs';
+import test from 'node:test';
+import {
+ qualifiedMessages,
+ qualifiedMessageReplay
+} from './message-qualified-matrix.ts';
+import {
+ messageFromWireParts,
+ messageToWireParts,
+ type MessageV1
+} from '../../src/lib/contracts/message-v1/index.ts';
+import { verifyEnvelope } from '../../src/lib/nostr/verified-envelope.ts';
+import type { NostrEvent } from 'applesauce-core/helpers';
+const digest = (bytes: string | Uint8Array) =>
+ createHash('sha256').update(bytes).digest('hex');
+const receipt = JSON.parse(
+ readFileSync(
+ new URL('./message-qualified-writer-rust.v1.json', import.meta.url),
+ 'utf8'
+ )
+) as {
+ schema_version: number;
+ revision: string;
+ recipe_sha256: string;
+ inputs: Record<string, string>;
+ consumed: { id: string; message: MessageV1 }[];
+ qualification: string;
+};
+void test('separate sixteen Message recipes replay actual pinned Rust consumption without changing original shared fixtures', () => {
+ assert.equal(
+ receipt.recipe_sha256,
+ digest(JSON.stringify(qualifiedMessageReplay))
+ );
+ assert.equal(receipt.schema_version, 1);
+ assert.equal(receipt.revision, '189c49b74b4bafc142b00b76b296477931139e72');
+ assert.equal(qualifiedMessageReplay.length, 16);
+ assert.deepEqual(
+ receipt.consumed,
+ qualifiedMessageReplay.map((row) => ({ id: row.id, message: row.expected }))
+ );
+ const inputs = {
+ 'message-qualified-matrix.ts': new URL(
+ './message-qualified-matrix.ts',
+ import.meta.url
+ ),
+ 'source_profile.v1.json': new URL(
+ '../../../contracts/interop/message/source_profile.v1.json',
+ import.meta.url
+ ),
+ 'corpus.v1.json': new URL(
+ '../../../contracts/interop/message/corpus.v1.json',
+ import.meta.url
+ ),
+ 'oracle/src/main.rs': new URL(
+ '../../../contracts/interop/message/oracle/src/main.rs',
+ import.meta.url
+ )
+ };
+ assert.deepEqual(
+ Object.keys(receipt.inputs).sort(),
+ Object.keys(inputs).sort()
+ );
+ for (const [name, url] of Object.entries(inputs))
+ assert.equal(receipt.inputs[name], digest(readFileSync(url)), name);
+ assert.match(receipt.qualification, /unsigned kind 14/);
+ assert.match(receipt.qualification, /not independent-client receive\/reply/);
+});
+void test('pure Message parity preserves exact p/e/subject, bounded raw text and ordinary citations without orders', () => {
+ for (const [index, row] of qualifiedMessageReplay.entries()) {
+ assert.deepEqual(
+ messageFromWireParts(JSON.stringify(row.wire_parts)),
+ row.expected,
+ row.id
+ );
+ assert.equal(row.wire_parts.kind, 14);
+ assert.deepEqual(
+ row.wire_parts.tags.map((tag) => tag[0]),
+ [
+ 'p',
+ ...(row.expected.reply_to ? ['e'] : []),
+ ...(row.expected.subject !== null ? ['subject'] : [])
+ ]
+ );
+ assert.equal(Object.hasOwn(row.wire_parts, 'sig'), false);
+ assert.equal(Object.hasOwn(row.wire_parts, 'id'), false);
+ assert.equal(Object.hasOwn(row.wire_parts, 'pubkey'), false);
+ assert.deepEqual(row.expected, qualifiedMessages[index]);
+ assert.equal(
+ messageToWireParts(
+ JSON.stringify({ ...row.expected, order: 'unauthorized' })
+ ),
+ undefined
+ );
+ }
+ assert.equal(
+ new TextEncoder().encode(qualifiedMessages[9].content).length,
+ 4096
+ );
+ assert.notEqual(qualifiedMessages[6].content, qualifiedMessages[7].content);
+ assert.equal(
+ qualifiedMessages[6].content.normalize('NFC'),
+ qualifiedMessages[7].content.normalize('NFC')
+ );
+});
+interface PublishedWires {
+ schema_version: number;
+ source: {
+ url: string;
+ revision: string;
+ sha256: string;
+ bytes: number;
+ scope: string;
+ };
+ cases: {
+ role: 'peer' | 'self';
+ fence_start_line: number;
+ event: NostrEvent;
+ }[];
+}
+const published = JSON.parse(
+ readFileSync(
+ new URL(
+ '../fixtures/independent-nip17/public-outer-wires.v1.json',
+ import.meta.url
+ ),
+ 'utf8'
+ )
+) as PublishedWires;
+void test('frozen official NIP17 peer and self outer vectors verify fresh public signatures and exact destinations without imported keys or plaintext claims', () => {
+ assert.equal(published.schema_version, 1);
+ assert.equal(
+ published.source.revision,
+ '0046368a747c5c25ae2bec28bae0e537744c8f10'
+ );
+ assert.equal(
+ published.source.sha256,
+ '7aa9c3a9c0458a9552c4be2f3bf17f7ec60a4afe88bce7977f03500a7873a64c'
+ );
+ assert.equal(published.source.bytes, 12439);
+ assert.equal(
+ published.source.url,
+ 'https://raw.githubusercontent.com/nostr-protocol/nips/0046368a747c5c25ae2bec28bae0e537744c8f10/17.md'
+ );
+ assert.match(published.source.scope, /outer ciphertext only/);
+ assert.deepEqual(
+ published.cases.map((row) => [row.role, row.fence_start_line]),
+ [
+ ['peer', 190],
+ ['self', 204]
+ ]
+ );
+ assert.deepEqual(
+ published.cases.map((row) => row.event.id),
+ [
+ '2886780f7349afc1344047524540ee716f7bdc1b64191699855662330bf235d8',
+ '162b0611a1911cfcb30f8a5502792b346e535a45658b3a31ae5c178465509721'
+ ]
+ );
+ const destinations = [
+ '918e2da906df4ccd12c8ac672d8335add131a4cf9d27ce42b3bb3625755f0788',
+ '44900586091b284416a0c001f677f9c49f7639a55c3f1e2ec130a8e1a7998e1b'
+ ];
+ for (const [index, row] of published.cases.entries()) {
+ assert.deepEqual(
+ Object.keys(row.event).sort(),
+ ['id', 'pubkey', 'created_at', 'kind', 'tags', 'content', 'sig'].sort()
+ );
+ assert.equal(row.event.kind, 1059);
+ assert.deepEqual(row.event.tags, [['p', destinations[index]]]);
+ assert.equal(verifyEnvelope(JSON.stringify(row.event)).ok, true);
+ assert.equal(messageFromWireParts(JSON.stringify(row.event)), undefined);
+ assert.equal(JSON.stringify(row.event).includes('nsec'), false);
+ }
+ assert.notEqual(
+ published.cases[0].event.pubkey,
+ published.cases[1].event.pubkey
+ );
+ assert.notEqual(published.cases[0].event.id, published.cases[1].event.id);
+});
+void test('altered official outer target, ciphertext and signature each fail fresh verification; public examples grant no decrypted rumor custody', () => {
+ for (const row of published.cases) {
+ for (const changed of [
+ { ...row.event, tags: [['p', '0'.repeat(64)]] },
+ { ...row.event, content: row.event.content + 'A' },
+ { ...row.event, sig: '0'.repeat(128) }
+ ])
+ assert.equal(verifyEnvelope(JSON.stringify(changed)).ok, false);
+ }
+});
diff --git a/web/tests/conformance/message-qualified-matrix.ts b/web/tests/conformance/message-qualified-matrix.ts
@@ -0,0 +1,79 @@
+import { naddrEncode, neventEncode } from 'applesauce-core/helpers/pointers';
+import {
+ messageToWireParts,
+ messageFromWireParts,
+ type MessageV1
+} from '../../src/lib/contracts/message-v1/index.ts';
+
+// Separate browser-owned recipes. These pure projections grant no room,
+// participant, extension, encryption, persistence or publication authority.
+const peer = '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798';
+const parent = '1'.repeat(64);
+const addressA = naddrEncode({
+ kind: 30402,
+ pubkey: peer,
+ identifier: 'carrots-a'
+});
+const addressB = naddrEncode({
+ kind: 30402,
+ pubkey: peer,
+ identifier: 'carrots-b'
+});
+const versionA = neventEncode({
+ id: '3'.repeat(64),
+ author: peer,
+ kind: 30402
+});
+const base: MessageV1 = {
+ recipients: [{ public_key: peer, relay_url: null }],
+ content: 'Could I buy carrots?\nPlease reply here.',
+ reply_to: null,
+ subject: null
+};
+export const qualifiedMessages: readonly MessageV1[] = [
+ base,
+ {
+ ...base,
+ recipients: [{ public_key: peer, relay_url: 'wss://hint.example.org' }]
+ },
+ { ...base, reply_to: { id: parent, relays: null } },
+ { ...base, reply_to: { id: parent, relays: 'wss://hint.example.org' } },
+ { ...base, subject: 'Carrots' },
+ { ...base, reply_to: { id: parent, relays: null }, subject: 'Carrots' },
+ { ...base, content: 'Fresh café' },
+ { ...base, content: 'Fresh cafe\u0301' },
+ { ...base, content: 'Line one\r\nLine two\rLine three\n' },
+ { ...base, content: '🥕'.repeat(1024) },
+ { ...base, content: ' Please keep these spaces. ' },
+ { ...base, content: '\ufeff' },
+ { ...base, content: '\u001c' },
+ { ...base, subject: '🥕'.repeat(160) },
+ {
+ ...base,
+ content: `Enquiry context: nostr:${addressA}\nViewed version: nostr:${versionA}\nEarlier conversation context: nostr:${addressB}`
+ },
+ {
+ ...base,
+ recipients: [
+ {
+ public_key:
+ '44900586091b284416a0c001f677f9c49f7639a55c3f1e2ec130a8e1a7998e1b',
+ relay_url: null
+ }
+ ],
+ reply_to: { id: '2'.repeat(64), relays: null },
+ subject: 'Another listing, same ordinary message fields'
+ }
+];
+export const qualifiedMessageReplay = qualifiedMessages.map(
+ (expected, index) => {
+ const wire_parts = messageToWireParts(JSON.stringify(expected));
+ if (!wire_parts || !messageFromWireParts(JSON.stringify(wire_parts)))
+ throw new Error(`Unsupported qualified Message recipe ${index}`);
+ return {
+ id: `qualified_message_${index.toString().padStart(3, '0')}`,
+ wire_parts,
+ expected
+ };
+ }
+);
diff --git a/web/tests/conformance/message-qualified-writer-rust.v1.json b/web/tests/conformance/message-qualified-writer-rust.v1.json
@@ -0,0 +1,250 @@
+{
+ "schema_version": 1,
+ "revision": "189c49b74b4bafc142b00b76b296477931139e72",
+ "recipe_sha256": "97ac1d122bededd3f84f73d99d239e892b91c59a0d528dfb80c5a516a34d7a5c",
+ "inputs": {
+ "message-qualified-matrix.ts": "1691845f50734191904b25f36fd54a54ddb146550d317b8563ce49a36202f807",
+ "source_profile.v1.json": "bff36b4941decca5471389e0155fb6b4027dac485c3e547be05743a936b5bc5f",
+ "corpus.v1.json": "27fb61b7d06133f6cf42456c0582d1246222755da80e034fa1a4f0c9e1669e19",
+ "oracle/src/main.rs": "290247c9151fb2490dc108a974eae7fe8633d085ee2d22c6aecbfb15306cd611"
+ },
+ "consumed": [
+ {
+ "id": "qualified_message_000",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_001",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": "wss://hint.example.org"
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_002",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": {
+ "id": "1111111111111111111111111111111111111111111111111111111111111111",
+ "relays": null
+ },
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_003",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": {
+ "id": "1111111111111111111111111111111111111111111111111111111111111111",
+ "relays": "wss://hint.example.org"
+ },
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_004",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": "Carrots"
+ }
+ },
+ {
+ "id": "qualified_message_005",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": {
+ "id": "1111111111111111111111111111111111111111111111111111111111111111",
+ "relays": null
+ },
+ "subject": "Carrots"
+ }
+ },
+ {
+ "id": "qualified_message_006",
+ "message": {
+ "content": "Fresh café",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_007",
+ "message": {
+ "content": "Fresh café",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_008",
+ "message": {
+ "content": "Line one\r\nLine two\rLine three\n",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_009",
+ "message": {
+ "content": "🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_010",
+ "message": {
+ "content": " Please keep these spaces. ",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_011",
+ "message": {
+ "content": "",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_012",
+ "message": {
+ "content": "\u001c",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_013",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": "🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕🥕"
+ }
+ },
+ {
+ "id": "qualified_message_014",
+ "message": {
+ "content": "Enquiry context: nostr:naddr1qvzqqqrkcgpzq7d7vel0nh9m4326qc54e6rskpczn07dktww9rv4nu5ptvt0s9ucqqykxctjwfhhguedvyd6eh6n\nViewed version: nostr:nevent1qvzqqqrkcgpzq7d7vel0nh9m4326qc54e6rskpczn07dktww9rv4nu5ptvt0s9ucqqsrxvenxvenxvenxvenxvenxvenxvenxvenxvenxvenxvenxvenxvcj7a7vp\nEarlier conversation context: nostr:naddr1qvzqqqrkcgpzq7d7vel0nh9m4326qc54e6rskpczn07dktww9rv4nu5ptvt0s9ucqqykxctjwfhhguedvguylat5",
+ "recipients": [
+ {
+ "public_key": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "relay_url": null
+ }
+ ],
+ "reply_to": null,
+ "subject": null
+ }
+ },
+ {
+ "id": "qualified_message_015",
+ "message": {
+ "content": "Could I buy carrots?\nPlease reply here.",
+ "recipients": [
+ {
+ "public_key": "44900586091b284416a0c001f677f9c49f7639a55c3f1e2ec130a8e1a7998e1b",
+ "relay_url": null
+ }
+ ],
+ "reply_to": {
+ "id": "2222222222222222222222222222222222222222222222222222222222222222",
+ "relays": null
+ },
+ "subject": "Another listing, same ordinary message fields"
+ }
+ }
+ ],
+ "qualification": "Actual pinned Rust99 consumes separate browser-owned unsigned kind 14 Message recipes; not independent-client receive/reply, encryption, extension, relay or publication qualification."
+}
diff --git a/web/tests/fixtures/independent-nip17/public-outer-wires.v1.json b/web/tests/fixtures/independent-nip17/public-outer-wires.v1.json
@@ -0,0 +1,48 @@
+{
+ "schema_version": 1,
+ "source": {
+ "url": "https://raw.githubusercontent.com/nostr-protocol/nips/0046368a747c5c25ae2bec28bae0e537744c8f10/17.md",
+ "revision": "0046368a747c5c25ae2bec28bae0e537744c8f10",
+ "sha256": "7aa9c3a9c0458a9552c4be2f3bf17f7ec60a4afe88bce7977f03500a7873a64c",
+ "bytes": 12439,
+ "scope": "Published peer/self outer ciphertext only; public signatures and destinations, not decrypted inner correspondence or independent-client receive/reply."
+ },
+ "cases": [
+ {
+ "role": "peer",
+ "fence_start_line": 190,
+ "event": {
+ "id": "2886780f7349afc1344047524540ee716f7bdc1b64191699855662330bf235d8",
+ "pubkey": "8f8a7ec43b77d25799281207e1a47f7a654755055788f7482653f9c9661c6d51",
+ "created_at": 1703128320,
+ "kind": 1059,
+ "tags": [
+ [
+ "p",
+ "918e2da906df4ccd12c8ac672d8335add131a4cf9d27ce42b3bb3625755f0788"
+ ]
+ ],
+ "content": "AsqzdlMsG304G8h08bE67dhAR1gFTzTckUUyuvndZ8LrGCvwI4pgC3d6hyAK0Wo9gtkLqSr2rT2RyHlE5wRqbCOlQ8WvJEKwqwIJwT5PO3l2RxvGCHDbd1b1o40ZgIVwwLCfOWJ86I5upXe8K5AgpxYTOM1BD+SbgI5jOMA8tgpRoitJedVSvBZsmwAxXM7o7sbOON4MXHzOqOZpALpS2zgBDXSAaYAsTdEM4qqFeik+zTk3+L6NYuftGidqVluicwSGS2viYWr5OiJ1zrj1ERhYSGLpQnPKrqDaDi7R1KrHGFGyLgkJveY/45y0rv9aVIw9IWF11u53cf2CP7akACel2WvZdl1htEwFu/v9cFXD06fNVZjfx3OssKM/uHPE9XvZttQboAvP5UoK6lv9o3d+0GM4/3zP+yO3C0NExz1ZgFmbGFz703YJzM+zpKCOXaZyzPjADXp8qBBeVc5lmJqiCL4solZpxA1865yPigPAZcc9acSUlg23J1dptFK4n3Tl5HfSHP+oZ/QS/SHWbVFCtq7ZMQSRxLgEitfglTNz9P1CnpMwmW/Y4Gm5zdkv0JrdUVrn2UO9ARdHlPsW5ARgDmzaxnJypkfoHXNfxGGXWRk0sKLbz/ipnaQP/eFJv/ibNuSfqL6E4BnN/tHJSHYEaTQ/PdrA2i9laG3vJti3kAl5Ih87ct0w/tzYfp4SRPhEF1zzue9G/16eJEMzwmhQ5Ec7jJVcVGa4RltqnuF8unUu3iSRTQ+/MNNUkK6Mk+YuaJJs6Fjw6tRHuWi57SdKKv7GGkr0zlBUU2Dyo1MwpAqzsCcCTeQSv+8qt4wLf4uhU9Br7F/L0ZY9bFgh6iLDCdB+4iABXyZwT7Ufn762195hrSHcU4Okt0Zns9EeiBOFxnmpXEslYkYBpXw70GmymQfJlFOfoEp93QKCMS2DAEVeI51dJV1e+6t3pCSsQN69Vg6jUCsm1TMxSs2VX4BRbq562+VffchvW2BB4gMjsvHVUSRl8i5/ZSDlfzSPXcSGALLHBRzy+gn0oXXJ/447VHYZJDL3Ig8+QW5oFMgnWYhuwI5QSLEyflUrfSz+Pdwn/5eyjybXKJftePBD9Q+8NQ8zulU5sqvsMeIx/bBUx0fmOXsS3vjqCXW5IjkmSUV7q54GewZqTQBlcx+90xh/LSUxXex7UwZwRnifvyCbZ+zwNTHNb12chYeNjMV7kAIr3cGQv8vlOMM8ajyaZ5KVy7HpSXQjz4PGT2/nXbL5jKt8Lx0erGXsSsazkdoYDG3U",
+ "sig": "a3c6ce632b145c0869423c1afaff4a6d764a9b64dedaf15f170b944ead67227518a72e455567ca1c2a0d187832cecbde7ed478395ec4c95dd3e71749ed66c480"
+ }
+ },
+ {
+ "role": "self",
+ "fence_start_line": 204,
+ "event": {
+ "id": "162b0611a1911cfcb30f8a5502792b346e535a45658b3a31ae5c178465509721",
+ "pubkey": "626be2af274b29ea4816ad672ee452b7cf96bbb4836815a55699ae402183f512",
+ "created_at": 1702711587,
+ "kind": 1059,
+ "tags": [
+ [
+ "p",
+ "44900586091b284416a0c001f677f9c49f7639a55c3f1e2ec130a8e1a7998e1b"
+ ]
+ ],
+ "content": "AsTClTzr0gzXXji7uye5UB6LYrx3HDjWGdkNaBS6BAX9CpHa+Vvtt5oI2xJrmWLen+Fo2NBOFazvl285Gb3HSM82gVycrzx1HUAaQDUG6HI7XBEGqBhQMUNwNMiN2dnilBMFC3Yc8ehCJT/gkbiNKOpwd2rFibMFRMDKai2mq2lBtPJF18oszKOjA+XlOJV8JRbmcAanTbEK5nA/GnG3eGUiUzhiYBoHomj3vztYYxc0QYHOx0WxiHY8dsC6jPsXC7f6k4P+Hv5ZiyTfzvjkSJOckel1lZuE5SfeZ0nduqTlxREGeBJ8amOykgEIKdH2VZBZB+qtOMc7ez9dz4wffGwBDA7912NFS2dPBr6txHNxBUkDZKFbuD5wijvonZDvfWq43tZspO4NutSokZB99uEiRH8NAUdGTiNb25m9JcDhVfdmABqTg5fIwwTwlem5aXIy8b66lmqqz2LBzJtnJDu36bDwkILph3kmvaKPD8qJXmPQ4yGpxIbYSTCohgt2/I0TKJNmqNvSN+IVoUuC7ZOfUV9lOV8Ri0AMfSr2YsdZ9ofV5o82ClZWlWiSWZwy6ypa7CuT1PEGHzywB4CZ5ucpO60Z7hnBQxHLiAQIO/QhiBp1rmrdQZFN6PUEjFDloykoeHe345Yqy9Ke95HIKUCS9yJurD+nZjjgOxZjoFCsB1hQAwINTIS3FbYOibZnQwv8PXvcSOqVZxC9U0+WuagK7IwxzhGZY3vLRrX01oujiRrevB4xbW7Oxi/Agp7CQGlJXCgmRE8Rhm+Vj2s+wc/4VLNZRHDcwtfejogjrjdi8p6nfUyqoQRRPARzRGUnnCbh+LqhigT6gQf3sVilnydMRScEc0/YYNLWnaw9nbyBa7wFBAiGbJwO40k39wj+xT6HTSbSUgFZzopxroO3f/o4+ubx2+IL3fkev22mEN38+dFmYF3zE+hpE7jVxrJpC3EP9PLoFgFPKCuctMnjXmeHoiGs756N5r1Mm1ffZu4H19MSuALJlxQR7VXE/LzxRXDuaB2u9days/6muP6gbGX1ASxbJd/ou8+viHmSC/ioHzNjItVCPaJjDyc6bv+gs1NPCt0qZ69G+JmgHW/PsMMeL4n5bh74g0fJSHqiI9ewEmOG/8bedSREv2XXtKV39STxPweceIOh0k23s3N6+wvuSUAJE7u1LkDo14cobtZ/MCw/QhimYPd1u5HnEJvRhPxz0nVPz0QqL/YQeOkAYk7uzgeb2yPzJ6DBtnTnGDkglekhVzQBFRJdk740LEj6swkJ",
+ "sig": "c94e74533b482aa8eeeb54ae72a5303e0b21f62909ca43c8ef06b0357412d6f8a92f96e1a205102753777fd25321a58fba3fb384eee114bd53ce6c06a1c22bab"
+ }
+ }
+ ]
+}
diff --git a/web/tools/check-message-interop.mjs b/web/tools/check-message-interop.mjs
@@ -16,10 +16,12 @@ import {
messageReplay,
actualWebMessage
} from '../tests/conformance/message-cases.ts';
+import { qualifiedMessageReplay } from '../tests/conformance/message-qualified-matrix.ts';
const args = process.argv.slice(2);
assert.ok(
- args.length === 0 || (args.length === 1 && args[0] === '--write'),
- 'expected no arguments or explicit --write'
+ args.length === 0 ||
+ (args.length === 1 && ['--write', '--write-qualified'].includes(args[0])),
+ 'expected no arguments or explicit --write or --write-qualified'
);
assert.equal(process.versions.node, '24.21.0');
const root = fileURLToPath(new URL('../../', import.meta.url));
@@ -215,23 +217,126 @@ const temporary = await mkdtemp(
join(tmpdir(), 'harvestcircle-message-interop-')
);
try {
- const replay = messageReplay();
- assert.ok(replay.length > 0);
- const file = join(temporary, 'web-to-rust.json');
- await writeFile(file, JSON.stringify(replay));
- const result = JSON.parse(success('cargo', [...cargo, '--consume', file]));
- assert.equal(result.revision, revision);
- assert.equal(result.consumed.length, replay.length);
- assert.deepEqual(
- result.consumed,
- replay.map((v) => ({ id: v.id, message: v.expected }))
+ async function consume(replay, batch) {
+ assert.ok(replay.length > 0);
+ const file = join(temporary, batch + '.json');
+ await writeFile(file, JSON.stringify(replay));
+ const result = JSON.parse(success('cargo', [...cargo, '--consume', file]));
+ assert.equal(result.revision, revision);
+ assert.equal(result.consumed.length, replay.length);
+ assert.deepEqual(
+ result.consumed,
+ replay.map((v) => ({ id: v.id, message: v.expected }))
+ );
+ return result;
+ }
+ const original = messageReplay();
+ assert.equal(original.length, 11);
+ await consume(original, 'original');
+ assert.equal(qualifiedMessageReplay.length, 16);
+ const qualified = await consume(qualifiedMessageReplay, 'qualified');
+ const recipePath = new URL(
+ '../tests/conformance/message-qualified-matrix.ts',
+ import.meta.url
+ );
+ const receiptPath = new URL(
+ '../tests/conformance/message-qualified-writer-rust.v1.json',
+ import.meta.url
);
+ const inputs = {
+ 'message-qualified-matrix.ts': digest(await readFile(recipePath))
+ };
+ for (const name of [
+ 'source_profile.v1.json',
+ 'corpus.v1.json',
+ 'oracle/src/main.rs'
+ ])
+ inputs[name] = digest(await owned(name));
+ const receipt = {
+ schema_version: 1,
+ revision,
+ recipe_sha256: digest(JSON.stringify(qualifiedMessageReplay)),
+ inputs,
+ consumed: qualified.consumed,
+ qualification:
+ 'Actual pinned Rust99 consumes separate browser-owned unsigned kind 14 Message recipes; not independent-client receive/reply, encryption, extension, relay or publication qualification.'
+ };
+ const existing = await lstat(receiptPath);
+ assert.ok(existing.isFile() && !existing.isSymbolicLink());
+ if (args[0] === '--write' || args[0] === '--write-qualified')
+ await writeFile(receiptPath, JSON.stringify(receipt, null, 2) + '\n');
+ assert.deepEqual(JSON.parse(await readFile(receiptPath, 'utf8')), receipt);
+ const controls = [
+ [
+ 'standalone-seal-kind',
+ 0,
+ (row) => {
+ row.wire_parts.kind = 13;
+ }
+ ],
+ [
+ 'missing-recipient',
+ 0,
+ (row) => {
+ row.wire_parts.tags = [];
+ }
+ ],
+ [
+ 'changed-reply-parent',
+ 2,
+ (row) => {
+ row.wire_parts.tags[1][1] = '4'.repeat(64);
+ }
+ ],
+ [
+ 'changed-subject',
+ 4,
+ (row) => {
+ row.wire_parts.tags[1][1] = 'Different subject';
+ }
+ ]
+ ];
+ for (const [mutation, index, change] of controls) {
+ const originalRow = qualifiedMessageReplay[index];
+ const row = {
+ ...originalRow,
+ wire_parts: {
+ ...originalRow.wire_parts,
+ tags: originalRow.wire_parts.tags.map((tag) => [...tag])
+ }
+ };
+ change(row);
+ const file = join(temporary, mutation + '.json');
+ await writeFile(file, JSON.stringify([row]));
+ const result = spawnSync('cargo', [...cargo, '--consume', file], {
+ cwd: root,
+ encoding: 'utf8',
+ maxBuffer: 1024 * 1024
+ });
+ assert.ifError(result.error);
+ assert.equal(result.signal, null);
+ assert.equal(result.status, 101, result.stderr || result.stdout);
+ assert.match(result.stderr, /assertion .* failed/);
+ console.log(
+ JSON.stringify({
+ direction: 'WEB_TO_RUST_NEGATIVE',
+ mutation,
+ exit_code: result.status,
+ actual_stderr: result.stderr
+ })
+ );
+ }
console.log(
- 'PASS actual Rust->web ' +
- corpus.vectors.length +
- ' and web->Rust ' +
- replay.length +
- ' Message cases; explicit web policy differences retained'
+ JSON.stringify({
+ result: 'PASS',
+ scope: 'SOURCE_ORACLE_NOT_INDEPENDENT_CLIENT_QUALIFICATION',
+ revision,
+ rust_reader_cases: corpus.vectors.length,
+ original_writer_cases: original.length,
+ qualified_writer_cases: qualifiedMessageReplay.length,
+ negative_controls: controls.length,
+ keys: 'NO_KEYS'
+ })
);
} finally {
await rm(temporary, { recursive: true, force: true });