@antseed/node 0.1.0 → 0.1.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 (130) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/interfaces/seller-provider.d.ts +13 -1
  6. package/dist/interfaces/seller-provider.d.ts.map +1 -1
  7. package/dist/node.d.ts +13 -3
  8. package/dist/node.d.ts.map +1 -1
  9. package/dist/node.js +123 -15
  10. package/dist/node.js.map +1 -1
  11. package/dist/proxy/proxy-mux.d.ts +3 -1
  12. package/dist/proxy/proxy-mux.d.ts.map +1 -1
  13. package/dist/proxy/proxy-mux.js +9 -5
  14. package/dist/proxy/proxy-mux.js.map +1 -1
  15. package/dist/types/http.d.ts +1 -0
  16. package/dist/types/http.d.ts.map +1 -1
  17. package/dist/types/http.js +1 -1
  18. package/dist/types/http.js.map +1 -1
  19. package/package.json +14 -10
  20. package/contracts/AntseedEscrow.sol +0 -310
  21. package/contracts/MockUSDC.sol +0 -64
  22. package/contracts/README.md +0 -102
  23. package/src/config/encryption.test.ts +0 -49
  24. package/src/config/encryption.ts +0 -53
  25. package/src/config/plugin-config-manager.test.ts +0 -92
  26. package/src/config/plugin-config-manager.ts +0 -153
  27. package/src/config/plugin-loader.ts +0 -90
  28. package/src/discovery/announcer.ts +0 -169
  29. package/src/discovery/bootstrap.ts +0 -57
  30. package/src/discovery/default-metadata-resolver.ts +0 -18
  31. package/src/discovery/dht-health.ts +0 -136
  32. package/src/discovery/dht-node.ts +0 -191
  33. package/src/discovery/http-metadata-resolver.ts +0 -47
  34. package/src/discovery/index.ts +0 -15
  35. package/src/discovery/metadata-codec.ts +0 -453
  36. package/src/discovery/metadata-resolver.ts +0 -7
  37. package/src/discovery/metadata-server.ts +0 -73
  38. package/src/discovery/metadata-validator.ts +0 -172
  39. package/src/discovery/peer-lookup.ts +0 -122
  40. package/src/discovery/peer-metadata.ts +0 -34
  41. package/src/discovery/peer-selector.ts +0 -134
  42. package/src/discovery/profile-manager.ts +0 -131
  43. package/src/discovery/profile-search.ts +0 -100
  44. package/src/discovery/reputation-verifier.ts +0 -54
  45. package/src/index.ts +0 -61
  46. package/src/interfaces/buyer-router.ts +0 -21
  47. package/src/interfaces/plugin.ts +0 -36
  48. package/src/interfaces/seller-provider.ts +0 -81
  49. package/src/metering/index.ts +0 -6
  50. package/src/metering/receipt-generator.ts +0 -105
  51. package/src/metering/receipt-verifier.ts +0 -102
  52. package/src/metering/session-tracker.ts +0 -145
  53. package/src/metering/storage.ts +0 -600
  54. package/src/metering/token-counter.ts +0 -127
  55. package/src/metering/usage-aggregator.ts +0 -236
  56. package/src/node.ts +0 -1698
  57. package/src/p2p/connection-auth.ts +0 -152
  58. package/src/p2p/connection-manager.ts +0 -916
  59. package/src/p2p/handshake.ts +0 -162
  60. package/src/p2p/ice-config.ts +0 -59
  61. package/src/p2p/identity.ts +0 -110
  62. package/src/p2p/index.ts +0 -11
  63. package/src/p2p/keepalive.ts +0 -118
  64. package/src/p2p/message-protocol.ts +0 -171
  65. package/src/p2p/nat-traversal.ts +0 -169
  66. package/src/p2p/payment-codec.ts +0 -165
  67. package/src/p2p/payment-mux.ts +0 -153
  68. package/src/p2p/reconnect.ts +0 -117
  69. package/src/payments/balance-manager.ts +0 -77
  70. package/src/payments/buyer-payment-manager.ts +0 -414
  71. package/src/payments/disputes.ts +0 -72
  72. package/src/payments/evm/escrow-client.ts +0 -263
  73. package/src/payments/evm/keypair.ts +0 -31
  74. package/src/payments/evm/signatures.ts +0 -103
  75. package/src/payments/evm/wallet.ts +0 -42
  76. package/src/payments/index.ts +0 -50
  77. package/src/payments/settlement.ts +0 -40
  78. package/src/payments/types.ts +0 -79
  79. package/src/proxy/index.ts +0 -3
  80. package/src/proxy/provider-detection.ts +0 -78
  81. package/src/proxy/proxy-mux.ts +0 -173
  82. package/src/proxy/request-codec.ts +0 -294
  83. package/src/reputation/index.ts +0 -6
  84. package/src/reputation/rating-manager.ts +0 -118
  85. package/src/reputation/report-manager.ts +0 -91
  86. package/src/reputation/trust-engine.ts +0 -120
  87. package/src/reputation/trust-score.ts +0 -74
  88. package/src/reputation/uptime-tracker.ts +0 -155
  89. package/src/routing/default-router.ts +0 -75
  90. package/src/types/bittorrent-dht.d.ts +0 -19
  91. package/src/types/buyer.ts +0 -37
  92. package/src/types/capability.ts +0 -34
  93. package/src/types/connection.ts +0 -29
  94. package/src/types/http.ts +0 -20
  95. package/src/types/index.ts +0 -14
  96. package/src/types/metering.ts +0 -175
  97. package/src/types/nat-api.d.ts +0 -29
  98. package/src/types/peer-profile.ts +0 -25
  99. package/src/types/peer.ts +0 -62
  100. package/src/types/plugin-config.ts +0 -31
  101. package/src/types/protocol.ts +0 -162
  102. package/src/types/provider.ts +0 -40
  103. package/src/types/rating.ts +0 -23
  104. package/src/types/report.ts +0 -30
  105. package/src/types/seller.ts +0 -38
  106. package/src/types/staking.ts +0 -23
  107. package/src/utils/debug.ts +0 -30
  108. package/src/utils/hex.ts +0 -14
  109. package/tests/balance-manager.test.ts +0 -156
  110. package/tests/bootstrap.test.ts +0 -108
  111. package/tests/buyer-payment-manager.test.ts +0 -358
  112. package/tests/connection-auth.test.ts +0 -87
  113. package/tests/default-router.test.ts +0 -148
  114. package/tests/evm-keypair.test.ts +0 -173
  115. package/tests/identity.test.ts +0 -133
  116. package/tests/message-protocol.test.ts +0 -212
  117. package/tests/metadata-codec.test.ts +0 -165
  118. package/tests/metadata-validator.test.ts +0 -261
  119. package/tests/metering-storage.test.ts +0 -244
  120. package/tests/payment-codec.test.ts +0 -95
  121. package/tests/payment-mux.test.ts +0 -191
  122. package/tests/peer-selector.test.ts +0 -184
  123. package/tests/provider-detection.test.ts +0 -107
  124. package/tests/proxy-mux-security.test.ts +0 -38
  125. package/tests/receipt.test.ts +0 -215
  126. package/tests/reputation-integration.test.ts +0 -195
  127. package/tests/request-codec.test.ts +0 -144
  128. package/tests/token-counter.test.ts +0 -122
  129. package/tsconfig.json +0 -9
  130. package/vitest.config.ts +0 -7
