@@ -34,6 +34,7 @@ use snarkvm::{
3434
3535use aleo_std:: StorageMode ;
3636use anyhow:: { Result , bail, ensure} ;
37+ use base64:: prelude:: * ;
3738use clap:: Parser ;
3839use colored:: Colorize ;
3940use core:: str:: FromStr ;
@@ -169,6 +170,14 @@ pub struct Start {
169170 /// If development mode is enabled, specify the custom bonded balances as a JSON object (default: None)
170171 #[ clap( long) ]
171172 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 > ,
172181}
173182
174183impl Start {
@@ -569,11 +578,24 @@ impl Start {
569578 ) ;
570579
571580 // 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 ( ) {
573582 if let Some ( rest_ip) = rest_ip {
574583 println ! ( "🌐 Starting the REST server at {}.\n " , rest_ip. to_string( ) . bold( ) ) ;
575584
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 ( ) {
577599 println ! ( "🔑 Your one-time JWT token is {}\n " , jwt_token. dimmed( ) ) ;
578600 }
579601 }
0 commit comments