@taquito/ledger-signer 24.2.0 → 24.3.0-beta.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.
@@ -4,7 +4,7 @@ exports.InvalidDerivationTypeError = exports.PublicKeyHashRetrievalError = expor
4
4
  const core_1 = require("@taquito/core");
5
5
  /**
6
6
  * @category Error
7
- * @description Error that indicates an invalid or unparseable ledger response
7
+ * Error that indicates an invalid or unparseable ledger response
8
8
  */
9
9
  class InvalidLedgerResponseError extends core_1.TaquitoError {
10
10
  constructor(message) {
@@ -16,7 +16,7 @@ class InvalidLedgerResponseError extends core_1.TaquitoError {
16
16
  exports.InvalidLedgerResponseError = InvalidLedgerResponseError;
17
17
  /**
18
18
  * @category Error
19
- * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
19
+ * Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
20
20
  */
21
21
  class PublicKeyRetrievalError extends core_1.TaquitoError {
22
22
  constructor(cause) {
@@ -29,7 +29,7 @@ class PublicKeyRetrievalError extends core_1.TaquitoError {
29
29
  exports.PublicKeyRetrievalError = PublicKeyRetrievalError;
30
30
  /**
31
31
  * @category Error
32
- * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
32
+ * Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
33
33
  */
34
34
  class PublicKeyHashRetrievalError extends core_1.TaquitoError {
35
35
  constructor() {
@@ -41,7 +41,7 @@ class PublicKeyHashRetrievalError extends core_1.TaquitoError {
41
41
  exports.PublicKeyHashRetrievalError = PublicKeyHashRetrievalError;
42
42
  /**
43
43
  * @category Error
44
- * @description Error that indicates an invalid derivation type being passed or used
44
+ * Error that indicates an invalid derivation type being passed or used
45
45
  */
46
46
  class InvalidDerivationTypeError extends core_1.ParameterValidationError {
47
47
  constructor(derivationType) {
@@ -3,15 +3,6 @@
3
3
  * @packageDocumentation
4
4
  * @module @taquito/ledger-signer
5
5
  */
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
6
  Object.defineProperty(exports, "__esModule", { value: true });
16
7
  exports.LedgerSigner = exports.VERSION = exports.HDPathTemplate = exports.InvalidDerivationTypeError = exports.DerivationType = exports.InvalidDerivationPathError = void 0;
17
8
  const utils_1 = require("@taquito/utils");
@@ -38,7 +29,7 @@ var version_1 = require("./version");
38
29
  Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
39
30
  /**
40
31
  *
41
- * @description Implementation of the Signer interface that will allow signing operation from a Ledger Nano device
32
+ * Implementation of the Signer interface that will allow signing operation from a Ledger Nano device
42
33
  *
43
34
  * @param transport A transport instance from LedgerJS libraries depending on the platform used (e.g. Web, Node)
44
35
  * @param path The ledger derivation path (default is "44'/1729'/0'/0'")
@@ -88,96 +79,84 @@ class LedgerSigner {
88
79
  throw new errors_1.InvalidDerivationTypeError(derivationType.toString());
89
80
  }
90
81
  }
91
- publicKeyHash() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- if (!this._publicKeyHash) {
94
- yield this.publicKey();
95
- }
96
- if (this._publicKeyHash) {
97
- return this._publicKeyHash;
98
- }
99
- throw new errors_1.PublicKeyHashRetrievalError();
100
- });
82
+ async publicKeyHash() {
83
+ if (!this._publicKeyHash) {
84
+ await this.publicKey();
85
+ }
86
+ if (this._publicKeyHash) {
87
+ return this._publicKeyHash;
88
+ }
89
+ throw new errors_1.PublicKeyHashRetrievalError();
101
90
  }
102
- publicKey() {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- if (this._publicKey) {
105
- return this._publicKey;
106
- }
107
- const responseLedger = yield this.getLedgerPublicKey();
108
- const publicKeyLength = responseLedger[0];
109
- const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
110
- const compressedPublicKey = (0, utils_2.compressPublicKey)(rawPublicKey, this.derivationType);
111
- const prefixes = this.getPrefixes();
112
- const publicKey = (0, utils_1.b58Encode)(compressedPublicKey, prefixes.prefPk);
113
- const publicKeyHash = (0, utils_1.b58Encode)((0, blake2b_1.hash)(compressedPublicKey, 20), prefixes.prefPkh);
114
- this._publicKey = publicKey;
115
- this._publicKeyHash = publicKeyHash;
116
- return publicKey;
117
- });
91
+ async publicKey() {
92
+ if (this._publicKey) {
93
+ return this._publicKey;
94
+ }
95
+ const responseLedger = await this.getLedgerPublicKey();
96
+ const publicKeyLength = responseLedger[0];
97
+ const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
98
+ const compressedPublicKey = (0, utils_2.compressPublicKey)(rawPublicKey, this.derivationType);
99
+ const prefixes = this.getPrefixes();
100
+ const publicKey = (0, utils_1.b58Encode)(compressedPublicKey, prefixes.prefPk);
101
+ const publicKeyHash = (0, utils_1.b58Encode)((0, blake2b_1.hash)(compressedPublicKey, 20), prefixes.prefPkh);
102
+ this._publicKey = publicKey;
103
+ this._publicKeyHash = publicKeyHash;
104
+ return publicKey;
118
105
  }
119
- getLedgerPublicKey() {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- try {
122
- let ins = this.INS_PROMPT_PUBLIC_KEY;
123
- if (this.prompt === false) {
124
- ins = this.INS_GET_PUBLIC_KEY;
125
- }
126
- const responseLedger = yield this.transport.send(this.CLA, ins, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, (0, utils_2.transformPathToBuffer)(this.path));
127
- return responseLedger;
128
- }
129
- catch (error) {
130
- throw new errors_1.PublicKeyRetrievalError(error);
106
+ async getLedgerPublicKey() {
107
+ try {
108
+ let ins = this.INS_PROMPT_PUBLIC_KEY;
109
+ if (this.prompt === false) {
110
+ ins = this.INS_GET_PUBLIC_KEY;
131
111
  }
132
- });
112
+ const responseLedger = await this.transport.send(this.CLA, ins, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, (0, utils_2.transformPathToBuffer)(this.path));
113
+ return responseLedger;
114
+ }
115
+ catch (error) {
116
+ throw new errors_1.PublicKeyRetrievalError(error);
117
+ }
133
118
  }
134
- secretKey() {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- throw new core_1.ProhibitedActionError('Secret key cannot be exposed');
137
- });
119
+ async secretKey() {
120
+ throw new core_1.ProhibitedActionError('Secret key cannot be exposed');
138
121
  }
139
- sign(bytes, watermark) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- const watermarkedBytes = (0, utils_2.appendWatermark)(bytes, watermark);
142
- const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');
143
- let messageToSend = [];
144
- messageToSend.push((0, utils_2.transformPathToBuffer)(this.path));
145
- messageToSend = (0, utils_2.chunkOperation)(messageToSend, watermarkedBytes2buff);
146
- const ledgerResponse = yield this.signWithLedger(messageToSend);
147
- let signature;
148
- if (this.derivationType === DerivationType.ED25519 ||
149
- this.derivationType === DerivationType.BIP32_ED25519) {
150
- signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');
151
- }
152
- else {
153
- if (!(0, utils_2.validateResponse)(ledgerResponse)) {
154
- throw new errors_1.InvalidLedgerResponseError('Invalid signature return by ledger unable to parse the response');
155
- }
156
- const idxLengthRVal = 3; // Third element of response is length of r value
157
- const rValue = (0, utils_2.extractValue)(idxLengthRVal, ledgerResponse);
158
- const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;
159
- const sValue = (0, utils_2.extractValue)(idxLengthSVal, ledgerResponse);
160
- const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);
161
- signature = signatureBuffer.toString('hex');
122
+ async sign(bytes, watermark) {
123
+ const watermarkedBytes = (0, utils_2.appendWatermark)(bytes, watermark);
124
+ const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');
125
+ let messageToSend = [];
126
+ messageToSend.push((0, utils_2.transformPathToBuffer)(this.path));
127
+ messageToSend = (0, utils_2.chunkOperation)(messageToSend, watermarkedBytes2buff);
128
+ const ledgerResponse = await this.signWithLedger(messageToSend);
129
+ let signature;
130
+ if (this.derivationType === DerivationType.ED25519 ||
131
+ this.derivationType === DerivationType.BIP32_ED25519) {
132
+ signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');
133
+ }
134
+ else {
135
+ if (!(0, utils_2.validateResponse)(ledgerResponse)) {
136
+ throw new errors_1.InvalidLedgerResponseError('Invalid signature return by ledger unable to parse the response');
162
137
  }
163
- return {
164
- bytes,
165
- sig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.GenericSignature),
166
- prefixSig: (0, utils_1.b58Encode)(signature, this.getPrefixes().prefSig),
167
- sbytes: bytes + signature,
168
- };
169
- });
138
+ const idxLengthRVal = 3; // Third element of response is length of r value
139
+ const rValue = (0, utils_2.extractValue)(idxLengthRVal, ledgerResponse);
140
+ const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;
141
+ const sValue = (0, utils_2.extractValue)(idxLengthSVal, ledgerResponse);
142
+ const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);
143
+ signature = signatureBuffer.toString('hex');
144
+ }
145
+ return {
146
+ bytes,
147
+ sig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.GenericSignature),
148
+ prefixSig: (0, utils_1.b58Encode)(signature, this.getPrefixes().prefSig),
149
+ sbytes: bytes + signature,
150
+ };
170
151
  }
171
- signWithLedger(message) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- // first element of the message represents the path
174
- let ledgerResponse = yield this.transport.send(this.CLA, this.INS_SIGN, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, message[0]);
175
- for (let i = 1; i < message.length; i++) {
176
- const p1 = i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;
177
- ledgerResponse = yield this.transport.send(this.CLA, this.INS_SIGN, p1, this.derivationType, message[i]);
178
- }
179
- return ledgerResponse;
180
- });
152
+ async signWithLedger(message) {
153
+ // first element of the message represents the path
154
+ let ledgerResponse = await this.transport.send(this.CLA, this.INS_SIGN, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, message[0]);
155
+ for (let i = 1; i < message.length; i++) {
156
+ const p1 = i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;
157
+ ledgerResponse = await this.transport.send(this.CLA, this.INS_SIGN, p1, this.derivationType, message[i]);
158
+ }
159
+ return ledgerResponse;
181
160
  }
182
161
  getPrefixes() {
183
162
  if (this.derivationType === DerivationType.ED25519 ||
package/dist/lib/utils.js CHANGED
@@ -13,7 +13,7 @@ exports.extractValue = extractValue;
13
13
  const MAX_CHUNK_SIZE = 230;
14
14
  /**
15
15
  *
16
- * @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)
16
+ * 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)
17
17
  *
18
18
  * @param path The ledger derivation path (default is "44'/1729'/0'/0'")
19
19
  * @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
@@ -40,7 +40,7 @@ function transformPathToBuffer(path) {
40
40
  }
41
41
  /**
42
42
  *
43
- * @description Converts uncompressed ledger key to standard tezos binary representation
43
+ * Converts uncompressed ledger key to standard tezos binary representation
44
44
  */
45
45
  function compressPublicKey(publicKey, curve) {
46
46
  if (curve === 0x00 || curve === 0x03) {
@@ -62,7 +62,7 @@ function appendWatermark(bytes, watermark) {
62
62
  }
63
63
  /**
64
64
  *
65
- * @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
65
+ * 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
66
66
  * @param messageToSend The message to send to the Ledger device
67
67
  * @param operation The operation which will be chunk if its length is over 230 bytes
68
68
  * @returns The instruction to send to the Ledger device
@@ -80,7 +80,7 @@ function chunkOperation(messageToSend, operation) {
80
80
  }
81
81
  /**
82
82
  *
83
- * @description Verify if the signature returned by the ledger for tz2 and tz3 is valid
83
+ * Verify if the signature returned by the ledger for tz2 and tz3 is valid
84
84
  * @param response The signature returned by the Ledger (return from the signWithLedger function)
85
85
  * @returns True if valid, false otherwise
86
86
  */
@@ -108,7 +108,7 @@ function validateResponse(response) {
108
108
  }
109
109
  /**
110
110
  *
111
- * @description Extract a part of the response returned by the Ledger
111
+ * Extract a part of the response returned by the Ledger
112
112
  * @param idxLength The index in the response from the Ledger that corresponds to the length of the part to extract
113
113
  * @param response The signature returned by the Ledger (return from the signWithLedger function)
114
114
  * @returns An object that contains the extracted buffer, the index where it starts in the response and the length of the extracted part
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
5
5
  exports.VERSION = {
6
- "commitHash": "105a7b15cfb862a0732c204e0e9741098d697775",
7
- "version": "24.2.0"
6
+ "commitHash": "27675679db6515e8b092195ef5c58c2c0ea5f5c8",
7
+ "version": "24.3.0-beta.0"
8
8
  };
@@ -1,40 +1,8 @@
1
- import { PrefixV2, b58Encode } from '@taquito/utils';
1
+ import { b58Encode, PrefixV2 } from '@taquito/utils';
2
2
  import { hash } from '@stablelib/blake2b';
3
3
  import { ParameterValidationError, TaquitoError, InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';
4
4
  export { InvalidDerivationPathError } from '@taquito/core';
5
5
 
6
- /******************************************************************************
7
- Copyright (c) Microsoft Corporation.
8
-
9
- Permission to use, copy, modify, and/or distribute this software for any
10
- purpose with or without fee is hereby granted.
11
-
12
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
- PERFORMANCE OF THIS SOFTWARE.
19
- ***************************************************************************** */
20
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
21
-
22
-
23
- function __awaiter(thisArg, _arguments, P, generator) {
24
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
- return new (P || (P = Promise))(function (resolve, reject) {
26
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
- step((generator = generator.apply(thisArg, _arguments || [])).next());
30
- });
31
- }
32
-
33
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
34
- var e = new Error(message);
35
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
36
- };
37
-
38
6
  /*
39
7
  * Some code in this file is adapted from sotez
40
8
  * Copyright (c) 2018 Andrew Kishino
@@ -42,7 +10,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
42
10
  const MAX_CHUNK_SIZE = 230;
43
11
  /**
44
12
  *
45
- * @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)
13
+ * 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)
46
14
  *
47
15
  * @param path The ledger derivation path (default is "44'/1729'/0'/0'")
48
16
  * @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
@@ -69,7 +37,7 @@ function transformPathToBuffer(path) {
69
37
  }
70
38
  /**
71
39
  *
72
- * @description Converts uncompressed ledger key to standard tezos binary representation
40
+ * Converts uncompressed ledger key to standard tezos binary representation
73
41
  */
74
42
  function compressPublicKey(publicKey, curve) {
75
43
  if (curve === 0x00 || curve === 0x03) {
@@ -91,7 +59,7 @@ function appendWatermark(bytes, watermark) {
91
59
  }
92
60
  /**
93
61
  *
94
- * @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
62
+ * 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
95
63
  * @param messageToSend The message to send to the Ledger device
96
64
  * @param operation The operation which will be chunk if its length is over 230 bytes
97
65
  * @returns The instruction to send to the Ledger device
@@ -109,7 +77,7 @@ function chunkOperation(messageToSend, operation) {
109
77
  }
110
78
  /**
111
79
  *
112
- * @description Verify if the signature returned by the ledger for tz2 and tz3 is valid
80
+ * Verify if the signature returned by the ledger for tz2 and tz3 is valid
113
81
  * @param response The signature returned by the Ledger (return from the signWithLedger function)
114
82
  * @returns True if valid, false otherwise
115
83
  */
@@ -137,7 +105,7 @@ function validateResponse(response) {
137
105
  }
138
106
  /**
139
107
  *
140
- * @description Extract a part of the response returned by the Ledger
108
+ * Extract a part of the response returned by the Ledger
141
109
  * @param idxLength The index in the response from the Ledger that corresponds to the length of the part to extract
142
110
  * @param response The signature returned by the Ledger (return from the signWithLedger function)
143
111
  * @returns An object that contains the extracted buffer, the index where it starts in the response and the length of the extracted part
@@ -157,7 +125,7 @@ function extractValue(idxLength, response) {
157
125
 
158
126
  /**
159
127
  * @category Error
160
- * @description Error that indicates an invalid or unparseable ledger response
128
+ * Error that indicates an invalid or unparseable ledger response
161
129
  */
162
130
  class InvalidLedgerResponseError extends TaquitoError {
163
131
  constructor(message) {
@@ -168,7 +136,7 @@ class InvalidLedgerResponseError extends TaquitoError {
168
136
  }
169
137
  /**
170
138
  * @category Error
171
- * @description Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
139
+ * Error that indicates a failure when trying to retrieve a Public Key from Ledger signer
172
140
  */
173
141
  class PublicKeyRetrievalError extends TaquitoError {
174
142
  constructor(cause) {
@@ -180,7 +148,7 @@ class PublicKeyRetrievalError extends TaquitoError {
180
148
  }
181
149
  /**
182
150
  * @category Error
183
- * @description Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
151
+ * Error that indicates a failure when trying to retrieve a Public Key Hash from Ledger signer
184
152
  */
185
153
  class PublicKeyHashRetrievalError extends TaquitoError {
186
154
  constructor() {
@@ -191,7 +159,7 @@ class PublicKeyHashRetrievalError extends TaquitoError {
191
159
  }
192
160
  /**
193
161
  * @category Error
194
- * @description Error that indicates an invalid derivation type being passed or used
162
+ * Error that indicates an invalid derivation type being passed or used
195
163
  */
196
164
  class InvalidDerivationTypeError extends ParameterValidationError {
197
165
  constructor(derivationType) {
@@ -204,8 +172,8 @@ class InvalidDerivationTypeError extends ParameterValidationError {
204
172
 
205
173
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
206
174
  const VERSION = {
207
- "commitHash": "105a7b15cfb862a0732c204e0e9741098d697775",
208
- "version": "24.2.0"
175
+ "commitHash": "27675679db6515e8b092195ef5c58c2c0ea5f5c8",
176
+ "version": "24.3.0-beta.0"
209
177
  };
210
178
 
211
179
  /**
@@ -224,7 +192,7 @@ const HDPathTemplate = (account) => {
224
192
  };
225
193
  /**
226
194
  *
227
- * @description Implementation of the Signer interface that will allow signing operation from a Ledger Nano device
195
+ * Implementation of the Signer interface that will allow signing operation from a Ledger Nano device
228
196
  *
229
197
  * @param transport A transport instance from LedgerJS libraries depending on the platform used (e.g. Web, Node)
230
198
  * @param path The ledger derivation path (default is "44'/1729'/0'/0'")
@@ -274,96 +242,84 @@ class LedgerSigner {
274
242
  throw new InvalidDerivationTypeError(derivationType.toString());
275
243
  }
276
244
  }
277
- publicKeyHash() {
278
- return __awaiter(this, void 0, void 0, function* () {
279
- if (!this._publicKeyHash) {
280
- yield this.publicKey();
281
- }
282
- if (this._publicKeyHash) {
283
- return this._publicKeyHash;
284
- }
285
- throw new PublicKeyHashRetrievalError();
286
- });
245
+ async publicKeyHash() {
246
+ if (!this._publicKeyHash) {
247
+ await this.publicKey();
248
+ }
249
+ if (this._publicKeyHash) {
250
+ return this._publicKeyHash;
251
+ }
252
+ throw new PublicKeyHashRetrievalError();
287
253
  }
288
- publicKey() {
289
- return __awaiter(this, void 0, void 0, function* () {
290
- if (this._publicKey) {
291
- return this._publicKey;
292
- }
293
- const responseLedger = yield this.getLedgerPublicKey();
294
- const publicKeyLength = responseLedger[0];
295
- const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
296
- const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);
297
- const prefixes = this.getPrefixes();
298
- const publicKey = b58Encode(compressedPublicKey, prefixes.prefPk);
299
- const publicKeyHash = b58Encode(hash(compressedPublicKey, 20), prefixes.prefPkh);
300
- this._publicKey = publicKey;
301
- this._publicKeyHash = publicKeyHash;
302
- return publicKey;
303
- });
254
+ async publicKey() {
255
+ if (this._publicKey) {
256
+ return this._publicKey;
257
+ }
258
+ const responseLedger = await this.getLedgerPublicKey();
259
+ const publicKeyLength = responseLedger[0];
260
+ const rawPublicKey = responseLedger.slice(1, 1 + publicKeyLength);
261
+ const compressedPublicKey = compressPublicKey(rawPublicKey, this.derivationType);
262
+ const prefixes = this.getPrefixes();
263
+ const publicKey = b58Encode(compressedPublicKey, prefixes.prefPk);
264
+ const publicKeyHash = b58Encode(hash(compressedPublicKey, 20), prefixes.prefPkh);
265
+ this._publicKey = publicKey;
266
+ this._publicKeyHash = publicKeyHash;
267
+ return publicKey;
304
268
  }
305
- getLedgerPublicKey() {
306
- return __awaiter(this, void 0, void 0, function* () {
307
- try {
308
- let ins = this.INS_PROMPT_PUBLIC_KEY;
309
- if (this.prompt === false) {
310
- ins = this.INS_GET_PUBLIC_KEY;
311
- }
312
- const responseLedger = yield this.transport.send(this.CLA, ins, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, transformPathToBuffer(this.path));
313
- return responseLedger;
314
- }
315
- catch (error) {
316
- throw new PublicKeyRetrievalError(error);
269
+ async getLedgerPublicKey() {
270
+ try {
271
+ let ins = this.INS_PROMPT_PUBLIC_KEY;
272
+ if (this.prompt === false) {
273
+ ins = this.INS_GET_PUBLIC_KEY;
317
274
  }
318
- });
275
+ const responseLedger = await this.transport.send(this.CLA, ins, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, transformPathToBuffer(this.path));
276
+ return responseLedger;
277
+ }
278
+ catch (error) {
279
+ throw new PublicKeyRetrievalError(error);
280
+ }
319
281
  }
320
- secretKey() {
321
- return __awaiter(this, void 0, void 0, function* () {
322
- throw new ProhibitedActionError('Secret key cannot be exposed');
323
- });
282
+ async secretKey() {
283
+ throw new ProhibitedActionError('Secret key cannot be exposed');
324
284
  }
325
- sign(bytes, watermark) {
326
- return __awaiter(this, void 0, void 0, function* () {
327
- const watermarkedBytes = appendWatermark(bytes, watermark);
328
- const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');
329
- let messageToSend = [];
330
- messageToSend.push(transformPathToBuffer(this.path));
331
- messageToSend = chunkOperation(messageToSend, watermarkedBytes2buff);
332
- const ledgerResponse = yield this.signWithLedger(messageToSend);
333
- let signature;
334
- if (this.derivationType === DerivationType.ED25519 ||
335
- this.derivationType === DerivationType.BIP32_ED25519) {
336
- signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');
337
- }
338
- else {
339
- if (!validateResponse(ledgerResponse)) {
340
- throw new InvalidLedgerResponseError('Invalid signature return by ledger unable to parse the response');
341
- }
342
- const idxLengthRVal = 3; // Third element of response is length of r value
343
- const rValue = extractValue(idxLengthRVal, ledgerResponse);
344
- const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;
345
- const sValue = extractValue(idxLengthSVal, ledgerResponse);
346
- const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);
347
- signature = signatureBuffer.toString('hex');
285
+ async sign(bytes, watermark) {
286
+ const watermarkedBytes = appendWatermark(bytes, watermark);
287
+ const watermarkedBytes2buff = Buffer.from(watermarkedBytes, 'hex');
288
+ let messageToSend = [];
289
+ messageToSend.push(transformPathToBuffer(this.path));
290
+ messageToSend = chunkOperation(messageToSend, watermarkedBytes2buff);
291
+ const ledgerResponse = await this.signWithLedger(messageToSend);
292
+ let signature;
293
+ if (this.derivationType === DerivationType.ED25519 ||
294
+ this.derivationType === DerivationType.BIP32_ED25519) {
295
+ signature = ledgerResponse.slice(0, ledgerResponse.length - 2).toString('hex');
296
+ }
297
+ else {
298
+ if (!validateResponse(ledgerResponse)) {
299
+ throw new InvalidLedgerResponseError('Invalid signature return by ledger unable to parse the response');
348
300
  }
349
- return {
350
- bytes,
351
- sig: b58Encode(signature, PrefixV2.GenericSignature),
352
- prefixSig: b58Encode(signature, this.getPrefixes().prefSig),
353
- sbytes: bytes + signature,
354
- };
355
- });
301
+ const idxLengthRVal = 3; // Third element of response is length of r value
302
+ const rValue = extractValue(idxLengthRVal, ledgerResponse);
303
+ const idxLengthSVal = rValue.idxValueStart + rValue.length + 1;
304
+ const sValue = extractValue(idxLengthSVal, ledgerResponse);
305
+ const signatureBuffer = Buffer.concat([rValue.buffer, sValue.buffer]);
306
+ signature = signatureBuffer.toString('hex');
307
+ }
308
+ return {
309
+ bytes,
310
+ sig: b58Encode(signature, PrefixV2.GenericSignature),
311
+ prefixSig: b58Encode(signature, this.getPrefixes().prefSig),
312
+ sbytes: bytes + signature,
313
+ };
356
314
  }
357
- signWithLedger(message) {
358
- return __awaiter(this, void 0, void 0, function* () {
359
- // first element of the message represents the path
360
- let ledgerResponse = yield this.transport.send(this.CLA, this.INS_SIGN, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, message[0]);
361
- for (let i = 1; i < message.length; i++) {
362
- const p1 = i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;
363
- ledgerResponse = yield this.transport.send(this.CLA, this.INS_SIGN, p1, this.derivationType, message[i]);
364
- }
365
- return ledgerResponse;
366
- });
315
+ async signWithLedger(message) {
316
+ // first element of the message represents the path
317
+ let ledgerResponse = await this.transport.send(this.CLA, this.INS_SIGN, this.FIRST_MESSAGE_SEQUENCE, this.derivationType, message[0]);
318
+ for (let i = 1; i < message.length; i++) {
319
+ const p1 = i === message.length - 1 ? this.LAST_MESSAGE_SEQUENCE : this.OTHER_MESSAGE_SEQUENCE;
320
+ ledgerResponse = await this.transport.send(this.CLA, this.INS_SIGN, p1, this.derivationType, message[i]);
321
+ }
322
+ return ledgerResponse;
367
323
  }
368
324
  getPrefixes() {
369
325
  if (this.derivationType === DerivationType.ED25519 ||
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-ledger-signer.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"taquito-ledger-signer.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}