yakmesh 1.7.0 → 1.8.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/CHANGELOG.md +87 -2
- package/README.md +2 -1
- package/announcements/discord-v1.7.0.md +35 -0
- package/announcements/patreon-welcome.md +83 -0
- package/announcements/telegram-v1.7.0.md +11 -0
- package/announcements/x-v1.7.0.md +41 -0
- package/cli/index.js +4 -4
- package/mesh/{phantom-routing.js → nakpak-routing.js} +50 -47
- package/mesh/sherpa-discovery.js +655 -0
- package/package.json +10 -4
- package/server/index.js +57 -0
- package/yakbot/index.js +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,92 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to YAKMESH will be documented in this file.
|
|
4
4
|
|
|
5
|
-
## [1.
|
|
5
|
+
## [1.8.0] - 2026-01-18
|
|
6
|
+
|
|
7
|
+
### 🏔️ SHERPA: Decentralized Peer Discovery
|
|
8
|
+
|
|
9
|
+
This release implements SHERPA, a novel peer discovery mechanism that uses the public web as a decentralized DHT.
|
|
10
|
+
|
|
11
|
+
#### New Feature: SHERPA Discovery
|
|
12
|
+
|
|
13
|
+
##### The Innovation: "The Web IS the DHT"
|
|
14
|
+
- Each node exposes `/.well-known/yakmesh/beacon` with its peer list
|
|
15
|
+
- Discovery crawls known endpoints to find new peers
|
|
16
|
+
- No central authority - truly decentralized bootstrap
|
|
17
|
+
- Works with existing CDN infrastructure
|
|
18
|
+
|
|
19
|
+
##### New Module: `mesh/sherpa-discovery.js`
|
|
20
|
+
- `SherpaDiscovery` - Main discovery engine with peer crawling
|
|
21
|
+
- `BeaconMessage` - Signed beacon format for peer advertisement
|
|
22
|
+
- `PeerRegistry` - Scored peer management with decay
|
|
23
|
+
- `createBeaconMiddleware` - Express middleware for beacon endpoint
|
|
24
|
+
|
|
25
|
+
##### New Endpoints
|
|
26
|
+
- `GET /.well-known/yakmesh/beacon` - Advertise this node and known peers
|
|
27
|
+
- `GET /sherpa/status` - Discovery statistics
|
|
28
|
+
- `GET /sherpa/candidates` - Get connection candidates
|
|
29
|
+
|
|
30
|
+
##### Configuration
|
|
31
|
+
```javascript
|
|
32
|
+
// yakmesh.config.js
|
|
33
|
+
export default {
|
|
34
|
+
sherpa: {
|
|
35
|
+
enabled: true,
|
|
36
|
+
selfEndpoint: 'https://mynode.example.com',
|
|
37
|
+
wsEndpoint: 'wss://mynode.example.com:9001',
|
|
38
|
+
seeds: ['https://peer1.example.com', 'https://peer2.example.com'],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
##### Beacon Response Format
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"version": "1.0",
|
|
47
|
+
"nodeId": "abc123...",
|
|
48
|
+
"networkName": "mobius-rabi-junction",
|
|
49
|
+
"timestamp": 1737225600000,
|
|
50
|
+
"capabilities": { "wsPort": 9001, "supportsAnnex": true },
|
|
51
|
+
"peers": [{ "nodeId": "...", "endpoint": "https://..." }],
|
|
52
|
+
"publicKey": "...",
|
|
53
|
+
"signature": "..."
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## [1.7.1] - 2026-01-18
|
|
60
|
+
|
|
61
|
+
### 🦬 NAKPAK & SHERPA: Yak-Themed Protocol Naming
|
|
62
|
+
|
|
63
|
+
This release renames dark-themed protocols to yak-themed names for brand consistency.
|
|
64
|
+
|
|
65
|
+
#### Renamed Protocols
|
|
66
|
+
|
|
67
|
+
##### NAKPAK (formerly Phantom)
|
|
68
|
+
- **N**ested **A**nonymous **K**ernel for **P**rivate **A**uthenticated **K**omms
|
|
69
|
+
- Post-quantum onion routing with ML-KEM768 key encapsulation
|
|
70
|
+
- File renamed: `phantom-routing.js` → `nakpak-routing.js`
|
|
71
|
+
- Classes renamed: `PhantomRouter` → `NakpakRouter`, etc.
|
|
72
|
+
- Etymology: NAK (female yak) + PAK (package) = sounds like "knapsack" 🎒
|
|
73
|
+
|
|
74
|
+
##### SHERPA (new protocol slot)
|
|
75
|
+
- **S**ecure **H**idden **E**ndpoint **R**esolution **P**ath **A**rchitecture
|
|
76
|
+
- Peer discovery DHT via public web layer
|
|
77
|
+
- Guides nodes to find each other like Sherpas guide travelers
|
|
78
|
+
|
|
79
|
+
#### Protocol Stack Update
|
|
80
|
+
```text
|
|
81
|
+
1. HTTP API - Public content delivery
|
|
82
|
+
2. Annex - Encrypted P2P messaging
|
|
83
|
+
3. Gossip - Message propagation
|
|
84
|
+
4. Beacon - Emergency broadcast
|
|
85
|
+
5. Nakpak - Onion routing (NEW NAME)
|
|
86
|
+
6. Sherpa - Peer discovery (NEW)
|
|
87
|
+
7. Mesh - Core P2P network
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
6
91
|
|
|
7
92
|
### 🛡️ SLH-DSA Backup Signatures & Monitoring Dashboard
|
|
8
93
|
|
|
@@ -95,7 +180,7 @@ All hash operations now use SHA3-256 for post-quantum consistency:
|
|
|
95
180
|
- `oracle/phase-epoch.js` - Phase derivation uses SHA3-256
|
|
96
181
|
- `gossip/protocol.js` - Bloom filters and message IDs use SHA3-256
|
|
97
182
|
- `mesh/temporal-encoder.js` - Temporal hashes use SHA3-256
|
|
98
|
-
- `mesh/
|
|
183
|
+
- `mesh/nakpak-routing.js` - Key derivation uses SHA3-256 (formerly phantom-routing)
|
|
99
184
|
- `mesh/annex.js` - Session key derivation uses SHA3-256
|
|
100
185
|
- `mesh/echo-ranging.js` - Probe key derivation uses SHA3-256
|
|
101
186
|
|
package/README.md
CHANGED
|
@@ -182,7 +182,8 @@ See [TRADEMARK.md](TRADEMARK.md) for trademark usage policy.
|
|
|
182
182
|
<p>
|
|
183
183
|
<a href="https://discord.gg/8mSPfbJB8N">💬 Discord</a> •
|
|
184
184
|
<a href="https://t.me/yakmesh">📱 Telegram</a> •
|
|
185
|
-
<a href="https://x.com/yakmesh_dev">𝕏 Twitter</a>
|
|
185
|
+
<a href="https://x.com/yakmesh_dev">𝕏 Twitter</a> •
|
|
186
|
+
<a href="https://patreon.com/yakmesh">❤️ Patreon</a>
|
|
186
187
|
</p>
|
|
187
188
|
<br>
|
|
188
189
|
<sub>© 2026 YAKMESH™ Project. Sturdy & Secure.</sub>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Discord Announcement - v1.7.0
|
|
2
|
+
|
|
3
|
+
## Embed
|
|
4
|
+
|
|
5
|
+
**Title:** 🦬 YAKMESH™ v1.7.0 Released!
|
|
6
|
+
|
|
7
|
+
**Description:**
|
|
8
|
+
Defense-in-depth with dual post-quantum signatures!
|
|
9
|
+
|
|
10
|
+
**Fields:**
|
|
11
|
+
|
|
12
|
+
### 🛡️ SLH-DSA Backup Signatures
|
|
13
|
+
- Hash-based signatures (FIPS 205) as backup to ML-DSA
|
|
14
|
+
- Defense-in-depth: if lattice breaks, hash-based still holds
|
|
15
|
+
- `signDual()` and `verifyDual()` for maximum security
|
|
16
|
+
|
|
17
|
+
### 📊 Monitoring Dashboard
|
|
18
|
+
- New `/metrics` endpoint with comprehensive node status
|
|
19
|
+
- Dashboard shows Oracle, Crypto, Time Source, Uptime
|
|
20
|
+
- Real-time health monitoring
|
|
21
|
+
|
|
22
|
+
### 🤖 Dev.to Automation
|
|
23
|
+
- Release articles now auto-posted to Dev.to
|
|
24
|
+
- Three platforms automated: Discord, Telegram, Dev.to
|
|
25
|
+
|
|
26
|
+
### 📦 Install
|
|
27
|
+
```
|
|
28
|
+
npm install yakmesh@1.7.0
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Links:** [npm](https://npmjs.com/package/yakmesh) • [GitHub](https://github.com/yakmesh/yakmesh) • [Docs](https://yakmesh.dev/docs) • [Discord](https://discord.gg/8mSPfbJB8N) • [Telegram](https://t.me/yakmesh)
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
YAKMESH™ - Sturdy & Secure 🏔️
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Welcome to YAKMESH™ Patreon! 🦬
|
|
2
|
+
|
|
3
|
+
## Thank You for Supporting Post-Quantum Security
|
|
4
|
+
|
|
5
|
+
Welcome to the YAKMESH™ community! Your support helps us build the future of secure, decentralized networking.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🏔️ What is YAKMESH?
|
|
10
|
+
|
|
11
|
+
**YAKMESH** (Yielding Atomic Kernel Modular Encryption Secured Hub) is a high-resiliency, decentralized mesh network designed to survive the quantum computing era.
|
|
12
|
+
|
|
13
|
+
### Why It Matters
|
|
14
|
+
- 🔐 **Post-quantum cryptography** - Protected against future quantum attacks using ML-DSA-65, ML-KEM768, and SLH-DSA
|
|
15
|
+
- 🌐 **Truly decentralized** - No central servers, no single points of failure
|
|
16
|
+
- 🔮 **Self-verifying oracle** - Code is the authority, not humans
|
|
17
|
+
- 🕵️ **Phantom routing** - Onion routing for privacy
|
|
18
|
+
- ⚡ **PCIe atomic timing** - Nanosecond precision across the network
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 💚 What Your Support Enables
|
|
23
|
+
|
|
24
|
+
### Infrastructure
|
|
25
|
+
- 🖥️ Official node hosting and bandwidth
|
|
26
|
+
- 🔒 Security audits and penetration testing
|
|
27
|
+
- 📊 Network monitoring and uptime
|
|
28
|
+
|
|
29
|
+
### Development
|
|
30
|
+
- 🛠️ Full-time development resources
|
|
31
|
+
- 🧪 Testing infrastructure
|
|
32
|
+
- 📚 Documentation and tutorials
|
|
33
|
+
|
|
34
|
+
### Community
|
|
35
|
+
- 🎮 Discord bot (YakBot) hosting
|
|
36
|
+
- 🎉 Community events and hackathons
|
|
37
|
+
- 📰 Regular development updates
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 🎁 Supporter Benefits
|
|
42
|
+
|
|
43
|
+
### All Supporters
|
|
44
|
+
- 💬 Patron-only Discord channel access
|
|
45
|
+
- 📋 Early access to roadmap discussions
|
|
46
|
+
- 🏷️ Patron badge in Discord
|
|
47
|
+
- 📰 Monthly development digest
|
|
48
|
+
|
|
49
|
+
### Future Tiers (Coming Soon)
|
|
50
|
+
- **Builder** - Vote on feature priorities
|
|
51
|
+
- **Pioneer** - Name in contributors list
|
|
52
|
+
- **Architect** - Monthly dev call access
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🔗 Connect With Us
|
|
57
|
+
|
|
58
|
+
- 🌐 **Website**: [yakmesh.dev](https://yakmesh.dev)
|
|
59
|
+
- 💬 **Discord**: [Join Server](https://discord.gg/8mSPfbJB8N)
|
|
60
|
+
- 📱 **Telegram**: [@yakmesh](https://t.me/yakmesh)
|
|
61
|
+
- 𝕏 **Twitter/X**: [@yakmesh_dev](https://x.com/yakmesh_dev)
|
|
62
|
+
- 📦 **npm**: [yakmesh](https://npmjs.com/package/yakmesh)
|
|
63
|
+
- 📂 **GitHub**: [yakmesh/yakmesh](https://github.com/yakmesh/yakmesh)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 🚀 Quick Start
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm install yakmesh
|
|
71
|
+
npx yakmesh init
|
|
72
|
+
npx yakmesh start
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
**Thank you for being part of the quantum-resistant future!**
|
|
78
|
+
|
|
79
|
+
*Sturdy & Secure* 🏔️
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
© 2026 YAKMESH™ Project | [PeerQuanta](https://peerquanta.com)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Telegram Announcement - v1.7.0
|
|
2
|
+
|
|
3
|
+
🦬 *YAKMESH™ v1.7.0 Released!*
|
|
4
|
+
|
|
5
|
+
🛡️ SLH-DSA backup signatures for defense-in-depth
|
|
6
|
+
📊 New monitoring dashboard with /metrics endpoint
|
|
7
|
+
🤖 Automated Dev.to article posting
|
|
8
|
+
|
|
9
|
+
📦 `npm install yakmesh@1.7.0`
|
|
10
|
+
|
|
11
|
+
🔗 https://github.com/yakmesh/yakmesh/releases/tag/v1.7.0
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# X/Twitter Announcement - v1.7.0
|
|
2
|
+
|
|
3
|
+
## Thread
|
|
4
|
+
|
|
5
|
+
### Tweet 1
|
|
6
|
+
🦬 YAKMESH™ v1.7.0 Released!
|
|
7
|
+
|
|
8
|
+
Defense-in-depth with dual post-quantum signatures 🛡️
|
|
9
|
+
|
|
10
|
+
Now using BOTH:
|
|
11
|
+
• ML-DSA (lattice-based) - fast primary
|
|
12
|
+
• SLH-DSA (hash-based) - backup
|
|
13
|
+
|
|
14
|
+
If lattice crypto ever breaks, hash-based still protects you.
|
|
15
|
+
|
|
16
|
+
npm i yakmesh@1.7.0
|
|
17
|
+
|
|
18
|
+
### Tweet 2 (Reply)
|
|
19
|
+
New features in v1.7.0:
|
|
20
|
+
|
|
21
|
+
📊 Monitoring Dashboard
|
|
22
|
+
- /metrics endpoint with full node status
|
|
23
|
+
- Oracle, Crypto, Time Source visualization
|
|
24
|
+
- Real-time uptime tracking
|
|
25
|
+
|
|
26
|
+
🤖 Automation
|
|
27
|
+
- Release articles auto-posted to Dev.to
|
|
28
|
+
- Discord + Telegram + Dev.to = 3 platforms automated
|
|
29
|
+
|
|
30
|
+
### Tweet 3 (Reply)
|
|
31
|
+
The philosophy: Sturdy & Secure 🏔️
|
|
32
|
+
|
|
33
|
+
Like a yak on a mountain, YAKMESH™ is built to survive harsh conditions.
|
|
34
|
+
|
|
35
|
+
Quantum computers? Covered.
|
|
36
|
+
Lattice assumptions break? Still covered.
|
|
37
|
+
Single point of failure? Mesh eliminates it.
|
|
38
|
+
|
|
39
|
+
Docs: yakmesh.dev
|
|
40
|
+
|
|
41
|
+
#PostQuantum #P2P #Cryptography
|
package/cli/index.js
CHANGED
|
@@ -56,7 +56,7 @@ program
|
|
|
56
56
|
// Parse bootstrap nodes
|
|
57
57
|
const bootstrapNodes = options.bootstrap
|
|
58
58
|
? options.bootstrap.split(',').map(s => s.trim())
|
|
59
|
-
: [
|
|
59
|
+
: []; // Empty by default - YAKMESH is decentralized, no central bootstrap
|
|
60
60
|
|
|
61
61
|
// Generate config
|
|
62
62
|
const config = `/**
|
|
@@ -302,6 +302,6 @@ if (!process.argv.slice(2).length) {
|
|
|
302
302
|
showBanner();
|
|
303
303
|
program.outputHelp();
|
|
304
304
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Yakmesh
|
|
2
|
+
* Yakmesh NAKPAK Routing - Nested Anonymous Kernel for Private Authenticated Komms
|
|
3
3
|
*
|
|
4
4
|
* The first post-quantum secure onion routing implementation featuring:
|
|
5
5
|
* - ML-DSA-65 signatures at every routing layer
|
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
* - Multi-layer encryption with perfect forward secrecy
|
|
8
8
|
* - Timing attack resistance through temporal padding
|
|
9
9
|
*
|
|
10
|
-
* Key Innovation: "Your packets
|
|
10
|
+
* Key Innovation: "Your packets travel like yak caravans through hidden mountain paths"
|
|
11
11
|
* - Each routing layer uses different quantum-resistant keys
|
|
12
12
|
* - Decoy traffic masks real communication patterns
|
|
13
13
|
* - Temporal obfuscation defeats traffic analysis
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* Etymology: NAK (female yak, the pack carrier) + PAK (package) = NAKPAK (sounds like "knapsack")
|
|
16
|
+
* Works with SHERPA (Secure Hidden Endpoint Resolution Path Architecture) for peer discovery.
|
|
17
|
+
*
|
|
18
|
+
* @module mesh/nakpak-routing
|
|
16
19
|
* @license MIT
|
|
17
20
|
* @copyright 2026 YAKMESH™ Contributors
|
|
18
21
|
*/
|
|
@@ -23,7 +26,7 @@ import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';
|
|
|
23
26
|
import { sha3_256 } from '@noble/hashes/sha3.js';
|
|
24
27
|
import { bytesToHex, hexToBytes, utf8ToBytes } from '@noble/hashes/utils.js';
|
|
25
28
|
|
|
26
|
-
const
|
|
29
|
+
const NAKPAK_CONFIG = {
|
|
27
30
|
// Circuit settings
|
|
28
31
|
defaultHopCount: 3, // Number of hops (like Tor)
|
|
29
32
|
maxHopCount: 7, // Maximum allowed hops
|
|
@@ -44,13 +47,13 @@ const PHANTOM_CONFIG = {
|
|
|
44
47
|
maxPayloadSize: 7000, // Max actual payload
|
|
45
48
|
|
|
46
49
|
// Key derivation
|
|
47
|
-
keyDerivationSalt: '
|
|
50
|
+
keyDerivationSalt: 'NAKPAK-YAKMESH-2026',
|
|
48
51
|
};
|
|
49
52
|
|
|
50
53
|
/**
|
|
51
|
-
* A single routing layer in the onion
|
|
54
|
+
* A single routing layer in the onion (like a yak's pack saddle layer)
|
|
52
55
|
*/
|
|
53
|
-
class
|
|
56
|
+
class NakpakLayer {
|
|
54
57
|
constructor(options) {
|
|
55
58
|
this.hopIndex = options.hopIndex;
|
|
56
59
|
this.nodeId = options.nodeId;
|
|
@@ -114,12 +117,12 @@ class PhantomLayer {
|
|
|
114
117
|
throw new Error('No encryption key established');
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
const nonce = randomBytes(
|
|
120
|
+
const nonce = randomBytes(NAKPAK_CONFIG.nonceSize);
|
|
118
121
|
const cipher = createCipheriv(
|
|
119
|
-
|
|
122
|
+
NAKPAK_CONFIG.layerEncryption,
|
|
120
123
|
this.encryptionKey,
|
|
121
124
|
nonce,
|
|
122
|
-
{ authTagLength:
|
|
125
|
+
{ authTagLength: NAKPAK_CONFIG.authTagLength }
|
|
123
126
|
);
|
|
124
127
|
|
|
125
128
|
const plaintext = typeof data === 'string' ? data : JSON.stringify(data);
|
|
@@ -148,10 +151,10 @@ class PhantomLayer {
|
|
|
148
151
|
const tag = Buffer.from(encryptedData.tag, 'hex');
|
|
149
152
|
|
|
150
153
|
const decipher = createDecipheriv(
|
|
151
|
-
|
|
154
|
+
NAKPAK_CONFIG.layerEncryption,
|
|
152
155
|
this.encryptionKey,
|
|
153
156
|
nonce,
|
|
154
|
-
{ authTagLength:
|
|
157
|
+
{ authTagLength: NAKPAK_CONFIG.authTagLength }
|
|
155
158
|
);
|
|
156
159
|
decipher.setAuthTag(tag);
|
|
157
160
|
|
|
@@ -166,16 +169,16 @@ class PhantomLayer {
|
|
|
166
169
|
_deriveEncryptionKey(sharedSecret) {
|
|
167
170
|
return createHash('sha3-256')
|
|
168
171
|
.update(sharedSecret)
|
|
169
|
-
.update(
|
|
172
|
+
.update(NAKPAK_CONFIG.keyDerivationSalt)
|
|
170
173
|
.update(Buffer.from([this.hopIndex]))
|
|
171
174
|
.digest();
|
|
172
175
|
}
|
|
173
176
|
}
|
|
174
177
|
|
|
175
178
|
/**
|
|
176
|
-
* An onion-wrapped packet
|
|
179
|
+
* An onion-wrapped packet (like a yak's cargo bundle)
|
|
177
180
|
*/
|
|
178
|
-
class
|
|
181
|
+
class NakpakPacket {
|
|
179
182
|
constructor(options = {}) {
|
|
180
183
|
this.id = options.id || bytesToHex(randomBytes(16));
|
|
181
184
|
this.circuitId = options.circuitId;
|
|
@@ -211,7 +214,7 @@ class PhantomPacket {
|
|
|
211
214
|
});
|
|
212
215
|
|
|
213
216
|
const currentSize = Buffer.byteLength(serialized, 'utf8');
|
|
214
|
-
const paddingNeeded =
|
|
217
|
+
const paddingNeeded = NAKPAK_CONFIG.fixedPacketSize - currentSize - 50; // Reserve for padding field
|
|
215
218
|
|
|
216
219
|
if (paddingNeeded > 0) {
|
|
217
220
|
this.padding = randomBytes(Math.max(1, paddingNeeded)).toString('base64');
|
|
@@ -222,7 +225,7 @@ class PhantomPacket {
|
|
|
222
225
|
* Create decoy packet
|
|
223
226
|
*/
|
|
224
227
|
static createDecoy(circuitId) {
|
|
225
|
-
const decoy = new
|
|
228
|
+
const decoy = new NakpakPacket({
|
|
226
229
|
circuitId,
|
|
227
230
|
isDecoy: true,
|
|
228
231
|
});
|
|
@@ -251,7 +254,7 @@ class PhantomPacket {
|
|
|
251
254
|
}
|
|
252
255
|
|
|
253
256
|
static deserialize(obj) {
|
|
254
|
-
const packet = new
|
|
257
|
+
const packet = new NakpakPacket({
|
|
255
258
|
id: obj.id,
|
|
256
259
|
circuitId: obj.circuitId,
|
|
257
260
|
timestamp: obj.timestamp,
|
|
@@ -263,12 +266,12 @@ class PhantomPacket {
|
|
|
263
266
|
}
|
|
264
267
|
|
|
265
268
|
/**
|
|
266
|
-
* A circuit through the mesh (like a
|
|
269
|
+
* A circuit through the mesh (like a yak caravan route)
|
|
267
270
|
*/
|
|
268
|
-
class
|
|
271
|
+
class NakpakCircuit {
|
|
269
272
|
constructor(options = {}) {
|
|
270
273
|
this.circuitId = options.circuitId || bytesToHex(randomBytes(16));
|
|
271
|
-
this.hops = []; // Array of
|
|
274
|
+
this.hops = []; // Array of NakpakLayer
|
|
272
275
|
this.isEstablished = false;
|
|
273
276
|
this.createdAt = Date.now();
|
|
274
277
|
this.lastUsed = Date.now();
|
|
@@ -279,14 +282,14 @@ class PhantomCircuit {
|
|
|
279
282
|
* Build a circuit through specified nodes
|
|
280
283
|
*/
|
|
281
284
|
async buildCircuit(nodeIds) {
|
|
282
|
-
if (nodeIds.length >
|
|
283
|
-
throw new Error('Too many hops: max is ' +
|
|
285
|
+
if (nodeIds.length > NAKPAK_CONFIG.maxHopCount) {
|
|
286
|
+
throw new Error('Too many hops: max is ' + NAKPAK_CONFIG.maxHopCount);
|
|
284
287
|
}
|
|
285
288
|
|
|
286
289
|
this.hops = [];
|
|
287
290
|
|
|
288
291
|
for (let i = 0; i < nodeIds.length; i++) {
|
|
289
|
-
const layer = new
|
|
292
|
+
const layer = new NakpakLayer({
|
|
290
293
|
hopIndex: i,
|
|
291
294
|
nodeId: nodeIds[i],
|
|
292
295
|
nextHop: nodeIds[i + 1] || null,
|
|
@@ -356,7 +359,7 @@ class PhantomCircuit {
|
|
|
356
359
|
};
|
|
357
360
|
}
|
|
358
361
|
|
|
359
|
-
const packet = new
|
|
362
|
+
const packet = new NakpakPacket({
|
|
360
363
|
circuitId: this.circuitId,
|
|
361
364
|
});
|
|
362
365
|
packet.addLayer(payload);
|
|
@@ -369,14 +372,14 @@ class PhantomCircuit {
|
|
|
369
372
|
}
|
|
370
373
|
|
|
371
374
|
isExpired() {
|
|
372
|
-
return Date.now() - this.createdAt >
|
|
375
|
+
return Date.now() - this.createdAt > NAKPAK_CONFIG.circuitTimeout;
|
|
373
376
|
}
|
|
374
377
|
}
|
|
375
378
|
|
|
376
379
|
/**
|
|
377
|
-
* Relay node handler for forwarding
|
|
380
|
+
* Relay node handler for forwarding nakpak packets
|
|
378
381
|
*/
|
|
379
|
-
class
|
|
382
|
+
class NakpakRelay {
|
|
380
383
|
constructor(options = {}) {
|
|
381
384
|
this.nodeId = options.nodeId || bytesToHex(randomBytes(16));
|
|
382
385
|
this.circuits = new Map(); // circuitId -> local layer info
|
|
@@ -401,7 +404,7 @@ class PhantomRelay {
|
|
|
401
404
|
* Handle incoming circuit creation request
|
|
402
405
|
*/
|
|
403
406
|
async handleCircuitCreate(request) {
|
|
404
|
-
const layer = new
|
|
407
|
+
const layer = new NakpakLayer({
|
|
405
408
|
hopIndex: request.hopIndex,
|
|
406
409
|
nodeId: this.nodeId,
|
|
407
410
|
nextHop: request.nextHop,
|
|
@@ -491,8 +494,8 @@ class PhantomRelay {
|
|
|
491
494
|
* Add random delay to defeat timing analysis
|
|
492
495
|
*/
|
|
493
496
|
async _addTimingDelay() {
|
|
494
|
-
const delay =
|
|
495
|
-
Math.random() * (
|
|
497
|
+
const delay = NAKPAK_CONFIG.minPaddingMs +
|
|
498
|
+
Math.random() * (NAKPAK_CONFIG.maxPaddingMs - NAKPAK_CONFIG.minPaddingMs);
|
|
496
499
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
497
500
|
}
|
|
498
501
|
|
|
@@ -500,9 +503,9 @@ class PhantomRelay {
|
|
|
500
503
|
* Maybe inject a decoy packet to mask traffic patterns
|
|
501
504
|
*/
|
|
502
505
|
_maybeInjectDecoy(circuitId) {
|
|
503
|
-
if (Math.random() <
|
|
506
|
+
if (Math.random() < NAKPAK_CONFIG.decoyProbability) {
|
|
504
507
|
this.stats.decoysInjected++;
|
|
505
|
-
return
|
|
508
|
+
return NakpakPacket.createDecoy(circuitId).serialize();
|
|
506
509
|
}
|
|
507
510
|
return null;
|
|
508
511
|
}
|
|
@@ -537,13 +540,13 @@ class PhantomRelay {
|
|
|
537
540
|
}
|
|
538
541
|
|
|
539
542
|
/**
|
|
540
|
-
* Main
|
|
543
|
+
* Main NAKPAK routing manager
|
|
541
544
|
*/
|
|
542
|
-
class
|
|
545
|
+
class NakpakRouter {
|
|
543
546
|
constructor(options = {}) {
|
|
544
547
|
this.nodeId = options.nodeId || bytesToHex(randomBytes(16));
|
|
545
|
-
this.relay = new
|
|
546
|
-
this.circuits = new Map(); // circuitId ->
|
|
548
|
+
this.relay = new NakpakRelay({ nodeId: this.nodeId });
|
|
549
|
+
this.circuits = new Map(); // circuitId -> NakpakCircuit (for circuits we created)
|
|
547
550
|
this.knownNodes = new Map(); // nodeId -> { publicKey, lastSeen }
|
|
548
551
|
|
|
549
552
|
this.stats = {
|
|
@@ -576,7 +579,7 @@ class PhantomRouter {
|
|
|
576
579
|
const availableNodes = Array.from(this.knownNodes.keys())
|
|
577
580
|
.filter(id => id !== this.nodeId);
|
|
578
581
|
|
|
579
|
-
if (availableNodes.length <
|
|
582
|
+
if (availableNodes.length < NAKPAK_CONFIG.defaultHopCount) {
|
|
580
583
|
throw new Error('Not enough known nodes for circuit');
|
|
581
584
|
}
|
|
582
585
|
|
|
@@ -586,10 +589,10 @@ class PhantomRouter {
|
|
|
586
589
|
[availableNodes[i], availableNodes[j]] = [availableNodes[j], availableNodes[i]];
|
|
587
590
|
}
|
|
588
591
|
|
|
589
|
-
hopNodeIds = availableNodes.slice(0,
|
|
592
|
+
hopNodeIds = availableNodes.slice(0, NAKPAK_CONFIG.defaultHopCount);
|
|
590
593
|
}
|
|
591
594
|
|
|
592
|
-
const circuit = new
|
|
595
|
+
const circuit = new NakpakCircuit();
|
|
593
596
|
const buildResult = await circuit.buildCircuit(hopNodeIds);
|
|
594
597
|
|
|
595
598
|
this.circuits.set(circuit.circuitId, circuit);
|
|
@@ -638,7 +641,7 @@ class PhantomRouter {
|
|
|
638
641
|
* Handle incoming packet (as a relay)
|
|
639
642
|
*/
|
|
640
643
|
async handlePacket(packetData) {
|
|
641
|
-
const packet =
|
|
644
|
+
const packet = NakpakPacket.deserialize(packetData);
|
|
642
645
|
const result = await this.relay.processPacket(packet);
|
|
643
646
|
|
|
644
647
|
if (result.type === 'EXIT') {
|
|
@@ -690,10 +693,10 @@ class PhantomRouter {
|
|
|
690
693
|
}
|
|
691
694
|
|
|
692
695
|
export {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
696
|
+
NAKPAK_CONFIG,
|
|
697
|
+
NakpakLayer,
|
|
698
|
+
NakpakPacket,
|
|
699
|
+
NakpakCircuit,
|
|
700
|
+
NakpakRelay,
|
|
701
|
+
NakpakRouter,
|
|
699
702
|
};
|