diff --git a/src/schemas/email-subscription.json b/src/schemas/email-subscription.json new file mode 100644 index 000000000..677282831 --- /dev/null +++ b/src/schemas/email-subscription.json @@ -0,0 +1,28 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/EmailSubscription", + "definitions": { + "EmailSubscription": { + "title": "EmailSubscription", + "type": "object", + "properties": { + "email": { + "type": "string", + "format": "email", + "title": "value", + "maxLength": 256 + }, + "subscriptions": { + "title": "subscriptions", + "type": "array", + "items": { + "type": "string", + "enum": ["summary", "newProposal", "closedProposal"] + } + } + }, + "required": [], + "additionalProperties": false + } + } +} diff --git a/src/schemas/index.ts b/src/schemas/index.ts index b95dccd18..f8f795f7f 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -3,6 +3,7 @@ import proposal from './proposal.json'; import updateProposal from './update-proposal.json'; import vote from './vote.json'; import profile from './profile.json'; +import emailSubscription from './email-subscription.json'; import statement from './statement.json'; import zodiac from './zodiac.json'; import alias from './alias.json'; @@ -13,6 +14,7 @@ export default { updateProposal: updateProposal.definitions.UpdateProposal, vote: vote.definitions.Vote, profile: profile.definitions.Profile, + emailSubscription: emailSubscription.definitions.EmailSubscription, statement: statement.definitions.Statement, zodiac: zodiac.definitions.Zodiac, alias: alias.definitions.Alias diff --git a/src/sign/hashedTypes.json b/src/sign/hashedTypes.json index 039741d3b..c1b41244c 100644 --- a/src/sign/hashedTypes.json +++ b/src/sign/hashedTypes.json @@ -62,5 +62,7 @@ "2ffbebcbd22ef48fd2f4a1182ff1feda7795b57689bd6f0dd73c89e925e7fefb": "profile", "4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement", "d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal", - "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal" + "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal", + "e3bd9bf9665e4dd5be252408e6d7c9e9a4572897153171a31e39e11641162003": "email-subscription", + "339bef62ba146350b9dfdcf04203c2b3c7f19effd1d8804954a8189645112394": "delete-email-subscription" } diff --git a/src/sign/index.ts b/src/sign/index.ts index af38c293f..2aaa8806f 100644 --- a/src/sign/index.ts +++ b/src/sign/index.ts @@ -16,6 +16,8 @@ import { Profile, Alias, DeleteSpace, + EmailSubscription, + DeleteEmailSubscription, Statement, spaceTypes, proposalTypes, @@ -36,7 +38,9 @@ import { profileTypes, aliasTypes, deleteSpaceType, - statementTypes + statementTypes, + emailSubscriptionTypes, + deleteEmailSubscriptionTypes } from './types'; import constants from '../constants.json'; @@ -234,4 +238,25 @@ export default class Client { ) { return await this.sign(web3, address, message, deleteSpaceType); } + + async emailSubscription( + web3: Web3Provider | Wallet, + address: string, + message: EmailSubscription + ) { + return await this.sign(web3, address, message, emailSubscriptionTypes); + } + + async deleteEmailSubscription( + web3: Web3Provider | Wallet, + address: string, + message: DeleteEmailSubscription + ) { + return await this.sign( + web3, + address, + message, + deleteEmailSubscriptionTypes + ); + } } diff --git a/src/sign/types.ts b/src/sign/types.ts index 6979d8e6c..1d3d6ea30 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -126,6 +126,18 @@ export interface DeleteSpace { timestamp?: number; } +export interface EmailSubscription { + from?: string; + email?: string; + subscriptions?: string[]; + timestamp?: number; +} + +export interface DeleteEmailSubscription { + from?: string; + timestamp?: number; +} + export const spaceTypes = { Space: [ { name: 'from', type: 'address' }, @@ -345,3 +357,19 @@ export const deleteSpaceType = { { name: 'timestamp', type: 'uint64' } ] }; + +export const emailSubscriptionTypes = { + EmailSubscription: [ + { name: 'from', type: 'address' }, + { name: 'email', type: 'string' }, + { name: 'subscriptions', type: 'string[]' }, + { name: 'timestamp', type: 'uint64' } + ] +}; + +export const deleteEmailSubscriptionTypes = { + DeleteEmailSubscription: [ + { name: 'from', type: 'address' }, + { name: 'timestamp', type: 'uint64' } + ] +}; diff --git a/test/examples/subscription.json b/test/examples/subscription.json new file mode 100644 index 000000000..a8f6c3301 --- /dev/null +++ b/test/examples/subscription.json @@ -0,0 +1,5 @@ +{ + "type": "email", + "value": "my-email@snapshot.org", + "metadata": "['summary', 'newProposal']" +} diff --git a/test/schema.spec.ts b/test/schema.spec.ts index 2abd2b60f..90960db45 100644 --- a/test/schema.spec.ts +++ b/test/schema.spec.ts @@ -7,6 +7,7 @@ import spaceStarknetDelegation from './examples/space-starknet-delegation.json'; import proposalTurbo from './examples/proposal-turbo.json'; import vote from './examples/vote.json'; import profile from './examples/profile.json'; +import subscription from './examples/subscription.json'; import statement from './examples/statement.json'; import alias from './examples/alias.json'; import schemas from '../src/schemas'; @@ -24,6 +25,11 @@ describe.each([ { schemaType: 'proposal', schema: schemas.proposal, example: proposal }, { schemaType: 'vote', schema: schemas.vote, example: vote }, { schemaType: 'profile', schema: schemas.profile, example: profile }, + { + schemaType: 'subscription', + schema: schemas.subscription, + example: subscription + }, { schemaType: 'statement', schema: schemas.statement, example: statement }, { schemaType: 'zodiac', schema: schemas.zodiac, example: space }, { schemaType: 'alias', schema: schemas.alias, example: alias }