@tokenizedrealutility/sdk 1.0.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/API.md +210 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE +201 -0
- package/NOTICE +40 -0
- package/README.md +559 -0
- package/SECURITY.md +34 -0
- package/dist/client.d.ts +59 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +83 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +71 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +8 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +52 -0
- package/dist/events.js.map +1 -0
- package/dist/explorer.d.ts +53 -0
- package/dist/explorer.d.ts.map +1 -0
- package/dist/explorer.js +39 -0
- package/dist/explorer.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/ai.d.ts +20 -0
- package/dist/modules/ai.d.ts.map +1 -0
- package/dist/modules/ai.js +18 -0
- package/dist/modules/ai.js.map +1 -0
- package/dist/modules/base.d.ts +8 -0
- package/dist/modules/base.d.ts.map +1 -0
- package/dist/modules/base.js +8 -0
- package/dist/modules/base.js.map +1 -0
- package/dist/modules/chain.d.ts +15 -0
- package/dist/modules/chain.d.ts.map +1 -0
- package/dist/modules/chain.js +12 -0
- package/dist/modules/chain.js.map +1 -0
- package/dist/modules/contracts.d.ts +13 -0
- package/dist/modules/contracts.d.ts.map +1 -0
- package/dist/modules/contracts.js +16 -0
- package/dist/modules/contracts.js.map +1 -0
- package/dist/modules/htlc.d.ts +43 -0
- package/dist/modules/htlc.d.ts.map +1 -0
- package/dist/modules/htlc.js +25 -0
- package/dist/modules/htlc.js.map +1 -0
- package/dist/modules/identity.d.ts +9 -0
- package/dist/modules/identity.d.ts.map +1 -0
- package/dist/modules/identity.js +15 -0
- package/dist/modules/identity.js.map +1 -0
- package/dist/modules/magic.d.ts +17 -0
- package/dist/modules/magic.d.ts.map +1 -0
- package/dist/modules/magic.js +14 -0
- package/dist/modules/magic.js.map +1 -0
- package/dist/modules/mining.d.ts +16 -0
- package/dist/modules/mining.d.ts.map +1 -0
- package/dist/modules/mining.js +23 -0
- package/dist/modules/mining.js.map +1 -0
- package/dist/modules/network.d.ts +6 -0
- package/dist/modules/network.d.ts.map +1 -0
- package/dist/modules/network.js +5 -0
- package/dist/modules/network.js.map +1 -0
- package/dist/modules/raw.d.ts +8 -0
- package/dist/modules/raw.d.ts.map +1 -0
- package/dist/modules/raw.js +10 -0
- package/dist/modules/raw.js.map +1 -0
- package/dist/modules/swaps.d.ts +12 -0
- package/dist/modules/swaps.d.ts.map +1 -0
- package/dist/modules/swaps.js +16 -0
- package/dist/modules/swaps.js.map +1 -0
- package/dist/modules/system.d.ts +11 -0
- package/dist/modules/system.d.ts.map +1 -0
- package/dist/modules/system.js +64 -0
- package/dist/modules/system.js.map +1 -0
- package/dist/modules/tokens.d.ts +65 -0
- package/dist/modules/tokens.d.ts.map +1 -0
- package/dist/modules/tokens.js +54 -0
- package/dist/modules/tokens.js.map +1 -0
- package/dist/modules/transactions.d.ts +22 -0
- package/dist/modules/transactions.d.ts.map +1 -0
- package/dist/modules/transactions.js +30 -0
- package/dist/modules/transactions.js.map +1 -0
- package/dist/modules/truscripts.d.ts +22 -0
- package/dist/modules/truscripts.d.ts.map +1 -0
- package/dist/modules/truscripts.js +14 -0
- package/dist/modules/truscripts.js.map +1 -0
- package/dist/modules/wallet.d.ts +18 -0
- package/dist/modules/wallet.d.ts.map +1 -0
- package/dist/modules/wallet.js +16 -0
- package/dist/modules/wallet.js.map +1 -0
- package/dist/neromesh.d.ts +58 -0
- package/dist/neromesh.d.ts.map +1 -0
- package/dist/neromesh.js +92 -0
- package/dist/neromesh.js.map +1 -0
- package/dist/rpc-catalog.d.ts +4 -0
- package/dist/rpc-catalog.d.ts.map +1 -0
- package/dist/rpc-catalog.js +115 -0
- package/dist/rpc-catalog.js.map +1 -0
- package/dist/transport.d.ts +29 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +144 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/address.d.ts +4 -0
- package/dist/utils/address.d.ts.map +1 -0
- package/dist/utils/address.js +12 -0
- package/dist/utils/address.js.map +1 -0
- package/dist/utils/amount.d.ts +6 -0
- package/dist/utils/amount.d.ts.map +1 -0
- package/dist/utils/amount.js +23 -0
- package/dist/utils/amount.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
# TRU SDK
|
|
2
|
+
|
|
3
|
+
**TRU SDK v1.0.0** is the first TypeScript/JavaScript developer SDK for **TRU — Tokenized Real Utility**.
|
|
4
|
+
|
|
5
|
+
It gives application developers one organized API for TRU Core JSON-RPC, the public Explorer API, TRUScripts, native tokens, contracts, Magic Locks, mining telemetry, AI/evolution, HTLC/swap primitives, DID/social functions, and NEROMESH / AXON HTTP services.
|
|
6
|
+
|
|
7
|
+
> Official npm package: `@tokenizedrealutility/sdk`
|
|
8
|
+
|
|
9
|
+
## Goals
|
|
10
|
+
|
|
11
|
+
The SDK is intentionally an **application/developer layer**, not a second consensus implementation.
|
|
12
|
+
|
|
13
|
+
TRU Core remains authoritative for:
|
|
14
|
+
|
|
15
|
+
- chain state
|
|
16
|
+
- consensus and block validation
|
|
17
|
+
- transaction validation
|
|
18
|
+
- wallet signing when Core-wallet RPCs are used
|
|
19
|
+
- token issuance/transfer rules
|
|
20
|
+
- contract execution
|
|
21
|
+
- TRUScript rules
|
|
22
|
+
- Magic Locks
|
|
23
|
+
- mining work construction and block submission
|
|
24
|
+
- HTLC/swap wallet operations
|
|
25
|
+
|
|
26
|
+
The SDK provides:
|
|
27
|
+
|
|
28
|
+
- typed, discoverable modules
|
|
29
|
+
- JSON-RPC transport and Bearer authentication
|
|
30
|
+
- browser-safe public gateway support
|
|
31
|
+
- consistent error classes
|
|
32
|
+
- exact TRU amount helpers using `bigint`
|
|
33
|
+
- current-mainnet address validation
|
|
34
|
+
- Explorer REST access
|
|
35
|
+
- NEROMESH / AXON access
|
|
36
|
+
- raw RPC escape hatch for forward compatibility
|
|
37
|
+
- a source-derived catalog of the current Core RPC surface
|
|
38
|
+
- block polling/events for application development
|
|
39
|
+
|
|
40
|
+
## Coverage in v1.0.0
|
|
41
|
+
|
|
42
|
+
The source-derived RPC catalog currently contains **106 TRU Core methods** grouped across:
|
|
43
|
+
|
|
44
|
+
- chain / blocks
|
|
45
|
+
- network / peers
|
|
46
|
+
- wallet
|
|
47
|
+
- transactions / UTXOs / mempool
|
|
48
|
+
- native tokens: FT / NFT / SFT / NCFT
|
|
49
|
+
- token metadata / burn / evolution
|
|
50
|
+
- TRUScripts
|
|
51
|
+
- contracts / hashlocks / timelocks / Voting V1 helpers
|
|
52
|
+
- Magic Locks / Magic Secrets
|
|
53
|
+
- mining / miner telemetry
|
|
54
|
+
- AI providers / AI tokens
|
|
55
|
+
- DID / social
|
|
56
|
+
- HTLC primitives
|
|
57
|
+
- swap records / role keys
|
|
58
|
+
- AXON wallet handoff RPCs
|
|
59
|
+
- chain data-provider calls
|
|
60
|
+
|
|
61
|
+
The public Explorer client covers the currently reviewed REST routes for stats, blocks, addresses, transactions, tokens, contracts, miners, miner reports, difficulty/hashrate history, TRUScripts, peers, DID/social, wallet-token views, price and hashrate.
|
|
62
|
+
|
|
63
|
+
The NEROMESH client covers public health/stats, direct-job compatibility APIs, AXON customer offer/funding/wallet-handoff flows, standalone worker APIs, and the current customer/worker/network portal endpoints.
|
|
64
|
+
|
|
65
|
+
For any newly added Core RPC that does not yet have a friendly method, use:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
await tru.raw.call("newmethod", { ...params });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
From a local checkout:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm install
|
|
77
|
+
npm run build
|
|
78
|
+
npm test
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
After publishing to npm:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npm install @tokenizedrealutility/sdk
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Requires Node.js 18+ for native `fetch`, or a modern browser/bundler.
|
|
88
|
+
|
|
89
|
+
## Quick start — local TRU Core
|
|
90
|
+
|
|
91
|
+
Direct Core RPC is privileged. Read the Core RPC cookie/token on the server side and pass the token to the SDK.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { readFile } from "node:fs/promises";
|
|
95
|
+
import { TruClient } from "@tokenizedrealutility/sdk";
|
|
96
|
+
|
|
97
|
+
const token = (await readFile(
|
|
98
|
+
`${process.env.HOME}/.tru/rpc-cookie-21832`,
|
|
99
|
+
"utf8"
|
|
100
|
+
)).trim();
|
|
101
|
+
|
|
102
|
+
const tru = new TruClient({
|
|
103
|
+
core: {
|
|
104
|
+
endpoint: "http://127.0.0.1:21832/rpc",
|
|
105
|
+
token
|
|
106
|
+
},
|
|
107
|
+
explorerUrl: "https://tokenizedrealutility.com",
|
|
108
|
+
neromesh: "https://tru.neromesh.space"
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
console.log(await tru.chain.getChainInfo());
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Never place a privileged Core token in browser JavaScript
|
|
115
|
+
|
|
116
|
+
For browser applications, use the public allowlisted gateway instead:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { TruClient } from "@tokenizedrealutility/sdk";
|
|
120
|
+
|
|
121
|
+
const tru = TruClient.public({
|
|
122
|
+
explorerUrl: "https://tokenizedrealutility.com",
|
|
123
|
+
gateway: "wallet"
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const info = await tru.system.getDesktopInfo();
|
|
127
|
+
console.log(info);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The public gateway intentionally exposes only an allowlisted subset of Core functionality.
|
|
131
|
+
|
|
132
|
+
## Chain
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const info = await tru.chain.getChainInfo();
|
|
136
|
+
const height = await tru.chain.getBlockCount();
|
|
137
|
+
const block = await tru.chain.getBlockByHeight(29408);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Wallet
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const address = "T...";
|
|
144
|
+
|
|
145
|
+
const balance = await tru.wallet.getBalance(address);
|
|
146
|
+
const utxos = await tru.wallet.listUnspent(address);
|
|
147
|
+
const history = await tru.transactions.getAddressTransactions(address, 100);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Privileged local Core wallet:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
const created = await tru.wallet.getNewAddress();
|
|
154
|
+
|
|
155
|
+
await tru.wallet.sendToAddress(
|
|
156
|
+
"TRecipient...",
|
|
157
|
+
"1.25000000"
|
|
158
|
+
);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Exact TRU amounts
|
|
162
|
+
|
|
163
|
+
Do not use binary floating point for application accounting.
|
|
164
|
+
|
|
165
|
+
TRU uses:
|
|
166
|
+
|
|
167
|
+
```text
|
|
168
|
+
1 TRU = 100,000,000 atoms
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Use the SDK helpers:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { parseTru, formatTru } from "@tokenizedrealutility/sdk";
|
|
175
|
+
|
|
176
|
+
const atoms = parseTru("45.25000000");
|
|
177
|
+
// 4525000000n
|
|
178
|
+
|
|
179
|
+
console.log(formatTru(atoms));
|
|
180
|
+
// 45.25000000
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Invalid precision is rejected:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
parseTru("0.000000001"); // throws
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Tokens
|
|
190
|
+
|
|
191
|
+
### Issue
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
const result = await tru.tokens.issue({
|
|
195
|
+
type: "FT",
|
|
196
|
+
name: "Example Token",
|
|
197
|
+
symbol: "EXT",
|
|
198
|
+
supply: "1000000",
|
|
199
|
+
decimals: 8,
|
|
200
|
+
description: "Built with the TRU SDK",
|
|
201
|
+
address: "TIssuer..."
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
TRU token families can be passed through the native Core token RPCs, including:
|
|
206
|
+
|
|
207
|
+
```text
|
|
208
|
+
FT
|
|
209
|
+
NFT
|
|
210
|
+
SFT
|
|
211
|
+
NCFT
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Transfer
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
await tru.tokens.send(
|
|
218
|
+
"TOKEN_ID",
|
|
219
|
+
"TRecipient...",
|
|
220
|
+
"1",
|
|
221
|
+
"TSender..."
|
|
222
|
+
);
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Metadata / balance / burn
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
await tru.tokens.metadata("TXID");
|
|
229
|
+
await tru.tokens.verifyMetadata("TXID");
|
|
230
|
+
await tru.tokens.verifyBalance("TOKEN_ID", "TAddress...");
|
|
231
|
+
await tru.tokens.burn("TOKEN_ID", "TSender...", true);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Token evolution
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
const preview = await tru.tokens.previewEvolution({
|
|
238
|
+
tokenID: "TOKEN_ID",
|
|
239
|
+
owner: "TOwner...",
|
|
240
|
+
trigger: "milestone reached"
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Signed evolution commits remain subject to Core's authoritative signature/authority checks.
|
|
245
|
+
|
|
246
|
+
## TRUScripts
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
await tru.scripts.list("TOwner...");
|
|
250
|
+
await tru.scripts.details("TXID");
|
|
251
|
+
|
|
252
|
+
await tru.scripts.inscribe(
|
|
253
|
+
"TOwner...",
|
|
254
|
+
{ message: "Hello TRU" }
|
|
255
|
+
);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Self-custody clients can use the signed transaction RPC wrappers where available rather than giving the server private keys.
|
|
259
|
+
|
|
260
|
+
## Contracts
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
const contracts = await tru.contracts.list();
|
|
264
|
+
|
|
265
|
+
const tx = await tru.contracts.createTransaction({
|
|
266
|
+
type: "...",
|
|
267
|
+
name: "...",
|
|
268
|
+
senderAddress: "T...",
|
|
269
|
+
scriptHex: "...",
|
|
270
|
+
amount: "...",
|
|
271
|
+
fee: "...",
|
|
272
|
+
utxo: { /* Core-compatible UTXO */ }
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Hashlock/timelock and Voting V1 helper RPCs are also exposed.
|
|
277
|
+
|
|
278
|
+
## Magic Locks
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
await tru.magic.create({
|
|
282
|
+
amount: "1.00000000",
|
|
283
|
+
targetPrefix: "000000",
|
|
284
|
+
address: "T..."
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const locks = await tru.magic.list("T...");
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Magic Secret preparation/read/publish RPCs are exposed separately because publication is an operator-gated privileged action.
|
|
291
|
+
|
|
292
|
+
## Mining
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
await tru.mining.register("TMiner...");
|
|
296
|
+
|
|
297
|
+
await tru.mining.reportActivity(
|
|
298
|
+
"TMiner...",
|
|
299
|
+
2_450_000_000,
|
|
300
|
+
1.0
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
const status = await tru.mining.status("TMiner...");
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Canonical work:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
const work = await tru.mining.getTemplate(
|
|
310
|
+
"TMiner...",
|
|
311
|
+
1
|
|
312
|
+
);
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
TRU Core remains authoritative for the candidate and final `submitblock` validation.
|
|
316
|
+
|
|
317
|
+
## AI / evolution
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
const providers = await tru.ai.providers();
|
|
321
|
+
const state = await tru.ai.tokenState("TOKEN_ID");
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Privileged operator applications can configure providers, create AI tokens, interact, retrieve responses and train AI tokens through the corresponding Core RPCs.
|
|
325
|
+
|
|
326
|
+
## DID / social
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
const mapping = await tru.identity.getDid("did:tru:example");
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Both Core-managed and signed DID registration paths are exposed where present.
|
|
333
|
+
|
|
334
|
+
## HTLC / swaps
|
|
335
|
+
|
|
336
|
+
Low-level canonical TRU HTLC operations are available under:
|
|
337
|
+
|
|
338
|
+
```ts
|
|
339
|
+
tru.htlc
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Swap state/role helpers are available under:
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
tru.swaps
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Examples:
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
const secret = await tru.htlc.generateSecret();
|
|
352
|
+
const records = await tru.swaps.recordList();
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
These are low-level financial primitives. Applications should preserve the Core's safety/idempotency model and should not automatically repeat funding after an ambiguous response.
|
|
356
|
+
|
|
357
|
+
## Explorer
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
const stats = await tru.explorer?.stats();
|
|
361
|
+
const miners = await tru.explorer?.miners({ timeout: 2, recent: 50 });
|
|
362
|
+
const reports = await tru.explorer?.minerReports();
|
|
363
|
+
const tokens = await tru.explorer?.tokens({ limit: 50 });
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
The Explorer client is read-only except for RPC gateways handled by `TruClient.public()`.
|
|
367
|
+
|
|
368
|
+
## NEROMESH / AXON
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
import { NeromeshClient } from "@tokenizedrealutility/sdk";
|
|
372
|
+
|
|
373
|
+
const mesh = new NeromeshClient({
|
|
374
|
+
baseUrl: "https://tru.neromesh.space",
|
|
375
|
+
customerToken: process.env.NEROMESH_CUSTOMER_TOKEN
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
console.log(await mesh.health());
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Post a marketplace offer:
|
|
382
|
+
|
|
383
|
+
```ts
|
|
384
|
+
const offer = await mesh.createOffer({
|
|
385
|
+
job_type: "text.generate",
|
|
386
|
+
privacy_tier: "community",
|
|
387
|
+
accept_community_processing: true,
|
|
388
|
+
reward_tru: "0.01000000",
|
|
389
|
+
input: {
|
|
390
|
+
prompt: "Write three original names for a science-fiction city.",
|
|
391
|
+
max_output_tokens: 128
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
NEROMESH credentials such as customer, worker, installation and wallet-capability tokens are secrets. Do not put them in URLs or commit them to source control.
|
|
397
|
+
|
|
398
|
+
## Block events
|
|
399
|
+
|
|
400
|
+
The first SDK provides a polling abstraction so application code does not need to hand-roll block polling:
|
|
401
|
+
|
|
402
|
+
```ts
|
|
403
|
+
const controller = new AbortController();
|
|
404
|
+
|
|
405
|
+
tru.events.watchBlocks(
|
|
406
|
+
({ height, block }) => {
|
|
407
|
+
console.log("new block", height, block);
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
intervalMs: 2000,
|
|
411
|
+
signal: controller.signal
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
The abstraction can later move to WebSocket/SSE notifications without forcing applications to redesign their business logic.
|
|
417
|
+
|
|
418
|
+
## Error handling
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
import {
|
|
422
|
+
TruNodeBusyError,
|
|
423
|
+
TruInsufficientFundsError,
|
|
424
|
+
TruTokenNotFoundError
|
|
425
|
+
} from "@tokenizedrealutility/sdk";
|
|
426
|
+
|
|
427
|
+
try {
|
|
428
|
+
await tru.tokens.send("TOKEN", "T...", "1");
|
|
429
|
+
} catch (error) {
|
|
430
|
+
if (error instanceof TruNodeBusyError) {
|
|
431
|
+
// retry only when your operation is safe to retry
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
SDK error classes include:
|
|
437
|
+
|
|
438
|
+
```text
|
|
439
|
+
TruError
|
|
440
|
+
TruRpcError
|
|
441
|
+
TruHttpError
|
|
442
|
+
TruAuthError
|
|
443
|
+
TruNodeBusyError
|
|
444
|
+
TruTimeoutError
|
|
445
|
+
TruNetworkError
|
|
446
|
+
TruInvalidAddressError
|
|
447
|
+
TruInsufficientFundsError
|
|
448
|
+
TruTokenNotFoundError
|
|
449
|
+
TruTransactionRejectedError
|
|
450
|
+
TruContractExecutionError
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
The transport **does not automatically retry writes**. This is intentional: blindly retrying a transaction/funding operation can duplicate side effects. Explicit per-call retries are available through the raw transport when an operation is known to be idempotent.
|
|
454
|
+
|
|
455
|
+
## Raw RPC
|
|
456
|
+
|
|
457
|
+
The SDK will not block developers from new Core functionality:
|
|
458
|
+
|
|
459
|
+
```ts
|
|
460
|
+
const result = await tru.raw.call(
|
|
461
|
+
"someFutureRpc",
|
|
462
|
+
{ value: "example" }
|
|
463
|
+
);
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Inspect the current catalog:
|
|
467
|
+
|
|
468
|
+
```ts
|
|
469
|
+
import { RPC_CATALOG } from "@tokenizedrealutility/sdk";
|
|
470
|
+
|
|
471
|
+
for (const method of RPC_CATALOG) {
|
|
472
|
+
console.log(method.method, method.category, method.gateway);
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
## Compatibility check
|
|
477
|
+
|
|
478
|
+
```ts
|
|
479
|
+
console.log(await tru.system.compatibility("0.07.5"));
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
The result reports the SDK version, minimum requested Core version, detected version when Core exposes one, and whether the comparison is known to be compatible.
|
|
483
|
+
|
|
484
|
+
## Browser security model
|
|
485
|
+
|
|
486
|
+
Do **not** bundle any of these into a web application:
|
|
487
|
+
|
|
488
|
+
```text
|
|
489
|
+
TRU Core bearer/cookie token
|
|
490
|
+
wallet private keys
|
|
491
|
+
seed phrases
|
|
492
|
+
NEROMESH nmc_ customer credentials unless intentionally entered into a secure flow
|
|
493
|
+
NEROMESH worker/private credentials
|
|
494
|
+
AXON axc_ capabilities beyond their intended short-lived handoff
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
Browser applications should use:
|
|
498
|
+
|
|
499
|
+
- the Explorer's allowlisted wallet/mining gateway
|
|
500
|
+
- signed/self-custody transaction flows
|
|
501
|
+
- secure server backends for privileged operations
|
|
502
|
+
- the NEROMESH portal/session model where appropriate
|
|
503
|
+
|
|
504
|
+
## Project structure
|
|
505
|
+
|
|
506
|
+
```text
|
|
507
|
+
TRU_SDK_v1.0.0/
|
|
508
|
+
├── src/
|
|
509
|
+
│ ├── client.ts
|
|
510
|
+
│ ├── transport.ts
|
|
511
|
+
│ ├── errors.ts
|
|
512
|
+
│ ├── rpc-catalog.ts
|
|
513
|
+
│ ├── explorer.ts
|
|
514
|
+
│ ├── neromesh.ts
|
|
515
|
+
│ ├── events.ts
|
|
516
|
+
│ ├── modules/
|
|
517
|
+
│ │ ├── chain.ts
|
|
518
|
+
│ │ ├── wallet.ts
|
|
519
|
+
│ │ ├── transactions.ts
|
|
520
|
+
│ │ ├── tokens.ts
|
|
521
|
+
│ │ ├── truscripts.ts
|
|
522
|
+
│ │ ├── contracts.ts
|
|
523
|
+
│ │ ├── magic.ts
|
|
524
|
+
│ │ ├── mining.ts
|
|
525
|
+
│ │ ├── ai.ts
|
|
526
|
+
│ │ ├── identity.ts
|
|
527
|
+
│ │ ├── htlc.ts
|
|
528
|
+
│ │ ├── swaps.ts
|
|
529
|
+
│ │ ├── system.ts
|
|
530
|
+
│ │ └── raw.ts
|
|
531
|
+
│ └── utils/
|
|
532
|
+
│ ├── amount.ts
|
|
533
|
+
│ └── address.ts
|
|
534
|
+
├── examples/
|
|
535
|
+
├── tests/
|
|
536
|
+
├── API.md
|
|
537
|
+
├── SECURITY.md
|
|
538
|
+
├── CHANGELOG.md
|
|
539
|
+
├── package.json
|
|
540
|
+
└── tsconfig.json
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
## Build and test
|
|
544
|
+
|
|
545
|
+
```bash
|
|
546
|
+
npm install
|
|
547
|
+
npm run typecheck
|
|
548
|
+
npm test
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
The v1.0.0 package has no runtime npm dependencies. It uses standards-based `fetch` and JSON.
|
|
552
|
+
|
|
553
|
+
## Version
|
|
554
|
+
|
|
555
|
+
```text
|
|
556
|
+
TRU SDK v1.0.0
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
Initial public developer SDK for TRU Core, Explorer, and NEROMESH / AXON integration.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# TRU SDK Security Notes
|
|
2
|
+
|
|
3
|
+
## Privileged Core RPC
|
|
4
|
+
|
|
5
|
+
Treat the TRU Core RPC bearer/cookie token as a server secret.
|
|
6
|
+
|
|
7
|
+
- Keep privileged Core RPC on loopback or a properly secured private network.
|
|
8
|
+
- Never embed the bearer token into browser JavaScript.
|
|
9
|
+
- Never commit RPC cookies, wallet passwords, seed phrases or private keys.
|
|
10
|
+
|
|
11
|
+
## Browser applications
|
|
12
|
+
|
|
13
|
+
Use the Explorer's allowlisted `/api/wallet/rpc` or `/api/mining/rpc` gateways for browser-safe operations. The allowlist is a security boundary; do not work around it by exposing privileged Core RPC publicly.
|
|
14
|
+
|
|
15
|
+
## Money
|
|
16
|
+
|
|
17
|
+
Use `parseTru()` / `formatTru()` and integer atoms for application accounting. Do not use JavaScript binary floating-point as the authoritative representation of TRU amounts.
|
|
18
|
+
|
|
19
|
+
## Transaction retries
|
|
20
|
+
|
|
21
|
+
Do not blindly retry state-changing RPCs. A network timeout can occur after Core already accepted/broadcast an operation. Inspect the chain/mempool or use an idempotent protocol before repeating a spend, HTLC funding operation, token mutation or marketplace funding action.
|
|
22
|
+
|
|
23
|
+
## NEROMESH / AXON
|
|
24
|
+
|
|
25
|
+
The following are secrets/capabilities and should not appear in logs, URLs or repositories:
|
|
26
|
+
|
|
27
|
+
- `nmc_` customer credentials
|
|
28
|
+
- `nmw_` worker bearer credentials
|
|
29
|
+
- `nmi_` one-use worker invitations
|
|
30
|
+
- `nmp_` worker account credentials
|
|
31
|
+
- `axc_` wallet-handoff capabilities
|
|
32
|
+
- private keys / seed phrases / wallet passwords
|
|
33
|
+
|
|
34
|
+
Public worker IDs, public claim keys, public funding outpoints, job IDs and confirmed transaction IDs are not wallet secrets, but applications should still follow the coordinator's privacy policy.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { FetchLike, RpcTransportOptions, TokenProvider } from "./types.js";
|
|
2
|
+
import { RpcTransport } from "./transport.js";
|
|
3
|
+
import { SystemModule } from "./modules/system.js";
|
|
4
|
+
import { ChainModule } from "./modules/chain.js";
|
|
5
|
+
import { NetworkModule } from "./modules/network.js";
|
|
6
|
+
import { WalletModule } from "./modules/wallet.js";
|
|
7
|
+
import { TransactionsModule } from "./modules/transactions.js";
|
|
8
|
+
import { TokensModule } from "./modules/tokens.js";
|
|
9
|
+
import { TruScriptsModule } from "./modules/truscripts.js";
|
|
10
|
+
import { ContractsModule } from "./modules/contracts.js";
|
|
11
|
+
import { MagicLocksModule } from "./modules/magic.js";
|
|
12
|
+
import { MiningModule } from "./modules/mining.js";
|
|
13
|
+
import { AiModule } from "./modules/ai.js";
|
|
14
|
+
import { IdentityModule } from "./modules/identity.js";
|
|
15
|
+
import { HtlcModule } from "./modules/htlc.js";
|
|
16
|
+
import { SwapsModule } from "./modules/swaps.js";
|
|
17
|
+
import { RawRpcModule } from "./modules/raw.js";
|
|
18
|
+
import { ExplorerClient } from "./explorer.js";
|
|
19
|
+
import { NeromeshClient, type NeromeshOptions } from "./neromesh.js";
|
|
20
|
+
import { TruEvents } from "./events.js";
|
|
21
|
+
export interface TruClientOptions {
|
|
22
|
+
core: RpcTransportOptions;
|
|
23
|
+
explorerUrl?: string;
|
|
24
|
+
neromesh?: NeromeshOptions | string;
|
|
25
|
+
}
|
|
26
|
+
export interface PublicTruClientOptions {
|
|
27
|
+
explorerUrl: string;
|
|
28
|
+
gateway?: "wallet" | "mining";
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
fetch?: FetchLike;
|
|
31
|
+
}
|
|
32
|
+
export declare class TruClient {
|
|
33
|
+
readonly rpc: RpcTransport;
|
|
34
|
+
readonly system: SystemModule;
|
|
35
|
+
readonly chain: ChainModule;
|
|
36
|
+
readonly network: NetworkModule;
|
|
37
|
+
readonly wallet: WalletModule;
|
|
38
|
+
readonly transactions: TransactionsModule;
|
|
39
|
+
readonly tokens: TokensModule;
|
|
40
|
+
readonly scripts: TruScriptsModule;
|
|
41
|
+
readonly contracts: ContractsModule;
|
|
42
|
+
readonly magic: MagicLocksModule;
|
|
43
|
+
readonly mining: MiningModule;
|
|
44
|
+
readonly ai: AiModule;
|
|
45
|
+
readonly identity: IdentityModule;
|
|
46
|
+
readonly htlc: HtlcModule;
|
|
47
|
+
readonly swaps: SwapsModule;
|
|
48
|
+
readonly raw: RawRpcModule;
|
|
49
|
+
readonly events: TruEvents;
|
|
50
|
+
readonly explorer?: ExplorerClient;
|
|
51
|
+
readonly neromesh?: NeromeshClient;
|
|
52
|
+
constructor(options: TruClientOptions);
|
|
53
|
+
static direct(endpoint: string, token: TokenProvider, extras?: Omit<TruClientOptions, "core"> & {
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
fetch?: FetchLike;
|
|
56
|
+
}): TruClient;
|
|
57
|
+
static public(options: PublicTruClientOptions): TruClient;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"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"}
|