@taquito/tzip16 11.0.2 → 11.2.0-beta-RC.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.
- package/README.md +31 -18
- package/dist/lib/composer.js +5 -4
- package/dist/lib/composer.js.map +1 -1
- package/dist/lib/handlers/http-handler.js +12 -43
- package/dist/lib/handlers/http-handler.js.map +1 -1
- package/dist/lib/handlers/ipfs-handler.js +13 -44
- package/dist/lib/handlers/ipfs-handler.js.map +1 -1
- package/dist/lib/handlers/tezos-storage-handler.js +31 -70
- package/dist/lib/handlers/tezos-storage-handler.js.map +1 -1
- package/dist/lib/metadata-provider.js +36 -71
- package/dist/lib/metadata-provider.js.map +1 -1
- package/dist/lib/tzip16-contract-abstraction.js +66 -151
- package/dist/lib/tzip16-contract-abstraction.js.map +1 -1
- package/dist/lib/tzip16-errors.js +44 -55
- package/dist/lib/tzip16-errors.js.map +1 -1
- package/dist/lib/tzip16-extension.js +9 -10
- package/dist/lib/tzip16-extension.js.map +1 -1
- package/dist/lib/tzip16-utils.js +1 -1
- package/dist/lib/tzip16-utils.js.map +1 -1
- package/dist/lib/version.js +2 -4
- package/dist/lib/version.js.map +1 -1
- package/dist/lib/viewKind/michelson-storage-view.js +98 -197
- package/dist/lib/viewKind/michelson-storage-view.js.map +1 -1
- package/dist/lib/viewKind/viewFactory.js +15 -18
- package/dist/lib/viewKind/viewFactory.js.map +1 -1
- package/dist/taquito-tzip16.es6.js +564 -0
- package/dist/taquito-tzip16.es6.js.map +1 -0
- package/dist/taquito-tzip16.umd.js +317 -518
- package/dist/taquito-tzip16.umd.js.map +1 -1
- package/dist/types/composer.d.ts +1 -1
- package/dist/types/tzip16-errors.d.ts +15 -22
- package/package.json +27 -27
- package/dist/taquito-tzip16.es5.js +0 -761
- package/dist/taquito-tzip16.es5.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,39 +1,54 @@
|
|
|
1
|
-
# Taquito
|
|
1
|
+
# Taquito TZIP-016 package
|
|
2
|
+
*Documentation can be found [here](https://tezostaquito.io/docs/metadata-tzip16/)*
|
|
3
|
+
*TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_tzip16.html)*
|
|
2
4
|
|
|
3
|
-
`@taquito/tzip16` is an npm package that provides developers with
|
|
5
|
+
`@taquito/tzip16` is an npm package that provides developers with TZIP-016 functionality for Taquito. TZIP-016 is a standard for encoding access to smart contract metadata either on-chain or off-chain. The `@taquito/tzip16` package allows developers to retrieve the metadata associated with a smart contract and execute the off-chain views found in the metadata.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## General Information
|
|
6
8
|
|
|
7
|
-
The
|
|
9
|
+
Contract metadata gathers valuable information about the contract that is not directly used for its operation. According to TZIP-016, a contract with metadata must include in its storage a big_map named `%metadata` of the following type: `(big_map %metadata string bytes)`. The big_map must have an empty string as a key where its value is a byte-encoded URI representing the metadata location. Contract metadata can be located on-chain or off-chain (web services or IPFS). Please refer to the following link for complete documentation on [TZIP-016](https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-16/tzip-16.md#introduction).
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
When using the `@taquito/tzip16` package, developers can retrieve metadata of a contract based on its address. The underlying steps performed by Taquito are to find the URI in the contract storage, decode it, extract the metadata depending on the protocol (tezos-storage, HTTP(S) or IPFS), perform an integrity check if the URI contains a sha256 hash, and return the metadata to the user.
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
Another functionality of the `@taquito/tzip16` package allows executing off-chain views. If a contract contains views in its metadata, Taquito builds an ordinary JavaScript object with methods corresponding to the views name.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
The package can be used to extend the well-known Taquito contract abstraction. The `@taquito/tzip16` and the `@taquito/taquito` packages need to be installed as follows:
|
|
18
|
+
```
|
|
19
|
+
npm i --save @taquito/tzip16
|
|
20
|
+
npm i --save @taquito/taquito
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
**Create an instance of the `Tzip16Module` and add it as an extension to the `TezosToolkit`**
|
|
26
|
+
|
|
27
|
+
The constructor of the `Tzip16Module` takes an optional `MetadataProvider` as a parameter. When none is passed, the default `MetadataProvider` of Taquito is instantiated, and the default handlers (`HttpHandler`, `IpfsHandler`, and `TezosStorageHandler`) are used.
|
|
28
|
+
The `MetadataProvider` can be customized by the user if needed.
|
|
29
|
+
|
|
30
|
+
**Use the `tzip16` function to extend a contract abstraction**
|
|
12
31
|
|
|
13
32
|
```js
|
|
14
33
|
import { TezosToolkit } from '@taquito/taquito';
|
|
15
34
|
import { Tzip16Module } from '@taquito/tzip16';
|
|
35
|
+
import { tzip16 } from '@taquito/tzip16';
|
|
16
36
|
|
|
17
37
|
const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL');
|
|
18
38
|
Tezos.addExtension(new Tzip16Module());
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
2. **Use the `tzip16` function to extend a contract abstraction**
|
|
22
39
|
|
|
23
|
-
```js
|
|
24
|
-
import { tzip16 } from '@taquito/tzip16';
|
|
25
40
|
const contract = await Tezos.contract.at("contractAddress", tzip16)
|
|
26
41
|
```
|
|
27
42
|
|
|
28
|
-
|
|
43
|
+
### Get the contract metadata
|
|
29
44
|
|
|
30
45
|
```ts
|
|
31
46
|
const metadata = await contract.tzip16().getMetadata();
|
|
32
47
|
```
|
|
33
48
|
|
|
34
|
-
The `getMetadata` method returns an object which contains the URI, the metadata in JSON format, an optional SHA256 hash of the metadata and an optional integrity check result.
|
|
49
|
+
The `getMetadata` method returns an object which contains the URI, the metadata in JSON format, an optional SHA256 hash of the metadata, and an optional integrity check result.
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
### Execute off-chain views
|
|
37
52
|
|
|
38
53
|
```ts
|
|
39
54
|
// Initialize off-chain views
|
|
@@ -41,11 +56,9 @@ const metadataViews = await contractAbstraction.tzip16().metadataViews();
|
|
|
41
56
|
const viewResult = await metadataViews.nameOfTheView().executeView(paramOfTheView);
|
|
42
57
|
```
|
|
43
58
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## API Documentation
|
|
59
|
+
## Additional info
|
|
47
60
|
|
|
48
|
-
|
|
61
|
+
See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing, and versioning.
|
|
49
62
|
|
|
50
63
|
## Disclaimer
|
|
51
64
|
|
package/dist/lib/composer.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tzip16 = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const tzip16_contract_abstraction_1 = require("./tzip16-contract-abstraction");
|
|
5
|
+
const ABSTRACTION_KEY = Symbol('Tzip16ContractAbstractionObjectKey');
|
|
6
6
|
function tzip16(abs, context) {
|
|
7
7
|
return Object.assign(abs, {
|
|
8
8
|
// namespace tzip16
|
|
9
|
-
tzip16
|
|
9
|
+
tzip16() {
|
|
10
10
|
if (!this[ABSTRACTION_KEY]) {
|
|
11
11
|
this[ABSTRACTION_KEY] = new tzip16_contract_abstraction_1.Tzip16ContractAbstraction(this, context);
|
|
12
12
|
}
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
13
14
|
return this[ABSTRACTION_KEY];
|
|
14
|
-
}
|
|
15
|
+
},
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
exports.tzip16 = tzip16;
|
package/dist/lib/composer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composer.js","sourceRoot":"","sources":["../../src/composer.ts"],"names":[],"mappings":";;;AACA
|
|
1
|
+
{"version":3,"file":"composer.js","sourceRoot":"","sources":["../../src/composer.ts"],"names":[],"mappings":";;;AACA,+EAA2F;AAE3F,MAAM,eAAe,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAErE,SAAgB,MAAM,CACpB,GAAM,EACN,OAAgB;IAEhB,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;QACxB,mBAAmB;QACnB,MAAM;YAKJ,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;gBAC1B,IAAI,CAAC,eAAe,CAAC,GAAG,IAAI,uDAAyB,CAAC,IAAI,EAAE,OAA0B,CAAC,CAAC;aACzF;YAED,oEAAoE;YACpE,OAAO,IAAI,CAAC,eAAe,CAAE,CAAC;QAChC,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAnBD,wBAmBC"}
|
|
@@ -8,54 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.HttpHandler = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
13
|
+
const http_utils_1 = require("@taquito/http-utils");
|
|
14
|
+
class HttpHandler {
|
|
15
|
+
constructor() {
|
|
43
16
|
this.httpBackend = new http_utils_1.HttpBackend();
|
|
44
17
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
mimeType: "text; charset=utf-8",
|
|
53
|
-
json: false
|
|
54
|
-
})];
|
|
18
|
+
getMetadata(_contractAbstraction, { protocol, location }, _context) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return this.httpBackend.createRequest({
|
|
21
|
+
url: `${protocol}:${decodeURIComponent(location)}`,
|
|
22
|
+
method: 'GET',
|
|
23
|
+
mimeType: "text; charset=utf-8",
|
|
24
|
+
json: false
|
|
55
25
|
});
|
|
56
26
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
}());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
60
29
|
exports.HttpHandler = HttpHandler;
|
|
61
30
|
//# sourceMappingURL=http-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-handler.js","sourceRoot":"","sources":["../../../src/handlers/http-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-handler.js","sourceRoot":"","sources":["../../../src/handlers/http-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkD;AAIlD,MAAa,WAAW;IAEpB;QACI,IAAI,CAAC,WAAW,GAAG,IAAI,wBAAW,EAAE,CAAC;IACzC,CAAC;IACK,WAAW,CAAC,oBAAoE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAa,EAAE,QAAiB;;YACxI,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAS;gBAC1C,GAAG,EAAE,GAAG,QAAQ,IAAI,kBAAkB,CAAC,QAAQ,CAAC,EAAE;gBAClD,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,qBAAqB;gBAC/B,IAAI,EAAE,KAAK;aACd,CAAC,CAAA;QACN,CAAC;KAAA;CACJ;AAbD,kCAaC"}
|
|
@@ -8,56 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.IpfsHttpHandler = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
13
|
+
const http_utils_1 = require("@taquito/http-utils");
|
|
14
|
+
class IpfsHttpHandler {
|
|
15
|
+
constructor(ipfsGatheway) {
|
|
43
16
|
this.httpBackend = new http_utils_1.HttpBackend();
|
|
44
17
|
this._ipfsGateway = ipfsGatheway ? ipfsGatheway : 'ipfs.io';
|
|
45
18
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
mimeType: "text; charset=utf-8",
|
|
55
|
-
json: false
|
|
56
|
-
})];
|
|
19
|
+
getMetadata(_contractAbstraction, { location }, _context) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return this.httpBackend.createRequest({
|
|
22
|
+
url: `https://${this._ipfsGateway}/ipfs/${location.substring(2)}/`,
|
|
23
|
+
method: 'GET',
|
|
24
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
25
|
+
mimeType: "text; charset=utf-8",
|
|
26
|
+
json: false
|
|
57
27
|
});
|
|
58
28
|
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
62
31
|
exports.IpfsHttpHandler = IpfsHttpHandler;
|
|
63
32
|
//# sourceMappingURL=ipfs-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfs-handler.js","sourceRoot":"","sources":["../../../src/handlers/ipfs-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ipfs-handler.js","sourceRoot":"","sources":["../../../src/handlers/ipfs-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkD;AAIlD,MAAa,eAAe;IAIxB,YAAY,YAAoB;QAFzB,gBAAW,GAAG,IAAI,wBAAW,EAAE,CAAC;QAGnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA,CAAC,CAAC,YAAY,CAAA,CAAC,CAAC,SAAS,CAAC;IAC9D,CAAC;IAEK,WAAW,CAAC,oBAAoE,EAAE,EAAE,QAAQ,EAAa,EAAE,QAAiB;;YAC9H,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAS;gBAC1C,GAAG,EAAE,WAAW,IAAI,CAAC,YAAY,SAAS,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG;gBAClE,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,EAAC,cAAc,EAAE,YAAY,EAAC;gBACvC,QAAQ,EAAE,qBAAqB;gBAC/B,IAAI,EAAE,KAAK;aACd,CAAC,CAAA;QACN,CAAC;KAAA;CACJ;AAjBD,0CAiBC"}
|
|
@@ -8,86 +8,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.TezosStorageHandler = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
13
|
+
const michelson_encoder_1 = require("@taquito/michelson-encoder");
|
|
14
|
+
const utils_1 = require("@taquito/utils");
|
|
15
|
+
const tzip16_errors_1 = require("../tzip16-errors");
|
|
16
|
+
const typeOfValueToFind = {
|
|
44
17
|
prim: 'big_map',
|
|
45
18
|
args: [{ prim: 'string' }, { prim: 'bytes' }],
|
|
46
19
|
annots: ['%metadata'],
|
|
47
20
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w
|
|
21
|
+
class TezosStorageHandler {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w|%]+)$/;
|
|
51
24
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
case 2:
|
|
72
|
-
bytes = _b.sent();
|
|
73
|
-
if (!bytes) {
|
|
74
|
-
throw new tzip16_errors_1.MetadataNotFound("No '" + parsedTezosStorageUri.path + "' key found in the big map %metadata of the contract " + (parsedTezosStorageUri.contractAddress || contractAbstraction.address));
|
|
75
|
-
}
|
|
76
|
-
if (!/^[0-9a-fA-F]*$/.test(bytes)) {
|
|
77
|
-
throw new tzip16_errors_1.InvalidMetadataType();
|
|
78
|
-
}
|
|
79
|
-
return [2 /*return*/, utils_1.bytes2Char(bytes)];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
25
|
+
getMetadata(contractAbstraction, { location }, context) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const parsedTezosStorageUri = this.parseTezosStorageUri(location);
|
|
28
|
+
if (!parsedTezosStorageUri) {
|
|
29
|
+
throw new tzip16_errors_1.InvalidUri(`tezos-storage:${location}`);
|
|
30
|
+
}
|
|
31
|
+
const storage = yield context.rpc.getNormalizedScript(parsedTezosStorageUri.contractAddress || contractAbstraction.address);
|
|
32
|
+
const bigMapId = michelson_encoder_1.Schema.fromRPCResponse({ script: storage }).FindFirstInTopLevelPair(storage.storage, typeOfValueToFind);
|
|
33
|
+
if (!bigMapId) {
|
|
34
|
+
throw new tzip16_errors_1.BigMapMetadataNotFound();
|
|
35
|
+
}
|
|
36
|
+
const bytes = yield context.contract.getBigMapKeyByID(bigMapId['int'].toString(), parsedTezosStorageUri.path, new michelson_encoder_1.Schema(typeOfValueToFind));
|
|
37
|
+
if (!bytes) {
|
|
38
|
+
throw new tzip16_errors_1.MetadataNotFound(`No '${parsedTezosStorageUri.path}' key found in the big map %metadata of the contract ${parsedTezosStorageUri.contractAddress || contractAbstraction.address}`);
|
|
39
|
+
}
|
|
40
|
+
if (!/^[0-9a-fA-F]*$/.test(bytes)) {
|
|
41
|
+
throw new tzip16_errors_1.InvalidMetadataType();
|
|
42
|
+
}
|
|
43
|
+
return utils_1.bytes2Char(bytes);
|
|
82
44
|
});
|
|
83
|
-
}
|
|
45
|
+
}
|
|
84
46
|
/**
|
|
85
47
|
* @description Extract the smart contract address, the network and the path pointing to the metadata from the uri
|
|
86
48
|
* @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
|
|
87
49
|
* @param tezosStorageURI URI (without the tezos-storage prefix)
|
|
88
50
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
51
|
+
parseTezosStorageUri(tezosStorageURI) {
|
|
52
|
+
const extractor = this.TEZOS_STORAGE_REGEX.exec(tezosStorageURI);
|
|
91
53
|
if (!extractor)
|
|
92
54
|
return;
|
|
93
55
|
return {
|
|
@@ -95,8 +57,7 @@ var TezosStorageHandler = /** @class */ (function () {
|
|
|
95
57
|
network: extractor[2],
|
|
96
58
|
path: decodeURIComponent(extractor[3]),
|
|
97
59
|
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
101
62
|
exports.TezosStorageHandler = TezosStorageHandler;
|
|
102
63
|
//# sourceMappingURL=tezos-storage-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tezos-storage-handler.js","sourceRoot":"","sources":["../../../src/handlers/tezos-storage-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tezos-storage-handler.js","sourceRoot":"","sources":["../../../src/handlers/tezos-storage-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kEAAoD;AAGpD,0CAA4C;AAC5C,oDAK0B;AAE1B,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC7C,MAAM,EAAE,CAAC,WAAW,CAAC;CACtB,CAAC;AAIF,MAAa,mBAAmB;IAAhC;QACmB,wBAAmB,GAAG,8CAA8C,CAAC;IAyDxF,CAAC;IAvDO,WAAW,CACf,mBAAmE,EACnE,EAAE,QAAQ,EAAa,EACvB,OAAgB;;YAEhB,MAAM,qBAAqB,GAAG,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAClE,IAAI,CAAC,qBAAqB,EAAE;gBAC1B,MAAM,IAAI,0BAAU,CAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC;aACnD;YACD,MAAM,OAAO,GAAQ,MAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CACxD,qBAAqB,CAAC,eAAe,IAAI,mBAAmB,CAAC,OAAO,CACrE,CAAC;YACF,MAAM,QAAQ,GAAG,0BAAM,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,uBAAuB,CAClF,OAAO,CAAC,OAAO,EACf,iBAAiB,CAClB,CAAC;YAEF,IAAI,CAAC,QAAQ,EAAE;gBACb,MAAM,IAAI,sCAAsB,EAAE,CAAC;aACpC;YAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CACnD,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAC1B,qBAAqB,CAAC,IAAI,EAC1B,IAAI,0BAAM,CAAC,iBAAiB,CAAC,CAC9B,CAAC;YAEF,IAAI,CAAC,KAAK,EAAE;gBACV,MAAM,IAAI,gCAAgB,CACxB,OAAO,qBAAqB,CAAC,IAAI,wDAC/B,qBAAqB,CAAC,eAAe,IAAI,mBAAmB,CAAC,OAC/D,EAAE,CACH,CAAC;aACH;YAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBACjC,MAAM,IAAI,mCAAmB,EAAE,CAAC;aACjC;YACD,OAAO,kBAAU,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;KAAA;IAED;;;;OAIG;IACK,oBAAoB,CAAC,eAAuB;QAClD,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS;YAAE,OAAO;QACvB,OAAO;YACL,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC;YAC7B,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;YACrB,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SACvC,CAAC;IACJ,CAAC;CACF;AA1DD,kDA0DC"}
|
|
@@ -8,44 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.MetadataProvider = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
13
|
+
const tzip16_errors_1 = require("./tzip16-errors");
|
|
14
|
+
const tzip16_utils_1 = require("./tzip16-utils");
|
|
42
15
|
/**
|
|
43
16
|
* @description: Metadata Provider
|
|
44
17
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
18
|
+
class MetadataProvider {
|
|
19
|
+
constructor(handlers) {
|
|
47
20
|
this.handlers = handlers;
|
|
48
|
-
this.PROTOCOL_REGEX = /(?:sha256
|
|
21
|
+
this.PROTOCOL_REGEX = /(?:sha256:\/\/0x(.*)\/)?(https?|ipfs|tezos-storage):(.*)/;
|
|
49
22
|
}
|
|
50
23
|
/**
|
|
51
24
|
* @description Fetch the metadata by using the appropriate handler based on the protcol found in the URI
|
|
@@ -54,51 +27,43 @@ var MetadataProvider = /** @class */ (function () {
|
|
|
54
27
|
* @param _uri the decoded uri found in the storage
|
|
55
28
|
* @param context the TezosToolkit Context
|
|
56
29
|
*/
|
|
57
|
-
|
|
58
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
uri: uri,
|
|
83
|
-
metadata: metadataJSON,
|
|
84
|
-
integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
|
|
85
|
-
sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined
|
|
86
|
-
}];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
30
|
+
provideMetadata(contractAbstraction, uri, context) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const uriInfo = this.extractProtocolInfo(uri);
|
|
33
|
+
if (!uriInfo || !uriInfo.location) {
|
|
34
|
+
throw new tzip16_errors_1.InvalidUri(uri);
|
|
35
|
+
}
|
|
36
|
+
const handler = this.handlers.get(uriInfo.protocol);
|
|
37
|
+
if (!handler) {
|
|
38
|
+
throw new tzip16_errors_1.ProtocolNotSupported(uriInfo.protocol);
|
|
39
|
+
}
|
|
40
|
+
const metadata = yield handler.getMetadata(contractAbstraction, uriInfo, context);
|
|
41
|
+
const sha256Hash = tzip16_utils_1.calculateSHA256Hash(metadata);
|
|
42
|
+
let metadataJSON;
|
|
43
|
+
try {
|
|
44
|
+
metadataJSON = JSON.parse(metadata);
|
|
45
|
+
}
|
|
46
|
+
catch (ex) {
|
|
47
|
+
throw new tzip16_errors_1.InvalidMetadata(metadata);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
uri,
|
|
51
|
+
metadata: metadataJSON,
|
|
52
|
+
integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
|
|
53
|
+
sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined,
|
|
54
|
+
};
|
|
89
55
|
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
56
|
+
}
|
|
57
|
+
extractProtocolInfo(_uri) {
|
|
58
|
+
const extractor = this.PROTOCOL_REGEX.exec(_uri);
|
|
93
59
|
if (!extractor)
|
|
94
60
|
return;
|
|
95
61
|
return {
|
|
96
62
|
sha256hash: extractor[1],
|
|
97
63
|
protocol: extractor[2],
|
|
98
|
-
location: extractor[3]
|
|
64
|
+
location: extractor[3],
|
|
99
65
|
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
}());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
103
68
|
exports.MetadataProvider = MetadataProvider;
|
|
104
69
|
//# sourceMappingURL=metadata-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-provider.js","sourceRoot":"","sources":["../../src/metadata-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata-provider.js","sourceRoot":"","sources":["../../src/metadata-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,mDAAoF;AACpF,iDAAqD;AA8BrD;;GAEG;AACH,MAAa,gBAAgB;IAG3B,YAAoB,QAA8B;QAA9B,aAAQ,GAAR,QAAQ,CAAsB;QAFjC,mBAAc,GAAG,0DAA0D,CAAC;IAExC,CAAC;IAEtD;;;;;;OAMG;IACG,eAAe,CACnB,mBAAmE,EACnE,GAAW,EACX,OAAgB;;YAEhB,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC9C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;gBACjC,MAAM,IAAI,0BAAU,CAAC,GAAG,CAAC,CAAC;aAC3B;YAED,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACpD,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,oCAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;aAClD;YAED,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAClF,MAAM,UAAU,GAAG,kCAAmB,CAAC,QAAQ,CAAC,CAAC;YACjD,IAAI,YAAY,CAAC;YACjB,IAAI;gBACF,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;aACrC;YAAC,OAAO,EAAE,EAAE;gBACX,MAAM,IAAI,+BAAe,CAAC,QAAQ,CAAC,CAAC;aACrC;YAED,OAAO;gBACL,GAAG;gBACH,QAAQ,EAAE,YAAY;gBACtB,oBAAoB,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS;gBACxF,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;aACxD,CAAC;QACJ,CAAC;KAAA;IAEO,mBAAmB,CAAC,IAAY;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,SAAS;YAAE,OAAO;QACvB,OAAO;YACL,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;YACxB,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;YACtB,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;SACvB,CAAC;IACJ,CAAC;CACF;AArDD,4CAqDC"}
|