@zondax/ledger-cosmos-js 4.0.1 → 4.1.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/README.npm.md +42 -0
- package/dist/consts.js +11 -1
- package/dist/consts.js.map +1 -1
- package/dist/index.d.ts +2 -18
- package/dist/index.js +23 -8
- package/dist/index.js.map +1 -1
- package/package.json +27 -29
package/README.npm.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @zondax/ledger-cosmos-js
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+
[](https://github.com/cosmos/ledger-cosmos-js/actions?query=workflow%3AMain)
|
|
7
|
+
[](https://badge.fury.io/js/%40cosmos%2Fledger-cosmos-js)
|
|
8
|
+
|
|
9
|
+
This package provides a basic client library to communicate with a Tendermint/Cosmos App running in a Ledger Nano S/S+/X devices
|
|
10
|
+
|
|
11
|
+
We recommend using the npmjs package in order to receive updates/fixes.
|
|
12
|
+
|
|
13
|
+
# Available commands
|
|
14
|
+
|
|
15
|
+
| Operation | Response | Command |
|
|
16
|
+
| -------------------- | --------------------------- | --------------------------- |
|
|
17
|
+
| getVersion | app version | --------------- |
|
|
18
|
+
| publicKey | pubkey | path (legacy command) |
|
|
19
|
+
| getAddressAndPubKey | pubkey + address | path + ( showInDevice ) |
|
|
20
|
+
| showAddressAndPubKey | signed message | path |
|
|
21
|
+
| appInfo | name, version, flags, etc | --------------- |
|
|
22
|
+
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
|
|
23
|
+
| sign | signed message | path + message + (HRP) |
|
|
24
|
+
|
|
25
|
+
getAddress command requires that you set the derivation path (account, change, index) and has an option parameter to display the address on the device. By default, it will retrieve the information without user confirmation.
|
|
26
|
+
|
|
27
|
+
# Testing with real devices
|
|
28
|
+
|
|
29
|
+
It is possible to test this package with a real Ledger Nano device. To accomplish that, you will need to follow these steps:
|
|
30
|
+
|
|
31
|
+
- Install the application in the Ledger device
|
|
32
|
+
- Install the dependencies from this project
|
|
33
|
+
- Run tests
|
|
34
|
+
|
|
35
|
+
```shell script
|
|
36
|
+
yarn install
|
|
37
|
+
yarn test:integration
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# Who we are?
|
|
41
|
+
|
|
42
|
+
We are Zondax, a company pioneering blockchain services. If you want to know more about us, please visit us at [zondax.ch](https://zondax.ch)
|
package/dist/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PKLEN = exports.CLA = void 0;
|
|
3
|
+
exports.PKLEN = exports.P2_VALUES = exports.P1_VALUES = exports.CLA = void 0;
|
|
4
4
|
/** ******************************************************************************
|
|
5
5
|
* (c) Zondax AG
|
|
6
6
|
*
|
|
@@ -17,5 +17,15 @@ exports.PKLEN = exports.CLA = void 0;
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
******************************************************************************* */
|
|
19
19
|
exports.CLA = 0x55;
|
|
20
|
+
var P1_VALUES;
|
|
21
|
+
(function (P1_VALUES) {
|
|
22
|
+
P1_VALUES[P1_VALUES["ONLY_RETRIEVE"] = 0] = "ONLY_RETRIEVE";
|
|
23
|
+
P1_VALUES[P1_VALUES["SHOW_ADDRESS_IN_DEVICE"] = 1] = "SHOW_ADDRESS_IN_DEVICE";
|
|
24
|
+
})(P1_VALUES || (exports.P1_VALUES = P1_VALUES = {}));
|
|
25
|
+
var P2_VALUES;
|
|
26
|
+
(function (P2_VALUES) {
|
|
27
|
+
P2_VALUES[P2_VALUES["JSON"] = 0] = "JSON";
|
|
28
|
+
P2_VALUES[P2_VALUES["TEXTUAL"] = 1] = "TEXTUAL";
|
|
29
|
+
})(P2_VALUES || (exports.P2_VALUES = P2_VALUES = {}));
|
|
20
30
|
exports.PKLEN = 33;
|
|
21
31
|
//# sourceMappingURL=consts.js.map
|
package/dist/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;mFAcmF;AACtE,QAAA,GAAG,GAAG,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;mFAcmF;AACtE,QAAA,GAAG,GAAG,IAAI,CAAA;AAEvB,IAAkB,SAGjB;AAHD,WAAkB,SAAS;IACzB,2DAAoB,CAAA;IACpB,6EAA6B,CAAA;AAC/B,CAAC,EAHiB,SAAS,yBAAT,SAAS,QAG1B;AAED,IAAkB,SAGjB;AAHD,WAAkB,SAAS;IACzB,yCAAU,CAAA;IACV,+CAAa,CAAA;AACf,CAAC,EAHiB,SAAS,yBAAT,SAAS,QAG1B;AAEY,QAAA,KAAK,GAAG,EAAE,CAAA","sourcesContent":["/** ******************************************************************************\n * (c) 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 ******************************************************************************* */\nexport const CLA = 0x55\n\nexport const enum P1_VALUES {\n ONLY_RETRIEVE = 0x00,\n SHOW_ADDRESS_IN_DEVICE = 0x01,\n}\n\nexport const enum P2_VALUES {\n JSON = 0x0,\n TEXTUAL = 0x1,\n}\n\nexport const PKLEN = 33\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* (c) 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
|
-
import type Transport from '@ledgerhq/hw-transport';
|
|
17
|
-
import BaseApp, { INSGeneric, ResponsePayload } from '@zondax/ledger-js';
|
|
1
|
+
import BaseApp, { INSGeneric, type LedgerTransport, ResponsePayload } from '@zondax/ledger-js';
|
|
18
2
|
import { P2_VALUES } from './consts';
|
|
19
3
|
import { type ResponseAddress, type ResponsePubkey, ResponseSign } from './types';
|
|
20
4
|
export default class CosmosApp extends BaseApp {
|
|
@@ -38,7 +22,7 @@ export default class CosmosApp extends BaseApp {
|
|
|
38
22
|
* @param transport - The transport instance.
|
|
39
23
|
* @throws {Error} - If the transport is not defined.
|
|
40
24
|
*/
|
|
41
|
-
constructor(transport:
|
|
25
|
+
constructor(transport: LedgerTransport);
|
|
42
26
|
private serializeHRP;
|
|
43
27
|
private serializeCosmosPath;
|
|
44
28
|
publicKey(path: string): Promise<ResponsePubkey>;
|
package/dist/index.js
CHANGED
|
@@ -33,8 +33,23 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
/** ******************************************************************************
|
|
37
|
+
* (c) Zondax AG
|
|
38
|
+
*
|
|
39
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
40
|
+
* you may not use this file except in compliance with the License.
|
|
41
|
+
* You may obtain a copy of the License at
|
|
42
|
+
*
|
|
43
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
44
|
+
*
|
|
45
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
46
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
47
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
48
|
+
* See the License for the specific language governing permissions and
|
|
49
|
+
* limitations under the License.
|
|
50
|
+
******************************************************************************* */
|
|
51
|
+
const legacy_js_1 = require("@noble/hashes/legacy.js");
|
|
52
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
38
53
|
const base_1 = require("@scure/base");
|
|
39
54
|
const ledger_js_1 = __importStar(require("@zondax/ledger-js"));
|
|
40
55
|
const byteStream_1 = require("@zondax/ledger-js/dist/byteStream");
|
|
@@ -121,7 +136,7 @@ class CosmosApp extends ledger_js_1.default {
|
|
|
121
136
|
const serializedPath = this.serializeCosmosPath(path);
|
|
122
137
|
const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
|
|
123
138
|
try {
|
|
124
|
-
const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1,
|
|
139
|
+
const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, consts_1.P1_VALUES.ONLY_RETRIEVE, 0, data);
|
|
125
140
|
const response = (0, ledger_js_1.processResponse)(responseBuffer);
|
|
126
141
|
const compressed_pk = response.readBytes(consts_1.PKLEN);
|
|
127
142
|
const bech32_address = response.readBytes(response.length()).toString();
|
|
@@ -135,7 +150,7 @@ class CosmosApp extends ledger_js_1.default {
|
|
|
135
150
|
const serializedPath = this.serializeCosmosPath(path);
|
|
136
151
|
const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
|
|
137
152
|
try {
|
|
138
|
-
const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1,
|
|
153
|
+
const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, consts_1.P1_VALUES.SHOW_ADDRESS_IN_DEVICE, 0, data);
|
|
139
154
|
const response = (0, ledger_js_1.processResponse)(responseBuffer);
|
|
140
155
|
const compressed_pk = response.readBytes(consts_1.PKLEN);
|
|
141
156
|
const bech32_address = response.readBytes(response.length()).toString();
|
|
@@ -149,8 +164,8 @@ class CosmosApp extends ledger_js_1.default {
|
|
|
149
164
|
if (pk.length !== 33) {
|
|
150
165
|
throw new Error('expected compressed public key [31 bytes]');
|
|
151
166
|
}
|
|
152
|
-
const hashSha256 = (0,
|
|
153
|
-
const hashRip = (0,
|
|
167
|
+
const hashSha256 = (0, sha2_js_1.sha256)(pk);
|
|
168
|
+
const hashRip = (0, legacy_js_1.ripemd160)(hashSha256);
|
|
154
169
|
return base_1.bech32.encode(hrp, base_1.bech32.toWords(hashRip));
|
|
155
170
|
}
|
|
156
171
|
async prepareChunks_hrp(path, buffer, hrp) {
|
|
@@ -163,7 +178,7 @@ class CosmosApp extends ledger_js_1.default {
|
|
|
163
178
|
}
|
|
164
179
|
return chunks;
|
|
165
180
|
}
|
|
166
|
-
async signSendCosmosChunk(chunkIdx, chunkNum, chunk, txtype =
|
|
181
|
+
async signSendCosmosChunk(chunkIdx, chunkNum, chunk, txtype = consts_1.P2_VALUES.JSON) {
|
|
167
182
|
const payloadType = chunkIdx === 1 ? ledger_js_1.PAYLOAD_TYPE.INIT : chunkIdx === chunkNum ? ledger_js_1.PAYLOAD_TYPE.LAST : ledger_js_1.PAYLOAD_TYPE.ADD;
|
|
168
183
|
const statusList = [ledger_js_1.LedgerError.NoErrors, ledger_js_1.LedgerError.DataIsInvalid, ledger_js_1.LedgerError.BadKeyHandle];
|
|
169
184
|
const responseBuffer = await this.transport.send(this.CLA, this.INS.SIGN_SECP256K1, payloadType, txtype, chunk, statusList);
|
|
@@ -182,7 +197,7 @@ class CosmosApp extends ledger_js_1.default {
|
|
|
182
197
|
throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
|
|
183
198
|
}
|
|
184
199
|
}
|
|
185
|
-
async sign(path, buffer, hrp, txtype =
|
|
200
|
+
async sign(path, buffer, hrp, txtype = consts_1.P2_VALUES.JSON) {
|
|
186
201
|
return this.signImpl(path, buffer, txtype, hrp);
|
|
187
202
|
}
|
|
188
203
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,uDAAmD;AACnD,iDAA6C;AAC7C,sCAAoC;AACpC,+DAU0B;AAC1B,kEAA8D;AAE9D,qCAA2D;AAG3D,IAAK,iBAMJ;AAND,WAAK,iBAAiB;IACpB,uIAAkD,CAAA;IAClD,mGAAgC,CAAA;IAChC,2FAA4B,CAAA;IAC5B,2GAAoC,CAAA;IACpC,6GAAqC,CAAA;AACvC,CAAC,EANI,iBAAiB,KAAjB,iBAAiB,QAMrB;AAED,MAAM,gCAAgC,GAAG;IACvC,GAAG,sCAA0B;IAC7B,CAAC,iBAAiB,CAAC,yCAAyC,CAAC,EAAE,gEAAgE;IAC/H,CAAC,iBAAiB,CAAC,uBAAuB,CAAC,EAAE,8CAA8C;IAC3F,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,EAAE,oBAAoB;IAC7D,CAAC,iBAAiB,CAAC,2BAA2B,CAAC,EAAE,4BAA4B;IAC7E,CAAC,iBAAiB,CAAC,4BAA4B,CAAC,EAAE,4BAA4B;CAC/E,CAAA;AAED,MAAqB,SAAU,SAAQ,mBAAO;IAe5C;;;;OAIG;IACH,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;QAEnC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAEO,YAAY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C/D,SAAS,EAAE,GAAG;IACd,mBAAmB,EAAE,CAAC,CAAC,CAAC;CACzB,CAAA;kBAbkB,SAAS","sourcesContent":["/** ******************************************************************************\n * (c) 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 type Transport from '@ledgerhq/hw-transport'\nimport { ripemd160 } from '@noble/hashes/ripemd160'\nimport { sha256 } from '@noble/hashes/sha256'\nimport { bech32 } from '@scure/base'\nimport BaseApp, {\n ERROR_DESCRIPTION_OVERRIDE,\n HARDENED,\n INSGeneric,\n LedgerError,\n PAYLOAD_TYPE,\n ResponseError,\n ResponsePayload,\n processErrorResponse,\n processResponse,\n} from '@zondax/ledger-js'\nimport { ByteStream } from '@zondax/ledger-js/dist/byteStream'\n\nimport { CLA, P1_VALUES, P2_VALUES, PKLEN } from './consts'\nimport { type ResponseAddress, type ResponsePubkey, ResponseSign } from './types'\n\nenum CosmosCostumError {\n ErrorTransactionDataExceedsBufferCapacity = 0x6988,\n ErrorInvalidHDPathValue = 0x6989,\n ErrorHrpWrongLength = 0x698a,\n ErrorInvalidHDPathCoinValue = 0x698b,\n ErrorChainConfigNotSupported = 0x698c,\n}\n\nconst COSMOS_CUSTOM_ERROR_DESCRIPTIONS = {\n ...ERROR_DESCRIPTION_OVERRIDE,\n [CosmosCostumError.ErrorTransactionDataExceedsBufferCapacity]: \"Transaction data exceeds the device's internal buffer capacity\",\n [CosmosCostumError.ErrorInvalidHDPathValue]: 'Invalid HD Path Value. Expert Mode required.',\n [CosmosCostumError.ErrorHrpWrongLength]: 'Invalid HRP length',\n [CosmosCostumError.ErrorInvalidHDPathCoinValue]: 'Invalid HD Path Coin Value',\n [CosmosCostumError.ErrorChainConfigNotSupported]: 'Chain config not supported',\n}\n\nexport default class CosmosApp extends BaseApp {\n static _INS = {\n GET_VERSION: 0x00,\n SIGN_SECP256K1: 0x02,\n GET_ADDR_SECP256K1: 0x04,\n }\n\n static _params = {\n cla: CLA,\n ins: { ...CosmosApp._INS } as INSGeneric,\n p1Values: { ONLY_RETRIEVE: 0x00, SHOW_ADDRESS_IN_DEVICE: 0x01 },\n chunkSize: 250,\n requiredPathLengths: [5],\n }\n\n /**\n * Constructs a new CosmosApp instance.\n * @param transport - The transport instance.\n * @throws {Error} - If the transport is not defined.\n */\n constructor(transport: Transport) {\n super(transport, CosmosApp._params)\n\n if (!this.transport) {\n throw new Error('Transport has not been defined')\n }\n }\n\n private serializeHRP(hrp: string) {\n if (!hrp || hrp.length < 3 || hrp.length > 83) {\n throw new Error('Invalid HRP')\n }\n\n const buf = new ByteStream()\n buf.appendUint8(hrp.length)\n buf.appendBytes(Buffer.from(hrp))\n\n return buf.getCompleteBuffer()\n }\n\n private serializeCosmosPath(path: string) {\n if (typeof path !== 'string') {\n throw new ResponseError(LedgerError.GenericError, \"Path should be a string (e.g \\\"m/44'/461'/5'/0/3\\\")\")\n }\n\n if (!path.startsWith('m/')) {\n throw new ResponseError(LedgerError.GenericError, 'Path should start with \"m/\" (e.g \"m/44\\'/461\\'/5\\'/0/3\")')\n }\n\n const pathArray = path.split('/').slice(1)\n\n if (this.REQUIRED_PATH_LENGTHS && this.REQUIRED_PATH_LENGTHS.length > 0 && !this.REQUIRED_PATH_LENGTHS.includes(pathArray.length)) {\n throw new ResponseError(LedgerError.GenericError, \"Invalid path length. (e.g \\\"m/44'/5757'/5'/0/3\\\")\")\n }\n\n const buf = new ByteStream()\n pathArray.forEach((child: string) => {\n let value = 0\n\n if (child.endsWith(\"'\")) {\n value += HARDENED\n child = child.slice(0, -1)\n }\n\n const numChild = Number(child)\n\n if (Number.isNaN(numChild)) {\n throw new ResponseError(LedgerError.GenericError, `Invalid path : ${child} is not a number. (e.g \"m/44'/461'/5'/0/3\")`)\n }\n value += numChild\n buf.appendUint32(value)\n })\n\n return buf.getCompleteBuffer()\n }\n\n async publicKey(path: string): Promise<ResponsePubkey> {\n const serializedPath = this.serializeCosmosPath(path)\n const data = Buffer.concat([this.serializeHRP('cosmos'), serializedPath])\n\n try {\n const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0, 0, data)\n const response = processResponse(responseBuffer)\n const compressed_pk = Buffer.from(response.readBytes(PKLEN))\n const bech32_address = response.readBytes(response.length()).toString()\n\n return { compressed_pk, bech32_address }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n\n async getAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress> {\n const serializedPath = this.serializeCosmosPath(path)\n const data = Buffer.concat([this.serializeHRP(hrp), serializedPath])\n\n try {\n const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, P1_VALUES.ONLY_RETRIEVE, 0, data)\n\n const response = processResponse(responseBuffer)\n const compressed_pk = response.readBytes(PKLEN)\n const bech32_address = response.readBytes(response.length()).toString()\n\n return { compressed_pk, bech32_address }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n\n async showAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress> {\n const serializedPath = this.serializeCosmosPath(path)\n const data = Buffer.concat([this.serializeHRP(hrp), serializedPath])\n\n try {\n const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, P1_VALUES.SHOW_ADDRESS_IN_DEVICE, 0, data)\n\n const response = processResponse(responseBuffer)\n const compressed_pk = response.readBytes(PKLEN)\n const bech32_address = response.readBytes(response.length()).toString()\n\n return { compressed_pk, bech32_address }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n\n static getBech32FromPK(hrp: string, pk: Buffer) {\n if (pk.length !== 33) {\n throw new Error('expected compressed public key [31 bytes]')\n }\n const hashSha256 = sha256(pk)\n const hashRip = ripemd160(hashSha256)\n return bech32.encode(hrp, bech32.toWords(hashRip))\n }\n\n async prepareChunks_hrp(path: string, buffer: Buffer, hrp?: string) {\n const serializedPath = this.serializeCosmosPath(path)\n const firstChunk = hrp ? Buffer.concat([serializedPath, this.serializeHRP(hrp)]) : serializedPath\n\n const chunks = [firstChunk]\n\n for (let i = 0; i < buffer.length; i += this.CHUNK_SIZE) {\n const end = Math.min(i + this.CHUNK_SIZE, buffer.length)\n chunks.push(buffer.subarray(i, end))\n }\n\n return chunks\n }\n\n async signSendCosmosChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, txtype = P2_VALUES.JSON): Promise<ResponsePayload> {\n const payloadType = chunkIdx === 1 ? PAYLOAD_TYPE.INIT : chunkIdx === chunkNum ? PAYLOAD_TYPE.LAST : PAYLOAD_TYPE.ADD\n\n const statusList = [LedgerError.NoErrors, LedgerError.DataIsInvalid, LedgerError.BadKeyHandle]\n\n const responseBuffer = await this.transport.send(this.CLA, this.INS.SIGN_SECP256K1, payloadType, txtype, chunk, statusList)\n return processResponse(responseBuffer)\n }\n\n private async signImpl(path: string, buffer: Buffer, txtype: number, hrp?: string): Promise<ResponseSign> {\n const chunks = await this.prepareChunks_hrp(path, buffer, hrp)\n\n try {\n let result = await this.signSendCosmosChunk(1, chunks.length, chunks[0], txtype)\n\n for (let i = 1; i < chunks.length; i++) {\n result = await this.signSendCosmosChunk(i + 1, chunks.length, chunks[i], txtype)\n }\n\n return { signature: result.readBytes(result.length()) }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n async sign(path: string, buffer: Buffer, hrp?: string, txtype = P2_VALUES.JSON): Promise<ResponseSign> {\n return this.signImpl(path, buffer, txtype, hrp)\n }\n}\n"]}
|
|
1
|
+
{"version":3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AG,MAAM,IAAI,CAAC,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;YAEhF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACvC,MAAM,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;YAClF,CAAC;YAED,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAA;QACzD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAA,gCAAoB,EAAC,CAAC,EAAE,gCAAgC,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,MAAc,EAAE,GAAY,EAAE,MAAM,GAAG,kBAAS,CAAC,IAAI;QAC5E,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;IACjD,CAAC;;AA9KM,cAAI,GAAG;IACZ,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,IAAI;IACpB,kBAAkB,EAAE,IAAI;CACzB,CAAA;AAEM,iBAAO,GAAG;IACf,GAAG,EAAE,YAAG;IACR,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC,IAAI,EAAgB;IACxC,QAAQ,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE;IAC/D,SAAS,EAAE,GAAG;IACd,mBAAmB,EAAE,CAAC,CAAC,CAAC;CACzB,CAAA;kBAbkB,SAAS","sourcesContent":["/** ******************************************************************************\n * (c) 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 { ripemd160 } from '@noble/hashes/legacy.js'\nimport { sha256 } from '@noble/hashes/sha2.js'\nimport { bech32 } from '@scure/base'\nimport BaseApp, {\n ERROR_DESCRIPTION_OVERRIDE,\n HARDENED,\n INSGeneric,\n LedgerError,\n type LedgerTransport,\n PAYLOAD_TYPE,\n ResponseError,\n ResponsePayload,\n processErrorResponse,\n processResponse,\n} from '@zondax/ledger-js'\nimport { ByteStream } from '@zondax/ledger-js/dist/byteStream'\n\nimport { CLA, P1_VALUES, P2_VALUES, PKLEN } from './consts'\nimport { type ResponseAddress, type ResponsePubkey, ResponseSign } from './types'\n\nenum CosmosCostumError {\n ErrorTransactionDataExceedsBufferCapacity = 0x6988,\n ErrorInvalidHDPathValue = 0x6989,\n ErrorHrpWrongLength = 0x698a,\n ErrorInvalidHDPathCoinValue = 0x698b,\n ErrorChainConfigNotSupported = 0x698c,\n}\n\nconst COSMOS_CUSTOM_ERROR_DESCRIPTIONS = {\n ...ERROR_DESCRIPTION_OVERRIDE,\n [CosmosCostumError.ErrorTransactionDataExceedsBufferCapacity]: \"Transaction data exceeds the device's internal buffer capacity\",\n [CosmosCostumError.ErrorInvalidHDPathValue]: 'Invalid HD Path Value. Expert Mode required.',\n [CosmosCostumError.ErrorHrpWrongLength]: 'Invalid HRP length',\n [CosmosCostumError.ErrorInvalidHDPathCoinValue]: 'Invalid HD Path Coin Value',\n [CosmosCostumError.ErrorChainConfigNotSupported]: 'Chain config not supported',\n}\n\nexport default class CosmosApp extends BaseApp {\n static _INS = {\n GET_VERSION: 0x00,\n SIGN_SECP256K1: 0x02,\n GET_ADDR_SECP256K1: 0x04,\n }\n\n static _params = {\n cla: CLA,\n ins: { ...CosmosApp._INS } as INSGeneric,\n p1Values: { ONLY_RETRIEVE: 0x00, SHOW_ADDRESS_IN_DEVICE: 0x01 },\n chunkSize: 250,\n requiredPathLengths: [5],\n }\n\n /**\n * Constructs a new CosmosApp instance.\n * @param transport - The transport instance.\n * @throws {Error} - If the transport is not defined.\n */\n constructor(transport: LedgerTransport) {\n super(transport, CosmosApp._params)\n\n if (!this.transport) {\n throw new Error('Transport has not been defined')\n }\n }\n\n private serializeHRP(hrp: string) {\n if (!hrp || hrp.length < 3 || hrp.length > 83) {\n throw new Error('Invalid HRP')\n }\n\n const buf = new ByteStream()\n buf.appendUint8(hrp.length)\n buf.appendBytes(Buffer.from(hrp))\n\n return buf.getCompleteBuffer()\n }\n\n private serializeCosmosPath(path: string) {\n if (typeof path !== 'string') {\n throw new ResponseError(LedgerError.GenericError, \"Path should be a string (e.g \\\"m/44'/461'/5'/0/3\\\")\")\n }\n\n if (!path.startsWith('m/')) {\n throw new ResponseError(LedgerError.GenericError, 'Path should start with \"m/\" (e.g \"m/44\\'/461\\'/5\\'/0/3\")')\n }\n\n const pathArray = path.split('/').slice(1)\n\n if (this.REQUIRED_PATH_LENGTHS && this.REQUIRED_PATH_LENGTHS.length > 0 && !this.REQUIRED_PATH_LENGTHS.includes(pathArray.length)) {\n throw new ResponseError(LedgerError.GenericError, \"Invalid path length. (e.g \\\"m/44'/5757'/5'/0/3\\\")\")\n }\n\n const buf = new ByteStream()\n pathArray.forEach((child: string) => {\n let value = 0\n\n if (child.endsWith(\"'\")) {\n value += HARDENED\n child = child.slice(0, -1)\n }\n\n const numChild = Number(child)\n\n if (Number.isNaN(numChild)) {\n throw new ResponseError(LedgerError.GenericError, `Invalid path : ${child} is not a number. (e.g \"m/44'/461'/5'/0/3\")`)\n }\n value += numChild\n buf.appendUint32(value)\n })\n\n return buf.getCompleteBuffer()\n }\n\n async publicKey(path: string): Promise<ResponsePubkey> {\n const serializedPath = this.serializeCosmosPath(path)\n const data = Buffer.concat([this.serializeHRP('cosmos'), serializedPath])\n\n try {\n const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0, 0, data)\n const response = processResponse(responseBuffer)\n const compressed_pk = Buffer.from(response.readBytes(PKLEN))\n const bech32_address = response.readBytes(response.length()).toString()\n\n return { compressed_pk, bech32_address }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n\n async getAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress> {\n const serializedPath = this.serializeCosmosPath(path)\n const data = Buffer.concat([this.serializeHRP(hrp), serializedPath])\n\n try {\n const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, P1_VALUES.ONLY_RETRIEVE, 0, data)\n\n const response = processResponse(responseBuffer)\n const compressed_pk = response.readBytes(PKLEN)\n const bech32_address = response.readBytes(response.length()).toString()\n\n return { compressed_pk, bech32_address }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n\n async showAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress> {\n const serializedPath = this.serializeCosmosPath(path)\n const data = Buffer.concat([this.serializeHRP(hrp), serializedPath])\n\n try {\n const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, P1_VALUES.SHOW_ADDRESS_IN_DEVICE, 0, data)\n\n const response = processResponse(responseBuffer)\n const compressed_pk = response.readBytes(PKLEN)\n const bech32_address = response.readBytes(response.length()).toString()\n\n return { compressed_pk, bech32_address }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n\n static getBech32FromPK(hrp: string, pk: Buffer) {\n if (pk.length !== 33) {\n throw new Error('expected compressed public key [31 bytes]')\n }\n const hashSha256 = sha256(pk)\n const hashRip = ripemd160(hashSha256)\n return bech32.encode(hrp, bech32.toWords(hashRip))\n }\n\n async prepareChunks_hrp(path: string, buffer: Buffer, hrp?: string) {\n const serializedPath = this.serializeCosmosPath(path)\n const firstChunk = hrp ? Buffer.concat([serializedPath, this.serializeHRP(hrp)]) : serializedPath\n\n const chunks = [firstChunk]\n\n for (let i = 0; i < buffer.length; i += this.CHUNK_SIZE) {\n const end = Math.min(i + this.CHUNK_SIZE, buffer.length)\n chunks.push(buffer.subarray(i, end))\n }\n\n return chunks\n }\n\n async signSendCosmosChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, txtype = P2_VALUES.JSON): Promise<ResponsePayload> {\n const payloadType = chunkIdx === 1 ? PAYLOAD_TYPE.INIT : chunkIdx === chunkNum ? PAYLOAD_TYPE.LAST : PAYLOAD_TYPE.ADD\n\n const statusList = [LedgerError.NoErrors, LedgerError.DataIsInvalid, LedgerError.BadKeyHandle]\n\n const responseBuffer = await this.transport.send(this.CLA, this.INS.SIGN_SECP256K1, payloadType, txtype, chunk, statusList)\n return processResponse(responseBuffer)\n }\n\n private async signImpl(path: string, buffer: Buffer, txtype: number, hrp?: string): Promise<ResponseSign> {\n const chunks = await this.prepareChunks_hrp(path, buffer, hrp)\n\n try {\n let result = await this.signSendCosmosChunk(1, chunks.length, chunks[0], txtype)\n\n for (let i = 1; i < chunks.length; i++) {\n result = await this.signSendCosmosChunk(i + 1, chunks.length, chunks[i], txtype)\n }\n\n return { signature: result.readBytes(result.length()) }\n } catch (e) {\n throw processErrorResponse(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS)\n }\n }\n async sign(path: string, buffer: Buffer, hrp?: string, txtype = P2_VALUES.JSON): Promise<ResponseSign> {\n return this.signImpl(path, buffer, txtype, hrp)\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zondax/ledger-cosmos-js",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Node API for Cosmos App (Ledger Nano S/S+/X)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/
|
|
17
|
+
"url": "git+https://github.com/Zondax/ledger-cosmos-js.git"
|
|
18
18
|
},
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"author": "Zondax AG",
|
|
@@ -32,46 +32,44 @@
|
|
|
32
32
|
"format:check": "FORCE_COLOR=1 prettier --check .",
|
|
33
33
|
"lint": "eslint .",
|
|
34
34
|
"lint:fix": "eslint --fix .",
|
|
35
|
-
"test": "
|
|
36
|
-
"upgrade": "
|
|
35
|
+
"test": "pnpm build && jest .",
|
|
36
|
+
"upgrade": "pnpm dlx npm-check-updates -i"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@zondax/ledger-js": "^1.2.0",
|
|
39
|
+
"@noble/hashes": "^1.8.0",
|
|
40
|
+
"@scure/base": "^1.2.6",
|
|
41
|
+
"@zondax/ledger-js": "^2.0.0",
|
|
43
42
|
"buffer": "^6.0.3",
|
|
44
43
|
"ripemd160": "^2.0.2"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@ledgerhq/hw-transport-mocker": "^6.29.
|
|
48
|
-
"@ledgerhq/hw-transport-node-hid": "^6.29.
|
|
49
|
-
"@noble/curves": "^1.
|
|
46
|
+
"@ledgerhq/hw-transport-mocker": "^6.29.9",
|
|
47
|
+
"@ledgerhq/hw-transport-node-hid": "^6.29.10",
|
|
48
|
+
"@noble/curves": "^1.9.7",
|
|
50
49
|
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|
|
51
|
-
"@types/jest": "^
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
54
|
-
"@typescript-eslint/parser": "^8.
|
|
50
|
+
"@types/jest": "^30.0.0",
|
|
51
|
+
"@types/node": "^24.3.0",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^8.40.0",
|
|
53
|
+
"@typescript-eslint/parser": "^8.40.0",
|
|
55
54
|
"bip32": "5.0.0-rc.0",
|
|
56
55
|
"bip39": "3.1.0",
|
|
57
|
-
"eslint": "^9.
|
|
58
|
-
"eslint-config-prettier": "^10.1.
|
|
59
|
-
"eslint-plugin-import": "^2.
|
|
60
|
-
"eslint-plugin-jest": "^
|
|
56
|
+
"eslint": "^9.33.0",
|
|
57
|
+
"eslint-config-prettier": "^10.1.8",
|
|
58
|
+
"eslint-plugin-import": "^2.32.0",
|
|
59
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
61
60
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
62
|
-
"eslint-plugin-unused-imports": "^4.
|
|
63
|
-
"jest": "^
|
|
64
|
-
"jest-runner": "^
|
|
65
|
-
"jest-serial-runner": "^1.2.
|
|
66
|
-
"prettier": "^3.
|
|
67
|
-
"sort-package-json": "^3.
|
|
68
|
-
"ts-jest": "29.
|
|
61
|
+
"eslint-plugin-unused-imports": "^4.2.0",
|
|
62
|
+
"jest": "^30.0.5",
|
|
63
|
+
"jest-runner": "^30.0.5",
|
|
64
|
+
"jest-serial-runner": "^1.2.2",
|
|
65
|
+
"prettier": "^3.6.2",
|
|
66
|
+
"sort-package-json": "^3.4.0",
|
|
67
|
+
"ts-jest": "29.4.1",
|
|
69
68
|
"ts-node": "^10.9.2",
|
|
70
|
-
"typescript": "^5.
|
|
69
|
+
"typescript": "^5.9.2"
|
|
71
70
|
},
|
|
72
71
|
"volta": {
|
|
73
|
-
"node": "20.11.1"
|
|
74
|
-
"bun": "1.0.20"
|
|
72
|
+
"node": "20.11.1"
|
|
75
73
|
},
|
|
76
74
|
"publishConfig": {
|
|
77
75
|
"access": "public"
|