@dxos/credentials 2.33.1-dev.0a5ae2e2 → 2.33.1-dev.376de34c

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 (42) hide show
  1. package/.rush/temp/package-deps_build:test.json +11 -11
  2. package/.rush/temp/package-deps_prerelease.json +11 -11
  3. package/dist/src/auth/auth-message.js +1 -1
  4. package/dist/src/auth/auth-message.js.map +1 -1
  5. package/dist/src/auth/auth.test.js +8 -8
  6. package/dist/src/auth/auth.test.js.map +1 -1
  7. package/dist/src/greet/greeter-plugin.test.js +4 -4
  8. package/dist/src/greet/greeter-plugin.test.js.map +1 -1
  9. package/dist/src/greet/greeter.d.ts +15 -15
  10. package/dist/src/greet/greeter.js +5 -5
  11. package/dist/src/greet/greeter.js.map +1 -1
  12. package/dist/src/greet/greeter.test.js +12 -12
  13. package/dist/src/greet/greeter.test.js.map +1 -1
  14. package/dist/src/greet/greeting-message.d.ts +2 -2
  15. package/dist/src/greet/greeting-message.js +9 -9
  16. package/dist/src/greet/greeting-message.js.map +1 -1
  17. package/dist/src/identity/identity-message.js +4 -4
  18. package/dist/src/identity/identity-message.js.map +1 -1
  19. package/dist/src/keys/keyring-helpers.d.ts.map +1 -1
  20. package/dist/src/keys/keyring-helpers.js +4 -3
  21. package/dist/src/keys/keyring-helpers.js.map +1 -1
  22. package/dist/src/keys/keyring.js +2 -2
  23. package/dist/src/keys/keyring.js.map +1 -1
  24. package/dist/src/party/party-credential.d.ts +1 -1
  25. package/dist/src/party/party-credential.js +10 -10
  26. package/dist/src/party/party-credential.js.map +1 -1
  27. package/dist/src/proto/any.d.ts +3 -3
  28. package/dist/src/proto/any.d.ts.map +1 -1
  29. package/dist/src/proto/substitutions.d.ts +1 -1
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +11 -11
  32. package/src/auth/auth-message.ts +1 -1
  33. package/src/auth/auth.test.ts +8 -8
  34. package/src/greet/greeter-plugin.test.ts +4 -4
  35. package/src/greet/greeter.test.js +12 -12
  36. package/src/greet/greeter.ts +5 -5
  37. package/src/greet/greeting-message.ts +9 -9
  38. package/src/identity/identity-message.ts +4 -4
  39. package/src/keys/keyring-helpers.ts +4 -3
  40. package/src/keys/keyring.ts +2 -2
  41. package/src/party/party-credential.ts +10 -10
  42. package/src/proto/any.ts +3 -3
@@ -10,11 +10,11 @@ const TYPE_URL_GREETING_COMMAND = 'dxos.credentials.greet.Command';
10
10
 
11
11
  /**
12
12
  * Create a Greeting 'BEGIN' command message.
13
- * @returns {{__type_url: string, command: *}}
13
+ * @returns {{'@type': string, command: *}}
14
14
  */
