@wharfkit/transact-plugin-resource-provider 0.3.0-ui-5

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.
@@ -0,0 +1,302 @@
1
+ /**
2
+ * @wharfkit/resource-provider-plugin v0.2.0
3
+ * https://github.com/wharfkit/resource-provider-plugin
4
+ *
5
+ * @license
6
+ * Copyright (c) 2021 FFF00 Agents AB & Greymass Inc. All Rights Reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without modification,
9
+ * are permitted provided that the following conditions are met:
10
+ *
11
+ * 1. Redistribution of source code must retain the above copyright notice, this
12
+ * list of conditions and the following disclaimer.
13
+ *
14
+ * 2. Redistribution in binary form must reproduce the above copyright notice,
15
+ * this list of conditions and the following disclaimer in the documentation
16
+ * and/or other materials provided with the distribution.
17
+ *
18
+ * 3. Neither the name of the copyright holder nor the names of its contributors
19
+ * may be used to endorse or promote products derived from this software without
20
+ * specific prior written permission.
21
+ *
22
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ *
33
+ * YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE
34
+ * IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY MILITARY FACILITY.
35
+ */
36
+ import { Struct, Name, Asset, AbstractTransactPlugin, TransactHookTypes, Serializer, Signature, Transaction, SigningRequest } from '@wharfkit/session';
37
+
38
+ /******************************************************************************
39
+ Copyright (c) Microsoft Corporation.
40
+
41
+ Permission to use, copy, modify, and/or distribute this software for any
42
+ purpose with or without fee is hereby granted.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
45
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
46
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
47
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
48
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
49
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
50
+ PERFORMANCE OF THIS SOFTWARE.
51
+ ***************************************************************************** */
52
+
53
+ function __decorate(decorators, target, key, desc) {
54
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
55
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
56
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
57
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
58
+ }
59
+
60
+ function hasOriginalActions(original, modified) {
61
+ return original.actions.every((originalAction) => {
62
+ return modified.actions.some((modifiedAction) => {
63
+ // Ensure the original contract account matches
64
+ const matchesOriginalContractAccount = originalAction.account.equals(modifiedAction.account);
65
+ // Ensure the original contract action matches
66
+ const matchesOriginalContractAction = originalAction.name.equals(modifiedAction.name);
67
+ // Ensure the original authorization is in tact
68
+ const matchesOriginalAuthorization = originalAction.authorization.length === modifiedAction.authorization.length &&
69
+ originalAction.authorization[0].actor.equals(modifiedAction.authorization[0].actor);
70
+ // Ensure the original action data matches
71
+ const matchesOriginalActionData = originalAction.data.equals(modifiedAction.data);
72
+ // Return any action that does not match the original
73
+ return (matchesOriginalContractAccount &&
74
+ matchesOriginalContractAction &&
75
+ matchesOriginalAuthorization &&
76
+ matchesOriginalActionData);
77
+ });
78
+ });
79
+ }
80
+ function getNewActions(original, modified) {
81
+ return modified.actions.filter((modifiedAction) => {
82
+ return original.actions.some((originalAction) => {
83
+ // Ensure the original contract account matches
84
+ const matchesOriginalContractAccount = originalAction.account.equals(modifiedAction.account);
85
+ // Ensure the original contract action matches
86
+ const matchesOriginalContractAction = originalAction.name.equals(modifiedAction.name);
87
+ // Ensure the original authorization is in tact
88
+ const matchesOriginalAuthorization = originalAction.authorization.length === modifiedAction.authorization.length &&
89
+ originalAction.authorization[0].actor.equals(modifiedAction.authorization[0].actor);
90
+ // Ensure the original action data matches
91
+ const matchesOriginalActionData = originalAction.data.equals(modifiedAction.data);
92
+ // Return any action that does not match the original
93
+ return !(matchesOriginalContractAccount &&
94
+ matchesOriginalContractAction &&
95
+ matchesOriginalAuthorization &&
96
+ matchesOriginalActionData);
97
+ });
98
+ });
99
+ }
100
+
101
+ let Transfer = class Transfer extends Struct {
102
+ };
103
+ __decorate([
104
+ Struct.field(Name)
105
+ ], Transfer.prototype, "from", void 0);
106
+ __decorate([
107
+ Struct.field(Name)
108
+ ], Transfer.prototype, "to", void 0);
109
+ __decorate([
110
+ Struct.field(Asset)
111
+ ], Transfer.prototype, "quantity", void 0);
112
+ __decorate([
113
+ Struct.field('string')
114
+ ], Transfer.prototype, "memo", void 0);
115
+ Transfer = __decorate([
116
+ Struct.type('transfer')
117
+ ], Transfer);
118
+ class ResourceProviderPlugin extends AbstractTransactPlugin {
119
+ constructor(options) {
120
+ super();
121
+ this.allowFees = false;
122
+ this.endpoints = {};
123
+ // Set the endpoints and chains available
124
+ this.endpoints = options.endpoints;
125
+ if (typeof options?.allowFees !== 'undefined') {
126
+ this.allowFees = options.allowFees;
127
+ }
128
+ // TODO: Allow contact/action combos to be passed in and checked against to ensure no rogue actions were appended.
129
+ // if (typeof options.allowActions !== 'undefined') {
130
+ // this.allowActions = options.allowActions.map((action) => Name.from(action))
131
+ // }
132
+ if (typeof options?.maxFee !== 'undefined') {
133
+ this.maxFee = Asset.from(options.maxFee);
134
+ }
135
+ }
136
+ register(context) {
137
+ context.addHook(TransactHookTypes.beforeSign, (request, context) => this.request(request, context));
138
+ }
139
+ getEndpoint(chain) {
140
+ return this.endpoints[String(chain.id)];
141
+ }
142
+ async request(request, context) {
143
+ // Validate that this request is valid for the resource provider
144
+ this.validateRequest(request, context);
145
+ // Determine appropriate URL for this request
146
+ const endpoint = this.getEndpoint(context.chain);
147
+ // If no endpoint was found, gracefully fail and return the original request.
148
+ if (!endpoint) {
149
+ return {
150
+ request,
151
+ };
152
+ }
153
+ // Assemble the request to the resource provider.
154
+ const url = `${endpoint}/v1/resource_provider/request_transaction`;
155
+ // Perform the request to the resource provider.
156
+ const response = await context.fetch(url, {
157
+ method: 'POST',
158
+ body: JSON.stringify({
159
+ ref: 'unittest',
160
+ request,
161
+ signer: context.permissionLevel,
162
+ }),
163
+ });
164
+ const json = await response.json();
165
+ // If the resource provider refused to process this request, return the original request without modification.
166
+ if (response.status === 400) {
167
+ return {
168
+ request,
169
+ };
170
+ }
171
+ const requiresPayment = response.status === 402;
172
+ if (requiresPayment) {
173
+ // If the resource provider offered transaction with a fee, but plugin doesn't allow fees, return the original transaction.
174
+ if (!this.allowFees) {
175
+ // TODO: Notify the script somehow of this, maybe we need an optional logger?
176
+ // Notify that a fee was required but not allowed via allowFees: false.
177
+ return {
178
+ request,
179
+ };
180
+ }
181
+ }
182
+ // Retrieve the transaction from the response
183
+ const modifiedTransaction = this.getModifiedTransaction(json);
184
+ // Ensure the new transaction has an unmodified version of the original action(s)
185
+ const originalActionsIntact = hasOriginalActions(request.getRawTransaction(), modifiedTransaction);
186
+ if (!originalActionsIntact) {
187
+ // TODO: Notify the script somehow of this, maybe we need an optional logger?
188
+ // Notify that the original actions requested were modified somehow, and reject the modification.
189
+ return {
190
+ request,
191
+ };
192
+ }
193
+ // Retrieve all newly appended actions from the modified transaction
194
+ const addedActions = getNewActions(request.getRawTransaction(), modifiedTransaction);
195
+ // TODO: Check that all the addedActions are allowed via this.allowActions
196
+ // Find any transfer actions that were added to the transaction, which we assume are fees
197
+ const addedFees = addedActions
198
+ .filter((action) => action.account.equals('eosio.token') && action.name.equals('transfer'))
199
+ .map((action) => Serializer.decode({
200
+ data: action.data,
201
+ type: Transfer,
202
+ }).quantity)
203
+ .reduce((total, fee) => {
204
+ total.units.add(fee.units);
205
+ return total;
206
+ }, Asset.from('0.0000 EOS'));
207
+ // If the resource provider offered transaction with a fee, but the fee was higher than allowed, return the original transaction.
208
+ if (this.maxFee) {
209
+ if (addedFees.units > this.maxFee.units) {
210
+ // TODO: Notify the script somehow of this, maybe we need an optional logger?
211
+ // Notify that a fee was required but higher than allowed via maxFee.
212
+ return {
213
+ request,
214
+ };
215
+ }
216
+ }
217
+ // Validate that the response is valid for the session.
218
+ await this.validateResponseData(json);
219
+ // NYI: Interact with interface via context for fee based prompting
220
+ /* Psuedo-code for fee based prompting
221
+
222
+ if (response.status === 402) {
223
+
224
+ // Prompt for the fee acceptance
225
+ const promptResponse = context.userPrompt({
226
+ title: 'Transaction Fee Required',
227
+ message: `This transaction requires a fee of ${response.json.data.fee} EOS. Do you wish to accept this fee?`,
228
+ })
229
+
230
+ // If the user did not accept the fee, return the original request without modification.
231
+ if (!promptResponse) {
232
+ return {
233
+ request,
234
+ }
235
+ }
236
+ } */
237
+ // Create a new signing request based on the response to return to the session's transact flow.
238
+ const modified = await this.createRequest(json, context);
239
+ // Return the modified transaction and additional signatures
240
+ return {
241
+ request: modified,
242
+ signatures: json.data.signatures.map((sig) => Signature.from(sig)),
243
+ };
244
+ }
245
+ getModifiedTransaction(json) {
246
+ switch (json.data.request[0]) {
247
+ case 'action':
248
+ throw new Error('A resource provider providing an "action" is not supported.');
249
+ case 'actions':
250
+ throw new Error('A resource provider providing "actions" is not supported.');
251
+ case 'transaction':
252
+ return Transaction.from(json.data.request[1]);
253
+ }
254
+ throw new Error('Invalid request type provided by resource provider.');
255
+ }
256
+ async createRequest(response, context) {
257
+ // Create a new signing request based on the response to return to the session's transact flow.
258
+ const request = await SigningRequest.create({ transaction: response.data.request[1] }, context.esrOptions);
259
+ // Set the required fee onto the request itself for wallets to process.
260
+ if (response.code === 402 && response.data.fee) {
261
+ request.setInfoKey('txfee', Asset.from(response.data.fee));
262
+ }
263
+ // If the fee costs exist, set them on the request for the signature provider to consume
264
+ if (response.data.costs) {
265
+ request.setInfoKey('txfeecpu', response.data.costs.cpu);
266
+ request.setInfoKey('txfeenet', response.data.costs.net);
267
+ request.setInfoKey('txfeeram', response.data.costs.ram);
268
+ }
269
+ return request;
270
+ }
271
+ /**
272
+ * Perform validation against the request to ensure it is valid for the resource provider.
273
+ */
274
+ validateRequest(request, context) {
275
+ // Retrieve first authorizer and ensure it matches session context.
276
+ const firstAction = request.getRawActions()[0];
277
+ const firstAuthorizer = firstAction.authorization[0];
278
+ if (!firstAuthorizer.actor.equals(context.permissionLevel.actor)) {
279
+ throw new Error('The first authorizer of the transaction does not match this session.');
280
+ }
281
+ }
282
+ /**
283
+ * Perform validation against the response to ensure it is valid for the session.
284
+ */
285
+ async validateResponseData(response) {
286
+ // If the data wasn't provided in the response, throw an error.
287
+ if (!response) {
288
+ throw new Error('Resource provider did not respond to the request.');
289
+ }
290
+ // If a malformed response with a fee was provided, throw an error.
291
+ if (response.code === 402 && !response.data.fee) {
292
+ throw new Error('Resource provider returned a response indicating required payment, but provided no fee amount.');
293
+ }
294
+ // If no signatures were provided, throw an error.
295
+ if (!response.data.signatures || !response.data.signatures[0]) {
296
+ throw new Error('Resource provider did not return a signature.');
297
+ }
298
+ }
299
+ }
300
+
301
+ export { Transfer, ResourceProviderPlugin as default };
302
+ //# sourceMappingURL=resource-provider-plugin.m.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-provider-plugin.m.js","sources":["../node_modules/tslib/tslib.es6.js","../src/utils.ts","../src/index.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n 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;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n",null,null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwCA;AACO,SAAS,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE;AAC1D,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;AACjI,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AACnI,SAAS,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;AACtJ,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,EAA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AC,CAAC,CAAC,CAAA;AACpD,QAAA,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE;AAC9D,YAAA,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAA;AAC1F,SAAA;KACJ;AACD;;AAEG;IACH,MAAM,oBAAoB,CAAC,QAA6B,EAAA;;QAEpD,IAAI,CAAC,QAAQ,EAAE;AACX,YAAA,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;AACvE,SAAA;;AAGD,QAAA,IAAI,QAAQ,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;AAC7C,YAAA,MAAM,IAAI,KAAK,CACX,gGAAgG,CACnG,CAAA;AACJ,SAAA;;AAGD,QAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;AAC3D,YAAA,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;AACnE,SAAA;KACJ;AACJ;;;;"}
@@ -0,0 +1,303 @@
1
+ var WharfKitResourceProviderPlugin = (function (exports, session, zlib) {
2
+ 'use strict';
3
+
4
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
5
+
6
+ var zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
7
+
8
+ /******************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
22
+
23
+ function __decorate(decorators, target, key, desc) {
24
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
25
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
26
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
27
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
28
+ }
29
+
30
+ function __awaiter(thisArg, _arguments, P, generator) {
31
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
+ return new (P || (P = Promise))(function (resolve, reject) {
33
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
37
+ });
38
+ }
39
+
40
+ function hasOriginalActions(original, modified) {
41
+ return original.actions.every((originalAction) => {
42
+ return modified.actions.some((modifiedAction) => {
43
+ // Ensure the original contract account matches
44
+ const matchesOriginalContractAccount = originalAction.account.equals(modifiedAction.account);
45
+ // Ensure the original contract action matches
46
+ const matchesOriginalContractAction = originalAction.name.equals(modifiedAction.name);
47
+ // Ensure the original authorization is in tact
48
+ const matchesOriginalAuthorization = originalAction.authorization.length === modifiedAction.authorization.length &&
49
+ originalAction.authorization[0].actor.equals(modifiedAction.authorization[0].actor);
50
+ // Ensure the original action data matches
51
+ const matchesOriginalActionData = originalAction.data.equals(modifiedAction.data);
52
+ // Return any action that does not match the original
53
+ return (matchesOriginalContractAccount &&
54
+ matchesOriginalContractAction &&
55
+ matchesOriginalAuthorization &&
56
+ matchesOriginalActionData);
57
+ });
58
+ });
59
+ }
60
+ function getNewActions(original, modified) {
61
+ return modified.actions.filter((modifiedAction) => {
62
+ return original.actions.some((originalAction) => {
63
+ // Ensure the original contract account matches
64
+ const matchesOriginalContractAccount = originalAction.account.equals(modifiedAction.account);
65
+ // Ensure the original contract action matches
66
+ const matchesOriginalContractAction = originalAction.name.equals(modifiedAction.name);
67
+ // Ensure the original authorization is in tact
68
+ const matchesOriginalAuthorization = originalAction.authorization.length === modifiedAction.authorization.length &&
69
+ originalAction.authorization[0].actor.equals(modifiedAction.authorization[0].actor);
70
+ // Ensure the original action data matches
71
+ const matchesOriginalActionData = originalAction.data.equals(modifiedAction.data);
72
+ // Return any action that does not match the original
73
+ return !(matchesOriginalContractAccount &&
74
+ matchesOriginalContractAction &&
75
+ matchesOriginalAuthorization &&
76
+ matchesOriginalActionData);
77
+ });
78
+ });
79
+ }
80
+
81
+ exports.Transfer = class Transfer extends session.Struct {
82
+ };
83
+ __decorate([
84
+ session.Struct.field(session.Name)
85
+ ], exports.Transfer.prototype, "from", void 0);
86
+ __decorate([
87
+ session.Struct.field(session.Name)
88
+ ], exports.Transfer.prototype, "to", void 0);
89
+ __decorate([
90
+ session.Struct.field(session.Asset)
91
+ ], exports.Transfer.prototype, "quantity", void 0);
92
+ __decorate([
93
+ session.Struct.field('string')
94
+ ], exports.Transfer.prototype, "memo", void 0);
95
+ exports.Transfer = __decorate([
96
+ session.Struct.type('transfer')
97
+ ], exports.Transfer);
98
+ class ResourceProviderPlugin extends session.AbstractTransactPlugin {
99
+ constructor(options) {
100
+ super();
101
+ this.allowFees = false;
102
+ if (typeof (options === null || options === void 0 ? void 0 : options.allowFees) !== 'undefined') {
103
+ this.allowFees = options.allowFees;
104
+ }
105
+ // TODO: Allow contact/action combos to be passed in and checked against to ensure no rogue actions were appended.
106
+ // if (typeof options.allowActions !== 'undefined') {
107
+ // this.allowActions = options.allowActions.map((action) => Name.from(action))
108
+ // }
109
+ if (typeof (options === null || options === void 0 ? void 0 : options.maxFee) !== 'undefined') {
110
+ this.maxFee = session.Asset.from(options.maxFee);
111
+ }
112
+ if (options === null || options === void 0 ? void 0 : options.url) {
113
+ this.url = options.url;
114
+ }
115
+ }
116
+ register(context) {
117
+ context.addHook(session.TransactHookTypes.beforeSign, (request, context) => this.request(request, context));
118
+ }
119
+ request(request, context) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ // Validate that this request is valid for the resource provider
122
+ this.validateRequest(request, context);
123
+ // Perform the request to the resource provider.
124
+ const response = yield context.fetch(this.url, {
125
+ method: 'POST',
126
+ body: JSON.stringify({
127
+ ref: 'unittest',
128
+ request,
129
+ signer: context.session,
130
+ }),
131
+ });
132
+ const json = yield response.json();
133
+ // If the resource provider refused to process this request, return the original request without modification.
134
+ if (response.status === 400) {
135
+ return {
136
+ request,
137
+ };
138
+ }
139
+ const requiresPayment = response.status === 402;
140
+ if (requiresPayment) {
141
+ // If the resource provider offered transaction with a fee, but plugin doesn't allow fees, return the original transaction.
142
+ if (!this.allowFees) {
143
+ // TODO: Notify the script somehow of this, maybe we need an optional logger?
144
+ // Notify that a fee was required but not allowed via allowFees: false.
145
+ return {
146
+ request,
147
+ };
148
+ }
149
+ }
150
+ // Retrieve the transaction from the response
151
+ const modifiedTransaction = this.getModifiedTransaction(json);
152
+ // Ensure the new transaction has an unmodified version of the original action(s)
153
+ const originalActionsIntact = hasOriginalActions(request.getRawTransaction(), modifiedTransaction);
154
+ if (!originalActionsIntact) {
155
+ // TODO: Notify the script somehow of this, maybe we need an optional logger?
156
+ // Notify that the original actions requested were modified somehow, and reject the modification.
157
+ return {
158
+ request,
159
+ };
160
+ }
161
+ // Retrieve all newly appended actions from the modified transaction
162
+ const addedActions = getNewActions(request.getRawTransaction(), modifiedTransaction);
163
+ // TODO: Check that all the addedActions are allowed via this.allowActions
164
+ // Find any transfer actions that were added to the transaction, which we assume are fees
165
+ const addedFees = addedActions
166
+ .filter((action) => action.account.equals('eosio.token') && action.name.equals('transfer'))
167
+ .map((action) => session.Serializer.decode({
168
+ data: action.data,
169
+ type: exports.Transfer,
170
+ }).quantity)
171
+ .reduce((total, fee) => {
172
+ total.units.add(fee.units);
173
+ return total;
174
+ }, session.Asset.from('0.0000 EOS'));
175
+ // If the resource provider offered transaction with a fee, but the fee was higher than allowed, return the original transaction.
176
+ if (this.maxFee) {
177
+ if (addedFees.units > this.maxFee.units) {
178
+ // TODO: Notify the script somehow of this, maybe we need an optional logger?
179
+ // Notify that a fee was required but higher than allowed via maxFee.
180
+ return {
181
+ request,
182
+ };
183
+ }
184
+ }
185
+ // Validate that the response is valid for the session.
186
+ yield this.validateResponseData(json);
187
+ // NYI: Interact with interface via context for fee based prompting
188
+ /* Psuedo-code for fee based prompting
189
+
190
+ if (response.status === 402) {
191
+
192
+ // Prompt for the fee acceptance
193
+ const promptResponse = context.userPrompt({
194
+ title: 'Transaction Fee Required',
195
+ message: `This transaction requires a fee of ${response.json.data.fee} EOS. Do you wish to accept this fee?`,
196
+ })
197
+
198
+ // If the user did not accept the fee, return the original request without modification.
199
+ if (!promptResponse) {
200
+ return {
201
+ request,
202
+ }
203
+ }
204
+ } */
205
+ // Create a new signing request based on the response to return to the session's transact flow.
206
+ const modified = yield this.createRequest(json, context);
207
+ // Return the modified transaction and additional signatures
208
+ return {
209
+ request: modified,
210
+ signatures: json.data.signatures.map((sig) => session.Signature.from(sig)),
211
+ };
212
+ });
213
+ }
214
+ getModifiedTransaction(json) {
215
+ switch (json.data.request[0]) {
216
+ case 'action':
217
+ throw new Error('A resource provider providing an "action" is not supported.');
218
+ case 'actions':
219
+ throw new Error('A resource provider providing "actions" is not supported.');
220
+ case 'transaction':
221
+ return session.Transaction.from(json.data.request[1]);
222
+ }
223
+ throw new Error('Invalid request type provided by resource provider.');
224
+ }
225
+ createRequest(response, context) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ // Establish an AbiProvider based on the session context.
228
+ const abiProvider = {
229
+ getAbi: (account) => __awaiter(this, void 0, void 0, function* () {
230
+ const response = yield context.client.v1.chain.get_abi(account);
231
+ if (!response.abi) {
232
+ /* istanbul ignore next */
233
+ throw new Error('could not load abi'); // TODO: Better coverage for this
234
+ }
235
+ return response.abi;
236
+ }),
237
+ };
238
+ // Create a new signing request based on the response to return to the session's transact flow.
239
+ const request = yield session.SigningRequest.create({ transaction: response.data.request[1] }, {
240
+ abiProvider,
241
+ zlib: zlib__default["default"],
242
+ });
243
+ // Set the required fee onto the request itself for wallets to process.
244
+ if (response.code === 402 && response.data.fee) {
245
+ request.setInfoKey('txfee', session.Asset.from(response.data.fee));
246
+ }
247
+ // If the fee costs exist, set them on the request for the signature provider to consume
248
+ if (response.data.costs) {
249
+ request.setInfoKey('txfeecpu', response.data.costs.cpu);
250
+ request.setInfoKey('txfeenet', response.data.costs.net);
251
+ request.setInfoKey('txfeeram', response.data.costs.ram);
252
+ }
253
+ return request;
254
+ });
255
+ }
256
+ /**
257
+ * Perform validation against the request to ensure it is valid for the resource provider.
258
+ */
259
+ validateRequest(request, context) {
260
+ // Retrieve first authorizer and ensure it matches session context.
261
+ const firstAction = request.getRawActions()[0];
262
+ const firstAuthorizer = firstAction.authorization[0];
263
+ if (!firstAuthorizer.actor.equals(context.session.actor)) {
264
+ throw new Error('The first authorizer of the transaction does not match this session.');
265
+ }
266
+ }
267
+ /**
268
+ * Perform validation against the response to ensure it is valid for the session.
269
+ */
270
+ validateResponseData(response) {
271
+ return __awaiter(this, void 0, void 0, function* () {
272
+ // If the data wasn't provided in the response, throw an error.
273
+ if (!response) {
274
+ throw new Error('Resource provider did not respond to the request.');
275
+ }
276
+ // If a malformed response with a fee was provided, throw an error.
277
+ if (response.code === 402 && !response.data.fee) {
278
+ throw new Error('Resource provider returned a response indicating required payment, but provided no fee amount.');
279
+ }
280
+ // If no signatures were provided, throw an error.
281
+ if (!response.data.signatures || !response.data.signatures[0]) {
282
+ throw new Error('Resource provider did not return a signature.');
283
+ }
284
+ });
285
+ }
286
+ }
287
+
288
+ exports["default"] = ResourceProviderPlugin;
289
+
290
+ Object.defineProperty(exports, '__esModule', { value: true });
291
+
292
+ return exports;
293
+
294
+ })({}, SessionKit, pako);
295
+
296
+ (function () {
297
+ var pkg = WharfKitResourceProviderPlugin;
298
+ WharfKitResourceProviderPlugin = pkg.default;
299
+ for (var key in pkg) {
300
+ if (key === 'default') continue;
301
+ WharfKitResourceProviderPlugin[key] = pkg[key];
302
+ }
303
+ })()