File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed
Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -57,4 +57,15 @@ describe("test ValidatorPEMs", () => {
5757 ) ;
5858 assert . equal ( entry . secretKey . hex ( ) , "3034b1d58628a842984da0c70da0b5a251ebb2aebf51afc5b586e2839b5e5263" ) ;
5959 } ) ;
60+
61+ it ( "should convert to text" , async function ( ) {
62+ let text = fs . readFileSync ( path . join ( walletsPath , "validatorKey00.pem" ) , "utf-8" ) . trim ( ) ;
63+ const entry = await ValidatorPEM . fromTextAll ( text ) ;
64+ assert . deepEqual ( entry [ 0 ] . toText ( ) , text ) ;
65+
66+ text = fs . readFileSync ( path . join ( walletsPath , "multipleValidatorKeys.pem" ) , "utf-8" ) . trim ( ) ;
67+ const entries = await ValidatorPEM . fromTextAll ( text ) ;
68+ const actualText = entries . map ( ( entry ) => entry . toText ( ) ) . join ( "\n" ) ;
69+ assert . deepEqual ( actualText , text ) ;
70+ } ) ;
6071} ) ;
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import { PemEntry } from "../wallet/pemEntry";
44import { BLS , ValidatorSecretKey } from "../wallet/validatorKeys" ;
55
66export class ValidatorPEM {
7- label : string ;
8- secretKey : ValidatorSecretKey ;
7+ readonly label : string ;
8+ readonly secretKey : ValidatorSecretKey ;
99
1010 constructor ( label : string , secretKey : ValidatorSecretKey ) {
1111 this . label = label ;
@@ -30,8 +30,8 @@ export class ValidatorPEM {
3030 const entries = PemEntry . fromTextAll ( text ) ;
3131 const resultItems : ValidatorPEM [ ] = [ ] ;
3232
33+ await BLS . initIfNecessary ( ) ;
3334 for ( const entry of entries ) {
34- await BLS . initIfNecessary ( ) ;
3535 const secretKey = new ValidatorSecretKey ( entry . message ) ;
3636 const item = new ValidatorPEM ( entry . label , secretKey ) ;
3737 resultItems . push ( item ) ;
Original file line number Diff line number Diff line change @@ -6,15 +6,19 @@ import { ValidatorPEM } from "./validatorPem";
66 * Validator signer (BLS signer)
77 */
88export class ValidatorSigner {
9- private secretKey : ValidatorSecretKey ;
9+ private readonly secretKey : ValidatorSecretKey ;
1010
1111 constructor ( secretKey : ValidatorSecretKey ) {
1212 this . secretKey = secretKey ;
1313 }
1414 /**
1515 * Signs a message.
1616 */
17- async signUsingPem ( pemText : string , pemIndex : number = 0 , signable : Buffer | Uint8Array ) : Promise < Uint8Array > {
17+ static async signUsingPem (
18+ pemText : string ,
19+ pemIndex : number = 0 ,
20+ signable : Buffer | Uint8Array ,
21+ ) : Promise < Uint8Array > {
1822 await BLS . initIfNecessary ( ) ;
1923
2024 try {
You can’t perform that action at this time.
0 commit comments