@dashevo/dashcore-lib
Advanced tools
Comparing version 0.16.10 to 0.17.0
@@ -154,4 +154,5 @@ /* eslint-disable */ | ||
* to json, buffer, or a hex string | ||
* @param {string} [network] | ||
*/ | ||
SimplifiedMNList.prototype.toSimplifiedMNListDiff = function toSimplifiedMNListDiff() { | ||
SimplifiedMNList.prototype.toSimplifiedMNListDiff = function toSimplifiedMNListDiff(network) { | ||
if (!this.cbTx || !this.cbTxMerkleTree) { | ||
@@ -169,5 +170,5 @@ throw new Error("Can't convert MN list to diff - cbTx is missing"); | ||
merkleRootMNList: this.merkleRootMNList | ||
}); | ||
}, network); | ||
}; | ||
module.exports = SimplifiedMNList; |
@@ -18,2 +18,3 @@ /* eslint-disable */ | ||
* @param {Buffer|Object|string} [arg] - A Buffer, JSON string, or Object representing a MnListDiff | ||
* @param {string} [network] | ||
* @class {SimplifiedMNListDiff} | ||
@@ -28,3 +29,3 @@ * @property {string} baseBlockHash - sha256 | ||
*/ | ||
function SimplifiedMNListDiff(arg) { | ||
function SimplifiedMNListDiff(arg, network) { | ||
if (arg) { | ||
@@ -34,7 +35,7 @@ if (arg instanceof SimplifiedMNListDiff) { | ||
} else if (BufferUtil.isBuffer(arg)) { | ||
return SimplifiedMNListDiff.fromBuffer(arg); | ||
return SimplifiedMNListDiff.fromBuffer(arg, network); | ||
} else if (_.isObject(arg)) { | ||
return SimplifiedMNListDiff.fromObject(arg); | ||
return SimplifiedMNListDiff.fromObject(arg, network); | ||
} else if (isHexString(arg)) { | ||
return SimplifiedMNListDiff.fromHexString(arg); | ||
return SimplifiedMNListDiff.fromHexString(arg, network); | ||
} else { | ||
@@ -49,5 +50,6 @@ throw new TypeError('Unrecognized argument passed to SimplifiedMNListDiff constructor'); | ||
* @param {Buffer} buffer | ||
* @param {string} [network] | ||
* @return {SimplifiedMNListDiff} | ||
*/ | ||
SimplifiedMNListDiff.fromBuffer = function fromBuffer(buffer) { | ||
SimplifiedMNListDiff.fromBuffer = function fromBuffer(buffer, network) { | ||
var bufferReader = new BufferReader(Buffer.from(buffer)); | ||
@@ -71,7 +73,7 @@ var data = {}; | ||
for (var i = 0; i < mnListSize; i++) { | ||
data.mnList.push(SimplifiedMNListEntry.fromBuffer(bufferReader.read(constants.SML_ENTRY_SIZE))); | ||
data.mnList.push(SimplifiedMNListEntry.fromBuffer(bufferReader.read(constants.SML_ENTRY_SIZE), network)); | ||
} | ||
data.merkleRootMNList = data.cbTx.extraPayload.merkleRootMNList; | ||
return this.fromObject(data); | ||
return this.fromObject(data, network); | ||
}; | ||
@@ -81,6 +83,7 @@ | ||
* @param {string} hexString | ||
* @param {string} [network] | ||
* @return {SimplifiedMNListDiff} | ||
*/ | ||
SimplifiedMNListDiff.fromHexString = function fromHexString(hexString) { | ||
return SimplifiedMNListDiff.fromBuffer(Buffer.from(hexString, 'hex')); | ||
SimplifiedMNListDiff.fromHexString = function fromHexString(hexString, network) { | ||
return SimplifiedMNListDiff.fromBuffer(Buffer.from(hexString, 'hex'), network); | ||
}; | ||
@@ -117,5 +120,6 @@ | ||
* @param obj | ||
* @param {string} [network] | ||
* @return {SimplifiedMNListDiff} | ||
*/ | ||
SimplifiedMNListDiff.fromObject = function fromObject(obj) { | ||
SimplifiedMNListDiff.fromObject = function fromObject(obj, network) { | ||
var simplifiedMNListDiff = new SimplifiedMNListDiff(); | ||
@@ -134,6 +138,8 @@ | ||
simplifiedMNListDiff.mnList = obj.mnList.map(function (SMLEntry) { | ||
return new SimplifiedMNListEntry(SMLEntry); | ||
return new SimplifiedMNListEntry(SMLEntry, network); | ||
}); | ||
simplifiedMNListDiff.merkleRootMNList = obj.merkleRootMNList; | ||
simplifiedMNListDiff.network = network; | ||
return simplifiedMNListDiff; | ||
@@ -163,5 +169,5 @@ }; | ||
SimplifiedMNListDiff.prototype.copy = function copy() { | ||
return SimplifiedMNListDiff.fromBuffer(this.toBuffer()); | ||
return SimplifiedMNListDiff.fromBuffer(this.toBuffer(), this.network); | ||
}; | ||
module.exports = SimplifiedMNListDiff; |
@@ -14,2 +14,3 @@ /* eslint-disable */ | ||
var ipUtils = require('../util/ip'); | ||
var Address = require('../address'); | ||
@@ -32,3 +33,3 @@ var isSha256 = utils.isSha256HexString; | ||
* @property {string} pubKeyOperator - operator public key | ||
* @property {string} keyIDVoting - public key hash, 20 bytes | ||
* @property {string} votingAddress | ||
* @property {boolean} isValid | ||
@@ -39,3 +40,4 @@ */ | ||
* @class SimplifiedMNListEntry | ||
* @param {*} arg - A Buffer, JSON string, or Object representing a SmlEntry | ||
* @param {string|Object|Buffer} arg - A Buffer, JSON string, or Object representing a SmlEntry | ||
* @param {string} [network] | ||
* @constructor | ||
@@ -46,6 +48,6 @@ * @property {string} proRegTxHash | ||
* @property {string} pubKeyOperator - operator public key | ||
* @property {string} keyIDVoting - public key hash, 20 bytes | ||
* @property {string} votingAddress | ||
* @property {boolean} isValid | ||
*/ | ||
function SimplifiedMNListEntry(arg) { | ||
function SimplifiedMNListEntry(arg, network) { | ||
if (arg) { | ||
@@ -55,3 +57,3 @@ if (arg instanceof SimplifiedMNListEntry) { | ||
} else if (BufferUtil.isBuffer(arg)) { | ||
return SimplifiedMNListEntry.fromBuffer(arg); | ||
return SimplifiedMNListEntry.fromBuffer(arg, network); | ||
} else if (_.isObject(arg)) { | ||
@@ -62,3 +64,3 @@ return SimplifiedMNListEntry.fromObject(arg); | ||
} else if (isHexString(arg)) { | ||
return SimplifiedMNListEntry.fromHexString(arg); | ||
return SimplifiedMNListEntry.fromHexString(arg, network); | ||
} else { | ||
@@ -72,6 +74,7 @@ throw new TypeError('Unrecognized argument for SimplifiedMNListEntry'); | ||
* Parse buffer and returns SimplifiedMNListEntry | ||
* @param buffer | ||
* @param {Buffer} buffer | ||
* @param {string} [network] | ||
* @return {SimplifiedMNListEntry} | ||
*/ | ||
SimplifiedMNListEntry.fromBuffer = function fromBuffer(buffer) { | ||
SimplifiedMNListEntry.fromBuffer = function fromBuffer(buffer, network) { | ||
var bufferReader = new BufferReader(buffer); | ||
@@ -84,3 +87,3 @@ | ||
pubKeyOperator: bufferReader.read(BLS_PUBLIC_KEY_SIZE).toString('hex'), | ||
keyIDVoting: bufferReader.read(PUBKEY_ID_SIZE).reverse().toString('hex'), | ||
votingAddress: Address.fromPublicKeyHash(bufferReader.read(PUBKEY_ID_SIZE), network).toString(), | ||
isValid: Boolean(bufferReader.readUInt8()) | ||
@@ -92,6 +95,7 @@ }); | ||
* @param {string} string | ||
* @param {string} [network] | ||
* @return {SimplifiedMNListEntry} | ||
*/ | ||
SimplifiedMNListEntry.fromHexString = function fromString(string) { | ||
return SimplifiedMNListEntry.fromBuffer(Buffer.from(string, 'hex')); | ||
SimplifiedMNListEntry.fromHexString = function fromString(string, network) { | ||
return SimplifiedMNListEntry.fromBuffer(Buffer.from(string, 'hex'), network); | ||
}; | ||
@@ -111,3 +115,3 @@ | ||
bufferWriter.write(Buffer.from(this.pubKeyOperator, 'hex')); | ||
bufferWriter.write(Buffer.from(this.keyIDVoting, 'hex').reverse()); | ||
bufferWriter.write(Buffer.from(Address.fromString(this.votingAddress).hashBuffer, 'hex')); | ||
bufferWriter.writeUInt8(Number(this.isValid)); | ||
@@ -129,5 +133,7 @@ | ||
SMLEntry.pubKeyOperator = obj.pubKeyOperator; | ||
SMLEntry.keyIDVoting = obj.keyIDVoting; | ||
SMLEntry.votingAddress = obj.votingAddress; | ||
SMLEntry.isValid = obj.isValid; | ||
SMLEntry.network = Address.fromString(obj.votingAddress).network; | ||
SMLEntry.validate(); | ||
@@ -143,7 +149,4 @@ return SMLEntry; | ||
} | ||
if (!isHexStringOfSize(this.keyIDVoting, PUBKEY_ID_SIZE * 2)) { | ||
console.log(this.keyIDVoting); | ||
} | ||
$.checkArgument(isHexStringOfSize(this.pubKeyOperator, BLS_PUBLIC_KEY_SIZE * 2), 'Expected pubKeyOperator to be a pubkey id'); | ||
$.checkArgument(isHexStringOfSize(this.keyIDVoting, PUBKEY_ID_SIZE * 2), 'Expected keyIDVoting to be a pubkey id'); | ||
$.checkArgument(Address.isValid(this.votingAddress), 'votingAddress is not valid'); | ||
$.checkArgument(typeof this.isValid === 'boolean', 'Expected isValid to be a boolean'); | ||
@@ -158,3 +161,3 @@ }; | ||
pubKeyOperator: this.pubKeyOperator, | ||
keyIDVoting: this.keyIDVoting, | ||
votingAddress: this.votingAddress, | ||
isValid: this.isValid | ||
@@ -176,5 +179,5 @@ }; | ||
SimplifiedMNListEntry.prototype.copy = function copy() { | ||
return SimplifiedMNListEntry.fromBuffer(this.toBuffer()); | ||
return SimplifiedMNListEntry.fromBuffer(this.toBuffer(), this.network); | ||
}; | ||
module.exports = SimplifiedMNListEntry; |
{ | ||
"name": "@dashevo/dashcore-lib", | ||
"version": "0.16.10", | ||
"version": "0.17.0", | ||
"description": "A pure and powerful JavaScript Dash library.", | ||
@@ -5,0 +5,0 @@ "author": "Dash Core Group, Inc. <dev@dash.org>", |
@@ -7,2 +7,3 @@ /* eslint-disable */ | ||
var constants = require('../../lib/constants'); | ||
var Networks = require('../../lib/networks'); | ||
@@ -125,3 +126,3 @@ describe('SimplifiedMNList', function () { | ||
var diff = originalMNList.toSimplifiedMNListDiff(); | ||
var diff = originalMNList.toSimplifiedMNListDiff(Networks.testnet); | ||
@@ -128,0 +129,0 @@ var restoredMNList = new SimplifiedMNList(diff); |
@@ -7,2 +7,3 @@ /* eslint-disable */ | ||
var sinon = require('sinon'); | ||
var Networks = require('../../lib/networks'); | ||
@@ -25,3 +26,3 @@ var mnListDiffHexString = 'd6c47184a6d7a08b9360a84c377e2320a7ec969a2fc7f80a7ef9b305000000007abac1d3fa5c8957bff0e9e1880c9d59ffefcc1b04b9b364c14f1604000000000100000001720668fc7eb874724c9fb50479009b8747d64f7c36bccb8f7b3fe247f346d6ce010103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff4b02bb520427f3355c08fabe6d6d01ac1912a0a88021110ad2364eade497dd1da0edd7857757c10f62dd720956ac0100000000000000100000175a0000000d2f6e6f64655374726174756d2f000000000200e12237010000001976a914cb594917ad4e5849688ec63f29a0f7f3badb5da688ac00e12237010000001976a914a3c5284d3cd896815ac815f2dd76a3a71cb3d8e688ac00000000260100bb5200009e8ecb69a1493e3d573cc9ce8460b9a0d7b05e77ca17878c9faf73959392cef3019f5c63c41c148ef09e4c82471db0500b6c2246d77a93c0387330201e6124d91404419aa9fed4f35fcb986c50fbaa0c7555c68f8a9876968c63c6f92064ff06f1fe7b34629e1f9f156e4e3720ed76745a9966adb50fb513f1285263d5050000000000000000000000000000ffff2d30b1de4e1f842476e8d82327adfb9b617a7ac3f62868946c0c4b6b0e365747cfb8825b8b79ba0eb1fa62e8583ae7102f59bf70c7c7ce2342a602ce6bd150809591377ecf31971558ca01685ce50d7f351dae246ab6d23033b1fb7ad8368467fb348086822fe6ce77d8a4398f99dae01aee02f174c49075e3e92422227fd6a57d4a44d7419c060000000000000000000000000000ffff5350e5d54e1f16415af54406658be9ea44d82b6b502bb90d93e32997484533a8a71a4ed98d12cea3709d84a5835b6ad8ed48d3101633d0669e929f06ac80c05365d9558ad79cbb78f2c000f1b186e58c0e1247221f1ce97cd273f917e034ff4b66baee366ede691e0590a66348fc52b6a63a7013cde16f282347e5949d88a8f9989a46411409190000000000000000000000000000ffff95f8374d4e1f8b165f653a3970a17f432f6c3abb8b681c71a3775f998fff322341d2994767c167c8a43b1b4661b9c01ef637763d4d814d31414b558eff2b3b489b6128ac6852e0fdb85c009f90d73441206a915ec0e889bba5d0d1e3fddf9ccb5ef37f51ede61ea0c1466afa7a17bc1dadb4a69815103b85f849eb9dc0db670bd01c7c033529090000000000000000000000000000ffff332670634e1f88ee437bc0ba444b71a6b8a525146e9c748a8430fc85ad47beda04bb2e5b698bca9f3d5a5d5dfdd5990cd08daa07371f8cbb11679781ce75b0f15db8eae0464672c34ae401'; | ||
"pubKeyOperator": "842476e8d82327adfb9b617a7ac3f62868946c0c4b6b0e365747cfb8825b8b79ba0eb1fa62e8583ae7102f59bf70c7c7", | ||
"keyIDVoting": "ca58159731cf7e3791958050d16bce02a64223ce", | ||
"votingAddress": "yf7QHemCfbmKEncwZxroTj8JtShXsC28V6", | ||
"isValid": true | ||
@@ -34,3 +35,3 @@ }, | ||
"pubKeyOperator": "16415af54406658be9ea44d82b6b502bb90d93e32997484533a8a71a4ed98d12cea3709d84a5835b6ad8ed48d3101633", | ||
"keyIDVoting": "c0f278bb9cd78a55d96553c080ac069f929e66d0", | ||
"votingAddress": "yfKNLE5v4QTnMvj7y3JVoWEfQanD4qHWGk", | ||
"isValid": false | ||
@@ -43,3 +44,3 @@ }, | ||
"pubKeyOperator": "8b165f653a3970a17f432f6c3abb8b681c71a3775f998fff322341d2994767c167c8a43b1b4661b9c01ef637763d4d81", | ||
"keyIDVoting": "5cb8fde05268ac28619b483b2bff8e554b41314d", | ||
"votingAddress": "yTMbtGvG722zFbkpAnBrQvJ8WXH2g2kosL", | ||
"isValid": false | ||
@@ -52,3 +53,3 @@ }, | ||
"pubKeyOperator": "88ee437bc0ba444b71a6b8a525146e9c748a8430fc85ad47beda04bb2e5b698bca9f3d5a5d5dfdd5990cd08daa07371f", | ||
"keyIDVoting": "e44ac3724646e0eab85df1b075ce81976711bb8c", | ||
"votingAddress": "yZ9ZYmfby7fcLpJm9hPosEVmkY6eQ4PXA4", | ||
"isValid": true | ||
@@ -132,3 +133,3 @@ } | ||
var buf = Buffer.from(mnListDiffHexString, 'hex'); | ||
var smlDiff = new SimplifiedMNListDiff(buf); | ||
var smlDiff = new SimplifiedMNListDiff(buf, Networks.testnet); | ||
var parsed = smlDiff.toObject(); | ||
@@ -146,3 +147,3 @@ expect(parsed).to.be.deep.equal(mnListDiffJSON); | ||
it('Should be able to create an instance from a hex string', function () { | ||
var diff = SimplifiedMNListDiff.fromHexString(mnListDiffHexString); | ||
var diff = SimplifiedMNListDiff.fromHexString(mnListDiffHexString, Networks.testnet); | ||
expect(diff.toObject()).to.be.deep.equal(mnListDiffJSON); | ||
@@ -149,0 +150,0 @@ }); |
@@ -6,2 +6,3 @@ /* eslint-disable */ | ||
var expect = require('chai').expect; | ||
var Networks = require('../../lib/networks'); | ||
@@ -13,3 +14,3 @@ var smlEntryJSON = { | ||
"pubKeyOperator": "1326ddac1044e0219dba7dccf6b43d1deed3e897717ca06757243b02516cfa67e24026f7a317cf575b40c10e7f6bf7f0", | ||
"keyIDVoting": "68976be39d5ef1d43761123f497c96cf4226da87", | ||
"votingAddress": "yYhmQPak2w5L8KSwVw9R5wpqzPbAJ1fK7v", | ||
"isValid": true | ||
@@ -25,3 +26,3 @@ }; | ||
"pubKeyOperator": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"keyIDVoting": "428c680677c45b1c2a50a2cca57e0ad0409f5d59", | ||
"votingAddress": "yUTy9Fb2ULXdgyqYtMMbuUWpFLaDgUqT3f", | ||
"isValid": false | ||
@@ -39,7 +40,7 @@ }; | ||
it('Should create an entry object from a buffer', function () { | ||
var entry = new SimplifiedMNListEntry(Buffer.from(smlEntryHex, 'hex')); | ||
var entry = new SimplifiedMNListEntry(Buffer.from(smlEntryHex, 'hex'), Networks.testnet); | ||
expect(entry.toObject()).to.be.deep.equal(smlEntryJSON); | ||
}); | ||
it('Should create an entry object from a hex string', function () { | ||
var entry = new SimplifiedMNListEntry(smlEntryHex); | ||
var entry = new SimplifiedMNListEntry(smlEntryHex, Networks.testnet); | ||
expect(entry.toObject()).to.be.deep.equal(smlEntryJSON); | ||
@@ -50,6 +51,6 @@ }); | ||
var entry2 = new SimplifiedMNListEntry(entry1); | ||
entry1.keyIDVoting = 'something'; | ||
entry1.votingAddress = 'something'; | ||
expect(entry2.toObject()).to.be.deep.equal(smlEntryJSON); | ||
expect(entry1.keyIDVoting).to.be.equal('something'); | ||
expect(entry2.keyIDVoting).to.be.equal('68976be39d5ef1d43761123f497c96cf4226da87'); | ||
expect(entry1.votingAddress).to.be.equal('something'); | ||
expect(entry2.votingAddress).to.be.equal('yYhmQPak2w5L8KSwVw9R5wpqzPbAJ1fK7v'); | ||
}); | ||
@@ -59,3 +60,3 @@ }); | ||
it('Should be able to parse data from a buffer when ip address is present', function () { | ||
var entry = SimplifiedMNListEntry.fromBuffer(Buffer.from(smlEntryHex, 'hex')); | ||
var entry = SimplifiedMNListEntry.fromBuffer(Buffer.from(smlEntryHex, 'hex'), Networks.testnet); | ||
var entryJSON = entry.toObject(); | ||
@@ -65,3 +66,3 @@ expect(entryJSON).to.be.deep.equal(smlEntryJSON); | ||
it('Should be able to parse data from a buffer when ip address is not present', function () { | ||
var entry = SimplifiedMNListEntry.fromBuffer(Buffer.from(smlEntryHex, 'hex')); | ||
var entry = SimplifiedMNListEntry.fromBuffer(Buffer.from(smlEntryHex, 'hex'), Networks.testnet); | ||
var entryJSON = entry.toObject(); | ||
@@ -106,3 +107,3 @@ expect(entryJSON).to.be.deep.equal(smlEntryJSON); | ||
it('Should serialize SMLEntry to JSON object', function () { | ||
var entry = new SimplifiedMNListEntry(smlEntryHex); | ||
var entry = new SimplifiedMNListEntry(smlEntryHex, Networks.testnet); | ||
@@ -114,3 +115,3 @@ expect(entry.toObject()).to.be.deep.equal(smlEntryJSON); | ||
it('Should be able to create an entry from a hex string', function () { | ||
var entry = SimplifiedMNListEntry.fromHexString(smlEntryHex); | ||
var entry = SimplifiedMNListEntry.fromHexString(smlEntryHex, Networks.testnet); | ||
@@ -117,0 +118,0 @@ expect(entry.toObject()).to.be.deep.equal(smlEntryJSON); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6027803
100327