15
15
  export const createGreetingBeginMessage = (): WithTypeUrl<Command> => {
16
16
  return {
17
- __type_url: TYPE_URL_GREETING_COMMAND,
17
+ '@type': TYPE_URL_GREETING_COMMAND,
18
18
  command: Command.Type.BEGIN,
19
19
  params: []
20
20
  };
@@ -28,7 +28,7 @@ export const createGreetingHandshakeMessage = (secret: Buffer, params = []): Wit
28
28
  assert(Array.isArray(params));
29
29
 
30
30
  return {
31
- __type_url: TYPE_URL_GREETING_COMMAND,
31
+ '@type': TYPE_URL_GREETING_COMMAND,
32
32
  command: Command.Type.HANDSHAKE,
33
33
  params,
34
34
  secret
@@ -43,7 +43,7 @@ export const createGreetingNotarizeMessage = (secret: Buffer, credentialMessages
43
43
  assert(Array.isArray(credentialMessages));
44
44
 
45
45
  return {
46
- __type_url: TYPE_URL_GREETING_COMMAND,
46
+ '@type': TYPE_URL_GREETING_COMMAND,
47
47
  command: Command.Type.NOTARIZE,
48
48
  params: credentialMessages,
49
49
  secret
@@ -57,7 +57,7 @@ export const createGreetingFinishMessage = (secret: Buffer): WithTypeUrl<Command
57
57
  assert(Buffer.isBuffer(secret), 'Secret is not a buffer.');
58
58
 
59
59
  return {
60
- __type_url: TYPE_URL_GREETING_COMMAND,
60
+ '@type': TYPE_URL_GREETING_COMMAND,
61
61
  command: Command.Type.FINISH,
62
62
  secret,
63
63
  params: []
@@ -71,11 +71,11 @@ export const createGreetingClaimMessage = (invitationID: Buffer): WithTypeUrl<Co
71
71
  assert(Buffer.isBuffer(invitationID), 'invitationID is not a buffer.');
72
72
 
73
73
  return {
74
- __type_url: TYPE_URL_GREETING_COMMAND,
74
+ '@type': TYPE_URL_GREETING_COMMAND,
75
75
  command: Command.Type.CLAIM,
76
76
  params: [
77
77
  {
78
- __type_url: 'google.protobuf.BytesValue',
78
+ '@type': 'google.protobuf.BytesValue',
79
79
  value: invitationID
80
80
  }
81
81
  ]
@@ -86,14 +86,14 @@ export const createGreetingClaimMessage = (invitationID: Buffer): WithTypeUrl<Co
86
86
  * Crate a Greeting ClaimResponse message.
87
87
  * @param {Buffer} id The ID of the new invitation.
88
88
  * @param {Buffer} rendezvousKey The swarm key to use for Greeting.
89
- * @returns {{__type_url: string, payload: {__type_url: string, rendezvousKey: *, id: *}}}
89
+ * @returns {{'@type': string, payload: {'@type': string, rendezvousKey: *, id: *}}}
90
90
  */
91
91
  export const createGreetingClaimResponse = (id: Buffer, rendezvousKey: Buffer): WithTypeUrl<ClaimResponse> => {
92
92
  assert(id);
93
93
  assert(Buffer.isBuffer(rendezvousKey), 'rendezvousKey is not a buffer.');
94
94
 
95
95
  return {
96
- __type_url: 'dxos.credentials.greet.ClaimResponse',
96
+ '@type': 'dxos.credentials.greet.ClaimResponse',
97
97
  id,
98
98
  rendezvousKey
99
99
  };
@@ -9,12 +9,12 @@ import { unwrapEnvelopes, extractContents, unwrapMessage, wrapMessage } from '..
9
9
  import { DeviceInfo, IdentityInfo, KeyRecord, Message, SignedMessage, WithTypeUrl } from '../proto';
10
10
 
11
11
  /**
12
- * Return the __type_url, if present.
12
+ * Return the @type, if present.
13
13
  * @param message
14
14
  */
15
15
  function getTypeUrl (message: any) {
16
16
  // eslint-disable-next-line camelcase
17
- return message?.__type_url;
17
+ return message?.['@type'];
18
18
  }
19
19
 
20
20
  /**
@@ -26,7 +26,7 @@ export const createDeviceInfoMessage = (keyring: Keyring, displayName: string, d
26
26
  assert(deviceKey);
27
27
 
28
28
  const message: WithTypeUrl<DeviceInfo> = {
29
- __type_url: 'dxos.credentials.identity.DeviceInfo',
29
+ '@type': 'dxos.credentials.identity.DeviceInfo',
30
30
  publicKey: deviceKey.publicKey,
31
31
  displayName
32
32
  };
@@ -43,7 +43,7 @@ export const createIdentityInfoMessage = (keyring: Keyring, displayName: string,
43
43
  assert(identityKey);
44
44
 
45
45
  const message: WithTypeUrl<IdentityInfo> = {
46
- __type_url: 'dxos.credentials.identity.IdentityInfo',
46
+ '@type': 'dxos.credentials.identity.IdentityInfo',
47
47
  publicKey: identityKey.publicKey,
48
48
  displayName
49
49
  };
@@ -132,11 +132,12 @@ export const canonicalStringify = (obj: any) => {
132
132
  return stableStringify(obj, {
133
133
  /* The point of signing and verifying is not that the internal, private state of the objects be
134
134
  * identical, but that the public contents can be verified not to have been altered. For that reason,
135
- * really private fields (indicated by '__') are not included in the signature. In practice, this skips __type_url,
136
- * and it also gives a mechanism for attaching other attributes to an object without breaking the signature.
135
+ * really private fields (indicated by '__') are not included in the signature.
136
+ * This gives a mechanism for attaching other attributes to an object without breaking the signature.
137
+ * We also skip @type.
137
138
  */
138
139
  replacer: (key: any, value: any) => {
139
- if (key.toString().startsWith('__')) {
140
+ if (key.toString().startsWith('__') || key.toString() === '@type') {
140
141
  return undefined;
141
142
  }
142
143
  if (value) {
@@ -140,7 +140,7 @@ export class Keyring implements Signer {
140
140
  });
141
141
 
142
142
  return {
143
- __type_url: 'dxos.credentials.SignedMessage',
143
+ '@type': 'dxos.credentials.SignedMessage',
144
144
  signed,
145
145
  signatures
146
146
  };
@@ -564,7 +564,7 @@ export class Keyring implements Signer {
564
564
  });
565
565
 
566
566
  return canonicalStringify({
567
- __type_url: 'dxos.credentials.keys.KeyRecordList',
567
+ '@type': 'dxos.credentials.keys.KeyRecordList',
568
568
  keys
569
569
  });
570
570
  }
@@ -34,7 +34,7 @@ export const createPartyGenesisMessage = (
34
34
  assert(typeof admitKeyPair.type !== 'undefined');
35
35
 
36
36
  const message: WithTypeUrl<PartyCredential> = {
37
- __type_url: TYPE_URL_PARTY_CREDENTIAL,
37
+ '@type': TYPE_URL_PARTY_CREDENTIAL,
38
38
  type: PartyCredential.Type.PARTY_GENESIS,
39
39
  partyGenesis: {
40
40
  partyKey: partyKeyPair.publicKey,
@@ -61,7 +61,7 @@ export const createKeyAdmitMessage = (
61
61
  partyKey = PublicKey.from(partyKey);
62
62
 
63
63
  const message: WithTypeUrl<PartyCredential> = {
64
- __type_url: TYPE_URL_PARTY_CREDENTIAL,
64
+ '@type': TYPE_URL_PARTY_CREDENTIAL,
65
65
  type: PartyCredential.Type.KEY_ADMIT,
66
66
  keyAdmit: {
67
67
  partyKey,
@@ -87,7 +87,7 @@ export const createFeedAdmitMessage = (
87
87
  partyKey = PublicKey.from(partyKey);
88
88
 
89
89
  const message: WithTypeUrl<PartyCredential> = {
90
- __type_url: TYPE_URL_PARTY_CREDENTIAL,
90
+ '@type': TYPE_URL_PARTY_CREDENTIAL,
91
91
  type: PartyCredential.Type.FEED_ADMIT,
92
92
  feedAdmit: {
93
93
  partyKey,
@@ -115,7 +115,7 @@ export const createEnvelopeMessage = (
115
115
  partyKey = PublicKey.from(partyKey);
116
116
 
117
117
  const message: WithTypeUrl<PartyCredential> = {
118
- __type_url: TYPE_URL_PARTY_CREDENTIAL,
118
+ '@type': TYPE_URL_PARTY_CREDENTIAL,
119
119
  type: PartyCredential.Type.ENVELOPE,
120
120
  envelope: {
121
121
  partyKey,
@@ -134,7 +134,7 @@ export const createEnvelopeMessage = (
134
134
  export const isPartyCredentialMessage = (message: Message | SignedMessage) => {
135
135
  const signed = unwrapMessage(message) as SignedMessage;
136
136
  // eslint-disable-next-line camelcase
137
- return signed?.signed?.payload?.__type_url === TYPE_URL_PARTY_CREDENTIAL;
137
+ return signed?.signed?.payload?.['@type'] === TYPE_URL_PARTY_CREDENTIAL;
138
138
  };
139
139
 
140
140
  /**
@@ -166,7 +166,7 @@ export function isSignedMessage (message: any): message is SignedMessage {
166
166
  // TODO(burdon): Typespec is too loose.
167
167
  export function wrapMessage (message: Message | SignedMessage | Command | Auth): WithTypeUrl<Message> {
168
168
  const payload = message as any;
169
- return { __type_url: TYPE_URL_MESSAGE, payload } as WithTypeUrl<Message>;
169
+ return { '@type': TYPE_URL_MESSAGE, payload } as WithTypeUrl<Message>;
170
170
  }
171
171
 
172
172
  /**
@@ -286,10 +286,10 @@ export const createPartyInvitationMessage = (
286
286
  inviteeKey = PublicKey.from(inviteeKey);
287
287
 
288
288
  return {
289
- __type_url: TYPE_URL_MESSAGE,
289
+ '@type': TYPE_URL_MESSAGE,
290
290
  payload:
291
291
  signer.sign({
292
- __type_url: TYPE_URL_PARTY_INVITATION,
292
+ '@type': TYPE_URL_PARTY_INVITATION,
293
293
  id: randomBytes(),
294
294
  partyKey,
295
295
  issuerKey: issuerKey.publicKey,
@@ -307,8 +307,8 @@ export const isPartyInvitationMessage = (message: Message | SignedMessage) => {
307
307
  const signed = unwrapMessage(message);
308
308
 
309
309
  // eslint-disable-next-line camelcase
310
- const payloadType = signed?.__type_url;
310
+ const payloadType = signed?.['@type'];
311
311
  // eslint-disable-next-line camelcase
312
- const signedType = signed?.signed?.payload?.__type_url;
312
+ const signedType = signed?.signed?.payload?.['@type'];
313
313
  return payloadType === TYPE_URL_SIGNED_MESSAGE && signedType === TYPE_URL_PARTY_INVITATION;
314
314
  };
package/src/proto/any.ts CHANGED
@@ -5,17 +5,17 @@
5
5
  import { TYPES } from './gen';
6
6
 
7
7
  // eslint-disable-next-line camelcase
8
- export type WithTypeUrl<T> = T & { __type_url: string }
8
+ export type WithTypeUrl<T> = T & { '@type': string }
9
9
 
10
10
  export interface DecodedAny {
11
11
  // eslint-disable-next-line camelcase
12
- __type_url: string,
12
+ '@type': string,
13
13
  [key: string]: any,
14
14
  }
15
15
 
16
16
  export type KnownAny = {
17
17
  [K in keyof TYPES]: {
18
18
  // eslint-disable-next-line camelcase
19
- __type_url: K,
19
+ '@type': K,
20
20
  } & TYPES[K]
21
21
  }[keyof TYPES]