This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
Removing native js dependency #257
Merged
holgerd77
merged 8 commits into
ethereumjs:master
from
Tenderly:removing-native-js-dependency
Jul 6, 2020
+66
−23
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da4827c
Remove keccak native dependency.
nebojsa94 6a6af8e
Remove secp256k1 native dependency.
nebojsa94 28d1354
Adds missing keccak tests.
nebojsa94 1d72012
Adds missing keccak test.
nebojsa94 eda4d21
Use secp256k1 lib instead of shims.
nebojsa94 ef5a7ac
Remove unused import.
nebojsa94 021add9
Merge pull request #1 from ethereumjs/master
nebojsa94 ae77d7a
Merge branch 'master' into removing-native-js-dependencies
nebojsa94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const createKeccakHash = require('keccak') | ||
const { keccak224, keccak384, keccak256: k256, keccak512 } = require('ethereum-cryptography/keccak') | ||
const createHash = require('create-hash') | ||
const ethjsUtil = require('ethjs-util') | ||
import * as rlp from 'rlp' | ||
|
@@ -12,9 +12,23 @@ import { assertIsString, assertIsBuffer, assertIsArray, assertIsHexString } from | |
*/ | ||
export const keccak = function(a: Buffer, bits: number = 256): Buffer { | ||
assertIsBuffer(a) | ||
return createKeccakHash(`keccak${bits}`) | ||
.update(a) | ||
.digest() | ||
switch (bits) { | ||
case 224: { | ||
return keccak224(a) | ||
} | ||
case 256: { | ||
return k256(a) | ||
} | ||
case 384: { | ||
return keccak384(a) | ||
} | ||
case 512: { | ||
return keccak512(a) | ||
} | ||
default: { | ||
throw new Error(`Invald algorithm: keccak${bits}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as secp256k1 from 'secp256k1' | ||
const { sign, publicKeyConvert } = require('ethereum-cryptography/shims/hdkey-secp256k1v3') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const { ecdsaRecover } = require('ethereum-cryptography/secp256k1') | ||
import * as BN from 'bn.js' | ||
import { toBuffer, setLengthLeft, bufferToHex } from './bytes' | ||
import { keccak } from './hash' | ||
|
@@ -18,8 +19,8 @@ export const ecsign = function( | |
privateKey: Buffer, | ||
chainId?: number, | ||
): ECDSASignature { | ||
const sig = secp256k1.ecdsaSign(msgHash, privateKey) | ||
const recovery: number = sig.recid | ||
const sig = sign(msgHash, privateKey) | ||
const recovery: number = sig.recovery | ||
|
||
const ret = { | ||
r: toBuffer(sig.signature.slice(0, 32)), | ||
|
@@ -46,8 +47,8 @@ export const ecrecover = function( | |
if (!isValidSigRecovery(recovery)) { | ||
throw new Error('Invalid signature v value') | ||
} | ||
const senderPubKey = secp256k1.ecdsaRecover(signature, recovery, msgHash) | ||
return toBuffer(secp256k1.publicKeyConvert(senderPubKey, false).slice(1)) | ||
const senderPubKey = ecdsaRecover(signature, recovery, msgHash) | ||
return toBuffer(publicKeyConvert(senderPubKey, false).slice(1)) | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See: https://github.com/ethereumjs/ethereumjs-util/pull/259/files#r441088580