@taquito/ledger-signer 12.0.2 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
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
@@ -0,0 +1 @@
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"}
@@ -13,16 +13,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  });
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.LedgerSigner = exports.VERSION = exports.HDPathTemplate = exports.DerivationType = void 0;
16
+ exports.LedgerSigner = exports.VERSION = exports.HDPathTemplate = exports.InvalidDerivationPathError = exports.InvalidDerivationTypeError = exports.DerivationType = void 0;
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
21
  var DerivationType;
21
22
  (function (DerivationType) {
22
23
  DerivationType[DerivationType["ED25519"] = 0] = "ED25519";
23
24
  DerivationType[DerivationType["SECP256K1"] = 1] = "SECP256K1";
24
25
  DerivationType[DerivationType["P256"] = 2] = "P256";
25
26
  })(DerivationType = exports.DerivationType || (exports.DerivationType = {}));
27
+ /**
28
+ * @category Error
29
+ * @description Error that indicates an invalid derivation type being passed or used
30
+ */
31
+ class InvalidDerivationTypeError extends Error {
32
+ constructor(derivationType) {
33
+ super(`The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256`);
34
+ this.derivationType = derivationType;
35
+ this.name = 'InvalidDerivationTypeError';
36
+ }
37
+ }
38
+ exports.InvalidDerivationTypeError = InvalidDerivationTypeError;
39
+ /**
40
+ * @category Error
41
+ * @description Error that indicates an invalid derivation path being passed or used
42
+ */
43
+ class InvalidDerivationPathError extends Error {
44
+ constructor(derivationPath) {
45
+ super(`The derivation path ${derivationPath} is invalid. The derivation path must start with 44'/1729`);
46
+ this.derivationPath = derivationPath;
47
+ this.name = 'InvalidDerivationPathError';
48
+ }
49
+ }
50
+ exports.InvalidDerivationPathError = InvalidDerivationPathError;
26
51
  const HDPathTemplate = (account) => {
27
52
  return `44'/1729'/${account}'/0'`;
28
53
  };
@@ -68,10 +93,10 @@ class LedgerSigner {
68
93
  this.OTHER_MESSAGE_SEQUENCE = 0x01;
69
94
  this.transport.setScrambleKey('XTZ');
70
95
  if (!path.startsWith("44'/1729'")) {
71
- throw new Error("The derivation path must start with 44'/1729'");
96
+ throw new InvalidDerivationPathError(path);
72
97
  }
73
98
  if (!Object.values(DerivationType).includes(derivationType)) {
74
- throw new Error('The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256');
99
+ throw new InvalidDerivationTypeError(derivationType.toString());
75
100
  }
76
101
  }
77
102
  publicKeyHash() {
@@ -82,7 +107,7 @@ class LedgerSigner {
82
107
  if (this._publicKeyHash) {
83
108
  return this._publicKeyHash;
84
109
  }
85
- throw new Error(`Unable to get the public key hash.`);
110
+ throw new error_1.PublicKeyHashRetrievalError();
86
111
  });
87
112
  }
88
113
  publicKey() {
@@ -90,7 +115,7 @@ class LedgerSigner {
90
115
  if (this._publicKey) {
91
116
  return this._publicKey;
92
117
  }
93
- const responseLedger = yield this.getLedgerpublicKey();
118
+ const responseLedger = yield this.getLedgerPublicKey();
94
119
  const publicKeyLength = responseLedger[0];
95
120
  const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
96
121
  const compressedPublicKey = utils_2.compressPublicKey(rawPublicKey, this.derivationType);
@@ -102,7 +127,7 @@ class LedgerSigner {
102
127
  return publicKey;
103
128
  });
104
129
  }
