@@ -35,6 +35,7 @@ const (
35
35
type SupplySubTree uint8
36
36
37
37
const (
38
+
38
39
// MintTreeType is the sub tree that tracks mints.
39
40
MintTreeType SupplySubTree = iota
40
41
@@ -235,6 +236,39 @@ func (r *RootCommitment) TxOut() (*wire.TxOut, error) {
235
236
return txOut , err
236
237
}
237
238
239
+ // CommitPoint returns the outpoint that corresponds to the root commitment.
240
+ func (r * RootCommitment ) CommitPoint () wire.OutPoint {
241
+ return wire.OutPoint {
242
+ Hash : r .Txn .TxHash (),
243
+ Index : r .TxOutIdx ,
244
+ }
245
+ }
246
+
247
+ // computeSupplyCommitTapscriptRoot creates the tapscript root hash for a supply
248
+ // commitment with the given supply root hash.
249
+ func computeSupplyCommitTapscriptRoot (supplyRootHash mssmt.NodeHash ,
250
+ ) ([]byte , error ) {
251
+
252
+ // Create a non-spendable script leaf that commits to the supply root.
253
+ tapLeaf , err := asset .NewNonSpendableScriptLeaf (
254
+ asset .PedersenVersion , supplyRootHash [:],
255
+ )
256
+ if err != nil {
257
+ return nil , fmt .Errorf ("unable to create leaf: %w" , err )
258
+ }
259
+
260
+ tapscriptTree := txscript .AssembleTaprootScriptTree (tapLeaf )
261
+ rootHash := tapscriptTree .RootNode .TapHash ()
262
+ return rootHash [:], nil
263
+ }
264
+
265
+ // TapscriptRoot returns the tapscript root hash that commits to the supply
266
+ // root. This is tweaked with the internal key to derive the output key.
267
+ func (r * RootCommitment ) TapscriptRoot () ([]byte , error ) {
268
+ supplyRootHash := r .SupplyRoot .NodeHash ()
269
+ return computeSupplyCommitTapscriptRoot (supplyRootHash )
270
+ }
271
+
238
272
// RootCommitTxOut returns the transaction output that corresponds to the root
239
273
// commitment. This is used to create a new commitment output.
240
274
func RootCommitTxOut (internalKey * btcec.PublicKey ,
@@ -245,21 +279,13 @@ func RootCommitTxOut(internalKey *btcec.PublicKey,
245
279
if tapOutKey == nil {
246
280
// We'll create a new unspendable output that contains a
247
281
// commitment to the root.
248
- //
249
- // TODO(roasbeef): need other version info here/
250
- tapLeaf , err := asset .NewNonSpendableScriptLeaf (
251
- asset .PedersenVersion , supplyRootHash [:],
252
- )
282
+ rootHash , err := computeSupplyCommitTapscriptRoot (supplyRootHash )
253
283
if err != nil {
254
- return nil , nil , fmt .Errorf ("unable to create leaf: %w" ,
255
- err )
284
+ return nil , nil , err
256
285
}
257
286
258
- tapscriptTree := txscript .AssembleTaprootScriptTree (tapLeaf )
259
-
260
- rootHash := tapscriptTree .RootNode .TapHash ()
261
287
taprootOutputKey = txscript .ComputeTaprootOutputKey (
262
- internalKey , rootHash [:] ,
288
+ internalKey , rootHash ,
263
289
)
264
290
} else {
265
291
taprootOutputKey = tapOutKey
0 commit comments