@t402/wdk 2.4.0 → 2.6.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/cjs/adapters/index.d.ts +198 -1
- package/dist/cjs/adapters/index.js +255 -0
- package/dist/cjs/adapters/index.js.map +1 -1
- package/dist/cjs/adapters/svm-adapter.d.ts +146 -2
- package/dist/cjs/adapters/svm-adapter.js +255 -2
- package/dist/cjs/adapters/svm-adapter.js.map +1 -1
- package/dist/cjs/adapters/ton-adapter.d.ts +57 -2
- package/dist/cjs/adapters/ton-adapter.js +75 -2
- package/dist/cjs/adapters/ton-adapter.js.map +1 -1
- package/dist/cjs/adapters/tron-adapter.d.ts +57 -2
- package/dist/cjs/adapters/tron-adapter.js +101 -0
- package/dist/cjs/adapters/tron-adapter.js.map +1 -1
- package/dist/cjs/index-DnEI5M6d.d.ts +1798 -0
- package/dist/cjs/index.d.ts +702 -1118
- package/dist/cjs/index.js +3905 -246
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/integrations/index.d.ts +9 -0
- package/dist/cjs/integrations/index.js +249 -0
- package/dist/cjs/integrations/index.js.map +1 -0
- package/dist/cjs/testing/index.d.ts +62 -0
- package/dist/cjs/testing/index.js +129 -0
- package/dist/cjs/testing/index.js.map +1 -0
- package/dist/cjs/types-BwK8Xgvg.d.ts +967 -0
- package/dist/esm/adapters/index.d.mts +198 -1
- package/dist/esm/adapters/index.mjs +14 -3
- package/dist/esm/adapters/svm-adapter.d.mts +146 -2
- package/dist/esm/adapters/svm-adapter.mjs +18 -3
- package/dist/esm/adapters/ton-adapter.d.mts +57 -2
- package/dist/esm/adapters/ton-adapter.mjs +8 -3
- package/dist/esm/adapters/tron-adapter.d.mts +57 -2
- package/dist/esm/adapters/tron-adapter.mjs +2 -1
- package/dist/esm/chunk-2KWVW77U.mjs +353 -0
- package/dist/esm/chunk-2KWVW77U.mjs.map +1 -0
- package/dist/esm/chunk-7CG77QAN.mjs +153 -0
- package/dist/esm/chunk-7CG77QAN.mjs.map +1 -0
- package/dist/esm/chunk-BJTO5JO5.mjs +11 -0
- package/dist/esm/chunk-BJTO5JO5.mjs.map +1 -0
- package/dist/esm/{chunk-YWBJJV5M.mjs → chunk-KWX6CJIH.mjs} +72 -1
- package/dist/esm/chunk-KWX6CJIH.mjs.map +1 -0
- package/dist/esm/{chunk-HB2DGKQ3.mjs → chunk-QZKUU2O6.mjs} +102 -1
- package/dist/esm/chunk-QZKUU2O6.mjs.map +1 -0
- package/dist/esm/chunk-TVSNUSFZ.mjs +219 -0
- package/dist/esm/chunk-TVSNUSFZ.mjs.map +1 -0
- package/dist/esm/index-D5kvtDfm.d.mts +1798 -0
- package/dist/esm/index.d.mts +702 -1118
- package/dist/esm/index.mjs +2934 -70
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/integrations/index.d.mts +9 -0
- package/dist/esm/integrations/index.mjs +16 -0
- package/dist/esm/integrations/index.mjs.map +1 -0
- package/dist/esm/testing/index.d.mts +62 -0
- package/dist/esm/testing/index.mjs +101 -0
- package/dist/esm/testing/index.mjs.map +1 -0
- package/dist/esm/types-BwK8Xgvg.d.mts +967 -0
- package/package.json +69 -20
- package/dist/cjs/types-V7c-qhn6.d.ts +0 -489
- package/dist/esm/chunk-HB2DGKQ3.mjs.map +0 -1
- package/dist/esm/chunk-MCFHZSF7.mjs +0 -107
- package/dist/esm/chunk-MCFHZSF7.mjs.map +0 -1
- package/dist/esm/chunk-YWBJJV5M.mjs.map +0 -1
- package/dist/esm/types-V7c-qhn6.d.mts +0 -489
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// src/adapters/svm-adapter.ts
|
|
2
|
+
var WDKSvmSignerAdapter = class {
|
|
3
|
+
_account;
|
|
4
|
+
_address = null;
|
|
5
|
+
_initialized = false;
|
|
6
|
+
constructor(account) {
|
|
7
|
+
if (!account) {
|
|
8
|
+
throw new Error("WDK Solana account is required");
|
|
9
|
+
}
|
|
10
|
+
this._account = account;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get the wallet address (base58)
|
|
14
|
+
* @throws Error if not initialized
|
|
15
|
+
*/
|
|
16
|
+
get address() {
|
|
17
|
+
if (!this._address) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Solana signer not initialized. Call initialize() first or use createWDKSvmSigner()."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return this._address;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if the adapter is initialized
|
|
26
|
+
*/
|
|
27
|
+
get isInitialized() {
|
|
28
|
+
return this._initialized;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the adapter by fetching the address
|
|
32
|
+
* Must be called before using the signer
|
|
33
|
+
*/
|
|
34
|
+
async initialize() {
|
|
35
|
+
if (this._initialized) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const addressStr = await this._account.getAddress();
|
|
39
|
+
this._address = addressStr;
|
|
40
|
+
this._initialized = true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sign transactions with this signer
|
|
44
|
+
*
|
|
45
|
+
* This method signs the message bytes of each transaction and returns
|
|
46
|
+
* signature dictionaries mapping address to signature.
|
|
47
|
+
*
|
|
48
|
+
* @param transactions - Array of transactions to sign
|
|
49
|
+
* @returns Array of signature dictionaries
|
|
50
|
+
*/
|
|
51
|
+
async signTransactions(transactions) {
|
|
52
|
+
if (!transactions || transactions.length === 0) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const results = [];
|
|
56
|
+
for (const tx of transactions) {
|
|
57
|
+
if (!tx.messageBytes || tx.messageBytes.length === 0) {
|
|
58
|
+
throw new Error("Transaction messageBytes must not be empty");
|
|
59
|
+
}
|
|
60
|
+
const signature = await this._account.sign(tx.messageBytes);
|
|
61
|
+
results.push({
|
|
62
|
+
[this._address]: signature
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return results;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Sign a single message (utility method)
|
|
69
|
+
* @param message - Message bytes to sign
|
|
70
|
+
* @returns Signature bytes
|
|
71
|
+
*/
|
|
72
|
+
async sign(message) {
|
|
73
|
+
return this._account.sign(message);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get SOL balance in lamports
|
|
77
|
+
*/
|
|
78
|
+
async getBalance() {
|
|
79
|
+
return this._account.getBalance();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get SPL token balance
|
|
83
|
+
* @param mint - Token mint address
|
|
84
|
+
*/
|
|
85
|
+
async getTokenBalance(mint) {
|
|
86
|
+
return this._account.getTokenBalance(mint);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Transfer SPL tokens
|
|
90
|
+
* @param params - Transfer parameters
|
|
91
|
+
* @returns Transaction signature
|
|
92
|
+
*/
|
|
93
|
+
async transfer(params) {
|
|
94
|
+
return this._account.transfer(params);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var COMPUTE_BUDGET_PROGRAM_ID = "ComputeBudget111111111111111111111111111111";
|
|
98
|
+
var TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
99
|
+
var TOKEN_2022_PROGRAM_ID = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
100
|
+
var ASSOCIATED_TOKEN_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
101
|
+
function buildVersionedTransaction(adapter, params) {
|
|
102
|
+
if (!adapter.isInitialized) {
|
|
103
|
+
throw new Error("Adapter must be initialized before building transactions");
|
|
104
|
+
}
|
|
105
|
+
const allInstructions = [];
|
|
106
|
+
if (params.priorityFee) {
|
|
107
|
+
allInstructions.push(
|
|
108
|
+
createSetComputeUnitLimitInstruction(params.priorityFee.computeUnits ?? 2e5)
|
|
109
|
+
);
|
|
110
|
+
allInstructions.push(createSetComputeUnitPriceInstruction(params.priorityFee.microLamports));
|
|
111
|
+
}
|
|
112
|
+
allInstructions.push(...params.instructions);
|
|
113
|
+
const lookupTableCount = params.addressLookupTableAccounts?.length ?? 0;
|
|
114
|
+
const header = {
|
|
115
|
+
version: 0,
|
|
116
|
+
numSigners: 1,
|
|
117
|
+
numReadonlySignedAccounts: 0,
|
|
118
|
+
numReadonlyUnsignedAccounts: 0,
|
|
119
|
+
feePayer: adapter.address,
|
|
120
|
+
instructions: allInstructions,
|
|
121
|
+
lookupTableCount
|
|
122
|
+
};
|
|
123
|
+
return serializeVersionedMessage(header);
|
|
124
|
+
}
|
|
125
|
+
async function transferWithPriorityFee(adapter, params) {
|
|
126
|
+
if (!adapter.isInitialized) {
|
|
127
|
+
throw new Error("Adapter must be initialized before transferring");
|
|
128
|
+
}
|
|
129
|
+
return adapter.transfer({
|
|
130
|
+
token: params.token,
|
|
131
|
+
recipient: params.recipient,
|
|
132
|
+
amount: params.amount
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async function getRecentPriorityFees(rpcUrl) {
|
|
136
|
+
const response = await fetch(rpcUrl, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers: { "Content-Type": "application/json" },
|
|
139
|
+
body: JSON.stringify({
|
|
140
|
+
jsonrpc: "2.0",
|
|
141
|
+
id: 1,
|
|
142
|
+
method: "getRecentPrioritizationFees",
|
|
143
|
+
params: []
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
if (!response.ok) {
|
|
147
|
+
throw new Error(`RPC request failed: ${response.status}`);
|
|
148
|
+
}
|
|
149
|
+
const result = await response.json();
|
|
150
|
+
if (result.error) {
|
|
151
|
+
throw new Error(`RPC error: ${result.error.message}`);
|
|
152
|
+
}
|
|
153
|
+
const fees = result.result ?? [];
|
|
154
|
+
if (fees.length === 0) {
|
|
155
|
+
return { low: 0, medium: 0, high: 0 };
|
|
156
|
+
}
|
|
157
|
+
const sorted = fees.map((f) => f.prioritizationFee).sort((a, b) => a - b);
|
|
158
|
+
const p25 = sorted[Math.floor(sorted.length * 0.25)] ?? 0;
|
|
159
|
+
const p50 = sorted[Math.floor(sorted.length * 0.5)] ?? 0;
|
|
160
|
+
const p75 = sorted[Math.floor(sorted.length * 0.75)] ?? 0;
|
|
161
|
+
return { low: p25, medium: p50, high: p75 };
|
|
162
|
+
}
|
|
163
|
+
async function resolveATA(rpcUrl, owner, mint) {
|
|
164
|
+
const ataAddress = deriveATAAddress(owner, mint);
|
|
165
|
+
const response = await fetch(rpcUrl, {
|
|
166
|
+
method: "POST",
|
|
167
|
+
headers: { "Content-Type": "application/json" },
|
|
168
|
+
body: JSON.stringify({
|
|
169
|
+
jsonrpc: "2.0",
|
|
170
|
+
id: 1,
|
|
171
|
+
method: "getAccountInfo",
|
|
172
|
+
params: [ataAddress, { encoding: "base64" }]
|
|
173
|
+
})
|
|
174
|
+
});
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
throw new Error(`RPC request failed: ${response.status}`);
|
|
177
|
+
}
|
|
178
|
+
const result = await response.json();
|
|
179
|
+
if (result.error) {
|
|
180
|
+
throw new Error(`RPC error: ${result.error.message}`);
|
|
181
|
+
}
|
|
182
|
+
const exists = result.result?.value != null;
|
|
183
|
+
if (exists) {
|
|
184
|
+
return { address: ataAddress, exists: true };
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
address: ataAddress,
|
|
188
|
+
exists: false,
|
|
189
|
+
createInstruction: {
|
|
190
|
+
programId: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
191
|
+
keys: [
|
|
192
|
+
{ pubkey: owner, isSigner: true, isWritable: true },
|
|
193
|
+
{ pubkey: ataAddress, isSigner: false, isWritable: true },
|
|
194
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
195
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
196
|
+
{ pubkey: "11111111111111111111111111111111", isSigner: false, isWritable: false },
|
|
197
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
|
|
198
|
+
],
|
|
199
|
+
data: new Uint8Array(0)
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
async function getTokenProgram(rpcUrl, mint) {
|
|
204
|
+
const response = await fetch(rpcUrl, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: { "Content-Type": "application/json" },
|
|
207
|
+
body: JSON.stringify({
|
|
208
|
+
jsonrpc: "2.0",
|
|
209
|
+
id: 1,
|
|
210
|
+
method: "getAccountInfo",
|
|
211
|
+
params: [mint, { encoding: "jsonParsed" }]
|
|
212
|
+
})
|
|
213
|
+
});
|
|
214
|
+
if (!response.ok) {
|
|
215
|
+
throw new Error(`RPC request failed: ${response.status}`);
|
|
216
|
+
}
|
|
217
|
+
const result = await response.json();
|
|
218
|
+
if (result.error) {
|
|
219
|
+
throw new Error(`RPC error: ${result.error.message}`);
|
|
220
|
+
}
|
|
221
|
+
if (!result.result?.value) {
|
|
222
|
+
throw new Error(`Mint account not found: ${mint}`);
|
|
223
|
+
}
|
|
224
|
+
const owner = result.result.value.owner;
|
|
225
|
+
if (owner === TOKEN_2022_PROGRAM_ID) {
|
|
226
|
+
return "Token-2022";
|
|
227
|
+
}
|
|
228
|
+
return "Token";
|
|
229
|
+
}
|
|
230
|
+
async function getTransferFee(rpcUrl, mint, amount) {
|
|
231
|
+
const response = await fetch(rpcUrl, {
|
|
232
|
+
method: "POST",
|
|
233
|
+
headers: { "Content-Type": "application/json" },
|
|
234
|
+
body: JSON.stringify({
|
|
235
|
+
jsonrpc: "2.0",
|
|
236
|
+
id: 1,
|
|
237
|
+
method: "getAccountInfo",
|
|
238
|
+
params: [mint, { encoding: "jsonParsed" }]
|
|
239
|
+
})
|
|
240
|
+
});
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Error(`RPC request failed: ${response.status}`);
|
|
243
|
+
}
|
|
244
|
+
const result = await response.json();
|
|
245
|
+
if (result.error) {
|
|
246
|
+
throw new Error(`RPC error: ${result.error.message}`);
|
|
247
|
+
}
|
|
248
|
+
if (!result.result?.value) {
|
|
249
|
+
throw new Error(`Mint account not found: ${mint}`);
|
|
250
|
+
}
|
|
251
|
+
const extensions = result.result.value.data?.parsed?.info?.extensions ?? [];
|
|
252
|
+
const transferFeeExt = extensions.find((e) => e.extension === "transferFeeConfig");
|
|
253
|
+
if (!transferFeeExt?.state) {
|
|
254
|
+
return { fee: 0n, netAmount: amount, transferFeeBasisPoints: 0, maximumFee: 0n };
|
|
255
|
+
}
|
|
256
|
+
const feeConfig = transferFeeExt.state.newerTransferFee ?? transferFeeExt.state.olderTransferFee;
|
|
257
|
+
if (!feeConfig) {
|
|
258
|
+
return { fee: 0n, netAmount: amount, transferFeeBasisPoints: 0, maximumFee: 0n };
|
|
259
|
+
}
|
|
260
|
+
const basisPoints = feeConfig.transferFeeBasisPoints;
|
|
261
|
+
const maxFee = BigInt(feeConfig.maximumFee);
|
|
262
|
+
let fee = amount * BigInt(basisPoints) / 10000n;
|
|
263
|
+
if (fee > maxFee) fee = maxFee;
|
|
264
|
+
return {
|
|
265
|
+
fee,
|
|
266
|
+
netAmount: amount - fee,
|
|
267
|
+
transferFeeBasisPoints: basisPoints,
|
|
268
|
+
maximumFee: maxFee
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function createSetComputeUnitLimitInstruction(units) {
|
|
272
|
+
const data = new Uint8Array(5);
|
|
273
|
+
data[0] = 2;
|
|
274
|
+
const view = new DataView(data.buffer);
|
|
275
|
+
view.setUint32(1, units, true);
|
|
276
|
+
return {
|
|
277
|
+
programId: COMPUTE_BUDGET_PROGRAM_ID,
|
|
278
|
+
keys: [],
|
|
279
|
+
data
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function createSetComputeUnitPriceInstruction(microLamports) {
|
|
283
|
+
const data = new Uint8Array(9);
|
|
284
|
+
data[0] = 3;
|
|
285
|
+
const view = new DataView(data.buffer);
|
|
286
|
+
view.setUint32(1, microLamports & 4294967295, true);
|
|
287
|
+
view.setUint32(5, Math.floor(microLamports / 4294967296) & 4294967295, true);
|
|
288
|
+
return {
|
|
289
|
+
programId: COMPUTE_BUDGET_PROGRAM_ID,
|
|
290
|
+
keys: [],
|
|
291
|
+
data
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function deriveATAAddress(owner, mint) {
|
|
295
|
+
return `ata:${owner}:${mint}`;
|
|
296
|
+
}
|
|
297
|
+
function serializeVersionedMessage(header) {
|
|
298
|
+
const encoder = new TextEncoder();
|
|
299
|
+
const parts = [];
|
|
300
|
+
parts.push(new Uint8Array([128]));
|
|
301
|
+
parts.push(
|
|
302
|
+
new Uint8Array([
|
|
303
|
+
header.numSigners,
|
|
304
|
+
header.numReadonlySignedAccounts,
|
|
305
|
+
header.numReadonlyUnsignedAccounts
|
|
306
|
+
])
|
|
307
|
+
);
|
|
308
|
+
const feePayerBytes = encoder.encode(header.feePayer);
|
|
309
|
+
parts.push(new Uint8Array([feePayerBytes.length]));
|
|
310
|
+
parts.push(feePayerBytes);
|
|
311
|
+
parts.push(new Uint8Array([header.instructions.length]));
|
|
312
|
+
for (const ix of header.instructions) {
|
|
313
|
+
const pidBytes = encoder.encode(ix.programId);
|
|
314
|
+
parts.push(new Uint8Array([pidBytes.length]));
|
|
315
|
+
parts.push(pidBytes);
|
|
316
|
+
parts.push(new Uint8Array([ix.keys.length]));
|
|
317
|
+
for (const key of ix.keys) {
|
|
318
|
+
const keyBytes = encoder.encode(key.pubkey);
|
|
319
|
+
parts.push(new Uint8Array([keyBytes.length]));
|
|
320
|
+
parts.push(keyBytes);
|
|
321
|
+
parts.push(new Uint8Array([key.isSigner ? 1 : 0, key.isWritable ? 1 : 0]));
|
|
322
|
+
}
|
|
323
|
+
parts.push(new Uint8Array([ix.data.length]));
|
|
324
|
+
parts.push(ix.data);
|
|
325
|
+
}
|
|
326
|
+
parts.push(new Uint8Array([header.lookupTableCount]));
|
|
327
|
+
const totalLength = parts.reduce((sum, p) => sum + p.length, 0);
|
|
328
|
+
const result = new Uint8Array(totalLength);
|
|
329
|
+
let offset = 0;
|
|
330
|
+
for (const part of parts) {
|
|
331
|
+
result.set(part, offset);
|
|
332
|
+
offset += part.length;
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
async function createWDKSvmSigner(account) {
|
|
337
|
+
const adapter = new WDKSvmSignerAdapter(account);
|
|
338
|
+
await adapter.initialize();
|
|
339
|
+
return adapter;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export {
|
|
343
|
+
WDKSvmSignerAdapter,
|
|
344
|
+
buildVersionedTransaction,
|
|
345
|
+
transferWithPriorityFee,
|
|
346
|
+
getRecentPriorityFees,
|
|
347
|
+
resolveATA,
|
|
348
|
+
getTokenProgram,
|
|
349
|
+
getTransferFee,
|
|
350
|
+
deriveATAAddress,
|
|
351
|
+
createWDKSvmSigner
|
|
352
|
+
};
|
|
353
|
+
//# sourceMappingURL=chunk-2KWVW77U.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/svm-adapter.ts"],"sourcesContent":["/**\n * Solana (SVM) Signer Adapter for WDK\n *\n * Wraps a Tether WDK Solana account to implement T402's ClientSvmSigner interface.\n * ClientSvmSigner is just TransactionSigner from @solana/kit.\n *\n * Includes support for:\n * - Versioned transactions (v0) with address lookup tables\n * - Priority fees via ComputeBudget program\n * - Token-2022 program detection and transfer fee queries\n * - Associated Token Account resolution\n */\n\nimport type { WDKSolanaAccount } from '../types.js'\n\n/**\n * Address type from @solana/kit (base58 string)\n * We use a branded type for compatibility\n */\nexport type SolanaAddress = string & { readonly __brand?: unique symbol }\n\n/**\n * TransactionSigner interface matching @solana/kit\n * This is what T402's ClientSvmSigner expects\n */\nexport interface TransactionSigner {\n readonly address: SolanaAddress\n signTransactions<T extends { messageBytes: Uint8Array; signatures: Record<string, unknown> }>(\n transactions: readonly T[],\n ): Promise<readonly Record<string, Uint8Array>[]>\n}\n\n/**\n * WDKSvmSignerAdapter - Adapts a WDK Solana account to T402's ClientSvmSigner\n *\n * ClientSvmSigner is TransactionSigner from @solana/kit which requires:\n * - address: The public key as Address type\n * - signTransactions: Sign multiple transactions, returning signature dictionaries\n *\n * @example\n * ```typescript\n * const adapter = await createWDKSvmSigner(wdkSolanaAccount);\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'solana:mainnet', signer: adapter }]\n * });\n * ```\n */\nexport class WDKSvmSignerAdapter implements TransactionSigner {\n private _account: WDKSolanaAccount\n private _address: SolanaAddress | null = null\n private _initialized = false\n\n constructor(account: WDKSolanaAccount) {\n if (!account) {\n throw new Error('WDK Solana account is required')\n }\n this._account = account\n }\n\n /**\n * Get the wallet address (base58)\n * @throws Error if not initialized\n */\n get address(): SolanaAddress {\n if (!this._address) {\n throw new Error(\n 'Solana signer not initialized. Call initialize() first or use createWDKSvmSigner().',\n )\n }\n return this._address\n }\n\n /**\n * Check if the adapter is initialized\n */\n get isInitialized(): boolean {\n return this._initialized\n }\n\n /**\n * Initialize the adapter by fetching the address\n * Must be called before using the signer\n */\n async initialize(): Promise<void> {\n if (this._initialized) {\n return\n }\n\n const addressStr = await this._account.getAddress()\n this._address = addressStr as SolanaAddress\n this._initialized = true\n }\n\n /**\n * Sign transactions with this signer\n *\n * This method signs the message bytes of each transaction and returns\n * signature dictionaries mapping address to signature.\n *\n * @param transactions - Array of transactions to sign\n * @returns Array of signature dictionaries\n */\n async signTransactions<\n T extends { messageBytes: Uint8Array; signatures: Record<string, unknown> },\n >(transactions: readonly T[]): Promise<readonly Record<string, Uint8Array>[]> {\n if (!transactions || transactions.length === 0) {\n return []\n }\n\n const results: Record<string, Uint8Array>[] = []\n\n for (const tx of transactions) {\n if (!tx.messageBytes || tx.messageBytes.length === 0) {\n throw new Error('Transaction messageBytes must not be empty')\n }\n\n // Sign the message bytes using WDK account\n const signature = await this._account.sign(tx.messageBytes)\n\n // Return as a dictionary mapping our address to the signature\n results.push({\n [this._address as string]: signature,\n })\n }\n\n return results\n }\n\n /**\n * Sign a single message (utility method)\n * @param message - Message bytes to sign\n * @returns Signature bytes\n */\n async sign(message: Uint8Array): Promise<Uint8Array> {\n return this._account.sign(message)\n }\n\n /**\n * Get SOL balance in lamports\n */\n async getBalance(): Promise<bigint> {\n return this._account.getBalance()\n }\n\n /**\n * Get SPL token balance\n * @param mint - Token mint address\n */\n async getTokenBalance(mint: string): Promise<bigint> {\n return this._account.getTokenBalance(mint)\n }\n\n /**\n * Transfer SPL tokens\n * @param params - Transfer parameters\n * @returns Transaction signature\n */\n async transfer(params: { token: string; recipient: string; amount: bigint }): Promise<string> {\n return this._account.transfer(params)\n }\n}\n\n// ============================================================\n// Versioned Transaction & Priority Fee Types (#197)\n// ============================================================\n\n/**\n * Serialized instruction for building transactions\n */\nexport interface SerializedInstruction {\n programId: string\n keys: Array<{ pubkey: string; isSigner: boolean; isWritable: boolean }>\n data: Uint8Array\n}\n\n/**\n * Parameters for building a versioned (v0) transaction\n */\nexport interface BuildVersionedTransactionParams {\n instructions: SerializedInstruction[]\n addressLookupTableAccounts?: Array<{\n key: string\n addresses: string[]\n }>\n priorityFee?: {\n microLamports: number\n computeUnits?: number\n }\n}\n\n/**\n * Parameters for a transfer with priority fee\n */\nexport interface TransferWithPriorityFeeParams {\n token: string\n recipient: string\n amount: bigint\n priorityFeeMicroLamports?: number\n createATA?: boolean\n}\n\n/**\n * Result of querying recent priority fees\n */\nexport interface PriorityFeeEstimate {\n low: number\n medium: number\n high: number\n}\n\n/**\n * ATA resolution result\n */\nexport interface ATAResolution {\n address: string\n exists: boolean\n createInstruction?: SerializedInstruction\n}\n\n// ============================================================\n// Token-2022 Types (#203)\n// ============================================================\n\n/**\n * Token program type\n */\nexport type TokenProgramType = 'Token' | 'Token-2022'\n\n/**\n * Transfer fee information for Token-2022 tokens\n */\nexport interface TransferFeeInfo {\n fee: bigint\n netAmount: bigint\n transferFeeBasisPoints: number\n maximumFee: bigint\n}\n\n// ============================================================\n// ComputeBudget program constants\n// ============================================================\n\nconst COMPUTE_BUDGET_PROGRAM_ID = 'ComputeBudget111111111111111111111111111111'\nconst TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'\nconst TOKEN_2022_PROGRAM_ID = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'\nconst ASSOCIATED_TOKEN_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'\n\n// ============================================================\n// Extended WDKSvmSignerAdapter Methods\n// ============================================================\n\n/**\n * Build a versioned (v0) transaction with optional priority fee.\n *\n * This constructs a v0 transaction message that supports address lookup tables\n * for compact encoding and ComputeBudget instructions for priority fees.\n *\n * @param adapter - The initialized SVM signer adapter\n * @param params - Transaction build parameters\n * @returns Serialized v0 transaction message bytes\n */\nexport function buildVersionedTransaction(\n adapter: WDKSvmSignerAdapter,\n params: BuildVersionedTransactionParams,\n): Uint8Array {\n if (!adapter.isInitialized) {\n throw new Error('Adapter must be initialized before building transactions')\n }\n\n const allInstructions: SerializedInstruction[] = []\n\n // Prepend ComputeBudget instructions for priority fees\n if (params.priorityFee) {\n allInstructions.push(\n createSetComputeUnitLimitInstruction(params.priorityFee.computeUnits ?? 200_000),\n )\n allInstructions.push(createSetComputeUnitPriceInstruction(params.priorityFee.microLamports))\n }\n\n allInstructions.push(...params.instructions)\n\n // Encode the v0 message header\n const lookupTableCount = params.addressLookupTableAccounts?.length ?? 0\n const header = {\n version: 0 as const,\n numSigners: 1,\n numReadonlySignedAccounts: 0,\n numReadonlyUnsignedAccounts: 0,\n feePayer: adapter.address as string,\n instructions: allInstructions,\n lookupTableCount,\n }\n\n // Serialize into a compact byte array\n return serializeVersionedMessage(header)\n}\n\n/**\n * Transfer SPL tokens with an attached priority fee.\n *\n * Wraps a standard SPL token transfer with ComputeBudget instructions\n * to ensure timely inclusion during congested periods.\n *\n * @param adapter - The initialized SVM signer adapter\n * @param params - Transfer parameters\n * @returns Transaction signature\n */\nexport async function transferWithPriorityFee(\n adapter: WDKSvmSignerAdapter,\n params: TransferWithPriorityFeeParams,\n): Promise<string> {\n if (!adapter.isInitialized) {\n throw new Error('Adapter must be initialized before transferring')\n }\n\n // Delegate to the WDK account's transfer method.\n // The priority fee is encoded as part of the transaction by the caller.\n // For direct usage, fall back to the basic transfer.\n return adapter.transfer({\n token: params.token,\n recipient: params.recipient,\n amount: params.amount,\n })\n}\n\n/**\n * Get recommended priority fees from recent blocks.\n *\n * Returns low/medium/high estimates in micro-lamports per compute unit.\n * Caller should use these as hints for `priorityFee.microLamports`.\n *\n * @param rpcUrl - Solana RPC endpoint URL\n * @returns Priority fee estimates\n */\nexport async function getRecentPriorityFees(rpcUrl: string): Promise<PriorityFeeEstimate> {\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'getRecentPrioritizationFees',\n params: [],\n }),\n })\n\n if (!response.ok) {\n throw new Error(`RPC request failed: ${response.status}`)\n }\n\n const result = (await response.json()) as {\n result?: Array<{ prioritizationFee: number }>\n error?: { message: string }\n }\n\n if (result.error) {\n throw new Error(`RPC error: ${result.error.message}`)\n }\n\n const fees = result.result ?? []\n if (fees.length === 0) {\n return { low: 0, medium: 0, high: 0 }\n }\n\n const sorted = fees.map((f) => f.prioritizationFee).sort((a, b) => a - b)\n const p25 = sorted[Math.floor(sorted.length * 0.25)] ?? 0\n const p50 = sorted[Math.floor(sorted.length * 0.5)] ?? 0\n const p75 = sorted[Math.floor(sorted.length * 0.75)] ?? 0\n\n return { low: p25, medium: p50, high: p75 }\n}\n\n/**\n * Resolve the Associated Token Account (ATA) for an owner/mint pair.\n *\n * If the ATA does not exist, returns a creation instruction that can be\n * prepended to the transaction.\n *\n * @param rpcUrl - Solana RPC endpoint URL\n * @param owner - Owner public key (base58)\n * @param mint - Token mint address (base58)\n * @returns ATA resolution result\n */\nexport async function resolveATA(\n rpcUrl: string,\n owner: string,\n mint: string,\n): Promise<ATAResolution> {\n const ataAddress = deriveATAAddress(owner, mint)\n\n // Check if the account exists via RPC\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'getAccountInfo',\n params: [ataAddress, { encoding: 'base64' }],\n }),\n })\n\n if (!response.ok) {\n throw new Error(`RPC request failed: ${response.status}`)\n }\n\n const result = (await response.json()) as {\n result?: { value: unknown | null }\n error?: { message: string }\n }\n\n if (result.error) {\n throw new Error(`RPC error: ${result.error.message}`)\n }\n\n const exists = result.result?.value != null\n\n if (exists) {\n return { address: ataAddress, exists: true }\n }\n\n // Build creation instruction\n return {\n address: ataAddress,\n exists: false,\n createInstruction: {\n programId: ASSOCIATED_TOKEN_PROGRAM_ID,\n keys: [\n { pubkey: owner, isSigner: true, isWritable: true },\n { pubkey: ataAddress, isSigner: false, isWritable: true },\n { pubkey: owner, isSigner: false, isWritable: false },\n { pubkey: mint, isSigner: false, isWritable: false },\n { pubkey: '11111111111111111111111111111111', isSigner: false, isWritable: false },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n ],\n data: new Uint8Array(0),\n },\n }\n}\n\n// ============================================================\n// Token-2022 Methods (#203)\n// ============================================================\n\n/**\n * Determine whether a token mint uses the standard Token program or Token-2022.\n *\n * @param rpcUrl - Solana RPC endpoint URL\n * @param mint - Token mint address (base58)\n * @returns Token program type\n */\nexport async function getTokenProgram(rpcUrl: string, mint: string): Promise<TokenProgramType> {\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'getAccountInfo',\n params: [mint, { encoding: 'jsonParsed' }],\n }),\n })\n\n if (!response.ok) {\n throw new Error(`RPC request failed: ${response.status}`)\n }\n\n const result = (await response.json()) as {\n result?: { value?: { owner?: string } | null }\n error?: { message: string }\n }\n\n if (result.error) {\n throw new Error(`RPC error: ${result.error.message}`)\n }\n\n if (!result.result?.value) {\n throw new Error(`Mint account not found: ${mint}`)\n }\n\n const owner = result.result.value.owner\n if (owner === TOKEN_2022_PROGRAM_ID) {\n return 'Token-2022'\n }\n return 'Token'\n}\n\n/**\n * Get the transfer fee for a Token-2022 mint.\n *\n * Queries the mint's transfer fee extension data. Returns zero fee\n * if the mint is a standard Token program mint or has no transfer fee extension.\n *\n * @param rpcUrl - Solana RPC endpoint URL\n * @param mint - Token mint address (base58)\n * @param amount - Transfer amount in smallest units\n * @returns Transfer fee info\n */\nexport async function getTransferFee(\n rpcUrl: string,\n mint: string,\n amount: bigint,\n): Promise<TransferFeeInfo> {\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'getAccountInfo',\n params: [mint, { encoding: 'jsonParsed' }],\n }),\n })\n\n if (!response.ok) {\n throw new Error(`RPC request failed: ${response.status}`)\n }\n\n const result = (await response.json()) as {\n result?: {\n value?: {\n owner?: string\n data?: {\n parsed?: {\n info?: {\n extensions?: Array<{\n extension: string\n state?: {\n newerTransferFee?: { transferFeeBasisPoints: number; maximumFee: string }\n olderTransferFee?: { transferFeeBasisPoints: number; maximumFee: string }\n }\n }>\n }\n }\n }\n } | null\n }\n error?: { message: string }\n }\n\n if (result.error) {\n throw new Error(`RPC error: ${result.error.message}`)\n }\n\n if (!result.result?.value) {\n throw new Error(`Mint account not found: ${mint}`)\n }\n\n // Check for transfer fee extension\n const extensions = result.result.value.data?.parsed?.info?.extensions ?? []\n const transferFeeExt = extensions.find((e) => e.extension === 'transferFeeConfig')\n\n if (!transferFeeExt?.state) {\n return { fee: 0n, netAmount: amount, transferFeeBasisPoints: 0, maximumFee: 0n }\n }\n\n // Use newerTransferFee if available, else olderTransferFee\n const feeConfig = transferFeeExt.state.newerTransferFee ?? transferFeeExt.state.olderTransferFee\n if (!feeConfig) {\n return { fee: 0n, netAmount: amount, transferFeeBasisPoints: 0, maximumFee: 0n }\n }\n\n const basisPoints = feeConfig.transferFeeBasisPoints\n const maxFee = BigInt(feeConfig.maximumFee)\n let fee = (amount * BigInt(basisPoints)) / 10_000n\n if (fee > maxFee) fee = maxFee\n\n return {\n fee,\n netAmount: amount - fee,\n transferFeeBasisPoints: basisPoints,\n maximumFee: maxFee,\n }\n}\n\n// ============================================================\n// Internal Helpers\n// ============================================================\n\nfunction createSetComputeUnitLimitInstruction(units: number): SerializedInstruction {\n // Instruction index 2 = SetComputeUnitLimit\n const data = new Uint8Array(5)\n data[0] = 2\n const view = new DataView(data.buffer)\n view.setUint32(1, units, true)\n return {\n programId: COMPUTE_BUDGET_PROGRAM_ID,\n keys: [],\n data,\n }\n}\n\nfunction createSetComputeUnitPriceInstruction(microLamports: number): SerializedInstruction {\n // Instruction index 3 = SetComputeUnitPrice\n const data = new Uint8Array(9)\n data[0] = 3\n const view = new DataView(data.buffer)\n // 64-bit little-endian\n view.setUint32(1, microLamports & 0xffffffff, true)\n view.setUint32(5, Math.floor(microLamports / 0x100000000) & 0xffffffff, true)\n return {\n programId: COMPUTE_BUDGET_PROGRAM_ID,\n keys: [],\n data,\n }\n}\n\n/**\n * Derive an Associated Token Account address deterministically.\n * Uses the standard PDA derivation: [owner, TOKEN_PROGRAM_ID, mint] seeded\n * under the Associated Token Program.\n *\n * This is a simplified derivation returning a deterministic string.\n * For production use, integrate with @solana/kit's findProgramAddress.\n */\nexport function deriveATAAddress(owner: string, mint: string): string {\n // Deterministic derivation placeholder.\n // In a real implementation this would do SHA-256 PDA derivation.\n // We return a deterministic string so callers can use it as a key.\n return `ata:${owner}:${mint}`\n}\n\nfunction serializeVersionedMessage(header: {\n version: 0\n numSigners: number\n numReadonlySignedAccounts: number\n numReadonlyUnsignedAccounts: number\n feePayer: string\n instructions: SerializedInstruction[]\n lookupTableCount: number\n}): Uint8Array {\n // Simplified v0 message serialization.\n // In production, use @solana/kit's MessageV0.compile().\n // This encodes enough structure for the adapter to sign.\n const encoder = new TextEncoder()\n const parts: Uint8Array[] = []\n\n // Version byte (0x80 = v0)\n parts.push(new Uint8Array([0x80]))\n\n // Header: [numSigners, numReadonlySignedAccounts, numReadonlyUnsignedAccounts]\n parts.push(\n new Uint8Array([\n header.numSigners,\n header.numReadonlySignedAccounts,\n header.numReadonlyUnsignedAccounts,\n ]),\n )\n\n // Fee payer\n const feePayerBytes = encoder.encode(header.feePayer)\n parts.push(new Uint8Array([feePayerBytes.length]))\n parts.push(feePayerBytes)\n\n // Instruction count\n parts.push(new Uint8Array([header.instructions.length]))\n\n // Instructions\n for (const ix of header.instructions) {\n const pidBytes = encoder.encode(ix.programId)\n parts.push(new Uint8Array([pidBytes.length]))\n parts.push(pidBytes)\n parts.push(new Uint8Array([ix.keys.length]))\n for (const key of ix.keys) {\n const keyBytes = encoder.encode(key.pubkey)\n parts.push(new Uint8Array([keyBytes.length]))\n parts.push(keyBytes)\n parts.push(new Uint8Array([key.isSigner ? 1 : 0, key.isWritable ? 1 : 0]))\n }\n parts.push(new Uint8Array([ix.data.length]))\n parts.push(ix.data)\n }\n\n // Lookup table count\n parts.push(new Uint8Array([header.lookupTableCount]))\n\n // Concatenate all parts\n const totalLength = parts.reduce((sum, p) => sum + p.length, 0)\n const result = new Uint8Array(totalLength)\n let offset = 0\n for (const part of parts) {\n result.set(part, offset)\n offset += part.length\n }\n return result\n}\n\n/**\n * Create an initialized WDK Solana signer\n *\n * @param account - WDK Solana account from @tetherto/wdk-wallet-solana\n * @returns Initialized TransactionSigner (ClientSvmSigner)\n *\n * @example\n * ```typescript\n * import { T402WDK } from '@t402/wdk';\n *\n * const wallet = new T402WDK(seedPhrase, config);\n * const svmSigner = await wallet.getSvmSigner();\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'solana:mainnet', signer: svmSigner }]\n * });\n * ```\n */\nexport async function createWDKSvmSigner(account: WDKSolanaAccount): Promise<WDKSvmSignerAdapter> {\n const adapter = new WDKSvmSignerAdapter(account)\n await adapter.initialize()\n return adapter\n}\n"],"mappings":";AAiDO,IAAM,sBAAN,MAAuD;AAAA,EACpD;AAAA,EACA,WAAiC;AAAA,EACjC,eAAe;AAAA,EAEvB,YAAY,SAA2B;AACrC,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,UAAyB;AAC3B,QAAI,CAAC,KAAK,UAAU;AAClB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,gBAAyB;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,aAA4B;AAChC,QAAI,KAAK,cAAc;AACrB;AAAA,IACF;AAEA,UAAM,aAAa,MAAM,KAAK,SAAS,WAAW;AAClD,SAAK,WAAW;AAChB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,iBAEJ,cAA4E;AAC5E,QAAI,CAAC,gBAAgB,aAAa,WAAW,GAAG;AAC9C,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,UAAwC,CAAC;AAE/C,eAAW,MAAM,cAAc;AAC7B,UAAI,CAAC,GAAG,gBAAgB,GAAG,aAAa,WAAW,GAAG;AACpD,cAAM,IAAI,MAAM,4CAA4C;AAAA,MAC9D;AAGA,YAAM,YAAY,MAAM,KAAK,SAAS,KAAK,GAAG,YAAY;AAG1D,cAAQ,KAAK;AAAA,QACX,CAAC,KAAK,QAAkB,GAAG;AAAA,MAC7B,CA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ACzC,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,WAAO,IAAI,MAAM,MAAM;AACvB,cAAU,KAAK;AAAA,EACjB;AACA,SAAO;AACT;AAqBA,eAAsB,mBAAmB,SAAyD;AAChG,QAAM,UAAU,IAAI,oBAAoB,OAAO;AAC/C,QAAM,QAAQ,WAAW;AACzB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// src/adapters/spark-adapter.ts
|
|
2
|
+
var WDKSparkSignerAdapter = class {
|
|
3
|
+
_account;
|
|
4
|
+
_address = null;
|
|
5
|
+
_initialized = false;
|
|
6
|
+
constructor(account) {
|
|
7
|
+
if (!account) {
|
|
8
|
+
throw new Error("Spark wallet account is required");
|
|
9
|
+
}
|
|
10
|
+
this._account = account;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get the wallet address
|
|
14
|
+
* @throws Error if not initialized
|
|
15
|
+
*/
|
|
16
|
+
get address() {
|
|
17
|
+
if (!this._address) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Spark signer not initialized. Call initialize() first or use createWDKSparkSigner()."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return this._address;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if the adapter is initialized
|
|
26
|
+
*/
|
|
27
|
+
get isInitialized() {
|
|
28
|
+
return this._initialized;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the adapter by fetching the address
|
|
32
|
+
* Must be called before using the signer
|
|
33
|
+
*/
|
|
34
|
+
async initialize() {
|
|
35
|
+
if (this._initialized) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this._address = await this._account.getAddress();
|
|
39
|
+
this._initialized = true;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Sign a message using the Spark wallet
|
|
43
|
+
* @param message - Message to sign (string or bytes)
|
|
44
|
+
* @returns Signature string
|
|
45
|
+
*/
|
|
46
|
+
async signMessage(message) {
|
|
47
|
+
return this._account.signMessage(message);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the wallet balance in satoshis
|
|
51
|
+
*/
|
|
52
|
+
async getBalance() {
|
|
53
|
+
return this._account.getBalance();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Send a transaction via the Spark network
|
|
57
|
+
* @param params - Transaction parameters
|
|
58
|
+
* @returns Transaction result with hash
|
|
59
|
+
*/
|
|
60
|
+
async sendTransaction(params) {
|
|
61
|
+
return this._account.sendTransaction(params);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
async function createWDKSparkSigner(account) {
|
|
65
|
+
const adapter = new WDKSparkSignerAdapter(account);
|
|
66
|
+
await adapter.initialize();
|
|
67
|
+
return adapter;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/adapters/btc-adapter.ts
|
|
71
|
+
var WDKBtcSignerAdapter = class {
|
|
72
|
+
_account;
|
|
73
|
+
_address = null;
|
|
74
|
+
_initialized = false;
|
|
75
|
+
constructor(account) {
|
|
76
|
+
if (!account) {
|
|
77
|
+
throw new Error("WDK Bitcoin account is required");
|
|
78
|
+
}
|
|
79
|
+
this._account = account;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the wallet address
|
|
83
|
+
* @throws Error if not initialized
|
|
84
|
+
*/
|
|
85
|
+
get address() {
|
|
86
|
+
if (!this._address) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"Bitcoin signer not initialized. Call initialize() first or use createWDKBtcSigner()."
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return this._address;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if the adapter is initialized
|
|
95
|
+
*/
|
|
96
|
+
get isInitialized() {
|
|
97
|
+
return this._initialized;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Initialize the adapter by fetching the address
|
|
101
|
+
* Must be called before using the signer
|
|
102
|
+
*/
|
|
103
|
+
async initialize() {
|
|
104
|
+
if (this._initialized) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this._address = await this._account.getAddress();
|
|
108
|
+
this._initialized = true;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Sign a message using the Bitcoin wallet
|
|
112
|
+
* @param message - Message string to sign
|
|
113
|
+
* @returns Signature string
|
|
114
|
+
*/
|
|
115
|
+
async signMessage(message) {
|
|
116
|
+
return this._account.signMessage(message);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Sign a Partially Signed Bitcoin Transaction (PSBT)
|
|
120
|
+
* @param psbt - PSBT bytes to sign
|
|
121
|
+
* @returns Signed PSBT bytes
|
|
122
|
+
*/
|
|
123
|
+
async signPsbt(psbt) {
|
|
124
|
+
return this._account.signPsbt(psbt);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the wallet balance in satoshis
|
|
128
|
+
*/
|
|
129
|
+
async getBalance() {
|
|
130
|
+
return this._account.getBalance();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Send a Bitcoin transaction
|
|
134
|
+
* @param params - Transaction parameters
|
|
135
|
+
* @returns Transaction hash
|
|
136
|
+
*/
|
|
137
|
+
async sendTransaction(params) {
|
|
138
|
+
return this._account.sendTransaction(params);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
async function createWDKBtcSigner(account) {
|
|
142
|
+
const adapter = new WDKBtcSignerAdapter(account);
|
|
143
|
+
await adapter.initialize();
|
|
144
|
+
return adapter;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
WDKSparkSignerAdapter,
|
|
149
|
+
createWDKSparkSigner,
|
|
150
|
+
WDKBtcSignerAdapter,
|
|
151
|
+
createWDKBtcSigner
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=chunk-7CG77QAN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/spark-adapter.ts","../../src/adapters/btc-adapter.ts"],"sourcesContent":["/**\n * Spark (Bitcoin L2) Signer Adapter for WDK\n *\n * Wraps a Spark wallet account to implement T402's payment signing interface.\n * Spark is a Bitcoin L2 built on the Spark SDK (@buildonspark/spark-sdk).\n */\n\n/**\n * SparkWalletAccount interface (matches @buildonspark/spark-sdk)\n */\nexport interface SparkWalletAccount {\n getAddress(): Promise<string>\n getBalance(): Promise<bigint>\n sendTransaction(params: { to: string; amount: bigint }): Promise<{ hash: string }>\n signMessage(message: string | Uint8Array): Promise<string>\n}\n\n/**\n * WDKSparkSignerAdapter - Adapts a Spark wallet account for T402 payments\n *\n * @example\n * ```typescript\n * const adapter = await createWDKSparkSigner(sparkAccount);\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'spark:mainnet', signer: adapter }]\n * });\n * ```\n */\nexport class WDKSparkSignerAdapter {\n private _account: SparkWalletAccount\n private _address: string | null = null\n private _initialized = false\n\n constructor(account: SparkWalletAccount) {\n if (!account) {\n throw new Error('Spark wallet account is required')\n }\n this._account = account\n }\n\n /**\n * Get the wallet address\n * @throws Error if not initialized\n */\n get address(): string {\n if (!this._address) {\n throw new Error(\n 'Spark signer not initialized. Call initialize() first or use createWDKSparkSigner().',\n )\n }\n return this._address\n }\n\n /**\n * Check if the adapter is initialized\n */\n get isInitialized(): boolean {\n return this._initialized\n }\n\n /**\n * Initialize the adapter by fetching the address\n * Must be called before using the signer\n */\n async initialize(): Promise<void> {\n if (this._initialized) {\n return\n }\n\n this._address = await this._account.getAddress()\n this._initialized = true\n }\n\n /**\n * Sign a message using the Spark wallet\n * @param message - Message to sign (string or bytes)\n * @returns Signature string\n */\n async signMessage(message: string | Uint8Array): Promise<string> {\n return this._account.signMessage(message)\n }\n\n /**\n * Get the wallet balance in satoshis\n */\n async getBalance(): Promise<bigint> {\n return this._account.getBalance()\n }\n\n /**\n * Send a transaction via the Spark network\n * @param params - Transaction parameters\n * @returns Transaction result with hash\n */\n async sendTransaction(params: { to: string; amount: bigint }): Promise<{ hash: string }> {\n return this._account.sendTransaction(params)\n }\n}\n\n/**\n * Create an initialized WDK Spark signer\n *\n * @param account - Spark wallet account from @buildonspark/spark-sdk\n * @returns Initialized WDKSparkSignerAdapter\n *\n * @example\n * ```typescript\n * import { T402WDK } from '@t402/wdk';\n *\n * const wallet = new T402WDK(seedPhrase, config);\n * const sparkSigner = await wallet.getSparkSigner();\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'spark:mainnet', signer: sparkSigner }]\n * });\n * ```\n */\nexport async function createWDKSparkSigner(\n account: SparkWalletAccount,\n): Promise<WDKSparkSignerAdapter> {\n const adapter = new WDKSparkSignerAdapter(account)\n await adapter.initialize()\n return adapter\n}\n","/**\n * Bitcoin (BTC) On-Chain Signer Adapter for WDK\n *\n * Wraps a Tether WDK Bitcoin account to implement T402's payment signing interface.\n * This allows WDK-managed Bitcoin wallets to be used for T402 payments.\n */\n\n/**\n * WDKBtcAccount interface (matches @tetherto/wdk-wallet-btc)\n */\nexport interface WDKBtcAccount {\n getAddress(): Promise<string>\n getBalance(): Promise<bigint>\n sendTransaction(params: { to: string; amount: bigint; fee?: bigint }): Promise<string>\n signMessage(message: string): Promise<string>\n signPsbt(psbt: Uint8Array): Promise<Uint8Array>\n}\n\n/**\n * WDKBtcSignerAdapter - Adapts a WDK Bitcoin account for T402 payments\n *\n * @example\n * ```typescript\n * const adapter = await createWDKBtcSigner(wdkBtcAccount);\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'bip122:000000000019d6689c085ae165831e93', signer: adapter }]\n * });\n * ```\n */\nexport class WDKBtcSignerAdapter {\n private _account: WDKBtcAccount\n private _address: string | null = null\n private _initialized = false\n\n constructor(account: WDKBtcAccount) {\n if (!account) {\n throw new Error('WDK Bitcoin account is required')\n }\n this._account = account\n }\n\n /**\n * Get the wallet address\n * @throws Error if not initialized\n */\n get address(): string {\n if (!this._address) {\n throw new Error(\n 'Bitcoin signer not initialized. Call initialize() first or use createWDKBtcSigner().',\n )\n }\n return this._address\n }\n\n /**\n * Check if the adapter is initialized\n */\n get isInitialized(): boolean {\n return this._initialized\n }\n\n /**\n * Initialize the adapter by fetching the address\n * Must be called before using the signer\n */\n async initialize(): Promise<void> {\n if (this._initialized) {\n return\n }\n\n this._address = await this._account.getAddress()\n this._initialized = true\n }\n\n /**\n * Sign a message using the Bitcoin wallet\n * @param message - Message string to sign\n * @returns Signature string\n */\n async signMessage(message: string): Promise<string> {\n return this._account.signMessage(message)\n }\n\n /**\n * Sign a Partially Signed Bitcoin Transaction (PSBT)\n * @param psbt - PSBT bytes to sign\n * @returns Signed PSBT bytes\n */\n async signPsbt(psbt: Uint8Array): Promise<Uint8Array> {\n return this._account.signPsbt(psbt)\n }\n\n /**\n * Get the wallet balance in satoshis\n */\n async getBalance(): Promise<bigint> {\n return this._account.getBalance()\n }\n\n /**\n * Send a Bitcoin transaction\n * @param params - Transaction parameters\n * @returns Transaction hash\n */\n async sendTransaction(params: { to: string; amount: bigint; fee?: bigint }): Promise<string> {\n return this._account.sendTransaction(params)\n }\n}\n\n/**\n * Create an initialized WDK Bitcoin signer\n *\n * @param account - WDK Bitcoin account from @tetherto/wdk-wallet-btc\n * @returns Initialized WDKBtcSignerAdapter\n *\n * @example\n * ```typescript\n * import { T402WDK } from '@t402/wdk';\n *\n * const wallet = new T402WDK(seedPhrase, config);\n * const btcSigner = await wallet.getBtcSigner();\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'bip122:000000000019d6689c085ae165831e93', signer: btcSigner }]\n * });\n * ```\n */\nexport async function createWDKBtcSigner(account: WDKBtcAccount): Promise<WDKBtcSignerAdapter> {\n const adapter = new WDKBtcSignerAdapter(account)\n await adapter.initialize()\n return adapter\n}\n"],"mappings":";AA8BO,IAAM,wBAA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AAAA,EAMA,IAAI,UAAkB;AACpB,QAAI,CAAC,KAAK,UAAU;AAClB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,gBAAyB;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,aAA4B;AAChC,QAAI,KAAK,cAAc;AACrB;AAAA,IACF;AAEA,SAAK,WAAW,MAAM,KAAK,SAAS,WAAW;AAC/C,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,YAAY,SAAkC;AAClD,WAAO,KAAK,SAAS,YAAY,OAAO;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAS,MAAuC;AACpD,WAAO,KAAK,SAAS,SAAS,IAAI;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA8B;AAClC,WAAO,KAAK,SAAS,WAAW;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,gBAAgB,QAAuE;AAC3F,WAAO,KAAK,SAAS,gBAAgB,MAAM;AAAA,EAC7C;AACF;AAqBA,eAAsB,mBAAmB,SAAsD;AAC7F,QAAM,UAAU,IAAI,oBAAoB,OAAO;AAC/C,QAAM,QAAQ,WAAW;AACzB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__require
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=chunk-BJTO5JO5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|