mirror of
https://github.com/bitcoin/bips.git
synced 2026-10-19 19:29:18 +00:00
bip-138: allow multiple content items per payload
This commit is contained in:
31
bip-0138.md
31
bip-0138.md
@@ -266,17 +266,17 @@ Implementations MUST reject empty payloads.
|
||||
`CIPHERTEXT` is the encrypted data resulting from encryption of `PAYLOAD` with algorithm
|
||||
defined in `ENCRYPTION` where `PAYLOAD` is encoded following this format:
|
||||
|
||||
`CONTENT` `LENGTH` `PLAINTEXT` (`PADDING`)
|
||||
`CONTENT` `LENGTH` `PLAINTEXT` (`CONTENT` `LENGTH` `PLAINTEXT` ...) (`PADDING`)
|
||||
|
||||
`LENGTH`: variable-length integer representing the length of `PLAINTEXT` in bytes. It MUST
|
||||
be present.
|
||||
|
||||
`PLAINTEXT`: the `LENGTH` bytes of payload data.
|
||||
|
||||
`PADDING`: OPTIONAL bytes after `PLAINTEXT`, up to the end of the decrypted `PAYLOAD`.
|
||||
Parsers MUST consume exactly `LENGTH` bytes of `PLAINTEXT` and MUST ignore everything after
|
||||
it. These bytes are reserved for size padding (see Padding) and/or vendor-specific data,
|
||||
the same way trailing bytes after `CIPHERTEXT` are reserved and ignored.
|
||||
`PADDING`: OPTIONAL bytes after the final `PLAINTEXT`, up to the end of the decrypted
|
||||
`PAYLOAD`. Parsers MUST consume exactly `LENGTH` bytes of each `PLAINTEXT`. The padding
|
||||
bytes are reserved for size padding (see Padding) and/or vendor-specific data, the same
|
||||
way trailing bytes after `CIPHERTEXT` are reserved and ignored.
|
||||
|
||||
#### Padding
|
||||
|
||||
@@ -307,14 +307,16 @@ All variable-length integers are encoded as
|
||||
|
||||
#### Content
|
||||
|
||||
`CONTENT` is a variable length field defining the type of `PLAINTEXT` being encrypted,
|
||||
it follows this format:
|
||||
`CONTENT` is a variable length field defining the type of the `PLAINTEXT` that follows
|
||||
it. It follows this format:
|
||||
|
||||
`TYPE` (`LENGTH`) `DATA`
|
||||
|
||||
`CONTENT` is a single `TYPE (LENGTH) DATA` triple, one blob describing `PLAINTEXT`.
|
||||
It is not a sequence of entries; it is immediately followed by the payload `LENGTH`
|
||||
and `PLAINTEXT`.
|
||||
A `PAYLOAD` carries one or more `CONTENT LENGTH PLAINTEXT` items, each `CONTENT`
|
||||
describing the `PLAINTEXT` immediately following it. The sequence ends at the first
|
||||
`TYPE` byte equal to `0x00`, or at the end of the `PAYLOAD`, whichever comes first; all
|
||||
remaining bytes are `PADDING`. A `PAYLOAD` MUST contain at least one item (see
|
||||
[Payload Size Limits](#payload-size-limits)).
|
||||
|
||||
`TYPE`: 1-byte unsigned integer identifying how to interpret `DATA`.
|
||||
|
||||
@@ -340,8 +342,8 @@ For all `TYPE` values except `0x01`, parsers MUST reject `CONTENT` if `LENGTH` e
|
||||
the remaining payload bytes.
|
||||
|
||||
For an unknown `TYPE` less than `0x80`, parsers MUST consume its `LENGTH` bytes of
|
||||
`DATA`, treat the content type as unknown, and continue with the payload `LENGTH`
|
||||
and `PLAINTEXT`.
|
||||
`DATA`, treat the content type as unknown, consume the following payload `LENGTH` and
|
||||
`PLAINTEXT`, and continue with the next item.
|
||||
|
||||
For an unknown `TYPE` greater than or equal to `0x80`, parsers MUST reject the
|
||||
payload.[^type-upgrade]
|
||||
@@ -480,7 +482,7 @@ The version field enables possible future enhancements:
|
||||
|
||||
### Implementation
|
||||
|
||||
- Rust [implementation](https://github.com/pythcoiner/bitcoin-encrypted-backup)
|
||||
- Rust [implementation](https://github.com/pythcoiner/bip138)
|
||||
|
||||
### Test Vectors
|
||||
|
||||
@@ -498,7 +500,8 @@ contains test vectors for generation of encryption secret.
|
||||
contains test vectors for ciphertexts generated using CHACHA20-POLY1305.
|
||||
[encrypted_backup.json](./bip-0138/test_vectors/encrypted_backup.json)
|
||||
contains test vectors for generation of complete encrypted backups, including
|
||||
BIP380 and BIP388 content.
|
||||
BIP380 and BIP388 content, a multi-content payload, and an all-zero-nonce backup
|
||||
that parsers MUST reject.
|
||||
[bip380_descriptor_backup.json](./bip-0138/test_vectors/bip380_descriptor_backup.json)
|
||||
contains test vectors for BIP380 descriptor backup documents.
|
||||
[bip388.json](./bip-0138/test_vectors/bip388.json)
|
||||
|
||||
Reference in New Issue
Block a user