@dxos/credentials 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8

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 (52) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/{browser → neutral}/index.mjs +114 -366
  4. package/dist/lib/neutral/index.mjs.map +7 -0
  5. package/dist/lib/neutral/meta.json +1 -0
  6. package/dist/types/src/credentials/assertions.d.ts.map +1 -1
  7. package/dist/types/src/credentials/credential-factory.d.ts +4 -4
  8. package/dist/types/src/credentials/credential-factory.d.ts.map +1 -1
  9. package/dist/types/src/credentials/credential-generator.d.ts +3 -3
  10. package/dist/types/src/credentials/credential-generator.d.ts.map +1 -1
  11. package/dist/types/src/credentials/signing.d.ts.map +1 -1
  12. package/dist/types/src/credentials/verifier.d.ts.map +1 -1
  13. package/dist/types/src/did.d.ts.map +1 -1
  14. package/dist/types/src/graph/credential-graph.d.ts.map +1 -1
  15. package/dist/types/src/passcode.d.ts.map +1 -1
  16. package/dist/types/src/presentations/presentation.d.ts.map +1 -1
  17. package/dist/types/src/presentations/signing.d.ts.map +1 -1
  18. package/dist/types/src/presentations/verifier.d.ts.map +1 -1
  19. package/dist/types/src/processor/device-state-machine.d.ts +2 -2
  20. package/dist/types/src/processor/device-state-machine.d.ts.map +1 -1
  21. package/dist/types/src/processor/profile-state-machine.d.ts +2 -2
  22. package/dist/types/src/processor/profile-state-machine.d.ts.map +1 -1
  23. package/dist/types/src/seedphrase.d.ts.map +1 -1
  24. package/dist/types/src/state-machine/feed-state-machine.d.ts.map +1 -1
  25. package/dist/types/src/state-machine/invitation-state-machine.d.ts.map +1 -1
  26. package/dist/types/src/state-machine/member-state-machine.d.ts.map +1 -1
  27. package/dist/types/src/state-machine/space-state-machine.d.ts +7 -1
  28. package/dist/types/src/state-machine/space-state-machine.d.ts.map +1 -1
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/docs/README.md +17 -17
  31. package/moon.yml +2 -1
  32. package/package.json +20 -24
  33. package/src/credentials/credential-factory.ts +4 -4
  34. package/src/credentials/credential-generator.ts +5 -0
  35. package/src/credentials/signing.ts +26 -0
  36. package/src/presentations/json-encoding.test.ts +0 -2
  37. package/src/presentations/presentation.ts +0 -1
  38. package/src/presentations/verifier.test.ts +0 -1
  39. package/src/presentations/verifier.ts +0 -1
  40. package/src/processor/device-state-machine.ts +2 -3
  41. package/src/processor/profile-state-machine.ts +2 -3
  42. package/src/state-machine/invitation-state-machine.test.ts +0 -1
  43. package/src/state-machine/member-state-machine.test.ts +0 -1
  44. package/src/state-machine/space-state-machine.test.ts +243 -2
  45. package/src/state-machine/space-state-machine.ts +20 -2
  46. package/vitest.config.ts +7 -6
  47. package/.swc/plugins/v7_linux_x86_64_13.0.0/c614d7475354583212fbd7669acbae95b9832c305bf51bdaabe2e6de05abb6bf +0 -0
  48. package/dist/lib/browser/index.mjs.map +0 -7
  49. package/dist/lib/browser/meta.json +0 -1
  50. package/dist/lib/node-esm/index.mjs +0 -1936
  51. package/dist/lib/node-esm/index.mjs.map +0 -7
  52. package/dist/lib/node-esm/meta.json +0 -1
@@ -28,15 +28,7 @@ import { invariant } from "@dxos/invariant";
28
28
  var __dxlog_file = "/__w/dxos/dxos/packages/core/halo/credentials/src/seedphrase.ts";
29
29
  var generateSeedPhrase = () => generateMnemonic();
30
30
  var keyPairFromSeedPhrase = (seedPhrase) => {
31
- invariant(seedPhrase, void 0, {
32
- F: __dxlog_file,
33
- L: 20,
34
- S: void 0,
35
- A: [
36
- "seedPhrase",
37
- ""
38
- ]
39
- });
31
+ invariant(seedPhrase, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 13, S: void 0, A: ["seedPhrase", ""] });
40
32
  const seed = mnemonicToSeedSync(seedPhrase);
41
33
  return createKeyPair(seed);
42
34
  };
@@ -68,6 +60,22 @@ var getCredentialProofPayload = (credential) => {
68
60
  delete copy.parentCredentialIds;
69
61
  }
70
62
  delete copy.id;
63
+ const originalAssertion = copy.subject?.assertion;
64
+ if (originalAssertion) {
65
+ const normalizedAssertion = {
66
+ ...originalAssertion
67
+ };
68
+ for (const key of Object.keys(normalizedAssertion)) {
69
+ const val = normalizedAssertion[key];
70
+ if (val === void 0 || val === null || val === 0 || val === "" || val === false || Array.isArray(val) && val.length === 0) {
71
+ delete normalizedAssertion[key];
72
+ }
73
+ }
74
+ copy.subject = {
75
+ ...copy.subject,
76
+ assertion: normalizedAssertion
77
+ };
78
+ }
71
79
  return Buffer.from(canonicalStringify(copy));
72
80
  };
