From df8deaae5d1c8a7b9dc350b502870cc9be5fac02 Mon Sep 17 00:00:00 2001 From: akp111 Date: Fri, 29 Sep 2023 18:30:02 +0530 Subject: [PATCH 1/3] fix: added counter to update group --- .../src/lib/pushNotification/channel.ts | 11 ++-- .../pushNotification/pushNotificationBase.ts | 24 ++++++- .../lib/pushNotification/onchain.test.ts | 66 ++++++++++++------- 3 files changed, 71 insertions(+), 30 deletions(-) diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index b21fa4e3a..76a6119c0 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -250,11 +250,14 @@ export class Channel extends PushNotificationBaseClass { config.TOKEN_VIEM_NETWORK_MAP[this.env!] ); const balance = await this.fetchBalance(pushTokenContract, this.account!); + // get counter + const counter = await this.fetchUpdateCounter(this.coreContract, this.account!); const fees = ethers.utils.parseUnits( config.MIN_TOKEN_BALANCE[this.env!].toString(), 18 ); - if (fees.gt(balance)) { + const totalFees = fees.mul(counter) + if (totalFees.gte(balance)) { throw new Error('Insufficient PUSH balance'); } // if alias is passed, check for the caip @@ -285,12 +288,12 @@ export class Channel extends PushNotificationBaseClass { config.CORE_CONFIG[this.env!].EPNS_CORE_CONTRACT ); // if allowance is not greater than the fees, dont call approval again - if (!allowanceAmount.gte(fees)) { + if (!allowanceAmount.gte(totalFees)) { progressHook?.(PROGRESSHOOK['PUSH-UPDATE-02'] as ProgressHookType); const approvalRes = await this.approveToken( pushTokenContract, config.CORE_CONFIG[this.env!].EPNS_CORE_CONTRACT, - fees + totalFees ); if (!approvalRes) { throw new Error('Something went wrong while approving the token'); @@ -305,7 +308,7 @@ export class Channel extends PushNotificationBaseClass { this.coreContract, this.account!, identityBytes, - fees + totalFees ); progressHook?.(PROGRESSHOOK['PUSH-UPDATE-04'] as ProgressHookType); return { transactionHash: updateChannelRes }; diff --git a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts index c081b2f0e..1d9aab9ab 100644 --- a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts +++ b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts @@ -328,6 +328,26 @@ export class PushNotificationBaseClass { } } + protected async fetchUpdateCounter(contract: any, userAddress: string) { + let count: BigNumber; + try { + if ('_signTypedData' in this.signer!) { + count = await contract!['channelUpdateCounter'](userAddress); + } else if ('signTypedData' in this.signer!) { + const countInBigInt = await contract.read.channelUpdateCounter({ + args: [userAddress], + }); + count = ethers.BigNumber.from(countInBigInt); + } else { + throw new Error('Unsupported signer'); + } + // add one and return the count + return count.add(ethers.BigNumber.from(1)); + } catch (error) { + throw new Error(JSON.stringify(error)); + } + } + protected async approveToken( contract: any, spenderAddress: string, @@ -650,7 +670,9 @@ export class PushNotificationBaseClass { ele.data.upper; notificationSettingDescription = - notificationSettingDescription + SETTING_SEPARATOR + ele.description; + notificationSettingDescription + + SETTING_SEPARATOR + + ele.description; } } } diff --git a/packages/restapi/tests/lib/pushNotification/onchain.test.ts b/packages/restapi/tests/lib/pushNotification/onchain.test.ts index e5412da59..c8e91058c 100644 --- a/packages/restapi/tests/lib/pushNotification/onchain.test.ts +++ b/packages/restapi/tests/lib/pushNotification/onchain.test.ts @@ -3,8 +3,8 @@ // dotenv.config({ path: path.resolve(__dirname, '../../../.env') }); // import { expect } from 'chai'; // import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; - -// import { PushNotification } from '../../../../src/lib/pushNotification/PushNotification'; +// import { PushNotificationBaseClass } from '../../../src/lib/pushNotification/pushNotificationBase'; +// import * as config from "../../../src/lib/config" // import { // createWalletClient, // http, @@ -15,6 +15,15 @@ // import { goerli, polygonMumbai } from 'viem/chains'; // import { BigNumber, ethers } from 'ethers'; +// enum ENV { +// PROD = 'prod', +// STAGING = 'staging', +// DEV = 'dev', +// /** +// * **This is for local development only** +// */ +// LOCAL = 'local', +// } // describe.only('test', () => { // const signer = createWalletClient({ // account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`), @@ -37,32 +46,35 @@ // `0x${process.env['WALLET_PRIVATE_KEY']}`, // provider // ); - -// it.only('testing with viem', async () => { -// const userViem = await PushNotification.initialize(signer); +// it('testing with viem', async () => { +// const account2 = await signer2.getAddress(); +// const viemUser = new PushNotificationBaseClass(signer, ENV.STAGING, account2) +// const contract = viemUser.createContractInstance("0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C", config.ABIS.CORE, goerli) +// const res = await viemUser.fetchUpdateCounter(contract, account2); +// console.log(res) // const viemContract = await userViem.createContractInstance( // '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33', // abi, // goerli // ); -// // const balance = await userViem.fetchBalance( -// // viemContract, -// // '0xD8634C39BBFd4033c0d3289C4515275102423681' -// // ); -// // console.log(balance); -// // const allowance = await userViem.fetchAllownace( -// // viemContract, -// // '0xD8634C39BBFd4033c0d3289C4515275102423681', -// // '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C' -// // ); -// // console.log(allowance); -// // const approveAmount = ethers.BigNumber.from(10000); -// // const approveRes = await userViem.approveToken( -// // viemContract, -// // '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C', -// // approveAmount -// // ); -// // console.log(approveRes); +// const balance = await userViem.fetchBalance( +// viemContract, +// '0xD8634C39BBFd4033c0d3289C4515275102423681' +// ); +// console.log(balance); +// const allowance = await userViem.fetchAllownace( +// viemContract, +// '0xD8634C39BBFd4033c0d3289C4515275102423681', +// '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C' +// ); +// console.log(allowance); +// const approveAmount = ethers.BigNumber.from(10000); +// const approveRes = await userViem.approveToken( +// viemContract, +// '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C', +// approveAmount +// ); +// console.log(approveRes); // const addDelegate = await userViem.delegate.add( // 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681' @@ -70,8 +82,12 @@ // console.log(addDelegate); // }); -// it('test with ethers', async () => { -// const userEthers = await PushNotification.initialize(signer2); +// it.only('test with ethers', async () => { +// const account2 = await signer2.getAddress(); +// const userEthers = new PushNotificationBaseClass(signer2, ENV.STAGING, account2,); +// const contract = userEthers.createContractInstance("0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C", config.ABIS.CORE, goerli) +// const res = await userEthers.fetchUpdateCounter(contract, account2); +// console.log(res) // const ethersContract = await userEthers.createContractInstance( // '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33', // abi, From d58c36ccb7efe8ae957f7d0df7962b2bea75f2be Mon Sep 17 00:00:00 2001 From: akp111 Date: Fri, 29 Sep 2023 19:05:09 +0530 Subject: [PATCH 2/3] fix: added counter logic, moved delegate and alias function to channel class --- .../src/lib/pushNotification/channel.ts | 10 ++++++ packages/restapi/src/lib/pushapi/PushAPI.ts | 7 +--- .../tests/lib/pushNotification/alias.test.ts | 2 +- .../lib/pushNotification/delegate.test.ts | 32 +++++++++---------- .../lib/pushNotification/notification.test.ts | 2 +- .../tests/lib/pushstream/initialize.test.ts | 2 +- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index 76a6119c0..da57c04bb 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -23,10 +23,16 @@ import PROGRESSHOOK from '../progressHook'; import { ethers } from 'ethers'; import { PushNotificationBaseClass } from './pushNotificationBase'; +import { Delegate } from './delegate'; +import { Alias } from './alias'; export class Channel extends PushNotificationBaseClass { + public delegate!: Delegate + public alias!: Alias constructor(signer?: SignerType, env?: ENV, account?: string) { super(signer, env, account); + this.delegate = new Delegate(signer, env, account) + this.alias = new Alias(env!); } /** @@ -346,6 +352,10 @@ export class Channel extends PushNotificationBaseClass { if (!ethers.utils.isAddress(channelToBeVerified)) { throw new Error('Invalid channel address'); } + const channelDetails = await this.info(this.account); + if(channelDetails?.verified_status == 0){ + throw new Error("Only verified channel can verify other channel") + } // if valid, continue with it const res = await this.verifyChannel( this.coreContract, diff --git a/packages/restapi/src/lib/pushapi/PushAPI.ts b/packages/restapi/src/lib/pushapi/PushAPI.ts index c785dead4..7a5ad86d8 100644 --- a/packages/restapi/src/lib/pushapi/PushAPI.ts +++ b/packages/restapi/src/lib/pushapi/PushAPI.ts @@ -10,9 +10,8 @@ import { Encryption } from './encryption'; import { User } from './user'; import { PushStream } from '../pushstream/PushStream'; import { Channel } from '../pushNotification/channel'; -import { Alias } from '../pushNotification/alias'; -import { Delegate } from '../pushNotification/delegate'; import { Notification } from '../pushNotification/notification'; + export class PushAPI { private signer: SignerType; private account: string; @@ -28,8 +27,6 @@ export class PushAPI { public stream!: PushStream; // Notification public channel!: Channel; - public alias!: Alias; - public delegate!: Delegate; public notification!: Notification; private constructor( @@ -48,8 +45,6 @@ export class PushAPI { this.progressHook = progressHook; // Instantiate the notification classes this.channel = new Channel(this.signer, this.env, this.account); - this.alias = new Alias(this.env); - this.delegate = new Delegate(this.signer, this.env, this.account); this.notification = new Notification(this.signer, this.env, this.account); // Initialize the instances of the four classes this.chat = new Chat( diff --git a/packages/restapi/tests/lib/pushNotification/alias.test.ts b/packages/restapi/tests/lib/pushNotification/alias.test.ts index 1bd9c5cfb..ae62cf864 100644 --- a/packages/restapi/tests/lib/pushNotification/alias.test.ts +++ b/packages/restapi/tests/lib/pushNotification/alias.test.ts @@ -42,7 +42,7 @@ describe('PushAPI.alias functionality', () => { describe('alias :: info', () => { // TODO: remove skip after signer becomes optional it('Should return response', async () => { - const res = await userBob.alias.info({ + const res = await userBob.channel.alias.info({ alias: '0x93A829d16DE51745Db0530A0F8E8A9B8CA5370E5', aliasChain: 'POLYGON', }); diff --git a/packages/restapi/tests/lib/pushNotification/delegate.test.ts b/packages/restapi/tests/lib/pushNotification/delegate.test.ts index 9f99794df..71a723cd2 100644 --- a/packages/restapi/tests/lib/pushNotification/delegate.test.ts +++ b/packages/restapi/tests/lib/pushNotification/delegate.test.ts @@ -41,7 +41,7 @@ describe('PushAPI.delegate functionality', () => { // TODO: remove skip after signer becomes optional it.skip('Without signer and account :: should throw error', async () => { await expect(() => - userBob.delegate.add( + userBob.channel.delegate.add( 'eip155:5:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ) ).to.Throw; @@ -49,14 +49,14 @@ describe('PushAPI.delegate functionality', () => { it('With signer and without provider :: should throw error', async () => { await expect(() => - userAlice.delegate.add( + userAlice.channel.delegate.add( 'eip155:5:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ) ).to.Throw; }); it('With signer and provider :: should add delegate', async () => { - const res = await userKate.delegate.add( + const res = await userKate.channel.delegate.add( 'eip155:5:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ); // console.log(res); @@ -65,7 +65,7 @@ describe('PushAPI.delegate functionality', () => { it('With signer and provider :: should throw error as delegate caip and provider doesnt match', async () => { await expect(() => - userKate.delegate.add( + userKate.channel.delegate.add( 'eip155:80001:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ) ).to.Throw; @@ -82,7 +82,7 @@ describe('PushAPI.delegate functionality', () => { provider ); userKate = await PushAPI.initialize(signer2); - const res = await userKate.delegate.add( + const res = await userKate.channel.delegate.add( 'eip155:80001:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ); // console.log(res); @@ -94,7 +94,7 @@ describe('PushAPI.delegate functionality', () => { // TODO: remove skip after signer becomes optional it.skip('Without signer and account :: should throw error', async () => { await expect(() => - userBob.delegate.remove( + userBob.channel.delegate.remove( 'eip155:5:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ) ).to.Throw; @@ -102,14 +102,14 @@ describe('PushAPI.delegate functionality', () => { it('With signer and without provider :: should throw error', async () => { await expect(() => - userAlice.delegate.remove( + userAlice.channel.delegate.remove( 'eip155:5:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ) ).to.Throw; }); it('With signer and provider :: should add delegate', async () => { - const res = await userKate.delegate.remove( + const res = await userKate.channel.delegate.remove( 'eip155:5:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ); console.log(res); @@ -118,13 +118,13 @@ describe('PushAPI.delegate functionality', () => { it('With signer and provider :: should throw error as delegate caip and provider doesnt match', async () => { await expect(() => - userKate.delegate.remove( + userKate.channel.delegate.remove( 'eip155:80001:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ) ).to.Throw; }); - it('With viem signer: Should add delegate', async () => { + it.only('With viem signer: Should remove delegate', async () => { // create polygon mumbai provider const provider = new ethers.providers.JsonRpcProvider( 'https://rpc-mumbai.maticvigil.com' @@ -135,7 +135,7 @@ describe('PushAPI.delegate functionality', () => { provider ); userKate = await PushAPI.initialize(signer2); - const res = await userKate.delegate.remove( + const res = await userKate.channel.delegate.remove( 'eip155:80001:0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924' ); // console.log(res); @@ -145,18 +145,18 @@ describe('PushAPI.delegate functionality', () => { describe('delegate :: get', () => { it.skip('Without signer and account : Should throw error', async () => { - await expect(() => userBob.delegate.get()).to.Throw; + await expect(() => userBob.channel.delegate.get()).to.Throw; }); it('Without signer : Should throw error for non-caip format', async () => { await expect(() => - userBob.delegate.get({ + userBob.channel.delegate.get({ channel: '0x74415Bc4C4Bf4Baecc2DD372426F0a1D016Fa924', }) ).to.Throw; }); it('Without signer : Should fetch delegates', async () => { - const res = await userBob.delegate.get({ + const res = await userBob.channel.delegate.get({ channel: 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681', }); console.log(res); @@ -164,7 +164,7 @@ describe('PushAPI.delegate functionality', () => { }); it('Without signer : Should fetch delegates for alias', async () => { - const res = await userBob.delegate.get({ + const res = await userBob.channel.delegate.get({ channel: 'eip155:80001:0xD8634C39BBFd4033c0d3289C4515275102423681', }); // console.log(res) @@ -172,7 +172,7 @@ describe('PushAPI.delegate functionality', () => { }); it('With signer : Should fetch delegates for channel', async () => { - const res = await userKate.delegate.get(); + const res = await userKate.channel.delegate.get(); // console.log(res); expect(res).not.null; }); diff --git a/packages/restapi/tests/lib/pushNotification/notification.test.ts b/packages/restapi/tests/lib/pushNotification/notification.test.ts index d9a6ec2c3..31442a287 100644 --- a/packages/restapi/tests/lib/pushNotification/notification.test.ts +++ b/packages/restapi/tests/lib/pushNotification/notification.test.ts @@ -52,7 +52,7 @@ describe('PushAPI.notification functionality', () => { userViem = await PushAPI.initialize(viemSigner); }); - describe('', () => { + describe('PushAPI.notification functionality', () => { it('Should return feeds with signer object', async () => { const response = await userAlice.notification.list('SPAM'); expect(response).not.null; diff --git a/packages/restapi/tests/lib/pushstream/initialize.test.ts b/packages/restapi/tests/lib/pushstream/initialize.test.ts index 260bdd667..9ae1527f6 100644 --- a/packages/restapi/tests/lib/pushstream/initialize.test.ts +++ b/packages/restapi/tests/lib/pushstream/initialize.test.ts @@ -12,7 +12,7 @@ import { STREAM } from '../../../src/lib/pushstream/pushStreamTypes'; import * as util from 'util'; import { ConditionType } from '../../../src/lib'; -describe.only('PushStream.initialize functionality', () => { +describe('PushStream.initialize functionality', () => { it('Should initialize new stream and listen to events', async () => { const MESSAGE = 'Hey There!!!'; From e1ddd73a33ea92916acb94042a4f2b102e1c2cd7 Mon Sep 17 00:00:00 2001 From: akp111 Date: Fri, 29 Sep 2023 19:21:14 +0530 Subject: [PATCH 3/3] fix: added readme for notification --- packages/restapi/README.md | 332 +++++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) diff --git a/packages/restapi/README.md b/packages/restapi/README.md index 281487e32..1aa9dffde 100644 --- a/packages/restapi/README.md +++ b/packages/restapi/README.md @@ -6461,3 +6461,335 @@ const aliceUpdateEncryption = await userAlice.encryption.update( --- + + +### **Fetch Inbox /Spam notifications** + +```tsx +// lists feeds +const aliceInfo = await userAlice.notification.list(); + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| spam | INBOX or SPAM | INBOX | A string representing the type of feed to retrieve. | +| options* | object | - | An object containing additional options for filtering and pagination. | +| options.account* | string | - | Account in full CAIP | +| options.channels* | [string] | - | An array of channels to filter feeds by. | +| options.page* | number | - | A number representing the page of results to retrieve. | +| options.limit* | number | - | A number representing the maximum number of feeds to retrieve per page. | +| options.raw* | boolean | - | A boolean indicating whether to retrieve raw feed data. | + +\* - Optional + +--- + +### **Fetch user subscriptions** + +```tsx +// fetches list of channels to which the user is subscribed +const subscriptions = await userAlice.notification.subscriptions(); + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| options* | object | - | An object containing additional options for subscriptions. | +| options.account* | string | - | Account in CAIP . | +| options.page* | number | - | page of results to retrieve. | +| options.limit* | number | - | represents the maximum number of subscriptions to retrieve per page. | + +\* - Optional + +--- + +### **Subscribe to a channel** + +```tsx +// subscribes to a channel +const subscribeStatus = await userAlice.notification.subscribe(channelInCAIP) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| channel | string | - | Channel/Alias address in CAIP format | +| options* | SubscribeUnsubscribeOptions | - | Optional configuration | +| options.onSuccess* | () => void | - | A callback function to execute when the subscription is successful. | +| options.onError* | (err: Error) => void | - | A callback function to execute when an error occurs during subscription. | + +\* - Optional + +--- + +### **Unsubscribe to a channel** + +```tsx +// unsubscribes to the channel +const unsubscribeStatus = await userAlice.notification.unsubscribe(channelInCAIP) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| channel | string | - | Channel/Alias address in CAIP format | +| options* | SubscribeUnsubscribeOptions | - | Optional configuration | +| options.onSuccess* | () => void | - | A callback function to execute when the unsubscription is successful. | +| options.onError* | (err: Error) => void | - | A callback function to execute when an error occurs during unsubscription. | + +\* - Optional + +--- + +### **Channel information** + +```tsx +// fetches information about the channel +const channelInfo = await userAlice.channel.info(pushChannelInCAIP) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| channel* | string | - | Channel address in CAIP format | + +\* - Optional + +--- + +### **Search Channels** + +```tsx +// returns channel matching the query +const searchResult = await userAlice.channel.search("push") + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| query | string | - | The search query to find channels. | +| options* | ChannelSearchOptions | - | Configuration options for the search. | +| options.page* | number | - | The page of results to retrieve. Default is set to 1 | +| options.limit* | number | - | The maximum number of channels to retrieve per page. Default is set to 10 | + +\* - Optional + +### **Get a channel's subscribers** + +```tsx +// fetches subscribers of a channel +const subscribersResult = await userAlice.channel.subscribers() + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| options* | ChannelInfoOptions | - | Configuration options for retrieving subscribers. | +| options.channel* | string | - | Channel address in CAIP | + +\* - Optional + +### **Send a notification** + +```tsx +// sends a notification +const sendNotifRes = await userAlice.channel.send(['*'], {notification: {title: 'test',body: 'test',},}) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| recipients | string[] | - | An array of recipient addresses. Possible values are: Broadcast -> [*], Targeted -> [0xA], Subset -> [0xA, 0xB] | +| options | NotificationOptions | - | Configuration options for sending notifications. | +| options.notification | INotification | - | An object containing the notification's title and body. (Mandatory) | +| options.payload* | IPayload | - | An object containing additional payload information for the notification. | +| options.payload.title* | string | - | The title for the notification. If not provided, it is taken from notification.title. | +| options.payload.body* | string | - | The body of the notification. If not provided, it is taken from notification.body. | +| options.payload.cta* | string | - | Call to action for the notification. | +| options.payload.embed | string | - | Media information like image/video links | +| options.payload.meta* | { domain?: string, type: string, data: string } | - | Metadata for the notification, including domain, type, and data. | +| options.config* | IConfig | - | An object containing configuration options for the notification. | +| options.config.expiry* | number | - | Expiry time for the notification in seconds | +| options.config.silent* | boolean | - | Indicates whether the notification is silent. | +| options.config.hidden* | boolean | - | Indicates whether the notification is hidden. | +| options.advanced* | IAdvance | - | An object containing advanced options for the notification. | +| options.advanced.graph* | { id: string, counter: number } | - | Advanced options related to the graph based notification. | +| options.advanced.ipfs* | string | - | IPFS information for the notification. | +| options.advanced.minimal* | string | - | Minimal Payload type notification. | +| options.advanced.chatid* | string | - | For chat based notification. | +| options.advanced.pgpPrivateKey* | string | - | PGP private key for chat based notification. | +| options.channel* | string | - | Channel address in CAIP. Mostly used when a delegator sends a notification on behalf of the channel | + +\* - Optional + +--- + +### **Create a channel** + +```tsx +// creates a channel +const createChannelRes = await userAlice.channel.create({name: channelName, description: channelDescription, url: channelURL, icon: base64FormatImage, alias?: aliasAddressInCAIP}) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| options | CreateChannelOptions | - | Configuration options for creating a channel. | +| options.name | string | - | The name of the channel. | +| options.description | string | - | A description of the channel. | +| options.icon | string (base64 encoded) | - | The channel's icon in base64 encoded string format. | +| options.url | string | - | The URL associated with the channel. | +| options.alias* | string | - | alias address in CAIP | +| options.progresshook* | () => void | - | (Optional) A callback function to execute when the channel creation progresses. | + +**Note**: Support for contract interaction via `viem` is coming soon +\* - Optional + +--- + +### **Update a channel's information** + +```tsx +// updates channel info +const updateChannelRes = await userAlice.channel.update({name: newChannelName, description: newChannelDescription, url: newChannelURL, icon: newBase64FormatImage, alias?: newAliasAddressInCAIP}) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| options | - | - | Configuration options for creating a channel. | +| options.name | string | - | New name of the channel. | +| options.description | string | - | New description of the channel. | +| options.icon | string (base64 encoded) | - | The channel's new icon in base64 encoded string format. | +| options.url | string | - | New URL associated with the channel. | +| options.alias* | string | - | New alias address in CAIP | +| options.progresshook* | () => void | - | A callback function to execute when the channel updation progresses. | +| Note: Support for contract interaction via viem is coming soon | | | | + +\* - Optional + +--- + +### **Verify a channel** + +```tsx +const verifyChannelRes = await userAlice.channel.verify(channelToBeVerified) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| channelToBeVerified | string | - | Channel address in CAIP to be verified | + +--- + +### **Create channel Setting** + +```tsx +// creates channel settings +const createChannelSettingRes = userAlice.channel.settings([{ type: 0, default: 1, description: 'marketing' }, {type: 2, default: 10, description: 'loan liquidation threshold', data: {upper: 100, lower: 5}}]) + +``` + +**Parameters:** + +| Property | Type | Default | Description | +| --- | --- | --- | --- | +| type | number | - | The type of notification setting. 1 for boolean type and 2 for slider type | +| default | number | - | The default value for the setting. | +| description | string | - | A description of the setting. | +| data.upper* | number | - | Valid for slider type only. The upper limit for the setting. | +| data.lower* | number | - | Valid for slider type only. The lower limit for the setting. | +| Note: Support for contract interaction via viem is coming soon | | | | +| \* - Optional | | | | + +--- + +### **Get delegators information** + +```tsx +// fetch delegate information +const delegatorsInfo = userAlice.channel.delegate.get() + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| options* | ChannelInfoOptions | - | Configuration options for retrieving delegator information. | +| options.channel* | string | - | channel address in CAIP | +| \* - Optional | | | | + +--- + +### **Add delegator to a channel/alias** + +```tsx +// adds a delegate +const addDelegatorRes = userAlice.channel.delegate.add(delegatorAddressInCAIP) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| delegate | string | - | delegator address in CAIP | +| Note: Support for contract interaction via viem is coming soon | | | | + +--- + +### **Remove delegator from a channel/alias** + +```tsx +// removes a delegate +const removeDelegatorRes = userAlice.channel.delegate.remove(delegatorAddressInCAIP) + +``` + +**Parameters:** + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| delegate | string | - | delegator address in CAIP | +| Note: Support for contract interaction via viem is coming soon | | | | + +--- + +### **Alias Information** + +```tsx +// fetch alias info +const aliasInfo = userAlice.channel.alias.info({alias: '0xABC', aliasChain:'POLYGON'}) + +``` + +| Parameter | Type | Default | Description | +| --- | --- | --- | --- | +| options | AliasOptions | - | Configuration options for retrieving alias information. | +| options.alias | string | - | The alias address | +| options.aliasChain | ALIAS_CHAIN | - | The name of the alias chain, which can be 'POLYGON' or 'BSC' or 'OPTIMISM' or 'POLYGONZKEVM' | \ No newline at end of file