@zbruceli/openclaw-dchat 0.1.7 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zbruceli/openclaw-dchat",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "OpenClaw D-Chat/nMobile channel plugin — decentralized E2E encrypted messaging over the NKN relay network",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/src/channel.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import {
2
2
  applyAccountNameToChannelSection,
3
+ buildBaseAccountStatusSnapshot,
4
+ buildBaseChannelStatusSummary,
3
5
  buildChannelConfigSchema,
6
+ collectStatusIssuesFromLastError,
7
+ createDefaultChannelRuntimeState,
4
8
  createScopedPairingAccess,
5
9
  DEFAULT_ACCOUNT_ID,
6
10
  deleteAccountFromConfigSection,
@@ -103,6 +107,7 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
103
107
  name: account.name,
104
108
  enabled: account.enabled,
105
109
  configured: account.configured,
110
+ nknAddress: account.nknAddress ?? null,
106
111
  }),
107
112
  resolveAllowFrom: ({ cfg, accountId }) => {
108
113
  const dchatConfig = resolveDchatAccountConfig({ cfg: cfg as CoreConfig, accountId });
@@ -262,46 +267,16 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
262
267
  },
263
268
  },
264
269
  status: {
265
- defaultRuntime: {
266
- accountId: DEFAULT_ACCOUNT_ID,
267
- running: false,
268
- lastStartAt: null,
269
- lastStopAt: null,
270
- lastError: null,
271
- },
270
+ defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
272
271
  buildChannelSummary: ({ snapshot }) => ({
273
- configured: snapshot.configured ?? false,
274
- running: snapshot.running ?? false,
275
- nknAddress: snapshot.baseUrl ?? null,
276
- lastStartAt: snapshot.lastStartAt ?? null,
277
- lastStopAt: snapshot.lastStopAt ?? null,
278
- lastError: snapshot.lastError ?? null,
272
+ ...buildBaseChannelStatusSummary(snapshot),
273
+ nknAddress: snapshot.nknAddress ?? null,
279
274
  }),
280
275
  buildAccountSnapshot: ({ account, runtime }) => ({
281
- accountId: account.accountId,
282
- name: account.name,
283
- enabled: account.enabled,
284
- configured: account.configured,
285
- running: runtime?.running ?? false,
286
- lastStartAt: runtime?.lastStartAt ?? null,
287
- lastStopAt: runtime?.lastStopAt ?? null,
288
- lastError: runtime?.lastError ?? null,
289
- lastInboundAt: runtime?.lastInboundAt ?? null,
290
- lastOutboundAt: runtime?.lastOutboundAt ?? null,
276
+ ...buildBaseAccountStatusSnapshot({ account, runtime }),
277
+ nknAddress: account.nknAddress ?? null,
291
278
  }),
292
- collectStatusIssues: (accounts) =>
293
- accounts.flatMap((account) => {
294
- const lastError = typeof account.lastError === "string" ? account.lastError.trim() : "";
295
- if (!lastError) return [];
296
- return [
297
- {
298
- channel: "dchat",
299
- accountId: account.accountId,
300
- kind: "runtime",
301
- message: `Channel error: ${lastError}`,
302
- },
303
- ];
304
- }),
279
+ collectStatusIssues: (accounts) => collectStatusIssuesFromLastError("dchat", accounts),
305
280
  },
306
281
  gateway: {
307
282
  startAccount: async (ctx) => {
@@ -1,3 +1,4 @@
1
+ import nkn from "nkn-sdk";
1
2
  import type { OpenClawConfig } from "openclaw/plugin-sdk";
2
3
  import { z } from "zod";
3
4
  import type { DchatAccountConfig, ResolvedDchatAccount } from "./types.js";
@@ -104,8 +105,18 @@ export function resolveDchatAccount(params: {
104
105
  const accountId = rawAccountId || DEFAULT_ACCOUNT_ID;
105
106
  const accountConfig = resolveDchatAccountConfig({ cfg, accountId });
106
107
 
107
- const hasSeed = Boolean(accountConfig.seed?.trim());
108
- const hasKeystore = Boolean(accountConfig.keystoreJson?.trim());
108
+ const seed = accountConfig.seed?.trim();
109
+ const hasSeed = Boolean(seed);
110
+
111
+ let nknAddress: string | undefined;
112
+ if (hasSeed && seed) {
113
+ try {
114
+ const wallet = new nkn.Wallet({ seed });
115
+ nknAddress = wallet.getPublicKey();
116
+ } catch {
117
+ // seed may be invalid
118
+ }
119
+ }
109
120
 
110
121
  const baseEnabled = cfg.channels?.dchat?.enabled !== false;
111
122
  return {
@@ -113,7 +124,8 @@ export function resolveDchatAccount(params: {
113
124
  name: accountConfig.name || accountId,
114
125
  enabled: baseEnabled && accountConfig.enabled !== false,
115
126
  configured: hasSeed,
116
- seed: accountConfig.seed?.trim(),
127
+ seed,
128
+ nknAddress,
117
129
  numSubClients: accountConfig.numSubClients ?? 4,
118
130
  ipfsGateway: accountConfig.ipfsGateway ?? "64.225.88.71:80",
119
131
  config: accountConfig,
package/src/types.ts CHANGED
@@ -128,6 +128,7 @@ export interface ResolvedDchatAccount {
128
128
  enabled: boolean;
129
129
  configured: boolean;
130
130
  seed?: string;
131
+ nknAddress?: string;
131
132
  numSubClients: number;
132
133
  ipfsGateway: string;
133
134
  config: DchatAccountConfig;