chore: migrate to typescript
This commit is contained in:
committed by
Justin Starry
parent
3eb9f7b3eb
commit
f912c63b22
43
web3.js/src/account.ts
Normal file
43
web3.js/src/account.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import * as nacl from 'tweetnacl';
|
||||
import type {SignKeyPair as KeyPair} from 'tweetnacl';
|
||||
|
||||
import {toBuffer} from './util/to-buffer';
|
||||
import {PublicKey} from './publickey';
|
||||
|
||||
/**
|
||||
* An account key pair (public and secret keys).
|
||||
*/
|
||||
export class Account {
|
||||
/** @internal */
|
||||
_keypair: KeyPair;
|
||||
|
||||
/**
|
||||
* Create a new Account object
|
||||
*
|
||||
* If the secretKey parameter is not provided a new key pair is randomly
|
||||
* created for the account
|
||||
*
|
||||
* @param secretKey Secret key for the account
|
||||
*/
|
||||
constructor(secretKey?: Buffer | Uint8Array | Array<number>) {
|
||||
if (secretKey) {
|
||||
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
||||
} else {
|
||||
this._keypair = nacl.sign.keyPair();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The public key for this account
|
||||
*/
|
||||
get publicKey(): PublicKey {
|
||||
return new PublicKey(this._keypair.publicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* The **unencrypted** secret key for this account
|
||||
*/
|
||||
get secretKey(): Buffer {
|
||||
return toBuffer(this._keypair.secretKey);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user