73
81
  var canonicalStringify = (obj) => stableStringify(obj, {
@@ -228,35 +236,11 @@ var verifyChain = async (chain, authority, subject) => {
228
236
  // src/credentials/credential-factory.ts
229
237
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/halo/credentials/src/credentials/credential-factory.ts";
230
238
  var createCredential = async ({ signer, issuer, subject, assertion, signingKey, chain, nonce, parentCredentialIds }) => {
231
- invariant2(assertion["@type"], "Invalid assertion.", {
232
- F: __dxlog_file2,
233
- L: 48,
234
- S: void 0,
235
- A: [
236
- "assertion['@type']",
237
- "'Invalid assertion.'"
238
- ]
239
- });
240
- invariant2(!!signingKey === !!chain, "Chain must be provided if and only if the signing key differs from the issuer.", {
241
- F: __dxlog_file2,
242
- L: 49,
243
- S: void 0,
244
- A: [
245
- "!!signingKey === !!chain",
246
- "'Chain must be provided if and only if the signing key differs from the issuer.'"
247
- ]
248
- });
239
+ invariant2(assertion["@type"], "Invalid assertion.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 12, S: void 0, A: ["assertion['@type']", "'Invalid assertion.'"] });
240
+ invariant2(!!signingKey === !!chain, "Chain must be provided if and only if the signing key differs from the issuer.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 13, S: void 0, A: ["!!signingKey === !!chain", "'Chain must be provided if and only if the signing key differs from the issuer.'"] });
249
241
  if (chain) {
250
242
  const result = await verifyChain(chain, issuer, signingKey);
251
- invariant2(result.kind === "pass", "Invalid chain.", {
252
- F: __dxlog_file2,
253
- L: 52,
254
- S: void 0,
255
- A: [
256
- "result.kind === 'pass'",
257
- "'Invalid chain.'"
258
- ]
259
- });
243
+ invariant2(result.kind === "pass", "Invalid chain.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 16, S: void 0, A: ["result.kind === 'pass'", "'Invalid chain.'"] });
260
244
  }
261
245
  const credential = {
262
246
  issuer,
@@ -314,7 +298,7 @@ var createCredentialSignerWithChain = (signer, chain, signingKey) => ({
314
298
  });
315
299
 
316
300
  // src/credentials/credential-generator.ts
317
- import { AdmittedFeed, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
301
+ import { AdmittedFeed, MembershipPolicy, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
318
302
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
319
303
  var CredentialGenerator = class {
320
304
  _signer;
@@ -328,7 +312,7 @@ var CredentialGenerator = class {
328
312
  /**
329
313
  * Create genesis messages for new Space.
330
314
  */
331
- async createSpaceGenesis(spaceKey, controlKey, creatorProfile) {
315
+ async createSpaceGenesis(spaceKey, controlKey, creatorProfile, membershipPolicy = MembershipPolicy.INVITE) {
332
316
  return [
333
317
  await createCredential({
334
318
  signer: this._signer,
@@ -336,7 +320,8 @@ var CredentialGenerator = class {
336
320
  subject: spaceKey,
337
321
  assertion: {
338
322
  "@type": "dxos.halo.credentials.SpaceGenesis",
339
- spaceKey
323
+ spaceKey,
324
+ membershipPolicy
340
325
  }
341
326
  }),
342
327
  await createCredential({
@@ -463,7 +448,7 @@ var createDeviceAuthorization = async (signer, identityKey, deviceKey) => {
463
448
  credential
464
449
  }));
465
450
  };
466
- var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, role = SpaceMember.Role.ADMIN, membershipChainHeads = [], profile, invitationCredentialId) => {
451
+ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, role = SpaceMember.Role.ADMIN, membershipChainHeads = [], profile, invitationCredentialId, tags) => {
467
452
  const credentials = await Promise.all([
468
453
  await signer.createCredential({
469
454
  subject: identityKey,
@@ -474,7 +459,8 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
474
459
  role,
475
460
  profile,
476
461
  genesisFeedKey,
477
- invitationCredentialId
462
+ invitationCredentialId,
463
+ tags: tags ?? []
478
464
  }
479
465
  })
480
466
  ]);
@@ -631,7 +617,7 @@ import { runInContextAsync, synchronized } from "@dxos/async";
631
617
  import { Context } from "@dxos/context";
632
618
  import { PublicKey as PublicKey8 } from "@dxos/keys";
633
619
  import { log as log3 } from "@dxos/log";
634
- import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
620
+ import { MembershipPolicy as MembershipPolicy2, SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
635
621
  import { Callback as Callback4, ComplexMap as ComplexMap6, ComplexSet as ComplexSet3 } from "@dxos/util";
636
622
 
637
623
  // src/state-machine/feed-state-machine.ts
@@ -641,12 +627,10 @@ import { Callback, ComplexMap as ComplexMap2 } from "@dxos/util";
641
627
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/halo/credentials/src/state-machine/feed-state-machine.ts";
642
628
  var FeedStateMachine = class {
643
629
  _spaceKey;
644
- _feeds;
645
- onFeedAdmitted;
630
+ _feeds = new ComplexMap2(PublicKey4.hash);
631
+ onFeedAdmitted = new Callback();
646
632
  constructor(_spaceKey) {
647
633
  this._spaceKey = _spaceKey;
648
- this._feeds = new ComplexMap2(PublicKey4.hash);
649
- this.onFeedAdmitted = new Callback();
650
634
  }
651
635
  get feeds() {
652
636
  return this._feeds;
@@ -659,24 +643,8 @@ var FeedStateMachine = class {
659
643
  */
660
644
  async process(credential, fromFeed) {
661
645
  const assertion = getCredentialAssertion(credential);
662
- invariant3(assertion["@type"] === "dxos.halo.credentials.AdmittedFeed", void 0, {
663
- F: __dxlog_file3,
664
- L: 47,
665
- S: this,
666
- A: [
667
- "assertion['@type'] === 'dxos.halo.credentials.AdmittedFeed'",
668
- ""
669
- ]
670
- });
671
- invariant3(assertion.spaceKey.equals(this._spaceKey), void 0, {
672
- F: __dxlog_file3,
673
- L: 48,
674
- S: this,
675
- A: [
676
- "assertion.spaceKey.equals(this._spaceKey)",
677
- ""
678
- ]
679
- });
646
+ invariant3(assertion["@type"] === "dxos.halo.credentials.AdmittedFeed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 28, S: this, A: ["assertion['@type'] === 'dxos.halo.credentials.AdmittedFeed'", ""] });
647
+ invariant3(assertion.spaceKey.equals(this._spaceKey), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 29, S: this, A: ["assertion.spaceKey.equals(this._spaceKey)", ""] });
680
648
  const info = {
681
649
  key: credential.subject.id,
682
650
  credential,
@@ -774,43 +742,36 @@ var CredentialGraph = class {
774
742
  /**
775
743
  * Local ids are used during traversals.
776
744
  */
777
- _vertexIdGenerator;
745
+ _vertexIdGenerator = 1;
778
746
  /**
779
747
  * All credentials without parent references are connected to the root.
780
748
  */
781
- _root;
749
+ _root = {
750
+ id: -1,
751
+ parents: [],
752
+ children: []
753
+ };
782
754
  /**
783
755
  * A credential which is not a parent of any other credential has the sentinel as a child.
784
756
  * Sentinel is a virtual merge-point of all credentials.
785
757
  */
786
- _sentinel;
758
+ _sentinel = {
759
+ id: -2,
760
+ parents: [],
761
+ children: []
762
+ };
787
763
  /**
788
764
  * Vertex references are used for fast credential inserts into the graph.
789
765
  */
790
- _vertexByCredentialId;
766
+ _vertexByCredentialId = new ComplexMap4(PublicKey6.hash);
791
767
  /**
792
768
  * The current state of the graph.
793
769
  */
794
- _subjectToVertex;
795
- _subjectToState;
796
- onSubjectStateChanged;
770
+ _subjectToVertex = new ComplexMap4(PublicKey6.hash);
771
+ _subjectToState = new ComplexMap4(PublicKey6.hash);
772
+ onSubjectStateChanged = new Callback3();
797
773
  constructor(_stateHandler) {
798
774
  this._stateHandler = _stateHandler;
799
- this._vertexIdGenerator = 1;
800
- this._root = {
801
- id: -1,
802
- parents: [],
803
- children: []
804
- };
805
- this._sentinel = {
806
- id: -2,
807
- parents: [],
808
- children: []
809
- };
810
- this._vertexByCredentialId = new ComplexMap4(PublicKey6.hash);
811
- this._subjectToVertex = new ComplexMap4(PublicKey6.hash);
812
- this._subjectToState = new ComplexMap4(PublicKey6.hash);
813
- this.onSubjectStateChanged = new Callback3();
814
775
  }
815
776
  getSubjectState(subjectId) {
816
777
  return this._subjectToState.get(subjectId);
@@ -846,12 +807,7 @@ var CredentialGraph = class {
846
807
  log.error("credential skipped because of the unknown parent", {
847
808
  credential,
848
809
  parentId
849
- }, {
850
- F: __dxlog_file4,
851
- L: 72,
852
- S: this,
853
- C: (f, a) => f(...a)
854
- });
810
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 70, S: this });
855
811
  continue;
856
812
  }
857
813
  parentVertex.children.push(newVertex);
@@ -868,29 +824,13 @@ var CredentialGraph = class {
868
824
  if (sentinelIdx >= 0) {
869
825
  vertex.children.splice(sentinelIdx, 1);
870
826
  const vertexInSentinelIdx = this._sentinel.parents.indexOf(vertex);
871
- invariant4(vertexInSentinelIdx >= 0, void 0, {
872
- F: __dxlog_file4,
873
- L: 90,
874
- S: this,
875
- A: [
876
- "vertexInSentinelIdx >= 0",
877
- ""
878
- ]
879
- });
827
+ invariant4(vertexInSentinelIdx >= 0, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 90, S: this, A: ["vertexInSentinelIdx >= 0", ""] });
880
828
  this._sentinel.parents.splice(vertexInSentinelIdx, 1);
881
829
  }
882
830
  }
883
831
  async _onVertexInserted(newVertex) {
884
832
  const { credential, assertion } = newVertex;
885
- invariant4(credential, void 0, {
886
- F: __dxlog_file4,
887
- L: 97,
888
- S: this,
889
- A: [
890
- "credential",
891
- ""
892
- ]
893
- });
833
+ invariant4(credential, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 96, S: this, A: ["credential", ""] });
894
834
  let changedSubjects = [];
895
835
  const isUpdateAppliedOnTopOfThePreviousState = this._sentinel.parents.length === 1;
896
836
  if (isUpdateAppliedOnTopOfThePreviousState) {
@@ -927,21 +867,11 @@ var CredentialGraph = class {
927
867
  const path = paths.pop();
928
868
  log("visit vertex", {
929
869
  id: path.head.id
930
- }, {
931
- F: __dxlog_file4,
932
- L: 132,
933
- S: this,
934
- C: (f, a) => f(...a)
935
- });
870
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 131, S: this });
936
871
  this._updatePathState(path);
937
872
  const convergedPaths = this._handleMergePoint(paths, pendingPaths, path);
938
873
  if (convergedPaths == null) {
939
- log("waiting for other paths", void 0, {
940
- F: __dxlog_file4,
941
- L: 136,
942
- S: this,
943
- C: (f, a) => f(...a)
944
- });
874
+ log("waiting for other paths", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 137, S: this });
945
875
  continue;
946
876
  }
947
877
  const mergeResult = this._mergePaths(convergedPaths);
@@ -965,12 +895,7 @@ var CredentialGraph = class {
965
895
  path: toChosenPath(p),
966
896
  head: p.head.id
967
897
  }))
968
- }, {
969
- F: __dxlog_file4,
970
- L: 155,
971
- S: this,
972
- C: (f, a) => f(...a)
973
- });
898
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 156, S: this });
974
899
  }
975
900
  return this._setCurrentState(lastPath);
976
901
  }
@@ -991,12 +916,7 @@ var CredentialGraph = class {
991
916
  path: toChosenPath(path),
992
917
  overrides: path?.stateOverrides?.mapValues((v) => this._stateHandler.toLogString(v.assertion))
993
918
  }))
994
- }), {
995
- F: __dxlog_file4,
996
- L: 175,
997
- S: this,
998
- C: (f, a) => f(...a)
999
- });
919
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 175, S: this });
1000
920
  const clearedPending = convergedPaths.filter((l) => !mergeResult.replay.includes(l));
1001
921
  pendingPaths.set(convergedPaths[0].head.id, clearedPending);
1002
922
  }
@@ -1008,12 +928,7 @@ var CredentialGraph = class {
1008
928
  return null;
1009
929
  }
1010
930
  if (path.head.id === this._sentinel.id && paths.length > 0) {
1011
- log("waiting for all the active paths to converge on the sentinel", void 0, {
1012
- F: __dxlog_file4,
1013
- L: 199,
1014
- S: this,
1015
- C: (f, a) => f(...a)
1016
- });
931
+ log("waiting for all the active paths to converge on the sentinel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 194, S: this });
1017
932
  return null;
1018
933
  }
1019
934
  pendingPaths.delete(path.head.id);
@@ -1038,12 +953,7 @@ var CredentialGraph = class {
1038
953
  log("path state updated", () => ({
1039
954
  subject: updatedSubject,
1040
955
  newState: this._stateHandler.toLogString(path.head.assertion)
1041
- }), {
1042
- F: __dxlog_file4,
1043
- L: 223,
1044
- S: this,
1045
- C: (f, a) => f(...a)
1046
- });
956
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 217, S: this });
1047
957
  }
1048
958
  }
