@zondax/ledger-cosmos-js 4.0.0 → 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/dist/consts.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** ******************************************************************************
2
- * (c) 2018 - 2023 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.
package/dist/consts.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PKLEN = exports.CLA = void 0;
4
4
  /** ******************************************************************************
5
- * (c) 2018 - 2023 Zondax AG
5
+ * (c) Zondax AG
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -1 +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"]}
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 - 2023 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,10 +13,10 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  ******************************************************************************* */
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";
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
20
  export default class CosmosApp extends BaseApp {
21
21
  static _INS: {
22
22
  GET_VERSION: number;
@@ -27,8 +27,8 @@ export default class CosmosApp extends BaseApp {
27
27
  cla: number;
28
28
  ins: INSGeneric;
29
29
  p1Values: {
30
- ONLY_RETRIEVE: 0;
31
- SHOW_ADDRESS_IN_DEVICE: 1;
30
+ ONLY_RETRIEVE: number;
31
+ SHOW_ADDRESS_IN_DEVICE: number;
32
32
  };
33
33
  chunkSize: number;
34
34
  requiredPathLengths: number[];
@@ -44,9 +44,9 @@ export default class CosmosApp extends BaseApp {
44
44
  publicKey(path: string): Promise<ResponsePubkey>;
45
45
  getAddressAndPubKey(path: string, hrp: string): Promise<ResponseAddress>;
46
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[]>;
47
+ static getBech32FromPK(hrp: string, pk: Buffer): `${Lowercase<string>}1${string}`;
48
+ prepareChunks_hrp(path: string, buffer: Buffer, hrp?: string): Promise<Buffer<ArrayBufferLike>[]>;
49
49
  signSendCosmosChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, txtype?: P2_VALUES): Promise<ResponsePayload>;
50
50
  private signImpl;
51
- sign(path: string, buffer: Buffer, hrp: string | undefined, txtype?: P2_VALUES): Promise<ResponseSign>;
51
+ sign(path: string, buffer: Buffer, hrp?: string, txtype?: P2_VALUES): Promise<ResponseSign>;
52
52
  }
package/dist/index.js CHANGED
@@ -15,20 +15,46 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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;
24
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const consts_1 = require("./consts");
36
+ const ripemd160_1 = require("@noble/hashes/ripemd160");
37
+ const sha256_1 = require("@noble/hashes/sha256");
38
+ const base_1 = require("@scure/base");
27
39
  const ledger_js_1 = __importStar(require("@zondax/ledger-js"));
28
40
  const byteStream_1 = require("@zondax/ledger-js/dist/byteStream");
29
- const crypto = require("crypto");
30
- const bech32 = require("bech32");
31
- const Ripemd160 = require("ripemd160");
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',
57
+ };
32
58
  class CosmosApp extends ledger_js_1.default {
33
59
  /**
34
60
  * Constructs a new CosmosApp instance.
@@ -38,12 +64,12 @@ class CosmosApp extends ledger_js_1.default {
38
64
  constructor(transport) {
39
65
  super(transport, CosmosApp._params);
40
66
  if (!this.transport) {
41
- throw new Error("Transport has not been defined");
67
+ throw new Error('Transport has not been defined');
42
68
  }
43
69
  }
44
70
  serializeHRP(hrp) {
45
- if (hrp == null || hrp.length < 3 || hrp.length > 83) {
46
- throw new Error("Invalid HRP");
71
+ if (!hrp || hrp.length < 3 || hrp.length > 83) {
72
+ throw new Error('Invalid HRP');
47
73
  }
48
74
  const buf = new byteStream_1.ByteStream();
49
75
  buf.appendUint8(hrp.length);
@@ -51,22 +77,18 @@ class CosmosApp extends ledger_js_1.default {
51
77
  return buf.getCompleteBuffer();
52
78
  }
53
79
  serializeCosmosPath(path) {
54
- if (typeof path !== "string") {
55
- // NOTE: this is probably unnecessary
80
+ if (typeof path !== 'string') {
56
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\")");
57
82
  }
58
- if (!path.startsWith("m/")) {
83
+ if (!path.startsWith('m/')) {
59
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")');
60
85
  }
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)) {
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)) {
66
88
  throw new ledger_js_1.ResponseError(ledger_js_1.LedgerError.GenericError, "Invalid path length. (e.g \"m/44'/5757'/5'/0/3\")");
67
89
  }
68
90
  const buf = new byteStream_1.ByteStream();
69
- pathArray.forEach((child, i) => {
91
+ pathArray.forEach((child) => {
70
92
  let value = 0;
71
93
  if (child.endsWith("'")) {
72
94
  value += ledger_js_1.HARDENED;
@@ -82,106 +104,86 @@ class CosmosApp extends ledger_js_1.default {
82
104
  return buf.getCompleteBuffer();
83
105
  }
84
106
  async publicKey(path) {
85
- const serializedPath = await this.serializeCosmosPath(path);
86
- const data = Buffer.concat([this.serializeHRP("cosmos"), serializedPath]);
107
+ const serializedPath = this.serializeCosmosPath(path);
108
+ const data = Buffer.concat([this.serializeHRP('cosmos'), serializedPath]);
87
109
  try {
88
110
  const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0, 0, data);
89
111
  const response = (0, ledger_js_1.processResponse)(responseBuffer);
90
112
  const compressed_pk = Buffer.from(response.readBytes(consts_1.PKLEN));
91
- return {
92
- compressed_pk,
93
- };
113
+ const bech32_address = response.readBytes(response.length()).toString();
114
+ return { compressed_pk, bech32_address };
94
115
  }
95
116
  catch (e) {
96
- throw (0, ledger_js_1.processErrorResponse)(e);
117
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
97
118
  }
98
119
  }
99
120
  async getAddressAndPubKey(path, hrp) {
100
- const serializedPath = await this.serializeCosmosPath(path);
121
+ const serializedPath = this.serializeCosmosPath(path);
101
122
  const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
102
123
  try {
103
124
  const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 0 /* P1_VALUES.ONLY_RETRIEVE */, 0, data);
104
125
  const response = (0, ledger_js_1.processResponse)(responseBuffer);
105
126
  const compressed_pk = response.readBytes(consts_1.PKLEN);
106
127
  const bech32_address = response.readBytes(response.length()).toString();
107
- return {
108
- compressed_pk,
109
- bech32_address,
110
- };
128
+ return { compressed_pk, bech32_address };
111
129
  }
