@tangle-network/blueprint-ui 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/iframe/testing.tsx"],"sourcesContent":["// Testing harness for iframe blueprints. The promise of the SDK is that\n// publishers can iterate on their UI without running the Tangle Cloud dapp\n// — these utilities are what makes that true.\n\nimport {\n type FC,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { Address } from 'viem';\n\nimport type {\n ServiceSnapshot,\n WalletSnapshot,\n} from './tangleIframeClient';\nimport type {\n CallJobRequest,\n JobInputs,\n JobResultEvent,\n ParentMessage,\n ServiceContextBroadcast,\n ServiceContextJob,\n ServiceContextOperator,\n} from '../wallet/parentBridgeProtocol';\n\nexport type MockWalletInput = Partial<{\n address: Address | null;\n chainId: number;\n isConnected: boolean;\n}>;\n\nexport type MockServiceInput = Partial<{\n blueprintId: string;\n serviceId: string | null;\n operators: readonly ServiceContextOperator[];\n jobs: readonly ServiceContextJob[];\n mode: string | null;\n}>;\n\n/**\n * Construct a deterministic wallet snapshot for tests. Defaults:\n * connected, vitalik.eth's address, Base Sepolia (84532).\n */\nexport function mockWallet(input: MockWalletInput = {}): WalletSnapshot {\n return {\n address:\n input.address === undefined\n ? '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'\n : input.address,\n chainId: input.chainId ?? 84532,\n isConnected: input.isConnected ?? input.address !== null,\n };\n}\n\n/**\n * Construct a deterministic service snapshot for tests. Defaults: blueprint\n * id `0`, no service deployed yet (serviceId null), single mock operator on\n * the canonical local sidecar URL.\n */\nexport function mockServiceContext(\n input: MockServiceInput = {},\n): ServiceSnapshot {\n return {\n blueprintId: input.blueprintId ?? '0',\n serviceId: input.serviceId === undefined ? null : input.serviceId,\n operators:\n input.operators ?? [\n {\n address: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',\n rpcAddress: 'http://localhost:8545',\n status: 'active',\n },\n ],\n jobs:\n input.jobs ?? [\n { index: 0, name: 'invoke' },\n ],\n mode: input.mode ?? null,\n };\n}\n\nexport type CallJobHandler = (\n request: CallJobRequest,\n) => Promise<{\n status: 'success' | 'error';\n data?: unknown;\n error?: string;\n /** Streaming chunks emitted in order before the terminal status. */\n chunks?: readonly unknown[];\n}>;\n\ntype HarnessProps = {\n appId?: string;\n wallet?: WalletSnapshot;\n service?: ServiceSnapshot;\n /** Override callJob behavior. Default: returns a static `{ ok: true }`. */\n onCallJob?: CallJobHandler;\n /** Surface a floating debug panel that lets the developer flip state at runtime. */\n showDebugPanel?: boolean;\n children: ReactNode;\n};\n\n/**\n * Drop-in parent simulator for tests + storybook + standalone dev. Wraps\n * children in a fake parent that:\n *\n * - Acks the iframe's handshake immediately\n * - Broadcasts the configured wallet + service context on mount\n * - Intercepts `callJob` requests and routes them through `onCallJob`\n * - (Optional) Mounts a floating debug panel so the developer can\n * mutate state at runtime: change account, switch chain, set\n * serviceId, fire a custom job\n *\n * The harness runs in the same JS context as the iframe app — there's no\n * cross-frame postMessage, just same-window event dispatch. That keeps it\n * fully synchronous + assertable, but the messages still flow through the\n * exact same protocol surface the production bridge uses.\n *\n * Usage:\n *\n * <TangleParentHarness wallet={mockWallet()} service={mockServiceContext()}>\n * <TangleIframeProvider appId=\"my-app\" mode=\"bridge\" parentOrigin=\"harness://\">\n * <App />\n * </TangleIframeProvider>\n * </TangleParentHarness>\n *\n * Set `mode=\"bridge\"` + `parentOrigin=\"harness://\"` on the provider so it\n * matches the harness's synthetic origin. In production, use `mode=\"auto\"`\n * (the default).\n */\nexport const TangleParentHarness: FC<HarnessProps> = ({\n appId = 'harness',\n wallet = mockWallet(),\n service = mockServiceContext(),\n onCallJob,\n showDebugPanel = false,\n children,\n}) => {\n const [currentWallet, setCurrentWallet] = useState<WalletSnapshot>(wallet);\n const [currentService, setCurrentService] =\n useState<ServiceSnapshot>(service);\n const [callLog, setCallLog] = useState<CallJobRequest[]>([]);\n const callJobHandler = useRef<CallJobHandler | undefined>(onCallJob);\n callJobHandler.current = onCallJob;\n const seenHandshake = useRef(false);\n\n // Listen for iframe → \"parent\" messages. Since the harness shares the\n // window, `window.postMessage` with the synthetic origin is the easiest\n // wire — the iframe SDK posts to `window.parent`, which in same-window\n // mode IS this listener.\n useEffect(() => {\n const reply = (message: ParentMessage) => {\n window.dispatchEvent(\n new MessageEvent('message', {\n data: message,\n origin: HARNESS_ORIGIN,\n }),\n );\n };\n\n const broadcast = () => {\n const broadcastMsg: ServiceContextBroadcast = {\n kind: 'tangle.app.serviceContext',\n blueprintId: currentService.blueprintId ?? '0',\n serviceId: currentService.serviceId,\n operators: currentService.operators,\n jobs: currentService.jobs,\n mode: currentService.mode,\n };\n reply(broadcastMsg);\n // Also broadcast wallet — combined into accountChanged + chainChanged.\n reply({\n kind: 'tangle.app.accountChanged',\n account: currentWallet.address,\n });\n if (currentWallet.chainId !== null) {\n reply({\n kind: 'tangle.app.chainChanged',\n chainId: currentWallet.chainId,\n });\n }\n };\n\n const handler = async (event: MessageEvent) => {\n // The iframe posts via `window.parent.postMessage(msg, parentOrigin)`.\n // In same-window mode, that fires a message event on this same window\n // with origin = parentOrigin. Filter out events the harness itself\n // dispatched (origin === HARNESS_ORIGIN) — those are replies.\n if (event.origin === HARNESS_ORIGIN) return;\n const data = event.data;\n if (typeof data !== 'object' || data === null) return;\n const message = data as { kind?: string; correlationId?: string };\n\n switch (message.kind) {\n case 'tangle.app.handshake': {\n if (!seenHandshake.current) {\n seenHandshake.current = true;\n reply({\n kind: 'tangle.app.handshakeAck',\n appId,\n protocolVersion: '1',\n });\n broadcast();\n }\n return;\n }\n case 'tangle.app.readAccount': {\n if (typeof message.correlationId !== 'string') return;\n reply({\n kind: 'tangle.app.readAccountResult',\n correlationId: message.correlationId,\n ok: true,\n data: {\n account:\n currentWallet.address ??\n ('0x0000000000000000000000000000000000000000' as Address),\n chainId: currentWallet.chainId ?? 0,\n },\n });\n return;\n }\n case 'tangle.app.callJob': {\n if (typeof message.correlationId !== 'string') return;\n const request = message as unknown as CallJobRequest;\n setCallLog((prev) => [...prev, request]);\n // Default behavior when no handler: emit a single `success` with\n // a echo of the inputs so UIs render *something* in dev mode.\n const handler = callJobHandler.current;\n if (!handler) {\n const result: JobResultEvent = {\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: 'success',\n data: { echo: request.inputs },\n };\n reply(result);\n return;\n }\n try {\n const outcome = await handler(request);\n for (const chunk of outcome.chunks ?? []) {\n reply({\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: 'streaming',\n chunk,\n });\n }\n reply({\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: outcome.status,\n ...(outcome.data !== undefined ? { data: outcome.data } : {}),\n ...(outcome.error !== undefined ? { error: outcome.error } : {}),\n });\n } catch (err) {\n reply({\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: 'error',\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return;\n }\n // Wallet ops respond optimistically — tests that want to assert\n // specific signatures should pre-set them via the dev handler.\n case 'tangle.app.signMessage': {\n if (typeof message.correlationId !== 'string') return;\n reply({\n kind: 'tangle.app.signMessageResult',\n correlationId: message.correlationId,\n ok: true,\n data: { signature: '0xdeadbeef' as `0x${string}` },\n });\n return;\n }\n case 'tangle.app.signTransaction': {\n if (typeof message.correlationId !== 'string') return;\n reply({\n kind: 'tangle.app.signTransactionResult',\n correlationId: message.correlationId,\n ok: true,\n data: { txHash: ('0x' + '00'.repeat(32)) as `0x${string}` },\n });\n return;\n }\n case 'tangle.app.switchChain': {\n if (\n typeof message.correlationId !== 'string' ||\n typeof (message as unknown as { chainId?: number }).chainId !== 'number'\n ) {\n return;\n }\n const chainId = (message as unknown as { chainId: number }).chainId;\n setCurrentWallet((w) => ({ ...w, chainId }));\n reply({\n kind: 'tangle.app.switchChainResult',\n correlationId: message.correlationId,\n ok: true,\n data: { chainId },\n });\n return;\n }\n }\n };\n window.addEventListener('message', handler);\n return () => window.removeEventListener('message', handler);\n }, [appId, currentWallet, currentService]);\n\n // Re-broadcast when state changes.\n useEffect(() => {\n if (!seenHandshake.current) return;\n window.dispatchEvent(\n new MessageEvent('message', {\n data: {\n kind: 'tangle.app.accountChanged',\n account: currentWallet.address,\n },\n origin: HARNESS_ORIGIN,\n }),\n );\n }, [currentWallet.address]);\n\n useEffect(() => {\n if (!seenHandshake.current || currentWallet.chainId === null) return;\n window.dispatchEvent(\n new MessageEvent('message', {\n data: {\n kind: 'tangle.app.chainChanged',\n chainId: currentWallet.chainId,\n },\n origin: HARNESS_ORIGIN,\n }),\n );\n }, [currentWallet.chainId]);\n\n useEffect(() => {\n if (!seenHandshake.current) return;\n window.dispatchEvent(\n new MessageEvent('message', {\n data: {\n kind: 'tangle.app.serviceContext',\n blueprintId: currentService.blueprintId ?? '0',\n serviceId: currentService.serviceId,\n operators: currentService.operators,\n jobs: currentService.jobs,\n mode: currentService.mode,\n },\n origin: HARNESS_ORIGIN,\n }),\n );\n }, [currentService]);\n\n const debugApi = useMemo(\n () => ({\n setWallet: setCurrentWallet,\n setService: setCurrentService,\n callLog,\n }),\n [callLog],\n );\n\n return (\n <>\n {children}\n {showDebugPanel && <DebugPanel api={debugApi} />}\n </>\n );\n};\n\n/**\n * Synthetic origin every harness instance uses. Stable across tests so the\n * iframe SDK + the harness can pin to the same string.\n */\nexport const HARNESS_ORIGIN = 'harness://tangle.local';\n\n// ── Debug panel ──────────────────────────────────────────────────────────────\n\nconst DebugPanel: FC<{\n api: {\n setWallet: (w: WalletSnapshot | ((prev: WalletSnapshot) => WalletSnapshot)) => void;\n setService: (\n s: ServiceSnapshot | ((prev: ServiceSnapshot) => ServiceSnapshot),\n ) => void;\n callLog: readonly CallJobRequest[];\n };\n}> = ({ api }) => {\n const [open, setOpen] = useState(true);\n const [tab, setTab] = useState<'wallet' | 'service' | 'log'>('wallet');\n if (!open) {\n return (\n <button\n type=\"button\"\n onClick={() => setOpen(true)}\n style={debugStyles.collapsedTrigger}\n >\n Debug\n </button>\n );\n }\n return (\n <div style={debugStyles.panel}>\n <header style={debugStyles.header}>\n <strong style={{ fontSize: 11 }}>TANGLE DEV HARNESS</strong>\n <button\n type=\"button\"\n onClick={() => setOpen(false)}\n style={debugStyles.closeButton}\n aria-label=\"Close debug panel\"\n >\n ×\n </button>\n </header>\n <nav style={debugStyles.tabs}>\n {(['wallet', 'service', 'log'] as const).map((t) => (\n <button\n key={t}\n type=\"button\"\n onClick={() => setTab(t)}\n style={{\n ...debugStyles.tab,\n ...(tab === t ? debugStyles.tabActive : {}),\n }}\n >\n {t}\n </button>\n ))}\n </nav>\n <div style={debugStyles.body}>\n {tab === 'wallet' && <WalletTab api={api} />}\n {tab === 'service' && <ServiceTab api={api} />}\n {tab === 'log' && <CallLogTab callLog={api.callLog} />}\n </div>\n </div>\n );\n};\n\nconst WalletTab: FC<{\n api: { setWallet: (w: WalletSnapshot | ((prev: WalletSnapshot) => WalletSnapshot)) => void };\n}> = ({ api }) => {\n const [address, setAddressInput] = useState(\n '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',\n );\n const [chainId, setChainIdInput] = useState('84532');\n const applyConnect = useCallback(() => {\n api.setWallet({\n address: address as Address,\n chainId: Number(chainId) || null,\n isConnected: true,\n });\n }, [address, chainId, api]);\n const disconnect = useCallback(() => {\n api.setWallet({ address: null, chainId: null, isConnected: false });\n }, [api]);\n return (\n <div>\n <label style={debugStyles.label}>address</label>\n <input\n value={address}\n onChange={(e) => setAddressInput(e.target.value)}\n style={debugStyles.input}\n />\n <label style={debugStyles.label}>chain id</label>\n <input\n value={chainId}\n onChange={(e) => setChainIdInput(e.target.value)}\n style={debugStyles.input}\n />\n <div style={debugStyles.buttonRow}>\n <button type=\"button\" onClick={applyConnect} style={debugStyles.primary}>\n Set connected\n </button>\n <button type=\"button\" onClick={disconnect} style={debugStyles.secondary}>\n Disconnect\n </button>\n </div>\n </div>\n );\n};\n\nconst ServiceTab: FC<{\n api: {\n setService: (\n s: ServiceSnapshot | ((prev: ServiceSnapshot) => ServiceSnapshot),\n ) => void;\n };\n}> = ({ api }) => {\n const [serviceId, setServiceIdInput] = useState('1');\n const [blueprintId, setBlueprintIdInput] = useState('0');\n const apply = useCallback(() => {\n api.setService((prev) => ({\n ...prev,\n serviceId: serviceId || null,\n blueprintId,\n }));\n }, [api, serviceId, blueprintId]);\n const clearService = useCallback(() => {\n api.setService((prev) => ({ ...prev, serviceId: null }));\n }, [api]);\n return (\n <div>\n <label style={debugStyles.label}>blueprint id</label>\n <input\n value={blueprintId}\n onChange={(e) => setBlueprintIdInput(e.target.value)}\n style={debugStyles.input}\n />\n <label style={debugStyles.label}>service id (empty = not deployed)</label>\n <input\n value={serviceId}\n onChange={(e) => setServiceIdInput(e.target.value)}\n style={debugStyles.input}\n />\n <div style={debugStyles.buttonRow}>\n <button type=\"button\" onClick={apply} style={debugStyles.primary}>\n Apply\n </button>\n <button type=\"button\" onClick={clearService} style={debugStyles.secondary}>\n Clear service\n </button>\n </div>\n </div>\n );\n};\n\nconst CallLogTab: FC<{ callLog: readonly CallJobRequest[] }> = ({ callLog }) => {\n if (callLog.length === 0) {\n return <p style={debugStyles.empty}>No callJob requests yet.</p>;\n }\n return (\n <ol style={debugStyles.log}>\n {callLog.map((entry) => (\n <li key={entry.correlationId} style={debugStyles.logEntry}>\n <strong>job {entry.jobIndex}</strong>\n <pre style={debugStyles.pre}>\n {JSON.stringify(entry.inputs, null, 2)}\n </pre>\n </li>\n ))}\n </ol>\n );\n};\n\n// Inline styles keep the harness style-system-agnostic — consumers may not\n// ship Tailwind, and the panel shouldn't add a dependency.\nconst debugStyles = {\n panel: {\n position: 'fixed' as const,\n right: 12,\n top: 12,\n width: 280,\n zIndex: 99999,\n background: '#0b0b14',\n color: '#fff',\n border: '1px solid #3a3a52',\n borderRadius: 10,\n boxShadow: '0 14px 32px rgba(0,0,0,0.4)',\n fontFamily:\n 'ui-monospace, SFMono-Regular, Menlo, Monaco, \"Cascadia Code\", monospace',\n fontSize: 12,\n },\n header: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n padding: '8px 10px',\n borderBottom: '1px solid #2a2a3e',\n },\n closeButton: {\n background: 'none',\n border: 'none',\n color: '#fff',\n fontSize: 18,\n cursor: 'pointer',\n lineHeight: 1,\n },\n tabs: {\n display: 'flex',\n borderBottom: '1px solid #2a2a3e',\n },\n tab: {\n flex: 1,\n background: 'none',\n border: 'none',\n color: '#a0a0c0',\n padding: '6px 8px',\n cursor: 'pointer',\n fontSize: 11,\n textTransform: 'uppercase' as const,\n },\n tabActive: {\n color: '#fff',\n borderBottom: '2px solid #818cf8',\n },\n body: {\n padding: 10,\n maxHeight: 320,\n overflow: 'auto' as const,\n },\n label: {\n display: 'block',\n color: '#a0a0c0',\n fontSize: 10,\n marginBottom: 4,\n marginTop: 6,\n textTransform: 'uppercase' as const,\n },\n input: {\n width: '100%',\n background: '#15152a',\n border: '1px solid #2a2a3e',\n color: '#fff',\n padding: '6px 8px',\n borderRadius: 4,\n fontFamily: 'inherit',\n fontSize: 11,\n boxSizing: 'border-box' as const,\n },\n buttonRow: { display: 'flex', gap: 6, marginTop: 8 },\n primary: {\n flex: 1,\n background: '#4f46e5',\n color: '#fff',\n border: 'none',\n padding: '6px 8px',\n borderRadius: 4,\n cursor: 'pointer',\n fontSize: 11,\n fontFamily: 'inherit',\n },\n secondary: {\n flex: 1,\n background: 'transparent',\n color: '#a0a0c0',\n border: '1px solid #3a3a52',\n padding: '6px 8px',\n borderRadius: 4,\n cursor: 'pointer',\n fontSize: 11,\n fontFamily: 'inherit',\n },\n collapsedTrigger: {\n position: 'fixed' as const,\n right: 12,\n top: 12,\n zIndex: 99999,\n padding: '6px 10px',\n background: '#0b0b14',\n border: '1px solid #3a3a52',\n color: '#fff',\n borderRadius: 6,\n fontFamily: 'inherit',\n fontSize: 11,\n cursor: 'pointer',\n },\n log: { listStyle: 'none', padding: 0, margin: 0 },\n logEntry: {\n padding: 6,\n borderBottom: '1px solid #2a2a3e',\n fontSize: 11,\n },\n pre: {\n margin: '4px 0 0',\n color: '#a0a0c0',\n fontSize: 10,\n whiteSpace: 'pre-wrap' as const,\n wordBreak: 'break-word' as const,\n },\n empty: { color: '#a0a0c0', fontSize: 11, margin: 0 },\n} as const;\n\nexport type { JobInputs };\n"],"mappings":";AAIA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAoWH,mBAEqB,KAFrB;AAjUG,SAAS,WAAW,QAAyB,CAAC,GAAmB;AACtE,SAAO;AAAA,IACL,SACE,MAAM,YAAY,SACd,+CACA,MAAM;AAAA,IACZ,SAAS,MAAM,WAAW;AAAA,IAC1B,aAAa,MAAM,eAAe,MAAM,YAAY;AAAA,EACtD;AACF;AAOO,SAAS,mBACd,QAA0B,CAAC,GACV;AACjB,SAAO;AAAA,IACL,aAAa,MAAM,eAAe;AAAA,IAClC,WAAW,MAAM,cAAc,SAAY,OAAO,MAAM;AAAA,IACxD,WACE,MAAM,aAAa;AAAA,MACjB;AAAA,QACE,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,IACF,MACE,MAAM,QAAQ;AAAA,MACZ,EAAE,OAAO,GAAG,MAAM,SAAS;AAAA,IAC7B;AAAA,IACF,MAAM,MAAM,QAAQ;AAAA,EACtB;AACF;AAmDO,IAAM,sBAAwC,CAAC;AAAA,EACpD,QAAQ;AAAA,EACR,SAAS,WAAW;AAAA,EACpB,UAAU,mBAAmB;AAAA,EAC7B;AAAA,EACA,iBAAiB;AAAA,EACjB;AACF,MAAM;AACJ,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAyB,MAAM;AACzE,QAAM,CAAC,gBAAgB,iBAAiB,IACtC,SAA0B,OAAO;AACnC,QAAM,CAAC,SAAS,UAAU,IAAI,SAA2B,CAAC,CAAC;AAC3D,QAAM,iBAAiB,OAAmC,SAAS;AACnE,i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AY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,EACV;AAAA,EACA,KAAK,EAAE,WAAW,QAAQ,SAAS,GAAG,QAAQ,EAAE;AAAA,EAChD,UAAU;AAAA,IACR,SAAS;AAAA,IACT,cAAc;AAAA,IACd,UAAU;AAAA,EACZ;AAAA,EACA,KAAK;AAAA,IACH,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,WAAW;AAAA,EACb;AAAA,EACA,OAAO,EAAE,OAAO,WAAW,UAAU,IAAI,QAAQ,EAAE;AACrD;","names":["handler"]}
1
+ {"version":3,"sources":["../../src/iframe/testing.tsx"],"sourcesContent":["// Testing harness for iframe blueprints. The promise of the SDK is that\n// publishers can iterate on their UI without running the Tangle Cloud dapp\n// — these utilities are what makes that true.\n\nimport {\n type FC,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { Address } from 'viem';\n\nimport type {\n ServiceSnapshot,\n WalletSnapshot,\n} from './tangleIframeClient';\nimport type {\n CallJobRequest,\n JobInputs,\n JobResultEvent,\n ParentMessage,\n ServiceContextBroadcast,\n ServiceContextJob,\n ServiceContextOperator,\n} from '../wallet/parentBridgeProtocol';\n\nexport type MockWalletInput = Partial<{\n address: Address | null;\n chainId: number;\n isConnected: boolean;\n}>;\n\nexport type MockServiceInput = Partial<{\n blueprintId: string;\n serviceId: string | null;\n operators: readonly ServiceContextOperator[];\n jobs: readonly ServiceContextJob[];\n mode: string | null;\n chain: import('../wallet/parentBridgeProtocol').ChainContext | null;\n}>;\n\n/**\n * Construct a deterministic wallet snapshot for tests. Defaults:\n * connected, vitalik.eth's address, Base Sepolia (84532).\n */\nexport function mockWallet(input: MockWalletInput = {}): WalletSnapshot {\n return {\n address:\n input.address === undefined\n ? '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'\n : input.address,\n chainId: input.chainId ?? 84532,\n isConnected: input.isConnected ?? input.address !== null,\n };\n}\n\n/**\n * Construct a deterministic service snapshot for tests. Defaults: blueprint\n * id `0`, no service deployed yet (serviceId null), single mock operator on\n * the canonical local sidecar URL.\n */\nexport function mockServiceContext(\n input: MockServiceInput = {},\n): ServiceSnapshot {\n return {\n blueprintId: input.blueprintId ?? '0',\n serviceId: input.serviceId === undefined ? null : input.serviceId,\n operators:\n input.operators ?? [\n {\n address: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',\n rpcAddress: 'http://localhost:8545',\n status: 'active',\n },\n ],\n jobs:\n input.jobs ?? [\n { index: 0, name: 'invoke' },\n ],\n mode: input.mode ?? null,\n chain:\n input.chain === undefined\n ? {\n id: 84532,\n name: 'Base Sepolia',\n rpcUrl: 'https://sepolia.base.org',\n blockExplorerUrl: 'https://sepolia.basescan.org',\n nativeCurrency: { name: 'Sepolia Ether', symbol: 'ETH', decimals: 18 },\n }\n : input.chain,\n };\n}\n\nexport type CallJobHandler = (\n request: CallJobRequest,\n) => Promise<{\n status: 'success' | 'error';\n data?: unknown;\n error?: string;\n /** Streaming chunks emitted in order before the terminal status. */\n chunks?: readonly unknown[];\n}>;\n\ntype HarnessProps = {\n appId?: string;\n wallet?: WalletSnapshot;\n service?: ServiceSnapshot;\n /** Override callJob behavior. Default: returns a static `{ ok: true }`. */\n onCallJob?: CallJobHandler;\n /** Surface a floating debug panel that lets the developer flip state at runtime. */\n showDebugPanel?: boolean;\n children: ReactNode;\n};\n\n/**\n * Drop-in parent simulator for tests + storybook + standalone dev. Wraps\n * children in a fake parent that:\n *\n * - Acks the iframe's handshake immediately\n * - Broadcasts the configured wallet + service context on mount\n * - Intercepts `callJob` requests and routes them through `onCallJob`\n * - (Optional) Mounts a floating debug panel so the developer can\n * mutate state at runtime: change account, switch chain, set\n * serviceId, fire a custom job\n *\n * The harness runs in the same JS context as the iframe app — there's no\n * cross-frame postMessage, just same-window event dispatch. That keeps it\n * fully synchronous + assertable, but the messages still flow through the\n * exact same protocol surface the production bridge uses.\n *\n * Usage:\n *\n * <TangleParentHarness wallet={mockWallet()} service={mockServiceContext()}>\n * <TangleIframeProvider appId=\"my-app\" mode=\"bridge\" parentOrigin=\"harness://\">\n * <App />\n * </TangleIframeProvider>\n * </TangleParentHarness>\n *\n * Set `mode=\"bridge\"` + `parentOrigin=\"harness://\"` on the provider so it\n * matches the harness's synthetic origin. In production, use `mode=\"auto\"`\n * (the default).\n */\nexport const TangleParentHarness: FC<HarnessProps> = ({\n appId = 'harness',\n wallet = mockWallet(),\n service = mockServiceContext(),\n onCallJob,\n showDebugPanel = false,\n children,\n}) => {\n const [currentWallet, setCurrentWallet] = useState<WalletSnapshot>(wallet);\n const [currentService, setCurrentService] =\n useState<ServiceSnapshot>(service);\n const [callLog, setCallLog] = useState<CallJobRequest[]>([]);\n const callJobHandler = useRef<CallJobHandler | undefined>(onCallJob);\n callJobHandler.current = onCallJob;\n const seenHandshake = useRef(false);\n\n // Bridge the iframe → \"parent\" channel. The SDK posts via\n // `window.parent.postMessage(msg, parentOrigin)`. In a real iframe that\n // crosses a window boundary; in the harness both live in one window, where\n // a same-window `postMessage` with a synthetic targetOrigin is *not*\n // delivered (the origin won't match the document's real origin in jsdom /\n // happy-dom / a real browser). So we intercept `window.parent.postMessage`\n // directly — identical to how production parents receive frames, minus the\n // window hop. Replies still travel back as dispatched `message` events\n // tagged with HARNESS_ORIGIN, which the SDK's listener filters for.\n useEffect(() => {\n const reply = (message: ParentMessage) => {\n window.dispatchEvent(\n new MessageEvent('message', {\n data: message,\n origin: HARNESS_ORIGIN,\n }),\n );\n };\n\n const broadcast = () => {\n const broadcastMsg: ServiceContextBroadcast = {\n kind: 'tangle.app.serviceContext',\n blueprintId: currentService.blueprintId ?? '0',\n serviceId: currentService.serviceId,\n operators: currentService.operators,\n jobs: currentService.jobs,\n mode: currentService.mode,\n ...(currentService.chain !== null\n ? { chain: currentService.chain }\n : {}),\n };\n reply(broadcastMsg);\n // Also broadcast wallet — combined into accountChanged + chainChanged.\n reply({\n kind: 'tangle.app.accountChanged',\n account: currentWallet.address,\n });\n if (currentWallet.chainId !== null) {\n reply({\n kind: 'tangle.app.chainChanged',\n chainId: currentWallet.chainId,\n });\n }\n };\n\n const handleInbound = async (data: unknown) => {\n if (typeof data !== 'object' || data === null) return;\n const message = data as { kind?: string; correlationId?: string };\n\n switch (message.kind) {\n case 'tangle.app.handshake': {\n if (!seenHandshake.current) {\n seenHandshake.current = true;\n reply({\n kind: 'tangle.app.handshakeAck',\n appId,\n protocolVersion: '1',\n });\n broadcast();\n }\n return;\n }\n case 'tangle.app.readAccount': {\n if (typeof message.correlationId !== 'string') return;\n reply({\n kind: 'tangle.app.readAccountResult',\n correlationId: message.correlationId,\n ok: true,\n data: {\n account:\n currentWallet.address ??\n ('0x0000000000000000000000000000000000000000' as Address),\n chainId: currentWallet.chainId ?? 0,\n },\n });\n return;\n }\n case 'tangle.app.callJob': {\n if (typeof message.correlationId !== 'string') return;\n const request = message as unknown as CallJobRequest;\n setCallLog((prev) => [...prev, request]);\n // Default behavior when no handler: emit a single `success` with\n // a echo of the inputs so UIs render *something* in dev mode.\n const handler = callJobHandler.current;\n if (!handler) {\n const result: JobResultEvent = {\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: 'success',\n data: { echo: request.inputs },\n };\n reply(result);\n return;\n }\n try {\n const outcome = await handler(request);\n for (const chunk of outcome.chunks ?? []) {\n reply({\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: 'streaming',\n chunk,\n });\n }\n reply({\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: outcome.status,\n ...(outcome.data !== undefined ? { data: outcome.data } : {}),\n ...(outcome.error !== undefined ? { error: outcome.error } : {}),\n });\n } catch (err) {\n reply({\n kind: 'tangle.app.jobResult',\n correlationId: request.correlationId,\n status: 'error',\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return;\n }\n // Wallet ops respond optimistically — tests that want to assert\n // specific signatures should pre-set them via the dev handler.\n case 'tangle.app.signMessage': {\n if (typeof message.correlationId !== 'string') return;\n reply({\n kind: 'tangle.app.signMessageResult',\n correlationId: message.correlationId,\n ok: true,\n data: { signature: '0xdeadbeef' as `0x${string}` },\n });\n return;\n }\n case 'tangle.app.signTypedData': {\n if (typeof message.correlationId !== 'string') return;\n // The harness signs deterministically — production parents show\n // an approval modal first. Tests that need to assert the\n // typed-data payload should inspect callLog (extend later if\n // needed) or pass a custom onSignTypedData handler.\n reply({\n kind: 'tangle.app.signTypedDataResult',\n correlationId: message.correlationId,\n ok: true,\n data: {\n signature: ('0x' + '11'.repeat(65)) as `0x${string}`,\n },\n });\n return;\n }\n case 'tangle.app.signTransaction': {\n if (typeof message.correlationId !== 'string') return;\n reply({\n kind: 'tangle.app.signTransactionResult',\n correlationId: message.correlationId,\n ok: true,\n data: { txHash: ('0x' + '00'.repeat(32)) as `0x${string}` },\n });\n return;\n }\n case 'tangle.app.switchChain': {\n if (\n typeof message.correlationId !== 'string' ||\n typeof (message as unknown as { chainId?: number }).chainId !== 'number'\n ) {\n return;\n }\n const chainId = (message as unknown as { chainId: number }).chainId;\n setCurrentWallet((w) => ({ ...w, chainId }));\n reply({\n kind: 'tangle.app.switchChainResult',\n correlationId: message.correlationId,\n ok: true,\n data: { chainId },\n });\n return;\n }\n }\n };\n\n // Route the iframe's outbound posts straight into the handler. We expose\n // only `postMessage` — the SDK never touches other `window.parent`\n // members — and restore the original on teardown.\n const originalParent = window.parent;\n const proxyParent = {\n postMessage: (message: unknown) => {\n void handleInbound(message);\n },\n } as unknown as Window;\n Object.defineProperty(window, 'parent', {\n configurable: true,\n get: () => proxyParent,\n });\n return () => {\n Object.defineProperty(window, 'parent', {\n configurable: true,\n value: originalParent,\n });\n };\n }, [appId, currentWallet, currentService]);\n\n // Re-broadcast when state changes.\n useEffect(() => {\n if (!seenHandshake.current) return;\n window.dispatchEvent(\n new MessageEvent('message', {\n data: {\n kind: 'tangle.app.accountChanged',\n account: currentWallet.address,\n },\n origin: HARNESS_ORIGIN,\n }),\n );\n }, [currentWallet.address]);\n\n useEffect(() => {\n if (!seenHandshake.current || currentWallet.chainId === null) return;\n window.dispatchEvent(\n new MessageEvent('message', {\n data: {\n kind: 'tangle.app.chainChanged',\n chainId: currentWallet.chainId,\n },\n origin: HARNESS_ORIGIN,\n }),\n );\n }, [currentWallet.chainId]);\n\n useEffect(() => {\n if (!seenHandshake.current) return;\n window.dispatchEvent(\n new MessageEvent('message', {\n data: {\n kind: 'tangle.app.serviceContext',\n blueprintId: currentService.blueprintId ?? '0',\n serviceId: currentService.serviceId,\n operators: currentService.operators,\n jobs: currentService.jobs,\n mode: currentService.mode,\n ...(currentService.chain !== null\n ? { chain: currentService.chain }\n : {}),\n },\n origin: HARNESS_ORIGIN,\n }),\n );\n }, [currentService]);\n\n const debugApi = useMemo(\n () => ({\n setWallet: setCurrentWallet,\n setService: setCurrentService,\n callLog,\n }),\n [callLog],\n );\n\n return (\n <>\n {children}\n {showDebugPanel && <DebugPanel api={debugApi} />}\n </>\n );\n};\n\n/**\n * Synthetic origin every harness instance uses. Stable across tests so the\n * iframe SDK + the harness can pin to the same string.\n */\nexport const HARNESS_ORIGIN = 'harness://tangle.local';\n\n// ── Debug panel ──────────────────────────────────────────────────────────────\n\nconst DebugPanel: FC<{\n api: {\n setWallet: (w: WalletSnapshot | ((prev: WalletSnapshot) => WalletSnapshot)) => void;\n setService: (\n s: ServiceSnapshot | ((prev: ServiceSnapshot) => ServiceSnapshot),\n ) => void;\n callLog: readonly CallJobRequest[];\n };\n}> = ({ api }) => {\n const [open, setOpen] = useState(true);\n const [tab, setTab] = useState<'wallet' | 'service' | 'log'>('wallet');\n if (!open) {\n return (\n <button\n type=\"button\"\n onClick={() => setOpen(true)}\n style={debugStyles.collapsedTrigger}\n >\n Debug\n </button>\n );\n }\n return (\n <div style={debugStyles.panel}>\n <header style={debugStyles.header}>\n <strong style={{ fontSize: 11 }}>TANGLE DEV HARNESS</strong>\n <button\n type=\"button\"\n onClick={() => setOpen(false)}\n style={debugStyles.closeButton}\n aria-label=\"Close debug panel\"\n >\n ×\n </button>\n </header>\n <nav style={debugStyles.tabs}>\n {(['wallet', 'service', 'log'] as const).map((t) => (\n <button\n key={t}\n type=\"button\"\n onClick={() => setTab(t)}\n style={{\n ...debugStyles.tab,\n ...(tab === t ? debugStyles.tabActive : {}),\n }}\n >\n {t}\n </button>\n ))}\n </nav>\n <div style={debugStyles.body}>\n {tab === 'wallet' && <WalletTab api={api} />}\n {tab === 'service' && <ServiceTab api={api} />}\n {tab === 'log' && <CallLogTab callLog={api.callLog} />}\n </div>\n </div>\n );\n};\n\nconst WalletTab: FC<{\n api: { setWallet: (w: WalletSnapshot | ((prev: WalletSnapshot) => WalletSnapshot)) => void };\n}> = ({ api }) => {\n const [address, setAddressInput] = useState(\n '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',\n );\n const [chainId, setChainIdInput] = useState('84532');\n const applyConnect = useCallback(() => {\n api.setWallet({\n address: address as Address,\n chainId: Number(chainId) || null,\n isConnected: true,\n });\n }, [address, chainId, api]);\n const disconnect = useCallback(() => {\n api.setWallet({ address: null, chainId: null, isConnected: false });\n }, [api]);\n return (\n <div>\n <label style={debugStyles.label}>address</label>\n <input\n value={address}\n onChange={(e) => setAddressInput(e.target.value)}\n style={debugStyles.input}\n />\n <label style={debugStyles.label}>chain id</label>\n <input\n value={chainId}\n onChange={(e) => setChainIdInput(e.target.value)}\n style={debugStyles.input}\n />\n <div style={debugStyles.buttonRow}>\n <button type=\"button\" onClick={applyConnect} style={debugStyles.primary}>\n Set connected\n </button>\n <button type=\"button\" onClick={disconnect} style={debugStyles.secondary}>\n Disconnect\n </button>\n </div>\n </div>\n );\n};\n\nconst ServiceTab: FC<{\n api: {\n setService: (\n s: ServiceSnapshot | ((prev: ServiceSnapshot) => ServiceSnapshot),\n ) => void;\n };\n}> = ({ api }) => {\n const [serviceId, setServiceIdInput] = useState('1');\n const [blueprintId, setBlueprintIdInput] = useState('0');\n const apply = useCallback(() => {\n api.setService((prev) => ({\n ...prev,\n serviceId: serviceId || null,\n blueprintId,\n }));\n }, [api, serviceId, blueprintId]);\n const clearService = useCallback(() => {\n api.setService((prev) => ({ ...prev, serviceId: null }));\n }, [api]);\n return (\n <div>\n <label style={debugStyles.label}>blueprint id</label>\n <input\n value={blueprintId}\n onChange={(e) => setBlueprintIdInput(e.target.value)}\n style={debugStyles.input}\n />\n <label style={debugStyles.label}>service id (empty = not deployed)</label>\n <input\n value={serviceId}\n onChange={(e) => setServiceIdInput(e.target.value)}\n style={debugStyles.input}\n />\n <div style={debugStyles.buttonRow}>\n <button type=\"button\" onClick={apply} style={debugStyles.primary}>\n Apply\n </button>\n <button type=\"button\" onClick={clearService} style={debugStyles.secondary}>\n Clear service\n </button>\n </div>\n </div>\n );\n};\n\nconst CallLogTab: FC<{ callLog: readonly CallJobRequest[] }> = ({ callLog }) => {\n if (callLog.length === 0) {\n return <p style={debugStyles.empty}>No callJob requests yet.</p>;\n }\n return (\n <ol style={debugStyles.log}>\n {callLog.map((entry) => (\n <li key={entry.correlationId} style={debugStyles.logEntry}>\n <strong>job {entry.jobIndex}</strong>\n <pre style={debugStyles.pre}>\n {JSON.stringify(entry.inputs, null, 2)}\n </pre>\n </li>\n ))}\n </ol>\n );\n};\n\n// Inline styles keep the harness style-system-agnostic — consumers may not\n// ship Tailwind, and the panel shouldn't add a dependency.\nconst debugStyles = {\n panel: {\n position: 'fixed' as const,\n right: 12,\n top: 12,\n width: 280,\n zIndex: 99999,\n background: '#0b0b14',\n color: '#fff',\n border: '1px solid #3a3a52',\n borderRadius: 10,\n boxShadow: '0 14px 32px rgba(0,0,0,0.4)',\n fontFamily:\n 'ui-monospace, SFMono-Regular, Menlo, Monaco, \"Cascadia Code\", monospace',\n fontSize: 12,\n },\n header: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n padding: '8px 10px',\n borderBottom: '1px solid #2a2a3e',\n },\n closeButton: {\n background: 'none',\n border: 'none',\n color: '#fff',\n fontSize: 18,\n cursor: 'pointer',\n lineHeight: 1,\n },\n tabs: {\n display: 'flex',\n borderBottom: '1px solid #2a2a3e',\n },\n tab: {\n flex: 1,\n background: 'none',\n border: 'none',\n color: '#a0a0c0',\n padding: '6px 8px',\n cursor: 'pointer',\n fontSize: 11,\n textTransform: 'uppercase' as const,\n },\n tabActive: {\n color: '#fff',\n borderBottom: '2px solid #818cf8',\n },\n body: {\n padding: 10,\n maxHeight: 320,\n overflow: 'auto' as const,\n },\n label: {\n display: 'block',\n color: '#a0a0c0',\n fontSize: 10,\n marginBottom: 4,\n marginTop: 6,\n textTransform: 'uppercase' as const,\n },\n input: {\n width: '100%',\n background: '#15152a',\n border: '1px solid #2a2a3e',\n color: '#fff',\n padding: '6px 8px',\n borderRadius: 4,\n fontFamily: 'inherit',\n fontSize: 11,\n boxSizing: 'border-box' as const,\n },\n buttonRow: { display: 'flex', gap: 6, marginTop: 8 },\n primary: {\n flex: 1,\n background: '#4f46e5',\n color: '#fff',\n border: 'none',\n padding: '6px 8px',\n borderRadius: 4,\n cursor: 'pointer',\n fontSize: 11,\n fontFamily: 'inherit',\n },\n secondary: {\n flex: 1,\n background: 'transparent',\n color: '#a0a0c0',\n border: '1px solid #3a3a52',\n padding: '6px 8px',\n borderRadius: 4,\n cursor: 'pointer',\n fontSize: 11,\n fontFamily: 'inherit',\n },\n collapsedTrigger: {\n position: 'fixed' as const,\n right: 12,\n top: 12,\n zIndex: 99999,\n padding: '6px 10px',\n background: '#0b0b14',\n border: '1px solid #3a3a52',\n color: '#fff',\n borderRadius: 6,\n fontFamily: 'inherit',\n fontSize: 11,\n cursor: 'pointer',\n },\n log: { listStyle: 'none', padding: 0, margin: 0 },\n logEntry: {\n padding: 6,\n borderBottom: '1px solid #2a2a3e',\n fontSize: 11,\n },\n pre: {\n margin: '4px 0 0',\n color: '#a0a0c0',\n fontSize: 10,\n whiteSpace: 'pre-wrap' as const,\n wordBreak: 'break-word' as const,\n },\n empty: { color: '#a0a0c0', fontSize: 11, margin: 0 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AAQ,KAAK,GAAG,WAAW,EAAE;AAAA,EACnD,SAAS;AAAA,IACP,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,cAAc;AAAA,IACd,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,YAAY;AAAA,EACd;AAAA,EACA,WAAW;AAAA,IACT,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,cAAc;AAAA,IACd,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,YAAY;AAAA,EACd;AAAA,EACA,kBAAkB;AAAA,IAChB,UAAU;AAAA,IACV,OAAO;AAAA,IACP,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,EACV;AAAA,EACA,KAAK,EAAE,WAAW,QAAQ,SAAS,GAAG,QAAQ,EAAE;AAAA,EAChD,UAAU;AAAA,IACR,SAAS;AAAA,IACT,cAAc;AAAA,IACd,UAAU;AAAA,EACZ;AAAA,EACA,KAAK;AAAA,IACH,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,WAAW;AAAA,EACb;AAAA,EACA,OAAO,EAAE,OAAO,WAAW,UAAU,IAAI,QAAQ,EAAE;AACrD;","names":[]}
@@ -30,6 +30,28 @@ type SignTransactionRequest = {
30
30
  data: Hex;
31
31
  value?: string;
32
32
  };
33
+ type SignTypedDataRequest = {
34
+ kind: 'tangle.app.signTypedData';
35
+ correlationId: string;
36
+ chainId: number;
37
+ domain: Readonly<{
38
+ name?: string;
39
+ version?: string;
40
+ chainId?: number;
41
+ verifyingContract?: Address;
42
+ salt?: Hex;
43
+ }>;
44
+ /** EIP-712 types map; do NOT include the EIP712Domain entry (the parent
45
+ * injects it derived from `domain`). */
46
+ types: Readonly<Record<string, ReadonlyArray<{
47
+ name: string;
48
+ type: string;
49
+ }>>>;
50
+ /** Top-level type name in `types` whose values appear in `message`. */
51
+ primaryType: string;
52
+ /** The actual typed-data values. Shape matches `types[primaryType]`. */
53
+ message: Readonly<Record<string, unknown>>;
54
+ };
33
55
  type HandshakeAck = {
34
56
  kind: 'tangle.app.handshakeAck';
35
57
  appId: string;
@@ -65,6 +87,11 @@ type SignTransactionResult = {
65
87
  } & ResultEnvelope<{
66
88
  txHash: Hex;
67
89
  }>;
90
+ type SignTypedDataResult = {
91
+ kind: 'tangle.app.signTypedDataResult';
92
+ } & ResultEnvelope<{
93
+ signature: Hex;
94
+ }>;
68
95
  type AccountChanged = {
69
96
  kind: 'tangle.app.accountChanged';
70
97
  account: Address | null;
@@ -83,6 +110,33 @@ type ServiceContextJob = {
83
110
  readonly name: string;
84
111
  readonly inputSchema?: unknown;
85
112
  };
113
+ /**
114
+ * Chain configuration the parent broadcasts to the iframe along with
115
+ * service context. Iframes use this to build a `viem` public client for
116
+ * READ-ONLY queries (`useTanglePublicClient` is the convenience hook).
117
+ *
118
+ * Iframes can ignore this and roll their own RPC config — particularly
119
+ * when they need to read from chains OTHER than the active one (e.g. a
120
+ * trading dapp pulling oracle data from mainnet while the active service
121
+ * lives on Base Sepolia). The injected client is a hint, not a constraint.
122
+ *
123
+ * `rpcUrl` is the public RPC the parent uses, NOT a wallet RPC. Iframes
124
+ * cannot sign or submit with this URL; signing always routes upstream via
125
+ * the bridge.
126
+ */
127
+ type ChainContext = {
128
+ readonly id: number;
129
+ readonly name: string;
130
+ readonly rpcUrl: string;
131
+ /** Block-explorer base URL — useful for rendering tx links. */
132
+ readonly blockExplorerUrl?: string;
133
+ /** Native currency metadata for cost displays. */
134
+ readonly nativeCurrency?: {
135
+ readonly name: string;
136
+ readonly symbol: string;
137
+ readonly decimals: number;
138
+ };
139
+ };
86
140
  type ServiceContextBroadcast = {
87
141
  kind: 'tangle.app.serviceContext';
88
142
  readonly blueprintId: string;
@@ -90,6 +144,10 @@ type ServiceContextBroadcast = {
90
144
  readonly operators: readonly ServiceContextOperator[];
91
145
  readonly jobs: readonly ServiceContextJob[];
92
146
  readonly mode: string | null;
147
+ /** Active chain the parent is connected to; iframes can build a viem
148
+ * publicClient against this for convenience. Optional for backwards
149
+ * compatibility with parents that haven't been upgraded yet. */
150
+ readonly chain?: ChainContext;
93
151
  };
94
152
  type JobInputs = Readonly<Record<string, unknown>>;
95
153
  type CallJobRequest = {
@@ -123,8 +181,8 @@ type JobResultEvent = {
123
181
  readonly eta_ms?: number;
124
182
  };
125
183
  };
126
- type ParentMessage = HandshakeAck | ReadAccountResult | SwitchChainResult | SignMessageResult | SignTransactionResult | AccountChanged | ChainChanged | ServiceContextBroadcast | JobResultEvent;
127
- type IframeRequest = HandshakeRequest | ReadAccountRequest | SwitchChainRequest | SignMessageRequest | SignTransactionRequest | CallJobRequest;
184
+ type ParentMessage = HandshakeAck | ReadAccountResult | SwitchChainResult | SignMessageResult | SignTransactionResult | SignTypedDataResult | AccountChanged | ChainChanged | ServiceContextBroadcast | JobResultEvent;
185
+ type IframeRequest = HandshakeRequest | ReadAccountRequest | SwitchChainRequest | SignMessageRequest | SignTransactionRequest | SignTypedDataRequest | CallJobRequest;
128
186
  declare const NO_WALLET_ADDRESS = "0x0000000000000000000000000000000000000000";
129
187
  /**
130
188
  * Cryptographically-random ASCII correlation id matching the parent's
@@ -133,4 +191,4 @@ declare const NO_WALLET_ADDRESS = "0x0000000000000000000000000000000000000000";
133
191
  */
134
192
  declare function makeCorrelationId(prefix: string): string;
135
193
 
136
- export { type AccountChanged as A, type CallJobRequest as C, type HandshakeAck as H, type IframeRequest as I, type JobInputs as J, NO_WALLET_ADDRESS as N, type ParentMessage as P, type ReadAccountRequest as R, type ServiceContextBroadcast as S, TANGLE_IFRAME_PROTOCOL_PREFIX as T, type ChainChanged as a, type HandshakeRequest as b, type JobResultEvent as c, type JobResultStatus as d, type ReadAccountResult as e, type ServiceContextJob as f, type ServiceContextOperator as g, type SignMessageRequest as h, type SignMessageResult as i, type SignTransactionRequest as j, type SignTransactionResult as k, type SwitchChainRequest as l, type SwitchChainResult as m, TANGLE_IFRAME_PROTOCOL_VERSION as n, makeCorrelationId as o };
194
+ export { type AccountChanged as A, type CallJobRequest as C, type HandshakeAck as H, type IframeRequest as I, type JobInputs as J, NO_WALLET_ADDRESS as N, type ParentMessage as P, type ReadAccountRequest as R, type ServiceContextBroadcast as S, TANGLE_IFRAME_PROTOCOL_PREFIX as T, type ChainChanged as a, type ChainContext as b, type HandshakeRequest as c, type JobResultEvent as d, type JobResultStatus as e, type ReadAccountResult as f, type ServiceContextJob as g, type ServiceContextOperator as h, type SignMessageRequest as i, type SignMessageResult as j, type SignTransactionRequest as k, type SignTransactionResult as l, type SignTypedDataRequest as m, type SignTypedDataResult as n, type SwitchChainRequest as o, type SwitchChainResult as p, TANGLE_IFRAME_PROTOCOL_VERSION as q, makeCorrelationId as r };
@@ -1,5 +1,5 @@
1
1
  import { Address, Hex } from 'viem';
2
- import { g as ServiceContextOperator, f as ServiceContextJob, d as JobResultStatus, J as JobInputs } from './parentBridgeProtocol-CqK9e6Fk.js';
2
+ import { h as ServiceContextOperator, g as ServiceContextJob, b as ChainContext, e as JobResultStatus, m as SignTypedDataRequest, J as JobInputs } from './parentBridgeProtocol-BS2zbIvX.js';
3
3
 
4
4
  type WalletSnapshot = {
5
5
  readonly address: Address | null;
@@ -12,6 +12,9 @@ type ServiceSnapshot = {
12
12
  readonly operators: readonly ServiceContextOperator[];
13
13
  readonly jobs: readonly ServiceContextJob[];
14
14
  readonly mode: string | null;
15
+ /** Chain context broadcast by the parent — drives `useTanglePublicClient`.
16
+ * `null` when the parent hasn't sent one (older parent or dev mode). */
17
+ readonly chain: ChainContext | null;
15
18
  };
16
19
  type JobInvocation = {
17
20
  readonly correlationId: string;
@@ -59,6 +62,7 @@ declare class TangleIframeClient {
59
62
  private handshakeAcked;
60
63
  private handshakeWaiters;
61
64
  private installed;
65
+ private handshakeRetry;
62
66
  private listeners;
63
67
  private pendingJobs;
64
68
  constructor(options: TangleIframeClientOptions);
@@ -75,6 +79,21 @@ declare class TangleIframeClient {
75
79
  value?: bigint;
76
80
  }): Promise<Hex>;
77
81
  switchChain(chainId: number): Promise<number>;
82
+ /**
83
+ * EIP-712 typed-data signing. The parent renders the typed-data fields in
84
+ * its approval modal; the user audits what they're signing. Use for
85
+ * operator envelopes, off-chain attestations, anything that needs a
86
+ * signature outside the standard blueprint-job RFQ flow.
87
+ *
88
+ * Shape mirrors viem's `signTypedData` argument. Do not include the
89
+ * EIP712Domain entry in `types` — the parent injects it from `domain`.
90
+ */
91
+ signTypedData(args: {
92
+ domain: SignTypedDataRequest['domain'];
93
+ types: SignTypedDataRequest['types'];
94
+ primaryType: string;
95
+ message: Readonly<Record<string, unknown>>;
96
+ }): Promise<Hex>;
78
97
  /**
79
98
  * Invoke a blueprint job. Returns a Promise that resolves on terminal
80
99
  * status (`success` or `error`); subscribe to the `job` event for
@@ -89,6 +108,7 @@ declare class TangleIframeClient {
89
108
  inputs: JobInputs;
90
109
  stream?: boolean;
91
110
  }): Promise<JobInvocation>;
111
+ private clearHandshakeRetry;
92
112
  private postHandshake;
93
113
  private postToParent;
94
114
  private handleParentMessage;
@@ -1,7 +1,7 @@
1
1
  export { T as TANGLE_CLOUD_ORIGINS_DEFAULT, d as detectTangleCloudParentOrigin } from '../detectParentOrigin-BYruoIdc.js';
2
2
  import * as wagmi from 'wagmi';
3
3
  import { Address } from 'viem';
4
- export { A as AccountChanged, C as CallJobRequest, a as ChainChanged, H as HandshakeAck, b as HandshakeRequest, I as IframeRequest, J as JobInputs, c as JobResultEvent, d as JobResultStatus, N as NO_WALLET_ADDRESS, P as ParentMessage, R as ReadAccountRequest, e as ReadAccountResult, S as ServiceContextBroadcast, f as ServiceContextJob, g as ServiceContextOperator, h as SignMessageRequest, i as SignMessageResult, j as SignTransactionRequest, k as SignTransactionResult, l as SwitchChainRequest, m as SwitchChainResult, T as TANGLE_IFRAME_PROTOCOL_PREFIX, n as TANGLE_IFRAME_PROTOCOL_VERSION, o as makeCorrelationId } from '../parentBridgeProtocol-CqK9e6Fk.js';
4
+ export { A as AccountChanged, C as CallJobRequest, a as ChainChanged, b as ChainContext, H as HandshakeAck, c as HandshakeRequest, I as IframeRequest, J as JobInputs, d as JobResultEvent, e as JobResultStatus, N as NO_WALLET_ADDRESS, P as ParentMessage, R as ReadAccountRequest, f as ReadAccountResult, S as ServiceContextBroadcast, g as ServiceContextJob, h as ServiceContextOperator, i as SignMessageRequest, j as SignMessageResult, k as SignTransactionRequest, l as SignTransactionResult, m as SignTypedDataRequest, n as SignTypedDataResult, o as SwitchChainRequest, p as SwitchChainResult, T as TANGLE_IFRAME_PROTOCOL_PREFIX, q as TANGLE_IFRAME_PROTOCOL_VERSION, r as makeCorrelationId } from '../parentBridgeProtocol-BS2zbIvX.js';
5
5
 
6
6
  type EventName = 'accountsChanged' | 'chainChanged' | 'connect' | 'disconnect' | 'message';
7
7
  type Listener = (...args: unknown[]) => void;
@@ -5,7 +5,7 @@ import {
5
5
  TANGLE_IFRAME_PROTOCOL_VERSION,
6
6
  detectTangleCloudParentOrigin,
7
7
  makeCorrelationId
8
- } from "../chunk-BLXSBQU4.js";
8
+ } from "../chunk-ZKICSKZH.js";
9
9
 
10
10
  // src/wallet/parentBridgeConnector.ts
11
11
  import { createConnector } from "wagmi";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/blueprint-ui",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Shared blueprint UI components, hooks, and contract utilities for Tangle Network apps",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {
@@ -57,6 +57,7 @@ const NULL_SERVICE: ServiceSnapshot = {
57
57
  operators: [],
58
58
  jobs: [],
59
59
  mode: null,
60
+ chain: null,
60
61
  };
61
62
 
62
63
  /**
@@ -1,5 +1,12 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'react';
2
- import type { Address, Hex } from 'viem';
2
+ import {
3
+ createPublicClient,
4
+ http,
5
+ type Address,
6
+ type Chain,
7
+ type Hex,
8
+ type PublicClient,
9
+ } from 'viem';
3
10
 
4
11
  import { useTangleIframeContext } from './TangleIframeProvider';
5
12
  import type {
@@ -7,7 +14,11 @@ import type {
7
14
  ServiceSnapshot,
8
15
  WalletSnapshot,
9
16
  } from './tangleIframeClient';
10
- import type { JobInputs } from '../wallet/parentBridgeProtocol';
17
+ import type {
18
+ ChainContext,
19
+ JobInputs,
20
+ SignTypedDataRequest,
21
+ } from '../wallet/parentBridgeProtocol';
11
22
 
12
23
  /**
13
24
  * Read-only view of the connected wallet, plus the operations the iframe
@@ -24,6 +35,12 @@ export function useTangleWallet(): WalletSnapshot & {
24
35
  data: Hex;
25
36
  value?: bigint;
26
37
  }) => Promise<Hex>;
38
+ signTypedData: (args: {
39
+ domain: SignTypedDataRequest['domain'];
40
+ types: SignTypedDataRequest['types'];
41
+ primaryType: string;
42
+ message: Readonly<Record<string, unknown>>;
43
+ }) => Promise<Hex>;
27
44
  switchChain: (chainId: number) => Promise<number>;
28
45
  } {
29
46
  const { client, wallet } = useTangleIframeContext();
@@ -41,6 +58,18 @@ export function useTangleWallet(): WalletSnapshot & {
41
58
  },
42
59
  [client],
43
60
  );
61
+ const signTypedData = useCallback(
62
+ (args: {
63
+ domain: SignTypedDataRequest['domain'];
64
+ types: SignTypedDataRequest['types'];
65
+ primaryType: string;
66
+ message: Readonly<Record<string, unknown>>;
67
+ }) => {
68
+ if (!client) throw new Error('Wallet not available in dev mode.');
69
+ return client.signTypedData(args);
70
+ },
71
+ [client],
72
+ );
44
73
  const switchChain = useCallback(
45
74
  (chainId: number) => {
46
75
  if (!client) throw new Error('Wallet not available in dev mode.');
@@ -48,7 +77,70 @@ export function useTangleWallet(): WalletSnapshot & {
48
77
  },
49
78
  [client],
50
79
  );
51
- return { ...wallet, signMessage, sendTransaction, switchChain };
80
+ return {
81
+ ...wallet,
82
+ signMessage,
83
+ sendTransaction,
84
+ signTypedData,
85
+ switchChain,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Chain configuration broadcast by the parent: chain id, name, RPC URL,
91
+ * block explorer, native currency. Returns `null` until the parent has
92
+ * sent its first `serviceContext` broadcast (or in dev mode without a
93
+ * seeded harness).
94
+ *
95
+ * Use this when you want to display chain-aware info (block explorer
96
+ * links, native currency labels) or when you want to build your own viem
97
+ * client with the parent's RPC URL. For a pre-built read-only client,
98
+ * see `useTanglePublicClient()`.
99
+ */
100
+ export function useChainContext(): ChainContext | null {
101
+ return useTangleIframeContext().service.chain;
102
+ }
103
+
104
+ /**
105
+ * Read-only viem `PublicClient` pinned to the chain the parent dapp is
106
+ * connected to. Useful for `readContract`, `getBalance`, `multicall`, etc.
107
+ *
108
+ * Returns `null` until the parent broadcasts a chain context. Iframes that
109
+ * need to read from chains *other* than the active one should bring their
110
+ * own client — this hook is a convenience for the common case, not a
111
+ * constraint. Multi-chain dashboards just create additional clients
112
+ * directly via `createPublicClient`.
113
+ *
114
+ * Memoized per chain id + RPC URL, so consumers get a stable identity
115
+ * across re-renders.
116
+ */
117
+ export function useTanglePublicClient(): PublicClient | null {
118
+ const chain = useChainContext();
119
+ return useMemo(() => {
120
+ if (!chain) return null;
121
+ const chainConfig: Chain = {
122
+ id: chain.id,
123
+ name: chain.name,
124
+ nativeCurrency:
125
+ chain.nativeCurrency !== undefined
126
+ ? { ...chain.nativeCurrency }
127
+ : { name: 'Ether', symbol: 'ETH', decimals: 18 },
128
+ rpcUrls: {
129
+ default: { http: [chain.rpcUrl] },
130
+ },
131
+ ...(chain.blockExplorerUrl
132
+ ? {
133
+ blockExplorers: {
134
+ default: { name: 'Explorer', url: chain.blockExplorerUrl },
135
+ },
136
+ }
137
+ : {}),
138
+ } as Chain;
139
+ return createPublicClient({
140
+ chain: chainConfig,
141
+ transport: http(chain.rpcUrl),
142
+ });
143
+ }, [chain]);
52
144
  }
53
145
 
54
146
  /**
@@ -48,6 +48,8 @@ export {
48
48
  useTangleAddress,
49
49
  useTangleReady,
50
50
  useTangleMode,
51
+ useChainContext,
52
+ useTanglePublicClient,
51
53
  } from './hooks';
52
54
 
53
55
  export {
@@ -63,10 +65,13 @@ export {
63
65
  // against the same wire format if they want to skip the React layer.
64
66
  export type {
65
67
  CallJobRequest,
68
+ ChainContext,
66
69
  JobInputs,
67
70
  JobResultEvent,
68
71
  JobResultStatus,
69
72
  ServiceContextBroadcast,
70
73
  ServiceContextJob,
71
74
  ServiceContextOperator,
75
+ SignTypedDataRequest,
76
+ SignTypedDataResult,
72
77
  } from '../wallet/parentBridgeProtocol';
@@ -0,0 +1,91 @@
1
+ import { render, screen, waitFor } from '@testing-library/react';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { TangleIframeProvider } from './TangleIframeProvider';
5
+ import {
6
+ useChainContext,
7
+ useTangleService,
8
+ useTangleWallet,
9
+ } from './hooks';
10
+ import {
11
+ HARNESS_ORIGIN,
12
+ TangleParentHarness,
13
+ mockServiceContext,
14
+ mockWallet,
15
+ } from './testing';
16
+
17
+ /**
18
+ * End-to-end: a consumer app mounts `TangleIframeProvider` (forced bridge
19
+ * mode) *inside* `TangleParentHarness`. This is exactly how a downstream
20
+ * blueprint tests itself, and it exercises the parts that unit tests of the
21
+ * client alone can't:
22
+ * - React mounts child effects before parent effects, so the provider's
23
+ * `install()` posts its first handshake before the harness has wired its
24
+ * `window.parent.postMessage` interceptor. The client's standing retry
25
+ * must recover from that dropped handshake.
26
+ * - The harness must receive iframe→parent posts via the `window.parent`
27
+ * override (same-window `postMessage` with a synthetic origin is dropped
28
+ * by the DOM), and replies must flow back as dispatched `message` events.
29
+ * A regression in either path makes wallet/service context never arrive.
30
+ */
31
+ function Probe() {
32
+ const wallet = useTangleWallet();
33
+ const service = useTangleService();
34
+ const chain = useChainContext();
35
+ return (
36
+ <div>
37
+ <span data-testid="address">{wallet.address ?? 'none'}</span>
38
+ <span data-testid="connected">{String(wallet.isConnected)}</span>
39
+ <span data-testid="chainId">{String(wallet.chainId)}</span>
40
+ <span data-testid="serviceId">{service.serviceId ?? 'none'}</span>
41
+ <span data-testid="operators">{String(service.operators.length)}</span>
42
+ <span data-testid="chainName">{chain?.name ?? 'none'}</span>
43
+ </div>
44
+ );
45
+ }
46
+
47
+ function mount(opts?: {
48
+ address?: `0x${string}` | null;
49
+ serviceId?: string | null;
50
+ }) {
51
+ return render(
52
+ <TangleParentHarness
53
+ appId="probe-app"
54
+ wallet={mockWallet({ address: opts?.address })}
55
+ service={mockServiceContext({ serviceId: opts?.serviceId ?? '7' })}
56
+ >
57
+ <TangleIframeProvider
58
+ appId="probe-app"
59
+ mode="bridge"
60
+ parentOrigin={HARNESS_ORIGIN}
61
+ >
62
+ <Probe />
63
+ </TangleIframeProvider>
64
+ </TangleParentHarness>,
65
+ );
66
+ }
67
+
68
+ describe('TangleIframeProvider ↔ TangleParentHarness integration', () => {
69
+ it('propagates wallet + chain + service context after handshake', async () => {
70
+ mount();
71
+ await waitFor(() => {
72
+ expect(screen.getByTestId('connected').textContent).toBe('true');
73
+ });
74
+ expect(screen.getByTestId('address').textContent).toBe(
75
+ '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
76
+ );
77
+ expect(screen.getByTestId('chainId').textContent).toBe('84532');
78
+ expect(screen.getByTestId('serviceId').textContent).toBe('7');
79
+ expect(screen.getByTestId('operators').textContent).toBe('1');
80
+ expect(screen.getByTestId('chainName').textContent).toBe('Base Sepolia');
81
+ });
82
+
83
+ it('reports a disconnected wallet when the parent has no account', async () => {
84
+ mount({ address: null });
85
+ await waitFor(() => {
86
+ expect(screen.getByTestId('serviceId').textContent).toBe('7');
87
+ });
88
+ expect(screen.getByTestId('connected').textContent).toBe('false');
89
+ expect(screen.getByTestId('address').textContent).toBe('none');
90
+ });
91
+ });