cojson 0.0.6 → 0.0.8

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 (74) hide show
  1. package/.eslintrc.cjs +11 -8
  2. package/dist/coValue.d.ts +97 -0
  3. package/dist/coValue.js +341 -401
  4. package/dist/coValue.js.map +1 -0
  5. package/dist/coValue.test.d.ts +1 -0
  6. package/dist/coValue.test.js +69 -113
  7. package/dist/coValue.test.js.map +1 -0
  8. package/dist/contentType.d.ts +15 -0
  9. package/dist/contentType.js +5 -5
  10. package/dist/contentType.js.map +1 -0
  11. package/dist/contentType.test.d.ts +1 -0
  12. package/dist/contentType.test.js +138 -168
  13. package/dist/contentType.test.js.map +1 -0
  14. package/dist/contentTypes/coList.d.ts +11 -0
  15. package/dist/contentTypes/coList.js +14 -16
  16. package/dist/contentTypes/coList.js.map +1 -0
  17. package/dist/contentTypes/coMap.d.ts +56 -0
  18. package/dist/contentTypes/coMap.js +112 -112
  19. package/dist/contentTypes/coMap.js.map +1 -0
  20. package/dist/contentTypes/coStream.d.ts +11 -0
  21. package/dist/contentTypes/coStream.js +14 -16
  22. package/dist/contentTypes/coStream.js.map +1 -0
  23. package/dist/contentTypes/static.d.ts +11 -0
  24. package/dist/contentTypes/static.js +12 -14
  25. package/dist/contentTypes/static.js.map +1 -0
  26. package/dist/crypto.d.ts +97 -0
  27. package/dist/crypto.js +100 -151
  28. package/dist/crypto.js.map +1 -0
  29. package/dist/crypto.test.d.ts +1 -0
  30. package/dist/crypto.test.js +94 -134
  31. package/dist/crypto.test.js.map +1 -0
  32. package/dist/ids.d.ts +7 -0
  33. package/dist/ids.js +2 -1
  34. package/dist/ids.js.map +1 -0
  35. package/dist/index.d.ts +19 -0
  36. package/dist/index.js +10 -18
  37. package/dist/index.js.map +1 -0
  38. package/dist/jsonValue.d.ts +7 -0
  39. package/dist/jsonValue.js +2 -1
  40. package/dist/jsonValue.js.map +1 -0
  41. package/dist/node.d.ts +33 -0
  42. package/dist/node.js +102 -133
  43. package/dist/node.js.map +1 -0
  44. package/dist/permissions.d.ts +54 -0
  45. package/dist/permissions.js +202 -228
  46. package/dist/permissions.js.map +1 -0
  47. package/dist/permissions.test.d.ts +1 -0
  48. package/dist/permissions.test.js +724 -915
  49. package/dist/permissions.test.js.map +1 -0
  50. package/dist/sync.d.ts +80 -0
  51. package/dist/sync.js +247 -294
  52. package/dist/sync.js.map +1 -0
  53. package/dist/sync.test.d.ts +1 -0
  54. package/dist/sync.test.js +763 -798
  55. package/dist/sync.test.js.map +1 -0
  56. package/package.json +7 -4
  57. package/src/coValue.test.ts +3 -4
  58. package/src/coValue.ts +11 -17
  59. package/src/contentType.test.ts +3 -3
  60. package/src/contentType.ts +6 -6
  61. package/src/contentTypes/coList.ts +4 -4
  62. package/src/contentTypes/coMap.ts +6 -6
  63. package/src/contentTypes/coStream.ts +4 -4
  64. package/src/contentTypes/static.ts +5 -5
  65. package/src/crypto.test.ts +1 -1
  66. package/src/crypto.ts +2 -2
  67. package/src/index.ts +9 -7
  68. package/src/jsonValue.ts +1 -1
  69. package/src/node.ts +6 -7
  70. package/src/permissions.test.ts +5 -5
  71. package/src/permissions.ts +7 -7
  72. package/src/sync.test.ts +7 -7
  73. package/src/sync.ts +6 -6
  74. package/tsconfig.json +1 -7
