Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 13 additions & 63 deletions apps/solana/token-gated/app/lib/encryption.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ace } from "@aptos-labs/ace-sdk";
import { config } from "./config";

// ============================================================================
Expand Down Expand Up @@ -85,96 +84,47 @@ export async function decryptFile(
// ============================================================================
// ACE Threshold IBE (for key encryption - the "greenBox")
// ============================================================================
// NOTE: These functions are placeholders. The @aptos-labs/ace-sdk package
// is not available in npm registry. Implement these with an alternative
// threshold encryption library or restore when the package is available.

/**
* Create an ACE committee instance.
* @deprecated - Package @aptos-labs/ace-sdk not available in npm registry
*/
export function createAceCommittee(): ace.Committee {
return new ace.Committee({
workerEndpoints: [...config.ace.workerEndpoints] as string[],
threshold: config.ace.threshold,
});
export function createAceCommittee() {
throw new Error("ACE committee functionality is not available. @aptos-labs/ace-sdk package is not in npm registry.");
}

/**
* Create an ACE contract ID for Solana.
* @deprecated - Package @aptos-labs/ace-sdk not available in npm registry
*/
export function createAceContractId(): ace.ContractID {
return ace.ContractID.newSolana({
knownChainName: config.ace.solanaChainName,
programId: config.programs.aceHook,
});
export function createAceContractId() {
throw new Error("ACE contract ID functionality is not available. @aptos-labs/ace-sdk package is not in npm registry.");
}

/**
* Encrypt the redKey into a greenBox using threshold IBE.
* This greenBox can only be decrypted by users who have purchased access.
* @deprecated - Package @aptos-labs/ace-sdk not available in npm registry
*/
export async function encryptRedKey(
redKey: Uint8Array,
fullBlobNameBytes: Uint8Array
): Promise<Uint8Array> {
const committee = createAceCommittee();
const contractId = createAceContractId();

// Fetch encryption key from committee
const encryptionKeyResult = await ace.EncryptionKey.fetch({
committee,
});
const encryptionKey = encryptionKeyResult.unwrapOrThrow(
"Failed to fetch encryption key"
);

// Encrypt the redKey
const encryptResult = ace.encrypt({
encryptionKey,
contractId,
domain: fullBlobNameBytes,
plaintext: redKey,
}).unwrapOrThrow("Failed to encrypt redKey");

return encryptResult.ciphertext.toBytes();
throw new Error("ACE encryption functionality is not available. @aptos-labs/ace-sdk package is not in npm registry.");
}

/**
* Decrypt the greenBox to recover the redKey using a proof-of-permission transaction.
* @param signedTransactionBytes - Serialized signed transaction bytes (from any Solana SDK)
* @deprecated - Package @aptos-labs/ace-sdk not available in npm registry
*/
export async function decryptGreenBox(
greenBoxBytes: Uint8Array,
fullBlobNameBytes: Uint8Array,
signedTransactionBytes: Uint8Array
): Promise<Uint8Array> {
const committee = createAceCommittee();
const contractId = createAceContractId();

// Reconstruct the ciphertext from bytes
const greenBox = ace.Ciphertext.fromBytes(greenBoxBytes).unwrapOrThrow(
"Failed to parse greenBox ciphertext"
);

// Create proof of permission from the signed transaction bytes
const pop = ace.ProofOfPermission.createSolana({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
txn: signedTransactionBytes as any,
});

// Fetch decryption key from committee
const decryptionKeyResult = await ace.DecryptionKey.fetch({
committee,
contractId,
domain: fullBlobNameBytes,
proof: pop,
});
const decryptionKey = decryptionKeyResult.unwrapOrThrow(
"Failed to fetch decryption key"
);

// Decrypt the greenBox
const plaintext = ace.decrypt({
decryptionKey,
ciphertext: greenBox,
}).unwrapOrThrow("Failed to decrypt greenBox");

return plaintext;
throw new Error("ACE decryption functionality is not available. @aptos-labs/ace-sdk package is not in npm registry.");
}
1 change: 0 additions & 1 deletion apps/solana/token-gated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@solana/react-hooks": "^1.1.5",
"@solana/web3.js": "^1.98.4",
"@tanstack/react-query": "^5.90.16",
"@aptos-labs/ace-sdk": "^0.1.0",
"next": "16.0.10",
"react": "^19.1.0",
"react-dom": "^19.1.0",
Expand Down
1 change: 1 addition & 0 deletions examples
Submodule examples added at 5663b2
17 changes: 0 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.