Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 26 additions & 1 deletion src/sign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
Unfollow,
Subscribe,
Unsubscribe,
Webhook,
RemoveWebhook,
Profile,
Alias,
spaceTypes,
Expand All @@ -27,6 +29,8 @@ import {
subscribeTypes,
unfollowTypes,
unsubscribeTypes,
webhookTypes,
removeWebhookTypes,
profileTypes,
aliasTypes,
deleteSpaceType,
Expand Down Expand Up @@ -64,7 +68,12 @@ export default class Client {
}

async send(envelop) {
const url = `${this.address}/api/msg`;
const webhookAction = Object.keys(envelop.data.types).filter((key) =>
['Webhook', 'RemoveWebhook'].includes(key)
).length;
const url = webhookAction
? `${this.address}/api/subscribers`
: `${this.address}/api/msg`;
const init = {
method: 'POST',
headers: {
Expand Down Expand Up @@ -159,6 +168,22 @@ export default class Client {
return await this.sign(web3, address, message, unsubscribeTypes);
}

async webhook(
web3: Web3Provider | Wallet,
address: string,
message: Webhook
) {
return await this.sign(web3, address, message, webhookTypes);
}

async removeWebhook(
web3: Web3Provider | Wallet,
address: string,
message: RemoveWebhook
) {
return await this.sign(web3, address, message, removeWebhookTypes);
}

async profile(
web3: Web3Provider | Wallet,
address: string,
Expand Down
32 changes: 32 additions & 0 deletions src/sign/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ export interface Unsubscribe {
timestamp?: number;
}

export interface Webhook {
from?: string;
space: string;
url: string;
active: number;
timestamp?: number;
}

export interface RemoveWebhook {
from?: string;
id: number;
active: number;
timestamp?: number;
}

export interface Profile {
from?: string;
timestamp?: number;
Expand Down Expand Up @@ -242,6 +257,23 @@ export const unsubscribeTypes = {
]
};

export const webhookTypes = {
Webhook: [
{ name: 'from', type: 'address' },
{ name: 'space', type: 'string' },
{ name: 'url', type: 'string' },
{ name: 'active', type: 'uint8' }
]
};

export const removeWebhookTypes = {
RemoveWebhook: [
{ name: 'from', type: 'address' },
{ name: 'id', type: 'uint64' },
{ name: 'active', type: 'uint8' }
]
};

export const profileTypes = {
Profile: [
{ name: 'from', type: 'address' },
Expand Down