|
|
@ -5,6 +5,7 @@ var PrivateKey = Bitcore.PrivateKey; |
|
|
|
var PublicKey = Bitcore.PublicKey; |
|
|
|
var crypto = Bitcore.crypto; |
|
|
|
var HDPath = require('./hdpath'); |
|
|
|
var sjcl = require('sjcl'); |
|
|
|
|
|
|
|
function WalletUtils() {}; |
|
|
|
|
|
|
@ -61,8 +62,9 @@ WalletUtils.xPubToCopayerId = function(xpub) { |
|
|
|
return (new Bitcore.HDPublicKey(xpub)).derive(HDPath.IdBranch).publicKey.toString(); |
|
|
|
}; |
|
|
|
|
|
|
|
<< << << < HEAD |
|
|
|
WalletUtils.toSecret = function(walletId, walletPrivKey, network) { |
|
|
|
return walletId + ':' + walletPrivKey.toWIF() + ':' + (network == 'testnet' ? 'T' : 'L'); |
|
|
|
return walletId + ':' + walletPrivKey.toWIF() + ':' + (network == 'testnet' ? 'T' : 'L'); |
|
|
|
}; |
|
|
|
|
|
|
|
WalletUtils.fromSecret = function(secret) { |
|
|
@ -72,7 +74,7 @@ WalletUtils.fromSecret = function(secret) { |
|
|
|
var networkChar = secretSplit[2]; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
walletId: walletId, |
|
|
|
walletPrivKey: walletPrivKey, |
|
|
|
network: networkChar == 'T' ? 'testnet' : 'livenet', |
|
|
@ -80,6 +82,19 @@ WalletUtils.fromSecret = function(secret) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WalletUtils.encryptMessage = function(message, password) { |
|
|
|
var key = sjcl.codec.utf8String.toBits(password); |
|
|
|
key = sjcl.bitArray.clamp(key, 256); |
|
|
|
return sjcl.encrypt(key, message, { |
|
|
|
ks: 256, |
|
|
|
iter: 1 |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
WalletUtils.decryptMessage = function(cyphertextJson, password) { |
|
|
|
var key = sjcl.codec.utf8String.toBits(password); |
|
|
|
key = sjcl.bitArray.clamp(key, 256); |
|
|
|
return sjcl.decrypt(key, cyphertextJson); |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = WalletUtils; |
|
|
|