@taquito/tzip16 25.2.0-beta1 → 25.2.0-beta3

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.
@@ -18062,6 +18062,7 @@ class IpfsHttpHandler {
18062
18062
  */
18063
18063
  constructor(ipfsGateway, timeout = 10000) {
18064
18064
  this.timeout = timeout;
18065
+ this.integrityVerified = true;
18065
18066
  this.httpBackend = new HttpBackend();
18066
18067
  if (!Number.isFinite(timeout) || timeout <= 0)
18067
18068
  throw new RangeError('IPFS gateway timeout must be positive');
@@ -18176,6 +18177,10 @@ class MichelsonStorageView {
18176
18177
  ];
18177
18178
  for (const forbiddenInstruction of illegalInstructions) {
18178
18179
  for (const instruction of code) {
18180
+ if (Array.isArray(instruction)) {
18181
+ this.findForbiddenInstructionInViewCodeError(instruction);
18182
+ continue;
18183
+ }
18179
18184
  if (instruction.prim === forbiddenInstruction) {
18180
18185
  throw new ForbiddenInstructionInViewCodeError(forbiddenInstruction);
18181
18186
  }
@@ -18190,10 +18195,15 @@ class MichelsonStorageView {
18190
18195
  * The method throws an error is the instruction SELF is present, but not followed by ADDRESS
18191
18196
  */
18192
18197
  illegalUseOfSelfInstruction(code) {
18193
- for (const instruction of code) {
18198
+ for (let i = 0; i < code.length; i++) {
18199
+ const instruction = code[i];
18200
+ if (Array.isArray(instruction)) {
18201
+ this.illegalUseOfSelfInstruction(instruction);
18202
+ continue;
18203
+ }
18194
18204
  if (instruction.prim === 'SELF') {
18195
- const index = code.indexOf(instruction);
18196
- const nextInstruction = code[index + 1] ? code[index + 1].prim : undefined;
18205
+ const next = code[i + 1];
18206
+ const nextInstruction = next && !Array.isArray(next) ? next.prim : undefined;
18197
18207
  if (nextInstruction !== 'ADDRESS') {
18198
18208
  throw new ForbiddenInstructionInViewCodeError('the instruction SELF should only be used before ADDRESS');
18199
18209
  }
@@ -18218,13 +18228,17 @@ class MichelsonStorageView {
18218
18228
  CHAIN_ID: [{ prim: 'PUSH', args: [{ prim: 'string' }, { string: chainId }] }],
18219
18229
  };
18220
18230
  code.forEach((x, i) => {
18231
+ if (Array.isArray(x)) {
18232
+ this.adaptViewCodeToContext(x, contractBalance, blockTimeStamp, chainId);
18233
+ return;
18234
+ }
18221
18235
  for (const instruction in instructionsToReplace) {
18222
18236
  if (x.prim === instruction) {
18223
18237
  code[i] = Object(instructionsToReplace)[instruction];
18224
18238
  }
18225
- if (x.args && x.args.length !== 0) {
18226
- this.adaptViewCodeToContext(x.args, contractBalance, blockTimeStamp, chainId);
18227
- }
18239
+ }
18240
+ if (x.args && x.args.length !== 0) {
18241
+ this.adaptViewCodeToContext(x.args, contractBalance, blockTimeStamp, chainId);
18228
18242
  }
18229
18243
  });
18230
18244
  return code;
@@ -18262,7 +18276,7 @@ class MichelsonStorageView {
18262
18276
  const chainId = await this.readProvider.getChainId();
18263
18277
  const contractBalance = (await this.readProvider.getBalance(this.contract.address, this.contract.readBlock)).toString();
18264
18278
  const blockTimestamp = await this.readProvider.getBlockTimestamp(this.contract.readBlock);
18265
- const code = this.adaptViewCodeToContext(this.code, contractBalance, blockTimestamp, chainId);
18279
+ const code = this.adaptViewCodeToContext(structuredClone(this.code), contractBalance, blockTimestamp, chainId);
18266
18280
  if (!this.viewParameterType) {
18267
18281
  code.unshift({ prim: 'CDR' });
18268
18282
  }
@@ -18357,15 +18371,33 @@ class Tzip16ContractAbstraction {
18357
18371
  return uri;
18358
18372
  }
18359
18373
  /**
18360
- * Return an object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
18374
+ * Fetch and cache the contract metadata envelope on this `Tzip16ContractAbstraction` instance.
18375
+ * Subsequent calls to `getMetadata()`, `metadataViews()`, and the `metadata*()` accessors
18376
+ * reuse the cached envelope without re-fetching.
18377
+ *
18378
+ * @returns an object containing the parsed `metadata`, the `uri`, the `sha256Hash` of the raw
18379
+ * metadata string, and an optional `integrityCheckResult` (`true` when verified via a
18380
+ * `sha256://` commitment or a content-verifying handler such as `IpfsHttpHandler`).
18361
18381
  */
18362
18382
  async getMetadata() {
18363
18383
  if (!this._metadataProvider) {
18364
18384
  throw new UnconfiguredContractMetadataProviderError();
18365
18385
  }
18366
18386
  if (!this._metadataEnvelope) {
18367
- const uri = await this.getUriOrFail();
18368
- this._metadataEnvelope = await this._metadataProvider.provideMetadata(this.constractAbstraction, bytesToString(uri), this.context);
18387
+ if (!this._metadataEnvelopePromise) {
18388
+ this._metadataEnvelopePromise = (async () => {
18389
+ try {
18390
+ const uri = await this.getUriOrFail();
18391
+ const envelope = await this._metadataProvider.provideMetadata(this.constractAbstraction, bytesToString(uri), this.context);
18392
+ this._metadataEnvelope = envelope;
18393
+ return envelope;
18394
+ }
18395
+ finally {
18396
+ this._metadataEnvelopePromise = undefined;
18397
+ }
18398
+ })();
18399
+ }
18400
+ return this._metadataEnvelopePromise;
18369
18401
  }
18370
18402
  return this._metadataEnvelope;
18371
18403
  }
@@ -18415,6 +18447,11 @@ class Tzip16ContractAbstraction {
18415
18447
  await this.getMetadata();
18416
18448
  return this._metadataEnvelope.metadata.errors;
18417
18449
  }
18450
+ /**
18451
+ * Build and cache off-chain view implementations from the cached metadata envelope returned by
18452
+ * `getMetadata()`. If `getMetadata()` has already resolved on this instance, `metadataViews()`
18453
+ * uses that same cached envelope without re-fetching.
18454
+ */
18418
18455
  async metadataViews() {
18419
18456
  if (Object.keys(this._metadataViewsObject).length === 0) {
18420
18457
  await this.initializeMetadataViewsList();
@@ -18502,7 +18539,7 @@ class MetadataProvider {
18502
18539
  try {
18503
18540
  metadataJSON = JSON.parse(metadata.replace(/^\uFEFF/, ''));
18504
18541
  }
18505
- catch (ex) {
18542
+ catch {
18506
18543
  const error = new InvalidContractMetadataError(metadata);
18507
18544
  error.message = `Unable to parse metadata from ${uri} as JSON.`;
18508
18545
  if (uriInfo.protocol === 'ipfs') {
@@ -18515,8 +18552,8 @@ class MetadataProvider {
18515
18552
  return {
18516
18553
  uri,
18517
18554
  metadata: metadataJSON,
18518
- integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
18519
- sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined,
18555
+ integrityCheckResult: uriInfo.sha256hash !== undefined || handler.integrityVerified === true ? true : undefined,
18556
+ sha256Hash,
18520
18557
  };
18521
18558
  }
18522
18559
  extractProtocolInfo(_uri) {
@@ -18567,8 +18604,8 @@ class Tzip16Module {
18567
18604
 
18568
18605
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
18569
18606
  const VERSION = {
18570
- "commitHash": "f79aa35b2b21310921f9170da32d441aff54b110",
18571
- "version": "25.2.0-beta1"
18607
+ "commitHash": "ef213b695ad2612be52315f787f1d719c968eddc",
18608
+ "version": "25.2.0-beta3"
18572
18609
  };
18573
18610
 
18574
18611
  export { BigMapContractMetadataNotFoundError, ContractMetadataNotFoundError, DEFAULT_HANDLERS, ForbiddenInstructionInViewCodeError, HttpHandler, InvalidContractMetadataError, InvalidContractMetadataTypeError, InvalidUriError, IpfsGatewayError, IpfsHttpHandler, MetadataHashMismatchError, MetadataProvider, MichelsonStorageView, NoParameterExpectedError, ProtocolNotSupportedError, TezosStorageHandler, Tzip16ContractAbstraction, Tzip16Module, UnconfiguredContractMetadataProviderError, UriNotFoundError, VERSION, ViewFactory, ViewImplementationType, calculateSHA256Hash, tzip16 };