Skip to content

Commit

Permalink
Make the privateKey a private field
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbochok committed Nov 26, 2020
1 parent b87c860 commit 921a348
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions sdk/zksync.js/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ import {
import { Address, EthSignerType, PubKeyHash, Transfer, Withdraw, ForcedExit, ChangePubKey } from './types';

export class Signer {
readonly privateKey: Uint8Array;
#privateKey: Uint8Array;

private constructor(privKey: Uint8Array) {
this.privateKey = privKey;
this.#privateKey = privKey;
}

private privateKey(): Uint8Array {
return this.#privateKey;
}

async pubKeyHash(): Promise<PubKeyHash> {
return await privateKeyToPubKeyHash(this.privateKey);
return await privateKeyToPubKeyHash(this.privateKey());
}

transferSignBytes(transfer: {
Expand Down Expand Up @@ -57,7 +61,7 @@ export class Signer {
nonce: number;
}): Promise<Transfer> {
const msgBytes = this.transferSignBytes(transfer);
const signature = await signTransactionBytes(this.privateKey, msgBytes);
const signature = await signTransactionBytes(this.privateKey(), msgBytes);

return {
type: 'Transfer',
Expand Down Expand Up @@ -113,7 +117,7 @@ export class Signer {
nonce: number;
}): Promise<Withdraw> {
const msgBytes = this.withdrawSignBytes(withdraw);
const signature = await signTransactionBytes(this.privateKey, msgBytes);
const signature = await signTransactionBytes(this.privateKey(), msgBytes);

return {
type: 'Withdraw',
Expand Down Expand Up @@ -161,7 +165,7 @@ export class Signer {
nonce: number;
}): Promise<ForcedExit> {
const msgBytes = this.forcedExitSignBytes(forcedExit);
const signature = await signTransactionBytes(this.privateKey, msgBytes);
const signature = await signTransactionBytes(this.privateKey(), msgBytes);
return {
type: 'ForcedExit',
initiatorAccountId: forcedExit.initiatorAccountId,
Expand Down Expand Up @@ -210,7 +214,7 @@ export class Signer {
nonce: number;
}): Promise<ChangePubKey> {
const msgBytes = this.changePubKeySignBytes(changePubKey);
const signature = await signTransactionBytes(this.privateKey, msgBytes);
const signature = await signTransactionBytes(this.privateKey(), msgBytes);
return {
type: 'ChangePubKey',
accountId: changePubKey.accountId,
Expand Down

0 comments on commit 921a348

Please sign in to comment.