How it works
is end-to-end encrypted messaging directly on . Every message is encrypted in your browser and stored in a contract on-chain. Only you and the other wallet can read it, and nobody can delete, change or censor it.
Getting started
- Connect your wallet and create your chat key. Your wallet signs a fixed text twice, and your browser turns that signature into the key. One transaction registers its public half on-chain (gas only). The same wallet always gets the same key, on any device, so there is nothing to back up.
- Paste the address of the wallet you want to reach, or open the link someone gave you.
- Write the message and send it. Your wallet asks you to confirm one transaction per message.
A wallet can only be written to once it has a chat key of its own: nothing can be encrypted for it before. Send it your link (Settings) and it can join in a minute. Messages from wallets you never wrote to are kept apart under Requests.
The encryption
Two wallets share a key from their chat keys (ECDH on secp256k1), and every message is sealed with it (AES-256-GCM) before it leaves your browser. Each new tab asks for one signature to unlock your key and forgets it when it closes.
Everyone can see who wrote to whom, when, and roughly how long the message is. Nobody but the two of you can see the text.
Where the messages live
In the messenger contract's storage, for good: each message's ciphertext, who wrote it and when. The contract also keeps every wallet's list of conversations.
There is no server in between. This page reads your chats straight from the contract through public nodes, and anyone can do the same with the functions below. If this site disappeared, every message would still be on-chain and readable.
Fees
per message, sent along with it, plus gas. The contract caps the fee at 0.001 for good.
Messages cost gas only.
Wallets holding at least () write for free, paying gas only. The balance is checked when each message is sent.
Holders of the messenger's token will write for free once it is set as the fee pass.
Gas is a fraction of a cent for a short message.
The contract
Messenger:
Token:
One contract, no proxy, no upgrade, no pause. Its owner can set the fee (up to the cap), where the fees go and the fee pass. Nobody, the owner included, can delete, change or block a message.
What it doesn't protect you from
- Permanence. A sent message can never be deleted or edited.
- A leaked chat key. Whoever gets the signature that makes your chat key can read every message encrypted with it, old and new. Only sign that text on this site. If in doubt, make a new key in Settings: new messages will use it.
- Strangers. Anyone can write to any wallet that has joined. Links in messages are deliberately not clickable. Never sign or send anything because a message told you to.
- Wallets that can't keep a key. Smart contract wallets and some keyless wallets sign the same text differently each time. They can't create a chat key.
- Bugs. The contract is small and tested, but it has not had a paid third-party audit.
Contract functions
Everything the page does goes through these public functions of the messenger (, chain ), so a script or bot can do the same. The owner's settings functions are left out.
send(address to, bytes payload) payable returns (uint256 index)
Stores one message: payload is the encrypted message (see Message
format), 1 to bytes. The value must be exactly feeOf(msg.sender),
both wallets need a chat key, writing to yourself is allowed. Returns its index in the conversation and emits
Message(from, to, index).
Reverts: BadAddress (to = 0), BadLength, WrongFee,
NoKey.
setKey(bytes32 key) returns (uint256 index)
Registers the caller's next chat key: the 32-byte x coordinate of a secp256k1 public key with an even y.
Earlier keys stay listed, the last one is current. Returns its index (the key number messages name). Emits
KeySet(account, index, key).
Reverts: BadKey (zero), TooManyKeys (255 per wallet).
chatCount(address account) view returns (uint256)
How many conversations the account has (notes to itself included).
chats(address account, uint256 start, uint256 count) view returns (Chat[])
The account's conversations number start onwards (at most count), in the order they
began. Each Chat is (address peer, uint256 count, uint256 lastTime, bool sent, bool received,
bytes last): the other wallet, its number of messages, the time of the latest one, whether the account and
the peer wrote in it, and the latest message's blob.
messageCount(address a, address b) view returns (uint256)
How many messages the conversation of two wallets holds (either order).
messages(address a, address b, uint256 start, uint256 count) view returns (bytes[])
The conversation's message blobs number start onwards (at most count), oldest
first, as described in Message format.
keysOf(address account) view returns (bytes32[])
Every chat key the account registered, in order. Empty = the wallet hasn't joined and can't be written to.
feeOf(address sender) view returns (uint256)
What a message from sender costs right now in wei: fee, or 0 while it holds
passMin of passToken. Send exactly this as the value.
flushFees()
Sends the collected fees to feeTo. Anyone can call it. Emits FeesFlushed(to, amount).
fee() · feeTo() · passToken() · passMin() · owner() view
The current settings: the fee in wei, its recipient, the pass token (0 = none) and the balance of it, in its
base units, that makes messages free. Constants: MAX_FEE (0.001 ether),
MAX_LENGTH (), MAX_KEYS (255), FROM_LO (1).
event Message(address indexed from, address indexed to, uint256 index)
One per message: watch it to learn about new messages without polling.
Message format
Stored message (a blob of messages / chats): [flags: 1 byte][block
timestamp: 5 bytes][payload]. Flag FROM_LO (1) set = written by the lower of the two
addresses (numeric order), else by the higher one.
Payloads are opaque to the contract. This is how the page builds them; anything that follows it can talk to the page's users.
Chat key number i (0-based, = its index in keysOf): the wallet signs this text
with personal_sign (key #1 shown, the first line counts up):
seed = HKDF-SHA256(ikm = r ‖ s, salt = "BNBChat chat key", info = "", 32 bytes), withr ‖ sthe signature's first 64 bytes.d = seed mod (n − 1) + 1(n = the secp256k1 group order); ifd·Ghas an odd y,d = n − d.- The public key is the x coordinate of
d·G, registered withsetKey.
Conversation key between wallets lo and hi (the two addresses in numeric order) and their key numbers loKey and hiKey:
shared= the x coordinate ofd · (0x02 ‖ peerKey)(ECDH, 32 bytes).key = HKDF-SHA256(ikm = shared, salt = "BNBChat conversation", info = "chainId|contract|lo|hi|loKey|hiKey"), an AES-256-GCM key; addresses lowercase hex, numbers in decimal.
Payload: [sender key number: 1 byte][recipient key number: 1 byte][nonce: 12 bytes][ciphertext +
16-byte tag], the text UTF-8 encoded, the sender's 20-byte address as the additional authenticated data.
New messages use both wallets' current keys. A message's text can be up to
bytes (30 bytes of overhead).