import { createSealClient } from './seal-client';
class SealWalrusIntegration {
private sealClient: any;
private walrusClient: any;
constructor(sealClient: any, walrusClient: any) {
this.sealClient = sealClient;
this.walrusClient = walrusClient;
}
async storeEncryptedData(
data: Buffer,
recipientAddress: string,
accessPolicy?: any
) {
const encryptedData = await this.sealClient.encrypt({
data,
recipientId: recipientAddress,
accessPolicy
});
const blobId = await this.walrusClient.store(
encryptedData.ciphertext
);
return {
blobId,
encryptionId: encryptedData.encryptionId,
accessPolicy: encryptedData.accessPolicy
};
}
async retrieveAndDecrypt(
blobId: string,
encryptionId: string,
userKeypair: any
) {
const encryptedData = await this.walrusClient.retrieve(blobId);
const decryptedData = await this.sealClient.decrypt({
ciphertext: encryptedData,
encryptionId,
recipientId: userKeypair.toSuiAddress()
});
return decryptedData;
}
}
async function walrusExample() {
const { sealClient } = await createSealClient();
const walrusClient = new WalrusClient('https://walrus-testnet.sui.io');
const integration = new SealWalrusIntegration(sealClient, walrusClient);
const fileData = Buffer.from('중요한 문서 내용');
const recipientAddress = '0x...';
const result = await integration.storeEncryptedData(
fileData,
recipientAddress
);
console.log('Blob ID로 저장됨:', result.blobId);
const decrypted = await integration.retrieveAndDecrypt(
result.blobId,
result.encryptionId,
recipientKeypair
);
console.log('검색된 데이터:', decrypted.toString());
}