Skip to content

wallet: deriveKey — an origin-bound key a site can ask for (perps trading keys on durian.market) - #16

Merged
dendisuhubdy merged 1 commit into
mainfrom
feat/derive-key
Nov 20, 2026
Merged

dendisuhubdy merged 1 commit into
mainfrom
feat/derive-key

Conversation

@dendisuhubdy

Copy link
Copy Markdown
Member

window.rand.deriveKey({ purpose }) → { key }: an origin-bound 32-byte key a connected site can ask the wallet for. durian.market's perps terminal (web/lib/perps/session.ts) uses it for its trading keys.

  • HKDF-SHA-256 (WebCrypto) from the spend key, salt rand-wallet/site-key/v1, info = length-prefixed (domain, origin, purpose, connected address). The viewing key is never an input.
  • Policy in provider-host.js: connected origin, unlocked wallet, purpose ^[a-z0-9./-]{1,64}$. The first request per (origin, purpose) waits for approval in derive.html. Later requests answer at once. Disconnecting forgets the approval.
  • inpage.js / content.js relay the method and the purpose string; new lib/derive-key.js with a pinned vector.
  • Nine new window strings in all twenty languages. Rebased onto main: main's new strings are kept and en.js is regenerated (1132 strings, extract-strings.mjs --check clean). The core/vendor/fullnode pointer is unchanged from main.

Local: extension + ui unit tests 1259/1260 pass. The one failure is rpc-methods.test.mjs, which needs the core/vendor/fullnode submodule, and the submodule is not checked out in the local worktree. smoke.mjs needs the wasm build and was not run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GFs5gyuBMf1nCmyHCP3AT8

…ding keys on durian.market)

window.rand.deriveKey({ purpose }) → { key }: 32 bytes (64 lowercase hex) derived in the
background by HKDF-SHA-256 (WebCrypto) from the wallet's spend key, salt
"rand-wallet/site-key/v1", info = length-prefixed (domain, sender origin, purpose, connected
address). Same wallet + origin + purpose gives the same key on any device restored from the
same key; another origin, purpose or wallet gives an unrelated one. The viewing key (which
provers receive) is never an input.

Policy beside connect/invoke in provider-host.js: connected origin (NOT_CONNECTED), unlocked
(LOCKED), purpose ^[a-z0-9./-]{1,64}$ (BAD_REQUEST); the first request per (origin, purpose)
is parked like an invoke (shared BUSY rule) and approved in derive.html; the yes is stored as
sites[origin].siteKeys[purpose] = {address, at} and later requests answer at once; disconnect
forgets it; Reject or a closed window is USER_REJECTED. The key is in no store and no message
but the answer to the asking frame; the window hears only {ok: true}.

inpage.js adds deriveKey; content.js relays the method and its purpose string only. New
lib/derive-key.js (classic script; Chrome importScripts, Firefox background.scripts) with a
pinned vector recomputed by node:crypto. Nine new window strings in all twenty languages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YGaYNNSAAQZWcccfnqCmLS
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dendisuhubdy
dendisuhubdy merged commit d6e6ebc into main Nov 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant