@t402/wdk 2.3.1 → 2.5.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.
Files changed (40) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/adapters/index.d.ts +5 -0
  3. package/dist/cjs/adapters/index.js +455 -0
  4. package/dist/cjs/adapters/index.js.map +1 -0
  5. package/dist/cjs/adapters/svm-adapter.d.ts +125 -0
  6. package/dist/cjs/adapters/svm-adapter.js +132 -0
  7. package/dist/cjs/adapters/svm-adapter.js.map +1 -0
  8. package/dist/cjs/adapters/ton-adapter.d.ts +139 -0
  9. package/dist/cjs/adapters/ton-adapter.js +152 -0
  10. package/dist/cjs/adapters/ton-adapter.js.map +1 -0
  11. package/dist/cjs/adapters/tron-adapter.d.ts +139 -0
  12. package/dist/cjs/adapters/tron-adapter.js +221 -0
  13. package/dist/cjs/adapters/tron-adapter.js.map +1 -0
  14. package/dist/cjs/index.d.ts +292 -217
  15. package/dist/cjs/index.js +1042 -23
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/types-C1S0k-2w.d.ts +489 -0
  18. package/dist/esm/adapters/index.d.mts +5 -0
  19. package/dist/esm/adapters/index.mjs +21 -0
  20. package/dist/esm/adapters/index.mjs.map +1 -0
  21. package/dist/esm/adapters/svm-adapter.d.mts +125 -0
  22. package/dist/esm/adapters/svm-adapter.mjs +9 -0
  23. package/dist/esm/adapters/svm-adapter.mjs.map +1 -0
  24. package/dist/esm/adapters/ton-adapter.d.mts +139 -0
  25. package/dist/esm/adapters/ton-adapter.mjs +9 -0
  26. package/dist/esm/adapters/ton-adapter.mjs.map +1 -0
  27. package/dist/esm/adapters/tron-adapter.d.mts +139 -0
  28. package/dist/esm/adapters/tron-adapter.mjs +9 -0
  29. package/dist/esm/adapters/tron-adapter.mjs.map +1 -0
  30. package/dist/esm/chunk-HB2DGKQ3.mjs +196 -0
  31. package/dist/esm/chunk-HB2DGKQ3.mjs.map +1 -0
  32. package/dist/esm/chunk-MCFHZSF7.mjs +107 -0
  33. package/dist/esm/chunk-MCFHZSF7.mjs.map +1 -0
  34. package/dist/esm/chunk-YWBJJV5M.mjs +117 -0
  35. package/dist/esm/chunk-YWBJJV5M.mjs.map +1 -0
  36. package/dist/esm/index.d.mts +292 -217
  37. package/dist/esm/index.mjs +640 -23
  38. package/dist/esm/index.mjs.map +1 -1
  39. package/dist/esm/types-C1S0k-2w.d.mts +489 -0
  40. package/package.json +82 -18
package/README.md CHANGED
@@ -511,6 +511,14 @@ import type {
511
511
  } from '@t402/wdk'
