@pooflabs/web 0.0.58 → 0.0.59
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/{index-qEuONikY.esm.js → index-B1INQP2H.esm.js} +827 -1957
- package/dist/index-B1INQP2H.esm.js.map +1 -0
- package/dist/{index-CLKeQYs1.js → index-BGYQ_HzF.js} +828 -1958
- package/dist/index-BGYQ_HzF.js.map +1 -0
- package/dist/{index-Dg6pd0nV.esm.js → index-C9sapvtl.esm.js} +991 -694
- package/dist/index-C9sapvtl.esm.js.map +1 -0
- package/dist/{index-DYv3VMgP.js → index-DZfjvlS2.js} +992 -694
- package/dist/index-DZfjvlS2.js.map +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/index-CLKeQYs1.js.map +0 -1
- package/dist/index-DYv3VMgP.js.map +0 -1
- package/dist/index-Dg6pd0nV.esm.js.map +0 -1
- package/dist/index-qEuONikY.esm.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var globalAxios = require('axios');
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-DZfjvlS2.js');
|
|
6
6
|
var web3_js = require('@solana/web3.js');
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
8
|
require('@coral-xyz/anchor');
|
|
@@ -1150,17 +1150,17 @@ function requireSrc () {
|
|
|
1150
1150
|
return src;
|
|
1151
1151
|
}
|
|
1152
1152
|
|
|
1153
|
-
var bs58
|
|
1153
|
+
var bs58;
|
|
1154
1154
|
var hasRequiredBs58;
|
|
1155
1155
|
|
|
1156
1156
|
function requireBs58 () {
|
|
1157
|
-
if (hasRequiredBs58) return bs58
|
|
1157
|
+
if (hasRequiredBs58) return bs58;
|
|
1158
1158
|
hasRequiredBs58 = 1;
|
|
1159
1159
|
const basex = requireSrc();
|
|
1160
1160
|
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
1161
1161
|
|
|
1162
|
-
bs58
|
|
1163
|
-
return bs58
|
|
1162
|
+
bs58 = basex(ALPHABET);
|
|
1163
|
+
return bs58;
|
|
1164
1164
|
}
|
|
1165
1165
|
|
|
1166
1166
|
requireBs58();
|
|
@@ -1457,7 +1457,7 @@ var PhantomClient = class {
|
|
|
1457
1457
|
throw new Error(`Failed to create wallet: ${error.response?.data?.message || error.message}`);
|
|
1458
1458
|
}
|
|
1459
1459
|
}
|
|
1460
|
-
async prepare(transaction, organizationId, submissionConfig, account) {
|
|
1460
|
+
async prepare(transaction, organizationId, submissionConfig, account, methodName) {
|
|
1461
1461
|
try {
|
|
1462
1462
|
const request = {
|
|
1463
1463
|
transaction,
|
|
@@ -1467,7 +1467,8 @@ var PhantomClient = class {
|
|
|
1467
1467
|
};
|
|
1468
1468
|
const response = await this.axiosInstance.post(`${this.config.apiBaseUrl}/prepare`, request, {
|
|
1469
1469
|
headers: {
|
|
1470
|
-
"Content-Type": "application/json"
|
|
1470
|
+
"Content-Type": "application/json",
|
|
1471
|
+
"X-Rpc-Method": methodName
|
|
1471
1472
|
}
|
|
1472
1473
|
});
|
|
1473
1474
|
return response.data;
|
|
@@ -1497,7 +1498,8 @@ var PhantomClient = class {
|
|
|
1497
1498
|
encodedTransaction,
|
|
1498
1499
|
this.config.organizationId,
|
|
1499
1500
|
submissionConfig,
|
|
1500
|
-
account
|
|
1501
|
+
account,
|
|
1502
|
+
params.methodName
|
|
1501
1503
|
);
|
|
1502
1504
|
return prepareResponse.transaction;
|
|
1503
1505
|
} catch (e) {
|
|
@@ -1510,6 +1512,13 @@ var PhantomClient = class {
|
|
|
1510
1512
|
}
|
|
1511
1513
|
return encodedTransaction;
|
|
1512
1514
|
}
|
|
1515
|
+
getRpcMethodName(networkId, includeSubmissionConfig) {
|
|
1516
|
+
const isEvm = isEthereumChain(networkId);
|
|
1517
|
+
if (isEvm) {
|
|
1518
|
+
return includeSubmissionConfig ? "eth_sendTransaction" : "eth_signTransaction";
|
|
1519
|
+
}
|
|
1520
|
+
return includeSubmissionConfig ? "signAndSendTransaction" : "signTransaction";
|
|
1521
|
+
}
|
|
1513
1522
|
/**
|
|
1514
1523
|
* Private method for shared signing logic
|
|
1515
1524
|
*/
|
|
@@ -1518,6 +1527,7 @@ var PhantomClient = class {
|
|
|
1518
1527
|
const encodedTransaction = params.transaction;
|
|
1519
1528
|
const networkIdParam = params.networkId;
|
|
1520
1529
|
const derivationIndex = params.derivationIndex ?? 0;
|
|
1530
|
+
const methodName = this.getRpcMethodName(networkIdParam, includeSubmissionConfig);
|
|
1521
1531
|
try {
|
|
1522
1532
|
if (!this.config.organizationId) {
|
|
1523
1533
|
throw new Error("organizationId is required to sign a transaction");
|
|
@@ -1539,7 +1549,8 @@ var PhantomClient = class {
|
|
|
1539
1549
|
encodedTransaction,
|
|
1540
1550
|
networkId: networkIdParam,
|
|
1541
1551
|
submissionConfig,
|
|
1542
|
-
account: params.account
|
|
1552
|
+
account: params.account,
|
|
1553
|
+
methodName
|
|
1543
1554
|
});
|
|
1544
1555
|
const signRequest = {
|
|
1545
1556
|
organizationId: this.config.organizationId,
|
|
@@ -1560,7 +1571,11 @@ var PhantomClient = class {
|
|
|
1560
1571
|
params: signRequest,
|
|
1561
1572
|
timestampMs: await getSecureTimestamp()
|
|
1562
1573
|
};
|
|
1563
|
-
const response = await this.kmsApi.postKmsRpc(request
|
|
1574
|
+
const response = await this.kmsApi.postKmsRpc(request, {
|
|
1575
|
+
headers: {
|
|
1576
|
+
"X-Rpc-Method": methodName
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1564
1579
|
const result = response.data.result;
|
|
1565
1580
|
const rpcSubmissionResult = response.data["rpc_submission_result"];
|
|
1566
1581
|
const hash = includeSubmissionConfig && rpcSubmissionResult ? rpcSubmissionResult.result : null;
|
|
@@ -1986,6 +2001,129 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1986
2001
|
return method;
|
|
1987
2002
|
};
|
|
1988
2003
|
|
|
2004
|
+
// src/ethereum/siwe.ts
|
|
2005
|
+
var ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
2006
|
+
var DOMAIN_REGEX = /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/;
|
|
2007
|
+
var IP_REGEX = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/;
|
|
2008
|
+
var LOCALHOST_REGEX = /^localhost(:[0-9]{1,5})?$/;
|
|
2009
|
+
var NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
|
|
2010
|
+
var SCHEME_REGEX = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
|
|
2011
|
+
function createSiweMessage({
|
|
2012
|
+
address,
|
|
2013
|
+
chainId,
|
|
2014
|
+
domain,
|
|
2015
|
+
nonce,
|
|
2016
|
+
uri,
|
|
2017
|
+
version,
|
|
2018
|
+
scheme,
|
|
2019
|
+
statement: _statement,
|
|
2020
|
+
requestId,
|
|
2021
|
+
resources,
|
|
2022
|
+
issuedAt = /* @__PURE__ */ new Date(),
|
|
2023
|
+
expirationTime,
|
|
2024
|
+
notBefore
|
|
2025
|
+
}) {
|
|
2026
|
+
if (!ADDRESS_REGEX.test(address)) {
|
|
2027
|
+
throw new Error("address must be a hex value of 20 bytes (40 hex characters).");
|
|
2028
|
+
}
|
|
2029
|
+
if (chainId !== Math.floor(chainId)) {
|
|
2030
|
+
throw new Error("chainId must be a EIP-155 chain ID.");
|
|
2031
|
+
}
|
|
2032
|
+
if (!(DOMAIN_REGEX.test(domain) || IP_REGEX.test(domain) || LOCALHOST_REGEX.test(domain))) {
|
|
2033
|
+
throw new Error("domain must be an RFC 3986 authority.");
|
|
2034
|
+
}
|
|
2035
|
+
if (!NONCE_REGEX.test(nonce)) {
|
|
2036
|
+
throw new Error("nonce must be at least 8 characters.");
|
|
2037
|
+
}
|
|
2038
|
+
if (!_isUri(uri)) {
|
|
2039
|
+
throw new Error("uri must be a RFC 3986 URI referring to the resource that is the subject of the signing.");
|
|
2040
|
+
}
|
|
2041
|
+
if (version !== "1") {
|
|
2042
|
+
throw new Error("version must be '1'.");
|
|
2043
|
+
}
|
|
2044
|
+
if (scheme && !SCHEME_REGEX.test(scheme)) {
|
|
2045
|
+
throw new Error("scheme must be an RFC 3986 URI scheme.");
|
|
2046
|
+
}
|
|
2047
|
+
if (_statement?.includes("\n")) {
|
|
2048
|
+
throw new Error("statement must not include '\\n'.");
|
|
2049
|
+
}
|
|
2050
|
+
const origin = scheme ? `${scheme}://${domain}` : domain;
|
|
2051
|
+
const statement = _statement ? `${_statement}
|
|
2052
|
+
` : "";
|
|
2053
|
+
const prefix = `${origin} wants you to sign in with your Ethereum account:
|
|
2054
|
+
${address}
|
|
2055
|
+
|
|
2056
|
+
${statement}`;
|
|
2057
|
+
let suffix = `URI: ${uri}
|
|
2058
|
+
Version: ${version}
|
|
2059
|
+
Chain ID: ${chainId}
|
|
2060
|
+
Nonce: ${nonce}
|
|
2061
|
+
Issued At: ${issuedAt.toISOString()}`;
|
|
2062
|
+
if (expirationTime) {
|
|
2063
|
+
suffix += `
|
|
2064
|
+
Expiration Time: ${expirationTime.toISOString()}`;
|
|
2065
|
+
}
|
|
2066
|
+
if (notBefore) {
|
|
2067
|
+
suffix += `
|
|
2068
|
+
Not Before: ${notBefore.toISOString()}`;
|
|
2069
|
+
}
|
|
2070
|
+
if (requestId) {
|
|
2071
|
+
suffix += `
|
|
2072
|
+
Request ID: ${requestId}`;
|
|
2073
|
+
}
|
|
2074
|
+
if (resources) {
|
|
2075
|
+
let content = "\nResources:";
|
|
2076
|
+
for (const resource of resources) {
|
|
2077
|
+
if (!_isUri(resource)) {
|
|
2078
|
+
throw new Error("resources must be RFC 3986 URIs.");
|
|
2079
|
+
}
|
|
2080
|
+
content += `
|
|
2081
|
+
- ${resource}`;
|
|
2082
|
+
}
|
|
2083
|
+
suffix += content;
|
|
2084
|
+
}
|
|
2085
|
+
return `${prefix}
|
|
2086
|
+
${suffix}`;
|
|
2087
|
+
}
|
|
2088
|
+
function _isUri(value) {
|
|
2089
|
+
if (/[^a-z0-9:/?#[\]@!$&'()*+,;=.\-_~%]/i.test(value))
|
|
2090
|
+
return false;
|
|
2091
|
+
if (/%[^0-9a-f]/i.test(value))
|
|
2092
|
+
return false;
|
|
2093
|
+
if (/%[0-9a-f](:?[^0-9a-f]|$)/i.test(value))
|
|
2094
|
+
return false;
|
|
2095
|
+
const splitted = splitUri(value);
|
|
2096
|
+
const scheme = splitted[1];
|
|
2097
|
+
const authority = splitted[2];
|
|
2098
|
+
const path = splitted[3];
|
|
2099
|
+
const query = splitted[4];
|
|
2100
|
+
const fragment = splitted[5];
|
|
2101
|
+
if (!(scheme?.length && path.length >= 0))
|
|
2102
|
+
return false;
|
|
2103
|
+
if (authority?.length) {
|
|
2104
|
+
if (!(path.length === 0 || /^\//.test(path)))
|
|
2105
|
+
return false;
|
|
2106
|
+
} else {
|
|
2107
|
+
if (/^\/\//.test(path))
|
|
2108
|
+
return false;
|
|
2109
|
+
}
|
|
2110
|
+
if (!/^[a-z][a-z0-9+\-.]*$/.test(scheme.toLowerCase()))
|
|
2111
|
+
return false;
|
|
2112
|
+
let out = "";
|
|
2113
|
+
out += `${scheme}:`;
|
|
2114
|
+
if (authority?.length)
|
|
2115
|
+
out += `//${authority}`;
|
|
2116
|
+
out += path;
|
|
2117
|
+
if (query?.length)
|
|
2118
|
+
out += `?${query}`;
|
|
2119
|
+
if (fragment?.length)
|
|
2120
|
+
out += `#${fragment}`;
|
|
2121
|
+
return out;
|
|
2122
|
+
}
|
|
2123
|
+
function splitUri(value) {
|
|
2124
|
+
return value.match(/(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
|
|
2125
|
+
}
|
|
2126
|
+
|
|
1989
2127
|
// src/ethereum/strategies/injected.ts
|
|
1990
2128
|
var MAX_RETRIES$1 = 4;
|
|
1991
2129
|
var BASE_DELAY$1 = 100;
|
|
@@ -2102,7 +2240,7 @@ var InjectedEthereumStrategy = class {
|
|
|
2102
2240
|
if (!provider) {
|
|
2103
2241
|
throw new Error("Provider not found.");
|
|
2104
2242
|
}
|
|
2105
|
-
const message =
|
|
2243
|
+
const message = createSiweMessage(signInData);
|
|
2106
2244
|
const address = provider.selectedAddress;
|
|
2107
2245
|
if (!address) {
|
|
2108
2246
|
throw new Error("No address available.");
|
|
@@ -2198,7 +2336,7 @@ function addEventListener$1(event, callback) {
|
|
|
2198
2336
|
eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
2199
2337
|
}
|
|
2200
2338
|
const listeners = eventListeners.get(event);
|
|
2201
|
-
listeners
|
|
2339
|
+
listeners?.add(callback);
|
|
2202
2340
|
return () => removeEventListener$1(event, callback);
|
|
2203
2341
|
}
|
|
2204
2342
|
function removeEventListener$1(event, callback) {
|
|
@@ -2272,16 +2410,6 @@ async function getAccounts() {
|
|
|
2272
2410
|
}
|
|
2273
2411
|
|
|
2274
2412
|
// src/ethereum/signMessage.ts
|
|
2275
|
-
async function signMessage$1(message, address) {
|
|
2276
|
-
const provider = await getProvider$2();
|
|
2277
|
-
if (!provider) {
|
|
2278
|
-
throw new Error("Provider not found.");
|
|
2279
|
-
}
|
|
2280
|
-
if (!provider.isConnected) {
|
|
2281
|
-
await provider.connect({ onlyIfTrusted: false });
|
|
2282
|
-
}
|
|
2283
|
-
return provider.signMessage(message, address);
|
|
2284
|
-
}
|
|
2285
2413
|
async function signPersonalMessage(message, address) {
|
|
2286
2414
|
const provider = await getProvider$2();
|
|
2287
2415
|
if (!provider) {
|
|
@@ -2303,18 +2431,6 @@ async function signTypedData(typedData, address) {
|
|
|
2303
2431
|
return provider.signTypedData(typedData, address);
|
|
2304
2432
|
}
|
|
2305
2433
|
|
|
2306
|
-
// src/ethereum/signIn.ts
|
|
2307
|
-
async function signIn$1(signInData) {
|
|
2308
|
-
const provider = await getProvider$2();
|
|
2309
|
-
if (!provider) {
|
|
2310
|
-
throw new Error("Provider not found.");
|
|
2311
|
-
}
|
|
2312
|
-
if (!provider.isConnected) {
|
|
2313
|
-
await provider.connect({ onlyIfTrusted: false });
|
|
2314
|
-
}
|
|
2315
|
-
return provider.signIn(signInData);
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
2434
|
// src/ethereum/sendTransaction.ts
|
|
2319
2435
|
async function sendTransaction(transaction) {
|
|
2320
2436
|
const provider = await getProvider$2();
|
|
@@ -2354,47 +2470,122 @@ async function switchChain(chainId) {
|
|
|
2354
2470
|
}
|
|
2355
2471
|
|
|
2356
2472
|
// src/ethereum/plugin.ts
|
|
2357
|
-
var
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2473
|
+
var Ethereum = class {
|
|
2474
|
+
constructor() {
|
|
2475
|
+
this._chainId = "0x1";
|
|
2476
|
+
this._accounts = [];
|
|
2477
|
+
this.bindProviderEvents();
|
|
2478
|
+
}
|
|
2479
|
+
get connected() {
|
|
2480
|
+
return this._accounts.length > 0;
|
|
2481
|
+
}
|
|
2482
|
+
get chainId() {
|
|
2483
|
+
return this._chainId;
|
|
2484
|
+
}
|
|
2485
|
+
get accounts() {
|
|
2486
|
+
return this._accounts;
|
|
2487
|
+
}
|
|
2488
|
+
async request(args) {
|
|
2489
|
+
const provider = await getProvider$2();
|
|
2490
|
+
if (!provider) {
|
|
2491
|
+
throw new Error("Provider not found.");
|
|
2492
|
+
}
|
|
2493
|
+
const providerInstance = provider.getProvider();
|
|
2494
|
+
if (!providerInstance) {
|
|
2495
|
+
throw new Error("Provider instance not found.");
|
|
2496
|
+
}
|
|
2497
|
+
return providerInstance.request(args);
|
|
2498
|
+
}
|
|
2499
|
+
async connect() {
|
|
2500
|
+
const accounts = await connect$1();
|
|
2501
|
+
this._accounts = accounts;
|
|
2502
|
+
return accounts;
|
|
2503
|
+
}
|
|
2504
|
+
async disconnect() {
|
|
2505
|
+
await disconnect$1();
|
|
2506
|
+
this._accounts = [];
|
|
2507
|
+
}
|
|
2508
|
+
signPersonalMessage(message, address) {
|
|
2509
|
+
return signPersonalMessage(message, address);
|
|
2510
|
+
}
|
|
2511
|
+
signTypedData(data, address) {
|
|
2512
|
+
return signTypedData(data, address);
|
|
2513
|
+
}
|
|
2514
|
+
signTransaction(transaction) {
|
|
2515
|
+
return signTransaction$1(transaction);
|
|
2516
|
+
}
|
|
2517
|
+
sendTransaction(transaction) {
|
|
2518
|
+
return sendTransaction(transaction);
|
|
2519
|
+
}
|
|
2520
|
+
async switchChain(chainId) {
|
|
2521
|
+
const hexChainId = typeof chainId === "string" ? chainId.toLowerCase().startsWith("0x") ? chainId.toLowerCase() : `0x${parseInt(chainId, 10).toString(16)}` : `0x${chainId.toString(16)}`;
|
|
2522
|
+
await switchChain(hexChainId);
|
|
2523
|
+
this._chainId = hexChainId;
|
|
2524
|
+
}
|
|
2525
|
+
async getChainId() {
|
|
2526
|
+
const chainId = await getChainId();
|
|
2527
|
+
const parsed = parseInt(chainId, 16);
|
|
2528
|
+
this._chainId = chainId;
|
|
2529
|
+
return parsed;
|
|
2530
|
+
}
|
|
2531
|
+
async getAccounts() {
|
|
2532
|
+
const accounts = await getAccounts();
|
|
2533
|
+
this._accounts = accounts;
|
|
2534
|
+
return accounts;
|
|
2535
|
+
}
|
|
2536
|
+
isConnected() {
|
|
2537
|
+
return this._accounts.length > 0;
|
|
2538
|
+
}
|
|
2539
|
+
on(event, listener) {
|
|
2540
|
+
addEventListener$1(event, listener);
|
|
2541
|
+
}
|
|
2542
|
+
off(event, listener) {
|
|
2543
|
+
removeEventListener$1(event, listener);
|
|
2544
|
+
}
|
|
2545
|
+
async bindProviderEvents() {
|
|
2546
|
+
try {
|
|
2547
|
+
const strategy = await getProvider$2();
|
|
2548
|
+
const provider = strategy.getProvider();
|
|
2549
|
+
if (provider) {
|
|
2550
|
+
provider.on("connect", async () => {
|
|
2551
|
+
try {
|
|
2552
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
2553
|
+
if (accounts?.length > 0) {
|
|
2554
|
+
this._accounts = accounts;
|
|
2555
|
+
triggerEvent$1("connect", accounts);
|
|
2556
|
+
}
|
|
2557
|
+
} catch {
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
provider.on("disconnect", () => {
|
|
2561
|
+
this._accounts = [];
|
|
2562
|
+
const error = {
|
|
2563
|
+
code: 4900,
|
|
2564
|
+
message: "Provider disconnected"
|
|
2565
|
+
};
|
|
2566
|
+
triggerEvent$1("disconnect", error);
|
|
2567
|
+
});
|
|
2568
|
+
provider.on("accountsChanged", (accounts) => {
|
|
2569
|
+
this._accounts = accounts;
|
|
2570
|
+
triggerEvent$1("accountsChanged", accounts);
|
|
2571
|
+
if (accounts && accounts.length > 0) {
|
|
2381
2572
|
triggerEvent$1("connect", accounts);
|
|
2382
|
-
|
|
2573
|
+
}
|
|
2383
2574
|
});
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2575
|
+
provider.on("chainChanged", (chainId) => {
|
|
2576
|
+
this._chainId = chainId;
|
|
2577
|
+
triggerEvent$1("chainChanged", chainId);
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2580
|
+
} catch (error) {
|
|
2388
2581
|
}
|
|
2389
|
-
} catch (error) {
|
|
2390
2582
|
}
|
|
2391
|
-
}
|
|
2583
|
+
};
|
|
2392
2584
|
function createEthereumPlugin() {
|
|
2393
2585
|
return {
|
|
2394
2586
|
name: "ethereum",
|
|
2395
2587
|
create: () => {
|
|
2396
|
-
|
|
2397
|
-
return ethereum;
|
|
2588
|
+
return new Ethereum();
|
|
2398
2589
|
}
|
|
2399
2590
|
};
|
|
2400
2591
|
}
|
|
@@ -2604,28 +2795,26 @@ function addEventListener(event, callback) {
|
|
|
2604
2795
|
if (!eventCallbacks.has(event)) {
|
|
2605
2796
|
eventCallbacks.set(event, /* @__PURE__ */ new Set());
|
|
2606
2797
|
}
|
|
2607
|
-
eventCallbacks.get(event)
|
|
2798
|
+
eventCallbacks.get(event)?.add(callback);
|
|
2608
2799
|
return () => {
|
|
2609
2800
|
removeEventListener(event, callback);
|
|
2610
2801
|
};
|
|
2611
2802
|
}
|
|
2612
2803
|
function removeEventListener(event, callback) {
|
|
2613
2804
|
if (eventCallbacks.has(event)) {
|
|
2614
|
-
eventCallbacks.get(event)
|
|
2615
|
-
if (eventCallbacks.get(event)
|
|
2805
|
+
eventCallbacks.get(event)?.delete(callback);
|
|
2806
|
+
if (eventCallbacks.get(event)?.size === 0) {
|
|
2616
2807
|
eventCallbacks.delete(event);
|
|
2617
2808
|
}
|
|
2618
2809
|
}
|
|
2619
2810
|
}
|
|
2620
2811
|
function triggerEvent(event, ...args) {
|
|
2621
2812
|
if (eventCallbacks.has(event)) {
|
|
2622
|
-
eventCallbacks.get(event)
|
|
2623
|
-
|
|
2624
|
-
cb(args
|
|
2625
|
-
}
|
|
2626
|
-
|
|
2627
|
-
} else if (event === "accountChanged" && args[0] && typeof args[0] === "string") {
|
|
2628
|
-
cb(args[0]);
|
|
2813
|
+
eventCallbacks.get(event)?.forEach((cb) => {
|
|
2814
|
+
try {
|
|
2815
|
+
cb(...args);
|
|
2816
|
+
} catch (error) {
|
|
2817
|
+
console.error(`Error in ${event} event listener:`, error);
|
|
2629
2818
|
}
|
|
2630
2819
|
});
|
|
2631
2820
|
}
|
|
@@ -2726,19 +2915,6 @@ async function signAllTransactions(transactions) {
|
|
|
2726
2915
|
return provider.signAllTransactions(transactions);
|
|
2727
2916
|
}
|
|
2728
2917
|
|
|
2729
|
-
// src/solana/signIn.ts
|
|
2730
|
-
async function signIn(signInData) {
|
|
2731
|
-
const provider = await getProvider$1();
|
|
2732
|
-
if (!provider) {
|
|
2733
|
-
throw new Error("Provider not found.");
|
|
2734
|
-
}
|
|
2735
|
-
const result = await provider.signIn(signInData);
|
|
2736
|
-
if (result.address) {
|
|
2737
|
-
triggerEvent("connect", result.address);
|
|
2738
|
-
}
|
|
2739
|
-
return result;
|
|
2740
|
-
}
|
|
2741
|
-
|
|
2742
2918
|
// src/solana/signMessage.ts
|
|
2743
2919
|
async function signMessage(message, display) {
|
|
2744
2920
|
const provider = await getProvider$1();
|
|
@@ -2752,43 +2928,112 @@ async function signMessage(message, display) {
|
|
|
2752
2928
|
}
|
|
2753
2929
|
|
|
2754
2930
|
// src/solana/plugin.ts
|
|
2755
|
-
var
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
const strategy = await getProvider$1();
|
|
2771
|
-
const provider = strategy.getProvider();
|
|
2772
|
-
if (provider) {
|
|
2773
|
-
provider.on("connect", (publicKey) => {
|
|
2774
|
-
if (publicKey)
|
|
2775
|
-
triggerEvent("connect", publicKey.toString());
|
|
2776
|
-
});
|
|
2777
|
-
provider.on("disconnect", () => triggerEvent("disconnect"));
|
|
2778
|
-
provider.on("accountChanged", (publicKey) => {
|
|
2779
|
-
if (publicKey)
|
|
2780
|
-
triggerEvent("accountChanged", publicKey.toString());
|
|
2781
|
-
});
|
|
2931
|
+
var Solana = class {
|
|
2932
|
+
constructor() {
|
|
2933
|
+
this._publicKey = null;
|
|
2934
|
+
this.bindProviderEvents();
|
|
2935
|
+
}
|
|
2936
|
+
get publicKey() {
|
|
2937
|
+
return this._publicKey;
|
|
2938
|
+
}
|
|
2939
|
+
get connected() {
|
|
2940
|
+
return this._publicKey !== null;
|
|
2941
|
+
}
|
|
2942
|
+
async connect(options) {
|
|
2943
|
+
const address = await connect(options);
|
|
2944
|
+
if (!address) {
|
|
2945
|
+
throw new Error("Failed to connect to Solana wallet");
|
|
2782
2946
|
}
|
|
2783
|
-
|
|
2947
|
+
this._publicKey = address;
|
|
2948
|
+
return { publicKey: address };
|
|
2784
2949
|
}
|
|
2785
|
-
|
|
2950
|
+
async disconnect() {
|
|
2951
|
+
await disconnect();
|
|
2952
|
+
this._publicKey = null;
|
|
2953
|
+
}
|
|
2954
|
+
async signMessage(message) {
|
|
2955
|
+
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
2956
|
+
const result = await signMessage(messageBytes);
|
|
2957
|
+
return {
|
|
2958
|
+
signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(result.signature),
|
|
2959
|
+
publicKey: result.address || this._publicKey || ""
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
signTransaction(transaction) {
|
|
2963
|
+
return signTransaction(transaction);
|
|
2964
|
+
}
|
|
2965
|
+
async signAndSendTransaction(transaction) {
|
|
2966
|
+
const result = await signAndSendTransaction(transaction);
|
|
2967
|
+
return { signature: result.signature };
|
|
2968
|
+
}
|
|
2969
|
+
signAllTransactions(transactions) {
|
|
2970
|
+
return signAllTransactions(transactions);
|
|
2971
|
+
}
|
|
2972
|
+
async signAndSendAllTransactions(transactions) {
|
|
2973
|
+
const result = await signAndSendAllTransactions(transactions);
|
|
2974
|
+
return { signatures: result.signatures };
|
|
2975
|
+
}
|
|
2976
|
+
async switchNetwork(_network) {
|
|
2977
|
+
return Promise.resolve();
|
|
2978
|
+
}
|
|
2979
|
+
async getPublicKey() {
|
|
2980
|
+
if (this._publicKey) {
|
|
2981
|
+
return this._publicKey;
|
|
2982
|
+
}
|
|
2983
|
+
try {
|
|
2984
|
+
const account = await getAccount();
|
|
2985
|
+
this._publicKey = account || null;
|
|
2986
|
+
return this._publicKey;
|
|
2987
|
+
} catch {
|
|
2988
|
+
return null;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
isConnected() {
|
|
2992
|
+
return this._publicKey !== null;
|
|
2993
|
+
}
|
|
2994
|
+
on(event, listener) {
|
|
2995
|
+
addEventListener(event, listener);
|
|
2996
|
+
}
|
|
2997
|
+
off(event, listener) {
|
|
2998
|
+
removeEventListener(event, listener);
|
|
2999
|
+
}
|
|
3000
|
+
async bindProviderEvents() {
|
|
3001
|
+
try {
|
|
3002
|
+
const strategy = await getProvider$1();
|
|
3003
|
+
const provider = strategy.getProvider();
|
|
3004
|
+
if (provider) {
|
|
3005
|
+
provider.on("connect", (publicKey) => {
|
|
3006
|
+
if (publicKey) {
|
|
3007
|
+
const pubKey = publicKey.toString();
|
|
3008
|
+
this._publicKey = pubKey;
|
|
3009
|
+
triggerEvent("connect", pubKey);
|
|
3010
|
+
}
|
|
3011
|
+
});
|
|
3012
|
+
provider.on("disconnect", () => {
|
|
3013
|
+
this._publicKey = null;
|
|
3014
|
+
triggerEvent("disconnect");
|
|
3015
|
+
});
|
|
3016
|
+
provider.on("accountChanged", (publicKey) => {
|
|
3017
|
+
if (publicKey) {
|
|
3018
|
+
const pubKey = publicKey.toString();
|
|
3019
|
+
this._publicKey = pubKey;
|
|
3020
|
+
triggerEvent("accountChanged", pubKey);
|
|
3021
|
+
triggerEvent("connect", pubKey);
|
|
3022
|
+
} else {
|
|
3023
|
+
this._publicKey = null;
|
|
3024
|
+
triggerEvent("accountChanged", null);
|
|
3025
|
+
}
|
|
3026
|
+
});
|
|
3027
|
+
}
|
|
3028
|
+
} catch (error) {
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
};
|
|
2786
3032
|
function createSolanaPlugin() {
|
|
2787
3033
|
return {
|
|
2788
3034
|
name: "solana",
|
|
2789
3035
|
create: () => {
|
|
2790
|
-
|
|
2791
|
-
return solana;
|
|
3036
|
+
return new Solana();
|
|
2792
3037
|
}
|
|
2793
3038
|
};
|
|
2794
3039
|
}
|
|
@@ -2875,356 +3120,6 @@ function createAutoConfirmPlugin() {
|
|
|
2875
3120
|
};
|
|
2876
3121
|
}
|
|
2877
3122
|
|
|
2878
|
-
var eventemitter3$1 = {exports: {}};
|
|
2879
|
-
|
|
2880
|
-
var hasRequiredEventemitter3$1;
|
|
2881
|
-
|
|
2882
|
-
function requireEventemitter3$1 () {
|
|
2883
|
-
if (hasRequiredEventemitter3$1) return eventemitter3$1.exports;
|
|
2884
|
-
hasRequiredEventemitter3$1 = 1;
|
|
2885
|
-
(function (module) {
|
|
2886
|
-
|
|
2887
|
-
var has = Object.prototype.hasOwnProperty
|
|
2888
|
-
, prefix = '~';
|
|
2889
|
-
|
|
2890
|
-
/**
|
|
2891
|
-
* Constructor to create a storage for our `EE` objects.
|
|
2892
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
2893
|
-
*
|
|
2894
|
-
* @constructor
|
|
2895
|
-
* @private
|
|
2896
|
-
*/
|
|
2897
|
-
function Events() {}
|
|
2898
|
-
|
|
2899
|
-
//
|
|
2900
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
2901
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
2902
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
2903
|
-
// character to make sure that the built-in object properties are not
|
|
2904
|
-
// overridden or used as an attack vector.
|
|
2905
|
-
//
|
|
2906
|
-
if (Object.create) {
|
|
2907
|
-
Events.prototype = Object.create(null);
|
|
2908
|
-
|
|
2909
|
-
//
|
|
2910
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
2911
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
2912
|
-
//
|
|
2913
|
-
if (!new Events().__proto__) prefix = false;
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
/**
|
|
2917
|
-
* Representation of a single event listener.
|
|
2918
|
-
*
|
|
2919
|
-
* @param {Function} fn The listener function.
|
|
2920
|
-
* @param {*} context The context to invoke the listener with.
|
|
2921
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
2922
|
-
* @constructor
|
|
2923
|
-
* @private
|
|
2924
|
-
*/
|
|
2925
|
-
function EE(fn, context, once) {
|
|
2926
|
-
this.fn = fn;
|
|
2927
|
-
this.context = context;
|
|
2928
|
-
this.once = once || false;
|
|
2929
|
-
}
|
|
2930
|
-
|
|
2931
|
-
/**
|
|
2932
|
-
* Add a listener for a given event.
|
|
2933
|
-
*
|
|
2934
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
2935
|
-
* @param {(String|Symbol)} event The event name.
|
|
2936
|
-
* @param {Function} fn The listener function.
|
|
2937
|
-
* @param {*} context The context to invoke the listener with.
|
|
2938
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
2939
|
-
* @returns {EventEmitter}
|
|
2940
|
-
* @private
|
|
2941
|
-
*/
|
|
2942
|
-
function addListener(emitter, event, fn, context, once) {
|
|
2943
|
-
if (typeof fn !== 'function') {
|
|
2944
|
-
throw new TypeError('The listener must be a function');
|
|
2945
|
-
}
|
|
2946
|
-
|
|
2947
|
-
var listener = new EE(fn, context || emitter, once)
|
|
2948
|
-
, evt = prefix ? prefix + event : event;
|
|
2949
|
-
|
|
2950
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
2951
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
2952
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
2953
|
-
|
|
2954
|
-
return emitter;
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
/**
|
|
2958
|
-
* Clear event by name.
|
|
2959
|
-
*
|
|
2960
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
2961
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
2962
|
-
* @private
|
|
2963
|
-
*/
|
|
2964
|
-
function clearEvent(emitter, evt) {
|
|
2965
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
2966
|
-
else delete emitter._events[evt];
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
|
-
/**
|
|
2970
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
2971
|
-
* `EventEmitter` interface.
|
|
2972
|
-
*
|
|
2973
|
-
* @constructor
|
|
2974
|
-
* @public
|
|
2975
|
-
*/
|
|
2976
|
-
function EventEmitter() {
|
|
2977
|
-
this._events = new Events();
|
|
2978
|
-
this._eventsCount = 0;
|
|
2979
|
-
}
|
|
2980
|
-
|
|
2981
|
-
/**
|
|
2982
|
-
* Return an array listing the events for which the emitter has registered
|
|
2983
|
-
* listeners.
|
|
2984
|
-
*
|
|
2985
|
-
* @returns {Array}
|
|
2986
|
-
* @public
|
|
2987
|
-
*/
|
|
2988
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
2989
|
-
var names = []
|
|
2990
|
-
, events
|
|
2991
|
-
, name;
|
|
2992
|
-
|
|
2993
|
-
if (this._eventsCount === 0) return names;
|
|
2994
|
-
|
|
2995
|
-
for (name in (events = this._events)) {
|
|
2996
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
2997
|
-
}
|
|
2998
|
-
|
|
2999
|
-
if (Object.getOwnPropertySymbols) {
|
|
3000
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
3001
|
-
}
|
|
3002
|
-
|
|
3003
|
-
return names;
|
|
3004
|
-
};
|
|
3005
|
-
|
|
3006
|
-
/**
|
|
3007
|
-
* Return the listeners registered for a given event.
|
|
3008
|
-
*
|
|
3009
|
-
* @param {(String|Symbol)} event The event name.
|
|
3010
|
-
* @returns {Array} The registered listeners.
|
|
3011
|
-
* @public
|
|
3012
|
-
*/
|
|
3013
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
3014
|
-
var evt = prefix ? prefix + event : event
|
|
3015
|
-
, handlers = this._events[evt];
|
|
3016
|
-
|
|
3017
|
-
if (!handlers) return [];
|
|
3018
|
-
if (handlers.fn) return [handlers.fn];
|
|
3019
|
-
|
|
3020
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
3021
|
-
ee[i] = handlers[i].fn;
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
return ee;
|
|
3025
|
-
};
|
|
3026
|
-
|
|
3027
|
-
/**
|
|
3028
|
-
* Return the number of listeners listening to a given event.
|
|
3029
|
-
*
|
|
3030
|
-
* @param {(String|Symbol)} event The event name.
|
|
3031
|
-
* @returns {Number} The number of listeners.
|
|
3032
|
-
* @public
|
|
3033
|
-
*/
|
|
3034
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
3035
|
-
var evt = prefix ? prefix + event : event
|
|
3036
|
-
, listeners = this._events[evt];
|
|
3037
|
-
|
|
3038
|
-
if (!listeners) return 0;
|
|
3039
|
-
if (listeners.fn) return 1;
|
|
3040
|
-
return listeners.length;
|
|
3041
|
-
};
|
|
3042
|
-
|
|
3043
|
-
/**
|
|
3044
|
-
* Calls each of the listeners registered for a given event.
|
|
3045
|
-
*
|
|
3046
|
-
* @param {(String|Symbol)} event The event name.
|
|
3047
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
3048
|
-
* @public
|
|
3049
|
-
*/
|
|
3050
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
3051
|
-
var evt = prefix ? prefix + event : event;
|
|
3052
|
-
|
|
3053
|
-
if (!this._events[evt]) return false;
|
|
3054
|
-
|
|
3055
|
-
var listeners = this._events[evt]
|
|
3056
|
-
, len = arguments.length
|
|
3057
|
-
, args
|
|
3058
|
-
, i;
|
|
3059
|
-
|
|
3060
|
-
if (listeners.fn) {
|
|
3061
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
3062
|
-
|
|
3063
|
-
switch (len) {
|
|
3064
|
-
case 1: return listeners.fn.call(listeners.context), true;
|
|
3065
|
-
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
3066
|
-
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
3067
|
-
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
3068
|
-
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
3069
|
-
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
3070
|
-
}
|
|
3071
|
-
|
|
3072
|
-
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
3073
|
-
args[i - 1] = arguments[i];
|
|
3074
|
-
}
|
|
3075
|
-
|
|
3076
|
-
listeners.fn.apply(listeners.context, args);
|
|
3077
|
-
} else {
|
|
3078
|
-
var length = listeners.length
|
|
3079
|
-
, j;
|
|
3080
|
-
|
|
3081
|
-
for (i = 0; i < length; i++) {
|
|
3082
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
3083
|
-
|
|
3084
|
-
switch (len) {
|
|
3085
|
-
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
3086
|
-
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
3087
|
-
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
3088
|
-
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
3089
|
-
default:
|
|
3090
|
-
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
3091
|
-
args[j - 1] = arguments[j];
|
|
3092
|
-
}
|
|
3093
|
-
|
|
3094
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
3095
|
-
}
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
|
|
3099
|
-
return true;
|
|
3100
|
-
};
|
|
3101
|
-
|
|
3102
|
-
/**
|
|
3103
|
-
* Add a listener for a given event.
|
|
3104
|
-
*
|
|
3105
|
-
* @param {(String|Symbol)} event The event name.
|
|
3106
|
-
* @param {Function} fn The listener function.
|
|
3107
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
3108
|
-
* @returns {EventEmitter} `this`.
|
|
3109
|
-
* @public
|
|
3110
|
-
*/
|
|
3111
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
3112
|
-
return addListener(this, event, fn, context, false);
|
|
3113
|
-
};
|
|
3114
|
-
|
|
3115
|
-
/**
|
|
3116
|
-
* Add a one-time listener for a given event.
|
|
3117
|
-
*
|
|
3118
|
-
* @param {(String|Symbol)} event The event name.
|
|
3119
|
-
* @param {Function} fn The listener function.
|
|
3120
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
3121
|
-
* @returns {EventEmitter} `this`.
|
|
3122
|
-
* @public
|
|
3123
|
-
*/
|
|
3124
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
3125
|
-
return addListener(this, event, fn, context, true);
|
|
3126
|
-
};
|
|
3127
|
-
|
|
3128
|
-
/**
|
|
3129
|
-
* Remove the listeners of a given event.
|
|
3130
|
-
*
|
|
3131
|
-
* @param {(String|Symbol)} event The event name.
|
|
3132
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
3133
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
3134
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
3135
|
-
* @returns {EventEmitter} `this`.
|
|
3136
|
-
* @public
|
|
3137
|
-
*/
|
|
3138
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
3139
|
-
var evt = prefix ? prefix + event : event;
|
|
3140
|
-
|
|
3141
|
-
if (!this._events[evt]) return this;
|
|
3142
|
-
if (!fn) {
|
|
3143
|
-
clearEvent(this, evt);
|
|
3144
|
-
return this;
|
|
3145
|
-
}
|
|
3146
|
-
|
|
3147
|
-
var listeners = this._events[evt];
|
|
3148
|
-
|
|
3149
|
-
if (listeners.fn) {
|
|
3150
|
-
if (
|
|
3151
|
-
listeners.fn === fn &&
|
|
3152
|
-
(!once || listeners.once) &&
|
|
3153
|
-
(!context || listeners.context === context)
|
|
3154
|
-
) {
|
|
3155
|
-
clearEvent(this, evt);
|
|
3156
|
-
}
|
|
3157
|
-
} else {
|
|
3158
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
3159
|
-
if (
|
|
3160
|
-
listeners[i].fn !== fn ||
|
|
3161
|
-
(once && !listeners[i].once) ||
|
|
3162
|
-
(context && listeners[i].context !== context)
|
|
3163
|
-
) {
|
|
3164
|
-
events.push(listeners[i]);
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3168
|
-
//
|
|
3169
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
3170
|
-
//
|
|
3171
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
3172
|
-
else clearEvent(this, evt);
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
return this;
|
|
3176
|
-
};
|
|
3177
|
-
|
|
3178
|
-
/**
|
|
3179
|
-
* Remove all listeners, or those of the specified event.
|
|
3180
|
-
*
|
|
3181
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
3182
|
-
* @returns {EventEmitter} `this`.
|
|
3183
|
-
* @public
|
|
3184
|
-
*/
|
|
3185
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
3186
|
-
var evt;
|
|
3187
|
-
|
|
3188
|
-
if (event) {
|
|
3189
|
-
evt = prefix ? prefix + event : event;
|
|
3190
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
3191
|
-
} else {
|
|
3192
|
-
this._events = new Events();
|
|
3193
|
-
this._eventsCount = 0;
|
|
3194
|
-
}
|
|
3195
|
-
|
|
3196
|
-
return this;
|
|
3197
|
-
};
|
|
3198
|
-
|
|
3199
|
-
//
|
|
3200
|
-
// Alias methods names because people roll like that.
|
|
3201
|
-
//
|
|
3202
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
3203
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
3204
|
-
|
|
3205
|
-
//
|
|
3206
|
-
// Expose the prefix.
|
|
3207
|
-
//
|
|
3208
|
-
EventEmitter.prefixed = prefix;
|
|
3209
|
-
|
|
3210
|
-
//
|
|
3211
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
3212
|
-
//
|
|
3213
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
3214
|
-
|
|
3215
|
-
//
|
|
3216
|
-
// Expose the module.
|
|
3217
|
-
//
|
|
3218
|
-
{
|
|
3219
|
-
module.exports = EventEmitter;
|
|
3220
|
-
}
|
|
3221
|
-
} (eventemitter3$1));
|
|
3222
|
-
return eventemitter3$1.exports;
|
|
3223
|
-
}
|
|
3224
|
-
|
|
3225
|
-
var eventemitter3Exports$1 = requireEventemitter3$1();
|
|
3226
|
-
var EventEmitter4 = /*@__PURE__*/index.getDefaultExportFromCjs(eventemitter3Exports$1);
|
|
3227
|
-
|
|
3228
3123
|
// src/index.ts
|
|
3229
3124
|
var isBrowser = typeof window !== "undefined" && typeof window.btoa !== "undefined";
|
|
3230
3125
|
function base64urlEncode(data) {
|
|
@@ -8388,133 +8283,6 @@ class Transaction {
|
|
|
8388
8283
|
}
|
|
8389
8284
|
}
|
|
8390
8285
|
|
|
8391
|
-
// base-x encoding / decoding
|
|
8392
|
-
// Copyright (c) 2018 base-x contributors
|
|
8393
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
8394
|
-
// Distributed under the MIT software license, see the accompanying
|
|
8395
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
8396
|
-
function base$3 (ALPHABET) {
|
|
8397
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
8398
|
-
const BASE_MAP = new Uint8Array(256);
|
|
8399
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
8400
|
-
BASE_MAP[j] = 255;
|
|
8401
|
-
}
|
|
8402
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
8403
|
-
const x = ALPHABET.charAt(i);
|
|
8404
|
-
const xc = x.charCodeAt(0);
|
|
8405
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
8406
|
-
BASE_MAP[xc] = i;
|
|
8407
|
-
}
|
|
8408
|
-
const BASE = ALPHABET.length;
|
|
8409
|
-
const LEADER = ALPHABET.charAt(0);
|
|
8410
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
8411
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
8412
|
-
function encode (source) {
|
|
8413
|
-
// eslint-disable-next-line no-empty
|
|
8414
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
8415
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
8416
|
-
} else if (Array.isArray(source)) {
|
|
8417
|
-
source = Uint8Array.from(source);
|
|
8418
|
-
}
|
|
8419
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
8420
|
-
if (source.length === 0) { return '' }
|
|
8421
|
-
// Skip & count leading zeroes.
|
|
8422
|
-
let zeroes = 0;
|
|
8423
|
-
let length = 0;
|
|
8424
|
-
let pbegin = 0;
|
|
8425
|
-
const pend = source.length;
|
|
8426
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
8427
|
-
pbegin++;
|
|
8428
|
-
zeroes++;
|
|
8429
|
-
}
|
|
8430
|
-
// Allocate enough space in big-endian base58 representation.
|
|
8431
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
8432
|
-
const b58 = new Uint8Array(size);
|
|
8433
|
-
// Process the bytes.
|
|
8434
|
-
while (pbegin !== pend) {
|
|
8435
|
-
let carry = source[pbegin];
|
|
8436
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
8437
|
-
let i = 0;
|
|
8438
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
8439
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
8440
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
8441
|
-
carry = (carry / BASE) >>> 0;
|
|
8442
|
-
}
|
|
8443
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8444
|
-
length = i;
|
|
8445
|
-
pbegin++;
|
|
8446
|
-
}
|
|
8447
|
-
// Skip leading zeroes in base58 result.
|
|
8448
|
-
let it2 = size - length;
|
|
8449
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
8450
|
-
it2++;
|
|
8451
|
-
}
|
|
8452
|
-
// Translate the result into a string.
|
|
8453
|
-
let str = LEADER.repeat(zeroes);
|
|
8454
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
8455
|
-
return str
|
|
8456
|
-
}
|
|
8457
|
-
function decodeUnsafe (source) {
|
|
8458
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
8459
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
8460
|
-
let psz = 0;
|
|
8461
|
-
// Skip and count leading '1's.
|
|
8462
|
-
let zeroes = 0;
|
|
8463
|
-
let length = 0;
|
|
8464
|
-
while (source[psz] === LEADER) {
|
|
8465
|
-
zeroes++;
|
|
8466
|
-
psz++;
|
|
8467
|
-
}
|
|
8468
|
-
// Allocate enough space in big-endian base256 representation.
|
|
8469
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
8470
|
-
const b256 = new Uint8Array(size);
|
|
8471
|
-
// Process the characters.
|
|
8472
|
-
while (psz < source.length) {
|
|
8473
|
-
// Find code of next character
|
|
8474
|
-
const charCode = source.charCodeAt(psz);
|
|
8475
|
-
// Base map can not be indexed using char code
|
|
8476
|
-
if (charCode > 255) { return }
|
|
8477
|
-
// Decode character
|
|
8478
|
-
let carry = BASE_MAP[charCode];
|
|
8479
|
-
// Invalid character
|
|
8480
|
-
if (carry === 255) { return }
|
|
8481
|
-
let i = 0;
|
|
8482
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
8483
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
8484
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
8485
|
-
carry = (carry / 256) >>> 0;
|
|
8486
|
-
}
|
|
8487
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8488
|
-
length = i;
|
|
8489
|
-
psz++;
|
|
8490
|
-
}
|
|
8491
|
-
// Skip leading zeroes in b256.
|
|
8492
|
-
let it4 = size - length;
|
|
8493
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
8494
|
-
it4++;
|
|
8495
|
-
}
|
|
8496
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
8497
|
-
let j = zeroes;
|
|
8498
|
-
while (it4 !== size) {
|
|
8499
|
-
vch[j++] = b256[it4++];
|
|
8500
|
-
}
|
|
8501
|
-
return vch
|
|
8502
|
-
}
|
|
8503
|
-
function decode (string) {
|
|
8504
|
-
const buffer = decodeUnsafe(string);
|
|
8505
|
-
if (buffer) { return buffer }
|
|
8506
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
8507
|
-
}
|
|
8508
|
-
return {
|
|
8509
|
-
encode,
|
|
8510
|
-
decodeUnsafe,
|
|
8511
|
-
decode
|
|
8512
|
-
}
|
|
8513
|
-
}
|
|
8514
|
-
|
|
8515
|
-
var ALPHABET$3 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
8516
|
-
var bs58$2 = base$3(ALPHABET$3);
|
|
8517
|
-
|
|
8518
8286
|
// src/index.ts
|
|
8519
8287
|
function parseSignMessageResponse(base64Response, networkId) {
|
|
8520
8288
|
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
@@ -8561,7 +8329,7 @@ function parseTransactionResponse(base64RawTransaction, networkId, hash) {
|
|
|
8561
8329
|
function parseSolanaSignatureResponse(base64Response) {
|
|
8562
8330
|
try {
|
|
8563
8331
|
const signatureBytes = base64urlDecode(base64Response);
|
|
8564
|
-
const signature = bs58
|
|
8332
|
+
const signature = index.bs58.encode(signatureBytes);
|
|
8565
8333
|
return {
|
|
8566
8334
|
signature,
|
|
8567
8335
|
rawSignature: base64Response
|
|
@@ -8801,610 +8569,6 @@ function parseBitcoinTransactionToBase64Url(transaction) {
|
|
|
8801
8569
|
throw new Error("Unsupported Bitcoin transaction format");
|
|
8802
8570
|
}
|
|
8803
8571
|
|
|
8804
|
-
// base-x encoding / decoding
|
|
8805
|
-
// Copyright (c) 2018 base-x contributors
|
|
8806
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
8807
|
-
// Distributed under the MIT software license, see the accompanying
|
|
8808
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
8809
|
-
function base$2 (ALPHABET) {
|
|
8810
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
8811
|
-
const BASE_MAP = new Uint8Array(256);
|
|
8812
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
8813
|
-
BASE_MAP[j] = 255;
|
|
8814
|
-
}
|
|
8815
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
8816
|
-
const x = ALPHABET.charAt(i);
|
|
8817
|
-
const xc = x.charCodeAt(0);
|
|
8818
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
8819
|
-
BASE_MAP[xc] = i;
|
|
8820
|
-
}
|
|
8821
|
-
const BASE = ALPHABET.length;
|
|
8822
|
-
const LEADER = ALPHABET.charAt(0);
|
|
8823
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
8824
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
8825
|
-
function encode (source) {
|
|
8826
|
-
// eslint-disable-next-line no-empty
|
|
8827
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
8828
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
8829
|
-
} else if (Array.isArray(source)) {
|
|
8830
|
-
source = Uint8Array.from(source);
|
|
8831
|
-
}
|
|
8832
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
8833
|
-
if (source.length === 0) { return '' }
|
|
8834
|
-
// Skip & count leading zeroes.
|
|
8835
|
-
let zeroes = 0;
|
|
8836
|
-
let length = 0;
|
|
8837
|
-
let pbegin = 0;
|
|
8838
|
-
const pend = source.length;
|
|
8839
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
8840
|
-
pbegin++;
|
|
8841
|
-
zeroes++;
|
|
8842
|
-
}
|
|
8843
|
-
// Allocate enough space in big-endian base58 representation.
|
|
8844
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
8845
|
-
const b58 = new Uint8Array(size);
|
|
8846
|
-
// Process the bytes.
|
|
8847
|
-
while (pbegin !== pend) {
|
|
8848
|
-
let carry = source[pbegin];
|
|
8849
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
8850
|
-
let i = 0;
|
|
8851
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
8852
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
8853
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
8854
|
-
carry = (carry / BASE) >>> 0;
|
|
8855
|
-
}
|
|
8856
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8857
|
-
length = i;
|
|
8858
|
-
pbegin++;
|
|
8859
|
-
}
|
|
8860
|
-
// Skip leading zeroes in base58 result.
|
|
8861
|
-
let it2 = size - length;
|
|
8862
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
8863
|
-
it2++;
|
|
8864
|
-
}
|
|
8865
|
-
// Translate the result into a string.
|
|
8866
|
-
let str = LEADER.repeat(zeroes);
|
|
8867
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
8868
|
-
return str
|
|
8869
|
-
}
|
|
8870
|
-
function decodeUnsafe (source) {
|
|
8871
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
8872
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
8873
|
-
let psz = 0;
|
|
8874
|
-
// Skip and count leading '1's.
|
|
8875
|
-
let zeroes = 0;
|
|
8876
|
-
let length = 0;
|
|
8877
|
-
while (source[psz] === LEADER) {
|
|
8878
|
-
zeroes++;
|
|
8879
|
-
psz++;
|
|
8880
|
-
}
|
|
8881
|
-
// Allocate enough space in big-endian base256 representation.
|
|
8882
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
8883
|
-
const b256 = new Uint8Array(size);
|
|
8884
|
-
// Process the characters.
|
|
8885
|
-
while (psz < source.length) {
|
|
8886
|
-
// Find code of next character
|
|
8887
|
-
const charCode = source.charCodeAt(psz);
|
|
8888
|
-
// Base map can not be indexed using char code
|
|
8889
|
-
if (charCode > 255) { return }
|
|
8890
|
-
// Decode character
|
|
8891
|
-
let carry = BASE_MAP[charCode];
|
|
8892
|
-
// Invalid character
|
|
8893
|
-
if (carry === 255) { return }
|
|
8894
|
-
let i = 0;
|
|
8895
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
8896
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
8897
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
8898
|
-
carry = (carry / 256) >>> 0;
|
|
8899
|
-
}
|
|
8900
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8901
|
-
length = i;
|
|
8902
|
-
psz++;
|
|
8903
|
-
}
|
|
8904
|
-
// Skip leading zeroes in b256.
|
|
8905
|
-
let it4 = size - length;
|
|
8906
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
8907
|
-
it4++;
|
|
8908
|
-
}
|
|
8909
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
8910
|
-
let j = zeroes;
|
|
8911
|
-
while (it4 !== size) {
|
|
8912
|
-
vch[j++] = b256[it4++];
|
|
8913
|
-
}
|
|
8914
|
-
return vch
|
|
8915
|
-
}
|
|
8916
|
-
function decode (string) {
|
|
8917
|
-
const buffer = decodeUnsafe(string);
|
|
8918
|
-
if (buffer) { return buffer }
|
|
8919
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
8920
|
-
}
|
|
8921
|
-
return {
|
|
8922
|
-
encode,
|
|
8923
|
-
decodeUnsafe,
|
|
8924
|
-
decode
|
|
8925
|
-
}
|
|
8926
|
-
}
|
|
8927
|
-
|
|
8928
|
-
var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
8929
|
-
var bs58$1 = base$2(ALPHABET$2);
|
|
8930
|
-
|
|
8931
|
-
// base-x encoding / decoding
|
|
8932
|
-
// Copyright (c) 2018 base-x contributors
|
|
8933
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
8934
|
-
// Distributed under the MIT software license, see the accompanying
|
|
8935
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
8936
|
-
function base$1 (ALPHABET) {
|
|
8937
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
8938
|
-
const BASE_MAP = new Uint8Array(256);
|
|
8939
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
8940
|
-
BASE_MAP[j] = 255;
|
|
8941
|
-
}
|
|
8942
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
8943
|
-
const x = ALPHABET.charAt(i);
|
|
8944
|
-
const xc = x.charCodeAt(0);
|
|
8945
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
8946
|
-
BASE_MAP[xc] = i;
|
|
8947
|
-
}
|
|
8948
|
-
const BASE = ALPHABET.length;
|
|
8949
|
-
const LEADER = ALPHABET.charAt(0);
|
|
8950
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
8951
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
8952
|
-
function encode (source) {
|
|
8953
|
-
// eslint-disable-next-line no-empty
|
|
8954
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
8955
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
8956
|
-
} else if (Array.isArray(source)) {
|
|
8957
|
-
source = Uint8Array.from(source);
|
|
8958
|
-
}
|
|
8959
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
8960
|
-
if (source.length === 0) { return '' }
|
|
8961
|
-
// Skip & count leading zeroes.
|
|
8962
|
-
let zeroes = 0;
|
|
8963
|
-
let length = 0;
|
|
8964
|
-
let pbegin = 0;
|
|
8965
|
-
const pend = source.length;
|
|
8966
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
8967
|
-
pbegin++;
|
|
8968
|
-
zeroes++;
|
|
8969
|
-
}
|
|
8970
|
-
// Allocate enough space in big-endian base58 representation.
|
|
8971
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
8972
|
-
const b58 = new Uint8Array(size);
|
|
8973
|
-
// Process the bytes.
|
|
8974
|
-
while (pbegin !== pend) {
|
|
8975
|
-
let carry = source[pbegin];
|
|
8976
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
8977
|
-
let i = 0;
|
|
8978
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
8979
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
8980
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
8981
|
-
carry = (carry / BASE) >>> 0;
|
|
8982
|
-
}
|
|
8983
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
8984
|
-
length = i;
|
|
8985
|
-
pbegin++;
|
|
8986
|
-
}
|
|
8987
|
-
// Skip leading zeroes in base58 result.
|
|
8988
|
-
let it2 = size - length;
|
|
8989
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
8990
|
-
it2++;
|
|
8991
|
-
}
|
|
8992
|
-
// Translate the result into a string.
|
|
8993
|
-
let str = LEADER.repeat(zeroes);
|
|
8994
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
8995
|
-
return str
|
|
8996
|
-
}
|
|
8997
|
-
function decodeUnsafe (source) {
|
|
8998
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
8999
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
9000
|
-
let psz = 0;
|
|
9001
|
-
// Skip and count leading '1's.
|
|
9002
|
-
let zeroes = 0;
|
|
9003
|
-
let length = 0;
|
|
9004
|
-
while (source[psz] === LEADER) {
|
|
9005
|
-
zeroes++;
|
|
9006
|
-
psz++;
|
|
9007
|
-
}
|
|
9008
|
-
// Allocate enough space in big-endian base256 representation.
|
|
9009
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
9010
|
-
const b256 = new Uint8Array(size);
|
|
9011
|
-
// Process the characters.
|
|
9012
|
-
while (psz < source.length) {
|
|
9013
|
-
// Find code of next character
|
|
9014
|
-
const charCode = source.charCodeAt(psz);
|
|
9015
|
-
// Base map can not be indexed using char code
|
|
9016
|
-
if (charCode > 255) { return }
|
|
9017
|
-
// Decode character
|
|
9018
|
-
let carry = BASE_MAP[charCode];
|
|
9019
|
-
// Invalid character
|
|
9020
|
-
if (carry === 255) { return }
|
|
9021
|
-
let i = 0;
|
|
9022
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
9023
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
9024
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
9025
|
-
carry = (carry / 256) >>> 0;
|
|
9026
|
-
}
|
|
9027
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
9028
|
-
length = i;
|
|
9029
|
-
psz++;
|
|
9030
|
-
}
|
|
9031
|
-
// Skip leading zeroes in b256.
|
|
9032
|
-
let it4 = size - length;
|
|
9033
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
9034
|
-
it4++;
|
|
9035
|
-
}
|
|
9036
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
9037
|
-
let j = zeroes;
|
|
9038
|
-
while (it4 !== size) {
|
|
9039
|
-
vch[j++] = b256[it4++];
|
|
9040
|
-
}
|
|
9041
|
-
return vch
|
|
9042
|
-
}
|
|
9043
|
-
function decode (string) {
|
|
9044
|
-
const buffer = decodeUnsafe(string);
|
|
9045
|
-
if (buffer) { return buffer }
|
|
9046
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
9047
|
-
}
|
|
9048
|
-
return {
|
|
9049
|
-
encode,
|
|
9050
|
-
decodeUnsafe,
|
|
9051
|
-
decode
|
|
9052
|
-
}
|
|
9053
|
-
}
|
|
9054
|
-
|
|
9055
|
-
var ALPHABET$1 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
9056
|
-
var bs582 = base$1(ALPHABET$1);
|
|
9057
|
-
|
|
9058
|
-
var eventemitter3 = {exports: {}};
|
|
9059
|
-
|
|
9060
|
-
var hasRequiredEventemitter3;
|
|
9061
|
-
|
|
9062
|
-
function requireEventemitter3 () {
|
|
9063
|
-
if (hasRequiredEventemitter3) return eventemitter3.exports;
|
|
9064
|
-
hasRequiredEventemitter3 = 1;
|
|
9065
|
-
(function (module) {
|
|
9066
|
-
|
|
9067
|
-
var has = Object.prototype.hasOwnProperty
|
|
9068
|
-
, prefix = '~';
|
|
9069
|
-
|
|
9070
|
-
/**
|
|
9071
|
-
* Constructor to create a storage for our `EE` objects.
|
|
9072
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
9073
|
-
*
|
|
9074
|
-
* @constructor
|
|
9075
|
-
* @private
|
|
9076
|
-
*/
|
|
9077
|
-
function Events() {}
|
|
9078
|
-
|
|
9079
|
-
//
|
|
9080
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
9081
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
9082
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
9083
|
-
// character to make sure that the built-in object properties are not
|
|
9084
|
-
// overridden or used as an attack vector.
|
|
9085
|
-
//
|
|
9086
|
-
if (Object.create) {
|
|
9087
|
-
Events.prototype = Object.create(null);
|
|
9088
|
-
|
|
9089
|
-
//
|
|
9090
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
9091
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
9092
|
-
//
|
|
9093
|
-
if (!new Events().__proto__) prefix = false;
|
|
9094
|
-
}
|
|
9095
|
-
|
|
9096
|
-
/**
|
|
9097
|
-
* Representation of a single event listener.
|
|
9098
|
-
*
|
|
9099
|
-
* @param {Function} fn The listener function.
|
|
9100
|
-
* @param {*} context The context to invoke the listener with.
|
|
9101
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
9102
|
-
* @constructor
|
|
9103
|
-
* @private
|
|
9104
|
-
*/
|
|
9105
|
-
function EE(fn, context, once) {
|
|
9106
|
-
this.fn = fn;
|
|
9107
|
-
this.context = context;
|
|
9108
|
-
this.once = once || false;
|
|
9109
|
-
}
|
|
9110
|
-
|
|
9111
|
-
/**
|
|
9112
|
-
* Add a listener for a given event.
|
|
9113
|
-
*
|
|
9114
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
9115
|
-
* @param {(String|Symbol)} event The event name.
|
|
9116
|
-
* @param {Function} fn The listener function.
|
|
9117
|
-
* @param {*} context The context to invoke the listener with.
|
|
9118
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
9119
|
-
* @returns {EventEmitter}
|
|
9120
|
-
* @private
|
|
9121
|
-
*/
|
|
9122
|
-
function addListener(emitter, event, fn, context, once) {
|
|
9123
|
-
if (typeof fn !== 'function') {
|
|
9124
|
-
throw new TypeError('The listener must be a function');
|
|
9125
|
-
}
|
|
9126
|
-
|
|
9127
|
-
var listener = new EE(fn, context || emitter, once)
|
|
9128
|
-
, evt = prefix ? prefix + event : event;
|
|
9129
|
-
|
|
9130
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
9131
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
9132
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
9133
|
-
|
|
9134
|
-
return emitter;
|
|
9135
|
-
}
|
|
9136
|
-
|
|
9137
|
-
/**
|
|
9138
|
-
* Clear event by name.
|
|
9139
|
-
*
|
|
9140
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
9141
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
9142
|
-
* @private
|
|
9143
|
-
*/
|
|
9144
|
-
function clearEvent(emitter, evt) {
|
|
9145
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
9146
|
-
else delete emitter._events[evt];
|
|
9147
|
-
}
|
|
9148
|
-
|
|
9149
|
-
/**
|
|
9150
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
9151
|
-
* `EventEmitter` interface.
|
|
9152
|
-
*
|
|
9153
|
-
* @constructor
|
|
9154
|
-
* @public
|
|
9155
|
-
*/
|
|
9156
|
-
function EventEmitter() {
|
|
9157
|
-
this._events = new Events();
|
|
9158
|
-
this._eventsCount = 0;
|
|
9159
|
-
}
|
|
9160
|
-
|
|
9161
|
-
/**
|
|
9162
|
-
* Return an array listing the events for which the emitter has registered
|
|
9163
|
-
* listeners.
|
|
9164
|
-
*
|
|
9165
|
-
* @returns {Array}
|
|
9166
|
-
* @public
|
|
9167
|
-
*/
|
|
9168
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
9169
|
-
var names = []
|
|
9170
|
-
, events
|
|
9171
|
-
, name;
|
|
9172
|
-
|
|
9173
|
-
if (this._eventsCount === 0) return names;
|
|
9174
|
-
|
|
9175
|
-
for (name in (events = this._events)) {
|
|
9176
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
9177
|
-
}
|
|
9178
|
-
|
|
9179
|
-
if (Object.getOwnPropertySymbols) {
|
|
9180
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
9181
|
-
}
|
|
9182
|
-
|
|
9183
|
-
return names;
|
|
9184
|
-
};
|
|
9185
|
-
|
|
9186
|
-
/**
|
|
9187
|
-
* Return the listeners registered for a given event.
|
|
9188
|
-
*
|
|
9189
|
-
* @param {(String|Symbol)} event The event name.
|
|
9190
|
-
* @returns {Array} The registered listeners.
|
|
9191
|
-
* @public
|
|
9192
|
-
*/
|
|
9193
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
9194
|
-
var evt = prefix ? prefix + event : event
|
|
9195
|
-
, handlers = this._events[evt];
|
|
9196
|
-
|
|
9197
|
-
if (!handlers) return [];
|
|
9198
|
-
if (handlers.fn) return [handlers.fn];
|
|
9199
|
-
|
|
9200
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
9201
|
-
ee[i] = handlers[i].fn;
|
|
9202
|
-
}
|
|
9203
|
-
|
|
9204
|
-
return ee;
|
|
9205
|
-
};
|
|
9206
|
-
|
|
9207
|
-
/**
|
|
9208
|
-
* Return the number of listeners listening to a given event.
|
|
9209
|
-
*
|
|
9210
|
-
* @param {(String|Symbol)} event The event name.
|
|
9211
|
-
* @returns {Number} The number of listeners.
|
|
9212
|
-
* @public
|
|
9213
|
-
*/
|
|
9214
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
9215
|
-
var evt = prefix ? prefix + event : event
|
|
9216
|
-
, listeners = this._events[evt];
|
|
9217
|
-
|
|
9218
|
-
if (!listeners) return 0;
|
|
9219
|
-
if (listeners.fn) return 1;
|
|
9220
|
-
return listeners.length;
|
|
9221
|
-
};
|
|
9222
|
-
|
|
9223
|
-
/**
|
|
9224
|
-
* Calls each of the listeners registered for a given event.
|
|
9225
|
-
*
|
|
9226
|
-
* @param {(String|Symbol)} event The event name.
|
|
9227
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
9228
|
-
* @public
|
|
9229
|
-
*/
|
|
9230
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
9231
|
-
var evt = prefix ? prefix + event : event;
|
|
9232
|
-
|
|
9233
|
-
if (!this._events[evt]) return false;
|
|
9234
|
-
|
|
9235
|
-
var listeners = this._events[evt]
|
|
9236
|
-
, len = arguments.length
|
|
9237
|
-
, args
|
|
9238
|
-
, i;
|
|
9239
|
-
|
|
9240
|
-
if (listeners.fn) {
|
|
9241
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
9242
|
-
|
|
9243
|
-
switch (len) {
|
|
9244
|
-
case 1: return listeners.fn.call(listeners.context), true;
|
|
9245
|
-
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
9246
|
-
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
9247
|
-
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
9248
|
-
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
9249
|
-
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
9250
|
-
}
|
|
9251
|
-
|
|
9252
|
-
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
9253
|
-
args[i - 1] = arguments[i];
|
|
9254
|
-
}
|
|
9255
|
-
|
|
9256
|
-
listeners.fn.apply(listeners.context, args);
|
|
9257
|
-
} else {
|
|
9258
|
-
var length = listeners.length
|
|
9259
|
-
, j;
|
|
9260
|
-
|
|
9261
|
-
for (i = 0; i < length; i++) {
|
|
9262
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
9263
|
-
|
|
9264
|
-
switch (len) {
|
|
9265
|
-
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
9266
|
-
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
9267
|
-
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
9268
|
-
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
9269
|
-
default:
|
|
9270
|
-
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
9271
|
-
args[j - 1] = arguments[j];
|
|
9272
|
-
}
|
|
9273
|
-
|
|
9274
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
9275
|
-
}
|
|
9276
|
-
}
|
|
9277
|
-
}
|
|
9278
|
-
|
|
9279
|
-
return true;
|
|
9280
|
-
};
|
|
9281
|
-
|
|
9282
|
-
/**
|
|
9283
|
-
* Add a listener for a given event.
|
|
9284
|
-
*
|
|
9285
|
-
* @param {(String|Symbol)} event The event name.
|
|
9286
|
-
* @param {Function} fn The listener function.
|
|
9287
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
9288
|
-
* @returns {EventEmitter} `this`.
|
|
9289
|
-
* @public
|
|
9290
|
-
*/
|
|
9291
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
9292
|
-
return addListener(this, event, fn, context, false);
|
|
9293
|
-
};
|
|
9294
|
-
|
|
9295
|
-
/**
|
|
9296
|
-
* Add a one-time listener for a given event.
|
|
9297
|
-
*
|
|
9298
|
-
* @param {(String|Symbol)} event The event name.
|
|
9299
|
-
* @param {Function} fn The listener function.
|
|
9300
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
9301
|
-
* @returns {EventEmitter} `this`.
|
|
9302
|
-
* @public
|
|
9303
|
-
*/
|
|
9304
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
9305
|
-
return addListener(this, event, fn, context, true);
|
|
9306
|
-
};
|
|
9307
|
-
|
|
9308
|
-
/**
|
|
9309
|
-
* Remove the listeners of a given event.
|
|
9310
|
-
*
|
|
9311
|
-
* @param {(String|Symbol)} event The event name.
|
|
9312
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
9313
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
9314
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
9315
|
-
* @returns {EventEmitter} `this`.
|
|
9316
|
-
* @public
|
|
9317
|
-
*/
|
|
9318
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
9319
|
-
var evt = prefix ? prefix + event : event;
|
|
9320
|
-
|
|
9321
|
-
if (!this._events[evt]) return this;
|
|
9322
|
-
if (!fn) {
|
|
9323
|
-
clearEvent(this, evt);
|
|
9324
|
-
return this;
|
|
9325
|
-
}
|
|
9326
|
-
|
|
9327
|
-
var listeners = this._events[evt];
|
|
9328
|
-
|
|
9329
|
-
if (listeners.fn) {
|
|
9330
|
-
if (
|
|
9331
|
-
listeners.fn === fn &&
|
|
9332
|
-
(!once || listeners.once) &&
|
|
9333
|
-
(!context || listeners.context === context)
|
|
9334
|
-
) {
|
|
9335
|
-
clearEvent(this, evt);
|
|
9336
|
-
}
|
|
9337
|
-
} else {
|
|
9338
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
9339
|
-
if (
|
|
9340
|
-
listeners[i].fn !== fn ||
|
|
9341
|
-
(once && !listeners[i].once) ||
|
|
9342
|
-
(context && listeners[i].context !== context)
|
|
9343
|
-
) {
|
|
9344
|
-
events.push(listeners[i]);
|
|
9345
|
-
}
|
|
9346
|
-
}
|
|
9347
|
-
|
|
9348
|
-
//
|
|
9349
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
9350
|
-
//
|
|
9351
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
9352
|
-
else clearEvent(this, evt);
|
|
9353
|
-
}
|
|
9354
|
-
|
|
9355
|
-
return this;
|
|
9356
|
-
};
|
|
9357
|
-
|
|
9358
|
-
/**
|
|
9359
|
-
* Remove all listeners, or those of the specified event.
|
|
9360
|
-
*
|
|
9361
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
9362
|
-
* @returns {EventEmitter} `this`.
|
|
9363
|
-
* @public
|
|
9364
|
-
*/
|
|
9365
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
9366
|
-
var evt;
|
|
9367
|
-
|
|
9368
|
-
if (event) {
|
|
9369
|
-
evt = prefix ? prefix + event : event;
|
|
9370
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
9371
|
-
} else {
|
|
9372
|
-
this._events = new Events();
|
|
9373
|
-
this._eventsCount = 0;
|
|
9374
|
-
}
|
|
9375
|
-
|
|
9376
|
-
return this;
|
|
9377
|
-
};
|
|
9378
|
-
|
|
9379
|
-
//
|
|
9380
|
-
// Alias methods names because people roll like that.
|
|
9381
|
-
//
|
|
9382
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
9383
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
9384
|
-
|
|
9385
|
-
//
|
|
9386
|
-
// Expose the prefix.
|
|
9387
|
-
//
|
|
9388
|
-
EventEmitter.prefixed = prefix;
|
|
9389
|
-
|
|
9390
|
-
//
|
|
9391
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
9392
|
-
//
|
|
9393
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
9394
|
-
|
|
9395
|
-
//
|
|
9396
|
-
// Expose the module.
|
|
9397
|
-
//
|
|
9398
|
-
{
|
|
9399
|
-
module.exports = EventEmitter;
|
|
9400
|
-
}
|
|
9401
|
-
} (eventemitter3));
|
|
9402
|
-
return eventemitter3.exports;
|
|
9403
|
-
}
|
|
9404
|
-
|
|
9405
|
-
var eventemitter3Exports = requireEventemitter3();
|
|
9406
|
-
var EventEmitter2 = /*@__PURE__*/index.getDefaultExportFromCjs(eventemitter3Exports);
|
|
9407
|
-
|
|
9408
8572
|
// src/embedded-provider.ts
|
|
9409
8573
|
|
|
9410
8574
|
// src/constants.ts
|
|
@@ -9416,7 +8580,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9416
8580
|
this.currentNetworkId = NetworkId.SOLANA_MAINNET;
|
|
9417
8581
|
this._connected = false;
|
|
9418
8582
|
this._publicKey = null;
|
|
9419
|
-
this.eventEmitter = new
|
|
8583
|
+
this.eventEmitter = new index.EventEmitter3();
|
|
9420
8584
|
this.setupEventListeners();
|
|
9421
8585
|
this.syncInitialState();
|
|
9422
8586
|
}
|
|
@@ -9440,7 +8604,7 @@ var EmbeddedSolanaChain = class {
|
|
|
9440
8604
|
message: messageStr,
|
|
9441
8605
|
networkId: this.currentNetworkId
|
|
9442
8606
|
});
|
|
9443
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
8607
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(index.bs58.decode(result.signature)) : result.signature;
|
|
9444
8608
|
return {
|
|
9445
8609
|
signature,
|
|
9446
8610
|
publicKey: this._publicKey || ""
|
|
@@ -9546,7 +8710,7 @@ var EmbeddedEthereumChain = class {
|
|
|
9546
8710
|
this.currentNetworkId = NetworkId.ETHEREUM_MAINNET;
|
|
9547
8711
|
this._connected = false;
|
|
9548
8712
|
this._accounts = [];
|
|
9549
|
-
this.eventEmitter = new
|
|
8713
|
+
this.eventEmitter = new index.EventEmitter3();
|
|
9550
8714
|
this.setupEventListeners();
|
|
9551
8715
|
this.syncInitialState();
|
|
9552
8716
|
}
|
|
@@ -9810,7 +8974,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
9810
8974
|
if (!this.eventListeners.has(event)) {
|
|
9811
8975
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
9812
8976
|
}
|
|
9813
|
-
this.eventListeners.get(event)
|
|
8977
|
+
this.eventListeners.get(event)?.add(callback);
|
|
9814
8978
|
this.logger.log("EMBEDDED_PROVIDER", "Event listener added", { event });
|
|
9815
8979
|
}
|
|
9816
8980
|
off(event, callback) {
|
|
@@ -10123,7 +9287,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
10123
9287
|
publicKey: stamperInfo.publicKey,
|
|
10124
9288
|
platform: platformName
|
|
10125
9289
|
});
|
|
10126
|
-
const base64urlPublicKey = base64urlEncode(
|
|
9290
|
+
const base64urlPublicKey = base64urlEncode(index.bs58.decode(stamperInfo.publicKey));
|
|
10127
9291
|
const username = `user-${randomUUID()}`;
|
|
10128
9292
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
10129
9293
|
{
|
|
@@ -10701,7 +9865,8 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
10701
9865
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
10702
9866
|
organizationId: session.organizationId,
|
|
10703
9867
|
headers: {
|
|
10704
|
-
...this.platform.analyticsHeaders || {}
|
|
9868
|
+
...this.platform.analyticsHeaders || {},
|
|
9869
|
+
...session.authUserId ? { "x-auth-user-id": session.authUserId } : {}
|
|
10705
9870
|
}
|
|
10706
9871
|
},
|
|
10707
9872
|
this.stamper
|
|
@@ -10711,133 +9876,6 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
|
|
|
10711
9876
|
}
|
|
10712
9877
|
};
|
|
10713
9878
|
|
|
10714
|
-
// base-x encoding / decoding
|
|
10715
|
-
// Copyright (c) 2018 base-x contributors
|
|
10716
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
10717
|
-
// Distributed under the MIT software license, see the accompanying
|
|
10718
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
10719
|
-
function base (ALPHABET) {
|
|
10720
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
10721
|
-
const BASE_MAP = new Uint8Array(256);
|
|
10722
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
10723
|
-
BASE_MAP[j] = 255;
|
|
10724
|
-
}
|
|
10725
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
10726
|
-
const x = ALPHABET.charAt(i);
|
|
10727
|
-
const xc = x.charCodeAt(0);
|
|
10728
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
10729
|
-
BASE_MAP[xc] = i;
|
|
10730
|
-
}
|
|
10731
|
-
const BASE = ALPHABET.length;
|
|
10732
|
-
const LEADER = ALPHABET.charAt(0);
|
|
10733
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
10734
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
10735
|
-
function encode (source) {
|
|
10736
|
-
// eslint-disable-next-line no-empty
|
|
10737
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
10738
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
10739
|
-
} else if (Array.isArray(source)) {
|
|
10740
|
-
source = Uint8Array.from(source);
|
|
10741
|
-
}
|
|
10742
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
10743
|
-
if (source.length === 0) { return '' }
|
|
10744
|
-
// Skip & count leading zeroes.
|
|
10745
|
-
let zeroes = 0;
|
|
10746
|
-
let length = 0;
|
|
10747
|
-
let pbegin = 0;
|
|
10748
|
-
const pend = source.length;
|
|
10749
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
10750
|
-
pbegin++;
|
|
10751
|
-
zeroes++;
|
|
10752
|
-
}
|
|
10753
|
-
// Allocate enough space in big-endian base58 representation.
|
|
10754
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
10755
|
-
const b58 = new Uint8Array(size);
|
|
10756
|
-
// Process the bytes.
|
|
10757
|
-
while (pbegin !== pend) {
|
|
10758
|
-
let carry = source[pbegin];
|
|
10759
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
10760
|
-
let i = 0;
|
|
10761
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
10762
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
10763
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
10764
|
-
carry = (carry / BASE) >>> 0;
|
|
10765
|
-
}
|
|
10766
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
10767
|
-
length = i;
|
|
10768
|
-
pbegin++;
|
|
10769
|
-
}
|
|
10770
|
-
// Skip leading zeroes in base58 result.
|
|
10771
|
-
let it2 = size - length;
|
|
10772
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
10773
|
-
it2++;
|
|
10774
|
-
}
|
|
10775
|
-
// Translate the result into a string.
|
|
10776
|
-
let str = LEADER.repeat(zeroes);
|
|
10777
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
10778
|
-
return str
|
|
10779
|
-
}
|
|
10780
|
-
function decodeUnsafe (source) {
|
|
10781
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
10782
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
10783
|
-
let psz = 0;
|
|
10784
|
-
// Skip and count leading '1's.
|
|
10785
|
-
let zeroes = 0;
|
|
10786
|
-
let length = 0;
|
|
10787
|
-
while (source[psz] === LEADER) {
|
|
10788
|
-
zeroes++;
|
|
10789
|
-
psz++;
|
|
10790
|
-
}
|
|
10791
|
-
// Allocate enough space in big-endian base256 representation.
|
|
10792
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
10793
|
-
const b256 = new Uint8Array(size);
|
|
10794
|
-
// Process the characters.
|
|
10795
|
-
while (psz < source.length) {
|
|
10796
|
-
// Find code of next character
|
|
10797
|
-
const charCode = source.charCodeAt(psz);
|
|
10798
|
-
// Base map can not be indexed using char code
|
|
10799
|
-
if (charCode > 255) { return }
|
|
10800
|
-
// Decode character
|
|
10801
|
-
let carry = BASE_MAP[charCode];
|
|
10802
|
-
// Invalid character
|
|
10803
|
-
if (carry === 255) { return }
|
|
10804
|
-
let i = 0;
|
|
10805
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
10806
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
10807
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
10808
|
-
carry = (carry / 256) >>> 0;
|
|
10809
|
-
}
|
|
10810
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
10811
|
-
length = i;
|
|
10812
|
-
psz++;
|
|
10813
|
-
}
|
|
10814
|
-
// Skip leading zeroes in b256.
|
|
10815
|
-
let it4 = size - length;
|
|
10816
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
10817
|
-
it4++;
|
|
10818
|
-
}
|
|
10819
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
10820
|
-
let j = zeroes;
|
|
10821
|
-
while (it4 !== size) {
|
|
10822
|
-
vch[j++] = b256[it4++];
|
|
10823
|
-
}
|
|
10824
|
-
return vch
|
|
10825
|
-
}
|
|
10826
|
-
function decode (string) {
|
|
10827
|
-
const buffer = decodeUnsafe(string);
|
|
10828
|
-
if (buffer) { return buffer }
|
|
10829
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
10830
|
-
}
|
|
10831
|
-
return {
|
|
10832
|
-
encode,
|
|
10833
|
-
decodeUnsafe,
|
|
10834
|
-
decode
|
|
10835
|
-
}
|
|
10836
|
-
}
|
|
10837
|
-
|
|
10838
|
-
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
10839
|
-
var bs58 = base(ALPHABET);
|
|
10840
|
-
|
|
10841
9879
|
// src/index.ts
|
|
10842
9880
|
var IndexedDbStamper = class {
|
|
10843
9881
|
// Optional for PKI, required for OIDC
|
|
@@ -10911,14 +9949,14 @@ var IndexedDbStamper = class {
|
|
|
10911
9949
|
const salt = params.type === "OIDC" ? params.salt : this.salt;
|
|
10912
9950
|
const stampData = stampType === "PKI" ? {
|
|
10913
9951
|
// Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
|
|
10914
|
-
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
9952
|
+
publicKey: base64urlEncode(index.bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10915
9953
|
signature: signatureBase64url,
|
|
10916
9954
|
kind: "PKI",
|
|
10917
9955
|
algorithm: this.algorithm
|
|
10918
9956
|
} : {
|
|
10919
9957
|
kind: "OIDC",
|
|
10920
9958
|
idToken,
|
|
10921
|
-
publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
9959
|
+
publicKey: base64urlEncode(index.bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
|
|
10922
9960
|
salt,
|
|
10923
9961
|
algorithm: this.algorithm,
|
|
10924
9962
|
signature: signatureBase64url
|
|
@@ -11021,7 +10059,7 @@ var IndexedDbStamper = class {
|
|
|
11021
10059
|
["sign", "verify"]
|
|
11022
10060
|
);
|
|
11023
10061
|
const rawPublicKeyBuffer = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
11024
|
-
const publicKeyBase58 = bs58.encode(new Uint8Array(rawPublicKeyBuffer));
|
|
10062
|
+
const publicKeyBase58 = index.bs58.encode(new Uint8Array(rawPublicKeyBuffer));
|
|
11025
10063
|
const keyIdBuffer = await crypto.subtle.digest("SHA-256", rawPublicKeyBuffer);
|
|
11026
10064
|
const keyId = base64urlEncode(new Uint8Array(keyIdBuffer)).substring(0, 16);
|
|
11027
10065
|
const now = Date.now();
|
|
@@ -11378,7 +10416,7 @@ async function discoverSolanaWallets() {
|
|
|
11378
10416
|
return chainLower.startsWith("solana:") || chainLower === "solana";
|
|
11379
10417
|
}) || wallet.features && typeof wallet.features === "object" && Object.keys(wallet.features).some((featureKey) => {
|
|
11380
10418
|
const featureLower = featureKey.toLowerCase();
|
|
11381
|
-
return featureLower.
|
|
10419
|
+
return featureLower.startsWith("solana:");
|
|
11382
10420
|
});
|
|
11383
10421
|
if (!supportsSolana) {
|
|
11384
10422
|
const featureKeys = wallet.features ? Object.keys(wallet.features) : [];
|
|
@@ -11521,7 +10559,8 @@ async function discoverWallets(addressTypes) {
|
|
|
11521
10559
|
}
|
|
11522
10560
|
var InjectedWalletSolanaChain = class {
|
|
11523
10561
|
constructor(provider, walletId, walletName) {
|
|
11524
|
-
|
|
10562
|
+
// Expose eventEmitter for testing - allows tests to trigger events directly
|
|
10563
|
+
this.eventEmitter = new index.EventEmitter3();
|
|
11525
10564
|
this._connected = false;
|
|
11526
10565
|
this._publicKey = null;
|
|
11527
10566
|
this.provider = provider;
|
|
@@ -11749,6 +10788,7 @@ var InjectedWalletSolanaChain = class {
|
|
|
11749
10788
|
});
|
|
11750
10789
|
this.provider.on("accountChanged", (publicKey) => {
|
|
11751
10790
|
this._publicKey = publicKey;
|
|
10791
|
+
this._connected = publicKey != null && publicKey.length > 0;
|
|
11752
10792
|
this.eventEmitter.emit("accountChanged", publicKey);
|
|
11753
10793
|
});
|
|
11754
10794
|
}
|
|
@@ -11762,22 +10802,23 @@ var InjectedWalletSolanaChain = class {
|
|
|
11762
10802
|
};
|
|
11763
10803
|
var WalletStandardSolanaAdapter = class {
|
|
11764
10804
|
constructor(wallet, walletId, walletName) {
|
|
11765
|
-
this.
|
|
10805
|
+
this.eventEmitter = new index.EventEmitter3();
|
|
11766
10806
|
this._publicKey = null;
|
|
11767
10807
|
this.wallet = wallet;
|
|
11768
10808
|
this.walletId = walletId;
|
|
11769
10809
|
this.walletName = walletName;
|
|
10810
|
+
this.setupEventListeners();
|
|
11770
10811
|
}
|
|
11771
10812
|
get connected() {
|
|
11772
|
-
return this.
|
|
10813
|
+
return this._publicKey !== null;
|
|
11773
10814
|
}
|
|
11774
10815
|
get publicKey() {
|
|
11775
10816
|
return this._publicKey;
|
|
11776
10817
|
}
|
|
11777
10818
|
async connect(_options) {
|
|
11778
10819
|
try {
|
|
11779
|
-
const connectFeature = this.wallet.features
|
|
11780
|
-
if (!connectFeature
|
|
10820
|
+
const connectFeature = this.wallet.features["standard:connect"];
|
|
10821
|
+
if (!connectFeature) {
|
|
11781
10822
|
throw new Error("Wallet Standard connect feature not available");
|
|
11782
10823
|
}
|
|
11783
10824
|
const connectResult = await connectFeature.connect();
|
|
@@ -11798,14 +10839,13 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11798
10839
|
if (typeof firstAccount === "string") {
|
|
11799
10840
|
address = firstAccount;
|
|
11800
10841
|
} else if (typeof firstAccount === "object" && firstAccount !== null) {
|
|
11801
|
-
address = firstAccount.address || firstAccount.publicKey?.toString() || (firstAccount.publicKey instanceof Uint8Array ? Buffer.from(firstAccount.publicKey).toString("hex") : void 0);
|
|
10842
|
+
address = firstAccount.address || firstAccount.publicKey?.toString() || (firstAccount.publicKey instanceof Uint8Array ? index.bufferExports.Buffer.from(firstAccount.publicKey).toString("hex") : void 0);
|
|
11802
10843
|
}
|
|
11803
10844
|
if (!address) {
|
|
11804
10845
|
throw new Error(
|
|
11805
10846
|
`Could not extract address from account. Account structure: ${JSON.stringify(firstAccount, null, 2)}`
|
|
11806
10847
|
);
|
|
11807
10848
|
}
|
|
11808
|
-
this._connected = true;
|
|
11809
10849
|
this._publicKey = address;
|
|
11810
10850
|
return { publicKey: address };
|
|
11811
10851
|
} catch (error) {
|
|
@@ -11819,11 +10859,10 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11819
10859
|
}
|
|
11820
10860
|
async disconnect() {
|
|
11821
10861
|
try {
|
|
11822
|
-
const disconnectFeature = this.wallet.features
|
|
11823
|
-
if (disconnectFeature
|
|
10862
|
+
const disconnectFeature = this.wallet.features["standard:disconnect"];
|
|
10863
|
+
if (disconnectFeature) {
|
|
11824
10864
|
await disconnectFeature.disconnect();
|
|
11825
10865
|
}
|
|
11826
|
-
this._connected = false;
|
|
11827
10866
|
this._publicKey = null;
|
|
11828
10867
|
} catch (error) {
|
|
11829
10868
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana disconnect failed", {
|
|
@@ -11836,14 +10875,14 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11836
10875
|
}
|
|
11837
10876
|
async signMessage(message) {
|
|
11838
10877
|
try {
|
|
11839
|
-
const signMessageFeature = this.wallet.features
|
|
11840
|
-
if (!signMessageFeature
|
|
10878
|
+
const signMessageFeature = this.wallet.features["solana:signMessage"];
|
|
10879
|
+
if (!signMessageFeature) {
|
|
11841
10880
|
throw new Error("Wallet Standard signMessage feature not available");
|
|
11842
10881
|
}
|
|
11843
10882
|
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
11844
10883
|
const result = await signMessageFeature.signMessage({
|
|
11845
10884
|
message: messageBytes,
|
|
11846
|
-
account: this.wallet.accounts
|
|
10885
|
+
account: this.wallet.accounts[0]
|
|
11847
10886
|
});
|
|
11848
10887
|
if (!Array.isArray(result) || result.length === 0) {
|
|
11849
10888
|
throw new Error(`Expected array result from signMessage, got: ${typeof result}`);
|
|
@@ -11856,7 +10895,7 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11856
10895
|
if (signature.length === 0) {
|
|
11857
10896
|
throw new Error(`Signature is empty`);
|
|
11858
10897
|
}
|
|
11859
|
-
const publicKey = signedMessageResult.account?.address || this.wallet.accounts
|
|
10898
|
+
const publicKey = signedMessageResult.account?.address || this.wallet.accounts[0]?.address || this._publicKey || "";
|
|
11860
10899
|
return { signature, publicKey };
|
|
11861
10900
|
} catch (error) {
|
|
11862
10901
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana signMessage failed", {
|
|
@@ -11869,8 +10908,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11869
10908
|
}
|
|
11870
10909
|
async signTransaction(transaction) {
|
|
11871
10910
|
try {
|
|
11872
|
-
const signTransactionFeature = this.wallet.features
|
|
11873
|
-
if (!signTransactionFeature
|
|
10911
|
+
const signTransactionFeature = this.wallet.features["solana:signTransaction"];
|
|
10912
|
+
if (!signTransactionFeature) {
|
|
11874
10913
|
throw new Error("Wallet Standard signTransaction feature not available");
|
|
11875
10914
|
}
|
|
11876
10915
|
if (!this.wallet.accounts || this.wallet.accounts.length === 0) {
|
|
@@ -11889,7 +10928,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11889
10928
|
transactionData = firstItem.signedTransaction || firstItem.transaction;
|
|
11890
10929
|
}
|
|
11891
10930
|
} else if (results && typeof results === "object" && !Array.isArray(results)) {
|
|
11892
|
-
|
|
10931
|
+
const resultObj = results;
|
|
10932
|
+
transactionData = resultObj.transaction || resultObj.signedTransaction;
|
|
11893
10933
|
}
|
|
11894
10934
|
if (!transactionData) {
|
|
11895
10935
|
throw new Error("No transaction data found in Wallet Standard result");
|
|
@@ -11911,8 +10951,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11911
10951
|
}
|
|
11912
10952
|
async signAndSendTransaction(transaction) {
|
|
11913
10953
|
try {
|
|
11914
|
-
const signAndSendTransactionFeature = this.wallet.features
|
|
11915
|
-
if (!signAndSendTransactionFeature
|
|
10954
|
+
const signAndSendTransactionFeature = this.wallet.features["solana:signAndSendTransaction"];
|
|
10955
|
+
if (!signAndSendTransactionFeature) {
|
|
11916
10956
|
throw new Error("Wallet Standard signAndSendTransaction feature not available");
|
|
11917
10957
|
}
|
|
11918
10958
|
if (!this.wallet.accounts || this.wallet.accounts.length === 0) {
|
|
@@ -11938,7 +10978,7 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11938
10978
|
throw new Error("No signature found in signAndSendTransaction result");
|
|
11939
10979
|
}
|
|
11940
10980
|
const signatureBytes = this.parseUint8Array(signatureOutput.signature);
|
|
11941
|
-
const signature = bs58
|
|
10981
|
+
const signature = index.bs58.encode(signatureBytes);
|
|
11942
10982
|
return { signature };
|
|
11943
10983
|
} catch (error) {
|
|
11944
10984
|
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana signAndSendTransaction failed", {
|
|
@@ -11983,40 +11023,93 @@ var WalletStandardSolanaAdapter = class {
|
|
|
11983
11023
|
throw error;
|
|
11984
11024
|
}
|
|
11985
11025
|
}
|
|
11986
|
-
async switchNetwork(
|
|
11987
|
-
|
|
11988
|
-
const switchNetworkFeature = this.wallet.features?.["standard:switchNetwork"];
|
|
11989
|
-
if (switchNetworkFeature && typeof switchNetworkFeature.switchNetwork === "function") {
|
|
11990
|
-
const chainId = network === "mainnet" ? "solana:mainnet" : "solana:devnet";
|
|
11991
|
-
await switchNetworkFeature.switchNetwork({ chain: chainId });
|
|
11992
|
-
}
|
|
11993
|
-
} catch (error) {
|
|
11994
|
-
debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana switchNetwork failed", {
|
|
11995
|
-
walletId: this.walletId,
|
|
11996
|
-
walletName: this.walletName,
|
|
11997
|
-
network,
|
|
11998
|
-
error: error instanceof Error ? error.message : String(error)
|
|
11999
|
-
});
|
|
12000
|
-
throw error;
|
|
12001
|
-
}
|
|
11026
|
+
async switchNetwork(_network) {
|
|
11027
|
+
return Promise.resolve();
|
|
12002
11028
|
}
|
|
12003
11029
|
getPublicKey() {
|
|
12004
11030
|
return Promise.resolve(this._publicKey);
|
|
12005
11031
|
}
|
|
12006
11032
|
isConnected() {
|
|
12007
|
-
return this.
|
|
11033
|
+
return this._publicKey !== null;
|
|
12008
11034
|
}
|
|
12009
|
-
|
|
12010
|
-
|
|
12011
|
-
|
|
12012
|
-
|
|
11035
|
+
/**
|
|
11036
|
+
* Set up event listeners for Wallet Standard events
|
|
11037
|
+
* Maps Wallet Standard "change" events to "accountChanged" events
|
|
11038
|
+
*
|
|
11039
|
+
* Note: Wallet Standard only has a "change" event. There are no "connect" or "disconnect" events.
|
|
11040
|
+
* Connection/disconnection is indicated by the presence or absence of accounts in the change event.
|
|
11041
|
+
*/
|
|
11042
|
+
setupEventListeners() {
|
|
11043
|
+
const eventsFeature = this.wallet.features["standard:events"];
|
|
11044
|
+
if (!eventsFeature) {
|
|
11045
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Wallet Standard events feature not available", {
|
|
11046
|
+
walletId: this.walletId,
|
|
11047
|
+
walletName: this.walletName
|
|
11048
|
+
});
|
|
11049
|
+
return;
|
|
12013
11050
|
}
|
|
11051
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Wallet Standard event listeners", {
|
|
11052
|
+
walletId: this.walletId,
|
|
11053
|
+
walletName: this.walletName
|
|
11054
|
+
});
|
|
11055
|
+
eventsFeature.on("change", (properties) => {
|
|
11056
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Wallet Standard change event received", {
|
|
11057
|
+
walletId: this.walletId,
|
|
11058
|
+
walletName: this.walletName,
|
|
11059
|
+
hasAccounts: !!properties.accounts,
|
|
11060
|
+
accountCount: properties.accounts?.length || 0
|
|
11061
|
+
});
|
|
11062
|
+
if (properties.accounts !== void 0) {
|
|
11063
|
+
if (properties.accounts.length > 0) {
|
|
11064
|
+
const firstAccount = properties.accounts[0];
|
|
11065
|
+
const address = this.extractAccountAddress(firstAccount);
|
|
11066
|
+
if (address) {
|
|
11067
|
+
this._publicKey = address;
|
|
11068
|
+
this.eventEmitter.emit("accountChanged", address);
|
|
11069
|
+
this.eventEmitter.emit("connect", address);
|
|
11070
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged and connect events", {
|
|
11071
|
+
walletId: this.walletId,
|
|
11072
|
+
walletName: this.walletName,
|
|
11073
|
+
address
|
|
11074
|
+
});
|
|
11075
|
+
} else {
|
|
11076
|
+
this._publicKey = null;
|
|
11077
|
+
this.eventEmitter.emit("accountChanged", null);
|
|
11078
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged event (null - invalid account)", {
|
|
11079
|
+
walletId: this.walletId,
|
|
11080
|
+
walletName: this.walletName
|
|
11081
|
+
});
|
|
11082
|
+
}
|
|
11083
|
+
} else {
|
|
11084
|
+
this._publicKey = null;
|
|
11085
|
+
this.eventEmitter.emit("accountChanged", null);
|
|
11086
|
+
this.eventEmitter.emit("disconnect");
|
|
11087
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged and disconnect events", {
|
|
11088
|
+
walletId: this.walletId,
|
|
11089
|
+
walletName: this.walletName
|
|
11090
|
+
});
|
|
11091
|
+
}
|
|
11092
|
+
}
|
|
11093
|
+
});
|
|
12014
11094
|
}
|
|
12015
|
-
|
|
12016
|
-
|
|
12017
|
-
|
|
12018
|
-
|
|
12019
|
-
|
|
11095
|
+
extractAccountAddress(account) {
|
|
11096
|
+
return account.address;
|
|
11097
|
+
}
|
|
11098
|
+
on(event, listener) {
|
|
11099
|
+
this.eventEmitter.on(event, listener);
|
|
11100
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Added event listener", {
|
|
11101
|
+
walletId: this.walletId,
|
|
11102
|
+
walletName: this.walletName,
|
|
11103
|
+
event
|
|
11104
|
+
});
|
|
11105
|
+
}
|
|
11106
|
+
off(event, listener) {
|
|
11107
|
+
this.eventEmitter.off(event, listener);
|
|
11108
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Removed event listener", {
|
|
11109
|
+
walletId: this.walletId,
|
|
11110
|
+
walletName: this.walletName,
|
|
11111
|
+
event
|
|
11112
|
+
});
|
|
12020
11113
|
}
|
|
12021
11114
|
/**
|
|
12022
11115
|
* Serialize a transaction to Uint8Array for Wallet Standard API
|
|
@@ -12060,7 +11153,8 @@ var WalletStandardSolanaAdapter = class {
|
|
|
12060
11153
|
};
|
|
12061
11154
|
var InjectedWalletEthereumChain = class {
|
|
12062
11155
|
constructor(provider, walletId, walletName) {
|
|
12063
|
-
|
|
11156
|
+
// Expose eventEmitter for testing - allows tests to trigger events directly
|
|
11157
|
+
this.eventEmitter = new index.EventEmitter3();
|
|
12064
11158
|
this._connected = false;
|
|
12065
11159
|
this._chainId = "0x1";
|
|
12066
11160
|
this._accounts = [];
|
|
@@ -12434,6 +11528,7 @@ var InjectedWalletEthereumChain = class {
|
|
|
12434
11528
|
});
|
|
12435
11529
|
this.provider.on("accountsChanged", (accounts) => {
|
|
12436
11530
|
this._accounts = accounts;
|
|
11531
|
+
this._connected = accounts.length > 0;
|
|
12437
11532
|
this.eventEmitter.emit("accountsChanged", accounts);
|
|
12438
11533
|
});
|
|
12439
11534
|
this.provider.on("chainChanged", (chainId) => {
|
|
@@ -12449,295 +11544,97 @@ var InjectedWalletEthereumChain = class {
|
|
|
12449
11544
|
this.eventEmitter.off(event, listener);
|
|
12450
11545
|
}
|
|
12451
11546
|
};
|
|
12452
|
-
|
|
12453
|
-
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
return this._publicKey;
|
|
12465
|
-
}
|
|
12466
|
-
// Connection methods
|
|
12467
|
-
async connect(options) {
|
|
12468
|
-
const result = await this.phantom.solana.connect(options);
|
|
12469
|
-
if (!result) {
|
|
12470
|
-
throw new Error("Failed to connect to Solana wallet");
|
|
12471
|
-
}
|
|
12472
|
-
const publicKey = typeof result === "string" ? result : "";
|
|
12473
|
-
this._publicKey = publicKey;
|
|
12474
|
-
return { publicKey };
|
|
12475
|
-
}
|
|
12476
|
-
async disconnect() {
|
|
12477
|
-
await this.phantom.solana.disconnect();
|
|
12478
|
-
this._publicKey = null;
|
|
12479
|
-
}
|
|
12480
|
-
// Standard wallet adapter methods
|
|
12481
|
-
async signMessage(message) {
|
|
12482
|
-
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
12483
|
-
const result = await this.phantom.solana.signMessage(messageBytes);
|
|
12484
|
-
return {
|
|
12485
|
-
signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(index.bufferExports.Buffer.from(result.signature, "base64")),
|
|
12486
|
-
publicKey: this._publicKey || ""
|
|
12487
|
-
};
|
|
11547
|
+
|
|
11548
|
+
// src/wallets/registry.ts
|
|
11549
|
+
function isPhantomWallet(wallet) {
|
|
11550
|
+
return wallet !== void 0 && wallet.id === "phantom" && "isPhantom" in wallet && wallet.isPhantom === true;
|
|
11551
|
+
}
|
|
11552
|
+
function isWalletStandardWallet(provider) {
|
|
11553
|
+
return provider !== null && typeof provider === "object" && "features" in provider && typeof provider.features === "object";
|
|
11554
|
+
}
|
|
11555
|
+
var InjectedWalletRegistry = class {
|
|
11556
|
+
constructor() {
|
|
11557
|
+
this.wallets = /* @__PURE__ */ new Map();
|
|
11558
|
+
this.discoveryPromise = null;
|
|
12488
11559
|
}
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
11560
|
+
register(info) {
|
|
11561
|
+
const wrappedProviders = {};
|
|
11562
|
+
if (info.providers?.solana) {
|
|
11563
|
+
if (isWalletStandardWallet(info.providers.solana)) {
|
|
11564
|
+
wrappedProviders.solana = new WalletStandardSolanaAdapter(info.providers.solana, info.id, info.name);
|
|
11565
|
+
debug.log(DebugCategory.BROWSER_SDK, "Wrapped Wallet Standard Solana wallet with adapter", {
|
|
11566
|
+
walletId: info.id,
|
|
11567
|
+
walletName: info.name
|
|
11568
|
+
});
|
|
11569
|
+
} else {
|
|
11570
|
+
wrappedProviders.solana = new InjectedWalletSolanaChain(info.providers.solana, info.id, info.name);
|
|
11571
|
+
debug.log(DebugCategory.BROWSER_SDK, "Wrapped Solana provider with InjectedWalletSolanaChain", {
|
|
11572
|
+
walletId: info.id,
|
|
11573
|
+
walletName: info.name
|
|
11574
|
+
});
|
|
11575
|
+
}
|
|
12492
11576
|
}
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
11577
|
+
if (info.providers?.ethereum) {
|
|
11578
|
+
wrappedProviders.ethereum = new InjectedWalletEthereumChain(info.providers.ethereum, info.id, info.name);
|
|
11579
|
+
debug.log(DebugCategory.BROWSER_SDK, "Wrapped Ethereum provider with InjectedWalletEthereumChain", {
|
|
11580
|
+
walletId: info.id,
|
|
11581
|
+
walletName: info.name
|
|
11582
|
+
});
|
|
12498
11583
|
}
|
|
11584
|
+
const wrappedInfo = {
|
|
11585
|
+
...info,
|
|
11586
|
+
providers: Object.keys(wrappedProviders).length > 0 ? wrappedProviders : info.providers
|
|
11587
|
+
};
|
|
11588
|
+
this.wallets.set(info.id, wrappedInfo);
|
|
12499
11589
|
}
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
11590
|
+
/**
|
|
11591
|
+
* Register Phantom wallet with its instance
|
|
11592
|
+
* This creates wrapped providers and stores the Phantom instance for auto-confirm access
|
|
11593
|
+
* Uses unified InjectedWallet chains for both Phantom and external wallets
|
|
11594
|
+
*/
|
|
11595
|
+
registerPhantom(phantomInstance, addressTypes) {
|
|
11596
|
+
const wrappedProviders = {};
|
|
11597
|
+
if (addressTypes.includes(exports.AddressType.solana) && phantomInstance.solana) {
|
|
11598
|
+
wrappedProviders.solana = new InjectedWalletSolanaChain(phantomInstance.solana, "phantom", "Phantom");
|
|
11599
|
+
debug.log(DebugCategory.BROWSER_SDK, "Created InjectedWalletSolanaChain wrapper for Phantom", {
|
|
11600
|
+
walletId: "phantom"
|
|
11601
|
+
});
|
|
12507
11602
|
}
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
11603
|
+
if (addressTypes.includes(exports.AddressType.ethereum) && phantomInstance.ethereum) {
|
|
11604
|
+
wrappedProviders.ethereum = new InjectedWalletEthereumChain(phantomInstance.ethereum, "phantom", "Phantom");
|
|
11605
|
+
debug.log(DebugCategory.BROWSER_SDK, "Created InjectedWalletEthereumChain wrapper for Phantom", {
|
|
11606
|
+
walletId: "phantom"
|
|
11607
|
+
});
|
|
12513
11608
|
}
|
|
11609
|
+
const phantomWallet = {
|
|
11610
|
+
id: "phantom",
|
|
11611
|
+
name: "Phantom",
|
|
11612
|
+
icon: "",
|
|
11613
|
+
// Icon will be rendered from icons package in UI components
|
|
11614
|
+
addressTypes,
|
|
11615
|
+
providers: wrappedProviders,
|
|
11616
|
+
isPhantom: true,
|
|
11617
|
+
phantomInstance,
|
|
11618
|
+
discovery: "phantom"
|
|
11619
|
+
};
|
|
11620
|
+
this.wallets.set("phantom", phantomWallet);
|
|
11621
|
+
debug.log(DebugCategory.BROWSER_SDK, "Registered Phantom wallet with chain wrappers", {
|
|
11622
|
+
addressTypes,
|
|
11623
|
+
hasSolana: !!wrappedProviders.solana,
|
|
11624
|
+
hasEthereum: !!wrappedProviders.ethereum
|
|
11625
|
+
});
|
|
12514
11626
|
}
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
return Promise.reject(new Error("Provider not connected. Call provider connect first."));
|
|
12518
|
-
}
|
|
12519
|
-
try {
|
|
12520
|
-
const result = await this.phantom.solana.signAndSendAllTransactions(transactions);
|
|
12521
|
-
return { signatures: result.signatures };
|
|
12522
|
-
} catch (error) {
|
|
12523
|
-
return Promise.reject(error);
|
|
12524
|
-
}
|
|
11627
|
+
unregister(id) {
|
|
11628
|
+
this.wallets.delete(id);
|
|
12525
11629
|
}
|
|
12526
|
-
|
|
12527
|
-
return
|
|
11630
|
+
has(id) {
|
|
11631
|
+
return this.wallets.has(id);
|
|
12528
11632
|
}
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
return Promise.resolve(this._publicKey);
|
|
11633
|
+
getById(id) {
|
|
11634
|
+
return this.wallets.get(id);
|
|
12532
11635
|
}
|
|
12533
|
-
|
|
12534
|
-
return this.
|
|
12535
|
-
}
|
|
12536
|
-
setupEventListeners() {
|
|
12537
|
-
this.phantom.solana.addEventListener("connect", (publicKey) => {
|
|
12538
|
-
this._publicKey = publicKey;
|
|
12539
|
-
this.eventEmitter.emit("connect", publicKey);
|
|
12540
|
-
});
|
|
12541
|
-
this.phantom.solana.addEventListener("disconnect", () => {
|
|
12542
|
-
this._publicKey = null;
|
|
12543
|
-
this.eventEmitter.emit("disconnect");
|
|
12544
|
-
});
|
|
12545
|
-
this.phantom.solana.addEventListener("accountChanged", (publicKey) => {
|
|
12546
|
-
this._publicKey = publicKey;
|
|
12547
|
-
this.eventEmitter.emit("accountChanged", publicKey);
|
|
12548
|
-
});
|
|
12549
|
-
}
|
|
12550
|
-
// Event methods for interface compliance
|
|
12551
|
-
on(event, listener) {
|
|
12552
|
-
this.eventEmitter.on(event, listener);
|
|
12553
|
-
}
|
|
12554
|
-
off(event, listener) {
|
|
12555
|
-
this.eventEmitter.off(event, listener);
|
|
12556
|
-
}
|
|
12557
|
-
};
|
|
12558
|
-
var PhantomEthereumChain = class {
|
|
12559
|
-
constructor(phantom) {
|
|
12560
|
-
this._chainId = "0x1";
|
|
12561
|
-
this._accounts = [];
|
|
12562
|
-
this.eventEmitter = new EventEmitter4();
|
|
12563
|
-
this.phantom = phantom;
|
|
12564
|
-
this.setupEventListeners();
|
|
12565
|
-
}
|
|
12566
|
-
// EIP-1193 compliant properties
|
|
12567
|
-
get connected() {
|
|
12568
|
-
return this._accounts.length > 0;
|
|
12569
|
-
}
|
|
12570
|
-
get chainId() {
|
|
12571
|
-
return this._chainId;
|
|
12572
|
-
}
|
|
12573
|
-
get accounts() {
|
|
12574
|
-
return this._accounts;
|
|
12575
|
-
}
|
|
12576
|
-
// EIP-1193 core method with eth_signTransaction support
|
|
12577
|
-
async request(args) {
|
|
12578
|
-
if (args.method === "eth_signTransaction") {
|
|
12579
|
-
const [transaction] = args.params;
|
|
12580
|
-
const result = await this.signTransaction(transaction);
|
|
12581
|
-
return result;
|
|
12582
|
-
}
|
|
12583
|
-
const phantomProvider = await this.phantom.ethereum.getProvider();
|
|
12584
|
-
return await phantomProvider.request(args);
|
|
12585
|
-
}
|
|
12586
|
-
// Connection methods
|
|
12587
|
-
async connect() {
|
|
12588
|
-
const accounts = await this.phantom.ethereum.getAccounts();
|
|
12589
|
-
this._accounts = accounts;
|
|
12590
|
-
return accounts;
|
|
12591
|
-
}
|
|
12592
|
-
async disconnect() {
|
|
12593
|
-
await this.phantom.ethereum.disconnect();
|
|
12594
|
-
this._accounts = [];
|
|
12595
|
-
}
|
|
12596
|
-
// Standard compliant methods (return raw values, not wrapped objects)
|
|
12597
|
-
async signPersonalMessage(message, address) {
|
|
12598
|
-
return await this.phantom.ethereum.signPersonalMessage(message, address);
|
|
12599
|
-
}
|
|
12600
|
-
async signTypedData(typedData, address) {
|
|
12601
|
-
return await this.phantom.ethereum.signTypedData(typedData, address);
|
|
12602
|
-
}
|
|
12603
|
-
async signTransaction(transaction) {
|
|
12604
|
-
return await this.phantom.ethereum.signTransaction(transaction);
|
|
12605
|
-
}
|
|
12606
|
-
async sendTransaction(transaction) {
|
|
12607
|
-
return await this.phantom.ethereum.sendTransaction(transaction);
|
|
12608
|
-
}
|
|
12609
|
-
async switchChain(chainId) {
|
|
12610
|
-
const hexChainId = typeof chainId === "string" ? chainId.toLowerCase().startsWith("0x") ? chainId : `0x${parseInt(chainId, 10).toString(16)}` : `0x${chainId.toString(16)}`;
|
|
12611
|
-
await this.phantom.ethereum.switchChain(hexChainId);
|
|
12612
|
-
this._chainId = hexChainId;
|
|
12613
|
-
this.eventEmitter.emit("chainChanged", this._chainId);
|
|
12614
|
-
}
|
|
12615
|
-
async getChainId() {
|
|
12616
|
-
const chainId = await this.phantom.ethereum.getChainId();
|
|
12617
|
-
return parseInt(chainId, 16);
|
|
12618
|
-
}
|
|
12619
|
-
async getAccounts() {
|
|
12620
|
-
return await this.phantom.ethereum.getAccounts();
|
|
12621
|
-
}
|
|
12622
|
-
isConnected() {
|
|
12623
|
-
return this.connected;
|
|
12624
|
-
}
|
|
12625
|
-
setupEventListeners() {
|
|
12626
|
-
this.phantom.ethereum.addEventListener("connect", (accounts) => {
|
|
12627
|
-
this._accounts = accounts;
|
|
12628
|
-
this.eventEmitter.emit("connect", { chainId: this._chainId });
|
|
12629
|
-
this.eventEmitter.emit("accountsChanged", accounts);
|
|
12630
|
-
});
|
|
12631
|
-
this.phantom.ethereum.addEventListener("disconnect", () => {
|
|
12632
|
-
this._accounts = [];
|
|
12633
|
-
this.eventEmitter.emit("disconnect", { code: 4900, message: "Provider disconnected" });
|
|
12634
|
-
this.eventEmitter.emit("accountsChanged", []);
|
|
12635
|
-
});
|
|
12636
|
-
this.phantom.ethereum.addEventListener("accountsChanged", (accounts) => {
|
|
12637
|
-
this._accounts = accounts;
|
|
12638
|
-
this.eventEmitter.emit("accountsChanged", accounts);
|
|
12639
|
-
});
|
|
12640
|
-
this.phantom.ethereum.addEventListener("chainChanged", (chainId) => {
|
|
12641
|
-
this._chainId = chainId;
|
|
12642
|
-
this.eventEmitter.emit("chainChanged", chainId);
|
|
12643
|
-
});
|
|
12644
|
-
}
|
|
12645
|
-
// Event methods for interface compliance
|
|
12646
|
-
on(event, listener) {
|
|
12647
|
-
this.eventEmitter.on(event, listener);
|
|
12648
|
-
}
|
|
12649
|
-
off(event, listener) {
|
|
12650
|
-
this.eventEmitter.off(event, listener);
|
|
12651
|
-
}
|
|
12652
|
-
};
|
|
12653
|
-
|
|
12654
|
-
// src/wallets/registry.ts
|
|
12655
|
-
function isPhantomWallet(wallet) {
|
|
12656
|
-
return wallet !== void 0 && wallet.id === "phantom" && "isPhantom" in wallet && wallet.isPhantom === true;
|
|
12657
|
-
}
|
|
12658
|
-
var InjectedWalletRegistry = class {
|
|
12659
|
-
constructor() {
|
|
12660
|
-
this.wallets = /* @__PURE__ */ new Map();
|
|
12661
|
-
this.discoveryPromise = null;
|
|
12662
|
-
}
|
|
12663
|
-
register(info) {
|
|
12664
|
-
const wrappedProviders = {};
|
|
12665
|
-
if (info.providers?.solana) {
|
|
12666
|
-
const isWalletStandard = info.providers.solana && typeof info.providers.solana === "object" && "features" in info.providers.solana && typeof info.providers.solana.features === "object";
|
|
12667
|
-
if (isWalletStandard) {
|
|
12668
|
-
wrappedProviders.solana = new WalletStandardSolanaAdapter(info.providers.solana, info.id, info.name);
|
|
12669
|
-
debug.log(DebugCategory.BROWSER_SDK, "Wrapped Wallet Standard Solana wallet with adapter", {
|
|
12670
|
-
walletId: info.id,
|
|
12671
|
-
walletName: info.name
|
|
12672
|
-
});
|
|
12673
|
-
} else {
|
|
12674
|
-
wrappedProviders.solana = new InjectedWalletSolanaChain(info.providers.solana, info.id, info.name);
|
|
12675
|
-
debug.log(DebugCategory.BROWSER_SDK, "Wrapped Solana provider with InjectedWalletSolanaChain", {
|
|
12676
|
-
walletId: info.id,
|
|
12677
|
-
walletName: info.name
|
|
12678
|
-
});
|
|
12679
|
-
}
|
|
12680
|
-
}
|
|
12681
|
-
if (info.providers?.ethereum) {
|
|
12682
|
-
wrappedProviders.ethereum = new InjectedWalletEthereumChain(info.providers.ethereum, info.id, info.name);
|
|
12683
|
-
debug.log(DebugCategory.BROWSER_SDK, "Wrapped Ethereum provider with InjectedWalletEthereumChain", {
|
|
12684
|
-
walletId: info.id,
|
|
12685
|
-
walletName: info.name
|
|
12686
|
-
});
|
|
12687
|
-
}
|
|
12688
|
-
const wrappedInfo = {
|
|
12689
|
-
...info,
|
|
12690
|
-
providers: Object.keys(wrappedProviders).length > 0 ? wrappedProviders : info.providers
|
|
12691
|
-
};
|
|
12692
|
-
this.wallets.set(info.id, wrappedInfo);
|
|
12693
|
-
}
|
|
12694
|
-
/**
|
|
12695
|
-
* Register Phantom wallet with its instance
|
|
12696
|
-
* This creates wrapped providers and stores the Phantom instance for auto-confirm access
|
|
12697
|
-
*/
|
|
12698
|
-
registerPhantom(phantomInstance, addressTypes) {
|
|
12699
|
-
const wrappedProviders = {};
|
|
12700
|
-
if (addressTypes.includes(exports.AddressType.solana) && phantomInstance.solana) {
|
|
12701
|
-
wrappedProviders.solana = new PhantomSolanaChain(phantomInstance);
|
|
12702
|
-
debug.log(DebugCategory.BROWSER_SDK, "Created PhantomSolanaChain wrapper", {
|
|
12703
|
-
walletId: "phantom"
|
|
12704
|
-
});
|
|
12705
|
-
}
|
|
12706
|
-
if (addressTypes.includes(exports.AddressType.ethereum) && phantomInstance.ethereum) {
|
|
12707
|
-
wrappedProviders.ethereum = new PhantomEthereumChain(phantomInstance);
|
|
12708
|
-
debug.log(DebugCategory.BROWSER_SDK, "Created PhantomEthereumChain wrapper", {
|
|
12709
|
-
walletId: "phantom"
|
|
12710
|
-
});
|
|
12711
|
-
}
|
|
12712
|
-
const phantomWallet = {
|
|
12713
|
-
id: "phantom",
|
|
12714
|
-
name: "Phantom",
|
|
12715
|
-
icon: "",
|
|
12716
|
-
// Icon will be rendered from icons package in UI components
|
|
12717
|
-
addressTypes,
|
|
12718
|
-
providers: wrappedProviders,
|
|
12719
|
-
isPhantom: true,
|
|
12720
|
-
phantomInstance,
|
|
12721
|
-
discovery: "phantom"
|
|
12722
|
-
};
|
|
12723
|
-
this.wallets.set("phantom", phantomWallet);
|
|
12724
|
-
debug.log(DebugCategory.BROWSER_SDK, "Registered Phantom wallet with chain wrappers", {
|
|
12725
|
-
addressTypes,
|
|
12726
|
-
hasSolana: !!wrappedProviders.solana,
|
|
12727
|
-
hasEthereum: !!wrappedProviders.ethereum
|
|
12728
|
-
});
|
|
12729
|
-
}
|
|
12730
|
-
unregister(id) {
|
|
12731
|
-
this.wallets.delete(id);
|
|
12732
|
-
}
|
|
12733
|
-
has(id) {
|
|
12734
|
-
return this.wallets.has(id);
|
|
12735
|
-
}
|
|
12736
|
-
getById(id) {
|
|
12737
|
-
return this.wallets.get(id);
|
|
12738
|
-
}
|
|
12739
|
-
getAll() {
|
|
12740
|
-
return Array.from(this.wallets.values());
|
|
11636
|
+
getAll() {
|
|
11637
|
+
return Array.from(this.wallets.values());
|
|
12741
11638
|
}
|
|
12742
11639
|
getByAddressTypes(addressTypes) {
|
|
12743
11640
|
if (addressTypes.length === 0) {
|
|
@@ -12790,15 +11687,16 @@ var WAS_CONNECTED_KEY = "phantom-injected-was-connected";
|
|
|
12790
11687
|
var WAS_CONNECTED_VALUE = "true";
|
|
12791
11688
|
var LAST_WALLET_ID_KEY = "phantom-injected-last-wallet-id";
|
|
12792
11689
|
var InjectedProvider = class {
|
|
12793
|
-
//
|
|
11690
|
+
// Store cleanups per walletId
|
|
12794
11691
|
constructor(config) {
|
|
12795
11692
|
this.selectedWalletId = null;
|
|
12796
11693
|
this.walletStates = /* @__PURE__ */ new Map();
|
|
12797
11694
|
// Event management
|
|
12798
11695
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
12799
|
-
this.browserInjectedCleanupFunctions = [];
|
|
12800
11696
|
this.eventsInitialized = false;
|
|
12801
|
-
this.
|
|
11697
|
+
this.eventListenersSetup = /* @__PURE__ */ new Set();
|
|
11698
|
+
// Track walletId that have listeners set up
|
|
11699
|
+
this.eventListenerCleanups = /* @__PURE__ */ new Map();
|
|
12802
11700
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Initializing InjectedProvider", { config });
|
|
12803
11701
|
this.addressTypes = config.addressTypes;
|
|
12804
11702
|
this.walletRegistry = getWalletRegistry();
|
|
@@ -12829,9 +11727,12 @@ var InjectedProvider = class {
|
|
|
12829
11727
|
});
|
|
12830
11728
|
}
|
|
12831
11729
|
}
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
11730
|
+
/**
|
|
11731
|
+
* Helper method to get a chain provider with consistent error handling
|
|
11732
|
+
*/
|
|
11733
|
+
getChainProvider(addressType, providerKey, chainName) {
|
|
11734
|
+
if (!this.addressTypes.includes(addressType)) {
|
|
11735
|
+
throw new Error(`${chainName} not enabled for this provider`);
|
|
12835
11736
|
}
|
|
12836
11737
|
const walletId = this.selectedWalletId || "phantom";
|
|
12837
11738
|
const walletInfo = this.walletRegistry.getById(walletId);
|
|
@@ -12846,39 +11747,22 @@ var InjectedProvider = class {
|
|
|
12846
11747
|
`Wallet "${walletId}" not found. Please ensure wallet discovery has completed. Make sure you call sdk.discoverWallets() and await it before accessing chain properties.`
|
|
12847
11748
|
);
|
|
12848
11749
|
}
|
|
12849
|
-
|
|
11750
|
+
const provider = walletInfo.providers?.[providerKey];
|
|
11751
|
+
if (!provider) {
|
|
12850
11752
|
throw new Error(
|
|
12851
|
-
`Selected wallet "${walletInfo.name}" does not support
|
|
11753
|
+
`Selected wallet "${walletInfo.name}" does not support ${chainName}. This wallet only supports: ${walletInfo.addressTypes.join(", ")}. Make sure your SDK config includes ${chainName} in addressTypes.`
|
|
12852
11754
|
);
|
|
12853
11755
|
}
|
|
12854
|
-
return
|
|
11756
|
+
return provider;
|
|
11757
|
+
}
|
|
11758
|
+
get solana() {
|
|
11759
|
+
return this.getChainProvider(exports.AddressType.solana, "solana", "Solana");
|
|
12855
11760
|
}
|
|
12856
11761
|
/**
|
|
12857
11762
|
* Access to Ethereum chain operations
|
|
12858
11763
|
*/
|
|
12859
11764
|
get ethereum() {
|
|
12860
|
-
|
|
12861
|
-
throw new Error("Ethereum not enabled for this provider");
|
|
12862
|
-
}
|
|
12863
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
12864
|
-
const walletInfo = this.walletRegistry.getById(walletId);
|
|
12865
|
-
if (!walletInfo) {
|
|
12866
|
-
const registry = this.walletRegistry;
|
|
12867
|
-
if (registry.discoveryPromise) {
|
|
12868
|
-
throw new Error(
|
|
12869
|
-
`Wallet "${walletId}" not found. Wallet discovery is still in progress. Please wait for sdk.discoverWallets() to complete before accessing chain properties.`
|
|
12870
|
-
);
|
|
12871
|
-
}
|
|
12872
|
-
throw new Error(
|
|
12873
|
-
`Wallet "${walletId}" not found. Please ensure wallet discovery has completed. Make sure you call sdk.discoverWallets() and await it before accessing chain properties.`
|
|
12874
|
-
);
|
|
12875
|
-
}
|
|
12876
|
-
if (!walletInfo.providers?.ethereum) {
|
|
12877
|
-
throw new Error(
|
|
12878
|
-
`Selected wallet "${walletInfo.name}" does not support Ethereum. This wallet only supports: ${walletInfo.addressTypes.join(", ")}. Make sure your SDK config includes Ethereum in addressTypes.`
|
|
12879
|
-
);
|
|
12880
|
-
}
|
|
12881
|
-
return walletInfo.providers.ethereum;
|
|
11765
|
+
return this.getChainProvider(exports.AddressType.ethereum, "ethereum", "Ethereum");
|
|
12882
11766
|
}
|
|
12883
11767
|
validateAndSelectWallet(requestedWalletId) {
|
|
12884
11768
|
if (!this.walletRegistry.has(requestedWalletId)) {
|
|
@@ -12916,13 +11800,7 @@ var InjectedProvider = class {
|
|
|
12916
11800
|
options
|
|
12917
11801
|
});
|
|
12918
11802
|
if (!options?.skipEventListeners) {
|
|
12919
|
-
this.
|
|
12920
|
-
if (this.selectedWalletId === "phantom" && isPhantomWallet(walletInfo)) {
|
|
12921
|
-
this.browserInjectedCleanupFunctions.forEach((cleanup) => cleanup());
|
|
12922
|
-
this.browserInjectedCleanupFunctions = [];
|
|
12923
|
-
this.setupBrowserInjectedEvents();
|
|
12924
|
-
this.eventsInitialized = true;
|
|
12925
|
-
}
|
|
11803
|
+
this.setupEventListeners(walletInfo);
|
|
12926
11804
|
}
|
|
12927
11805
|
const connectedAddresses = [];
|
|
12928
11806
|
if (this.addressTypes.includes(exports.AddressType.solana) && walletInfo.providers?.solana) {
|
|
@@ -13104,10 +11982,14 @@ var InjectedProvider = class {
|
|
|
13104
11982
|
}
|
|
13105
11983
|
}
|
|
13106
11984
|
}
|
|
13107
|
-
this.
|
|
13108
|
-
|
|
11985
|
+
const walletId = this.selectedWalletId || "phantom";
|
|
11986
|
+
const cleanups = this.eventListenerCleanups.get(walletId);
|
|
11987
|
+
if (cleanups) {
|
|
11988
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
11989
|
+
this.eventListenerCleanups.delete(walletId);
|
|
11990
|
+
}
|
|
11991
|
+
this.eventListenersSetup.delete(walletId);
|
|
13109
11992
|
if (this.selectedWalletId) {
|
|
13110
|
-
this.externalWalletEventListenersSetup.delete(this.selectedWalletId);
|
|
13111
11993
|
this.setWalletState(this.selectedWalletId, {
|
|
13112
11994
|
connected: false,
|
|
13113
11995
|
addresses: []
|
|
@@ -13176,13 +12058,7 @@ var InjectedProvider = class {
|
|
|
13176
12058
|
});
|
|
13177
12059
|
return;
|
|
13178
12060
|
}
|
|
13179
|
-
this.
|
|
13180
|
-
if (this.selectedWalletId === "phantom" && isPhantomWallet(walletInfo)) {
|
|
13181
|
-
this.browserInjectedCleanupFunctions.forEach((cleanup) => cleanup());
|
|
13182
|
-
this.browserInjectedCleanupFunctions = [];
|
|
13183
|
-
this.setupBrowserInjectedEvents();
|
|
13184
|
-
this.eventsInitialized = true;
|
|
13185
|
-
}
|
|
12061
|
+
this.setupEventListeners(walletInfo);
|
|
13186
12062
|
if (this.selectedWalletId) {
|
|
13187
12063
|
this.setWalletState(this.selectedWalletId, {
|
|
13188
12064
|
connected: true,
|
|
@@ -13223,6 +12099,166 @@ var InjectedProvider = class {
|
|
|
13223
12099
|
setWalletState(walletId, state) {
|
|
13224
12100
|
this.walletStates.set(walletId, state);
|
|
13225
12101
|
}
|
|
12102
|
+
/**
|
|
12103
|
+
* Update wallet state with new addresses for a specific address type
|
|
12104
|
+
* Replaces all existing addresses of the given type with the new addresses
|
|
12105
|
+
* @param walletId - The wallet ID to update
|
|
12106
|
+
* @param newAddresses - Array of new addresses (strings) for the address type
|
|
12107
|
+
* @param addressType - The type of addresses being updated
|
|
12108
|
+
* @returns The updated addresses array
|
|
12109
|
+
*/
|
|
12110
|
+
updateWalletAddresses(walletId, newAddresses, addressType) {
|
|
12111
|
+
const state = this.getWalletState(walletId);
|
|
12112
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== addressType);
|
|
12113
|
+
const addressesOfType = newAddresses.map((address) => ({ addressType, address }));
|
|
12114
|
+
const updatedAddresses = [...otherAddresses, ...addressesOfType];
|
|
12115
|
+
this.setWalletState(walletId, {
|
|
12116
|
+
connected: updatedAddresses.length > 0,
|
|
12117
|
+
addresses: updatedAddresses
|
|
12118
|
+
});
|
|
12119
|
+
return updatedAddresses;
|
|
12120
|
+
}
|
|
12121
|
+
/**
|
|
12122
|
+
* Helper to construct account change source string
|
|
12123
|
+
*/
|
|
12124
|
+
getAccountChangeSource(source) {
|
|
12125
|
+
return `${source}-account-change`;
|
|
12126
|
+
}
|
|
12127
|
+
/**
|
|
12128
|
+
* Create a handler for Solana connect events
|
|
12129
|
+
*/
|
|
12130
|
+
createSolanaConnectHandler(walletId, source) {
|
|
12131
|
+
return async (publicKey) => {
|
|
12132
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana connect event received", { publicKey, walletId });
|
|
12133
|
+
const newAddresses = this.updateWalletAddresses(walletId, [publicKey], exports.AddressType.solana);
|
|
12134
|
+
const authUserId = await this.getAuthUserId("Solana connect event");
|
|
12135
|
+
this.emit("connect", {
|
|
12136
|
+
addresses: newAddresses,
|
|
12137
|
+
source,
|
|
12138
|
+
authUserId
|
|
12139
|
+
});
|
|
12140
|
+
};
|
|
12141
|
+
}
|
|
12142
|
+
/**
|
|
12143
|
+
* Create a handler for Solana disconnect events
|
|
12144
|
+
*/
|
|
12145
|
+
createSolanaDisconnectHandler(walletId, source) {
|
|
12146
|
+
return () => {
|
|
12147
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received", { walletId });
|
|
12148
|
+
const state = this.getWalletState(walletId);
|
|
12149
|
+
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.solana);
|
|
12150
|
+
this.setWalletState(walletId, {
|
|
12151
|
+
connected: filteredAddresses.length > 0,
|
|
12152
|
+
addresses: filteredAddresses
|
|
12153
|
+
});
|
|
12154
|
+
this.emit("disconnect", {
|
|
12155
|
+
source
|
|
12156
|
+
});
|
|
12157
|
+
};
|
|
12158
|
+
}
|
|
12159
|
+
/**
|
|
12160
|
+
* Create a handler for Solana account change events
|
|
12161
|
+
* Can receive string | null per Wallet Standard
|
|
12162
|
+
*/
|
|
12163
|
+
createSolanaAccountChangeHandler(walletId, source) {
|
|
12164
|
+
return async (publicKey) => {
|
|
12165
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana account changed event received", { publicKey, walletId });
|
|
12166
|
+
if (publicKey) {
|
|
12167
|
+
const newAddresses = this.updateWalletAddresses(walletId, [publicKey], exports.AddressType.solana);
|
|
12168
|
+
const authUserId = await this.getAuthUserId("Solana account changed event");
|
|
12169
|
+
this.emit("connect", {
|
|
12170
|
+
addresses: newAddresses,
|
|
12171
|
+
source: this.getAccountChangeSource(source),
|
|
12172
|
+
authUserId
|
|
12173
|
+
});
|
|
12174
|
+
} else {
|
|
12175
|
+
const state = this.getWalletState(walletId);
|
|
12176
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.solana);
|
|
12177
|
+
this.setWalletState(walletId, {
|
|
12178
|
+
connected: otherAddresses.length > 0,
|
|
12179
|
+
addresses: otherAddresses
|
|
12180
|
+
});
|
|
12181
|
+
this.emit("disconnect", {
|
|
12182
|
+
source: this.getAccountChangeSource(source)
|
|
12183
|
+
});
|
|
12184
|
+
}
|
|
12185
|
+
};
|
|
12186
|
+
}
|
|
12187
|
+
/**
|
|
12188
|
+
* Create a handler for Ethereum connect events
|
|
12189
|
+
* EIP-1193 connect event receives { chainId: string }, but we need to get accounts separately
|
|
12190
|
+
*/
|
|
12191
|
+
createEthereumConnectHandler(walletId, source) {
|
|
12192
|
+
return async (connectInfo) => {
|
|
12193
|
+
let accounts = [];
|
|
12194
|
+
if (Array.isArray(connectInfo)) {
|
|
12195
|
+
accounts = connectInfo;
|
|
12196
|
+
} else {
|
|
12197
|
+
try {
|
|
12198
|
+
const walletInfo = this.walletRegistry.getById(walletId);
|
|
12199
|
+
if (walletInfo?.providers?.ethereum) {
|
|
12200
|
+
accounts = await walletInfo.providers.ethereum.getAccounts();
|
|
12201
|
+
}
|
|
12202
|
+
} catch (error) {
|
|
12203
|
+
debug.warn(DebugCategory.INJECTED_PROVIDER, "Failed to get accounts on connect", { error });
|
|
12204
|
+
}
|
|
12205
|
+
}
|
|
12206
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum connect event received", { accounts, walletId });
|
|
12207
|
+
if (accounts.length > 0) {
|
|
12208
|
+
const newAddresses = this.updateWalletAddresses(walletId, accounts, exports.AddressType.ethereum);
|
|
12209
|
+
const authUserId = await this.getAuthUserId("Ethereum connect event");
|
|
12210
|
+
this.emit("connect", {
|
|
12211
|
+
addresses: newAddresses,
|
|
12212
|
+
source,
|
|
12213
|
+
authUserId
|
|
12214
|
+
});
|
|
12215
|
+
}
|
|
12216
|
+
};
|
|
12217
|
+
}
|
|
12218
|
+
/**
|
|
12219
|
+
* Create a handler for Ethereum disconnect events
|
|
12220
|
+
*/
|
|
12221
|
+
createEthereumDisconnectHandler(walletId, source) {
|
|
12222
|
+
return () => {
|
|
12223
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received", { walletId });
|
|
12224
|
+
const state = this.getWalletState(walletId);
|
|
12225
|
+
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.ethereum);
|
|
12226
|
+
this.setWalletState(walletId, {
|
|
12227
|
+
connected: filteredAddresses.length > 0,
|
|
12228
|
+
addresses: filteredAddresses
|
|
12229
|
+
});
|
|
12230
|
+
this.emit("disconnect", {
|
|
12231
|
+
source
|
|
12232
|
+
});
|
|
12233
|
+
};
|
|
12234
|
+
}
|
|
12235
|
+
/**
|
|
12236
|
+
* Create a handler for Ethereum account change events
|
|
12237
|
+
*/
|
|
12238
|
+
createEthereumAccountChangeHandler(walletId, source) {
|
|
12239
|
+
return async (accounts) => {
|
|
12240
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum accounts changed event received", { accounts, walletId });
|
|
12241
|
+
if (accounts && accounts.length > 0) {
|
|
12242
|
+
const newAddresses = this.updateWalletAddresses(walletId, accounts, exports.AddressType.ethereum);
|
|
12243
|
+
const authUserId = await this.getAuthUserId("Ethereum accounts changed event");
|
|
12244
|
+
this.emit("connect", {
|
|
12245
|
+
addresses: newAddresses,
|
|
12246
|
+
source: this.getAccountChangeSource(source),
|
|
12247
|
+
authUserId
|
|
12248
|
+
});
|
|
12249
|
+
} else {
|
|
12250
|
+
const state = this.getWalletState(walletId);
|
|
12251
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.ethereum);
|
|
12252
|
+
this.setWalletState(walletId, {
|
|
12253
|
+
connected: otherAddresses.length > 0,
|
|
12254
|
+
addresses: otherAddresses
|
|
12255
|
+
});
|
|
12256
|
+
this.emit("disconnect", {
|
|
12257
|
+
source: this.getAccountChangeSource(source)
|
|
12258
|
+
});
|
|
12259
|
+
}
|
|
12260
|
+
};
|
|
12261
|
+
}
|
|
13226
12262
|
getAddresses() {
|
|
13227
12263
|
const walletId = this.selectedWalletId || "phantom";
|
|
13228
12264
|
return this.getWalletState(walletId).addresses;
|
|
@@ -13316,19 +12352,22 @@ var InjectedProvider = class {
|
|
|
13316
12352
|
on(event, callback) {
|
|
13317
12353
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Adding event listener", { event });
|
|
13318
12354
|
if (!this.eventsInitialized) {
|
|
13319
|
-
this.
|
|
13320
|
-
|
|
12355
|
+
const walletId = this.selectedWalletId || "phantom";
|
|
12356
|
+
const walletInfo = this.walletRegistry.getById(walletId);
|
|
12357
|
+
if (walletInfo) {
|
|
12358
|
+
this.setupEventListeners(walletInfo);
|
|
12359
|
+
}
|
|
13321
12360
|
}
|
|
13322
12361
|
if (!this.eventListeners.has(event)) {
|
|
13323
12362
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
13324
12363
|
}
|
|
13325
|
-
this.eventListeners.get(event)
|
|
12364
|
+
this.eventListeners.get(event)?.add(callback);
|
|
13326
12365
|
}
|
|
13327
12366
|
off(event, callback) {
|
|
13328
12367
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Removing event listener", { event });
|
|
13329
12368
|
if (this.eventListeners.has(event)) {
|
|
13330
|
-
this.eventListeners.get(event)
|
|
13331
|
-
if (this.eventListeners.get(event)
|
|
12369
|
+
this.eventListeners.get(event)?.delete(callback);
|
|
12370
|
+
if (this.eventListeners.get(event)?.size === 0) {
|
|
13332
12371
|
this.eventListeners.delete(event);
|
|
13333
12372
|
}
|
|
13334
12373
|
}
|
|
@@ -13350,246 +12389,76 @@ var InjectedProvider = class {
|
|
|
13350
12389
|
});
|
|
13351
12390
|
}
|
|
13352
12391
|
}
|
|
13353
|
-
|
|
13354
|
-
|
|
13355
|
-
|
|
13356
|
-
|
|
12392
|
+
/**
|
|
12393
|
+
* Set up Solana event listeners for any provider (Phantom or external)
|
|
12394
|
+
*/
|
|
12395
|
+
setupSolanaEventListeners(provider, walletId, source) {
|
|
12396
|
+
if (typeof provider.on !== "function")
|
|
13357
12397
|
return;
|
|
13358
|
-
}
|
|
13359
|
-
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13363
|
-
}
|
|
13364
|
-
if (this.addressTypes.includes(exports.AddressType.ethereum)) {
|
|
13365
|
-
this.setupEthereumEvents(walletInfo.phantomInstance);
|
|
13366
|
-
}
|
|
13367
|
-
}
|
|
13368
|
-
}
|
|
13369
|
-
setupSolanaEvents(phantom) {
|
|
13370
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Solana event listeners");
|
|
13371
|
-
const handleSolanaConnect = async (publicKey) => {
|
|
13372
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana connect event received", { publicKey });
|
|
13373
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
13374
|
-
const state = this.getWalletState(walletId);
|
|
13375
|
-
const solanaAddress = { addressType: exports.AddressType.solana, address: publicKey };
|
|
13376
|
-
const hasSolana = state.addresses.some((addr) => addr.addressType === exports.AddressType.solana);
|
|
13377
|
-
const newAddresses = hasSolana ? state.addresses.map((addr) => addr.addressType === exports.AddressType.solana ? solanaAddress : addr) : [...state.addresses, solanaAddress];
|
|
13378
|
-
this.setWalletState(walletId, {
|
|
13379
|
-
connected: true,
|
|
13380
|
-
addresses: newAddresses
|
|
13381
|
-
});
|
|
13382
|
-
const authUserId = await this.getAuthUserId("Solana connect event");
|
|
13383
|
-
this.emit("connect", {
|
|
13384
|
-
addresses: newAddresses,
|
|
13385
|
-
source: "injected-extension",
|
|
13386
|
-
authUserId
|
|
13387
|
-
});
|
|
12398
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Solana event listeners", { walletId, source });
|
|
12399
|
+
const handlers = {
|
|
12400
|
+
connect: this.createSolanaConnectHandler(walletId, source),
|
|
12401
|
+
disconnect: this.createSolanaDisconnectHandler(walletId, source),
|
|
12402
|
+
accountChanged: this.createSolanaAccountChangeHandler(walletId, source)
|
|
13388
12403
|
};
|
|
13389
|
-
|
|
13390
|
-
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
|
|
13394
|
-
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
13399
|
-
|
|
13400
|
-
|
|
13401
|
-
|
|
13402
|
-
const handleSolanaAccountChanged = async (publicKey) => {
|
|
13403
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana account changed event received", { publicKey });
|
|
13404
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
13405
|
-
const state = this.getWalletState(walletId);
|
|
13406
|
-
const solanaIndex = state.addresses.findIndex((addr) => addr.addressType === exports.AddressType.solana);
|
|
13407
|
-
const newAddresses = solanaIndex >= 0 ? state.addresses.map(
|
|
13408
|
-
(addr, idx) => idx === solanaIndex ? { addressType: exports.AddressType.solana, address: publicKey } : addr
|
|
13409
|
-
) : [...state.addresses, { addressType: exports.AddressType.solana, address: publicKey }];
|
|
13410
|
-
this.setWalletState(walletId, {
|
|
13411
|
-
connected: true,
|
|
13412
|
-
addresses: newAddresses
|
|
13413
|
-
});
|
|
13414
|
-
const authUserId = await this.getAuthUserId("Solana account changed event");
|
|
13415
|
-
this.emit("connect", {
|
|
13416
|
-
addresses: newAddresses,
|
|
13417
|
-
source: "injected-extension-account-change",
|
|
13418
|
-
authUserId
|
|
13419
|
-
});
|
|
13420
|
-
};
|
|
13421
|
-
const cleanupConnect = phantom.solana.addEventListener("connect", handleSolanaConnect);
|
|
13422
|
-
const cleanupDisconnect = phantom.solana.addEventListener("disconnect", handleSolanaDisconnect);
|
|
13423
|
-
const cleanupAccountChanged = phantom.solana.addEventListener("accountChanged", handleSolanaAccountChanged);
|
|
13424
|
-
this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountChanged);
|
|
13425
|
-
}
|
|
13426
|
-
setupEthereumEvents(phantom) {
|
|
13427
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Ethereum event listeners");
|
|
13428
|
-
const handleEthereumConnect = async (accounts) => {
|
|
13429
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum connect event received", { accounts });
|
|
13430
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
13431
|
-
const state = this.getWalletState(walletId);
|
|
13432
|
-
const ethAddresses = accounts.map((address) => ({ addressType: exports.AddressType.ethereum, address }));
|
|
13433
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.ethereum);
|
|
13434
|
-
const newAddresses = [...otherAddresses, ...ethAddresses];
|
|
13435
|
-
this.setWalletState(walletId, {
|
|
13436
|
-
connected: true,
|
|
13437
|
-
addresses: newAddresses
|
|
13438
|
-
});
|
|
13439
|
-
const authUserId = await this.getAuthUserId("Ethereum connect event");
|
|
13440
|
-
this.emit("connect", {
|
|
13441
|
-
addresses: newAddresses,
|
|
13442
|
-
source: "injected-extension",
|
|
13443
|
-
authUserId
|
|
13444
|
-
});
|
|
13445
|
-
};
|
|
13446
|
-
const handleEthereumDisconnect = () => {
|
|
13447
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received");
|
|
13448
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
13449
|
-
const state = this.getWalletState(walletId);
|
|
13450
|
-
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.ethereum);
|
|
13451
|
-
this.setWalletState(walletId, {
|
|
13452
|
-
connected: filteredAddresses.length > 0,
|
|
13453
|
-
addresses: filteredAddresses
|
|
13454
|
-
});
|
|
13455
|
-
this.emit("disconnect", {
|
|
13456
|
-
source: "injected-extension"
|
|
13457
|
-
});
|
|
13458
|
-
};
|
|
13459
|
-
const handleEthereumAccountsChanged = async (accounts) => {
|
|
13460
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum accounts changed event received", { accounts });
|
|
13461
|
-
const walletId = this.selectedWalletId || "phantom";
|
|
13462
|
-
const state = this.getWalletState(walletId);
|
|
13463
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.ethereum);
|
|
13464
|
-
if (accounts && accounts.length > 0) {
|
|
13465
|
-
const ethAddresses = accounts.map((address) => ({ addressType: exports.AddressType.ethereum, address }));
|
|
13466
|
-
const newAddresses = [...otherAddresses, ...ethAddresses];
|
|
13467
|
-
this.setWalletState(walletId, {
|
|
13468
|
-
connected: true,
|
|
13469
|
-
addresses: newAddresses
|
|
13470
|
-
});
|
|
13471
|
-
const authUserId = await this.getAuthUserId("Ethereum accounts changed event");
|
|
13472
|
-
this.emit("connect", {
|
|
13473
|
-
addresses: newAddresses,
|
|
13474
|
-
source: "injected-extension-account-change",
|
|
13475
|
-
authUserId
|
|
13476
|
-
});
|
|
13477
|
-
} else {
|
|
13478
|
-
this.setWalletState(walletId, {
|
|
13479
|
-
connected: otherAddresses.length > 0,
|
|
13480
|
-
addresses: otherAddresses
|
|
13481
|
-
});
|
|
13482
|
-
this.emit("disconnect", {
|
|
13483
|
-
source: "injected-extension-account-change"
|
|
13484
|
-
});
|
|
13485
|
-
}
|
|
13486
|
-
};
|
|
13487
|
-
const cleanupConnect = phantom.ethereum.addEventListener("connect", handleEthereumConnect);
|
|
13488
|
-
const cleanupDisconnect = phantom.ethereum.addEventListener("disconnect", handleEthereumDisconnect);
|
|
13489
|
-
const cleanupAccountsChanged = phantom.ethereum.addEventListener("accountsChanged", handleEthereumAccountsChanged);
|
|
13490
|
-
this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountsChanged);
|
|
12404
|
+
provider.on("connect", handlers.connect);
|
|
12405
|
+
provider.on("disconnect", handlers.disconnect);
|
|
12406
|
+
provider.on("accountChanged", handlers.accountChanged);
|
|
12407
|
+
const cleanups = [];
|
|
12408
|
+
if (typeof provider.off === "function") {
|
|
12409
|
+
cleanups.push(
|
|
12410
|
+
() => provider.off("connect", handlers.connect),
|
|
12411
|
+
() => provider.off("disconnect", handlers.disconnect),
|
|
12412
|
+
() => provider.off("accountChanged", handlers.accountChanged)
|
|
12413
|
+
);
|
|
12414
|
+
}
|
|
12415
|
+
const existingCleanups = this.eventListenerCleanups.get(walletId) || [];
|
|
12416
|
+
this.eventListenerCleanups.set(walletId, [...existingCleanups, ...cleanups]);
|
|
13491
12417
|
}
|
|
13492
|
-
|
|
13493
|
-
|
|
12418
|
+
/**
|
|
12419
|
+
* Set up Ethereum event listeners for any provider (Phantom or external)
|
|
12420
|
+
*/
|
|
12421
|
+
setupEthereumEventListeners(provider, walletId, source) {
|
|
12422
|
+
if (typeof provider.on !== "function")
|
|
13494
12423
|
return;
|
|
12424
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Ethereum event listeners", { walletId, source });
|
|
12425
|
+
const handlers = {
|
|
12426
|
+
connect: this.createEthereumConnectHandler(walletId, source),
|
|
12427
|
+
disconnect: this.createEthereumDisconnectHandler(walletId, source),
|
|
12428
|
+
accountsChanged: this.createEthereumAccountChangeHandler(walletId, source)
|
|
12429
|
+
};
|
|
12430
|
+
provider.on("connect", handlers.connect);
|
|
12431
|
+
provider.on("disconnect", handlers.disconnect);
|
|
12432
|
+
provider.on("accountsChanged", handlers.accountsChanged);
|
|
12433
|
+
const cleanups = [];
|
|
12434
|
+
if (typeof provider.off === "function") {
|
|
12435
|
+
cleanups.push(
|
|
12436
|
+
() => provider.off("connect", handlers.connect),
|
|
12437
|
+
() => provider.off("disconnect", handlers.disconnect),
|
|
12438
|
+
() => provider.off("accountsChanged", handlers.accountsChanged)
|
|
12439
|
+
);
|
|
13495
12440
|
}
|
|
13496
|
-
|
|
12441
|
+
const existingCleanups = this.eventListenerCleanups.get(walletId) || [];
|
|
12442
|
+
this.eventListenerCleanups.set(walletId, [...existingCleanups, ...cleanups]);
|
|
12443
|
+
}
|
|
12444
|
+
/**
|
|
12445
|
+
* Unified event listener setup for all wallet types (Phantom and external)
|
|
12446
|
+
*/
|
|
12447
|
+
setupEventListeners(walletInfo) {
|
|
12448
|
+
const walletId = this.selectedWalletId || "phantom";
|
|
12449
|
+
if (this.eventListenersSetup.has(walletId)) {
|
|
12450
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Event listeners already set up for wallet", { walletId });
|
|
13497
12451
|
return;
|
|
13498
12452
|
}
|
|
13499
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
if (walletInfo.providers?.ethereum) {
|
|
13503
|
-
const handleExternalEthereumAccountsChanged = async (accounts) => {
|
|
13504
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "External wallet Ethereum accounts changed event received", {
|
|
13505
|
-
walletId: this.selectedWalletId,
|
|
13506
|
-
accounts
|
|
13507
|
-
});
|
|
13508
|
-
const walletId = this.selectedWalletId;
|
|
13509
|
-
const state = this.getWalletState(walletId);
|
|
13510
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.ethereum);
|
|
13511
|
-
if (accounts && accounts.length > 0) {
|
|
13512
|
-
const ethAddresses = accounts.map((address) => ({ addressType: exports.AddressType.ethereum, address }));
|
|
13513
|
-
const newAddresses = [...otherAddresses, ...ethAddresses];
|
|
13514
|
-
this.setWalletState(walletId, {
|
|
13515
|
-
connected: true,
|
|
13516
|
-
addresses: newAddresses
|
|
13517
|
-
});
|
|
13518
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "Updated Ethereum addresses after account change", {
|
|
13519
|
-
walletId,
|
|
13520
|
-
oldCount: 0,
|
|
13521
|
-
// We filtered them out
|
|
13522
|
-
newCount: accounts.length,
|
|
13523
|
-
addresses: newAddresses.filter((addr) => addr.addressType === exports.AddressType.ethereum)
|
|
13524
|
-
});
|
|
13525
|
-
const authUserId = await this.getAuthUserId("External wallet Ethereum accounts changed event");
|
|
13526
|
-
this.emit("connect", {
|
|
13527
|
-
addresses: newAddresses,
|
|
13528
|
-
source: "external-wallet-account-change",
|
|
13529
|
-
authUserId
|
|
13530
|
-
});
|
|
13531
|
-
} else {
|
|
13532
|
-
this.setWalletState(walletId, {
|
|
13533
|
-
connected: otherAddresses.length > 0,
|
|
13534
|
-
addresses: otherAddresses
|
|
13535
|
-
});
|
|
13536
|
-
this.emit("disconnect", {
|
|
13537
|
-
source: "external-wallet-account-change"
|
|
13538
|
-
});
|
|
13539
|
-
}
|
|
13540
|
-
};
|
|
13541
|
-
if (typeof walletInfo.providers.ethereum.on === "function") {
|
|
13542
|
-
walletInfo.providers.ethereum.on("accountsChanged", handleExternalEthereumAccountsChanged);
|
|
13543
|
-
this.browserInjectedCleanupFunctions.push(() => {
|
|
13544
|
-
if (typeof walletInfo.providers?.ethereum?.off === "function") {
|
|
13545
|
-
walletInfo.providers.ethereum.off("accountsChanged", handleExternalEthereumAccountsChanged);
|
|
13546
|
-
}
|
|
13547
|
-
});
|
|
13548
|
-
}
|
|
13549
|
-
}
|
|
13550
|
-
if (walletInfo.providers?.solana) {
|
|
13551
|
-
const handleExternalSolanaAccountChanged = async (publicKey) => {
|
|
13552
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "External wallet Solana account changed event received", {
|
|
13553
|
-
walletId: this.selectedWalletId,
|
|
13554
|
-
publicKey
|
|
13555
|
-
});
|
|
13556
|
-
const walletId = this.selectedWalletId;
|
|
13557
|
-
const state = this.getWalletState(walletId);
|
|
13558
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== exports.AddressType.solana);
|
|
13559
|
-
if (publicKey) {
|
|
13560
|
-
const newAddresses = [...otherAddresses, { addressType: exports.AddressType.solana, address: publicKey }];
|
|
13561
|
-
this.setWalletState(walletId, {
|
|
13562
|
-
connected: true,
|
|
13563
|
-
addresses: newAddresses
|
|
13564
|
-
});
|
|
13565
|
-
const authUserId = await this.getAuthUserId("External wallet Solana account changed event");
|
|
13566
|
-
this.emit("connect", {
|
|
13567
|
-
addresses: newAddresses,
|
|
13568
|
-
source: "external-wallet-account-change",
|
|
13569
|
-
authUserId
|
|
13570
|
-
});
|
|
13571
|
-
} else {
|
|
13572
|
-
this.setWalletState(walletId, {
|
|
13573
|
-
connected: otherAddresses.length > 0,
|
|
13574
|
-
addresses: otherAddresses
|
|
13575
|
-
});
|
|
13576
|
-
this.emit("disconnect", {
|
|
13577
|
-
source: "external-wallet-account-change"
|
|
13578
|
-
});
|
|
13579
|
-
}
|
|
13580
|
-
};
|
|
13581
|
-
if (typeof walletInfo.providers.solana.on === "function") {
|
|
13582
|
-
walletInfo.providers.solana.on("accountChanged", handleExternalSolanaAccountChanged);
|
|
13583
|
-
this.browserInjectedCleanupFunctions.push(() => {
|
|
13584
|
-
if (typeof walletInfo.providers?.solana?.off === "function") {
|
|
13585
|
-
walletInfo.providers.solana.off("accountChanged", handleExternalSolanaAccountChanged);
|
|
13586
|
-
}
|
|
13587
|
-
});
|
|
13588
|
-
}
|
|
12453
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up event listeners", { walletId });
|
|
12454
|
+
if (this.addressTypes.includes(exports.AddressType.solana) && walletInfo.providers?.solana) {
|
|
12455
|
+
this.setupSolanaEventListeners(walletInfo.providers.solana, walletId, "wallet");
|
|
13589
12456
|
}
|
|
13590
|
-
if (this.
|
|
13591
|
-
this.
|
|
12457
|
+
if (this.addressTypes.includes(exports.AddressType.ethereum) && walletInfo.providers?.ethereum) {
|
|
12458
|
+
this.setupEthereumEventListeners(walletInfo.providers.ethereum, walletId, "wallet");
|
|
13592
12459
|
}
|
|
12460
|
+
this.eventListenersSetup.add(walletId);
|
|
12461
|
+
this.eventsInitialized = true;
|
|
13593
12462
|
}
|
|
13594
12463
|
};
|
|
13595
12464
|
|
|
@@ -13891,7 +12760,7 @@ var BrowserAuthProvider = class {
|
|
|
13891
12760
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
13892
12761
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
13893
12762
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
13894
|
-
sdk_version: "1.0.
|
|
12763
|
+
sdk_version: "1.0.2",
|
|
13895
12764
|
sdk_type: "browser",
|
|
13896
12765
|
platform: detectBrowser().name
|
|
13897
12766
|
});
|
|
@@ -14146,7 +13015,7 @@ var EmbeddedProvider = class extends EmbeddedProvider$1 {
|
|
|
14146
13015
|
// Full user agent for more detailed info
|
|
14147
13016
|
[ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
14148
13017
|
[ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
14149
|
-
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.
|
|
13018
|
+
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.2"
|
|
14150
13019
|
// Replaced at build time
|
|
14151
13020
|
}
|
|
14152
13021
|
};
|
|
@@ -14425,7 +13294,7 @@ var ProviderManager = class {
|
|
|
14425
13294
|
if (!this.eventListeners.has(event)) {
|
|
14426
13295
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
14427
13296
|
}
|
|
14428
|
-
this.eventListeners.get(event)
|
|
13297
|
+
this.eventListeners.get(event)?.add(callback);
|
|
14429
13298
|
this.ensureProviderEventForwarding();
|
|
14430
13299
|
}
|
|
14431
13300
|
/**
|
|
@@ -14434,8 +13303,8 @@ var ProviderManager = class {
|
|
|
14434
13303
|
off(event, callback) {
|
|
14435
13304
|
debug.log(DebugCategory.PROVIDER_MANAGER, "Removing event listener", { event });
|
|
14436
13305
|
if (this.eventListeners.has(event)) {
|
|
14437
|
-
this.eventListeners.get(event)
|
|
14438
|
-
if (this.eventListeners.get(event)
|
|
13306
|
+
this.eventListeners.get(event)?.delete(callback);
|
|
13307
|
+
if (this.eventListeners.get(event)?.size === 0) {
|
|
14439
13308
|
this.eventListeners.delete(event);
|
|
14440
13309
|
}
|
|
14441
13310
|
}
|
|
@@ -15692,7 +14561,8 @@ function ConnectModalContent({
|
|
|
15692
14561
|
const isConnectingState = baseConnect.isConnecting || isConnecting;
|
|
15693
14562
|
const errorState = baseConnect.error ? baseConnect.error.message : error;
|
|
15694
14563
|
const showDivider = !(allowedProviders.length === 1 && allowedProviders.includes("injected"));
|
|
15695
|
-
const
|
|
14564
|
+
const isInjectedOnly = allowedProviders.length === 1 && allowedProviders.includes("injected");
|
|
14565
|
+
const shouldShowOtherWalletsButton = !isInjectedOnly && discoveredWallets.length > 2;
|
|
15696
14566
|
const walletsToShowInline = shouldShowOtherWalletsButton ? [] : discoveredWallets;
|
|
15697
14567
|
const connectWithAuthProvider = React.useCallback(
|
|
15698
14568
|
async (provider, walletId) => {
|
|
@@ -15961,7 +14831,7 @@ function ConnectModalContent({
|
|
|
15961
14831
|
] })
|
|
15962
14832
|
}
|
|
15963
14833
|
),
|
|
15964
|
-
allowedProviders.includes("injected") && (isExtensionInstalled.isInstalled || discoveredWallets.length > 0) &&
|
|
14834
|
+
allowedProviders.includes("injected") && (isExtensionInstalled.isInstalled || discoveredWallets.length > 0) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
15965
14835
|
showDivider && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: dividerStyle, children: [
|
|
15966
14836
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: dividerLineStyle }),
|
|
15967
14837
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: dividerTextStyle, children: "OR" }),
|
|
@@ -16540,4 +15410,4 @@ exports.useModal = useModal;
|
|
|
16540
15410
|
exports.usePhantom = usePhantom;
|
|
16541
15411
|
exports.useSolana = useSolana;
|
|
16542
15412
|
exports.useTheme = useTheme;
|
|
16543
|
-
//# sourceMappingURL=index-
|
|
15413
|
+
//# sourceMappingURL=index-BGYQ_HzF.js.map
|