Skip to content

Commit

Permalink
Added key validation to make it easier to debug key errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinbrown committed May 22, 2019
1 parent 8fdce04 commit b618d6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/@types/eosjs-ecc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ declare module 'eosjs-ecc' {
export function unsafeRandomKey(): Promise<string>;
export function privateToPublic(privateKey: string): string;
export function sha256(data: string | Buffer): string;
export function isValidPublic(key: string | Buffer, prefix: string): boolean;
export function isValidPrivate(key: string | Buffer): boolean;
}
8 changes: 6 additions & 2 deletions src/accounts/account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Permissions } from './permissions';
import * as ecc from 'eosjs-ecc';
import { Contract } from '../contracts';

import { AccountManager } from './accountManager';
import { Permissions } from './permissions';

export class Account {
/** EOSIO account name */
Expand All @@ -18,6 +18,10 @@ export class Account {
this.name = name;

if (privateKey) {
if (!ecc.isValidPrivate(privateKey)) {
throw new Error('Private key is not valid.');
}

this.privateKey = privateKey;

this.publicKey = ecc.privateToPublic(privateKey);
Expand Down

0 comments on commit b618d6c

Please sign in to comment.