@zondax/ledger-cosmos-js 3.0.3 → 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.
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) 2018 - 2023 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) 2018 - 2023 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,CAAC;AAYX,QAAA,KAAK,GAAG,EAAE,CAAC","sourcesContent":["/** ******************************************************************************\n * (c) 2018 - 2023 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) 2018 - 2023 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 { ResponseSign, type ResponseAddress, type ResponsePubkey } from "./types";
17
+ import { P2_VALUES } from "./consts";
18
+ import type Transport from "@ledgerhq/hw-transport";
19
+ import BaseApp, { INSGeneric, ResponsePayload } from "@zondax/ledger-js";
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: 0;
31
+ SHOW_ADDRESS_IN_DEVICE: 1;
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): any;
48
+ prepareChunks_hrp(path: string, buffer: Buffer, hrp: string | undefined): Promise<Buffer[]>;
49
+ signSendCosmosChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, txtype?: P2_VALUES): Promise<ResponsePayload>;
50
+ private signImpl;
51
+ sign(path: string, buffer: Buffer, hrp: string | undefined, 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,191 @@ 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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
30
24
  };
31
- exports.__esModule = true;
32
- __exportStar(require("./cosmosApp"), exports);
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const consts_1 = require("./consts");
27
+ const ledger_js_1 = __importStar(require("@zondax/ledger-js"));
28
+ const byteStream_1 = require("@zondax/ledger-js/dist/byteStream");
29
+ const crypto = require("crypto");
30
+ const bech32 = require("bech32");
31
+ const Ripemd160 = require("ripemd160");
32
+ class CosmosApp extends ledger_js_1.default {
33
+ /**
34
+ * Constructs a new CosmosApp instance.
35
+ * @param transport - The transport instance.
36
+ * @throws {Error} - If the transport is not defined.
37
+ */
38
+ constructor(transport) {
39
+ super(transport, CosmosApp._params);
40
+ if (!this.transport) {
41
+ throw new Error("Transport has not been defined");
42
+ }
43
+ }
44
+ serializeHRP(hrp) {
45
+ if (hrp == null || hrp.length < 3 || hrp.length > 83) {
46
+ throw new Error("Invalid HRP");
47
+ }
48
+ const buf = new byteStream_1.ByteStream();
49
+ buf.appendUint8(hrp.length);
50
+ buf.appendBytes(Buffer.from(hrp));
51
+ return buf.getCompleteBuffer();
52
+ }
53
+ serializeCosmosPath(path) {
54
+ if (typeof path !== "string") {
55
+ // NOTE: this is probably unnecessary
56
+ throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, "Path should be a string (e.g \"m/44'/461'/5'/0/3\")");
57
+ }
58
+ if (!path.startsWith("m/")) {
59
+ throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, 'Path should start with "m/" (e.g "m/44\'/461\'/5\'/0/3")');
60
+ }
61
+ const pathArray = path.split("/");
62
+ pathArray.shift(); // remove "m"
63
+ if (this.REQUIRED_PATH_LENGTHS &&
64
+ this.REQUIRED_PATH_LENGTHS.length > 0 &&
65
+ !this.REQUIRED_PATH_LENGTHS.includes(pathArray.length)) {
66
+ throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, "Invalid path length. (e.g \"m/44'/5757'/5'/0/3\")");
67
+ }
68
+ const buf = new byteStream_1.ByteStream();
69
+ pathArray.forEach((child, i) => {
70
+ let value = 0;
71
+ if (child.endsWith("'")) {
72
+ value += ledger_js_1.HARDENED;
73
+ child = child.slice(0, -1);
74
+ }
75
+ const numChild = Number(child);
76
+ if (Number.isNaN(numChild)) {
77
+ 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")`);
78
+ }
79
+ value += numChild;
80
+ buf.appendUint32(value);
81
+ });
82
+ return buf.getCompleteBuffer();
83
+ }
84
+ async publicKey(path) {
85
+ const serializedPath = await this.serializeCosmosPath(path);
86
+ const data = Buffer.concat([this.serializeHRP("cosmos"), serializedPath]);
87
+ try {
88
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0, 0, data);
89
+ const response = (0, ledger_js_1.processResponse)(responseBuffer);
90
+ const compressed_pk = Buffer.from(response.readBytes(consts_1.PKLEN));
91
+ return {
92
+ compressed_pk,
93
+ };
94
+ }
95
+ catch (e) {
96
+ throw (0, ledger_js_1.processErrorResponse)(e);
97
+ }
98
+ }
99
+ async getAddressAndPubKey(path, hrp) {
100
+ const serializedPath = await this.serializeCosmosPath(path);
101
+ const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
102
+ try {
103
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0 /* P1_VALUES.ONLY_RETRIEVE */, 0, data);
104
+ const response = (0, ledger_js_1.processResponse)(responseBuffer);
105
+ const compressed_pk = response.readBytes(consts_1.PKLEN);
106
+ const bech32_address = response.readBytes(response.length()).toString();
107
+ return {
108
+ compressed_pk,
109
+ bech32_address,
110
+ };
111
+ }
112
+ catch (e) {
113
+ throw (0, ledger_js_1.processErrorResponse)(e);
114
+ }
115
+ }
116
+ async showAddressAndPubKey(path, hrp) {
117
+ const serializedPath = await this.serializeCosmosPath(path);
118
+ const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
119
+ try {
120
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 1 /* P1_VALUES.SHOW_ADDRESS_IN_DEVICE */, 0, data);
121
+ const response = (0, ledger_js_1.processResponse)(responseBuffer);
122
+ const compressed_pk = response.readBytes(consts_1.PKLEN);
123
+ const bech32_address = response.readBytes(response.length()).toString();
124
+ return {
125
+ compressed_pk,
126
+ bech32_address,
127
+ };
128
+ }
129
+ catch (e) {
130
+ throw (0, ledger_js_1.processErrorResponse)(e);
131
+ }
132
+ }
133
+ static getBech32FromPK(hrp, pk) {
134
+ if (pk.length !== 33) {
135
+ throw new Error("expected compressed public key [31 bytes]");
136
+ }
137
+ const hashSha256 = crypto.createHash("sha256").update(pk).digest();
138
+ const hashRip = new Ripemd160().update(hashSha256).digest();
139
+ return bech32.encode(hrp, bech32.toWords(hashRip));
140
+ }
141
+ async prepareChunks_hrp(path, buffer, hrp) {
142
+ const serializedPath = await this.serializeCosmosPath(path);
143
+ const firstChunk = hrp === undefined ? serializedPath : Buffer.concat([serializedPath, this.serializeHRP(hrp)]);
144
+ const chunks = [];
145
+ chunks.push(firstChunk);
146
+ for (let i = 0; i < buffer.length; i += this.CHUNK_SIZE) {
147
+ let end = i + this.CHUNK_SIZE;
148
+ if (i > buffer.length) {
149
+ end = buffer.length;
150
+ }
151
+ chunks.push(buffer.subarray(i, end));
152
+ }
153
+ return chunks;
154
+ }
155
+ async signSendCosmosChunk(chunkIdx, chunkNum, chunk, txtype = 0 /* P2_VALUES.JSON */) {
156
+ let payloadType = ledger_js_1.PAYLOAD_TYPE.ADD;
157
+ if (chunkIdx === 1) {
158
+ payloadType = ledger_js_1.PAYLOAD_TYPE.INIT;
159
+ }
160
+ if (chunkIdx === chunkNum) {
161
+ payloadType = ledger_js_1.PAYLOAD_TYPE.LAST;
162
+ }
163
+ const statusList = [ledger_js_1.LedgerError.NoErrors, ledger_js_1.LedgerError.DataIsInvalid, ledger_js_1.LedgerError.BadKeyHandle];
164
+ const responseBuffer = await this.transport.send(this.CLA, this.INS.SIGN_SECP256K1, payloadType, txtype, chunk, statusList);
165
+ const response = (0, ledger_js_1.processResponse)(responseBuffer);
166
+ return response;
167
+ }
168
+ async signImpl(path, buffer, hrp, txtype) {
169
+ const chunks = await this.prepareChunks_hrp(path, buffer, hrp);
170
+ try {
171
+ let result = await this.signSendCosmosChunk(1, chunks.length, chunks[0], txtype);
172
+ for (let i = 1; i < chunks.length; i += 1) {
173
+ result = await this.signSendCosmosChunk(1 + i, chunks.length, chunks[i], txtype);
174
+ }
175
+ return {
176
+ signature: result.readBytes(result.length()),
177
+ };
178
+ }
179
+ catch (e) {
180
+ throw (0, ledger_js_1.processErrorResponse)(e);
181
+ }
182
+ }
183
+ async sign(path, buffer, hrp, txtype = 0 /* P2_VALUES.JSON */) {
184
+ return await this.signImpl(path, buffer, hrp, txtype);
185
+ }
186
+ }
187
+ CosmosApp._INS = {
188
+ GET_VERSION: 0x00,
189
+ SIGN_SECP256K1: 0x02,
190
+ GET_ADDR_SECP256K1: 0x04,
191
+ };
192
+ CosmosApp._params = {
193
+ cla: consts_1.CLA,
194
+ ins: { ...CosmosApp._INS },
195
+ p1Values: { ONLY_RETRIEVE: 0x00, SHOW_ADDRESS_IN_DEVICE: 0x01 },
196
+ chunkSize: 250,
197
+ requiredPathLengths: [5],
198
+ };
199
+ exports.default = CosmosApp;
33
200
  //# 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,qCAA4D;AAE5D,+DAS2B;AAC3B,kEAA+D;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,MAAM,GAAG,OAAO,CAAC,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AAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CACR,IAAY,EACZ,MAAc,EACd,GAAuB,EACvB,MAAM,yBAAiB;QAEvB,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;;AAtPM,cAAI,GAAG;IACZ,WAAW,EAAE,IAAc;IAC3B,cAAc,EAAE,IAAc;IAC9B,kBAAkB,EAAE,IAAc;CACnC,CAAC;AAEK,iBAAO,GAAG;IACf,GAAG,EAAE,YAAG;IACR,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC,IAAI,EAAgB;IACxC,QAAQ,EAAE,EAAE,aAAa,EAAE,IAAS,EAAE,sBAAsB,EAAE,IAAS,EAAE;IACzE,SAAS,EAAE,GAAG;IACd,mBAAmB,EAAE,CAAC,CAAC,CAAC;CACzB,CAAC;kBAbiB,SAAS","sourcesContent":["/** ******************************************************************************\n * (c) 2018 - 2023 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 { ResponseSign, type ResponseAddress, type ResponsePubkey } from \"./types\";\nimport { CLA, P1_VALUES, P2_VALUES, PKLEN } from \"./consts\";\nimport type Transport from \"@ledgerhq/hw-transport\";\nimport BaseApp, {\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\nconst crypto = require(\"crypto\");\nconst bech32 = require(\"bech32\");\nconst Ripemd160 = require(\"ripemd160\");\n\nexport default class CosmosApp extends BaseApp {\n static _INS = {\n GET_VERSION: 0x00 as number,\n SIGN_SECP256K1: 0x02 as number,\n GET_ADDR_SECP256K1: 0x04 as number,\n };\n\n static _params = {\n cla: CLA,\n ins: { ...CosmosApp._INS } as INSGeneric,\n p1Values: { ONLY_RETRIEVE: 0x00 as 0, SHOW_ADDRESS_IN_DEVICE: 0x01 as 1 },\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 == null || 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 // NOTE: this is probably unnecessary\n throw new ResponseError(\n LedgerError.GenericError,\n \"Path should be a string (e.g \\\"m/44'/461'/5'/0/3\\\")\",\n );\n }\n\n if (!path.startsWith(\"m/\")) {\n throw new ResponseError(\n LedgerError.GenericError,\n 'Path should start with \"m/\" (e.g \"m/44\\'/461\\'/5\\'/0/3\")',\n );\n }\n\n const pathArray = path.split(\"/\");\n pathArray.shift(); // remove \"m\"\n\n if (\n this.REQUIRED_PATH_LENGTHS &&\n this.REQUIRED_PATH_LENGTHS.length > 0 &&\n !this.REQUIRED_PATH_LENGTHS.includes(pathArray.length)\n ) {\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, i: number) => {\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(\n LedgerError.GenericError,\n `Invalid path : ${child} is not a number. (e.g \"m/44'/461'/5'/0/3\")`,\n );\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 = await 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\n return {\n compressed_pk,\n } as ResponsePubkey;\n } catch (e) {\n throw processErrorResponse(e);\n }\n }\n\n async getAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress> {\n const serializedPath = await this.serializeCosmosPath(path);\n const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);\n\n try {\n const responseBuffer = await this.transport.send(\n this.CLA,\n this.INS.GET_ADDR_SECP256K1,\n P1_VALUES.ONLY_RETRIEVE,\n 0,\n data,\n );\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 {\n compressed_pk,\n bech32_address,\n } as ResponseAddress;\n } catch (e) {\n throw processErrorResponse(e);\n }\n }\n\n async showAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress> {\n const serializedPath = await this.serializeCosmosPath(path);\n const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);\n\n try {\n const responseBuffer = await this.transport.send(\n this.CLA,\n this.INS.GET_ADDR_SECP256K1,\n P1_VALUES.SHOW_ADDRESS_IN_DEVICE,\n 0,\n data,\n );\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 {\n compressed_pk,\n bech32_address,\n } as ResponseAddress;\n } catch (e) {\n throw processErrorResponse(e);\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 = crypto.createHash(\"sha256\").update(pk).digest();\n const hashRip = new Ripemd160().update(hashSha256).digest();\n return bech32.encode(hrp, bech32.toWords(hashRip));\n }\n\n async prepareChunks_hrp(path: string, buffer: Buffer, hrp: string | undefined) {\n const serializedPath = await this.serializeCosmosPath(path);\n const firstChunk =\n hrp === undefined ? serializedPath : Buffer.concat([serializedPath, this.serializeHRP(hrp)]);\n\n const chunks = [];\n chunks.push(firstChunk);\n\n for (let i = 0; i < buffer.length; i += this.CHUNK_SIZE) {\n let end = i + this.CHUNK_SIZE;\n if (i > buffer.length) {\n end = buffer.length;\n }\n chunks.push(buffer.subarray(i, end));\n }\n\n return chunks;\n }\n\n async signSendCosmosChunk(\n chunkIdx: number,\n chunkNum: number,\n chunk: Buffer,\n txtype = P2_VALUES.JSON,\n ): Promise<ResponsePayload> {\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 const statusList = [LedgerError.NoErrors, LedgerError.DataIsInvalid, LedgerError.BadKeyHandle];\n\n const responseBuffer = await this.transport.send(\n this.CLA,\n this.INS.SIGN_SECP256K1,\n payloadType,\n txtype,\n chunk,\n statusList,\n );\n const response = processResponse(responseBuffer);\n\n return response;\n }\n\n private async signImpl(\n path: string,\n buffer: Buffer,\n hrp: string | undefined,\n txtype: number,\n ): 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 += 1) {\n result = await this.signSendCosmosChunk(1 + i, chunks.length, chunks[i], txtype);\n }\n\n return {\n signature: result.readBytes(result.length()),\n };\n } catch (e) {\n throw processErrorResponse(e);\n }\n }\n\n async sign(\n path: string,\n buffer: Buffer,\n hrp: string | undefined,\n txtype = P2_VALUES.JSON,\n ): Promise<ResponseSign> {\n return await this.signImpl(path, buffer, hrp, txtype);\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
