@tomo-inc/inject-providers 0.0.12 → 0.0.14

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.
@@ -0,0 +1,330 @@
1
+ import { EventEmitter } from "events";
2
+
3
+ /**
4
+ * State interface for DogecoinProvider
5
+ */
6
+ export interface IDogecoinProviderState {
7
+ accounts: string[] | null;
8
+ isConnected: boolean;
9
+ isUnlocked: boolean;
10
+ initialized: boolean;
11
+ isPermanentlyDisconnected: boolean;
12
+ }
13
+
14
+ /**
15
+ * Balance response interface
16
+ */
17
+ export interface IDogecoinBalance {
18
+ confirmed: number;
19
+ unconfirmed: number;
20
+ total: number;
21
+ }
22
+
23
+ /**
24
+ * Transaction status response interface
25
+ */
26
+ export interface ITransactionStatus {
27
+ status: string;
28
+ confirmations: number;
29
+ }
30
+
31
+ /**
32
+ * Signed message response interface
33
+ */
34
+ export interface ISignedMessage {
35
+ signedMessage: string;
36
+ }
37
+
38
+ /**
39
+ * Decrypted message response interface
40
+ */
41
+ export interface IDecryptedMessage {
42
+ decryptedMessage: string;
43
+ }
44
+
45
+ /**
46
+ * PSBT request parameters interface
47
+ */
48
+ export interface IRequestPsbtParams {
49
+ rawTx: string;
50
+ indexes?: [];
51
+ feeOnly?: boolean;
52
+ signOnly?: boolean;
53
+ partial?: boolean;
54
+ sighashType?: string;
55
+ }
56
+
57
+ /**
58
+ * PSBT response interface
59
+ */
60
+ export interface IPsbtResponse {
61
+ signedRawTx?: string;
62
+ txId?: string;
63
+ }
64
+
65
+ /**
66
+ * Send options interface
67
+ */
68
+ export interface ISendOptions {
69
+ feeRate?: number;
70
+ memo?: string;
71
+ }
72
+
73
+ /**
74
+ * Connection status response interface
75
+ */
76
+ export interface IConnectionStatus {
77
+ connected: boolean;
78
+ address: string;
79
+ selectedWalletAddress: string;
80
+ }
81
+
82
+ /**
83
+ * DRC20 balance response interface
84
+ */
85
+ export interface IDRC20Balance {
86
+ availableBalance: number;
87
+ transferableBalance: number;
88
+ ticker: string;
89
+ address: string;
90
+ }
91
+
92
+ /**
93
+ * Transferable DRC20 response interface
94
+ */
95
+ export interface ITransferableDRC20 {
96
+ inscriptions: any[];
97
+ ticker: string;
98
+ address: string;
99
+ }
100
+
101
+ /**
102
+ * DRC20 transaction response interface
103
+ */
104
+ export interface IDRC20Transaction {
105
+ txId: string;
106
+ ticker: string;
107
+ amount: number;
108
+ }
109
+
110
+ /**
111
+ * Dunes balance response interface
112
+ */
113
+ export interface IDunesBalance {
114
+ balance: number;
115
+ ticker: string;
116
+ }
117
+
118
+ /**
119
+ * Main interface for DogecoinProvider
120
+ * Extends EventEmitter to support event handling
121
+ */
122
+ export interface IDogecoinProvider extends EventEmitter {
123
+ type: "dogecoin";
124
+
125
+ rdns: string;
126
+ name: string;
127
+
128
+ // Connection methods
129
+ /**
130
+ * Connect to the wallet
131
+ * @returns Promise resolving to connection result with address, approved, balance, publicKey
132
+ */
133
+ connect(): Promise<any>;
134
+
135
+ /**
136
+ * Disconnect from the wallet
137
+ * @returns Promise resolving to disconnect result with disconnected status
138
+ */
139
+ disconnect(): Promise<any>;
140
+
141
+ /**
142
+ * Get connection status
143
+ * @returns Promise resolving to connection status with connected, address, selectedWalletAddress
144
+ */
145
+ getConnectionStatus(): Promise<IConnectionStatus>;
146
+
147
+ // Account methods
148
+ /**
149
+ * Request accounts from the wallet
150
+ * @returns Promise resolving to array of account addresses
151
+ */
152
+ requestAccounts(): Promise<string[]>;
153
+
154
+ /**
155
+ * Get current accounts
156
+ * @returns Promise resolving to array of account addresses
157
+ */
158
+ getAccounts(): Promise<string[]>;
159
+
160
+ /**
161
+ * Get public key
162
+ * @returns Promise resolving to public key string
163
+ */
164
+ getPublicKey(): Promise<string>;
165
+
166
+ // Balance methods
167
+ /**
168
+ * Get balance
169
+ * @returns Promise resolving to balance object with confirmed, unconfirmed, and total
170
+ */
171
+ getBalance(): Promise<IDogecoinBalance>;
172
+
173
+ // Transaction methods
174
+ /**
175
+ * Get transaction status
176
+ * @param params - Transaction status parameters
177
+ * @param params.txId - Transaction ID
178
+ * @returns Promise resolving to transaction status
179
+ */
180
+ getTransactionStatus(params: { txId: string }): Promise<ITransactionStatus>;
181
+
182
+ /**
183
+ * Request a transaction
184
+ * @param params - Transaction parameters
185
+ * @param params.recipientAddress - Recipient address
186
+ * @param params.dogeAmount - Amount in DOGE
187
+ * @returns Promise resolving to transaction result with txId
188
+ */
189
+ requestTransaction(params: { recipientAddress: string; dogeAmount: number }): Promise<{ txId: string }>;
190
+
191
+ /**
192
+ * Send DOGE
193
+ * @param toAddress - Recipient address
194
+ * @param satoshis - Amount in satoshis (optional)
195
+ * @param options - Send options (optional)
196
+ * @returns Promise resolving to transaction ID
197
+ */
198
+ send(toAddress: string, satoshis?: number, options?: ISendOptions): Promise<string>;
199
+
200
+ /**
201
+ * Send DOGE (alias for send)
202
+ * @param toAddress - Recipient address
203
+ * @param satoshis - Amount in satoshis (optional)
204
+ * @param options - Send options (optional)
205
+ * @returns Promise resolving to transaction ID
206
+ */
207
+ sendDogecoin(toAddress: string, satoshis?: number, options?: ISendOptions): Promise<string>;
208
+
209
+ // Message signing methods
210
+ /**
211
+ * Request signed message
212
+ * @param params - Sign message parameters
213
+ * @param params.message - Message to sign
214
+ * @param params.type - Message type (optional)
215
+ * @returns Promise resolving to signed message result
216
+ */
217
+ requestSignedMessage(params: { message: string; type?: string }): Promise<ISignedMessage>;
218
+
219
+ /**
220
+ * Sign message
221
+ * @param message - Message to sign
222
+ * @param type - Message type (optional)
223
+ * @returns Promise resolving to signed message string
224
+ */
225
+ signMessage(message: string, type?: string): Promise<string>;
226
+
227
+ /**
228
+ * Request decrypted message
229
+ * @param params - Decrypt message parameters
230
+ * @param params.message - Message to decrypt
231
+ * @returns Promise resolving to decrypted message result
232
+ */
233
+ requestDecryptedMessage(params: { message: string }): Promise<IDecryptedMessage>;
234
+
235
+ // PSBT methods
236
+ /**
237
+ * Request PSBT
238
+ * @param params - PSBT request parameters
239
+ * @returns Promise resolving to PSBT result with signedRawTx and/or txId
240
+ */
241
+ requestPsbt(params: IRequestPsbtParams): Promise<IPsbtResponse>;
242
+
243
+ /**
244
+ * Sign PSBT
245
+ * @param psbtHex - PSBT hex string
246
+ * @param options - Sign options (optional)
247
+ * @returns Promise resolving to signed PSBT hex string
248
+ */
249
+ signPsbt(psbtHex: string, options?: any): Promise<string>;
250
+
251
+ /**
252
+ * Sign multiple PSBTs
253
+ * @param psbtHexs - Array of PSBT hex strings
254
+ * @param options - Sign options (optional)
255
+ * @returns Promise resolving to signed PSBTs
256
+ */
257
+ signPsbts(psbtHexs: string[], options?: any): Promise<any>;
258
+
259
+ // DRC20 methods
260
+ /**
261
+ * Get DRC20 balances
262
+ * @param address - Address to query
263
+ * @param ticker - Token ticker (optional)
264
+ * @returns Promise resolving to DRC20 balances
265
+ */
266
+ getDRC20Balances(address: string, ticker?: string): Promise<any>;
267
+
268
+ /**
269
+ * Get DRC20 balance
270
+ * @param params - Balance query parameters
271
+ * @param params.ticker - Token ticker (optional)
272
+ * @returns Promise resolving to DRC20 balance
273
+ */
274
+ getDRC20Balance(params: { ticker?: string }): Promise<IDRC20Balance>;
275
+
276
+ /**
277
+ * Get transferable DRC20
278
+ * @param params - Transferable query parameters
279
+ * @param params.ticker - Token ticker (optional)
280
+ * @returns Promise resolving to transferable DRC20
281
+ */
282
+ getTransferableDRC20(params: { ticker?: string }): Promise<ITransferableDRC20>;
283
+
284
+ /**
285
+ * Request available DRC20 transaction
286
+ * @param params - Transaction parameters
287
+ * @param params.ticker - Token ticker
288
+ * @param params.amount - Amount to transfer
289
+ * @returns Promise resolving to DRC20 transaction result
290
+ */
291
+ requestAvailableDRC20Transaction(params: { ticker: string; amount: number }): Promise<IDRC20Transaction>;
292
+
293
+ /**
294
+ * Request inscription transaction
295
+ * @param params - Inscription transaction parameters
296
+ * @param params.location - Inscription location
297
+ * @param params.recipientAddress - Recipient address
298
+ * @returns Promise resolving to transaction result with txId
299
+ */
300
+ requestInscriptionTransaction(params: { location: string; recipientAddress: string }): Promise<{ txId: string }>;
301
+
302
+ // Dunes methods
303
+ /**
304
+ * Get Dunes balance
305
+ * @param params - Balance query parameters
306
+ * @param params.ticker - Token ticker
307
+ * @returns Promise resolving to Dunes balance
308
+ */
309
+ getDunesBalance(params: { ticker: string }): Promise<IDunesBalance>;
310
+
311
+ /**
312
+ * Request Dunes transaction
313
+ * @param params - Transaction parameters
314
+ * @param params.ticker - Token ticker
315
+ * @param params.amount - Amount to transfer
316
+ * @param params.recipientAddress - Recipient address
317
+ * @returns Promise resolving to transaction result
318
+ */
319
+ requestDunesTransaction(params: { ticker: string; amount: number; recipientAddress: string }): Promise<any>;
320
+
321
+ // Generic request method
322
+ /**
323
+ * Generic request method
324
+ * @param params - Request parameters
325
+ * @param params.method - RPC method name
326
+ * @param params.params - Method parameters
327
+ * @returns Promise resolving to request result
328
+ */
329
+ request(params: { method: string; params: any }): Promise<any>;
330
+ }
@@ -0,0 +1,189 @@
1
+ import { EventEmitter } from "events";
2
+ import { JsonRpcRequest, JsonRpcResponse } from "json-rpc-engine";
3
+ import { Maybe } from "./utils";
4
+ import { RequestArguments, SendSyncJsonRpcRequest } from "./type";
5
+
6
+ /**
7
+ * Connect event data interface
8
+ */
9
+ export interface IConnectEvent {
10
+ chainId?: string;
11
+ }
12
+
13
+ /**
14
+ * Disconnect event data interface
15
+ */
16
+ export interface IDisconnectEvent {
17
+ code: number;
18
+ message: string;
19
+ data?: unknown;
20
+ }
21
+
22
+ /**
23
+ * Provider message interface
24
+ */
25
+ export interface IProviderMessage {
26
+ type: string;
27
+ data: unknown;
28
+ }
29
+
30
+ /**
31
+ * Main interface for EvmProvider
32
+ * Extends EventEmitter to support event handling
33
+ * Implements EIP-1193 standard
34
+ */
35
+ export interface IEvmProvider extends EventEmitter {
36
+ type: "evm";
37
+
38
+ // Public properties
39
+ /**
40
+ * The chain ID of the currently connected Ethereum chain.
41
+ * See https://chainid.network for more information.
42
+ */
43
+ chainId: string | null;
44
+
45
+ /**
46
+ * The user's currently selected Ethereum address.
47
+ * If null, wallet is either locked or the user has not permitted any
48
+ * addresses to be viewed.
49
+ */
50
+ selectedAddress: string | null;
51
+
52
+ /**
53
+ * Provider name
54
+ */
55
+ name: string;
56
+
57
+ /**
58
+ * Provider icon
59
+ */
60
+ icon: string;
61
+
62
+ // Connection methods
63
+ /**
64
+ * Returns whether the provider can process RPC requests.
65
+ * @returns true if connected, false otherwise
66
+ */
67
+ isConnected(): boolean;
68
+
69
+ /**
70
+ * Submits an RPC request for the given method, with the given params.
71
+ * Resolves with the result of the method call, or rejects on error.
72
+ *
73
+ * @param args - The RPC request arguments.
74
+ * @param args.method - The RPC method name.
75
+ * @param args.params - The parameters for the RPC method.
76
+ * @returns A Promise that resolves with the result of the RPC method,
77
+ * or rejects if an error is encountered.
78
+ */
79
+ request<T = unknown>(args: RequestArguments): Promise<Maybe<T>>;
80
+
81
+ /**
82
+ * Connect to the wallet
83
+ * Equivalent to: ethereum.request('eth_requestAccounts')
84
+ * @returns Promise resolving to array of account addresses
85
+ */
86
+ connect(): Promise<string[]>;
87
+
88
+ /**
89
+ * Disconnect from the wallet
90
+ * @returns Promise resolving to boolean indicating disconnect status
91
+ */
92
+ disconnect(): Promise<boolean>;
93
+
94
+ /**
95
+ * Equivalent to: ethereum.request('eth_requestAccounts')
96
+ * @deprecated Use request({ method: 'eth_requestAccounts' }) instead.
97
+ * @returns Promise resolving to array of addresses
98
+ */
99
+ enable(): Promise<string[]>;
100
+
101
+ // Legacy send methods (deprecated)
102
+ /**
103
+ * Submits an RPC request for the given method, with the given params.
104
+ * @deprecated Use request() instead.
105
+ * @param method - The method to request.
106
+ * @param params - Any params for the method.
107
+ * @returns A Promise that resolves with the JSON-RPC response object for the request.
108
+ */
109
+ send<T>(method: string, params?: T[]): Promise<JsonRpcResponse<T>>;
110
+
111
+ /**
112
+ * Submits an RPC request per the given JSON-RPC request object.
113
+ * @deprecated Use request() instead.
114
+ * @param payload - A JSON-RPC request object.
115
+ * @param callback - An error-first callback that will receive the JSON-RPC response object.
116
+ */
117
+ send<T>(payload: JsonRpcRequest<unknown>, callback: (error: Error | null, result?: JsonRpcResponse<T>) => void): void;
118
+
119
+ /**
120
+ * Accepts a JSON-RPC request object, and synchronously returns the cached result
121
+ * for the given method. Only supports 4 specific RPC methods.
122
+ * @deprecated Use request() instead.
123
+ * @param payload - A JSON-RPC request object.
124
+ * @returns A JSON-RPC response object.
125
+ */
126
+ send<T>(payload: SendSyncJsonRpcRequest): JsonRpcResponse<T>;
127
+
128
+ /**
129
+ * Adds a listener for the specified event.
130
+ * @param eventName - Event name
131
+ * @param listener - Event listener function
132
+ * @returns This instance for chaining
133
+ */
134
+ on(eventName: string, listener: (...args: unknown[]) => void): this;
135
+
136
+ /**
137
+ * Adds a one-time listener for the specified event.
138
+ * @param eventName - Event name
139
+ * @param listener - Event listener function
140
+ * @returns This instance for chaining
141
+ */
142
+ once(eventName: string, listener: (...args: unknown[]) => void): this;
143
+
144
+ // Event types
145
+ /**
146
+ * Emitted when the provider connects to a chain.
147
+ * @event
148
+ */
149
+ on(event: "connect", listener: (connectInfo: IConnectEvent) => void): this;
150
+
151
+ /**
152
+ * Emitted when the provider disconnects from a chain.
153
+ * @event
154
+ */
155
+ on(event: "disconnect", listener: (error: IDisconnectEvent) => void): this;
156
+
157
+ /**
158
+ * Emitted when the chain ID changes.
159
+ * @event
160
+ */
161
+ on(event: "chainChanged", listener: (chainId: string) => void): this;
162
+
163
+ /**
164
+ * Emitted when accounts change.
165
+ * @event
166
+ */
167
+ on(event: "accountsChanged", listener: (accounts: string[]) => void): this;
168
+
169
+ /**
170
+ * Emitted when the connection closes (deprecated).
171
+ * @event
172
+ * @deprecated
173
+ */
174
+ on(event: "close", listener: (error: IDisconnectEvent) => void): this;
175
+
176
+ /**
177
+ * Emitted when data is received (deprecated).
178
+ * @event
179
+ * @deprecated
180
+ */
181
+ on(event: "data", listener: (payload: unknown) => void): this;
182
+
183
+ /**
184
+ * Emitted when the network changes (deprecated).
185
+ * @event
186
+ * @deprecated
187
+ */
188
+ on(event: "networkChanged", listener: (networkId: string) => void): this;
189
+ }
package/src/index.ts CHANGED
@@ -5,3 +5,7 @@ import { SolanaProvider } from "./solana";
5
5
  import { TronProvider } from "./tron";
6
6
 
7
7
  export { BtcProvider, DogecoinProvider, EvmProvider, SolanaProvider, TronProvider };
8
+
9
+ import { IDogecoinProvider } from "./dogecoin/interface";
10
+ import { IEvmProvider } from "./evm/interface";
11
+ export type WalletProvider = IDogecoinProvider | IEvmProvider;