@taquito/remote-signer 16.2.0 → 17.0.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.
@@ -1,59 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PublicKeyMismatch = exports.BadSigningDataError = exports.OperationNotAuthorizedError = exports.KeyNotFoundError = void 0;
3
+ exports.SignatureVerificationError = exports.PublicKeyVerificationError = exports.BadSigningDataError = exports.OperationNotAuthorizedError = exports.PublicKeyNotFoundError = void 0;
4
+ const core_1 = require("@taquito/core");
4
5
  /**
5
6
  * @category Error
6
- * @description Error that indicates a failure in grabbing the public key
7
+ * @description Error indicates a failure in grabbing the public key
7
8
  */
8
- class KeyNotFoundError extends Error {
9
- constructor(message, innerException) {
10
- super(message);
11
- this.message = message;
12
- this.innerException = innerException;
9
+ class PublicKeyNotFoundError extends core_1.TaquitoError {
10
+ constructor(pkh, cause) {
11
+ super();
12
+ this.pkh = pkh;
13
+ this.cause = cause;
13
14
  this.name = 'KeyNotFoundError';
15
+ this.message = `Public key not found of this address "${pkh}".`;
14
16
  }
15
17
  }
16
- exports.KeyNotFoundError = KeyNotFoundError;
18
+ exports.PublicKeyNotFoundError = PublicKeyNotFoundError;
17
19
  /**
18
20
  * @category Error
19
- * @description Error that indicates an unauthorized operation being attempted
21
+ * @description Error indicates an unauthorized operation being attempted
20
22
  */
21
- class OperationNotAuthorizedError extends Error {
22
- constructor(message, innerException) {
23
- super(message);
23
+ class OperationNotAuthorizedError extends core_1.PermissionDeniedError {
24
+ constructor(message, cause) {
25
+ super();
24
26
  this.message = message;
25
- this.innerException = innerException;
27
+ this.cause = cause;
26
28
  this.name = 'OperationNotAuthorized';
27
29
  }
28
30
  }
29
31
  exports.OperationNotAuthorizedError = OperationNotAuthorizedError;
30
32
  /**
31
33
  * @category Error
32
- * @description Error that indicates bad signing data
34
+ * @description Error indicates bad signing data
33
35
  */
34
- class BadSigningDataError extends Error {
35
- constructor(message, innerException, data) {
36
- super(message);
37
- this.message = message;
38
- this.innerException = innerException;
39
- this.data = data;
36
+ class BadSigningDataError extends core_1.TaquitoError {
37
+ constructor(cause, bytes, watermark) {
38
+ super();
39
+ this.cause = cause;
40
+ this.bytes = bytes;
40
41
  this.name = 'BadSigningData';
42
+ this.message = watermark
43
+ ? `Invalid signing data with watermark`
44
+ : `Invalid signing data: "${bytes}"`;
41
45
  }
42
46
  }
43
47
  exports.BadSigningDataError = BadSigningDataError;
44
48
  /**
45
49
  * @category Error
46
- * @description Error that indicates a mismatch between the initialized and the requested public key
50
+ * @description Error indicates a mismatch between the initialized and the requested public key
51
+ */
52
+ class PublicKeyVerificationError extends core_1.TaquitoError {
53
+ constructor(requestedPk, requestedPkh, initializedPkh) {
54
+ super();
55
+ this.requestedPk = requestedPk;
56
+ this.requestedPkh = requestedPkh;
57
+ this.initializedPkh = initializedPkh;
58
+ this.name = 'PublicKeyVerificationFailedError';
59
+ this.message = `Requested pk "${requestedPk}" has pkh "${requestedPkh}" deesn't match initialized pkh "${initializedPkh}."`;
60
+ }
61
+ }
62
+ exports.PublicKeyVerificationError = PublicKeyVerificationError;
63
+ /**
64
+ * @category Error
65
+ * @description Error
47
66
  */
48
- class PublicKeyMismatch extends Error {
49
- constructor(requested, initialized) {
50
- super(`Requested public key hash does not match the initialized public key hash: {
51
- requested: ${requested},
52
- initialized: ${initialized}
53
- }`);
54
- this.requested = requested;
55
- this.name = 'PublicKeyMismatch';
67
+ class SignatureVerificationError extends core_1.TaquitoError {
68
+ constructor(bytes, signature) {
69
+ super();
70
+ this.bytes = bytes;
71
+ this.signature = signature;
72
+ this.name = 'SignatureVerificationFailedError';
73
+ this.name = 'SignatureVerificationFailedError';
74
+ this.message = `Invalid signature of bytes failed verification agaisnt public key.`;
56
75
  }
57
76
  }
58
- exports.PublicKeyMismatch = PublicKeyMismatch;
77
+ exports.SignatureVerificationError = SignatureVerificationError;
59
78
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IAEzC,YAAmB,OAAe,EAAS,cAAmB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAQ;QAAS,mBAAc,GAAd,cAAc,CAAK;QADvD,SAAI,GAAG,kBAAkB,CAAC;IAGjC,CAAC;CACF;AALD,4CAKC;AAED;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,KAAK;IAEpD,YAAmB,OAAe,EAAS,cAAmB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAQ;QAAS,mBAAc,GAAd,cAAc,CAAK;QADvD,SAAI,GAAG,wBAAwB,CAAC;IAGvC,CAAC;CACF;AALD,kEAKC;AAED;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAE5C,YAAmB,OAAe,EAAS,cAAmB,EAAkB,IAAS;QACvF,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAQ;QAAS,mBAAc,GAAd,cAAc,CAAK;QAAkB,SAAI,GAAJ,IAAI,CAAK;QADlF,SAAI,GAAG,gBAAgB,CAAC;IAG/B,CAAC;CACF;AALD,kDAKC;AAED;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAE1C,YAAmB,SAAiB,EAAE,WAAmB;QACvD,KAAK,CACH;qBACe,SAAS;uBACP,WAAW;QAC1B,CACH,CAAC;QANe,cAAS,GAAT,SAAS,CAAQ;QAD7B,SAAI,GAAG,mBAAmB,CAAC;IAQlC,CAAC;CACF;AAVD,8CAUC"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,wCAAoE;AAEpE;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,mBAAY;IACtD,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ACH,MAAa,0BAA2B,SAAQ,mBAAY;IAE1D,YAAmB,KAAa,EAAS,SAAiB;QACxD,KAAK,EAAE,CAAC;QADS,UAAK,GAAL,KAAK,CAAQ;QAAS,cAAS,GAAT,SAAS,CAAQ;QADnD,SAAI,GAAG,kCAAkC,CAAC;QAG/C,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;QAC/C,IAAI,CAAC,OAAO,GAAG,oEAAoE,CAAC;IACtF,CAAC;CACF;AAPD,gEAOC"}
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RemoteSigner = exports.VERSION = exports.SignatureVerificationFailedError = void 0;
12
+ exports.RemoteSigner = exports.VERSION = void 0;
13
13
  /**
14
14
  * @packageDocumentation
15
15
  * @module @taquito/remote-signer
@@ -20,25 +20,6 @@ const blake2b_1 = require("@stablelib/blake2b");
20
20
  const typedarray_to_buffer_1 = require("typedarray-to-buffer");
21
21
  const errors_1 = require("./errors");
22
22
  const core_1 = require("@taquito/core");
23
- /**
24
- * @category Error
25
- * @description Error
26
- */
27
- class SignatureVerificationFailedError extends Error {
28
- constructor(bytes, signature) {
29
- super(`
30
- Signature failed verification against public key:
31
- {
32
- bytes: ${bytes},
33
- signature: ${signature}
34
- }
35
- `);
36
- this.bytes = bytes;
37
- this.signature = signature;
38
- this.name = 'SignatureVerificationFailedError';
39
- }
40
- }
41
- exports.SignatureVerificationFailedError = SignatureVerificationFailedError;
42
23
  var version_1 = require("./version");
43
24
  Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
44
25
  const pref = {
@@ -69,7 +50,7 @@ class RemoteSigner {
69
50
  this.http = http;
70
51
  const pkhValidation = utils_1.validateKeyHash(this.pkh);
71
52
  if (pkhValidation !== utils_1.ValidationResult.VALID) {
72
- throw new core_1.InvalidKeyHashError(this.pkh, utils_1.invalidErrorDetail(pkhValidation));
53
+ throw new core_1.InvalidKeyHashError(this.pkh, utils_1.invalidDetail(pkhValidation));
73
54
  }
74
55
  }
75
56
  publicKeyHash() {
@@ -94,7 +75,7 @@ class RemoteSigner {
94
75
  catch (ex) {
95
76
  if (ex instanceof http_utils_1.HttpResponseError) {
96
77
  if (ex.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
97
- throw new errors_1.KeyNotFoundError(`Key not found: ${this.pkh}`, ex);
78
+ throw new errors_1.PublicKeyNotFoundError(this.pkh, ex);
98
79
  }
99
80
  }
100
81
  throw ex;
@@ -123,14 +104,14 @@ class RemoteSigner {
123
104
  ? signature.substring(0, 3)
124
105
  : signature.substring(0, 5);
125
106
  if (!utils_1.isValidPrefix(pref)) {
126
- throw new core_1.InvalidSignatureError(signature, utils_1.invalidErrorDetail(utils_1.ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
107
+ throw new core_1.InvalidSignatureError(signature, utils_1.invalidDetail(utils_1.ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
127
108
  }
128
109
  const decoded = utils_1.b58cdecode(signature, utils_1.prefix[pref]);
129
110
  const pk = yield this.publicKey();
130
111
  yield this.verifyPublicKey(pk);
131
112
  const signatureVerified = utils_1.verifySignature(watermarkedBytes, pk, signature);
132
113
  if (!signatureVerified) {
133
- throw new SignatureVerificationFailedError(watermarkedBytes, signature);
114
+ throw new errors_1.SignatureVerificationError(watermarkedBytes, signature);
134
115
  }
135
116
  return {
136
117
  bytes,
@@ -142,16 +123,13 @@ class RemoteSigner {
142
123
  catch (ex) {
143
124
  if (ex instanceof http_utils_1.HttpResponseError) {
144
125
  if (ex.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
145
- throw new errors_1.KeyNotFoundError(`Key not found: ${this.pkh}`, ex);
126
+ throw new errors_1.PublicKeyNotFoundError(this.pkh, ex);
146
127
  }
147
128
  else if (ex.status === http_utils_1.STATUS_CODE.FORBIDDEN) {
148
129
  throw new errors_1.OperationNotAuthorizedError('Signing Operation not authorized', ex);
149
130
  }
150
131
  else if (ex.status === http_utils_1.STATUS_CODE.BAD_REQUEST) {
151
- throw new errors_1.BadSigningDataError('Invalid data', ex, {
152
- bytes,
153
- watermark,
154
- });
132
+ throw new errors_1.BadSigningDataError(ex, bytes, watermark);
155
133
  }
156
134
  }
157
135
  throw ex;
@@ -164,7 +142,7 @@ class RemoteSigner {
164
142
  const _publicKey = utils_1.b58cdecode(publicKey, pref[curve].pk);
165
143
  const publicKeyHash = utils_1.b58cencode(blake2b_1.hash(_publicKey, 20), pref[curve].pkh);
166
144
  if (publicKeyHash !== this.pkh) {
167
- throw new errors_1.PublicKeyMismatch(publicKeyHash, this.pkh);
145
+ throw new errors_1.PublicKeyVerificationError(publicKey, publicKeyHash, this.pkh);
168
146
  }
169
147
  });
170
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-remote-signer.js","sourceRoot":"","sources":["../../src/taquito-remote-signer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;GAGG;AACH,oDAAkF;AAClF,0CAYwB;AACxB,gDAA0C;AAC1C,+DAA4C;AAC5C,qCAKkB;AAElB,wCAAkG;AAElG;;;GAGG;AACH,MAAa,gCAAiC,SAAQ,KAAK;IAEzD,YAAmB,KAAa,EAAS,SAAiB;QACxD,KAAK,CACH;;;mBAGa,KAAK;uBACD,SAAS;;OAEzB,CACF,CAAC;QATe,UAAK,GAAL,KAAK,CAAQ;QAAS,cAAS,GAAT,SAAS,CAAQ;QADnD,SAAI,GAAG,kCAAkC,CAAC;IAWjD,CAAC;CACF;AAbD,4EAaC;AAgBD,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,MAAM,IAAI,GAAG;IACX,EAAE,EAAE;QACF,EAAE,EAAE,cAAM,CAAC,MAAM,CAAC;QAClB,EAAE,EAAE,cAAM,CAAC,MAAM,CAAC;QAClB,GAAG,EAAE,cAAM,CAAC,GAAG;QACf,GAAG,EAAE,cAAM,CAAC,KAAK;KA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CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAW,CAAC;YAClD,MAAM,UAAU,GAAG,kBAAU,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;YAEzD,MAAM,aAAa,GAAG,kBAAU,CAAC,cAAI,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;YACxE,IAAI,aAAa,KAAK,IAAI,CAAC,GAAG,EAAE;gBAC9B,MAAM,IAAI,mCAA0B,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;aAC1E;QACH,CAAC;KAAA;CACF;AA5GD,oCA4GC"}
@@ -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": "adc0f8c31492e8eb2f03b06ac36ba053e8ba6224",
7
- "version": "16.2.0"
6
+ "commitHash": "1169170fdbf4efd03283dc902bc03b9df5bb2fb1",
7
+ "version": "17.0.0-beta-RC.0"
8
8
  };
9
9
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;AAC9D,QAAA,OAAO,GAAG;IACnB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,QAAQ;CACtB,CAAC"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;AAC9D,QAAA,OAAO,GAAG;IACnB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,kBAAkB;CAChC,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { HttpBackend, HttpResponseError, STATUS_CODE } from '@taquito/http-utils';
2
- import { prefix, validateKeyHash, ValidationResult, invalidErrorDetail, hex2buf, mergebuf, buf2hex, isValidPrefix, b58cdecode, verifySignature, b58cencode } from '@taquito/utils';
2
+ import { prefix, validateKeyHash, ValidationResult, invalidDetail, hex2buf, mergebuf, buf2hex, isValidPrefix, b58cdecode, verifySignature, b58cencode } from '@taquito/utils';
3
3
  import { hash } from '@stablelib/blake2b';
4
4
  import toBuffer from 'typedarray-to-buffer';
5
- import { InvalidKeyHashError, ProhibitedActionError, InvalidSignatureError } from '@taquito/core';
5
+ import { TaquitoError, PermissionDeniedError, InvalidKeyHashError, ProhibitedActionError, InvalidSignatureError } from '@taquito/core';
6
6
 
7
7
  /******************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -31,80 +31,79 @@ function __awaiter(thisArg, _arguments, P, generator) {
31
31
 
32
32
  /**
33
33
  * @category Error
34
- * @description Error that indicates a failure in grabbing the public key
34
+ * @description Error indicates a failure in grabbing the public key
35
35
  */
36
- class KeyNotFoundError extends Error {
37
- constructor(message, innerException) {
38
- super(message);
39
- this.message = message;
40
- this.innerException = innerException;
36
+ class PublicKeyNotFoundError extends TaquitoError {
37
+ constructor(pkh, cause) {
38
+ super();
39
+ this.pkh = pkh;
40
+ this.cause = cause;
41
41
  this.name = 'KeyNotFoundError';
42
+ this.message = `Public key not found of this address "${pkh}".`;
42
43
  }
43
44
  }
44
45
  /**
45
46
  * @category Error
46
- * @description Error that indicates an unauthorized operation being attempted
47
+ * @description Error indicates an unauthorized operation being attempted
47
48
  */
48
- class OperationNotAuthorizedError extends Error {
49
- constructor(message, innerException) {
50
- super(message);
49
+ class OperationNotAuthorizedError extends PermissionDeniedError {
50
+ constructor(message, cause) {
51
+ super();
51
52
  this.message = message;
52
- this.innerException = innerException;
53
+ this.cause = cause;
53
54
  this.name = 'OperationNotAuthorized';
54
55
  }
55
56
  }
56
57
  /**
57
58
  * @category Error
58
- * @description Error that indicates bad signing data
59
+ * @description Error indicates bad signing data
59
60
  */
60
- class BadSigningDataError extends Error {
61
- constructor(message, innerException, data) {
62
- super(message);
63
- this.message = message;
64
- this.innerException = innerException;
65
- this.data = data;
61
+ class BadSigningDataError extends TaquitoError {
62
+ constructor(cause, bytes, watermark) {
63
+ super();
64
+ this.cause = cause;
65
+ this.bytes = bytes;
66
66
  this.name = 'BadSigningData';
67
+ this.message = watermark
68
+ ? `Invalid signing data with watermark`
69
+ : `Invalid signing data: "${bytes}"`;
67
70
  }
68
71
  }
69
72
  /**
70
73
  * @category Error
71
- * @description Error that indicates a mismatch between the initialized and the requested public key
74
+ * @description Error indicates a mismatch between the initialized and the requested public key
72
75
  */
73
- class PublicKeyMismatch extends Error {
74
- constructor(requested, initialized) {
75
- super(`Requested public key hash does not match the initialized public key hash: {
76
- requested: ${requested},
77
- initialized: ${initialized}
78
- }`);
79
- this.requested = requested;
80
- this.name = 'PublicKeyMismatch';
76
+ class PublicKeyVerificationError extends TaquitoError {
77
+ constructor(requestedPk, requestedPkh, initializedPkh) {
78
+ super();
79
+ this.requestedPk = requestedPk;
80
+ this.requestedPkh = requestedPkh;
81
+ this.initializedPkh = initializedPkh;
82
+ this.name = 'PublicKeyVerificationFailedError';
83
+ this.message = `Requested pk "${requestedPk}" has pkh "${requestedPkh}" deesn't match initialized pkh "${initializedPkh}."`;
81
84
  }
82
- }
83
-
84
- // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
85
- const VERSION = {
86
- "commitHash": "adc0f8c31492e8eb2f03b06ac36ba053e8ba6224",
87
- "version": "16.2.0"
88
- };
89
-
85
+ }
90
86
  /**
91
87
  * @category Error
92
88
  * @description Error
93
89
  */
94
- class SignatureVerificationFailedError extends Error {
90
+ class SignatureVerificationError extends TaquitoError {
95
91
  constructor(bytes, signature) {
96
- super(`
97
- Signature failed verification against public key:
98
- {
99
- bytes: ${bytes},
100
- signature: ${signature}
101
- }
102
- `);
92
+ super();
103
93
  this.bytes = bytes;
104
94
  this.signature = signature;
105
95
  this.name = 'SignatureVerificationFailedError';
96
+ this.name = 'SignatureVerificationFailedError';
97
+ this.message = `Invalid signature of bytes failed verification agaisnt public key.`;
106
98
  }
107
- }
99
+ }
100
+
101
+ // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
102
+ const VERSION = {
103
+ "commitHash": "1169170fdbf4efd03283dc902bc03b9df5bb2fb1",
104
+ "version": "17.0.0-beta-RC.0"
105
+ };
106
+
108
107
  const pref = {
109
108
  ed: {
110
109
  pk: prefix['edpk'],
@@ -133,7 +132,7 @@ class RemoteSigner {
133
132
  this.http = http;
134
133
  const pkhValidation = validateKeyHash(this.pkh);
135
134
  if (pkhValidation !== ValidationResult.VALID) {
136
- throw new InvalidKeyHashError(this.pkh, invalidErrorDetail(pkhValidation));
135
+ throw new InvalidKeyHashError(this.pkh, invalidDetail(pkhValidation));
137
136
  }
138
137
  }
139
138
  publicKeyHash() {
@@ -158,7 +157,7 @@ class RemoteSigner {
158
157
  catch (ex) {
159
158
  if (ex instanceof HttpResponseError) {
160
159
  if (ex.status === STATUS_CODE.NOT_FOUND) {
161
- throw new KeyNotFoundError(`Key not found: ${this.pkh}`, ex);
160
+ throw new PublicKeyNotFoundError(this.pkh, ex);
162
161
  }
163
162
  }
164
163
  throw ex;
@@ -187,14 +186,14 @@ class RemoteSigner {
187
186
  ? signature.substring(0, 3)
188
187
  : signature.substring(0, 5);
189
188
  if (!isValidPrefix(pref)) {
190
- throw new InvalidSignatureError(signature, invalidErrorDetail(ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
189
+ throw new InvalidSignatureError(signature, invalidDetail(ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
191
190
  }
192
191
  const decoded = b58cdecode(signature, prefix[pref]);
193
192
  const pk = yield this.publicKey();
194
193
  yield this.verifyPublicKey(pk);
195
194
  const signatureVerified = verifySignature(watermarkedBytes, pk, signature);
196
195
  if (!signatureVerified) {
197
- throw new SignatureVerificationFailedError(watermarkedBytes, signature);
196
+ throw new SignatureVerificationError(watermarkedBytes, signature);
198
197
  }
199
198
  return {
200
199
  bytes,
@@ -206,16 +205,13 @@ class RemoteSigner {
206
205
  catch (ex) {
207
206
  if (ex instanceof HttpResponseError) {
208
207
  if (ex.status === STATUS_CODE.NOT_FOUND) {
209
- throw new KeyNotFoundError(`Key not found: ${this.pkh}`, ex);
208
+ throw new PublicKeyNotFoundError(this.pkh, ex);
210
209
  }
211
210
  else if (ex.status === STATUS_CODE.FORBIDDEN) {
212
211
  throw new OperationNotAuthorizedError('Signing Operation not authorized', ex);
213
212
  }
214
213
  else if (ex.status === STATUS_CODE.BAD_REQUEST) {
215
- throw new BadSigningDataError('Invalid data', ex, {
216
- bytes,
217
- watermark,
218
- });
214
+ throw new BadSigningDataError(ex, bytes, watermark);
219
215
  }
220
216
  }
221
217
  throw ex;
@@ -228,11 +224,11 @@ class RemoteSigner {
228
224
  const _publicKey = b58cdecode(publicKey, pref[curve].pk);
229
225
  const publicKeyHash = b58cencode(hash(_publicKey, 20), pref[curve].pkh);
230
226
  if (publicKeyHash !== this.pkh) {
231
- throw new PublicKeyMismatch(publicKeyHash, this.pkh);
227
+ throw new PublicKeyVerificationError(publicKey, publicKeyHash, this.pkh);
232
228
  }
233
229
  });
234
230
  }
235
231
  }
236
232
 
237
- export { RemoteSigner, SignatureVerificationFailedError, VERSION };
233
+ export { RemoteSigner, VERSION };
238
234
  //# sourceMappingURL=taquito-remote-signer.es6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-remote-signer.es6.js","sources":["../src/errors.ts","../src/version.ts","../src/taquito-remote-signer.ts"],"sourcesContent":["/**\n * @category Error\n * @description Error that indicates a failure in grabbing the public key\n */\nexport class KeyNotFoundError extends Error {\n public name = 'KeyNotFoundError';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates an unauthorized operation being attempted\n */\nexport class OperationNotAuthorizedError extends Error {\n public name = 'OperationNotAuthorized';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates bad signing data\n */\nexport class BadSigningDataError extends Error {\n public name = 'BadSigningData';\n constructor(public message: string, public innerException: any, public readonly data: any) {\n super(message);\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 PublicKeyMismatch extends Error {\n public name = 'PublicKeyMismatch';\n constructor(public requested: string, initialized: string) {\n super(\n `Requested public key hash does not match the initialized public key hash: {\n requested: ${requested},\n initialized: ${initialized}\n }`\n );\n }\n}\n","\n// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"adc0f8c31492e8eb2f03b06ac36ba053e8ba6224\",\n \"version\": \"16.2.0\"\n};\n","/**\n * @packageDocumentation\n * @module @taquito/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 invalidErrorDetail,\n} from '@taquito/utils';\nimport { hash } from '@stablelib/blake2b';\nimport toBuffer from 'typedarray-to-buffer';\nimport {\n BadSigningDataError,\n KeyNotFoundError,\n OperationNotAuthorizedError,\n PublicKeyMismatch,\n} from './errors';\nimport { Signer } from '@taquito/taquito';\nimport { InvalidSignatureError, InvalidKeyHashError, ProhibitedActionError } from '@taquito/core';\n\n/**\n * @category Error\n * @description Error\n */\nexport class SignatureVerificationFailedError extends Error {\n public name = 'SignatureVerificationFailedError';\n constructor(public bytes: string, public signature: string) {\n super(\n `\n Signature failed verification against public key:\n {\n bytes: ${bytes},\n signature: ${signature}\n }\n `\n );\n }\n}\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, invalidErrorDetail(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 KeyNotFoundError(`Key not found: ${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 invalidErrorDetail(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 SignatureVerificationFailedError(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 KeyNotFoundError(`Key not found: ${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('Invalid data', ex, {\n bytes,\n watermark,\n });\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 PublicKeyMismatch(publicKeyHash, this.pkh);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;AAGG;AACG,MAAO,gBAAiB,SAAQ,KAAK,CAAA;IAEzC,WAAmB,CAAA,OAAe,EAAS,cAAmB,EAAA;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;QAAS,IAAc,CAAA,cAAA,GAAd,cAAc,CAAK;QADvD,IAAI,CAAA,IAAA,GAAG,kBAAkB,CAAC;KAGhC;AACF,CAAA;AAED;;;AA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C,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;AACxE,YAAA,IAAI,aAAa,KAAK,IAAI,CAAC,GAAG,EAAE;gBAC9B,MAAM,IAAI,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,aAAA;SACF,CAAA,CAAA;AAAA,KAAA;AACF;;;;"}
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 indicates a failure in grabbing the public key\n */\nexport class PublicKeyNotFoundError extends TaquitoError {\n constructor(public pkh: string, public cause: any) {\n super();\n this.name = 'KeyNotFoundError';\n this.message = `Public key not found of this address \"${pkh}\".`;\n }\n}\n\n/**\n * @category Error\n * @description Error indicates an unauthorized operation being attempted\n */\nexport class OperationNotAuthorizedError extends PermissionDeniedError {\n constructor(public message: string, public cause: any) {\n super();\n this.name = 'OperationNotAuthorized';\n }\n}\n\n/**\n * @category Error\n * @description Error indicates bad signing data\n */\nexport class BadSigningDataError extends TaquitoError {\n constructor(public cause: any, public bytes: string, watermark?: Uint8Array) {\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 indicates a mismatch between the initialized and the requested public key\n */\nexport class PublicKeyVerificationError extends TaquitoError {\n constructor(\n public requestedPk: string,\n public requestedPkh: string,\n public 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 bytes: string, public 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\": \"1169170fdbf4efd03283dc902bc03b9df5bb2fb1\",\n \"version\": \"17.0.0-beta-RC.0\"\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 PublicKeyNotFoundError,\n OperationNotAuthorizedError,\n PublicKeyVerificationError,\n SignatureVerificationError,\n} from './errors';\nimport { Signer } from '@taquito/taquito';\nimport { InvalidSignatureError, InvalidKeyHashError, ProhibitedActionError } 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,sBAAuB,SAAQ,YAAY,CAAA;IACtD,WAAmB,CAAA,GAAW,EAAS,KAAU,EAAA;AAC/C,QAAA,KAAK,EAAE,CAAC;QADS,IAAG,CAAA,GAAA,GAAH,GAAG,CAAQ;QAAS,IAAK,CAAA,KAAA,GAAL,KAAK,CAAK;AAE/C,QAAA,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;AAC/B,QAAA,IAAI,CAAC,OAAO,GAAG,CAAyC,sCAAA,EAAA,GAAG,IAAI,CAAC;KACjE;AACF,CAAA;AAED;;;AAGG;AACG,MAAO,2BAA4B,SAAQ,qBAAqB,CAAA;IACpE,WAAmB,CAAA,OAAe,EAAS,KAAU,EAAA;AACnD,QAAA,KAAK,EAAE,CAAC;QADS,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;QAAS,IAAK,CAAA,KAAA,GAAL,KAAK,CAAK;AAEnD,QAAA,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;KACtC;AACF,CAAA;AAED;;;AAGG;AACG,MAAO,mBAAoB,SAAQ,YAAY,CAAA;AACnD,IAAA,WAAA,CAAmB,KAAU,EAAS,KAAa,EAAE,SA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EAAE,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1E,aAAA;SACF,CAAA,CAAA;AAAA,KAAA;AACF;;;;"}
@@ -35,80 +35,79 @@
35
35
 
36
36
  /**
37
37
  * @category Error
38
- * @description Error that indicates a failure in grabbing the public key
38
+ * @description Error indicates a failure in grabbing the public key
39
39
  */
40
- class KeyNotFoundError extends Error {
41
- constructor(message, innerException) {
42
- super(message);
43
- this.message = message;
44
- this.innerException = innerException;
40
+ class PublicKeyNotFoundError extends core.TaquitoError {
41
+ constructor(pkh, cause) {
42
+ super();
43
+ this.pkh = pkh;
44
+ this.cause = cause;
45
45
  this.name = 'KeyNotFoundError';
46
+ this.message = `Public key not found of this address "${pkh}".`;
46
47
  }
47
48
  }
48
49
  /**
49
50
  * @category Error
50
- * @description Error that indicates an unauthorized operation being attempted
51
+ * @description Error indicates an unauthorized operation being attempted
51
52
  */
52
- class OperationNotAuthorizedError extends Error {
53
- constructor(message, innerException) {
54
- super(message);
53
+ class OperationNotAuthorizedError extends core.PermissionDeniedError {
54
+ constructor(message, cause) {
55
+ super();
55
56
  this.message = message;
56
- this.innerException = innerException;
57
+ this.cause = cause;
57
58
  this.name = 'OperationNotAuthorized';
58
59
  }
59
60
  }
60
61
  /**
61
62
  * @category Error
62
- * @description Error that indicates bad signing data
63
+ * @description Error indicates bad signing data
63
64
  */
64
- class BadSigningDataError extends Error {
65
- constructor(message, innerException, data) {
66
- super(message);
67
- this.message = message;
68
- this.innerException = innerException;
69
- this.data = data;
65
+ class BadSigningDataError extends core.TaquitoError {
66
+ constructor(cause, bytes, watermark) {
67
+ super();
68
+ this.cause = cause;
69
+ this.bytes = bytes;
70
70
  this.name = 'BadSigningData';
71
+ this.message = watermark
72
+ ? `Invalid signing data with watermark`
73
+ : `Invalid signing data: "${bytes}"`;
71
74
  }
72
75
  }
73
76
  /**
74
77
  * @category Error
75
- * @description Error that indicates a mismatch between the initialized and the requested public key
78
+ * @description Error indicates a mismatch between the initialized and the requested public key
76
79
  */
77
- class PublicKeyMismatch extends Error {
78
- constructor(requested, initialized) {
79
- super(`Requested public key hash does not match the initialized public key hash: {
80
- requested: ${requested},
81
- initialized: ${initialized}
82
- }`);
83
- this.requested = requested;
84
- this.name = 'PublicKeyMismatch';
80
+ class PublicKeyVerificationError extends core.TaquitoError {
81
+ constructor(requestedPk, requestedPkh, initializedPkh) {
82
+ super();
83
+ this.requestedPk = requestedPk;
84
+ this.requestedPkh = requestedPkh;
85
+ this.initializedPkh = initializedPkh;
86
+ this.name = 'PublicKeyVerificationFailedError';
87
+ this.message = `Requested pk "${requestedPk}" has pkh "${requestedPkh}" deesn't match initialized pkh "${initializedPkh}."`;
85
88
  }
86
- }
87
-
88
- // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
89
- const VERSION = {
90
- "commitHash": "adc0f8c31492e8eb2f03b06ac36ba053e8ba6224",
91
- "version": "16.2.0"
92
- };
93
-
89
+ }
94
90
  /**
95
91
  * @category Error
96
92
  * @description Error
97
93
  */
98
- class SignatureVerificationFailedError extends Error {
94
+ class SignatureVerificationError extends core.TaquitoError {
99
95
  constructor(bytes, signature) {
100
- super(`
101
- Signature failed verification against public key:
102
- {
103
- bytes: ${bytes},
104
- signature: ${signature}
105
- }
106
- `);
96
+ super();
107
97
  this.bytes = bytes;
108
98
  this.signature = signature;
109
99
  this.name = 'SignatureVerificationFailedError';
100
+ this.name = 'SignatureVerificationFailedError';
101
+ this.message = `Invalid signature of bytes failed verification agaisnt public key.`;
110
102
  }
111
- }
103
+ }
104
+
105
+ // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
106
+ const VERSION = {
107
+ "commitHash": "1169170fdbf4efd03283dc902bc03b9df5bb2fb1",
108
+ "version": "17.0.0-beta-RC.0"
109
+ };
110
+
112
111
  const pref = {
113
112
  ed: {
114
113
  pk: utils.prefix['edpk'],
@@ -137,7 +136,7 @@
137
136
  this.http = http;
138
137
  const pkhValidation = utils.validateKeyHash(this.pkh);
139
138
  if (pkhValidation !== utils.ValidationResult.VALID) {
140
- throw new core.InvalidKeyHashError(this.pkh, utils.invalidErrorDetail(pkhValidation));
139
+ throw new core.InvalidKeyHashError(this.pkh, utils.invalidDetail(pkhValidation));
141
140
  }
142
141
  }
143
142
  publicKeyHash() {
@@ -162,7 +161,7 @@
162
161
  catch (ex) {
163
162
  if (ex instanceof httpUtils.HttpResponseError) {
164
163
  if (ex.status === httpUtils.STATUS_CODE.NOT_FOUND) {
165
- throw new KeyNotFoundError(`Key not found: ${this.pkh}`, ex);
164
+ throw new PublicKeyNotFoundError(this.pkh, ex);
166
165
  }
167
166
  }
168
167
  throw ex;
@@ -191,14 +190,14 @@
191
190
  ? signature.substring(0, 3)
192
191
  : signature.substring(0, 5);
193
192
  if (!utils.isValidPrefix(pref)) {
194
- throw new core.InvalidSignatureError(signature, utils.invalidErrorDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
193
+ throw new core.InvalidSignatureError(signature, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` from a remote signer.`);
195
194
  }
196
195
  const decoded = utils.b58cdecode(signature, utils.prefix[pref]);
197
196
  const pk = yield this.publicKey();
198
197
  yield this.verifyPublicKey(pk);
199
198
  const signatureVerified = utils.verifySignature(watermarkedBytes, pk, signature);
200
199
  if (!signatureVerified) {
201
- throw new SignatureVerificationFailedError(watermarkedBytes, signature);
200
+ throw new SignatureVerificationError(watermarkedBytes, signature);
202
201
  }
203
202
  return {
204
203
  bytes,
@@ -210,16 +209,13 @@
210
209
  catch (ex) {
211
210
  if (ex instanceof httpUtils.HttpResponseError) {
212
211
  if (ex.status === httpUtils.STATUS_CODE.NOT_FOUND) {
213
- throw new KeyNotFoundError(`Key not found: ${this.pkh}`, ex);
212
+ throw new PublicKeyNotFoundError(this.pkh, ex);
214
213
  }
215
214
  else if (ex.status === httpUtils.STATUS_CODE.FORBIDDEN) {
216
215
  throw new OperationNotAuthorizedError('Signing Operation not authorized', ex);
217
216
  }
218
217
  else if (ex.status === httpUtils.STATUS_CODE.BAD_REQUEST) {
219
- throw new BadSigningDataError('Invalid data', ex, {
220
- bytes,
221
- watermark,
222
- });
218
+ throw new BadSigningDataError(ex, bytes, watermark);
223
219
  }
224
220
  }
225
221
  throw ex;
@@ -232,14 +228,13 @@
232
228
  const _publicKey = utils.b58cdecode(publicKey, pref[curve].pk);
233
229
  const publicKeyHash = utils.b58cencode(blake2b.hash(_publicKey, 20), pref[curve].pkh);
234
230
  if (publicKeyHash !== this.pkh) {
235
- throw new PublicKeyMismatch(publicKeyHash, this.pkh);
231
+ throw new PublicKeyVerificationError(publicKey, publicKeyHash, this.pkh);
236
232
  }
237
233
  });
238
234
  }
239
235
  }
240
236
 
241
237
  exports.RemoteSigner = RemoteSigner;
242
- exports.SignatureVerificationFailedError = SignatureVerificationFailedError;
243
238
  exports.VERSION = VERSION;
244
239
 
245
240
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-remote-signer.umd.js","sources":["../src/errors.ts","../src/version.ts","../src/taquito-remote-signer.ts"],"sourcesContent":["/**\n * @category Error\n * @description Error that indicates a failure in grabbing the public key\n */\nexport class KeyNotFoundError extends Error {\n public name = 'KeyNotFoundError';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates an unauthorized operation being attempted\n */\nexport class OperationNotAuthorizedError extends Error {\n public name = 'OperationNotAuthorized';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates bad signing data\n */\nexport class BadSigningDataError extends Error {\n public name = 'BadSigningData';\n constructor(public message: string, public innerException: any, public readonly data: any) {\n super(message);\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 PublicKeyMismatch extends Error {\n public name = 'PublicKeyMismatch';\n constructor(public requested: string, initialized: string) {\n super(\n `Requested public key hash does not match the initialized public key hash: {\n requested: ${requested},\n initialized: ${initialized}\n }`\n );\n }\n}\n","\n// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"adc0f8c31492e8eb2f03b06ac36ba053e8ba6224\",\n \"version\": \"16.2.0\"\n};\n","/**\n * @packageDocumentation\n * @module @taquito/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 invalidErrorDetail,\n} from '@taquito/utils';\nimport { hash } from '@stablelib/blake2b';\nimport toBuffer from 'typedarray-to-buffer';\nimport {\n BadSigningDataError,\n KeyNotFoundError,\n OperationNotAuthorizedError,\n PublicKeyMismatch,\n} from './errors';\nimport { Signer } from '@taquito/taquito';\nimport { InvalidSignatureError, InvalidKeyHashError, ProhibitedActionError } from '@taquito/core';\n\n/**\n * @category Error\n * @description Error\n */\nexport class SignatureVerificationFailedError extends Error {\n public name = 'SignatureVerificationFailedError';\n constructor(public bytes: string, public signature: string) {\n super(\n `\n Signature failed verification against public key:\n {\n bytes: ${bytes},\n signature: ${signature}\n }\n `\n );\n }\n}\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, invalidErrorDetail(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 KeyNotFoundError(`Key not found: ${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 invalidErrorDetail(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 SignatureVerificationFailedError(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 KeyNotFoundError(`Key not found: ${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('Invalid data', ex, {\n bytes,\n watermark,\n });\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 PublicKeyMismatch(publicKeyHash, this.pkh);\n }\n }\n}\n"],"names":["prefix","HttpBackend","validateKeyHash","ValidationResult","InvalidKeyHashError","invalidErrorDetail","HttpResponseError","STATUS_CODE","ProhibitedActionError","hex2buf","mergebuf","buf2hex","toBuffer","isValidPrefix","InvalidSignatureError","b58cdecode","verifySignature","b58cencode","hash"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;;IAGG;IACG,MAAO,gBAAiB,SAAQ,KAAK,CAAA;QAEzC,WAAmB,CAAA,OAAe,EAAS,cAAmB,EAAA;YAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;YADE,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;YAAS,IAAc,CAAA,cAAA,GAAd,cAAc,CAAK;YADvD,IAAI,CAAA,IAAA,GAAG,kBAAkB,CAAC;SAGhC;IACF,CAAA;IAED;;;IAGG;IACG,MAAO,2BAA4B,SAAQ,KAAK,CAAA;QAEpD,WAAmB,CAAA,OAAe,EAAS,cAAmB,EAAA;YAC5D,KAAK,CA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AAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IACxE,YAAA,IAAI,aAAa,KAAK,IAAI,CAAC,GAAG,EAAE;oBAC9B,MAAM,IAAI,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACtD,aAAA;aACF,CAAA,CAAA;IAAA,KAAA;IACF;;;;;;;;;;;;"}
1
+ {"version":3,"file":"taquito-remote-signer.umd.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 indicates a failure in grabbing the public key\n */\nexport class PublicKeyNotFoundError extends TaquitoError {\n constructor(public pkh: string, public cause: any) {\n super();\n this.name = 'KeyNotFoundError';\n this.message = `Public key not found of this address \"${pkh}\".`;\n }\n}\n\n/**\n * @category Error\n * @description Error indicates an unauthorized operation being attempted\n */\nexport class OperationNotAuthorizedError extends PermissionDeniedError {\n constructor(public message: string, public cause: any) {\n super();\n this.name = 'OperationNotAuthorized';\n }\n}\n\n/**\n * @category Error\n * @description Error indicates bad signing data\n */\nexport class BadSigningDataError extends TaquitoError {\n constructor(public cause: any, public bytes: string, watermark?: Uint8Array) {\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 indicates a mismatch between the initialized and the requested public key\n */\nexport class PublicKeyVerificationError extends TaquitoError {\n constructor(\n public requestedPk: string,\n public requestedPkh: string,\n public 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 bytes: string, public 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\": \"1169170fdbf4efd03283dc902bc03b9df5bb2fb1\",\n \"version\": \"17.0.0-beta-RC.0\"\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 PublicKeyNotFoundError,\n OperationNotAuthorizedError,\n PublicKeyVerificationError,\n SignatureVerificationError,\n} from './errors';\nimport { Signer } from '@taquito/taquito';\nimport { InvalidSignatureError, InvalidKeyHashError, ProhibitedActionError } 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":["TaquitoError","PermissionDeniedError","prefix","HttpBackend","validateKeyHash","ValidationResult","InvalidKeyHashError","invalidDetail","HttpResponseError","STATUS_CODE","ProhibitedActionError","hex2buf","mergebuf","buf2hex","toBuffer","isValidPrefix","InvalidSignatureError","b58cdecode","verifySignature","b58cencode","hash"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEA;;;IAGG;IACG,MAAO,sBAAuB,SAAQA,iBAAY,CAAA;QACtD,WAAmB,CAAA,GAAW,EAAS,KAAU,EAAA;IAC/C,QAAA,KAAK,EAAE,CAAC;YADS,IAAG,CAAA,GAAA,GAAH,GAAG,CAAQ;YAAS,IAAK,CAAA,KAAA,GAAL,KAAK,CAAK;IAE/C,QAAA,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IAC/B,QAAA,IAAI,CAAC,OAAO,GAAG,CAAyC,sCAAA,EAAA,GAAG,IAAI,CAAC;SACjE;IACF,CAAA;IAED;;;IAGG;IACG,MAAO,2BAA4B,SAAQC,0BAAqB,CAAA;QACpE,WAAmB,CAAA,OAAe,EAAS,KAAU,EAAA;IACnD,QAAA,KAAK,EAAE,CAAC;YADS,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;YAAS,IAAK,CAAA,KAAA,GAAL,KAAK,CAAK;IAEnD,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AC,CAAC;IAEzD,YAAA,MAAM,aAAa,GAAGE,gBAAU,CAACC,YAAI,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IACxE,YAAA,IAAI,aAAa,KAAK,IAAI,CAAC,GAAG,EAAE;oBAC9B,MAAM,IAAI,0BAA0B,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1E,aAAA;aACF,CAAA,CAAA;IAAA,KAAA;IACF;;;;;;;;;;;"}
@@ -1,40 +1,48 @@
1
+ import { PermissionDeniedError, TaquitoError } from '@taquito/core';
1
2
  /**
2
3
  * @category Error
3
- * @description Error that indicates a failure in grabbing the public key
4
+ * @description Error indicates a failure in grabbing the public key
4
5
  */
5
- export declare class KeyNotFoundError extends Error {
6
- message: string;
7
- innerException: any;
8
- name: string;
9
- constructor(message: string, innerException: any);
6
+ export declare class PublicKeyNotFoundError extends TaquitoError {
7
+ pkh: string;
8
+ cause: any;
9
+ constructor(pkh: string, cause: any);
10
10
  }
11
11
  /**
12
12
  * @category Error
13
- * @description Error that indicates an unauthorized operation being attempted
13
+ * @description Error indicates an unauthorized operation being attempted
14
14
  */
15
- export declare class OperationNotAuthorizedError extends Error {
15
+ export declare class OperationNotAuthorizedError extends PermissionDeniedError {
16
16
  message: string;
17
- innerException: any;
18
- name: string;
19
- constructor(message: string, innerException: any);
17
+ cause: any;
18
+ constructor(message: string, cause: any);
20
19
  }
21
20
  /**
22
21
  * @category Error
23
- * @description Error that indicates bad signing data
22
+ * @description Error indicates bad signing data
24
23
  */
25
- export declare class BadSigningDataError extends Error {
26
- message: string;
27
- innerException: any;
28
- readonly data: any;
29
- name: string;
30
- constructor(message: string, innerException: any, data: any);
24
+ export declare class BadSigningDataError extends TaquitoError {
25
+ cause: any;
26
+ bytes: string;
27
+ constructor(cause: any, bytes: string, watermark?: Uint8Array);
28
+ }
29
+ /**
30
+ * @category Error
31
+ * @description Error indicates a mismatch between the initialized and the requested public key
32
+ */
33
+ export declare class PublicKeyVerificationError extends TaquitoError {
34
+ requestedPk: string;
35
+ requestedPkh: string;
36
+ initializedPkh: string;
37
+ constructor(requestedPk: string, requestedPkh: string, initializedPkh: string);
31
38
  }
32
39
  /**
33
40
  * @category Error
34
- * @description Error that indicates a mismatch between the initialized and the requested public key
41
+ * @description Error
35
42
  */
36
- export declare class PublicKeyMismatch extends Error {
37
- requested: string;
43
+ export declare class SignatureVerificationError extends TaquitoError {
44
+ bytes: string;
45
+ signature: string;
38
46
  name: string;
39
- constructor(requested: string, initialized: string);
47
+ constructor(bytes: string, signature: string);
40
48
  }
@@ -4,16 +4,6 @@
4
4
  */
5
5
  import { HttpBackend } from '@taquito/http-utils';
6
6
  import { Signer } from '@taquito/taquito';
7
- /**
8
- * @category Error
9
- * @description Error
10
- */
11
- export declare class SignatureVerificationFailedError extends Error {
12
- bytes: string;
13
- signature: string;
14
- name: string;
15
- constructor(bytes: string, signature: string);
16
- }
17
7
  export interface RemoteSignerOptions {
18
8
  headers?: {
19
9
  [key: string]: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taquito/remote-signer",
3
- "version": "16.2.0",
3
+ "version": "17.0.0-beta-RC.0",
4
4
  "description": "Remote signer provider",
5
5
  "keywords": [
6
6
  "tezos",
@@ -63,9 +63,10 @@
63
63
  "dependencies": {
64
64
  "@stablelib/blake2b": "^1.0.1",
65
65
  "@stablelib/ed25519": "^1.0.3",
66
- "@taquito/http-utils": "^16.2.0",
67
- "@taquito/taquito": "^16.2.0",
68
- "@taquito/utils": "^16.2.0",
66
+ "@taquito/core": "^17.0.0-beta-RC.0",
67
+ "@taquito/http-utils": "^17.0.0-beta-RC.0",
68
+ "@taquito/taquito": "^17.0.0-beta-RC.0",
69
+ "@taquito/utils": "^17.0.0-beta-RC.0",
69
70
  "typedarray-to-buffer": "^4.0.0"
70
71
  },
71
72
  "devDependencies": {
@@ -97,5 +98,5 @@
97
98
  "ts-toolbelt": "^9.6.0",
98
99
  "typescript": "~4.1.5"
99
100
  },
100
- "gitHead": "148b11675d2c3d3a10ce20c02dcece388ef59414"
101
+ "gitHead": "8acebfdf7b4361533d963eed87f03f8983dc679b"
101
102
  }