mirror of
https://github.com/embarklabs/ethereumjs-wallet.git
synced 2025-02-26 17:10:34 +00:00
Introduce .generate() for creating new wallets
This commit is contained in:
parent
fed7bcde9a
commit
4cf1f60e7f
@ -21,6 +21,7 @@ Features not supported:
|
||||
|
||||
Constructors:
|
||||
|
||||
* `generate([icap])` - create an instance based on a new random key (setting `icap` to true will generate an address suitable for the `ICAP Direct mode`)
|
||||
* `fromPrivateKey(input)` - create an instance based on a raw key
|
||||
* `fromV1(input, password)` - import a wallet (Version 1 of the Ethereum wallet format)
|
||||
* `fromV3(input, password)` - import a wallet (Version 3 of the Ethereum wallet format)
|
||||
|
13
index.js
13
index.js
@ -17,6 +17,19 @@ var Wallet = function (priv) {
|
||||
this.privKey = priv
|
||||
}
|
||||
|
||||
Wallet.generate = function (icapDirect) {
|
||||
if (icapDirect) {
|
||||
while (true) {
|
||||
var privKey = crypto.randomBytes(32)
|
||||
if (ethUtil.privateToAddress(privKey)[0] === 0) {
|
||||
return new Wallet(privKey)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return new Wallet(crypto.randomBytes(32))
|
||||
}
|
||||
}
|
||||
|
||||
Wallet.prototype.getPrivateKey = function () {
|
||||
return this.privKey
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user