@dxos/credentials 0.4.10-main.fd8ea31 → 0.4.10-next.71cec10

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.
@@ -31,7 +31,6 @@ __export(node_exports, {
31
31
  CredentialGenerator: () => CredentialGenerator,
32
32
  DeviceStateMachine: () => DeviceStateMachine,
33
33
  FeedStateMachine: () => FeedStateMachine,
34
- InvitationStateMachine: () => InvitationStateMachine,
35
34
  MemberStateMachine: () => MemberStateMachine,
36
35
  ProfileStateMachine: () => ProfileStateMachine,
37
36
  SIGNATURE_TYPE_ED25519: () => SIGNATURE_TYPE_ED25519,
@@ -43,7 +42,6 @@ __export(node_exports, {
43
42
  createCredentialMessage: () => createCredentialMessage,
44
43
  createCredentialSignerWithChain: () => createCredentialSignerWithChain,
45
44
  createCredentialSignerWithKey: () => createCredentialSignerWithKey,
46
- createDelegatedSpaceInvitationCredential: () => createDelegatedSpaceInvitationCredential,
47
45
  createDeviceAuthorization: () => createDeviceAuthorization,
48
46
  credentialTypeFilter: () => credentialTypeFilter,
49
47
  defaultSecretProvider: () => defaultSecretProvider,
@@ -82,17 +80,15 @@ var import_util2 = require("@dxos/util");
82
80
  var import_invariant2 = require("@dxos/invariant");
83
81
  var import_keys4 = require("@dxos/keys");
84
82
  var import_util3 = require("@dxos/util");
85
- var import_keys5 = require("@dxos/keys");
86
- var import_util4 = require("@dxos/util");
87
83
  var import_invariant3 = require("@dxos/invariant");
88
- var import_keys6 = require("@dxos/keys");
84
+ var import_keys5 = require("@dxos/keys");
89
85
  var import_log2 = require("@dxos/log");
90
- var import_util5 = require("@dxos/util");
86
+ var import_util4 = require("@dxos/util");
91
87
  var import_async2 = require("@dxos/async");
92
88
  var import_invariant4 = require("@dxos/invariant");
93
- var import_keys7 = require("@dxos/keys");
89
+ var import_keys6 = require("@dxos/keys");
94
90
  var import_log3 = require("@dxos/log");
95
- var import_util6 = require("@dxos/util");
91
+ var import_util5 = require("@dxos/util");
96
92
  var import_log4 = require("@dxos/log");
97
93
  var defaultSecretProvider = async () => Buffer.from("0000");
98
94
  var defaultSecretValidator = async (invitation, secret) => true;
@@ -466,7 +462,7 @@ var createDeviceAuthorization = async (signer, identityKey, deviceKey) => {
466
462
  credential
467
463
  }));
468
464
  };
469
- var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, profile, invitationCredentialId) => {
465
+ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, profile) => {
470
466
  const credentials = await Promise.all([
471
467
  await signer.createCredential({
472
468
  subject: identityKey,
@@ -475,8 +471,7 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
475
471
  spaceKey,
476
472
  role: import_credentials.SpaceMember.Role.ADMIN,
477
473
  profile,
478
- genesisFeedKey,
479
- invitationCredentialId
474
+ genesisFeedKey
480
475
  }
481
476
  })
482
477
  ]);
@@ -486,26 +481,6 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
486
481
  }
487
482
  }));
488
483
  };
