@pooflabs/web 0.0.84 → 0.0.85-rc2
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 +47 -20
- package/dist/{index-BM6hgCdH.js → index-B1_Q49qQ.js} +2 -2
- package/dist/{index-BM6hgCdH.js.map → index-B1_Q49qQ.js.map} +1 -1
- package/dist/{index-CH2G5Y9i.esm.js → index-B7tJ8TAn.esm.js} +2 -2
- package/dist/{index-CH2G5Y9i.esm.js.map → index-B7tJ8TAn.esm.js.map} +1 -1
- package/dist/{index-BPlF6-PQ.js → index-BeFR3-cf.js} +522 -289
- package/dist/{index-BPlF6-PQ.js.map → index-BeFR3-cf.js.map} +1 -1
- package/dist/index-DbJCCvVN.esm.js +6 -0
- package/dist/index-DbJCCvVN.esm.js.map +1 -0
- package/dist/{index-CSeN3jbG.js → index-DflG_JAB.js} +3 -3
- package/dist/{index-CSeN3jbG.js.map → index-DflG_JAB.js.map} +1 -1
- package/dist/{index-Bp4b5LXs.js → index-DyRIXw-l.js} +2 -2
- package/dist/index-DyRIXw-l.js.map +1 -0
- package/dist/{index-XHbmzFFO.esm.js → index-QukWgaIi.esm.js} +523 -290
- package/dist/{index-XHbmzFFO.esm.js.map → index-QukWgaIi.esm.js.map} +1 -1
- package/dist/{index-ep10Sw82.esm.js → index-agGmWBn4.esm.js} +3 -3
- package/dist/{index-ep10Sw82.esm.js.map → index-agGmWBn4.esm.js.map} +1 -1
- package/dist/{index.browser-C1QL04xM.js → index.browser-BJmFjY2f.js} +1006 -15
- package/dist/index.browser-BJmFjY2f.js.map +1 -0
- package/dist/index.browser-DZtZWdul.js +4994 -0
- package/dist/index.browser-DZtZWdul.js.map +1 -0
- package/dist/index.browser-lHP9glAW.esm.js +6060 -0
- package/dist/index.browser-lHP9glAW.esm.js.map +1 -0
- package/dist/{index.browser-Cgj7Hs6n.esm.js → index.browser-p-pgsxxW.esm.js} +836 -916
- package/dist/index.browser-p-pgsxxW.esm.js.map +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{index.native-BmtuyGXs.js → index.native-ANhb4jEB.js} +4 -4
- package/dist/{index.native-BmtuyGXs.js.map → index.native-ANhb4jEB.js.map} +1 -1
- package/dist/{index.native-X01vlukI.esm.js → index.native-a3mhu9HP.esm.js} +4 -4
- package/dist/{index.native-X01vlukI.esm.js.map → index.native-a3mhu9HP.esm.js.map} +1 -1
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +1 -1
- package/dist/{phantom-wallet-provider-C_LPU6Ns.js → phantom-wallet-provider-BOdn0D1Q.js} +4 -4
- package/dist/{phantom-wallet-provider-C_LPU6Ns.js.map → phantom-wallet-provider-BOdn0D1Q.js.map} +1 -1
- package/dist/{phantom-wallet-provider-DRvhBbbR.esm.js → phantom-wallet-provider-Dsza6TBv.esm.js} +4 -4
- package/dist/{phantom-wallet-provider-DRvhBbbR.esm.js.map → phantom-wallet-provider-Dsza6TBv.esm.js.map} +1 -1
- package/dist/{privy-wallet-provider-DQM8xO38.js → privy-wallet-provider-BlPh3Gn_.js} +3 -3
- package/dist/{privy-wallet-provider-DQM8xO38.js.map → privy-wallet-provider-BlPh3Gn_.js.map} +1 -1
- package/dist/{privy-wallet-provider-ZGu8q5T5.esm.js → privy-wallet-provider-bwwhkFjL.esm.js} +3 -3
- package/dist/{privy-wallet-provider-ZGu8q5T5.esm.js.map → privy-wallet-provider-bwwhkFjL.esm.js.map} +1 -1
- package/dist/solana-mobile-wallet-provider-S8yWHG6i.js +841 -0
- package/dist/solana-mobile-wallet-provider-S8yWHG6i.js.map +1 -0
- package/dist/solana-mobile-wallet-provider-fzLIgJBf.esm.js +820 -0
- package/dist/solana-mobile-wallet-provider-fzLIgJBf.esm.js.map +1 -0
- package/package.json +2 -1
- package/dist/index-Bp4b5LXs.js.map +0 -1
- package/dist/index-C80kRxWk.esm.js +0 -6
- package/dist/index-C80kRxWk.esm.js.map +0 -1
- package/dist/index.browser-BvNsUWjt.js +0 -105
- package/dist/index.browser-BvNsUWjt.js.map +0 -1
- package/dist/index.browser-BwIqqM4U.js +0 -1099
- package/dist/index.browser-BwIqqM4U.js.map +0 -1
- package/dist/index.browser-C1QL04xM.js.map +0 -1
- package/dist/index.browser-Cgj7Hs6n.esm.js.map +0 -1
- package/dist/index.browser-CifFI7Ju.esm.js +0 -1096
- package/dist/index.browser-CifFI7Ju.esm.js.map +0 -1
- package/dist/index.browser-D8VWPXTZ.esm.js +0 -102
- package/dist/index.browser-D8VWPXTZ.esm.js.map +0 -1
- package/dist/index.browser-OvGNsMPu.esm.js +0 -1002
- package/dist/index.browser-OvGNsMPu.esm.js.map +0 -1
- package/dist/index.browser-vuTr40so.js +0 -1008
- package/dist/index.browser-vuTr40so.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-6gNw2_bX.js +0 -608
- package/dist/solana-mobile-wallet-provider-6gNw2_bX.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-B65A7abd.esm.js +0 -587
- package/dist/solana-mobile-wallet-provider-B65A7abd.esm.js.map +0 -1
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as getDefaultExportFromCjs, a as base58 } from './index-XHbmzFFO.esm.js';
|
|
1
|
+
import { d as base58 } from './index.native-a3mhu9HP.esm.js';
|
|
3
2
|
import 'axios';
|
|
4
3
|
import '@solana/web3.js';
|
|
5
4
|
import '@coral-xyz/anchor';
|
|
6
5
|
import 'react';
|
|
7
6
|
|
|
8
|
-
/** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */
|
|
9
|
-
const SOLANA_MAINNET_CHAIN = 'solana:mainnet';
|
|
10
|
-
|
|
11
7
|
/** Name of the feature. */
|
|
12
8
|
const SolanaSignAndSendTransaction = 'solana:signAndSendTransaction';
|
|
13
9
|
|
|
@@ -20,6 +16,779 @@ const SolanaSignMessage = 'solana:signMessage';
|
|
|
20
16
|
/** Name of the feature. */
|
|
21
17
|
const SolanaSignTransaction = 'solana:signTransaction';
|
|
22
18
|
|
|
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
|
+
return base64;
|
|
168
|
+
}
|
|
169
|
+
function toUint8Array$1(base64EncodedByteArray) {
|
|
170
|
+
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/createHelloReq.ts
|
|
174
|
+
async function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
|
|
175
|
+
const publicKeyBuffer = await crypto.subtle.exportKey("raw", ecdhPublicKey);
|
|
176
|
+
const signatureBuffer = await crypto.subtle.sign({
|
|
177
|
+
hash: "SHA-256",
|
|
178
|
+
name: "ECDSA"
|
|
179
|
+
}, associationKeypairPrivateKey, publicKeyBuffer);
|
|
180
|
+
const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
|
|
181
|
+
response.set(new Uint8Array(publicKeyBuffer), 0);
|
|
182
|
+
response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
|
|
183
|
+
return response;
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/base58Utils.ts
|
|
187
|
+
function fromUint8Array$2(byteArray) {
|
|
188
|
+
return getBase58Decoder().decode(byteArray);
|
|
189
|
+
}
|
|
190
|
+
function base64ToBase58(base64EncodedString) {
|
|
191
|
+
return fromUint8Array$2(toUint8Array$1(base64EncodedString));
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/createSIWSMessage.ts
|
|
195
|
+
function createSIWSMessage(payload) {
|
|
196
|
+
return createSignInMessageText(payload);
|
|
197
|
+
}
|
|
198
|
+
function createSIWSMessageBase64Url(payload) {
|
|
199
|
+
return encode(createSIWSMessage(payload)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/types.ts
|
|
203
|
+
const SolanaSignTransactions = "solana:signTransactions";
|
|
204
|
+
const SolanaCloneAuthorization = "solana:cloneAuthorization";
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/createMobileWalletProxy.ts
|
|
207
|
+
/**
|
|
208
|
+
* Creates a {@link MobileWallet} proxy that handles backwards compatibility and API to RPC conversion.
|
|
209
|
+
*
|
|
210
|
+
* @param protocolVersion the protocol version in use for this session/request
|
|
211
|
+
* @param protocolRequestHandler callback function that handles sending the RPC request to the wallet endpoint.
|
|
212
|
+
* @returns a {@link MobileWallet} proxy
|
|
213
|
+
*/
|
|
214
|
+
function createMobileWalletProxy(protocolVersion, protocolRequestHandler) {
|
|
215
|
+
return new Proxy({}, {
|
|
216
|
+
get(target, p) {
|
|
217
|
+
if (p === "then") return null;
|
|
218
|
+
if (target[p] == null) target[p] = async function(inputParams) {
|
|
219
|
+
const { method, params } = handleMobileWalletRequest(p, inputParams, protocolVersion);
|
|
220
|
+
const result = await protocolRequestHandler(method, params);
|
|
221
|
+
if (method === "authorize" && params.sign_in_payload && !result.sign_in_result) result.sign_in_result = await signInFallback(params.sign_in_payload, result, protocolRequestHandler);
|
|
222
|
+
return handleMobileWalletResponse(p, result, protocolVersion);
|
|
223
|
+
};
|
|
224
|
+
return target[p];
|
|
225
|
+
},
|
|
226
|
+
defineProperty() {
|
|
227
|
+
return false;
|
|
228
|
+
},
|
|
229
|
+
deleteProperty() {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Handles all {@link MobileWallet} API requests and determines the correct MWA RPC method and params to call.
|
|
236
|
+
* This handles backwards compatibility, based on the provided @protocolVersion.
|
|
237
|
+
*
|
|
238
|
+
* @param methodName the name of {@link MobileWallet} method that was called
|
|
239
|
+
* @param methodParams the parameters that were passed to the method
|
|
240
|
+
* @param protocolVersion the protocol version in use for this session/request
|
|
241
|
+
* @returns the RPC request method and params that should be sent to the wallet endpoint
|
|
242
|
+
*/
|
|
243
|
+
function handleMobileWalletRequest(methodName, methodParams, protocolVersion) {
|
|
244
|
+
let params = methodParams;
|
|
245
|
+
let method = methodName.toString().replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`).toLowerCase();
|
|
246
|
+
switch (methodName) {
|
|
247
|
+
case "authorize": {
|
|
248
|
+
const authorizeParams = params;
|
|
249
|
+
let { chain } = authorizeParams;
|
|
250
|
+
if (protocolVersion === "legacy") {
|
|
251
|
+
switch (chain) {
|
|
252
|
+
case "solana:testnet":
|
|
253
|
+
chain = "testnet";
|
|
254
|
+
break;
|
|
255
|
+
case "solana:devnet":
|
|
256
|
+
chain = "devnet";
|
|
257
|
+
break;
|
|
258
|
+
case "solana:mainnet":
|
|
259
|
+
chain = "mainnet-beta";
|
|
260
|
+
break;
|
|
261
|
+
default: chain = authorizeParams.cluster;
|
|
262
|
+
}
|
|
263
|
+
authorizeParams.cluster = chain;
|
|
264
|
+
params = authorizeParams;
|
|
265
|
+
} else {
|
|
266
|
+
switch (chain) {
|
|
267
|
+
case "testnet":
|
|
268
|
+
case "devnet":
|
|
269
|
+
chain = `solana:${chain}`;
|
|
270
|
+
break;
|
|
271
|
+
case "mainnet-beta":
|
|
272
|
+
chain = "solana:mainnet";
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
authorizeParams.chain = chain;
|
|
276
|
+
params = authorizeParams;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
case "reauthorize": {
|
|
280
|
+
const { auth_token, identity } = params;
|
|
281
|
+
if (auth_token) switch (protocolVersion) {
|
|
282
|
+
case "legacy":
|
|
283
|
+
method = "reauthorize";
|
|
284
|
+
params = {
|
|
285
|
+
auth_token,
|
|
286
|
+
identity
|
|
287
|
+
};
|
|
288
|
+
break;
|
|
289
|
+
default:
|
|
290
|
+
method = "authorize";
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
method,
|
|
298
|
+
params
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Handles all {@link MobileWallet} API responses and modifies the response for backwards compatibility, if needed
|
|
303
|
+
*
|
|
304
|
+
* @param method the {@link MobileWallet} method that was called
|
|
305
|
+
* @param response the original response that was returned by the method call
|
|
306
|
+
* @param protocolVersion the protocol version in use for this session/request
|
|
307
|
+
* @returns the possibly modified response
|
|
308
|
+
*/
|
|
309
|
+
function handleMobileWalletResponse(method, response, protocolVersion) {
|
|
310
|
+
switch (method) {
|
|
311
|
+
case "getCapabilities": {
|
|
312
|
+
const capabilities = response;
|
|
313
|
+
switch (protocolVersion) {
|
|
314
|
+
case "legacy": {
|
|
315
|
+
const features = [SolanaSignTransactions];
|
|
316
|
+
if (capabilities.supports_clone_authorization === true) features.push(SolanaCloneAuthorization);
|
|
317
|
+
return {
|
|
318
|
+
...capabilities,
|
|
319
|
+
features
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
case "v1": return {
|
|
323
|
+
...capabilities,
|
|
324
|
+
supports_sign_and_send_transactions: true,
|
|
325
|
+
supports_clone_authorization: capabilities.features.includes(SolanaCloneAuthorization)
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return response;
|
|
331
|
+
}
|
|
332
|
+
async function signInFallback(signInPayload, authorizationResult, protocolRequestHandler) {
|
|
333
|
+
const domain = signInPayload.domain ?? window.location.host;
|
|
334
|
+
const address = authorizationResult.accounts[0].address;
|
|
335
|
+
const siwsMessage = createSIWSMessageBase64Url({
|
|
336
|
+
...signInPayload,
|
|
337
|
+
domain,
|
|
338
|
+
address: base64ToBase58(address)
|
|
339
|
+
});
|
|
340
|
+
const signedPayload = toUint8Array$1((await protocolRequestHandler("sign_messages", {
|
|
341
|
+
addresses: [address],
|
|
342
|
+
payloads: [siwsMessage]
|
|
343
|
+
})).signed_payloads[0]);
|
|
344
|
+
const signedMessage = fromUint8Array$1(signedPayload.slice(0, signedPayload.length - 64));
|
|
345
|
+
const signature = fromUint8Array$1(signedPayload.slice(signedPayload.length - 64));
|
|
346
|
+
return {
|
|
347
|
+
address,
|
|
348
|
+
signed_message: signedMessage.length == 0 ? siwsMessage : signedMessage,
|
|
349
|
+
signature
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function createSequenceNumberVector(sequenceNumber) {
|
|
353
|
+
if (sequenceNumber >= 4294967296) throw new Error("Outbound sequence number overflow. The maximum sequence number is 32-bytes.");
|
|
354
|
+
const byteArray = /* @__PURE__ */ new ArrayBuffer(4);
|
|
355
|
+
new DataView(byteArray).setUint32(0, sequenceNumber, false);
|
|
356
|
+
return new Uint8Array(byteArray);
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/encryptedMessage.ts
|
|
360
|
+
const INITIALIZATION_VECTOR_BYTES = 12;
|
|
361
|
+
async function encryptMessage(plaintext, sequenceNumber, sharedSecret) {
|
|
362
|
+
const sequenceNumberVector = createSequenceNumberVector(sequenceNumber);
|
|
363
|
+
const initializationVector = new Uint8Array(INITIALIZATION_VECTOR_BYTES);
|
|
364
|
+
crypto.getRandomValues(initializationVector);
|
|
365
|
+
const ciphertext = await crypto.subtle.encrypt(getAlgorithmParams(sequenceNumberVector, initializationVector), sharedSecret, new TextEncoder().encode(plaintext));
|
|
366
|
+
const response = new Uint8Array(sequenceNumberVector.byteLength + initializationVector.byteLength + ciphertext.byteLength);
|
|
367
|
+
response.set(new Uint8Array(sequenceNumberVector), 0);
|
|
368
|
+
response.set(new Uint8Array(initializationVector), sequenceNumberVector.byteLength);
|
|
369
|
+
response.set(new Uint8Array(ciphertext), sequenceNumberVector.byteLength + initializationVector.byteLength);
|
|
370
|
+
return response;
|
|
371
|
+
}
|
|
372
|
+
async function decryptMessage(message, sharedSecret) {
|
|
373
|
+
const sequenceNumberVector = message.slice(0, 4);
|
|
374
|
+
const initializationVector = message.slice(4, 4 + INITIALIZATION_VECTOR_BYTES);
|
|
375
|
+
const ciphertext = message.slice(4 + INITIALIZATION_VECTOR_BYTES);
|
|
376
|
+
const plaintextBuffer = await crypto.subtle.decrypt(getAlgorithmParams(sequenceNumberVector, initializationVector), sharedSecret, ciphertext);
|
|
377
|
+
return getUtf8Decoder().decode(plaintextBuffer);
|
|
378
|
+
}
|
|
379
|
+
function getAlgorithmParams(sequenceNumber, initializationVector) {
|
|
380
|
+
return {
|
|
381
|
+
additionalData: sequenceNumber,
|
|
382
|
+
iv: initializationVector,
|
|
383
|
+
name: "AES-GCM",
|
|
384
|
+
tagLength: 128
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
let _utf8Decoder;
|
|
388
|
+
function getUtf8Decoder() {
|
|
389
|
+
if (_utf8Decoder === void 0) _utf8Decoder = new TextDecoder("utf-8");
|
|
390
|
+
return _utf8Decoder;
|
|
391
|
+
}
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/generateAssociationKeypair.ts
|
|
394
|
+
async function generateAssociationKeypair() {
|
|
395
|
+
return await crypto.subtle.generateKey({
|
|
396
|
+
name: "ECDSA",
|
|
397
|
+
namedCurve: "P-256"
|
|
398
|
+
}, false, ["sign"]);
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/generateECDHKeypair.ts
|
|
402
|
+
async function generateECDHKeypair() {
|
|
403
|
+
return await crypto.subtle.generateKey({
|
|
404
|
+
name: "ECDH",
|
|
405
|
+
namedCurve: "P-256"
|
|
406
|
+
}, false, ["deriveKey", "deriveBits"]);
|
|
407
|
+
}
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/arrayBufferToBase64String.ts
|
|
410
|
+
function arrayBufferToBase64String(buffer) {
|
|
411
|
+
let binary = "";
|
|
412
|
+
const bytes = new Uint8Array(buffer);
|
|
413
|
+
const len = bytes.byteLength;
|
|
414
|
+
for (let ii = 0; ii < len; ii++) binary += String.fromCharCode(bytes[ii]);
|
|
415
|
+
return window.btoa(binary);
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/associationPort.ts
|
|
419
|
+
function getRandomAssociationPort() {
|
|
420
|
+
return assertAssociationPort(49152 + Math.floor(Math.random() * 16384));
|
|
421
|
+
}
|
|
422
|
+
function assertAssociationPort(port) {
|
|
423
|
+
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 });
|
|
424
|
+
return port;
|
|
425
|
+
}
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region src/getStringWithURLUnsafeBase64CharactersReplaced.ts
|
|
428
|
+
function getStringWithURLUnsafeCharactersReplaced(unsafeBase64EncodedString) {
|
|
429
|
+
return unsafeBase64EncodedString.replace(/[/+=]/g, (m) => ({
|
|
430
|
+
"/": "_",
|
|
431
|
+
"+": "-",
|
|
432
|
+
"=": "."
|
|
433
|
+
})[m]);
|
|
434
|
+
}
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/getAssociateAndroidIntentURL.ts
|
|
437
|
+
const INTENT_NAME = "solana-wallet";
|
|
438
|
+
function getPathParts(pathString) {
|
|
439
|
+
return pathString.replace(/(^\/+|\/+$)/g, "").split("/");
|
|
440
|
+
}
|
|
441
|
+
function getIntentURL(methodPathname, intentUrlBase) {
|
|
442
|
+
let baseUrl = null;
|
|
443
|
+
if (intentUrlBase) {
|
|
444
|
+
try {
|
|
445
|
+
baseUrl = new URL(intentUrlBase);
|
|
446
|
+
} catch {}
|
|
447
|
+
if (baseUrl?.protocol !== "https:") throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL, "Base URLs supplied by wallets must be valid `https` URLs");
|
|
448
|
+
}
|
|
449
|
+
baseUrl ||= new URL(`${INTENT_NAME}:/`);
|
|
450
|
+
const pathname = methodPathname.startsWith("/") ? methodPathname : [...getPathParts(baseUrl.pathname), ...getPathParts(methodPathname)].join("/");
|
|
451
|
+
return new URL(pathname, baseUrl);
|
|
452
|
+
}
|
|
453
|
+
async function getAssociateAndroidIntentURL(associationPublicKey, putativePort, associationURLBase, protocolVersions = ["v1"]) {
|
|
454
|
+
const associationPort = assertAssociationPort(putativePort);
|
|
455
|
+
const encodedKey = arrayBufferToBase64String(await crypto.subtle.exportKey("raw", associationPublicKey));
|
|
456
|
+
const url = getIntentURL("v1/associate/local", associationURLBase);
|
|
457
|
+
url.searchParams.set("association", getStringWithURLUnsafeCharactersReplaced(encodedKey));
|
|
458
|
+
url.searchParams.set("port", `${associationPort}`);
|
|
459
|
+
protocolVersions.forEach((version) => {
|
|
460
|
+
url.searchParams.set("v", version);
|
|
461
|
+
});
|
|
462
|
+
return url;
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/jsonRpcMessage.ts
|
|
466
|
+
async function encryptJsonRpcMessage(jsonRpcMessage, sharedSecret) {
|
|
467
|
+
const plaintext = JSON.stringify(jsonRpcMessage);
|
|
468
|
+
const sequenceNumber = jsonRpcMessage.id;
|
|
469
|
+
return encryptMessage(plaintext, sequenceNumber, sharedSecret);
|
|
470
|
+
}
|
|
471
|
+
async function decryptJsonRpcMessage(message, sharedSecret) {
|
|
472
|
+
const plaintext = await decryptMessage(message, sharedSecret);
|
|
473
|
+
const jsonRpcMessage = JSON.parse(plaintext);
|
|
474
|
+
if (Object.hasOwnProperty.call(jsonRpcMessage, "error")) throw new SolanaMobileWalletAdapterProtocolError(jsonRpcMessage.id, jsonRpcMessage.error.code, jsonRpcMessage.error.message);
|
|
475
|
+
return jsonRpcMessage;
|
|
476
|
+
}
|
|
477
|
+
//#endregion
|
|
478
|
+
//#region src/parseHelloRsp.ts
|
|
479
|
+
async function parseHelloRsp(payloadBuffer, associationPublicKey, ecdhPrivateKey) {
|
|
480
|
+
const [associationPublicKeyBuffer, walletPublicKey] = await Promise.all([crypto.subtle.exportKey("raw", associationPublicKey), crypto.subtle.importKey("raw", payloadBuffer.slice(0, 65), {
|
|
481
|
+
name: "ECDH",
|
|
482
|
+
namedCurve: "P-256"
|
|
483
|
+
}, false, [])]);
|
|
484
|
+
const sharedSecret = await crypto.subtle.deriveBits({
|
|
485
|
+
name: "ECDH",
|
|
486
|
+
public: walletPublicKey
|
|
487
|
+
}, ecdhPrivateKey, 256);
|
|
488
|
+
const ecdhSecretKey = await crypto.subtle.importKey("raw", sharedSecret, "HKDF", false, ["deriveKey"]);
|
|
489
|
+
return await crypto.subtle.deriveKey({
|
|
490
|
+
name: "HKDF",
|
|
491
|
+
hash: "SHA-256",
|
|
492
|
+
salt: new Uint8Array(associationPublicKeyBuffer),
|
|
493
|
+
info: new Uint8Array()
|
|
494
|
+
}, ecdhSecretKey, {
|
|
495
|
+
name: "AES-GCM",
|
|
496
|
+
length: 128
|
|
497
|
+
}, false, ["encrypt", "decrypt"]);
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/parseSessionProps.ts
|
|
501
|
+
async function parseSessionProps(message, sharedSecret) {
|
|
502
|
+
const plaintext = await decryptMessage(message, sharedSecret);
|
|
503
|
+
const jsonProperties = JSON.parse(plaintext);
|
|
504
|
+
let protocolVersion = "legacy";
|
|
505
|
+
if (Object.hasOwnProperty.call(jsonProperties, "v")) switch (jsonProperties.v) {
|
|
506
|
+
case 1:
|
|
507
|
+
case "1":
|
|
508
|
+
case "v1":
|
|
509
|
+
protocolVersion = "v1";
|
|
510
|
+
break;
|
|
511
|
+
case "legacy":
|
|
512
|
+
protocolVersion = "legacy";
|
|
513
|
+
break;
|
|
514
|
+
default: throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_INVALID_PROTOCOL_VERSION, `Unknown/unsupported protocol version: ${jsonProperties.v}`);
|
|
515
|
+
}
|
|
516
|
+
return { protocol_version: protocolVersion };
|
|
517
|
+
}
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/startSession.ts
|
|
520
|
+
const Browser = {
|
|
521
|
+
Firefox: 0,
|
|
522
|
+
Other: 1
|
|
523
|
+
};
|
|
524
|
+
function assertUnreachable(x) {
|
|
525
|
+
return x;
|
|
526
|
+
}
|
|
527
|
+
function getBrowser() {
|
|
528
|
+
return navigator.userAgent.indexOf("Firefox/") !== -1 ? Browser.Firefox : Browser.Other;
|
|
529
|
+
}
|
|
530
|
+
function getDetectionPromise() {
|
|
531
|
+
return new Promise((resolve, reject) => {
|
|
532
|
+
function cleanup() {
|
|
533
|
+
clearTimeout(timeoutId);
|
|
534
|
+
window.removeEventListener("blur", handleBlur);
|
|
535
|
+
}
|
|
536
|
+
function handleBlur() {
|
|
537
|
+
cleanup();
|
|
538
|
+
resolve();
|
|
539
|
+
}
|
|
540
|
+
window.addEventListener("blur", handleBlur);
|
|
541
|
+
const timeoutId = setTimeout(() => {
|
|
542
|
+
cleanup();
|
|
543
|
+
reject();
|
|
544
|
+
}, 3e3);
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
let _frame = null;
|
|
548
|
+
function launchUrlThroughHiddenFrame(url) {
|
|
549
|
+
if (_frame == null) {
|
|
550
|
+
_frame = document.createElement("iframe");
|
|
551
|
+
_frame.style.display = "none";
|
|
552
|
+
document.body.appendChild(_frame);
|
|
553
|
+
}
|
|
554
|
+
_frame.contentWindow.location.href = url.toString();
|
|
555
|
+
}
|
|
556
|
+
async function launchAssociation(associationUrl) {
|
|
557
|
+
if (associationUrl.protocol === "https:") window.location.assign(associationUrl);
|
|
558
|
+
else try {
|
|
559
|
+
const browser = getBrowser();
|
|
560
|
+
switch (browser) {
|
|
561
|
+
case Browser.Firefox:
|
|
562
|
+
launchUrlThroughHiddenFrame(associationUrl);
|
|
563
|
+
break;
|
|
564
|
+
case Browser.Other: {
|
|
565
|
+
const detectionPromise = getDetectionPromise();
|
|
566
|
+
window.location.assign(associationUrl);
|
|
567
|
+
await detectionPromise;
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
default: assertUnreachable(browser);
|
|
571
|
+
}
|
|
572
|
+
} catch {
|
|
573
|
+
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND, "Found no installed wallet that supports the mobile wallet protocol.");
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
async function startSession(associationPublicKey, associationURLBase) {
|
|
577
|
+
const randomAssociationPort = getRandomAssociationPort();
|
|
578
|
+
await launchAssociation(await getAssociateAndroidIntentURL(associationPublicKey, randomAssociationPort, associationURLBase));
|
|
579
|
+
return randomAssociationPort;
|
|
580
|
+
}
|
|
581
|
+
//#endregion
|
|
582
|
+
//#region src/transact.ts
|
|
583
|
+
const WEBSOCKET_CONNECTION_CONFIG = {
|
|
584
|
+
retryDelayScheduleMs: [
|
|
585
|
+
150,
|
|
586
|
+
150,
|
|
587
|
+
200,
|
|
588
|
+
500,
|
|
589
|
+
500,
|
|
590
|
+
750,
|
|
591
|
+
750,
|
|
592
|
+
1e3
|
|
593
|
+
],
|
|
594
|
+
timeoutMs: 3e4
|
|
595
|
+
};
|
|
596
|
+
const WEBSOCKET_PROTOCOL_BINARY = "com.solana.mobilewalletadapter.v1";
|
|
597
|
+
function assertSecureContext() {
|
|
598
|
+
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`).");
|
|
599
|
+
}
|
|
600
|
+
function assertSecureEndpointSpecificURI(walletUriBase) {
|
|
601
|
+
let url;
|
|
602
|
+
try {
|
|
603
|
+
url = new URL(walletUriBase);
|
|
604
|
+
} catch {
|
|
605
|
+
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL, "Invalid base URL supplied by wallet");
|
|
606
|
+
}
|
|
607
|
+
if (url.protocol !== "https:") throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_FORBIDDEN_WALLET_BASE_URL, "Base URLs supplied by wallets must be valid `https` URLs");
|
|
608
|
+
}
|
|
609
|
+
function getSequenceNumberFromByteArray(byteArray) {
|
|
610
|
+
return new DataView(byteArray).getUint32(0, false);
|
|
611
|
+
}
|
|
612
|
+
async function startScenario(config) {
|
|
613
|
+
assertSecureContext();
|
|
614
|
+
const associationKeypair = await generateAssociationKeypair();
|
|
615
|
+
const websocketURL = `ws://localhost:${await startSession(associationKeypair.publicKey, config?.baseUri)}/solana-wallet`;
|
|
616
|
+
let connectionStartTime;
|
|
617
|
+
const getNextRetryDelayMs = (() => {
|
|
618
|
+
const schedule = [...WEBSOCKET_CONNECTION_CONFIG.retryDelayScheduleMs];
|
|
619
|
+
return () => schedule.length > 1 ? schedule.shift() : schedule[0];
|
|
620
|
+
})();
|
|
621
|
+
let nextJsonRpcMessageId = 1;
|
|
622
|
+
let lastKnownInboundSequenceNumber = 0;
|
|
623
|
+
let state = { __type: "disconnected" };
|
|
624
|
+
let socket;
|
|
625
|
+
let sessionEstablished = false;
|
|
626
|
+
let handleForceClose;
|
|
627
|
+
return {
|
|
628
|
+
close: () => {
|
|
629
|
+
socket.close();
|
|
630
|
+
handleForceClose();
|
|
631
|
+
},
|
|
632
|
+
wallet: new Promise((resolve, reject) => {
|
|
633
|
+
const jsonRpcResponsePromises = {};
|
|
634
|
+
const handleOpen = async () => {
|
|
635
|
+
if (state.__type !== "connecting") {
|
|
636
|
+
console.warn(`Expected adapter state to be \`connecting\` at the moment the websocket opens. Got \`${state.__type}\`.`);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
socket.removeEventListener("open", handleOpen);
|
|
640
|
+
const { associationKeypair } = state;
|
|
641
|
+
const ecdhKeypair = await generateECDHKeypair();
|
|
642
|
+
socket.send(await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey));
|
|
643
|
+
state = {
|
|
644
|
+
__type: "hello_req_sent",
|
|
645
|
+
associationPublicKey: associationKeypair.publicKey,
|
|
646
|
+
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
647
|
+
};
|
|
648
|
+
};
|
|
649
|
+
const handleClose = (evt) => {
|
|
650
|
+
if (evt.wasClean) state = { __type: "disconnected" };
|
|
651
|
+
else reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED, `The wallet session dropped unexpectedly (${evt.code}: ${evt.reason}).`, { closeEvent: evt }));
|
|
652
|
+
disposeSocket();
|
|
653
|
+
};
|
|
654
|
+
const handleError = async (_evt) => {
|
|
655
|
+
disposeSocket();
|
|
656
|
+
if (Date.now() - connectionStartTime >= WEBSOCKET_CONNECTION_CONFIG.timeoutMs) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_TIMEOUT, `Failed to connect to the wallet websocket at ${websocketURL}.`));
|
|
657
|
+
else {
|
|
658
|
+
await new Promise((resolve) => {
|
|
659
|
+
const retryDelayMs = getNextRetryDelayMs();
|
|
660
|
+
retryWaitTimeoutId = window.setTimeout(resolve, retryDelayMs);
|
|
661
|
+
});
|
|
662
|
+
attemptSocketConnection();
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
const handleMessage = async (evt) => {
|
|
666
|
+
const responseBuffer = await evt.data.arrayBuffer();
|
|
667
|
+
switch (state.__type) {
|
|
668
|
+
case "connecting": {
|
|
669
|
+
if (responseBuffer.byteLength !== 0) throw new Error("Encountered unexpected message while connecting");
|
|
670
|
+
const ecdhKeypair = await generateECDHKeypair();
|
|
671
|
+
socket.send(await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey));
|
|
672
|
+
state = {
|
|
673
|
+
__type: "hello_req_sent",
|
|
674
|
+
associationPublicKey: associationKeypair.publicKey,
|
|
675
|
+
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
676
|
+
};
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
case "connected":
|
|
680
|
+
try {
|
|
681
|
+
const sequenceNumber = getSequenceNumberFromByteArray(responseBuffer.slice(0, 4));
|
|
682
|
+
if (sequenceNumber !== lastKnownInboundSequenceNumber + 1) throw new Error("Encrypted message has invalid sequence number");
|
|
683
|
+
lastKnownInboundSequenceNumber = sequenceNumber;
|
|
684
|
+
const jsonRpcMessage = await decryptJsonRpcMessage(responseBuffer, state.sharedSecret);
|
|
685
|
+
const responsePromise = jsonRpcResponsePromises[jsonRpcMessage.id];
|
|
686
|
+
delete jsonRpcResponsePromises[jsonRpcMessage.id];
|
|
687
|
+
responsePromise.resolve(jsonRpcMessage.result);
|
|
688
|
+
} catch (e) {
|
|
689
|
+
if (e instanceof SolanaMobileWalletAdapterProtocolError) {
|
|
690
|
+
const responsePromise = jsonRpcResponsePromises[e.jsonRpcMessageId];
|
|
691
|
+
delete jsonRpcResponsePromises[e.jsonRpcMessageId];
|
|
692
|
+
responsePromise.reject(e);
|
|
693
|
+
} else throw e;
|
|
694
|
+
}
|
|
695
|
+
break;
|
|
696
|
+
case "hello_req_sent": {
|
|
697
|
+
if (responseBuffer.byteLength === 0) {
|
|
698
|
+
const ecdhKeypair = await generateECDHKeypair();
|
|
699
|
+
socket.send(await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey));
|
|
700
|
+
state = {
|
|
701
|
+
__type: "hello_req_sent",
|
|
702
|
+
associationPublicKey: associationKeypair.publicKey,
|
|
703
|
+
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
704
|
+
};
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
const sharedSecret = await parseHelloRsp(responseBuffer, state.associationPublicKey, state.ecdhPrivateKey);
|
|
708
|
+
const sessionPropertiesBuffer = responseBuffer.slice(65);
|
|
709
|
+
const sessionProperties = sessionPropertiesBuffer.byteLength !== 0 ? await (async () => {
|
|
710
|
+
const sequenceNumber = getSequenceNumberFromByteArray(sessionPropertiesBuffer.slice(0, 4));
|
|
711
|
+
if (sequenceNumber !== lastKnownInboundSequenceNumber + 1) throw new Error("Encrypted message has invalid sequence number");
|
|
712
|
+
lastKnownInboundSequenceNumber = sequenceNumber;
|
|
713
|
+
return parseSessionProps(sessionPropertiesBuffer, sharedSecret);
|
|
714
|
+
})() : { protocol_version: "legacy" };
|
|
715
|
+
state = {
|
|
716
|
+
__type: "connected",
|
|
717
|
+
sharedSecret,
|
|
718
|
+
sessionProperties
|
|
719
|
+
};
|
|
720
|
+
const wallet = createMobileWalletProxy(sessionProperties.protocol_version, async (method, params) => {
|
|
721
|
+
const id = nextJsonRpcMessageId++;
|
|
722
|
+
socket.send(await encryptJsonRpcMessage({
|
|
723
|
+
id,
|
|
724
|
+
jsonrpc: "2.0",
|
|
725
|
+
method,
|
|
726
|
+
params: params ?? {}
|
|
727
|
+
}, sharedSecret));
|
|
728
|
+
return new Promise((resolve, reject) => {
|
|
729
|
+
jsonRpcResponsePromises[id] = {
|
|
730
|
+
resolve(result) {
|
|
731
|
+
switch (method) {
|
|
732
|
+
case "authorize":
|
|
733
|
+
case "reauthorize": {
|
|
734
|
+
const { wallet_uri_base } = result;
|
|
735
|
+
if (wallet_uri_base != null) try {
|
|
736
|
+
assertSecureEndpointSpecificURI(wallet_uri_base);
|
|
737
|
+
} catch (e) {
|
|
738
|
+
reject(e);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
resolve(result);
|
|
745
|
+
},
|
|
746
|
+
reject
|
|
747
|
+
};
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
sessionEstablished = true;
|
|
751
|
+
try {
|
|
752
|
+
resolve(wallet);
|
|
753
|
+
} catch (e) {
|
|
754
|
+
reject(e);
|
|
755
|
+
}
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
handleForceClose = () => {
|
|
761
|
+
socket.removeEventListener("message", handleMessage);
|
|
762
|
+
disposeSocket();
|
|
763
|
+
if (!sessionEstablished) reject(new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_CLOSED, `The wallet session was closed before connection.`, { closeEvent: new CloseEvent("socket was closed before connection") }));
|
|
764
|
+
};
|
|
765
|
+
let disposeSocket;
|
|
766
|
+
let retryWaitTimeoutId;
|
|
767
|
+
const attemptSocketConnection = () => {
|
|
768
|
+
if (disposeSocket) disposeSocket();
|
|
769
|
+
state = {
|
|
770
|
+
__type: "connecting",
|
|
771
|
+
associationKeypair
|
|
772
|
+
};
|
|
773
|
+
if (connectionStartTime === void 0) connectionStartTime = Date.now();
|
|
774
|
+
socket = new WebSocket(websocketURL, [WEBSOCKET_PROTOCOL_BINARY]);
|
|
775
|
+
socket.addEventListener("open", handleOpen);
|
|
776
|
+
socket.addEventListener("close", handleClose);
|
|
777
|
+
socket.addEventListener("error", handleError);
|
|
778
|
+
socket.addEventListener("message", handleMessage);
|
|
779
|
+
disposeSocket = () => {
|
|
780
|
+
window.clearTimeout(retryWaitTimeoutId);
|
|
781
|
+
socket.removeEventListener("open", handleOpen);
|
|
782
|
+
socket.removeEventListener("close", handleClose);
|
|
783
|
+
socket.removeEventListener("error", handleError);
|
|
784
|
+
socket.removeEventListener("message", handleMessage);
|
|
785
|
+
};
|
|
786
|
+
};
|
|
787
|
+
attemptSocketConnection();
|
|
788
|
+
})
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
|
|
23
792
|
/** Name of the feature. */
|
|
24
793
|
const StandardConnect = 'standard:connect';
|
|
25
794
|
|
|
@@ -3098,82 +3867,7 @@ function requireBrowser () {
|
|
|
3098
3867
|
return browser;
|
|
3099
3868
|
}
|
|
3100
3869
|
|
|
3101
|
-
|
|
3102
|
-
var QRCode = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
3103
|
-
|
|
3104
|
-
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3105
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3106
|
-
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");
|
|
3107
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
3108
|
-
};
|
|
3109
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3110
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3111
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
3112
|
-
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");
|
|
3113
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
3114
|
-
};
|
|
3115
|
-
var _RegisterWalletEvent_detail;
|
|
3116
|
-
/**
|
|
3117
|
-
* Register a {@link "@wallet-standard/base".Wallet} as a Standard Wallet with the app.
|
|
3118
|
-
*
|
|
3119
|
-
* This dispatches a {@link "@wallet-standard/base".WindowRegisterWalletEvent} to notify the app that the Wallet is
|
|
3120
|
-
* ready to be registered.
|
|
3121
|
-
*
|
|
3122
|
-
* This also adds a listener for {@link "@wallet-standard/base".WindowAppReadyEvent} to listen for a notification from
|
|
3123
|
-
* the app that the app is ready to register the Wallet.
|
|
3124
|
-
*
|
|
3125
|
-
* This combination of event dispatch and listener guarantees that the Wallet will be registered synchronously as soon
|
|
3126
|
-
* as the app is ready whether the Wallet loads before or after the app.
|
|
3127
|
-
*
|
|
3128
|
-
* @param wallet Wallet to register.
|
|
3129
|
-
*
|
|
3130
|
-
* @group Wallet
|
|
3131
|
-
*/
|
|
3132
|
-
function registerWallet(wallet) {
|
|
3133
|
-
const callback = ({ register }) => register(wallet);
|
|
3134
|
-
try {
|
|
3135
|
-
window.dispatchEvent(new RegisterWalletEvent(callback));
|
|
3136
|
-
}
|
|
3137
|
-
catch (error) {
|
|
3138
|
-
console.error('wallet-standard:register-wallet event could not be dispatched\n', error);
|
|
3139
|
-
}
|
|
3140
|
-
try {
|
|
3141
|
-
window.addEventListener('wallet-standard:app-ready', ({ detail: api }) => callback(api));
|
|
3142
|
-
}
|
|
3143
|
-
catch (error) {
|
|
3144
|
-
console.error('wallet-standard:app-ready event listener could not be added\n', error);
|
|
3145
|
-
}
|
|
3146
|
-
}
|
|
3147
|
-
class RegisterWalletEvent extends Event {
|
|
3148
|
-
get detail() {
|
|
3149
|
-
return __classPrivateFieldGet(this, _RegisterWalletEvent_detail, "f");
|
|
3150
|
-
}
|
|
3151
|
-
get type() {
|
|
3152
|
-
return 'wallet-standard:register-wallet';
|
|
3153
|
-
}
|
|
3154
|
-
constructor(callback) {
|
|
3155
|
-
super('wallet-standard:register-wallet', {
|
|
3156
|
-
bubbles: false,
|
|
3157
|
-
cancelable: false,
|
|
3158
|
-
composed: false,
|
|
3159
|
-
});
|
|
3160
|
-
_RegisterWalletEvent_detail.set(this, void 0);
|
|
3161
|
-
__classPrivateFieldSet(this, _RegisterWalletEvent_detail, callback, "f");
|
|
3162
|
-
}
|
|
3163
|
-
/** @deprecated */
|
|
3164
|
-
preventDefault() {
|
|
3165
|
-
throw new Error('preventDefault cannot be called');
|
|
3166
|
-
}
|
|
3167
|
-
/** @deprecated */
|
|
3168
|
-
stopImmediatePropagation() {
|
|
3169
|
-
throw new Error('stopImmediatePropagation cannot be called');
|
|
3170
|
-
}
|
|
3171
|
-
/** @deprecated */
|
|
3172
|
-
stopPropagation() {
|
|
3173
|
-
throw new Error('stopPropagation cannot be called');
|
|
3174
|
-
}
|
|
3175
|
-
}
|
|
3176
|
-
_RegisterWalletEvent_detail = new WeakMap();
|
|
3870
|
+
requireBrowser();
|
|
3177
3871
|
|
|
3178
3872
|
//#region src/base64Utils.ts
|
|
3179
3873
|
function fromUint8Array(byteArray) {
|
|
@@ -3483,361 +4177,79 @@ var EmbeddedModal = class {
|
|
|
3483
4177
|
};
|
|
3484
4178
|
};
|
|
3485
4179
|
//#endregion
|
|
3486
|
-
//#region src/embedded-modal/
|
|
3487
|
-
var
|
|
3488
|
-
contentStyles = css$
|
|
3489
|
-
contentHtml =
|
|
3490
|
-
|
|
4180
|
+
//#region src/embedded-modal/localConnectionModal.ts
|
|
4181
|
+
var LocalConnectionModal = class extends EmbeddedModal {
|
|
4182
|
+
contentStyles = css$3;
|
|
4183
|
+
contentHtml = ErrorDialogHtml$3;
|
|
4184
|
+
initWithCallback(callback) {
|
|
3491
4185
|
super.init();
|
|
3492
|
-
this
|
|
4186
|
+
this.#prepareLaunchAction(callback);
|
|
3493
4187
|
}
|
|
3494
|
-
|
|
3495
|
-
const
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
else qrcodeContainer.appendChild(qrCodeElement);
|
|
3503
|
-
const qrPlaceholder = this.dom?.getElementById("mobile-wallet-adapter-embedded-modal-qr-placeholder");
|
|
3504
|
-
if (qrPlaceholder) qrPlaceholder.style.display = "none";
|
|
3505
|
-
} else console.error("QRCode Container not found");
|
|
4188
|
+
#prepareLaunchAction(callback) {
|
|
4189
|
+
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
4190
|
+
const listener = async () => {
|
|
4191
|
+
launchButton?.removeEventListener("click", listener);
|
|
4192
|
+
this.close();
|
|
4193
|
+
callback();
|
|
4194
|
+
};
|
|
4195
|
+
launchButton?.addEventListener("click", listener);
|
|
3506
4196
|
}
|
|
3507
4197
|
};
|
|
3508
|
-
const
|
|
3509
|
-
<
|
|
3510
|
-
<
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
<
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
<
|
|
3519
|
-
<
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
</
|
|
3528
|
-
<div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
|
|
3529
|
-
<div class="mobile-wallet-adapter-embedded-modal-footer">
|
|
3530
|
-
<div class="mobile-wallet-adapter-embedded-modal-subtitle">
|
|
3531
|
-
Follow the instructions on your device. When you're finished, this screen will update.
|
|
3532
|
-
</div>
|
|
3533
|
-
<div class="mobile-wallet-adapter-embedded-modal-progress-badge">
|
|
3534
|
-
<div>
|
|
3535
|
-
<div class="spinner">
|
|
3536
|
-
<div class="leftWrapper">
|
|
3537
|
-
<div class="left">
|
|
3538
|
-
<div class="circle"></div>
|
|
3539
|
-
</div>
|
|
3540
|
-
</div>
|
|
3541
|
-
<div class="rightWrapper">
|
|
3542
|
-
<div class="right">
|
|
3543
|
-
<div class="circle"></div>
|
|
3544
|
-
</div>
|
|
3545
|
-
</div>
|
|
3546
|
-
</div>
|
|
3547
|
-
</div>
|
|
3548
|
-
<div>Waiting for scan</div>
|
|
3549
|
-
</div>
|
|
4198
|
+
const ErrorDialogHtml$3 = `
|
|
4199
|
+
<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">
|
|
4200
|
+
<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"/>
|
|
4201
|
+
<mask id="mask0_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
4202
|
+
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
4203
|
+
</mask>
|
|
4204
|
+
<g mask="url(#mask0_189_522)">
|
|
4205
|
+
<mask id="mask1_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
4206
|
+
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
4207
|
+
</mask>
|
|
4208
|
+
<g mask="url(#mask1_189_522)">
|
|
4209
|
+
<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"/>
|
|
4210
|
+
</g>
|
|
4211
|
+
</g>
|
|
4212
|
+
</svg>
|
|
4213
|
+
<div class="mobile-wallet-adapter-embedded-modal-title">Ready to connect!</div>
|
|
4214
|
+
<div>
|
|
4215
|
+
<button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
|
|
4216
|
+
Connect Wallet
|
|
4217
|
+
</button>
|
|
3550
4218
|
</div>
|
|
3551
4219
|
`;
|
|
3552
|
-
const css$
|
|
3553
|
-
.mobile-wallet-adapter-embedded-modal-
|
|
3554
|
-
display:
|
|
3555
|
-
margin-top: 10px;
|
|
3556
|
-
padding: 10px;
|
|
3557
|
-
}
|
|
3558
|
-
|
|
3559
|
-
.mobile-wallet-adapter-embedded-modal-qr-content > div:first-child {
|
|
3560
|
-
display: flex;
|
|
3561
|
-
flex-direction: column;
|
|
3562
|
-
flex: 2;
|
|
3563
|
-
margin-top: auto;
|
|
3564
|
-
margin-right: 30px;
|
|
4220
|
+
const css$3 = `
|
|
4221
|
+
.mobile-wallet-adapter-embedded-modal-close {
|
|
4222
|
+
display: none;
|
|
3565
4223
|
}
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
flex-direction: column;
|
|
3570
|
-
flex: 1;
|
|
3571
|
-
margin-left: auto;
|
|
4224
|
+
.mobile-wallet-adapter-embedded-modal-content {
|
|
4225
|
+
text-align: center;
|
|
4226
|
+
min-width: 300px;
|
|
3572
4227
|
}
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
display: flex;
|
|
3576
|
-
padding: 10px;
|
|
4228
|
+
.mobile-wallet-adapter-embedded-modal-launch-icon {
|
|
4229
|
+
margin-top: 24px;
|
|
3577
4230
|
}
|
|
3578
|
-
|
|
3579
|
-
.mobile-wallet-adapter-embedded-modal-icon {}
|
|
3580
|
-
|
|
3581
4231
|
.mobile-wallet-adapter-embedded-modal-title {
|
|
4232
|
+
margin: 18px 100px 30px 100px;
|
|
3582
4233
|
color: #000000;
|
|
3583
|
-
font-size: 2.
|
|
4234
|
+
font-size: 2.75em;
|
|
3584
4235
|
font-weight: 600;
|
|
3585
4236
|
}
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
4237
|
+
.mobile-wallet-adapter-embedded-modal-launch-action {
|
|
4238
|
+
display: block;
|
|
4239
|
+
width: 100%;
|
|
4240
|
+
height: 56px;
|
|
4241
|
+
font-size: 1.25em;
|
|
4242
|
+
background: #000000;
|
|
4243
|
+
color: #FFFFFF;
|
|
4244
|
+
border-radius: 18px;
|
|
3590
4245
|
}
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
min-width: 200px;
|
|
3599
|
-
min-height: 200px;
|
|
3600
|
-
background: linear-gradient(-60deg, #F7F8F8 30%, #ECEEEE 50%, #F7F8F8 70%);
|
|
3601
|
-
background-size: 200%;
|
|
3602
|
-
animation: placeholderAnimate 2.7s linear infinite;
|
|
3603
|
-
border-radius: 12px;
|
|
3604
|
-
}
|
|
3605
|
-
|
|
3606
|
-
.mobile-wallet-adapter-embedded-modal-divider {
|
|
3607
|
-
margin-top: 20px;
|
|
3608
|
-
padding-left: 10px;
|
|
3609
|
-
padding-right: 10px;
|
|
3610
|
-
}
|
|
3611
|
-
|
|
3612
|
-
.mobile-wallet-adapter-embedded-modal-divider hr {
|
|
3613
|
-
border-top: 1px solid #D9DEDE;
|
|
3614
|
-
}
|
|
3615
|
-
|
|
3616
|
-
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
3617
|
-
margin: auto;
|
|
3618
|
-
margin-right: 60px;
|
|
3619
|
-
padding: 20px;
|
|
3620
|
-
color: #6E8286;
|
|
3621
|
-
}
|
|
3622
|
-
|
|
3623
|
-
.mobile-wallet-adapter-embedded-modal-progress-badge {
|
|
3624
|
-
display: flex;
|
|
3625
|
-
background: #F7F8F8;
|
|
3626
|
-
height: 56px;
|
|
3627
|
-
min-width: 200px;
|
|
3628
|
-
margin: auto;
|
|
3629
|
-
padding-left: 20px;
|
|
3630
|
-
padding-right: 20px;
|
|
3631
|
-
border-radius: 18px;
|
|
3632
|
-
color: #A8B6B8;
|
|
3633
|
-
align-items: center;
|
|
3634
|
-
}
|
|
3635
|
-
|
|
3636
|
-
.mobile-wallet-adapter-embedded-modal-progress-badge > div:first-child {
|
|
3637
|
-
margin-left: auto;
|
|
3638
|
-
margin-right: 20px;
|
|
3639
|
-
}
|
|
3640
|
-
|
|
3641
|
-
.mobile-wallet-adapter-embedded-modal-progress-badge > div:nth-child(2) {
|
|
3642
|
-
margin-right: auto;
|
|
3643
|
-
}
|
|
3644
|
-
|
|
3645
|
-
/* Smaller screens */
|
|
3646
|
-
@media all and (max-width: 600px) {
|
|
3647
|
-
.mobile-wallet-adapter-embedded-modal-card {
|
|
3648
|
-
text-align: center;
|
|
3649
|
-
}
|
|
3650
|
-
.mobile-wallet-adapter-embedded-modal-qr-content {
|
|
3651
|
-
flex-direction: column;
|
|
3652
|
-
}
|
|
3653
|
-
.mobile-wallet-adapter-embedded-modal-qr-content > div:first-child {
|
|
3654
|
-
margin: auto;
|
|
3655
|
-
}
|
|
3656
|
-
.mobile-wallet-adapter-embedded-modal-qr-content > div:nth-child(2) {
|
|
3657
|
-
margin: auto;
|
|
3658
|
-
flex: 2 auto;
|
|
3659
|
-
}
|
|
3660
|
-
.mobile-wallet-adapter-embedded-modal-footer {
|
|
3661
|
-
flex-direction: column;
|
|
3662
|
-
}
|
|
3663
|
-
.mobile-wallet-adapter-embedded-modal-icon {
|
|
3664
|
-
display: none;
|
|
3665
|
-
}
|
|
3666
|
-
.mobile-wallet-adapter-embedded-modal-title {
|
|
3667
|
-
font-size: 1.5em;
|
|
3668
|
-
}
|
|
3669
|
-
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
3670
|
-
margin-right: unset;
|
|
3671
|
-
}
|
|
3672
|
-
.mobile-wallet-adapter-embedded-modal-qr-label {
|
|
3673
|
-
text-align: center;
|
|
3674
|
-
}
|
|
3675
|
-
.mobile-wallet-adapter-embedded-modal-qr-code-container {
|
|
3676
|
-
margin: auto;
|
|
3677
|
-
}
|
|
3678
|
-
.mobile-wallet-adapter-embedded-modal-qr-placeholder {
|
|
3679
|
-
margin: auto;
|
|
3680
|
-
}
|
|
3681
|
-
}
|
|
3682
|
-
|
|
3683
|
-
/* QR Placeholder */
|
|
3684
|
-
@keyframes placeholderAnimate {
|
|
3685
|
-
0% { background-position: 200% 0; }
|
|
3686
|
-
100% { background-position: -200% 0; }
|
|
3687
|
-
}
|
|
3688
|
-
|
|
3689
|
-
/* Spinner */
|
|
3690
|
-
@keyframes spinLeft {
|
|
3691
|
-
0% {
|
|
3692
|
-
transform: rotate(20deg);
|
|
3693
|
-
}
|
|
3694
|
-
50% {
|
|
3695
|
-
transform: rotate(160deg);
|
|
3696
|
-
}
|
|
3697
|
-
100% {
|
|
3698
|
-
transform: rotate(20deg);
|
|
3699
|
-
}
|
|
3700
|
-
}
|
|
3701
|
-
@keyframes spinRight {
|
|
3702
|
-
0% {
|
|
3703
|
-
transform: rotate(160deg);
|
|
3704
|
-
}
|
|
3705
|
-
50% {
|
|
3706
|
-
transform: rotate(20deg);
|
|
3707
|
-
}
|
|
3708
|
-
100% {
|
|
3709
|
-
transform: rotate(160deg);
|
|
3710
|
-
}
|
|
3711
|
-
}
|
|
3712
|
-
@keyframes spin {
|
|
3713
|
-
0% {
|
|
3714
|
-
transform: rotate(0deg);
|
|
3715
|
-
}
|
|
3716
|
-
100% {
|
|
3717
|
-
transform: rotate(2520deg);
|
|
3718
|
-
}
|
|
3719
|
-
}
|
|
3720
|
-
|
|
3721
|
-
.spinner {
|
|
3722
|
-
position: relative;
|
|
3723
|
-
width: 1.5em;
|
|
3724
|
-
height: 1.5em;
|
|
3725
|
-
margin: auto;
|
|
3726
|
-
animation: spin 10s linear infinite;
|
|
3727
|
-
}
|
|
3728
|
-
.spinner::before {
|
|
3729
|
-
content: "";
|
|
3730
|
-
position: absolute;
|
|
3731
|
-
top: 0;
|
|
3732
|
-
bottom: 0;
|
|
3733
|
-
left: 0;
|
|
3734
|
-
right: 0;
|
|
3735
|
-
}
|
|
3736
|
-
.right, .rightWrapper, .left, .leftWrapper {
|
|
3737
|
-
position: absolute;
|
|
3738
|
-
top: 0;
|
|
3739
|
-
overflow: hidden;
|
|
3740
|
-
width: .75em;
|
|
3741
|
-
height: 1.5em;
|
|
3742
|
-
}
|
|
3743
|
-
.left, .leftWrapper {
|
|
3744
|
-
left: 0;
|
|
3745
|
-
}
|
|
3746
|
-
.right {
|
|
3747
|
-
left: -12px;
|
|
3748
|
-
}
|
|
3749
|
-
.rightWrapper {
|
|
3750
|
-
right: 0;
|
|
3751
|
-
}
|
|
3752
|
-
.circle {
|
|
3753
|
-
border: .125em solid #A8B6B8;
|
|
3754
|
-
width: 1.25em; /* 1.5em - 2*0.125em border */
|
|
3755
|
-
height: 1.25em; /* 1.5em - 2*0.125em border */
|
|
3756
|
-
border-radius: 0.75em; /* 0.5*1.5em spinner size 8 */
|
|
3757
|
-
}
|
|
3758
|
-
.left {
|
|
3759
|
-
transform-origin: 100% 50%;
|
|
3760
|
-
animation: spinLeft 2.5s cubic-bezier(.2,0,.8,1) infinite;
|
|
3761
|
-
}
|
|
3762
|
-
.right {
|
|
3763
|
-
transform-origin: 100% 50%;
|
|
3764
|
-
animation: spinRight 2.5s cubic-bezier(.2,0,.8,1) infinite;
|
|
3765
|
-
}
|
|
3766
|
-
`;
|
|
3767
|
-
//#endregion
|
|
3768
|
-
//#region src/embedded-modal/localConnectionModal.ts
|
|
3769
|
-
var LocalConnectionModal = class extends EmbeddedModal {
|
|
3770
|
-
contentStyles = css$3;
|
|
3771
|
-
contentHtml = ErrorDialogHtml$3;
|
|
3772
|
-
initWithCallback(callback) {
|
|
3773
|
-
super.init();
|
|
3774
|
-
this.#prepareLaunchAction(callback);
|
|
3775
|
-
}
|
|
3776
|
-
#prepareLaunchAction(callback) {
|
|
3777
|
-
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
3778
|
-
const listener = async () => {
|
|
3779
|
-
launchButton?.removeEventListener("click", listener);
|
|
3780
|
-
this.close();
|
|
3781
|
-
callback();
|
|
3782
|
-
};
|
|
3783
|
-
launchButton?.addEventListener("click", listener);
|
|
3784
|
-
}
|
|
3785
|
-
};
|
|
3786
|
-
const ErrorDialogHtml$3 = `
|
|
3787
|
-
<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">
|
|
3788
|
-
<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"/>
|
|
3789
|
-
<mask id="mask0_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
3790
|
-
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
3791
|
-
</mask>
|
|
3792
|
-
<g mask="url(#mask0_189_522)">
|
|
3793
|
-
<mask id="mask1_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
3794
|
-
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
3795
|
-
</mask>
|
|
3796
|
-
<g mask="url(#mask1_189_522)">
|
|
3797
|
-
<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"/>
|
|
3798
|
-
</g>
|
|
3799
|
-
</g>
|
|
3800
|
-
</svg>
|
|
3801
|
-
<div class="mobile-wallet-adapter-embedded-modal-title">Ready to connect!</div>
|
|
3802
|
-
<div>
|
|
3803
|
-
<button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
|
|
3804
|
-
Connect Wallet
|
|
3805
|
-
</button>
|
|
3806
|
-
</div>
|
|
3807
|
-
`;
|
|
3808
|
-
const css$3 = `
|
|
3809
|
-
.mobile-wallet-adapter-embedded-modal-close {
|
|
3810
|
-
display: none;
|
|
3811
|
-
}
|
|
3812
|
-
.mobile-wallet-adapter-embedded-modal-content {
|
|
3813
|
-
text-align: center;
|
|
3814
|
-
min-width: 300px;
|
|
3815
|
-
}
|
|
3816
|
-
.mobile-wallet-adapter-embedded-modal-launch-icon {
|
|
3817
|
-
margin-top: 24px;
|
|
3818
|
-
}
|
|
3819
|
-
.mobile-wallet-adapter-embedded-modal-title {
|
|
3820
|
-
margin: 18px 100px 30px 100px;
|
|
3821
|
-
color: #000000;
|
|
3822
|
-
font-size: 2.75em;
|
|
3823
|
-
font-weight: 600;
|
|
3824
|
-
}
|
|
3825
|
-
.mobile-wallet-adapter-embedded-modal-launch-action {
|
|
3826
|
-
display: block;
|
|
3827
|
-
width: 100%;
|
|
3828
|
-
height: 56px;
|
|
3829
|
-
font-size: 1.25em;
|
|
3830
|
-
background: #000000;
|
|
3831
|
-
color: #FFFFFF;
|
|
3832
|
-
border-radius: 18px;
|
|
3833
|
-
}
|
|
3834
|
-
/* Smaller screens */
|
|
3835
|
-
@media all and (max-width: 600px) {
|
|
3836
|
-
.mobile-wallet-adapter-embedded-modal-title {
|
|
3837
|
-
font-size: 1.5em;
|
|
3838
|
-
margin-right: 12px;
|
|
3839
|
-
margin-left: 12px;
|
|
3840
|
-
}
|
|
4246
|
+
/* Smaller screens */
|
|
4247
|
+
@media all and (max-width: 600px) {
|
|
4248
|
+
.mobile-wallet-adapter-embedded-modal-title {
|
|
4249
|
+
font-size: 1.5em;
|
|
4250
|
+
margin-right: 12px;
|
|
4251
|
+
margin-left: 12px;
|
|
4252
|
+
}
|
|
3841
4253
|
}
|
|
3842
4254
|
`;
|
|
3843
4255
|
//#endregion
|
|
@@ -4095,17 +4507,6 @@ const css$1 = `
|
|
|
4095
4507
|
}
|
|
4096
4508
|
}
|
|
4097
4509
|
`;
|
|
4098
|
-
//#endregion
|
|
4099
|
-
//#region src/getIsSupported.ts
|
|
4100
|
-
function getIsLocalAssociationSupported() {
|
|
4101
|
-
return typeof window !== "undefined" && window.isSecureContext && typeof document !== "undefined" && /android/i.test(navigator.userAgent);
|
|
4102
|
-
}
|
|
4103
|
-
function getIsRemoteAssociationSupported() {
|
|
4104
|
-
return typeof window !== "undefined" && window.isSecureContext && typeof document !== "undefined" && !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
4105
|
-
}
|
|
4106
|
-
function isWebView(userAgentString) {
|
|
4107
|
-
return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
|
|
4108
|
-
}
|
|
4109
4510
|
function isSolanaMobileWebShell(userAgentString) {
|
|
4110
4511
|
return userAgentString.includes("Solana Mobile Web Shell");
|
|
4111
4512
|
}
|
|
@@ -4166,7 +4567,6 @@ const icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZp
|
|
|
4166
4567
|
//#endregion
|
|
4167
4568
|
//#region src/wallet.ts
|
|
4168
4569
|
const SolanaMobileWalletAdapterWalletName = "Mobile Wallet Adapter";
|
|
4169
|
-
const SolanaMobileWalletAdapterRemoteWalletName = "Remote Mobile Wallet Adapter";
|
|
4170
4570
|
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
4171
4571
|
const DEFAULT_FEATURES = [
|
|
4172
4572
|
SolanaSignAndSendTransaction,
|
|
@@ -4534,486 +4934,6 @@ var LocalSolanaMobileWalletAdapterWallet = class {
|
|
|
4534
4934
|
}
|
|
4535
4935
|
};
|
|
4536
4936
|
};
|
|
4537
|
-
var RemoteSolanaMobileWalletAdapterWallet = class {
|
|
4538
|
-
#listeners = {};
|
|
4539
|
-
#version = "1.0.0";
|
|
4540
|
-
#name = SolanaMobileWalletAdapterRemoteWalletName;
|
|
4541
|
-
#url = "https://solanamobile.com/wallets";
|
|
4542
|
-
#icon = icon;
|
|
4543
|
-
#appIdentity;
|
|
4544
|
-
#authorization;
|
|
4545
|
-
#authorizationCache;
|
|
4546
|
-
#connecting = false;
|
|
4547
|
-
/**
|
|
4548
|
-
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
4549
|
-
* increment this and use it to make sure that `transact` calls from the previous
|
|
4550
|
-
* 'generation' don't continue to do work and throw exceptions.
|
|
4551
|
-
*/
|
|
4552
|
-
#connectionGeneration = 0;
|
|
4553
|
-
#chains = [];
|
|
4554
|
-
#chainSelector;
|
|
4555
|
-
#optionalFeatures;
|
|
4556
|
-
#onWalletNotFound;
|
|
4557
|
-
#hostAuthority;
|
|
4558
|
-
#session;
|
|
4559
|
-
get version() {
|
|
4560
|
-
return this.#version;
|
|
4561
|
-
}
|
|
4562
|
-
get name() {
|
|
4563
|
-
return this.#name;
|
|
4564
|
-
}
|
|
4565
|
-
get url() {
|
|
4566
|
-
return this.#url;
|
|
4567
|
-
}
|
|
4568
|
-
get icon() {
|
|
4569
|
-
return this.#icon;
|
|
4570
|
-
}
|
|
4571
|
-
get chains() {
|
|
4572
|
-
return this.#chains;
|
|
4573
|
-
}
|
|
4574
|
-
get features() {
|
|
4575
|
-
return {
|
|
4576
|
-
[StandardConnect]: {
|
|
4577
|
-
version: "1.0.0",
|
|
4578
|
-
connect: this.#connect
|
|
4579
|
-
},
|
|
4580
|
-
[StandardDisconnect]: {
|
|
4581
|
-
version: "1.0.0",
|
|
4582
|
-
disconnect: this.#disconnect
|
|
4583
|
-
},
|
|
4584
|
-
[StandardEvents]: {
|
|
4585
|
-
version: "1.0.0",
|
|
4586
|
-
on: this.#on
|
|
4587
|
-
},
|
|
4588
|
-
[SolanaSignMessage]: {
|
|
4589
|
-
version: "1.0.0",
|
|
4590
|
-
signMessage: this.#signMessage
|
|
4591
|
-
},
|
|
4592
|
-
[SolanaSignIn]: {
|
|
4593
|
-
version: "1.0.0",
|
|
4594
|
-
signIn: this.#signIn
|
|
4595
|
-
},
|
|
4596
|
-
...this.#optionalFeatures
|
|
4597
|
-
};
|
|
4598
|
-
}
|
|
4599
|
-
get accounts() {
|
|
4600
|
-
return this.#authorization?.accounts ?? [];
|
|
4601
|
-
}
|
|
4602
|
-
constructor(config) {
|
|
4603
|
-
this.#authorizationCache = config.authorizationCache;
|
|
4604
|
-
this.#appIdentity = config.appIdentity;
|
|
4605
|
-
this.#chains = config.chains;
|
|
4606
|
-
this.#chainSelector = config.chainSelector;
|
|
4607
|
-
this.#hostAuthority = config.remoteHostAuthority;
|
|
4608
|
-
this.#onWalletNotFound = config.onWalletNotFound;
|
|
4609
|
-
this.#optionalFeatures = {
|
|
4610
|
-
[SolanaSignAndSendTransaction]: {
|
|
4611
|
-
version: "1.0.0",
|
|
4612
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
4613
|
-
signAndSendTransaction: this.#signAndSendTransaction
|
|
4614
|
-
},
|
|
4615
|
-
[SolanaSignTransaction]: {
|
|
4616
|
-
version: "1.0.0",
|
|
4617
|
-
supportedTransactionVersions: ["legacy", 0],
|
|
4618
|
-
signTransaction: this.#signTransaction
|
|
4619
|
-
}
|
|
4620
|
-
};
|
|
4621
|
-
}
|
|
4622
|
-
get connected() {
|
|
4623
|
-
return !!this.#session && !!this.#authorization;
|
|
4624
|
-
}
|
|
4625
|
-
get isAuthorized() {
|
|
4626
|
-
return !!this.#authorization;
|
|
4627
|
-
}
|
|
4628
|
-
get currentAuthorization() {
|
|
4629
|
-
return this.#authorization;
|
|
4630
|
-
}
|
|
4631
|
-
get cachedAuthorizationResult() {
|
|
4632
|
-
return this.#authorizationCache.get();
|
|
4633
|
-
}
|
|
4634
|
-
#on = (event, listener) => {
|
|
4635
|
-
this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
|
|
4636
|
-
return () => this.#off(event, listener);
|
|
4637
|
-
};
|
|
4638
|
-
#emit(event, ...args) {
|
|
4639
|
-
this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
|
|
4640
|
-
}
|
|
4641
|
-
#off(event, listener) {
|
|
4642
|
-
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
4643
|
-
}
|
|
4644
|
-
#connect = async (_input = {}) => {
|
|
4645
|
-
if (this.#connecting || this.connected) return { accounts: this.accounts };
|
|
4646
|
-
this.#connecting = true;
|
|
4647
|
-
try {
|
|
4648
|
-
await this.#performAuthorization();
|
|
4649
|
-
} catch (e) {
|
|
4650
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
4651
|
-
} finally {
|
|
4652
|
-
this.#connecting = false;
|
|
4653
|
-
}
|
|
4654
|
-
return { accounts: this.accounts };
|
|
4655
|
-
};
|
|
4656
|
-
#performAuthorization = async (signInPayload) => {
|
|
4657
|
-
try {
|
|
4658
|
-
const cachedAuthorizationResult = await this.#authorizationCache.get();
|
|
4659
|
-
if (cachedAuthorizationResult) {
|
|
4660
|
-
this.#handleAuthorizationResult(cachedAuthorizationResult);
|
|
4661
|
-
return cachedAuthorizationResult;
|
|
4662
|
-
}
|
|
4663
|
-
if (this.#session) this.#session = void 0;
|
|
4664
|
-
const selectedChain = await this.#chainSelector.select(this.#chains);
|
|
4665
|
-
return await this.#transact(async (wallet) => {
|
|
4666
|
-
const [capabilities, mwaAuthorizationResult] = await Promise.all([wallet.getCapabilities(), wallet.authorize({
|
|
4667
|
-
chain: selectedChain,
|
|
4668
|
-
identity: this.#appIdentity,
|
|
4669
|
-
sign_in_payload: signInPayload
|
|
4670
|
-
})]);
|
|
4671
|
-
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
4672
|
-
const authorizationResult = {
|
|
4673
|
-
...mwaAuthorizationResult,
|
|
4674
|
-
accounts,
|
|
4675
|
-
chain: selectedChain,
|
|
4676
|
-
capabilities
|
|
4677
|
-
};
|
|
4678
|
-
Promise.all([
|
|
4679
|
-
this.#handleWalletCapabilitiesResult(capabilities),
|
|
4680
|
-
this.#authorizationCache.set(authorizationResult),
|
|
4681
|
-
this.#handleAuthorizationResult(authorizationResult)
|
|
4682
|
-
]);
|
|
4683
|
-
return authorizationResult;
|
|
4684
|
-
});
|
|
4685
|
-
} catch (e) {
|
|
4686
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
4687
|
-
}
|
|
4688
|
-
};
|
|
4689
|
-
#handleAuthorizationResult = async (authorization) => {
|
|
4690
|
-
const didPublicKeysChange = this.#authorization == null || this.#authorization?.accounts.length !== authorization.accounts.length || this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
4691
|
-
this.#authorization = authorization;
|
|
4692
|
-
if (didPublicKeysChange) this.#emit("change", { accounts: this.accounts });
|
|
4693
|
-
};
|
|
4694
|
-
#handleWalletCapabilitiesResult = async (capabilities) => {
|
|
4695
|
-
const supportsSignTransaction = capabilities.features.includes("solana:signTransactions");
|
|
4696
|
-
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions || capabilities.features.includes("solana:signAndSendTransaction");
|
|
4697
|
-
const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction || SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
4698
|
-
this.#optionalFeatures = {
|
|
4699
|
-
...supportsSignAndSendTransaction && { [SolanaSignAndSendTransaction]: {
|
|
4700
|
-
version: "1.0.0",
|
|
4701
|
-
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
4702
|
-
signAndSendTransaction: this.#signAndSendTransaction
|
|
4703
|
-
} },
|
|
4704
|
-
...supportsSignTransaction && { [SolanaSignTransaction]: {
|
|
4705
|
-
version: "1.0.0",
|
|
4706
|
-
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
4707
|
-
signTransaction: this.#signTransaction
|
|
4708
|
-
} }
|
|
4709
|
-
};
|
|
4710
|
-
if (didCapabilitiesChange) this.#emit("change", { features: this.features });
|
|
4711
|
-
};
|
|
4712
|
-
#performReauthorization = async (wallet, authToken, chain) => {
|
|
4713
|
-
try {
|
|
4714
|
-
const [capabilities, mwaAuthorizationResult] = await Promise.all([this.#authorization?.capabilities ?? await wallet.getCapabilities(), wallet.authorize({
|
|
4715
|
-
auth_token: authToken,
|
|
4716
|
-
identity: this.#appIdentity,
|
|
4717
|
-
chain
|
|
4718
|
-
})]);
|
|
4719
|
-
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
4720
|
-
const authorization = {
|
|
4721
|
-
...mwaAuthorizationResult,
|
|
4722
|
-
accounts,
|
|
4723
|
-
chain,
|
|
4724
|
-
capabilities
|
|
4725
|
-
};
|
|
4726
|
-
Promise.all([this.#authorizationCache.set(authorization), this.#handleAuthorizationResult(authorization)]);
|
|
4727
|
-
} catch (e) {
|
|
4728
|
-
this.#disconnect();
|
|
4729
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
4730
|
-
}
|
|
4731
|
-
};
|
|
4732
|
-
#disconnect = async () => {
|
|
4733
|
-
this.#session?.close();
|
|
4734
|
-
this.#authorizationCache.clear();
|
|
4735
|
-
this.#connecting = false;
|
|
4736
|
-
this.#connectionGeneration++;
|
|
4737
|
-
this.#authorization = void 0;
|
|
4738
|
-
this.#session = void 0;
|
|
4739
|
-
this.#emit("change", { accounts: this.accounts });
|
|
4740
|
-
};
|
|
4741
|
-
#transact = async (callback) => {
|
|
4742
|
-
const walletUriBase = this.#authorization?.wallet_uri_base;
|
|
4743
|
-
const remoteConfig = {
|
|
4744
|
-
...walletUriBase ? { baseUri: walletUriBase } : void 0,
|
|
4745
|
-
remoteHostAuthority: this.#hostAuthority
|
|
4746
|
-
};
|
|
4747
|
-
const currentConnectionGeneration = this.#connectionGeneration;
|
|
4748
|
-
const modal = new RemoteConnectionModal();
|
|
4749
|
-
if (this.#session) return callback(this.#session.wallet);
|
|
4750
|
-
try {
|
|
4751
|
-
modal.init();
|
|
4752
|
-
modal.open();
|
|
4753
|
-
const { associationUrl, close, wallet } = await startRemoteScenario(remoteConfig);
|
|
4754
|
-
const removeCloseListener = modal.addEventListener("close", (event) => {
|
|
4755
|
-
if (event) close();
|
|
4756
|
-
});
|
|
4757
|
-
modal.populateQRCode(associationUrl.toString());
|
|
4758
|
-
this.#session = {
|
|
4759
|
-
close,
|
|
4760
|
-
wallet: await wallet
|
|
4761
|
-
};
|
|
4762
|
-
removeCloseListener();
|
|
4763
|
-
modal.close();
|
|
4764
|
-
return await callback(this.#session.wallet);
|
|
4765
|
-
} catch (e) {
|
|
4766
|
-
modal.close();
|
|
4767
|
-
if (this.#connectionGeneration !== currentConnectionGeneration) await new Promise(() => {});
|
|
4768
|
-
if (e instanceof Error && e.name === "SolanaMobileWalletAdapterError" && e.code === "ERROR_WALLET_NOT_FOUND") await this.#onWalletNotFound(this);
|
|
4769
|
-
throw e;
|
|
4770
|
-
}
|
|
4771
|
-
};
|
|
4772
|
-
#assertIsAuthorized = () => {
|
|
4773
|
-
if (!this.#authorization) throw new Error("Wallet not connected");
|
|
4774
|
-
return {
|
|
4775
|
-
authToken: this.#authorization.auth_token,
|
|
4776
|
-
chain: this.#authorization.chain
|
|
4777
|
-
};
|
|
4778
|
-
};
|
|
4779
|
-
#accountsToWalletStandardAccounts = (accounts) => {
|
|
4780
|
-
return accounts.map((account) => {
|
|
4781
|
-
const publicKey = toUint8Array(account.address);
|
|
4782
|
-
return {
|
|
4783
|
-
address: base58.encode(publicKey),
|
|
4784
|
-
publicKey,
|
|
4785
|
-
label: account.label,
|
|
4786
|
-
icon: account.icon,
|
|
4787
|
-
chains: account.chains ?? this.#chains,
|
|
4788
|
-
features: account.features ?? DEFAULT_FEATURES
|
|
4789
|
-
};
|
|
4790
|
-
});
|
|
4791
|
-
};
|
|
4792
|
-
#performSignTransactions = async (transactions) => {
|
|
4793
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
4794
|
-
try {
|
|
4795
|
-
return await this.#transact(async (wallet) => {
|
|
4796
|
-
await this.#performReauthorization(wallet, authToken, chain);
|
|
4797
|
-
return (await wallet.signTransactions({ payloads: transactions.map(fromUint8Array) })).signed_payloads.map(toUint8Array);
|
|
4798
|
-
});
|
|
4799
|
-
} catch (e) {
|
|
4800
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
4801
|
-
}
|
|
4802
|
-
};
|
|
4803
|
-
#performSignAndSendTransaction = async (transaction, options) => {
|
|
4804
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
4805
|
-
try {
|
|
4806
|
-
return await this.#transact(async (wallet) => {
|
|
4807
|
-
const [capabilities] = await Promise.all([wallet.getCapabilities(), this.#performReauthorization(wallet, authToken, chain)]);
|
|
4808
|
-
if (capabilities.supports_sign_and_send_transactions) return (await wallet.signAndSendTransactions({
|
|
4809
|
-
...options,
|
|
4810
|
-
payloads: [fromUint8Array(transaction)]
|
|
4811
|
-
})).signatures.map(toUint8Array)[0];
|
|
4812
|
-
else throw new Error("connected wallet does not support signAndSendTransaction");
|
|
4813
|
-
});
|
|
4814
|
-
} catch (e) {
|
|
4815
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
4816
|
-
}
|
|
4817
|
-
};
|
|
4818
|
-
#signAndSendTransaction = async (...inputs) => {
|
|
4819
|
-
const outputs = [];
|
|
4820
|
-
for (const input of inputs) {
|
|
4821
|
-
const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
|
|
4822
|
-
outputs.push({ signature });
|
|
4823
|
-
}
|
|
4824
|
-
return outputs;
|
|
4825
|
-
};
|
|
4826
|
-
#signTransaction = async (...inputs) => {
|
|
4827
|
-
return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction))).map((signedTransaction) => {
|
|
4828
|
-
return { signedTransaction };
|
|
4829
|
-
});
|
|
4830
|
-
};
|
|
4831
|
-
#signMessage = async (...inputs) => {
|
|
4832
|
-
const { authToken, chain } = this.#assertIsAuthorized();
|
|
4833
|
-
const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
|
|
4834
|
-
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
4835
|
-
try {
|
|
4836
|
-
return await this.#transact(async (wallet) => {
|
|
4837
|
-
await this.#performReauthorization(wallet, authToken, chain);
|
|
4838
|
-
return (await wallet.signMessages({
|
|
4839
|
-
addresses,
|
|
4840
|
-
payloads: messages
|
|
4841
|
-
})).signed_payloads.map(toUint8Array).map((signedMessage) => {
|
|
4842
|
-
return {
|
|
4843
|
-
signedMessage,
|
|
4844
|
-
signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES)
|
|
4845
|
-
};
|
|
4846
|
-
});
|
|
4847
|
-
});
|
|
4848
|
-
} catch (e) {
|
|
4849
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
4850
|
-
}
|
|
4851
|
-
};
|
|
4852
|
-
#signIn = async (...inputs) => {
|
|
4853
|
-
const outputs = [];
|
|
4854
|
-
if (inputs.length > 1) for (const input of inputs) outputs.push(await this.#performSignIn(input));
|
|
4855
|
-
else return [await this.#performSignIn(inputs[0])];
|
|
4856
|
-
return outputs;
|
|
4857
|
-
};
|
|
4858
|
-
#performSignIn = async (input) => {
|
|
4859
|
-
this.#connecting = true;
|
|
4860
|
-
try {
|
|
4861
|
-
const authorizationResult = await this.#performAuthorization({
|
|
4862
|
-
...input,
|
|
4863
|
-
domain: input?.domain ?? window.location.host
|
|
4864
|
-
});
|
|
4865
|
-
if (!authorizationResult.sign_in_result) throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
4866
|
-
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
4867
|
-
const signedInAccount = authorizationResult.accounts.find((acc) => acc.address == signedInAddress);
|
|
4868
|
-
return {
|
|
4869
|
-
account: {
|
|
4870
|
-
...signedInAccount ?? { address: base58.encode(toUint8Array(signedInAddress)) },
|
|
4871
|
-
publicKey: toUint8Array(signedInAddress),
|
|
4872
|
-
chains: signedInAccount?.chains ?? this.#chains,
|
|
4873
|
-
features: signedInAccount?.features ?? authorizationResult.capabilities.features
|
|
4874
|
-
},
|
|
4875
|
-
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
4876
|
-
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
4877
|
-
};
|
|
4878
|
-
} catch (e) {
|
|
4879
|
-
throw new Error(getErrorMessage(e), { cause: e });
|
|
4880
|
-
} finally {
|
|
4881
|
-
this.#connecting = false;
|
|
4882
|
-
}
|
|
4883
|
-
};
|
|
4884
|
-
};
|
|
4885
|
-
//#endregion
|
|
4886
|
-
//#region src/initialize.ts
|
|
4887
|
-
function registerMwa(config) {
|
|
4888
|
-
if (typeof window === "undefined") {
|
|
4889
|
-
console.warn(`MWA not registered: no window object`);
|
|
4890
|
-
return;
|
|
4891
|
-
}
|
|
4892
|
-
if (!window.isSecureContext) {
|
|
4893
|
-
console.warn(`MWA not registered: secure context required (https)`);
|
|
4894
|
-
return;
|
|
4895
|
-
}
|
|
4896
|
-
const userAgent = navigator.userAgent;
|
|
4897
|
-
if (getIsLocalAssociationSupported() && (!isWebView(userAgent) || isSolanaMobileWebShell(userAgent))) registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
|
|
4898
|
-
else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== void 0) registerWallet(new RemoteSolanaMobileWalletAdapterWallet({
|
|
4899
|
-
...config,
|
|
4900
|
-
remoteHostAuthority: config.remoteHostAuthority
|
|
4901
|
-
}));
|
|
4902
|
-
}
|
|
4903
|
-
//#endregion
|
|
4904
|
-
//#region src/embedded-modal/errorModal.ts
|
|
4905
|
-
const WALLET_NOT_FOUND_ERROR_MESSAGE = "To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.";
|
|
4906
|
-
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.";
|
|
4907
|
-
var ErrorModal = class extends EmbeddedModal {
|
|
4908
|
-
contentStyles = css;
|
|
4909
|
-
contentHtml = ErrorDialogHtml;
|
|
4910
|
-
initWithError(error) {
|
|
4911
|
-
super.init();
|
|
4912
|
-
this.populateError(error);
|
|
4913
|
-
}
|
|
4914
|
-
populateError(error) {
|
|
4915
|
-
const errorMessageElement = this.dom?.getElementById("mobile-wallet-adapter-error-message");
|
|
4916
|
-
const actionBtn = this.dom?.getElementById("mobile-wallet-adapter-error-action");
|
|
4917
|
-
if (errorMessageElement) {
|
|
4918
|
-
if (error.name === "SolanaMobileWalletAdapterError") switch (error.code) {
|
|
4919
|
-
case "ERROR_WALLET_NOT_FOUND":
|
|
4920
|
-
errorMessageElement.innerHTML = WALLET_NOT_FOUND_ERROR_MESSAGE;
|
|
4921
|
-
if (actionBtn) actionBtn.addEventListener("click", () => {
|
|
4922
|
-
window.location.href = "https://solanamobile.com/wallets";
|
|
4923
|
-
});
|
|
4924
|
-
return;
|
|
4925
|
-
case "ERROR_BROWSER_NOT_SUPPORTED":
|
|
4926
|
-
errorMessageElement.innerHTML = BROWSER_NOT_SUPPORTED_ERROR_MESSAGE;
|
|
4927
|
-
if (actionBtn) actionBtn.style.display = "none";
|
|
4928
|
-
return;
|
|
4929
|
-
}
|
|
4930
|
-
errorMessageElement.innerHTML = `An unexpected error occurred: ${error.message}`;
|
|
4931
|
-
} else console.log("Failed to locate error dialog element");
|
|
4932
|
-
}
|
|
4933
|
-
};
|
|
4934
|
-
const ErrorDialogHtml = `
|
|
4935
|
-
<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>
|
|
4936
|
-
<div class="mobile-wallet-adapter-embedded-modal-title">We can't find a wallet.</div>
|
|
4937
|
-
<div id="mobile-wallet-adapter-error-message" class="mobile-wallet-adapter-embedded-modal-subtitle"></div>
|
|
4938
|
-
<div>
|
|
4939
|
-
<button data-error-action id="mobile-wallet-adapter-error-action" class="mobile-wallet-adapter-embedded-modal-error-action">
|
|
4940
|
-
Find a wallet
|
|
4941
|
-
</button>
|
|
4942
|
-
</div>
|
|
4943
|
-
`;
|
|
4944
|
-
const css = `
|
|
4945
|
-
.mobile-wallet-adapter-embedded-modal-content {
|
|
4946
|
-
text-align: center;
|
|
4947
|
-
}
|
|
4948
|
-
|
|
4949
|
-
.mobile-wallet-adapter-embedded-modal-error-icon {
|
|
4950
|
-
margin-top: 24px;
|
|
4951
|
-
}
|
|
4952
|
-
|
|
4953
|
-
.mobile-wallet-adapter-embedded-modal-title {
|
|
4954
|
-
margin: 18px 100px auto 100px;
|
|
4955
|
-
color: #000000;
|
|
4956
|
-
font-size: 2.75em;
|
|
4957
|
-
font-weight: 600;
|
|
4958
|
-
}
|
|
4959
|
-
|
|
4960
|
-
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
4961
|
-
margin: 30px 60px 40px 60px;
|
|
4962
|
-
color: #000000;
|
|
4963
|
-
font-size: 1.25em;
|
|
4964
|
-
font-weight: 400;
|
|
4965
|
-
}
|
|
4966
|
-
|
|
4967
|
-
.mobile-wallet-adapter-embedded-modal-error-action {
|
|
4968
|
-
display: block;
|
|
4969
|
-
width: 100%;
|
|
4970
|
-
height: 56px;
|
|
4971
|
-
/*margin-top: 40px;*/
|
|
4972
|
-
font-size: 1.25em;
|
|
4973
|
-
/*line-height: 24px;*/
|
|
4974
|
-
/*letter-spacing: -1%;*/
|
|
4975
|
-
background: #000000;
|
|
4976
|
-
color: #FFFFFF;
|
|
4977
|
-
border-radius: 18px;
|
|
4978
|
-
}
|
|
4979
|
-
|
|
4980
|
-
/* Smaller screens */
|
|
4981
|
-
@media all and (max-width: 600px) {
|
|
4982
|
-
.mobile-wallet-adapter-embedded-modal-title {
|
|
4983
|
-
font-size: 1.5em;
|
|
4984
|
-
margin-right: 12px;
|
|
4985
|
-
margin-left: 12px;
|
|
4986
|
-
}
|
|
4987
|
-
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
4988
|
-
margin-right: 12px;
|
|
4989
|
-
margin-left: 12px;
|
|
4990
|
-
}
|
|
4991
|
-
}
|
|
4992
|
-
`;
|
|
4993
|
-
//#endregion
|
|
4994
|
-
//#region src/createDefaultWalletNotFoundHandler.ts
|
|
4995
|
-
async function defaultErrorModalWalletNotFoundHandler() {
|
|
4996
|
-
if (typeof window !== "undefined") {
|
|
4997
|
-
const userAgent = window.navigator.userAgent.toLowerCase();
|
|
4998
|
-
const errorDialog = new ErrorModal();
|
|
4999
|
-
if (userAgent.includes("wv")) errorDialog.initWithError({
|
|
5000
|
-
name: "SolanaMobileWalletAdapterError",
|
|
5001
|
-
code: "ERROR_BROWSER_NOT_SUPPORTED",
|
|
5002
|
-
message: ""
|
|
5003
|
-
});
|
|
5004
|
-
else errorDialog.initWithError({
|
|
5005
|
-
name: "SolanaMobileWalletAdapterError",
|
|
5006
|
-
code: "ERROR_WALLET_NOT_FOUND",
|
|
5007
|
-
message: ""
|
|
5008
|
-
});
|
|
5009
|
-
errorDialog.open();
|
|
5010
|
-
}
|
|
5011
|
-
}
|
|
5012
|
-
function createDefaultWalletNotFoundHandler() {
|
|
5013
|
-
return async () => {
|
|
5014
|
-
defaultErrorModalWalletNotFoundHandler();
|
|
5015
|
-
};
|
|
5016
|
-
}
|
|
5017
4937
|
//#endregion
|
|
5018
4938
|
//#region src/createDefaultAuthorizationCache.ts
|
|
5019
4939
|
const CACHE_KEY = "SolanaMobileWalletAdapterDefaultAuthorizationCache";
|
|
@@ -5065,5 +4985,5 @@ function createDefaultChainSelector() {
|
|
|
5065
4985
|
} };
|
|
5066
4986
|
}
|
|
5067
4987
|
|
|
5068
|
-
export { LocalSolanaMobileWalletAdapterWallet,
|
|
5069
|
-
//# sourceMappingURL=index.browser-
|
|
4988
|
+
export { LocalSolanaMobileWalletAdapterWallet, SolanaMobileWalletAdapterWalletName, createDefaultAuthorizationCache, createDefaultChainSelector };
|
|
4989
|
+
//# sourceMappingURL=index.browser-p-pgsxxW.esm.js.map
|