@babylonlabs-io/wallet-connector 0.4.2 → 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 +9 -23
- package/dist/components/WalletProvider/components/WalletDialog.d.ts +3 -1
- package/dist/components/WalletProvider/constants.d.ts +1 -0
- package/dist/context/Chain.context.d.ts +3 -2
- package/dist/core/index.d.ts +3 -3
- package/dist/core/storage.d.ts +7 -0
- package/dist/core/types.d.ts +17 -33
- package/dist/hooks/useWalletConnectors.d.ts +7 -2
- package/dist/index.cjs.js +35 -35
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +3345 -3238
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
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.
|
|
@@ -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,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 {};
|
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.
|
|
@@ -234,3 +212,9 @@ export interface IBBNProvider extends IProvider {
|
|
|
234
212
|
*/
|
|
235
213
|
off(eventName: string, callBack: () => void): void;
|
|
236
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;
|
|
220
|
+
}
|
|
@@ -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 {};
|