Pre-ZIP: Hardware-wallet App Storage Keys (encrypting a light wallet's data with a key from the signer)

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.

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", path m_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 labels db, ufvk and commit. 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.

1 Like

The Local quick unlock section gives “a WebAuthn authenticator through its PRF extension” as an example of a platform key that is generated in secure hardware and never leaves it. That holds for a device-bound credential, but a synced passkey is copied to the user’s other devices through the provider (Apple’s support page: passkeys “sync across a user’s devices using iCloud Keychain”). The authenticator data says which kind it is: the BE (backup eligible) flag is set when the credential may be backed up. It might help to say that a quick unlock key should be device-bound, or that the App should check BE before using it.

Something from practice on the same section. In Konclave we wrap a vault secret under a PRF output in the browser, and we only ever open that wrap on the device that made it. The WebAuthn spec does not promise the same PRF output on another device after a passkey syncs, and we also had an Android phone stop opening a wrap it had made itself, with no sync involved. Your fallback to the Signer covers this. A line saying a wrap can stop opening, and that the App should then go back to the Signer instead of retrying, would help whoever implements it.

A small question on scope. Konclave is a group vault on FROST: there is no seed and no Signer in your sense, and the viewing key is built from the group’s public key plus random material. I read the draft as not covering that case, which is fine. Is that the intent?

1 Like

You would need to use the h/w everytime you open the app for syncing. That removes the convenience of a watch-only wallet.
More importantly, the trust model of a h/w is that no secret escapes the device. Here, nothing prevents a malicious app from keeping the storage key and/or the decrypted ufvk.

2 Likes

Thank you @danielgorgonha, this is exactly the kind of feedback I was hoping for, and it comes from real experience, which I don’t have yet on the browser side.

You’re right about synced passkeys. I had treated a WebAuthn PRF credential as if it always stayed on one device, and that’s not true. I’ve updated the draft:

  • What the key needs: quick unlock now lists the properties its key must have: created in secure hardware, can’t be exported, bound to one device and not synced, and usable only after a biometric or device PIN with hardware attempt limits.
  • The BE flag: an App must not use a credential with the BE (backup eligible) flag set. I also noted that a clear BE flag alone isn’t enough, since it doesn’t prove the other properties.
  • A wrap can stop opening: even on the device that made it. The App should then go back to the Signer and wrap the key again, rather than retrying, and it must never delete the encrypted data.

On scope: yes, that’s the intent. The draft assumes one seed held by one Signer, so a FROST group vault like Konclave isn’t covered. I added that to the non-requirements so it’s explicit. I’d be curious whether any part of it (the subkeys or the storage format, maybe) would still be useful for a group vault. If you see a way, I’d love to hear it.

What is the common procedure, I edit the original post? my repo and the website docs??

Thank you @hanh. Both points are fair, and they showed me the draft wasn’t clear enough about what it does and doesn’t do.

Convenience: you’re right that needing the device on every open would take away what makes a watch-only wallet pleasant. That was never meant to be the only way, but the draft made it sound like the default. I’ve added a “Storage modes” section near the top, and the draft no longer names any default:

  • Remembered: works like today’s watch-only wallets, protected by the phone’s lock screen.
  • Quick unlock: one unlock with the hardware wallet, then fingerprint or face, guarded by the phone’s secure hardware.
  • Signer every time: for savings, or setups that want to trust the phone less.

My thinking is that everyday use would sit on quick unlock or remembered mode, and the stricter mode would be there for the people who want it.

Malicious apps: agreed. Nothing here stops a malicious app from keeping the storage key or the decrypted UFVK. It only protects data at rest: a lost or stolen phone, a disk image, a backup. The section now says this up front, together with what no mode protects against. Spending keys still never leave the device, but the UFVK already leaves it with today’s hardware wallets, so the aim is to protect what the app stores, not to make the app trustworthy. I may be underestimating the cost of adding one more key that leaves the device, though, and I’d value your view on that.

Two things I’ve separated more clearly:

  • Checking what gets signed is a different problem from storage. I’d like to build an independent checker for that one day, something like safe-tx-hashes-util for Safe, but it’s outside this proposal.
  • If someone has already seen your UFVK, the only real fix is moving funds to a new seed. That stops future watching, but it can’t undo the history they’ve already seen.

The question I’m least sure about, and would most like your opinion on, is whether an optional encryption layer like this is worth adopting for existing watch-only workflows. Or would it add complexity that wallets wouldn’t use?

I don’t see what you gain vs. requesting the UFVK from the h/w when needed. If it’s encryption at rest of the db files, the wallet can derive a key from the UFVK. No need to change h/w firmware.

1 Like

Glad it helped. On the procedure, ZIP 0 has it: once the discussion settles, the draft goes to the zcash/zips repository as a pull request, named with an alias like draft-0xoucan-app-storage-keys (the editors assign the number), and later updates go in as pull requests to that draft. Until then, a short post here listing what changed is easier to follow than edits to the first post.

1 Like

Thanks @hanh, that’s a fair challenge, and I think you’re right that it covers most of what this is for. If the app asks the hardware wallet for the UFVK on each opening and derives the database key from it, the data is encrypted at rest and nothing new is needed in the firmware. The draft’s “Why not derive from the viewing key” section doesn’t answer that case: it assumes the app stores the UFVK, and in your version it doesn’t.

The one difference I can still see is separation. With a key derived from the UFVK, anyone the user has given the viewing key to (an auditor, a watch-only service) could also open each app’s local data: contacts, labels, notes, which aren’t on chain. A signer-released per-app key keeps those apart. Whether that’s worth a firmware change in every hardware wallet is a fair question, and I’m not sure it is.

So I’m thinking of reshaping it: a baseline that needs no firmware change (a storage key derived from the UFVK and the app identifier, with the same storage modes), and the signer-released key as an optional extension, or dropped if nobody needs that separation. Would a baseline like that be useful to you, or is it simple enough that wallets should just do it themselves?

Thanks @danielgorgonha, that’s helpful. I’ll post changes as short replies here from now on, and move to a draft PR in zcash/zips once the discussion settles. Hanh’s last point may change the shape of the proposal first, so I’ll wait for that before opening it.

1 Like