Expand description
Wire protocol for hashtree WebRTC data exchange
Compatible with hashtree-ts wire format:
- Request: [0x00][msgpack: {h: bytes32, htl?: u8, q?: u64}]
- Response: [0x01][msgpack: {h: bytes32, d: bytes, i?: u32, n?: u32}]
- QuoteRequest: [0x02][msgpack: {h: bytes32, p: u64, t: u32, m?: string}]
- QuoteResponse: [0x03][msgpack: {h: bytes32, a: bool, q?: u64, p?: u64, t?: u32, m?: string}]
- Payment: [0x04][msgpack: {h: bytes32, q: u64, c: u32, p: u64, m?: string, tok: string}]
- PaymentAck: [0x05][msgpack: {h: bytes32, q: u64, c: u32, a: bool, e?: string}]
- Chunk: [0x06][msgpack: {h: bytes32, q: u64, c: u32, n: u32, p: u64, d: bytes}]
Fragmented responses include i (index) and n (total), unfragmented omit them.
Structs§
- Data
Chunk - Quoted data chunk delivered after payment negotiation.
- Data
Payment - Payment message body for chunk-by-chunk settlement.
- Data
Payment Ack - Payment acknowledgement for quoted chunk settlement.
- Data
Quote Request - Quote request message body
- Data
Quote Response - Quote response message body
- Data
Request - Data request message body
- Data
Response - Data response message body
Enums§
- Data
Message - Parsed data message
Constants§
- FRAGMENT_
SIZE - Fragment size for large data (32KB - safe limit for WebRTC)
- MSG_
TYPE_ CHUNK - MSG_
TYPE_ PAYMENT - MSG_
TYPE_ PAYMENT_ ACK - MSG_
TYPE_ QUOTE_ REQUEST - MSG_
TYPE_ QUOTE_ RESPONSE - MSG_
TYPE_ REQUEST - Message type bytes (prefix before MessagePack body)
- MSG_
TYPE_ RESPONSE
Functions§
- bytes_
to_ hash - Convert bytes to Hash
- create_
fragment_ response - Create a fragmented response
- create_
quote_ request - Create a quote request.
- create_
quote_ response_ available - Create an accepted quote response.
- create_
quote_ response_ unavailable - Create a declined quote response.
- create_
request - Create a request
- create_
request_ with_ quote - Create a request that references a previously accepted quote.
- create_
response - Create an unfragmented response
- encode_
chunk - Encode a quoted data chunk to wire format.
- encode_
payment - Encode a payment message to wire format.
- encode_
payment_ ack - Encode a payment acknowledgement to wire format.
- encode_
quote_ request - Encode a quote request message to wire format.
- encode_
quote_ response - Encode a quote response message to wire format.
- encode_
request - Encode a request message to wire format Uses named/map encoding for compatibility with hashtree-ts and to support optional fields
- encode_
response - Encode a response message to wire format Uses named/map encoding for compatibility with hashtree-ts and to support optional fields
- hash_
to_ bytes - Convert Hash to bytes
- hash_
to_ key - Convert hash bytes to hex string for use as map key
- is_
fragmented - Check if a response is fragmented
- parse_
message - Parse a wire format message