112
130
  catch (e) {
113
- throw (0, ledger_js_1.processErrorResponse)(e);
131
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
114
132
  }
115
133
  }
116
134
  async showAddressAndPubKey(path, hrp) {
117
- const serializedPath = await this.serializeCosmosPath(path);
135
+ const serializedPath = this.serializeCosmosPath(path);
118
136
  const data = Buffer.concat([this.serializeHRP(hrp), serializedPath]);
119
137
  try {
120
138
  const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_ADDR_SECP256K1, 1 /* P1_VALUES.SHOW_ADDRESS_IN_DEVICE */, 0, data);
121
139
  const response = (0, ledger_js_1.processResponse)(responseBuffer);
122
140
  const compressed_pk = response.readBytes(consts_1.PKLEN);
123
141
  const bech32_address = response.readBytes(response.length()).toString();
124
- return {
125
- compressed_pk,
126
- bech32_address,
127
- };
142
+ return { compressed_pk, bech32_address };
128
143
  }
129
144
  catch (e) {
130
- throw (0, ledger_js_1.processErrorResponse)(e);
145
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
131
146
  }
132
147
  }
133
148
  static getBech32FromPK(hrp, pk) {
134
149
  if (pk.length !== 33) {
135
- throw new Error("expected compressed public key [31 bytes]");
150
+ throw new Error('expected compressed public key [31 bytes]');
136
151
  }
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));
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));
140
155
  }
141
156
  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);
157
+ const serializedPath = this.serializeCosmosPath(path);
158
+ const firstChunk = hrp ? Buffer.concat([serializedPath, this.serializeHRP(hrp)]) : serializedPath;
159
+ const chunks = [firstChunk];
146
160
  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
- }
161
+ const end = Math.min(i + this.CHUNK_SIZE, buffer.length);
151
162
  chunks.push(buffer.subarray(i, end));
152
163
  }
