@zondax/ledger-cosmos-js 3.0.3 → 4.0.1

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 CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2018 - 2023 Zondax AG
189
+ Copyright Zondax AG
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # @zondax/ledger-cosmos-js
2
2
 
3
- ![zondax_light](docs/zondax_light.png#gh-light-mode-only)
4
- ![zondax_dark](docs/zondax_dark.png#gh-dark-mode-only)
3
+ ![zondax](docs/zondax_light.png)
5
4
 
6
5
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
6
  [![Main](https://github.com/cosmos/ledger-cosmos-js/workflows/Main/badge.svg)](https://github.com/cosmos/ledger-cosmos-js/actions?query=workflow%3AMain)
@@ -0,0 +1,25 @@
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
+ export declare const CLA = 85;
17
+ export declare const enum P1_VALUES {
18
+ ONLY_RETRIEVE = 0,
19
+ SHOW_ADDRESS_IN_DEVICE = 1
20
+ }
21
+ export declare const enum P2_VALUES {
22
+ JSON = 0,
23
+ TEXTUAL = 1
24
+ }
25
+ export declare const PKLEN = 33;
package/dist/consts.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PKLEN = exports.CLA = void 0;
4
+ /** ******************************************************************************
5
+ * (c) Zondax AG
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ ******************************************************************************* */
19
+ exports.CLA = 0x55;
20
+ exports.PKLEN = 33;
21
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;mFAcmF;AACtE,QAAA,GAAG,GAAG,IAAI,CAAA;AAYV,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,5 +1,5 @@
1
1
  /** ******************************************************************************
2
- * (c) 2018 - 2022 Zondax AG
2
+ * (c) Zondax AG
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,4 +13,40 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  ******************************************************************************* */
16
- export * from './cosmosApp';
16
+ import type Transport from '@ledgerhq/hw-transport';
17
+ import BaseApp, { INSGeneric, ResponsePayload } from '@zondax/ledger-js';
18
+ import { P2_VALUES } from './consts';
19
+ import { type ResponseAddress, type ResponsePubkey, ResponseSign } from './types';
20
+ export default class CosmosApp extends BaseApp {
21
+ static _INS: {
22
+ GET_VERSION: number;
23
+ SIGN_SECP256K1: number;
24
+ GET_ADDR_SECP256K1: number;
25
+ };
26
+ static _params: {
27
+ cla: number;
28
+ ins: INSGeneric;
29
+ p1Values: {
30
+ ONLY_RETRIEVE: number;
31
+ SHOW_ADDRESS_IN_DEVICE: number;
32
+ };
33
+ chunkSize: number;
34
+ requiredPathLengths: number[];
35
+ };
36
+ /**
37
+ * Constructs a new CosmosApp instance.
38
+ * @param transport - The transport instance.
39
+ * @throws {Error} - If the transport is not defined.
40
+ */
41
+ constructor(transport: Transport);
42
+ private serializeHRP;
43
+ private serializeCosmosPath;
44
+ publicKey(path: string): Promise<ResponsePubkey>;
45
+ getAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress>;
46
+ showAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress>;
47
+ static getBech32FromPK(hrp: string, pk: Buffer): `${Lowercase<string>}1${string}`;
48
+ prepareChunks_hrp(path: string, buffer: Buffer, hrp?: string): Promise<Buffer<ArrayBufferLike>[]>;
49
+ signSendCosmosChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, txtype?: P2_VALUES): Promise<ResponsePayload>;
50
+ private signImpl;
51
+ sign(path: string, buffer: Buffer, hrp?: string, txtype?: P2_VALUES): Promise<ResponseSign>;
52
+ }
package/dist/index.js CHANGED
@@ -1,19 +1,4 @@
1
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
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
3
  if (k2 === undefined) k2 = k;
19
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -25,9 +10,193 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
25
10
  if (k2 === undefined) k2 = k;
26
11
  o[k2] = m[k];
27
12
  }));
