Skip to content

Commit 14e0093

Browse files
committed
universe: add new UniqueLeafKey that includes the asset ID
We then also add a new concrete implementation of this leaf key. The interface will allow us to pass it in anywhere that the normal LeafKey is expected.
1 parent 5995896 commit 14e0093

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

universe/interface.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ type LeafKey interface {
274274
LeafOutPoint() wire.OutPoint
275275
}
276276

277+
// UniqueLeafKey is an interface that allows us to obtain the universe key for a
278+
// leaf within a universe. This is used to uniquely identify a leaf within a
279+
// universe. Compared to LeafKey, it includes the asset ID of a leaf within the
280+
// universe key calculation.
281+
type UniqueLeafKey interface {
282+
LeafKey
283+
284+
// LeafAssetID returns the asset ID for the leaf.
285+
LeafAssetID() asset.ID
286+
}
287+
277288
// BaseLeafKey is the top level leaf key for a universe. This will be used to
278289
// key into a universe's MS-SMT data structure. The final serialized key is:
279290
// sha256(mintingOutpoint || scriptKey). This ensures that all leaves for a
@@ -314,6 +325,35 @@ func (b BaseLeafKey) LeafOutPoint() wire.OutPoint {
314325
return b.OutPoint
315326
}
316327

328+
// AssetLeafKey is a super-set of the BaseLeafKey struct that also includes the
329+
// asset ID.
330+
type AssetLeafKey struct {
331+
BaseLeafKey
332+
333+
// AssetID is the asset ID of the asset that the leaf is associated
334+
// with.
335+
AssetID asset.ID
336+
}
337+
338+
// LeafAssetID returns the asset ID for the leaf.
339+
func (a AssetLeafKey) LeafAssetID() asset.ID {
340+
return a.AssetID
341+
}
342+
343+
// UniverseKey returns the universe key for the leaf.
344+
func (a AssetLeafKey) UniverseKey() [32]byte {
345+
// key = sha256(mintingOutpoint || scriptKey || assetID)
346+
h := sha256.New()
347+
_ = wire.WriteOutPoint(h, 0, 0, &a.OutPoint)
348+
h.Write(schnorr.SerializePubKey(a.ScriptKey.PubKey))
349+
h.Write(a.AssetID[:])
350+
351+
var k [32]byte
352+
copy(k[:], h.Sum(nil))
353+
354+
return k
355+
}
356+
317357
// Proof associates a universe leaf (and key) with its corresponding multiverse
318358
// and universe inclusion proofs.
319359
//

0 commit comments

Comments
 (0)