Skip to content

Commit

Permalink
replace secp256k1 with bcrypto#secp256k1 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored May 4, 2020
1 parent 7d848f3 commit 30ca0e3
Show file tree
Hide file tree
Showing 3 changed files with 6,447 additions and 6,200 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"@types/crypto-js": "^3.1.43",
"@types/jest": "^23.3.2",
"@types/node": "^10.11.0",
"@types/secp256k1": "^3.5.0",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"husky": "^1.0.1",
Expand All @@ -117,10 +116,10 @@
"webpack-cli": "^3.3.2"
},
"dependencies": {
"bcrypto": "^5.1.0",
"bech32": "^1.1.3",
"bip32": "^2.0.4",
"bip39": "^3.0.2",
"crypto-js": "^3.1.9-1",
"secp256k1": "^3.6.2"
"crypto-js": "^3.1.9-1"
}
}
12 changes: 8 additions & 4 deletions src/cosmos-keys.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as bip39 from 'bip39'
import * as bip32 from 'bip32'
import * as bech32 from 'bech32'
import * as secp256k1 from 'secp256k1'
// @ts-ignore - there are no types for bcrypto
import { secp256k1 } from 'bcrypto'
import * as CryptoJS from 'crypto-js'
import { Wallet, StdSignMsg, KeyPair } from './types'

Expand Down Expand Up @@ -30,7 +31,11 @@ export function randomBytes(size: number, window = windowObject): Buffer {
)
}

export function getNewWalletFromSeed(mnemonic: string, bech32Prefix: string, hdPath: string = hdPathAtom): Wallet {
export function getNewWalletFromSeed(
mnemonic: string,
bech32Prefix: string,
hdPath: string = hdPathAtom
): Wallet {
const masterKey = deriveMasterKey(mnemonic)
const { privateKey, publicKey } = deriveKeypair(masterKey, hdPath)
const cosmosAddress = getCosmosAddress(publicKey, bech32Prefix)
Expand Down Expand Up @@ -99,9 +104,8 @@ export function signWithPrivateKey(signMessage: StdSignMsg | string, privateKey:
const signMessageString: string =
typeof signMessage === 'string' ? signMessage : JSON.stringify(signMessage)
const signHash = Buffer.from(CryptoJS.SHA256(signMessageString).toString(), `hex`)
const { signature } = secp256k1.sign(signHash, privateKey)

return signature
return secp256k1.sign(signHash, privateKey)
}

export function verifySignature(
Expand Down
Loading

0 comments on commit 30ca0e3

Please sign in to comment.