28
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const ripemd160_1 = require("@noble/hashes/ripemd160");
37
+ const sha256_1 = require("@noble/hashes/sha256");
38
+ const base_1 = require("@scure/base");
39
+ const ledger_js_1 = __importStar(require("@zondax/ledger-js"));
40
+ const byteStream_1 = require("@zondax/ledger-js/dist/byteStream");
41
+ const consts_1 = require("./consts");
42
+ var CosmosCostumError;
43
+ (function (CosmosCostumError) {
44
+ CosmosCostumError[CosmosCostumError["ErrorTransactionDataExceedsBufferCapacity"] = 27016] = "ErrorTransactionDataExceedsBufferCapacity";
45
+ CosmosCostumError[CosmosCostumError["ErrorInvalidHDPathValue"] = 27017] = "ErrorInvalidHDPathValue";
46
+ CosmosCostumError[CosmosCostumError["ErrorHrpWrongLength"] = 27018] = "ErrorHrpWrongLength";
47
+ CosmosCostumError[CosmosCostumError["ErrorInvalidHDPathCoinValue"] = 27019] = "ErrorInvalidHDPathCoinValue";
48
+ CosmosCostumError[CosmosCostumError["ErrorChainConfigNotSupported"] = 27020] = "ErrorChainConfigNotSupported";
49
+ })(CosmosCostumError || (CosmosCostumError = {}));
50
+ const COSMOS_CUSTOM_ERROR_DESCRIPTIONS = {
51
+ ...ledger_js_1.ERROR_DESCRIPTION_OVERRIDE,
52
+ [CosmosCostumError.ErrorTransactionDataExceedsBufferCapacity]: "Transaction data exceeds the device's internal buffer capacity",
53
+ [CosmosCostumError.ErrorInvalidHDPathValue]: 'Invalid HD Path Value. Expert Mode required.',
54
+ [CosmosCostumError.ErrorHrpWrongLength]: 'Invalid HRP length',
55
+ [CosmosCostumError.ErrorInvalidHDPathCoinValue]: 'Invalid HD Path Coin Value',
56
+ [CosmosCostumError.ErrorChainConfigNotSupported]: 'Chain config not supported',
30
57
  };
