diff --git a/packages/api-kit/src/SafeApiKit.ts b/packages/api-kit/src/SafeApiKit.ts index 2dc05fd15..d757e8be8 100644 --- a/packages/api-kit/src/SafeApiKit.ts +++ b/packages/api-kit/src/SafeApiKit.ts @@ -659,7 +659,7 @@ class SafeApiKit { async addMessage( safeAddress: string, - { message, safeAppId, signature }: AddMessageProps + { message, safeAppId = 0, signature }: AddMessageProps ): Promise { if (!safeAddress) { throw new Error('Invalid safeAddress') diff --git a/packages/api-kit/src/types/safeTransactionServiceTypes.ts b/packages/api-kit/src/types/safeTransactionServiceTypes.ts index dd383c938..00a4880e6 100644 --- a/packages/api-kit/src/types/safeTransactionServiceTypes.ts +++ b/packages/api-kit/src/types/safeTransactionServiceTypes.ts @@ -301,6 +301,6 @@ export type EIP712TypedData = { export type AddMessageProps = { message: string | EIP712TypedData - safeAppId: number + safeAppId?: number signature: string } diff --git a/packages/api-kit/tests/e2e/addMessage.test.ts b/packages/api-kit/tests/e2e/addMessage.test.ts new file mode 100644 index 000000000..5a89cc2f8 --- /dev/null +++ b/packages/api-kit/tests/e2e/addMessage.test.ts @@ -0,0 +1,45 @@ +import { Signer } from '@ethersproject/abstract-signer' +import SafeApiKit, { AddSafeDelegateProps } from '@safe-global/api-kit/index' +import chai from 'chai' +import chaiAsPromised from 'chai-as-promised' +import config from '../utils/config' +import { getServiceClient } from '../utils/setupServiceClient' +import { ethers } from 'ethers' + +chai.use(chaiAsPromised) + +let safeApiKit: SafeApiKit +let signer: Signer + +const MESSAGE = 'I am the owner of this safe' + +describe.only('addMessage', () => { + before(async () => { + ;({ safeApiKit, signer } = await getServiceClient( + '0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d' + )) + }) + + it('should fail if safeAddress is empty', async () => { + await chai + .expect( + safeApiKit.addMessage('', { + message: MESSAGE, + signature: '0x' + }) + ) + .to.be.rejectedWith('Invalid safeAddress') + }) + + it('should allow to add an offchain message', async () => { + console.log(await signer.getAddress()) + const signature = await signer.signMessage(MESSAGE) + + await chai.expect( + safeApiKit.addMessage('0x9D1E7371852a9baF631Ea115b9815deb97cC3205', { + message: MESSAGE, + signature + }) + ).to.be.fulfilled + }) +})