@agentunion/fastaun 0.5.30 → 0.5.32

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 (105) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/_packed_docs/CHANGELOG.md +60 -0
  3. package/_packed_docs/sdk/0.5.31-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +162 -0
  4. package/_packed_docs/sdk/0.5.31-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +167 -0
  5. package/_packed_docs/sdk/0.5.32-SDK/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +350 -0
  6. package/_packed_docs/sdk/0.5.32-SDK/345/274/200/345/217/221/344/270/216/347/247/273/346/244/215/346/214/207/345/215/227.md +319 -0
  7. package/_packed_docs/sdk/AUN_DOCS_GUIDE.md +12 -5
  8. package/_packed_docs/sdk/AUN/344/272/213/344/273/266/345/217/221/345/270/203/350/256/242/351/230/205/345/272/224/347/224/250/351/233/206/346/210/220/346/214/207/345/215/227.md +459 -0
  9. package/_packed_docs/sdk/AUN/344/272/213/344/273/266/345/217/221/345/270/203/350/256/242/351/230/205/345/274/200/345/217/221/347/247/273/346/244/215/346/214/207/345/215/227.md +554 -0
  10. package/_packed_docs/sdk/INDEX.md +27 -5
  11. package/_packed_docs/sdk//345/255/220AID/344/277/256/346/224/271agent.md/351/200/232/347/237/245Owner/345/234/272/346/231/257/346/214/207/345/215/227.md +234 -0
  12. package/dist/agent-md-schema.js +7 -6
  13. package/dist/agent-md-schema.js.map +1 -1
  14. package/dist/agent-md.d.ts +2 -0
  15. package/dist/agent-md.js +20 -6
  16. package/dist/agent-md.js.map +1 -1
  17. package/dist/aid-store.d.ts +1 -0
  18. package/dist/aid-store.js +1 -0
  19. package/dist/aid-store.js.map +1 -1
  20. package/dist/aid.js +1 -1
  21. package/dist/aid.js.map +1 -1
  22. package/dist/auth.js +1 -1
  23. package/dist/auth.js.map +1 -1
  24. package/dist/client/control-messages.d.ts +22 -7
  25. package/dist/client/control-messages.js +220 -185
  26. package/dist/client/control-messages.js.map +1 -1
  27. package/dist/client/delivery.d.ts +3 -0
  28. package/dist/client/delivery.js +67 -3
  29. package/dist/client/delivery.js.map +1 -1
  30. package/dist/client/group-state.d.ts +3 -0
  31. package/dist/client/group-state.js +48 -14
  32. package/dist/client/group-state.js.map +1 -1
  33. package/dist/client/lifecycle.js +12 -3
  34. package/dist/client/lifecycle.js.map +1 -1
  35. package/dist/client/rpc-pipeline.d.ts +9 -3
  36. package/dist/client/rpc-pipeline.js +61 -26
  37. package/dist/client/rpc-pipeline.js.map +1 -1
  38. package/dist/client/v2-e2ee.d.ts +13 -1
  39. package/dist/client/v2-e2ee.js +32 -19
  40. package/dist/client/v2-e2ee.js.map +1 -1
  41. package/dist/client.d.ts +18 -1
  42. package/dist/client.js +396 -140
  43. package/dist/client.js.map +1 -1
  44. package/dist/discovery.d.ts +1 -0
  45. package/dist/discovery.js +3 -1
  46. package/dist/discovery.js.map +1 -1
  47. package/dist/group-fs.js +1 -1
  48. package/dist/group-fs.js.map +1 -1
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.js +1 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/ownership-v21.d.ts +2 -2
  53. package/dist/ownership-v21.js +18 -21
  54. package/dist/ownership-v21.js.map +1 -1
  55. package/dist/ownership-workflow.js +6 -4
  56. package/dist/ownership-workflow.js.map +1 -1
  57. package/dist/pubsub/binding.d.ts +54 -0
  58. package/dist/pubsub/binding.js +343 -0
  59. package/dist/pubsub/binding.js.map +1 -0
  60. package/dist/pubsub/channel.d.ts +45 -0
  61. package/dist/pubsub/channel.js +137 -0
  62. package/dist/pubsub/channel.js.map +1 -0
  63. package/dist/pubsub/client.d.ts +93 -0
  64. package/dist/pubsub/client.js +318 -0
  65. package/dist/pubsub/client.js.map +1 -0
  66. package/dist/pubsub/credentials.d.ts +51 -0
  67. package/dist/pubsub/credentials.js +360 -0
  68. package/dist/pubsub/credentials.js.map +1 -0
  69. package/dist/pubsub/errors.d.ts +5 -0
  70. package/dist/pubsub/errors.js +6 -0
  71. package/dist/pubsub/errors.js.map +1 -0
  72. package/dist/pubsub/index.d.ts +48 -0
  73. package/dist/pubsub/index.js +152 -0
  74. package/dist/pubsub/index.js.map +1 -0
  75. package/dist/pubsub/scheduler.d.ts +58 -0
  76. package/dist/pubsub/scheduler.js +249 -0
  77. package/dist/pubsub/scheduler.js.map +1 -0
  78. package/dist/pubsub/service.d.ts +100 -0
  79. package/dist/pubsub/service.js +650 -0
  80. package/dist/pubsub/service.js.map +1 -0
  81. package/dist/pubsub/types.d.ts +119 -0
  82. package/dist/pubsub/types.js +2 -0
  83. package/dist/pubsub/types.js.map +1 -0
  84. package/dist/register-flow.js +1 -1
  85. package/dist/register-flow.js.map +1 -1
  86. package/dist/storage/lowlevel.js +49 -8
  87. package/dist/storage/lowlevel.js.map +1 -1
  88. package/dist/storage/read-cache.d.ts +7 -3
  89. package/dist/storage/read-cache.js +137 -18
  90. package/dist/storage/read-cache.js.map +1 -1
  91. package/dist/storage/vfs.d.ts +1 -0
  92. package/dist/storage/vfs.js +12 -4
  93. package/dist/storage/vfs.js.map +1 -1
  94. package/dist/tools/cross-sdk-agent.d.ts +1 -1
  95. package/dist/tools/cross-sdk-agent.js +4 -2
  96. package/dist/tools/cross-sdk-agent.js.map +1 -1
  97. package/dist/tools/pubsub-actor.d.ts +27 -0
  98. package/dist/tools/pubsub-actor.js +260 -0
  99. package/dist/tools/pubsub-actor.js.map +1 -0
  100. package/dist/transport.d.ts +26 -2
  101. package/dist/transport.js +182 -17
  102. package/dist/transport.js.map +1 -1
  103. package/dist/version.d.ts +1 -1
  104. package/dist/version.js +1 -1
  105. package/package.json +1 -1
