1
1
use chia_protocol:: Bytes32 ;
2
2
use chia_puzzles:: {
3
3
did:: { DidArgs , DidSolution , DID_INNER_PUZZLE_HASH } ,
4
- singleton:: SingletonStruct ,
4
+ singleton:: { SingletonStruct , SINGLETON_LAUNCHER_PUZZLE_HASH , SINGLETON_TOP_LAYER_PUZZLE_HASH } ,
5
5
} ;
6
6
use clvm_traits:: { FromClvm , ToClvm } ;
7
7
use clvm_utils:: { CurriedProgram , ToTreeHash , TreeHash } ;
8
8
use clvmr:: { Allocator , NodePtr } ;
9
9
10
10
use crate :: { DriverError , Layer , Puzzle , SpendContext } ;
11
11
12
+ /// The DID [`Layer`] keeps track of metadata and handles recovery capabilities.
13
+ /// It's typically an inner layer of the [`SingletonLayer`](crate::SingletonLayer).
12
14
#[ derive( Debug ) ]
13
15
pub struct DidLayer < M , I > {
14
- pub singleton_struct : SingletonStruct ,
16
+ /// The unique launcher id for the DID. Also referred to as the DID id.
17
+ pub launcher_id : Bytes32 ,
18
+ /// The tree hash of a list of recovery DIDs.
19
+ /// Note that this is currently *not* optional, but will be in the future.
15
20
pub recovery_list_hash : Bytes32 ,
21
+ /// The number of verifications required to recover the DID.
16
22
pub num_verifications_required : u64 ,
23
+ /// Metadata associated with the DID. This is often just `()` for DIDs without metadata.
17
24
pub metadata : M ,
25
+ /// The inner puzzle layer, commonly used for determining ownership.
18
26
pub inner_puzzle : I ,
19
27
}
20
28
21
29
impl < M , I > DidLayer < M , I > {
22
30
pub fn new (
23
- singleton_struct : SingletonStruct ,
31
+ launcher_id : Bytes32 ,
24
32
recovery_list_hash : Bytes32 ,
25
33
num_verifications_required : u64 ,
26
34
metadata : M ,
27
35
inner_puzzle : I ,
28
36
) -> Self {
29
37
Self {
30
- singleton_struct ,
38
+ launcher_id ,
31
39
recovery_list_hash,
32
40
num_verifications_required,
33
41
metadata,
@@ -54,14 +62,20 @@ where
54
62
55
63
let args = DidArgs :: < NodePtr , M > :: from_clvm ( allocator, puzzle. args ) ?;
56
64
65
+ if args. singleton_struct . mod_hash != SINGLETON_TOP_LAYER_PUZZLE_HASH . into ( )
66
+ || args. singleton_struct . launcher_puzzle_hash != SINGLETON_LAUNCHER_PUZZLE_HASH . into ( )
67
+ {
68
+ return Err ( DriverError :: InvalidSingletonStruct ) ;
69
+ }
70
+
57
71
let Some ( inner_puzzle) =
58
72
I :: parse_puzzle ( allocator, Puzzle :: parse ( allocator, args. inner_puzzle ) ) ?
59
73
else {
60
74
return Ok ( None ) ;
61
75
} ;
62
76
63
77
Ok ( Some ( Self {
64
- singleton_struct : args. singleton_struct ,
78
+ launcher_id : args. singleton_struct . launcher_id ,
65
79
recovery_list_hash : args. recovery_list_hash ,
66
80
num_verifications_required : args. num_verifications_required ,
67
81
metadata : args. metadata ,
89
103
self . inner_puzzle . construct_puzzle ( ctx) ?,
90
104
self . recovery_list_hash ,
91
105
self . num_verifications_required ,
92
- self . singleton_struct ,
106
+ SingletonStruct :: new ( self . launcher_id ) ,
93
107
& self . metadata ,
94
108
) ,
95
109
} ;
@@ -125,7 +139,7 @@ where
125
139
inner_puzzle_hash,
126
140
self . recovery_list_hash ,
127
141
self . num_verifications_required ,
128
- self . singleton_struct ,
142
+ SingletonStruct :: new ( self . launcher_id ) ,
129
143
metadata_hash,
130
144
)
131
145
}
0 commit comments