Questo è il client di riferimento per l'API GhostDeploy Universal Node Hosting, gds.api/1 (GDS-1 §10,
spec/api/openapi.yaml). Funziona su Node 18+ e dispone di nessuna dipendenza di runtime. Utilizza soltanto node:tls,
node:http e node:crypto.
Modello di sicurezza
- Solo HTTPS, con certificato fissato. Il client non usa
https.request e non si fida di alcuna CA.
- Apre da solo la connessione TLS con
tls.connect.
- Su
secureConnect confronta lo SHA-256 del certificato DER del peer con l'impronta fissata, in tempo costante.
- Solo dopo che l'impronta corrisponde passa il socket a
node:http (createConnection).
- Prima di allora non viene scritto alcun byte della richiesta, compreso il token bearer.
- In caso di mancata corrispondenza lancia
FingerprintMismatchError. La fingerprint è obbligatoria e il controllo non può essere disabilitato.
- Nessun proxy, nessun agente condiviso. Ogni richiesta riceve una propria connessione con un nuovo vincolo della fingerprint.
- Errori. Gli errori del server lanciano
APIError con .status e .code, che è il codice gds.api/1. Un 429 viene ritentata con backoff.
- Verifica PoP.
verifyPop() esegue sempre ogni controllo, compresa la firma ed25519. La crittografia integrata di Node fornisce ed25519.
Utilizzo
import { Client, verifyPop } from "@ghostdeploy/client";
const c = new Client({ baseUrl: "https://203.0.113.10:8790", fingerprint: "57dc07ba...dd3", token: "gd_<id>_<secret>" });
await c.capabilities(); // works without a token
await c.listInstances(); await c.getInstance("alice"); await c.status("alice"); await c.events("alice", 50);
await c.profiles(); await c.benchmark(); await c.offers(); await c.openapi();
const op = await c.stop("alice"); // start / restart / startSigners / backup / action(name, action)
await c.waitOperation(op, { timeoutMs: 300_000 });
await c.deploy({ name: "carol", profile: "cold-smartnode", chain_id: 20778 });
await c.deleteInstance("carol");
await c.smartnodeKeygen("alice", "v1");
const pkg = await c.smartnodePop("alice", "v1", "0xYourOwnerAddress");
verifyPop(pkg, { expectedOwner: "0xYourOwnerAddress", expectedChainId: 20778 }); // BEFORE signing
verifyPop verifica quanto segue:
- Il calldata è esattamente
0x01 || RLP([vote_pubkey, pop]). Per una rotazione è
0x06 || RLP([rotated_id, vote_pubkey, pop]).
validator_id == sha256(vote_pubkey).
to è il registro degli Smartnode.
- Le aspettative facoltative su proprietario, chain e genesi corrispondono.
- La firma ed25519 su
sha256("PQAI-G4-POP-V1" || chainID[32] || genesis[32] || owner[20] || key[32]) è valida.
Sviluppa e testa
cd sdk/typescript
npm install # dev only: typescript + @types/node
npm test # tsc, then node --test on dist/test/*.test.js
npm run test:src # Node 22.18+/23.6+: run the .ts sources directly (type stripping), no build step
I sorgenti usano solo sintassi TypeScript cancellabile e importano con estensioni .ts . rewriteRelativeImportExtensions
trasforma quegli import in .js in dist/.
test/integration.test.ts compila sdk/testserver con go build ed esegue il server reale internal/api su 127.0.0.1, con una radice usa e getta e il manifest 20778 incorporato. Non usa la rete e non esegue comandi di sistema. Viene saltato se Go non è presente. Imposta GHOSTDEPLOY_GO per scegliere una toolchain.