아래 다이어그램은 온체인 비밀 흐름을 보여줍니다: 볼트를 할당하고, TDH2로 비밀을
로컬에서 암호화한 다음, 암호문을 볼트에 기록합니다.
가장 간단한 “소유자 전용” 패턴은 지갑(EOA) 주소를 쓰기 조건과 읽기 조건 모두로
사용합니다. CDR 컨트랙트는 msg.sender가 구성된 조건 주소와 같으면 조건 검사를
건너뛰므로, 해당 지갑만이 볼트에 쓰거나 읽을 수 있습니다. 고수준 uploadCDR()
헬퍼는 조건 주소가 배포된 조건 컨트랙트를 가리키는지 검증하기 때문에, EOA
조건은 skipConditionValidation: true와 함께 저수준 allocate() 호출을 통해
구성됩니다.
import { initWasm, uuidToLabel } from "@piplabs/cdr-sdk";import { toHex } from "viem";await initWasm();// Assumes `client` and `walletClient` are already created (see Setup)const { uploader, observer } = client;const walletAddress = walletClient.account!.address;// Pure read: fetch the DKG global public keyconst globalPubKey = await observer.getGlobalPubKey();// Encode your secret as bytesconst secret = "my confidential data";const dataKey = new TextEncoder().encode(secret);// On-chain transaction: allocate a vault using the wallet address as the// write AND read condition. Only this EOA can write or read.const { uuid, txHash: allocateTx } = await uploader.allocate({ updatable: false, writeConditionAddr: walletAddress, readConditionAddr: walletAddress, writeConditionData: "0x", readConditionData: "0x", skipConditionValidation: true,});// Local: TDH2-encrypt the secret, bound to this vault's UUIDconst label = uuidToLabel(uuid);const ciphertext = await uploader.encryptDataKey({ dataKey, globalPubKey, label,});// On-chain transaction: write encrypted data to the vaultconst { txHash: writeTx } = await uploader.write({ uuid, accessAuxData: "0x", encryptedData: toHex(ciphertext.raw),});console.log(`Vault created with UUID: ${uuid}`);console.log(`Allocate tx: ${allocateTx}`);console.log(`Write tx: ${writeTx}`);
어떤 EOA 주소든 쓰기 또는 읽기 조건으로 작동하며, 해당 EOA만이 매칭되는
동작을 수행할 수 있습니다. 한쪽만 게이팅하려면 해당 측에 지갑 주소를
설정하고 다른 측에 조건 컨트랙트(예: LicenseReadCondition)를 설정하세요.
고수준 uploadCDR() 헬퍼는 양쪽 모두에 배포된 조건 컨트랙트가 있을 것을
기대하며 EOA 조건을 지원하지 않으므로, DATA Foundation 라이선스 게이트
읽기와 같은 패턴(IP Asset Vaults 참조)에는
헬퍼를 사용하고, 소유자 전용 EOA 조건에는 위에 표시된 저수준 allocate() +
write() 흐름을 사용하세요.
트랜잭션의 값은 수수료와 정확히 동일해야 합니다.
dataKey는 기존 매개변수 이름입니다. encryptDataKey()에서는 단지
암호화 키뿐만 아니라 어떤 비밀 바이트든 될 수 있습니다.
볼트 암호화 데이터는 Aeneid에서 1024바이트로 제한됩니다
(maxEncryptedDataSize). TDH2는 오버헤드를 추가하므로 최대 평문은 더 작습니다.
더 큰 콘텐츠의 경우, 작은 {cid, key} 페이로드만 볼트에 기록되도록
uploadFile()을 사용하세요.
암호화된 페이로드는 오프체인에 보관하고 암호화된 파일 키와 포인터만 볼트에
저장해야 할 때 파일 워크플로를 사용하세요.업로드는 데이터 소유자가 한 번 수행합니다. 다운로드는 나중에 권한이 있는
독자가 볼트 페이로드를 복구한 후 저장된 파일을 복호화하여 수행합니다.uploadFile() 헬퍼는 양쪽 모두에 배포된 조건 컨트랙트가 필요하므로, 아래
예제에서는 쓰기 측에 DATA Foundation의 OwnerWriteCondition을, 읽기 측에
LicenseReadCondition을 사용합니다. 라이선스 토큰 보유자는 파일을 복호화할 수
있습니다(엔드 투 엔드 라이선스 설정은 IP Asset Vaults
참조). 소유자 전용 파일 흐름의 경우, 지갑(EOA) 주소를 양쪽 조건 모두로 사용하여
앞서 표시된 저수준 단계를 복제하세요.