0480bfcbc5c7aff91eeb74a3177976132c20a315
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
74e1e0cc6a
|
feat(util-crypto): export quantus-cli wallet files
The counterpart to the importer, and the thing that stops it being a one-way door. Without it an extension backup is readable only by polkadot-js-format tooling, so a user who brought a wallet in could not take it back out. The assumption that blocked this — that we cannot write the CLI format because we do not store a mnemonic — turns out to be false. The format has a null-mnemonic shape and the CLI writes one itself for every raw-seed wallet; crystal_alice, which `quantus developer create-test-wallets` produces, has exactly that alongside `derivation_path: "m/"`. Verified against quantus-cli 2.2.2 rather than inferred. Exports of both schemes were written into ~/.quantus/wallets and the CLI listed them with the correct address, scheme and human checkphrase, showed them under `wallet view`, and answered `export --format mnemonic` with "Mnemonic phrase is not available for this wallet" — which is a correct statement about the file, and only reachable by deriving the Argon2 key, opening the AES-GCM box and parsing the payload. Those probes were removed; the committed test round-trips through our own importer, since CI has no CLI. What a null-mnemonic export costs the user is exactly one thing, and it is not spending: the CLI cannot re-export a phrase from it or derive further accounts. That is the honest consequence of never storing a phrase we showed once, and it is the same position a raw-seed CLI wallet is already in. Argon2 parameters match the CLI's rather than being raised. They travel in the file and the CLI reads them, so in principle anything works — but "in principle" is load-bearing there, and a wallet a slightly older CLI cannot open is worse than a conservatively tuned KDF. Salt and nonce are fresh per export. metadata.exported_by marks the file, so a CLI maintainer reading a bug report can tell where it came from without inferring from shape. Refs quantus/common#8 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f |
||
|
|
e55352aa4e
|
feat(util-crypto): import quantus-cli wallet files
A must-have per the UX decision in quantus/extension#8: the extension has to be able to take a wallet a user already has. My earlier recommendation against this was withdrawn — the reasoning was that a file importer would pull the mnemonic into storage, which is a property of an implementation rather than of the format. This one derives and discards. Converts at the edge rather than teaching the keyring a second container. Decrypt (Argon2id -> AES-256-GCM), take the key material, and hand back a plain keypair for the caller to re-encrypt as the extension's own PKCS8 under a password the user chooses. decodePair does not learn about Argon2 and the keyring keeps exactly one on-disk format. The CLI stores a mnemonic in every HD wallet. This returns `hadMnemonic` and not the phrase — the posture is that a storage password unlocks signing and nothing on disk regenerates the tree, and an import must leave us holding exactly what importing the same mnemonic by hand would leave us holding. Matching upstream, which stores key material only. No new dependencies: @noble/hashes/argon2 was already a util-crypto dependency and AES-GCM is WebCrypto. Async only because WebCrypto has no synchronous form, which is a second reason this belongs at the edge — createFromJson is sync and should stay so. Three things are refused rather than worked around: Argon2 parameters are read from the file, not assumed. They are stored because they are expected to change, and a build that hardcoded m=19456,t=2,p=1 would reject a correct password on an older or newer wallet — the least useful thing it could say. Non-empty kyber_ciphertext/kyber_public_key, and any encryption_version other than 2, are refused with a message. Those fields are an ML-KEM envelope mode that is planned or optional; decrypting by the path we know and ignoring them would fail later and more confusingly, most likely as a bad-password error. The address sits outside the encrypted blob, so it is the one field an attacker can edit without the password. cliWalletAddressMatches is exposed separately so a caller can say "this file's address does not match its key" rather than "wrong password" — a user can act on the difference. Fixtures are genuine CLI 2.2.2 output, not blobs this repo encrypted; testing a decoder against its own encryption proves only self-consistency. They contain no secret: the mnemonic inside each is the public Substrate dev phrase and the password is empty, which is the only reason committing a decryptable wallet is acceptable. The strongest test reaches the same account two ways — through the CLI container and by deriving from that phrase ourselves. Refs quantus/common#7 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f |