@@ -2,7 +2,7 @@
2
2
  "name": "@zondax/ledger-cosmos-js",
3
3
  "author": "Zondax AG",
4
4
  "license": "Apache-2.0",
5
- "version": "3.0.3",
5
+ "version": "4.0.0",
6
6
  "description": "Node API for Cosmos App (Ledger Nano S/S+/X)",
7
7
  "main": "./dist/index.js",
8
8
  "typings": "./dist/index.d.ts",
@@ -28,54 +28,45 @@
28
28
  "@ledgerhq/hw-transport-node-hid-noevents": "6.27.1"
29
29
  },
30
30
  "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",
31
+ "@ledgerhq/hw-transport": "6.30.6",
32
+ "@zondax/ledger-js": "^0.10.0",
33
+ "bech32": "^2.0.0",
37
34
  "buffer": "^6.0.3",
38
35
  "crypto": "^1.0.1",
39
36
  "crypto-browserify": "^3.12.0",
40
37
  "ripemd160": "^2.0.2",
41
- "stream-browserify": "^3.0.0",
42
- "vue": "^2.7.7",
43
- "vue-template-compiler": "^2.7.10"
38
+ "stream-browserify": "^3.0.0"
44
39
  },
45
40
  "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",
41
+ "@ledgerhq/hw-transport-node-hid": "6.28.6",
42
+ "@ledgerhq/hw-transport-webusb": "6.28.6",
43
+ "@ledgerhq/hw-transport-mocker": "^6.28.6",
44
+ "@swc/core": "^1.6.1",
45
+ "@types/jest": "^29.5.12",
46
+ "@types/ledgerhq__hw-transport": "4.21.8",
47
+ "@types/node": "^20.14.2",
48
+ "@typescript-eslint/eslint-plugin": "^7.13.0",
49
+ "@typescript-eslint/parser": "^7.13.0",
50
+ "bip32": "4.0.0",
51
+ "bip39": "3.1.0",
63
52
  "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",