105
- getLedgerpublicKey() {
130
+ getLedgerPublicKey() {
106
131
  return __awaiter(this, void 0, void 0, function* () {
107
132
  try {
108
133
  let ins = this.INS_PROMPT_PUBLIC_KEY;
@@ -113,13 +138,13 @@ class LedgerSigner {
113
138
  return responseLedger;
114
139
  }
115
140
  catch (error) {
116
- throw new Error('Unable to retrieve public key');
141
+ throw new error_1.PublicKeyRetrievalError();
117
142
  }
118
143
  });
119
144
  }
120
145
  secretKey() {
121
146
  return __awaiter(this, void 0, void 0, function* () {
122
- throw new Error('Secret key cannot be exposed');
147
+ throw new utils_1.ProhibitedActionError('Secret key cannot be exposed');
123
148
  });
124
149
  }
125
150
  sign(bytes, watermark) {
@@ -136,7 +161,7 @@ class LedgerSigner {
136
161
  }
137
162
  else {
138
163
  if (!utils_2.validateResponse(ledgerResponse)) {
139
- throw new Error('Cannot parse ledger response.');
164
+ throw new error_1.InvalidLedgerResponseError('Cannot parse ledger response');
140
165
  }
141
166
  const idxLengthRVal = 3; // Third element of response is length of r value
142
167
  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;AAI1C,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,yDAAc,CAAA;IACd,6DAAgB,CAAA;IAChB,mDAAW,CAAA;AACb,CAAC,EAJW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAIzB;AAEM,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,EAAE;IAChD,OAAO,aAAa,OAAO,MAAM,CAAC;AACpC,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEF,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,YAAY;IAYvB,YACU,SAA0B,EAC1B,OAAe,iBAAiB,EAChC,SAAkB,IAAI,EACtB,iBAAiC,cAAc,CAAC,OAAO;QAHvD,cAA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ClD,OAAO;gBACL,MAAM,EAAE,cAAM,CAAC,cAAM,CAAC,IAAI,CAAC;gBAC3B,OAAO,EAAE,cAAM,CAAC,cAAM,CAAC,GAAG,CAAC;gBAC3B,OAAO,EAAE,cAAM,CAAC,cAAM,CAAC,KAAK,CAAC;aAC9B,CAAC;SACH;aAAM,IAAI,IAAI,CAAC,cAAc,KAAK,cAAc,CAAC,SAAS,EAAE;YAC3D,OAAO;gBACL,MAAM,EAAE,cAAM,CAAC,cAAM,CAAC,IAAI,CAAC;gBAC3B,OAAO,EAAE,cAAM,CAAC,cAAM,CAAC,GAAG,CAAC;gBAC3B,OAAO,EAAE,cAAM,CAAC,cAAM,CAAC,KAAK,CAAC;aAC9B,CAAC;SACH;aAAM;YACL,OAAO;gBACL,MAAM,EAAE,cAAM,CAAC,cAAM,CAAC,IAAI,CAAC;gBAC3B,OAAO,EAAE,cAAM,CAAC,cAAM,CAAC,GAAG,CAAC;gBAC3B,OAAO,EAAE,cAAM,CAAC,cAAM,CAAC,KAAK,CAAC;aAC9B,CAAC;SACH;IACH,CAAC;CACF;AAxJD,oCAwJC"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
5
5
  exports.VERSION = {
6
- "commitHash": "5996bf6b665e26de3201cf45884b4a2bb9218e09",
7
- "version": "12.0.2"
6
+ "commitHash": "cbdd0af87e400489076259d065e2d328feb8e1b4",
7
+ "version": "12.1.0"
8
8
  };
9
9
  //# sourceMappingURL=version.js.map
@@ -1,4 +1,4 @@
1
- import { b58cencode, prefix, Prefix } from '@taquito/utils';
1
+ import { b58cencode, ProhibitedActionError, prefix, Prefix } from '@taquito/utils';
2
2
  import { hash } from '@stablelib/blake2b';
3
3
 
4
4
  /*! *****************************************************************************
@@ -146,10 +146,42 @@ function extractValue(idxLength, response) {
146
146
  return { buffer, idxValueStart, length };
147
147
  }
148
148
 
149
+ /**
150
+ * @category Error
151
+ * @description Error that indicates an invalid or unparseable ledger response
152
+ */
153
+ class InvalidLedgerResponseError extends Error {
154
+ constructor(message) {
155
+ super(message);
156
+ this.message = message;
157
+ this.name = 'InvalidLedgerResponseError';
158
+ }
159
+ }
160
+ /**
161
+ * @category Error
162
+ * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
163
+ */
164
+ class PublicKeyRetrievalError extends Error {
165
+ constructor() {
166
+ super(`Unable to retrieve Public Key from Ledger`);
167
+ this.name = 'PublicKeyRetrievalError';
168
+ }
169
+ }
170
+ /**
171
+ * @category Error
172
+ * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
173
+ */
174
+ class PublicKeyHashRetrievalError extends Error {
175
+ constructor() {
176
+ super(`Unable to retrieve Public Key Hash from Ledger`);
177
+ this.name = 'PublicKeyHashRetrievalError';
178
+ }
179
+ }
180
+
149
181
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
150
182
  const VERSION = {
151
- "commitHash": "5996bf6b665e26de3201cf45884b4a2bb9218e09",
152
- "version": "12.0.2"
183
+ "commitHash": "cbdd0af87e400489076259d065e2d328feb8e1b4",
184
+ "version": "12.1.0"
153
185
  };
154
186
 
155
187
  /**
@@ -162,6 +194,28 @@ var DerivationType;
162
194
  DerivationType[DerivationType["SECP256K1"] = 1] = "SECP256K1";
163
195
  DerivationType[DerivationType["P256"] = 2] = "P256";
164
196
  })(DerivationType || (DerivationType = {}));
197
+ /**
198
+ * @category Error
199
+ * @description Error that indicates an invalid derivation type being passed or used
200
+ */
201
+ class InvalidDerivationTypeError extends Error {
202
+ constructor(derivationType) {
203
+ super(`The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256`);
204
+ this.derivationType = derivationType;
205
+ this.name = 'InvalidDerivationTypeError';
206
+ }
207
+ }
208
+ /**
209
+ * @category Error
210
+ * @description Error that indicates an invalid derivation path being passed or used
211
+ */
212
+ class InvalidDerivationPathError extends Error {
213
+ constructor(derivationPath) {
214
+ super(`The derivation path ${derivationPath} is invalid. The derivation path must start with 44'/1729`);
215
+ this.derivationPath = derivationPath;
216
+ this.name = 'InvalidDerivationPathError';
217
+ }
218
+ }
165
219
  const HDPathTemplate = (account) => {
166
220
  return `44'/1729'/${account}'/0'`;
167
221
  };
@@ -204,10 +258,10 @@ class LedgerSigner {
204
258
  this.OTHER_MESSAGE_SEQUENCE = 0x01;
205
259
  this.transport.setScrambleKey('XTZ');
206
260
  if (!path.startsWith("44'/1729'")) {
207
- throw new Error("The derivation path must start with 44'/1729'");
261
+ throw new InvalidDerivationPathError(path);
208
262
  }
209
263
  if (!Object.values(DerivationType).includes(derivationType)) {
210
- throw new Error('The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256');
264
+ throw new InvalidDerivationTypeError(derivationType.toString());
211
265
  }
212
266
  }
213
267
  publicKeyHash() {
@@ -218,7 +272,7 @@ class LedgerSigner {
218
272
  if (this._publicKeyHash) {
219
273
  return this._publicKeyHash;
220
274
  }
221
- throw new Error(`Unable to get the public key hash.`);
275
+ throw new PublicKeyHashRetrievalError();
222
276
  });
223
277
  }
224
278
  publicKey() {
@@ -226,7 +280,7 @@ class LedgerSigner {
226
280
  if (this._publicKey) {
227
281
  return this._publicKey;
228
282
  }
229
- const responseLedger = yield this.getLedgerpublicKey();
283
+ const responseLedger = yield this.getLedgerPublicKey();
230
284
  const publicKeyLength = responseLedger[0];
231
285
  const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
232
286
  const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);
@@ -238,7 +292,7 @@ class LedgerSigner {
238
292
  return publicKey;
239
293
  });
240
294
  }
241
- getLedgerpublicKey() {
295
+ getLedgerPublicKey() {
242
296
  return __awaiter(this, void 0, void 0, function* () {
243
297
  try {
244
298
  let ins = this.INS_PROMPT_PUBLIC_KEY;
@@ -249,13 +303,13 @@ class LedgerSigner {
249
303
  return responseLedger;
250
304
  }
251
305
  catch (error) {
252
- throw new Error('Unable to retrieve public key');
306
+ throw new PublicKeyRetrievalError();
253
307
  }
254
308
  });
255
309
  }
256
310
  secretKey() {
257
311
  return __awaiter(this, void 0, void 0, function* () {
258
- throw new Error('Secret key cannot be exposed');
312
+ throw new ProhibitedActionError('Secret key cannot be exposed');
259
313
  });
260
314
  }
261
315
  sign(bytes, watermark) {
@@ -272,7 +326,7 @@ class LedgerSigner {
272
326
  }
273
327
  else {
274
328
  if (!validateResponse(ledgerResponse)) {
275
- throw new Error('Cannot parse ledger response.');
329
+ throw new InvalidLedgerResponseError('Cannot parse ledger response');
276
330
  }
277
331
  const idxLengthRVal = 3; // Third element of response is length of r value
278
332
  const rValue = extractValue(idxLengthRVal, ledgerResponse);
@@ -325,5 +379,5 @@ class LedgerSigner {
325
379
  }
326
380
  }
327
381
 
328
- export { DerivationType, HDPathTemplate, LedgerSigner, VERSION };
382
+ export { DerivationType, HDPathTemplate, InvalidDerivationPathError, InvalidDerivationTypeError, LedgerSigner, VERSION };
329
383
  //# sourceMappingURL=taquito-ledger-signer.es6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-ledger-signer.es6.js","sources":["../src/utils.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: any[] = [];\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) {\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// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"5996bf6b665e26de3201cf45884b4a2bb9218e09\",\n \"version\": \"12.0.2\"\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';\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}\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)\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 */\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 Error(\"The derivation path must start with 44'/1729'\");\n }\n if (!Object.values(DerivationType).includes(derivationType)) {\n throw new Error(\n 'The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256'\n );\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 Error(`Unable to get the public key hash.`);\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 Error('Unable to retrieve public key');\n }\n }\n\n async secretKey(): Promise<string> {\n throw new Error('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 (this.derivationType === DerivationType.ED25519) {\n signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');\n } else {\n if (!validateResponse(ledgerResponse)) {\n throw new Error('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: any): 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 (this.derivationType === DerivationType.ED25519) {\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;;;;AAOA,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;;;;;;SAOgB,qBAAqB,CAAC,IAAY;IAChD,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO;QACzB,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,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AAC,KAAK,CAAC;aAC9B,CAAC;SACH;aAAM;YACL,OAAO;gBACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;gBAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9B,CAAC;SACH;KACF;;;;;"}
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: any[] = [];\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) {\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\": \"cbdd0af87e400489076259d065e2d328feb8e1b4\",\n \"version\": \"12.1.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, ProhibitedActionError } 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';\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}\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 or DerivationType.P256`\n );\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates an invalid derivation path being passed or used\n */\nexport class InvalidDerivationPathError extends Error {\n public name = 'InvalidDerivationPathError';\n constructor(public derivationPath: string) {\n super(\n `The derivation path ${derivationPath} is invalid. The derivation path must start with 44'/1729`\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)\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 */\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);\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 (this.derivationType === DerivationType.ED25519) {\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: any): 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 (this.derivationType === DerivationType.ED25519) {\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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;YACL,OAAO;gBACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;gBAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9B,CAAC;SACH;KACF;;;;;"}
@@ -149,10 +149,42 @@
149
149
  return { buffer, idxValueStart, length };
150
150
  }
151
151
 
152
+ /**
153
+ * @category Error
154
+ * @description Error that indicates an invalid or unparseable ledger response
155
+ */
156
+ class InvalidLedgerResponseError extends Error {
157
+ constructor(message) {
158
+ super(message);
159
+ this.message = message;
160
+ this.name = 'InvalidLedgerResponseError';
161
+ }
162
+ }
163
+ /**
164
+ * @category Error
165
+ * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
166
+ */
167
+ class PublicKeyRetrievalError extends Error {
168
+ constructor() {
169
+ super(`Unable to retrieve Public Key from Ledger`);
170
+ this.name = 'PublicKeyRetrievalError';
171
+ }
172
+ }
173
+ /**
174
+ * @category Error
175
+ * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
176
+ */
177
+ class PublicKeyHashRetrievalError extends Error {
178
+ constructor() {
179
+ super(`Unable to retrieve Public Key Hash from Ledger`);
180
+ this.name = 'PublicKeyHashRetrievalError';
181
+ }
182
+ }
183
+
152
184
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
153
185
  const VERSION = {
154
- "commitHash": "5996bf6b665e26de3201cf45884b4a2bb9218e09",
155
- "version": "12.0.2"
186
+ "commitHash": "cbdd0af87e400489076259d065e2d328feb8e1b4",
187
+ "version": "12.1.0"
156
188
  };
157
189
 
158
190
  /**
@@ -165,6 +197,28 @@
165
197
  DerivationType[DerivationType["SECP256K1"] = 1] = "SECP256K1";
166
198
  DerivationType[DerivationType["P256"] = 2] = "P256";
167
199
  })(exports.DerivationType || (exports.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 or DerivationType.P256`);
207
+ this.derivationType = derivationType;
208
+ this.name = 'InvalidDerivationTypeError';
209
+ }
210
+ }
211
+ /**
212
+ * @category Error
213
+ * @description Error that indicates an invalid derivation path being passed or used
214
+ */
215
+ class InvalidDerivationPathError extends Error {
216
+ constructor(derivationPath) {
217
+ super(`The derivation path ${derivationPath} is invalid. The derivation path must start with 44'/1729`);
218
+ this.derivationPath = derivationPath;
219
+ this.name = 'InvalidDerivationPathError';
220
+ }
221
+ }
168
222
  const HDPathTemplate = (account) => {
169
223
  return `44'/1729'/${account}'/0'`;
170
224
  };
@@ -207,10 +261,10 @@
207
261
  this.OTHER_MESSAGE_SEQUENCE = 0x01;
208
262
  this.transport.setScrambleKey('XTZ');
209
263
  if (!path.startsWith("44'/1729'")) {
210
- throw new Error("The derivation path must start with 44'/1729'");
264
+ throw new InvalidDerivationPathError(path);
211
265
  }
212
266
  if (!Object.values(exports.DerivationType).includes(derivationType)) {
213
- throw new Error('The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256');
267
+ throw new InvalidDerivationTypeError(derivationType.toString());
214
268
  }
215
269
  }
216
270
  publicKeyHash() {
@@ -221,7 +275,7 @@
221
275
  if (this._publicKeyHash) {
222
276
  return this._publicKeyHash;
223
277
  }
224
- throw new Error(`Unable to get the public key hash.`);
278
+ throw new PublicKeyHashRetrievalError();
225
279
  });
226
280
  }
