@dxos/credentials 0.8.4-main.fffef41 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/{browser → neutral}/index.mjs +83 -311
  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 +19 -20
  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/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  47. package/dist/lib/browser/index.mjs.map +0 -7
  48. package/dist/lib/browser/meta.json +0 -1
  49. package/dist/lib/node-esm/index.mjs +0 -1912
  50. package/dist/lib/node-esm/index.mjs.map +0 -7
  51. 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
@@ -657,24 +643,8 @@ var FeedStateMachine = class {
657
643
  */
658
644
  async process(credential, fromFeed) {
659
645
  const assertion = getCredentialAssertion(credential);
660
- invariant3(assertion["@type"] === "dxos.halo.credentials.AdmittedFeed", void 0, {
661
- F: __dxlog_file3,
662
- L: 47,
663
- S: this,
664
- A: [
665
- "assertion['@type'] === 'dxos.halo.credentials.AdmittedFeed'",
666
- ""
667
- ]
668
- });
669
- invariant3(assertion.spaceKey.equals(this._spaceKey), void 0, {
670
- F: __dxlog_file3,
671
- L: 48,
672
- S: this,
673
- A: [
674
- "assertion.spaceKey.equals(this._spaceKey)",
675
- ""
676
- ]
677
- });
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)", ""] });
678
648
  const info = {
679
649
  key: credential.subject.id,
680
650
  credential,
@@ -837,12 +807,7 @@ var CredentialGraph = class {
837
807
  log.error("credential skipped because of the unknown parent", {
838
808
  credential,
839
809
  parentId
840
- }, {
841
- F: __dxlog_file4,
842
- L: 72,
843
- S: this,
844
- C: (f, a) => f(...a)
845
- });
810
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 70, S: this });
846
811
  continue;
847
812
  }
848
813
  parentVertex.children.push(newVertex);
@@ -859,29 +824,13 @@ var CredentialGraph = class {
859
824
  if (sentinelIdx >= 0) {
860
825
  vertex.children.splice(sentinelIdx, 1);
861
826
  const vertexInSentinelIdx = this._sentinel.parents.indexOf(vertex);
862
- invariant4(vertexInSentinelIdx >= 0, void 0, {
863
- F: __dxlog_file4,
864
- L: 90,
865
- S: this,
866
- A: [
867
- "vertexInSentinelIdx >= 0",
868
- ""
869
- ]
870
- });
827
+ invariant4(vertexInSentinelIdx >= 0, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 90, S: this, A: ["vertexInSentinelIdx >= 0", ""] });
871
828
  this._sentinel.parents.splice(vertexInSentinelIdx, 1);
872
829
  }
873
830
  }
874
831
  async _onVertexInserted(newVertex) {
875
832
  const { credential, assertion } = newVertex;
876
- invariant4(credential, void 0, {
877
- F: __dxlog_file4,
878
- L: 97,
879
- S: this,
880
- A: [
881
- "credential",
882
- ""
883
- ]
884
- });
833
+ invariant4(credential, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 96, S: this, A: ["credential", ""] });
885
834
  let changedSubjects = [];
886
835
  const isUpdateAppliedOnTopOfThePreviousState = this._sentinel.parents.length === 1;
887
836
  if (isUpdateAppliedOnTopOfThePreviousState) {
@@ -918,21 +867,11 @@ var CredentialGraph = class {
918
867
  const path = paths.pop();
919
868
  log("visit vertex", {
920
869
  id: path.head.id
921
- }, {
922
- F: __dxlog_file4,
923
- L: 132,
924
- S: this,
925
- C: (f, a) => f(...a)
926
- });
870
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 131, S: this });
927
871
  this._updatePathState(path);
928
872
  const convergedPaths = this._handleMergePoint(paths, pendingPaths, path);
929
873
  if (convergedPaths == null) {
930
- log("waiting for other paths", void 0, {
931
- F: __dxlog_file4,
932
- L: 136,
933
- S: this,
934
- C: (f, a) => f(...a)
935
- });
874
+ log("waiting for other paths", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 137, S: this });
936
875
  continue;
937
876
  }
938
877
  const mergeResult = this._mergePaths(convergedPaths);
@@ -956,12 +895,7 @@ var CredentialGraph = class {
956
895
  path: toChosenPath(p),
957
896
  head: p.head.id
958
897
  }))
