Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 4cf1f60

Browse files
committed
Introduce .generate() for creating new wallets
1 parent fed7bcd commit 4cf1f60

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Features not supported:
2121

2222
Constructors:
2323

24+
* `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`)
2425
* `fromPrivateKey(input)` - create an instance based on a raw key
2526
* `fromV1(input, password)` - import a wallet (Version 1 of the Ethereum wallet format)
2627
* `fromV3(input, password)` - import a wallet (Version 3 of the Ethereum wallet format)

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ var Wallet = function (priv) {
1717
this.privKey = priv
1818
}
1919

20+
Wallet.generate = function (icapDirect) {
21+
if (icapDirect) {
22+
while (true) {
23+
var privKey = crypto.randomBytes(32)
24+
if (ethUtil.privateToAddress(privKey)[0] === 0) {
25+
return new Wallet(privKey)
26+
}
27+
}
28+
} else {
29+
return new Wallet(crypto.randomBytes(32))
30+
}
31+
}
32+
2033
Wallet.prototype.getPrivateKey = function () {
2134
return this.privKey
2235
}

0 commit comments

Comments
 (0)