Matias Alejo Garcia
11 years ago
16 changed files with 714 additions and 714 deletions
@ -1,116 +1,116 @@ |
|||
require('classtool'); |
|||
|
|||
function ClassSpec(b) { |
|||
var MAX_BLOOM_FILTER_SIZE = 36000; // bytes
|
|||
var MAX_HASH_FUNCS = 50; |
|||
var LN2SQUARED = 0.4804530139182014246671025263266649717305529515945455; |
|||
var LN2 = 0.6931471805599453094172321214581765680755001343602552; |
|||
var bit_mask = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]; |
|||
|
|||
function Bloom() { |
|||
this.data = ''; |
|||
this.hashFuncs = 0; |
|||
}; |
|||
|
|||
function ROTL32(x, r) { |
|||
return (x << r) | (x >> (32 - r)); |
|||
}; |
|||
|
|||
function getBlockU32(blockIdx, data) { |
|||
var idx = blockIdx * 4; |
|||
var v = (data[idx + 0] << (0 * 8)) | |
|||
(data[idx + 1] << (1 * 8)) | |
|||
(data[idx + 2] << (2 * 8)) | |
|||
(data[idx + 3] << (3 * 8)); |
|||
return v; |
|||
}; |
|||
|
|||
Bloom.prototype.hash = function(hashNum, data) { |
|||
var h1 = hashNum * (0xffffffff / (this.hashFuncs - 1)); |
|||
var c1 = 0xcc9e2d51; |
|||
var c2 = 0x1b873593; |
|||
var nBlocks = data.length / 4; |
|||
|
|||
// data body
|
|||
for (var i = -nBlocks; i; i++) { |
|||
var k1 = getBlockU32(i); |
|||
|
|||
k1 *= c1; |
|||
k1 = ROTLF32(k1, 15); |
|||
k1 *= c2; |
|||
|
|||
h1 ^= k1; |
|||
h1 = ROTFL(h1, 13); |
|||
h1 = h1 * 5 + 0xe6546b64; |
|||
} |
|||
|
|||
// tail (trailing 1-3 bytes)
|
|||
var tail = data.slice(nBlocks * 4); |
|||
|
|||
var k1 = 0; |
|||
|
|||
switch (data.length & 3) { |
|||
case 3: k1 ^= tail[2] << 16; |
|||
case 2: k1 ^= tail[1] << 8; |
|||
case 1: k1 ^= tail[0]; |
|||
k1 *= c1; |
|||
k1 = ROTL32(k1, 15); |
|||
k1 *= c2; |
|||
h1 ^= k1; |
|||
} |
|||
|
|||
// finalize
|
|||
h1 ^= data.length; |
|||
h1 ^= h1 >> 16; |
|||
h1 *= 0x85ebca6b; |
|||
h1 ^= h1 >> 13; |
|||
h1 *= 0xc2b2ae35; |
|||
h1 ^= h1 >> 16; |
|||
|
|||
return h1 % (this.data.length * 8); |
|||
}; |
|||
|
|||
Bloom.prototype.insert = function(data) { |
|||
for (var i = 0; i < this.hashFuncs; i++) { |
|||
var index = this.hash(i, data); |
|||
this.data[index >> 3] |= bit_mask[7 & index]; |
|||
} |
|||
}; |
|||
|
|||
Bloom.prototype.contains = function(data) { |
|||
for (var i = 0; i < this.hashFuncs; i++) { |
|||
var index = this.hash(i, data); |
|||
if (!(this.data[index >> 3] & bit_mask[7 & index])) |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
}; |
|||
|
|||
Bloom.prototype.sizeOk = function() { |
|||
return this.data.length <= MAX_BLOOM_FILTER_SIZE && |
|||
this.hashFuncs <= MAX_HASH_FUNCS; |
|||
}; |
|||
|
|||
function toInt(v) { |
|||
return ~~v; |
|||
} |
|||
|
|||
function min(a, b) { |
|||
if (a < b) |
|||
return a; |
|||
return b; |
|||
} |
|||
|
|||
Bloom.prototype.init = function(elements, FPRate) { |
|||
var filterSize = min(toInt(-1.0 / LN2SQUARED * elements * Math.log(FPRate)), |
|||
MAX_BLOOM_FILTER_SIZE * 8) / 8; |
|||
this.data[filterSize] = 0; |
|||
this.hashFuncs = min(toInt(this.data.length * 8 / elements * LN2), |
|||
MAX_HASH_FUNCS); |
|||
}; |
|||
|
|||
return Bloom; |
|||
var MAX_BLOOM_FILTER_SIZE = 36000; // bytes
|
|||
var MAX_HASH_FUNCS = 50; |
|||
var LN2SQUARED = 0.4804530139182014246671025263266649717305529515945455; |
|||
var LN2 = 0.6931471805599453094172321214581765680755001343602552; |
|||
var bit_mask = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]; |
|||
|
|||
function Bloom() { |
|||
this.data = ''; |
|||
this.hashFuncs = 0; |
|||
}; |
|||
|
|||
function ROTL32(x, r) { |
|||
return (x << r) | (x >> (32 - r)); |
|||
}; |
|||
|
|||
function getBlockU32(blockIdx, data) { |
|||
var idx = blockIdx * 4; |
|||
var v = (data[idx + 0] << (0 * 8)) | |
|||
(data[idx + 1] << (1 * 8)) | |
|||
(data[idx + 2] << (2 * 8)) | |
|||
(data[idx + 3] << (3 * 8)); |
|||
return v; |
|||
}; |
|||
|
|||
Bloom.prototype.hash = function(hashNum, data) { |
|||
var h1 = hashNum * (0xffffffff / (this.hashFuncs - 1)); |
|||
var c1 = 0xcc9e2d51; |
|||
var c2 = 0x1b873593; |
|||
var nBlocks = data.length / 4; |
|||
|
|||
// data body
|
|||
for (var i = -nBlocks; i; i++) { |
|||
var k1 = getBlockU32(i); |
|||
|
|||
k1 *= c1; |
|||
k1 = ROTLF32(k1, 15); |
|||
k1 *= c2; |
|||
|
|||
h1 ^= k1; |
|||
h1 = ROTFL(h1, 13); |
|||
h1 = h1 * 5 + 0xe6546b64; |
|||
} |
|||
|
|||
// tail (trailing 1-3 bytes)
|
|||
var tail = data.slice(nBlocks * 4); |
|||
|
|||
var k1 = 0; |
|||
|
|||
switch (data.length & 3) { |
|||
case 3: k1 ^= tail[2] << 16; |
|||
case 2: k1 ^= tail[1] << 8; |
|||
case 1: k1 ^= tail[0]; |
|||
k1 *= c1; |
|||
k1 = ROTL32(k1, 15); |
|||
k1 *= c2; |
|||
h1 ^= k1; |
|||
} |
|||
|
|||
// finalize
|
|||
h1 ^= data.length; |
|||
h1 ^= h1 >> 16; |
|||
h1 *= 0x85ebca6b; |
|||
h1 ^= h1 >> 13; |
|||
h1 *= 0xc2b2ae35; |
|||
h1 ^= h1 >> 16; |
|||
|
|||
return h1 % (this.data.length * 8); |
|||
}; |
|||
|
|||
Bloom.prototype.insert = function(data) { |
|||
for (var i = 0; i < this.hashFuncs; i++) { |
|||
var index = this.hash(i, data); |
|||
this.data[index >> 3] |= bit_mask[7 & index]; |
|||
} |
|||
}; |
|||
|
|||
Bloom.prototype.contains = function(data) { |
|||
for (var i = 0; i < this.hashFuncs; i++) { |
|||
var index = this.hash(i, data); |
|||
if (!(this.data[index >> 3] & bit_mask[7 & index])) |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
}; |
|||
|
|||
Bloom.prototype.sizeOk = function() { |
|||
return this.data.length <= MAX_BLOOM_FILTER_SIZE && |
|||
this.hashFuncs <= MAX_HASH_FUNCS; |
|||
}; |
|||
|
|||
function toInt(v) { |
|||
return ~~v; |
|||
} |
|||
|
|||
function min(a, b) { |
|||
if (a < b) |
|||
return a; |
|||
return b; |
|||
} |
|||
|
|||
Bloom.prototype.init = function(elements, FPRate) { |
|||
var filterSize = min(toInt(-1.0 / LN2SQUARED * elements * Math.log(FPRate)), |
|||
MAX_BLOOM_FILTER_SIZE * 8) / 8; |
|||
this.data[filterSize] = 0; |
|||
this.hashFuncs = min(toInt(this.data.length * 8 / elements * LN2), |
|||
MAX_HASH_FUNCS); |
|||
}; |
|||
|
|||
return Bloom; |
|||
}; |
|||
module.defineClass(ClassSpec); |
|||
|
|||
|
@ -1,8 +1,8 @@ |
|||
|
|||
exports.intFromCompact = function(c) |
|||
{ |
|||
var bytes = ((c >>> 24) & 0xff) >>> 0; |
|||
var v = ((c & 0xffffff) << (8 * (bytes - 3))) >>> 0; |
|||
return v; |
|||
var bytes = ((c >>> 24) & 0xff) >>> 0; |
|||
var v = ((c & 0xffffff) << (8 * (bytes - 3))) >>> 0; |
|||
return v; |
|||
} |
|||
|
|||
|
@ -1,43 +1,43 @@ |
|||
require('classtool'); |
|||
|
|||
function ClassSpec(b) { |
|||
var coinUtil = require('./util/util'); |
|||
var timeUtil = require('./util/time'); |
|||
var KeyModule = require('./Key'); |
|||
var SIN = require('./SIN').class(); |
|||
|
|||
function SINKey(cfg) { |
|||
if (typeof cfg != 'object') |
|||
cfg = {}; |
|||
|
|||
this.created = cfg.created; |
|||
this.privKey = cfg.privKey; |
|||
}; |
|||
|
|||
SINKey.prototype.generate = function() { |
|||
this.privKey = KeyModule.Key.generateSync(); |
|||
this.created = timeUtil.curtime(); |
|||
}; |
|||
|
|||
SINKey.prototype.pubkeyHash = function() { |
|||
return coinUtil.sha256ripe160(this.privKey.public); |
|||
}; |
|||
|
|||
SINKey.prototype.storeObj = function() { |
|||
var pubKey = this.privKey.public.toString('hex'); |
|||
var pubKeyHash = this.pubkeyHash(); |
|||
var sin = new SIN(SIN.SIN_EPHEM, pubKeyHash); |
|||
var obj = { |
|||
created: this.created, |
|||
priv: this.privKey.private.toString('hex'), |
|||
pub: pubKey, |
|||
sin: sin.toString(), |
|||
}; |
|||
|
|||
return obj; |
|||
}; |
|||
|
|||
return SINKey; |
|||
var coinUtil = require('./util/util'); |
|||
var timeUtil = require('./util/time'); |
|||
var KeyModule = require('./Key'); |
|||
var SIN = require('./SIN').class(); |
|||
|
|||
function SINKey(cfg) { |
|||
if (typeof cfg != 'object') |
|||
cfg = {}; |
|||
|
|||
this.created = cfg.created; |
|||
this.privKey = cfg.privKey; |
|||
}; |
|||
|
|||
SINKey.prototype.generate = function() { |
|||
this.privKey = KeyModule.Key.generateSync(); |
|||
this.created = timeUtil.curtime(); |
|||
}; |
|||
|
|||
SINKey.prototype.pubkeyHash = function() { |
|||
return coinUtil.sha256ripe160(this.privKey.public); |
|||
}; |
|||
|
|||
SINKey.prototype.storeObj = function() { |
|||
var pubKey = this.privKey.public.toString('hex'); |
|||
var pubKeyHash = this.pubkeyHash(); |
|||
var sin = new SIN(SIN.SIN_EPHEM, pubKeyHash); |
|||
var obj = { |
|||
created: this.created, |
|||
priv: this.privKey.private.toString('hex'), |
|||
pub: pubKey, |
|||
sin: sin.toString(), |
|||
}; |
|||
|
|||
return obj; |
|||
}; |
|||
|
|||
return SINKey; |
|||
}; |
|||
module.defineClass(ClassSpec); |
|||
|
|||
|
@ -1,133 +1,133 @@ |
|||
|
|||
function signOne(hash, addrStr, keys) |
|||
{ |
|||
var keyObj = keys[addrStr]; |
|||
var rawPrivKey = new Buffer(keyObj.priv, 'hex'); |
|||
var key = new KeyModule.Key(); |
|||
key.private = rawPrivKey; |
|||
var signature = key.signSync(hash); |
|||
var keyObj = keys[addrStr]; |
|||
var rawPrivKey = new Buffer(keyObj.priv, 'hex'); |
|||
var key = new KeyModule.Key(); |
|||
key.private = rawPrivKey; |
|||
var signature = key.signSync(hash); |
|||
|
|||
return signature; |
|||
return signature; |
|||
} |
|||
|
|||
function signTxIn(nIn, tx, txInputs, network, keys, scripts) |
|||
{ |
|||
// locate TX input needing a signature
|
|||
var txin = tx.ins[nIn]; |
|||
var scriptSig = txin.getScript(); |
|||
|
|||
// locate TX output, within txInputs
|
|||
var txoutHash = txin.getOutpointHash(); |
|||
if (!(txoutHash in txInputs)) |
|||
throw new Error("signTxIn missing input hash"); |
|||
var txFrom = txInputs[txoutHash]; |
|||
var txoutIndex = txin.getOutpointIndex(); |
|||
if (txFrom.outs.length >= txoutIndex) |
|||
throw new Error("signTxIn missing input index"); |
|||
var txout = txFrom.outs[txoutIndex]; |
|||
var scriptPubKey = txout.getScript(); |
|||
|
|||
// detect type of transaction, and extract useful elements
|
|||
var txType = scriptPubKey.classify(); |
|||
if (txType == TX_UNKNOWN) |
|||
throw new Error("unknown TX type"); |
|||
var scriptData = scriptPubKey.capture(); |
|||
|
|||
// if P2SH, lookup the script
|
|||
var subscriptRaw = undefined; |
|||
var subscript = undefined; |
|||
var subType = undefined; |
|||
var subData = undefined; |
|||
if (txType == TX_SCRIPTHASH) { |
|||
var addr = new Address(network.addressScript, scriptData[0]); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in scripts)) |
|||
throw new Error("unknown script hash address"); |
|||
|
|||
subscriptRaw = new Buffer(scripts[addrStr], 'hex'); |
|||
subscript = new Script(subscriptRaw); |
|||
subType = subscript.classify(); |
|||
if (subType == TX_UNKNOWN) |
|||
throw new Error("unknown subscript TX type"); |
|||
subData = subscript.capture(); |
|||
} |
|||
|
|||
var hash = tx.hashForSignature(scriptPubKey, i, 0); |
|||
|
|||
switch (txType) { |
|||
case TX_PUBKEY: |
|||
// already signed
|
|||
if (scriptSig.chunks.length > 0) |
|||
return; |
|||
|
|||
var pubkeyhash = util.sha256ripe160(scriptData[0]); |
|||
var addr = new Address(network.addressPubkey, pubkeyhash); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
throw new Error("unknown pubkey"); |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.writeBytes(signature); |
|||
break; |
|||
|
|||
case TX_PUBKEYHASH: |
|||
// already signed
|
|||
if (scriptSig.chunks.length > 0) |
|||
return; |
|||
|
|||
var addr = new Address(network.addressPubkey, scriptData[0]); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
throw new Error("unknown pubkey hash address"); |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.writeBytes(signature); |
|||
scriptSig.writeBytes(key.public); |
|||
break; |
|||
|
|||
case TX_SCRIPTHASH: |
|||
// already signed
|
|||
if (scriptSig.chunks.length > 0) |
|||
return; |
|||
|
|||
var addr = new Address(network.addressPubkey, subData[0]); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
throw new Error("unknown script(pubkey hash) address"); |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.writeBytes(signature); |
|||
scriptSig.writeBytes(key.public); |
|||
break; |
|||
|
|||
case TX_MULTISIG: |
|||
while (scriptSig.chunks.length < scriptData.length) { |
|||
scriptSig.writeBytes(util.EMPTY_BUFFER); |
|||
} |
|||
for (var i = 0; i < scriptData.length; i++) { |
|||
// skip already signed
|
|||
if (scriptSig.chunks[i].length > 0) |
|||
continue; |
|||
|
|||
var pubkeyhash = util.sha256ripe160(scriptSig.chunks[i]); |
|||
var addr = new Address(network.addressPubkey, pubkeyhash); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
continue; |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.chunks[i] = signature; |
|||
} |
|||
break; |
|||
} |
|||
|
|||
if (txtype == TX_SCRIPTHASH) |
|||
scriptSig.writeBytes(subscriptRaw); |
|||
// locate TX input needing a signature
|
|||
var txin = tx.ins[nIn]; |
|||
var scriptSig = txin.getScript(); |
|||
|
|||
// locate TX output, within txInputs
|
|||
var txoutHash = txin.getOutpointHash(); |
|||
if (!(txoutHash in txInputs)) |
|||
throw new Error("signTxIn missing input hash"); |
|||
var txFrom = txInputs[txoutHash]; |
|||
var txoutIndex = txin.getOutpointIndex(); |
|||
if (txFrom.outs.length >= txoutIndex) |
|||
throw new Error("signTxIn missing input index"); |
|||
var txout = txFrom.outs[txoutIndex]; |
|||
var scriptPubKey = txout.getScript(); |
|||
|
|||
// detect type of transaction, and extract useful elements
|
|||
var txType = scriptPubKey.classify(); |
|||
if (txType == TX_UNKNOWN) |
|||
throw new Error("unknown TX type"); |
|||
var scriptData = scriptPubKey.capture(); |
|||
|
|||
// if P2SH, lookup the script
|
|||
var subscriptRaw = undefined; |
|||
var subscript = undefined; |
|||
var subType = undefined; |
|||
var subData = undefined; |
|||
if (txType == TX_SCRIPTHASH) { |
|||
var addr = new Address(network.addressScript, scriptData[0]); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in scripts)) |
|||
throw new Error("unknown script hash address"); |
|||
|
|||
subscriptRaw = new Buffer(scripts[addrStr], 'hex'); |
|||
subscript = new Script(subscriptRaw); |
|||
subType = subscript.classify(); |
|||
if (subType == TX_UNKNOWN) |
|||
throw new Error("unknown subscript TX type"); |
|||
subData = subscript.capture(); |
|||
} |
|||
|
|||
var hash = tx.hashForSignature(scriptPubKey, i, 0); |
|||
|
|||
switch (txType) { |
|||
case TX_PUBKEY: |
|||
// already signed
|
|||
if (scriptSig.chunks.length > 0) |
|||
return; |
|||
|
|||
var pubkeyhash = util.sha256ripe160(scriptData[0]); |
|||
var addr = new Address(network.addressPubkey, pubkeyhash); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
throw new Error("unknown pubkey"); |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.writeBytes(signature); |
|||
break; |
|||
|
|||
case TX_PUBKEYHASH: |
|||
// already signed
|
|||
if (scriptSig.chunks.length > 0) |
|||
return; |
|||
|
|||
var addr = new Address(network.addressPubkey, scriptData[0]); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
throw new Error("unknown pubkey hash address"); |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.writeBytes(signature); |
|||
scriptSig.writeBytes(key.public); |
|||
break; |
|||
|
|||
case TX_SCRIPTHASH: |
|||
// already signed
|
|||
if (scriptSig.chunks.length > 0) |
|||
return; |
|||
|
|||
var addr = new Address(network.addressPubkey, subData[0]); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
throw new Error("unknown script(pubkey hash) address"); |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.writeBytes(signature); |
|||
scriptSig.writeBytes(key.public); |
|||
break; |
|||
|
|||
case TX_MULTISIG: |
|||
while (scriptSig.chunks.length < scriptData.length) { |
|||
scriptSig.writeBytes(util.EMPTY_BUFFER); |
|||
} |
|||
for (var i = 0; i < scriptData.length; i++) { |
|||
// skip already signed
|
|||
if (scriptSig.chunks[i].length > 0) |
|||
continue; |
|||
|
|||
var pubkeyhash = util.sha256ripe160(scriptSig.chunks[i]); |
|||
var addr = new Address(network.addressPubkey, pubkeyhash); |
|||
var addrStr = addr.toString(); |
|||
if (!(addrStr in keys)) |
|||
continue; |
|||
|
|||
var signature = signOne(hash, addrStr, keys); |
|||
scriptSig.chunks[i] = signature; |
|||
} |
|||
break; |
|||
} |
|||
|
|||
if (txtype == TX_SCRIPTHASH) |
|||
scriptSig.writeBytes(subscriptRaw); |
|||
} |
|||
|
|||
exports.Transaction = function Transaction(tx, txInputs, network, keys, scripts) |
|||
{ |
|||
for (var i = 0; i < tx.ins.length; i++) |
|||
signTxIn(i, tx, txInputs, network, keys, scripts); |
|||
for (var i = 0; i < tx.ins.length; i++) |
|||
signTxIn(i, tx, txInputs, network, keys, scripts); |
|||
}; |
|||
|
|||
|
@ -1,53 +1,53 @@ |
|||
require('classtool'); |
|||
|
|||
function ClassSpec(b) { |
|||
var coinUtil = require('./util/util'); |
|||
var timeUtil = require('./util/time'); |
|||
var KeyModule = require('./Key'); |
|||
var PrivateKey = require('./PrivateKey').class(); |
|||
var Address = require('./Address').class(); |
|||
var coinUtil = require('./util/util'); |
|||
var timeUtil = require('./util/time'); |
|||
var KeyModule = require('./Key'); |
|||
var PrivateKey = require('./PrivateKey').class(); |
|||
var Address = require('./Address').class(); |
|||
|
|||
function WalletKey(cfg) { |
|||
this.network = cfg.network; // required
|
|||
this.created = cfg.created; |
|||
this.privKey = cfg.privKey; |
|||
}; |
|||
function WalletKey(cfg) { |
|||
this.network = cfg.network; // required
|
|||
this.created = cfg.created; |
|||
this.privKey = cfg.privKey; |
|||
}; |
|||
|
|||
WalletKey.prototype.generate = function() { |
|||
this.privKey = KeyModule.Key.generateSync(); |
|||
this.created = timeUtil.curtime(); |
|||
}; |
|||
WalletKey.prototype.generate = function() { |
|||
this.privKey = KeyModule.Key.generateSync(); |
|||
this.created = timeUtil.curtime(); |
|||
}; |
|||
|
|||
WalletKey.prototype.storeObj = function() { |
|||
var pubKey = this.privKey.public.toString('hex'); |
|||
var pubKeyHash = coinUtil.sha256ripe160(this.privKey.public); |
|||
var addr = new Address(this.network.addressPubkey, pubKeyHash); |
|||
var priv = new PrivateKey(this.network.keySecret, this.privKey.private, this.privKey.compressed); |
|||
var obj = { |
|||
created: this.created, |
|||
priv: priv.toString(), |
|||
pub: pubKey, |
|||
addr: addr.toString(), |
|||
}; |
|||
WalletKey.prototype.storeObj = function() { |
|||
var pubKey = this.privKey.public.toString('hex'); |
|||
var pubKeyHash = coinUtil.sha256ripe160(this.privKey.public); |
|||
var addr = new Address(this.network.addressPubkey, pubKeyHash); |
|||
var priv = new PrivateKey(this.network.keySecret, this.privKey.private, this.privKey.compressed); |
|||
var obj = { |
|||
created: this.created, |
|||
priv: priv.toString(), |
|||
pub: pubKey, |
|||
addr: addr.toString(), |
|||
}; |
|||
|
|||
return obj; |
|||
}; |
|||
return obj; |
|||
}; |
|||
|
|||
WalletKey.prototype.fromObj = function(obj) { |
|||
this.created = obj.created; |
|||
this.privKey = new KeyModule.Key(); |
|||
if (obj.priv.length==64) { |
|||
this.privKey.private = new Buffer(obj.priv,'hex'); |
|||
this.privKey.compressed = true; |
|||
} |
|||
else { |
|||
var priv = new PrivateKey(obj.priv); |
|||
this.privKey.private = new Buffer(priv.payload()); |
|||
this.privKey.compressed = priv.compressed(); |
|||
} |
|||
this.privKey.regenerateSync(); |
|||
}; |
|||
WalletKey.prototype.fromObj = function(obj) { |
|||
this.created = obj.created; |
|||
this.privKey = new KeyModule.Key(); |
|||
if (obj.priv.length==64) { |
|||
this.privKey.private = new Buffer(obj.priv,'hex'); |
|||
this.privKey.compressed = true; |
|||
} |
|||
else { |
|||
var priv = new PrivateKey(obj.priv); |
|||
this.privKey.private = new Buffer(priv.payload()); |
|||
this.privKey.compressed = priv.compressed(); |
|||
} |
|||
this.privKey.regenerateSync(); |
|||
}; |
|||
|
|||
return WalletKey; |
|||
return WalletKey; |
|||
}; |
|||
module.defineClass(ClassSpec); |
|||
|
Loading…
Reference in new issue