@dxos/credentials 0.8.3 → 0.8.4-main.1068cf700f

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 (53) hide show
  1. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  2. package/dist/lib/{browser → neutral}/index.mjs +130 -88
  3. package/dist/lib/neutral/index.mjs.map +7 -0
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/types/src/credentials/assertions.d.ts +1 -1
  6. package/dist/types/src/credentials/assertions.d.ts.map +1 -1
  7. package/dist/types/src/credentials/credential-factory.d.ts +4 -4
  8. package/dist/types/src/credentials/credential-factory.d.ts.map +1 -1
  9. package/dist/types/src/credentials/credential-generator.d.ts.map +1 -1
  10. package/dist/types/src/did.d.ts +1 -1
  11. package/dist/types/src/did.d.ts.map +1 -1
  12. package/dist/types/src/presentations/presentation.d.ts.map +1 -1
  13. package/dist/types/src/presentations/verifier.d.ts.map +1 -1
  14. package/dist/types/src/processor/device-state-machine.d.ts +2 -2
  15. package/dist/types/src/processor/device-state-machine.d.ts.map +1 -1
  16. package/dist/types/src/processor/index.d.ts +1 -1
  17. package/dist/types/src/processor/index.d.ts.map +1 -1
  18. package/dist/types/src/processor/profile-state-machine.d.ts +2 -2
  19. package/dist/types/src/processor/profile-state-machine.d.ts.map +1 -1
  20. package/dist/types/src/state-machine/member-state-machine.d.ts +1 -1
  21. package/dist/types/src/state-machine/member-state-machine.d.ts.map +1 -1
  22. package/dist/types/src/state-machine/space-state-machine.d.ts +1 -1
  23. package/dist/types/src/state-machine/space-state-machine.d.ts.map +1 -1
  24. package/dist/types/tsconfig.tsbuildinfo +1 -1
  25. package/moon.yml +12 -0
  26. package/package.json +20 -20
  27. package/src/credentials/assertions.ts +1 -1
  28. package/src/credentials/credential-factory.ts +5 -5
  29. package/src/credentials/credential-generator.ts +1 -1
  30. package/src/did.ts +2 -2
  31. package/src/presentations/json-encoding.test.ts +3 -1
  32. package/src/presentations/presentation.ts +2 -1
  33. package/src/presentations/verifier.test.ts +2 -1
  34. package/src/presentations/verifier.ts +2 -1
  35. package/src/processor/device-state-machine.ts +4 -3
  36. package/src/processor/index.ts +1 -1
  37. package/src/processor/profile-state-machine.ts +4 -3
  38. package/src/state-machine/invitation-state-machine.test.ts +3 -2
  39. package/src/state-machine/member-state-machine.test.ts +2 -1
  40. package/src/state-machine/member-state-machine.ts +1 -1
  41. package/src/state-machine/space-state-machine.test.ts +2 -1
  42. package/src/state-machine/space-state-machine.ts +14 -8
  43. package/vitest.config.ts +7 -3
  44. package/.eslintrc.cjs +0 -7
  45. package/dist/lib/browser/index.mjs.map +0 -7
  46. package/dist/lib/browser/meta.json +0 -1
  47. package/dist/lib/node/index.cjs +0 -1894
  48. package/dist/lib/node/index.cjs.map +0 -7
  49. package/dist/lib/node/meta.json +0 -1
  50. package/dist/lib/node-esm/index.mjs +0 -1870
  51. package/dist/lib/node-esm/index.mjs.map +0 -7
  52. package/dist/lib/node-esm/meta.json +0 -1
  53. package/project.json +0 -27
package/moon.yml ADDED
@@ -0,0 +1,12 @@
1
+ layer: library
2
+ language: typescript
3
+ tags:
4
+ - ts-build
5
+ - ts-test
6
+ - pack
7
+ tasks:
8
+ compile:
9
+ args:
10
+ - '--entryPoint=src/index.ts'
11
+ - '--injectGlobals'
12
+ - '--platform=neutral'
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "@dxos/credentials",
3
- "version": "0.8.3",
3
+ "version": "0.8.4-main.1068cf700f",
4
4
  "description": "DXOS Credentials",
5
5
  "homepage": "https://github.com/dxos/dxos/tree/main/packages/core/halo/credentials#readme",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
- "repository": "github:dxos/dxos",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
8
11
  "license": "MIT",
9
12
  "author": "info@dxos.org",
