Socket
Socket
Sign inDemoInstall

bitcore

Package Overview
Dependencies
Maintainers
2
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore - npm Package Compare versions

Comparing version 0.12.14 to 0.12.15

lib/transaction/#output.js#

2

bower.json
{
"name": "bitcore",
"main": "./bitcore.min.js",
"version": "0.12.14",
"version": "0.12.15",
"homepage": "http://bitcore.io",

@@ -6,0 +6,0 @@ "authors": [

@@ -5,3 +5,3 @@ # Bitcore v0.12

Bitcoin is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Bitcoin network allows for highly resilient bitcoin infrastructure, and the developer community needs reliable, open-source tools to implement bitcoin apps and services. Bitcore provides a reliable API for javascript apps that need to interface with Bitcoin.
Bitcoin is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Bitcoin network allows for highly resilient bitcoin infrastructure, and the developer community needs reliable, open-source tools to implement bitcoin apps and services. Bitcore provides a reliable API for JavaScript apps that need to interface with Bitcoin.

@@ -8,0 +8,0 @@ To get started, just `npm install bitcore` or `bower install bitcore`.

@@ -146,3 +146,3 @@ ---

* `toObject`: Returns a plain javascript object with no methods and enough information to fully restore the state of this transaction. Using other serialization methods (except for `toJSON`) will cause a some information to be lost.
* `toObject`: Returns a plain JavaScript object with no methods and enough information to fully restore the state of this transaction. Using other serialization methods (except for `toJSON`) will cause a some information to be lost.
* `toJSON`: Returns a string with a JSON-encoded version of the output for `toObject`.

@@ -149,0 +149,0 @@ * `toString` or `uncheckedSerialize`: Returns an hexadecimal serialization of the transaction, in the [serialization format for bitcoin](https://bitcoin.org/en/developer-reference#raw-transaction-format).

@@ -65,3 +65,3 @@ 'use strict';

/**
* @param {Object} - A plain javascript object
* @param {Object} - A plain JavaScript object
* @returns {Object} - An object representing block data

@@ -96,3 +96,3 @@ * @private

/**
* @param {Object} - A plain javascript object
* @param {Object} - A plain JavaScript object
* @returns {Block} - An instance of block

@@ -99,0 +99,0 @@ */

@@ -96,3 +96,3 @@ 'use strict';

/**
* @param {Object} - A plain javascript object
* @param {Object} - A plain JavaScript object
* @returns {BlockHeader} - An instance of block header

@@ -99,0 +99,0 @@ */

@@ -31,3 +31,3 @@ 'use strict';

name: 'AbstractMethodInvoked',
message: 'Abstract Method Invokation: {0}'
message: 'Abstract Method Invocation: {0}'
}, {

@@ -34,0 +34,0 @@ name: 'InvalidArgumentType',

@@ -394,3 +394,3 @@ 'use strict';

/**
* Returns a plain javascript object with information to reconstruct a key.
* Returns a plain JavaScript object with information to reconstruct a key.
*

@@ -397,0 +397,0 @@ * Fields are: <ul>

@@ -134,2 +134,44 @@ 'use strict';

Script.fromASM = function(str) {
var script = new Script();
script.chunks = [];
var tokens = str.split(' ');
var i = 0;
while (i < tokens.length) {
var token = tokens[i];
var opcode = Opcode(token);
var opcodenum = opcode.toNumber();
if (_.isUndefined(opcodenum)) {
var buf = new Buffer(tokens[i], 'hex');
script.chunks.push({
buf: buf,
len: buf.length,
opcodenum: buf.length
});
i = i + 1;
} else if (opcodenum === Opcode.OP_PUSHDATA1 ||
opcodenum === Opcode.OP_PUSHDATA2 ||
opcodenum === Opcode.OP_PUSHDATA4) {
script.chunks.push({
buf: new Buffer(tokens[i + 2], 'hex'),
len: parseInt(tokens[i + 1]),
opcodenum: opcodenum
});
i = i + 3;
} else {
script.chunks.push({
opcodenum: opcodenum
});
i = i + 1;
}
}
return script;
};
Script.fromHex = function(str) {
return new Script(new buffer.Buffer(str, 'hex'));
};
Script.fromString = function(str) {

@@ -183,4 +225,5 @@ if (JSUtil.isHexa(str) || str.length === 0) {

Script.prototype._chunkToString = function(chunk) {
Script.prototype._chunkToString = function(chunk, type) {
var opcodenum = chunk.opcodenum;
var asm = (type === 'asm');
var str = '';

@@ -196,3 +239,7 @@ if (!chunk.buf) {

}
str = str + ' ' + '0x' + numstr;
if (asm) {
str = str + ' ' + numstr;
} else {
str = str + ' ' + '0x' + numstr;
}
}

@@ -206,5 +253,8 @@ } else {

}
str = str + ' ' + chunk.len;
if (chunk.len > 0) {
str = str + ' ' + '0x' + chunk.buf.toString('hex');
if (asm) {
str = str + ' ' + chunk.buf.toString('hex');
} else {
str = str + ' ' + chunk.len + ' ' + '0x' + chunk.buf.toString('hex');
}
}

@@ -215,2 +265,12 @@ }

Script.prototype.toASM = function() {
var str = '';
for (var i = 0; i < this.chunks.length; i++) {
var chunk = this.chunks[i];
str += this._chunkToString(chunk, 'asm');
}
return str.substr(1);
};
Script.prototype.toString = function() {

@@ -275,2 +335,7 @@ var str = '';

Script.prototype.getPublicKey = function() {
$.checkState(this.isPublicKeyOut(), 'Can\'t retreive PublicKey from a non-PK output');
return this.chunks[0].buf;
};
Script.prototype.getPublicKeyHash = function() {

@@ -310,8 +375,13 @@ $.checkState(this.isPublicKeyHashOut(), 'Can\'t retrieve PublicKeyHash from a non-PKH output');

Script.prototype.isPublicKeyIn = function() {
return this.chunks.length === 1 &&
BufferUtil.isBuffer(this.chunks[0].buf) &&
this.chunks[0].buf.length === 0x47;
if (this.chunks.length === 1) {
var signatureBuf = this.chunks[0].buf;
if (signatureBuf &&
signatureBuf.length &&
signatureBuf[0] === 0x30) {
return true;
}
}
return false;
};
/**

@@ -692,8 +762,9 @@ * @returns {boolean} if this is a p2sh output script

* @returns {Script} a new OP_RETURN script with data
* @param {(string|Buffer)} to - the data to embed in the output
* @param {(string|Buffer)} data - the data to embed in the output
* @param {(string)} encoding - the type of encoding of the string
*/
Script.buildDataOut = function(data) {
Script.buildDataOut = function(data, encoding) {
$.checkArgument(_.isUndefined(data) || _.isString(data) || BufferUtil.isBuffer(data));
if (typeof data === 'string') {
data = new Buffer(data);
if (_.isString(data)) {
data = new Buffer(data, encoding);
}

@@ -726,2 +797,22 @@ var s = new Script();

/**
* Builds a scriptSig (a script for an input) that signs a public key output script.
*
* @param {Signature|Buffer} signature - a Signature object, or the signature in DER cannonical encoding
* @param {number=} sigtype - the type of the signature (defaults to SIGHASH_ALL)
*/
Script.buildPublicKeyIn = function(signature, sigtype) {
$.checkArgument(signature instanceof Signature || BufferUtil.isBuffer(signature));
$.checkArgument(_.isUndefined(sigtype) || _.isNumber(sigtype));
if (signature instanceof Signature) {
signature = signature.toBuffer();
}
var script = new Script();
script.add(BufferUtil.concat([
signature,
BufferUtil.integerAsSingleByteBuffer(sigtype || Signature.SIGHASH_ALL)
]));
return script;
};
/**
* Builds a scriptSig (a script for an input) that signs a public key hash

@@ -728,0 +819,0 @@ * output script.

module.exports = require('./input');
module.exports.PublicKey = require('./publickey');
module.exports.PublicKeyHash = require('./publickeyhash');
module.exports.MultiSigScriptHash = require('./multisigscripthash.js');

@@ -44,8 +44,11 @@ 'use strict';

Input.prototype._fromObject = function(params) {
var prevTxId;
if (_.isString(params.prevTxId) && JSUtil.isHexa(params.prevTxId)) {
params.prevTxId = new buffer.Buffer(params.prevTxId, 'hex');
prevTxId = new buffer.Buffer(params.prevTxId, 'hex');
} else {
prevTxId = params.prevTxId;
}
this.output = params.output ?
(params.output instanceof Output ? params.output : new Output(params.output)) : undefined;
this.prevTxId = params.prevTxId || params.txidbuf;
this.prevTxId = prevTxId || params.txidbuf;
this.outputIndex = _.isUndefined(params.outputIndex) ? params.txoutnum : params.outputIndex;

@@ -52,0 +55,0 @@ this.sequenceNumber = _.isUndefined(params.sequenceNumber) ?

@@ -24,6 +24,9 @@ 'use strict';

} else {
var script;
if (_.isString(args.script) && JSUtil.isHexa(args.script)) {
args.script = new buffer.Buffer(args.script, 'hex');
script = new buffer.Buffer(args.script, 'hex');
} else {
script = args.script;
}
this.setScript(args.script);
this.setScript(script);
}

@@ -30,0 +33,0 @@ } else if (JSUtil.isValidJSON(args)) {

@@ -20,2 +20,3 @@ 'use strict';

var PublicKeyHashInput = Input.PublicKeyHash;
var PublicKeyInput = Input.PublicKey;
var MultiSigScriptHashInput = Input.MultiSigScriptHash;

@@ -362,7 +363,7 @@ var Output = require('./output');

}
input.output.script = new Script(input.output.script);
var script = new Script(input.output.script);
var txin;
if (input.output.script.isPublicKeyHashOut()) {
if (script.isPublicKeyHashOut()) {
txin = new Input.PublicKeyHash(input);
} else if (input.output.script.isScriptHashOut() && input.publicKeys && input.threshold) {
} else if (script.isScriptHashOut() && input.publicKeys && input.threshold) {
txin = new Input.MultiSigScriptHash(

@@ -543,2 +544,4 @@ input, input.publicKeys, input.threshold, input.signatures

clazz = PublicKeyHashInput;
} else if (utxo.script.isPublicKeyOut()) {
clazz = PublicKeyInput;
} else {

@@ -545,0 +548,0 @@ clazz = Input;

{
"name": "bitcore",
"version": "0.12.13",
"version": "0.12.15",
"dependencies": {

@@ -5,0 +5,0 @@ "bn.js": {

{
"name": "bitcore",
"version": "0.12.14",
"version": "0.12.15",
"description": "A pure and powerful JavaScript Bitcoin library.",

@@ -5,0 +5,0 @@ "author": "BitPay <dev@bitpay.com>",

@@ -107,3 +107,3 @@ Bitcore

You can also run just the NodeJS tests with `gulp test:node`, just the browser tests with `gulp test:browser`
You can also run just the Node.js tests with `gulp test:node`, just the browser tests with `gulp test:browser`
or create a test coverage report (you can open `coverage/lcov-report/index.html` to visualize it) with `gulp coverage`.

@@ -110,0 +110,0 @@

@@ -162,2 +162,15 @@ 'use strict';

describe('#fromASM', function() {
it('should parse this known script in ASM', function() {
var asm = 'OP_DUP OP_HASH160 f4c03610e60ad15100929cc23da2f3a799af1725 OP_EQUALVERIFY OP_CHECKSIG';
var script = Script.fromASM(asm);
script.chunks[0].opcodenum.should.equal(Opcode.OP_DUP);
script.chunks[1].opcodenum.should.equal(Opcode.OP_HASH160);
script.chunks[2].opcodenum.should.equal(20);
script.chunks[2].buf.toString('hex').should.equal('f4c03610e60ad15100929cc23da2f3a799af1725');
script.chunks[3].opcodenum.should.equal(Opcode.OP_EQUALVERIFY);
script.chunks[4].opcodenum.should.equal(Opcode.OP_CHECKSIG);
});
});
describe('#fromString', function() {

@@ -195,2 +208,7 @@

it('should output this known script as ASM', function() {
var script = Script.fromHex('76a914f4c03610e60ad15100929cc23da2f3a799af172588ac');
script.toASM().should.equal('OP_DUP OP_HASH160 f4c03610e60ad15100929cc23da2f3a799af1725 OP_EQUALVERIFY OP_CHECKSIG');
});
});

@@ -236,2 +254,12 @@

describe('#isPublicKeyIn', function() {
it('correctly identify scriptSig as a public key in', function() {
// from txid: 5c85ed63469aa9971b5d01063dbb8bcdafd412b2f51a3d24abf2e310c028bbf8
// and input index: 5
var scriptBuffer = new Buffer('483045022050eb59c79435c051f45003d9f82865c8e4df5699d7722e77113ef8cadbd92109022100d4ab233e070070eb8e0e62e3d2d2eb9474a5bf135c9eda32755acb0875a6c20601', 'hex');
var script = bitcore.Script.fromBuffer(scriptBuffer);
script.isPublicKeyIn().should.equal(true);
});
});
describe('#isPublicKeyHashIn', function() {

@@ -469,3 +497,3 @@

it('should work for no data OP_RETURN', function() {
Script().add(Opcode.OP_RETURN).add(new Buffer('')).toString().should.equal('OP_RETURN 0');
Script().add(Opcode.OP_RETURN).add(new Buffer('')).toString().should.equal('OP_RETURN');
});

@@ -589,3 +617,3 @@ it('works with objects', function() {

should.exist(s);
s.toString().should.equal('OP_RETURN 0');
s.toString().should.equal('OP_RETURN');
s.isDataOut().should.equal(true);

@@ -607,2 +635,9 @@ });

});
it('should create script from a hex string', function() {
var hexString = 'abcdef0123456789';
var s = Script.buildDataOut(hexString, 'hex');
should.exist(s);
s.toString().should.equal('OP_RETURN 8 0xabcdef0123456789');
s.isDataOut().should.equal(true);
});
});

@@ -609,0 +644,0 @@ describe('#buildScriptHashOut', function() {

@@ -61,6 +61,5 @@ 'use strict';

var input = transaction.inputs[0];
input.getSignatures(transaction, new PrivateKey(), 0);
input.isFullySigned().should.equal(false);
var signatures = input.getSignatures(transaction, new PrivateKey(), 0);
signatures.length.should.equal(0);
});
});

@@ -66,4 +66,6 @@ 'use strict';

it('serialize to Object roundtrip', function() {
new Transaction(testTransaction.toObject()).uncheckedSerialize()
.should.equal(testTransaction.uncheckedSerialize());
var a = testTransaction.toObject();
var newTransaction = new Transaction(a);
var b = newTransaction.toObject();
a.should.deep.equal(b);
});

@@ -70,0 +72,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc