@dxos/credentials 0.6.12 → 0.6.13-main.548ca8d

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.
@@ -0,0 +1,1843 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // packages/core/halo/credentials/src/invitations.ts
4
+ var defaultSecretProvider = async () => Buffer.from("0000");
5
+ var defaultSecretValidator = async (invitation, secret) => true;
6
+
7
+ // packages/core/halo/credentials/src/passcode.ts
8
+ var generatePasscode = (length = 4) => {
9
+ let passcode = "";
10
+ for (let i = 0; i < length; i++) {
11
+ passcode += `${Math.floor(Math.random() * 10)}`;
12
+ }
13
+ return passcode;
14
+ };
15
+
16
+ // packages/core/halo/credentials/src/credentials/signing.ts
17
+ import stableStringify from "json-stable-stringify";
18
+ import { PublicKey } from "@dxos/keys";
19
+ import { Timeframe } from "@dxos/timeframe";
20
+ import { arrayToBuffer } from "@dxos/util";
21
+ var getCredentialProofPayload = (credential) => {
22
+ const copy = {
23
+ ...credential,
24
+ proof: {
25
+ ...credential.proof,
26
+ value: new Uint8Array(),
27
+ chain: void 0
28
+ }
29
+ };
30
+ if (copy.parentCredentialIds?.length === 0) {
31
+ delete copy.parentCredentialIds;
32
+ }
33
+ delete copy.id;
34
+ return Buffer.from(canonicalStringify(copy));
35
+ };
36
+ var canonicalStringify = (obj) => stableStringify(obj, {
37
+ /* The point of signing and verifying is not that the internal, private state of the objects be
38
+ * identical, but that the public contents can be verified not to have been altered. For that reason,
39
+ * really private fields (indicated by '__') are not included in the signature.
40
+ * This gives a mechanism for attaching other attributes to an object without breaking the signature.
41
+ * We also skip @type.
42
+ */
43
+ // TODO(dmaretskyi): Should we actually skip the @type field?
44
+ replacer: function(key, value) {
45
+ if (key.toString().startsWith("__") || key.toString() === "@type") {
46
+ return void 0;
47
+ }
48
+ if (value === null) {
49
+ return void 0;
50
+ }
51
+ const original = this[key];
52
+ if (value) {
53
+ if (PublicKey.isPublicKey(value)) {
54
+ return value.toHex();
55
+ }
56
+ if (Buffer.isBuffer(value)) {
57
+ return value.toString("hex");
58
+ }
59
+ if (value instanceof Uint8Array) {
60
+ return arrayToBuffer(value).toString("hex");
61
+ }
62
+ if (value.data && value.type === "Buffer") {
63
+ return Buffer.from(value).toString("hex");
64
+ }
65
+ if (original instanceof Timeframe) {
66
+ return original.frames().reduce((frames, [key2, seq]) => {
67
+ frames[truncateKey(key2)] = seq;
68
+ return frames;
69
+ }, {});
70
+ }
71
+ }
72
+ return value;
73
+ }
74
+ });
75
+ var truncateKey = (key) => {
76
+ const str = key.toHex();
77
+ return `${str.substring(0, 4)}...${str.substring(str.length - 4)}`;
78
+ };
79
+
80
+ // packages/core/halo/credentials/src/presentations/signing.ts
81
+ var getPresentationProofPayload = (credentials, proof) => {
82
+ const copy = {
83
+ credentials: credentials.map((credential) => removeEmptyParentCredentialIds(credential)),
84
+ proof: {
85
+ ...proof,
86
+ value: new Uint8Array(),
87
+ chain: void 0
88
+ }
89
+ };
90
+ return Buffer.from(canonicalStringify(copy));
91
+ };
92
+ var removeEmptyParentCredentialIds = (credential) => {
93
+ const copy = {
94
+ ...credential,
95
+ proof: credential.proof ? {
96
+ ...credential.proof,
97
+ chain: credential.proof.chain ? {
98
+ credential: removeEmptyParentCredentialIds(credential.proof.chain.credential)
99
+ } : void 0
100
+ } : void 0
101
+ };
102
+ if (copy.parentCredentialIds?.length === 0) {
103
+ delete copy.parentCredentialIds;
104
+ }
105
+ return copy;
106
+ };
107
+
108
+ // packages/core/halo/credentials/src/credentials/assertions.ts
109
+ var getCredentialAssertion = (credential) => credential.subject.assertion;
110
+ var isValidAuthorizedDeviceCredential = (credential, identityKey, deviceKey) => {
111
+ const assertion = getCredentialAssertion(credential);
112
+ return credential.subject.id.equals(deviceKey) && credential.issuer.equals(identityKey) && assertion["@type"] === "dxos.halo.credentials.AuthorizedDevice" && assertion.identityKey.equals(identityKey) && assertion.deviceKey.equals(deviceKey);
113
+ };
114
+ var checkCredentialType = (credential, type) => credential.subject.assertion["@type"] === type;
115
+ var credentialTypeFilter = (type) => (credential) => checkCredentialType(credential, type);
116
+
117
+ // packages/core/halo/credentials/src/credentials/credential-factory.ts
118
+ import { subtleCrypto } from "@dxos/crypto";
119
+ import { invariant } from "@dxos/invariant";
120
+ import { PublicKey as PublicKey2 } from "@dxos/keys";
121
+
122
+ // packages/core/halo/credentials/src/credentials/verifier.ts
123
+ import { verifySignature } from "@dxos/crypto";
124
+ var SIGNATURE_TYPE_ED25519 = "ED25519Signature";
125
+ var verifyCredential = async (credential) => {
126
+ if (credential.parentCredentialIds?.length === 0) {
127
+ delete credential.parentCredentialIds;
128
+ }
129
+ if (!credential.issuer.equals(credential.proof.signer)) {
130
+ if (!credential.proof.chain) {
131
+ return {
132
+ kind: "fail",
133
+ errors: [
134
+ "Delegated credential is missing credential chain."
135
+ ]
136
+ };
137
+ }
138
+ const result2 = await verifyChain(credential.proof.chain, credential.issuer, credential.proof.signer);
139
+ if (result2.kind === "fail") {
140
+ return result2;
141
+ }
142
+ }
143
+ const result = await verifyCredentialSignature(credential);
144
+ if (result.kind === "fail") {
145
+ return result;
146
+ }
147
+ return {
148
+ kind: "pass"
149
+ };
150
+ };
151
+ var verifyCredentialSignature = async (credential) => {
152
+ if (credential.proof.type !== SIGNATURE_TYPE_ED25519) {
153
+ return {
154
+ kind: "fail",
155
+ errors: [
156
+ `Invalid signature type: ${credential.proof.type}`
157
+ ]
158
+ };
159
+ }
160
+ const signData = getCredentialProofPayload(credential);
161
+ if (!await verifySignature(credential.proof.signer, signData, credential.proof.value)) {
162
+ return {
163
+ kind: "fail",
164
+ errors: [
165
+ "Invalid signature"
166
+ ]
167
+ };
168
+ }
169
+ return {
170
+ kind: "pass"
171
+ };
172
+ };
173
+ var verifyChain = async (chain, authority, subject) => {
174
+ const result = await verifyCredential(chain.credential);
175
+ if (result.kind === "fail") {
176
+ return result;
177
+ }
178
+ if (!isValidAuthorizedDeviceCredential(chain.credential, authority, subject)) {
179
+ return {
180
+ kind: "fail",
181
+ errors: [
182
+ `Invalid credential chain: invalid assertion for key: ${subject}`
183
+ ]
184
+ };
185
+ }
186
+ return {
187
+ kind: "pass"
188
+ };
189
+ };
190
+
191
+ // packages/core/halo/credentials/src/credentials/credential-factory.ts
192
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/credentials/credential-factory.ts";
193
+ var createCredential = async ({ signer, issuer, subject, assertion, signingKey, chain, nonce, parentCredentialIds }) => {
194
+ invariant(assertion["@type"], "Invalid assertion.", {
195
+ F: __dxlog_file,
196
+ L: 48,
197
+ S: void 0,
198
+ A: [
199
+ "assertion['@type']",
200
+ "'Invalid assertion.'"
201
+ ]
202
+ });
203
+ invariant(!!signingKey === !!chain, "Chain must be provided if and only if the signing key differs from the issuer.", {
204
+ F: __dxlog_file,
205
+ L: 49,
206
+ S: void 0,
207
+ A: [
208
+ "!!signingKey === !!chain",
209
+ "'Chain must be provided if and only if the signing key differs from the issuer.'"
210
+ ]
211
+ });
212
+ if (chain) {
213
+ const result = await verifyChain(chain, issuer, signingKey);
214
+ invariant(result.kind === "pass", "Invalid chain.", {
215
+ F: __dxlog_file,
216
+ L: 52,
217
+ S: void 0,
218
+ A: [
219
+ "result.kind === 'pass'",
220
+ "'Invalid chain.'"
221
+ ]
222
+ });
223
+ }
224
+ const credential = {
225
+ issuer,
226
+ issuanceDate: /* @__PURE__ */ new Date(),
227
+ subject: {
228
+ id: subject,
229
+ assertion
230
+ },
231
+ parentCredentialIds,
232
+ proof: {
233
+ type: SIGNATURE_TYPE_ED25519,
234
+ creationDate: /* @__PURE__ */ new Date(),
235
+ signer: signingKey ?? issuer,
236
+ value: new Uint8Array(),
237
+ nonce
238
+ }
239
+ };
240
+ const signedPayload = getCredentialProofPayload(credential);
241
+ credential.proof.value = await signer.sign(signingKey ?? issuer, signedPayload);
242
+ if (chain) {
243
+ credential.proof.chain = chain;
244
+ }
245
+ credential.id = PublicKey2.from(await subtleCrypto.digest("SHA-256", signedPayload));
246
+ return credential;
247
+ };
248
+ var createCredentialMessage = (credential) => {
249
+ return {
250
+ "@type": "dxos.echo.feed.CredentialsMessage",
251
+ credential
252
+ };
253
+ };
254
+ var createCredentialSignerWithKey = (signer, issuer) => ({
255
+ getIssuer: () => issuer,
256
+ createCredential: ({ subject, assertion, nonce, parentCredentialIds }) => createCredential({
257
+ signer,
258
+ issuer,
259
+ subject,
260
+ assertion,
261
+ nonce,
262
+ parentCredentialIds
263
+ })
264
+ });
265
+ var createCredentialSignerWithChain = (signer, chain, signingKey) => ({
266
+ getIssuer: () => chain.credential.issuer,
267
+ createCredential: ({ subject, assertion, nonce, parentCredentialIds }) => createCredential({
268
+ signer,
269
+ issuer: chain.credential.issuer,
270
+ signingKey,
271
+ chain,
272
+ subject,
273
+ assertion,
274
+ nonce,
275
+ parentCredentialIds
276
+ })
277
+ });
278
+
279
+ // packages/core/halo/credentials/src/credentials/credential-generator.ts
280
+ import { AdmittedFeed, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
281
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
282
+ var CredentialGenerator = class {
283
+ constructor(_signer, _identityKey, _deviceKey) {
284
+ this._signer = _signer;
285
+ this._identityKey = _identityKey;
286
+ this._deviceKey = _deviceKey;
287
+ }
288
+ /**
289
+ * Create genesis messages for new Space.
290
+ */
291
+ async createSpaceGenesis(spaceKey, controlKey, creatorProfile) {
292
+ return [
293
+ await createCredential({
294
+ signer: this._signer,
295
+ issuer: spaceKey,
296
+ subject: spaceKey,
297
+ assertion: {
298
+ "@type": "dxos.halo.credentials.SpaceGenesis",
299
+ spaceKey
300
+ }
301
+ }),
302
+ await createCredential({
303
+ signer: this._signer,
304
+ issuer: spaceKey,
305
+ subject: this._identityKey,
306
+ assertion: {
307
+ "@type": "dxos.halo.credentials.SpaceMember",
308
+ spaceKey,
309
+ role: SpaceMember.Role.ADMIN,
310
+ profile: creatorProfile,
311
+ genesisFeedKey: controlKey
312
+ }
313
+ }),
314
+ await this.createFeedAdmission(spaceKey, controlKey, AdmittedFeed.Designation.CONTROL)
315
+ ];
316
+ }
317
+ /**
318
+ * Create invitation.
319
+ * Admit identity and control and data feeds.
320
+ */
321
+ // TODO(burdon): Reconcile with above (esp. Signer).
322
+ async createMemberInvitation(spaceKey, identityKey, deviceKey, controlKey, dataKey, genesisFeedKey) {
323
+ return [
324
+ await createCredential({
325
+ signer: this._signer,
326
+ issuer: this._identityKey,
327
+ subject: identityKey,
328
+ assertion: {
329
+ "@type": "dxos.halo.credentials.SpaceMember",
330
+ spaceKey,
331
+ role: SpaceMember.Role.EDITOR,
332
+ genesisFeedKey
333
+ }
334
+ }),
335
+ await this.createFeedAdmission(spaceKey, controlKey, AdmittedFeed.Designation.CONTROL),
336
+ await this.createFeedAdmission(spaceKey, dataKey, AdmittedFeed.Designation.DATA)
337
+ ];
338
+ }
339
+ /**
340
+ * Add device to space.
341
+ */
342
+ // TODO(burdon): Reconcile with below.
343
+ async createDeviceAuthorization(deviceKey) {
344
+ return createCredential({
345
+ signer: this._signer,
346
+ issuer: this._identityKey,
347
+ subject: deviceKey,
348
+ assertion: {
349
+ "@type": "dxos.halo.credentials.AuthorizedDevice",
350
+ identityKey: this._identityKey,
351
+ deviceKey
352
+ }
353
+ });
354
+ }
355
+ /**
356
+ * Add device metadata.
357
+ */
358
+ async createDeviceProfile(profile) {
359
+ return createCredential({
360
+ signer: this._signer,
361
+ issuer: this._identityKey,
362
+ subject: this._deviceKey,
363
+ assertion: {
364
+ "@type": "dxos.halo.credentials.DeviceProfile",
365
+ profile
366
+ }
367
+ });
368
+ }
369
+ /**
370
+ * Add feed to space.
371
+ */
372
+ async createFeedAdmission(spaceKey, feedKey, designation) {
373
+ return createCredential({
374
+ signer: this._signer,
375
+ issuer: this._identityKey,
376
+ subject: feedKey,
377
+ assertion: {
378
+ "@type": "dxos.halo.credentials.AdmittedFeed",
379
+ spaceKey,
380
+ identityKey: this._identityKey,
381
+ deviceKey: this._deviceKey,
382
+ designation
383
+ }
384
+ });
385
+ }
386
+ async createProfileCredential(profile) {
387
+ return createCredential({
388
+ signer: this._signer,
389
+ issuer: this._identityKey,
390
+ subject: this._identityKey,
391
+ assertion: {
392
+ "@type": "dxos.halo.credentials.IdentityProfile",
393
+ profile
394
+ }
395
+ });
396
+ }
397
+ async createEpochCredential(spaceKey) {
398
+ return createCredential({
399
+ signer: this._signer,
400
+ issuer: this._identityKey,
401
+ subject: spaceKey,
402
+ assertion: {
403
+ "@type": "dxos.halo.credentials.Epoch",
404
+ number: 0,
405
+ timeframe: new Timeframe2()
406
+ }
407
+ });
408
+ }
409
+ };
410
+ var createDeviceAuthorization = async (signer, identityKey, deviceKey) => {
411
+ const credentials = await Promise.all([
412
+ await signer.createCredential({
413
+ subject: deviceKey,
414
+ assertion: {
415
+ "@type": "dxos.halo.credentials.AuthorizedDevice",
416
+ identityKey,
417
+ deviceKey
418
+ }
419
+ })
420
+ ]);
421
+ return credentials.map((credential) => ({
422
+ "@type": "dxos.echo.feed.CredentialsMessage",
423
+ credential
424
+ }));
425
+ };
426
+ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, role = SpaceMember.Role.ADMIN, membershipChainHeads = [], profile, invitationCredentialId) => {
427
+ const credentials = await Promise.all([
428
+ await signer.createCredential({
429
+ subject: identityKey,
430
+ parentCredentialIds: membershipChainHeads,
431
+ assertion: {
432
+ "@type": "dxos.halo.credentials.SpaceMember",
433
+ spaceKey,
434
+ role,
435
+ profile,
436
+ genesisFeedKey,
437
+ invitationCredentialId
438
+ }
439
+ })
440
+ ]);
441
+ return credentials.map((credential) => ({
442
+ credential: {
443
+ credential
444
+ }
445
+ }));
446
+ };
447
+ var createDelegatedSpaceInvitationCredential = async (signer, subject, invitation) => {
448
+ const credential = await signer.createCredential({
449
+ subject,
450
+ assertion: {
451
+ "@type": "dxos.halo.invitations.DelegateSpaceInvitation",
452
+ invitationId: invitation.invitationId,
453
+ authMethod: invitation.authMethod,
454
+ swarmKey: invitation.swarmKey,
455
+ role: invitation.role,
456
+ guestKey: invitation.guestKey,
457
+ expiresOn: invitation.expiresOn,
458
+ multiUse: invitation.multiUse
459
+ }
460
+ });
461
+ return {
462
+ credential: {
463
+ credential
464
+ }
465
+ };
466
+ };
467
+ var createCancelDelegatedSpaceInvitationCredential = async (signer, subject, invitationCredentialId) => {
468
+ const credential = await signer.createCredential({
469
+ subject,
470
+ assertion: {
471
+ "@type": "dxos.halo.invitations.CancelDelegatedInvitation",
472
+ credentialId: invitationCredentialId
473
+ }
474
+ });
475
+ return {
476
+ credential: {
477
+ credential
478
+ }
479
+ };
480
+ };
481
+
482
+ // packages/core/halo/credentials/src/presentations/presentation.ts
483
+ var signPresentation = async ({ presentation, signer, signerKey, chain, nonce }) => {
484
+ const proof = {
485
+ type: SIGNATURE_TYPE_ED25519,
486
+ value: new Uint8Array(),
487
+ creationDate: /* @__PURE__ */ new Date(),
488
+ signer: signerKey,
489
+ nonce
490
+ };
491
+ const signedPayload = getPresentationProofPayload(presentation.credentials ?? [], proof);
492
+ proof.value = await signer.sign(signerKey, signedPayload);
493
+ if (chain) {
494
+ proof.chain = chain;
495
+ }
496
+ return {
497
+ credentials: presentation.credentials,
498
+ proofs: [
499
+ ...presentation.proofs ?? [],
500
+ proof
501
+ ]
502
+ };
503
+ };
504
+
505
+ // packages/core/halo/credentials/src/presentations/verifier.ts
506
+ import { verifySignature as verifySignature2 } from "@dxos/crypto";
507
+ var verifyPresentation = async (presentation) => {
508
+ const errors = [];
509
+ const credentialsVerifications = await Promise.all(presentation.credentials?.map((credential) => verifyCredential(credential)) ?? []);
510
+ for (const verification of credentialsVerifications) {
511
+ if (verification.kind === "fail") {
512
+ errors.push(...verification.errors);
513
+ }
514
+ }
515
+ const proofVerification = await Promise.all(presentation.proofs?.map(async (proof) => {
516
+ const chainVerification = await verifyPresentationChain(presentation, proof);
517
+ if (chainVerification.kind === "fail") {
518
+ return chainVerification;
519
+ }
520
+ const signatureVerification = await verifyPresentationSignature(presentation, proof);
521
+ if (signatureVerification.kind === "fail") {
522
+ return signatureVerification;
523
+ }
524
+ return {
525
+ kind: "pass"
526
+ };
527
+ }) ?? []);
528
+ for (const verification of proofVerification) {
529
+ if (verification.kind === "fail") {
530
+ errors.push(...verification.errors);
531
+ }
532
+ }
533
+ if (errors.length === 0) {
534
+ return {
535
+ kind: "pass"
536
+ };
537
+ }
538
+ {
539
+ return {
540
+ kind: "fail",
541
+ errors
542
+ };
543
+ }
544
+ };
545
+ var verifyPresentationChain = async (presentation, proof) => {
546
+ for (const credential of presentation.credentials ?? []) {
547
+ if (!credential.issuer.equals(proof.signer)) {
548
+ if (!proof.chain) {
549
+ return {
550
+ kind: "fail",
551
+ errors: [
552
+ "Delegated credential is missing credential chain."
553
+ ]
554
+ };
555
+ }
556
+ const chainVerification = await verifyChain(proof.chain, credential.subject.id, proof.signer);
557
+ if (chainVerification.kind === "fail") {
558
+ return chainVerification;
559
+ }
560
+ }
561
+ }
562
+ return {
563
+ kind: "pass"
564
+ };
565
+ };
566
+ var verifyPresentationSignature = async (presentation, proof) => {
567
+ if (proof.type !== SIGNATURE_TYPE_ED25519) {
568
+ return {
569
+ kind: "fail",
570
+ errors: [
571
+ `Invalid signature type: ${proof.type}`
572
+ ]
573
+ };
574
+ }
575
+ const signData = getPresentationProofPayload(presentation.credentials ?? [], proof);
576
+ if (!await verifySignature2(proof.signer, signData, proof.value)) {
577
+ return {
578
+ kind: "fail",
579
+ errors: [
580
+ "Invalid signature"
581
+ ]
582
+ };
583
+ }
584
+ return {
585
+ kind: "pass"
586
+ };
587
+ };
588
+
589
+ // packages/core/halo/credentials/src/state-machine/space-state-machine.ts
590
+ import { runInContextAsync } from "@dxos/async";
591
+ import { Context } from "@dxos/context";
592
+ import { PublicKey as PublicKey7 } from "@dxos/keys";
593
+ import { log as log3 } from "@dxos/log";
594
+ import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
595
+ import { Callback as Callback4, ComplexMap as ComplexMap5, ComplexSet as ComplexSet3 } from "@dxos/util";
596
+
597
+ // packages/core/halo/credentials/src/state-machine/feed-state-machine.ts
598
+ import { invariant as invariant2 } from "@dxos/invariant";
599
+ import { PublicKey as PublicKey3 } from "@dxos/keys";
600
+ import { Callback, ComplexMap } from "@dxos/util";
601
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/feed-state-machine.ts";
602
+ var FeedStateMachine = class {
603
+ constructor(_spaceKey) {
604
+ this._spaceKey = _spaceKey;
605
+ this._feeds = new ComplexMap(PublicKey3.hash);
606
+ this.onFeedAdmitted = new Callback();
607
+ }
608
+ get feeds() {
609
+ return this._feeds;
610
+ }
611
+ /**
612
+ * Processes the AdmittedFeed credential.
613
+ * Assumes the credential is already pre-verified
614
+ * and the issuer has been authorized to issue credentials of this type.
615
+ * @param fromFeed Key of the feed where this credential is recorded.
616
+ */
617
+ async process(credential, fromFeed) {
618
+ const assertion = getCredentialAssertion(credential);
619
+ invariant2(assertion["@type"] === "dxos.halo.credentials.AdmittedFeed", void 0, {
620
+ F: __dxlog_file2,
621
+ L: 47,
622
+ S: this,
623
+ A: [
624
+ "assertion['@type'] === 'dxos.halo.credentials.AdmittedFeed'",
625
+ ""
626
+ ]
627
+ });
628
+ invariant2(assertion.spaceKey.equals(this._spaceKey), void 0, {
629
+ F: __dxlog_file2,
630
+ L: 48,
631
+ S: this,
632
+ A: [
633
+ "assertion.spaceKey.equals(this._spaceKey)",
634
+ ""
635
+ ]
636
+ });
637
+ const info = {
638
+ key: credential.subject.id,
639
+ credential,
640
+ assertion,
641
+ parent: fromFeed
642
+ };
643
+ this._feeds.set(credential.subject.id, info);
644
+ await this.onFeedAdmitted.callIfSet(info);
645
+ }
646
+ };
647
+
648
+ // packages/core/halo/credentials/src/state-machine/invitation-state-machine.ts
649
+ import { PublicKey as PublicKey4 } from "@dxos/keys";
650
+ import { Callback as Callback2, ComplexMap as ComplexMap2, ComplexSet } from "@dxos/util";
651
+ var InvitationStateMachine = class {
652
+ constructor() {
653
+ this._invitations = new ComplexMap2(PublicKey4.hash);
654
+ this._redeemedInvitationCredentialIds = new ComplexSet(PublicKey4.hash);
655
+ this._cancelledInvitationCredentialIds = new ComplexSet(PublicKey4.hash);
656
+ this.onDelegatedInvitation = new Callback2();
657
+ this.onDelegatedInvitationRemoved = new Callback2();
658
+ }
659
+ get invitations() {
660
+ return this._invitations;
661
+ }
662
+ async process(credential) {
663
+ const credentialId = credential.id;
664
+ if (credentialId == null) {
665
+ return;
666
+ }
667
+ const assertion = getCredentialAssertion(credential);
668
+ switch (assertion["@type"]) {
669
+ case "dxos.halo.invitations.CancelDelegatedInvitation": {
670
+ this._cancelledInvitationCredentialIds.add(assertion.credentialId);
671
+ const existingInvitation = this._invitations.get(assertion.credentialId);
672
+ if (existingInvitation != null) {
673
+ this._invitations.delete(assertion.credentialId);
674
+ await this.onDelegatedInvitationRemoved.callIfSet({
675
+ credentialId: assertion.credentialId,
676
+ invitation: existingInvitation
677
+ });
678
+ }
679
+ break;
680
+ }
681
+ case "dxos.halo.invitations.DelegateSpaceInvitation": {
682
+ if (credential.id) {
683
+ const isExpired = assertion.expiresOn && assertion.expiresOn.getTime() < Date.now();
684
+ const wasUsed = this._redeemedInvitationCredentialIds.has(credential.id) && !assertion.multiUse;
685
+ const wasCancelled = this._cancelledInvitationCredentialIds.has(credential.id);
686
+ if (isExpired || wasCancelled || wasUsed) {
687
+ return;
688
+ }
689
+ const invitation = {
690
+ ...assertion
691
+ };
692
+ this._invitations.set(credential.id, invitation);
693
+ await this.onDelegatedInvitation.callIfSet({
694
+ credentialId: credential.id,
695
+ invitation
696
+ });
697
+ }
698
+ break;
699
+ }
700
+ case "dxos.halo.credentials.SpaceMember": {
701
+ if (assertion.invitationCredentialId != null) {
702
+ this._redeemedInvitationCredentialIds.add(assertion.invitationCredentialId);
703
+ const existingInvitation = this._invitations.get(assertion.invitationCredentialId);
704
+ if (existingInvitation != null && !existingInvitation.multiUse) {
705
+ this._invitations.delete(assertion.invitationCredentialId);
706
+ await this.onDelegatedInvitationRemoved.callIfSet({
707
+ credentialId: assertion.invitationCredentialId,
708
+ invitation: existingInvitation
709
+ });
710
+ }
711
+ }
712
+ break;
713
+ }
714
+ }
715
+ }
716
+ };
717
+
718
+ // packages/core/halo/credentials/src/state-machine/member-state-machine.ts
719
+ import { invariant as invariant4 } from "@dxos/invariant";
720
+ import { PublicKey as PublicKey6 } from "@dxos/keys";
721
+ import { log as log2 } from "@dxos/log";
722
+ import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
723
+ import { ComplexMap as ComplexMap4 } from "@dxos/util";
724
+
725
+ // packages/core/halo/credentials/src/graph/credential-graph.ts
726
+ import { invariant as invariant3 } from "@dxos/invariant";
727
+ import { PublicKey as PublicKey5 } from "@dxos/keys";
728
+ import { log } from "@dxos/log";
729
+ import { Callback as Callback3, ComplexMap as ComplexMap3, ComplexSet as ComplexSet2 } from "@dxos/util";
730
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/graph/credential-graph.ts";
731
+ var CredentialGraph = class {
732
+ constructor(_stateHandler) {
733
+ this._stateHandler = _stateHandler;
734
+ this._vertexIdGenerator = 1;
735
+ this._root = {
736
+ id: -1,
737
+ parents: [],
738
+ children: []
739
+ };
740
+ this._sentinel = {
741
+ id: -2,
742
+ parents: [],
743
+ children: []
744
+ };
745
+ this._vertexByCredentialId = new ComplexMap3(PublicKey5.hash);
746
+ this._subjectToVertex = new ComplexMap3(PublicKey5.hash);
747
+ this._subjectToState = new ComplexMap3(PublicKey5.hash);
748
+ this.onSubjectStateChanged = new Callback3();
749
+ }
750
+ getSubjectState(subjectId) {
751
+ return this._subjectToState.get(subjectId);
752
+ }
753
+ getState() {
754
+ return this._subjectToState;
755
+ }
756
+ getLeafIds() {
757
+ return this._sentinel.parents.map((v) => v.credential.id);
758
+ }
759
+ getGlobalStateScope() {
760
+ return {
761
+ state: this._subjectToVertex
762
+ };
763
+ }
764
+ addVertex(credential, assertion) {
765
+ const newVertex = {
766
+ id: this._vertexIdGenerator++,
767
+ credential,
768
+ assertion,
769
+ parents: [],
770
+ children: []
771
+ };
772
+ this._vertexByCredentialId.set(credential.id, newVertex);
773
+ const parentIds = credential.parentCredentialIds ?? [];
774
+ if (parentIds.length === 0) {
775
+ this._root.children.push(newVertex);
776
+ newVertex.parents.push(this._root);
777
+ } else {
778
+ for (const parentId of parentIds) {
779
+ const parentVertex = this._vertexByCredentialId.get(parentId);
780
+ if (parentVertex == null) {
781
+ log.error("credential skipped because of the unknown parent", {
782
+ credential,
783
+ parentId
784
+ }, {
785
+ F: __dxlog_file3,
786
+ L: 72,
787
+ S: this,
788
+ C: (f, a) => f(...a)
789
+ });
790
+ continue;
791
+ }
792
+ parentVertex.children.push(newVertex);
793
+ newVertex.parents.push(parentVertex);
794
+ this._removeSentinelConnection(parentVertex);
795
+ }
796
+ }
797
+ newVertex.children.push(this._sentinel);
798
+ this._sentinel.parents.push(newVertex);
799
+ return this._onVertexInserted(newVertex);
800
+ }
801
+ _removeSentinelConnection(vertex) {
802
+ const sentinelIdx = vertex.children.indexOf(this._sentinel);
803
+ if (sentinelIdx >= 0) {
804
+ vertex.children.splice(sentinelIdx, 1);
805
+ const vertexInSentinelIdx = this._sentinel.parents.indexOf(vertex);
806
+ invariant3(vertexInSentinelIdx >= 0, void 0, {
807
+ F: __dxlog_file3,
808
+ L: 90,
809
+ S: this,
810
+ A: [
811
+ "vertexInSentinelIdx >= 0",
812
+ ""
813
+ ]
814
+ });
815
+ this._sentinel.parents.splice(vertexInSentinelIdx, 1);
816
+ }
817
+ }
818
+ async _onVertexInserted(newVertex) {
819
+ const { credential, assertion } = newVertex;
820
+ invariant3(credential, void 0, {
821
+ F: __dxlog_file3,
822
+ L: 97,
823
+ S: this,
824
+ A: [
825
+ "credential",
826
+ ""
827
+ ]
828
+ });
829
+ let changedSubjects = [];
830
+ const isUpdateAppliedOnTopOfThePreviousState = this._sentinel.parents.length === 1;
831
+ if (isUpdateAppliedOnTopOfThePreviousState) {
832
+ const subjectId = credential.subject.id;
833
+ if (this._stateHandler.isUpdateAllowed(this.getGlobalStateScope(), credential, assertion)) {
834
+ const newSubjectState = this._stateHandler.createState(credential, newVertex.assertion);
835
+ const prevSubjectState = this._subjectToState.get(subjectId);
836
+ this._subjectToState.set(subjectId, newSubjectState);
837
+ this._subjectToVertex.set(subjectId, newVertex);
838
+ if (this._stateHandler.hasStateChanged(newSubjectState, prevSubjectState)) {
839
+ changedSubjects.push(newSubjectState);
840
+ }
841
+ }
842
+ } else {
843
+ changedSubjects = this._recomputeState();
844
+ }
845
+ if (changedSubjects.length > 0) {
846
+ await this.onSubjectStateChanged.callIfSet(changedSubjects);
847
+ }
848
+ }
849
+ /**
850
+ * DFS the graph from root to sentinel pausing on merge points (nodes with multiple parents).
851
+ * Continue after all paths leading to a merge point converge by merging their states.
852
+ * In case of a concurrent update paths are replayed taking into account the state set
853
+ * by the winning branch.
854
+ */
855
+ _recomputeState() {
856
+ const pendingPaths = /* @__PURE__ */ new Map();
857
+ const paths = [
858
+ this._createRootPath()
859
+ ];
860
+ let lastPath = null;
861
+ while (lastPath == null) {
862
+ const path = paths.pop();
863
+ log("visit vertex", {
864
+ id: path.head.id
865
+ }, {
866
+ F: __dxlog_file3,
867
+ L: 132,
868
+ S: this,
869
+ C: (f, a) => f(...a)
870
+ });
871
+ this._updatePathState(path);
872
+ const convergedPaths = this._handleMergePoint(paths, pendingPaths, path);
873
+ if (convergedPaths == null) {
874
+ log("waiting for other paths", void 0, {
875
+ F: __dxlog_file3,
876
+ L: 136,
877
+ S: this,
878
+ C: (f, a) => f(...a)
879
+ });
880
+ continue;
881
+ }
882
+ const mergeResult = this._mergePaths(convergedPaths);
883
+ if (mergeResult.type === "replay_required") {
884
+ this._replayFailedPaths(paths, pendingPaths, mergeResult, convergedPaths);
885
+ continue;
886
+ }
887
+ const merged = mergeResult.path;
888
+ if (merged.head.children.length === 0) {
889
+ lastPath = merged;
890
+ } else if (merged.head.children.length === 1) {
891
+ merged.head = merged.head.children[0];
892
+ paths.push(merged);
893
+ } else {
894
+ this._forkTraversal(paths, merged);
895
+ }
896
+ }
897
+ if (paths.length > 0) {
898
+ log.error("traversal finished while there were active paths", {
899
+ paths: paths.map((p) => ({
900
+ path: toChosenPath(p),
901
+ head: p.head.id
902
+ }))
903
+ }, {
904
+ F: __dxlog_file3,
905
+ L: 155,
906
+ S: this,
907
+ C: (f, a) => f(...a)
908
+ });
909
+ }
910
+ return this._setCurrentState(lastPath);
911
+ }
912
+ _replayFailedPaths(paths, pendingPaths, mergeResult, convergedPaths) {
913
+ paths.push(...mergeResult.replay.map((path) => {
914
+ const stateOverrides = path.stateOverrides ?? new ComplexMap3(PublicKey5.hash);
915
+ mergeResult.stateOverrides.forEach((value, key) => stateOverrides.set(key, value));
916
+ return {
917
+ ...mergeResult.from,
918
+ chosenPath: path.chosenPath,
919
+ stateOverrides
920
+ };
921
+ }));
922
+ log("replay paths", () => ({
923
+ count: paths.length,
924
+ paths: paths.map((path) => ({
925
+ from: mergeResult.from.head.id,
926
+ path: toChosenPath(path),
927
+ overrides: path?.stateOverrides?.mapValues((v) => this._stateHandler.toLogString(v.assertion))
928
+ }))
929
+ }), {
930
+ F: __dxlog_file3,
931
+ L: 175,
932
+ S: this,
933
+ C: (f, a) => f(...a)
934
+ });
935
+ const clearedPending = convergedPaths.filter((l) => !mergeResult.replay.includes(l));
936
+ pendingPaths.set(convergedPaths[0].head.id, clearedPending);
937
+ }
938
+ _handleMergePoint(paths, pendingPaths, path) {
939
+ const pendingList = pendingPaths.get(path.head.id) ?? [];
940
+ pendingPaths.set(path.head.id, pendingList);
941
+ pendingList.push(path);
942
+ if (pendingList.length < path.head.parents.length) {
943
+ return null;
944
+ }
945
+ if (path.head.id === this._sentinel.id && paths.length > 0) {
946
+ log("waiting for all the active paths to converge on the sentinel", void 0, {
947
+ F: __dxlog_file3,
948
+ L: 199,
949
+ S: this,
950
+ C: (f, a) => f(...a)
951
+ });
952
+ return null;
953
+ }
954
+ pendingPaths.delete(path.head.id);
955
+ return pendingList;
956
+ }
957
+ _updatePathState(path) {
958
+ const headCredential = path.head.credential;
959
+ if (headCredential == null) {
960
+ return;
961
+ }
962
+ const updatedSubject = headCredential.subject.id;
963
+ path.credentials.add(headCredential.id);
964
+ let isUpdateAllowed = this._stateHandler.isUpdateAllowed(path, headCredential, path.head.assertion);
965
+ if (!isUpdateAllowed && path.head.parents[0]?.id === this._root.id) {
966
+ const globalState = this.getGlobalStateScope();
967
+ isUpdateAllowed = this._stateHandler.isUpdateAllowed(globalState, headCredential, path.head.assertion);
968
+ }
969
+ if (isUpdateAllowed) {
970
+ path.forkChangedSubjects.add(updatedSubject);
971
+ path.forkIssuers.add(headCredential.issuer);
972
+ path.state.set(updatedSubject, path.head);
973
+ log("path state updated", () => ({
974
+ subject: updatedSubject,
975
+ newState: this._stateHandler.toLogString(path.head.assertion)
976
+ }), {
977
+ F: __dxlog_file3,
978
+ L: 223,
979
+ S: this,
980
+ C: (f, a) => f(...a)
981
+ });
982
+ }
983
+ }
984
+ _forkTraversal(paths, path) {
985
+ const replayChoice = path.chosenPath?.[path.head.id];
986
+ const choices = replayChoice ?? path.head.children;
987
+ for (const choice of choices) {
988
+ log("edge traversal", {
989
+ from: path.head.id,
990
+ to: choice.id
991
+ }, {
992
+ F: __dxlog_file3,
993
+ L: 234,
994
+ S: this,
995
+ C: (f, a) => f(...a)
996
+ });
997
+ const fork = {
998
+ forkPoint: path,
999
+ chosenPath: {
1000
+ ...path.chosenPath,
1001
+ [path.head.id]: [
1002
+ choice
1003
+ ]
1004
+ },
1005
+ head: choice,
1006
+ credentials: new ComplexSet2(PublicKey5.hash, path.credentials),
1007
+ state: new ComplexMap3(PublicKey5.hash, [
1008
+ ...path.state.entries()
1009
+ ]),
1010
+ forkIssuers: new ComplexSet2(PublicKey5.hash),
1011
+ forkChangedSubjects: new ComplexSet2(PublicKey5.hash),
1012
+ stateOverrides: path.stateOverrides
1013
+ };
1014
+ paths.push(fork);
1015
+ }
1016
+ }
1017
+ /**
1018
+ * Updates the current graph state.
1019
+ * @returns changed states.
1020
+ */
1021
+ _setCurrentState(path) {
1022
+ const changedSubjects = [];
1023
+ const newStateMap = new ComplexMap3(PublicKey5.hash);
1024
+ const newVertexMap = new ComplexMap3(PublicKey5.hash);
1025
+ for (const [subjectKey, subjectVertex] of path.state.entries()) {
1026
+ const newState = this._stateHandler.createState(subjectVertex.credential, subjectVertex.assertion);
1027
+ const prevState = this._subjectToState.get(subjectKey);
1028
+ newStateMap.set(subjectKey, newState);
1029
+ newVertexMap.set(subjectKey, subjectVertex);
1030
+ if (this._stateHandler.hasStateChanged(newState, prevState)) {
1031
+ changedSubjects.push(newState);
1032
+ }
1033
+ }
1034
+ this._subjectToState = newStateMap;
1035
+ this._subjectToVertex = newVertexMap;
1036
+ return changedSubjects;
1037
+ }
1038
+ /*
1039
+ * Walk up all the fork points and return the first one present in all the paths.
1040
+ * We use local id to determine vertex position in the graph, because nodes can't
1041
+ * be inserted in the middle (between a parent and a child) and ids are monotonically increasing.
1042
+ */
1043
+ _leastCommonAncestor(paths) {
1044
+ const uniqueForkPoints = paths.reduce((acc, path) => {
1045
+ let it = path.forkPoint;
1046
+ while (it) {
1047
+ acc.set(it.head.id, it);
1048
+ it = it.forkPoint;
1049
+ }
1050
+ return acc;
1051
+ }, /* @__PURE__ */ new Map());
1052
+ let maxId = this._root.id;
1053
+ let maxState = null;
1054
+ for (const [id, state] of uniqueForkPoints.entries()) {
1055
+ const headCredential = state.head.credential;
1056
+ if (headCredential != null) {
1057
+ const isPointInEveryPath = paths.every((p) => p.credentials.has(headCredential.id));
1058
+ if (isPointInEveryPath && id > maxId) {
1059
+ maxId = id;
1060
+ maxState = state;
1061
+ }
1062
+ }
1063
+ }
1064
+ return maxState ?? this._createRootPath();
1065
+ }
1066
+ /**
1067
+ * We might be merging paths where some of them had fork points after the initial forking.
1068
+ * We need all the paths to point to the least common fork point and contain all the changes
1069
+ * that happened after it.
1070
+ */
1071
+ _moveUpToForkPoint(forkPoint, path) {
1072
+ const isForkPointInPath = path.chosenPath[forkPoint.head.id] == null || path.forkPoint == null;
1073
+ if (isForkPointInPath) {
1074
+ return path;
1075
+ }
1076
+ if (forkPoint.head.id === path.forkPoint?.head.id) {
1077
+ return path;
1078
+ }
1079
+ let it = path.forkPoint;
1080
+ while (it.head.id !== forkPoint.head.id) {
1081
+ it.forkIssuers.forEach((iss) => path.forkIssuers.add(iss));
1082
+ it.forkChangedSubjects.forEach((m) => path.forkChangedSubjects.add(m));
1083
+ it = it.forkPoint;
1084
+ path.forkPoint = it;
1085
+ }
1086
+ return path;
1087
+ }
1088
+ _mergePaths(convergedPaths) {
1089
+ invariant3(convergedPaths.length >= 1, void 0, {
1090
+ F: __dxlog_file3,
1091
+ L: 324,
1092
+ S: this,
1093
+ A: [
1094
+ "convergedPaths.length >= 1",
1095
+ ""
1096
+ ]
1097
+ });
1098
+ if (convergedPaths.length === 1) {
1099
+ return {
1100
+ type: "merged",
1101
+ path: convergedPaths[0]
1102
+ };
1103
+ }
1104
+ const forkPoint = this._leastCommonAncestor(convergedPaths);
1105
+ log("merging paths", () => ({
1106
+ forkPointId: forkPoint.head.id,
1107
+ pathCount: convergedPaths.length,
1108
+ forkPoints: convergedPaths.map((fp) => fp.forkPoint?.head.id)
1109
+ }), {
1110
+ F: __dxlog_file3,
1111
+ L: 329,
1112
+ S: this,
1113
+ C: (f, a) => f(...a)
1114
+ });
1115
+ const paths = convergedPaths.map((p) => this._moveUpToForkPoint(forkPoint, p));
1116
+ invariant3(forkPoint, void 0, {
1117
+ F: __dxlog_file3,
1118
+ L: 335,
1119
+ S: this,
1120
+ A: [
1121
+ "forkPoint",
1122
+ ""
1123
+ ]
1124
+ });
1125
+ const result = {
1126
+ forkPoint: forkPoint.forkPoint,
1127
+ chosenPath: {
1128
+ ...forkPoint.chosenPath,
1129
+ [forkPoint.head.id]: []
1130
+ },
1131
+ stateOverrides: forkPoint.stateOverrides,
1132
+ credentials: new ComplexSet2(PublicKey5.hash, forkPoint.credentials),
1133
+ forkIssuers: new ComplexSet2(PublicKey5.hash, forkPoint.forkIssuers),
1134
+ forkChangedSubjects: new ComplexSet2(PublicKey5.hash, forkPoint.forkChangedSubjects),
1135
+ state: forkPoint.state.mapValues((v) => v),
1136
+ head: paths[0].head
1137
+ };
1138
+ const subjectToBranch = new ComplexMap3(PublicKey5.hash);
1139
+ for (const path of paths) {
1140
+ log("processing a path", () => ({
1141
+ choices: toChosenPath(path),
1142
+ modified: path.forkChangedSubjects,
1143
+ forkIssuers: path.forkIssuers,
1144
+ state: path.state.mapValues((v) => this._stateHandler.toLogString(v.assertion))
1145
+ }), {
1146
+ F: __dxlog_file3,
1147
+ L: 348,
1148
+ S: this,
1149
+ C: (f, a) => f(...a)
1150
+ });
1151
+ path.forkIssuers.forEach((iss) => result.forkIssuers.add(iss));
1152
+ path.credentials.forEach((cred) => result.credentials.add(cred));
1153
+ result.chosenPath[forkPoint.head.id].push(...path.chosenPath[forkPoint.head.id] ?? []);
1154
+ for (const modifiedSubject of path.forkChangedSubjects) {
1155
+ const existingBranch = subjectToBranch.get(modifiedSubject);
1156
+ if (existingBranch == null || this._shouldOverrideCredential(existingBranch, path, modifiedSubject)) {
1157
+ subjectToBranch.set(modifiedSubject, path);
1158
+ }
1159
+ }
1160
+ }
1161
+ const replayPaths = /* @__PURE__ */ new Set();
1162
+ const addReplayPath = replayPaths.add.bind(replayPaths);
1163
+ for (const [subject, branch] of subjectToBranch.entries()) {
1164
+ result.forkChangedSubjects.add(subject);
1165
+ const vertex = branch.state.get(subject);
1166
+ result.state.set(subject, vertex);
1167
+ log("set subject state", () => ({
1168
+ subject,
1169
+ state: this._stateHandler.toLogString(vertex.assertion)
1170
+ }), {
1171
+ F: __dxlog_file3,
1172
+ L: 370,
1173
+ S: this,
1174
+ C: (f, a) => f(...a)
1175
+ });
1176
+ const otherPaths = paths.filter((p) => p !== branch);
1177
+ this._stateHandler.getConflictingPaths(otherPaths, vertex).forEach(addReplayPath);
1178
+ }
1179
+ if (replayPaths.size > 0) {
1180
+ return {
1181
+ type: "replay_required",
1182
+ replay: [
1183
+ ...replayPaths.values()
1184
+ ],
1185
+ from: forkPoint,
1186
+ stateOverrides: subjectToBranch.mapValues((v, key) => v.state.get(key))
1187
+ };
1188
+ }
1189
+ return {
1190
+ type: "merged",
1191
+ path: result
1192
+ };
1193
+ }
1194
+ /**
1195
+ * A candidate credential is preferred over the existing credential if:
1196
+ * 1. It is the merge-point, because it's the last credential that was issued in awareness of all
1197
+ * the previously existing ones.
1198
+ * 2. A path where candidate was set contains existing credential in it, which means that the candidate
1199
+ * was issued after the existing credential by a legitimate issuer.
1200
+ * 3. A state-specific logic (_stateHandler) is able to justify using the candidate credential.
1201
+ * 4. The path where candidate was set has more issuers than the existing path (longer branch).
1202
+ * 5. The issuance time of the candidate is after the issuance time of the existing credential (LWW).
1203
+ */
1204
+ _shouldOverrideCredential(existing, candidate, modifiedSubject) {
1205
+ const candidateVertex = candidate.state.get(modifiedSubject);
1206
+ const currentVertex = existing.state.get(modifiedSubject);
1207
+ if (candidateVertex.id === currentVertex.id) {
1208
+ return false;
1209
+ }
1210
+ const mergePointId = existing.head.id;
1211
+ if (candidateVertex.id === mergePointId || currentVertex.id === mergePointId) {
1212
+ log("merge point chosen to break the tie", {
1213
+ mergePointId: existing.head.id
1214
+ }, {
1215
+ F: __dxlog_file3,
1216
+ L: 408,
1217
+ S: this,
1218
+ C: (f, a) => f(...a)
1219
+ });
1220
+ return mergePointId === candidateVertex.id;
1221
+ }
1222
+ const candidateCredential = candidateVertex.credential;
1223
+ const currentCredential = currentVertex.credential;
1224
+ if (existing.credentials.has(candidateCredential.id) !== candidate.credentials.has(currentCredential.id)) {
1225
+ log("one of the credentials was overridden in another branch", {
1226
+ current: currentVertex.id,
1227
+ candidate: candidateVertex.id
1228
+ }, {
1229
+ F: __dxlog_file3,
1230
+ L: 415,
1231
+ S: this,
1232
+ C: (f, a) => f(...a)
1233
+ });
1234
+ return candidate.credentials.has(currentCredential.id);
1235
+ }
1236
+ const winningCredential = this._stateHandler.tryPickWinningUpdate(existing, currentCredential, candidate, candidateCredential);
1237
+ if (winningCredential != null) {
1238
+ return winningCredential === candidateCredential;
1239
+ }
1240
+ if (candidate.forkIssuers.size !== existing.forkIssuers.size) {
1241
+ log("longer issuers branch used to break the tie", {
1242
+ issuerCount: [
1243
+ existing.forkIssuers.size,
1244
+ candidate.forkIssuers.size
1245
+ ]
1246
+ }, {
1247
+ F: __dxlog_file3,
1248
+ L: 432,
1249
+ S: this,
1250
+ C: (f, a) => f(...a)
1251
+ });
1252
+ return candidate.forkIssuers.size > existing.forkIssuers.size;
1253
+ }
1254
+ log("issuance date used to break the tie", void 0, {
1255
+ F: __dxlog_file3,
1256
+ L: 437,
1257
+ S: this,
1258
+ C: (f, a) => f(...a)
1259
+ });
1260
+ return candidateCredential.issuanceDate.getTime() > currentCredential.issuanceDate.getTime();
1261
+ }
1262
+ _createRootPath() {
1263
+ return {
1264
+ head: this._root,
1265
+ chosenPath: {},
1266
+ forkIssuers: new ComplexSet2(PublicKey5.hash),
1267
+ forkChangedSubjects: new ComplexSet2(PublicKey5.hash),
1268
+ state: new ComplexMap3(PublicKey5.hash),
1269
+ credentials: new ComplexSet2(PublicKey5.hash)
1270
+ };
1271
+ }
1272
+ };
1273
+ var toChosenPath = (path) => {
1274
+ return Object.fromEntries(Object.entries(path.chosenPath).map(([k, vs]) => [
1275
+ k,
1276
+ vs.map((v) => v.id)
1277
+ ]));
1278
+ };
1279
+
1280
+ // packages/core/halo/credentials/src/state-machine/member-state-machine.ts
1281
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/member-state-machine.ts";
1282
+ var MemberStateMachine = class {
1283
+ constructor(_spaceKey) {
1284
+ this._spaceKey = _spaceKey;
1285
+ this._memberProfiles = new ComplexMap4(PublicKey6.hash);
1286
+ this._hashgraph = new CredentialGraph(this);
1287
+ this.onMemberRoleChanged = this._hashgraph.onSubjectStateChanged;
1288
+ }
1289
+ get creator() {
1290
+ return this._ownerKey && this._hashgraph.getSubjectState(this._ownerKey);
1291
+ }
1292
+ get members() {
1293
+ return this._hashgraph.getState();
1294
+ }
1295
+ get membershipChainHeads() {
1296
+ return this._hashgraph.getLeafIds();
1297
+ }
1298
+ getRole(member) {
1299
+ return this._getRole(this._hashgraph.getGlobalStateScope(), member);
1300
+ }
1301
+ /**
1302
+ * Processes the SpaceMember credential.
1303
+ * Assumes the credential is already pre-verified and the issuer has been authorized to issue credentials of this type.
1304
+ */
1305
+ async process(credential) {
1306
+ const assertion = getCredentialAssertion(credential);
1307
+ switch (assertion["@type"]) {
1308
+ case "dxos.halo.credentials.SpaceMember": {
1309
+ invariant4(assertion.spaceKey.equals(this._spaceKey), void 0, {
1310
+ F: __dxlog_file4,
1311
+ L: 66,
1312
+ S: this,
1313
+ A: [
1314
+ "assertion.spaceKey.equals(this._spaceKey)",
1315
+ ""
1316
+ ]
1317
+ });
1318
+ if (this._ownerKey == null && credential.issuer === this._spaceKey) {
1319
+ this._ownerKey = credential.subject.id;
1320
+ }
1321
+ if (assertion.profile != null) {
1322
+ this._memberProfiles.set(credential.subject.id, assertion.profile);
1323
+ }
1324
+ await this._hashgraph.addVertex(credential, assertion);
1325
+ break;
1326
+ }
1327
+ case "dxos.halo.credentials.MemberProfile": {
1328
+ const member = this._hashgraph.getSubjectState(credential.subject.id);
1329
+ if (member) {
1330
+ member.profile = assertion.profile;
1331
+ } else {
1332
+ log2.warn("Member not found", {
1333
+ id: credential.subject.id
1334
+ }, {
1335
+ F: __dxlog_file4,
1336
+ L: 81,
1337
+ S: this,
1338
+ C: (f, a) => f(...a)
1339
+ });
1340
+ }
1341
+ this._memberProfiles.set(credential.subject.id, assertion.profile);
1342
+ break;
1343
+ }
1344
+ default:
1345
+ throw new Error("Invalid assertion type");
1346
+ }
1347
+ }
1348
+ createState(credential, assertion) {
1349
+ const memberKey = credential.subject.id;
1350
+ return {
1351
+ key: memberKey,
1352
+ role: assertion.role,
1353
+ credential,
1354
+ assertion,
1355
+ profile: this._memberProfiles.get(memberKey)
1356
+ };
1357
+ }
1358
+ isUpdateAllowed(scope, credential, assertion) {
1359
+ if (assertion.role === SpaceMember2.Role.OWNER) {
1360
+ return credential.issuer.equals(this._spaceKey);
1361
+ }
1362
+ const issuer = credential.issuer;
1363
+ const isChangingOwnRole = issuer.equals(credential.subject.id);
1364
+ if (isChangingOwnRole) {
1365
+ return false;
1366
+ }
1367
+ if (issuer.equals(assertion.spaceKey)) {
1368
+ return true;
1369
+ }
1370
+ const issuerRole = this._getRole(scope, issuer);
1371
+ return issuerRole === SpaceMember2.Role.ADMIN || issuerRole === SpaceMember2.Role.OWNER;
1372
+ }
1373
+ getConflictingPaths(paths, update) {
1374
+ if (update.assertion.role !== SpaceMember2.Role.REMOVED && update.assertion.role !== SpaceMember2.Role.EDITOR) {
1375
+ return [];
1376
+ }
1377
+ const memberId = update.credential.subject.id;
1378
+ return paths.filter((p) => p.forkIssuers.has(memberId));
1379
+ }
1380
+ tryPickWinningUpdate(scope1, update1, scope2, update2) {
1381
+ const path1IssuerRole = this._getRole(scope1, update1.issuer);
1382
+ const path2IssuerRole = this._getRole(scope2, update2.issuer);
1383
+ if (path2IssuerRole === SpaceMember2.Role.OWNER !== (path1IssuerRole === SpaceMember2.Role.OWNER)) {
1384
+ log2("owner decision used to break the tie", void 0, {
1385
+ F: __dxlog_file4,
1386
+ L: 139,
1387
+ S: this,
1388
+ C: (f, a) => f(...a)
1389
+ });
1390
+ return path1IssuerRole === SpaceMember2.Role.OWNER ? update1 : update2;
1391
+ }
1392
+ return null;
1393
+ }
1394
+ toLogString(assertion) {
1395
+ const role = assertion?.role ?? SpaceMember2.Role.REMOVED;
1396
+ return Object.entries(SpaceMember2.Role).find(([_, value]) => value === role)[0];
1397
+ }
1398
+ hasStateChanged(s1, s2) {
1399
+ return s1?.role !== s2?.role;
1400
+ }
1401
+ _getRole(scope, memberId) {
1402
+ if (this._ownerKey?.equals(memberId)) {
1403
+ return SpaceMember2.Role.OWNER;
1404
+ }
1405
+ const realRole = scope.state.get(memberId)?.assertion?.role ?? SpaceMember2.Role.REMOVED;
1406
+ if (scope.stateOverrides != null) {
1407
+ const override = scope.stateOverrides.get(memberId);
1408
+ if (override != null) {
1409
+ log2("member role overridden in path", () => ({
1410
+ headId: scope.head?.id,
1411
+ roleOverride: this.toLogString(override.assertion),
1412
+ realRole: this.toLogString(scope.state.get(memberId)?.assertion)
1413
+ }), {
1414
+ F: __dxlog_file4,
1415
+ L: 162,
1416
+ S: this,
1417
+ C: (f, a) => f(...a)
1418
+ });
1419
+ return override.assertion.role;
1420
+ }
1421
+ }
1422
+ return realRole;
1423
+ }
1424
+ };
1425
+
1426
+ // packages/core/halo/credentials/src/state-machine/space-state-machine.ts
1427
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
1428
+ var SpaceStateMachine = class {
1429
+ constructor(_spaceKey) {
1430
+ this._spaceKey = _spaceKey;
1431
+ this._members = new MemberStateMachine(this._spaceKey);
1432
+ this._feeds = new FeedStateMachine(this._spaceKey);
1433
+ this._invitations = new InvitationStateMachine();
1434
+ this._credentials = [];
1435
+ this._credentialsById = new ComplexMap5(PublicKey7.hash);
1436
+ this._processedCredentials = new ComplexSet3(PublicKey7.hash);
1437
+ this._credentialProcessors = [];
1438
+ this.onCredentialProcessed = new Callback4();
1439
+ this.onMemberRoleChanged = this._members.onMemberRoleChanged;
1440
+ this.onFeedAdmitted = this._feeds.onFeedAdmitted;
1441
+ this.onDelegatedInvitation = this._invitations.onDelegatedInvitation;
1442
+ this.onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;
1443
+ }
1444
+ get creator() {
1445
+ return this._members.creator;
1446
+ }
1447
+ get members() {
1448
+ return this._members.members;
1449
+ }
1450
+ get membershipChainHeads() {
1451
+ return this._members.membershipChainHeads;
1452
+ }
1453
+ get feeds() {
1454
+ return this._feeds.feeds;
1455
+ }
1456
+ get credentials() {
1457
+ return this._credentials.map((entry) => entry.credential);
1458
+ }
1459
+ get credentialEntries() {
1460
+ return this._credentials;
1461
+ }
1462
+ get genesisCredential() {
1463
+ return this._genesisCredential;
1464
+ }
1465
+ get invitations() {
1466
+ return this._invitations.invitations;
1467
+ }
1468
+ async addCredentialProcessor(processor) {
1469
+ if (this._credentialProcessors.find((p) => p.processor === processor)) {
1470
+ throw new Error("Credential processor already added.");
1471
+ }
1472
+ const consumer = new CredentialConsumer(processor, async () => {
1473
+ for (const credential of this.credentials) {
1474
+ await consumer._process(credential);
1475
+ }
1476
+ consumer._isReadyForLiveCredentials = true;
1477
+ }, async () => {
1478
+ this._credentialProcessors = this._credentialProcessors.filter((p) => p !== consumer);
1479
+ });
1480
+ this._credentialProcessors.push(consumer);
1481
+ await consumer.open();
1482
+ }
1483
+ async removeCredentialProcessor(processor) {
1484
+ const consumer = this._credentialProcessors.find((p) => p.processor === processor);
1485
+ await consumer?.close();
1486
+ }
1487
+ getCredentialsOfType(type) {
1488
+ return this.credentials.filter((credential) => getCredentialAssertion(credential)["@type"] === type);
1489
+ }
1490
+ /**
1491
+ * @param credential Message to process.
1492
+ * @param fromFeed Key of the feed where this credential is recorded.
1493
+ */
1494
+ async process(credential, { sourceFeed, skipVerification }) {
1495
+ if (credential.id) {
1496
+ if (this._processedCredentials.has(credential.id)) {
1497
+ return true;
1498
+ }
1499
+ this._processedCredentials.add(credential.id);
1500
+ }
1501
+ if (!skipVerification) {
1502
+ const result = await verifyCredential(credential);
1503
+ if (result.kind !== "pass") {
1504
+ log3.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, {
1505
+ F: __dxlog_file5,
1506
+ L: 155,
1507
+ S: this,
1508
+ C: (f, a) => f(...a)
1509
+ });
1510
+ return false;
1511
+ }
1512
+ }
1513
+ const assertion = getCredentialAssertion(credential);
1514
+ switch (assertion["@type"]) {
1515
+ case "dxos.halo.credentials.SpaceGenesis": {
1516
+ if (this._genesisCredential) {
1517
+ log3.warn("Space already has a genesis credential.", void 0, {
1518
+ F: __dxlog_file5,
1519
+ L: 164,
1520
+ S: this,
1521
+ C: (f, a) => f(...a)
1522
+ });
1523
+ return false;
1524
+ }
1525
+ if (!credential.issuer.equals(this._spaceKey)) {
1526
+ log3.warn("Space genesis credential must be issued by space.", void 0, {
1527
+ F: __dxlog_file5,
1528
+ L: 168,
1529
+ S: this,
1530
+ C: (f, a) => f(...a)
1531
+ });
1532
+ return false;
1533
+ }
1534
+ if (!credential.subject.id.equals(this._spaceKey)) {
1535
+ log3.warn("Space genesis credential must be issued to space.", void 0, {
1536
+ F: __dxlog_file5,
1537
+ L: 172,
1538
+ S: this,
1539
+ C: (f, a) => f(...a)
1540
+ });
1541
+ return false;
1542
+ }
1543
+ this._genesisCredential = credential;
1544
+ break;
1545
+ }
1546
+ case "dxos.halo.credentials.SpaceMember": {
1547
+ if (!assertion.spaceKey.equals(this._spaceKey)) {
1548
+ break;
1549
+ }
1550
+ if (!this._genesisCredential) {
1551
+ log3.warn("Space must have a genesis credential before adding members.", void 0, {
1552
+ F: __dxlog_file5,
1553
+ L: 185,
1554
+ S: this,
1555
+ C: (f, a) => f(...a)
1556
+ });
1557
+ return false;
1558
+ }
1559
+ if (!this._canInviteNewMembers(credential.issuer)) {
1560
+ log3.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1561
+ F: __dxlog_file5,
1562
+ L: 189,
1563
+ S: this,
1564
+ C: (f, a) => f(...a)
1565
+ });
1566
+ return false;
1567
+ }
1568
+ await this._members.process(credential);
1569
+ await this._invitations.process(credential);
1570
+ break;
1571
+ }
1572
+ case "dxos.halo.credentials.MemberProfile": {
1573
+ if (!this._genesisCredential) {
1574
+ log3.warn("Space must have a genesis credential before adding members.", void 0, {
1575
+ F: __dxlog_file5,
1576
+ L: 200,
1577
+ S: this,
1578
+ C: (f, a) => f(...a)
1579
+ });
1580
+ return false;
1581
+ }
1582
+ await this._members.process(credential);
1583
+ break;
1584
+ }
1585
+ case "dxos.halo.credentials.AdmittedFeed": {
1586
+ if (!this._genesisCredential) {
1587
+ log3.warn("Space must have a genesis credential before admitting feeds.", void 0, {
1588
+ F: __dxlog_file5,
1589
+ L: 210,
1590
+ S: this,
1591
+ C: (f, a) => f(...a)
1592
+ });
1593
+ return false;
1594
+ }
1595
+ if (!this._canAdmitFeeds(credential.issuer)) {
1596
+ log3.warn(`Space member is not authorized to admit feeds: ${credential.issuer}`, void 0, {
1597
+ F: __dxlog_file5,
1598
+ L: 214,
1599
+ S: this,
1600
+ C: (f, a) => f(...a)
1601
+ });
1602
+ return false;
1603
+ }
1604
+ await this._feeds.process(credential, sourceFeed);
1605
+ break;
1606
+ }
1607
+ case "dxos.halo.invitations.CancelDelegatedInvitation":
1608
+ case "dxos.halo.invitations.DelegateSpaceInvitation": {
1609
+ if (!this._canInviteNewMembers(credential.issuer)) {
1610
+ log3.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1611
+ F: __dxlog_file5,
1612
+ L: 225,
1613
+ S: this,
1614
+ C: (f, a) => f(...a)
1615
+ });
1616
+ return false;
1617
+ }
1618
+ await this._invitations.process(credential);
1619
+ break;
1620
+ }
1621
+ }
1622
+ const newEntry = {
1623
+ credential,
1624
+ sourceFeed,
1625
+ revoked: false
1626
+ };
1627
+ this._credentials.push(newEntry);
1628
+ if (credential.id) {
1629
+ this._credentialsById.set(credential.id, newEntry);
1630
+ }
1631
+ for (const processor of this._credentialProcessors) {
1632
+ if (processor._isReadyForLiveCredentials) {
1633
+ await processor._process(credential);
1634
+ }
1635
+ }
1636
+ await this.onCredentialProcessed.callIfSet(credential);
1637
+ return true;
1638
+ }
1639
+ getMemberRole(memberKey) {
1640
+ return this._members.getRole(memberKey);
1641
+ }
1642
+ hasMembershipManagementPermission(memberKey) {
1643
+ return this._canInviteNewMembers(memberKey);
1644
+ }
1645
+ _canInviteNewMembers(key) {
1646
+ return key.equals(this._spaceKey) || this._members.getRole(key) === SpaceMember3.Role.ADMIN || this._members.getRole(key) === SpaceMember3.Role.OWNER;
1647
+ }
1648
+ _canAdmitFeeds(key) {
1649
+ const role = this._members.getRole(key);
1650
+ return role === SpaceMember3.Role.EDITOR || role === SpaceMember3.Role.ADMIN || role === SpaceMember3.Role.OWNER;
1651
+ }
1652
+ };
1653
+ var CredentialConsumer = class {
1654
+ constructor(processor, _onOpen, _onClose) {
1655
+ this.processor = processor;
1656
+ this._onOpen = _onOpen;
1657
+ this._onClose = _onClose;
1658
+ this._ctx = new Context(void 0, {
1659
+ F: __dxlog_file5,
1660
+ L: 275
1661
+ });
1662
+ this._isReadyForLiveCredentials = false;
1663
+ }
1664
+ /**
1665
+ * @internal
1666
+ */
1667
+ async _process(credential) {
1668
+ await runInContextAsync(this._ctx, async () => {
1669
+ await this.processor.processCredential(credential);
1670
+ });
1671
+ }
1672
+ async open() {
1673
+ if (this._ctx.disposed) {
1674
+ throw new Error("CredentialProcessor is disposed");
1675
+ }
1676
+ await this._onOpen();
1677
+ }
1678
+ async close() {
1679
+ await this._ctx.dispose();
1680
+ await this._onClose();
1681
+ }
1682
+ };
1683
+
1684
+ // packages/core/halo/credentials/src/processor/device-state-machine.ts
1685
+ import { Trigger } from "@dxos/async";
1686
+ import { invariant as invariant5 } from "@dxos/invariant";
1687
+ import { PublicKey as PublicKey8 } from "@dxos/keys";
1688
+ import { log as log4 } from "@dxos/log";
1689
+ import { ComplexMap as ComplexMap6 } from "@dxos/util";
1690
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/processor/device-state-machine.ts";
1691
+ var DeviceStateMachine = class {
1692
+ constructor(_params) {
1693
+ this._params = _params;
1694
+ this.authorizedDeviceKeys = new ComplexMap6(PublicKey8.hash);
1695
+ this.deviceChainReady = new Trigger();
1696
+ }
1697
+ async processCredential(credential) {
1698
+ log4("processing credential...", {
1699
+ identityKey: this._params.identityKey,
1700
+ deviceKey: this._params.deviceKey,
1701
+ credential
1702
+ }, {
1703
+ F: __dxlog_file6,
1704
+ L: 35,
1705
+ S: this,
1706
+ C: (f, a) => f(...a)
1707
+ });
1708
+ if (isValidAuthorizedDeviceCredential(credential, this._params.identityKey, this._params.deviceKey)) {
1709
+ this.deviceCredentialChain = {
1710
+ credential
1711
+ };
1712
+ this.deviceChainReady.wake();
1713
+ }
1714
+ const assertion = getCredentialAssertion(credential);
1715
+ switch (assertion["@type"]) {
1716
+ case "dxos.halo.credentials.AuthorizedDevice": {
1717
+ invariant5(!this.authorizedDeviceKeys.has(assertion.deviceKey), "Device already added.", {
1718
+ F: __dxlog_file6,
1719
+ L: 51,
1720
+ S: this,
1721
+ A: [
1722
+ "!this.authorizedDeviceKeys.has(assertion.deviceKey)",
1723
+ "'Device already added.'"
1724
+ ]
1725
+ });
1726
+ this.authorizedDeviceKeys.set(assertion.deviceKey, {});
1727
+ log4("added device", {
1728
+ localDeviceKey: this._params.deviceKey,
1729
+ deviceKey: assertion.deviceKey,
1730
+ size: this.authorizedDeviceKeys.size
1731
+ }, {
1732
+ F: __dxlog_file6,
1733
+ L: 54,
1734
+ S: this,
1735
+ C: (f, a) => f(...a)
1736
+ });
1737
+ this._params.onUpdate?.();
1738
+ break;
1739
+ }
1740
+ case "dxos.halo.credentials.DeviceProfile": {
1741
+ invariant5(this.authorizedDeviceKeys.has(credential.subject.id), "Device not found.", {
1742
+ F: __dxlog_file6,
1743
+ L: 64,
1744
+ S: this,
1745
+ A: [
1746
+ "this.authorizedDeviceKeys.has(credential.subject.id)",
1747
+ "'Device not found.'"
1748
+ ]
1749
+ });
1750
+ if (assertion && credential.subject.id.equals(this._params.deviceKey)) {
1751
+ log4.trace("dxos.halo.device", {
1752
+ deviceKey: credential.subject.id,
1753
+ profile: assertion.profile
1754
+ }, {
1755
+ F: __dxlog_file6,
1756
+ L: 67,
1757
+ S: this,
1758
+ C: (f, a) => f(...a)
1759
+ });
1760
+ }
1761
+ this.authorizedDeviceKeys.set(credential.subject.id, assertion.profile);
1762
+ this._params.onUpdate?.();
1763
+ break;
1764
+ }
1765
+ }
1766
+ }
1767
+ };
1768
+
1769
+ // packages/core/halo/credentials/src/processor/profile-state-machine.ts
1770
+ import { log as log5 } from "@dxos/log";
1771
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/processor/profile-state-machine.ts";
1772
+ var ProfileStateMachine = class {
1773
+ constructor(_params) {
1774
+ this._params = _params;
1775
+ }
1776
+ async processCredential(credential) {
1777
+ const assertion = getCredentialAssertion(credential);
1778
+ switch (assertion["@type"]) {
1779
+ case "dxos.halo.credentials.IdentityProfile": {
1780
+ if (!credential.issuer.equals(this._params.identityKey) || !credential.subject.id.equals(this._params.identityKey)) {
1781
+ log5.warn("Invalid profile credential", {
1782
+ expectedIdentity: this._params.identityKey,
1783
+ credential
1784
+ }, {
1785
+ F: __dxlog_file7,
1786
+ L: 34,
1787
+ S: this,
1788
+ C: (f, a) => f(...a)
1789
+ });
1790
+ return;
1791
+ }
1792
+ this.profile = assertion.profile;
1793
+ log5("updated profile", {
1794
+ identityKey: this._params.identityKey,
1795
+ profile: this.profile
1796
+ }, {
1797
+ F: __dxlog_file7,
1798
+ L: 40,
1799
+ S: this,
1800
+ C: (f, a) => f(...a)
1801
+ });
1802
+ this._params.onUpdate?.();
1803
+ break;
1804
+ }
1805
+ }
1806
+ }
1807
+ };
1808
+ export {
1809
+ CredentialGenerator,
1810
+ DeviceStateMachine,
1811
+ FeedStateMachine,
1812
+ InvitationStateMachine,
1813
+ MemberStateMachine,
1814
+ ProfileStateMachine,
1815
+ SIGNATURE_TYPE_ED25519,
1816
+ SpaceStateMachine,
1817
+ canonicalStringify,
1818
+ checkCredentialType,
1819
+ createAdmissionCredentials,
1820
+ createCancelDelegatedSpaceInvitationCredential,
1821
+ createCredential,
1822
+ createCredentialMessage,
1823
+ createCredentialSignerWithChain,
1824
+ createCredentialSignerWithKey,
1825
+ createDelegatedSpaceInvitationCredential,
1826
+ createDeviceAuthorization,
1827
+ credentialTypeFilter,
1828
+ defaultSecretProvider,
1829
+ defaultSecretValidator,
1830
+ generatePasscode,
1831
+ getCredentialAssertion,
1832
+ getCredentialProofPayload,
1833
+ getPresentationProofPayload,
1834
+ isValidAuthorizedDeviceCredential,
1835
+ signPresentation,
1836
+ verifyChain,
1837
+ verifyCredential,
1838
+ verifyCredentialSignature,
1839
+ verifyPresentation,
1840
+ verifyPresentationChain,
1841
+ verifyPresentationSignature
1842
+ };
1843
+ //# sourceMappingURL=index.mjs.map