@spalx/http-transport-adapter
v1.1.0
Published
Services call each other with `POST /http-transport`, carrying a `CorrelatedMessage` from `@spalx/transport-pkg`.
Readme
http-transport-adapter
Services call each other with POST /http-transport, carrying a CorrelatedMessage from @spalx/transport-pkg.
Signed calls
Pass signing options and every call the adapter sends is signed, and every call it receives is checked:
new HTTPTransportAdapter(port, {
serviceName: 'billing', // the name it signs as
privateKey: '<base64 PKCS#8 DER Ed25519 private key>',
trustedKeys: 'gateway:<base64 raw public key>,scheduler:<…>', // needed to receive calls
});
transportService.setActionHandler('billing.charge', handler, ['gateway']); // '*' allows any trusted callerA sender adds X-Transport-Caller, X-Transport-Timestamp (Unix milliseconds) and X-Transport-Signature: the
base64 Ed25519 signature of <caller>\n<timestamp>\n<body bytes>. A receiver answers 403, and runs nothing, when the
call is unsigned, its caller has no trusted key, the signature doesn't verify, its time is more than 30 seconds off,
its message id was already accepted from that caller, or its action doesn't list that caller. A name may appear more
than once in trustedKeys, so a key can be replaced without refusing calls. A receiving adapter refuses to start
without trusted keys, or when any action has no callers list.
Make a key pair with:
openssl genpkey -algorithm ed25519 -outform DER | base64 # private key
echo "<private key>" | base64 -d | openssl pkey -inform DER -pubout -outform DER | tail -c 32 | base64 # public keyWithout signing options, the adapter neither signs nor checks.
A send that gets an answer other than 200 fails with a TransportStatusError carrying that status and the answer's
error text.