1049
959
  _forkTraversal(paths, path) {
@@ -1053,12 +963,7 @@ var CredentialGraph = class {
1053
963
  log("edge traversal", {
1054
964
  from: path.head.id,
1055
965
  to: choice.id
1056
- }, {
1057
- F: __dxlog_file4,
1058
- L: 234,
1059
- S: this,
1060
- C: (f, a) => f(...a)
1061
- });
966
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 227, S: this });
1062
967
  const fork = {
1063
968
  forkPoint: path,
1064
969
  chosenPath: {
@@ -1151,15 +1056,7 @@ var CredentialGraph = class {
1151
1056
  return path;
1152
1057
  }
1153
1058
  _mergePaths(convergedPaths) {
1154
- invariant4(convergedPaths.length >= 1, void 0, {
1155
- F: __dxlog_file4,
1156
- L: 324,
1157
- S: this,
1158
- A: [
1159
- "convergedPaths.length >= 1",
1160
- ""
1161
- ]
1162
- });
1059
+ invariant4(convergedPaths.length >= 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 320, S: this, A: ["convergedPaths.length >= 1", ""] });
1163
1060
  if (convergedPaths.length === 1) {
1164
1061
  return {
1165
1062
  type: "merged",
@@ -1171,22 +1068,9 @@ var CredentialGraph = class {
1171
1068
  forkPointId: forkPoint.head.id,
1172
1069
  pathCount: convergedPaths.length,
1173
1070
  forkPoints: convergedPaths.map((fp) => fp.forkPoint?.head.id)
1174
- }), {
1175
- F: __dxlog_file4,
1176
- L: 329,
1177
- S: this,
1178
- C: (f, a) => f(...a)
1179
- });
1071
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 328, S: this });
1180
1072
  const paths = convergedPaths.map((p) => this._moveUpToForkPoint(forkPoint, p));
1181
- invariant4(forkPoint, void 0, {
1182
- F: __dxlog_file4,
1183
- L: 335,
1184
- S: this,
1185
- A: [
1186
- "forkPoint",
1187
- ""
1188
- ]
1189
- });
1073
+ invariant4(forkPoint, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 334, S: this, A: ["forkPoint", ""] });
1190
1074
  const result = {
1191
1075
  forkPoint: forkPoint.forkPoint,
1192
1076
  chosenPath: {
@@ -1207,12 +1091,7 @@ var CredentialGraph = class {
1207
1091
  modified: path.forkChangedSubjects,
1208
1092
  forkIssuers: path.forkIssuers,
1209
1093
  state: path.state.mapValues((v) => this._stateHandler.toLogString(v.assertion))
1210
- }), {
1211
- F: __dxlog_file4,
1212
- L: 348,
1213
- S: this,
1214
- C: (f, a) => f(...a)
1215
- });
1094
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 350, S: this });
1216
1095
  path.forkIssuers.forEach((iss) => result.forkIssuers.add(iss));
1217
1096
  path.credentials.forEach((cred) => result.credentials.add(cred));
1218
1097
  result.chosenPath[forkPoint.head.id].push(...path.chosenPath[forkPoint.head.id] ?? []);
@@ -1232,12 +1111,7 @@ var CredentialGraph = class {
1232
1111
  log("set subject state", () => ({
1233
1112
  subject,
1234
1113
  state: this._stateHandler.toLogString(vertex.assertion)
1235
- }), {
1236
- F: __dxlog_file4,
1237
- L: 370,
1238
- S: this,
1239
- C: (f, a) => f(...a)
1240
- });
1114
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 372, S: this });
1241
1115
  const otherPaths = paths.filter((p) => p !== branch);
