Skip to content

Commit 3a6839b

Browse files
committed
add toText tests and update private fields
1 parent 5b44df2 commit 3a6839b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/wallet/validatorPem.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

src/wallet/validatorPem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { PemEntry } from "../wallet/pemEntry";
44
import { BLS, ValidatorSecretKey } from "../wallet/validatorKeys";
55

66
export 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);

src/wallet/validatorSigner.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ import { ValidatorPEM } from "./validatorPem";
66
* Validator signer (BLS signer)
77
*/
88
export 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 {

0 commit comments

Comments
 (0)