11const ethjsUtil = require ( 'ethjs-util' )
2+ const {
3+ privateKeyVerify,
4+ publicKeyCreate,
5+ publicKeyVerify,
6+ publicKeyConvert,
7+ } = require ( 'ethereum-cryptography/shims/hdkey-secp256k1v3' )
28import * as assert from 'assert'
3- import * as secp256k1 from 'secp256k1'
49import * as BN from 'bn.js'
510import { zeros , bufferToHex , toBuffer } from './bytes'
611import { keccak , keccak256 , keccakFromString , rlphash } from './hash'
@@ -119,7 +124,7 @@ export const generateAddress2 = function(from: Buffer, salt: Buffer, initCode: B
119124 * Checks if the private key satisfies the rules of the curve secp256k1.
120125 */
121126export const isValidPrivate = function ( privateKey : Buffer ) : boolean {
122- return secp256k1 . privateKeyVerify ( privateKey )
127+ return privateKeyVerify ( privateKey )
123128}
124129
125130/**
@@ -132,14 +137,14 @@ export const isValidPublic = function(publicKey: Buffer, sanitize: boolean = fal
132137 assertIsBuffer ( publicKey )
133138 if ( publicKey . length === 64 ) {
134139 // Convert to SEC1 for secp256k1
135- return secp256k1 . publicKeyVerify ( Buffer . concat ( [ Buffer . from ( [ 4 ] ) , publicKey ] ) )
140+ return publicKeyVerify ( Buffer . concat ( [ Buffer . from ( [ 4 ] ) , publicKey ] ) )
136141 }
137142
138143 if ( ! sanitize ) {
139144 return false
140145 }
141146
142- return secp256k1 . publicKeyVerify ( publicKey )
147+ return publicKeyVerify ( publicKey )
143148}
144149
145150/**
@@ -151,7 +156,7 @@ export const isValidPublic = function(publicKey: Buffer, sanitize: boolean = fal
151156export const pubToAddress = function ( pubKey : Buffer , sanitize : boolean = false ) : Buffer {
152157 assertIsBuffer ( pubKey )
153158 if ( sanitize && pubKey . length !== 64 ) {
154- pubKey = toBuffer ( secp256k1 . publicKeyConvert ( pubKey , false ) . slice ( 1 ) )
159+ pubKey = toBuffer ( publicKeyConvert ( pubKey , false ) . slice ( 1 ) )
155160 }
156161 assert ( pubKey . length === 64 )
157162 // Only take the lower 160bits of the hash
@@ -174,7 +179,7 @@ export const privateToAddress = function(privateKey: Buffer): Buffer {
174179export const privateToPublic = function ( privateKey : Buffer ) : Buffer {
175180 assertIsBuffer ( privateKey )
176181 // skip the type flag and use the X, Y points
177- return toBuffer ( secp256k1 . publicKeyCreate ( privateKey , false ) . slice ( 1 ) )
182+ return toBuffer ( publicKeyCreate ( privateKey , false ) . slice ( 1 ) )
178183}
179184
180185/**
@@ -183,7 +188,7 @@ export const privateToPublic = function(privateKey: Buffer): Buffer {
183188export const importPublic = function ( publicKey : Buffer ) : Buffer {
184189 assertIsBuffer ( publicKey )
185190 if ( publicKey . length !== 64 ) {
186- publicKey = toBuffer ( secp256k1 . publicKeyConvert ( publicKey , false ) . slice ( 1 ) )
191+ publicKey = toBuffer ( publicKeyConvert ( publicKey , false ) . slice ( 1 ) )
187192 }
188193 return publicKey
189194}
0 commit comments