959
- }, {
960
- F: __dxlog_file4,
961
- L: 155,
962
- S: this,
963
- C: (f, a) => f(...a)
964
- });
898
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 156, S: this });
965
899
  }
966
900
  return this._setCurrentState(lastPath);
967
901
  }
@@ -982,12 +916,7 @@ var CredentialGraph = class {
982
916
  path: toChosenPath(path),
983
917
  overrides: path?.stateOverrides?.mapValues((v) => this._stateHandler.toLogString(v.assertion))
984
918
  }))
985
- }), {
986
- F: __dxlog_file4,
987
- L: 175,
988
- S: this,
989
- C: (f, a) => f(...a)
990
- });
919
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 175, S: this });
991
920
  const clearedPending = convergedPaths.filter((l) => !mergeResult.replay.includes(l));
992
921
  pendingPaths.set(convergedPaths[0].head.id, clearedPending);
993
922
  }
@@ -999,12 +928,7 @@ var CredentialGraph = class {
999
928
  return null;
1000
929
  }
1001
930
  if (path.head.id === this._sentinel.id && paths.length > 0) {
1002
- log("waiting for all the active paths to converge on the sentinel", void 0, {
1003
- F: __dxlog_file4,
1004
- L: 199,
1005
- S: this,
1006
- C: (f, a) => f(...a)
1007
- });
931
+ log("waiting for all the active paths to converge on the sentinel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 194, S: this });
1008
932
  return null;
1009
933
  }
1010
934
  pendingPaths.delete(path.head.id);
@@ -1029,12 +953,7 @@ var CredentialGraph = class {
1029
953
  log("path state updated", () => ({
1030
954
  subject: updatedSubject,
1031
955
  newState: this._stateHandler.toLogString(path.head.assertion)
1032
- }), {
1033
- F: __dxlog_file4,
1034
- L: 223,
1035
- S: this,
1036
- C: (f, a) => f(...a)
1037
- });
956
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 217, S: this });
1038
957
  }
1039
958
  }
1040
959
  _forkTraversal(paths, path) {
@@ -1044,12 +963,7 @@ var CredentialGraph = class {
1044
963
  log("edge traversal", {
1045
964
  from: path.head.id,
1046
965
  to: choice.id
1047
- }, {
1048
- F: __dxlog_file4,
1049
- L: 234,
1050
- S: this,
1051
- C: (f, a) => f(...a)
1052
- });
966
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 227, S: this });
1053
967
  const fork = {
1054
968
  forkPoint: path,
1055
969
  chosenPath: {
@@ -1142,15 +1056,7 @@ var CredentialGraph = class {
1142
1056
  return path;
1143
1057
  }
1144
1058
  _mergePaths(convergedPaths) {
1145
- invariant4(convergedPaths.length >= 1, void 0, {
1146
- F: __dxlog_file4,
1147
- L: 324,
1148
- S: this,
1149
- A: [
1150
- "convergedPaths.length >= 1",
1151
- ""
1152
- ]
1153
- });
1059
+ invariant4(convergedPaths.length >= 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 320, S: this, A: ["convergedPaths.length >= 1", ""] });
1154
1060
  if (convergedPaths.length === 1) {
1155
1061
  return {
1156
1062
  type: "merged",
@@ -1162,22 +1068,9 @@ var CredentialGraph = class {
1162
1068
  forkPointId: forkPoint.head.id,
1163
1069
  pathCount: convergedPaths.length,
1164
1070
  forkPoints: convergedPaths.map((fp) => fp.forkPoint?.head.id)
1165
- }), {
1166
- F: __dxlog_file4,
1167
- L: 329,
1168
- S: this,
1169
- C: (f, a) => f(...a)
1170
- });
1071
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 328, S: this });
1171
1072
  const paths = convergedPaths.map((p) => this._moveUpToForkPoint(forkPoint, p));
1172
- invariant4(forkPoint, void 0, {
1173
- F: __dxlog_file4,
1174
- L: 335,
1175
- S: this,
1176
- A: [
1177
- "forkPoint",
1178
- ""
1179
- ]
1180
- });
1073
+ invariant4(forkPoint, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 334, S: this, A: ["forkPoint", ""] });
1181
1074
  const result = {
1182
1075
  forkPoint: forkPoint.forkPoint,
1183
1076
  chosenPath: {
@@ -1198,12 +1091,7 @@ var CredentialGraph = class {
1198
1091
  modified: path.forkChangedSubjects,
1199
1092
  forkIssuers: path.forkIssuers,
1200
1093
  state: path.state.mapValues((v) => this._stateHandler.toLogString(v.assertion))
1201
- }), {
1202
- F: __dxlog_file4,
1203
- L: 348,
1204
- S: this,
1205
- C: (f, a) => f(...a)
1206
- });
1094
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 350, S: this });
1207
1095
  path.forkIssuers.forEach((iss) => result.forkIssuers.add(iss));