@@ -0,0 +1,360 @@
1
+ import { buildRequestBinding, createCredential, digest, validateCredentialCapability, verifyCredentialChain, verifyCredentialSignature, verifyRegistrationReceipt } from '../org-protocol.js';
2
+ import { identifier } from './channel.js';
3
+ import { PubSubError } from './errors.js';
4
+ export class SDKCredentials {
5
+ sdk;
6
+ serviceAid;
7
+ options;
8
+ revoked = new Set();
9
+ verified = new Map();
10
+ generation = 0;
11
+ bodyBudget;
12
+ verifiedBytes = 0;
13
+ nextVerifiedExpiry = Infinity;
14
+ verifiedLimits = { items: 4096, bytes: 8 * 1024 * 1024 };
15
+ records;
16
+ loaded;
17
+ tail = Promise.resolve();
18
+ constructor(sdk, serviceAid = String(sdk.aid ?? ''), options = {}) {
19
+ this.sdk = sdk;
20
+ this.serviceAid = serviceAid;
21
+ this.options = options;
22
+ this.records = { version: 1, service_aid: serviceAid, issues: {}, revokes: {} };
23
+ }
24
+ async issue(subjectAid, scope, expiresAt, requestId) {
25
+ return this.serial(async () => {
26
+ await this.load();
27
+ try {
28
+ const input = { subject: subjectAid, scope, expires_at: expiresAt };
29
+ let record = this.records.issues[requestId];
30
+ if (record && digest(record.input) !== digest(input))
31
+ throw new PubSubError('REQUEST_CONFLICT');
32
+ if (!record) {
33
+ const signer = this.options.signer ? await this.options.signer(this.serviceAid) : await this.sdk._credentialRenewalSigner?.(this.serviceAid) ?? await this.sdk._credentialSigningIdentity?.(this.serviceAid) ?? (this.sdk.currentAid?.aid === this.serviceAid ? this.sdk.currentAid : null);
34
+ if (!signer)
35
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
36
+ const grant = await createCredential({ sub: subjectAid, aud: [this.serviceAid], delegate: false, exp: Math.floor(expiresAt / 1000), key_version: signer.certFingerprint, cap: scope.map(item => ({ ns: 'event', action: item.action, resource: item.event_name, constraints: [] })) }, signer);
37
+ record = { input: structuredClone(input), grant, request: this.request('credential.register', String(grant.cid), requestId, { credential: grant, registrar_aid: this.serviceAid }) };
38
+ this.records.issues[requestId] = record;
39
+ }
40
+ await this.save();
41
+ if (record.result)
42
+ return structuredClone(record.result);
43
+ let result;
44
+ if (Date.now() / 1000 >= Number(record.request.request_binding.exp)) {
45
+ const proof = await this.recoverRegistration(record);
46
+ result = { grant: record.grant, cid: record.grant.cid, receipt: null, registration_confirmation: proof };
47
+ }
48
+ else {
49
+ const response = await this.register(record);
50
+ const receipt = response?.registrationReceipt ?? response?.receipt;
51
+ if (!receipt || !receipt.signature)
52
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
53
+ const certificate = await this.certificate(this.authority, String(receipt.signature.cert_fingerprint));
54
+ await verifyRegistrationReceipt(receipt, record.grant, record.request, () => certificate, this.authority, Math.floor(Date.now() / 1000));
55
+ result = { grant: record.grant, cid: record.grant.cid, receipt };
56
+ }
57
+ record.result = structuredClone(result);
58
+ await this.save();
59
+ return structuredClone(result);
60
+ }
61
+ catch (error) {
62
+ if (error instanceof PubSubError)
63
+ throw error;
64
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE', String(error));
65
+ }
66
+ });
67
+ }
68
+ async verify(grant, subjectAid, scope, request, deadline = request?.expires_at) {
69
+ const generation = this.generation;
70
+ await this.beforeDeadline(deadline, () => this.load());
71
+ if (!scope.length || this.isRevoked(grant))
72
+ throw new PubSubError('FORBIDDEN');
73
+ await this.assertNotRevoked(grant, deadline);
74
+ this.cleanupVerified();
75
+ const facade = this.sdk.credential;
76
+ if (typeof facade?.verify !== 'function')
77
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
78
+ const identity = digest([subjectAid, grant]);
79
+ const previous = this.verified.get(identity)?.params;
80
+ if (!request && scope.some(item => !previous?.has(`${item.event_name}\0${item.action}`)))
81
+ throw new PubSubError('FORBIDDEN');
82
+ const documents = [grant, ...(Array.isArray(grant.proof_chain) ? grant.proof_chain : [])];
83
+ if (grant.sub !== subjectAid || documents.at(-1)?.iss !== this.serviceAid || documents.some(document => Number(document.exp) * 1000 <= Date.now()))
84
+ throw new PubSubError('FORBIDDEN');
85
+ const extra = this.options.verificationContext ? await this.beforeDeadline(deadline, () => this.options.verificationContext(subjectAid, request, grant)) : await this.context(grant, deadline);
86
+ if (typeof extra.resolveCertificate !== 'function' || typeof extra.resolveStatusProof !== 'function')
87
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
88
+ let proofUntil = Infinity;
89
+ for (const document of documents) {
90
+ const proof = extra.resolveStatusProof(String(document.cid));
91
+ if (!proof || typeof proof.proofExpiresAt !== 'number' || proof.proofExpiresAt * 1000 <= Date.now())
92
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
93
+ proofUntil = Math.min(proofUntil, proof.proofExpiresAt * 1000);
94
+ }
95
+ try {
96
+ for (const item of scope) {
97
+ const params = request ?? previous.get(`${item.event_name}\0${item.action}`);
98
+ const context = { ...extra, resolveCertificate: extra.resolveCertificate, audience: this.serviceAid, subject: subjectAid, rootIssuer: this.serviceAid, ns: 'event', action: item.action, resource: item.event_name, params };
99
+ if (request)
100
+ await this.beforeDeadline(deadline, () => facade.verify(grant, { ...context, method: `pubsub.${request.op}`, target: this.serviceAid, requestId: request.request_id, nonce: request.nonce, requestBinding: request.request_binding }));
101
+ else {
102
+ await this.beforeDeadline(deadline, async () => this.sdk._assertCredentialNotRevoked?.(grant));
103
+ await verifyCredentialChain(grant, context.resolveCertificate, cid => extra.resolveStatusProof(cid)?.status, Math.floor(Date.now() / 1000), this.serviceAid);
104
+ await validateCredentialCapability(grant, { ns: 'event', action: item.action, resource: item.event_name, params, now: Math.floor(Date.now() / 1000) });
105
+ }
106
+ }
107
+ }
108
+ catch (error) {
109
+ if (error instanceof PubSubError && error.code === 'TIMEOUT')
110
+ throw error;
111
+ throw new PubSubError('FORBIDDEN', String(error));
112
+ }
113
+ this.checkDeadline(deadline);
114
+ if (generation !== this.generation)
115
+ throw new PubSubError('SERVICE_CLOSED');
116
+ if (request) {
117
+ const saved = new Map(previous);
118
+ for (const item of scope)
119
+ saved.set(`${item.event_name}\0${item.action}`, this.verificationParams(grant, item, request));
120
+ const size = new TextEncoder().encode(JSON.stringify([identity, [...saved]])).byteLength + 128, old = this.verified.get(identity);
121
+ if ((this.bodyBudget && !this.bodyBudget(size - (old?.size ?? 0))) || (!old && this.verified.size >= this.verifiedLimits.items) || this.verifiedBytes + size - (old?.size ?? 0) > this.verifiedLimits.bytes)
122
+ throw new PubSubError('OVERLOADED');
123
+ const expiresAt = Math.min(...documents.map(document => Number(document.exp) * 1000));
124
+ this.verified.set(identity, { params: saved, size, expiresAt });
125
+ this.verifiedBytes += size - (old?.size ?? 0);
126
+ this.nextVerifiedExpiry = Math.min(this.nextVerifiedExpiry, expiresAt);
127
+ }
128
+ await this.assertNotRevoked(grant, deadline);
129
+ if (this.isRevoked(grant))
130
+ throw new PubSubError('FORBIDDEN');
131
+ return { cid: grant.cid, expires_at: Math.min(...documents.map(document => Number(document.exp) * 1000)), proof_expires_at: proofUntil };
132
+ }
133
+ verificationParams(grant, item, request) {
134
+ const result = {};
135
+ for (const capability of (grant.cap ?? [])) {
136
+ if (capability.ns !== 'event' || ![item.action, '*'].includes(String(capability.action)) || ![item.event_name, '*'].includes(String(capability.resource)))
137
+ continue;
138
+ for (const constraint of (capability.constraints ?? [])) {
139
+ const field = String(constraint.field ?? '');
140
+ if (['ns', 'action', 'resource', 'sub', 'delegation_depth', 'operation', 'valid_time', 'now'].includes(field))
141
+ continue;
142
+ const parts = (field.startsWith('params.') ? field.slice(7) : field).split('.');
143
+ let value = request, found = true;
144
+ for (const key of parts) {
145
+ if (!value || typeof value !== 'object' || !Object.hasOwn(value, key)) {
146
+ found = false;
147
+ break;
148
+ }
149
+ value = value[key];
150
+ }
151
+ if (!found)
152
+ continue;
153
+ let target = result;
154
+ for (const key of parts.slice(0, -1)) {
155
+ if (!Object.hasOwn(target, key))
156
+ Object.defineProperty(target, key, { value: {}, enumerable: true, writable: true, configurable: true });
157
+ target = target[key];
158
+ }
159
+ Object.defineProperty(target, parts.at(-1), { value: structuredClone(value), enumerable: true, writable: true, configurable: true });
160
+ }
161
+ }
162
+ return result;
163
+ }
164
+ cleanupVerified() { const now = Date.now(); if (now < this.nextVerifiedExpiry)
165
+ return; this.nextVerifiedExpiry = Infinity; for (const [key, entry] of this.verified) {
166
+ if (entry.expiresAt <= now) {
167
+ this.verified.delete(key);
168
+ this.verifiedBytes -= entry.size;
169
+ }
170
+ else
171
+ this.nextVerifiedExpiry = Math.min(this.nextVerifiedExpiry, entry.expiresAt);
172
+ } }
173
+ async checkVerified(grant, subjectAid, scope) {
174
+ this.cleanupVerified();
175
+ const previous = this.verified.get(digest([subjectAid, grant]))?.params;
176
+ try {
177
+ for (const item of scope) {
178
+ const params = previous?.get(`${item.event_name}\0${item.action}`);
179
+ if (!params)
180
+ throw new PubSubError('FORBIDDEN');
181
+ await validateCredentialCapability(grant, { ns: 'event', action: item.action, resource: item.event_name, params, now: Math.floor(Date.now() / 1000) });
182
+ }
183
+ }
184
+ catch {
185
+ throw new PubSubError('FORBIDDEN');
186
+ }
187
+ }
188
+ retainedBodyBytes() { return this.verifiedBytes; }
189
+ setBodyBudget(available) { this.bodyBudget = available; }
190
+ clearVerified() { this.generation++; this.verified.clear(); this.verifiedBytes = 0; this.nextVerifiedExpiry = Infinity; }
191
+ async assertNotRevoked(grant, deadline) { if (this.isRevoked(grant))
192
+ throw new PubSubError('REAUTH_REQUIRED'); if (typeof grant === 'string')
193
+ return; try {
194
+ await this.beforeDeadline(deadline, async () => { await this.sdk._assertCredentialNotRevoked?.(grant); });
195
+ }
196
+ catch (error) {
197
+ if (error instanceof PubSubError && error.code === 'TIMEOUT')
198
+ throw error;
199
+ throw new PubSubError('REAUTH_REQUIRED');
200
+ } }
201
+ async context(grant, deadline) {
202
+ const manager = this.sdk._getCredentialRenewal?.();
203
+ if (typeof manager?.statusFresh !== 'function')
204
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
205
+ const certificates = new Map();
206
+ const proofs = new Map();
207
+ for (const document of [grant, ...(Array.isArray(grant.proof_chain) ? grant.proof_chain : [])]) {
208
+ const proof = {};
209
+ await this.statusFresh(document, undefined, proof, deadline);
210
+ proofs.set(String(document.cid), proof);
211
+ const signature = document.signature;
212
+ const fingerprint = String(signature.cert_fingerprint);
213
+ certificates.set(fingerprint, await this.certificate(String(document.iss), fingerprint, deadline));
214
+ }
215
+ return { resolveCertificate: fingerprint => certificates.get(fingerprint) ?? null, resolveStatusProof: cid => proofs.get(cid) ?? null };
216
+ }
217
+ async revoke(cid, requestId) {
218
+ return this.serial(async () => {
219
+ await this.load();
220
+ try {
221
+ let record = this.records.revokes[requestId];
222
+ if (record && record.cid !== cid)
223
+ throw new PubSubError('REQUEST_CONFLICT');
224
+ this.revoked.add(cid);
225
+ if (!record) {
226
+ record = { cid, request: this.request('credential.revoke', cid, requestId, { credential_cid: cid, registrar_aid: this.serviceAid, reason_code: 'grant_withdrawn', cascade: true }) };
227
+ this.records.revokes[requestId] = record;
228
+ }
229
+ await this.save();
230
+ if (record.result)
231
+ return structuredClone(record.result);
232
+ const revoke = this.sdk.credential?.revoke;
233
+ if (typeof revoke !== 'function')
234
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
235
+ const result = await revoke.call(this.sdk.credential, structuredClone(record.request));
236
+ if (!result || result.credentialCid !== cid || result.status !== 'revoked')
237
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
238
+ record.result = structuredClone(result);
239
+ await this.save();
240
+ this.sdk._getCredentialRenewal?.().invalidateQueries?.();
241
+ return structuredClone(result);
242
+ }
243
+ catch (error) {
244
+ if (error instanceof PubSubError)
245
+ throw error;
246
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE', String(error));
247
+ }
248
+ });
249
+ }
250
+ get authority() { return 'credential.' + this.serviceAid.split('.').slice(1).join('.'); }
251
+ serial(operation) { const result = this.tail.then(operation); this.tail = result.catch(() => { }); return result; }
252
+ load() {
253
+ return this.loaded ??= (async () => {
254
+ const store = this.sdk._tokenStore;
255
+ let saved;
256
+ if (this.options.state?.load)
257
+ saved = await this.options.state.load();
258
+ else if (typeof store?._getMetadataStrict === 'function' || typeof store?.getMetadata === 'function') {
259
+ const value = await (store._getMetadataStrict?.(this.serviceAid, 'pubsub_credentials_v1') ?? store.getMetadata?.(this.serviceAid, 'pubsub_credentials_v1'));
260
+ saved = typeof value === 'string' && value !== '' ? JSON.parse(value) : value;
261
+ }
262
+ else
263
+ saved = (store?._loadMetadataStrict?.(this.serviceAid) ?? store?.loadMetadata?.(this.serviceAid))?.pubsub_credentials_v1;
264
+ if (saved) {
265
+ if (saved.version !== 1 || saved.service_aid !== this.serviceAid || !saved.issues || !saved.revokes)
266
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
267
+ this.records = structuredClone(saved);
268
+ }
269
+ for (const record of Object.values(this.records.revokes))
270
+ this.revoked.add(record.cid);
271
+ })().catch(error => { throw error instanceof PubSubError ? error : new PubSubError('CREDENTIAL_UNAVAILABLE', String(error)); });
272
+ }
273
+ async save() {
274
+ const value = structuredClone(this.records);
275
+ const store = this.sdk._tokenStore;
276
+ if (this.options.state?.save)
277
+ await this.options.state.save(value);
278
+ else if (typeof store?.setMetadata === 'function')
279
+ await store.setMetadata(this.serviceAid, 'pubsub_credentials_v1', JSON.stringify(value));
280
+ else
281
+ await store?.saveMetadata?.(this.serviceAid, { pubsub_credentials_v1: value });
282
+ }
283
+ async certificate(aid, fingerprint, deadline) {
284
+ const resolve = this.sdk._fetchServiceEventCertificate ?? this.sdk._resolveServiceEventCertificate;
285
+ if (typeof resolve !== 'function')
286
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
287
+ return this.beforeDeadline(deadline, () => resolve.call(this.sdk, aid, fingerprint));
288
+ }
289
+ async register(record) {
290
+ const pipeline = this.sdk._rpcPipeline;
291
+ if (typeof pipeline?._callWithSent === 'function')
292
+ return pipeline._callWithSent('credential.register', structuredClone(record.request), async () => {
293
+ const now = Math.floor(Date.now() / 1000), binding = record.request.request_binding;
294
+ if (now < Number(binding.iat) || now >= Number(binding.exp))
295
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
296
+ if (record.submitted_at === undefined) {
297
+ record.submitted_at = now;
298
+ record.submission_hash = digest(record.request);
299
+ await this.save();
300
+ }
301
+ });
302
+ if (typeof this.sdk.credential?.register !== 'function')
303
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
304
+ return this.sdk.credential.register(structuredClone(record.request));
305
+ }
306
+ async recoverRegistration(record) {
307
+ const binding = record.request.request_binding;
308
+ if (!Number.isInteger(record.submitted_at) || record.submitted_at < Number(binding.iat) || record.submitted_at >= Number(binding.exp) || record.submission_hash !== digest(record.request))
309
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
310
+ const signature = record.grant.signature;
311
+ const certificate = await this.certificate(String(record.grant.iss), String(signature.cert_fingerprint));
312
+ await verifyCredentialSignature(record.grant, () => certificate, Math.floor(Date.now() / 1000), this.serviceAid);
313
+ const proof = {};
314
+ await this.statusFresh(record.grant, record.submitted_at, proof);
315
+ if (proof.credentialStatus !== 'active' || Number(proof.proofExpiresAt) * 1000 <= Date.now() || Number(record.grant.exp) * 1000 <= Date.now())
316
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
317
+ return proof;
318
+ }
319
+ async statusFresh(grant, submittedAt, proof, deadline) {
320
+ this.checkDeadline(deadline);
321
+ const manager = this.sdk._getCredentialRenewal?.();
322
+ if (typeof manager?.statusFresh !== 'function')
323
+ throw new PubSubError('CREDENTIAL_UNAVAILABLE');
324
+ const scoped = Object.create(manager);
325
+ if (manager.ports?.call)
326
+ scoped.ports = { ...manager.ports,
327
+ call: async (method, params, onSent) => { this.checkDeadline(deadline); const result = await manager.ports.call(method, { ...params, _rpc_background_kind: 'event', _rpc_background: 'event', ...(deadline !== undefined ? { _rpc_deadline: deadline } : {}) }, onSent); this.checkDeadline(deadline); return result; },
328
+ certificate: (aid, fingerprint) => this.beforeDeadline(deadline, () => manager.ports.certificate(aid, fingerprint)) };
329
+ await manager.statusFresh.call(scoped, grant, this.serviceAid, false, submittedAt, proof);
330
+ this.checkDeadline(deadline);
331
+ }
332
+ checkDeadline(deadline) { if (deadline !== undefined && deadline <= Date.now())
333
+ throw new PubSubError('TIMEOUT'); }
334
+ async beforeDeadline(deadline, operation) {
335
+ this.checkDeadline(deadline);
336
+ if (deadline === undefined)
337
+ return operation();
338
+ let timer;
339
+ try {
340
+ const result = await Promise.race([operation(), new Promise((_, reject) => { timer = setTimeout(() => reject(new PubSubError('TIMEOUT')), Math.max(0, deadline - Date.now())); })]);
341
+ this.checkDeadline(deadline);
342
+ return result;
343
+ }
344
+ finally {
345
+ if (timer)
346
+ clearTimeout(timer);
347
+ }
348
+ }
349
+ isRevoked(grant) { if (typeof grant === 'string')
350
+ return this.revoked.has(grant); return [grant, ...(Array.isArray(grant.proof_chain) ? grant.proof_chain : [])].some(document => this.revoked.has(String(document.cid ?? ''))); }
351
+ async getIssuedScope(cid) { await this.load(); const record = Object.values(this.records.issues).find(item => item.grant.cid === cid); return record ? structuredClone(record.input.scope) : null; }
352
+ request(method, cid, requestId, fields) {
353
+ const params = { ...fields, request_id: requestId, nonce: identifier() };
354
+ const now = Math.floor(Date.now() / 1000);
355
+ params.request_binding = buildRequestBinding(method, 'credential.' + this.serviceAid.split('.').slice(1).join('.'), params, cid, String(params.nonce), requestId, now, now + 300);
356
+ return params;
357
+ }
358
+ async refreshRevocations() { await this.load(); this.sdk._getCredentialRenewal?.().invalidateQueries?.(); }
359
+ }
360
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/pubsub/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,yBAAyB,EAA6D,MAAM,oBAAoB,CAAC;AACzP,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAY1C,MAAM,OAAO,cAAc;IAMJ;IAAmB;IAAqD;IAL5E,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,QAAQ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,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;QAClL,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,KAAK,CAAC,kBAAkB,KAAoB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,CAAC;CAC3H"}
@@ -0,0 +1,5 @@
1
+ export declare class PubSubError extends Error {
2
+ readonly code: string;
3
+ readonly details?: unknown;
4
+ constructor(code: string, message?: string, details?: unknown);
5
+ }
@@ -0,0 +1,6 @@
1
+ export class PubSubError extends Error {
2
+ code;
3
+ details;
4
+ constructor(code, message, details) { super(message ? `${code}: ${message}` : code); this.name = 'PubSubError'; this.code = code; this.details = details; }
5
+ }
6
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/pubsub/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAAY,IAAI,CAAS;IAAU,OAAO,CAAW;IAAC,YAAY,IAAY,EAAE,OAAgB,EAAE,OAAiB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAAE"}
@@ -0,0 +1,48 @@
1
+ import { EventService as EventBusCore } from './service.js';
2
+ import { type EventServiceBindingOptions } from './binding.js';
3
+ import { PubSubClient, type PublishOptions } from './client.js';
4
+ import { type SDKCredentialsOptions } from './credentials.js';
5
+ import { type PubSubSDK } from './channel.js';
6
+ import type { CredentialProvider, EventAllowlist, EventCatalog, EventServiceLimits, EventServiceOptions, JsonMap } from './types.js';
7
+ export { PubSubError } from './errors.js';
8
+ export type * from './types.js';
9
+ export type { PublishOptions } from './client.js';
10
+ export type EventRole = 'pub' | 'sub' | 'bus';
11
+ export interface EventServiceStartOptions {
12
+ catalog?: EventCatalog;
13
+ allowlist?: EventAllowlist;
14
+ credentials?: CredentialProvider;
15
+ credentialOptions?: SDKCredentialsOptions;
16
+ state?: EventServiceOptions['state'];
17
+ clock?: () => number;
18
+ limits?: EventServiceLimits;
19
+ bindingOptions?: EventServiceBindingOptions;
20
+ }
21
+ export declare class EventService {
22
+ readonly sdk: PubSubSDK;
23
+ private readonly buses;
24
+ constructor(sdk: PubSubSDK);
25
+ private bindBus;
26
+ private bound;
27
+ private client;
28
+ private serialize;
29
+ start(bus_aid: string, options?: EventServiceStartOptions): Promise<this>;
30
+ drain(bus_aid: string): Promise<void>;
31
+ close(bus_aid: string): Promise<void>;
32
+ private _closeAll;
33
+ updateConfig(bus_aid: string, config: Parameters<EventBusCore['updateConfig']>[0]): Promise<void>;
34
+ authorize(bus_aid: string, role: 'pub' | 'sub', authMode: 'allowlist' | 'credential', events: string[], credential?: JsonMap): Promise<JsonMap>;
35
+ renew(bus_aid: string): Promise<JsonMap>;
36
+ publish(bus_aid: string, eventName: string, data: JsonMap, options?: PublishOptions): Promise<string>;
37
+ waitPublished(bus_aid: string, eventId: string): Promise<JsonMap>;
38
+ onPublish(bus_aid: string, handler: Parameters<PubSubClient['onPublish']>[0]): () => boolean;
39
+ subscribe(bus_aid: string, events: string[]): Promise<JsonMap>;
40
+ unsubscribe(bus_aid: string, events: string[]): Promise<JsonMap>;
41
+ nextEvent(bus_aid: string, timeout?: number): Promise<JsonMap>;
42
+ onEvent(bus_aid: string, handler: Parameters<PubSubClient['onEvent']>[0]): () => boolean;
43
+ catalog(bus_aid: string, params?: JsonMap): Promise<JsonMap>;
44
+ stats(bus_aid: string, params?: JsonMap): Promise<JsonMap>;
45
+ issueGrant(bus_aid: string, params: JsonMap): Promise<JsonMap>;
46
+ revokeGrant(bus_aid: string, params: JsonMap): Promise<JsonMap>;
47
+ private manage;
48
+ }
@@ -0,0 +1,152 @@
1
+ import { EventService as EventBusCore } from './service.js';
2
+ import { EventServiceBinding } from './binding.js';
3
+ import { PubSubClient } from './client.js';
4
+ import { SDKCredentials } from './credentials.js';
5
+ import { PubSubError } from './errors.js';
6
+ import { identifier } from './channel.js';
7
+ export { PubSubError } from './errors.js';
8
+ const bindings = new WeakMap();
9
+ function jsonValue(value, parents = new Set()) {
10
+ if (value === null || typeof value === 'string' || typeof value === 'boolean')
11
+ return true;
12
+ if (typeof value === 'number')
13
+ return Number.isFinite(value);
14
+ if (typeof value !== 'object' || parents.has(value))
15
+ return false;
16
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
17
+ return false;
18
+ if (Object.getOwnPropertySymbols(value).length)
19
+ return false;
20
+ parents.add(value);
21
+ const valid = Array.isArray(value) ? Array.from(value).every(item => jsonValue(item, parents)) : Object.values(value).every(item => jsonValue(item, parents));
22
+ parents.delete(value);
23
+ return valid;
24
+ }
25
+ export class EventService {
26
+ sdk;
27
+ buses;
28
+ constructor(sdk) {
29
+ this.sdk = sdk;
30
+ let buses = bindings.get(sdk);
31
+ if (!buses) {
32
+ buses = new Map();
33
+ bindings.set(sdk, buses);
34
+ }
35
+ this.buses = buses;
36
+ }
37
+ bindBus(bus_aid, role, options = {}) {
38
+ if (this.sdk._closing)
39
+ throw new PubSubError('CLOSED');
40
+ if (!['pub', 'sub', 'bus'].includes(role))
41
+ throw new PubSubError('INVALID_ROLE');
42
+ const previous = this.buses.get(bus_aid);
43
+ if (previous) {
44
+ if (previous.role !== role)
45
+ throw new PubSubError('BUS_ROLE_CONFLICT');
46
+ return this;
47
+ }
48
+ if (role === 'bus') {
49
+ if (bus_aid !== this.sdk.aid)
50
+ throw new PubSubError('SERVICE_IDENTITY_MISMATCH');
51
+ const service = new EventBusCore(bus_aid, options.catalog ?? {}, options.allowlist ?? {}, {
52
+ send: async () => ({}), credentials: options.credentials ?? new SDKCredentials(this.sdk, bus_aid, options.credentialOptions),
53
+ clock: options.clock, state: options.state, limits: options.limits,
54
+ });
55
+ this.buses.set(bus_aid, { role, service, binding: new EventServiceBinding(service, this.sdk, options.bindingOptions), running: false, lifecycle: Promise.resolve() });
56
+ }
57
+ else {
58
+ this.buses.set(bus_aid, { role, client: new PubSubClient(this.sdk, bus_aid, { clock: options.clock, limits: options.limits }), lifecycle: Promise.resolve() });
59
+ }
60
+ return this;
61
+ }
62
+ bound(bus_aid, roles = ['pub', 'sub', 'bus']) {
63
+ const bound = this.buses.get(bus_aid);
64
+ if (!bound)
65
+ throw new PubSubError('BUS_NOT_BOUND');
66
+ if (!roles.includes(bound.role))
67
+ throw new PubSubError('ROLE_MISMATCH');
68
+ return bound;
69
+ }
70
+ client(bus_aid, role) { return this.bound(bus_aid, role ? [role] : ['pub', 'sub']).client; }
71
+ serialize(bound, action) { const result = bound.lifecycle.then(action); bound.lifecycle = result.catch(() => { }); return result; }
72
+ async start(bus_aid, options = {}) {
73
+ if (this.sdk._closing)
74
+ throw new PubSubError('CLOSED');
75
+ const created = !this.buses.has(bus_aid);
76
+ if (created)
77
+ this.bindBus(bus_aid, 'bus', options);
78
+ const bound = this.bound(bus_aid);
79
+ await this.serialize(bound, async () => {
80
+ if (this.sdk._closing)
81
+ throw new PubSubError('CLOSED');
82
+ if (bound.role !== 'bus') {
83
+ await bound.client.start();
84
+ bound.closed = false;
85
+ return;
86
+ }
87
+ try {
88
+ await bound.binding.start();
89
+ bound.running = true;
90
+ }
91
+ catch (error) {
92
+ if (created && this.buses.get(bus_aid) === bound) {
93
+ await bound.binding.close().catch(() => { });
94
+ this.buses.delete(bus_aid);
95
+ }
96
+ throw error;
97
+ }
98
+ });
99
+ return this;
100
+ }
101
+ async drain(bus_aid) { const bound = this.bound(bus_aid); await bound.lifecycle; if (bound.role === 'bus')
102
+ await bound.binding.drain();
103
+ else
104
+ await bound.client.drain(); }
105
+ async close(bus_aid) { const bound = this.bound(bus_aid); await this.serialize(bound, async () => { if (bound.role === 'bus') {
106
+ bound.running = false;
107
+ await bound.binding.close();
108
+ }
109
+ else {
110
+ bound.closed = true;
111
+ await bound.client.close();
112
+ } }); }
113
+ async _closeAll() { await Promise.allSettled([...this.buses.keys()].map(bus_aid => this.close(bus_aid))); }
114
+ async updateConfig(bus_aid, config) { await this.bound(bus_aid, ['bus']).service.updateConfig(config); }
115
+ async authorize(bus_aid, role, authMode, events, credential) {
116
+ if (role !== 'pub' && role !== 'sub')
117
+ throw new PubSubError('INVALID_ROLE');
118
+ this.bindBus(bus_aid, role);
119
+ await this.start(bus_aid);
120
+ const bound = this.bound(bus_aid, ['pub', 'sub']);
121
+ return bound.client.authorize(authMode, events, [role === 'pub' ? 'publish' : 'subscribe'], credential);
122
+ }
123
+ async renew(bus_aid) { return this.client(bus_aid).renew(); }
124
+ async publish(bus_aid, eventName, data, options = {}) { const client = this.client(bus_aid, 'pub'); if (data === null || Array.isArray(data) || typeof data !== 'object' || !jsonValue(data))
125
+ throw new PubSubError('INVALID_CONTENT'); return client.publish(eventName, data, options); }
126
+ async waitPublished(bus_aid, eventId) { return this.client(bus_aid, 'pub').waitPublished(eventId); }
127
+ onPublish(bus_aid, handler) { return this.client(bus_aid, 'pub').onPublish(handler); }
128
+ async subscribe(bus_aid, events) { return this.client(bus_aid, 'sub').subscribe(events); }
129
+ async unsubscribe(bus_aid, events) { return this.client(bus_aid, 'sub').unsubscribe(events); }
130
+ async nextEvent(bus_aid, timeout) { return { ...await this.client(bus_aid, 'sub').nextEvent(timeout), bus_aid }; }
131
+ onEvent(bus_aid, handler) { return this.client(bus_aid, 'sub').onEvent(event => handler({ ...event, bus_aid })); }
132
+ async catalog(bus_aid, params = {}) { if (this.sdk._closing)
133
+ throw new PubSubError('CLOSED'); const bound = this.bound(bus_aid); return bound.role !== 'bus' ? bound.client.catalog(params) : this.manage(bus_aid, 'catalog', params); }
134
+ async stats(bus_aid, params = {}) { return this.manage(bus_aid, 'stats', params); }
135
+ async issueGrant(bus_aid, params) { return this.manage(bus_aid, 'issue_grant', params); }
136
+ async revokeGrant(bus_aid, params) { return this.manage(bus_aid, 'revoke_grant', params); }
137
+ async manage(bus_aid, op, params) {
138
+ if (this.sdk._closing)
139
+ throw new PubSubError('CLOSED');
140
+ const bound = this.bound(bus_aid, ['bus']);
141
+ await bound.lifecycle;
142
+ if (!bound.running)
143
+ throw new PubSubError('CLOSED');
144
+ const now = bound.service.clock();
145
+ const request = { ...structuredClone(params), type: 'app.pubsub.v1', op, service_aid: bus_aid, request_id: typeof params.request_id === 'string' ? params.request_id : identifier(), nonce: typeof params.nonce === 'string' ? params.nonce : identifier(), issued_at: now, expires_at: Number(params.expires_at ?? now + 60_000) };
146
+ const result = await bound.service._handleLocal(request);
147
+ if (op === 'catalog' && Array.isArray(result.items) && result.events === undefined)
148
+ result.events = structuredClone(result.items);
149
+ return result;
150
+ }
151
+ }
152
+ //# sourceMappingURL=index.js.map