open-standards/smart-byte/smart-byte-rs/crates/smart-byte-nostr/tests/bech32_roundtrip.rs
Transaction Science 7ef14c2ea9 ingest wave B: 3 crates · op-payouts + smart-byte-nostr + eoc-streaming
OpenPay (1 crate, 2174 LOC, 14 tests)
  op-payouts          Multi-rail payout engine. Visa Direct, Mastercard Send,
                      ACH credits (NACHA), Fedwire + SWIFT MT103 + ISO 20022
                      pacs.008, SEPA SCT + SCT Inst (mod-97 IBAN), UK FPS,
                      FedNow, RTP, PayPal, Wise. Crypto: USDC/USDT on
                      ETH/Polygon/Base/Solana + BTC + Lightning with real
                      ERC-20 transfer(address,uint256) calldata. Offline-pure
                      drivers (emit wire payloads — operators transmit).

Smart Byte (1 crate, 2605 LOC, 38 tests)
  smart-byte-nostr    Nostr adapter. NIP-01 canonical event id + BIP-340
                      Schnorr sign/verify; from-scratch bech32 + NIP-19 TLV
                      (npub/nsec/note/nprofile/nevent/nrelay); NIP-04 legacy
                      AES-256-CBC DMs; NIP-44 v2 HKDF-SHA256→ChaCha20+HMAC
                      with bucketed padding; NIP-17 gift-wrap (kind 1059) +
                      seal (kind 13) + rumor (kind 14); NIP-05/11/13/26/65.
                      Relay client message vocabulary (REQ/EVENT/CLOSE/AUTH/
                      EOSE/OK/NOTICE/CLOSED) + in-memory router.

EOC (1 crate, 2024 LOC, 30 tests)
  eoc-streaming       Token-by-token + tool-call streaming primitives.
                      SSE framing (data: lines); Anthropic event mapper
                      (message_start/content_block_*/message_delta/stop/ping);
                      OpenAI delta mapper; Vercel AI SDK mapper. Bounded-channel
                      backpressure with watermarks; CancelToken propagation;
                      Last-Event-ID resumable streams; per-stream joule meter.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-24 13:39:09 -04:00

59 lines
1.7 KiB
Rust

//! Integration test: NIP-19 bech32 encodings.
use smart_byte_nostr::bech32::{
NEvent, NProfile, NRelay, decode_nevent, decode_note, decode_nprofile, decode_npub,
decode_nrelay, decode_nsec, encode_nevent, encode_note, encode_nprofile, encode_npub,
encode_nrelay, encode_nsec,
};
#[test]
fn npub_nsec_note_roundtrip() {
let pk = [0x11u8; 32];
let sk = [0x22u8; 32];
let note = [0x33u8; 32];
assert_eq!(decode_npub(&encode_npub(&pk).expect("enc")).expect("dec"), pk);
assert_eq!(decode_nsec(&encode_nsec(&sk).expect("enc")).expect("dec"), sk);
assert_eq!(decode_note(&encode_note(&note).expect("enc")).expect("dec"), note);
}
#[test]
fn nprofile_roundtrip_with_relays() {
let p = NProfile {
pubkey: [0x44u8; 32],
relays: vec!["wss://a.relay".into(), "wss://b.relay".into()],
};
let s = encode_nprofile(&p).expect("enc");
let d = decode_nprofile(&s).expect("dec");
assert_eq!(d, p);
}
#[test]
fn nevent_roundtrip_full() {
let e = NEvent {
event_id: [0x55u8; 32],
relays: vec!["wss://relay.example".into()],
author: Some([0x66u8; 32]),
kind: Some(1),
};
let s = encode_nevent(&e).expect("enc");
let d = decode_nevent(&s).expect("dec");
assert_eq!(d, e);
}
#[test]
fn nrelay_roundtrip() {
let r = NRelay {
url: "wss://only.relay".into(),
};
let s = encode_nrelay(&r).expect("enc");
let d = decode_nrelay(&s).expect("dec");
assert_eq!(d, r);
}
#[test]
fn hrp_mismatch_is_rejected() {
let pk = [0x77u8; 32];
let s = encode_npub(&pk).expect("enc");
// Trying to decode an npub as an nsec should fail.
assert!(decode_nsec(&s).is_err());
}