Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cardano-foundation/ledgerjs-hw-app-cardano

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardano-foundation/ledgerjs-hw-app-cardano - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

755

lib/Ada.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.utils = exports.getErrorDescription = exports.ErrorCodes = undefined;
Object.defineProperty(exports, "utils", {
enumerable: true,
get: function get() {
return _utils["default"];
}
});
exports["default"] = exports.getErrorDescription = exports.ErrorCodes = void 0;
var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray");
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _createClass2 = require("babel-runtime/helpers/createClass");
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _createClass3 = _interopRequireDefault(_createClass2);
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _regenerator = require("babel-runtime/regenerator");
var _hwTransport = require("@ledgerhq/hw-transport");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _utils = _interopRequireWildcard(require("./utils"));
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
var _ErrorMsgs;
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
var _defineProperty2 = require("babel-runtime/helpers/defineProperty");
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var _ErrorMsgs; /********************************************************************************
* Ledger Node JS API
* (c) 2016-2017 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
var _hwTransport = require("@ledgerhq/hw-transport");
var _utils = require("./utils");
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var CLA = 0xd7;
var INS = {
GET_VERSION: 0x00,
GET_EXT_PUBLIC_KEY: 0x10,
DERIVE_ADDRESS: 0x11,
ATTEST_UTXO: 0x20,
SIGN_TX: 0x21,
RUN_TESTS: 0xf0
};
var ErrorCodes = exports.ErrorCodes = {
ERR_STILL_IN_CALL: 0x6e04, // internal
var ErrorCodes = {
ERR_STILL_IN_CALL: 0x6e04,
// internal
ERR_INVALID_DATA: 0x6e07,

@@ -79,19 +59,14 @@ ERR_INVALID_BIP_PATH: 0x6e08,

ERR_DEVICE_LOCKED: 0x6e11,
// Not thrown by ledger-app-cardano itself but other apps
ERR_CLA_NOT_SUPPORTED: 0x6e00
};
exports.ErrorCodes = ErrorCodes;
var GH_ERRORS_LINK = "https://github.com/cardano-foundation/ledger-app-cardano/blob/master/src/errors.h";
var ErrorMsgs = (_ErrorMsgs = {}, (0, _defineProperty2["default"])(_ErrorMsgs, ErrorCodes.ERR_INVALID_DATA, "Invalid data supplied to Ledger"), (0, _defineProperty2["default"])(_ErrorMsgs, ErrorCodes.ERR_INVALID_BIP_PATH, "Invalid derivation path supplied to Ledger"), (0, _defineProperty2["default"])(_ErrorMsgs, ErrorCodes.ERR_REJECTED_BY_USER, "Action rejected by user"), (0, _defineProperty2["default"])(_ErrorMsgs, ErrorCodes.ERR_REJECTED_BY_POLICY, "Action rejected by Ledger's security policy"), (0, _defineProperty2["default"])(_ErrorMsgs, ErrorCodes.ERR_DEVICE_LOCKED, "Device is locked"), (0, _defineProperty2["default"])(_ErrorMsgs, ErrorCodes.ERR_CLA_NOT_SUPPORTED, "Wrong Ledger app"), _ErrorMsgs);
var ErrorMsgs = (_ErrorMsgs = {}, (0, _defineProperty3.default)(_ErrorMsgs, ErrorCodes.ERR_INVALID_DATA, "Invalid data supplied to Ledger"), (0, _defineProperty3.default)(_ErrorMsgs, ErrorCodes.ERR_INVALID_BIP_PATH, "Invalid derivation path supplied to Ledger"), (0, _defineProperty3.default)(_ErrorMsgs, ErrorCodes.ERR_REJECTED_BY_USER, "Action rejected by user"), (0, _defineProperty3.default)(_ErrorMsgs, ErrorCodes.ERR_REJECTED_BY_POLICY, "Action rejected by Ledger's security policy"), (0, _defineProperty3.default)(_ErrorMsgs, ErrorCodes.ERR_DEVICE_LOCKED, "Device is locked"), (0, _defineProperty3.default)(_ErrorMsgs, ErrorCodes.ERR_CLA_NOT_SUPPORTED, "Wrong Ledger app"), _ErrorMsgs);
var getErrorDescription = exports.getErrorDescription = function getErrorDescription(statusCode) {
var statusCodeHex = "0x" + statusCode.toString(16);
var defaultMsg = "General error " + statusCodeHex + ". Please consult " + GH_ERRORS_LINK;
var getErrorDescription = function getErrorDescription(statusCode) {
var statusCodeHex = "0x".concat(statusCode.toString(16));
var defaultMsg = "General error ".concat(statusCodeHex, ". Please consult ").concat(GH_ERRORS_LINK);
return ErrorMsgs[statusCode] || defaultMsg;
};
// It can happen that we try to send a message to the device
}; // It can happen that we try to send a message to the device
// when the device thinks it is still in a middle of previous ADPU stream.

@@ -103,87 +78,80 @@ // This happens mostly if host does abort communication for some reason

// Note though that only the *first* request in an multi-APDU exchange should be retried.
exports.getErrorDescription = getErrorDescription;
var wrapRetryStillInCall = function wrapRetryStillInCall(fn) {
return function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var _args = arguments;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return fn.apply(undefined, _args);
return /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var _args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return fn.apply(void 0, _args);
case 3:
return _context.abrupt("return", _context.sent);
case 3:
return _context.abrupt("return", _context.sent);
case 6:
_context.prev = 6;
_context.t0 = _context["catch"](0);
case 6:
_context.prev = 6;
_context.t0 = _context["catch"](0);
if (!(_context.t0 && _context.t0.statusCode && _context.t0.statusCode === ErrorCodes.ERR_STILL_IN_CALL)) {
_context.next = 12;
break;
}
if (!(_context.t0 && _context.t0.statusCode && _context.t0.statusCode === ErrorCodes.ERR_STILL_IN_CALL)) {
_context.next = 12;
break;
}
_context.next = 11;
return fn.apply(undefined, _args);
_context.next = 11;
return fn.apply(void 0, _args);
case 11:
return _context.abrupt("return", _context.sent);
case 11:
return _context.abrupt("return", _context.sent);
case 12:
throw _context.t0;
case 12:
throw _context.t0;
case 13:
case "end":
return _context.stop();
}
case 13:
case "end":
return _context.stop();
}
}, _callee, undefined, [[0, 6]]);
}));
return function () {
return _ref.apply(this, arguments);
};
}();
}
}, _callee, null, [[0, 6]]);
}));
};
var wrapConvertError = function wrapConvertError(fn) {
return function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var _args2 = arguments;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return fn.apply(undefined, _args2);
return /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
var _args2 = arguments;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return fn.apply(void 0, _args2);
case 3:
return _context2.abrupt("return", _context2.sent);
case 3:
return _context2.abrupt("return", _context2.sent);
case 6:
_context2.prev = 6;
_context2.t0 = _context2["catch"](0);
case 6:
_context2.prev = 6;
_context2.t0 = _context2["catch"](0);
if (_context2.t0 && _context2.t0.statusCode) {
// keep HwTransport.TransportStatusError
// just override the message
_context2.t0.message = "Ledger device: " + getErrorDescription(_context2.t0.statusCode);
}
throw _context2.t0;
if (_context2.t0 && _context2.t0.statusCode) {
// keep HwTransport.TransportStatusError
// just override the message
_context2.t0.message = "Ledger device: ".concat(getErrorDescription(_context2.t0.statusCode));
}
case 10:
case "end":
return _context2.stop();
}
throw _context2.t0;
case 10:
case "end":
return _context2.stop();
}
}, _callee2, undefined, [[0, 6]]);
}));
return function () {
return _ref2.apply(this, arguments);
};
}();
}
}, _callee2, null, [[0, 6]]);
}));
};

@@ -198,7 +166,7 @@ /**

var Ada = function () {
var Ada = /*#__PURE__*/function () {
function Ada(transport) {
var scrambleKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "ADA";
(0, _classCallCheck3.default)(this, Ada);
(0, _classCallCheck2["default"])(this, Ada);
this.transport = transport;

@@ -209,3 +177,2 @@ this.methods = ["getVersion", "getExtendedPublicKey", "signTransaction", "deriveAddress", "showAddress"];

}
/**

@@ -223,6 +190,6 @@ * Returns an object containing the app version.

(0, _createClass3.default)(Ada, [{
(0, _createClass2["default"])(Ada, [{
key: "getVersion",
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
var _getVersion = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
var _this = this;

@@ -232,3 +199,3 @@

return _regenerator2.default.wrap(function _callee3$(_context3) {
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {

@@ -238,3 +205,3 @@ switch (_context3.prev = _context3.next) {

_send = function _send(p1, p2, data) {
return _this.send(CLA, INS.GET_VERSION, p1, p2, data).then(_utils2.default.stripRetcodeFromResponse);
return _this.send(CLA, INS.GET_VERSION, p1, p2, data).then(_utils["default"].stripRetcodeFromResponse);
};

@@ -245,3 +212,3 @@

_context3.next = 5;
return wrapRetryStillInCall(_send)(P1_UNUSED, P2_UNUSED, _utils2.default.hex_to_buf(""));
return wrapRetryStillInCall(_send)(P1_UNUSED, P2_UNUSED, _utils["default"].hex_to_buf(""));

@@ -252,10 +219,15 @@ case 5:

_utils.Assert.assert(response.length == 4);
_response = (0, _slicedToArray3.default)(response, 4), major = _response[0], minor = _response[1], patch = _response[2], flags_value = _response[3];
FLAG_IS_DEBUG = 1;
//const FLAG_IS_HEADLESS = 2;
_response = (0, _slicedToArray2["default"])(response, 4), major = _response[0], minor = _response[1], patch = _response[2], flags_value = _response[3];
FLAG_IS_DEBUG = 1; //const FLAG_IS_HEADLESS = 2;
flags = {
isDebug: (flags_value & FLAG_IS_DEBUG) == FLAG_IS_DEBUG
};
return _context3.abrupt("return", { major: major, minor: minor, patch: patch, flags: flags });
return _context3.abrupt("return", {
major: major,
minor: minor,
patch: patch,
flags: flags
});

@@ -267,7 +239,7 @@ case 11:

}
}, _callee3, this);
}, _callee3);
}));
function getVersion() {
return _ref3.apply(this, arguments);
return _getVersion.apply(this, arguments);
}

@@ -277,3 +249,2 @@

}()
/**

@@ -288,4 +259,4 @@ * Runs unit tests on the device (DEVEL app build only)

value: function () {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
return _regenerator2.default.wrap(function _callee4$(_context4) {
var _runTests = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {

@@ -306,3 +277,3 @@ switch (_context4.prev = _context4.next) {

function runTests() {
return _ref4.apply(this, arguments);
return _runTests.apply(this, arguments);
}

@@ -315,3 +286,3 @@

value: function () {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(txDataHex, outputIndex) {
var _attestUtxo2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(txDataHex, outputIndex) {
var _this2 = this;

@@ -321,3 +292,3 @@

return _regenerator2.default.wrap(function _callee5$(_context5) {
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {

@@ -327,6 +298,7 @@ switch (_context5.prev = _context5.next) {

_utils.Precondition.checkIsHexString(txDataHex);
_utils.Precondition.checkIsUint32(outputIndex);
_send = function _send(p1, p2, data) {
return _this2.send(CLA, INS.ATTEST_UTXO, p1, p2, data).then(_utils2.default.stripRetcodeFromResponse);
return _this2.send(CLA, INS.ATTEST_UTXO, p1, p2, data).then(_utils["default"].stripRetcodeFromResponse);
};

@@ -336,11 +308,8 @@

P1_CONTINUE = 0x02;
P2_UNUSED = 0x00;
// Note: U2F transport does not like APDU length longer than 255
P2_UNUSED = 0x00; // Note: U2F transport does not like APDU length longer than 255
// so we are leaving it some space
CHUNK_SIZE = 245;
// Initial request
data = _utils2.default.uint32_to_buf(outputIndex);
data = _utils["default"].uint32_to_buf(outputIndex);
_context5.next = 10;

@@ -353,3 +322,4 @@ return wrapRetryStillInCall(_send)(P1_INIT, P2_UNUSED, data);

_utils.Assert.assert(result.length == 0);
txData = _utils2.default.hex_to_buf(txDataHex);
txData = _utils["default"].hex_to_buf(txDataHex);
i = 0;

@@ -371,2 +341,3 @@

_utils.Assert.assert(_result.length == 0);
i += CHUNK_SIZE;

@@ -394,9 +365,9 @@ _context5.next = 14;

_utils$chunkBy = _utils2.default.chunkBy(_result2, sizes), _utils$chunkBy2 = (0, _slicedToArray3.default)(_utils$chunkBy, 4), txHash = _utils$chunkBy2[0], outputNumber = _utils$chunkBy2[1], amount = _utils$chunkBy2[2], hmac = _utils$chunkBy2[3];
_utils$chunkBy = _utils["default"].chunkBy(_result2, sizes), _utils$chunkBy2 = (0, _slicedToArray2["default"])(_utils$chunkBy, 4), txHash = _utils$chunkBy2[0], outputNumber = _utils$chunkBy2[1], amount = _utils$chunkBy2[2], hmac = _utils$chunkBy2[3];
return _context5.abrupt("return", {
rawBuffer: _result2,
txHashHex: _utils2.default.buf_to_hex(txHash),
outputIndex: _utils2.default.buf_to_uint32(outputNumber),
amountStr: _utils2.default.buf_to_amount(amount),
hmacHex: _utils2.default.buf_to_hex(hmac)
txHashHex: _utils["default"].buf_to_hex(txHash),
outputIndex: _utils["default"].buf_to_uint32(outputNumber),
amountStr: _utils["default"].buf_to_amount(amount),
hmacHex: _utils["default"].buf_to_hex(hmac)
});

@@ -409,7 +380,7 @@

}
}, _callee5, this);
}, _callee5);
}));
function _attestUtxo(_x2, _x3) {
return _ref5.apply(this, arguments);
function _attestUtxo(_x, _x2) {
return _attestUtxo2.apply(this, arguments);
}

@@ -419,3 +390,2 @@

}()
/**

@@ -430,4 +400,4 @@ * @param string Raw transaction data (without witnesses) encoded as hex string

value: function () {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(txDataHex, outputIndex) {
return _regenerator2.default.wrap(function _callee6$(_context6) {
var _attestUtxo3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(txDataHex, outputIndex) {
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) {

@@ -446,4 +416,4 @@ switch (_context6.prev = _context6.next) {

function attestUtxo(_x4, _x5) {
return _ref6.apply(this, arguments);
function attestUtxo(_x3, _x4) {
return _attestUtxo3.apply(this, arguments);
}

@@ -453,3 +423,2 @@

}()
/**

@@ -470,3 +439,3 @@ * @description Get a public key from the specified BIP 32 path.

value: function () {
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(path) {
var _getExtendedPublicKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(path) {
var _this3 = this;

@@ -476,3 +445,3 @@

return _regenerator2.default.wrap(function _callee7$(_context7) {
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) {

@@ -484,3 +453,3 @@ switch (_context7.prev = _context7.next) {

_send = function _send(p1, p2, data) {
return _this3.send(CLA, INS.GET_EXT_PUBLIC_KEY, p1, p2, data).then(_utils2.default.stripRetcodeFromResponse);
return _this3.send(CLA, INS.GET_EXT_PUBLIC_KEY, p1, p2, data).then(_utils["default"].stripRetcodeFromResponse);
};

@@ -490,3 +459,3 @@

P2_UNUSED = 0x00;
data = _utils2.default.path_to_buf(path);
data = _utils["default"].path_to_buf(path);
_context7.next = 7;

@@ -497,3 +466,3 @@ return wrapRetryStillInCall(_send)(P1_UNUSED, P2_UNUSED, data);

response = _context7.sent;
_utils$chunkBy3 = _utils2.default.chunkBy(response, [32, 32]), _utils$chunkBy4 = (0, _slicedToArray3.default)(_utils$chunkBy3, 3), publicKey = _utils$chunkBy4[0], chainCode = _utils$chunkBy4[1], rest = _utils$chunkBy4[2];
_utils$chunkBy3 = _utils["default"].chunkBy(response, [32, 32]), _utils$chunkBy4 = (0, _slicedToArray2["default"])(_utils$chunkBy3, 3), publicKey = _utils$chunkBy4[0], chainCode = _utils$chunkBy4[1], rest = _utils$chunkBy4[2];

@@ -512,7 +481,7 @@ _utils.Assert.assert(rest.length == 0);

}
}, _callee7, this);
}, _callee7);
}));
function getExtendedPublicKey(_x6) {
return _ref7.apply(this, arguments);
function getExtendedPublicKey(_x5) {
return _getExtendedPublicKey.apply(this, arguments);
}

@@ -522,3 +491,2 @@

}()
/**

@@ -542,3 +510,3 @@ * @description Gets an address from the specified BIP 32 path.

value: function () {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(path) {
var _deriveAddress = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(path) {
var _this4 = this;

@@ -548,3 +516,3 @@

return _regenerator2.default.wrap(function _callee8$(_context8) {
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) {

@@ -556,3 +524,3 @@ switch (_context8.prev = _context8.next) {

_send = function _send(p1, p2, data) {
return _this4.send(CLA, INS.DERIVE_ADDRESS, p1, p2, data).then(_utils2.default.stripRetcodeFromResponse);
return _this4.send(CLA, INS.DERIVE_ADDRESS, p1, p2, data).then(_utils["default"].stripRetcodeFromResponse);
};

@@ -562,3 +530,3 @@

P2_UNUSED = 0x00;
data = _utils2.default.path_to_buf(path);
data = _utils["default"].path_to_buf(path);
_context8.next = 7;

@@ -570,3 +538,3 @@ return _send(P1_RETURN, P2_UNUSED, data);

return _context8.abrupt("return", {
address58: _utils2.default.base58_encode(response)
address58: _utils["default"].base58_encode(response)
});

@@ -579,7 +547,7 @@

}
}, _callee8, this);
}, _callee8);
}));
function deriveAddress(_x7) {
return _ref8.apply(this, arguments);
function deriveAddress(_x6) {
return _deriveAddress.apply(this, arguments);
}

@@ -592,3 +560,3 @@

value: function () {
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(path) {
var _showAddress = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(path) {
var _this5 = this;

@@ -598,3 +566,3 @@

return _regenerator2.default.wrap(function _callee9$(_context9) {
return _regenerator["default"].wrap(function _callee9$(_context9) {
while (1) {

@@ -606,3 +574,3 @@ switch (_context9.prev = _context9.next) {

_send = function _send(p1, p2, data) {
return _this5.send(CLA, INS.DERIVE_ADDRESS, p1, p2, data).then(_utils2.default.stripRetcodeFromResponse);
return _this5.send(CLA, INS.DERIVE_ADDRESS, p1, p2, data).then(_utils["default"].stripRetcodeFromResponse);
};

@@ -612,3 +580,3 @@

P2_UNUSED = 0x00;
data = _utils2.default.path_to_buf(path);
data = _utils["default"].path_to_buf(path);
_context9.next = 7;

@@ -627,7 +595,7 @@ return _send(P1_DISPLAY, P2_UNUSED, data);

}
}, _callee9, this);
}, _callee9);
}));
function showAddress(_x8) {
return _ref9.apply(this, arguments);
function showAddress(_x7) {
return _showAddress.apply(this, arguments);
}

@@ -640,8 +608,8 @@

value: function () {
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16(inputs, outputs) {
var _signTransaction = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(inputs, outputs) {
var _this6 = this;
var P1_STAGE_INIT, P1_STAGE_INPUTS, P1_STAGE_OUTPUTS, P1_STAGE_CONFIRM, P1_STAGE_WITNESSES, P2_UNUSED, SIGN_TX_INPUT_TYPE_ATTESTED_UTXO, _send, signTx_init, signTx_addInput, signTx_addAddressOutput, signTx_addChangeOutput, signTx_awaitConfirm, signTx_getWitness, attestedInputs, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _ref17, _txDataHex, _outputIndex, attestation, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, output, _ref18, txHashHex, witnesses, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, input, witness;
var P1_STAGE_INIT, P1_STAGE_INPUTS, P1_STAGE_OUTPUTS, P1_STAGE_CONFIRM, P1_STAGE_WITNESSES, P2_UNUSED, SIGN_TX_INPUT_TYPE_ATTESTED_UTXO, _send, signTx_init, signTx_addInput, signTx_addAddressOutput, signTx_addChangeOutput, signTx_awaitConfirm, signTx_getWitness, attestedInputs, _iterator, _step, _step$value, txDataHex, outputIndex, _attestation, _i, _attestedInputs, attestation, _iterator2, _step2, output, _yield$signTx_awaitCo, txHashHex, witnesses, _iterator3, _step3, input, witness;
return _regenerator2.default.wrap(function _callee16$(_context16) {
return _regenerator["default"].wrap(function _callee16$(_context16) {
while (1) {

@@ -651,3 +619,2 @@ switch (_context16.prev = _context16.next) {

//console.log("sign");
P1_STAGE_INIT = 0x01;

@@ -662,13 +629,13 @@ P1_STAGE_INPUTS = 0x02;

_send = function _send(p1, p2, data) {
return _this6.send(CLA, INS.SIGN_TX, p1, p2, data).then(_utils2.default.stripRetcodeFromResponse);
return _this6.send(CLA, INS.SIGN_TX, p1, p2, data).then(_utils["default"].stripRetcodeFromResponse);
};
signTx_init = function () {
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(numInputs, numOutputs) {
signTx_init = /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(numInputs, numOutputs) {
var data, response;
return _regenerator2.default.wrap(function _callee10$(_context10) {
return _regenerator["default"].wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
data = Buffer.concat([_utils2.default.uint32_to_buf(numInputs), _utils2.default.uint32_to_buf(numOutputs)]);
data = Buffer.concat([_utils["default"].uint32_to_buf(numInputs), _utils["default"].uint32_to_buf(numOutputs)]);
_context10.next = 3;

@@ -687,18 +654,18 @@ return wrapRetryStillInCall(_send)(P1_STAGE_INIT, P2_UNUSED, data);

}
}, _callee10, _this6);
}, _callee10);
}));
return function signTx_init(_x11, _x12) {
return _ref11.apply(this, arguments);
return function signTx_init(_x10, _x11) {
return _ref3.apply(this, arguments);
};
}();
signTx_addInput = function () {
var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(attestation) {
signTx_addInput = /*#__PURE__*/function () {
var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(attestation) {
var data, response;
return _regenerator2.default.wrap(function _callee11$(_context11) {
return _regenerator["default"].wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
data = Buffer.concat([_utils2.default.uint8_to_buf(SIGN_TX_INPUT_TYPE_ATTESTED_UTXO), attestation.rawBuffer]);
data = Buffer.concat([_utils["default"].uint8_to_buf(SIGN_TX_INPUT_TYPE_ATTESTED_UTXO), attestation.rawBuffer]);
_context11.next = 3;

@@ -717,18 +684,18 @@ return _send(P1_STAGE_INPUTS, P2_UNUSED, data);

}
}, _callee11, _this6);
}, _callee11);
}));
return function signTx_addInput(_x13) {
return _ref12.apply(this, arguments);
return function signTx_addInput(_x12) {
return _ref4.apply(this, arguments);
};
}();
signTx_addAddressOutput = function () {
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(address58, amountStr) {
signTx_addAddressOutput = /*#__PURE__*/function () {
var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(address58, amountStr) {
var data, response;
return _regenerator2.default.wrap(function _callee12$(_context12) {
return _regenerator["default"].wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
data = Buffer.concat([_utils2.default.amount_to_buf(amountStr), _utils2.default.uint8_to_buf(0x01), _utils2.default.base58_decode(address58)]);
data = Buffer.concat([_utils["default"].amount_to_buf(amountStr), _utils["default"].uint8_to_buf(0x01), _utils["default"].base58_decode(address58)]);
_context12.next = 3;

@@ -747,18 +714,18 @@ return _send(P1_STAGE_OUTPUTS, P2_UNUSED, data);

}
}, _callee12, _this6);
}, _callee12);
}));
return function signTx_addAddressOutput(_x14, _x15) {
return _ref13.apply(this, arguments);
return function signTx_addAddressOutput(_x13, _x14) {
return _ref5.apply(this, arguments);
};
}();
signTx_addChangeOutput = function () {
var _ref14 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(path, amountStr) {
signTx_addChangeOutput = /*#__PURE__*/function () {
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(path, amountStr) {
var data, response;
return _regenerator2.default.wrap(function _callee13$(_context13) {
return _regenerator["default"].wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
data = Buffer.concat([_utils2.default.amount_to_buf(amountStr), _utils2.default.uint8_to_buf(0x02), _utils2.default.path_to_buf(path)]);
data = Buffer.concat([_utils["default"].amount_to_buf(amountStr), _utils["default"].uint8_to_buf(0x02), _utils["default"].path_to_buf(path)]);
_context13.next = 3;

@@ -777,14 +744,14 @@ return _send(P1_STAGE_OUTPUTS, P2_UNUSED, data);

}
}, _callee13, _this6);
}, _callee13);
}));
return function signTx_addChangeOutput(_x16, _x17) {
return _ref14.apply(this, arguments);
return function signTx_addChangeOutput(_x15, _x16) {
return _ref6.apply(this, arguments);
};
}();
signTx_awaitConfirm = function () {
var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14() {
signTx_awaitConfirm = /*#__PURE__*/function () {
var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14() {
var response;
return _regenerator2.default.wrap(function _callee14$(_context14) {
return _regenerator["default"].wrap(function _callee14$(_context14) {
while (1) {

@@ -794,3 +761,3 @@ switch (_context14.prev = _context14.next) {

_context14.next = 2;
return _send(P1_STAGE_CONFIRM, P2_UNUSED, _utils2.default.hex_to_buf(""));
return _send(P1_STAGE_CONFIRM, P2_UNUSED, _utils["default"].hex_to_buf(""));

@@ -808,18 +775,18 @@ case 2:

}
}, _callee14, _this6);
}, _callee14);
}));
return function signTx_awaitConfirm() {
return _ref15.apply(this, arguments);
return _ref7.apply(this, arguments);
};
}();
signTx_getWitness = function () {
var _ref16 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15(path) {
signTx_getWitness = /*#__PURE__*/function () {
var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(path) {
var data, response;
return _regenerator2.default.wrap(function _callee15$(_context15) {
return _regenerator["default"].wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
data = Buffer.concat([_utils2.default.path_to_buf(path)]);
data = Buffer.concat([_utils["default"].path_to_buf(path)]);
_context15.next = 3;

@@ -832,3 +799,3 @@ return _send(P1_STAGE_WITNESSES, P2_UNUSED, data);

path: path,
witnessSignatureHex: _utils2.default.buf_to_hex(response)
witnessSignatureHex: _utils["default"].buf_to_hex(response)
});

@@ -841,297 +808,190 @@

}
}, _callee15, _this6);
}, _callee15);
}));
return function signTx_getWitness(_x18) {
return _ref16.apply(this, arguments);
return function signTx_getWitness(_x17) {
return _ref8.apply(this, arguments);
};
}();
}(); //console.log("attest");
//console.log("attest");
attestedInputs = []; // attest
attestedInputs = [];
// attest
_iterator = _createForOfIteratorHelper(inputs);
_context16.prev = 16;
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context16.prev = 18;
_iterator = inputs[Symbol.iterator]();
_iterator.s();
case 20:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context16.next = 30;
case 18:
if ((_step = _iterator.n()).done) {
_context16.next = 26;
break;
}
_ref17 = _step.value;
_txDataHex = _ref17.txDataHex, _outputIndex = _ref17.outputIndex;
_context16.next = 25;
return this._attestUtxo(_txDataHex, _outputIndex);
_step$value = _step.value, txDataHex = _step$value.txDataHex, outputIndex = _step$value.outputIndex;
_context16.next = 22;
return this._attestUtxo(txDataHex, outputIndex);
case 25:
attestation = _context16.sent;
case 22:
_attestation = _context16.sent;
attestedInputs.push(_attestation);
attestedInputs.push(attestation);
case 27:
_iteratorNormalCompletion = true;
_context16.next = 20;
case 24:
_context16.next = 18;
break;
case 30:
_context16.next = 36;
case 26:
_context16.next = 31;
break;
case 32:
_context16.prev = 32;
_context16.t0 = _context16["catch"](18);
_didIteratorError = true;
_iteratorError = _context16.t0;
case 28:
_context16.prev = 28;
_context16.t0 = _context16["catch"](16);
case 36:
_context16.prev = 36;
_context16.prev = 37;
_iterator.e(_context16.t0);
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 31:
_context16.prev = 31;
case 39:
_context16.prev = 39;
_iterator.f();
if (!_didIteratorError) {
_context16.next = 42;
break;
}
return _context16.finish(31);
throw _iteratorError;
case 42:
return _context16.finish(39);
case 43:
return _context16.finish(36);
case 44:
_context16.next = 46;
case 34:
_context16.next = 36;
return signTx_init(attestedInputs.length, outputs.length);
case 46:
case 36:
_i = 0, _attestedInputs = attestedInputs;
// inputs
//console.log("inputs");
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_iteratorError2 = undefined;
_context16.prev = 49;
_iterator2 = attestedInputs[Symbol.iterator]();
case 51:
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
_context16.next = 58;
case 37:
if (!(_i < _attestedInputs.length)) {
_context16.next = 44;
break;
}
attestation = _step2.value;
_context16.next = 55;
attestation = _attestedInputs[_i];
_context16.next = 41;
return signTx_addInput(attestation);
case 55:
_iteratorNormalCompletion2 = true;
_context16.next = 51;
case 41:
_i++;
_context16.next = 37;
break;
case 58:
_context16.next = 64;
break;
case 60:
_context16.prev = 60;
_context16.t1 = _context16["catch"](49);
_didIteratorError2 = true;
_iteratorError2 = _context16.t1;
case 64:
_context16.prev = 64;
_context16.prev = 65;
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
case 67:
_context16.prev = 67;
if (!_didIteratorError2) {
_context16.next = 70;
break;
}
throw _iteratorError2;
case 70:
return _context16.finish(67);
case 71:
return _context16.finish(64);
case 72:
case 44:
// outputs
//console.log("outputs");
_iteratorNormalCompletion3 = true;
_didIteratorError3 = false;
_iteratorError3 = undefined;
_context16.prev = 75;
_iterator3 = outputs[Symbol.iterator]();
_iterator2 = _createForOfIteratorHelper(outputs);
_context16.prev = 45;
case 77:
if (_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done) {
_context16.next = 93;
_iterator2.s();
case 47:
if ((_step2 = _iterator2.n()).done) {
_context16.next = 62;
break;
}
output = _step3.value;
output = _step2.value;
if (!output.address58) {
_context16.next = 84;
_context16.next = 54;
break;
}
_context16.next = 82;
_context16.next = 52;
return signTx_addAddressOutput(output.address58, output.amountStr);
case 82:
_context16.next = 90;
case 52:
_context16.next = 60;
break;
case 84:
case 54:
if (!output.path) {
_context16.next = 89;
_context16.next = 59;
break;
}
_context16.next = 87;
_context16.next = 57;
return signTx_addChangeOutput(output.path, output.amountStr);
case 87:
_context16.next = 90;
case 57:
_context16.next = 60;
break;
case 89:
case 59:
throw new Error("TODO");
case 90:
_iteratorNormalCompletion3 = true;
_context16.next = 77;
case 60:
_context16.next = 47;
break;
case 93:
_context16.next = 99;
case 62:
_context16.next = 67;
break;
case 95:
_context16.prev = 95;
_context16.t2 = _context16["catch"](75);
_didIteratorError3 = true;
_iteratorError3 = _context16.t2;
case 64:
_context16.prev = 64;
_context16.t1 = _context16["catch"](45);
case 99:
_context16.prev = 99;
_context16.prev = 100;
_iterator2.e(_context16.t1);
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
case 67:
_context16.prev = 67;
case 102:
_context16.prev = 102;
_iterator2.f();
if (!_didIteratorError3) {
_context16.next = 105;
break;
}
return _context16.finish(67);
throw _iteratorError3;
case 105:
return _context16.finish(102);
case 106:
return _context16.finish(99);
case 107:
_context16.next = 109;
case 70:
_context16.next = 72;
return signTx_awaitConfirm();
case 109:
_ref18 = _context16.sent;
txHashHex = _ref18.txHashHex;
case 72:
_yield$signTx_awaitCo = _context16.sent;
txHashHex = _yield$signTx_awaitCo.txHashHex;
//console.log("witnesses");
witnesses = [];
_iteratorNormalCompletion4 = true;
_didIteratorError4 = false;
_iteratorError4 = undefined;
_context16.prev = 115;
_iterator4 = inputs[Symbol.iterator]();
_iterator3 = _createForOfIteratorHelper(inputs);
_context16.prev = 76;
case 117:
if (_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done) {
_context16.next = 126;
_iterator3.s();
case 78:
if ((_step3 = _iterator3.n()).done) {
_context16.next = 86;
break;
}
input = _step4.value;
_context16.next = 121;
input = _step3.value;
_context16.next = 82;
return signTx_getWitness(input.path);
case 121:
case 82:
witness = _context16.sent;
witnesses.push(witness);
case 123:
_iteratorNormalCompletion4 = true;
_context16.next = 117;
case 84:
_context16.next = 78;
break;
case 126:
_context16.next = 132;
case 86:
_context16.next = 91;
break;
case 128:
_context16.prev = 128;
_context16.t3 = _context16["catch"](115);
_didIteratorError4 = true;
_iteratorError4 = _context16.t3;
case 88:
_context16.prev = 88;
_context16.t2 = _context16["catch"](76);
case 132:
_context16.prev = 132;
_context16.prev = 133;
_iterator3.e(_context16.t2);
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
case 91:
_context16.prev = 91;
case 135:
_context16.prev = 135;
_iterator3.f();
if (!_didIteratorError4) {
_context16.next = 138;
break;
}
return _context16.finish(91);
throw _iteratorError4;
case 138:
return _context16.finish(135);
case 139:
return _context16.finish(132);
case 140:
case 94:
return _context16.abrupt("return", {

@@ -1142,3 +1002,3 @@ txHashHex: txHashHex,

case 141:
case 95:
case "end":

@@ -1148,7 +1008,7 @@ return _context16.stop();

}
}, _callee16, this, [[18, 32, 36, 44], [37,, 39, 43], [49, 60, 64, 72], [65,, 67, 71], [75, 95, 99, 107], [100,, 102, 106], [115, 128, 132, 140], [133,, 135, 139]]);
}, _callee16, this, [[16, 28, 31, 34], [45, 64, 67, 70], [76, 88, 91, 94]]);
}));
function signTransaction(_x9, _x10) {
return _ref10.apply(this, arguments);
function signTransaction(_x8, _x9) {
return _signTransaction.apply(this, arguments);
}

@@ -1162,4 +1022,3 @@

exports.default = Ada;
exports.utils = _utils2.default;
exports["default"] = Ada;
//# sourceMappingURL=Ada.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Assert = exports.Precondition = undefined;
var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
exports.uint32_to_buf = uint32_to_buf;

@@ -25,22 +21,22 @@ exports.buf_to_uint32 = buf_to_uint32;

exports.str_to_path = str_to_path;
exports["default"] = exports.Assert = exports.Precondition = void 0;
var _baseX = require("base-x");
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _baseX2 = _interopRequireDefault(_baseX);
var _baseX = _interopRequireDefault(require("base-x"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
var bs58 = (0, _baseX2.default)(BASE58_ALPHABET);
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var HARDENED = 0x80000000;
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
var bs58 = (0, _baseX["default"])(BASE58_ALPHABET);
var HARDENED = 0x80000000; // We use bs10 as an easy way to parse/encode amount strings
// We use bs10 as an easy way to parse/encode amount strings
var bs10 = (0, _baseX2.default)("0123456789");
var bs10 = (0, _baseX["default"])("0123456789"); // Max supply in lovelace
// Max supply in lovelace
var MAX_LOVELACE_SUPPLY_STR = ["45", "000", "000", "000", "000000"].join("");
var Precondition = exports.Precondition = {
var Precondition = {
// Generic check

@@ -63,3 +59,2 @@ check: function check(cond) {

},
// Extended checks

@@ -76,3 +71,2 @@ checkIsUint32: function checkIsUint32(data) {

},
checkIsHexString: function checkIsHexString(data) {

@@ -85,25 +79,15 @@ Precondition.checkIsString(data);

Precondition.checkIsArray(path);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var _iterator = _createForOfIteratorHelper(path),
_step;
try {
for (var _iterator = path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var x = _step.value;
Precondition.checkIsUint32(x);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
_iterator.e(err);
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
_iterator.f();
}

@@ -113,11 +97,12 @@ },

Precondition.checkIsString(amount);
Precondition.check(/^[0-9]*$/.test(amount));
// Length checks
Precondition.check(/^[0-9]*$/.test(amount)); // Length checks
Precondition.check(amount.length > 0);
Precondition.check(amount.length <= MAX_LOVELACE_SUPPLY_STR.length);
// Leading zeros
Precondition.check(amount.length <= MAX_LOVELACE_SUPPLY_STR.length); // Leading zeros
if (amount.length > 1) {
Precondition.check(amount[0] != "0");
}
// less than max supply
} // less than max supply
if (amount.length == MAX_LOVELACE_SUPPLY_STR.length) {

@@ -130,30 +115,20 @@ // Note: this is string comparison!

Precondition.checkIsString(data);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
var _iterator2 = _createForOfIteratorHelper(data),
_step2;
try {
for (var _iterator2 = data[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var c = _step2.value;
Precondition.check(BASE58_ALPHABET.includes(c));
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
_iterator2.e(err);
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
_iterator2.f();
}
}
};
var Assert = exports.Assert = {
exports.Precondition = Precondition;
var Assert = {
assert: function assert(cond) {

@@ -163,6 +138,6 @@ if (!cond) throw new Error("Assertion failed");

};
exports.Assert = Assert;
function uint32_to_buf(value) {
Precondition.checkIsUint32(value);
var data = Buffer.alloc(4);

@@ -175,3 +150,2 @@ data.writeUInt32BE(value, 0);

Precondition.check(data.length == 4);
return data.readUIntBE(0, 4);

@@ -182,3 +156,2 @@ }

Precondition.checkIsUint8(value);
var data = Buffer.alloc(1);

@@ -196,9 +169,7 @@ data.writeUInt8(value, 0);

return data.toString("hex");
}
} // no buf_to_uint8
// no buf_to_uint8
function path_to_buf(path) {
Precondition.checkIsValidPath(path);
var data = Buffer.alloc(1 + 4 * path.length);

@@ -210,2 +181,3 @@ data.writeUInt8(path.length, 0);

}
return data;

@@ -223,10 +195,9 @@ }

Precondition.checkIsArray(chunkLengths);
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
var _iterator3 = _createForOfIteratorHelper(chunkLengths),
_step3;
try {
for (var _iterator3 = chunkLengths[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var len = _step3.value;
Precondition.checkIsInteger(len);

@@ -236,29 +207,15 @@ Precondition.check(len > 0);

} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
_iterator3.e(err);
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
_iterator3.f();
}
Precondition.check(data.length <= sum(chunkLengths));
var offset = 0;
var result = [];
var restLength = data.length - sum(chunkLengths);
var _arr = [].concat((0, _toConsumableArray3.default)(chunkLengths), [restLength]);
for (var _i = 0; _i < _arr.length; _i++) {
for (var _i = 0, _arr = [].concat((0, _toConsumableArray2["default"])(chunkLengths), [restLength]); _i < _arr.length; _i++) {
var c = _arr[_i];
result.push(data.slice(offset, offset + c));
offset += c;

@@ -273,7 +230,5 @@ }

Precondition.check(response.length >= 2);
var L = response.length - 2;
var retcode = response.slice(L, L + 2);
if (retcode.toString("hex") != "9000") throw new Error("Invalid retcode " + retcode.toString("hex"));
if (retcode.toString("hex") != "9000") throw new Error("Invalid retcode ".concat(retcode.toString("hex")));
return response.slice(0, L);

@@ -285,5 +240,4 @@ }

Precondition.check(data.length == 8);
var encoded = bs10.encode(data); // Strip leading zeros
var encoded = bs10.encode(data);
// Strip leading zeros
return encoded.replace(/^0*(.)/, "$1");

@@ -294,7 +248,5 @@ }

Precondition.checkIsValidAmount(amount);
var data = bs10.decode(amount); // Amount should fit uin64_t
var data = bs10.decode(amount);
// Amount should fit uin64_t
Assert.assert(data.length <= 8);
var padding = Buffer.alloc(8 - data.length);

@@ -306,3 +258,2 @@ return Buffer.concat([padding, data]);

Precondition.checkIsBuffer(data);
return bs58.encode(data);

@@ -313,3 +264,2 @@ }

Precondition.checkIsValidBase58(data);
return bs58.decode(data);

@@ -320,8 +270,8 @@ }

Precondition.checkIsString(str);
var i = parseInt(str);
// Check that we parsed everything
Precondition.check("" + i == str);
// Could be invalid
Precondition.check(!isNaN(i));
// Could still be float
var i = parseInt(str); // Check that we parsed everything
Precondition.check("" + i == str); // Could be invalid
Precondition.check(!isNaN(i)); // Could still be float
Precondition.checkIsInteger(i);

@@ -333,2 +283,3 @@ return i;

var base = 0;
if (str.endsWith("'")) {

@@ -338,2 +289,3 @@ str = str.slice(0, -1);

}
var i = safe_parseInt(str);

@@ -348,32 +300,24 @@ Precondition.check(i >= 0);

Precondition.check(data.length > 0);
return data.split("/").map(parseBIP32Index);
}
exports.default = {
var _default = {
HARDENED: HARDENED,
hex_to_buf: hex_to_buf,
buf_to_hex: buf_to_hex,
uint32_to_buf: uint32_to_buf,
buf_to_uint32: buf_to_uint32,
// no pair for now
uint8_to_buf: uint8_to_buf,
// no pair for now
path_to_buf: path_to_buf,
amount_to_buf: amount_to_buf,
buf_to_amount: buf_to_amount,
base58_encode: base58_encode,
base58_decode: base58_decode,
chunkBy: chunkBy,
stripRetcodeFromResponse: stripRetcodeFromResponse,
str_to_path: str_to_path
};
exports["default"] = _default;
//# sourceMappingURL=utils.js.map
{
"name": "@cardano-foundation/ledgerjs-hw-app-cardano",
"version": "1.0.7",
"version": "1.0.8",
"files": [

@@ -23,3 +23,3 @@ "lib"

"dependencies": {
"@ledgerhq/hw-transport": "^4.35.0",
"@ledgerhq/hw-transport": "^5.12.0",
"babel-polyfill": "^6.26.0",

@@ -31,16 +31,15 @@ "babel-runtime": "^6.26.0",

"devDependencies": {
"@ledgerhq/hw-transport-node-hid": "^4.35.0",
"babel-cli": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-flow": "^6.23.0",
"babel-preset-stage-0": "^6.24.1",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/preset-flow": "^7.9.0",
"@ledgerhq/hw-transport-node-hid": "^5.12.0",
"chai": "^4.2.0",
"chalk": "^2.3.1",
"flow-bin": "^0.78.0",
"flow-copy-source": "^2.0.3",
"flow-typed": "^2.4.0",
"lerna": "^3.13.0",
"mocha": "^5.0.1",
"prettier": "^1.16.4"
"chalk": "^4.0.0",
"flow-bin": "^0.122.0",
"flow-copy-source": "^2.0.9",
"flow-typed": "^3.1.0",
"mocha": "^7.1.1",
"prettier": "^2.0.3"
},

@@ -47,0 +46,0 @@ "bugs": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc