cojson 0.1.9 → 0.1.11
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.
- package/dist/account.d.ts +2 -1
- package/dist/account.js.map +1 -1
- package/dist/base64url.d.ts +2 -0
- package/dist/base64url.js +46 -0
- package/dist/base64url.js.map +1 -0
- package/dist/coValue.d.ts +4 -3
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore.d.ts +3 -0
- package/dist/coValueCore.js +21 -9
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/coList.d.ts +2 -1
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coStream.d.ts +60 -5
- package/dist/coValues/coStream.js +111 -1
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/crypto.js +6 -5
- package/dist/crypto.js.map +1 -1
- package/dist/group.d.ts +3 -0
- package/dist/group.js +26 -0
- package/dist/group.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/account.ts +2 -1
- package/src/base64url.test.ts +32 -0
- package/src/base64url.ts +58 -0
- package/src/coValue.test.ts +104 -1
- package/src/coValue.ts +4 -2
- package/src/coValueCore.test.ts +1 -2
- package/src/coValueCore.ts +25 -14
- package/src/coValues/coList.ts +2 -2
- package/src/coValues/coStream.ts +224 -7
- package/src/crypto.ts +13 -7
- package/src/group.test.ts +47 -0
- package/src/group.ts +33 -0
- package/src/index.ts +16 -0
- package/src/node.ts +1 -1
package/dist/group.js
CHANGED
|
@@ -163,6 +163,32 @@ export class Group {
|
|
|
163
163
|
})
|
|
164
164
|
.getCurrentContent();
|
|
165
165
|
}
|
|
166
|
+
createStream(meta) {
|
|
167
|
+
return this.node
|
|
168
|
+
.createCoValue({
|
|
169
|
+
type: "costream",
|
|
170
|
+
ruleset: {
|
|
171
|
+
type: "ownedByGroup",
|
|
172
|
+
group: this.underlyingMap.id,
|
|
173
|
+
},
|
|
174
|
+
meta: meta || null,
|
|
175
|
+
...createdNowUnique(),
|
|
176
|
+
})
|
|
177
|
+
.getCurrentContent();
|
|
178
|
+
}
|
|
179
|
+
createBinaryStream(meta = { type: "binary" }) {
|
|
180
|
+
return this.node
|
|
181
|
+
.createCoValue({
|
|
182
|
+
type: "costream",
|
|
183
|
+
ruleset: {
|
|
184
|
+
type: "ownedByGroup",
|
|
185
|
+
group: this.underlyingMap.id,
|
|
186
|
+
},
|
|
187
|
+
meta: meta,
|
|
188
|
+
...createdNowUnique(),
|
|
189
|
+
})
|
|
190
|
+
.getCurrentContent();
|
|
191
|
+
}
|
|
166
192
|
/** @internal */
|
|
167
193
|
testWithDifferentAccount(account, sessionId) {
|
|
168
194
|
return new Group(expectGroupContent(this.underlyingMap.core
|
package/dist/group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.js","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAGA,OAAO,EAIH,gBAAgB,EAChB,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAEhB,mBAAmB,EACnB,yBAAyB,EACzB,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAsB,SAAS,EAAE,MAAM,UAAU,CAAC;AAGzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAGA,OAAO,EAIH,gBAAgB,EAChB,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAEhB,mBAAmB,EACnB,yBAAyB,EACzB,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAsB,SAAS,EAAE,MAAM,UAAU,CAAC;AAGzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAerC,MAAM,UAAU,kBAAkB,CAC9B,OAAoB;IAEpB,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,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5C;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,13 +3,16 @@ import { LocalNode } from "./node.js";
|
|
|
3
3
|
import type { CoValue, ReadableCoValue } from "./coValue.js";
|
|
4
4
|
import { CoMap, WriteableCoMap } from "./coValues/coMap.js";
|
|
5
5
|
import { CoList, WriteableCoList } from "./coValues/coList.js";
|
|
6
|
+
import { CoStream, WriteableCoStream, BinaryCoStream, WriteableBinaryCoStream } from "./coValues/coStream.js";
|
|
6
7
|
import { agentSecretFromBytes, agentSecretToBytes, getAgentID, newRandomAgentSecret, newRandomSecretSeed, agentSecretFromSecretSeed } from "./crypto.js";
|
|
7
8
|
import { connectedPeers } from "./streamUtils.js";
|
|
8
9
|
import { AnonymousControlledAccount, ControlledAccount } from "./account.js";
|
|
9
10
|
import { rawCoIDtoBytes, rawCoIDfromBytes } from "./ids.js";
|
|
10
11
|
import { Group, expectGroupContent } from "./group.js";
|
|
12
|
+
import { base64URLtoBytes, bytesToBase64url } from "./base64url.js";
|
|
11
13
|
import type { SessionID, AgentID } from "./ids.js";
|
|
12
14
|
import type { CoID, CoValueImpl } from "./coValue.js";
|
|
15
|
+
import type { BinaryChunkInfo, BinaryCoStreamMeta } from "./coValues/coStream.js";
|
|
13
16
|
import type { JsonValue } from "./jsonValue.js";
|
|
14
17
|
import type { SyncMessage, Peer } from "./sync.js";
|
|
15
18
|
import type { AgentSecret } from "./crypto.js";
|
|
@@ -31,9 +34,11 @@ export declare const cojsonInternals: {
|
|
|
31
34
|
secretSeedLength: number;
|
|
32
35
|
shortHashLength: number;
|
|
33
36
|
expectGroupContent: typeof expectGroupContent;
|
|
37
|
+
base64URLtoBytes: typeof base64URLtoBytes;
|
|
38
|
+
bytesToBase64url: typeof bytesToBase64url;
|
|
34
39
|
};
|
|
35
|
-
export { LocalNode, Group, CoMap, WriteableCoMap, CoList, WriteableCoList, CoValueCore, AnonymousControlledAccount, ControlledAccount, };
|
|
36
|
-
export type { Value, JsonValue, CoValue, ReadableCoValue, CoValueImpl, CoID, AccountID, Profile, SessionID, Peer, AgentID, AgentSecret, InviteSecret, SyncMessage, };
|
|
40
|
+
export { LocalNode, Group, CoMap, WriteableCoMap, CoList, WriteableCoList, CoStream, WriteableCoStream, BinaryCoStream, WriteableBinaryCoStream, CoValueCore, AnonymousControlledAccount, ControlledAccount, };
|
|
41
|
+
export type { Value, JsonValue, CoValue, ReadableCoValue, CoValueImpl, CoID, AccountID, Profile, SessionID, Peer, BinaryChunkInfo, BinaryCoStreamMeta, AgentID, AgentSecret, InviteSecret, SyncMessage, };
|
|
37
42
|
export declare namespace CojsonInternalTypes {
|
|
38
43
|
type CoValueKnownState = import("./sync.js").CoValueKnownState;
|
|
39
44
|
type DoneMessage = import("./sync.js").DoneMessage;
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,13 @@ import { CoValueCore, newRandomSessionID } from "./coValueCore.js";
|
|
|
2
2
|
import { LocalNode } from "./node.js";
|
|
3
3
|
import { CoMap, WriteableCoMap } from "./coValues/coMap.js";
|
|
4
4
|
import { CoList, WriteableCoList } from "./coValues/coList.js";
|
|
5
|
+
import { CoStream, WriteableCoStream, BinaryCoStream, WriteableBinaryCoStream, } from "./coValues/coStream.js";
|
|
5
6
|
import { agentSecretFromBytes, agentSecretToBytes, getAgentID, newRandomAgentSecret, newRandomSecretSeed, agentSecretFromSecretSeed, secretSeedLength, shortHashLength, } from "./crypto.js";
|
|
6
7
|
import { connectedPeers } from "./streamUtils.js";
|
|
7
8
|
import { AnonymousControlledAccount, ControlledAccount } from "./account.js";
|
|
8
9
|
import { rawCoIDtoBytes, rawCoIDfromBytes } from "./ids.js";
|
|
9
10
|
import { Group, expectGroupContent } from "./group.js";
|
|
11
|
+
import { base64URLtoBytes, bytesToBase64url } from "./base64url.js";
|
|
10
12
|
/** @hidden */
|
|
11
13
|
export const cojsonInternals = {
|
|
12
14
|
agentSecretFromBytes,
|
|
@@ -22,6 +24,8 @@ export const cojsonInternals = {
|
|
|
22
24
|
secretSeedLength,
|
|
23
25
|
shortHashLength,
|
|
24
26
|
expectGroupContent,
|
|
27
|
+
base64URLtoBytes,
|
|
28
|
+
bytesToBase64url
|
|
25
29
|
};
|
|
26
|
-
export { LocalNode, Group, CoMap, WriteableCoMap, CoList, WriteableCoList, CoValueCore, AnonymousControlledAccount, ControlledAccount, };
|
|
30
|
+
export { LocalNode, Group, CoMap, WriteableCoMap, CoList, WriteableCoList, CoStream, WriteableCoStream, BinaryCoStream, WriteableBinaryCoStream, CoValueCore, AnonymousControlledAccount, ControlledAccount, };
|
|
27
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EACH,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,gBAAgB,EAChB,eAAe,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"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AAW,EACX,0BAA0B,EAC1B,iBAAiB,GACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "0.1.
|
|
8
|
+
"version": "0.1.11",
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/jest": "^29.5.3",
|
|
11
11
|
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"/dist/"
|
|
53
53
|
]
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "92eae0e1803850c0a68420e0e2f0dd6190b12bb5"
|
|
56
56
|
}
|
package/src/account.ts
CHANGED
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
getAgentSignerSecret,
|
|
14
14
|
} from "./crypto.js";
|
|
15
15
|
import { AgentID } from "./ids.js";
|
|
16
|
-
import { CoMap
|
|
16
|
+
import { CoMap } from "./coValues/coMap.js";
|
|
17
|
+
import { LocalNode } from "./node.js";
|
|
17
18
|
import { Group, GroupContent } from "./group.js";
|
|
18
19
|
|
|
19
20
|
export function accountHeaderForInitialAgentSecret(
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { base64URLtoBytes, bytesToBase64url } from "./base64url";
|
|
2
|
+
|
|
3
|
+
const txt = new TextEncoder();
|
|
4
|
+
|
|
5
|
+
test("Test our Base64 URL encoding and decoding", () => {
|
|
6
|
+
// tests from the RFC
|
|
7
|
+
|
|
8
|
+
expect(base64URLtoBytes("")).toEqual(new Uint8Array([]));
|
|
9
|
+
expect(bytesToBase64url(new Uint8Array([]))).toEqual("");
|
|
10
|
+
|
|
11
|
+
expect(bytesToBase64url(txt.encode("f"))).toEqual("Zg==");
|
|
12
|
+
expect(bytesToBase64url(txt.encode("fo"))).toEqual("Zm8=");
|
|
13
|
+
expect(bytesToBase64url(txt.encode("foo"))).toEqual("Zm9v");
|
|
14
|
+
expect(bytesToBase64url(txt.encode("foob"))).toEqual("Zm9vYg==");
|
|
15
|
+
expect(bytesToBase64url(txt.encode("fooba"))).toEqual("Zm9vYmE=");
|
|
16
|
+
expect(bytesToBase64url(txt.encode("foobar"))).toEqual("Zm9vYmFy");
|
|
17
|
+
// reverse
|
|
18
|
+
expect(base64URLtoBytes("Zg==")).toEqual(txt.encode("f"));
|
|
19
|
+
expect(base64URLtoBytes("Zm8=")).toEqual(txt.encode("fo"));
|
|
20
|
+
expect(base64URLtoBytes("Zm9v")).toEqual(txt.encode("foo"));
|
|
21
|
+
expect(base64URLtoBytes("Zm9vYg==")).toEqual(txt.encode("foob"));
|
|
22
|
+
expect(base64URLtoBytes("Zm9vYmE=")).toEqual(txt.encode("fooba"));
|
|
23
|
+
expect(base64URLtoBytes("Zm9vYmFy")).toEqual(txt.encode("foobar"));
|
|
24
|
+
|
|
25
|
+
expect(base64URLtoBytes("V2hhdCBkb2VzIDIgKyAyLjEgZXF1YWw_PyB-IDQ=")).toEqual(
|
|
26
|
+
txt.encode("What does 2 + 2.1 equal?? ~ 4")
|
|
27
|
+
);
|
|
28
|
+
// reverse
|
|
29
|
+
expect(
|
|
30
|
+
bytesToBase64url(txt.encode("What does 2 + 2.1 equal?? ~ 4"))
|
|
31
|
+
).toEqual("V2hhdCBkb2VzIDIgKyAyLjEgZXF1YWw_PyB-IDQ=");
|
|
32
|
+
});
|
package/src/base64url.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const encoder = new TextEncoder();
|
|
2
|
+
const decoder = new TextDecoder();
|
|
3
|
+
|
|
4
|
+
export function base64URLtoBytes(base64: string) {
|
|
5
|
+
base64 = base64.replace(/=/g, "");
|
|
6
|
+
const n = base64.length;
|
|
7
|
+
const rem = n % 4;
|
|
8
|
+
const k = rem && rem - 1; // how many bytes the last base64 chunk encodes
|
|
9
|
+
const m = (n >> 2) * 3 + k; // total encoded bytes
|
|
10
|
+
|
|
11
|
+
const encoded = new Uint8Array(n + 3);
|
|
12
|
+
encoder.encodeInto(base64 + "===", encoded);
|
|
13
|
+
|
|
14
|
+
for (let i = 0, j = 0; i < n; i += 4, j += 3) {
|
|
15
|
+
const x =
|
|
16
|
+
(lookup[encoded[i]!]! << 18) +
|
|
17
|
+
(lookup[encoded[i + 1]!]! << 12) +
|
|
18
|
+
(lookup[encoded[i + 2]!]! << 6) +
|
|
19
|
+
lookup[encoded[i + 3]!]!;
|
|
20
|
+
encoded[j] = x >> 16;
|
|
21
|
+
encoded[j + 1] = (x >> 8) & 0xff;
|
|
22
|
+
encoded[j + 2] = x & 0xff;
|
|
23
|
+
}
|
|
24
|
+
return new Uint8Array(encoded.buffer, 0, m);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function bytesToBase64url(bytes: Uint8Array) {
|
|
28
|
+
const m = bytes.length;
|
|
29
|
+
const k = m % 3;
|
|
30
|
+
const n = Math.floor(m / 3) * 4 + (k && k + 1);
|
|
31
|
+
const N = Math.ceil(m / 3) * 4;
|
|
32
|
+
const encoded = new Uint8Array(N);
|
|
33
|
+
|
|
34
|
+
for (let i = 0, j = 0; j < m; i += 4, j += 3) {
|
|
35
|
+
const y =
|
|
36
|
+
(bytes[j]! << 16) + (bytes[j + 1]! << 8) + (bytes[j + 2]! | 0);
|
|
37
|
+
encoded[i] = encodeLookup[y >> 18]!;
|
|
38
|
+
encoded[i + 1] = encodeLookup[(y >> 12) & 0x3f]!;
|
|
39
|
+
encoded[i + 2] = encodeLookup[(y >> 6) & 0x3f]!;
|
|
40
|
+
encoded[i + 3] = encodeLookup[y & 0x3f]!;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let base64 = decoder.decode(new Uint8Array(encoded.buffer, 0, n));
|
|
44
|
+
if (k === 1) base64 += "==";
|
|
45
|
+
if (k === 2) base64 += "=";
|
|
46
|
+
return base64;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const alphabet =
|
|
50
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
51
|
+
const lookup = Object.fromEntries(
|
|
52
|
+
Array.from(alphabet).map((a, i) => [a.charCodeAt(0), i])
|
|
53
|
+
);
|
|
54
|
+
lookup["=".charCodeAt(0)] = 0;
|
|
55
|
+
|
|
56
|
+
const encodeLookup = Object.fromEntries(
|
|
57
|
+
Array.from(alphabet).map((a, i) => [i, a.charCodeAt(0)])
|
|
58
|
+
);
|
package/src/coValue.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { accountOrAgentIDfromSessionID } from "./coValueCore.js";
|
|
2
|
+
import { BinaryCoStream } from "./coValues/coStream.js";
|
|
2
3
|
import { createdNowUnique } from "./crypto.js";
|
|
3
4
|
import { LocalNode } from "./node.js";
|
|
4
5
|
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
@@ -281,4 +282,106 @@ test("Can push into empty list", () => {
|
|
|
281
282
|
editable.push("hello", "trusting");
|
|
282
283
|
expect(editable.toJSON()).toEqual(["hello"]);
|
|
283
284
|
});
|
|
284
|
-
})
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test("Empty CoStream works", () => {
|
|
288
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID());
|
|
289
|
+
|
|
290
|
+
const coValue = node.createCoValue({
|
|
291
|
+
type: "costream",
|
|
292
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
293
|
+
meta: null,
|
|
294
|
+
...createdNowUnique(),
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const content = coValue.getCurrentContent();
|
|
298
|
+
|
|
299
|
+
if (content.type !== "costream") {
|
|
300
|
+
throw new Error("Expected stream");
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
expect(content.type).toEqual("costream");
|
|
304
|
+
expect(content.toJSON()).toEqual({});
|
|
305
|
+
expect(content.getSingleStream()).toEqual(undefined);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test("Can push into CoStream", () => {
|
|
309
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID());
|
|
310
|
+
|
|
311
|
+
const coValue = node.createCoValue({
|
|
312
|
+
type: "costream",
|
|
313
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
314
|
+
meta: null,
|
|
315
|
+
...createdNowUnique(),
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const content = coValue.getCurrentContent();
|
|
319
|
+
|
|
320
|
+
if (content.type !== "costream") {
|
|
321
|
+
throw new Error("Expected stream");
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
content.edit((editable) => {
|
|
325
|
+
editable.push({ hello: "world" }, "trusting");
|
|
326
|
+
expect(editable.toJSON()).toEqual({
|
|
327
|
+
[node.currentSessionID]: [{ hello: "world" }],
|
|
328
|
+
});
|
|
329
|
+
editable.push({ foo: "bar" }, "trusting");
|
|
330
|
+
expect(editable.toJSON()).toEqual({
|
|
331
|
+
[node.currentSessionID]: [{ hello: "world" }, { foo: "bar" }],
|
|
332
|
+
});
|
|
333
|
+
expect(editable.getSingleStream()).toEqual([
|
|
334
|
+
{ hello: "world" },
|
|
335
|
+
{ foo: "bar" },
|
|
336
|
+
]);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("Empty BinaryCoStream works", () => {
|
|
341
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID());
|
|
342
|
+
|
|
343
|
+
const coValue = node.createCoValue({
|
|
344
|
+
type: "costream",
|
|
345
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
346
|
+
meta: { type: "binary" },
|
|
347
|
+
...createdNowUnique(),
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const content = coValue.getCurrentContent();
|
|
351
|
+
|
|
352
|
+
if (content.type !== "costream" || content.meta?.type !== "binary" || !(content instanceof BinaryCoStream)) {
|
|
353
|
+
throw new Error("Expected binary stream");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
expect(content.type).toEqual("costream");
|
|
357
|
+
expect(content.meta.type).toEqual("binary");
|
|
358
|
+
expect(content.toJSON()).toEqual({});
|
|
359
|
+
expect(content.getBinaryChunks()).toEqual(undefined);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
test("Can push into BinaryCoStream", () => {
|
|
363
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID());
|
|
364
|
+
|
|
365
|
+
const coValue = node.createCoValue({
|
|
366
|
+
type: "costream",
|
|
367
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
368
|
+
meta: { type: "binary" },
|
|
369
|
+
...createdNowUnique(),
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
const content = coValue.getCurrentContent();
|
|
373
|
+
|
|
374
|
+
if (content.type !== "costream" || content.meta?.type !== "binary" || !(content instanceof BinaryCoStream)) {
|
|
375
|
+
throw new Error("Expected binary stream");
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
content.edit((editable) => {
|
|
379
|
+
editable.startBinaryStream({mimeType: "text/plain", fileName: "test.txt"}, "trusting");
|
|
380
|
+
expect(editable.getBinaryChunks()).toEqual({
|
|
381
|
+
mimeType: "text/plain",
|
|
382
|
+
fileName: "test.txt",
|
|
383
|
+
chunks: [],
|
|
384
|
+
finished: false,
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
package/src/coValue.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from "./jsonValue.js";
|
|
2
2
|
import { RawCoID } from "./ids.js";
|
|
3
3
|
import { CoMap } from "./coValues/coMap.js";
|
|
4
|
-
import { CoStream } from "./coValues/coStream.js";
|
|
4
|
+
import { BinaryCoStream, BinaryCoStreamMeta, CoStream } from "./coValues/coStream.js";
|
|
5
5
|
import { Static } from "./coValues/static.js";
|
|
6
6
|
import { CoList } from "./coValues/coList.js";
|
|
7
|
-
import { CoValueCore
|
|
7
|
+
import { CoValueCore } from "./coValueCore.js";
|
|
8
|
+
import { Group } from "./group.js";
|
|
8
9
|
|
|
9
10
|
export type CoID<T extends CoValueImpl> = RawCoID & {
|
|
10
11
|
readonly __type: T;
|
|
@@ -49,6 +50,7 @@ export type CoValueImpl =
|
|
|
49
50
|
| CoMap<{ [key: string]: JsonValue }, JsonObject | null>
|
|
50
51
|
| CoList<JsonValue, JsonObject | null>
|
|
51
52
|
| CoStream<JsonValue, JsonObject | null>
|
|
53
|
+
| BinaryCoStream<BinaryCoStreamMeta>
|
|
52
54
|
| Static<JsonObject>;
|
|
53
55
|
|
|
54
56
|
export function expectMap(
|
package/src/coValueCore.test.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { Transaction } from "./coValueCore.js";
|
|
|
2
2
|
import { LocalNode } from "./node.js";
|
|
3
3
|
import { createdNowUnique, getAgentSignerSecret, newRandomAgentSecret, sign } from "./crypto.js";
|
|
4
4
|
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
5
|
-
import {
|
|
6
|
-
import { AccountID } from "./index.js";
|
|
5
|
+
import { MapOpPayload } from "./coValues/coMap.js";
|
|
7
6
|
import { Role } from "./permissions.js";
|
|
8
7
|
|
|
9
8
|
test("Can create coValue with new agent credentials and add transaction to it", () => {
|
package/src/coValueCore.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "@noble/hashes/utils";
|
|
2
2
|
import { CoValueImpl } from "./coValue.js";
|
|
3
3
|
import { Static } from "./coValues/static.js";
|
|
4
|
-
import { CoStream } from "./coValues/coStream.js";
|
|
4
|
+
import { BinaryCoStream, CoStream } from "./coValues/coStream.js";
|
|
5
5
|
import { CoMap } from "./coValues/coMap.js";
|
|
6
6
|
import {
|
|
7
7
|
Encrypted,
|
|
@@ -100,6 +100,7 @@ export class CoValueCore {
|
|
|
100
100
|
_sessions: { [key: SessionID]: SessionLog };
|
|
101
101
|
_cachedContent?: CoValueImpl;
|
|
102
102
|
listeners: Set<(content?: CoValueImpl) => void> = new Set();
|
|
103
|
+
_decryptionCache: {[key: Encrypted<JsonValue[], JsonValue>]: JsonValue[] | undefined} = {}
|
|
103
104
|
|
|
104
105
|
constructor(
|
|
105
106
|
header: CoValueHeader,
|
|
@@ -222,10 +223,11 @@ export class CoValueCore {
|
|
|
222
223
|
|
|
223
224
|
this._cachedContent = undefined;
|
|
224
225
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
if (this.listeners.size > 0) {
|
|
227
|
+
const content = this.getCurrentContent();
|
|
228
|
+
for (const listener of this.listeners) {
|
|
229
|
+
listener(content);
|
|
230
|
+
}
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
return true;
|
|
@@ -328,7 +330,11 @@ export class CoValueCore {
|
|
|
328
330
|
} else if (this.header.type === "colist") {
|
|
329
331
|
this._cachedContent = new CoList(this);
|
|
330
332
|
} else if (this.header.type === "costream") {
|
|
331
|
-
this.
|
|
333
|
+
if (this.header.meta && this.header.meta.type === "binary") {
|
|
334
|
+
this._cachedContent = new BinaryCoStream(this);
|
|
335
|
+
} else {
|
|
336
|
+
this._cachedContent = new CoStream(this);
|
|
337
|
+
}
|
|
332
338
|
} else if (this.header.type === "static") {
|
|
333
339
|
this._cachedContent = new Static(this);
|
|
334
340
|
} else {
|
|
@@ -355,14 +361,19 @@ export class CoValueCore {
|
|
|
355
361
|
if (!readKey) {
|
|
356
362
|
return undefined;
|
|
357
363
|
} else {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
let decrytedChanges = this._decryptionCache[tx.encryptedChanges];
|
|
365
|
+
|
|
366
|
+
if (!decrytedChanges) {
|
|
367
|
+
decrytedChanges = decryptForTransaction(
|
|
368
|
+
tx.encryptedChanges,
|
|
369
|
+
readKey,
|
|
370
|
+
{
|
|
371
|
+
in: this.id,
|
|
372
|
+
tx: txID,
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
this._decryptionCache[tx.encryptedChanges] = decrytedChanges;
|
|
376
|
+
}
|
|
366
377
|
|
|
367
378
|
if (!decrytedChanges) {
|
|
368
379
|
console.error(
|
package/src/coValues/coList.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { JsonObject, JsonValue } from "../jsonValue.js";
|
|
|
2
2
|
import { CoID, ReadableCoValue, WriteableCoValue } from "../coValue.js";
|
|
3
3
|
import { CoValueCore, accountOrAgentIDfromSessionID } from "../coValueCore.js";
|
|
4
4
|
import { SessionID, TransactionID } from "../ids.js";
|
|
5
|
-
import {
|
|
6
|
-
import { isAccountID } from "../account.js";
|
|
5
|
+
import { Group } from "../group.js";
|
|
6
|
+
import { AccountID, isAccountID } from "../account.js";
|
|
7
7
|
|
|
8
8
|
type OpID = TransactionID & { changeIdx: number };
|
|
9
9
|
|