@antseed/node 0.1.0 → 0.1.2
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/LICENSE +674 -0
- package/README.md +7 -5
- package/dist/discovery/http-metadata-resolver.d.ts +6 -0
- package/dist/discovery/http-metadata-resolver.d.ts.map +1 -1
- package/dist/discovery/http-metadata-resolver.js +32 -4
- package/dist/discovery/http-metadata-resolver.js.map +1 -1
- package/dist/discovery/peer-lookup.d.ts +1 -0
- package/dist/discovery/peer-lookup.d.ts.map +1 -1
- package/dist/discovery/peer-lookup.js +10 -25
- package/dist/discovery/peer-lookup.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/seller-provider.d.ts +13 -1
- package/dist/interfaces/seller-provider.d.ts.map +1 -1
- package/dist/node.d.ts +13 -3
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +146 -21
- package/dist/node.js.map +1 -1
- package/dist/proxy/proxy-mux.d.ts +3 -1
- package/dist/proxy/proxy-mux.d.ts.map +1 -1
- package/dist/proxy/proxy-mux.js +9 -5
- package/dist/proxy/proxy-mux.js.map +1 -1
- package/dist/types/http.d.ts +1 -0
- package/dist/types/http.d.ts.map +1 -1
- package/dist/types/http.js +1 -1
- package/dist/types/http.js.map +1 -1
- package/package.json +14 -10
- package/contracts/AntseedEscrow.sol +0 -310
- package/contracts/MockUSDC.sol +0 -64
- package/contracts/README.md +0 -102
- package/src/config/encryption.test.ts +0 -49
- package/src/config/encryption.ts +0 -53
- package/src/config/plugin-config-manager.test.ts +0 -92
- package/src/config/plugin-config-manager.ts +0 -153
- package/src/config/plugin-loader.ts +0 -90
- package/src/discovery/announcer.ts +0 -169
- package/src/discovery/bootstrap.ts +0 -57
- package/src/discovery/default-metadata-resolver.ts +0 -18
- package/src/discovery/dht-health.ts +0 -136
- package/src/discovery/dht-node.ts +0 -191
- package/src/discovery/http-metadata-resolver.ts +0 -47
- package/src/discovery/index.ts +0 -15
- package/src/discovery/metadata-codec.ts +0 -453
- package/src/discovery/metadata-resolver.ts +0 -7
- package/src/discovery/metadata-server.ts +0 -73
- package/src/discovery/metadata-validator.ts +0 -172
- package/src/discovery/peer-lookup.ts +0 -122
- package/src/discovery/peer-metadata.ts +0 -34
- package/src/discovery/peer-selector.ts +0 -134
- package/src/discovery/profile-manager.ts +0 -131
- package/src/discovery/profile-search.ts +0 -100
- package/src/discovery/reputation-verifier.ts +0 -54
- package/src/index.ts +0 -61
- package/src/interfaces/buyer-router.ts +0 -21
- package/src/interfaces/plugin.ts +0 -36
- package/src/interfaces/seller-provider.ts +0 -81
- package/src/metering/index.ts +0 -6
- package/src/metering/receipt-generator.ts +0 -105
- package/src/metering/receipt-verifier.ts +0 -102
- package/src/metering/session-tracker.ts +0 -145
- package/src/metering/storage.ts +0 -600
- package/src/metering/token-counter.ts +0 -127
- package/src/metering/usage-aggregator.ts +0 -236
- package/src/node.ts +0 -1698
- package/src/p2p/connection-auth.ts +0 -152
- package/src/p2p/connection-manager.ts +0 -916
- package/src/p2p/handshake.ts +0 -162
- package/src/p2p/ice-config.ts +0 -59
- package/src/p2p/identity.ts +0 -110
- package/src/p2p/index.ts +0 -11
- package/src/p2p/keepalive.ts +0 -118
- package/src/p2p/message-protocol.ts +0 -171
- package/src/p2p/nat-traversal.ts +0 -169
- package/src/p2p/payment-codec.ts +0 -165
- package/src/p2p/payment-mux.ts +0 -153
- package/src/p2p/reconnect.ts +0 -117
- package/src/payments/balance-manager.ts +0 -77
- package/src/payments/buyer-payment-manager.ts +0 -414
- package/src/payments/disputes.ts +0 -72
- package/src/payments/evm/escrow-client.ts +0 -263
- package/src/payments/evm/keypair.ts +0 -31
- package/src/payments/evm/signatures.ts +0 -103
- package/src/payments/evm/wallet.ts +0 -42
- package/src/payments/index.ts +0 -50
- package/src/payments/settlement.ts +0 -40
- package/src/payments/types.ts +0 -79
- package/src/proxy/index.ts +0 -3
- package/src/proxy/provider-detection.ts +0 -78
- package/src/proxy/proxy-mux.ts +0 -173
- package/src/proxy/request-codec.ts +0 -294
- package/src/reputation/index.ts +0 -6
- package/src/reputation/rating-manager.ts +0 -118
- package/src/reputation/report-manager.ts +0 -91
- package/src/reputation/trust-engine.ts +0 -120
- package/src/reputation/trust-score.ts +0 -74
- package/src/reputation/uptime-tracker.ts +0 -155
- package/src/routing/default-router.ts +0 -75
- package/src/types/bittorrent-dht.d.ts +0 -19
- package/src/types/buyer.ts +0 -37
- package/src/types/capability.ts +0 -34
- package/src/types/connection.ts +0 -29
- package/src/types/http.ts +0 -20
- package/src/types/index.ts +0 -14
- package/src/types/metering.ts +0 -175
- package/src/types/nat-api.d.ts +0 -29
- package/src/types/peer-profile.ts +0 -25
- package/src/types/peer.ts +0 -62
- package/src/types/plugin-config.ts +0 -31
- package/src/types/protocol.ts +0 -162
- package/src/types/provider.ts +0 -40
- package/src/types/rating.ts +0 -23
- package/src/types/report.ts +0 -30
- package/src/types/seller.ts +0 -38
- package/src/types/staking.ts +0 -23
- package/src/utils/debug.ts +0 -30
- package/src/utils/hex.ts +0 -14
- package/tests/balance-manager.test.ts +0 -156
- package/tests/bootstrap.test.ts +0 -108
- package/tests/buyer-payment-manager.test.ts +0 -358
- package/tests/connection-auth.test.ts +0 -87
- package/tests/default-router.test.ts +0 -148
- package/tests/evm-keypair.test.ts +0 -173
- package/tests/identity.test.ts +0 -133
- package/tests/message-protocol.test.ts +0 -212
- package/tests/metadata-codec.test.ts +0 -165
- package/tests/metadata-validator.test.ts +0 -261
- package/tests/metering-storage.test.ts +0 -244
- package/tests/payment-codec.test.ts +0 -95
- package/tests/payment-mux.test.ts +0 -191
- package/tests/peer-selector.test.ts +0 -184
- package/tests/provider-detection.test.ts +0 -107
- package/tests/proxy-mux-security.test.ts +0 -38
- package/tests/receipt.test.ts +0 -215
- package/tests/reputation-integration.test.ts +0 -195
- package/tests/request-codec.test.ts +0 -144
- package/tests/token-counter.test.ts +0 -122
- package/tsconfig.json +0 -9
- 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
|
-
}
|