From b6f0ab8da705d9db2b594041b9293648e7919947 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 3 Oct 2023 11:15:42 -0700 Subject: [PATCH 01/13] Add CBOR metadata --- Cargo.lock | 35 +++++++++ Cargo.toml | 3 +- docs/src/SUMMARY.md | 1 + docs/src/inscriptions/metadata.md | 73 +++++++++++++++++ src/envelope.rs | 16 ++++ src/inscription.rs | 27 +++++-- src/lib.rs | 1 + src/subcommand/preview.rs | 4 +- src/subcommand/wallet/inscribe.rs | 32 +++++++- src/templates.rs | 2 + src/templates/metadata.rs | 125 ++++++++++++++++++++++++++++++ templates/inscription.html | 6 ++ 12 files changed, 315 insertions(+), 10 deletions(-) create mode 100644 docs/src/inscriptions/metadata.md create mode 100644 src/templates/metadata.rs diff --git a/Cargo.lock b/Cargo.lock index fad35c04ec..741613aa70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -661,6 +661,33 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "ciborium" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" + +[[package]] +name = "ciborium-ll" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "clap" version = "4.4.4" @@ -1352,6 +1379,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "hashbrown" version = "0.12.3" @@ -2084,6 +2117,7 @@ dependencies = [ "bitcoin", "boilerplate", "chrono", + "ciborium", "clap", "ctrlc", "derive_more", @@ -2846,6 +2880,7 @@ version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ + "indexmap 2.0.0", "itoa", "ryu", "serde", diff --git a/Cargo.toml b/Cargo.toml index 41806b48c5..aad9e93602 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ bip39 = "2.0.0" bitcoin = { version = "0.30.0", features = ["rand"] } boilerplate = { version = "1.0.0", features = ["axum"] } chrono = "0.4.19" +ciborium = "0.2.1" clap = { version = "4.4.2", features = ["derive"] } ctrlc = { version = "3.2.1", features = ["termination"] } derive_more = "0.99.17" @@ -49,7 +50,7 @@ rust-embed = "8.0.0" rustls = "0.21.1" rustls-acme = { version = "0.7.1", features = ["axum"] } serde = { version = "1.0.137", features = ["derive"] } -serde_json = { version = "1.0.81" } +serde_json = { version = "1.0.81", features = ["preserve_order"] } serde_yaml = "0.9.17" sysinfo = "0.29.2" tempfile = "3.2.0" diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 2ed5bace41..acc5b95551 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -3,6 +3,7 @@ - [Overview](overview.md) - [Digital Artifacts](digital-artifacts.md) - [Inscriptions](inscriptions.md) + - [Metadata](inscriptions/metadata.md) - [Provenance](inscriptions/provenance.md) - [Recursion](inscriptions/recursion.md) - [FAQ](faq.md) diff --git a/docs/src/inscriptions/metadata.md b/docs/src/inscriptions/metadata.md new file mode 100644 index 0000000000..fb03357fe7 --- /dev/null +++ b/docs/src/inscriptions/metadata.md @@ -0,0 +1,73 @@ +Metadata +======== + +Inscriptions may include CBOR metadata, stored as data pushes in fields with +tag `5`. Tapscript data pushes are limited to 520 bytes. Metadata longer than +520 bytes may be split into multiple tag `5` fields, which will then be +concatinated before decoding. + +Metadata is human readable, and all metadata will be displayed to the user with +its inscription. Inscribers are encouraged to consider how metadata will be +displayed, and make metadata concise and attractive. + +Metadata is rendered to HTML for display as follows: + +- `null`, `true`, `false`, numbers, and strings are rendered as plain text. +- Arrays are rendered as `