Skip to content

Commit

Permalink
change create-hash to @noble/hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan committed Mar 3, 2023
1 parent 5af12b9 commit bd9d363
Show file tree
Hide file tree
Showing 5 changed files with 9,280 additions and 80 deletions.
93 changes: 93 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var aes = require('browserify-aes')
var assert = require('assert')
var Buffer = require('safe-buffer').Buffer
var bs58check = require('bs58check')
var createHash = require('create-hash')
var { sha256 } = require('@noble/hashes/sha256')
var { ripemd160 } = require('@noble/hashes/ripemd160')
var scrypt = require('scryptsy')
var xor = require('buffer-xor/inplace')

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

function hash160 (buffer) {
var hash
try {
hash = createHash('rmd160')
} catch (e) {
hash = createHash('ripemd160')
}
return hash.update(
createHash('sha256').update(buffer).digest()
var hash = ripemd160.create()
var uint8Arr = hash.update(
sha256.create().update(buffer).digest()
).digest()
return Buffer.from(uint8Arr)
}

function hash256 (buffer) {
return createHash('sha256').update(
createHash('sha256').update(buffer).digest()
var uint8Arr = sha256.create().update(
sha256.create().update(buffer).digest()
).digest()
return Buffer.from(uint8Arr)
}

function getAddress (d, compressed) {
Expand Down Expand Up @@ -213,11 +211,11 @@ function decryptRaw (buffer, passphrase, progressCallback, scryptParams) {
}

async function decryptAsync (string, passphrase, progressCallback, scryptParams, promiseInterval) {
return decryptRawAsync(bs58check.decode(string), passphrase, progressCallback, scryptParams, promiseInterval)
return decryptRawAsync(Buffer.from(bs58check.decode(string)), passphrase, progressCallback, scryptParams, promiseInterval)
}

function decrypt (string, passphrase, progressCallback, scryptParams) {
return decryptRaw(bs58check.decode(string), passphrase, progressCallback, scryptParams)
return decryptRaw(Buffer.from(bs58check.decode(string)), passphrase, progressCallback, scryptParams)
}

function prepareDecryptECMult (buffer, passphrase, progressCallback, scryptParams) {
Expand Down Expand Up @@ -363,8 +361,10 @@ function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
}

function verify (string) {
var decoded = bs58check.decodeUnsafe(string)
if (!decoded) return false
var unsafe = bs58check.decodeUnsafe(string)
if (!unsafe) return false

var decoded = Buffer.from(unsafe)

if (decoded.length !== 39) return false
if (decoded.readUInt8(0) !== 0x01) return false
Expand Down
Loading

0 comments on commit bd9d363

Please sign in to comment.