@taquito/ledger-signer 16.2.0 → 17.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.
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidDerivationTypeError = exports.PublicKeyHashRetrievalError = exports.PublicKeyRetrievalError = exports.InvalidLedgerResponseError = void 0;
4
+ const core_1 = require("@taquito/core");
5
+ /**
6
+ * @category Error
7
+ * @description Error indicates an invalid or unparseable ledger response
8
+ */
9
+ class InvalidLedgerResponseError extends core_1.TaquitoError {
10
+ constructor(message) {
11
+ super();
12
+ this.message = message;
13
+ this.name = 'InvalidLedgerResponseError';
14
+ }
15
+ }
16
+ exports.InvalidLedgerResponseError = InvalidLedgerResponseError;
17
+ /**
18
+ * @category Error
19
+ * @description Error indicates a failure when trying to retrieve a Public Key from Ledger signer
20
+ */
21
+ class PublicKeyRetrievalError extends core_1.TaquitoError {
22
+ constructor(cause) {
23
+ super();
24
+ this.cause = cause;
25
+ this.name = 'PublicKeyRetrievalError';
26
+ this.message = `Unable to retrieve Public Key from Ledger`;
27
+ }
28
+ }
29
+ exports.PublicKeyRetrievalError = PublicKeyRetrievalError;
30
+ /**
31
+ * @category Error
32
+ * @description Error indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
33
+ */
34
+ class PublicKeyHashRetrievalError extends core_1.TaquitoError {
35
+ constructor() {
36
+ super();
37
+ this.name = 'PublicKeyHashRetrievalError';
38
+ this.message = 'Unable to retrieve Public Key Hash from Ledger';
39
+ }
40
+ }
41
+ exports.PublicKeyHashRetrievalError = PublicKeyHashRetrievalError;
42
+ /**
43
+ * @category Error
44
+ * @description Error indicates an invalid derivation type being passed or used
45
+ */
46
+ class InvalidDerivationTypeError extends core_1.ParameterValidationError {
47
+ constructor(derivationType) {
48
+ super();
49
+ this.derivationType = derivationType;
50
+ this.name = 'InvalidDerivationTypeError';
51
+ this.message = `Invalid derivation type ${derivationType} expecting one of the following: DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`;
52
+ }
53
+ }
54
+ exports.InvalidDerivationTypeError = InvalidDerivationTypeError;
55
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,wCAAuE;AAEvE;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,mBAAY;IAC1D,YAAmB,OAAe;QAChC,KAAK,EAAE,CAAC;QADS,YAAO,GAAP,OAAO,CAAQ;QAEhC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AALD,gEAKC;AAED;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,mBAAY;IACvD,YAAmB,KAAU;QAC3B,KAAK,EAAE,CAAC;QADS,UAAK,GAAL,KAAK,CAAK;QAE3B,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,2CAA2C,CAAC;IAC7D,CAAC;CACF;AAND,0DAMC;AAED;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,mBAAY;IAC3D;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,OAAO,GAAG,gDAAgD,CAAC;IAClE,CAAC;CACF;AAND,kEAMC;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,+BAAwB;IACtE,YAAmB,cAAsB;QACvC,KAAK,EAAE,CAAC;QADS,mBAAc,GAAd,cAAc,CAAQ;QAEvC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,2BAA2B,cAAc,wIAAwI,CAAC;IACnM,CAAC;CACF;AAND,gEAMC"}
@@ -17,7 +17,7 @@ exports.LedgerSigner = exports.VERSION = exports.HDPathTemplate = exports.Invali
17
17
  const utils_1 = require("@taquito/utils");
18
18
  const utils_2 = require("./utils");
19
19
  const blake2b_1 = require("@stablelib/blake2b");
20
- const error_1 = require("./error");
20
+ const errors_1 = require("./errors");
21
21
  const core_1 = require("@taquito/core");
22
22
  var core_2 = require("@taquito/core");
23
23
  Object.defineProperty(exports, "InvalidDerivationPathError", { enumerable: true, get: function () { return core_2.InvalidDerivationPathError; } });
@@ -28,18 +28,8 @@ var DerivationType;
28
28
  DerivationType[DerivationType["P256"] = 2] = "P256";
29
29
  DerivationType[DerivationType["BIP32_ED25519"] = 3] = "BIP32_ED25519";
30
30
  })(DerivationType = exports.DerivationType || (exports.DerivationType = {}));
31
- /**
32
- * @category Error
33
- * @description Error that indicates an invalid derivation type being passed or used
34
- */
35
- class InvalidDerivationTypeError extends Error {
36
- constructor(derivationType) {
37
- super(`The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`);
38
- this.derivationType = derivationType;
39
- this.name = 'InvalidDerivationTypeError';
40
- }
41
- }
42
- exports.InvalidDerivationTypeError = InvalidDerivationTypeError;
31
+ var errors_2 = require("./errors");
32
+ Object.defineProperty(exports, "InvalidDerivationTypeError", { enumerable: true, get: function () { return errors_2.InvalidDerivationTypeError; } });
43
33
  const HDPathTemplate = (account) => {
44
34
  return `44'/1729'/${account}'/0'`;
45
35
  };
@@ -92,10 +82,10 @@ class LedgerSigner {
92
82
  this.OTHER_MESSAGE_SEQUENCE = 0x01;
93
83
  this.transport.setScrambleKey('XTZ');
94
84
  if (!path.startsWith(`44'/1729'`)) {
95
- throw new core_1.InvalidDerivationPathError(path, `: Invalid prefix expecting prefix "44'/1729'".`);
85
+ throw new core_1.InvalidDerivationPathError(path, `${utils_1.invalidDetail(utils_1.ValidationResult.NO_PREFIX_MATCHED)} expecting prefix "44'/1729'".`);
96
86
  }
97
87
  if (!Object.values(DerivationType).includes(derivationType)) {
98
- throw new InvalidDerivationTypeError(derivationType.toString());
88
+ throw new errors_1.InvalidDerivationTypeError(derivationType.toString());
99
89
  }
100
90
  }
101
91
  publicKeyHash() {
@@ -106,7 +96,7 @@ class LedgerSigner {
106
96
  if (this._publicKeyHash) {
107
97
  return this._publicKeyHash;
108
98
  }
109
- throw new error_1.PublicKeyHashRetrievalError();
99
+ throw new errors_1.PublicKeyHashRetrievalError();
110
100
  });
111
101
  }
112
102
  publicKey() {
@@ -137,7 +127,7 @@ class LedgerSigner {
137
127
  return responseLedger;
138
128
  }
139
129
  catch (error) {
140
- throw new error_1.PublicKeyRetrievalError();
130
+ throw new errors_1.PublicKeyRetrievalError(error);
141
131
  }
142
132
  });
143
133
  }
@@ -161,7 +151,7 @@ class LedgerSigner {
161
151
  }
