@babylonlabs-io/wallet-connector 0.4.1 → 0.5.0
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 +34 -23
- package/dist/components/WalletProvider/components/WalletDialog.d.ts +3 -1
- package/dist/components/WalletProvider/constants.d.ts +1 -0
- package/dist/components/WalletProvider/index.d.ts +3 -1
- package/dist/context/Chain.context.d.ts +3 -2
- package/dist/context/LifecycleHooks.context.d.ts +9 -0
- package/dist/core/index.d.ts +3 -3
- package/dist/core/storage.d.ts +7 -0
- package/dist/core/types.d.ts +39 -33
- package/dist/core/wallets/bbn/keplr/provider.d.ts +3 -0
- package/dist/core/wallets/bbn/leap/provider.d.ts +3 -0
- package/dist/core/wallets/bbn/okx/provider.d.ts +3 -0
- package/dist/hooks/useWalletConnectors.d.ts +7 -2
- package/dist/index.cjs.js +38 -38
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +4791 -4596
- package/dist/index.es.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -89,14 +89,13 @@ Full interface definitions can be found in
|
|
|
89
89
|
Below we outline the interfaces for Bitcoin and Babylon wallets that need to be
|
|
90
90
|
implemented for integration with the Babylon staking app.
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
### IProvider
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
|
-
interface
|
|
95
|
+
export interface IProvider {
|
|
96
96
|
/**
|
|
97
97
|
* Connects to the wallet and returns the instance of the wallet provider.
|
|
98
|
-
*
|
|
99
|
-
* @returns A promise that resolves to an instance of the wrapper wallet provider in babylon friendly format.
|
|
98
|
+
* @returns A promise that resolves to an instance of the wrapper wallet provider.
|
|
100
99
|
* @throws An error if the wallet is not installed or if connection fails.
|
|
101
100
|
*/
|
|
102
101
|
connectWallet(): Promise<void>;
|
|
@@ -112,7 +111,13 @@ interface IBTCProvider extends IProvider {
|
|
|
112
111
|
* @returns A promise that resolves to the public key of the connected wallet.
|
|
113
112
|
*/
|
|
114
113
|
getPublicKeyHex(): Promise<string>;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### IBTCProvider
|
|
115
118
|
|
|
119
|
+
```ts
|
|
120
|
+
interface IBTCProvider extends IProvider {
|
|
116
121
|
/**
|
|
117
122
|
* Signs the given PSBT in hex format.
|
|
118
123
|
* @param psbtHex - The hex string of the unsigned PSBT to sign.
|
|
@@ -180,25 +185,6 @@ interface IBTCProvider extends IProvider {
|
|
|
180
185
|
|
|
181
186
|
```ts
|
|
182
187
|
export interface IBBNProvider extends IProvider {
|
|
183
|
-
/**
|
|
184
|
-
* Connects to the wallet and returns the instance of the wallet provider.
|
|
185
|
-
* @returns A promise that resolves to an instance of the wrapper wallet provider.
|
|
186
|
-
* @throws An error if the wallet is not installed or if connection fails.
|
|
187
|
-
*/
|
|
188
|
-
connectWallet(): Promise<void>;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Gets the address of the connected wallet.
|
|
192
|
-
* @returns A promise that resolves to the address of the connected wallet.
|
|
193
|
-
*/
|
|
194
|
-
getAddress(): Promise<string>;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Gets the public key of the connected wallet.
|
|
198
|
-
* @returns A promise that resolves to the public key of the connected wallet.
|
|
199
|
-
*/
|
|
200
|
-
getPublicKeyHex(): Promise<string>;
|
|
201
|
-
|
|
202
188
|
/**
|
|
203
189
|
* Gets the name of the wallet provider.
|
|
204
190
|
* @returns A promise that resolves to the name of the wallet provider.
|
|
@@ -219,6 +205,31 @@ export interface IBBNProvider extends IProvider {
|
|
|
219
205
|
* @throws {Error} If wallet connection is not established or signer cannot be retrieved
|
|
220
206
|
*/
|
|
221
207
|
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Retrieves an offline signer that supports either Amino or Direct signing methods.
|
|
211
|
+
* This is required for compatibility with older wallets and hardware wallets (like Ledger) that do not support both signing methods.
|
|
212
|
+
* This signer is used for signing transactions offline before broadcasting them to the network.
|
|
213
|
+
*
|
|
214
|
+
* @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting either Amino or Direct signing
|
|
215
|
+
* @throws {Error} If wallet connection is not established or signer cannot be retrieved
|
|
216
|
+
*/
|
|
217
|
+
getOfflineSignerAuto?(): Promise<OfflineAminoSigner | OfflineDirectSigner>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Registers an event listener for the specified event.
|
|
221
|
+
* At the moment, only the "accountChanged" event is supported.
|
|
222
|
+
* @param eventName - The name of the event to listen for.
|
|
223
|
+
* @param callBack - The callback function to be executed when the event occurs.
|
|
224
|
+
*/
|
|
225
|
+
on(eventName: string, callBack: () => void): void;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Unregisters an event listener for the specified event.
|
|
229
|
+
* @param eventName - The name of the event to listen for.
|
|
230
|
+
* @param callBack - The callback function to be executed when the event occurs.
|
|
231
|
+
*/
|
|
232
|
+
off(eventName: string, callBack: () => void): void;
|
|
222
233
|
}
|
|
223
234
|
```
|
|
224
235
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { HashMap } from '../../../core/types';
|
|
1
2
|
interface WalletDialogProps {
|
|
2
3
|
onError?: (e: Error) => void;
|
|
4
|
+
storage: HashMap;
|
|
3
5
|
config: any;
|
|
4
6
|
}
|
|
5
|
-
export declare function WalletDialog({ config, onError }: WalletDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function WalletDialog({ storage, config, onError }: WalletDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
6
8
|
export {};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { ChainConfigArr } from '../../context/Chain.context';
|
|
3
|
+
import { LifeCycleHooksProps } from '../../context/LifecycleHooks.context';
|
|
3
4
|
interface WalletProviderProps {
|
|
5
|
+
lifecycleHooks?: LifeCycleHooksProps;
|
|
4
6
|
context?: any;
|
|
5
7
|
config: Readonly<ChainConfigArr>;
|
|
6
8
|
onError?: (e: Error) => void;
|
|
7
9
|
}
|
|
8
|
-
export declare function WalletProvider({ children, config, context, onError, }: PropsWithChildren<WalletProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function WalletProvider({ lifecycleHooks, children, config, context, onError, }: PropsWithChildren<WalletProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
9
11
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { WalletConnector } from '../core/WalletConnector';
|
|
3
|
-
import { BBNConfig, BTCConfig, ExternalConnector, IBBNProvider, IBTCProvider, IProvider } from '../core/types';
|
|
3
|
+
import { BBNConfig, BTCConfig, ExternalConnector, HashMap, IBBNProvider, IBTCProvider, IProvider } from '../core/types';
|
|
4
4
|
interface ChainConfig<K extends string = string, P extends IProvider = IProvider, C = any> {
|
|
5
5
|
chain: K;
|
|
6
6
|
name?: string;
|
|
@@ -10,6 +10,7 @@ interface ChainConfig<K extends string = string, P extends IProvider = IProvider
|
|
|
10
10
|
}
|
|
11
11
|
export type ChainConfigArr = (ChainConfig<"BTC", IBTCProvider, BTCConfig> | ChainConfig<"BBN", IBBNProvider, BBNConfig>)[];
|
|
12
12
|
interface ProviderProps {
|
|
13
|
+
storage: HashMap;
|
|
13
14
|
context: any;
|
|
14
15
|
config: Readonly<ChainConfigArr>;
|
|
15
16
|
onError?: (e: Error) => void;
|
|
@@ -19,6 +20,6 @@ export interface Connectors {
|
|
|
19
20
|
BBN: WalletConnector<"BBN", IBBNProvider, BBNConfig> | null;
|
|
20
21
|
}
|
|
21
22
|
export declare const Context: import('react').Context<Connectors>;
|
|
22
|
-
export declare function ChainProvider({ children, context, config, onError }: PropsWithChildren<ProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare function ChainProvider({ storage, children, context, config, onError }: PropsWithChildren<ProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
23
24
|
export declare const useChainProviders: () => Connectors;
|
|
24
25
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
export interface LifeCycleHooksProps {
|
|
3
|
+
verifyBTCAddress?: (address: string) => Promise<boolean>;
|
|
4
|
+
acceptTermsOfService?: () => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare function LifeCycleHooksProvider({ children, value }: PropsWithChildren<{
|
|
7
|
+
value?: LifeCycleHooksProps;
|
|
8
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare const useLifeCycleHooks: () => LifeCycleHooksProps;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Wallet } from './Wallet';
|
|
2
2
|
import { WalletConnector } from './WalletConnector';
|
|
3
|
-
import {
|
|
4
|
-
export declare const createWallet: <P extends IProvider, C>(metadata
|
|
3
|
+
import { ExternalWalletProps, IProvider, WalletConnectorProps, WalletProps } from './types';
|
|
4
|
+
export declare const createWallet: <P extends IProvider, C>({ metadata, context, config }: WalletProps<P, C>) => Promise<Wallet<P>>;
|
|
5
5
|
export declare const createExternalWallet: <P extends IProvider>({ id, name, icon, provider }: ExternalWalletProps<P>) => Wallet<P>;
|
|
6
|
-
export declare const createWalletConnector: <N extends string, P extends IProvider, C>(metadata
|
|
6
|
+
export declare const createWalletConnector: <N extends string, P extends IProvider, C>({ metadata, context, config, accountStorage, }: WalletConnectorProps<N, P, C>) => Promise<WalletConnector<N, P, C>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HashMap } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Factory method instantiates an instance of persistent key value storage with predefined ttl value
|
|
4
|
+
* @param ttl - time to live in ms
|
|
5
|
+
* @returns - key value storage
|
|
6
|
+
*/
|
|
7
|
+
export declare const createAccountStorage: (ttl: number) => HashMap;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -95,6 +95,17 @@ export interface ExternalWalletProps<P extends IProvider> {
|
|
|
95
95
|
icon: string;
|
|
96
96
|
provider: P;
|
|
97
97
|
}
|
|
98
|
+
export interface WalletConnectorProps<N extends string, P extends IProvider, C> {
|
|
99
|
+
metadata: ChainMetadata<N, P, C>;
|
|
100
|
+
context: any;
|
|
101
|
+
config: C;
|
|
102
|
+
accountStorage: HashMap;
|
|
103
|
+
}
|
|
104
|
+
export interface WalletProps<P extends IProvider, C> {
|
|
105
|
+
metadata: WalletMetadata<P, C>;
|
|
106
|
+
context: any;
|
|
107
|
+
config: C;
|
|
108
|
+
}
|
|
98
109
|
export interface WidgetProps<P extends IProvider = IProvider> {
|
|
99
110
|
id: string;
|
|
100
111
|
connector: IConnector;
|
|
@@ -106,23 +117,6 @@ export interface ExternalConnector<P extends IProvider = IProvider> {
|
|
|
106
117
|
widget: WidgetComponent<P>;
|
|
107
118
|
}
|
|
108
119
|
export interface IBTCProvider extends IProvider {
|
|
109
|
-
/**
|
|
110
|
-
* Connects to the wallet and returns the instance of the wallet provider.
|
|
111
|
-
* Currently only supports "native segwit" and "taproot" address types.
|
|
112
|
-
* @returns A promise that resolves to an instance of the wrapper wallet provider in babylon friendly format.
|
|
113
|
-
* @throws An error if the wallet is not installed or if connection fails.
|
|
114
|
-
*/
|
|
115
|
-
connectWallet(): Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* Gets the address of the connected wallet.
|
|
118
|
-
* @returns A promise that resolves to the address of the connected wallet.
|
|
119
|
-
*/
|
|
120
|
-
getAddress(): Promise<string>;
|
|
121
|
-
/**
|
|
122
|
-
* Gets the public key of the connected wallet.
|
|
123
|
-
* @returns A promise that resolves to the public key of the connected wallet.
|
|
124
|
-
*/
|
|
125
|
-
getPublicKeyHex(): Promise<string>;
|
|
126
120
|
/**
|
|
127
121
|
* Signs the given PSBT in hex format.
|
|
128
122
|
* @param psbtHex - The hex string of the unsigned PSBT to sign.
|
|
@@ -177,22 +171,6 @@ export interface IBTCProvider extends IProvider {
|
|
|
177
171
|
getWalletProviderIcon(): Promise<string>;
|
|
178
172
|
}
|
|
179
173
|
export interface IBBNProvider extends IProvider {
|
|
180
|
-
/**
|
|
181
|
-
* Connects to the wallet and returns the instance of the wallet provider.
|
|
182
|
-
* @returns A promise that resolves to an instance of the wrapper wallet provider.
|
|
183
|
-
* @throws An error if the wallet is not installed or if connection fails.
|
|
184
|
-
*/
|
|
185
|
-
connectWallet(): Promise<void>;
|
|
186
|
-
/**
|
|
187
|
-
* Gets the address of the connected wallet.
|
|
188
|
-
* @returns A promise that resolves to the address of the connected wallet.
|
|
189
|
-
*/
|
|
190
|
-
getAddress(): Promise<string>;
|
|
191
|
-
/**
|
|
192
|
-
* Gets the public key of the connected wallet.
|
|
193
|
-
* @returns A promise that resolves to the public key of the connected wallet.
|
|
194
|
-
*/
|
|
195
|
-
getPublicKeyHex(): Promise<string>;
|
|
196
174
|
/**
|
|
197
175
|
* Gets the name of the wallet provider.
|
|
198
176
|
* @returns A promise that resolves to the name of the wallet provider.
|
|
@@ -211,4 +189,32 @@ export interface IBBNProvider extends IProvider {
|
|
|
211
189
|
* @throws {Error} If wallet connection is not established or signer cannot be retrieved
|
|
212
190
|
*/
|
|
213
191
|
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
|
|
192
|
+
/**
|
|
193
|
+
* Retrieves an offline signer that supports either Amino or Direct signing methods.
|
|
194
|
+
* This is required for compatibility with older wallets and hardware wallets (like Ledger) that do not support both signing methods.
|
|
195
|
+
* This signer is used for signing transactions offline before broadcasting them to the network.
|
|
196
|
+
*
|
|
197
|
+
* @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting either Amino or Direct signing
|
|
198
|
+
* @throws {Error} If wallet connection is not established or signer cannot be retrieved
|
|
199
|
+
*/
|
|
200
|
+
getOfflineSignerAuto?(): Promise<OfflineAminoSigner | OfflineDirectSigner>;
|
|
201
|
+
/**
|
|
202
|
+
* Registers an event listener for the specified event.
|
|
203
|
+
* At the moment, only the "accountChanged" event is supported.
|
|
204
|
+
* @param eventName - The name of the event to listen for.
|
|
205
|
+
* @param callBack - The callback function to be executed when the event occurs.
|
|
206
|
+
*/
|
|
207
|
+
on(eventName: string, callBack: () => void): void;
|
|
208
|
+
/**
|
|
209
|
+
* Unregisters an event listener for the specified event.
|
|
210
|
+
* @param eventName - The name of the event to listen for.
|
|
211
|
+
* @param callBack - The callback function to be executed when the event occurs.
|
|
212
|
+
*/
|
|
213
|
+
off(eventName: string, callBack: () => void): void;
|
|
214
|
+
}
|
|
215
|
+
export interface HashMap {
|
|
216
|
+
get: (key: string) => string | undefined;
|
|
217
|
+
set: (key: string, value: any) => void;
|
|
218
|
+
has: (key: string) => boolean;
|
|
219
|
+
delete: (key: string) => boolean;
|
|
214
220
|
}
|
|
@@ -19,4 +19,7 @@ export declare class KeplrProvider implements IBBNProvider {
|
|
|
19
19
|
getWalletProviderName(): Promise<string>;
|
|
20
20
|
getWalletProviderIcon(): Promise<string>;
|
|
21
21
|
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
|
|
22
|
+
getOfflineSignerAuto(): Promise<OfflineAminoSigner | OfflineDirectSigner>;
|
|
23
|
+
on: (eventName: string, callBack: () => void) => void;
|
|
24
|
+
off: (eventName: string, callBack: () => void) => void;
|
|
22
25
|
}
|
|
@@ -14,4 +14,7 @@ export declare class LeapProvider implements IBBNProvider {
|
|
|
14
14
|
getWalletProviderName(): Promise<string>;
|
|
15
15
|
getWalletProviderIcon(): Promise<string>;
|
|
16
16
|
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
|
|
17
|
+
getOfflineSignerAuto(): Promise<OfflineAminoSigner | OfflineDirectSigner>;
|
|
18
|
+
on: (eventName: string, callBack: () => void) => void;
|
|
19
|
+
off: (eventName: string, callBack: () => void) => void;
|
|
17
20
|
}
|
|
@@ -14,4 +14,7 @@ export declare class OKXBabylonProvider implements IBBNProvider {
|
|
|
14
14
|
getWalletProviderName(): Promise<string>;
|
|
15
15
|
getWalletProviderIcon(): Promise<string>;
|
|
16
16
|
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
|
|
17
|
+
getOfflineSignerAuto(): Promise<OfflineAminoSigner | OfflineDirectSigner>;
|
|
18
|
+
on: (eventName: string, callBack: () => void) => void;
|
|
19
|
+
off: (eventName: string, callBack: () => void) => void;
|
|
17
20
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { IChain, IWallet } from '../core/types';
|
|
2
|
-
|
|
1
|
+
import { HashMap, IChain, IWallet } from '../core/types';
|
|
2
|
+
interface Props {
|
|
3
|
+
accountStorage: HashMap;
|
|
4
|
+
onError?: (e: Error) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function useWalletConnectors({ accountStorage, onError }: Props): {
|
|
3
7
|
connect: (chain: IChain, wallet: IWallet) => Promise<void>;
|
|
4
8
|
disconnect: (chainId: string) => Promise<void>;
|
|
5
9
|
};
|
|
10
|
+
export {};
|