Skip to main content

Module request

Module request 

Source
Expand description

Requests: Nostr events of kind REQUEST_KIND signed by an account’s key, each applied at most once by its id (teller.mjs requestTags, requestEvent, parseRequest).

  • join: be watched (the operator derives the account’s deposit address);
  • withdraw: an amount to an address, paid out by the operator;
  • transfer: an amount to another account, applied on sight.

The tags are ledger (the ledger’s hash), op, id, and for a withdrawal or transfer amount (whole satoshis as a string) and to. The content is empty. The teller draws a missing id from the browser’s random source; this crate does no I/O, so the caller supplies the id (request_id writes 16 random bytes the teller’s way).

use bitcoin::secp256k1::SecretKey;
use webledgers_teller::{parse_request, pubkey_hex, request_event, request_id, Op, RequestParams};

let alice = SecretKey::from_slice(&[0x22; 32]).unwrap();
let ledger = "cd".repeat(32);
let id = request_id([7; 16]);
let ev = request_event(&alice, &RequestParams::transfer(&ledger, 5, "bb".repeat(32).as_str(), &id), 1_759_300_000).unwrap();

let r = parse_request(&ev, &ledger).unwrap();
assert_eq!(r.op, Op::Transfer);
assert_eq!(r.account, format!("did:nostr:{}", pubkey_hex(&alice)));
assert_eq!(r.amount, Some(5));
assert_eq!(r.to.as_deref(), Some(format!("did:nostr:{}", "bb".repeat(32)).as_str()));

Structs§

Request
A request read back and verified (parseRequest’s result).
RequestParams
What a request carries (requestTags’ argument).

Enums§

Op
What a request asks for.

Functions§

parse_request
parseRequest: a request for the ledger ledger_hash, verified, its account its author. Refusals in the teller’s words: not kind 3700, does not verify, for another ledger, no valid op or id (8 to 64 lowercase hex), a bad amount, no destination; a transfer’s to must be an account.
request_event
requestEvent: the request signed by the account’s key (BIP 340, zero auxiliary randomness).
request_id
A request id the teller’s way: 16 bytes (from the caller’s random source) as 32 lowercase hex digits.
request_tags
requestTags: ledger, op, id, and for a withdrawal or transfer amount and to (a transfer’s to read as an account, a withdrawal’s trimmed). Refuses a ledger hash that is not 64 lowercase hex (Error::RequestLedgerHash), a withdrawal or transfer with no amount or one beyond 21 million coins (Error::Amount) and one with no to (Error::NoDestination).
request_template
The unsigned request (kind REQUEST_KIND, empty content); its pubkey is the signer’s, filled in when it is signed. For a key held elsewhere: sign UnsignedEvent::id_bytes and attach it with UnsignedEvent::with_signature.