@taquito/tzip16 25.1.1 → 25.2.0-beta1
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 +18054 -139
- package/dist/taquito-tzip16.es6.js.map +1 -1
- package/dist/taquito-tzip16.umd.js +18047 -130
- 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 +16 -3
- package/dist/types/handlers/ipfs-metadata.d.ts +8 -0
- package/package.json +20 -20
- 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 -137
- package/dist/lib/tzip16-extension.js +0 -22
- package/dist/lib/tzip16-utils.js +0 -7
- 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,22 @@
|
|
|
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;
|
|
6
15
|
httpBackend: HttpBackend;
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @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.
|
|
18
|
+
* @param timeout - Total deadline in milliseconds for each gateway, including all block and body reads (default `10000`).
|
|
19
|
+
*/
|
|
20
|
+
constructor(ipfsGateway?: string, timeout?: number);
|
|
21
|
+
getMetadata(_contractAbstraction: ContractAbstraction<ContractProvider | Wallet>, { location, sha256hash }: Tzip16Uri, _context: Context): Promise<string>;
|
|
9
22
|
}
|
|
@@ -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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taquito/tzip16",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.2.0-beta1",
|
|
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,38 +55,34 @@
|
|
|
51
55
|
]
|
|
52
56
|
},
|
|
53
57
|
"dependencies": {
|
|
54
|
-
"@taquito/core": "^25.
|
|
55
|
-
"@taquito/http-utils": "^25.
|
|
56
|
-
"@taquito/michelson-encoder": "^25.
|
|
57
|
-
"@taquito/rpc": "^25.
|
|
58
|
-
"@taquito/taquito": "^25.
|
|
59
|
-
"@taquito/utils": "^25.
|
|
58
|
+
"@taquito/core": "^25.2.0-beta1",
|
|
59
|
+
"@taquito/http-utils": "^25.2.0-beta1",
|
|
60
|
+
"@taquito/michelson-encoder": "^25.2.0-beta1",
|
|
61
|
+
"@taquito/rpc": "^25.2.0-beta1",
|
|
62
|
+
"@taquito/taquito": "^25.2.0-beta1",
|
|
63
|
+
"@taquito/utils": "^25.2.0-beta1",
|
|
60
64
|
"bignumber.js": "^10.0.2",
|
|
61
65
|
"crypto-js": "^4.2.0"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
64
|
-
"@
|
|
68
|
+
"@rollup/plugin-commonjs": "29.0.3",
|
|
69
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
70
|
+
"@rollup/plugin-node-resolve": "16.0.3",
|
|
65
71
|
"@types/crypto-js": "^4.2.2",
|
|
66
72
|
"@types/node": "^22.20.5",
|
|
67
|
-
"@types/ws": "^8.5.12",
|
|
68
73
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
69
74
|
"@typescript-eslint/parser": "^6.21.0",
|
|
70
|
-
"colors": "^1.4.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
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"rimraf": "^6.0.1",
|
|
79
|
-
"rollup": "^4.64.7",
|
|
80
|
-
"rollup-plugin-json": "^4.0.0",
|
|
81
|
+
"rimraf": "^6.1.3",
|
|
82
|
+
"rollup": "^4.67.3",
|
|
81
83
|
"rollup-plugin-typescript2": "^0.37.0",
|
|
82
|
-
"shelljs": "^0.8.5",
|
|
83
84
|
"ts-node": "^10.9.2",
|
|
84
|
-
"
|
|
85
|
-
"typescript": "^5.9.3"
|
|
85
|
+
"typescript": "^6.0.3"
|
|
86
86
|
},
|
|
87
87
|
"gitHead": "551e35aeff7d6dcde1c72284238c0ed3c3aae77e"
|
|
88
88
|
}
|
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; } });
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Tzip16ContractAbstraction = void 0;
|
|
4
|
-
const taquito_1 = require("@taquito/taquito");
|
|
5
|
-
const utils_1 = require("@taquito/utils");
|
|
6
|
-
const errors_1 = require("./errors");
|
|
7
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
8
|
-
const michelson_encoder_1 = require("@taquito/michelson-encoder");
|
|
9
|
-
const viewFactory_1 = require("./viewKind/viewFactory");
|
|
10
|
-
const metadataBigMapType = {
|
|
11
|
-
prim: 'big_map',
|
|
12
|
-
args: [{ prim: 'string' }, { prim: 'bytes' }],
|
|
13
|
-
annots: ['%metadata'],
|
|
14
|
-
};
|
|
15
|
-
class Tzip16ContractAbstraction {
|
|
16
|
-
constructor(constractAbstraction, context) {
|
|
17
|
-
this.constractAbstraction = constractAbstraction;
|
|
18
|
-
this.context = context;
|
|
19
|
-
this._viewFactory = new viewFactory_1.ViewFactory();
|
|
20
|
-
this._metadataViewsObject = {};
|
|
21
|
-
this._metadataProvider = context.metadataProvider;
|
|
22
|
-
}
|
|
23
|
-
async findMetadataBigMap() {
|
|
24
|
-
const metadataBigMapId = this.constractAbstraction.schema.FindFirstInTopLevelPair(this.constractAbstraction.readBlock === 'head'
|
|
25
|
-
? await this.context.readProvider.getStorage(this.constractAbstraction.address, 'head')
|
|
26
|
-
: this.constractAbstraction.script.storage, metadataBigMapType);
|
|
27
|
-
if (!metadataBigMapId || !metadataBigMapId.int) {
|
|
28
|
-
throw new errors_1.BigMapContractMetadataNotFoundError(metadataBigMapId);
|
|
29
|
-
}
|
|
30
|
-
return new taquito_1.BigMapAbstraction(new bignumber_js_1.default(metadataBigMapId['int']), new michelson_encoder_1.Schema(metadataBigMapType), this.context.contract, this.constractAbstraction.readBlock);
|
|
31
|
-
}
|
|
32
|
-
async getUriOrFail() {
|
|
33
|
-
const metadataBigMap = await this.findMetadataBigMap();
|
|
34
|
-
const uri = await metadataBigMap.get('');
|
|
35
|
-
if (!uri) {
|
|
36
|
-
throw new errors_1.UriNotFoundError();
|
|
37
|
-
}
|
|
38
|
-
return uri;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Return an object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
|
|
42
|
-
*/
|
|
43
|
-
async getMetadata() {
|
|
44
|
-
if (!this._metadataProvider) {
|
|
45
|
-
throw new errors_1.UnconfiguredContractMetadataProviderError();
|
|
46
|
-
}
|
|
47
|
-
if (!this._metadataEnvelope) {
|
|
48
|
-
const uri = await this.getUriOrFail();
|
|
49
|
-
this._metadataEnvelope = await this._metadataProvider.provideMetadata(this.constractAbstraction, (0, utils_1.bytesToString)(uri), this.context);
|
|
50
|
-
}
|
|
51
|
-
return this._metadataEnvelope;
|
|
52
|
-
}
|
|
53
|
-
async metadataName() {
|
|
54
|
-
if (!this._metadataEnvelope) {
|
|
55
|
-
await this.getMetadata();
|
|
56
|
-
}
|
|
57
|
-
return this._metadataEnvelope.metadata.name;
|
|
58
|
-
}
|
|
59
|
-
async metadataDescription() {
|
|
60
|
-
if (!this._metadataEnvelope)
|
|
61
|
-
await this.getMetadata();
|
|
62
|
-
return this._metadataEnvelope.metadata.description;
|
|
63
|
-
}
|
|
64
|
-
async metadataVersion() {
|
|
65
|
-
if (!this._metadataEnvelope)
|
|
66
|
-
await this.getMetadata();
|
|
67
|
-
return this._metadataEnvelope.metadata.version;
|
|
68
|
-
}
|
|
69
|
-
async metadataLicense() {
|
|
70
|
-
if (!this._metadataEnvelope)
|
|
71
|
-
await this.getMetadata();
|
|
72
|
-
return this._metadataEnvelope.metadata.license;
|
|
73
|
-
}
|
|
74
|
-
async metadataAuthors() {
|
|
75
|
-
if (!this._metadataEnvelope)
|
|
76
|
-
await this.getMetadata();
|
|
77
|
-
return this._metadataEnvelope.metadata.authors;
|
|
78
|
-
}
|
|
79
|
-
async metadataHomepage() {
|
|
80
|
-
if (!this._metadataEnvelope)
|
|
81
|
-
await this.getMetadata();
|
|
82
|
-
return this._metadataEnvelope.metadata.homepage;
|
|
83
|
-
}
|
|
84
|
-
async metadataSource() {
|
|
85
|
-
if (!this._metadataEnvelope)
|
|
86
|
-
await this.getMetadata();
|
|
87
|
-
return this._metadataEnvelope.metadata.source;
|
|
88
|
-
}
|
|
89
|
-
async metadataInterfaces() {
|
|
90
|
-
if (!this._metadataEnvelope)
|
|
91
|
-
await this.getMetadata();
|
|
92
|
-
return this._metadataEnvelope.metadata.interfaces;
|
|
93
|
-
}
|
|
94
|
-
async metadataErrors() {
|
|
95
|
-
if (!this._metadataEnvelope)
|
|
96
|
-
await this.getMetadata();
|
|
97
|
-
return this._metadataEnvelope.metadata.errors;
|
|
98
|
-
}
|
|
99
|
-
async metadataViews() {
|
|
100
|
-
if (Object.keys(this._metadataViewsObject).length === 0) {
|
|
101
|
-
await this.initializeMetadataViewsList();
|
|
102
|
-
}
|
|
103
|
-
return this._metadataViewsObject;
|
|
104
|
-
}
|
|
105
|
-
async initializeMetadataViewsList() {
|
|
106
|
-
const { metadata } = await this.getMetadata();
|
|
107
|
-
const metadataViews = {};
|
|
108
|
-
metadata.views?.forEach((view) => this.createViewImplementations(view, metadataViews));
|
|
109
|
-
this._metadataViewsObject = metadataViews;
|
|
110
|
-
}
|
|
111
|
-
generateIndexedViewName(viewName, metadataViews) {
|
|
112
|
-
let i = 1;
|
|
113
|
-
if (viewName in metadataViews) {
|
|
114
|
-
while (`${viewName}${i}` in metadataViews) {
|
|
115
|
-
i++;
|
|
116
|
-
}
|
|
117
|
-
viewName = `${viewName}${i}`;
|
|
118
|
-
}
|
|
119
|
-
return viewName;
|
|
120
|
-
}
|
|
121
|
-
createViewImplementations(view, metadataViews) {
|
|
122
|
-
for (const viewImplementation of view?.implementations ?? []) {
|
|
123
|
-
if (view.name) {
|
|
124
|
-
// when views have the same name, add an index at the end of the name
|
|
125
|
-
const viewName = this.generateIndexedViewName(view.name, metadataViews);
|
|
126
|
-
const metadataView = this._viewFactory.getView(viewName, this.context.rpc, this.context.readProvider, this.constractAbstraction, viewImplementation);
|
|
127
|
-
if (metadataView) {
|
|
128
|
-
metadataViews[viewName] = metadataView;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
console.warn(`Skipped generating ${viewName} because the view has an unsupported type: ${this._viewFactory.getImplementationType(viewImplementation)}`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.Tzip16ContractAbstraction = Tzip16ContractAbstraction;
|