@sodax/wallet-sdk-react 1.3.1-beta-rc1 → 1.3.1-beta-rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +505 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +108 -4
- package/dist/index.d.ts +108 -4
- package/dist/index.mjs +499 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/actions/getXService.ts +3 -1
- package/src/hooks/useWalletProvider.ts +14 -2
- package/src/index.ts +1 -0
- package/src/types/index.ts +1 -0
- package/src/useXWagmiStore.ts +13 -1
- package/src/utils/index.ts +2 -1
- package/src/xchains/bitcoin/BitcoinXConnector.ts +34 -0
- package/src/xchains/bitcoin/BitcoinXService.ts +40 -0
- package/src/xchains/bitcoin/OKXXConnector.ts +117 -0
- package/src/xchains/bitcoin/UnisatXConnector.ts +117 -0
- package/src/xchains/bitcoin/XverseXConnector.ts +216 -0
- package/src/xchains/bitcoin/index.ts +6 -0
- package/src/xchains/bitcoin/useBitcoinXConnectors.ts +14 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainId, ChainType, XToken, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
|
|
1
|
+
import { ChainId, ChainType, XToken, IBitcoinWalletProvider, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
|
|
2
2
|
import { Config, Connector } from 'wagmi';
|
|
3
3
|
import { IconService } from 'icon-sdk-js';
|
|
4
4
|
import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi } from '@injectivelabs/sdk-ts';
|
|
@@ -20,6 +20,7 @@ declare function getXChainType(xChainId: ChainId | undefined): ChainType | undef
|
|
|
20
20
|
type XAccount = {
|
|
21
21
|
address: string | undefined;
|
|
22
22
|
xChainType: ChainType | undefined;
|
|
23
|
+
publicKey?: string;
|
|
23
24
|
};
|
|
24
25
|
type XConnection = {
|
|
25
26
|
xAccount: XAccount;
|
|
@@ -127,6 +128,109 @@ declare function getXService(xChainType: ChainType): XService;
|
|
|
127
128
|
declare const isNativeToken: (xToken: XToken) => boolean;
|
|
128
129
|
declare const getWagmiChainId: (xChainId: ChainId) => number;
|
|
129
130
|
|
|
131
|
+
declare class BitcoinXService extends XService {
|
|
132
|
+
private static instance;
|
|
133
|
+
private rpcUrl;
|
|
134
|
+
private constructor();
|
|
135
|
+
static getInstance(rpcUrl?: string): BitcoinXService;
|
|
136
|
+
getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Abstract base class for Bitcoin wallet connectors.
|
|
141
|
+
* Subclasses implement wallet-specific connection logic (Unisat, Xverse, OKX).
|
|
142
|
+
*/
|
|
143
|
+
declare abstract class BitcoinXConnector extends XConnector {
|
|
144
|
+
constructor(name: string, id: string);
|
|
145
|
+
getXService(): BitcoinXService;
|
|
146
|
+
abstract connect(): Promise<XAccount | undefined>;
|
|
147
|
+
abstract disconnect(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Returns an IBitcoinWalletProvider instance after connecting.
|
|
150
|
+
* Used by useSpokeProvider to build BitcoinSpokeProvider.
|
|
151
|
+
*/
|
|
152
|
+
abstract getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Recreates a walletProvider from the browser extension window object
|
|
155
|
+
* and stored xAccount data (no connect() call, no popup).
|
|
156
|
+
* Used to restore provider after page reload without requiring reconnect.
|
|
157
|
+
*/
|
|
158
|
+
abstract recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface UnisatWallet {
|
|
162
|
+
getAccounts(): Promise<string[]>;
|
|
163
|
+
getPublicKey(): Promise<string>;
|
|
164
|
+
signPsbt(psbtHex: string, options?: {
|
|
165
|
+
autoFinalized?: boolean;
|
|
166
|
+
}): Promise<string>;
|
|
167
|
+
signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
168
|
+
requestAccounts(): Promise<string[]>;
|
|
169
|
+
sendBitcoin(address: string, satoshis: number): Promise<string>;
|
|
170
|
+
}
|
|
171
|
+
declare global {
|
|
172
|
+
interface Window {
|
|
173
|
+
unisat?: UnisatWallet;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
declare class UnisatXConnector extends BitcoinXConnector {
|
|
177
|
+
private walletProvider;
|
|
178
|
+
constructor();
|
|
179
|
+
static isAvailable(): boolean;
|
|
180
|
+
get icon(): string;
|
|
181
|
+
connect(): Promise<XAccount | undefined>;
|
|
182
|
+
disconnect(): Promise<void>;
|
|
183
|
+
getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
184
|
+
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare class XverseXConnector extends BitcoinXConnector {
|
|
188
|
+
private walletProvider;
|
|
189
|
+
constructor();
|
|
190
|
+
static isAvailable(): boolean;
|
|
191
|
+
get icon(): string;
|
|
192
|
+
connect(): Promise<XAccount | undefined>;
|
|
193
|
+
disconnect(): Promise<void>;
|
|
194
|
+
getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
195
|
+
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface OKXBitcoinWallet {
|
|
199
|
+
getAccounts(): Promise<string[]>;
|
|
200
|
+
getPublicKey(): Promise<string>;
|
|
201
|
+
signPsbt(psbtHex: string, options?: {
|
|
202
|
+
autoFinalized?: boolean;
|
|
203
|
+
}): Promise<string>;
|
|
204
|
+
signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
205
|
+
connect(): Promise<{
|
|
206
|
+
address: string;
|
|
207
|
+
publicKey: string;
|
|
208
|
+
}>;
|
|
209
|
+
sendBitcoin(toAddress: string, satoshis: number): Promise<string>;
|
|
210
|
+
}
|
|
211
|
+
declare global {
|
|
212
|
+
interface Window {
|
|
213
|
+
okxwallet?: {
|
|
214
|
+
bitcoin?: OKXBitcoinWallet;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
declare class OKXXConnector extends BitcoinXConnector {
|
|
219
|
+
private walletProvider;
|
|
220
|
+
constructor();
|
|
221
|
+
static isAvailable(): boolean;
|
|
222
|
+
get icon(): string;
|
|
223
|
+
connect(): Promise<XAccount | undefined>;
|
|
224
|
+
disconnect(): Promise<void>;
|
|
225
|
+
getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
226
|
+
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Hook to return available Bitcoin wallet connectors from the globally registered xService.
|
|
231
|
+
*/
|
|
232
|
+
declare function useBitcoinXConnectors(): BitcoinXConnector[];
|
|
233
|
+
|
|
130
234
|
/**
|
|
131
235
|
* Service class for handling EVM chain interactions.
|
|
132
236
|
* Implements singleton pattern and provides methods for wallet/chain operations.
|
|
@@ -271,7 +375,7 @@ declare class SuiXConnector extends XConnector {
|
|
|
271
375
|
|
|
272
376
|
declare function useXAccount(chainIdentifier?: ChainType | ChainId): XAccount;
|
|
273
377
|
|
|
274
|
-
declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR", XAccount>>;
|
|
378
|
+
declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR" | "BITCOIN", XAccount>>;
|
|
275
379
|
|
|
276
380
|
/**
|
|
277
381
|
* Hook for connecting to various blockchain wallets across different chains
|
|
@@ -425,7 +529,7 @@ declare const useEvmSwitchChain: (expectedXChainId: ChainId) => UseEvmSwitchChai
|
|
|
425
529
|
* const walletProvider = useWalletProvider('sui');
|
|
426
530
|
* ```
|
|
427
531
|
*/
|
|
428
|
-
declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | INearWalletProvider | undefined;
|
|
532
|
+
declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | IBitcoinWalletProvider | INearWalletProvider | undefined;
|
|
429
533
|
|
|
430
534
|
type SignMessageReturnType = `0x${string}` | Uint8Array | string | undefined;
|
|
431
535
|
declare function useXSignMessage(): UseMutationResult<SignMessageReturnType, Error, {
|
|
@@ -464,4 +568,4 @@ declare const SodaxWalletProvider: ({ children, rpcConfig }: {
|
|
|
464
568
|
rpcConfig: RpcConfig;
|
|
465
569
|
}) => React.JSX.Element;
|
|
466
570
|
|
|
467
|
-
export { type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, WalletId, type XAccount, type XConnection, XConnector, XService, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
|
|
571
|
+
export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, OKXXConnector, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useBitcoinXConnectors, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainId, ChainType, XToken, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
|
|
1
|
+
import { ChainId, ChainType, XToken, IBitcoinWalletProvider, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
|
|
2
2
|
import { Config, Connector } from 'wagmi';
|
|
3
3
|
import { IconService } from 'icon-sdk-js';
|
|
4
4
|
import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi } from '@injectivelabs/sdk-ts';
|
|
@@ -20,6 +20,7 @@ declare function getXChainType(xChainId: ChainId | undefined): ChainType | undef
|
|
|
20
20
|
type XAccount = {
|
|
21
21
|
address: string | undefined;
|
|
22
22
|
xChainType: ChainType | undefined;
|
|
23
|
+
publicKey?: string;
|
|
23
24
|
};
|
|
24
25
|
type XConnection = {
|
|
25
26
|
xAccount: XAccount;
|
|
@@ -127,6 +128,109 @@ declare function getXService(xChainType: ChainType): XService;
|
|
|
127
128
|
declare const isNativeToken: (xToken: XToken) => boolean;
|
|
128
129
|
declare const getWagmiChainId: (xChainId: ChainId) => number;
|
|
129
130
|
|
|
131
|
+
declare class BitcoinXService extends XService {
|
|
132
|
+
private static instance;
|
|
133
|
+
private rpcUrl;
|
|
134
|
+
private constructor();
|
|
135
|
+
static getInstance(rpcUrl?: string): BitcoinXService;
|
|
136
|
+
getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Abstract base class for Bitcoin wallet connectors.
|
|
141
|
+
* Subclasses implement wallet-specific connection logic (Unisat, Xverse, OKX).
|
|
142
|
+
*/
|
|
143
|
+
declare abstract class BitcoinXConnector extends XConnector {
|
|
144
|
+
constructor(name: string, id: string);
|
|
145
|
+
getXService(): BitcoinXService;
|
|
146
|
+
abstract connect(): Promise<XAccount | undefined>;
|
|
147
|
+
abstract disconnect(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Returns an IBitcoinWalletProvider instance after connecting.
|
|
150
|
+
* Used by useSpokeProvider to build BitcoinSpokeProvider.
|
|
151
|
+
*/
|
|
152
|
+
abstract getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Recreates a walletProvider from the browser extension window object
|
|
155
|
+
* and stored xAccount data (no connect() call, no popup).
|
|
156
|
+
* Used to restore provider after page reload without requiring reconnect.
|
|
157
|
+
*/
|
|
158
|
+
abstract recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface UnisatWallet {
|
|
162
|
+
getAccounts(): Promise<string[]>;
|
|
163
|
+
getPublicKey(): Promise<string>;
|
|
164
|
+
signPsbt(psbtHex: string, options?: {
|
|
165
|
+
autoFinalized?: boolean;
|
|
166
|
+
}): Promise<string>;
|
|
167
|
+
signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
168
|
+
requestAccounts(): Promise<string[]>;
|
|
169
|
+
sendBitcoin(address: string, satoshis: number): Promise<string>;
|
|
170
|
+
}
|
|
171
|
+
declare global {
|
|
172
|
+
interface Window {
|
|
173
|
+
unisat?: UnisatWallet;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
declare class UnisatXConnector extends BitcoinXConnector {
|
|
177
|
+
private walletProvider;
|
|
178
|
+
constructor();
|
|
179
|
+
static isAvailable(): boolean;
|
|
180
|
+
get icon(): string;
|
|
181
|
+
connect(): Promise<XAccount | undefined>;
|
|
182
|
+
disconnect(): Promise<void>;
|
|
183
|
+
getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
184
|
+
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare class XverseXConnector extends BitcoinXConnector {
|
|
188
|
+
private walletProvider;
|
|
189
|
+
constructor();
|
|
190
|
+
static isAvailable(): boolean;
|
|
191
|
+
get icon(): string;
|
|
192
|
+
connect(): Promise<XAccount | undefined>;
|
|
193
|
+
disconnect(): Promise<void>;
|
|
194
|
+
getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
195
|
+
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface OKXBitcoinWallet {
|
|
199
|
+
getAccounts(): Promise<string[]>;
|
|
200
|
+
getPublicKey(): Promise<string>;
|
|
201
|
+
signPsbt(psbtHex: string, options?: {
|
|
202
|
+
autoFinalized?: boolean;
|
|
203
|
+
}): Promise<string>;
|
|
204
|
+
signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
205
|
+
connect(): Promise<{
|
|
206
|
+
address: string;
|
|
207
|
+
publicKey: string;
|
|
208
|
+
}>;
|
|
209
|
+
sendBitcoin(toAddress: string, satoshis: number): Promise<string>;
|
|
210
|
+
}
|
|
211
|
+
declare global {
|
|
212
|
+
interface Window {
|
|
213
|
+
okxwallet?: {
|
|
214
|
+
bitcoin?: OKXBitcoinWallet;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
declare class OKXXConnector extends BitcoinXConnector {
|
|
219
|
+
private walletProvider;
|
|
220
|
+
constructor();
|
|
221
|
+
static isAvailable(): boolean;
|
|
222
|
+
get icon(): string;
|
|
223
|
+
connect(): Promise<XAccount | undefined>;
|
|
224
|
+
disconnect(): Promise<void>;
|
|
225
|
+
getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
226
|
+
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Hook to return available Bitcoin wallet connectors from the globally registered xService.
|
|
231
|
+
*/
|
|
232
|
+
declare function useBitcoinXConnectors(): BitcoinXConnector[];
|
|
233
|
+
|
|
130
234
|
/**
|
|
131
235
|
* Service class for handling EVM chain interactions.
|
|
132
236
|
* Implements singleton pattern and provides methods for wallet/chain operations.
|
|
@@ -271,7 +375,7 @@ declare class SuiXConnector extends XConnector {
|
|
|
271
375
|
|
|
272
376
|
declare function useXAccount(chainIdentifier?: ChainType | ChainId): XAccount;
|
|
273
377
|
|
|
274
|
-
declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR", XAccount>>;
|
|
378
|
+
declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR" | "BITCOIN", XAccount>>;
|
|
275
379
|
|
|
276
380
|
/**
|
|
277
381
|
* Hook for connecting to various blockchain wallets across different chains
|
|
@@ -425,7 +529,7 @@ declare const useEvmSwitchChain: (expectedXChainId: ChainId) => UseEvmSwitchChai
|
|
|
425
529
|
* const walletProvider = useWalletProvider('sui');
|
|
426
530
|
* ```
|
|
427
531
|
*/
|
|
428
|
-
declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | INearWalletProvider | undefined;
|
|
532
|
+
declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | IBitcoinWalletProvider | INearWalletProvider | undefined;
|
|
429
533
|
|
|
430
534
|
type SignMessageReturnType = `0x${string}` | Uint8Array | string | undefined;
|
|
431
535
|
declare function useXSignMessage(): UseMutationResult<SignMessageReturnType, Error, {
|
|
@@ -464,4 +568,4 @@ declare const SodaxWalletProvider: ({ children, rpcConfig }: {
|
|
|
464
568
|
rpcConfig: RpcConfig;
|
|
465
569
|
}) => React.JSX.Element;
|
|
466
570
|
|
|
467
|
-
export { type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, WalletId, type XAccount, type XConnection, XConnector, XService, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
|
|
571
|
+
export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, OKXXConnector, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useBitcoinXConnectors, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
|