@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.
- package/LICENSE +1 -1
- package/README.md +39 -7
- package/dist/commandsV1.d.ts +4 -0
- package/dist/commandsV1.js +129 -0
- package/dist/commandsV1.js.map +1 -0
- package/dist/commandsV2.d.ts +4 -0
- package/dist/commandsV2.js +104 -0
- package/dist/commandsV2.js.map +1 -0
- package/dist/common.d.ts +39 -0
- package/dist/common.js +143 -132
- package/dist/common.js.map +1 -0
- package/dist/cosmosApp.d.ts +19 -0
- package/dist/cosmosApp.js +377 -0
- package/dist/cosmosApp.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -608
- package/dist/index.js.map +1 -0
- package/package.json +64 -50
- package/yarn.lock +6661 -0
- package/.babelrc +0 -13
- package/.circleci/config.yml +0 -62
- package/.editorconfig +0 -14
- package/.eslintrc.json +0 -31
- package/.idea/codeStyles/Project.xml +0 -57
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/ledger-cosmos-js.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -57
- package/.prettierrc.json +0 -4
- package/certs/.gitkeep +0 -0
- package/certs/openssl.cnf +0 -12
- package/dist/helperV1.js +0 -127
- package/dist/helperV2.js +0 -97
- package/docs/example.png +0 -0
- package/jest.config.integration.js +0 -9
- package/jest.config.js +0 -32
- package/jest.config.unit.js +0 -9
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -17
- package/src/common.js +0 -114
- package/src/helperV1.js +0 -73
- package/src/helperV2.js +0 -44
- package/src/index.js +0 -336
- package/tests/basic.ispec.js +0 -390
- package/tests/basic.spec.js +0 -8
- package/tests/jest.js +0 -2
- package/vue.config.js +0 -11
- package/vue_example/App.vue +0 -29
- package/vue_example/assets/logo.png +0 -0
- package/vue_example/components/LedgerExample.vue +0 -252
- package/vue_example/main.js +0 -9
package/dist/common.js
CHANGED
|
@@ -1,151 +1,162 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
LAST: 0x02
|
|
64
|
+
exports.PAYLOAD_TYPE = {
|
|
65
|
+
INIT: 0x00,
|
|
66
|
+
ADD: 0x01,
|
|
67
|
+
LAST: 0x02
|
|
37
68
|
};
|
|
38
|
-
exports.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
SHOW_ADDRESS_IN_DEVICE: 0x01
|
|
69
|
+
exports.P1_VALUES = {
|
|
70
|
+
ONLY_RETRIEVE: 0x00,
|
|
71
|
+
SHOW_ADDRESS_IN_DEVICE: 0x01
|
|
42
72
|
};
|
|
43
|
-
exports.
|
|
44
|
-
|
|
45
|
-
NoError: 0x9000
|
|
73
|
+
exports.ERROR_CODE = {
|
|
74
|
+
NoError: 0x9000
|
|
46
75
|
};
|
|
47
|
-
exports.ERROR_CODE = ERROR_CODE;
|
|
48
76
|
var ERROR_DESCRIPTION = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
75
|
-
|
|
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
|
-
|
|
107
|
+
return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
|
|
80
108
|
}
|
|
81
|
-
|
|
82
109
|
function processErrorResponse(response) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
88
|
-
|
|
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
|
-
|
|
99
|
-
|
|
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(
|
|
110
|
-
|
|
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
|
-
|
|
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;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,UAAU,GAAG;IACxB,OAAO,EAAE,MAAM;CAChB,CAAA;AAED,IAAM,iBAAiB,GAAQ;IAC7B,CAAC,EAAE,cAAc;IACjB,CAAC,EAAE,kBAAkB;IACrB,CAAC,EAAE,gCAAgC;IACnC,CAAC,EAAE,wBAAwB;IAC3B,CAAC,EAAE,cAAc;IACjB,EAAE,EAAE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E,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
|
+
}
|