Skip to content

Commit bd9d363

Browse files
author
ivan
committed
change create-hash to @noble/hashes
1 parent 5af12b9 commit bd9d363

File tree

5 files changed

+9280
-80
lines changed

5 files changed

+9280
-80
lines changed

.idea/workspace.xml

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var aes = require('browserify-aes')
22
var assert = require('assert')
33
var Buffer = require('safe-buffer').Buffer
44
var bs58check = require('bs58check')
5-
var createHash = require('create-hash')
5+
var { sha256 } = require('@noble/hashes/sha256')
6+
var { ripemd160 } = require('@noble/hashes/ripemd160')
67
var scrypt = require('scryptsy')
78
var xor = require('buffer-xor/inplace')
89

@@ -20,21 +21,18 @@ var SCRYPT_PARAMS = {
2021
var NULL = Buffer.alloc(0)
2122

2223
function 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

3431
function 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

4038
function getAddress (d, compressed) {
@@ -213,11 +211,11 @@ function decryptRaw (buffer, passphrase, progressCallback, scryptParams) {
213211
}
214212

215213
async 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

219217
function 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

223221
function prepareDecryptECMult (buffer, passphrase, progressCallback, scryptParams) {
@@ -363,8 +361,10 @@ function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
363361
}
364362

365363
function 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

Comments
 (0)