489
- var createDelegatedSpaceInvitationCredential = async (signer, subject, invitation) => {
490
- const credential = await signer.createCredential({
491
- subject,
492
- assertion: {
493
- "@type": "dxos.halo.invitations.DelegateSpaceInvitation",
494
- invitationId: invitation.invitationId,
495
- authMethod: invitation.authMethod,
496
- swarmKey: invitation.swarmKey,
497
- role: invitation.role,
498
- guestKey: invitation.guestKey,
499
- expiresOn: invitation.expiresOn,
500
- multiUse: invitation.multiUse
501
- }
502
- });
503
- return {
504
- credential: {
505
- credential
506
- }
507
- };
508
- };
509
484
  var signPresentation = async ({ presentation, signer, signerKey, chain, nonce }) => {
510
485
  const proof = {
511
486
  type: SIGNATURE_TYPE_ED25519,
@@ -654,78 +629,12 @@ var FeedStateMachine = class {
654
629
  await this.onFeedAdmitted.callIfSet(info);
655
630
  }
656
631
  };
657
- var InvitationStateMachine = class {
658
- constructor() {
659
- this._invitations = new import_util4.ComplexMap(import_keys5.PublicKey.hash);
660
- this._redeemedInvitationCredentialIds = new import_util4.ComplexSet(import_keys5.PublicKey.hash);
661
- this._cancelledInvitationCredentialIds = new import_util4.ComplexSet(import_keys5.PublicKey.hash);
662
- this.onDelegatedInvitation = new import_util4.Callback();
663
- this.onDelegatedInvitationRemoved = new import_util4.Callback();
664
- }
665
- get invitations() {
666
- return this._invitations;
667
- }
668
- async process(credential) {
669
- const credentialId = credential.id;
670
- if (credentialId == null) {
671
- return;
672
- }
673
- const assertion = getCredentialAssertion(credential);
674
- switch (assertion["@type"]) {
675
- case "dxos.halo.invitations.CancelDelegatedInvitation": {
676
- this._cancelledInvitationCredentialIds.add(assertion.credentialId);
677
- const existingInvitation = this._invitations.get(assertion.credentialId);
678
- if (existingInvitation != null) {
679
- this._invitations.delete(assertion.credentialId);
680
- await this.onDelegatedInvitationRemoved.callIfSet({
681
- credentialId: assertion.credentialId,
682
- invitation: existingInvitation
683
- });
684
- }
685
- break;
686
- }
687
- case "dxos.halo.invitations.DelegateSpaceInvitation": {
688
- if (credential.id) {
689
- const isExpired = assertion.expiresOn && assertion.expiresOn.getTime() < Date.now();
690
- const wasUsed = this._redeemedInvitationCredentialIds.has(credential.id) && !assertion.multiUse;
691
- const wasCancelled = this._cancelledInvitationCredentialIds.has(credential.id);
692
- if (isExpired || wasCancelled || wasUsed) {
693
- return;
694
- }
695
- const invitation = {
696
- ...assertion
697
- };
698
- this._invitations.set(credential.id, invitation);
699
- await this.onDelegatedInvitation.callIfSet({
700
- credentialId: credential.id,
701
- invitation
702
- });
703
- }
704
- break;
705
- }
706
- case "dxos.halo.credentials.SpaceMember": {
707
- if (assertion.invitationCredentialId != null) {
708
- this._redeemedInvitationCredentialIds.add(assertion.invitationCredentialId);
709
- const existingInvitation = this._invitations.get(assertion.invitationCredentialId);
710
- if (existingInvitation != null && !existingInvitation.multiUse) {
711
- this._invitations.delete(assertion.invitationCredentialId);
712
- await this.onDelegatedInvitationRemoved.callIfSet({
713
- credentialId: assertion.invitationCredentialId,
714
- invitation: existingInvitation
715
- });
716
- }
717
- }
718
- break;
719
- }
720
- }
721
- }
722
- };
723
632
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/member-state-machine.ts";
724
633
  var MemberStateMachine = class {
725
634
  constructor(_spaceKey) {
726
635
  this._spaceKey = _spaceKey;
727
- this._members = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
728
- this.onMemberAdmitted = new import_util5.Callback();
636
+ this._members = new import_util4.ComplexMap(import_keys5.PublicKey.hash);
637
+ this.onMemberAdmitted = new import_util4.Callback();
729
638
  }
730
639
  get creator() {
731
640
  return this._creator;
@@ -820,7 +729,7 @@ var MemberStateMachine = class {
820
729
  }
821
730
  };
822
731
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
823
- var REVOCABLE_CREDENTIALS = [
732
+ var REVOKABLE_CREDENTIALS = [
824
733
  "dxos.halo.credentials.SpaceMember"
825
734
  ];
826
735
  var SpaceStateMachine = class {
@@ -828,7 +737,6 @@ var SpaceStateMachine = class {
828
737
  this._spaceKey = _spaceKey;
829
738
  this._members = new MemberStateMachine(this._spaceKey);
830
739
  this._feeds = new FeedStateMachine(this._spaceKey);
831
- this._invitations = new InvitationStateMachine();
832
740
  this._credentials = [];
833
741
  this._credentialsById = new import_util2.ComplexMap(import_keys3.PublicKey.hash);
834
742
  this._processedCredentials = new import_util2.ComplexSet(import_keys3.PublicKey.hash);
@@ -836,8 +744,6 @@ var SpaceStateMachine = class {
836
744
  this.onCredentialProcessed = new import_util2.Callback();
837
745
  this.onMemberAdmitted = this._members.onMemberAdmitted;
838
746
  this.onFeedAdmitted = this._feeds.onFeedAdmitted;
839
- this.onDelegatedInvitation = this._invitations.onDelegatedInvitation;
840
- this.onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;
841
747
  }
842
748
  get creator() {
843
749
  return this._members.creator;
@@ -857,9 +763,6 @@ var SpaceStateMachine = class {
857
763
  get genesisCredential() {
858
764
  return this._genesisCredential;
859
765
  }
860
- get invitations() {
861
- return this._invitations.invitations;
862
- }
863
766
  async addCredentialProcessor(processor) {
864
767
  if (this._credentialProcessors.find((p) => p.processor === processor)) {
865
768
  throw new Error("Credential processor already added.");
@@ -898,7 +801,7 @@ var SpaceStateMachine = class {
898
801
  if (result.kind !== "pass") {
899
802
  import_log.log.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, {
900
803
  F: __dxlog_file4,
901
- L: 149,
804
+ L: 139,
902
805
  S: this,
903
806
  C: (f, a) => f(...a)
904
807
  });
@@ -911,7 +814,7 @@ var SpaceStateMachine = class {
911
814
  if (!this._canRevokeCredentials(credential.issuer)) {
912
815
  import_log.log.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
913
816
  F: __dxlog_file4,
914
- L: 158,
817
+ L: 148,
915
818
  S: this,
916
819
  C: (f, a) => f(...a)
917
820
  });
@@ -921,7 +824,7 @@ var SpaceStateMachine = class {
921
824
  if (!toBeRevoked) {
922
825
  import_log.log.warn(`Credential to revoke not found: ${credential.subject.id}`, void 0, {
923
826
  F: __dxlog_file4,
924
- L: 163,
827
+ L: 153,
925
828
  S: this,
926
829
  C: (f, a) => f(...a)
927
830
  });
@@ -930,7 +833,7 @@ var SpaceStateMachine = class {
930
833
  if (!this._credentialCanBeRevoked(toBeRevoked)) {
931
834
  import_log.log.warn(`Credential cannot be revoked: ${credential.subject.id}`, void 0, {
932
835
  F: __dxlog_file4,
933
- L: 167,
836
+ L: 157,
934
837
  S: this,
935
838
  C: (f, a) => f(...a)
936
839
  });
@@ -943,7 +846,7 @@ var SpaceStateMachine = class {
943
846
  if (this._genesisCredential) {
944
847
  import_log.log.warn("Space already has a genesis credential.", void 0, {
945
848
  F: __dxlog_file4,
946
- L: 176,
849
+ L: 167,
947
850
  S: this,
948
851
  C: (f, a) => f(...a)
949
852
  });
@@ -952,7 +855,7 @@ var SpaceStateMachine = class {
952
855
  if (!credential.issuer.equals(this._spaceKey)) {
953
856
  import_log.log.warn("Space genesis credential must be issued by space.", void 0, {
954
857
  F: __dxlog_file4,
955
- L: 180,
858
+ L: 171,
956
859
  S: this,
957
860
  C: (f, a) => f(...a)
958
861
  });
@@ -961,7 +864,7 @@ var SpaceStateMachine = class {
961
864
  if (!credential.subject.id.equals(this._spaceKey)) {
962
865
  import_log.log.warn("Space genesis credential must be issued to space.", void 0, {
963
866
  F: __dxlog_file4,
964
- L: 184,
867
+ L: 175,
965
868
  S: this,
966
869
  C: (f, a) => f(...a)
967
870
  });
@@ -977,7 +880,7 @@ var SpaceStateMachine = class {
977
880
  if (!this._genesisCredential) {
978
881
  import_log.log.warn("Space must have a genesis credential before adding members.", void 0, {
979
882
  F: __dxlog_file4,
980
- L: 198,
883
+ L: 189,
981
884
  S: this,
982
885
  C: (f, a) => f(...a)
983
886
  });
@@ -986,21 +889,20 @@ var SpaceStateMachine = class {
986
889
  if (!this._canInviteNewMembers(credential.issuer)) {
987
890
  import_log.log.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
988
891
  F: __dxlog_file4,
989
- L: 202,
892
+ L: 193,
990
893
  S: this,
991
894
  C: (f, a) => f(...a)
992
895
  });
993
896
  return false;
994
897
  }
995
898
  await this._members.process(credential);
996
- await this._invitations.process(credential);
997
899
  break;
998
900
  }
999
901
  case "dxos.halo.credentials.MemberProfile": {
1000
902
  if (!this._genesisCredential) {
1001
903
  import_log.log.warn("Space must have a genesis credential before adding members.", void 0, {
1002
904
  F: __dxlog_file4,
1003
- L: 213,
905
+ L: 203,
1004
906
  S: this,
1005
907
  C: (f, a) => f(...a)
1006
908
  });
@@ -1013,7 +915,7 @@ var SpaceStateMachine = class {
1013
915
  if (!this._genesisCredential) {
1014
916
  import_log.log.warn("Space must have a genesis credential before admitting feeds.", void 0, {
1015
917
  F: __dxlog_file4,
1016
- L: 223,
918
+ L: 213,
1017
919
  S: this,
1018
920
  C: (f, a) => f(...a)
1019
921
  });
@@ -1022,7 +924,7 @@ var SpaceStateMachine = class {
1022
924
  if (!this._canAdmitFeeds(credential.issuer)) {
1023
925
  import_log.log.warn(`Space member is not authorized to admit feeds: ${credential.issuer}`, void 0, {
1024
926
  F: __dxlog_file4,
1025
- L: 227,
927
+ L: 217,
1026
928
  S: this,
1027
929
  C: (f, a) => f(...a)
1028
930
  });
@@ -1031,20 +933,6 @@ var SpaceStateMachine = class {
1031
933
  await this._feeds.process(credential, sourceFeed);
1032
934
  break;
1033
935
  }
1034
- case "dxos.halo.invitations.CancelDelegatedInvitation":
1035
- case "dxos.halo.invitations.DelegateSpaceInvitation": {
1036
- if (!this._canInviteNewMembers(credential.issuer)) {
1037
- import_log.log.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1038
- F: __dxlog_file4,
1039
- L: 238,
1040
- S: this,
1041
- C: (f, a) => f(...a)
1042
- });
1043
- return false;
1044
- }
1045
- await this._invitations.process(credential);
1046
- break;
1047
- }
1048
936
  }
1049
937
  const newEntry = {
1050
938
  credential,
@@ -1074,7 +962,7 @@ var SpaceStateMachine = class {
1074
962
  return key.equals(this._spaceKey) || this._members.getRole(key) === import_credentials2.SpaceMember.Role.ADMIN;
1075
963
  }
1076
964
  _credentialCanBeRevoked(entry) {
1077
- return REVOCABLE_CREDENTIALS.includes(entry.credential.subject.assertion["@type"]);
965
+ return REVOKABLE_CREDENTIALS.includes(entry.credential.subject.assertion["@type"]);
1078
966
  }
1079
967
  };
1080
968
  var CredentialConsumer = class {
@@ -1108,7 +996,7 @@ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/
1108
996
  var DeviceStateMachine = class {
1109
997
  constructor(_params) {
1110
998
  this._params = _params;
1111
- this.authorizedDeviceKeys = new import_util6.ComplexMap(import_keys7.PublicKey.hash);
999
+ this.authorizedDeviceKeys = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
1112
1000
  this.deviceChainReady = new import_async2.Trigger();
1113
1001
  }
1114
1002
  async processCredential(credential) {
@@ -1224,7 +1112,6 @@ var ProfileStateMachine = class {
1224
1112
  CredentialGenerator,
1225
1113
  DeviceStateMachine,
1226
1114
  FeedStateMachine,
1227
- InvitationStateMachine,
1228
1115
  MemberStateMachine,
1229
1116
  ProfileStateMachine,
1230
1117
  SIGNATURE_TYPE_ED25519,
@@ -1236,7 +1123,6 @@ var ProfileStateMachine = class {
1236
1123
  createCredentialMessage,
1237
1124
  createCredentialSignerWithChain,
1238
1125
  createCredentialSignerWithKey,
1239
- createDelegatedSpaceInvitationCredential,
1240
1126
  createDeviceAuthorization,
1241
1127
  credentialTypeFilter,
1242
1128
  defaultSecretProvider,