add changelog and shrink diff

This commit is contained in:
Alain Brenzikofer committed 2026-08-18 15:02:14 +02:00
1 parent d2cc96516a
commit cee76fe787
7 files changed
+204 -96

No files matched your search

+14
View File
@@ -1,5 +1,19 @@
# Release History
## Unreleased
SimpleX names MVP (in development, CLI only):
- Register a name for a contact address or channel from the terminal with
`/name register <service> <name> <simplex_link>`, via commit/reveal against the
badge service so the registrar cannot front-run the name.
- The badge service gains the names commands and an in-memory chain mock; there
is no deployed contract and no payment.
- Wallet: a BIP-39 seed is created on first registration and persisted, with one
BIP-44 account per chat profile, so a registered name stays owned by an address
the client can still derive after restart. No signing, so edits, transfers and
renewal are not possible yet.
- Design: docs/rfcs/2026-08-18-simplex-names-mvp.md
## v6.5
30 April, 2026
+172
View File
@@ -0,0 +1,172 @@
# SimpleX names MVP — register a name from the CLI
The smallest PR that registers a name for an SMP address or channel from the TUI.
It **targets the badges branch** and extends the existing badge service
with registrar commands plus an in-memory chain mock — no new bot, no new
transport. The wallet is real but read-only: generate a seed, derive the owner
address, no signing. Every piece extends into the full design already prototyped.
## Scope
**In:** `/name register <name> <simplex_link>` in the CLI → core `purchaseName` →
two RPCs to the (extended) badge service (commit, then reveal). The name then
resolves on the mock chain to that owner and SimpleX link. Real wallet key derivation
supplies the owner address, and **the seed is persisted in the chat database**, so a
registered name stays owned by an address the client can still derive after restart.
The client keeps no local names record.
**Out (later):** signing (edits, transfers, renewal), seed *backup and recovery*
(the recovery-phrase UI and the recovery scan — persistence itself is in), real
chain, payment, stealth/gifting, GUIs, min-commitment-age enforcement,
tx-hash inclusion verification, anti-grief deposits.
## Why two RPCs for one call
`purchaseName` splits into **commit** then **reveal** so the registrar cannot
front-run the name:
- **commit** publishes only `H(name, ownerAddr, secret, ttl)`. No one — the
service included — can tell which name it is.
- **reveal** submits the plaintext once the commitment is on chain already binding
it to *your* owner address. A service that tries to grab the name at reveal
fails: the aged commitment names you, not it.
Between commit and reveal the core waits a hardcoded **T = 1 s**, standing in for
the on-chain minimum commitment age. Real aging (and deposit hardening) is
deferred; the two-step shape and the wait are what this MVP locks in.
## Sequence
```mermaid
sequenceDiagram
autonumber
participant UI as TUI
participant Core
participant Svc as Badge service
participant Chain as Chain mock
UI->>Core: /name register example.simplex simplex_link
Note over Core: generate seed via Wallet.newSeed once and lazy
Note over Core: commitment hashes [name owner secret and ttl]
Note over Core,Svc: RPC 1 commit
Core-->>UI: progress (committing)
Core->>Svc: APISendServiceRequest NRCommit (commitment)
Svc->>Chain: commit commitment
Chain-->>Svc: committed (txHash)
Svc-->>Core: NRPCommitted (txHash)
Core-->>UI: progress (committed and waiting 1s before revealing)
Note over Core: wait T=1s (stand-in for min commitment age)
Note over Core,Svc: RPC 2 reveal
Core-->>UI: progress (revealing)
Core->>Svc: APISendServiceRequest NRReveal [name owner secret ttl simplex_link]
Svc->>Chain: register (name owner ttl simplex_link)
Chain-->>Svc: registered (txHash expiry)
Svc-->>Core: NRPRegistered (name expiry txHash)
Core-->>UI: registered example.simplex expires on date
Note over Core,Svc: a second reveal of a live name fails with name_taken
```
## Protocol (same service-RPC transport as badges)
Request travels in `APISendServiceRequest.request`, response in
`CRServiceResponse.responseData`; one response per request, per-call timeout. The
service's existing `handleServiceRequest` already decodes a `type`-discriminated
envelope and replies via `APISendServiceResponse` — names commands are added to
that dispatch.
Envelope: `version` and `request`, discriminated on `type`.
There is deliberately **no `ownerKey`** field, though the badge envelope has the
analogous `purchaseKey`. The service-RPC signing key is Ed25519, while a name
owner is a secp256k1 Ethereum address — two different keys — so an `ownerKey`
here would be a second public key that nothing verifies. The owner address
travels in `NRReveal` instead, and the request is sent unsigned. Authenticating
the owner needs signing, which is out of scope; when it arrives it binds the
commitment to a signature rather than to a bare key field.
```
NamesRequest = { version, request }
NamesCommand
| NRCommit { commitment } -- H(name, owner, secret, ttl)
| NRReveal { name, owner, secret, ttl, simplex_link } -- simplex_link: SMP contact or channel
NamesResponse
| NRPCommitted { txHash }
| NRPRegistered { name, expiry, txHash }
| NRPError { code, message?, retryAfter? } -- e.g. name_taken, bad_request
```
`simplex_link` is written on chain as the name's resolver **text record** — the SMP
contact or channel a resolver reads back to turn `example.simplex` into a live
address. `register` in RPC 2 therefore does two chain writes: the registration
(owner, ttl) and this text record.
Each response carries the transaction's **`txHash`**. Using it to verify block
inclusion is out of scope here (see above); the field is returned now so that
path needs no protocol change later.
## Progress events
`purchaseName` stays one command but streams `CEvt` progress to the UI as it
advances — the same async event channel the app already uses for XFTP transfer
and ratchet-sync progress. The TUI prints a live line per phase; the command's
final response returns at the end.
```
CEvtNameRegistrationProgress { name, phase, waitMs? }
phase = Committing | Committed | Revealing | Registered
```
`Committed` carries `waitMs = 1000` and the wait starts the moment it is emitted,
so the TUI renders it as one line — `committed. waiting 1s before revealing`.
There is no separate `Waiting` phase: nothing happens between the two, so it would
only print a second line and then sit there. No verification phases (out of
scope). Against a real chain the same `waitMs` carries the real
min-commitment-age unchanged.
**Idempotency.** `NRCommit` re-accepts an existing commitment, so re-committing
is free. `NRReveal` is *not* idempotent: once a name is registered any further
reveal of it fails with `name_taken`, including from its own owner — registering
again is not an edit, and edits need signing (out of scope).
This MVP has no automatic retry, so the only way to reach a repeat reveal is to
run the command twice, which is a duplicate registration and must say so rather
than silently report success. When retry-on-timeout is added, idempotency has to
key on a **request id**: matching fields cannot distinguish a resent request from
a user registering the same name again.
## Components and reuse
| Component | This PR | Extends to |
|---|---|---|
| **Wallet** | `Wallet.newSeed` + `deriveAccount` + `accountAddress`, already built. No signing. | `signIntent` (also built) unlocks edits/transfers with no shape change. |
| **Wallet storage** | the prototype's `wallet_seeds` migration and `Store.Wallets` verbatim: one seed per DB, one account index per profile, allocated from a stored high-water mark. | recovery import, `backed_up` reminder and the one-time-address table are already in the schema; they need code only. |
| **RPC transport** | badges' `APISendServiceRequest` / `APISendServiceResponse`, unchanged. | shared. |
| **Service** | extend `BadgeService/Service.hs` `handleServiceRequest` to dispatch `NRCommit`/`NRReveal`; add an in-memory chain mock (a `TVar (Map name entry)`, like `Names.Service.Mock`). | swap the mock for a relayer to a deployed SNRC. |
| **Resolution** | the mock chain is the record: the name resolves there to owner and SimpleX link. No client-side names store. | a resolver read against a deployed SNRC; add a local cache only if a listing UX needs it. |
| **TUI** | `/name register <name> <simplex_link>`; renders `CEvt` progress lines including the 1 s wait, then the result. | further `/name …` verbs; richer progress once the chain is real. |
## Milestones (each ends with passing tests)
1. **Envelope + types** — `NamesRequest`/`NamesResponse` in the shared service
module; JSON roundtrip test. No behaviour yet.
2. **Service dispatch + chain mock** — `handleServiceRequest` recognises the names
commands; the in-memory chain answers commit/reveal and rejects a taken name.
3. **Core `purchaseName` + progress** — derive owner from a lazily-generated
seed persisted in the chat DB; commit, wait 1 s, reveal against the mock chain; stream
`CEvtNameRegistrationProgress` at each phase. `/name register` renders the
progress lines, the announced wait, and the result. No local names record.
4. **End-to-end CLI test** — `/name register example.simplex <simplex_link>` emits the
phase progress (including the 1 s wait on `Committed`) and resolves the name to the
derived owner with the given SimpleX link; a second registration of the same name
fails with `name_taken`; and a restarted client derives the same owner address.
## Success criterion
The milestone-4 test passes: one name registered through commit+reveal against the
in-service chain mock, owned by a real derived address, with `name_taken` on
repeat.
@@ -12,8 +12,6 @@ m20260806_wallet_seeds =
CREATE TABLE wallet_seeds (
wallet_seed_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
seed BYTEA NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
backed_up SMALLINT NOT NULL DEFAULT 0,
-- High-water mark for account allocation; see the SQLite migration for why
-- this cannot be derived from MAX(users.wallet_account_index).
next_account_index BIGINT NOT NULL DEFAULT 0
@@ -21,34 +19,15 @@ CREATE TABLE wallet_seeds (
ALTER TABLE users ADD COLUMN wallet_seed_id BIGINT REFERENCES wallet_seeds ON DELETE RESTRICT;
ALTER TABLE users ADD COLUMN wallet_account_index BIGINT;
ALTER TABLE users ADD COLUMN wallet_scanned_to TEXT;
CREATE INDEX idx_users_wallet_seed_id ON users(wallet_seed_id);
CREATE TABLE wallet_one_time_addresses (
wallet_one_time_address_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users ON DELETE CASCADE,
chain TEXT NOT NULL,
address BYTEA NOT NULL,
ephemeral_pub_key BYTEA NOT NULL,
discovered_at TIMESTAMPTZ NOT NULL DEFAULT now(),
accepted_at TIMESTAMPTZ,
UNIQUE (user_id, chain, address)
);
CREATE INDEX idx_wallet_one_time_addresses_user ON wallet_one_time_addresses(user_id, chain);
|]
down_m20260806_wallet_seeds :: Text
down_m20260806_wallet_seeds =
[r|
DROP INDEX idx_wallet_one_time_addresses_user;
DROP TABLE wallet_one_time_addresses;
DROP INDEX idx_users_wallet_seed_id;
ALTER TABLE users DROP COLUMN wallet_scanned_to;
ALTER TABLE users DROP COLUMN wallet_account_index;
ALTER TABLE users DROP COLUMN wallet_seed_id;
@@ -7,66 +7,34 @@ import Database.SQLite.Simple.QQ (sql)
-- | Wallet seeds: BIP-39 entropy, one or more per database.
--
-- The schema allows several seeds per database, with each chat profile bound to
-- exactly one of them plus its own BIP-44 account index. Only the single-seed
-- case is reachable from the UI today — profiles all share one seed and differ
-- by account index — but modelling it this way now means importing a second
-- recovery key later is a UI change, not a migration of live key material.
-- The schema allows several seeds, with each chat profile bound to exactly one
-- of them plus its own BIP-44 account index. Only the single-seed case is
-- reachable today.
m20260806_wallet_seeds :: Query
m20260806_wallet_seeds =
[sql|
CREATE TABLE wallet_seeds (
wallet_seed_id INTEGER PRIMARY KEY AUTOINCREMENT,
seed BLOB NOT NULL, -- BIP-39 entropy, 16-32 bytes
created_at TEXT NOT NULL DEFAULT (datetime('now')),
backed_up INTEGER NOT NULL DEFAULT 0, -- user acknowledged saving the recovery key
-- High-water mark for account allocation. Deliberately not derived from
-- MAX(users.wallet_account_index): after recovery from the phrase alone that
-- table is empty while accounts 0..N already hold names on chain, so a new
-- profile would silently reuse a recovered account's keys and meta-address.
-- The recovery probe raises this before any profile is created.
-- profile would silently reuse a recovered account's keys.
next_account_index INTEGER NOT NULL DEFAULT 0
) STRICT;
ALTER TABLE users ADD COLUMN wallet_seed_id INTEGER REFERENCES wallet_seeds ON DELETE RESTRICT;
ALTER TABLE users ADD COLUMN wallet_account_index INTEGER;
-- Position of the last recovery scan, so a repeat scan resumes. Not a live
-- watermark: incoming names are learned from a chat message, not by scanning.
ALTER TABLE users ADD COLUMN wallet_scanned_to TEXT;
-- required: the .lint check enforces an index on every foreign key
CREATE INDEX idx_users_wallet_seed_id ON users(wallet_seed_id);
-- Destinations learned from a sender's message, or rediscovered by a recovery
-- scan. Holds no private key: the key is re-derived from the seed and the
-- ephemeral public key on demand, so this table is a cache and losing it costs
-- a rescan rather than an asset.
--
-- 'chain' is carried from the first migration so that adding Bitcoin or Monero
-- later is new rows, not a schema change.
CREATE TABLE wallet_one_time_addresses (
wallet_one_time_address_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
chain TEXT NOT NULL, -- 'eth' today; 'btc', 'xmr' later
address BLOB NOT NULL,
ephemeral_pub_key BLOB NOT NULL, -- compressed secp256k1 point, 33 bytes
discovered_at TEXT NOT NULL DEFAULT (datetime('now')),
accepted_at TEXT, -- NULL = received but not accepted
UNIQUE (user_id, chain, address)
) STRICT;
CREATE INDEX idx_wallet_one_time_addresses_user ON wallet_one_time_addresses(user_id, chain);
|]
down_m20260806_wallet_seeds :: Query
down_m20260806_wallet_seeds =
[sql|
DROP INDEX idx_wallet_one_time_addresses_user;
DROP TABLE wallet_one_time_addresses;
DROP INDEX idx_users_wallet_seed_id;
ALTER TABLE users DROP COLUMN wallet_scanned_to;
ALTER TABLE users DROP COLUMN wallet_account_index;
ALTER TABLE users DROP COLUMN wallet_seed_id;
@@ -55,8 +55,7 @@ CREATE TABLE users(
is_user_chat_relay INTEGER NOT NULL DEFAULT 0,
client_service INTEGER NOT NULL DEFAULT 0,
wallet_seed_id INTEGER REFERENCES wallet_seeds ON DELETE RESTRICT,
wallet_account_index INTEGER,
wallet_scanned_to TEXT, -- 1 for active user
wallet_account_index INTEGER, -- 1 for active user
FOREIGN KEY(user_id, local_display_name)
REFERENCES display_names(user_id, local_display_name)
ON DELETE RESTRICT
@@ -851,25 +850,11 @@ CREATE TABLE rcv_roster_transfers(
CREATE TABLE wallet_seeds(
wallet_seed_id INTEGER PRIMARY KEY AUTOINCREMENT,
seed BLOB NOT NULL, -- BIP-39 entropy, 16-32 bytes
created_at TEXT NOT NULL DEFAULT(datetime('now')),
backed_up INTEGER NOT NULL DEFAULT 0, -- user acknowledged saving the recovery key
-- High-water mark for account allocation. Deliberately not derived from
-- MAX(users.wallet_account_index): after recovery from the phrase alone that
-- table is empty while accounts 0..N already hold names on chain, so a new
-- profile would silently reuse a recovered account's keys and meta-address.
-- The recovery probe raises this before any profile is created.
next_account_index INTEGER NOT NULL DEFAULT 0
) STRICT;
CREATE TABLE wallet_one_time_addresses(
wallet_one_time_address_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
chain TEXT NOT NULL, -- 'eth' today; 'btc',
'xmr' later
address BLOB NOT NULL,
ephemeral_pub_key BLOB NOT NULL, -- compressed secp256k1 point, 33 bytes
discovered_at TEXT NOT NULL DEFAULT(datetime('now')),
accepted_at TEXT, -- NULL = received but not accepted
UNIQUE(user_id, chain, address)
-- profile would silently reuse a recovered account's keys.
next_account_index INTEGER NOT NULL DEFAULT 0
) STRICT;
CREATE INDEX contact_profiles_index ON contact_profiles(
display_name,
@@ -1406,10 +1391,6 @@ CREATE INDEX idx_chat_items_item_signed_by_group_member_id ON chat_items(
item_signed_by_group_member_id
);
CREATE INDEX idx_users_wallet_seed_id ON users(wallet_seed_id);
CREATE INDEX idx_wallet_one_time_addresses_user ON wallet_one_time_addresses(
user_id,
chain
);
CREATE TRIGGER on_group_members_insert_update_summary
AFTER INSERT ON group_members
FOR EACH ROW
+8 -13
View File
@@ -8,15 +8,10 @@
-- The schema holds several seeds and binds each chat profile to one of them
-- plus its own account index. Only the single-seed case is reachable from the
-- UI: 'getOrCreateAccountRef' reuses the database's first seed and allocates the
-- next free account index.
-- next free account index. It is the only export, because it is all that name
-- registration needs; the helpers below stay internal until they have a caller.
module Simplex.Chat.Store.Wallets
( getWalletSeeds,
getWalletSeed,
createWalletSeed,
getAccountRef,
bindAccount,
getOrCreateAccountRef,
getNextAccountIndex,
( getOrCreateAccountRef,
)
where
@@ -35,18 +30,18 @@ import Database.PostgreSQL.Simple (Only (..))
import Database.SQLite.Simple (Only (..))
#endif
toSeed :: (Int64, ByteString, Bool) -> WalletSeed
toSeed (sId, seed, backedUp) = WalletSeed {wsId = SeedId sId, wsEntropy = seed, wsBackedUp = backedUp}
toSeed :: (Int64, ByteString) -> WalletSeed
toSeed (sId, seed) = WalletSeed {wsId = SeedId sId, wsEntropy = seed}
getWalletSeeds :: DB.Connection -> IO [WalletSeed]
getWalletSeeds db =
map toSeed
<$> DB.query_ db "SELECT wallet_seed_id, seed, backed_up FROM wallet_seeds ORDER BY wallet_seed_id"
<$> DB.query_ db "SELECT wallet_seed_id, seed FROM wallet_seeds ORDER BY wallet_seed_id"
getWalletSeed :: DB.Connection -> SeedId -> IO (Maybe WalletSeed)
getWalletSeed db (SeedId sId) =
maybeFirstRow toSeed $
DB.query db "SELECT wallet_seed_id, seed, backed_up FROM wallet_seeds WHERE wallet_seed_id = ?" (Only sId)
DB.query db "SELECT wallet_seed_id, seed FROM wallet_seeds WHERE wallet_seed_id = ?" (Only sId)
-- | Insert a seed. Callers generate the entropy; this module never does, so the
-- DRG stays with the agent.
@@ -54,7 +49,7 @@ createWalletSeed :: DB.Connection -> ByteString -> IO WalletSeed
createWalletSeed db seed = do
DB.execute db "INSERT INTO wallet_seeds (seed) VALUES (?)" (Only seed)
sId <- insertedRowId db
pure WalletSeed {wsId = SeedId sId, wsEntropy = seed, wsBackedUp = False}
pure WalletSeed {wsId = SeedId sId, wsEntropy = seed}
getAccountRef :: DB.Connection -> User -> IO (Maybe AccountRef)
getAccountRef db User {userId} = do
+2 -3
View File
@@ -53,13 +53,12 @@ type AccountIndex = Word32
-- 'Show' is redacting: this is the root secret behind every name it owns.
data WalletSeed = WalletSeed
{ wsId :: SeedId,
wsEntropy :: ByteString,
wsBackedUp :: Bool
wsEntropy :: ByteString
}
deriving (Eq)
instance Show WalletSeed where
show s = "WalletSeed " <> show (wsId s) <> " <redacted, backedUp=" <> show (wsBackedUp s) <> ">"
show s = "WalletSeed " <> show (wsId s) <> " <redacted>"
-- | What a chat profile stores: which seed, and which account index within it.
data AccountRef = AccountRef