@meshconnect/uwc-injected-connector 0.25.0 → 0.26.1-snapshot.0c4e867
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/services/ethereum/ethereum-transaction-service.d.ts.map +1 -1
- package/dist/services/ethereum/ethereum-transaction-service.js +28 -7
- package/dist/services/ethereum/ethereum-transaction-service.js.map +1 -1
- package/dist/services/solana/solana-transaction-service.d.ts +17 -0
- package/dist/services/solana/solana-transaction-service.d.ts.map +1 -1
- package/dist/services/solana/solana-transaction-service.js +44 -24
- package/dist/services/solana/solana-transaction-service.js.map +1 -1
- package/package.json +7 -7
- package/src/services/ethereum/ethereum-transaction-service.test.ts +222 -5
- package/src/services/ethereum/ethereum-transaction-service.ts +41 -12
- package/src/services/solana/solana-transaction-service.test.ts +135 -1
- package/src/services/solana/solana-transaction-service.ts +60 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum-transaction-service.d.ts","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAKV,0BAA0B,EAE3B,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"ethereum-transaction-service.d.ts","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAKV,0BAA0B,EAE3B,MAAM,wBAAwB,CAAA;AAY/B;;GAEG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,OAAO,CAA4B;IAE3C,cAEC;IAED;;OAEG;IACG,eAAe,CACnB,OAAO,EAAE,0BAA0B,EACnC,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,CAAC,CAiCjB;IAED;;OAEG;YACW,qBAAqB;IAiCnC;;OAEG;YACW,gBAAgB;IAkC9B;;OAEG;YACW,gBAAgB;IAkC9B;;OAEG;YACW,SAAS;CAgJxB"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { createWalletClient, custom } from 'viem';
|
|
2
|
+
import { BatchConfirmedWithoutReceiptError } from '@meshconnect/uwc-types';
|
|
2
3
|
import { parseError } from '../../utils/error-utils';
|
|
3
4
|
import { EthereumTransactionBuilder } from './ethereum-transaction-builder';
|
|
5
|
+
/**
|
|
6
|
+
* How long a confirmed (200) batch without receipts is re-read before giving up.
|
|
7
|
+
* EIP-5792 makes receipts optional; a wallet may still add them on a later read.
|
|
8
|
+
*/
|
|
9
|
+
const RECEIPT_POLL_INTERVAL_MS = 1000;
|
|
10
|
+
const RECEIPT_POLL_ATTEMPTS = 10;
|
|
4
11
|
/**
|
|
5
12
|
* Service for handling Ethereum/EVM transaction operations
|
|
6
13
|
*/
|
|
@@ -188,13 +195,14 @@ export class EthereumTransactionService {
|
|
|
188
195
|
});
|
|
189
196
|
// Poll for completion with retry logic for specific errors
|
|
190
197
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
198
|
+
const getCallsStatus = () => client.request({
|
|
199
|
+
method: 'wallet_getCallsStatus',
|
|
200
|
+
params: [response.id]
|
|
201
|
+
});
|
|
191
202
|
let result;
|
|
192
203
|
while (true) {
|
|
193
204
|
try {
|
|
194
|
-
result = await
|
|
195
|
-
method: 'wallet_getCallsStatus',
|
|
196
|
-
params: [response.id]
|
|
197
|
-
});
|
|
205
|
+
result = await getCallsStatus();
|
|
198
206
|
// Wait 1 second if still pending
|
|
199
207
|
if (result?.status === 100) {
|
|
200
208
|
await sleep(1000);
|
|
@@ -218,10 +226,23 @@ export class EthereumTransactionService {
|
|
|
218
226
|
if (result.status !== 200) {
|
|
219
227
|
throw new Error('Batch transaction failed');
|
|
220
228
|
}
|
|
221
|
-
// Return first transaction hash
|
|
222
|
-
|
|
229
|
+
// Return first transaction hash. A confirmed batch may come without
|
|
230
|
+
// receipts (optional in EIP-5792): re-read for a while in case the wallet
|
|
231
|
+
// adds them, and only then report it as confirmed-without-receipt.
|
|
232
|
+
let firstReceipt = result.receipts?.find(r => r);
|
|
233
|
+
for (let attempt = 0; !firstReceipt && attempt < RECEIPT_POLL_ATTEMPTS; attempt++) {
|
|
234
|
+
await sleep(RECEIPT_POLL_INTERVAL_MS);
|
|
235
|
+
try {
|
|
236
|
+
firstReceipt = (await getCallsStatus())?.receipts?.find(r => r);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// The batch is already confirmed; a failed re-read must not turn it
|
|
240
|
+
// into a failure. Stop and report it without a receipt.
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
223
244
|
if (!firstReceipt) {
|
|
224
|
-
throw new
|
|
245
|
+
throw new BatchConfirmedWithoutReceiptError(response.id, request.chainId);
|
|
225
246
|
}
|
|
226
247
|
return firstReceipt.transactionHash;
|
|
227
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum-transaction-service.js","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAUjD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAA;AAE3E;;GAEG;AACH,MAAM,OAAO,0BAA0B;IAC7B,OAAO,CAA4B;IAE3C;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,0BAA0B,EAAE,CAAA;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CACnB,OAAmC,EACnC,QAA0B;QAE1B,IAAI,CAAC;YACH,6CAA6C;YAC7C,IAAI,iBAAiB,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;gBACrD,gBAAg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CAAC,kBAAkB,CAClD,EAA4B,CAC7B,CAAA;oBACD,OAAO;wBACL,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE;wBACnB,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;qBAChD,CAAA;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;gBACrD,CAAC;YACH,CAAC,CAAC,CACH,CAAA;YAED,4BAA4B;YAC5B,MAAM,MAAM,GAAG,kBAAkB,CAAC;gBAChC,OAAO,EAAE,OAAO,CAAC,IAAqB;gBACtC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC;aAC5B,CAAC,CAAA;YAEF,wCAAwC;YACxC,MAAM,QAAQ,GAAmB,MAC/B,MAAM,CAAC,OAIR,CAAC;gBACA,MAAM,EAAE,kBAAkB;gBAC1B,MAAM,EAAE;oBACN;wBACE,OAAO,EAAE,OAAO,CAAC,OAAO;wBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;wBAClB,OAAO,EAAE,OAAO,CAAC,OAAO;wBACxB,cAAc,EAAE,OAAO,CAAC,cAAc;wBACtC,KAAK,EAAE,KAAK;qBACb;iBACF;aACF,CAAC,CAAA;YAEF,2DAA2D;YAC3D,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAC3B,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;YACjD,
|
|
1
|
+
{"version":3,"file":"ethereum-transaction-service.js","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAUjD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAA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CAAA;YAC7C,CAAC;YAED,oEAAoE;YACpE,0EAA0E;YAC1E,mEAAmE;YACnE,IAAI,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YAChD,KACE,IAAI,OAAO,GAAG,CAAC,EACf,CAAC,YAAY,IAAI,OAAO,GAAG,qBAAqB,EAChD,OAAO,EAAE,EACT,CAAC;gBACD,MAAM,KAAK,CAAC,wBAAwB,CAAC,CAAA;gBACrC,IAAI,CAAC;oBACH,YAAY,GAAG,CAAC,MAAM,cAAc,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;gBACjE,CAAC;gBAAC,MAAM,CAAC;oBACP,oEAAoE;oBACpE,wDAAwD;oBACxD,MAAK;gBACP,CAAC;YACH,CAAC;YACD,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,MAAM,IAAI,iCAAiC,CACzC,QAAQ,CAAC,EAAE,EACX,OAAO,CAAC,OAAO,CAChB,CAAA;YACH,CAAC;YAED,OAAO,YAAY,CAAC,eAAe,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -19,6 +19,17 @@ export declare class SolanaTransactionService {
|
|
|
19
19
|
* Helper: Get RPC URL with fallback
|
|
20
20
|
*/
|
|
21
21
|
private getRpcUrl;
|
|
22
|
+
/**
|
|
23
|
+
* Helper: Whether the wallet declares V0 support. A bridged adapter is a
|
|
24
|
+
* Comlink proxy whose property reads return a Promise (its `.has` would
|
|
25
|
+
* always look truthy), so the value is always resolved first.
|
|
26
|
+
*/
|
|
27
|
+
private supportsVersionedTransactions;
|
|
28
|
+
/**
|
|
29
|
+
* Helper: Serialize for the bridge path. Legacy skips signature checks
|
|
30
|
+
* because the wallet has not signed yet.
|
|
31
|
+
*/
|
|
32
|
+
private serializeTransaction;
|
|
22
33
|
/**
|
|
23
34
|
* Two mutually exclusive paths:
|
|
24
35
|
* 1. sendSerializedTransaction(Uint8Array, string) — Comlink bridge safe.
|
|
@@ -33,6 +44,12 @@ export declare class SolanaTransactionService {
|
|
|
33
44
|
* Send SPL token transfer
|
|
34
45
|
*/
|
|
35
46
|
private sendSplTokenTransaction;
|
|
47
|
+
/**
|
|
48
|
+
* Legacy by default. V0 only when the request opts in and the wallet
|
|
49
|
+
* declares V0 support: Trust's mobile in-app provider cannot sign a legacy
|
|
50
|
+
* transaction delivered through the Wallet Standard, but signs V0.
|
|
51
|
+
*/
|
|
52
|
+
private buildTransferTransaction;
|
|
36
53
|
/**
|
|
37
54
|
* Send native SOL transfer
|
|
38
55
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solana-transaction-service.d.ts","sourceRoot":"","sources":["../../../src/services/solana/solana-transaction-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"solana-transaction-service.d.ts","sourceRoot":"","sources":["../../../src/services/solana/solana-transaction-service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,aAAa,EACb,SAAS,EAGT,wBAAwB,EACzB,MAAM,wBAAwB,CAAA;AAG/B,OAAO,KAAK,EAEV,aAAa,EACd,MAAM,iCAAiC,CAAA;AAExC;;GAEG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,OAAO,CAA0B;IAEzC,YAAY,aAAa,GAAE,aAAkB,EAG5C;IAED;;OAEG;IACG,eAAe,CACnB,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE,aAAa,EACtB,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,MAAM,CAAC,CA2BjB;IAED;;OAEG;YACW,mBAAmB;IAWjC;;OAEG;IACH,OAAO,CAAC,SAAS;IAMjB;;;;OAIG;YACW,6BAA6B;IAO3C;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;;;OAIG;YACW,kBAAkB;IA2BhC;;OAEG;YACW,qBAAqB;IA2BnC;;OAEG;YACW,uBAAuB;IA2BrC;;;;OAIG;YACW,wBAAwB;IAqBtC;;OAEG;YACW,mCAAmC;CAiClD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Transaction, VersionedTransaction, Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { isVersionedTransaction } from '@solana/wallet-adapter-base';
|
|
2
3
|
import { parseError } from '../../utils/error-utils';
|
|
3
4
|
import { SolanaTransactionBuilder } from './solana-transaction-builder';
|
|
4
5
|
/**
|
|
@@ -52,6 +53,27 @@ export class SolanaTransactionService {
|
|
|
52
53
|
? this.networkRpcMap[networkId]
|
|
53
54
|
: 'https://api.mainnet-beta.solana.com';
|
|
54
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Helper: Whether the wallet declares V0 support. A bridged adapter is a
|
|
58
|
+
* Comlink proxy whose property reads return a Promise (its `.has` would
|
|
59
|
+
* always look truthy), so the value is always resolved first.
|
|
60
|
+
*/
|
|
61
|
+
async supportsVersionedTransactions(adapter) {
|
|
62
|
+
const versions = await Promise.resolve(adapter.supportedTransactionVersions);
|
|
63
|
+
return versions?.has(0) ?? false;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Helper: Serialize for the bridge path. Legacy skips signature checks
|
|
67
|
+
* because the wallet has not signed yet.
|
|
68
|
+
*/
|
|
69
|
+
serializeTransaction(transaction) {
|
|
70
|
+
return isVersionedTransaction(transaction)
|
|
71
|
+
? transaction.serialize()
|
|
72
|
+
: transaction.serialize({
|
|
73
|
+
requireAllSignatures: false,
|
|
74
|
+
verifySignatures: false
|
|
75
|
+
});
|
|
76
|
+
}
|
|
55
77
|
/**
|
|
56
78
|
* Two mutually exclusive paths:
|
|
57
79
|
* 1. sendSerializedTransaction(Uint8Array, string) — Comlink bridge safe.
|
|
@@ -84,18 +106,8 @@ export class SolanaTransactionService {
|
|
|
84
106
|
if (!request.blockhash) {
|
|
85
107
|
throw new Error('Blockhash is required for Solana transactions');
|
|
86
108
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
transaction.instructions =
|
|
90
|
-
await this.builder.buildTransferInstructions(request);
|
|
91
|
-
transaction.recentBlockhash = request.blockhash;
|
|
92
|
-
transaction.feePayer = new PublicKey(request.from);
|
|
93
|
-
const rpcUrl = this.getRpcUrl(networkId);
|
|
94
|
-
const serializedTx = transaction.serialize({
|
|
95
|
-
requireAllSignatures: false,
|
|
96
|
-
verifySignatures: false
|
|
97
|
-
});
|
|
98
|
-
return await this.executeTransaction(adapter, serializedTx, transaction, rpcUrl);
|
|
109
|
+
const transaction = await this.buildTransferTransaction(adapter, request);
|
|
110
|
+
return await this.executeTransaction(adapter, this.serializeTransaction(transaction), transaction, this.getRpcUrl(networkId));
|
|
99
111
|
}
|
|
100
112
|
catch (error) {
|
|
101
113
|
parseError(error);
|
|
@@ -112,23 +124,31 @@ export class SolanaTransactionService {
|
|
|
112
124
|
if (!request.blockhash) {
|
|
113
125
|
throw new Error('Blockhash is required for Solana transactions');
|
|
114
126
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
transaction.instructions =
|
|
118
|
-
await this.builder.buildTransferInstructions(request);
|
|
119
|
-
transaction.recentBlockhash = request.blockhash;
|
|
120
|
-
transaction.feePayer = new PublicKey(request.from);
|
|
121
|
-
const rpcUrl = this.getRpcUrl(networkId);
|
|
122
|
-
const serializedTx = transaction.serialize({
|
|
123
|
-
requireAllSignatures: false,
|
|
124
|
-
verifySignatures: false
|
|
125
|
-
});
|
|
126
|
-
return await this.executeTransaction(adapter, serializedTx, transaction, rpcUrl);
|
|
127
|
+
const transaction = await this.buildTransferTransaction(adapter, request);
|
|
128
|
+
return await this.executeTransaction(adapter, this.serializeTransaction(transaction), transaction, this.getRpcUrl(networkId));
|
|
127
129
|
}
|
|
128
130
|
catch (error) {
|
|
129
131
|
parseError(error);
|
|
130
132
|
}
|
|
131
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Legacy by default. V0 only when the request opts in and the wallet
|
|
136
|
+
* declares V0 support: Trust's mobile in-app provider cannot sign a legacy
|
|
137
|
+
* transaction delivered through the Wallet Standard, but signs V0.
|
|
138
|
+
*/
|
|
139
|
+
async buildTransferTransaction(adapter, request) {
|
|
140
|
+
const feePayer = new PublicKey(request.from);
|
|
141
|
+
if (request.preferVersionedTransaction &&
|
|
142
|
+
(await this.supportsVersionedTransactions(adapter))) {
|
|
143
|
+
return this.builder.getVersionedTransaction(feePayer, request);
|
|
144
|
+
}
|
|
145
|
+
const transaction = new Transaction();
|
|
146
|
+
transaction.instructions =
|
|
147
|
+
await this.builder.buildTransferInstructions(request);
|
|
148
|
+
transaction.recentBlockhash = request.blockhash;
|
|
149
|
+
transaction.feePayer = feePayer;
|
|
150
|
+
return transaction;
|
|
151
|
+
}
|
|
132
152
|
/**
|
|
133
153
|
* Send native SOL transfer
|
|
134
154
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solana-transaction-service.js","sourceRoot":"","sources":["../../../src/services/solana/solana-transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"solana-transaction-service.js","sourceRoot":"","sources":["../../../src/services/solana/solana-transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AASpE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AAMvE;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAC3B,aAAa,CAAe;IAC5B,O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M,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;YACxC,MAAM,YAAY,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;YAE5C,OAAO,MAAM,IAAI,CAAC,kBAAkB,CAClC,OAAO,EACP,YAAY,EACZ,WAAW,EACX,MAAM,CACP,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-injected-connector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1-snapshot.0c4e867",
|
|
4
4
|
"description": "Injected connector for Universal Wallet Connector",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"buffer": "^6.0.3",
|
|
28
28
|
"uuid": "^14.0.2",
|
|
29
29
|
"viem": "^2.56.5",
|
|
30
|
-
"@meshconnect/uwc-bridge-child": "0.6.0",
|
|
31
|
-
"@meshconnect/uwc-constants": "0.
|
|
32
|
-
"@meshconnect/uwc-ton-connector": "0.9.
|
|
33
|
-
"@meshconnect/uwc-bitcoin": "0.5.
|
|
34
|
-
"@meshconnect/uwc-tron-connector": "0.7.
|
|
35
|
-
"@meshconnect/uwc-types": "0.
|
|
30
|
+
"@meshconnect/uwc-bridge-child": "0.6.0-snapshot.0c4e867",
|
|
31
|
+
"@meshconnect/uwc-constants": "0.8.0-snapshot.0c4e867",
|
|
32
|
+
"@meshconnect/uwc-ton-connector": "0.9.8-snapshot.0c4e867",
|
|
33
|
+
"@meshconnect/uwc-bitcoin": "0.5.2-snapshot.0c4e867",
|
|
34
|
+
"@meshconnect/uwc-tron-connector": "0.7.12-snapshot.0c4e867",
|
|
35
|
+
"@meshconnect/uwc-types": "0.30.0-snapshot.0c4e867"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "^7.0.2"
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
2
|
import { EthereumTransactionService } from './ethereum-transaction-service'
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import {
|
|
4
|
+
BatchConfirmedWithoutReceiptError,
|
|
5
|
+
WalletConnectorError,
|
|
6
|
+
type EVMNativeTransferRequest,
|
|
7
|
+
type EVMContractCallRequest,
|
|
8
|
+
type EVMDataTransferRequest,
|
|
9
|
+
type EVMBatchTransactionRequest
|
|
7
10
|
} from '@meshconnect/uwc-types'
|
|
8
11
|
import type { EthereumProvider } from '../../eip6963-discovery'
|
|
9
12
|
|
|
@@ -271,4 +274,218 @@ describe('EthereumTransactionService', () => {
|
|
|
271
274
|
).rejects.toThrow()
|
|
272
275
|
})
|
|
273
276
|
})
|
|
277
|
+
|
|
278
|
+
describe('sendBatch (EIP-5792)', () => {
|
|
279
|
+
const BATCH_ID = '0x8becd65ed2d2425485a9a90d04b63ec0'
|
|
280
|
+
const TX_HASH =
|
|
281
|
+
'0x1986bfb2c0ffee00000000000000000000000000000000000000000000aad1'
|
|
282
|
+
|
|
283
|
+
// Recorded from MetaMask Mobile (iOS in-app browser) paying the network fee
|
|
284
|
+
// in ARB on Arbitrum: confirmed, atomic, and no `receipts` field at all.
|
|
285
|
+
const confirmedWithoutReceipts = {
|
|
286
|
+
version: '2.0.0',
|
|
287
|
+
id: BATCH_ID,
|
|
288
|
+
chainId: '0xa4b1',
|
|
289
|
+
atomic: true,
|
|
290
|
+
status: 200
|
|
291
|
+
}
|
|
292
|
+
const confirmedWithReceipts = {
|
|
293
|
+
...confirmedWithoutReceipts,
|
|
294
|
+
receipts: [{ transactionHash: TX_HASH }]
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const batchRequest: EVMBatchTransactionRequest = {
|
|
298
|
+
version: '2.0.0',
|
|
299
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
300
|
+
chainId: '0xa4b1',
|
|
301
|
+
atomicRequired: true,
|
|
302
|
+
calls: [
|
|
303
|
+
{
|
|
304
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
305
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
306
|
+
data: '0x095ea7b3',
|
|
307
|
+
chainId: '42161'
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
311
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
312
|
+
data: '0xa9059cbb',
|
|
313
|
+
chainId: '42161'
|
|
314
|
+
}
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Provider that accepts `wallet_sendCalls` and answers each
|
|
320
|
+
* `wallet_getCallsStatus` with the next scripted reply (the last one
|
|
321
|
+
* repeats). A reply that is an Error is thrown instead.
|
|
322
|
+
*/
|
|
323
|
+
const batchProvider = (statusReplies: unknown[]) => {
|
|
324
|
+
let call = 0
|
|
325
|
+
const request = vi.fn(async ({ method }: { method: string }) => {
|
|
326
|
+
if (method === 'wallet_sendCalls') return { id: BATCH_ID }
|
|
327
|
+
if (method === 'wallet_getCallsStatus') {
|
|
328
|
+
const reply =
|
|
329
|
+
statusReplies[Math.min(call++, statusReplies.length - 1)]
|
|
330
|
+
if (reply instanceof Error) throw reply
|
|
331
|
+
return reply
|
|
332
|
+
}
|
|
333
|
+
throw new Error(`unexpected method ${method}`)
|
|
334
|
+
})
|
|
335
|
+
return { request } as unknown as EthereumProvider & {
|
|
336
|
+
request: typeof request
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const statusCalls = (provider: { request: ReturnType<typeof vi.fn> }) =>
|
|
341
|
+
provider.request.mock.calls.filter(
|
|
342
|
+
([args]) =>
|
|
343
|
+
(args as { method: string }).method === 'wallet_getCallsStatus'
|
|
344
|
+
).length
|
|
345
|
+
|
|
346
|
+
/** Run a send to completion under fake timers; resolves to its outcome. */
|
|
347
|
+
const settle = async (provider: EthereumProvider) => {
|
|
348
|
+
const outcome = service.sendTransaction(batchRequest, provider).then(
|
|
349
|
+
hash => ({ hash }),
|
|
350
|
+
(error: unknown) => ({ error })
|
|
351
|
+
)
|
|
352
|
+
await vi.runAllTimersAsync()
|
|
353
|
+
return outcome
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
beforeEach(() => {
|
|
357
|
+
vi.useFakeTimers()
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
afterEach(() => {
|
|
361
|
+
vi.useRealTimers()
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it('returns the first receipt hash when the confirmation carries receipts', async () => {
|
|
365
|
+
const provider = batchProvider([confirmedWithReceipts])
|
|
366
|
+
|
|
367
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
368
|
+
expect(statusCalls(provider)).toBe(1)
|
|
369
|
+
const sendCalls = provider.request.mock.calls.find(
|
|
370
|
+
([args]) => (args as { method: string }).method === 'wallet_sendCalls'
|
|
371
|
+
)
|
|
372
|
+
expect(sendCalls?.[0]).toMatchObject({
|
|
373
|
+
params: [{ version: '2.0.0', chainId: '0xa4b1', atomicRequired: true }]
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
it('keeps polling a receipt-less confirmation and returns the hash once receipts appear', async () => {
|
|
378
|
+
const provider = batchProvider([
|
|
379
|
+
confirmedWithoutReceipts,
|
|
380
|
+
confirmedWithoutReceipts,
|
|
381
|
+
confirmedWithReceipts
|
|
382
|
+
])
|
|
383
|
+
|
|
384
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
385
|
+
expect(statusCalls(provider)).toBe(3)
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
it('throws BatchConfirmedWithoutReceiptError when receipts never appear', async () => {
|
|
389
|
+
const provider = batchProvider([confirmedWithoutReceipts])
|
|
390
|
+
|
|
391
|
+
const outcome = await settle(provider)
|
|
392
|
+
|
|
393
|
+
expect(outcome).not.toHaveProperty('hash')
|
|
394
|
+
const { error } = outcome as { error: unknown }
|
|
395
|
+
expect(error).toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
396
|
+
// Subclass of the connector error, so `parseError` passes it through.
|
|
397
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
398
|
+
expect(error).toMatchObject({
|
|
399
|
+
name: 'BatchConfirmedWithoutReceiptError',
|
|
400
|
+
batchId: BATCH_ID,
|
|
401
|
+
chainId: '0xa4b1'
|
|
402
|
+
})
|
|
403
|
+
// The initial read plus 10 one-second re-reads, then it gives up.
|
|
404
|
+
expect(statusCalls(provider)).toBe(11)
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
it('gives up on receipts after about 10 seconds', async () => {
|
|
408
|
+
const provider = batchProvider([confirmedWithoutReceipts])
|
|
409
|
+
const outcome = service.sendTransaction(batchRequest, provider).then(
|
|
410
|
+
() => 'resolved',
|
|
411
|
+
() => 'rejected'
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
await vi.advanceTimersByTimeAsync(9_999)
|
|
415
|
+
expect(statusCalls(provider)).toBe(10)
|
|
416
|
+
await vi.advanceTimersByTimeAsync(1)
|
|
417
|
+
|
|
418
|
+
expect(await outcome).toBe('rejected')
|
|
419
|
+
expect(statusCalls(provider)).toBe(11)
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
it('treats an empty receipts array like a missing one', async () => {
|
|
423
|
+
const provider = batchProvider([
|
|
424
|
+
{ ...confirmedWithoutReceipts, receipts: [] }
|
|
425
|
+
])
|
|
426
|
+
|
|
427
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
428
|
+
|
|
429
|
+
expect(error).toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
430
|
+
expect(error).toMatchObject({ batchId: BATCH_ID, chainId: '0xa4b1' })
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
it('reports a confirmed batch without receipt when a re-read fails', async () => {
|
|
434
|
+
const provider = batchProvider([
|
|
435
|
+
confirmedWithoutReceipts,
|
|
436
|
+
new Error('Internal JSON-RPC error')
|
|
437
|
+
])
|
|
438
|
+
|
|
439
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
440
|
+
|
|
441
|
+
expect(error).toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
it.each([400, 500])(
|
|
445
|
+
'throws "Batch transaction failed" for status %i without re-reading',
|
|
446
|
+
async status => {
|
|
447
|
+
const provider = batchProvider([
|
|
448
|
+
{ ...confirmedWithoutReceipts, status }
|
|
449
|
+
])
|
|
450
|
+
|
|
451
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
452
|
+
|
|
453
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
454
|
+
expect(error).not.toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
455
|
+
expect((error as Error).message).toBe('Batch transaction failed')
|
|
456
|
+
expect(statusCalls(provider)).toBe(1)
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
|
|
460
|
+
it('keeps polling while the batch is pending (status 100)', async () => {
|
|
461
|
+
const provider = batchProvider([
|
|
462
|
+
{ ...confirmedWithoutReceipts, status: 100 },
|
|
463
|
+
confirmedWithReceipts
|
|
464
|
+
])
|
|
465
|
+
|
|
466
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
467
|
+
expect(statusCalls(provider)).toBe(2)
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
it('retries "No matching bundle found" until the batch is known', async () => {
|
|
471
|
+
const provider = batchProvider([
|
|
472
|
+
new Error('No matching bundle found'),
|
|
473
|
+
new Error('No matching bundle found'),
|
|
474
|
+
confirmedWithReceipts
|
|
475
|
+
])
|
|
476
|
+
|
|
477
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
478
|
+
expect(statusCalls(provider)).toBe(3)
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
it('fails immediately on any other status-read error', async () => {
|
|
482
|
+
const provider = batchProvider([new Error('Unsupported method')])
|
|
483
|
+
|
|
484
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
485
|
+
|
|
486
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
487
|
+
expect(error).not.toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
488
|
+
expect((error as Error).message).toContain('Unsupported method')
|
|
489
|
+
})
|
|
490
|
+
})
|
|
274
491
|
})
|
|
@@ -8,9 +8,17 @@ import type {
|
|
|
8
8
|
EthereumTransactionRequest,
|
|
9
9
|
EVMDataTransferRequest
|
|
10
10
|
} from '@meshconnect/uwc-types'
|
|
11
|
+
import { BatchConfirmedWithoutReceiptError } from '@meshconnect/uwc-types'
|
|
11
12
|
import { parseError } from '../../utils/error-utils'
|
|
12
13
|
import { EthereumTransactionBuilder } from './ethereum-transaction-builder'
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* How long a confirmed (200) batch without receipts is re-read before giving up.
|
|
17
|
+
* EIP-5792 makes receipts optional; a wallet may still add them on a later read.
|
|
18
|
+
*/
|
|
19
|
+
const RECEIPT_POLL_INTERVAL_MS = 1000
|
|
20
|
+
const RECEIPT_POLL_ATTEMPTS = 10
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* Service for handling Ethereum/EVM transaction operations
|
|
16
24
|
*/
|
|
@@ -246,19 +254,21 @@ export class EthereumTransactionService {
|
|
|
246
254
|
// Poll for completion with retry logic for specific errors
|
|
247
255
|
const sleep = (ms: number) =>
|
|
248
256
|
new Promise(resolve => setTimeout(resolve, ms))
|
|
257
|
+
const getCallsStatus = () =>
|
|
258
|
+
(
|
|
259
|
+
client.request as (args: {
|
|
260
|
+
method: string
|
|
261
|
+
params: unknown[]
|
|
262
|
+
}) => Promise<BatchTransactionResult>
|
|
263
|
+
)({
|
|
264
|
+
method: 'wallet_getCallsStatus',
|
|
265
|
+
params: [response.id]
|
|
266
|
+
})
|
|
249
267
|
let result: BatchTransactionResult | undefined
|
|
250
268
|
|
|
251
269
|
while (true) {
|
|
252
270
|
try {
|
|
253
|
-
result = await (
|
|
254
|
-
client.request as (args: {
|
|
255
|
-
method: string
|
|
256
|
-
params: unknown[]
|
|
257
|
-
}) => Promise<BatchTransactionResult>
|
|
258
|
-
)({
|
|
259
|
-
method: 'wallet_getCallsStatus',
|
|
260
|
-
params: [response.id]
|
|
261
|
-
})
|
|
271
|
+
result = await getCallsStatus()
|
|
262
272
|
|
|
263
273
|
// Wait 1 second if still pending
|
|
264
274
|
if (result?.status === 100) {
|
|
@@ -287,10 +297,29 @@ export class EthereumTransactionService {
|
|
|
287
297
|
throw new Error('Batch transaction failed')
|
|
288
298
|
}
|
|
289
299
|
|
|
290
|
-
// Return first transaction hash
|
|
291
|
-
|
|
300
|
+
// Return first transaction hash. A confirmed batch may come without
|
|
301
|
+
// receipts (optional in EIP-5792): re-read for a while in case the wallet
|
|
302
|
+
// adds them, and only then report it as confirmed-without-receipt.
|
|
303
|
+
let firstReceipt = result.receipts?.find(r => r)
|
|
304
|
+
for (
|
|
305
|
+
let attempt = 0;
|
|
306
|
+
!firstReceipt && attempt < RECEIPT_POLL_ATTEMPTS;
|
|
307
|
+
attempt++
|
|
308
|
+
) {
|
|
309
|
+
await sleep(RECEIPT_POLL_INTERVAL_MS)
|
|
310
|
+
try {
|
|
311
|
+
firstReceipt = (await getCallsStatus())?.receipts?.find(r => r)
|
|
312
|
+
} catch {
|
|
313
|
+
// The batch is already confirmed; a failed re-read must not turn it
|
|
314
|
+
// into a failure. Stop and report it without a receipt.
|
|
315
|
+
break
|
|
316
|
+
}
|
|
317
|
+
}
|
|
292
318
|
if (!firstReceipt) {
|
|
293
|
-
throw new
|
|
319
|
+
throw new BatchConfirmedWithoutReceiptError(
|
|
320
|
+
response.id,
|
|
321
|
+
request.chainId
|
|
322
|
+
)
|
|
294
323
|
}
|
|
295
324
|
|
|
296
325
|
return firstReceipt.transactionHash
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
2
2
|
import { SolanaTransactionService } from './solana-transaction-service'
|
|
3
|
-
import
|
|
3
|
+
import { Transaction } from '@solana/web3.js'
|
|
4
|
+
import type {
|
|
5
|
+
SolanaNativeTransferRequest,
|
|
6
|
+
SolanaTokenTransferRequest
|
|
7
|
+
} from '@meshconnect/uwc-types'
|
|
4
8
|
import type { ExtendedStandardWalletAdapter } from '../../wallet-standard-discovery'
|
|
5
9
|
|
|
6
10
|
vi.mock('@solana/web3.js', () => {
|
|
@@ -211,4 +215,134 @@ describe('SolanaTransactionService', () => {
|
|
|
211
215
|
expect(mockAdapter.sendTransaction).not.toHaveBeenCalled()
|
|
212
216
|
})
|
|
213
217
|
})
|
|
218
|
+
|
|
219
|
+
describe('preferVersionedTransaction — native SOL and SPL transfers', () => {
|
|
220
|
+
const networkId = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
|
|
221
|
+
const nativeRequest: SolanaNativeTransferRequest = {
|
|
222
|
+
from: '5SDmgvJWAeu8Pcp1WRV9uyeiRRrFC654n3vGPSuLEdhm',
|
|
223
|
+
to: '2cXWFBHqJamsAsgZjZgLrDDCvszrRVdMMaaCp9gQTsWL',
|
|
224
|
+
amount: BigInt(100000),
|
|
225
|
+
blockhash: '3PQ5dzi2ZCTfnu5aoncPBW1LBkqGGA54xpakg4JlNF1X'
|
|
226
|
+
}
|
|
227
|
+
const splRequest: SolanaTokenTransferRequest = {
|
|
228
|
+
...nativeRequest,
|
|
229
|
+
tokenMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
230
|
+
tokenDecimals: 6
|
|
231
|
+
}
|
|
232
|
+
const requests = [
|
|
233
|
+
['native SOL', nativeRequest],
|
|
234
|
+
['SPL token', splRequest]
|
|
235
|
+
] as const
|
|
236
|
+
|
|
237
|
+
const v0Bytes = new Uint8Array([4, 5, 6])
|
|
238
|
+
const legacyBytes = new Uint8Array([1, 2, 3])
|
|
239
|
+
const v0Transaction = { version: 0, serialize: () => v0Bytes }
|
|
240
|
+
const supportsV0 = new Set(['legacy', 0])
|
|
241
|
+
|
|
242
|
+
beforeEach(() => {
|
|
243
|
+
mockGetVersionedTransaction.mockResolvedValue(v0Transaction)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
const directAdapter = (supportedTransactionVersions: unknown) =>
|
|
247
|
+
({
|
|
248
|
+
publicKey: { toBase58: vi.fn().mockResolvedValue(nativeRequest.from) },
|
|
249
|
+
supportedTransactionVersions,
|
|
250
|
+
sendTransaction: vi.fn().mockResolvedValue('sig')
|
|
251
|
+
}) as unknown as ExtendedStandardWalletAdapter
|
|
252
|
+
|
|
253
|
+
const bridgedAdapter = (supportedTransactionVersions: unknown) =>
|
|
254
|
+
({
|
|
255
|
+
publicKey: { toBase58: vi.fn().mockResolvedValue(nativeRequest.from) },
|
|
256
|
+
supportedTransactionVersions: Promise.resolve(
|
|
257
|
+
supportedTransactionVersions
|
|
258
|
+
),
|
|
259
|
+
sendSerializedTransaction: vi.fn().mockResolvedValue('sig'),
|
|
260
|
+
sendTransaction: vi.fn()
|
|
261
|
+
}) as unknown as ExtendedStandardWalletAdapter
|
|
262
|
+
|
|
263
|
+
const sentTransaction = (adapter: ExtendedStandardWalletAdapter) =>
|
|
264
|
+
vi.mocked(adapter.sendTransaction).mock.calls[0]![0]
|
|
265
|
+
|
|
266
|
+
it.each(requests)(
|
|
267
|
+
'%s: sends legacy when the request does not opt in, even if the wallet supports V0',
|
|
268
|
+
async (_, request) => {
|
|
269
|
+
const adapter = directAdapter(supportsV0)
|
|
270
|
+
|
|
271
|
+
await service.sendTransaction(request, adapter, networkId)
|
|
272
|
+
|
|
273
|
+
expect(sentTransaction(adapter)).toBeInstanceOf(Transaction)
|
|
274
|
+
expect(mockGetVersionedTransaction).not.toHaveBeenCalled()
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
it.each(requests)(
|
|
279
|
+
'%s: sends V0 when the request opts in and the wallet supports V0',
|
|
280
|
+
async (_, request) => {
|
|
281
|
+
const adapter = directAdapter(supportsV0)
|
|
282
|
+
const optedIn = { ...request, preferVersionedTransaction: true }
|
|
283
|
+
|
|
284
|
+
await service.sendTransaction(optedIn, adapter, networkId)
|
|
285
|
+
|
|
286
|
+
expect(sentTransaction(adapter)).toBe(v0Transaction)
|
|
287
|
+
expect(mockGetVersionedTransaction).toHaveBeenCalledWith(
|
|
288
|
+
expect.objectContaining({ toBase58: expect.any(Function) }),
|
|
289
|
+
optedIn
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
it.each([
|
|
295
|
+
['null (legacy-only Wallet Standard wallet)', null],
|
|
296
|
+
['legacy only', new Set(['legacy'])],
|
|
297
|
+
['undefined', undefined]
|
|
298
|
+
])(
|
|
299
|
+
'falls back to legacy when the wallet declares %s',
|
|
300
|
+
async (_, versions) => {
|
|
301
|
+
const adapter = directAdapter(versions)
|
|
302
|
+
|
|
303
|
+
await service.sendTransaction(
|
|
304
|
+
{ ...nativeRequest, preferVersionedTransaction: true },
|
|
305
|
+
adapter,
|
|
306
|
+
networkId
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
expect(sentTransaction(adapter)).toBeInstanceOf(Transaction)
|
|
310
|
+
expect(mockGetVersionedTransaction).not.toHaveBeenCalled()
|
|
311
|
+
}
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
it.each(requests)(
|
|
315
|
+
'%s: bridged adapter (Comlink promise) sends V0 bytes when supported',
|
|
316
|
+
async (_, request) => {
|
|
317
|
+
const adapter = bridgedAdapter(supportsV0)
|
|
318
|
+
|
|
319
|
+
await service.sendTransaction(
|
|
320
|
+
{ ...request, preferVersionedTransaction: true },
|
|
321
|
+
adapter,
|
|
322
|
+
networkId
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
expect(adapter.sendSerializedTransaction).toHaveBeenCalledWith(
|
|
326
|
+
v0Bytes,
|
|
327
|
+
expect.any(String)
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
it('bridged adapter (Comlink promise) sends legacy bytes when V0 is not supported', async () => {
|
|
333
|
+
const adapter = bridgedAdapter(null)
|
|
334
|
+
|
|
335
|
+
await service.sendTransaction(
|
|
336
|
+
{ ...nativeRequest, preferVersionedTransaction: true },
|
|
337
|
+
adapter,
|
|
338
|
+
networkId
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
expect(adapter.sendSerializedTransaction).toHaveBeenCalledWith(
|
|
342
|
+
legacyBytes,
|
|
343
|
+
expect.any(String)
|
|
344
|
+
)
|
|
345
|
+
expect(mockGetVersionedTransaction).not.toHaveBeenCalled()
|
|
346
|
+
})
|
|
347
|
+
})
|
|
214
348
|
})
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Connection,
|
|
5
5
|
PublicKey
|
|
6
6
|
} from '@solana/web3.js'
|
|
7
|
+
import { isVersionedTransaction } from '@solana/wallet-adapter-base'
|
|
7
8
|
import type {
|
|
8
9
|
SolanaNativeTransferRequest,
|
|
9
10
|
NetworkRpcMap,
|
|
@@ -90,6 +91,33 @@ export class SolanaTransactionService {
|
|
|
90
91
|
: 'https://api.mainnet-beta.solana.com'
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Helper: Whether the wallet declares V0 support. A bridged adapter is a
|
|
96
|
+
* Comlink proxy whose property reads return a Promise (its `.has` would
|
|
97
|
+
* always look truthy), so the value is always resolved first.
|
|
98
|
+
*/
|
|
99
|
+
private async supportsVersionedTransactions(
|
|
100
|
+
adapter: SolanaAdapter
|
|
101
|
+
): Promise<boolean> {
|
|
102
|
+
const versions = await Promise.resolve(adapter.supportedTransactionVersions)
|
|
103
|
+
return versions?.has(0) ?? false
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Helper: Serialize for the bridge path. Legacy skips signature checks
|
|
108
|
+
* because the wallet has not signed yet.
|
|
109
|
+
*/
|
|
110
|
+
private serializeTransaction(
|
|
111
|
+
transaction: Transaction | VersionedTransaction
|
|
112
|
+
): Uint8Array {
|
|
113
|
+
return isVersionedTransaction(transaction)
|
|
114
|
+
? transaction.serialize()
|
|
115
|
+
: transaction.serialize({
|
|
116
|
+
requireAllSignatures: false,
|
|
117
|
+
verifySignatures: false
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
93
121
|
/**
|
|
94
122
|
* Two mutually exclusive paths:
|
|
95
123
|
* 1. sendSerializedTransaction(Uint8Array, string) — Comlink bridge safe.
|
|
@@ -139,25 +167,13 @@ export class SolanaTransactionService {
|
|
|
139
167
|
throw new Error('Blockhash is required for Solana transactions')
|
|
140
168
|
}
|
|
141
169
|
|
|
142
|
-
|
|
143
|
-
const transaction = new Transaction()
|
|
144
|
-
transaction.instructions =
|
|
145
|
-
await this.builder.buildTransferInstructions(request)
|
|
146
|
-
|
|
147
|
-
transaction.recentBlockhash = request.blockhash
|
|
148
|
-
transaction.feePayer = new PublicKey(request.from)
|
|
149
|
-
|
|
150
|
-
const rpcUrl = this.getRpcUrl(networkId)
|
|
151
|
-
const serializedTx = transaction.serialize({
|
|
152
|
-
requireAllSignatures: false,
|
|
153
|
-
verifySignatures: false
|
|
154
|
-
})
|
|
170
|
+
const transaction = await this.buildTransferTransaction(adapter, request)
|
|
155
171
|
|
|
156
172
|
return await this.executeTransaction(
|
|
157
173
|
adapter,
|
|
158
|
-
|
|
174
|
+
this.serializeTransaction(transaction),
|
|
159
175
|
transaction,
|
|
160
|
-
|
|
176
|
+
this.getRpcUrl(networkId)
|
|
161
177
|
)
|
|
162
178
|
} catch (error) {
|
|
163
179
|
parseError(error)
|
|
@@ -181,31 +197,45 @@ export class SolanaTransactionService {
|
|
|
181
197
|
throw new Error('Blockhash is required for Solana transactions')
|
|
182
198
|
}
|
|
183
199
|
|
|
184
|
-
|
|
185
|
-
const transaction = new Transaction()
|
|
186
|
-
transaction.instructions =
|
|
187
|
-
await this.builder.buildTransferInstructions(request)
|
|
188
|
-
|
|
189
|
-
transaction.recentBlockhash = request.blockhash
|
|
190
|
-
transaction.feePayer = new PublicKey(request.from)
|
|
191
|
-
|
|
192
|
-
const rpcUrl = this.getRpcUrl(networkId)
|
|
193
|
-
const serializedTx = transaction.serialize({
|
|
194
|
-
requireAllSignatures: false,
|
|
195
|
-
verifySignatures: false
|
|
196
|
-
})
|
|
200
|
+
const transaction = await this.buildTransferTransaction(adapter, request)
|
|
197
201
|
|
|
198
202
|
return await this.executeTransaction(
|
|
199
203
|
adapter,
|
|
200
|
-
|
|
204
|
+
this.serializeTransaction(transaction),
|
|
201
205
|
transaction,
|
|
202
|
-
|
|
206
|
+
this.getRpcUrl(networkId)
|
|
203
207
|
)
|
|
204
208
|
} catch (error) {
|
|
205
209
|
parseError(error)
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Legacy by default. V0 only when the request opts in and the wallet
|
|
215
|
+
* declares V0 support: Trust's mobile in-app provider cannot sign a legacy
|
|
216
|
+
* transaction delivered through the Wallet Standard, but signs V0.
|
|
217
|
+
*/
|
|
218
|
+
private async buildTransferTransaction(
|
|
219
|
+
adapter: SolanaAdapter,
|
|
220
|
+
request: SolanaNativeTransferRequest | SolanaTokenTransferRequest
|
|
221
|
+
): Promise<Transaction | VersionedTransaction> {
|
|
222
|
+
const feePayer = new PublicKey(request.from)
|
|
223
|
+
|
|
224
|
+
if (
|
|
225
|
+
request.preferVersionedTransaction &&
|
|
226
|
+
(await this.supportsVersionedTransactions(adapter))
|
|
227
|
+
) {
|
|
228
|
+
return this.builder.getVersionedTransaction(feePayer, request)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const transaction = new Transaction()
|
|
232
|
+
transaction.instructions =
|
|
233
|
+
await this.builder.buildTransferInstructions(request)
|
|
234
|
+
transaction.recentBlockhash = request.blockhash
|
|
235
|
+
transaction.feePayer = feePayer
|
|
236
|
+
return transaction
|
|
237
|
+
}
|
|
238
|
+
|
|
209
239
|
/**
|
|
210
240
|
* Send native SOL transfer
|
|
211
241
|
*/
|