Authenticated Requests
To carry out an unauthenticated request, 4 headers are required:
Authentication Header -
X-Encrypted-Session orX-Encrypted-WebAuthn-Signature orX-Encrypted-Key-SignatureX-Encrypted-KeyX-Encrypted-UserX-Scope-Id
X-Encrypted-Session is obtained when you authenticate with the Authenticating with API endpoint. This is used by enclave to verify your requests. Other 2 types of headers are obtained by signing the user details object directly using your auth method (passkeys or private key)
To setup an X-Encrypted-Key you need to generate a random AES Key, and then RSA encrypt it with the secure enclaves public key, we'll use TypeScript for the example below.
Here we setup a cryptoObj that can work in both browser and server environments and then a function to generate an AES Key.
const cryptoObj = typeof window !== "undefined" ? window.crypto : crypto;
export const generateAesKey = async () => {
const cryptoKey = await cryptoObj.subtle.generateKey(
{
name: "AES-GCM",
length: 256,
},
true,
["encrypt", "decrypt"]
);
return await cryptoObj.subtle.exportKey("raw", cryptoKey);
};Next we setup two function an encrypt function, which we then use in our rsaEncrypt function.
With these function setup, we are able to generate our AES key, and then RSA Encrypt it using the public key of the secure enclave.
Now you have your encryptedAesKey and encryptedUser you can use this value as the value in the request header as X-Encrypted-Key . With X-Scope-Id, X-Encrypted-User , X-Encrypted-Session and X-Encrypted-Key setup, you can now start interacting with Passport API to sign messages, transactions and everythig else!
Last updated