@@ -4,7 +4,7 @@ use ic_management_canister_types_private::{
4
4
self as ic00, CanisterInstallMode , DerivationPath , ECDSAPublicKeyResponse , EcdsaCurve ,
5
5
EcdsaKeyId , MasterPublicKeyId , Method , Payload as Ic00Payload , SchnorrAlgorithm , SchnorrKeyId ,
6
6
SchnorrPublicKeyResponse , SignWithBip341Aux , SignWithECDSAReply , SignWithSchnorrAux ,
7
- SignWithSchnorrReply ,
7
+ SignWithSchnorrReply , VetKdCurve , VetKdDeriveKeyResult , VetKdKeyId , VetKdPublicKeyResult ,
8
8
} ;
9
9
use ic_registry_subnet_type:: SubnetType ;
10
10
use ic_state_machine_tests:: { StateMachine , StateMachineBuilder , UserError } ;
@@ -48,6 +48,13 @@ fn make_bip340_key(name: &str) -> MasterPublicKeyId {
48
48
} )
49
49
}
50
50
51
+ fn make_vetkd_key ( name : & str ) -> MasterPublicKeyId {
52
+ MasterPublicKeyId :: VetKd ( VetKdKeyId {
53
+ curve : VetKdCurve :: Bls12_381_G2 ,
54
+ name : name. to_string ( ) ,
55
+ } )
56
+ }
57
+
51
58
fn into_inner_ecdsa ( key_id : MasterPublicKeyId ) -> EcdsaKeyId {
52
59
match key_id {
53
60
MasterPublicKeyId :: Ecdsa ( key) => key,
@@ -62,6 +69,13 @@ fn into_inner_schnorr(key_id: MasterPublicKeyId) -> SchnorrKeyId {
62
69
}
63
70
}
64
71
72
+ fn into_inner_vetkd ( key_id : MasterPublicKeyId ) -> VetKdKeyId {
73
+ match key_id {
74
+ MasterPublicKeyId :: VetKd ( key) => key,
75
+ _ => panic ! ( "unexpected key_id type" ) ,
76
+ }
77
+ }
78
+
65
79
fn compute_initial_threshold_key_dealings_payload (
66
80
method : Method ,
67
81
key_id : MasterPublicKeyId ,
@@ -107,6 +121,17 @@ fn sign_with_threshold_key_payload(method: Method, key_id: MasterPublicKeyId) ->
107
121
}
108
122
}
109
123
. encode ( ) ,
124
+ Method :: VetKdDeriveKey => {
125
+ let key_id = into_inner_vetkd ( key_id) ;
126
+
127
+ ic00:: VetKdDeriveKeyArgs {
128
+ context : vec ! [ ] ,
129
+ input : vec ! [ ] ,
130
+ key_id,
131
+ transport_public_key : ic_crypto_test_utils_vetkd:: dummy_transport_public_key ( ) ,
132
+ }
133
+ }
134
+ . encode ( ) ,
110
135
_ => panic ! ( "unexpected method" ) ,
111
136
}
112
137
}
@@ -125,6 +150,12 @@ fn threshold_public_key_payload(method: Method, key_id: MasterPublicKeyId) -> Ve
125
150
key_id : into_inner_schnorr ( key_id) ,
126
151
}
127
152
. encode ( ) ,
153
+ Method :: VetKdPublicKey => ic00:: VetKdPublicKeyArgs {
154
+ canister_id : None ,
155
+ context : vec ! [ ] ,
156
+ key_id : into_inner_vetkd ( key_id) ,
157
+ }
158
+ . encode ( ) ,
128
159
_ => panic ! ( "unexpected method" ) ,
129
160
}
130
161
}
@@ -422,6 +453,7 @@ fn test_sign_with_threshold_key_fee_charged() {
422
453
let contexts = match method {
423
454
Method :: SignWithECDSA => env. sign_with_ecdsa_contexts ( ) ,
424
455
Method :: SignWithSchnorr => env. sign_with_schnorr_contexts ( ) ,
456
+ Method :: VetKdDeriveKey => env. vetkd_derive_key_contexts ( ) ,
425
457
_ => panic ! ( "Unexpected method" ) ,
426
458
} ;
427
459
let ( _, context) = contexts. iter ( ) . next ( ) . unwrap ( ) ;
@@ -435,6 +467,7 @@ fn test_sign_with_threshold_key_fee_charged() {
435
467
let signature = match method {
436
468
Method :: SignWithECDSA => expect_reply :: < SignWithECDSAReply > ( result) . signature ,
437
469
Method :: SignWithSchnorr => expect_reply :: < SignWithSchnorrReply > ( result) . signature ,
470
+ Method :: VetKdDeriveKey => expect_reply :: < VetKdDeriveKeyResult > ( result) . encrypted_key ,
438
471
_ => panic ! ( "Unexpected method" ) ,
439
472
} ;
440
473
// Expect non-empty signature.
@@ -512,6 +545,11 @@ fn test_sign_with_threshold_key_unknown_key_rejected() {
512
545
make_bip340_key( "correct_key" ) ,
513
546
make_bip340_key( "wrong_key" ) ,
514
547
) ,
548
+ (
549
+ Method :: VetKdDeriveKey ,
550
+ make_vetkd_key( "correct_key" ) ,
551
+ make_vetkd_key( "wrong_key" ) ,
552
+ ) ,
515
553
] ;
516
554
for ( method, correct_key, wrong_key) in test_cases {
517
555
let own_subnet = subnet_test_id ( 1 ) ;
@@ -624,6 +662,12 @@ fn test_signing_disabled_vs_unknown_key_on_public_key_and_signing_requests() {
624
662
make_bip340_key( "signing_disabled_key" ) ,
625
663
make_bip340_key( "unknown_key" ) ,
626
664
) ,
665
+ (
666
+ Method :: VetKdPublicKey ,
667
+ Method :: VetKdDeriveKey ,
668
+ make_vetkd_key( "signing_disabled_key" ) ,
669
+ make_vetkd_key( "unknown_key" ) ,
670
+ ) ,
627
671
] ;
628
672
for ( public_key_method, sign_with_method, signing_disabled_key, unknown_key) in test_cases {
629
673
let own_subnet = subnet_test_id ( 1 ) ;
@@ -654,6 +698,10 @@ fn test_signing_disabled_vs_unknown_key_on_public_key_and_signing_requests() {
654
698
let response = expect_reply :: < SchnorrPublicKeyResponse > ( result) ;
655
699
assert ! ( !response. public_key. is_empty( ) && !response. chain_code. is_empty( ) ) ;
656
700
}
701
+ Method :: VetKdPublicKey => {
702
+ let response = expect_reply :: < VetKdPublicKeyResult > ( result) ;
703
+ assert ! ( !response. public_key. is_empty( ) ) ;
704
+ }
657
705
_ => panic ! ( "Unexpected method" ) ,
658
706
}
659
707
@@ -710,6 +758,11 @@ fn test_threshold_key_public_key_req_with_unknown_key_rejected() {
710
758
make_bip340_key( "correct_key" ) ,
711
759
make_bip340_key( "wrong_key" ) ,
712
760
) ,
761
+ (
762
+ Method :: VetKdPublicKey ,
763
+ make_vetkd_key( "correct_key" ) ,
764
+ make_vetkd_key( "wrong_key" ) ,
765
+ ) ,
713
766
] ;
714
767
for ( method, correct_key, wrong_key) in test_cases {
715
768
let own_subnet = subnet_test_id ( 1 ) ;
@@ -742,6 +795,7 @@ fn test_sign_with_threshold_key_fee_ignored_for_nns() {
742
795
( Method :: SignWithECDSA , make_ecdsa_key( "some_key" ) ) ,
743
796
( Method :: SignWithSchnorr , make_ed25519_key( "some_key" ) ) ,
744
797
( Method :: SignWithSchnorr , make_bip340_key( "some_key" ) ) ,
798
+ ( Method :: VetKdDeriveKey , make_vetkd_key( "some_key" ) ) ,
745
799
] ;
746
800
for ( method, key_id) in test_cases {
747
801
let fee = 1_000_000 ;
@@ -778,6 +832,7 @@ fn test_sign_with_threshold_key_fee_ignored_for_nns() {
778
832
let contexts = match method {
779
833
Method :: SignWithECDSA => env. sign_with_ecdsa_contexts ( ) ,
780
834
Method :: SignWithSchnorr => env. sign_with_schnorr_contexts ( ) ,
835
+ Method :: VetKdDeriveKey => env. vetkd_derive_key_contexts ( ) ,
781
836
_ => panic ! ( "Unexpected method" ) ,
782
837
} ;
783
838
let ( _, context) = contexts. iter ( ) . next ( ) . unwrap ( ) ;
@@ -791,6 +846,7 @@ fn test_sign_with_threshold_key_queue_fills_up() {
791
846
( Method :: SignWithECDSA , make_ecdsa_key( "some_key" ) , 20 ) ,
792
847
( Method :: SignWithSchnorr , make_ed25519_key( "some_key" ) , 20 ) ,
793
848
( Method :: SignWithSchnorr , make_bip340_key( "some_key" ) , 20 ) ,
849
+ ( Method :: VetKdDeriveKey , make_vetkd_key( "some_key" ) , 20 ) ,
794
850
] ;
795
851
for ( method, key_id, max_queue_size) in test_cases {
796
852
let fee = 1_000_000 ;
@@ -804,11 +860,14 @@ fn test_sign_with_threshold_key_queue_fills_up() {
804
860
. with_nns_subnet_id ( nns_subnet)
805
861
. with_ecdsa_signature_fee ( fee)
806
862
. with_schnorr_signature_fee ( fee)
863
+ . with_vetkd_derive_key_fee ( fee)
807
864
. with_chain_key ( key_id. clone ( ) )
808
865
// Turn off automatic ECDSA signatures to fill up the queue.
809
866
. with_ecdsa_signing_enabled ( false )
810
867
// Turn off automatic Schnorr signatures to fill up the queue.
811
868
. with_schnorr_signing_enabled ( false )
869
+ // Turn off automatic VetKey derivation to fill up the queue.
870
+ . with_vetkd_enabled ( false )
812
871
. build ( ) ;
813
872
814
873
let canister_id = create_universal_canister ( & env) ;
0 commit comments