227
281
  publicKey() {
@@ -229,7 +283,7 @@
229
283
  if (this._publicKey) {
230
284
  return this._publicKey;
231
285
  }
232
- const responseLedger = yield this.getLedgerpublicKey();
286
+ const responseLedger = yield this.getLedgerPublicKey();
233
287
  const publicKeyLength = responseLedger[0];
234
288
  const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
235
289
  const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);
@@ -241,7 +295,7 @@
241
295
  return publicKey;
242
296
  });
243
297
  }
244
- getLedgerpublicKey() {
298
+ getLedgerPublicKey() {
245
299
  return __awaiter(this, void 0, void 0, function* () {
246
300
  try {
247
301
  let ins = this.INS_PROMPT_PUBLIC_KEY;
@@ -252,13 +306,13 @@
252
306
  return responseLedger;
253
307
  }
254
308
  catch (error) {
255
- throw new Error('Unable to retrieve public key');
309
+ throw new PublicKeyRetrievalError();
256
310
  }
257
311
  });
258
312
  }
259
313
  secretKey() {
260
314
  return __awaiter(this, void 0, void 0, function* () {
261
- throw new Error('Secret key cannot be exposed');
315
+ throw new utils.ProhibitedActionError('Secret key cannot be exposed');
262
316
  });
263
317
  }
264
318
  sign(bytes, watermark) {
@@ -275,7 +329,7 @@
275
329
  }
276
330
  else {
277
331
  if (!validateResponse(ledgerResponse)) {
278
- throw new Error('Cannot parse ledger response.');
332
+ throw new InvalidLedgerResponseError('Cannot parse ledger response');
279
333
  }
280
334
  const idxLengthRVal = 3; // Third element of response is length of r value
281
335
  const rValue = extractValue(idxLengthRVal, ledgerResponse);
@@ -329,6 +383,8 @@
329
383
  }
330
384
 
331
385
  exports.HDPathTemplate = HDPathTemplate;
386
+ exports.InvalidDerivationPathError = InvalidDerivationPathError;
387
+ exports.InvalidDerivationTypeError = InvalidDerivationTypeError;
332
388
  exports.LedgerSigner = LedgerSigner;
333
389
  exports.VERSION = VERSION;
334
390
 
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-ledger-signer.umd.js","sources":["../src/utils.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: any[] = [];\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) {\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// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"5996bf6b665e26de3201cf45884b4a2bb9218e09\",\n \"version\": \"12.0.2\"\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';\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}\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)\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 */\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 Error(\"The derivation path must start with 44'/1729'\");\n }\n if (!Object.values(DerivationType).includes(derivationType)) {\n throw new Error(\n 'The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256'\n );\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 Error(`Unable to get the public key hash.`);\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 Error('Unable to retrieve public key');\n }\n }\n\n async secretKey(): Promise<string> {\n throw new Error('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 (this.derivationType === DerivationType.ED25519) {\n signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');\n } else {\n if (!validateResponse(ledgerResponse)) {\n throw new Error('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: any): 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 (this.derivationType === DerivationType.ED25519) {\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","b58cencode","hash","prefix","Prefix"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;;;IAOA,MAAM,cAAc,GAAG,GAAG,CAAC;IAE3B;;;;;;;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C3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,KAAK,CAAC;iBAC9B,CAAC;aACH;iBAAM,IAAI,IAAI,CAAC,cAAc,KAAKJ,sBAAc,CAAC,SAAS,EAAE;gBAC3D,OAAO;oBACL,MAAM,EAAEG,YAAM,CAACC,YAAM,CAAC,IAAI,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,GAAG,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,KAAK,CAAC;iBAC9B,CAAC;aACH;iBAAM;gBACL,OAAO;oBACL,MAAM,EAAED,YAAM,CAACC,YAAM,CAAC,IAAI,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,GAAG,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,KAAK,CAAC;iBAC9B,CAAC;aACH;SACF;;;;;;;;;;;;;"}
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: any[] = [];\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) {\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\": \"cbdd0af87e400489076259d065e2d328feb8e1b4\",\n \"version\": \"12.1.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, ProhibitedActionError } 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';\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}\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 or DerivationType.P256`\n );\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates an invalid derivation path being passed or used\n */\nexport class InvalidDerivationPathError extends Error {\n public name = 'InvalidDerivationPathError';\n constructor(public derivationPath: string) {\n super(\n `The derivation path ${derivationPath} is invalid. The derivation path must start with 44'/1729`\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)\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 */\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);\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 (this.derivationType === DerivationType.ED25519) {\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: any): 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 (this.derivationType === DerivationType.ED25519) {\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","b58cencode","hash","ProhibitedActionError","prefix","Prefix"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;;;IAOA,MAAM,cAAc,GAAG,GAAG,CAAC;IAE3B;;;;;;;aAOgB,qBAAqB,CAAC,IAAY;QAChD,MAAM,MAAM,GAAU,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO;YACzB,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACrC,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBAC1B,OAAO;aACR;YACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC7D,QAAQ,IAAI,UAAU,CAAC;aACxB;YACD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACvB,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC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AAM,EAAEI,YAAM,CAACC,YAAM,CAAC,IAAI,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,GAAG,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,KAAK,CAAC;iBAC9B,CAAC;aACH;iBAAM,IAAI,IAAI,CAAC,cAAc,KAAKL,sBAAc,CAAC,SAAS,EAAE;gBAC3D,OAAO;oBACL,MAAM,EAAEI,YAAM,CAACC,YAAM,CAAC,IAAI,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,GAAG,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,KAAK,CAAC;iBAC9B,CAAC;aACH;iBAAM;gBACL,OAAO;oBACL,MAAM,EAAED,YAAM,CAACC,YAAM,CAAC,IAAI,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,GAAG,CAAC;oBAC3B,OAAO,EAAED,YAAM,CAACC,YAAM,CAAC,KAAK,CAAC;iBAC9B,CAAC;aACH;SACF;;;;;;;;;;;;;;;"}
@@ -0,0 +1,25 @@
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
+ }
@@ -10,6 +10,24 @@ export declare enum DerivationType {
10
10
  SECP256K1 = 1,
11
11
  P256 = 2
12
12
  }
