@@ -34,6 +34,7 @@ use snarkvm::{
34
34
35
35
use aleo_std:: StorageMode ;
36
36
use anyhow:: { Result , bail, ensure} ;
37
+ use base64:: prelude:: * ;
37
38
use clap:: Parser ;
38
39
use colored:: Colorize ;
39
40
use core:: str:: FromStr ;
@@ -169,6 +170,14 @@ pub struct Start {
169
170
/// If development mode is enabled, specify the custom bonded balances as a JSON object (default: None)
170
171
#[ clap( long) ]
171
172
pub dev_bonded_balances : Option < BondedBalances > ,
173
+ /// Pass in an optional jwt secret for the node instance (16 bytes, base64 encoded) for keeping
174
+ /// the JWT constant
175
+ #[ clap( long) ]
176
+ pub jwt_secret : Option < String > ,
177
+ /// Pass in an optional jwt creation timestamp for keeping the JWT constant. Can be any time in
178
+ /// the last 10 years
179
+ #[ clap( long) ]
180
+ pub jwt_timestamp : Option < i64 > ,
172
181
}
173
182
174
183
impl Start {
@@ -569,11 +578,24 @@ impl Start {
569
578
) ;
570
579
571
580
// If the node is running a REST server, print the REST IP and JWT.
572
- if node_type. is_validator ( ) {
581
+ if node_type. is_validator ( ) || node_type . is_client ( ) {
573
582
if let Some ( rest_ip) = rest_ip {
574
583
println ! ( "🌐 Starting the REST server at {}.\n " , rest_ip. to_string( ) . bold( ) ) ;
575
584
576
- if let Ok ( jwt_token) = snarkos_node_rest:: Claims :: new ( account. address ( ) ) . to_jwt_string ( ) {
585
+ let jwt_secret = if let Some ( jwt_b64) = & self . jwt_secret {
586
+ if self . jwt_timestamp . is_none ( ) {
587
+ bail ! ( "The '--jwt-timestamp' flag must be set if the '--jwt-secret' flag is set" ) ;
588
+ }
589
+ let jwt_bytes = BASE64_STANDARD . decode ( jwt_b64) . map_err ( |_| anyhow:: anyhow!( "Invalid JWT secret" ) ) ?;
590
+ if jwt_bytes. len ( ) != 16 {
591
+ bail ! ( "The JWT secret must be 16 bytes long" ) ;
592
+ }
593
+ Some ( jwt_bytes)
594
+ } else {
595
+ None
596
+ } ;
597
+
598
+ if let Ok ( jwt_token) = snarkos_node_rest:: Claims :: new ( account. address ( ) , jwt_secret, self . jwt_timestamp ) . to_jwt_string ( ) {
577
599
println ! ( "🔑 Your one-time JWT token is {}\n " , jwt_token. dimmed( ) ) ;
578
600
}
579
601
}
0 commit comments