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