Skip to content

feat: add email subscription #1081

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions scripts/generateHashWithTypes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { createHash } = require('crypto');

const types = {
Statement: [
DeleteSubscription: [
{ name: 'from', type: 'address' },
{ name: 'timestamp', type: 'uint64' },
{ name: 'space', type: 'string' },
{ name: 'about', type: 'string' },
{ name: 'statement', type: 'string' }
{ name: 'type', type: 'string' },
{ name: 'value', type: 'string' },
{ name: 'timestamp', type: 'uint64' }
]
};
function sha256(str) {
Expand Down
23 changes: 23 additions & 0 deletions src/schemas/delete-subscription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/DeleteSubscription",
"definitions": {
"DeleteSubscription": {
"title": "DeleteSubscription",
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["email"]
},
"value": {
"type": "string",
"title": "value",
"maxLength": 256
}
},
"required": ["type", "value"],
"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 subscription from './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,
subscription: subscription.definitions.Subscription,
statement: statement.definitions.Statement,
zodiac: zodiac.definitions.Zodiac,
alias: alias.definitions.Alias
Expand Down
27 changes: 27 additions & 0 deletions src/schemas/subscription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Subscription",
"definitions": {
"Subscription": {
"title": "Subscription",
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["email"]
},
"value": {
"type": "string",
"title": "value",
"maxLength": 256
},
"metadata": {
"type": "string",
"title": "metadata"
}
},
"required": ["type", "value"],
"additionalProperties": false
}
}
}
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",
"499ff7269df478dede66b3c0b96a0b90286c479b4013b423ac7cf8628a94e6db": "subscription",
"da79044f9b55496aed0fa5fdb25aff50b07f59fde4d22e02ab5da9d65da546e1": "delete-subscription"
}
12 changes: 11 additions & 1 deletion src/sign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Profile,
Alias,
DeleteSpace,
DeleteSubscription,
Statement,
spaceTypes,
proposalTypes,
Expand All @@ -36,7 +37,8 @@ import {
profileTypes,
aliasTypes,
deleteSpaceType,
statementTypes
statementTypes,
deleteSubscriptionTypes
} from './types';
import constants from '../constants.json';

Expand Down Expand Up @@ -234,4 +236,12 @@ export default class Client {
) {
return await this.sign(web3, address, message, deleteSpaceType);
}

async deleteSubscription(
web3: Web3Provider | Wallet,
address: string,
message: DeleteSubscription
) {
return await this.sign(web3, address, message, deleteSubscriptionTypes);
}
}
26 changes: 26 additions & 0 deletions src/sign/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ export interface DeleteSpace {
timestamp?: number;
}

export interface DeleteSubscription {
from?: string;
type: string;
value: string;
timestamp?: number;
}

export const spaceTypes = {
Space: [
{ name: 'from', type: 'address' },
Expand Down Expand Up @@ -345,3 +352,22 @@ export const deleteSpaceType = {
{ name: 'timestamp', type: 'uint64' }
]
};

export const subscriptionTypes = {
Subscription: [
{ name: 'from', type: 'address' },
{ name: 'type', type: 'string' },
{ name: 'value', type: 'string' },
{ name: 'metadata', type: 'string' },
{ name: 'timestamp', type: 'uint64' }
]
};

export const deleteSubscriptionTypes = {
DeleteSubscription: [
{ name: 'from', type: 'address' },
{ name: 'type', type: 'string' },
{ name: 'value', type: 'string' },
{ 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