call-binary-codec
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -5,8 +5,8 @@ 'use strict'; /* eslint-disable func-style */ | ||
var types = require('./types');var _require = | ||
require('./hash-prefixes');var HashPrefix = _require.HashPrefix;var _require2 = | ||
require('./serdes/binary-parser');var BinaryParser = _require2.BinaryParser;var _require3 = | ||
require('./serdes/binary-serializer');var BinarySerializer = _require3.BinarySerializer;var BytesList = _require3.BytesList;var _require4 = | ||
require('./utils/bytes-utils');var bytesToHex = _require4.bytesToHex;var slice = _require4.slice;var parseBytes = _require4.parseBytes;var _require5 = | ||
require('./hash-prefixes'),HashPrefix = _require.HashPrefix;var _require2 = | ||
require('./serdes/binary-parser'),BinaryParser = _require2.BinaryParser;var _require3 = | ||
require('./serdes/binary-serializer'),BinarySerializer = _require3.BinarySerializer,BytesList = _require3.BytesList;var _require4 = | ||
require('./utils/bytes-utils'),bytesToHex = _require4.bytesToHex,slice = _require4.slice,parseBytes = _require4.parseBytes;var _require5 = | ||
require('./hashes');var sha512Half = _require5.sha512Half;var transactionID = _require5.transactionID; | ||
require('./hashes'),sha512Half = _require5.sha512Half,transactionID = _require5.transactionID; | ||
@@ -17,8 +17,4 @@ var makeParser = function makeParser(bytes) {return new BinaryParser(bytes);}; | ||
function serializeObject(object) { | ||
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var prefix = opts.prefix; | ||
var suffix = opts.suffix; | ||
var _opts$signingFieldsOn = opts.signingFieldsOnly; | ||
var signingFieldsOnly = _opts$signingFieldsOn === undefined ? false : _opts$signingFieldsOn; | ||
function serializeObject(object) {var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};var | ||
prefix = opts.prefix,suffix = opts.suffix,_opts$signingFieldsOn = opts.signingFieldsOnly,signingFieldsOnly = _opts$signingFieldsOn === undefined ? false : _opts$signingFieldsOn; | ||
var bytesList = new BytesList(); | ||
@@ -28,17 +24,14 @@ if (prefix) { | ||
} | ||
var filter = signingFieldsOnly ? function (f) {return f.isSigningField;} : undefined; | ||
types.STObject.from(object).toBytesSink(bytesList, filter); | ||
if (suffix) { | ||
bytesList.put(suffix);} | ||
bytesList.put(suffix); | ||
} | ||
return bytesList.toBytes(); | ||
} | ||
return bytesList.toBytes();} | ||
function signingData(tx) { | ||
var prefix = arguments.length <= 1 || arguments[1] === undefined ? HashPrefix.transactionSig : arguments[1]; | ||
function signingData(tx) {var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : HashPrefix.transactionSig; | ||
return serializeObject(tx, { prefix: prefix, signingFieldsOnly: true }); | ||
} | ||
function signingClaimData(claim) { | ||
@@ -54,11 +47,11 @@ var prefix = HashPrefix.paymentChannelClaim; | ||
bytesList.put(amount); | ||
return bytesList.toBytes();} | ||
return bytesList.toBytes(); | ||
} | ||
function multiSigningData(tx, signingAccount) { | ||
var prefix = HashPrefix.transactionMultiSig; | ||
var suffix = types.AccountID.from(signingAccount).toBytes(); | ||
return serializeObject(tx, { prefix: prefix, suffix: suffix, signingFieldsOnly: true });} | ||
return serializeObject(tx, { prefix: prefix, suffix: suffix, signingFieldsOnly: true }); | ||
} | ||
module.exports = { | ||
@@ -79,2 +72,2 @@ BinaryParser: BinaryParser, | ||
transactionID: transactionID, | ||
slice: slice }; | ||
slice: slice }; |
'use strict';var _ = require('lodash'); | ||
var enums = require('./enums');var | ||
var enums = require('./enums');var | ||
Field = enums.Field; | ||
var types = require('./types'); | ||
var binary = require('./binary');var _require = | ||
require('./shamap');var ShaMap = _require.ShaMap; | ||
var binary = require('./binary');var _require = | ||
require('./shamap'),ShaMap = _require.ShaMap; | ||
var ledgerHashes = require('./ledger-hashes'); | ||
var hashes = require('./hashes'); | ||
var quality = require('./quality'); | ||
var signing = require('./signing');var _require2 = | ||
require('./hash-prefixes');var HashPrefix = _require2.HashPrefix; | ||
var signing = require('./signing');var _require2 = | ||
require('./hash-prefixes'),HashPrefix = _require2.HashPrefix; | ||
module.exports = _.assign({ | ||
hashes: _.assign({}, hashes, ledgerHashes), | ||
binary: binary, | ||
enums: enums, | ||
signing: signing, | ||
quality: quality, | ||
Field: Field, | ||
HashPrefix: HashPrefix, | ||
ShaMap: ShaMap }, | ||
module.exports = _.assign({ | ||
hashes: _.assign({}, hashes, ledgerHashes), | ||
binary: binary, | ||
enums: enums, | ||
signing: signing, | ||
quality: quality, | ||
Field: Field, | ||
HashPrefix: HashPrefix, | ||
ShaMap: ShaMap }, | ||
types); |
@@ -25,17 +25,24 @@ { | ||
"LEDGER_ENTRY_TYPES": { | ||
"Any": -3, | ||
"Child": -2, | ||
"Invalid": -1, | ||
"AccountRoot": 97, | ||
"DirectoryNode": 100, | ||
"CallState": 114, | ||
"Ticket": 84, | ||
"SignerList": 83, | ||
"Offer": 111, | ||
"LedgerHashes": 104, | ||
"Amendments": 102, | ||
"SignerList": 83, | ||
"Offer": 111, | ||
"AccountRoot": 97, | ||
"CallState": 114, | ||
"FeeSettings": 115, | ||
"Escrow": 117, | ||
"DirectoryNode": 100, | ||
"PayChannel": 120, | ||
"DepositPreauth": 112, | ||
"Check": 67, | ||
"NickName": 110, | ||
"Contract": 99, | ||
"GeneratorMap": 103, | ||
"Contract": 99, | ||
"PayChannel": 120, | ||
"Invalid": -1, | ||
"IssueRoot":105 | ||
"IssueRoot": 105, | ||
"FeeRoot": 70, | ||
"InvoiceRoot": 118 | ||
}, | ||
@@ -444,2 +451,22 @@ "FIELDS": [ | ||
[ | ||
"SignerListID", | ||
{ | ||
"nth": 38, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt32" | ||
} | ||
], | ||
[ | ||
"SettleDelay", | ||
{ | ||
"nth": 39, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt32" | ||
} | ||
], | ||
[ | ||
"IndexNext", | ||
@@ -525,2 +552,22 @@ { | ||
[ | ||
"DestinationNode", | ||
{ | ||
"nth": 9, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt64" | ||
} | ||
], | ||
[ | ||
"Fans", | ||
{ | ||
"nth": 10, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "UInt64" | ||
} | ||
], | ||
[ | ||
"EmailHash", | ||
@@ -816,2 +863,22 @@ { | ||
[ | ||
"Issued", | ||
{ | ||
"nth": 12, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Amount" | ||
} | ||
], | ||
[ | ||
"Freezed", | ||
{ | ||
"nth": 12, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Amount" | ||
} | ||
], | ||
[ | ||
"MinimumOffer", | ||
@@ -1047,2 +1114,12 @@ { | ||
[ | ||
"Invoice", | ||
{ | ||
"nth": 20, | ||
"isVLEncoded": true, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Blob" | ||
} | ||
], | ||
[ | ||
"Account", | ||
@@ -1088,2 +1165,22 @@ { | ||
[ | ||
"Authorize", | ||
{ | ||
"nth": 5, | ||
"isVLEncoded": true, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "AccountID" | ||
} | ||
], | ||
[ | ||
"Unauthorize", | ||
{ | ||
"nth": 6, | ||
"isVLEncoded": true, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "AccountID" | ||
} | ||
], | ||
[ | ||
"Target", | ||
@@ -1499,2 +1596,22 @@ { | ||
[ | ||
"ConsensusHash", | ||
{ | ||
"nth": 23, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"CheckID", | ||
{ | ||
"nth": 24, | ||
"isVLEncoded": false, | ||
"isSerialized": true, | ||
"isSigningField": true, | ||
"type": "Hash256" | ||
} | ||
], | ||
[ | ||
"TickSize", | ||
@@ -1521,6 +1638,3 @@ { | ||
"TRANSACTION_RESULTS": { | ||
"tecINSUFFICIENT_RESERVE": 141, | ||
"telNO_DST_PARTIAL": -393, | ||
"tecUNFUNDED_PAYMENT": 104, | ||
"tecNO_TARGET": 138, | ||
"temBAD_SRC_ACCOUNT": -281, | ||
@@ -1538,3 +1652,2 @@ "tefPAST_SEQ": -189, | ||
"temBAD_EXPIRATION": -295, | ||
"tecNO_ISSUER": 133, | ||
"temBAD_SEND_CALL_NO_DIRECT": -286, | ||
@@ -1544,22 +1657,10 @@ "temBAD_SEND_CALL_PATHS": -284, | ||
"tefNO_AUTH_REQUIRED": -190, | ||
"tecINSUF_RESERVE_LINE": 122, | ||
"terOWNERS": -93, | ||
"tecNO_REGULAR_KEY": 131, | ||
"tecINSUFF_FEE": 136, | ||
"tecNO_ALTERNATIVE_KEY": 130, | ||
"tecNO_ENTRY": 140, | ||
"terLAST": -91, | ||
"terNO_CALL": -90, | ||
"tecNO_PERMISSION": 139, | ||
"tecNEED_MASTER_KEY": 142, | ||
"terNO_RIPPLE": -90, | ||
"temBAD_FEE": -294, | ||
"terPRE_SEQ": -92, | ||
"tecOVERSIZE": 145, | ||
"tecCRYPTOCONDITION_ERROR": 146, | ||
"tefMASTER_DISABLED": -187, | ||
"temBAD_CURRENCY": -296, | ||
"tefDST_TAG_NEEDED": -193, | ||
"tecUNFUNDED_ADD": 102, | ||
"tecOWNERS": 132, | ||
"tecNO_LINE_REDUNDANT": 127, | ||
"temBAD_SIGNATURE": -282, | ||
@@ -1570,4 +1671,2 @@ "tefFAILURE": -199, | ||
"tefWRONG_PRIOR": -188, | ||
"tecNO_DST": 124, | ||
"tecNO_AUTH": 134, | ||
"telBAD_DOMAIN": -398, | ||
@@ -1578,7 +1677,4 @@ "temBAD_AMOUNT": -298, | ||
"temBAD_ISSUER": -293, | ||
"tecNO_DST_INSUF_CALL": 125, | ||
"tecPATH_PARTIAL": 101, | ||
"telBAD_PUBLIC_KEY": -396, | ||
"tefBAD_ADD_AUTH": -197, | ||
"tecDST_TAG_NEEDED": 143, | ||
"temBAD_OFFER": -291, | ||
@@ -1588,7 +1684,3 @@ "temBAD_SEND_CALL_PARTIAL": -285, | ||
"tefALREADY": -198, | ||
"tecUNFUNDED": 129, | ||
"tecNO_LINE": 135, | ||
"tecFROZEN": 137, | ||
"temUNCERTAIN": -272, | ||
"tecFAILED_PROCESSING": 105, | ||
"telLOCAL_ERROR": -399, | ||
@@ -1598,7 +1690,4 @@ "temREDUNDANT_SEND_MAX": -274, | ||
"temBAD_PATH_LOOP": -289, | ||
"tecPATH_DRY": 128, | ||
"tefEXCEPTION": -192, | ||
"tecDIR_FULL": 121, | ||
"tecUNFUNDED_OFFER": 103, | ||
"temCALL_EMPTY": -273, | ||
"temRIPPLE_EMPTY": -273, | ||
"telINSUF_FEE_P": -394, | ||
@@ -1611,3 +1700,2 @@ "temBAD_SEQUENCE": -283, | ||
"terINSUF_FEE_B": -97, | ||
"tecCLAIM": 100, | ||
"tesSUCCESS": 0, | ||
@@ -1617,32 +1705,68 @@ "temBAD_PATH": -290, | ||
"temUNKNOWN": -271, | ||
"tecINTERNAL": 144, | ||
"temINVALID": -277, | ||
"terNO_AUTH": -95, | ||
"temBAD_TICK_SIZE": -270, | ||
"tecCLAIM": 100, | ||
"tecPATH_PARTIAL": 101, | ||
"tecUNFUNDED_ADD": 102, | ||
"tecUNFUNDED_OFFER": 103, | ||
"tecUNFUNDED_PAYMENT": 104, | ||
"tecFAILED_PROCESSING": 105, | ||
"tecDIR_FULL": 121, | ||
"tecINSUF_RESERVE_LINE": 122, | ||
"tecINSUF_RESERVE_OFFER": 123, | ||
"tecNO_DST": 124, | ||
"tecNO_DST_INSUF_CALL": 125, | ||
"tecNO_LINE_INSUF_RESERVE": 126, | ||
"terNO_AUTH": -95, | ||
"temBAD_TICK_SIZE": -270 | ||
"tecNO_LINE_REDUNDANT": 127, | ||
"tecPATH_DRY": 128, | ||
"tecUNFUNDED": 129, | ||
"tecNO_ALTERNATIVE_KEY": 130, | ||
"tecNO_REGULAR_KEY": 131, | ||
"tecOWNERS": 132, | ||
"tecNO_ISSUER": 133, | ||
"tecNO_AUTH": 134, | ||
"tecNO_LINE": 135, | ||
"tecINSUFF_FEE": 136, | ||
"tecFROZEN": 137, | ||
"tecNO_TARGET": 138, | ||
"tecNO_PERMISSION": 139, | ||
"tecNO_ENTRY": 140, | ||
"tecINSUFFICIENT_RESERVE": 141, | ||
"tecNEED_MASTER_KEY": 142, | ||
"tecDST_TAG_NEEDED": 143, | ||
"tecINTERNAL": 144, | ||
"tecOVERSIZE": 145, | ||
"tecCRYPTOCONDITION_ERROR": 146, | ||
"tecINVARIANT_FAILED": 147, | ||
"tecEXPIRED": 148, | ||
"tecDUPLICATE": 149, | ||
"tecKILLED": 150 | ||
}, | ||
"TRANSACTION_TYPES": { | ||
"Invalid": -1, | ||
"Payment": 0, | ||
"EscrowCreate": 1, | ||
"EscrowFinish": 2, | ||
"AccountSet": 3, | ||
"EscrowCancel": 4, | ||
"SetRegularKey": 5, | ||
"NickNameSet": 6, | ||
"OfferCreate": 7, | ||
"OfferCancel": 8, | ||
"EnableAmendment": 100, | ||
"SetFee": 101, | ||
"SetRegularKey": 5, | ||
"Contract": 9, | ||
"TicketCreate": 10, | ||
"TicketCancel": 11, | ||
"NickNameSet": 6, | ||
"TrustSet": 20, | ||
"Payment": 0, | ||
"AccountSet": 3, | ||
"OfferCreate": 7, | ||
"SignerListSet": 12, | ||
"Contract": 9, | ||
"EscrowCreate": 1, | ||
"EscrowFinish": 2, | ||
"EscrowCancel": 4, | ||
"PaymentChannelCreate": 13, | ||
"PaymentChannelFund": 14, | ||
"PaymentChannelClaim": 15, | ||
"Invalid": -1, | ||
"IssueSet": 16 | ||
"IssueSet": 16, | ||
"DepositPreauth": 19, | ||
"TrustSet": 20, | ||
"EnableAmendment": 100, | ||
"SetFee": 101 | ||
} | ||
} |
'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var assert = require('assert'); | ||
var _ = require('lodash');var _require = | ||
require('./../utils/bytes-utils');var parseBytes = _require.parseBytes;var serializeUIntN = _require.serializeUIntN; | ||
var _ = require('lodash');var _require = | ||
require('./../utils/bytes-utils'),parseBytes = _require.parseBytes,serializeUIntN = _require.serializeUIntN; | ||
var makeClass = require('./../utils/make-class'); | ||
@@ -8,13 +8,13 @@ var enums = require('./definitions.json'); | ||
function transformWith(func, obj) { | ||
return _.transform(obj, func);} | ||
return _.transform(obj, func); | ||
} | ||
function biMap(obj, valueKey) { | ||
return _.transform(obj, function (result, value, key) { | ||
result[key] = value; | ||
result[value[valueKey]] = value;});} | ||
result[value[valueKey]] = value; | ||
}); | ||
} | ||
var EnumType = makeClass({ | ||
var EnumType = makeClass({ | ||
EnumType: function EnumType(definition) { | ||
@@ -25,18 +25,18 @@ _.assign(this, definition); | ||
assert(typeof this.ordinal === 'number'); | ||
assert(typeof this.name === 'string');}, | ||
assert(typeof this.name === 'string'); | ||
}, | ||
toString: function toString() { | ||
return this.name;}, | ||
return this.name; | ||
}, | ||
toJSON: function toJSON() { | ||
return this.name;}, | ||
return this.name; | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
sink.put(this.bytes);}, | ||
statics: { | ||
ordinalByteWidth: 1, | ||
sink.put(this.bytes); | ||
}, | ||
statics: { | ||
ordinalByteWidth: 1, | ||
fromParser: function fromParser(parser) { | ||
return this.from(parser.readUIntN(this.ordinalByteWidth));}, | ||
return this.from(parser.readUIntN(this.ordinalByteWidth)); | ||
}, | ||
from: function from(val) { | ||
@@ -46,6 +46,6 @@ var ret = val instanceof this ? val : this[val]; | ||
throw new Error( | ||
val + ' is not a valid name or ordinal for ' + this.enumName);} | ||
return ret;}, | ||
val + ' is not a valid name or ordinal for ' + this.enumName); | ||
} | ||
return ret; | ||
}, | ||
valuesByName: function valuesByName() {var _this = this; | ||
@@ -55,5 +55,5 @@ return _.transform(this.initVals, function (result, ordinal, name) { | ||
var type = new _this({ name: name, ordinal: ordinal, bytes: bytes }); | ||
result[name] = type;});}, | ||
result[name] = type; | ||
}); | ||
}, | ||
init: function init() { | ||
@@ -63,29 +63,29 @@ var mapped = this.valuesByName(); | ||
this.values = _.values(mapped); | ||
return this;} } }); | ||
return this; | ||
} } }); | ||
function makeEnum(name, definition) { | ||
return makeClass({ | ||
inherits: EnumType, | ||
statics: _.assign(definition, { enumName: name }) });} | ||
return makeClass({ | ||
inherits: EnumType, | ||
statics: _.assign(definition, { enumName: name }) }); | ||
} | ||
function makeEnums(to, definition, name) { | ||
to[name] = makeEnum(name, definition);} | ||
to[name] = makeEnum(name, definition); | ||
} | ||
var Enums = transformWith(makeEnums, { | ||
Type: { | ||
initVals: enums.TYPES }, | ||
var Enums = transformWith(makeEnums, { | ||
Type: { | ||
initVals: enums.TYPES }, | ||
LedgerEntryType: { | ||
initVals: enums.LEDGER_ENTRY_TYPES, ordinalByteWidth: 2 }, | ||
LedgerEntryType: { | ||
initVals: enums.LEDGER_ENTRY_TYPES, ordinalByteWidth: 2 }, | ||
TransactionType: { | ||
initVals: enums.TRANSACTION_TYPES, ordinalByteWidth: 2 }, | ||
TransactionType: { | ||
initVals: enums.TRANSACTION_TYPES, ordinalByteWidth: 2 }, | ||
TransactionResult: { | ||
TransactionResult: { | ||
initVals: enums.TRANSACTION_RESULTS, ordinalByteWidth: 1 } }); | ||
@@ -95,9 +95,9 @@ | ||
Enums.Field = makeClass({ | ||
inherits: EnumType, | ||
statics: { | ||
enumName: 'Field', | ||
initVals: enums.FIELDS, | ||
Enums.Field = makeClass({ | ||
inherits: EnumType, | ||
statics: { | ||
enumName: 'Field', | ||
initVals: enums.FIELDS, | ||
valuesByName: function valuesByName() {var _this2 = this; | ||
var fields = _.map(this.initVals, function (_ref) {var _ref2 = _slicedToArray(_ref, 2);var name = _ref2[0];var definition = _ref2[1]; | ||
var fields = _.map(this.initVals, function (_ref) {var _ref2 = _slicedToArray(_ref, 2),name = _ref2[0],definition = _ref2[1]; | ||
var type = Enums.Type[definition.type]; | ||
@@ -107,6 +107,6 @@ var bytes = _this2.header(type.ordinal, definition.nth); | ||
var extra = { ordinal: ordinal, name: name, type: type, bytes: bytes }; | ||
return new _this2(_.assign(definition, extra));}); | ||
return _.keyBy(fields, 'name');}, | ||
return new _this2(_.assign(definition, extra)); | ||
}); | ||
return _.keyBy(fields, 'name'); | ||
}, | ||
header: function header(type, nth) { | ||
@@ -118,16 +118,16 @@ var name = nth; | ||
if (name < 16) { | ||
push(type << 4 | name);} else | ||
{ | ||
push(type << 4, name);}} else | ||
push(type << 4 | name); | ||
} else { | ||
push(type << 4, name); | ||
} | ||
} else if (name < 16) { | ||
push(name, type); | ||
} else { | ||
push(0, type, name); | ||
} | ||
return parseBytes(header, Uint8Array); | ||
} } }); | ||
if (name < 16) { | ||
push(name, type);} else | ||
{ | ||
push(0, type, name);} | ||
return parseBytes(header, Uint8Array);} } }); | ||
module.exports = Enums; |
@@ -1,25 +0,25 @@ | ||
'use strict';var _require = require('./utils/bytes-utils');var serializeUIntN = _require.serializeUIntN; | ||
'use strict';var _require = require('./utils/bytes-utils'),serializeUIntN = _require.serializeUIntN; | ||
function bytes(uint32) { | ||
return serializeUIntN(uint32, 4);} | ||
return serializeUIntN(uint32, 4); | ||
} | ||
var HashPrefix = { | ||
transactionID: bytes(0x54584E00), | ||
var HashPrefix = { | ||
transactionID: bytes(0x54584E00), | ||
// transaction plus metadata | ||
transaction: bytes(0x534E4400), | ||
transaction: bytes(0x534E4400), | ||
// account state | ||
accountStateEntry: bytes(0x4D4C4E00), | ||
accountStateEntry: bytes(0x4D4C4E00), | ||
// inner node in tree | ||
innerNode: bytes(0x4D494E00), | ||
innerNode: bytes(0x4D494E00), | ||
// ledger master data for signing | ||
ledgerHeader: bytes(0x4C575200), | ||
ledgerHeader: bytes(0x4C575200), | ||
// inner transaction to sign | ||
transactionSig: bytes(0x53545800), | ||
transactionSig: bytes(0x53545800), | ||
// inner transaction to sign | ||
transactionMultiSig: bytes(0x534D5400), | ||
transactionMultiSig: bytes(0x534D5400), | ||
// validation for signing | ||
validation: bytes(0x56414C00), | ||
validation: bytes(0x56414C00), | ||
// proposal for signing | ||
proposal: bytes(0x50525000), | ||
proposal: bytes(0x50525000), | ||
// payment channel claim | ||
@@ -29,3 +29,3 @@ paymentChannelClaim: bytes(0x434C4D00) }; | ||
module.exports = { | ||
module.exports = { | ||
HashPrefix: HashPrefix }; |
@@ -1,42 +0,42 @@ | ||
'use strict';var makeClass = require('./utils/make-class');var _require = | ||
require('./hash-prefixes');var HashPrefix = _require.HashPrefix;var _require2 = | ||
require('./types');var Hash256 = _require2.Hash256;var _require3 = | ||
require('./utils/bytes-utils');var parseBytes = _require3.parseBytes; | ||
'use strict';var makeClass = require('./utils/make-class');var _require = | ||
require('./hash-prefixes'),HashPrefix = _require.HashPrefix;var _require2 = | ||
require('./types'),Hash256 = _require2.Hash256;var _require3 = | ||
require('./utils/bytes-utils'),parseBytes = _require3.parseBytes; | ||
var createHash = require('create-hash'); | ||
var Sha512Half = makeClass({ | ||
var Sha512Half = makeClass({ | ||
Sha512Half: function Sha512Half() { | ||
this.hash = createHash('sha512');}, | ||
statics: { | ||
this.hash = createHash('sha512'); | ||
}, | ||
statics: { | ||
put: function put(bytes) { | ||
return new this().put(bytes);} }, | ||
return new this().put(bytes); | ||
} }, | ||
put: function put(bytes) { | ||
this.hash.update(parseBytes(bytes, Buffer)); | ||
return this;}, | ||
return this; | ||
}, | ||
finish256: function finish256() { | ||
var bytes = this.hash.digest(); | ||
return bytes.slice(0, 32);}, | ||
return bytes.slice(0, 32); | ||
}, | ||
finish: function finish() { | ||
return new Hash256(this.finish256());} }); | ||
return new Hash256(this.finish256()); | ||
} }); | ||
function sha512Half() { | ||
var hash = new Sha512Half();for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];} | ||
args.forEach(function (a) {return hash.put(a);}); | ||
return parseBytes(hash.finish256(), Uint8Array);} | ||
return parseBytes(hash.finish256(), Uint8Array); | ||
} | ||
function transactionID(serialized) { | ||
return new Hash256(sha512Half(HashPrefix.transactionID, serialized));} | ||
return new Hash256(sha512Half(HashPrefix.transactionID, serialized)); | ||
} | ||
module.exports = { | ||
Sha512Half: Sha512Half, | ||
sha512Half: sha512Half, | ||
module.exports = { | ||
Sha512Half: Sha512Half, | ||
sha512Half: sha512Half, | ||
transactionID: transactionID }; |
@@ -1,14 +0,12 @@ | ||
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;};var assert = require('assert'); | ||
var coreTypes = require('./coretypes'); | ||
var quality = coreTypes.quality; | ||
var _coreTypes$binary = coreTypes.binary; | ||
var bytesToHex = _coreTypes$binary.bytesToHex; | ||
var signingData = _coreTypes$binary.signingData; | ||
var signingClaimData = _coreTypes$binary.signingClaimData; | ||
var multiSigningData = _coreTypes$binary.multiSigningData; | ||
var binaryToJSON = _coreTypes$binary.binaryToJSON; | ||
var serializeObject = _coreTypes$binary.serializeObject; | ||
var BinaryParser = _coreTypes$binary.BinaryParser; | ||
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};var assert = require('assert'); | ||
var coreTypes = require('./coretypes');var | ||
quality = | ||
coreTypes.quality,_coreTypes$binary = coreTypes.binary,bytesToHex = _coreTypes$binary.bytesToHex,signingData = _coreTypes$binary.signingData,signingClaimData = _coreTypes$binary.signingClaimData,multiSigningData = _coreTypes$binary.multiSigningData,binaryToJSON = _coreTypes$binary.binaryToJSON,serializeObject = _coreTypes$binary.serializeObject,BinaryParser = _coreTypes$binary.BinaryParser; | ||
function decodeLedgerData(binary) { | ||
@@ -26,16 +24,16 @@ assert(typeof binary === 'string', 'binary must be a hex string'); | ||
close_time_resolution: parser.readUInt8(), | ||
close_flags: parser.readUInt8() };} | ||
close_flags: parser.readUInt8() }; | ||
} | ||
function decode(binary) { | ||
assert(typeof binary === 'string', 'binary must be a hex string'); | ||
return binaryToJSON(binary);} | ||
return binaryToJSON(binary); | ||
} | ||
function encode(json) { | ||
assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object'); | ||
return bytesToHex(serializeObject(json));} | ||
return bytesToHex(serializeObject(json)); | ||
} | ||
function encodeForSigning(json) { | ||
@@ -46,24 +44,23 @@ assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object'); | ||
function encodeForSigningClaim(json) { | ||
assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object'); | ||
return bytesToHex(signingClaimData(json));} | ||
return bytesToHex(signingClaimData(json)); | ||
} | ||
function encodeForMultisigning(json, signer) { | ||
assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object'); | ||
assert.equal(json.SigningPubKey, ''); | ||
return bytesToHex(multiSigningData(json, signer));} | ||
return bytesToHex(multiSigningData(json, signer)); | ||
} | ||
function encodeQuality(value) { | ||
assert(typeof value === 'string'); | ||
return bytesToHex(quality.encode(value));} | ||
return bytesToHex(quality.encode(value)); | ||
} | ||
function decodeQuality(value) { | ||
assert(typeof value === 'string'); | ||
return quality.decode(value).toString();} | ||
return quality.decode(value).toString(); | ||
} | ||
module.exports = { | ||
@@ -77,2 +74,2 @@ decode: decode, | ||
decodeQuality: decodeQuality, | ||
decodeLedgerData: decodeLedgerData }; | ||
decodeLedgerData: decodeLedgerData }; |
'use strict';function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {arr2[i] = arr[i];}return arr2;} else {return Array.from(arr);}}var _ = require('lodash'); | ||
var BN = require('bn.js'); | ||
var assert = require('assert'); | ||
var types = require('./types');var | ||
STObject = types.STObject;var Hash256 = types.Hash256;var _require = | ||
require('./shamap');var ShaMap = _require.ShaMap;var _require2 = | ||
require('./hash-prefixes');var HashPrefix = _require2.HashPrefix;var _require3 = | ||
require('./hashes');var Sha512Half = _require3.Sha512Half;var _require4 = | ||
require('./binary');var BinarySerializer = _require4.BinarySerializer;var serializeObject = _require4.serializeObject; | ||
var types = require('./types');var | ||
STObject = types.STObject,Hash256 = types.Hash256;var _require = | ||
require('./shamap'),ShaMap = _require.ShaMap;var _require2 = | ||
require('./hash-prefixes'),HashPrefix = _require2.HashPrefix;var _require3 = | ||
require('./hashes'),Sha512Half = _require3.Sha512Half;var _require4 = | ||
require('./binary'),BinarySerializer = _require4.BinarySerializer,serializeObject = _require4.serializeObject; | ||
@@ -14,35 +14,35 @@ function computeHash(itemizer, itemsJson) { | ||
itemsJson.forEach(function (item) {return map.addItem.apply(map, _toConsumableArray(itemizer(item)));}); | ||
return map.hash();} | ||
return map.hash(); | ||
} | ||
function transactionItem(json) { | ||
assert(json.hash); | ||
var index = Hash256.from(json.hash); | ||
var item = { | ||
var item = { | ||
hashPrefix: function hashPrefix() { | ||
return HashPrefix.transaction;}, | ||
return HashPrefix.transaction; | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
var serializer = new BinarySerializer(sink); | ||
serializer.writeLengthEncoded(STObject.from(json)); | ||
serializer.writeLengthEncoded(STObject.from(json.metaData));} }; | ||
serializer.writeLengthEncoded(STObject.from(json.metaData)); | ||
} }; | ||
return [index, item]; | ||
} | ||
return [index, item];} | ||
function entryItem(json) { | ||
var index = Hash256.from(json.index); | ||
var bytes = serializeObject(json); | ||
var item = { | ||
var item = { | ||
hashPrefix: function hashPrefix() { | ||
return HashPrefix.accountStateEntry;}, | ||
return HashPrefix.accountStateEntry; | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
sink.put(bytes);} }; | ||
sink.put(bytes); | ||
} }; | ||
return [index, item]; | ||
} | ||
return [index, item];} | ||
var transactionTreeHash = _.partial(computeHash, transactionItem); | ||
@@ -66,8 +66,8 @@ var accountStateHash = _.partial(computeHash, entryItem); | ||
types.UInt8.from(header.close_flags).toBytesSink(hash); | ||
return hash.finish();} | ||
return hash.finish(); | ||
} | ||
module.exports = { | ||
accountStateHash: accountStateHash, | ||
transactionTreeHash: transactionTreeHash, | ||
module.exports = { | ||
accountStateHash: accountStateHash, | ||
transactionTreeHash: transactionTreeHash, | ||
ledgerHash: ledgerHash }; |
@@ -1,7 +0,7 @@ | ||
'use strict';var Decimal = require('decimal.js');var _require = | ||
require('./utils/bytes-utils');var bytesToHex = _require.bytesToHex;var slice = _require.slice;var parseBytes = _require.parseBytes;var _require2 = | ||
require('./types');var UInt64 = _require2.UInt64; | ||
'use strict';var Decimal = require('decimal.js');var _require = | ||
require('./utils/bytes-utils'),bytesToHex = _require.bytesToHex,slice = _require.slice,parseBytes = _require.parseBytes;var _require2 = | ||
require('./types'),UInt64 = _require2.UInt64; | ||
var BN = require('bn.js'); | ||
module.exports = { | ||
module.exports = { | ||
encode: function encode(arg) { | ||
@@ -13,4 +13,4 @@ var quality = arg instanceof Decimal ? arg : new Decimal(arg); | ||
bytes[0] = exponent + 100; | ||
return bytes;}, | ||
return bytes; | ||
}, | ||
decode: function decode(arg) { | ||
@@ -20,2 +20,3 @@ var bytes = slice(parseBytes(arg), -8); | ||
var mantissa = new Decimal('0x' + bytesToHex(slice(bytes, 1))); | ||
return mantissa.times('1e' + exponent);} }; | ||
return mantissa.times('1e' + exponent); | ||
} }; |
'use strict';var assert = require('assert'); | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('../enums');var Field = _require.Field;var _require2 = | ||
require('../utils/bytes-utils');var slice = _require2.slice;var parseBytes = _require2.parseBytes; | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('../enums'),Field = _require.Field;var _require2 = | ||
require('../utils/bytes-utils'),slice = _require2.slice,parseBytes = _require2.parseBytes; | ||
var BinaryParser = makeClass({ | ||
var BinaryParser = makeClass({ | ||
BinaryParser: function BinaryParser(buf) { | ||
this._buf = parseBytes(buf, Uint8Array); | ||
this._length = this._buf.length; | ||
this._cursor = 0;}, | ||
this._cursor = 0; | ||
}, | ||
skip: function skip(n) { | ||
this._cursor += n;}, | ||
read: function read(n) {var to = arguments.length <= 1 || arguments[1] === undefined ? Uint8Array : arguments[1]; | ||
this._cursor += n; | ||
}, | ||
read: function read(n) {var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Uint8Array; | ||
var start = this._cursor; | ||
@@ -20,44 +20,44 @@ var end = this._cursor + n; | ||
this._cursor = end; | ||
return slice(this._buf, start, end, to);}, | ||
return slice(this._buf, start, end, to); | ||
}, | ||
readUIntN: function readUIntN(n) { | ||
return this.read(n, Array).reduce(function (a, b) {return a << 8 | b;}) >>> 0;}, | ||
return this.read(n, Array).reduce(function (a, b) {return a << 8 | b;}) >>> 0; | ||
}, | ||
readUInt8: function readUInt8() { | ||
return this._buf[this._cursor++];}, | ||
return this._buf[this._cursor++]; | ||
}, | ||
readUInt16: function readUInt16() { | ||
return this.readUIntN(2);}, | ||
return this.readUIntN(2); | ||
}, | ||
readUInt32: function readUInt32() { | ||
return this.readUIntN(4);}, | ||
return this.readUIntN(4); | ||
}, | ||
pos: function pos() { | ||
return this._cursor;}, | ||
return this._cursor; | ||
}, | ||
size: function size() { | ||
return this._buf.length;}, | ||
return this._buf.length; | ||
}, | ||
end: function end(customEnd) { | ||
var cursor = this.pos(); | ||
return cursor >= this._length || customEnd !== null && | ||
cursor >= customEnd;}, | ||
return cursor >= this._length || customEnd !== null && | ||
cursor >= customEnd; | ||
}, | ||
readVL: function readVL() { | ||
return this.read(this.readVLLength());}, | ||
return this.read(this.readVLLength()); | ||
}, | ||
readVLLength: function readVLLength() { | ||
var b1 = this.readUInt8(); | ||
if (b1 <= 192) { | ||
return b1;} else | ||
if (b1 <= 240) { | ||
return b1; | ||
} else if (b1 <= 240) { | ||
var b2 = this.readUInt8(); | ||
return 193 + (b1 - 193) * 256 + b2;} else | ||
if (b1 <= 254) { | ||
return 193 + (b1 - 193) * 256 + b2; | ||
} else if (b1 <= 254) { | ||
var _b = this.readUInt8(); | ||
var b3 = this.readUInt8(); | ||
return 12481 + (b1 - 241) * 65536 + _b * 256 + b3;} | ||
throw new Error('Invalid varint length indicator');}, | ||
return 12481 + (b1 - 241) * 65536 + _b * 256 + b3; | ||
} | ||
throw new Error('Invalid varint length indicator'); | ||
}, | ||
readFieldOrdinal: function readFieldOrdinal() { | ||
@@ -67,34 +67,34 @@ var tagByte = this.readUInt8(); | ||
var nth = tagByte & 0x0F || this.readUInt8(); | ||
return type << 16 | nth;}, | ||
return type << 16 | nth; | ||
}, | ||
readField: function readField() { | ||
return Field.from(this.readFieldOrdinal());}, | ||
return Field.from(this.readFieldOrdinal()); | ||
}, | ||
readType: function readType(type) { | ||
return type.fromParser(this);}, | ||
return type.fromParser(this); | ||
}, | ||
typeForField: function typeForField(field) { | ||
return field.associatedType;}, | ||
return field.associatedType; | ||
}, | ||
readFieldValue: function readFieldValue(field) { | ||
var kls = this.typeForField(field); | ||
if (!kls) { | ||
throw new Error('unsupported: (' + field.name + ', ' + field.type.name + ')');} | ||
throw new Error('unsupported: (' + field.name + ', ' + field.type.name + ')'); | ||
} | ||
var sizeHint = field.isVLEncoded ? this.readVLLength() : null; | ||
var value = kls.fromParser(this, sizeHint); | ||
if (value === undefined) { | ||
throw new Error('fromParser for (' + | ||
field.name + ', ' + field.type.name + ') -> undefined ');} | ||
return value;}, | ||
throw new Error('fromParser for (' + | ||
field.name + ', ' + field.type.name + ') -> undefined '); | ||
} | ||
return value; | ||
}, | ||
readFieldAndValue: function readFieldAndValue() { | ||
var field = this.readField(); | ||
return [field, this.readFieldValue(field)];} }); | ||
return [field, this.readFieldValue(field)]; | ||
} }); | ||
module.exports = { | ||
module.exports = { | ||
BinaryParser: BinaryParser }; |
@@ -1,7 +0,7 @@ | ||
'use strict';var assert = require('assert');var _require = | ||
require('../utils/bytes-utils');var parseBytes = _require.parseBytes;var bytesToHex = _require.bytesToHex; | ||
var makeClass = require('../utils/make-class');var _require2 = | ||
require('../enums');var Type = _require2.Type;var Field = _require2.Field; | ||
'use strict';var assert = require('assert');var _require = | ||
require('../utils/bytes-utils'),parseBytes = _require.parseBytes,bytesToHex = _require.bytesToHex; | ||
var makeClass = require('../utils/make-class');var _require2 = | ||
require('../enums'),Type = _require2.Type,Field = _require2.Field; | ||
var BytesSink = { | ||
var BytesSink = { | ||
put: function put() /* bytesSequence */{ | ||
@@ -12,8 +12,8 @@ // any hex string or any object with a `length` and where 0 <= [ix] <= 255 | ||
var BytesList = makeClass({ | ||
implementing: BytesSink, | ||
var BytesList = makeClass({ | ||
implementing: BytesSink, | ||
BytesList: function BytesList() { | ||
this.arrays = []; | ||
this.length = 0;}, | ||
this.length = 0; | ||
}, | ||
put: function put(bytesArg) { | ||
@@ -23,9 +23,9 @@ var bytes = parseBytes(bytesArg, Uint8Array); | ||
this.arrays.push(bytes); | ||
return this;}, | ||
return this; | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
this.arrays.forEach(function (arr) { | ||
sink.put(arr);});}, | ||
sink.put(arr); | ||
}); | ||
}, | ||
toBytes: function toBytes() { | ||
@@ -36,27 +36,27 @@ var concatenated = new Uint8Array(this.length); | ||
concatenated.set(arr, pointer); | ||
pointer += arr.length;}); | ||
return concatenated;}, | ||
pointer += arr.length; | ||
}); | ||
return concatenated; | ||
}, | ||
toHex: function toHex() { | ||
return bytesToHex(this.toBytes());} }); | ||
return bytesToHex(this.toBytes()); | ||
} }); | ||
var BinarySerializer = makeClass({ | ||
var BinarySerializer = makeClass({ | ||
BinarySerializer: function BinarySerializer(sink) { | ||
this.sink = sink;}, | ||
this.sink = sink; | ||
}, | ||
write: function write(value) { | ||
value.toBytesSink(this.sink);}, | ||
value.toBytesSink(this.sink); | ||
}, | ||
put: function put(bytes) { | ||
this.sink.put(bytes);}, | ||
this.sink.put(bytes); | ||
}, | ||
writeType: function writeType(type, value) { | ||
this.write(type.from(value));}, | ||
this.write(type.from(value)); | ||
}, | ||
writeBytesList: function writeBytesList(bl) { | ||
bl.toBytesSink(this.sink);}, | ||
bl.toBytesSink(this.sink); | ||
}, | ||
encodeVL: function encodeVL(len) { | ||
@@ -67,9 +67,9 @@ var length = len; | ||
lenBytes[0] = length; | ||
return lenBytes.subarray(0, 1);} else | ||
if (length <= 12480) { | ||
return lenBytes.subarray(0, 1); | ||
} else if (length <= 12480) { | ||
length -= 193; | ||
lenBytes[0] = 193 + (length >>> 8); | ||
lenBytes[1] = length & 0xff; | ||
return lenBytes.subarray(0, 2);} else | ||
if (length <= 918744) { | ||
return lenBytes.subarray(0, 2); | ||
} else if (length <= 918744) { | ||
length -= 12481; | ||
@@ -79,6 +79,6 @@ lenBytes[0] = 241 + (length >>> 16); | ||
lenBytes[2] = length & 0xff; | ||
return lenBytes.subarray(0, 3);} | ||
throw new Error('Overflow error');}, | ||
return lenBytes.subarray(0, 3); | ||
} | ||
throw new Error('Overflow error'); | ||
}, | ||
writeFieldAndValue: function writeFieldAndValue(field, _value) { | ||
@@ -91,12 +91,12 @@ var sink = this.sink; | ||
if (field.isVLEncoded) { | ||
this.writeLengthEncoded(value);} else | ||
{ | ||
this.writeLengthEncoded(value); | ||
} else { | ||
value.toBytesSink(sink); | ||
if (field.type === Type.STObject) { | ||
sink.put(Field.ObjectEndMarker.bytes);} else | ||
if (field.type === Type.STArray) { | ||
sink.put(Field.ArrayEndMarker.bytes);}}}, | ||
sink.put(Field.ObjectEndMarker.bytes); | ||
} else if (field.type === Type.STArray) { | ||
sink.put(Field.ArrayEndMarker.bytes); | ||
} | ||
} | ||
}, | ||
writeLengthEncoded: function writeLengthEncoded(value) { | ||
@@ -106,8 +106,8 @@ var bytes = new BytesList(); | ||
this.put(this.encodeVL(bytes.length)); | ||
this.writeBytesList(bytes);} }); | ||
this.writeBytesList(bytes); | ||
} }); | ||
module.exports = { | ||
BytesList: BytesList, | ||
module.exports = { | ||
BytesList: BytesList, | ||
BinarySerializer: BinarySerializer }; |
'use strict';var assert = require('assert'); | ||
var makeClass = require('./utils/make-class');var _require = | ||
require('./types');var Hash256 = _require.Hash256;var _require2 = | ||
require('./hash-prefixes');var HashPrefix = _require2.HashPrefix;var _require3 = | ||
require('./hashes');var Hasher = _require3.Sha512Half; | ||
var makeClass = require('./utils/make-class');var _require = | ||
require('./types'),Hash256 = _require.Hash256;var _require2 = | ||
require('./hash-prefixes'),HashPrefix = _require2.HashPrefix;var _require3 = | ||
require('./hashes'),Hasher = _require3.Sha512Half; | ||
var ShaMapNode = makeClass({ | ||
virtuals: { | ||
hashPrefix: function hashPrefix() {}, | ||
isLeaf: function isLeaf() {}, | ||
isInner: function isInner() {} }, | ||
var ShaMapNode = makeClass({ | ||
virtuals: { | ||
hashPrefix: function hashPrefix() {}, | ||
isLeaf: function isLeaf() {}, | ||
isInner: function isInner() {} }, | ||
cached: { | ||
cached: { | ||
hash: function hash() { | ||
var hasher = Hasher.put(this.hashPrefix()); | ||
this.toBytesSink(hasher); | ||
return hasher.finish();} } }); | ||
return hasher.finish(); | ||
} } }); | ||
var ShaMapLeaf = makeClass({ | ||
inherits: ShaMapNode, | ||
var ShaMapLeaf = makeClass({ | ||
inherits: ShaMapNode, | ||
ShaMapLeaf: function ShaMapLeaf(index, item) { | ||
ShaMapNode.call(this); | ||
this.index = index; | ||
this.item = item;}, | ||
this.item = item; | ||
}, | ||
isLeaf: function isLeaf() { | ||
return true;}, | ||
return true; | ||
}, | ||
isInner: function isInner() { | ||
return false;}, | ||
return false; | ||
}, | ||
hashPrefix: function hashPrefix() { | ||
return this.item.hashPrefix();}, | ||
return this.item.hashPrefix(); | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
this.item.toBytesSink(sink); | ||
this.index.toBytesSink(sink);} }); | ||
this.index.toBytesSink(sink); | ||
} }); | ||
var $uper = ShaMapNode.prototype; | ||
var ShaMapInner = makeClass({ | ||
inherits: ShaMapNode, | ||
ShaMapInner: function ShaMapInner() {var depth = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; | ||
var ShaMapInner = makeClass({ | ||
inherits: ShaMapNode, | ||
ShaMapInner: function ShaMapInner() {var depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
ShaMapNode.call(this); | ||
this.depth = depth; | ||
this.slotBits = 0; | ||
this.branches = Array(16);}, | ||
this.branches = Array(16); | ||
}, | ||
isInner: function isInner() { | ||
return true;}, | ||
return true; | ||
}, | ||
isLeaf: function isLeaf() { | ||
return false;}, | ||
return false; | ||
}, | ||
hashPrefix: function hashPrefix() { | ||
return HashPrefix.innerNode;}, | ||
return HashPrefix.innerNode; | ||
}, | ||
setBranch: function setBranch(slot, branch) { | ||
this.slotBits = this.slotBits | 1 << slot; | ||
this.branches[slot] = branch;}, | ||
this.branches[slot] = branch; | ||
}, | ||
empty: function empty() { | ||
return this.slotBits === 0;}, | ||
return this.slotBits === 0; | ||
}, | ||
hash: function hash() { | ||
if (this.empty()) { | ||
return Hash256.ZERO_256;} | ||
return $uper.hash.call(this);}, | ||
return Hash256.ZERO_256; | ||
} | ||
return $uper.hash.call(this); | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
@@ -80,5 +80,5 @@ for (var i = 0; i < this.branches.length; i++) { | ||
var hash = branch ? branch.hash() : Hash256.ZERO_256; | ||
hash.toBytesSink(sink);}}, | ||
hash.toBytesSink(sink); | ||
} | ||
}, | ||
addItem: function addItem(index, item, leaf) { | ||
@@ -89,21 +89,21 @@ assert(index instanceof Hash256); | ||
if (!existing) { | ||
this.setBranch(nibble, leaf || new ShaMapLeaf(index, item));} else | ||
if (existing.isLeaf()) { | ||
this.setBranch(nibble, leaf || new ShaMapLeaf(index, item)); | ||
} else if (existing.isLeaf()) { | ||
var newInner = new ShaMapInner(this.depth + 1); | ||
newInner.addItem(existing.index, null, existing); | ||
newInner.addItem(index, item, leaf); | ||
this.setBranch(nibble, newInner);} else | ||
if (existing.isInner()) { | ||
existing.addItem(index, item, leaf);} else | ||
{ | ||
assert(false);}} }); | ||
this.setBranch(nibble, newInner); | ||
} else if (existing.isInner()) { | ||
existing.addItem(index, item, leaf); | ||
} else { | ||
assert(false); | ||
} | ||
} }); | ||
var ShaMap = makeClass({ | ||
var ShaMap = makeClass({ | ||
inherits: ShaMapInner }); | ||
module.exports = { | ||
module.exports = { | ||
ShaMap: ShaMap }; |
'use strict'; /* eslint-disable func-style */ | ||
var _ = require('lodash');var _require = | ||
require('./types');var AccountID = _require.AccountID; | ||
var binary = require('./binary');var | ||
var _ = require('lodash');var _require = | ||
require('./types'),AccountID = _require.AccountID; | ||
var binary = require('./binary');var | ||
serializeObject = | ||
serializeObject = | ||
@@ -12,3 +12,3 @@ | ||
binary.serializeObject;var bytesToHex = binary.bytesToHex;var multiSigningData = binary.multiSigningData;var transactionID = binary.transactionID;var signingData = binary.signingData; | ||
binary.serializeObject,bytesToHex = binary.bytesToHex,multiSigningData = binary.multiSigningData,transactionID = binary.transactionID,signingData = binary.signingData; | ||
@@ -23,5 +23,5 @@ var FULL_CANONICAL_SIGNATURE = 0x80000000; | ||
tx_json.Flags |= FULL_CANONICAL_SIGNATURE; | ||
tx_json.Flags >>>= 0;} | ||
tx_json.Flags >>>= 0; | ||
} | ||
function serializedBundle(tx_json) { | ||
@@ -31,6 +31,6 @@ var serialized = serializeObject(tx_json); | ||
var tx_blob = toHex(serialized); | ||
return { tx_json: tx_json, tx_blob: tx_blob, hash: hash };} | ||
return { tx_json: tx_json, tx_blob: tx_blob, hash: hash }; | ||
} | ||
function signFor(tx_json_, keyPair) {var signingAccount = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
function signFor(tx_json_, keyPair) {var signingAccount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var tx_json = _.clone(tx_json_); | ||
@@ -41,6 +41,6 @@ tx_json.SigningPubKey = ''; | ||
var signature = keyPair.sign(multiSigningData(tx_json, signerID)); | ||
var signer = { | ||
Signer: { | ||
SigningPubKey: toHex(keyPair.publicBytes()), | ||
TxnSignature: toHex(signature), | ||
var signer = { | ||
Signer: { | ||
SigningPubKey: toHex(keyPair.publicBytes()), | ||
TxnSignature: toHex(signature), | ||
Account: signerID } }; | ||
@@ -54,5 +54,5 @@ | ||
return serializedBundle(tx_json);} | ||
return serializedBundle(tx_json); | ||
} | ||
function sign(tx_json_, keyPair) { | ||
@@ -65,7 +65,7 @@ var tx_json = _.clone(tx_json_); | ||
return serializedBundle(tx_json);} | ||
return serializedBundle(tx_json); | ||
} | ||
module.exports = { | ||
signFor: signFor, | ||
module.exports = { | ||
signFor: signFor, | ||
sign: sign }; |
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('call-address-codec');var decodeAccountID = _require.decodeAccountID;var encodeAccountID = _require.encodeAccountID;var _require2 = | ||
require('./hash-160');var Hash160 = _require2.Hash160; | ||
require('call-address-codec'),decodeAccountID = _require.decodeAccountID,encodeAccountID = _require.encodeAccountID;var _require2 = | ||
require('./hash-160'),Hash160 = _require2.Hash160; | ||
var AccountID = makeClass({ | ||
AccountID: function AccountID(bytes) { | ||
Hash160.call(this, bytes);}, | ||
Hash160.call(this, bytes); | ||
}, | ||
inherits: Hash160, | ||
@@ -14,4 +14,4 @@ statics: { | ||
/^c/.test(value) ? this.fromBase58(value) : | ||
new this(value);}, | ||
new this(value); | ||
}, | ||
cache: {}, | ||
@@ -21,23 +21,23 @@ fromCache: function fromCache(base58) { | ||
if (!cached) { | ||
cached = this.cache[base58] = this.fromBase58(base58);} | ||
return cached;}, | ||
cached = this.cache[base58] = this.fromBase58(base58); | ||
} | ||
return cached; | ||
}, | ||
fromBase58: function fromBase58(value) { | ||
var acc = new this(decodeAccountID(value)); | ||
acc._toBase58 = value; | ||
return acc;} }, | ||
return acc; | ||
} }, | ||
toJSON: function toJSON() { | ||
return this.toBase58();}, | ||
return this.toBase58(); | ||
}, | ||
cached: { | ||
toBase58: function toBase58() { | ||
return encodeAccountID(this._bytes);} } }); | ||
return encodeAccountID(this._bytes); | ||
} } }); | ||
module.exports = { | ||
AccountID: AccountID }; | ||
AccountID: AccountID }; |
@@ -1,11 +0,11 @@ | ||
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;};function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {arr2[i] = arr[i];}return arr2;} else {return Array.from(arr);}}var _ = require('lodash'); | ||
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {arr2[i] = arr[i];}return arr2;} else {return Array.from(arr);}}var _ = require('lodash'); | ||
var assert = require('assert'); | ||
var BN = require('bn.js'); | ||
var Decimal = require('decimal.js'); | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type');var SerializedType = _require.SerializedType;var _require2 = | ||
require('../utils/bytes-utils');var bytesToHex = _require2.bytesToHex;var _require3 = | ||
require('./currency');var Currency = _require3.Currency;var _require4 = | ||
require('./account-id');var AccountID = _require4.AccountID;var _require5 = | ||
require('./uint-64');var UInt64 = _require5.UInt64; | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type'),SerializedType = _require.SerializedType;var _require2 = | ||
require('../utils/bytes-utils'),bytesToHex = _require2.bytesToHex;var _require3 = | ||
require('./currency'),Currency = _require3.Currency;var _require4 = | ||
require('./account-id'),AccountID = _require4.AccountID;var _require5 = | ||
require('./uint-64'),UInt64 = _require5.UInt64; | ||
@@ -25,21 +25,21 @@ var MIN_IOU_EXPONENT = -96; | ||
// Never use exponential form | ||
Decimal.config({ | ||
toExpPos: MAX_IOU_EXPONENT + MAX_IOU_PRECISION, | ||
Decimal.config({ | ||
toExpPos: MAX_IOU_EXPONENT + MAX_IOU_PRECISION, | ||
toExpNeg: MIN_IOU_EXPONENT - MAX_IOU_PRECISION }); | ||
var AMOUNT_PARAMETERS_DESCRIPTION = '\nNative values must be described in drops, a million of which equal one CALL.\nThis must be an integer number, with the absolute value not exceeding ' + | ||
var AMOUNT_PARAMETERS_DESCRIPTION = '\nNative values must be described in drops, a million of which equal one CALL.\nThis must be an integer number, with the absolute value not exceeding ' + | ||
MAX_NETWORK_DROPS + '\n\nIOU values must have a maximum precision of ' + | ||
MAX_NETWORK_DROPS + '\n\nIOU values must have a maximum precision of ' + | ||
MAX_IOU_PRECISION + ' significant digits. They are serialized as\na canonicalised mantissa and exponent. \n\nThe valid range for a mantissa is between ' + | ||
MAX_IOU_PRECISION + ' significant digits. They are serialized as\na canonicalised mantissa and exponent.\n\nThe valid range for a mantissa is between ' + | ||
MIN_IOU_MANTISSA + ' and ' + | ||
MAX_IOU_MANTISSA + '\nThe exponent must be >= ' + | ||
MIN_IOU_EXPONENT + ' and <= ' + MAX_IOU_EXPONENT + '\n\nThus the largest serializable IOU value is:\n' + | ||
MIN_IOU_MANTISSA + ' and ' + | ||
MAX_IOU_MANTISSA + '\nThe exponent must be >= ' + | ||
MIN_IOU_EXPONENT + ' and <= ' + MAX_IOU_EXPONENT + '\n\nThus the largest serializable IOU value is:\n' + | ||
MAX_IOU.toString() + '\n\nAnd the smallest:\n' + | ||
MAX_IOU.toString() + '\n\nAnd the smallest:\n' + | ||
@@ -51,45 +51,47 @@ | ||
function isDefined(val) { | ||
return !_.isUndefined(val);} | ||
return !_.isUndefined(val); | ||
} | ||
function raiseIllegalAmountError(value) { | ||
throw new Error(value.toString() + ' is an illegal amount\n' + | ||
AMOUNT_PARAMETERS_DESCRIPTION);} | ||
throw new Error(value.toString() + ' is an illegal amount\n' + | ||
AMOUNT_PARAMETERS_DESCRIPTION); | ||
} | ||
var parsers = { | ||
var parsers = { | ||
string: function string(str) { | ||
if (!str.match(/\d+/)) { | ||
raiseIllegalAmountError(str);} | ||
return [new Decimal(str).dividedBy(DROPS_PER_CALL), Currency.CALL];}, | ||
raiseIllegalAmountError(str); | ||
} | ||
return [new Decimal(str).dividedBy(DROPS_PER_CALL), Currency.CALL]; | ||
}, | ||
object: function object(_object) { | ||
assert(isDefined(_object.currency), 'currency must be defined'); | ||
assert(isDefined(_object.issuer), 'issuer must be defined'); | ||
return [new Decimal(_object.value), | ||
Currency.from(_object.currency), | ||
AccountID.from(_object.issuer)];} }; | ||
return [new Decimal(_object.value), | ||
Currency.from(_object.currency), | ||
AccountID.from(_object.issuer)]; | ||
} }; | ||
var Amount = makeClass({ | ||
Amount: function Amount(value, currency, issuer) { | ||
var Amount = makeClass({ | ||
Amount: function Amount(value, currency, issuer) {var validate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; | ||
this.value = value || new Decimal('0'); | ||
this.currency = currency || Currency.CALL; | ||
this.issuer = issuer || null; | ||
this.assertValueIsValid();}, | ||
mixins: SerializedType, | ||
statics: { | ||
if (validate) { | ||
this.assertValueIsValid(); | ||
} | ||
}, | ||
mixins: SerializedType, | ||
statics: { | ||
from: function from(value) { | ||
if (value instanceof this) { | ||
return value;} | ||
return value; | ||
} | ||
var parser = parsers[typeof value === 'undefined' ? 'undefined' : _typeof(value)]; | ||
if (parser) { | ||
return new (Function.prototype.bind.apply(this, [null].concat(_toConsumableArray(parser(value)))))();} | ||
throw new Error('unsupported value: ' + value);}, | ||
return new (Function.prototype.bind.apply(this, [null].concat(_toConsumableArray(parser(value)))))(); | ||
} | ||
throw new Error('unsupported value: ' + value); | ||
}, | ||
fromParser: function fromParser(parser) { | ||
@@ -113,11 +115,11 @@ var mantissa = parser.read(8); | ||
times('1e' + exponent); | ||
return new this(value, currency, issuer);} | ||
return new this(value, currency, issuer, false); | ||
} | ||
mantissa[0] &= 0x3F; | ||
var drops = new Decimal(sign + '0x' + bytesToHex(mantissa)); | ||
var CALLValue = drops.dividedBy(DROPS_PER_CALL); | ||
return new this(CALLValue, Currency.CALL);} }, | ||
var callValue = drops.dividedBy(DROPS_PER_CALL); | ||
return new this(callValue, Currency.CALL, null, false); | ||
} }, | ||
assertValueIsValid: function assertValueIsValid() { | ||
@@ -130,32 +132,32 @@ // zero is always a valid amount value | ||
// value is in CALL scale, but show the value in canonical json form | ||
raiseIllegalAmountError(this.value.times(DROPS_PER_CALL));}} else | ||
{ | ||
raiseIllegalAmountError(this.value.times(DROPS_PER_CALL)); | ||
} | ||
} else { | ||
var p = this.value.precision(); | ||
var e = this.exponent(); | ||
if (p > MAX_IOU_PRECISION || | ||
e > MAX_IOU_EXPONENT || | ||
if (p > MAX_IOU_PRECISION || | ||
e > MAX_IOU_EXPONENT || | ||
e < MIN_IOU_EXPONENT) { | ||
raiseIllegalAmountError(this.value);}}}}, | ||
raiseIllegalAmountError(this.value); | ||
} | ||
} | ||
} | ||
}, | ||
isNative: function isNative() { | ||
return this.currency.isNative();}, | ||
return this.currency.isNative(); | ||
}, | ||
mantissa: function mantissa() { | ||
return new UInt64( | ||
new BN(this.value.times('1e' + -this.exponent()).abs().toString()));}, | ||
new BN(this.value.times('1e' + -this.exponent()).abs().toString())); | ||
}, | ||
isZero: function isZero() { | ||
return this.value.isZero();}, | ||
return this.value.isZero(); | ||
}, | ||
exponent: function exponent() { | ||
return this.isNative() ? -6 : this.value.e - 15;}, | ||
return this.isNative() ? -6 : this.value.e - 15; | ||
}, | ||
valueString: function valueString() { | ||
return (this.isNative() ? this.value.times(DROPS_PER_CALL) : this.value). | ||
toString();}, | ||
toString(); | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
@@ -168,33 +170,33 @@ var isNative = this.isNative(); | ||
mantissa[0] |= notNegative ? 0x40 : 0; | ||
sink.put(mantissa);} else | ||
{ | ||
sink.put(mantissa); | ||
} else { | ||
mantissa[0] |= 0x80; | ||
if (!this.isZero()) { | ||
if (notNegative) { | ||
mantissa[0] |= 0x40;} | ||
mantissa[0] |= 0x40; | ||
} | ||
var exponent = this.value.e - 15; | ||
var exponentByte = 97 + exponent; | ||
mantissa[0] |= exponentByte >>> 2; | ||
mantissa[1] |= (exponentByte & 0x03) << 6;} | ||
mantissa[1] |= (exponentByte & 0x03) << 6; | ||
} | ||
sink.put(mantissa); | ||
this.currency.toBytesSink(sink); | ||
this.issuer.toBytesSink(sink);}}, | ||
this.issuer.toBytesSink(sink); | ||
} | ||
}, | ||
toJSON: function toJSON() { | ||
var valueString = this.valueString(); | ||
if (this.isNative()) { | ||
return valueString;} | ||
return valueString; | ||
} | ||
return { | ||
value: valueString, | ||
currency: this.currency.toJSON(), | ||
issuer: this.issuer.toJSON() }; | ||
return { | ||
value: valueString, | ||
currency: this.currency.toJSON(), | ||
issuer: this.issuer.toJSON() };} }); | ||
} }); | ||
module.exports = { | ||
Amount: Amount }; | ||
module.exports = { | ||
Amount: Amount }; |
@@ -1,28 +0,28 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('../utils/bytes-utils');var parseBytes = _require.parseBytes;var _require2 = | ||
require('./serialized-type');var SerializedType = _require2.SerializedType; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('../utils/bytes-utils'),parseBytes = _require.parseBytes;var _require2 = | ||
require('./serialized-type'),SerializedType = _require2.SerializedType; | ||
var Blob = makeClass({ | ||
mixins: SerializedType, | ||
var Blob = makeClass({ | ||
mixins: SerializedType, | ||
Blob: function Blob(bytes) { | ||
if (bytes) { | ||
this._bytes = parseBytes(bytes, Uint8Array);} else | ||
{ | ||
this._bytes = new Uint8Array(0);}}, | ||
statics: { | ||
this._bytes = parseBytes(bytes, Uint8Array); | ||
} else { | ||
this._bytes = new Uint8Array(0); | ||
} | ||
}, | ||
statics: { | ||
fromParser: function fromParser(parser, hint) { | ||
return new this(parser.read(hint));}, | ||
return new this(parser.read(hint)); | ||
}, | ||
from: function from(value) { | ||
if (value instanceof this) { | ||
return value;} | ||
return value; | ||
} | ||
return new this(value); | ||
} } }); | ||
return new this(value);} } }); | ||
module.exports = { | ||
module.exports = { | ||
Blob: Blob }; |
'use strict';var _ = require('lodash'); | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('../utils/bytes-utils');var slice = _require.slice;var _require2 = | ||
require('./hash-160');var Hash160 = _require2.Hash160; | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('../utils/bytes-utils'),slice = _require.slice;var _require2 = | ||
require('./hash-160'),Hash160 = _require2.Hash160; | ||
var ISO_REGEX = /^[A-Z0-9]{3}$/; | ||
@@ -12,7 +12,7 @@ var HEX_REGEX = /^[A-F0-9]{40}$/; | ||
var isoBytes = iso.split('').map(function (c) {return c.charCodeAt(0);}); | ||
bytes.set(isoBytes, 12);} | ||
bytes.set(isoBytes, 12); | ||
} | ||
return bytes; | ||
} | ||
return bytes;} | ||
function isISOCode(val) { | ||
@@ -23,17 +23,17 @@ return val.length === 3; // ISO_REGEX.test(val); | ||
function isHex(val) { | ||
return HEX_REGEX.test(val);} | ||
return HEX_REGEX.test(val); | ||
} | ||
function isStringRepr(val) { | ||
return _.isString(val) && (isISOCode(val) || isHex(val));} | ||
return _.isString(val) && (isISOCode(val) || isHex(val)); | ||
} | ||
function isBytesArray(val) { | ||
return val.length === 20;} | ||
return val.length === 20; | ||
} | ||
function isValidRepr(val) { | ||
return isStringRepr(val) || isBytesArray(val);} | ||
return isStringRepr(val) || isBytesArray(val); | ||
} | ||
function bytesFromRepr(val) { | ||
@@ -43,23 +43,23 @@ if (isValidRepr(val)) { | ||
// 20 or 40. | ||
return val.length === 3 ? isoToBytes(val) : val;} | ||
return val.length === 3 ? isoToBytes(val) : val; | ||
} | ||
throw new Error('Unsupported Currency repr: ' + val); | ||
} | ||
throw new Error('Unsupported Currency repr: ' + val);} | ||
var $uper = Hash160.prototype; | ||
var Currency = makeClass({ | ||
inherits: Hash160, | ||
getters: ['isNative', 'iso'], | ||
statics: { | ||
var Currency = makeClass({ | ||
inherits: Hash160, | ||
getters: ['isNative', 'iso'], | ||
statics: { | ||
init: function init() { | ||
this.CALL = new this(new Uint8Array(20));}, | ||
this.CALL = new this(new Uint8Array(20)); | ||
}, | ||
from: function from(val) { | ||
return val instanceof this ? val : new this(bytesFromRepr(val));} }, | ||
return val instanceof this ? val : new this(bytesFromRepr(val)); | ||
} }, | ||
Currency: function Currency(bytes) { | ||
Hash160.call(this, bytes); | ||
this.classify();}, | ||
this.classify(); | ||
}, | ||
classify: function classify() { | ||
@@ -78,18 +78,18 @@ // We only have a non null iso() property available if the currency can be | ||
onlyISO = false; | ||
break;}} | ||
break; | ||
} | ||
} | ||
var lossLessISO = onlyISO && iso !== 'CALL' && ISO_REGEX.test(iso); | ||
this._isNative = onlyISO && _.isEqual(code, [0, 0, 0]); | ||
this._iso = this._isNative ? 'CALL' : lossLessISO ? iso : null;}, | ||
this._iso = this._isNative ? 'CALL' : lossLessISO ? iso : null; | ||
}, | ||
toJSON: function toJSON() { | ||
if (this.iso()) { | ||
return this.iso();} | ||
return this.iso(); | ||
} | ||
return $uper.toJSON.call(this); | ||
} }); | ||
return $uper.toJSON.call(this);} }); | ||
module.exports = { | ||
Currency: Currency }; | ||
module.exports = { | ||
Currency: Currency }; |
@@ -1,10 +0,10 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash');var Hash = _require.Hash; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash'),Hash = _require.Hash; | ||
var Hash128 = makeClass({ | ||
inherits: Hash, | ||
var Hash128 = makeClass({ | ||
inherits: Hash, | ||
statics: { width: 16 } }); | ||
module.exports = { | ||
module.exports = { | ||
Hash128: Hash128 }; |
@@ -1,10 +0,10 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash');var Hash = _require.Hash; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash'),Hash = _require.Hash; | ||
var Hash160 = makeClass({ | ||
inherits: Hash, | ||
var Hash160 = makeClass({ | ||
inherits: Hash, | ||
statics: { width: 20 } }); | ||
module.exports = { | ||
module.exports = { | ||
Hash160: Hash160 }; |
@@ -1,15 +0,15 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash');var Hash = _require.Hash; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash'),Hash = _require.Hash; | ||
var Hash256 = makeClass({ | ||
inherits: Hash, | ||
statics: { | ||
width: 32, | ||
var Hash256 = makeClass({ | ||
inherits: Hash, | ||
statics: { | ||
width: 32, | ||
init: function init() { | ||
this.ZERO_256 = new this(new Uint8Array(this.width));} } }); | ||
this.ZERO_256 = new this(new Uint8Array(this.width)); | ||
} } }); | ||
module.exports = { | ||
module.exports = { | ||
Hash256: Hash256 }; |
'use strict';var assert = require('assert'); | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type');var Comparable = _require.Comparable;var SerializedType = _require.SerializedType;var _require2 = | ||
require('../utils/bytes-utils');var compareBytes = _require2.compareBytes;var parseBytes = _require2.parseBytes; | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type'),Comparable = _require.Comparable,SerializedType = _require.SerializedType;var _require2 = | ||
require('../utils/bytes-utils'),compareBytes = _require2.compareBytes,parseBytes = _require2.parseBytes; | ||
var Hash = makeClass({ | ||
var Hash = makeClass({ | ||
Hash: function Hash(bytes) { | ||
var width = this.constructor.width; | ||
this._bytes = bytes ? parseBytes(bytes, Uint8Array) : | ||
this._bytes = bytes ? parseBytes(bytes, Uint8Array) : | ||
new Uint8Array(width); | ||
assert.equal(this._bytes.length, width);}, | ||
mixins: [Comparable, SerializedType], | ||
statics: { | ||
width: NaN, | ||
assert.equal(this._bytes.length, width); | ||
}, | ||
mixins: [Comparable, SerializedType], | ||
statics: { | ||
width: NaN, | ||
from: function from(value) { | ||
if (value instanceof this) { | ||
return value;} | ||
return new this(parseBytes(value));}, | ||
return value; | ||
} | ||
return new this(parseBytes(value)); | ||
}, | ||
fromParser: function fromParser(parser, hint) { | ||
return new this(parser.read(hint || this.width));} }, | ||
return new this(parser.read(hint || this.width)); | ||
} }, | ||
compareTo: function compareTo(other) { | ||
return compareBytes(this._bytes, this.constructor.from(other)._bytes);}, | ||
return compareBytes(this._bytes, this.constructor.from(other)._bytes); | ||
}, | ||
toString: function toString() { | ||
return this.toHex();}, | ||
return this.toHex(); | ||
}, | ||
nibblet: function nibblet(depth) { | ||
@@ -36,11 +36,11 @@ var byte_ix = depth > 0 ? depth / 2 | 0 : 0; | ||
if (depth % 2 === 0) { | ||
b = (b & 0xF0) >>> 4;} else | ||
{ | ||
b = b & 0x0F;} | ||
b = (b & 0xF0) >>> 4; | ||
} else { | ||
b = b & 0x0F; | ||
} | ||
return b; | ||
} }); | ||
return b;} }); | ||
module.exports = { | ||
module.exports = { | ||
Hash: Hash }; |
@@ -1,34 +0,34 @@ | ||
'use strict';var enums = require('../enums');var | ||
Field = enums.Field;var _require = | ||
require('./account-id');var AccountID = _require.AccountID;var _require2 = | ||
require('./amount');var Amount = _require2.Amount;var _require3 = | ||
require('./blob');var Blob = _require3.Blob;var _require4 = | ||
require('./currency');var Currency = _require4.Currency;var _require5 = | ||
require('./hash-128');var Hash128 = _require5.Hash128;var _require6 = | ||
require('./hash-160');var Hash160 = _require6.Hash160;var _require7 = | ||
require('./hash-256');var Hash256 = _require7.Hash256;var _require8 = | ||
require('./path-set');var PathSet = _require8.PathSet;var _require9 = | ||
require('./st-array');var STArray = _require9.STArray;var _require10 = | ||
require('./st-object');var STObject = _require10.STObject;var _require11 = | ||
require('./uint-16');var UInt16 = _require11.UInt16;var _require12 = | ||
require('./uint-32');var UInt32 = _require12.UInt32;var _require13 = | ||
require('./uint-64');var UInt64 = _require13.UInt64;var _require14 = | ||
require('./uint-8');var UInt8 = _require14.UInt8;var _require15 = | ||
require('./vector-256');var Vector256 = _require15.Vector256; | ||
'use strict';var enums = require('../enums');var | ||
Field = enums.Field;var _require = | ||
require('./account-id'),AccountID = _require.AccountID;var _require2 = | ||
require('./amount'),Amount = _require2.Amount;var _require3 = | ||
require('./blob'),Blob = _require3.Blob;var _require4 = | ||
require('./currency'),Currency = _require4.Currency;var _require5 = | ||
require('./hash-128'),Hash128 = _require5.Hash128;var _require6 = | ||
require('./hash-160'),Hash160 = _require6.Hash160;var _require7 = | ||
require('./hash-256'),Hash256 = _require7.Hash256;var _require8 = | ||
require('./path-set'),PathSet = _require8.PathSet;var _require9 = | ||
require('./st-array'),STArray = _require9.STArray;var _require10 = | ||
require('./st-object'),STObject = _require10.STObject;var _require11 = | ||
require('./uint-16'),UInt16 = _require11.UInt16;var _require12 = | ||
require('./uint-32'),UInt32 = _require12.UInt32;var _require13 = | ||
require('./uint-64'),UInt64 = _require13.UInt64;var _require14 = | ||
require('./uint-8'),UInt8 = _require14.UInt8;var _require15 = | ||
require('./vector-256'),Vector256 = _require15.Vector256; | ||
var coreTypes = { | ||
AccountID: AccountID, | ||
Amount: Amount, | ||
Blob: Blob, | ||
Currency: Currency, | ||
Hash128: Hash128, | ||
Hash160: Hash160, | ||
Hash256: Hash256, | ||
PathSet: PathSet, | ||
STArray: STArray, | ||
STObject: STObject, | ||
UInt8: UInt8, | ||
UInt16: UInt16, | ||
UInt32: UInt32, | ||
UInt64: UInt64, | ||
var coreTypes = { | ||
AccountID: AccountID, | ||
Amount: Amount, | ||
Blob: Blob, | ||
Currency: Currency, | ||
Hash128: Hash128, | ||
Hash160: Hash160, | ||
Hash256: Hash256, | ||
PathSet: PathSet, | ||
STArray: STArray, | ||
STObject: STObject, | ||
UInt8: UInt8, | ||
UInt16: UInt16, | ||
UInt32: UInt32, | ||
UInt64: UInt64, | ||
Vector256: Vector256 }; | ||
@@ -38,5 +38,5 @@ | ||
Field.values.forEach(function (field) { | ||
field.associatedType = coreTypes[field.type];}); | ||
field.associatedType = coreTypes[field.type]; | ||
}); | ||
Field.TransactionType.associatedType = enums.TransactionType; | ||
@@ -43,0 +43,0 @@ Field.TransactionResult.associatedType = enums.TransactionResult; |
'use strict'; /* eslint-disable no-unused-expressions */ | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type');var SerializedType = _require.SerializedType;var ensureArrayLikeIs = _require.ensureArrayLikeIs;var _require2 = | ||
require('./currency');var Currency = _require2.Currency;var _require3 = | ||
require('./account-id');var AccountID = _require3.AccountID; | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type'),SerializedType = _require.SerializedType,ensureArrayLikeIs = _require.ensureArrayLikeIs;var _require2 = | ||
require('./currency'),Currency = _require2.Currency;var _require3 = | ||
require('./account-id'),AccountID = _require3.AccountID; | ||
@@ -14,8 +14,8 @@ var PATHSET_END_BYTE = 0x00; | ||
var Hop = makeClass({ | ||
statics: { | ||
var Hop = makeClass({ | ||
statics: { | ||
from: function from(value) { | ||
if (value instanceof this) { | ||
return value;} | ||
return value; | ||
} | ||
var hop = new Hop(); | ||
@@ -25,4 +25,4 @@ value.issuer && (hop.issuer = AccountID.from(value.issuer)); | ||
value.currency && (hop.currency = Currency.from(value.currency)); | ||
return hop;}, | ||
return hop; | ||
}, | ||
parse: function parse(parser, type) { | ||
@@ -33,5 +33,5 @@ var hop = new Hop(); | ||
type & TYPE_ISSUER && (hop.issuer = AccountID.fromParser(parser)); | ||
return hop;} }, | ||
return hop; | ||
} }, | ||
toJSON: function toJSON() { | ||
@@ -43,4 +43,4 @@ var type = this.type(); | ||
type & TYPE_CURRENCY && (ret.currency = this.currency.toJSON()); | ||
return ret;}, | ||
return ret; | ||
}, | ||
type: function type() { | ||
@@ -51,25 +51,25 @@ var type = 0; | ||
this.currency && (type += TYPE_CURRENCY); | ||
return type;} }); | ||
return type; | ||
} }); | ||
var Path = makeClass({ | ||
inherits: Array, | ||
statics: { | ||
var Path = makeClass({ | ||
inherits: Array, | ||
statics: { | ||
from: function from(value) { | ||
return ensureArrayLikeIs(Path, value).withChildren(Hop);} }, | ||
return ensureArrayLikeIs(Path, value).withChildren(Hop); | ||
} }, | ||
toJSON: function toJSON() { | ||
return this.map(function (k) {return k.toJSON();});} }); | ||
return this.map(function (k) {return k.toJSON();}); | ||
} }); | ||
var PathSet = makeClass({ | ||
mixins: SerializedType, | ||
inherits: Array, | ||
statics: { | ||
var PathSet = makeClass({ | ||
mixins: SerializedType, | ||
inherits: Array, | ||
statics: { | ||
from: function from(value) { | ||
return ensureArrayLikeIs(PathSet, value).withChildren(Path);}, | ||
return ensureArrayLikeIs(PathSet, value).withChildren(Path); | ||
}, | ||
fromParser: function fromParser(parser) { | ||
@@ -81,20 +81,20 @@ var pathSet = new this(); | ||
if (type === PATHSET_END_BYTE) { | ||
break;} | ||
break; | ||
} | ||
if (type === PATH_SEPARATOR_BYTE) { | ||
path = null; | ||
continue;} | ||
continue; | ||
} | ||
if (!path) { | ||
path = new Path(); | ||
pathSet.push(path);} | ||
pathSet.push(path); | ||
} | ||
path.push(Hop.parse(parser, type)); | ||
} | ||
return pathSet; | ||
} }, | ||
path.push(Hop.parse(parser, type));} | ||
return pathSet;} }, | ||
toJSON: function toJSON() { | ||
return this.map(function (k) {return k.toJSON();});}, | ||
return this.map(function (k) {return k.toJSON();}); | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
@@ -104,4 +104,4 @@ var n = 0; | ||
if (n++ !== 0) { | ||
sink.put([PATH_SEPARATOR_BYTE]);} | ||
sink.put([PATH_SEPARATOR_BYTE]); | ||
} | ||
path.forEach(function (hop) { | ||
@@ -111,10 +111,10 @@ sink.put([hop.type()]); | ||
hop.currency && hop.currency.toBytesSink(sink); | ||
hop.issuer && hop.issuer.toBytesSink(sink);});}); | ||
hop.issuer && hop.issuer.toBytesSink(sink); | ||
}); | ||
}); | ||
sink.put([PATHSET_END_BYTE]); | ||
} }); | ||
sink.put([PATHSET_END_BYTE]);} }); | ||
module.exports = { | ||
module.exports = { | ||
PathSet: PathSet }; |
@@ -1,63 +0,63 @@ | ||
'use strict';var _require = require('../utils/bytes-utils');var bytesToHex = _require.bytesToHex;var slice = _require.slice;var _require2 = | ||
require('../serdes/binary-serializer');var BytesList = _require2.BytesList; | ||
'use strict';var _require = require('../utils/bytes-utils'),bytesToHex = _require.bytesToHex,slice = _require.slice;var _require2 = | ||
require('../serdes/binary-serializer'),BytesList = _require2.BytesList; | ||
var Comparable = { | ||
var Comparable = { | ||
lt: function lt(other) { | ||
return this.compareTo(other) < 0;}, | ||
return this.compareTo(other) < 0; | ||
}, | ||
eq: function eq(other) { | ||
return this.compareTo(other) === 0;}, | ||
return this.compareTo(other) === 0; | ||
}, | ||
gt: function gt(other) { | ||
return this.compareTo(other) > 0;}, | ||
return this.compareTo(other) > 0; | ||
}, | ||
gte: function gte(other) { | ||
return this.compareTo(other) > -1;}, | ||
return this.compareTo(other) > -1; | ||
}, | ||
lte: function lte(other) { | ||
return this.compareTo(other) < 1;} }; | ||
return this.compareTo(other) < 1; | ||
} }; | ||
var SerializedType = { | ||
var SerializedType = { | ||
toBytesSink: function toBytesSink(sink) { | ||
sink.put(this._bytes);}, | ||
sink.put(this._bytes); | ||
}, | ||
toHex: function toHex() { | ||
return bytesToHex(this.toBytes());}, | ||
return bytesToHex(this.toBytes()); | ||
}, | ||
toBytes: function toBytes() { | ||
if (this._bytes) { | ||
return slice(this._bytes);} | ||
return slice(this._bytes); | ||
} | ||
var bl = new BytesList(); | ||
this.toBytesSink(bl); | ||
return bl.toBytes();}, | ||
return bl.toBytes(); | ||
}, | ||
toJSON: function toJSON() { | ||
return this.toHex();}, | ||
return this.toHex(); | ||
}, | ||
toString: function toString() { | ||
return this.toHex();} }; | ||
return this.toHex(); | ||
} }; | ||
function ensureArrayLikeIs(Type, arrayLike) { | ||
return { | ||
return { | ||
withChildren: function withChildren(Child) { | ||
if (arrayLike instanceof Type) { | ||
return arrayLike;} | ||
return arrayLike; | ||
} | ||
var obj = new Type(); | ||
for (var i = 0; i < arrayLike.length; i++) { | ||
obj.push(Child.from(arrayLike[i]));} | ||
obj.push(Child.from(arrayLike[i])); | ||
} | ||
return obj; | ||
} }; | ||
return obj;} };} | ||
} | ||
module.exports = { | ||
ensureArrayLikeIs: ensureArrayLikeIs, | ||
SerializedType: SerializedType, | ||
module.exports = { | ||
ensureArrayLikeIs: ensureArrayLikeIs, | ||
SerializedType: SerializedType, | ||
Comparable: Comparable }; |
@@ -1,11 +0,11 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type');var ensureArrayLikeIs = _require.ensureArrayLikeIs;var SerializedType = _require.SerializedType;var _require2 = | ||
require('../enums');var Field = _require2.Field;var _require3 = | ||
require('./st-object');var STObject = _require3.STObject;var | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type'),ensureArrayLikeIs = _require.ensureArrayLikeIs,SerializedType = _require.SerializedType;var _require2 = | ||
require('../enums'),Field = _require2.Field;var _require3 = | ||
require('./st-object'),STObject = _require3.STObject;var | ||
ArrayEndMarker = Field.ArrayEndMarker; | ||
var STArray = makeClass({ | ||
mixins: SerializedType, | ||
inherits: Array, | ||
statics: { | ||
var STArray = makeClass({ | ||
mixins: SerializedType, | ||
inherits: Array, | ||
statics: { | ||
fromParser: function fromParser(parser) { | ||
@@ -16,23 +16,23 @@ var array = new STArray(); | ||
if (field === ArrayEndMarker) { | ||
break;} | ||
break; | ||
} | ||
var outer = new STObject(); | ||
outer[field] = parser.readFieldValue(field); | ||
array.push(outer);} | ||
return array;}, | ||
array.push(outer); | ||
} | ||
return array; | ||
}, | ||
from: function from(value) { | ||
return ensureArrayLikeIs(STArray, value).withChildren(STObject);} }, | ||
return ensureArrayLikeIs(STArray, value).withChildren(STObject); | ||
} }, | ||
toJSON: function toJSON() { | ||
return this.map(function (v) {return v.toJSON();});}, | ||
return this.map(function (v) {return v.toJSON();}); | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
this.forEach(function (so) {return so.toBytesSink(sink);});} }); | ||
this.forEach(function (so) {return so.toBytesSink(sink);}); | ||
} }); | ||
module.exports = { | ||
module.exports = { | ||
STArray: STArray }; |
@@ -1,7 +0,7 @@ | ||
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;};var _ = require('lodash'); | ||
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};var _ = require('lodash'); | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('../enums');var Field = _require.Field;var _require2 = | ||
require('../serdes/binary-serializer');var BinarySerializer = _require2.BinarySerializer;var | ||
require('../enums'),Field = _require.Field;var _require2 = | ||
require('../serdes/binary-serializer'),BinarySerializer = _require2.BinarySerializer;var | ||
ObjectEndMarker = Field.ObjectEndMarker;var _require3 = | ||
require('./serialized-type');var SerializedType = _require3.SerializedType; | ||
require('./serialized-type'),SerializedType = _require3.SerializedType; | ||
@@ -17,12 +17,12 @@ var STObject = makeClass({ | ||
if (field === ObjectEndMarker) { | ||
break;} | ||
so[field] = parser.readFieldValue(field);} | ||
return so;}, | ||
break; | ||
} | ||
so[field] = parser.readFieldValue(field); | ||
} | ||
return so; | ||
}, | ||
from: function from(value) { | ||
if (value instanceof this) { | ||
return value;} | ||
return value; | ||
} | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
@@ -32,16 +32,14 @@ return _.transform(value, function (so, val, key) { | ||
if (field) { | ||
so[field] = field.associatedType.from(val) | ||
so[field] = field.associatedType.from(val); | ||
} else { | ||
so[key] = val; | ||
} | ||
}, | ||
new this()); | ||
}, new this()); | ||
} | ||
throw new Error(value + ' is unsupported'); | ||
} }, | ||
throw new Error(value + ' is unsupported');} }, | ||
fieldKeys: function fieldKeys() { | ||
return Object.keys(this).map(function (k) {return Field[k];}).filter(Boolean);}, | ||
return Object.keys(this).map(function (k) {return Field[k];}).filter(Boolean); | ||
}, | ||
toJSON: function toJSON() { | ||
@@ -51,6 +49,6 @@ // Otherwise seemingly result will have same prototype as `this` | ||
return _.transform(this, function (result, value, key) { | ||
result[key] = value && value.toJSON ? value.toJSON() : value;}, | ||
accumulator);}, | ||
toBytesSink: function toBytesSink(sink) {var _this = this;var filter = arguments.length <= 1 || arguments[1] === undefined ? function () {return true;} : arguments[1]; | ||
result[key] = value && value.toJSON ? value.toJSON() : value; | ||
}, accumulator); | ||
}, | ||
toBytesSink: function toBytesSink(sink) {var _this = this;var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {return true;}; | ||
var serializer = new BinarySerializer(sink); | ||
@@ -62,10 +60,10 @@ var fields = this.fieldKeys(); | ||
if (!field.isSerialized) { | ||
return;} | ||
return; | ||
} | ||
serializer.writeFieldAndValue(field, value); | ||
}); | ||
} }); | ||
serializer.writeFieldAndValue(field, value);});} }); | ||
module.exports = { | ||
STObject: STObject }; | ||
STObject: STObject }; |
@@ -1,10 +0,10 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./uint');var UInt = _require.UInt; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./uint'),UInt = _require.UInt; | ||
var UInt16 = makeClass({ | ||
inherits: UInt, | ||
var UInt16 = makeClass({ | ||
inherits: UInt, | ||
statics: { width: 2 } }); | ||
module.exports = { | ||
module.exports = { | ||
UInt16: UInt16 }; |
@@ -1,10 +0,10 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./uint');var UInt = _require.UInt; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./uint'),UInt = _require.UInt; | ||
var UInt32 = makeClass({ | ||
inherits: UInt, | ||
var UInt32 = makeClass({ | ||
inherits: UInt, | ||
statics: { width: 4 } }); | ||
module.exports = { | ||
module.exports = { | ||
UInt32: UInt32 }; |
@@ -1,14 +0,14 @@ | ||
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;};var assert = require('assert'); | ||
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};var assert = require('assert'); | ||
var BN = require('bn.js'); | ||
var makeClass = require('../utils/make-class');var _require = | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('../utils/bytes-utils');var bytesToHex = _require.bytesToHex;var parseBytes = _require.parseBytes;var serializeUIntN = _require.serializeUIntN;var _require2 = | ||
require('./uint');var UInt = _require2.UInt; | ||
require('../utils/bytes-utils'),bytesToHex = _require.bytesToHex,parseBytes = _require.parseBytes,serializeUIntN = _require.serializeUIntN;var _require2 = | ||
require('./uint'),UInt = _require2.UInt; | ||
var HEX_REGEX = /^[A-F0-9]{16}$/; | ||
var UInt64 = makeClass({ | ||
inherits: UInt, | ||
statics: { width: 8 }, | ||
UInt64: function UInt64() {var arg = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; | ||
var UInt64 = makeClass({ | ||
inherits: UInt, | ||
statics: { width: 8 }, | ||
UInt64: function UInt64() {var arg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var argType = typeof arg === 'undefined' ? 'undefined' : _typeof(arg); | ||
@@ -18,33 +18,33 @@ if (argType === 'number') { | ||
this._bytes = new Uint8Array(8); | ||
this._bytes.set(serializeUIntN(arg, 4), 4);} else | ||
if (arg instanceof BN) { | ||
this._bytes.set(serializeUIntN(arg, 4), 4); | ||
} else if (arg instanceof BN) { | ||
this._bytes = parseBytes(arg.toArray('be', 8), Uint8Array); | ||
this._toBN = arg;} else | ||
{ | ||
this._toBN = arg; | ||
} else { | ||
if (argType === 'string') { | ||
if (!HEX_REGEX.test(arg)) { | ||
throw new Error(arg + ' is not a valid UInt64 hex string');}} | ||
this._bytes = parseBytes(arg, Uint8Array);} | ||
assert(this._bytes.length === 8);}, | ||
throw new Error(arg + ' is not a valid UInt64 hex string'); | ||
} | ||
} | ||
this._bytes = parseBytes(arg, Uint8Array); | ||
} | ||
assert(this._bytes.length === 8); | ||
}, | ||
toJSON: function toJSON() { | ||
return bytesToHex(this._bytes);}, | ||
return bytesToHex(this._bytes); | ||
}, | ||
valueOf: function valueOf() { | ||
return this.toBN();}, | ||
cached: { | ||
return this.toBN(); | ||
}, | ||
cached: { | ||
toBN: function toBN() { | ||
return new BN(this._bytes);} }, | ||
return new BN(this._bytes); | ||
} }, | ||
toBytes: function toBytes() { | ||
return this._bytes;} }); | ||
return this._bytes; | ||
} }); | ||
module.exports = { | ||
module.exports = { | ||
UInt64: UInt64 }; |
@@ -1,10 +0,10 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./uint');var UInt = _require.UInt; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./uint'),UInt = _require.UInt; | ||
var UInt8 = makeClass({ | ||
inherits: UInt, | ||
var UInt8 = makeClass({ | ||
inherits: UInt, | ||
statics: { width: 1 } }); | ||
module.exports = { | ||
module.exports = { | ||
UInt8: UInt8 }; |
'use strict';var assert = require('assert'); | ||
var BN = require('bn.js'); | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type');var Comparable = _require.Comparable;var SerializedType = _require.SerializedType;var _require2 = | ||
require('../utils/bytes-utils');var serializeUIntN = _require2.serializeUIntN; | ||
var makeClass = require('../utils/make-class');var _require = | ||
require('./serialized-type'),Comparable = _require.Comparable,SerializedType = _require.SerializedType;var _require2 = | ||
require('../utils/bytes-utils'),serializeUIntN = _require2.serializeUIntN; | ||
var MAX_VALUES = [0, 255, 65535, 16777215, 4294967295]; | ||
function signum(a, b) { | ||
return a < b ? -1 : a === b ? 0 : 1;} | ||
return a < b ? -1 : a === b ? 0 : 1; | ||
} | ||
var UInt = makeClass({ | ||
mixins: [Comparable, SerializedType], | ||
UInt: function UInt() {var val = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; | ||
var UInt = makeClass({ | ||
mixins: [Comparable, SerializedType], | ||
UInt: function UInt() {var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var max = MAX_VALUES[this.constructor.width]; | ||
if (val < 0 || !(val <= max)) { | ||
throw new Error(val + ' not in range 0 <= $val <= ' + max);} | ||
this.val = val;}, | ||
statics: { | ||
width: 0, | ||
throw new Error(val + ' not in range 0 <= $val <= ' + max); | ||
} | ||
this.val = val; | ||
}, | ||
statics: { | ||
width: 0, | ||
fromParser: function fromParser(parser) { | ||
var val = this.width > 4 ? parser.read(this.width) : | ||
var val = this.width > 4 ? parser.read(this.width) : | ||
parser.readUIntN(this.width); | ||
return new this(val);}, | ||
return new this(val); | ||
}, | ||
from: function from(val) { | ||
return val instanceof this ? val : new this(val);} }, | ||
return val instanceof this ? val : new this(val); | ||
} }, | ||
toJSON: function toJSON() { | ||
return this.val;}, | ||
return this.val; | ||
}, | ||
valueOf: function valueOf() { | ||
return this.val;}, | ||
return this.val; | ||
}, | ||
compareTo: function compareTo(other) { | ||
@@ -42,20 +42,20 @@ var thisValue = this.valueOf(); | ||
if (thisValue instanceof BN) { | ||
return otherValue instanceof BN ? | ||
thisValue.cmp(otherValue) : | ||
thisValue.cmpn(otherValue);} else | ||
if (otherValue instanceof BN) { | ||
return -other.compareTo(this);} | ||
return otherValue instanceof BN ? | ||
thisValue.cmp(otherValue) : | ||
thisValue.cmpn(otherValue); | ||
} else if (otherValue instanceof BN) { | ||
return -other.compareTo(this); | ||
} | ||
assert(typeof otherValue === 'number'); | ||
return signum(thisValue, otherValue);}, | ||
return signum(thisValue, otherValue); | ||
}, | ||
toBytesSink: function toBytesSink(sink) { | ||
sink.put(this.toBytes());}, | ||
sink.put(this.toBytes()); | ||
}, | ||
toBytes: function toBytes() { | ||
return serializeUIntN(this.val, this.constructor.width);} }); | ||
return serializeUIntN(this.val, this.constructor.width); | ||
} }); | ||
module.exports = { | ||
module.exports = { | ||
UInt: UInt }; |
@@ -1,9 +0,9 @@ | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash-256');var Hash256 = _require.Hash256;var _require2 = | ||
require('./serialized-type');var ensureArrayLikeIs = _require2.ensureArrayLikeIs;var SerializedType = _require2.SerializedType; | ||
'use strict';var makeClass = require('../utils/make-class');var _require = | ||
require('./hash-256'),Hash256 = _require.Hash256;var _require2 = | ||
require('./serialized-type'),ensureArrayLikeIs = _require2.ensureArrayLikeIs,SerializedType = _require2.SerializedType; | ||
var Vector256 = makeClass({ | ||
mixins: SerializedType, | ||
inherits: Array, | ||
statics: { | ||
var Vector256 = makeClass({ | ||
mixins: SerializedType, | ||
inherits: Array, | ||
statics: { | ||
fromParser: function fromParser(parser, hint) { | ||
@@ -14,19 +14,19 @@ var vector256 = new this(); | ||
for (var i = 0; i < hashes; i++) { | ||
vector256.push(Hash256.fromParser(parser));} | ||
return vector256;}, | ||
vector256.push(Hash256.fromParser(parser)); | ||
} | ||
return vector256; | ||
}, | ||
from: function from(value) { | ||
return ensureArrayLikeIs(Vector256, value).withChildren(Hash256);} }, | ||
return ensureArrayLikeIs(Vector256, value).withChildren(Hash256); | ||
} }, | ||
toBytesSink: function toBytesSink(sink) { | ||
this.forEach(function (h) {return h.toBytesSink(sink);});}, | ||
this.forEach(function (h) {return h.toBytesSink(sink);}); | ||
}, | ||
toJSON: function toJSON() { | ||
return this.map(function (hash) {return hash.toJSON();});} }); | ||
return this.map(function (hash) {return hash.toJSON();}); | ||
} }); | ||
module.exports = { | ||
module.exports = { | ||
Vector256: Vector256 }; |
'use strict';var assert = require('assert'); | ||
function signum(a, b) { | ||
return a < b ? -1 : a === b ? 0 : 1;} | ||
return a < b ? -1 : a === b ? 0 : 1; | ||
} | ||
var hexLookup = function () { | ||
@@ -19,6 +19,8 @@ var res = {}; | ||
res[byteHex] = byte; | ||
reverse[byte] = byteHex;}} | ||
return res;}(); | ||
reverse[byte] = byteHex; | ||
} | ||
} | ||
return res; | ||
}(); | ||
var reverseHexLookup = hexLookup.reverse; | ||
@@ -34,3 +36,2 @@ | ||
function byteForHex(hex) { | ||
@@ -44,7 +45,7 @@ var byte = hexLookup[hex]; | ||
function parseBytes(val) {var Output = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Array; | ||
if (!val || val.length === undefined) { | ||
throw new Error(val + ' is not a sequence'); | ||
} | ||
function parseBytes(val) { | ||
var Output = arguments.length <= 1 || arguments[1] === undefined ? Array : arguments[1]; | ||
if (!val || val.length === undefined) { | ||
throw new Error(val + ' is not a sequence');} | ||
if (typeof val === 'string') { | ||
@@ -72,3 +73,2 @@ var start = val.length % 2; | ||
function serializeUIntN(val, width) { | ||
@@ -78,7 +78,7 @@ var newBytes = new Uint8Array(width); | ||
for (var i = 0; i < width; i++) { | ||
newBytes[lastIx - i] = val >>> i * 8 & 0xff;} | ||
newBytes[lastIx - i] = val >>> i * 8 & 0xff; | ||
} | ||
return newBytes; | ||
} | ||
return newBytes;} | ||
function compareBytes(a, b) { | ||
@@ -89,16 +89,16 @@ assert(a.length === b.length); | ||
if (cmp !== 0) { | ||
return cmp;}} | ||
return cmp; | ||
} | ||
} | ||
return 0; | ||
} | ||
return 0;} | ||
function slice(val) {var startIx = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];var endIx = arguments.length <= 2 || arguments[2] === undefined ? val.length : arguments[2];var Output = arguments.length <= 3 || arguments[3] === undefined ? val.constructor : arguments[3]; | ||
function slice(val) {var startIx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;var endIx = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : val.length;var Output = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : val.constructor; | ||
/* eslint-disable no-param-reassign*/ | ||
if (startIx < 0) { | ||
startIx += val.length;} | ||
startIx += val.length; | ||
} | ||
if (endIx < 0) { | ||
endIx += val.length;} | ||
endIx += val.length; | ||
} | ||
/* eslint-enable no-param-reassign*/ | ||
@@ -108,7 +108,7 @@ var len = endIx - startIx; | ||
for (var i = endIx - 1; i >= startIx; i--) { | ||
res[i - startIx] = val[i];} | ||
res[i - startIx] = val[i]; | ||
} | ||
return res; | ||
} | ||
return res;} | ||
module.exports = { | ||
@@ -119,2 +119,2 @@ parseBytes: parseBytes, | ||
compareBytes: compareBytes, | ||
serializeUIntN: serializeUIntN }; | ||
serializeUIntN: serializeUIntN }; |
@@ -6,10 +6,10 @@ 'use strict';var _ = require('lodash'); | ||
Object.keys(obj || {}).forEach(function (k) { | ||
func(obj[k], k);});} | ||
func(obj[k], k); | ||
}); | ||
} | ||
function ensureArray(val) { | ||
return Array.isArray(val) ? val : [val];} | ||
return Array.isArray(val) ? val : [val]; | ||
} | ||
module.exports = function makeClass(klass_, definition_) { | ||
@@ -22,6 +22,6 @@ var definition = definition_ || klass_; | ||
klass = definition[k]; | ||
break;}}} | ||
break; | ||
} | ||
} | ||
} | ||
var parent = definition.inherits; | ||
@@ -31,36 +31,36 @@ if (parent) { | ||
klass = function klass() { | ||
parent.apply(this, arguments);};} | ||
parent.apply(this, arguments); | ||
}; | ||
} | ||
inherits(klass, parent); | ||
_.defaults(klass, parent);} | ||
_.defaults(klass, parent); | ||
} | ||
if (klass === null) { | ||
klass = function klass() {};} | ||
klass = function klass() {}; | ||
} | ||
var proto = klass.prototype; | ||
function addFunc(original, name, wrapper) { | ||
proto[name] = wrapper || original;} | ||
proto[name] = wrapper || original; | ||
} | ||
(definition.getters || []).forEach(function (k) { | ||
var key = '_' + k; | ||
proto[k] = function () { | ||
return this[key];};}); | ||
return this[key]; | ||
}; | ||
}); | ||
forEach(definition.virtuals, function (f, n) { | ||
addFunc(f, n, function () { | ||
throw new Error('unimplemented');});}); | ||
throw new Error('unimplemented'); | ||
}); | ||
}); | ||
forEach(definition.methods, addFunc); | ||
forEach(definition, function (f, n) { | ||
if (_.isFunction(f) && f !== klass) { | ||
addFunc(f, n);}}); | ||
addFunc(f, n); | ||
} | ||
}); | ||
_.assign(klass, definition.statics); | ||
if (typeof klass.init === 'function') { | ||
klass.init();} | ||
klass.init(); | ||
} | ||
forEach(definition.cached, function (f, n) { | ||
@@ -71,16 +71,17 @@ var key = '_' + n; | ||
if (value === undefined) { | ||
value = this[key] = f.call(this);} | ||
value = this[key] = f.call(this); | ||
} | ||
return value; | ||
}); | ||
}); | ||
if (definition.mixins) { | ||
var mixins = {}; | ||
// Right-most in the list win | ||
ensureArray(definition.mixins).reverse().forEach(function (o) { | ||
_.defaults(mixins, o); | ||
}); | ||
_.defaults(proto, mixins); | ||
} | ||
return value;});}); | ||
if (definition.mixins) {(function () { | ||
var mixins = {}; | ||
// Right-most in the list win | ||
ensureArray(definition.mixins).reverse().forEach(function (o) { | ||
_.defaults(mixins, o);}); | ||
_.defaults(proto, mixins);})();} | ||
return klass;}; | ||
return klass; | ||
}; |
{ | ||
"name": "call-binary-codec", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "call binary codec", | ||
"keywords": [], | ||
"files": [ | ||
"distrib/npm/*", | ||
"bin/*", | ||
"test/*" | ||
], | ||
"main": "distrib/npm/", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": { | ||
@@ -30,8 +38,22 @@ "babel-runtime": "^6.6.1", | ||
}, | ||
"scripts": { | ||
"compile": "babel --optional runtime -d distrib/npm/ src/ && cp src/enums/definitions.json distrib/npm/enums", | ||
"prepublish": "npm test && npm run lint && npm run compile", | ||
"test": "istanbul test _mocha", | ||
"codecov": "cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js", | ||
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/call/javascript-style-guide/es6/eslintrc'; echo 'parser: babel-eslint' >> eslintrc; fi; eslint -c eslintrc src/**/*.js test/*.js examples/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/call/call-binary-codec.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.12.0" | ||
}, | ||
"main": "distrib/npm/", | ||
"bugs": { | ||
"url": "https://github.com/call/call-binary-codec/issues" | ||
}, | ||
"homepage": "https://github.com/call/call-binary-codec#readme", | ||
"author": "dev@callchain.live", | ||
"license": "ISC" | ||
} | ||
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
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances 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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
905349
77
13321
2
1
6
3
3