@dxos/protocols 2.33.9-dev.7d11f506 → 2.33.9-dev.8e92e630

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.
@@ -23,20 +23,27 @@ message SignedMessage {
23
23
  // Provides the common metadata needed for all signed objects.
24
24
  //
25
25
  message Signed {
26
- required string created = 1; // RFC-3339 datetime string.
26
+ /// RFC-3339 datetime string.
27
+ required string created = 1;
27
28
  required bytes nonce = 2;
28
- required google.protobuf.Any payload = 10; // The payload to be signed.
29
+ /// The payload to be signed.
30
+ required google.protobuf.Any payload = 10;
29
31
  }
30
32
 
31
33
  //
32
34
  // The signature data itself.
33
35
  //
34
36
  message Signature {
35
- required PubKey key = 1; // The publicKey of the keypair that made this signature.
36
- required bytes signature = 2; // The bytes of the signature.
37
- KeyChain keyChain = 3; // Optional. The certification chain of SignedMessages for this key.
37
+ /// The publicKey of the keypair that made this signature.
38
+ required PubKey key = 1;
39
+ /// The bytes of the signature.
40
+ required bytes signature = 2;
41
+ /// The certification chain of SignedMessages for this key.
42
+ optional KeyChain keyChain = 3;
38
43
  }
39
44
 
40
- required Signed signed = 1; // The signed message contents.
41
- repeated Signature signatures = 2; // An array of Signatures, one for each key that signed the message.
45
+ /// The signed message contents.
46
+ required Signed signed = 1;
47
+ /// An array of Signatures, one for each key that signed the message.
48
+ repeated Signature signatures = 2;
42
49
  }
@@ -45,9 +45,9 @@ message StreamClose {
45
45
  }
46
46
 
47
47
  message Error {
48
- string name = 1;
49
- string message = 2;
50
- string stack = 3;
48
+ optional string name = 1;
49
+ optional string message = 2;
50
+ optional string stack = 3;
51
51
  }
52
52
 
53
53
  message MessageTrace {
@@ -4,5 +4,3 @@
4
4
 
5
5
  // TODO(burdon): Add more exports?
6
6
  // Reconcile with echo-protocols, halo-protocols?
7
-
8
- export * from './gen/dxos/halo/keys';
package/src/public-key.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
5
+ import assert from 'node:assert';
6
+ import { inspect, InspectOptionsStylized } from 'node:util';
6
7
  import randomBytes from 'randombytes';
7
- import { inspect } from 'util';
8
8
 
9
9
  export const PUBLIC_KEY_LENGTH = 32;
10
10
  export const SECRET_KEY_LENGTH = 64;
@@ -156,8 +156,36 @@ export class PublicKey {
156
156
  /**
157
157
  * Used by NodeJS to get textual representation of this object when it's printed with a `console.log` statement.
158
158
  */
159
- [inspect.custom] () {
160
- return `<PublicKey ${this.truncate()}>`;
159
+ [inspect.custom] (depth: number, options: InspectOptionsStylized) {
160
+ if (!options.colors || !process.stdout.hasColors()) {
161
+ return `<PublicKey ${this.truncate()}>`;
162
+ }
163
+
164
+ const printControlCode = (code: number) => {
165
+ return `\x1b[${code}m`;
166
+ };
167
+
168
+ // Compute simple hash of the key.
169
+ const hash = Math.abs(this._value.reduce((acc, val) => acc ^ val | 0, 0));
170
+
171
+ const colors = [
172
+ 'red',
173
+ 'green',
174
+ 'yellow',
175
+ 'blue',
176
+ 'magenta',
177
+ 'cyan',
178
+ 'redBright',
179
+ 'greenBright',
180
+ 'yellowBright',
181
+ 'blueBright',
182
+ 'magentaBright',
183
+ 'cyanBright',
184
+ 'whiteBright'
185
+ ];
186
+ const color = colors[hash % colors.length];
187
+
188
+ return `<PublicKey ${printControlCode(inspect.colors[color]![0])}${this.truncate()}${printControlCode(inspect.colors.reset![0])}>`;
161
189
  }
162
190
 
163
191
  /**
package/src/timeframe.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { inspect } from 'util';
5
+ import { inspect } from 'node:util';
6
6
 
7
7
  import { PublicKey } from './public-key';
8
8