11'use strict'
2+ var Buffer = require ( 'safe-buffer' ) . Buffer
23var createHash = require ( 'create-hash' )
34var BN = require ( 'bn.js' )
45var EC = require ( 'elliptic' ) . ec
@@ -68,7 +69,7 @@ exports.privateKeyExport = function (privateKey, compressed) {
6869 var d = new BN ( privateKey )
6970 if ( d . cmp ( ecparams . n ) >= 0 || d . isZero ( ) ) throw new Error ( messages . EC_PRIVATE_KEY_EXPORT_DER_FAIL )
7071
71- return new Buffer ( ec . keyFromPrivate ( privateKey ) . getPublic ( compressed , true ) )
72+ return Buffer . from ( ec . keyFromPrivate ( privateKey ) . getPublic ( compressed , true ) )
7273}
7374
7475exports . privateKeyTweakAdd = function ( privateKey , tweak ) {
@@ -96,14 +97,14 @@ exports.publicKeyCreate = function (privateKey, compressed) {
9697 var d = new BN ( privateKey )
9798 if ( d . cmp ( ecparams . n ) >= 0 || d . isZero ( ) ) throw new Error ( messages . EC_PUBLIC_KEY_CREATE_FAIL )
9899
99- return new Buffer ( ec . keyFromPrivate ( privateKey ) . getPublic ( compressed , true ) )
100+ return Buffer . from ( ec . keyFromPrivate ( privateKey ) . getPublic ( compressed , true ) )
100101}
101102
102103exports . publicKeyConvert = function ( publicKey , compressed ) {
103104 var pair = loadPublicKey ( publicKey )
104105 if ( pair === null ) throw new Error ( messages . EC_PUBLIC_KEY_PARSE_FAIL )
105106
106- return new Buffer ( pair . getPublic ( compressed , true ) )
107+ return Buffer . from ( pair . getPublic ( compressed , true ) )
107108}
108109
109110exports . publicKeyVerify = function ( publicKey ) {
@@ -117,7 +118,7 @@ exports.publicKeyTweakAdd = function (publicKey, tweak, compressed) {
117118 tweak = new BN ( tweak )
118119 if ( tweak . cmp ( ecparams . n ) >= 0 ) throw new Error ( messages . EC_PUBLIC_KEY_TWEAK_ADD_FAIL )
119120
120- return new Buffer ( ecparams . g . mul ( tweak ) . add ( pair . pub ) . encode ( true , compressed ) )
121+ return Buffer . from ( ecparams . g . mul ( tweak ) . add ( pair . pub ) . encode ( true , compressed ) )
121122}
122123
123124exports . publicKeyTweakMul = function ( publicKey , tweak , compressed ) {
@@ -127,7 +128,7 @@ exports.publicKeyTweakMul = function (publicKey, tweak, compressed) {
127128 tweak = new BN ( tweak )
128129 if ( tweak . cmp ( ecparams . n ) >= 0 || tweak . isZero ( ) ) throw new Error ( messages . EC_PUBLIC_KEY_TWEAK_MUL_FAIL )
129130
130- return new Buffer ( pair . pub . mul ( tweak ) . encode ( true , compressed ) )
131+ return Buffer . from ( pair . pub . mul ( tweak ) . encode ( true , compressed ) )
131132}
132133
133134exports . publicKeyCombine = function ( publicKeys , compressed ) {
@@ -141,15 +142,15 @@ exports.publicKeyCombine = function (publicKeys, compressed) {
141142 for ( var j = 1 ; j < pairs . length ; ++ j ) point = point . add ( pairs [ j ] . pub )
142143 if ( point . isInfinity ( ) ) throw new Error ( messages . EC_PUBLIC_KEY_COMBINE_FAIL )
143144
144- return new Buffer ( point . encode ( true , compressed ) )
145+ return Buffer . from ( point . encode ( true , compressed ) )
145146}
146147
147148exports . signatureNormalize = function ( signature ) {
148149 var r = new BN ( signature . slice ( 0 , 32 ) )
149150 var s = new BN ( signature . slice ( 32 , 64 ) )
150151 if ( r . cmp ( ecparams . n ) >= 0 || s . cmp ( ecparams . n ) >= 0 ) throw new Error ( messages . ECDSA_SIGNATURE_PARSE_FAIL )
151152
152- var result = new Buffer ( signature )
153+ var result = Buffer . from ( signature )
153154 if ( s . cmp ( ec . nh ) === 1 ) ecparams . n . sub ( s ) . toArrayLike ( Buffer , 'be' , 32 ) . copy ( result , 32 )
154155
155156 return result
@@ -225,7 +226,7 @@ exports.recover = function (message, signature, recovery, compressed) {
225226 if ( sigr . isZero ( ) || sigs . isZero ( ) ) throw new Error ( )
226227
227228 var point = ec . recoverPubKey ( message , sigObj , recovery )
228- return new Buffer ( point . encode ( true , compressed ) )
229+ return Buffer . from ( point . encode ( true , compressed ) )
229230 } catch ( err ) {
230231 throw new Error ( messages . ECDSA_RECOVER_FAIL )
231232 }
@@ -243,5 +244,5 @@ exports.ecdhUnsafe = function (publicKey, privateKey, compressed) {
243244 var scalar = new BN ( privateKey )
244245 if ( scalar . cmp ( ecparams . n ) >= 0 || scalar . isZero ( ) ) throw new Error ( messages . ECDH_FAIL )
245246
246- return new Buffer ( pair . pub . mul ( scalar ) . encode ( true , compressed ) )
247+ return Buffer . from ( pair . pub . mul ( scalar ) . encode ( true , compressed ) )
247248}
0 commit comments