Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add email subscription #1081

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
28 changes: 28 additions & 0 deletions src/schemas/email-subscription.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 2 additions & 0 deletions src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/sign/hashedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@
"2ffbebcbd22ef48fd2f4a1182ff1feda7795b57689bd6f0dd73c89e925e7fefb": "profile",
"4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement",
"d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal",
"df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal"
"df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal",
"e3bd9bf9665e4dd5be252408e6d7c9e9a4572897153171a31e39e11641162003": "email-subscription",
"339bef62ba146350b9dfdcf04203c2b3c7f19effd1d8804954a8189645112394": "delete-email-subscription"
}
27 changes: 26 additions & 1 deletion src/sign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
Profile,
Alias,
DeleteSpace,
EmailSubscription,
DeleteEmailSubscription,
Statement,
spaceTypes,
proposalTypes,
Expand All @@ -36,7 +38,9 @@ import {
profileTypes,
aliasTypes,
deleteSpaceType,
statementTypes
statementTypes,
emailSubscriptionTypes,
deleteEmailSubscriptionTypes
} from './types';
import constants from '../constants.json';

Expand Down Expand Up @@ -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
);
}
}
28 changes: 28 additions & 0 deletions src/sign/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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' }
]
};
5 changes: 5 additions & 0 deletions test/examples/subscription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "email",
"value": "[email protected]",
"metadata": "['summary', 'newProposal']"
Comment on lines +2 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what this file is for 🤔

}
6 changes: 6 additions & 0 deletions test/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should rename this file also to avoid confusions

import statement from './examples/statement.json';
import alias from './examples/alias.json';
import schemas from '../src/schemas';
Expand All @@ -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 }
Expand Down
Loading