solana/web3.js/src/account.js

26 lines
500 B
JavaScript
Raw Normal View History

2018-08-23 10:07:30 -07:00
// @flow
2018-08-22 17:03:50 -07:00
import nacl from 'tweetnacl';
import bs58 from 'bs58';
2018-08-23 10:07:30 -07:00
import type {KeyPair} from 'tweetnacl';
2018-08-22 17:03:50 -07:00
export class Account {
2018-08-23 10:07:30 -07:00
_keypair: KeyPair;
2018-08-22 17:03:50 -07:00
constructor(secretKey: ?Buffer = null) {
if (secretKey) {
this._keypair = nacl.sign.keyPair.fromSecretKey(secretKey);
} else {
this._keypair = nacl.sign.keyPair();
}
}
get publicKey(): string {
return bs58.encode(this._keypair.publicKey);
}
2018-08-23 10:07:30 -07:00
get secretKey(): Buffer {
2018-08-22 17:03:50 -07:00
return this._keypair.secretKey;
}
}