153
164
  return chunks;
154
165
  }
155
166
  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
- }
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;
163
168
  const statusList = [ledger_js_1.LedgerError.NoErrors, ledger_js_1.LedgerError.DataIsInvalid, ledger_js_1.LedgerError.BadKeyHandle];
164
169
  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;
170
+ return (0, ledger_js_1.processResponse)(responseBuffer);
167
171
  }
168
- async signImpl(path, buffer, hrp, txtype) {
172
+ async signImpl(path, buffer, txtype, hrp) {
169
173
  const chunks = await this.prepareChunks_hrp(path, buffer, hrp);
170
174
  try {
171
175
  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);
176
+ for (let i = 1; i < chunks.length; i++) {
177
+ result = await this.signSendCosmosChunk(i + 1, chunks.length, chunks[i], txtype);
174
178
  }
175
- return {
176
- signature: result.readBytes(result.length()),
177
- };
179
+ return { signature: result.readBytes(result.length()) };
178
180
  }
179
181
  catch (e) {
180
- throw (0, ledger_js_1.processErrorResponse)(e);
182
+ throw (0, ledger_js_1.processErrorResponse)(e, COSMOS_CUSTOM_ERROR_DESCRIPTIONS);
181
183
  }
182
184
  }
183
185
  async sign(path, buffer, hrp, txtype = 0 /* P2_VALUES.JSON */) {
184
- return await this.signImpl(path, buffer, hrp, txtype);
186
+ return this.signImpl(path, buffer, txtype, hrp);
185
187
  }
186
188
  }
187
189
  CosmosApp._INS = {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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,QAAQ,CAAC,CAAC;AACjC,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAEvC,MAAqB,SAA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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"]}
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,CAAC,GAAW;QAC9B,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,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I,MAAM,GAAG,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,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"]}
package/dist/types.js.map CHANGED
@@ -1 +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"]}
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,98 +1,83 @@
1
1
  {
2
2
  "name": "@zondax/ledger-cosmos-js",
3
- "author": "Zondax AG",
4
- "license": "Apache-2.0",
5
- "version": "4.0.0",
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
- "@ledgerhq/hw-transport": "6.30.6",
32
- "@zondax/ledger-js": "^0.10.0",
33
- "bech32": "^2.0.0",
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",
34
43
  "buffer": "^6.0.3",
35
- "crypto": "^1.0.1",
36
- "crypto-browserify": "^3.12.0",
37
- "ripemd160": "^2.0.2",
38
- "stream-browserify": "^3.0.0"
44
+ "ripemd160": "^2.0.2"
39
45
  },
40
46
  "devDependencies": {
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",
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",
51
56
  "bip39": "3.1.0",
52
- "copyfiles": "^2.4.1",
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",
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",
62
63
  "jest": "^29.7.0",
63
- "jest-serial-runner": "^1.2.0",
64
- "prettier": "^3.3.2",
65
- "secp256k1": "^5.0.0",
66
- "ts-jest": "29.1.5",
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",
67
69
  "ts-node": "^10.9.2",
68
- "typescript": "^5.4.5",
69
- "webpack": "^5.92.0"
70
+ "typescript": "^5.8.3"
71
+ },
72
+ "volta": {
73
+ "node": "20.11.1",
74
+ "bun": "1.0.20"
70
75
  },
71
- "moduleDirectories": [
72
- "node_modules",
73
- "dist"
74
- ],
75
- "browserslist": [
76
- "> 1%",
77
- "last 2 versions"
78
- ],
79
- "files": [
80
- "dist/*",
81
- "LICENSE",
82
- "yarn.lock"
83
- ],
84
76
  "publishConfig": {
85
77
  "access": "public"
86
78
  },
87
- "peerDependencies": {
88
- "@babel/core": "^7.17.5",
89
- "@types/node": "^17.0.21"
90
- },
91
- "scripts": {
92
- "build": "tsc",
93
- "lint": "eslint .",
94
- "lint:fix": "eslint --fix .",
95
- "format": "prettier --write .",
96
- "test": "yarn build && jest"
97
- }
79
+ "moduleDirectories": [
80
+ "node_modules",
81
+ "dist"
82
+ ]
98
83
  }