#Upload with Encryption Example

Example of uploading files with encryption enabled.

#Upload with Encryption

import { Walbucket } from '@walbucket/sdk';

const walbucket = new Walbucket({
  apiKey: 'your-api-key',
  network: 'testnet',
  sponsorPrivateKey: 'your-private-key',
});

// Upload with wallet-gated encryption
const result = await walbucket.upload(file, {
  name: 'secret-document.pdf',
  encryption: true,
  policy: {
    type: 'wallet-gated',
    addresses: ['0x123...', '0x456...']
  }
});

console.log('Encrypted asset:', result.assetId);
console.log('Policy ID:', result.policyId);
typescript

#Retrieve and Decrypt

import { SealClient } from '@mysten/seal';
import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';

const suiClient = new SuiClient({
  url: getFullnodeUrl('testnet'),
});

const sealClient = new SealClient({ suiClient });
const sessionKey = await sealClient.getSessionKey(policyId);

const result = await walbucket.retrieve(assetId, {
  sessionKey,
});

// Use the file data
const fileContent = result.data.toString('utf8');
typescript