53
+ "core-js": "^3.37.1",
54
+ "crypto-js": "4.2.0",
55
+ "eslint": "^9.5.0",
56
+ "eslint-config-prettier": "^9.1.0",
57
+ "eslint-plugin-import": "^2.29.1",
58
+ "eslint-plugin-jest": "^28.6.0",
59
+ "eslint-plugin-prettier": "^5.1.3",
60
+ "eslint-plugin-unused-imports": "^3.2.0",
61
+ "eslint-plugin-tsdoc": "^0.2.17",
62
+ "jest": "^29.7.0",
72
63
  "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"
64
+ "prettier": "^3.3.2",
65
+ "secp256k1": "^5.0.0",
66
+ "ts-jest": "29.1.5",
67
+ "ts-node": "^10.9.2",
68
+ "typescript": "^5.4.5",
69
+ "webpack": "^5.92.0"
79
70
  },
80
71
  "moduleDirectories": [
81
72
  "node_modules",
@@ -98,12 +89,10 @@
98
89
  "@types/node": "^17.0.21"
99
90
  },
100
91
  "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}\""
92
+ "build": "tsc",
93
+ "lint": "eslint .",
94
+ "lint:fix": "eslint --fix .",
95
+ "format": "prettier --write .",
96
+ "test": "yarn build && jest"
108
97
  }
109
98
  }
@@ -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>;
@@ -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