UNPKG

@thorchain/ledger-thorchain

Version:
129 lines 6.8 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.ledgerErrorFromResponse = exports.errorCodeToString = exports.LedgerErrorDescription = exports.LedgerErrorType = exports.LedgerError = exports.P1_VALUES = exports.PAYLOAD_TYPE = exports.INS = exports.APP_KEY = exports.CHUNK_SIZE = exports.CLA = void 0; exports.CLA = 0x55; exports.CHUNK_SIZE = 250; exports.APP_KEY = "CSM"; exports.INS = { GET_VERSION: 0x00, SIGN_SECP256K1: 0x02, GET_ADDR_SECP256K1: 0x04, }; exports.PAYLOAD_TYPE = { INIT: 0x00, ADD: 0x01, LAST: 0x02, }; exports.P1_VALUES = { ONLY_RETRIEVE: 0x00, SHOW_ADDRESS_IN_DEVICE: 0x01, }; var LedgerError = /** @class */ (function (_super) { __extends(LedgerError, _super); function LedgerError(type, message) { if (message === void 0) { message = ""; } var _this = _super.call(this, "LedgerError " + type + ": " + (message ? message : errorCodeToString(type))) || this; _this.type = type; return _this; } LedgerError.prototype.toString = function () { return this.message; }; return LedgerError; }(Error)); exports.LedgerError = LedgerError; var LedgerErrorType; (function (LedgerErrorType) { LedgerErrorType[LedgerErrorType["U2FUnknown"] = 1] = "U2FUnknown"; LedgerErrorType[LedgerErrorType["U2FBadRequest"] = 2] = "U2FBadRequest"; LedgerErrorType[LedgerErrorType["U2FConfigurationUnsupported"] = 3] = "U2FConfigurationUnsupported"; LedgerErrorType[LedgerErrorType["U2FDeviceIneligible"] = 4] = "U2FDeviceIneligible"; LedgerErrorType[LedgerErrorType["U2FTimeout"] = 5] = "U2FTimeout"; LedgerErrorType[LedgerErrorType["HPRInvalid"] = 10] = "HPRInvalid"; LedgerErrorType[LedgerErrorType["PKInvalidBytes"] = 20] = "PKInvalidBytes"; LedgerErrorType[LedgerErrorType["Timeout"] = 30] = "Timeout"; LedgerErrorType[LedgerErrorType["NoErrors"] = 36864] = "NoErrors"; LedgerErrorType[LedgerErrorType["DeviceIsBusy"] = 36865] = "DeviceIsBusy"; LedgerErrorType[LedgerErrorType["ErrorDerivingKeys"] = 26626] = "ErrorDerivingKeys"; LedgerErrorType[LedgerErrorType["ExecutionError"] = 25600] = "ExecutionError"; LedgerErrorType[LedgerErrorType["WrongLength"] = 26368] = "WrongLength"; LedgerErrorType[LedgerErrorType["EmptyBuffer"] = 27010] = "EmptyBuffer"; LedgerErrorType[LedgerErrorType["OutputBufferTooSmall"] = 27011] = "OutputBufferTooSmall"; LedgerErrorType[LedgerErrorType["DataIsInvalid"] = 27012] = "DataIsInvalid"; LedgerErrorType[LedgerErrorType["ConditionsNotSatisfied"] = 27013] = "ConditionsNotSatisfied"; LedgerErrorType[LedgerErrorType["TransactionRejected"] = 27014] = "TransactionRejected"; LedgerErrorType[LedgerErrorType["BadKeyHandle"] = 27264] = "BadKeyHandle"; LedgerErrorType[LedgerErrorType["InvalidP1P2"] = 27392] = "InvalidP1P2"; LedgerErrorType[LedgerErrorType["InstructionNotSupported"] = 27904] = "InstructionNotSupported"; LedgerErrorType[LedgerErrorType["AppDoesNotSeemToBeOpen"] = 28160] = "AppDoesNotSeemToBeOpen"; LedgerErrorType[LedgerErrorType["UnknownError"] = 28416] = "UnknownError"; LedgerErrorType[LedgerErrorType["SignVerifyError"] = 28417] = "SignVerifyError"; LedgerErrorType[LedgerErrorType["UnknownResponse"] = 65535] = "UnknownResponse"; })(LedgerErrorType = exports.LedgerErrorType || (exports.LedgerErrorType = {})); exports.LedgerErrorDescription = (_a = {}, _a[LedgerErrorType.U2FUnknown] = "U2F: Unknown", _a[LedgerErrorType.U2FBadRequest] = "U2F: Bad request", _a[LedgerErrorType.U2FConfigurationUnsupported] = "U2F: Configuration unsupported", _a[LedgerErrorType.U2FDeviceIneligible] = "U2F: Device Ineligible", _a[LedgerErrorType.U2FTimeout] = "U2F: Timeout", _a[LedgerErrorType.Timeout] = "Timeout", _a[LedgerErrorType.HPRInvalid] = "Invalid HPR", _a[LedgerErrorType.PKInvalidBytes] = "Expected compressed public key [31 bytes]", _a[LedgerErrorType.NoErrors] = "No errors", _a[LedgerErrorType.DeviceIsBusy] = "Device is busy", _a[LedgerErrorType.ErrorDerivingKeys] = "Error deriving keys", _a[LedgerErrorType.ExecutionError] = "Execution Error", _a[LedgerErrorType.WrongLength] = "Wrong Length", _a[LedgerErrorType.EmptyBuffer] = "Empty Buffer", _a[LedgerErrorType.OutputBufferTooSmall] = "Output buffer too small", _a[LedgerErrorType.DataIsInvalid] = "Data is invalid", _a[LedgerErrorType.ConditionsNotSatisfied] = "Conditions not satisfied", _a[LedgerErrorType.TransactionRejected] = "Transaction rejected", _a[LedgerErrorType.BadKeyHandle] = "Bad key handle", _a[LedgerErrorType.InvalidP1P2] = "Invalid P1/P2", _a[LedgerErrorType.InstructionNotSupported] = "Instruction not supported", _a[LedgerErrorType.AppDoesNotSeemToBeOpen] = "App does not seem to be open", _a[LedgerErrorType.UnknownError] = "Unknown error", _a[LedgerErrorType.SignVerifyError] = "Sign/verify error", _a[LedgerErrorType.UnknownResponse] = "Unknown response", _a); var isLedgerErrorType = function (code) { return code in exports.LedgerErrorDescription; }; function errorCodeToString(statusCode) { if (isLedgerErrorType(statusCode)) return exports.LedgerErrorDescription[statusCode]; return "Unknown Status Code: " + statusCode; } exports.errorCodeToString = errorCodeToString; function isErrorResponse(v) { return typeof v === "object" && !!v && "return_code" in v && "return_message" in v; } function isStatusCodeResponse(v) { return typeof v === "object" && !!v && "statusCode" in v; } function ledgerErrorFromResponse(response) { if (isStatusCodeResponse(response)) { return new LedgerError(response.statusCode); } if (isErrorResponse(response)) { return new LedgerError(response.return_code, response.error_message); } return new LedgerError(LedgerErrorType.UnknownResponse, "Unknown response " + response); } exports.ledgerErrorFromResponse = ledgerErrorFromResponse; //# sourceMappingURL=common.js.map