diff --git a/README.md b/README.md index 24dd0c4..8d2a087 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/index.js b/index.js index 4a90393..3c92c47 100644 --- a/index.js +++ b/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 }