From 5330d7b20788aaf1f6621d93ec80cbdd11e21652 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 28 Jan 2025 14:56:19 -0300 Subject: [PATCH] fix: canonicalize identity before encrypting --- packages/hypergraph/src/identity/identity-encryption.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hypergraph/src/identity/identity-encryption.ts b/packages/hypergraph/src/identity/identity-encryption.ts index 8ffb5c21..668965e6 100644 --- a/packages/hypergraph/src/identity/identity-encryption.ts +++ b/packages/hypergraph/src/identity/identity-encryption.ts @@ -5,7 +5,7 @@ import { sha256 } from '@noble/hashes/sha256'; import type { Hex } from 'viem'; import { verifyMessage } from 'viem'; -import { bytesToHex, hexToBytes } from '../utils/index.js'; +import { bytesToHex, canonicalize, hexToBytes } from '../utils/index.js'; import type { IdentityKeys, Signer } from './types.js'; // Adapted from the XMTP approach to encrypt keys @@ -36,7 +36,7 @@ const encrypt = (msg: Uint8Array, secret: Uint8Array): string => { const ciphertext = aes.encrypt(msg); // TODO: Use Effect Schema and better serialization? - const ciphertextJson = JSON.stringify({ + const ciphertextJson = canonicalize({ aes256GcmHkdfSha256: { payload: bytesToHex(ciphertext), hkdfSalt: bytesToHex(hkdfSalt),