pico-engine 1.4.0 → 1.6.0

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.
Files changed (82) hide show
  1. package/README.md +188 -0
  2. package/dist/RulesetRegistryLoaderFs.js +2 -0
  3. package/dist/auth/AuthService.js +601 -0
  4. package/dist/auth/index.js +8 -0
  5. package/dist/auth/webauthn.js +97 -0
  6. package/dist/bundledKrl.js +42 -0
  7. package/dist/cli.js +11 -0
  8. package/dist/identity/IdentityService.js +340 -0
  9. package/dist/identity/crossPico.js +238 -0
  10. package/dist/identity/dbHelpers.js +67 -0
  11. package/dist/identity/didcommIngressRoutes.js +44 -0
  12. package/dist/identity/didoModule.js +252 -0
  13. package/dist/identity/errors.js +11 -0
  14. package/dist/identity/establishSubscription.js +97 -0
  15. package/dist/identity/index.js +15 -0
  16. package/dist/identity/peerDid.js +9 -0
  17. package/dist/identity/skyIntro.js +194 -0
  18. package/dist/identity/skyProtocol.js +105 -0
  19. package/dist/identity/store.js +233 -0
  20. package/dist/identity/types.js +13 -0
  21. package/dist/identity/veramoDidComm.js +260 -0
  22. package/dist/identity/webvh.js +266 -0
  23. package/dist/identity/webvhCrypto.js +128 -0
  24. package/dist/identity/webvhRoutes.js +61 -0
  25. package/dist/index.js +100 -44
  26. package/dist/oauth/OAuthService.js +388 -0
  27. package/dist/oauth/acg.js +495 -0
  28. package/dist/oauth/channelEligibility.js +26 -0
  29. package/dist/oauth/errors.js +12 -0
  30. package/dist/oauth/index.js +21 -0
  31. package/dist/oauth/krlModule.js +27 -0
  32. package/dist/oauth/meshOAuth.js +43 -0
  33. package/dist/provisionRoot.js +118 -0
  34. package/dist/server.js +609 -15
  35. package/dist/uiChannelPolicies.js +48 -0
  36. package/krl/io.picolabs.did-o.krl +5 -1
  37. package/krl/io.picolabs.oauth.krl +48 -0
  38. package/krl/io.picolabs.pico-engine-ui.krl +106 -18
  39. package/krl/io.picolabs.subscription.krl +242 -23
  40. package/krl/io.picolabs.wrangler.krl +225 -16
  41. package/package.json +38 -9
  42. package/public/docs/krl/_sidebar.md +1 -0
  43. package/public/docs/krl/discovery.md +144 -0
  44. package/public/docs/krl/modules/ctx.md +8 -0
  45. package/public/docs/krl/modules/event.md +41 -0
  46. package/public/pico-engine-ui.css +1 -1
  47. package/public/pico-engine-ui.js +24 -20
  48. package/public/pico-labs-logo.png +0 -0
  49. package/src/RulesetRegistryLoaderFs.ts +2 -0
  50. package/src/auth/AuthService.ts +850 -0
  51. package/src/auth/index.ts +17 -0
  52. package/src/auth/webauthn.ts +182 -0
  53. package/src/bundledKrl.ts +42 -0
  54. package/src/cli.ts +11 -0
  55. package/src/identity/IdentityService.ts +571 -0
  56. package/src/identity/crossPico.ts +371 -0
  57. package/src/identity/dbHelpers.ts +51 -0
  58. package/src/identity/didcommIngressRoutes.ts +54 -0
  59. package/src/identity/didoModule.ts +388 -0
  60. package/src/identity/errors.ts +8 -0
  61. package/src/identity/establishSubscription.ts +160 -0
  62. package/src/identity/index.ts +24 -0
  63. package/src/identity/peerDid.ts +22 -0
  64. package/src/identity/skyIntro.ts +321 -0
  65. package/src/identity/skyProtocol.ts +192 -0
  66. package/src/identity/store.ts +343 -0
  67. package/src/identity/types.ts +63 -0
  68. package/src/identity/veramoDidComm.ts +363 -0
  69. package/src/identity/webvh.ts +325 -0
  70. package/src/identity/webvhCrypto.ts +200 -0
  71. package/src/identity/webvhRoutes.ts +64 -0
  72. package/src/index.ts +145 -53
  73. package/src/oauth/OAuthService.ts +510 -0
  74. package/src/oauth/acg.ts +666 -0
  75. package/src/oauth/channelEligibility.ts +26 -0
  76. package/src/oauth/errors.ts +10 -0
  77. package/src/oauth/index.ts +14 -0
  78. package/src/oauth/krlModule.ts +31 -0
  79. package/src/oauth/meshOAuth.ts +50 -0
  80. package/src/provisionRoot.ts +151 -0
  81. package/src/server.ts +700 -24
  82. package/src/uiChannelPolicies.ts +49 -0
