cojson 0.17.8 → 0.17.10
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +13 -0
- package/dist/coValueCore/SessionMap.d.ts +44 -0
- package/dist/coValueCore/SessionMap.d.ts.map +1 -0
- package/dist/coValueCore/SessionMap.js +118 -0
- package/dist/coValueCore/SessionMap.js.map +1 -0
- package/dist/coValueCore/coValueCore.d.ts +1 -0
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +40 -61
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/coValueCore/verifiedState.d.ts +14 -18
- package/dist/coValueCore/verifiedState.d.ts.map +1 -1
- package/dist/coValueCore/verifiedState.js +23 -86
- package/dist/coValueCore/verifiedState.js.map +1 -1
- package/dist/coValues/account.d.ts +4 -0
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/account.js +24 -4
- package/dist/coValues/account.js.map +1 -1
- package/dist/crypto/PureJSCrypto.d.ts +31 -3
- package/dist/crypto/PureJSCrypto.d.ts.map +1 -1
- package/dist/crypto/PureJSCrypto.js +112 -0
- package/dist/crypto/PureJSCrypto.js.map +1 -1
- package/dist/crypto/WasmCrypto.d.ts +23 -4
- package/dist/crypto/WasmCrypto.d.ts.map +1 -1
- package/dist/crypto/WasmCrypto.js +44 -2
- package/dist/crypto/WasmCrypto.js.map +1 -1
- package/dist/crypto/crypto.d.ts +17 -1
- package/dist/crypto/crypto.d.ts.map +1 -1
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/localNode.d.ts +1 -0
- package/dist/localNode.d.ts.map +1 -1
- package/dist/localNode.js +10 -5
- package/dist/localNode.js.map +1 -1
- package/dist/sync.d.ts +2 -0
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +8 -1
- package/dist/sync.js.map +1 -1
- package/dist/tests/PureJSCrypto.test.d.ts +2 -0
- package/dist/tests/PureJSCrypto.test.d.ts.map +1 -0
- package/dist/tests/PureJSCrypto.test.js +88 -0
- package/dist/tests/PureJSCrypto.test.js.map +1 -0
- package/dist/tests/WasmCrypto.test.d.ts +2 -0
- package/dist/tests/WasmCrypto.test.d.ts.map +1 -0
- package/dist/tests/WasmCrypto.test.js +88 -0
- package/dist/tests/WasmCrypto.test.js.map +1 -0
- package/dist/tests/coValueCore.test.js +62 -187
- package/dist/tests/coValueCore.test.js.map +1 -1
- package/dist/tests/coreWasm.test.d.ts +2 -0
- package/dist/tests/coreWasm.test.d.ts.map +1 -0
- package/dist/tests/coreWasm.test.js +80 -0
- package/dist/tests/coreWasm.test.js.map +1 -0
- package/dist/tests/sync.test.js +19 -1
- package/dist/tests/sync.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts +3 -0
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js +4 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/package.json +3 -3
- package/src/coValueCore/SessionMap.ts +230 -0
- package/src/coValueCore/coValueCore.ts +66 -91
- package/src/coValueCore/verifiedState.ts +60 -129
- package/src/coValues/account.ts +28 -4
- package/src/crypto/PureJSCrypto.ts +202 -2
- package/src/crypto/WasmCrypto.ts +95 -4
- package/src/crypto/crypto.ts +38 -1
- package/src/localNode.ts +18 -10
- package/src/sync.ts +10 -0
- package/src/tests/PureJSCrypto.test.ts +130 -0
- package/src/tests/WasmCrypto.test.ts +130 -0
- package/src/tests/coValueCore.test.ts +84 -292
- package/src/tests/coreWasm.test.ts +142 -0
- package/src/tests/sync.test.ts +32 -0
- package/src/tests/testUtils.ts +9 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { assert, describe, expect, it } from "vitest";
|
|
2
|
+
import { WasmCrypto } from "../crypto/WasmCrypto";
|
|
3
|
+
import { JsonValue, LocalNode, SessionID } from "../exports";
|
|
4
|
+
import {
|
|
5
|
+
agentAndSessionIDFromSecret,
|
|
6
|
+
randomAgentAndSessionID,
|
|
7
|
+
} from "./testUtils";
|
|
8
|
+
import { PureJSCrypto } from "../crypto/PureJSCrypto";
|
|
9
|
+
import { Encrypted } from "../crypto/crypto";
|
|
10
|
+
import { PrivateTransaction } from "../coValueCore/verifiedState";
|
|
11
|
+
|
|
12
|
+
const wasmCrypto = await WasmCrypto.create();
|
|
13
|
+
const jsCrypto = await PureJSCrypto.create();
|
|
14
|
+
|
|
15
|
+
const agentSecret =
|
|
16
|
+
"sealerSecret_zE3Nr7YFr1KkVbJSx4JDCzYn4ApYdm8kJ5ghNBxREHQya/signerSecret_z9fEu4eNG1eXHMak3YSzY7uLdoG8HESSJ8YW4xWdNNDSP";
|
|
17
|
+
|
|
18
|
+
function createTestNode() {
|
|
19
|
+
const [agent, session] = agentAndSessionIDFromSecret(agentSecret);
|
|
20
|
+
return {
|
|
21
|
+
agent,
|
|
22
|
+
session,
|
|
23
|
+
node: new LocalNode(agent.agentSecret, session, jsCrypto),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("SessionLog WASM", () => {
|
|
28
|
+
it("it works", () => {
|
|
29
|
+
const [agent, sessionId] = agentAndSessionIDFromSecret(agentSecret);
|
|
30
|
+
|
|
31
|
+
const session = wasmCrypto.createSessionLog(
|
|
32
|
+
"co_test1" as any,
|
|
33
|
+
sessionId,
|
|
34
|
+
agent.currentSignerID(),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(session).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("test_add_from_example_json", () => {
|
|
41
|
+
const { agent, session, node } = createTestNode();
|
|
42
|
+
|
|
43
|
+
const group = node.createGroup();
|
|
44
|
+
const sessionContent =
|
|
45
|
+
group.core.verified.newContentSince(undefined)?.[0]?.new[session];
|
|
46
|
+
assert(sessionContent);
|
|
47
|
+
|
|
48
|
+
let log = wasmCrypto.createSessionLog(
|
|
49
|
+
group.id,
|
|
50
|
+
session,
|
|
51
|
+
agent.currentSignerID(),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
log.tryAdd(
|
|
55
|
+
sessionContent.newTransactions,
|
|
56
|
+
sessionContent.lastSignature,
|
|
57
|
+
false,
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("test_add_new_transaction", () => {
|
|
62
|
+
const { agent, session, node } = createTestNode();
|
|
63
|
+
|
|
64
|
+
const group = node.createGroup();
|
|
65
|
+
const sessionContent =
|
|
66
|
+
group.core.verified.newContentSince(undefined)?.[0]?.new[session];
|
|
67
|
+
assert(sessionContent);
|
|
68
|
+
|
|
69
|
+
let log = wasmCrypto.createSessionLog(
|
|
70
|
+
group.id,
|
|
71
|
+
session,
|
|
72
|
+
agent.currentSignerID(),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const changesJson = [
|
|
76
|
+
{ after: "start", op: "app", value: "co_zMphsnYN6GU8nn2HDY5suvyGufY" },
|
|
77
|
+
];
|
|
78
|
+
const key = group.getCurrentReadKey();
|
|
79
|
+
assert(key);
|
|
80
|
+
assert(key.secret);
|
|
81
|
+
|
|
82
|
+
const { signature, transaction } = log.addNewPrivateTransaction(
|
|
83
|
+
agent,
|
|
84
|
+
changesJson,
|
|
85
|
+
key.id,
|
|
86
|
+
key.secret,
|
|
87
|
+
0,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect(signature).toMatch(/^signature_z[a-zA-Z0-9]+$/);
|
|
91
|
+
expect(transaction).toEqual({
|
|
92
|
+
encryptedChanges: expect.stringMatching(/^encrypted_U/),
|
|
93
|
+
keyUsed: expect.stringMatching(/^key_z/),
|
|
94
|
+
madeAt: 0,
|
|
95
|
+
privacy: "private",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const decrypted = log.decryptNextTransactionChangesJson(0, key.secret);
|
|
99
|
+
|
|
100
|
+
expect(decrypted).toEqual(
|
|
101
|
+
'[{"after":"start","op":"app","value":"co_zMphsnYN6GU8nn2HDY5suvyGufY"}]',
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("test_decrypt + clone", () => {
|
|
106
|
+
const [agent] = agentAndSessionIDFromSecret(agentSecret);
|
|
107
|
+
const fixtures = {
|
|
108
|
+
id: "co_zWwrEiushQLvbkWd6Z3L8WxTU1r",
|
|
109
|
+
signature:
|
|
110
|
+
"signature_z3ktW7wxMnW7VYExCGZv4Ug2UJSW3ag6zLDiP8GpZThzif6veJt7JipYpUgshhuGbgHtLcWywWSWysV7hChxFypDt",
|
|
111
|
+
decrypted:
|
|
112
|
+
'[{"after":"start","op":"app","value":"co_zMphsnYN6GU8nn2HDY5suvyGufY"}]',
|
|
113
|
+
key: {
|
|
114
|
+
secret: "keySecret_z3dU66SsyQkkGKpNCJW6NX74MnfVGHUyY7r85b4M8X88L",
|
|
115
|
+
id: "key_z5XUAHyoqUV9zXWvMK",
|
|
116
|
+
},
|
|
117
|
+
transaction: {
|
|
118
|
+
privacy: "private",
|
|
119
|
+
madeAt: 0,
|
|
120
|
+
encryptedChanges:
|
|
121
|
+
"encrypted_UNAxqdUSGRZ2rzuLU99AFPKCe2C0HwsTzMWQreXZqLr6RpWrSMa-5lwgwIev7xPHTgZFq5UyUgMFrO9zlHJHJGgjJcDzFihY=" as any,
|
|
122
|
+
keyUsed: "key_z5XUAHyoqUV9zXWvMK",
|
|
123
|
+
},
|
|
124
|
+
session:
|
|
125
|
+
"sealer_z5yhsCCe2XwLTZC4254mUoMASshm3Diq49JrefPpjTktp/signer_z7gVGDpNz9qUtsRxAkHMuu4DYdtVVCG4XELTKPYdoYLPr_session_z9mDP8FoonSA",
|
|
126
|
+
} as const;
|
|
127
|
+
|
|
128
|
+
let log = wasmCrypto.createSessionLog(
|
|
129
|
+
fixtures.id,
|
|
130
|
+
fixtures.session,
|
|
131
|
+
agent.currentSignerID(),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
log.tryAdd([fixtures.transaction], fixtures.signature, true);
|
|
135
|
+
|
|
136
|
+
const decrypted = log
|
|
137
|
+
.clone()
|
|
138
|
+
.decryptNextTransactionChangesJson(0, fixtures.key.secret);
|
|
139
|
+
|
|
140
|
+
expect(decrypted).toEqual(fixtures.decrypted);
|
|
141
|
+
});
|
|
142
|
+
});
|
package/src/tests/sync.test.ts
CHANGED
|
@@ -20,11 +20,13 @@ import {
|
|
|
20
20
|
createTestNode,
|
|
21
21
|
loadCoValueOrFail,
|
|
22
22
|
nodeWithRandomAgentAndSessionID,
|
|
23
|
+
randomAgentAndSessionID,
|
|
23
24
|
setupTestAccount,
|
|
24
25
|
setupTestNode,
|
|
25
26
|
tearDownTestMetricReader,
|
|
26
27
|
waitFor,
|
|
27
28
|
} from "./testUtils.js";
|
|
29
|
+
import { stableStringify } from "../jsonStringify.js";
|
|
28
30
|
|
|
29
31
|
// We want to simulate a real world communication that happens asynchronously
|
|
30
32
|
TEST_NODE_CONFIG.withAsyncPeers = true;
|
|
@@ -160,6 +162,36 @@ test("should delete the peer state when the peer closes if persistent is false",
|
|
|
160
162
|
expect(syncManager.peers[peer.id]).toBeUndefined();
|
|
161
163
|
});
|
|
162
164
|
|
|
165
|
+
test("should not verify transactions when SyncManager has verification disabled", async () => {
|
|
166
|
+
jazzCloud.node.syncManager.disableTransactionVerification();
|
|
167
|
+
|
|
168
|
+
const [agent] = randomAgentAndSessionID();
|
|
169
|
+
const client = await setupTestAccount({ connected: true });
|
|
170
|
+
|
|
171
|
+
const group = client.node.createGroup();
|
|
172
|
+
const map = group.createMap();
|
|
173
|
+
|
|
174
|
+
map.core.tryAddTransactions(
|
|
175
|
+
client.node.currentSessionID,
|
|
176
|
+
[
|
|
177
|
+
{
|
|
178
|
+
privacy: "trusting",
|
|
179
|
+
changes: stableStringify([{ op: "set", key: "hello", value: "world" }]),
|
|
180
|
+
madeAt: Date.now(),
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
undefined,
|
|
184
|
+
Crypto.sign(agent.currentSignerSecret(), "hash_z12345678"),
|
|
185
|
+
"immediate",
|
|
186
|
+
true,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
await map.core.waitForSync();
|
|
190
|
+
|
|
191
|
+
const loadedMap = await loadCoValueOrFail(jazzCloud.node, map.id);
|
|
192
|
+
expect(loadedMap.get("hello")).toEqual("world");
|
|
193
|
+
});
|
|
194
|
+
|
|
163
195
|
describe("sync - extra tests", () => {
|
|
164
196
|
test("Node handles disconnection and reconnection of a peer gracefully", async () => {
|
|
165
197
|
// Create two nodes
|
package/src/tests/testUtils.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type AgentSecret,
|
|
13
13
|
type CoID,
|
|
14
14
|
type CoValueCore,
|
|
15
|
+
CryptoProvider,
|
|
15
16
|
type RawAccount,
|
|
16
17
|
type RawCoValue,
|
|
17
18
|
StorageAPI,
|
|
@@ -23,8 +24,15 @@ import type { Peer, SyncMessage } from "../sync.js";
|
|
|
23
24
|
import { expectGroup } from "../typeUtils/expectGroup.js";
|
|
24
25
|
import { toSimplifiedMessages } from "./messagesTestUtils.js";
|
|
25
26
|
import { createAsyncStorage, createSyncStorage } from "./testStorage.js";
|
|
27
|
+
import { PureJSCrypto } from "../crypto/PureJSCrypto.js";
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
let Crypto = await WasmCrypto.create();
|
|
30
|
+
|
|
31
|
+
export function setCurrentTestCryptoProvider(
|
|
32
|
+
crypto: WasmCrypto | PureJSCrypto,
|
|
33
|
+
) {
|
|
34
|
+
Crypto = crypto;
|
|
35
|
+
}
|
|
28
36
|
|
|
29
37
|
const syncServer: {
|
|
30
38
|
current: undefined | LocalNode;
|