Skip to main content

wire

import "github.com/bsv8/go-bitfs/wire"

Package wire 是 Wire v1 的 exact Artifact 层与严格分派入口。每个完整报文 以 [protocol.WireVersion, kind] 开头:Parse 从外层头自读版本与 Kind,分派到 对应的严格 decoder,验证完整数组长度、canonical CBOR、attachment 分支与 trailing 字段;ParseAs 额外交叉验证传输路由声明的 Kind 与报文自描述 Kind。 本包复制 exact CBOR 字节,不添加 envelope、签名、存储、业务验证或网络行为; 签名、金额、身份与业务状态验证由角色 API 或领域包完成。

Index​

Constants​

maxWireParseBytes 是进入 CBOR decoder 之前的全局字节上限:它必须容纳所有 Kind 的合法最大报文。Kind 11 available 分支的 payload bundle 与 Kind 8 满 载整包(payload 上限 + Claim 上限 + 签名上限 + 外壳开销)分别决定两个下 界;任何超限输入直接以 malformed_wire 拒绝,保证超大不可信输入不会消耗解 码内存与 CPU。应用可设置更小的传输层限额,但不得静默抬高本值。 MaxWireParseBytes 是完整 BitFS 报文的协议解析上限,也是 bitcoin-libp2p uvarint transport 的默认单帧接收上限。应用可以配置更小的本地限额,但不能 配置得更大后绕过 wire parser 的协议边界。

const MaxWireParseBytes = max(content.MaxContentPayloadsCBORBytes+1024, arbitration.MaxArbitrationRequestBytes)

ProtocolFamily 是外部协议族/manifest 标识字符串(wire 报文本身只携带 [WireVersion, kind, ...],不含族名称)。它是 protocol.ProtocolFamily 的 别名,仓库内不存在第二份版本字符串。

const ProtocolFamily = protocol.ProtocolFamily

func DecodeArbitrationRequest​

func DecodeArbitrationRequest(artifact Artifact) (*arbitration.ArbitrationRequest, error)

DecodeArbitrationRequest strictly decodes a Kind 8 Artifact.

func DecodeArbitrationResponse​

func DecodeArbitrationResponse(artifact Artifact) (*arbitration.ArbitrationResponse, error)

DecodeArbitrationResponse strictly decodes a Kind 9 Artifact.

func DecodeContentDelivery​

func DecodeContentDelivery(artifact Artifact) (*content.SignedContentDelivery, error)

DecodeContentDelivery strictly decodes a Kind 6 Artifact.

func DecodeContentRequest​

func DecodeContentRequest(artifact Artifact) (*content.SignedContentRequest, error)

DecodeContentRequest strictly decodes a Kind 5 Artifact.

func DecodeContentRetrievalRequest​

func DecodeContentRetrievalRequest(artifact Artifact) (*arbitration.ContentRetrievalRequest, error)

DecodeContentRetrievalRequest strictly decodes a Kind 10 Artifact.

func DecodeContentRetrievalResponse​

func DecodeContentRetrievalResponse(artifact Artifact) (*arbitration.ContentRetrievalResponse, error)

DecodeContentRetrievalResponse strictly decodes a Kind 11 Artifact.

func DecodeFileQuote​

func DecodeFileQuote(artifact Artifact) (*content.SignedFileQuote, error)

DecodeFileQuote strictly decodes a Kind 1 Artifact.

func DecodeFundingTransactionDelivery​

func DecodeFundingTransactionDelivery(artifact Artifact) (*pool.FundingTransactionDelivery, error)

DecodeFundingTransactionDelivery strictly decodes a Kind 4 Artifact.

func DecodePaymentUpdate​

func DecodePaymentUpdate(artifact Artifact) (*pool.PaymentUpdate, error)

DecodePaymentUpdate strictly decodes a Kind 7 Artifact.

func DecodeRefundPresignRequest​

func DecodeRefundPresignRequest(artifact Artifact) (*pool.RefundPresignRequest, error)

DecodeRefundPresignRequest strictly decodes a Kind 2 Artifact.

func DecodeRefundPresignResponse​

func DecodeRefundPresignResponse(artifact Artifact) (*pool.RefundPresignResponse, error)

DecodeRefundPresignResponse strictly decodes a Kind 3 Artifact.

type Artifact​

Artifact 是已通过严格解析的不可变 exact bytes:它证明 complete wire 的规范 结构(outer header、canonical CBOR、attachment 分支、trailing 字段全部 正确),不代表签名、金额、身份或业务状态已经验证。字段私有:构造只能经 Parse/ParseAs 或 typed encoder;Bytes() 返回副本,调用方无法修改内部字节, 输入 raw 的后续变异也不影响 Artifact。

type Artifact struct {
// contains filtered or unexported fields
}

func EncodeArbitrationRequest​

func EncodeArbitrationRequest(request *arbitration.ArbitrationRequest) (Artifact, error)

EncodeArbitrationRequest encodes the complete 007 evidence package into a Kind 8 Artifact.

func EncodeArbitrationResponse​

func EncodeArbitrationResponse(response *arbitration.ArbitrationResponse) (Artifact, error)

EncodeArbitrationResponse encodes the four-element receipt response into a Kind 9 Artifact.

func EncodeContentDelivery​

func EncodeContentDelivery(delivery *content.SignedContentDelivery) (Artifact, error)

EncodeContentDelivery encodes a signed delivery into a Kind 6 Artifact.

func EncodeContentRequest​

func EncodeContentRequest(request *content.SignedContentRequest) (Artifact, error)

