app

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

inbox-readback.ts (2019B)


      1 export * from './inbox-preference-publisher.ts';
      2 export {
      3   createPublicRuntimeContext,
      4   mountPublicRuntime,
      5   createPublicView,
      6   beginPublicViewRun,
      7   disposePublicView,
      8   closePublicRuntime
      9 } from '../../../src/lib/runtime/public-runtime.ts';
     10 export {
     11   createPrivateSession,
     12   closePrivateSession
     13 } from '../../../src/lib/runtime/private-session.ts';
     14 export {
     15   resolveInboxReadback,
     16   inboxReadbackSnapshot,
     17   inboxReadbackEvidence,
     18   closeInboxReadback
     19 } from '../../../src/lib/nostr/inbox-readback.ts';
     20 export {
     21   verifyInboxSetupOperation,
     22   existingInboxSetupSnapshot
     23 } from '../../../src/lib/messaging/inbox-setup-verification.ts';
     24 
     25 import type { RequestClock } from '../../../src/lib/nostr/request-scope.ts';
     26 export function makeReadbackClock() {
     27   const state: { next?: () => void } = {};
     28   const clock: RequestClock = {
     29     now: () => {
     30       const next = state.next;
     31       state.next = undefined;
     32       next?.();
     33       return performance.now();
     34     },
     35     schedule: (callback, delay) => {
     36       const timer = setTimeout(callback, delay);
     37       return () => clearTimeout(timer);
     38     }
     39   };
     40   return {
     41     clock,
     42     once: (callback: () => void) => {
     43       state.next = callback;
     44     }
     45   };
     46 }
     47 
     48 import { makePublisherFixture } from './inbox-preference-publisher.ts';
     49 import {
     50   validateRelayPolicy,
     51   readRelayPolicy
     52 } from '../../../src/lib/config/relays.ts';
     53 export async function makeDisjointReadbackFixture() {
     54   const fixture = await makePublisherFixture();
     55   const manifest = readRelayPolicy(fixture.policy);
     56   const policy = validateRelayPolicy(
     57     JSON.stringify({
     58       ...manifest,
     59       public: [
     60         {
     61           origin: 'wss://discovery.example.org',
     62           read: true,
     63           write: false,
     64           nip50: false
     65         },
     66         {
     67           origin: 'wss://publisher.example.org',
     68           read: false,
     69           write: true,
     70           nip50: false
     71         }
     72       ]
     73     })
     74   );
     75   if (!policy) throw new Error('invalid actual disjoint policy');
     76   return { ...fixture, policy };
     77 }