diff --git a/src/utils/aleph-persistent-storage.ts b/src/utils/aleph-persistent-storage.ts index d026e9b..369438a 100644 --- a/src/utils/aleph-persistent-storage.ts +++ b/src/utils/aleph-persistent-storage.ts @@ -8,7 +8,13 @@ import { import { AuthenticatedAlephHttpClient } from '@aleph-sdk/client'; import { ItemType } from '@aleph-sdk/message'; import { getAccountFromProvider as getSolAccountFromProvider, SOLAccount } from '@aleph-sdk/solana'; -import { type Config, getConnectorClient, signMessage as signWagmiMessage } from '@wagmi/core'; +import { + type Config, + getConnections, + getConnectorClient, + signMessage as signWagmiMessage, + switchChain, +} from '@wagmi/core'; import { base } from '@wagmi/vue/chains'; import { PrivateKey } from 'eciesjs'; import { providers } from 'ethers'; @@ -155,6 +161,13 @@ export class AlephPersistentStorage { private static async getAlephAccount(chain: AccountChain): Promise { if (chain === 'base') { + const connections = getConnections(config); + if (connections.length === 0) { + throw Error('No wallet connection active'); + } + if (connections[0].chainId !== env.WAGMI_BASE_ID) { + await switchChain(config, { chainId: env.WAGMI_BASE_ID }); + } const provider = await getEthersProvider(config); return getBaseAccountFromProvider(provider); } else { diff --git a/src/utils/encryption.ts b/src/utils/encryption.ts index 7431806..c7ff27b 100644 --- a/src/utils/encryption.ts +++ b/src/utils/encryption.ts @@ -24,7 +24,7 @@ export const decrypt = (encryptedText: string, key: Buffer, iv: Buffer): string export const encryptFile = async (file: File, key: Buffer, iv: Buffer): Promise => { const arrayBuffer = await file.arrayBuffer(); - const bufferString = Buffer.from(arrayBuffer).toString('hex'); + const bufferString = Buffer.from(arrayBuffer).toString(BUFFER_ENCODING); const encryptedString = encrypt(bufferString, key, iv); return Buffer.from(encryptedString); }; @@ -32,7 +32,7 @@ export const encryptFile = async (file: File, key: Buffer, iv: Buffer): Promise< export const decryptFile = (arrayBuffer: ArrayBuffer, key: Buffer, iv: Buffer): Buffer => { const fileBufferString = Buffer.from(arrayBuffer).toString(); const decryptedString = decrypt(fileBufferString, key, iv); - return Buffer.from(decryptedString, 'hex'); + return Buffer.from(decryptedString, BUFFER_ENCODING); }; export const generateKey = () => Buffer.from(randomBytes(16).toString('hex'));