@zondax/ledger-cosmos-js 2.1.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +39 -7
  3. package/dist/commandsV1.d.ts +4 -0
  4. package/dist/commandsV1.js +129 -0
  5. package/dist/commandsV1.js.map +1 -0
  6. package/dist/commandsV2.d.ts +4 -0
  7. package/dist/commandsV2.js +104 -0
  8. package/dist/commandsV2.js.map +1 -0
  9. package/dist/common.d.ts +39 -0
  10. package/dist/common.js +143 -132
  11. package/dist/common.js.map +1 -0
  12. package/dist/cosmosApp.d.ts +19 -0
  13. package/dist/cosmosApp.js +377 -0
  14. package/dist/cosmosApp.js.map +1 -0
  15. package/dist/index.d.ts +16 -0
  16. package/dist/index.js +17 -608
  17. package/dist/index.js.map +1 -0
  18. package/package.json +64 -50
  19. package/yarn.lock +6661 -0
  20. package/.babelrc +0 -13
  21. package/.circleci/config.yml +0 -62
  22. package/.editorconfig +0 -14
  23. package/.eslintrc.json +0 -31
  24. package/.idea/codeStyles/Project.xml +0 -57
  25. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  26. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  27. package/.idea/jsLibraryMappings.xml +0 -6
  28. package/.idea/ledger-cosmos-js.iml +0 -12
  29. package/.idea/modules.xml +0 -8
  30. package/.idea/vcs.xml +0 -6
  31. package/.idea/workspace.xml +0 -57
  32. package/.prettierrc.json +0 -4
  33. package/certs/.gitkeep +0 -0
  34. package/certs/openssl.cnf +0 -12
  35. package/dist/helperV1.js +0 -127
  36. package/dist/helperV2.js +0 -97
  37. package/docs/example.png +0 -0
  38. package/jest.config.integration.js +0 -9
  39. package/jest.config.js +0 -32
  40. package/jest.config.unit.js +0 -9
  41. package/public/favicon.ico +0 -0
  42. package/public/index.html +0 -17
  43. package/src/common.js +0 -114
  44. package/src/helperV1.js +0 -73
  45. package/src/helperV2.js +0 -44
  46. package/src/index.js +0 -336
  47. package/tests/basic.ispec.js +0 -390
  48. package/tests/basic.spec.js +0 -8
  49. package/tests/jest.js +0 -2
  50. package/vue.config.js +0 -11
  51. package/vue_example/App.vue +0 -29
  52. package/vue_example/assets/logo.png +0 -0
  53. package/vue_example/components/LedgerExample.vue +0 -252
  54. package/vue_example/main.js +0 -9
