跳到主要内容

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 或领域包完成。

索引​

常量​

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

函数 DecodeArbitrationRequest​

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

DecodeArbitrationRequest 严格解码 Kind 8 Artifact。

函数 DecodeArbitrationResponse​

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

DecodeArbitrationResponse 严格解码 Kind 9 Artifact。

函数 DecodeContentDelivery​

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

DecodeContentDelivery 严格解码 Kind 6 Artifact。

函数 DecodeContentRequest​

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

DecodeContentRequest 严格解码 Kind 5 Artifact。

函数 DecodeContentRetrievalRequest​

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

DecodeContentRetrievalRequest 严格解码 Kind 10 Artifact。

函数 DecodeContentRetrievalResponse​

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

DecodeContentRetrievalResponse 严格解码 Kind 11 Artifact。

函数 DecodeFileQuote​

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

DecodeFileQuote 严格解码 Kind 1 Artifact。

函数 DecodeFundingTransactionDelivery​

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

DecodeFundingTransactionDelivery 严格解码 Kind 4 Artifact。

函数 DecodePaymentUpdate​

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

DecodePaymentUpdate 严格解码 Kind 7 Artifact。

函数 DecodeRefundPresignRequest​

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

DecodeRefundPresignRequest 严格解码 Kind 2 Artifact。

函数 DecodeRefundPresignResponse​

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

DecodeRefundPresignResponse 严格解码 Kind 3 Artifact。

类型 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
}

函数 EncodeArbitrationRequest​

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

EncodeArbitrationRequest 把完整 007 证据包编码为 Kind 8 Artifact。

函数 EncodeArbitrationResponse​

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

EncodeArbitrationResponse 把四元回执应答编码为 Kind 9 Artifact。

函数 EncodeContentDelivery​

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

EncodeContentDelivery 把已签交付编码为 Kind 6 Artifact。

函数 EncodeContentRequest​

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

EncodeContentRequest 把已签付款授权编码为 Kind 5 Artifact。

函数 EncodeContentRetrievalRequest​

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

EncodeContentRetrievalRequest 把买方取回请求编码为 Kind 10 Artifact。

函数 EncodeContentRetrievalResponse​

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

EncodeContentRetrievalResponse 把仲裁方签署的取回结果编码为 Kind 11 Artifact。

函数 EncodeFileQuote​

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

EncodeFileQuote 把 SignedFileQuote 编码为 Kind 1 Artifact。

函数 EncodeFundingTransactionDelivery​

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

EncodeFundingTransactionDelivery 把资金交付编码为 Kind 4 Artifact。

函数 EncodePaymentUpdate​

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

EncodePaymentUpdate 把买方付款凭证编码为 Kind 7 Artifact。

函数 EncodeRefundPresignRequest​

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

EncodeRefundPresignRequest 把开池预签请求编码为 Kind 2 Artifact。

函数 EncodeRefundPresignResponse​

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

EncodeRefundPresignResponse 把预签响应编码为 Kind 3 Artifact。

函数 Parse​

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

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

函数 ParseAs​

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

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

函数 (Artifact) Bytes​

func (a Artifact) Bytes() []byte

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

函数 (Artifact) IsZero​

func (a Artifact) IsZero() bool

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

函数 (Artifact) Kind​

func (a Artifact) Kind() Kind

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

类型 Kind​

Kind 标识传输层选择的报文类型。外层对 [protocol.WireVersion, kind] 开启每个完整 wire 报文;由 Kind 选出的严格 decoder 在解释任何子文档前都会复核这两个值。Kind 从不标识资金池实例:定义 RefundTemplateTxID 的报文在 payload 中携带它,而预签请求从 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
)

由 gomarkdoc 生成