@dxos/credentials 0.7.5-feature-compute.4d9d99a → 0.7.5-labs.35b4b42

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