@@ -2,7 +2,8 @@ var aes = require('browserify-aes')
22var assert = require ( 'assert' )
33var Buffer = require ( 'safe-buffer' ) . Buffer
44var bs58check = require ( 'bs58check' )
5- var createHash = require ( 'create-hash' )
5+ var { sha256 } = require ( '@noble/hashes/sha256' )
6+ var { ripemd160 } = require ( '@noble/hashes/ripemd160' )
67var scrypt = require ( 'scryptsy' )
78var xor = require ( 'buffer-xor/inplace' )
89
@@ -20,21 +21,18 @@ var SCRYPT_PARAMS = {
2021var NULL = Buffer . alloc ( 0 )
2122
2223function hash160 ( buffer ) {
23- var hash
24- try {
25- hash = createHash ( 'rmd160' )
26- } catch ( e ) {
27- hash = createHash ( 'ripemd160' )
28- }
29- return hash . update (
30- createHash ( 'sha256' ) . update ( buffer ) . digest ( )
24+ var hash = ripemd160 . create ( )
25+ var uint8Arr = hash . update (
26+ sha256 . create ( ) . update ( buffer ) . digest ( )
3127 ) . digest ( )
28+ return Buffer . from ( uint8Arr )
3229}
3330
3431function hash256 ( buffer ) {
35- return createHash ( ' sha256' ) . update (
36- createHash ( ' sha256' ) . update ( buffer ) . digest ( )
32+ var uint8Arr = sha256 . create ( ) . update (
33+ sha256 . create ( ) . update ( buffer ) . digest ( )
3734 ) . digest ( )
35+ return Buffer . from ( uint8Arr )
3836}
3937
4038function getAddress ( d , compressed ) {
@@ -213,11 +211,11 @@ function decryptRaw (buffer, passphrase, progressCallback, scryptParams) {
213211}
214212
215213async function decryptAsync ( string , passphrase , progressCallback , scryptParams , promiseInterval ) {
216- return decryptRawAsync ( bs58check . decode ( string ) , passphrase , progressCallback , scryptParams , promiseInterval )
214+ return decryptRawAsync ( Buffer . from ( bs58check . decode ( string ) ) , passphrase , progressCallback , scryptParams , promiseInterval )
217215}
218216
219217function decrypt ( string , passphrase , progressCallback , scryptParams ) {
220- return decryptRaw ( bs58check . decode ( string ) , passphrase , progressCallback , scryptParams )
218+ return decryptRaw ( Buffer . from ( bs58check . decode ( string ) ) , passphrase , progressCallback , scryptParams )
221219}
222220
223221function prepareDecryptECMult ( buffer , passphrase , progressCallback , scryptParams ) {
@@ -363,8 +361,10 @@ function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
363361}
364362
365363function verify ( string ) {
366- var decoded = bs58check . decodeUnsafe ( string )
367- if ( ! decoded ) return false
364+ var unsafe = bs58check . decodeUnsafe ( string )
365+ if ( ! unsafe ) return false
366+
367+ var decoded = Buffer . from ( unsafe )
368368
369369 if ( decoded . length !== 39 ) return false
370370 if ( decoded . readUInt8 ( 0 ) !== 0x01 ) return false
0 commit comments