@@ -11,15 +11,139 @@ import (
1111 "time"
1212
1313 "github.com/btcsuite/btcd/btcec/v2"
14+ "github.com/btcsuite/btcd/btcec/v2/schnorr"
1415 "github.com/btcsuite/btcd/chaincfg/chainhash"
16+ "github.com/btcsuite/btcd/txscript"
1517 "github.com/btcsuite/btcd/wire"
1618 "github.com/lightninglabs/taproot-assets/asset"
1719 "github.com/lightninglabs/taproot-assets/commitment"
1820 "github.com/lightninglabs/taproot-assets/fn"
1921 "github.com/lightninglabs/taproot-assets/internal/test"
22+ "github.com/lightningnetwork/lnd/keychain"
2023 "github.com/stretchr/testify/require"
2124)
2225
26+ func RandProof (t testing.TB , genesis asset.Genesis ,
27+ scriptKey * btcec.PublicKey , block wire.MsgBlock , txIndex int ,
28+ outputIndex uint32 ) Proof {
29+
30+ txMerkleProof , err := NewTxMerkleProof (block .Transactions , txIndex )
31+ require .NoError (t , err )
32+
33+ tweakedScriptKey := asset .NewScriptKey (scriptKey )
34+ protoAsset := asset .NewAssetNoErr (
35+ t , genesis , 1 , 0 , 0 , tweakedScriptKey , nil ,
36+ )
37+ groupKey := asset .RandGroupKey (t , genesis , protoAsset )
38+ groupReveal := asset.GroupKeyReveal {
39+ RawKey : asset .ToSerialized (& groupKey .GroupPubKey ),
40+ TapscriptRoot : test .RandBytes (32 ),
41+ }
42+
43+ amount := uint64 (1 )
44+ mintCommitment , assets , err := commitment .Mint (
45+ genesis , groupKey , & commitment.AssetDetails {
46+ Type : genesis .Type ,
47+ ScriptKey : test .PubToKeyDesc (scriptKey ),
48+ Amount : & amount ,
49+ LockTime : 1337 ,
50+ RelativeLockTime : 6 ,
51+ },
52+ )
53+ require .NoError (t , err )
54+ proofAsset := assets [0 ]
55+ proofAsset .GroupKey .RawKey = keychain.KeyDescriptor {}
56+
57+ // Empty the group witness, since it will eventually be stored as the
58+ // asset's witness within the proof.
59+ // TODO(guggero): Actually store the witness in the proof.
60+ proofAsset .GroupKey .Witness = nil
61+
62+ // Empty the raw script key, since we only serialize the tweaked
63+ // pubkey. We'll also force the main script key to be an x-only key as
64+ // well.
65+ proofAsset .ScriptKey .PubKey , err = schnorr .ParsePubKey (
66+ schnorr .SerializePubKey (proofAsset .ScriptKey .PubKey ),
67+ )
68+ require .NoError (t , err )
69+
70+ proofAsset .ScriptKey .TweakedScriptKey = nil
71+
72+ _ , commitmentProof , err := mintCommitment .Proof (
73+ proofAsset .TapCommitmentKey (), proofAsset .AssetCommitmentKey (),
74+ )
75+ require .NoError (t , err )
76+
77+ leaf1 := txscript .NewBaseTapLeaf ([]byte {1 })
78+ leaf2 := txscript .NewBaseTapLeaf ([]byte {2 })
79+ testLeafPreimage := commitment .NewPreimageFromLeaf (leaf1 )
80+ testLeafPreimage2 := commitment .NewPreimageFromLeaf (leaf2 )
81+ testBranchPreimage := commitment .NewPreimageFromBranch (
82+ txscript .NewTapBranch (leaf1 , leaf2 ),
83+ )
84+ return Proof {
85+ PrevOut : genesis .FirstPrevOut ,
86+ BlockHeader : block .Header ,
87+ BlockHeight : 42 ,
88+ AnchorTx : * block .Transactions [txIndex ],
89+ TxMerkleProof : * txMerkleProof ,
90+ Asset : * proofAsset ,
91+ InclusionProof : TaprootProof {
92+ OutputIndex : outputIndex ,
93+ InternalKey : test .RandPubKey (t ),
94+ CommitmentProof : & CommitmentProof {
95+ Proof : * commitmentProof ,
96+ TapSiblingPreimage : testLeafPreimage ,
97+ },
98+ TapscriptProof : nil ,
99+ },
100+ ExclusionProofs : []TaprootProof {
101+ {
102+ OutputIndex : 2 ,
103+ InternalKey : test .RandPubKey (t ),
104+ CommitmentProof : & CommitmentProof {
105+ Proof : * commitmentProof ,
106+ TapSiblingPreimage : testLeafPreimage ,
107+ },
108+ TapscriptProof : nil ,
109+ },
110+ {
111+ OutputIndex : 3 ,
112+ InternalKey : test .RandPubKey (t ),
113+ CommitmentProof : nil ,
114+ TapscriptProof : & TapscriptProof {
115+ TapPreimage1 : testBranchPreimage ,
116+ TapPreimage2 : testLeafPreimage2 ,
117+ Bip86 : true ,
118+ },
119+ },
120+ {
121+ OutputIndex : 4 ,
122+ InternalKey : test .RandPubKey (t ),
123+ CommitmentProof : nil ,
124+ TapscriptProof : & TapscriptProof {
125+ Bip86 : true ,
126+ },
127+ },
128+ },
129+ SplitRootProof : & TaprootProof {
130+ OutputIndex : 4 ,
131+ InternalKey : test .RandPubKey (t ),
132+ CommitmentProof : & CommitmentProof {
133+ Proof : * commitmentProof ,
134+ TapSiblingPreimage : nil ,
135+ },
136+ },
137+ MetaReveal : & MetaReveal {
138+ Data : []byte ("quoth the raven nevermore" ),
139+ Type : MetaOpaque ,
140+ },
141+ ChallengeWitness : wire.TxWitness {[]byte ("foo" ), []byte ("bar" )},
142+ GenesisReveal : & genesis ,
143+ GroupKeyReveal : & groupReveal ,
144+ }
145+ }
146+
23147type MockVerifier struct {
24148 t * testing.T
25149}
0 commit comments