@zondax/ledger-cosmos-js 3.0.2 → 4.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.
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- exports.publicKeyv1 = exports.signSendChunkv1 = exports.serializePathv1 = void 0;
40
- /** ******************************************************************************
41
- * (c) 2018 - 2022 Zondax AG
42
- *
43
- * Licensed under the Apache License, Version 2.0 (the "License");
44
- * you may not use this file except in compliance with the License.
45
- * You may obtain a copy of the License at
46
- *
47
- * http://www.apache.org/licenses/LICENSE-2.0
48
- *
49
- * Unless required by applicable law or agreed to in writing, software
50
- * distributed under the License is distributed on an "AS IS" BASIS,
51
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
- * See the License for the specific language governing permissions and
53
- * limitations under the License.
54
- ******************************************************************************* */
55
- var common_1 = require("./common");
56
- function serializePathv1(path) {
57
- if (path == null || path.length < 3) {
58
- throw new Error('Invalid path.');
59
- }
60
- if (path.length > 10) {
61
- throw new Error('Invalid path. Length should be <= 10');
62
- }
63
- var buf = Buffer.alloc(1 + 4 * path.length);
64
- buf.writeUInt8(path.length, 0);
65
- for (var i = 0; i < path.length; i += 1) {
66
- var v = path[i];
67
- if (i < 3) {
68
- // eslint-disable-next-line no-bitwise
69
- v |= 0x80000000; // Harden
70
- }
71
- buf.writeInt32LE(v, 1 + i * 4);
72
- }
73
- return buf;
74
- }
75
- exports.serializePathv1 = serializePathv1;
76
- function signSendChunkv1(app, chunkIdx, chunkNum, chunk, txType) {
77
- if (txType === void 0) { txType = common_1.P2_VALUES.JSON; }
78
- return __awaiter(this, void 0, void 0, function () {
79
- return __generator(this, function (_a) {
80
- return [2 /*return*/, app.transport
81
- .send(common_1.CLA, common_1.INS.SIGN_SECP256K1, chunkIdx, txType, chunk, [common_1.ERROR_CODE.NoError, 0x6984, 0x6a80])
82
- .then(function (response) {
83
- var errorCodeData = response.slice(-2);
84
- var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
85
- var errorMessage = (0, common_1.errorCodeToString)(returnCode);
86
- if (returnCode === 0x6a80 || returnCode === 0x6984) {
87
- errorMessage = "".concat(errorMessage, " : ").concat(response.slice(0, response.length - 2).toString('ascii'));
88
- }
89
- var signature = null;
90
- if (response.length > 2) {
91
- signature = response.slice(0, response.length - 2);
92
- }
93
- return {
94
- signature: signature,
95
- return_code: returnCode,
96
- error_message: errorMessage
97
- };
98
- }, common_1.processErrorResponse)];
99
- });
100
- });
101
- }
102
- exports.signSendChunkv1 = signSendChunkv1;
103
- function compressPublicKey(publicKey) {
104
- if (publicKey.length !== 65) {
105
- throw new Error('decompressed public key length should be 65 bytes');
106
- }
107
- var y = publicKey.slice(33, 65);
108
- // eslint-disable-next-line no-bitwise
109
- var z = Buffer.from([2 + (y[y.length - 1] & 1)]);
110
- return Buffer.concat([z, publicKey.slice(1, 33)]);
111
- }
112
- function publicKeyv1(app, data) {
113
- return __awaiter(this, void 0, void 0, function () {
114
- return __generator(this, function (_a) {
115
- return [2 /*return*/, app.transport.send(common_1.CLA, common_1.INS.INS_PUBLIC_KEY_SECP256K1, 0, 0, data, [common_1.ERROR_CODE.NoError]).then(function (response) {
116
- var errorCodeData = response.slice(-2);
117
- var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
118
- var pk = Buffer.from(response.slice(0, 65));
119
- return {
120
- pk: pk,
121
- compressed_pk: compressPublicKey(pk),
122
- return_code: returnCode,
123
- error_message: (0, common_1.errorCodeToString)(returnCode)
124
- };
125
- }, common_1.processErrorResponse)];
126
- });
127
- });
128
- }
129
- exports.publicKeyv1 = publicKeyv1;
130
- //# sourceMappingURL=commandsV1.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commandsV1.js","sourceRoot":"","sources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,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAClD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;AACnD,CAAC;AAED,SAAsB,WAAW,CAAC,GAAQ,EAAE,IAAY;;;YACtD,sBAAO,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,YAAG,EAAE,YAAG,CAAC,wBAAwB,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,mBAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,UAAC,QAAa;oBAChH,IAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;oBACxC,IAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;oBAC5D,IAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;oBAE7C,OAAO;wBACL,EAAE,IAAA;wBACF,aAAa,EAAE,iBAAiB,CAAC,EAAE,CAAC;wBACpC,WAAW,EAAE,UAAU;wBACvB,aAAa,EAAE,IAAA,0BAAiB,EAAC,UAAU,CAAC;qBAC7C,CAAA;gBACH,CAAC,EAAE,6BAAoB,CAAC,EAAA;;;CACzB;AAbD,kCAaC","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 ******************************************************************************* */\nimport { CLA, ERROR_CODE, errorCodeToString, INS, processErrorResponse, P2_VALUES } from './common'\n\nexport function serializePathv1(path: number[]) {\n if (path == null || path.length < 3) {\n throw new Error('Invalid path.')\n }\n if (path.length > 10) {\n throw new Error('Invalid path. Length should be <= 10')\n }\n const buf = Buffer.alloc(1 + 4 * path.length)\n buf.writeUInt8(path.length, 0)\n for (let i = 0; i < path.length; i += 1) {\n let v = path[i]\n if (i < 3) {\n // eslint-disable-next-line no-bitwise\n v |= 0x80000000 // Harden\n }\n buf.writeInt32LE(v, 1 + i * 4)\n }\n return buf\n}\n\nexport async function signSendChunkv1(app: any, chunkIdx: number, chunkNum: number, chunk: Buffer, txType = P2_VALUES.JSON) {\n return app.transport\n .send(CLA, INS.SIGN_SECP256K1, chunkIdx, txType, chunk, [ERROR_CODE.NoError, 0x6984, 0x6a80])\n .then((response: any) => {\n const errorCodeData = response.slice(-2)\n const returnCode = errorCodeData[0] * 256 + errorCodeData[1]\n let errorMessage = errorCodeToString(returnCode)\n\n if (returnCode === 0x6a80 || returnCode === 0x6984) {\n errorMessage = `${errorMessage} : ${response.slice(0, response.length - 2).toString('ascii')}`\n }\n\n let signature = null\n if (response.length > 2) {\n signature = response.slice(0, response.length - 2)\n }\n\n return {\n signature,\n return_code: returnCode,\n error_message: errorMessage,\n }\n }, processErrorResponse)\n}\n\nfunction compressPublicKey(publicKey: Buffer) {\n if (publicKey.length !== 65) {\n throw new Error('decompressed public key length should be 65 bytes')\n }\n const y = publicKey.slice(33, 65)\n // eslint-disable-next-line no-bitwise\n const z = Buffer.from([2 + (y[y.length - 1] & 1)])\n return Buffer.concat([z, publicKey.slice(1, 33)])\n}\n\nexport async function publicKeyv1(app: any, data: Buffer) {\n return app.transport.send(CLA, INS.INS_PUBLIC_KEY_SECP256K1, 0, 0, data, [ERROR_CODE.NoError]).then((response: any) => {\n const errorCodeData = response.slice(-2)\n const returnCode = errorCodeData[0] * 256 + errorCodeData[1]\n const pk = Buffer.from(response.slice(0, 65))\n\n return {\n pk,\n compressed_pk: compressPublicKey(pk),\n return_code: returnCode,\n error_message: errorCodeToString(returnCode),\n }\n }, processErrorResponse)\n}\n"]}
@@ -1,4 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function serializePathv2(path: number[]): Buffer;
3
- export declare function signSendChunkv2(app: any, chunkIdx: number, chunkNum: number, chunk: Buffer, txType?: number): Promise<any>;
4
- export declare function publicKeyv2(app: any, data: Buffer): Promise<any>;
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- exports.publicKeyv2 = exports.signSendChunkv2 = exports.serializePathv2 = void 0;
40
- /** ******************************************************************************
41
- * (c) 2018 - 2022 Zondax AG
42
- *
43
- * Licensed under the Apache License, Version 2.0 (the "License");
44
- * you may not use this file except in compliance with the License.
45
- * You may obtain a copy of the License at
46
- *
47
- * http://www.apache.org/licenses/LICENSE-2.0
48
- *
49
- * Unless required by applicable law or agreed to in writing, software
50
- * distributed under the License is distributed on an "AS IS" BASIS,
51
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
- * See the License for the specific language governing permissions and
53
- * limitations under the License.
54
- ******************************************************************************* */
55
- var commandsV1_1 = require("./commandsV1");
56
- var common_1 = require("./common");
57
- function serializePathv2(path) {
58
- if (!path || path.length !== 5) {
59
- throw new Error('Invalid path.');
60
- }
61
- var buf = Buffer.alloc(20);
62
- buf.writeUInt32LE(0x80000000 + path[0], 0);
63
- buf.writeUInt32LE(0x80000000 + path[1], 4);
64
- buf.writeUInt32LE(0x80000000 + path[2], 8);
65
- buf.writeUInt32LE(path[3], 12);
66
- buf.writeUInt32LE(path[4], 16);
67
- return buf;
68
- }
69
- exports.serializePathv2 = serializePathv2;
70
- function signSendChunkv2(app, chunkIdx, chunkNum, chunk, txType) {
71
- if (txType === void 0) { txType = common_1.P2_VALUES.JSON; }
72
- return __awaiter(this, void 0, void 0, function () {
73
- var payloadType;
74
- return __generator(this, function (_a) {
75
- payloadType = common_1.PAYLOAD_TYPE.ADD;
76
- if (chunkIdx === 1) {
77
- payloadType = common_1.PAYLOAD_TYPE.INIT;
78
- }
79
- if (chunkIdx === chunkNum) {
80
- payloadType = common_1.PAYLOAD_TYPE.LAST;
81
- }
82
- return [2 /*return*/, (0, commandsV1_1.signSendChunkv1)(app, payloadType, 0, chunk, txType)];
83
- });
84
- });
85
- }
86
- exports.signSendChunkv2 = signSendChunkv2;
87
- function publicKeyv2(app, data) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- return __generator(this, function (_a) {
90
- return [2 /*return*/, app.transport.send(common_1.CLA, common_1.INS.GET_ADDR_SECP256K1, 0, 0, data, [common_1.ERROR_CODE.NoError]).then(function (response) {
91
- var errorCodeData = response.slice(-2);
92
- var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
93
- var compressedPk = Buffer.from(response.slice(0, 33));
94
- return {
95
- pk: 'OBSOLETE PROPERTY',
96
- compressed_pk: compressedPk,
97
- return_code: returnCode,
98
- error_message: (0, common_1.errorCodeToString)(returnCode)
99
- };
100
- }, common_1.processErrorResponse)];
101
- });
102
- });
103
- }
104
- exports.publicKeyv2 = publicKeyv2;
105
- //# sourceMappingURL=commandsV2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commandsV2.js","sourceRoot":"","sources":["../src/commandsV2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;mFAcmF;AACnF,2CAA8C;AAC9C,mCAAiH;AAEjH,SAAgB,eAAe,CAAC,IAAc;IAC5C,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;KACjC;IAED,IAAM,GAAG,GAAG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Aa;oBAC1G,IAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;oBACxC,IAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;oBAC5D,IAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;oBAEvD,OAAO;wBACL,EAAE,EAAE,mBAAmB;wBACvB,aAAa,EAAE,YAAY;wBAC3B,WAAW,EAAE,UAAU;wBACvB,aAAa,EAAE,IAAA,0BAAiB,EAAC,UAAU,CAAC;qBAC7C,CAAA;gBACH,CAAC,EAAE,6BAAoB,CAAC,EAAA;;;CACzB;AAbD,kCAaC","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 ******************************************************************************* */\nimport { signSendChunkv1 } from './commandsV1'\nimport { CLA, ERROR_CODE, errorCodeToString, INS, PAYLOAD_TYPE, processErrorResponse, P2_VALUES } from './common'\n\nexport function serializePathv2(path: number[]) {\n if (!path || path.length !== 5) {\n throw new Error('Invalid path.')\n }\n\n const buf = Buffer.alloc(20)\n buf.writeUInt32LE(0x80000000 + path[0], 0)\n buf.writeUInt32LE(0x80000000 + path[1], 4)\n buf.writeUInt32LE(0x80000000 + path[2], 8)\n buf.writeUInt32LE(path[3], 12)\n buf.writeUInt32LE(path[4], 16)\n\n return buf\n}\n\nexport async function signSendChunkv2(app: any, chunkIdx: number, chunkNum: number, chunk: Buffer, txType = P2_VALUES.JSON) {\n let payloadType = PAYLOAD_TYPE.ADD\n if (chunkIdx === 1) {\n payloadType = PAYLOAD_TYPE.INIT\n }\n if (chunkIdx === chunkNum) {\n payloadType = PAYLOAD_TYPE.LAST\n }\n\n return signSendChunkv1(app, payloadType, 0, chunk, txType)\n}\n\nexport async function publicKeyv2(app: any, data: Buffer) {\n return app.transport.send(CLA, INS.GET_ADDR_SECP256K1, 0, 0, data, [ERROR_CODE.NoError]).then((response: any) => {\n const errorCodeData = response.slice(-2)\n const returnCode = errorCodeData[0] * 256 + errorCodeData[1]\n const compressedPk = Buffer.from(response.slice(0, 33))\n\n return {\n pk: 'OBSOLETE PROPERTY',\n compressed_pk: compressedPk,\n return_code: returnCode,\n error_message: errorCodeToString(returnCode),\n }\n }, processErrorResponse)\n}\n"]}
package/dist/common.d.ts DELETED
@@ -1,43 +0,0 @@
1
- /** ******************************************************************************
2
- * (c) 2018 - 2022 Zondax AG
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- ******************************************************************************* */
16
- export declare const CLA = 85;
17
- export declare const CHUNK_SIZE = 250;
18
- export declare const APP_KEY = "CSM";
19
- export declare const INS: {
20
- GET_VERSION: number;
21
- INS_PUBLIC_KEY_SECP256K1: number;
22
- SIGN_SECP256K1: number;
23
- GET_ADDR_SECP256K1: number;
24
- };
25
- export declare const PAYLOAD_TYPE: {
26
- INIT: number;
27
- ADD: number;
28
- LAST: number;
29
- };
30
- export declare const P1_VALUES: {
31
- ONLY_RETRIEVE: number;
32
- SHOW_ADDRESS_IN_DEVICE: number;
33
- };
34
- export declare const P2_VALUES: {
35
- JSON: number;
36
- TEXTUAL: number;
37
- };
38
- export declare const ERROR_CODE: {
39
- NoError: number;
40
- };
41
- export declare function errorCodeToString(statusCode: number): any;
42
- export declare function processErrorResponse(response: any): any;
43
- export declare function getVersion(transport: any): Promise<any>;
package/dist/common.js DELETED
@@ -1,166 +0,0 @@
1
- "use strict";
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 (g && (g = 0, op[0] && (_ = 0)), _) 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.P2_VALUES = 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
63
- };
64
- exports.PAYLOAD_TYPE = {
65
- INIT: 0x00,
66
- ADD: 0x01,
67
- LAST: 0x02
68
- };
69
- exports.P1_VALUES = {
70
- ONLY_RETRIEVE: 0x00,
71
- SHOW_ADDRESS_IN_DEVICE: 0x01
72
- };
73
- exports.P2_VALUES = {
74
- JSON: 0x0,
75
- TEXTUAL: 0x1
76
- };
77
- exports.ERROR_CODE = {
78
- NoError: 0x9000
79
- };
80
- var ERROR_DESCRIPTION = {
81
- 1: 'U2F: Unknown',
82
- 2: 'U2F: Bad request',
83
- 3: 'U2F: Configuration unsupported',
84
- 4: 'U2F: Device Ineligible',
85
- 5: 'U2F: Timeout',
86
- 14: 'Timeout',
87
- 0x9000: 'No errors',
88
- 0x9001: 'Device is busy',
89
- 0x6802: 'Error deriving keys',
90
- 0x6400: 'Execution Error',
91
- 0x6700: 'Wrong Length',
92
- 0x6982: 'Empty Buffer',
93
- 0x6983: 'Output buffer too small',
94
- 0x6984: 'Data is invalid',
95
- 0x6985: 'Conditions not satisfied',
96
- 0x6986: 'Transaction rejected',
97
- 0x6a80: 'Bad key handle',
98
- 0x6b00: 'Invalid P1/P2',
99
- 0x6d00: 'Instruction not supported',
100
- 0x6e00: 'App does not seem to be open',
101
- 0x6f00: 'Unknown error',
102
- 0x6f01: 'Sign/verify error'
103
- };
104
- function errorCodeToString(statusCode) {
105
- if (statusCode in ERROR_DESCRIPTION)
106
- return ERROR_DESCRIPTION[statusCode];
107
- return "Unknown Status Code: ".concat(statusCode);
108
- }
109
- exports.errorCodeToString = errorCodeToString;
110
- function isDict(v) {
111
- return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
112
- }
113
- function processErrorResponse(response) {
114
- if (response) {
115
- if (isDict(response)) {
116
- if (Object.prototype.hasOwnProperty.call(response, 'statusCode')) {
117
- return {
118
- return_code: response.statusCode,
119
- error_message: errorCodeToString(response.statusCode)
120
- };
121
- }
122
- if (Object.prototype.hasOwnProperty.call(response, 'return_code') &&
123
- Object.prototype.hasOwnProperty.call(response, 'error_message')) {
124
- return response;
125
- }
126
- }
127
- return {
128
- return_code: 0xffff,
129
- error_message: response.toString()
130
- };
131
- }
132
- return {
133
- return_code: 0xffff,
134
- error_message: response.toString()
135
- };
136
- }
137
- exports.processErrorResponse = processErrorResponse;
138
- function getVersion(transport) {
139
- return __awaiter(this, void 0, void 0, function () {
140
- return __generator(this, function (_a) {
141
- return [2 /*return*/, transport.send(exports.CLA, exports.INS.GET_VERSION, 0, 0).then(function (response) {
142
- var errorCodeData = response.slice(-2);
143
- var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
144
- var targetId = 0;
145
- if (response.length >= 9) {
146
- /* eslint-disable no-bitwise */
147
- targetId = (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0);
148
- /* eslint-enable no-bitwise */
149
- }
150
- return {
151
- return_code: returnCode,
152
- error_message: errorCodeToString(returnCode),
153
- // ///
154
- test_mode: response[0] !== 0,
155
- major: response[1],
156
- minor: response[2],
157
- patch: response[3],
158
- device_locked: response[4] === 1,
159
- target_id: targetId.toString(16)
160
- };
161
- }, processErrorResponse)];
162
- });
163
- });
164
- }
165
- exports.getVersion = getVersion;
166
- //# sourceMappingURL=common.js.map
@@ -1 +0,0 @@
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;AAChB,QAAA,OAAO,GAAG,KAAK,CAAA;AAEf,QAAA,GAAG,GAAG;IACjB,WAAW,EAAE,IAAI;IACjB,wBAAwB,EAAE,IAAI;IAC9B,cAAc,EAAE,IAAI;IACpB,kBAAkB,EAAE,IAAI;CACzB,CAAA;AAEY,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,IAAI;CACX,CAAA;AAEY,QAAA,SAAS,GAAG;IACvB,aAAa,EAAE,IAAI;IACnB,sBAAsB,EAAE,IAAI;CAC7B,CAAA;AAEY,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,GAAG;IACT,OAAO,EAAE,GAAG;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AAA;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 P2_VALUES = {\n JSON: 0x0,\n TEXTUAL: 0x1,\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"]}
@@ -1,19 +0,0 @@
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[], buffer: Buffer): 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, txType?: number): Promise<any>;
18
- sign(path: number[], buffer: Buffer, txType?: number): Promise<any>;
19
- }