@pooflabs/web 0.0.86 → 0.0.88
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/dist/auth/providers/solana-mobile-wallet-provider.d.ts +43 -0
- package/dist/{index-DK28JaJm.esm.js → index-BfsQaxom.esm.js} +3054 -301
- package/dist/index-BfsQaxom.esm.js.map +1 -0
- package/dist/{index-BQUfNEiY.esm.js → index-CJRFnq6O.esm.js} +476 -103
- package/dist/index-CJRFnq6O.esm.js.map +1 -0
- package/dist/{index-BHkED2YI.js → index-CTtGbOzo.js} +3054 -300
- package/dist/index-CTtGbOzo.js.map +1 -0
- package/dist/{index-D-Wbwevj.js → index-CvNX4W0l.js} +2 -2
- package/dist/index-CvNX4W0l.js.map +1 -0
- package/dist/{index-DUn32Hkh.js → index-DBYgqO9f.js} +3055 -301
- package/dist/index-DBYgqO9f.js.map +1 -0
- package/dist/index-DpiO7Cpe.esm.js +6 -0
- package/dist/index-DpiO7Cpe.esm.js.map +1 -0
- package/dist/{index-hEc5_KoM.js → index-Lm0k5Hwv.js} +477 -102
- package/dist/index-Lm0k5Hwv.js.map +1 -0
- package/dist/{index-Cfp30Jm_.esm.js → index-MF_M5V0O.esm.js} +3055 -300
- package/dist/index-MF_M5V0O.esm.js.map +1 -0
- package/dist/{index.browser-CbawPvh6.js → index.browser-BCr9Sc8V.js} +506 -1876
- package/dist/index.browser-BCr9Sc8V.js.map +1 -0
- package/dist/{index.browser-DD8pg_L2.js → index.browser-BxKN5pIs.js} +1223 -2565
- package/dist/index.browser-BxKN5pIs.js.map +1 -0
- package/dist/{index.browser-DQqKPfDA.esm.js → index.browser-CGZvkfTO.esm.js} +506 -1876
- package/dist/index.browser-CGZvkfTO.esm.js.map +1 -0
- package/dist/{index.browser-C9gHoUen.esm.js → index.browser-CMijwVwX.esm.js} +1223 -2565
- package/dist/index.browser-CMijwVwX.esm.js.map +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{index.native-7hiNiSyC.js → index.native-FMbSnE7i.js} +44 -61
- package/dist/index.native-FMbSnE7i.js.map +1 -0
- package/dist/{index.native-BItnSD47.esm.js → index.native-GyqT8Dn5.esm.js} +43 -62
- package/dist/index.native-GyqT8Dn5.esm.js.map +1 -0
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +1 -1
- package/dist/{phantom-wallet-provider-CjvLq_2_.js → phantom-wallet-provider-4_DBhDbx.js} +4 -4
- package/dist/{phantom-wallet-provider-CjvLq_2_.js.map → phantom-wallet-provider-4_DBhDbx.js.map} +1 -1
- package/dist/{phantom-wallet-provider-DE3vit2Z.esm.js → phantom-wallet-provider-BFSfBW0w.esm.js} +4 -4
- package/dist/{phantom-wallet-provider-DE3vit2Z.esm.js.map → phantom-wallet-provider-BFSfBW0w.esm.js.map} +1 -1
- package/dist/{privy-wallet-provider-DFZaQPss.js → privy-wallet-provider-DRss_Hua.js} +3 -3
- package/dist/privy-wallet-provider-DRss_Hua.js.map +1 -0
- package/dist/{privy-wallet-provider-ip2pqo_U.esm.js → privy-wallet-provider-Dl0feuCb.esm.js} +3 -3
- package/dist/privy-wallet-provider-Dl0feuCb.esm.js.map +1 -0
- package/dist/{solana-mobile-wallet-provider-D7BbSpez.esm.js → solana-mobile-wallet-provider-C5mN8Dxh.esm.js} +437 -45
- package/dist/solana-mobile-wallet-provider-C5mN8Dxh.esm.js.map +1 -0
- package/dist/{solana-mobile-wallet-provider-DwER68Rz.js → solana-mobile-wallet-provider-CAZs-TkL.js} +437 -45
- package/dist/solana-mobile-wallet-provider-CAZs-TkL.js.map +1 -0
- package/package.json +1 -1
- package/dist/index-BHkED2YI.js.map +0 -1
- package/dist/index-BQUfNEiY.esm.js.map +0 -1
- package/dist/index-Cfp30Jm_.esm.js.map +0 -1
- package/dist/index-D-Wbwevj.js.map +0 -1
- package/dist/index-DK28JaJm.esm.js.map +0 -1
- package/dist/index-DKyWaxCB.esm.js +0 -6
- package/dist/index-DKyWaxCB.esm.js.map +0 -1
- package/dist/index-DUn32Hkh.js.map +0 -1
- package/dist/index-hEc5_KoM.js.map +0 -1
- package/dist/index.browser-C9gHoUen.esm.js.map +0 -1
- package/dist/index.browser-CbawPvh6.js.map +0 -1
- package/dist/index.browser-DD8pg_L2.js.map +0 -1
- package/dist/index.browser-DQqKPfDA.esm.js.map +0 -1
- package/dist/index.native-7hiNiSyC.js.map +0 -1
- package/dist/index.native-BItnSD47.esm.js.map +0 -1
- package/dist/privy-wallet-provider-DFZaQPss.js.map +0 -1
- package/dist/privy-wallet-provider-ip2pqo_U.esm.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-D7BbSpez.esm.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-DwER68Rz.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { g as getDefaultExportFromCjs, a as base58 } from './index-
|
|
1
|
+
import { g as getDefaultExportFromCjs, a as base58 } from './index-CJRFnq6O.esm.js';
|
|
2
|
+
import { startRemoteScenario, transact } from '@solana-mobile/mobile-wallet-adapter-protocol';
|
|
2
3
|
import 'axios';
|
|
3
4
|
import '@solana/web3.js';
|
|
4
5
|
import '@coral-xyz/anchor';
|
|
@@ -16,1010 +17,6 @@ const SolanaSignMessage = 'solana:signMessage';
|
|
|
16
17
|
/** Name of the feature. */
|
|
17
18
|
const SolanaSignTransaction = 'solana:signTransaction';
|
|
18
19
|
|
|
19
|
-
function createDecoder(decoder) {
|
|
20
|
-
return Object.freeze({
|
|
21
|
-
...decoder,
|
|
22
|
-
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var getBaseXDecoder = (alphabet4) => {
|
|
27
|
-
return createDecoder({
|
|
28
|
-
read(rawBytes, offset) {
|
|
29
|
-
const bytes = offset === 0 || offset <= -rawBytes.byteLength ? rawBytes : rawBytes.slice(offset);
|
|
30
|
-
if (bytes.length === 0) return ["", 0];
|
|
31
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
32
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
33
|
-
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
34
|
-
if (trailIndex === bytes.length) return [leadingZeroes, rawBytes.length];
|
|
35
|
-
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
36
|
-
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
|
|
37
|
-
return [leadingZeroes + tailChars, rawBytes.length];
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
function getBaseXFromBigInt(value, alphabet4) {
|
|
42
|
-
const base = BigInt(alphabet4.length);
|
|
43
|
-
const tailChars = [];
|
|
44
|
-
while (value > 0n) {
|
|
45
|
-
tailChars.unshift(alphabet4[Number(value % base)]);
|
|
46
|
-
value /= base;
|
|
47
|
-
}
|
|
48
|
-
return tailChars.join("");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/base58.ts
|
|
52
|
-
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
53
|
-
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
54
|
-
|
|
55
|
-
/** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */
|
|
56
|
-
const SOLANA_MAINNET_CHAIN = 'solana:mainnet';
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* TODO: docs
|
|
60
|
-
*/
|
|
61
|
-
function createSignInMessageText(input) {
|
|
62
|
-
// ${domain} wants you to sign in with your Solana account:
|
|
63
|
-
// ${address}
|
|
64
|
-
//
|
|
65
|
-
// ${statement}
|
|
66
|
-
//
|
|
67
|
-
// URI: ${uri}
|
|
68
|
-
// Version: ${version}
|
|
69
|
-
// Chain ID: ${chain}
|
|
70
|
-
// Nonce: ${nonce}
|
|
71
|
-
// Issued At: ${issued-at}
|
|
72
|
-
// Expiration Time: ${expiration-time}
|
|
73
|
-
// Not Before: ${not-before}
|
|
74
|
-
// Request ID: ${request-id}
|
|
75
|
-
// Resources:
|
|
76
|
-
// - ${resources[0]}
|
|
77
|
-
// - ${resources[1]}
|
|
78
|
-
// ...
|
|
79
|
-
// - ${resources[n]}
|
|
80
|
-
let message = `${input.domain} wants you to sign in with your Solana account:\n`;
|
|
81
|
-
message += `${input.address}`;
|
|
82
|
-
if (input.statement) {
|
|
83
|
-
message += `\n\n${input.statement}`;
|
|
84
|
-
}
|
|
85
|
-
const fields = [];
|
|
86
|
-
if (input.uri) {
|
|
87
|
-
fields.push(`URI: ${input.uri}`);
|
|
88
|
-
}
|
|
89
|
-
if (input.version) {
|
|
90
|
-
fields.push(`Version: ${input.version}`);
|
|
91
|
-
}
|
|
92
|
-
if (input.chainId) {
|
|
93
|
-
fields.push(`Chain ID: ${input.chainId}`);
|
|
94
|
-
}
|
|
95
|
-
if (input.nonce) {
|
|
96
|
-
fields.push(`Nonce: ${input.nonce}`);
|
|
97
|
-
}
|
|
98
|
-
if (input.issuedAt) {
|
|
99
|
-
fields.push(`Issued At: ${input.issuedAt}`);
|
|
100
|
-
}
|
|
101
|
-
if (input.expirationTime) {
|
|
102
|
-
fields.push(`Expiration Time: ${input.expirationTime}`);
|
|
103
|
-
}
|
|
104
|
-
if (input.notBefore) {
|
|
105
|
-
fields.push(`Not Before: ${input.notBefore}`);
|
|
106
|
-
}
|
|
107
|
-
if (input.requestId) {
|
|
108
|
-
fields.push(`Request ID: ${input.requestId}`);
|
|
109
|
-
}
|
|
110
|
-
if (input.resources) {
|
|
111
|
-
fields.push(`Resources:`);
|
|
112
|
-
for (const resource of input.resources) {
|
|
113
|
-
fields.push(`- ${resource}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (fields.length) {
|
|
117
|
-
message += `\n\n${fields.join('\n')}`;
|
|
118
|
-
}
|
|
119
|
-
return message;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
//#region src/errors.ts
|
|
123
|
-
const SolanaMobileWalletAdapterErrorCode = {
|
|
124
|
-
ERROR_ASSOCIATION_PORT_OUT_OF_RANGE: "ERROR_ASSOCIATION_PORT_OUT_OF_RANGE",
|
|
125
|
-
ERROR_REFLECTOR_ID_OUT_OF_RANGE: "ERROR_REFLECTOR_ID_OUT_OF_RANGE",
|
|
126
|
-
ERROR_FORBIDDEN_WALLET_BASE_URL: "ERROR_FORBIDDEN_WALLET_BASE_URL",
|
|
127
|
-
ERROR_SECURE_CONTEXT_REQUIRED: "ERROR_SECURE_CONTEXT_REQUIRED",
|
|
128
|
-
ERROR_SESSION_CLOSED: "ERROR_SESSION_CLOSED",
|
|
129
|
-
ERROR_SESSION_TIMEOUT: "ERROR_SESSION_TIMEOUT",
|
|
130
|
-
ERROR_WALLET_NOT_FOUND: "ERROR_WALLET_NOT_FOUND",
|
|
131
|
-
ERROR_INVALID_PROTOCOL_VERSION: "ERROR_INVALID_PROTOCOL_VERSION",
|
|
132
|
-
ERROR_BROWSER_NOT_SUPPORTED: "ERROR_BROWSER_NOT_SUPPORTED",
|
|
133
|
-
ERROR_LOOPBACK_ACCESS_BLOCKED: "ERROR_LOOPBACK_ACCESS_BLOCKED",
|
|
134
|
-
ERROR_ASSOCIATION_CANCELLED: "ERROR_ASSOCIATION_CANCELLED"
|
|
135
|
-
};
|
|
136
|
-
var SolanaMobileWalletAdapterError = class extends Error {
|
|
137
|
-
data;
|
|
138
|
-
code;
|
|
139
|
-
constructor(...args) {
|
|
140
|
-
const [code, message, data] = args;
|
|
141
|
-
super(message);
|
|
142
|
-
this.code = code;
|
|
143
|
-
this.data = data;
|
|
144
|
-
this.name = "SolanaMobileWalletAdapterError";
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
var SolanaMobileWalletAdapterProtocolError = class extends Error {
|
|
148
|
-
data;
|
|
149
|
-
code;
|
|
150
|
-
jsonRpcMessageId;
|
|
151
|
-
constructor(...args) {
|
|
152
|
-
const [jsonRpcMessageId, code, message, data] = args;
|
|
153
|
-
super(message);
|
|
154
|
-
this.code = code;
|
|
155
|
-
this.data = data;
|
|
156
|
-
this.jsonRpcMessageId = jsonRpcMessageId;
|
|
157
|
-
this.name = "SolanaMobileWalletAdapterProtocolError";
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/base64Utils.ts
|
|
162
|
-
function encode(input) {
|
|
163
|
-
return window.btoa(input);
|
|
164
|
-
}
|
|
165
|
-
function fromUint8Array$1(byteArray, urlsafe) {
|
|
166
|
-
const base64 = window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
167
|
-
if (urlsafe) return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
168
|
-
else return base64;
|
|
169
|
-
}
|
|
170
|
-
function toUint8Array$1(base64EncodedByteArray) {
|
|
171
|
-
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/createHelloReq.ts
|
|
175
|
-
async function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
|
|
176
|
-
const publicKeyBuffer = await crypto.subtle.exportKey("raw", ecdhPublicKey);
|
|
177
|
-
const signatureBuffer = await crypto.subtle.sign({
|
|
178
|
-
hash: "SHA-256",
|
|
179
|
-
name: "ECDSA"
|
|
180
|
-
}, associationKeypairPrivateKey, publicKeyBuffer);
|
|
181
|
-
const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
|
|
182
|
-
response.set(new Uint8Array(publicKeyBuffer), 0);
|
|
183
|
-
response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
|
|
184
|
-
return response;
|
|
185
|
-
}
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/base58Utils.ts
|
|
188
|
-
function fromUint8Array$2(byteArray) {
|
|
189
|
-
return getBase58Decoder().decode(byteArray);
|
|
190
|
-
}
|
|
191
|
-
function base64ToBase58(base64EncodedString) {
|
|
192
|
-
return fromUint8Array$2(toUint8Array$1(base64EncodedString));
|
|
193
|
-
}
|
|
194
|
-
//#endregion
|
|
195
|
-
//#region src/createSIWSMessage.ts
|
|
196
|
-
function createSIWSMessage(payload) {
|
|
197
|
-
return createSignInMessageText(payload);
|
|
198
|
-
}
|
|
199
|
-
function createSIWSMessageBase64Url(payload) {
|
|
200
|
-
return encode(createSIWSMessage(payload)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
201
|
-
}
|
|
202
|
-
//#endregion
|
|
203
|
-
//#region src/types.ts
|
|
204
|
-
const SolanaSignTransactions = "solana:signTransactions";
|
|
205
|
-
const SolanaCloneAuthorization = "solana:cloneAuthorization";
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/createMobileWalletProxy.ts
|
|
208
|
-
/**
|
|
209
|
-
* Creates a {@link MobileWallet} proxy that handles backwards compatibility and API to RPC conversion.
|
|
210
|
-
*
|
|
211
|
-
* @param protocolVersion the protocol version in use for this session/request
|
|
212
|
-
* @param protocolRequestHandler callback function that handles sending the RPC request to the wallet endpoint.
|
|
213
|
-
* @returns a {@link MobileWallet} proxy
|
|
214
|
-
*/
|
|
215
|
-
function createMobileWalletProxy(protocolVersion, protocolRequestHandler) {
|
|
216
|
-
return new Proxy({}, {
|
|
217
|
-
get(target, p) {
|
|
218
|
-
if (p === "then") return null;
|
|
219
|
-
if (target[p] == null) target[p] = async function(inputParams) {
|
|
220
|
-
const { method, params } = handleMobileWalletRequest(p, inputParams, protocolVersion);
|
|
221
|
-
const result = await protocolRequestHandler(method, params);
|
|
222
|
-
if (method === "authorize" && params.sign_in_payload && !result.sign_in_result) result.sign_in_result = await signInFallback(params.sign_in_payload, result, protocolRequestHandler);
|
|
223
|
-
return handleMobileWalletResponse(p, result, protocolVersion);
|
|
224
|
-
};
|
|
225
|
-
return target[p];
|
|
226
|
-
},
|
|
227
|
-
defineProperty() {
|
|
228
|
-
return false;
|
|
229
|
-
},
|
|
230
|
-
deleteProperty() {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Handles all {@link MobileWallet} API requests and determines the correct MWA RPC method and params to call.
|
|
237
|
-
* This handles backwards compatibility, based on the provided @protocolVersion.
|
|
238
|
-
*
|
|
239
|
-
* @param methodName the name of {@link MobileWallet} method that was called
|
|
240
|
-
* @param methodParams the parameters that were passed to the method
|
|
241
|
-
* @param protocolVersion the protocol version in use for this session/request
|
|
242
|
-
* @returns the RPC request method and params that should be sent to the wallet endpoint
|
|
243
|
-
*/
|
|
244
|
-
function handleMobileWalletRequest(methodName, methodParams, protocolVersion) {
|
|
245
|
-
let params = methodParams;
|
|
246
|
-
let method = methodName.toString().replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`).toLowerCase();
|
|
247
|
-
switch (methodName) {
|
|
248
|
-
case "authorize": {
|
|
249
|
-
const authorizeParams = params;
|
|
250
|
-
let { chain } = authorizeParams;
|
|
251
|
-
if (protocolVersion === "legacy") {
|
|
252
|
-
switch (chain) {
|
|
253
|
-
case "solana:testnet":
|
|
254
|
-
chain = "testnet";
|
|
255
|
-
break;
|
|
256
|
-
case "solana:devnet":
|
|
257
|
-
chain = "devnet";
|
|
258
|
-
break;
|
|
259
|
-
case "solana:mainnet":
|
|
260
|
-
chain = "mainnet-beta";
|
|
261
|
-
break;
|
|
262
|
-
default: chain = authorizeParams.cluster;
|
|
263
|
-
}
|
|
264
|
-
authorizeParams.cluster = chain;
|
|
265
|
-
params = authorizeParams;
|
|
266
|
-
} else {
|
|
267
|
-
switch (chain) {
|
|
268
|
-
case "testnet":
|
|
269
|
-
case "devnet":
|
|
270
|
-
chain = `solana:${chain}`;
|
|
271
|
-
break;
|
|
272
|
-
case "mainnet-beta":
|
|
273
|
-
chain = "solana:mainnet";
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
authorizeParams.chain = chain;
|
|
277
|
-
params = authorizeParams;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
case "reauthorize": {
|
|
281
|
-
const { auth_token, identity } = params;
|
|
282
|
-
if (auth_token) switch (protocolVersion) {
|
|
283
|
-
case "legacy":
|
|
284
|
-
method = "reauthorize";
|
|
285
|
-
params = {
|
|
286
|
-
auth_token,
|
|
287
|
-
identity
|
|
288
|
-
};
|
|
289
|
-
break;
|
|
290
|
-
default:
|
|
291
|
-
method = "authorize";
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return {
|
|
298
|
-
method,
|
|
299
|
-
params
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Handles all {@link MobileWallet} API responses and modifies the response for backwards compatibility, if needed
|
|
304
|
-
*
|
|
305
|
-
* @param method the {@link MobileWallet} method that was called
|
|
306
|
-
* @param response the original response that was returned by the method call
|
|
307
|
-
* @param protocolVersion the protocol version in use for this session/request
|
|
308
|
-
* @returns the possibly modified response
|
|
309
|
-
*/
|
|
310
|
-
function handleMobileWalletResponse(method, response, protocolVersion) {
|
|
311
|
-
switch (method) {
|
|
312
|
-
case "getCapabilities": {
|
|
313
|
-
const capabilities = response;
|
|
314
|
-
switch (protocolVersion) {
|
|
315
|
-
case "legacy": {
|
|
316
|
-
const features = [SolanaSignTransactions];
|
|
317
|
-
if (capabilities.supports_clone_authorization === true) features.push(SolanaCloneAuthorization);
|
|
318
|
-
return {
|
|
319
|
-
...capabilities,
|
|
320
|
-
features
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
case "v1": return {
|
|
324
|
-
...capabilities,
|
|
325
|
-
supports_sign_and_send_transactions: true,
|
|
326
|
-
supports_clone_authorization: capabilities.features.includes(SolanaCloneAuthorization)
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return response;
|
|
332
|
-
}
|
|
333
|
-
async function signInFallback(signInPayload, authorizationResult, protocolRequestHandler) {
|
|
334
|
-
const domain = signInPayload.domain ?? window.location.host;
|
|
335
|
-
const address = authorizationResult.accounts[0].address;
|
|
336
|
-
const siwsMessage = createSIWSMessageBase64Url({
|
|
337
|
-
...signInPayload,
|
|
338
|
-
domain,
|
|
339
|
-
address: base64ToBase58(address)
|
|
340
|
-
});
|
|
341
|
-
const signedPayload = toUint8Array$1((await protocolRequestHandler("sign_messages", {
|
|
342
|
-
addresses: [address],
|
|
343
|
-
payloads: [siwsMessage]
|
|
344
|
-
})).signed_payloads[0]);
|
|
345
|
-
const signedMessage = fromUint8Array$1(signedPayload.slice(0, signedPayload.length - 64));
|
|
346
|
-
const signature = fromUint8Array$1(signedPayload.slice(signedPayload.length - 64));
|
|
347
|
-
return {
|
|
348
|
-
address,
|
|
349
|
-
signed_message: signedMessage.length == 0 ? siwsMessage : signedMessage,
|
|
350
|
-
signature
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
function createSequenceNumberVector(sequenceNumber) {
|
|
354
|
-
if (sequenceNumber >= 4294967296) throw new Error("Outbound sequence number overflow. The maximum sequence number is 32-bytes.");
|
|
355
|
-
const byteArray = /* @__PURE__ */ new ArrayBuffer(4);
|
|
356
|
-
new DataView(byteArray).setUint32(0, sequenceNumber, false);
|
|
357
|
-
return new Uint8Array(byteArray);
|
|
358
|
-
}
|
|
359
|
-
//#endregion
|
|
360
|
-
//#region src/encryptedMessage.ts
|
|
361
|
-
const INITIALIZATION_VECTOR_BYTES = 12;
|
|
362
|
-
async function encryptMessage(plaintext, sequenceNumber, sharedSecret) {
|
|
363
|
-
const sequenceNumberVector = createSequenceNumberVector(sequenceNumber);
|
|
364
|
-
const initializationVector = new Uint8Array(INITIALIZATION_VECTOR_BYTES);
|
|
365
|
-
crypto.getRandomValues(initializationVector);
|
|
366
|
-
const ciphertext = await crypto.subtle.encrypt(getAlgorithmParams(sequenceNumberVector, initializationVector), sharedSecret, new TextEncoder().encode(plaintext));
|
|
367
|
-
const response = new Uint8Array(sequenceNumberVector.byteLength + initializationVector.byteLength + ciphertext.byteLength);
|
|
368
|
-
response.set(new Uint8Array(sequenceNumberVector), 0);
|
|
369
|
-
response.set(new Uint8Array(initializationVector), sequenceNumberVector.byteLength);
|
|
370
|
-
response.set(new Uint8Array(ciphertext), sequenceNumberVector.byteLength + initializationVector.byteLength);
|
|
371
|
-
return response;
|
|
372
|
-
}
|
|
373
|
-
async function decryptMessage(message, sharedSecret) {
|
|
374
|
-
const sequenceNumberVector = message.slice(0, 4);
|
|
375
|
-
const initializationVector = message.slice(4, 4 + INITIALIZATION_VECTOR_BYTES);
|
|
376
|
-
const ciphertext = message.slice(4 + INITIALIZATION_VECTOR_BYTES);
|
|
377
|
-
const plaintextBuffer = await crypto.subtle.decrypt(getAlgorithmParams(sequenceNumberVector, initializationVector), sharedSecret, ciphertext);
|
|
378
|
-
return getUtf8Decoder().decode(plaintextBuffer);
|
|
379
|
-
}
|
|
380
|
-
function getAlgorithmParams(sequenceNumber, initializationVector) {
|
|
381
|
-
return {
|
|
382
|
-
additionalData: sequenceNumber,
|
|
383
|
-
iv: initializationVector,
|
|
384
|
-
name: "AES-GCM",
|
|
385
|
-
tagLength: 128
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
let _utf8Decoder;
|
|
389
|
-
function getUtf8Decoder() {
|
|
390
|
-
if (_utf8Decoder === void 0) _utf8Decoder = new TextDecoder("utf-8");
|
|
391
|
-
return _utf8Decoder;
|
|
392
|
-
}
|
|
393
|
-
//#endregion
|
|
394
|
-
//#region src/generateAssociationKeypair.ts
|
|
395
|
-
async function generateAssociationKeypair() {
|
|
396
|
-
return await crypto.subtle.generateKey({
|
|
397
|
-
name: "ECDSA",
|
|
398
|
-
namedCurve: "P-256"
|
|
399
|
-
}, false, ["sign"]);
|
|
400
|
-
}
|
|
401
|
-
//#endregion
|
|
402
|
-
//#region src/generateECDHKeypair.ts
|
|
403
|
-
async function generateECDHKeypair() {
|
|
404
|
-
return await crypto.subtle.generateKey({
|
|
405
|
-
name: "ECDH",
|
|
406
|
-
namedCurve: "P-256"
|
|
407
|
-
}, false, ["deriveKey", "deriveBits"]);
|
|
408
|
-
}
|
|
409
|
-
//#endregion
|
|
410
|
-
//#region src/arrayBufferToBase64String.ts
|
|
411
|
-
function arrayBufferToBase64String(buffer) {
|
|
412
|
-
let binary = "";
|
|
413
|
-
const bytes = new Uint8Array(buffer);
|
|
414
|
-
const len = bytes.byteLength;
|
|
415
|
-
for (let ii = 0; ii < len; ii++) binary += String.fromCharCode(bytes[ii]);
|
|
416
|
-
return window.btoa(binary);
|
|
417
|
-
}
|
|
418
|
-
//#endregion
|
|
419
|
-
//#region src/associationPort.ts
|
|
420
|
-
function getRandomAssociationPort() {
|
|
421
|
-
return assertAssociationPort(49152 + Math.floor(Math.random() * 16384));
|
|
422
|
-
}
|
|
423
|
-
function assertAssociationPort(port) {
|
|
424
|
-
if (port < 49152 || port > 65535) throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_PORT_OUT_OF_RANGE, `Association port number must be between 49152 and 65535. ${port} given.`, { port });
|
|
425
|
-
return port;
|
|
426
|
-
}
|
|
427
|
-
//#endregion
|
|
428
|
-
//#region src/getStringWithURLUnsafeBase64CharactersReplaced.ts
|
|
429
|
-
function getStringWithURLUnsafeCharactersReplaced(unsafeBase64EncodedString) {
|
|
430
|
-
return unsafeBase64EncodedString.replace(/[/+=]/g, (m) => ({
|
|
431
|
-
"/": "_",
|
|
432
|
-
"+": "-",
|
|
433
|
-
"=": "."
|
|
434
|
-
})[m]);
|
|
435
|
-
}
|
|
436
|
-
//#endregion
|
|
437
|
-
//#region src/getAssociateAndroidIntentURL.ts
|
|
438
|
-
const INTENT_NAME = "solana-wallet";
|
|
439
|
-
function getPathParts(pathString) {
|
|
440
|
-
return pathString.replace(/(^\/+|\/+$)/g, "").split("/");
|
|
441
|
-
}
|
|
442
|
-
function getIntentURL(methodPathname, intentUrlBase) {
|
|
443
|
-
let baseUrl = null;
|
|
444
|
-
if (intentUrlBase) {
|
|
445
|
-
try {
|
|
446
|
-
baseUrl = new URL(intentUrlBase);
|
|
447
|
-
} catch {}
|
|
448
|
-
if (baseUrl?.protocol !== "https:") throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL, "Base URLs supplied by wallets must be valid `https` URLs");
|
|
449
|
-
}
|
|
450
|
-
baseUrl ||= new URL(`${INTENT_NAME}:/`);
|
|
451
|
-
const pathname = methodPathname.startsWith("/") ? methodPathname : [...getPathParts(baseUrl.pathname), ...getPathParts(methodPathname)].join("/");
|
|
452
|
-
return new URL(pathname, baseUrl);
|
|
453
|
-
}
|
|
454
|
-
async function getAssociateAndroidIntentURL(associationPublicKey, putativePort, associationURLBase, protocolVersions = ["v1"]) {
|
|
455
|
-
const associationPort = assertAssociationPort(putativePort);
|
|
456
|
-
const encodedKey = arrayBufferToBase64String(await crypto.subtle.exportKey("raw", associationPublicKey));
|
|
457
|
-
const url = getIntentURL("v1/associate/local", associationURLBase);
|
|
458
|
-
url.searchParams.set("association", getStringWithURLUnsafeCharactersReplaced(encodedKey));
|
|
459
|
-
url.searchParams.set("port", `${associationPort}`);
|
|
460
|
-
protocolVersions.forEach((version) => {
|
|
461
|
-
url.searchParams.set("v", version);
|
|
462
|
-
});
|
|
463
|
-
return url;
|
|
464
|
-
}
|
|
465
|
-
async function getRemoteAssociateAndroidIntentURL(associationPublicKey, hostAuthority, reflectorId, associationURLBase, protocolVersions = ["v1"]) {
|
|
466
|
-
const encodedKey = arrayBufferToBase64String(await crypto.subtle.exportKey("raw", associationPublicKey));
|
|
467
|
-
const url = getIntentURL("v1/associate/remote", associationURLBase);
|
|
468
|
-
url.searchParams.set("association", getStringWithURLUnsafeCharactersReplaced(encodedKey));
|
|
469
|
-
url.searchParams.set("reflector", `${hostAuthority}`);
|
|
470
|
-
url.searchParams.set("id", `${fromUint8Array$1(reflectorId, true)}`);
|
|
471
|
-
protocolVersions.forEach((version) => {
|
|
472
|
-
url.searchParams.set("v", version);
|
|
473
|
-
});
|
|
474
|
-
return url;
|
|
475
|
-
}
|
|
476
|
-
//#endregion
|
|
477
|
-
//#region src/jsonRpcMessage.ts
|
|
478
|
-
async function encryptJsonRpcMessage(jsonRpcMessage, sharedSecret) {
|
|
479
|
-
const plaintext = JSON.stringify(jsonRpcMessage);
|
|
480
|
-
const sequenceNumber = jsonRpcMessage.id;
|
|
481
|
-
return encryptMessage(plaintext, sequenceNumber, sharedSecret);
|
|
482
|
-
}
|
|
483
|
-
async function decryptJsonRpcMessage(message, sharedSecret) {
|
|
484
|
-
const plaintext = await decryptMessage(message, sharedSecret);
|
|
485
|
-
const jsonRpcMessage = JSON.parse(plaintext);
|
|
486
|
-
if (Object.hasOwnProperty.call(jsonRpcMessage, "error")) throw new SolanaMobileWalletAdapterProtocolError(jsonRpcMessage.id, jsonRpcMessage.error.code, jsonRpcMessage.error.message);
|
|
487
|
-
return jsonRpcMessage;
|
|
488
|
-
}
|
|
489
|
-
//#endregion
|
|
490
|
-
//#region src/parseHelloRsp.ts
|
|
491
|
-
async function parseHelloRsp(payloadBuffer, associationPublicKey, ecdhPrivateKey) {
|
|
492
|
-
const [associationPublicKeyBuffer, walletPublicKey] = await Promise.all([crypto.subtle.exportKey("raw", associationPublicKey), crypto.subtle.importKey("raw", payloadBuffer.slice(0, 65), {
|
|
493
|
-
name: "ECDH",
|
|
494
|
-
namedCurve: "P-256"
|
|
495
|
-
}, false, [])]);
|
|
496
|
-
const sharedSecret = await crypto.subtle.deriveBits({
|
|
497
|
-
name: "ECDH",
|
|
498
|
-
public: walletPublicKey
|
|
499
|
-
}, ecdhPrivateKey, 256);
|
|
500
|
-
const ecdhSecretKey = await crypto.subtle.importKey("raw", sharedSecret, "HKDF", false, ["deriveKey"]);
|
|
501
|
-
return await crypto.subtle.deriveKey({
|
|
502
|
-
name: "HKDF",
|
|
503
|
-
hash: "SHA-256",
|
|
504
|
-
salt: new Uint8Array(associationPublicKeyBuffer),
|
|
505
|
-
info: new Uint8Array()
|
|
506
|
-
}, ecdhSecretKey, {
|
|
507
|
-
name: "AES-GCM",
|
|
508
|
-
length: 128
|
|
509
|
-
}, false, ["encrypt", "decrypt"]);
|
|
510
|
-
}
|
|
511
|
-
//#endregion
|
|
512
|
-
//#region src/parseSessionProps.ts
|
|
513
|
-
async function parseSessionProps(message, sharedSecret) {
|
|
514
|
-
const plaintext = await decryptMessage(message, sharedSecret);
|
|
515
|
-
const jsonProperties = JSON.parse(plaintext);
|
|
516
|
-
let protocolVersion = "legacy";
|
|
517
|
-
if (Object.hasOwnProperty.call(jsonProperties, "v")) switch (jsonProperties.v) {
|
|
518
|
-
case 1:
|
|
519
|
-
case "1":
|
|
520
|
-
case "v1":
|
|
521
|
-
protocolVersion = "v1";
|
|
522
|
-
break;
|
|
523
|
-
case "legacy":
|
|
524
|
-
protocolVersion = "legacy";
|
|
525
|
-
break;
|
|
526
|
-
default: throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_INVALID_PROTOCOL_VERSION, `Unknown/unsupported protocol version: ${jsonProperties.v}`);
|
|
527
|
-
}
|
|
528
|
-
return { protocol_version: protocolVersion };
|
|
529
|
-
}
|
|
530
|
-
//#endregion
|
|
531
|
-
//#region src/startSession.ts
|
|
532
|
-
const Browser = {
|
|
533
|
-
Firefox: 0,
|
|
534
|
-
Other: 1
|
|
535
|
-
};
|
|
536
|
-
function assertUnreachable(x) {
|
|
537
|
-
return x;
|
|
538
|
-
}
|
|
539
|
-
function getBrowser() {
|
|
540
|
-
return navigator.userAgent.indexOf("Firefox/") !== -1 ? Browser.Firefox : Browser.Other;
|
|
541
|
-
}
|
|
542
|
-
function getDetectionPromise() {
|
|
543
|
-
return new Promise((resolve, reject) => {
|
|
544
|
-
function cleanup() {
|
|
545
|
-
clearTimeout(timeoutId);
|
|
546
|
-
window.removeEventListener("blur", handleBlur);
|
|
547
|
-
}
|
|
548
|
-
function handleBlur() {
|
|
549
|
-
cleanup();
|
|
550
|
-
resolve();
|
|
551
|
-
}
|
|
552
|
-
window.addEventListener("blur", handleBlur);
|
|
553
|
-
const timeoutId = setTimeout(() => {
|
|
554
|
-
cleanup();
|
|
555
|
-
reject();
|
|
556
|
-
}, 3e3);
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
let _frame = null;
|
|
560
|
-
function launchUrlThroughHiddenFrame(url) {
|
|
561
|
-
if (_frame == null) {
|
|
562
|
-
_frame = document.createElement("iframe");
|
|
563
|
-
_frame.style.display = "none";
|
|
564
|
-
document.body.appendChild(_frame);
|
|
565
|
-
}
|
|
566
|
-
_frame.contentWindow.location.href = url.toString();
|
|
567
|
-
}
|
|
568
|
-
async function launchAssociation(associationUrl) {
|
|
569
|
-
if (associationUrl.protocol === "https:") window.location.assign(associationUrl);
|
|
570
|
-
else try {
|
|
571
|
-
const browser = getBrowser();
|
|
572
|
-
switch (browser) {
|
|
573
|
-
case Browser.Firefox:
|
|
574
|
-
launchUrlThroughHiddenFrame(associationUrl);
|
|
575
|
-
break;
|
|
576
|
-
case Browser.Other: {
|
|
577
|
-
const detectionPromise = getDetectionPromise();
|
|
578
|
-
window.location.assign(associationUrl);
|
|
579
|
-
await detectionPromise;
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
default: assertUnreachable(browser);
|
|
583
|
-
}
|
|
584
|
-
} catch {
|
|
585
|
-
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND, "Found no installed wallet that supports the mobile wallet protocol.");
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
async function startSession(associationPublicKey, associationURLBase) {
|
|
589
|
-
const randomAssociationPort = getRandomAssociationPort();
|
|
590
|
-
await launchAssociation(await getAssociateAndroidIntentURL(associationPublicKey, randomAssociationPort, associationURLBase));
|
|
591
|
-
return randomAssociationPort;
|
|
592
|
-
}
|
|
593
|
-
//#endregion
|
|
594
|
-
//#region src/transact.ts
|
|
595
|
-
const WEBSOCKET_CONNECTION_CONFIG = {
|
|
596
|
-
retryDelayScheduleMs: [
|
|
597
|
-
150,
|
|
598
|
-
150,
|
|
599
|
-
200,
|
|
600
|
-
500,
|
|
601
|
-
500,
|
|
602
|
-
750,
|
|
603
|
-
750,
|
|
604
|
-
1e3
|
|
605
|
-
],
|
|
606
|
-
timeoutMs: 3e4
|
|
607
|
-
};
|
|
608
|
-
const WEBSOCKET_PROTOCOL_BINARY = "com.solana.mobilewalletadapter.v1";
|
|
609
|
-
const WEBSOCKET_PROTOCOL_BASE64 = "com.solana.mobilewalletadapter.v1.base64";
|
|
610
|
-
function assertSecureContext() {
|
|
611
|
-
if (typeof window === "undefined" || window.isSecureContext !== true) throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SECURE_CONTEXT_REQUIRED, "The mobile wallet adapter protocol must be used in a secure context (`https`).");
|
|
612
|
-
}
|
|
613
|
-
function assertSecureEndpointSpecificURI(walletUriBase) {
|
|
614
|
-
let url;
|
|
615
|
-
try {
|
|
616
|
-
url = new URL(walletUriBase);
|
|
617
|
-
} catch {
|
|
618
|
-
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL, "Invalid base URL supplied by wallet");
|
|
619
|
-
}
|
|
620
|
-
if (url.protocol !== "https:") throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL, "Base URLs supplied by wallets must be valid `https` URLs");
|
|
621
|
-
}
|
|
622
|
-
function getSequenceNumberFromByteArray(byteArray) {
|
|
623
|
-
return new DataView(byteArray).getUint32(0, false);
|
|
624
|
-
}
|
|
625
|
-
function decodeVarLong(byteArray) {
|
|
626
|
-
const bytes = new Uint8Array(byteArray);
|
|
627
|
-
const l = byteArray.byteLength;
|
|
628
|
-
const limit = 10;
|
|
629
|
-
let value = 0, offset = 0, b;
|
|
630
|
-
do {
|
|
631
|
-
if (offset >= l || offset > limit) throw new RangeError("Failed to decode varint");
|
|
632
|
-
b = bytes[offset++];
|
|
633
|
-
value |= (b & 127) << 7 * offset;
|
|
634
|
-
} while (b >= 128);
|
|
635
|
-
return {
|
|
636
|
-
value,
|
|
637
|
-
offset
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
function getReflectorIdFromByteArray(byteArray) {
|
|
641
|
-
const { value: length, offset } = decodeVarLong(byteArray);
|
|
642
|
-
return new Uint8Array(byteArray.slice(offset, offset + length));
|
|
643
|
-
}
|
|
644
|
-
async function startScenario(config) {
|
|
645
|
-
assertSecureContext();
|
|
646
|
-
const associationKeypair = await generateAssociationKeypair();
|
|
647
|
-
const websocketURL = `ws://localhost:${await startSession(associationKeypair.publicKey, config?.baseUri)}/solana-wallet`;
|
|
648
|
-
let connectionStartTime;
|
|
649
|
-
const getNextRetryDelayMs = (() => {
|
|
650
|
-
const schedule = [...WEBSOCKET_CONNECTION_CONFIG.retryDelayScheduleMs];
|
|
651
|
-
return () => schedule.length > 1 ? schedule.shift() : schedule[0];
|
|
652
|
-
})();
|
|
653
|
-
let nextJsonRpcMessageId = 1;
|
|
654
|
-
let lastKnownInboundSequenceNumber = 0;
|
|
655
|
-
let state = { __type: "disconnected" };
|
|
656
|
-
let socket;
|
|
657
|
-
let sessionEstablished = false;
|
|
658
|
-
let handleForceClose;
|
|
659
|
-
return {
|
|
660
|
-
close: () => {
|
|
661
|
-
socket.close();
|
|
662
|
-
handleForceClose();
|
|
663
|
-
},
|
|
664
|
-
wallet: new Promise((resolve, reject) => {
|
|
665
|
-
const jsonRpcResponsePromises = {};
|
|
666
|
-
const handleOpen = async () => {
|
|
667
|
-
if (state.__type !== "connecting") {
|
|
668
|
-
console.warn(`Expected adapter state to be \`connecting\` at the moment the websocket opens. Got \`${state.__type}\`.`);
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
socket.removeEventListener("open", handleOpen);
|
|
672
|
-
const { associationKeypair } = state;
|
|
673
|
-
const ecdhKeypair = await generateECDHKeypair();
|
|
674
|
-
socket.send(await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey));
|
|
675
|
-
state = {
|
|
676
|
-
__type: "hello_req_sent",
|
|
677
|
-
associationPublicKey: associationKeypair.publicKey,
|
|
678
|
-
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
679
|
-
};
|
|
680
|
-
};
|
|
681
|
-
const handleClose = (evt) => {
|
|
682
|
-
if (evt.wasClean) state = { __type: "disconnected" };
|
|
683
|
-
else reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED, `The wallet session dropped unexpectedly (${evt.code}: ${evt.reason}).`, { closeEvent: evt }));
|
|
684
|
-
disposeSocket();
|
|
685
|
-
};
|
|
686
|
-
const handleError = async (_evt) => {
|
|
687
|
-
disposeSocket();
|
|
688
|
-
if (Date.now() - connectionStartTime >= WEBSOCKET_CONNECTION_CONFIG.timeoutMs) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_TIMEOUT, `Failed to connect to the wallet websocket at ${websocketURL}.`));
|
|
689
|
-
else {
|
|
690
|
-
await new Promise((resolve) => {
|
|
691
|
-
const retryDelayMs = getNextRetryDelayMs();
|
|
692
|
-
retryWaitTimeoutId = window.setTimeout(resolve, retryDelayMs);
|
|
693
|
-
});
|
|
694
|
-
attemptSocketConnection();
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
const handleMessage = async (evt) => {
|
|
698
|
-
const responseBuffer = await evt.data.arrayBuffer();
|
|
699
|
-
switch (state.__type) {
|
|
700
|
-
case "connecting": {
|
|
701
|
-
if (responseBuffer.byteLength !== 0) throw new Error("Encountered unexpected message while connecting");
|
|
702
|
-
const ecdhKeypair = await generateECDHKeypair();
|
|
703
|
-
socket.send(await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey));
|
|
704
|
-
state = {
|
|
705
|
-
__type: "hello_req_sent",
|
|
706
|
-
associationPublicKey: associationKeypair.publicKey,
|
|
707
|
-
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
708
|
-
};
|
|
709
|
-
break;
|
|
710
|
-
}
|
|
711
|
-
case "connected":
|
|
712
|
-
try {
|
|
713
|
-
const sequenceNumber = getSequenceNumberFromByteArray(responseBuffer.slice(0, 4));
|
|
714
|
-
if (sequenceNumber !== lastKnownInboundSequenceNumber + 1) throw new Error("Encrypted message has invalid sequence number");
|
|
715
|
-
lastKnownInboundSequenceNumber = sequenceNumber;
|
|
716
|
-
const jsonRpcMessage = await decryptJsonRpcMessage(responseBuffer, state.sharedSecret);
|
|
717
|
-
const responsePromise = jsonRpcResponsePromises[jsonRpcMessage.id];
|
|
718
|
-
delete jsonRpcResponsePromises[jsonRpcMessage.id];
|
|
719
|
-
responsePromise.resolve(jsonRpcMessage.result);
|
|
720
|
-
} catch (e) {
|
|
721
|
-
if (e instanceof SolanaMobileWalletAdapterProtocolError) {
|
|
722
|
-
const responsePromise = jsonRpcResponsePromises[e.jsonRpcMessageId];
|
|
723
|
-
delete jsonRpcResponsePromises[e.jsonRpcMessageId];
|
|
724
|
-
responsePromise.reject(e);
|
|
725
|
-
} else throw e;
|
|
726
|
-
}
|
|
727
|
-
break;
|
|
728
|
-
case "hello_req_sent": {
|
|
729
|
-
if (responseBuffer.byteLength === 0) {
|
|
730
|
-
const ecdhKeypair = await generateECDHKeypair();
|
|
731
|
-
socket.send(await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey));
|
|
732
|
-
state = {
|
|
733
|
-
__type: "hello_req_sent",
|
|
734
|
-
associationPublicKey: associationKeypair.publicKey,
|
|
735
|
-
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
736
|
-
};
|
|
737
|
-
break;
|
|
738
|
-
}
|
|
739
|
-
const sharedSecret = await parseHelloRsp(responseBuffer, state.associationPublicKey, state.ecdhPrivateKey);
|
|
740
|
-
const sessionPropertiesBuffer = responseBuffer.slice(65);
|
|
741
|
-
const sessionProperties = sessionPropertiesBuffer.byteLength !== 0 ? await (async () => {
|
|
742
|
-
const sequenceNumber = getSequenceNumberFromByteArray(sessionPropertiesBuffer.slice(0, 4));
|
|
743
|
-
if (sequenceNumber !== lastKnownInboundSequenceNumber + 1) throw new Error("Encrypted message has invalid sequence number");
|
|
744
|
-
lastKnownInboundSequenceNumber = sequenceNumber;
|
|
745
|
-
return parseSessionProps(sessionPropertiesBuffer, sharedSecret);
|
|
746
|
-
})() : { protocol_version: "legacy" };
|
|
747
|
-
state = {
|
|
748
|
-
__type: "connected",
|
|
749
|
-
sharedSecret,
|
|
750
|
-
sessionProperties
|
|
751
|
-
};
|
|
752
|
-
const wallet = createMobileWalletProxy(sessionProperties.protocol_version, async (method, params) => {
|
|
753
|
-
const id = nextJsonRpcMessageId++;
|
|
754
|
-
socket.send(await encryptJsonRpcMessage({
|
|
755
|
-
id,
|
|
756
|
-
jsonrpc: "2.0",
|
|
757
|
-
method,
|
|
758
|
-
params: params ?? {}
|
|
759
|
-
}, sharedSecret));
|
|
760
|
-
return new Promise((resolve, reject) => {
|
|
761
|
-
jsonRpcResponsePromises[id] = {
|
|
762
|
-
resolve(result) {
|
|
763
|
-
switch (method) {
|
|
764
|
-
case "authorize":
|
|
765
|
-
case "reauthorize": {
|
|
766
|
-
const { wallet_uri_base } = result;
|
|
767
|
-
if (wallet_uri_base != null) try {
|
|
768
|
-
assertSecureEndpointSpecificURI(wallet_uri_base);
|
|
769
|
-
} catch (e) {
|
|
770
|
-
reject(e);
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
resolve(result);
|
|
777
|
-
},
|
|
778
|
-
reject
|
|
779
|
-
};
|
|
780
|
-
});
|
|
781
|
-
});
|
|
782
|
-
sessionEstablished = true;
|
|
783
|
-
try {
|
|
784
|
-
resolve(wallet);
|
|
785
|
-
} catch (e) {
|
|
786
|
-
reject(e);
|
|
787
|
-
}
|
|
788
|
-
break;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
handleForceClose = () => {
|
|
793
|
-
socket.removeEventListener("message", handleMessage);
|
|
794
|
-
disposeSocket();
|
|
795
|
-
if (!sessionEstablished) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED, `The wallet session was closed before connection.`, { closeEvent: new CloseEvent("socket was closed before connection") }));
|
|
796
|
-
};
|
|
797
|
-
let disposeSocket;
|
|
798
|
-
let retryWaitTimeoutId;
|
|
799
|
-
const attemptSocketConnection = () => {
|
|
800
|
-
if (disposeSocket) disposeSocket();
|
|
801
|
-
state = {
|
|
802
|
-
__type: "connecting",
|
|
803
|
-
associationKeypair
|
|
804
|
-
};
|
|
805
|
-
if (connectionStartTime === void 0) connectionStartTime = Date.now();
|
|
806
|
-
socket = new WebSocket(websocketURL, [WEBSOCKET_PROTOCOL_BINARY]);
|
|
807
|
-
socket.addEventListener("open", handleOpen);
|
|
808
|
-
socket.addEventListener("close", handleClose);
|
|
809
|
-
socket.addEventListener("error", handleError);
|
|
810
|
-
socket.addEventListener("message", handleMessage);
|
|
811
|
-
disposeSocket = () => {
|
|
812
|
-
window.clearTimeout(retryWaitTimeoutId);
|
|
813
|
-
socket.removeEventListener("open", handleOpen);
|
|
814
|
-
socket.removeEventListener("close", handleClose);
|
|
815
|
-
socket.removeEventListener("error", handleError);
|
|
816
|
-
socket.removeEventListener("message", handleMessage);
|
|
817
|
-
};
|
|
818
|
-
};
|
|
819
|
-
attemptSocketConnection();
|
|
820
|
-
})
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
async function startRemoteScenario(config) {
|
|
824
|
-
assertSecureContext();
|
|
825
|
-
const associationKeypair = await generateAssociationKeypair();
|
|
826
|
-
const websocketURL = `wss://${config?.remoteHostAuthority}/reflect`;
|
|
827
|
-
let connectionStartTime;
|
|
828
|
-
const getNextRetryDelayMs = (() => {
|
|
829
|
-
const schedule = [...WEBSOCKET_CONNECTION_CONFIG.retryDelayScheduleMs];
|
|
830
|
-
return () => schedule.length > 1 ? schedule.shift() : schedule[0];
|
|
831
|
-
})();
|
|
832
|
-
let nextJsonRpcMessageId = 1;
|
|
833
|
-
let lastKnownInboundSequenceNumber = 0;
|
|
834
|
-
let encoding;
|
|
835
|
-
let state = { __type: "disconnected" };
|
|
836
|
-
let socket;
|
|
837
|
-
let disposeSocket;
|
|
838
|
-
const decodeBytes = async (evt) => {
|
|
839
|
-
if (encoding == "base64") return toUint8Array$1(await evt.data).buffer;
|
|
840
|
-
else return await evt.data.arrayBuffer();
|
|
841
|
-
};
|
|
842
|
-
const associationUrl = await new Promise((resolve, reject) => {
|
|
843
|
-
const handleOpen = async () => {
|
|
844
|
-
if (state.__type !== "connecting") {
|
|
845
|
-
console.warn(`Expected adapter state to be \`connecting\` at the moment the websocket opens. Got \`${state.__type}\`.`);
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
if (socket.protocol.includes(WEBSOCKET_PROTOCOL_BASE64)) encoding = "base64";
|
|
849
|
-
else encoding = "binary";
|
|
850
|
-
socket.removeEventListener("open", handleOpen);
|
|
851
|
-
};
|
|
852
|
-
const handleClose = (evt) => {
|
|
853
|
-
if (evt.wasClean) state = { __type: "disconnected" };
|
|
854
|
-
else reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED, `The wallet session dropped unexpectedly (${evt.code}: ${evt.reason}).`, { closeEvent: evt }));
|
|
855
|
-
disposeSocket();
|
|
856
|
-
};
|
|
857
|
-
const handleError = async (_evt) => {
|
|
858
|
-
disposeSocket();
|
|
859
|
-
if (Date.now() - connectionStartTime >= WEBSOCKET_CONNECTION_CONFIG.timeoutMs) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_TIMEOUT, `Failed to connect to the wallet websocket at ${websocketURL}.`));
|
|
860
|
-
else {
|
|
861
|
-
await new Promise((resolve) => {
|
|
862
|
-
const retryDelayMs = getNextRetryDelayMs();
|
|
863
|
-
retryWaitTimeoutId = window.setTimeout(resolve, retryDelayMs);
|
|
864
|
-
});
|
|
865
|
-
attemptSocketConnection();
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
const handleReflectorIdMessage = async (evt) => {
|
|
869
|
-
const responseBuffer = await decodeBytes(evt);
|
|
870
|
-
if (state.__type === "connecting") {
|
|
871
|
-
if (responseBuffer.byteLength == 0) throw new Error("Encountered unexpected message while connecting");
|
|
872
|
-
const reflectorId = getReflectorIdFromByteArray(responseBuffer);
|
|
873
|
-
state = {
|
|
874
|
-
__type: "reflector_id_received",
|
|
875
|
-
reflectorId
|
|
876
|
-
};
|
|
877
|
-
const associationUrl = await getRemoteAssociateAndroidIntentURL(associationKeypair.publicKey, config.remoteHostAuthority, reflectorId, config?.baseUri);
|
|
878
|
-
socket.removeEventListener("message", handleReflectorIdMessage);
|
|
879
|
-
resolve(associationUrl);
|
|
880
|
-
}
|
|
881
|
-
};
|
|
882
|
-
let retryWaitTimeoutId;
|
|
883
|
-
const attemptSocketConnection = () => {
|
|
884
|
-
if (disposeSocket) disposeSocket();
|
|
885
|
-
state = {
|
|
886
|
-
__type: "connecting",
|
|
887
|
-
associationKeypair
|
|
888
|
-
};
|
|
889
|
-
if (connectionStartTime === void 0) connectionStartTime = Date.now();
|
|
890
|
-
socket = new WebSocket(websocketURL, [WEBSOCKET_PROTOCOL_BINARY, WEBSOCKET_PROTOCOL_BASE64]);
|
|
891
|
-
socket.addEventListener("open", handleOpen);
|
|
892
|
-
socket.addEventListener("close", handleClose);
|
|
893
|
-
socket.addEventListener("error", handleError);
|
|
894
|
-
socket.addEventListener("message", handleReflectorIdMessage);
|
|
895
|
-
disposeSocket = () => {
|
|
896
|
-
window.clearTimeout(retryWaitTimeoutId);
|
|
897
|
-
socket.removeEventListener("open", handleOpen);
|
|
898
|
-
socket.removeEventListener("close", handleClose);
|
|
899
|
-
socket.removeEventListener("error", handleError);
|
|
900
|
-
socket.removeEventListener("message", handleReflectorIdMessage);
|
|
901
|
-
};
|
|
902
|
-
};
|
|
903
|
-
attemptSocketConnection();
|
|
904
|
-
});
|
|
905
|
-
let sessionEstablished = false;
|
|
906
|
-
let handleClose;
|
|
907
|
-
return {
|
|
908
|
-
associationUrl,
|
|
909
|
-
close: () => {
|
|
910
|
-
socket.close();
|
|
911
|
-
handleClose();
|
|
912
|
-
},
|
|
913
|
-
wallet: new Promise((resolve, reject) => {
|
|
914
|
-
const jsonRpcResponsePromises = {};
|
|
915
|
-
const handleMessage = async (evt) => {
|
|
916
|
-
const responseBuffer = await decodeBytes(evt);
|
|
917
|
-
switch (state.__type) {
|
|
918
|
-
case "reflector_id_received": {
|
|
919
|
-
if (responseBuffer.byteLength !== 0) throw new Error("Encountered unexpected message while awaiting reflection");
|
|
920
|
-
const ecdhKeypair = await generateECDHKeypair();
|
|
921
|
-
const binaryMsg = await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey);
|
|
922
|
-
if (encoding == "base64") socket.send(fromUint8Array$1(binaryMsg));
|
|
923
|
-
else socket.send(binaryMsg);
|
|
924
|
-
state = {
|
|
925
|
-
__type: "hello_req_sent",
|
|
926
|
-
associationPublicKey: associationKeypair.publicKey,
|
|
927
|
-
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
928
|
-
};
|
|
929
|
-
break;
|
|
930
|
-
}
|
|
931
|
-
case "connected":
|
|
932
|
-
try {
|
|
933
|
-
const sequenceNumber = getSequenceNumberFromByteArray(responseBuffer.slice(0, 4));
|
|
934
|
-
if (sequenceNumber !== lastKnownInboundSequenceNumber + 1) throw new Error("Encrypted message has invalid sequence number");
|
|
935
|
-
lastKnownInboundSequenceNumber = sequenceNumber;
|
|
936
|
-
const jsonRpcMessage = await decryptJsonRpcMessage(responseBuffer, state.sharedSecret);
|
|
937
|
-
const responsePromise = jsonRpcResponsePromises[jsonRpcMessage.id];
|
|
938
|
-
delete jsonRpcResponsePromises[jsonRpcMessage.id];
|
|
939
|
-
responsePromise.resolve(jsonRpcMessage.result);
|
|
940
|
-
} catch (e) {
|
|
941
|
-
if (e instanceof SolanaMobileWalletAdapterProtocolError) {
|
|
942
|
-
const responsePromise = jsonRpcResponsePromises[e.jsonRpcMessageId];
|
|
943
|
-
delete jsonRpcResponsePromises[e.jsonRpcMessageId];
|
|
944
|
-
responsePromise.reject(e);
|
|
945
|
-
} else throw e;
|
|
946
|
-
}
|
|
947
|
-
break;
|
|
948
|
-
case "hello_req_sent": {
|
|
949
|
-
const sharedSecret = await parseHelloRsp(responseBuffer, state.associationPublicKey, state.ecdhPrivateKey);
|
|
950
|
-
const sessionPropertiesBuffer = responseBuffer.slice(65);
|
|
951
|
-
const sessionProperties = sessionPropertiesBuffer.byteLength !== 0 ? await (async () => {
|
|
952
|
-
const sequenceNumber = getSequenceNumberFromByteArray(sessionPropertiesBuffer.slice(0, 4));
|
|
953
|
-
if (sequenceNumber !== lastKnownInboundSequenceNumber + 1) throw new Error("Encrypted message has invalid sequence number");
|
|
954
|
-
lastKnownInboundSequenceNumber = sequenceNumber;
|
|
955
|
-
return parseSessionProps(sessionPropertiesBuffer, sharedSecret);
|
|
956
|
-
})() : { protocol_version: "legacy" };
|
|
957
|
-
state = {
|
|
958
|
-
__type: "connected",
|
|
959
|
-
sharedSecret,
|
|
960
|
-
sessionProperties
|
|
961
|
-
};
|
|
962
|
-
const wallet = createMobileWalletProxy(sessionProperties.protocol_version, async (method, params) => {
|
|
963
|
-
const id = nextJsonRpcMessageId++;
|
|
964
|
-
const binaryMsg = await encryptJsonRpcMessage({
|
|
965
|
-
id,
|
|
966
|
-
jsonrpc: "2.0",
|
|
967
|
-
method,
|
|
968
|
-
params: params ?? {}
|
|
969
|
-
}, sharedSecret);
|
|
970
|
-
if (encoding == "base64") socket.send(fromUint8Array$1(binaryMsg));
|
|
971
|
-
else socket.send(binaryMsg);
|
|
972
|
-
return new Promise((resolve, reject) => {
|
|
973
|
-
jsonRpcResponsePromises[id] = {
|
|
974
|
-
resolve(result) {
|
|
975
|
-
switch (method) {
|
|
976
|
-
case "authorize":
|
|
977
|
-
case "reauthorize": {
|
|
978
|
-
const { wallet_uri_base } = result;
|
|
979
|
-
if (wallet_uri_base != null) try {
|
|
980
|
-
assertSecureEndpointSpecificURI(wallet_uri_base);
|
|
981
|
-
} catch (e) {
|
|
982
|
-
reject(e);
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
|
-
break;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
resolve(result);
|
|
989
|
-
},
|
|
990
|
-
reject
|
|
991
|
-
};
|
|
992
|
-
});
|
|
993
|
-
});
|
|
994
|
-
sessionEstablished = true;
|
|
995
|
-
try {
|
|
996
|
-
resolve(wallet);
|
|
997
|
-
} catch (e) {
|
|
998
|
-
reject(e);
|
|
999
|
-
}
|
|
1000
|
-
break;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
};
|
|
1004
|
-
socket.addEventListener("message", handleMessage);
|
|
1005
|
-
handleClose = () => {
|
|
1006
|
-
socket.removeEventListener("message", handleMessage);
|
|
1007
|
-
disposeSocket();
|
|
1008
|
-
if (!sessionEstablished) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED, `The wallet session was closed before connection.`, { closeEvent: new CloseEvent("socket was closed before connection") }));
|
|
1009
|
-
};
|
|
1010
|
-
})
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
/** Name of the feature. */
|
|
1015
|
-
const StandardConnect = 'standard:connect';
|
|
1016
|
-
|
|
1017
|
-
/** Name of the feature. */
|
|
1018
|
-
const StandardDisconnect = 'standard:disconnect';
|
|
1019
|
-
|
|
1020
|
-
/** Name of the feature. */
|
|
1021
|
-
const StandardEvents = 'standard:events';
|
|
1022
|
-
|
|
1023
20
|
var browser = {};
|
|
1024
21
|
|
|
1025
22
|
var canPromise;
|
|
@@ -4092,239 +3089,55 @@ function requireBrowser () {
|
|
|
4092
3089
|
var browserExports = requireBrowser();
|
|
4093
3090
|
var QRCode = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
4094
3091
|
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
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");
|
|
4098
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
4099
|
-
};
|
|
4100
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
4101
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4102
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4103
|
-
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");
|
|
4104
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
4105
|
-
};
|
|
4106
|
-
var _RegisterWalletEvent_detail;
|
|
4107
|
-
/**
|
|
4108
|
-
* Register a {@link "@wallet-standard/base".Wallet} as a Standard Wallet with the app.
|
|
4109
|
-
*
|
|
4110
|
-
* This dispatches a {@link "@wallet-standard/base".WindowRegisterWalletEvent} to notify the app that the Wallet is
|
|
4111
|
-
* ready to be registered.
|
|
4112
|
-
*
|
|
4113
|
-
* This also adds a listener for {@link "@wallet-standard/base".WindowAppReadyEvent} to listen for a notification from
|
|
4114
|
-
* the app that the app is ready to register the Wallet.
|
|
4115
|
-
*
|
|
4116
|
-
* This combination of event dispatch and listener guarantees that the Wallet will be registered synchronously as soon
|
|
4117
|
-
* as the app is ready whether the Wallet loads before or after the app.
|
|
4118
|
-
*
|
|
4119
|
-
* @param wallet Wallet to register.
|
|
4120
|
-
*
|
|
4121
|
-
* @group Wallet
|
|
4122
|
-
*/
|
|
4123
|
-
function registerWallet(wallet) {
|
|
4124
|
-
const callback = ({ register }) => register(wallet);
|
|
4125
|
-
try {
|
|
4126
|
-
window.dispatchEvent(new RegisterWalletEvent(callback));
|
|
4127
|
-
}
|
|
4128
|
-
catch (error) {
|
|
4129
|
-
console.error('wallet-standard:register-wallet event could not be dispatched\n', error);
|
|
4130
|
-
}
|
|
4131
|
-
try {
|
|
4132
|
-
window.addEventListener('wallet-standard:app-ready', ({ detail: api }) => callback(api));
|
|
4133
|
-
}
|
|
4134
|
-
catch (error) {
|
|
4135
|
-
console.error('wallet-standard:app-ready event listener could not be added\n', error);
|
|
4136
|
-
}
|
|
4137
|
-
}
|
|
4138
|
-
class RegisterWalletEvent extends Event {
|
|
4139
|
-
get detail() {
|
|
4140
|
-
return __classPrivateFieldGet(this, _RegisterWalletEvent_detail, "f");
|
|
4141
|
-
}
|
|
4142
|
-
get type() {
|
|
4143
|
-
return 'wallet-standard:register-wallet';
|
|
4144
|
-
}
|
|
4145
|
-
constructor(callback) {
|
|
4146
|
-
super('wallet-standard:register-wallet', {
|
|
4147
|
-
bubbles: false,
|
|
4148
|
-
cancelable: false,
|
|
4149
|
-
composed: false,
|
|
4150
|
-
});
|
|
4151
|
-
_RegisterWalletEvent_detail.set(this, void 0);
|
|
4152
|
-
__classPrivateFieldSet(this, _RegisterWalletEvent_detail, callback, "f");
|
|
4153
|
-
}
|
|
4154
|
-
/** @deprecated */
|
|
4155
|
-
preventDefault() {
|
|
4156
|
-
throw new Error('preventDefault cannot be called');
|
|
4157
|
-
}
|
|
4158
|
-
/** @deprecated */
|
|
4159
|
-
stopImmediatePropagation() {
|
|
4160
|
-
throw new Error('stopImmediatePropagation cannot be called');
|
|
4161
|
-
}
|
|
4162
|
-
/** @deprecated */
|
|
4163
|
-
stopPropagation() {
|
|
4164
|
-
throw new Error('stopPropagation cannot be called');
|
|
4165
|
-
}
|
|
4166
|
-
}
|
|
4167
|
-
_RegisterWalletEvent_detail = new WeakMap();
|
|
3092
|
+
/** Name of the feature. */
|
|
3093
|
+
const StandardConnect = 'standard:connect';
|
|
4168
3094
|
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
4172
|
-
}
|
|
4173
|
-
function toUint8Array(base64EncodedByteArray) {
|
|
4174
|
-
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
4175
|
-
}
|
|
4176
|
-
//#endregion
|
|
4177
|
-
//#region src/embedded-modal/loadingSpinner.ts
|
|
4178
|
-
const modalHtml$1 = `
|
|
4179
|
-
<div class="mobile-wallet-adapter-embedded-loading-indicator" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
|
4180
|
-
<div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
|
|
4181
|
-
<div class="mobile-wallet-adapter-embedded-loading-container">
|
|
4182
|
-
<div class="mobile-wallet-adapter-embedded-loading-animation"></div>
|
|
4183
|
-
</div>
|
|
4184
|
-
</div>
|
|
4185
|
-
`;
|
|
4186
|
-
const css$6 = `
|
|
4187
|
-
.mobile-wallet-adapter-embedded-loading-indicator {
|
|
4188
|
-
display: flex; /* Use flexbox to center content */
|
|
4189
|
-
justify-content: center; /* Center horizontally */
|
|
4190
|
-
align-items: start; /* Center vertically */
|
|
4191
|
-
position: fixed; /* Stay in place */
|
|
4192
|
-
z-index: 1; /* Sit on top */
|
|
4193
|
-
left: 0;
|
|
4194
|
-
top: 0;
|
|
4195
|
-
width: 100%; /* Full width */
|
|
4196
|
-
height: 100%; /* Full height */
|
|
4197
|
-
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
|
|
4198
|
-
overflow-y: auto; /* enable scrolling */
|
|
4199
|
-
}
|
|
3095
|
+
/** Name of the feature. */
|
|
3096
|
+
const StandardDisconnect = 'standard:disconnect';
|
|
4200
3097
|
|
|
4201
|
-
.
|
|
4202
|
-
|
|
4203
|
-
margin: auto;
|
|
4204
|
-
}
|
|
3098
|
+
/** Name of the feature. */
|
|
3099
|
+
const StandardEvents = 'standard:events';
|
|
4205
3100
|
|
|
4206
|
-
.
|
|
4207
|
-
|
|
4208
|
-
left: -9999px;
|
|
4209
|
-
width: 10px;
|
|
4210
|
-
height: 10px;
|
|
4211
|
-
border-radius: 5px;
|
|
4212
|
-
background-color: var(--spinner-color);
|
|
4213
|
-
color: var(--spinner-color);
|
|
4214
|
-
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
4215
|
-
9999px 0 0 0 var(--spinner-color),
|
|
4216
|
-
10014px 0 0 0 var(--spinner-color);
|
|
4217
|
-
animation: dot-typing 1.5s infinite linear;
|
|
4218
|
-
}
|
|
3101
|
+
/** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */
|
|
3102
|
+
const SOLANA_MAINNET_CHAIN = 'solana:mainnet';
|
|
4219
3103
|
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
10014px 0 0 0 var(--spinner-color);
|
|
4255
|
-
}
|
|
3104
|
+
/******************************************************************************
|
|
3105
|
+
Copyright (c) Microsoft Corporation.
|
|
3106
|
+
|
|
3107
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
3108
|
+
purpose with or without fee is hereby granted.
|
|
3109
|
+
|
|
3110
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
3111
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
3112
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
3113
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
3114
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
3115
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
3116
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
3117
|
+
***************************************************************************** */
|
|
3118
|
+
|
|
3119
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
3120
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3121
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3122
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3123
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3124
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3125
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
3126
|
+
});
|
|
3127
|
+
}
|
|
3128
|
+
|
|
3129
|
+
function __classPrivateFieldGet$1(receiver, state, kind, f) {
|
|
3130
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3131
|
+
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");
|
|
3132
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
function __classPrivateFieldSet$1(receiver, state, value, kind, f) {
|
|
3136
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
3137
|
+
return (state.set(receiver, value)), value;
|
|
4256
3138
|
}
|
|
4257
|
-
|
|
4258
|
-
var
|
|
4259
|
-
#root = null;
|
|
4260
|
-
#eventListeners = {};
|
|
4261
|
-
#listenersAttached = false;
|
|
4262
|
-
dom = null;
|
|
4263
|
-
constructor() {
|
|
4264
|
-
this.init = this.init.bind(this);
|
|
4265
|
-
this.#root = document.getElementById("mobile-wallet-adapter-embedded-root-ui");
|
|
4266
|
-
}
|
|
4267
|
-
async init() {
|
|
4268
|
-
console.log("Injecting modal");
|
|
4269
|
-
this.#injectHTML();
|
|
4270
|
-
}
|
|
4271
|
-
open = () => {
|
|
4272
|
-
console.debug("Modal open");
|
|
4273
|
-
this.#attachEventListeners();
|
|
4274
|
-
if (this.#root) this.#root.style.display = "flex";
|
|
4275
|
-
};
|
|
4276
|
-
close = (event = void 0) => {
|
|
4277
|
-
console.debug("Modal close");
|
|
4278
|
-
this.#removeEventListeners();
|
|
4279
|
-
if (this.#root) this.#root.style.display = "none";
|
|
4280
|
-
this.#eventListeners["close"]?.forEach((listener) => listener(event));
|
|
4281
|
-
};
|
|
4282
|
-
addEventListener(event, listener) {
|
|
4283
|
-
this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
|
|
4284
|
-
return () => this.removeEventListener(event, listener);
|
|
4285
|
-
}
|
|
4286
|
-
removeEventListener(event, listener) {
|
|
4287
|
-
this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
4288
|
-
}
|
|
4289
|
-
#injectHTML() {
|
|
4290
|
-
if (this.dom) return;
|
|
4291
|
-
this.#root = document.createElement("div");
|
|
4292
|
-
this.#root.id = "mobile-wallet-adapter-embedded-root-ui";
|
|
4293
|
-
this.#root.innerHTML = modalHtml$1;
|
|
4294
|
-
this.#root.style.display = "none";
|
|
4295
|
-
const styles = document.createElement("style");
|
|
4296
|
-
styles.id = "mobile-wallet-adapter-embedded-modal-styles";
|
|
4297
|
-
styles.textContent = css$6;
|
|
4298
|
-
const host = document.createElement("div");
|
|
4299
|
-
this.dom = host.attachShadow({ mode: "closed" });
|
|
4300
|
-
host.style.setProperty("--spinner-color", "#FFFFFF");
|
|
4301
|
-
this.dom.appendChild(styles);
|
|
4302
|
-
this.dom.appendChild(this.#root);
|
|
4303
|
-
document.body.appendChild(host);
|
|
4304
|
-
}
|
|
4305
|
-
#attachEventListeners() {
|
|
4306
|
-
if (!this.#root || this.#listenersAttached) return;
|
|
4307
|
-
[...this.#root.querySelectorAll("[data-modal-close]")].forEach((closer) => closer?.addEventListener("click", (event) => {
|
|
4308
|
-
this.close(event);
|
|
4309
|
-
}));
|
|
4310
|
-
window.addEventListener("load", this.close);
|
|
4311
|
-
document.addEventListener("keydown", this.#handleKeyDown);
|
|
4312
|
-
this.#listenersAttached = true;
|
|
4313
|
-
}
|
|
4314
|
-
#removeEventListeners() {
|
|
4315
|
-
if (!this.#listenersAttached) return;
|
|
4316
|
-
window.removeEventListener("load", this.close);
|
|
4317
|
-
document.removeEventListener("keydown", this.#handleKeyDown);
|
|
4318
|
-
if (!this.#root) return;
|
|
4319
|
-
[...this.#root.querySelectorAll("[data-modal-close]")].forEach((closer) => closer?.removeEventListener("click", this.close));
|
|
4320
|
-
this.#listenersAttached = false;
|
|
4321
|
-
}
|
|
4322
|
-
#handleKeyDown = (event) => {
|
|
4323
|
-
if (event.key === "Escape") this.close(event);
|
|
4324
|
-
};
|
|
4325
|
-
};
|
|
4326
|
-
//#endregion
|
|
4327
|
-
//#region src/embedded-modal/modal.ts
|
|
3139
|
+
|
|
3140
|
+
var _EmbeddedModal_instances, _EmbeddedModal_root, _EmbeddedModal_eventListeners, _EmbeddedModal_listenersAttached, _EmbeddedModal_injectHTML, _EmbeddedModal_attachEventListeners, _EmbeddedModal_removeEventListeners, _EmbeddedModal_handleKeyDown;
|
|
4328
3141
|
const modalHtml = `
|
|
4329
3142
|
<div class="mobile-wallet-adapter-embedded-modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
|
4330
3143
|
<div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
|
|
@@ -4340,13 +3153,13 @@ const modalHtml = `
|
|
|
4340
3153
|
</div>
|
|
4341
3154
|
</div>
|
|
4342
3155
|
`;
|
|
4343
|
-
const css$
|
|
3156
|
+
const css$2 = `
|
|
4344
3157
|
.mobile-wallet-adapter-embedded-modal-container {
|
|
4345
3158
|
display: flex; /* Use flexbox to center content */
|
|
4346
3159
|
justify-content: center; /* Center horizontally */
|
|
4347
3160
|
align-items: center; /* Center vertically */
|
|
4348
3161
|
position: fixed; /* Stay in place */
|
|
4349
|
-
z-index:
|
|
3162
|
+
z-index: 1; /* Sit on top */
|
|
4350
3163
|
left: 0;
|
|
4351
3164
|
top: 0;
|
|
4352
3165
|
width: 100%; /* Full width */
|
|
@@ -4402,100 +3215,134 @@ const fonts = `
|
|
|
4402
3215
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
4403
3216
|
<link href="https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
|
|
4404
3217
|
`;
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
};
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
3218
|
+
class EmbeddedModal {
|
|
3219
|
+
constructor() {
|
|
3220
|
+
_EmbeddedModal_instances.add(this);
|
|
3221
|
+
_EmbeddedModal_root.set(this, null);
|
|
3222
|
+
_EmbeddedModal_eventListeners.set(this, {});
|
|
3223
|
+
_EmbeddedModal_listenersAttached.set(this, false);
|
|
3224
|
+
this.dom = null;
|
|
3225
|
+
this.open = () => {
|
|
3226
|
+
console.debug('Modal open');
|
|
3227
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_attachEventListeners).call(this);
|
|
3228
|
+
if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
|
|
3229
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'flex';
|
|
3230
|
+
}
|
|
3231
|
+
};
|
|
3232
|
+
this.close = (event = undefined) => {
|
|
3233
|
+
var _a;
|
|
3234
|
+
console.debug('Modal close');
|
|
3235
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_removeEventListeners).call(this);
|
|
3236
|
+
if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
|
|
3237
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
|
|
3238
|
+
}
|
|
3239
|
+
(_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")['close']) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener(event));
|
|
3240
|
+
};
|
|
3241
|
+
_EmbeddedModal_handleKeyDown.set(this, (event) => {
|
|
3242
|
+
if (event.key === 'Escape')
|
|
3243
|
+
this.close(event);
|
|
3244
|
+
});
|
|
3245
|
+
// Bind methods to ensure `this` context is correct
|
|
3246
|
+
this.init = this.init.bind(this);
|
|
3247
|
+
__classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'));
|
|
3248
|
+
}
|
|
3249
|
+
init() {
|
|
3250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3251
|
+
console.log('Injecting modal');
|
|
3252
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_injectHTML).call(this);
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3255
|
+
addEventListener(event, listener) {
|
|
3256
|
+
var _a;
|
|
3257
|
+
((_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = [listener]);
|
|
3258
|
+
return () => this.removeEventListener(event, listener);
|
|
3259
|
+
}
|
|
3260
|
+
removeEventListener(event, listener) {
|
|
3261
|
+
var _a;
|
|
3262
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
_EmbeddedModal_root = new WeakMap(), _EmbeddedModal_eventListeners = new WeakMap(), _EmbeddedModal_listenersAttached = new WeakMap(), _EmbeddedModal_handleKeyDown = new WeakMap(), _EmbeddedModal_instances = new WeakSet(), _EmbeddedModal_injectHTML = function _EmbeddedModal_injectHTML() {
|
|
3266
|
+
// Check if the HTML has already been injected
|
|
3267
|
+
if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
|
|
3268
|
+
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
|
|
3269
|
+
__classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'));
|
|
3270
|
+
return;
|
|
3271
|
+
}
|
|
3272
|
+
// Create a container for the modal
|
|
3273
|
+
__classPrivateFieldSet$1(this, _EmbeddedModal_root, document.createElement('div'));
|
|
3274
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").id = 'mobile-wallet-adapter-embedded-root-ui';
|
|
3275
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").innerHTML = modalHtml;
|
|
3276
|
+
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
|
|
3277
|
+
// Add modal content
|
|
3278
|
+
const content = __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelector('.mobile-wallet-adapter-embedded-modal-content');
|
|
3279
|
+
if (content)
|
|
3280
|
+
content.innerHTML = this.contentHtml;
|
|
3281
|
+
// Apply styles
|
|
3282
|
+
const styles = document.createElement('style');
|
|
3283
|
+
styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
|
|
3284
|
+
styles.textContent = css$2 + this.contentStyles;
|
|
3285
|
+
// Create a shadow DOM to encapsulate the modal
|
|
3286
|
+
const host = document.createElement('div');
|
|
3287
|
+
host.innerHTML = fonts;
|
|
3288
|
+
this.dom = host.attachShadow({ mode: 'closed' });
|
|
3289
|
+
this.dom.appendChild(styles);
|
|
3290
|
+
this.dom.appendChild(__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"));
|
|
3291
|
+
// Append the shadow DOM host to the body
|
|
3292
|
+
document.body.appendChild(host);
|
|
3293
|
+
}, _EmbeddedModal_attachEventListeners = function _EmbeddedModal_attachEventListeners() {
|
|
3294
|
+
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f") || __classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
|
|
3295
|
+
return;
|
|
3296
|
+
const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
|
|
3297
|
+
closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.addEventListener('click', this.close));
|
|
3298
|
+
window.addEventListener('load', this.close);
|
|
3299
|
+
document.addEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
|
|
3300
|
+
__classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, true);
|
|
3301
|
+
}, _EmbeddedModal_removeEventListeners = function _EmbeddedModal_removeEventListeners() {
|
|
3302
|
+
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
|
|
3303
|
+
return;
|
|
3304
|
+
window.removeEventListener('load', this.close);
|
|
3305
|
+
document.removeEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
|
|
3306
|
+
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
|
|
3307
|
+
return;
|
|
3308
|
+
const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
|
|
3309
|
+
closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.removeEventListener('click', this.close));
|
|
3310
|
+
__classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, false);
|
|
4498
3311
|
};
|
|
3312
|
+
|
|
3313
|
+
class RemoteConnectionModal extends EmbeddedModal {
|
|
3314
|
+
constructor() {
|
|
3315
|
+
super(...arguments);
|
|
3316
|
+
this.contentStyles = css$1;
|
|
3317
|
+
this.contentHtml = QRCodeHtml;
|
|
3318
|
+
}
|
|
3319
|
+
initWithQR(qrCode) {
|
|
3320
|
+
const _super = Object.create(null, {
|
|
3321
|
+
init: { get: () => super.init }
|
|
3322
|
+
});
|
|
3323
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3324
|
+
_super.init.call(this);
|
|
3325
|
+
this.populateQRCode(qrCode);
|
|
3326
|
+
});
|
|
3327
|
+
}
|
|
3328
|
+
populateQRCode(qrUrl) {
|
|
3329
|
+
var _a;
|
|
3330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3331
|
+
const qrcodeContainer = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
|
|
3332
|
+
if (qrcodeContainer) {
|
|
3333
|
+
const qrCodeElement = yield QRCode.toCanvas(qrUrl, { width: 200, margin: 0 });
|
|
3334
|
+
if (qrcodeContainer.firstElementChild !== null) {
|
|
3335
|
+
qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
|
|
3336
|
+
}
|
|
3337
|
+
else
|
|
3338
|
+
qrcodeContainer.appendChild(qrCodeElement);
|
|
3339
|
+
}
|
|
3340
|
+
else {
|
|
3341
|
+
console.error('QRCode Container not found');
|
|
3342
|
+
}
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
4499
3346
|
const QRCodeHtml = `
|
|
4500
3347
|
<div class="mobile-wallet-adapter-embedded-modal-qr-content">
|
|
4501
3348
|
<div>
|
|
@@ -4511,9 +3358,7 @@ const QRCodeHtml = `
|
|
|
4511
3358
|
Open your wallet and scan this code
|
|
4512
3359
|
</h4>
|
|
4513
3360
|
</div>
|
|
4514
|
-
<div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container">
|
|
4515
|
-
<div id="mobile-wallet-adapter-embedded-modal-qr-placeholder" class="mobile-wallet-adapter-embedded-modal-qr-placeholder"></div>
|
|
4516
|
-
</div>
|
|
3361
|
+
<div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container"></div>
|
|
4517
3362
|
</div>
|
|
4518
3363
|
</div>
|
|
4519
3364
|
<div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
|
|
@@ -4540,7 +3385,7 @@ const QRCodeHtml = `
|
|
|
4540
3385
|
</div>
|
|
4541
3386
|
</div>
|
|
4542
3387
|
`;
|
|
4543
|
-
const css$
|
|
3388
|
+
const css$1 = `
|
|
4544
3389
|
.mobile-wallet-adapter-embedded-modal-qr-content {
|
|
4545
3390
|
display: flex;
|
|
4546
3391
|
margin-top: 10px;
|
|
@@ -4584,16 +3429,6 @@ const css$4 = `
|
|
|
4584
3429
|
margin-left: auto;
|
|
4585
3430
|
}
|
|
4586
3431
|
|
|
4587
|
-
.mobile-wallet-adapter-embedded-modal-qr-placeholder {
|
|
4588
|
-
margin-left: auto;
|
|
4589
|
-
min-width: 200px;
|
|
4590
|
-
min-height: 200px;
|
|
4591
|
-
background: linear-gradient(-60deg, #F7F8F8 30%, #ECEEEE 50%, #F7F8F8 70%);
|
|
4592
|
-
background-size: 200%;
|
|
4593
|
-
animation: placeholderAnimate 2.7s linear infinite;
|
|
4594
|
-
border-radius: 12px;
|
|
4595
|
-
}
|
|
4596
|
-
|
|
4597
3432
|
.mobile-wallet-adapter-embedded-modal-divider {
|
|
4598
3433
|
margin-top: 20px;
|
|
4599
3434
|
padding-left: 10px;
|
|
@@ -4666,15 +3501,6 @@ const css$4 = `
|
|
|
4666
3501
|
.mobile-wallet-adapter-embedded-modal-qr-code-container {
|
|
4667
3502
|
margin: auto;
|
|
4668
3503
|
}
|
|
4669
|
-
.mobile-wallet-adapter-embedded-modal-qr-placeholder {
|
|
4670
|
-
margin: auto;
|
|
4671
|
-
}
|
|
4672
|
-
}
|
|
4673
|
-
|
|
4674
|
-
/* QR Placeholder */
|
|
4675
|
-
@keyframes placeholderAnimate {
|
|
4676
|
-
0% { background-position: 200% 0; }
|
|
4677
|
-
100% { background-position: -200% 0; }
|
|
4678
3504
|
}
|
|
4679
3505
|
|
|
4680
3506
|
/* Spinner */
|
|
@@ -4755,1173 +3581,962 @@ const css$4 = `
|
|
|
4755
3581
|
animation: spinRight 2.5s cubic-bezier(.2,0,.8,1) infinite;
|
|
4756
3582
|
}
|
|
4757
3583
|
`;
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
initWithCallback(callback) {
|
|
4764
|
-
super.init();
|
|
4765
|
-
this.#prepareLaunchAction(callback);
|
|
4766
|
-
}
|
|
4767
|
-
#prepareLaunchAction(callback) {
|
|
4768
|
-
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
4769
|
-
const listener = async () => {
|
|
4770
|
-
launchButton?.removeEventListener("click", listener);
|
|
4771
|
-
this.close();
|
|
4772
|
-
callback();
|
|
4773
|
-
};
|
|
4774
|
-
launchButton?.addEventListener("click", listener);
|
|
4775
|
-
}
|
|
4776
|
-
};
|
|
4777
|
-
const ErrorDialogHtml$3 = `
|
|
4778
|
-
<svg class="mobile-wallet-adapter-embedded-modal-launch-icon" width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
4779
|
-
<path d="M21.6 48C7.2 48 0 40.8 0 26.4V21.6C0 7.2 7.2 0 21.6 0H26.4C40.8 0 48 7.2 48 21.6V26.4C48 40.8 40.8 48 26.4 48H21.6Z" fill="#15994E"/>
|
|
4780
|
-
<mask id="mask0_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
4781
|
-
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
4782
|
-
</mask>
|
|
4783
|
-
<g mask="url(#mask0_189_522)">
|
|
4784
|
-
<mask id="mask1_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
4785
|
-
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
4786
|
-
</mask>
|
|
4787
|
-
<g mask="url(#mask1_189_522)">
|
|
4788
|
-
<path d="M22.1092 26.1208L19.4498 23.4615C19.1736 23.1851 18.8253 23.0468 18.4048 23.0468C17.9846 23.0468 17.6363 23.1851 17.3598 23.4615C17.0836 23.7377 16.9468 24.0861 16.9495 24.5065C16.9522 24.9267 17.0916 25.275 17.3678 25.5512L21.0405 29.2238C21.3463 29.5276 21.7031 29.6795 22.1108 29.6795C22.5184 29.6795 22.8742 29.5276 23.1782 29.2238L30.5918 21.8098C30.8683 21.5336 31.0065 21.1867 31.0065 20.7692C31.0065 20.3514 30.8683 20.0044 30.5918 19.7282C30.3156 19.4517 29.9673 19.3135 29.5468 19.3135C29.1266 19.3135 28.7784 19.4517 28.5022 19.7282L22.1092 26.1208ZM23.9998 37.6042C22.113 37.6042 20.3425 37.2473 18.6885 36.5335C17.0343 35.8197 15.5954 34.8512 14.3718 33.6278C13.1485 32.4043 12.18 30.9654 11.4662 29.3112C10.7524 27.6572 10.3955 25.8867 10.3955 23.9998C10.3955 22.113 10.7524 20.3425 11.4662 18.6885C12.18 17.0343 13.1485 15.5954 14.3718 14.3718C15.5954 13.1485 17.0343 12.18 18.6885 11.4662C20.3425 10.7524 22.113 10.3955 23.9998 10.3955C25.8867 10.3955 27.6572 10.7524 29.3112 11.4662C30.9654 12.18 32.4043 13.1485 33.6278 14.3718C34.8512 15.5954 35.8197 17.0343 36.5335 18.6885C37.2473 20.3425 37.6042 22.113 37.6042 23.9998C37.6042 25.8867 37.2473 27.6572 36.5335 29.3112C35.8197 30.9654 34.8512 32.4043 33.6278 33.6278C32.4043 34.8512 30.9654 35.8197 29.3112 36.5335C27.6572 37.2473 25.8867 37.6042 23.9998 37.6042Z" fill="white"/>
|
|
4789
|
-
</g>
|
|
4790
|
-
</g>
|
|
4791
|
-
</svg>
|
|
4792
|
-
<div class="mobile-wallet-adapter-embedded-modal-title">Ready to connect!</div>
|
|
4793
|
-
<div>
|
|
4794
|
-
<button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
|
|
4795
|
-
Connect Wallet
|
|
4796
|
-
</button>
|
|
4797
|
-
</div>
|
|
4798
|
-
`;
|
|
4799
|
-
const css$3 = `
|
|
4800
|
-
.mobile-wallet-adapter-embedded-modal-close {
|
|
4801
|
-
display: none;
|
|
4802
|
-
}
|
|
4803
|
-
.mobile-wallet-adapter-embedded-modal-content {
|
|
4804
|
-
text-align: center;
|
|
4805
|
-
min-width: 300px;
|
|
4806
|
-
}
|
|
4807
|
-
.mobile-wallet-adapter-embedded-modal-launch-icon {
|
|
4808
|
-
margin-top: 24px;
|
|
4809
|
-
}
|
|
4810
|
-
.mobile-wallet-adapter-embedded-modal-title {
|
|
4811
|
-
margin: 18px 100px 30px 100px;
|
|
4812
|
-
color: #000000;
|
|
4813
|
-
font-size: 2.75em;
|
|
4814
|
-
font-weight: 600;
|
|
3584
|
+
|
|
3585
|
+
const icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=';
|
|
3586
|
+
|
|
3587
|
+
function fromUint8Array(byteArray) {
|
|
3588
|
+
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
4815
3589
|
}
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
background: #000000;
|
|
4822
|
-
color: #FFFFFF;
|
|
4823
|
-
border-radius: 18px;
|
|
3590
|
+
function toUint8Array(base64EncodedByteArray) {
|
|
3591
|
+
return new Uint8Array(window
|
|
3592
|
+
.atob(base64EncodedByteArray)
|
|
3593
|
+
.split('')
|
|
3594
|
+
.map((c) => c.charCodeAt(0)));
|
|
4824
3595
|
}
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
3596
|
+
|
|
3597
|
+
var _LocalSolanaMobileWalletAdapterWallet_instances, _LocalSolanaMobileWalletAdapterWallet_listeners, _LocalSolanaMobileWalletAdapterWallet_version, _LocalSolanaMobileWalletAdapterWallet_name, _LocalSolanaMobileWalletAdapterWallet_url, _LocalSolanaMobileWalletAdapterWallet_icon, _LocalSolanaMobileWalletAdapterWallet_appIdentity, _LocalSolanaMobileWalletAdapterWallet_authorization, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, _LocalSolanaMobileWalletAdapterWallet_connecting, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, _LocalSolanaMobileWalletAdapterWallet_chains, _LocalSolanaMobileWalletAdapterWallet_chainSelector, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, _LocalSolanaMobileWalletAdapterWallet_on, _LocalSolanaMobileWalletAdapterWallet_emit, _LocalSolanaMobileWalletAdapterWallet_off, _LocalSolanaMobileWalletAdapterWallet_connect, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, _LocalSolanaMobileWalletAdapterWallet_disconnect, _LocalSolanaMobileWalletAdapterWallet_transact, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signTransaction, _LocalSolanaMobileWalletAdapterWallet_signMessage, _LocalSolanaMobileWalletAdapterWallet_signIn, _LocalSolanaMobileWalletAdapterWallet_performSignIn, _RemoteSolanaMobileWalletAdapterWallet_instances, _RemoteSolanaMobileWalletAdapterWallet_listeners, _RemoteSolanaMobileWalletAdapterWallet_version, _RemoteSolanaMobileWalletAdapterWallet_name, _RemoteSolanaMobileWalletAdapterWallet_url, _RemoteSolanaMobileWalletAdapterWallet_icon, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, _RemoteSolanaMobileWalletAdapterWallet_authorization, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, _RemoteSolanaMobileWalletAdapterWallet_connecting, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, _RemoteSolanaMobileWalletAdapterWallet_chains, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, _RemoteSolanaMobileWalletAdapterWallet_session, _RemoteSolanaMobileWalletAdapterWallet_on, _RemoteSolanaMobileWalletAdapterWallet_emit, _RemoteSolanaMobileWalletAdapterWallet_off, _RemoteSolanaMobileWalletAdapterWallet_connect, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, _RemoteSolanaMobileWalletAdapterWallet_disconnect, _RemoteSolanaMobileWalletAdapterWallet_transact, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, _RemoteSolanaMobileWalletAdapterWallet_signMessage, _RemoteSolanaMobileWalletAdapterWallet_signIn, _RemoteSolanaMobileWalletAdapterWallet_performSignIn;
|
|
3598
|
+
const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
|
|
3599
|
+
const SolanaMobileWalletAdapterRemoteWalletName = 'Remote Mobile Wallet Adapter';
|
|
3600
|
+
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
3601
|
+
const DEFAULT_FEATURES = [SolanaSignAndSendTransaction, SolanaSignTransaction, SolanaSignMessage, SolanaSignIn];
|
|
3602
|
+
class LocalSolanaMobileWalletAdapterWallet {
|
|
3603
|
+
constructor(config) {
|
|
3604
|
+
_LocalSolanaMobileWalletAdapterWallet_instances.add(this);
|
|
3605
|
+
_LocalSolanaMobileWalletAdapterWallet_listeners.set(this, {});
|
|
3606
|
+
_LocalSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
|
|
3607
|
+
_LocalSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterWalletName);
|
|
3608
|
+
_LocalSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
|
|
3609
|
+
_LocalSolanaMobileWalletAdapterWallet_icon.set(this, icon);
|
|
3610
|
+
_LocalSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
|
|
3611
|
+
_LocalSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
|
|
3612
|
+
_LocalSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
|
|
3613
|
+
_LocalSolanaMobileWalletAdapterWallet_connecting.set(this, false);
|
|
3614
|
+
/**
|
|
3615
|
+
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
3616
|
+
* increment this and use it to make sure that `transact` calls from the previous
|
|
3617
|
+
* 'generation' don't continue to do work and throw exceptions.
|
|
3618
|
+
*/
|
|
3619
|
+
_LocalSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
|
|
3620
|
+
_LocalSolanaMobileWalletAdapterWallet_chains.set(this, []);
|
|
3621
|
+
_LocalSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
|
|
3622
|
+
_LocalSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
|
|
3623
|
+
_LocalSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
|
|
3624
|
+
_LocalSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
|
|
3625
|
+
var _a;
|
|
3626
|
+
((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
|
|
3627
|
+
return () => __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
|
|
3628
|
+
});
|
|
3629
|
+
_LocalSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
3630
|
+
if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
|
|
3631
|
+
return { accounts: this.accounts };
|
|
3632
|
+
}
|
|
3633
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true);
|
|
3634
|
+
try {
|
|
3635
|
+
if (silent) {
|
|
3636
|
+
const cachedAuthorization = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
|
|
3637
|
+
if (cachedAuthorization) {
|
|
3638
|
+
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, cachedAuthorization.capabilities);
|
|
3639
|
+
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorization);
|
|
3640
|
+
}
|
|
3641
|
+
else {
|
|
3642
|
+
return { accounts: this.accounts };
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
else {
|
|
3646
|
+
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
catch (e) {
|
|
3650
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
3651
|
+
}
|
|
3652
|
+
finally {
|
|
3653
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false);
|
|
3654
|
+
}
|
|
3655
|
+
return { accounts: this.accounts };
|
|
3656
|
+
}));
|
|
3657
|
+
_LocalSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
|
|
3658
|
+
try {
|
|
3659
|
+
const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
|
|
3660
|
+
if (cachedAuthorizationResult) {
|
|
3661
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
3662
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
|
|
3663
|
+
return cachedAuthorizationResult;
|
|
3664
|
+
}
|
|
3665
|
+
const selectedChain = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"));
|
|
3666
|
+
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
3667
|
+
const [capabilities, mwaAuthorizationResult] = yield Promise.all([
|
|
3668
|
+
wallet.getCapabilities(),
|
|
3669
|
+
wallet.authorize({
|
|
3670
|
+
chain: selectedChain,
|
|
3671
|
+
identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
|
|
3672
|
+
sign_in_payload: signInPayload,
|
|
3673
|
+
})
|
|
3674
|
+
]);
|
|
3675
|
+
const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
|
|
3676
|
+
const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain, capabilities: capabilities });
|
|
3677
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
3678
|
+
Promise.all([
|
|
3679
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
|
|
3680
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
|
|
3681
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
|
|
3682
|
+
]);
|
|
3683
|
+
return authorization;
|
|
3684
|
+
}));
|
|
3685
|
+
}
|
|
3686
|
+
catch (e) {
|
|
3687
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
3688
|
+
}
|
|
3689
|
+
}));
|
|
3690
|
+
_LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
|
|
3691
|
+
var _a;
|
|
3692
|
+
const didPublicKeysChange =
|
|
3693
|
+
// Case 1: We started from having no authorization.
|
|
3694
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
|
|
3695
|
+
// Case 2: The number of authorized accounts changed.
|
|
3696
|
+
((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
|
|
3697
|
+
// Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
|
|
3698
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
3699
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, authorization);
|
|
3700
|
+
if (didPublicKeysChange) {
|
|
3701
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
|
|
3702
|
+
}
|
|
3703
|
+
}));
|
|
3704
|
+
_LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
|
|
3705
|
+
// TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
|
|
3706
|
+
const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
|
|
3707
|
+
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
|
|
3708
|
+
const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
|
|
3709
|
+
SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
3710
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, ((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
|
|
3711
|
+
[SolanaSignAndSendTransaction]: {
|
|
3712
|
+
version: '1.0.0',
|
|
3713
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
3714
|
+
signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
|
|
3715
|
+
},
|
|
3716
|
+
})), (supportsSignTransaction && {
|
|
3717
|
+
[SolanaSignTransaction]: {
|
|
3718
|
+
version: '1.0.0',
|
|
3719
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
3720
|
+
signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
|
|
3721
|
+
},
|
|
3722
|
+
})));
|
|
3723
|
+
if (didCapabilitiesChange) {
|
|
3724
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
|
|
3725
|
+
}
|
|
3726
|
+
}));
|
|
3727
|
+
_LocalSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
|
|
3728
|
+
var _b, _c;
|
|
3729
|
+
try {
|
|
3730
|
+
const [capabilities, mwaAuthorizationResult] = yield Promise.all([
|
|
3731
|
+
(_c = (_b = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _b === void 0 ? void 0 : _b.capabilities) !== null && _c !== void 0 ? _c : yield wallet.getCapabilities(),
|
|
3732
|
+
wallet.authorize({
|
|
3733
|
+
auth_token: authToken,
|
|
3734
|
+
identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
|
|
3735
|
+
chain: chain
|
|
3736
|
+
})
|
|
3737
|
+
]);
|
|
3738
|
+
const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
|
|
3739
|
+
const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
|
|
3740
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
3741
|
+
Promise.all([
|
|
3742
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
|
|
3743
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
|
|
3744
|
+
]);
|
|
3745
|
+
}
|
|
3746
|
+
catch (e) {
|
|
3747
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
|
|
3748
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
3749
|
+
}
|
|
3750
|
+
}));
|
|
3751
|
+
_LocalSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
3752
|
+
var _d;
|
|
3753
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
3754
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false);
|
|
3755
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, (_d = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _d++, _d));
|
|
3756
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, undefined);
|
|
3757
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
|
|
3758
|
+
}));
|
|
3759
|
+
_LocalSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
|
|
3760
|
+
var _e;
|
|
3761
|
+
const walletUriBase = (_e = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _e === void 0 ? void 0 : _e.wallet_uri_base;
|
|
3762
|
+
const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
|
|
3763
|
+
const currentConnectionGeneration = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
|
|
3764
|
+
try {
|
|
3765
|
+
return yield transact(callback, config);
|
|
3766
|
+
}
|
|
3767
|
+
catch (e) {
|
|
3768
|
+
if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
|
|
3769
|
+
yield new Promise(() => { }); // Never resolve.
|
|
3770
|
+
}
|
|
3771
|
+
if (e instanceof Error &&
|
|
3772
|
+
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
3773
|
+
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
3774
|
+
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
|
|
3775
|
+
}
|
|
3776
|
+
throw e;
|
|
3777
|
+
}
|
|
3778
|
+
}));
|
|
3779
|
+
_LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
|
|
3780
|
+
if (!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f"))
|
|
3781
|
+
throw new Error('Wallet not connected');
|
|
3782
|
+
return { authToken: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").chain };
|
|
3783
|
+
});
|
|
3784
|
+
_LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
|
|
3785
|
+
return accounts.map((account) => {
|
|
3786
|
+
var _a, _b;
|
|
3787
|
+
const publicKey = toUint8Array(account.address);
|
|
3788
|
+
return {
|
|
3789
|
+
address: base58.encode(publicKey),
|
|
3790
|
+
publicKey,
|
|
3791
|
+
label: account.label,
|
|
3792
|
+
icon: account.icon,
|
|
3793
|
+
chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"),
|
|
3794
|
+
// TODO: get supported features from getCapabilities API
|
|
3795
|
+
features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
|
|
3796
|
+
};
|
|
3797
|
+
});
|
|
3798
|
+
});
|
|
3799
|
+
_LocalSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
|
|
3800
|
+
const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
3801
|
+
try {
|
|
3802
|
+
const base64Transactions = transactions.map((tx) => { return fromUint8Array(tx); });
|
|
3803
|
+
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
3804
|
+
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
|
|
3805
|
+
const signedTransactions = (yield wallet.signTransactions({
|
|
3806
|
+
payloads: base64Transactions,
|
|
3807
|
+
})).signed_payloads.map(toUint8Array);
|
|
3808
|
+
return signedTransactions;
|
|
3809
|
+
}));
|
|
3810
|
+
}
|
|
3811
|
+
catch (e) {
|
|
3812
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
3813
|
+
}
|
|
3814
|
+
}));
|
|
3815
|
+
_LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
|
|
3816
|
+
const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
3817
|
+
try {
|
|
3818
|
+
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
3819
|
+
const [capabilities, _1] = yield Promise.all([
|
|
3820
|
+
wallet.getCapabilities(),
|
|
3821
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
|
|
3822
|
+
]);
|
|
3823
|
+
if (capabilities.supports_sign_and_send_transactions) {
|
|
3824
|
+
const base64Transaction = fromUint8Array(transaction);
|
|
3825
|
+
const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [base64Transaction] }))).signatures.map(toUint8Array);
|
|
3826
|
+
return signatures[0];
|
|
3827
|
+
}
|
|
3828
|
+
else {
|
|
3829
|
+
throw new Error('connected wallet does not support signAndSendTransaction');
|
|
3830
|
+
}
|
|
3831
|
+
}));
|
|
3832
|
+
}
|
|
3833
|
+
catch (e) {
|
|
3834
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
3835
|
+
}
|
|
3836
|
+
}));
|
|
3837
|
+
_LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
3838
|
+
const outputs = [];
|
|
3839
|
+
for (const input of inputs) {
|
|
3840
|
+
const signature = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options);
|
|
3841
|
+
outputs.push({ signature });
|
|
3842
|
+
}
|
|
3843
|
+
return outputs;
|
|
3844
|
+
}));
|
|
3845
|
+
_LocalSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
3846
|
+
return (yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
|
|
3847
|
+
.map((signedTransaction) => {
|
|
3848
|
+
return { signedTransaction };
|
|
3849
|
+
});
|
|
3850
|
+
}));
|
|
3851
|
+
_LocalSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
3852
|
+
const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
3853
|
+
const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
|
|
3854
|
+
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
3855
|
+
try {
|
|
3856
|
+
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
3857
|
+
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
|
|
3858
|
+
const signedMessages = (yield wallet.signMessages({
|
|
3859
|
+
addresses: addresses,
|
|
3860
|
+
payloads: messages,
|
|
3861
|
+
})).signed_payloads.map(toUint8Array);
|
|
3862
|
+
return signedMessages.map((signedMessage) => {
|
|
3863
|
+
return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
|
|
3864
|
+
});
|
|
3865
|
+
}));
|
|
3866
|
+
}
|
|
3867
|
+
catch (e) {
|
|
3868
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
3869
|
+
}
|
|
3870
|
+
}));
|
|
3871
|
+
_LocalSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
3872
|
+
const outputs = [];
|
|
3873
|
+
if (inputs.length > 1) {
|
|
3874
|
+
for (const input of inputs) {
|
|
3875
|
+
outputs.push(yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
else {
|
|
3879
|
+
return [yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
|
|
3880
|
+
}
|
|
3881
|
+
return outputs;
|
|
3882
|
+
}));
|
|
3883
|
+
_LocalSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
|
|
3884
|
+
var _f, _g, _h;
|
|
3885
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true);
|
|
3886
|
+
try {
|
|
3887
|
+
const authorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_f = input === null || input === void 0 ? void 0 : input.domain) !== null && _f !== void 0 ? _f : window.location.host }));
|
|
3888
|
+
if (!authorizationResult.sign_in_result) {
|
|
3889
|
+
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
3890
|
+
}
|
|
3891
|
+
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
3892
|
+
const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
|
|
3893
|
+
return {
|
|
3894
|
+
account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
|
|
3895
|
+
address: base58.encode(toUint8Array(signedInAddress))
|
|
3896
|
+
}), { publicKey: toUint8Array(signedInAddress), chains: (_g = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _g !== void 0 ? _g : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"), features: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _h !== void 0 ? _h : authorizationResult.capabilities.features }),
|
|
3897
|
+
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
3898
|
+
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
3899
|
+
};
|
|
3900
|
+
}
|
|
3901
|
+
catch (e) {
|
|
3902
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
3903
|
+
}
|
|
3904
|
+
finally {
|
|
3905
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false);
|
|
3906
|
+
}
|
|
3907
|
+
}));
|
|
3908
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache);
|
|
3909
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity);
|
|
3910
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, config.chains);
|
|
3911
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector);
|
|
3912
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound);
|
|
3913
|
+
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, {
|
|
3914
|
+
// In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
|
|
3915
|
+
// signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
|
|
3916
|
+
// 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
|
|
3917
|
+
// assume both are supported here. The features will be updated based on the actual connected
|
|
3918
|
+
// wallets capabilities during connection regardless, so this is safe.
|
|
3919
|
+
[SolanaSignAndSendTransaction]: {
|
|
3920
|
+
version: '1.0.0',
|
|
3921
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
3922
|
+
signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
|
|
3923
|
+
},
|
|
3924
|
+
[SolanaSignTransaction]: {
|
|
3925
|
+
version: '1.0.0',
|
|
3926
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
3927
|
+
signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
|
|
3928
|
+
},
|
|
3929
|
+
});
|
|
3930
|
+
}
|
|
3931
|
+
get version() {
|
|
3932
|
+
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_version, "f");
|
|
3933
|
+
}
|
|
3934
|
+
get name() {
|
|
3935
|
+
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_name, "f");
|
|
3936
|
+
}
|
|
3937
|
+
get url() {
|
|
3938
|
+
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_url, "f");
|
|
3939
|
+
}
|
|
3940
|
+
get icon() {
|
|
3941
|
+
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_icon, "f");
|
|
3942
|
+
}
|
|
3943
|
+
get chains() {
|
|
3944
|
+
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f");
|
|
3945
|
+
}
|
|
3946
|
+
get features() {
|
|
3947
|
+
return Object.assign({ [StandardConnect]: {
|
|
3948
|
+
version: '1.0.0',
|
|
3949
|
+
connect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connect, "f"),
|
|
3950
|
+
}, [StandardDisconnect]: {
|
|
3951
|
+
version: '1.0.0',
|
|
3952
|
+
disconnect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f"),
|
|
3953
|
+
}, [StandardEvents]: {
|
|
3954
|
+
version: '1.0.0',
|
|
3955
|
+
on: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_on, "f"),
|
|
3956
|
+
}, [SolanaSignMessage]: {
|
|
3957
|
+
version: '1.0.0',
|
|
3958
|
+
signMessage: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signMessage, "f"),
|
|
3959
|
+
}, [SolanaSignIn]: {
|
|
3960
|
+
version: '1.0.0',
|
|
3961
|
+
signIn: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signIn, "f"),
|
|
3962
|
+
} }, __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
|
|
3963
|
+
}
|
|
3964
|
+
get accounts() {
|
|
3965
|
+
var _a, _b;
|
|
3966
|
+
return (_b = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
|
|
3967
|
+
}
|
|
3968
|
+
get connected() {
|
|
3969
|
+
return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
|
|
3970
|
+
}
|
|
3971
|
+
get isAuthorized() {
|
|
3972
|
+
return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
|
|
3973
|
+
}
|
|
3974
|
+
get currentAuthorization() {
|
|
3975
|
+
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
|
|
3976
|
+
}
|
|
3977
|
+
get cachedAuthorizationResult() {
|
|
3978
|
+
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
|
|
4831
3979
|
}
|
|
4832
3980
|
}
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
return ErrorDialogHtml$2.replace("{{PERMISSION_INSTRUCTION_DETAIL}}", instructions);
|
|
4841
|
-
}
|
|
4842
|
-
async init() {
|
|
4843
|
-
super.init();
|
|
4844
|
-
this.#prepareLaunchAction();
|
|
4845
|
-
}
|
|
4846
|
-
#prepareLaunchAction() {
|
|
4847
|
-
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
4848
|
-
const listener = async (event) => {
|
|
4849
|
-
launchButton?.removeEventListener("click", listener);
|
|
4850
|
-
this.close(event);
|
|
4851
|
-
};
|
|
4852
|
-
launchButton?.addEventListener("click", listener);
|
|
4853
|
-
}
|
|
3981
|
+
_LocalSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_version = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_name = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_url = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_on = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _LocalSolanaMobileWalletAdapterWallet_emit = function _LocalSolanaMobileWalletAdapterWallet_emit(event, ...args) {
|
|
3982
|
+
var _a;
|
|
3983
|
+
// eslint-disable-next-line prefer-spread
|
|
3984
|
+
(_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
|
|
3985
|
+
}, _LocalSolanaMobileWalletAdapterWallet_off = function _LocalSolanaMobileWalletAdapterWallet_off(event, listener) {
|
|
3986
|
+
var _a;
|
|
3987
|
+
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
|
|
4854
3988
|
};
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
.
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
.
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
}
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
.
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
}
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
.
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
3989
|
+
class RemoteSolanaMobileWalletAdapterWallet {
|
|
3990
|
+
constructor(config) {
|
|
3991
|
+
_RemoteSolanaMobileWalletAdapterWallet_instances.add(this);
|
|
3992
|
+
_RemoteSolanaMobileWalletAdapterWallet_listeners.set(this, {});
|
|
3993
|
+
_RemoteSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
|
|
3994
|
+
_RemoteSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterRemoteWalletName);
|
|
3995
|
+
_RemoteSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
|
|
3996
|
+
_RemoteSolanaMobileWalletAdapterWallet_icon.set(this, icon);
|
|
3997
|
+
_RemoteSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
|
|
3998
|
+
_RemoteSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
|
|
3999
|
+
_RemoteSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
|
|
4000
|
+
_RemoteSolanaMobileWalletAdapterWallet_connecting.set(this, false);
|
|
4001
|
+
/**
|
|
4002
|
+
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
4003
|
+
* increment this and use it to make sure that `transact` calls from the previous
|
|
4004
|
+
* 'generation' don't continue to do work and throw exceptions.
|
|
4005
|
+
*/
|
|
4006
|
+
_RemoteSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
|
|
4007
|
+
_RemoteSolanaMobileWalletAdapterWallet_chains.set(this, []);
|
|
4008
|
+
_RemoteSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
|
|
4009
|
+
_RemoteSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
|
|
4010
|
+
_RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
|
|
4011
|
+
_RemoteSolanaMobileWalletAdapterWallet_hostAuthority.set(this, void 0);
|
|
4012
|
+
_RemoteSolanaMobileWalletAdapterWallet_session.set(this, void 0);
|
|
4013
|
+
_RemoteSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
|
|
4014
|
+
var _a;
|
|
4015
|
+
((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
|
|
4016
|
+
return () => __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
|
|
4017
|
+
});
|
|
4018
|
+
_RemoteSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
4019
|
+
if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
|
|
4020
|
+
return { accounts: this.accounts };
|
|
4021
|
+
}
|
|
4022
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true);
|
|
4023
|
+
try {
|
|
4024
|
+
yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
|
|
4025
|
+
}
|
|
4026
|
+
catch (e) {
|
|
4027
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
4028
|
+
}
|
|
4029
|
+
finally {
|
|
4030
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false);
|
|
4031
|
+
}
|
|
4032
|
+
return { accounts: this.accounts };
|
|
4033
|
+
}));
|
|
4034
|
+
_RemoteSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
|
|
4035
|
+
try {
|
|
4036
|
+
const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
|
|
4037
|
+
if (cachedAuthorizationResult) {
|
|
4038
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
4039
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
|
|
4040
|
+
return cachedAuthorizationResult;
|
|
4041
|
+
}
|
|
4042
|
+
if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f"))
|
|
4043
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined, "f");
|
|
4044
|
+
const selectedChain = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"));
|
|
4045
|
+
return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
4046
|
+
const [capabilities, mwaAuthorizationResult] = yield Promise.all([
|
|
4047
|
+
wallet.getCapabilities(),
|
|
4048
|
+
wallet.authorize({
|
|
4049
|
+
chain: selectedChain,
|
|
4050
|
+
identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
|
|
4051
|
+
sign_in_payload: signInPayload,
|
|
4052
|
+
})
|
|
4053
|
+
]);
|
|
4054
|
+
const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
|
|
4055
|
+
const authorizationResult = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain, capabilities: capabilities });
|
|
4056
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
4057
|
+
Promise.all([
|
|
4058
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
|
|
4059
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorizationResult),
|
|
4060
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorizationResult),
|
|
4061
|
+
]);
|
|
4062
|
+
return authorizationResult;
|
|
4063
|
+
}));
|
|
4064
|
+
}
|
|
4065
|
+
catch (e) {
|
|
4066
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
4067
|
+
}
|
|
4068
|
+
}));
|
|
4069
|
+
_RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
|
|
4070
|
+
var _a;
|
|
4071
|
+
const didPublicKeysChange =
|
|
4072
|
+
// Case 1: We started from having no authorization.
|
|
4073
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
|
|
4074
|
+
// Case 2: The number of authorized accounts changed.
|
|
4075
|
+
((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
|
|
4076
|
+
// Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
|
|
4077
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
4078
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, authorization);
|
|
4079
|
+
if (didPublicKeysChange) {
|
|
4080
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
|
|
4081
|
+
}
|
|
4082
|
+
}));
|
|
4083
|
+
_RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
|
|
4084
|
+
// TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
|
|
4085
|
+
const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
|
|
4086
|
+
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions ||
|
|
4087
|
+
capabilities.features.includes('solana:signAndSendTransaction');
|
|
4088
|
+
const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
|
|
4089
|
+
SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
4090
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, (supportsSignAndSendTransaction && {
|
|
4091
|
+
[SolanaSignAndSendTransaction]: {
|
|
4092
|
+
version: '1.0.0',
|
|
4093
|
+
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
4094
|
+
signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
|
|
4095
|
+
},
|
|
4096
|
+
})), (supportsSignTransaction && {
|
|
4097
|
+
[SolanaSignTransaction]: {
|
|
4098
|
+
version: '1.0.0',
|
|
4099
|
+
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
4100
|
+
signTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, "f"),
|
|
4101
|
+
},
|
|
4102
|
+
})));
|
|
4103
|
+
if (didCapabilitiesChange) {
|
|
4104
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
|
|
4105
|
+
}
|
|
4106
|
+
}));
|
|
4107
|
+
_RemoteSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
|
|
4108
|
+
var _b, _c;
|
|
4109
|
+
try {
|
|
4110
|
+
const [capabilities, mwaAuthorizationResult] = yield Promise.all([
|
|
4111
|
+
(_c = (_b = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _b === void 0 ? void 0 : _b.capabilities) !== null && _c !== void 0 ? _c : yield wallet.getCapabilities(),
|
|
4112
|
+
wallet.authorize({
|
|
4113
|
+
auth_token: authToken,
|
|
4114
|
+
identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
|
|
4115
|
+
chain: chain
|
|
4116
|
+
})
|
|
4117
|
+
]);
|
|
4118
|
+
const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
|
|
4119
|
+
const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
|
|
4120
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
4121
|
+
Promise.all([
|
|
4122
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
|
|
4123
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
|
|
4124
|
+
]);
|
|
4125
|
+
}
|
|
4126
|
+
catch (e) {
|
|
4127
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
|
|
4128
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
4129
|
+
}
|
|
4130
|
+
}));
|
|
4131
|
+
_RemoteSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
4132
|
+
var _d;
|
|
4133
|
+
var _e;
|
|
4134
|
+
(_d = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) === null || _d === void 0 ? void 0 : _d.close();
|
|
4135
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
4136
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false);
|
|
4137
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, (_e = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _e++, _e));
|
|
4138
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, undefined);
|
|
4139
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined);
|
|
4140
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
|
|
4141
|
+
}));
|
|
4142
|
+
_RemoteSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
|
|
4143
|
+
var _f;
|
|
4144
|
+
const walletUriBase = (_f = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _f === void 0 ? void 0 : _f.wallet_uri_base;
|
|
4145
|
+
const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
|
|
4146
|
+
const remoteConfig = Object.assign(Object.assign({}, baseConfig), { remoteHostAuthority: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, "f") });
|
|
4147
|
+
const currentConnectionGeneration = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
|
|
4148
|
+
const modal = new RemoteConnectionModal();
|
|
4149
|
+
if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) {
|
|
4150
|
+
return callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
|
|
4151
|
+
}
|
|
4152
|
+
try {
|
|
4153
|
+
const { associationUrl, close, wallet } = yield startRemoteScenario(remoteConfig);
|
|
4154
|
+
const removeCloseListener = modal.addEventListener('close', (event) => {
|
|
4155
|
+
if (event)
|
|
4156
|
+
close();
|
|
4157
|
+
});
|
|
4158
|
+
modal.initWithQR(associationUrl.toString());
|
|
4159
|
+
modal.open();
|
|
4160
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, { close, wallet: yield wallet }, "f");
|
|
4161
|
+
removeCloseListener();
|
|
4162
|
+
modal.close();
|
|
4163
|
+
return yield callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
|
|
4164
|
+
}
|
|
4165
|
+
catch (e) {
|
|
4166
|
+
modal.close();
|
|
4167
|
+
if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
|
|
4168
|
+
yield new Promise(() => { }); // Never resolve.
|
|
4169
|
+
}
|
|
4170
|
+
if (e instanceof Error &&
|
|
4171
|
+
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
4172
|
+
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
4173
|
+
yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
|
|
4174
|
+
}
|
|
4175
|
+
throw e;
|
|
4176
|
+
}
|
|
4177
|
+
}));
|
|
4178
|
+
_RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
|
|
4179
|
+
if (!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f"))
|
|
4180
|
+
throw new Error('Wallet not connected');
|
|
4181
|
+
return { authToken: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").chain };
|
|
4182
|
+
});
|
|
4183
|
+
_RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
|
|
4184
|
+
return accounts.map((account) => {
|
|
4185
|
+
var _a, _b;
|
|
4186
|
+
const publicKey = toUint8Array(account.address);
|
|
4187
|
+
return {
|
|
4188
|
+
address: base58.encode(publicKey),
|
|
4189
|
+
publicKey,
|
|
4190
|
+
label: account.label,
|
|
4191
|
+
icon: account.icon,
|
|
4192
|
+
chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"),
|
|
4193
|
+
// TODO: get supported features from getCapabilities API
|
|
4194
|
+
features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
|
|
4195
|
+
};
|
|
4196
|
+
});
|
|
4197
|
+
});
|
|
4198
|
+
_RemoteSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
|
|
4199
|
+
const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
4200
|
+
try {
|
|
4201
|
+
return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
4202
|
+
yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
|
|
4203
|
+
const signedTransactions = (yield wallet.signTransactions({
|
|
4204
|
+
payloads: transactions.map(fromUint8Array),
|
|
4205
|
+
})).signed_payloads.map(toUint8Array);
|
|
4206
|
+
return signedTransactions;
|
|
4207
|
+
}));
|
|
4208
|
+
}
|
|
4209
|
+
catch (e) {
|
|
4210
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
4211
|
+
}
|
|
4212
|
+
}));
|
|
4213
|
+
_RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
|
|
4214
|
+
const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
4215
|
+
try {
|
|
4216
|
+
return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
4217
|
+
const [capabilities, _1] = yield Promise.all([
|
|
4218
|
+
wallet.getCapabilities(),
|
|
4219
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
|
|
4220
|
+
]);
|
|
4221
|
+
if (capabilities.supports_sign_and_send_transactions) {
|
|
4222
|
+
const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [fromUint8Array(transaction)] }))).signatures.map(toUint8Array);
|
|
4223
|
+
return signatures[0];
|
|
4224
|
+
}
|
|
4225
|
+
else {
|
|
4226
|
+
throw new Error('connected wallet does not support signAndSendTransaction');
|
|
4227
|
+
}
|
|
4228
|
+
}));
|
|
4229
|
+
}
|
|
4230
|
+
catch (e) {
|
|
4231
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
4232
|
+
}
|
|
4233
|
+
}));
|
|
4234
|
+
_RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
4235
|
+
const outputs = [];
|
|
4236
|
+
for (const input of inputs) {
|
|
4237
|
+
const signature = (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options));
|
|
4238
|
+
outputs.push({ signature });
|
|
4239
|
+
}
|
|
4240
|
+
return outputs;
|
|
4241
|
+
}));
|
|
4242
|
+
_RemoteSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
4243
|
+
return (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
|
|
4244
|
+
.map((signedTransaction) => {
|
|
4245
|
+
return { signedTransaction };
|
|
4246
|
+
});
|
|
4247
|
+
}));
|
|
4248
|
+
_RemoteSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
4249
|
+
const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
4250
|
+
const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
|
|
4251
|
+
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
4252
|
+
try {
|
|
4253
|
+
return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
4254
|
+
yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
|
|
4255
|
+
const signedMessages = (yield wallet.signMessages({
|
|
4256
|
+
addresses: addresses,
|
|
4257
|
+
payloads: messages,
|
|
4258
|
+
})).signed_payloads.map(toUint8Array);
|
|
4259
|
+
return signedMessages.map((signedMessage) => {
|
|
4260
|
+
return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
|
|
4261
|
+
});
|
|
4262
|
+
}));
|
|
4263
|
+
}
|
|
4264
|
+
catch (e) {
|
|
4265
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
4266
|
+
}
|
|
4267
|
+
}));
|
|
4268
|
+
_RemoteSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
4269
|
+
const outputs = [];
|
|
4270
|
+
if (inputs.length > 1) {
|
|
4271
|
+
for (const input of inputs) {
|
|
4272
|
+
outputs.push(yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
else {
|
|
4276
|
+
return [yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
|
|
4277
|
+
}
|
|
4278
|
+
return outputs;
|
|
4279
|
+
}));
|
|
4280
|
+
_RemoteSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
|
|
4281
|
+
var _g, _h, _j;
|
|
4282
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true);
|
|
4283
|
+
try {
|
|
4284
|
+
const authorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_g = input === null || input === void 0 ? void 0 : input.domain) !== null && _g !== void 0 ? _g : window.location.host }));
|
|
4285
|
+
if (!authorizationResult.sign_in_result) {
|
|
4286
|
+
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
4287
|
+
}
|
|
4288
|
+
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
4289
|
+
const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
|
|
4290
|
+
return {
|
|
4291
|
+
account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
|
|
4292
|
+
address: base58.encode(toUint8Array(signedInAddress))
|
|
4293
|
+
}), { publicKey: toUint8Array(signedInAddress), chains: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _h !== void 0 ? _h : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"), features: (_j = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _j !== void 0 ? _j : authorizationResult.capabilities.features }),
|
|
4294
|
+
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
4295
|
+
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
4296
|
+
};
|
|
4297
|
+
}
|
|
4298
|
+
catch (e) {
|
|
4299
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
4300
|
+
}
|
|
4301
|
+
finally {
|
|
4302
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false);
|
|
4303
|
+
}
|
|
4304
|
+
}));
|
|
4305
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache);
|
|
4306
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity);
|
|
4307
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, config.chains);
|
|
4308
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector);
|
|
4309
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, config.remoteHostAuthority);
|
|
4310
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound);
|
|
4311
|
+
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, {
|
|
4312
|
+
// In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
|
|
4313
|
+
// signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
|
|
4314
|
+
// 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
|
|
4315
|
+
// assume both are supported here. The features will be updated based on the actual connected
|
|
4316
|
+
// wallets capabilities during connection regardless, so this is safe.
|
|
4317
|
+
[SolanaSignAndSendTransaction]: {
|
|
4318
|
+
version: '1.0.0',
|
|
4319
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
4320
|
+
signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
|
|
4321
|
+
},
|
|
4322
|
+
[SolanaSignTransaction]: {
|
|
4323
|
+
version: '1.0.0',
|
|
4324
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
4325
|
+
signTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, "f"),
|
|
4326
|
+
},
|
|
4327
|
+
});
|
|
4988
4328
|
}
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4329
|
+
get version() {
|
|
4330
|
+
return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_version, "f");
|
|
4331
|
+
}
|
|
4332
|
+
get name() {
|
|
4333
|
+
return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_name, "f");
|
|
4334
|
+
}
|
|
4335
|
+
get url() {
|
|
4336
|
+
return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_url, "f");
|
|
4337
|
+
}
|
|
4338
|
+
get icon() {
|
|
4339
|
+
return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_icon, "f");
|
|
4340
|
+
}
|
|
4341
|
+
get chains() {
|
|
4342
|
+
return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f");
|
|
4343
|
+
}
|
|
4344
|
+
get features() {
|
|
4345
|
+
return Object.assign({ [StandardConnect]: {
|
|
4346
|
+
version: '1.0.0',
|
|
4347
|
+
connect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connect, "f"),
|
|
4348
|
+
}, [StandardDisconnect]: {
|
|
4349
|
+
version: '1.0.0',
|
|
4350
|
+
disconnect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f"),
|
|
4351
|
+
}, [StandardEvents]: {
|
|
4352
|
+
version: '1.0.0',
|
|
4353
|
+
on: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_on, "f"),
|
|
4354
|
+
}, [SolanaSignMessage]: {
|
|
4355
|
+
version: '1.0.0',
|
|
4356
|
+
signMessage: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signMessage, "f"),
|
|
4357
|
+
}, [SolanaSignIn]: {
|
|
4358
|
+
version: '1.0.0',
|
|
4359
|
+
signIn: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signIn, "f"),
|
|
4360
|
+
} }, __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
|
|
4361
|
+
}
|
|
4362
|
+
get accounts() {
|
|
4363
|
+
var _a, _b;
|
|
4364
|
+
return (_b = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
|
|
4365
|
+
}
|
|
4366
|
+
get connected() {
|
|
4367
|
+
return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f") && !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
|
|
4368
|
+
}
|
|
4369
|
+
get isAuthorized() {
|
|
4370
|
+
return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
|
|
4371
|
+
}
|
|
4372
|
+
get currentAuthorization() {
|
|
4373
|
+
return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
|
|
4374
|
+
}
|
|
4375
|
+
get cachedAuthorizationResult() {
|
|
4376
|
+
return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
|
|
4992
4377
|
}
|
|
4993
4378
|
}
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
super.init();
|
|
5002
|
-
this.#prepareLaunchAction();
|
|
5003
|
-
}
|
|
5004
|
-
#prepareLaunchAction() {
|
|
5005
|
-
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
5006
|
-
const listener = async () => {
|
|
5007
|
-
launchButton?.removeEventListener("click", listener);
|
|
5008
|
-
try {
|
|
5009
|
-
await fetch("http://localhost");
|
|
5010
|
-
} catch {}
|
|
5011
|
-
this.close();
|
|
5012
|
-
};
|
|
5013
|
-
launchButton?.addEventListener("click", listener);
|
|
5014
|
-
}
|
|
4379
|
+
_RemoteSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_version = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_name = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_url = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_hostAuthority = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_session = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_on = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _RemoteSolanaMobileWalletAdapterWallet_emit = function _RemoteSolanaMobileWalletAdapterWallet_emit(event, ...args) {
|
|
4380
|
+
var _a;
|
|
4381
|
+
// eslint-disable-next-line prefer-spread
|
|
4382
|
+
(_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
|
|
4383
|
+
}, _RemoteSolanaMobileWalletAdapterWallet_off = function _RemoteSolanaMobileWalletAdapterWallet_off(event, listener) {
|
|
4384
|
+
var _a;
|
|
4385
|
+
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
|
|
5015
4386
|
};
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
}
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
font-weight: 400;
|
|
5060
|
-
}
|
|
5061
|
-
.mobile-wallet-adapter-embedded-modal-permission-prompt-mock {
|
|
5062
|
-
width: 90%;
|
|
5063
|
-
height: auto;
|
|
5064
|
-
margin: 0 auto 30px auto;
|
|
5065
|
-
display: block;
|
|
5066
|
-
}
|
|
5067
|
-
.mobile-wallet-adapter-embedded-modal-launch-action {
|
|
5068
|
-
display: block;
|
|
5069
|
-
width: 100%;
|
|
5070
|
-
height: 56px;
|
|
5071
|
-
font-size: 1.25em;
|
|
5072
|
-
background: #000000;
|
|
5073
|
-
color: #FFFFFF;
|
|
5074
|
-
border-radius: 18px;
|
|
4387
|
+
|
|
4388
|
+
var __classPrivateFieldSet = function (receiver, state, value, kind, f) {
|
|
4389
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4390
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4391
|
+
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");
|
|
4392
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
4393
|
+
};
|
|
4394
|
+
var __classPrivateFieldGet = function (receiver, state, kind, f) {
|
|
4395
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4396
|
+
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");
|
|
4397
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
4398
|
+
};
|
|
4399
|
+
var _RegisterWalletEvent_detail;
|
|
4400
|
+
/**
|
|
4401
|
+
* Register a {@link "@wallet-standard/base".Wallet} as a Standard Wallet with the app.
|
|
4402
|
+
*
|
|
4403
|
+
* This dispatches a {@link "@wallet-standard/base".WindowRegisterWalletEvent} to notify the app that the Wallet is
|
|
4404
|
+
* ready to be registered.
|
|
4405
|
+
*
|
|
4406
|
+
* This also adds a listener for {@link "@wallet-standard/base".WindowAppReadyEvent} to listen for a notification from
|
|
4407
|
+
* the app that the app is ready to register the Wallet.
|
|
4408
|
+
*
|
|
4409
|
+
* This combination of event dispatch and listener guarantees that the Wallet will be registered synchronously as soon
|
|
4410
|
+
* as the app is ready whether the Wallet loads before or after the app.
|
|
4411
|
+
*
|
|
4412
|
+
* @param wallet Wallet to register.
|
|
4413
|
+
*
|
|
4414
|
+
* @group Wallet
|
|
4415
|
+
*/
|
|
4416
|
+
function registerWallet(wallet) {
|
|
4417
|
+
const callback = ({ register }) => register(wallet);
|
|
4418
|
+
try {
|
|
4419
|
+
window.dispatchEvent(new RegisterWalletEvent(callback));
|
|
4420
|
+
}
|
|
4421
|
+
catch (error) {
|
|
4422
|
+
console.error('wallet-standard:register-wallet event could not be dispatched\n', error);
|
|
4423
|
+
}
|
|
4424
|
+
try {
|
|
4425
|
+
window.addEventListener('wallet-standard:app-ready', ({ detail: api }) => callback(api));
|
|
4426
|
+
}
|
|
4427
|
+
catch (error) {
|
|
4428
|
+
console.error('wallet-standard:app-ready event listener could not be added\n', error);
|
|
4429
|
+
}
|
|
5075
4430
|
}
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
4431
|
+
class RegisterWalletEvent extends Event {
|
|
4432
|
+
constructor(callback) {
|
|
4433
|
+
super('wallet-standard:register-wallet', {
|
|
4434
|
+
bubbles: false,
|
|
4435
|
+
cancelable: false,
|
|
4436
|
+
composed: false,
|
|
4437
|
+
});
|
|
4438
|
+
_RegisterWalletEvent_detail.set(this, void 0);
|
|
4439
|
+
__classPrivateFieldSet(this, _RegisterWalletEvent_detail, callback, "f");
|
|
5082
4440
|
}
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
4441
|
+
get detail() {
|
|
4442
|
+
return __classPrivateFieldGet(this, _RegisterWalletEvent_detail, "f");
|
|
4443
|
+
}
|
|
4444
|
+
get type() {
|
|
4445
|
+
return 'wallet-standard:register-wallet';
|
|
4446
|
+
}
|
|
4447
|
+
/** @deprecated */
|
|
4448
|
+
preventDefault() {
|
|
4449
|
+
throw new Error('preventDefault cannot be called');
|
|
4450
|
+
}
|
|
4451
|
+
/** @deprecated */
|
|
4452
|
+
stopImmediatePropagation() {
|
|
4453
|
+
throw new Error('stopImmediatePropagation cannot be called');
|
|
4454
|
+
}
|
|
4455
|
+
/** @deprecated */
|
|
4456
|
+
stopPropagation() {
|
|
4457
|
+
throw new Error('stopPropagation cannot be called');
|
|
5086
4458
|
}
|
|
5087
4459
|
}
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
//#region src/getIsSupported.ts
|
|
4460
|
+
_RegisterWalletEvent_detail = new WeakMap();
|
|
4461
|
+
|
|
5091
4462
|
function getIsLocalAssociationSupported() {
|
|
5092
|
-
|
|
4463
|
+
return (typeof window !== 'undefined' &&
|
|
4464
|
+
window.isSecureContext &&
|
|
4465
|
+
typeof document !== 'undefined' &&
|
|
4466
|
+
/android/i.test(navigator.userAgent));
|
|
5093
4467
|
}
|
|
5094
4468
|
function getIsRemoteAssociationSupported() {
|
|
5095
|
-
|
|
4469
|
+
return (typeof window !== 'undefined' &&
|
|
4470
|
+
window.isSecureContext &&
|
|
4471
|
+
typeof document !== 'undefined' &&
|
|
4472
|
+
!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
|
|
5096
4473
|
}
|
|
4474
|
+
// Source: https://github.com/anza-xyz/wallet-adapter/blob/master/packages/core/react/src/getEnvironment.ts#L14
|
|
4475
|
+
// This is the same implementation that gated MWA in the Anza wallet-adapter-react library.
|
|
5097
4476
|
function isWebView(userAgentString) {
|
|
5098
|
-
|
|
4477
|
+
return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
|
|
5099
4478
|
}
|
|
5100
|
-
|
|
5101
|
-
return userAgentString.includes("Solana Mobile Web Shell");
|
|
5102
|
-
}
|
|
5103
|
-
function getIsPwaLaunchedAsApp() {
|
|
5104
|
-
const isAndroidTwa = typeof document !== "undefined" && document.referrer.startsWith("android-app://");
|
|
5105
|
-
if (typeof window == "undefined") return isAndroidTwa;
|
|
5106
|
-
const isStandalone = window.matchMedia("(display-mode: standalone)").matches;
|
|
5107
|
-
const isFullscreen = window.matchMedia("(display-mode: fullscreen)").matches;
|
|
5108
|
-
const isMinimalUI = window.matchMedia("(display-mode: minimal-ui)").matches;
|
|
5109
|
-
return isAndroidTwa || isStandalone || isFullscreen || isMinimalUI;
|
|
5110
|
-
}
|
|
5111
|
-
async function checkLocalNetworkAccessPermission() {
|
|
5112
|
-
if (typeof navigator !== "undefined" && isSolanaMobileWebShell(navigator.userAgent)) return;
|
|
5113
|
-
try {
|
|
5114
|
-
const lnaPermission = await navigator.permissions.query({ name: "loopback-network" });
|
|
5115
|
-
if (lnaPermission.state === "granted") return;
|
|
5116
|
-
else if (lnaPermission.state === "denied") {
|
|
5117
|
-
const modal = new LoopbackPermissionBlockedModal();
|
|
5118
|
-
modal.init();
|
|
5119
|
-
modal.open();
|
|
5120
|
-
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, "Local Network Access permission denied");
|
|
5121
|
-
} else if (lnaPermission.state === "prompt") {
|
|
5122
|
-
const modal = new LoopbackPermissionModal();
|
|
5123
|
-
if (await new Promise((resolve, reject) => {
|
|
5124
|
-
modal.addEventListener("close", (event) => {
|
|
5125
|
-
if (event) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection cancelled by user", { event }));
|
|
5126
|
-
});
|
|
5127
|
-
lnaPermission.onchange = () => {
|
|
5128
|
-
lnaPermission.onchange = null;
|
|
5129
|
-
resolve(lnaPermission.state);
|
|
5130
|
-
};
|
|
5131
|
-
modal.init();
|
|
5132
|
-
modal.open();
|
|
5133
|
-
}) === "granted") {
|
|
5134
|
-
const modal = new LocalConnectionModal();
|
|
5135
|
-
await new Promise((resolve, reject) => {
|
|
5136
|
-
modal.addEventListener("close", (event) => {
|
|
5137
|
-
if (event) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection cancelled by user", { event }));
|
|
5138
|
-
});
|
|
5139
|
-
modal.initWithCallback(async () => {
|
|
5140
|
-
resolve(true);
|
|
5141
|
-
});
|
|
5142
|
-
modal.open();
|
|
5143
|
-
});
|
|
5144
|
-
return;
|
|
5145
|
-
} else return await checkLocalNetworkAccessPermission();
|
|
5146
|
-
}
|
|
5147
|
-
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, "Local Network Access permission unknown");
|
|
5148
|
-
} catch (e) {
|
|
5149
|
-
if (e instanceof TypeError && (e.message.includes("loopback-network") || e.message.includes("local-network-access"))) return;
|
|
5150
|
-
if (e instanceof SolanaMobileWalletAdapterError) throw e;
|
|
5151
|
-
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, e instanceof Error ? e.message : "Local Network Access permission unknown");
|
|
5152
|
-
}
|
|
5153
|
-
}
|
|
5154
|
-
//#endregion
|
|
5155
|
-
//#region src/icon.ts
|
|
5156
|
-
const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=";
|
|
5157
|
-
//#endregion
|
|
5158
|
-
//#region src/wallet.ts
|
|
5159
|
-
const SolanaMobileWalletAdapterWalletName = "Mobile Wallet Adapter";
|
|
5160
|
-
const SolanaMobileWalletAdapterRemoteWalletName = "Remote Mobile Wallet Adapter";
|
|
5161
|
-
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
5162
|
-
const DEFAULT_FEATURES = [
|
|
5163
|
-
SolanaSignAndSendTransaction,
|
|
5164
|
-
SolanaSignTransaction,
|
|
5165
|
-
SolanaSignMessage,
|
|
5166
|
-
SolanaSignIn
|
|
5167
|
-
];
|
|
5168
|
-
const WALLET_ASSOCIATION_TIMEOUT = 3e4;
|
|
5169
|
-
function getErrorMessage(error) {
|
|
5170
|
-
return error instanceof Error ? error.message : "Unknown error";
|
|
5171
|
-
}
|
|
5172
|
-
var LocalSolanaMobileWalletAdapterWallet = class {
|
|
5173
|
-
#listeners = {};
|
|
5174
|
-
#version = "1.0.0";
|
|
5175
|
-
#name = SolanaMobileWalletAdapterWalletName;
|
|
5176
|
-
#url = "https://solanamobile.com/wallets";
|
|
5177
|
-
#icon = icon;
|
|
5178
|
-
#appIdentity;
|
|
5179
|
-
#authorization;
|
|
5180
|
-
#authorizationCache;
|
|
5181
|
-
#connecting = false;
|
|
5182
|
-
/**
|
|
5183
|
-
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
5184
|
-
* increment this and use it to make sure that `transact` calls from the previous
|
|
5185
|
-
* 'generation' don't continue to do work and throw exceptions.
|
|
5186
|
-
*/
|
|
5187
|
-
#connectionGeneration = 0;
|
|
5188
|
-
#chains = [];
|
|
5189
|
-
#chainSelector;
|
|
5190
|
-
#optionalFeatures;
|
|
5191
|
-
#onWalletNotFound;
|
|
5192
|
-
get version() {
|
|
5193
|
-
return this.#version;
|
|
5194
|
-
}
|
|
5195
|
-
get name() {
|
|
5196
|
-
return this.#name;
|
|
5197
|
-
}
|
|
5198
|
-
get url() {
|
|
5199
|
-
return this.#url;
|
|
5200
|
-
}
|
|
5201
|
-
get icon() {
|
|
5202
|
-
return this.#icon;
|
|
5203
|
-
}
|
|
5204
|
-
get chains() {
|
|
5205
|
-
return this.#chains;
|
|
5206
|
-
}
|
|
5207
|
-
get features() {
|
|
5208
|
-
return {
|
|
5209
|
-
[StandardConnect]: {
|
|
5210
|
-
version: "1.0.0",
|
|
5211
|
-
connect: this.#connect
|
|
5212
|
-
},
|
|
5213
|
-
[StandardDisconnect]: {
|
|
5214
|
-
version: "1.0.0",
|
|
5215
|
-
disconnect: this.#disconnect
|
|
5216
|
-
},
|
|
5217
|
-
[StandardEvents]: {
|
|
5218
|
-
version: "1.0.0",
|
|
5219
|
-
on: this.#on
|
|
5220
|
-
},
|
|
5221
|
-
[SolanaSignMessage]: {
|
|
5222
|
-
version: "1.0.0",
|
|
5223
|
-
signMessage: this.#signMessage
|
|
5224
|
-
},
|
|
5225
|
-
[SolanaSignIn]: {
|
|
5226
|
-
version: "1.0.0",
|
|
5227
|
-
signIn: this.#signIn
|
|
5228
|
-
},
|
|
5229
|
-
...this.#optionalFeatures
|
|
5230
|
-
};
|
|
5231
|
-
}
|
|
5232
|
-
get accounts() {
|
|
5233
|
-
return this.#authorization?.accounts ?? [];
|
|
5234
|
-
}
|
|
5235
|
-
constructor(config) {
|
|
5236
|
-
this.#authorizationCache = config.authorizationCache;
|
|
5237
|
-
this.#appIdentity = config.appIdentity;
|
|
5238
|
-
this.#chains = config.chains;
|
|
5239
|
-
this.#chainSelector = config.chainSelector;
|
|
5240
|
-
this.#onWalletNotFound = config.onWalletNotFound;
|
|
5241
|
-
this.#optionalFeatures = {
|
|
5242
|
-
[SolanaSignAndSendTransaction]: {
|
|
5243
|
-
version: "1.0.0",
|
|
5244
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
5245
|
-
signAndSendTransaction: this.#signAndSendTransaction
|
|
5246
|
-
},
|
|
5247
|
-
[SolanaSignTransaction]: {
|
|
5248
|
-
version: "1.0.0",
|
|
5249
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
5250
|
-
signTransaction: this.#signTransaction
|
|
5251
|
-
}
|
|
5252
|
-
};
|
|
5253
|
-
}
|
|
5254
|
-
get connected() {
|
|
5255
|
-
return !!this.#authorization;
|
|
5256
|
-
}
|
|
5257
|
-
get isAuthorized() {
|
|
5258
|
-
return !!this.#authorization;
|
|
5259
|
-
}
|
|
5260
|
-
get currentAuthorization() {
|
|
5261
|
-
return this.#authorization;
|
|
5262
|
-
}
|
|
5263
|
-
get cachedAuthorizationResult() {
|
|
5264
|
-
return this.#authorizationCache.get();
|
|
5265
|
-
}
|
|
5266
|
-
#on = (event, listener) => {
|
|
5267
|
-
this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
|
|
5268
|
-
return () => this.#off(event, listener);
|
|
5269
|
-
};
|
|
5270
|
-
#emit(event, ...args) {
|
|
5271
|
-
this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
|
|
5272
|
-
}
|
|
5273
|
-
#off(event, listener) {
|
|
5274
|
-
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
5275
|
-
}
|
|
5276
|
-
#connect = async ({ silent } = {}) => {
|
|
5277
|
-
if (this.#connecting || this.connected) return { accounts: this.accounts };
|
|
5278
|
-
this.#connecting = true;
|
|
5279
|
-
try {
|
|
5280
|
-
if (silent) {
|
|
5281
|
-
const cachedAuthorization = await this.#authorizationCache.get();
|
|
5282
|
-
if (cachedAuthorization) {
|
|
5283
|
-
await this.#handleWalletCapabilitiesResult(cachedAuthorization.capabilities);
|
|
5284
|
-
await this.#handleAuthorizationResult(cachedAuthorization);
|
|
5285
|
-
} else return { accounts: this.accounts };
|
|
5286
|
-
} else await this.#performAuthorization();
|
|
5287
|
-
} catch (e) {
|
|
5288
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5289
|
-
} finally {
|
|
5290
|
-
this.#connecting = false;
|
|
5291
|
-
}
|
|
5292
|
-
return { accounts: this.accounts };
|
|
5293
|
-
};
|
|
5294
|
-
#performAuthorization = async (signInPayload) => {
|
|
5295
|
-
try {
|
|
5296
|
-
const cachedAuthorizationResult = await this.#authorizationCache.get();
|
|
5297
|
-
if (cachedAuthorizationResult) {
|
|
5298
|
-
this.#handleAuthorizationResult(cachedAuthorizationResult);
|
|
5299
|
-
return cachedAuthorizationResult;
|
|
5300
|
-
}
|
|
5301
|
-
const selectedChain = await this.#chainSelector.select(this.#chains);
|
|
5302
|
-
return await this.#transact(async (wallet) => {
|
|
5303
|
-
const [capabilities, mwaAuthorizationResult] = await Promise.all([wallet.getCapabilities(), wallet.authorize({
|
|
5304
|
-
chain: selectedChain,
|
|
5305
|
-
identity: this.#appIdentity,
|
|
5306
|
-
sign_in_payload: signInPayload
|
|
5307
|
-
})]);
|
|
5308
|
-
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
5309
|
-
const authorization = {
|
|
5310
|
-
...mwaAuthorizationResult,
|
|
5311
|
-
accounts,
|
|
5312
|
-
chain: selectedChain,
|
|
5313
|
-
capabilities
|
|
5314
|
-
};
|
|
5315
|
-
Promise.all([
|
|
5316
|
-
this.#handleWalletCapabilitiesResult(capabilities),
|
|
5317
|
-
this.#authorizationCache.set(authorization),
|
|
5318
|
-
this.#handleAuthorizationResult(authorization)
|
|
5319
|
-
]);
|
|
5320
|
-
return authorization;
|
|
5321
|
-
});
|
|
5322
|
-
} catch (e) {
|
|
5323
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5324
|
-
}
|
|
5325
|
-
};
|
|
5326
|
-
#handleAuthorizationResult = async (authorization) => {
|
|
5327
|
-
const didPublicKeysChange = this.#authorization == null || this.#authorization?.accounts.length !== authorization.accounts.length || this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
5328
|
-
this.#authorization = authorization;
|
|
5329
|
-
if (didPublicKeysChange) this.#emit("change", { accounts: this.accounts });
|
|
5330
|
-
};
|
|
5331
|
-
#handleWalletCapabilitiesResult = async (capabilities) => {
|
|
5332
|
-
const supportsSignTransaction = capabilities.features.includes("solana:signTransactions");
|
|
5333
|
-
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
|
|
5334
|
-
const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction || SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
5335
|
-
this.#optionalFeatures = {
|
|
5336
|
-
...(supportsSignAndSendTransaction || !supportsSignAndSendTransaction && !supportsSignTransaction) && { [SolanaSignAndSendTransaction]: {
|
|
5337
|
-
version: "1.0.0",
|
|
5338
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
5339
|
-
signAndSendTransaction: this.#signAndSendTransaction
|
|
5340
|
-
} },
|
|
5341
|
-
...supportsSignTransaction && { [SolanaSignTransaction]: {
|
|
5342
|
-
version: "1.0.0",
|
|
5343
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
5344
|
-
signTransaction: this.#signTransaction
|
|
5345
|
-
} }
|
|
5346
|
-
};
|
|
5347
|
-
if (didCapabilitiesChange) this.#emit("change", { features: this.features });
|
|
5348
|
-
};
|
|
5349
|
-
#performReauthorization = async (wallet, authToken, chain) => {
|
|
5350
|
-
try {
|
|
5351
|
-
const [capabilities, mwaAuthorizationResult] = await Promise.all([this.#authorization?.capabilities ?? await wallet.getCapabilities(), wallet.authorize({
|
|
5352
|
-
auth_token: authToken,
|
|
5353
|
-
identity: this.#appIdentity,
|
|
5354
|
-
chain
|
|
5355
|
-
})]);
|
|
5356
|
-
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
5357
|
-
const authorization = {
|
|
5358
|
-
...mwaAuthorizationResult,
|
|
5359
|
-
accounts,
|
|
5360
|
-
chain,
|
|
5361
|
-
capabilities
|
|
5362
|
-
};
|
|
5363
|
-
Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
|
|
5364
|
-
} catch (e) {
|
|
5365
|
-
this.#disconnect();
|
|
5366
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5367
|
-
}
|
|
5368
|
-
};
|
|
5369
|
-
#disconnect = async () => {
|
|
5370
|
-
this.#authorizationCache.clear();
|
|
5371
|
-
this.#connecting = false;
|
|
5372
|
-
this.#connectionGeneration++;
|
|
5373
|
-
this.#authorization = void 0;
|
|
5374
|
-
this.#emit("change", { accounts: this.accounts });
|
|
5375
|
-
};
|
|
5376
|
-
#transact = async (callback) => {
|
|
5377
|
-
const walletUriBase = this.#authorization?.wallet_uri_base;
|
|
5378
|
-
const config = walletUriBase ? { baseUri: walletUriBase } : void 0;
|
|
5379
|
-
const currentConnectionGeneration = this.#connectionGeneration;
|
|
5380
|
-
const loadingSpinner = new EmbeddedLoadingSpinner();
|
|
5381
|
-
try {
|
|
5382
|
-
let associating = true;
|
|
5383
|
-
let timeout = void 0;
|
|
5384
|
-
const result = await Promise.race([checkLocalNetworkAccessPermission().then(async () => {
|
|
5385
|
-
loadingSpinner.init();
|
|
5386
|
-
const { wallet, close } = await startScenario(config);
|
|
5387
|
-
associating = false;
|
|
5388
|
-
loadingSpinner.addEventListener("close", (event) => {
|
|
5389
|
-
if (event) close();
|
|
5390
|
-
});
|
|
5391
|
-
loadingSpinner.open();
|
|
5392
|
-
const result = await callback(await wallet);
|
|
5393
|
-
loadingSpinner.close();
|
|
5394
|
-
close();
|
|
5395
|
-
return result;
|
|
5396
|
-
}), new Promise((_, reject) => {
|
|
5397
|
-
timeout = setTimeout(() => {
|
|
5398
|
-
if (associating) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, "Wallet connection timed out", { event: void 0 }));
|
|
5399
|
-
}, WALLET_ASSOCIATION_TIMEOUT);
|
|
5400
|
-
})]);
|
|
5401
|
-
clearTimeout(timeout);
|
|
5402
|
-
return result;
|
|
5403
|
-
} catch (e) {
|
|
5404
|
-
loadingSpinner.close();
|
|
5405
|
-
if (this.#connectionGeneration !== currentConnectionGeneration) await new Promise(() => {});
|
|
5406
|
-
if (e instanceof Error && e.name === "SolanaMobileWalletAdapterError" && e.code === "ERROR_WALLET_NOT_FOUND") await this.#onWalletNotFound(this);
|
|
5407
|
-
throw e;
|
|
5408
|
-
}
|
|
5409
|
-
};
|
|
5410
|
-
#assertIsAuthorized = () => {
|
|
5411
|
-
if (!this.#authorization) throw new Error("Wallet not connected");
|
|
5412
|
-
return {
|
|
5413
|
-
authToken: this.#authorization.auth_token,
|
|
5414
|
-
chain: this.#authorization.chain
|
|
5415
|
-
};
|
|
5416
|
-
};
|
|
5417
|
-
#accountsToWalletStandardAccounts = (accounts) => {
|
|
5418
|
-
return accounts.map((account) => {
|
|
5419
|
-
const publicKey = toUint8Array(account.address);
|
|
5420
|
-
return {
|
|
5421
|
-
address: base58.encode(publicKey),
|
|
5422
|
-
publicKey,
|
|
5423
|
-
label: account.label,
|
|
5424
|
-
icon: account.icon,
|
|
5425
|
-
chains: account.chains ?? this.#chains,
|
|
5426
|
-
features: account.features ?? DEFAULT_FEATURES
|
|
5427
|
-
};
|
|
5428
|
-
});
|
|
5429
|
-
};
|
|
5430
|
-
#performSignTransactions = async (transactions) => {
|
|
5431
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
5432
|
-
try {
|
|
5433
|
-
const base64Transactions = transactions.map((tx) => {
|
|
5434
|
-
return fromUint8Array(tx);
|
|
5435
|
-
});
|
|
5436
|
-
return await this.#transact(async (wallet) => {
|
|
5437
|
-
await this.#performReauthorization(wallet, authToken, chain);
|
|
5438
|
-
return (await wallet.signTransactions({ payloads: base64Transactions })).signed_payloads.map(toUint8Array);
|
|
5439
|
-
});
|
|
5440
|
-
} catch (e) {
|
|
5441
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5442
|
-
}
|
|
5443
|
-
};
|
|
5444
|
-
#performSignAndSendTransaction = async (transaction, options) => {
|
|
5445
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
5446
|
-
try {
|
|
5447
|
-
return await this.#transact(async (wallet) => {
|
|
5448
|
-
const [capabilities] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
|
|
5449
|
-
if (capabilities.supports_sign_and_send_transactions) {
|
|
5450
|
-
const base64Transaction = fromUint8Array(transaction);
|
|
5451
|
-
return (await wallet.signAndSendTransactions({
|
|
5452
|
-
...options,
|
|
5453
|
-
payloads: [base64Transaction]
|
|
5454
|
-
})).signatures.map(toUint8Array)[0];
|
|
5455
|
-
} else throw new Error("connected wallet does not support signAndSendTransaction");
|
|
5456
|
-
});
|
|
5457
|
-
} catch (e) {
|
|
5458
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5459
|
-
}
|
|
5460
|
-
};
|
|
5461
|
-
#signAndSendTransaction = async (...inputs) => {
|
|
5462
|
-
const outputs = [];
|
|
5463
|
-
for (const input of inputs) {
|
|
5464
|
-
const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
|
|
5465
|
-
outputs.push({ signature });
|
|
5466
|
-
}
|
|
5467
|
-
return outputs;
|
|
5468
|
-
};
|
|
5469
|
-
#signTransaction = async (...inputs) => {
|
|
5470
|
-
return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction))).map((signedTransaction) => {
|
|
5471
|
-
return { signedTransaction };
|
|
5472
|
-
});
|
|
5473
|
-
};
|
|
5474
|
-
#signMessage = async (...inputs) => {
|
|
5475
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
5476
|
-
const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
|
|
5477
|
-
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
5478
|
-
try {
|
|
5479
|
-
return await this.#transact(async (wallet) => {
|
|
5480
|
-
await this.#performReauthorization(wallet, authToken, chain);
|
|
5481
|
-
return (await wallet.signMessages({
|
|
5482
|
-
addresses,
|
|
5483
|
-
payloads: messages
|
|
5484
|
-
})).signed_payloads.map(toUint8Array).map((signedMessage) => {
|
|
5485
|
-
return {
|
|
5486
|
-
signedMessage,
|
|
5487
|
-
signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES)
|
|
5488
|
-
};
|
|
5489
|
-
});
|
|
5490
|
-
});
|
|
5491
|
-
} catch (e) {
|
|
5492
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5493
|
-
}
|
|
5494
|
-
};
|
|
5495
|
-
#signIn = async (...inputs) => {
|
|
5496
|
-
const outputs = [];
|
|
5497
|
-
if (inputs.length > 1) for (const input of inputs) outputs.push(await this.#performSignIn(input));
|
|
5498
|
-
else return [await this.#performSignIn(inputs[0])];
|
|
5499
|
-
return outputs;
|
|
5500
|
-
};
|
|
5501
|
-
#performSignIn = async (input) => {
|
|
5502
|
-
this.#connecting = true;
|
|
5503
|
-
try {
|
|
5504
|
-
const authorizationResult = await this.#performAuthorization({
|
|
5505
|
-
...input,
|
|
5506
|
-
domain: input?.domain ?? window.location.host
|
|
5507
|
-
});
|
|
5508
|
-
if (!authorizationResult.sign_in_result) throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
5509
|
-
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
5510
|
-
const signedInAccount = authorizationResult.accounts.find((acc) => acc.address == signedInAddress);
|
|
5511
|
-
return {
|
|
5512
|
-
account: {
|
|
5513
|
-
...signedInAccount ?? { address: base58.encode(toUint8Array(signedInAddress)) },
|
|
5514
|
-
publicKey: toUint8Array(signedInAddress),
|
|
5515
|
-
chains: signedInAccount?.chains ?? this.#chains,
|
|
5516
|
-
features: signedInAccount?.features ?? authorizationResult.capabilities.features
|
|
5517
|
-
},
|
|
5518
|
-
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
5519
|
-
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
5520
|
-
};
|
|
5521
|
-
} catch (e) {
|
|
5522
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5523
|
-
} finally {
|
|
5524
|
-
this.#connecting = false;
|
|
5525
|
-
}
|
|
5526
|
-
};
|
|
5527
|
-
};
|
|
5528
|
-
var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
5529
|
-
#listeners = {};
|
|
5530
|
-
#version = "1.0.0";
|
|
5531
|
-
#name = SolanaMobileWalletAdapterRemoteWalletName;
|
|
5532
|
-
#url = "https://solanamobile.com/wallets";
|
|
5533
|
-
#icon = icon;
|
|
5534
|
-
#appIdentity;
|
|
5535
|
-
#authorization;
|
|
5536
|
-
#authorizationCache;
|
|
5537
|
-
#connecting = false;
|
|
5538
|
-
/**
|
|
5539
|
-
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
5540
|
-
* increment this and use it to make sure that `transact` calls from the previous
|
|
5541
|
-
* 'generation' don't continue to do work and throw exceptions.
|
|
5542
|
-
*/
|
|
5543
|
-
#connectionGeneration = 0;
|
|
5544
|
-
#chains = [];
|
|
5545
|
-
#chainSelector;
|
|
5546
|
-
#optionalFeatures;
|
|
5547
|
-
#onWalletNotFound;
|
|
5548
|
-
#hostAuthority;
|
|
5549
|
-
#session;
|
|
5550
|
-
get version() {
|
|
5551
|
-
return this.#version;
|
|
5552
|
-
}
|
|
5553
|
-
get name() {
|
|
5554
|
-
return this.#name;
|
|
5555
|
-
}
|
|
5556
|
-
get url() {
|
|
5557
|
-
return this.#url;
|
|
5558
|
-
}
|
|
5559
|
-
get icon() {
|
|
5560
|
-
return this.#icon;
|
|
5561
|
-
}
|
|
5562
|
-
get chains() {
|
|
5563
|
-
return this.#chains;
|
|
5564
|
-
}
|
|
5565
|
-
get features() {
|
|
5566
|
-
return {
|
|
5567
|
-
[StandardConnect]: {
|
|
5568
|
-
version: "1.0.0",
|
|
5569
|
-
connect: this.#connect
|
|
5570
|
-
},
|
|
5571
|
-
[StandardDisconnect]: {
|
|
5572
|
-
version: "1.0.0",
|
|
5573
|
-
disconnect: this.#disconnect
|
|
5574
|
-
},
|
|
5575
|
-
[StandardEvents]: {
|
|
5576
|
-
version: "1.0.0",
|
|
5577
|
-
on: this.#on
|
|
5578
|
-
},
|
|
5579
|
-
[SolanaSignMessage]: {
|
|
5580
|
-
version: "1.0.0",
|
|
5581
|
-
signMessage: this.#signMessage
|
|
5582
|
-
},
|
|
5583
|
-
[SolanaSignIn]: {
|
|
5584
|
-
version: "1.0.0",
|
|
5585
|
-
signIn: this.#signIn
|
|
5586
|
-
},
|
|
5587
|
-
...this.#optionalFeatures
|
|
5588
|
-
};
|
|
5589
|
-
}
|
|
5590
|
-
get accounts() {
|
|
5591
|
-
return this.#authorization?.accounts ?? [];
|
|
5592
|
-
}
|
|
5593
|
-
constructor(config) {
|
|
5594
|
-
this.#authorizationCache = config.authorizationCache;
|
|
5595
|
-
this.#appIdentity = config.appIdentity;
|
|
5596
|
-
this.#chains = config.chains;
|
|
5597
|
-
this.#chainSelector = config.chainSelector;
|
|
5598
|
-
this.#hostAuthority = config.remoteHostAuthority;
|
|
5599
|
-
this.#onWalletNotFound = config.onWalletNotFound;
|
|
5600
|
-
this.#optionalFeatures = {
|
|
5601
|
-
[SolanaSignAndSendTransaction]: {
|
|
5602
|
-
version: "1.0.0",
|
|
5603
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
5604
|
-
signAndSendTransaction: this.#signAndSendTransaction
|
|
5605
|
-
},
|
|
5606
|
-
[SolanaSignTransaction]: {
|
|
5607
|
-
version: "1.0.0",
|
|
5608
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
5609
|
-
signTransaction: this.#signTransaction
|
|
5610
|
-
}
|
|
5611
|
-
};
|
|
5612
|
-
}
|
|
5613
|
-
get connected() {
|
|
5614
|
-
return !!this.#session && !!this.#authorization;
|
|
5615
|
-
}
|
|
5616
|
-
get isAuthorized() {
|
|
5617
|
-
return !!this.#authorization;
|
|
5618
|
-
}
|
|
5619
|
-
get currentAuthorization() {
|
|
5620
|
-
return this.#authorization;
|
|
5621
|
-
}
|
|
5622
|
-
get cachedAuthorizationResult() {
|
|
5623
|
-
return this.#authorizationCache.get();
|
|
5624
|
-
}
|
|
5625
|
-
#on = (event, listener) => {
|
|
5626
|
-
this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
|
|
5627
|
-
return () => this.#off(event, listener);
|
|
5628
|
-
};
|
|
5629
|
-
#emit(event, ...args) {
|
|
5630
|
-
this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
|
|
5631
|
-
}
|
|
5632
|
-
#off(event, listener) {
|
|
5633
|
-
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
5634
|
-
}
|
|
5635
|
-
#connect = async (_input = {}) => {
|
|
5636
|
-
if (this.#connecting || this.connected) return { accounts: this.accounts };
|
|
5637
|
-
this.#connecting = true;
|
|
5638
|
-
try {
|
|
5639
|
-
await this.#performAuthorization();
|
|
5640
|
-
} catch (e) {
|
|
5641
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5642
|
-
} finally {
|
|
5643
|
-
this.#connecting = false;
|
|
5644
|
-
}
|
|
5645
|
-
return { accounts: this.accounts };
|
|
5646
|
-
};
|
|
5647
|
-
#performAuthorization = async (signInPayload) => {
|
|
5648
|
-
try {
|
|
5649
|
-
const cachedAuthorizationResult = await this.#authorizationCache.get();
|
|
5650
|
-
if (cachedAuthorizationResult) {
|
|
5651
|
-
this.#handleAuthorizationResult(cachedAuthorizationResult);
|
|
5652
|
-
return cachedAuthorizationResult;
|
|
5653
|
-
}
|
|
5654
|
-
if (this.#session) this.#session = void 0;
|
|
5655
|
-
const selectedChain = await this.#chainSelector.select(this.#chains);
|
|
5656
|
-
return await this.#transact(async (wallet) => {
|
|
5657
|
-
const [capabilities, mwaAuthorizationResult] = await Promise.all([wallet.getCapabilities(), wallet.authorize({
|
|
5658
|
-
chain: selectedChain,
|
|
5659
|
-
identity: this.#appIdentity,
|
|
5660
|
-
sign_in_payload: signInPayload
|
|
5661
|
-
})]);
|
|
5662
|
-
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
5663
|
-
const authorizationResult = {
|
|
5664
|
-
...mwaAuthorizationResult,
|
|
5665
|
-
accounts,
|
|
5666
|
-
chain: selectedChain,
|
|
5667
|
-
capabilities
|
|
5668
|
-
};
|
|
5669
|
-
Promise.all([
|
|
5670
|
-
this.#handleWalletCapabilitiesResult(capabilities),
|
|
5671
|
-
this.#authorizationCache.set(authorizationResult),
|
|
5672
|
-
this.#handleAuthorizationResult(authorizationResult)
|
|
5673
|
-
]);
|
|
5674
|
-
return authorizationResult;
|
|
5675
|
-
});
|
|
5676
|
-
} catch (e) {
|
|
5677
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5678
|
-
}
|
|
5679
|
-
};
|
|
5680
|
-
#handleAuthorizationResult = async (authorization) => {
|
|
5681
|
-
const didPublicKeysChange = this.#authorization == null || this.#authorization?.accounts.length !== authorization.accounts.length || this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
5682
|
-
this.#authorization = authorization;
|
|
5683
|
-
if (didPublicKeysChange) this.#emit("change", { accounts: this.accounts });
|
|
5684
|
-
};
|
|
5685
|
-
#handleWalletCapabilitiesResult = async (capabilities) => {
|
|
5686
|
-
const supportsSignTransaction = capabilities.features.includes("solana:signTransactions");
|
|
5687
|
-
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions || capabilities.features.includes("solana:signAndSendTransaction");
|
|
5688
|
-
const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction || SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
5689
|
-
this.#optionalFeatures = {
|
|
5690
|
-
...supportsSignAndSendTransaction && { [SolanaSignAndSendTransaction]: {
|
|
5691
|
-
version: "1.0.0",
|
|
5692
|
-
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
5693
|
-
signAndSendTransaction: this.#signAndSendTransaction
|
|
5694
|
-
} },
|
|
5695
|
-
...supportsSignTransaction && { [SolanaSignTransaction]: {
|
|
5696
|
-
version: "1.0.0",
|
|
5697
|
-
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
5698
|
-
signTransaction: this.#signTransaction
|
|
5699
|
-
} }
|
|
5700
|
-
};
|
|
5701
|
-
if (didCapabilitiesChange) this.#emit("change", { features: this.features });
|
|
5702
|
-
};
|
|
5703
|
-
#performReauthorization = async (wallet, authToken, chain) => {
|
|
5704
|
-
try {
|
|
5705
|
-
const [capabilities, mwaAuthorizationResult] = await Promise.all([this.#authorization?.capabilities ?? await wallet.getCapabilities(), wallet.authorize({
|
|
5706
|
-
auth_token: authToken,
|
|
5707
|
-
identity: this.#appIdentity,
|
|
5708
|
-
chain
|
|
5709
|
-
})]);
|
|
5710
|
-
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
5711
|
-
const authorization = {
|
|
5712
|
-
...mwaAuthorizationResult,
|
|
5713
|
-
accounts,
|
|
5714
|
-
chain,
|
|
5715
|
-
capabilities
|
|
5716
|
-
};
|
|
5717
|
-
Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
|
|
5718
|
-
} catch (e) {
|
|
5719
|
-
this.#disconnect();
|
|
5720
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5721
|
-
}
|
|
5722
|
-
};
|
|
5723
|
-
#disconnect = async () => {
|
|
5724
|
-
this.#session?.close();
|
|
5725
|
-
this.#authorizationCache.clear();
|
|
5726
|
-
this.#connecting = false;
|
|
5727
|
-
this.#connectionGeneration++;
|
|
5728
|
-
this.#authorization = void 0;
|
|
5729
|
-
this.#session = void 0;
|
|
5730
|
-
this.#emit("change", { accounts: this.accounts });
|
|
5731
|
-
};
|
|
5732
|
-
#transact = async (callback) => {
|
|
5733
|
-
const walletUriBase = this.#authorization?.wallet_uri_base;
|
|
5734
|
-
const remoteConfig = {
|
|
5735
|
-
...walletUriBase ? { baseUri: walletUriBase } : void 0,
|
|
5736
|
-
remoteHostAuthority: this.#hostAuthority
|
|
5737
|
-
};
|
|
5738
|
-
const currentConnectionGeneration = this.#connectionGeneration;
|
|
5739
|
-
const modal = new RemoteConnectionModal();
|
|
5740
|
-
if (this.#session) return callback(this.#session.wallet);
|
|
5741
|
-
try {
|
|
5742
|
-
modal.init();
|
|
5743
|
-
modal.open();
|
|
5744
|
-
const { associationUrl, close, wallet } = await startRemoteScenario(remoteConfig);
|
|
5745
|
-
const removeCloseListener = modal.addEventListener("close", (event) => {
|
|
5746
|
-
if (event) close();
|
|
5747
|
-
});
|
|
5748
|
-
modal.populateQRCode(associationUrl.toString());
|
|
5749
|
-
this.#session = {
|
|
5750
|
-
close,
|
|
5751
|
-
wallet: await wallet
|
|
5752
|
-
};
|
|
5753
|
-
removeCloseListener();
|
|
5754
|
-
modal.close();
|
|
5755
|
-
return await callback(this.#session.wallet);
|
|
5756
|
-
} catch (e) {
|
|
5757
|
-
modal.close();
|
|
5758
|
-
if (this.#connectionGeneration !== currentConnectionGeneration) await new Promise(() => {});
|
|
5759
|
-
if (e instanceof Error && e.name === "SolanaMobileWalletAdapterError" && e.code === "ERROR_WALLET_NOT_FOUND") await this.#onWalletNotFound(this);
|
|
5760
|
-
throw e;
|
|
5761
|
-
}
|
|
5762
|
-
};
|
|
5763
|
-
#assertIsAuthorized = () => {
|
|
5764
|
-
if (!this.#authorization) throw new Error("Wallet not connected");
|
|
5765
|
-
return {
|
|
5766
|
-
authToken: this.#authorization.auth_token,
|
|
5767
|
-
chain: this.#authorization.chain
|
|
5768
|
-
};
|
|
5769
|
-
};
|
|
5770
|
-
#accountsToWalletStandardAccounts = (accounts) => {
|
|
5771
|
-
return accounts.map((account) => {
|
|
5772
|
-
const publicKey = toUint8Array(account.address);
|
|
5773
|
-
return {
|
|
5774
|
-
address: base58.encode(publicKey),
|
|
5775
|
-
publicKey,
|
|
5776
|
-
label: account.label,
|
|
5777
|
-
icon: account.icon,
|
|
5778
|
-
chains: account.chains ?? this.#chains,
|
|
5779
|
-
features: account.features ?? DEFAULT_FEATURES
|
|
5780
|
-
};
|
|
5781
|
-
});
|
|
5782
|
-
};
|
|
5783
|
-
#performSignTransactions = async (transactions) => {
|
|
5784
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
5785
|
-
try {
|
|
5786
|
-
return await this.#transact(async (wallet) => {
|
|
5787
|
-
await this.#performReauthorization(wallet, authToken, chain);
|
|
5788
|
-
return (await wallet.signTransactions({ payloads: transactions.map(fromUint8Array) })).signed_payloads.map(toUint8Array);
|
|
5789
|
-
});
|
|
5790
|
-
} catch (e) {
|
|
5791
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5792
|
-
}
|
|
5793
|
-
};
|
|
5794
|
-
#performSignAndSendTransaction = async (transaction, options) => {
|
|
5795
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
5796
|
-
try {
|
|
5797
|
-
return await this.#transact(async (wallet) => {
|
|
5798
|
-
const [capabilities] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
|
|
5799
|
-
if (capabilities.supports_sign_and_send_transactions) return (await wallet.signAndSendTransactions({
|
|
5800
|
-
...options,
|
|
5801
|
-
payloads: [fromUint8Array(transaction)]
|
|
5802
|
-
})).signatures.map(toUint8Array)[0];
|
|
5803
|
-
else throw new Error("connected wallet does not support signAndSendTransaction");
|
|
5804
|
-
});
|
|
5805
|
-
} catch (e) {
|
|
5806
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5807
|
-
}
|
|
5808
|
-
};
|
|
5809
|
-
#signAndSendTransaction = async (...inputs) => {
|
|
5810
|
-
const outputs = [];
|
|
5811
|
-
for (const input of inputs) {
|
|
5812
|
-
const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
|
|
5813
|
-
outputs.push({ signature });
|
|
5814
|
-
}
|
|
5815
|
-
return outputs;
|
|
5816
|
-
};
|
|
5817
|
-
#signTransaction = async (...inputs) => {
|
|
5818
|
-
return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction))).map((signedTransaction) => {
|
|
5819
|
-
return { signedTransaction };
|
|
5820
|
-
});
|
|
5821
|
-
};
|
|
5822
|
-
#signMessage = async (...inputs) => {
|
|
5823
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
5824
|
-
const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
|
|
5825
|
-
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
5826
|
-
try {
|
|
5827
|
-
return await this.#transact(async (wallet) => {
|
|
5828
|
-
await this.#performReauthorization(wallet, authToken, chain);
|
|
5829
|
-
return (await wallet.signMessages({
|
|
5830
|
-
addresses,
|
|
5831
|
-
payloads: messages
|
|
5832
|
-
})).signed_payloads.map(toUint8Array).map((signedMessage) => {
|
|
5833
|
-
return {
|
|
5834
|
-
signedMessage,
|
|
5835
|
-
signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES)
|
|
5836
|
-
};
|
|
5837
|
-
});
|
|
5838
|
-
});
|
|
5839
|
-
} catch (e) {
|
|
5840
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5841
|
-
}
|
|
5842
|
-
};
|
|
5843
|
-
#signIn = async (...inputs) => {
|
|
5844
|
-
const outputs = [];
|
|
5845
|
-
if (inputs.length > 1) for (const input of inputs) outputs.push(await this.#performSignIn(input));
|
|
5846
|
-
else return [await this.#performSignIn(inputs[0])];
|
|
5847
|
-
return outputs;
|
|
5848
|
-
};
|
|
5849
|
-
#performSignIn = async (input) => {
|
|
5850
|
-
this.#connecting = true;
|
|
5851
|
-
try {
|
|
5852
|
-
const authorizationResult = await this.#performAuthorization({
|
|
5853
|
-
...input,
|
|
5854
|
-
domain: input?.domain ?? window.location.host
|
|
5855
|
-
});
|
|
5856
|
-
if (!authorizationResult.sign_in_result) throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
5857
|
-
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
5858
|
-
const signedInAccount = authorizationResult.accounts.find((acc) => acc.address == signedInAddress);
|
|
5859
|
-
return {
|
|
5860
|
-
account: {
|
|
5861
|
-
...signedInAccount ?? { address: base58.encode(toUint8Array(signedInAddress)) },
|
|
5862
|
-
publicKey: toUint8Array(signedInAddress),
|
|
5863
|
-
chains: signedInAccount?.chains ?? this.#chains,
|
|
5864
|
-
features: signedInAccount?.features ?? authorizationResult.capabilities.features
|
|
5865
|
-
},
|
|
5866
|
-
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
5867
|
-
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
5868
|
-
};
|
|
5869
|
-
} catch (e) {
|
|
5870
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
5871
|
-
} finally {
|
|
5872
|
-
this.#connecting = false;
|
|
5873
|
-
}
|
|
5874
|
-
};
|
|
5875
|
-
};
|
|
5876
|
-
//#endregion
|
|
5877
|
-
//#region src/initialize.ts
|
|
4479
|
+
|
|
5878
4480
|
function registerMwa(config) {
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
4481
|
+
if (typeof window === 'undefined') {
|
|
4482
|
+
console.warn(`MWA not registered: no window object`);
|
|
4483
|
+
return;
|
|
4484
|
+
}
|
|
4485
|
+
if (!window.isSecureContext) {
|
|
4486
|
+
console.warn(`MWA not registered: secure context required (https)`);
|
|
4487
|
+
return;
|
|
4488
|
+
}
|
|
4489
|
+
// Local association technically is possible in a webview, but we prevent registration
|
|
4490
|
+
// by default because it usually fails in the most common cases (e.g wallet browsers).
|
|
4491
|
+
if (getIsLocalAssociationSupported() && !isWebView(navigator.userAgent)) {
|
|
4492
|
+
registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
|
|
4493
|
+
}
|
|
4494
|
+
else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== undefined) {
|
|
4495
|
+
registerWallet(new RemoteSolanaMobileWalletAdapterWallet(Object.assign(Object.assign({}, config), { remoteHostAuthority: config.remoteHostAuthority })));
|
|
4496
|
+
}
|
|
4497
|
+
else ;
|
|
4498
|
+
}
|
|
4499
|
+
|
|
4500
|
+
const WALLET_NOT_FOUND_ERROR_MESSAGE = 'To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.';
|
|
4501
|
+
const BROWSER_NOT_SUPPORTED_ERROR_MESSAGE = 'This browser appears to be incompatible with mobile wallet adapter. Open this page in a compatible mobile browser app and try again.';
|
|
4502
|
+
class ErrorModal extends EmbeddedModal {
|
|
4503
|
+
constructor() {
|
|
4504
|
+
super(...arguments);
|
|
4505
|
+
this.contentStyles = css;
|
|
4506
|
+
this.contentHtml = ErrorDialogHtml;
|
|
4507
|
+
}
|
|
4508
|
+
initWithError(error) {
|
|
4509
|
+
super.init();
|
|
4510
|
+
this.populateError(error);
|
|
4511
|
+
}
|
|
4512
|
+
populateError(error) {
|
|
4513
|
+
var _a, _b;
|
|
4514
|
+
const errorMessageElement = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-error-message');
|
|
4515
|
+
const actionBtn = (_b = this.dom) === null || _b === void 0 ? void 0 : _b.getElementById('mobile-wallet-adapter-error-action');
|
|
4516
|
+
if (errorMessageElement) {
|
|
4517
|
+
if (error.name === 'SolanaMobileWalletAdapterError') {
|
|
4518
|
+
switch (error.code) {
|
|
4519
|
+
case 'ERROR_WALLET_NOT_FOUND':
|
|
4520
|
+
errorMessageElement.innerHTML = WALLET_NOT_FOUND_ERROR_MESSAGE;
|
|
4521
|
+
if (actionBtn)
|
|
4522
|
+
actionBtn.addEventListener('click', () => {
|
|
4523
|
+
window.location.href = 'https://solanamobile.com/wallets';
|
|
4524
|
+
});
|
|
4525
|
+
return;
|
|
4526
|
+
case 'ERROR_BROWSER_NOT_SUPPORTED':
|
|
4527
|
+
errorMessageElement.innerHTML = BROWSER_NOT_SUPPORTED_ERROR_MESSAGE;
|
|
4528
|
+
if (actionBtn)
|
|
4529
|
+
actionBtn.style.display = 'none';
|
|
4530
|
+
return;
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
errorMessageElement.innerHTML = `An unexpected error occurred: ${error.message}`;
|
|
4534
|
+
}
|
|
4535
|
+
else {
|
|
4536
|
+
console.log('Failed to locate error dialog element');
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
5893
4539
|
}
|
|
5894
|
-
//#endregion
|
|
5895
|
-
//#region src/embedded-modal/errorModal.ts
|
|
5896
|
-
const WALLET_NOT_FOUND_ERROR_MESSAGE = "To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.";
|
|
5897
|
-
const BROWSER_NOT_SUPPORTED_ERROR_MESSAGE = "This browser appears to be incompatible with mobile wallet adapter. Open this page in a compatible mobile browser app and try again.";
|
|
5898
|
-
var ErrorModal = class extends EmbeddedModal {
|
|
5899
|
-
contentStyles = css;
|
|
5900
|
-
contentHtml = ErrorDialogHtml;
|
|
5901
|
-
initWithError(error) {
|
|
5902
|
-
super.init();
|
|
5903
|
-
this.populateError(error);
|
|
5904
|
-
}
|
|
5905
|
-
populateError(error) {
|
|
5906
|
-
const errorMessageElement = this.dom?.getElementById("mobile-wallet-adapter-error-message");
|
|
5907
|
-
const actionBtn = this.dom?.getElementById("mobile-wallet-adapter-error-action");
|
|
5908
|
-
if (errorMessageElement) {
|
|
5909
|
-
if (error.name === "SolanaMobileWalletAdapterError") switch (error.code) {
|
|
5910
|
-
case "ERROR_WALLET_NOT_FOUND":
|
|
5911
|
-
errorMessageElement.innerHTML = WALLET_NOT_FOUND_ERROR_MESSAGE;
|
|
5912
|
-
if (actionBtn) actionBtn.addEventListener("click", () => {
|
|
5913
|
-
window.location.href = "https://solanamobile.com/wallets";
|
|
5914
|
-
});
|
|
5915
|
-
return;
|
|
5916
|
-
case "ERROR_BROWSER_NOT_SUPPORTED":
|
|
5917
|
-
errorMessageElement.innerHTML = BROWSER_NOT_SUPPORTED_ERROR_MESSAGE;
|
|
5918
|
-
if (actionBtn) actionBtn.style.display = "none";
|
|
5919
|
-
return;
|
|
5920
|
-
}
|
|
5921
|
-
errorMessageElement.innerHTML = `An unexpected error occurred: ${error.message}`;
|
|
5922
|
-
} else console.log("Failed to locate error dialog element");
|
|
5923
|
-
}
|
|
5924
|
-
};
|
|
5925
4540
|
const ErrorDialogHtml = `
|
|
5926
4541
|
<svg class="mobile-wallet-adapter-embedded-modal-error-icon" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#000000"><path d="M 280,-80 Q 197,-80 138.5,-138.5 80,-197 80,-280 80,-363 138.5,-421.5 197,-480 280,-480 q 83,0 141.5,58.5 58.5,58.5 58.5,141.5 0,83 -58.5,141.5 Q 363,-80 280,-80 Z M 824,-120 568,-376 Q 556,-389 542.5,-402.5 529,-416 516,-428 q 38,-24 61,-64 23,-40 23,-88 0,-75 -52.5,-127.5 Q 495,-760 420,-760 345,-760 292.5,-707.5 240,-655 240,-580 q 0,6 0.5,11.5 0.5,5.5 1.5,11.5 -18,2 -39.5,8 -21.5,6 -38.5,14 -2,-11 -3,-22 -1,-11 -1,-23 0,-109 75.5,-184.5 Q 311,-840 420,-840 q 109,0 184.5,75.5 75.5,75.5 75.5,184.5 0,43 -13.5,81.5 Q 653,-460 629,-428 l 251,252 z m -615,-61 71,-71 70,71 29,-28 -71,-71 71,-71 -28,-28 -71,71 -71,-71 -28,28 71,71 -71,71 z"/></svg>
|
|
5927
4542
|
<div class="mobile-wallet-adapter-embedded-modal-title">We can't find a wallet.</div>
|
|
@@ -5981,80 +4596,123 @@ const css = `
|
|
|
5981
4596
|
}
|
|
5982
4597
|
}
|
|
5983
4598
|
`;
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
4599
|
+
|
|
4600
|
+
function defaultErrorModalWalletNotFoundHandler() {
|
|
4601
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4602
|
+
if (typeof window !== 'undefined') {
|
|
4603
|
+
const userAgent = window.navigator.userAgent.toLowerCase();
|
|
4604
|
+
const errorDialog = new ErrorModal();
|
|
4605
|
+
if (userAgent.includes('wv')) { // Android WebView
|
|
4606
|
+
// MWA is not supported in this browser so we inform the user
|
|
4607
|
+
// errorDialog.initWithError(
|
|
4608
|
+
// new SolanaMobileWalletAdapterError(
|
|
4609
|
+
// SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED,
|
|
4610
|
+
// ''
|
|
4611
|
+
// )
|
|
4612
|
+
// );
|
|
4613
|
+
// TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
|
|
4614
|
+
errorDialog.initWithError({
|
|
4615
|
+
name: 'SolanaMobileWalletAdapterError',
|
|
4616
|
+
code: 'ERROR_BROWSER_NOT_SUPPORTED',
|
|
4617
|
+
message: ''
|
|
4618
|
+
});
|
|
4619
|
+
}
|
|
4620
|
+
else { // Browser, user does not have a wallet installed.
|
|
4621
|
+
// errorDialog.initWithError(
|
|
4622
|
+
// new SolanaMobileWalletAdapterError(
|
|
4623
|
+
// SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
|
|
4624
|
+
// ''
|
|
4625
|
+
// )
|
|
4626
|
+
// );
|
|
4627
|
+
// TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
|
|
4628
|
+
errorDialog.initWithError({
|
|
4629
|
+
name: 'SolanaMobileWalletAdapterError',
|
|
4630
|
+
code: 'ERROR_WALLET_NOT_FOUND',
|
|
4631
|
+
message: ''
|
|
4632
|
+
});
|
|
4633
|
+
}
|
|
4634
|
+
errorDialog.open();
|
|
4635
|
+
}
|
|
4636
|
+
});
|
|
6002
4637
|
}
|
|
6003
4638
|
function createDefaultWalletNotFoundHandler() {
|
|
6004
|
-
|
|
6005
|
-
defaultErrorModalWalletNotFoundHandler();
|
|
6006
|
-
};
|
|
4639
|
+
return () => __awaiter(this, void 0, void 0, function* () { defaultErrorModalWalletNotFoundHandler(); });
|
|
6007
4640
|
}
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
const CACHE_KEY = "SolanaMobileWalletAdapterDefaultAuthorizationCache";
|
|
4641
|
+
|
|
4642
|
+
const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
|
|
6011
4643
|
function createDefaultAuthorizationCache() {
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
4644
|
+
let storage;
|
|
4645
|
+
try {
|
|
4646
|
+
storage = window.localStorage;
|
|
4647
|
+
// eslint-disable-next-line no-empty
|
|
4648
|
+
}
|
|
4649
|
+
catch (_a) { }
|
|
4650
|
+
return {
|
|
4651
|
+
clear() {
|
|
4652
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4653
|
+
if (!storage) {
|
|
4654
|
+
return;
|
|
4655
|
+
}
|
|
4656
|
+
try {
|
|
4657
|
+
storage.removeItem(CACHE_KEY);
|
|
4658
|
+
// eslint-disable-next-line no-empty
|
|
4659
|
+
}
|
|
4660
|
+
catch (_a) { }
|
|
4661
|
+
});
|
|
4662
|
+
},
|
|
4663
|
+
get() {
|
|
4664
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4665
|
+
if (!storage) {
|
|
4666
|
+
return;
|
|
4667
|
+
}
|
|
4668
|
+
try {
|
|
4669
|
+
const parsed = JSON.parse(storage.getItem(CACHE_KEY));
|
|
4670
|
+
if (parsed && parsed.accounts) {
|
|
4671
|
+
const parsedAccounts = parsed.accounts.map((account) => {
|
|
4672
|
+
return Object.assign(Object.assign({}, account), { publicKey: 'publicKey' in account
|
|
4673
|
+
? new Uint8Array(Object.values(account.publicKey)) // Rebuild publicKey for WalletAccount
|
|
4674
|
+
: base58.decode(account.address) });
|
|
4675
|
+
});
|
|
4676
|
+
return Object.assign(Object.assign({}, parsed), { accounts: parsedAccounts });
|
|
4677
|
+
}
|
|
4678
|
+
else
|
|
4679
|
+
return parsed || undefined;
|
|
4680
|
+
// eslint-disable-next-line no-empty
|
|
4681
|
+
}
|
|
4682
|
+
catch (_a) { }
|
|
4683
|
+
});
|
|
4684
|
+
},
|
|
4685
|
+
set(authorization) {
|
|
4686
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4687
|
+
if (!storage) {
|
|
4688
|
+
return;
|
|
4689
|
+
}
|
|
4690
|
+
try {
|
|
4691
|
+
storage.setItem(CACHE_KEY, JSON.stringify(authorization));
|
|
4692
|
+
// eslint-disable-next-line no-empty
|
|
4693
|
+
}
|
|
4694
|
+
catch (_a) { }
|
|
4695
|
+
});
|
|
4696
|
+
},
|
|
4697
|
+
};
|
|
6048
4698
|
}
|
|
6049
|
-
|
|
6050
|
-
//#region src/createDefaultChainSelector.ts
|
|
4699
|
+
|
|
6051
4700
|
function createDefaultChainSelector() {
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
4701
|
+
return {
|
|
4702
|
+
select(chains) {
|
|
4703
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4704
|
+
if (chains.length === 1) {
|
|
4705
|
+
return chains[0];
|
|
4706
|
+
}
|
|
4707
|
+
else if (chains.includes(SOLANA_MAINNET_CHAIN)) {
|
|
4708
|
+
return SOLANA_MAINNET_CHAIN;
|
|
4709
|
+
}
|
|
4710
|
+
else
|
|
4711
|
+
return chains[0];
|
|
4712
|
+
});
|
|
4713
|
+
},
|
|
4714
|
+
};
|
|
6057
4715
|
}
|
|
6058
4716
|
|
|
6059
4717
|
export { LocalSolanaMobileWalletAdapterWallet, RemoteSolanaMobileWalletAdapterWallet, SolanaMobileWalletAdapterRemoteWalletName, SolanaMobileWalletAdapterWalletName, createDefaultAuthorizationCache, createDefaultChainSelector, createDefaultWalletNotFoundHandler, defaultErrorModalWalletNotFoundHandler, registerMwa };
|
|
6060
|
-
//# sourceMappingURL=index.browser-
|
|
4718
|
+
//# sourceMappingURL=index.browser-CMijwVwX.esm.js.map
|