Skip to content

Frank Instant Multi-Device QR Pairing & E2EE State Sync (frank-device-pair-v1, #1704) ​

This document specifies Frank's peer-to-peer multi-device onboarding and end-to-end encrypted (E2EE) state synchronization protocol (#1704), enabling an existing authenticated Frank wallet device (Initiator) to pair a new desktop or mobile device (Responder) by scanning an out-of-band QR code (frank://pair?...) and transferring encrypted wallet state over a WebRTC RTCDataChannel (frank-device-pair-v1).


1. Architecture & Protocol Flow ​


2. Pairing QR URI Schema (frank://pair) ​

The Initiator encodes a DevicePairingQrPayload as a compact frank://pair?... URI with a default time-to-live of DEFAULT_PAIRING_TTL_MS = 180_000 (3 minutes):

text
frank://pair?v=1&sid=<32-hex>&dev=<deviceId>&pub=<66-hex-compressed-secp256k1>&fp=<AA:BB:...:FF>&exp=<epochMs>[&relay=<url>]
Query ParamDevicePairingQrPayload FieldFormat / Validation Rules
vversionMust be 1 (DEVICE_PAIRING_PROTOCOL_VERSION)
sidsessionId32 lowercase hex characters (16 CSPRNG bytes)
devinitiatorDeviceId1..128 printable non-whitespace ASCII characters ([\x21-\x7e])
pubinitiatorEphemeralPubKeyHex66 hex characters (02 or 03 prefix) representing a valid on-curve compressed secp256k1 point
fpdtlsFingerprintSha256Canonical uppercase 32-byte colon-separated SHA-256 fingerprint (AA:BB:...:FF); sha-1, md5, all-00, and all-FF are rejected
expexpiresAtMsPositive Unix epoch milliseconds (nowMs < expiresAtMs)
relayrelayUrl (optional)Optional signaling endpoint (https:, http:, wss:, or ws:)

3. Mutual Cryptographic Binding & Short Authentication String (SAS) ​

Even though WebRTC RTCDataChannel uses DTLS encryption, an untrusted signaling relay could attempt an active man-in-the-middle (MITM) attack by substituting the Responder's DTLS certificate or ephemeral public key during signaling.

deriveDevicePairingKeys prevents both attacks by cryptographically binding the ECDH shared secret and both peers' WebRTC DTLS SHA-256 certificate fingerprints into a single HKDF-SHA256 key schedule:

  1. ECDH Shared Secret:
    sharedSecret=secp256k1.getSharedSecret(privlocal,pubremote,compressed=true)\text{sharedSecret} = \text{secp256k1.getSharedSecret}(\text{priv}_{\text{local}}, \text{pub}_{\text{remote}}, \text{compressed}=\text{true})
    Public key reflection (publocal==pubremote\text{pub}_{\text{local}} == \text{pub}_{\text{remote}}) is rejected fail-closed.
  2. Canonical Transcript Binding:
    • salt=SHA256("frank-device-pair-salt-v1:"∥sessionId)\text{salt} = \text{SHA256}(\texttt{"frank-device-pair-salt-v1:"} \parallel \text{sessionId})
    • Let (publow,pubhigh)(\text{pub}_{\text{low}}, \text{pub}_{\text{high}}) be the lexicographically sorted pair of (pubI,pubR)(\text{pub}_I, \text{pub}_R).
    • info="frank-device-pair-transcript-v1|"∥sessionId∥"|"∥fpI∥"|"∥fpR∥"|"∥publow∥"|"∥pubhigh\text{info} = \texttt{"frank-device-pair-transcript-v1|"} \parallel \text{sessionId} \parallel \texttt{"|"} \parallel \text{fp}_I \parallel \texttt{"|"} \parallel \text{fp}_R \parallel \texttt{"|"} \parallel \text{pub}_{\text{low}} \parallel \texttt{"|"} \parallel \text{pub}_{\text{high}}
    • OKM64=HKDF-SHA256(sharedSecret,salt,info,64)\text{OKM}_{64} = \text{HKDF-SHA256}(\text{sharedSecret}, \text{salt}, \text{info}, 64)
  3. Key & SAS Split:
    • encryptionKey = OKM[0..31]\text{OKM}[0..31] (256-bit ChaCha20-Poly1305 key)
    • sasMaterial = OKM[32..63]\text{OKM}[32..63]
    • transcriptHashHex = hex(SHA256(sasMaterial))\text{hex}(\text{SHA256}(\text{sasMaterial}))
    • sasDigits: 6-digit zero-padded integer (uint32_be(sasMaterial[0..3]) mod 1,000,000)(\text{uint32\_be}(\text{sasMaterial}[0..3]) \bmod 1{,}000{,}000)
    • sasWords: 4 high-contrast words indexed by sasMaterial[4..7](mod64)\text{sasMaterial}[4..7] \pmod{64} from SAS_WORDLIST.

4. Application-Layer E2EE State Sync Bundle (DeviceSyncBundle) ​

In addition to transport-layer DTLS, the wallet state bundle (DeviceSyncBundle) is encrypted end-to-end at the application layer using ChaCha20-Poly1305 (@noble/ciphers/chacha):

  • Cipher: chacha20poly1305(encryptionKey, nonce12, aad)
  • AAD: utf8ToBytes("frank-device-pair-bundle-v1:" + sessionId)
  • Integrity Digest: bundleDigestHex = sha256(plaintextUtf8Bytes)
  • Zeroization: Both DevicePairingHandshakeMachine instances automatically overwrite ephemeralPrivKey and encryptionKey with zeros (zeroizePairingKeys) immediately upon completion, failure, abort, or TTL expiration.

5. Threat Model (#1704) ​

Threat / Attack VectorAdversary CapabilityProtocol MitigationEnforcement Function
Initiator DTLS MITMSignaling relay swaps Initiator's SDP a=fingerprintResponder compares Initiator SDP fingerprint in constant time against QR dtlsFingerprintSha256 scanned via cameraDevicePairingHandshakeMachine.createResponder
Responder DTLS or ECDH MITMSignaling relay swaps Responder's SDP a=fingerprint or responder_hello public keyBoth fp_I, fp_R, pub_I, and pub_R are bound into HKDF info; any substitution alters sasDigits, sasWords, and encryptionKeyderiveDevicePairingKeys, handleResponderHello
Pre-SAS Bundle ExfiltrationMalicious responder tries to obtain sync_bundle without user confirmationInitiator refuses to encrypt/send sync_bundle and Responder refuses to decrypt until explicit SAS confirmationconfirmSasAndSendBundle, handleSyncBundle
Cross-Session ReplayAttacker replays an encrypted sync_bundle into another pairing sessionChaCha20-Poly1305 AAD binds frank-device-pair-bundle-v1:<sessionId> alongside fresh per-session ECDH keysencryptDeviceSyncBundle, decryptDeviceSyncBundle
Stale QR Code CaptureAttacker photographs an unattended pairing QR screen after 3 minutesStrict expiresAtMs check (DEFAULT_PAIRING_TTL_MS = 180_000) enforced on URI parse and every state machine transitionparseDevicePairingUri, checkTimeout
Post-Pairing Memory ForensicsHeap inspection after pairing finishes or failsEphemeral private keys, HKDF intermediates, plaintext buffers, and encryptionKey are zeroized in-place via .fill(0)zeroizePairingKeys

Frank & Cashweb High-Assurance Protocol Documentation