app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 19c5fc473accb3f750e9428165d5a1b70206d203
parent 1c07aca935b7ef41e527d12b3ae94bfb37cdc0fa
Author: triesap <tyson@radroots.org>
Date:   Mon,  5 Oct 2026 16:50:22 +0000

web: bound product coordinate encoding (HCP-017)

- Snapshot the validated coordinate fields before Applesauce encoding.
- Exclude extra relay fields and getters from encoding work.
- Verify exact coordinate fidelity with both regression controls.
- Preserve bounded input and qualified primitive source admission.

Diffstat:
Mweb/src/lib/nostr/references.ts | 17+++++++++--------
Mweb/tests/unit/references.test.ts | 26++++++++++++++++++++++++++
Mweb/tools/source-boundaries.mjs | 2+-
3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/web/src/lib/nostr/references.ts b/web/src/lib/nostr/references.ts @@ -88,19 +88,20 @@ export function decodeProductReference( export function encodeProductReference( value: Readonly<{ kind: number; pubkey: string; identifier: string }> ): string | undefined { + const { kind, pubkey, identifier } = value; if ( - value.kind !== 30402 || - canonicalPublicKey(value.pubkey) === undefined || - typeof value.identifier !== 'string' || - !value.identifier.isWellFormed() || - value.identifier.length > 255 || - encoder.encode(value.identifier).length > 255 + kind !== 30402 || + canonicalPublicKey(pubkey) === undefined || + typeof identifier !== 'string' || + !identifier.isWellFormed() || + identifier.length > 255 || + encoder.encode(identifier).length > 255 ) return undefined; try { - const encoded = naddrEncode(value); + const encoded = naddrEncode({ kind: 30402, pubkey, identifier }); const decoded = decodeProductReference(encoded); - return decoded?.identifier === value.identifier ? decoded.naddr : undefined; + return decoded?.identifier === identifier ? decoded.naddr : undefined; } catch { return undefined; } diff --git a/web/tests/unit/references.test.ts b/web/tests/unit/references.test.ts @@ -29,6 +29,32 @@ const wrap = (data: Uint8Array) => bech32.encode('naddr', bech32.toWords(data), 2048); describe('bounded exact product references', () => { + it('ignores extra relay hints when encoding the same raw coordinate', () => { + const coordinate = { kind: 30402, pubkey, identifier: 'Carrots:菜' }; + const subtype = { + ...coordinate, + relays: ['wss://example.invalid/' + 'x'.repeat(2500)] + }; + expect(encodeProductReference(subtype)).toBe( + pointers.naddrEncode(coordinate) + ); + }); + it('never reads extra relay getters during coordinate encoding', () => { + const coordinate = { kind: 30402, pubkey, identifier: 'Carrots:菜' }; + const read = vi.fn(() => { + throw new Error('Extra relay field read'); + }); + const subtype = { + ...coordinate, + get relays() { + return read(); + } + }; + expect(encodeProductReference(subtype)).toBe( + pointers.naddrEncode(coordinate) + ); + expect(read).not.toHaveBeenCalled(); + }); for (const row of oracle.coordinate_cases) it(`Rust raw identifier ${JSON.stringify(row.identifier)}`, () => { const input = encode(row.identifier); diff --git a/web/tools/source-boundaries.mjs b/web/tools/source-boundaries.mjs @@ -1323,7 +1323,7 @@ export async function auditSource(root) { import: '@scure/base', file: 'src/lib/nostr/references.ts', sha256: - 'b6a2ee32e89b60410bd84f5bbf2adc464d4f9d4d29b6a067e75927540b006ac4' + 'b417864961a184cab732bebab4fb35089034dbb6a742068d2742f7b353525d80' } }; const primitive = Object.hasOwn(primitiveAdmissions, actualName)