Skip to content

Commit d380e92

Browse files
committed
tappsbt: add ProofSuffix field to VOutput
We need a way to transport proofs that are complete in terms of MS-SMT proofs committing to the correct asset but incomplete in terms of the asset witness (in the ASSET_VERSION_V1 case). The virtual transaction output is as good a place as any other. This will also allow us to simplify some of the data structures around passive assets, as currently we need to carry those proofs around in a separate map.
1 parent dc6b106 commit d380e92

File tree

5 files changed

+208
-6
lines changed

5 files changed

+208
-6
lines changed

tappsbt/decode.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ func (o *VOutput) decode(pOut psbt.POutput, txOut *wire.TxOut) error {
289289
key: PsbtKeyTypeOutputTapProofDeliveryAddress,
290290
decoder: urlDecoder(&o.ProofDeliveryAddress),
291291
},
292+
{
293+
key: PsbtKeyTypeOutputTapAssetProofSuffix,
294+
decoder: proofDecoder(&o.ProofSuffix),
295+
},
292296
}
293297

294298
for idx := range mapping {

tappsbt/encode.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ func (o *VOutput) encode(coinType uint32) (psbt.POutput, *wire.TxOut, error) {
289289
key: PsbtKeyTypeOutputTapProofDeliveryAddress,
290290
encoder: urlEncoder(o.ProofDeliveryAddress),
291291
},
292+
{
293+
key: PsbtKeyTypeOutputTapAssetProofSuffix,
294+
encoder: proofEncoder(o.ProofSuffix),
295+
},
292296
}
293297

294298
for idx := range mapping {

tappsbt/interface.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var (
5454
PsbtKeyTypeOutputTapAnchorTapscriptSibling = []byte{0x78}
5555
PsbtKeyTypeOutputTapAssetVersion = []byte{0x79}
5656
PsbtKeyTypeOutputTapProofDeliveryAddress = []byte{0x7a}
57+
PsbtKeyTypeOutputTapAssetProofSuffix = []byte{0x7b}
5758
)
5859

5960
// The following keys are used as custom fields on the BTC level anchor
@@ -528,6 +529,13 @@ type VOutput struct {
528529
// ProofDeliveryAddress is the address to which the proof of the asset
529530
// transfer should be delivered.
530531
ProofDeliveryAddress *url.URL
532+
533+
// ProofSuffix is the optional new transition proof blob that is created
534+
// once the asset output was successfully committed to the anchor
535+
// transaction referenced above. The proof suffix is not yet complete
536+
// since the header information needs to be added once the anchor
537+
// transaction was confirmed in a block.
538+
ProofSuffix *proof.Proof
531539
}
532540

533541
// SplitLocator creates a split locator from the output. The asset ID is passed
@@ -749,3 +757,19 @@ func deserializeTweakedScriptKey(pOut psbt.POutput) (*asset.TweakedScriptKey,
749757
Tweak: tweak,
750758
}, nil
751759
}
760+
761+
// Encode encodes the virtual packet into a byte slice.
762+
func Encode(vPkt *VPacket) ([]byte, error) {
763+
var buf bytes.Buffer
764+
err := vPkt.Serialize(&buf)
765+
if err != nil {
766+
return nil, err
767+
}
768+
769+
return buf.Bytes(), nil
770+
}
771+
772+
// Decode decodes a virtual packet from a byte slice.
773+
func Decode(encoded []byte) (*VPacket, error) {
774+
return NewFromRawBytes(bytes.NewReader(encoded), false)
775+
}

tappsbt/mock.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func RandPacket(t testing.TB) *VPacket {
141141
SplitAsset: testOutputAsset,
142142
AnchorOutputTapscriptSibling: testPreimage1,
143143
ProofDeliveryAddress: courierAddress,
144+
ProofSuffix: &inputProof,
144145
}, {
145146
Amount: 345,
146147
AssetVersion: asset.Version(
@@ -502,6 +503,10 @@ func NewTestFromVOutput(t testing.TB, v *VOutput,
502503
vo.ProofDeliveryAddress = v.ProofDeliveryAddress.String()
503504
}
504505

506+
if v.ProofSuffix != nil {
507+
vo.ProofSuffix = proof.NewTestFromProof(t, v.ProofSuffix)
508+
}
509+
505510
if v.ScriptKey.TweakedScriptKey != nil {
506511
bip32Derivation, trBip32Derivation := Bip32DerivationFromKeyDesc(
507512
v.ScriptKey.RawKey, coinType,
@@ -582,6 +587,7 @@ type TestVOutput struct {
582587
TrInternalKey string `json:"tr_internal_key"`
583588
TrMerkleRoot string `json:"tr_merkle_root"`
584589
ProofDeliveryAddress string `json:"proof_delivery_address"`
590+
ProofSuffix *proof.TestProof `json:"proof_suffix"`
585591
}
586592

587593
func (to *TestVOutput) ToVOutput(t testing.TB) *VOutput {
@@ -625,6 +631,10 @@ func (to *TestVOutput) ToVOutput(t testing.TB) *VOutput {
625631
require.NoError(t, err)
626632
}
627633

634+
if to.ProofSuffix != nil {
635+
v.ProofSuffix = to.ProofSuffix.ToProof(t)
636+
}
637+
628638
if len(to.Bip32Derivation) > 0 && to.TrInternalKey != "" {
629639
firstDerivation := to.Bip32Derivation[0].ToBip32Derivation(t)
630640
keyDesc, err := KeyDescFromBip32Derivation(firstDerivation)

tappsbt/testdata/psbt_encoding_generated.json

Lines changed: 166 additions & 6 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)