13
+ /**
14
+ * @category Error
15
+ * @description Error that indicates an invalid derivation type being passed or used
16
+ */
17
+ export declare class InvalidDerivationTypeError extends Error {
18
+ derivationType: string;
19
+ name: string;
20
+ constructor(derivationType: string);
21
+ }
22
+ /**
23
+ * @category Error
24
+ * @description Error that indicates an invalid derivation path being passed or used
25
+ */
26
+ export declare class InvalidDerivationPathError extends Error {
27
+ derivationPath: string;
28
+ name: string;
29
+ constructor(derivationPath: string);
30
+ }
13
31
  export declare const HDPathTemplate: (account: number) => string;
14
32
  export { VERSION } from './version';
15
33
  /**
@@ -52,7 +70,7 @@ export declare class LedgerSigner implements Signer {
52
70
  constructor(transport: LedgerTransport, path?: string, prompt?: boolean, derivationType?: DerivationType);
53
71
  publicKeyHash(): Promise<string>;
54
72
  publicKey(): Promise<string>;
55
- private getLedgerpublicKey;
73
+ private getLedgerPublicKey;
56
74
  secretKey(): Promise<string>;
57
75
  sign(bytes: string, watermark?: Uint8Array): Promise<{
58
76
  bytes: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taquito/ledger-signer",
3
- "version": "12.0.2",
3
+ "version": "12.1.0",
4
4
  "description": "Ledger signer provider",
5
5
  "keywords": [
6
6
  "tezos",
@@ -59,8 +59,8 @@
59
59
  "dependencies": {
60
60
  "@ledgerhq/hw-transport": "^6.20.0",
61
61
  "@stablelib/blake2b": "^1.0.1",
62
- "@taquito/taquito": "^12.0.2",
63
- "@taquito/utils": "^12.0.2",
62
+ "@taquito/taquito": "^12.1.0",
63
+ "@taquito/utils": "^12.1.0",
64
64
  "buffer": "^6.0.3"
65
65
  },
66
66
  "devDependencies": {
@@ -92,5 +92,5 @@
92
92
  "ts-toolbelt": "^9.6.0",
93
93
  "typescript": "~4.1.5"
94
94
  },
95
- "gitHead": "a224127fe138d46674af2f9605e5bb452b2e4d74"
95
+ "gitHead": "8e044472d87e92bfa748e8193ba84a7ee57d659f"
96
96
  }
package/src/error.ts ADDED
@@ -0,0 +1,32 @@
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
+ }
@@ -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, prefix, Prefix, ProhibitedActionError } from '@taquito/utils';
9
9
  import {
10
10
  appendWatermark,
11
11
  transformPathToBuffer,
@@ -15,6 +15,11 @@ import {
15
15
  extractValue,
16
16
  } from './utils';
17
17
  import { hash } from '@stablelib/blake2b';
18
+ import {
19
+ PublicKeyHashRetrievalError,
20
+ PublicKeyRetrievalError,
21
+ InvalidLedgerResponseError,
22
+ } from './error';
18
23
 
19
24
  export type LedgerTransport = Pick<Transport, 'send' | 'decorateAppAPIMethods' | 'setScrambleKey'>;
20
25
 
@@ -24,6 +29,32 @@ export enum DerivationType {
24
29
  P256 = 0x02, // tz3
25
30
  }
26
31
 
32
+ /**
33
+ * @category Error
34
+ * @description Error that indicates an invalid derivation type being passed or used
35
+ */
36
+ export class InvalidDerivationTypeError extends Error {
37
+ public name = 'InvalidDerivationTypeError';
38
+ constructor(public derivationType: string) {
39
+ super(
40
+ `The derivation type ${derivationType} is invalid. The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256`
41
+ );
42
+ }
43
+ }
44
+
45
+ /**
46
+ * @category Error
47
+ * @description Error that indicates an invalid derivation path being passed or used
48
+ */
49
+ export class InvalidDerivationPathError extends Error {
50
+ public name = 'InvalidDerivationPathError';
51
+ constructor(public derivationPath: string) {
52
+ super(
53
+ `The derivation path ${derivationPath} is invalid. The derivation path must start with 44'/1729`
54
+ );
55
+ }
56
+ }
57
+
27
58
  export const HDPathTemplate = (account: number) => {
28
59
  return `44'/1729'/${account}'/0'`;
29
60
  };
