Skip to main content

Module nut16

Module nut16 

Source
Expand description

NUT-16: Animated QR codes

https://github.com/cashubtc/nuts/blob/main/16.md

Tokens that are too large for a single QR code are shared as an animated QR code based on the UR protocol. The sender splits the token into a fountain-coded sequence of UR fragments (TokenUrEncoder) and displays each fragment as one QR frame. The receiver scans the frames and feeds them into a TokenUrDecoder until the token is reassembled.

Fragments are ur:bytes URs whose payload is the serialized token (cashuB…) encoded as a CBOR byte string, matching the de-facto standard used by existing NUT-16 implementations (e.g. cashu.me).

§Example

use std::str::FromStr;

use cashu::nuts::nut16::DEFAULT_MAX_FRAGMENT_LENGTH;
use cashu::nuts::{Token, TokenUrDecoder};

let token = Token::from_str("cashuBpGF0gaJhaUgArSaMTR9YJmFwgaNhYQFhc3hAOWE2ZGJiODQ3YmQyMzJiYTc2ZGIwZGYxOTcyMTZiMjlkM2I4Y2MxNDU1M2NkMjc4MjdmYzFjYzk0MmZlZGI0ZWFjWCEDhhhUP_trhpXfStS6vN6So0qWvc2X3O4NfM-Y1HISZ5JhZGlUaGFuayB5b3VhbXVodHRwOi8vbG9jYWxob3N0OjMzMzhhdWNzYXQ=")?;

// Sender: display each fragment as one QR frame
let mut encoder = token.ur_encoder(DEFAULT_MAX_FRAGMENT_LENGTH)?;
let mut decoder = TokenUrDecoder::default();

// Receiver: feed scanned frames until the token is reassembled
while !decoder.complete() {
    decoder.receive(&encoder.next_part()?)?;
}

assert_eq!(decoder.token()?, Some(token));

Structs§

TokenUrDecoder
Reassembles a Token from scanned UR fragments
TokenUrEncoder
Encodes a Token into UR fragments for display as an animated QR code

Enums§

Error
NUT-16 Error

Constants§

DEFAULT_MAX_FRAGMENT_LENGTH
Default maximum fragment length, in payload bytes per QR frame
MAX_UR_FRAGMENT_COUNT
Maximum number of source fragments accepted by the decoder
MAX_UR_MESSAGE_LENGTH
Maximum reconstructed UR message length accepted by the decoder
MAX_UR_PART_LENGTH
Maximum encoded length accepted for one UR part
TOKEN_UR_TYPE
UR type used for Cashu tokens: ur:bytes