@taquito/tzip16 11.1.0 → 12.0.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 +14 -43
- package/dist/lib/handlers/http-handler.js.map +1 -1
- package/dist/lib/handlers/ipfs-handler.js +14 -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 +72 -155
- 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 -196
- package/dist/lib/viewKind/michelson-storage-view.js.map +1 -1
- package/dist/lib/viewKind/viewFactory.js +16 -19
- package/dist/lib/viewKind/viewFactory.js.map +1 -1
- package/dist/taquito-tzip16.es6.js +569 -0
- package/dist/taquito-tzip16.es6.js.map +1 -0
- package/dist/taquito-tzip16.umd.js +326 -522
- 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/dist/types/viewKind/michelson-storage-view.d.ts +3 -1
- package/dist/types/viewKind/viewFactory.d.ts +2 -2
- package/package.json +27 -27
- package/dist/taquito-tzip16.es5.js +0 -761
- package/dist/taquito-tzip16.es5.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@taquito/http-utils'), require('@taquito/michelson-encoder'), require('@taquito/utils'), require('@taquito/taquito'), require('bignumber.js'), require('crypto-js')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', '@taquito/http-utils', '@taquito/michelson-encoder', '@taquito/utils', '@taquito/taquito', 'bignumber.js', 'crypto-js'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoTzip16 = {}, global.httpUtils, global.michelsonEncoder, global.utils, global.taquito, global.BigNumber, global.CryptoJS));
|
|
5
|
-
}(this, (function (exports, httpUtils, michelsonEncoder, utils, taquito, BigNumber, CryptoJS) { 'use strict';
|
|
5
|
+
})(this, (function (exports, httpUtils, michelsonEncoder, utils, taquito, BigNumber, CryptoJS) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -32,228 +32,140 @@
|
|
|
32
32
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
33
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
34
|
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function __generator(thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (_) try {
|
|
44
|
-
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;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function __values(o) {
|
|
66
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
67
|
-
if (m) return m.call(o);
|
|
68
|
-
if (o && typeof o.length === "number") return {
|
|
69
|
-
next: function () {
|
|
70
|
-
if (o && i >= o.length) o = void 0;
|
|
71
|
-
return { value: o && o[i++], done: !o };
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function __read(o, n) {
|
|
78
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
79
|
-
if (!m) return o;
|
|
80
|
-
var i = m.call(o), r, ar = [], e;
|
|
81
|
-
try {
|
|
82
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
83
|
-
}
|
|
84
|
-
catch (error) { e = { error: error }; }
|
|
85
|
-
finally {
|
|
86
|
-
try {
|
|
87
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
88
|
-
}
|
|
89
|
-
finally { if (e) throw e.error; }
|
|
90
|
-
}
|
|
91
|
-
return ar;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** @deprecated */
|
|
95
|
-
function __spread() {
|
|
96
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
97
|
-
ar = ar.concat(__read(arguments[i]));
|
|
98
|
-
return ar;
|
|
99
35
|
}
|
|
100
36
|
|
|
101
|
-
|
|
102
|
-
|
|
37
|
+
class HttpHandler {
|
|
38
|
+
constructor() {
|
|
103
39
|
this.httpBackend = new httpUtils.HttpBackend();
|
|
104
40
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})];
|
|
41
|
+
getMetadata(_contractAbstraction, { protocol, location }, _context) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return this.httpBackend.createRequest({
|
|
44
|
+
url: `${protocol}:${decodeURIComponent(location)}`,
|
|
45
|
+
method: 'GET',
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': 'text/plain; charset=utf-8'
|
|
48
|
+
},
|
|
49
|
+
json: false
|
|
115
50
|
});
|
|
116
51
|
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
120
54
|
|
|
121
|
-
|
|
122
|
-
|
|
55
|
+
class BigMapMetadataNotFound extends Error {
|
|
56
|
+
constructor() {
|
|
57
|
+
super('Non-compliance with the TZIP-016 standard. No big map named metadata was found in the contract storage.');
|
|
123
58
|
this.name = 'BigMapMetadataNotFound';
|
|
124
|
-
this.message = 'Non-compliance with the TZIP-016 standard. No big map named metadata was found in the contract storage.';
|
|
125
59
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
60
|
+
}
|
|
61
|
+
class MetadataNotFound extends Error {
|
|
62
|
+
constructor(info) {
|
|
63
|
+
super(`No metadata was found in the contract storage. ${info}`);
|
|
130
64
|
this.info = info;
|
|
131
65
|
this.name = 'MetadataNotFound';
|
|
132
|
-
this.message = "No metadata was found in the contract storage. " + info;
|
|
133
66
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
67
|
+
}
|
|
68
|
+
class UriNotFound extends Error {
|
|
69
|
+
constructor() {
|
|
70
|
+
super('Non-compliance with the TZIP-016 standard. No URI found in the contract storage.');
|
|
138
71
|
this.name = 'UriNotFound';
|
|
139
|
-
this.message = 'Non-compliance with the TZIP-016 standard. No URI found in the contract storage.';
|
|
140
72
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
73
|
+
}
|
|
74
|
+
class InvalidUri extends Error {
|
|
75
|
+
constructor(uri) {
|
|
76
|
+
super(`Non-compliance with the TZIP-016 standard. The URI is invalid: ${uri}.`);
|
|
145
77
|
this.uri = uri;
|
|
146
78
|
this.name = 'InvalidUri';
|
|
147
|
-
this.message = "Non-compliance with the TZIP-016 standard. The URI is invalid: " + uri + ".";
|
|
148
79
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
80
|
+
}
|
|
81
|
+
class InvalidMetadata extends Error {
|
|
82
|
+
constructor(invalidMetadata) {
|
|
83
|
+
super(`The metadata found at the pointed ressource are not compliant with tzip16 standard: ${invalidMetadata}.`);
|
|
153
84
|
this.invalidMetadata = invalidMetadata;
|
|
154
85
|
this.name = 'InvalidMetadata';
|
|
155
|
-
this.message = "The metadata found at the pointed ressource are not compliant with tzip16 standard: " + invalidMetadata + ".";
|
|
156
86
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
87
|
+
}
|
|
88
|
+
class ProtocolNotSupported extends Error {
|
|
89
|
+
constructor(protocol) {
|
|
90
|
+
super(`The protocol found in the URI is not supported: ${protocol}.`);
|
|
161
91
|
this.protocol = protocol;
|
|
162
92
|
this.name = 'ProtocolNotSupported';
|
|
163
|
-
this.message = "The protocol found in the URI is not supported: " + protocol + ".";
|
|
164
93
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
94
|
+
}
|
|
95
|
+
class InvalidMetadataType extends Error {
|
|
96
|
+
constructor() {
|
|
97
|
+
super('The contract does not comply with the tzip16 standard. The type of metadata should be bytes.');
|
|
169
98
|
this.name = 'InvalidMetadataType';
|
|
170
|
-
this.message = 'The contract does not comply with the tzip16 standard. The type of metadata should be bytes.';
|
|
171
99
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
100
|
+
}
|
|
101
|
+
class UnconfiguredMetadataProviderError extends Error {
|
|
102
|
+
constructor() {
|
|
103
|
+
super('No metadata provider has been configured. The default one can be configured by calling addExtension(new Tzip16Module()) on your TezosToolkit instance.');
|
|
176
104
|
this.name = 'UnconfiguredMetadataProviderError';
|
|
177
|
-
this.message = 'No metadata provider has been configured. The default one can be configured by calling addExtension(new Tzip16Module()) on your TezosToolkit instance.';
|
|
178
105
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
106
|
+
}
|
|
107
|
+
class ForbiddenInstructionInViewCode extends Error {
|
|
108
|
+
constructor(instruction) {
|
|
109
|
+
super(`Error found in the code of the view. It contains a forbidden instruction: ${instruction}.`);
|
|
183
110
|
this.instruction = instruction;
|
|
184
111
|
this.name = 'ForbiddenInstructionInViewCode';
|
|
185
|
-
this.message = "Error found in the code of the view. It contains a forbidden instruction: " + instruction + ".";
|
|
186
112
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
113
|
+
}
|
|
114
|
+
class NoParameterExpectedError extends Error {
|
|
115
|
+
constructor(viewName, args) {
|
|
116
|
+
super(`${viewName} Received ${args.length} arguments while expecting no parameter or 'Unit'`);
|
|
191
117
|
this.viewName = viewName;
|
|
192
118
|
this.args = args;
|
|
193
119
|
this.name = 'NoParameterExpectedError';
|
|
194
|
-
this.message = viewName + " Received " + args.length + " arguments while expecting no parameter or 'Unit'";
|
|
195
120
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
121
|
+
}
|
|
122
|
+
class InvalidViewParameterError extends Error {
|
|
123
|
+
constructor(viewName, sigs, args) {
|
|
124
|
+
super(`${viewName} Received ${args.length} arguments while expecting one of the following signatures (${JSON.stringify(sigs)})`);
|
|
200
125
|
this.viewName = viewName;
|
|
201
126
|
this.sigs = sigs;
|
|
202
127
|
this.args = args;
|
|
203
128
|
this.name = 'InvalidViewParameterError';
|
|
204
|
-
this.message = viewName + " Received " + args.length + " arguments while expecting one of the following signatures (" + JSON.stringify(sigs) + ")";
|
|
205
129
|
}
|
|
206
|
-
|
|
207
|
-
}());
|
|
130
|
+
}
|
|
208
131
|
|
|
209
|
-
|
|
132
|
+
const typeOfValueToFind = {
|
|
210
133
|
prim: 'big_map',
|
|
211
134
|
args: [{ prim: 'string' }, { prim: 'bytes' }],
|
|
212
135
|
annots: ['%metadata'],
|
|
213
136
|
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
case 2:
|
|
238
|
-
bytes = _b.sent();
|
|
239
|
-
if (!bytes) {
|
|
240
|
-
throw new MetadataNotFound("No '" + parsedTezosStorageUri.path + "' key found in the big map %metadata of the contract " + (parsedTezosStorageUri.contractAddress || contractAbstraction.address));
|
|
241
|
-
}
|
|
242
|
-
if (!/^[0-9a-fA-F]*$/.test(bytes)) {
|
|
243
|
-
throw new InvalidMetadataType();
|
|
244
|
-
}
|
|
245
|
-
return [2 /*return*/, utils.bytes2Char(bytes)];
|
|
246
|
-
}
|
|
247
|
-
});
|
|
137
|
+
class TezosStorageHandler {
|
|
138
|
+
constructor() {
|
|
139
|
+
this.TEZOS_STORAGE_REGEX = /^(?:\/\/(KT1\w{33})(?:\.(.+))?\/)?([\w|%]+)$/;
|
|
140
|
+
}
|
|
141
|
+
getMetadata(contractAbstraction, { location }, context) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const parsedTezosStorageUri = this.parseTezosStorageUri(location);
|
|
144
|
+
if (!parsedTezosStorageUri) {
|
|
145
|
+
throw new InvalidUri(`tezos-storage:${location}`);
|
|
146
|
+
}
|
|
147
|
+
const script = yield context.readProvider.getScript(parsedTezosStorageUri.contractAddress || contractAbstraction.address, 'head');
|
|
148
|
+
const bigMapId = michelsonEncoder.Schema.fromRPCResponse({ script }).FindFirstInTopLevelPair(script.storage, typeOfValueToFind);
|
|
149
|
+
if (!bigMapId) {
|
|
150
|
+
throw new BigMapMetadataNotFound();
|
|
151
|
+
}
|
|
152
|
+
const bytes = yield context.contract.getBigMapKeyByID(bigMapId['int'].toString(), parsedTezosStorageUri.path, new michelsonEncoder.Schema(typeOfValueToFind));
|
|
153
|
+
if (!bytes) {
|
|
154
|
+
throw new MetadataNotFound(`No '${parsedTezosStorageUri.path}' key found in the big map %metadata of the contract ${parsedTezosStorageUri.contractAddress || contractAbstraction.address}`);
|
|
155
|
+
}
|
|
156
|
+
if (!/^[0-9a-fA-F]*$/.test(bytes)) {
|
|
157
|
+
throw new InvalidMetadataType();
|
|
158
|
+
}
|
|
159
|
+
return utils.bytes2Char(bytes);
|
|
248
160
|
});
|
|
249
|
-
}
|
|
161
|
+
}
|
|
250
162
|
/**
|
|
251
163
|
* @description Extract the smart contract address, the network and the path pointing to the metadata from the uri
|
|
252
164
|
* @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
|
|
253
165
|
* @param tezosStorageURI URI (without the tezos-storage prefix)
|
|
254
166
|
*/
|
|
255
|
-
|
|
256
|
-
|
|
167
|
+
parseTezosStorageUri(tezosStorageURI) {
|
|
168
|
+
const extractor = this.TEZOS_STORAGE_REGEX.exec(tezosStorageURI);
|
|
257
169
|
if (!extractor)
|
|
258
170
|
return;
|
|
259
171
|
return {
|
|
@@ -261,31 +173,27 @@
|
|
|
261
173
|
network: extractor[2],
|
|
262
174
|
path: decodeURIComponent(extractor[3]),
|
|
263
175
|
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
}());
|
|
176
|
+
}
|
|
177
|
+
}
|
|
267
178
|
|
|
268
|
-
|
|
269
|
-
|
|
179
|
+
class IpfsHttpHandler {
|
|
180
|
+
constructor(ipfsGatheway) {
|
|
270
181
|
this.httpBackend = new httpUtils.HttpBackend();
|
|
271
182
|
this._ipfsGateway = ipfsGatheway ? ipfsGatheway : 'ipfs.io';
|
|
272
183
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
json: false
|
|
283
|
-
})];
|
|
184
|
+
getMetadata(_contractAbstraction, { location }, _context) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
return this.httpBackend.createRequest({
|
|
187
|
+
url: `https://${this._ipfsGateway}/ipfs/${location.substring(2)}/`,
|
|
188
|
+
method: 'GET',
|
|
189
|
+
headers: {
|
|
190
|
+
'Content-Type': 'text/plain; charset=utf-8'
|
|
191
|
+
},
|
|
192
|
+
json: false
|
|
284
193
|
});
|
|
285
194
|
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
}());
|
|
195
|
+
}
|
|
196
|
+
}
|
|
289
197
|
|
|
290
198
|
exports.ViewImplementationType = void 0;
|
|
291
199
|
(function (ViewImplementationType) {
|
|
@@ -293,17 +201,18 @@
|
|
|
293
201
|
ViewImplementationType["REST_API_QUERY"] = "restApiQuery";
|
|
294
202
|
})(exports.ViewImplementationType || (exports.ViewImplementationType = {}));
|
|
295
203
|
|
|
296
|
-
|
|
297
|
-
|
|
204
|
+
class MichelsonStorageView {
|
|
205
|
+
constructor(viewName, contract, rpc, readProvider, returnType, code, viewParameterType) {
|
|
298
206
|
this.viewName = viewName;
|
|
299
207
|
this.contract = contract;
|
|
300
208
|
this.rpc = rpc;
|
|
209
|
+
this.readProvider = readProvider;
|
|
301
210
|
this.returnType = returnType;
|
|
302
211
|
this.code = code;
|
|
303
212
|
this.viewParameterType = viewParameterType;
|
|
304
|
-
this.validateArgs =
|
|
305
|
-
|
|
306
|
-
if (!sigs.find(
|
|
213
|
+
this.validateArgs = (args, schema, viewName) => {
|
|
214
|
+
const sigs = schema.ExtractSignatures();
|
|
215
|
+
if (!sigs.find((x) => x.length === args.length)) {
|
|
307
216
|
throw new InvalidViewParameterError(viewName, sigs, args);
|
|
308
217
|
}
|
|
309
218
|
};
|
|
@@ -313,106 +222,73 @@
|
|
|
313
222
|
* 'AMOUNT', 'CREATE_CONTRACT', 'SENDER', 'SET_DELEGATE', 'SOURCE', and 'TRANSFER_TOKENS'
|
|
314
223
|
* The method throw an error if an illegal instruction is found
|
|
315
224
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
var illegalInstructions = [
|
|
225
|
+
findForbiddenInstructionInViewCode(code) {
|
|
226
|
+
const illegalInstructions = [
|
|
319
227
|
'AMOUNT',
|
|
320
228
|
'CREATE_CONTRACT',
|
|
321
229
|
'SENDER',
|
|
322
230
|
'SET_DELEGATE',
|
|
323
231
|
'SOURCE',
|
|
324
|
-
'TRANSFER_TOKENS'
|
|
232
|
+
'TRANSFER_TOKENS',
|
|
325
233
|
];
|
|
326
|
-
|
|
327
|
-
for (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
for (var code_1 = (e_2 = void 0, __values(code)), code_1_1 = code_1.next(); !code_1_1.done; code_1_1 = code_1.next()) {
|
|
331
|
-
var instruction = code_1_1.value;
|
|
332
|
-
if (instruction.prim === forbiddenInstruction) {
|
|
333
|
-
throw new ForbiddenInstructionInViewCode(forbiddenInstruction);
|
|
334
|
-
}
|
|
335
|
-
if (instruction.args && instruction.args.length !== 0) {
|
|
336
|
-
this.findForbiddenInstructionInViewCode(instruction.args);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
234
|
+
for (const forbiddenInstruction of illegalInstructions) {
|
|
235
|
+
for (const instruction of code) {
|
|
236
|
+
if (instruction.prim === forbiddenInstruction) {
|
|
237
|
+
throw new ForbiddenInstructionInViewCode(forbiddenInstruction);
|
|
339
238
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
try {
|
|
343
|
-
if (code_1_1 && !code_1_1.done && (_b = code_1.return)) _b.call(code_1);
|
|
344
|
-
}
|
|
345
|
-
finally { if (e_2) throw e_2.error; }
|
|
239
|
+
if (instruction.args && instruction.args.length !== 0) {
|
|
240
|
+
this.findForbiddenInstructionInViewCode(instruction.args);
|
|
346
241
|
}
|
|
347
242
|
}
|
|
348
243
|
}
|
|
349
|
-
|
|
350
|
-
finally {
|
|
351
|
-
try {
|
|
352
|
-
if (illegalInstructions_1_1 && !illegalInstructions_1_1.done && (_a = illegalInstructions_1.return)) _a.call(illegalInstructions_1);
|
|
353
|
-
}
|
|
354
|
-
finally { if (e_1) throw e_1.error; }
|
|
355
|
-
}
|
|
356
|
-
};
|
|
244
|
+
}
|
|
357
245
|
/**
|
|
358
246
|
* @description According to the tzip-16 standard, in the first version of the specification, the instruction SELF should only be used before ADDRESS
|
|
359
247
|
* The method throws an error is the instruction SELF is present, but not followed by ADDRESS
|
|
360
248
|
*/
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
var nextInstruction = code[index + 1] ? code[index + 1].prim : undefined;
|
|
369
|
-
if (nextInstruction !== 'ADDRESS') {
|
|
370
|
-
throw new ForbiddenInstructionInViewCode('the instruction SELF should only be used before ADDRESS');
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
if (instruction.args && instruction.args.length !== 0) {
|
|
374
|
-
this.illegalUseOfSelfInstruction(instruction.args);
|
|
249
|
+
illegalUseOfSelfInstruction(code) {
|
|
250
|
+
for (const instruction of code) {
|
|
251
|
+
if (instruction.prim === 'SELF') {
|
|
252
|
+
const index = code.indexOf(instruction);
|
|
253
|
+
const nextInstruction = code[index + 1] ? code[index + 1].prim : undefined;
|
|
254
|
+
if (nextInstruction !== 'ADDRESS') {
|
|
255
|
+
throw new ForbiddenInstructionInViewCode('the instruction SELF should only be used before ADDRESS');
|
|
375
256
|
}
|
|
376
257
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
finally {
|
|
380
|
-
try {
|
|
381
|
-
if (code_2_1 && !code_2_1.done && (_a = code_2.return)) _a.call(code_2);
|
|
258
|
+
if (instruction.args && instruction.args.length !== 0) {
|
|
259
|
+
this.illegalUseOfSelfInstruction(instruction.args);
|
|
382
260
|
}
|
|
383
|
-
finally { if (e_3) throw e_3.error; }
|
|
384
261
|
}
|
|
385
|
-
}
|
|
262
|
+
}
|
|
386
263
|
/**
|
|
387
264
|
* @description Loops through the view's code and replace SELF, BALANCE, NOW, and CHAIN_ID with Michelson expressions that match the current context, if applicable.
|
|
388
265
|
*/
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
var instructionsToReplace = {
|
|
266
|
+
adaptViewCodeToContext(code, contractBalance, blockTimeStamp, chainId) {
|
|
267
|
+
const instructionsToReplace = {
|
|
392
268
|
SELF: [
|
|
393
269
|
{ prim: 'PUSH', args: [{ prim: 'address' }, { string: this.contract.address }] },
|
|
394
270
|
{ prim: 'CONTRACT', args: [{ prim: 'unit' }] },
|
|
395
|
-
{ prim: 'IF_NONE', args: [[{ prim: 'UNIT' }, { prim: 'FAILWITH' }], []] }
|
|
271
|
+
{ prim: 'IF_NONE', args: [[{ prim: 'UNIT' }, { prim: 'FAILWITH' }], []] },
|
|
396
272
|
],
|
|
397
273
|
BALANCE: [{ prim: 'PUSH', args: [{ prim: 'mutez' }, { int: contractBalance }] }],
|
|
398
274
|
NOW: [{ prim: 'PUSH', args: [{ prim: 'timestamp' }, { string: blockTimeStamp }] }],
|
|
399
|
-
CHAIN_ID: [{ prim: 'PUSH', args: [{ prim: 'string' }, { string: chainId }] }]
|
|
275
|
+
CHAIN_ID: [{ prim: 'PUSH', args: [{ prim: 'string' }, { string: chainId }] }],
|
|
400
276
|
};
|
|
401
|
-
code.forEach(
|
|
402
|
-
for (
|
|
277
|
+
code.forEach((x, i) => {
|
|
278
|
+
for (const instruction in instructionsToReplace) {
|
|
403
279
|
if (x.prim === instruction) {
|
|
404
280
|
code[i] = Object(instructionsToReplace)[instruction];
|
|
405
281
|
}
|
|
406
282
|
if (x.args && x.args.length !== 0) {
|
|
407
|
-
|
|
283
|
+
this.adaptViewCodeToContext(x.args, contractBalance, blockTimeStamp, chainId);
|
|
408
284
|
}
|
|
409
285
|
}
|
|
410
286
|
});
|
|
411
287
|
return code;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
288
|
+
}
|
|
289
|
+
formatArgsAndParameter(argView) {
|
|
290
|
+
let args = argView;
|
|
291
|
+
let viewParameterType = this.viewParameterType;
|
|
416
292
|
if (!viewParameterType) {
|
|
417
293
|
viewParameterType = { args: [], prim: 'unit', annots: [] };
|
|
418
294
|
}
|
|
@@ -424,263 +300,206 @@
|
|
|
424
300
|
throw new NoParameterExpectedError(this.viewName, argView);
|
|
425
301
|
}
|
|
426
302
|
}
|
|
427
|
-
|
|
303
|
+
const parameterViewSchema = new michelsonEncoder.ParameterSchema(viewParameterType);
|
|
428
304
|
this.validateArgs(args, parameterViewSchema, this.viewName);
|
|
429
|
-
|
|
430
|
-
return { arg
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
viewScript = {
|
|
464
|
-
script: [
|
|
465
|
-
{ prim: 'parameter', args: [{ prim: 'pair', args: [viewParameterType, storageArgs] }] },
|
|
466
|
-
{ prim: 'storage', args: [{ prim: 'option', args: [this.returnType] }] },
|
|
467
|
-
{
|
|
468
|
-
prim: 'code',
|
|
469
|
-
args: [
|
|
470
|
-
[
|
|
471
|
-
{ prim: 'CAR' },
|
|
472
|
-
code,
|
|
473
|
-
{ prim: 'SOME' },
|
|
474
|
-
{ prim: 'NIL', args: [{ prim: 'operation' }] },
|
|
475
|
-
{ prim: 'PAIR' }
|
|
476
|
-
]
|
|
477
|
-
]
|
|
478
|
-
}
|
|
305
|
+
const arg = parameterViewSchema.Encode(...args);
|
|
306
|
+
return { arg, viewParameterType };
|
|
307
|
+
}
|
|
308
|
+
executeView(...args) {
|
|
309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
// validate view code against tzip-16 specifications
|
|
311
|
+
this.findForbiddenInstructionInViewCode(this.code);
|
|
312
|
+
this.illegalUseOfSelfInstruction(this.code);
|
|
313
|
+
const { arg, viewParameterType } = this.formatArgsAndParameter(args);
|
|
314
|
+
const storageType = this.contract.script.code.find((x) => x.prim === 'storage');
|
|
315
|
+
const storageArgs = storageType.args[0];
|
|
316
|
+
// currentContext
|
|
317
|
+
const storageValue = yield this.readProvider.getStorage(this.contract.address, 'head');
|
|
318
|
+
const chainId = yield this.readProvider.getChainId();
|
|
319
|
+
const contractBalance = (yield this.readProvider.getBalance(this.contract.address, 'head')).toString();
|
|
320
|
+
const blockTimestamp = yield this.readProvider.getBlockTimestamp('head');
|
|
321
|
+
const code = this.adaptViewCodeToContext(this.code, contractBalance, blockTimestamp, chainId);
|
|
322
|
+
if (!this.viewParameterType) {
|
|
323
|
+
code.unshift({ prim: 'CDR' });
|
|
324
|
+
}
|
|
325
|
+
const viewScript = {
|
|
326
|
+
script: [
|
|
327
|
+
{ prim: 'parameter', args: [{ prim: 'pair', args: [viewParameterType, storageArgs] }] },
|
|
328
|
+
{ prim: 'storage', args: [{ prim: 'option', args: [this.returnType] }] },
|
|
329
|
+
{
|
|
330
|
+
prim: 'code',
|
|
331
|
+
args: [
|
|
332
|
+
[
|
|
333
|
+
{ prim: 'CAR' },
|
|
334
|
+
code,
|
|
335
|
+
{ prim: 'SOME' },
|
|
336
|
+
{ prim: 'NIL', args: [{ prim: 'operation' }] },
|
|
337
|
+
{ prim: 'PAIR' },
|
|
479
338
|
],
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
storage: { prim: 'None' },
|
|
343
|
+
input: { prim: 'Pair', args: [arg, storageValue] },
|
|
344
|
+
amount: '0',
|
|
345
|
+
chain_id: chainId,
|
|
346
|
+
balance: '0',
|
|
347
|
+
};
|
|
348
|
+
let result;
|
|
349
|
+
try {
|
|
350
|
+
result = yield this.rpc.runCode(viewScript);
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
const failWith = taquito.validateAndExtractFailwith(error);
|
|
354
|
+
throw failWith
|
|
355
|
+
? new taquito.ViewSimulationError(`The simulation of the Michelson view failed with: ${JSON.stringify(failWith)}`, this.viewName, failWith, error)
|
|
356
|
+
: error;
|
|
357
|
+
}
|
|
358
|
+
const viewResultSchema = new michelsonEncoder.ParameterSchema(this.returnType);
|
|
359
|
+
return viewResultSchema.Execute(result.storage.args[0]);
|
|
493
360
|
});
|
|
494
|
-
};
|
|
495
|
-
return MichelsonStorageView;
|
|
496
|
-
}());
|
|
497
|
-
|
|
498
|
-
var ViewFactory = /** @class */ (function () {
|
|
499
|
-
function ViewFactory() {
|
|
500
361
|
}
|
|
501
|
-
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
class ViewFactory {
|
|
365
|
+
getView(viewName, rpc, readProvider, contract, viewImplementation) {
|
|
502
366
|
if (this.isMichelsonStorageView(viewImplementation)) {
|
|
503
|
-
|
|
504
|
-
if (!
|
|
505
|
-
console.warn(viewName
|
|
367
|
+
const viewValues = viewImplementation[exports.ViewImplementationType.MICHELSON_STORAGE];
|
|
368
|
+
if (!viewValues.returnType || !viewValues.code) {
|
|
369
|
+
console.warn(`${viewName} is missing mandatory code or returnType property therefore it will be skipped.`);
|
|
506
370
|
return;
|
|
507
371
|
}
|
|
508
|
-
return
|
|
509
|
-
|
|
372
|
+
return () => {
|
|
373
|
+
const view = new MichelsonStorageView(viewName, contract, rpc, readProvider, viewValues.returnType, viewValues.code, viewValues.parameter);
|
|
510
374
|
return view;
|
|
511
375
|
};
|
|
512
376
|
}
|
|
513
|
-
}
|
|
514
|
-
|
|
377
|
+
}
|
|
378
|
+
getImplementationType(viewImplementation) {
|
|
515
379
|
return Object.keys(viewImplementation)[0];
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
return this.getImplementationType(viewImplementation) === exports.ViewImplementationType.MICHELSON_STORAGE;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
}());
|
|
380
|
+
}
|
|
381
|
+
isMichelsonStorageView(viewImplementation) {
|
|
382
|
+
return (this.getImplementationType(viewImplementation) === exports.ViewImplementationType.MICHELSON_STORAGE);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
522
385
|
|
|
523
|
-
|
|
386
|
+
const metadataBigMapType = {
|
|
524
387
|
prim: 'big_map',
|
|
525
388
|
args: [{ prim: 'string' }, { prim: 'bytes' }],
|
|
526
|
-
annots: ['%metadata']
|
|
389
|
+
annots: ['%metadata'],
|
|
527
390
|
};
|
|
528
|
-
|
|
529
|
-
|
|
391
|
+
class Tzip16ContractAbstraction {
|
|
392
|
+
constructor(constractAbstraction, context) {
|
|
530
393
|
this.constractAbstraction = constractAbstraction;
|
|
531
394
|
this.context = context;
|
|
532
395
|
this._viewFactory = new ViewFactory();
|
|
533
396
|
this._metadataViewsObject = {};
|
|
534
397
|
this._metadataProvider = context.metadataProvider;
|
|
535
398
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
if (!uri) {
|
|
554
|
-
throw new UriNotFound();
|
|
555
|
-
}
|
|
556
|
-
return [2 /*return*/, uri];
|
|
557
|
-
}
|
|
558
|
-
});
|
|
399
|
+
findMetadataBigMap() {
|
|
400
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
+
const metadataBigMapId = this.constractAbstraction.schema.FindFirstInTopLevelPair(yield this.context.readProvider.getStorage(this.constractAbstraction.address, 'head'), metadataBigMapType);
|
|
402
|
+
if (!metadataBigMapId) {
|
|
403
|
+
throw new BigMapMetadataNotFound();
|
|
404
|
+
}
|
|
405
|
+
return new taquito.BigMapAbstraction(new BigNumber__default["default"](metadataBigMapId['int']), new michelsonEncoder.Schema(metadataBigMapType), this.context.contract);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
getUriOrFail() {
|
|
409
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
410
|
+
const metadataBigMap = yield this.findMetadataBigMap();
|
|
411
|
+
const uri = yield metadataBigMap.get('');
|
|
412
|
+
if (!uri) {
|
|
413
|
+
throw new UriNotFound();
|
|
414
|
+
}
|
|
415
|
+
return uri;
|
|
559
416
|
});
|
|
560
|
-
}
|
|
417
|
+
}
|
|
561
418
|
/**
|
|
562
419
|
* @description Return an object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
|
|
563
420
|
*/
|
|
564
|
-
|
|
565
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return [4 /*yield*/, this.getUriOrFail()];
|
|
575
|
-
case 1:
|
|
576
|
-
uri = _b.sent();
|
|
577
|
-
_a = this;
|
|
578
|
-
return [4 /*yield*/, this._metadataProvider.provideMetadata(this.constractAbstraction, utils.bytes2Char(uri), this.context)];
|
|
579
|
-
case 2:
|
|
580
|
-
_a._metadataEnvelope = _b.sent();
|
|
581
|
-
_b.label = 3;
|
|
582
|
-
case 3: return [2 /*return*/, this._metadataEnvelope];
|
|
583
|
-
}
|
|
584
|
-
});
|
|
421
|
+
getMetadata() {
|
|
422
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
423
|
+
if (!this._metadataProvider) {
|
|
424
|
+
throw new UnconfiguredMetadataProviderError();
|
|
425
|
+
}
|
|
426
|
+
if (!this._metadataEnvelope) {
|
|
427
|
+
const uri = yield this.getUriOrFail();
|
|
428
|
+
this._metadataEnvelope = yield this._metadataProvider.provideMetadata(this.constractAbstraction, utils.bytes2Char(uri), this.context);
|
|
429
|
+
}
|
|
430
|
+
return this._metadataEnvelope;
|
|
585
431
|
});
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
return [4 /*yield*/, this.initializeMetadataViewsList()];
|
|
594
|
-
case 1:
|
|
595
|
-
_a.sent();
|
|
596
|
-
_a.label = 2;
|
|
597
|
-
case 2: return [2 /*return*/, this._metadataViewsObject];
|
|
598
|
-
}
|
|
599
|
-
});
|
|
432
|
+
}
|
|
433
|
+
metadataViews() {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
if (Object.keys(this._metadataViewsObject).length === 0) {
|
|
436
|
+
yield this.initializeMetadataViewsList();
|
|
437
|
+
}
|
|
438
|
+
return this._metadataViewsObject;
|
|
600
439
|
});
|
|
601
|
-
}
|
|
602
|
-
|
|
440
|
+
}
|
|
441
|
+
initializeMetadataViewsList() {
|
|
603
442
|
var _a;
|
|
604
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
case 0: return [4 /*yield*/, this.getMetadata()];
|
|
610
|
-
case 1:
|
|
611
|
-
metadata = (_b.sent()).metadata;
|
|
612
|
-
metadataViews = {};
|
|
613
|
-
(_a = metadata.views) === null || _a === void 0 ? void 0 : _a.forEach(function (view) { return _this.createViewImplementations(view, metadataViews); });
|
|
614
|
-
this._metadataViewsObject = metadataViews;
|
|
615
|
-
return [2 /*return*/];
|
|
616
|
-
}
|
|
617
|
-
});
|
|
443
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
+
const { metadata } = yield this.getMetadata();
|
|
445
|
+
const metadataViews = {};
|
|
446
|
+
(_a = metadata.views) === null || _a === void 0 ? void 0 : _a.forEach((view) => this.createViewImplementations(view, metadataViews));
|
|
447
|
+
this._metadataViewsObject = metadataViews;
|
|
618
448
|
});
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
|
|
449
|
+
}
|
|
450
|
+
generateIndexedViewName(viewName, metadataViews) {
|
|
451
|
+
let i = 1;
|
|
622
452
|
if (viewName in metadataViews) {
|
|
623
|
-
while (
|
|
453
|
+
while (`${viewName}${i}` in metadataViews) {
|
|
624
454
|
i++;
|
|
625
455
|
}
|
|
626
|
-
viewName =
|
|
456
|
+
viewName = `${viewName}${i}`;
|
|
627
457
|
}
|
|
628
458
|
return viewName;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
var
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
console.warn("Skipped generating " + viewName + " because the view has an unsupported type: " + this._viewFactory.getImplementationType(viewImplementation));
|
|
645
|
-
}
|
|
459
|
+
}
|
|
460
|
+
createViewImplementations(view, metadataViews) {
|
|
461
|
+
var _a;
|
|
462
|
+
for (const viewImplementation of (_a = view === null || view === void 0 ? void 0 : view.implementations) !== null && _a !== void 0 ? _a : []) {
|
|
463
|
+
if (view.name) {
|
|
464
|
+
// when views have the same name, add an index at the end of the name
|
|
465
|
+
const viewName = this.generateIndexedViewName(view.name, metadataViews);
|
|
466
|
+
const metadataView = this._viewFactory.getView(viewName, this.context.rpc, this.context.readProvider, this.constractAbstraction, viewImplementation);
|
|
467
|
+
if (metadataView) {
|
|
468
|
+
metadataViews[viewName] = metadataView;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
console.warn(`Skipped generating ${viewName} because the view has an unsupported type: ${this._viewFactory.getImplementationType(viewImplementation)}`);
|
|
646
472
|
}
|
|
647
473
|
}
|
|
648
474
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
try {
|
|
652
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
653
|
-
}
|
|
654
|
-
finally { if (e_1) throw e_1.error; }
|
|
655
|
-
}
|
|
656
|
-
};
|
|
657
|
-
return Tzip16ContractAbstraction;
|
|
658
|
-
}());
|
|
475
|
+
}
|
|
476
|
+
}
|
|
659
477
|
|
|
660
|
-
|
|
478
|
+
const ABSTRACTION_KEY = Symbol('Tzip16ContractAbstractionObjectKey');
|
|
661
479
|
function tzip16(abs, context) {
|
|
662
480
|
return Object.assign(abs, {
|
|
663
481
|
// namespace tzip16
|
|
664
|
-
tzip16
|
|
482
|
+
tzip16() {
|
|
665
483
|
if (!this[ABSTRACTION_KEY]) {
|
|
666
484
|
this[ABSTRACTION_KEY] = new Tzip16ContractAbstraction(this, context);
|
|
667
485
|
}
|
|
486
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
668
487
|
return this[ABSTRACTION_KEY];
|
|
669
|
-
}
|
|
488
|
+
},
|
|
670
489
|
});
|
|
671
490
|
}
|
|
672
491
|
|
|
673
492
|
function calculateSHA256Hash(preimage) {
|
|
674
|
-
return CryptoJS__default[
|
|
493
|
+
return CryptoJS__default["default"].SHA256(preimage).toString(CryptoJS__default["default"].enc.Hex);
|
|
675
494
|
}
|
|
676
495
|
|
|
677
496
|
/**
|
|
678
497
|
* @description: Metadata Provider
|
|
679
498
|
*/
|
|
680
|
-
|
|
681
|
-
|
|
499
|
+
class MetadataProvider {
|
|
500
|
+
constructor(handlers) {
|
|
682
501
|
this.handlers = handlers;
|
|
683
|
-
this.PROTOCOL_REGEX = /(?:sha256
|
|
502
|
+
this.PROTOCOL_REGEX = /(?:sha256:\/\/0x(.*)\/)?(https?|ipfs|tezos-storage):(.*)/;
|
|
684
503
|
}
|
|
685
504
|
/**
|
|
686
505
|
* @description Fetch the metadata by using the appropriate handler based on the protcol found in the URI
|
|
@@ -689,88 +508,73 @@
|
|
|
689
508
|
* @param _uri the decoded uri found in the storage
|
|
690
509
|
* @param context the TezosToolkit Context
|
|
691
510
|
*/
|
|
692
|
-
|
|
693
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
uri: uri,
|
|
718
|
-
metadata: metadataJSON,
|
|
719
|
-
integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
|
|
720
|
-
sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined
|
|
721
|
-
}];
|
|
722
|
-
}
|
|
723
|
-
});
|
|
511
|
+
provideMetadata(contractAbstraction, uri, context) {
|
|
512
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
513
|
+
const uriInfo = this.extractProtocolInfo(uri);
|
|
514
|
+
if (!uriInfo || !uriInfo.location) {
|
|
515
|
+
throw new InvalidUri(uri);
|
|
516
|
+
}
|
|
517
|
+
const handler = this.handlers.get(uriInfo.protocol);
|
|
518
|
+
if (!handler) {
|
|
519
|
+
throw new ProtocolNotSupported(uriInfo.protocol);
|
|
520
|
+
}
|
|
521
|
+
const metadata = yield handler.getMetadata(contractAbstraction, uriInfo, context);
|
|
522
|
+
const sha256Hash = calculateSHA256Hash(metadata);
|
|
523
|
+
let metadataJSON;
|
|
524
|
+
try {
|
|
525
|
+
metadataJSON = JSON.parse(metadata);
|
|
526
|
+
}
|
|
527
|
+
catch (ex) {
|
|
528
|
+
throw new InvalidMetadata(metadata);
|
|
529
|
+
}
|
|
530
|
+
return {
|
|
531
|
+
uri,
|
|
532
|
+
metadata: metadataJSON,
|
|
533
|
+
integrityCheckResult: uriInfo.sha256hash ? uriInfo.sha256hash === sha256Hash : undefined,
|
|
534
|
+
sha256Hash: uriInfo.sha256hash ? sha256Hash : undefined,
|
|
535
|
+
};
|
|
724
536
|
});
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
|
|
537
|
+
}
|
|
538
|
+
extractProtocolInfo(_uri) {
|
|
539
|
+
const extractor = this.PROTOCOL_REGEX.exec(_uri);
|
|
728
540
|
if (!extractor)
|
|
729
541
|
return;
|
|
730
542
|
return {
|
|
731
543
|
sha256hash: extractor[1],
|
|
732
544
|
protocol: extractor[2],
|
|
733
|
-
location: extractor[3]
|
|
545
|
+
location: extractor[3],
|
|
734
546
|
};
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
}());
|
|
547
|
+
}
|
|
548
|
+
}
|
|
738
549
|
|
|
739
|
-
|
|
550
|
+
const DEFAULT_HANDLERS = new Map([
|
|
740
551
|
['http', new HttpHandler()],
|
|
741
552
|
['https', new HttpHandler()],
|
|
742
553
|
['tezos-storage', new TezosStorageHandler()],
|
|
743
554
|
['ipfs', new IpfsHttpHandler()]
|
|
744
555
|
]);
|
|
745
|
-
|
|
746
|
-
|
|
556
|
+
class Tzip16Module {
|
|
557
|
+
constructor(metadataProvider) {
|
|
747
558
|
this._metadataProvider = metadataProvider ? metadataProvider : new MetadataProvider(DEFAULT_HANDLERS);
|
|
748
559
|
}
|
|
749
|
-
|
|
560
|
+
configureContext(context) {
|
|
750
561
|
Object.assign(context, { metadataProvider: this._metadataProvider });
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
}());
|
|
562
|
+
}
|
|
563
|
+
}
|
|
754
564
|
|
|
755
565
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
"
|
|
759
|
-
|
|
760
|
-
};
|
|
761
|
-
/* tslint:enable */
|
|
566
|
+
const VERSION = {
|
|
567
|
+
"commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
|
|
568
|
+
"version": "12.0.0-beta-RC.0"
|
|
569
|
+
};
|
|
762
570
|
|
|
763
571
|
Object.defineProperty(exports, 'bytes2Char', {
|
|
764
572
|
enumerable: true,
|
|
765
|
-
get: function () {
|
|
766
|
-
return utils.bytes2Char;
|
|
767
|
-
}
|
|
573
|
+
get: function () { return utils.bytes2Char; }
|
|
768
574
|
});
|
|
769
575
|
Object.defineProperty(exports, 'char2Bytes', {
|
|
770
576
|
enumerable: true,
|
|
771
|
-
get: function () {
|
|
772
|
-
return utils.char2Bytes;
|
|
773
|
-
}
|
|
577
|
+
get: function () { return utils.char2Bytes; }
|
|
774
578
|
});
|
|
775
579
|
exports.BigMapMetadataNotFound = BigMapMetadataNotFound;
|
|
776
580
|
exports.DEFAULT_HANDLERS = DEFAULT_HANDLERS;
|
|
@@ -798,5 +602,5 @@
|
|
|
798
602
|
|
|
799
603
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
800
604
|
|
|
801
|
-
}))
|
|
605
|
+
}));
|
|
802
606
|
//# sourceMappingURL=taquito-tzip16.umd.js.map
|