@dxos/credentials 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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.
Files changed (37) hide show
  1. package/dist/lib/{browser → neutral}/index.mjs +45 -22
  2. package/dist/lib/neutral/index.mjs.map +7 -0
  3. package/dist/lib/{browser → neutral}/meta.json +1 -1
  4. package/dist/types/src/credentials/credential-factory.d.ts +4 -4
  5. package/dist/types/src/credentials/credential-factory.d.ts.map +1 -1
  6. package/dist/types/src/credentials/credential-generator.d.ts +3 -3
  7. package/dist/types/src/credentials/credential-generator.d.ts.map +1 -1
  8. package/dist/types/src/credentials/signing.d.ts.map +1 -1
  9. package/dist/types/src/presentations/presentation.d.ts.map +1 -1
  10. package/dist/types/src/presentations/verifier.d.ts.map +1 -1
  11. package/dist/types/src/processor/device-state-machine.d.ts +2 -2
  12. package/dist/types/src/processor/device-state-machine.d.ts.map +1 -1
  13. package/dist/types/src/processor/profile-state-machine.d.ts +2 -2
  14. package/dist/types/src/processor/profile-state-machine.d.ts.map +1 -1
  15. package/dist/types/src/state-machine/space-state-machine.d.ts +7 -1
  16. package/dist/types/src/state-machine/space-state-machine.d.ts.map +1 -1
  17. package/dist/types/tsconfig.tsbuildinfo +1 -1
  18. package/docs/README.md +17 -17
  19. package/moon.yml +2 -1
  20. package/package.json +18 -16
  21. package/src/credentials/credential-factory.ts +4 -4
  22. package/src/credentials/credential-generator.ts +5 -0
  23. package/src/credentials/signing.ts +12 -0
  24. package/src/presentations/json-encoding.test.ts +0 -2
  25. package/src/presentations/presentation.ts +0 -1
  26. package/src/presentations/verifier.test.ts +0 -1
  27. package/src/presentations/verifier.ts +0 -1
  28. package/src/processor/device-state-machine.ts +2 -3
  29. package/src/processor/profile-state-machine.ts +2 -3
  30. package/src/state-machine/invitation-state-machine.test.ts +0 -1
  31. package/src/state-machine/member-state-machine.test.ts +0 -1
  32. package/src/state-machine/space-state-machine.test.ts +243 -2
  33. package/src/state-machine/space-state-machine.ts +20 -2
  34. package/dist/lib/browser/index.mjs.map +0 -7
  35. package/dist/lib/node-esm/index.mjs +0 -1912
  36. package/dist/lib/node-esm/index.mjs.map +0 -7
  37. package/dist/lib/node-esm/meta.json +0 -1
@@ -68,6 +68,14 @@ var getCredentialProofPayload = (credential) => {
68
68
  delete copy.parentCredentialIds;
69
69
  }
70
70
  delete copy.id;
71
+ const assertion = copy.subject?.assertion;
72
+ if (assertion) {
73
+ for (const key of Object.keys(assertion)) {
74
+ if (Array.isArray(assertion[key]) && assertion[key].length === 0) {
75
+ delete assertion[key];
76
+ }
77
+ }
78
+ }
71
79
  return Buffer.from(canonicalStringify(copy));
72
80
  };
