@taquito/tzip16 25.2.0-beta0 → 25.2.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -13
- package/dist/taquito-tzip16.es6.js +18093 -141
- package/dist/taquito-tzip16.es6.js.map +1 -1
- package/dist/taquito-tzip16.umd.js +18086 -132
- package/dist/taquito-tzip16.umd.js.map +1 -1
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/handlers/ipfs-handler.d.ts +17 -3
- package/dist/types/handlers/ipfs-metadata.d.ts +8 -0
- package/dist/types/metadata-provider.d.ts +2 -1
- package/dist/types/tzip16-contract-abstraction.d.ts +13 -1
- package/package.json +16 -12
- package/dist/lib/composer.js +0 -17
- package/dist/lib/errors.js +0 -138
- package/dist/lib/handlers/http-handler.js +0 -20
- package/dist/lib/handlers/ipfs-handler.js +0 -35
- package/dist/lib/handlers/tezos-storage-handler.js +0 -55
- package/dist/lib/metadata-interface.js +0 -8
- package/dist/lib/metadata-provider.js +0 -80
- package/dist/lib/taquito-tzip16.js +0 -36
- package/dist/lib/tzip16-contract-abstraction.js +0 -140
- package/dist/lib/tzip16-extension.js +0 -22
- package/dist/lib/tzip16-utils.js +0 -10
- package/dist/lib/version.js +0 -8
- package/dist/lib/viewKind/interface.js +0 -2
- package/dist/lib/viewKind/michelson-storage-view.js +0 -168
- package/dist/lib/viewKind/viewFactory.js +0 -27
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { ParameterValidationError, TaquitoError, TezosToolkitConfigError } from '@taquito/core';
|
|
2
2
|
export { InvalidViewParameterError } from '@taquito/core';
|
|
3
|
+
/** Metadata bytes do not match the hash committed by their URI or CID. */
|
|
4
|
+
export declare class MetadataHashMismatchError extends TaquitoError {
|
|
5
|
+
readonly uri: string;
|
|
6
|
+
readonly expectedHash: string;
|
|
7
|
+
readonly actualHash: string;
|
|
8
|
+
constructor(uri: string, expectedHash: string, actualHash: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Every configured IPFS gateway failed to return verified metadata.
|
|
12
|
+
* For production reliability, configure a paid gateway service with an SLA or a self-hosted HTTPS IPFS gateway via `IpfsHttpHandler`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class IpfsGatewayError extends TaquitoError {
|
|
15
|
+
readonly errors: readonly Error[];
|
|
16
|
+
constructor(errors: readonly Error[]);
|
|
17
|
+
}
|
|
3
18
|
/**
|
|
4
19
|
* @category Error
|
|
5
20
|
* Error that indicates missing big map metadata (non compliance to the TZIP-16 standard)
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { HttpBackend } from '@taquito/http-utils';
|
|
2
2
|
import { ContractAbstraction, ContractProvider, Wallet, Context } from '@taquito/taquito';
|
|
3
3
|
import { Handler, Tzip16Uri } from '../metadata-provider';
|
|
4
|
+
/**
|
|
5
|
+
* Handler for retrieving and verifying TZIP-16 contract metadata over HTTPS IPFS gateways.
|
|
6
|
+
*
|
|
7
|
+
* By default, tries the public gateways `ipfs.filebase.io` and `gateway.pinata.cloud` in order
|
|
8
|
+
* with a 10-second per-gateway deadline. Public gateways are best-effort and may rate-limit or
|
|
9
|
+
* time out; for production applications, configure a paid IPFS gateway service with an SLA or
|
|
10
|
+
* a self-hosted HTTPS IPFS gateway supporting raw block retrieval (`?format=raw`).
|
|
11
|
+
*/
|
|
4
12
|
export declare class IpfsHttpHandler implements Handler {
|
|
5
|
-
private
|
|
13
|
+
private readonly timeout;
|
|
14
|
+
private readonly gateways;
|
|
15
|
+
readonly integrityVerified = true;
|
|
6
16
|
httpBackend: HttpBackend;
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @param ipfsGateway - Optional HTTPS gateway hostname (without `https://` or `/ipfs/`). For production, use a paid gateway service with an SLA or a self-hosted HTTPS IPFS gateway. When omitted, falls back across the default public gateways.
|
|
19
|
+
* @param timeout - Total deadline in milliseconds for each gateway, including all block and body reads (default `10000`).
|
|
20
|
+
*/
|
|
21
|
+
constructor(ipfsGateway?: string, timeout?: number);
|
|
22
|
+
getMetadata(_contractAbstraction: ContractAbstraction<ContractProvider | Wallet>, { location, sha256hash }: Tzip16Uri, _context: Context): Promise<string>;
|
|
9
23
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const MAX_IPFS_BLOCK_BYTES: number;
|
|
2
|
+
export declare const MAX_IPFS_METADATA_BYTES: number;
|
|
3
|
+
export declare function parseIpfsLocation(location: string): {
|
|
4
|
+
root: string;
|
|
5
|
+
path: string[];
|
|
6
|
+
};
|
|
7
|
+
/** Only verified blocks enter the UnixFS decoder, including directory and HAMT links. */
|
|
8
|
+
export declare function readVerifiedIpfsFile(root: string, path: string[], fetchBlock: (cid: string) => Promise<Uint8Array>, signal: AbortSignal): Promise<string>;
|
|
@@ -7,10 +7,11 @@ export interface MetadataProviderInterface {
|
|
|
7
7
|
export interface MetadataEnvelope {
|
|
8
8
|
uri: string;
|
|
9
9
|
integrityCheckResult?: boolean;
|
|
10
|
-
sha256Hash
|
|
10
|
+
sha256Hash: string;
|
|
11
11
|
metadata: MetadataInterface;
|
|
12
12
|
}
|
|
13
13
|
export interface Handler {
|
|
14
|
+
readonly integrityVerified?: boolean;
|
|
14
15
|
getMetadata(contractAbstraction: ContractAbstraction<ContractProvider | Wallet>, uri: Tzip16Uri, context: Context): Promise<string>;
|
|
15
16
|
}
|
|
16
17
|
export interface Tzip16Uri {
|
|
@@ -9,13 +9,20 @@ export declare class Tzip16ContractAbstraction {
|
|
|
9
9
|
private context;
|
|
10
10
|
private _metadataProvider;
|
|
11
11
|
private _metadataEnvelope?;
|
|
12
|
+
private _metadataEnvelopePromise?;
|
|
12
13
|
private _viewFactory;
|
|
13
14
|
private _metadataViewsObject;
|
|
14
15
|
constructor(constractAbstraction: ContractAbstraction<ContractProvider | Wallet>, context: MetadataContext);
|
|
15
16
|
private findMetadataBigMap;
|
|
16
17
|
private getUriOrFail;
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* Fetch and cache the contract metadata envelope on this `Tzip16ContractAbstraction` instance.
|
|
20
|
+
* Subsequent calls to `getMetadata()`, `metadataViews()`, and the `metadata*()` accessors
|
|
21
|
+
* reuse the cached envelope without re-fetching.
|
|
22
|
+
*
|
|
23
|
+
* @returns an object containing the parsed `metadata`, the `uri`, the `sha256Hash` of the raw
|
|
24
|
+
* metadata string, and an optional `integrityCheckResult` (`true` when verified via a
|
|
25
|
+
* `sha256://` commitment or a content-verifying handler such as `IpfsHttpHandler`).
|
|
19
26
|
*/
|
|
20
27
|
getMetadata(): Promise<MetadataEnvelope>;
|
|
21
28
|
metadataName(): Promise<string | undefined>;
|
|
@@ -33,6 +40,11 @@ export declare class Tzip16ContractAbstraction {
|
|
|
33
40
|
} | undefined>;
|
|
34
41
|
metadataInterfaces(): Promise<string[] | undefined>;
|
|
35
42
|
metadataErrors(): Promise<import("./metadata-interface").ErrorsTzip16 | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Build and cache off-chain view implementations from the cached metadata envelope returned by
|
|
45
|
+
* `getMetadata()`. If `getMetadata()` has already resolved on this instance, `metadataViews()`
|
|
46
|
+
* uses that same cached envelope without re-fetching.
|
|
47
|
+
*/
|
|
36
48
|
metadataViews(): Promise<{
|
|
37
49
|
[key: string]: () => View;
|
|
38
50
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taquito/tzip16",
|
|
3
|
-
"version": "25.2.0-
|
|
3
|
+
"version": "25.2.0-beta2",
|
|
4
4
|
"description": "TZIP-16 contract metadata support for Taquito.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"taquito",
|
|
@@ -12,7 +12,11 @@
|
|
|
12
12
|
"module": "dist/taquito-tzip16.es6.js",
|
|
13
13
|
"typings": "dist/types/taquito-tzip16.d.ts",
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist/taquito-tzip16.umd.js",
|
|
16
|
+
"dist/taquito-tzip16.umd.js.map",
|
|
17
|
+
"dist/taquito-tzip16.es6.js",
|
|
18
|
+
"dist/taquito-tzip16.es6.js.map",
|
|
19
|
+
"dist/types"
|
|
16
20
|
],
|
|
17
21
|
"publishConfig": {
|
|
18
22
|
"access": "public"
|
|
@@ -51,33 +55,33 @@
|
|
|
51
55
|
]
|
|
52
56
|
},
|
|
53
57
|
"dependencies": {
|
|
54
|
-
"@taquito/core": "^25.2.0-
|
|
55
|
-
"@taquito/http-utils": "^25.2.0-
|
|
56
|
-
"@taquito/michelson-encoder": "^25.2.0-
|
|
57
|
-
"@taquito/rpc": "^25.2.0-
|
|
58
|
-
"@taquito/taquito": "^25.2.0-
|
|
59
|
-
"@taquito/utils": "^25.2.0-
|
|
58
|
+
"@taquito/core": "^25.2.0-beta2",
|
|
59
|
+
"@taquito/http-utils": "^25.2.0-beta2",
|
|
60
|
+
"@taquito/michelson-encoder": "^25.2.0-beta2",
|
|
61
|
+
"@taquito/rpc": "^25.2.0-beta2",
|
|
62
|
+
"@taquito/taquito": "^25.2.0-beta2",
|
|
63
|
+
"@taquito/utils": "^25.2.0-beta2",
|
|
60
64
|
"bignumber.js": "^10.0.2",
|
|
61
65
|
"crypto-js": "^4.2.0"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
68
|
+
"@rollup/plugin-commonjs": "29.0.3",
|
|
64
69
|
"@rollup/plugin-json": "^6.1.0",
|
|
65
|
-
"@
|
|
70
|
+
"@rollup/plugin-node-resolve": "16.0.3",
|
|
66
71
|
"@types/crypto-js": "^4.2.2",
|
|
67
72
|
"@types/node": "^22.20.5",
|
|
68
|
-
"@types/ws": "^8.18.2",
|
|
69
73
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
70
74
|
"@typescript-eslint/parser": "^6.21.0",
|
|
71
|
-
"cross-env": "^7.0.3",
|
|
72
75
|
"eslint": "^8.57.0",
|
|
76
|
+
"ipfs-unixfs-exporter": "16.2.3",
|
|
73
77
|
"lint-staged": "^15.2.7",
|
|
74
78
|
"lodash.camelcase": "^4.3.0",
|
|
79
|
+
"multiformats": "14.0.5",
|
|
75
80
|
"prettier": "^3.9.10",
|
|
76
81
|
"rimraf": "^6.1.3",
|
|
77
82
|
"rollup": "^4.67.3",
|
|
78
83
|
"rollup-plugin-typescript2": "^0.37.0",
|
|
79
84
|
"ts-node": "^10.9.2",
|
|
80
|
-
"ts-toolbelt": "^9.6.0",
|
|
81
85
|
"typescript": "^6.0.3"
|
|
82
86
|
},
|
|
83
87
|
"gitHead": "551e35aeff7d6dcde1c72284238c0ed3c3aae77e"
|
package/dist/lib/composer.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tzip16 = tzip16;
|
|
4
|
-
const tzip16_contract_abstraction_1 = require("./tzip16-contract-abstraction");
|
|
5
|
-
const ABSTRACTION_KEY = Symbol('Tzip16ContractAbstractionObjectKey');
|
|
6
|
-
function tzip16(abs, context) {
|
|
7
|
-
return Object.assign(abs, {
|
|
8
|
-
// namespace tzip16
|
|
9
|
-
tzip16() {
|
|
10
|
-
if (!this[ABSTRACTION_KEY]) {
|
|
11
|
-
this[ABSTRACTION_KEY] = new tzip16_contract_abstraction_1.Tzip16ContractAbstraction(this, context);
|
|
12
|
-
}
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
14
|
-
return this[ABSTRACTION_KEY];
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
}
|
package/dist/lib/errors.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoParameterExpectedError = exports.ForbiddenInstructionInViewCodeError = exports.UnconfiguredContractMetadataProviderError = exports.InvalidContractMetadataTypeError = exports.ProtocolNotSupportedError = exports.InvalidContractMetadataError = exports.InvalidUriError = exports.UriNotFoundError = exports.ContractMetadataNotFoundError = exports.BigMapContractMetadataNotFoundError = exports.InvalidViewParameterError = void 0;
|
|
4
|
-
const core_1 = require("@taquito/core");
|
|
5
|
-
var core_2 = require("@taquito/core");
|
|
6
|
-
Object.defineProperty(exports, "InvalidViewParameterError", { enumerable: true, get: function () { return core_2.InvalidViewParameterError; } });
|
|
7
|
-
/**
|
|
8
|
-
* @category Error
|
|
9
|
-
* Error that indicates missing big map metadata (non compliance to the TZIP-16 standard)
|
|
10
|
-
*/
|
|
11
|
-
class BigMapContractMetadataNotFoundError extends core_1.TaquitoError {
|
|
12
|
-
constructor(invalidBigMapId) {
|
|
13
|
-
super();
|
|
14
|
-
this.invalidBigMapId = invalidBigMapId;
|
|
15
|
-
this.name = 'BigMapContractMetadataNotFoundError';
|
|
16
|
-
this.message =
|
|
17
|
-
'Non-compliance with the TZIP-016 standard. No big map named metadata was found in the contract storage.';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.BigMapContractMetadataNotFoundError = BigMapContractMetadataNotFoundError;
|
|
21
|
-
/**
|
|
22
|
-
* @category Error
|
|
23
|
-
* Error that indicates missing metadata in storage
|
|
24
|
-
*/
|
|
25
|
-
class ContractMetadataNotFoundError extends core_1.TaquitoError {
|
|
26
|
-
constructor(info) {
|
|
27
|
-
super();
|
|
28
|
-
this.info = info;
|
|
29
|
-
this.name = 'ContractMetadataNotFoundError';
|
|
30
|
-
this.message = `No metadata was found in the contract storage. ${info}`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.ContractMetadataNotFoundError = ContractMetadataNotFoundError;
|
|
34
|
-
/**
|
|
35
|
-
* @category Error
|
|
36
|
-
* Error that indicates missing URI (non compliance to the TZIP-16 standard)
|
|
37
|
-
*/
|
|
38
|
-
class UriNotFoundError extends core_1.TaquitoError {
|
|
39
|
-
constructor() {
|
|
40
|
-
super();
|
|
41
|
-
this.name = 'UriNotFoundError';
|
|
42
|
-
this.message =
|
|
43
|
-
'Non-compliance with the TZIP-016 standard. No URI found in the contract storage.';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.UriNotFoundError = UriNotFoundError;
|
|
47
|
-
/**
|
|
48
|
-
* @category Error
|
|
49
|
-
* Error that indicates an invalid URI (non compliance to the TZIP-16 standard)
|
|
50
|
-
*/
|
|
51
|
-
class InvalidUriError extends core_1.TaquitoError {
|
|
52
|
-
constructor(uri) {
|
|
53
|
-
super();
|
|
54
|
-
this.uri = uri;
|
|
55
|
-
this.name = 'InvalidUriError';
|
|
56
|
-
this.message = `Non-compliance with the TZIP-016 standard. The URI is invalid: ${uri}.`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.InvalidUriError = InvalidUriError;
|
|
60
|
-
/**
|
|
61
|
-
* @category Error
|
|
62
|
-
* Error that indicates invalid metadata (non compliance to the TZIP-16 standard)
|
|
63
|
-
*/
|
|
64
|
-
class InvalidContractMetadataError extends core_1.TaquitoError {
|
|
65
|
-
constructor(invalidMetadata) {
|
|
66
|
-
super();
|
|
67
|
-
this.invalidMetadata = invalidMetadata;
|
|
68
|
-
this.name = 'InvalidContractMetadataError';
|
|
69
|
-
this.message = `The metadata found at the pointed ressource are not compliant with tzip16 standard: ${invalidMetadata}.`;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.InvalidContractMetadataError = InvalidContractMetadataError;
|
|
73
|
-
/**
|
|
74
|
-
* @category Error
|
|
75
|
-
* Error that indicates the uri protocol being passed or used is not supported
|
|
76
|
-
*/
|
|
77
|
-
class ProtocolNotSupportedError extends core_1.ParameterValidationError {
|
|
78
|
-
constructor(protocol) {
|
|
79
|
-
super();
|
|
80
|
-
this.protocol = protocol;
|
|
81
|
-
this.name = 'ProtocolNotSupportedError';
|
|
82
|
-
this.message = `The protocol found in the URI is not supported: ${protocol}.`;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.ProtocolNotSupportedError = ProtocolNotSupportedError;
|
|
86
|
-
/**
|
|
87
|
-
* @category Error
|
|
88
|
-
* Error that indicates the metadata type is invalid (non compliance to the TZIP-16 standard)
|
|
89
|
-
*/
|
|
90
|
-
class InvalidContractMetadataTypeError extends core_1.TaquitoError {
|
|
91
|
-
constructor() {
|
|
92
|
-
super();
|
|
93
|
-
this.name = 'InvalidContractMetadataTypeError';
|
|
94
|
-
this.message =
|
|
95
|
-
'Non-compliance with the TZIP-016 standard. The type of metadata should be bytes.';
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.InvalidContractMetadataTypeError = InvalidContractMetadataTypeError;
|
|
99
|
-
/**
|
|
100
|
-
* @category Error
|
|
101
|
-
* Error that indicates metadata provider being unconfigured in the TezosToolkit instance
|
|
102
|
-
*/
|
|
103
|
-
class UnconfiguredContractMetadataProviderError extends core_1.TezosToolkitConfigError {
|
|
104
|
-
constructor() {
|
|
105
|
-
super();
|
|
106
|
-
this.name = 'UnconfiguredContractMetadataProviderError';
|
|
107
|
-
this.message =
|
|
108
|
-
'No metadata provider has been configured. The default one can be configured by calling addExtension(new Tzip16Module()) on your TezosToolkit instance.';
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.UnconfiguredContractMetadataProviderError = UnconfiguredContractMetadataProviderError;
|
|
112
|
-
/**
|
|
113
|
-
* @category Error
|
|
114
|
-
* Error that indicates a forbidden instruction being found inside the View code
|
|
115
|
-
*/
|
|
116
|
-
class ForbiddenInstructionInViewCodeError extends core_1.TaquitoError {
|
|
117
|
-
constructor(instruction) {
|
|
118
|
-
super();
|
|
119
|
-
this.instruction = instruction;
|
|
120
|
-
this.name = 'ForbiddenInstructionInViewCodeError';
|
|
121
|
-
this.message = `Error found in the code of the view. It contains a forbidden instruction: ${instruction}.`;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.ForbiddenInstructionInViewCodeError = ForbiddenInstructionInViewCodeError;
|
|
125
|
-
/**
|
|
126
|
-
* @category Error
|
|
127
|
-
* Error that indicates parameters are being passed when it is not required
|
|
128
|
-
*/
|
|
129
|
-
class NoParameterExpectedError extends core_1.ParameterValidationError {
|
|
130
|
-
constructor(viewName, args) {
|
|
131
|
-
super();
|
|
132
|
-
this.viewName = viewName;
|
|
133
|
-
this.args = args;
|
|
134
|
-
this.name = 'NoParameterExpectedError';
|
|
135
|
-
this.message = `${viewName} Received ${args.length} arguments while expecting no parameter or 'Unit'`;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.NoParameterExpectedError = NoParameterExpectedError;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpHandler = void 0;
|
|
4
|
-
const http_utils_1 = require("@taquito/http-utils");
|
|
5
|
-
class HttpHandler {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.httpBackend = new http_utils_1.HttpBackend();
|
|
8
|
-
}
|
|
9
|
-
async getMetadata(_contractAbstraction, { protocol, location }, _context) {
|
|
10
|
-
return this.httpBackend.createRequest({
|
|
11
|
-
url: `${protocol}:${decodeURIComponent(location)}`,
|
|
12
|
-
method: 'GET',
|
|
13
|
-
headers: {
|
|
14
|
-
'Content-Type': 'text/plain; charset=utf-8'
|
|
15
|
-
},
|
|
16
|
-
json: false
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.HttpHandler = HttpHandler;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IpfsHttpHandler = void 0;
|
|
4
|
-
const http_utils_1 = require("@taquito/http-utils");
|
|
5
|
-
class IpfsHttpHandler {
|
|
6
|
-
constructor(ipfsGateway) {
|
|
7
|
-
this.httpBackend = new http_utils_1.HttpBackend();
|
|
8
|
-
this._ipfsGateway = ipfsGateway ? ipfsGateway : 'ipfs.filebase.io';
|
|
9
|
-
}
|
|
10
|
-
async getMetadata(_contractAbstraction, { location }, _context) {
|
|
11
|
-
const url = `https://${this._ipfsGateway}/ipfs/${location.substring(2)}/`;
|
|
12
|
-
try {
|
|
13
|
-
return await this.httpBackend.createRequest({
|
|
14
|
-
url,
|
|
15
|
-
method: 'GET',
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'text/plain; charset=utf-8',
|
|
18
|
-
},
|
|
19
|
-
json: false,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
const guidance = `IPFS metadata retrieval failed at ${url}. Check gateway availability and that the content is retrievable. ` +
|
|
24
|
-
`Configure a reliable gateway with IpfsHttpHandler('your-gateway-hostname').`;
|
|
25
|
-
if (error instanceof http_utils_1.HttpResponseError) {
|
|
26
|
-
throw new http_utils_1.HttpResponseError(`${guidance} ${error.message}`, error.status, error.statusText, error.body, error.url);
|
|
27
|
-
}
|
|
28
|
-
if (error instanceof http_utils_1.HttpRequestFailed || error instanceof http_utils_1.HttpTimeoutError) {
|
|
29
|
-
error.message = `${guidance} ${error.message}`;
|
|
30
|
-
}
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.IpfsHttpHandler = IpfsHttpHandler;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TezosStorageHandler = void 0;
|
|
4
|
-
const michelson_encoder_1 = require("@taquito/michelson-encoder");
|
|
5
|
-
const utils_1 = require("@taquito/utils");
|
|
6
|
-
const errors_1 = require("../errors");
|
|
7
|
-
const typeOfValueToFind = {
|
|
8
|
-
prim: 'big_map',
|
|
9
|
-
args: [{ prim: 'string' }, { prim: 'bytes' }],
|
|
10
|
-
annots: ['%metadata'],
|
|
11
|
-
};
|
|
12
|
-
class TezosStorageHandler {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w|%]+)$/;
|
|
15
|
-
}
|
|
16
|
-
async getMetadata(contractAbstraction, { location }, context) {
|
|
17
|
-
const parsedTezosStorageUri = this.parseTezosStorageUri(location);
|
|
18
|
-
if (!parsedTezosStorageUri) {
|
|
19
|
-
throw new errors_1.InvalidUriError(`tezos-storage:${location}`);
|
|
20
|
-
}
|
|
21
|
-
const block = contractAbstraction.readBlock;
|
|
22
|
-
const targetAddress = parsedTezosStorageUri.contractAddress || contractAbstraction.address;
|
|
23
|
-
const script = !parsedTezosStorageUri.contractAddress && block !== 'head'
|
|
24
|
-
? contractAbstraction.script
|
|
25
|
-
: await context.readProvider.getScript(targetAddress, block);
|
|
26
|
-
const bigMapId = michelson_encoder_1.Schema.fromRPCResponse({ script }).FindFirstInTopLevelPair(script.storage, typeOfValueToFind);
|
|
27
|
-
if (!bigMapId || !bigMapId.int) {
|
|
28
|
-
throw new errors_1.BigMapContractMetadataNotFoundError(bigMapId);
|
|
29
|
-
}
|
|
30
|
-
const bytes = await context.contract.getBigMapKeyByID(bigMapId.int.toString(), parsedTezosStorageUri.path, new michelson_encoder_1.Schema(typeOfValueToFind), block);
|
|
31
|
-
if (!bytes) {
|
|
32
|
-
throw new errors_1.ContractMetadataNotFoundError(`No '${parsedTezosStorageUri.path}' key found in the big map %metadata of the contract ${parsedTezosStorageUri.contractAddress || contractAbstraction.address}`);
|
|
33
|
-
}
|
|
34
|
-
if (!/^[0-9a-fA-F]*$/.test(bytes)) {
|
|
35
|
-
throw new errors_1.InvalidContractMetadataTypeError();
|
|
36
|
-
}
|
|
37
|
-
return (0, utils_1.bytesToString)(bytes);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Extract the smart contract address, the network and the path pointing to the metadata from the uri
|
|
41
|
-
* @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
|
|
42
|
-
* @param tezosStorageURI URI (without the tezos-storage prefix)
|
|
43
|
-
*/
|
|
44
|
-
parseTezosStorageUri(tezosStorageURI) {
|
|
45
|
-
const extractor = this.TEZOS_STORAGE_REGEX.exec(tezosStorageURI);
|
|
46
|
-
if (!extractor)
|
|
47
|
-
return;
|
|
48
|
-
return {
|
|
49
|
-
contractAddress: extractor[1],
|
|
50
|
-
network: extractor[2],
|
|
51
|
-
path: decodeURIComponent(extractor[3]),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.TezosStorageHandler = TezosStorageHandler;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ViewImplementationType = void 0;
|
|
4
|
-
var ViewImplementationType;
|
|
5
|
-
(function (ViewImplementationType) {
|
|
6
|
-
ViewImplementationType["MICHELSON_STORAGE"] = "michelsonStorageView";
|
|
7
|
-
ViewImplementationType["REST_API_QUERY"] = "restApiQuery";
|
|
8
|
-
})(ViewImplementationType || (exports.ViewImplementationType = ViewImplementationType = {}));
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetadataProvider = void 0;
|
|
4
|
-
const errors_1 = require("./errors");
|
|
5
|
-
const tzip16_utils_1 = require("./tzip16-utils");
|
|
6
|
-
const SHA256_PREFIX = 'sha256://0x';
|
|
7
|
-
const SUPPORTED_PROTOCOLS = new Set(['http', 'https', 'ipfs', 'tezos-storage']);
|
|
8
|
-
/**
|
|
9
|
-
\* Metadata Provider
|
|
10
|
-
*/
|
|
11
|
-
class MetadataProvider {
|
|
12
|
-
constructor(handlers) {
|
|
13
|
-
this.handlers = handlers;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Fetch the metadata by using the appropriate handler based on the protcol found in the URI
|
|
17
|
-
* @returns an object which contains the uri, the metadata, an optional integrity check result and an optional SHA256 hash
|
|
18
|
-
* @param contractAbstraction the contract abstraction which contains the URI in its storage
|
|
19
|
-
* @param uri the decoded uri found in the storage
|
|
20
|
-
* @param context the TezosToolkit Context
|
|
21
|
-
*/
|
|
22
|
-
async provideMetadata(contractAbstraction, uri, context) {
|
|
23
|
-
const uriInfo = this.extractProtocolInfo(uri);
|
|
24
|
-
if (!uriInfo || !uriInfo.location) {
|
|
25
|
-
throw new errors_1.InvalidUriError(uri);
|
|
26
|
-
}
|
|
27
|
-
const handler = this.handlers.get(uriInfo.protocol);
|
|
28
|
-
if (!handler) {
|
|
29
|
-
throw new errors_1.ProtocolNotSupportedError(uriInfo.protocol);
|
|
30
|
-
}
|
|
31
|
-
const metadata = await handler.getMetadata(contractAbstraction, uriInfo, context);
|
|
32
|
-
const sha256Hash = (0, tzip16_utils_1.calculateSHA256Hash)(metadata);
|
|
33
|
-
let metadataJSON;
|
|
34
|
-
try {
|
|
35
|
-
metadataJSON = JSON.parse(metadata);
|
|
36
|
-
}
|
|
37
|
-
catch (ex) {
|
|
38
|
-
const error = new errors_1.InvalidContractMetadataError(metadata);
|
|
39
|
-
error.message = `Unable to parse metadata from ${uri} as JSON.`;
|
|
40
|
-
if (uriInfo.protocol === 'ipfs') {
|
|
41
|
-
error.message +=
|
|
42
|
-
' The IPFS gateway may have returned an HTML error or service-worker page.' +
|
|
43
|
-
" Configure a reliable gateway with IpfsHttpHandler('your-gateway-hostname').";
|
|
44
|
-
}
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
uri,
|
|
49
|
-
metadata: metadataJSON,
|
|
50
|
-
integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
|
|
51
|
-
sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
extractProtocolInfo(_uri) {
|
|
55
|
-
let uri = _uri;
|
|
56
|
-
let sha256hash;
|
|
57
|
-
if (uri.startsWith(SHA256_PREFIX)) {
|
|
58
|
-
const sha256EndIndex = uri.indexOf('/', SHA256_PREFIX.length);
|
|
59
|
-
if (sha256EndIndex === -1) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
sha256hash = uri.slice(SHA256_PREFIX.length, sha256EndIndex);
|
|
63
|
-
uri = uri.slice(sha256EndIndex + 1);
|
|
64
|
-
}
|
|
65
|
-
const protocolSeparatorIndex = uri.indexOf(':');
|
|
66
|
-
if (protocolSeparatorIndex === -1) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const protocol = uri.slice(0, protocolSeparatorIndex);
|
|
70
|
-
if (!SUPPORTED_PROTOCOLS.has(protocol)) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
sha256hash,
|
|
75
|
-
protocol,
|
|
76
|
-
location: uri.slice(protocolSeparatorIndex + 1),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.MetadataProvider = MetadataProvider;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.VERSION = void 0;
|
|
18
|
-
/**
|
|
19
|
-
* @packageDocumentation
|
|
20
|
-
* @module @taquito/tzip16
|
|
21
|
-
*/
|
|
22
|
-
__exportStar(require("./handlers/http-handler"), exports);
|
|
23
|
-
__exportStar(require("./handlers/tezos-storage-handler"), exports);
|
|
24
|
-
__exportStar(require("./handlers/ipfs-handler"), exports);
|
|
25
|
-
__exportStar(require("./composer"), exports);
|
|
26
|
-
__exportStar(require("./metadata-interface"), exports);
|
|
27
|
-
__exportStar(require("./metadata-provider"), exports);
|
|
28
|
-
__exportStar(require("./tzip16-contract-abstraction"), exports);
|
|
29
|
-
__exportStar(require("./errors"), exports);
|
|
30
|
-
__exportStar(require("./tzip16-extension"), exports);
|
|
31
|
-
__exportStar(require("./tzip16-utils"), exports);
|
|
32
|
-
__exportStar(require("./viewKind/interface"), exports);
|
|
33
|
-
__exportStar(require("./viewKind/michelson-storage-view"), exports);
|
|
34
|
-
__exportStar(require("./viewKind/viewFactory"), exports);
|
|
35
|
-
var version_1 = require("./version");
|
|
36
|
-
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
|