@taquito/tzip16 11.1.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.
Files changed (36) hide show
  1. package/README.md +31 -18
  2. package/dist/lib/composer.js +5 -4
  3. package/dist/lib/composer.js.map +1 -1
  4. package/dist/lib/handlers/http-handler.js +14 -43
  5. package/dist/lib/handlers/http-handler.js.map +1 -1
  6. package/dist/lib/handlers/ipfs-handler.js +14 -44
  7. package/dist/lib/handlers/ipfs-handler.js.map +1 -1
  8. package/dist/lib/handlers/tezos-storage-handler.js +31 -70
  9. package/dist/lib/handlers/tezos-storage-handler.js.map +1 -1
  10. package/dist/lib/metadata-provider.js +36 -71
  11. package/dist/lib/metadata-provider.js.map +1 -1
  12. package/dist/lib/tzip16-contract-abstraction.js +72 -155
  13. package/dist/lib/tzip16-contract-abstraction.js.map +1 -1
  14. package/dist/lib/tzip16-errors.js +44 -55
  15. package/dist/lib/tzip16-errors.js.map +1 -1
  16. package/dist/lib/tzip16-extension.js +9 -10
  17. package/dist/lib/tzip16-extension.js.map +1 -1
  18. package/dist/lib/tzip16-utils.js +1 -1
  19. package/dist/lib/tzip16-utils.js.map +1 -1
  20. package/dist/lib/version.js +2 -4
  21. package/dist/lib/version.js.map +1 -1
  22. package/dist/lib/viewKind/michelson-storage-view.js +98 -196
  23. package/dist/lib/viewKind/michelson-storage-view.js.map +1 -1
  24. package/dist/lib/viewKind/viewFactory.js +16 -19
  25. package/dist/lib/viewKind/viewFactory.js.map +1 -1
  26. package/dist/taquito-tzip16.es6.js +569 -0
  27. package/dist/taquito-tzip16.es6.js.map +1 -0
  28. package/dist/taquito-tzip16.umd.js +326 -522
  29. package/dist/taquito-tzip16.umd.js.map +1 -1
  30. package/dist/types/composer.d.ts +1 -1
  31. package/dist/types/tzip16-errors.d.ts +15 -22
  32. package/dist/types/viewKind/michelson-storage-view.d.ts +3 -1
  33. package/dist/types/viewKind/viewFactory.d.ts +2 -2
  34. package/package.json +27 -27
  35. package/dist/taquito-tzip16.es5.js +0 -761
  36. package/dist/taquito-tzip16.es5.js.map +0 -1
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@taquito/http-utils'), require('@taquito/michelson-encoder'), require('@taquito/utils'), require('@taquito/taquito'), require('bignumber.js'), require('crypto-js')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@taquito/http-utils', '@taquito/michelson-encoder', '@taquito/utils', '@taquito/taquito', 'bignumber.js', 'crypto-js'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoTzip16 = {}, global.httpUtils, global.michelsonEncoder, global.utils, global.taquito, global.BigNumber, global.CryptoJS));
5
- }(this, (function (exports, httpUtils, michelsonEncoder, utils, taquito, BigNumber, CryptoJS) { 'use strict';
5
+ })(this, (function (exports, httpUtils, michelsonEncoder, utils, taquito, BigNumber, CryptoJS) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -32,228 +32,140 @@
32
32
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
33
  step((generator = generator.apply(thisArg, _arguments || [])).next());
34
34
  });
35
- }
36
-
37
- function __generator(thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (_) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- }
64
-
65
- function __values(o) {
66
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
67
- if (m) return m.call(o);
68
- if (o && typeof o.length === "number") return {
69
- next: function () {
70
- if (o && i >= o.length) o = void 0;
71
- return { value: o && o[i++], done: !o };
72
- }
73
- };
74
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
75
- }
76
-
77
- function __read(o, n) {
78
- var m = typeof Symbol === "function" && o[Symbol.iterator];
79
- if (!m) return o;
80
- var i = m.call(o), r, ar = [], e;
81
- try {
82
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
83
- }
84
- catch (error) { e = { error: error }; }
85
- finally {
86
- try {
87
- if (r && !r.done && (m = i["return"])) m.call(i);
88
- }
89
- finally { if (e) throw e.error; }
90
- }
91
- return ar;
92
- }
93
-
94
- /** @deprecated */
95
- function __spread() {
96
- for (var ar = [], i = 0; i < arguments.length; i++)
97
- ar = ar.concat(__read(arguments[i]));
98
- return ar;
99
35
  }
100
36
 