@@ -73,12 +104,10 @@ export class LedgerSigner implements Signer {
73
104
  ) {
74
105
  this.transport.setScrambleKey('XTZ');
75
106
  if (!path.startsWith("44'/1729'")) {
76
- throw new Error("The derivation path must start with 44'/1729'");
107
+ throw new InvalidDerivationPathError(path);
77
108
  }
78
109
  if (!Object.values(DerivationType).includes(derivationType)) {
79
- throw new Error(
80
- 'The derivation type must be DerivationType.ED25519, DerivationType.SECP256K1 or DerivationType.P256'
81
- );
110
+ throw new InvalidDerivationTypeError(derivationType.toString());
82
111
  }
83
112
  }
84
113
 
@@ -89,14 +118,14 @@ export class LedgerSigner implements Signer {
89
118
  if (this._publicKeyHash) {
90
119
  return this._publicKeyHash;
91
120
  }
92
- throw new Error(`Unable to get the public key hash.`);
121
+ throw new PublicKeyHashRetrievalError();
93
122
  }
94
123
 
95
124
  async publicKey(): Promise<string> {
96
125
  if (this._publicKey) {
97
126
  return this._publicKey;
98
127
  }
99
- const responseLedger = await this.getLedgerpublicKey();
128
+ const responseLedger = await this.getLedgerPublicKey();
100
129
  const publicKeyLength = responseLedger[0];
101
130
  const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
102
131
  const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);
@@ -110,7 +139,7 @@ export class LedgerSigner implements Signer {
110
139
  return publicKey;
111
140
  }
112
141
 