73
81
  var canonicalStringify = (obj) => stableStringify(obj, {
@@ -314,7 +322,7 @@ var createCredentialSignerWithChain = (signer, chain, signingKey) => ({
314
322
  });
315
323
 
316
324
  // src/credentials/credential-generator.ts
317
- import { AdmittedFeed, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
325
+ import { AdmittedFeed, MembershipPolicy, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
318
326
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
319
327
  var CredentialGenerator = class {
320
328
  _signer;
@@ -328,7 +336,7 @@ var CredentialGenerator = class {
328
336
  /**
329
337
  * Create genesis messages for new Space.
330
338
  */
331
- async createSpaceGenesis(spaceKey, controlKey, creatorProfile) {
339
+ async createSpaceGenesis(spaceKey, controlKey, creatorProfile, membershipPolicy = MembershipPolicy.INVITE) {
332
340
  return [
333
341
  await createCredential({
334
342
  signer: this._signer,
@@ -336,7 +344,8 @@ var CredentialGenerator = class {
336
344
  subject: spaceKey,
337
345
  assertion: {
338
346
  "@type": "dxos.halo.credentials.SpaceGenesis",
339
- spaceKey
347
+ spaceKey,
348
+ membershipPolicy
340
349
  }
341
350
  }),
342
351
  await createCredential({
@@ -463,7 +472,7 @@ var createDeviceAuthorization = async (signer, identityKey, deviceKey) => {
463
472
  credential
464
473
  }));
465
474
  };
466
- var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, role = SpaceMember.Role.ADMIN, membershipChainHeads = [], profile, invitationCredentialId) => {
475
+ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFeedKey, role = SpaceMember.Role.ADMIN, membershipChainHeads = [], profile, invitationCredentialId, tags) => {
467
476
  const credentials = await Promise.all([
468
477
  await signer.createCredential({
469
478
  subject: identityKey,
@@ -474,7 +483,8 @@ var createAdmissionCredentials = async (signer, identityKey, spaceKey, genesisFe
474
483
  role,
475
484
  profile,
476
485
  genesisFeedKey,
477
- invitationCredentialId
486
+ invitationCredentialId,
487
+ tags: tags ?? []
478
488
  }
479
489
  })
480
490
  ]);
@@ -631,7 +641,7 @@ import { runInContextAsync, synchronized } from "@dxos/async";
631
641
  import { Context } from "@dxos/context";
632
642
  import { PublicKey as PublicKey8 } from "@dxos/keys";
633
643
  import { log as log3 } from "@dxos/log";
634
- import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
644
+ import { MembershipPolicy as MembershipPolicy2, SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
635
645
  import { Callback as Callback4, ComplexMap as ComplexMap6, ComplexSet as ComplexSet3 } from "@dxos/util";
636
646
 
637
647
  // src/state-machine/feed-state-machine.ts
@@ -1498,6 +1508,8 @@ var SpaceStateMachine = class {
1498
1508
  _credentialsById = new ComplexMap6(PublicKey8.hash);
1499
1509
  _processedCredentials = new ComplexSet3(PublicKey8.hash);
1500
1510
  _genesisCredential;
1511
+ _tags = [];
1512
+ _membershipPolicy = MembershipPolicy2.INVITE;
1501
1513
  _credentialProcessors = [];
1502
1514
  onCredentialProcessed = new Callback4();
1503
1515
  onMemberRoleChanged;
@@ -1532,6 +1544,12 @@ var SpaceStateMachine = class {
1532
1544
  get genesisCredential() {
1533
1545
  return this._genesisCredential;
1534
1546
  }
1547
+ get tags() {
1548
+ return this._tags;
1549
+ }
1550
+ get membershipPolicy() {
1551
+ return this._membershipPolicy;
1552
+ }
1535
1553
  get invitations() {
1536
1554
  return this._invitations.invitations;
1537
1555
  }
@@ -1573,7 +1591,7 @@ var SpaceStateMachine = class {
1573
1591
  if (result.kind !== "pass") {
1574
1592
  log3.warn(`Invalid credential: ${result.errors.join(", ")}`, void 0, {
1575
1593
  F: __dxlog_file6,
1576
- L: 162,
1594
+ L: 173,
1577
1595
  S: this,
1578
1596
  C: (f, a) => f(...a)
1579
1597
  });
@@ -1586,7 +1604,7 @@ var SpaceStateMachine = class {
1586
1604
  if (this._genesisCredential) {
1587
1605
  log3.warn("Space already has a genesis credential.", void 0, {
1588
1606
  F: __dxlog_file6,
1589
- L: 171,
1607
+ L: 182,
1590
1608
  S: this,
1591
1609
  C: (f, a) => f(...a)
1592
1610
  });
@@ -1595,7 +1613,7 @@ var SpaceStateMachine = class {
1595
1613
  if (!credential.issuer.equals(this._spaceKey)) {
1596
1614
  log3.warn("Space genesis credential must be issued by space.", void 0, {
1597
1615
  F: __dxlog_file6,
1598
- L: 175,
1616
+ L: 186,
1599
1617
  S: this,
1600
1618
  C: (f, a) => f(...a)
1601
1619
  });
@@ -1604,13 +1622,15 @@ var SpaceStateMachine = class {
1604
1622
  if (!credential.subject.id.equals(this._spaceKey)) {
1605
1623
  log3.warn("Space genesis credential must be issued to space.", void 0, {
1606
1624
  F: __dxlog_file6,
1607
- L: 179,
1625
+ L: 190,
1608
1626
  S: this,
1609
1627
  C: (f, a) => f(...a)
1610
1628
  });
1611
1629
  return false;
1612
1630
  }
1613
1631
  this._genesisCredential = credential;
1632
+ this._tags = assertion.tags ?? [];
1633
+ this._membershipPolicy = assertion.membershipPolicy ?? MembershipPolicy2.INVITE;
1614
1634
  break;
1615
1635
  }
1616
1636
  case "dxos.halo.credentials.SpaceMember": {
@@ -1620,7 +1640,7 @@ var SpaceStateMachine = class {
1620
1640
  if (!this._genesisCredential) {
1621
1641
  log3.warn("Space must have a genesis credential before adding members.", void 0, {
1622
1642
  F: __dxlog_file6,
1623
- L: 192,
1643
+ L: 205,
1624
1644
  S: this,
1625
1645
  C: (f, a) => f(...a)
1626
1646
  });
@@ -1629,7 +1649,7 @@ var SpaceStateMachine = class {
1629
1649
  if (!this._canInviteNewMembers(credential.issuer)) {
1630
1650
  log3.warn(`Space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1631
1651
  F: __dxlog_file6,
1632
- L: 196,
1652
+ L: 209,
1633
1653
  S: this,
1634
1654
  C: (f, a) => f(...a)
1635
1655
  });
@@ -1643,7 +1663,7 @@ var SpaceStateMachine = class {
1643
1663
  if (!this._genesisCredential) {
1644
1664
  log3.warn("Space must have a genesis credential before adding members.", void 0, {
1645
1665
  F: __dxlog_file6,
1646
- L: 207,
1666
+ L: 220,
1647
1667
  S: this,
1648
1668
  C: (f, a) => f(...a)
1649
1669
  });
@@ -1656,7 +1676,7 @@ var SpaceStateMachine = class {
1656
1676
  if (!this._genesisCredential) {
1657
1677
  log3.warn("Space must have a genesis credential before admitting feeds.", void 0, {
1658
1678
  F: __dxlog_file6,
1659
- L: 217,
1679
+ L: 230,
1660
1680
  S: this,
1661
1681
  C: (f, a) => f(...a)
1662
1682
  });
@@ -1670,7 +1690,7 @@ var SpaceStateMachine = class {
1670
1690
  if (!this._canInviteNewMembers(credential.issuer)) {
1671
1691
  log3.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`, void 0, {
1672
1692
  F: __dxlog_file6,
1673
- L: 228,
1693
+ L: 241,
1674
1694
  S: this,
1675
1695
  C: (f, a) => f(...a)
1676
1696
  });
@@ -1704,6 +1724,9 @@ var SpaceStateMachine = class {
1704
1724
  return this._canInviteNewMembers(memberKey);
1705
1725
  }
1706
1726
  _canInviteNewMembers(key) {
1727
+ if (this._membershipPolicy === MembershipPolicy2.LOCKED) {
1728
+ return key.equals(this._spaceKey) && this._members.members.size === 0;
1729
+ }
1707
1730
  return key.equals(this._spaceKey) || this._members.getRole(key) === SpaceMember3.Role.ADMIN || this._members.getRole(key) === SpaceMember3.Role.OWNER;
1708
1731
  }
1709
1732
  };
@@ -1716,7 +1739,7 @@ var CredentialConsumer = class {
1716
1739
  _onClose;
1717
1740
  _ctx = new Context(void 0, {
1718
1741
  F: __dxlog_file6,
1719
- L: 273
1742
+ L: 291
1720
1743
  });
1721
1744
  /**
1722
1745
  * @internal
@@ -1773,7 +1796,7 @@ var DeviceStateMachine = class {
1773
1796
  credential
1774
1797
  }, {
1775
1798
  F: __dxlog_file7,
1776
- L: 36,
1799
+ L: 35,
1777
1800
  S: this,
1778
1801
  C: (f, a) => f(...a)
1779
1802
  });
@@ -1793,7 +1816,7 @@ var DeviceStateMachine = class {
1793
1816
  size: this.authorizedDeviceKeys.size
1794
1817
  }, {
1795
1818
  F: __dxlog_file7,
1796
- L: 56,
1819
+ L: 55,
1797
1820
  S: this,
1798
1821
  C: (f, a) => f(...a)
1799
1822
  });
@@ -1803,7 +1826,7 @@ var DeviceStateMachine = class {
1803
1826
  case "dxos.halo.credentials.DeviceProfile": {
1804
1827
  invariant6(this.authorizedDeviceKeys.has(credential.subject.id), "Device not found.", {
1805
1828
  F: __dxlog_file7,
1806
- L: 66,
1829
+ L: 65,
1807
1830
  S: this,
1808
1831
  A: [
1809
1832
  "this.authorizedDeviceKeys.has(credential.subject.id)",
@@ -1816,7 +1839,7 @@ var DeviceStateMachine = class {
1816
1839
  profile: assertion.profile
1817
1840
  }, {
1818
1841
  F: __dxlog_file7,
1819
- L: 69,
1842
+ L: 68,
1820
1843
  S: this,
1821
1844
  C: (f, a) => f(...a)
1822
1845
  });
@@ -1849,7 +1872,7 @@ var ProfileStateMachine = class {
1849
1872
  credential
1850
1873
  }, {
1851
1874
  F: __dxlog_file8,
1852
- L: 35,
1875
+ L: 34,
1853
1876
  S: this,
1854
1877
  C: (f, a) => f(...a)
1855
1878
  });
@@ -1861,7 +1884,7 @@ var ProfileStateMachine = class {
1861
1884
  profile: this.profile
1862
1885
  }, {
1863
1886
  F: __dxlog_file8,
1864
- L: 41,
1887
+ L: 40,
1865
1888
  S: this,
1866
1889
  C: (f, a) => f(...a)
1867
1890
  });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/did.ts", "../../../src/invitations.ts", "../../../src/seedphrase.ts", "../../../src/passcode.ts", "../../../src/credentials/signing.ts", "../../../src/presentations/signing.ts", "../../../src/credentials/assertions.ts", "../../../src/credentials/credential-factory.ts", "../../../src/credentials/verifier.ts", "../../../src/credentials/credential-generator.ts", "../../../src/presentations/presentation.ts", "../../../src/presentations/verifier.ts", "../../../src/state-machine/space-state-machine.ts", "../../../src/state-machine/feed-state-machine.ts", "../../../src/state-machine/invitation-state-machine.ts", "../../../src/state-machine/member-state-machine.ts", "../../../src/graph/credential-graph.ts", "../../../src/processor/device-state-machine.ts", "../../../src/processor/profile-state-machine.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { IdentityDid, PublicKey } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\nconst IDENTITY_DIDS_CACHE = new ComplexMap<PublicKey, IdentityDid>(PublicKey.hash);\n\n/**\n * Identity DIDs are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * Inspired by how ethereum addresses are derived.\n */\nexport const createDidFromIdentityKey = async (identityKey: PublicKey): Promise<IdentityDid> => {\n const cachedValue = IDENTITY_DIDS_CACHE.get(identityKey);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const digest = await subtleCrypto.digest('SHA-256', identityKey.asUint8Array() as Uint8Array<ArrayBuffer>);\n\n const bytes = new Uint8Array(digest).slice(0, IdentityDid.byteLength);\n const identityDid = IdentityDid.encode(bytes);\n IDENTITY_DIDS_CACHE.set(identityKey, identityDid);\n return identityDid;\n};\n", "//\n// Copyright 2019 DXOS.org\n//\n\n/**\n * Info required for offline invitations.\n */\n// TODO(burdon): Define types.\nexport interface SecretInfo {\n id: any;\n authNonce: any;\n}\n\n/**\n * Provides a shared secret during an invitation process.\n */\nexport type SecretProvider = (info?: SecretInfo) => Promise<Buffer>;\n\n/**\n * Validates the shared secret during an invitation process.\n */\nexport type SecretValidator = (invitation: never, secret: Buffer) => Promise<boolean>;\n\nexport const defaultSecretProvider: SecretProvider = async () => Buffer.from('0000');\n\nexport const defaultSecretValidator: SecretValidator = async (invitation, secret) => true;\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { generateMnemonic, mnemonicToSeedSync } from 'bip39';\n\nimport { createKeyPair } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { type KeyPair } from '@dxos/keys';\n\n/**\n * Generate bip39 seed phrase (aka mnemonic).\n */\nexport const generateSeedPhrase = (): string => generateMnemonic();\n\n/**\n * Generate key pair from seed phrase.\n */\nexport const keyPairFromSeedPhrase = (seedPhrase: string): KeyPair => {\n invariant(seedPhrase);\n const seed = mnemonicToSeedSync(seedPhrase);\n return createKeyPair(seed);\n};\n", "//\n// Copyright 2019 DXOS.org\n//\n\n/**\n * Generates a numeric passcode.\n * @param {number} length\n * @returns {string}\n */\nexport const generatePasscode = (length = 4) => {\n let passcode = '';\n for (let i = 0; i < length; i++) {\n passcode += `${Math.floor(Math.random() * 10)}`;\n }\n\n return passcode;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport stableStringify from 'json-stable-stringify';\n\nimport { PublicKey } from '@dxos/keys';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { Timeframe } from '@dxos/timeframe';\nimport { arrayToBuffer } from '@dxos/util';\n\n/**\n * @returns The input message to be signed for a given credential.\n */\n// TODO(nf): rename, this returns not the proof itself, but the payload for verifying against the proof.\nexport const getCredentialProofPayload = (credential: Credential): Uint8Array => {\n const copy = {\n ...credential,\n proof: {\n ...credential.proof,\n value: new Uint8Array(),\n chain: undefined,\n },\n };\n if (copy.parentCredentialIds?.length === 0) {\n delete copy.parentCredentialIds;\n }\n delete copy.id; // ID is not part of the signature payload.\n\n // Normalize empty repeated fields in the assertion to avoid proto3 serialization asymmetry.\n // Proto3 does not encode empty repeated fields, but the codec may restore them as [] after deserialization,\n // causing a signature mismatch if the original signing payload did not include the field.\n const assertion = (copy.subject as any)?.assertion;\n if (assertion) {\n for (const key of Object.keys(assertion)) {\n if (Array.isArray(assertion[key]) && assertion[key].length === 0) {\n delete assertion[key];\n }\n }\n }\n\n return Buffer.from(canonicalStringify(copy));\n};\n\n/**\n * Utility method to produce stable output for signing/verifying.\n */\nexport const canonicalStringify = (obj: any): string =>\n stableStringify(obj, {\n /* The point of signing and verifying is not that the internal, private state of the objects be\n * identical, but that the public contents can be verified not to have been altered. For that reason,\n * really private fields (indicated by '__') are not included in the signature.\n * This gives a mechanism for attaching other attributes to an object without breaking the signature.\n * We also skip @type.\n */\n // TODO(dmaretskyi): Should we actually skip the @type field?\n replacer: function (this: any, key: any, value: any) {\n if (key.toString().startsWith('__') || key.toString() === '@type') {\n return undefined;\n }\n\n if (value === null) {\n return undefined;\n }\n\n // Value before .toJSON() is called.\n const original = this[key];\n\n if (value) {\n if (PublicKey.isPublicKey(value)) {\n return value.toHex();\n }\n if (Buffer.isBuffer(value)) {\n return value.toString('hex');\n }\n\n if (value instanceof Uint8Array) {\n return arrayToBuffer(value).toString('hex');\n }\n if (value.data && value.type === 'Buffer') {\n return Buffer.from(value).toString('hex');\n }\n if (original instanceof Timeframe) {\n // Uses old key truncation method (339d...9d66) to keep backwards compatibility.\n return original.frames().reduce((frames: Record<string, number>, [key, seq]) => {\n frames[truncateKey(key)] = seq;\n return frames;\n }, {});\n }\n }\n\n return value;\n },\n }) as string;\n\n/**\n * Old key truncation method (339d...9d66) to keep backwards compatibility with credentials signed with old method\n */\nconst truncateKey = (key: PublicKey) => {\n const str = key.toHex();\n return `${str.substring(0, 4)}...${str.substring(str.length - 4)}`;\n};\n\n/**\n * export const truncateKey = (key: any, { length = 8, start }: TruncateKeyOptions = {}) => {\nconst str = String(key);\nif (str.length <= length) {\n return str;\n}\n\nreturn start\n ? `${str.slice(0, length)}...`\n : `${str.substring(0, length / 2)}...${str.substring(str.length - length / 2)}`;\n};\n\n{\n\"04009285\": 20,\n\"0415004f\": 0,\n\"0415e6d7\": 9964,\n\"042a4fa9\": 8,\n\"0448e62f\": 3,\n\"04775053\": 257,\n\"04a6b603\": 97,\n\"04bc5c9d\": 198,\n\"04da9930\": 59,\n\"04df0449\": 676,\n\"04e122ae\": 5435,\n\"04ee588b\": 1703\n}\n\n */\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Credential, type Proof } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { canonicalStringify } from '../credentials/signing';\n\nexport const getPresentationProofPayload = (credentials: Credential[], proof: Proof): Uint8Array => {\n const copy = {\n credentials: credentials.map((credential) => removeEmptyParentCredentialIds(credential)),\n proof: {\n ...proof,\n value: new Uint8Array(),\n chain: undefined,\n },\n };\n\n return Buffer.from(canonicalStringify(copy));\n};\n\nconst removeEmptyParentCredentialIds = (credential: Credential): Credential => {\n const copy = {\n ...credential,\n proof: credential.proof\n ? {\n ...credential.proof,\n chain: credential.proof.chain\n ? { credential: removeEmptyParentCredentialIds(credential.proof.chain.credential) }\n : undefined,\n }\n : undefined,\n };\n if (copy.parentCredentialIds?.length === 0) {\n delete copy.parentCredentialIds;\n }\n return copy;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type PublicKey } from '@dxos/keys';\nimport { type TYPES, type TypedMessage } from '@dxos/protocols/proto';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nexport const getCredentialAssertion = (credential: Credential): TypedMessage => credential.subject.assertion;\n\nexport const isValidAuthorizedDeviceCredential = (\n credential: Credential,\n identityKey: PublicKey,\n deviceKey: PublicKey,\n): boolean => {\n const assertion = getCredentialAssertion(credential);\n return (\n credential.subject.id.equals(deviceKey) &&\n credential.issuer.equals(identityKey) &&\n assertion['@type'] === 'dxos.halo.credentials.AuthorizedDevice' &&\n assertion.identityKey.equals(identityKey) &&\n assertion.deviceKey.equals(deviceKey)\n );\n};\n\nexport type SpecificCredential<T> = Omit<Credential, 'subject'> & {\n subject: Omit<Credential['subject'], 'assertion'> & { assertion: T };\n};\n\nexport const checkCredentialType = <K extends keyof TYPES>(\n credential: Credential,\n type: K,\n): credential is SpecificCredential<TYPES[K]> => credential.subject.assertion['@type'] === type;\n\nexport const credentialTypeFilter =\n <K extends keyof TYPES>(type: K) =>\n (credential: Credential): credential is SpecificCredential<TYPES[K]> =>\n checkCredentialType(credential, type);\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Signer, subtleCrypto } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { type TypedMessage } from '@dxos/protocols/proto';\nimport { type Chain, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { getCredentialProofPayload } from './signing';\nimport { SIGNATURE_TYPE_ED25519, verifyChain } from './verifier';\n\nexport type CreateCredentialSignerProps = {\n subject: PublicKey;\n assertion: TypedMessage;\n nonce?: Uint8Array;\n parentCredentialIds?: PublicKey[];\n};\n\nexport type CreateCredentialProps = {\n signer: Signer;\n issuer: PublicKey;\n signingKey?: PublicKey;\n\n // Provided only if signer is different from issuer.\n chain?: Chain;\n\n subject: PublicKey;\n assertion: TypedMessage;\n nonce?: Uint8Array;\n parentCredentialIds?: PublicKey[];\n};\n\n/**\n * Construct a signed credential message.\n */\nexport const createCredential = async ({\n signer,\n issuer,\n subject,\n assertion,\n signingKey,\n chain,\n nonce,\n parentCredentialIds,\n}: CreateCredentialProps): Promise<Credential> => {\n invariant(assertion['@type'], 'Invalid assertion.');\n invariant(!!signingKey === !!chain, 'Chain must be provided if and only if the signing key differs from the issuer.');\n if (chain) {\n const result = await verifyChain(chain, issuer, signingKey!);\n invariant(result.kind === 'pass', 'Invalid chain.');\n }\n\n // Create the credential with proof value and chain fields missing (for signature payload).\n const credential: Credential = {\n issuer,\n issuanceDate: new Date(),\n subject: {\n id: subject,\n assertion,\n },\n parentCredentialIds,\n proof: {\n type: SIGNATURE_TYPE_ED25519,\n creationDate: new Date(),\n signer: signingKey ?? issuer,\n value: new Uint8Array(),\n nonce,\n },\n };\n\n // Set proof after creating signature.\n const signedPayload = getCredentialProofPayload(credential);\n credential.proof!.value = await signer.sign(signingKey ?? issuer, signedPayload);\n if (chain) {\n credential.proof!.chain = chain;\n }\n\n credential.id = PublicKey.from(await subtleCrypto.digest('SHA-256', signedPayload as Uint8Array<ArrayBuffer>));\n\n return credential;\n};\n\n// TODO(burdon): Use consistently (merge halo/echo protocol packages).\nexport const createCredentialMessage = (credential: Credential) => {\n return {\n '@type': 'dxos.echo.feed.CredentialsMessage',\n credential,\n };\n};\n\n// TODO(burdon): Vs. Signer.\nexport interface CredentialSigner {\n getIssuer(): PublicKey;\n createCredential: (params: CreateCredentialSignerProps) => Promise<Credential>;\n}\n\n/**\n * Issue credentials directly signed by the issuer.\n */\nexport const createCredentialSignerWithKey = (signer: Signer, issuer: PublicKey): CredentialSigner => ({\n getIssuer: () => issuer,\n createCredential: ({ subject, assertion, nonce, parentCredentialIds }) =>\n createCredential({\n signer,\n issuer,\n subject,\n assertion,\n nonce,\n parentCredentialIds,\n }),\n});\n\n/**\n * Issue credentials with transitive proof via a chain.\n */\nexport const createCredentialSignerWithChain = (\n signer: Signer,\n chain: Chain,\n signingKey: PublicKey,\n): CredentialSigner => ({\n getIssuer: () => chain.credential.issuer,\n createCredential: ({ subject, assertion, nonce, parentCredentialIds }) =>\n createCredential({\n signer,\n issuer: chain.credential.issuer,\n signingKey,\n chain,\n subject,\n assertion,\n nonce,\n parentCredentialIds,\n }),\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { verifySignature } from '@dxos/crypto';\nimport { type PublicKey } from '@dxos/keys';\nimport { type Chain, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { isValidAuthorizedDeviceCredential } from './assertions';\nimport { getCredentialProofPayload } from './signing';\n\nexport const SIGNATURE_TYPE_ED25519 = 'ED25519Signature';\n\nexport type VerificationResult = { kind: 'pass' } | { kind: 'fail'; errors: string[] };\n\nexport const verifyCredential = async (credential: Credential): Promise<VerificationResult> => {\n if (credential.parentCredentialIds?.length === 0) {\n delete credential.parentCredentialIds;\n }\n\n if (!credential.issuer.equals(credential.proof!.signer)) {\n if (!credential.proof!.chain) {\n return {\n kind: 'fail',\n errors: ['Delegated credential is missing credential chain.'],\n };\n }\n\n const result = await verifyChain(credential.proof!.chain, credential.issuer, credential.proof!.signer);\n if (result.kind === 'fail') {\n return result;\n }\n }\n\n const result = await verifyCredentialSignature(credential);\n if (result.kind === 'fail') {\n return result;\n }\n\n return { kind: 'pass' };\n};\n\n/**\n * Verifies that the signature is valid and was made by the signer.\n * Does not validate other semantics (e.g. chains).\n */\nexport const verifyCredentialSignature = async (credential: Credential): Promise<VerificationResult> => {\n if (credential.proof!.type !== SIGNATURE_TYPE_ED25519) {\n return {\n kind: 'fail',\n errors: [`Invalid signature type: ${credential.proof!.type}`],\n };\n }\n\n const signData = getCredentialProofPayload(credential);\n if (!(await verifySignature(credential.proof!.signer, signData, credential.proof!.value))) {\n return { kind: 'fail', errors: ['Invalid signature'] };\n }\n\n return { kind: 'pass' };\n};\n\n/**\n * Verifies that the signer has the delegated authority to create credentials on behalf of the issuer.\n */\nexport const verifyChain = async (\n chain: Chain,\n authority: PublicKey,\n subject: PublicKey,\n): Promise<VerificationResult> => {\n const result = await verifyCredential(chain.credential);\n if (result.kind === 'fail') {\n return result;\n }\n\n if (!isValidAuthorizedDeviceCredential(chain.credential, authority, subject)) {\n return {\n kind: 'fail',\n errors: [`Invalid credential chain: invalid assertion for key: ${subject}`],\n };\n }\n\n return { kind: 'pass' };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Signer } from '@dxos/crypto';\nimport { type PublicKey } from '@dxos/keys';\nimport { type TypedMessage } from '@dxos/protocols/proto';\nimport { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\nimport {\n AdmittedFeed,\n type Credential,\n type DeviceProfileDocument,\n MembershipPolicy,\n type ProfileDocument,\n SpaceMember,\n} from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';\nimport { Timeframe } from '@dxos/timeframe';\n\nimport { type CredentialSigner, createCredential } from './credential-factory';\n\n// TODO(burdon): Normalize generate and functions below.\n// Use throughout stack and in tests.\n\n/**\n * Utility class for generating credential messages, where the issuer is the current identity or device.\n */\nexport class CredentialGenerator {\n constructor(\n private readonly _signer: Signer,\n private readonly _identityKey: PublicKey,\n private readonly _deviceKey: PublicKey,\n ) {}\n\n /**\n * Create genesis messages for new Space.\n */\n async createSpaceGenesis(\n spaceKey: PublicKey,\n controlKey: PublicKey,\n creatorProfile?: ProfileDocument,\n membershipPolicy: MembershipPolicy = MembershipPolicy.INVITE,\n ): Promise<Credential[]> {\n return [\n await createCredential({\n signer: this._signer,\n issuer: spaceKey,\n subject: spaceKey,\n assertion: {\n '@type': 'dxos.halo.credentials.SpaceGenesis',\n spaceKey,\n membershipPolicy,\n },\n }),\n\n await createCredential({\n signer: this._signer,\n issuer: spaceKey,\n subject: this._identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.SpaceMember',\n spaceKey,\n role: SpaceMember.Role.ADMIN,\n profile: creatorProfile,\n genesisFeedKey: controlKey,\n },\n }),\n\n await this.createFeedAdmission(spaceKey, controlKey, AdmittedFeed.Designation.CONTROL),\n ];\n }\n\n /**\n * Create invitation.\n * Admit identity and control and data feeds.\n */\n // TODO(burdon): Reconcile with above (esp. Signer).\n async createMemberInvitation(\n spaceKey: PublicKey,\n identityKey: PublicKey,\n deviceKey: PublicKey,\n controlKey: PublicKey,\n dataKey: PublicKey,\n genesisFeedKey: PublicKey,\n ): Promise<Credential[]> {\n return [\n await createCredential({\n signer: this._signer,\n issuer: this._identityKey,\n subject: identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.SpaceMember',\n spaceKey,\n role: SpaceMember.Role.EDITOR,\n genesisFeedKey,\n },\n }),\n\n await this.createFeedAdmission(spaceKey, controlKey, AdmittedFeed.Designation.CONTROL),\n await this.createFeedAdmission(spaceKey, dataKey, AdmittedFeed.Designation.DATA),\n ];\n }\n\n /**\n * Add device to space.\n */\n // TODO(burdon): Reconcile with below.\n async createDeviceAuthorization(deviceKey: PublicKey): Promise<Credential> {\n return createCredential({\n signer: this._signer,\n issuer: this._identityKey,\n subject: deviceKey,\n assertion: {\n '@type': 'dxos.halo.credentials.AuthorizedDevice',\n identityKey: this._identityKey,\n deviceKey,\n },\n });\n }\n\n /**\n * Add device metadata.\n */\n async createDeviceProfile(profile: DeviceProfileDocument): Promise<Credential> {\n return createCredential({\n signer: this._signer,\n issuer: this._identityKey,\n subject: this._deviceKey,\n assertion: {\n '@type': 'dxos.halo.credentials.DeviceProfile',\n profile,\n },\n });\n }\n\n /**\n * Add feed to space.\n */\n async createFeedAdmission(\n spaceKey: PublicKey,\n feedKey: PublicKey,\n designation: AdmittedFeed.Designation,\n ): Promise<Credential> {\n return createCredential({\n signer: this._signer,\n issuer: this._identityKey,\n subject: feedKey,\n assertion: {\n '@type': 'dxos.halo.credentials.AdmittedFeed',\n spaceKey,\n identityKey: this._identityKey,\n deviceKey: this._deviceKey,\n designation,\n },\n });\n }\n\n async createProfileCredential(profile: ProfileDocument): Promise<Credential> {\n return createCredential({\n signer: this._signer,\n issuer: this._identityKey,\n subject: this._identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.IdentityProfile',\n profile,\n },\n });\n }\n\n async createEpochCredential(spaceKey: PublicKey): Promise<Credential> {\n return createCredential({\n signer: this._signer,\n issuer: this._identityKey,\n subject: spaceKey,\n assertion: {\n '@type': 'dxos.halo.credentials.Epoch',\n number: 0,\n timeframe: new Timeframe(),\n },\n });\n }\n}\n\n// TODO(burdon): Reconcile with above (esp. Signer).\nexport const createDeviceAuthorization = async (\n signer: CredentialSigner,\n identityKey: PublicKey,\n deviceKey: PublicKey,\n): Promise<TypedMessage[]> => {\n const credentials = await Promise.all([\n await signer.createCredential({\n subject: deviceKey,\n assertion: {\n '@type': 'dxos.halo.credentials.AuthorizedDevice',\n identityKey,\n deviceKey,\n },\n }),\n ]);\n\n return credentials.map((credential) => ({\n '@type': 'dxos.echo.feed.CredentialsMessage',\n credential,\n }));\n};\n\n// TODO(burdon): Reconcile with above (esp. Signer).\n/**\n * @param signer - invitation signer.\n * @param identityKey - identity key of the admitted member.\n * @param spaceKey - subject space key.\n * @param genesisFeedKey - genesis feed key of the space.\n * @param role - role of the newly added member.\n * @param membershipChainHeads - ids of the last known SpaceMember credentials (branching possible).\n * @param profile - profile of the newly added member.\n * @param invitationCredentialId - id of the delegated invitation credential in case one was used to add the member.\n */\nexport const createAdmissionCredentials = async (\n signer: CredentialSigner,\n identityKey: PublicKey,\n spaceKey: PublicKey,\n genesisFeedKey: PublicKey,\n role: SpaceMember.Role = SpaceMember.Role.ADMIN,\n membershipChainHeads: PublicKey[] = [],\n profile?: ProfileDocument,\n invitationCredentialId?: PublicKey,\n tags?: string[],\n): Promise<FeedMessage.Payload[]> => {\n const credentials = await Promise.all([\n await signer.createCredential({\n subject: identityKey,\n parentCredentialIds: membershipChainHeads,\n assertion: {\n '@type': 'dxos.halo.credentials.SpaceMember',\n spaceKey,\n role,\n profile,\n genesisFeedKey,\n invitationCredentialId,\n tags: tags ?? [],\n },\n }),\n ]);\n\n return credentials.map((credential) => ({\n credential: { credential },\n }));\n};\n\nexport const createDelegatedSpaceInvitationCredential = async (\n signer: CredentialSigner,\n subject: PublicKey,\n invitation: DelegateSpaceInvitation,\n): Promise<FeedMessage.Payload> => {\n const credential = await signer.createCredential({\n subject,\n assertion: {\n '@type': 'dxos.halo.invitations.DelegateSpaceInvitation',\n invitationId: invitation.invitationId,\n authMethod: invitation.authMethod,\n swarmKey: invitation.swarmKey,\n role: invitation.role,\n guestKey: invitation.guestKey,\n expiresOn: invitation.expiresOn,\n multiUse: invitation.multiUse,\n },\n });\n return { credential: { credential } };\n};\n\n/**\n * @param signer - credential issuer.\n * @param subject - key of the space the invitation was for.\n * @param invitationCredentialId id of a dxos.halo.invitations.DelegateSpaceInvitation credential.\n */\nexport const createCancelDelegatedSpaceInvitationCredential = async (\n signer: CredentialSigner,\n subject: PublicKey,\n invitationCredentialId: PublicKey,\n): Promise<FeedMessage.Payload> => {\n const credential = await signer.createCredential({\n subject,\n assertion: {\n '@type': 'dxos.halo.invitations.CancelDelegatedInvitation',\n credentialId: invitationCredentialId,\n },\n });\n return { credential: { credential } };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Signer } from '@dxos/crypto';\nimport { type PublicKey } from '@dxos/keys';\nimport { type Chain, type Presentation, type Proof } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { SIGNATURE_TYPE_ED25519 } from '../credentials';\nimport { getPresentationProofPayload } from './signing';\n\n// TODO(burdon): Rename createPresentation?\nexport const signPresentation = async ({\n presentation,\n signer,\n signerKey,\n chain,\n nonce,\n}: {\n presentation: Presentation;\n signer: Signer;\n signerKey: PublicKey;\n chain?: Chain;\n nonce?: Uint8Array;\n}): Promise<Presentation> => {\n const proof: Proof = {\n type: SIGNATURE_TYPE_ED25519,\n value: new Uint8Array(),\n creationDate: new Date(),\n signer: signerKey,\n nonce,\n };\n\n const signedPayload = getPresentationProofPayload(presentation.credentials ?? [], proof);\n proof.value = await signer.sign(signerKey, signedPayload);\n if (chain) {\n proof.chain = chain;\n }\n\n return {\n credentials: presentation.credentials,\n proofs: [...(presentation.proofs ?? []), proof],\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { verifySignature } from '@dxos/crypto';\nimport { type Presentation, type Proof } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { SIGNATURE_TYPE_ED25519, type VerificationResult, verifyChain, verifyCredential } from '../credentials';\nimport { getPresentationProofPayload } from './signing';\n\nexport const verifyPresentation = async (presentation: Presentation): Promise<VerificationResult> => {\n const errors: string[] = [];\n\n // Verify all credentials.\n const credentialsVerifications = await Promise.all(\n presentation.credentials?.map((credential) => verifyCredential(credential)) ?? [],\n );\n for (const verification of credentialsVerifications) {\n if (verification.kind === 'fail') {\n errors.push(...verification.errors);\n }\n }\n\n // Verify all proofs.\n const proofVerification = await Promise.all(\n presentation.proofs?.map(async (proof) => {\n const chainVerification = await verifyPresentationChain(presentation, proof);\n if (chainVerification.kind === 'fail') {\n return chainVerification;\n }\n const signatureVerification = await verifyPresentationSignature(presentation, proof);\n if (signatureVerification.kind === 'fail') {\n return signatureVerification;\n }\n return { kind: 'pass' } as VerificationResult;\n }) ?? [],\n );\n for (const verification of proofVerification) {\n if (verification.kind === 'fail') {\n errors.push(...verification.errors);\n }\n }\n\n if (errors.length === 0) {\n return { kind: 'pass' };\n }\n {\n return {\n kind: 'fail',\n errors,\n };\n }\n};\n\nexport const verifyPresentationChain = async (\n presentation: Presentation,\n proof: Proof,\n): Promise<VerificationResult> => {\n for (const credential of presentation.credentials ?? []) {\n if (!credential.issuer.equals(proof.signer)) {\n if (!proof.chain) {\n return {\n kind: 'fail',\n errors: ['Delegated credential is missing credential chain.'],\n };\n }\n\n const chainVerification = await verifyChain(proof.chain, credential.subject.id, proof.signer);\n if (chainVerification.kind === 'fail') {\n return chainVerification;\n }\n }\n }\n\n return { kind: 'pass' };\n};\n\n/**\n * Verifies that the signature is valid and was made by the signer.\n * Does not validate other semantics (e.g. chains).\n */\nexport const verifyPresentationSignature = async (\n presentation: Presentation,\n proof: Proof,\n): Promise<VerificationResult> => {\n if (proof.type !== SIGNATURE_TYPE_ED25519) {\n return {\n kind: 'fail',\n errors: [`Invalid signature type: ${proof.type}`],\n };\n }\n\n const signData = getPresentationProofPayload(presentation.credentials ?? [], proof);\n if (!(await verifySignature(proof.signer, signData, proof.value))) {\n return { kind: 'fail', errors: ['Invalid signature'] };\n }\n\n return { kind: 'pass' };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { runInContextAsync, synchronized } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type TypedMessage } from '@dxos/protocols/proto';\nimport { type Credential, MembershipPolicy, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';\nimport { type AsyncCallback, Callback, ComplexMap, ComplexSet } from '@dxos/util';\n\nimport { getCredentialAssertion, verifyCredential } from '../credentials';\nimport { type CredentialProcessor } from '../processor/credential-processor';\nimport { type FeedInfo, FeedStateMachine } from './feed-state-machine';\nimport { InvitationStateMachine } from './invitation-state-machine';\nimport { type MemberInfo, MemberStateMachine } from './member-state-machine';\n\nexport interface SpaceState {\n readonly members: ReadonlyMap<PublicKey, MemberInfo>;\n readonly membershipChainHeads: PublicKey[];\n readonly feeds: ReadonlyMap<PublicKey, FeedInfo>;\n readonly credentials: Credential[];\n readonly genesisCredential: Credential | undefined;\n readonly tags: string[];\n readonly membershipPolicy: MembershipPolicy;\n readonly creator: MemberInfo | undefined;\n readonly invitations: ReadonlyMap<PublicKey, DelegateSpaceInvitation>;\n\n addCredentialProcessor(processor: CredentialProcessor): Promise<void>;\n removeCredentialProcessor(processor: CredentialProcessor): Promise<void>;\n\n getCredentialsOfType(type: TypedMessage['@type']): Credential[];\n\n getMemberRole(memberKey: PublicKey): SpaceMember.Role;\n hasMembershipManagementPermission(memberKey: PublicKey): boolean;\n}\n\nexport type ProcessOptions = {\n sourceFeed: PublicKey;\n skipVerification?: boolean;\n};\n\nexport type CredentialEntry = {\n credential: Credential;\n sourceFeed: PublicKey;\n revoked: boolean;\n};\n\n/**\n * Validates and processes credentials for a single space.\n * Keeps a list of members and feeds.\n * Keeps and in-memory index of credentials and allows to query them.\n */\nexport class SpaceStateMachine implements SpaceState {\n private readonly _members: MemberStateMachine;\n private readonly _feeds: FeedStateMachine;\n private readonly _invitations = new InvitationStateMachine();\n private readonly _credentials: CredentialEntry[] = [];\n private readonly _credentialsById = new ComplexMap<PublicKey, CredentialEntry>(PublicKey.hash);\n private readonly _processedCredentials = new ComplexSet<PublicKey>(PublicKey.hash);\n\n private _genesisCredential: Credential | undefined;\n private _tags: string[] = [];\n private _membershipPolicy: MembershipPolicy = MembershipPolicy.INVITE;\n private _credentialProcessors: CredentialConsumer<any>[] = [];\n\n readonly onCredentialProcessed = new Callback<AsyncCallback<Credential>>();\n readonly onMemberRoleChanged: Callback<AsyncCallback<MemberInfo[]>>;\n readonly onFeedAdmitted: Callback<AsyncCallback<FeedInfo>>;\n readonly onDelegatedInvitation = this._invitations.onDelegatedInvitation;\n readonly onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;\n\n constructor(private readonly _spaceKey: PublicKey) {\n this._members = new MemberStateMachine(this._spaceKey);\n this._feeds = new FeedStateMachine(this._spaceKey);\n this.onMemberRoleChanged = this._members.onMemberRoleChanged;\n this.onFeedAdmitted = this._feeds.onFeedAdmitted;\n }\n\n get creator(): MemberInfo | undefined {\n return this._members.creator;\n }\n\n get members(): ReadonlyMap<PublicKey, MemberInfo> {\n return this._members.members;\n }\n\n get membershipChainHeads(): PublicKey[] {\n return this._members.membershipChainHeads;\n }\n\n get feeds(): ReadonlyMap<PublicKey, FeedInfo> {\n return this._feeds.feeds;\n }\n\n get credentials(): Credential[] {\n return this._credentials.map((entry) => entry.credential);\n }\n\n get credentialEntries(): CredentialEntry[] {\n return this._credentials;\n }\n\n get genesisCredential(): Credential | undefined {\n return this._genesisCredential;\n }\n\n get tags(): string[] {\n return this._tags;\n }\n\n get membershipPolicy(): MembershipPolicy {\n return this._membershipPolicy;\n }\n\n get invitations(): ReadonlyMap<PublicKey, DelegateSpaceInvitation> {\n return this._invitations.invitations;\n }\n\n async addCredentialProcessor(processor: CredentialProcessor): Promise<void> {\n if (this._credentialProcessors.find((p) => p.processor === processor)) {\n throw new Error('Credential processor already added.');\n }\n\n const consumer = new CredentialConsumer(\n processor,\n async () => {\n for (const credential of this.credentials) {\n await consumer._process(credential);\n }\n\n // NOTE: It is important to set this flag after immediately after processing existing credentials.\n // Otherwise, we might miss some credentials.\n // Having an `await` statement between the end of the loop and setting the flag would cause a race condition.\n consumer._isReadyForLiveCredentials = true;\n },\n async () => {\n this._credentialProcessors = this._credentialProcessors.filter((p) => p !== consumer);\n },\n );\n this._credentialProcessors.push(consumer);\n\n await consumer.open();\n }\n\n async removeCredentialProcessor(processor: CredentialProcessor): Promise<void> {\n const consumer = this._credentialProcessors.find((p) => p.processor === processor);\n await consumer?.close();\n }\n\n getCredentialsOfType(type: TypedMessage['@type']): Credential[] {\n return this.credentials.filter((credential) => getCredentialAssertion(credential)['@type'] === type);\n }\n\n /**\n * @param credential Message to process.\n * @param fromFeed Key of the feed where this credential is recorded.\n */\n @synchronized\n async process(credential: Credential, { sourceFeed, skipVerification }: ProcessOptions): Promise<boolean> {\n if (credential.id) {\n if (this._processedCredentials.has(credential.id)) {\n return true;\n }\n this._processedCredentials.add(credential.id);\n }\n\n if (!skipVerification) {\n const result = await verifyCredential(credential);\n if (result.kind !== 'pass') {\n log.warn(`Invalid credential: ${result.errors.join(', ')}`);\n return false;\n }\n }\n\n const assertion = getCredentialAssertion(credential);\n switch (assertion['@type']) {\n case 'dxos.halo.credentials.SpaceGenesis': {\n if (this._genesisCredential) {\n log.warn('Space already has a genesis credential.');\n return false;\n }\n if (!credential.issuer.equals(this._spaceKey)) {\n log.warn('Space genesis credential must be issued by space.');\n return false;\n }\n if (!credential.subject.id.equals(this._spaceKey)) {\n log.warn('Space genesis credential must be issued to space.');\n return false;\n }\n this._genesisCredential = credential;\n this._tags = assertion.tags ?? [];\n this._membershipPolicy = assertion.membershipPolicy ?? MembershipPolicy.INVITE;\n break;\n }\n\n case 'dxos.halo.credentials.SpaceMember': {\n if (!assertion.spaceKey.equals(this._spaceKey)) {\n break; // Ignore credentials for other spaces.\n }\n\n if (!this._genesisCredential) {\n log.warn('Space must have a genesis credential before adding members.');\n return false;\n }\n if (!this._canInviteNewMembers(credential.issuer)) {\n log.warn(`Space member is not authorized to invite new members: ${credential.issuer}`);\n return false;\n }\n\n await this._members.process(credential);\n await this._invitations.process(credential);\n break;\n }\n\n case 'dxos.halo.credentials.MemberProfile': {\n if (!this._genesisCredential) {\n log.warn('Space must have a genesis credential before adding members.');\n return false;\n }\n\n await this._members.process(credential);\n break;\n }\n\n case 'dxos.halo.credentials.AdmittedFeed': {\n if (!this._genesisCredential) {\n log.warn('Space must have a genesis credential before admitting feeds.');\n return false;\n }\n\n // We don't do any validation on feed admission since we would perform the same validation on the credentials inside .\n await this._feeds.process(credential, sourceFeed);\n break;\n }\n case 'dxos.halo.invitations.CancelDelegatedInvitation':\n case 'dxos.halo.invitations.DelegateSpaceInvitation': {\n if (!this._canInviteNewMembers(credential.issuer)) {\n log.warn(`Invalid invitation, space member is not authorized to invite new members: ${credential.issuer}`);\n return false;\n }\n await this._invitations.process(credential);\n break;\n }\n }\n\n const newEntry: CredentialEntry = { credential, sourceFeed, revoked: false };\n this._credentials.push(newEntry);\n\n // TODO(dmaretskyi): Invariant on every credential having an id?\n if (credential.id) {\n this._credentialsById.set(credential.id, newEntry);\n }\n\n for (const processor of this._credentialProcessors) {\n if (processor._isReadyForLiveCredentials) {\n await processor._process(credential);\n }\n }\n\n await this.onCredentialProcessed.callIfSet(credential);\n return true;\n }\n\n public getMemberRole(memberKey: PublicKey): SpaceMember.Role {\n return this._members.getRole(memberKey);\n }\n\n public hasMembershipManagementPermission(memberKey: PublicKey): boolean {\n return this._canInviteNewMembers(memberKey);\n }\n\n private _canInviteNewMembers(key: PublicKey): boolean {\n if (this._membershipPolicy === MembershipPolicy.LOCKED) {\n // When locked, only the space key can add the initial owner during genesis.\n // Once a member exists, no new members can be added.\n return key.equals(this._spaceKey) && this._members.members.size === 0;\n }\n return (\n key.equals(this._spaceKey) ||\n this._members.getRole(key) === SpaceMember.Role.ADMIN ||\n this._members.getRole(key) === SpaceMember.Role.OWNER\n );\n }\n}\n\n// TODO(dmaretskyi): Simplify.\nclass CredentialConsumer<T extends CredentialProcessor> {\n private _ctx = new Context();\n\n /**\n * @internal\n * Processor is ready to process live credentials.\n * NOTE: Setting this flag before all existing credentials are processed will cause them to be processed out of order.\n * Set externally.\n */\n _isReadyForLiveCredentials = false;\n\n constructor(\n public readonly processor: T,\n private readonly _onOpen: () => Promise<void>,\n private readonly _onClose: () => Promise<void>,\n ) {}\n\n /**\n * @internal\n */\n async _process(credential: Credential): Promise<void> {\n await runInContextAsync(this._ctx, async () => {\n await this.processor.processCredential(credential);\n });\n }\n\n async open(): Promise<void> {\n if (this._ctx.disposed) {\n throw new Error('CredentialProcessor is disposed');\n }\n\n await this._onOpen();\n }\n\n async close(): Promise<void> {\n await this._ctx.dispose();\n\n await this._onClose();\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { type AdmittedFeed, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { type AsyncCallback, Callback, ComplexMap } from '@dxos/util';\n\nimport { getCredentialAssertion } from '../credentials';\n\nexport interface FeedInfo {\n key: PublicKey;\n /**\n * Parent feed from the feed tree.\n * This is the feed where the AdmittedFeed assertion is written.\n * The genesis feed will have itself as a parent.\n */\n parent: PublicKey;\n credential: Credential;\n assertion: AdmittedFeed;\n}\n\n/**\n * Tracks the feed tree for a space.\n * Provides a list of admitted feeds.\n */\nexport class FeedStateMachine {\n private _feeds = new ComplexMap<PublicKey, FeedInfo>(PublicKey.hash);\n\n readonly onFeedAdmitted = new Callback<AsyncCallback<FeedInfo>>();\n\n constructor(private readonly _spaceKey: PublicKey) {}\n\n get feeds(): ReadonlyMap<PublicKey, FeedInfo> {\n return this._feeds;\n }\n\n /**\n * Processes the AdmittedFeed credential.\n * Assumes the credential is already pre-verified\n * and the issuer has been authorized to issue credentials of this type.\n * @param fromFeed Key of the feed where this credential is recorded.\n */\n async process(credential: Credential, fromFeed: PublicKey): Promise<void> {\n const assertion = getCredentialAssertion(credential);\n invariant(assertion['@type'] === 'dxos.halo.credentials.AdmittedFeed');\n invariant(assertion.spaceKey.equals(this._spaceKey));\n\n const info: FeedInfo = {\n key: credential.subject.id,\n credential,\n assertion,\n parent: fromFeed,\n };\n\n this._feeds.set(credential.subject.id, info);\n await this.onFeedAdmitted.callIfSet(info);\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/keys';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';\nimport { type AsyncCallback, Callback, ComplexMap, ComplexSet } from '@dxos/util';\n\nimport { getCredentialAssertion } from '../credentials';\n\nexport interface DelegateInvitationCredential {\n credentialId: PublicKey;\n invitation: DelegateSpaceInvitation;\n}\n\n/**\n * Tracks the feed tree for a space.\n * Provides a list of admitted feeds.\n */\nexport class InvitationStateMachine {\n private readonly _invitations = new ComplexMap<PublicKey, DelegateSpaceInvitation>(PublicKey.hash);\n private readonly _redeemedInvitationCredentialIds = new ComplexSet(PublicKey.hash);\n private readonly _cancelledInvitationCredentialIds = new ComplexSet(PublicKey.hash);\n\n readonly onDelegatedInvitation = new Callback<AsyncCallback<DelegateInvitationCredential>>();\n readonly onDelegatedInvitationRemoved = new Callback<AsyncCallback<DelegateInvitationCredential>>();\n\n get invitations(): ReadonlyMap<PublicKey, DelegateSpaceInvitation> {\n return this._invitations;\n }\n\n async process(credential: Credential): Promise<void> {\n const credentialId = credential.id;\n if (credentialId == null) {\n return;\n }\n const assertion = getCredentialAssertion(credential);\n switch (assertion['@type']) {\n case 'dxos.halo.invitations.CancelDelegatedInvitation': {\n this._cancelledInvitationCredentialIds.add(assertion.credentialId);\n const existingInvitation = this._invitations.get(assertion.credentialId);\n if (existingInvitation != null) {\n this._invitations.delete(assertion.credentialId);\n await this.onDelegatedInvitationRemoved.callIfSet({\n credentialId: assertion.credentialId,\n invitation: existingInvitation,\n });\n }\n break;\n }\n case 'dxos.halo.invitations.DelegateSpaceInvitation': {\n if (credential.id) {\n const isExpired = assertion.expiresOn && assertion.expiresOn.getTime() < Date.now();\n const wasUsed = this._redeemedInvitationCredentialIds.has(credential.id) && !assertion.multiUse;\n const wasCancelled = this._cancelledInvitationCredentialIds.has(credential.id);\n if (isExpired || wasCancelled || wasUsed) {\n return;\n }\n const invitation: DelegateSpaceInvitation = { ...assertion };\n this._invitations.set(credential.id, invitation);\n await this.onDelegatedInvitation.callIfSet({\n credentialId: credential.id,\n invitation,\n });\n }\n break;\n }\n case 'dxos.halo.credentials.SpaceMember': {\n if (assertion.invitationCredentialId != null) {\n this._redeemedInvitationCredentialIds.add(assertion.invitationCredentialId);\n const existingInvitation = this._invitations.get(assertion.invitationCredentialId);\n if (existingInvitation != null && !existingInvitation.multiUse) {\n this._invitations.delete(assertion.invitationCredentialId);\n await this.onDelegatedInvitationRemoved.callIfSet({\n credentialId: assertion.invitationCredentialId,\n invitation: existingInvitation,\n });\n }\n }\n break;\n }\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Credential, type ProfileDocument, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { ComplexMap } from '@dxos/util';\n\nimport { getCredentialAssertion } from '../credentials';\nimport {\n type ChainVertex,\n CredentialGraph,\n type CredentialGraphStateHandler,\n type PathState,\n type StateScope,\n} from '../graph/credential-graph';\n\nexport interface MemberInfo {\n key: PublicKey;\n role: SpaceMember.Role;\n credential: Credential;\n assertion: SpaceMember;\n profile?: ProfileDocument;\n}\n\n/**\n * Tracks the list of members (with roles) for the space.\n * Provides a list of admitted feeds.\n */\nexport class MemberStateMachine implements CredentialGraphStateHandler<SpaceMember, MemberInfo> {\n private _ownerKey: PublicKey | undefined;\n private _memberProfiles = new ComplexMap<PublicKey, ProfileDocument | undefined>(PublicKey.hash);\n private _hashgraph = new CredentialGraph<SpaceMember, MemberInfo>(this);\n\n readonly onMemberRoleChanged = this._hashgraph.onSubjectStateChanged;\n\n constructor(private readonly _spaceKey: PublicKey) {}\n\n get creator(): MemberInfo | undefined {\n return this._ownerKey && this._hashgraph.getSubjectState(this._ownerKey);\n }\n\n get members(): ReadonlyMap<PublicKey, MemberInfo> {\n return this._hashgraph.getState();\n }\n\n get membershipChainHeads(): PublicKey[] {\n return this._hashgraph.getLeafIds();\n }\n\n getRole(member: PublicKey): SpaceMember.Role {\n return this._getRole(this._hashgraph.getGlobalStateScope(), member);\n }\n\n /**\n * Processes the SpaceMember credential.\n * Assumes the credential is already pre-verified and the issuer has been authorized to issue credentials of this type.\n */\n async process(credential: Credential): Promise<void> {\n const assertion = getCredentialAssertion(credential);\n\n switch (assertion['@type']) {\n case 'dxos.halo.credentials.SpaceMember': {\n invariant(assertion.spaceKey.equals(this._spaceKey));\n if (this._ownerKey == null && credential.issuer === this._spaceKey) {\n this._ownerKey = credential.subject.id;\n }\n if (assertion.profile != null) {\n this._memberProfiles.set(credential.subject.id, assertion.profile);\n }\n await this._hashgraph.addVertex(credential, assertion);\n break;\n }\n case 'dxos.halo.credentials.MemberProfile': {\n const member = this._hashgraph.getSubjectState(credential.subject.id);\n if (member) {\n member.profile = assertion.profile;\n } else {\n log.warn('Member not found', { id: credential.subject.id });\n }\n this._memberProfiles.set(credential.subject.id, assertion.profile);\n break;\n }\n default:\n throw new Error('Invalid assertion type');\n }\n }\n\n public createState(credential: Credential, assertion: SpaceMember): MemberInfo {\n const memberKey = credential.subject.id;\n return {\n key: memberKey,\n role: assertion.role,\n credential,\n assertion,\n profile: this._memberProfiles.get(memberKey),\n };\n }\n\n public isUpdateAllowed(scope: StateScope<SpaceMember>, credential: Credential, assertion: SpaceMember): boolean {\n if (assertion.role === SpaceMember.Role.OWNER) {\n return credential!.issuer.equals(this._spaceKey);\n }\n const issuer = credential.issuer;\n const isChangingOwnRole = issuer.equals(credential.subject.id);\n if (isChangingOwnRole) {\n return false;\n }\n if (issuer.equals(assertion.spaceKey)) {\n return true;\n }\n const issuerRole = this._getRole(scope, issuer);\n return issuerRole === SpaceMember.Role.ADMIN || issuerRole === SpaceMember.Role.OWNER;\n }\n\n public getConflictingPaths(\n paths: PathState<SpaceMember>[],\n update: ChainVertex<SpaceMember>,\n ): PathState<SpaceMember>[] {\n // a member can't be an issuer in a concurrent branch if we decided to remove or revoke admin permissions during merge\n if (update.assertion.role !== SpaceMember.Role.REMOVED && update.assertion.role !== SpaceMember.Role.EDITOR) {\n return [];\n }\n const memberId = update.credential!.subject.id!;\n return paths.filter((p) => p.forkIssuers.has(memberId));\n }\n\n public tryPickWinningUpdate(\n scope1: StateScope<SpaceMember>,\n update1: Credential,\n scope2: StateScope<SpaceMember>,\n update2: Credential,\n ): Credential | null {\n const path1IssuerRole = this._getRole(scope1, update1.issuer);\n const path2IssuerRole = this._getRole(scope2, update2.issuer);\n if ((path2IssuerRole === SpaceMember.Role.OWNER) !== (path1IssuerRole === SpaceMember.Role.OWNER)) {\n log('owner decision used to break the tie');\n return path1IssuerRole === SpaceMember.Role.OWNER ? update1 : update2;\n }\n return null;\n }\n\n public toLogString(assertion: SpaceMember | undefined): string {\n const role = assertion?.role ?? SpaceMember.Role.REMOVED;\n return Object.entries(SpaceMember.Role).find(([_, value]) => value === role)![0];\n }\n\n public hasStateChanged(s1?: MemberInfo, s2?: MemberInfo): boolean {\n return s1?.role !== s2?.role;\n }\n\n private _getRole(scope: StateScope<SpaceMember>, memberId: PublicKey): SpaceMember.Role {\n if (this._ownerKey?.equals(memberId)) {\n return SpaceMember.Role.OWNER;\n }\n const realRole = scope.state.get(memberId)?.assertion?.role ?? SpaceMember.Role.REMOVED;\n if (scope.stateOverrides != null) {\n const override = scope.stateOverrides.get(memberId);\n if (override != null) {\n log('member role overridden in path', () => ({\n headId: scope.head?.id,\n roleOverride: this.toLogString(override.assertion),\n realRole: this.toLogString(scope.state.get(memberId)?.assertion),\n }));\n return override.assertion.role;\n }\n }\n return realRole;\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { type AsyncCallback, Callback, ComplexMap, ComplexSet } from '@dxos/util';\n\nexport class CredentialGraph<A, State> {\n /**\n * Local ids are used during traversals.\n */\n private _vertexIdGenerator = 1;\n /**\n * All credentials without parent references are connected to the root.\n */\n private _root = { id: -1, parents: [], children: [] } as any as ChainVertex<A>;\n /**\n * A credential which is not a parent of any other credential has the sentinel as a child.\n * Sentinel is a virtual merge-point of all credentials.\n */\n private _sentinel = { id: -2, parents: [], children: [] } as any as ChainVertex<A>;\n /**\n * Vertex references are used for fast credential inserts into the graph.\n */\n private _vertexByCredentialId = new ComplexMap<PublicKey, ChainVertex<A>>(PublicKey.hash);\n /**\n * The current state of the graph.\n */\n private _subjectToVertex = new ComplexMap<PublicKey, ChainVertex<A>>(PublicKey.hash);\n private _subjectToState = new ComplexMap<PublicKey, State>(PublicKey.hash);\n\n public onSubjectStateChanged = new Callback<AsyncCallback<State[]>>();\n\n constructor(private readonly _stateHandler: CredentialGraphStateHandler<A, State>) {}\n\n public getSubjectState(subjectId: PublicKey): State | undefined {\n return this._subjectToState.get(subjectId);\n }\n\n public getState(): ReadonlyMap<PublicKey, State> {\n return this._subjectToState;\n }\n\n public getLeafIds(): PublicKey[] {\n return this._sentinel.parents.map((v) => v.credential!.id!);\n }\n\n public getGlobalStateScope(): StateScope<A> {\n return { state: this._subjectToVertex };\n }\n\n public addVertex(credential: Credential, assertion: A): Promise<void> {\n const newVertex: ChainVertex<A> = {\n id: this._vertexIdGenerator++,\n credential,\n assertion,\n parents: [],\n children: [],\n };\n this._vertexByCredentialId.set(credential.id!, newVertex);\n const parentIds = credential.parentCredentialIds ?? [];\n if (parentIds.length === 0) {\n this._root.children.push(newVertex);\n newVertex.parents.push(this._root);\n } else {\n for (const parentId of parentIds) {\n const parentVertex = this._vertexByCredentialId.get(parentId);\n if (parentVertex == null) {\n log.error('credential skipped because of the unknown parent', { credential, parentId });\n continue;\n }\n parentVertex.children.push(newVertex);\n newVertex.parents.push(parentVertex);\n this._removeSentinelConnection(parentVertex);\n }\n }\n newVertex.children.push(this._sentinel);\n this._sentinel.parents.push(newVertex);\n return this._onVertexInserted(newVertex);\n }\n\n private _removeSentinelConnection(vertex: ChainVertex<A>): void {\n const sentinelIdx = vertex.children.indexOf(this._sentinel);\n if (sentinelIdx >= 0) {\n vertex.children.splice(sentinelIdx, 1);\n const vertexInSentinelIdx = this._sentinel.parents.indexOf(vertex);\n invariant(vertexInSentinelIdx >= 0);\n this._sentinel.parents.splice(vertexInSentinelIdx, 1);\n }\n }\n\n private async _onVertexInserted(newVertex: ChainVertex<A>): Promise<void> {\n const { credential, assertion } = newVertex;\n invariant(credential);\n let changedSubjects: State[] = [];\n const isUpdateAppliedOnTopOfThePreviousState = this._sentinel.parents.length === 1;\n if (isUpdateAppliedOnTopOfThePreviousState) {\n const subjectId = credential.subject.id;\n if (this._stateHandler.isUpdateAllowed(this.getGlobalStateScope(), credential, assertion)) {\n const newSubjectState = this._stateHandler.createState(credential, newVertex.assertion);\n const prevSubjectState = this._subjectToState.get(subjectId);\n this._subjectToState.set(subjectId, newSubjectState);\n this._subjectToVertex.set(subjectId, newVertex);\n if (this._stateHandler.hasStateChanged(newSubjectState, prevSubjectState)) {\n changedSubjects.push(newSubjectState);\n }\n }\n } else {\n changedSubjects = this._recomputeState();\n }\n if (changedSubjects.length > 0) {\n await this.onSubjectStateChanged.callIfSet(changedSubjects);\n }\n }\n\n /**\n * DFS the graph from root to sentinel pausing on merge points (nodes with multiple parents).\n * Continue after all paths leading to a merge point converge by merging their states.\n * In case of a concurrent update paths are replayed taking into account the state set\n * by the winning branch.\n */\n private _recomputeState(): State[] {\n // ID of a merge point to the list of paths that reached the point.\n const pendingPaths = new Map<number, PathState<A>[]>();\n const paths: PathState<A>[] = [this._createRootPath()];\n let lastPath: PathState<A> | null = null;\n while (lastPath == null) {\n const path = paths.pop()!;\n log('visit vertex', { id: path.head.id });\n this._updatePathState(path);\n const convergedPaths = this._handleMergePoint(paths, pendingPaths, path);\n if (convergedPaths == null) {\n log('waiting for other paths');\n continue;\n }\n const mergeResult = this._mergePaths(convergedPaths);\n if (mergeResult.type === 'replay_required') {\n this._replayFailedPaths(paths, pendingPaths, mergeResult, convergedPaths);\n continue;\n }\n const merged = mergeResult.path;\n if (merged.head.children.length === 0) {\n lastPath = merged;\n } else if (merged.head.children.length === 1) {\n merged.head = merged.head.children[0];\n paths.push(merged);\n } else {\n this._forkTraversal(paths, merged);\n }\n }\n if (paths.length > 0) {\n log.error('traversal finished while there were active paths', {\n paths: paths.map((p) => ({ path: toChosenPath(p), head: p.head.id })),\n });\n }\n return this._setCurrentState(lastPath);\n }\n\n private _replayFailedPaths(\n paths: PathState<A>[],\n pendingPaths: Map<number, PathState<A>[]>,\n mergeResult: ReplayRequiredMergeResult<A>,\n convergedPaths: PathState<A>[],\n ): void {\n paths.push(\n ...mergeResult.replay.map((path) => {\n const stateOverrides = path.stateOverrides ?? new ComplexMap<PublicKey, ChainVertex<A>>(PublicKey.hash);\n mergeResult.stateOverrides.forEach((value, key) => stateOverrides.set(key, value));\n return { ...mergeResult.from, chosenPath: path.chosenPath, stateOverrides };\n }),\n );\n log('replay paths', () => ({\n count: paths.length,\n paths: paths.map((path) => ({\n from: mergeResult.from.head.id,\n path: toChosenPath(path),\n overrides: path?.stateOverrides?.mapValues((v) => this._stateHandler.toLogString(v.assertion)),\n })),\n }));\n const clearedPending = convergedPaths.filter((l) => !mergeResult.replay.includes(l));\n pendingPaths.set(convergedPaths[0].head.id, clearedPending);\n }\n\n private _handleMergePoint(\n paths: PathState<A>[],\n pendingPaths: Map<number, PathState<A>[]>,\n path: PathState<A>,\n ): PathState<A>[] | null {\n const pendingList = pendingPaths.get(path.head.id) ?? [];\n pendingPaths.set(path.head.id, pendingList);\n pendingList.push(path);\n if (pendingList.length < path.head.parents.length) {\n return null;\n }\n if (path.head.id === this._sentinel.id && paths.length > 0) {\n log('waiting for all the active paths to converge on the sentinel');\n return null;\n }\n pendingPaths.delete(path.head.id);\n return pendingList;\n }\n\n private _updatePathState(path: PathState<A>): void {\n const headCredential = path.head.credential;\n if (headCredential == null) {\n return;\n }\n const updatedSubject = headCredential.subject.id;\n path.credentials.add(headCredential.id!);\n let isUpdateAllowed = this._stateHandler.isUpdateAllowed(path, headCredential, path.head.assertion);\n // Compatibility with old credentials where parent references were not specified.\n if (!isUpdateAllowed && path.head.parents[0]?.id === this._root.id) {\n const globalState = this.getGlobalStateScope();\n isUpdateAllowed = this._stateHandler.isUpdateAllowed(globalState, headCredential, path.head.assertion);\n }\n if (isUpdateAllowed) {\n path.forkChangedSubjects.add(updatedSubject);\n path.forkIssuers.add(headCredential.issuer);\n path.state.set(updatedSubject, path.head);\n log('path state updated', () => ({\n subject: updatedSubject,\n newState: this._stateHandler.toLogString(path.head.assertion),\n }));\n }\n }\n\n private _forkTraversal(paths: PathState<A>[], path: PathState<A>): void {\n const replayChoice = path.chosenPath?.[path.head.id];\n const choices = replayChoice ?? path.head.children;\n for (const choice of choices) {\n log('edge traversal', { from: path.head.id, to: choice.id });\n const fork: PathState<A> = {\n forkPoint: path,\n chosenPath: { ...path.chosenPath, [path.head.id]: [choice] },\n head: choice,\n credentials: new ComplexSet(PublicKey.hash, path.credentials),\n state: new ComplexMap(PublicKey.hash, [...path.state.entries()]),\n forkIssuers: new ComplexSet(PublicKey.hash),\n forkChangedSubjects: new ComplexSet(PublicKey.hash),\n stateOverrides: path.stateOverrides,\n };\n paths.push(fork);\n }\n }\n\n /**\n * Updates the current graph state.\n * @returns changed states.\n */\n private _setCurrentState(path: PathState<A>): State[] {\n const changedSubjects: State[] = [];\n const newStateMap = new ComplexMap<PublicKey, State>(PublicKey.hash);\n const newVertexMap = new ComplexMap<PublicKey, ChainVertex<A>>(PublicKey.hash);\n for (const [subjectKey, subjectVertex] of path.state.entries()) {\n const newState = this._stateHandler.createState(subjectVertex.credential!, subjectVertex.assertion);\n const prevState = this._subjectToState.get(subjectKey);\n newStateMap.set(subjectKey, newState);\n newVertexMap.set(subjectKey, subjectVertex);\n if (this._stateHandler.hasStateChanged(newState, prevState)) {\n changedSubjects.push(newState);\n }\n }\n this._subjectToState = newStateMap;\n this._subjectToVertex = newVertexMap;\n return changedSubjects;\n }\n\n /*\n * Walk up all the fork points and return the first one present in all the paths.\n * We use local id to determine vertex position in the graph, because nodes can't\n * be inserted in the middle (between a parent and a child) and ids are monotonically increasing.\n */\n private _leastCommonAncestor(paths: PathState<A>[]): PathState<A> {\n const uniqueForkPoints = paths.reduce((acc, path) => {\n let it = path.forkPoint;\n while (it) {\n acc.set(it.head.id, it);\n it = it.forkPoint;\n }\n return acc;\n }, new Map<number, PathState<A>>());\n let maxId = this._root.id;\n let maxState: PathState<A> | null = null;\n for (const [id, state] of uniqueForkPoints.entries()) {\n const headCredential = state.head.credential;\n if (headCredential != null) {\n const isPointInEveryPath = paths.every((p) => p.credentials.has(headCredential.id!));\n if (isPointInEveryPath && id > maxId) {\n maxId = id;\n maxState = state;\n }\n }\n }\n return maxState ?? this._createRootPath();\n }\n\n /**\n * We might be merging paths where some of them had fork points after the initial forking.\n * We need all the paths to point to the least common fork point and contain all the changes\n * that happened after it.\n */\n private _moveUpToForkPoint(forkPoint: PathState<A>, path: PathState<A>): PathState<A> {\n const isForkPointInPath = path.chosenPath[forkPoint.head.id] == null || path.forkPoint == null;\n if (isForkPointInPath) {\n return path;\n }\n if (forkPoint.head.id === path.forkPoint?.head.id) {\n return path;\n }\n let it = path.forkPoint!;\n while (it.head.id !== forkPoint.head.id) {\n it.forkIssuers.forEach((iss) => path.forkIssuers.add(iss));\n it.forkChangedSubjects.forEach((m) => path.forkChangedSubjects.add(m));\n it = it!.forkPoint!;\n path.forkPoint = it;\n }\n return path;\n }\n\n private _mergePaths(convergedPaths: PathState<A>[]): PathMergeResult<A> {\n invariant(convergedPaths.length >= 1);\n if (convergedPaths.length === 1) {\n return { type: 'merged', path: convergedPaths[0] };\n }\n const forkPoint = this._leastCommonAncestor(convergedPaths);\n log('merging paths', () => ({\n forkPointId: forkPoint.head.id,\n pathCount: convergedPaths.length,\n forkPoints: convergedPaths.map((fp) => fp.forkPoint?.head.id),\n }));\n const paths = convergedPaths.map((p) => this._moveUpToForkPoint(forkPoint, p));\n invariant(forkPoint);\n const result: PathState<A> = {\n forkPoint: forkPoint.forkPoint,\n chosenPath: { ...forkPoint.chosenPath, [forkPoint.head.id]: [] },\n stateOverrides: forkPoint.stateOverrides,\n credentials: new ComplexSet(PublicKey.hash, forkPoint.credentials),\n forkIssuers: new ComplexSet(PublicKey.hash, forkPoint.forkIssuers),\n forkChangedSubjects: new ComplexSet(PublicKey.hash, forkPoint.forkChangedSubjects),\n state: forkPoint.state.mapValues((v) => v),\n head: paths[0].head,\n };\n const subjectToBranch = new ComplexMap<PublicKey, PathState<A>>(PublicKey.hash);\n for (const path of paths) {\n log('processing a path', () => ({\n choices: toChosenPath(path),\n modified: path.forkChangedSubjects,\n forkIssuers: path.forkIssuers,\n state: path.state.mapValues((v) => this._stateHandler.toLogString(v.assertion)),\n }));\n path.forkIssuers.forEach((iss) => result.forkIssuers.add(iss));\n path.credentials.forEach((cred) => result.credentials.add(cred));\n result.chosenPath![forkPoint.head.id].push(...(path.chosenPath![forkPoint.head.id] ?? []));\n for (const modifiedSubject of path.forkChangedSubjects) {\n const existingBranch = subjectToBranch.get(modifiedSubject);\n if (existingBranch == null || this._shouldOverrideCredential(existingBranch, path, modifiedSubject)) {\n subjectToBranch.set(modifiedSubject, path);\n }\n }\n }\n const replayPaths = new Set<PathState<A>>();\n const addReplayPath = replayPaths.add.bind(replayPaths);\n for (const [subject, branch] of subjectToBranch.entries()) {\n result.forkChangedSubjects.add(subject);\n const vertex = branch.state.get(subject)!;\n result.state.set(subject, vertex);\n log('set subject state', () => ({ subject, state: this._stateHandler.toLogString(vertex.assertion) }));\n const otherPaths = paths.filter((p) => p !== branch);\n this._stateHandler.getConflictingPaths(otherPaths, vertex).forEach(addReplayPath);\n }\n if (replayPaths.size > 0) {\n return {\n type: 'replay_required',\n replay: [...replayPaths.values()],\n from: forkPoint,\n stateOverrides: subjectToBranch.mapValues((v, key) => v.state.get(key)!),\n };\n }\n return { type: 'merged', path: result };\n }\n\n /**\n * A candidate credential is preferred over the existing credential if:\n * 1. It is the merge-point, because it's the last credential that was issued in awareness of all\n * the previously existing ones.\n * 2. A path where candidate was set contains existing credential in it, which means that the candidate\n * was issued after the existing credential by a legitimate issuer.\n * 3. A state-specific logic (_stateHandler) is able to justify using the candidate credential.\n * 4. The path where candidate was set has more issuers than the existing path (longer branch).\n * 5. The issuance time of the candidate is after the issuance time of the existing credential (LWW).\n */\n private _shouldOverrideCredential(\n existing: PathState<A>,\n candidate: PathState<A>,\n modifiedSubject: PublicKey,\n ): boolean {\n const candidateVertex = candidate.state.get(modifiedSubject)!;\n const currentVertex = existing.state.get(modifiedSubject)!;\n if (candidateVertex.id === currentVertex.id) {\n return false;\n }\n // During merge all paths are pointing to the same head, which is the merge point.\n const mergePointId = existing.head.id;\n if (candidateVertex.id === mergePointId || currentVertex.id === mergePointId) {\n log('merge point chosen to break the tie', { mergePointId: existing.head.id });\n return mergePointId === candidateVertex.id;\n }\n const candidateCredential = candidateVertex.credential!;\n const currentCredential = currentVertex.credential!;\n // A credential is contained in a branch where another credential for this subject was issued.\n if (existing.credentials.has(candidateCredential.id!) !== candidate.credentials.has(currentCredential.id!)) {\n log('one of the credentials was overridden in another branch', {\n current: currentVertex.id,\n candidate: candidateVertex.id,\n });\n return candidate.credentials.has(currentCredential.id!);\n }\n // Give a chance to state-specific conflict resolution logic.\n const winningCredential = this._stateHandler.tryPickWinningUpdate(\n existing,\n currentCredential,\n candidate,\n candidateCredential,\n );\n if (winningCredential != null) {\n return winningCredential === candidateCredential;\n }\n if (candidate.forkIssuers.size !== existing.forkIssuers.size) {\n log('longer issuers branch used to break the tie', {\n issuerCount: [existing.forkIssuers.size, candidate.forkIssuers.size],\n });\n return candidate.forkIssuers.size > existing.forkIssuers.size;\n }\n log('issuance date used to break the tie');\n return candidateCredential.issuanceDate.getTime() > currentCredential.issuanceDate.getTime();\n }\n\n private _createRootPath(): PathState<A> {\n return {\n head: this._root,\n chosenPath: {},\n forkIssuers: new ComplexSet(PublicKey.hash),\n forkChangedSubjects: new ComplexSet(PublicKey.hash),\n state: new ComplexMap<PublicKey, ChainVertex<A>>(PublicKey.hash),\n credentials: new ComplexSet(PublicKey.hash),\n };\n }\n}\n\nexport interface StateScope<A> {\n head?: { id: number };\n state: ReadonlyMap<PublicKey, ChainVertex<A>>;\n stateOverrides?: ReadonlyMap<PublicKey, ChainVertex<A>>;\n}\n\nexport interface CredentialGraphStateHandler<Assertion, State> {\n hasStateChanged(s1?: State, s2?: State): boolean;\n\n createState(credential: Credential, assertion: Assertion): State;\n\n isUpdateAllowed: (scope: StateScope<Assertion>, update: Credential, assertion: Assertion) => boolean;\n\n getConflictingPaths(paths: PathState<Assertion>[], update: ChainVertex<Assertion>): PathState<Assertion>[];\n\n tryPickWinningUpdate(\n scope1: StateScope<Assertion>,\n update1: Credential,\n scope2: StateScope<Assertion>,\n update2: Credential,\n ): Credential | null;\n\n toLogString(assertion: Assertion): string;\n}\n\nexport interface PathState<A> {\n /**\n * The current vertex position in path, always advances.\n */\n head: ChainVertex<A>;\n /**\n * Subject info local to the current path.\n */\n state: ComplexMap<PublicKey, ChainVertex<A>>;\n /**\n * Used during path replay to throw away cascading concurrent modifications.\n * Overrides pathState.\n */\n stateOverrides?: ComplexMap<PublicKey, ChainVertex<A>>;\n /**\n * Used to faster search of conflicting branches. Is different from pathState.keys()\n * because pathState is not reset on forks.\n */\n forkChangedSubjects: ComplexSet<PublicKey>;\n /**\n * Used to find winning branches. A branch wins if it had more participants.\n * Ties are broken using credential issuance date.\n */\n forkIssuers: ComplexSet<PublicKey>;\n /**\n * All the credentials processed during this path traversal.\n */\n credentials: ComplexSet<PublicKey>;\n /**\n * PathState where we had multiple children in the current vertex.\n * Will be merged with child branches when they converge.\n */\n forkPoint?: PathState<A>;\n /**\n * Used for a particular path replay with stateOverrides for conflict resolution\n * forkVertexId is mapped to child vertex selection.\n * Contains choices that lead to the current state. Value is an array when\n * some branches converged before converging with the remaining branches.\n */\n chosenPath: { [forkVertexId: number]: ChainVertex<A>[] };\n}\n\nexport interface ChainVertex<Assertion> {\n /**\n * The field is missing on root and sentinel vertices. Assertion is not undefined to avoid\n * always asserting two fields.\n */\n credential?: Credential;\n assertion: Assertion;\n /**\n * Local incrementing counter used to form paths. Is used only for causality resolution.\n */\n id: number;\n /**\n * Parents references are used to handle divergent branch merge-points.\n */\n parents: ChainVertex<Assertion>[];\n /**\n * Child references are traversed when computing the current state.\n */\n children: ChainVertex<Assertion>[];\n}\n\ntype PathMergeResult<A> = SuccessfulMergeResult<A> | ReplayRequiredMergeResult<A>;\n\ninterface SuccessfulMergeResult<A> {\n type: 'merged';\n path: PathState<A>;\n}\n\ninterface ReplayRequiredMergeResult<A> {\n type: 'replay_required';\n from: PathState<A>;\n replay: PathState<A>[];\n stateOverrides: ComplexMap<PublicKey, ChainVertex<A>>;\n}\n\nconst toChosenPath = <A>(path: PathState<A>) => {\n return Object.fromEntries(Object.entries(path.chosenPath!).map(([k, vs]) => [k, vs.map((v) => v.id)]));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Trigger } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Chain, type Credential, type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { ComplexMap } from '@dxos/util';\n\nimport { getCredentialAssertion, isValidAuthorizedDeviceCredential } from '../credentials';\nimport { type CredentialProcessor } from './credential-processor';\n\nexport type DeviceStateMachineProps = {\n identityKey: PublicKey;\n deviceKey: PublicKey;\n onUpdate?: () => void;\n};\n\n/**\n * Processes device invitation credentials.\n */\nexport class DeviceStateMachine implements CredentialProcessor {\n // TODO(burdon): Return values via getter.\n public readonly authorizedDeviceKeys = new ComplexMap<PublicKey, DeviceProfileDocument>(PublicKey.hash);\n\n public readonly deviceChainReady = new Trigger();\n\n public deviceCredentialChain?: Chain;\n\n constructor(private readonly _params: DeviceStateMachineProps) {}\n\n async processCredential(credential: Credential): Promise<void> {\n log('processing credential...', {\n identityKey: this._params.identityKey,\n deviceKey: this._params.deviceKey,\n credential,\n });\n\n // Save device keychain credential when processed by the space state machine.\n if (isValidAuthorizedDeviceCredential(credential, this._params.identityKey, this._params.deviceKey)) {\n this.deviceCredentialChain = { credential };\n this.deviceChainReady.wake();\n }\n\n const assertion = getCredentialAssertion(credential);\n\n switch (assertion['@type']) {\n case 'dxos.halo.credentials.AuthorizedDevice': {\n // We don't need to validate that the device is already added since the credentials are considered idempotent.\n // In the future, when we will have device-specific attributes, we should join them from all concurrent credentials.\n this.authorizedDeviceKeys.set(assertion.deviceKey, this.authorizedDeviceKeys.get(assertion.deviceKey) ?? {});\n\n log('added device', {\n localDeviceKey: this._params.deviceKey,\n deviceKey: assertion.deviceKey,\n size: this.authorizedDeviceKeys.size,\n });\n this._params.onUpdate?.();\n break;\n }\n\n case 'dxos.halo.credentials.DeviceProfile': {\n invariant(this.authorizedDeviceKeys.has(credential.subject.id), 'Device not found.');\n\n if (assertion && credential.subject.id.equals(this._params.deviceKey)) {\n log.trace('dxos.halo.device', {\n deviceKey: credential.subject.id,\n profile: assertion.profile,\n });\n }\n\n this.authorizedDeviceKeys.set(credential.subject.id, assertion.profile);\n this._params.onUpdate?.();\n break;\n }\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { getCredentialAssertion } from '../credentials';\nimport { type CredentialProcessor } from './credential-processor';\n\nexport type ProfileStateMachineProps = {\n identityKey: PublicKey;\n onUpdate?: () => void;\n};\n\n/**\n * Processes device invitation credentials.\n */\nexport class ProfileStateMachine implements CredentialProcessor {\n // TODO(burdon): Return values via getter.\n public profile?: ProfileDocument;\n\n constructor(private readonly _params: ProfileStateMachineProps) {}\n\n async processCredential(credential: Credential): Promise<void> {\n const assertion = getCredentialAssertion(credential);\n switch (assertion['@type']) {\n case 'dxos.halo.credentials.IdentityProfile': {\n if (\n !credential.issuer.equals(this._params.identityKey) ||\n !credential.subject.id.equals(this._params.identityKey)\n ) {\n log.warn('Invalid profile credential', { expectedIdentity: this._params.identityKey, credential });\n return;\n }\n\n // TODO(dmaretskyi): Extra validation for the credential?\n this.profile = assertion.profile;\n log('updated profile', {\n identityKey: this._params.identityKey,\n profile: this.profile,\n });\n this._params.onUpdate?.();\n break;\n }\n }\n }\n}\n"],
5
+ "mappings": ";;;AAIA,SAASA,oBAAoB;AAC7B,SAASC,aAAaC,iBAAiB;AACvC,SAASC,kBAAkB;AAE3B,IAAMC,sBAAsB,IAAIC,WAAmCC,UAAUC,IAAI;AAM1E,IAAMC,2BAA2B,OAAOC,gBAAAA;AAC7C,QAAMC,cAAcN,oBAAoBO,IAAIF,WAAAA;AAC5C,MAAIC,gBAAgBE,QAAW;AAC7B,WAAOF;EACT;AAEA,QAAMG,SAAS,MAAMC,aAAaD,OAAO,WAAWJ,YAAYM,aAAY,CAAA;AAE5E,QAAMC,QAAQ,IAAIC,WAAWJ,MAAAA,EAAQK,MAAM,GAAGC,YAAYC,UAAU;AACpE,QAAMC,cAAcF,YAAYG,OAAON,KAAAA;AACvCZ,sBAAoBmB,IAAId,aAAaY,WAAAA;AACrC,SAAOA;AACT;;;ACHO,IAAMG,wBAAwC,YAAYC,OAAOC,KAAK,MAAA;AAEtE,IAAMC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,GAAA;;;;;;AACA,aAAKb,QAAQc,WAAQ;AACrB;MACF;MAEA,KAAK,uCAAuC;AAC1CC,QAAAA,WAAU,KAAKtB,qBAAqBuB,IAAId,WAAWe,QAAQC,EAAE,GAAG,qBAAA;;;;;;;;;AAEhE,YAAIV,aAAaN,WAAWe,QAAQC,GAAGC,OAAO,KAAKnB,QAAQK,SAAS,GAAG;AACrEF,UAAAA,KAAIiB,MAAM,oBAAoB;YAC5Bf,WAAWH,WAAWe,QAAQC;YAC9BG,SAASb,UAAUa;UACrB,GAAA;;;;;;QACF;AAEA,aAAK5B,qBAAqBiB,IAAIR,WAAWe,QAAQC,IAAIV,UAAUa,OAAO;AACtE,aAAKrB,QAAQc,WAAQ;AACrB;MACF;IACF;EACF;AACF;;;AC1EA,SAASQ,OAAAA,YAAW;;AAcb,IAAMC,sBAAN,MAAMA;;;EAEJC;EAEP,YAA6BC,SAAmC;SAAnCA,UAAAA;EAAoC;EAEjE,MAAMC,kBAAkBC,YAAuC;AAC7D,UAAMC,YAAYC,uBAAuBF,UAAAA;AACzC,YAAQC,UAAU,OAAA,GAAQ;MACxB,KAAK,yCAAyC;AAC5C,YACE,CAACD,WAAWG,OAAOC,OAAO,KAAKN,QAAQO,WAAW,KAClD,CAACL,WAAWM,QAAQC,GAAGH,OAAO,KAAKN,QAAQO,WAAW,GACtD;AACAG,UAAAA,KAAIC,KAAK,8BAA8B;YAAEC,kBAAkB,KAAKZ,QAAQO;YAAaL;UAAW,GAAA;;;;;;AAChG;QACF;AAGA,aAAKH,UAAUI,UAAUJ;AACzBW,QAAAA,KAAI,mBAAmB;UACrBH,aAAa,KAAKP,QAAQO;UAC1BR,SAAS,KAAKA;QAChB,GAAA;;;;;;AACA,aAAKC,QAAQa,WAAQ;AACrB;MACF;IACF;EACF;AACF;",
6
+ "names": ["subtleCrypto", "IdentityDid", "PublicKey", "ComplexMap", "IDENTITY_DIDS_CACHE", "ComplexMap", "PublicKey", "hash", "createDidFromIdentityKey", "identityKey", "cachedValue", "get", "undefined", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "slice", "IdentityDid", "byteLength", "identityDid", "encode", "set", "defaultSecretProvider", "Buffer", "from", "defaultSecretValidator", "invitation", "secret", "generateMnemonic", "mnemonicToSeedSync", "createKeyPair", "invariant", "generateSeedPhrase", "keyPairFromSeedPhrase", "seedPhrase", "seed", "generatePasscode", "length", "passcode", "i", "Math", "floor", "random", "stableStringify", "PublicKey", "Timeframe", "arrayToBuffer", "getCredentialProofPayload", "credential", "copy", "proof", "value", "Uint8Array", "chain", "undefined", "parentCredentialIds", "length", "id", "assertion", "subject", "key", "Object", "keys", "Array", "isArray", "Buffer", "from", "canonicalStringify", "obj", "stableStringify", "replacer", "toString", "startsWith", "original", "PublicKey", "isPublicKey", "toHex", "isBuffer", "arrayToBuffer", "data", "type", "Timeframe", "frames", "reduce", "seq", "truncateKey", "str", "substring", "getPresentationProofPayload", "credentials", "proof", "copy", "map", "credential", "removeEmptyParentCredentialIds", "value", "Uint8Array", "chain", "undefined", "Buffer", "from", "canonicalStringify", "parentCredentialIds", "length", "getCredentialAssertion", "credential", "subject", "assertion", "isValidAuthorizedDeviceCredential", "identityKey", "deviceKey", "id", "equals", "issuer", "checkCredentialType", "type", "credentialTypeFilter", "subtleCrypto", "invariant", "PublicKey", "verifySignature", "SIGNATURE_TYPE_ED25519", "verifyCredential", "credential", "parentCredentialIds", "length", "issuer", "equals", "proof", "signer", "chain", "kind", "errors", "result", "verifyChain", "verifyCredentialSignature", "type", "signData", "getCredentialProofPayload", "verifySignature", "value", "authority", "subject", "isValidAuthorizedDeviceCredential", "createCredential", "signer", "issuer", "subject", "assertion", "signingKey", "chain", "nonce", "parentCredentialIds", "invariant", "result", "verifyChain", "kind", "credential", "issuanceDate", "Date", "id", "proof", "type", "SIGNATURE_TYPE_ED25519", "creationDate", "value", "Uint8Array", "signedPayload", "getCredentialProofPayload", "sign", "PublicKey", "from", "subtleCrypto", "digest", "createCredentialMessage", "createCredentialSignerWithKey", "getIssuer", "createCredentialSignerWithChain", "AdmittedFeed", "MembershipPolicy", "SpaceMember", "Timeframe", "CredentialGenerator", "_signer", "_identityKey", "_deviceKey", "createSpaceGenesis", "spaceKey", "controlKey", "creatorProfile", "membershipPolicy", "MembershipPolicy", "INVITE", "createCredential", "signer", "issuer", "subject", "assertion", "role", "SpaceMember", "Role", "ADMIN", "profile", "genesisFeedKey", "createFeedAdmission", "AdmittedFeed", "Designation", "CONTROL", "createMemberInvitation", "identityKey", "deviceKey", "dataKey", "EDITOR", "DATA", "createDeviceAuthorization", "createDeviceProfile", "feedKey", "designation", "createProfileCredential", "createEpochCredential", "number", "timeframe", "Timeframe", "credentials", "Promise", "all", "map", "credential", "createAdmissionCredentials", "membershipChainHeads", "invitationCredentialId", "tags", "parentCredentialIds", "createDelegatedSpaceInvitationCredential", "invitation", "invitationId", "authMethod", "swarmKey", "guestKey", "expiresOn", "multiUse", "createCancelDelegatedSpaceInvitationCredential", "credentialId", "signPresentation", "presentation", "signer", "signerKey", "chain", "nonce", "proof", "type", "SIGNATURE_TYPE_ED25519", "value", "Uint8Array", "creationDate", "Date", "signedPayload", "getPresentationProofPayload", "credentials", "sign", "proofs", "verifySignature", "verifyPresentation", "presentation", "errors", "credentialsVerifications", "Promise", "all", "credentials", "map", "credential", "verifyCredential", "verification", "kind", "push", "proofVerification", "proofs", "proof", "chainVerification", "verifyPresentationChain", "signatureVerification", "verifyPresentationSignature", "length", "issuer", "equals", "signer", "chain", "verifyChain", "subject", "id", "type", "SIGNATURE_TYPE_ED25519", "signData", "getPresentationProofPayload", "verifySignature", "value", "runInContextAsync", "synchronized", "Context", "PublicKey", "log", "MembershipPolicy", "SpaceMember", "Callback", "ComplexMap", "ComplexSet", "invariant", "PublicKey", "Callback", "ComplexMap", "FeedStateMachine", "_feeds", "ComplexMap", "PublicKey", "hash", "onFeedAdmitted", "Callback", "_spaceKey", "feeds", "process", "credential", "fromFeed", "assertion", "getCredentialAssertion", "invariant", "spaceKey", "equals", "info", "key", "subject", "id", "parent", "set", "callIfSet", "PublicKey", "Callback", "ComplexMap", "ComplexSet", "InvitationStateMachine", "_invitations", "ComplexMap", "PublicKey", "hash", "_redeemedInvitationCredentialIds", "ComplexSet", "_cancelledInvitationCredentialIds", "onDelegatedInvitation", "Callback", "onDelegatedInvitationRemoved", "invitations", "process", "credential", "credentialId", "id", "assertion", "getCredentialAssertion", "add", "existingInvitation", "get", "delete", "callIfSet", "invitation", "isExpired", "expiresOn", "getTime", "Date", "now", "wasUsed", "has", "multiUse", "wasCancelled", "set", "invitationCredentialId", "invariant", "PublicKey", "log", "SpaceMember", "ComplexMap", "invariant", "PublicKey", "log", "Callback", "ComplexMap", "ComplexSet", "CredentialGraph", "_vertexIdGenerator", "_root", "id", "parents", "children", "_sentinel", "_vertexByCredentialId", "hash", "_subjectToVertex", "_subjectToState", "onSubjectStateChanged", "_stateHandler", "getSubjectState", "subjectId", "get", "getState", "getLeafIds", "map", "v", "credential", "getGlobalStateScope", "state", "addVertex", "assertion", "newVertex", "set", "parentIds", "parentCredentialIds", "length", "push", "parentId", "parentVertex", "error", "_removeSentinelConnection", "_onVertexInserted", "vertex", "sentinelIdx", "indexOf", "splice", "vertexInSentinelIdx", "changedSubjects", "isUpdateAppliedOnTopOfThePreviousState", "subject", "isUpdateAllowed", "newSubjectState", "createState", "prevSubjectState", "hasStateChanged", "_recomputeState", "callIfSet", "pendingPaths", "Map", "paths", "_createRootPath", "lastPath", "path", "pop", "head", "_updatePathState", "convergedPaths", "_handleMergePoint", "mergeResult", "_mergePaths", "type", "_replayFailedPaths", "merged", "_forkTraversal", "p", "toChosenPath", "_setCurrentState", "replay", "stateOverrides", "forEach", "value", "key", "from", "chosenPath", "count", "overrides", "mapValues", "toLogString", "clearedPending", "filter", "l", "includes", "pendingList", "delete", "headCredential", "updatedSubject", "credentials", "add", "globalState", "forkChangedSubjects", "forkIssuers", "issuer", "newState", "replayChoice", "choices", "choice", "to", "fork", "forkPoint", "entries", "newStateMap", "newVertexMap", "subjectKey", "subjectVertex", "prevState", "_leastCommonAncestor", "uniqueForkPoints", "reduce", "acc", "it", "maxId", "maxState", "isPointInEveryPath", "every", "has", "_moveUpToForkPoint", "isForkPointInPath", "iss", "m", "forkPointId", "pathCount", "forkPoints", "fp", "result", "subjectToBranch", "modified", "cred", "modifiedSubject", "existingBranch", "_shouldOverrideCredential", "replayPaths", "Set", "addReplayPath", "bind", "branch", "otherPaths", "getConflictingPaths", "size", "values", "existing", "candidate", "candidateVertex", "currentVertex", "mergePointId", "candidateCredential", "currentCredential", "current", "winningCredential", "tryPickWinningUpdate", "issuerCount", "issuanceDate", "getTime", "Object", "fromEntries", "k", "vs", "MemberStateMachine", "_ownerKey", "_memberProfiles", "ComplexMap", "PublicKey", "hash", "_hashgraph", "CredentialGraph", "onMemberRoleChanged", "onSubjectStateChanged", "_spaceKey", "creator", "getSubjectState", "members", "getState", "membershipChainHeads", "getLeafIds", "getRole", "member", "_getRole", "getGlobalStateScope", "process", "credential", "assertion", "getCredentialAssertion", "invariant", "spaceKey", "equals", "issuer", "subject", "id", "profile", "set", "addVertex", "log", "warn", "Error", "createState", "memberKey", "key", "role", "get", "isUpdateAllowed", "scope", "SpaceMember", "Role", "OWNER", "isChangingOwnRole", "issuerRole", "ADMIN", "getConflictingPaths", "paths", "update", "REMOVED", "EDITOR", "memberId", "filter", "p", "forkIssuers", "has", "tryPickWinningUpdate", "scope1", "update1", "scope2", "update2", "path1IssuerRole", "path2IssuerRole", "toLogString", "Object", "entries", "find", "_", "value", "hasStateChanged", "s1", "s2", "realRole", "state", "stateOverrides", "override", "headId", "head", "roleOverride", "SpaceStateMachine", "_members", "_feeds", "_invitations", "InvitationStateMachine", "_credentials", "_credentialsById", "ComplexMap", "PublicKey", "hash", "_processedCredentials", "ComplexSet", "_genesisCredential", "_tags", "_membershipPolicy", "MembershipPolicy", "INVITE", "_credentialProcessors", "onCredentialProcessed", "Callback", "onMemberRoleChanged", "onFeedAdmitted", "onDelegatedInvitation", "onDelegatedInvitationRemoved", "_spaceKey", "MemberStateMachine", "FeedStateMachine", "creator", "members", "membershipChainHeads", "feeds", "credentials", "map", "entry", "credential", "credentialEntries", "genesisCredential", "tags", "membershipPolicy", "invitations", "addCredentialProcessor", "processor", "find", "p", "Error", "consumer", "CredentialConsumer", "_process", "_isReadyForLiveCredentials", "filter", "push", "open", "removeCredentialProcessor", "close", "getCredentialsOfType", "type", "getCredentialAssertion", "process", "sourceFeed", "skipVerification", "id", "has", "add", "result", "verifyCredential", "kind", "log", "warn", "errors", "join", "assertion", "issuer", "equals", "subject", "spaceKey", "_canInviteNewMembers", "newEntry", "revoked", "set", "callIfSet", "getMemberRole", "memberKey", "getRole", "hasMembershipManagementPermission", "key", "LOCKED", "size", "SpaceMember", "Role", "ADMIN", "OWNER", "_ctx", "Context", "_onOpen", "_onClose", "runInContextAsync", "processCredential", "disposed", "dispose", "Trigger", "invariant", "PublicKey", "log", "ComplexMap", "DeviceStateMachine", "authorizedDeviceKeys", "ComplexMap", "PublicKey", "hash", "deviceChainReady", "Trigger", "deviceCredentialChain", "_params", "processCredential", "credential", "log", "identityKey", "deviceKey", "isValidAuthorizedDeviceCredential", "wake", "assertion", "getCredentialAssertion", "set", "get", "localDeviceKey", "size", "onUpdate", "invariant", "has", "subject", "id", "equals", "trace", "profile", "log", "ProfileStateMachine", "profile", "_params", "processCredential", "credential", "assertion", "getCredentialAssertion", "issuer", "equals", "identityKey", "subject", "id", "log", "warn", "expectedIdentity", "onUpdate"]
7
+ }