Downloading programs and ciphertexts
To maintain local copies of FHE programs and encrypted inputs, both programs and ciphertexts can be downloaded using the TypeScript client library.
Ensure the client is initialized before using these functions.
Program download
To download a previously uploaded FHE program from SPF, use the downloadProgram() function:
export async function downloadProgramExample(
libraryId: spf.LibraryId,
): Promise<Uint8Array> {
// Download a program by its library ID
const programBytes: Uint8Array = await spf.downloadProgram(libraryId);
// Save to file (optional)
writeFileSync("downloaded_program", programBytes);
console.log(`Downloaded program: ${programBytes.length} bytes`);
return programBytes;
}
Program downloads do not require authentication. Anyone can download a program library if they know its library ID.
Parameters:
libraryId:LibraryId- The library identifier (branded hex string with0xprefix)
Returns: Promise<Uint8Array> - The program binary data
Ciphertext download
To download a ciphertext from SPF, use the downloadCiphertext() function:
export async function downloadCiphertextExample(
signer: spf.PrivateKeySigner,
ciphertextId: spf.CiphertextId,
): Promise<Uint8Array> {
// Download a ciphertext by its ID
const ciphertextBytes: Uint8Array = await spf.downloadCiphertext(
signer,
ciphertextId,
);
// Save to file (optional)
writeFileSync("downloaded_ciphertext.bin", ciphertextBytes);
console.log(`Downloaded ciphertext: ${ciphertextBytes.length} bytes`);
return ciphertextBytes;
}
Important: Downloading ciphertexts requires the signer to have access to the ciphertext but there is no dedicated download permission - it uses decryption permission. See the Access Control page for details.
Parameters:
signer:AnySigner- Signer for authentication (must have decrypt access)ciphertextId:CiphertextId- The ciphertext identifier (branded hex string with0xprefix)
Returns: Promise<Uint8Array> - The ciphertext binary data
The function throws an error if the signer lacks decrypt access to the specified ciphertext.