@@ -1,18 +1,16 @@
1
- "use strict";
2
1
  export class CoList {
3
- id;
4
- type = "colist";
5
- coValue;
6
- constructor(coValue) {
7
- this.id = coValue.id;
8
- this.coValue = coValue;
9
- }
10
- toJSON() {
11
- throw new Error("Method not implemented.");
12
- }
13
- subscribe(listener) {
14
- return this.coValue.subscribe((content) => {
15
- listener(content);
16
- });
17
- }
2
+ constructor(coValue) {
3
+ this.type = "colist";
4
+ this.id = coValue.id;
5
+ this.coValue = coValue;
6
+ }
7
+ toJSON() {
8
+ throw new Error("Method not implemented.");
9
+ }
10
+ subscribe(listener) {
11
+ return this.coValue.subscribe((content) => {
12
+ listener(content);
13
+ });
14
+ }
18
15
  }
16
+ //# sourceMappingURL=coList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coList.js","sourceRoot":"","sources":["../../src/contentTypes/coList.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,MAAM;IAKf,YAAY,OAAgB;QAH5B,SAAI,GAAG,QAAiB,CAAC;QAIrB,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAgC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACF,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,QAA0C;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE;YACtC,QAAQ,CAAC,OAA0B,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,56 @@
1
+ import { JsonObject, JsonValue } from '../jsonValue.js';
2
+ import { TransactionID } from '../ids.js';
3
+ import { CoValueID } from '../contentType.js';
4
+ import { CoValue } from '../coValue.js';
5
+ type MapOp<K extends string, V extends JsonValue> = {
6
+ txID: TransactionID;
7
+ madeAt: number;
8
+ changeIdx: number;
9
+ } & MapOpPayload<K, V>;
10
+ export type MapOpPayload<K extends string, V extends JsonValue> = {
11
+ op: "insert";
12
+ key: K;
13
+ value: V;
14
+ } | {
15
+ op: "delete";
16
+ key: K;
17
+ };
18
+ export declare class CoMap<M extends {
19
+ [key: string]: JsonValue;
20
+ }, Meta extends JsonValue, K extends string = keyof M & string, V extends JsonValue = M[K], MM extends {
21
+ [key: string]: JsonValue;
22
+ } = {
23
+ [KK in K]: M[KK];
24
+ }> {
25
+ id: CoValueID<CoMap<MM, Meta>>;
26
+ coValue: CoValue;
27
+ type: "comap";
28
+ ops: {
29
+ [KK in K]?: MapOp<K, M[KK]>[];
30
+ };
31
+ constructor(coValue: CoValue);
32
+ protected fillOpsFromCoValue(): void;
33
+ keys(): K[];
34
+ get<KK extends K>(key: KK): M[KK] | undefined;
35
+ getAtTime<KK extends K>(key: KK, time: number): M[KK] | undefined;
36
+ getLastTxID<KK extends K>(key: KK): TransactionID | undefined;
37
+ getHistory<KK extends K>(key: KK): {
38
+ at: number;
39
+ txID: TransactionID;
40
+ value: M[KK] | undefined;
41
+ }[];
42
+ toJSON(): JsonObject;
43
+ edit(changer: (editable: WriteableCoMap<M, Meta>) => void): CoMap<M, Meta>;
44
+ subscribe(listener: (coMap: CoMap<M, Meta>) => void): () => void;
45
+ }
46
+ export declare class WriteableCoMap<M extends {
47
+ [key: string]: JsonValue;
48
+ }, Meta extends JsonValue, K extends string = keyof M & string, V extends JsonValue = M[K], MM extends {
49
+ [key: string]: JsonValue;
50
+ } = {
51
+ [KK in K]: M[KK];
52
+ }> extends CoMap<M, Meta, K, V, MM> {
53
+ set<KK extends K>(key: KK, value: M[KK], privacy?: "private" | "trusting"): void;
54
+ delete(key: K, privacy?: "private" | "trusting"): void;
55
+ }
56
+ export {};
@@ -1,126 +1,126 @@
1
- "use strict";
2
1
  export class CoMap {
3
- id;
4
- coValue;
5
- type = "comap";
6
- ops;
7
- constructor(coValue) {
8
- this.id = coValue.id;
9
- this.coValue = coValue;
10
- this.ops = {};
11
- this.fillOpsFromCoValue();
12
- }
13
- fillOpsFromCoValue() {
14
- this.ops = {};
15
- for (const { txID, changes, madeAt } of this.coValue.getValidSortedTransactions()) {
16
- for (const [changeIdx, changeUntyped] of changes.entries()) {
17
- const change = changeUntyped;
18
- let entries = this.ops[change.key];
19
- if (!entries) {
20
- entries = [];
21
- this.ops[change.key] = entries;
22
- }
23
- entries.push({
24
- txID,
25
- madeAt,
26
- changeIdx,
27
- ...change
28
- });
29
- }
2
+ constructor(coValue) {
3
+ this.type = "comap";
4
+ this.id = coValue.id;
5
+ this.coValue = coValue;
6
+ this.ops = {};
7
+ this.fillOpsFromCoValue();
30
8
  }
31
- }
32
- keys() {
33
- return Object.keys(this.ops);
34
- }
35
- get(key) {
36
- const ops = this.ops[key];
37
- if (!ops) {
38
- return void 0;
9
+ fillOpsFromCoValue() {
10
+ this.ops = {};
11
+ for (const { txID, changes, madeAt } of this.coValue.getValidSortedTransactions()) {
12
+ for (const [changeIdx, changeUntyped] of (changes).entries()) {
13
+ const change = changeUntyped;
14
+ let entries = this.ops[change.key];
15
+ if (!entries) {
16
+ entries = [];
17
+ this.ops[change.key] = entries;
18
+ }
19
+ entries.push({
20
+ txID,
21
+ madeAt,
22
+ changeIdx,
23
+ ...change,
24
+ });
25
+ }
26
+ }
39
27
  }
40
- const lastEntry = ops[ops.length - 1];
41
- if (lastEntry.op === "delete") {
42
- return void 0;
43
- } else {
44
- return lastEntry.value;
28
+ keys() {
29
+ return Object.keys(this.ops);
45
30
  }
46
- }
47
- getAtTime(key, time) {
48
- const ops = this.ops[key];
49
- if (!ops) {
50
- return void 0;
31
+ get(key) {
32
+ const ops = this.ops[key];
33
+ if (!ops) {
34
+ return undefined;
35
+ }
36
+ const lastEntry = ops[ops.length - 1];
37
+ if (lastEntry.op === "delete") {
38
+ return undefined;
39
+ }
40
+ else {
41
+ return lastEntry.value;
42
+ }
51
43
  }
52
- const lastOpBeforeOrAtTime = ops.findLast((op) => op.madeAt <= time);
53
- if (!lastOpBeforeOrAtTime) {
54
- return void 0;
44
+ getAtTime(key, time) {
45
+ const ops = this.ops[key];
46
+ if (!ops) {
47
+ return undefined;
48
+ }
49
+ const lastOpBeforeOrAtTime = ops.findLast((op) => op.madeAt <= time);
50
+ if (!lastOpBeforeOrAtTime) {
51
+ return undefined;
52
+ }
53
+ if (lastOpBeforeOrAtTime.op === "delete") {
54
+ return undefined;
55
+ }
56
+ else {
57
+ return lastOpBeforeOrAtTime.value;
58
+ }
55
59
  }
56
- if (lastOpBeforeOrAtTime.op === "delete") {
57
- return void 0;
58
- } else {
59
- return lastOpBeforeOrAtTime.value;
60
+ getLastTxID(key) {
61
+ const ops = this.ops[key];
62
+ if (!ops) {
63
+ return undefined;
64
+ }
65
+ const lastEntry = ops[ops.length - 1];
66
+ return lastEntry.txID;
60
67
  }
61
- }
62
- getLastTxID(key) {
63
- const ops = this.ops[key];
64
- if (!ops) {
65
- return void 0;
68
+ getHistory(key) {
69
+ const ops = this.ops[key];
70
+ if (!ops) {
71
+ return [];
72
+ }
73
+ const history = [];
74
+ for (const op of ops) {
75
+ if (op.op === "delete") {
76
+ history.push({ at: op.madeAt, txID: op.txID, value: undefined });
77
+ }
78
+ else {
79
+ history.push({ at: op.madeAt, txID: op.txID, value: op.value });
80
+ }
81
+ }
82
+ return history;
66
83
  }
67
- const lastEntry = ops[ops.length - 1];
68
- return lastEntry.txID;
69
- }
70
- getHistory(key) {
71
- const ops = this.ops[key];
72
- if (!ops) {
73
- return [];
84
+ toJSON() {
85
+ const json = {};
86
+ for (const key of this.keys()) {
87
+ const value = this.get(key);
88
+ if (value !== undefined) {
89
+ json[key] = value;
90
+ }
91
+ }
92
+ return json;
74
93
  }
75
- const history = [];
76
- for (const op of ops) {
77
- if (op.op === "delete") {
78
- history.push({ at: op.madeAt, txID: op.txID, value: void 0 });
79
- } else {
80
- history.push({ at: op.madeAt, txID: op.txID, value: op.value });
81
- }
94
+ edit(changer) {
95
+ const editable = new WriteableCoMap(this.coValue);
96
+ changer(editable);
97
+ return new CoMap(this.coValue);
82
98
  }
83
- return history;
84
- }
85
- toJSON() {
86
- const json = {};
87
- for (const key of this.keys()) {
88
- const value = this.get(key);
89
- if (value !== void 0) {
90
- json[key] = value;
91
- }
99
+ subscribe(listener) {
100
+ return this.coValue.subscribe((content) => {
101
+ listener(content);
102
+ });
92
103
  }
93
- return json;
94
- }
95
- edit(changer) {
96
- const editable = new WriteableCoMap(this.coValue);
97
- changer(editable);
98
- return new CoMap(this.coValue);
99
- }
100
- subscribe(listener) {
101
- return this.coValue.subscribe((content) => {
102
- listener(content);
103
- });
104
- }
105
104
  }
106
105
  export class WriteableCoMap extends CoMap {
107
- set(key, value, privacy = "private") {
108
- this.coValue.makeTransaction([
109
- {
110
- op: "insert",
111
- key,
112
- value
113
- }
114
- ], privacy);
115
- this.fillOpsFromCoValue();
116
- }
117
- delete(key, privacy = "private") {
118
- this.coValue.makeTransaction([
119
- {
120
- op: "delete",
121
- key
122
- }
123
- ], privacy);
124
- this.fillOpsFromCoValue();
125
- }
106
+ set(key, value, privacy = "private") {
107
+ this.coValue.makeTransaction([
108
+ {
109
+ op: "insert",
110
+ key,
111
+ value,
112
+ },
113
+ ], privacy);
114
+ this.fillOpsFromCoValue();
115
+ }
116
+ delete(key, privacy = "private") {
117
+ this.coValue.makeTransaction([
118
+ {
119
+ op: "delete",
120
+ key,
121
+ },
122
+ ], privacy);
123
+ this.fillOpsFromCoValue();
124
+ }
126
125
  }
126
+ //# sourceMappingURL=coMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coMap.js","sourceRoot":"","sources":["../../src/contentTypes/coMap.ts"],"names":[],"mappings":"AAsBA,MAAM,OAAO,KAAK;IAgBd,YAAY,OAAgB;QAL5B,SAAI,GAAG,OAAgB,CAAC;QAMpB,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAgC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QAEd,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;IAES,kBAAkB;QACxB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QAEd,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE;YAC/E,KAAK,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,CACrC,OAAO,CACV,CAAC,OAAO,EAAE,EAAE;gBACT,MAAM,MAAM,GAAG,aAAmC,CAAC;gBACnD,IAAI,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACnC,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,QAAQ,GAAG,IAAI,cAAc,CAAU,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3D,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClB,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,SAAS,CAAC,QAAyC;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE;YACtC,QAAQ,CAAC,OAAyB,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,MAAM,OAAO,cAQX,SAAQ,KAAwB;IAC9B,GAAG,CAAe,GAAO,EAAE,KAAY,EAAE,UAAkC,SAAS;QAChF,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;YACzB;gBACI,EAAE,EAAE,QAAQ;gBACZ,GAAG;gBACH,KAAK;aACR;SACJ,EAAE,OAAO,CAAC,CAAC;QAEZ,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,GAAM,EAAE,UAAkC,SAAS;QACtD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;YACzB;gBACI,EAAE,EAAE,QAAQ;gBACZ,GAAG;aACN;SACJ,EAAE,OAAO,CAAC,CAAC;QAEZ,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;CACJ"}
@@ -0,0 +1,11 @@
1
+ import { JsonObject, JsonValue } from '../jsonValue.js';
2
+ import { CoValueID } from '../contentType.js';
3
+ import { CoValue } from '../coValue.js';
4
+ export declare class CoStream<T extends JsonValue, Meta extends JsonValue> {
5
+ id: CoValueID<CoStream<T, Meta>>;
6
+ type: "costream";
7
+ coValue: CoValue;
8
+ constructor(coValue: CoValue);
9
+ toJSON(): JsonObject;
10
+ subscribe(listener: (coMap: CoStream<T, Meta>) => void): () => void;
11
+ }
@@ -1,18 +1,16 @@
1
- "use strict";
2
1
  export class CoStream {
3
- id;
4
- type = "costream";
5
- coValue;
6
- constructor(coValue) {
7
- this.id = coValue.id;
8
- this.coValue = coValue;
9
- }
10
- toJSON() {
11
- throw new Error("Method not implemented.");
12
- }
13
- subscribe(listener) {
14
- return this.coValue.subscribe((content) => {
15
- listener(content);
16
- });
17
- }
2
+ constructor(coValue) {
3
+ this.type = "costream";
4
+ this.id = coValue.id;
5
+ this.coValue = coValue;
6
+ }
7
+ toJSON() {
8
+ throw new Error("Method not implemented.");
9
+ }
10
+ subscribe(listener) {
11
+ return this.coValue.subscribe((content) => {
12
+ listener(content);
13
+ });
14
+ }
18
15
  }
16
+ //# sourceMappingURL=coStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coStream.js","sourceRoot":"","sources":["../../src/contentTypes/coStream.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,QAAQ;IAKjB,YAAY,OAAgB;QAH5B,SAAI,GAAG,UAAmB,CAAC;QAIvB,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAkC,CAAC;QACrD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACF,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,QAA4C;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE;YACtC,QAAQ,CAAC,OAA4B,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,11 @@
1
+ import { JsonObject, JsonValue } from '../jsonValue.js';
2
+ import { CoValueID } from '../contentType.js';
3
+ import { CoValue } from '../coValue.js';
4
+ export declare class Static<T extends JsonValue> {
5
+ id: CoValueID<Static<T>>;
6
+ type: "static";
7
+ coValue: CoValue;
8
+ constructor(coValue: CoValue);
9
+ toJSON(): JsonObject;
10
+ subscribe(_listener: (coMap: Static<T>) => void): () => void;
11
+ }
@@ -1,16 +1,14 @@
1
- "use strict";
2
1
  export class Static {
3
- id;
4
- type = "static";
5
- coValue;
6
- constructor(coValue) {
7
- this.id = coValue.id;
8
- this.coValue = coValue;
9
- }
10
- toJSON() {
11
- throw new Error("Method not implemented.");
12
- }
13
- subscribe(listener) {
14
- throw new Error("Method not implemented.");
15
- }
2
+ constructor(coValue) {
3
+ this.type = "static";
4
+ this.id = coValue.id;
5
+ this.coValue = coValue;
6
+ }
7
+ toJSON() {
8
+ throw new Error("Method not implemented.");
9
+ }
10
+ subscribe(_listener) {
11
+ throw new Error("Method not implemented.");
12
+ }
16
13
  }
14
+ //# sourceMappingURL=static.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static.js","sourceRoot":"","sources":["../../src/contentTypes/static.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,MAAM;IAKf,YAAY,OAAgB;QAH5B,SAAI,GAAG,QAAiB,CAAC;QAIrB,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAA0B,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACF,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,SAAqC;QAC3C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CACJ"}
@@ -0,0 +1,97 @@
1
+ import { JsonValue } from './jsonValue.js';
2
+ import { blake3 } from "@noble/hashes/blake3";
3
+ import { RawCoValueID, TransactionID } from './ids.js';
4
+ export type SignatorySecret = `signatorySecret_z${string}`;
5
+ export type SignatoryID = `signatory_z${string}`;
6
+ export type Signature = `signature_z${string}`;
7
+ export type RecipientSecret = `recipientSecret_z${string}`;
8
+ export type RecipientID = `recipient_z${string}`;
9
+ export type Sealed<T> = `sealed_U${string}` & {
10
+ __type: T;
11
+ };
12
+ export declare function newRandomSignatory(): SignatorySecret;
13
+ export declare function signatorySecretToBytes(secret: SignatorySecret): Uint8Array;
14
+ export declare function signatorySecretFromBytes(bytes: Uint8Array): SignatorySecret;
15
+ export declare function getSignatoryID(secret: SignatorySecret): SignatoryID;
16
+ export declare function sign(secret: SignatorySecret, message: JsonValue): Signature;
17
+ export declare function verify(signature: Signature, message: JsonValue, id: SignatoryID): boolean;
18
+ export declare function newRandomRecipient(): RecipientSecret;
19
+ export declare function recipientSecretToBytes(secret: RecipientSecret): Uint8Array;
20
+ export declare function recipientSecretFromBytes(bytes: Uint8Array): RecipientSecret;
21
+ export declare function getRecipientID(secret: RecipientSecret): RecipientID;
22
+ export type SealedSet<T> = {
23
+ [recipient: RecipientID]: Sealed<T>;
24
+ };
25
+ export declare function seal<T extends JsonValue>(message: T, from: RecipientSecret, to: Set<RecipientID>, nOnceMaterial: {
26
+ in: RawCoValueID;
27
+ tx: TransactionID;
28
+ }): SealedSet<T>;
29
+ export declare function openAs<T extends JsonValue>(sealedSet: SealedSet<T>, recipient: RecipientSecret, from: RecipientID, nOnceMaterial: {
30
+ in: RawCoValueID;
31
+ tx: TransactionID;
32
+ }): T | undefined;
33
+ export type Hash = `hash_z${string}`;
34
+ export declare function secureHash(value: JsonValue): Hash;
35
+ export declare class StreamingHash {
36
+ state: ReturnType<typeof blake3.create>;
37
+ constructor(fromClone?: ReturnType<typeof blake3.create>);
38
+ update(value: JsonValue): void;
39
+ digest(): Hash;
40
+ clone(): StreamingHash;
41
+ }
42
+ export type ShortHash = `shortHash_z${string}`;
43
+ export declare function shortHash(value: JsonValue): ShortHash;
44
+ export type Encrypted<T extends JsonValue, N extends JsonValue> = `encrypted_U${string}` & {
45
+ __type: T;
46
+ __nOnceMaterial: N;
47
+ };
48
+ export type KeySecret = `keySecret_z${string}`;
49
+ export type KeyID = `key_z${string}`;
50
+ export declare function newRandomKeySecret(): {
51
+ secret: KeySecret;
52
+ id: KeyID;
53
+ };
54
+ export declare function encryptForTransaction<T extends JsonValue>(value: T, keySecret: KeySecret, nOnceMaterial: {
55
+ in: RawCoValueID;
56
+ tx: TransactionID;
57
+ }): Encrypted<T, {
58
+ in: RawCoValueID;
59
+ tx: TransactionID;
60
+ }>;
61
+ export declare function sealKeySecret(keys: {
62
+ toSeal: {
63
+ id: KeyID;
64
+ secret: KeySecret;
65
+ };
66
+ sealing: {
67
+ id: KeyID;
68
+ secret: KeySecret;
69
+ };
70
+ }): {
71
+ sealed: KeyID;
72
+ sealing: KeyID;
73
+ encrypted: Encrypted<KeySecret, {
74
+ sealed: KeyID;
75
+ sealing: KeyID;
76
+ }>;
77
+ };
78
+ export declare function decryptForTransaction<T extends JsonValue>(encrypted: Encrypted<T, {
79
+ in: RawCoValueID;
80
+ tx: TransactionID;
81
+ }>, keySecret: KeySecret, nOnceMaterial: {
82
+ in: RawCoValueID;
83
+ tx: TransactionID;
84
+ }): T | undefined;
85
+ export declare function unsealKeySecret(sealedInfo: {
86
+ sealed: KeyID;
87
+ sealing: KeyID;
88
+ encrypted: Encrypted<KeySecret, {
89
+ sealed: KeyID;
90
+ sealing: KeyID;
91
+ }>;
92
+ }, sealingSecret: KeySecret): KeySecret | undefined;
93
+ export declare function uniquenessForHeader(): `z${string}`;
94
+ export declare function createdNowUnique(): {
95
+ createdAt: `2${string}`;
96
+ uniqueness: `z${string}`;
97
+ };