@@ -0,0 +1,571 @@
1
+ import * as cuid from "cuid";
2
+ import fetch from "cross-fetch";
3
+ import { PicoFramework } from "pico-framework";
4
+ import { IdentityStore } from "./store";
5
+ import { DidCommRoutes, PeerSubscriptionRecord } from "./types";
6
+ import { IdentityError } from "./errors";
7
+ import {
8
+ ensureWebvhDid,
9
+ ensureWebvhForLoadedPicos as provisionWebvhForAllLoadedPicos,
10
+ formatDidLogAsJsonl,
11
+ parallelWebDocForPico,
12
+ portableWebvhLogHttpUrl,
13
+ resolveLocalWebvhLog,
14
+ resolveWebvhDid,
15
+ type EnsureWebvhDidOptions,
16
+ } from "./webvh";
17
+ import {
18
+ packDidCommMessage,
19
+ unpackDidCommMessage,
20
+ createPeerDid,
21
+ warmPeerDidsForPico,
22
+ resolvePeerDidDocument,
23
+ } from "./veramoDidComm";
24
+ import {
25
+ establishSubscriptionIdentity,
26
+ linkRemotePeer,
27
+ establishInputFromBus,
28
+ type EstablishSubscriptionInput,
29
+ type EstablishSubscriptionResult,
30
+ type LinkRemotePeerInput,
31
+ } from "./establishSubscription";
32
+ import {
33
+ crossPicoEvent,
34
+ crossPicoQuery,
35
+ extractDidcommEndpoint,
36
+ type CrossPicoEventInput,
37
+ type CrossPicoQueryInput,
38
+ } from "./crossPico";
39
+ import {
40
+ SKY_INTRO,
41
+ SKY_INTRO_RESPONSE,
42
+ SKY_EVENT,
43
+ SKY_QUERY,
44
+ parseSkyEventBody,
45
+ parseSkyQueryBody,
46
+ } from "./skyProtocol";
47
+ import {
48
+ sendSkyIntro,
49
+ sendSkyIntroResponse,
50
+ handleSkyIntroAtIngress,
51
+ handleSkyIntroResponseAtIngress,
52
+ type SkyIntroSendInput,
53
+ } from "./skyIntro";
54
+ import type { SkyIntroResponseBody } from "./skyProtocol";
55
+
56
+ export interface DidCommMessageOptions {
57
+ type: string;
58
+ body: unknown;
59
+ from?: string;
60
+ to?: string[];
61
+ thid?: string;
62
+ pthid?: string;
63
+ expires_time?: number;
64
+ }
65
+
66
+ export interface DidCommPlainMessage {
67
+ id: string;
68
+ typ: string;
69
+ type: string;
70
+ body: unknown;
71
+ from?: string;
72
+ to?: string[];
73
+ thid?: string;
74
+ pthid?: string;
75
+ created_time: number;
76
+ expires_time?: number;
77
+ }
78
+
79
+ export interface IdentityServiceDeps {
80
+ store: IdentityStore;
81
+ getBaseUrl: () => string;
82
+ pf: PicoFramework;
83
+ }
84
+
85
+ /**
86
+ * Engine identity primitive — store-backed DID state and DIDComm capabilities.
87
+ * Crypto (pack/unpack) is delegated to Veramo when installed (Epic 2+).
88
+ */
89
+ export class IdentityService {
90
+ private store: IdentityStore;
91
+ private getBaseUrl: () => string;
92
+ private pf: PicoFramework;
93
+
94
+ constructor(deps: IdentityServiceDeps) {
95
+ this.store = deps.store;
96
+ this.getBaseUrl = deps.getBaseUrl;
97
+ this.pf = deps.pf;
98
+ }
99
+
100
+ async ensureWebvhDid(
101
+ picoId: string,
102
+ options: EnsureWebvhDidOptions = {}
103
+ ): Promise<string> {
104
+ return ensureWebvhDid(
105
+ this.store,
106
+ this.pf,
107
+ () => this.getBaseUrl(),
108
+ picoId,
109
+ options
110
+ );
111
+ }
112
+
113
+ async ensureWebvhForAllLoadedPicos(): Promise<void> {
114
+ await provisionWebvhForAllLoadedPicos(
115
+ this.store,
116
+ this.pf,
117
+ () => this.getBaseUrl()
118
+ );
119
+ for (const pico of this.pf.loadedPicos()) {
120
+ await warmPeerDidsForPico(this.store, pico.id);
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Layer 2 subscription establish — create did:peer + internal Rx + persist keys.
126
+ * Idempotent when called again with the same subscriptionId.
127
+ */
128
+ async establishSubscription(
129
+ picoId: string,
130
+ input: EstablishSubscriptionInput
131
+ ): Promise<EstablishSubscriptionResult> {
132
+ return establishSubscriptionIdentity(this.store, this.pf, picoId, input);
133
+ }
134
+
135
+ async establishSubscriptionFromBus(
136
+ picoId: string,
137
+ bus: Record<string, unknown>
138
+ ): Promise<EstablishSubscriptionResult> {
139
+ return this.establishSubscription(picoId, establishInputFromBus(bus));
140
+ }
141
+
142
+ async linkRemotePeer(
143
+ picoId: string,
144
+ subscriptionId: string,
145
+ input: LinkRemotePeerInput
146
+ ): Promise<PeerSubscriptionRecord> {
147
+ return linkRemotePeer(this.store, picoId, subscriptionId, input);
148
+ }
149
+
150
+ async teardownSubscription(
151
+ picoId: string,
152
+ subscriptionId: string
153
+ ): Promise<void> {
154
+ await this.store.deletePeerSubscription(picoId, subscriptionId);
155
+ }
156
+
157
+ async findSubscriptionIdForDid(
158
+ picoId: string,
159
+ did: string
160
+ ): Promise<string | null> {
161
+ return this.store.findSubscriptionIdForDid(picoId, did);
162
+ }
163
+
164
+ /**
165
+ * Query a remote pico by DID — layer2 subscription route first, then cold did:webvh.
166
+ */
167
+ async picoQuery(
168
+ picoId: string,
169
+ did: string,
170
+ query: CrossPicoQueryInput
171
+ ): Promise<unknown> {
172
+ const subId = await this.findSubscriptionIdForDid(picoId, did);
173
+ if (subId) {
174
+ return this.crossPicoQuery(picoId, undefined, subId, query);
175
+ }
176
+ return this.coldDidQuery(picoId, did, query);
177
+ }
178
+
179
+ /**
180
+ * Send an event to a remote pico by DID via an established layer2 subscription.
181
+ */
182
+ async picoEvent(
183
+ picoId: string,
184
+ did: string,
185
+ event: CrossPicoEventInput
186
+ ): Promise<{ eid: string; responses: unknown[] }> {
187
+ const subId = await this.findSubscriptionIdForDid(picoId, did);
188
+ if (!subId) {
189
+ throw new IdentityError(`No layer2 subscription route for DID ${did}`, 404);
190
+ }
191
+ return this.crossPicoEvent(picoId, undefined, subId, event);
192
+ }
193
+
194
+ private async coldDidQuery(
195
+ picoId: string,
196
+ did: string,
197
+ query: CrossPicoQueryInput
198
+ ): Promise<unknown> {
199
+ const from = await this.getMyDid(picoId);
200
+ if (!from) {
201
+ throw new IdentityError("Pico has no did:webvh for cold DID query", 404);
202
+ }
203
+ const message = this.generateMessage({
204
+ type: "https://picolabs.io/query/1.0/query",
205
+ from,
206
+ to: [did],
207
+ body: query,
208
+ });
209
+ const doc = await this.resolveDid(picoId, did);
210
+ const endpoint = extractDidcommEndpoint(doc);
211
+ const packed = await this.packMessage(picoId, message, from, did);
212
+ const res = await fetch(endpoint, {
213
+ method: "POST",
214
+ headers: { "Content-Type": "application/didcomm-encrypted+json" },
215
+ body: packed,
216
+ });
217
+ if (!res.ok) {
218
+ throw new IdentityError(`Cold DID query failed: HTTP ${res.status}`, res.status);
219
+ }
220
+ const data = await res.json();
221
+ if (data.result !== undefined) {
222
+ return data.result;
223
+ }
224
+ return data;
225
+ }
226
+
227
+ async getMyDid(picoId: string): Promise<string | null> {
228
+ return this.store.getWebvhDid(picoId);
229
+ }
230
+
231
+ async getPublicIntro(picoId: string): Promise<boolean> {
232
+ const value = await this.store.getPublicIntro(picoId);
233
+ if (value === null) {
234
+ return false;
235
+ }
236
+ return value;
237
+ }
238
+
239
+ async setPublicIntro(picoId: string, enabled: boolean): Promise<boolean> {
240
+ await this.store.putPublicIntro(picoId, enabled);
241
+ return true;
242
+ }
243
+
244
+ /** Whether unsolicited DIDComm intro to this pico's did:webvh is allowed. */
245
+ async acceptsPublicIntro(picoId: string): Promise<boolean> {
246
+ return this.getPublicIntro(picoId);
247
+ }
248
+
249
+ async getWebvhLogJsonl(picoId: string): Promise<string | null> {
250
+ const log = await this.store.getWebvhLog(picoId);
251
+ if (!log || log.length === 0) {
252
+ return null;
253
+ }
254
+ return formatDidLogAsJsonl(log);
255
+ }
256
+
257
+ async getParallelWebDoc(
258
+ picoId: string
259
+ ): Promise<Record<string, unknown> | null> {
260
+ return parallelWebDocForPico(this.store, picoId);
261
+ }
262
+
263
+ async addRoute(
264
+ picoId: string,
265
+ type: string,
266
+ domain: string,
267
+ name: string
268
+ ): Promise<boolean> {
269
+ const routes = (await this.store.getRoutes(picoId)) || {};
270
+ routes[type] = { domain, name };
271
+ await this.store.putRoutes(picoId, routes);
272
+ return true;
273
+ }
274
+
275
+ async getRoutes(picoId: string): Promise<DidCommRoutes> {
276
+ return (await this.store.getRoutes(picoId)) || {};
277
+ }
278
+
279
+ generateMessage(options: DidCommMessageOptions): DidCommPlainMessage {
280
+ const message: DidCommPlainMessage = {
281
+ id: cuid(),
282
+ typ: "application/didcomm-plain+json",
283
+ type: options.type,
284
+ body: options.body,
285
+ from: options.from,
286
+ to: options.to,
287
+ thid: options.thid,
288
+ pthid: options.pthid,
289
+ created_time: Math.floor(Date.now() / 1000),
290
+ };
291
+ if (options.expires_time) {
292
+ message.expires_time =
293
+ Math.floor(Date.now() / 1000) + options.expires_time;
294
+ }
295
+ return message;
296
+ }
297
+
298
+ /**
299
+ * Pack a plaintext DIDComm message (authcrypt). Requires @veramo/did-comm and
300
+ * supporting packages to be installed (`npm install` in packages/pico-engine).
301
+ */
302
+ async packMessage(
303
+ picoId: string,
304
+ message: DidCommPlainMessage,
305
+ from: string,
306
+ to: string
307
+ ): Promise<string> {
308
+ return packDidCommMessage(picoId, message, from, to, this.store, {
309
+ resolveDid: (did) => this.resolveDid("", did),
310
+ });
311
+ }
312
+
313
+ async unpackMessage(picoId: string, jwe: string): Promise<{
314
+ message: DidCommPlainMessage;
315
+ metadata: Record<string, unknown>;
316
+ }> {
317
+ return unpackDidCommMessage(picoId, jwe, this.store);
318
+ }
319
+
320
+ /** Create a did:peer (num_algo 2). Prefer establishSubscription for subscriptions. */
321
+ async createPeerDid(_picoId: string): Promise<string> {
322
+ return createPeerDid();
323
+ }
324
+
325
+ async registerPeerSubscription(
326
+ picoId: string,
327
+ record: PeerSubscriptionRecord
328
+ ): Promise<void> {
329
+ await this.store.putPeerSubscription(picoId, record);
330
+ }
331
+
332
+ async crossPicoEvent(
333
+ fromPicoId: string,
334
+ toPicoId: string | undefined,
335
+ subscriptionId: string,
336
+ event: CrossPicoEventInput
337
+ ): Promise<{ eid: string; responses: unknown[] }> {
338
+ return crossPicoEvent(
339
+ {
340
+ store: this.store,
341
+ pf: this.pf,
342
+ getBaseUrl: this.getBaseUrl,
343
+ identity: this,
344
+ },
345
+ fromPicoId,
346
+ toPicoId,
347
+ subscriptionId,
348
+ event
349
+ );
350
+ }
351
+
352
+ async crossPicoQuery(
353
+ fromPicoId: string,
354
+ toPicoId: string | undefined,
355
+ subscriptionId: string,
356
+ query: CrossPicoQueryInput
357
+ ): Promise<unknown> {
358
+ return crossPicoQuery(
359
+ {
360
+ store: this.store,
361
+ pf: this.pf,
362
+ getBaseUrl: this.getBaseUrl,
363
+ identity: this,
364
+ },
365
+ fromPicoId,
366
+ toPicoId,
367
+ subscriptionId,
368
+ query
369
+ );
370
+ }
371
+
372
+ private skyIntroDeps() {
373
+ return {
374
+ store: this.store,
375
+ pf: this.pf,
376
+ getBaseUrl: this.getBaseUrl,
377
+ identity: this,
378
+ };
379
+ }
380
+
381
+ async sendSkyIntro(
382
+ picoId: string,
383
+ input: SkyIntroSendInput
384
+ ): Promise<{ messageId: string; peerDid: string }> {
385
+ return sendSkyIntro(this.skyIntroDeps(), picoId, input);
386
+ }
387
+
388
+ async sendSkyIntroResponse(
389
+ picoId: string,
390
+ subscriptionId: string,
391
+ toPeerDid: string,
392
+ response: Omit<SkyIntroResponseBody, "sky_version">,
393
+ options: { thid?: string; remoteDidcommEndpoint?: string } = {}
394
+ ): Promise<string> {
395
+ return sendSkyIntroResponse(
396
+ this.skyIntroDeps(),
397
+ picoId,
398
+ subscriptionId,
399
+ toPeerDid,
400
+ response,
401
+ options
402
+ );
403
+ }
404
+
405
+ /**
406
+ * Door verify: unpack JWE at ingress, route by sender peer DID, deliver SKY payload.
407
+ */
408
+ async handleDidcommIngress(
409
+ ingressEci: string,
410
+ jwe: string
411
+ ): Promise<Record<string, unknown>> {
412
+ const picoId = await this.store.findPicoIdByIngressEci(ingressEci);
413
+ if (!picoId) {
414
+ throw new IdentityError("Unknown DIDComm ingress channel", 404);
415
+ }
416
+
417
+ const { message } = await this.unpackMessage(picoId, jwe);
418
+ const senderDid = message.from;
419
+ if (!senderDid) {
420
+ throw new IdentityError("DIDComm message missing from", 400);
421
+ }
422
+
423
+ if (message.type === SKY_INTRO) {
424
+ return handleSkyIntroAtIngress(this.skyIntroDeps(), picoId, message);
425
+ }
426
+
427
+ if (message.type === SKY_INTRO_RESPONSE) {
428
+ return handleSkyIntroResponseAtIngress(
429
+ this.skyIntroDeps(),
430
+ picoId,
431
+ message
432
+ );
433
+ }
434
+
435
+ // Channel policy (Epic 7): authenticated sender peer DID → subscription record →
436
+ // internal Rx channel. Door verify proves crypto + subscription relationship;
437
+ // pf.eventWait / pf.query enforce assertEventPolicy / assertQueryPolicy on rxEci.
438
+ const sub = await this.store.findPeerSubscriptionBySenderDid(
439
+ picoId,
440
+ senderDid
441
+ );
442
+ if (!sub || !sub.rxEci) {
443
+ throw new IdentityError("unknown_subscription", 404);
444
+ }
445
+
446
+ const callerDid = sub.remoteWebvhDid || senderDid;
447
+
448
+ if (message.type === SKY_EVENT) {
449
+ const body = parseSkyEventBody(message.body);
450
+ try {
451
+ const result = await this.pf.eventWait(
452
+ {
453
+ eci: sub.rxEci,
454
+ domain: body.domain,
455
+ name: body.name,
456
+ data: {
457
+ attrs: { ...body.attrs, callerDid },
458
+ },
459
+ time: 0,
460
+ },
461
+ undefined
462
+ );
463
+ return {
464
+ eid: result.eid,
465
+ responses: result.responses,
466
+ directives: result.responses,
467
+ };
468
+ } catch (err) {
469
+ if (isPolicyError(err)) {
470
+ throw new IdentityError("policy_denied", 403);
471
+ }
472
+ throw err;
473
+ }
474
+ }
475
+
476
+ if (message.type === SKY_QUERY) {
477
+ const body = parseSkyQueryBody(message.body);
478
+ try {
479
+ const result = await this.pf.query({
480
+ eci: sub.rxEci,
481
+ rid: body.rid,
482
+ name: body.name,
483
+ args: body.args,
484
+ });
485
+ return { status: "ok", result };
486
+ } catch (err) {
487
+ if (isPolicyError(err)) {
488
+ throw new IdentityError("policy_denied", 403);
489
+ }
490
+ throw new IdentityError(
491
+ (err as Error).message || "query_failed",
492
+ 502
493
+ );
494
+ }
495
+ }
496
+
497
+ const routes = await this.getRoutes(picoId);
498
+ const route = routes[message.type];
499
+ if (route) {
500
+ return { status: "routed", type: message.type };
501
+ }
502
+
503
+ throw new IdentityError(`Unknown SKY message type: ${message.type}`, 400);
504
+ }
505
+
506
+ /** Resolve a DID from the local store, then via did:webvh remote resolution. */
507
+ async resolveDid(picoId: string, did: string): Promise<Record<string, unknown>> {
508
+ const normalized = did.trim();
509
+ const cached = await this.store.getDidDoc(picoId, normalized);
510
+ if (cached) {
511
+ return cached.doc;
512
+ }
513
+ if (normalized.startsWith("did:webvh:")) {
514
+ const localPicoId = await this.store.findPicoIdByWebvhDid(normalized);
515
+ if (localPicoId) {
516
+ const log = await this.store.getWebvhLog(localPicoId);
517
+ if (log && log.length > 0) {
518
+ const resolved = await resolveLocalWebvhLog(log);
519
+ await this.store.putDidDoc(picoId, {
520
+ did: resolved.did,
521
+ doc: resolved.doc,
522
+ cachedAt: new Date().toISOString(),
523
+ });
524
+ return resolved.doc;
525
+ }
526
+ }
527
+ try {
528
+ const resolved = await resolveWebvhDid(this.store, normalized);
529
+ await this.store.putDidDoc(picoId, {
530
+ did: resolved.did,
531
+ doc: resolved.doc,
532
+ cachedAt: new Date().toISOString(),
533
+ });
534
+ return resolved.doc;
535
+ } catch (err) {
536
+ const detail = err instanceof Error ? err.message : String(err);
537
+ const logUrl = portableWebvhLogHttpUrl(normalized);
538
+ throw new IdentityError(
539
+ `Remote did:webvh resolution failed${logUrl ? ` (${logUrl})` : ""}: ${detail}`,
540
+ 404
541
+ );
542
+ }
543
+ }
544
+ if (normalized.startsWith("did:peer:")) {
545
+ const doc = await resolvePeerDidDocument(normalized);
546
+ await this.store.putDidDoc(picoId, {
547
+ did: normalized,
548
+ doc,
549
+ cachedAt: new Date().toISOString(),
550
+ });
551
+ return doc;
552
+ }
553
+ throw new IdentityError(`DID not found in identity store: ${normalized}`, 404);
554
+ }
555
+
556
+ createInviteUrl(base64: string): string {
557
+ const host = this.getBaseUrl();
558
+ if (host.indexOf("localhost") >= 0) {
559
+ return "http://example.com/invite?_oob=" + base64;
560
+ }
561
+ return host + "/invite?_oob=" + base64;
562
+ }
563
+ }
564
+
565
+ function isPolicyError(err: unknown): boolean {
566
+ return (
567
+ err instanceof Error &&
568
+ (err.message.includes("channel policy") ||
569
+ err.message.includes("Denied by channel"))
570
+ );
571
+ }