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

V6 Removing native js dependencies #259

Merged
merged 15 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
"@types/bn.js": "^4.11.3",
"bn.js": "^4.11.0",
"create-hash": "^1.1.2",
"ethereum-cryptography": "^0.1.3",
"elliptic": "^6.5.2",
"ethjs-util": "0.1.6",
"keccak": "^2.0.0",
"rlp": "^2.2.3",
"secp256k1": "^3.0.1"
"rlp": "^2.2.3"
},
"devDependencies": {
"@ethereumjs/config-prettier": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert')
const ethjsUtil = require('ethjs-util')
const secp256k1 = require('secp256k1')
const secp256k1 = require('./secp256k1v3-adapter')
import BN = require('bn.js')
import { toBuffer, addHexPrefix, zeros, bufferToHex, unpad } from './bytes'
import { keccak, keccak256, rlphash } from './hash'
Expand Down
22 changes: 18 additions & 4 deletions src/hash.ts
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 rlp = require('rlp')
Expand All @@ -19,9 +19,23 @@ export const keccak = function(a: any, bits: number = 256): Buffer {

if (!bits) bits = 256

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}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: There aren't versions of keccak other than 224, 256, 384, and 512. This API is confusing, but we have to keep it for backward compatibility reasons.

}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const secp256k1 = require('secp256k1')
const secp256k1 = require('./secp256k1v3-adapter')
const ethjsUtil = require('ethjs-util')
import BN = require('bn.js')
import rlp = require('rlp')
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy