@taquito/tzip16 24.2.0 → 24.3.0-beta.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.
@@ -4,59 +4,25 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoTzip16 = {}, global.httpUtils, global.michelsonEncoder, global.taquitoUtils, global.taquitoCore, global.taquito, global.BigNumber, global.CryptoJS));
5
5
  })(this, (function (exports, httpUtils, michelsonEncoder, utils, core, taquito, BigNumber, CryptoJS) { 'use strict';
6
6
 
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
-
23
-
24
- function __awaiter(thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- }
33
-
34
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
- var e = new Error(message);
36
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
- };
38
-
39
7
  class HttpHandler {
40
8
  constructor() {
41
9
  this.httpBackend = new httpUtils.HttpBackend();
42
10
  }
43
- getMetadata(_contractAbstraction_1, _a, _context_1) {
44
- return __awaiter(this, arguments, void 0, function* (_contractAbstraction, { protocol, location }, _context) {
45
- return this.httpBackend.createRequest({
46
- url: `${protocol}:${decodeURIComponent(location)}`,
47
- method: 'GET',
48
- headers: {
49
- 'Content-Type': 'text/plain; charset=utf-8'
50
- },
51
- json: false
52
- });
11
+ async getMetadata(_contractAbstraction, { protocol, location }, _context) {
12
+ return this.httpBackend.createRequest({
13
+ url: `${protocol}:${decodeURIComponent(location)}`,
14
+ method: 'GET',
15
+ headers: {
16
+ 'Content-Type': 'text/plain; charset=utf-8'
17
+ },
18
+ json: false
53
19
  });
54
20
  }
55
21
  }
56
22
 
57
23
  /**
58
24
  * @category Error
59
- * @description Error that indicates missing big map metadata (non compliance to the TZIP-16 standard)
25
+ * Error that indicates missing big map metadata (non compliance to the TZIP-16 standard)
60
26
  */
61
27
  class BigMapContractMetadataNotFoundError extends core.TaquitoError {
62
28
  constructor(invalidBigMapId) {
@@ -69,7 +35,7 @@
69
35
  }
70
36
  /**
71
37
  * @category Error
72
- * @description Error that indicates missing metadata in storage
38
+ * Error that indicates missing metadata in storage
73
39
  */
74
40
  class ContractMetadataNotFoundError extends core.TaquitoError {
75
41
  constructor(info) {
@@ -81,7 +47,7 @@
81
47
  }
82
48
  /**
83
49
  * @category Error
84
- * @description Error that indicates missing URI (non compliance to the TZIP-16 standard)
50
+ * Error that indicates missing URI (non compliance to the TZIP-16 standard)
85
51
  */
86
52
  class UriNotFoundError extends core.TaquitoError {
87
53
  constructor() {
@@ -93,7 +59,7 @@
93
59
  }
94
60
  /**
95
61
  * @category Error
96
- * @description Error that indicates an invalid URI (non compliance to the TZIP-16 standard)
62
+ * Error that indicates an invalid URI (non compliance to the TZIP-16 standard)
97
63
  */
98
64
  class InvalidUriError extends core.TaquitoError {
99
65
  constructor(uri) {
@@ -105,7 +71,7 @@
105
71
  }
106
72
  /**
107
73
  * @category Error
108
- * @description Error that indicates invalid metadata (non compliance to the TZIP-16 standard)
74
+ * Error that indicates invalid metadata (non compliance to the TZIP-16 standard)
109
75
  */
110
76
  class InvalidContractMetadataError extends core.TaquitoError {
111
77
  constructor(invalidMetadata) {
@@ -117,7 +83,7 @@
117
83
  }
118
84
  /**
119
85
  * @category Error
120
- * @description Error that indicates the uri protocol being passed or used is not supported
86
+ * Error that indicates the uri protocol being passed or used is not supported
121
87
  */
122
88
  class ProtocolNotSupportedError extends core.ParameterValidationError {
123
89
  constructor(protocol) {
@@ -129,7 +95,7 @@
129
95
  }
130
96
  /**
131
97
  * @category Error
132
- * @description Error that indicates the metadata type is invalid (non compliance to the TZIP-16 standard)
98
+ * Error that indicates the metadata type is invalid (non compliance to the TZIP-16 standard)
133
99
  */
134
100
  class InvalidContractMetadataTypeError extends core.TaquitoError {
135
101
  constructor() {
@@ -141,7 +107,7 @@
141
107
  }
142
108
  /**
143
109
  * @category Error
144
- * @description Error that indicates metadata provider being unconfigured in the TezosToolkit instance
110
+ * Error that indicates metadata provider being unconfigured in the TezosToolkit instance
145
111
  */
146
112
  class UnconfiguredContractMetadataProviderError extends core.TezosToolkitConfigError {
147
113
  constructor() {
@@ -153,7 +119,7 @@
153
119
  }
154
120
  /**
155
121
  * @category Error
156
- * @description Error that indicates a forbidden instruction being found inside the View code
122
+ * Error that indicates a forbidden instruction being found inside the View code
157
123
  */
158
124
  class ForbiddenInstructionInViewCodeError extends core.TaquitoError {
159
125
  constructor(instruction) {
@@ -165,7 +131,7 @@
165
131
  }
166
132
  /**
167
133
  * @category Error
168
- * @description Error that indicates parameters are being passed when it is not required
134
+ * Error that indicates parameters are being passed when it is not required
169
135
  */
170
136
  class NoParameterExpectedError extends core.ParameterValidationError {
171
137
  constructor(viewName, args) {
@@ -186,29 +152,27 @@
186
152
  constructor() {
187
153
  this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w|%]+)$/;
188
154
  }
189
- getMetadata(contractAbstraction_1, _a, context_1) {
190
- return __awaiter(this, arguments, void 0, function* (contractAbstraction, { location }, context) {
191
- const parsedTezosStorageUri = this.parseTezosStorageUri(location);
192
- if (!parsedTezosStorageUri) {
193
- throw new InvalidUriError(`tezos-storage:${location}`);
194
- }
195
- const script = yield context.readProvider.getScript(parsedTezosStorageUri.contractAddress || contractAbstraction.address, 'head');
196
- const bigMapId = michelsonEncoder.Schema.fromRPCResponse({ script }).FindFirstInTopLevelPair(script.storage, typeOfValueToFind);
197
- if (!bigMapId || !bigMapId.int) {
198
- throw new BigMapContractMetadataNotFoundError(bigMapId);
199
- }
200
- const bytes = yield context.contract.getBigMapKeyByID(bigMapId.int.toString(), parsedTezosStorageUri.path, new michelsonEncoder.Schema(typeOfValueToFind));
201
- if (!bytes) {
202
- throw new ContractMetadataNotFoundError(`No '${parsedTezosStorageUri.path}' key found in the big map %metadata of the contract ${parsedTezosStorageUri.contractAddress || contractAbstraction.address}`);
203
- }
204
- if (!/^[0-9a-fA-F]*$/.test(bytes)) {
205
- throw new InvalidContractMetadataTypeError();
206
- }
207
- return utils.bytesToString(bytes);
208
- });
155
+ async getMetadata(contractAbstraction, { location }, context) {
156
+ const parsedTezosStorageUri = this.parseTezosStorageUri(location);
157
+ if (!parsedTezosStorageUri) {
158
+ throw new InvalidUriError(`tezos-storage:${location}`);
159
+ }
160
+ const script = await context.readProvider.getScript(parsedTezosStorageUri.contractAddress || contractAbstraction.address, 'head');
161
+ const bigMapId = michelsonEncoder.Schema.fromRPCResponse({ script }).FindFirstInTopLevelPair(script.storage, typeOfValueToFind);
162
+ if (!bigMapId || !bigMapId.int) {
163
+ throw new BigMapContractMetadataNotFoundError(bigMapId);
164
+ }
165
+ const bytes = await context.contract.getBigMapKeyByID(bigMapId.int.toString(), parsedTezosStorageUri.path, new michelsonEncoder.Schema(typeOfValueToFind));
166
+ if (!bytes) {
167
+ throw new ContractMetadataNotFoundError(`No '${parsedTezosStorageUri.path}' key found in the big map %metadata of the contract ${parsedTezosStorageUri.contractAddress || contractAbstraction.address}`);
168
+ }
169
+ if (!/^[0-9a-fA-F]*$/.test(bytes)) {
170
+ throw new InvalidContractMetadataTypeError();
171
+ }
172
+ return utils.bytesToString(bytes);
209
173
  }
210
174
  /**
211
- * @description Extract the smart contract address, the network and the path pointing to the metadata from the uri
175
+ * Extract the smart contract address, the network and the path pointing to the metadata from the uri
212
176
  * @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
213
177
  * @param tezosStorageURI URI (without the tezos-storage prefix)
214
178
  */
@@ -229,16 +193,14 @@
229
193
  this.httpBackend = new httpUtils.HttpBackend();
230
194
  this._ipfsGateway = ipfsGatheway ? ipfsGatheway : 'ipfs.io';
231
195
  }
232
- getMetadata(_contractAbstraction_1, _a, _context_1) {
233
- return __awaiter(this, arguments, void 0, function* (_contractAbstraction, { location }, _context) {
234
- return this.httpBackend.createRequest({
235
- url: `https://${this._ipfsGateway}/ipfs/${location.substring(2)}/`,
236
- method: 'GET',
237
- headers: {
238
- 'Content-Type': 'text/plain; charset=utf-8'
239
- },
240
- json: false
241
- });
196
+ async getMetadata(_contractAbstraction, { location }, _context) {
197
+ return this.httpBackend.createRequest({
198
+ url: `https://${this._ipfsGateway}/ipfs/${location.substring(2)}/`,
199
+ method: 'GET',
200
+ headers: {
201
+ 'Content-Type': 'text/plain; charset=utf-8'
202
+ },
203
+ json: false
242
204
  });
243
205
  }
244
206
  }
@@ -266,7 +228,7 @@
266
228
  };
267
229
  }
268
230
  /**
269
- * @description According to the tzip-16 standard, the following instructions must not be used in the code of the view:
231
+ * According to the tzip-16 standard, the following instructions must not be used in the code of the view:
270
232
  * 'AMOUNT', 'CREATE_CONTRACT', 'SENDER', 'SET_DELEGATE', 'SOURCE', and 'TRANSFER_TOKENS'
271
233
  * The method throw an error if an illegal instruction is found
272
234
  */
@@ -291,7 +253,7 @@
291
253
  }
292
254
  }
293
255
  /**
294
- * @description According to the tzip-16 standard, in the first version of the specification, the instruction SELF should only be used before ADDRESS
256
+ * According to the tzip-16 standard, in the first version of the specification, the instruction SELF should only be used before ADDRESS
295
257
  * The method throws an error is the instruction SELF is present, but not followed by ADDRESS
296
258
  */
297
259
  illegalUseOfSelfInstruction(code) {
@@ -309,7 +271,7 @@
309
271
  }
310
272
  }
311
273
  /**
312
- * @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.
274
+ * Loops through the view's code and replace SELF, BALANCE, NOW, and CHAIN_ID with Michelson expressions that match the current context, if applicable.
313
275
  */
314
276
  adaptViewCodeToContext(code, contractBalance, blockTimeStamp, chainId) {
315
277
  const instructionsToReplace = {
@@ -353,59 +315,57 @@
353
315
  const arg = parameterViewSchema.Encode(...args);
354
316
  return { arg, viewParameterType };
355
317
  }
356
- executeView(...args) {
357
- return __awaiter(this, void 0, void 0, function* () {
358
- // validate view code against tzip-16 specifications
359
- this.findForbiddenInstructionInViewCodeError(this.code);
360
- this.illegalUseOfSelfInstruction(this.code);
361
- const { arg, viewParameterType } = this.formatArgsAndParameter(args);
362
- const storageType = this.contract.script.code.find((x) => x.prim === 'storage');
363
- const storageArgs = storageType.args[0];
364
- // currentContext
365
- const storageValue = yield this.readProvider.getStorage(this.contract.address, 'head');
366
- const chainId = yield this.readProvider.getChainId();
367
- const contractBalance = (yield this.readProvider.getBalance(this.contract.address, 'head')).toString();
368
- const blockTimestamp = yield this.readProvider.getBlockTimestamp('head');
369
- const code = this.adaptViewCodeToContext(this.code, contractBalance, blockTimestamp, chainId);
370
- if (!this.viewParameterType) {
371
- code.unshift({ prim: 'CDR' });
372
- }
373
- const viewScript = {
374
- script: [
375
- { prim: 'parameter', args: [{ prim: 'pair', args: [viewParameterType, storageArgs] }] },
376
- { prim: 'storage', args: [{ prim: 'option', args: [this.returnType] }] },
377
- {
378
- prim: 'code',
379
- args: [
380
- [
381
- { prim: 'CAR' },
382
- code,
383
- { prim: 'SOME' },
384
- { prim: 'NIL', args: [{ prim: 'operation' }] },
385
- { prim: 'PAIR' },
386
- ],
318
+ async executeView(...args) {
319
+ // validate view code against tzip-16 specifications
320
+ this.findForbiddenInstructionInViewCodeError(this.code);
321
+ this.illegalUseOfSelfInstruction(this.code);
322
+ const { arg, viewParameterType } = this.formatArgsAndParameter(args);
323
+ const storageType = this.contract.script.code.find((x) => x.prim === 'storage');
324
+ const storageArgs = storageType.args[0];
325
+ // currentContext
326
+ const storageValue = await this.readProvider.getStorage(this.contract.address, 'head');
327
+ const chainId = await this.readProvider.getChainId();
328
+ const contractBalance = (await this.readProvider.getBalance(this.contract.address, 'head')).toString();
329
+ const blockTimestamp = await this.readProvider.getBlockTimestamp('head');
330
+ const code = this.adaptViewCodeToContext(this.code, contractBalance, blockTimestamp, chainId);
331
+ if (!this.viewParameterType) {
332
+ code.unshift({ prim: 'CDR' });
333
+ }
334
+ const viewScript = {
335
+ script: [
336
+ { prim: 'parameter', args: [{ prim: 'pair', args: [viewParameterType, storageArgs] }] },
337
+ { prim: 'storage', args: [{ prim: 'option', args: [this.returnType] }] },
338
+ {
339
+ prim: 'code',
340
+ args: [
341
+ [
342
+ { prim: 'CAR' },
343
+ code,
344
+ { prim: 'SOME' },
345
+ { prim: 'NIL', args: [{ prim: 'operation' }] },
346
+ { prim: 'PAIR' },
387
347
  ],
388
- },
389
- ],
390
- storage: { prim: 'None' },
391
- input: { prim: 'Pair', args: [arg, storageValue] },
392
- amount: '0',
393
- chain_id: chainId,
394
- balance: '0',
395
- };
396
- let result;
397
- try {
398
- result = yield this.rpc.runCode(viewScript);
399
- }
400
- catch (error) {
401
- const failWith = taquito.validateAndExtractFailwith(error);
402
- throw failWith
403
- ? new taquito.ViewSimulationError(`The simulation of the Michelson view failed with: ${JSON.stringify(failWith)}`, this.viewName, failWith, error)
404
- : error;
405
- }
406
- const viewResultSchema = new michelsonEncoder.ParameterSchema(this.returnType);
407
- return viewResultSchema.Execute(result.storage.args[0]);
408
- });
348
+ ],
349
+ },
350
+ ],
351
+ storage: { prim: 'None' },
352
+ input: { prim: 'Pair', args: [arg, storageValue] },
353
+ amount: '0',
354
+ chain_id: chainId,
355
+ balance: '0',
356
+ };
357
+ let result;
358
+ try {
359
+ result = await this.rpc.runCode(viewScript);
360
+ }
361
+ catch (error) {
362
+ const failWith = taquito.validateAndExtractFailwith(error);
363
+ throw failWith
364
+ ? new taquito.ViewSimulationError(`The simulation of the Michelson view failed with: ${JSON.stringify(failWith)}`, this.viewName, failWith, error)
365
+ : error;
366
+ }
367
+ const viewResultSchema = new michelsonEncoder.ParameterSchema(this.returnType);
368
+ return viewResultSchema.Execute(result.storage.args[0]);
409
369
  }
410
370
  }
411
371
 
@@ -444,120 +404,91 @@
444
404
  this._metadataViewsObject = {};
445
405
  this._metadataProvider = context.metadataProvider;
446
406
  }
447
- findMetadataBigMap() {
448
- return __awaiter(this, void 0, void 0, function* () {
449
- const metadataBigMapId = this.constractAbstraction.schema.FindFirstInTopLevelPair(yield this.context.readProvider.getStorage(this.constractAbstraction.address, 'head'), metadataBigMapType);
450
- if (!metadataBigMapId || !metadataBigMapId.int) {
451
- throw new BigMapContractMetadataNotFoundError(metadataBigMapId);
452
- }
453
- return new taquito.BigMapAbstraction(new BigNumber(metadataBigMapId['int']), new michelsonEncoder.Schema(metadataBigMapType), this.context.contract);
454
- });
407
+ async findMetadataBigMap() {
408
+ const metadataBigMapId = this.constractAbstraction.schema.FindFirstInTopLevelPair(await this.context.readProvider.getStorage(this.constractAbstraction.address, 'head'), metadataBigMapType);
409
+ if (!metadataBigMapId || !metadataBigMapId.int) {
410
+ throw new BigMapContractMetadataNotFoundError(metadataBigMapId);
411
+ }
412
+ return new taquito.BigMapAbstraction(new BigNumber(metadataBigMapId['int']), new michelsonEncoder.Schema(metadataBigMapType), this.context.contract);
455
413
  }
456
- getUriOrFail() {
457
- return __awaiter(this, void 0, void 0, function* () {
458
- const metadataBigMap = yield this.findMetadataBigMap();
459
- const uri = yield metadataBigMap.get('');
460
- if (!uri) {
461
- throw new UriNotFoundError();
462
- }
463
- return uri;
464
- });
414
+ async getUriOrFail() {
415
+ const metadataBigMap = await this.findMetadataBigMap();
416
+ const uri = await metadataBigMap.get('');
417
+ if (!uri) {
418
+ throw new UriNotFoundError();
419
+ }
420
+ return uri;
465
421
  }
466
422
  /**
467
- * @description Return an object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
423
+ * Return an object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
468
424
  */
469
- getMetadata() {
470
- return __awaiter(this, void 0, void 0, function* () {
471
- if (!this._metadataProvider) {
472
- throw new UnconfiguredContractMetadataProviderError();
473
- }
474
- if (!this._metadataEnvelope) {
475
- const uri = yield this.getUriOrFail();
476
- this._metadataEnvelope = yield this._metadataProvider.provideMetadata(this.constractAbstraction, utils.bytesToString(uri), this.context);
477
- }
478
- return this._metadataEnvelope;
479
- });
480
- }
481
- metadataName() {
482
- return __awaiter(this, void 0, void 0, function* () {
483
- if (!this._metadataEnvelope) {
484
- yield this.getMetadata();
485
- }
486
- return this._metadataEnvelope.metadata.name;
487
- });
488
- }
489
- metadataDescription() {
490
- return __awaiter(this, void 0, void 0, function* () {
491
- if (!this._metadataEnvelope)
492
- yield this.getMetadata();
493
- return this._metadataEnvelope.metadata.description;
494
- });
495
- }
496
- metadataVersion() {
497
- return __awaiter(this, void 0, void 0, function* () {
498
- if (!this._metadataEnvelope)
499
- yield this.getMetadata();
500
- return this._metadataEnvelope.metadata.version;
501
- });
502
- }
503
- metadataLicense() {
504
- return __awaiter(this, void 0, void 0, function* () {
505
- if (!this._metadataEnvelope)
506
- yield this.getMetadata();
507
- return this._metadataEnvelope.metadata.license;
508
- });
509
- }
510
- metadataAuthors() {
511
- return __awaiter(this, void 0, void 0, function* () {
512
- if (!this._metadataEnvelope)
513
- yield this.getMetadata();
514
- return this._metadataEnvelope.metadata.authors;
515
- });
516
- }
517
- metadataHomepage() {
518
- return __awaiter(this, void 0, void 0, function* () {
519
- if (!this._metadataEnvelope)
520
- yield this.getMetadata();
521
- return this._metadataEnvelope.metadata.homepage;
522
- });
523
- }
524
- metadataSource() {
525
- return __awaiter(this, void 0, void 0, function* () {
526
- if (!this._metadataEnvelope)
527
- yield this.getMetadata();
528
- return this._metadataEnvelope.metadata.source;
529
- });
530
- }
531
- metadataInterfaces() {
532
- return __awaiter(this, void 0, void 0, function* () {
533
- if (!this._metadataEnvelope)
534
- yield this.getMetadata();
535
- return this._metadataEnvelope.metadata.interfaces;
536
- });
537
- }
538
- metadataErrors() {
539
- return __awaiter(this, void 0, void 0, function* () {
540
- if (!this._metadataEnvelope)
541
- yield this.getMetadata();
542
- return this._metadataEnvelope.metadata.errors;
543
- });
425
+ async getMetadata() {
426
+ if (!this._metadataProvider) {
427
+ throw new UnconfiguredContractMetadataProviderError();
428
+ }
429
+ if (!this._metadataEnvelope) {
430
+ const uri = await this.getUriOrFail();
431
+ this._metadataEnvelope = await this._metadataProvider.provideMetadata(this.constractAbstraction, utils.bytesToString(uri), this.context);
432
+ }
433
+ return this._metadataEnvelope;
544
434
  }
545
- metadataViews() {
546
- return __awaiter(this, void 0, void 0, function* () {
547
- if (Object.keys(this._metadataViewsObject).length === 0) {
548
- yield this.initializeMetadataViewsList();
549
- }
550
- return this._metadataViewsObject;
551
- });
435
+ async metadataName() {
436
+ if (!this._metadataEnvelope) {
437
+ await this.getMetadata();
438
+ }
439
+ return this._metadataEnvelope.metadata.name;
440
+ }
441
+ async metadataDescription() {
442
+ if (!this._metadataEnvelope)
443
+ await this.getMetadata();
444
+ return this._metadataEnvelope.metadata.description;
445
+ }
446
+ async metadataVersion() {
447
+ if (!this._metadataEnvelope)
448
+ await this.getMetadata();
449
+ return this._metadataEnvelope.metadata.version;
450
+ }
451
+ async metadataLicense() {
452
+ if (!this._metadataEnvelope)
453
+ await this.getMetadata();
454
+ return this._metadataEnvelope.metadata.license;
455
+ }
456
+ async metadataAuthors() {
457
+ if (!this._metadataEnvelope)
458
+ await this.getMetadata();
459
+ return this._metadataEnvelope.metadata.authors;
460
+ }
461
+ async metadataHomepage() {
462
+ if (!this._metadataEnvelope)
463
+ await this.getMetadata();
464
+ return this._metadataEnvelope.metadata.homepage;
465
+ }
466
+ async metadataSource() {
467
+ if (!this._metadataEnvelope)
468
+ await this.getMetadata();
469
+ return this._metadataEnvelope.metadata.source;
470
+ }
471
+ async metadataInterfaces() {
472
+ if (!this._metadataEnvelope)
473
+ await this.getMetadata();
474
+ return this._metadataEnvelope.metadata.interfaces;
475
+ }
476
+ async metadataErrors() {
477
+ if (!this._metadataEnvelope)
478
+ await this.getMetadata();
479
+ return this._metadataEnvelope.metadata.errors;
480
+ }
481
+ async metadataViews() {
482
+ if (Object.keys(this._metadataViewsObject).length === 0) {
483
+ await this.initializeMetadataViewsList();
484
+ }
485
+ return this._metadataViewsObject;
552
486
  }
553
- initializeMetadataViewsList() {
554
- return __awaiter(this, void 0, void 0, function* () {
555
- var _a;
556
- const { metadata } = yield this.getMetadata();
557
- const metadataViews = {};
558
- (_a = metadata.views) === null || _a === void 0 ? void 0 : _a.forEach((view) => this.createViewImplementations(view, metadataViews));
559
- this._metadataViewsObject = metadataViews;
560
- });
487
+ async initializeMetadataViewsList() {
488
+ const { metadata } = await this.getMetadata();
489
+ const metadataViews = {};
490
+ metadata.views?.forEach((view) => this.createViewImplementations(view, metadataViews));
491
+ this._metadataViewsObject = metadataViews;
561
492
  }
562
493
  generateIndexedViewName(viewName, metadataViews) {
563
494
  let i = 1;
@@ -570,8 +501,7 @@
570
501
  return viewName;
571
502
  }
572
503
  createViewImplementations(view, metadataViews) {
573
- var _a;
574
- for (const viewImplementation of (_a = view === null || view === void 0 ? void 0 : view.implementations) !== null && _a !== void 0 ? _a : []) {
504
+ for (const viewImplementation of view?.implementations ?? []) {
575
505
  if (view.name) {
576
506
  // when views have the same name, add an index at the end of the name
577
507
  const viewName = this.generateIndexedViewName(view.name, metadataViews);
@@ -606,7 +536,7 @@
606
536
  }
607
537
 
608
538
  /**
609
- * @description: Metadata Provider
539
+ \* Metadata Provider
610
540
  */
611
541
  class MetadataProvider {
612
542
  constructor(handlers) {
@@ -614,38 +544,36 @@
614
544
  this.PROTOCOL_REGEX = /(?:sha256:\/\/0x(.*)\/)?(https?|ipfs|tezos-storage):(.*)/;
615
545
  }
616
546
  /**
617
- * @description Fetch the metadata by using the appropriate handler based on the protcol found in the URI
547
+ * Fetch the metadata by using the appropriate handler based on the protcol found in the URI
618
548
  * @returns an object which contains the uri, the metadata, an optional integrity check result and an optional SHA256 hash
619
- * @param _contractAbstraction the contract abstraction which contains the URI in its storage
620
- * @param _uri the decoded uri found in the storage
549
+ * @param contractAbstraction the contract abstraction which contains the URI in its storage
550
+ * @param uri the decoded uri found in the storage
621
551
  * @param context the TezosToolkit Context
622
552
  */
623
- provideMetadata(contractAbstraction, uri, context) {
624
- return __awaiter(this, void 0, void 0, function* () {
625
- const uriInfo = this.extractProtocolInfo(uri);
626
- if (!uriInfo || !uriInfo.location) {
627
- throw new InvalidUriError(uri);
628
- }
629
- const handler = this.handlers.get(uriInfo.protocol);
630
- if (!handler) {
631
- throw new ProtocolNotSupportedError(uriInfo.protocol);
632
- }
633
- const metadata = yield handler.getMetadata(contractAbstraction, uriInfo, context);
634
- const sha256Hash = calculateSHA256Hash(metadata);
635
- let metadataJSON;
636
- try {
637
- metadataJSON = JSON.parse(metadata);
638
- }
639
- catch (ex) {
640
- throw new InvalidContractMetadataError(metadata);
641
- }
642
- return {
643
- uri,
644
- metadata: metadataJSON,
645
- integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
646
- sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined,
647
- };
648
- });
553
+ async provideMetadata(contractAbstraction, uri, context) {
554
+ const uriInfo = this.extractProtocolInfo(uri);
555
+ if (!uriInfo || !uriInfo.location) {
556
+ throw new InvalidUriError(uri);
557
+ }
558
+ const handler = this.handlers.get(uriInfo.protocol);
559
+ if (!handler) {
560
+ throw new ProtocolNotSupportedError(uriInfo.protocol);
561
+ }
562
+ const metadata = await handler.getMetadata(contractAbstraction, uriInfo, context);
563
+ const sha256Hash = calculateSHA256Hash(metadata);
564
+ let metadataJSON;
565
+ try {
566
+ metadataJSON = JSON.parse(metadata);
567
+ }
568
+ catch (ex) {
569
+ throw new InvalidContractMetadataError(metadata);
570
+ }
571
+ return {
572
+ uri,
573
+ metadata: metadataJSON,
574
+ integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
575
+ sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined,
576
+ };
649
577
  }
650
578
  extractProtocolInfo(_uri) {
651
579
  const extractor = this.PROTOCOL_REGEX.exec(_uri);
@@ -676,8 +604,8 @@
676
604
 
677
605
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
678
606
  const VERSION = {
679
- "commitHash": "105a7b15cfb862a0732c204e0e9741098d697775",
680
- "version": "24.2.0"
607
+ "commitHash": "27675679db6515e8b092195ef5c58c2c0ea5f5c8",
608
+ "version": "24.3.0-beta.0"
681
609
  };
682
610
 
683
611
  Object.defineProperty(exports, "InvalidViewParameterError", {