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
package/dist/index.js CHANGED
@@ -1,21 +1,13 @@
1
- "use strict";
2
- import {
3
- CoValue,
4
- agentCredentialFromBytes,
5
- agentCredentialToBytes,
6
- getAgent,
7
- getAgentID,
8
- newRandomAgentCredential,
9
- newRandomSessionID
10
- } from "./coValue";
11
- import { LocalNode } from "./node";
12
- import { CoMap } from "./contentTypes/coMap";
1
+ import { CoValue, agentCredentialFromBytes, agentCredentialToBytes, getAgent, getAgentID, newRandomAgentCredential, newRandomSessionID, } from './coValue.js';
2
+ import { LocalNode } from './node.js';
3
+ import { CoMap } from './contentTypes/coMap.js';
13
4
  const internals = {
14
- agentCredentialToBytes,
15
- agentCredentialFromBytes,
16
- getAgent,
17
- getAgentID,
18
- newRandomAgentCredential,
19
- newRandomSessionID
5
+ agentCredentialToBytes,
6
+ agentCredentialFromBytes,
7
+ getAgent,
8
+ getAgentID,
9
+ newRandomAgentCredential,
10
+ newRandomSessionID,
20
11
  };
21
12
  export { LocalNode, CoValue, CoMap, internals };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,wBAAwB,EACxB,sBAAsB,EACtB,QAAQ,EACR,UAAU,EACV,wBAAwB,EACxB,kBAAkB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAUhD,MAAM,SAAS,GAAG;IACd,sBAAsB;IACtB,wBAAwB;IACxB,QAAQ;IACR,UAAU;IACV,wBAAwB;IACxB,kBAAkB;CACrB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { CoValueID, ContentType } from './contentType.js';
