@dxos/credentials 0.8.3 → 0.8.4-main.28f8d3d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.swc/plugins/v7_linux_x86_64_13.0.0/c614d7475354583212fbd7669acbae95b9832c305bf51bdaabe2e6de05abb6bf +0 -0
- package/dist/lib/browser/index.mjs +124 -58
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +124 -58
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/credentials/assertions.d.ts +1 -1
- package/dist/types/src/credentials/assertions.d.ts.map +1 -1
- package/dist/types/src/credentials/credential-generator.d.ts.map +1 -1
- package/dist/types/src/did.d.ts +1 -1
- package/dist/types/src/did.d.ts.map +1 -1
- package/dist/types/src/presentations/presentation.d.ts.map +1 -1
- package/dist/types/src/presentations/verifier.d.ts.map +1 -1
- package/dist/types/src/processor/device-state-machine.d.ts.map +1 -1
- package/dist/types/src/processor/index.d.ts +1 -1
- package/dist/types/src/processor/index.d.ts.map +1 -1
- package/dist/types/src/processor/profile-state-machine.d.ts.map +1 -1
- package/dist/types/src/state-machine/member-state-machine.d.ts +1 -1
- package/dist/types/src/state-machine/member-state-machine.d.ts.map +1 -1
- package/dist/types/src/state-machine/space-state-machine.d.ts +1 -1
- package/dist/types/src/state-machine/space-state-machine.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/moon.yml +11 -0
- package/package.json +13 -12
- package/src/credentials/assertions.ts +1 -1
- package/src/credentials/credential-factory.ts +1 -1
- package/src/credentials/credential-generator.ts +1 -1
- package/src/did.ts +2 -2
- package/src/presentations/json-encoding.test.ts +3 -1
- package/src/presentations/presentation.ts +2 -1
- package/src/presentations/verifier.test.ts +2 -1
- package/src/presentations/verifier.ts +2 -1
- package/src/processor/device-state-machine.ts +2 -1
- package/src/processor/index.ts +1 -1
- package/src/processor/profile-state-machine.ts +2 -1
- package/src/state-machine/invitation-state-machine.test.ts +3 -2
- package/src/state-machine/member-state-machine.test.ts +2 -1
- package/src/state-machine/member-state-machine.ts +1 -1
- package/src/state-machine/space-state-machine.test.ts +2 -1
- package/src/state-machine/space-state-machine.ts +14 -8
- package/vitest.config.ts +5 -2
- package/.eslintrc.cjs +0 -7
- package/dist/lib/node/index.cjs +0 -1894
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/project.json +0 -27
package/moon.yml
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/credentials",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.28f8d3d",
|
|
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",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
+
"source": "./src/index.ts",
|
|
14
15
|
"types": "./dist/types/src/index.d.ts",
|
|
15
16
|
"browser": "./dist/lib/browser/index.mjs",
|
|
16
17
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
@@ -23,17 +24,17 @@
|
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"bip39": "^3.1.0",
|
|
25
26
|
"json-stable-stringify": "^1.0.1",
|
|
26
|
-
"@dxos/async": "0.8.
|
|
27
|
-
"@dxos/context": "0.8.
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/keys": "0.8.
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/protocols": "0.8.
|
|
35
|
-
"@dxos/timeframe": "0.8.
|
|
36
|
-
"@dxos/util": "0.8.
|
|
27
|
+
"@dxos/async": "0.8.4-main.28f8d3d",
|
|
28
|
+
"@dxos/context": "0.8.4-main.28f8d3d",
|
|
29
|
+
"@dxos/crypto": "0.8.4-main.28f8d3d",
|
|
30
|
+
"@dxos/keyring": "0.8.4-main.28f8d3d",
|
|
31
|
+
"@dxos/keys": "0.8.4-main.28f8d3d",
|
|
32
|
+
"@dxos/log": "0.8.4-main.28f8d3d",
|
|
33
|
+
"@dxos/node-std": "0.8.4-main.28f8d3d",
|
|
34
|
+
"@dxos/invariant": "0.8.4-main.28f8d3d",
|
|
35
|
+
"@dxos/protocols": "0.8.4-main.28f8d3d",
|
|
36
|
+
"@dxos/timeframe": "0.8.4-main.28f8d3d",
|
|
37
|
+
"@dxos/util": "0.8.4-main.28f8d3d"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/json-stable-stringify": "^1.0.32"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PublicKey } from '@dxos/keys';
|
|
6
|
-
import { type
|
|
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;
|
|
@@ -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
|
};
|
|
@@ -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 {
|
|
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 {
|
|
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,9 +9,10 @@ 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
|
|
|
14
|
+
import { type CredentialProcessor } from './credential-processor';
|
|
15
|
+
|
|
15
16
|
export type DeviceStateMachineParams = {
|
|
16
17
|
identityKey: PublicKey;
|
|
17
18
|
deviceKey: PublicKey;
|
package/src/processor/index.ts
CHANGED
|
@@ -6,9 +6,10 @@ 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
|
|
|
11
|
+
import { type CredentialProcessor } from './credential-processor';
|
|
12
|
+
|
|
12
13
|
export type ProfileStateMachineParams = {
|
|
13
14
|
identityKey: PublicKey;
|
|
14
15
|
onUpdate?: () => void;
|
|
@@ -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 {
|
|
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,
|
|
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
|
|
56
|
-
private readonly _feeds
|
|
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
|
|
67
|
-
readonly 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
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import { defineConfig, mergeConfig } from 'vitest/config';
|
|
6
6
|
|
|
7
|
-
import { baseConfig } from '../../../../vitest.
|
|
7
|
+
import { baseConfig } from '../../../../vitest.base.config';
|
|
8
8
|
|
|
9
|
-
export default mergeConfig(
|
|
9
|
+
export default mergeConfig(
|
|
10
|
+
baseConfig({ cwd: __dirname }),
|
|
11
|
+
defineConfig({}),
|
|
12
|
+
);
|