cc-assetid-encoder
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -1,46 +0,145 @@ | ||
var cs = require('coinstring') | ||
var bitcoin = require('bitcoinjs-lib') | ||
var bs58check = require('bs58check') | ||
var hash = require('crypto-hashing') | ||
var UNLOCKEPADDING = 0xc8 | ||
var LOCKEPADDING = 0x8e | ||
var NETWORKVERSIONS = [0x00, 0x05, 0x6f, 0xc4] | ||
var debug = require('debug')('assetIdEncoder') | ||
var UNLOCKEPADDING = { | ||
aggregatable: 0x2e37, | ||
hybrid: 0x2e6b, | ||
dispersed: 0x2e4e | ||
} | ||
var LOCKEPADDING = { | ||
aggregatable: 0x20ce, | ||
hybrid: 0x2102, | ||
dispersed: 0x20e4 | ||
} | ||
var BTC_P2PKH = 0x00 | ||
var BTC_TESTNET_P2PKH = 0x6f | ||
var BTC_P2SH = 0x05 | ||
var BTC_TESTNET_P2SH = 0xc4 | ||
var NETWORKVERSIONS = [BTC_P2PKH, BTC_TESTNET_P2PKH, BTC_P2SH, BTC_TESTNET_P2SH] | ||
var POSTFIXBYTELENGTH = 2 | ||
var padLeadingZeros = function (hex, byteSize) { | ||
if (!byteSize) { | ||
byteSize = Math.ceil(hex.length / 2) | ||
} | ||
return (hex.length === byteSize * 2) ? hex : padLeadingZeros('0' + hex, byteSize) | ||
} | ||
var createId = function (publicKey, padding, divisibility) { | ||
divisibility = divisibility || 0 | ||
divisibility = new Buffer(padLeadingZeros(divisibility.toString(16), POSTFIXBYTELENGTH), 'hex') | ||
if (!Buffer.isBuffer(publicKey)) { | ||
publicKey = new Buffer(publicKey, 'hex') | ||
var createIdFromTxidIndex = function (txid, index, padding, divisibility) { | ||
debug('createIdFromTxidIndex') | ||
debug('txid = ', txid, ', index = ', index) | ||
var str = txid + ':' + index | ||
return hashAndBase58CheckEncode(str, padding, divisibility) | ||
} | ||
var createIdFromPreviousOutputScriptPubKey = function (previousOutputHex, padding, divisibility) { | ||
var buffer = new Buffer(previousOutputHex, 'hex') | ||
debug('buffer = ', buffer) | ||
return hashAndBase58CheckEncode(buffer, padding, divisibility) | ||
} | ||
var createIdFromPubKeyHashInput = function (scriptSig, padding, divisibility) { | ||
debug('createIdFromPubKeyHashInput') | ||
if (!scriptSig.asm) { | ||
scriptSig.asm = bitcoin.script.toASM(scriptSig.hex) | ||
} | ||
var publicKey = scriptSig.asm.split(' ')[1] | ||
debug('publicKey = ', publicKey) | ||
publicKey = new Buffer(publicKey, 'hex') | ||
var hash256 = hash.sha256(publicKey) | ||
var hash160 = hash.ripemd160(hash256) | ||
var hash160Buf = new Buffer(hash160, 'hex') | ||
hash160Buf = Buffer.concat([hash160Buf, divisibility]) | ||
return cs.encode(hash160Buf, padding) | ||
var pubKeyHash = hash.ripemd160(hash256) | ||
debug('pubKeyHash = ', pubKeyHash) | ||
var pubKeyHashOutput = bitcoin.script.pubKeyHashOutput(pubKeyHash) | ||
debug('pubKeyHashOutput = ', pubKeyHashOutput) | ||
return hashAndBase58CheckEncode(pubKeyHashOutput, padding, divisibility) | ||
} | ||
var createIdFromScriptHashInput = function (scriptSig, padding, divisibility) { | ||
debug('createIdFromScriptHashInput') | ||
var buffer = new Buffer(scriptSig.hex, 'hex') | ||
debug('buffer = ', buffer) | ||
var chunks = bitcoin.script.decompile(buffer) | ||
var lastChunk = chunks[chunks.length - 1] | ||
debug('lastChunk = ', lastChunk) | ||
var redeemScriptChunks = bitcoin.script.decompile(lastChunk) | ||
redeemScriptChunks = redeemScriptChunks.map(function (chunk) { return Buffer.isBuffer(chunk) ? chunk : new Buffer(chunk.toString(16), 'hex') }) | ||
var redeemScript = Buffer.concat(redeemScriptChunks) | ||
debug('redeemScript = ', redeemScript) | ||
var hash256 = hash.sha256(redeemScript) | ||
var scriptHash = hash.ripemd160(hash256) | ||
var scriptHashOutput = bitcoin.script.scriptHashOutput(scriptHash) | ||
return hashAndBase58CheckEncode(scriptHashOutput, padding, divisibility) | ||
} | ||
var createIdFromAddress = function (address, padding, divisibility) { | ||
divisibility = divisibility || 0 | ||
debug('createIdFromAddress') | ||
var addressBuffer = bs58check.decode(address) | ||
var versionBuffer = addressBuffer.slice(0, 1) | ||
var version = parseInt(versionBuffer.toString('hex'), 16) | ||
debug('version = ', version) | ||
if (NETWORKVERSIONS.indexOf(version) === -1) throw new Error('Unrecognized address network') | ||
if (version === BTC_P2SH || version === BTC_TESTNET_P2SH) { | ||
var scriptHash = addressBuffer.slice(versionBuffer.length, 21) | ||
var scriptHashOutput = bitcoin.script.scriptHashOutput(scriptHash) | ||
debug('scriptHashOutput = ', scriptHashOutput) | ||
return hashAndBase58CheckEncode(scriptHashOutput, padding, divisibility) | ||
} | ||
if (version === BTC_P2PKH || version === BTC_TESTNET_P2PKH) { | ||
var pubKeyHash = addressBuffer.slice(versionBuffer.length, 21) | ||
var pubKeyHashOutput = bitcoin.script.pubKeyHashOutput(pubKeyHash) | ||
debug('pubKeyHashOutput = ', pubKeyHashOutput) | ||
return hashAndBase58CheckEncode(pubKeyHashOutput, padding, divisibility) | ||
} | ||
} | ||
var hashAndBase58CheckEncode = function (payloadToHash, padding, divisibility) { | ||
debug('hashAndBase58CheckEncode') | ||
debug('padding and divisibility = ' + padding.toString(16) + ', ' + divisibility) | ||
var hash256 = hash.sha256(payloadToHash) | ||
var hash160 = hash.ripemd160(hash256) | ||
debug('hash160 = ', hash160) | ||
padding = new Buffer(padLeadingZeros(padding.toString(16)), 'hex') | ||
divisibility = new Buffer(padLeadingZeros(divisibility.toString(16), POSTFIXBYTELENGTH), 'hex') | ||
address = cs.decode(address) | ||
var version = address.slice(0, 1) | ||
// if (version[0] === 4) version = address.slice(0, 4) | ||
var hash160Buf = address.slice(version.length, 21) | ||
if (NETWORKVERSIONS.indexOf(parseInt(version.toString('hex'), 16)) === -1) throw new Error('Unrecognized address network') | ||
hash160Buf = Buffer.concat([hash160Buf, divisibility]) | ||
return cs.encode(hash160Buf, padding) | ||
var concatenation = Buffer.concat([padding, hash160, divisibility]) | ||
return bs58check.encode(concatenation) | ||
} | ||
module.exports = function (bitcoinTransaction) { | ||
if (!bitcoinTransaction.cc_data) throw new Error('Missing Colored Coin Metadata') | ||
if (bitcoinTransaction.cc_data[0].type !== 'issuance') throw new Error('Not An issuance transaction') | ||
if (typeof bitcoinTransaction.cc_data[0].lockStatus === 'undefined') throw new Error('Missing Lock Status data') | ||
var lockStatus = bitcoinTransaction.cc_data[0].lockStatus | ||
debug('bitcoinTransaction.txid = ', bitcoinTransaction.txid) | ||
if (!bitcoinTransaction.ccdata) throw new Error('Missing Colored Coin Metadata') | ||
if (bitcoinTransaction.ccdata[0].type !== 'issuance') throw new Error('Not An issuance transaction') | ||
if (typeof bitcoinTransaction.ccdata[0].lockStatus === 'undefined') throw new Error('Missing Lock Status data') | ||
var lockStatus = bitcoinTransaction.ccdata[0].lockStatus | ||
var aggregationPolicy = bitcoinTransaction.ccdata[0].aggregationPolicy || 'aggregatable' | ||
var divisibility = bitcoinTransaction.ccdata[0].divisibility || 0 | ||
var firstInput = bitcoinTransaction.vin[0] | ||
if (lockStatus) return createId(firstInput.txid + '-' + firstInput.vout, LOCKEPADDING, bitcoinTransaction.cc_data[0].divisibility) | ||
if (firstInput.scriptSig && firstInput.scriptSig.asm) return createId(firstInput.scriptSig.asm.split(' ')[1], UNLOCKEPADDING, bitcoinTransaction.cc_data[0].divisibility) | ||
if (firstInput.address) return createIdFromAddress(firstInput.address, UNLOCKEPADDING, bitcoinTransaction.cc_data[0].divisibility) | ||
} | ||
var padding | ||
if (lockStatus) { | ||
padding = LOCKEPADDING[aggregationPolicy] | ||
return createIdFromTxidIndex(firstInput.txid, firstInput.vout, padding, divisibility) | ||
} | ||
padding = UNLOCKEPADDING[aggregationPolicy] | ||
if (firstInput.previousOutput && firstInput.previousOutput.hex) { | ||
return createIdFromPreviousOutputScriptPubKey(firstInput.previousOutput.hex, padding, divisibility) | ||
} | ||
if (firstInput.scriptSig && (firstInput.scriptSig.hex || firstInput.scriptSig.asm)) { | ||
var scriptSig = firstInput.scriptSig | ||
scriptSig.hex = scriptSig.hex || bitcoin.script.fromASM(scriptSig.asm) | ||
debug('scriptSig.hex = ', scriptSig.hex) | ||
var buffer = Buffer.isBuffer(scriptSig.hex) ? scriptSig.hex : new Buffer(scriptSig.hex, 'hex') | ||
var type = bitcoin.script.classifyInput(buffer) | ||
if (type === 'pubkeyhash') { | ||
return createIdFromPubKeyHashInput(scriptSig, padding, divisibility) | ||
} | ||
if (type === 'scripthash') { | ||
return createIdFromScriptHashInput(scriptSig, padding, divisibility) | ||
} | ||
} | ||
if (firstInput.address) { | ||
return createIdFromAddress(firstInput.address, padding, divisibility) | ||
} | ||
} |
{ | ||
"name": "cc-assetid-encoder", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Creates an Asset Id for Issuance transaction", | ||
@@ -26,5 +26,7 @@ "main": "assetIdEncoder.js", | ||
"dependencies": { | ||
"coinstring": "2.3.0", | ||
"crypto-hashing": "0.3.1" | ||
"bitcoinjs-lib": "2.2.0", | ||
"bs58check": "1.0.8", | ||
"crypto-hashing": "0.3.1", | ||
"debug": "2.2.0" | ||
} | ||
} |
478
test/test.js
@@ -1,203 +0,337 @@ | ||
var assetId = require(__dirname + '/../assetIdEncoder') | ||
/* eslint-env mocha */ | ||
var path = require('path') | ||
var assetIdEncoder = require(path.join(__dirname, '/../assetIdEncoder')) | ||
var assert = require('assert') | ||
var assetId1, assetId2, assetId3 | ||
describe('Test Issuance decoder', function () { | ||
var bitcoinTransaction = { | ||
'txid': 'bc1083ff98873050d2fa9d38823057f0125161ecad43ab2e2dcd1dd3c2668fb7', | ||
'cc_data': [{ | ||
'protocol': 17219, | ||
'version': 1, | ||
'type': 'issuance', | ||
'lockStatus': false, | ||
'divisibility': 3, | ||
'amount': 1, | ||
'payments': [{ | ||
'input': 0, | ||
'amount': 1, | ||
'output': 0, | ||
'range': false, | ||
'percent': false | ||
}] | ||
}], | ||
'iosparsed': false, | ||
'time': null, | ||
'blockheight': -1, | ||
'blocktime': null, | ||
'vout': [{ | ||
'value': 600, | ||
'n': 0, | ||
'scriptPubKey': { | ||
'asm': 'OP_DUP OP_HASH160 5c7432e747af0d7e8f60de97d5ddd30ec1d9c726 OP_EQUALVERIFY OP_CHECKSIG', | ||
'hex': '76a9145c7432e747af0d7e8f60de97d5ddd30ec1d9c72688ac', | ||
'reqSigs': 1, | ||
'type': 'pubkeyhash', | ||
'addresses': ['mowofLeEYcoxdneKmy2mkLyVLDr3yoHbdt'] | ||
} | ||
}, { | ||
'value': 0, | ||
'n': 1, | ||
'scriptPubKey': { | ||
'asm': 'OP_RETURN 4343010501000100', | ||
'hex': '6a084343010501000100', | ||
'type': 'nulldata', | ||
'addresses': [] | ||
} | ||
}, { | ||
'value': 67996800, | ||
'n': 2, | ||
'scriptPubKey': { | ||
'asm': 'OP_DUP OP_HASH160 b8df2b3d4ca896915875afeda7730be816559df6 OP_EQUALVERIFY OP_CHECKSIG', | ||
'hex': '76a914b8df2b3d4ca896915875afeda7730be816559df688ac', | ||
'reqSigs': 1, | ||
'type': 'pubkeyhash', | ||
'addresses': ['mxNTyQ3WdFMQE7SGVpSQGXnSDevGMLq7dg'] | ||
} | ||
}], | ||
'vin': [{ | ||
'txid': '0f45f38a8bcd8331877267e0f3f5f8a4b3c716165e40db4eee34d52759ad954f', | ||
'vout': 2, | ||
'sequence': 4294967295.0, | ||
'value': 67998400, | ||
'fixed': true, | ||
'addresses': ['mxNTyQ3WdFMQE7SGVpSQGXnSDevGMLq7dg'], | ||
'scriptSig': { | ||
'asm': '3045022100daf8f8d65ea908a28d90f700dc932ecb3b68f402b04ba92f987e8abd7080fcad02205ce81b698b8013b86813c9edafc9e79997610626c9dd1bfb49f60abee9daa43801 029b622e5f0f87f2be9f23c4d82f818a73e258a11c26f01f73c8b595042507a574', | ||
'hex': '483045022100daf8f8d65ea908a28d90f700dc932ecb3b68f402b04ba92f987e8abd7080fcad02205ce81b698b8013b86813c9edafc9e79997610626c9dd1bfb49f60abee9daa4380121029b622e5f0f87f2be9f23c4d82f818a73e258a11c26f01f73c8b595042507a574' | ||
} | ||
}], | ||
'version': 1, | ||
'hex': '01000000014f95ad5927d534ee4edb405e1616c7b3a4f8f5f3e06772873183cd8b8af3450f020000006b483045022100daf8f8d65ea908a28d90f700dc932ecb3b68f402b04ba92f987e8abd7080fcad02205ce81b698b8013b86813c9edafc9e79997610626c9dd1bfb49f60abee9daa4380121029b622e5f0f87f2be9f23c4d82f818a73e258a11c26f01f73c8b595042507a574ffffffff0358020000000000001976a9145c7432e747af0d7e8f60de97d5ddd30ec1d9c72688ac00000000000000000a6a084343010501000100808c0d04000000001976a914b8df2b3d4ca896915875afeda7730be816559df688ac00000000' | ||
} | ||
it('should return Unlocked asset ID from scriptSig.asm', function (done) { | ||
assetId1 = assetId(bitcoinTransaction) | ||
assert.equal(assetId1[0], 'U', 'Should be Unlocked') | ||
// console.log(assetId(bitcoinTransaction)) | ||
done() | ||
}) | ||
describe('Test asset ID encoder', function () { | ||
describe('1st input pubkeyhash', function () { | ||
var assetId | ||
var bitcoinTransaction = { | ||
'txid': 'bc1083ff98873050d2fa9d38823057f0125161ecad43ab2e2dcd1dd3c2668fb7', | ||
'ccdata': [{ | ||
'protocol': 17219, | ||
'version': 1, | ||
'type': 'issuance', | ||
'lockStatus': true, | ||
'aggregationPolicy': 'aggregatable', | ||
'divisibility': 3, | ||
'amount': 1, | ||
'payments': [{ | ||
'input': 0, | ||
'amount': 1, | ||
'output': 0, | ||
'range': false, | ||
'percent': false | ||
}] | ||
}], | ||
'time': null, | ||
'vout': [ | ||
{ | ||
'value': 600, | ||
'n': 0 | ||
}, | ||
{ | ||
'value': 0, | ||
'n': 1 | ||
}, | ||
{ | ||
'value': 67996800, | ||
'n': 2 | ||
} | ||
], | ||
'vin': [{ | ||
'txid': '0f45f38a8bcd8331877267e0f3f5f8a4b3c716165e40db4eee34d52759ad954f', | ||
'vout': 2, | ||
'value': 67998400, | ||
'addresses': ['mxNTyQ3WdFMQE7SGVpSQGXnSDevGMLq7dg'], | ||
'scriptSig': { | ||
'asm': '3045022100daf8f8d65ea908a28d90f700dc932ecb3b68f402b04ba92f987e8abd7080fcad02205ce81b698b8013b86813c9edafc9e79997610626c9dd1bfb49f60abee9daa43801 029b622e5f0f87f2be9f23c4d82f818a73e258a11c26f01f73c8b595042507a574', | ||
'hex': '483045022100daf8f8d65ea908a28d90f700dc932ecb3b68f402b04ba92f987e8abd7080fcad02205ce81b698b8013b86813c9edafc9e79997610626c9dd1bfb49f60abee9daa4380121029b622e5f0f87f2be9f23c4d82f818a73e258a11c26f01f73c8b595042507a574' | ||
} | ||
}] | ||
} | ||
it('should return Locked asset ID', function (done) { | ||
bitcoinTransaction.cc_data[0].lockStatus = true | ||
assetId2 = assetId(bitcoinTransaction) | ||
assert.equal(assetId2[0], 'L', 'Should be Locked') | ||
// console.log(assetId(bitcoinTransaction)) | ||
done() | ||
it('should return correct locked aggregatable asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'aggregatable' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'La8kMVUzB9RT2GGKpkpuWJgp1oTPVheheTjMi6') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct locked hybrid asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'hybrid' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'LhANhrERyCPXq5b4ZC92LtYSdJ8Xbsu18G1pHy') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct locked dispersed asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ld7CtQsq1dSsN54B8i9j1nPtMHCiYKDXDZ6YBq') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked aggregatable asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].lockStatus = false | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'aggregatable' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ua3Kt8WJtsx61VC8DUJiRmseQ45NfW2eJXbbE8') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked hybrid asset ID from scriptSig.asm', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'hybrid' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Uh4xEVFkgvvApJWrwucqGMjH1YkWmgGwizurnM') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked dispersed asset ID from scriptSig.asm', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ud9d5N9NVkLfNCCc3ExquxPQUbimDEV3ctXUKS') | ||
console.log(assetId) | ||
done() | ||
}) | ||
}) | ||
it('should return Unlocked asset ID from testnet address', function (done) { | ||
bitcoinTransaction = { | ||
cc_data: | ||
[{ | ||
type: 'issuance', | ||
lockStatus: false, | ||
divisibility: 3 | ||
}], | ||
vin: | ||
[{ txid: '095d3352d3c54b435d833be5d78016e3daa49b137a20c2941ed80214b519ecbe', | ||
describe('1st input scripthash', function () { | ||
var bitcoinTransaction = { | ||
ccdata: [{ | ||
type: 'issuance', | ||
aggregationPolicy: 'aggregatable', | ||
divisibility: 3, | ||
lockStatus: true | ||
}], | ||
vin: [{ | ||
txid: '0f45f38a8bcd8331877267e0f3f5f8a4b3c716165e40db4eee34d52759ad954f', | ||
vout: 2, | ||
address: 'mxNTyQ3WdFMQE7SGVpSQGXnSDevGMLq7dg' | ||
scriptSig: { | ||
hex: '0047304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801483045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d14050147522102359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1210395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a52ae', | ||
asm: 'OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501 522102359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1210395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a52ae' | ||
} | ||
}] | ||
} | ||
assetId3 = assetId(bitcoinTransaction) | ||
assert.equal(assetId3[0], 'U', 'Should be Unlocked') | ||
assert.equal(assetId3, assetId1, 'Should get the same assetId from public key or asset') | ||
// console.log(assetId(bitcoinTransaction)) | ||
done() | ||
var assetId | ||
it('should return correct locked aggregatable asset ID', function (done) { | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'La8kMVUzB9RT2GGKpkpuWJgp1oTPVheheTjMi6') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct locked hybrid asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'hybrid' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'LhANhrERyCPXq5b4ZC92LtYSdJ8Xbsu18G1pHy') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct locked dispersed asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ld7CtQsq1dSsN54B8i9j1nPtMHCiYKDXDZ6YBq') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked aggregatable asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'aggregatable' | ||
bitcoinTransaction.ccdata[0].lockStatus = false | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ua3gB6zfKRDzNHoQ9V84V7K2zkYmjKnr77D2rk') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked hybrid asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'hybrid' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Uh5JXTk77UC5B788svSBKhAfcFDuqW39Z36n5Z') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked dispersed asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ud9yNLdivHcZizosyFnByHpo5JCAH4FFUyFSTo') | ||
console.log(assetId) | ||
done() | ||
}) | ||
}) | ||
it('should return Unrecognized address network Error', function (done) { | ||
bitcoinTransaction = { | ||
cc_data: | ||
[{ | ||
type: 'issuance', | ||
lockStatus: false | ||
}], | ||
vin: | ||
[{ txid: '095d3352d3c54b435d833be5d78016e3daa49b137a20c2941ed80214b519ecbe', | ||
describe('1st input multisig, create asset ID from previousOutput.hex', function () { | ||
var bitcoinTransaction = { | ||
ccdata: [{ | ||
type: 'issuance', | ||
aggregationPolicy: 'aggregatable', | ||
divisibility: 3, | ||
lockStatus: false | ||
}], | ||
vin: [{ | ||
txid: '0f45f38a8bcd8331877267e0f3f5f8a4b3c716165e40db4eee34d52759ad954f', | ||
vout: 2, | ||
address: 'fxNTyQ3WdFMQE7SGVpSQGXnSDevGMLq7dg' | ||
scriptSig: { | ||
asm: 'OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501', | ||
hex: '0047304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801483045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501' | ||
}, | ||
previousOutput: { | ||
hex: '76a914ee54bdd81113a2a8f02cd0dcdd1fa8b14c523fd988ac' | ||
} | ||
}] | ||
} | ||
assert.throws(function () { | ||
assetId(bitcoinTransaction) | ||
} | ||
, 'Unrecognized address network' | ||
, 'Unrecognized address network') | ||
done() | ||
var assetId | ||
it('should return correct unlocked aggregatable asset ID', function (done) { | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ua9CgfGFKCVRdV4aUj4hYz2XtxCg4Smpu8TVAQ') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked hybrid asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'hybrid' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'UhAq321h7FTWSJPKDANpPZtAWSspAd28P59scH') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked dispersed asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'UdFVstuJv4szzC54JViq3AYHyVr4cBEEEdCFyB') | ||
console.log(assetId) | ||
done() | ||
}) | ||
}) | ||
it('should return Unlocked asset ID from mainnet address', function (done) { | ||
bitcoinTransaction = { | ||
cc_data: | ||
[{ | ||
type: 'issuance', | ||
lockStatus: false | ||
}], | ||
vin: | ||
[{ txid: '095d3352d3c54b435d833be5d78016e3daa49b137a20c2941ed80214b519ecbe', | ||
describe('create assetID from address', function () { | ||
var bitcoinTransaction = { | ||
ccdata: [{ | ||
type: 'issuance', | ||
aggregationPolicy: 'aggregatable', | ||
divisibility: 3, | ||
lockStatus: false | ||
}], | ||
vin: [{ | ||
txid: '0f45f38a8bcd8331877267e0f3f5f8a4b3c716165e40db4eee34d52759ad954f', | ||
vout: 2, | ||
address: '1PuKhp9CmFL9Xs2apKKeTAtLoZPcvoikE1' | ||
address: 'mxNTyQ3WdFMQE7SGVpSQGXnSDevGMLq7dg' | ||
}] | ||
} | ||
assetId3 = assetId(bitcoinTransaction) | ||
assert.equal(assetId3[0], 'U', 'Should be Unlocked') | ||
// console.log(assetId3) | ||
done() | ||
var assetId | ||
it('should return correct unlocked aggregatable asset ID', function (done) { | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ua3Kt8WJtsx61VC8DUJiRmseQ45NfW2eJXbbE8') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked hybrid asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'hybrid' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Uh4xEVFkgvvApJWrwucqGMjH1YkWmgGwizurnM') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked dispersed asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ud9d5N9NVkLfNCCc3ExquxPQUbimDEV3ctXUKS') | ||
console.log(assetId) | ||
done() | ||
}) | ||
}) | ||
it('should return Unlocked asset ID from mainnet script address', function (done) { | ||
bitcoinTransaction = { | ||
cc_data: | ||
[{ | ||
type: 'issuance', | ||
lockStatus: false | ||
}], | ||
vin: | ||
[{ txid: '095d3352d3c54b435d833be5d78016e3daa49b137a20c2941ed80214b519ecbe', | ||
describe('create assetID from pay-to-scripthash address', function () { | ||
var bitcoinTransaction = { | ||
ccdata: [{ | ||
type: 'issuance', | ||
aggregationPolicy: 'aggregatable', | ||
divisibility: 3, | ||
lockStatus: false | ||
}], | ||
vin: [{ | ||
txid: '0f45f38a8bcd8331877267e0f3f5f8a4b3c716165e40db4eee34d52759ad954f', | ||
vout: 2, | ||
address: '3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX' | ||
address: '3P14159f73E4gFr7JterCCQh9QjiTjiZrG' | ||
}] | ||
} | ||
assetId3 = assetId(bitcoinTransaction) | ||
assert.equal(assetId3[0], 'U', 'Should be Unlocked') | ||
// console.log(assetId3) | ||
done() | ||
}) | ||
var assetId | ||
it('should return Locked asset ID', function (done) { | ||
bitcoinTransaction = { | ||
'cc_data': [{ | ||
'type': 'issuance', | ||
'lockStatus': true | ||
}], | ||
'vin': [{ | ||
'txid': '0f45f38a8bcd8331877267e0f3f5f8a4b3c716165e40db4eee34d52759ad954f', | ||
'vout': 2 | ||
}] | ||
} | ||
assetId3 = assetId(bitcoinTransaction) | ||
assert.equal(assetId3[0], 'L', 'Should be Locked') | ||
// console.log(assetId3) | ||
done() | ||
it('should return correct unlocked aggregatable asset ID', function (done) { | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Ua7LQe4WHDZooow4exMVDqGhM47FWnBxbN8j35') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked hybrid asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'hybrid' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'Uh8xkzox5GXtcdFoPPfc4R8KxYnPcxSFzbdQr1') | ||
console.log(assetId) | ||
done() | ||
}) | ||
it('should return correct unlocked dispersed asset ID', function (done) { | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'UdDdbshZt5xPAWwYUj1ci1nTRbke4WeMseyejd') | ||
console.log(assetId) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('should return Unlocked asset ID from testnet script address', function (done) { | ||
bitcoinTransaction = { | ||
cc_data: | ||
[{ | ||
type: 'issuance', | ||
lockStatus: false | ||
}], | ||
vin: | ||
[{ txid: '095d3352d3c54b435d833be5d78016e3daa49b137a20c2941ed80214b519ecbe', | ||
vout: 2, | ||
address: '2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc' | ||
describe('create assetID from scriptSig.asm', function () { | ||
it('should return the right asset ID', function (done) { | ||
var bitcoinTransaction = { | ||
'vin': [ | ||
{ | ||
'scriptSig': { | ||
'asm': '3045022100b5aaae72b05c0698ea22e2f4cb3f3a46e5a0a1c1a98772b1c7305476b9ae5e1f02200276a003694eab8d12bc5791624b60b1c68486e4b985f2a672751bb35295202b01 02b509613c7e5d9e47347635f872c3aa271d01ac4a9a6445839ce2c5820a0f48a8' | ||
} | ||
} | ||
], | ||
'ccdata': [{ | ||
'payments': [ | ||
{ | ||
'input': 0, | ||
'amount': 26, | ||
'output': 0, | ||
'range': false, | ||
'precent': false | ||
} | ||
], | ||
'protocol': 17219, | ||
'version': 2, | ||
'type': 'issuance', | ||
'lockStatus': false, | ||
'aggregationPolicy': 'dispersed', | ||
'divisibility': 2, | ||
'amount': 26, | ||
'multiSig': [], | ||
'torrentHash': 'd36854c461e1ce4d90dd73857ae9fa5349f6ba4a', | ||
'sha2': 'da9f9603314dcbc0225f39b9313b7d67a5059e00e0b179e01cf8f879eaaa7fa3' | ||
}] | ||
} | ||
assetId3 = assetId(bitcoinTransaction) | ||
assert.equal(assetId3[0], 'U', 'Should be Unlocked') | ||
// console.log(assetId3) | ||
bitcoinTransaction.ccdata[0].aggregationPolicy = 'dispersed' | ||
var assetId = assetIdEncoder(bitcoinTransaction) | ||
assert.equal(assetId, 'UdDszTzN2NV4frsfVeXQKDiTZMbRvMqDfK6KF4') | ||
console.log(assetId) | ||
done() | ||
}) | ||
}) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
25192
447
4
+ Addedbitcoinjs-lib@2.2.0
+ Addedbs58check@1.0.8
+ Addeddebug@2.2.0
+ Addedbigi@1.4.2(transitive)
+ Addedbip66@1.1.5(transitive)
+ Addedbitcoinjs-lib@2.2.0(transitive)
+ Addedbs58check@1.0.8(transitive)
+ Addedbuffer-compare@1.1.1(transitive)
+ Addedbuffer-equals@1.0.4(transitive)
+ Addedbuffer-reverse@1.0.1(transitive)
+ Addedcreate-hmac@1.1.7(transitive)
+ Addeddebug@2.2.0(transitive)
+ Addedecurve@1.0.6(transitive)
+ Addedms@0.7.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedtypeforce@1.18.0(transitive)
+ Addedwif@1.2.1(transitive)
- Removedcoinstring@2.3.0
- Removedcoinstring@2.3.0(transitive)