@thru/protocol when you are implementing the embedded wallet message layer directly, such as a host page, an iframe messenger, or a compatibility shim for @thru/browser-sdk.
Install
When to use it
Choose this package when you need the wire format, not the higher-level wallet API:- Build a custom embedded wallet host.
- Implement an iframe messenger that speaks the Thru protocol.
- Validate request and response envelopes in tests or middleware.
- Share request/event constants across browser packages.
Entry point
The package exposes a single public entry point at@thru/protocol.
What it exports
| Area | Key exports |
|---|---|
| Request kinds | POST_MESSAGE_REQUEST_TYPES |
| Request envelopes | PostMessageRequest, ConnectRequestMessage, SignMessageRequestMessage, SignTransactionRequestMessage, GetAccountsRequestMessage, SelectAccountRequestMessage |
| Response envelopes | PostMessageResponse, SuccessfulPostMessageResponse, InferPostMessageResponse, InferSuccessfulPostMessageResponse |
| Channel events | POST_MESSAGE_EVENT_TYPE, IFRAME_READY_EVENT, EMBEDDED_PROVIDER_EVENTS, PostMessageEvent |
| Errors and helpers | ErrorCode, createRequestId, DEFAULT_IFRAME_URL |
| Shared payload types | AppMetadata, ConnectResult, WalletAccount |
Example
Request flow
Every request envelope includes anid and origin, plus a type and optional payload:
connect requests carry ConnectRequestPayload, which currently accepts optional app metadata. signMessage and signTransaction requests carry the corresponding payload types, while getAccounts and disconnect are payload-free.
Response flow
Responses are discriminated bysuccess:
success: truereturns a typedresultbased on the request typesuccess: falsereturns an error payload with anErrorCodeand message
InferPostMessageResponse and InferSuccessfulPostMessageResponse so you can derive the matching response type from a request type at compile time.
Shared types
The package re-exportsAppMetadata and ConnectResult from @thru/chain-interfaces, and its payloads also depend on WalletAccount.
If you are already using @thru/browser-sdk or @thru/embedded-provider, this package is the lower-level protocol layer those packages build on.