All requests sent to the ENSC API are secured by encrypting payloads using AES-256-GCM and signing them with Ed25519. The client encrypts and signs outgoing requests, while the server decrypts and verifies the signature before processing the request.
Ed25519 Example:
Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error. Below is a TypeScript code snippet that demonstrates how to sign a plaintext message with Ed25519. This signature is later verified by the ENSC API server to ensure data integrity.
import*ascryptofrom'crypto';/** * Signs a plaintext message using Ed25519. * * @parammessage - The plaintext message to sign. * @paramprivateKey - The PEM-formatted private key. * @returns The signature as a base64-encoded string.*/functionsignMessage(message:string,privateKey:string):string{constsignature=crypto.sign(null,Buffer.from(message,'utf8'),{key:privateKey,format:'pem',});returnsignature.toString('base64');}// Example usage:constmessage='Hello ENSC!';constprivateKey=`-----BEGIN PRIVATE KEY-----YOUR_PRIVATE_KEY_CONTENT-----END PRIVATE KEY-----`;constsignature=signMessage(message,privateKey);console.log('Signature (base64):',signature);
AES Example:
This example shows how to encrypt and decrypt a payload using AES-256-GCM. The ENSC API client encrypts the JSON payload before sending it, and the server decrypts it using the shared encryption key.