@dxos/credentials 0.6.12-main.78ddbdf → 0.6.12-main.89e9959

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=json-encoding.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-encoding.test.d.ts","sourceRoot":"","sources":["../../../../src/presentations/json-encoding.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/credentials",
3
- "version": "0.6.12-main.78ddbdf",
3
+ "version": "0.6.12-main.89e9959",
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",
@@ -24,17 +24,17 @@
24
24
  "dependencies": {
25
25
  "bip39": "^3.0.4",
26
26
  "json-stable-stringify": "^1.0.1",
27
- "@dxos/async": "0.6.12-main.78ddbdf",
28
- "@dxos/context": "0.6.12-main.78ddbdf",
29
- "@dxos/crypto": "0.6.12-main.78ddbdf",
30
- "@dxos/invariant": "0.6.12-main.78ddbdf",
31
- "@dxos/keys": "0.6.12-main.78ddbdf",
32
- "@dxos/keyring": "0.6.12-main.78ddbdf",
33
- "@dxos/log": "0.6.12-main.78ddbdf",
34
- "@dxos/protocols": "0.6.12-main.78ddbdf",
35
- "@dxos/timeframe": "0.6.12-main.78ddbdf",
36
- "@dxos/node-std": "0.6.12-main.78ddbdf",
37
- "@dxos/util": "0.6.12-main.78ddbdf"
27
+ "@dxos/async": "0.6.12-main.89e9959",
28
+ "@dxos/context": "0.6.12-main.89e9959",
29
+ "@dxos/crypto": "0.6.12-main.89e9959",
30
+ "@dxos/invariant": "0.6.12-main.89e9959",
31
+ "@dxos/keyring": "0.6.12-main.89e9959",
32
+ "@dxos/log": "0.6.12-main.89e9959",
33
+ "@dxos/keys": "0.6.12-main.89e9959",
34
+ "@dxos/node-std": "0.6.12-main.89e9959",
35
+ "@dxos/timeframe": "0.6.12-main.89e9959",
36
+ "@dxos/protocols": "0.6.12-main.89e9959",
37
+ "@dxos/util": "0.6.12-main.89e9959"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/json-stable-stringify": "^1.0.32"
@@ -0,0 +1,65 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { inspect } from 'util';
6
+ import { describe, test } from 'vitest';
7
+
8
+ import { randomBytes } from '@dxos/crypto';
9
+ import { Keyring } from '@dxos/keyring';
10
+ import { buf } from '@dxos/protocols/buf';
11
+ import { PresentationSchema } from '@dxos/protocols/buf/dxos/halo/credentials_pb';
12
+ import { schema } from '@dxos/protocols/proto';
13
+
14
+ import { signPresentation } from './presentation';
15
+ import { createCredential } from '../credentials';
16
+
17
+ describe('json encoding', () => {
18
+ test.skip('service access exercise by a device', async () => {
19
+ const keyring = new Keyring();
20
+ const serviceProvider = await keyring.createKey();
21
+ const identity = await keyring.createKey();
22
+ const device = await keyring.createKey();
23
+
24
+ const serviceAccessCredential = await createCredential({
25
+ assertion: {
26
+ '@type': 'dxos.halo.credentials.ServiceAccess',
27
+ serverName: 'hub.dxos.network',
28
+ serverKey: serviceProvider,
29
+ identityKey: identity,
30
+ capabilities: ['beta'],
31
+ },
32
+ subject: identity,
33
+ issuer: serviceProvider,
34
+ signer: keyring,
35
+ });
36
+
37
+ const deviceAuthorization = await createCredential({
38
+ assertion: {
39
+ '@type': 'dxos.halo.credentials.AuthorizedDevice',
40
+ deviceKey: device,
41
+ identityKey: identity,
42
+ },
43
+ subject: device,
44
+ issuer: identity,
45
+ signer: keyring,
46
+ });
47
+
48
+ const presentation = await signPresentation({
49
+ presentation: { credentials: [serviceAccessCredential] },
50
+ signer: keyring,
51
+ signerKey: device,
52
+ chain: { credential: deviceAuthorization },
53
+ nonce: randomBytes(32),
54
+ });
55
+
56
+ console.log('original (codec-protobuf object):', inspect(presentation, false, null, true));
57
+
58
+ const json = schema.getCodecForType('dxos.halo.credentials.Presentation').encodeToJson(presentation);
59
+ console.log('json (pb.js):', inspect(json, false, null, true));
60
+
61
+ // TODO(dmaretskyi): Fails because protobuf.js encodes timestamp as object.
62
+ const obj = buf.fromJson(PresentationSchema, json);
63
+ console.log('object (buf):', inspect(obj, false, null, true));
64
+ });
65
+ });