Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5010 from trufflesuite/bump-ethereum-cryptography
Browse files Browse the repository at this point in the history
Dependency update: Bump ethereum-cryptography to 1.0.3
  • Loading branch information
eggplantzzz authored Apr 12, 2022
2 parents b551309 + ea62e1f commit b95d810
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 17 deletions.
15 changes: 10 additions & 5 deletions packages/core/lib/mnemonics/mnemonic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

const Config = require("@truffle/config");
const defaultUserConfig = Config.getUserConfig();
const bip39 = require("ethereum-cryptography/bip39");
const {
entropyToMnemonic,
mnemonicToSeedSync
} = require("ethereum-cryptography/bip39");
const { wordlist } = require("ethereum-cryptography/bip39/wordlists/english");
const { hdkey } = require("ethereumjs-wallet");
const crypto = require("crypto");
Expand All @@ -19,11 +22,11 @@ const mnemonic = {
* gets user-level mnemonic from user config, and if missing generates a new mnemonic
* @returns {String} mnemonic
*/
getOrGenerateMnemonic: function() {
getOrGenerateMnemonic: function () {
let mnemonic;
const userMnemonicExists = defaultUserConfig.get("mnemonic");
if (!userMnemonicExists) {
mnemonic = bip39.entropyToMnemonic(crypto.randomBytes(16), wordlist);
mnemonic = entropyToMnemonic(crypto.randomBytes(16), wordlist);
defaultUserConfig.set({ mnemonic: mnemonic });
} else {
mnemonic = userMnemonicExists;
Expand All @@ -37,12 +40,14 @@ const mnemonic = {
* @param {String}
* @returns {Object} mnemonicObject
*/
getAccountsInfo: function(numAddresses) {
getAccountsInfo: function (numAddresses) {
let mnemonic = this.getOrGenerateMnemonic();
let accounts = [];
let privateKeys = [];

let hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeedSync(mnemonic));
let hdwallet = hdkey.fromMasterSeed(
Buffer.from(mnemonicToSeedSync(mnemonic))
);
let addressIndex = 0;
let walletHdpath = "m/44'/60'/0'/0/";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"conf": "^10.0.2",
"debug": "^4.3.1",
"del": "^2.2.0",
"ethereum-cryptography": "^0.1.3",
"ethereum-cryptography": "1.0.3",
"ethereumjs-wallet": "^1.0.1",
"ethpm": "0.0.19",
"ethpm-registry": "0.1.0-next.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/hdwallet-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@ethereumjs/common": "^2.4.0",
"@ethereumjs/tx": "^3.3.0",
"eth-sig-util": "^3.0.1",
"ethereum-cryptography": "^0.1.3",
"ethereum-cryptography": "1.0.3",
"ethereum-protocol": "^1.0.1",
"ethereumjs-util": "^6.1.0",
"ethereumjs-wallet": "^1.0.1",
Expand Down
17 changes: 10 additions & 7 deletions packages/hdwallet-provider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as bip39 from "ethereum-cryptography/bip39";
import {
mnemonicToSeedSync,
validateMnemonic
} from "ethereum-cryptography/bip39";
import { wordlist } from "ethereum-cryptography/bip39/wordlists/english";
import * as EthUtil from "ethereumjs-util";
import ethJSWallet from "ethereumjs-wallet";
Expand Down Expand Up @@ -95,7 +98,7 @@ class HDWalletProvider {
[
`No provider or an invalid provider was specified: '${providerToUse}'`,
"Please specify a valid provider or URL, using the http, https, " +
"ws, or wss protocol.",
"ws, or wss protocol.",
""
].join("\n")
);
Expand Down Expand Up @@ -303,14 +306,14 @@ class HDWalletProvider {
phrase: string;
password?: string;
}) {
this.hdwallet = EthereumHDKey.fromMasterSeed(
bip39.mnemonicToSeedSync(phrase, password)
);

if (!bip39.validateMnemonic(phrase, wordlist)) {
if (!validateMnemonic(phrase, wordlist)) {
throw new Error("Mnemonic invalid or undefined");
}

this.hdwallet = EthereumHDKey.fromMasterSeed(
Buffer.from(mnemonicToSeedSync(phrase, password))
);

// crank the addresses out
for (let i = addressIndex; i < addressIndex + numberOfAddresses; i++) {
const wallet = this.hdwallet
Expand Down
8 changes: 5 additions & 3 deletions packages/hdwallet-provider/test/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("HD Wallet Provider", function () {
let server: any;
let provider: HDWalletProvider;

before(done => {
before(async () => {
server = Ganache.server({
miner: {
instamine: "strict"
Expand All @@ -20,7 +20,7 @@ describe("HD Wallet Provider", function () {
quiet: true
}
});
server.listen(port, done);
await server.listen(port);
});

after(async () => {
Expand All @@ -29,7 +29,9 @@ describe("HD Wallet Provider", function () {

afterEach(() => {
web3.setProvider(new Web3.providers.HttpProvider("ws://localhost:8545"));
provider.engine.stop();
if (provider) {
provider.engine.stop();
}
});

describe("instantiating with positional arguments", () => {
Expand Down
42 changes: 42 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4721,6 +4721,16 @@
resolved "https://registry.yarnpkg.com/@multiformats/base-x/-/base-x-4.0.1.tgz#95ff0fa58711789d53aefb2590a8b7a4e715d121"
integrity sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw==

"@noble/hashes@1.0.0", "@noble/hashes@~1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.0.0.tgz#d5e38bfbdaba174805a4e649f13be9a9ed3351ae"
integrity sha512-DZVbtY62kc3kkBtMHqwCOfXrT/hnoORy5BJ4+HU1IR59X0KWAOqsfzQPcUl/lQLlG7qXbe/fZ3r/emxtAl+sqg==

"@noble/secp256k1@1.5.5", "@noble/secp256k1@~1.5.2":
version "1.5.5"
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.5.5.tgz#315ab5745509d1a8c8e90d0bdf59823ccf9bcfc3"
integrity sha512-sZ1W6gQzYnu45wPrWx8D3kwI2/U29VYTx9OjbDAd7jwRItJ0cSTMPRL/C8AWZFn9kWFLQGqEXVEE86w4Z8LpIQ==

"@nodefactory/filsnap-adapter@^0.2.1":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@nodefactory/filsnap-adapter/-/filsnap-adapter-0.2.2.tgz#0e182150ce3825b6c26b8512ab9355ab7759b498"
Expand Down Expand Up @@ -5085,6 +5095,28 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@scure/base@~1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.0.0.tgz#109fb595021de285f05a7db6806f2f48296fcee7"
integrity sha512-gIVaYhUsy+9s58m/ETjSJVKHhKTBMmcRb9cEV5/5dwvfDlfORjKrFsDeDHWRrm6RjcPvCLZFwGJjAjLj1gg4HA==

"@scure/bip32@1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.0.1.tgz#1409bdf9f07f0aec99006bb0d5827693418d3aa5"
integrity sha512-AU88KKTpQ+YpTLoicZ/qhFhRRIo96/tlb+8YmDDHR9yiKVjSsFZiefJO4wjS2PMTkz5/oIcw84uAq/8pleQURA==
dependencies:
"@noble/hashes" "~1.0.0"
"@noble/secp256k1" "~1.5.2"
"@scure/base" "~1.0.0"

"@scure/bip39@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.0.0.tgz#47504e58de9a56a4bbed95159d2d6829fa491bb0"
integrity sha512-HrtcikLbd58PWOkl02k9V6nXWQyoa7A0+Ek9VF7z17DDk9XZAFUcIdqfh0jJXLypmizc5/8P6OxoUeKliiWv4w==
dependencies:
"@noble/hashes" "~1.0.0"
"@scure/base" "~1.0.0"

"@sindresorhus/is@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
Expand Down Expand Up @@ -14347,6 +14379,16 @@ ethereum-common@^0.0.18:
resolved "https://registry.yarnpkg.com/ethereum-common/-/ethereum-common-0.0.18.tgz#2fdc3576f232903358976eb39da783213ff9523f"
integrity sha1-L9w1dvIykDNYl26znaeDIT/5Uj8=

ethereum-cryptography@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-1.0.3.tgz#b1f8f4e702434b2016248dbb2f9fdd60c54772d8"
integrity sha512-NQLTW0x0CosoVb/n79x/TRHtfvS3hgNUPTUSCu0vM+9k6IIhHFFrAOJReneexjZsoZxMjJHnJn4lrE8EbnSyqQ==
dependencies:
"@noble/hashes" "1.0.0"
"@noble/secp256k1" "1.5.5"
"@scure/bip32" "1.0.1"
"@scure/bip39" "1.0.0"

ethereum-cryptography@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz#8d6143cfc3d74bf79bbd8edecdf29e4ae20dd191"
Expand Down

0 comments on commit b95d810

Please sign in to comment.