Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.

Commit d85a78f

Browse files
authored
Merge pull request #146 from ethereumjs/create2
add generateAddress2 for CREATE2
2 parents 5c3b651 + 90d20a0 commit d85a78f

File tree

6 files changed

+310
-213
lines changed

6 files changed

+310
-213
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: node_js
22
node_js:
3-
- "4"
43
- "6"
54
- "8"
5+
- "10"
66
env:
77
- CXX=g++-4.8
88
addons:

docs/index.md

Lines changed: 63 additions & 48 deletions
Large diffs are not rendered by default.

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,31 @@ exports.generateAddress = function (from, nonce) {
534534
return exports.rlphash([from, nonce]).slice(-20)
535535
}
536536

537+
/**
538+
* Generates an address for a contract created using CREATE2
539+
* @param {Buffer} from the address which is creating this new address
540+
* @param {Buffer} salt a salt
541+
* @param {Buffer} initCode the init code of the contract being created
542+
* @return {Buffer}
543+
*/
544+
exports.generateAddress2 = function (from, salt, initCode) {
545+
from = exports.toBuffer(from)
546+
salt = exports.toBuffer(salt)
547+
initCode = exports.toBuffer(initCode)
548+
549+
assert(from.length === 20)
550+
assert(salt.length === 32)
551+
552+
let address = exports.keccak256(Buffer.concat([
553+
Buffer.from('ff', 'hex'),
554+
from,
555+
salt,
556+
exports.keccak256(initCode)
557+
]))
558+
559+
return address.slice(-20)
560+
}
561+
537562
/**
538563
* Returns true if the supplied address belongs to a precompiled account (Byzantium)
539564
* @param {Buffer|String} address

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"coverage": "npm run build:dist && istanbul cover _mocha",
1111
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
1212
"lint": "standard",
13-
"prepublishOnly": "npm run lint && npm run build:dist && npm run test",
14-
"test": "npm run test:node && npm run test:browser",
13+
"prepublishOnly": "npm run test && npm run build:dist",
14+
"test": "npm run lint && npm run test:node && npm run test:browser",
1515
"test:browser": "npm run build:dist && karma start karma.conf.js",
1616
"test:node": "npm run build:dist && istanbul test mocha -- --reporter spec",
1717
"build:dist": "babel index.js --source-root ./ -d ./dist",
@@ -128,7 +128,7 @@
128128
"karma-firefox-launcher": "^1.0.0",
129129
"karma-mocha": "^1.3.0",
130130
"mocha": "^4.0.0",
131-
"standard": "*"
131+
"standard": "^10.0.0"
132132
},
133133
"standard": {
134134
"globals": [

0 commit comments

Comments
 (0)