1208
1096
  path.credentials.forEach((cred) => result.credentials.add(cred));
1209
1097
  result.chosenPath[forkPoint.head.id].push(...path.chosenPath[forkPoint.head.id] ?? []);
@@ -1223,12 +1111,7 @@ var CredentialGraph = class {
1223
1111
  log("set subject state", () => ({
1224
1112
  subject,
1225
1113
  state: this._stateHandler.toLogString(vertex.assertion)
1226
- }), {
1227
- F: __dxlog_file4,
1228
- L: 370,
1229
- S: this,
1230
- C: (f, a) => f(...a)
1231
- });
1114
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 372, S: this });
1232
1115
  const otherPaths = paths.filter((p) => p !== branch);
1233
1116
  this._stateHandler.getConflictingPaths(otherPaths, vertex).forEach(addReplayPath);
1234
1117
  }
@@ -1267,12 +1150,7 @@ var CredentialGraph = class {
1267
1150
  if (candidateVertex.id === mergePointId || currentVertex.id === mergePointId) {
1268
1151
  log("merge point chosen to break the tie", {
1269
1152
  mergePointId: existing.head.id
1270
- }, {
1271
- F: __dxlog_file4,
1272
- L: 408,
1273
- S: this,
1274
- C: (f, a) => f(...a)
1275
- });
1153
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 412, S: this });
1276
1154
  return mergePointId === candidateVertex.id;
1277
1155
  }
1278
1156
  const candidateCredential = candidateVertex.credential;
@@ -1281,12 +1159,7 @@ var CredentialGraph = class {
1281
1159
  log("one of the credentials was overridden in another branch", {
1282
1160
  current: currentVertex.id,
1283
1161
  candidate: candidateVertex.id
1284
- }, {
1285
- F: __dxlog_file4,
1286
- L: 415,
1287
- S: this,
1288
- C: (f, a) => f(...a)
1289
- });
1162
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 421, S: this });
1290
1163
  return candidate.credentials.has(currentCredential.id);
1291
1164
  }
1292
1165
  const winningCredential = this._stateHandler.tryPickWinningUpdate(existing, currentCredential, candidate, candidateCredential);
@@ -1299,20 +1172,10 @@ var CredentialGraph = class {
1299
1172
  existing.forkIssuers.size,
1300
1173
  candidate.forkIssuers.size
1301
1174
  ]
1302
- }, {
1303
- F: __dxlog_file4,
1304
- L: 432,
1305
- S: this,
1306
- C: (f, a) => f(...a)
1307
- });
1175
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 433, S: this });
1308
1176
  return candidate.forkIssuers.size > existing.forkIssuers.size;
1309
1177
  }
1310
- log("issuance date used to break the tie", void 0, {
1311
- F: __dxlog_file4,
1312
- L: 437,
1313
- S: this,
1314
- C: (f, a) => f(...a)
1315
- });
1178
+ log("issuance date used to break the tie", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 441, S: this });
1316
1179
  return candidateCredential.issuanceDate.getTime() > currentCredential.issuanceDate.getTime();
1317
1180
  }