package/dist/common.js CHANGED
@@ -1,151 +1,162 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.errorCodeToString = errorCodeToString;
9
- exports.processErrorResponse = processErrorResponse;
10
- exports.getVersion = getVersion;
11
- exports.ERROR_CODE = exports.P1_VALUES = exports.PAYLOAD_TYPE = exports.INS = exports.APP_KEY = exports.CHUNK_SIZE = exports.CLA = void 0;
12
-
13
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
-
15
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
-
17
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
18
-
19
- var CLA = 0x55;
20
- exports.CLA = CLA;
21
- var CHUNK_SIZE = 250;
22
- exports.CHUNK_SIZE = CHUNK_SIZE;
23
- var APP_KEY = "CSM";
24
- exports.APP_KEY = APP_KEY;
25
- var INS = {
26
- GET_VERSION: 0x00,
27
- INS_PUBLIC_KEY_SECP256K1: 0x01,
28
- // Obsolete
29
- SIGN_SECP256K1: 0x02,
30
- GET_ADDR_SECP256K1: 0x04
2
+ /** ******************************************************************************
3
+ * (c) 2018 - 2022 Zondax AG
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ ******************************************************************************* */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ exports.__esModule = true;
54
+ exports.getVersion = exports.processErrorResponse = exports.errorCodeToString = exports.ERROR_CODE = exports.P1_VALUES = exports.PAYLOAD_TYPE = exports.INS = exports.APP_KEY = exports.CHUNK_SIZE = exports.CLA = void 0;
55
+ exports.CLA = 0x55;
56
+ exports.CHUNK_SIZE = 250;
57
+ exports.APP_KEY = 'CSM';
58
+ exports.INS = {
59
+ GET_VERSION: 0x00,
60
+ INS_PUBLIC_KEY_SECP256K1: 0x01,
61
+ SIGN_SECP256K1: 0x02,
62
+ GET_ADDR_SECP256K1: 0x04
31
63
  };
32
- exports.INS = INS;
33
- var PAYLOAD_TYPE = {
34
- INIT: 0x00,
35
- ADD: 0x01,
36
- LAST: 0x02
64
+ exports.PAYLOAD_TYPE = {
65
+ INIT: 0x00,
66
+ ADD: 0x01,
67
+ LAST: 0x02
37
68
  };
38
- exports.PAYLOAD_TYPE = PAYLOAD_TYPE;
39
- var P1_VALUES = {
40
- ONLY_RETRIEVE: 0x00,
41
- SHOW_ADDRESS_IN_DEVICE: 0x01
69
+ exports.P1_VALUES = {
70
+ ONLY_RETRIEVE: 0x00,
71
+ SHOW_ADDRESS_IN_DEVICE: 0x01
42
72
  };
43
- exports.P1_VALUES = P1_VALUES;
44
- var ERROR_CODE = {
45
- NoError: 0x9000
73
+ exports.ERROR_CODE = {
74
+ NoError: 0x9000
46
75
  };
47
- exports.ERROR_CODE = ERROR_CODE;
48
76
  var ERROR_DESCRIPTION = {
49
- 1: "U2F: Unknown",
50
- 2: "U2F: Bad request",
51
- 3: "U2F: Configuration unsupported",
52
- 4: "U2F: Device Ineligible",
53
- 5: "U2F: Timeout",
54
- 14: "Timeout",
55
- 0x9000: "No errors",
56
- 0x9001: "Device is busy",
57
- 0x6802: "Error deriving keys",
58
- 0x6400: "Execution Error",
59
- 0x6700: "Wrong Length",
60
- 0x6982: "Empty Buffer",
61
- 0x6983: "Output buffer too small",
62
- 0x6984: "Data is invalid",
63
- 0x6985: "Conditions not satisfied",
64
- 0x6986: "Transaction rejected",
65
- 0x6a80: "Bad key handle",
66
- 0x6b00: "Invalid P1/P2",
67
- 0x6d00: "Instruction not supported",
68
- 0x6e00: "App does not seem to be open",
69
- 0x6f00: "Unknown error",
70
- 0x6f01: "Sign/verify error"
77
+ 1: 'U2F: Unknown',
78
+ 2: 'U2F: Bad request',
79
+ 3: 'U2F: Configuration unsupported',
80
+ 4: 'U2F: Device Ineligible',
81
+ 5: 'U2F: Timeout',
82
+ 14: 'Timeout',
83
+ 0x9000: 'No errors',
84
+ 0x9001: 'Device is busy',
85
+ 0x6802: 'Error deriving keys',
86
+ 0x6400: 'Execution Error',
87
+ 0x6700: 'Wrong Length',
88
+ 0x6982: 'Empty Buffer',
89
+ 0x6983: 'Output buffer too small',
90
+ 0x6984: 'Data is invalid',
91
+ 0x6985: 'Conditions not satisfied',
92
+ 0x6986: 'Transaction rejected',
93
+ 0x6a80: 'Bad key handle',
94
+ 0x6b00: 'Invalid P1/P2',
95
+ 0x6d00: 'Instruction not supported',
96
+ 0x6e00: 'App does not seem to be open',
97
+ 0x6f00: 'Unknown error',
98
+ 0x6f01: 'Sign/verify error'
71
99
  };
72
-
73
100
  function errorCodeToString(statusCode) {
74
- if (statusCode in ERROR_DESCRIPTION) return ERROR_DESCRIPTION[statusCode];
75
- return "Unknown Status Code: ".concat(statusCode);
101
+ if (statusCode in ERROR_DESCRIPTION)
102
+ return ERROR_DESCRIPTION[statusCode];
103
+ return "Unknown Status Code: ".concat(statusCode);
76
104
  }
77
-
105
+ exports.errorCodeToString = errorCodeToString;
78
106
  function isDict(v) {
79
- return (0, _typeof2.default)(v) === "object" && v !== null && !(v instanceof Array) && !(v instanceof Date);
107
+ return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
80
108
  }
81
-
82
109
  function processErrorResponse(response) {
83
- if (response) {
84
- if (isDict(response)) {
85
- if (Object.prototype.hasOwnProperty.call(response, "statusCode")) {
110
+ if (response) {
111
+ if (isDict(response)) {
112
+ if (Object.prototype.hasOwnProperty.call(response, 'statusCode')) {
113
+ return {
114
+ return_code: response.statusCode,
115
+ error_message: errorCodeToString(response.statusCode)
116
+ };
117
+ }
118
+ if (Object.prototype.hasOwnProperty.call(response, 'return_code') &&
119
+ Object.prototype.hasOwnProperty.call(response, 'error_message')) {
120
+ return response;
121
+ }
122
+ }
86
123
  return {
87
- return_code: response.statusCode,
88
- error_message: errorCodeToString(response.statusCode)
124
+ return_code: 0xffff,
125
+ error_message: response.toString()
89
126
  };
90
- }
91
-
92
- if (Object.prototype.hasOwnProperty.call(response, "return_code") && Object.prototype.hasOwnProperty.call(response, "error_message")) {
93
- return response;
94
- }
95
127
  }
96
-
97
128
  return {
98
- return_code: 0xffff,
99
- error_message: response.toString()
129
+ return_code: 0xffff,
130
+ error_message: response.toString()
100
131
  };
101
- }
102
-
103
- return {
104
- return_code: 0xffff,
105
- error_message: response.toString()
106
- };
107
132
  }
108
-
109
- function getVersion(_x) {
110
- return _getVersion.apply(this, arguments);
133
+ exports.processErrorResponse = processErrorResponse;
134
+ function getVersion(transport) {
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ return __generator(this, function (_a) {
137
+ return [2 /*return*/, transport.send(exports.CLA, exports.INS.GET_VERSION, 0, 0).then(function (response) {
138
+ var errorCodeData = response.slice(-2);
139
+ var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
140
+ var targetId = 0;
141
+ if (response.length >= 9) {
142
+ /* eslint-disable no-bitwise */
143
+ targetId = (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0);
144
+ /* eslint-enable no-bitwise */
145
+ }
146
+ return {
147
+ return_code: returnCode,
148
+ error_message: errorCodeToString(returnCode),
149
+ // ///
150
+ test_mode: response[0] !== 0,
151
+ major: response[1],
152
+ minor: response[2],
153
+ patch: response[3],
154
+ device_locked: response[4] === 1,
155
+ target_id: targetId.toString(16)
156
+ };
157
+ }, processErrorResponse)];
158
+ });
159
+ });
111
160
  }
112
-
113
- function _getVersion() {
114
- _getVersion = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(transport) {
115
- return _regenerator.default.wrap(function _callee$(_context) {
116
- while (1) {
117
- switch (_context.prev = _context.next) {
118
- case 0:
119
- return _context.abrupt("return", transport.send(CLA, INS.GET_VERSION, 0, 0).then(function (response) {
120
- var errorCodeData = response.slice(-2);
121
- var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
122
- var targetId = 0;
123
-
124
- if (response.length >= 9) {
125
- /* eslint-disable no-bitwise */
126
- targetId = (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0);
127
- /* eslint-enable no-bitwise */
128
- }
129
-
130
- return {
131
- return_code: returnCode,
132
- error_message: errorCodeToString(returnCode),
133
- // ///
134
- test_mode: response[0] !== 0,
135
- major: response[1],
136
- minor: response[2],
137
- patch: response[3],
138
- device_locked: response[4] === 1,
139
- target_id: targetId.toString(16)
140
- };
141
- }, processErrorResponse));
142
-
143
- case 1:
144
- case "end":
145
- return _context.stop();
146
- }
147
- }
148
- }, _callee);
149
- }));
150
- return _getVersion.apply(this, arguments);
151
- }
161
+ exports.getVersion = getVersion;
162
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;mFAcmF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtE,QAAA,GAAG,GAAG,IAAI,CAAA;AACV,QAAA,UAAU,GAAG,GAAG,CAAA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C,CAAC,CAAA;oBAE5D,IAAI,QAAQ,GAAG,CAAC,CAAA;oBAChB,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;wBACxB,+BAA+B;wBAC/B,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;wBAC9F,8BAA8B;qBAC/B;oBAED,OAAO;wBACL,WAAW,EAAE,UAAU;wBACvB,aAAa,EAAE,iBAAiB,CAAC,UAAU,CAAC;wBAC5C,MAAM;wBACN,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;wBAC5B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;wBAClB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;wBAClB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;wBAClB,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;wBAChC,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;qBACjC,CAAA;gBACH,CAAC,EAAE,oBAAoB,CAAC,EAAA;;;CACzB;AAxBD,gCAwBC","sourcesContent":["/** ******************************************************************************\n * (c) 2018 - 2022 Zondax AG\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n ******************************************************************************* */\n\nexport const CLA = 0x55\nexport const CHUNK_SIZE = 250\nexport const APP_KEY = 'CSM'\n\nexport const INS = {\n GET_VERSION: 0x00,\n INS_PUBLIC_KEY_SECP256K1: 0x01, // Obsolete\n SIGN_SECP256K1: 0x02,\n GET_ADDR_SECP256K1: 0x04,\n}\n\nexport const PAYLOAD_TYPE = {\n INIT: 0x00,\n ADD: 0x01,\n LAST: 0x02,\n}\n\nexport const P1_VALUES = {\n ONLY_RETRIEVE: 0x00,\n SHOW_ADDRESS_IN_DEVICE: 0x01,\n}\n\nexport const ERROR_CODE = {\n NoError: 0x9000,\n}\n\nconst ERROR_DESCRIPTION: any = {\n 1: 'U2F: Unknown',\n 2: 'U2F: Bad request',\n 3: 'U2F: Configuration unsupported',\n 4: 'U2F: Device Ineligible',\n 5: 'U2F: Timeout',\n 14: 'Timeout',\n 0x9000: 'No errors',\n 0x9001: 'Device is busy',\n 0x6802: 'Error deriving keys',\n 0x6400: 'Execution Error',\n 0x6700: 'Wrong Length',\n 0x6982: 'Empty Buffer',\n 0x6983: 'Output buffer too small',\n 0x6984: 'Data is invalid',\n 0x6985: 'Conditions not satisfied',\n 0x6986: 'Transaction rejected',\n 0x6a80: 'Bad key handle',\n 0x6b00: 'Invalid P1/P2',\n 0x6d00: 'Instruction not supported',\n 0x6e00: 'App does not seem to be open',\n 0x6f00: 'Unknown error',\n 0x6f01: 'Sign/verify error',\n}\n\nexport function errorCodeToString(statusCode: number) {\n if (statusCode in ERROR_DESCRIPTION) return ERROR_DESCRIPTION[statusCode]\n return `Unknown Status Code: ${statusCode}`\n}\n\nfunction isDict(v: any) {\n return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date)\n}\n\nexport function processErrorResponse(response: any) {\n if (response) {\n if (isDict(response)) {\n if (Object.prototype.hasOwnProperty.call(response, 'statusCode')) {\n return {\n return_code: response.statusCode,\n error_message: errorCodeToString(response.statusCode),\n }\n }\n\n if (\n Object.prototype.hasOwnProperty.call(response, 'return_code') &&\n Object.prototype.hasOwnProperty.call(response, 'error_message')\n ) {\n return response\n }\n }\n return {\n return_code: 0xffff,\n error_message: response.toString(),\n }\n }\n\n return {\n return_code: 0xffff,\n error_message: response.toString(),\n }\n}\n\nexport async function getVersion(transport: any) {\n return transport.send(CLA, INS.GET_VERSION, 0, 0).then((response: any) => {\n const errorCodeData = response.slice(-2)\n const returnCode = errorCodeData[0] * 256 + errorCodeData[1]\n\n let targetId = 0\n if (response.length >= 9) {\n /* eslint-disable no-bitwise */\n targetId = (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0)\n /* eslint-enable no-bitwise */\n }\n\n return {\n return_code: returnCode,\n error_message: errorCodeToString(returnCode),\n // ///\n test_mode: response[0] !== 0,\n major: response[1],\n minor: response[2],\n patch: response[3],\n device_locked: response[4] === 1,\n target_id: targetId.toString(16),\n }\n }, processErrorResponse)\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import Transport from '@ledgerhq/hw-transport';
3
+ export declare class CosmosApp {
4
+ transport: Transport;
5
+ versionResponse?: any;
6
+ constructor(transport: any);
7
+ static serializeHRP(hrp: string): Buffer;
8
+ static getBech32FromPK(hrp: string, pk: Buffer): any;
9
+ serializePath(path: number[]): Promise<Buffer>;
10
+ signGetChunks(path: number[], message: string): Promise<Buffer[]>;
11
+ getVersion(): Promise<any>;
12
+ appInfo(): Promise<any>;
13
+ deviceInfo(): Promise<any>;
14
+ publicKey(path: number[]): Promise<any>;
15
+ getAddressAndPubKey(path: number[], hrp: string, showInDevice?: boolean): Promise<any>;
16
+ showAddressAndPubKey(path: number[], hrp: string): Promise<any>;
17
+ signSendChunk(chunkIdx: number, chunkNum: number, chunk: Buffer): Promise<any>;
18
+ sign(path: number[], message: string): Promise<any>;
19
+ }