113
- private async getLedgerpublicKey(): Promise<Buffer> {
142
+ private async getLedgerPublicKey(): Promise<Buffer> {
114
143
  try {
115
144
  let ins = this.INS_PROMPT_PUBLIC_KEY;
116
145
  if (this.prompt === false) {
@@ -125,12 +154,12 @@ export class LedgerSigner implements Signer {
125
154
  );
126
155
  return responseLedger;
127
156
  } catch (error) {
128
- throw new Error('Unable to retrieve public key');
157
+ throw new PublicKeyRetrievalError();
129
158
  }
130
159
  }
131
160
 
132
161
  async secretKey(): Promise<string> {
133
- throw new Error('Secret key cannot be exposed');
162
+ throw new ProhibitedActionError('Secret key cannot be exposed');
134
163
  }
135
164
 
136
165
  async sign(bytes: string, watermark?: Uint8Array) {
@@ -145,7 +174,7 @@ export class LedgerSigner implements Signer {
145
174
  signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');
146
175
  } else {
147
176
  if (!validateResponse(ledgerResponse)) {
148
- throw new Error('Cannot parse ledger response.');
177
+ throw new InvalidLedgerResponseError('Cannot parse ledger response');
149
178
  }
150
179
  const idxLengthRVal = 3; // Third element of response is length of r value
151
180
  const rValue = extractValue(idxLengthRVal, ledgerResponse);
package/src/version.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
3
3
  export const VERSION = {
4
- "commitHash": "5996bf6b665e26de3201cf45884b4a2bb9218e09",
5
- "version": "12.0.2"
4
+ "commitHash": "cbdd0af87e400489076259d065e2d328feb8e1b4",
5
+ "version": "12.1.0"
6
6
  };
@@ -12,39 +12,32 @@ describe('LedgerSigner test', () => {
12
12
  };
13
13
 
14
14
  beforeEach(async () => {
15
- mockTransport = {
16
- send: jest.fn(),
15
+ mockTransport = {
16
+ send: jest.fn(),
17
17
  decorateAppAPIMethods: jest.fn(),
18
18
  setScrambleKey: jest.fn(),
19
- }
19
+ };
20
20
  });
21
21
 
22
22
  it('LedgerSigner is instantiable with parameters', () => {
23
23
  expect(
24
- new LedgerSigner(
25
- mockTransport,
26
- "44'/1729'/0'/0'",
27
- true,
28
- DerivationType.SECP256K1
29
- )
24
+ new LedgerSigner(mockTransport, "44'/1729'/0'/0'", true, DerivationType.SECP256K1)
30
25
  ).toBeInstanceOf(LedgerSigner);
31
26
  });
32
27
 
33
28
  it('Should throw exception if path is incorrect', () => {
34
29
  expect(() => {
35
- new LedgerSigner(
36
- mockTransport,
37
- "4'/1729'/0'/0'",
38
- true,
39
- DerivationType.SECP256K1
40
- )}
41
- ).toThrow("The derivation path must start with 44'/1729'");
30
+ new LedgerSigner(mockTransport, "4'/1729'/0'/0'", true, DerivationType.SECP256K1);
31
+ }).toThrow("The derivation path 4'/1729'/0'/0' is invalid");
42
32
  });
43
33
 
44
- it('Should get public key and public key hash for default path and tz1 curve', async () => {
34
+ it('Should get public key and public key hash for default path and tz1 curve', async () => {
45
35
  const signer = new LedgerSigner(mockTransport);
46
- const mockpk = Buffer.from('21026760ff228c2c16cbca18bb782a106e51c43a131776f5dfad30ecb5d5e43eccbd9000', 'hex');
47
- mockTransport.send.mockResolvedValue(mockpk);
36
+ const mockpk = Buffer.from(
37
+ '21026760ff228c2c16cbca18bb782a106e51c43a131776f5dfad30ecb5d5e43eccbd9000',
38
+ 'hex'
39
+ );
40
+ mockTransport.send.mockResolvedValue(mockpk);
48
41
  const pk = await signer.publicKey();
49
42
  const pkh = await signer.publicKeyHash();
50
43
  const path = "44'/1729'/0'/0'";
@@ -53,12 +46,20 @@ it('Should get public key and public key hash for default path and tz1 curve', a
53
46
  expect(mockTransport.send).toHaveBeenCalledTimes(1);
54
47
  expect(pk).toEqual('edpkuRkcStobJ569XFxmE6edyRQQzMmtf4ZnmPkTPfSQnt6P3Nym2V');
55
48
  expect(pkh).toEqual('tz1e42w8ZaGAbM3gucbBy8iRypdbnqUj7oWY');
56
- })
49
+ });
57
50
 
58
51
  it('Should get public key and public key hash for default path and tz2 curve', async () => {
59
- const signer = new LedgerSigner(mockTransport, "44'/1729'/0'/0'", false, DerivationType.SECP256K1);
60
- const mockpk = Buffer.from('410406285dc14a52f870054debb9add64359c968698b16697651d2457a9b3235ce3686f3821d7373b00e91670b137920cc0f3480dca3373d057c34a163047549cc3e9000', 'hex');
61
- mockTransport.send.mockResolvedValue(mockpk);
52
+ const signer = new LedgerSigner(
53
+ mockTransport,
54
+ "44'/1729'/0'/0'",
55
+ false,
56
+ DerivationType.SECP256K1
57
+ );
58
+ const mockpk = Buffer.from(
59
+ '410406285dc14a52f870054debb9add64359c968698b16697651d2457a9b3235ce3686f3821d7373b00e91670b137920cc0f3480dca3373d057c34a163047549cc3e9000',
60
+ 'hex'
61
+ );
62
+ mockTransport.send.mockResolvedValue(mockpk);
62
63
  const pk = await signer.publicKey();
63
64
  const pkh = await signer.publicKeyHash();
64
65
  const path = "44'/1729'/0'/0'";
@@ -67,12 +68,15 @@ it('Should get public key and public key hash for default path and tz1 curve', a
67
68
  expect(mockTransport.send).toHaveBeenCalledTimes(1);
68
69
  expect(pk).toEqual('sppk7ZMM9NZLPPueTKcoJobdUG7MjLtaGsdrZqddcn9U6C9Yt99m8sU');
69
70
  expect(pkh).toEqual('tz2SxDTGnT3mHzaHf6mwy6Wtw1qUX1hzm1Sw');
70
- })
71
+ });
71
72
 
72
73
  it('Should get public key and public key hash for path which accounnt is 1 and tz3 curve', async () => {
73
74
  const signer = new LedgerSigner(mockTransport, "44'/1729'/1'/0'", false, DerivationType.P256);
74
- const mockpk = Buffer.from('4104eac3db090c124a2d57623d8e743f4a2beef9e6f96e80b49a4755c525c6c80ee391d9d93595479ae1d0099ecc8f4d56ca0542516407ff9f386c48678de965b8809000', 'hex');
75
- mockTransport.send.mockResolvedValue(mockpk);
75
+ const mockpk = Buffer.from(
76
+ '4104eac3db090c124a2d57623d8e743f4a2beef9e6f96e80b49a4755c525c6c80ee391d9d93595479ae1d0099ecc8f4d56ca0542516407ff9f386c48678de965b8809000',
77
+ 'hex'
78
+ );
79
+ mockTransport.send.mockResolvedValue(mockpk);
76
80
  const pk = await signer.publicKey();
77
81
  const pkh = await signer.publicKeyHash();
78
82
  const path = "44'/1729'/1'/0'";
@@ -81,13 +85,16 @@ it('Should get public key and public key hash for default path and tz1 curve', a
81
85
  expect(mockTransport.send).toHaveBeenCalledTimes(1);
82
86
  expect(pk).toEqual('p2pk66MZ9MuDHfn5cQsUvtCvU376cijjvDLtTQzBFNeDHMijG4snUZZ');
83
87
  expect(pkh).toEqual('tz3PX4M9x9N7oXp2WWxNcQNK6GtaGdCdesK9');
84
- })
88
+ });
85
89
 
86
90
  it('Should get the right public key and public key hash using HDPathTemplate with index 1', async () => {
87
91
  const path = HDPathTemplate(1); //"44'/1729'/1'/0'"
88
92
  const signer = new LedgerSigner(mockTransport, path, false, DerivationType.ED25519);
89
- const mockpk = Buffer.from('2102ba40b58f38f54512f79e0d6c416e501759d08a05948989d84204a81d841e76749000', 'hex');
90
- mockTransport.send.mockResolvedValue(mockpk);
93
+ const mockpk = Buffer.from(
94
+ '2102ba40b58f38f54512f79e0d6c416e501759d08a05948989d84204a81d841e76749000',
95
+ 'hex'
96
+ );
97
+ mockTransport.send.mockResolvedValue(mockpk);
91
98
  const pk = await signer.publicKey();
92
99
  const pkh = await signer.publicKeyHash();
93
100
  const buff = transformPathToBuffer(path);
@@ -95,13 +102,18 @@ it('Should get public key and public key hash for default path and tz1 curve', a
95
102
  expect(mockTransport.send).toHaveBeenCalledTimes(1);
96
103
  expect(pk).toEqual('edpkv4FWm7YkppQNmKjxrSHCYzoh2pYRdeFeUeXWVjPTLPzyJduaox');
97
104
  expect(pkh).toEqual('tz1fpJJ331QrGMkdEPJzSWWEZRfVgrUCwzUf');
98
- })
105
+ });
99
106
 
100
107
  it('Should sign operation for tz1', async () => {
101
108
  const signer = new LedgerSigner(mockTransport);
102
- const mocksig = Buffer.from('35c1f3340121965a1350af2082af3c83d4338c23c254591ec7a12fef5d4e9fc2a63f7051508cc41255894fe511cfd11af827e8f8e6c3730c3dd0775aff33dc029000', 'hex');
103
- mockTransport.send.mockResolvedValue(mocksig);
104
- const signature = await signer.sign('367325bbba406bc3f8c1bf12b27b6e8081064722d3342e34142c172b322ba0426b00c9fc72e8491bd2973e196f04ec6918ad5bcee22d8c0bbcb98d01e85200006760ff228c2c16cbca18bb782a106e51c43a131776f5dfad30ecb5d5e43eccbd6c00c9fc72e8491bd2973e196f04ec6918ad5bcee22dea0abdb98d01c35000a0c21e0000eadc0855adb415fa69a76fc10397dc2fb37039a000');
109
+ const mocksig = Buffer.from(
110
+ '35c1f3340121965a1350af2082af3c83d4338c23c254591ec7a12fef5d4e9fc2a63f7051508cc41255894fe511cfd11af827e8f8e6c3730c3dd0775aff33dc029000',
111
+ 'hex'
112
+ );
113
+ mockTransport.send.mockResolvedValue(mocksig);
114
+ const signature = await signer.sign(
115
+ '367325bbba406bc3f8c1bf12b27b6e8081064722d3342e34142c172b322ba0426b00c9fc72e8491bd2973e196f04ec6918ad5bcee22d8c0bbcb98d01e85200006760ff228c2c16cbca18bb782a106e51c43a131776f5dfad30ecb5d5e43eccbd6c00c9fc72e8491bd2973e196f04ec6918ad5bcee22dea0abdb98d01c35000a0c21e0000eadc0855adb415fa69a76fc10397dc2fb37039a000'
116
+ );
105
117
  const path = "44'/1729'/0'/0'";
106
118
  const buff = transformPathToBuffer(path);
107
119
  expect(mockTransport.send).toHaveBeenCalledTimes(2);
@@ -113,16 +125,25 @@ it('Should get public key and public key hash for default path and tz1 curve', a
113
125
  'edsigteqgHGYbzsxxFmQjGSf9eeNjTML4g6GBqryKvy7uy6y2XczT6C3ehhfzCBgQBdAMy9NLoD6MZVzCUbtSUoSC1iWAgPXGdW',
114
126
  sbytes:
115
127
  '367325bbba406bc3f8c1bf12b27b6e8081064722d3342e34142c172b322ba0426b00c9fc72e8491bd2973e196f04ec6918ad5bcee22d8c0bbcb98d01e85200006760ff228c2c16cbca18bb782a106e51c43a131776f5dfad30ecb5d5e43eccbd6c00c9fc72e8491bd2973e196f04ec6918ad5bcee22dea0abdb98d01c35000a0c21e0000eadc0855adb415fa69a76fc10397dc2fb37039a00035c1f3340121965a1350af2082af3c83d4338c23c254591ec7a12fef5d4e9fc2a63f7051508cc41255894fe511cfd11af827e8f8e6c3730c3dd0775aff33dc02',
116
- sig:
117
- 'sigV2DADKhiwmvCaRS8QoxhM6DgXF8hTPbUBDbCd7vxkx5Do3rbJ8ZceS59b4c69z1XbtishJzit2RjorEpf6DpfS4paStBK',
128
+ sig: 'sigV2DADKhiwmvCaRS8QoxhM6DgXF8hTPbUBDbCd7vxkx5Do3rbJ8ZceS59b4c69z1XbtishJzit2RjorEpf6DpfS4paStBK',
118
129
  });
119
- })
130
+ });
120
131
 