1318
1181
  _createRootPath() {
@@ -1364,15 +1227,7 @@ var MemberStateMachine = class {
1364
1227
  const assertion = getCredentialAssertion(credential);
1365
1228
  switch (assertion["@type"]) {
1366
1229
  case "dxos.halo.credentials.SpaceMember": {
1367
- invariant5(assertion.spaceKey.equals(this._spaceKey), void 0, {
1368
- F: __dxlog_file5,
1369
- L: 66,
1370
- S: this,
1371
- A: [
1372
- "assertion.spaceKey.equals(this._spaceKey)",
1373
- ""
1374
- ]
1375
- });
1230
+ invariant5(assertion.spaceKey.equals(this._spaceKey), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 43, S: this, A: ["assertion.spaceKey.equals(this._spaceKey)", ""] });
1376
1231
  if (this._ownerKey == null && credential.issuer === this._spaceKey) {
1377
1232
  this._ownerKey = credential.subject.id;
1378
1233
  }
@@ -1389,12 +1244,7 @@ var MemberStateMachine = class {
1389
1244
  } else {
1390
1245
  log2.warn("Member not found", {
1391
1246
  id: credential.subject.id
1392
- }, {
1393
- F: __dxlog_file5,
1394
- L: 81,
1395
- S: this,
1396
- C: (f, a) => f(...a)
1397
- });
1247
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 59, S: this });
1398
1248
  }
1399
1249
  this._memberProfiles.set(credential.subject.id, assertion.profile);
1400
1250
  break;
@@ -1439,12 +1289,7 @@ var MemberStateMachine = class {
1439
1289
  const path1IssuerRole = this._getRole(scope1, update1.issuer);
1440
1290
  const path2IssuerRole = this._getRole(scope2, update2.issuer);
1441
1291
  if (path2IssuerRole === SpaceMember2.Role.OWNER !== (path1IssuerRole === SpaceMember2.Role.OWNER)) {
1442
- log2("owner decision used to break the tie", void 0, {
1443
- F: __dxlog_file5,
1444
- L: 139,
1445
- S: this,
1446
- C: (f, a) => f(...a)
1447
- });
1292
+ log2("owner decision used to break the tie", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 107, S: this });
1448
1293
  return path1IssuerRole === SpaceMember2.Role.OWNER ? update1 : update2;
1449
1294
  }
1450
1295
  return null;
@@ -1468,12 +1313,7 @@ var MemberStateMachine = class {
1468
1313
  headId: scope.head?.id,
1469
1314
  roleOverride: this.toLogString(override.assertion),
1470
1315
  realRole: this.toLogString(scope.state.get(memberId)?.assertion)
1471
- }), {
1472
- F: __dxlog_file5,
1473
- L: 162,
1474
- S: this,
1475
- C: (f, a) => f(...a)
1476
- });
1316
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 127, S: this });
1477
1317
  return override.assertion.role;
1478
1318
  }
1479
1319
  }
@@ -1482,13 +1322,13 @@ var MemberStateMachine = class {
1482
1322
  };
1483
1323
 
1484
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";
1485
1326
  function _ts_decorate(decorators, target, key, desc) {
1486
1327
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1487
1328
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1488
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;
1489
1330
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1490
1331
  }
