@taquito/beacon-wallet 24.2.0 → 24.3.0-beta.1

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,45 +1,13 @@
1
- import { Regions, getDAppClientInstance, SigningType, PermissionScope } from '@ecadlabs/beacon-dapp';
1
+ import { Regions, getDAppClientInstance, PermissionScope, SigningType } from '@ecadlabs/beacon-dapp';
2
2
  export { BeaconEvent } from '@ecadlabs/beacon-dapp';
3
3
  import { PermissionDeniedError, UnsupportedActionError } from '@taquito/core';
4
4
  import toBuffer from 'typedarray-to-buffer';
5
5
  import { createTransferOperation, createTransferTicketOperation, createIncreasePaidStorageOperation, createOriginationOperation, createSetDelegateOperation, createRegisterGlobalConstantOperation } from '@taquito/taquito';
6
6
  import { hex2buf, mergebuf, buf2hex } from '@taquito/utils';
7
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
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
23
-
24
-
25
- function __awaiter(thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- }
34
-
35
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
36
- var e = new Error(message);
37
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
38
- };
39
-
40
8
  /**
41
9
  * @category Error
42
- * @description Error that indicates the Beacon wallet not being initialized
10
+ * Error that indicates the Beacon wallet not being initialized
43
11
  */
44
12
  class BeaconWalletNotInitialized extends PermissionDeniedError {
45
13
  constructor() {
@@ -51,7 +19,7 @@ class BeaconWalletNotInitialized extends PermissionDeniedError {
51
19
  }
52
20
  /**
53
21
  * @category Error
54
- * @description Error that indicates missing required permission scopes
22
+ * Error that indicates missing required permission scopes
55
23
  */
56
24
  class MissingRequiredScopes extends PermissionDeniedError {
57
25
  constructor(requiredScopes) {
@@ -64,8 +32,8 @@ class MissingRequiredScopes extends PermissionDeniedError {
64
32
 
65
33
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
66
34
  const VERSION = {
67
- "commitHash": "105a7b15cfb862a0732c204e0e9741098d697775",
68
- "version": "24.2.0"
35
+ "commitHash": "05df48fee92f846cba793920d6fa829afd6a1847",
36
+ "version": "24.3.0-beta.1"
69
37
  };
70
38
 
71
39
  /**
@@ -115,9 +83,11 @@ const TAQUITO_CURATED_MATRIX_NODES = {
115
83
  };
116
84
  class BeaconWallet {
117
85
  constructor(options) {
118
- var _a;
119
- const matrixNodes = Object.assign(Object.assign({}, TAQUITO_CURATED_MATRIX_NODES), ((_a = options.matrixNodes) !== null && _a !== void 0 ? _a : {}));
120
- this.client = getDAppClientInstance(Object.assign(Object.assign({}, options), { matrixNodes }));
86
+ const matrixNodes = {
87
+ ...TAQUITO_CURATED_MATRIX_NODES,
88
+ ...(options.matrixNodes ?? {}),
89
+ };
90
+ this.client = getDAppClientInstance({ ...options, matrixNodes });
121
91
  }
122
92
  validateRequiredScopesOrFail(permissionScopes, requiredScopes) {
123
93
  const mandatoryScope = new Set(requiredScopes);
@@ -130,155 +100,130 @@ class BeaconWallet {
130
100
  throw new MissingRequiredScopes(Array.from(mandatoryScope));
131
101
  }
132
102
  }
133
- requestPermissions(request) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- yield this.client.requestPermissions(request);
136
- });
103
+ async requestPermissions(request) {
104
+ await this.client.requestPermissions(request);
137
105
  }
138
- getPKH() {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- const account = yield this.client.getActiveAccount();
141
- if (!account) {
142
- throw new BeaconWalletNotInitialized();
143
- }
144
- return account.address;
145
- });
106
+ async getPKH() {
107
+ const account = await this.client.getActiveAccount();
108
+ if (!account) {
109
+ throw new BeaconWalletNotInitialized();
110
+ }
111
+ return account.address;
146
112
  }
147
- getPK() {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- var _a;
150
- const account = yield this.client.getActiveAccount();
151
- if (!account) {
152
- throw new BeaconWalletNotInitialized();
153
- }
154
- return (_a = account.publicKey) !== null && _a !== void 0 ? _a : '';
155
- });
113
+ async getPK() {
114
+ const account = await this.client.getActiveAccount();
115
+ if (!account) {
116
+ throw new BeaconWalletNotInitialized();
117
+ }
118
+ return account.publicKey ?? '';
156
119
  }
157
- mapTransferParamsToWalletParams(params) {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- let walletParams;
160
- yield this.client.showPrepare();
161
- try {
162
- walletParams = yield params();
163
- }
164
- catch (err) {
165
- yield this.client.hideUI(['alert']);
166
- throw err;
167
- }
168
- return this.removeDefaultParams(walletParams, yield createTransferOperation(this.formatParameters(walletParams)));
169
- });
120
+ async mapTransferParamsToWalletParams(params) {
121
+ let walletParams;
122
+ await this.client.showPrepare();
123
+ try {
124
+ walletParams = await params();
125
+ }
126
+ catch (err) {
127
+ await this.client.hideUI(['alert']);
128
+ throw err;
129
+ }
130
+ return this.removeDefaultParams(walletParams, await createTransferOperation(this.formatParameters(walletParams)));
170
131
  }
171
- mapTransferTicketParamsToWalletParams(params) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- let walletParams;
174
- yield this.client.showPrepare();
175
- try {
176
- walletParams = yield params();
177
- }
178
- catch (err) {
179
- yield this.client.hideUI(['alert']);
180
- throw err;
181
- }
182
- return this.removeDefaultParams(walletParams, yield createTransferTicketOperation(this.formatParameters(walletParams)));
183
- });
132
+ async mapTransferTicketParamsToWalletParams(params) {
133
+ let walletParams;
134
+ await this.client.showPrepare();
135
+ try {
136
+ walletParams = await params();
137
+ }
138
+ catch (err) {
139
+ await this.client.hideUI(['alert']);
140
+ throw err;
141
+ }
142
+ return this.removeDefaultParams(walletParams, await createTransferTicketOperation(this.formatParameters(walletParams)));
184
143
  }
185
- mapStakeParamsToWalletParams(params) {
186
- return __awaiter(this, void 0, void 0, function* () {
187
- let walletParams;
188
- yield this.client.showPrepare();
189
- try {
190
- walletParams = yield params();
191
- }
192
- catch (err) {
193
- yield this.client.hideUI(['alert']);
194
- throw err;
195
- }
196
- return this.removeDefaultParams(walletParams, yield createTransferOperation(this.formatParameters(walletParams)));
197
- });
144
+ async mapStakeParamsToWalletParams(params) {
145
+ let walletParams;
146
+ await this.client.showPrepare();
147
+ try {
148
+ walletParams = await params();
149
+ }
150
+ catch (err) {
151
+ await this.client.hideUI(['alert']);
152
+ throw err;
153
+ }
154
+ return this.removeDefaultParams(walletParams, await createTransferOperation(this.formatParameters(walletParams)));
198
155
  }
199
- mapUnstakeParamsToWalletParams(params) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- let walletParams;
202
- yield this.client.showPrepare();
203
- try {
204
- walletParams = yield params();
205
- }
206
- catch (err) {
207
- yield this.client.hideUI(['alert']);
208
- throw err;
209
- }
210
- return this.removeDefaultParams(walletParams, yield createTransferOperation(this.formatParameters(walletParams)));
211
- });
156
+ async mapUnstakeParamsToWalletParams(params) {
157
+ let walletParams;
158
+ await this.client.showPrepare();
159
+ try {
160
+ walletParams = await params();
161
+ }
162
+ catch (err) {
163
+ await this.client.hideUI(['alert']);
164
+ throw err;
165
+ }
166
+ return this.removeDefaultParams(walletParams, await createTransferOperation(this.formatParameters(walletParams)));
212
167
  }
213
- mapFinalizeUnstakeParamsToWalletParams(params) {
214
- return __awaiter(this, void 0, void 0, function* () {
215
- let walletParams;
216
- yield this.client.showPrepare();
217
- try {
218
- walletParams = yield params();
219
- }
220
- catch (err) {
221
- yield this.client.hideUI(['alert']);
222
- throw err;
223
- }
224
- return this.removeDefaultParams(walletParams, yield createTransferOperation(this.formatParameters(walletParams)));
225
- });
168
+ async mapFinalizeUnstakeParamsToWalletParams(params) {
169
+ let walletParams;
170
+ await this.client.showPrepare();
171
+ try {
172
+ walletParams = await params();
173
+ }
174
+ catch (err) {
175
+ await this.client.hideUI(['alert']);
176
+ throw err;
177
+ }
178
+ return this.removeDefaultParams(walletParams, await createTransferOperation(this.formatParameters(walletParams)));
226
179
  }
227
- mapIncreasePaidStorageWalletParams(params) {
228
- return __awaiter(this, void 0, void 0, function* () {
229
- let walletParams;
230
- yield this.client.showPrepare();
231
- try {
232
- walletParams = yield params();
233
- }
234
- catch (err) {
235
- yield this.client.hideUI(['alert']);
236
- throw err;
237
- }
238
- return this.removeDefaultParams(walletParams, yield createIncreasePaidStorageOperation(this.formatParameters(walletParams)));
239
- });
180
+ async mapIncreasePaidStorageWalletParams(params) {
181
+ let walletParams;
182
+ await this.client.showPrepare();
183
+ try {
184
+ walletParams = await params();
185
+ }
186
+ catch (err) {
187
+ await this.client.hideUI(['alert']);
188
+ throw err;
189
+ }
190
+ return this.removeDefaultParams(walletParams, await createIncreasePaidStorageOperation(this.formatParameters(walletParams)));
240
191
  }
241
- mapOriginateParamsToWalletParams(params) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- let walletParams;
244
- yield this.client.showPrepare();
245
- try {
246
- walletParams = yield params();
247
- }
248
- catch (err) {
249
- yield this.client.hideUI(['alert']);
250
- throw err;
251
- }
252
- return this.removeDefaultParams(walletParams, yield createOriginationOperation(this.formatParameters(walletParams)));
253
- });
192
+ async mapOriginateParamsToWalletParams(params) {
193
+ let walletParams;
194
+ await this.client.showPrepare();
195
+ try {
196
+ walletParams = await params();
197
+ }
198
+ catch (err) {
199
+ await this.client.hideUI(['alert']);
200
+ throw err;
201
+ }
202
+ return this.removeDefaultParams(walletParams, await createOriginationOperation(this.formatParameters(walletParams)));
254
203
  }
255
- mapDelegateParamsToWalletParams(params) {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- let walletParams;
258
- yield this.client.showPrepare();
259
- try {
260
- walletParams = yield params();
261
- }
262
- catch (err) {
263
- yield this.client.hideUI(['alert']);
264
- throw err;
265
- }
266
- return this.removeDefaultParams(walletParams, yield createSetDelegateOperation(this.formatParameters(walletParams)));
267
- });
204
+ async mapDelegateParamsToWalletParams(params) {
205
+ let walletParams;
206
+ await this.client.showPrepare();
207
+ try {
208
+ walletParams = await params();
209
+ }
210
+ catch (err) {
211
+ await this.client.hideUI(['alert']);
212
+ throw err;
213
+ }
214
+ return this.removeDefaultParams(walletParams, await createSetDelegateOperation(this.formatParameters(walletParams)));
268
215
  }
269
- mapRegisterGlobalConstantParamsToWalletParams(params) {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- let walletParams;
272
- yield this.client.showPrepare();
273
- try {
274
- walletParams = yield params();
275
- }
276
- catch (err) {
277
- yield this.client.hideUI(['alert']);
278
- throw err;
279
- }
280
- return this.removeDefaultParams(walletParams, yield createRegisterGlobalConstantOperation(this.formatParameters(walletParams)));
281
- });
216
+ async mapRegisterGlobalConstantParamsToWalletParams(params) {
217
+ let walletParams;
218
+ await this.client.showPrepare();
219
+ try {
220
+ walletParams = await params();
221
+ }
222
+ catch (err) {
223
+ await this.client.hideUI(['alert']);
224
+ throw err;
225
+ }
226
+ return this.removeDefaultParams(walletParams, await createRegisterGlobalConstantOperation(this.formatParameters(walletParams)));
282
227
  }
283
228
  formatParameters(params) {
284
229
  if (params.fee) {
@@ -307,20 +252,18 @@ class BeaconWallet {
307
252
  }
308
253
  return operatedParams;
309
254
  }
310
- sendOperations(params) {
311
- return __awaiter(this, void 0, void 0, function* () {
312
- const account = yield this.client.getActiveAccount();
313
- if (!account) {
314
- throw new BeaconWalletNotInitialized();
315
- }
316
- const permissions = account.scopes;
317
- this.validateRequiredScopesOrFail(permissions, [PermissionScope.OPERATION_REQUEST]);
318
- const { transactionHash } = yield this.client.requestOperation({ operationDetails: params });
319
- return transactionHash;
320
- });
255
+ async sendOperations(params) {
256
+ const account = await this.client.getActiveAccount();
257
+ if (!account) {
258
+ throw new BeaconWalletNotInitialized();
259
+ }
260
+ const permissions = account.scopes;
261
+ this.validateRequiredScopesOrFail(permissions, [PermissionScope.OPERATION_REQUEST]);
262
+ const { transactionHash } = await this.client.requestOperation({ operationDetails: params });
263
+ return transactionHash;
321
264
  }
322
265
  /**
323
- * @description Disconnect the wallet and remove all Beacon data from localStorage.
266
+ * Disconnect the wallet and remove all Beacon data from localStorage.
324
267
  *
325
268
  * This is the recommended way to end a user session (logout). It calls
326
269
  * `client.destroy()` under the hood, which clears the active account,
@@ -332,13 +275,11 @@ class BeaconWallet {
332
275
  *
333
276
  * For switching accounts without a full logout, use {@link clearActiveAccount} instead.
334
277
  */
335
- disconnect() {
336
- return __awaiter(this, void 0, void 0, function* () {
337
- yield this.client.destroy();
338
- });
278
+ async disconnect() {
279
+ await this.client.destroy();
339
280
  }
340
281
  /**
341
- * @description Clear the active account without destroying the Beacon session.
282
+ * Clear the active account without destroying the Beacon session.
342
283
  *
343
284
  * This removes the active account reference from local storage but does
344
285
  * **not** clear other Beacon state such as the cached relay node
@@ -349,28 +290,24 @@ class BeaconWallet {
349
290
  *
350
291
  * @see {@link disconnect}
351
292
  */
352
- clearActiveAccount() {
353
- return __awaiter(this, void 0, void 0, function* () {
354
- yield this.client.setActiveAccount();
355
- });
293
+ async clearActiveAccount() {
294
+ await this.client.setActiveAccount();
356
295
  }
357
- sign(bytes, watermark) {
358
- return __awaiter(this, void 0, void 0, function* () {
359
- let bb = hex2buf(bytes);
360
- if (typeof watermark !== 'undefined') {
361
- bb = mergebuf(watermark, bb);
362
- }
363
- const watermarkedBytes = buf2hex(toBuffer(bb));
364
- const signingType = this.getSigningType(watermark);
365
- if (signingType !== SigningType.OPERATION) {
366
- throw new UnsupportedActionError(`Taquito Beacon Wallet currently only supports signing operations, not ${signingType}`);
367
- }
368
- const { signature } = yield this.client.requestSignPayload({
369
- payload: watermarkedBytes,
370
- signingType,
371
- });
372
- return signature;
296
+ async sign(bytes, watermark) {
297
+ let bb = hex2buf(bytes);
298
+ if (typeof watermark !== 'undefined') {
299
+ bb = mergebuf(watermark, bb);
300
+ }
301
+ const watermarkedBytes = buf2hex(toBuffer(bb));
302
+ const signingType = this.getSigningType(watermark);
303
+ if (signingType !== SigningType.OPERATION) {
304
+ throw new UnsupportedActionError(`Taquito Beacon Wallet currently only supports signing operations, not ${signingType}`);
305
+ }
306
+ const { signature } = await this.client.requestSignPayload({
307
+ payload: watermarkedBytes,
308
+ signingType,
373
309
  });
310
+ return signature;
374
311
  }
375
312
  getSigningType(watermark) {
376
313
  if (!watermark || watermark.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-beacon-wallet.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"taquito-beacon-wallet.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}