diff --git a/lib/hd/mnemonic.js b/lib/hd/mnemonic.js index 165a223c..b8325093 100644 --- a/lib/hd/mnemonic.js +++ b/lib/hd/mnemonic.js @@ -121,7 +121,7 @@ Mnemonic.prototype.destroy = function destroy() { this.bits = constants.hd.MIN_ENTROPY; this.language = 'english'; if (this.entropy) { - this.entropy.fill(0); + crypto.cleanse(this.entropy); this.entropy = null; } this.phrase = null; diff --git a/lib/hd/private.js b/lib/hd/private.js index 20524cf4..d95a525a 100644 --- a/lib/hd/private.js +++ b/lib/hd/private.js @@ -155,14 +155,15 @@ HDPrivateKey.prototype.__defineGetter__('xpubkey', function() { HDPrivateKey.prototype.destroy = function destroy(pub) { this.depth = 0; - this.parentFingerPrint.fill(0); this.childIndex = 0; - this.chainCode.fill(0); - this.privateKey.fill(0); - this.publicKey.fill(0); + + crypto.cleanse(this.parentFingerPrint); + crypto.cleanse(this.chainCode); + crypto.cleanse(this.privateKey); + crypto.cleanse(this.publicKey); if (this.fingerPrint) { - this.fingerPrint.fill(0); + crypto.cleanse(this.fingerPrint); this.fingerPrint = null; } diff --git a/lib/hd/public.js b/lib/hd/public.js index b849632a..ac5ef742 100644 --- a/lib/hd/public.js +++ b/lib/hd/public.js @@ -118,13 +118,14 @@ HDPublicKey.prototype.__defineGetter__('xpubkey', function() { HDPublicKey.prototype.destroy = function destroy() { this.depth = 0; - this.parentFingerPrint.fill(0); this.childIndex = 0; - this.chainCode.fill(0); - this.publicKey.fill(0); + + crypto.cleanse(this.parentFingerPrint); + crypto.cleanse(this.chainCode); + crypto.cleanse(this.publicKey); if (this.fingerPrint) { - this.fingerPrint.fill(0); + crypto.cleanse(this.fingerPrint); this.fingerPrint = null; } diff --git a/lib/wallet/masterkey.js b/lib/wallet/masterkey.js index 2157ae25..0ff4c8b6 100644 --- a/lib/wallet/masterkey.js +++ b/lib/wallet/masterkey.js @@ -315,7 +315,7 @@ MasterKey.prototype._lock = function lock() { } if (this.aesKey) { - this.aesKey.fill(0); + crypto.cleanse(this.aesKey); this.aesKey = null; } }; @@ -371,7 +371,7 @@ MasterKey.prototype._decrypt = co(function* decrypt(passphrase, aes) { this.ciphertext = null; if (!aes) { - key.fill(0); + crypto.cleanse(key); return; } @@ -423,7 +423,7 @@ MasterKey.prototype._encrypt = co(function* encrypt(passphrase, aes) { this.ciphertext = data; if (!aes) { - key.fill(0); + crypto.cleanse(key); return; } diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index 2b3a857b..f7fb140a 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -405,12 +405,12 @@ Wallet.prototype._encrypt = co(function* encrypt(passphrase) { try { yield this.db.encryptKeys(this, key); } catch (e) { - key.fill(0); + crypto.cleanse(key); this.drop(); throw e; } - key.fill(0); + crypto.cleanse(key); this.save(); @@ -447,12 +447,12 @@ Wallet.prototype._decrypt = co(function* decrypt(passphrase) { try { yield this.db.decryptKeys(this, key); } catch (e) { - key.fill(0); + crypto.cleanse(key); this.drop(); throw e; } - key.fill(0); + crypto.cleanse(key); this.save();