@dxos/credentials 0.7.5-labs.35b4b42 → 0.7.5-labs.5f04cf6

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.
@@ -1,22 +1,5 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
- // packages/core/halo/credentials/src/did.ts
4
- import { subtleCrypto } from "@dxos/crypto";
5
- import { PublicKey, IdentityDid } from "@dxos/keys";
6
- import { ComplexMap } from "@dxos/util";
7
- var IDENTITY_DIDS_CACHE = new ComplexMap(PublicKey.hash);
8
- var createDidFromIdentityKey = async (identityKey) => {
9
- const cachedValue = IDENTITY_DIDS_CACHE.get(identityKey);
10
- if (cachedValue !== void 0) {
11
- return cachedValue;
12
- }
13
- const digest = await subtleCrypto.digest("SHA-256", identityKey.asUint8Array());
14
- const bytes = new Uint8Array(digest).slice(0, IdentityDid.byteLength);
15
- const identityDid = IdentityDid.encode(bytes);
16
- IDENTITY_DIDS_CACHE.set(identityKey, identityDid);
17
- return identityDid;
18
- };
19
-
20
3
  // packages/core/halo/credentials/src/invitations.ts
21
4
  var defaultSecretProvider = async () => Buffer.from("0000");
22
5
  var defaultSecretValidator = async (invitation, secret) => true;
