@taquito/wallet-connect 20.2.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.
- package/LICENSE +202 -0
- package/README.md +62 -0
- package/dist/lib/errors.js +147 -0
- package/dist/lib/taquito-wallet-connect.js +530 -0
- package/dist/lib/types.js +29 -0
- package/dist/lib/version.js +8 -0
- package/dist/taquito-wallet-connect.es6.js +695 -0
- package/dist/taquito-wallet-connect.es6.js.map +1 -0
- package/dist/taquito-wallet-connect.umd.js +710 -0
- package/dist/taquito-wallet-connect.umd.js.map +1 -0
- package/dist/types/errors.d.ts +103 -0
- package/dist/types/taquito-wallet-connect.d.ts +147 -0
- package/dist/types/types.d.ts +63 -0
- package/dist/types/version.d.ts +4 -0
- package/package.json +106 -0
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
* @module @taquito/wallet-connect
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.WalletConnect = void 0;
|
|
31
|
+
const sign_client_1 = require("@walletconnect/sign-client");
|
|
32
|
+
const legacy_modal_1 = require("@walletconnect/legacy-modal");
|
|
33
|
+
const taquito_1 = require("@taquito/taquito");
|
|
34
|
+
const utils_1 = require("@walletconnect/utils");
|
|
35
|
+
const types_1 = require("./types");
|
|
36
|
+
const errors_1 = require("./errors");
|
|
37
|
+
__exportStar(require("./errors"), exports);
|
|
38
|
+
__exportStar(require("./types"), exports);
|
|
39
|
+
const TEZOS_PLACEHOLDER = 'tezos';
|
|
40
|
+
/**
|
|
41
|
+
* @description The `WalletConnect` class implements the `WalletProvider` interface, providing an alternative to `BeaconWallet`.
|
|
42
|
+
* This package enables dapps built with Taquito to connect to wallets via the WalletConnect/Reown protocol.
|
|
43
|
+
* @note Currently, a QR code is displayed to establish a connection with a wallet. As more Tezos wallets integrate with WalletConnect,
|
|
44
|
+
* we plan showing a list of available wallets alongside the QR code.
|
|
45
|
+
*/
|
|
46
|
+
class WalletConnect {
|
|
47
|
+
constructor(signClient) {
|
|
48
|
+
this.signClient = signClient;
|
|
49
|
+
this.signClient.on('session_delete', ({ topic }) => {
|
|
50
|
+
var _a;
|
|
51
|
+
if (((_a = this.session) === null || _a === void 0 ? void 0 : _a.topic) === topic) {
|
|
52
|
+
this.session = undefined;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.signClient.on('session_expire', ({ topic }) => {
|
|
56
|
+
var _a;
|
|
57
|
+
if (((_a = this.session) === null || _a === void 0 ? void 0 : _a.topic) === topic) {
|
|
58
|
+
this.session = undefined;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
this.signClient.on('session_update', ({ params, topic }) => {
|
|
62
|
+
var _a;
|
|
63
|
+
if (((_a = this.session) === null || _a === void 0 ? void 0 : _a.topic) === topic) {
|
|
64
|
+
this.session.namespaces = params.namespaces;
|
|
65
|
+
// TODO determine if we need validation on the namespace here
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
this.signClient.on('session_event', () => {
|
|
69
|
+
// TODO Do we need to handle other session events, such as "chainChanged", "accountsChanged", etc.
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @description Initialize a WalletConnect provider
|
|
74
|
+
* (Initialize a WalletConnect client with persisted storage and a network connection)
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```
|
|
78
|
+
* await WalletConnect.init({
|
|
79
|
+
* projectId: "YOUR_PROJECT_ID", // can get YOUR_PROJECT_ID from [Reown Cloud](https://cloud.reown.com)
|
|
80
|
+
* metadata: {
|
|
81
|
+
* name: "YOUR_DAPP_NAME",
|
|
82
|
+
* description: "YOUR_DAPP_DESCRIPTION",
|
|
83
|
+
* icons: ["ICON_URL"],
|
|
84
|
+
* url: "DAPP_URL",
|
|
85
|
+
* },
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
static init(initParams) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const client = yield sign_client_1.default.init(initParams);
|
|
92
|
+
return new WalletConnect(client);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @description Request permission for a new session and establish a connection.
|
|
97
|
+
*
|
|
98
|
+
* @param connectParams.permissionScope The networks, methods, and events that will be granted permission
|
|
99
|
+
* @param connectParams.pairingTopic Option to connect to an existing active pairing. If pairingTopic is defined, a prompt will appear in the corresponding wallet to accept or decline the session proposal. If no pairingTopic, a QR code modal will open in the dapp, allowing to connect to a wallet.
|
|
100
|
+
* @param connectParams.registryUrl Optional registry of wallet deep links to show in the Modal
|
|
101
|
+
* @error ConnectionFailed is thrown if no connection can be established with a wallet
|
|
102
|
+
*/
|
|
103
|
+
requestPermissions(connectParams) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
var _a;
|
|
106
|
+
// TODO when Tezos wallets will officially support wallet connect, we need to provide a default value for registryUrl
|
|
107
|
+
try {
|
|
108
|
+
const { uri, approval } = yield this.signClient.connect({
|
|
109
|
+
requiredNamespaces: {
|
|
110
|
+
[TEZOS_PLACEHOLDER]: {
|
|
111
|
+
chains: connectParams.permissionScope.networks.map((network) => `${TEZOS_PLACEHOLDER}:${network}`),
|
|
112
|
+
methods: connectParams.permissionScope.methods,
|
|
113
|
+
events: (_a = connectParams.permissionScope.events) !== null && _a !== void 0 ? _a : [],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
pairingTopic: connectParams.pairingTopic,
|
|
117
|
+
});
|
|
118
|
+
if (uri) {
|
|
119
|
+
legacy_modal_1.default.open(uri, () => { }, { registryUrl: connectParams.registryUrl });
|
|
120
|
+
}
|
|
121
|
+
this.session = yield approval();
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new errors_1.ConnectionFailed(error);
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
legacy_modal_1.default.close();
|
|
128
|
+
}
|
|
129
|
+
this.validateReceivedNamespace(connectParams.permissionScope, this.session.namespaces);
|
|
130
|
+
this.setDefaultAccountAndNetwork();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @description Access all existing active pairings
|
|
135
|
+
*/
|
|
136
|
+
getAvailablePairing() {
|
|
137
|
+
return this.signClient.pairing.getAll({ active: true });
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @description Access all existing sessions
|
|
141
|
+
* @return an array of strings which represent the session keys
|
|
142
|
+
*/
|
|
143
|
+
getAllExistingSessionKeys() {
|
|
144
|
+
return this.signClient.session.keys;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @description Configure the Client with an existing session.
|
|
148
|
+
* The session is immediately restored without a prompt on the wallet to accept/decline it.
|
|
149
|
+
* @error InvalidSessionKey is thrown if the provided session key doesn't exist
|
|
150
|
+
*/
|
|
151
|
+
configureWithExistingSessionKey(key) {
|
|
152
|
+
const sessions = this.getAllExistingSessionKeys();
|
|
153
|
+
if (!sessions.includes(key)) {
|
|
154
|
+
throw new errors_1.InvalidSessionKey(key);
|
|
155
|
+
}
|
|
156
|
+
this.session = this.signClient.session.get(key);
|
|
157
|
+
this.setDefaultAccountAndNetwork();
|
|
158
|
+
}
|
|
159
|
+
disconnect() {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
if (this.session) {
|
|
162
|
+
yield this.signClient.disconnect({
|
|
163
|
+
topic: this.session.topic,
|
|
164
|
+
reason: (0, utils_1.getSdkError)('USER_DISCONNECTED'),
|
|
165
|
+
});
|
|
166
|
+
this.clearState();
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
getPeerMetadata() {
|
|
171
|
+
return this.getSession().peer.metadata;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @description Once the session is establish, send Tezos operations to be approved, signed and inject by the wallet.
|
|
175
|
+
* @error MissingRequiredScope is thrown if permission to send operation was not granted
|
|
176
|
+
*/
|
|
177
|
+
sendOperations(params) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
const session = this.getSession();
|
|
180
|
+
if (!this.getPermittedMethods().includes(types_1.PermissionScopeMethods.TEZOS_SEND)) {
|
|
181
|
+
throw new errors_1.MissingRequiredScope(types_1.PermissionScopeMethods.TEZOS_SEND);
|
|
182
|
+
}
|
|
183
|
+
const network = this.getActiveNetwork();
|
|
184
|
+
const account = yield this.getPKH();
|
|
185
|
+
this.validateNetworkAndAccount(network, account);
|
|
186
|
+
const { operationHash } = yield this.signClient.request({
|
|
187
|
+
topic: session.topic,
|
|
188
|
+
chainId: `${TEZOS_PLACEHOLDER}:${network}`,
|
|
189
|
+
request: {
|
|
190
|
+
method: types_1.PermissionScopeMethods.TEZOS_SEND,
|
|
191
|
+
params: {
|
|
192
|
+
account,
|
|
193
|
+
operations: params,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
return operationHash;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* @description Once the session is establish, send payload to be signed by the wallet.
|
|
202
|
+
* @error MissingRequiredScope is thrown if permission to sign payload was not granted
|
|
203
|
+
*/
|
|
204
|
+
sign(bytes, watermark) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
const session = this.getSession();
|
|
207
|
+
if (!this.getPermittedMethods().includes(types_1.PermissionScopeMethods.TEZOS_SIGN)) {
|
|
208
|
+
throw new errors_1.MissingRequiredScope(types_1.PermissionScopeMethods.TEZOS_SIGN);
|
|
209
|
+
}
|
|
210
|
+
const network = this.getActiveNetwork();
|
|
211
|
+
const account = yield this.getPKH();
|
|
212
|
+
this.validateNetworkAndAccount(network, account);
|
|
213
|
+
let expression = bytes;
|
|
214
|
+
if (watermark) {
|
|
215
|
+
expression =
|
|
216
|
+
Array.from(watermark, (byte) => byte.toString(16).padStart(2, '0')).join('') + expression;
|
|
217
|
+
}
|
|
218
|
+
const { signature } = yield this.signClient.request({
|
|
219
|
+
topic: session.topic,
|
|
220
|
+
chainId: `${TEZOS_PLACEHOLDER}:${network}`,
|
|
221
|
+
request: {
|
|
222
|
+
method: types_1.PermissionScopeMethods.TEZOS_SIGN,
|
|
223
|
+
params: {
|
|
224
|
+
account: yield this.getPKH(),
|
|
225
|
+
payload: expression,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
return signature;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @description Return all connected accounts from the active session
|
|
234
|
+
* @error NotConnected if no active session
|
|
235
|
+
*/
|
|
236
|
+
getAccounts() {
|
|
237
|
+
return this.getTezosNamespace().accounts.map((account) => account.split(':')[2]);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @description Set the active account.
|
|
241
|
+
* Must be called if there are multiple accounts in the session and every time the active account is switched
|
|
242
|
+
* @param pkh public key hash of the selected account
|
|
243
|
+
* @error InvalidAccount thrown if the pkh is not part of the active accounts in the session
|
|
244
|
+
*/
|
|
245
|
+
setActiveAccount(pkh) {
|
|
246
|
+
if (!this.getAccounts().includes(pkh)) {
|
|
247
|
+
throw new errors_1.InvalidAccount(pkh);
|
|
248
|
+
}
|
|
249
|
+
this.activeAccount = pkh;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @description Access the public key hash of the active account
|
|
253
|
+
* @error ActiveAccountUnspecified thrown when there are multiple Tezos account in the session and none is set as the active one
|
|
254
|
+
*/
|
|
255
|
+
getPKH() {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
if (!this.activeAccount) {
|
|
258
|
+
this.getSession();
|
|
259
|
+
throw new errors_1.ActiveAccountUnspecified();
|
|
260
|
+
}
|
|
261
|
+
return this.activeAccount;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* @description Access the public key of the active account
|
|
266
|
+
* @error ActiveAccountUnspecified thrown when there are multiple Tezos account in the session and none is set as the active one
|
|
267
|
+
* @error MissingRequiredScope is thrown if permission to get accounts was not granted
|
|
268
|
+
* @error PublicKeyRetrievalError is thrown if the public key is not found
|
|
269
|
+
*/
|
|
270
|
+
getPK() {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
const session = this.getSession();
|
|
273
|
+
if (!this.getPermittedMethods().includes(types_1.PermissionScopeMethods.TEZOS_GET_ACCOUNTS)) {
|
|
274
|
+
throw new errors_1.MissingRequiredScope(types_1.PermissionScopeMethods.TEZOS_GET_ACCOUNTS);
|
|
275
|
+
}
|
|
276
|
+
const network = this.getActiveNetwork();
|
|
277
|
+
const account = yield this.getPKH();
|
|
278
|
+
const accounts = yield this.signClient.request({
|
|
279
|
+
topic: session.topic,
|
|
280
|
+
chainId: `${TEZOS_PLACEHOLDER}:${network}`,
|
|
281
|
+
request: {
|
|
282
|
+
method: types_1.PermissionScopeMethods.TEZOS_GET_ACCOUNTS,
|
|
283
|
+
params: {},
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
const selectedAccount = accounts.find((acc) => acc.address === account);
|
|
287
|
+
if (!selectedAccount) {
|
|
288
|
+
throw new errors_1.PublicKeyRetrievalError();
|
|
289
|
+
}
|
|
290
|
+
return selectedAccount.pubkey;
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* @description Return all networks from the namespace of the active session
|
|
295
|
+
* @error NotConnected if no active session
|
|
296
|
+
*/
|
|
297
|
+
getNetworks() {
|
|
298
|
+
return this.getPermittedNetwork();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* @description Set the active network.
|
|
302
|
+
* Must be called if there are multiple network in the session and every time the active network is switched
|
|
303
|
+
* @param network selected network
|
|
304
|
+
* @error InvalidNetwork thrown if the network is not part of the active networks in the session
|
|
305
|
+
*/
|
|
306
|
+
setActiveNetwork(network) {
|
|
307
|
+
if (!this.getNetworks().includes(network)) {
|
|
308
|
+
throw new errors_1.InvalidNetwork(network);
|
|
309
|
+
}
|
|
310
|
+
this.activeNetwork = network;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* @description Access the active network
|
|
314
|
+
* @error ActiveNetworkUnspecified thorwn when there are multiple Tezos netwroks in the session and none is set as the active one
|
|
315
|
+
*/
|
|
316
|
+
getActiveNetwork() {
|
|
317
|
+
if (!this.activeNetwork) {
|
|
318
|
+
this.getSession();
|
|
319
|
+
throw new errors_1.ActiveNetworkUnspecified();
|
|
320
|
+
}
|
|
321
|
+
return this.activeNetwork;
|
|
322
|
+
}
|
|
323
|
+
setDefaultAccountAndNetwork() {
|
|
324
|
+
const activeAccount = this.getAccounts();
|
|
325
|
+
if (activeAccount.length === 1) {
|
|
326
|
+
this.activeAccount = activeAccount[0];
|
|
327
|
+
}
|
|
328
|
+
const activeNetwork = this.getNetworks();
|
|
329
|
+
if (activeNetwork.length === 1) {
|
|
330
|
+
this.activeNetwork = activeNetwork[0];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
clearState() {
|
|
334
|
+
this.session = undefined;
|
|
335
|
+
this.activeAccount = undefined;
|
|
336
|
+
this.activeNetwork = undefined;
|
|
337
|
+
}
|
|
338
|
+
getSession() {
|
|
339
|
+
if (!this.session) {
|
|
340
|
+
throw new errors_1.NotConnected();
|
|
341
|
+
}
|
|
342
|
+
return this.session;
|
|
343
|
+
}
|
|
344
|
+
isActiveSession() {
|
|
345
|
+
return this.session ? true : false;
|
|
346
|
+
}
|
|
347
|
+
ping() {
|
|
348
|
+
this.signClient.ping({ topic: this.getSession().topic });
|
|
349
|
+
}
|
|
350
|
+
// https://docs.reown.com/api/sign/wallet-usage#namespaces
|
|
351
|
+
// TODO: add validations related to Namespaces extensions and related unit tests:
|
|
352
|
+
validateReceivedNamespace(scope, receivedNamespaces) {
|
|
353
|
+
if (receivedNamespaces[TEZOS_PLACEHOLDER]) {
|
|
354
|
+
this.validateMethods(scope.methods, receivedNamespaces[TEZOS_PLACEHOLDER].methods);
|
|
355
|
+
if (scope.events) {
|
|
356
|
+
this.validateEvents(scope.events, receivedNamespaces['tezos'].events);
|
|
357
|
+
}
|
|
358
|
+
this.validateAccounts(scope.networks, receivedNamespaces[TEZOS_PLACEHOLDER].accounts);
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
this.clearState();
|
|
362
|
+
throw new errors_1.InvalidReceivedSessionNamespace('All namespaces must be approved', (0, utils_1.getSdkError)('USER_REJECTED').code, 'incomplete', 'tezos');
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
validateMethods(requiredMethods, receivedMethods) {
|
|
366
|
+
const missingMethods = [];
|
|
367
|
+
requiredMethods.forEach((method) => {
|
|
368
|
+
if (!receivedMethods.includes(method)) {
|
|
369
|
+
missingMethods.push(method);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
if (missingMethods.length > 0) {
|
|
373
|
+
this.clearState();
|
|
374
|
+
throw new errors_1.InvalidReceivedSessionNamespace('All methods must be approved', (0, utils_1.getSdkError)('USER_REJECTED_METHODS').code, 'incomplete', missingMethods);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
validateEvents(requiredEvents, receivedEvents) {
|
|
378
|
+
const missingEvents = [];
|
|
379
|
+
requiredEvents.forEach((method) => {
|
|
380
|
+
if (!receivedEvents.includes(method)) {
|
|
381
|
+
missingEvents.push(method);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
if (missingEvents.length > 0) {
|
|
385
|
+
this.clearState();
|
|
386
|
+
throw new errors_1.InvalidReceivedSessionNamespace('All events must be approved', (0, utils_1.getSdkError)('USER_REJECTED_EVENTS').code, 'incomplete', missingEvents);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
validateAccounts(requiredNetwork, receivedAccounts) {
|
|
390
|
+
if (receivedAccounts.length === 0) {
|
|
391
|
+
this.clearState();
|
|
392
|
+
throw new errors_1.InvalidReceivedSessionNamespace('Accounts must not be empty', (0, utils_1.getSdkError)('USER_REJECTED_CHAINS').code, 'incomplete');
|
|
393
|
+
}
|
|
394
|
+
const receivedChains = [];
|
|
395
|
+
const invalidChains = [];
|
|
396
|
+
const missingChains = [];
|
|
397
|
+
const invalidChainsNamespace = [];
|
|
398
|
+
receivedAccounts.forEach((chain) => {
|
|
399
|
+
const accountId = chain.split(':');
|
|
400
|
+
if (accountId.length !== 3) {
|
|
401
|
+
invalidChains.push(chain);
|
|
402
|
+
}
|
|
403
|
+
if (accountId[0] !== TEZOS_PLACEHOLDER) {
|
|
404
|
+
invalidChainsNamespace.push(chain);
|
|
405
|
+
}
|
|
406
|
+
const network = accountId[1];
|
|
407
|
+
if (!receivedChains.includes(network)) {
|
|
408
|
+
receivedChains.push(network);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
if (invalidChains.length > 0) {
|
|
412
|
+
this.clearState();
|
|
413
|
+
throw new errors_1.InvalidReceivedSessionNamespace('Accounts must be CAIP-10 compliant', (0, utils_1.getSdkError)('USER_REJECTED_CHAINS').code, 'invalid', invalidChains);
|
|
414
|
+
}
|
|
415
|
+
if (invalidChainsNamespace.length > 0) {
|
|
416
|
+
this.clearState();
|
|
417
|
+
throw new errors_1.InvalidReceivedSessionNamespace('Accounts must be defined in matching namespace', (0, utils_1.getSdkError)('UNSUPPORTED_ACCOUNTS').code, 'invalid', invalidChainsNamespace);
|
|
418
|
+
}
|
|
419
|
+
requiredNetwork.forEach((network) => {
|
|
420
|
+
if (!receivedChains.includes(network)) {
|
|
421
|
+
missingChains.push(network);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
if (missingChains.length > 0) {
|
|
425
|
+
this.clearState();
|
|
426
|
+
throw new errors_1.InvalidReceivedSessionNamespace('All chains must have at least one account', (0, utils_1.getSdkError)('USER_REJECTED_CHAINS').code, 'incomplete', missingChains);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
getTezosNamespace() {
|
|
430
|
+
if (TEZOS_PLACEHOLDER in this.getSession().namespaces) {
|
|
431
|
+
return this.getSession().namespaces[TEZOS_PLACEHOLDER];
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
throw new errors_1.InvalidSession('Tezos not found in namespaces');
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
getTezosRequiredNamespace() {
|
|
438
|
+
if (TEZOS_PLACEHOLDER in this.getSession().requiredNamespaces) {
|
|
439
|
+
return this.getSession().requiredNamespaces[TEZOS_PLACEHOLDER];
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
throw new errors_1.InvalidSession('Tezos not found in requiredNamespaces');
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
validateNetworkAndAccount(network, account) {
|
|
446
|
+
if (!this.getTezosNamespace().accounts.includes(`${TEZOS_PLACEHOLDER}:${network}:${account}`)) {
|
|
447
|
+
throw new errors_1.InvalidNetworkOrAccount(network, account);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
getPermittedMethods() {
|
|
451
|
+
return this.getTezosRequiredNamespace().methods;
|
|
452
|
+
}
|
|
453
|
+
getPermittedNetwork() {
|
|
454
|
+
return this.getTezosRequiredNamespace().chains.map((chain) => chain.split(':')[1]);
|
|
455
|
+
}
|
|
456
|
+
formatParameters(params) {
|
|
457
|
+
const formatedParams = params;
|
|
458
|
+
if (typeof params.fee !== 'undefined') {
|
|
459
|
+
formatedParams.fee = params.fee.toString();
|
|
460
|
+
}
|
|
461
|
+
if (typeof params.storageLimit !== 'undefined') {
|
|
462
|
+
formatedParams.storageLimit = params.storageLimit.toString();
|
|
463
|
+
}
|
|
464
|
+
if (typeof params.gasLimit !== 'undefined') {
|
|
465
|
+
formatedParams.gasLimit = params.gasLimit.toString();
|
|
466
|
+
}
|
|
467
|
+
return formatedParams;
|
|
468
|
+
}
|
|
469
|
+
removeDefaultLimits(params, operatedParams) {
|
|
470
|
+
if (typeof params.fee === 'undefined') {
|
|
471
|
+
delete operatedParams.fee;
|
|
472
|
+
}
|
|
473
|
+
if (typeof params.storageLimit === 'undefined') {
|
|
474
|
+
delete operatedParams.storage_limit;
|
|
475
|
+
}
|
|
476
|
+
if (typeof params.gasLimit === 'undefined') {
|
|
477
|
+
delete operatedParams.gas_limit;
|
|
478
|
+
}
|
|
479
|
+
return operatedParams;
|
|
480
|
+
}
|
|
481
|
+
mapTransferParamsToWalletParams(params) {
|
|
482
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
483
|
+
const walletParams = yield params();
|
|
484
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createTransferOperation)(this.formatParameters(walletParams)));
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
mapTransferTicketParamsToWalletParams(params) {
|
|
488
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
489
|
+
const walletParams = yield params();
|
|
490
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createTransferTicketOperation)(this.formatParameters(walletParams)));
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
mapStakeParamsToWalletParams(params) {
|
|
494
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
495
|
+
const walletParams = yield params();
|
|
496
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createTransferOperation)(this.formatParameters(walletParams)));
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
mapUnstakeParamsToWalletParams(params) {
|
|
500
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
501
|
+
const walletParams = yield params();
|
|
502
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createTransferOperation)(this.formatParameters(walletParams)));
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
mapFinalizeUnstakeParamsToWalletParams(params) {
|
|
506
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
507
|
+
const walletParams = yield params();
|
|
508
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createTransferOperation)(this.formatParameters(walletParams)));
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
mapOriginateParamsToWalletParams(params) {
|
|
512
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
513
|
+
const walletParams = yield params();
|
|
514
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createOriginationOperation)(this.formatParameters(walletParams)));
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
mapDelegateParamsToWalletParams(params) {
|
|
518
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
519
|
+
const walletParams = yield params();
|
|
520
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createSetDelegateOperation)(this.formatParameters(walletParams)));
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
mapIncreasePaidStorageWalletParams(params) {
|
|
524
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
525
|
+
const walletParams = yield params();
|
|
526
|
+
return this.removeDefaultLimits(walletParams, yield (0, taquito_1.createIncreasePaidStorageOperation)(this.formatParameters(walletParams)));
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
exports.WalletConnect = WalletConnect;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SigningType = exports.PermissionScopeEvents = exports.PermissionScopeMethods = exports.NetworkType = void 0;
|
|
4
|
+
var NetworkType;
|
|
5
|
+
(function (NetworkType) {
|
|
6
|
+
NetworkType["MAINNET"] = "mainnet";
|
|
7
|
+
NetworkType["GHOSTNET"] = "ghostnet";
|
|
8
|
+
NetworkType["WEEKLYNET"] = "weeklynet";
|
|
9
|
+
NetworkType["OXFORDNET"] = "oxfordnet";
|
|
10
|
+
NetworkType["PARISNET"] = "parisnet";
|
|
11
|
+
// QUEBECNET = 'quebecnet',
|
|
12
|
+
})(NetworkType || (exports.NetworkType = NetworkType = {}));
|
|
13
|
+
var PermissionScopeMethods;
|
|
14
|
+
(function (PermissionScopeMethods) {
|
|
15
|
+
PermissionScopeMethods["TEZOS_GET_ACCOUNTS"] = "tezos_getAccounts";
|
|
16
|
+
PermissionScopeMethods["TEZOS_SEND"] = "tezos_send";
|
|
17
|
+
PermissionScopeMethods["TEZOS_SIGN"] = "tezos_sign";
|
|
18
|
+
})(PermissionScopeMethods || (exports.PermissionScopeMethods = PermissionScopeMethods = {}));
|
|
19
|
+
var PermissionScopeEvents;
|
|
20
|
+
(function (PermissionScopeEvents) {
|
|
21
|
+
PermissionScopeEvents["CHAIN_CHANGED"] = "chainChanged";
|
|
22
|
+
PermissionScopeEvents["ACCOUNTS_CHANGED"] = "accountsChanged";
|
|
23
|
+
})(PermissionScopeEvents || (exports.PermissionScopeEvents = PermissionScopeEvents = {}));
|
|
24
|
+
var SigningType;
|
|
25
|
+
(function (SigningType) {
|
|
26
|
+
SigningType["RAW"] = "raw";
|
|
27
|
+
SigningType["OPERATION"] = "operation";
|
|
28
|
+
SigningType["MICHELINE"] = "micheline";
|
|
29
|
+
})(SigningType || (exports.SigningType = SigningType = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION = void 0;
|
|
4
|
+
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
5
|
+
exports.VERSION = {
|
|
6
|
+
"commitHash": "3e5b607831fe4d2e3ec023b1648b84a890c0035e",
|
|
7
|
+
"version": "20.2.0-beta.0"
|
|
8
|
+
};
|