@t402/wdk 2.3.0 → 2.4.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-V7c-qhn6.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-V7c-qhn6.d.mts +489 -0
  40. package/package.json +70 -6
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/adapters/svm-adapter.ts
21
+ var svm_adapter_exports = {};
22
+ __export(svm_adapter_exports, {
23
+ WDKSvmSignerAdapter: () => WDKSvmSignerAdapter,
24
+ createWDKSvmSigner: () => createWDKSvmSigner
25
+ });
26
+ module.exports = __toCommonJS(svm_adapter_exports);
27
+ var WDKSvmSignerAdapter = class {
28
+ _account;
29
+ _address = null;
30
+ _initialized = false;
31
+ constructor(account) {
32
+ if (!account) {
33
+ throw new Error("WDK Solana account is required");
34
+ }
35
+ this._account = account;
36
+ }
37
+ /**
38
+ * Get the wallet address (base58)
39
+ * @throws Error if not initialized
40
+ */
41
+ get address() {
42
+ if (!this._address) {
43
+ throw new Error(
44
+ "Solana signer not initialized. Call initialize() first or use createWDKSvmSigner()."
45
+ );
46
+ }
47
+ return this._address;
48
+ }
49
+ /**
50
+ * Check if the adapter is initialized
51
+ */
52
+ get isInitialized() {
53
+ return this._initialized;
54
+ }
55
+ /**
56
+ * Initialize the adapter by fetching the address
57
+ * Must be called before using the signer
58
+ */
59
+ async initialize() {
60
+ if (this._initialized) {
61
+ return;
62
+ }
63
+ const addressStr = await this._account.getAddress();
64
+ this._address = addressStr;
65
+ this._initialized = true;
66
+ }
67
+ /**
68
+ * Sign transactions with this signer
69
+ *
70
+ * This method signs the message bytes of each transaction and returns
71
+ * signature dictionaries mapping address to signature.
72
+ *
73
+ * @param transactions - Array of transactions to sign
74
+ * @returns Array of signature dictionaries
75
+ */
76
+ async signTransactions(transactions) {
77
+ if (!transactions || transactions.length === 0) {
78
+ return [];
79
+ }
80
+ const results = [];
81
+ for (const tx of transactions) {
82
+ if (!tx.messageBytes || tx.messageBytes.length === 0) {
83
+ throw new Error("Transaction messageBytes must not be empty");
84
+ }
85
+ const signature = await this._account.sign(tx.messageBytes);
86
+ results.push({
87
+ [this._address]: signature
88
+ });
89
+ }
90
+ return results;
91
+ }
92
+ /**
93
+ * Sign a single message (utility method)
94
+ * @param message - Message bytes to sign
95
+ * @returns Signature bytes
96
+ */
97
+ async sign(message) {
98
+ return this._account.sign(message);
99
+ }
100
+ /**
101
+ * Get SOL balance in lamports
102
+ */
103
+ async getBalance() {
104
+ return this._account.getBalance();
105
+ }
106
+ /**
107
+ * Get SPL token balance
108
+ * @param mint - Token mint address
109
+ */
110
+ async getTokenBalance(mint) {
111
+ return this._account.getTokenBalance(mint);
112
+ }
113
+ /**
114
+ * Transfer SPL tokens
115
+ * @param params - Transfer parameters
116
+ * @returns Transaction signature
117
+ */
118
+ async transfer(params) {
119
+ return this._account.transfer(params);
120
+ }
121
+ };
122
+ async function createWDKSvmSigner(account) {
123
+ const adapter = new WDKSvmSignerAdapter(account);
124
+ await adapter.initialize();
125
+ return adapter;
126
+ }
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ WDKSvmSignerAdapter,
130
+ createWDKSvmSigner
131
+ });
132
+ //# sourceMappingURL=svm-adapter.js.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\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CO,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,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,KAAK,SAA0C;AACnD,WAAO,KAAK,SAAS,KAAK,OAAO;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA8B;AAClC,WAAO,KAAK,SAAS,WAAW;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,gBAAgB,MAA+B;AACnD,WAAO,KAAK,SAAS,gBAAgB,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAS,QAA+E;AAC5F,WAAO,KAAK,SAAS,SAAS,MAAM;AAAA,EACtC;AACF;AAqBA,eAAsB,mBAAmB,SAAyD;AAChG,QAAM,UAAU,IAAI,oBAAoB,OAAO;AAC/C,QAAM,QAAQ,WAAW;AACzB,SAAO;AACT;","names":[]}
@@ -0,0 +1,139 @@
1
+ import { a as WDKTonAccount } from '../types-V7c-qhn6.js';
2
+ import 'viem';
3
+
4
+ /**
5
+ * TON Signer Adapter for WDK
6
+ *
7
+ * Wraps a Tether WDK TON account to implement T402's ClientTonSigner interface.
8
+ * This allows WDK-managed TON wallets to be used for T402 payments.
9
+ */
10
+
11
+ /**
12
+ * TON Address type (compatible with @ton/core Address)
13
+ * We define our own interface to avoid direct import
14
+ */
15
+ interface TonAddress {
16
+ toString(): string;
17
+ toRawString(): string;
18
+ }
19
+ /**
20
+ * TON Cell type (compatible with @ton/core Cell)
21
+ * We define our own interface to avoid direct import
22
+ */
23
+ interface TonCell {
24
+ hash(): Uint8Array;
25
+ toBoc(): Uint8Array;
26
+ }
27
+ /**
28
+ * SignMessageParams type matching T402's @t402/ton interface
29
+ */
30
+ interface SignMessageParams {
31
+ /** Destination address */
32
+ to: TonAddress;
33
+ /** Amount of TON to attach (for gas) in nanoTON */
34
+ value: bigint;
35
+ /** Message body (Jetton transfer cell) */
36
+ body: TonCell;
37
+ /** Send mode flags (from @ton/core SendMode) */
38
+ sendMode?: number;
39
+ /** Bounce flag */
40
+ bounce?: boolean;
41
+ /** Message validity timeout in seconds */
42
+ timeout?: number;
43
+ }
44
+ /**
45
+ * ClientTonSigner interface matching T402's @t402/ton
46
+ */
47
+ interface ClientTonSigner {
48
+ readonly address: TonAddress;
49
+ signMessage(params: SignMessageParams): Promise<TonCell>;
50
+ getSeqno(): Promise<number>;
51
+ }
52
+ /**
53
+ * WDKTonSignerAdapter - Adapts a WDK TON account to T402's ClientTonSigner
54
+ *
55
+ * This adapter wraps a Tether WDK TON account and provides T402-compatible
56
+ * signing functionality. The actual message building and signing is delegated
57
+ * to the WDK account, which handles TON-specific details internally.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const adapter = await createWDKTonSigner(wdkTonAccount);
62
+ * const signed = await adapter.signMessage({
63
+ * to: jettonWalletAddress,
64
+ * value: toNano('0.05'),
65
+ * body: jettonTransferBody,
66
+ * });
67
+ * ```
68
+ */
69
+ declare class WDKTonSignerAdapter implements ClientTonSigner {
70
+ private _account;
71
+ private _address;
72
+ private _initialized;
73
+ constructor(account: WDKTonAccount);
74
+ /**
75
+ * Get the wallet address
76
+ * @throws Error if not initialized
77
+ */
78
+ get address(): TonAddress;
79
+ /**
80
+ * Check if the adapter is initialized
81
+ */
82
+ get isInitialized(): boolean;
83
+ /**
84
+ * Initialize the adapter by fetching the address
85
+ * Must be called before using the signer
86
+ */
87
+ initialize(): Promise<void>;
88
+ /**
89
+ * Sign an internal message for Jetton transfer
90
+ *
91
+ * Attempts to build a proper signed Cell using @ton/core if available.
92
+ * Falls back to a simplified wrapper that embeds the raw signature.
93
+ *
94
+ * @param params - Message parameters
95
+ * @returns Signed external message as Cell (BOC)
96
+ */
97
+ signMessage(params: SignMessageParams): Promise<TonCell>;
98
+ /**
99
+ * Get current seqno for the wallet
100
+ * Used for replay protection
101
+ */
102
+ getSeqno(): Promise<number>;
103
+ /**
104
+ * Get TON balance in nanoTON
105
+ */
106
+ getBalance(): Promise<bigint>;
107
+ /**
108
+ * Get Jetton balance
109
+ * @param jettonMaster - Jetton master contract address
110
+ */
111
+ getJettonBalance(jettonMaster: string): Promise<bigint>;
112
+ /**
113
+ * Get the underlying WDK account
114
+ * Useful for advanced operations not covered by this adapter
115
+ */
116
+ getWDKAccount(): WDKTonAccount;
117
+ }
118
+ /**
119
+ * Create an initialized WDK TON signer
120
+ *
121
+ * @param account - WDK TON account from @tetherto/wdk-wallet-ton
122
+ * @returns Initialized ClientTonSigner
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * import { T402WDK } from '@t402/wdk';
127
+ *
128
+ * const wallet = new T402WDK(seedPhrase, config);
129
+ * const tonSigner = await wallet.getTonSigner();
130
+ *
131
+ * // Use with T402 client
132
+ * const client = createT402HTTPClient({
133
+ * signers: [{ scheme: 'exact', network: 'ton:mainnet', signer: tonSigner }]
134
+ * });
135
+ * ```
136
+ */
137
+ declare function createWDKTonSigner(account: WDKTonAccount): Promise<WDKTonSignerAdapter>;
138
+
139
+ export { type ClientTonSigner, type SignMessageParams, type TonAddress, type TonCell, WDKTonSignerAdapter, createWDKTonSigner };
@@ -0,0 +1,152 @@
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/ton-adapter.ts
31
+ var ton_adapter_exports = {};
32
+ __export(ton_adapter_exports, {
33
+ WDKTonSignerAdapter: () => WDKTonSignerAdapter,
34
+ createWDKTonSigner: () => createWDKTonSigner
35
+ });
36
+ module.exports = __toCommonJS(ton_adapter_exports);
37
+ var WDKTonAddress = class {
38
+ constructor(_address) {
39
+ this._address = _address;
40
+ }
41
+ toString() {
42
+ return this._address;
43
+ }
44
+ toRawString() {
45
+ return this._address;
46
+ }
47
+ };
48
+ var WDKTonSignerAdapter = class {
49
+ _account;
50
+ _address = null;
51
+ _initialized = false;
52
+ constructor(account) {
53
+ if (!account) {
54
+ throw new Error("WDK TON account is required");
55
+ }
56
+ this._account = account;
57
+ }
58
+ /**
59
+ * Get the wallet address
60
+ * @throws Error if not initialized
61
+ */
62
+ get address() {
63
+ if (!this._address) {
64
+ throw new Error(
65
+ "TON signer not initialized. Call initialize() first or use createWDKTonSigner()."
66
+ );
67
+ }
68
+ return this._address;
69
+ }
70
+ /**
71
+ * Check if the adapter is initialized
72
+ */
73
+ get isInitialized() {
74
+ return this._initialized;
75
+ }
76
+ /**
77
+ * Initialize the adapter by fetching the address
78
+ * Must be called before using the signer
79
+ */
80
+ async initialize() {
81
+ if (this._initialized) {
82
+ return;
83
+ }
84
+ const addressStr = await this._account.getAddress();
85
+ this._address = new WDKTonAddress(addressStr);
86
+ this._initialized = true;
87
+ }
88
+ /**
89
+ * Sign an internal message for Jetton transfer
90
+ *
91
+ * Attempts to build a proper signed Cell using @ton/core if available.
92
+ * Falls back to a simplified wrapper that embeds the raw signature.
93
+ *
94
+ * @param params - Message parameters
95
+ * @returns Signed external message as Cell (BOC)
96
+ */
97
+ async signMessage(params) {
98
+ const msgHash = params.body.hash();
99
+ const signature = await this._account.signMessage(msgHash);
100
+ try {
101
+ const tonCore = await import("@ton/core");
102
+ const sigBuffer = Buffer.from(signature.buffer, signature.byteOffset, signature.byteLength);
103
+ const bodyBoc = params.body.toBoc();
104
+ const bocBuffer = Buffer.from(bodyBoc.buffer, bodyBoc.byteOffset, bodyBoc.byteLength);
105
+ const signedCell = tonCore.beginCell().storeBuffer(sigBuffer).storeSlice(tonCore.Cell.fromBoc(bocBuffer)[0].beginParse()).endCell();
106
+ return signedCell;
107
+ } catch {
108
+ return {
109
+ hash: () => msgHash,
110
+ toBoc: () => signature
111
+ };
112
+ }
113
+ }
114
+ /**
115
+ * Get current seqno for the wallet
116
+ * Used for replay protection
117
+ */
118
+ async getSeqno() {
119
+ return this._account.getSeqno();
120
+ }
121
+ /**
122
+ * Get TON balance in nanoTON
123
+ */
124
+ async getBalance() {
125
+ return this._account.getBalance();
126
+ }
127
+ /**
128
+ * Get Jetton balance
129
+ * @param jettonMaster - Jetton master contract address
130
+ */
131
+ async getJettonBalance(jettonMaster) {
132
+ return this._account.getJettonBalance(jettonMaster);
133
+ }
134
+ /**
135
+ * Get the underlying WDK account
136
+ * Useful for advanced operations not covered by this adapter
137
+ */
138
+ getWDKAccount() {
139
+ return this._account;
140
+ }
141
+ };
142
+ async function createWDKTonSigner(account) {
143
+ const adapter = new WDKTonSignerAdapter(account);
144
+ await adapter.initialize();
145
+ return adapter;
146
+ }
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ WDKTonSignerAdapter,
150
+ createWDKTonSigner
151
+ });
152
+ //# sourceMappingURL=ton-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/ton-adapter.ts"],"sourcesContent":["/**\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyDA,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,YAAY,QAA6C;AAC7D,UAAM,UAAU,OAAO,KAAK,KAAK;AACjC,UAAM,YAAY,MAAM,KAAK,SAAS,YAAY,OAAO;AAGzD,QAAI;AACF,YAAM,UAAU,MAAM,OAAO,WAAW;AACxC,YAAM,YAAY,OAAO,KAAK,UAAU,QAAQ,UAAU,YAAY,UAAU,UAAU;AAC1F,YAAM,UAAU,OAAO,KAAK,MAAM;AAClC,YAAM,YAAY,OAAO,KAAK,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,UAAU;AACpF,YAAM,aAAa,QAChB,UAAU,EACV,YAAY,SAAS,EACrB,WAAW,QAAQ,KAAK,QAAQ,SAAS,EAAE,CAAC,EAAG,WAAW,CAAC,EAC3D,QAAQ;AACX,aAAO;AAAA,IACT,QAAQ;AAKN,aAAO;AAAA,QACL,MAAM,MAAM;AAAA,QACZ,OAAO,MAAM;AAAA,MACf;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAA4B;AAChC,WAAO,KAAK,SAAS,SAAS;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA8B;AAClC,WAAO,KAAK,SAAS,WAAW;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,iBAAiB,cAAuC;AAC5D,WAAO,KAAK,SAAS,iBAAiB,YAAY;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAA+B;AAC7B,WAAO,KAAK;AAAA,EACd;AACF;AAqBA,eAAsB,mBAAmB,SAAsD;AAC7F,QAAM,UAAU,IAAI,oBAAoB,OAAO;AAC/C,QAAM,QAAQ,WAAW;AACzB,SAAO;AACT;","names":[]}
@@ -0,0 +1,139 @@
1
+ import { b as WDKTronAccount } from '../types-V7c-qhn6.js';
2
+ import 'viem';
3
+
4
+ /**
5
+ * TRON Signer Adapter for WDK
6
+ *
7
+ * Wraps a Tether WDK TRON account to implement T402's ClientTronSigner interface.
8
+ * This allows WDK-managed TRON wallets to be used for T402 payments.
9
+ */
10
+
11
+ /**
12
+ * SignTransactionParams matching T402's @t402/tron interface
13
+ */
14
+ interface SignTransactionParams {
15
+ /** TRC20 contract address */
16
+ contractAddress: string;
17
+ /** Recipient address (T-prefix base58check) */
18
+ to: string;
19
+ /** Amount to transfer (in smallest units) */
20
+ amount: string;
21
+ /** Fee limit in SUN (optional, defaults to 100 TRX) */
22
+ feeLimit?: number;
23
+ /** Transaction expiration time in milliseconds (optional) */
24
+ expiration?: number;
25
+ }
26
+ /**
27
+ * Block info for transaction building
28
+ */
29
+ interface BlockInfo {
30
+ /** Reference block bytes (hex) */
31
+ refBlockBytes: string;
32
+ /** Reference block hash (hex) */
33
+ refBlockHash: string;
34
+ /** Expiration timestamp in milliseconds */
35
+ expiration: number;
36
+ }
37
+ /**
38
+ * ClientTronSigner interface matching T402's @t402/tron
39
+ */
40
+ interface ClientTronSigner {
41
+ readonly address: string;
42
+ signTransaction(params: SignTransactionParams): Promise<string>;
43
+ getBlockInfo(): Promise<BlockInfo>;
44
+ }
45
+ /**
46
+ * WDKTronSignerAdapter - Adapts a WDK TRON account to T402's ClientTronSigner
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const adapter = await createWDKTronSigner(wdkTronAccount);
51
+ * const signedTx = await adapter.signTransaction({
52
+ * contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
53
+ * to: 'TRecipientAddress...',
54
+ * amount: '1000000', // 1 USDT
55
+ * });
56
+ * ```
57
+ */
58
+ declare class WDKTronSignerAdapter implements ClientTronSigner {
59
+ private _account;
60
+ private _address;
61
+ private _initialized;
62
+ private _rpcUrl;
63
+ constructor(account: WDKTronAccount, rpcUrl?: string);
64
+ /**
65
+ * Get the wallet address (T-prefix base58check)
66
+ * @throws Error if not initialized
67
+ */
68
+ get address(): string;
69
+ /**
70
+ * Check if the adapter is initialized
71
+ */
72
+ get isInitialized(): boolean;
73
+ /**
74
+ * Initialize the adapter by fetching the address
75
+ * Must be called before using the signer
76
+ */
77
+ initialize(): Promise<void>;
78
+ /**
79
+ * Sign a TRC20 transfer transaction
80
+ *
81
+ * This method:
82
+ * 1. Builds a TRC20 transfer transaction
83
+ * 2. Signs it using the WDK account
84
+ * 3. Returns the hex-encoded signed transaction
85
+ *
86
+ * @param params - Transaction parameters
87
+ * @returns Hex-encoded signed transaction
88
+ */
89
+ signTransaction(params: SignTransactionParams): Promise<string>;
90
+ /**
91
+ * Get the current reference block info for transaction building
92
+ * This is required for TRON's replay protection mechanism
93
+ */
94
+ getBlockInfo(): Promise<BlockInfo>;
95
+ /**
96
+ * Build a TRC20 transfer transaction
97
+ */
98
+ private buildTrc20Transaction;
99
+ /**
100
+ * Serialize a signed transaction to hex format
101
+ */
102
+ private serializeTransaction;
103
+ /**
104
+ * Convert TRON base58 address to hex format
105
+ */
106
+ private addressToHex;
107
+ /**
108
+ * Get TRX balance in SUN
109
+ */
110
+ getBalance(): Promise<bigint>;
111
+ /**
112
+ * Get TRC20 token balance
113
+ * @param contractAddress - TRC20 contract address
114
+ */
115
+ getTrc20Balance(contractAddress: string): Promise<bigint>;
116
+ }
117
+ /**
118
+ * Create an initialized WDK TRON signer
119
+ *
120
+ * @param account - WDK TRON account from @tetherto/wdk-wallet-tron
121
+ * @param rpcUrl - Optional custom RPC URL (default: https://api.trongrid.io)
122
+ * @returns Initialized ClientTronSigner
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * import { T402WDK } from '@t402/wdk';
127
+ *
128
+ * const wallet = new T402WDK(seedPhrase, config);
129
+ * const tronSigner = await wallet.getTronSigner();
130
+ *
131
+ * // Use with T402 client
132
+ * const client = createT402HTTPClient({
133
+ * signers: [{ scheme: 'exact', network: 'tron:mainnet', signer: tronSigner }]
134
+ * });
135
+ * ```
136
+ */
137
+ declare function createWDKTronSigner(account: WDKTronAccount, rpcUrl?: string): Promise<WDKTronSignerAdapter>;
138
+
139
+ export { type BlockInfo, type ClientTronSigner, type SignTransactionParams, WDKTronSignerAdapter, createWDKTronSigner };