@t402/ton 2.3.0 → 2.3.1

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 (2) hide show
  1. package/README.md +147 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # @t402/ton
2
+
3
+ TON blockchain implementation of the t402 payment protocol using the **Exact** payment scheme with Jetton (TEP-74) transfers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @t402/ton
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ This package provides three main components for handling t402 payments on TON:
14
+
15
+ - **Client** - For applications that need to make payments (sign Jetton transfer messages)
16
+ - **Server** - For resource servers that accept payments and build payment requirements
17
+ - **Facilitator** - For payment processors that verify signatures and execute on-chain settlements
18
+
19
+ ## Quick Start
20
+
21
+ ### Client
22
+
23
+ ```typescript
24
+ import { ExactTonScheme, toClientTonSigner } from "@t402/ton";
25
+ import { mnemonicToPrivateKey } from "@ton/crypto";
26
+
27
+ const keyPair = await mnemonicToPrivateKey(mnemonic.split(" "));
28
+ const signer = toClientTonSigner(keyPair);
29
+
30
+ const client = new ExactTonScheme(signer);
31
+ const payload = await client.createPaymentPayload(requirements);
32
+ ```
33
+
34
+ ### Server
35
+
36
+ ```typescript
37
+ import { registerExactTonServerScheme } from "@t402/ton";
38
+ import { t402ResourceServer } from "@t402/express";
39
+ import { HTTPFacilitatorClient } from "@t402/core/server";
40
+
41
+ const facilitator = new HTTPFacilitatorClient({ url: "https://facilitator.t402.io" });
42
+ const resourceServer = new t402ResourceServer(facilitator);
43
+ registerExactTonServerScheme(resourceServer);
44
+ ```
45
+
46
+ ### Facilitator
47
+
48
+ ```typescript
49
+ import { registerExactTonFacilitatorScheme, toFacilitatorTonSigner } from "@t402/ton";
50
+ import { mnemonicToPrivateKey } from "@ton/crypto";
51
+
52
+ const keyPair = await mnemonicToPrivateKey(mnemonic.split(" "));
53
+ const signer = toFacilitatorTonSigner(keyPair);
54
+
55
+ registerExactTonFacilitatorScheme(facilitator, { signer });
56
+ ```
57
+
58
+ ## Package Exports
59
+
60
+ ### Main Package (`@t402/ton`)
61
+
62
+ - `ExactTonScheme` - Main scheme class
63
+ - `registerExactTonClientScheme` - Register client with t402Client
64
+ - `registerExactTonServerScheme` - Register server with t402ResourceServer
65
+ - `registerExactTonFacilitatorScheme` - Register with facilitator
66
+ - `toClientTonSigner` / `toFacilitatorTonSigner` - Signer converters
67
+
68
+ ### Subpath Exports
69
+
70
+ - `@t402/ton/exact/client` - Client-only imports
71
+ - `@t402/ton/exact/server` - Server-only imports
72
+ - `@t402/ton/exact/facilitator` - Facilitator-only imports
73
+
74
+ ## Supported Networks
75
+
76
+ | Network | CAIP-2 Identifier |
77
+ |---------|-------------------|
78
+ | TON Mainnet | `ton:mainnet` |
79
+ | TON Testnet | `ton:testnet` |
80
+
81
+ ## Supported Assets
82
+
83
+ | Token | Network | Jetton Address |
84
+ |-------|---------|----------------|
85
+ | USDT | Mainnet | `EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs` |
86
+ | USDT | Testnet | `kQBqSpvo4S87mX9tTc4FX3Sfqf4uSp3Tx-Fz4RBUfTRWBx` |
87
+
88
+ ## Token Utilities
89
+
90
+ ```typescript
91
+ import {
92
+ getJettonConfig,
93
+ getNetworkJettons,
94
+ getDefaultJetton,
95
+ getSupportedNetworks,
96
+ isNetworkSupported,
97
+ } from "@t402/ton";
98
+
99
+ // Check if a network is supported
100
+ isNetworkSupported("ton:mainnet"); // true
101
+
102
+ // Get USDT config for mainnet
103
+ const config = getJettonConfig("ton:mainnet", "USDT");
104
+
105
+ // Get all supported networks
106
+ const networks = getSupportedNetworks();
107
+ ```
108
+
109
+ ## Address & Amount Utilities
110
+
111
+ ```typescript
112
+ import {
113
+ validateTonAddress,
114
+ convertToJettonAmount,
115
+ convertFromJettonAmount,
116
+ buildJettonTransferBody,
117
+ estimateJettonTransferGas,
118
+ } from "@t402/ton";
119
+
120
+ // Validate TON address
121
+ validateTonAddress("EQ..."); // true/false
122
+
123
+ // Convert amounts (6 decimals for USDT)
124
+ convertToJettonAmount("1.5", 6); // 1500000n
125
+ convertFromJettonAmount(1500000n, 6); // "1.5"
126
+ ```
127
+
128
+ ## Security
129
+
130
+ - Client signs Jetton transfer messages off-chain using Ed25519
131
+ - Replay protection via unique `query_id` per transaction
132
+ - Facilitator verifies signatures before broadcasting to TON network
133
+
134
+ ## Development
135
+
136
+ ```bash
137
+ pnpm build # Build the package
138
+ pnpm test # Run unit tests
139
+ pnpm test:integration # Run integration tests
140
+ ```
141
+
142
+ ## Related Packages
143
+
144
+ - `@t402/core` - Core protocol types and client
145
+ - `@t402/fetch` - HTTP wrapper with automatic payment handling
146
+ - `@t402/evm` - EVM chains implementation
147
+ - `@t402/svm` - Solana implementation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t402/ton",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "@ton/core": "^0.62.1",
39
39
  "@ton/crypto": "^3.2.0",
40
40
  "@ton/ton": "^16.1.0",
41
- "@t402/core": "2.3.0"
41
+ "@t402/core": "2.3.1"
42
42
  },
43
43
  "exports": {
44
44
  ".": {