Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
digicontributer committed Jul 6, 2019
1 parent 3b9df14 commit b16bb67
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 11,520 deletions.
289 changes: 165 additions & 124 deletions digibyte.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,10 @@ Address._transformString = function(data, network, type) {
var result = Bech32.decode(data);
var version = result.shift();
var buf = Bech32.fromWords(result);
var info = Address._transformBuffer(Buffer.from(buf), Networks.get(network || 'livenet'), type, Networks.get(network || 'livenet').prefix);
network = Networks.get(data.split('1')[0], 'prefix');
var info = Address._transformBuffer(Buffer.from(buf), network, type, network.prefix);
return info;
} catch (e) {
if(data === 'dgb1qhv27ve0hs94kz3k8ywxwd6522y04pdud3lq74k'){
console.log(Buffer.from(buf).toString('hex'))
}
if (type === Address.PayToWitnessPublicKeyHash || type === Address.PayToWitnessScriptHash) {
return e;
}
Expand Down Expand Up @@ -9623,6 +9621,38 @@ Script.prototype.isPublicKeyHashIn = function() {
return false;
};

/**
* @returns {boolean} if this is a pay to public key hash input script
*/
Script.prototype.isWitnessPublicKeyHashIn = function() {
console.log(this)
if (this.chunks.length === 2) {
var signatureBuf = this.chunks[0].buf;
var pubkeyBuf = this.chunks[1].buf;
console.log(signatureBuf &&
signatureBuf.length &&
signatureBuf[0] === 0x30 &&
pubkeyBuf &&
pubkeyBuf.length);
if (signatureBuf &&
signatureBuf.length &&
signatureBuf[0] === 0x30 &&
pubkeyBuf &&
pubkeyBuf.length
) {
var version = pubkeyBuf[0];
if ((version === 0x04 ||
version === 0x06 ||
version === 0x07) && pubkeyBuf.length === 65) {
return true;
} else if ((version === 0x03 || version === 0x02) && pubkeyBuf.length === 33) {
return true;
}
}
}
return false;
};

Script.prototype.getPublicKey = function() {
$.checkState(this.isPublicKeyOut(), 'Can\'t retrieve PublicKey from a non-PK output');
return this.chunks[0].buf;
Expand Down Expand Up @@ -10613,6 +10643,7 @@ Input.prototype.toObject = Input.prototype.toJSON = function toObject() {
outputIndex: this.outputIndex,
sequenceNumber: this.sequenceNumber,
script: this._scriptBuffer.toString('hex'),
witnesses: this.witnesses
};
// add human readable form if input contains valid script
if (this.script) {
Expand Down Expand Up @@ -11528,6 +11559,11 @@ WitnessPublicKeyHashInput.prototype.getScriptCode = function() {
return writer.toBuffer();
};

WitnessPublicKeyHashInput.prototype.isFullySigned = function() {
return true;
};


module.exports = WitnessPublicKeyHashInput;

}).call(this,require("buffer").Buffer)
Expand Down Expand Up @@ -12743,6 +12779,12 @@ Transaction.prototype.fromObject = function fromObject(arg) {
);
} else if (script.isPublicKeyOut()) {
txin = new Input.PublicKey(input);
} else if (script.isWitnessPublicKeyHashOut()) {
txin = new Input.WitnessPublicKeyHash(input);
} else if (script.isWitnessScriptHashOut()) {
txin = new Input.WitnessScriptHash(
input, input.publicKeys, input.threshold, input.signatures
);
} else {
throw new errors.Transaction.Input.UnsupportedScript(input.output.script);
}
Expand Down Expand Up @@ -13044,7 +13086,6 @@ Transaction.prototype._fromMultisigUtxo = function(utxo, pubkeys, threshold, nes
} else {
throw new Error("@TODO");
}
console.log(clazz, 'class');
this.addInput(new clazz({
output: new Output({
script: utxo.script,
Expand Down Expand Up @@ -13630,13 +13671,13 @@ Transaction.prototype.verify = function() {
if (txout.invalidSatoshis()) {
return 'transaction txout ' + i + ' satoshis is invalid';
}
if (txout._satoshisBN.gt(new BN(Transaction.MAX_MONEY, 10))) {
return 'transaction txout ' + i + ' greater than MAX_MONEY';
}
valueoutbn = valueoutbn.add(txout._satoshisBN);
if (valueoutbn.gt(new BN(Transaction.MAX_MONEY))) {
return 'transaction txout ' + i + ' total output greater than MAX_MONEY';
}
//if (txout._satoshisBN.gt(new BN(Transaction.MAX_MONEY, 10))) {
// return 'transaction txout ' + i + ' greater than MAX_MONEY';
//}
//valueoutbn = valueoutbn.add(txout._satoshisBN);
//if (valueoutbn.gt(new BN(Transaction.MAX_MONEY))) {
// return 'transaction txout ' + i + ' total output greater than MAX_MONEY';
//}
}

// Size limits
Expand Down Expand Up @@ -59406,117 +59447,117 @@ module.exports = safer
}).call(this,require('_process'))
},{"_process":207,"buffer":116}],237:[function(require,module,exports){
(function (Buffer){
var flagMask = 0xe0
var encodingSchemeTable =
[
{
'flag': 0x20,
'exponent': 4,
'byteSize': 2,
'mantis': 9
},
{
'flag': 0x40,
'exponent': 4,
'byteSize': 3,
'mantis': 17
},
{
'flag': 0x60,
'exponent': 4,
'byteSize': 4,
'mantis': 25
},
{
'flag': 0x80,
'exponent': 3,
'byteSize': 5,
'mantis': 34
},
{
'flag': 0xa0,
'exponent': 3,
'byteSize': 6,
'mantis': 42
},
{
'flag': 0xc0,
'exponent': 0,
'byteSize': 7,
'mantis': 54
}
]

var flagLookup = {}
var mantisLookup = {}

for (var i = 0; i < encodingSchemeTable.length; i++) {
var flagObject = encodingSchemeTable[i]
flagLookup[flagObject.flag] = flagObject
}
var currentIndex = 0
var currentMantis = encodingSchemeTable[currentIndex].mantis
var endMantis = encodingSchemeTable[encodingSchemeTable.length - 1].mantis

for (var i = 1; i <= endMantis; i++) {
if (i > currentMantis) {
currentIndex++
currentMantis = encodingSchemeTable[currentIndex].mantis
}
mantisLookup[i] = encodingSchemeTable[currentIndex]
}

var intToFloatArray = function (number, n) {
n = n || 0
return number % 10 ? [number, n] : intToFloatArray(number / 10, n + 1)
}

var padLeadingZeros = function (hex, byteSize) {
return (hex.length === byteSize * 2) ? hex : padLeadingZeros('0' + hex, byteSize)
}

module.exports = {
encode: function (number) {
var buf
if (number < 0) throw new Error('Number is out of bounds')
if (number > Number.MAX_SAFE_INTEGER) throw new Error('Number is out of bounds')
if (number < 32) {
buf = new Buffer([number])
return buf
}
var floatingNumberArray = intToFloatArray(number)
while (true) {
var encodingObject = mantisLookup[floatingNumberArray[0].toString(2).length]
if (!encodingObject) throw new Error('Number is out of bounds')
if ((Math.pow(2, encodingObject.exponent) - 1) >= floatingNumberArray[1]) break
floatingNumberArray[0] *= 10
floatingNumberArray[1] -= 1
}
var shiftedNumber = floatingNumberArray[0] * Math.pow(2, encodingObject.exponent)
var numberString = padLeadingZeros(shiftedNumber.toString(16), encodingObject.byteSize)
buf = new Buffer(numberString, 'hex')
buf[0] = buf[0] | encodingObject.flag
buf[buf.length - 1] = buf[buf.length - 1] | floatingNumberArray[1]

return buf
},

decode: function (consume) {
var flagByte = consume(1)[0]
var flag = flagByte & flagMask
if (flag === 0) return flagByte
if (flag === 0xe0) flag = 0xc0
var encodingObject = flagLookup[flag]
var headOfNumber = new Buffer([flagByte & (~flag)])
var tailOfNumber = consume(encodingObject.byteSize - 1)
var fullNumber = Buffer.concat([headOfNumber, tailOfNumber])
var number = parseInt(fullNumber.toString('hex'), 16)
var exponentShift = Math.pow(2, encodingObject.exponent)
var exponent = number % exponentShift
var mantis = Math.floor(number / exponentShift)
return mantis * Math.pow(10, exponent)
}
}
var flagMask = 0xe0
var encodingSchemeTable =
[
{
'flag': 0x20,
'exponent': 4,
'byteSize': 2,
'mantis': 9
},
{
'flag': 0x40,
'exponent': 4,
'byteSize': 3,
'mantis': 17
},
{
'flag': 0x60,
'exponent': 4,
'byteSize': 4,
'mantis': 25
},
{
'flag': 0x80,
'exponent': 3,
'byteSize': 5,
'mantis': 34
},
{
'flag': 0xa0,
'exponent': 3,
'byteSize': 6,
'mantis': 42
},
{
'flag': 0xc0,
'exponent': 0,
'byteSize': 7,
'mantis': 54
}
]
var flagLookup = {}
var mantisLookup = {}
for (var i = 0; i < encodingSchemeTable.length; i++) {
var flagObject = encodingSchemeTable[i]
flagLookup[flagObject.flag] = flagObject
}
var currentIndex = 0
var currentMantis = encodingSchemeTable[currentIndex].mantis
var endMantis = encodingSchemeTable[encodingSchemeTable.length - 1].mantis
for (var i = 1; i <= endMantis; i++) {
if (i > currentMantis) {
currentIndex++
currentMantis = encodingSchemeTable[currentIndex].mantis
}
mantisLookup[i] = encodingSchemeTable[currentIndex]
}
var intToFloatArray = function (number, n) {
n = n || 0
return number % 10 ? [number, n] : intToFloatArray(number / 10, n + 1)
}
var padLeadingZeros = function (hex, byteSize) {
return (hex.length === byteSize * 2) ? hex : padLeadingZeros('0' + hex, byteSize)
}
module.exports = {
encode: function (number) {
var buf
if (number < 0) throw new Error('Number is out of bounds')
if (number > Number.MAX_SAFE_INTEGER) throw new Error('Number is out of bounds')
if (number < 32) {
buf = new Buffer([number])
return buf
}
var floatingNumberArray = intToFloatArray(number)
while (true) {
var encodingObject = mantisLookup[floatingNumberArray[0].toString(2).length]
if (!encodingObject) throw new Error('Number is out of bounds')
if ((Math.pow(2, encodingObject.exponent) - 1) >= floatingNumberArray[1]) break
floatingNumberArray[0] *= 10
floatingNumberArray[1] -= 1
}
var shiftedNumber = floatingNumberArray[0] * Math.pow(2, encodingObject.exponent)
var numberString = padLeadingZeros(shiftedNumber.toString(16), encodingObject.byteSize)
buf = new Buffer(numberString, 'hex')
buf[0] = buf[0] | encodingObject.flag
buf[buf.length - 1] = buf[buf.length - 1] | floatingNumberArray[1]
return buf
},
decode: function (consume) {
var flagByte = consume(1)[0]
var flag = flagByte & flagMask
if (flag === 0) return flagByte
if (flag === 0xe0) flag = 0xc0
var encodingObject = flagLookup[flag]
var headOfNumber = new Buffer([flagByte & (~flag)])
var tailOfNumber = consume(encodingObject.byteSize - 1)
var fullNumber = Buffer.concat([headOfNumber, tailOfNumber])
var number = parseInt(fullNumber.toString('hex'), 16)
var exponentShift = Math.pow(2, encodingObject.exponent)
var exponent = number % exponentShift
var mantis = Math.floor(number / exponentShift)
return mantis * Math.pow(10, exponent)
}
}

}).call(this,require("buffer").Buffer)
},{"buffer":116}],238:[function(require,module,exports){
Expand Down Expand Up @@ -61800,7 +61841,7 @@ exports.createContext = Script.createContext = function (context) {
},{"indexof":170}],253:[function(require,module,exports){
module.exports={
"name": "digibyte",
"version": "0.15.4",
"version": "0.15.5",
"description": "A pure and powerful JavaScript DigiByte library.",
"author": "DigiByte <[email protected]>",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion digibyte.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit b16bb67

Please sign in to comment.