@toon-protocol/core 1.2.0 → 1.3.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 +125 -6
- package/dist/index.d.ts +1314 -171
- package/dist/index.js +1491 -148
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @toon-protocol/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Peer discovery, bootstrap, settlement negotiation, and TOON event encoding for the TOON Protocol network.
|
|
4
|
+
|
|
5
|
+
> This is an internal package. Most users should start with [`@toon-protocol/client`](../client) or [`@toon-protocol/sdk`](../sdk).
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -8,18 +10,135 @@ Core library for Nostr-based ILP peer discovery, bootstrap, and settlement negot
|
|
|
8
10
|
npm install @toon-protocol/core
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Key Exports
|
|
14
|
+
|
|
15
|
+
### TOON Codec
|
|
16
|
+
|
|
17
|
+
Encode and decode Nostr events in the compact TOON binary format.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { encodeEventToToon, decodeEventFromToon, shallowParseToon } from '@toon-protocol/core';
|
|
21
|
+
|
|
22
|
+
// Encode a Nostr event to TOON binary format
|
|
23
|
+
const toonBytes = encodeEventToToon(nostrEvent);
|
|
24
|
+
|
|
25
|
+
// Decode back to a Nostr event
|
|
26
|
+
const event = decodeEventFromToon(toonBytes);
|
|
27
|
+
|
|
28
|
+
// Fast metadata extraction without full decode
|
|
29
|
+
const meta = shallowParseToon(toonBytes);
|
|
30
|
+
console.log(meta.kind, meta.pubkey);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Peer Discovery
|
|
34
|
+
|
|
35
|
+
Discover ILP peers from Nostr relays, genesis nodes, or ArDrive registries.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { NostrPeerDiscovery, GenesisPeerLoader, parseIlpPeerInfo } from '@toon-protocol/core';
|
|
39
|
+
|
|
40
|
+
// Query Nostr relays for kind:10032 peer info events
|
|
41
|
+
const discovery = new NostrPeerDiscovery({ relayUrls: ['wss://relay.example.com'] });
|
|
42
|
+
const peers = await discovery.query();
|
|
43
|
+
|
|
44
|
+
// Or load peers from a genesis node
|
|
45
|
+
const loader = new GenesisPeerLoader('http://localhost:3100');
|
|
46
|
+
const genesisPeers = await loader.load();
|
|
47
|
+
|
|
48
|
+
// Parse a raw Nostr event into typed peer info
|
|
49
|
+
const peerInfo = parseIlpPeerInfo(event);
|
|
50
|
+
console.log(peerInfo.ilpAddress, peerInfo.btpEndpoint);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Bootstrap Service
|
|
54
|
+
|
|
55
|
+
Orchestrates the full peer lifecycle: discovery, registration, settlement negotiation, and announcement.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { BootstrapService } from '@toon-protocol/core';
|
|
59
|
+
|
|
60
|
+
const bootstrap = new BootstrapService(config);
|
|
61
|
+
|
|
62
|
+
bootstrap.addEventListener('phase', (e) => {
|
|
63
|
+
console.log('Phase:', e.phase); // 'discovering' → 'registering' → 'announcing' → 'ready'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
await bootstrap.start();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Compose API (Embedded Connector)
|
|
70
|
+
|
|
71
|
+
Wire a full TOON node with zero-latency embedded connector.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { createToonNode } from '@toon-protocol/core';
|
|
75
|
+
|
|
76
|
+
const node = createToonNode({
|
|
77
|
+
connector,
|
|
78
|
+
secretKey,
|
|
79
|
+
basePricePerByte: 10n,
|
|
80
|
+
relayPort: 7100,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
node.on(1, async (ctx) => {
|
|
84
|
+
const event = ctx.decode();
|
|
85
|
+
return ctx.accept();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await node.start();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Event Builders
|
|
92
|
+
|
|
93
|
+
Build typed Nostr events for ILP peer info, service discovery, seed relay lists, and TEE attestation.
|
|
12
94
|
|
|
13
95
|
```ts
|
|
14
96
|
import {
|
|
15
|
-
NostrPeerDiscovery,
|
|
16
|
-
BootstrapService,
|
|
17
|
-
SocialPeerDiscovery,
|
|
18
|
-
parseIlpPeerInfo,
|
|
19
97
|
buildIlpPeerInfoEvent,
|
|
98
|
+
buildServiceDiscoveryEvent,
|
|
99
|
+
buildAttestationEvent,
|
|
100
|
+
buildJobRequestEvent,
|
|
20
101
|
} from '@toon-protocol/core';
|
|
21
102
|
```
|
|
22
103
|
|
|
104
|
+
### Chain Configuration
|
|
105
|
+
|
|
106
|
+
Resolve chain presets for settlement (Anvil, Arbitrum Sepolia, Arbitrum One).
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { resolveChainConfig, CHAIN_PRESETS } from '@toon-protocol/core';
|
|
110
|
+
|
|
111
|
+
const chain = resolveChainConfig('arbitrum-sepolia');
|
|
112
|
+
console.log(chain.chainId, chain.usdcAddress);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Settlement Negotiation
|
|
116
|
+
|
|
117
|
+
Find a common settlement chain between two peers.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { negotiateSettlementChain } from '@toon-protocol/core';
|
|
121
|
+
|
|
122
|
+
const chain = negotiateSettlementChain(peerInfo, localConfig);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Full API
|
|
126
|
+
|
|
127
|
+
| Category | Exports |
|
|
128
|
+
|----------|---------|
|
|
129
|
+
| **Codec** | `encodeEventToToon`, `decodeEventFromToon`, `shallowParseToon`, `encodeEventToToonString` |
|
|
130
|
+
| **Discovery** | `NostrPeerDiscovery`, `GenesisPeerLoader`, `ArDrivePeerRegistry`, `SocialPeerDiscovery`, `SeedRelayDiscovery` |
|
|
131
|
+
| **Bootstrap** | `BootstrapService`, `createDiscoveryTracker` |
|
|
132
|
+
| **Compose** | `createToonNode`, `ToonNode`, `EmbeddableConnectorLike` |
|
|
133
|
+
| **Events** | `buildIlpPeerInfoEvent`, `buildServiceDiscoveryEvent`, `buildAttestationEvent`, `buildSeedRelayListEvent` |
|
|
134
|
+
| **DVM** | `buildJobRequestEvent`, `buildJobResultEvent`, `buildJobFeedbackEvent`, `parseJobRequest/Result/Feedback` |
|
|
135
|
+
| **Chain** | `resolveChainConfig`, `CHAIN_PRESETS`, `buildEip712Domain`, `validateChainId` |
|
|
136
|
+
| **Settlement** | `negotiateSettlementChain`, `resolveTokenForChain` |
|
|
137
|
+
| **TEE** | `AttestationVerifier`, `AttestationState`, `AttestationBootstrap`, `deriveFromKmsSeed` |
|
|
138
|
+
| **ILP Clients** | `createDirectIlpClient`, `createHttpIlpClient`, `createDirectConnectorAdmin`, `createHttpConnectorAdmin` |
|
|
139
|
+
| **Errors** | `ToonError`, `InvalidEventError`, `PeerDiscoveryError`, `ToonEncodeError`, `ToonDecodeError` |
|
|
140
|
+
| **Logging** | `createLogger`, `LogLevel` |
|
|
141
|
+
|
|
23
142
|
## License
|
|
24
143
|
|
|
25
144
|
MIT
|