diff --git a/lib/types/avatar-types.js b/lib/types/avatar-types.js --- a/lib/types/avatar-types.js +++ b/lib/types/avatar-types.js @@ -65,6 +65,12 @@ +encryptionKey: string, +thumbHash: ?string, }; +const clientEncryptedImageAvatarValidator = tShape({ + type: tString('encrypted_image'), + blobURI: t.String, + encryptionKey: t.String, + thumbHash: t.maybe(t.String), +}); export type ClientENSAvatar = ENSAvatarDBContent; const clientENSAvatarValidator = ensAvatarDBContentValidator; @@ -78,6 +84,7 @@ clientEmojiAvatarValidator, clientImageAvatarValidator, clientENSAvatarValidator, + clientEncryptedImageAvatarValidator, ]); export type ResolvedClientAvatar = diff --git a/lib/utils/avatar-utils.js b/lib/utils/avatar-utils.js --- a/lib/utils/avatar-utils.js +++ b/lib/utils/avatar-utils.js @@ -17,6 +17,12 @@ uploadID: tID, }); +const encryptedImageAvatarDBContentValidator: TInterface = + tShape({ + type: tString('encrypted_image'), + uploadID: tID, + }); + const updateUserAvatarRemoveRequestValidator: TInterface = tShape({ type: tString('remove'), @@ -26,6 +32,7 @@ t.union([ emojiAvatarDBContentValidator, imageAvatarDBContentValidator, + encryptedImageAvatarDBContentValidator, ensAvatarDBContentValidator, updateUserAvatarRemoveRequestValidator, ]); @@ -33,6 +40,7 @@ export { emojiAvatarDBContentValidator, imageAvatarDBContentValidator, + encryptedImageAvatarDBContentValidator, ensAvatarDBContentValidator, updateUserAvatarRemoveRequestValidator, updateUserAvatarRequestValidator, diff --git a/lib/utils/avatar-utils.test.js b/lib/utils/avatar-utils.test.js --- a/lib/utils/avatar-utils.test.js +++ b/lib/utils/avatar-utils.test.js @@ -4,6 +4,7 @@ emojiAvatarDBContentValidator, ensAvatarDBContentValidator, imageAvatarDBContentValidator, + encryptedImageAvatarDBContentValidator, updateUserAvatarRequestValidator, } from './avatar-utils.js'; @@ -85,6 +86,35 @@ }); }); +describe('encryptedImageAvatarDBContentValidator', () => { + it('should succeed for valid input', () => { + expect( + encryptedImageAvatarDBContentValidator.is({ + type: 'encrypted_image', + uploadID: '123456', + }), + ).toBe(true); + }); + + it('should fail if type is incorrect', () => { + expect( + encryptedImageAvatarDBContentValidator.is({ + type: 'emoji', + uploadID: '123456', + }), + ).toBe(false); + }); + + it('should fail if uploadID is incorrect type', () => { + expect( + encryptedImageAvatarDBContentValidator.is({ + type: 'encrypted_image', + uploadID: 123456, + }), + ).toBe(false); + }); +}); + describe('ensAvatarDBContentValidator', () => { it('should succeed for valid input', () => { expect(