Skip to main content

Module protocol

Module protocol 

Source
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§

DataChunk
Quoted data chunk delivered after payment negotiation.
DataPayment
Payment message body for chunk-by-chunk settlement.
DataPaymentAck
Payment acknowledgement for quoted chunk settlement.
DataQuoteRequest
Quote request message body
DataQuoteResponse
Quote response message body
DataRequest
Data request message body
DataResponse
Data response message body

Enums§

DataMessage
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