162
152
  else {
163
153
  if (!utils_2.validateResponse(ledgerResponse)) {
164
- throw new error_1.InvalidLedgerResponseError('Cannot parse ledger response');
154
+ throw new errors_1.InvalidLedgerResponseError('Invalid signature return by ledger unable to parse the response');
165
155
  }
166
156
  const idxLengthRVal = 3; // Third element of response is length of r value
167
157
  const rValue = utils_2.extractValue(idxLengthRVal, ledgerResponse);
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-ledger-signer.js","sourceRoot":"","sources":["../../src/taquito-ledger-signer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAIH,0CAA4D;AAC5D,mCAOiB;AACjB,gDAA0C;AAC1C,mCAIiB;AACjB,wCAAkF;AAElF,sCAA2D;AAAlD,kHAAA,0BAA0B,OAAA;AAInC,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yDAAc,CAAA;IACd,6DAAgB,CAAA;IAChB,mDAAW,CAAA;IACX,qEAAoB,CAAA;AACtB,CAAC,EALW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAKzB;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IAEnD,YAAmB,cAAsB;QACvC,KAAK,CACH,uBAAuB,cAAc,gJAAgJ,CACtL,CAAC;QAHe,mBA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!
5
5
  exports.VERSION = {
6
- "commitHash": "adc0f8c31492e8eb2f03b06ac36ba053e8ba6224",
7
- "version": "16.2.0"
6
+ "commitHash": "b357541c90c2168d48216d62a07de5dd3baab9a0",
7
+ "version": "17.0.0"
8
8
  };
9
9
  //# sourceMappingURL=version.js.map
@@ -1,6 +1,6 @@
1
- import { prefix, Prefix, b58cencode } from '@taquito/utils';
1
+ import { invalidDetail, ValidationResult, prefix, Prefix, b58cencode } from '@taquito/utils';
2
2
  import { hash } from '@stablelib/blake2b';
3
- import { InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';
3
+ import { ParameterValidationError, TaquitoError, InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';
4
4
  export { InvalidDerivationPathError } from '@taquito/core';
5
5
 
6
6
  /******************************************************************************
@@ -150,40 +150,55 @@ function extractValue(idxLength, response) {
150
150
 
151
151
  /**
152
152
  * @category Error
153
- * @description Error that indicates an invalid or unparseable ledger response
153
+ * @description Error indicates an invalid or unparseable ledger response
154
154
  */
155
- class InvalidLedgerResponseError extends Error {
155
+ class InvalidLedgerResponseError extends TaquitoError {
156
156
  constructor(message) {
157
- super(message);
157
+ super();
158
158
  this.message = message;
159
159
  this.name = 'InvalidLedgerResponseError';
160
160
  }
161
161
  }
162
162
  /**
163
163
  * @category Error
164
- * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
164
+ * @description Error indicates a failure when trying to retrieve a Public Key from Ledger signer
165
165
  */
166
- class PublicKeyRetrievalError extends Error {
167
- constructor() {
168
- super(`Unable to retrieve Public Key from Ledger`);
166
+ class PublicKeyRetrievalError extends TaquitoError {
167
+ constructor(cause) {
168
+ super();
169
+ this.cause = cause;
169
170
  this.name = 'PublicKeyRetrievalError';
171
+ this.message = `Unable to retrieve Public Key from Ledger`;
170
172
  }
171
173
  }
172
174
  /**
173
175
  * @category Error
174
- * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
176
+ * @description Error indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
175
177
  */
176
- class PublicKeyHashRetrievalError extends Error {
178
+ class PublicKeyHashRetrievalError extends TaquitoError {
177
179
  constructor() {
178
- super(`Unable to retrieve Public Key Hash from Ledger`);
180
+ super();
179
181
  this.name = 'PublicKeyHashRetrievalError';
182
+ this.message = 'Unable to retrieve Public Key Hash from Ledger';
183
+ }
184
+ }
185
+ /**
186
+ * @category Error
187
+ * @description Error indicates an invalid derivation type being passed or used
188
+ */
189
+ class InvalidDerivationTypeError extends ParameterValidationError {
190
+ constructor(derivationType) {
191
+ super();
192
+ this.derivationType = derivationType;
193
+ this.name = 'InvalidDerivationTypeError';
194
+ this.message = `Invalid derivation type ${derivationType} expecting one of the following: DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`;
180
195
  }
181
196
  }
182
197
 
183
198
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
184
199
  const VERSION = {
185
- "commitHash": "adc0f8c31492e8eb2f03b06ac36ba053e8ba6224",
186
- "version": "16.2.0"
200
+ "commitHash": "b357541c90c2168d48216d62a07de5dd3baab9a0",
201
+ "version": "17.0.0"
187
202
  };
188
203
 
189
204
  /**
@@ -197,17 +212,6 @@ var DerivationType;
197
212
  DerivationType[DerivationType["P256"] = 2] = "P256";
198
213
  DerivationType[DerivationType["BIP32_ED25519"] = 3] = "BIP32_ED25519";
199
214
  })(DerivationType || (DerivationType = {}));
200
- /**
201
- * @category Error
202
- * @description Error that indicates an invalid derivation type being passed or used
203
- */
204
- class InvalidDerivationTypeError extends Error {
205
- constructor(derivationType) {
206
- super(`The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`);
207
- this.derivationType = derivationType;
208
- this.name = 'InvalidDerivationTypeError';
209
- }
210
- }
211
215
  const HDPathTemplate = (account) => {
212
216
  return `44'/1729'/${account}'/0'`;
213
217
  };
@@ -257,7 +261,7 @@ class LedgerSigner {
257
261
  this.OTHER_MESSAGE_SEQUENCE = 0x01;
258
262
  this.transport.setScrambleKey('XTZ');
259
263
  if (!path.startsWith(`44'/1729'`)) {
260
- throw new InvalidDerivationPathError(path, `: Invalid prefix expecting prefix "44'/1729'".`);
264
+ throw new InvalidDerivationPathError(path, `${invalidDetail(ValidationResult.NO_PREFIX_MATCHED)} expecting prefix "44'/1729'".`);
261
265
  }
262
266
  if (!Object.values(DerivationType).includes(derivationType)) {
263
267
  throw new InvalidDerivationTypeError(derivationType.toString());
@@ -302,7 +306,7 @@ class LedgerSigner {
302
306
  return responseLedger;
303
307
  }
304
308
  catch (error) {
305
- throw new PublicKeyRetrievalError();
309
+ throw new PublicKeyRetrievalError(error);
306
310
  }
307
311
  });
308
312
  }
@@ -326,7 +330,7 @@ class LedgerSigner {
326
330
  }
327
331
  else {
328
332
  if (!validateResponse(ledgerResponse)) {
329
- throw new InvalidLedgerResponseError('Cannot parse ledger response');
333
+ throw new InvalidLedgerResponseError('Invalid signature return by ledger unable to parse the response');
330
334
  }
331
335
  const idxLengthRVal = 3; // Third element of response is length of r value
332
336
  const rValue = extractValue(idxLengthRVal, ledgerResponse);
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-ledger-signer.es6.js","sources":["../src/utils.ts","../src/error.ts","../src/version.ts","../src/taquito-ledger-signer.ts"],"sourcesContent":["/*\n * Some code in this file is adapted from sotez\n * Copyright (c) 2018 Andrew Kishino\n */\n\nimport { DerivationType } from './taquito-ledger-signer';\n\nconst MAX_CHUNK_SIZE = 230;\n\n/**\n *\n * @description Convert the path to a buffer that will be used as LC and CDATA in the APDU send to the ledger device (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n *\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @returns A buffer where the first element is the length of the path (default is 4), then 3 bytes for each number of the path to which is added 0x8000000\n */\nexport function transformPathToBuffer(path: string): Buffer {\n const result: number[] = [];\n const components = path.split('/');\n components.forEach((element) => {\n let toNumber = parseInt(element, 10);\n if (Number.isNaN(toNumber)) {\n return;\n }\n if (element.length > 1 && element[element.length - 1] === \"'\") {\n toNumber += 0x80000000;\n }\n result.push(toNumber);\n });\n const buffer = Buffer.alloc(1 + result.length * 4);\n buffer[0] = result.length;\n result.forEach((element, index) => {\n buffer.writeUInt32BE(element, 1 + 4 * index);\n });\n return buffer;\n}\n\n/**\n *\n * @description Converts uncompressed ledger key to standard tezos binary representation\n */\nexport function compressPublicKey(publicKey: Buffer, curve: DerivationType) {\n if (curve === 0x00 || curve === 0x03) {\n publicKey = publicKey.slice(1);\n } else {\n publicKey[0] = 0x02 + (publicKey[64] & 0x01);\n publicKey = publicKey.slice(0, 33);\n }\n return publicKey;\n}\n\nexport function appendWatermark(bytes: string, watermark?: Uint8Array): string {\n let transactionHex = bytes;\n if (typeof watermark !== 'undefined') {\n const hexWatermark = Buffer.from(watermark).toString('hex');\n transactionHex = hexWatermark.concat(bytes);\n }\n return transactionHex;\n}\n\n/**\n *\n * @description In order not to exceed the data length allowed by the Ledger device, split the operation into buffers of 230 bytes (max) and add them to the message to send to the Ledger\n * @param messageToSend The message to send to the Ledger device\n * @param operation The operation which will be chunk if its length is over 230 bytes\n * @returns The instruction to send to the Ledger device\n */\nexport function chunkOperation(messageToSend: any, operation: Buffer) {\n let offset = 0;\n while (offset !== operation.length) {\n const chunkSize =\n offset + MAX_CHUNK_SIZE >= operation.length ? operation.length - offset : MAX_CHUNK_SIZE;\n const buff = Buffer.alloc(chunkSize);\n operation.copy(buff, 0, offset, offset + chunkSize);\n messageToSend.push(buff);\n offset += chunkSize;\n }\n return messageToSend;\n}\n\n/**\n *\n * @description Verify if the signature returned by the ledger for tz2 and tz3 is valid\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns True if valid, false otherwise\n */\nexport function validateResponse(response: Buffer): boolean {\n let valid = true;\n if (response[0] !== 0x31 && response[0] !== 0x30) {\n valid = false;\n }\n if (response[1] + 4 !== response.length) {\n valid = false;\n }\n if (response[2] !== 0x02) {\n valid = false;\n }\n const rLength = response[3];\n if (response[4 + rLength] !== 0x02) {\n valid = false;\n }\n\n const idxLengthSVal = 5 + rLength;\n const sLength = response[idxLengthSVal];\n if (idxLengthSVal + 1 + sLength + 2 !== response.length) {\n valid = false;\n }\n return valid;\n}\n\n/**\n *\n * @description Extract a part of the response returned by the Ledger\n * @param idxLength The index in the response from the Ledger that corresponds to the length of the part to extract\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns An object that contains the extracted buffer, the index where it starts in the response and the length of the extracted part\n */\nexport function extractValue(idxLength: number, response: Buffer) {\n const buffer = Buffer.alloc(32);\n buffer.fill(0);\n\n let length = response[idxLength];\n let idxValueStart = idxLength + 1;\n if (length > 32) {\n idxValueStart += length - 32;\n length = 32;\n }\n response.copy(buffer, 32 - length, idxValueStart, idxValueStart + length);\n return { buffer, idxValueStart, length };\n}\n","/**\n * @category Error\n * @description Error that indicates an invalid or unparseable ledger response\n */\nexport class InvalidLedgerResponseError extends Error {\n public name = 'InvalidLedgerResponseError';\n constructor(public message: string) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer\n */\nexport class PublicKeyRetrievalError extends Error {\n public name = 'PublicKeyRetrievalError';\n constructor() {\n super(`Unable to retrieve Public Key from Ledger`);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer\n */\nexport class PublicKeyHashRetrievalError extends Error {\n public name = 'PublicKeyHashRetrievalError';\n constructor() {\n super(`Unable to retrieve Public Key Hash from Ledger`);\n }\n}\n","\n// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"adc0f8c31492e8eb2f03b06ac36ba053e8ba6224\",\n \"version\": \"16.2.0\"\n};\n","/**\n * @packageDocumentation\n * @module @taquito/ledger-signer\n */\n\nimport { Signer } from '@taquito/taquito';\nimport Transport from '@ledgerhq/hw-transport';\nimport { b58cencode, prefix, Prefix } from '@taquito/utils';\nimport {\n appendWatermark,\n transformPathToBuffer,\n compressPublicKey,\n chunkOperation,\n validateResponse,\n extractValue,\n} from './utils';\nimport { hash } from '@stablelib/blake2b';\nimport {\n PublicKeyHashRetrievalError,\n PublicKeyRetrievalError,\n InvalidLedgerResponseError,\n} from './error';\nimport { InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';\n\nexport { InvalidDerivationPathError } from '@taquito/core';\n\nexport type LedgerTransport = Pick<Transport, 'send' | 'decorateAppAPIMethods' | 'setScrambleKey'>;\n\nexport enum DerivationType {\n ED25519 = 0x00, // tz1\n SECP256K1 = 0x01, // tz2\n P256 = 0x02, // tz3\n BIP32_ED25519 = 0x03, // tz1 BIP32\n}\n\n/**\n * @category Error\n * @description Error that indicates an invalid derivation type being passed or used\n */\nexport class InvalidDerivationTypeError extends Error {\n public name = 'InvalidDerivationTypeError';\n constructor(public derivationType: string) {\n super(\n `The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`\n );\n }\n}\n\nexport const HDPathTemplate = (account: number) => {\n return `44'/1729'/${account}'/0'`;\n};\n\nexport { VERSION } from './version';\n\n/**\n *\n * @description Implementation of the Signer interface that will allow signing operation from a Ledger Nano device\n *\n * @param transport A transport instance from LedgerJS libraries depending on the platform used (e.g. Web, Node)\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @param prompt Whether to prompt the ledger for public key (default is true)\n * @param derivationType The value which defines the curve to use (DerivationType.ED25519(default), DerivationType.SECP256K1, DerivationType.P256, DerivationType.BIP32_ED25519)\n *\n * @example\n * ```\n * import TransportNodeHid from \"@ledgerhq/hw-transport-node-hid\";\n * const transport = await TransportNodeHid.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", false, DerivationType.ED25519);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", true, DerivationType.SECP256K1);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/6'/0'\", true, DerivationType.BIP32_ED25519);\n * ```\n */\nexport class LedgerSigner implements Signer {\n // constants for APDU requests (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n private readonly CLA = 0x80; // Instruction class (always 0x80)\n private readonly INS_GET_PUBLIC_KEY = 0x02; // Instruction code to get the ledger’s internal public key without prompt\n private readonly INS_PROMPT_PUBLIC_KEY = 0x03; // Instruction code to get the ledger’s internal public key with prompt\n private readonly INS_SIGN = 0x04; // Sign a message with the ledger’s key\n private readonly FIRST_MESSAGE_SEQUENCE = 0x00;\n private readonly LAST_MESSAGE_SEQUENCE = 0x81;\n private readonly OTHER_MESSAGE_SEQUENCE = 0x01;\n\n private _publicKey?: string;\n private _publicKeyHash?: string;\n constructor(\n private transport: LedgerTransport,\n private path: string = \"44'/1729'/0'/0'\",\n private prompt: boolean = true,\n private derivationType: DerivationType = DerivationType.ED25519\n ) {\n this.transport.setScrambleKey('XTZ');\n if (!path.startsWith(`44'/1729'`)) {\n throw new InvalidDerivationPathError(path, `: Invalid prefix expecting prefix \"44'/1729'\".`);\n }\n if (!Object.values(DerivationType).includes(derivationType)) {\n throw new InvalidDerivationTypeError(derivationType.toString());\n }\n }\n\n async publicKeyHash(): Promise<string> {\n if (!this._publicKeyHash) {\n await this.publicKey();\n }\n if (this._publicKeyHash) {\n return this._publicKeyHash;\n }\n throw new PublicKeyHashRetrievalError();\n }\n\n async publicKey(): Promise<string> {\n if (this._publicKey) {\n return this._publicKey;\n }\n const responseLedger = await this.getLedgerPublicKey();\n const publicKeyLength = responseLedger[0];\n const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);\n const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);\n\n const prefixes = this.getPrefixes();\n const publicKey = b58cencode(compressedPublicKey, prefixes.prefPk);\n const publicKeyHash = b58cencode(hash(compressedPublicKey, 20), prefixes.prefPkh);\n\n this._publicKey = publicKey;\n this._publicKeyHash = publicKeyHash;\n return publicKey;\n }\n\n private async getLedgerPublicKey(): Promise<Buffer> {\n try {\n let ins = this.INS_PROMPT_PUBLIC_KEY;\n if (this.prompt === false) {\n ins = this.INS_GET_PUBLIC_KEY;\n }\n const responseLedger = await this.transport.send(\n this.CLA,\n ins,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n transformPathToBuffer(this.path)\n );\n return responseLedger;\n } catch (error) {\n throw new PublicKeyRetrievalError();\n }\n }\n\n async secretKey(): Promise<string> {\n throw new ProhibitedActionError('Secret key cannot be exposed');\n }\n\n async sign(bytes: string, watermark?: Uint8Array) {\n const watermarkedBytes = appendWatermark(bytes, watermark);\n const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');\n let messageToSend = [];\n messageToSend.push(transformPathToBuffer(this.path));\n messageToSend = chunkOperation(messageToSend, watermarkedBytes2buff);\n const ledgerResponse = await this.signWithLedger(messageToSend);\n let signature;\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');\n } else {\n if (!validateResponse(ledgerResponse)) {\n throw new InvalidLedgerResponseError('Cannot parse ledger response');\n }\n const idxLengthRVal = 3; // Third element of response is length of r value\n const rValue = extractValue(idxLengthRVal, ledgerResponse);\n const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;\n const sValue = extractValue(idxLengthSVal, ledgerResponse);\n const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);\n signature = signatureBuffer.toString('hex');\n }\n\n return {\n bytes,\n sig: b58cencode(signature, prefix[Prefix.SIG]),\n prefixSig: b58cencode(signature, this.getPrefixes().prefSig),\n sbytes: bytes + signature,\n };\n }\n\n private async signWithLedger(message: Buffer[]): Promise<Buffer> {\n // first element of the message represents the path\n let ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n message[0]\n );\n for (let i = 1; i < message.length; i++) {\n const p1 =\n i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;\n ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n p1,\n this.derivationType,\n message[i]\n );\n }\n return ledgerResponse;\n }\n\n private getPrefixes() {\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n return {\n prefPk: prefix[Prefix.EDPK],\n prefPkh: prefix[Prefix.TZ1],\n prefSig: prefix[Prefix.EDSIG],\n };\n } else if (this.derivationType === DerivationType.SECP256K1) {\n return {\n prefPk: prefix[Prefix.SPPK],\n prefPkh: prefix[Prefix.TZ2],\n prefSig: prefix[Prefix.SPSIG],\n };\n } else {\n return {\n prefPk: prefix[Prefix.P2PK],\n prefPkh: prefix[Prefix.TZ3],\n prefSig: prefix[Prefix.P2SIG],\n };\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;AAGG;AAIH,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;;;;;AAMG;AACG,SAAU,qBAAqB,CAAC,IAAY,EAAA;IAChD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACnC,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,KAAI;QAC7B,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACrC,QAAA,IAAI,MAAM,CAAC,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AAAM,aAAA;YACL,OAAO;AACL,gBAAA,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;AAC3B,gBAAA,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;AAC3B,gBAAA,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9B,CAAC;AACH,SAAA;KACF;AACF;;;;"}
1
+ {"version":3,"file":"taquito-ledger-signer.es6.js","sources":["../src/utils.ts","../src/errors.ts","../src/version.ts","../src/taquito-ledger-signer.ts"],"sourcesContent":["/*\n * Some code in this file is adapted from sotez\n * Copyright (c) 2018 Andrew Kishino\n */\n\nimport { DerivationType } from './taquito-ledger-signer';\n\nconst MAX_CHUNK_SIZE = 230;\n\n/**\n *\n * @description Convert the path to a buffer that will be used as LC and CDATA in the APDU send to the ledger device (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n *\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @returns A buffer where the first element is the length of the path (default is 4), then 3 bytes for each number of the path to which is added 0x8000000\n */\nexport function transformPathToBuffer(path: string): Buffer {\n const result: number[] = [];\n const components = path.split('/');\n components.forEach((element) => {\n let toNumber = parseInt(element, 10);\n if (Number.isNaN(toNumber)) {\n return;\n }\n if (element.length > 1 && element[element.length - 1] === \"'\") {\n toNumber += 0x80000000;\n }\n result.push(toNumber);\n });\n const buffer = Buffer.alloc(1 + result.length * 4);\n buffer[0] = result.length;\n result.forEach((element, index) => {\n buffer.writeUInt32BE(element, 1 + 4 * index);\n });\n return buffer;\n}\n\n/**\n *\n * @description Converts uncompressed ledger key to standard tezos binary representation\n */\nexport function compressPublicKey(publicKey: Buffer, curve: DerivationType) {\n if (curve === 0x00 || curve === 0x03) {\n publicKey = publicKey.slice(1);\n } else {\n publicKey[0] = 0x02 + (publicKey[64] & 0x01);\n publicKey = publicKey.slice(0, 33);\n }\n return publicKey;\n}\n\nexport function appendWatermark(bytes: string, watermark?: Uint8Array): string {\n let transactionHex = bytes;\n if (typeof watermark !== 'undefined') {\n const hexWatermark = Buffer.from(watermark).toString('hex');\n transactionHex = hexWatermark.concat(bytes);\n }\n return transactionHex;\n}\n\n/**\n *\n * @description In order not to exceed the data length allowed by the Ledger device, split the operation into buffers of 230 bytes (max) and add them to the message to send to the Ledger\n * @param messageToSend The message to send to the Ledger device\n * @param operation The operation which will be chunk if its length is over 230 bytes\n * @returns The instruction to send to the Ledger device\n */\nexport function chunkOperation(messageToSend: any, operation: Buffer) {\n let offset = 0;\n while (offset !== operation.length) {\n const chunkSize =\n offset + MAX_CHUNK_SIZE >= operation.length ? operation.length - offset : MAX_CHUNK_SIZE;\n const buff = Buffer.alloc(chunkSize);\n operation.copy(buff, 0, offset, offset + chunkSize);\n messageToSend.push(buff);\n offset += chunkSize;\n }\n return messageToSend;\n}\n\n/**\n *\n * @description Verify if the signature returned by the ledger for tz2 and tz3 is valid\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns True if valid, false otherwise\n */\nexport function validateResponse(response: Buffer): boolean {\n let valid = true;\n if (response[0] !== 0x31 && response[0] !== 0x30) {\n valid = false;\n }\n if (response[1] + 4 !== response.length) {\n valid = false;\n }\n if (response[2] !== 0x02) {\n valid = false;\n }\n const rLength = response[3];\n if (response[4 + rLength] !== 0x02) {\n valid = false;\n }\n\n const idxLengthSVal = 5 + rLength;\n const sLength = response[idxLengthSVal];\n if (idxLengthSVal + 1 + sLength + 2 !== response.length) {\n valid = false;\n }\n return valid;\n}\n\n/**\n *\n * @description Extract a part of the response returned by the Ledger\n * @param idxLength The index in the response from the Ledger that corresponds to the length of the part to extract\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns An object that contains the extracted buffer, the index where it starts in the response and the length of the extracted part\n */\nexport function extractValue(idxLength: number, response: Buffer) {\n const buffer = Buffer.alloc(32);\n buffer.fill(0);\n\n let length = response[idxLength];\n let idxValueStart = idxLength + 1;\n if (length > 32) {\n idxValueStart += length - 32;\n length = 32;\n }\n response.copy(buffer, 32 - length, idxValueStart, idxValueStart + length);\n return { buffer, idxValueStart, length };\n}\n","import { ParameterValidationError, TaquitoError } from '@taquito/core';\n\n/**\n * @category Error\n * @description Error indicates an invalid or unparseable ledger response\n */\nexport class InvalidLedgerResponseError extends TaquitoError {\n constructor(public message: string) {\n super();\n this.name = 'InvalidLedgerResponseError';\n }\n}\n\n/**\n * @category Error\n * @description Error indicates a failure when trying to retrieve a Public Key from Ledger signer\n */\nexport class PublicKeyRetrievalError extends TaquitoError {\n constructor(public cause: any) {\n super();\n this.name = 'PublicKeyRetrievalError';\n this.message = `Unable to retrieve Public Key from Ledger`;\n }\n}\n\n/**\n * @category Error\n * @description Error indicates a failure when trying to retrieve a Public Key Hash from Ledger signer\n */\nexport class PublicKeyHashRetrievalError extends TaquitoError {\n constructor() {\n super();\n this.name = 'PublicKeyHashRetrievalError';\n this.message = 'Unable to retrieve Public Key Hash from Ledger';\n }\n}\n\n/**\n * @category Error\n * @description Error indicates an invalid derivation type being passed or used\n */\nexport class InvalidDerivationTypeError extends ParameterValidationError {\n constructor(public derivationType: string) {\n super();\n this.name = 'InvalidDerivationTypeError';\n this.message = `Invalid derivation type ${derivationType} expecting one of the following: DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`;\n }\n}\n","\n// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"b357541c90c2168d48216d62a07de5dd3baab9a0\",\n \"version\": \"17.0.0\"\n};\n","/**\n * @packageDocumentation\n * @module @taquito/ledger-signer\n */\n\nimport { Signer } from '@taquito/taquito';\nimport Transport from '@ledgerhq/hw-transport';\nimport { b58cencode, invalidDetail, prefix, Prefix, ValidationResult } from '@taquito/utils';\nimport {\n appendWatermark,\n transformPathToBuffer,\n compressPublicKey,\n chunkOperation,\n validateResponse,\n extractValue,\n} from './utils';\nimport { hash } from '@stablelib/blake2b';\nimport {\n PublicKeyHashRetrievalError,\n PublicKeyRetrievalError,\n InvalidLedgerResponseError,\n InvalidDerivationTypeError,\n} from './errors';\nimport { InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';\n\nexport { InvalidDerivationPathError } from '@taquito/core';\n\nexport type LedgerTransport = Pick<Transport, 'send' | 'decorateAppAPIMethods' | 'setScrambleKey'>;\n\nexport enum DerivationType {\n ED25519 = 0x00, // tz1\n SECP256K1 = 0x01, // tz2\n P256 = 0x02, // tz3\n BIP32_ED25519 = 0x03, // tz1 BIP32\n}\n\nexport { InvalidDerivationTypeError } from './errors';\n\nexport const HDPathTemplate = (account: number) => {\n return `44'/1729'/${account}'/0'`;\n};\n\nexport { VERSION } from './version';\n\n/**\n *\n * @description Implementation of the Signer interface that will allow signing operation from a Ledger Nano device\n *\n * @param transport A transport instance from LedgerJS libraries depending on the platform used (e.g. Web, Node)\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @param prompt Whether to prompt the ledger for public key (default is true)\n * @param derivationType The value which defines the curve to use (DerivationType.ED25519(default), DerivationType.SECP256K1, DerivationType.P256, DerivationType.BIP32_ED25519)\n *\n * @example\n * ```\n * import TransportNodeHid from \"@ledgerhq/hw-transport-node-hid\";\n * const transport = await TransportNodeHid.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", false, DerivationType.ED25519);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", true, DerivationType.SECP256K1);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/6'/0'\", true, DerivationType.BIP32_ED25519);\n * ```\n */\nexport class LedgerSigner implements Signer {\n // constants for APDU requests (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n private readonly CLA = 0x80; // Instruction class (always 0x80)\n private readonly INS_GET_PUBLIC_KEY = 0x02; // Instruction code to get the ledger’s internal public key without prompt\n private readonly INS_PROMPT_PUBLIC_KEY = 0x03; // Instruction code to get the ledger’s internal public key with prompt\n private readonly INS_SIGN = 0x04; // Sign a message with the ledger’s key\n private readonly FIRST_MESSAGE_SEQUENCE = 0x00;\n private readonly LAST_MESSAGE_SEQUENCE = 0x81;\n private readonly OTHER_MESSAGE_SEQUENCE = 0x01;\n\n private _publicKey?: string;\n private _publicKeyHash?: string;\n constructor(\n private transport: LedgerTransport,\n private path: string = \"44'/1729'/0'/0'\",\n private prompt: boolean = true,\n private derivationType: DerivationType = DerivationType.ED25519\n ) {\n this.transport.setScrambleKey('XTZ');\n if (!path.startsWith(`44'/1729'`)) {\n throw new InvalidDerivationPathError(\n path,\n `${invalidDetail(ValidationResult.NO_PREFIX_MATCHED)} expecting prefix \"44'/1729'\".`\n );\n }\n if (!Object.values(DerivationType).includes(derivationType)) {\n throw new InvalidDerivationTypeError(derivationType.toString());\n }\n }\n\n async publicKeyHash(): Promise<string> {\n if (!this._publicKeyHash) {\n await this.publicKey();\n }\n if (this._publicKeyHash) {\n return this._publicKeyHash;\n }\n throw new PublicKeyHashRetrievalError();\n }\n\n async publicKey(): Promise<string> {\n if (this._publicKey) {\n return this._publicKey;\n }\n const responseLedger = await this.getLedgerPublicKey();\n const publicKeyLength = responseLedger[0];\n const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);\n const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);\n\n const prefixes = this.getPrefixes();\n const publicKey = b58cencode(compressedPublicKey, prefixes.prefPk);\n const publicKeyHash = b58cencode(hash(compressedPublicKey, 20), prefixes.prefPkh);\n\n this._publicKey = publicKey;\n this._publicKeyHash = publicKeyHash;\n return publicKey;\n }\n\n private async getLedgerPublicKey(): Promise<Buffer> {\n try {\n let ins = this.INS_PROMPT_PUBLIC_KEY;\n if (this.prompt === false) {\n ins = this.INS_GET_PUBLIC_KEY;\n }\n const responseLedger = await this.transport.send(\n this.CLA,\n ins,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n transformPathToBuffer(this.path)\n );\n return responseLedger;\n } catch (error) {\n throw new PublicKeyRetrievalError(error);\n }\n }\n\n async secretKey(): Promise<string> {\n throw new ProhibitedActionError('Secret key cannot be exposed');\n }\n\n async sign(bytes: string, watermark?: Uint8Array) {\n const watermarkedBytes = appendWatermark(bytes, watermark);\n const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');\n let messageToSend = [];\n messageToSend.push(transformPathToBuffer(this.path));\n messageToSend = chunkOperation(messageToSend, watermarkedBytes2buff);\n const ledgerResponse = await this.signWithLedger(messageToSend);\n let signature;\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');\n } else {\n if (!validateResponse(ledgerResponse)) {\n throw new InvalidLedgerResponseError(\n 'Invalid signature return by ledger unable to parse the response'\n );\n }\n const idxLengthRVal = 3; // Third element of response is length of r value\n const rValue = extractValue(idxLengthRVal, ledgerResponse);\n const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;\n const sValue = extractValue(idxLengthSVal, ledgerResponse);\n const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);\n signature = signatureBuffer.toString('hex');\n }\n\n return {\n bytes,\n sig: b58cencode(signature, prefix[Prefix.SIG]),\n prefixSig: b58cencode(signature, this.getPrefixes().prefSig),\n sbytes: bytes + signature,\n };\n }\n\n private async signWithLedger(message: Buffer[]): Promise<Buffer> {\n // first element of the message represents the path\n let ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n message[0]\n );\n for (let i = 1; i < message.length; i++) {\n const p1 =\n i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;\n ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n p1,\n this.derivationType,\n message[i]\n );\n }\n return ledgerResponse;\n }\n\n private getPrefixes() {\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n return {\n prefPk: prefix[Prefix.EDPK],\n prefPkh: prefix[Prefix.TZ1],\n prefSig: prefix[Prefix.EDSIG],\n };\n } else if (this.derivationType === DerivationType.SECP256K1) {\n return {\n prefPk: prefix[Prefix.SPPK],\n prefPkh: prefix[Prefix.TZ2],\n prefSig: prefix[Prefix.SPSIG],\n };\n } else {\n return {\n prefPk: prefix[Prefix.P2PK],\n prefPkh: prefix[Prefix.TZ3],\n prefSig: prefix[Prefix.P2SIG],\n };\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;AAGG;AAIH,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;;;;;AAMG;AACG,SAAU,qBAAqB,CAAC,IAAY,EAAA;IAChD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACnC,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,KAAI;QAC7B,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACrC,QAAA,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;YAC1B,OAAO;AACR,SAAA;AACD,QAAA,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;YAC7D,QAAQ,IAAI,UAAU,CAAC;AACxB,SAAA;AACD,QAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxB,KAAC,CAAC,CAAC;AACH,IAAA,MAA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,CAAC;AAC3B,gBAAA,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;AAC3B,gBAAA,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9B,CAAC;AACH,SAAA;KACF;AACF;;;;"}
@@ -151,40 +151,55 @@
151
151
 
152
152
  /**
153
153
  * @category Error
154
- * @description Error that indicates an invalid or unparseable ledger response
154
+ * @description Error indicates an invalid or unparseable ledger response
155
155
  */
156
- class InvalidLedgerResponseError extends Error {
156
+ class InvalidLedgerResponseError extends core.TaquitoError {
157
157
  constructor(message) {
158
- super(message);
158
+ super();
159
159
  this.message = message;
160
160
  this.name = 'InvalidLedgerResponseError';
161
161
  }
162
162
  }
163
163
  /**
164
164
  * @category Error
165
- * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
165
+ * @description Error indicates a failure when trying to retrieve a Public Key from Ledger signer
166
166
  */
167
- class PublicKeyRetrievalError extends Error {
168
- constructor() {
169
- super(`Unable to retrieve Public Key from Ledger`);
167
+ class PublicKeyRetrievalError extends core.TaquitoError {
168
+ constructor(cause) {
169
+ super();
170
+ this.cause = cause;
170
171
  this.name = 'PublicKeyRetrievalError';
172
+ this.message = `Unable to retrieve Public Key from Ledger`;
171
173
  }
172
174
  }
173
175
  /**
174
176
  * @category Error
175
- * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
177
+ * @description Error indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
176
178
  */
177
- class PublicKeyHashRetrievalError extends Error {
179
+ class PublicKeyHashRetrievalError extends core.TaquitoError {
178
180
  constructor() {
179
- super(`Unable to retrieve Public Key Hash from Ledger`);
181
+ super();
180
182
  this.name = 'PublicKeyHashRetrievalError';
183
+ this.message = 'Unable to retrieve Public Key Hash from Ledger';
184
+ }
185
+ }
186
+ /**
187
+ * @category Error
188
+ * @description Error indicates an invalid derivation type being passed or used
189
+ */
190
+ class InvalidDerivationTypeError extends core.ParameterValidationError {
191
+ constructor(derivationType) {
192
+ super();
193
+ this.derivationType = derivationType;
194
+ this.name = 'InvalidDerivationTypeError';
195
+ this.message = `Invalid derivation type ${derivationType} expecting one of the following: DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`;
181
196
  }
182
197
  }
183
198
 
184
199
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
185
200
  const VERSION = {
186
- "commitHash": "adc0f8c31492e8eb2f03b06ac36ba053e8ba6224",
187
- "version": "16.2.0"
201
+ "commitHash": "b357541c90c2168d48216d62a07de5dd3baab9a0",
202
+ "version": "17.0.0"
188
203
  };
189
204
 
190
205
  /**
@@ -198,17 +213,6 @@
198
213
  DerivationType[DerivationType["P256"] = 2] = "P256";
199
214
  DerivationType[DerivationType["BIP32_ED25519"] = 3] = "BIP32_ED25519";
200
215
  })(exports.DerivationType || (exports.DerivationType = {}));
201
- /**
202
- * @category Error
203
- * @description Error that indicates an invalid derivation type being passed or used
204
- */
205
- class InvalidDerivationTypeError extends Error {
206
- constructor(derivationType) {
207
- super(`The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`);
208
- this.derivationType = derivationType;
209
- this.name = 'InvalidDerivationTypeError';
210
- }
211
- }
212
216
  const HDPathTemplate = (account) => {
213
217
  return `44'/1729'/${account}'/0'`;
214
218
  };
@@ -258,7 +262,7 @@
258
262
  this.OTHER_MESSAGE_SEQUENCE = 0x01;
259
263
  this.transport.setScrambleKey('XTZ');
260
264
  if (!path.startsWith(`44'/1729'`)) {
261
- throw new core.InvalidDerivationPathError(path, `: Invalid prefix expecting prefix "44'/1729'".`);
265
+ throw new core.InvalidDerivationPathError(path, `${utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED)} expecting prefix "44'/1729'".`);
262
266
  }
263
267
  if (!Object.values(exports.DerivationType).includes(derivationType)) {
264
268
  throw new InvalidDerivationTypeError(derivationType.toString());
@@ -303,7 +307,7 @@
303
307
  return responseLedger;
304
308
  }
305
309
  catch (error) {
306
- throw new PublicKeyRetrievalError();
310
+ throw new PublicKeyRetrievalError(error);
307
311
  }
308
312
  });
309
313
  }
@@ -327,7 +331,7 @@
327
331
  }
328
332
  else {
329
333
  if (!validateResponse(ledgerResponse)) {
330
- throw new InvalidLedgerResponseError('Cannot parse ledger response');
334
+ throw new InvalidLedgerResponseError('Invalid signature return by ledger unable to parse the response');
331
335
  }
332
336
  const idxLengthRVal = 3; // Third element of response is length of r value
333
337
  const rValue = extractValue(idxLengthRVal, ledgerResponse);
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-ledger-signer.umd.js","sources":["../src/utils.ts","../src/error.ts","../src/version.ts","../src/taquito-ledger-signer.ts"],"sourcesContent":["/*\n * Some code in this file is adapted from sotez\n * Copyright (c) 2018 Andrew Kishino\n */\n\nimport { DerivationType } from './taquito-ledger-signer';\n\nconst MAX_CHUNK_SIZE = 230;\n\n/**\n *\n * @description Convert the path to a buffer that will be used as LC and CDATA in the APDU send to the ledger device (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n *\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @returns A buffer where the first element is the length of the path (default is 4), then 3 bytes for each number of the path to which is added 0x8000000\n */\nexport function transformPathToBuffer(path: string): Buffer {\n const result: number[] = [];\n const components = path.split('/');\n components.forEach((element) => {\n let toNumber = parseInt(element, 10);\n if (Number.isNaN(toNumber)) {\n return;\n }\n if (element.length > 1 && element[element.length - 1] === \"'\") {\n toNumber += 0x80000000;\n }\n result.push(toNumber);\n });\n const buffer = Buffer.alloc(1 + result.length * 4);\n buffer[0] = result.length;\n result.forEach((element, index) => {\n buffer.writeUInt32BE(element, 1 + 4 * index);\n });\n return buffer;\n}\n\n/**\n *\n * @description Converts uncompressed ledger key to standard tezos binary representation\n */\nexport function compressPublicKey(publicKey: Buffer, curve: DerivationType) {\n if (curve === 0x00 || curve === 0x03) {\n publicKey = publicKey.slice(1);\n } else {\n publicKey[0] = 0x02 + (publicKey[64] & 0x01);\n publicKey = publicKey.slice(0, 33);\n }\n return publicKey;\n}\n\nexport function appendWatermark(bytes: string, watermark?: Uint8Array): string {\n let transactionHex = bytes;\n if (typeof watermark !== 'undefined') {\n const hexWatermark = Buffer.from(watermark).toString('hex');\n transactionHex = hexWatermark.concat(bytes);\n }\n return transactionHex;\n}\n\n/**\n *\n * @description In order not to exceed the data length allowed by the Ledger device, split the operation into buffers of 230 bytes (max) and add them to the message to send to the Ledger\n * @param messageToSend The message to send to the Ledger device\n * @param operation The operation which will be chunk if its length is over 230 bytes\n * @returns The instruction to send to the Ledger device\n */\nexport function chunkOperation(messageToSend: any, operation: Buffer) {\n let offset = 0;\n while (offset !== operation.length) {\n const chunkSize =\n offset + MAX_CHUNK_SIZE >= operation.length ? operation.length - offset : MAX_CHUNK_SIZE;\n const buff = Buffer.alloc(chunkSize);\n operation.copy(buff, 0, offset, offset + chunkSize);\n messageToSend.push(buff);\n offset += chunkSize;\n }\n return messageToSend;\n}\n\n/**\n *\n * @description Verify if the signature returned by the ledger for tz2 and tz3 is valid\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns True if valid, false otherwise\n */\nexport function validateResponse(response: Buffer): boolean {\n let valid = true;\n if (response[0] !== 0x31 && response[0] !== 0x30) {\n valid = false;\n }\n if (response[1] + 4 !== response.length) {\n valid = false;\n }\n if (response[2] !== 0x02) {\n valid = false;\n }\n const rLength = response[3];\n if (response[4 + rLength] !== 0x02) {\n valid = false;\n }\n\n const idxLengthSVal = 5 + rLength;\n const sLength = response[idxLengthSVal];\n if (idxLengthSVal + 1 + sLength + 2 !== response.length) {\n valid = false;\n }\n return valid;\n}\n\n/**\n *\n * @description Extract a part of the response returned by the Ledger\n * @param idxLength The index in the response from the Ledger that corresponds to the length of the part to extract\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns An object that contains the extracted buffer, the index where it starts in the response and the length of the extracted part\n */\nexport function extractValue(idxLength: number, response: Buffer) {\n const buffer = Buffer.alloc(32);\n buffer.fill(0);\n\n let length = response[idxLength];\n let idxValueStart = idxLength + 1;\n if (length > 32) {\n idxValueStart += length - 32;\n length = 32;\n }\n response.copy(buffer, 32 - length, idxValueStart, idxValueStart + length);\n return { buffer, idxValueStart, length };\n}\n","/**\n * @category Error\n * @description Error that indicates an invalid or unparseable ledger response\n */\nexport class InvalidLedgerResponseError extends Error {\n public name = 'InvalidLedgerResponseError';\n constructor(public message: string) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer\n */\nexport class PublicKeyRetrievalError extends Error {\n public name = 'PublicKeyRetrievalError';\n constructor() {\n super(`Unable to retrieve Public Key from Ledger`);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer\n */\nexport class PublicKeyHashRetrievalError extends Error {\n public name = 'PublicKeyHashRetrievalError';\n constructor() {\n super(`Unable to retrieve Public Key Hash from Ledger`);\n }\n}\n","\n// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"adc0f8c31492e8eb2f03b06ac36ba053e8ba6224\",\n \"version\": \"16.2.0\"\n};\n","/**\n * @packageDocumentation\n * @module @taquito/ledger-signer\n */\n\nimport { Signer } from '@taquito/taquito';\nimport Transport from '@ledgerhq/hw-transport';\nimport { b58cencode, prefix, Prefix } from '@taquito/utils';\nimport {\n appendWatermark,\n transformPathToBuffer,\n compressPublicKey,\n chunkOperation,\n validateResponse,\n extractValue,\n} from './utils';\nimport { hash } from '@stablelib/blake2b';\nimport {\n PublicKeyHashRetrievalError,\n PublicKeyRetrievalError,\n InvalidLedgerResponseError,\n} from './error';\nimport { InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';\n\nexport { InvalidDerivationPathError } from '@taquito/core';\n\nexport type LedgerTransport = Pick<Transport, 'send' | 'decorateAppAPIMethods' | 'setScrambleKey'>;\n\nexport enum DerivationType {\n ED25519 = 0x00, // tz1\n SECP256K1 = 0x01, // tz2\n P256 = 0x02, // tz3\n BIP32_ED25519 = 0x03, // tz1 BIP32\n}\n\n/**\n * @category Error\n * @description Error that indicates an invalid derivation type being passed or used\n */\nexport class InvalidDerivationTypeError extends Error {\n public name = 'InvalidDerivationTypeError';\n constructor(public derivationType: string) {\n super(\n `The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`\n );\n }\n}\n\nexport const HDPathTemplate = (account: number) => {\n return `44'/1729'/${account}'/0'`;\n};\n\nexport { VERSION } from './version';\n\n/**\n *\n * @description Implementation of the Signer interface that will allow signing operation from a Ledger Nano device\n *\n * @param transport A transport instance from LedgerJS libraries depending on the platform used (e.g. Web, Node)\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @param prompt Whether to prompt the ledger for public key (default is true)\n * @param derivationType The value which defines the curve to use (DerivationType.ED25519(default), DerivationType.SECP256K1, DerivationType.P256, DerivationType.BIP32_ED25519)\n *\n * @example\n * ```\n * import TransportNodeHid from \"@ledgerhq/hw-transport-node-hid\";\n * const transport = await TransportNodeHid.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", false, DerivationType.ED25519);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", true, DerivationType.SECP256K1);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/6'/0'\", true, DerivationType.BIP32_ED25519);\n * ```\n */\nexport class LedgerSigner implements Signer {\n // constants for APDU requests (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n private readonly CLA = 0x80; // Instruction class (always 0x80)\n private readonly INS_GET_PUBLIC_KEY = 0x02; // Instruction code to get the ledger’s internal public key without prompt\n private readonly INS_PROMPT_PUBLIC_KEY = 0x03; // Instruction code to get the ledger’s internal public key with prompt\n private readonly INS_SIGN = 0x04; // Sign a message with the ledger’s key\n private readonly FIRST_MESSAGE_SEQUENCE = 0x00;\n private readonly LAST_MESSAGE_SEQUENCE = 0x81;\n private readonly OTHER_MESSAGE_SEQUENCE = 0x01;\n\n private _publicKey?: string;\n private _publicKeyHash?: string;\n constructor(\n private transport: LedgerTransport,\n private path: string = \"44'/1729'/0'/0'\",\n private prompt: boolean = true,\n private derivationType: DerivationType = DerivationType.ED25519\n ) {\n this.transport.setScrambleKey('XTZ');\n if (!path.startsWith(`44'/1729'`)) {\n throw new InvalidDerivationPathError(path, `: Invalid prefix expecting prefix \"44'/1729'\".`);\n }\n if (!Object.values(DerivationType).includes(derivationType)) {\n throw new InvalidDerivationTypeError(derivationType.toString());\n }\n }\n\n async publicKeyHash(): Promise<string> {\n if (!this._publicKeyHash) {\n await this.publicKey();\n }\n if (this._publicKeyHash) {\n return this._publicKeyHash;\n }\n throw new PublicKeyHashRetrievalError();\n }\n\n async publicKey(): Promise<string> {\n if (this._publicKey) {\n return this._publicKey;\n }\n const responseLedger = await this.getLedgerPublicKey();\n const publicKeyLength = responseLedger[0];\n const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);\n const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);\n\n const prefixes = this.getPrefixes();\n const publicKey = b58cencode(compressedPublicKey, prefixes.prefPk);\n const publicKeyHash = b58cencode(hash(compressedPublicKey, 20), prefixes.prefPkh);\n\n this._publicKey = publicKey;\n this._publicKeyHash = publicKeyHash;\n return publicKey;\n }\n\n private async getLedgerPublicKey(): Promise<Buffer> {\n try {\n let ins = this.INS_PROMPT_PUBLIC_KEY;\n if (this.prompt === false) {\n ins = this.INS_GET_PUBLIC_KEY;\n }\n const responseLedger = await this.transport.send(\n this.CLA,\n ins,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n transformPathToBuffer(this.path)\n );\n return responseLedger;\n } catch (error) {\n throw new PublicKeyRetrievalError();\n }\n }\n\n async secretKey(): Promise<string> {\n throw new ProhibitedActionError('Secret key cannot be exposed');\n }\n\n async sign(bytes: string, watermark?: Uint8Array) {\n const watermarkedBytes = appendWatermark(bytes, watermark);\n const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');\n let messageToSend = [];\n messageToSend.push(transformPathToBuffer(this.path));\n messageToSend = chunkOperation(messageToSend, watermarkedBytes2buff);\n const ledgerResponse = await this.signWithLedger(messageToSend);\n let signature;\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');\n } else {\n if (!validateResponse(ledgerResponse)) {\n throw new InvalidLedgerResponseError('Cannot parse ledger response');\n }\n const idxLengthRVal = 3; // Third element of response is length of r value\n const rValue = extractValue(idxLengthRVal, ledgerResponse);\n const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;\n const sValue = extractValue(idxLengthSVal, ledgerResponse);\n const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);\n signature = signatureBuffer.toString('hex');\n }\n\n return {\n bytes,\n sig: b58cencode(signature, prefix[Prefix.SIG]),\n prefixSig: b58cencode(signature, this.getPrefixes().prefSig),\n sbytes: bytes + signature,\n };\n }\n\n private async signWithLedger(message: Buffer[]): Promise<Buffer> {\n // first element of the message represents the path\n let ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n message[0]\n );\n for (let i = 1; i < message.length; i++) {\n const p1 =\n i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;\n ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n p1,\n this.derivationType,\n message[i]\n );\n }\n return ledgerResponse;\n }\n\n private getPrefixes() {\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n return {\n prefPk: prefix[Prefix.EDPK],\n prefPkh: prefix[Prefix.TZ1],\n prefSig: prefix[Prefix.EDSIG],\n };\n } else if (this.derivationType === DerivationType.SECP256K1) {\n return {\n prefPk: prefix[Prefix.SPPK],\n prefPkh: prefix[Prefix.TZ2],\n prefSig: prefix[Prefix.SPSIG],\n };\n } else {\n return {\n prefPk: prefix[Prefix.P2PK],\n prefPkh: prefix[Prefix.TZ3],\n prefSig: prefix[Prefix.P2SIG],\n };\n }\n }\n}\n"],"names":["DerivationType","InvalidDerivationPathError","b58cencode","hash","ProhibitedActionError","prefix","Prefix"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;;IAGG;IAIH,MAAM,cAAc,GAAG,GAAG,CAAC;IAE3B;;;;;;IAMG;IACG,SAAU,qBAAqB,CAAC,IAAY,EAAA;QAChD,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,KAAI;YAC7B,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrC,QAAA,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBAC1B,OAAO;IACR,SAAA;IACD,QAAA,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC7D,QAAQ,IAAI,UAAU,CAAC;IACxB,SAAA;IACD,QAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxB,KAAC,CAAC,CA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AA;SACF;IACF;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"taquito-ledger-signer.umd.js","sources":["../src/utils.ts","../src/errors.ts","../src/version.ts","../src/taquito-ledger-signer.ts"],"sourcesContent":["/*\n * Some code in this file is adapted from sotez\n * Copyright (c) 2018 Andrew Kishino\n */\n\nimport { DerivationType } from './taquito-ledger-signer';\n\nconst MAX_CHUNK_SIZE = 230;\n\n/**\n *\n * @description Convert the path to a buffer that will be used as LC and CDATA in the APDU send to the ledger device (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n *\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @returns A buffer where the first element is the length of the path (default is 4), then 3 bytes for each number of the path to which is added 0x8000000\n */\nexport function transformPathToBuffer(path: string): Buffer {\n const result: number[] = [];\n const components = path.split('/');\n components.forEach((element) => {\n let toNumber = parseInt(element, 10);\n if (Number.isNaN(toNumber)) {\n return;\n }\n if (element.length > 1 && element[element.length - 1] === \"'\") {\n toNumber += 0x80000000;\n }\n result.push(toNumber);\n });\n const buffer = Buffer.alloc(1 + result.length * 4);\n buffer[0] = result.length;\n result.forEach((element, index) => {\n buffer.writeUInt32BE(element, 1 + 4 * index);\n });\n return buffer;\n}\n\n/**\n *\n * @description Converts uncompressed ledger key to standard tezos binary representation\n */\nexport function compressPublicKey(publicKey: Buffer, curve: DerivationType) {\n if (curve === 0x00 || curve === 0x03) {\n publicKey = publicKey.slice(1);\n } else {\n publicKey[0] = 0x02 + (publicKey[64] & 0x01);\n publicKey = publicKey.slice(0, 33);\n }\n return publicKey;\n}\n\nexport function appendWatermark(bytes: string, watermark?: Uint8Array): string {\n let transactionHex = bytes;\n if (typeof watermark !== 'undefined') {\n const hexWatermark = Buffer.from(watermark).toString('hex');\n transactionHex = hexWatermark.concat(bytes);\n }\n return transactionHex;\n}\n\n/**\n *\n * @description In order not to exceed the data length allowed by the Ledger device, split the operation into buffers of 230 bytes (max) and add them to the message to send to the Ledger\n * @param messageToSend The message to send to the Ledger device\n * @param operation The operation which will be chunk if its length is over 230 bytes\n * @returns The instruction to send to the Ledger device\n */\nexport function chunkOperation(messageToSend: any, operation: Buffer) {\n let offset = 0;\n while (offset !== operation.length) {\n const chunkSize =\n offset + MAX_CHUNK_SIZE >= operation.length ? operation.length - offset : MAX_CHUNK_SIZE;\n const buff = Buffer.alloc(chunkSize);\n operation.copy(buff, 0, offset, offset + chunkSize);\n messageToSend.push(buff);\n offset += chunkSize;\n }\n return messageToSend;\n}\n\n/**\n *\n * @description Verify if the signature returned by the ledger for tz2 and tz3 is valid\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns True if valid, false otherwise\n */\nexport function validateResponse(response: Buffer): boolean {\n let valid = true;\n if (response[0] !== 0x31 && response[0] !== 0x30) {\n valid = false;\n }\n if (response[1] + 4 !== response.length) {\n valid = false;\n }\n if (response[2] !== 0x02) {\n valid = false;\n }\n const rLength = response[3];\n if (response[4 + rLength] !== 0x02) {\n valid = false;\n }\n\n const idxLengthSVal = 5 + rLength;\n const sLength = response[idxLengthSVal];\n if (idxLengthSVal + 1 + sLength + 2 !== response.length) {\n valid = false;\n }\n return valid;\n}\n\n/**\n *\n * @description Extract a part of the response returned by the Ledger\n * @param idxLength The index in the response from the Ledger that corresponds to the length of the part to extract\n * @param response The signature returned by the Ledger (return from the signWithLedger function)\n * @returns An object that contains the extracted buffer, the index where it starts in the response and the length of the extracted part\n */\nexport function extractValue(idxLength: number, response: Buffer) {\n const buffer = Buffer.alloc(32);\n buffer.fill(0);\n\n let length = response[idxLength];\n let idxValueStart = idxLength + 1;\n if (length > 32) {\n idxValueStart += length - 32;\n length = 32;\n }\n response.copy(buffer, 32 - length, idxValueStart, idxValueStart + length);\n return { buffer, idxValueStart, length };\n}\n","import { ParameterValidationError, TaquitoError } from '@taquito/core';\n\n/**\n * @category Error\n * @description Error indicates an invalid or unparseable ledger response\n */\nexport class InvalidLedgerResponseError extends TaquitoError {\n constructor(public message: string) {\n super();\n this.name = 'InvalidLedgerResponseError';\n }\n}\n\n/**\n * @category Error\n * @description Error indicates a failure when trying to retrieve a Public Key from Ledger signer\n */\nexport class PublicKeyRetrievalError extends TaquitoError {\n constructor(public cause: any) {\n super();\n this.name = 'PublicKeyRetrievalError';\n this.message = `Unable to retrieve Public Key from Ledger`;\n }\n}\n\n/**\n * @category Error\n * @description Error indicates a failure when trying to retrieve a Public Key Hash from Ledger signer\n */\nexport class PublicKeyHashRetrievalError extends TaquitoError {\n constructor() {\n super();\n this.name = 'PublicKeyHashRetrievalError';\n this.message = 'Unable to retrieve Public Key Hash from Ledger';\n }\n}\n\n/**\n * @category Error\n * @description Error indicates an invalid derivation type being passed or used\n */\nexport class InvalidDerivationTypeError extends ParameterValidationError {\n constructor(public derivationType: string) {\n super();\n this.name = 'InvalidDerivationTypeError';\n this.message = `Invalid derivation type ${derivationType} expecting one of the following: DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`;\n }\n}\n","\n// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"b357541c90c2168d48216d62a07de5dd3baab9a0\",\n \"version\": \"17.0.0\"\n};\n","/**\n * @packageDocumentation\n * @module @taquito/ledger-signer\n */\n\nimport { Signer } from '@taquito/taquito';\nimport Transport from '@ledgerhq/hw-transport';\nimport { b58cencode, invalidDetail, prefix, Prefix, ValidationResult } from '@taquito/utils';\nimport {\n appendWatermark,\n transformPathToBuffer,\n compressPublicKey,\n chunkOperation,\n validateResponse,\n extractValue,\n} from './utils';\nimport { hash } from '@stablelib/blake2b';\nimport {\n PublicKeyHashRetrievalError,\n PublicKeyRetrievalError,\n InvalidLedgerResponseError,\n InvalidDerivationTypeError,\n} from './errors';\nimport { InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';\n\nexport { InvalidDerivationPathError } from '@taquito/core';\n\nexport type LedgerTransport = Pick<Transport, 'send' | 'decorateAppAPIMethods' | 'setScrambleKey'>;\n\nexport enum DerivationType {\n ED25519 = 0x00, // tz1\n SECP256K1 = 0x01, // tz2\n P256 = 0x02, // tz3\n BIP32_ED25519 = 0x03, // tz1 BIP32\n}\n\nexport { InvalidDerivationTypeError } from './errors';\n\nexport const HDPathTemplate = (account: number) => {\n return `44'/1729'/${account}'/0'`;\n};\n\nexport { VERSION } from './version';\n\n/**\n *\n * @description Implementation of the Signer interface that will allow signing operation from a Ledger Nano device\n *\n * @param transport A transport instance from LedgerJS libraries depending on the platform used (e.g. Web, Node)\n * @param path The ledger derivation path (default is \"44'/1729'/0'/0'\")\n * @param prompt Whether to prompt the ledger for public key (default is true)\n * @param derivationType The value which defines the curve to use (DerivationType.ED25519(default), DerivationType.SECP256K1, DerivationType.P256, DerivationType.BIP32_ED25519)\n *\n * @example\n * ```\n * import TransportNodeHid from \"@ledgerhq/hw-transport-node-hid\";\n * const transport = await TransportNodeHid.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", false, DerivationType.ED25519);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", true, DerivationType.SECP256K1);\n * ```\n *\n * @example\n * ```\n * import TransportU2F from \"@ledgerhq/hw-transport-u2f\";\n * const transport = await TransportU2F.create();\n * const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/6'/0'\", true, DerivationType.BIP32_ED25519);\n * ```\n */\nexport class LedgerSigner implements Signer {\n // constants for APDU requests (https://github.com/obsidiansystems/ledger-app-tezos/blob/master/APDUs.md)\n private readonly CLA = 0x80; // Instruction class (always 0x80)\n private readonly INS_GET_PUBLIC_KEY = 0x02; // Instruction code to get the ledger’s internal public key without prompt\n private readonly INS_PROMPT_PUBLIC_KEY = 0x03; // Instruction code to get the ledger’s internal public key with prompt\n private readonly INS_SIGN = 0x04; // Sign a message with the ledger’s key\n private readonly FIRST_MESSAGE_SEQUENCE = 0x00;\n private readonly LAST_MESSAGE_SEQUENCE = 0x81;\n private readonly OTHER_MESSAGE_SEQUENCE = 0x01;\n\n private _publicKey?: string;\n private _publicKeyHash?: string;\n constructor(\n private transport: LedgerTransport,\n private path: string = \"44'/1729'/0'/0'\",\n private prompt: boolean = true,\n private derivationType: DerivationType = DerivationType.ED25519\n ) {\n this.transport.setScrambleKey('XTZ');\n if (!path.startsWith(`44'/1729'`)) {\n throw new InvalidDerivationPathError(\n path,\n `${invalidDetail(ValidationResult.NO_PREFIX_MATCHED)} expecting prefix \"44'/1729'\".`\n );\n }\n if (!Object.values(DerivationType).includes(derivationType)) {\n throw new InvalidDerivationTypeError(derivationType.toString());\n }\n }\n\n async publicKeyHash(): Promise<string> {\n if (!this._publicKeyHash) {\n await this.publicKey();\n }\n if (this._publicKeyHash) {\n return this._publicKeyHash;\n }\n throw new PublicKeyHashRetrievalError();\n }\n\n async publicKey(): Promise<string> {\n if (this._publicKey) {\n return this._publicKey;\n }\n const responseLedger = await this.getLedgerPublicKey();\n const publicKeyLength = responseLedger[0];\n const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);\n const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);\n\n const prefixes = this.getPrefixes();\n const publicKey = b58cencode(compressedPublicKey, prefixes.prefPk);\n const publicKeyHash = b58cencode(hash(compressedPublicKey, 20), prefixes.prefPkh);\n\n this._publicKey = publicKey;\n this._publicKeyHash = publicKeyHash;\n return publicKey;\n }\n\n private async getLedgerPublicKey(): Promise<Buffer> {\n try {\n let ins = this.INS_PROMPT_PUBLIC_KEY;\n if (this.prompt === false) {\n ins = this.INS_GET_PUBLIC_KEY;\n }\n const responseLedger = await this.transport.send(\n this.CLA,\n ins,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n transformPathToBuffer(this.path)\n );\n return responseLedger;\n } catch (error) {\n throw new PublicKeyRetrievalError(error);\n }\n }\n\n async secretKey(): Promise<string> {\n throw new ProhibitedActionError('Secret key cannot be exposed');\n }\n\n async sign(bytes: string, watermark?: Uint8Array) {\n const watermarkedBytes = appendWatermark(bytes, watermark);\n const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');\n let messageToSend = [];\n messageToSend.push(transformPathToBuffer(this.path));\n messageToSend = chunkOperation(messageToSend, watermarkedBytes2buff);\n const ledgerResponse = await this.signWithLedger(messageToSend);\n let signature;\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');\n } else {\n if (!validateResponse(ledgerResponse)) {\n throw new InvalidLedgerResponseError(\n 'Invalid signature return by ledger unable to parse the response'\n );\n }\n const idxLengthRVal = 3; // Third element of response is length of r value\n const rValue = extractValue(idxLengthRVal, ledgerResponse);\n const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;\n const sValue = extractValue(idxLengthSVal, ledgerResponse);\n const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);\n signature = signatureBuffer.toString('hex');\n }\n\n return {\n bytes,\n sig: b58cencode(signature, prefix[Prefix.SIG]),\n prefixSig: b58cencode(signature, this.getPrefixes().prefSig),\n sbytes: bytes + signature,\n };\n }\n\n private async signWithLedger(message: Buffer[]): Promise<Buffer> {\n // first element of the message represents the path\n let ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n this.FIRST_MESSAGE_SEQUENCE,\n this.derivationType,\n message[0]\n );\n for (let i = 1; i < message.length; i++) {\n const p1 =\n i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;\n ledgerResponse = await this.transport.send(\n this.CLA,\n this.INS_SIGN,\n p1,\n this.derivationType,\n message[i]\n );\n }\n return ledgerResponse;\n }\n\n private getPrefixes() {\n if (\n this.derivationType === DerivationType.ED25519 ||\n this.derivationType === DerivationType.BIP32_ED25519\n ) {\n return {\n prefPk: prefix[Prefix.EDPK],\n prefPkh: prefix[Prefix.TZ1],\n prefSig: prefix[Prefix.EDSIG],\n };\n } else if (this.derivationType === DerivationType.SECP256K1) {\n return {\n prefPk: prefix[Prefix.SPPK],\n prefPkh: prefix[Prefix.TZ2],\n prefSig: prefix[Prefix.SPSIG],\n };\n } else {\n return {\n prefPk: prefix[Prefix.P2PK],\n prefPkh: prefix[Prefix.TZ3],\n prefSig: prefix[Prefix.P2SIG],\n };\n }\n }\n}\n"],"names":["TaquitoError","ParameterValidationError","DerivationType","InvalidDerivationPathError","invalidDetail","ValidationResult","b58cencode","hash","ProhibitedActionError","prefix","Prefix"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;;IAGG;IAIH,MAAM,cAAc,GAAG,GAAG,CAAC;IAE3B;;;;;;IAMG;IACG,SAAU,qBAAqB,CAAC,IAAY,EAAA;QAChD,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,KAAI;YAC7B,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrC,QAAA,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBAC1B,OAAO;IACR,SAAA;IACD,QAAA,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC7D,QAAQ,IAAI,UAAU,CAAC;IACxB,SAAA;IACD,QAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxB,KAAC,CAAC,CAAC;IACH,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,IAAA,MAAM,CAAC,C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AM,CAAC,GAAG,CAAC;IAC3B,gBAAA,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,KAAK,CAAC;iBAC9B,CAAC;IACH,SAAA;SACF;IACF;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,32 @@
1
+ import { ParameterValidationError, TaquitoError } from '@taquito/core';
2
+ /**
3
+ * @category Error
4
+ * @description Error indicates an invalid or unparseable ledger response
5
+ */
6
+ export declare class InvalidLedgerResponseError extends TaquitoError {
7
+ message: string;
8
+ constructor(message: string);
9
+ }
10
+ /**
11
+ * @category Error
12
+ * @description Error indicates a failure when trying to retrieve a Public Key from Ledger signer
13
+ */
14
+ export declare class PublicKeyRetrievalError extends TaquitoError {
15
+ cause: any;
16
+ constructor(cause: any);
17
+ }
18
+ /**
19
+ * @category Error
20
+ * @description Error indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
21
+ */
22
+ export declare class PublicKeyHashRetrievalError extends TaquitoError {
23
+ constructor();
24
+ }
25
+ /**
26
+ * @category Error
27
+ * @description Error indicates an invalid derivation type being passed or used
28
+ */
29
+ export declare class InvalidDerivationTypeError extends ParameterValidationError {
30
+ derivationType: string;
31
+ constructor(derivationType: string);
32
+ }
@@ -12,15 +12,7 @@ export declare enum DerivationType {
12
12
  P256 = 2,
13
13
  BIP32_ED25519 = 3
14
14
  }
15
- /**
16
- * @category Error
17
- * @description Error that indicates an invalid derivation type being passed or used
18
- */
19
- export declare class InvalidDerivationTypeError extends Error {
20
- derivationType: string;
21
- name: string;
22
- constructor(derivationType: string);
23
- }
15
+ export { InvalidDerivationTypeError } from './errors';
24
16
  export declare const HDPathTemplate: (account: number) => string;
25
17
  export { VERSION } from './version';
26
18
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taquito/ledger-signer",
3
- "version": "16.2.0",
3
+ "version": "17.0.0",
4
4
  "description": "Ledger signer provider",
5
5
  "keywords": [
6
6
  "tezos",
@@ -60,8 +60,8 @@
60
60
  "dependencies": {
61
61
  "@ledgerhq/hw-transport": "^6.27.3",
62
62
  "@stablelib/blake2b": "^1.0.1",
63
- "@taquito/taquito": "^16.2.0",
64
- "@taquito/utils": "^16.2.0",
63
+ "@taquito/taquito": "^17.0.0",
64
+ "@taquito/utils": "^17.0.0",
65
65
  "buffer": "^6.0.3"
66
66
  },
67
67
  "devDependencies": {
@@ -93,5 +93,5 @@
93
93
  "ts-toolbelt": "^9.6.0",
94
94
  "typescript": "~4.1.5"
95
95
  },
96
- "gitHead": "148b11675d2c3d3a10ce20c02dcece388ef59414"
96
+ "gitHead": "388db853edd4d45c1e6e0121a96fa9b71fa699c0"
97
97
  }
package/src/errors.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { ParameterValidationError, TaquitoError } from '@taquito/core';
2
+
3
+ /**
4
+ * @category Error
5
+ * @description Error indicates an invalid or unparseable ledger response
6
+ */
7
+ export class InvalidLedgerResponseError extends TaquitoError {
8
+ constructor(public message: string) {
9
+ super();
10
+ this.name = 'InvalidLedgerResponseError';
11
+ }
12
+ }
13
+
14
+ /**
15
+ * @category Error
16
+ * @description Error indicates a failure when trying to retrieve a Public Key from Ledger signer
17
+ */
18
+ export class PublicKeyRetrievalError extends TaquitoError {
19
+ constructor(public cause: any) {
20
+ super();
21
+ this.name = 'PublicKeyRetrievalError';
22
+ this.message = `Unable to retrieve Public Key from Ledger`;
23
+ }
24
+ }
25
+
26
+ /**
27
+ * @category Error
28
+ * @description Error indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
29
+ */
30
+ export class PublicKeyHashRetrievalError extends TaquitoError {
31
+ constructor() {
32
+ super();
33
+ this.name = 'PublicKeyHashRetrievalError';
34
+ this.message = 'Unable to retrieve Public Key Hash from Ledger';
35
+ }
36
+ }
37
+
38
+ /**
39
+ * @category Error
40
+ * @description Error indicates an invalid derivation type being passed or used
41
+ */
42
+ export class InvalidDerivationTypeError extends ParameterValidationError {
43
+ constructor(public derivationType: string) {
44
+ super();
45
+ this.name = 'InvalidDerivationTypeError';
46
+ this.message = `Invalid derivation type ${derivationType} expecting one of the following: DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`;
47
+ }
48
+ }
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { Signer } from '@taquito/taquito';
7
7
  import Transport from '@ledgerhq/hw-transport';
8
- import { b58cencode, prefix, Prefix } from '@taquito/utils';
8
+ import { b58cencode, invalidDetail, prefix, Prefix, ValidationResult } from '@taquito/utils';
9
9
  import {
10
10
  appendWatermark,
11
11
  transformPathToBuffer,
@@ -19,7 +19,8 @@ import {
19
19
  PublicKeyHashRetrievalError,
20
20
  PublicKeyRetrievalError,
21
21
  InvalidLedgerResponseError,
22
- } from './error';
22
+ InvalidDerivationTypeError,
23
+ } from './errors';
23
24
  import { InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';
24
25
 
25
26
  export { InvalidDerivationPathError } from '@taquito/core';
@@ -33,18 +34,7 @@ export enum DerivationType {
33
34
  BIP32_ED25519 = 0x03, // tz1 BIP32
34
35
  }
35
36
 
36
- /**
37
- * @category Error
38
- * @description Error that indicates an invalid derivation type being passed or used
39
- */
40
- export class InvalidDerivationTypeError extends Error {
41
- public name = 'InvalidDerivationTypeError';
42
- constructor(public derivationType: string) {
43
- super(
44
- `The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1, DerivationType.P256 or DerivationType.BIP32_ED25519`
45
- );
46
- }
47
- }
37
+ export { InvalidDerivationTypeError } from './errors';
48
38
 
49
39
  export const HDPathTemplate = (account: number) => {
50
40
  return `44'/1729'/${account}'/0'`;
@@ -102,7 +92,10 @@ export class LedgerSigner implements Signer {
102
92
  ) {
103
93
  this.transport.setScrambleKey('XTZ');
104
94
  if (!path.startsWith(`44'/1729'`)) {
105
- throw new InvalidDerivationPathError(path, `: Invalid prefix expecting prefix "44'/1729'".`);
95
+ throw new InvalidDerivationPathError(
96
+ path,
97
+ `${invalidDetail(ValidationResult.NO_PREFIX_MATCHED)} expecting prefix "44'/1729'".`
98
+ );
106
99
  }
107
100
  if (!Object.values(DerivationType).includes(derivationType)) {
108
101
  throw new InvalidDerivationTypeError(derivationType.toString());
@@ -152,7 +145,7 @@ export class LedgerSigner implements Signer {
152
145
  );
153
146
  return responseLedger;
154
147
  } catch (error) {
155
- throw new PublicKeyRetrievalError();
148
+ throw new PublicKeyRetrievalError(error);
156
149
  }
157
150
  }
158
151
 
@@ -175,7 +168,9 @@ export class LedgerSigner implements Signer {
175
168
  signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');
176
169
  } else {
177
170
  if (!validateResponse(ledgerResponse)) {
178
- throw new InvalidLedgerResponseError('Cannot parse ledger response');
171
+ throw new InvalidLedgerResponseError(
172
+ 'Invalid signature return by ledger unable to parse the response'
173
+ );
179
174
  }
180
175
  const idxLengthRVal = 3; // Third element of response is length of r value
181
176
  const rValue = extractValue(idxLengthRVal, ledgerResponse);
package/src/version.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
2
2
  export const VERSION = {
3
- commitHash: 'adc0f8c31492e8eb2f03b06ac36ba053e8ba6224',
4
- version: '16.2.0',
3
+ commitHash: 'b357541c90c2168d48216d62a07de5dd3baab9a0',
4
+ version: '17.0.0',
5
5
  };
@@ -29,7 +29,7 @@ describe('LedgerSigner test', () => {
29
29
  expect(() => {
30
30
  new LedgerSigner(mockTransport, "4'/1729'/0'/0'", true, DerivationType.SECP256K1);
31
31
  }).toThrow(
32
- `Invalid derivation path "4'/1729'/0'/0'": Invalid prefix expecting prefix "44'/1729'".`
32
+ `Invalid derivation path "4'/1729'/0'/0'" with unsupported prefix expecting prefix "44'/1729'".`
33
33
  );
34
34
  });
35
35
 
package/dist/lib/error.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PublicKeyHashRetrievalError = exports.PublicKeyRetrievalError = exports.InvalidLedgerResponseError = void 0;
4
- /**
5
- * @category Error
6
- * @description Error that indicates an invalid or unparseable ledger response
7
- */
8
- class InvalidLedgerResponseError extends Error {
9
- constructor(message) {
10
- super(message);
11
- this.message = message;
12
- this.name = 'InvalidLedgerResponseError';
13
- }
14
- }
15
- exports.InvalidLedgerResponseError = InvalidLedgerResponseError;
16
- /**
17
- * @category Error
18
- * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
19
- */
20
- class PublicKeyRetrievalError extends Error {
21
- constructor() {
22
- super(`Unable to retrieve Public Key from Ledger`);
23
- this.name = 'PublicKeyRetrievalError';
24
- }
25
- }
26
- exports.PublicKeyRetrievalError = PublicKeyRetrievalError;
27
- /**
28
- * @category Error
29
- * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
30
- */
31
- class PublicKeyHashRetrievalError extends Error {
32
- constructor() {
33
- super(`Unable to retrieve Public Key Hash from Ledger`);
34
- this.name = 'PublicKeyHashRetrievalError';
35
- }
36
- }
37
- exports.PublicKeyHashRetrievalError = PublicKeyHashRetrievalError;
38
- //# sourceMappingURL=error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IAEnD,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAQ;QAD3B,SAAI,GAAG,4BAA4B,CAAC;IAG3C,CAAC;CACF;AALD,gEAKC;AAED;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAEhD;QACE,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAF9C,SAAI,GAAG,yBAAyB,CAAC;IAGxC,CAAC;CACF;AALD,0DAKC;AAED;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,KAAK;IAEpD;QACE,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAFnD,SAAI,GAAG,6BAA6B,CAAC;IAG5C,CAAC;CACF;AALD,kEAKC"}
@@ -1,25 +0,0 @@
1
- /**
2
- * @category Error
3
- * @description Error that indicates an invalid or unparseable ledger response
4
- */
5
- export declare class InvalidLedgerResponseError extends Error {
6
- message: string;
7
- name: string;
8
- constructor(message: string);
9
- }
10
- /**
11
- * @category Error
12
- * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
13
- */
14
- export declare class PublicKeyRetrievalError extends Error {
15
- name: string;
16
- constructor();
17
- }
18
- /**
19
- * @category Error
20
- * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
21
- */
22
- export declare class PublicKeyHashRetrievalError extends Error {
23
- name: string;
24
- constructor();
25
- }
package/src/error.ts DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * @category Error
3
- * @description Error that indicates an invalid or unparseable ledger response
4
- */
5
- export class InvalidLedgerResponseError extends Error {
6
- public name = 'InvalidLedgerResponseError';
7
- constructor(public message: string) {
8
- super(message);
9
- }
10
- }
11
-
12
- /**
13
- * @category Error
14
- * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
15
- */
16
- export class PublicKeyRetrievalError extends Error {
17
- public name = 'PublicKeyRetrievalError';
18
- constructor() {
19
- super(`Unable to retrieve Public Key from Ledger`);
20
- }
21
- }
22
-
23
- /**
24
- * @category Error
25
- * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
26
- */
27
- export class PublicKeyHashRetrievalError extends Error {
28
- public name = 'PublicKeyHashRetrievalError';
29
- constructor() {
30
- super(`Unable to retrieve Public Key Hash from Ledger`);
31
- }
32
- }