EncodeContentRequest encodes a signed payment authorization into a Kind 5 Artifact.

func EncodeContentRetrievalRequest​

func EncodeContentRetrievalRequest(request *arbitration.ContentRetrievalRequest) (Artifact, error)

EncodeContentRetrievalRequest encodes a buyer retrieval request into a Kind 10 Artifact.

func EncodeContentRetrievalResponse​

func EncodeContentRetrievalResponse(response *arbitration.ContentRetrievalResponse) (Artifact, error)

EncodeContentRetrievalResponse encodes an arbiter-signed retrieval result into a Kind 11 Artifact.

func EncodeFileQuote​

func EncodeFileQuote(quote *content.SignedFileQuote) (Artifact, error)

EncodeFileQuote encodes a SignedFileQuote into a Kind 1 Artifact.

func EncodeFundingTransactionDelivery​

func EncodeFundingTransactionDelivery(delivery *pool.FundingTransactionDelivery) (Artifact, error)

EncodeFundingTransactionDelivery encodes the funding delivery into a Kind 4 Artifact.

func EncodePaymentUpdate​

func EncodePaymentUpdate(update *pool.PaymentUpdate) (Artifact, error)

EncodePaymentUpdate encodes a buyer payment credential into a Kind 7 Artifact.

func EncodeRefundPresignRequest​

func EncodeRefundPresignRequest(request *pool.RefundPresignRequest) (Artifact, error)

EncodeRefundPresignRequest encodes a pool-opening presign request into a Kind 2 Artifact.

func EncodeRefundPresignResponse​

func EncodeRefundPresignResponse(response *pool.RefundPresignResponse) (Artifact, error)

EncodeRefundPresignResponse encodes a presign response into a Kind 3 Artifact.

func Parse​

func Parse(raw []byte) (Artifact, error)

Parse 从 exact bytes 解析一个 Artifact:外层头自读 version/kind,显式 switch 分派到对应严格 decoder。未知版本/Kind 返回 unsupported 错误并保留原 bytes 供调用方升级或审计。

func ParseAs​

func ParseAs(expected Kind, raw []byte) (Artifact, error)

ParseAs 在 Parse 的基础上额外验证传输路由声明的 Kind 与报文自描述 Kind 一致; 路由声明可以用于分发,但不能成为唯一 Kind 真值。

func (Artifact) Bytes​

func (a Artifact) Bytes() []byte

Bytes 返回 exact CBOR 字节的副本;调用方修改副本不会影响本 Artifact。

func (Artifact) IsZero​

func (a Artifact) IsZero() bool

IsZero 报告该 Artifact 是否为空值(未经过 Parse 或编码失败后的零值)。

func (Artifact) Kind​

func (a Artifact) Kind() Kind

Kind 返回报文自描述的 Kind(从 outer header 派生)。

type Kind​

Kind identifies the message type selected by the transport. The outer pair [protocol.WireVersion, kind] opens every complete wire message; the strict decoder selected by Kind re-checks both values before interpreting any child document. Kind never identifies a pool instance: messages that define a RefundTemplateTxID carry it in their payload, while the presign request derives it from refund_template_raw.

type Kind uint16
const (
// FileQuote is a signed file quote. Direction: seller -> buyer.
FileQuote Kind = 1
// RefundPresignRequest requests the seller's refund transaction signature.
// Direction: buyer -> seller.
RefundPresignRequest Kind = 2
// RefundPresignResponse carries the seller's refund transaction signature.
// Direction: seller -> buyer.
RefundPresignResponse Kind = 3
// FundingTransactionDelivery carries the signed funding transaction.
// Direction: buyer -> seller.
FundingTransactionDelivery Kind = 4
// ContentRequest carries the signed payment authorization.
// Direction: buyer -> seller.
ContentRequest Kind = 5
// ContentDelivery carries the signed content delivery and its payload
// attachment. Direction: seller -> buyer.
ContentDelivery Kind = 6
// PaymentUpdate carries a minimal cumulative payment credential: the
// payment authorization ID plus the buyer transaction signature over the
// locally rebuilt state transaction. The receiver routes it by the
// authorization ID to the exact saved signed content request; no pool ID
// or raw transaction travels on the wire.
// Direction: buyer -> seller.
PaymentUpdate Kind = 7
// ArbitrationRequest carries evidence for arbitration.
// Direction: seller -> arbiter.
ArbitrationRequest Kind = 8
// ArbitrationResponse carries the arbitration receipt and the arbiter's
// unified signature over [1, 9, exact_receipt_cbor]; the receipt binds the
// Claim ID, the positive arbiter amount, and the arbitration transaction
// signature over the independently rebuilt candidate.
// Direction: arbiter -> seller.
ArbitrationResponse Kind = 9
// ContentRetrievalRequest carries a buyer's authenticated retrieval request
// for one arbitrated custody record:
// [1, 10, content_retrieval_request_cbor, buyer_signature]. The Claim ID
// inside the signed document routes the lookup; only the buyer key
// recovered from the stored Claim can authorize it.
// Direction: buyer -> arbiter.
ContentRetrievalRequest Kind = 10
// ContentRetrievalResponse returns one arbiter-signed retrieval result:
// branch 0 answers unavailable with a structured reason and no attachment;
// branch 1 binds the exact content_payloads_cbor through its
// content_payloads_id and attaches the payloads verbatim.
// Direction: arbiter -> buyer.
ContentRetrievalResponse Kind = 11
)

Generated by gomarkdoc