1242
1116
  this._stateHandler.getConflictingPaths(otherPaths, vertex).forEach(addReplayPath);
1243
1117
  }
@@ -1276,12 +1150,7 @@ var CredentialGraph = class {
1276
1150
  if (candidateVertex.id === mergePointId || currentVertex.id === mergePointId) {
1277
1151
  log("merge point chosen to break the tie", {
1278
1152
  mergePointId: existing.head.id
1279
- }, {
1280
- F: __dxlog_file4,
1281
- L: 408,
1282
- S: this,
1283
- C: (f, a) => f(...a)
1284
- });
1153
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 412, S: this });
1285
1154
  return mergePointId === candidateVertex.id;
1286
1155
  }
1287
1156
  const candidateCredential = candidateVertex.credential;
@@ -1290,12 +1159,7 @@ var CredentialGraph = class {
1290
1159
  log("one of the credentials was overridden in another branch", {
1291
1160
  current: currentVertex.id,
1292
1161
  candidate: candidateVertex.id
1293
- }, {
1294
- F: __dxlog_file4,
1295
- L: 415,
1296
- S: this,
1297
- C: (f, a) => f(...a)
1298
- });
1162
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 421, S: this });
1299
1163
  return candidate.credentials.has(currentCredential.id);
1300
1164
  }
1301
1165
  const winningCredential = this._stateHandler.tryPickWinningUpdate(existing, currentCredential, candidate, candidateCredential);
@@ -1308,20 +1172,10 @@ var CredentialGraph = class {
1308
1172
  existing.forkIssuers.size,
1309
1173
  candidate.forkIssuers.size
1310
1174
  ]
1311
- }, {
1312
- F: __dxlog_file4,
1313
- L: 432,
1314
- S: this,
1315
- C: (f, a) => f(...a)
1316
- });
1175
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 433, S: this });
1317
1176
  return candidate.forkIssuers.size > existing.forkIssuers.size;
1318
1177
  }
1319
- log("issuance date used to break the tie", void 0, {
1320
- F: __dxlog_file4,
1321
- L: 437,
1322
- S: this,
1323
- C: (f, a) => f(...a)
1324
- });
1178
+ log("issuance date used to break the tie", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 441, S: this });
1325
1179
  return candidateCredential.issuanceDate.getTime() > currentCredential.issuanceDate.getTime();
1326
1180
  }
