@bit-buccaneers/wallet-abstraction 0.0.17 → 0.0.19
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 +273 -232
- package/dist/dev.jsx +295 -251
- package/dist/index.js +273 -232
- package/dist/index.jsx +295 -251
- package/dist/lib/connectors/coinbase.d.ts +1 -0
- package/dist/lib/connectors/index.d.ts +1 -1
- package/dist/lib/connectors/shared/wc-connector-factory.d.ts +2 -0
- package/package.json +3 -1
package/dist/index.jsx
CHANGED
|
@@ -383,8 +383,8 @@ var parseEvmAccount = (account) => {
|
|
|
383
383
|
var parseSolanaAccount = async (account) => {
|
|
384
384
|
const address = account.split(":")[2];
|
|
385
385
|
if (!address) throw new Error("Invalid Solana account format");
|
|
386
|
-
const { default:
|
|
387
|
-
return connectedResult(address, { publicKey:
|
|
386
|
+
const { default: bs588 } = await import("bs58");
|
|
387
|
+
return connectedResult(address, { publicKey: bs588.decode(address) });
|
|
388
388
|
};
|
|
389
389
|
var getEvmAccountFromSession = (namespaces) => {
|
|
390
390
|
const account = namespaces.eip155?.accounts?.[0];
|
|
@@ -620,7 +620,7 @@ var disconnectWcOrSolana = async () => {
|
|
|
620
620
|
};
|
|
621
621
|
var createWcEvmConnector = (config2) => {
|
|
622
622
|
const walletConfig2 = WALLETS.find((w) => w.id === config2.walletId);
|
|
623
|
-
const getDeeplink = createDeeplink(config2.wcDeeplink);
|
|
623
|
+
const getDeeplink = config2.getDeeplink ?? createDeeplink(config2.wcDeeplink);
|
|
624
624
|
const isInWallet = () => isInWalletBrowser(config2.injectedKey);
|
|
625
625
|
return {
|
|
626
626
|
...walletConfig2,
|
|
@@ -665,7 +665,7 @@ var createWcEvmConnector = (config2) => {
|
|
|
665
665
|
};
|
|
666
666
|
var createWcSolanaConnector = (config2) => {
|
|
667
667
|
const walletConfig2 = WALLETS.find((w) => w.id === config2.walletId);
|
|
668
|
-
const getDeeplink = createDeeplink(config2.wcDeeplink);
|
|
668
|
+
const getDeeplink = config2.getDeeplink ?? createDeeplink(config2.wcDeeplink);
|
|
669
669
|
const isInWallet = () => isInWalletBrowser(config2.injectedKey);
|
|
670
670
|
return {
|
|
671
671
|
...walletConfig2,
|
|
@@ -881,7 +881,7 @@ var createRabbyEvmConnector = () => createDownloadOnlyEvmConnector({ walletId: "
|
|
|
881
881
|
// src/lib/connectors/binance.ts
|
|
882
882
|
var BINANCE_CONFIG = {
|
|
883
883
|
walletId: "binance",
|
|
884
|
-
wcDeeplink: "
|
|
884
|
+
wcDeeplink: "https://app.binance.com/cedefi/wc",
|
|
885
885
|
injectedKey: "isBinance"
|
|
886
886
|
};
|
|
887
887
|
var buildBinanceBrowseUrl = () => `bnc://app.binance.com/cedefi/dapp?url=${encodeURIComponent(window.location.href)}`;
|
|
@@ -896,7 +896,7 @@ var createBinanceSolanaDappBrowserConnector = () => createDappBrowserSolanaConne
|
|
|
896
896
|
// src/lib/connectors/okx.ts
|
|
897
897
|
var OKX_CONFIG = {
|
|
898
898
|
walletId: "okx",
|
|
899
|
-
wcDeeplink: "
|
|
899
|
+
wcDeeplink: "okex://main/wc",
|
|
900
900
|
injectedKey: "isOkxWallet"
|
|
901
901
|
};
|
|
902
902
|
var buildOkxBrowseUrl = () => `okx://wallet/dapp/url?dappUrl=${encodeURIComponent(window.location.href)}`;
|
|
@@ -909,245 +909,8 @@ var createOkxSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector
|
|
|
909
909
|
});
|
|
910
910
|
|
|
911
911
|
// src/lib/connectors/coinbase.ts
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
walletId: "coinbase",
|
|
915
|
-
injectedKey: "isCoinbaseWallet",
|
|
916
|
-
buildUrl: buildCoinbaseBrowseUrl
|
|
917
|
-
});
|
|
918
|
-
|
|
919
|
-
// src/lib/connectors/bitget.ts
|
|
920
|
-
var BITGET_CONFIG = {
|
|
921
|
-
walletId: "bitget",
|
|
922
|
-
wcDeeplink: "bitkeep://bkconnect",
|
|
923
|
-
injectedKey: "isBitKeep"
|
|
924
|
-
};
|
|
925
|
-
var buildBitgetBrowseUrl = () => `https://bkcode.vip?action=dapp&url=${encodeURIComponent(window.location.href)}`;
|
|
926
|
-
var createBitgetSolanaConnector = () => createWcSolanaConnector(BITGET_CONFIG);
|
|
927
|
-
var createBitgetSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
928
|
-
walletId: "bitget",
|
|
929
|
-
injectedKey: "isBitKeep",
|
|
930
|
-
buildUrl: buildBitgetBrowseUrl
|
|
931
|
-
});
|
|
932
|
-
|
|
933
|
-
// src/lib/connectors/walletconnect.ts
|
|
934
|
-
import bs584 from "bs58";
|
|
935
|
-
var walletConfig = WALLETS.find((w) => w.id === "walletconnect");
|
|
936
|
-
var disconnectWc2 = async () => {
|
|
937
|
-
if (getCurrentSession()) {
|
|
938
|
-
await disconnectWalletConnect();
|
|
939
|
-
}
|
|
940
|
-
};
|
|
941
|
-
var createWalletConnectEvmConnector = () => {
|
|
942
|
-
return {
|
|
943
|
-
id: walletConfig.id,
|
|
944
|
-
name: walletConfig.name,
|
|
945
|
-
icon: walletConfig.icon,
|
|
946
|
-
type: "evm",
|
|
947
|
-
installed: false,
|
|
948
|
-
wallet: {
|
|
949
|
-
_connector: null,
|
|
950
|
-
connect: async () => {
|
|
951
|
-
return connectViaWalletConnect(EVM_WC_CONFIG, getEvmAccountFromSession);
|
|
952
|
-
},
|
|
953
|
-
disconnect: disconnectWc2,
|
|
954
|
-
signMessage: async (message) => {
|
|
955
|
-
const session = getCurrentSession();
|
|
956
|
-
if (!session) {
|
|
957
|
-
throw new Error("No WalletConnect session");
|
|
958
|
-
}
|
|
959
|
-
const account = session.namespaces.eip155?.accounts?.[0];
|
|
960
|
-
if (!account) {
|
|
961
|
-
throw new Error("No EVM account in session");
|
|
962
|
-
}
|
|
963
|
-
const address = account.split(":")[2];
|
|
964
|
-
const result = await requestWalletConnect(
|
|
965
|
-
"personal_sign",
|
|
966
|
-
[message, address],
|
|
967
|
-
WC_CHAINS.EVM_MAINNET
|
|
968
|
-
);
|
|
969
|
-
return result;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
};
|
|
973
|
-
};
|
|
974
|
-
var createWalletConnectSolanaConnector = () => {
|
|
975
|
-
return {
|
|
976
|
-
id: walletConfig.id,
|
|
977
|
-
name: walletConfig.name,
|
|
978
|
-
icon: walletConfig.icon,
|
|
979
|
-
type: "solana",
|
|
980
|
-
installed: false,
|
|
981
|
-
wallet: {
|
|
982
|
-
_provider: null,
|
|
983
|
-
connect: async () => {
|
|
984
|
-
return connectViaWalletConnect(SOLANA_WC_CONFIG, getSolanaAccountFromSession);
|
|
985
|
-
},
|
|
986
|
-
disconnect: disconnectWc2,
|
|
987
|
-
signMessage: async (message) => {
|
|
988
|
-
const session = getCurrentSession();
|
|
989
|
-
if (!session) {
|
|
990
|
-
throw new Error("No WalletConnect session");
|
|
991
|
-
}
|
|
992
|
-
const account = session.namespaces.solana?.accounts?.[0];
|
|
993
|
-
if (!account) {
|
|
994
|
-
throw new Error("No Solana account in session");
|
|
995
|
-
}
|
|
996
|
-
const pubkey = account.split(":")[2];
|
|
997
|
-
const messageBytes = new TextEncoder().encode(message);
|
|
998
|
-
const result = await requestWalletConnect(
|
|
999
|
-
"solana_signMessage",
|
|
1000
|
-
{ message: bs584.encode(messageBytes), pubkey },
|
|
1001
|
-
WC_CHAINS.SOLANA_MAINNET
|
|
1002
|
-
);
|
|
1003
|
-
return result.signature;
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
};
|
|
1007
|
-
};
|
|
1008
|
-
|
|
1009
|
-
// src/lib/evm/connectors.ts
|
|
1010
|
-
var EVM_FALLBACK_CONNECTORS = [
|
|
1011
|
-
{
|
|
1012
|
-
id: "phantom",
|
|
1013
|
-
create: isMobile() ? createPhantomEvmConnectorDeeplink : createPhantomEvmConnector
|
|
1014
|
-
},
|
|
1015
|
-
...isMobile() ? [] : [{ id: "metamask", create: createMetaMaskEvmConnector }],
|
|
1016
|
-
{ id: "trust", create: createTrustEvmMobileConnector },
|
|
1017
|
-
{ id: "binance", create: createBinanceEvmConnector },
|
|
1018
|
-
{ id: "okx", create: createOkxEvmConnector },
|
|
1019
|
-
{ id: "rainbow", create: createRainbowEvmMobileConnector },
|
|
1020
|
-
...isMobile() ? [] : [{ id: "rabby", create: createRabbyEvmConnector }]
|
|
1021
|
-
];
|
|
1022
|
-
var sleep = (ms) => new Promise((r) => window.setTimeout(r, ms));
|
|
1023
|
-
var checkEvmWalletInstalled = (connectorId) => {
|
|
1024
|
-
if (typeof window === "undefined") return false;
|
|
1025
|
-
const providers = window.ethereum?.providers ?? (window.ethereum ? [window.ethereum] : []);
|
|
1026
|
-
switch (connectorId) {
|
|
1027
|
-
case "metaMaskSDK":
|
|
1028
|
-
return providers.some((p) => p.isMetaMask && !p.isBraveWallet);
|
|
1029
|
-
case "coinbaseWalletSDK":
|
|
1030
|
-
if ("coinbaseWalletExtension" in window) return true;
|
|
1031
|
-
return providers.some(
|
|
1032
|
-
(p) => p.isCoinbaseWallet || p.isCoinbaseBrowser
|
|
1033
|
-
);
|
|
1034
|
-
default:
|
|
1035
|
-
return true;
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
var cleanupWalletLocalStorage = () => {
|
|
1039
|
-
Object.keys(window.localStorage).filter((key) => key.startsWith("wagmi.")).forEach((key) => window.localStorage.removeItem(key));
|
|
1040
|
-
};
|
|
1041
|
-
var getEvmConnectors = () => {
|
|
1042
|
-
const wagmiConnectors = getConnectors(getEvmConfig());
|
|
1043
|
-
const connectors = wagmiConnectors.map((c) => ({
|
|
1044
|
-
id: normalizeEvmWalletId(c.id),
|
|
1045
|
-
name: c.name,
|
|
1046
|
-
icon: c.icon,
|
|
1047
|
-
type: "evm",
|
|
1048
|
-
installed: checkEvmWalletInstalled(c.id),
|
|
1049
|
-
wallet: {
|
|
1050
|
-
_connector: c,
|
|
1051
|
-
connect: async () => {
|
|
1052
|
-
try {
|
|
1053
|
-
const result = await connect(getEvmConfig(), { connector: c });
|
|
1054
|
-
if (!result.accounts[0]) throw new Error("No accounts returned");
|
|
1055
|
-
return connectedResult(result.accounts[0], { chainId: result.chainId });
|
|
1056
|
-
} catch (err) {
|
|
1057
|
-
if (err instanceof Error && err.name === "ConnectorAlreadyConnectedError") {
|
|
1058
|
-
cleanupWalletLocalStorage();
|
|
1059
|
-
await disconnect(getEvmConfig(), { connector: c });
|
|
1060
|
-
await sleep(100);
|
|
1061
|
-
const result = await connect(getEvmConfig(), { connector: c });
|
|
1062
|
-
if (!result.accounts[0]) throw new Error("No accounts returned");
|
|
1063
|
-
return connectedResult(result.accounts[0], { chainId: result.chainId });
|
|
1064
|
-
}
|
|
1065
|
-
throw err;
|
|
1066
|
-
}
|
|
1067
|
-
},
|
|
1068
|
-
disconnect: async () => {
|
|
1069
|
-
cleanupWalletLocalStorage();
|
|
1070
|
-
await disconnect(getEvmConfig());
|
|
1071
|
-
},
|
|
1072
|
-
signMessage: async (message) => {
|
|
1073
|
-
return wagmiSignMessage(getEvmConfig(), { message });
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
}));
|
|
1077
|
-
addFallbackConnectors(connectors, EVM_FALLBACK_CONNECTORS);
|
|
1078
|
-
return connectors;
|
|
1079
|
-
};
|
|
1080
|
-
|
|
1081
|
-
// src/lib/evm/connection.ts
|
|
1082
|
-
import { watchConnections } from "@wagmi/core";
|
|
1083
|
-
var watchEvmConnections = (onChange) => {
|
|
1084
|
-
return watchConnections(getEvmConfig(), { onChange });
|
|
1085
|
-
};
|
|
1086
|
-
|
|
1087
|
-
// src/lib/evm/transactions.ts
|
|
1088
|
-
import {
|
|
1089
|
-
sendTransaction as wagmiSendTransaction,
|
|
1090
|
-
switchChain as wagmiSwitchChain,
|
|
1091
|
-
waitForTransactionReceipt as wagmiWaitForReceipt
|
|
1092
|
-
} from "@wagmi/core";
|
|
1093
|
-
var switchChain = async (chainId) => {
|
|
1094
|
-
await wagmiSwitchChain(getEvmConfig(), { chainId });
|
|
1095
|
-
};
|
|
1096
|
-
var sendTransaction = async (params) => {
|
|
1097
|
-
const hash = await wagmiSendTransaction(getEvmConfig(), {
|
|
1098
|
-
to: params.to,
|
|
1099
|
-
value: params.value,
|
|
1100
|
-
data: params.data
|
|
1101
|
-
});
|
|
1102
|
-
return { hash };
|
|
1103
|
-
};
|
|
1104
|
-
var waitForTransactionReceipt = async (hash) => {
|
|
1105
|
-
const receipt = await wagmiWaitForReceipt(getEvmConfig(), { hash });
|
|
1106
|
-
return {
|
|
1107
|
-
hash: receipt.transactionHash,
|
|
1108
|
-
status: receipt.status,
|
|
1109
|
-
blockNumber: receipt.blockNumber
|
|
1110
|
-
};
|
|
1111
|
-
};
|
|
1112
|
-
|
|
1113
|
-
// src/lib/evm/erc20.ts
|
|
1114
|
-
import { readContract, writeContract } from "@wagmi/core";
|
|
1115
|
-
import { erc20Abi } from "viem";
|
|
1116
|
-
var getAllowance = async (params) => {
|
|
1117
|
-
return readContract(getEvmConfig(), {
|
|
1118
|
-
abi: erc20Abi,
|
|
1119
|
-
address: params.tokenAddress,
|
|
1120
|
-
functionName: "allowance",
|
|
1121
|
-
args: [params.owner, params.spender]
|
|
1122
|
-
});
|
|
1123
|
-
};
|
|
1124
|
-
var approve = async (params) => {
|
|
1125
|
-
const hash = await writeContract(getEvmConfig(), {
|
|
1126
|
-
address: params.tokenAddress,
|
|
1127
|
-
abi: erc20Abi,
|
|
1128
|
-
functionName: "approve",
|
|
1129
|
-
args: [params.spender, params.amount]
|
|
1130
|
-
});
|
|
1131
|
-
return waitForTransactionReceipt(hash);
|
|
1132
|
-
};
|
|
1133
|
-
var ensureAllowance = async (params) => {
|
|
1134
|
-
const currentAllowance = await getAllowance({
|
|
1135
|
-
tokenAddress: params.tokenAddress,
|
|
1136
|
-
owner: params.owner,
|
|
1137
|
-
spender: params.spender
|
|
1138
|
-
});
|
|
1139
|
-
if (currentAllowance >= params.amount) {
|
|
1140
|
-
return null;
|
|
1141
|
-
}
|
|
1142
|
-
if (currentAllowance > 0n) {
|
|
1143
|
-
await approve({
|
|
1144
|
-
tokenAddress: params.tokenAddress,
|
|
1145
|
-
spender: params.spender,
|
|
1146
|
-
amount: 0n
|
|
1147
|
-
});
|
|
1148
|
-
}
|
|
1149
|
-
return approve(params);
|
|
1150
|
-
};
|
|
912
|
+
import { CoinbaseWalletAdapter } from "@solana/wallet-adapter-coinbase";
|
|
913
|
+
import bs585 from "bs58";
|
|
1151
914
|
|
|
1152
915
|
// src/lib/solana/connection.ts
|
|
1153
916
|
var currentConnection = {
|
|
@@ -1175,7 +938,7 @@ import {
|
|
|
1175
938
|
isWalletAdapterCompatibleStandardWallet
|
|
1176
939
|
} from "@solana/wallet-adapter-base";
|
|
1177
940
|
import { getWallets } from "@wallet-standard/app";
|
|
1178
|
-
import
|
|
941
|
+
import bs584 from "bs58";
|
|
1179
942
|
var createSolanaConnector = (provider) => {
|
|
1180
943
|
const id = normalizeSolanaWalletId(provider.name.toLowerCase().replace(/\s+/g, "-"));
|
|
1181
944
|
const connector = {
|
|
@@ -1219,7 +982,7 @@ var createSolanaConnector = (provider) => {
|
|
|
1219
982
|
const result = await signFeature.signMessage({ message: encodedMessage, account });
|
|
1220
983
|
const signature = result[0]?.signature;
|
|
1221
984
|
if (!signature) throw new Error("No signature returned");
|
|
1222
|
-
return
|
|
985
|
+
return bs584.encode(signature);
|
|
1223
986
|
}
|
|
1224
987
|
}
|
|
1225
988
|
};
|
|
@@ -1284,8 +1047,12 @@ var SOLANA_FALLBACK_CONNECTORS = isMobile() ? [
|
|
|
1284
1047
|
create: () => createSolanaMobileConnector(createTrustSolanaMobileConnector())
|
|
1285
1048
|
},
|
|
1286
1049
|
{ id: "binance", create: () => createSolanaMobileConnector(createBinanceSolanaConnector()) },
|
|
1287
|
-
{ id: "bitget", create: createBitgetSolanaConnector },
|
|
1288
|
-
{ id: "okx", create: createOkxSolanaConnector }
|
|
1050
|
+
{ id: "bitget", create: () => createSolanaMobileConnector(createBitgetSolanaConnector()) },
|
|
1051
|
+
{ id: "okx", create: () => createSolanaMobileConnector(createOkxSolanaConnector()) },
|
|
1052
|
+
{
|
|
1053
|
+
id: "coinbase",
|
|
1054
|
+
create: () => createSolanaMobileConnector(createCoinbaseSolanaConnector())
|
|
1055
|
+
}
|
|
1289
1056
|
];
|
|
1290
1057
|
var getSolanaWallets = () => {
|
|
1291
1058
|
const { get } = getWallets();
|
|
@@ -1391,6 +1158,283 @@ var checkSolflareSignCallback = () => {
|
|
|
1391
1158
|
return handleSolflareSignCallback();
|
|
1392
1159
|
};
|
|
1393
1160
|
|
|
1161
|
+
// src/lib/connectors/coinbase.ts
|
|
1162
|
+
var buildCoinbaseBrowseUrl = () => `cbwallet://dapp?url=${encodeURIComponent(window.location.href)}`;
|
|
1163
|
+
var createCoinbaseSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
1164
|
+
walletId: "coinbase",
|
|
1165
|
+
injectedKey: "isCoinbaseWallet",
|
|
1166
|
+
buildUrl: buildCoinbaseBrowseUrl
|
|
1167
|
+
});
|
|
1168
|
+
var createCoinbaseSolanaConnector = () => {
|
|
1169
|
+
const walletConfig2 = WALLETS.find((w) => w.id === "coinbase");
|
|
1170
|
+
const adapter = new CoinbaseWalletAdapter();
|
|
1171
|
+
const connector = {
|
|
1172
|
+
id: "coinbase",
|
|
1173
|
+
name: walletConfig2.name,
|
|
1174
|
+
icon: walletConfig2.icon,
|
|
1175
|
+
type: "solana",
|
|
1176
|
+
installed: adapter.readyState === "Installed",
|
|
1177
|
+
wallet: {
|
|
1178
|
+
_provider: adapter,
|
|
1179
|
+
connect: async () => {
|
|
1180
|
+
await adapter.connect();
|
|
1181
|
+
if (!adapter.publicKey) {
|
|
1182
|
+
throw new Error("No public key returned from Coinbase Wallet");
|
|
1183
|
+
}
|
|
1184
|
+
const address = adapter.publicKey.toBase58();
|
|
1185
|
+
const result = connectedResult(address, {
|
|
1186
|
+
publicKey: adapter.publicKey.toBytes()
|
|
1187
|
+
});
|
|
1188
|
+
storage.setString(STORAGE_KEYS.SOLANA_WALLET, "coinbase");
|
|
1189
|
+
setConnection(result, connector);
|
|
1190
|
+
return result;
|
|
1191
|
+
},
|
|
1192
|
+
disconnect: async () => {
|
|
1193
|
+
await adapter.disconnect();
|
|
1194
|
+
},
|
|
1195
|
+
signMessage: async (message) => {
|
|
1196
|
+
const encodedMessage = new TextEncoder().encode(message);
|
|
1197
|
+
const signature = await adapter.signMessage(encodedMessage);
|
|
1198
|
+
return bs585.encode(signature);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
return connector;
|
|
1203
|
+
};
|
|
1204
|
+
|
|
1205
|
+
// src/lib/connectors/bitget.ts
|
|
1206
|
+
var BITGET_CONFIG = {
|
|
1207
|
+
walletId: "bitget",
|
|
1208
|
+
wcDeeplink: "bitkeep://bkconnect",
|
|
1209
|
+
injectedKey: "isBitKeep"
|
|
1210
|
+
};
|
|
1211
|
+
var buildBitgetBrowseUrl = () => `https://bkcode.vip?action=dapp&url=${encodeURIComponent(window.location.href)}`;
|
|
1212
|
+
var createBitgetSolanaConnector = () => createWcSolanaConnector(BITGET_CONFIG);
|
|
1213
|
+
var createBitgetSolanaDappBrowserConnector = () => createDappBrowserSolanaConnector({
|
|
1214
|
+
walletId: "bitget",
|
|
1215
|
+
injectedKey: "isBitKeep",
|
|
1216
|
+
buildUrl: buildBitgetBrowseUrl
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
// src/lib/connectors/walletconnect.ts
|
|
1220
|
+
import bs586 from "bs58";
|
|
1221
|
+
var walletConfig = WALLETS.find((w) => w.id === "walletconnect");
|
|
1222
|
+
var disconnectWc2 = async () => {
|
|
1223
|
+
if (getCurrentSession()) {
|
|
1224
|
+
await disconnectWalletConnect();
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
var createWalletConnectEvmConnector = () => {
|
|
1228
|
+
return {
|
|
1229
|
+
id: walletConfig.id,
|
|
1230
|
+
name: walletConfig.name,
|
|
1231
|
+
icon: walletConfig.icon,
|
|
1232
|
+
type: "evm",
|
|
1233
|
+
installed: false,
|
|
1234
|
+
wallet: {
|
|
1235
|
+
_connector: null,
|
|
1236
|
+
connect: async () => {
|
|
1237
|
+
return connectViaWalletConnect(EVM_WC_CONFIG, getEvmAccountFromSession);
|
|
1238
|
+
},
|
|
1239
|
+
disconnect: disconnectWc2,
|
|
1240
|
+
signMessage: async (message) => {
|
|
1241
|
+
const session = getCurrentSession();
|
|
1242
|
+
if (!session) {
|
|
1243
|
+
throw new Error("No WalletConnect session");
|
|
1244
|
+
}
|
|
1245
|
+
const account = session.namespaces.eip155?.accounts?.[0];
|
|
1246
|
+
if (!account) {
|
|
1247
|
+
throw new Error("No EVM account in session");
|
|
1248
|
+
}
|
|
1249
|
+
const address = account.split(":")[2];
|
|
1250
|
+
const result = await requestWalletConnect(
|
|
1251
|
+
"personal_sign",
|
|
1252
|
+
[message, address],
|
|
1253
|
+
WC_CHAINS.EVM_MAINNET
|
|
1254
|
+
);
|
|
1255
|
+
return result;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
};
|
|
1260
|
+
var createWalletConnectSolanaConnector = () => {
|
|
1261
|
+
return {
|
|
1262
|
+
id: walletConfig.id,
|
|
1263
|
+
name: walletConfig.name,
|
|
1264
|
+
icon: walletConfig.icon,
|
|
1265
|
+
type: "solana",
|
|
1266
|
+
installed: false,
|
|
1267
|
+
wallet: {
|
|
1268
|
+
_provider: null,
|
|
1269
|
+
connect: async () => {
|
|
1270
|
+
return connectViaWalletConnect(SOLANA_WC_CONFIG, getSolanaAccountFromSession);
|
|
1271
|
+
},
|
|
1272
|
+
disconnect: disconnectWc2,
|
|
1273
|
+
signMessage: async (message) => {
|
|
1274
|
+
const session = getCurrentSession();
|
|
1275
|
+
if (!session) {
|
|
1276
|
+
throw new Error("No WalletConnect session");
|
|
1277
|
+
}
|
|
1278
|
+
const account = session.namespaces.solana?.accounts?.[0];
|
|
1279
|
+
if (!account) {
|
|
1280
|
+
throw new Error("No Solana account in session");
|
|
1281
|
+
}
|
|
1282
|
+
const pubkey = account.split(":")[2];
|
|
1283
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
1284
|
+
const result = await requestWalletConnect(
|
|
1285
|
+
"solana_signMessage",
|
|
1286
|
+
{ message: bs586.encode(messageBytes), pubkey },
|
|
1287
|
+
WC_CHAINS.SOLANA_MAINNET
|
|
1288
|
+
);
|
|
1289
|
+
return result.signature;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
// src/lib/evm/connectors.ts
|
|
1296
|
+
var EVM_FALLBACK_CONNECTORS = [
|
|
1297
|
+
{
|
|
1298
|
+
id: "phantom",
|
|
1299
|
+
create: isMobile() ? createPhantomEvmConnectorDeeplink : createPhantomEvmConnector
|
|
1300
|
+
},
|
|
1301
|
+
...isMobile() ? [] : [{ id: "metamask", create: createMetaMaskEvmConnector }],
|
|
1302
|
+
{ id: "trust", create: createTrustEvmMobileConnector },
|
|
1303
|
+
{ id: "binance", create: createBinanceEvmConnector },
|
|
1304
|
+
{ id: "okx", create: createOkxEvmConnector },
|
|
1305
|
+
{ id: "rainbow", create: createRainbowEvmMobileConnector },
|
|
1306
|
+
...isMobile() ? [] : [{ id: "rabby", create: createRabbyEvmConnector }]
|
|
1307
|
+
];
|
|
1308
|
+
var sleep = (ms) => new Promise((r) => window.setTimeout(r, ms));
|
|
1309
|
+
var checkEvmWalletInstalled = (connectorId) => {
|
|
1310
|
+
if (typeof window === "undefined") return false;
|
|
1311
|
+
const providers = window.ethereum?.providers ?? (window.ethereum ? [window.ethereum] : []);
|
|
1312
|
+
switch (connectorId) {
|
|
1313
|
+
case "metaMaskSDK":
|
|
1314
|
+
return providers.some((p) => p.isMetaMask && !p.isBraveWallet);
|
|
1315
|
+
case "coinbaseWalletSDK":
|
|
1316
|
+
if ("coinbaseWalletExtension" in window) return true;
|
|
1317
|
+
return providers.some(
|
|
1318
|
+
(p) => p.isCoinbaseWallet || p.isCoinbaseBrowser
|
|
1319
|
+
);
|
|
1320
|
+
default:
|
|
1321
|
+
return true;
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
var cleanupWalletLocalStorage = () => {
|
|
1325
|
+
Object.keys(window.localStorage).filter((key) => key.startsWith("wagmi.")).forEach((key) => window.localStorage.removeItem(key));
|
|
1326
|
+
};
|
|
1327
|
+
var getEvmConnectors = () => {
|
|
1328
|
+
const wagmiConnectors = getConnectors(getEvmConfig());
|
|
1329
|
+
const connectors = wagmiConnectors.map((c) => ({
|
|
1330
|
+
id: normalizeEvmWalletId(c.id),
|
|
1331
|
+
name: c.name,
|
|
1332
|
+
icon: c.icon,
|
|
1333
|
+
type: "evm",
|
|
1334
|
+
installed: checkEvmWalletInstalled(c.id),
|
|
1335
|
+
wallet: {
|
|
1336
|
+
_connector: c,
|
|
1337
|
+
connect: async () => {
|
|
1338
|
+
try {
|
|
1339
|
+
const result = await connect(getEvmConfig(), { connector: c });
|
|
1340
|
+
if (!result.accounts[0]) throw new Error("No accounts returned");
|
|
1341
|
+
return connectedResult(result.accounts[0], { chainId: result.chainId });
|
|
1342
|
+
} catch (err) {
|
|
1343
|
+
if (err instanceof Error && err.name === "ConnectorAlreadyConnectedError") {
|
|
1344
|
+
cleanupWalletLocalStorage();
|
|
1345
|
+
await disconnect(getEvmConfig(), { connector: c });
|
|
1346
|
+
await sleep(100);
|
|
1347
|
+
const result = await connect(getEvmConfig(), { connector: c });
|
|
1348
|
+
if (!result.accounts[0]) throw new Error("No accounts returned");
|
|
1349
|
+
return connectedResult(result.accounts[0], { chainId: result.chainId });
|
|
1350
|
+
}
|
|
1351
|
+
throw err;
|
|
1352
|
+
}
|
|
1353
|
+
},
|
|
1354
|
+
disconnect: async () => {
|
|
1355
|
+
cleanupWalletLocalStorage();
|
|
1356
|
+
await disconnect(getEvmConfig());
|
|
1357
|
+
},
|
|
1358
|
+
signMessage: async (message) => {
|
|
1359
|
+
return wagmiSignMessage(getEvmConfig(), { message });
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}));
|
|
1363
|
+
addFallbackConnectors(connectors, EVM_FALLBACK_CONNECTORS);
|
|
1364
|
+
return connectors;
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
// src/lib/evm/connection.ts
|
|
1368
|
+
import { watchConnections } from "@wagmi/core";
|
|
1369
|
+
var watchEvmConnections = (onChange) => {
|
|
1370
|
+
return watchConnections(getEvmConfig(), { onChange });
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
// src/lib/evm/transactions.ts
|
|
1374
|
+
import {
|
|
1375
|
+
sendTransaction as wagmiSendTransaction,
|
|
1376
|
+
switchChain as wagmiSwitchChain,
|
|
1377
|
+
waitForTransactionReceipt as wagmiWaitForReceipt
|
|
1378
|
+
} from "@wagmi/core";
|
|
1379
|
+
var switchChain = async (chainId) => {
|
|
1380
|
+
await wagmiSwitchChain(getEvmConfig(), { chainId });
|
|
1381
|
+
};
|
|
1382
|
+
var sendTransaction = async (params) => {
|
|
1383
|
+
const hash = await wagmiSendTransaction(getEvmConfig(), {
|
|
1384
|
+
to: params.to,
|
|
1385
|
+
value: params.value,
|
|
1386
|
+
data: params.data
|
|
1387
|
+
});
|
|
1388
|
+
return { hash };
|
|
1389
|
+
};
|
|
1390
|
+
var waitForTransactionReceipt = async (hash) => {
|
|
1391
|
+
const receipt = await wagmiWaitForReceipt(getEvmConfig(), { hash });
|
|
1392
|
+
return {
|
|
1393
|
+
hash: receipt.transactionHash,
|
|
1394
|
+
status: receipt.status,
|
|
1395
|
+
blockNumber: receipt.blockNumber
|
|
1396
|
+
};
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
// src/lib/evm/erc20.ts
|
|
1400
|
+
import { readContract, writeContract } from "@wagmi/core";
|
|
1401
|
+
import { erc20Abi } from "viem";
|
|
1402
|
+
var getAllowance = async (params) => {
|
|
1403
|
+
return readContract(getEvmConfig(), {
|
|
1404
|
+
abi: erc20Abi,
|
|
1405
|
+
address: params.tokenAddress,
|
|
1406
|
+
functionName: "allowance",
|
|
1407
|
+
args: [params.owner, params.spender]
|
|
1408
|
+
});
|
|
1409
|
+
};
|
|
1410
|
+
var approve = async (params) => {
|
|
1411
|
+
const hash = await writeContract(getEvmConfig(), {
|
|
1412
|
+
address: params.tokenAddress,
|
|
1413
|
+
abi: erc20Abi,
|
|
1414
|
+
functionName: "approve",
|
|
1415
|
+
args: [params.spender, params.amount]
|
|
1416
|
+
});
|
|
1417
|
+
return waitForTransactionReceipt(hash);
|
|
1418
|
+
};
|
|
1419
|
+
var ensureAllowance = async (params) => {
|
|
1420
|
+
const currentAllowance = await getAllowance({
|
|
1421
|
+
tokenAddress: params.tokenAddress,
|
|
1422
|
+
owner: params.owner,
|
|
1423
|
+
spender: params.spender
|
|
1424
|
+
});
|
|
1425
|
+
if (currentAllowance >= params.amount) {
|
|
1426
|
+
return null;
|
|
1427
|
+
}
|
|
1428
|
+
if (currentAllowance > 0n) {
|
|
1429
|
+
await approve({
|
|
1430
|
+
tokenAddress: params.tokenAddress,
|
|
1431
|
+
spender: params.spender,
|
|
1432
|
+
amount: 0n
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
return approve(params);
|
|
1436
|
+
};
|
|
1437
|
+
|
|
1394
1438
|
// src/lib/context/WalletContext.tsx
|
|
1395
1439
|
import { createContext, useContext } from "solid-js";
|
|
1396
1440
|
|
|
@@ -1571,7 +1615,7 @@ var useSolanaWallet = () => {
|
|
|
1571
1615
|
};
|
|
1572
1616
|
|
|
1573
1617
|
// src/lib/context/hooks/useWalletConnect.ts
|
|
1574
|
-
import
|
|
1618
|
+
import bs587 from "bs58";
|
|
1575
1619
|
import { onCleanup as onCleanup3, onMount as onMount3 } from "solid-js";
|
|
1576
1620
|
var useWalletConnect = (options) => {
|
|
1577
1621
|
onMount3(async () => {
|
|
@@ -1626,7 +1670,7 @@ var useWalletConnect = (options) => {
|
|
|
1626
1670
|
const messageBytes = new TextEncoder().encode(message);
|
|
1627
1671
|
const result = await requestWalletConnect(
|
|
1628
1672
|
"solana_signMessage",
|
|
1629
|
-
{ message:
|
|
1673
|
+
{ message: bs587.encode(messageBytes), pubkey },
|
|
1630
1674
|
WC_CHAINS.SOLANA_MAINNET
|
|
1631
1675
|
);
|
|
1632
1676
|
return result.signature;
|
|
@@ -6,6 +6,6 @@ export { createRainbowEvmMobileConnector } from './rainbow';
|
|
|
6
6
|
export { createRabbyEvmConnector } from './rabby';
|
|
7
7
|
export { createBinanceEvmConnector, createBinanceSolanaConnector, createBinanceSolanaDappBrowserConnector, } from './binance';
|
|
8
8
|
export { createOkxEvmConnector, createOkxSolanaConnector, createOkxSolanaDappBrowserConnector, } from './okx';
|
|
9
|
-
export { createCoinbaseSolanaDappBrowserConnector } from './coinbase';
|
|
9
|
+
export { createCoinbaseSolanaDappBrowserConnector, createCoinbaseSolanaConnector } from './coinbase';
|
|
10
10
|
export { createBitgetSolanaDappBrowserConnector, createBitgetSolanaConnector } from './bitget';
|
|
11
11
|
export { createWalletConnectEvmConnector, createWalletConnectSolanaConnector, } from './walletconnect';
|
|
@@ -5,6 +5,8 @@ export interface WcWalletConfig {
|
|
|
5
5
|
walletId: WalletId;
|
|
6
6
|
wcDeeplink: string;
|
|
7
7
|
injectedKey: string;
|
|
8
|
+
/** Custom deeplink builder for wallets that need special formatting */
|
|
9
|
+
getDeeplink?: (uri: string) => string;
|
|
8
10
|
}
|
|
9
11
|
export declare const createWcEvmConnector: (config: WcWalletConfig) => EvmWalletConnector;
|
|
10
12
|
export declare const createWcSolanaConnector: (config: WcWalletConfig) => SolanaWalletConnector;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bit-buccaneers/wallet-abstraction",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "Solid.js web3 wallet abstraction for EVM and Solana",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bit Buccaneers",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"typesVersions": {},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@solana/wallet-adapter-base": "^0.9.0",
|
|
45
|
+
"@solana/wallet-adapter-coinbase": "^0.1.0",
|
|
45
46
|
"@wagmi/connectors": "^5.8.5",
|
|
46
47
|
"@wagmi/core": "^2.17.3",
|
|
47
48
|
"@wallet-standard/app": "^1.0.0",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"viem": "^2.0.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
54
|
+
"@solana/wallet-adapter-coinbase": "^0.1.0",
|
|
53
55
|
"@eslint/js": "^9.39.2",
|
|
54
56
|
"@types/node": "^20.12.12",
|
|
55
57
|
"@typescript-eslint/eslint-plugin": "^8.54.0",
|