@@ -31,8 +31,11 @@ impl RedeemerWitnessKey {
3131#[ wasm_bindgen]
3232#[ derive( Clone ) ]
3333pub struct RequiredWitnessSet {
34- vkeys : HashSet < Vkey > ,
35- bootstraps : HashSet < Vkey > ,
34+ // note: the real key type for these is Vkey
35+ // but cryptographically these should be equivalent and Ed25519KeyHash is more flexible
36+ vkeys : HashSet < Ed25519KeyHash > ,
37+ bootstraps : HashSet < Ed25519KeyHash > ,
38+
3639 native_scripts : HashSet < ScriptHash > ,
3740 plutus_scripts : HashSet < ScriptHash > ,
3841 plutus_data : HashSet < DataHash > ,
@@ -45,14 +48,20 @@ impl RequiredWitnessSet {
4548 self . add_vkey_key ( & vkey. vkey ( ) ) ;
4649 }
4750 pub fn add_vkey_key ( & mut self , vkey : & Vkey ) {
48- self . vkeys . insert ( vkey. clone ( ) ) ;
51+ self . add_vkey_key_hash ( & vkey. public_key ( ) . hash ( ) ) ;
52+ }
53+ pub fn add_vkey_key_hash ( & mut self , hash : & Ed25519KeyHash ) {
54+ self . vkeys . insert ( hash. clone ( ) ) ;
4955 }
5056
5157 pub fn add_bootstrap ( & mut self , bootstrap : & BootstrapWitness ) {
5258 self . add_bootstrap_key ( & bootstrap. vkey ( ) ) ;
5359 }
5460 pub fn add_bootstrap_key ( & mut self , bootstrap : & Vkey ) {
55- self . bootstraps . insert ( bootstrap. clone ( ) ) ;
61+ self . add_bootstrap_key_hash ( & bootstrap. public_key ( ) . hash ( ) ) ;
62+ }
63+ pub fn add_bootstrap_key_hash ( & mut self , hash : & Ed25519KeyHash ) {
64+ self . bootstraps . insert ( hash. clone ( ) ) ;
5665 }
5766
5867 pub fn add_native_script ( & mut self , native_script : & NativeScript ) {
@@ -63,7 +72,6 @@ impl RequiredWitnessSet {
6372 }
6473
6574 pub fn add_plutus_script ( & mut self , plutus_script : & PlutusScript ) {
66- // TODO: don't assume PlutusV1 and instead somehow calculate this
6775 self . add_plutus_hash ( & plutus_script. hash ( ScriptHashNamespace :: PlutusV1 ) ) ;
6876 }
6977 pub fn add_plutus_hash ( & mut self , plutus_script : & ScriptHash ) {
@@ -156,7 +164,6 @@ impl TransactionWitnessSetBuilder {
156164 }
157165
158166 pub fn add_plutus_script ( & mut self , plutus_script : & PlutusScript ) {
159- // TODO: don't assume PlutusV1 and instead somehow calculate this
160167 self . plutus_scripts . insert ( plutus_script. hash ( ScriptHashNamespace :: PlutusV1 ) , plutus_script. clone ( ) ) ;
161168 }
162169
@@ -220,11 +227,11 @@ impl TransactionWitnessSetBuilder {
220227
221228 if self . vkeys . len ( ) > 0 {
222229 result. set_vkeys ( & Vkeywitnesses ( self . vkeys . values ( ) . cloned ( ) . collect ( ) ) ) ;
223- self . vkeys . keys ( ) . for_each ( |key| { remaining_wits. vkeys . remove ( key) ; } ) ;
230+ self . vkeys . keys ( ) . for_each ( |key| { remaining_wits. vkeys . remove ( & key. public_key ( ) . hash ( ) ) ; } ) ;
224231 }
225232 if self . bootstraps . len ( ) > 0 {
226233 result. set_bootstraps ( & BootstrapWitnesses ( self . bootstraps . values ( ) . cloned ( ) . collect ( ) ) ) ;
227- self . bootstraps . keys ( ) . for_each ( |key| { remaining_wits. bootstraps . remove ( key) ; } ) ;
234+ self . bootstraps . keys ( ) . for_each ( |key| { remaining_wits. bootstraps . remove ( & key. public_key ( ) . hash ( ) ) ; } ) ;
228235 }
229236 if self . native_scripts . len ( ) > 0 {
230237 result. set_native_scripts ( & NativeScripts ( self . native_scripts . values ( ) . cloned ( ) . collect ( ) ) ) ;
@@ -367,7 +374,7 @@ mod tests {
367374 // once we have mock data for them
368375
369376 #[ test]
370- fn requirement_test ( ) {
377+ fn requirement_test_fail ( ) {
371378 let mut builder = TransactionWitnessSetBuilder :: new ( ) ;
372379
373380 let mut required_wits = RequiredWitnessSet :: new ( ) ;
@@ -383,7 +390,23 @@ mod tests {
383390 & fake_raw_key_sig ( 1 )
384391 ) ) ;
385392
386- assert ! ( builder. build( ) . is_err( )
387- ) ;
393+ assert ! ( builder. build( ) . is_err( ) ) ;
394+ }
395+
396+ #[ test]
397+ fn requirement_test_pass ( ) {
398+ let mut builder = TransactionWitnessSetBuilder :: new ( ) ;
399+
400+ let mut required_wits = RequiredWitnessSet :: new ( ) ;
401+ required_wits. add_vkey_key ( & Vkey :: new ( & fake_raw_key_public ( 0 ) ) ) ;
402+ builder. add_required_wits ( & required_wits) ;
403+
404+ // add a different element
405+ builder. add_vkey ( & Vkeywitness :: new (
406+ & Vkey :: new ( & fake_raw_key_public ( 0 ) ) ,
407+ & fake_raw_key_sig ( 0 )
408+ ) ) ;
409+
410+ assert ! ( builder. build( ) . is_ok( ) ) ;
388411 }
389412}
0 commit comments