Module BSV::Wallet::Wire::Frame ¶
BRC-103 request and result frame codec.
Port of go-sdk/wallet/serializer/frame.go. Two frame types:
Request frame (client → wallet): [1 byte: call][1 byte: originator_len][originator_len bytes: UTF-8][remaining: params]
Result frame (wallet → client): [1 byte: error_code] On success (0x00): [remaining bytes: payload] On error (non-zero): [VarInt: message_len][message bytes] [VarInt: stack_len][stack bytes]
Constants¶
MAX_ORIGINATOR_BYTES ¶
Maximum originator byte length enforced at write time. Matches the BRC-100 OriginatorDomainNameStringUnder250Bytes branded type used by Wire::Validation.originator_domain!.
Public Class Methods¶
decode_varint(data, offset = 0) ¶
- @param
data[String] binary data - @param
offset[Integer] byte offset - @raise [ArgumentError]
- @return [Array(Integer, Integer)] decoded value, bytes consumed
encode_varint(n) ¶
- @param
n[Integer] unsigned integer - @return [String] Bitcoin varint encoding
read_request(bytes) ¶
Decode a request frame. - @param bytes [String] binary frame - @raise [ArgumentError] if the frame is truncated or malformed - @return [Hash] { call: Integer, originator: String, params: String }
read_result(bytes) ¶
Decode a result frame. - @param bytes [String] binary frame - @raise [BSV::Wallet::Error] the appropriate subclass on error - @raise [ArgumentError] if the frame is truncated or malformed - @return [String] binary payload on success
write_error(error:) ¶
Encode an error result frame. - @param error [BSV::Wallet::Error] the error to encode - @return [String] binary frame
write_request(call:, originator:, params: = nil) ¶
Encode a request frame. - @param call [Integer] call byte (1..28) - @param originator [String] originator domain (0..250 bytes UTF-8) - @param params [String, nil] binary params payload - @raise [ArgumentError] if originator exceeds 250 bytes - @return [String] binary frame (ASCII-8BIT encoding)
write_result(payload: = nil) ¶
Encode a success result frame. - @param payload [String, nil] binary payload - @return [String] binary frame