101
- var HttpHandler = /** @class */ (function () {
102
- function HttpHandler() {
37
+ class HttpHandler {
38
+ constructor() {
103
39
  this.httpBackend = new httpUtils.HttpBackend();
104
40
  }
105
- HttpHandler.prototype.getMetadata = function (_contractAbstraction, _a, _context) {
106
- var protocol = _a.protocol, location = _a.location;
107
- return __awaiter(this, void 0, void 0, function () {
108
- return __generator(this, function (_b) {
109
- return [2 /*return*/, this.httpBackend.createRequest({
110
- url: protocol + ":" + decodeURIComponent(location),
111
- method: 'GET',
112
- mimeType: "text; charset=utf-8",
113
- json: false
114
- })];
41
+ getMetadata(_contractAbstraction, { protocol, location }, _context) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ return this.httpBackend.createRequest({
44
+ url: `${protocol}:${decodeURIComponent(location)}`,
45
+ method: 'GET',
46
+ headers: {
47
+ 'Content-Type': 'text/plain; charset=utf-8'
48
+ },
49
+ json: false
115
50
  });
116
51
  });
117
- };
118
- return HttpHandler;
119
- }());
52
+ }
53
+ }
120
54
 
121
- var BigMapMetadataNotFound = /** @class */ (function () {
122
- function BigMapMetadataNotFound() {
55
+ class BigMapMetadataNotFound extends Error {
56
+ constructor() {
57
+ super('Non-compliance with the TZIP-016 standard. No big map named metadata was found in the contract storage.');
123
58
  this.name = 'BigMapMetadataNotFound';
124
- this.message = 'Non-compliance with the TZIP-016 standard. No big map named metadata was found in the contract storage.';
125
59
  }
126
- return BigMapMetadataNotFound;
127
- }());
128
- var MetadataNotFound = /** @class */ (function () {
129
- function MetadataNotFound(info) {
60
+ }
61
+ class MetadataNotFound extends Error {
62
+ constructor(info) {
63
+ super(`No metadata was found in the contract storage. ${info}`);
130
64
  this.info = info;
131
65
  this.name = 'MetadataNotFound';
132
- this.message = "No metadata was found in the contract storage. " + info;
133
66
  }
134
- return MetadataNotFound;
135
- }());
136
- var UriNotFound = /** @class */ (function () {
137
- function UriNotFound() {
67
+ }
68
+ class UriNotFound extends Error {
69
+ constructor() {
70
+ super('Non-compliance with the TZIP-016 standard. No URI found in the contract storage.');
138
71
  this.name = 'UriNotFound';
139
- this.message = 'Non-compliance with the TZIP-016 standard. No URI found in the contract storage.';
140
72
  }
141
- return UriNotFound;
142
- }());
143
- var InvalidUri = /** @class */ (function () {
144
- function InvalidUri(uri) {
73
+ }
74
+ class InvalidUri extends Error {
75
+ constructor(uri) {
76
+ super(`Non-compliance with the TZIP-016 standard. The URI is invalid: ${uri}.`);
145
77
  this.uri = uri;
146
78
  this.name = 'InvalidUri';
147
- this.message = "Non-compliance with the TZIP-016 standard. The URI is invalid: " + uri + ".";
148
79
  }
149
- return InvalidUri;
150
- }());
151
- var InvalidMetadata = /** @class */ (function () {
152
- function InvalidMetadata(invalidMetadata) {
80
+ }
81
+ class InvalidMetadata extends Error {
82
+ constructor(invalidMetadata) {
83
+ super(`The metadata found at the pointed ressource are not compliant with tzip16 standard: ${invalidMetadata}.`);
153
84
  this.invalidMetadata = invalidMetadata;
154
85
  this.name = 'InvalidMetadata';
155
- this.message = "The metadata found at the pointed ressource are not compliant with tzip16 standard: " + invalidMetadata + ".";
156
86
  }
157
- return InvalidMetadata;
158
- }());
159
- var ProtocolNotSupported = /** @class */ (function () {
160
- function ProtocolNotSupported(protocol) {
87
+ }
88
+ class ProtocolNotSupported extends Error {
89
+ constructor(protocol) {
90
+ super(`The protocol found in the URI is not supported: ${protocol}.`);
161
91
  this.protocol = protocol;
162
92
  this.name = 'ProtocolNotSupported';
163
- this.message = "The protocol found in the URI is not supported: " + protocol + ".";
164
93
  }
165
- return ProtocolNotSupported;
166
- }());
167
- var InvalidMetadataType = /** @class */ (function () {
168
- function InvalidMetadataType() {
94
+ }
95
+ class InvalidMetadataType extends Error {
96
+ constructor() {
97
+ super('The contract does not comply with the tzip16 standard. The type of metadata should be bytes.');
169
98
  this.name = 'InvalidMetadataType';
170
- this.message = 'The contract does not comply with the tzip16 standard. The type of metadata should be bytes.';
171
99
  }
172
- return InvalidMetadataType;
173
- }());
174
- var UnconfiguredMetadataProviderError = /** @class */ (function () {
175
- function UnconfiguredMetadataProviderError() {
100
+ }
101
+ class UnconfiguredMetadataProviderError extends Error {
102
+ constructor() {
103
+ super('No metadata provider has been configured. The default one can be configured by calling addExtension(new Tzip16Module()) on your TezosToolkit instance.');
176
104
  this.name = 'UnconfiguredMetadataProviderError';
177
- this.message = 'No metadata provider has been configured. The default one can be configured by calling addExtension(new Tzip16Module()) on your TezosToolkit instance.';
178
105
  }
179
- return UnconfiguredMetadataProviderError;
180
- }());
181
- var ForbiddenInstructionInViewCode = /** @class */ (function () {
182
- function ForbiddenInstructionInViewCode(instruction) {
106
+ }
107
+ class ForbiddenInstructionInViewCode extends Error {
108
+ constructor(instruction) {
109
+ super(`Error found in the code of the view. It contains a forbidden instruction: ${instruction}.`);
183
110
  this.instruction = instruction;
184
111
  this.name = 'ForbiddenInstructionInViewCode';
185
- this.message = "Error found in the code of the view. It contains a forbidden instruction: " + instruction + ".";
186
112
  }
187
- return ForbiddenInstructionInViewCode;
188
- }());
189
- var NoParameterExpectedError = /** @class */ (function () {
190
- function NoParameterExpectedError(viewName, args) {
113
+ }
114
+ class NoParameterExpectedError extends Error {
115
+ constructor(viewName, args) {
116
+ super(`${viewName} Received ${args.length} arguments while expecting no parameter or 'Unit'`);
191
117
  this.viewName = viewName;
192
118
  this.args = args;
193
119
  this.name = 'NoParameterExpectedError';
194
- this.message = viewName + " Received " + args.length + " arguments while expecting no parameter or 'Unit'";
195
120
  }
196
- return NoParameterExpectedError;
197
- }());
198
- var InvalidViewParameterError = /** @class */ (function () {
199
- function InvalidViewParameterError(viewName, sigs, args) {
121
+ }
122
+ class InvalidViewParameterError extends Error {
123
+ constructor(viewName, sigs, args) {
124
+ super(`${viewName} Received ${args.length} arguments while expecting one of the following signatures (${JSON.stringify(sigs)})`);
200
125
  this.viewName = viewName;
201
126
  this.sigs = sigs;
202
127
  this.args = args;
203
128
  this.name = 'InvalidViewParameterError';
204
- this.message = viewName + " Received " + args.length + " arguments while expecting one of the following signatures (" + JSON.stringify(sigs) + ")";
205
129
  }
206
- return InvalidViewParameterError;
207
- }());
130
+ }
208
131
 
209
- var typeOfValueToFind = {
132
+ const typeOfValueToFind = {
210
133
  prim: 'big_map',
211
134
  args: [{ prim: 'string' }, { prim: 'bytes' }],
212
135
  annots: ['%metadata'],
213
136
  };
214
- var TezosStorageHandler = /** @class */ (function () {
215
- function TezosStorageHandler() {
216
- this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w|\%]+)$/;
217
- }
218
- TezosStorageHandler.prototype.getMetadata = function (contractAbstraction, _a, context) {
219
- var location = _a.location;
220
- return __awaiter(this, void 0, void 0, function () {
221
- var parsedTezosStorageUri, storage, bigMapId, bytes;
222
- return __generator(this, function (_b) {
223
- switch (_b.label) {
224
- case 0:
225
- parsedTezosStorageUri = this.parseTezosStorageUri(location);
226
- if (!parsedTezosStorageUri) {
227
- throw new InvalidUri("tezos-storage:" + location);
228
- }
229
- return [4 /*yield*/, context.rpc.getNormalizedScript(parsedTezosStorageUri.contractAddress || contractAbstraction.address)];
230
- case 1:
231
- storage = _b.sent();
232
- bigMapId = michelsonEncoder.Schema.fromRPCResponse({ script: storage }).FindFirstInTopLevelPair(storage.storage, typeOfValueToFind);
233
- if (!bigMapId) {
234
- throw new BigMapMetadataNotFound();
235
- }
236
- return [4 /*yield*/, context.contract.getBigMapKeyByID(bigMapId['int'].toString(), parsedTezosStorageUri.path, new michelsonEncoder.Schema(typeOfValueToFind))];
237
- case 2:
238
- bytes = _b.sent();
239
- if (!bytes) {
240
- throw new MetadataNotFound("No '" + parsedTezosStorageUri.path + "' key found in the big map %metadata of the contract " + (parsedTezosStorageUri.contractAddress || contractAbstraction.address));
241
- }
242
- if (!/^[0-9a-fA-F]*$/.test(bytes)) {
243
- throw new InvalidMetadataType();
244
- }
245
- return [2 /*return*/, utils.bytes2Char(bytes)];
246
- }
247
- });
137
+ class TezosStorageHandler {
138
+ constructor() {
139
+ this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w|%]+)$/;
140
+ }
141
+ getMetadata(contractAbstraction, { location }, context) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ const parsedTezosStorageUri = this.parseTezosStorageUri(location);
144
+ if (!parsedTezosStorageUri) {
145
+ throw new InvalidUri(`tezos-storage:${location}`);
146
+ }
147
+ const script = yield context.readProvider.getScript(parsedTezosStorageUri.contractAddress || contractAbstraction.address, 'head');
148
+ const bigMapId = michelsonEncoder.Schema.fromRPCResponse({ script }).FindFirstInTopLevelPair(script.storage, typeOfValueToFind);
149
+ if (!bigMapId) {
150
+ throw new BigMapMetadataNotFound();
151
+ }
152
+ const bytes = yield context.contract.getBigMapKeyByID(bigMapId['int'].toString(), parsedTezosStorageUri.path, new michelsonEncoder.Schema(typeOfValueToFind));
153
+ if (!bytes) {
154
+ throw new MetadataNotFound(`No '${parsedTezosStorageUri.path}' key found in the big map %metadata of the contract ${parsedTezosStorageUri.contractAddress || contractAbstraction.address}`);
155
+ }
156
+ if (!/^[0-9a-fA-F]*$/.test(bytes)) {
157
+ throw new InvalidMetadataType();
158
+ }
159
+ return utils.bytes2Char(bytes);
248
160
  });
249
- };
161
+ }
250
162
  /**
251
163
  * @description Extract the smart contract address, the network and the path pointing to the metadata from the uri
252
164
  * @returns an object which contains the properties allowing to find where the metadata are located or it returns undefined if the uri is not valid
253
165
  * @param tezosStorageURI URI (without the tezos-storage prefix)
254
166
  */
255
- TezosStorageHandler.prototype.parseTezosStorageUri = function (tezosStorageURI) {
256
- var extractor = this.TEZOS_STORAGE_REGEX.exec(tezosStorageURI);
167
+ parseTezosStorageUri(tezosStorageURI) {
168
+ const extractor = this.TEZOS_STORAGE_REGEX.exec(tezosStorageURI);
257
169
  if (!extractor)
258
170
  return;
259
171
  return {
@@ -261,31 +173,27 @@
261
173
  network: extractor[2],
262
174
  path: decodeURIComponent(extractor[3]),
263
175
  };
264
- };
265
- return TezosStorageHandler;
266
- }());
176
+ }
177
+ }
267
178
 
268
- var IpfsHttpHandler = /** @class */ (function () {
269
- function IpfsHttpHandler(ipfsGatheway) {
179
+ class IpfsHttpHandler {
180
+ constructor(ipfsGatheway) {
270
181
  this.httpBackend = new httpUtils.HttpBackend();
271
182
  this._ipfsGateway = ipfsGatheway ? ipfsGatheway : 'ipfs.io';
272
183
  }
273
- IpfsHttpHandler.prototype.getMetadata = function (_contractAbstraction, _a, _context) {
274
- var location = _a.location;
275
- return __awaiter(this, void 0, void 0, function () {
276
- return __generator(this, function (_b) {
277
- return [2 /*return*/, this.httpBackend.createRequest({
278
- url: "https://" + this._ipfsGateway + "/ipfs/" + location.substring(2) + "/",
279
- method: 'GET',
280
- headers: { 'Content-Type': 'text/plain' },
281
- mimeType: "text; charset=utf-8",
282
- json: false
283
- })];
184
+ getMetadata(_contractAbstraction, { location }, _context) {
185
+ return __awaiter(this, void 0, void 0, function* () {
186
+ return this.httpBackend.createRequest({
187
+ url: `https://${this._ipfsGateway}/ipfs/${location.substring(2)}/`,
188
+ method: 'GET',
189
+ headers: {
190
+ 'Content-Type': 'text/plain; charset=utf-8'
191
+ },
192
+ json: false
284
193
  });
285
194
  });
286
- };
287
- return IpfsHttpHandler;
288
- }());
195
+ }
196
+ }
289
197
 
290
198
  exports.ViewImplementationType = void 0;
291
199
  (function (ViewImplementationType) {
@@ -293,17 +201,18 @@
293
201
  ViewImplementationType["REST_API_QUERY"] = "restApiQuery";
294
202
  })(exports.ViewImplementationType || (exports.ViewImplementationType = {}));
295
203
 
296
- var MichelsonStorageView = /** @class */ (function () {
297
- function MichelsonStorageView(viewName, contract, rpc, returnType, code, viewParameterType) {
204
+ class MichelsonStorageView {
205
+ constructor(viewName, contract, rpc, readProvider, returnType, code, viewParameterType) {
298
206
  this.viewName = viewName;
299
207
  this.contract = contract;
300
208
  this.rpc = rpc;
209
+ this.readProvider = readProvider;
301
210
  this.returnType = returnType;
302
211
  this.code = code;
303
212
  this.viewParameterType = viewParameterType;
304
- this.validateArgs = function (args, schema, viewName) {
305
- var sigs = schema.ExtractSignatures();
306
- if (!sigs.find(function (x) { return x.length === args.length; })) {
213
+ this.validateArgs = (args, schema, viewName) => {
214
+ const sigs = schema.ExtractSignatures();
215
+ if (!sigs.find((x) => x.length === args.length)) {
307
216
  throw new InvalidViewParameterError(viewName, sigs, args);
308
217
  }
309
218
  };
@@ -313,106 +222,73 @@
313
222
  * 'AMOUNT', 'CREATE_CONTRACT', 'SENDER', 'SET_DELEGATE', 'SOURCE', and 'TRANSFER_TOKENS'
314
223
  * The method throw an error if an illegal instruction is found
315
224
  */
316
- MichelsonStorageView.prototype.findForbiddenInstructionInViewCode = function (code) {
317
- var e_1, _a, e_2, _b;
318
- var illegalInstructions = [
225
+ findForbiddenInstructionInViewCode(code) {
226
+ const illegalInstructions = [
319
227
  'AMOUNT',
320
228
  'CREATE_CONTRACT',
321
229
  'SENDER',
322
230
  'SET_DELEGATE',
323
231
  'SOURCE',
324
- 'TRANSFER_TOKENS'
232
+ 'TRANSFER_TOKENS',
325
233
  ];
326
- try {
327
- for (var illegalInstructions_1 = __values(illegalInstructions), illegalInstructions_1_1 = illegalInstructions_1.next(); !illegalInstructions_1_1.done; illegalInstructions_1_1 = illegalInstructions_1.next()) {
328
- var forbiddenInstruction = illegalInstructions_1_1.value;
329
- try {
330
- for (var code_1 = (e_2 = void 0, __values(code)), code_1_1 = code_1.next(); !code_1_1.done; code_1_1 = code_1.next()) {
331
- var instruction = code_1_1.value;
332
- if (instruction.prim === forbiddenInstruction) {
333
- throw new ForbiddenInstructionInViewCode(forbiddenInstruction);
334
- }
335
- if (instruction.args && instruction.args.length !== 0) {
336
- this.findForbiddenInstructionInViewCode(instruction.args);
337
- }
338
- }
234
+ for (const forbiddenInstruction of illegalInstructions) {
235
+ for (const instruction of code) {
236
+ if (instruction.prim === forbiddenInstruction) {
237
+ throw new ForbiddenInstructionInViewCode(forbiddenInstruction);
339
238
  }
340
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
341
- finally {
342
- try {
343
- if (code_1_1 && !code_1_1.done && (_b = code_1.return)) _b.call(code_1);
344
- }
345
- finally { if (e_2) throw e_2.error; }
239
+ if (instruction.args && instruction.args.length !== 0) {
240
+ this.findForbiddenInstructionInViewCode(instruction.args);
346
241
  }
347
242
  }
348
243
  }
349
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
350
- finally {
351
- try {
352
- if (illegalInstructions_1_1 && !illegalInstructions_1_1.done && (_a = illegalInstructions_1.return)) _a.call(illegalInstructions_1);
353
- }
354
- finally { if (e_1) throw e_1.error; }
355
- }
356
- };
244
+ }
357
245
  /**
358
246
  * @description According to the tzip-16 standard, in the first version of the specification, the instruction SELF should only be used before ADDRESS
359
247
  * The method throws an error is the instruction SELF is present, but not followed by ADDRESS
360
248
  */
361
- MichelsonStorageView.prototype.illegalUseOfSelfInstruction = function (code) {
362
- var e_3, _a;
363
- try {
364
- for (var code_2 = __values(code), code_2_1 = code_2.next(); !code_2_1.done; code_2_1 = code_2.next()) {
365
- var instruction = code_2_1.value;
366
- if (instruction.prim === 'SELF') {
367
- var index = code.indexOf(instruction);
368
- var nextInstruction = code[index + 1] ? code[index + 1].prim : undefined;
369
- if (nextInstruction !== 'ADDRESS') {
370
- throw new ForbiddenInstructionInViewCode('the instruction SELF should only be used before ADDRESS');
371
- }
372
- }
373
- if (instruction.args && instruction.args.length !== 0) {
374
- this.illegalUseOfSelfInstruction(instruction.args);
249
+ illegalUseOfSelfInstruction(code) {
250
+ for (const instruction of code) {
251
+ if (instruction.prim === 'SELF') {
252
+ const index = code.indexOf(instruction);
253
+ const nextInstruction = code[index + 1] ? code[index + 1].prim : undefined;
254
+ if (nextInstruction !== 'ADDRESS') {
255
+ throw new ForbiddenInstructionInViewCode('the instruction SELF should only be used before ADDRESS');
375
256
  }
376
257
  }
377
- }
378
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
379
- finally {
380
- try {
381
- if (code_2_1 && !code_2_1.done && (_a = code_2.return)) _a.call(code_2);
258
+ if (instruction.args && instruction.args.length !== 0) {
259
+ this.illegalUseOfSelfInstruction(instruction.args);
382
260
  }
383
- finally { if (e_3) throw e_3.error; }
384
261
  }
385
- };
262
+ }
386
263
  /**
387
264
  * @description Loops through the view's code and replace SELF, BALANCE, NOW, and CHAIN_ID with Michelson expressions that match the current context, if applicable.
388
265
  */
389
- MichelsonStorageView.prototype.adaptViewCodeToContext = function (code, contractBalance, blockTimeStamp, chainId) {
390
- var _this = this;
391
- var instructionsToReplace = {
266
+ adaptViewCodeToContext(code, contractBalance, blockTimeStamp, chainId) {
267
+ const instructionsToReplace = {
392
268
  SELF: [
393
269
  { prim: 'PUSH', args: [{ prim: 'address' }, { string: this.contract.address }] },
394
270
  { prim: 'CONTRACT', args: [{ prim: 'unit' }] },
395
- { prim: 'IF_NONE', args: [[{ prim: 'UNIT' }, { prim: 'FAILWITH' }], []] }
271
+ { prim: 'IF_NONE', args: [[{ prim: 'UNIT' }, { prim: 'FAILWITH' }], []] },
396
272
  ],
397
273
  BALANCE: [{ prim: 'PUSH', args: [{ prim: 'mutez' }, { int: contractBalance }] }],
398
274
  NOW: [{ prim: 'PUSH', args: [{ prim: 'timestamp' }, { string: blockTimeStamp }] }],
399
- CHAIN_ID: [{ prim: 'PUSH', args: [{ prim: 'string' }, { string: chainId }] }]
275
+ CHAIN_ID: [{ prim: 'PUSH', args: [{ prim: 'string' }, { string: chainId }] }],
400
276
  };
401
- code.forEach(function (x, i) {
402
- for (var instruction in instructionsToReplace) {
277
+ code.forEach((x, i) => {
278
+ for (const instruction in instructionsToReplace) {
403
279
  if (x.prim === instruction) {
404
280
  code[i] = Object(instructionsToReplace)[instruction];
405
281
  }
406
282
  if (x.args && x.args.length !== 0) {
407
- _this.adaptViewCodeToContext(x.args, contractBalance, blockTimeStamp, chainId);
283
+ this.adaptViewCodeToContext(x.args, contractBalance, blockTimeStamp, chainId);
408
284
  }
409
285
  }
410
286
  });
411
287
  return code;
412
- };
413
- MichelsonStorageView.prototype.formatArgsAndParameter = function (argView) {
414
- var args = argView;
415
- var viewParameterType = this.viewParameterType;
288
+ }
289
+ formatArgsAndParameter(argView) {
290
+ let args = argView;
291
+ let viewParameterType = this.viewParameterType;
416
292
  if (!viewParameterType) {
417
293
  viewParameterType = { args: [], prim: 'unit', annots: [] };
418
294
  }
@@ -424,263 +300,206 @@
424
300
  throw new NoParameterExpectedError(this.viewName, argView);
425
301
  }
426
302
  }
427
- var parameterViewSchema = new michelsonEncoder.ParameterSchema(viewParameterType);
303
+ const parameterViewSchema = new michelsonEncoder.ParameterSchema(viewParameterType);
428
304
  this.validateArgs(args, parameterViewSchema, this.viewName);
429
- var arg = parameterViewSchema.Encode.apply(parameterViewSchema, __spread(args));
430
- return { arg: arg, viewParameterType: viewParameterType };
431
- };
432
- MichelsonStorageView.prototype.executeView = function () {
433
- var args = [];
434
- for (var _i = 0; _i < arguments.length; _i++) {
435
- args[_i] = arguments[_i];
436
- }
437
- return __awaiter(this, void 0, void 0, function () {
438
- var _a, arg, viewParameterType, storageType, storageArgs, storageValue, chainId, contractBalance, block, blockTimestamp, code, viewScript, result, viewResultSchema;
439
- return __generator(this, function (_b) {
440
- switch (_b.label) {
441
- case 0:
442
- // validate view code against tzip-16 specifications
443
- this.findForbiddenInstructionInViewCode(this.code);
444
- this.illegalUseOfSelfInstruction(this.code);
445
- _a = this.formatArgsAndParameter(args), arg = _a.arg, viewParameterType = _a.viewParameterType;
446
- storageType = this.contract.script.code.find(function (x) { return x.prim === 'storage'; });
447
- storageArgs = storageType.args[0];
448
- storageValue = this.contract.script.storage;
449
- return [4 /*yield*/, this.rpc.getChainId()];
450
- case 1:
451
- chainId = _b.sent();
452
- return [4 /*yield*/, this.rpc.getBalance(this.contract.address)];
453
- case 2:
454
- contractBalance = (_b.sent()).toString();
455
- return [4 /*yield*/, this.rpc.getBlock()];
456
- case 3:
457
- block = _b.sent();
458
- blockTimestamp = block.header.timestamp.toString();
459
- code = this.adaptViewCodeToContext(this.code, contractBalance, blockTimestamp, chainId);
460
- if (!this.viewParameterType) {
461
- code.unshift({ prim: 'CDR' });
462
- }
463
- viewScript = {
464
- script: [
465
- { prim: 'parameter', args: [{ prim: 'pair', args: [viewParameterType, storageArgs] }] },
466
- { prim: 'storage', args: [{ prim: 'option', args: [this.returnType] }] },
467
- {
468
- prim: 'code',
469
- args: [
470
- [
471
- { prim: 'CAR' },
472
- code,
473
- { prim: 'SOME' },
474
- { prim: 'NIL', args: [{ prim: 'operation' }] },
475
- { prim: 'PAIR' }
476
- ]
477
- ]
478
- }
305
+ const arg = parameterViewSchema.Encode(...args);
306
+ return { arg, viewParameterType };
307
+ }
308
+ executeView(...args) {
309
+ return __awaiter(this, void 0, void 0, function* () {
310
+ // validate view code against tzip-16 specifications
311
+ this.findForbiddenInstructionInViewCode(this.code);
312
+ this.illegalUseOfSelfInstruction(this.code);
313
+ const { arg, viewParameterType } = this.formatArgsAndParameter(args);
314
+ const storageType = this.contract.script.code.find((x) => x.prim === 'storage');
315
+ const storageArgs = storageType.args[0];
316
+ // currentContext
317
+ const storageValue = yield this.readProvider.getStorage(this.contract.address, 'head');
318
+ const chainId = yield this.readProvider.getChainId();
319
+ const contractBalance = (yield this.readProvider.getBalance(this.contract.address, 'head')).toString();
320
+ const blockTimestamp = yield this.readProvider.getBlockTimestamp('head');
321
+ const code = this.adaptViewCodeToContext(this.code, contractBalance, blockTimestamp, chainId);
322
+ if (!this.viewParameterType) {
323
+ code.unshift({ prim: 'CDR' });
324
+ }
325
+ const viewScript = {
326
+ script: [
327
+ { prim: 'parameter', args: [{ prim: 'pair', args: [viewParameterType, storageArgs] }] },
328
+ { prim: 'storage', args: [{ prim: 'option', args: [this.returnType] }] },
329
+ {
330
+ prim: 'code',
331
+ args: [
332
+ [
333
+ { prim: 'CAR' },
334
+ code,
335
+ { prim: 'SOME' },
336
+ { prim: 'NIL', args: [{ prim: 'operation' }] },
337
+ { prim: 'PAIR' },
479
338
  ],
480
- storage: { prim: 'None' },
481
- input: { prim: 'Pair', args: [arg, storageValue] },
482
- amount: '0',
483
- chain_id: chainId,
484
- balance: '0'
485
- };
486
- return [4 /*yield*/, this.rpc.runCode(viewScript)];
487
- case 4:
488
- result = _b.sent();
489
- viewResultSchema = new michelsonEncoder.ParameterSchema(this.returnType);
490
- return [2 /*return*/, viewResultSchema.Execute(result.storage.args[0])];
491
- }
492
- });
339
+ ],
340
+ },
341
+ ],
342
+ storage: { prim: 'None' },
343
+ input: { prim: 'Pair', args: [arg, storageValue] },
344
+ amount: '0',
345
+ chain_id: chainId,
346
+ balance: '0',
347
+ };
348
+ let result;
349
+ try {
350
+ result = yield this.rpc.runCode(viewScript);
351
+ }
352
+ catch (error) {
353
+ const failWith = taquito.validateAndExtractFailwith(error);
354
+ throw failWith
355
+ ? new taquito.ViewSimulationError(`The simulation of the Michelson view failed with: ${JSON.stringify(failWith)}`, this.viewName, failWith, error)
356
+ : error;
357
+ }
358
+ const viewResultSchema = new michelsonEncoder.ParameterSchema(this.returnType);
359
+ return viewResultSchema.Execute(result.storage.args[0]);
493
360
  });
494
- };
495
- return MichelsonStorageView;
496
- }());
497
-
498
- var ViewFactory = /** @class */ (function () {
499
- function ViewFactory() {
500
361
  }
501
- ViewFactory.prototype.getView = function (viewName, rpc, contract, viewImplementation) {
362
+ }
363
+
364
+ class ViewFactory {
365
+ getView(viewName, rpc, readProvider, contract, viewImplementation) {
502
366
  if (this.isMichelsonStorageView(viewImplementation)) {
503
- var viewValues_1 = viewImplementation[exports.ViewImplementationType.MICHELSON_STORAGE];
504
- if (!viewValues_1.returnType || !viewValues_1.code) {
505
- console.warn(viewName + " is missing mandatory code or returnType property therefore it will be skipped.");
367
+ const viewValues = viewImplementation[exports.ViewImplementationType.MICHELSON_STORAGE];
368
+ if (!viewValues.returnType || !viewValues.code) {
369
+ console.warn(`${viewName} is missing mandatory code or returnType property therefore it will be skipped.`);
506
370
  return;
507
371
  }
508
- return function () {
509
- var view = new MichelsonStorageView(viewName, contract, rpc, viewValues_1.returnType, viewValues_1.code, viewValues_1.parameter);
372
+ return () => {
373
+ const view = new MichelsonStorageView(viewName, contract, rpc, readProvider, viewValues.returnType, viewValues.code, viewValues.parameter);
510
374
  return view;
511
375
  };
512
376
  }
513
- };
514
- ViewFactory.prototype.getImplementationType = function (viewImplementation) {
377
+ }
378
+ getImplementationType(viewImplementation) {
515
379
  return Object.keys(viewImplementation)[0];
516
- };
517
- ViewFactory.prototype.isMichelsonStorageView = function (viewImplementation) {
518
- return this.getImplementationType(viewImplementation) === exports.ViewImplementationType.MICHELSON_STORAGE;
519
- };
520
- return ViewFactory;
521
- }());
380
+ }
381
+ isMichelsonStorageView(viewImplementation) {
382
+ return (this.getImplementationType(viewImplementation) === exports.ViewImplementationType.MICHELSON_STORAGE);
383
+ }
384
+ }
522
385
 
523
- var metadataBigMapType = {
386
+ const metadataBigMapType = {
524
387
  prim: 'big_map',
525
388
  args: [{ prim: 'string' }, { prim: 'bytes' }],
526
- annots: ['%metadata']
389
+ annots: ['%metadata'],
527
390
  };
528
- var Tzip16ContractAbstraction = /** @class */ (function () {
529
- function Tzip16ContractAbstraction(constractAbstraction, context) {
391
+ class Tzip16ContractAbstraction {
392
+ constructor(constractAbstraction, context) {
530
393
  this.constractAbstraction = constractAbstraction;
531
394
  this.context = context;
532
395
  this._viewFactory = new ViewFactory();
533
396
  this._metadataViewsObject = {};
534
397
  this._metadataProvider = context.metadataProvider;
535
398
  }
536
- Tzip16ContractAbstraction.prototype.findMetadataBigMap = function () {
537
- var metadataBigMapId = this.constractAbstraction.schema.FindFirstInTopLevelPair(this.constractAbstraction.script.storage, metadataBigMapType);
538
- if (!metadataBigMapId) {
539
- throw new BigMapMetadataNotFound();
540
- }
541
- return new taquito.BigMapAbstraction(new BigNumber__default['default'](metadataBigMapId['int']), new michelsonEncoder.Schema(metadataBigMapType), this.context.contract);
542
- };
543
- Tzip16ContractAbstraction.prototype.getUriOrFail = function () {
544
- return __awaiter(this, void 0, void 0, function () {
545
- var metadataBigMap, uri;
546
- return __generator(this, function (_a) {
547
- switch (_a.label) {
548
- case 0:
549
- metadataBigMap = this.findMetadataBigMap();
550
- return [4 /*yield*/, metadataBigMap.get('')];
551
- case 1:
552
- uri = _a.sent();
553
- if (!uri) {
554
- throw new UriNotFound();
555
- }
556
- return [2 /*return*/, uri];
557
- }
558
- });
399
+ findMetadataBigMap() {
400
+ return __awaiter(this, void 0, void 0, function* () {
401
+ const metadataBigMapId = this.constractAbstraction.schema.FindFirstInTopLevelPair(yield this.context.readProvider.getStorage(this.constractAbstraction.address, 'head'), metadataBigMapType);
402
+ if (!metadataBigMapId) {
403
+ throw new BigMapMetadataNotFound();
404
+ }
405
+ return new taquito.BigMapAbstraction(new BigNumber__default["default"](metadataBigMapId['int']), new michelsonEncoder.Schema(metadataBigMapType), this.context.contract);
406
+ });
407
+ }
408
+ getUriOrFail() {
409
+ return __awaiter(this, void 0, void 0, function* () {
410
+ const metadataBigMap = yield this.findMetadataBigMap();
411
+ const uri = yield metadataBigMap.get('');
412
+ if (!uri) {
413
+ throw new UriNotFound();
414
+ }
415
+ return uri;
559
416
  });
560
- };
417
+ }
561
418
  /**
562
419
  * @description Return an object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
563
420
  */
564
- Tzip16ContractAbstraction.prototype.getMetadata = function () {
565
- return __awaiter(this, void 0, void 0, function () {
566
- var uri, _a;
567
- return __generator(this, function (_b) {
568
- switch (_b.label) {
569
- case 0:
570
- if (!this._metadataProvider) {
571
- throw new UnconfiguredMetadataProviderError();
572
- }
573
- if (!!this._metadataEnvelope) return [3 /*break*/, 3];
574
- return [4 /*yield*/, this.getUriOrFail()];
575
- case 1:
576
- uri = _b.sent();
577
- _a = this;
578
- return [4 /*yield*/, this._metadataProvider.provideMetadata(this.constractAbstraction, utils.bytes2Char(uri), this.context)];
579
- case 2:
580
- _a._metadataEnvelope = _b.sent();
581
- _b.label = 3;
582
- case 3: return [2 /*return*/, this._metadataEnvelope];
583
- }
584
- });
421
+ getMetadata() {
422
+ return __awaiter(this, void 0, void 0, function* () {
423
+ if (!this._metadataProvider) {
424
+ throw new UnconfiguredMetadataProviderError();
425
+ }
426
+ if (!this._metadataEnvelope) {
427
+ const uri = yield this.getUriOrFail();
428
+ this._metadataEnvelope = yield this._metadataProvider.provideMetadata(this.constractAbstraction, utils.bytes2Char(uri), this.context);
429
+ }
430
+ return this._metadataEnvelope;
585
431
  });
586
- };
587
- Tzip16ContractAbstraction.prototype.metadataViews = function () {
588
- return __awaiter(this, void 0, void 0, function () {
589
- return __generator(this, function (_a) {
590
- switch (_a.label) {
591
- case 0:
592
- if (!(Object.keys(this._metadataViewsObject).length === 0)) return [3 /*break*/, 2];
593
- return [4 /*yield*/, this.initializeMetadataViewsList()];
594
- case 1:
595
- _a.sent();
596
- _a.label = 2;
597
- case 2: return [2 /*return*/, this._metadataViewsObject];
598
- }
599
- });
432
+ }
433
+ metadataViews() {
434
+ return __awaiter(this, void 0, void 0, function* () {
435
+ if (Object.keys(this._metadataViewsObject).length === 0) {
436
+ yield this.initializeMetadataViewsList();
437
+ }
438
+ return this._metadataViewsObject;
600
439
  });
601
- };
602
- Tzip16ContractAbstraction.prototype.initializeMetadataViewsList = function () {
440
+ }
441
+ initializeMetadataViewsList() {
603
442
  var _a;
604
- return __awaiter(this, void 0, void 0, function () {
605
- var metadata, metadataViews;
606
- var _this = this;
607
- return __generator(this, function (_b) {
608
- switch (_b.label) {
609
- case 0: return [4 /*yield*/, this.getMetadata()];
610
- case 1:
611
- metadata = (_b.sent()).metadata;
612
- metadataViews = {};
613
- (_a = metadata.views) === null || _a === void 0 ? void 0 : _a.forEach(function (view) { return _this.createViewImplementations(view, metadataViews); });
614
- this._metadataViewsObject = metadataViews;
615
- return [2 /*return*/];
616
- }
617
- });
443
+ return __awaiter(this, void 0, void 0, function* () {
444
+ const { metadata } = yield this.getMetadata();
445
+ const metadataViews = {};
446
+ (_a = metadata.views) === null || _a === void 0 ? void 0 : _a.forEach((view) => this.createViewImplementations(view, metadataViews));
447
+ this._metadataViewsObject = metadataViews;
618
448
  });
619
- };
620
- Tzip16ContractAbstraction.prototype.generateIndexedViewName = function (viewName, metadataViews) {
621
- var i = 1;
449
+ }
450
+ generateIndexedViewName(viewName, metadataViews) {
451
+ let i = 1;
622
452
  if (viewName in metadataViews) {
623
- while ("" + viewName + i in metadataViews) {
453
+ while (`${viewName}${i}` in metadataViews) {
624
454
  i++;
625
455
  }
626
- viewName = "" + viewName + i;
456
+ viewName = `${viewName}${i}`;
627
457
  }
628
458
  return viewName;
629
- };
630
- Tzip16ContractAbstraction.prototype.createViewImplementations = function (view, metadataViews) {
631
- var e_1, _a;
632
- var _b;
633
- try {
634
- for (var _c = __values((_b = view === null || view === void 0 ? void 0 : view.implementations) !== null && _b !== void 0 ? _b : []), _d = _c.next(); !_d.done; _d = _c.next()) {
635
- var viewImplementation = _d.value;
636
- if (view.name) {
637
- // when views have the same name, add an index at the end of the name
638
- var viewName = this.generateIndexedViewName(view.name, metadataViews);
639
- var metadataView = this._viewFactory.getView(viewName, this.context.rpc, this.constractAbstraction, viewImplementation);
640
- if (metadataView) {
641
- metadataViews[viewName] = metadataView;
642
- }
643
- else {
644
- console.warn("Skipped generating " + viewName + " because the view has an unsupported type: " + this._viewFactory.getImplementationType(viewImplementation));
645
- }
459
+ }
460
+ createViewImplementations(view, metadataViews) {
461
+ var _a;
462
+ for (const viewImplementation of (_a = view === null || view === void 0 ? void 0 : view.implementations) !== null && _a !== void 0 ? _a : []) {
463
+ if (view.name) {
464
+ // when views have the same name, add an index at the end of the name
465
+ const viewName = this.generateIndexedViewName(view.name, metadataViews);
466
+ const metadataView = this._viewFactory.getView(viewName, this.context.rpc, this.context.readProvider, this.constractAbstraction, viewImplementation);
467
+ if (metadataView) {
468
+ metadataViews[viewName] = metadataView;
469
+ }
470
+ else {
471
+ console.warn(`Skipped generating ${viewName} because the view has an unsupported type: ${this._viewFactory.getImplementationType(viewImplementation)}`);
646
472
  }
647
473
  }
648
474
  }
649
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
650
- finally {
651
- try {
652
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
653
- }
654
- finally { if (e_1) throw e_1.error; }
655
- }
656
- };
657
- return Tzip16ContractAbstraction;
658
- }());
475
+ }
476
+ }
659
477
 
660
- var ABSTRACTION_KEY = Symbol("Tzip16ContractAbstractionObjectKey");
478
+ const ABSTRACTION_KEY = Symbol('Tzip16ContractAbstractionObjectKey');
661
479
  function tzip16(abs, context) {
662
480
  return Object.assign(abs, {
663
481
  // namespace tzip16
664
- tzip16: function () {
482
+ tzip16() {
665
483
  if (!this[ABSTRACTION_KEY]) {
666
484
  this[ABSTRACTION_KEY] = new Tzip16ContractAbstraction(this, context);
667
485
  }
486
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
668
487
  return this[ABSTRACTION_KEY];
669
- }
488
+ },
670
489
  });
671
490
  }
672
491
 
673
492
  function calculateSHA256Hash(preimage) {
674
- return CryptoJS__default['default'].SHA256(preimage).toString(CryptoJS__default['default'].enc.Hex);
493
+ return CryptoJS__default["default"].SHA256(preimage).toString(CryptoJS__default["default"].enc.Hex);
675
494
  }
676
495
 
677
496
  /**
678
497
  * @description: Metadata Provider
679
498
  */
680
- var MetadataProvider = /** @class */ (function () {
681
- function MetadataProvider(handlers) {
499
+ class MetadataProvider {
500
+ constructor(handlers) {
682
501
  this.handlers = handlers;
683
- this.PROTOCOL_REGEX = /(?:sha256\:\/\/0x(.*)\/)?(https?|ipfs|tezos-storage)\:(.*)/;
502
+ this.PROTOCOL_REGEX = /(?:sha256:\/\/0x(.*)\/)?(https?|ipfs|tezos-storage):(.*)/;
684
503
  }
685
504
  /**
686
505
  * @description Fetch the metadata by using the appropriate handler based on the protcol found in the URI
@@ -689,88 +508,73 @@
689
508
  * @param _uri the decoded uri found in the storage
690
509
  * @param context the TezosToolkit Context
691
510
  */
692
- MetadataProvider.prototype.provideMetadata = function (contractAbstraction, uri, context) {
693
- return __awaiter(this, void 0, void 0, function () {
694
- var uriInfo, handler, metadata, sha256Hash, metadataJSON;
695
- return __generator(this, function (_a) {
696
- switch (_a.label) {
697
- case 0:
698
- uriInfo = this.extractProtocolInfo(uri);
699
- if (!uriInfo || !uriInfo.location) {
700
- throw new InvalidUri(uri);
701
- }
702
- handler = this.handlers.get(uriInfo.protocol);
703
- if (!handler) {
704
- throw new ProtocolNotSupported(uriInfo.protocol);
705
- }
706
- return [4 /*yield*/, handler.getMetadata(contractAbstraction, uriInfo, context)];
707
- case 1:
708
- metadata = _a.sent();
709
- sha256Hash = calculateSHA256Hash(metadata);
710
- try {
711
- metadataJSON = JSON.parse(metadata);
712
- }
713
- catch (ex) {
714
- throw new InvalidMetadata(metadata);
715
- }
716
- return [2 /*return*/, {
717
- uri: uri,
718
- metadata: metadataJSON,
719
- integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
720
- sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined
721
- }];
722
- }
723
- });
511
+ provideMetadata(contractAbstraction, uri, context) {
512
+ return __awaiter(this, void 0, void 0, function* () {
513
+ const uriInfo = this.extractProtocolInfo(uri);
514
+ if (!uriInfo || !uriInfo.location) {
515
+ throw new InvalidUri(uri);
516
+ }
517
+ const handler = this.handlers.get(uriInfo.protocol);
518
+ if (!handler) {
519
+ throw new ProtocolNotSupported(uriInfo.protocol);
520
+ }
521
+ const metadata = yield handler.getMetadata(contractAbstraction, uriInfo, context);
522
+ const sha256Hash = calculateSHA256Hash(metadata);
523
+ let metadataJSON;
524
+ try {
525
+ metadataJSON = JSON.parse(metadata);
526
+ }
527
+ catch (ex) {
528
+ throw new InvalidMetadata(metadata);
529
+ }
530
+ return {
531
+ uri,
532
+ metadata: metadataJSON,
533
+ integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
534
+ sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined,
535
+ };
724
536
  });
725
- };
726
- MetadataProvider.prototype.extractProtocolInfo = function (_uri) {
727
- var extractor = this.PROTOCOL_REGEX.exec(_uri);
537
+ }
538
+ extractProtocolInfo(_uri) {
539
+ const extractor = this.PROTOCOL_REGEX.exec(_uri);
728
540
  if (!extractor)
729
541
  return;
730
542
  return {
731
543
  sha256hash: extractor[1],
732
544
  protocol: extractor[2],
733
- location: extractor[3]
545
+ location: extractor[3],
734
546
  };
735
- };
736
- return MetadataProvider;
737
- }());
547
+ }
548
+ }
738
549
 
739
- var DEFAULT_HANDLERS = new Map([
550
+ const DEFAULT_HANDLERS = new Map([
740
551
  ['http', new HttpHandler()],
741
552
  ['https', new HttpHandler()],
742
553
  ['tezos-storage', new TezosStorageHandler()],
743
554
  ['ipfs', new IpfsHttpHandler()]
744
555
  ]);
745
- var Tzip16Module = /** @class */ (function () {
746
- function Tzip16Module(metadataProvider) {
556
+ class Tzip16Module {
557
+ constructor(metadataProvider) {
747
558
  this._metadataProvider = metadataProvider ? metadataProvider : new MetadataProvider(DEFAULT_HANDLERS);
748
559
  }
749
- Tzip16Module.prototype.configureContext = function (context) {
560
+ configureContext(context) {
750
561
  Object.assign(context, { metadataProvider: this._metadataProvider });
751
- };
752
- return Tzip16Module;
753
- }());
562
+ }
563
+ }
754
564
 
755
565
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
756
- /* tslint:disable */
757
- var VERSION = {
758
- "commitHash": "e1723ab725df70755b4cd73b75aa981f913d0d5c",
759
- "version": "11.1.0"
760
- };
761
- /* tslint:enable */
566
+ const VERSION = {
567
+ "commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
568
+ "version": "12.0.0-beta-RC.0"
569
+ };
762
570
 
763
571
  Object.defineProperty(exports, 'bytes2Char', {
764
572
  enumerable: true,
765
- get: function () {
766
- return utils.bytes2Char;
767
- }
573
+ get: function () { return utils.bytes2Char; }
768
574
  });
769
575
  Object.defineProperty(exports, 'char2Bytes', {
770
576
  enumerable: true,
771
- get: function () {
772
- return utils.char2Bytes;
773
- }
577
+ get: function () { return utils.char2Bytes; }
774
578
  });
775
579
  exports.BigMapMetadataNotFound = BigMapMetadataNotFound;
776
580
  exports.DEFAULT_HANDLERS = DEFAULT_HANDLERS;
@@ -798,5 +602,5 @@
798
602
 
799
603
  Object.defineProperty(exports, '__esModule', { value: true });
800
604
 
801
- })));
605
+ }));
802
606
  //# sourceMappingURL=taquito-tzip16.umd.js.map