@@ -1,152 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
- import type { PeerId } from '../types/peer.js';
3
- import { toPeerId } from '../types/peer.js';
4
- import { signUtf8Ed25519, verifyUtf8Ed25519 } from './identity.js';
5
-
6
- export type InitialWireType = 'intro' | 'hello';
7
-
8
- export interface ConnectionAuthEnvelope {
9
- peerId: string;
10
- ts: number;
11
- nonce: string;
12
- sig: string;
13
- }
14
-
15
- export interface VerifyConnectionAuthOptions {
16
- type: InitialWireType;
17
- auth: ConnectionAuthEnvelope | null | undefined;
18
- nowMs?: number;
19
- maxSkewMs?: number;
20
- replayGuard?: NonceReplayGuard;
21
- }
22
-
23
- export interface VerifyConnectionAuthResult {
24
- ok: boolean;
25
- peerId?: PeerId;
26
- reason?: string;
27
- }
28
-
29
- export const INTRO_AUTH_MAX_SKEW_MS = 30_000;
30
-
31
- const NONCE_SIZE_BYTES = 16;
32
- const SIG_HEX_LEN = 128;
33
- const NONCE_HEX_REGEX = /^[0-9a-f]{32}$/;
34
- const SIG_HEX_REGEX = /^[0-9a-f]{128}$/;
35
-
36
- function buildSigningPayload(
37
- type: InitialWireType,
38
- peerId: string,
39
- ts: number,
40
- nonce: string,
41
- ): string {
42
- return `${type}|${peerId}|${ts}|${nonce}`;
43
- }
44
-
45
- function buildReplayKey(peerId: PeerId, nonce: string): string {
46
- return `${peerId}:${nonce}`;
47
- }
48
-
49
- /**
50
- * Tracks recently seen nonces to reject replayed intro messages.
51
- */
52
- export class NonceReplayGuard {
53
- private readonly seen = new Map<string, number>();
54
-
55
- constructor(
56
- private readonly ttlMs = INTRO_AUTH_MAX_SKEW_MS * 2,
57
- private readonly maxEntries = 20_000,
58
- ) {}
59
-
60
- checkAndRemember(peerId: PeerId, nonce: string, nowMs = Date.now()): boolean {
61
- this.evictExpired(nowMs);
62
- const key = buildReplayKey(peerId, nonce);
63
- const existingExpiry = this.seen.get(key);
64
- if (existingExpiry && existingExpiry > nowMs) {
65
- return false;
66
- }
67
-
68
- this.seen.set(key, nowMs + this.ttlMs);
69
- if (this.seen.size > this.maxEntries) {
70
- const overflow = this.seen.size - this.maxEntries;
71
- let removed = 0;
72
- for (const oldestKey of this.seen.keys()) {
73
- this.seen.delete(oldestKey);
74
- removed++;
75
- if (removed >= overflow) {
76
- break;
77
- }
78
- }
79
- }
80
- return true;
81
- }
82
-
83
- private evictExpired(nowMs: number): void {
84
- for (const [key, expiresAt] of this.seen) {
85
- if (expiresAt <= nowMs) {
86
- this.seen.delete(key);
87
- }
88
- }
89
- }
90
- }
91
-
92
- export function buildConnectionAuthEnvelope(
93
- type: InitialWireType,
94
- peerId: PeerId,
95
- privateKeySeed: Uint8Array,
96
- nowMs = Date.now(),
97
- ): ConnectionAuthEnvelope {
98
- const nonce = randomBytes(NONCE_SIZE_BYTES).toString('hex');
99
- const payload = buildSigningPayload(type, peerId, nowMs, nonce);
100
- const sig = signUtf8Ed25519(privateKeySeed, payload);
101
-
102
- return {
103
- peerId,
104
- ts: nowMs,
105
- nonce,
106
- sig,
107
- };
108
- }
109
-
110
- export function verifyConnectionAuthEnvelope(
111
- options: VerifyConnectionAuthOptions,
112
- ): VerifyConnectionAuthResult {
113
- const nowMs = options.nowMs ?? Date.now();
114
- const maxSkewMs = options.maxSkewMs ?? INTRO_AUTH_MAX_SKEW_MS;
115
- const auth = options.auth;
116
- if (!auth || typeof auth !== 'object') {
117
- return { ok: false, reason: 'missing auth envelope' };
118
- }
119
-
120
- let peerId: PeerId;
121
- try {
122
- peerId = toPeerId(auth.peerId);
123
- } catch {
124
- return { ok: false, reason: 'invalid peerId' };
125
- }
126
-
127
- if (!Number.isInteger(auth.ts)) {
128
- return { ok: false, reason: 'invalid timestamp' };
129
- }
130
- if (Math.abs(nowMs - auth.ts) > maxSkewMs) {
131
- return { ok: false, reason: 'timestamp outside allowed skew' };
132
- }
133
-
134
- if (!NONCE_HEX_REGEX.test(auth.nonce)) {
135
- return { ok: false, reason: 'invalid nonce format' };
136
- }
137
- if (!SIG_HEX_REGEX.test(auth.sig) || auth.sig.length !== SIG_HEX_LEN) {
138
- return { ok: false, reason: 'invalid signature format' };
139
- }
140
-
141
- if (options.replayGuard && !options.replayGuard.checkAndRemember(peerId, auth.nonce, nowMs)) {
142
- return { ok: false, reason: 'replayed intro auth nonce' };
143
- }
144
-
145
- const payload = buildSigningPayload(options.type, peerId, auth.ts, auth.nonce);
146
- const valid = verifyUtf8Ed25519(peerId, payload, auth.sig);
147
- if (!valid) {
148
- return { ok: false, reason: 'signature verification failed' };
149
- }
150
-
151
- return { ok: true, peerId };
152
- }