archethic-foundation / archethic-foundation/messaging_notification_backend
Handle chat creation and invitations
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
# Is your feature request related to a problem?
A user can subscribe to notifications related to a smart contract address.
He will then receive a PUSH notif and/or a Websocket notification every time a user emits a transaction and asks backend to notify.
Although this works well when you already know the addresses of the discussion smart contracts, it does not cover invitations to new conversations.
We need add a subscription to get notifications when we are invited to a new Chat.
# Describe the solution you'd like
## New chat publication
### Request
After creating a new chat, the creator must send the following request.
```ts
POST
/chatCreated
body: {
smartContractGenesisAddress: string // Chat smart contract address
signedPayload: string // privKey.sign(smartContractGenesisAddress)
}
```
### Backend validation :
Before sending notifications, the backend must ensure the request is legitimate :
consider `pubKey = Tx.read(smartContractGenesisAddress).previousPublicKey)`
- `pubKey.verify(signedPayload, smartContractGenesisAddress)`
- `Tx.read(smartContractGenesisAddress)` created by `pubKey`
- `Tx.read(smartContractGenesisAddress)` created less than 1 min ago
- No notification sent yet for `smartContractGenesisAddress` creation
### Notifications send
Backend will then read the smart contract to extract the chat members `pubKey`s.
Notification will be sent to all the members.
## Message send
This is a rework of the `transactionSent` endpoint.
It mainly adds a validation to ensure the transaction is a message of the chat smart contract.
### Request
Rename the endpoint `transactionSent` to `messageSent`.
```ts
POST
/messageSent
body: {
pubKey: string // Message creator pubKey
messageAddress: string // Message Tx address
smartContractGenesisAddress: string // Chat smart contract address
signedPayload: string // privKey.sign(messageAddress)
}
```
### Backend validation :
Before sending notifications, the backend must ensure the request is legitimate :
consider `pubKey = Tx.read(smartContractGenesisAddress).previousPublicKey)`
- `Tx.read(messageAddress)` is a `call` `input` of `Tx.read(smartContractGenesisAddress)` // Ensures the message is related to this chat
- `pubKey.verify(signedPayload, messageAddress)`
- `Tx.read(messageAddress)` created by `pubKey`
- `Tx.read(messageAddress)` created less than 1 min ago
- No notification sent yet for `messageAddress` creation
### Notifications send
Backend will then check :
- all the clients subscribed to `smartContractGenesisAddress`
- all the members of the chat smart contract
Backend will notify members of both sets.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the existing transactionSent endpoint and trace its notification flow. Define the new chatCreated and messageSent entry points, then verify the stated signature, transaction-age, chat-membership, and duplicate-notification validations. Done means newly created chats notify their members, messages notify subscribers and chat members, and transactionSent is replaced by messageSent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend, security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100