@meshconnect/uwc-wallet-connect-connector 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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/services/connection-service.d.ts +60 -0
- package/dist/services/connection-service.d.ts.map +1 -0
- package/dist/services/connection-service.js +235 -0
- package/dist/services/connection-service.js.map +1 -0
- package/dist/services/network-switch-service.d.ts +16 -0
- package/dist/services/network-switch-service.d.ts.map +1 -0
- package/dist/services/network-switch-service.js +71 -0
- package/dist/services/network-switch-service.js.map +1 -0
- package/dist/services/signature-service.d.ts +15 -0
- package/dist/services/signature-service.d.ts.map +1 -0
- package/dist/services/signature-service.js +102 -0
- package/dist/services/signature-service.js.map +1 -0
- package/dist/services/transaction-service.d.ts +33 -0
- package/dist/services/transaction-service.d.ts.map +1 -0
- package/dist/services/transaction-service.js +287 -0
- package/dist/services/transaction-service.js.map +1 -0
- package/dist/services/walletconnect-client.d.ts +28 -0
- package/dist/services/walletconnect-client.d.ts.map +1 -0
- package/dist/services/walletconnect-client.js +92 -0
- package/dist/services/walletconnect-client.js.map +1 -0
- package/dist/utils/account-utils.d.ts +41 -0
- package/dist/utils/account-utils.d.ts.map +1 -0
- package/dist/utils/account-utils.js +81 -0
- package/dist/utils/account-utils.js.map +1 -0
- package/dist/utils/encoding-utils.d.ts +6 -0
- package/dist/utils/encoding-utils.d.ts.map +1 -0
- package/dist/utils/encoding-utils.js +27 -0
- package/dist/utils/encoding-utils.js.map +1 -0
- package/dist/utils/error-utils.d.ts +6 -0
- package/dist/utils/error-utils.d.ts.map +1 -0
- package/dist/utils/error-utils.js +55 -0
- package/dist/utils/error-utils.js.map +1 -0
- package/dist/utils/solana-transactions.d.ts +4 -0
- package/dist/utils/solana-transactions.d.ts.map +1 -0
- package/dist/utils/solana-transactions.js +15 -0
- package/dist/utils/solana-transactions.js.map +1 -0
- package/dist/wallet-connect-connector.d.ts +17 -0
- package/dist/wallet-connect-connector.d.ts.map +1 -0
- package/dist/wallet-connect-connector.js +47 -0
- package/dist/wallet-connect-connector.js.map +1 -0
- package/package.json +41 -0
- package/src/index.ts +1 -0
- package/src/services/connection-service.ts +304 -0
- package/src/services/network-switch-service.ts +83 -0
- package/src/services/signature-service.ts +128 -0
- package/src/services/transaction-service.ts +397 -0
- package/src/services/walletconnect-client.ts +103 -0
- package/src/utils/account-utils.ts +116 -0
- package/src/utils/encoding-utils.ts +32 -0
- package/src/utils/error-utils.ts +62 -0
- package/src/utils/solana-transactions.ts +24 -0
- package/src/wallet-connect-connector.ts +83 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
import { Connection, PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
import { WalletConnectClient } from './walletconnect-client';
|
|
5
|
+
import { ConnectionService } from './connection-service';
|
|
6
|
+
import { getChainIdFromNetworkId } from '../utils/account-utils';
|
|
7
|
+
import { parseError } from '../utils/error-utils';
|
|
8
|
+
import { getSolanaTransaction } from '../utils/solana-transactions';
|
|
9
|
+
import base58 from 'bs58';
|
|
10
|
+
import { standardizeSignature } from '../utils/encoding-utils';
|
|
11
|
+
/**
|
|
12
|
+
* Service for handling transactions in WalletConnect
|
|
13
|
+
*/
|
|
14
|
+
export class TransactionService {
|
|
15
|
+
walletConnectClient;
|
|
16
|
+
connectionService;
|
|
17
|
+
networkRpcMap;
|
|
18
|
+
constructor(walletConnectClient, connectionService, networkRpcMap = {}) {
|
|
19
|
+
this.walletConnectClient = walletConnectClient;
|
|
20
|
+
this.connectionService = connectionService;
|
|
21
|
+
this.networkRpcMap = networkRpcMap;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Send a transaction with the connected wallet
|
|
25
|
+
*/
|
|
26
|
+
async sendTransaction(request) {
|
|
27
|
+
const session = this.connectionService.getSession();
|
|
28
|
+
if (!session) {
|
|
29
|
+
throw new Error('No active session. Please connect first.');
|
|
30
|
+
}
|
|
31
|
+
const activeNetwork = this.connectionService.getActiveNetwork();
|
|
32
|
+
const activeAddress = this.connectionService.getActiveAddress();
|
|
33
|
+
if (!activeNetwork) {
|
|
34
|
+
throw new Error('No active network. Please connect first.');
|
|
35
|
+
}
|
|
36
|
+
if (!activeAddress) {
|
|
37
|
+
throw new Error('No active address. Please connect first.');
|
|
38
|
+
}
|
|
39
|
+
const client = await this.walletConnectClient.getClient();
|
|
40
|
+
// Determine namespace from network ID
|
|
41
|
+
const namespace = activeNetwork.id.split(':')[0];
|
|
42
|
+
if (namespace === 'eip155') {
|
|
43
|
+
return this.sendEthereumTransaction(client, session, request, activeNetwork.id, activeAddress);
|
|
44
|
+
}
|
|
45
|
+
else if (namespace === 'solana') {
|
|
46
|
+
return this.sendSolanaTransaction(client, session, request, activeNetwork.id, activeAddress);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
throw new Error(`Unsupported namespace: ${namespace}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Send an Ethereum transaction
|
|
54
|
+
*/
|
|
55
|
+
async sendEthereumTransaction(client, session, request, activeNetworkId, activeAddress) {
|
|
56
|
+
try {
|
|
57
|
+
// Handle different types of EVM transactions
|
|
58
|
+
if ('contractAddress' in request && 'abi' in request) {
|
|
59
|
+
// Contract call
|
|
60
|
+
return await this.sendContractCall(client, session, request, activeNetworkId, activeAddress);
|
|
61
|
+
}
|
|
62
|
+
else if ('calls' in request) {
|
|
63
|
+
// Batch transaction - not yet supported
|
|
64
|
+
throw new Error('Batch transactions are not yet supported for WalletConnect');
|
|
65
|
+
}
|
|
66
|
+
else if ('amount' in request && typeof request.amount === 'bigint') {
|
|
67
|
+
// Native transfer
|
|
68
|
+
return await this.sendNativeTransfer(client, session, request, activeNetworkId, activeAddress);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
throw new Error('Invalid transaction request type');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw parseError(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Send a Solana transaction
|
|
80
|
+
*/
|
|
81
|
+
async sendSolanaTransaction(client, session, request, activeNetworkId, activeAddress) {
|
|
82
|
+
try {
|
|
83
|
+
// Verify the from address matches active address
|
|
84
|
+
if (request.from !== activeAddress) {
|
|
85
|
+
throw new Error('From address does not match connected wallet');
|
|
86
|
+
}
|
|
87
|
+
// Blockhash is required
|
|
88
|
+
if (!request.blockhash) {
|
|
89
|
+
throw new Error('Blockhash is required for Solana transactions');
|
|
90
|
+
}
|
|
91
|
+
// Create the transaction using the utility function
|
|
92
|
+
let transaction = getSolanaTransaction(request);
|
|
93
|
+
// Serialize the transaction for WalletConnect
|
|
94
|
+
const serializedTransaction = transaction
|
|
95
|
+
.serialize({
|
|
96
|
+
verifySignatures: false
|
|
97
|
+
})
|
|
98
|
+
.toString('base64');
|
|
99
|
+
// Get the chain ID (e.g., "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" for mainnet)
|
|
100
|
+
const chainId = activeNetworkId;
|
|
101
|
+
try {
|
|
102
|
+
// First try signAndSendTransaction (preferred method)
|
|
103
|
+
const result = await client.request({
|
|
104
|
+
topic: session.topic,
|
|
105
|
+
chainId,
|
|
106
|
+
request: {
|
|
107
|
+
method: 'solana_signAndSendTransaction',
|
|
108
|
+
params: {
|
|
109
|
+
transaction: serializedTransaction
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
// WalletConnect returns the signature directly for Solana
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
catch (signAndSendError) {
|
|
117
|
+
const errorMessage = signAndSendError instanceof Error
|
|
118
|
+
? signAndSendError.message
|
|
119
|
+
: String(signAndSendError);
|
|
120
|
+
// If signAndSendTransaction is not supported, fallback to signTransaction
|
|
121
|
+
if (errorMessage.includes('solana_signAndSendTransaction') ||
|
|
122
|
+
errorMessage.includes('Missing or invalid')) {
|
|
123
|
+
// Sign the transaction only
|
|
124
|
+
const result = await client.request({
|
|
125
|
+
topic: session.topic,
|
|
126
|
+
chainId,
|
|
127
|
+
request: {
|
|
128
|
+
method: 'solana_signTransaction',
|
|
129
|
+
params: {
|
|
130
|
+
transaction: serializedTransaction
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
if ('signature' in result) {
|
|
135
|
+
const decoded = base58.decode(result.signature);
|
|
136
|
+
transaction.addSignature(new PublicKey(request.from), Buffer.from(decoded));
|
|
137
|
+
}
|
|
138
|
+
if ('transaction' in result) {
|
|
139
|
+
const decodedTransaction = Buffer.from(result.transaction, 'base64');
|
|
140
|
+
if (transaction instanceof VersionedTransaction) {
|
|
141
|
+
transaction = VersionedTransaction.deserialize(new Uint8Array(decodedTransaction));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
transaction = Transaction.from(decodedTransaction);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Get RPC URL from the network RPC map or fall back to public endpoint
|
|
148
|
+
const rpcUrl = this.networkRpcMap[activeNetworkId] ||
|
|
149
|
+
'https://api.mainnet-beta.solana.com';
|
|
150
|
+
const connection = new Connection(rpcUrl);
|
|
151
|
+
const rawSignature = await connection.sendRawTransaction(transaction.serialize(), {
|
|
152
|
+
skipPreflight: false,
|
|
153
|
+
maxRetries: 3,
|
|
154
|
+
preflightCommitment: 'confirmed'
|
|
155
|
+
});
|
|
156
|
+
return standardizeSignature(rawSignature);
|
|
157
|
+
}
|
|
158
|
+
// If it's a different error, throw it
|
|
159
|
+
throw signAndSendError;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
throw parseError(error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Send native token transfer (ETH, BNB, MATIC, etc.)
|
|
168
|
+
*/
|
|
169
|
+
async sendNativeTransfer(client, session, request, activeNetworkId, activeAddress) {
|
|
170
|
+
try {
|
|
171
|
+
// Use the active network chainId
|
|
172
|
+
const chainId = getChainIdFromNetworkId(activeNetworkId);
|
|
173
|
+
// Build transaction using ethers
|
|
174
|
+
const tx = {
|
|
175
|
+
from: request.from || activeAddress,
|
|
176
|
+
to: request.to,
|
|
177
|
+
value: request.amount
|
|
178
|
+
};
|
|
179
|
+
// Add gas configuration if provided
|
|
180
|
+
if (request.gasConfig?.gasLimit) {
|
|
181
|
+
tx.gasLimit = BigInt(Math.floor(request.gasConfig.gasLimit));
|
|
182
|
+
}
|
|
183
|
+
if (request.gasConfig?.maxFeePerGas) {
|
|
184
|
+
tx.maxFeePerGas = BigInt(Math.floor(request.gasConfig.maxFeePerGas));
|
|
185
|
+
}
|
|
186
|
+
if (request.gasConfig?.maxPriorityFeePerGas) {
|
|
187
|
+
tx.maxPriorityFeePerGas = BigInt(Math.floor(request.gasConfig.maxPriorityFeePerGas));
|
|
188
|
+
}
|
|
189
|
+
// Convert to hex format for WalletConnect
|
|
190
|
+
const txParams = {
|
|
191
|
+
from: tx.from,
|
|
192
|
+
to: tx.to,
|
|
193
|
+
value: '0x' + (tx.value ? BigInt(tx.value).toString(16) : '0'),
|
|
194
|
+
data: '0x' // Empty data for native transfers
|
|
195
|
+
};
|
|
196
|
+
// Add gas params if present
|
|
197
|
+
if (tx.gasLimit) {
|
|
198
|
+
txParams['gasLimit'] = '0x' + tx.gasLimit.toString(16);
|
|
199
|
+
}
|
|
200
|
+
if (tx.maxFeePerGas) {
|
|
201
|
+
txParams['maxFeePerGas'] = '0x' + tx.maxFeePerGas.toString(16);
|
|
202
|
+
}
|
|
203
|
+
if (tx.maxPriorityFeePerGas) {
|
|
204
|
+
txParams['maxPriorityFeePerGas'] =
|
|
205
|
+
'0x' + tx.maxPriorityFeePerGas.toString(16);
|
|
206
|
+
}
|
|
207
|
+
const hash = await client.request({
|
|
208
|
+
topic: session.topic,
|
|
209
|
+
chainId: `eip155:${chainId}`,
|
|
210
|
+
request: {
|
|
211
|
+
method: 'eth_sendTransaction',
|
|
212
|
+
params: [txParams]
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return hash;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
throw parseError(error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Send smart contract transaction (including ERC-20 transfers)
|
|
223
|
+
*/
|
|
224
|
+
async sendContractCall(client, session, request, activeNetworkId, activeAddress) {
|
|
225
|
+
try {
|
|
226
|
+
// Use the active network chainId
|
|
227
|
+
const chainId = getChainIdFromNetworkId(activeNetworkId);
|
|
228
|
+
// Encode the contract call data using ethers
|
|
229
|
+
const iface = new ethers.Interface(request.abi);
|
|
230
|
+
const data = iface.encodeFunctionData(request.functionName, request.args);
|
|
231
|
+
// Build transaction using ethers
|
|
232
|
+
const tx = {
|
|
233
|
+
from: request.from || activeAddress,
|
|
234
|
+
to: request.contractAddress,
|
|
235
|
+
data
|
|
236
|
+
};
|
|
237
|
+
// Add value for payable functions
|
|
238
|
+
if (request.value) {
|
|
239
|
+
tx.value = BigInt(request.value);
|
|
240
|
+
}
|
|
241
|
+
// Add gas configuration if provided
|
|
242
|
+
if (request.gasConfig?.gasLimit) {
|
|
243
|
+
tx.gasLimit = BigInt(Math.floor(request.gasConfig.gasLimit));
|
|
244
|
+
}
|
|
245
|
+
if (request.gasConfig?.maxFeePerGas) {
|
|
246
|
+
tx.maxFeePerGas = BigInt(Math.floor(request.gasConfig.maxFeePerGas));
|
|
247
|
+
}
|
|
248
|
+
if (request.gasConfig?.maxPriorityFeePerGas) {
|
|
249
|
+
tx.maxPriorityFeePerGas = BigInt(Math.floor(request.gasConfig.maxPriorityFeePerGas));
|
|
250
|
+
}
|
|
251
|
+
// Convert to hex format for WalletConnect
|
|
252
|
+
const txParams = {
|
|
253
|
+
from: tx.from,
|
|
254
|
+
to: tx.to,
|
|
255
|
+
data: tx.data
|
|
256
|
+
};
|
|
257
|
+
// Add value if present
|
|
258
|
+
if (tx.value) {
|
|
259
|
+
txParams['value'] = '0x' + BigInt(tx.value).toString(16);
|
|
260
|
+
}
|
|
261
|
+
// Add gas params if present
|
|
262
|
+
if (tx.gasLimit) {
|
|
263
|
+
txParams['gasLimit'] = '0x' + tx.gasLimit.toString(16);
|
|
264
|
+
}
|
|
265
|
+
if (tx.maxFeePerGas) {
|
|
266
|
+
txParams['maxFeePerGas'] = '0x' + tx.maxFeePerGas.toString(16);
|
|
267
|
+
}
|
|
268
|
+
if (tx.maxPriorityFeePerGas) {
|
|
269
|
+
txParams['maxPriorityFeePerGas'] =
|
|
270
|
+
'0x' + tx.maxPriorityFeePerGas.toString(16);
|
|
271
|
+
}
|
|
272
|
+
const hash = await client.request({
|
|
273
|
+
topic: session.topic,
|
|
274
|
+
chainId: `eip155:${chainId}`,
|
|
275
|
+
request: {
|
|
276
|
+
method: 'eth_sendTransaction',
|
|
277
|
+
params: [txParams]
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return hash;
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
throw parseError(error);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=transaction-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-service.js","sourceRoot":"","sources":["../../src/services/transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAWxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAA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,EAAE,CAAC;YACf,MAAM,UAAU,CAAC,KAAK,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import SignClient from '@walletconnect/sign-client';
|
|
2
|
+
import type { WalletConnectConfig } from '@meshconnect/uwc-types';
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing WalletConnect client instance
|
|
5
|
+
*/
|
|
6
|
+
export declare class WalletConnectClient {
|
|
7
|
+
private config;
|
|
8
|
+
private client;
|
|
9
|
+
private initPromise;
|
|
10
|
+
constructor(config: WalletConnectConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Initialize or get the WalletConnect client
|
|
13
|
+
*/
|
|
14
|
+
getClient(): Promise<SignClient>;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the WalletConnect client
|
|
17
|
+
*/
|
|
18
|
+
private initClient;
|
|
19
|
+
/**
|
|
20
|
+
* Disconnect all sessions
|
|
21
|
+
*/
|
|
22
|
+
disconnectAll(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Disconnect a specific session
|
|
25
|
+
*/
|
|
26
|
+
disconnect(topic: string): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=walletconnect-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletconnect-client.d.ts","sourceRoot":"","sources":["../../src/services/walletconnect-client.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,4BAA4B,CAAA;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAEjE;;GAEG;AACH,qBAAa,mBAAmB;IAIlB,OAAO,CAAC,MAAM;IAH1B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,WAAW,CAAmC;gBAElC,MAAM,EAAE,mBAAmB;IAE/C;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC;IAmBtC;;OAEG;YACW,UAAU;IA6BxB;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBpC;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAW/C"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import SignClient from '@walletconnect/sign-client';
|
|
2
|
+
/**
|
|
3
|
+
* Service for managing WalletConnect client instance
|
|
4
|
+
*/
|
|
5
|
+
export class WalletConnectClient {
|
|
6
|
+
config;
|
|
7
|
+
client = null;
|
|
8
|
+
initPromise = null;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Initialize or get the WalletConnect client
|
|
14
|
+
*/
|
|
15
|
+
async getClient() {
|
|
16
|
+
// If already initialized, return the client
|
|
17
|
+
if (this.client) {
|
|
18
|
+
return this.client;
|
|
19
|
+
}
|
|
20
|
+
// If initialization is in progress, wait for it
|
|
21
|
+
if (this.initPromise) {
|
|
22
|
+
return this.initPromise;
|
|
23
|
+
}
|
|
24
|
+
// Start initialization
|
|
25
|
+
this.initPromise = this.initClient();
|
|
26
|
+
this.client = await this.initPromise;
|
|
27
|
+
this.initPromise = null;
|
|
28
|
+
return this.client;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the WalletConnect client
|
|
32
|
+
*/
|
|
33
|
+
async initClient() {
|
|
34
|
+
if (!this.config.projectId) {
|
|
35
|
+
throw new Error('WalletConnect projectId is required');
|
|
36
|
+
}
|
|
37
|
+
let url = this.config.metadata?.url || '';
|
|
38
|
+
if (!url && typeof globalThis !== 'undefined') {
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
const global = globalThis;
|
|
41
|
+
if (global.location?.origin) {
|
|
42
|
+
url = global.location.origin;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const metadata = {
|
|
46
|
+
name: this.config.metadata?.name || 'Universal Wallet Connector',
|
|
47
|
+
description: this.config.metadata?.description || 'Connect your wallet',
|
|
48
|
+
url,
|
|
49
|
+
icons: this.config.metadata?.icons || []
|
|
50
|
+
};
|
|
51
|
+
const client = await SignClient.init({
|
|
52
|
+
projectId: this.config.projectId,
|
|
53
|
+
metadata
|
|
54
|
+
});
|
|
55
|
+
return client;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Disconnect all sessions
|
|
59
|
+
*/
|
|
60
|
+
async disconnectAll() {
|
|
61
|
+
const client = await this.getClient();
|
|
62
|
+
const sessions = client.session.getAll();
|
|
63
|
+
for (const session of sessions) {
|
|
64
|
+
try {
|
|
65
|
+
await client.disconnect({
|
|
66
|
+
topic: session.topic,
|
|
67
|
+
reason: {
|
|
68
|
+
code: 6000,
|
|
69
|
+
message: 'User disconnected'
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Silently ignore disconnect errors
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Disconnect a specific session
|
|
80
|
+
*/
|
|
81
|
+
async disconnect(topic) {
|
|
82
|
+
const client = await this.getClient();
|
|
83
|
+
await client.disconnect({
|
|
84
|
+
topic,
|
|
85
|
+
reason: {
|
|
86
|
+
code: 6000,
|
|
87
|
+
message: 'User disconnected'
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=walletconnect-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletconnect-client.js","sourceRoot":"","sources":["../../src/services/walletconnect-client.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,4BAA4B,CAAA;AAGnD;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAIV;IAHZ,MAAM,GAAsB,IAAI,CAAA;IAChC,WAAW,GAA+B,IAAI,CAAA;IAEtD,YAAoB,MAA2B;Q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AM,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;SACzC,CAAA;QAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC;YACnC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,QAAQ;SACT,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa;QACjB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;QACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAA;QAExC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,UAAU,CAAC;oBACtB,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,MAAM,EAAE;wBACN,IAAI,EAAE,IAAI;wBACV,OAAO,EAAE,mBAAmB;qBAC7B;iBACF,CAAC,CAAA;YACJ,CAAC;YAAC,MAAM,CAAC;gBACP,oCAAoC;YACtC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,KAAa;QAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;QAErC,MAAM,MAAM,CAAC,UAAU,CAAC;YACtB,KAAK;YACL,MAAM,EAAE;gBACN,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,mBAAmB;aAC7B;SACF,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { NetworkId, Namespace } from '@meshconnect/uwc-types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a WalletConnect account string into its components
|
|
4
|
+
* Account format: "namespace:chainId:address"
|
|
5
|
+
* Example: "eip155:1:0x1234..." or "solana:mainnet:ABC123..."
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseAccount(account: string): {
|
|
8
|
+
namespace: Namespace;
|
|
9
|
+
chainId: string;
|
|
10
|
+
networkId: NetworkId;
|
|
11
|
+
address: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Build a WalletConnect account string from components
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildAccount(namespace: Namespace, chainId: string, address: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Extract namespace from a network ID
|
|
19
|
+
* Example: "eip155:1" -> "eip155"
|
|
20
|
+
*/
|
|
21
|
+
export declare function getNamespaceFromNetworkId(networkId: NetworkId): Namespace;
|
|
22
|
+
/**
|
|
23
|
+
* Extract chain ID from a network ID
|
|
24
|
+
* Example: "eip155:1" -> "1"
|
|
25
|
+
*/
|
|
26
|
+
export declare function getChainIdFromNetworkId(networkId: NetworkId): string;
|
|
27
|
+
/**
|
|
28
|
+
* Find an account in session namespaces that matches the given network and address
|
|
29
|
+
*/
|
|
30
|
+
export declare function findAccountInNamespaces(namespaces: Record<string, any>, targetNetworkId: NetworkId, targetAddress: string): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Extract all accounts from session namespaces
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractAccountsFromNamespaces(namespaces: Record<string, any>): Array<{
|
|
35
|
+
account: string;
|
|
36
|
+
namespace: Namespace;
|
|
37
|
+
chainId: string;
|
|
38
|
+
networkId: NetworkId;
|
|
39
|
+
address: string;
|
|
40
|
+
}>;
|
|
41
|
+
//# sourceMappingURL=account-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-utils.d.ts","sourceRoot":"","sources":["../../src/utils/account-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAElE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG;IAC7C,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;CAChB,CAkBA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAGzE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAGpE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,eAAe,EAAE,SAAS,EAC1B,aAAa,EAAE,MAAM,GACpB,MAAM,GAAG,IAAI,CAUf;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC9B,KAAK,CAAC;IACP,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC,CAwBD"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a WalletConnect account string into its components
|
|
3
|
+
* Account format: "namespace:chainId:address"
|
|
4
|
+
* Example: "eip155:1:0x1234..." or "solana:mainnet:ABC123..."
|
|
5
|
+
*/
|
|
6
|
+
export function parseAccount(account) {
|
|
7
|
+
const parts = account.split(':');
|
|
8
|
+
if (parts.length < 3) {
|
|
9
|
+
throw new Error(`Invalid account format: ${account}`);
|
|
10
|
+
}
|
|
11
|
+
const namespace = parts[0];
|
|
12
|
+
const chainId = parts[1];
|
|
13
|
+
const networkId = `${namespace}:${chainId}`;
|
|
14
|
+
// Handle addresses that might contain colons (like some Solana addresses)
|
|
15
|
+
const address = parts.slice(2).join(':');
|
|
16
|
+
return {
|
|
17
|
+
namespace,
|
|
18
|
+
chainId,
|
|
19
|
+
networkId,
|
|
20
|
+
address
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build a WalletConnect account string from components
|
|
25
|
+
*/
|
|
26
|
+
export function buildAccount(namespace, chainId, address) {
|
|
27
|
+
return `${namespace}:${chainId}:${address}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract namespace from a network ID
|
|
31
|
+
* Example: "eip155:1" -> "eip155"
|
|
32
|
+
*/
|
|
33
|
+
export function getNamespaceFromNetworkId(networkId) {
|
|
34
|
+
const [namespace] = networkId.split(':');
|
|
35
|
+
return namespace;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Extract chain ID from a network ID
|
|
39
|
+
* Example: "eip155:1" -> "1"
|
|
40
|
+
*/
|
|
41
|
+
export function getChainIdFromNetworkId(networkId) {
|
|
42
|
+
const [, chainId] = networkId.split(':');
|
|
43
|
+
return chainId || '';
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Find an account in session namespaces that matches the given network and address
|
|
47
|
+
*/
|
|
48
|
+
export function findAccountInNamespaces(namespaces, targetNetworkId, targetAddress) {
|
|
49
|
+
for (const [, namespaceData] of Object.entries(namespaces)) {
|
|
50
|
+
for (const account of namespaceData.accounts || []) {
|
|
51
|
+
const { networkId, address } = parseAccount(account);
|
|
52
|
+
if (networkId === targetNetworkId && address === targetAddress) {
|
|
53
|
+
return account;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Extract all accounts from session namespaces
|
|
61
|
+
*/
|
|
62
|
+
export function extractAccountsFromNamespaces(namespaces) {
|
|
63
|
+
const accounts = [];
|
|
64
|
+
Object.entries(namespaces).forEach(([, namespaceData]) => {
|
|
65
|
+
;
|
|
66
|
+
(namespaceData.accounts || []).forEach((account) => {
|
|
67
|
+
try {
|
|
68
|
+
const parsed = parseAccount(account);
|
|
69
|
+
accounts.push({
|
|
70
|
+
account,
|
|
71
|
+
...parsed
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Skip invalid accounts
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
return accounts;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=account-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-utils.js","sourceRoot":"","sources":["../../src/utils/account-utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAM1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAChC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAc,CAAA;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;IACzB,MAAM,SAAS,GAAG,GAAG,SAAS,IAAI,OAAO,EAAe,CAAA;IACxD,0EAA0E;IAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAExC,OAAO;QACL,SAAS;QACT,OAAO;QACP,SAAS;QACT,OAAO;KACR,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAoB,EACpB,OAAe,EACf,OAAe;IAEf,OAAO,GAAG,SAAS,IAAI,OAAO,IAAI,OAAO,EAAE,CAAA;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,SAAoB;IAC5D,MAAM,CAAC,SAAS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YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode a string message to base58 format (used for Solana message signing)
|
|
3
|
+
*/
|
|
4
|
+
export declare const base58Encode: (message: string) => string;
|
|
5
|
+
export declare const standardizeSignature: (rawSignature: string | Uint8Array) => string;
|
|
6
|
+
//# sourceMappingURL=encoding-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding-utils.d.ts","sourceRoot":"","sources":["../../src/utils/encoding-utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,WAK3C,CAAA;AAED,eAAO,MAAM,oBAAoB,GAC/B,cAAc,MAAM,GAAG,UAAU,KAChC,MAiBF,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import bs58 from 'bs58';
|
|
2
|
+
/**
|
|
3
|
+
* Encode a string message to base58 format (used for Solana message signing)
|
|
4
|
+
*/
|
|
5
|
+
export const base58Encode = (message) => {
|
|
6
|
+
// Use TextEncoder for browser compatibility
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const messageBytes = encoder.encode(message);
|
|
9
|
+
return bs58.encode(messageBytes);
|
|
10
|
+
};
|
|
11
|
+
export const standardizeSignature = (rawSignature) => {
|
|
12
|
+
// First ensure we have a string
|
|
13
|
+
let signature = typeof rawSignature === 'string' ? rawSignature : bs58.encode(rawSignature);
|
|
14
|
+
// If signature is longer than standard 88 chars, decode and re-encode
|
|
15
|
+
if (signature.length > 88) {
|
|
16
|
+
try {
|
|
17
|
+
const bytes = bs58.decode(signature);
|
|
18
|
+
const truncatedBytes = bytes.slice(0, 64);
|
|
19
|
+
signature = bs58.encode(truncatedBytes);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error('Failed to normalize signature');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return signature;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=encoding-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding-utils.js","sourceRoot":"","sources":["../../src/utils/encoding-utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,EAAE;IAC9C,4CAA4C;IAC5C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;IACjC,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AAClC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,YAAiC,EACzB,EAAE;IACV,gCAAgC;IAChC,IAAI,SAAS,GACX,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IAE7E,sEAAsE;IACtE,IAAI,SAAS,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YACpC,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YACzC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;QACzC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;QAClD,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAsDhD"}
|