@taquito/ledger-signer 24.2.0 → 24.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/errors.js +4 -4
- package/dist/lib/taquito-ledger-signer.js +72 -93
- package/dist/lib/utils.js +5 -5
- package/dist/lib/version.js +2 -2
- package/dist/taquito-ledger-signer.es6.js +84 -128
- package/dist/taquito-ledger-signer.es6.js.map +1 -1
- package/dist/taquito-ledger-signer.umd.js +351 -395
- package/dist/taquito-ledger-signer.umd.js.map +1 -1
- package/dist/types/errors.d.ts +4 -4
- package/dist/types/taquito-ledger-signer.d.ts +1 -1
- package/dist/types/utils.d.ts +7 -7
- package/package.json +24 -11
- package/src/errors.ts +4 -4
- package/src/taquito-ledger-signer.ts +1 -1
- package/src/utils.ts +5 -5
- package/src/version.ts +2 -2
- package/LICENSE +0 -202
- package/coverage/clover.xml +0 -185
- package/coverage/coverage-final.json +0 -5
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/errors.ts.html +0 -229
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -161
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/taquito-ledger-signer.ts.html +0 -790
- package/coverage/lcov-report/utils.ts.html +0 -475
- package/coverage/lcov-report/version.ts.html +0 -103
- package/coverage/lcov.info +0 -296
package/dist/lib/errors.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.InvalidDerivationTypeError = exports.PublicKeyHashRetrievalError = expor
|
|
|
4
4
|
const core_1 = require("@taquito/core");
|
|
5
5
|
/**
|
|
6
6
|
* @category Error
|
|
7
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
package/dist/lib/version.js
CHANGED
|
@@ -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": "
|
|
7
|
-
"version": "24.
|
|
6
|
+
"commitHash": "05df48fee92f846cba793920d6fa829afd6a1847",
|
|
7
|
+
"version": "24.3.0-beta.1"
|
|
8
8
|
};
|
|
@@ -1,40 +1,8 @@
|
|
|
1
|
-
import {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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": "
|
|
208
|
-
"version": "24.
|
|
175
|
+
"commitHash": "05df48fee92f846cba793920d6fa829afd6a1847",
|
|
176
|
+
"version": "24.3.0-beta.1"
|
|
209
177
|
};
|
|
210
178
|
|
|
211
179
|
/**
|
|
@@ -224,7 +192,7 @@ const HDPathTemplate = (account) => {
|
|
|
224
192
|
};
|
|
225
193
|
/**
|
|
226
194
|
*
|
|
227
|
-
*
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|