512
512
  ```
513
513
 
514
+ ## Related Packages
515
+
516
+ - `@t402/core` - Core protocol types and client
517
+ - `@t402/evm` - EVM mechanism implementation
518
+ - `@t402/wdk-gasless` - ERC-4337 gasless payments
519
+ - `@t402/wdk-bridge` - Cross-chain LayerZero bridging
520
+ - `@t402/wdk-multisig` - Safe multi-sig wallets
521
+
514
522
  ## License
515
523
 
516
524
  Apache 2.0
@@ -0,0 +1,5 @@
1
+ export { WDKTonSignerAdapter, createWDKTonSigner } from './ton-adapter.js';
2
+ export { WDKSvmSignerAdapter, createWDKSvmSigner } from './svm-adapter.js';
3
+ export { WDKTronSignerAdapter, createWDKTronSigner } from './tron-adapter.js';
4
+ import '../types-C1S0k-2w.js';
5
+ import 'viem';
@@ -0,0 +1,455 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/adapters/index.ts
31
+ var adapters_exports = {};
32
+ __export(adapters_exports, {
33
+ WDKSvmSignerAdapter: () => WDKSvmSignerAdapter,
34
+ WDKTonSignerAdapter: () => WDKTonSignerAdapter,
35
+ WDKTronSignerAdapter: () => WDKTronSignerAdapter,
36
+ createWDKSvmSigner: () => createWDKSvmSigner,
37
+ createWDKTonSigner: () => createWDKTonSigner,
38
+ createWDKTronSigner: () => createWDKTronSigner
39
+ });
40
+ module.exports = __toCommonJS(adapters_exports);
41
+
42
+ // src/adapters/ton-adapter.ts
43
+ var WDKTonAddress = class {
44
+ constructor(_address) {
45
+ this._address = _address;
46
+ }
47
+ toString() {
48
+ return this._address;
49
+ }
50
+ toRawString() {
51
+ return this._address;
52
+ }
53
+ };
54
+ var WDKTonSignerAdapter = class {
55
+ _account;
56
+ _address = null;
57
+ _initialized = false;
58
+ constructor(account) {
59
+ if (!account) {
60
+ throw new Error("WDK TON account is required");
61
+ }
62
+ this._account = account;
63
+ }
64
+ /**
65
+ * Get the wallet address
66
+ * @throws Error if not initialized
67
+ */
68
+ get address() {
69
+ if (!this._address) {
70
+ throw new Error(
71
+ "TON signer not initialized. Call initialize() first or use createWDKTonSigner()."
72
+ );
73
+ }
74
+ return this._address;
75
+ }
76
+ /**
77
+ * Check if the adapter is initialized
78
+ */
79
+ get isInitialized() {
80
+ return this._initialized;
81
+ }
82
+ /**
83
+ * Initialize the adapter by fetching the address
84
+ * Must be called before using the signer
85
+ */
86
+ async initialize() {
87
+ if (this._initialized) {
88
+ return;
89
+ }
90
+ const addressStr = await this._account.getAddress();
91
+ this._address = new WDKTonAddress(addressStr);
92
+ this._initialized = true;
93
+ }
94
+ /**
95
+ * Sign an internal message for Jetton transfer
96
+ *
97
+ * Attempts to build a proper signed Cell using @ton/core if available.
98
+ * Falls back to a simplified wrapper that embeds the raw signature.
99
+ *
100
+ * @param params - Message parameters
101
+ * @returns Signed external message as Cell (BOC)
102
+ */
103
+ async signMessage(params) {
104
+ const msgHash = params.body.hash();
105
+ const signature = await this._account.signMessage(msgHash);
106
+ try {
107
+ const tonCore = await import("@ton/core");
108
+ const sigBuffer = Buffer.from(signature.buffer, signature.byteOffset, signature.byteLength);
109
+ const bodyBoc = params.body.toBoc();
110
+ const bocBuffer = Buffer.from(bodyBoc.buffer, bodyBoc.byteOffset, bodyBoc.byteLength);
111
+ const signedCell = tonCore.beginCell().storeBuffer(sigBuffer).storeSlice(tonCore.Cell.fromBoc(bocBuffer)[0].beginParse()).endCell();
112
+ return signedCell;
113
+ } catch {
114
+ return {
115
+ hash: () => msgHash,
116
+ toBoc: () => signature
117
+ };
118
+ }
119
+ }
120
+ /**
121
+ * Get current seqno for the wallet
122
+ * Used for replay protection
123
+ */
124
+ async getSeqno() {
125
+ return this._account.getSeqno();
126
+ }
127
+ /**
128
+ * Get TON balance in nanoTON
129
+ */
130
+ async getBalance() {
131
+ return this._account.getBalance();
132
+ }
133
+ /**
134
+ * Get Jetton balance
135
+ * @param jettonMaster - Jetton master contract address
136
+ */
137
+ async getJettonBalance(jettonMaster) {
138
+ return this._account.getJettonBalance(jettonMaster);
139
+ }
140
+ /**
141
+ * Get the underlying WDK account
142
+ * Useful for advanced operations not covered by this adapter
143
+ */
144
+ getWDKAccount() {
145
+ return this._account;
146
+ }
147
+ };
148
+ async function createWDKTonSigner(account) {
149
+ const adapter = new WDKTonSignerAdapter(account);
150
+ await adapter.initialize();
151
+ return adapter;
152
+ }
153
+
154
+ // src/adapters/svm-adapter.ts
155
+ var WDKSvmSignerAdapter = class {
156
+ _account;
157
+ _address = null;
158
+ _initialized = false;
159
+ constructor(account) {
160
+ if (!account) {
161
+ throw new Error("WDK Solana account is required");
162
+ }
163
+ this._account = account;
164
+ }
165
+ /**
166
+ * Get the wallet address (base58)
167
+ * @throws Error if not initialized
168
+ */
169
+ get address() {
170
+ if (!this._address) {
171
+ throw new Error(
172
+ "Solana signer not initialized. Call initialize() first or use createWDKSvmSigner()."
173
+ );
174
+ }
175
+ return this._address;
176
+ }
177
+ /**
178
+ * Check if the adapter is initialized
179
+ */
180
+ get isInitialized() {
181
+ return this._initialized;
182
+ }
183
+ /**
184
+ * Initialize the adapter by fetching the address
185
+ * Must be called before using the signer
186
+ */
187
+ async initialize() {
188
+ if (this._initialized) {
189
+ return;
190
+ }
191
+ const addressStr = await this._account.getAddress();
192
+ this._address = addressStr;
193
+ this._initialized = true;
194
+ }
195
+ /**
196
+ * Sign transactions with this signer
197
+ *
198
+ * This method signs the message bytes of each transaction and returns
199
+ * signature dictionaries mapping address to signature.
200
+ *
201
+ * @param transactions - Array of transactions to sign
202
+ * @returns Array of signature dictionaries
203
+ */
204
+ async signTransactions(transactions) {
205
+ if (!transactions || transactions.length === 0) {
206
+ return [];
207
+ }
208
+ const results = [];
209
+ for (const tx of transactions) {
210
+ if (!tx.messageBytes || tx.messageBytes.length === 0) {
211
+ throw new Error("Transaction messageBytes must not be empty");
212
+ }
213
+ const signature = await this._account.sign(tx.messageBytes);
214
+ results.push({
215
+ [this._address]: signature
216
+ });
217
+ }
218
+ return results;
219
+ }
220
+ /**
221
+ * Sign a single message (utility method)
222
+ * @param message - Message bytes to sign
223
+ * @returns Signature bytes
224
+ */
225
+ async sign(message) {
226
+ return this._account.sign(message);
227
+ }
228
+ /**
229
+ * Get SOL balance in lamports
230
+ */
231
+ async getBalance() {
232
+ return this._account.getBalance();
233
+ }
234
+ /**
235
+ * Get SPL token balance
236
+ * @param mint - Token mint address
237
+ */
238
+ async getTokenBalance(mint) {
239
+ return this._account.getTokenBalance(mint);
240
+ }
241
+ /**
242
+ * Transfer SPL tokens
243
+ * @param params - Transfer parameters
244
+ * @returns Transaction signature
245
+ */
246
+ async transfer(params) {
247
+ return this._account.transfer(params);
248
+ }
249
+ };
250
+ async function createWDKSvmSigner(account) {
251
+ const adapter = new WDKSvmSignerAdapter(account);
252
+ await adapter.initialize();
253
+ return adapter;
254
+ }
255
+
256
+ // src/adapters/tron-adapter.ts
257
+ var WDKTronSignerAdapter = class {
258
+ _account;
259
+ _address = null;
260
+ _initialized = false;
261
+ _rpcUrl;
262
+ constructor(account, rpcUrl = "https://api.trongrid.io") {
263
+ if (!account) {
264
+ throw new Error("WDK TRON account is required");
265
+ }
266
+ this._account = account;
267
+ this._rpcUrl = rpcUrl;
268
+ }
269
+ /**
270
+ * Get the wallet address (T-prefix base58check)
271
+ * @throws Error if not initialized
272
+ */
273
+ get address() {
274
+ if (!this._address) {
275
+ throw new Error(
276
+ "TRON signer not initialized. Call initialize() first or use createWDKTronSigner()."
277
+ );
278
+ }
279
+ return this._address;
280
+ }
281
+ /**
282
+ * Check if the adapter is initialized
283
+ */
284
+ get isInitialized() {
285
+ return this._initialized;
286
+ }
287
+ /**
288
+ * Initialize the adapter by fetching the address
289
+ * Must be called before using the signer
290
+ */
291
+ async initialize() {
292
+ if (this._initialized) {
293
+ return;
294
+ }
295
+ this._address = await this._account.getAddress();
296
+ this._initialized = true;
297
+ }
298
+ /**
299
+ * Sign a TRC20 transfer transaction
300
+ *
301
+ * This method:
302
+ * 1. Builds a TRC20 transfer transaction
303
+ * 2. Signs it using the WDK account
304
+ * 3. Returns the hex-encoded signed transaction
305
+ *
306
+ * @param params - Transaction parameters
307
+ * @returns Hex-encoded signed transaction
308
+ */
309
+ async signTransaction(params) {
310
+ if (!params.contractAddress) {
311
+ throw new Error("contractAddress is required");
312
+ }
313
+ if (!params.to) {
314
+ throw new Error("recipient address (to) is required");
315
+ }
316
+ if (!params.amount || BigInt(params.amount) <= 0n) {
317
+ throw new Error("amount must be a positive value");
318
+ }
319
+ const blockInfo = await this.getBlockInfo();
320
+ const feeLimit = params.feeLimit ?? 1e8;
321
+ const transaction = await this.buildTrc20Transaction({
322
+ contractAddress: params.contractAddress,
323
+ to: params.to,
324
+ amount: params.amount,
325
+ feeLimit,
326
+ refBlockBytes: blockInfo.refBlockBytes,
327
+ refBlockHash: blockInfo.refBlockHash,
328
+ expiration: params.expiration ?? blockInfo.expiration
329
+ });
330
+ const signedTx = await this._account.signTransaction(transaction);
331
+ return this.serializeTransaction(signedTx);
332
+ }
333
+ /**
334
+ * Get the current reference block info for transaction building
335
+ * This is required for TRON's replay protection mechanism
336
+ */
337
+ async getBlockInfo() {
338
+ try {
339
+ const response = await fetch(`${this._rpcUrl}/wallet/getnowblock`, {
340
+ method: "POST",
341
+ headers: { "Content-Type": "application/json" },
342
+ body: JSON.stringify({})
343
+ });
344
+ if (!response.ok) {
345
+ throw new Error(`Failed to get block info: ${response.status}`);
346
+ }
347
+ const block = await response.json();
348
+ const blockNum = block.block_header.raw_data.number;
349
+ const refBlockBytes = blockNum.toString(16).padStart(8, "0").slice(-4);
350
+ const refBlockHash = block.blockID.slice(16, 32);
351
+ const expiration = block.block_header.raw_data.timestamp + 6e4;
352
+ return {
353
+ refBlockBytes,
354
+ refBlockHash,
355
+ expiration
356
+ };
357
+ } catch (error) {
358
+ throw new Error(
359
+ `Failed to get TRON block info: ${error instanceof Error ? error.message : String(error)}`
360
+ );
361
+ }
362
+ }
363
+ /**
364
+ * Build a TRC20 transfer transaction
365
+ */
366
+ async buildTrc20Transaction(params) {
367
+ const functionSelector = "transfer(address,uint256)";
368
+ const toAddressHex = this.addressToHex(params.to).slice(2).padStart(64, "0");
369
+ const amountHex = BigInt(params.amount).toString(16).padStart(64, "0");
370
+ const parameter = toAddressHex + amountHex;
371
+ try {
372
+ const response = await fetch(`${this._rpcUrl}/wallet/triggersmartcontract`, {
373
+ method: "POST",
374
+ headers: { "Content-Type": "application/json" },
375
+ body: JSON.stringify({
376
+ owner_address: this.addressToHex(this._address),
377
+ contract_address: this.addressToHex(params.contractAddress),
378
+ function_selector: functionSelector,
379
+ parameter,
380
+ fee_limit: params.feeLimit
381
+ })
382
+ });
383
+ if (!response.ok) {
384
+ throw new Error(`Failed to build transaction: ${response.status}`);
385
+ }
386
+ const result = await response.json();
387
+ if (result.result?.code) {
388
+ throw new Error(`Transaction build failed: ${result.result.message}`);
389
+ }
390
+ return result.transaction;
391
+ } catch (error) {
392
+ throw new Error(
393
+ `Failed to build TRC20 transaction: ${error instanceof Error ? error.message : String(error)}`
394
+ );
395
+ }
396
+ }
397
+ /**
398
+ * Serialize a signed transaction to hex format
399
+ */
400
+ serializeTransaction(signedTx) {
401
+ if (signedTx.signature && signedTx.signature.length > 0) {
402
+ return JSON.stringify(signedTx);
403
+ }
404
+ return signedTx.raw_data_hex;
405
+ }
406
+ /**
407
+ * Convert TRON base58 address to hex format
408
+ */
409
+ addressToHex(address) {
410
+ if (address.startsWith("41") || address.startsWith("0x")) {
411
+ return address.startsWith("0x") ? "41" + address.slice(2) : address;
412
+ }
413
+ const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
414
+ let num = BigInt(0);
415
+ for (const char of address) {
416
+ num = num * BigInt(58) + BigInt(ALPHABET.indexOf(char));
417
+ }
418
+ let hex = num.toString(16);
419
+ let leadingZeros = 0;
420
+ for (const char of address) {
421
+ if (char === "1") leadingZeros++;
422
+ else break;
423
+ }
424
+ hex = "00".repeat(leadingZeros) + hex;
425
+ return hex.slice(0, 42);
426
+ }
427
+ /**
428
+ * Get TRX balance in SUN
429
+ */
430
+ async getBalance() {
431
+ return this._account.getBalance();
432
+ }
433
+ /**
434
+ * Get TRC20 token balance
435
+ * @param contractAddress - TRC20 contract address
436
+ */
437
+ async getTrc20Balance(contractAddress) {
438
+ return this._account.getTrc20Balance(contractAddress);
439
+ }
440
+ };
441
+ async function createWDKTronSigner(account, rpcUrl) {
442
+ const adapter = new WDKTronSignerAdapter(account, rpcUrl);
443
+ await adapter.initialize();
444
+ return adapter;
445
+ }
446
+ // Annotate the CommonJS export names for ESM import in node:
447
+ 0 && (module.exports = {
448
+ WDKSvmSignerAdapter,
449
+ WDKTonSignerAdapter,
450
+ WDKTronSignerAdapter,
451
+ createWDKSvmSigner,
452
+ createWDKTonSigner,
453
+ createWDKTronSigner
454
+ });
455
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/index.ts","../../../src/adapters/ton-adapter.ts","../../../src/adapters/svm-adapter.ts","../../../src/adapters/tron-adapter.ts"],"sourcesContent":["/**\n * Multi-chain WDK adapters for T402\n *\n * These adapters wrap Tether WDK wallet accounts to implement\n * T402's existing signer interfaces for each chain.\n */\n\nexport { WDKTonSignerAdapter, createWDKTonSigner } from './ton-adapter.js'\nexport { WDKSvmSignerAdapter, createWDKSvmSigner } from './svm-adapter.js'\nexport { WDKTronSignerAdapter, createWDKTronSigner } from './tron-adapter.js'\n","/**\n * TON Signer Adapter for WDK\n *\n * Wraps a Tether WDK TON account to implement T402's ClientTonSigner interface.\n * This allows WDK-managed TON wallets to be used for T402 payments.\n */\n\nimport type { WDKTonAccount } from '../types.js'\n\n/**\n * TON Address type (compatible with @ton/core Address)\n * We define our own interface to avoid direct import\n */\nexport interface TonAddress {\n toString(): string\n toRawString(): string\n}\n\n/**\n * TON Cell type (compatible with @ton/core Cell)\n * We define our own interface to avoid direct import\n */\nexport interface TonCell {\n hash(): Uint8Array\n toBoc(): Uint8Array\n}\n\n/**\n * SignMessageParams type matching T402's @t402/ton interface\n */\nexport interface SignMessageParams {\n /** Destination address */\n to: TonAddress\n /** Amount of TON to attach (for gas) in nanoTON */\n value: bigint\n /** Message body (Jetton transfer cell) */\n body: TonCell\n /** Send mode flags (from @ton/core SendMode) */\n sendMode?: number\n /** Bounce flag */\n bounce?: boolean\n /** Message validity timeout in seconds */\n timeout?: number\n}\n\n/**\n * ClientTonSigner interface matching T402's @t402/ton\n */\nexport interface ClientTonSigner {\n readonly address: TonAddress\n signMessage(params: SignMessageParams): Promise<TonCell>\n getSeqno(): Promise<number>\n}\n\n/**\n * Simple TonAddress implementation for WDK\n */\nclass WDKTonAddress implements TonAddress {\n constructor(private _address: string) {}\n\n toString(): string {\n return this._address\n }\n\n toRawString(): string {\n return this._address\n }\n}\n\n/**\n * WDKTonSignerAdapter - Adapts a WDK TON account to T402's ClientTonSigner\n *\n * This adapter wraps a Tether WDK TON account and provides T402-compatible\n * signing functionality. The actual message building and signing is delegated\n * to the WDK account, which handles TON-specific details internally.\n *\n * @example\n * ```typescript\n * const adapter = await createWDKTonSigner(wdkTonAccount);\n * const signed = await adapter.signMessage({\n * to: jettonWalletAddress,\n * value: toNano('0.05'),\n * body: jettonTransferBody,\n * });\n * ```\n */\nexport class WDKTonSignerAdapter implements ClientTonSigner {\n private _account: WDKTonAccount\n private _address: TonAddress | null = null\n private _initialized = false\n\n constructor(account: WDKTonAccount) {\n if (!account) {\n throw new Error('WDK TON 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(): TonAddress {\n if (!this._address) {\n throw new Error(\n 'TON signer not initialized. Call initialize() first or use createWDKTonSigner().',\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 = new WDKTonAddress(addressStr)\n this._initialized = true\n }\n\n /**\n * Sign an internal message for Jetton transfer\n *\n * Attempts to build a proper signed Cell using @ton/core if available.\n * Falls back to a simplified wrapper that embeds the raw signature.\n *\n * @param params - Message parameters\n * @returns Signed external message as Cell (BOC)\n */\n async signMessage(params: SignMessageParams): Promise<TonCell> {\n const msgHash = params.body.hash()\n const signature = await this._account.signMessage(msgHash)\n\n // Try to use @ton/core for proper Cell construction\n try {\n const tonCore = await import('@ton/core')\n const sigBuffer = Buffer.from(signature.buffer, signature.byteOffset, signature.byteLength)\n const bodyBoc = params.body.toBoc()\n const bocBuffer = Buffer.from(bodyBoc.buffer, bodyBoc.byteOffset, bodyBoc.byteLength)\n const signedCell = tonCore\n .beginCell()\n .storeBuffer(sigBuffer)\n .storeSlice(tonCore.Cell.fromBoc(bocBuffer)[0]!.beginParse())\n .endCell()\n return signedCell as unknown as TonCell\n } catch {\n // @ton/core not available — return simplified wrapper.\n // The signature is accessible via toBoc() and the original\n // message hash via hash(), which is sufficient for T402\n // facilitator verification.\n return {\n hash: () => msgHash,\n toBoc: () => signature,\n }\n }\n }\n\n /**\n * Get current seqno for the wallet\n * Used for replay protection\n */\n async getSeqno(): Promise<number> {\n return this._account.getSeqno()\n }\n\n /**\n * Get TON balance in nanoTON\n */\n async getBalance(): Promise<bigint> {\n return this._account.getBalance()\n }\n\n /**\n * Get Jetton balance\n * @param jettonMaster - Jetton master contract address\n */\n async getJettonBalance(jettonMaster: string): Promise<bigint> {\n return this._account.getJettonBalance(jettonMaster)\n }\n\n /**\n * Get the underlying WDK account\n * Useful for advanced operations not covered by this adapter\n */\n getWDKAccount(): WDKTonAccount {\n return this._account\n }\n}\n\n/**\n * Create an initialized WDK TON signer\n *\n * @param account - WDK TON account from @tetherto/wdk-wallet-ton\n * @returns Initialized ClientTonSigner\n *\n * @example\n * ```typescript\n * import { T402WDK } from '@t402/wdk';\n *\n * const wallet = new T402WDK(seedPhrase, config);\n * const tonSigner = await wallet.getTonSigner();\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'ton:mainnet', signer: tonSigner }]\n * });\n * ```\n */\nexport async function createWDKTonSigner(account: WDKTonAccount): Promise<WDKTonSignerAdapter> {\n const adapter = new WDKTonSignerAdapter(account)\n await adapter.initialize()\n return adapter\n}\n","/**\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\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 * 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","/**\n * TRON Signer Adapter for WDK\n *\n * Wraps a Tether WDK TRON account to implement T402's ClientTronSigner interface.\n * This allows WDK-managed TRON wallets to be used for T402 payments.\n */\n\nimport type { WDKTronAccount } from '../types.js'\n\n/**\n * SignTransactionParams matching T402's @t402/tron interface\n */\nexport interface SignTransactionParams {\n /** TRC20 contract address */\n contractAddress: string\n /** Recipient address (T-prefix base58check) */\n to: string\n /** Amount to transfer (in smallest units) */\n amount: string\n /** Fee limit in SUN (optional, defaults to 100 TRX) */\n feeLimit?: number\n /** Transaction expiration time in milliseconds (optional) */\n expiration?: number\n}\n\n/**\n * Block info for transaction building\n */\nexport interface BlockInfo {\n /** Reference block bytes (hex) */\n refBlockBytes: string\n /** Reference block hash (hex) */\n refBlockHash: string\n /** Expiration timestamp in milliseconds */\n expiration: number\n}\n\n/**\n * ClientTronSigner interface matching T402's @t402/tron\n */\nexport interface ClientTronSigner {\n readonly address: string\n signTransaction(params: SignTransactionParams): Promise<string>\n getBlockInfo(): Promise<BlockInfo>\n}\n\n// TronWeb-compatible types\ninterface TronWebTransaction {\n txID: string\n raw_data: {\n contract: unknown[]\n ref_block_bytes: string\n ref_block_hash: string\n expiration: number\n timestamp: number\n }\n raw_data_hex: string\n signature?: string[]\n}\n\ninterface TronWebBlock {\n block_header: {\n raw_data: {\n number: number\n txTrieRoot: string\n witness_address: string\n parentHash: string\n version: number\n timestamp: number\n }\n witness_signature: string\n }\n blockID: string\n}\n\n/**\n * WDKTronSignerAdapter - Adapts a WDK TRON account to T402's ClientTronSigner\n *\n * @example\n * ```typescript\n * const adapter = await createWDKTronSigner(wdkTronAccount);\n * const signedTx = await adapter.signTransaction({\n * contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',\n * to: 'TRecipientAddress...',\n * amount: '1000000', // 1 USDT\n * });\n * ```\n */\nexport class WDKTronSignerAdapter implements ClientTronSigner {\n private _account: WDKTronAccount\n private _address: string | null = null\n private _initialized = false\n private _rpcUrl: string\n\n constructor(account: WDKTronAccount, rpcUrl = 'https://api.trongrid.io') {\n if (!account) {\n throw new Error('WDK TRON account is required')\n }\n this._account = account\n this._rpcUrl = rpcUrl\n }\n\n /**\n * Get the wallet address (T-prefix base58check)\n * @throws Error if not initialized\n */\n get address(): string {\n if (!this._address) {\n throw new Error(\n 'TRON signer not initialized. Call initialize() first or use createWDKTronSigner().',\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 TRC20 transfer transaction\n *\n * This method:\n * 1. Builds a TRC20 transfer transaction\n * 2. Signs it using the WDK account\n * 3. Returns the hex-encoded signed transaction\n *\n * @param params - Transaction parameters\n * @returns Hex-encoded signed transaction\n */\n async signTransaction(params: SignTransactionParams): Promise<string> {\n if (!params.contractAddress) {\n throw new Error('contractAddress is required')\n }\n if (!params.to) {\n throw new Error('recipient address (to) is required')\n }\n if (!params.amount || BigInt(params.amount) <= 0n) {\n throw new Error('amount must be a positive value')\n }\n\n // Get block info for transaction\n const blockInfo = await this.getBlockInfo()\n\n // Default fee limit: 100 TRX = 100_000_000 SUN\n const feeLimit = params.feeLimit ?? 100_000_000\n\n // Build the TRC20 transfer transaction\n const transaction = await this.buildTrc20Transaction({\n contractAddress: params.contractAddress,\n to: params.to,\n amount: params.amount,\n feeLimit,\n refBlockBytes: blockInfo.refBlockBytes,\n refBlockHash: blockInfo.refBlockHash,\n expiration: params.expiration ?? blockInfo.expiration,\n })\n\n // Sign the transaction using WDK account\n const signedTx = await this._account.signTransaction(transaction)\n\n // Serialize to hex format\n return this.serializeTransaction(signedTx as TronWebTransaction)\n }\n\n /**\n * Get the current reference block info for transaction building\n * This is required for TRON's replay protection mechanism\n */\n async getBlockInfo(): Promise<BlockInfo> {\n try {\n const response = await fetch(`${this._rpcUrl}/wallet/getnowblock`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({}),\n })\n\n if (!response.ok) {\n throw new Error(`Failed to get block info: ${response.status}`)\n }\n\n const block = (await response.json()) as TronWebBlock\n\n // Extract reference block bytes (last 4 bytes of block number)\n const blockNum = block.block_header.raw_data.number\n const refBlockBytes = blockNum.toString(16).padStart(8, '0').slice(-4)\n\n // Reference block hash (first 8 bytes of block ID)\n const refBlockHash = block.blockID.slice(16, 32)\n\n // Expiration: block timestamp + 60 seconds\n const expiration = block.block_header.raw_data.timestamp + 60000\n\n return {\n refBlockBytes,\n refBlockHash,\n expiration,\n }\n } catch (error) {\n throw new Error(\n `Failed to get TRON block info: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n\n /**\n * Build a TRC20 transfer transaction\n */\n private async buildTrc20Transaction(params: {\n contractAddress: string\n to: string\n amount: string\n feeLimit: number\n refBlockBytes: string\n refBlockHash: string\n expiration: number\n }): Promise<TronWebTransaction> {\n // Build TRC20 transfer function call\n // transfer(address,uint256) = 0xa9059cbb\n const functionSelector = 'transfer(address,uint256)'\n\n // Encode parameters\n const toAddressHex = this.addressToHex(params.to).slice(2).padStart(64, '0')\n const amountHex = BigInt(params.amount).toString(16).padStart(64, '0')\n const parameter = toAddressHex + amountHex\n\n try {\n const response = await fetch(`${this._rpcUrl}/wallet/triggersmartcontract`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n owner_address: this.addressToHex(this._address!),\n contract_address: this.addressToHex(params.contractAddress),\n function_selector: functionSelector,\n parameter,\n fee_limit: params.feeLimit,\n }),\n })\n\n if (!response.ok) {\n throw new Error(`Failed to build transaction: ${response.status}`)\n }\n\n const result = await response.json()\n\n if (result.result?.code) {\n throw new Error(`Transaction build failed: ${result.result.message}`)\n }\n\n return result.transaction as TronWebTransaction\n } catch (error) {\n throw new Error(\n `Failed to build TRC20 transaction: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n\n /**\n * Serialize a signed transaction to hex format\n */\n private serializeTransaction(signedTx: TronWebTransaction): string {\n // Return the raw_data_hex with signature appended\n if (signedTx.signature && signedTx.signature.length > 0) {\n return JSON.stringify(signedTx)\n }\n return signedTx.raw_data_hex\n }\n\n /**\n * Convert TRON base58 address to hex format\n */\n private addressToHex(address: string): string {\n // If already hex, return as-is\n if (address.startsWith('41') || address.startsWith('0x')) {\n return address.startsWith('0x') ? '41' + address.slice(2) : address\n }\n\n // Convert base58 to hex using simple algorithm\n const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'\n let num = BigInt(0)\n for (const char of address) {\n num = num * BigInt(58) + BigInt(ALPHABET.indexOf(char))\n }\n\n // Convert to hex and take first 42 chars (21 bytes)\n let hex = num.toString(16)\n // Handle leading zeros\n let leadingZeros = 0\n for (const char of address) {\n if (char === '1') leadingZeros++\n else break\n }\n hex = '00'.repeat(leadingZeros) + hex\n\n // TRON address is 21 bytes = 42 hex chars\n return hex.slice(0, 42)\n }\n\n /**\n * Get TRX balance in SUN\n */\n async getBalance(): Promise<bigint> {\n return this._account.getBalance()\n }\n\n /**\n * Get TRC20 token balance\n * @param contractAddress - TRC20 contract address\n */\n async getTrc20Balance(contractAddress: string): Promise<bigint> {\n return this._account.getTrc20Balance(contractAddress)\n }\n}\n\n/**\n * Create an initialized WDK TRON signer\n *\n * @param account - WDK TRON account from @tetherto/wdk-wallet-tron\n * @param rpcUrl - Optional custom RPC URL (default: https://api.trongrid.io)\n * @returns Initialized ClientTronSigner\n *\n * @example\n * ```typescript\n * import { T402WDK } from '@t402/wdk';\n *\n * const wallet = new T402WDK(seedPhrase, config);\n * const tronSigner = await wallet.getTronSigner();\n *\n * // Use with T402 client\n * const client = createT402HTTPClient({\n * signers: [{ scheme: 'exact', network: 'tron:mainnet', signer: tronSigner }]\n * });\n * ```\n */\nexport async function createWDKTronSigner(\n account: WDKTronAccount,\n rpcUrl?: string,\n): Promise<WDKTronSignerAdapter> {\n const adapter = new WDKTronSignerAdapter(account, rpcUrl)\n await adapter.initialize()\n return adapter\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACyDA,IAAM,gBAAN,MAA0C;AAAA,EACxC,YAAoB,UAAkB;AAAlB;AAAA,EAAmB;AAAA,EAEvC,WAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,cAAsB;AACpB,WAAO,KAAK;AAAA,EACd;AACF;AAmBO,IAAM,sBAAN,MAAqD;AAAA,EAClD;AAAA,EACA,WAA8B;AAAA,EAC9B,eAAe;AAAA,EAEvB,YAAY,SAAwB;AAClC,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AACA,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,UAAsB;AACxB,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,IAAI,cAAc,UAAU;AAC5C,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,YAA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CAAC,IAAI;AAAA,IAC9D;AAGA,UAAM,WAAW;AACjB,QAAI,MAAM,OAAO,CAAC;AAClB,eAAW,QAAQ,SAAS;AAC1B,YAAM,MAAM,OAAO,EAAE,IAAI,OAAO,SAAS,QAAQ,IAAI,CAAC;AAAA,IACxD;AAGA,QAAI,MAAM,IAAI,SAAS,EAAE;AAEzB,QAAI,eAAe;AACnB,eAAW,QAAQ,SAAS;AAC1B,UAAI,SAAS,IAAK;AAAA,UACb;AAAA,IACP;AACA,UAAM,KAAK,OAAO,YAAY,IAAI;AAGlC,WAAO,IAAI,MAAM,GAAG,EAAE;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA8B;AAClC,WAAO,KAAK,SAAS,WAAW;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,gBAAgB,iBAA0C;AAC9D,WAAO,KAAK,SAAS,gBAAgB,eAAe;AAAA,EACtD;AACF;AAsBA,eAAsB,oBACpB,SACA,QAC+B;AAC/B,QAAM,UAAU,IAAI,qBAAqB,SAAS,MAAM;AACxD,QAAM,QAAQ,WAAW;AACzB,SAAO;AACT;","names":[]}
@@ -0,0 +1,125 @@
1
+ import { W as WDKSolanaAccount } from '../types-C1S0k-2w.js';
2
+ import 'viem';
3
+
4
+ /**
5
+ * Solana (SVM) Signer Adapter for WDK
6
+ *
7
+ * Wraps a Tether WDK Solana account to implement T402's ClientSvmSigner interface.
8
+ * ClientSvmSigner is just TransactionSigner from @solana/kit.
9
+ */
10
+
11
+ /**
12
+ * Address type from @solana/kit (base58 string)
13
+ * We use a branded type for compatibility
14
+ */
15
+ type SolanaAddress = string & {
16
+ readonly __brand?: unique symbol;
17
+ };
18
+ /**
19
+ * TransactionSigner interface matching @solana/kit
20
+ * This is what T402's ClientSvmSigner expects
21
+ */
22
+ interface TransactionSigner {
23
+ readonly address: SolanaAddress;
24
+ signTransactions<T extends {
25
+ messageBytes: Uint8Array;
26
+ signatures: Record<string, unknown>;
27
+ }>(transactions: readonly T[]): Promise<readonly Record<string, Uint8Array>[]>;
28
+ }
29
+ /**
30
+ * WDKSvmSignerAdapter - Adapts a WDK Solana account to T402's ClientSvmSigner
31
+ *
32
+ * ClientSvmSigner is TransactionSigner from @solana/kit which requires:
33
+ * - address: The public key as Address type
34
+ * - signTransactions: Sign multiple transactions, returning signature dictionaries
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const adapter = await createWDKSvmSigner(wdkSolanaAccount);
39
+ *
40
+ * // Use with T402 client
41
+ * const client = createT402HTTPClient({
42
+ * signers: [{ scheme: 'exact', network: 'solana:mainnet', signer: adapter }]
43
+ * });
44
+ * ```
45
+ */
46
+ declare class WDKSvmSignerAdapter implements TransactionSigner {
47
+ private _account;
48
+ private _address;
49
+ private _initialized;
50
+ constructor(account: WDKSolanaAccount);
51
+ /**
52
+ * Get the wallet address (base58)
53
+ * @throws Error if not initialized
54
+ */
55
+ get address(): SolanaAddress;
56
+ /**
57
+ * Check if the adapter is initialized
58
+ */
59
+ get isInitialized(): boolean;
60
+ /**
61
+ * Initialize the adapter by fetching the address
62
+ * Must be called before using the signer
63
+ */
64
+ initialize(): Promise<void>;
65
+ /**
66
+ * Sign transactions with this signer
67
+ *
68
+ * This method signs the message bytes of each transaction and returns
69
+ * signature dictionaries mapping address to signature.
70
+ *
71
+ * @param transactions - Array of transactions to sign
72
+ * @returns Array of signature dictionaries
73
+ */
74
+ signTransactions<T extends {
75
+ messageBytes: Uint8Array;
76
+ signatures: Record<string, unknown>;
77
+ }>(transactions: readonly T[]): Promise<readonly Record<string, Uint8Array>[]>;
78
+ /**
79
+ * Sign a single message (utility method)
80
+ * @param message - Message bytes to sign
81
+ * @returns Signature bytes
82
+ */
83
+ sign(message: Uint8Array): Promise<Uint8Array>;
84
+ /**
85
+ * Get SOL balance in lamports
86
+ */
87
+ getBalance(): Promise<bigint>;
88
+ /**
89
+ * Get SPL token balance
90
+ * @param mint - Token mint address
91
+ */
92
+ getTokenBalance(mint: string): Promise<bigint>;
93
+ /**
94
+ * Transfer SPL tokens
95
+ * @param params - Transfer parameters
96
+ * @returns Transaction signature
97
+ */
98
+ transfer(params: {
99
+ token: string;
100
+ recipient: string;
101
+ amount: bigint;
102
+ }): Promise<string>;
103
+ }
104
+ /**
105
+ * Create an initialized WDK Solana signer
106
+ *
107
+ * @param account - WDK Solana account from @tetherto/wdk-wallet-solana
108
+ * @returns Initialized TransactionSigner (ClientSvmSigner)
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * import { T402WDK } from '@t402/wdk';
113
+ *
114
+ * const wallet = new T402WDK(seedPhrase, config);
115
+ * const svmSigner = await wallet.getSvmSigner();
116
+ *
117
+ * // Use with T402 client
118
+ * const client = createT402HTTPClient({
119
+ * signers: [{ scheme: 'exact', network: 'solana:mainnet', signer: svmSigner }]
120
+ * });
121
+ * ```
122
+ */
123
+ declare function createWDKSvmSigner(account: WDKSolanaAccount): Promise<WDKSvmSignerAdapter>;
124
+
125
+ export { type SolanaAddress, type TransactionSigner, WDKSvmSignerAdapter, createWDKSvmSigner };