Introduce .generate() for creating new wallets
This commit is contained in:
parent
fed7bcde9a
commit
4cf1f60e7f
|
@ -21,6 +21,7 @@ Features not supported:
|
||||||
|
|
||||||
Constructors:
|
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
|
* `fromPrivateKey(input)` - create an instance based on a raw key
|
||||||
* `fromV1(input, password)` - import a wallet (Version 1 of the Ethereum wallet format)
|
* `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)
|
* `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
|
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 () {
|
Wallet.prototype.getPrivateKey = function () {
|
||||||
return this.privKey
|
return this.privKey
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue