@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.
- package/README.md +8 -0
- package/dist/cjs/adapters/index.d.ts +5 -0
- package/dist/cjs/adapters/index.js +455 -0
- package/dist/cjs/adapters/index.js.map +1 -0
- package/dist/cjs/adapters/svm-adapter.d.ts +125 -0
- package/dist/cjs/adapters/svm-adapter.js +132 -0
- package/dist/cjs/adapters/svm-adapter.js.map +1 -0
- package/dist/cjs/adapters/ton-adapter.d.ts +139 -0
- package/dist/cjs/adapters/ton-adapter.js +152 -0
- package/dist/cjs/adapters/ton-adapter.js.map +1 -0
- package/dist/cjs/adapters/tron-adapter.d.ts +139 -0
- package/dist/cjs/adapters/tron-adapter.js +221 -0
- package/dist/cjs/adapters/tron-adapter.js.map +1 -0
- package/dist/cjs/index.d.ts +292 -217
- package/dist/cjs/index.js +1042 -23
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types-V7c-qhn6.d.ts +489 -0
- package/dist/esm/adapters/index.d.mts +5 -0
- package/dist/esm/adapters/index.mjs +21 -0
- package/dist/esm/adapters/index.mjs.map +1 -0
- package/dist/esm/adapters/svm-adapter.d.mts +125 -0
- package/dist/esm/adapters/svm-adapter.mjs +9 -0
- package/dist/esm/adapters/svm-adapter.mjs.map +1 -0
- package/dist/esm/adapters/ton-adapter.d.mts +139 -0
- package/dist/esm/adapters/ton-adapter.mjs +9 -0
- package/dist/esm/adapters/ton-adapter.mjs.map +1 -0
- package/dist/esm/adapters/tron-adapter.d.mts +139 -0
- package/dist/esm/adapters/tron-adapter.mjs +9 -0
- package/dist/esm/adapters/tron-adapter.mjs.map +1 -0
- package/dist/esm/chunk-HB2DGKQ3.mjs +196 -0
- package/dist/esm/chunk-HB2DGKQ3.mjs.map +1 -0
- package/dist/esm/chunk-MCFHZSF7.mjs +107 -0
- package/dist/esm/chunk-MCFHZSF7.mjs.map +1 -0
- package/dist/esm/chunk-YWBJJV5M.mjs +117 -0
- package/dist/esm/chunk-YWBJJV5M.mjs.map +1 -0
- package/dist/esm/index.d.mts +292 -217
- package/dist/esm/index.mjs +640 -23
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types-V7c-qhn6.d.mts +489 -0
- package/package.json +70 -6
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/adapters/ton-adapter.ts
|
|
2
|
+
var WDKTonAddress = class {
|
|
3
|
+
constructor(_address) {
|
|
4
|
+
this._address = _address;
|
|
5
|
+
}
|
|
6
|
+
toString() {
|
|
7
|
+
return this._address;
|
|
8
|
+
}
|
|
9
|
+
toRawString() {
|
|
10
|
+
return this._address;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var WDKTonSignerAdapter = class {
|
|
14
|
+
_account;
|
|
15
|
+
_address = null;
|
|
16
|
+
_initialized = false;
|
|
17
|
+
constructor(account) {
|
|
18
|
+
if (!account) {
|
|
19
|
+
throw new Error("WDK TON account is required");
|
|
20
|
+
}
|
|
21
|
+
this._account = account;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the wallet address
|
|
25
|
+
* @throws Error if not initialized
|
|
26
|
+
*/
|
|
27
|
+
get address() {
|
|
28
|
+
if (!this._address) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"TON signer not initialized. Call initialize() first or use createWDKTonSigner()."
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return this._address;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if the adapter is initialized
|
|
37
|
+
*/
|
|
38
|
+
get isInitialized() {
|
|
39
|
+
return this._initialized;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Initialize the adapter by fetching the address
|
|
43
|
+
* Must be called before using the signer
|
|
44
|
+
*/
|
|
45
|
+
async initialize() {
|
|
46
|
+
if (this._initialized) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const addressStr = await this._account.getAddress();
|
|
50
|
+
this._address = new WDKTonAddress(addressStr);
|
|
51
|
+
this._initialized = true;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sign an internal message for Jetton transfer
|
|
55
|
+
*
|
|
56
|
+
* Attempts to build a proper signed Cell using @ton/core if available.
|
|
57
|
+
* Falls back to a simplified wrapper that embeds the raw signature.
|
|
58
|
+
*
|
|
59
|
+
* @param params - Message parameters
|
|
60
|
+
* @returns Signed external message as Cell (BOC)
|
|
61
|
+
*/
|
|
62
|
+
async signMessage(params) {
|
|
63
|
+
const msgHash = params.body.hash();
|
|
64
|
+
const signature = await this._account.signMessage(msgHash);
|
|
65
|
+
try {
|
|
66
|
+
const tonCore = await import("@ton/core");
|
|
67
|
+
const sigBuffer = Buffer.from(signature.buffer, signature.byteOffset, signature.byteLength);
|
|
68
|
+
const bodyBoc = params.body.toBoc();
|
|
69
|
+
const bocBuffer = Buffer.from(bodyBoc.buffer, bodyBoc.byteOffset, bodyBoc.byteLength);
|
|
70
|
+
const signedCell = tonCore.beginCell().storeBuffer(sigBuffer).storeSlice(tonCore.Cell.fromBoc(bocBuffer)[0].beginParse()).endCell();
|
|
71
|
+
return signedCell;
|
|
72
|
+
} catch {
|
|
73
|
+
return {
|
|
74
|
+
hash: () => msgHash,
|
|
75
|
+
toBoc: () => signature
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get current seqno for the wallet
|
|
81
|
+
* Used for replay protection
|
|
82
|
+
*/
|
|
83
|
+
async getSeqno() {
|
|
84
|
+
return this._account.getSeqno();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get TON balance in nanoTON
|
|
88
|
+
*/
|
|
89
|
+
async getBalance() {
|
|
90
|
+
return this._account.getBalance();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get Jetton balance
|
|
94
|
+
* @param jettonMaster - Jetton master contract address
|
|
95
|
+
*/
|
|
96
|
+
async getJettonBalance(jettonMaster) {
|
|
97
|
+
return this._account.getJettonBalance(jettonMaster);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the underlying WDK account
|
|
101
|
+
* Useful for advanced operations not covered by this adapter
|
|
102
|
+
*/
|
|
103
|
+
getWDKAccount() {
|
|
104
|
+
return this._account;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
async function createWDKTonSigner(account) {
|
|
108
|
+
const adapter = new WDKTonSignerAdapter(account);
|
|
109
|
+
await adapter.initialize();
|
|
110
|
+
return adapter;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
WDKTonSignerAdapter,
|
|
115
|
+
createWDKTonSigner
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=chunk-YWBJJV5M.mjs.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":";AAyDA,IAAM,gBAAN,MAA0C;AAAA,EACxC,YAAoB,UAAkB;AAAlB;AAAA,EAAmB;AAAA,EAEvC,W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