message-qualified-matrix.ts (2559B)
1 import { naddrEncode, neventEncode } from 'applesauce-core/helpers/pointers'; 2 import { 3 messageToWireParts, 4 messageFromWireParts, 5 type MessageV1 6 } from '../../src/lib/contracts/message-v1/index.ts'; 7 8 // Separate browser-owned recipes. These pure projections grant no room, 9 // participant, extension, encryption, persistence or publication authority. 10 const peer = '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'; 11 const parent = '1'.repeat(64); 12 const addressA = naddrEncode({ 13 kind: 30402, 14 pubkey: peer, 15 identifier: 'carrots-a' 16 }); 17 const addressB = naddrEncode({ 18 kind: 30402, 19 pubkey: peer, 20 identifier: 'carrots-b' 21 }); 22 const versionA = neventEncode({ 23 id: '3'.repeat(64), 24 author: peer, 25 kind: 30402 26 }); 27 const base: MessageV1 = { 28 recipients: [{ public_key: peer, relay_url: null }], 29 content: 'Could I buy carrots?\nPlease reply here.', 30 reply_to: null, 31 subject: null 32 }; 33 export const qualifiedMessages: readonly MessageV1[] = [ 34 base, 35 { 36 ...base, 37 recipients: [{ public_key: peer, relay_url: 'wss://hint.example.org' }] 38 }, 39 { ...base, reply_to: { id: parent, relays: null } }, 40 { ...base, reply_to: { id: parent, relays: 'wss://hint.example.org' } }, 41 { ...base, subject: 'Carrots' }, 42 { ...base, reply_to: { id: parent, relays: null }, subject: 'Carrots' }, 43 { ...base, content: 'Fresh café' }, 44 { ...base, content: 'Fresh cafe\u0301' }, 45 { ...base, content: 'Line one\r\nLine two\rLine three\n' }, 46 { ...base, content: '🥕'.repeat(1024) }, 47 { ...base, content: ' Please keep these spaces. ' }, 48 { ...base, content: '\ufeff' }, 49 { ...base, content: '\u001c' }, 50 { ...base, subject: '🥕'.repeat(160) }, 51 { 52 ...base, 53 content: `Enquiry context: nostr:${addressA}\nViewed version: nostr:${versionA}\nEarlier conversation context: nostr:${addressB}` 54 }, 55 { 56 ...base, 57 recipients: [ 58 { 59 public_key: 60 '44900586091b284416a0c001f677f9c49f7639a55c3f1e2ec130a8e1a7998e1b', 61 relay_url: null 62 } 63 ], 64 reply_to: { id: '2'.repeat(64), relays: null }, 65 subject: 'Another listing, same ordinary message fields' 66 } 67 ]; 68 export const qualifiedMessageReplay = qualifiedMessages.map( 69 (expected, index) => { 70 const wire_parts = messageToWireParts(JSON.stringify(expected)); 71 if (!wire_parts || !messageFromWireParts(JSON.stringify(wire_parts))) 72 throw new Error(`Unsupported qualified Message recipe ${index}`); 73 return { 74 id: `qualified_message_${index.toString().padStart(3, '0')}`, 75 wire_parts, 76 expected 77 }; 78 } 79 );