@sodax/wallet-sdk-react 1.5.7-beta → 2.0.0-rc.2
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/README.md +103 -145
- package/ai-exported/AGENTS.md +122 -0
- package/ai-exported/integration/README.md +102 -0
- package/ai-exported/integration/ai-rules.md +136 -0
- package/ai-exported/integration/architecture.md +181 -0
- package/ai-exported/integration/examples/01-minimal-evm.tsx +75 -0
- package/ai-exported/integration/examples/02-multi-chain-modal.tsx +169 -0
- package/ai-exported/integration/examples/03-nextjs-app-router.tsx +99 -0
- package/ai-exported/integration/examples/04-walletconnect-setup.tsx +89 -0
- package/ai-exported/integration/examples/README.md +29 -0
- package/ai-exported/integration/recipes/batch-operations.md +223 -0
- package/ai-exported/integration/recipes/bridge-to-sdk.md +164 -0
- package/ai-exported/integration/recipes/chain-detection.md +254 -0
- package/ai-exported/integration/recipes/connect-button.md +156 -0
- package/ai-exported/integration/recipes/multi-chain-modal.md +199 -0
- package/ai-exported/integration/recipes/setup.md +158 -0
- package/ai-exported/integration/recipes/sign-message.md +137 -0
- package/ai-exported/integration/recipes/sub-path-imports.md +95 -0
- package/ai-exported/integration/recipes/switch-chain.md +141 -0
- package/ai-exported/integration/recipes/walletconnect-setup.md +139 -0
- package/ai-exported/integration/reference/api-surface.md +175 -0
- package/ai-exported/integration/reference/chain-support.md +78 -0
- package/ai-exported/integration/reference/connectors.md +74 -0
- package/ai-exported/integration/reference/hooks.md +204 -0
- package/ai-exported/integration/reference/wallet-brands.md +106 -0
- package/ai-exported/migration/README.md +49 -0
- package/ai-exported/migration/ai-rules.md +144 -0
- package/ai-exported/migration/breaking-changes.md +305 -0
- package/ai-exported/migration/checklist.md +159 -0
- package/ai-exported/migration/recipes/connect-button.md +166 -0
- package/ai-exported/migration/recipes/multi-chain-modal.md +244 -0
- package/ai-exported/migration/recipes/ssr-setup.md +162 -0
- package/ai-exported/migration/recipes/walletconnect-migration.md +168 -0
- package/ai-exported/migration/reference/components.md +73 -0
- package/ai-exported/migration/reference/config.md +307 -0
- package/ai-exported/migration/reference/hooks.md +278 -0
- package/ai-exported/migration/reference/imports.md +157 -0
- package/dist/XConnector-B9YQTVJ4.d.ts +146 -0
- package/dist/chunk-2BOUGCJ7.mjs +150 -0
- package/dist/chunk-2BOUGCJ7.mjs.map +1 -0
- package/dist/chunk-66BAUK56.mjs +202 -0
- package/dist/chunk-66BAUK56.mjs.map +1 -0
- package/dist/chunk-7ULB6DW4.mjs +102 -0
- package/dist/chunk-7ULB6DW4.mjs.map +1 -0
- package/dist/chunk-BKJB527E.mjs +125 -0
- package/dist/chunk-BKJB527E.mjs.map +1 -0
- package/dist/chunk-BXJLBR4G.mjs +88 -0
- package/dist/chunk-BXJLBR4G.mjs.map +1 -0
- package/dist/chunk-E5IAZ7E6.mjs +186 -0
- package/dist/chunk-E5IAZ7E6.mjs.map +1 -0
- package/dist/chunk-MAQ47Q52.mjs +33 -0
- package/dist/chunk-MAQ47Q52.mjs.map +1 -0
- package/dist/chunk-MXZVF5HR.mjs +34 -0
- package/dist/chunk-MXZVF5HR.mjs.map +1 -0
- package/dist/chunk-N5A2TMF6.mjs +33 -0
- package/dist/chunk-N5A2TMF6.mjs.map +1 -0
- package/dist/chunk-NY7U7OJW.mjs +64 -0
- package/dist/chunk-NY7U7OJW.mjs.map +1 -0
- package/dist/chunk-PJLEJVAU.mjs +140 -0
- package/dist/chunk-PJLEJVAU.mjs.map +1 -0
- package/dist/chunk-PLCA4ZDJ.mjs +1585 -0
- package/dist/chunk-PLCA4ZDJ.mjs.map +1 -0
- package/dist/chunk-TZMKDXFA.mjs +3 -0
- package/dist/chunk-TZMKDXFA.mjs.map +1 -0
- package/dist/chunk-X2MHIWXO.mjs +100 -0
- package/dist/chunk-X2MHIWXO.mjs.map +1 -0
- package/dist/chunk-XZ7CHO2S.mjs +41 -0
- package/dist/chunk-XZ7CHO2S.mjs.map +1 -0
- package/dist/config-OlnzyEUE.d.ts +146 -0
- package/dist/index.cjs +2784 -1594
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +768 -1498
- package/dist/index.mjs +463 -2004
- package/dist/index.mjs.map +1 -1
- package/dist/xchains/bitcoin/index.cjs +1927 -0
- package/dist/xchains/bitcoin/index.cjs.map +1 -0
- package/dist/xchains/bitcoin/index.d.ts +125 -0
- package/dist/xchains/bitcoin/index.mjs +16 -0
- package/dist/xchains/bitcoin/index.mjs.map +1 -0
- package/dist/xchains/evm/index.cjs +316 -0
- package/dist/xchains/evm/index.cjs.map +1 -0
- package/dist/xchains/evm/index.d.ts +39 -0
- package/dist/xchains/evm/index.mjs +5 -0
- package/dist/xchains/evm/index.mjs.map +1 -0
- package/dist/xchains/icon/index.cjs +311 -0
- package/dist/xchains/icon/index.cjs.map +1 -0
- package/dist/xchains/icon/index.d.ts +37 -0
- package/dist/xchains/icon/index.mjs +7 -0
- package/dist/xchains/icon/index.mjs.map +1 -0
- package/dist/xchains/injective/index.cjs +223 -0
- package/dist/xchains/injective/index.cjs.map +1 -0
- package/dist/xchains/injective/index.d.ts +35 -0
- package/dist/xchains/injective/index.mjs +5 -0
- package/dist/xchains/injective/index.mjs.map +1 -0
- package/dist/xchains/near/index.cjs +190 -0
- package/dist/xchains/near/index.cjs.map +1 -0
- package/dist/xchains/near/index.d.ts +34 -0
- package/dist/xchains/near/index.mjs +6 -0
- package/dist/xchains/near/index.mjs.map +1 -0
- package/dist/xchains/solana/index.cjs +186 -0
- package/dist/xchains/solana/index.cjs.map +1 -0
- package/dist/xchains/solana/index.d.ts +26 -0
- package/dist/xchains/solana/index.mjs +7 -0
- package/dist/xchains/solana/index.mjs.map +1 -0
- package/dist/xchains/stacks/index.cjs +240 -0
- package/dist/xchains/stacks/index.cjs.map +1 -0
- package/dist/xchains/stacks/index.d.ts +36 -0
- package/dist/xchains/stacks/index.mjs +5 -0
- package/dist/xchains/stacks/index.mjs.map +1 -0
- package/dist/xchains/stellar/index.cjs +322 -0
- package/dist/xchains/stellar/index.cjs.map +1 -0
- package/dist/xchains/stellar/index.d.ts +44 -0
- package/dist/xchains/stellar/index.mjs +6 -0
- package/dist/xchains/stellar/index.mjs.map +1 -0
- package/dist/xchains/sui/index.cjs +248 -0
- package/dist/xchains/sui/index.cjs.map +1 -0
- package/dist/xchains/sui/index.d.ts +37 -0
- package/dist/xchains/sui/index.mjs +7 -0
- package/dist/xchains/sui/index.mjs.map +1 -0
- package/docs/ADDING_A_NEW_CHAIN.md +440 -0
- package/docs/ARCHITECTURE.md +291 -0
- package/docs/BATCH_OPERATIONS.md +267 -0
- package/docs/CHAIN_DETECTION.md +216 -0
- package/docs/CONFIGURE_PROVIDER.md +360 -0
- package/docs/CONNECTORS.md +247 -0
- package/docs/CONNECT_FLOW.md +276 -0
- package/docs/EVM_SWITCH_CHAIN.md +161 -0
- package/docs/SIGN_MESSAGE.md +213 -0
- package/docs/SUB_PATH_EXPORTS.md +246 -0
- package/docs/WALLETCONNECT.md +154 -0
- package/docs/WALLET_MODAL.md +331 -0
- package/docs/WALLET_PROVIDER_BRIDGE.md +226 -0
- package/package.json +37 -12
- package/skills/SKILLS.md +84 -0
- package/skills/bridge-to-sdk.md +148 -0
- package/skills/connect-button.md +116 -0
- package/skills/evm-only-walletconnect.md +111 -0
- package/skills/multi-chain-modal.md +178 -0
- package/skills/setup.md +107 -0
- package/dist/index.d.cts +0 -1579
- package/src/Hydrate.ts +0 -65
- package/src/SodaxWalletProvider.tsx +0 -97
- package/src/actions/getXChainType.ts +0 -8
- package/src/actions/getXService.ts +0 -33
- package/src/actions/index.ts +0 -2
- package/src/assets/wallets/hana.svg +0 -6
- package/src/assets/wallets/havah.svg +0 -76
- package/src/assets/wallets/keplr.svg +0 -30
- package/src/assets/wallets/metamask.svg +0 -60
- package/src/assets/wallets/phantom.svg +0 -4
- package/src/assets/wallets/sui.svg +0 -20
- package/src/core/XConnector.ts +0 -54
- package/src/core/XService.ts +0 -85
- package/src/core/index.ts +0 -2
- package/src/hooks/index.ts +0 -11
- package/src/hooks/useEthereumChainId.ts +0 -44
- package/src/hooks/useEvmSwitchChain.ts +0 -91
- package/src/hooks/useWalletProvider.ts +0 -206
- package/src/hooks/useXAccount.ts +0 -51
- package/src/hooks/useXAccounts.ts +0 -56
- package/src/hooks/useXBalances.ts +0 -65
- package/src/hooks/useXConnect.ts +0 -118
- package/src/hooks/useXConnection.ts +0 -72
- package/src/hooks/useXConnectors.ts +0 -72
- package/src/hooks/useXDisconnect.ts +0 -73
- package/src/hooks/useXService.ts +0 -8
- package/src/hooks/useXSignMessage.ts +0 -82
- package/src/index.ts +0 -19
- package/src/types/index.ts +0 -22
- package/src/useXWagmiStore.ts +0 -116
- package/src/utils/index.ts +0 -21
- package/src/xchains/bitcoin/BitcoinXConnector.ts +0 -34
- package/src/xchains/bitcoin/BitcoinXService.ts +0 -40
- package/src/xchains/bitcoin/OKXXConnector.ts +0 -117
- package/src/xchains/bitcoin/UnisatXConnector.ts +0 -117
- package/src/xchains/bitcoin/XverseXConnector.ts +0 -232
- package/src/xchains/bitcoin/index.ts +0 -7
- package/src/xchains/bitcoin/useBitcoinXConnectors.ts +0 -14
- package/src/xchains/evm/EvmXConnector.ts +0 -27
- package/src/xchains/evm/EvmXService.ts +0 -211
- package/src/xchains/evm/index.ts +0 -3
- package/src/xchains/icon/IconHanaXConnector.ts +0 -39
- package/src/xchains/icon/IconXService.ts +0 -117
- package/src/xchains/icon/actions.ts +0 -28
- package/src/xchains/icon/iconex/index.tsx +0 -46
- package/src/xchains/icon/index.ts +0 -2
- package/src/xchains/injective/InjectiveXConnector.ts +0 -60
- package/src/xchains/injective/InjectiveXService.ts +0 -62
- package/src/xchains/injective/actions.ts +0 -32
- package/src/xchains/injective/index.ts +0 -2
- package/src/xchains/near/NearXConnector.ts +0 -42
- package/src/xchains/near/NearXService.ts +0 -46
- package/src/xchains/near/useNearXConnectors.ts +0 -23
- package/src/xchains/solana/SolanaXConnector.ts +0 -26
- package/src/xchains/solana/SolanaXService.ts +0 -46
- package/src/xchains/solana/index.ts +0 -2
- package/src/xchains/stacks/StacksXConnector.ts +0 -63
- package/src/xchains/stacks/StacksXService.ts +0 -59
- package/src/xchains/stacks/constants.ts +0 -42
- package/src/xchains/stacks/index.ts +0 -4
- package/src/xchains/stacks/useStacksXConnectors.ts +0 -7
- package/src/xchains/stellar/CustomSorobanServer.ts +0 -93
- package/src/xchains/stellar/StellarWalletsKitXConnector.ts +0 -53
- package/src/xchains/stellar/StellarXService.ts +0 -93
- package/src/xchains/stellar/actions.ts +0 -24
- package/src/xchains/stellar/index.tsx +0 -2
- package/src/xchains/stellar/useStellarXConnectors.ts +0 -21
- package/src/xchains/stellar/utils.ts +0 -49
- package/src/xchains/sui/SuiXConnector.ts +0 -28
- package/src/xchains/sui/SuiXService.ts +0 -66
- package/src/xchains/sui/index.ts +0 -2
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
import { detectBitcoinAddressType, type IBitcoinWalletProvider, type AddressType } from '@sodax/types';
|
|
3
|
-
import { BitcoinXConnector } from './BitcoinXConnector';
|
|
4
|
-
|
|
5
|
-
// OKX Bitcoin wallet window API types
|
|
6
|
-
interface OKXBitcoinWallet {
|
|
7
|
-
getAccounts(): Promise<string[]>;
|
|
8
|
-
getPublicKey(): Promise<string>;
|
|
9
|
-
signPsbt(psbtHex: string, options?: { autoFinalized?: boolean }): Promise<string>;
|
|
10
|
-
signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
11
|
-
connect(): Promise<{ address: string; publicKey: string }>;
|
|
12
|
-
sendBitcoin(toAddress: string, satoshis: number): Promise<string>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare global {
|
|
16
|
-
interface Window {
|
|
17
|
-
okxwallet?: {
|
|
18
|
-
bitcoin?: OKXBitcoinWallet;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class OKXWalletProvider implements IBitcoinWalletProvider {
|
|
24
|
-
private okx: OKXBitcoinWallet;
|
|
25
|
-
private cachedAddress: string;
|
|
26
|
-
|
|
27
|
-
constructor(okx: OKXBitcoinWallet, address: string) {
|
|
28
|
-
this.okx = okx;
|
|
29
|
-
this.cachedAddress = address;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async getWalletAddress(): Promise<string> {
|
|
33
|
-
try {
|
|
34
|
-
const accounts = await this.okx.getAccounts();
|
|
35
|
-
if (accounts[0]) this.cachedAddress = accounts[0];
|
|
36
|
-
} catch {
|
|
37
|
-
// wallet locked — fall through to cached address
|
|
38
|
-
}
|
|
39
|
-
return this.cachedAddress;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async getPublicKey(): Promise<string> {
|
|
43
|
-
return this.okx.getPublicKey();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getAddressType(_address: string): Promise<AddressType> {
|
|
47
|
-
const address = await this.getWalletAddress();
|
|
48
|
-
return detectBitcoinAddressType(address);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async signTransaction(psbtBase64: string, finalize = false): Promise<string> {
|
|
52
|
-
const psbtHex = Buffer.from(psbtBase64, 'base64').toString('hex');
|
|
53
|
-
return this.okx.signPsbt(psbtHex, { autoFinalized: finalize });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async signEcdsaMessage(message: string): Promise<string> {
|
|
57
|
-
return this.okx.signMessage(message, 'ecdsa');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async signBip322Message(message: string): Promise<string> {
|
|
61
|
-
return this.okx.signMessage(message, 'bip322-simple');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async sendBitcoin(toAddress: string, satoshis: bigint): Promise<string> {
|
|
65
|
-
if (satoshis > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
66
|
-
throw new Error(`Amount ${satoshis} satoshis exceeds safe integer range`);
|
|
67
|
-
}
|
|
68
|
-
return this.okx.sendBitcoin(toAddress, Number(satoshis));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export class OKXXConnector extends BitcoinXConnector {
|
|
73
|
-
private walletProvider: OKXWalletProvider | undefined;
|
|
74
|
-
|
|
75
|
-
constructor() {
|
|
76
|
-
super('OKX Wallet', 'okx-bitcoin');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public static isAvailable(): boolean {
|
|
80
|
-
return typeof window !== 'undefined' && !!window.okxwallet?.bitcoin;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public get icon(): string {
|
|
84
|
-
return 'https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png';
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async connect(): Promise<XAccount | undefined> {
|
|
88
|
-
const okx = window.okxwallet?.bitcoin;
|
|
89
|
-
if (!okx) {
|
|
90
|
-
throw new Error('OKX wallet is not installed');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { address } = await okx.connect();
|
|
94
|
-
if (!address) return undefined;
|
|
95
|
-
|
|
96
|
-
this.walletProvider = new OKXWalletProvider(okx, address);
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
address,
|
|
100
|
-
xChainType: 'BITCOIN',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async disconnect(): Promise<void> {
|
|
105
|
-
this.walletProvider = undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getWalletProvider(): IBitcoinWalletProvider | undefined {
|
|
109
|
-
return this.walletProvider;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined {
|
|
113
|
-
const okx = window.okxwallet?.bitcoin;
|
|
114
|
-
if (!okx || !xAccount.address) return undefined;
|
|
115
|
-
return new OKXWalletProvider(okx, xAccount.address);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
import { detectBitcoinAddressType, type IBitcoinWalletProvider, type AddressType } from '@sodax/types';
|
|
3
|
-
import { BitcoinXConnector } from './BitcoinXConnector';
|
|
4
|
-
|
|
5
|
-
// Minimal Unisat window API types
|
|
6
|
-
interface UnisatWallet {
|
|
7
|
-
getAccounts(): Promise<string[]>;
|
|
8
|
-
getPublicKey(): Promise<string>;
|
|
9
|
-
signPsbt(psbtHex: string, options?: { autoFinalized?: boolean }): Promise<string>;
|
|
10
|
-
signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
11
|
-
requestAccounts(): Promise<string[]>;
|
|
12
|
-
sendBitcoin(address: string, satoshis: number): Promise<string>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare global {
|
|
16
|
-
interface Window {
|
|
17
|
-
unisat?: UnisatWallet;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
class UnisatWalletProvider implements IBitcoinWalletProvider {
|
|
22
|
-
private unisat: UnisatWallet;
|
|
23
|
-
private cachedAddress: string;
|
|
24
|
-
|
|
25
|
-
constructor(unisat: UnisatWallet, address: string) {
|
|
26
|
-
this.unisat = unisat;
|
|
27
|
-
this.cachedAddress = address;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async getWalletAddress(): Promise<string> {
|
|
31
|
-
try {
|
|
32
|
-
const accounts = await this.unisat.getAccounts();
|
|
33
|
-
if (accounts[0]) this.cachedAddress = accounts[0];
|
|
34
|
-
} catch {
|
|
35
|
-
// wallet locked — fall through to cached address
|
|
36
|
-
}
|
|
37
|
-
return this.cachedAddress;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async getPublicKey(): Promise<string> {
|
|
41
|
-
return this.unisat.getPublicKey();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getAddressType(_address: string): Promise<AddressType> {
|
|
45
|
-
const address = await this.getWalletAddress();
|
|
46
|
-
return detectBitcoinAddressType(address);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async signTransaction(psbtBase64: string, finalize = false): Promise<string> {
|
|
50
|
-
// Convert base64 → hex for Unisat, then back
|
|
51
|
-
const psbtHex = Buffer.from(psbtBase64, 'base64').toString('hex');
|
|
52
|
-
const signedHex = await this.unisat.signPsbt(psbtHex, { autoFinalized: finalize });
|
|
53
|
-
// Return as hex (BTCWalletProvider.signTransaction expects this)
|
|
54
|
-
return signedHex;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async signEcdsaMessage(message: string): Promise<string> {
|
|
58
|
-
return this.unisat.signMessage(message, 'ecdsa');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async signBip322Message(message: string): Promise<string> {
|
|
62
|
-
return this.unisat.signMessage(message, 'bip322-simple');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async sendBitcoin(toAddress: string, satoshis: bigint): Promise<string> {
|
|
66
|
-
if (satoshis > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
67
|
-
throw new Error(`Amount ${satoshis} satoshis exceeds safe integer range`);
|
|
68
|
-
}
|
|
69
|
-
return this.unisat.sendBitcoin(toAddress, Number(satoshis));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export class UnisatXConnector extends BitcoinXConnector {
|
|
74
|
-
private walletProvider: UnisatWalletProvider | undefined;
|
|
75
|
-
|
|
76
|
-
constructor() {
|
|
77
|
-
super('Unisat', 'unisat');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public static isAvailable(): boolean {
|
|
81
|
-
return typeof window !== 'undefined' && !!window.unisat;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public get icon(): string {
|
|
85
|
-
return 'https://avatars.githubusercontent.com/u/125119198?s=200&v=4';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async connect(): Promise<XAccount | undefined> {
|
|
89
|
-
if (!window.unisat) {
|
|
90
|
-
throw new Error('Unisat wallet is not installed');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const accounts = await window.unisat.requestAccounts();
|
|
94
|
-
const address = accounts[0];
|
|
95
|
-
if (!address) return undefined;
|
|
96
|
-
|
|
97
|
-
this.walletProvider = new UnisatWalletProvider(window.unisat, address);
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
address,
|
|
101
|
-
xChainType: 'BITCOIN',
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async disconnect(): Promise<void> {
|
|
106
|
-
this.walletProvider = undefined;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
getWalletProvider(): IBitcoinWalletProvider | undefined {
|
|
110
|
-
return this.walletProvider;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined {
|
|
114
|
-
if (!window.unisat || !xAccount.address) return undefined;
|
|
115
|
-
return new UnisatWalletProvider(window.unisat, xAccount.address);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
import { detectBitcoinAddressType, type IBitcoinWalletProvider, type AddressType, type BtcWalletAddressType } from '@sodax/types';
|
|
3
|
-
import { AddressPurpose, MessageSigningProtocols } from 'sats-connect';
|
|
4
|
-
import { BitcoinXConnector } from './BitcoinXConnector';
|
|
5
|
-
|
|
6
|
-
// sats-connect types
|
|
7
|
-
interface SignPsbtResult {
|
|
8
|
-
psbt: string; // base64 signed PSBT
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface GetAccountsResult {
|
|
12
|
-
address: string;
|
|
13
|
-
publicKey: string;
|
|
14
|
-
purpose: string;
|
|
15
|
-
addressType: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface SignMessageResult {
|
|
19
|
-
signature: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class XverseWalletProvider implements IBitcoinWalletProvider {
|
|
24
|
-
private address: string;
|
|
25
|
-
private publicKey: string;
|
|
26
|
-
|
|
27
|
-
constructor(address: string, publicKey: string) {
|
|
28
|
-
this.address = address;
|
|
29
|
-
this.publicKey = publicKey;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async getWalletAddress(): Promise<string> {
|
|
33
|
-
return this.address;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async getPublicKey(): Promise<string> {
|
|
37
|
-
return this.publicKey;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async getAddressType(_address: string): Promise<AddressType> {
|
|
41
|
-
return detectBitcoinAddressType(this.address);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Parse a base64-encoded PSBT to count the number of inputs.
|
|
46
|
-
* Reads the unsigned transaction from the PSBT global section.
|
|
47
|
-
*/
|
|
48
|
-
private countPsbtInputs(psbtBase64: string): number {
|
|
49
|
-
const data = Buffer.from(psbtBase64, 'base64');
|
|
50
|
-
// Skip 5-byte magic (0x70736274FF = "psbt" + separator)
|
|
51
|
-
let offset = 5;
|
|
52
|
-
|
|
53
|
-
// Global section: first key-value pair should be key 0x00 (unsigned tx)
|
|
54
|
-
const keyLen = data[offset++] ?? 0;
|
|
55
|
-
if (keyLen !== 1 || data[offset++] !== 0x00) {
|
|
56
|
-
return 1; // fallback: assume 1 input
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Read value length (compact size)
|
|
60
|
-
const firstByte = data[offset++] ?? 0;
|
|
61
|
-
if (firstByte === 0xfd) offset += 2;
|
|
62
|
-
else if (firstByte === 0xfe) offset += 4;
|
|
63
|
-
else if (firstByte === 0xff) offset += 8;
|
|
64
|
-
// else firstByte IS the length (< 0xfd), no extra bytes
|
|
65
|
-
|
|
66
|
-
// Unsigned tx: skip 4-byte version
|
|
67
|
-
offset += 4;
|
|
68
|
-
|
|
69
|
-
// Read input count (varint)
|
|
70
|
-
const inputByte = data[offset] ?? 0;
|
|
71
|
-
if (inputByte < 0xfd) return inputByte;
|
|
72
|
-
return 1; // fallback for unusual cases
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async signTransaction(psbtBase64: string, finalize = false): Promise<string> {
|
|
76
|
-
const { request } = await import('sats-connect');
|
|
77
|
-
|
|
78
|
-
const inputCount = this.countPsbtInputs(psbtBase64);
|
|
79
|
-
const signingIndexes = Array.from({ length: inputCount }, (_, i) => i);
|
|
80
|
-
|
|
81
|
-
const response = await request('signPsbt', {
|
|
82
|
-
psbt: psbtBase64,
|
|
83
|
-
broadcast: false,
|
|
84
|
-
signInputs: {
|
|
85
|
-
[this.address]: signingIndexes,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (response.status === 'error') {
|
|
90
|
-
throw new Error(response.error?.message || 'Xverse PSBT signing failed');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const result = response.result as SignPsbtResult;
|
|
94
|
-
|
|
95
|
-
if (finalize) {
|
|
96
|
-
// Return hex for broadcast
|
|
97
|
-
return Buffer.from(result.psbt, 'base64').toString('hex');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Return base64 signed PSBT (partially signed)
|
|
101
|
-
return result.psbt;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async signEcdsaMessage(message: string): Promise<string> {
|
|
105
|
-
const { request } = await import('sats-connect');
|
|
106
|
-
|
|
107
|
-
const response = await request('signMessage', {
|
|
108
|
-
address: this.address,
|
|
109
|
-
message,
|
|
110
|
-
protocol: MessageSigningProtocols.ECDSA,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
if (response.status === 'error') {
|
|
114
|
-
throw new Error(response.error?.message || 'Xverse ECDSA signing failed');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return (response.result as SignMessageResult).signature;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async signBip322Message(message: string): Promise<string> {
|
|
121
|
-
const { request } = await import('sats-connect');
|
|
122
|
-
|
|
123
|
-
const response = await request('signMessage', {
|
|
124
|
-
address: this.address,
|
|
125
|
-
message,
|
|
126
|
-
protocol: MessageSigningProtocols.BIP322,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
if (response.status === 'error') {
|
|
130
|
-
throw new Error(response.error?.message || 'Xverse BIP322 signing failed');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return (response.result as SignMessageResult).signature;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async sendBitcoin(toAddress: string, satoshis: bigint): Promise<string> {
|
|
137
|
-
const { request } = await import('sats-connect');
|
|
138
|
-
|
|
139
|
-
const response = await request('sendTransfer', {
|
|
140
|
-
recipients: [
|
|
141
|
-
{
|
|
142
|
-
address: toAddress,
|
|
143
|
-
amount: Number(satoshis),
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
if (response.status === 'error') {
|
|
149
|
-
throw new Error(response.error?.message || 'Xverse sendTransfer failed');
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return (response.result as { txid: string }).txid;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const XVERSE_ADDRESS_TYPE_KEY = 'xverse-address-type';
|
|
157
|
-
|
|
158
|
-
export class XverseXConnector extends BitcoinXConnector {
|
|
159
|
-
private walletProvider: XverseWalletProvider | undefined;
|
|
160
|
-
|
|
161
|
-
/** Address purpose used when connecting. Taproot (Ordinals) by default to match Radfi. */
|
|
162
|
-
public addressPurpose: AddressPurpose;
|
|
163
|
-
|
|
164
|
-
constructor() {
|
|
165
|
-
super('Xverse', 'xverse');
|
|
166
|
-
// Restore saved preference, default to Taproot
|
|
167
|
-
const saved = typeof window !== 'undefined' ? localStorage.getItem(XVERSE_ADDRESS_TYPE_KEY) : null;
|
|
168
|
-
this.addressPurpose = saved === 'segwit' ? AddressPurpose.Payment : AddressPurpose.Ordinals;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** Set address purpose and persist to localStorage. */
|
|
172
|
-
public setAddressPurpose(type: BtcWalletAddressType): void {
|
|
173
|
-
this.addressPurpose = type === 'taproot' ? AddressPurpose.Ordinals : AddressPurpose.Payment;
|
|
174
|
-
if (typeof window !== 'undefined') {
|
|
175
|
-
localStorage.setItem(XVERSE_ADDRESS_TYPE_KEY, type);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public static isAvailable(): boolean {
|
|
180
|
-
return typeof window !== 'undefined' && !!window.BitcoinProvider;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public get icon(): string {
|
|
184
|
-
return 'https://cdn.brandfetch.io/iddzGN5Rcv/w/400/h/400/theme/dark/icon.jpeg?c=1bxid64Mup7aczewSAYMX&t=1771902357797';
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
async connect(): Promise<XAccount | undefined> {
|
|
188
|
-
if (!XverseXConnector.isAvailable()) {
|
|
189
|
-
throw new Error('Xverse wallet is not installed');
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const { request } = await import('sats-connect');
|
|
193
|
-
|
|
194
|
-
const response = await request('getAccounts', {
|
|
195
|
-
purposes: [this.addressPurpose],
|
|
196
|
-
message: 'Connect to Sodax',
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
if (response.status === 'error') {
|
|
200
|
-
throw new Error(response.error?.message || 'Xverse connection failed');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const accounts = response.result as GetAccountsResult[];
|
|
204
|
-
const paymentAccount = accounts.find(a => a.purpose === this.addressPurpose) || accounts[0];
|
|
205
|
-
|
|
206
|
-
if (!paymentAccount) return undefined;
|
|
207
|
-
|
|
208
|
-
this.walletProvider = new XverseWalletProvider(
|
|
209
|
-
paymentAccount.address,
|
|
210
|
-
paymentAccount.publicKey,
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
address: paymentAccount.address,
|
|
215
|
-
publicKey: paymentAccount.publicKey,
|
|
216
|
-
xChainType: 'BITCOIN',
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
async disconnect(): Promise<void> {
|
|
221
|
-
this.walletProvider = undefined;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
getWalletProvider(): IBitcoinWalletProvider | undefined {
|
|
225
|
-
return this.walletProvider;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined {
|
|
229
|
-
if (!xAccount.address || !xAccount.publicKey) return undefined;
|
|
230
|
-
return new XverseWalletProvider(xAccount.address, xAccount.publicKey);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { BitcoinXService } from './BitcoinXService';
|
|
2
|
-
export { BitcoinXConnector } from './BitcoinXConnector';
|
|
3
|
-
export { UnisatXConnector } from './UnisatXConnector';
|
|
4
|
-
export { XverseXConnector } from './XverseXConnector';
|
|
5
|
-
export type { BtcWalletAddressType } from '@sodax/types';
|
|
6
|
-
export { OKXXConnector } from './OKXXConnector';
|
|
7
|
-
export { useBitcoinXConnectors } from './useBitcoinXConnectors';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import type { BitcoinXConnector } from './BitcoinXConnector';
|
|
3
|
-
import { useXService } from '../../hooks';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Hook to return available Bitcoin wallet connectors from the globally registered xService.
|
|
7
|
-
*/
|
|
8
|
-
export function useBitcoinXConnectors(): BitcoinXConnector[] {
|
|
9
|
-
const xService = useXService('BITCOIN');
|
|
10
|
-
|
|
11
|
-
return useMemo(() => {
|
|
12
|
-
return (xService?.getXConnectors() || []) as BitcoinXConnector[];
|
|
13
|
-
}, [xService]);
|
|
14
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { XConnector } from '@/core/XConnector';
|
|
2
|
-
import type { XAccount } from '@/types';
|
|
3
|
-
import type { Connector } from 'wagmi';
|
|
4
|
-
|
|
5
|
-
export class EvmXConnector extends XConnector {
|
|
6
|
-
connector: Connector;
|
|
7
|
-
|
|
8
|
-
constructor(connector: Connector) {
|
|
9
|
-
super('EVM', connector.name, connector.id);
|
|
10
|
-
this.connector = connector;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async connect(): Promise<XAccount | undefined> {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async disconnect(): Promise<void> {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public get id() {
|
|
22
|
-
return this.connector.id;
|
|
23
|
-
}
|
|
24
|
-
public get icon() {
|
|
25
|
-
return this.connector.icon;
|
|
26
|
-
}
|
|
27
|
-
}
|