Word shares #
The word form of a share: the same record as the qs1/qs2/qs3 hex form, written as BIP-39 English words
so it is easier to write on paper and read aloud (README: Share format).
bytes = version(1) ‖ setid(4) ‖ k(1) ‖ x(1) ‖ len(1) ‖ payload(len) ‖ token ‖ crc32(4)
words = the bytes in 11-bit groups (`Bits.pack`), each group as a word, separated by spaces
version is 1 for the qs1 record (CRC-32 secret tag), 2 for qs2 (AMD tag) and 3 for qs3
(AMD tag and share token). token is the 16-byte share token in version 3 and absent before.
crc32 is the CRC-32 of all bytes before it (accident detection only, as in the hex form). The
one-byte len limits word shares to payloads of at most 255 bytes, i.e. secrets of at most
251 bytes in version 1 (4-byte tag), 223 bytes in version 2 (32-byte tag) and 223 − 16k bytes
in version 3 (the token polynomial adds 16k).
Decoding accepts any whitespace between words, upper case and 4-letter abbreviations
(Wordlist.lookup), and checks, in order: every word is known, the version, the payload length,
that the words are exactly the canonical encoding of the bytes they decode to (right word count,
zero padding bits), and the checksum.
Not BIP-39. These words are not a BIP-39 mnemonic and must never be used as a wallet seed.
decode_encode proves that decoding an encoded share gives back exactly the same record.
Version byte of the word format: 1 for qs1 records, 2 for qs2, 3 for qs3.
Equations
Instances For
Read the version byte.
Equations
Instances For
Reading a written version byte gives its format.
Everything the checksum covers: version ‖ setid ‖ k ‖ x ‖ len ‖ payload ‖ token.
Equations
- One or more equations did not get rendered due to their size.
Instances For
All bytes of the word form: the body followed by its CRC-32.
Equations
Instances For
The word for an 11-bit number ("" outside 0 … 2047, which pack never produces).
Equations
Instances For
The words of a record.
Equations
Instances For
The words of a record as characters, separated by single spaces.
Equations
Instances For
Encode a record as a word share (lowercase words separated by spaces).
Equations
Instances For
Splitting text into words #
The words of a text: pieces between whitespace, empty pieces dropped.
Equations
- QedShare.Mnemonic.splitWords cs = List.filter (fun (x : List Char) => !x.isEmpty) (QedShare.Mnemonic.splitBy Char.isWhitespace cs)
Instances For
Decoding #
Why a word share could not be decoded. Errors name positions, never the words themselves.
- unknownWord (pos : Nat) : DecodeError
The word at this position (counting from 0) is not in the word list.
- badLength : DecodeError
Too few or too many words, or the length field does not fit.
- badVersion : DecodeError
The version number is not 1, 2 or 3.
- notCanonical : DecodeError
The words are not exactly what encoding the decoded bytes gives (e.g. wrong padding).
- badChecksum : DecodeError
The checksum does not match: the share was mistyped or damaged.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq (QedShare.Mnemonic.DecodeError.unknownWord a) (QedShare.Mnemonic.DecodeError.unknownWord b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq (QedShare.Mnemonic.DecodeError.unknownWord pos) QedShare.Mnemonic.DecodeError.badLength = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq (QedShare.Mnemonic.DecodeError.unknownWord pos) QedShare.Mnemonic.DecodeError.badVersion = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq (QedShare.Mnemonic.DecodeError.unknownWord pos) QedShare.Mnemonic.DecodeError.notCanonical = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq (QedShare.Mnemonic.DecodeError.unknownWord pos) QedShare.Mnemonic.DecodeError.badChecksum = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.badLength (QedShare.Mnemonic.DecodeError.unknownWord pos) = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.badLength QedShare.Mnemonic.DecodeError.badLength = isTrue ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.badVersion (QedShare.Mnemonic.DecodeError.unknownWord pos) = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.badVersion QedShare.Mnemonic.DecodeError.badVersion = isTrue ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.notCanonical (QedShare.Mnemonic.DecodeError.unknownWord pos) = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.notCanonical QedShare.Mnemonic.DecodeError.notCanonical = isTrue ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.badChecksum (QedShare.Mnemonic.DecodeError.unknownWord pos) = isFalse ⋯
- QedShare.Mnemonic.instDecidableEqDecodeError.decEq QedShare.Mnemonic.DecodeError.badChecksum QedShare.Mnemonic.DecodeError.badChecksum = isTrue ⋯
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
The set id from its 4 bytes.
Equations
- QedShare.Mnemonic.setIdOf s0 s1 s2 s3 = (QedShare.Encoding.fromBytes4 [s0, s1, s2, s3]).getD 0
Instances For
Decode word numbers into a record (see the module comment for the checks).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decode a word share given as characters.
Equations
- QedShare.Mnemonic.decodeChars cs = do let __do_lift ← QedShare.Mnemonic.lookupAll (QedShare.Mnemonic.splitWords cs) 0 QedShare.Mnemonic.decodeNums __do_lift
Instances For
Decode a word share.
Equations
Instances For
Round trip #
Below 2048, wordOf n is word number n of the list.
Decoding the word numbers of a record with a payload of at most 255 bytes (and a token of the length its format needs) gives the record.
Decoding the characters of an encoded record gives back the record.
Round trip. Decoding the word form of a share gives back exactly the same record, for every record whose payload is at most 255 bytes and whose token has the length its format needs.