@dxos/keys 0.8.2-main.f081794 → 0.8.2-main.fbd8ed0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"random-bytes.d.ts","sourceRoot":"","sources":["../../../src/random-bytes.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,WAAY,MAAM,4BAQzC,CAAC"}
1
+ {"version":3,"file":"random-bytes.d.ts","sourceRoot":"","sources":["../../../src/random-bytes.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,4BAQzC,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { Schema } from 'effect';
1
2
  /**
2
3
  * A unique identifier for a space.
3
4
  * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).
@@ -6,11 +7,11 @@
6
7
  export type SpaceId = string & {
7
8
  __SpaceId: true;
8
9
  };
9
- export declare const SpaceId: Readonly<{
10
- byteLength: 20;
10
+ export declare const SpaceId: Schema.Schema<SpaceId, string> & {
11
+ byteLength: number;
11
12
  encode: (value: Uint8Array) => SpaceId;
12
13
  decode: (value: SpaceId) => Uint8Array;
13
14
  isValid: (value: string) => value is SpaceId;
14
15
  random: () => SpaceId;
15
- }>;
16
+ };
16
17
  //# sourceMappingURL=space-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"space-id.d.ts","sourceRoot":"","sources":["../../../src/space-id.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AAEH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAEnD,eAAO,MAAM,OAAO;;oBAEF,UAAU,KAAG,OAAO;oBAMpB,OAAO,KAAG,UAAU;qBAKnB,MAAM,KAAG,KAAK,IAAI,OAAO;kBAG9B,OAAO;EAGnB,CAAC"}
1
+ {"version":3,"file":"space-id.d.ts","sourceRoot":"","sources":["../../../src/space-id.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAiBhC;;;;GAIG;AAEH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAEnD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC;IACvC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,UAAU,CAAC;IACvC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,OAAO,CAAC;IAC7C,MAAM,EAAE,MAAM,OAAO,CAAC;CAmBvB,CAAC"}
@@ -1 +1 @@
1
- {"version":"5.7.3"}
1
+ {"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/keys",
3
- "version": "0.8.2-main.f081794",
3
+ "version": "0.8.2-main.fbd8ed0",
4
4
  "description": "Key utils and definitions.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -27,9 +27,10 @@
27
27
  "src"
28
28
  ],
29
29
  "dependencies": {
30
- "@dxos/debug": "0.8.2-main.f081794",
31
- "@dxos/invariant": "0.8.2-main.f081794",
32
- "@dxos/node-std": "0.8.2-main.f081794"
30
+ "effect": "3.14.21",
31
+ "@dxos/debug": "0.8.2-main.fbd8ed0",
32
+ "@dxos/node-std": "0.8.2-main.fbd8ed0",
33
+ "@dxos/invariant": "0.8.2-main.fbd8ed0"
33
34
  },
34
35
  "devDependencies": {
35
36
  "base32-decode": "^1.0.0",
package/src/dxn.ts CHANGED
@@ -153,6 +153,7 @@ export class DXN {
153
153
  return this.#parts;
154
154
  }
155
155
 
156
+ // TODO(burdon): Should getters fail?
156
157
  get typename() {
157
158
  invariant(this.#kind === DXN.kind.TYPE);
158
159
  return this.#parts[0];
package/src/space-id.ts CHANGED
@@ -4,43 +4,53 @@
4
4
 
5
5
  import base32Decode from 'base32-decode';
6
6
  import base32Encode from 'base32-encode';
7
+ import { Schema } from 'effect';
7
8
 
8
9
  import { invariant } from '@dxos/invariant';
9
10
 
10
11
  import { randomBytes } from './random-bytes';
11
12
 
13
+ /**
14
+ * Denotes RFC4648 base-32 format.
15
+ */
16
+ const MULTIBASE_PREFIX = 'B';
17
+
18
+ const ENCODED_LENGTH = 33;
19
+
20
+ const isValid = (value: string): value is SpaceId => {
21
+ return typeof value === 'string' && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
22
+ };
23
+
12
24
  /**
13
25
  * A unique identifier for a space.
14
26
  * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).
15
27
  * @example BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE
16
28
  */
17
- // TODO(burdon): Use effect brand.
29
+ // TODO(burdon): Use effect branded type?
18
30
  export type SpaceId = string & { __SpaceId: true };
19
31
 
20
- export const SpaceId = Object.freeze({
21
- byteLength: 20,
22
- encode: (value: Uint8Array): SpaceId => {
32
+ export const SpaceId: Schema.Schema<SpaceId, string> & {
33
+ byteLength: number;
34
+ encode: (value: Uint8Array) => SpaceId;
35
+ decode: (value: SpaceId) => Uint8Array;
36
+ isValid: (value: string) => value is SpaceId;
37
+ random: () => SpaceId;
38
+ } = class extends Schema.String.pipe(Schema.filter(isValid)) {
39
+ static byteLength = 20;
40
+
41
+ static encode = (value: Uint8Array): SpaceId => {
23
42
  invariant(value instanceof Uint8Array, 'Invalid type');
24
43
  invariant(value.length === SpaceId.byteLength, 'Invalid length');
25
-
26
44
  return (MULTIBASE_PREFIX + base32Encode(value, 'RFC4648')) as SpaceId;
27
- },
28
- decode: (value: SpaceId): Uint8Array => {
29
- invariant(value.startsWith(MULTIBASE_PREFIX), 'Invalid multibase32 encoding');
45
+ };
30
46
 
47
+ static decode = (value: SpaceId): Uint8Array => {
48
+ invariant(value.startsWith(MULTIBASE_PREFIX), 'Invalid multibase32 encoding');
31
49
  return new Uint8Array(base32Decode(value.slice(1), 'RFC4648'));
32
- },
33
- isValid: (value: string): value is SpaceId => {
34
- return typeof value === 'string' && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
35
- },
36
- random: (): SpaceId => {
37
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
38
- },
39
- });
40
-
41
- /**
42
- * Denotes RFC4648 base-32 format.
43
- */
44
- const MULTIBASE_PREFIX = 'B';
50
+ };
45
51
 
46
- const ENCODED_LENGTH = 33;
52
+ static isValid = isValid;
53
+ static random = (): SpaceId => {
54
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
55
+ };
56
+ };