10
- "sideEffects": true,
13
+ "sideEffects": false,
11
14
  "type": "module",
12
15
  "exports": {
13
16
  ".": {
17
+ "source": "./src/index.ts",
14
18
  "types": "./dist/types/src/index.d.ts",
15
- "browser": "./dist/lib/browser/index.mjs",
16
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
17
20
  }
18
21
  },
19
22
  "types": "dist/types/src/index.d.ts",
@@ -22,21 +25,18 @@
22
25
  },
23
26
  "dependencies": {
24
27
  "bip39": "^3.1.0",
25
- "json-stable-stringify": "^1.0.1",
26
- "@dxos/async": "0.8.3",
27
- "@dxos/context": "0.8.3",
28
- "@dxos/invariant": "0.8.3",
29
- "@dxos/crypto": "0.8.3",
30
- "@dxos/keys": "0.8.3",
31
- "@dxos/keyring": "0.8.3",
32
- "@dxos/log": "0.8.3",
33
- "@dxos/node-std": "0.8.3",
34
- "@dxos/protocols": "0.8.3",
35
- "@dxos/timeframe": "0.8.3",
36
- "@dxos/util": "0.8.3"
37
- },
38
- "devDependencies": {
39
- "@types/json-stable-stringify": "^1.0.32"
28
+ "json-stable-stringify": "^1.3.0",
29
+ "@dxos/async": "0.8.4-main.1068cf700f",
30
+ "@dxos/context": "0.8.4-main.1068cf700f",
31
+ "@dxos/crypto": "0.8.4-main.1068cf700f",
32
+ "@dxos/invariant": "0.8.4-main.1068cf700f",
33
+ "@dxos/keyring": "0.8.4-main.1068cf700f",
34
+ "@dxos/keys": "0.8.4-main.1068cf700f",
35
+ "@dxos/node-std": "0.8.4-main.1068cf700f",
36
+ "@dxos/protocols": "0.8.4-main.1068cf700f",
37
+ "@dxos/timeframe": "0.8.4-main.1068cf700f",
38
+ "@dxos/log": "0.8.4-main.1068cf700f",
39
+ "@dxos/util": "0.8.4-main.1068cf700f"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type PublicKey } from '@dxos/keys';
6
- import { type TypedMessage, type TYPES } from '@dxos/protocols/proto';
6
+ import { type TYPES, type TypedMessage } from '@dxos/protocols/proto';
7
7
  import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
8
8
 
9
9
  export const getCredentialAssertion = (credential: Credential): TypedMessage => credential.subject.assertion;
@@ -11,14 +11,14 @@ import { type Chain, type Credential } from '@dxos/protocols/proto/dxos/halo/cre
11
11
  import { getCredentialProofPayload } from './signing';
12
12
  import { SIGNATURE_TYPE_ED25519, verifyChain } from './verifier';
13
13
 
