@babylonlabs-io/wallet-connector 0.4.2 → 0.5.1

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 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
- #### IBTCProvider
92
+ ### IProvider
93
93
 
94
94
  ```ts
95
- interface IBTCProvider extends IProvider {
95
+ export interface IProvider {
96
96
  /**
97
97
  * Connects to the wallet and returns the instance of the wallet provider.
98
- * Currently only supports "native segwit" and "taproot" address types.
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.
@@ -134,12 +139,15 @@ interface IBTCProvider extends IProvider {
134
139
  getNetwork(): Promise<Network>;
135
140
 
136
141
  /**
137
- * Signs a message using the specified signing method.
142
+ * Signs a message using either BIP322-Simple or ECDSA signing method.
138
143
  * @param message - The message to sign.
139
144
  * @param type - The signing method to use.
140
145
  * @returns A promise that resolves to the signed message.
141
146
  */
142
- signMessage(message: string, type: "ecdsa"): Promise<string>;
147
+ signMessage(
148
+ message: string,
149
+ type: "bip322-simple" | "ecdsa",
150
+ ): Promise<string>;
143
151
 
144
152
  /**
145
153
  * Retrieves the inscriptions for the connected wallet.
@@ -180,25 +188,6 @@ interface IBTCProvider extends IProvider {
180
188
 
181
189
  ```ts
182
190
  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
191
  /**
203
192
  * Gets the name of the wallet provider.
204
193
  * @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,2 +1,3 @@
1
1
  import { ChainConfigArr } from '../../context/Chain.context';
2
+ export declare const ONE_HOUR: number;
2
3
  export declare const config: ChainConfigArr;
@@ -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 {};
@@ -1,6 +1,6 @@
1
1
  import { Wallet } from './Wallet';
2
2
  import { WalletConnector } from './WalletConnector';
3
- import { ChainMetadata, ExternalWalletProps, IProvider, WalletMetadata } from './types';
4
- export declare const createWallet: <P extends IProvider, C>(metadata: WalletMetadata<P, C>, context: any, config: C) => Promise<Wallet<P>>;
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: ChainMetadata<N, P, C>, context: any, config: C) => Promise<WalletConnector<N, P, C>>;
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;
@@ -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.
@@ -141,12 +135,12 @@ export interface IBTCProvider extends IProvider {
141
135
  */
142
136
  getNetwork(): Promise<Network>;
143
137
  /**
144
- * Signs a message using the specified signing method.
138
+ * Signs a message using either BIP322-Simple or ECDSA signing method.
145
139
  * @param message - The message to sign.
146
140
  * @param type - The signing method to use.
147
141
  * @returns A promise that resolves to the signed message.
148
142
  */
149
- signMessage(message: string, type: "ecdsa"): Promise<string>;
143
+ signMessage(message: string, type: "bip322-simple" | "ecdsa"): Promise<string>;
150
144
  /**
151
145
  * Retrieves the inscriptions for the connected wallet.
152
146
  * @returns A promise that resolves to an array of inscriptions.
@@ -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
+ }
@@ -12,7 +12,7 @@ export declare class OKXProvider implements IBTCProvider {
12
12
  signPsbt: (psbtHex: string) => Promise<string>;
13
13
  signPsbts: (psbtsHexes: string[]) => Promise<string[]>;
14
14
  getNetwork: () => Promise<Network>;
15
- signMessage: (message: string, type: "ecdsa") => Promise<string>;
15
+ signMessage: (message: string, type: "bip322-simple" | "ecdsa") => Promise<string>;
16
16
  getInscriptions: () => Promise<InscriptionIdentifier[]>;
17
17
  on: (eventName: string, callBack: () => void) => any;
18
18
  off: (eventName: string, callBack: () => void) => any;
@@ -11,7 +11,7 @@ export declare class OneKeyProvider implements IBTCProvider {
11
11
  signPsbt: (psbtHex: string) => Promise<string>;
12
12
  signPsbts: (psbtsHexes: string[]) => Promise<string[]>;
13
13
  getNetwork: () => Promise<Network>;
14
- signMessage: (message: string, type: "ecdsa") => Promise<string>;
14
+ signMessage: (message: string, type: "bip322-simple" | "ecdsa") => Promise<string>;
15
15
  getInscriptions: () => Promise<InscriptionIdentifier[]>;
16
16
  on: (eventName: string, callBack: () => void) => any;
17
17
  off: (eventName: string, callBack: () => void) => any;
@@ -12,7 +12,7 @@ export declare class UnisatProvider implements IBTCProvider {
12
12
  signPsbts: (psbtsHexes: string[]) => Promise<string[]>;
13
13
  private getSignPsbtDefaultOptions;
14
14
  getNetwork: () => Promise<Network>;
15
- signMessage: (message: string, type: "ecdsa") => Promise<string>;
15
+ signMessage: (message: string, type: "bip322-simple" | "ecdsa") => Promise<string>;
16
16
  getInscriptions: () => Promise<InscriptionIdentifier[]>;
17
17
  on: (eventName: string, callBack: () => void) => any;
18
18
  off: (eventName: string, callBack: () => void) => any;
@@ -1,5 +1,10 @@
1
- import { IChain, IWallet } from '../core/types';
2
- export declare function useWalletConnectors(onError?: (e: Error) => void): {
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 {};