From a61292a0b940fc91dac115eab2fc98c122c7b93c Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Mon, 28 Oct 2024 01:38:43 +0400 Subject: [PATCH 01/13] feat: add-email-subscription-to-profile --- src/schemas/profile.json | 18 ++++++++++++++++++ .../examples/profile-addEmailSubscription.json | 8 ++++++++ .../profile-updateEmailSubscription.json | 8 ++++++++ test/schema.spec.ts | 12 ++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 test/examples/profile-addEmailSubscription.json create mode 100644 test/examples/profile-updateEmailSubscription.json diff --git a/src/schemas/profile.json b/src/schemas/profile.json index aef11d085..64a41b2be 100644 --- a/src/schemas/profile.json +++ b/src/schemas/profile.json @@ -51,6 +51,24 @@ "title": "farcaster", "pattern": "^[a-z0-9-]*$", "maxLength": 17 + }, + "emailSubscription": { + "type": "object", + "properties": { + "email": { + "type": "string", + "title": "email", + "maxLength": 256 + }, + "subscriptions": { + "type": "array", + "title": "subscriptions", + "uniqueItems": true, + "items": { "type": "string" } + } + }, + "required": [], + "additionalProperties": false } }, "required": [], diff --git a/test/examples/profile-addEmailSubscription.json b/test/examples/profile-addEmailSubscription.json new file mode 100644 index 000000000..c53877b43 --- /dev/null +++ b/test/examples/profile-addEmailSubscription.json @@ -0,0 +1,8 @@ +{ + "name": "Vitalik", + "avatar": "ipfs://NnVTdgcFciJUoxqgsNe9Hy2R7rgvEb5jDu5Pa5mmEG3UghbubTf2M78jUXbKLqKM", + "about": "This is my about info", + "emailSubscription": { + "email": "test@email.com" + } +} diff --git a/test/examples/profile-updateEmailSubscription.json b/test/examples/profile-updateEmailSubscription.json new file mode 100644 index 000000000..f08a6beee --- /dev/null +++ b/test/examples/profile-updateEmailSubscription.json @@ -0,0 +1,8 @@ +{ + "name": "Vitalik", + "avatar": "ipfs://NnVTdgcFciJUoxqgsNe9Hy2R7rgvEb5jDu5Pa5mmEG3UghbubTf2M78jUXbKLqKM", + "about": "This is my about info", + "emailSubscription": { + "subscriptions": ["summary", "newProposal"] + } +} diff --git a/test/schema.spec.ts b/test/schema.spec.ts index 2abd2b60f..dd78eb4d0 100644 --- a/test/schema.spec.ts +++ b/test/schema.spec.ts @@ -7,6 +7,8 @@ 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 profileAddEmailSubscription from './examples/profile-addEmailSubscription.json'; +import profileUpdateEmailSubscription from './examples/profile-updateEmailSubscription.json'; import statement from './examples/statement.json'; import alias from './examples/alias.json'; import schemas from '../src/schemas'; @@ -24,6 +26,16 @@ describe.each([ { schemaType: 'proposal', schema: schemas.proposal, example: proposal }, { schemaType: 'vote', schema: schemas.vote, example: vote }, { schemaType: 'profile', schema: schemas.profile, example: profile }, + { + schemaType: 'profile', + schema: schemas.profile, + example: profileAddEmailSubscription + }, + { + schemaType: 'profile', + schema: schemas.profile, + example: profileUpdateEmailSubscription + }, { schemaType: 'statement', schema: schemas.statement, example: statement }, { schemaType: 'zodiac', schema: schemas.zodiac, example: space }, { schemaType: 'alias', schema: schemas.alias, example: alias } From ed5304c48c4b326dcc686be0ce70ab388e1bd7c3 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:35:03 +0900 Subject: [PATCH 02/13] fix: move out email subscription creation from profile --- src/schemas/profile.json | 22 +++++-------------- .../profile-addEmailSubscription.json | 8 ------- .../profile-updateEmailSubscription.json | 4 +--- test/schema.spec.ts | 6 ----- 4 files changed, 6 insertions(+), 34 deletions(-) delete mode 100644 test/examples/profile-addEmailSubscription.json diff --git a/src/schemas/profile.json b/src/schemas/profile.json index 64a41b2be..e30c6f15c 100644 --- a/src/schemas/profile.json +++ b/src/schemas/profile.json @@ -52,23 +52,11 @@ "pattern": "^[a-z0-9-]*$", "maxLength": 17 }, - "emailSubscription": { - "type": "object", - "properties": { - "email": { - "type": "string", - "title": "email", - "maxLength": 256 - }, - "subscriptions": { - "type": "array", - "title": "subscriptions", - "uniqueItems": true, - "items": { "type": "string" } - } - }, - "required": [], - "additionalProperties": false + "emailSubscriptions": { + "type": "array", + "title": "email subscriptions", + "uniqueItems": true, + "items": { "type": "string" } } }, "required": [], diff --git a/test/examples/profile-addEmailSubscription.json b/test/examples/profile-addEmailSubscription.json deleted file mode 100644 index c53877b43..000000000 --- a/test/examples/profile-addEmailSubscription.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "Vitalik", - "avatar": "ipfs://NnVTdgcFciJUoxqgsNe9Hy2R7rgvEb5jDu5Pa5mmEG3UghbubTf2M78jUXbKLqKM", - "about": "This is my about info", - "emailSubscription": { - "email": "test@email.com" - } -} diff --git a/test/examples/profile-updateEmailSubscription.json b/test/examples/profile-updateEmailSubscription.json index f08a6beee..b893c4bdd 100644 --- a/test/examples/profile-updateEmailSubscription.json +++ b/test/examples/profile-updateEmailSubscription.json @@ -2,7 +2,5 @@ "name": "Vitalik", "avatar": "ipfs://NnVTdgcFciJUoxqgsNe9Hy2R7rgvEb5jDu5Pa5mmEG3UghbubTf2M78jUXbKLqKM", "about": "This is my about info", - "emailSubscription": { - "subscriptions": ["summary", "newProposal"] - } + "emailSubscriptions": ["summary", "newProposal"] } diff --git a/test/schema.spec.ts b/test/schema.spec.ts index dd78eb4d0..b82d15934 100644 --- a/test/schema.spec.ts +++ b/test/schema.spec.ts @@ -7,7 +7,6 @@ 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 profileAddEmailSubscription from './examples/profile-addEmailSubscription.json'; import profileUpdateEmailSubscription from './examples/profile-updateEmailSubscription.json'; import statement from './examples/statement.json'; import alias from './examples/alias.json'; @@ -26,11 +25,6 @@ describe.each([ { schemaType: 'proposal', schema: schemas.proposal, example: proposal }, { schemaType: 'vote', schema: schemas.vote, example: vote }, { schemaType: 'profile', schema: schemas.profile, example: profile }, - { - schemaType: 'profile', - schema: schemas.profile, - example: profileAddEmailSubscription - }, { schemaType: 'profile', schema: schemas.profile, From 37a0014c9157f1dde92d16d585595dc4ab33a276 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:52:27 +0900 Subject: [PATCH 03/13] feat: add Subscription schema --- src/schemas/index.ts | 2 ++ src/schemas/subscription.json | 23 +++++++++++++++++++++++ src/sign/hashedTypes.json | 3 ++- src/sign/types.ts | 9 +++++++++ test/examples/subscription.json | 4 ++++ test/schema.spec.ts | 6 ++++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/schemas/subscription.json create mode 100644 test/examples/subscription.json diff --git a/src/schemas/index.ts b/src/schemas/index.ts index b95dccd18..f5e603210 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 subscription from './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, + subscription: subscription.definitions.Subscription, statement: statement.definitions.Statement, zodiac: zodiac.definitions.Zodiac, alias: alias.definitions.Alias diff --git a/src/schemas/subscription.json b/src/schemas/subscription.json new file mode 100644 index 000000000..841d0d39e --- /dev/null +++ b/src/schemas/subscription.json @@ -0,0 +1,23 @@ +{ + "$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 + } + }, + "required": ["type", "value"], + "additionalProperties": false + } + } +} diff --git a/src/sign/hashedTypes.json b/src/sign/hashedTypes.json index 039741d3b..c7238cb54 100644 --- a/src/sign/hashedTypes.json +++ b/src/sign/hashedTypes.json @@ -62,5 +62,6 @@ "2ffbebcbd22ef48fd2f4a1182ff1feda7795b57689bd6f0dd73c89e925e7fefb": "profile", "4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement", "d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal", - "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal" + "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal", + "3c211382d04e80cbd21f3275e0674387bde366bbb885215e3735151763ca2813": "subscription" } diff --git a/src/sign/types.ts b/src/sign/types.ts index 6979d8e6c..db136a6ea 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -345,3 +345,12 @@ export const deleteSpaceType = { { name: 'timestamp', type: 'uint64' } ] }; + +export const subscriptionTypes = { + Subscription: [ + { name: 'from', type: 'address' }, + { name: 'type', type: 'string' }, + { name: 'value', type: 'string' }, + { name: 'timestamp', type: 'uint64' } + ] +}; diff --git a/test/examples/subscription.json b/test/examples/subscription.json new file mode 100644 index 000000000..0fecc2b44 --- /dev/null +++ b/test/examples/subscription.json @@ -0,0 +1,4 @@ +{ + "type": "email", + "value": "my-email@snapshot.org" +} diff --git a/test/schema.spec.ts b/test/schema.spec.ts index b82d15934..f5f8045ed 100644 --- a/test/schema.spec.ts +++ b/test/schema.spec.ts @@ -8,6 +8,7 @@ import proposalTurbo from './examples/proposal-turbo.json'; import vote from './examples/vote.json'; import profile from './examples/profile.json'; import profileUpdateEmailSubscription from './examples/profile-updateEmailSubscription.json'; +import subscription from './examples/subscription.json'; import statement from './examples/statement.json'; import alias from './examples/alias.json'; import schemas from '../src/schemas'; @@ -30,6 +31,11 @@ describe.each([ schema: schemas.profile, example: profileUpdateEmailSubscription }, + { + 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 } From 977a8c586ac9a0967bba01ade24a88b1141f1984 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:18:37 +0900 Subject: [PATCH 04/13] refactor: move emailSubscription to subscription --- src/schemas/profile.json | 6 ------ src/schemas/subscription.json | 4 ++++ src/sign/hashedTypes.json | 2 +- src/sign/types.ts | 1 + test/examples/profile-updateEmailSubscription.json | 6 ------ test/examples/subscription.json | 3 ++- test/schema.spec.ts | 6 ------ 7 files changed, 8 insertions(+), 20 deletions(-) delete mode 100644 test/examples/profile-updateEmailSubscription.json diff --git a/src/schemas/profile.json b/src/schemas/profile.json index e30c6f15c..aef11d085 100644 --- a/src/schemas/profile.json +++ b/src/schemas/profile.json @@ -51,12 +51,6 @@ "title": "farcaster", "pattern": "^[a-z0-9-]*$", "maxLength": 17 - }, - "emailSubscriptions": { - "type": "array", - "title": "email subscriptions", - "uniqueItems": true, - "items": { "type": "string" } } }, "required": [], diff --git a/src/schemas/subscription.json b/src/schemas/subscription.json index 841d0d39e..cafb82861 100644 --- a/src/schemas/subscription.json +++ b/src/schemas/subscription.json @@ -14,6 +14,10 @@ "type": "string", "title": "value", "maxLength": 256 + }, + "metadata": { + "type": "string", + "title": "metadata" } }, "required": ["type", "value"], diff --git a/src/sign/hashedTypes.json b/src/sign/hashedTypes.json index c7238cb54..fc3c33c64 100644 --- a/src/sign/hashedTypes.json +++ b/src/sign/hashedTypes.json @@ -63,5 +63,5 @@ "4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement", "d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal", "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal", - "3c211382d04e80cbd21f3275e0674387bde366bbb885215e3735151763ca2813": "subscription" + "499ff7269df478dede66b3c0b96a0b90286c479b4013b423ac7cf8628a94e6db": "subscription" } diff --git a/src/sign/types.ts b/src/sign/types.ts index db136a6ea..278161ba9 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -351,6 +351,7 @@ export const subscriptionTypes = { { name: 'from', type: 'address' }, { name: 'type', type: 'string' }, { name: 'value', type: 'string' }, + { name: 'metadata', type: 'string' }, { name: 'timestamp', type: 'uint64' } ] }; diff --git a/test/examples/profile-updateEmailSubscription.json b/test/examples/profile-updateEmailSubscription.json deleted file mode 100644 index b893c4bdd..000000000 --- a/test/examples/profile-updateEmailSubscription.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Vitalik", - "avatar": "ipfs://NnVTdgcFciJUoxqgsNe9Hy2R7rgvEb5jDu5Pa5mmEG3UghbubTf2M78jUXbKLqKM", - "about": "This is my about info", - "emailSubscriptions": ["summary", "newProposal"] -} diff --git a/test/examples/subscription.json b/test/examples/subscription.json index 0fecc2b44..a8f6c3301 100644 --- a/test/examples/subscription.json +++ b/test/examples/subscription.json @@ -1,4 +1,5 @@ { "type": "email", - "value": "my-email@snapshot.org" + "value": "my-email@snapshot.org", + "metadata": "['summary', 'newProposal']" } diff --git a/test/schema.spec.ts b/test/schema.spec.ts index f5f8045ed..90960db45 100644 --- a/test/schema.spec.ts +++ b/test/schema.spec.ts @@ -7,7 +7,6 @@ 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 profileUpdateEmailSubscription from './examples/profile-updateEmailSubscription.json'; import subscription from './examples/subscription.json'; import statement from './examples/statement.json'; import alias from './examples/alias.json'; @@ -26,11 +25,6 @@ describe.each([ { schemaType: 'proposal', schema: schemas.proposal, example: proposal }, { schemaType: 'vote', schema: schemas.vote, example: vote }, { schemaType: 'profile', schema: schemas.profile, example: profile }, - { - schemaType: 'profile', - schema: schemas.profile, - example: profileUpdateEmailSubscription - }, { schemaType: 'subscription', schema: schemas.subscription, From 071172e71c6a32d08d15e455b7498e0fb5dad112 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:23:52 +0900 Subject: [PATCH 05/13] feat: add unsubscription type --- scripts/generateHashWithTypes.ts | 9 ++++----- src/schemas/unsubscription.json | 23 +++++++++++++++++++++++ src/sign/hashedTypes.json | 3 ++- src/sign/types.ts | 9 +++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/schemas/unsubscription.json diff --git a/scripts/generateHashWithTypes.ts b/scripts/generateHashWithTypes.ts index f8c820a4b..51b1f9aa0 100644 --- a/scripts/generateHashWithTypes.ts +++ b/scripts/generateHashWithTypes.ts @@ -1,12 +1,11 @@ const { createHash } = require('crypto'); const types = { - Statement: [ + Unsubscription: [ { 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) { diff --git a/src/schemas/unsubscription.json b/src/schemas/unsubscription.json new file mode 100644 index 000000000..32f0b6985 --- /dev/null +++ b/src/schemas/unsubscription.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/Unsubscription", + "definitions": { + "Unsubscription": { + "title": "Unsubscription", + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": ["email"] + }, + "value": { + "type": "string", + "title": "value", + "maxLength": 256 + } + }, + "required": ["type", "value"], + "additionalProperties": false + } + } +} diff --git a/src/sign/hashedTypes.json b/src/sign/hashedTypes.json index fc3c33c64..a9d90852f 100644 --- a/src/sign/hashedTypes.json +++ b/src/sign/hashedTypes.json @@ -63,5 +63,6 @@ "4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement", "d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal", "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal", - "499ff7269df478dede66b3c0b96a0b90286c479b4013b423ac7cf8628a94e6db": "subscription" + "499ff7269df478dede66b3c0b96a0b90286c479b4013b423ac7cf8628a94e6db": "subscription", + "07332dd26824595cc95dcb5c2f13173c57c23944b328220ce46de163f0e94191": "unsubscription" } diff --git a/src/sign/types.ts b/src/sign/types.ts index 278161ba9..170a54b4b 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -355,3 +355,12 @@ export const subscriptionTypes = { { name: 'timestamp', type: 'uint64' } ] }; + +export const unsubscriptionTypes = { + Unsubscription: [ + { name: 'from', type: 'address' }, + { name: 'type', type: 'string' }, + { name: 'value', type: 'string' }, + { name: 'timestamp', type: 'uint64' } + ] +}; From f8d5630edb4a7db81e881091ec8eee542cd5b479 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:08:31 +0900 Subject: [PATCH 06/13] refactor: rename unsubscription to delete-subscription --- scripts/generateHashWithTypes.ts | 2 +- .../{unsubscription.json => delete-subscription.json} | 6 +++--- src/sign/hashedTypes.json | 2 +- src/sign/types.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/schemas/{unsubscription.json => delete-subscription.json} (78%) diff --git a/scripts/generateHashWithTypes.ts b/scripts/generateHashWithTypes.ts index 51b1f9aa0..94135a9e3 100644 --- a/scripts/generateHashWithTypes.ts +++ b/scripts/generateHashWithTypes.ts @@ -1,7 +1,7 @@ const { createHash } = require('crypto'); const types = { - Unsubscription: [ + DeleteSubscription: [ { name: 'from', type: 'address' }, { name: 'type', type: 'string' }, { name: 'value', type: 'string' }, diff --git a/src/schemas/unsubscription.json b/src/schemas/delete-subscription.json similarity index 78% rename from src/schemas/unsubscription.json rename to src/schemas/delete-subscription.json index 32f0b6985..9a86a7105 100644 --- a/src/schemas/unsubscription.json +++ b/src/schemas/delete-subscription.json @@ -1,9 +1,9 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/Unsubscription", + "$ref": "#/definitions/DeleteSubscription", "definitions": { - "Unsubscription": { - "title": "Unsubscription", + "DeleteSubscription": { + "title": "DeleteSubscription", "type": "object", "properties": { "type": { diff --git a/src/sign/hashedTypes.json b/src/sign/hashedTypes.json index a9d90852f..07ea361ea 100644 --- a/src/sign/hashedTypes.json +++ b/src/sign/hashedTypes.json @@ -64,5 +64,5 @@ "d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal", "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal", "499ff7269df478dede66b3c0b96a0b90286c479b4013b423ac7cf8628a94e6db": "subscription", - "07332dd26824595cc95dcb5c2f13173c57c23944b328220ce46de163f0e94191": "unsubscription" + "da79044f9b55496aed0fa5fdb25aff50b07f59fde4d22e02ab5da9d65da546e1": "delete-subscription" } diff --git a/src/sign/types.ts b/src/sign/types.ts index 170a54b4b..4368ef681 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -356,8 +356,8 @@ export const subscriptionTypes = { ] }; -export const unsubscriptionTypes = { - Unsubscription: [ +export const deleteSubscriptionTypes = { + DeleteSubscription: [ { name: 'from', type: 'address' }, { name: 'type', type: 'string' }, { name: 'value', type: 'string' }, From 24edc54a5c3f0c67ac64aafaaba0a3447972875c Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:08:53 +0900 Subject: [PATCH 07/13] feat: add delete-subscription to signer --- src/sign/index.ts | 12 +++++++++++- src/sign/types.ts | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sign/index.ts b/src/sign/index.ts index af38c293f..4eac66318 100644 --- a/src/sign/index.ts +++ b/src/sign/index.ts @@ -16,6 +16,7 @@ import { Profile, Alias, DeleteSpace, + DeleteSubscription, Statement, spaceTypes, proposalTypes, @@ -36,7 +37,8 @@ import { profileTypes, aliasTypes, deleteSpaceType, - statementTypes + statementTypes, + deleteSubscriptionTypes } from './types'; import constants from '../constants.json'; @@ -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); + } } diff --git a/src/sign/types.ts b/src/sign/types.ts index 4368ef681..697d89619 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -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' }, From 8a694b2fa7e6333c70050ce03b1d68d642ff5c19 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:15:35 +0900 Subject: [PATCH 08/13] revert: revert unrelated changes --- scripts/generateHashWithTypes.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/generateHashWithTypes.ts b/scripts/generateHashWithTypes.ts index 94135a9e3..f8c820a4b 100644 --- a/scripts/generateHashWithTypes.ts +++ b/scripts/generateHashWithTypes.ts @@ -1,11 +1,12 @@ const { createHash } = require('crypto'); const types = { - DeleteSubscription: [ + Statement: [ { name: 'from', type: 'address' }, - { name: 'type', type: 'string' }, - { name: 'value', type: 'string' }, - { name: 'timestamp', type: 'uint64' } + { name: 'timestamp', type: 'uint64' }, + { name: 'space', type: 'string' }, + { name: 'about', type: 'string' }, + { name: 'statement', type: 'string' } ] }; function sha256(str) { From 7a045aa47234b1cffe75c826af25f024b6ff98e9 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:19:43 +0900 Subject: [PATCH 09/13] fix: add missing types --- src/sign/types.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sign/types.ts b/src/sign/types.ts index 697d89619..a1816dcf0 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -126,6 +126,14 @@ export interface DeleteSpace { timestamp?: number; } +export interface subscription { + from?: string; + type: string; + value: string; + metadata: string; + timestamp?: number; +} + export interface DeleteSubscription { from?: string; type: string; From 6cac76d0b753b9b820142f4d4bb7d048a48b57af Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:23:56 +0900 Subject: [PATCH 10/13] feat: support subscription in sign --- src/sign/index.ts | 10 ++++++++++ src/sign/types.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sign/index.ts b/src/sign/index.ts index 4eac66318..0683b77ae 100644 --- a/src/sign/index.ts +++ b/src/sign/index.ts @@ -16,6 +16,7 @@ import { Profile, Alias, DeleteSpace, + Subscription, DeleteSubscription, Statement, spaceTypes, @@ -38,6 +39,7 @@ import { aliasTypes, deleteSpaceType, statementTypes, + subscriptionTypes, deleteSubscriptionTypes } from './types'; import constants from '../constants.json'; @@ -237,6 +239,14 @@ export default class Client { return await this.sign(web3, address, message, deleteSpaceType); } + async subscription( + web3: Web3Provider | Wallet, + address: string, + message: Subscription + ) { + return await this.sign(web3, address, message, subscriptionTypes); + } + async deleteSubscription( web3: Web3Provider | Wallet, address: string, diff --git a/src/sign/types.ts b/src/sign/types.ts index a1816dcf0..9b19d77d1 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -126,7 +126,7 @@ export interface DeleteSpace { timestamp?: number; } -export interface subscription { +export interface Subscription { from?: string; type: string; value: string; From 8fdef578e6f4dd4c7abd09183f3117c0b99f2c81 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:48:08 +0700 Subject: [PATCH 11/13] fix: add email validation to subscription value type --- src/schemas/subscription.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/schemas/subscription.json b/src/schemas/subscription.json index cafb82861..02217deb7 100644 --- a/src/schemas/subscription.json +++ b/src/schemas/subscription.json @@ -12,6 +12,7 @@ }, "value": { "type": "string", + "format": "email", "title": "value", "maxLength": 256 }, From 086ad9e3eca63d317de4601c713525559d7ebe20 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:42:37 +0800 Subject: [PATCH 12/13] refactor: rename subscription to email-subscription --- src/schemas/delete-subscription.json | 23 ----------------------- src/schemas/email-subscription.json | 28 ++++++++++++++++++++++++++++ src/schemas/index.ts | 4 ++-- src/schemas/subscription.json | 28 ---------------------------- src/sign/hashedTypes.json | 4 ++-- src/sign/index.ts | 25 +++++++++++++++---------- src/sign/types.ts | 26 ++++++++++---------------- 7 files changed, 57 insertions(+), 81 deletions(-) delete mode 100644 src/schemas/delete-subscription.json create mode 100644 src/schemas/email-subscription.json delete mode 100644 src/schemas/subscription.json diff --git a/src/schemas/delete-subscription.json b/src/schemas/delete-subscription.json deleted file mode 100644 index 9a86a7105..000000000 --- a/src/schemas/delete-subscription.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "$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 - } - } -} 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 f5e603210..f8f795f7f 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -3,7 +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 emailSubscription from './email-subscription.json'; import statement from './statement.json'; import zodiac from './zodiac.json'; import alias from './alias.json'; @@ -14,7 +14,7 @@ export default { updateProposal: updateProposal.definitions.UpdateProposal, vote: vote.definitions.Vote, profile: profile.definitions.Profile, - subscription: subscription.definitions.Subscription, + emailSubscription: emailSubscription.definitions.EmailSubscription, statement: statement.definitions.Statement, zodiac: zodiac.definitions.Zodiac, alias: alias.definitions.Alias diff --git a/src/schemas/subscription.json b/src/schemas/subscription.json deleted file mode 100644 index 02217deb7..000000000 --- a/src/schemas/subscription.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "$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", - "format": "email", - "title": "value", - "maxLength": 256 - }, - "metadata": { - "type": "string", - "title": "metadata" - } - }, - "required": ["type", "value"], - "additionalProperties": false - } - } -} diff --git a/src/sign/hashedTypes.json b/src/sign/hashedTypes.json index 07ea361ea..c1b41244c 100644 --- a/src/sign/hashedTypes.json +++ b/src/sign/hashedTypes.json @@ -63,6 +63,6 @@ "4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement", "d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal", "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal", - "499ff7269df478dede66b3c0b96a0b90286c479b4013b423ac7cf8628a94e6db": "subscription", - "da79044f9b55496aed0fa5fdb25aff50b07f59fde4d22e02ab5da9d65da546e1": "delete-subscription" + "e3bd9bf9665e4dd5be252408e6d7c9e9a4572897153171a31e39e11641162003": "email-subscription", + "339bef62ba146350b9dfdcf04203c2b3c7f19effd1d8804954a8189645112394": "delete-email-subscription" } diff --git a/src/sign/index.ts b/src/sign/index.ts index 0683b77ae..2aaa8806f 100644 --- a/src/sign/index.ts +++ b/src/sign/index.ts @@ -16,8 +16,8 @@ import { Profile, Alias, DeleteSpace, - Subscription, - DeleteSubscription, + EmailSubscription, + DeleteEmailSubscription, Statement, spaceTypes, proposalTypes, @@ -39,8 +39,8 @@ import { aliasTypes, deleteSpaceType, statementTypes, - subscriptionTypes, - deleteSubscriptionTypes + emailSubscriptionTypes, + deleteEmailSubscriptionTypes } from './types'; import constants from '../constants.json'; @@ -239,19 +239,24 @@ export default class Client { return await this.sign(web3, address, message, deleteSpaceType); } - async subscription( + async emailSubscription( web3: Web3Provider | Wallet, address: string, - message: Subscription + message: EmailSubscription ) { - return await this.sign(web3, address, message, subscriptionTypes); + return await this.sign(web3, address, message, emailSubscriptionTypes); } - async deleteSubscription( + async deleteEmailSubscription( web3: Web3Provider | Wallet, address: string, - message: DeleteSubscription + message: DeleteEmailSubscription ) { - return await this.sign(web3, address, message, deleteSubscriptionTypes); + return await this.sign( + web3, + address, + message, + deleteEmailSubscriptionTypes + ); } } diff --git a/src/sign/types.ts b/src/sign/types.ts index 9b19d77d1..7f0732778 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -126,18 +126,15 @@ export interface DeleteSpace { timestamp?: number; } -export interface Subscription { +export interface EmailSubscription { from?: string; - type: string; - value: string; - metadata: string; + email: string; + subscriptions: string[]; timestamp?: number; } -export interface DeleteSubscription { +export interface DeleteEmailSubscription { from?: string; - type: string; - value: string; timestamp?: number; } @@ -361,21 +358,18 @@ export const deleteSpaceType = { ] }; -export const subscriptionTypes = { - Subscription: [ +export const emailSubscriptionTypes = { + EmailSubscription: [ { name: 'from', type: 'address' }, - { name: 'type', type: 'string' }, - { name: 'value', type: 'string' }, - { name: 'metadata', type: 'string' }, + { name: 'email', type: 'string' }, + { name: 'subscriptions', type: 'string[]' }, { name: 'timestamp', type: 'uint64' } ] }; -export const deleteSubscriptionTypes = { - DeleteSubscription: [ +export const deleteEmailSubscriptionTypes = { + DeleteEmailSubscription: [ { name: 'from', type: 'address' }, - { name: 'type', type: 'string' }, - { name: 'value', type: 'string' }, { name: 'timestamp', type: 'uint64' } ] }; From 91879d9b7cb1ce930ebb8a4eec9125e0291da641 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Sat, 23 Nov 2024 21:30:42 +0800 Subject: [PATCH 13/13] fix: properties can be optional --- src/sign/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sign/types.ts b/src/sign/types.ts index 7f0732778..1d3d6ea30 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -128,8 +128,8 @@ export interface DeleteSpace { export interface EmailSubscription { from?: string; - email: string; - subscriptions: string[]; + email?: string; + subscriptions?: string[]; timestamp?: number; }