14
- export type CreateCredentialSignerParams = {
14
+ export type CreateCredentialSignerProps = {
15
15
  subject: PublicKey;
16
16
  assertion: TypedMessage;
17
17
  nonce?: Uint8Array;
18
18
  parentCredentialIds?: PublicKey[];
19
19
  };
20
20
 
21
- export type CreateCredentialParams = {
21
+ export type CreateCredentialProps = {
22
22
  signer: Signer;
23
23
  issuer: PublicKey;
24
24
  signingKey?: PublicKey;
@@ -44,7 +44,7 @@ export const createCredential = async ({
44
44
  chain,
45
45
  nonce,
46
46
  parentCredentialIds,
47
- }: CreateCredentialParams): Promise<Credential> => {
47
+ }: CreateCredentialProps): Promise<Credential> => {
48
48
  invariant(assertion['@type'], 'Invalid assertion.');
49
49
  invariant(!!signingKey === !!chain, 'Chain must be provided if and only if the signing key differs from the issuer.');
50
50
  if (chain) {
@@ -77,7 +77,7 @@ export const createCredential = async ({
77
77
  credential.proof!.chain = chain;
78
78
  }
79
79
 
80
- credential.id = PublicKey.from(await subtleCrypto.digest('SHA-256', signedPayload));
80
+ credential.id = PublicKey.from(await subtleCrypto.digest('SHA-256', signedPayload as Uint8Array<ArrayBuffer>));
81
81
 
82
82
  return credential;
83
83
  };
@@ -93,7 +93,7 @@ export const createCredentialMessage = (credential: Credential) => {
93
93
  // TODO(burdon): Vs. Signer.
94
94
  export interface CredentialSigner {
95
95
  getIssuer(): PublicKey;
96
- createCredential: (params: CreateCredentialSignerParams) => Promise<Credential>;
96
+ createCredential: (params: CreateCredentialSignerProps) => Promise<Credential>;
97
97
  }
98
98
 
99
99
  /**
@@ -16,7 +16,7 @@ import {
16
16
  import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
17
17
  import { Timeframe } from '@dxos/timeframe';
18
18
 
19
- import { createCredential, type CredentialSigner } from './credential-factory';
19
+ import { type CredentialSigner, createCredential } from './credential-factory';
20
20
 
21
21
  // TODO(burdon): Normalize generate and functions below.
22
22
  // Use throughout stack and in tests.
package/src/did.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { subtleCrypto } from '@dxos/crypto';
6
- import { PublicKey, IdentityDid } from '@dxos/keys';
6
+ import { IdentityDid, PublicKey } from '@dxos/keys';
7
7
  import { ComplexMap } from '@dxos/util';
8
8
 
9
9
  const IDENTITY_DIDS_CACHE = new ComplexMap<PublicKey, IdentityDid>(PublicKey.hash);
@@ -18,7 +18,7 @@ export const createDidFromIdentityKey = async (identityKey: PublicKey): Promise<
18
18
  return cachedValue;
19
19
  }
20
20
 
21
- const digest = await subtleCrypto.digest('SHA-256', identityKey.asUint8Array());
21
+ const digest = await subtleCrypto.digest('SHA-256', identityKey.asUint8Array() as Uint8Array<ArrayBuffer>);
22
22
 
23
23
  const bytes = new Uint8Array(digest).slice(0, IdentityDid.byteLength);
24
24
  const identityDid = IdentityDid.encode(bytes);
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { inspect } from 'util';
6
+
6
7
  import { describe, test } from 'vitest';
7
8
 
8
9
  import { randomBytes } from '@dxos/crypto';
@@ -11,9 +12,10 @@ import { buf } from '@dxos/protocols/buf';
11
12
  import { PresentationSchema } from '@dxos/protocols/buf/dxos/halo/credentials_pb';
12
13
  import { schema } from '@dxos/protocols/proto';
13
14
 
14
- import { signPresentation } from './presentation';
15
15
  import { createCredential } from '../credentials';
16
16
 
17
+ import { signPresentation } from './presentation';
18
+
17
19
  describe('json encoding', () => {
18
20
  test.skip('service access exercise by a device', async () => {
19
21
  const keyring = new Keyring();
@@ -6,9 +6,10 @@ import { type Signer } from '@dxos/crypto';
6
6
  import { type PublicKey } from '@dxos/keys';
7
7
  import { type Chain, type Presentation, type Proof } from '@dxos/protocols/proto/dxos/halo/credentials';
8
8
 
9
- import { getPresentationProofPayload } from './signing';
10
9
  import { SIGNATURE_TYPE_ED25519 } from '../credentials';
11
10
 
11
+ import { getPresentationProofPayload } from './signing';
12
+
12
13
  // TODO(burdon): Rename createPresentation?
13
14
  export const signPresentation = async ({
14
15
  presentation,
@@ -9,9 +9,10 @@ import { Keyring } from '@dxos/keyring';
9
9
  import { PublicKey } from '@dxos/keys';
10
10
  import { type Chain, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
11
11
 
12
+ import { createCredential } from '../credentials';
13
+
12
14
  import { signPresentation } from './presentation';
13
15
  import { verifyPresentation, verifyPresentationSignature } from './verifier';
14
- import { createCredential } from '../credentials';
15
16
 
16
17
  describe('presentation verifier', () => {
17
18
  describe('chain', () => {
@@ -5,9 +5,10 @@
5
5
  import { verifySignature } from '@dxos/crypto';
6
6
  import { type Presentation, type Proof } from '@dxos/protocols/proto/dxos/halo/credentials';
7
7
 
8
- import { getPresentationProofPayload } from './signing';
9
8
  import { SIGNATURE_TYPE_ED25519, type VerificationResult, verifyChain, verifyCredential } from '../credentials';
10
9
 
10
+ import { getPresentationProofPayload } from './signing';
11
+
11
12
  export const verifyPresentation = async (presentation: Presentation): Promise<VerificationResult> => {
12
13
  const errors: string[] = [];
13
14
 
@@ -9,10 +9,11 @@ import { log } from '@dxos/log';
9
9
  import { type Chain, type Credential, type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
10
10
  import { ComplexMap } from '@dxos/util';
11
11
 
12
- import { type CredentialProcessor } from './credential-processor';
13
12
  import { getCredentialAssertion, isValidAuthorizedDeviceCredential } from '../credentials';
14
13
 
15
- export type DeviceStateMachineParams = {
14
+ import { type CredentialProcessor } from './credential-processor';
15
+
16
+ export type DeviceStateMachineProps = {
16
17
  identityKey: PublicKey;
17
18
  deviceKey: PublicKey;
18
19
  onUpdate?: () => void;
@@ -29,7 +30,7 @@ export class DeviceStateMachine implements CredentialProcessor {
29
30
 
30
31
  public deviceCredentialChain?: Chain;
31
32
 
32
- constructor(private readonly _params: DeviceStateMachineParams) {}
33
+ constructor(private readonly _params: DeviceStateMachineProps) {}
33
34
 
34
35
  async processCredential(credential: Credential): Promise<void> {
35
36
  log('processing credential...', {
@@ -2,6 +2,6 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './credential-processor';
5
+ export type * from './credential-processor';
6
6
  export * from './device-state-machine';
7
7
  export * from './profile-state-machine';
@@ -6,10 +6,11 @@ import { type PublicKey } from '@dxos/keys';
6
6
  import { log } from '@dxos/log';
7
7
  import { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
8
8
 
9
- import { type CredentialProcessor } from './credential-processor';
10
9
  import { getCredentialAssertion } from '../credentials';
11
10
 
12
- export type ProfileStateMachineParams = {
11
+ import { type CredentialProcessor } from './credential-processor';
12
+
13
+ export type ProfileStateMachineProps = {
13
14
  identityKey: PublicKey;
14
15
  onUpdate?: () => void;
15
16
  };
@@ -21,7 +22,7 @@ export class ProfileStateMachine implements CredentialProcessor {
21
22
  // TODO(burdon): Return values via getter.
22
23
  public profile?: ProfileDocument;
23
24
 
24
- constructor(private readonly _params: ProfileStateMachineParams) {}
25
+ constructor(private readonly _params: ProfileStateMachineProps) {}
25
26
 
26
27
  async processCredential(credential: Credential): Promise<void> {
27
28
  const assertion = getCredentialAssertion(credential);
@@ -7,17 +7,18 @@ import { beforeEach, describe, expect, test } from 'vitest';
7
7
  import { Keyring } from '@dxos/keyring';
8
8
  import { PublicKey } from '@dxos/keys';
9
9
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
10
- import { SpaceMember, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
10
+ import { type Credential, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
11
11
  import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
12
12
  import { range } from '@dxos/util';
13
13
 
14
- import { InvitationStateMachine } from './invitation-state-machine';
15
14
  import {
16
15
  createCredential,
17
16
  createCredentialSignerWithKey,
18
17
  createDelegatedSpaceInvitationCredential,
19
18
  } from '../credentials';
20
19
 
20
+ import { InvitationStateMachine } from './invitation-state-machine';
21
+
21
22
  describe('InvitationStateMachine', () => {
22
23
  const keyring = new Keyring();
23
24
  let space: PublicKey;
@@ -9,9 +9,10 @@ import { PublicKey } from '@dxos/keys';
9
9
  import { SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
10
10
  import { range } from '@dxos/util';
11
11
 
12
- import { MemberStateMachine } from './member-state-machine';
13
12
  import { createAdmissionCredentials, createCredentialSignerWithKey } from '../credentials';
14
13
 
14
+ import { MemberStateMachine } from './member-state-machine';
15
+
15
16
  const keyring = new Keyring();
16
17
 
17
18
  describe('MemberStateMachine', () => {
@@ -5,7 +5,7 @@
5
5
  import { invariant } from '@dxos/invariant';
6
6
  import { PublicKey } from '@dxos/keys';
7
7
  import { log } from '@dxos/log';
8
- import { type Credential, SpaceMember, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
8
+ import { type Credential, type ProfileDocument, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
9
9
  import { ComplexMap } from '@dxos/util';
10
10
 
11
11
  import { getCredentialAssertion } from '../credentials';
@@ -8,9 +8,10 @@ import { Keyring } from '@dxos/keyring';
8
8
  import { type PublicKey } from '@dxos/keys';
9
9
  import { AdmittedFeed, type Chain, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
10
10
 
11
- import { SpaceStateMachine } from './space-state-machine';
12
11
  import { createCredential, verifyCredential } from '../credentials';
13
12
 
13
+ import { SpaceStateMachine } from './space-state-machine';
14
+
14
15
  describe('SpaceStateMachine', () => {
15
16
  test('basic space creation', async () => {
16
17
  const keyring = new Keyring();
@@ -11,12 +11,13 @@ import { type Credential, SpaceMember } from '@dxos/protocols/proto/dxos/halo/cr
11
11
  import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
12
12
  import { type AsyncCallback, Callback, ComplexMap, ComplexSet } from '@dxos/util';
13
13
 
14
- import { type FeedInfo, FeedStateMachine } from './feed-state-machine';
15
- import { InvitationStateMachine } from './invitation-state-machine';
16
- import { MemberStateMachine, type MemberInfo } from './member-state-machine';
17
14
  import { getCredentialAssertion, verifyCredential } from '../credentials';
18
15
  import { type CredentialProcessor } from '../processor/credential-processor';
19
16
 
17
+ import { type FeedInfo, FeedStateMachine } from './feed-state-machine';
18
+ import { InvitationStateMachine } from './invitation-state-machine';
19
+ import { type MemberInfo, MemberStateMachine } from './member-state-machine';
20
+
20
21
  export interface SpaceState {
21
22
  readonly members: ReadonlyMap<PublicKey, MemberInfo>;
22
23
  readonly membershipChainHeads: PublicKey[];
@@ -52,8 +53,8 @@ export type CredentialEntry = {
52
53
  * Keeps and in-memory index of credentials and allows to query them.
53
54
  */
54
55
  export class SpaceStateMachine implements SpaceState {
55
- private readonly _members = new MemberStateMachine(this._spaceKey);
56
- private readonly _feeds = new FeedStateMachine(this._spaceKey);
56
+ private readonly _members: MemberStateMachine;
57
+ private readonly _feeds: FeedStateMachine;
57
58
  private readonly _invitations = new InvitationStateMachine();
58
59
  private readonly _credentials: CredentialEntry[] = [];
59
60
  private readonly _credentialsById = new ComplexMap<PublicKey, CredentialEntry>(PublicKey.hash);
@@ -63,12 +64,17 @@ export class SpaceStateMachine implements SpaceState {
63
64
  private _credentialProcessors: CredentialConsumer<any>[] = [];
64
65
 
65
66
  readonly onCredentialProcessed = new Callback<AsyncCallback<Credential>>();
66
- readonly onMemberRoleChanged = this._members.onMemberRoleChanged;
67
- readonly onFeedAdmitted = this._feeds.onFeedAdmitted;
67
+ readonly onMemberRoleChanged: Callback<AsyncCallback<MemberInfo[]>>;
68
+ readonly onFeedAdmitted: Callback<AsyncCallback<FeedInfo>>;
68
69
  readonly onDelegatedInvitation = this._invitations.onDelegatedInvitation;
69
70
  readonly onDelegatedInvitationRemoved = this._invitations.onDelegatedInvitationRemoved;
70
71
 
71
- constructor(private readonly _spaceKey: PublicKey) {}
72
+ constructor(private readonly _spaceKey: PublicKey) {
73
+ this._members = new MemberStateMachine(this._spaceKey);
74
+ this._feeds = new FeedStateMachine(this._spaceKey);
75
+ this.onMemberRoleChanged = this._members.onMemberRoleChanged;
76
+ this.onFeedAdmitted = this._feeds.onFeedAdmitted;
77
+ }
72
78
 
73
79
  get creator(): MemberInfo | undefined {
74
80
  return this._members.creator;
package/vitest.config.ts CHANGED
@@ -2,8 +2,12 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { defineConfig, mergeConfig } from 'vitest/config';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
6
7
 
7
- import { baseConfig } from '../../../../vitest.shared';
8
+ import { createConfig } from '../../../../vitest.base.config';
8
9
 
9
- export default mergeConfig(baseConfig({ cwd: __dirname }), defineConfig({}));
10
+ export default createConfig({
11
+ dirname: typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url)),
12
+ node: true,
13
+ });
package/.eslintrc.cjs DELETED
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- "extends": ["../../../../.eslintrc.js"],
3
- "parserOptions": {
4
- "project": "tsconfig.json",
5
- "tsconfigRootDir": __dirname,
6
- }
7
- }