@taquito/beacon-wallet 24.2.0 → 24.3.0-beta.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.
@@ -1,400 +1,337 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ecadlabs/beacon-dapp'), require('@taquito/core'), require('typedarray-to-buffer'), require('@taquito/taquito'), require('@taquito/utils')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@ecadlabs/beacon-dapp', '@taquito/core', 'typedarray-to-buffer', '@taquito/taquito', '@taquito/utils'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoBeaconWallet = {}, global.beaconDapp, global.taquitoCore, global.typedarrayToBuffer, global.taquito, global.taquitoUtils));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ecadlabs/beacon-dapp'), require('@taquito/core'), require('typedarray-to-buffer'), require('@taquito/taquito'), require('@taquito/utils')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@ecadlabs/beacon-dapp', '@taquito/core', 'typedarray-to-buffer', '@taquito/taquito', '@taquito/utils'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoBeaconWallet = {}, global.beaconDapp, global.taquitoCore, global.typedarrayToBuffer, global.taquito, global.taquitoUtils));
5
5
  })(this, (function (exports, beaconDapp, core, toBuffer, taquito, utils) { 'use strict';
6
6
 
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
-
23
-
24
- function __awaiter(thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- }
33
-
34
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
- var e = new Error(message);
36
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
- };
7
+ /**
8
+ * @category Error
9
+ * Error that indicates the Beacon wallet not being initialized
10
+ */
11
+ class BeaconWalletNotInitialized extends core.PermissionDeniedError {
12
+ constructor() {
13
+ super();
14
+ this.name = 'BeaconWalletNotInitialized';
15
+ this.message =
16
+ 'BeaconWallet needs to be initialized by calling `await BeaconWallet.requestPermissions({network: {type: "chosen_network"}})` first.';
17
+ }
18
+ }
19
+ /**
20
+ * @category Error
21
+ * Error that indicates missing required permission scopes
22
+ */
23
+ class MissingRequiredScopes extends core.PermissionDeniedError {
24
+ constructor(requiredScopes) {
25
+ super();
26
+ this.requiredScopes = requiredScopes;
27
+ this.name = 'MissingRequiredScopes';
28
+ this.message = `Required permissions scopes: ${requiredScopes.join(',')} were not granted.`;
29
+ }
30
+ }
38
31
 
39
- /**
40
- * @category Error
41
- * @description Error that indicates the Beacon wallet not being initialized
42
- */
43
- class BeaconWalletNotInitialized extends core.PermissionDeniedError {
44
- constructor() {
45
- super();
46
- this.name = 'BeaconWalletNotInitialized';
47
- this.message =
48
- 'BeaconWallet needs to be initialized by calling `await BeaconWallet.requestPermissions({network: {type: "chosen_network"}})` first.';
49
- }
50
- }
51
- /**
52
- * @category Error
53
- * @description Error that indicates missing required permission scopes
54
- */
55
- class MissingRequiredScopes extends core.PermissionDeniedError {
56
- constructor(requiredScopes) {
57
- super();
58
- this.requiredScopes = requiredScopes;
59
- this.name = 'MissingRequiredScopes';
60
- this.message = `Required permissions scopes: ${requiredScopes.join(',')} were not granted.`;
61
- }
62
- }
32
+ // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
33
+ const VERSION = {
34
+ "commitHash": "27675679db6515e8b092195ef5c58c2c0ea5f5c8",
35
+ "version": "24.3.0-beta.0"
36
+ };
63
37
 
64
- // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
65
- const VERSION = {
66
- "commitHash": "105a7b15cfb862a0732c204e0e9741098d697775",
67
- "version": "24.2.0"
68
- };
38
+ /**
39
+ * @packageDocumentation
40
+ * @module @taquito/beacon-wallet
41
+ */
42
+ /**
43
+ * Default matrix relay nodes curated by Taquito.
44
+ *
45
+ * Includes only nodes operated by Papers and Trilitech running the latest
46
+ * Synapse version. These replace the Beacon SDK built-in defaults so that
47
+ * Taquito controls which relay infrastructure its users hit.
48
+ *
49
+ * The geographically distributed Papers nodes (NA-East, NA-West, Asia-East,
50
+ * Australia) have been decommissioned by Papers, so those regions are emptied
51
+ * to prevent connection attempts to dead servers.
52
+ *
53
+ * Users can still override specific regions (or the entire list) by passing
54
+ * their own `matrixNodes` in the BeaconWallet constructor options.
55
+ */
56
+ const TAQUITO_CURATED_MATRIX_NODES = {
57
+ [beaconDapp.Regions.EUROPE_WEST]: [
58
+ // Papers
59
+ 'beacon-node-1.diamond.papers.tech',
60
+ 'beacon-node-1.sky.papers.tech',
61
+ 'beacon-node-2.sky.papers.tech',
62
+ 'beacon-node-1.hope.papers.tech',
63
+ 'beacon-node-1.hope-2.papers.tech',
64
+ 'beacon-node-1.hope-3.papers.tech',
65
+ 'beacon-node-1.hope-4.papers.tech',
66
+ 'beacon-node-1.hope-5.papers.tech',
67
+ // Trilitech
68
+ 'beacon-node-1.octez.io',
69
+ 'beacon-node-2.octez.io',
70
+ 'beacon-node-3.octez.io',
71
+ 'beacon-node-4.octez.io',
72
+ 'beacon-node-5.octez.io',
73
+ 'beacon-node-6.octez.io',
74
+ 'beacon-node-7.octez.io',
75
+ 'beacon-node-8.octez.io',
76
+ ],
77
+ // Decommissioned by Papers; emptied to prevent connections to dead servers
78
+ [beaconDapp.Regions.NORTH_AMERICA_EAST]: [],
79
+ [beaconDapp.Regions.NORTH_AMERICA_WEST]: [],
80
+ [beaconDapp.Regions.ASIA_EAST]: [],
81
+ [beaconDapp.Regions.AUSTRALIA]: [],
82
+ };
83
+ class BeaconWallet {
84
+ constructor(options) {
85
+ const matrixNodes = {
86
+ ...TAQUITO_CURATED_MATRIX_NODES,
87
+ ...(options.matrixNodes ?? {}),
88
+ };
89
+ this.client = beaconDapp.getDAppClientInstance({ ...options, matrixNodes });
90
+ }
91
+ validateRequiredScopesOrFail(permissionScopes, requiredScopes) {
92
+ const mandatoryScope = new Set(requiredScopes);
93
+ for (const scope of permissionScopes) {
94
+ if (mandatoryScope.has(scope)) {
95
+ mandatoryScope.delete(scope);
96
+ }
97
+ }
98
+ if (mandatoryScope.size > 0) {
99
+ throw new MissingRequiredScopes(Array.from(mandatoryScope));
100
+ }
101
+ }
102
+ async requestPermissions(request) {
103
+ await this.client.requestPermissions(request);
104
+ }
105
+ async getPKH() {
106
+ const account = await this.client.getActiveAccount();
107
+ if (!account) {
108
+ throw new BeaconWalletNotInitialized();
109
+ }
110
+ return account.address;
111
+ }
112
+ async getPK() {
113
+ const account = await this.client.getActiveAccount();
114
+ if (!account) {
115
+ throw new BeaconWalletNotInitialized();
116
+ }
117
+ return account.publicKey ?? '';
118
+ }
119
+ async mapTransferParamsToWalletParams(params) {
120
+ let walletParams;
121
+ await this.client.showPrepare();
122
+ try {
123
+ walletParams = await params();
124
+ }
125
+ catch (err) {
126
+ await this.client.hideUI(['alert']);
127
+ throw err;
128
+ }
129
+ return this.removeDefaultParams(walletParams, await taquito.createTransferOperation(this.formatParameters(walletParams)));
130
+ }
131
+ async mapTransferTicketParamsToWalletParams(params) {
132
+ let walletParams;
133
+ await this.client.showPrepare();
134
+ try {
135
+ walletParams = await params();
136
+ }
137
+ catch (err) {
138
+ await this.client.hideUI(['alert']);
139
+ throw err;
140
+ }
141
+ return this.removeDefaultParams(walletParams, await taquito.createTransferTicketOperation(this.formatParameters(walletParams)));
142
+ }
143
+ async mapStakeParamsToWalletParams(params) {
144
+ let walletParams;
145
+ await this.client.showPrepare();
146
+ try {
147
+ walletParams = await params();
148
+ }
149
+ catch (err) {
150
+ await this.client.hideUI(['alert']);
151
+ throw err;
152
+ }
153
+ return this.removeDefaultParams(walletParams, await taquito.createTransferOperation(this.formatParameters(walletParams)));
154
+ }
155
+ async mapUnstakeParamsToWalletParams(params) {
156
+ let walletParams;
157
+ await this.client.showPrepare();
158
+ try {
159
+ walletParams = await params();
160
+ }
161
+ catch (err) {
162
+ await this.client.hideUI(['alert']);
163
+ throw err;
164
+ }
165
+ return this.removeDefaultParams(walletParams, await taquito.createTransferOperation(this.formatParameters(walletParams)));
166
+ }
167
+ async mapFinalizeUnstakeParamsToWalletParams(params) {
168
+ let walletParams;
169
+ await this.client.showPrepare();
170
+ try {
171
+ walletParams = await params();
172
+ }
173
+ catch (err) {
174
+ await this.client.hideUI(['alert']);
175
+ throw err;
176
+ }
177
+ return this.removeDefaultParams(walletParams, await taquito.createTransferOperation(this.formatParameters(walletParams)));
178
+ }
179
+ async mapIncreasePaidStorageWalletParams(params) {
180
+ let walletParams;
181
+ await this.client.showPrepare();
182
+ try {
183
+ walletParams = await params();
184
+ }
185
+ catch (err) {
186
+ await this.client.hideUI(['alert']);
187
+ throw err;
188
+ }
189
+ return this.removeDefaultParams(walletParams, await taquito.createIncreasePaidStorageOperation(this.formatParameters(walletParams)));
190
+ }
191
+ async mapOriginateParamsToWalletParams(params) {
192
+ let walletParams;
193
+ await this.client.showPrepare();
194
+ try {
195
+ walletParams = await params();
196
+ }
197
+ catch (err) {
198
+ await this.client.hideUI(['alert']);
199
+ throw err;
200
+ }
201
+ return this.removeDefaultParams(walletParams, await taquito.createOriginationOperation(this.formatParameters(walletParams)));
202
+ }
203
+ async mapDelegateParamsToWalletParams(params) {
204
+ let walletParams;
205
+ await this.client.showPrepare();
206
+ try {
207
+ walletParams = await params();
208
+ }
209
+ catch (err) {
210
+ await this.client.hideUI(['alert']);
211
+ throw err;
212
+ }
213
+ return this.removeDefaultParams(walletParams, await taquito.createSetDelegateOperation(this.formatParameters(walletParams)));
214
+ }
215
+ async mapRegisterGlobalConstantParamsToWalletParams(params) {
216
+ let walletParams;
217
+ await this.client.showPrepare();
218
+ try {
219
+ walletParams = await params();
220
+ }
221
+ catch (err) {
222
+ await this.client.hideUI(['alert']);
223
+ throw err;
224
+ }
225
+ return this.removeDefaultParams(walletParams, await taquito.createRegisterGlobalConstantOperation(this.formatParameters(walletParams)));
226
+ }
227
+ formatParameters(params) {
228
+ if (params.fee) {
229
+ params.fee = params.fee.toString();
230
+ }
231
+ if (params.storageLimit) {
232
+ params.storageLimit = params.storageLimit.toString();
233
+ }
234
+ if (params.gasLimit) {
235
+ params.gasLimit = params.gasLimit.toString();
236
+ }
237
+ return params;
238
+ }
239
+ removeDefaultParams(params, operatedParams) {
240
+ // If fee, storageLimit or gasLimit is undefined by user
241
+ // in case of beacon wallet, dont override it by
242
+ // defaults.
243
+ if (!params.fee) {
244
+ delete operatedParams.fee;
245
+ }
246
+ if (!params.storageLimit) {
247
+ delete operatedParams.storage_limit;
248
+ }
249
+ if (!params.gasLimit) {
250
+ delete operatedParams.gas_limit;
251
+ }
252
+ return operatedParams;
253
+ }
254
+ async sendOperations(params) {
255
+ const account = await this.client.getActiveAccount();
256
+ if (!account) {
257
+ throw new BeaconWalletNotInitialized();
258
+ }
259
+ const permissions = account.scopes;
260
+ this.validateRequiredScopesOrFail(permissions, [beaconDapp.PermissionScope.OPERATION_REQUEST]);
261
+ const { transactionHash } = await this.client.requestOperation({ operationDetails: params });
262
+ return transactionHash;
263
+ }
264
+ /**
265
+ * Disconnect the wallet and remove all Beacon data from localStorage.
266
+ *
267
+ * This is the recommended way to end a user session (logout). It calls
268
+ * `client.destroy()` under the hood, which clears the active account,
269
+ * cached relay node (`beacon:matrix-selected-node`), peer data, and all
270
+ * other `beacon:*` localStorage keys.
271
+ *
272
+ * After calling this method, the BeaconWallet instance is no longer usable.
273
+ * You must instantiate a new BeaconWallet to reconnect.
274
+ *
275
+ * For switching accounts without a full logout, use {@link clearActiveAccount} instead.
276
+ */
277
+ async disconnect() {
278
+ await this.client.destroy();
279
+ }
280
+ /**
281
+ * Clear the active account without destroying the Beacon session.
282
+ *
283
+ * This removes the active account reference from local storage but does
284
+ * **not** clear other Beacon state such as the cached relay node
285
+ * (`beacon:matrix-selected-node`) or peer data.
286
+ *
287
+ * Use this for switching between accounts within an active session.
288
+ * For a full logout that clears all Beacon storage, use {@link disconnect} instead.
289
+ *
290
+ * @see {@link disconnect}
291
+ */
292
+ async clearActiveAccount() {
293
+ await this.client.setActiveAccount();
294
+ }
295
+ async sign(bytes, watermark) {
296
+ let bb = utils.hex2buf(bytes);
297
+ if (typeof watermark !== 'undefined') {
298
+ bb = utils.mergebuf(watermark, bb);
299
+ }
300
+ const watermarkedBytes = utils.buf2hex(toBuffer(bb));
301
+ const signingType = this.getSigningType(watermark);
302
+ if (signingType !== beaconDapp.SigningType.OPERATION) {
303
+ throw new core.UnsupportedActionError(`Taquito Beacon Wallet currently only supports signing operations, not ${signingType}`);
304
+ }
305
+ const { signature } = await this.client.requestSignPayload({
306
+ payload: watermarkedBytes,
307
+ signingType,
308
+ });
309
+ return signature;
310
+ }
311
+ getSigningType(watermark) {
312
+ if (!watermark || watermark.length === 0) {
313
+ return beaconDapp.SigningType.RAW;
314
+ }
315
+ if (watermark.length === 1) {
316
+ if (watermark[0] === 5) {
317
+ return beaconDapp.SigningType.MICHELINE;
318
+ }
319
+ if (watermark[0] === 3) {
320
+ return beaconDapp.SigningType.OPERATION;
321
+ }
322
+ }
323
+ throw new Error(`Invalid watermark ${JSON.stringify(watermark)}`);
324
+ }
325
+ }
69
326
 
70
- /**
71
- * @packageDocumentation
72
- * @module @taquito/beacon-wallet
73
- */
74
- /**
75
- * Default matrix relay nodes curated by Taquito.
76
- *
77
- * Includes only nodes operated by Papers and Trilitech running the latest
78
- * Synapse version. These replace the Beacon SDK built-in defaults so that
79
- * Taquito controls which relay infrastructure its users hit.
80
- *
81
- * The geographically distributed Papers nodes (NA-East, NA-West, Asia-East,
82
- * Australia) have been decommissioned by Papers, so those regions are emptied
83
- * to prevent connection attempts to dead servers.
84
- *
85
- * Users can still override specific regions (or the entire list) by passing
86
- * their own `matrixNodes` in the BeaconWallet constructor options.
87
- */
88
- const TAQUITO_CURATED_MATRIX_NODES = {
89
- [beaconDapp.Regions.EUROPE_WEST]: [
90
- // Papers
91
- 'beacon-node-1.diamond.papers.tech',
92
- 'beacon-node-1.sky.papers.tech',
93
- 'beacon-node-2.sky.papers.tech',
94
- 'beacon-node-1.hope.papers.tech',
95
- 'beacon-node-1.hope-2.papers.tech',
96
- 'beacon-node-1.hope-3.papers.tech',
97
- 'beacon-node-1.hope-4.papers.tech',
98
- 'beacon-node-1.hope-5.papers.tech',
99
- // Trilitech
100
- 'beacon-node-1.octez.io',
101
- 'beacon-node-2.octez.io',
102
- 'beacon-node-3.octez.io',
103
- 'beacon-node-4.octez.io',
104
- 'beacon-node-5.octez.io',
105
- 'beacon-node-6.octez.io',
106
- 'beacon-node-7.octez.io',
107
- 'beacon-node-8.octez.io',
108
- ],
109
- // Decommissioned by Papers; emptied to prevent connections to dead servers
110
- [beaconDapp.Regions.NORTH_AMERICA_EAST]: [],
111
- [beaconDapp.Regions.NORTH_AMERICA_WEST]: [],
112
- [beaconDapp.Regions.ASIA_EAST]: [],
113
- [beaconDapp.Regions.AUSTRALIA]: [],
114
- };
115
- class BeaconWallet {
116
- constructor(options) {
117
- var _a;
118
- const matrixNodes = Object.assign(Object.assign({}, TAQUITO_CURATED_MATRIX_NODES), ((_a = options.matrixNodes) !== null && _a !== void 0 ? _a : {}));
119
- this.client = beaconDapp.getDAppClientInstance(Object.assign(Object.assign({}, options), { matrixNodes }));
120
- }
121
- validateRequiredScopesOrFail(permissionScopes, requiredScopes) {
122
- const mandatoryScope = new Set(requiredScopes);
123
- for (const scope of permissionScopes) {
124
- if (mandatoryScope.has(scope)) {
125
- mandatoryScope.delete(scope);
126
- }
127
- }
128
- if (mandatoryScope.size > 0) {
129
- throw new MissingRequiredScopes(Array.from(mandatoryScope));
130
- }
131
- }
132
- requestPermissions(request) {
133
- return __awaiter(this, void 0, void 0, function* () {
134
- yield this.client.requestPermissions(request);
135
- });
136
- }
137
- getPKH() {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- const account = yield this.client.getActiveAccount();
140
- if (!account) {
141
- throw new BeaconWalletNotInitialized();
142
- }
143
- return account.address;
144
- });
145
- }
146
- getPK() {
147
- return __awaiter(this, void 0, void 0, function* () {
148
- var _a;
149
- const account = yield this.client.getActiveAccount();
150
- if (!account) {
151
- throw new BeaconWalletNotInitialized();
152
- }
153
- return (_a = account.publicKey) !== null && _a !== void 0 ? _a : '';
154
- });
155
- }
156
- mapTransferParamsToWalletParams(params) {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- let walletParams;
159
- yield this.client.showPrepare();
160
- try {
161
- walletParams = yield params();
162
- }
163
- catch (err) {
164
- yield this.client.hideUI(['alert']);
165
- throw err;
166
- }
167
- return this.removeDefaultParams(walletParams, yield taquito.createTransferOperation(this.formatParameters(walletParams)));
168
- });
169
- }
170
- mapTransferTicketParamsToWalletParams(params) {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- let walletParams;
173
- yield this.client.showPrepare();
174
- try {
175
- walletParams = yield params();
176
- }
177
- catch (err) {
178
- yield this.client.hideUI(['alert']);
179
- throw err;
180
- }
181
- return this.removeDefaultParams(walletParams, yield taquito.createTransferTicketOperation(this.formatParameters(walletParams)));
182
- });
183
- }
184
- mapStakeParamsToWalletParams(params) {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- let walletParams;
187
- yield this.client.showPrepare();
188
- try {
189
- walletParams = yield params();
190
- }
191
- catch (err) {
192
- yield this.client.hideUI(['alert']);
193
- throw err;
194
- }
195
- return this.removeDefaultParams(walletParams, yield taquito.createTransferOperation(this.formatParameters(walletParams)));
196
- });
197
- }
198
- mapUnstakeParamsToWalletParams(params) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- let walletParams;
201
- yield this.client.showPrepare();
202
- try {
203
- walletParams = yield params();
204
- }
205
- catch (err) {
206
- yield this.client.hideUI(['alert']);
207
- throw err;
208
- }
209
- return this.removeDefaultParams(walletParams, yield taquito.createTransferOperation(this.formatParameters(walletParams)));
210
- });
211
- }
212
- mapFinalizeUnstakeParamsToWalletParams(params) {
213
- return __awaiter(this, void 0, void 0, function* () {
214
- let walletParams;
215
- yield this.client.showPrepare();
216
- try {
217
- walletParams = yield params();
218
- }
219
- catch (err) {
220
- yield this.client.hideUI(['alert']);
221
- throw err;
222
- }
223
- return this.removeDefaultParams(walletParams, yield taquito.createTransferOperation(this.formatParameters(walletParams)));
224
- });
225
- }
226
- mapIncreasePaidStorageWalletParams(params) {
227
- return __awaiter(this, void 0, void 0, function* () {
228
- let walletParams;
229
- yield this.client.showPrepare();
230
- try {
231
- walletParams = yield params();
232
- }
233
- catch (err) {
234
- yield this.client.hideUI(['alert']);
235
- throw err;
236
- }
237
- return this.removeDefaultParams(walletParams, yield taquito.createIncreasePaidStorageOperation(this.formatParameters(walletParams)));
238
- });
239
- }
240
- mapOriginateParamsToWalletParams(params) {
241
- return __awaiter(this, void 0, void 0, function* () {
242
- let walletParams;
243
- yield this.client.showPrepare();
244
- try {
245
- walletParams = yield params();
246
- }
247
- catch (err) {
248
- yield this.client.hideUI(['alert']);
249
- throw err;
250
- }
251
- return this.removeDefaultParams(walletParams, yield taquito.createOriginationOperation(this.formatParameters(walletParams)));
252
- });
253
- }
254
- mapDelegateParamsToWalletParams(params) {
255
- return __awaiter(this, void 0, void 0, function* () {
256
- let walletParams;
257
- yield this.client.showPrepare();
258
- try {
259
- walletParams = yield params();
260
- }
261
- catch (err) {
262
- yield this.client.hideUI(['alert']);
263
- throw err;
264
- }
265
- return this.removeDefaultParams(walletParams, yield taquito.createSetDelegateOperation(this.formatParameters(walletParams)));
266
- });
267
- }
268
- mapRegisterGlobalConstantParamsToWalletParams(params) {
269
- return __awaiter(this, void 0, void 0, function* () {
270
- let walletParams;
271
- yield this.client.showPrepare();
272
- try {
273
- walletParams = yield params();
274
- }
275
- catch (err) {
276
- yield this.client.hideUI(['alert']);
277
- throw err;
278
- }
279
- return this.removeDefaultParams(walletParams, yield taquito.createRegisterGlobalConstantOperation(this.formatParameters(walletParams)));
280
- });
281
- }
282
- formatParameters(params) {
283
- if (params.fee) {
284
- params.fee = params.fee.toString();
285
- }
286
- if (params.storageLimit) {
287
- params.storageLimit = params.storageLimit.toString();
288
- }
289
- if (params.gasLimit) {
290
- params.gasLimit = params.gasLimit.toString();
291
- }
292
- return params;
293
- }
294
- removeDefaultParams(params, operatedParams) {
295
- // If fee, storageLimit or gasLimit is undefined by user
296
- // in case of beacon wallet, dont override it by
297
- // defaults.
298
- if (!params.fee) {
299
- delete operatedParams.fee;
300
- }
301
- if (!params.storageLimit) {
302
- delete operatedParams.storage_limit;
303
- }
304
- if (!params.gasLimit) {
305
- delete operatedParams.gas_limit;
306
- }
307
- return operatedParams;
308
- }
309
- sendOperations(params) {
310
- return __awaiter(this, void 0, void 0, function* () {
311
- const account = yield this.client.getActiveAccount();
312
- if (!account) {
313
- throw new BeaconWalletNotInitialized();
314
- }
315
- const permissions = account.scopes;
316
- this.validateRequiredScopesOrFail(permissions, [beaconDapp.PermissionScope.OPERATION_REQUEST]);
317
- const { transactionHash } = yield this.client.requestOperation({ operationDetails: params });
318
- return transactionHash;
319
- });
320
- }
321
- /**
322
- * @description Disconnect the wallet and remove all Beacon data from localStorage.
323
- *
324
- * This is the recommended way to end a user session (logout). It calls
325
- * `client.destroy()` under the hood, which clears the active account,
326
- * cached relay node (`beacon:matrix-selected-node`), peer data, and all
327
- * other `beacon:*` localStorage keys.
328
- *
329
- * After calling this method, the BeaconWallet instance is no longer usable.
330
- * You must instantiate a new BeaconWallet to reconnect.
331
- *
332
- * For switching accounts without a full logout, use {@link clearActiveAccount} instead.
333
- */
334
- disconnect() {
335
- return __awaiter(this, void 0, void 0, function* () {
336
- yield this.client.destroy();
337
- });
338
- }
339
- /**
340
- * @description Clear the active account without destroying the Beacon session.
341
- *
342
- * This removes the active account reference from local storage but does
343
- * **not** clear other Beacon state such as the cached relay node
344
- * (`beacon:matrix-selected-node`) or peer data.
345
- *
346
- * Use this for switching between accounts within an active session.
347
- * For a full logout that clears all Beacon storage, use {@link disconnect} instead.
348
- *
349
- * @see {@link disconnect}
350
- */
351
- clearActiveAccount() {
352
- return __awaiter(this, void 0, void 0, function* () {
353
- yield this.client.setActiveAccount();
354
- });
355
- }
356
- sign(bytes, watermark) {
357
- return __awaiter(this, void 0, void 0, function* () {
358
- let bb = utils.hex2buf(bytes);
359
- if (typeof watermark !== 'undefined') {
360
- bb = utils.mergebuf(watermark, bb);
361
- }
362
- const watermarkedBytes = utils.buf2hex(toBuffer(bb));
363
- const signingType = this.getSigningType(watermark);
364
- if (signingType !== beaconDapp.SigningType.OPERATION) {
365
- throw new core.UnsupportedActionError(`Taquito Beacon Wallet currently only supports signing operations, not ${signingType}`);
366
- }
367
- const { signature } = yield this.client.requestSignPayload({
368
- payload: watermarkedBytes,
369
- signingType,
370
- });
371
- return signature;
372
- });
373
- }
374
- getSigningType(watermark) {
375
- if (!watermark || watermark.length === 0) {
376
- return beaconDapp.SigningType.RAW;
377
- }
378
- if (watermark.length === 1) {
379
- if (watermark[0] === 5) {
380
- return beaconDapp.SigningType.MICHELINE;
381
- }
382
- if (watermark[0] === 3) {
383
- return beaconDapp.SigningType.OPERATION;
384
- }
385
- }
386
- throw new Error(`Invalid watermark ${JSON.stringify(watermark)}`);
387
- }
388
- }
389
-
390
- Object.defineProperty(exports, "BeaconEvent", {
391
- enumerable: true,
392
- get: function () { return beaconDapp.BeaconEvent; }
393
- });
394
- exports.BeaconWallet = BeaconWallet;
395
- exports.BeaconWalletNotInitialized = BeaconWalletNotInitialized;
396
- exports.MissingRequiredScopes = MissingRequiredScopes;
397
- exports.VERSION = VERSION;
327
+ Object.defineProperty(exports, "BeaconEvent", {
328
+ enumerable: true,
329
+ get: function () { return beaconDapp.BeaconEvent; }
330
+ });
331
+ exports.BeaconWallet = BeaconWallet;
332
+ exports.BeaconWalletNotInitialized = BeaconWalletNotInitialized;
333
+ exports.MissingRequiredScopes = MissingRequiredScopes;
334
+ exports.VERSION = VERSION;
398
335
 
399
336
  }));
400
337
  //# sourceMappingURL=taquito-beacon-wallet.umd.js.map