121
132
  it('Should sign operation for tz2', async () => {
122
- const signer = new LedgerSigner(mockTransport, "44'/1729'/0'/0'", false, DerivationType.SECP256K1);
123
- const mocksig = Buffer.from('314402201bf0d530c35c70dacddfc14c2073e6666df839dca23ff18f0b2a375493fe06a4022036992c38fd5c3e88d6381208744c859dab96de0d8d221ead65b08b553680eee59000', 'hex');
124
- mockTransport.send.mockResolvedValue(mocksig);
125
- const signature = await signer.sign('0372a589146bff99c31469fde4a7ac539e0ea5d926cbea4b72f2ae048fefacdaa16c01cc70a574e52e16028ce0fead32e8b2d8cc1440aca40e9bba8d01ed760000016ca589ff04efc7f657ded2a796631183b3d3709a00ffff09696e6372656d656e74000000020007');
133
+ const signer = new LedgerSigner(
134
+ mockTransport,
135
+ "44'/1729'/0'/0'",
136
+ false,
137
+ DerivationType.SECP256K1
138
+ );
139
+ const mocksig = Buffer.from(
140
+ '314402201bf0d530c35c70dacddfc14c2073e6666df839dca23ff18f0b2a375493fe06a4022036992c38fd5c3e88d6381208744c859dab96de0d8d221ead65b08b553680eee59000',
141
+ 'hex'
142
+ );
143
+ mockTransport.send.mockResolvedValue(mocksig);
144
+ const signature = await signer.sign(
145
+ '0372a589146bff99c31469fde4a7ac539e0ea5d926cbea4b72f2ae048fefacdaa16c01cc70a574e52e16028ce0fead32e8b2d8cc1440aca40e9bba8d01ed760000016ca589ff04efc7f657ded2a796631183b3d3709a00ffff09696e6372656d656e74000000020007'
146
+ );
126
147
  const path = "44'/1729'/0'/0'";
127
148
  const buff = transformPathToBuffer(path);
128
149
  expect(mockTransport.send).toHaveBeenCalledTimes(2);
@@ -134,16 +155,20 @@ it('Should get public key and public key hash for default path and tz1 curve', a
134
155
  'spsig19TzJiKZN8xDGw2qBGyR5FLMAgPamCEpYBXiq7JNzN9WaSkdZbhjWuFK7f1tg4c1h8AHdyrktPYa2UFn1a6YsaLKSRMwiC',
135
156
  sbytes:
136
157
  '0372a589146bff99c31469fde4a7ac539e0ea5d926cbea4b72f2ae048fefacdaa16c01cc70a574e52e16028ce0fead32e8b2d8cc1440aca40e9bba8d01ed760000016ca589ff04efc7f657ded2a796631183b3d3709a00ffff09696e6372656d656e740000000200071bf0d530c35c70dacddfc14c2073e6666df839dca23ff18f0b2a375493fe06a436992c38fd5c3e88d6381208744c859dab96de0d8d221ead65b08b553680eee5',
137
- sig:
138
- 'sigReJyeiJtnz4tm35D8RGRLeyFrc1h8c84cQQ4K95BUDo9P6pP2dMZmmTRHSocfY9cQR8u218TFPqwBYfVhR3xMoCzr7hYu',
158
+ sig: 'sigReJyeiJtnz4tm35D8RGRLeyFrc1h8c84cQQ4K95BUDo9P6pP2dMZmmTRHSocfY9cQR8u218TFPqwBYfVhR3xMoCzr7hYu',
139
159
  });
140
- })
160
+ });
141
161
 