@@ -52,7 +35,7 @@ var generatePasscode = (length = 4) => {
52
35
 
53
36
  // packages/core/halo/credentials/src/credentials/signing.ts
54
37
  import stableStringify from "json-stable-stringify";
55
- import { PublicKey as PublicKey2 } from "@dxos/keys";
38
+ import { PublicKey } from "@dxos/keys";
56
39
  import { Timeframe } from "@dxos/timeframe";
57
40
  import { arrayToBuffer } from "@dxos/util";
58
41
  var getCredentialProofPayload = (credential) => {
@@ -87,7 +70,7 @@ var canonicalStringify = (obj) => stableStringify(obj, {
87
70
  }
88
71
  const original = this[key];
89
72
  if (value) {
90
- if (PublicKey2.isPublicKey(value)) {
73
+ if (PublicKey.isPublicKey(value)) {
91
74
  return value.toHex();
92
75
  }
93
76
  if (Buffer.isBuffer(value)) {
@@ -152,9 +135,9 @@ var checkCredentialType = (credential, type) => credential.subject.assertion["@t
152
135
  var credentialTypeFilter = (type) => (credential) => checkCredentialType(credential, type);
153
136
 
154
137
  // packages/core/halo/credentials/src/credentials/credential-factory.ts
155
- import { subtleCrypto as subtleCrypto2 } from "@dxos/crypto";
138
+ import { subtleCrypto } from "@dxos/crypto";
156
139
  import { invariant as invariant2 } from "@dxos/invariant";
157
- import { PublicKey as PublicKey3 } from "@dxos/keys";
140
+ import { PublicKey as PublicKey2 } from "@dxos/keys";
158
141
 
159
142
  // packages/core/halo/credentials/src/credentials/verifier.ts
160
143
  import { verifySignature } from "@dxos/crypto";
@@ -279,7 +262,7 @@ var createCredential = async ({ signer, issuer, subject, assertion, signingKey,
279
262
  if (chain) {
280
263
  credential.proof.chain = chain;
281
264
  }
282
- credential.id = PublicKey3.from(await subtleCrypto2.digest("SHA-256", signedPayload));
265
+ credential.id = PublicKey2.from(await subtleCrypto.digest("SHA-256", signedPayload));
283
266
  return credential;
284
267
  };
285
268
  var createCredentialMessage = (credential) => {
@@ -624,22 +607,22 @@ var verifyPresentationSignature = async (presentation, proof) => {
624
607
  };
625
608
 
626
609
  // packages/core/halo/credentials/src/state-machine/space-state-machine.ts
627
- import { runInContextAsync, synchronized } from "@dxos/async";
610
+ import { runInContextAsync } from "@dxos/async";
628
611
  import { Context } from "@dxos/context";
629
- import { PublicKey as PublicKey8 } from "@dxos/keys";
612
+ import { PublicKey as PublicKey7 } from "@dxos/keys";
630
613
  import { log as log3 } from "@dxos/log";
631
614
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
632
- import { Callback as Callback4, ComplexMap as ComplexMap6, ComplexSet as ComplexSet3 } from "@dxos/util";
615
+ import { Callback as Callback4, ComplexMap as ComplexMap5, ComplexSet as ComplexSet3 } from "@dxos/util";
633
616
 
634
617
  // packages/core/halo/credentials/src/state-machine/feed-state-machine.ts
635
618
  import { invariant as invariant3 } from "@dxos/invariant";
636
- import { PublicKey as PublicKey4 } from "@dxos/keys";
637
- import { Callback, ComplexMap as ComplexMap2 } from "@dxos/util";
619
+ import { PublicKey as PublicKey3 } from "@dxos/keys";
620
+ import { Callback, ComplexMap } from "@dxos/util";
638
621
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/feed-state-machine.ts";
639
622
  var FeedStateMachine = class {
640
623
  constructor(_spaceKey) {
641
624
  this._spaceKey = _spaceKey;
642
- this._feeds = new ComplexMap2(PublicKey4.hash);
625
+ this._feeds = new ComplexMap(PublicKey3.hash);
643
626
  this.onFeedAdmitted = new Callback();
644
627
  }
645
628
  get feeds() {
@@ -683,13 +666,13 @@ var FeedStateMachine = class {
683
666
  };
684
667
 
685
668
  // packages/core/halo/credentials/src/state-machine/invitation-state-machine.ts
686
- import { PublicKey as PublicKey5 } from "@dxos/keys";
687
- import { Callback as Callback2, ComplexMap as ComplexMap3, ComplexSet } from "@dxos/util";
669
+ import { PublicKey as PublicKey4 } from "@dxos/keys";
670
+ import { Callback as Callback2, ComplexMap as ComplexMap2, ComplexSet } from "@dxos/util";
688
671
  var InvitationStateMachine = class {
689
672
  constructor() {
690
- this._invitations = new ComplexMap3(PublicKey5.hash);
691
- this._redeemedInvitationCredentialIds = new ComplexSet(PublicKey5.hash);
692
- this._cancelledInvitationCredentialIds = new ComplexSet(PublicKey5.hash);
673
+ this._invitations = new ComplexMap2(PublicKey4.hash);
674
+ this._redeemedInvitationCredentialIds = new ComplexSet(PublicKey4.hash);
675
+ this._cancelledInvitationCredentialIds = new ComplexSet(PublicKey4.hash);
693
676
  this.onDelegatedInvitation = new Callback2();
694
677
  this.onDelegatedInvitationRemoved = new Callback2();
695
678
  }
@@ -754,16 +737,16 @@ var InvitationStateMachine = class {
754
737
 
755
738
  // packages/core/halo/credentials/src/state-machine/member-state-machine.ts
756
739
  import { invariant as invariant5 } from "@dxos/invariant";
757
- import { PublicKey as PublicKey7 } from "@dxos/keys";
740
+ import { PublicKey as PublicKey6 } from "@dxos/keys";
758
741
  import { log as log2 } from "@dxos/log";
759
742
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
760
- import { ComplexMap as ComplexMap5 } from "@dxos/util";
743
+ import { ComplexMap as ComplexMap4 } from "@dxos/util";
761
744
 
762
745
  // packages/core/halo/credentials/src/graph/credential-graph.ts
763
746
  import { invariant as invariant4 } from "@dxos/invariant";
764
- import { PublicKey as PublicKey6 } from "@dxos/keys";
747
+ import { PublicKey as PublicKey5 } from "@dxos/keys";
765
748
  import { log } from "@dxos/log";
766
- import { Callback as Callback3, ComplexMap as ComplexMap4, ComplexSet as ComplexSet2 } from "@dxos/util";
749
+ import { Callback as Callback3, ComplexMap as ComplexMap3, ComplexSet as ComplexSet2 } from "@dxos/util";
767
750
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/graph/credential-graph.ts";
768
751
  var CredentialGraph = class {
769
752
  constructor(_stateHandler) {
@@ -779,9 +762,9 @@ var CredentialGraph = class {
779
762
  parents: [],
780
763
  children: []
781
764
  };
782
- this._vertexByCredentialId = new ComplexMap4(PublicKey6.hash);
783
- this._subjectToVertex = new ComplexMap4(PublicKey6.hash);
784
- this._subjectToState = new ComplexMap4(PublicKey6.hash);
765
+ this._vertexByCredentialId = new ComplexMap3(PublicKey5.hash);
766
+ this._subjectToVertex = new ComplexMap3(PublicKey5.hash);
767
+ this._subjectToState = new ComplexMap3(PublicKey5.hash);
785
768
  this.onSubjectStateChanged = new Callback3();
786
769
  }
787
770
  getSubjectState(subjectId) {
@@ -948,7 +931,7 @@ var CredentialGraph = class {
948
931
  }
949
932
  _replayFailedPaths(paths, pendingPaths, mergeResult, convergedPaths) {
950
933
  paths.push(...mergeResult.replay.map((path) => {
951
- const stateOverrides = path.stateOverrides ?? new ComplexMap4(PublicKey6.hash);
934
+ const stateOverrides = path.stateOverrides ?? new ComplexMap3(PublicKey5.hash);
952
935
  mergeResult.stateOverrides.forEach((value, key) => stateOverrides.set(key, value));
953
936
  return {
954
937
  ...mergeResult.from,
@@ -1040,12 +1023,12 @@ var CredentialGraph = class {
1040
1023
  ]
1041
1024
  },
1042
1025
  head: choice,
1043
- credentials: new ComplexSet2(PublicKey6.hash, path.credentials),
1044
- state: new ComplexMap4(PublicKey6.hash, [
1026
+ credentials: new ComplexSet2(PublicKey5.hash, path.credentials),
1027
+ state: new ComplexMap3(PublicKey5.hash, [
1045
1028
  ...path.state.entries()
1046
1029
  ]),
1047
- forkIssuers: new ComplexSet2(PublicKey6.hash),
1048
- forkChangedSubjects: new ComplexSet2(PublicKey6.hash),
1030
+ forkIssuers: new ComplexSet2(PublicKey5.hash),
1031
+ forkChangedSubjects: new ComplexSet2(PublicKey5.hash),
1049
1032
  stateOverrides: path.stateOverrides
1050
1033
  };
1051
1034
  paths.push(fork);
@@ -1057,8 +1040,8 @@ var CredentialGraph = class {
1057
1040
  */
1058
1041
  _setCurrentState(path) {
1059
1042
  const changedSubjects = [];
1060
- const newStateMap = new ComplexMap4(PublicKey6.hash);
1061
- const newVertexMap = new ComplexMap4(PublicKey6.hash);
1043
+ const newStateMap = new ComplexMap3(PublicKey5.hash);
1044
+ const newVertexMap = new ComplexMap3(PublicKey5.hash);
1062
1045
  for (const [subjectKey, subjectVertex] of path.state.entries()) {
1063
1046
  const newState = this._stateHandler.createState(subjectVertex.credential, subjectVertex.assertion);
1064
1047
  const prevState = this._subjectToState.get(subjectKey);
@@ -1166,13 +1149,13 @@ var CredentialGraph = class {
1166
1149
  [forkPoint.head.id]: []
1167
1150
  },
1168
1151
  stateOverrides: forkPoint.stateOverrides,
1169
- credentials: new ComplexSet2(PublicKey6.hash, forkPoint.credentials),
1170
- forkIssuers: new ComplexSet2(PublicKey6.hash, forkPoint.forkIssuers),
1171
- forkChangedSubjects: new ComplexSet2(PublicKey6.hash, forkPoint.forkChangedSubjects),
1152
+ credentials: new ComplexSet2(PublicKey5.hash, forkPoint.credentials),
1153
+ forkIssuers: new ComplexSet2(PublicKey5.hash, forkPoint.forkIssuers),
1154
+ forkChangedSubjects: new ComplexSet2(PublicKey5.hash, forkPoint.forkChangedSubjects),
1172
1155
  state: forkPoint.state.mapValues((v) => v),
1173
1156
  head: paths[0].head
1174
1157
  };
1175
- const subjectToBranch = new ComplexMap4(PublicKey6.hash);
1158
+ const subjectToBranch = new ComplexMap3(PublicKey5.hash);
1176
1159
  for (const path of paths) {
1177
1160
  log("processing a path", () => ({
1178
1161
  choices: toChosenPath(path),
@@ -1300,10 +1283,10 @@ var CredentialGraph = class {
1300
1283
  return {
1301
1284
  head: this._root,
1302
1285
  chosenPath: {},
1303
- forkIssuers: new ComplexSet2(PublicKey6.hash),
1304
- forkChangedSubjects: new ComplexSet2(PublicKey6.hash),
1305
- state: new ComplexMap4(PublicKey6.hash),
1306
- credentials: new ComplexSet2(PublicKey6.hash)
1286
+ forkIssuers: new ComplexSet2(PublicKey5.hash),
1287
+ forkChangedSubjects: new ComplexSet2(PublicKey5.hash),
1288
+ state: new ComplexMap3(PublicKey5.hash),
1289
+ credentials: new ComplexSet2(PublicKey5.hash)
1307
1290
  };
1308
1291
  }
1309
1292
  };
@@ -1319,7 +1302,7 @@ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/
1319
1302
  var MemberStateMachine = class {
1320
1303
  constructor(_spaceKey) {
1321
1304
  this._spaceKey = _spaceKey;
1322
- this._memberProfiles = new ComplexMap5(PublicKey7.hash);
1305
+ this._memberProfiles = new ComplexMap4(PublicKey6.hash);
1323
1306
  this._hashgraph = new CredentialGraph(this);
1324
1307
  this.onMemberRoleChanged = this._hashgraph.onSubjectStateChanged;
1325
1308
  }
@@ -1461,12 +1444,6 @@ var MemberStateMachine = class {
1461
1444
  };
1462
1445
 
1463
1446
  // packages/core/halo/credentials/src/state-machine/space-state-machine.ts
1464
- function _ts_decorate(decorators, target, key, desc) {
1465
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1466
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1467
- 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;
1468
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1469
- }
1470
1447
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/state-machine/space-state-machine.ts";
1471
1448
  var SpaceStateMachine = class {
1472
1449
  constructor(_spaceKey) {
@@ -1475,8 +1452,8 @@ var SpaceStateMachine = class {
1475
1452
  this._feeds = new FeedStateMachine(this._spaceKey);
1476
1453
  this._invitations = new InvitationStateMachine();
1477
1454
  this._credentials = [];
1478
- this._credentialsById = new ComplexMap6(PublicKey8.hash);
1479
- this._processedCredentials = new ComplexSet3(PublicKey8.hash);
1455
+ this._credentialsById = new ComplexMap5(PublicKey7.hash);
1456
+ this._processedCredentials = new ComplexSet3(PublicKey7.hash);
1480
1457
  this._credentialProcessors = [];
1481
1458
  this.onCredentialProcessed = new Callback4();
1482
1459
  this.onMemberRoleChanged = this._members.onMemberRoleChanged;
@@ -1533,6 +1510,7 @@ var SpaceStateMachine = class {
1533
1510
  /**
1534
1511
  * @param credential Message to process.
1535
1512
  * @param fromFeed Key of the feed where this credential is recorded.
1513
+ * @synchronized
1536
1514
  */
1537
1515
  async process(credential, { sourceFeed, skipVerification }) {
1538
1516
  if (credential.id && this._processedCredentials.has(credential.id)) {
@@ -1696,9 +1674,6 @@ var SpaceStateMachine = class {
1696
1674
  return role === SpaceMember3.Role.EDITOR || role === SpaceMember3.Role.ADMIN || role === SpaceMember3.Role.OWNER;
1697
1675
  }
1698
1676
  };
1699
- _ts_decorate([
1700
- synchronized
1701
- ], SpaceStateMachine.prototype, "process", null);
1702
1677
  var CredentialConsumer = class {
1703
1678
  constructor(processor, _onOpen, _onClose) {
1704
1679
  this.processor = processor;
@@ -1733,14 +1708,14 @@ var CredentialConsumer = class {
1733
1708
  // packages/core/halo/credentials/src/processor/device-state-machine.ts
1734
1709
  import { Trigger } from "@dxos/async";
1735
1710
  import { invariant as invariant6 } from "@dxos/invariant";
1736
- import { PublicKey as PublicKey9 } from "@dxos/keys";
1711
+ import { PublicKey as PublicKey8 } from "@dxos/keys";
1737
1712
  import { log as log4 } from "@dxos/log";
1738
- import { ComplexMap as ComplexMap7 } from "@dxos/util";
1713
+ import { ComplexMap as ComplexMap6 } from "@dxos/util";
1739
1714
  var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/halo/credentials/src/processor/device-state-machine.ts";
1740
1715
  var DeviceStateMachine = class {
1741
1716
  constructor(_params) {
1742
1717
  this._params = _params;
1743
- this.authorizedDeviceKeys = new ComplexMap7(PublicKey9.hash);
1718
+ this.authorizedDeviceKeys = new ComplexMap6(PublicKey8.hash);
1744
1719
  this.deviceChainReady = new Trigger();
1745
1720
  }
1746
1721
  async processCredential(credential) {
@@ -1873,7 +1848,6 @@ export {
1873
1848
  createCredentialSignerWithKey,
1874
1849
  createDelegatedSpaceInvitationCredential,
1875
1850
  createDeviceAuthorization,
1876
- createDidFromIdentityKey,
1877
1851
  credentialTypeFilter,
1878
1852
  defaultSecretProvider,
1879
1853
  defaultSecretValidator,