Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

[No-Ticket] rename getter related methods and private key with secret key #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions packages/sdk/src/lib/CasperClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CasperClient {
* Generate new key pair.
* @param algo Currently we support Ed25519 and Secp256K1.
*/
public newKeyPair(algo: SignatureAlgorithm): AsymmetricKey {
public getKeyPair(algo: SignatureAlgorithm): AsymmetricKey {
switch (algo) {
case SignatureAlgorithm.Ed25519:
return Keys.Ed25519.new();
Expand All @@ -43,58 +43,58 @@ export class CasperClient {
}

/**
* Load private key from file
* Load public key from file
*
* @param path the path to the publicKey file
* @param algo the signature algorithm of the file
*/
public loadPublicKeyFromFile(
public getPublicKeyFromPEMFile(
path: string,
algo: SignatureAlgorithm
): ByteArray {
switch (algo) {
case SignatureAlgorithm.Ed25519:
return Keys.Ed25519.parsePublicKeyFile(path);
return Keys.Ed25519.getPublicKeyFromPEMFile(path);
case SignatureAlgorithm.Secp256K1:
return Keys.Secp256K1.parsePublicKeyFile(path);
return Keys.Secp256K1.getPublicKeyFromPEMFile(path);
default:
throw new Error('Invalid signature algorithm');
}
}

/**
* Load private key
* @param path the path to the private key file
* Load secret key
* @param path the path to the secret key file
*/
public loadPrivateKeyFromFile(
public getSecretKeyFromPEMFile(
path: string,
algo: SignatureAlgorithm
): ByteArray {
switch (algo) {
case SignatureAlgorithm.Ed25519:
return Keys.Ed25519.parsePrivateKeyFile(path);
return Keys.Ed25519.getSecretKeyFromPEMFile(path);
case SignatureAlgorithm.Secp256K1:
return Keys.Secp256K1.parsePrivateKeyFile(path);
return Keys.Secp256K1.getSecretKeyFromPEMFile(path);
default:
throw new Error('Invalid signature algorithm');
}
}

/**
* Load private key file to restore keyPair
* Load secret key file to restore keyPair
*
* @param path The path to the private key
* @param path The path to the secret key
* @param algo
*/
public loadKeyPairFromPrivateFile(
public getKeyPairFromSecretPEMFile(
path: string,
algo: SignatureAlgorithm
): AsymmetricKey {
switch (algo) {
case SignatureAlgorithm.Ed25519:
return Keys.Ed25519.loadKeyPairFromPrivateFile(path);
return Keys.Ed25519.getKeyPairFromSecretPEMFile(path);
case SignatureAlgorithm.Secp256K1:
return Keys.Secp256K1.loadKeyPairFromPrivateFile(path);
return Keys.Secp256K1.getKeyPairFromSecretPEMFile(path);
default:
throw new Error('Invalid signature algorithm');
}
Expand All @@ -105,23 +105,23 @@ export class CasperClient {
*
* @param seed The seed buffer for parent key
*/
public newHdWallet(seed: ByteArray): CasperHDKey {
public getWalletFromSeed(seed: ByteArray): CasperHDKey {
return CasperHDKey.fromMasterSeed(seed);
}

/**
* Compute public key from private Key.
* @param privateKey
* Compute public key from secret Key.
* @param secretKey
*/
public privateToPublicKey(
privateKey: ByteArray,
public getPublicKeyFromSecretKey(
secretKey: ByteArray,
algo: SignatureAlgorithm
): ByteArray {
switch (algo) {
case SignatureAlgorithm.Ed25519:
return Keys.Ed25519.privateToPublicKey(privateKey);
return Keys.Ed25519.getPublicKeyFromSecretKey(secretKey);
case SignatureAlgorithm.Secp256K1:
return Keys.Secp256K1.privateToPublicKey(privateKey);
return Keys.Secp256K1.getPublicKeyFromSecretKey(secretKey);
default:
throw new Error('Invalid signature algorithm');
}
Expand Down Expand Up @@ -163,8 +163,8 @@ export class CasperClient {
* convert the deploy object to json
* @param deploy
*/
public deployToJson(deploy: Deploy) {
return DeployUtil.deployToJson(deploy);
public getDeployAsJSON(deploy: Deploy) {
return DeployUtil.getDeployAsJSON(deploy);
}

/**
Expand All @@ -185,14 +185,18 @@ export class CasperClient {
/**
* Get the balance of public key
*/
public async balanceOfByPublicKey(publicKey: PublicKey): Promise<number> {
return this.balanceOfByAccountHash(encodeBase16(publicKey.toAccountHash()));
public async getBalanceOfByPublicKey(publicKey: PublicKey): Promise<number> {
return this.getBalanceOfByAccountHash(
encodeBase16(publicKey.toAccountHash())
);
}

/**
* Get the balance by account hash
*/
public async balanceOfByAccountHash(accountHashStr: string): Promise<number> {
public async getBalanceOfByAccountHash(
accountHashStr: string
): Promise<number> {
try {
const stateRootHash = await this.nodeClient
.getLatestBlockInfo()
Expand Down Expand Up @@ -225,7 +229,7 @@ export class CasperClient {
* @param page
* @param limit
*/
public async getAccountsDeploys(
public async getAccountDeploys(
publicKey: PublicKey,
page: number = 0,
limit: number = 20
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/lib/CasperHDKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class CasperHDKey {
return this.hdKey.publicKey;
}

public privateKey() {
public secretKey() {
return this.hdKey.privateKey;
}

public privateExtendedKey() {
public secretExtendedKey() {
return this.hdKey.privateExtendedKey;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/lib/DeployUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ export const signDeploy = (
): Deploy => {
const approval = new Approval();
const signature = signingKey.sign(deploy.hash);
approval.signer = signingKey.accountHex();
approval.signature = Keys.Ed25519.accountHex(signature);
approval.signer = signingKey.getAccountHex();
approval.signature = Keys.Ed25519.getAccountHex(signature);
deploy.approvals.push(approval);

return deploy;
Expand Down Expand Up @@ -524,7 +524,7 @@ export const standardPayment = (paymentAmount: bigint | JSBI) => {
*
* @param deploy
*/
export const deployToJson = (deploy: Deploy) => {
export const getDeployAsJSON = (deploy: Deploy) => {
const header = deploy.header;
const headerJson = {
account: header.account.toAccountHex(),
Expand Down
Loading