@taquito/remote-signer 11.2.0 → 12.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.
- package/dist/lib/taquito-remote-signer.js +3 -4
- package/dist/lib/taquito-remote-signer.js.map +1 -1
- package/dist/lib/version.js +2 -2
- package/dist/lib/version.js.map +1 -1
- package/dist/taquito-remote-signer.es6.js +5 -6
- package/dist/taquito-remote-signer.es6.js.map +1 -1
- package/dist/taquito-remote-signer.umd.js +8 -10
- package/dist/taquito-remote-signer.umd.js.map +1 -1
- package/package.json +7 -7
|
@@ -16,7 +16,7 @@ exports.RemoteSigner = exports.VERSION = void 0;
|
|
|
16
16
|
*/
|
|
17
17
|
const http_utils_1 = require("@taquito/http-utils");
|
|
18
18
|
const utils_1 = require("@taquito/utils");
|
|
19
|
-
const
|
|
19
|
+
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
|
var version_1 = require("./version");
|
|
@@ -143,10 +143,9 @@ class RemoteSigner {
|
|
|
143
143
|
}
|
|
144
144
|
verifyPublicKey(publicKey) {
|
|
145
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
yield libsodium_wrappers_1.default.ready;
|
|
147
146
|
const curve = publicKey.substring(0, 2);
|
|
148
|
-
const _publicKey =
|
|
149
|
-
const publicKeyHash = utils_1.b58cencode(
|
|
147
|
+
const _publicKey = utils_1.b58cdecode(publicKey, pref[curve].pk);
|
|
148
|
+
const publicKeyHash = utils_1.b58cencode(blake2b_1.hash(_publicKey, 20), pref[curve].pkh);
|
|
150
149
|
if (publicKeyHash !== this.pkh) {
|
|
151
150
|
throw new Error(`Requested public key does not match the initialized public key hash: {
|
|
152
151
|
publicKey: ${publicKey},
|
|
@@ -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;
|
|
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,qCAA8F;AAiB9F,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;KAClB;IACD,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;KAClB;IACD,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;KAClB;CACF,CAAC;AAEF,MAAa,YAAY;IACvB,YACU,GAAW,EACX,OAAe,EACf,UAA+B,EAAE,EACjC,OAAO,IAAI,wBAAW,EAAE;QAHxB,QAAG,GAAH,GAAG,CAAQ;QACX,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAA0B;QACjC,SAAI,GAAJ,IAAI,CAAoB;QAEhC,IAAI,uBAAe,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,wBAAgB,CAAC,KAAK,EAAE;YACxD,MAAO,IAAI,2BAAmB,CAAC,4BA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EAAE,EAAE;gBACX,IAAI,EAAE,YAAY,8BAAiB,EAAE;oBACnC,IAAI,EAAE,CAAC,MAAM,KAAK,wBAAW,CAAC,SAAS,EAAE;wBACvC,MAAM,IAAI,yBAAgB,CAAC,kBAAkB,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;qBAC9D;yBAAM,IAAI,EAAE,CAAC,MAAM,KAAK,wBAAW,CAAC,SAAS,EAAE;wBAC9C,MAAM,IAAI,oCAA2B,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAC;qBAC/E;yBAAM,IAAI,EAAE,CAAC,MAAM,KAAK,wBAAW,CAAC,WAAW,EAAE;wBAChD,MAAM,IAAI,4BAAmB,CAAC,cAAc,EAAE,EAAE,EAAE;4BAChD,KAAK;4BACL,SAAS;yBACV,CAAC,CAAC;qBACJ;iBACF;gBACD,MAAM,EAAE,CAAC;aACV;QACH,CAAC;KAAA;IAEK,eAAe,CAAC,SAAiB;;YACrC,MAAM,KAAK,GAAG,SAAS,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,KAAK,CACb;uBACe,SAAS;2BACL,IAAI,CAAC,GAAG;UACzB,CACH,CAAC;aACH;QACH,CAAC;KAAA;CACF;AAtHD,oCAsHC"}
|
package/dist/lib/version.js
CHANGED
|
@@ -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": "
|
|
7
|
-
"version": "
|
|
6
|
+
"commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
|
|
7
|
+
"version": "12.0.0-beta-RC.0"
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
package/dist/lib/version.js.map
CHANGED
|
@@ -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,
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { HttpBackend, HttpResponseError, STATUS_CODE } from '@taquito/http-utils';
|
|
2
2
|
import { prefix, validateKeyHash, ValidationResult, InvalidKeyHashError, hex2buf, mergebuf, buf2hex, isValidPrefix, b58cdecode, verifySignature, b58cencode } from '@taquito/utils';
|
|
3
|
-
import
|
|
3
|
+
import { hash } from '@stablelib/blake2b';
|
|
4
4
|
import toBuffer from 'typedarray-to-buffer';
|
|
5
5
|
|
|
6
6
|
/*! *****************************************************************************
|
|
@@ -56,8 +56,8 @@ class BadSigningDataError extends Error {
|
|
|
56
56
|
|
|
57
57
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
58
58
|
const VERSION = {
|
|
59
|
-
"commitHash": "
|
|
60
|
-
"version": "
|
|
59
|
+
"commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
|
|
60
|
+
"version": "12.0.0-beta-RC.0"
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const pref = {
|
|
@@ -182,10 +182,9 @@ class RemoteSigner {
|
|
|
182
182
|
}
|
|
183
183
|
verifyPublicKey(publicKey) {
|
|
184
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
yield sodium.ready;
|
|
186
185
|
const curve = publicKey.substring(0, 2);
|
|
187
|
-
const _publicKey =
|
|
188
|
-
const publicKeyHash = b58cencode(
|
|
186
|
+
const _publicKey = b58cdecode(publicKey, pref[curve].pk);
|
|
187
|
+
const publicKeyHash = b58cencode(hash(_publicKey, 20), pref[curve].pkh);
|
|
189
188
|
if (publicKeyHash !== this.pkh) {
|
|
190
189
|
throw new Error(`Requested public key does not match the initialized public key hash: {
|
|
191
190
|
publicKey: ${publicKey},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-remote-signer.es6.js","sources":["../src/errors.ts","../src/version.ts","../src/taquito-remote-signer.ts"],"sourcesContent":["export class KeyNotFoundError extends Error {\n public name = 'KeyNotFoundError';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\nexport class OperationNotAuthorizedError extends Error {\n public name = 'OperationNotAuthorized';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\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// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"81f0a5b103f867f57fbe5d526315c375a3788346\",\n \"version\": \"11.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 InvalidKeyHashError\n} from '@taquito/utils';\n\nimport sodium from 'libsodium-wrappers';\nimport toBuffer from 'typedarray-to-buffer';\nimport { BadSigningDataError, KeyNotFoundError, OperationNotAuthorizedError } from './errors';\nimport { Signer } from '@taquito/taquito';\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 if (validateKeyHash(this.pkh) !== ValidationResult.VALID) {\n throw new InvalidKeyHashError(`Invalid Public Key Hash: ${this.pkh}`);\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 Error('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 Error(`Unsupported signature given by remote signer: ${signature}`);\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 Error(\n `Signature failed verification against public key:\n {\n bytes: ${watermarkedBytes},\n signature: ${signature}\n }`\n );\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 await sodium.ready;\n const curve = publicKey.substring(0, 2) as curves;\n const _publicKey = toBuffer(b58cdecode(publicKey, pref[curve].pk));\n\n const publicKeyHash = b58cencode(sodium.crypto_generichash(20, _publicKey), pref[curve].pkh);\n if (publicKeyHash !== this.pkh) {\n throw new Error(\n `Requested public key does not match the initialized public key hash: {\n publicKey: ${publicKey},\n publicKeyHash: ${this.pkh}\n }`\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAa,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AI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;YAC7F,IAAI,aAAa,KAAK,IAAI,CAAC,GAAG,EAAE;gBAC9B,MAAM,IAAI,KAAK,CACb;uBACe,SAAS;2BACL,IAAI,CAAC,GAAG;UACzB,CACH,CAAC;aACH;SACF;KAAA;;;;;"}
|
|
1
|
+
{"version":3,"file":"taquito-remote-signer.es6.js","sources":["../src/errors.ts","../src/version.ts","../src/taquito-remote-signer.ts"],"sourcesContent":["export class KeyNotFoundError extends Error {\n public name = 'KeyNotFoundError';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\nexport class OperationNotAuthorizedError extends Error {\n public name = 'OperationNotAuthorized';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\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// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0\",\n \"version\": \"12.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 InvalidKeyHashError\n} from '@taquito/utils';\nimport { hash } from '@stablelib/blake2b';\nimport toBuffer from 'typedarray-to-buffer';\nimport { BadSigningDataError, KeyNotFoundError, OperationNotAuthorizedError } from './errors';\nimport { Signer } from '@taquito/taquito';\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 if (validateKeyHash(this.pkh) !== ValidationResult.VALID) {\n throw new InvalidKeyHashError(`Invalid Public Key Hash: ${this.pkh}`);\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 Error('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 Error(`Unsupported signature given by remote signer: ${signature}`);\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 Error(\n `Signature failed verification against public key:\n {\n bytes: ${watermarkedBytes},\n signature: ${signature}\n }`\n );\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 Error(\n `Requested public key does not match the initialized public key hash: {\n publicKey: ${publicKey},\n publicKeyHash: ${this.pkh}\n }`\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;KAGhC;CACF;MAEY,2BAA4B,SAAQ,KAAK;IAEpD,YAAmB,OAAe,EAAS,cAAmB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,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AE,EAAE;gBACX,IAAI,EAAE,YAAY,iBAAiB,EAAE;oBACnC,IAAI,EAAE,CAAC,MAAM,KAAK,WAAW,CAAC,SAAS,EAAE;wBACvC,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;qBAC9D;yBAAM,IAAI,EAAE,CAAC,MAAM,KAAK,WAAW,CAAC,SAAS,EAAE;wBAC9C,MAAM,IAAI,2BAA2B,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAC;qBAC/E;yBAAM,IAAI,EAAE,CAAC,MAAM,KAAK,WAAW,CAAC,WAAW,EAAE;wBAChD,MAAM,IAAI,mBAAmB,CAAC,cAAc,EAAE,EAAE,EAAE;4BAChD,KAAK;4BACL,SAAS;yBACV,CAAC,CAAC;qBACJ;iBACF;gBACD,MAAM,EAAE,CAAC;aACV;SACF;KAAA;IAEK,eAAe,CAAC,SAAiB;;YACrC,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAW,CAAC;YAClD,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;YAEzD,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,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,KAAK,CACb;uBACe,SAAS;2BACL,IAAI,CAAC,GAAG;UACzB,CACH,CAAC;aACH;SACF;KAAA;;;;;"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@taquito/http-utils'), require('@taquito/utils'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@taquito/http-utils', '@taquito/utils', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoRemoteSigner = {}, global.httpUtils, global.utils, global.
|
|
5
|
-
})(this, (function (exports, httpUtils, utils,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@taquito/http-utils'), require('@taquito/utils'), require('@stablelib/blake2b'), require('typedarray-to-buffer')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@taquito/http-utils', '@taquito/utils', '@stablelib/blake2b', 'typedarray-to-buffer'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoRemoteSigner = {}, global.httpUtils, global.utils, global.blake2b, global.toBuffer));
|
|
5
|
+
})(this, (function (exports, httpUtils, utils, blake2b, toBuffer) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
-
var sodium__default = /*#__PURE__*/_interopDefaultLegacy(sodium);
|
|
10
9
|
var toBuffer__default = /*#__PURE__*/_interopDefaultLegacy(toBuffer);
|
|
11
10
|
|
|
12
11
|
/*! *****************************************************************************
|
|
@@ -62,8 +61,8 @@
|
|
|
62
61
|
|
|
63
62
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
64
63
|
const VERSION = {
|
|
65
|
-
"commitHash": "
|
|
66
|
-
"version": "
|
|
64
|
+
"commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
|
|
65
|
+
"version": "12.0.0-beta-RC.0"
|
|
67
66
|
};
|
|
68
67
|
|
|
69
68
|
const pref = {
|
|
@@ -188,10 +187,9 @@
|
|
|
188
187
|
}
|
|
189
188
|
verifyPublicKey(publicKey) {
|
|
190
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
yield sodium__default["default"].ready;
|
|
192
190
|
const curve = publicKey.substring(0, 2);
|
|
193
|
-
const _publicKey =
|
|
194
|
-
const publicKeyHash = utils.b58cencode(
|
|
191
|
+
const _publicKey = utils.b58cdecode(publicKey, pref[curve].pk);
|
|
192
|
+
const publicKeyHash = utils.b58cencode(blake2b.hash(_publicKey, 20), pref[curve].pkh);
|
|
195
193
|
if (publicKeyHash !== this.pkh) {
|
|
196
194
|
throw new Error(`Requested public key does not match the initialized public key hash: {
|
|
197
195
|
publicKey: ${publicKey},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-remote-signer.umd.js","sources":["../src/errors.ts","../src/version.ts","../src/taquito-remote-signer.ts"],"sourcesContent":["export class KeyNotFoundError extends Error {\n public name = 'KeyNotFoundError';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\nexport class OperationNotAuthorizedError extends Error {\n public name = 'OperationNotAuthorized';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\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// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"81f0a5b103f867f57fbe5d526315c375a3788346\",\n \"version\": \"11.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 InvalidKeyHashError\n} from '@taquito/utils';\n\nimport sodium from 'libsodium-wrappers';\nimport toBuffer from 'typedarray-to-buffer';\nimport { BadSigningDataError, KeyNotFoundError, OperationNotAuthorizedError } from './errors';\nimport { Signer } from '@taquito/taquito';\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 if (validateKeyHash(this.pkh) !== ValidationResult.VALID) {\n throw new InvalidKeyHashError(`Invalid Public Key Hash: ${this.pkh}`);\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 Error('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 Error(`Unsupported signature given by remote signer: ${signature}`);\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 Error(\n `Signature failed verification against public key:\n {\n bytes: ${watermarkedBytes},\n signature: ${signature}\n }`\n );\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 await sodium.ready;\n const curve = publicKey.substring(0, 2) as curves;\n const _publicKey = toBuffer(b58cdecode(publicKey, pref[curve].pk));\n\n const publicKeyHash = b58cencode(sodium.crypto_generichash(20, _publicKey), pref[curve].pkh);\n if (publicKeyHash !== this.pkh) {\n throw new Error(\n `Requested public key does not match the initialized public key hash: {\n publicKey: ${publicKey},\n publicKeyHash: ${this.pkh}\n }`\n );\n }\n }\n}\n"],"names":["prefix","HttpBackend","validateKeyHash","ValidationResult","InvalidKeyHashError","HttpResponseError","STATUS_CODE","hex2buf","mergebuf","buf2hex","toBuffer","isValidPrefix","b58cdecode","verifySignature","b58cencode","sodium"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAAa,gBAAiB,SAAQ,KAAK;QAEzC,YAAmB,OAAe,EAAS,cAAmB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EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;gBAC7F,IAAI,aAAa,KAAK,IAAI,CAAC,GAAG,EAAE;oBAC9B,MAAM,IAAI,KAAK,CACb;uBACe,SAAS;2BACL,IAAI,CAAC,GAAG;UACzB,CACH,CAAC;iBACH;aACF;SAAA;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"taquito-remote-signer.umd.js","sources":["../src/errors.ts","../src/version.ts","../src/taquito-remote-signer.ts"],"sourcesContent":["export class KeyNotFoundError extends Error {\n public name = 'KeyNotFoundError';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\n\nexport class OperationNotAuthorizedError extends Error {\n public name = 'OperationNotAuthorized';\n constructor(public message: string, public innerException: any) {\n super(message);\n }\n}\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// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!\nexport const VERSION = {\n \"commitHash\": \"5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0\",\n \"version\": \"12.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 InvalidKeyHashError\n} from '@taquito/utils';\nimport { hash } from '@stablelib/blake2b';\nimport toBuffer from 'typedarray-to-buffer';\nimport { BadSigningDataError, KeyNotFoundError, OperationNotAuthorizedError } from './errors';\nimport { Signer } from '@taquito/taquito';\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 if (validateKeyHash(this.pkh) !== ValidationResult.VALID) {\n throw new InvalidKeyHashError(`Invalid Public Key Hash: ${this.pkh}`);\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 Error('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 Error(`Unsupported signature given by remote signer: ${signature}`);\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 Error(\n `Signature failed verification against public key:\n {\n bytes: ${watermarkedBytes},\n signature: ${signature}\n }`\n );\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 Error(\n `Requested public key does not match the initialized public key hash: {\n publicKey: ${publicKey},\n publicKeyHash: ${this.pkh}\n }`\n );\n }\n }\n}\n"],"names":["prefix","HttpBackend","validateKeyHash","ValidationResult","InvalidKeyHashError","HttpResponseError","STATUS_CODE","hex2buf","mergebuf","buf2hex","toBuffer","isValidPrefix","b58cdecode","verifySignature","b58cencode","hash"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAAa,gBAAiB,SAAQ,KAAK;QAEzC,YAAmB,OAAe,EAAS,cAAmB;YAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;YADE,YAAO,GAAP,OAAO,CAAQ;YAAS,mBAAc,GAAd,cAAc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ACL,IAAI,CAAC,GAAG;UACzB,CACH,CAAC;iBACH;aACF;SAAA;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taquito/remote-signer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0-beta-RC.0",
|
|
4
4
|
"description": "Remote signer provider",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tezos",
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
66
|
-
"@taquito/utils": "^
|
|
67
|
-
"
|
|
64
|
+
"@stablelib/blake2b": "^1.0.1",
|
|
65
|
+
"@stablelib/ed25519": "^1.0.2",
|
|
66
|
+
"@taquito/http-utils": "^12.0.0-beta-RC.0",
|
|
67
|
+
"@taquito/taquito": "^12.0.0-beta-RC.0",
|
|
68
|
+
"@taquito/utils": "^12.0.0-beta-RC.0",
|
|
68
69
|
"typedarray-to-buffer": "^4.0.0"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"@types/bluebird": "^3.5.36",
|
|
72
73
|
"@types/jest": "^26.0.24",
|
|
73
|
-
"@types/libsodium-wrappers": "0.7.8",
|
|
74
74
|
"@types/node": "^17.0.0",
|
|
75
75
|
"@types/ws": "^8.2.2",
|
|
76
76
|
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"ts-toolbelt": "^9.6.0",
|
|
98
98
|
"typescript": "~4.1.5"
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "02c79fe3e9bff81668b22a17f0e2aa4bc8d1e231"
|
|
101
101
|
}
|