142
162
  it('Should sign operation for tz3', async () => {
143
163
  const signer = new LedgerSigner(mockTransport, "44'/1729'/0'/0'", false, DerivationType.P256);
144
- const mocksig = Buffer.from('3144022005ccc37c4c434b39054a68d15f9f4d4d279699dd3a406cb235e0b3bf62a6ec1702204f72794ad3f06dd3ebb21b36b63eb44b98f5607e8751513741d73660b7952c399000', 'hex');
145
- mockTransport.send.mockResolvedValue(mocksig);
146
- const signature = await signer.sign('038e1824a75961255a36e47d354733d6923c5849579d6abb4bd8c2a929ab5d393a6b02bd2cbb50fb2bfd7237b474a25b1b4ae447c577208c0babbc8d01e8520002022937a7444d7a00cb29f353058444d26d19382f0079e34b5aaf0eda4cec6665f16d02bd2cbb50fb2bfd7237b474a25b1b4ae447c577209310acbc8d01bb78c2030000000000b702000000b205000764045b0000000a2564656372656d656e74045b0000000a25696e6372656d656e740501035b0502020000008303210317057000010321057100020316072e020000002b032105700002032105710003034203210317057000010321057100020316034b051f020000000405200002020000002b0321057000020321057100030342032103170570000103210571000203160312051f020000000405200002053d036d0342051f020000000405200002000000020000');
164
+ const mocksig = Buffer.from(
165
+ '3144022005ccc37c4c434b39054a68d15f9f4d4d279699dd3a406cb235e0b3bf62a6ec1702204f72794ad3f06dd3ebb21b36b63eb44b98f5607e8751513741d73660b7952c399000',
166
+ 'hex'
167
+ );
168
+ mockTransport.send.mockResolvedValue(mocksig);
169
+ const signature = await signer.sign(
170
+ '038e1824a75961255a36e47d354733d6923c5849579d6abb4bd8c2a929ab5d393a6b02bd2cbb50fb2bfd7237b474a25b1b4ae447c577208c0babbc8d01e8520002022937a7444d7a00cb29f353058444d26d19382f0079e34b5aaf0eda4cec6665f16d02bd2cbb50fb2bfd7237b474a25b1b4ae447c577209310acbc8d01bb78c2030000000000b702000000b205000764045b0000000a2564656372656d656e74045b0000000a25696e6372656d656e740501035b0502020000008303210317057000010321057100020316072e020000002b032105700002032105710003034203210317057000010321057100020316034b051f020000000405200002020000002b0321057000020321057100030342032103170570000103210571000203160312051f020000000405200002053d036d0342051f020000000405200002000000020000'
171
+ );
147
172
  const path = "44'/1729'/0'/0'";
148
173
  const buff = transformPathToBuffer(path);
149
174
  expect(mockTransport.send).toHaveBeenCalledTimes(3);
@@ -155,9 +180,7 @@ it('Should get public key and public key hash for default path and tz1 curve', a
155
180
  'p2sigN4XTiSicEot77bsR9BvpnDtSm4KDm2YyRew4isqiqxhN6fJpQeYFu8acN8NSDJCxPrqgpqyML3M7ubfBicRfqNz7oGhnX',
156
181
  sbytes:
157
182
  '038e1824a75961255a36e47d354733d6923c5849579d6abb4bd8c2a929ab5d393a6b02bd2cbb50fb2bfd7237b474a25b1b4ae447c577208c0babbc8d01e8520002022937a7444d7a00cb29f353058444d26d19382f0079e34b5aaf0eda4cec6665f16d02bd2cbb50fb2bfd7237b474a25b1b4ae447c577209310acbc8d01bb78c2030000000000b702000000b205000764045b0000000a2564656372656d656e74045b0000000a25696e6372656d656e740501035b0502020000008303210317057000010321057100020316072e020000002b032105700002032105710003034203210317057000010321057100020316034b051f020000000405200002020000002b0321057000020321057100030342032103170570000103210571000203160312051f020000000405200002053d036d0342051f02000000040520000200000002000005ccc37c4c434b39054a68d15f9f4d4d279699dd3a406cb235e0b3bf62a6ec174f72794ad3f06dd3ebb21b36b63eb44b98f5607e8751513741d73660b7952c39',
158
- sig:
159
- 'sigNkJcdMAWmsqeBM7ARbQ3Gm74NQ5xfc8kyt5gKRQRdWQpZPXW2bT2cxAKBBrCn6ddmqKfkc31q62kWujT8AEEZgeAquYy5',
183
+ sig: 'sigNkJcdMAWmsqeBM7ARbQ3Gm74NQ5xfc8kyt5gKRQRdWQpZPXW2bT2cxAKBBrCn6ddmqKfkc31q62kWujT8AEEZgeAquYy5',
160
184
  });
161
- })
162
-
163
- });
185
+ });
186
+ });