@bit-buccaneers/wallet-abstraction 0.0.4 → 0.0.7
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/dev.js +306 -70
- package/dist/dev.jsx +314 -73
- package/dist/index.js +306 -70
- package/dist/index.jsx +314 -73
- package/dist/lib/connectors/binance.d.ts +1 -0
- package/dist/lib/connectors/bitget.d.ts +2 -0
- package/dist/lib/connectors/coinbase.d.ts +2 -0
- package/dist/lib/connectors/exodus.d.ts +1 -0
- package/dist/lib/connectors/index.d.ts +10 -6
- package/dist/lib/connectors/metamask.d.ts +1 -0
- package/dist/lib/connectors/okx.d.ts +2 -0
- package/dist/lib/connectors/phantom.d.ts +1 -0
- package/dist/lib/connectors/shared/dapp-browser.d.ts +10 -0
- package/dist/lib/connectors/shared/index.d.ts +1 -0
- package/dist/lib/connectors/solflare.d.ts +1 -0
- package/dist/lib/connectors/trust.d.ts +1 -0
- package/dist/lib/connectors/walletconnect.d.ts +4 -0
- package/dist/lib/core/types.d.ts +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/wallets/config.d.ts +2 -2
- package/package.json +1 -1
package/dist/dev.jsx
CHANGED
|
@@ -149,6 +149,11 @@ var WALLETS = [
|
|
|
149
149
|
name: "Exodus",
|
|
150
150
|
icon: "https://iconic.dynamic-static-assets.com/icons/sprite.svg#exodus",
|
|
151
151
|
chromeExtensionUrl: "https://chromewebstore.google.com/detail/aholpfdialjgjfhomihkjbmgjidlcdno"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "walletconnect",
|
|
155
|
+
name: "WalletConnect",
|
|
156
|
+
icon: "https://iconic.dynamic-static-assets.com/icons/sprite.svg#walletconnect"
|
|
152
157
|
}
|
|
153
158
|
];
|
|
154
159
|
|
|
@@ -200,8 +205,95 @@ var SOLANA_WC_CONFIG = {
|
|
|
200
205
|
events: WC_EVENTS.SOLANA
|
|
201
206
|
};
|
|
202
207
|
|
|
203
|
-
// src/lib/connectors/shared/
|
|
208
|
+
// src/lib/connectors/shared/injected.ts
|
|
204
209
|
import bs58 from "bs58";
|
|
210
|
+
var connectEvmInjected = async () => {
|
|
211
|
+
if (!window.ethereum) throw new Error("No injected EVM provider");
|
|
212
|
+
const accounts = await window.ethereum.request({
|
|
213
|
+
method: "eth_requestAccounts"
|
|
214
|
+
});
|
|
215
|
+
if (!accounts[0]) throw new Error("No accounts returned");
|
|
216
|
+
const chainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
217
|
+
return connectedResult(accounts[0], { chainId: parseInt(chainId, 16) });
|
|
218
|
+
};
|
|
219
|
+
var connectSolanaInjected = async () => {
|
|
220
|
+
if (!window.solana) throw new Error("No injected Solana provider");
|
|
221
|
+
const response = await window.solana.connect();
|
|
222
|
+
const publicKey = response.publicKey;
|
|
223
|
+
return connectedResult(publicKey.toBase58(), { publicKey: publicKey.toBytes() });
|
|
224
|
+
};
|
|
225
|
+
var signSolanaInjected = async (message) => {
|
|
226
|
+
if (!window.solana?.signMessage) {
|
|
227
|
+
throw new Error("No injected Solana provider or signMessage not supported");
|
|
228
|
+
}
|
|
229
|
+
const encodedMessage = new TextEncoder().encode(message);
|
|
230
|
+
const result = await window.solana.signMessage(encodedMessage, "utf8");
|
|
231
|
+
return bs58.encode(new Uint8Array(result.signature));
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// src/lib/connectors/shared/utils.ts
|
|
235
|
+
var isMobile = () => {
|
|
236
|
+
return typeof window !== "undefined" && /iPhone|iPad|iPod|Android/i.test(window.navigator.userAgent);
|
|
237
|
+
};
|
|
238
|
+
var isInWalletBrowser = (key) => {
|
|
239
|
+
return typeof window !== "undefined" && !!window.ethereum?.[key];
|
|
240
|
+
};
|
|
241
|
+
var openDeeplink = (url) => {
|
|
242
|
+
const link = document.createElement("a");
|
|
243
|
+
link.href = url;
|
|
244
|
+
link.click();
|
|
245
|
+
};
|
|
246
|
+
var waitForValue = (getValue) => {
|
|
247
|
+
return new Promise((resolve) => {
|
|
248
|
+
const check = () => {
|
|
249
|
+
const value = getValue();
|
|
250
|
+
if (value != null) resolve(value);
|
|
251
|
+
else window.setTimeout(check, 50);
|
|
252
|
+
};
|
|
253
|
+
check();
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/lib/connectors/shared/dapp-browser.ts
|
|
258
|
+
var buildBrowseUrl = (config2) => {
|
|
259
|
+
if (config2.buildUrl) return config2.buildUrl();
|
|
260
|
+
if (config2.stripProtocol) {
|
|
261
|
+
return `${config2.browseUrl}/${window.location.host}${window.location.pathname}${window.location.search}`;
|
|
262
|
+
}
|
|
263
|
+
return `${config2.browseUrl}/${encodeURIComponent(window.location.href)}`;
|
|
264
|
+
};
|
|
265
|
+
var createDappBrowserSolanaConnector = (config2) => {
|
|
266
|
+
const walletConfig2 = WALLETS.find((w) => w.id === config2.walletId);
|
|
267
|
+
const isInWallet = () => isInWalletBrowser(config2.injectedKey);
|
|
268
|
+
return {
|
|
269
|
+
...walletConfig2,
|
|
270
|
+
type: "solana",
|
|
271
|
+
wallet: {
|
|
272
|
+
_provider: null,
|
|
273
|
+
connect: async () => {
|
|
274
|
+
if (isInWallet() && window.solana) {
|
|
275
|
+
return connectSolanaInjected();
|
|
276
|
+
}
|
|
277
|
+
window.location.href = buildBrowseUrl(config2);
|
|
278
|
+
return pendingResult();
|
|
279
|
+
},
|
|
280
|
+
disconnect: async () => {
|
|
281
|
+
if (window.solana?.disconnect) {
|
|
282
|
+
await window.solana.disconnect();
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
signMessage: async (message) => {
|
|
286
|
+
if (isInWallet() && window.solana) {
|
|
287
|
+
return signSolanaInjected(message);
|
|
288
|
+
}
|
|
289
|
+
throw new Error("signMessage requires dApp browser");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/lib/connectors/shared/deeplink.ts
|
|
296
|
+
import bs582 from "bs58";
|
|
205
297
|
import nacl from "tweetnacl";
|
|
206
298
|
var getDappKeyPair = (storageKey) => {
|
|
207
299
|
const stored = storage.get(storageKey);
|
|
@@ -222,7 +314,7 @@ var buildConnectUrl = (config2, params) => {
|
|
|
222
314
|
const keyPair = getDappKeyPair(`${config2.storageKeyPrefix}_keypair`);
|
|
223
315
|
const url = new URL(config2.connectUrl);
|
|
224
316
|
url.searchParams.set("app_url", params.appUrl);
|
|
225
|
-
url.searchParams.set("dapp_encryption_public_key",
|
|
317
|
+
url.searchParams.set("dapp_encryption_public_key", bs582.encode(keyPair.publicKey));
|
|
226
318
|
url.searchParams.set("redirect_link", params.redirectUrl);
|
|
227
319
|
if (params.cluster) {
|
|
228
320
|
url.searchParams.set("cluster", params.cluster);
|
|
@@ -241,8 +333,8 @@ var parseConnectResponse = (urlParams, config2) => {
|
|
|
241
333
|
}
|
|
242
334
|
try {
|
|
243
335
|
const keyPair = getDappKeyPair(`${config2.storageKeyPrefix}_keypair`);
|
|
244
|
-
const sharedSecret = nacl.box.before(
|
|
245
|
-
const decrypted = nacl.box.open.after(
|
|
336
|
+
const sharedSecret = nacl.box.before(bs582.decode(walletPublicKey), keyPair.secretKey);
|
|
337
|
+
const decrypted = nacl.box.open.after(bs582.decode(data), bs582.decode(nonce), sharedSecret);
|
|
246
338
|
if (!decrypted) {
|
|
247
339
|
return null;
|
|
248
340
|
}
|
|
@@ -292,7 +384,7 @@ var buildSignMessageUrl = (signUrl, config2, sessionKey, message, redirectUrl) =
|
|
|
292
384
|
const keyPair = getDappKeyPair(`${config2.storageKeyPrefix}_keypair`);
|
|
293
385
|
const sharedSecret = new Uint8Array(session.sharedSecret);
|
|
294
386
|
const payload = {
|
|
295
|
-
message:
|
|
387
|
+
message: bs582.encode(new TextEncoder().encode(message)),
|
|
296
388
|
session: session.session,
|
|
297
389
|
display: "utf8"
|
|
298
390
|
};
|
|
@@ -303,10 +395,10 @@ var buildSignMessageUrl = (signUrl, config2, sessionKey, message, redirectUrl) =
|
|
|
303
395
|
sharedSecret
|
|
304
396
|
);
|
|
305
397
|
const url = new URL(signUrl);
|
|
306
|
-
url.searchParams.set("dapp_encryption_public_key",
|
|
307
|
-
url.searchParams.set("nonce",
|
|
398
|
+
url.searchParams.set("dapp_encryption_public_key", bs582.encode(keyPair.publicKey));
|
|
399
|
+
url.searchParams.set("nonce", bs582.encode(nonce));
|
|
308
400
|
url.searchParams.set("redirect_link", redirectUrl);
|
|
309
|
-
url.searchParams.set("payload",
|
|
401
|
+
url.searchParams.set("payload", bs582.encode(encrypted));
|
|
310
402
|
return url.toString();
|
|
311
403
|
};
|
|
312
404
|
var parseSignMessageResponse = (config2, sessionKey) => {
|
|
@@ -318,7 +410,7 @@ var parseSignMessageResponse = (config2, sessionKey) => {
|
|
|
318
410
|
if (!session) return null;
|
|
319
411
|
try {
|
|
320
412
|
const sharedSecret = new Uint8Array(session.sharedSecret);
|
|
321
|
-
const decrypted = nacl.box.open.after(
|
|
413
|
+
const decrypted = nacl.box.open.after(bs582.decode(data), bs582.decode(nonce), sharedSecret);
|
|
322
414
|
if (!decrypted) return null;
|
|
323
415
|
const response = JSON.parse(new TextDecoder().decode(decrypted));
|
|
324
416
|
return response.signature;
|
|
@@ -327,32 +419,6 @@ var parseSignMessageResponse = (config2, sessionKey) => {
|
|
|
327
419
|
}
|
|
328
420
|
};
|
|
329
421
|
|
|
330
|
-
// src/lib/connectors/shared/injected.ts
|
|
331
|
-
import bs582 from "bs58";
|
|
332
|
-
var connectEvmInjected = async () => {
|
|
333
|
-
if (!window.ethereum) throw new Error("No injected EVM provider");
|
|
334
|
-
const accounts = await window.ethereum.request({
|
|
335
|
-
method: "eth_requestAccounts"
|
|
336
|
-
});
|
|
337
|
-
if (!accounts[0]) throw new Error("No accounts returned");
|
|
338
|
-
const chainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
339
|
-
return connectedResult(accounts[0], { chainId: parseInt(chainId, 16) });
|
|
340
|
-
};
|
|
341
|
-
var connectSolanaInjected = async () => {
|
|
342
|
-
if (!window.solana) throw new Error("No injected Solana provider");
|
|
343
|
-
const response = await window.solana.connect();
|
|
344
|
-
const publicKey = response.publicKey;
|
|
345
|
-
return connectedResult(publicKey.toBase58(), { publicKey: publicKey.toBytes() });
|
|
346
|
-
};
|
|
347
|
-
var signSolanaInjected = async (message) => {
|
|
348
|
-
if (!window.solana?.signMessage) {
|
|
349
|
-
throw new Error("No injected Solana provider or signMessage not supported");
|
|
350
|
-
}
|
|
351
|
-
const encodedMessage = new TextEncoder().encode(message);
|
|
352
|
-
const result = await window.solana.signMessage(encodedMessage, "utf8");
|
|
353
|
-
return bs582.encode(new Uint8Array(result.signature));
|
|
354
|
-
};
|
|
355
|
-
|
|
356
422
|
// src/lib/connectors/shared/parsers.ts
|
|
357
423
|
var parseEvmAccount = (account) => {
|
|
358
424
|
const [, chainIdStr, address] = account.split(":");
|
|
@@ -362,8 +428,8 @@ var parseEvmAccount = (account) => {
|
|
|
362
428
|
var parseSolanaAccount = async (account) => {
|
|
363
429
|
const address = account.split(":")[2];
|
|
364
430
|
if (!address) throw new Error("Invalid Solana account format");
|
|
365
|
-
const { default:
|
|
366
|
-
return connectedResult(address, { publicKey:
|
|
431
|
+
const { default: bs587 } = await import("bs58");
|
|
432
|
+
return connectedResult(address, { publicKey: bs587.decode(address) });
|
|
367
433
|
};
|
|
368
434
|
var getEvmAccountFromSession = (namespaces) => {
|
|
369
435
|
const account = namespaces.eip155?.accounts?.[0];
|
|
@@ -376,29 +442,6 @@ var getSolanaAccountFromSession = async (namespaces) => {
|
|
|
376
442
|
return parseSolanaAccount(account);
|
|
377
443
|
};
|
|
378
444
|
|
|
379
|
-
// src/lib/connectors/shared/utils.ts
|
|
380
|
-
var isMobile = () => {
|
|
381
|
-
return typeof window !== "undefined" && /iPhone|iPad|iPod|Android/i.test(window.navigator.userAgent);
|
|
382
|
-
};
|
|
383
|
-
var isInWalletBrowser = (key) => {
|
|
384
|
-
return typeof window !== "undefined" && !!window.ethereum?.[key];
|
|
385
|
-
};
|
|
386
|
-
var openDeeplink = (url) => {
|
|
387
|
-
const link = document.createElement("a");
|
|
388
|
-
link.href = url;
|
|
389
|
-
link.click();
|
|
390
|
-
};
|
|
391
|
-
var waitForValue = (getValue) => {
|
|
392
|
-
return new Promise((resolve) => {
|
|
393
|
-
const check = () => {
|
|
394
|
-
const value = getValue();
|
|
395
|
-
if (value != null) resolve(value);
|
|
396
|
-
else window.setTimeout(check, 50);
|
|
397
|
-
};
|
|
398
|
-
check();
|
|
399
|
-
});
|
|
400
|
-
};
|
|
401
|
-
|
|
402
445
|
// src/lib/walletconnect/client.ts
|
|
403
446
|
import { SignClient } from "@walletconnect/sign-client";
|
|
404
447
|
var signClient = null;
|
|
@@ -573,11 +616,11 @@ var disconnectWcOrSolana = async () => {
|
|
|
573
616
|
}
|
|
574
617
|
};
|
|
575
618
|
var createWcEvmConnector = (config2) => {
|
|
576
|
-
const
|
|
619
|
+
const walletConfig2 = WALLETS.find((w) => w.id === config2.walletId);
|
|
577
620
|
const getDeeplink = createDeeplink(config2.wcDeeplink);
|
|
578
621
|
const isInWallet = () => isInWalletBrowser(config2.injectedKey);
|
|
579
622
|
return {
|
|
580
|
-
...
|
|
623
|
+
...walletConfig2,
|
|
581
624
|
type: "evm",
|
|
582
625
|
wallet: {
|
|
583
626
|
_connector: null,
|
|
@@ -618,11 +661,11 @@ var createWcEvmConnector = (config2) => {
|
|
|
618
661
|
};
|
|
619
662
|
};
|
|
620
663
|
var createWcSolanaConnector = (config2) => {
|
|
621
|
-
const
|
|
664
|
+
const walletConfig2 = WALLETS.find((w) => w.id === config2.walletId);
|
|
622
665
|
const getDeeplink = createDeeplink(config2.wcDeeplink);
|
|
623
666
|
const isInWallet = () => isInWalletBrowser(config2.injectedKey);
|
|
624
667
|
return {
|
|
625
|
-
...
|
|
668
|
+
...walletConfig2,
|
|
626
669
|
type: "solana",
|
|
627
670
|
wallet: {
|
|
628
671
|
_provider: null,
|
|
@@ -662,6 +705,11 @@ var createWcSolanaConnector = (config2) => {
|
|
|
662
705
|
var PHANTOM_CONNECT_URL = "https://phantom.app/ul/v1/connect";
|
|
663
706
|
var PHANTOM_SIGN_MESSAGE_URL = "https://phantom.app/ul/v1/signMessage";
|
|
664
707
|
var PHANTOM_BROWSE_URL = "https://phantom.app/ul/browse";
|
|
708
|
+
var createPhantomSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
709
|
+
walletId: "phantom",
|
|
710
|
+
browseUrl: PHANTOM_BROWSE_URL,
|
|
711
|
+
injectedKey: "isPhantom"
|
|
712
|
+
});
|
|
665
713
|
var PHANTOM_CONFIG = {
|
|
666
714
|
connectUrl: PHANTOM_CONNECT_URL,
|
|
667
715
|
storageKeyPrefix: "phantom_mobile",
|
|
@@ -758,11 +806,24 @@ var METAMASK_CONFIG = {
|
|
|
758
806
|
wcDeeplink: "https://metamask.app.link/wc",
|
|
759
807
|
injectedKey: "isMetaMask"
|
|
760
808
|
};
|
|
809
|
+
var METAMASK_BROWSE_URL = "https://metamask.app.link/dapp";
|
|
761
810
|
var createMetaMaskEvmConnector = () => createWcEvmConnector(METAMASK_CONFIG);
|
|
811
|
+
var createMetaMaskSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
812
|
+
walletId: "metamask",
|
|
813
|
+
browseUrl: METAMASK_BROWSE_URL,
|
|
814
|
+
injectedKey: "isMetaMask",
|
|
815
|
+
stripProtocol: true
|
|
816
|
+
});
|
|
762
817
|
|
|
763
818
|
// src/lib/connectors/solflare.ts
|
|
764
819
|
var SOLFLARE_CONNECT_URL = "https://solflare.com/ul/v1/connect";
|
|
765
820
|
var SOLFLARE_SIGN_MESSAGE_URL = "https://solflare.com/ul/v1/signMessage";
|
|
821
|
+
var SOLFLARE_BROWSE_URL = "https://solflare.com/ul/v1/browse";
|
|
822
|
+
var createSolflareSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
823
|
+
walletId: "solflare",
|
|
824
|
+
browseUrl: SOLFLARE_BROWSE_URL,
|
|
825
|
+
injectedKey: "isSolflare"
|
|
826
|
+
});
|
|
766
827
|
var SOLFLARE_CONFIG = {
|
|
767
828
|
connectUrl: SOLFLARE_CONNECT_URL,
|
|
768
829
|
storageKeyPrefix: "solflare_mobile",
|
|
@@ -832,8 +893,14 @@ var TRUST_CONFIG = {
|
|
|
832
893
|
wcDeeplink: "https://link.trustwallet.com/wc",
|
|
833
894
|
injectedKey: "isTrust"
|
|
834
895
|
};
|
|
896
|
+
var TRUST_BROWSE_URL = "https://link.trustwallet.com/open_url";
|
|
835
897
|
var createTrustEvmMobileConnector = () => createWcEvmConnector(TRUST_CONFIG);
|
|
836
898
|
var createTrustSolanaMobileConnector = () => createWcSolanaConnector(TRUST_CONFIG);
|
|
899
|
+
var createTrustSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
900
|
+
walletId: "trust",
|
|
901
|
+
browseUrl: TRUST_BROWSE_URL,
|
|
902
|
+
injectedKey: "isTrust"
|
|
903
|
+
});
|
|
837
904
|
|
|
838
905
|
// src/lib/connectors/rainbow.ts
|
|
839
906
|
var RAINBOW_CONFIG = {
|
|
@@ -849,8 +916,14 @@ var EXODUS_CONFIG = {
|
|
|
849
916
|
wcDeeplink: "https://exodus.com/wc",
|
|
850
917
|
injectedKey: "isExodus"
|
|
851
918
|
};
|
|
919
|
+
var EXODUS_BROWSE_URL = "https://exodus.com/m/browser";
|
|
852
920
|
var createExodusEvmMobileConnector = () => createWcEvmConnector(EXODUS_CONFIG);
|
|
853
921
|
var createExodusSolanaMobileConnector = () => createWcSolanaConnector(EXODUS_CONFIG);
|
|
922
|
+
var createExodusSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
923
|
+
walletId: "exodus",
|
|
924
|
+
browseUrl: EXODUS_BROWSE_URL,
|
|
925
|
+
injectedKey: "isExodus"
|
|
926
|
+
});
|
|
854
927
|
|
|
855
928
|
// src/lib/connectors/binance.ts
|
|
856
929
|
var BINANCE_CONFIG = {
|
|
@@ -858,8 +931,121 @@ var BINANCE_CONFIG = {
|
|
|
858
931
|
wcDeeplink: "bnc://app.binance.com/cedefi/wc",
|
|
859
932
|
injectedKey: "isBinance"
|
|
860
933
|
};
|
|
934
|
+
var buildBinanceBrowseUrl = () => `bnc://app.binance.com/cedefi/dapp?url=${encodeURIComponent(window.location.href)}`;
|
|
861
935
|
var createBinanceEvmConnector = () => createWcEvmConnector(BINANCE_CONFIG);
|
|
862
936
|
var createBinanceSolanaConnector = () => createWcSolanaConnector(BINANCE_CONFIG);
|
|
937
|
+
var createBinanceSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
938
|
+
walletId: "binance",
|
|
939
|
+
injectedKey: "isBinance",
|
|
940
|
+
buildUrl: buildBinanceBrowseUrl
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
// src/lib/connectors/okx.ts
|
|
944
|
+
var buildOkxBrowseUrl = () => {
|
|
945
|
+
const dappUrl = window.location.href;
|
|
946
|
+
const deepLink = `okx://wallet/dapp/url?dappUrl=${encodeURIComponent(dappUrl)}`;
|
|
947
|
+
return `https://web3.okx.com/download?deeplink=${encodeURIComponent(deepLink)}`;
|
|
948
|
+
};
|
|
949
|
+
var createOkxSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
950
|
+
walletId: "okx",
|
|
951
|
+
injectedKey: "isOkxWallet",
|
|
952
|
+
buildUrl: buildOkxBrowseUrl
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
// src/lib/connectors/coinbase.ts
|
|
956
|
+
var buildCoinbaseBrowseUrl = () => `cbwallet://dapp?url=${encodeURIComponent(window.location.href)}`;
|
|
957
|
+
var createCoinbaseSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
958
|
+
walletId: "coinbase",
|
|
959
|
+
injectedKey: "isCoinbaseWallet",
|
|
960
|
+
buildUrl: buildCoinbaseBrowseUrl
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// src/lib/connectors/bitget.ts
|
|
964
|
+
var BITGET_BROWSE_URL = "https://bkcode.vip/dapp";
|
|
965
|
+
var createBitgetSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
966
|
+
walletId: "bitget",
|
|
967
|
+
browseUrl: BITGET_BROWSE_URL,
|
|
968
|
+
injectedKey: "isBitKeep",
|
|
969
|
+
stripProtocol: true
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
// src/lib/connectors/walletconnect.ts
|
|
973
|
+
import bs584 from "bs58";
|
|
974
|
+
var walletConfig = WALLETS.find((w) => w.id === "walletconnect");
|
|
975
|
+
var disconnectWc2 = async () => {
|
|
976
|
+
if (getCurrentSession()) {
|
|
977
|
+
await disconnectWalletConnect();
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
var createWalletConnectEvmConnector = () => {
|
|
981
|
+
if (isMobile()) return null;
|
|
982
|
+
return {
|
|
983
|
+
id: walletConfig.id,
|
|
984
|
+
name: walletConfig.name,
|
|
985
|
+
icon: walletConfig.icon,
|
|
986
|
+
type: "evm",
|
|
987
|
+
installed: false,
|
|
988
|
+
wallet: {
|
|
989
|
+
_connector: null,
|
|
990
|
+
connect: async () => {
|
|
991
|
+
return connectViaWalletConnect(EVM_WC_CONFIG, getEvmAccountFromSession);
|
|
992
|
+
},
|
|
993
|
+
disconnect: disconnectWc2,
|
|
994
|
+
signMessage: async (message) => {
|
|
995
|
+
const session = getCurrentSession();
|
|
996
|
+
if (!session) {
|
|
997
|
+
throw new Error("No WalletConnect session");
|
|
998
|
+
}
|
|
999
|
+
const account = session.namespaces.eip155?.accounts?.[0];
|
|
1000
|
+
if (!account) {
|
|
1001
|
+
throw new Error("No EVM account in session");
|
|
1002
|
+
}
|
|
1003
|
+
const address = account.split(":")[2];
|
|
1004
|
+
const result = await requestWalletConnect(
|
|
1005
|
+
"personal_sign",
|
|
1006
|
+
[message, address],
|
|
1007
|
+
WC_CHAINS.EVM_MAINNET
|
|
1008
|
+
);
|
|
1009
|
+
return result;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
};
|
|
1014
|
+
var createWalletConnectSolanaConnector = () => {
|
|
1015
|
+
if (isMobile()) return null;
|
|
1016
|
+
return {
|
|
1017
|
+
id: walletConfig.id,
|
|
1018
|
+
name: walletConfig.name,
|
|
1019
|
+
icon: walletConfig.icon,
|
|
1020
|
+
type: "solana",
|
|
1021
|
+
installed: false,
|
|
1022
|
+
wallet: {
|
|
1023
|
+
_provider: null,
|
|
1024
|
+
connect: async () => {
|
|
1025
|
+
return connectViaWalletConnect(SOLANA_WC_CONFIG, getSolanaAccountFromSession);
|
|
1026
|
+
},
|
|
1027
|
+
disconnect: disconnectWc2,
|
|
1028
|
+
signMessage: async (message) => {
|
|
1029
|
+
const session = getCurrentSession();
|
|
1030
|
+
if (!session) {
|
|
1031
|
+
throw new Error("No WalletConnect session");
|
|
1032
|
+
}
|
|
1033
|
+
const account = session.namespaces.solana?.accounts?.[0];
|
|
1034
|
+
if (!account) {
|
|
1035
|
+
throw new Error("No Solana account in session");
|
|
1036
|
+
}
|
|
1037
|
+
const pubkey = account.split(":")[2];
|
|
1038
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
1039
|
+
const result = await requestWalletConnect(
|
|
1040
|
+
"solana_signMessage",
|
|
1041
|
+
{ message: bs584.encode(messageBytes), pubkey },
|
|
1042
|
+
WC_CHAINS.SOLANA_MAINNET
|
|
1043
|
+
);
|
|
1044
|
+
return result.signature;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
};
|
|
863
1049
|
|
|
864
1050
|
// src/lib/evm/connectors.ts
|
|
865
1051
|
var EVM_FALLBACK_CONNECTORS = [
|
|
@@ -929,7 +1115,7 @@ import {
|
|
|
929
1115
|
isWalletAdapterCompatibleStandardWallet
|
|
930
1116
|
} from "@solana/wallet-adapter-base";
|
|
931
1117
|
import { getWallets } from "@wallet-standard/app";
|
|
932
|
-
import
|
|
1118
|
+
import bs585 from "bs58";
|
|
933
1119
|
var createSolanaConnector = (provider) => {
|
|
934
1120
|
const id = normalizeSolanaWalletId(provider.name.toLowerCase().replace(/\s+/g, "-"));
|
|
935
1121
|
const connector = {
|
|
@@ -973,7 +1159,7 @@ var createSolanaConnector = (provider) => {
|
|
|
973
1159
|
const result = await signFeature.signMessage({ message: encodedMessage, account });
|
|
974
1160
|
const signature = result[0]?.signature;
|
|
975
1161
|
if (!signature) throw new Error("No signature returned");
|
|
976
|
-
return
|
|
1162
|
+
return bs585.encode(signature);
|
|
977
1163
|
}
|
|
978
1164
|
}
|
|
979
1165
|
};
|
|
@@ -990,16 +1176,59 @@ var createSolanaMobileConnector = (connector) => ({
|
|
|
990
1176
|
}
|
|
991
1177
|
}
|
|
992
1178
|
});
|
|
993
|
-
var SOLANA_FALLBACK_CONNECTORS = [
|
|
1179
|
+
var SOLANA_FALLBACK_CONNECTORS = isMobile() ? [
|
|
1180
|
+
{
|
|
1181
|
+
id: "phantom",
|
|
1182
|
+
create: () => createSolanaMobileConnector(createPhantomSolanaDappBrowserConnector())
|
|
1183
|
+
},
|
|
1184
|
+
{
|
|
1185
|
+
id: "solflare",
|
|
1186
|
+
create: () => createSolanaMobileConnector(createSolflareSolanaDappBrowserConnector())
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
id: "metamask",
|
|
1190
|
+
create: () => createSolanaMobileConnector(createMetaMaskSolanaDappBrowserConnector())
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
id: "okx",
|
|
1194
|
+
create: () => createSolanaMobileConnector(createOkxSolanaDappBrowserConnector())
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
id: "coinbase",
|
|
1198
|
+
create: () => createSolanaMobileConnector(createCoinbaseSolanaDappBrowserConnector())
|
|
1199
|
+
},
|
|
1200
|
+
{
|
|
1201
|
+
id: "bitget",
|
|
1202
|
+
create: () => createSolanaMobileConnector(createBitgetSolanaDappBrowserConnector())
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
id: "trust",
|
|
1206
|
+
create: () => createSolanaMobileConnector(createTrustSolanaDappBrowserConnector())
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
id: "binance",
|
|
1210
|
+
create: () => createSolanaMobileConnector(createBinanceSolanaDappBrowserConnector())
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
id: "exodus",
|
|
1214
|
+
create: () => createSolanaMobileConnector(createExodusSolanaDappBrowserConnector())
|
|
1215
|
+
}
|
|
1216
|
+
] : [
|
|
994
1217
|
{ id: "phantom", create: () => createSolanaMobileConnector(createPhantomSolanaConnector()) },
|
|
995
1218
|
// { id: 'metamask', create: () => createSolanaMobileConnector(createMetaMaskSolanaConnector()) },
|
|
996
1219
|
{
|
|
997
1220
|
id: "solflare",
|
|
998
1221
|
create: () => createSolanaMobileConnector(createSolflareSolanaMobileConnector())
|
|
999
1222
|
},
|
|
1000
|
-
{
|
|
1223
|
+
{
|
|
1224
|
+
id: "trust",
|
|
1225
|
+
create: () => createSolanaMobileConnector(createTrustSolanaMobileConnector())
|
|
1226
|
+
},
|
|
1001
1227
|
{ id: "binance", create: () => createSolanaMobileConnector(createBinanceSolanaConnector()) },
|
|
1002
|
-
{
|
|
1228
|
+
{
|
|
1229
|
+
id: "exodus",
|
|
1230
|
+
create: () => createSolanaMobileConnector(createExodusSolanaMobileConnector())
|
|
1231
|
+
}
|
|
1003
1232
|
];
|
|
1004
1233
|
var getSolanaWallets = () => {
|
|
1005
1234
|
const { get } = getWallets();
|
|
@@ -1109,7 +1338,12 @@ var useEvmWallet = (options) => {
|
|
|
1109
1338
|
const [connectedConnector, setConnectedConnector] = createSignal(null);
|
|
1110
1339
|
onMount(() => {
|
|
1111
1340
|
createEvmConfig(options.chains);
|
|
1112
|
-
|
|
1341
|
+
const connectors = getEvmConnectors();
|
|
1342
|
+
const wcConnector = createWalletConnectEvmConnector();
|
|
1343
|
+
if (wcConnector) {
|
|
1344
|
+
connectors.unshift(wcConnector);
|
|
1345
|
+
}
|
|
1346
|
+
setEvmConnectors(connectors);
|
|
1113
1347
|
const unsubscribe = watchEvmConnections((connections) => {
|
|
1114
1348
|
const connection = connections[0];
|
|
1115
1349
|
if (connection && connection.accounts[0]) {
|
|
@@ -1158,7 +1392,12 @@ var useSolanaWallet = () => {
|
|
|
1158
1392
|
null
|
|
1159
1393
|
);
|
|
1160
1394
|
onMount2(() => {
|
|
1161
|
-
|
|
1395
|
+
const connectors = getSolanaWallets();
|
|
1396
|
+
const wcConnector = createWalletConnectSolanaConnector();
|
|
1397
|
+
if (wcConnector) {
|
|
1398
|
+
connectors.unshift(wcConnector);
|
|
1399
|
+
}
|
|
1400
|
+
setSolanaConnectors(connectors);
|
|
1162
1401
|
const unsubscribeWallets = onSolanaWalletsChange(setSolanaConnectors);
|
|
1163
1402
|
const unsubscribeConnection = watchSolanaConnection((state) => {
|
|
1164
1403
|
setSolanaConnection(state.connection);
|
|
@@ -1211,7 +1450,7 @@ var useSolanaWallet = () => {
|
|
|
1211
1450
|
};
|
|
1212
1451
|
|
|
1213
1452
|
// src/lib/context/hooks/useWalletConnect.ts
|
|
1214
|
-
import
|
|
1453
|
+
import bs586 from "bs58";
|
|
1215
1454
|
import { onCleanup as onCleanup3, onMount as onMount3 } from "solid-js";
|
|
1216
1455
|
var useWalletConnect = (options) => {
|
|
1217
1456
|
onMount3(async () => {
|
|
@@ -1266,7 +1505,7 @@ var useWalletConnect = (options) => {
|
|
|
1266
1505
|
const messageBytes = new TextEncoder().encode(message);
|
|
1267
1506
|
const result = await requestWalletConnect(
|
|
1268
1507
|
"solana_signMessage",
|
|
1269
|
-
{ message:
|
|
1508
|
+
{ message: bs586.encode(messageBytes), pubkey },
|
|
1270
1509
|
WC_CHAINS.SOLANA_MAINNET
|
|
1271
1510
|
);
|
|
1272
1511
|
return result.signature;
|
|
@@ -1373,11 +1612,13 @@ export {
|
|
|
1373
1612
|
checkPhantomSignCallback,
|
|
1374
1613
|
checkSolflareSignCallback,
|
|
1375
1614
|
createEvmConfig,
|
|
1615
|
+
getCurrentSession,
|
|
1376
1616
|
getEvmConfig,
|
|
1377
1617
|
getEvmConnectors,
|
|
1378
1618
|
getSolanaWallets,
|
|
1379
1619
|
initWalletConnect,
|
|
1380
1620
|
onSolanaWalletsChange,
|
|
1621
|
+
onWalletConnectSessionChange,
|
|
1381
1622
|
reconnectSolana,
|
|
1382
1623
|
useWallet,
|
|
1383
1624
|
watchEvmConnections,
|