1327
1181
  _createRootPath() {
@@ -1347,14 +1201,11 @@ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/halo/credentials/src/state-mac
1347
1201
  var MemberStateMachine = class {
1348
1202
  _spaceKey;
1349
1203
  _ownerKey;
1350
- _memberProfiles;
1351
- _hashgraph;
1352
- onMemberRoleChanged;
1204
+ _memberProfiles = new ComplexMap5(PublicKey7.hash);
1205
+ _hashgraph = new CredentialGraph(this);
1206
+ onMemberRoleChanged = this._hashgraph.onSubjectStateChanged;
1353
1207
  constructor(_spaceKey) {
1354
1208
  this._spaceKey = _spaceKey;
1355
- this._memberProfiles = new ComplexMap5(PublicKey7.hash);
1356
- this._hashgraph = new CredentialGraph(this);
1357
- this.onMemberRoleChanged = this._hashgraph.onSubjectStateChanged;
1358
1209
  }
1359
1210
  get creator() {
1360
1211
  return this._ownerKey && this._hashgraph.getSubjectState(this._ownerKey);
@@ -1376,15 +1227,7 @@ var MemberStateMachine = class {
1376
1227
  const assertion = getCredentialAssertion(credential);
1377
1228
  switch (assertion["@type"]) {
1378
1229
  case "dxos.halo.credentials.SpaceMember": {
1379
- invariant5(assertion.spaceKey.equals(this._spaceKey), void 0, {
1380
- F: __dxlog_file5,
1381
- L: 66,
1382
- S: this,
1383
- A: [
1384
- "assertion.spaceKey.equals(this._spaceKey)",
1385
- ""
1386
- ]
1387
- });
1230
+ invariant5(assertion.spaceKey.equals(this._spaceKey), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 43, S: this, A: ["assertion.spaceKey.equals(this._spaceKey)", ""] });
1388
1231
  if (this._ownerKey == null && credential.issuer === this._spaceKey) {
1389
1232
  this._ownerKey = credential.subject.id;
1390
1233
  }
@@ -1401,12 +1244,7 @@ var MemberStateMachine = class {
1401
1244
  } else {
1402
1245
  log2.warn("Member not found", {
1403
1246
  id: credential.subject.id
1404
- }, {
1405
- F: __dxlog_file5,
1406
- L: 81,
1407
- S: this,
1408
- C: (f, a) => f(...a)
1409
- });
1247
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 59, S: this });
1410
1248
  }
1411
1249
  this._memberProfiles.set(credential.subject.id, assertion.profile);
1412
1250
  break;
@@ -1451,12 +1289,7 @@ var MemberStateMachine = class {
1451
1289
  const path1IssuerRole = this._getRole(scope1, update1.issuer);
1452
1290
  const path2IssuerRole = this._getRole(scope2, update2.issuer);
1453
1291
  if (path2IssuerRole === SpaceMember2.Role.OWNER !== (path1IssuerRole === SpaceMember2.Role.OWNER)) {
1454
- log2("owner decision used to break the tie", void 0, {
1455
- F: __dxlog_file5,
1456
- L: 139,
1457
- S: this,
1458
- C: (f, a) => f(...a)
1459
- });
1292
+ log2("owner decision used to break the tie", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 107, S: this });
1460
1293
  return path1IssuerRole === SpaceMember2.Role.OWNER ? update1 : update2;
1461
1294
  }
1462
1295
  return null;
@@ -1480,12 +1313,7 @@ var MemberStateMachine = class {
1480
1313
  headId: scope.head?.id,
1481
1314
  roleOverride: this.toLogString(override.assertion),
1482
1315
  realRole: this.toLogString(scope.state.get(memberId)?.assertion)
1483
- }), {
1484
- F: __dxlog_file5,
1485
- L: 162,
1486
- S: this,
1487
- C: (f, a) => f(...a)
1488
- });
1316
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 127, S: this });
1489
1317
  return override.assertion.role;
1490
1318
  }
1491
1319
  }
@@ -1494,38 +1322,32 @@ var MemberStateMachine = class {
1494
1322
  };
1495
1323
 
1496
1324
  // src/state-machine/space-state-machine.ts
1325
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
1497
1326
  function _ts_decorate(decorators, target, key, desc) {
1498
1327
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1499
1328
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1500
1329
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1501
1330
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1502
1331
  }