31
- exports.__esModule = true;
32
- __exportStar(require("./cosmosApp"), exports);
58
+ class CosmosApp extends ledger_js_1.default {
59
+ /**
60
+ * Constructs a new CosmosApp instance.
61
+ * @param transport - The transport instance.
62
+ * @throws {Error} - If the transport is not defined.
63
+ */
64
+ constructor(transport) {
65
+ super(transport, CosmosApp._params);
66
+ if (!this.transport) {
67
+ throw new Error('Transport has not been defined');
68
+ }
69
+ }
70
+ serializeHRP(hrp) {
71
+ if (!hrp || hrp.length < 3 || hrp.length > 83) {
72
+ throw new Error('Invalid HRP');
73
+ }
74
+ const buf = new byteStream_1.ByteStream();
75
+ buf.appendUint8(hrp.length);
76
+ buf.appendBytes(Buffer.from(hrp));
77
+ return buf.getCompleteBuffer();
78
+ }
79
+ serializeCosmosPath(path) {
80
+ if (typeof path !== 'string') {
81
+ throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, "Path should be a string (e.g \"m/44'/461'/5'/0/3\")");
82
+ }
83
+ if (!path.startsWith('m/')) {
84
+ throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, 'Path should start with "m/" (e.g "m/44\'/461\'/5\'/0/3")');
85
+ }
86
+ const pathArray = path.split('/').slice(1);
87
+ if (this.REQUIRED_PATH_LENGTHS && this.REQUIRED_PATH_LENGTHS.length > 0 && !this.REQUIRED_PATH_LENGTHS.includes(pathArray.length)) {
88
+ throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, "Invalid path length. (e.g \"m/44'/5757'/5'/0/3\")");
89
+ }
90
+ const buf = new byteStream_1.ByteStream();
91
+ pathArray.forEach((child) => {
92
+ let value = 0;
93
+ if (child.endsWith("'")) {
94
+ value += ledger_js_1.HARDENED;
95
+ child = child.slice(0, -1);
96
+ }
97
+ const numChild = Number(child);
98
+ if (Number.isNaN(numChild)) {
99
+ throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, `Invalid path : ${child} is not a number. (e.g "m/44'/461'/5'/0/3")`);
100
+ }
101
+ value += numChild;
102
+ buf.appendUint32(value);
103
+ });
104
+ return buf.getCompleteBuffer();
105
+ }
106
+ async publicKey(path) {
107
+ const serializedPath = this.serializeCosmosPath(path);
108
+ const data = Buffer.concat([this.serializeHRP('cosmos'), serializedPath]);
109
+ try {
110
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0, 0, data);
111
+ const response = (0, ledger_js_1.processResponse)(responseBuffer);
112
+ const compressed_pk = Buffer.from(response.readBytes(consts_1.PKLEN));
113
+ const bech32_address = response.readBytes(response.length()).toString();
114
+ return { compressed_pk, bech32_address };
115
+ }
116
+ catch (e) {
117
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
118
+ }
119
+ }
120
+ async getAddressAndPubKey(path, hrp) {
121
+ const serializedPath = this.serializeCosmosPath(path);
122
+ const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
123
+ try {
124
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0 /* P1_VALUES.ONLY_RETRIEVE */, 0, data);
125
+ const response = (0, ledger_js_1.processResponse)(responseBuffer);
126
+ const compressed_pk = response.readBytes(consts_1.PKLEN);
127
+ const bech32_address = response.readBytes(response.length()).toString();
128
+ return { compressed_pk, bech32_address };
129
+ }
130
+ catch (e) {
131
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
132
+ }
133
+ }
134
+ async showAddressAndPubKey(path, hrp) {
135
+ const serializedPath = this.serializeCosmosPath(path);
136
+ const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
137
+ try {
138
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 1 /* P1_VALUES.SHOW_ADDRESS_IN_DEVICE */, 0, data);
139
+ const response = (0, ledger_js_1.processResponse)(responseBuffer);
140
+ const compressed_pk = response.readBytes(consts_1.PKLEN);
141
+ const bech32_address = response.readBytes(response.length()).toString();
142
+ return { compressed_pk, bech32_address };
143
+ }
144
+ catch (e) {
145
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
146
+ }
147
+ }
148
+ static getBech32FromPK(hrp, pk) {
149
+ if (pk.length !== 33) {
150
+ throw new Error('expected compressed public key [31 bytes]');
151
+ }
152
+ const hashSha256 = (0, sha256_1.sha256)(pk);
153
+ const hashRip = (0, ripemd160_1.ripemd160)(hashSha256);
154
+ return base_1.bech32.encode(hrp, base_1.bech32.toWords(hashRip));
155
+ }
156
+ async prepareChunks_hrp(path, buffer, hrp) {
157
+ const serializedPath = this.serializeCosmosPath(path);
158
+ const firstChunk = hrp ? Buffer.concat([serializedPath, this.serializeHRP(hrp)]) : serializedPath;
159
+ const chunks = [firstChunk];
160
+ for (let i = 0; i < buffer.length; i += this.CHUNK_SIZE) {
161
+ const end = Math.min(i + this.CHUNK_SIZE, buffer.length);
162
+ chunks.push(buffer.subarray(i, end));
163
+ }
164
+ return chunks;
165
+ }
166
+ async signSendCosmosChunk(chunkIdx, chunkNum, chunk, txtype = 0 /* P2_VALUES.JSON */) {
167
+ 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
+ const statusList = [ledger_js_1.LedgerError.NoErrors, ledger_js_1.LedgerError.DataIsInvalid, ledger_js_1.LedgerError.BadKeyHandle];
169
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.SIGN_SECP256K1, payloadType, txtype, chunk, statusList);
170
+ return (0, ledger_js_1.processResponse)(responseBuffer);
171
+ }
172
+ async signImpl(path, buffer, txtype, hrp) {
173
+ const chunks = await this.prepareChunks_hrp(path, buffer, hrp);
174
+ try {
175
+ let result = await this.signSendCosmosChunk(1, chunks.length, chunks[0], txtype);
176
+ for (let i = 1; i < chunks.length; i++) {
177
+ result = await this.signSendCosmosChunk(i + 1, chunks.length, chunks[i], txtype);
178
+ }
179
+ return { signature: result.readBytes(result.length()) };
180
+ }
181
+ catch (e) {
182
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
183
+ }
184
+ }
185
+ async sign(path, buffer, hrp, txtype = 0 /* P2_VALUES.JSON */) {
186
+ return this.signImpl(path, buffer, txtype, hrp);
187
+ }
188
+ }
189
+ CosmosApp._INS = {
190
+ GET_VERSION: 0x00,
191
+ SIGN_SECP256K1: 0x02,
192
+ GET_ADDR_SECP256K1: 0x04,
193
+ };
194
+ CosmosApp._params = {
195
+ cla: consts_1.CLA,
196
+ ins: { ...CosmosApp._INS },
197
+ p1Values: { ONLY_RETRIEVE: 0x00, SHOW_ADDRESS_IN_DEVICE: 0x01 },
198
+ chunkSize: 250,
199
+ requiredPathLengths: [5],
200
+ };
201
+ exports.default = CosmosApp;
33
202
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;mFAcmF;;;;;;;;;;;;;;;;AAEnF,8CAA2B","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 * from './cosmosApp'\n"]}
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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M,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,yBAAiB;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 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"]}
@@ -0,0 +1,11 @@
1
+ export interface ResponseAddress {
2
+ bech32_address: string;
3
+ compressed_pk: Buffer;
4
+ }
5
+ export interface ResponsePubkey {
6
+ bech32_address: string;
7
+ compressed_pk: Buffer;
8
+ }
9
+ export interface ResponseSign {
10
+ signature: Buffer;
11
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface ResponseAddress {\n bech32_address: string\n compressed_pk: Buffer\n}\n\nexport interface ResponsePubkey {\n bech32_address: string\n compressed_pk: Buffer\n}\n\nexport interface ResponseSign {\n signature: Buffer\n}\n"]}
package/package.json CHANGED
@@ -1,109 +1,83 @@
1
1
  {
2
2
  "name": "@zondax/ledger-cosmos-js",
3
- "author": "Zondax AG",
4
- "license": "Apache-2.0",
5
- "version": "3.0.3",
3
+ "version": "4.0.1",
6
4
  "description": "Node API for Cosmos App (Ledger Nano S/S+/X)",
7
- "main": "./dist/index.js",
8
- "typings": "./dist/index.d.ts",
9
- "types": "./dist/index.d.ts",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/cosmos/ledger-cosmos-js.git"
13
- },
14
5
  "keywords": [
15
6
  "Ledger",
16
7
  "Typescript",
17
8
  "Tendermint",
18
9
  "Cosmos"
19
10
  ],
11
+ "homepage": "https://github.com/Zondax/ledger-cosmos-js",
20
12
  "bugs": {
21
- "url": "https://github.com/cosmos/ledger-cosmos-js/issues"
13
+ "url": "https://github.com/Zondax/ledger-cosmos-js/issues"
22
14
  },
23
- "homepage": "https://github.com/cosmos/ledger-cosmos-js",
24
- "resolutions": {
25
- "@ledgerhq/hw-transport": "6.27.1",
26
- "@ledgerhq/devices": "6.27.1",
27
- "@ledgerhq/hw-transport-node-hid": "6.27.1",
28
- "@ledgerhq/hw-transport-node-hid-noevents": "6.27.1"
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/cosmos/ledger-cosmos-js.git"
18
+ },
19
+ "license": "Apache-2.0",
20
+ "author": "Zondax AG",
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "typings": "./dist/index.d.ts",
24
+ "files": [
25
+ "dist/**",
26
+ "LICENSE",
27
+ "package.json"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "format": "FORCE_COLOR=1 prettier --write . && sort-package-json",
32
+ "format:check": "FORCE_COLOR=1 prettier --check .",
33
+ "lint": "eslint .",
34
+ "lint:fix": "eslint --fix .",
35
+ "test": "yarn build && jest .",
36
+ "upgrade": "bunx npm-check-updates -i"
29
37
  },
30
38
  "dependencies": {
31
- "@babel/runtime": "^7.14.8",
32
- "@ledgerhq/hw-transport": "6.27.1",
33
- "@ledgerhq/hw-transport-u2f": "^5.36.0-deprecated",
34
- "@vue/cli-plugin-typescript": "^5.0.8",
35
- "@vue/cli-service": "^5.0.8",
36
- "bech32": "^1.1.4",
39
+ "@ledgerhq/hw-transport": "6.31.4",
40
+ "@noble/hashes": "^1.7.1",
41
+ "@scure/base": "^1.2.4",
42
+ "@zondax/ledger-js": "^1.2.0",
37
43
  "buffer": "^6.0.3",
38
- "crypto": "^1.0.1",
39
- "crypto-browserify": "^3.12.0",
40
- "ripemd160": "^2.0.2",
41
- "stream-browserify": "^3.0.0",
42
- "vue": "^2.7.7",
43
- "vue-template-compiler": "^2.7.10"
44
+ "ripemd160": "^2.0.2"
44
45
  },
45
46
  "devDependencies": {
46
- "@babel/cli": "^7.18.10",
47
- "@babel/core": "^7.18.10",
48
- "@babel/node": "^7.18.10",
49
- "@babel/plugin-transform-runtime": "^7.18.9",
50
- "@babel/preset-env": "^7.18.9",
51
- "@ledgerhq/hw-transport-node-hid": "6.27.1",
52
- "@ledgerhq/hw-transport-webusb": "6.27.1",
53
- "@swc/core": "^1.2.237",
54
- "@types/jest": "^26.0.24",
55
- "@types/ledgerhq__hw-transport": "4.21.4",
56
- "@types/node": "^18.11.9",
57
- "@typescript-eslint/eslint-plugin": "^5.33.1",
58
- "@typescript-eslint/parser": "^5.33.1",
59
- "babel-eslint": "^10.1.0",
60
- "babel-jest": "^28.1.3",
61
- "bip32": "2.0.6",
62
- "bip39": "3.0.2",
63
- "copyfiles": "^2.4.1",
64
- "core-js": "^3.15.2",
65
- "crypto-js": "4.1.1",
66
- "eslint": "^8.22.0",
67
- "eslint-config-prettier": "^8.5.0",
68
- "eslint-plugin-import": "^2.26.0",
69
- "eslint-plugin-jest": "^26.8.3",
70
- "eslint-plugin-prettier": "^3.4.0",
71
- "jest": "^26",
72
- "jest-serial-runner": "^1.2.0",
73
- "prettier": "^2.3.2",
74
- "secp256k1": "^4.0.2",
75
- "ts-jest": "26",
76
- "ts-node": "^10.8.1",
77
- "typescript": "^4.7.4",
78
- "webpack": "^5.74.0"
47
+ "@ledgerhq/hw-transport-mocker": "^6.29.4",
48
+ "@ledgerhq/hw-transport-node-hid": "^6.29.5",
49
+ "@noble/curves": "^1.8.1",
50
+ "@trivago/prettier-plugin-sort-imports": "^5.2.2",
51
+ "@types/jest": "^29.5.14",
52
+ "@types/node": "^22.14.0",
53
+ "@typescript-eslint/eslint-plugin": "^8.29.1",
54
+ "@typescript-eslint/parser": "^8.29.1",
55
+ "bip32": "5.0.0-rc.0",
56
+ "bip39": "3.1.0",
57
+ "eslint": "^9.24.0",
58
+ "eslint-config-prettier": "^10.1.2",
59
+ "eslint-plugin-import": "^2.31.0",
60
+ "eslint-plugin-jest": "^28.11.0",
61
+ "eslint-plugin-tsdoc": "^0.4.0",
62
+ "eslint-plugin-unused-imports": "^4.1.4",
63
+ "jest": "^29.7.0",
64
+ "jest-runner": "^29.7.0",
65
+ "jest-serial-runner": "^1.2.1",
66
+ "prettier": "^3.5.3",
67
+ "sort-package-json": "^3.0.0",
68
+ "ts-jest": "29.3.1",
69
+ "ts-node": "^10.9.2",
70
+ "typescript": "^5.8.3"
71
+ },
72
+ "volta": {
73
+ "node": "20.11.1",
74
+ "bun": "1.0.20"
79
75
  },
80
- "moduleDirectories": [
81
- "node_modules",
82
- "dist"
83
- ],
84
- "browserslist": [
85
- "> 1%",
86
- "last 2 versions"
87
- ],
88
- "files": [
89
- "dist/*",
90
- "LICENSE",
91
- "yarn.lock"
92
- ],
93
76
  "publishConfig": {
94
77
  "access": "public"
95
78
  },
96
- "peerDependencies": {
97
- "@babel/core": "^7.17.5",
98
- "@types/node": "^17.0.21"
99
- },
100
- "scripts": {
101
- "build": "tsc && yarn copy-files",
102
- "copy-files": "copyfiles -u 0 src/**/*.proto dist/",
103
- "test:integration": "yarn build && jest -t 'Integration'",
104
- "test:unit": "yarn build && jest tests/basic_unit.test.ts",
105
- "serve": "openssl req -nodes -new -x509 -config certs/openssl.cnf -keyout certs/server.key -out certs/server.cert; openssl x509 -in certs/server.cert -out certs/cert.pem -outform PEM; vue-cli-service serve vue_example/main.js",
106
- "linter": "eslint --ext .ts,.tsx,.js,.jsx --ignore-path .eslintignore . --max-warnings 0",
107
- "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\""
108
- }
79
+ "moduleDirectories": [
80
+ "node_modules",
81
+ "dist"
82
+ ]
109
83
  }
@@ -1,4 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function serializePathv1(path: number[]): Buffer;
3
- export declare function signSendChunkv1(app: any, chunkIdx: number, chunkNum: number, chunk: Buffer, txType?: number): Promise<any>;
4
- export declare function publicKeyv1(app: any, data: Buffer): Promise<any>;