Protocol
Message envelope
Every message is a JSON-serializable object of the following shape:
interface Web3KitMessage {
type: WEB3_KIT_MESSAGE_TYPES;
payload: {
connectionId: string;
// ...event-specific fields
};
}
See Message Contracts for the exact payload shape of each type.
connectionId
connectionId is a UUID generated by the iframe at mount time and sent to the host in WEB3_KIT_INIT. It is the canonical handle for this particular iframe instance:
- The host must echo it in every outgoing message (
WEB3_KIT_GET_SIGNATURE_MSG,WEB3_KIT_AUTH_BY_WALLET). - The iframe silently drops any inbound message whose
payload.connectionIddoes not match the one it generated. - Hosts embedding multiple iframes simultaneously must track and route by
connectionIdto avoid cross-talk.
If the host remounts the iframe, a new connectionId is generated. Do not reuse a stored one.
Directions
| Direction | Message types |
|---|---|
| iframe → parent | WEB3_KIT_INIT, WEB3_KIT_SIGNATURE_MSG, WEB3_KIT_AUTH_DATA, WEB3_KIT_AUTH_FAILED |
| parent → iframe | WEB3_KIT_GET_SIGNATURE_MSG, WEB3_KIT_AUTH_BY_WALLET |
Origin handling
- The iframe currently posts with
targetOrigin: '*'. This will be tightened to a whitelist once allowed host origins are fixed. - The host must filter inbound messages by
event.origin === WEB3KIT_ORIGINregardless of what the iframe sends. - When the host posts to the iframe via
iframeRef.current.contentWindow.postMessage(...), set the second argument toWEB3KIT_ORIGINin production.'*'is acceptable only during local development.
Ordering
Within a single iframe lifetime the expected order is:
- iframe →
WEB3_KIT_INIT - parent →
WEB3_KIT_GET_SIGNATURE_MSG - iframe →
WEB3_KIT_SIGNATURE_MSG(orWEB3_KIT_AUTH_FAILEDon signature-endpoint failure) - parent →
WEB3_KIT_AUTH_BY_WALLET - iframe →
WEB3_KIT_AUTH_DATAorWEB3_KIT_AUTH_FAILED
The host may repeat steps 2–5 within the same iframe instance if needed (for example, after a nonce expires).
Logging
When the auth-central app is built with appConfig.demo.available = true, both sides emit verbose console.log traces:
- Iframe side: prefix
[web3-kit], with direction tagin/out. - Reference host (
DemoWeb3KitTestPage): prefix[web3-kit-demo], also taggedin/out.
In production builds (demo.available = false) all logging is a no-op.