1503
- var __dxlog_file6 = "/__w/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
1504
1332
  var SpaceStateMachine = class {
1505
1333
  _spaceKey;
1506
1334
  _members;
1507
1335
  _feeds;
1508
- _invitations;
1509
- _credentials;
1510
- _credentialsById;
1511
- _processedCredentials;
1336
+ _invitations = new InvitationStateMachine();
1337
+ _credentials = [];
1338
+ _credentialsById = new ComplexMap6(PublicKey8.hash);
1339
+ _processedCredentials = new ComplexSet3(PublicKey8.hash);
1512
1340
  _genesisCredential;
1513
- _credentialProcessors;
1514
- onCredentialProcessed;
1341
+ _tags = [];
1342
+ _membershipPolicy = MembershipPolicy2.INVITE;
1343
+ _credentialProcessors = [];
1344
+ onCredentialProcessed = new Callback4();
1515
1345
  onMemberRoleChanged;
1516
1346
  onFeedAdmitted;
1517
- onDelegatedInvitation;
1518
- onDelegatedInvitationRemoved;
1347
+ onDelegatedInvitation = this._invitations.onDelegatedInvitation;
1348
+ onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;
1519
1349
  constructor(_spaceKey) {
1520
1350
  this._spaceKey = _spaceKey;
1521
- this._invitations = new InvitationStateMachine();
1522
- this._credentials = [];
1523
- this._credentialsById = new ComplexMap6(PublicKey8.hash);
1524
- this._processedCredentials = new ComplexSet3(PublicKey8.hash);
1525
- this._credentialProcessors = [];
1526
- this.onCredentialProcessed = new Callback4();
1527
- this.onDelegatedInvitation = this._invitations.onDelegatedInvitation;
1528
- this.onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;
1529
1351
  this._members = new MemberStateMachine(this._spaceKey);
1530
1352
  this._feeds = new FeedStateMachine(this._spaceKey);
1531
1353
  this.onMemberRoleChanged = this._members.onMemberRoleChanged;
@@ -1552,6 +1374,12 @@ var SpaceStateMachine = class {
1552
1374
  get genesisCredential() {
1553
1375
  return this._genesisCredential;
1554
1376
  }
1377
+ get tags() {
1378
+ return this._tags;
1379
+ }
1380
+ get membershipPolicy() {
1381
+ return this._membershipPolicy;
1382
+ }
1555
1383
  get invitations() {
1556
1384
  return this._invitations.invitations;
1557
1385
  }
@@ -1591,12 +1419,7 @@ var SpaceStateMachine = class {
1591
1419
  if (!skipVerification) {
1592
1420
  const result = await verifyCredential(credential);
1593
1421
  if (result.kind !== "pass") {
1594
- log3.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, {
1595
- F: __dxlog_file6,
1596
- L: 162,
1597
- S: this,
1598
- C: (f, a) => f(...a)
1599
- });
1422
+ log3.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 116, S: this });
1600
1423
  return false;
1601
1424
  }
1602
1425
  }
@@ -1604,33 +1427,20 @@ var SpaceStateMachine = class {
1604
1427
  switch (assertion["@type"]) {
1605
1428
  case "dxos.halo.credentials.SpaceGenesis": {
1606
1429
  if (this._genesisCredential) {
1607
- log3.warn("Space already has a genesis credential.", void 0, {
1608
- F: __dxlog_file6,
1609
- L: 171,
1610
- S: this,
1611
- C: (f, a) => f(...a)
1612
- });
1430
+ log3.warn("Space already has a genesis credential.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 125, S: this });
1613
1431
  return false;
1614
1432
  }
1615
1433
  if (!credential.issuer.equals(this._spaceKey)) {
1616
- log3.warn("Space genesis credential must be issued by space.", void 0, {
1617
- F: __dxlog_file6,
1618
- L: 175,
1619
- S: this,
1620
- C: (f, a) => f(...a)
1621
- });
1434
+ log3.warn("Space genesis credential must be issued by space.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 129, S: this });
1622
1435
  return false;
1623
1436
  }
1624
1437
  if (!credential.subject.id.equals(this._spaceKey)) {
1625
- log3.warn("Space genesis credential must be issued to space.", void 0, {
1626
- F: __dxlog_file6,
1627
- L: 179,
1628
- S: this,
1629
- C: (f, a) => f(...a)
1630
- });
1438
+ log3.warn("Space genesis credential must be issued to space.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 133, S: this });
1631
1439
  return false;
1632
1440
  }
1633
1441
  this._genesisCredential = credential;
1442
+ this._tags = assertion.tags ?? [];
1443
+ this._membershipPolicy = assertion.membershipPolicy ?? MembershipPolicy2.INVITE;
1634
1444
  break;
1635
1445
  }
1636
1446
  case "dxos.halo.credentials.SpaceMember": {
@@ -1638,21 +1448,11 @@ var SpaceStateMachine = class {
1638
1448
  break;
1639
1449
  }
1640
1450
  if (!this._genesisCredential) {
1641
- log3.warn("Space must have a genesis credential before adding members.", void 0, {
1642
- F: __dxlog_file6,
1643
- L: 192,
1644
- S: this,
1645
- C: (f, a) => f(...a)
1646
- });
1451
+ log3.warn("Space must have a genesis credential before adding members.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 147, S: this });
1647
1452
  return false;
1648
1453
  }
1649
1454
  if (!this._canInviteNewMembers(credential.issuer)) {
1650
- log3.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1651
- F: __dxlog_file6,
1652
- L: 196,
1653
- S: this,
1654
- C: (f, a) => f(...a)
1655
- });
1455
+ log3.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 151, S: this });
1656
1456
  return false;
1657
1457
  }
1658
1458
  await this._members.process(credential);
@@ -1661,12 +1461,7 @@ var SpaceStateMachine = class {
1661
1461
  }
1662
1462
  case "dxos.halo.credentials.MemberProfile": {
1663
1463
  if (!this._genesisCredential) {
1664
- log3.warn("Space must have a genesis credential before adding members.", void 0, {
1665
- F: __dxlog_file6,
1666
- L: 207,
1667
- S: this,
1668
- C: (f, a) => f(...a)
1669
- });
1464
+ log3.warn("Space must have a genesis credential before adding members.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 161, S: this });
1670
1465
  return false;
1671
1466
  }
1672
1467
  await this._members.process(credential);
@@ -1674,12 +1469,7 @@ var SpaceStateMachine = class {
1674
1469
  }
1675
1470
  case "dxos.halo.credentials.AdmittedFeed": {
1676
1471
  if (!this._genesisCredential) {
1677
- log3.warn("Space must have a genesis credential before admitting feeds.", void 0, {
1678
- F: __dxlog_file6,
1679
- L: 217,
1680
- S: this,
1681
- C: (f, a) => f(...a)
1682
- });
1472
+ log3.warn("Space must have a genesis credential before admitting feeds.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 170, S: this });
1683
1473
  return false;
1684
1474
  }
1685
1475
  await this._feeds.process(credential, sourceFeed);
@@ -1688,12 +1478,7 @@ var SpaceStateMachine = class {
1688
1478
  case "dxos.halo.invitations.CancelDelegatedInvitation":
1689
1479
  case "dxos.halo.invitations.DelegateSpaceInvitation": {
1690
1480
  if (!this._canInviteNewMembers(credential.issuer)) {
1691
- log3.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1692
- F: __dxlog_file6,
1693
- L: 228,
1694
- S: this,
1695
- C: (f, a) => f(...a)
1696
- });
1481
+ log3.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 181, S: this });
1697
1482
  return false;
1698
1483
  }
1699
1484
  await this._invitations.process(credential);
@@ -1724,6 +1509,9 @@ var SpaceStateMachine = class {
1724
1509
  return this._canInviteNewMembers(memberKey);
1725
1510
  }
1726
1511
  _canInviteNewMembers(key) {
1512
+ if (this._membershipPolicy === MembershipPolicy2.LOCKED) {
1513
+ return key.equals(this._spaceKey) && this._members.members.size === 0;
1514
+ }
1727
1515
  return key.equals(this._spaceKey) || this._members.getRole(key) === SpaceMember3.Role.ADMIN || this._members.getRole(key) === SpaceMember3.Role.OWNER;
1728
1516
  }
1729
1517
  };
@@ -1734,23 +1522,18 @@ var CredentialConsumer = class {
1734
1522
  processor;
1735
1523
  _onOpen;
1736
1524
  _onClose;
1737
- _ctx;
1525
+ _ctx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 229 });
1738
1526
  /**
1739
1527
  * @internal
1740
1528
  * Processor is ready to process live credentials.
1741
1529
  * NOTE: Setting this flag before all existing credentials are processed will cause them to be processed out of order.
1742
1530
  * Set externally.
1743
1531
  */
1744
- _isReadyForLiveCredentials;
1532
+ _isReadyForLiveCredentials = false;
1745
1533
  constructor(processor, _onOpen, _onClose) {
1746
1534
  this.processor = processor;
1747
1535
  this._onOpen = _onOpen;
1748
1536
  this._onClose = _onClose;
1749
- this._ctx = new Context(void 0, {
1750
- F: __dxlog_file6,
1751
- L: 273
1752
- });
1753
- this._isReadyForLiveCredentials = false;
1754
1537
  }
1755
1538
  /**
1756
1539
  * @internal
@@ -1782,25 +1565,18 @@ var __dxlog_file7 = "/__w/dxos/dxos/packages/core/halo/credentials/src/processor
1782
1565
  var DeviceStateMachine = class {
1783
1566
  _params;
1784
1567
  // TODO(burdon): Return values via getter.
1785
- authorizedDeviceKeys;
1786
- deviceChainReady;
1568
+ authorizedDeviceKeys = new ComplexMap7(PublicKey9.hash);
1569
+ deviceChainReady = new Trigger();
1787
1570
  deviceCredentialChain;
1788
1571
  constructor(_params) {
1789
1572
  this._params = _params;
1790
- this.authorizedDeviceKeys = new ComplexMap7(PublicKey9.hash);
1791
- this.deviceChainReady = new Trigger();
1792
1573
  }
1793
1574
  async processCredential(credential) {
1794
1575
  log4("processing credential...", {
1795
1576
  identityKey: this._params.identityKey,
1796
1577
  deviceKey: this._params.deviceKey,
1797
1578
  credential
1798
- }, {
1799
- F: __dxlog_file7,
1800
- L: 36,
1801
- S: this,
1802
- C: (f, a) => f(...a)
1803
- });
1579
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 22, S: this });
1804
1580
  if (isValidAuthorizedDeviceCredential(credential, this._params.identityKey, this._params.deviceKey)) {
1805
1581
  this.deviceCredentialChain = {
1806
1582
  credential
@@ -1815,35 +1591,17 @@ var DeviceStateMachine = class {
1815
1591
  localDeviceKey: this._params.deviceKey,
1816
1592
  deviceKey: assertion.deviceKey,
1817
1593
  size: this.authorizedDeviceKeys.size
1818
- }, {
1819
- F: __dxlog_file7,
1820
- L: 56,
1821
- S: this,
1822
- C: (f, a) => f(...a)
1823
- });
1594
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 41, S: this });
1824
1595
  this._params.onUpdate?.();
1825
1596
  break;
1826
1597
  }
1827
1598
  case "dxos.halo.credentials.DeviceProfile": {
1828
- invariant6(this.authorizedDeviceKeys.has(credential.subject.id), "Device not found.", {
1829
- F: __dxlog_file7,
1830
- L: 66,
1831
- S: this,
1832
- A: [
1833
- "this.authorizedDeviceKeys.has(credential.subject.id)",
1834
- "'Device not found.'"
1835
- ]
1836
- });
1599
+ invariant6(this.authorizedDeviceKeys.has(credential.subject.id), "Device not found.", { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 51, S: this, A: ["this.authorizedDeviceKeys.has(credential.subject.id)", "'Device not found.'"] });
1837
1600
  if (assertion && credential.subject.id.equals(this._params.deviceKey)) {
1838
1601
  log4.trace("dxos.halo.device", {
1839
1602
  deviceKey: credential.subject.id,
1840
1603
  profile: assertion.profile
1841
- }, {
1842
- F: __dxlog_file7,
1843
- L: 69,
1844
- S: this,
1845
- C: (f, a) => f(...a)
1846
- });
1604
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 53, S: this });
1847
1605
  }
1848
1606
  this.authorizedDeviceKeys.set(credential.subject.id, assertion.profile);
1849
1607
  this._params.onUpdate?.();
@@ -1871,24 +1629,14 @@ var ProfileStateMachine = class {
1871
1629
  log5.warn("Invalid profile credential", {
1872
1630
  expectedIdentity: this._params.identityKey,
1873
1631
  credential
1874
- }, {
1875
- F: __dxlog_file8,
1876
- L: 35,
1877
- S: this,
1878
- C: (f, a) => f(...a)
1879
- });
1632
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 21, S: this });
1880
1633
  return;
1881
1634
  }
1882
1635
  this.profile = assertion.profile;
1883
1636
  log5("updated profile", {
1884
1637
  identityKey: this._params.identityKey,
1885
1638
  profile: this.profile
1886
- }, {
1887
- F: __dxlog_file8,
1888
- L: 41,
1889
- S: this,
1890
- C: (f, a) => f(...a)
1891
- });
1639
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 29, S: this });
1892
1640
  this._params.onUpdate?.();
1893
1641
  break;
1894
1642
  }