Skip to content

fix: use Connect encryption key to encrypt app identities#275

Merged
nikgraf merged 5 commits into
mainfrom
pcv/change-app-identity-encryption
Jul 22, 2025
Merged

fix: use Connect encryption key to encrypt app identities#275
nikgraf merged 5 commits into
mainfrom
pcv/change-app-identity-encryption

Conversation

@pcarranzav
Copy link
Copy Markdown
Member

@pcarranzav pcarranzav commented Jun 27, 2025

Depends on #276 - please merge that one first and change the base branch.
This simplifies the Connect flow removing an unnecessary wallet signature previously used to encrypt/decrypt the app identity.

@pcarranzav pcarranzav force-pushed the pcv/change-app-identity-encryption branch 3 times, most recently from 4e5b447 to 7aa132c Compare June 27, 2025 18:58
@pcarranzav pcarranzav marked this pull request as draft June 27, 2025 20:35
@pcarranzav pcarranzav force-pushed the pcv/change-app-identity-encryption branch 3 times, most recently from e608b19 to a2510cf Compare June 27, 2025 23:46
@pcarranzav pcarranzav marked this pull request as ready for review June 28, 2025 14:08
@pcarranzav pcarranzav force-pushed the pcv/change-app-identity-encryption branch from a2510cf to e67272d Compare June 28, 2025 16:33
@pcarranzav pcarranzav changed the base branch from main to pcv/fix-connect-keys June 28, 2025 16:34
@pcarranzav pcarranzav force-pushed the pcv/fix-connect-keys branch from 59de1c4 to c090340 Compare July 14, 2025 19:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR simplifies the Connect flow by removing the unnecessary wallet signature-based encryption for app identities and instead uses the Connect encryption key directly. This change eliminates the nonce field from app identity structures and updates the encryption/decryption methods to use a more straightforward approach.

  • Removes nonce field from all app identity schemas and database models
  • Replaces wallet signature-based encryption with direct Connect encryption key usage
  • Simplifies encryption/decryption functions by removing signer dependency

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/hypergraph/src/messages/types.ts Removes nonce field from RequestConnectCreateAppIdentity schema
packages/hypergraph/src/connect/types.ts Removes nonce field from AppIdentityResponse schema
packages/hypergraph/src/connect/identity-encryption.ts Refactors encryption/decryption to use Connect keys instead of wallet signatures
apps/server/src/index.ts Updates API endpoint to remove nonce handling
apps/server/src/handlers/create-app-identity.ts Removes nonce parameter from handler function
apps/server/prisma/schema.prisma Removes nonce field and unique constraint from AppIdentity model
apps/server/prisma/migrations/* Database migration to drop nonce column
apps/connect/src/routes/authenticate.tsx Updates client code to use new encryption method without signer

Comment on lines +169 to 173
const keysMsg = cryptoBoxSealOpen({
ciphertext: ciphertextBytes,
privateKey: hexToBytes(keys.encryptionPrivateKey),
publicKey: hexToBytes(keys.encryptionPublicKey),
});
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function should handle potential decryption failures and provide a meaningful error message. The cryptoBoxSealOpen function can throw if decryption fails, but there's no error handling or context about what went wrong.

Suggested change
const keysMsg = cryptoBoxSealOpen({
ciphertext: ciphertextBytes,
privateKey: hexToBytes(keys.encryptionPrivateKey),
publicKey: hexToBytes(keys.encryptionPublicKey),
});
let keysMsg: Uint8Array;
try {
keysMsg = cryptoBoxSealOpen({
ciphertext: ciphertextBytes,
privateKey: hexToBytes(keys.encryptionPrivateKey),
publicKey: hexToBytes(keys.encryptionPublicKey),
});
} catch (error) {
throw new Error('Decryption failed. Ensure the ciphertext and keys are correct.');
}

Copilot uses AI. Check for mistakes.
Comment on lines +169 to 173
const keysMsg = cryptoBoxSealOpen({
ciphertext: ciphertextBytes,
privateKey: hexToBytes(keys.encryptionPrivateKey),
publicKey: hexToBytes(keys.encryptionPublicKey),
});
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should wrap cryptoBoxSealOpen in a try-catch block to provide better error handling. If decryption fails, the error should indicate that the app identity could not be decrypted rather than exposing low-level crypto errors.

Suggested change
const keysMsg = cryptoBoxSealOpen({
ciphertext: ciphertextBytes,
privateKey: hexToBytes(keys.encryptionPrivateKey),
publicKey: hexToBytes(keys.encryptionPublicKey),
});
let keysMsg;
try {
keysMsg = cryptoBoxSealOpen({
ciphertext: ciphertextBytes,
privateKey: hexToBytes(keys.encryptionPrivateKey),
publicKey: hexToBytes(keys.encryptionPublicKey),
});
} catch (error) {
throw new Error("Failed to decrypt app identity. Please check the provided keys and ciphertext.");
}

Copilot uses AI. Check for mistakes.
@nikgraf nikgraf merged commit 141eb28 into main Jul 22, 2025
6 checks passed
@nikgraf nikgraf deleted the pcv/change-app-identity-encryption branch July 22, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants