Skip to content
This repository was archived by the owner on Dec 3, 2025. It is now read-only.
Closed
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
11 changes: 11 additions & 0 deletions packages/notify-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class NotifyClient extends INotifyClient {
public messages: INotifyClient["messages"];
public watchedAccounts: INotifyClient["watchedAccounts"];
public registrationData: INotifyClient["registrationData"];
public clientStateMaintenance: INotifyClient["clientStateMaintenance"];
public identityKeys: INotifyClient["identityKeys"];

static async init(opts: NotifyClientTypes.ClientOptions) {
Expand Down Expand Up @@ -95,6 +96,15 @@ export class NotifyClient extends INotifyClient {

this.identityKeys =
opts.identityKeys ?? new IdentityKeys(this.core, this.keyserverUrl);

this.clientStateMaintenance = new Store(
this.core,
this.logger,
"clientStateMaintenance",
NOTIFY_CLIENT_STORAGE_PREFIX,
() => "stateMaintenance"
);

this.engine = new NotifyEngine(this);
}

Expand Down Expand Up @@ -244,6 +254,7 @@ export class NotifyClient extends INotifyClient {
await this.registrationData.init();
await this.identityKeys.init();
await this.watchedAccounts.init();
await this.clientStateMaintenance.init();
await this.engine.init();

this.logger.info(`NotifyClient Initialization Success`);
Expand Down
14 changes: 14 additions & 0 deletions packages/notify-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,20 @@ export class NotifyEngine extends INotifyEngine {
| NotifyClientTypes.UpdateResponseJWTClaims
>(jwt, act);

const latestSubscriptionSequence = this.client.clientStateMaintenance.length
? this.client.clientStateMaintenance.get("stateMaintenance")
.latestSubscriptionSequence
: 0;

const incomingMessageIsOld = latestSubscriptionSequence > claims.seq;
if (incomingMessageIsOld) {
return this.client.subscriptions.getAll();
}

await this.client.clientStateMaintenance.set("stateMaintenance", {
latestSubscriptionSequence: claims.seq,
});

this.client.logger.info("updateSubscriptionsUsingJwt > claims", claims);

// Clean up any subscriptions that are no longer valid.
Expand Down
12 changes: 12 additions & 0 deletions packages/notify-client/src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export declare namespace NotifyClientTypes {
aud: string; // did:pkh blockchain account that notify subscription is associated with
sub: string; // did:pkh of blockchain account that this notify subscription is associated with
sbs: NotifyServerSubscription[]; // array of [Notify Server Subscriptions]
seq: number;
}

interface CommonResponseJWTClaims extends BaseJwtClaims {
Expand All @@ -220,16 +221,19 @@ export declare namespace NotifyClientTypes {
interface SubscriptionResponseJWTClaims extends CommonResponseJWTClaims {
act: "notify_subscription_response";
sbs: NotifyServerSubscription[]; // array of [Notify Server Subscriptions]
seq: number;
}

interface UpdateResponseJWTClaims extends CommonResponseJWTClaims {
act: "notify_update_response";
sbs: NotifyServerSubscription[]; // array of [Notify Server Subscriptions]
seq: number;
}

interface DeleteResponseJWTClaims extends CommonResponseJWTClaims {
act: "notify_delete_response";
sbs: NotifyServerSubscription[]; // array of [Notify Server Subscriptions]
seq: number;
}

interface GetNotificationsResponseClaims extends BaseJwtClaims {
Expand All @@ -247,6 +251,7 @@ export declare namespace NotifyClientTypes {
aud: string; // did:key of client identity key
sub: string; // did:key of the public key used for key agreement on the Notify topic
sbs: NotifyServerSubscription[]; // array of [Notify Server Subscriptions]
seq: number;
}

interface NotifySubscriptionsChangedResponseClaims extends BaseJwtClaims {
Expand Down Expand Up @@ -331,6 +336,13 @@ export abstract class INotifyClient {
}
>;

public abstract clientStateMaintenance: IStore<
"stateMaintenance",
{
latestSubscriptionSequence: number;
}
>;

public abstract identityKeys: IdentityKeys;

public abstract subscriptions: IStore<
Expand Down