@taquito/remote-signer 17.3.2 → 17.4.0-beta-RC.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.
- package/dist/lib/errors.js +0 -1
- package/dist/lib/taquito-remote-signer.js +20 -15
- package/dist/lib/version.js +2 -3
- package/dist/taquito-remote-signer.es6.js +191 -183
- package/dist/taquito-remote-signer.es6.js.map +1 -1
- package/dist/taquito-remote-signer.umd.js +191 -189
- package/dist/taquito-remote-signer.umd.js.map +1 -1
- package/dist/types/errors.d.ts +40 -40
- package/dist/types/taquito-remote-signer.d.ts +30 -30
- package/dist/types/version.d.ts +4 -4
- package/package.json +28 -30
- package/signature.json +4 -6
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/taquito-remote-signer.js.map +0 -1
- package/dist/lib/version.js.map +0 -1
package/dist/lib/errors.js
CHANGED
|
@@ -48,9 +48,9 @@ class RemoteSigner {
|
|
|
48
48
|
this.rootUrl = rootUrl;
|
|
49
49
|
this.options = options;
|
|
50
50
|
this.http = http;
|
|
51
|
-
const pkhValidation = utils_1.validateKeyHash(this.pkh);
|
|
51
|
+
const pkhValidation = (0, utils_1.validateKeyHash)(this.pkh);
|
|
52
52
|
if (pkhValidation !== utils_1.ValidationResult.VALID) {
|
|
53
|
-
throw new core_1.InvalidKeyHashError(this.pkh, utils_1.invalidDetail(pkhValidation));
|
|
53
|
+
throw new core_1.InvalidKeyHashError(this.pkh, (0, utils_1.invalidDetail)(pkhValidation));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
publicKeyHash() {
|
|
@@ -60,7 +60,13 @@ class RemoteSigner {
|
|
|
60
60
|
}
|
|
61
61
|
createURL(path) {
|
|
62
62
|
// Trim trailing slashes because it is assumed to be included in path
|
|
63
|
-
|
|
63
|
+
// the regex solution is prone to ReDoS. Please see: https://stackoverflow.com/questions/6680825/return-string-without-trailing-slash#comment124306698_6680877
|
|
64
|
+
// We also got a CodeQL error for the regex based solution
|
|
65
|
+
let rootUrl = this.rootUrl;
|
|
66
|
+
while (rootUrl.endsWith('/')) {
|
|
67
|
+
rootUrl = rootUrl.slice(0, -1);
|
|
68
|
+
}
|
|
69
|
+
return `${rootUrl}${path}`;
|
|
64
70
|
}
|
|
65
71
|
publicKey() {
|
|
66
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -90,11 +96,11 @@ class RemoteSigner {
|
|
|
90
96
|
sign(bytes, watermark) {
|
|
91
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
98
|
try {
|
|
93
|
-
let bb = utils_1.hex2buf(bytes);
|
|
99
|
+
let bb = (0, utils_1.hex2buf)(bytes);
|
|
94
100
|
if (typeof watermark !== 'undefined') {
|
|
95
|
-
bb = utils_1.mergebuf(watermark, bb);
|
|
101
|
+
bb = (0, utils_1.mergebuf)(watermark, bb);
|
|
96
102
|
}
|
|
97
|
-
const watermarkedBytes = utils_1.buf2hex(typedarray_to_buffer_1.default(bb));
|
|
103
|
+
const watermarkedBytes = (0, utils_1.buf2hex)((0, typedarray_to_buffer_1.default)(bb));
|
|
98
104
|
const { signature } = yield this.http.createRequest({
|
|
99
105
|
url: this.createURL(`/keys/${this.pkh}`),
|
|
100
106
|
method: 'POST',
|
|
@@ -103,21 +109,21 @@ class RemoteSigner {
|
|
|
103
109
|
const pref = signature.startsWith('sig')
|
|
104
110
|
? signature.substring(0, 3)
|
|
105
111
|
: signature.substring(0, 5);
|
|
106
|
-
if (!utils_1.isValidPrefix(pref)) {
|
|
107
|
-
throw new core_1.InvalidSignatureError(signature, utils_1.invalidDetail(utils_1.ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
|
|
112
|
+
if (!(0, utils_1.isValidPrefix)(pref)) {
|
|
113
|
+
throw new core_1.InvalidSignatureError(signature, (0, utils_1.invalidDetail)(utils_1.ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
|
|
108
114
|
}
|
|
109
|
-
const decoded = utils_1.b58cdecode(signature, utils_1.prefix[pref]);
|
|
115
|
+
const decoded = (0, utils_1.b58cdecode)(signature, utils_1.prefix[pref]);
|
|
110
116
|
const pk = yield this.publicKey();
|
|
111
117
|
yield this.verifyPublicKey(pk);
|
|
112
|
-
const signatureVerified = utils_1.verifySignature(watermarkedBytes, pk, signature);
|
|
118
|
+
const signatureVerified = (0, utils_1.verifySignature)(watermarkedBytes, pk, signature);
|
|
113
119
|
if (!signatureVerified) {
|
|
114
120
|
throw new errors_1.SignatureVerificationError(watermarkedBytes, signature);
|
|
115
121
|
}
|
|
116
122
|
return {
|
|
117
123
|
bytes,
|
|
118
|
-
sig: utils_1.b58cencode(decoded, utils_1.prefix.sig),
|
|
124
|
+
sig: (0, utils_1.b58cencode)(decoded, utils_1.prefix.sig),
|
|
119
125
|
prefixSig: signature,
|
|
120
|
-
sbytes: bytes + utils_1.buf2hex(typedarray_to_buffer_1.default(decoded)),
|
|
126
|
+
sbytes: bytes + (0, utils_1.buf2hex)((0, typedarray_to_buffer_1.default)(decoded)),
|
|
121
127
|
};
|
|
122
128
|
}
|
|
123
129
|
catch (ex) {
|
|
@@ -139,8 +145,8 @@ class RemoteSigner {
|
|
|
139
145
|
verifyPublicKey(publicKey) {
|
|
140
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
147
|
const curve = publicKey.substring(0, 2);
|
|
142
|
-
const _publicKey = utils_1.b58cdecode(publicKey, pref[curve].pk);
|
|
143
|
-
const publicKeyHash = utils_1.b58cencode(blake2b_1.hash(_publicKey, 20), pref[curve].pkh);
|
|
148
|
+
const _publicKey = (0, utils_1.b58cdecode)(publicKey, pref[curve].pk);
|
|
149
|
+
const publicKeyHash = (0, utils_1.b58cencode)((0, blake2b_1.hash)(_publicKey, 20), pref[curve].pkh);
|
|
144
150
|
if (publicKeyHash !== this.pkh) {
|
|
145
151
|
throw new errors_1.PublicKeyVerificationError(publicKey, publicKeyHash, this.pkh);
|
|
146
152
|
}
|
|
@@ -148,4 +154,3 @@ class RemoteSigner {
|
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
exports.RemoteSigner = RemoteSigner;
|
|
151
|
-
//# sourceMappingURL=taquito-remote-signer.js.map
|
package/dist/lib/version.js
CHANGED
|
@@ -3,7 +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 OR CHECKIN!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "17.
|
|
6
|
+
"commitHash": "4f44dd73b7659554c167acb80f0c20f222f893a5",
|
|
7
|
+
"version": "17.4.0-beta-RC.0"
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=version.js.map
|
|
@@ -18,6 +18,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
18
18
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
19
|
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
22
|
+
|
|
21
23
|
|
|
22
24
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
23
25
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -34,193 +36,199 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
34
36
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
35
37
|
};
|
|
36
38
|
|
|
37
|
-
/**
|
|
38
|
-
* @category Error
|
|
39
|
-
* @description Error that indicates an unauthorized operation being attempted
|
|
40
|
-
*/
|
|
41
|
-
class OperationNotAuthorizedError extends PermissionDeniedError {
|
|
42
|
-
constructor(message, cause) {
|
|
43
|
-
super();
|
|
44
|
-
this.message = message;
|
|
45
|
-
this.cause = cause;
|
|
46
|
-
this.name = 'OperationNotAuthorized';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* @category Error
|
|
51
|
-
* @description Error that indicates bad signing data
|
|
52
|
-
*/
|
|
53
|
-
class BadSigningDataError extends TaquitoError {
|
|
54
|
-
constructor(cause, bytes, watermark) {
|
|
55
|
-
super();
|
|
56
|
-
this.cause = cause;
|
|
57
|
-
this.bytes = bytes;
|
|
58
|
-
this.watermark = watermark;
|
|
59
|
-
this.name = 'BadSigningData';
|
|
60
|
-
this.message = watermark
|
|
61
|
-
? `Invalid signing data with watermark`
|
|
62
|
-
: `Invalid signing data: "${bytes}"`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @category Error
|
|
67
|
-
* @description Error that indicates a mismatch between the initialized and the requested public key
|
|
68
|
-
*/
|
|
69
|
-
class PublicKeyVerificationError extends TaquitoError {
|
|
70
|
-
constructor(requestedPk, requestedPkh, initializedPkh) {
|
|
71
|
-
super();
|
|
72
|
-
this.requestedPk = requestedPk;
|
|
73
|
-
this.requestedPkh = requestedPkh;
|
|
74
|
-
this.initializedPkh = initializedPkh;
|
|
75
|
-
this.name = 'PublicKeyVerificationFailedError';
|
|
76
|
-
this.message = `Requested pk "${requestedPk}" has pkh "${requestedPkh}" deesn't match initialized pkh "${initializedPkh}."`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @category Error
|
|
81
|
-
* @description Error
|
|
82
|
-
*/
|
|
83
|
-
class SignatureVerificationError extends TaquitoError {
|
|
84
|
-
constructor(bytes, signature) {
|
|
85
|
-
super();
|
|
86
|
-
this.bytes = bytes;
|
|
87
|
-
this.signature = signature;
|
|
88
|
-
this.name = 'SignatureVerificationFailedError';
|
|
89
|
-
this.name = 'SignatureVerificationFailedError';
|
|
90
|
-
this.message = `Invalid signature of bytes failed verification agaisnt public key.`;
|
|
91
|
-
}
|
|
39
|
+
/**
|
|
40
|
+
* @category Error
|
|
41
|
+
* @description Error that indicates an unauthorized operation being attempted
|
|
42
|
+
*/
|
|
43
|
+
class OperationNotAuthorizedError extends PermissionDeniedError {
|
|
44
|
+
constructor(message, cause) {
|
|
45
|
+
super();
|
|
46
|
+
this.message = message;
|
|
47
|
+
this.cause = cause;
|
|
48
|
+
this.name = 'OperationNotAuthorized';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @category Error
|
|
53
|
+
* @description Error that indicates bad signing data
|
|
54
|
+
*/
|
|
55
|
+
class BadSigningDataError extends TaquitoError {
|
|
56
|
+
constructor(cause, bytes, watermark) {
|
|
57
|
+
super();
|
|
58
|
+
this.cause = cause;
|
|
59
|
+
this.bytes = bytes;
|
|
60
|
+
this.watermark = watermark;
|
|
61
|
+
this.name = 'BadSigningData';
|
|
62
|
+
this.message = watermark
|
|
63
|
+
? `Invalid signing data with watermark`
|
|
64
|
+
: `Invalid signing data: "${bytes}"`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @category Error
|
|
69
|
+
* @description Error that indicates a mismatch between the initialized and the requested public key
|
|
70
|
+
*/
|
|
71
|
+
class PublicKeyVerificationError extends TaquitoError {
|
|
72
|
+
constructor(requestedPk, requestedPkh, initializedPkh) {
|
|
73
|
+
super();
|
|
74
|
+
this.requestedPk = requestedPk;
|
|
75
|
+
this.requestedPkh = requestedPkh;
|
|
76
|
+
this.initializedPkh = initializedPkh;
|
|
77
|
+
this.name = 'PublicKeyVerificationFailedError';
|
|
78
|
+
this.message = `Requested pk "${requestedPk}" has pkh "${requestedPkh}" deesn't match initialized pkh "${initializedPkh}."`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @category Error
|
|
83
|
+
* @description Error
|
|
84
|
+
*/
|
|
85
|
+
class SignatureVerificationError extends TaquitoError {
|
|
86
|
+
constructor(bytes, signature) {
|
|
87
|
+
super();
|
|
88
|
+
this.bytes = bytes;
|
|
89
|
+
this.signature = signature;
|
|
90
|
+
this.name = 'SignatureVerificationFailedError';
|
|
91
|
+
this.name = 'SignatureVerificationFailedError';
|
|
92
|
+
this.message = `Invalid signature of bytes failed verification agaisnt public key.`;
|
|
93
|
+
}
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
95
|
-
const VERSION = {
|
|
96
|
-
"commitHash": "
|
|
97
|
-
"version": "17.
|
|
96
|
+
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
97
|
+
const VERSION = {
|
|
98
|
+
"commitHash": "4f44dd73b7659554c167acb80f0c20f222f893a5",
|
|
99
|
+
"version": "17.4.0-beta-RC.0"
|
|
98
100
|
};
|
|
99
101
|
|
|
100
|
-
const pref = {
|
|
101
|
-
ed: {
|
|
102
|
-
pk: prefix['edpk'],
|
|
103
|
-
sk: prefix['edsk'],
|
|
104
|
-
pkh: prefix.tz1,
|
|
105
|
-
sig: prefix.edsig,
|
|
106
|
-
},
|
|
107
|
-
p2: {
|
|
108
|
-
pk: prefix['p2pk'],
|
|
109
|
-
sk: prefix['p2sk'],
|
|
110
|
-
pkh: prefix.tz3,
|
|
111
|
-
sig: prefix.p2sig,
|
|
112
|
-
},
|
|
113
|
-
sp: {
|
|
114
|
-
pk: prefix['sppk'],
|
|
115
|
-
sk: prefix['spsk'],
|
|
116
|
-
pkh: prefix.tz2,
|
|
117
|
-
sig: prefix.spsig,
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
class RemoteSigner {
|
|
121
|
-
constructor(pkh, rootUrl, options = {}, http = new HttpBackend()) {
|
|
122
|
-
this.pkh = pkh;
|
|
123
|
-
this.rootUrl = rootUrl;
|
|
124
|
-
this.options = options;
|
|
125
|
-
this.http = http;
|
|
126
|
-
const pkhValidation = validateKeyHash(this.pkh);
|
|
127
|
-
if (pkhValidation !== ValidationResult.VALID) {
|
|
128
|
-
throw new InvalidKeyHashError(this.pkh, invalidDetail(pkhValidation));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
publicKeyHash() {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
return this.pkh;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
createURL(path) {
|
|
137
|
-
// Trim trailing slashes because it is assumed to be included in path
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
throw new
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
102
|
+
const pref = {
|
|
103
|
+
ed: {
|
|
104
|
+
pk: prefix['edpk'],
|
|
105
|
+
sk: prefix['edsk'],
|
|
106
|
+
pkh: prefix.tz1,
|
|
107
|
+
sig: prefix.edsig,
|
|
108
|
+
},
|
|
109
|
+
p2: {
|
|
110
|
+
pk: prefix['p2pk'],
|
|
111
|
+
sk: prefix['p2sk'],
|
|
112
|
+
pkh: prefix.tz3,
|
|
113
|
+
sig: prefix.p2sig,
|
|
114
|
+
},
|
|
115
|
+
sp: {
|
|
116
|
+
pk: prefix['sppk'],
|
|
117
|
+
sk: prefix['spsk'],
|
|
118
|
+
pkh: prefix.tz2,
|
|
119
|
+
sig: prefix.spsig,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
class RemoteSigner {
|
|
123
|
+
constructor(pkh, rootUrl, options = {}, http = new HttpBackend()) {
|
|
124
|
+
this.pkh = pkh;
|
|
125
|
+
this.rootUrl = rootUrl;
|
|
126
|
+
this.options = options;
|
|
127
|
+
this.http = http;
|
|
128
|
+
const pkhValidation = validateKeyHash(this.pkh);
|
|
129
|
+
if (pkhValidation !== ValidationResult.VALID) {
|
|
130
|
+
throw new InvalidKeyHashError(this.pkh, invalidDetail(pkhValidation));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
publicKeyHash() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
return this.pkh;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
createURL(path) {
|
|
139
|
+
// Trim trailing slashes because it is assumed to be included in path
|
|
140
|
+
// the regex solution is prone to ReDoS. Please see: https://stackoverflow.com/questions/6680825/return-string-without-trailing-slash#comment124306698_6680877
|
|
141
|
+
// We also got a CodeQL error for the regex based solution
|
|
142
|
+
let rootUrl = this.rootUrl;
|
|
143
|
+
while (rootUrl.endsWith('/')) {
|
|
144
|
+
rootUrl = rootUrl.slice(0, -1);
|
|
145
|
+
}
|
|
146
|
+
return `${rootUrl}${path}`;
|
|
147
|
+
}
|
|
148
|
+
publicKey() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
try {
|
|
151
|
+
const { public_key } = yield this.http.createRequest({
|
|
152
|
+
url: this.createURL(`/keys/${this.pkh}`),
|
|
153
|
+
method: 'GET',
|
|
154
|
+
headers: this.options.headers,
|
|
155
|
+
});
|
|
156
|
+
return public_key;
|
|
157
|
+
}
|
|
158
|
+
catch (ex) {
|
|
159
|
+
if (ex instanceof HttpResponseError) {
|
|
160
|
+
if (ex.status === STATUS_CODE.NOT_FOUND) {
|
|
161
|
+
throw new PublicKeyNotFoundError(this.pkh, ex);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
throw ex;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
secretKey() {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
throw new ProhibitedActionError('Secret key cannot be exposed');
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
sign(bytes, watermark) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
try {
|
|
176
|
+
let bb = hex2buf(bytes);
|
|
177
|
+
if (typeof watermark !== 'undefined') {
|
|
178
|
+
bb = mergebuf(watermark, bb);
|
|
179
|
+
}
|
|
180
|
+
const watermarkedBytes = buf2hex(toBuffer(bb));
|
|
181
|
+
const { signature } = yield this.http.createRequest({
|
|
182
|
+
url: this.createURL(`/keys/${this.pkh}`),
|
|
183
|
+
method: 'POST',
|
|
184
|
+
headers: this.options.headers,
|
|
185
|
+
}, watermarkedBytes);
|
|
186
|
+
const pref = signature.startsWith('sig')
|
|
187
|
+
? signature.substring(0, 3)
|
|
188
|
+
: signature.substring(0, 5);
|
|
189
|
+
if (!isValidPrefix(pref)) {
|
|
190
|
+
throw new InvalidSignatureError(signature, invalidDetail(ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
|
|
191
|
+
}
|
|
192
|
+
const decoded = b58cdecode(signature, prefix[pref]);
|
|
193
|
+
const pk = yield this.publicKey();
|
|
194
|
+
yield this.verifyPublicKey(pk);
|
|
195
|
+
const signatureVerified = verifySignature(watermarkedBytes, pk, signature);
|
|
196
|
+
if (!signatureVerified) {
|
|
197
|
+
throw new SignatureVerificationError(watermarkedBytes, signature);
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
bytes,
|
|
201
|
+
sig: b58cencode(decoded, prefix.sig),
|
|
202
|
+
prefixSig: signature,
|
|
203
|
+
sbytes: bytes + buf2hex(toBuffer(decoded)),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
catch (ex) {
|
|
207
|
+
if (ex instanceof HttpResponseError) {
|
|
208
|
+
if (ex.status === STATUS_CODE.NOT_FOUND) {
|
|
209
|
+
throw new PublicKeyNotFoundError(this.pkh, ex);
|
|
210
|
+
}
|
|
211
|
+
else if (ex.status === STATUS_CODE.FORBIDDEN) {
|
|
212
|
+
throw new OperationNotAuthorizedError('Signing Operation not authorized', ex);
|
|
213
|
+
}
|
|
214
|
+
else if (ex.status === STATUS_CODE.BAD_REQUEST) {
|
|
215
|
+
throw new BadSigningDataError(ex, bytes, watermark);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
throw ex;
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
verifyPublicKey(publicKey) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const curve = publicKey.substring(0, 2);
|
|
225
|
+
const _publicKey = b58cdecode(publicKey, pref[curve].pk);
|
|
226
|
+
const publicKeyHash = b58cencode(hash(_publicKey, 20), pref[curve].pkh);
|
|
227
|
+
if (publicKeyHash !== this.pkh) {
|
|
228
|
+
throw new PublicKeyVerificationError(publicKey, publicKeyHash, this.pkh);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
224
232
|
}
|
|
225
233
|
|
|
226
234
|
export { RemoteSigner, VERSION };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-remote-signer.es6.js","sources":["../src/errors.ts","../src/version.ts","../src/taquito-remote-signer.ts"],"sourcesContent":["import { PermissionDeniedError, TaquitoError } from '@taquito/core';\n\n/**\n * @category Error\n * @description Error that indicates an unauthorized operation being attempted\n */\nexport class OperationNotAuthorizedError extends PermissionDeniedError {\n constructor(public readonly message: string, public readonly cause: any) {\n super();\n this.name = 'OperationNotAuthorized';\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates bad signing data\n */\nexport class BadSigningDataError extends TaquitoError {\n constructor(\n public readonly cause: any,\n public readonly bytes: string,\n readonly watermark?: Uint8Array\n ) {\n super();\n this.name = 'BadSigningData';\n this.message = watermark\n ? `Invalid signing data with watermark`\n : `Invalid signing data: \"${bytes}\"`;\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates a mismatch between the initialized and the requested public key\n */\nexport class PublicKeyVerificationError extends TaquitoError {\n constructor(\n public readonly requestedPk: string,\n public readonly requestedPkh: string,\n public readonly initializedPkh: string\n ) {\n super();\n this.name = 'PublicKeyVerificationFailedError';\n this.message = `Requested pk \"${requestedPk}\" has pkh \"${requestedPkh}\" deesn't match initialized pkh \"${initializedPkh}.\"`;\n }\n}\n\n/**\n * @category Error\n * @description Error\n */\nexport class SignatureVerificationError extends TaquitoError {\n public name = 'SignatureVerificationFailedError';\n constructor(public readonly bytes: string, public readonly signature: string) {\n super();\n this.name = 'SignatureVerificationFailedError';\n this.message = `Invalid signature of bytes failed verification agaisnt public key.`;\n }\n}\n","\n// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"a97e506efd61b86e39ae30db588401b8fda46553\",\n \"version\": \"17.3.2\"\n};\n","/**\n * @packageDocumentation\n * @module @taquito/remote-signer\n */\nimport { HttpBackend, HttpResponseError, STATUS_CODE } from '@taquito/http-utils';\nimport {\n b58cdecode,\n b58cencode,\n buf2hex,\n hex2buf,\n isValidPrefix,\n mergebuf,\n prefix,\n verifySignature,\n validateKeyHash,\n ValidationResult,\n invalidDetail,\n} from '@taquito/utils';\nimport { hash } from '@stablelib/blake2b';\nimport toBuffer from 'typedarray-to-buffer';\nimport {\n BadSigningDataError,\n OperationNotAuthorizedError,\n PublicKeyVerificationError,\n SignatureVerificationError,\n} from './errors';\nimport { Signer } from '@taquito/taquito';\nimport {\n InvalidSignatureError,\n InvalidKeyHashError,\n ProhibitedActionError,\n PublicKeyNotFoundError,\n} from '@taquito/core';\n\ninterface PublicKeyResponse {\n public_key: string;\n}\n\ninterface SignResponse {\n signature: string;\n}\n\ntype curves = 'ed' | 'p2' | 'sp';\n\nexport interface RemoteSignerOptions {\n headers?: { [key: string]: string };\n}\n\nexport { VERSION } from './version';\n\nconst pref = {\n ed: {\n pk: prefix['edpk'],\n sk: prefix['edsk'],\n pkh: prefix.tz1,\n sig: prefix.edsig,\n },\n p2: {\n pk: prefix['p2pk'],\n sk: prefix['p2sk'],\n pkh: prefix.tz3,\n sig: prefix.p2sig,\n },\n sp: {\n pk: prefix['sppk'],\n sk: prefix['spsk'],\n pkh: prefix.tz2,\n sig: prefix.spsig,\n },\n};\n\nexport class RemoteSigner implements Signer {\n constructor(\n private pkh: string,\n private rootUrl: string,\n private options: RemoteSignerOptions = {},\n private http = new HttpBackend()\n ) {\n const pkhValidation = validateKeyHash(this.pkh);\n if (pkhValidation !== ValidationResult.VALID) {\n throw new InvalidKeyHashError(this.pkh, invalidDetail(pkhValidation));\n }\n }\n\n async publicKeyHash(): Promise<string> {\n return this.pkh;\n }\n\n private createURL(path: string) {\n // Trim trailing slashes because it is assumed to be included in path\n return `${this.rootUrl.replace(/\\/+$/g, '')}${path}`;\n }\n\n async publicKey(): Promise<string> {\n try {\n const { public_key } = await this.http.createRequest<PublicKeyResponse>({\n url: this.createURL(`/keys/${this.pkh}`),\n method: 'GET',\n headers: this.options.headers,\n });\n return public_key;\n } catch (ex) {\n if (ex instanceof HttpResponseError) {\n if (ex.status === STATUS_CODE.NOT_FOUND) {\n throw new PublicKeyNotFoundError(this.pkh, ex);\n }\n }\n throw ex;\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 try {\n let bb = hex2buf(bytes);\n if (typeof watermark !== 'undefined') {\n bb = mergebuf(watermark, bb);\n }\n const watermarkedBytes = buf2hex(toBuffer(bb));\n const { signature } = await this.http.createRequest<SignResponse>(\n {\n url: this.createURL(`/keys/${this.pkh}`),\n method: 'POST',\n headers: this.options.headers,\n },\n watermarkedBytes\n );\n const pref = signature.startsWith('sig')\n ? signature.substring(0, 3)\n : signature.substring(0, 5);\n\n if (!isValidPrefix(pref)) {\n throw new InvalidSignatureError(\n signature,\n invalidDetail(ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`\n );\n }\n\n const decoded = b58cdecode(signature, prefix[pref]);\n\n const pk = await this.publicKey();\n await this.verifyPublicKey(pk);\n const signatureVerified = verifySignature(watermarkedBytes, pk, signature);\n if (!signatureVerified) {\n throw new SignatureVerificationError(watermarkedBytes, signature);\n }\n\n return {\n bytes,\n sig: b58cencode(decoded, prefix.sig),\n prefixSig: signature,\n sbytes: bytes + buf2hex(toBuffer(decoded)),\n };\n } catch (ex) {\n if (ex instanceof HttpResponseError) {\n if (ex.status === STATUS_CODE.NOT_FOUND) {\n throw new PublicKeyNotFoundError(this.pkh, ex);\n } else if (ex.status === STATUS_CODE.FORBIDDEN) {\n throw new OperationNotAuthorizedError('Signing Operation not authorized', ex);\n } else if (ex.status === STATUS_CODE.BAD_REQUEST) {\n throw new BadSigningDataError(ex, bytes, watermark);\n }\n }\n throw ex;\n }\n }\n\n async verifyPublicKey(publicKey: string) {\n const curve = publicKey.substring(0, 2) as curves;\n const _publicKey = b58cdecode(publicKey, pref[curve].pk);\n\n const publicKeyHash = b58cencode(hash(_publicKey, 20), pref[curve].pkh);\n if (publicKeyHash !== this.pkh) {\n throw new PublicKeyVerificationError(publicKey, publicKeyHash, this.pkh);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;AAGG;AACG,MAAO,2BAA4B,SAAQ,qBAAqB,CAAA;IACpE,WAA4B,CAAA,OAAe,EAAkB,KAAU,EAAA;AACrE,QAAA,KAAK,EAAE,CAAC;QADkB,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;QAAkB,IAAK,CAAA,KAAA,GAAL,KAAK,CAAK;AAErE,QAAA,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;KACtC;AACF,CAAA;AAED;;;AAGG;AACG,MAAO,mBAAoB,SAAQ,YAAY,CAAA;AACnD,IAAA,WAAA,CACkB,KAAU,EACV,KAAa,EACpB,SAAsB,EAAA;AAE/B,QAAA,KAAK,EAAE,CAAC;QAJQ,IAAK,CAAA,KAAA,GAAL,KAAK,CAAK;QACV,IAAK,CAAA,KAAA,GAAL,KAAK,CAAQ;QACpB,IAAS,CAAA,SAAA,GAAT,SAAS,CAAa;AAG/B,QAAA,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,SAAS;AACtB,cAAE,CAAqC,mCAAA,CAAA;AACvC,cAAE,CAAA,uBAAA,EAA0B,KAAK,CAAA,CAAA,CAAG,CAAC;KACxC;AACF,CAAA;AAED;;;AAGG;AACG,MAAO,0BAA2B,SAAQ,YAAY,CAAA;AAC1D,IAAA,WAAA,CACkB,WAAmB,EACnB,YAAoB,EACpB,cAAsB,EAAA;AAEtC,QAAA,KAAK,EAAE,CAAC;QAJQ,IAAW,CAAA,WAAA,GAAX,WAAW,CAAQ;QACnB,IAAY,CAAA,YAAA,GAAZ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