In one line: a standard way for a hardware wallet to let each app encrypt its local data, viewing key included, so the private history on the phone stops being the weak spot.
ZIP: Unassigned
Title: Hardware-Wallet App Storage Keys
Owners: 0xOucan <0xoucanxxx@gmail.com>
Status: Draft
Community Status: Request for comments
Category: Standards / Wallet
License: MIT
Hi all, this is a pre-ZIP, posted here to check the idea before it goes to the ZIP editors. It came out of building the LeekWallet Zcash SDK, but it’s meant for any hardware signer and any wallet app.
- Full draft (key tree, rationale, test vectors): ZIP draft: Hardware-Wallet App Storage Keys | LeekWallet Zcash docs
- Source:
docs/zcash/zip-draft-app-storage-keys.mdin GitHub - 0xOucan/leekwallet-zcash: DIY Zcash hardware wallet on ESP32-S3: PCZT signer for Ironwood/Orchard, USB/BLE/QR/SD, with Android and CLI companions · GitHub (branchzecathon) - Reference implementation: the LeekWallet firmware (
zGetStorageKey) and theleek-zcashSDK. Both reproduce the draft’s four test vectors. - A 60-second explainer video: https://youtu.be/F-YRyLxuLzI
Abstract
A wallet app that uses a hardware wallet can keep its data (the UFVK and the wallet database) encrypted at rest under a per-app Storage Key. The signer derives that key from its seed with ZIP 32 Registered key derivation, from the app identifier, the network and the account, and releases it only over an authenticated session after showing the app identifier on its screen and getting the user’s OK. The app keeps only ciphertext and forgets the key when it closes. Restoring the seed brings the same keys back, so there is nothing new to back up.
Motivation
The app never holds spending keys, but it holds the UFVK and a database of notes, memos, addresses and contacts. That is usually stored in plaintext or only behind the host’s own protection, so a stolen phone, a disk image or a cloud backup reveals the whole history and lets someone keep watching with the UFVK. The user already owns a device built to guard secrets and ask for approval on a trusted screen, so it can hold the key to that data too.
Requirements
- The seed never leaves the signer, and releasing a Storage Key reveals nothing about the seed, spending keys or viewing keys.
- Same seed, app identifier, network and account always give the same key.
- Keys for different apps, networks or accounts are independent of each other.
- The derivation is public, so any conforming signer (or, in an emergency, an offline tool with the seed phrase) gives the same keys.
- The user sees which app asks and approves each release on the signer.
- Keys are released only over an authenticated session.
- No backup beyond the existing seed phrase (and passphrase, if any).
Out of scope: authenticating the app (a signer can’t tell which software is asking), protecting data from the app itself or from malware while the app is open, key rotation within one seed, syncing or backing up the ciphertext, and anything on chain.
How it fits with ZIP 32 and ZIP 325
- ZIP 32: it uses Registered key derivation, the mechanism ZIP 32 provides so a new protocol gets its own key tree without colliding with anything else. The Storage Key is a full-width leaf cryptovalue, so it can’t be extended into other keys, and the app identifier goes in as a length-prefixed (prefix-free) tag, as ZIP 32 recommends.
- ZIP 325 (Account Metadata Keys): same goal for software wallets (seed-derived keys for off-chain data, no new backup). What this adds is the hardware-signer part: one key per app, only the leaf ever leaves the signer, an approval on the signer’s screen every time, and rules for apps, including quick unlock.
- It could live under ZIP 325. The draft describes that alternative: a standardised metadata protocol (a 2000-series update to ZIP 325) at
m_metadata / 325' / coin_type' / account' / 0' / P' / (0', AppIdTag). Only the path and the test vectors would change; everything else stays. I’m happy to go that way if the editors prefer it.
Specification (summary)
- Registered key derivation (ZIP 32), context string
"AppStorageKeys", pathm_storage / ZIP_NUMBER' / coin_type' / account' / (0', AppIdTag). - The Storage Key is the first 32 bytes of the derived 64-byte value.
- The app identifier is lowercase ASCII reverse-DNS, 3 to 64 bytes (for example
xyz.leekwallet.zcash), length-prefixed in the tag. - The signer MUST show the app identifier and MUST get the user’s approval before releasing a key, and MUST release it only over an authenticated session.
- Subkeys come from HKDF-SHA256 with info
"Zcash_AppStorage_v1"and the labelsdb,ufvkandcommit. The recommended encryption is XChaCha20-Poly1305. - An app MAY offer a “remember the viewing key on this device” mode instead, which skips this and keeps the UFVK in the OS secure storage.
- Non-normative quick unlock: after one unlock with the signer, an app MAY keep the Storage Key wrapped by a platform key that lives in secure hardware and needs the user’s biometric or device PIN (Android Keystore / StrongBox, the iOS Secure Enclave, a passkey’s PRF). A stolen device is then protected by the phone’s secure hardware and its attempt limits, not by the signer.
- An app MUST NOT protect a Storage Key, a subkey or the UFVK with a key derived on the host from a short PIN alone: it can be guessed offline from a copy of the files, in hours to days even behind a slow hash.
Issues and further discussion
- Its own ZIP, or a protocol under ZIP 325? This is the main question for the editors. I wrote it as its own registered tree, but the ZIP 325 route (above) keeps apps just as isolated, as long as only the leaf leaves the signer, and means one key tree fewer for the ecosystem. I’ll follow the editors’ preference.
- The context string and HKDF info prefix are proposals.
- Should a signer release keys for the other network than the one it is set to?
- Is MUST NOT right for software-only PINs, or would the editors prefer SHOULD NOT? I chose MUST NOT because I can’t think of a deployment where that trade is acceptable.
- I left out a standard wire format between the signer and the app; that could come later if more than one signer adopts this.
- The test vectors use a placeholder ZIP number (65535) until a real one is assigned. Following ZIP 32’s advice not to deploy a registered tree before its spec settles, the reference implementation is only on a development branch, not in any release, and its keys will change.
Implications for other users
- Nothing changes on chain and nothing changes for wallets that don’t adopt it.
- A signer and an app can adopt it independently; any conforming app works with any conforming signer.
- Users restore exactly as today, from the seed phrase.
Feedback very welcome, especially from wallet teams and other hardware-wallet folks (Keystone, the Ledger app maintainers) on whether you would use this.