Skip to content

Encryption ​

Paypunk uses two layers of encryption: envelopes for data in transit between the app and the enclave, and a password-protected vault for your wallet list.

Envelope encryption ​

An envelope is sealed to an X25519 public key and can only be opened by the holder of the matching secret key. Every envelope uses a fresh ephemeral keypair and a fresh 24-byte nonce, so sealing the same plaintext twice produces different ciphertexts.

Envelopes are used in two directions:

  • Viewing keys. Your browser seals a 32-byte RAILGUN viewing key to the enclave's public key. Only the enclave can open it.
  • Notes. The enclave seals each note to your public key. Only your browser can open it.

The envelope treats the plaintext as opaque bytes. Nullifier events are public on-chain data and are not enveloped.

Wire format ​

text
version(1) || ephemeral_pk(32) || nonce(24) || ciphertext(plaintext + tag(16))
OffsetLengthFieldNotes
01versionAlways 0x01.
132ephemeral_pkX25519 public key of the sender's ephemeral secret.
3324nonceXChaCha20-Poly1305 nonce.
57variableciphertextXChaCha20-Poly1305 output, including the 16-byte tag.

The minimum envelope is 73 bytes. The plaintext length is envelope.len() - 73.

Key derivation ​

text
shared = X25519(ephemeral_sk, recipient_pk)
key    = HKDF-SHA256(ikm = shared, salt = empty, info = "paypunk-envelope-v1", L = 32)

The associated data binds the version, the ephemeral public key, and the recipient public key:

text
AAD = version || ephemeral_pk || recipient_pk

Passing a different recipient public key to open fails authentication even when the secret key is correct.

Vault encryption ​

Your wallet vault uses XChaCha20-Poly1305 with a versioned wire format:

text
version(1) || nonce(24) || ciphertext(plaintext + tag(16))
AAD = version || username_bytes

The vault key is derived with Argon2id from your password and username. The vault plaintext holds the random per-user secret that seeds your user keypair, so changing your password re-encrypts the vault without changing the keypair.

Binding the username in the associated data prevents a vault from being replayed onto another account.

Key rotation ​

The enclave keeps a key history. If it restarts with a new keypair, it opens each stored viewing-key envelope with the old key and re-seals the plaintext to the new public key. The envelope wire format does not change during this migration.