import * as Mppx from 'mppx' import * as Store from '../../../internal/Store.js' /** Returns the normalized Tempo sender and recipients in a validated credential. */ export function addresses(result: Awaited>) { const details = result.details as { sender?: string transfers?: readonly { recipient: string }[] } return [details.sender, ...(details.transfers?.map(({ recipient }) => recipient) ?? [])] .filter((address): address is string => address !== undefined) .map((address) => address.toLowerCase()) .filter((address, index, values) => values.indexOf(address) === index) } /** Adapts Tempo API durable state to MPPX's atomic Cloudflare store contract. */ export function mppxStore(state: Store.State): Mppx.Store.AtomicStore { return Mppx.Store.cloudflare({ delete: (key) => state.delete(key), get: (key) => state.get(key), put: (key, value) => state.put(key, value), update: (key, change) => Store.change(state, key, (current) => { const next = change(current) // MPPX's Cloudflare adapter represents a missing value with JSON null. return next.op === 'delete' ? { ...next, op: 'set', value: 'null' as const } : next }), }) }