1491
- var __dxlog_file6 = "/__w/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
1492
1332
  var SpaceStateMachine = class {
1493
1333
  _spaceKey;
1494
1334
  _members;
@@ -1498,6 +1338,8 @@ var SpaceStateMachine = class {
1498
1338
  _credentialsById = new ComplexMap6(PublicKey8.hash);
1499
1339
  _processedCredentials = new ComplexSet3(PublicKey8.hash);
1500
1340
  _genesisCredential;
1341
+ _tags = [];
1342
+ _membershipPolicy = MembershipPolicy2.INVITE;
1501
1343
  _credentialProcessors = [];
1502
1344
  onCredentialProcessed = new Callback4();
1503
1345
  onMemberRoleChanged;
@@ -1532,6 +1374,12 @@ var SpaceStateMachine = class {
1532
1374
  get genesisCredential() {
1533
1375
  return this._genesisCredential;
1534
1376
  }
1377
+ get tags() {
1378
+ return this._tags;
1379
+ }
1380
+ get membershipPolicy() {
1381
+ return this._membershipPolicy;
1382
+ }
1535
1383
  get invitations() {
1536
1384
  return this._invitations.invitations;
1537
1385
  }
@@ -1571,12 +1419,7 @@ var SpaceStateMachine = class {
1571
1419
  if (!skipVerification) {
1572
1420
  const result = await verifyCredential(credential);
1573
1421
  if (result.kind !== "pass") {
1574
- log3.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, {
1575
- F: __dxlog_file6,
1576
- L: 162,
1577
- S: this,
1578
- C: (f, a) => f(...a)
1579
- });
1422
+ log3.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 116, S: this });
1580
1423
  return false;
1581
1424
  }
1582
1425
  }
@@ -1584,33 +1427,20 @@ var SpaceStateMachine = class {
1584
1427
  switch (assertion["@type"]) {
1585
1428
  case "dxos.halo.credentials.SpaceGenesis": {
1586
1429
  if (this._genesisCredential) {
1587
- log3.warn("Space already has a genesis credential.", void 0, {
1588
- F: __dxlog_file6,
1589
- L: 171,
1590
- S: this,
1591
- C: (f, a) => f(...a)
1592
- });
1430
+ log3.warn("Space already has a genesis credential.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 125, S: this });
1593
1431
  return false;
1594
1432
  }
1595
1433
  if (!credential.issuer.equals(this._spaceKey)) {
1596
- log3.warn("Space genesis credential must be issued by space.", void 0, {
1597
- F: __dxlog_file6,
1598
- L: 175,
1599
- S: this,
1600
- C: (f, a) => f(...a)
1601
- });
1434
+ log3.warn("Space genesis credential must be issued by space.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 129, S: this });
1602
1435
  return false;
1603
1436
  }
1604
1437
  if (!credential.subject.id.equals(this._spaceKey)) {
1605
- log3.warn("Space genesis credential must be issued to space.", void 0, {
1606
- F: __dxlog_file6,
1607
- L: 179,
1608
- S: this,
1609
- C: (f, a) => f(...a)
1610
- });
1438
+ log3.warn("Space genesis credential must be issued to space.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 133, S: this });
1611
1439
  return false;
1612
1440
  }
1613
1441
  this._genesisCredential = credential;
1442
+ this._tags = assertion.tags ?? [];
1443
+ this._membershipPolicy = assertion.membershipPolicy ?? MembershipPolicy2.INVITE;
1614
1444
  break;
1615
1445
  }
1616
1446
  case "dxos.halo.credentials.SpaceMember": {
@@ -1618,21 +1448,11 @@ var SpaceStateMachine = class {
1618
1448
  break;
1619
1449
  }
1620
1450
  if (!this._genesisCredential) {
1621
- log3.warn("Space must have a genesis credential before adding members.", void 0, {
1622
- F: __dxlog_file6,
1623
- L: 192,
1624
- S: this,
1625
- C: (f, a) => f(...a)
1626
- });
1451
+ log3.warn("Space must have a genesis credential before adding members.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 147, S: this });
1627
1452
  return false;
1628
1453
  }
1629
1454
  if (!this._canInviteNewMembers(credential.issuer)) {
1630
- log3.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1631
- F: __dxlog_file6,
1632
- L: 196,
1633
- S: this,
1634
- C: (f, a) => f(...a)
1635
- });
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 });
1636
1456
  return false;
1637
1457
  }
1638
1458
  await this._members.process(credential);
@@ -1641,12 +1461,7 @@ var SpaceStateMachine = class {
1641
1461
  }
1642
1462
  case "dxos.halo.credentials.MemberProfile": {
1643
1463
  if (!this._genesisCredential) {
1644
- log3.warn("Space must have a genesis credential before adding members.", void 0, {
1645
- F: __dxlog_file6,
1646
- L: 207,
1647
- S: this,
1648
- C: (f, a) => f(...a)
1649
- });
1464
+ log3.warn("Space must have a genesis credential before adding members.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 161, S: this });
1650
1465
  return false;
1651
1466
  }
1652
1467
  await this._members.process(credential);
@@ -1654,12 +1469,7 @@ var SpaceStateMachine = class {
1654
1469
  }
1655
1470
  case "dxos.halo.credentials.AdmittedFeed": {
1656
1471
  if (!this._genesisCredential) {
1657
- log3.warn("Space must have a genesis credential before admitting feeds.", void 0, {
1658
- F: __dxlog_file6,
1659
- L: 217,
1660
- S: this,
1661
- C: (f, a) => f(...a)
1662
- });
1472
+ log3.warn("Space must have a genesis credential before admitting feeds.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 170, S: this });
1663
1473
  return false;
1664
1474
  }
1665
1475
  await this._feeds.process(credential, sourceFeed);
@@ -1668,12 +1478,7 @@ var SpaceStateMachine = class {
1668
1478
  case "dxos.halo.invitations.CancelDelegatedInvitation":
1669
1479
  case "dxos.halo.invitations.DelegateSpaceInvitation": {
1670
1480
  if (!this._canInviteNewMembers(credential.issuer)) {
1671
- log3.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1672
- F: __dxlog_file6,
1673
- L: 228,
1674
- S: this,
1675
- C: (f, a) => f(...a)
1676
- });
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 });
1677
1482
  return false;
1678
1483
  }
1679
1484
  await this._invitations.process(credential);
@@ -1704,6 +1509,9 @@ var SpaceStateMachine = class {
1704
1509
  return this._canInviteNewMembers(memberKey);
1705
1510
  }
1706
1511
  _canInviteNewMembers(key) {
1512
+ if (this._membershipPolicy === MembershipPolicy2.LOCKED) {
1513
+ return key.equals(this._spaceKey) && this._members.members.size === 0;
1514
+ }
1707
1515
  return key.equals(this._spaceKey) || this._members.getRole(key) === SpaceMember3.Role.ADMIN || this._members.getRole(key) === SpaceMember3.Role.OWNER;
1708
1516
  }
1709
1517
  };
@@ -1714,10 +1522,7 @@ var CredentialConsumer = class {
1714
1522
  processor;
1715
1523
  _onOpen;
1716
1524
  _onClose;
1717
- _ctx = new Context(void 0, {
1718
- F: __dxlog_file6,
1719
- L: 273
1720
- });
1525
+ _ctx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 229 });
1721
1526
  /**
1722
1527
  * @internal
1723
1528
  * Processor is ready to process live credentials.
@@ -1771,12 +1576,7 @@ var DeviceStateMachine = class {
1771
1576
  identityKey: this._params.identityKey,
1772
1577
  deviceKey: this._params.deviceKey,
1773
1578
  credential
1774
- }, {
1775
- F: __dxlog_file7,
1776
- L: 36,
1777
- S: this,
1778
- C: (f, a) => f(...a)
1779
- });
1579
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 22, S: this });
1780
1580
  if (isValidAuthorizedDeviceCredential(credential, this._params.identityKey, this._params.deviceKey)) {
1781
1581
  this.deviceCredentialChain = {
1782
1582
  credential
@@ -1791,35 +1591,17 @@ var DeviceStateMachine = class {
1791
1591
  localDeviceKey: this._params.deviceKey,
1792
1592
  deviceKey: assertion.deviceKey,
1793
1593
  size: this.authorizedDeviceKeys.size
1794
- }, {
1795
- F: __dxlog_file7,
1796
- L: 56,
1797
- S: this,
1798
- C: (f, a) => f(...a)
1799
- });
1594
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 41, S: this });
1800
1595
  this._params.onUpdate?.();
1801
1596
  break;
1802
1597
  }
1803
1598
  case "dxos.halo.credentials.DeviceProfile": {
1804
- invariant6(this.authorizedDeviceKeys.has(credential.subject.id), "Device not found.", {
1805
- F: __dxlog_file7,
1806
- L: 66,
1807
- S: this,
1808
- A: [
1809
- "this.authorizedDeviceKeys.has(credential.subject.id)",
1810
- "'Device not found.'"
1811
- ]
1812
- });
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.'"] });
1813
1600
  if (assertion && credential.subject.id.equals(this._params.deviceKey)) {
1814
1601
  log4.trace("dxos.halo.device", {
1815
1602
  deviceKey: credential.subject.id,
1816
1603
  profile: assertion.profile
1817
- }, {
1818
- F: __dxlog_file7,
1819
- L: 69,
1820
- S: this,
1821
- C: (f, a) => f(...a)
1822
- });
1604
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 53, S: this });
1823
1605
  }
1824
1606
  this.authorizedDeviceKeys.set(credential.subject.id, assertion.profile);
1825
1607
  this._params.onUpdate?.();
@@ -1847,24 +1629,14 @@ var ProfileStateMachine = class {
1847
1629
  log5.warn("Invalid profile credential", {
1848
1630
  expectedIdentity: this._params.identityKey,
1849
1631
  credential
1850
- }, {
1851
- F: __dxlog_file8,
1852
- L: 35,
1853
- S: this,
1854
- C: (f, a) => f(...a)
1855
- });
1632
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 21, S: this });
1856
1633
  return;
1857
1634
  }
1858
1635
  this.profile = assertion.profile;
1859
1636
  log5("updated profile", {
1860
1637
  identityKey: this._params.identityKey,
1861
1638
  profile: this.profile
1862
- }, {
1863
- F: __dxlog_file8,
1864
- L: 41,
1865
- S: this,
1866
- C: (f, a) => f(...a)
1867
- });
1639
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 29, S: this });
1868
1640
  this._params.onUpdate?.();
1869
1641
  break;
1870
1642
  }