@meshconnect/uwc-types 0.2.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/dist/UWC-state.d.ts +62 -0
- package/dist/UWC-state.d.ts.map +1 -0
- package/dist/UWC-state.js +2 -0
- package/dist/UWC-state.js.map +1 -0
- package/dist/connection-mode.d.ts +2 -0
- package/dist/connection-mode.d.ts.map +1 -0
- package/dist/connection-mode.js +2 -0
- package/dist/connection-mode.js.map +1 -0
- package/dist/connector.d.ts +76 -0
- package/dist/connector.d.ts.map +1 -0
- package/dist/connector.js +2 -0
- package/dist/connector.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/network-rpc.d.ts +6 -0
- package/dist/network-rpc.d.ts.map +1 -0
- package/dist/network-rpc.js +2 -0
- package/dist/network-rpc.js.map +1 -0
- package/dist/networks.d.ts +33 -0
- package/dist/networks.d.ts.map +1 -0
- package/dist/networks.js +2 -0
- package/dist/networks.js.map +1 -0
- package/dist/providers.d.ts +7 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +2 -0
- package/dist/providers.js.map +1 -0
- package/dist/react-hooks.d.ts +231 -0
- package/dist/react-hooks.d.ts.map +1 -0
- package/dist/react-hooks.js +2 -0
- package/dist/react-hooks.js.map +1 -0
- package/dist/session.d.ts +16 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +2 -0
- package/dist/session.js.map +1 -0
- package/dist/signature.d.ts +28 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +2 -0
- package/dist/signature.js.map +1 -0
- package/dist/transactions.d.ts +109 -0
- package/dist/transactions.d.ts.map +1 -0
- package/dist/transactions.js +5 -0
- package/dist/transactions.js.map +1 -0
- package/dist/wallet-connect-connector.d.ts +13 -0
- package/dist/wallet-connect-connector.d.ts.map +1 -0
- package/dist/wallet-connect-connector.js +2 -0
- package/dist/wallet-connect-connector.js.map +1 -0
- package/package.json +32 -0
- package/src/UWC-state.ts +77 -0
- package/src/connection-mode.ts +1 -0
- package/src/connector.ts +118 -0
- package/src/errors.ts +20 -0
- package/src/index.ts +12 -0
- package/src/network-rpc.ts +6 -0
- package/src/networks.ts +62 -0
- package/src/providers.ts +14 -0
- package/src/react-hooks.ts +256 -0
- package/src/session.ts +17 -0
- package/src/signature.ts +36 -0
- package/src/transactions.ts +127 -0
- package/src/wallet-connect-connector.ts +12 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NetworkId,
|
|
3
|
+
Network,
|
|
4
|
+
ConnectionMode,
|
|
5
|
+
Session,
|
|
6
|
+
AvailableAddress,
|
|
7
|
+
TransactionRequest,
|
|
8
|
+
TransactionResult,
|
|
9
|
+
WalletError
|
|
10
|
+
} from './index'
|
|
11
|
+
|
|
12
|
+
// useConnection hook types
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* WalletConnect connection interface for the useConnection hook
|
|
16
|
+
*/
|
|
17
|
+
export interface WalletConnectConnection {
|
|
18
|
+
/**
|
|
19
|
+
* Connects to the specified wallet using WalletConnect protocol
|
|
20
|
+
* @param networkId - Optional network ID to connect to. If not provided, uses the default network
|
|
21
|
+
* @returns Promise that resolves when connection is established
|
|
22
|
+
*/
|
|
23
|
+
connect: (networkId?: NetworkId) => Promise<void>
|
|
24
|
+
/**
|
|
25
|
+
* The WalletConnect connection URI for QR code display
|
|
26
|
+
* Will be undefined if not using WalletConnect or if connection is already established
|
|
27
|
+
*/
|
|
28
|
+
connectionURI: string | undefined
|
|
29
|
+
/**
|
|
30
|
+
* Indicates if the WalletConnect connection is currently being established
|
|
31
|
+
*/
|
|
32
|
+
isLoading: boolean
|
|
33
|
+
/**
|
|
34
|
+
* Error from the last connection attempt, undefined if no error occurred
|
|
35
|
+
*/
|
|
36
|
+
error: WalletError | undefined
|
|
37
|
+
/**
|
|
38
|
+
* Indicates if WalletConnect is currently available for use
|
|
39
|
+
* This depends on whether the wallet supports WalletConnect
|
|
40
|
+
*/
|
|
41
|
+
available: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Injected wallet connection interface for the useConnection hook
|
|
46
|
+
*/
|
|
47
|
+
export interface InjectedConnection {
|
|
48
|
+
/**
|
|
49
|
+
* Connects to the specified wallet using browser injection (MetaMask, Trust Wallet, etc.)
|
|
50
|
+
* @param networkId - Optional network ID to connect to. If not provided, uses the default network
|
|
51
|
+
* @returns Promise that resolves when connection is established
|
|
52
|
+
*/
|
|
53
|
+
connect: (networkId?: NetworkId) => Promise<void>
|
|
54
|
+
/**
|
|
55
|
+
* Indicates if the injected wallet connection is currently being established
|
|
56
|
+
*/
|
|
57
|
+
isLoading: boolean
|
|
58
|
+
/**
|
|
59
|
+
* Error from the last connection attempt, undefined if no error occurred
|
|
60
|
+
*/
|
|
61
|
+
error: WalletError | undefined
|
|
62
|
+
/**
|
|
63
|
+
* Indicates if injected connection is currently available for use
|
|
64
|
+
*/
|
|
65
|
+
available: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Return type for the useConnection hook
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* const { walletConnect, injected } = useConnection('metamask')
|
|
73
|
+
*
|
|
74
|
+
* // Connect with WalletConnect
|
|
75
|
+
* await walletConnect.connect('eip155:1')
|
|
76
|
+
* console.log(walletConnect.connectionURI) // Display QR code
|
|
77
|
+
*
|
|
78
|
+
* // Connect with injected wallet
|
|
79
|
+
* await injected.connect('eip155:1')
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export interface UseConnectionReturn {
|
|
83
|
+
/**
|
|
84
|
+
* WalletConnect connection methods and state
|
|
85
|
+
*/
|
|
86
|
+
walletConnect: WalletConnectConnection
|
|
87
|
+
/**
|
|
88
|
+
* Injected wallet connection methods and state
|
|
89
|
+
*/
|
|
90
|
+
injected: InjectedConnection
|
|
91
|
+
/**
|
|
92
|
+
* Indicates if wallet detection has completed and the connector is ready to use
|
|
93
|
+
*/
|
|
94
|
+
isReady: boolean
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// useSession hook types
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Return type for the useSession hook
|
|
101
|
+
* Provides access to the current wallet session state
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* const { activeAddress, activeNetwork, session } = useSession()
|
|
105
|
+
*
|
|
106
|
+
* if (activeAddress) {
|
|
107
|
+
* console.log(`Connected to ${activeNetwork?.name} with ${activeAddress}`)
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export interface UseSessionReturn {
|
|
112
|
+
/**
|
|
113
|
+
* The complete session object containing all wallet connection state
|
|
114
|
+
*/
|
|
115
|
+
session: Session
|
|
116
|
+
/**
|
|
117
|
+
* The currently connected wallet address, or null if not connected
|
|
118
|
+
*/
|
|
119
|
+
activeAddress: string | null
|
|
120
|
+
/**
|
|
121
|
+
* The currently selected network, or null if not connected
|
|
122
|
+
*/
|
|
123
|
+
activeNetwork: Network | null
|
|
124
|
+
/**
|
|
125
|
+
* List of networks available for the connected wallet
|
|
126
|
+
*/
|
|
127
|
+
availableNetworks: Network[]
|
|
128
|
+
/**
|
|
129
|
+
* The active connection mode ('injected' or 'walletConnect'), or null if not connected
|
|
130
|
+
*/
|
|
131
|
+
activeConnector: ConnectionMode | null
|
|
132
|
+
/**
|
|
133
|
+
* List of available addresses for the connected wallet
|
|
134
|
+
*/
|
|
135
|
+
availableAddresses: AvailableAddress[]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// useSwitchNetwork hook types
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Return type for the useSwitchNetwork hook
|
|
142
|
+
* Provides network switching functionality with loading states
|
|
143
|
+
* @example
|
|
144
|
+
* ```tsx
|
|
145
|
+
* const { switchNetwork, isLoading, isWaitingForUserApproval } = useSwitchNetwork()
|
|
146
|
+
*
|
|
147
|
+
* const handleNetworkSwitch = async () => {
|
|
148
|
+
* await switchNetwork('eip155:8453') // Switch to Base
|
|
149
|
+
*
|
|
150
|
+
* if (isWaitingForUserApproval) {
|
|
151
|
+
* console.log('Waiting for user to approve in wallet...')
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export interface UseSwitchNetworkReturn {
|
|
157
|
+
/**
|
|
158
|
+
* Switches the connected wallet to the specified network
|
|
159
|
+
* @param networkId - The ID of the network to switch to (e.g., 'eip155:1' for Ethereum mainnet)
|
|
160
|
+
* @returns Promise that resolves when the network switch is complete
|
|
161
|
+
* @throws Error if network switch fails or is rejected by the user
|
|
162
|
+
*/
|
|
163
|
+
switchNetwork: (networkId: NetworkId) => Promise<void>
|
|
164
|
+
/**
|
|
165
|
+
* Indicates if a network switch operation is currently in progress
|
|
166
|
+
*/
|
|
167
|
+
isLoading: boolean
|
|
168
|
+
/**
|
|
169
|
+
* Indicates if the wallet is waiting for user approval to switch networks
|
|
170
|
+
* This depends on the wallet's metadata configuration (requiresUserApprovalOnNetworkSwitch)
|
|
171
|
+
*/
|
|
172
|
+
isWaitingForUserApproval: boolean
|
|
173
|
+
/**
|
|
174
|
+
* Error from the last network switch attempt, undefined if no error occurred
|
|
175
|
+
*/
|
|
176
|
+
error: WalletError | undefined
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// useSignMessage hook types
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Return type for the useSignMessage hook
|
|
183
|
+
* Provides message signing functionality with loading state and signature result
|
|
184
|
+
* @example
|
|
185
|
+
* ```tsx
|
|
186
|
+
* const { signMessage, isLoading, signature } = useSignMessage()
|
|
187
|
+
*
|
|
188
|
+
* const handleSign = async () => {
|
|
189
|
+
* const sig = await signMessage('Hello World')
|
|
190
|
+
* console.log('Signature:', sig)
|
|
191
|
+
* // The signature state will also contain the result
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export interface UseSignMessageReturn {
|
|
196
|
+
/**
|
|
197
|
+
* Signs a message with the connected wallet
|
|
198
|
+
* @param message - The message to sign
|
|
199
|
+
* @returns Promise that resolves to the signature string
|
|
200
|
+
* @throws Error if no wallet is connected or signing fails
|
|
201
|
+
*/
|
|
202
|
+
signMessage: (message: string) => Promise<string>
|
|
203
|
+
/**
|
|
204
|
+
* Indicates if a message signing operation is currently in progress
|
|
205
|
+
*/
|
|
206
|
+
isLoading: boolean
|
|
207
|
+
/**
|
|
208
|
+
* The last signature result, undefined if no message has been signed yet
|
|
209
|
+
*/
|
|
210
|
+
signature: string | undefined
|
|
211
|
+
/**
|
|
212
|
+
* Error from the last signing attempt, undefined if no error occurred
|
|
213
|
+
*/
|
|
214
|
+
error: WalletError | undefined
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// useTransaction hook types
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Return type for the useTransaction hook
|
|
221
|
+
* Provides transaction sending functionality with loading state and result
|
|
222
|
+
* @example
|
|
223
|
+
* ```tsx
|
|
224
|
+
* const { sendTransaction, isLoading, transactionResult } = useTransaction()
|
|
225
|
+
*
|
|
226
|
+
* const handleSend = async () => {
|
|
227
|
+
* const result = await sendTransaction({
|
|
228
|
+
* to: '0x...',
|
|
229
|
+
* amount: BigInt('1000000000000000000'),
|
|
230
|
+
* from: session.activeAddress
|
|
231
|
+
* })
|
|
232
|
+
* console.log('Transaction hash:', result.hash)
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export interface UseTransactionReturn {
|
|
237
|
+
/**
|
|
238
|
+
* Sends a transaction with the connected wallet
|
|
239
|
+
* @param request - The transaction request object
|
|
240
|
+
* @returns Promise that resolves to the transaction result
|
|
241
|
+
* @throws Error if no wallet is connected or transaction fails
|
|
242
|
+
*/
|
|
243
|
+
sendTransaction: (request: TransactionRequest) => Promise<TransactionResult>
|
|
244
|
+
/**
|
|
245
|
+
* Indicates if a transaction is currently being processed
|
|
246
|
+
*/
|
|
247
|
+
isLoading: boolean
|
|
248
|
+
/**
|
|
249
|
+
* The last transaction result, undefined if no transaction has been sent yet
|
|
250
|
+
*/
|
|
251
|
+
transactionResult: TransactionResult | undefined
|
|
252
|
+
/**
|
|
253
|
+
* Error from the last transaction attempt, undefined if no error occurred
|
|
254
|
+
*/
|
|
255
|
+
error: WalletError | undefined
|
|
256
|
+
}
|
package/src/session.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ConnectionMode } from './connection-mode'
|
|
2
|
+
import type { Network, NetworkId } from './networks'
|
|
3
|
+
import type { WalletMetadata } from './UWC-state'
|
|
4
|
+
|
|
5
|
+
export interface AvailableAddress {
|
|
6
|
+
address: string
|
|
7
|
+
networkId: NetworkId
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Session {
|
|
11
|
+
connectionMode: ConnectionMode | null
|
|
12
|
+
activeNetwork: Network | null
|
|
13
|
+
activeAddress: string | null
|
|
14
|
+
availableNetworks: Network[]
|
|
15
|
+
activeWallet: WalletMetadata | null
|
|
16
|
+
availableAddresses: AvailableAddress[]
|
|
17
|
+
}
|
package/src/signature.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionInjectedProvider,
|
|
3
|
+
IntegratedBrowserInjectedProvider
|
|
4
|
+
} from './UWC-state'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Result interface for signature operations
|
|
8
|
+
*/
|
|
9
|
+
export interface SignatureResult {
|
|
10
|
+
signature: string
|
|
11
|
+
address: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Error types for signature operations
|
|
16
|
+
*/
|
|
17
|
+
export interface SignatureError {
|
|
18
|
+
code: number
|
|
19
|
+
message: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Signature service interface
|
|
24
|
+
*/
|
|
25
|
+
export interface SignatureService {
|
|
26
|
+
/**
|
|
27
|
+
* Sign a message with the connected wallet
|
|
28
|
+
* @param message The message to sign
|
|
29
|
+
* @param provider The wallet provider to use for signing
|
|
30
|
+
* @returns A promise that resolves to the signature result
|
|
31
|
+
*/
|
|
32
|
+
signMessage(
|
|
33
|
+
message: string,
|
|
34
|
+
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider
|
|
35
|
+
): Promise<SignatureResult>
|
|
36
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM Transaction Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Gas configuration for EVM transactions
|
|
7
|
+
*/
|
|
8
|
+
export interface EVMGasConfig {
|
|
9
|
+
gasLimit?: number | null
|
|
10
|
+
maxFeePerGas?: number | null
|
|
11
|
+
maxPriorityFeePerGas?: number | null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Request for native EVM token transfer (ETH, BNB, MATIC, etc.)
|
|
16
|
+
*/
|
|
17
|
+
export interface EVMNativeTransferRequest {
|
|
18
|
+
to: string
|
|
19
|
+
amount: bigint
|
|
20
|
+
from: string
|
|
21
|
+
gasConfig?: EVMGasConfig
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Request for EVM smart contract interaction
|
|
26
|
+
*/
|
|
27
|
+
export interface EVMContractCallRequest {
|
|
28
|
+
contractAddress: string
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
abi: any[] // ethers.InterfaceAbi
|
|
31
|
+
functionName: string
|
|
32
|
+
args: unknown[]
|
|
33
|
+
from: string
|
|
34
|
+
value?: string // For payable functions (in wei)
|
|
35
|
+
gasConfig?: EVMGasConfig
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Single call in a batch transaction
|
|
40
|
+
*/
|
|
41
|
+
export interface EVMBatchCall {
|
|
42
|
+
to: string
|
|
43
|
+
value: string
|
|
44
|
+
data?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Request for batch EVM transactions (EIP-5792)
|
|
49
|
+
*/
|
|
50
|
+
export interface EVMBatchTransactionRequest {
|
|
51
|
+
version: string
|
|
52
|
+
from: string
|
|
53
|
+
chainId: string
|
|
54
|
+
atomicRequired: boolean
|
|
55
|
+
calls: EVMBatchCall[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* EVM wallet capabilities
|
|
60
|
+
*/
|
|
61
|
+
export interface EVMCapabilities {
|
|
62
|
+
atomicBatch?: {
|
|
63
|
+
supported: boolean
|
|
64
|
+
}
|
|
65
|
+
paymasterService?: {
|
|
66
|
+
supported: boolean
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Solana Transaction Types
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Request for native SOL transfer
|
|
76
|
+
*/
|
|
77
|
+
export interface SolanaNativeTransferRequest {
|
|
78
|
+
from: string
|
|
79
|
+
to: string
|
|
80
|
+
amount: bigint
|
|
81
|
+
blockhash: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Configuration for Solana transactions (internal use)
|
|
86
|
+
*/
|
|
87
|
+
export interface SolanaTransactionConfig {
|
|
88
|
+
fromAddress: string
|
|
89
|
+
toAddress: string
|
|
90
|
+
amount: string | number
|
|
91
|
+
blockhash: string
|
|
92
|
+
// Token-specific
|
|
93
|
+
tokenMint?: string
|
|
94
|
+
tokenDecimals?: number
|
|
95
|
+
tokenProgram?: string
|
|
96
|
+
createATA?: boolean
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Common Transaction Types
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Result of a transaction
|
|
105
|
+
*/
|
|
106
|
+
export type TransactionResult = string // Transaction hash
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Result of a batch transaction
|
|
110
|
+
*/
|
|
111
|
+
export interface BatchTransactionResult {
|
|
112
|
+
id: string
|
|
113
|
+
status: number
|
|
114
|
+
atomic: boolean
|
|
115
|
+
receipts: Array<{
|
|
116
|
+
transactionHash: string
|
|
117
|
+
}>
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Generic transaction request that can be either EVM or Solana
|
|
122
|
+
*/
|
|
123
|
+
export type TransactionRequest =
|
|
124
|
+
| EVMNativeTransferRequest
|
|
125
|
+
| EVMContractCallRequest
|
|
126
|
+
| EVMBatchTransactionRequest
|
|
127
|
+
| SolanaNativeTransferRequest
|