@massalabs/gossip-sdk 0.0.2-dev.20260305101123 → 0.0.2-dev.20260306154623
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/gossip.js +1 -1
- package/dist/services/auth.d.ts +5 -3
- package/dist/services/auth.js +13 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -209,7 +209,7 @@ const result = await sdk.announcements.fetch();
|
|
|
209
209
|
|
|
210
210
|
```typescript
|
|
211
211
|
// Publish public key so the user is discoverable
|
|
212
|
-
await sdk.auth.
|
|
212
|
+
await sdk.auth.publishPublicKey(publicKey);
|
|
213
213
|
```
|
|
214
214
|
|
|
215
215
|
## Events
|
package/dist/gossip.js
CHANGED
|
@@ -235,7 +235,7 @@ class GossipSdk {
|
|
|
235
235
|
this._message = new MessageService(messageProtocol, session, this.eventEmitter, config, queries);
|
|
236
236
|
this._refresh = new RefreshService(this._message, this._discussion, this._announcement, session, this.eventEmitter, queries, this.config);
|
|
237
237
|
// Publish gossip ID (public key) on messageProtocol so the user is discoverable
|
|
238
|
-
await this._auth.
|
|
238
|
+
await this._auth.publishPublicKey(session.ourPk, session.userIdEncoded, queries);
|
|
239
239
|
// Now set refreshService on services (circular dependency resolved via setter)
|
|
240
240
|
this._discussion.setRefreshService(this._refresh);
|
|
241
241
|
this._message.setRefreshService(this._refresh);
|
package/dist/services/auth.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { UserPublicKeys } from '../wasm/bindings.js';
|
|
7
7
|
import { IAuthProtocol } from '../api/authProtocol.js';
|
|
8
|
+
import type { Queries } from '../db/queries/index.js';
|
|
8
9
|
export declare class AuthService {
|
|
9
10
|
authProtocol: IAuthProtocol;
|
|
10
11
|
constructor(authProtocol: IAuthProtocol);
|
|
@@ -14,11 +15,12 @@ export declare class AuthService {
|
|
|
14
15
|
*/
|
|
15
16
|
fetchPublicKeyByUserId(userId: string): Promise<UserPublicKeys>;
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
+
* Publish public key to the server if not published in the last 24 hours.
|
|
18
19
|
* @param publicKeys - UserPublicKeys instance
|
|
19
|
-
* @param userId - Bech32-encoded userId
|
|
20
|
+
* @param userId - Bech32-encoded userId
|
|
21
|
+
* @param queries - Database queries
|
|
20
22
|
*/
|
|
21
|
-
|
|
23
|
+
publishPublicKey(publicKeys: UserPublicKeys, userId: string, queries: Queries): Promise<void>;
|
|
22
24
|
}
|
|
23
25
|
export declare const PUBLIC_KEY_NOT_FOUND_ERROR = "Public key not found";
|
|
24
26
|
export declare const PUBLIC_KEY_NOT_FOUND_MESSAGE = "Contact public key not found. It may not be published yet.";
|
package/dist/services/auth.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { UserPublicKeys } from '../wasm/bindings.js';
|
|
7
7
|
import { decodeUserId } from '../utils/userId.js';
|
|
8
8
|
import { encodeToBase64, decodeFromBase64 } from '../utils/base64.js';
|
|
9
|
+
const REPUBLISH_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
9
10
|
export class AuthService {
|
|
10
11
|
constructor(authProtocol) {
|
|
11
12
|
Object.defineProperty(this, "authProtocol", {
|
|
@@ -29,20 +30,22 @@ export class AuthService {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
+
* Publish public key to the server if not published in the last 24 hours.
|
|
33
34
|
* @param publicKeys - UserPublicKeys instance
|
|
34
|
-
* @param userId - Bech32-encoded userId
|
|
35
|
+
* @param userId - Bech32-encoded userId
|
|
36
|
+
* @param queries - Database queries
|
|
35
37
|
*/
|
|
36
|
-
async
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
catch {
|
|
43
|
-
// Key not found on server — publish it
|
|
38
|
+
async publishPublicKey(publicKeys, userId, queries) {
|
|
39
|
+
const profile = await queries.userProfiles.getById(userId);
|
|
40
|
+
if (profile?.lastPublicKeyPush) {
|
|
41
|
+
const elapsed = Date.now() - profile.lastPublicKeyPush.getTime();
|
|
42
|
+
if (elapsed < REPUBLISH_INTERVAL_MS)
|
|
43
|
+
return;
|
|
44
44
|
}
|
|
45
45
|
await this.authProtocol.postPublicKey(encodeToBase64(publicKeys.to_bytes()));
|
|
46
|
+
await queries.userProfiles.updateById(userId, {
|
|
47
|
+
lastPublicKeyPush: new Date(),
|
|
48
|
+
});
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
export const PUBLIC_KEY_NOT_FOUND_ERROR = 'Public key not found';
|
package/package.json
CHANGED