@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.
- package/dist/lib/browser/index.mjs +28 -142
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +23 -137
- 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 +1 -3
- package/dist/types/src/credentials/credential-generator.d.ts.map +1 -1
- package/dist/types/src/state-machine/index.d.ts +0 -1
- package/dist/types/src/state-machine/index.d.ts.map +1 -1
- package/dist/types/src/state-machine/space-state-machine.d.ts +0 -6
- 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 +0 -24
- package/src/state-machine/index.ts +0 -1
- package/src/state-machine/space-state-machine.ts +3 -22
- package/dist/types/src/state-machine/invitation-state-machine.d.ts +0 -22
- package/dist/types/src/state-machine/invitation-state-machine.d.ts.map +0 -1
- package/dist/types/src/state-machine/invitation-state-machine.test.d.ts +0 -2
- package/dist/types/src/state-machine/invitation-state-machine.test.d.ts.map +0 -1
- package/src/state-machine/invitation-state-machine.test.ts +0 -166
- package/src/state-machine/invitation-state-machine.ts +0 -85
|
@@ -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) => {
|
|
410
410
|
const credentials = await Promise.all([
|
|
411
411
|
await signer.createCredential({
|
|
412
412
|
subject: identityKey,
|
|
@@ -415,8 +415,7 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
|
|
|
415
415
|
spaceKey,
|
|
416
416
|
role: SpaceMember.Role.ADMIN,
|
|
417
417
|
profile,
|
|
418
|
-
genesisFeedKey
|
|
419
|
-
invitationCredentialId
|
|
418
|
+
genesisFeedKey
|
|
420
419
|
}
|
|
421
420
|
})
|
|
422
421
|
]);
|
|
@@ -426,26 +425,6 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
|
|
|
426
425
|
}
|
|
427
426
|
}));
|
|
428
427
|
};
|
|
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
|
-
};
|
|
449
428
|
|
|
450
429
|
// packages/core/halo/credentials/src/presentations/presentation.ts
|
|
451
430
|
var signPresentation = async ({ presentation, signer, signerKey, chain, nonce }) => {
|
|
@@ -557,10 +536,10 @@ var verifyPresentationSignature = async (presentation, proof) => {
|
|
|
557
536
|
// packages/core/halo/credentials/src/state-machine/space-state-machine.ts
|
|
558
537
|
import { runInContextAsync } from "@dxos/async";
|
|
559
538
|
import { Context } from "@dxos/context";
|
|
560
|
-
import { PublicKey as
|
|
539
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
561
540
|
import { log as log2 } from "@dxos/log";
|
|
562
541
|
import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
563
|
-
import { Callback as
|
|
542
|
+
import { Callback as Callback3, ComplexMap as ComplexMap3, ComplexSet } from "@dxos/util";
|
|
564
543
|
|
|
565
544
|
// packages/core/halo/credentials/src/state-machine/feed-state-machine.ts
|
|
566
545
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
@@ -613,87 +592,17 @@ var FeedStateMachine = class {
|
|
|
613
592
|
}
|
|
614
593
|
};
|
|
615
594
|
|
|
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
|
-
|
|
686
595
|
// packages/core/halo/credentials/src/state-machine/member-state-machine.ts
|
|
687
596
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
688
|
-
import { PublicKey as
|
|
597
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
689
598
|
import { log } from "@dxos/log";
|
|
690
|
-
import { Callback as
|
|
599
|
+
import { Callback as Callback2, ComplexMap as ComplexMap2 } from "@dxos/util";
|
|
691
600
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/member-state-machine.ts";
|
|
692
601
|
var MemberStateMachine = class {
|
|
693
602
|
constructor(_spaceKey) {
|
|
694
603
|
this._spaceKey = _spaceKey;
|
|
695
|
-
this._members = new
|
|
696
|
-
this.onMemberAdmitted = new
|
|
604
|
+
this._members = new ComplexMap2(PublicKey4.hash);
|
|
605
|
+
this.onMemberAdmitted = new Callback2();
|
|
697
606
|
}
|
|
698
607
|
get creator() {
|
|
699
608
|
return this._creator;
|
|
@@ -790,7 +699,7 @@ var MemberStateMachine = class {
|
|
|
790
699
|
|
|
791
700
|
// packages/core/halo/credentials/src/state-machine/space-state-machine.ts
|
|
792
701
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
|
|
793
|
-
var
|
|
702
|
+
var REVOKABLE_CREDENTIALS = [
|
|
794
703
|
"dxos.halo.credentials.SpaceMember"
|
|
795
704
|
];
|
|
796
705
|
var SpaceStateMachine = class {
|
|
@@ -798,16 +707,13 @@ var SpaceStateMachine = class {
|
|
|
798
707
|
this._spaceKey = _spaceKey;
|
|
799
708
|
this._members = new MemberStateMachine(this._spaceKey);
|
|
800
709
|
this._feeds = new FeedStateMachine(this._spaceKey);
|
|
801
|
-
this._invitations = new InvitationStateMachine();
|
|
802
710
|
this._credentials = [];
|
|
803
|
-
this._credentialsById = new
|
|
804
|
-
this._processedCredentials = new
|
|
711
|
+
this._credentialsById = new ComplexMap3(PublicKey5.hash);
|
|
712
|
+
this._processedCredentials = new ComplexSet(PublicKey5.hash);
|
|
805
713
|
this._credentialProcessors = [];
|
|
806
|
-
this.onCredentialProcessed = new
|
|
714
|
+
this.onCredentialProcessed = new Callback3();
|
|
807
715
|
this.onMemberAdmitted = this._members.onMemberAdmitted;
|
|
808
716
|
this.onFeedAdmitted = this._feeds.onFeedAdmitted;
|
|
809
|
-
this.onDelegatedInvitation = this._invitations.onDelegatedInvitation;
|
|
810
|
-
this.onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;
|
|
811
717
|
}
|
|
812
718
|
get creator() {
|
|
813
719
|
return this._members.creator;
|
|
@@ -827,9 +733,6 @@ var SpaceStateMachine = class {
|
|
|
827
733
|
get genesisCredential() {
|
|
828
734
|
return this._genesisCredential;
|
|
829
735
|
}
|
|
830
|
-
get invitations() {
|
|
831
|
-
return this._invitations.invitations;
|
|
832
|
-
}
|
|
833
736
|
async addCredentialProcessor(processor) {
|
|
834
737
|
if (this._credentialProcessors.find((p) => p.processor === processor)) {
|
|
835
738
|
throw new Error("Credential processor already added.");
|
|
@@ -868,7 +771,7 @@ var SpaceStateMachine = class {
|
|
|
868
771
|
if (result.kind !== "pass") {
|
|
869
772
|
log2.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, {
|
|
870
773
|
F: __dxlog_file4,
|
|
871
|
-
L:
|
|
774
|
+
L: 139,
|
|
872
775
|
S: this,
|
|
873
776
|
C: (f, a) => f(...a)
|
|
874
777
|
});
|
|
@@ -881,7 +784,7 @@ var SpaceStateMachine = class {
|
|
|
881
784
|
if (!this._canRevokeCredentials(credential.issuer)) {
|
|
882
785
|
log2.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
|
|
883
786
|
F: __dxlog_file4,
|
|
884
|
-
L:
|
|
787
|
+
L: 148,
|
|
885
788
|
S: this,
|
|
886
789
|
C: (f, a) => f(...a)
|
|
887
790
|
});
|
|
@@ -891,7 +794,7 @@ var SpaceStateMachine = class {
|
|
|
891
794
|
if (!toBeRevoked) {
|
|
892
795
|
log2.warn(`Credential to revoke not found: ${credential.subject.id}`, void 0, {
|
|
893
796
|
F: __dxlog_file4,
|
|
894
|
-
L:
|
|
797
|
+
L: 153,
|
|
895
798
|
S: this,
|
|
896
799
|
C: (f, a) => f(...a)
|
|
897
800
|
});
|
|
@@ -900,7 +803,7 @@ var SpaceStateMachine = class {
|
|
|
900
803
|
if (!this._credentialCanBeRevoked(toBeRevoked)) {
|
|
901
804
|
log2.warn(`Credential cannot be revoked: ${credential.subject.id}`, void 0, {
|
|
902
805
|
F: __dxlog_file4,
|
|
903
|
-
L:
|
|
806
|
+
L: 157,
|
|
904
807
|
S: this,
|
|
905
808
|
C: (f, a) => f(...a)
|
|
906
809
|
});
|
|
@@ -913,7 +816,7 @@ var SpaceStateMachine = class {
|
|
|
913
816
|
if (this._genesisCredential) {
|
|
914
817
|
log2.warn("Space already has a genesis credential.", void 0, {
|
|
915
818
|
F: __dxlog_file4,
|
|
916
|
-
L:
|
|
819
|
+
L: 167,
|
|
917
820
|
S: this,
|
|
918
821
|
C: (f, a) => f(...a)
|
|
919
822
|
});
|
|
@@ -922,7 +825,7 @@ var SpaceStateMachine = class {
|
|
|
922
825
|
if (!credential.issuer.equals(this._spaceKey)) {
|
|
923
826
|
log2.warn("Space genesis credential must be issued by space.", void 0, {
|
|
924
827
|
F: __dxlog_file4,
|
|
925
|
-
L:
|
|
828
|
+
L: 171,
|
|
926
829
|
S: this,
|
|
927
830
|
C: (f, a) => f(...a)
|
|
928
831
|
});
|
|
@@ -931,7 +834,7 @@ var SpaceStateMachine = class {
|
|
|
931
834
|
if (!credential.subject.id.equals(this._spaceKey)) {
|
|
932
835
|
log2.warn("Space genesis credential must be issued to space.", void 0, {
|
|
933
836
|
F: __dxlog_file4,
|
|
934
|
-
L:
|
|
837
|
+
L: 175,
|
|
935
838
|
S: this,
|
|
936
839
|
C: (f, a) => f(...a)
|
|
937
840
|
});
|
|
@@ -947,7 +850,7 @@ var SpaceStateMachine = class {
|
|
|
947
850
|
if (!this._genesisCredential) {
|
|
948
851
|
log2.warn("Space must have a genesis credential before adding members.", void 0, {
|
|
949
852
|
F: __dxlog_file4,
|
|
950
|
-
L:
|
|
853
|
+
L: 189,
|
|
951
854
|
S: this,
|
|
952
855
|
C: (f, a) => f(...a)
|
|
953
856
|
});
|
|
@@ -956,21 +859,20 @@ var SpaceStateMachine = class {
|
|
|
956
859
|
if (!this._canInviteNewMembers(credential.issuer)) {
|
|
957
860
|
log2.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
|
|
958
861
|
F: __dxlog_file4,
|
|
959
|
-
L:
|
|
862
|
+
L: 193,
|
|
960
863
|
S: this,
|
|
961
864
|
C: (f, a) => f(...a)
|
|
962
865
|
});
|
|
963
866
|
return false;
|
|
964
867
|
}
|
|
965
868
|
await this._members.process(credential);
|
|
966
|
-
await this._invitations.process(credential);
|
|
967
869
|
break;
|
|
968
870
|
}
|
|
969
871
|
case "dxos.halo.credentials.MemberProfile": {
|
|
970
872
|
if (!this._genesisCredential) {
|
|
971
873
|
log2.warn("Space must have a genesis credential before adding members.", void 0, {
|
|
972
874
|
F: __dxlog_file4,
|
|
973
|
-
L:
|
|
875
|
+
L: 203,
|
|
974
876
|
S: this,
|
|
975
877
|
C: (f, a) => f(...a)
|
|
976
878
|
});
|
|
@@ -983,7 +885,7 @@ var SpaceStateMachine = class {
|
|
|
983
885
|
if (!this._genesisCredential) {
|
|
984
886
|
log2.warn("Space must have a genesis credential before admitting feeds.", void 0, {
|
|
985
887
|
F: __dxlog_file4,
|
|
986
|
-
L:
|
|
888
|
+
L: 213,
|
|
987
889
|
S: this,
|
|
988
890
|
C: (f, a) => f(...a)
|
|
989
891
|
});
|
|
@@ -992,7 +894,7 @@ var SpaceStateMachine = class {
|
|
|
992
894
|
if (!this._canAdmitFeeds(credential.issuer)) {
|
|
993
895
|
log2.warn(`Space member is not authorized to admit feeds: ${credential.issuer}`, void 0, {
|
|
994
896
|
F: __dxlog_file4,
|
|
995
|
-
L:
|
|
897
|
+
L: 217,
|
|
996
898
|
S: this,
|
|
997
899
|
C: (f, a) => f(...a)
|
|
998
900
|
});
|
|
@@ -1001,20 +903,6 @@ var SpaceStateMachine = class {
|
|
|
1001
903
|
await this._feeds.process(credential, sourceFeed);
|
|
1002
904
|
break;
|
|
1003
905
|
}
|
|
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
|
-
}
|
|
1018
906
|
}
|
|
1019
907
|
const newEntry = {
|
|
1020
908
|
credential,
|
|
@@ -1044,7 +932,7 @@ var SpaceStateMachine = class {
|
|
|
1044
932
|
return key.equals(this._spaceKey) || this._members.getRole(key) === SpaceMember2.Role.ADMIN;
|
|
1045
933
|
}
|
|
1046
934
|
_credentialCanBeRevoked(entry) {
|
|
1047
|
-
return
|
|
935
|
+
return REVOKABLE_CREDENTIALS.includes(entry.credential.subject.assertion["@type"]);
|
|
1048
936
|
}
|
|
1049
937
|
};
|
|
1050
938
|
var CredentialConsumer = class {
|
|
@@ -1078,14 +966,14 @@ var CredentialConsumer = class {
|
|
|
1078
966
|
// packages/core/halo/credentials/src/processor/device-state-machine.ts
|
|
1079
967
|
import { Trigger } from "@dxos/async";
|
|
1080
968
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1081
|
-
import { PublicKey as
|
|
969
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1082
970
|
import { log as log3 } from "@dxos/log";
|
|
1083
|
-
import { ComplexMap as
|
|
971
|
+
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
1084
972
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/processor/device-state-machine.ts";
|
|
1085
973
|
var DeviceStateMachine = class {
|
|
1086
974
|
constructor(_params) {
|
|
1087
975
|
this._params = _params;
|
|
1088
|
-
this.authorizedDeviceKeys = new
|
|
976
|
+
this.authorizedDeviceKeys = new ComplexMap4(PublicKey6.hash);
|
|
1089
977
|
this.deviceChainReady = new Trigger();
|
|
1090
978
|
}
|
|
1091
979
|
async processCredential(credential) {
|
|
@@ -1203,7 +1091,6 @@ export {
|
|
|
1203
1091
|
CredentialGenerator,
|
|
1204
1092
|
DeviceStateMachine,
|
|
1205
1093
|
FeedStateMachine,
|
|
1206
|
-
InvitationStateMachine,
|
|
1207
1094
|
MemberStateMachine,
|
|
1208
1095
|
ProfileStateMachine,
|
|
1209
1096
|
SIGNATURE_TYPE_ED25519,
|
|
@@ -1215,7 +1102,6 @@ export {
|
|
|
1215
1102
|
createCredentialMessage,
|
|
1216
1103
|
createCredentialSignerWithChain,
|
|
1217
1104
|
createCredentialSignerWithKey,
|
|
1218
|
-
createDelegatedSpaceInvitationCredential,
|
|
1219
1105
|
createDeviceAuthorization,
|
|
1220
1106
|
credentialTypeFilter,
|
|
1221
1107
|
defaultSecretProvider,
|