2
+ export type JsonAtom = string | number | boolean | null;
3
+ export type JsonValue = JsonAtom | JsonArray | JsonObject | CoValueID<ContentType>;
4
+ export type JsonArray = JsonValue[];
5
+ export type JsonObject = {
6
+ [key: string]: JsonValue;
7
+ };
package/dist/jsonValue.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";
1
+ export {};
2
+ //# sourceMappingURL=jsonValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonValue.js","sourceRoot":"","sources":["../src/jsonValue.ts"],"names":[],"mappings":""}
package/dist/node.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { CoValue, AgentCredential, Agent, CoValueHeader } from './coValue.js';
2
+ import { Team } from './permissions.js';
3
+ import { SyncManager } from './sync.js';
4
+ import { AgentID, RawCoValueID, SessionID } from './ids.js';
5
+ import { CoValueID, ContentType } from './contentType.js';
6
+ export declare class LocalNode {
7
+ coValues: {
8
+ [key: RawCoValueID]: CoValueState;
9
+ };
10
+ agentCredential: AgentCredential;
11
+ agentID: AgentID;
12
+ ownSessionID: SessionID;
13
+ sync: SyncManager;
14
+ constructor(agentCredential: AgentCredential, ownSessionID: SessionID);
15
+ createCoValue(header: CoValueHeader): CoValue;
16
+ loadCoValue(id: RawCoValueID): Promise<CoValue>;
17
+ load<T extends ContentType>(id: CoValueID<T>): Promise<T>;
18
+ expectCoValueLoaded(id: RawCoValueID, expectation?: string): CoValue;
19
+ createAgent(publicNickname: string): AgentCredential;
20
+ expectAgentLoaded(id: AgentID, expectation?: string): Agent;
21
+ createTeam(): Team;
22
+ testWithDifferentCredentials(agentCredential: AgentCredential, ownSessionID: SessionID): LocalNode;
23
+ }
24
+ type CoValueState = {
25
+ state: "loading";
26
+ done: Promise<CoValue>;
27
+ resolve: (coValue: CoValue) => void;
28
+ } | {
29
+ state: "loaded";
30
+ coValue: CoValue;
31
+ };
32
+ export declare function newLoadingState(): CoValueState;
33
+ export {};
package/dist/node.js CHANGED
@@ -1,144 +1,113 @@
1
- "use strict";
2
- import { createdNowUnique, newRandomKeySecret, seal } from "./crypto";
3
- import {
4
- CoValue,
5
- getAgent,
6
- getAgentID,
7
- getAgentCoValueHeader,
8
- newRandomAgentCredential
9
- } from "./coValue";
10
- import { Team, expectTeamContent } from "./permissions";
11
- import { SyncManager } from "./sync";
1
+ import { createdNowUnique, newRandomKeySecret, seal } from './crypto.js';
2
+ import { CoValue, getAgent, getAgentID, getAgentCoValueHeader, newRandomAgentCredential, } from './coValue.js';
3
+ import { Team, expectTeamContent } from './permissions.js';
4
+ import { SyncManager } from './sync.js';
12
5
  export class LocalNode {
13
- coValues = {};
14
- agentCredential;
15
- agentID;
16
- ownSessionID;
17
- sync = new SyncManager(this);
18
- constructor(agentCredential, ownSessionID) {
19
- this.agentCredential = agentCredential;
20
- const agent = getAgent(agentCredential);
21
- const agentID = getAgentID(agent);
22
- this.agentID = agentID;
23
- this.ownSessionID = ownSessionID;
24
- const agentCoValue = new CoValue(getAgentCoValueHeader(agent), this);
25
- this.coValues[agentCoValue.id] = {
26
- state: "loaded",
27
- coValue: agentCoValue
28
- };
29
- }
30
- createCoValue(header) {
31
- const coValue = new CoValue(header, this);
32
- this.coValues[coValue.id] = { state: "loaded", coValue };
33
- void this.sync.syncCoValue(coValue);
34
- return coValue;
35
- }
36
- loadCoValue(id) {
37
- let entry = this.coValues[id];
38
- if (!entry) {
39
- entry = newLoadingState();
40
- this.coValues[id] = entry;
41
- this.sync.loadFromPeers(id);
42
- }
43
- if (entry.state === "loaded") {
44
- return Promise.resolve(entry.coValue);
6
+ constructor(agentCredential, ownSessionID) {
7
+ this.coValues = {};
8
+ this.sync = new SyncManager(this);
9
+ this.agentCredential = agentCredential;
10
+ const agent = getAgent(agentCredential);
11
+ const agentID = getAgentID(agent);
12
+ this.agentID = agentID;
13
+ this.ownSessionID = ownSessionID;
14
+ const agentCoValue = new CoValue(getAgentCoValueHeader(agent), this);
15
+ this.coValues[agentCoValue.id] = {
16
+ state: "loaded",
17
+ coValue: agentCoValue,
18
+ };
45
19
  }
46
- return entry.done;
47
- }
48
- async load(id) {
49
- return (await this.loadCoValue(id)).getCurrentContent();
50
- }
51
- expectCoValueLoaded(id, expectation) {
52
- const entry = this.coValues[id];
53
- if (!entry) {
54
- throw new Error(
55
- `${expectation ? expectation + ": " : ""}Unknown CoValue ${id}`
56
- );
20
+ createCoValue(header) {
21
+ const coValue = new CoValue(header, this);
22
+ this.coValues[coValue.id] = { state: "loaded", coValue: coValue };
23
+ void this.sync.syncCoValue(coValue);
24
+ return coValue;
57
25
  }
58
- if (entry.state === "loading") {
59
- throw new Error(
60
- `${expectation ? expectation + ": " : ""}CoValue ${id} not yet loaded`
61
- );
26
+ loadCoValue(id) {
27
+ let entry = this.coValues[id];
28
+ if (!entry) {
29
+ entry = newLoadingState();
30
+ this.coValues[id] = entry;
31
+ this.sync.loadFromPeers(id);
32
+ }
33
+ if (entry.state === "loaded") {
34
+ return Promise.resolve(entry.coValue);
35
+ }
36
+ return entry.done;
62
37
  }
63
- return entry.coValue;
64
- }
65
- createAgent(publicNickname) {
66
- const agentCredential = newRandomAgentCredential(publicNickname);
67
- this.createCoValue(getAgentCoValueHeader(getAgent(agentCredential)));
68
- return agentCredential;
69
- }
70
- expectAgentLoaded(id, expectation) {
71
- var _a;
72
- const coValue = this.expectCoValueLoaded(
73
- id,
74
- expectation
75
- );
76
- if (coValue.header.type !== "comap" || coValue.header.ruleset.type !== "agent") {
77
- throw new Error(
78
- `${expectation ? expectation + ": " : ""}CoValue ${id} is not an agent`
79
- );
38
+ async load(id) {
39
+ return (await this.loadCoValue(id)).getCurrentContent();
80
40
  }
81
- return {
82
- recipientID: coValue.header.ruleset.initialRecipientID,
83
- signatoryID: coValue.header.ruleset.initialSignatoryID,
84
- publicNickname: (_a = coValue.header.publicNickname) == null ? void 0 : _a.replace("agent-", "")
85
- };
86
- }
87
- createTeam() {
88
- const teamCoValue = this.createCoValue({
89
- type: "comap",
90
- ruleset: { type: "team", initialAdmin: this.agentID },
91
- meta: null,
92
- ...createdNowUnique(),
93
- publicNickname: "team"
94
- });
95
- let teamContent = expectTeamContent(teamCoValue.getCurrentContent());
96
- teamContent = teamContent.edit((editable) => {
97
- editable.set(this.agentID, "admin", "trusting");
98
- const readKey = newRandomKeySecret();
99
- const revelation = seal(
100
- readKey.secret,
101
- this.agentCredential.recipientSecret,
102
- /* @__PURE__ */ new Set([getAgent(this.agentCredential).recipientID]),
103
- {
104
- in: teamCoValue.id,
105
- tx: teamCoValue.nextTransactionID()
41
+ expectCoValueLoaded(id, expectation) {
42
+ const entry = this.coValues[id];
43
+ if (!entry) {
44
+ throw new Error(`${expectation ? expectation + ": " : ""}Unknown CoValue ${id}`);
106
45
  }
107
- );
108
- editable.set(
109
- "readKey",
110
- { keyID: readKey.id, revelation },
111
- "trusting"
112
- );
113
- });
114
- return new Team(teamContent, this);
115
- }
116
- testWithDifferentCredentials(agentCredential, ownSessionID) {
117
- const newNode = new LocalNode(agentCredential, ownSessionID);
118
- newNode.coValues = Object.fromEntries(
119
- Object.entries(this.coValues).map(([id, entry]) => {
120
46
  if (entry.state === "loading") {
121
- return void 0;
47
+ throw new Error(`${expectation ? expectation + ": " : ""}CoValue ${id} not yet loaded`);
122
48
  }
123
- const newCoValue = new CoValue(
124
- entry.coValue.header,
125
- newNode
126
- );
127
- newCoValue.sessions = entry.coValue.sessions;
128
- return [id, { state: "loaded", coValue: newCoValue }];
129
- }).filter((x) => !!x)
130
- );
131
- return newNode;
132
- }
49
+ return entry.coValue;
50
+ }
51
+ createAgent(publicNickname) {
52
+ const agentCredential = newRandomAgentCredential(publicNickname);
53
+ this.createCoValue(getAgentCoValueHeader(getAgent(agentCredential)));
54
+ return agentCredential;
55
+ }
56
+ expectAgentLoaded(id, expectation) {
57
+ const coValue = this.expectCoValueLoaded(id, expectation);
58
+ if (coValue.header.type !== "comap" || coValue.header.ruleset.type !== "agent") {
59
+ throw new Error(`${expectation ? expectation + ": " : ""}CoValue ${id} is not an agent`);
60
+ }
61
+ return {
62
+ recipientID: coValue.header.ruleset.initialRecipientID,
63
+ signatoryID: coValue.header.ruleset.initialSignatoryID,
64
+ publicNickname: coValue.header.publicNickname?.replace("agent-", ""),
65
+ };
66
+ }
67
+ createTeam() {
68
+ const teamCoValue = this.createCoValue({
69
+ type: "comap",
70
+ ruleset: { type: "team", initialAdmin: this.agentID },
71
+ meta: null,
72
+ ...createdNowUnique(),
73
+ publicNickname: "team",
74
+ });
75
+ let teamContent = expectTeamContent(teamCoValue.getCurrentContent());
76
+ teamContent = teamContent.edit((editable) => {
77
+ editable.set(this.agentID, "admin", "trusting");
78
+ const readKey = newRandomKeySecret();
79
+ const revelation = seal(readKey.secret, this.agentCredential.recipientSecret, new Set([getAgent(this.agentCredential).recipientID]), {
80
+ in: teamCoValue.id,
81
+ tx: teamCoValue.nextTransactionID(),
82
+ });
83
+ editable.set("readKey", { keyID: readKey.id, revelation }, "trusting");
84
+ });
85
+ return new Team(teamContent, this);
86
+ }
87
+ testWithDifferentCredentials(agentCredential, ownSessionID) {
88
+ const newNode = new LocalNode(agentCredential, ownSessionID);
89
+ newNode.coValues = Object.fromEntries(Object.entries(this.coValues)
90
+ .map(([id, entry]) => {
91
+ if (entry.state === "loading") {
92
+ return undefined;
93
+ }
94
+ const newCoValue = new CoValue(entry.coValue.header, newNode);
95
+ newCoValue.sessions = entry.coValue.sessions;
96
+ return [id, { state: "loaded", coValue: newCoValue }];
97
+ })
98
+ .filter((x) => !!x));
99
+ return newNode;
100
+ }
133
101
  }
134
102
  export function newLoadingState() {
135
- let resolve;
136
- const promise = new Promise((r) => {
137
- resolve = r;
138
- });
139
- return {
140
- state: "loading",
141
- done: promise,
142
- resolve
143
- };
103
+ let resolve;
104
+ const promise = new Promise((r) => {
105
+ resolve = r;
106
+ });
107
+ return {
108
+ state: "loading",
109
+ done: promise,
110
+ resolve: resolve,
111
+ };
144
112
  }
113
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EACH,OAAO,EAGP,QAAQ,EACR,UAAU,EACV,qBAAqB,EAErB,wBAAwB,GAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAIxC,MAAM,OAAO,SAAS;IAOlB,YAAY,eAAgC,EAAE,YAAuB;QANrE,aAAQ,GAA0C,EAAE,CAAC;QAIrD,SAAI,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;QAGzB,IAAI,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AI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,4BAA4B,CACxB,eAAgC,EAChC,YAAuB;QAEvB,MAAM,OAAO,GAAG,IAAI,SAAS,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAE7D,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;aACxB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE;YACjB,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC3B,OAAO,SAAS,CAAC;aACpB;YAED,MAAM,UAAU,GAAG,IAAI,OAAO,CAC1B,KAAK,CAAC,OAAO,CAAC,MAAM,EACpB,OAAO,CACV,CAAC;YAEF,UAAU,CAAC,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YAE7C,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QAC1D,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAqC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAC7D,CAAC;QAEF,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAUD,MAAM,UAAU,eAAe;IAC3B,IAAI,OAAmC,CAAC;IAExC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAU,CAAC,CAAC,EAAE,EAAE;QACvC,OAAO,GAAG,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,OAAO;QACH,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,OAAQ;KACpB,CAAC;AACN,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { ContentType } from './contentType.js';
2
+ import { CoMap } from './contentTypes/coMap.js';
3
+ import { JsonValue } from './jsonValue.js';
4
+ import { Encrypted, KeyID, KeySecret, RecipientID, SealedSet, SignatoryID } from './crypto.js';
5
+ import { AgentCredential, CoValue, Transaction } from './coValue.js';
6
+ import { LocalNode } from "./node.js";
7
+ import { AgentID, RawCoValueID, SessionID, TransactionID } from './ids.js';
8
+ export type PermissionsDef = {
9
+ type: "team";
10
+ initialAdmin: AgentID;
11
+ parentTeams?: RawCoValueID[];
12
+ } | {
13
+ type: "ownedByTeam";
14
+ team: RawCoValueID;
15
+ } | {
16
+ type: "agent";
17
+ initialSignatoryID: SignatoryID;
18
+ initialRecipientID: RecipientID;
19
+ } | {
20
+ type: "unsafeAllowAll";
21
+ };
22
+ export type Role = "reader" | "writer" | "admin" | "revoked";
23
+ export declare function determineValidTransactions(coValue: CoValue): {
24
+ txID: TransactionID;
25
+ tx: Transaction;
26
+ }[];
27
+ export type TeamContent = {
28
+ [key: AgentID]: Role;
29
+ } & {
30
+ readKey: {
31
+ keyID: KeyID;
32
+ revelation: SealedSet<KeySecret>;
33
+ previousKeys?: {
34
+ [key: KeyID]: Encrypted<KeySecret, {
35
+ sealed: KeyID;
36
+ sealing: KeyID;
37
+ }>;
38
+ };
39
+ };
40
+ };
41
+ export declare function expectTeamContent(content: ContentType): CoMap<TeamContent, {}>;
42
+ export declare class Team {
43
+ teamMap: CoMap<TeamContent, {}>;
44
+ node: LocalNode;
45
+ constructor(teamMap: CoMap<TeamContent, {}>, node: LocalNode);
46
+ get id(): RawCoValueID;
47
+ addMember(agentID: AgentID, role: Role): void;
48
+ rotateReadKey(): void;
49
+ removeMember(agentID: AgentID): void;
50
+ createMap<M extends {
51
+ [key: string]: JsonValue;
52
+ }, Meta extends JsonValue>(meta?: M): CoMap<M, Meta>;
53
+ testWithDifferentCredentials(credential: AgentCredential, sessionId: SessionID): Team;
54
+ }