|
@ -7,6 +7,7 @@ var Address = Bitcore.Address; |
|
|
var PrivateKey = Bitcore.PrivateKey; |
|
|
var PrivateKey = Bitcore.PrivateKey; |
|
|
var PublicKey = Bitcore.PublicKey; |
|
|
var PublicKey = Bitcore.PublicKey; |
|
|
var crypto = Bitcore.crypto; |
|
|
var crypto = Bitcore.crypto; |
|
|
|
|
|
var encoding = Bitcore.encoding; |
|
|
var HDPath = require('./hdpath'); |
|
|
var HDPath = require('./hdpath'); |
|
|
var Utils = require('./utils'); |
|
|
var Utils = require('./utils'); |
|
|
|
|
|
|
|
@ -32,10 +33,10 @@ WalletUtils.signMessage = function(text, privKey) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WalletUtils.accessFromData = function(data) { |
|
|
WalletUtils.accessFromData = function(data) { |
|
|
if (data.xPrivKey) |
|
|
if (data.xPrivKey) |
|
|
return 'full'; |
|
|
return 'full'; |
|
|
|
|
|
|
|
|
if (data.rwPrivKey) |
|
|
if (data.rwPrivKey) |
|
|
return 'readwrite'; |
|
|
return 'readwrite'; |
|
|
|
|
|
|
|
|
return 'readonly'; |
|
|
return 'readonly'; |
|
@ -84,22 +85,42 @@ WalletUtils.xPubToCopayerId = function(xpub) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
WalletUtils.toSecret = function(walletId, walletPrivKey, network) { |
|
|
WalletUtils.toSecret = function(walletId, walletPrivKey, network) { |
|
|
return walletId + ':' + walletPrivKey.toWIF() + ':' + (network == 'testnet' ? 'T' : 'L'); |
|
|
var widHex = new Buffer(walletId.replace(/-/g, ''), 'hex'); |
|
|
|
|
|
widBase58 = new encoding.Base58(widHex).toString(); |
|
|
|
|
|
return widBase58 + walletPrivKey.toWIF() + (network == 'testnet' ? 'T' : 'L'); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
WalletUtils.fromSecret = function(secret) { |
|
|
WalletUtils.fromSecret = function(secret) { |
|
|
$.checkArgument(secret); |
|
|
$.checkArgument(secret); |
|
|
var secretSplit = secret.split(':'); |
|
|
|
|
|
var walletId = secretSplit[0]; |
|
|
|
|
|
var walletPrivKey = Bitcore.PrivateKey.fromString(secretSplit[1]); |
|
|
|
|
|
var networkChar = secretSplit[2]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
function split(str, indexes) { |
|
|
walletId: walletId, |
|
|
var parts = []; |
|
|
walletPrivKey: walletPrivKey, |
|
|
indexes.push(str.length); |
|
|
network: networkChar == 'T' ? 'testnet' : 'livenet', |
|
|
var i = 0; |
|
|
|
|
|
while (i < indexes.length) { |
|
|
|
|
|
parts.push(str.substring(i == 0 ? 0 : indexes[i - 1], indexes[i])); |
|
|
|
|
|
i++; |
|
|
|
|
|
}; |
|
|
|
|
|
return parts; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
var secretSplit = split(secret, [22, 74]); |
|
|
|
|
|
var widBase58 = secretSplit[0]; |
|
|
|
|
|
var widHex = encoding.Base58.decode(widBase58).toString('hex'); |
|
|
|
|
|
var walletId = split(widHex, [8, 12, 16, 20]).join('-'); |
|
|
|
|
|
|
|
|
|
|
|
var walletPrivKey = Bitcore.PrivateKey.fromString(secretSplit[1]); |
|
|
|
|
|
var networkChar = secretSplit[2]; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
walletId: walletId, |
|
|
|
|
|
walletPrivKey: walletPrivKey, |
|
|
|
|
|
network: networkChar == 'T' ? 'testnet' : 'livenet', |
|
|
|
|
|
}; |
|
|
|
|
|
} catch (ex) { |
|
|
|
|
|
throw new Error('Invalid secret'); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|