@dxos/credentials 0.4.10-main.0302e13 → 0.4.10-main.05dbd64
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.
- package/dist/lib/browser/index.mjs +142 -28
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +137 -23
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/credentials/credential-generator.d.ts +3 -1
- package/dist/types/src/credentials/credential-generator.d.ts.map +1 -1
- package/dist/types/src/state-machine/index.d.ts +1 -0
- package/dist/types/src/state-machine/index.d.ts.map +1 -1
- package/dist/types/src/state-machine/invitation-state-machine.d.ts +22 -0
- package/dist/types/src/state-machine/invitation-state-machine.d.ts.map +1 -0
- package/dist/types/src/state-machine/invitation-state-machine.test.d.ts +2 -0
- package/dist/types/src/state-machine/invitation-state-machine.test.d.ts.map +1 -0
- package/dist/types/src/state-machine/space-state-machine.d.ts +6 -0
- package/dist/types/src/state-machine/space-state-machine.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/credentials/credential-generator.ts +24 -0
- package/src/state-machine/index.ts +1 -0
- package/src/state-machine/invitation-state-machine.test.ts +166 -0
- package/src/state-machine/invitation-state-machine.ts +85 -0
- package/src/state-machine/space-state-machine.ts +22 -3
|
@@ -406,7 +406,7 @@ var createDeviceAuthorization = async (signer, identityKey, deviceKey) => {
|
|
|
406
406
|
credential
|
|
407
407
|
}));
|
|
408
408
|
};
|
|
409
|
-
var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, profile) => {
|
|
409
|
+
var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, profile, invitationCredentialId) => {
|
|
410
410
|
const credentials = await Promise.all([
|
|
411
411
|
await signer.createCredential({
|
|
412
412
|
subject: identityKey,
|
|
@@ -415,7 +415,8 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
|
|
|
415
415
|
spaceKey,
|
|
416
416
|
role: SpaceMember.Role.ADMIN,
|
|
417
417
|
profile,
|
|
418
|
-
genesisFeedKey
|
|
418
|
+
genesisFeedKey,
|
|
419
|
+
invitationCredentialId
|
|
419
420
|
}
|
|
420
421
|
})
|
|
421
422
|
]);
|
|
@@ -425,6 +426,26 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
|
|
|
425
426
|
}
|
|
426
427
|
}));
|
|
427
428
|
};
|
|
429
|
+
var createDelegatedSpaceInvitationCredential = async (signer, subject, invitation) => {
|
|
430
|
+
const credential = await signer.createCredential({
|
|
431
|
+
subject,
|
|
432
|
+
assertion: {
|
|
433
|
+
"@type": "dxos.halo.invitations.DelegateSpaceInvitation",
|
|
434
|
+
invitationId: invitation.invitationId,
|
|
435
|
+
authMethod: invitation.authMethod,
|
|
436
|
+
swarmKey: invitation.swarmKey,
|
|
437
|
+
role: invitation.role,
|
|
438
|
+
guestKey: invitation.guestKey,
|
|
439
|
+
expiresOn: invitation.expiresOn,
|
|
440
|
+
multiUse: invitation.multiUse
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
return {
|
|
444
|
+
credential: {
|
|
445
|
+
credential
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
};
|
|
428
449
|
|
|
429
450
|
// packages/core/halo/credentials/src/presentations/presentation.ts
|
|
430
451
|
var signPresentation = async ({ presentation, signer, signerKey, chain, nonce }) => {
|
|
@@ -536,10 +557,10 @@ var verifyPresentationSignature = async (presentation, proof) => {
|
|
|
536
557
|
// packages/core/halo/credentials/src/state-machine/space-state-machine.ts
|
|
537
558
|
import { runInContextAsync } from "@dxos/async";
|
|
538
559
|
import { Context } from "@dxos/context";
|
|
539
|
-
import { PublicKey as
|
|
560
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
540
561
|
import { log as log2 } from "@dxos/log";
|
|
541
562
|
import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
542
|
-
import { Callback as
|
|
563
|
+
import { Callback as Callback4, ComplexMap as ComplexMap4, ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
543
564
|
|
|
544
565
|
// packages/core/halo/credentials/src/state-machine/feed-state-machine.ts
|
|
545
566
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
@@ -592,17 +613,87 @@ var FeedStateMachine = class {
|
|
|
592
613
|
}
|
|
593
614
|
};
|
|
594
615
|
|
|
616
|
+
// packages/core/halo/credentials/src/state-machine/invitation-state-machine.ts
|
|
617
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
618
|
+
import { Callback as Callback2, ComplexMap as ComplexMap2, ComplexSet } from "@dxos/util";
|
|
619
|
+
var InvitationStateMachine = class {
|
|
620
|
+
constructor() {
|
|
621
|
+
this._invitations = new ComplexMap2(PublicKey4.hash);
|
|
622
|
+
this._redeemedInvitationCredentialIds = new ComplexSet(PublicKey4.hash);
|
|
623
|
+
this._cancelledInvitationCredentialIds = new ComplexSet(PublicKey4.hash);
|
|
624
|
+
this.onDelegatedInvitation = new Callback2();
|
|
625
|
+
this.onDelegatedInvitationRemoved = new Callback2();
|
|
626
|
+
}
|
|
627
|
+
get invitations() {
|
|
628
|
+
return this._invitations;
|
|
629
|
+
}
|
|
630
|
+
async process(credential) {
|
|
631
|
+
const credentialId = credential.id;
|
|
632
|
+
if (credentialId == null) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const assertion = getCredentialAssertion(credential);
|
|
636
|
+
switch (assertion["@type"]) {
|
|
637
|
+
case "dxos.halo.invitations.CancelDelegatedInvitation": {
|
|
638
|
+
this._cancelledInvitationCredentialIds.add(assertion.credentialId);
|
|
639
|
+
const existingInvitation = this._invitations.get(assertion.credentialId);
|
|
640
|
+
if (existingInvitation != null) {
|
|
641
|
+
this._invitations.delete(assertion.credentialId);
|
|
642
|
+
await this.onDelegatedInvitationRemoved.callIfSet({
|
|
643
|
+
credentialId: assertion.credentialId,
|
|
644
|
+
invitation: existingInvitation
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
break;
|
|
648
|
+
}
|
|
649
|
+
case "dxos.halo.invitations.DelegateSpaceInvitation": {
|
|
650
|
+
if (credential.id) {
|
|
651
|
+
const isExpired = assertion.expiresOn && assertion.expiresOn.getTime() < Date.now();
|
|
652
|
+
const wasUsed = this._redeemedInvitationCredentialIds.has(credential.id) && !assertion.multiUse;
|
|
653
|
+
const wasCancelled = this._cancelledInvitationCredentialIds.has(credential.id);
|
|
654
|
+
if (isExpired || wasCancelled || wasUsed) {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const invitation = {
|
|
658
|
+
...assertion
|
|
659
|
+
};
|
|
660
|
+
this._invitations.set(credential.id, invitation);
|
|
661
|
+
await this.onDelegatedInvitation.callIfSet({
|
|
662
|
+
credentialId: credential.id,
|
|
663
|
+
invitation
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
case "dxos.halo.credentials.SpaceMember": {
|
|
669
|
+
if (assertion.invitationCredentialId != null) {
|
|
670
|
+
this._redeemedInvitationCredentialIds.add(assertion.invitationCredentialId);
|
|
671
|
+
const existingInvitation = this._invitations.get(assertion.invitationCredentialId);
|
|
672
|
+
if (existingInvitation != null && !existingInvitation.multiUse) {
|
|
673
|
+
this._invitations.delete(assertion.invitationCredentialId);
|
|
674
|
+
await this.onDelegatedInvitationRemoved.callIfSet({
|
|
675
|
+
credentialId: assertion.invitationCredentialId,
|
|
676
|
+
invitation: existingInvitation
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
break;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
|
|
595
686
|
// packages/core/halo/credentials/src/state-machine/member-state-machine.ts
|
|
596
687
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
597
|
-
import { PublicKey as
|
|
688
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
598
689
|
import { log } from "@dxos/log";
|
|
599
|
-
import { Callback as
|
|
690
|
+
import { Callback as Callback3, ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
600
691
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/member-state-machine.ts";
|
|
601
692
|
var MemberStateMachine = class {
|
|
602
693
|
constructor(_spaceKey) {
|
|
603
694
|
this._spaceKey = _spaceKey;
|
|
604
|
-
this._members = new
|
|
605
|
-
this.onMemberAdmitted = new
|
|
695
|
+
this._members = new ComplexMap3(PublicKey5.hash);
|
|
696
|
+
this.onMemberAdmitted = new Callback3();
|
|
606
697
|
}
|
|
607
698
|
get creator() {
|
|
608
699
|
return this._creator;
|
|
@@ -699,7 +790,7 @@ var MemberStateMachine = class {
|
|
|
699
790
|
|
|
700
791
|
// packages/core/halo/credentials/src/state-machine/space-state-machine.ts
|
|
701
792
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
|
|
702
|
-
var
|
|
793
|
+
var REVOCABLE_CREDENTIALS = [
|
|
703
794
|
"dxos.halo.credentials.SpaceMember"
|
|
704
795
|
];
|
|
705
796
|
var SpaceStateMachine = class {
|
|
@@ -707,13 +798,16 @@ var SpaceStateMachine = class {
|
|
|
707
798
|
this._spaceKey = _spaceKey;
|
|
708
799
|
this._members = new MemberStateMachine(this._spaceKey);
|
|
709
800
|
this._feeds = new FeedStateMachine(this._spaceKey);
|
|
801
|
+
this._invitations = new InvitationStateMachine();
|
|
710
802
|
this._credentials = [];
|
|
711
|
-
this._credentialsById = new
|
|
712
|
-
this._processedCredentials = new
|
|
803
|
+
this._credentialsById = new ComplexMap4(PublicKey6.hash);
|
|
804
|
+
this._processedCredentials = new ComplexSet2(PublicKey6.hash);
|
|
713
805
|
this._credentialProcessors = [];
|
|
714
|
-
this.onCredentialProcessed = new
|
|
806
|
+
this.onCredentialProcessed = new Callback4();
|
|
715
807
|
this.onMemberAdmitted = this._members.onMemberAdmitted;
|
|
716
808
|
this.onFeedAdmitted = this._feeds.onFeedAdmitted;
|
|
809
|
+
this.onDelegatedInvitation = this._invitations.onDelegatedInvitation;
|
|
810
|
+
this.onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;
|
|
717
811
|
}
|
|
718
812
|
get creator() {
|
|
719
813
|
return this._members.creator;
|
|
@@ -733,6 +827,9 @@ var SpaceStateMachine = class {
|
|
|
733
827
|
get genesisCredential() {
|
|
734
828
|
return this._genesisCredential;
|
|
735
829
|
}
|
|
830
|
+
get invitations() {
|
|
831
|
+
return this._invitations.invitations;
|
|
832
|
+
}
|
|
736
833
|
async addCredentialProcessor(processor) {
|
|
737
834
|
if (this._credentialProcessors.find((p) => p.processor === processor)) {
|
|
738
835
|
throw new Error("Credential processor already added.");
|
|
@@ -771,7 +868,7 @@ var SpaceStateMachine = class {
|
|
|
771
868
|
if (result.kind !== "pass") {
|
|
772
869
|
log2.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, {
|
|
773
870
|
F: __dxlog_file4,
|
|
774
|
-
L:
|
|
871
|
+
L: 149,
|
|
775
872
|
S: this,
|
|
776
873
|
C: (f, a) => f(...a)
|
|
777
874
|
});
|
|
@@ -784,7 +881,7 @@ var SpaceStateMachine = class {
|
|
|
784
881
|
if (!this._canRevokeCredentials(credential.issuer)) {
|
|
785
882
|
log2.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
|
|
786
883
|
F: __dxlog_file4,
|
|
787
|
-
L:
|
|
884
|
+
L: 158,
|
|
788
885
|
S: this,
|
|
789
886
|
C: (f, a) => f(...a)
|
|
790
887
|
});
|
|
@@ -794,7 +891,7 @@ var SpaceStateMachine = class {
|
|
|
794
891
|
if (!toBeRevoked) {
|
|
795
892
|
log2.warn(`Credential to revoke not found: ${credential.subject.id}`, void 0, {
|
|
796
893
|
F: __dxlog_file4,
|
|
797
|
-
L:
|
|
894
|
+
L: 163,
|
|
798
895
|
S: this,
|
|
799
896
|
C: (f, a) => f(...a)
|
|
800
897
|
});
|
|
@@ -803,7 +900,7 @@ var SpaceStateMachine = class {
|
|
|
803
900
|
if (!this._credentialCanBeRevoked(toBeRevoked)) {
|
|
804
901
|
log2.warn(`Credential cannot be revoked: ${credential.subject.id}`, void 0, {
|
|
805
902
|
F: __dxlog_file4,
|
|
806
|
-
L:
|
|
903
|
+
L: 167,
|
|
807
904
|
S: this,
|
|
808
905
|
C: (f, a) => f(...a)
|
|
809
906
|
});
|
|
@@ -816,7 +913,7 @@ var SpaceStateMachine = class {
|
|
|
816
913
|
if (this._genesisCredential) {
|
|
817
914
|
log2.warn("Space already has a genesis credential.", void 0, {
|
|
818
915
|
F: __dxlog_file4,
|
|
819
|
-
L:
|
|
916
|
+
L: 176,
|
|
820
917
|
S: this,
|
|
821
918
|
C: (f, a) => f(...a)
|
|
822
919
|
});
|
|
@@ -825,7 +922,7 @@ var SpaceStateMachine = class {
|
|
|
825
922
|
if (!credential.issuer.equals(this._spaceKey)) {
|
|
826
923
|
log2.warn("Space genesis credential must be issued by space.", void 0, {
|
|
827
924
|
F: __dxlog_file4,
|
|
828
|
-
L:
|
|
925
|
+
L: 180,
|
|
829
926
|
S: this,
|
|
830
927
|
C: (f, a) => f(...a)
|
|
831
928
|
});
|
|
@@ -834,7 +931,7 @@ var SpaceStateMachine = class {
|
|
|
834
931
|
if (!credential.subject.id.equals(this._spaceKey)) {
|
|
835
932
|
log2.warn("Space genesis credential must be issued to space.", void 0, {
|
|
836
933
|
F: __dxlog_file4,
|
|
837
|
-
L:
|
|
934
|
+
L: 184,
|
|
838
935
|
S: this,
|
|
839
936
|
C: (f, a) => f(...a)
|
|
840
937
|
});
|
|
@@ -850,7 +947,7 @@ var SpaceStateMachine = class {
|
|
|
850
947
|
if (!this._genesisCredential) {
|
|
851
948
|
log2.warn("Space must have a genesis credential before adding members.", void 0, {
|
|
852
949
|
F: __dxlog_file4,
|
|
853
|
-
L:
|
|
950
|
+
L: 198,
|
|
854
951
|
S: this,
|
|
855
952
|
C: (f, a) => f(...a)
|
|
856
953
|
});
|
|
@@ -859,20 +956,21 @@ var SpaceStateMachine = class {
|
|
|
859
956
|
if (!this._canInviteNewMembers(credential.issuer)) {
|
|
860
957
|
log2.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
|
|
861
958
|
F: __dxlog_file4,
|
|
862
|
-
L:
|
|
959
|
+
L: 202,
|
|
863
960
|
S: this,
|
|
864
961
|
C: (f, a) => f(...a)
|
|
865
962
|
});
|
|
866
963
|
return false;
|
|
867
964
|
}
|
|
868
965
|
await this._members.process(credential);
|
|
966
|
+
await this._invitations.process(credential);
|
|
869
967
|
break;
|
|
870
968
|
}
|
|
871
969
|
case "dxos.halo.credentials.MemberProfile": {
|
|
872
970
|
if (!this._genesisCredential) {
|
|
873
971
|
log2.warn("Space must have a genesis credential before adding members.", void 0, {
|
|
874
972
|
F: __dxlog_file4,
|
|
875
|
-
L:
|
|
973
|
+
L: 213,
|
|
876
974
|
S: this,
|
|
877
975
|
C: (f, a) => f(...a)
|
|
878
976
|
});
|
|
@@ -885,7 +983,7 @@ var SpaceStateMachine = class {
|
|
|
885
983
|
if (!this._genesisCredential) {
|
|
886
984
|
log2.warn("Space must have a genesis credential before admitting feeds.", void 0, {
|
|
887
985
|
F: __dxlog_file4,
|
|
888
|
-
L:
|
|
986
|
+
L: 223,
|
|
889
987
|
S: this,
|
|
890
988
|
C: (f, a) => f(...a)
|
|
891
989
|
});
|
|
@@ -894,7 +992,7 @@ var SpaceStateMachine = class {
|
|
|
894
992
|
if (!this._canAdmitFeeds(credential.issuer)) {
|
|
895
993
|
log2.warn(`Space member is not authorized to admit feeds: ${credential.issuer}`, void 0, {
|
|
896
994
|
F: __dxlog_file4,
|
|
897
|
-
L:
|
|
995
|
+
L: 227,
|
|
898
996
|
S: this,
|
|
899
997
|
C: (f, a) => f(...a)
|
|
900
998
|
});
|
|
@@ -903,6 +1001,20 @@ var SpaceStateMachine = class {
|
|
|
903
1001
|
await this._feeds.process(credential, sourceFeed);
|
|
904
1002
|
break;
|
|
905
1003
|
}
|
|
1004
|
+
case "dxos.halo.invitations.CancelDelegatedInvitation":
|
|
1005
|
+
case "dxos.halo.invitations.DelegateSpaceInvitation": {
|
|
1006
|
+
if (!this._canInviteNewMembers(credential.issuer)) {
|
|
1007
|
+
log2.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
|
|
1008
|
+
F: __dxlog_file4,
|
|
1009
|
+
L: 238,
|
|
1010
|
+
S: this,
|
|
1011
|
+
C: (f, a) => f(...a)
|
|
1012
|
+
});
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
await this._invitations.process(credential);
|
|
1016
|
+
break;
|
|
1017
|
+
}
|
|
906
1018
|
}
|
|
907
1019
|
const newEntry = {
|
|
908
1020
|
credential,
|
|
@@ -932,7 +1044,7 @@ var SpaceStateMachine = class {
|
|
|
932
1044
|
return key.equals(this._spaceKey) || this._members.getRole(key) === SpaceMember2.Role.ADMIN;
|
|
933
1045
|
}
|
|
934
1046
|
_credentialCanBeRevoked(entry) {
|
|
935
|
-
return
|
|
1047
|
+
return REVOCABLE_CREDENTIALS.includes(entry.credential.subject.assertion["@type"]);
|
|
936
1048
|
}
|
|
937
1049
|
};
|
|
938
1050
|
var CredentialConsumer = class {
|
|
@@ -966,14 +1078,14 @@ var CredentialConsumer = class {
|
|
|
966
1078
|
// packages/core/halo/credentials/src/processor/device-state-machine.ts
|
|
967
1079
|
import { Trigger } from "@dxos/async";
|
|
968
1080
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
969
|
-
import { PublicKey as
|
|
1081
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
970
1082
|
import { log as log3 } from "@dxos/log";
|
|
971
|
-
import { ComplexMap as
|
|
1083
|
+
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
972
1084
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/processor/device-state-machine.ts";
|
|
973
1085
|
var DeviceStateMachine = class {
|
|
974
1086
|
constructor(_params) {
|
|
975
1087
|
this._params = _params;
|
|
976
|
-
this.authorizedDeviceKeys = new
|
|
1088
|
+
this.authorizedDeviceKeys = new ComplexMap5(PublicKey7.hash);
|
|
977
1089
|
this.deviceChainReady = new Trigger();
|
|
978
1090
|
}
|
|
979
1091
|
async processCredential(credential) {
|
|
@@ -1091,6 +1203,7 @@ export {
|
|
|
1091
1203
|
CredentialGenerator,
|
|
1092
1204
|
DeviceStateMachine,
|
|
1093
1205
|
FeedStateMachine,
|
|
1206
|
+
InvitationStateMachine,
|
|
1094
1207
|
MemberStateMachine,
|
|
1095
1208
|
ProfileStateMachine,
|
|
1096
1209
|
SIGNATURE_TYPE_ED25519,
|
|
@@ -1102,6 +1215,7 @@ export {
|
|
|
1102
1215
|
createCredentialMessage,
|
|
1103
1216
|
createCredentialSignerWithChain,
|
|
1104
1217
|
createCredentialSignerWithKey,
|
|
1218
|
+
createDelegatedSpaceInvitationCredential,
|
|
1105
1219
|
createDeviceAuthorization,
|
|
1106
1220
|
credentialTypeFilter,
|
|
1107
1221
|
defaultSecretProvider,
|