diff --git a/src/utils/aleph-persistent-storage.ts b/src/utils/aleph-persistent-storage.ts index c756ebc..bc52a96 100644 --- a/src/utils/aleph-persistent-storage.ts +++ b/src/utils/aleph-persistent-storage.ts @@ -87,59 +87,39 @@ export class AlephPersistentStorage { subAccount: BaseAccount, accountClient: AuthenticatedAlephHttpClient, ) { - try { - // TODO: Add zod parsing - const securitySettings = (await accountClient.fetchAggregate(account.address, SECURITY_AGGREGATE_KEY)) as any; - - type SecurityAuthorization = { - address: string; - chain?: string; - channels?: string; - types?: string; - post_types?: string; - aggregate_keys?: string; - }; - - if ( - !securitySettings.authorizations.find( - (authorization: SecurityAuthorization) => - authorization.address === subAccount.address && - authorization.types === undefined && - authorization.channels?.includes(LIBERTAI_GENERAL_CHANNEL) && - authorization.channels?.includes(LIBERTAI_UI_CHANNEL), - ) - ) { - const oldAuthorizations = securitySettings.authorizations.filter( - (a: SecurityAuthorization) => a.address !== subAccount.address, - ); - - await accountClient.createAggregate({ - key: SECURITY_AGGREGATE_KEY, - content: { - authorizations: [ - ...oldAuthorizations, - { - address: subAccount.address, - channels: [LIBERTAI_GENERAL_CHANNEL, LIBERTAI_UI_CHANNEL], - }, - ], - }, - }); - } - } catch (error) { - // Security aggregate does not exist or with invalid content, creating a new one - await accountClient.createAggregate({ - key: SECURITY_AGGREGATE_KEY, - content: { - authorizations: [ - { - address: subAccount.address, - channels: [LIBERTAI_GENERAL_CHANNEL, LIBERTAI_UI_CHANNEL], - }, - ], - }, - }); - } + type SecurityAuthorization = { + address: string; + chain?: string; + channels?: string[]; + types?: string[]; + post_types?: string[]; + aggregate_keys?: string[]; + }; + + const agentsAuthorization: SecurityAuthorization = { + chain: 'ETH', + address: '0x501DD421f2B9F96E3e20945f42aeCBDd4A607a03', + channels: ['libertai', 'libertai-agents'], + types: ['POST', 'STORE', 'PROGRAM'], + post_types: ['libertai-agent'], + }; + + const subscriptionsAuthorization: SecurityAuthorization = { + chain: 'ETH', + address: '0x964c8A4cDabDa3c1f2E84662714563684599f76F', + channels: ['libertai', 'libertai-subscriptions'], + types: ['POST'], + post_types: ['libertai-subscription'], + }; + + const mosheAuthorizations: SecurityAuthorization[] = [agentsAuthorization, subscriptionsAuthorization]; + + await accountClient.createAggregate({ + key: SECURITY_AGGREGATE_KEY, + content: { + authorizations: mosheAuthorizations, + }, + }); } private static async getAlephAccount(chain: AccountChain): Promise {