// Full flow
async function createSecureLink(file, recipient, expiry) {
// 1. Encrypt
const { encrypted, secretKey } = await encryptFile(file);
// 2. Upload to IPFS
const cid = await uploadToIPFS(encrypted);
// 3. Create on-chain policy
const policyId = await createPolicy(recipient, expiry, 3);
// 4. Store metadata
await fetch('/api/storeMetadata', {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` },
body: JSON.stringify({
policyId,
cid,
sender: address,
recipient,
expiry,
maxAttempts: 3,
contentType: 'file',
fileName: file.name,
fileSize: file.size,
}),
});
// 5. Return secure link
return `${APP_URL}/access/${policyId}#${secretKey}`;
}