Compare commits
1176 Commits
cojson@0.1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
688316f199 | ||
|
|
65332631d2 | ||
|
|
bb9d837236 | ||
|
|
fd186f769e | ||
|
|
97bf06fb9f | ||
|
|
85740f01ff | ||
|
|
842b7fa05a | ||
|
|
9decbb4d5b | ||
|
|
e301ad63ae | ||
|
|
f1d0c4244b | ||
|
|
4afe200553 | ||
|
|
a06bc8f868 | ||
|
|
c805d132fd | ||
|
|
33936b8fe3 | ||
|
|
23e7d07ab9 | ||
|
|
22944b5025 | ||
|
|
257ded37a7 | ||
|
|
a6f7b0c64e | ||
|
|
bbf9b1b1ca | ||
|
|
0ec9906357 | ||
|
|
91aec2536c | ||
|
|
d0ae8ef8cd | ||
|
|
6dab1e01c1 | ||
|
|
6adc931b7f | ||
|
|
b2165f3758 | ||
|
|
14f0d557e8 | ||
|
|
42ac056b99 | ||
|
|
0aef1705a2 | ||
|
|
15f09aefeb | ||
|
|
472142e926 | ||
|
|
3fca60bc23 | ||
|
|
c87e5abba6 | ||
|
|
c55297cdc5 | ||
|
|
07db808253 | ||
|
|
657ac7344a | ||
|
|
6061cad555 | ||
|
|
4c2e60ab51 | ||
|
|
1830171930 | ||
|
|
6574090402 | ||
|
|
a6f65472a7 | ||
|
|
109952aa6a | ||
|
|
556bdf977b | ||
|
|
0213b4e5b9 | ||
|
|
01c195756c | ||
|
|
9c69917d24 | ||
|
|
b4d68f0a32 | ||
|
|
fbc3839777 | ||
|
|
296464b282 | ||
|
|
2e73d09ab9 | ||
|
|
c463654970 | ||
|
|
debc052bdc | ||
|
|
3c7846153d | ||
|
|
e410fedda7 | ||
|
|
94172c9972 | ||
|
|
52ea0c7a9b | ||
|
|
4d3d99504b | ||
|
|
b91c93caed | ||
|
|
ae8e77d216 | ||
|
|
d36291e9e2 | ||
|
|
7586c3bac5 | ||
|
|
9b96cd4a65 | ||
|
|
2e66ea8e56 | ||
|
|
336cc1f0fe | ||
|
|
cc2ca5c23c | ||
|
|
3664385113 | ||
|
|
2b2ecdaf3d | ||
|
|
506491aebe | ||
|
|
6dbb05320a | ||
|
|
0160a188fa | ||
|
|
ac3e694f4e | ||
|
|
d70e4a9773 | ||
|
|
a7dca75955 | ||
|
|
143156cd6a | ||
|
|
1a182f07de | ||
|
|
7e7e7ebb51 | ||
|
|
0966a90f3d | ||
|
|
76f142b70d | ||
|
|
cd2f0846db | ||
|
|
c2e411d056 | ||
|
|
70cdb1100e | ||
|
|
0167153da2 | ||
|
|
e4a4d0decc | ||
|
|
be5211d088 | ||
|
|
dd7b30b5d8 | ||
|
|
747f73d168 | ||
|
|
7501702f7b | ||
|
|
16fb9fab5f | ||
|
|
82de51c93d | ||
|
|
5d96991981 | ||
|
|
694b168fb4 | ||
|
|
feaa69ebdd | ||
|
|
384ebf7f92 | ||
|
|
f5acd5c8a3 | ||
|
|
d7df996fdc | ||
|
|
820718ebb2 | ||
|
|
344206a7a6 | ||
|
|
ca51fe2296 | ||
|
|
e40a4f2f76 | ||
|
|
d5fa172b17 | ||
|
|
96de15593b | ||
|
|
5ba03ebc70 | ||
|
|
4609cebed6 | ||
|
|
06d21b9529 | ||
|
|
f3426beaf5 | ||
|
|
8b3e038a98 | ||
|
|
e794ddbd3d | ||
|
|
436f9393b3 | ||
|
|
4002d6afb9 | ||
|
|
7dd128962d | ||
|
|
d8ae47c4d1 | ||
|
|
8fb1748433 | ||
|
|
c8644bf678 | ||
|
|
269ee94338 | ||
|
|
dae80eeba8 | ||
|
|
ce54667b4d | ||
|
|
5963658e28 | ||
|
|
71c1411bbd | ||
|
|
71b221dc79 | ||
|
|
2d11d448dc | ||
|
|
2d42fc9b34 | ||
|
|
c9bda7e1e3 | ||
|
|
476f2d7eee | ||
|
|
1ba3a2ca34 | ||
|
|
7dd3d005a3 | ||
|
|
2c2dfb52d4 | ||
|
|
d33917fbaa | ||
|
|
f0c73d9cc6 | ||
|
|
d9324a9809 | ||
|
|
f7b5454cc6 | ||
|
|
5de338bdaf | ||
|
|
e67d44d47a | ||
|
|
a310293346 | ||
|
|
716d770258 | ||
|
|
4e85b50e1b | ||
|
|
643297b42e | ||
|
|
261efd99be | ||
|
|
f75f4f9b2d | ||
|
|
a0021f060c | ||
|
|
86bd87e6d0 | ||
|
|
ae55e80801 | ||
|
|
e830caf966 | ||
|
|
2f7240121d | ||
|
|
97699a6d5b | ||
|
|
5f8a2ba8df | ||
|
|
fe06e12b85 | ||
|
|
5b2b16a5c6 | ||
|
|
a966912c8a | ||
|
|
b63b70fb80 | ||
|
|
6b3e02920a | ||
|
|
f566961390 | ||
|
|
265b265365 | ||
|
|
83fc22f39a | ||
|
|
794681a8bb | ||
|
|
899bb0d2a1 | ||
|
|
92c0048984 | ||
|
|
33cfc4cc25 | ||
|
|
42c60c99fe | ||
|
|
e42518ed29 | ||
|
|
5b7ef3cd89 | ||
|
|
8e3bb4b4d9 | ||
|
|
fc02fc0608 | ||
|
|
37d1bbf00a | ||
|
|
ceaa555e83 | ||
|
|
3cd472f47a | ||
|
|
d453709d94 | ||
|
|
03229b2ea9 | ||
|
|
e2737d44b6 | ||
|
|
4b73834883 | ||
|
|
1b3d43d5f4 | ||
|
|
2ba972f444 | ||
|
|
7865455cb1 | ||
|
|
4d909ea4cc | ||
|
|
9c9a689879 | ||
|
|
62f79df20a | ||
|
|
8fd3c4c96c | ||
|
|
60b5288042 | ||
|
|
2fd88b938c | ||
|
|
d1f955006f | ||
|
|
bb3d5f1f87 | ||
|
|
26ce61ab78 | ||
|
|
1f300114d5 | ||
|
|
da69f812f8 | ||
|
|
0bcbf551ca | ||
|
|
6b3d5b5560 | ||
|
|
d1bdbf5d49 | ||
|
|
621e809fad | ||
|
|
d6600d9322 | ||
|
|
2b08bd77c1 | ||
|
|
c1c6e31711 | ||
|
|
0b16085f3c | ||
|
|
e53db2e96a | ||
|
|
384f0e23c0 | ||
|
|
daaf1789d9 | ||
|
|
1f9e20e753 | ||
|
|
ce9ca54f5c | ||
|
|
67e0968809 | ||
|
|
96a922cceb | ||
|
|
9b22fc74cd | ||
|
|
1bebe3c6c8 | ||
|
|
0a98b826f1 | ||
|
|
e1bd16d08b | ||
|
|
0967c2ee5a | ||
|
|
62a3854c41 | ||
|
|
f22ef4e646 | ||
|
|
6c35d0031d | ||
|
|
7bdb6f4279 | ||
|
|
93f3fb231b | ||
|
|
01d13d5df2 | ||
|
|
944e725b95 | ||
|
|
16024fec8e | ||
|
|
f90414ab95 | ||
|
|
492eecb46a | ||
|
|
51144ec832 | ||
|
|
fcaf4b9c30 | ||
|
|
afae2649f5 | ||
|
|
b5b0284c61 | ||
|
|
bf1475a143 | ||
|
|
e82cb80ca4 | ||
|
|
32c2a617d6 | ||
|
|
d3c2a41c81 | ||
|
|
4b99ff1fe3 | ||
|
|
3ebf8258a0 | ||
|
|
4809d14f6d | ||
|
|
5ae1f33127 | ||
|
|
ca5d84f6a9 | ||
|
|
6e6acc3404 | ||
|
|
b17b7b6481 | ||
|
|
5341646301 | ||
|
|
5416165d28 | ||
|
|
b5a9f681c5 | ||
|
|
7dffc006eb | ||
|
|
cd3cc5b0ab | ||
|
|
ceab75eb4d | ||
|
|
103d1b41f7 | ||
|
|
b87cc6973e | ||
|
|
3d541ca241 | ||
|
|
e72bfec884 | ||
|
|
19c7ad27d9 | ||
|
|
0bc7bfc5cc | ||
|
|
2c8120d46f | ||
|
|
c936c8c611 | ||
|
|
58c6013770 | ||
|
|
3eb3291a97 | ||
|
|
6b659f2df3 | ||
|
|
dcc9c9a5ec | ||
|
|
fe9a244363 | ||
|
|
9440bbc058 | ||
|
|
1c92cc2997 | ||
|
|
33ebbf0bdd | ||
|
|
d630b5bde5 | ||
|
|
8c56445882 | ||
|
|
1c6ae12cd9 | ||
|
|
ac5d20d159 | ||
|
|
21bcaabd5a | ||
|
|
17b4d5b668 | ||
|
|
3cd15862d5 | ||
|
|
b3d1ad7201 | ||
|
|
d87df11795 | ||
|
|
82c2a62b2a | ||
|
|
0a9112506e | ||
|
|
d9c9b5f099 | ||
|
|
fbc29f2f17 | ||
|
|
3915bbbf3c | ||
|
|
0b471c4e89 | ||
|
|
09077d37ef | ||
|
|
afe06b4fa6 | ||
|
|
d89b6e488a | ||
|
|
f6361ee43b | ||
|
|
726dbfb6df | ||
|
|
267f689f10 | ||
|
|
893ad3ae23 | ||
|
|
f5590b1be8 | ||
|
|
17a01f57e8 | ||
|
|
7318d86f52 | ||
|
|
1c8403e87a | ||
|
|
dd747c068a | ||
|
|
1f0f230fe2 | ||
|
|
da655cbff5 | ||
|
|
02f6c6220e | ||
|
|
0755cd198e | ||
|
|
c4a8227b66 | ||
|
|
86f0302233 | ||
|
|
72b5542130 | ||
|
|
5fd9225a54 | ||
|
|
9138d30208 | ||
|
|
a5ece15797 | ||
|
|
9f8877202e | ||
|
|
d190097ed9 | ||
|
|
9841617c66 | ||
|
|
165a6170cd | ||
|
|
5148419df9 | ||
|
|
fc0ecb0968 | ||
|
|
802b5a3060 | ||
|
|
e47af262b3 | ||
|
|
688a4850a4 | ||
|
|
e87fef751e | ||
|
|
8f714440f8 | ||
|
|
70cd09170e | ||
|
|
e98b610fd0 | ||
|
|
b554983558 | ||
|
|
4c63334299 | ||
|
|
4aef7cdac5 | ||
|
|
76adeb0d53 | ||
|
|
d95dcbe7db | ||
|
|
f9d538f049 | ||
|
|
40c7336c09 | ||
|
|
e0d2723615 | ||
|
|
93e68c62f5 | ||
|
|
dadee9dcc5 | ||
|
|
6724c4bd83 | ||
|
|
1942bd5de4 | ||
|
|
16764f6365 | ||
|
|
b56cfc2e1f | ||
|
|
7091bcf9c0 | ||
|
|
436cbfa095 | ||
|
|
c19a25f928 | ||
|
|
104e664bbb | ||
|
|
f199b451eb | ||
|
|
70bc48458e | ||
|
|
f28b2a6135 | ||
|
|
55b770b7c9 | ||
|
|
e6838dfb98 | ||
|
|
5e34061fdc | ||
|
|
6d9b77195a | ||
|
|
9bf7946ee6 | ||
|
|
acecffaeb2 | ||
|
|
0a98d6aaf2 | ||
|
|
4ea1a63a0a | ||
|
|
41a4c3bc95 | ||
|
|
60d0027f9d | ||
|
|
748c2ff751 | ||
|
|
cc291b590a | ||
|
|
1f144e89bf | ||
|
|
70938b0ab3 | ||
|
|
f2f5b55dbf | ||
|
|
3c3acae803 | ||
|
|
896ee3460f | ||
|
|
9b9bf44e2b | ||
|
|
8e9acb37f8 | ||
|
|
392aa88d95 | ||
|
|
7ce82cd934 | ||
|
|
0c8158b91c | ||
|
|
5a48c9c44c | ||
|
|
25c56146f5 | ||
|
|
8115e194d3 | ||
|
|
c564fbb02e | ||
|
|
12481e14c2 | ||
|
|
fd2d247ff5 | ||
|
|
9e9ea029b2 | ||
|
|
a0da272dcd | ||
|
|
72fbcc3262 | ||
|
|
f4c8cc858b | ||
|
|
0ab4d7a20d | ||
|
|
5c98ff4e4f | ||
|
|
4cbda689c4 | ||
|
|
771b0ed914 | ||
|
|
79913c3136 | ||
|
|
43d3511d15 | ||
|
|
928ef14086 | ||
|
|
048dd7def0 | ||
|
|
51fcb8a44b | ||
|
|
c5888c39f5 | ||
|
|
2defcfae67 | ||
|
|
873b146d15 | ||
|
|
213de11c3b | ||
|
|
2f24d35471 | ||
|
|
42667c81bb | ||
|
|
1b881cc89f | ||
|
|
af295d816a | ||
|
|
fe8d3497c0 | ||
|
|
c2899e94ca | ||
|
|
f4be67e9b6 | ||
|
|
ba9ad295b6 | ||
|
|
9ed5a96ef8 | ||
|
|
4272ea9019 | ||
|
|
9509307ed1 | ||
|
|
be08921bc5 | ||
|
|
77e3c21cbd | ||
|
|
ab1798c7bd | ||
|
|
26ae69a242 | ||
|
|
25be055a51 | ||
|
|
21ad3767b9 | ||
|
|
a9383516c1 | ||
|
|
bffc516c68 | ||
|
|
9e7c0d9887 | ||
|
|
99b44d5780 | ||
|
|
02db5f3b1d | ||
|
|
626775caa8 | ||
|
|
1949a5fcd9 | ||
|
|
dcd3b022cc | ||
|
|
a7b837c7e1 | ||
|
|
88ebcf58ab | ||
|
|
b173e0884a | ||
|
|
f379a168be | ||
|
|
bde6ac7d45 | ||
|
|
231947c97a | ||
|
|
d1609cdd55 | ||
|
|
d5b57ad1fc | ||
|
|
b71ab3168a | ||
|
|
0c8f6e5039 | ||
|
|
0bf5c53bec | ||
|
|
e7b1550003 | ||
|
|
6a93a1b8a3 | ||
|
|
9f654a2603 | ||
|
|
dbf735d9e1 | ||
|
|
c62abefb66 | ||
|
|
1453869a46 | ||
|
|
f5039cefc1 | ||
|
|
239da90c9f | ||
|
|
972791e7a8 | ||
|
|
6540893caf | ||
|
|
bfc85c4573 | ||
|
|
e9076313ab | ||
|
|
c6afd8ae36 | ||
|
|
370f20d13d | ||
|
|
0c0178764e | ||
|
|
928350b821 | ||
|
|
be3fd9c696 | ||
|
|
269c028df0 | ||
|
|
e4df837138 | ||
|
|
54fe6d93ba | ||
|
|
979689c6d8 | ||
|
|
859a37868f | ||
|
|
57bd32d77e | ||
|
|
f9b3116deb | ||
|
|
e51c4d4b5b | ||
|
|
352d34979f | ||
|
|
7ff736ace4 | ||
|
|
5bab466fd0 | ||
|
|
329b8c3d6a | ||
|
|
e21cbccd4b | ||
|
|
a66ab7d174 | ||
|
|
78e91f4030 | ||
|
|
7a915c198e | ||
|
|
c9b0420746 | ||
|
|
2303f3e70a | ||
|
|
a7bc9569a3 | ||
|
|
f351ba0fcd | ||
|
|
d3e554f491 | ||
|
|
b5e31456ad | ||
|
|
c0aeb7baf9 | ||
|
|
8a14de10d7 | ||
|
|
b585b39a86 | ||
|
|
42d07ba7b4 | ||
|
|
b81b6ba69b | ||
|
|
1bc1759bb4 | ||
|
|
225bc1f63f | ||
|
|
5d94564f99 | ||
|
|
9633d0187f | ||
|
|
b82ecaa3ca | ||
|
|
111ec8d351 | ||
|
|
512aacdbc2 | ||
|
|
7ad843aa3e | ||
|
|
071128339b | ||
|
|
688ced499d | ||
|
|
ac91c8e7c2 | ||
|
|
c3b303c310 | ||
|
|
fc027a56db | ||
|
|
959a7a3927 | ||
|
|
2548085b59 | ||
|
|
b27bb3e65b | ||
|
|
937284f7e9 | ||
|
|
e999727c70 | ||
|
|
2197766624 | ||
|
|
d1efde468f | ||
|
|
4d4fd0beaa | ||
|
|
2b61e853a7 | ||
|
|
6f79b45544 | ||
|
|
2e1ff99579 | ||
|
|
7361854ee4 | ||
|
|
4a775fada3 | ||
|
|
3fe53a3a4a | ||
|
|
fe37516786 | ||
|
|
4beafb7cf3 | ||
|
|
82a592e08a | ||
|
|
4c6926153a | ||
|
|
c51b088243 | ||
|
|
3eff28a896 | ||
|
|
867cb6b7a5 | ||
|
|
3a1fdd7600 | ||
|
|
3fdbb43b54 | ||
|
|
02969ee89b | ||
|
|
e9b2860e74 | ||
|
|
9b4988a514 | ||
|
|
6327d74f68 | ||
|
|
8aa4b59d49 | ||
|
|
ac782674de | ||
|
|
bedbabdcb4 | ||
|
|
5eb406d54d | ||
|
|
a3be832414 | ||
|
|
7ca8dd960e | ||
|
|
62c8aff73f | ||
|
|
7731109a28 | ||
|
|
0401fcf2a8 | ||
|
|
139a649279 | ||
|
|
9acccb5df2 | ||
|
|
fd90cdb49a | ||
|
|
7d7a810bba | ||
|
|
4a29999c6a | ||
|
|
df487d5335 | ||
|
|
1efe84c691 | ||
|
|
73b99c6c1a | ||
|
|
039b92c839 | ||
|
|
618af5f1e3 | ||
|
|
dfc4286694 | ||
|
|
970ff0d813 | ||
|
|
65eee0ef01 | ||
|
|
eee221f563 | ||
|
|
063553090e | ||
|
|
97f6bcedbd | ||
|
|
7c63e6bb0f | ||
|
|
08aedcf517 | ||
|
|
3e12ee127f | ||
|
|
2283d375ef | ||
|
|
202e763380 | ||
|
|
52bbdb37a9 | ||
|
|
c2c223f22a | ||
|
|
96f743b2f4 | ||
|
|
f5c47feeb6 | ||
|
|
6dffe73bd2 | ||
|
|
6f9ee31179 | ||
|
|
52f324ffc4 | ||
|
|
2d86f53575 | ||
|
|
68cb357a94 | ||
|
|
56ccf9ab9d | ||
|
|
b8b0851433 | ||
|
|
2bbb07b0bf | ||
|
|
4f7bc91502 | ||
|
|
d3053955d8 | ||
|
|
f61a120560 | ||
|
|
2f1307a0ba | ||
|
|
fa15ea56d1 | ||
|
|
1e58ecb3ac | ||
|
|
ceeabfaf89 | ||
|
|
70ce7c5736 | ||
|
|
f40484eca9 | ||
|
|
d581a59aa1 | ||
|
|
0ca09f75c1 | ||
|
|
e8fcd101f2 | ||
|
|
cf43fa7529 | ||
|
|
df1cdda4e8 | ||
|
|
be46042cdc | ||
|
|
6afdb16739 | ||
|
|
7a60d7bb76 | ||
|
|
f8263a8358 | ||
|
|
f6da966922 | ||
|
|
b0b2b85a6f | ||
|
|
8a2ab51543 | ||
|
|
28c19c134f | ||
|
|
0924c9baaa | ||
|
|
8bfaa0a18b | ||
|
|
b2712e18a2 | ||
|
|
66894b63d7 | ||
|
|
147be76399 | ||
|
|
36770bed52 | ||
|
|
466e6c44ee | ||
|
|
5bd8277161 | ||
|
|
b1a05143e3 | ||
|
|
fb761ce66d | ||
|
|
07a6c340dc | ||
|
|
8b4261f7d8 | ||
|
|
0ec917e453 | ||
|
|
6326d0fc45 | ||
|
|
d746b1279a | ||
|
|
0fea904dd0 | ||
|
|
373aef313f | ||
|
|
c09dcdfc76 | ||
|
|
a584590ed8 | ||
|
|
0a830e29a9 | ||
|
|
4402c553b6 | ||
|
|
e76fe343da | ||
|
|
dc183a19b2 | ||
|
|
fef55a4cd6 | ||
|
|
ddef54048f | ||
|
|
a2626a0f38 | ||
|
|
ec579bcaf7 | ||
|
|
8aa2d2a789 | ||
|
|
a39d009b87 | ||
|
|
13e7e80482 | ||
|
|
d491b66abd | ||
|
|
6b662b0efe | ||
|
|
efff4d0f4f | ||
|
|
ea2b01d8a2 | ||
|
|
e9af90c841 | ||
|
|
2b7c6f5aa7 | ||
|
|
d73a3d9d46 | ||
|
|
8af39077a3 | ||
|
|
54bd487818 | ||
|
|
f01dab5c8f | ||
|
|
a8b3ec7bb0 | ||
|
|
a7f6870048 | ||
|
|
3b294f6994 | ||
|
|
a420b43029 | ||
|
|
a57268de32 | ||
|
|
6b2c4ed280 | ||
|
|
8d4e0027be | ||
|
|
a4141da1b7 | ||
|
|
c9ca5202f9 | ||
|
|
7b50a2e06d | ||
|
|
43dabccb57 | ||
|
|
b6d04f56ef | ||
|
|
628195b678 | ||
|
|
9a5d769717 | ||
|
|
e30a3f66bf | ||
|
|
6327fce933 | ||
|
|
a650da4184 | ||
|
|
6e4a94f6ce | ||
|
|
b73bec64bc | ||
|
|
50ae2f47c2 | ||
|
|
724d8e7f30 | ||
|
|
7b285ab110 | ||
|
|
01ac9b8c4c | ||
|
|
4e2e1ac73e | ||
|
|
94960c1f65 | ||
|
|
b5af58347b | ||
|
|
46a84558c5 | ||
|
|
f93566c045 | ||
|
|
d97ed603a3 | ||
|
|
8d33103182 | ||
|
|
aaa1ff978b | ||
|
|
82655ea7a7 | ||
|
|
8afe3a2e02 | ||
|
|
ae2adcbd15 | ||
|
|
eb0460d330 | ||
|
|
55cb83e6e0 | ||
|
|
6290088fec | ||
|
|
b9c17b37db | ||
|
|
6c76ff8fbf | ||
|
|
3c6a2a6092 | ||
|
|
e8a950e61a | ||
|
|
e2cbf035de | ||
|
|
47599b6307 | ||
|
|
901d0762ee | ||
|
|
d1c1b0c5cc | ||
|
|
cf4ad7285d | ||
|
|
255a947ea6 | ||
|
|
530a263d35 | ||
|
|
2983c7bd58 | ||
|
|
9f9c235e4b | ||
|
|
d60e345b4d | ||
|
|
a3e6ff1ae7 | ||
|
|
745020b7a8 | ||
|
|
be47d866bc | ||
|
|
d01e2080d1 | ||
|
|
ab6328f767 | ||
|
|
e0555debde | ||
|
|
247f4556e7 | ||
|
|
7903c737f4 | ||
|
|
6145da5525 | ||
|
|
fc0a2e77a3 | ||
|
|
334fbbbb7f | ||
|
|
da86337d13 | ||
|
|
eaac1e6580 | ||
|
|
114898d8a9 | ||
|
|
991aebf7a7 | ||
|
|
cbc3f0cc65 | ||
|
|
29c487e288 | ||
|
|
0b0590a364 | ||
|
|
1eb01997d8 | ||
|
|
0dc8d511a1 | ||
|
|
9b75880b10 | ||
|
|
962213c712 | ||
|
|
427df8fcbb | ||
|
|
98fe72ed42 | ||
|
|
1f5c81c2ea | ||
|
|
c40aad55dc | ||
|
|
fc41aa165b | ||
|
|
dfca5926de | ||
|
|
9815ec61f0 | ||
|
|
fca60d213e | ||
|
|
b4fdab475b | ||
|
|
2b043abffa | ||
|
|
c4df2a2189 | ||
|
|
958c122c36 | ||
|
|
5842838371 | ||
|
|
e136e1b696 | ||
|
|
2475a46578 | ||
|
|
41466ea399 | ||
|
|
44f653a64b | ||
|
|
f8437042a6 | ||
|
|
3b91594d10 | ||
|
|
ac88bdcb98 | ||
|
|
30704bcaf7 | ||
|
|
acd908fbc2 | ||
|
|
4e61d1d191 | ||
|
|
db23582b4c | ||
|
|
4b0b6d8a69 | ||
|
|
d450b394fa | ||
|
|
0abc96e400 | ||
|
|
7562354b29 | ||
|
|
6c085a3919 | ||
|
|
6afff848bc | ||
|
|
47059845cc | ||
|
|
a1735a8232 | ||
|
|
1f5750d8c4 | ||
|
|
f756ce26b5 | ||
|
|
84f5bdda74 | ||
|
|
ee7aefa97c | ||
|
|
b0895981ba | ||
|
|
94f636b2ee | ||
|
|
331ab070f6 | ||
|
|
13e73adfb9 | ||
|
|
265a6405af | ||
|
|
9f6079b6c6 | ||
|
|
cf606c7c2f | ||
|
|
4033d78fa6 | ||
|
|
83af94c850 | ||
|
|
70fe856713 | ||
|
|
42e4afc42b | ||
|
|
0e6797b222 | ||
|
|
3634eaf8e9 | ||
|
|
58dfda3d0f | ||
|
|
d304b0bcb5 | ||
|
|
44f5a3f5a2 | ||
|
|
ebb3ce1c25 | ||
|
|
a67bba0dcf | ||
|
|
4a72c26e42 | ||
|
|
084cb5936d | ||
|
|
f1552b8262 | ||
|
|
6826ad8e45 | ||
|
|
7c1b757b62 | ||
|
|
326e1734a4 | ||
|
|
0cf027c91b | ||
|
|
e358881b76 | ||
|
|
cee8010918 | ||
|
|
cc877139ef | ||
|
|
56a9b89538 | ||
|
|
199c463e28 | ||
|
|
50e523d19c | ||
|
|
796ea24288 | ||
|
|
c8be86e823 | ||
|
|
41b7054aab | ||
|
|
101adcd024 | ||
|
|
63a03b4139 | ||
|
|
a2854aeec9 | ||
|
|
bdc9aee689 | ||
|
|
2f53ae0ab8 | ||
|
|
f76c05448c | ||
|
|
585e7e8177 | ||
|
|
82d8d1d873 | ||
|
|
2c523c86ff | ||
|
|
6616668d4a | ||
|
|
e47e18b84d | ||
|
|
8f5a7a091a | ||
|
|
a4d23d527b | ||
|
|
e04cec6092 | ||
|
|
8a3be85e97 | ||
|
|
1a7f2b7379 | ||
|
|
caac82dffd | ||
|
|
27b48378e5 | ||
|
|
cfd3c3ca5c | ||
|
|
41f26b7a4f | ||
|
|
c57ebb1cea | ||
|
|
259aded5cc | ||
|
|
1f5e091dd7 | ||
|
|
bbb1c44977 | ||
|
|
4327ecbfdf | ||
|
|
114c10bc77 | ||
|
|
cecdf29721 | ||
|
|
bd717fc0d7 | ||
|
|
739fff68b3 | ||
|
|
d49cab0afa | ||
|
|
ffebb4fdaf | ||
|
|
32565f0e53 | ||
|
|
61a5889bea | ||
|
|
82bd3e1ea6 | ||
|
|
b800a6fba2 | ||
|
|
1b6dbfdfff | ||
|
|
061a70f1b3 | ||
|
|
f1c1e0dafd | ||
|
|
c3912fdb37 | ||
|
|
356bfa4860 | ||
|
|
38446668c4 | ||
|
|
e2bb3b8015 | ||
|
|
8868032376 | ||
|
|
11dcfd703d | ||
|
|
0b09d23bd1 | ||
|
|
879b726537 | ||
|
|
66bbd03262 | ||
|
|
c09b63698f | ||
|
|
bed7db0a33 | ||
|
|
8ff3e234c1 | ||
|
|
296da5a5c4 | ||
|
|
700a4f1ba1 | ||
|
|
6f6663d825 | ||
|
|
844cdc907f | ||
|
|
9e32d4cb92 | ||
|
|
85dc6ba148 | ||
|
|
16c4d27e00 | ||
|
|
69170fe0e0 | ||
|
|
a646ba54b3 | ||
|
|
45d60fc3c8 | ||
|
|
6f0c399ccd | ||
|
|
40e1ca7cb1 | ||
|
|
80cf21e453 | ||
|
|
48c8a3d219 | ||
|
|
31bb1201fc | ||
|
|
08d1b05607 | ||
|
|
d64a14210d | ||
|
|
7e53d33e9b | ||
|
|
ea2b39cc30 | ||
|
|
6b835f95cf | ||
|
|
a229ae5f70 | ||
|
|
84fdc1d8fd | ||
|
|
9b1d52d183 | ||
|
|
14a8b32522 | ||
|
|
ddc09a0d6b | ||
|
|
3b45a3f2fd | ||
|
|
9034a45da0 | ||
|
|
6247fac6c5 | ||
|
|
a5ceaffb0c | ||
|
|
dcee2f9b4e | ||
|
|
f27a2c541e | ||
|
|
83fdc504ff | ||
|
|
2317a23fd4 | ||
|
|
a34c0675cd | ||
|
|
5a8a62b4a3 | ||
|
|
325a554bd1 | ||
|
|
7422943e83 | ||
|
|
23bfea5861 | ||
|
|
605a54eb11 | ||
|
|
a7aaee51e6 | ||
|
|
4b8983858a | ||
|
|
8a8c4d11e1 | ||
|
|
26994684d7 | ||
|
|
14a5e036a4 | ||
|
|
5b1c1ca522 | ||
|
|
a9c8458c51 | ||
|
|
5f31d6cbe1 | ||
|
|
b774bb345d | ||
|
|
7fd891d7b9 | ||
|
|
27cac4a6d7 | ||
|
|
2b71ef1181 | ||
|
|
ae169c7b3a | ||
|
|
d888c99d9a | ||
|
|
0b54917f19 | ||
|
|
c87b215b75 | ||
|
|
e4ba23cbef | ||
|
|
98c005a6e0 | ||
|
|
477fd8a62d | ||
|
|
90999ee709 | ||
|
|
38065f0cdf | ||
|
|
c77d16cdb3 | ||
|
|
9410084e6a | ||
|
|
8528db4de4 | ||
|
|
e0fe5a20b7 | ||
|
|
e16e4d53d1 | ||
|
|
d904fae506 | ||
|
|
f67c0b3db3 | ||
|
|
283d7c6bf0 | ||
|
|
e67c5838a9 | ||
|
|
0e7a7dbbc0 | ||
|
|
63c69b6b95 | ||
|
|
a141cbc7f7 | ||
|
|
6a5352cf3a | ||
|
|
27762637ee | ||
|
|
03108871e9 | ||
|
|
dcebe34891 | ||
|
|
99d510815f | ||
|
|
928962c08b | ||
|
|
cdadd6db1d | ||
|
|
d45b8ae70b | ||
|
|
445a58c864 | ||
|
|
1895b474ea | ||
|
|
fd02627069 | ||
|
|
827adc991d | ||
|
|
651b69e5af | ||
|
|
277e4d49e8 | ||
|
|
8990ff39a5 | ||
|
|
71e4c97255 | ||
|
|
577e960e28 | ||
|
|
f232f75d40 | ||
|
|
cfa44f32eb | ||
|
|
ef920435e9 | ||
|
|
87d05404dd | ||
|
|
535c460f5a | ||
|
|
e1a7f829b4 | ||
|
|
fa1b302474 | ||
|
|
45f73a774c | ||
|
|
2a9e271dc3 | ||
|
|
3d96d9c829 | ||
|
|
844051405d | ||
|
|
625eff2333 | ||
|
|
59e2871065 | ||
|
|
acdc88fb91 | ||
|
|
05eab4e2a9 | ||
|
|
efcd65ae38 | ||
|
|
f82177b9da | ||
|
|
ad60fa942a | ||
|
|
c1c553bad0 | ||
|
|
5272d3cd2a | ||
|
|
588ea02f63 | ||
|
|
d837811813 | ||
|
|
2b4aba2d1b | ||
|
|
50b4da18d9 | ||
|
|
d18d09e002 | ||
|
|
d983f27bbe | ||
|
|
fcf83b0da4 | ||
|
|
9231e2c22f | ||
|
|
33157ee0ad | ||
|
|
4b964edcaf | ||
|
|
df22f2617e | ||
|
|
ddc69f2268 | ||
|
|
7c62689319 | ||
|
|
280495c533 | ||
|
|
d5c6fbdc3c | ||
|
|
57776a1400 | ||
|
|
156c45aa0e | ||
|
|
2d0dba6bbc | ||
|
|
7241d2ad95 | ||
|
|
4a9eeace00 | ||
|
|
4f9c91f6ff | ||
|
|
a8e1726797 | ||
|
|
a6eeada331 | ||
|
|
3b38a8241c | ||
|
|
c49330c308 | ||
|
|
0c4e27c18d | ||
|
|
d8d273821e | ||
|
|
def0ca81b4 | ||
|
|
7ff13a8f55 | ||
|
|
53fff71f25 | ||
|
|
0e7e53238b | ||
|
|
fcc18e5212 | ||
|
|
5741d7f09c | ||
|
|
766d2c8846 | ||
|
|
70a43d0c39 | ||
|
|
c28a04d09e | ||
|
|
56fe0aa614 | ||
|
|
745e3132ca | ||
|
|
ace1c796b5 | ||
|
|
1556e41895 | ||
|
|
2badb7e706 | ||
|
|
6f5731b86e | ||
|
|
b9214a8ef4 | ||
|
|
c65940fa94 | ||
|
|
74e3c0864a | ||
|
|
1d3a0e8d6c | ||
|
|
e1f2c1936a | ||
|
|
10c139ae97 | ||
|
|
e0cd3a5637 | ||
|
|
cf44258848 | ||
|
|
4db5ec2dd8 | ||
|
|
c3610d3b98 | ||
|
|
4983e57e62 | ||
|
|
5b2fc70ca1 | ||
|
|
0e3a4d2c46 | ||
|
|
53af54570c | ||
|
|
c1be360e3b | ||
|
|
3b4c83088e | ||
|
|
25fd7f39ae | ||
|
|
591d6f1ed8 | ||
|
|
e0b4626c22 | ||
|
|
fbf9dd29db | ||
|
|
ae09b47c33 | ||
|
|
a273a0db58 | ||
|
|
277104ebba | ||
|
|
7eac549606 | ||
|
|
042d03f002 | ||
|
|
434e59d5c4 | ||
|
|
bb20907774 | ||
|
|
282425575f | ||
|
|
8e4cfd08b2 | ||
|
|
66b5f8d4c8 | ||
|
|
9c6ca9e864 | ||
|
|
858386b5b1 | ||
|
|
238e9ab7a0 | ||
|
|
f45af0a5cf | ||
|
|
22af329930 | ||
|
|
c27ac18135 | ||
|
|
8f86d44174 | ||
|
|
4d7555a4ee | ||
|
|
75501a9051 | ||
|
|
fc342306e2 | ||
|
|
8e4a9c7211 | ||
|
|
362284f6b7 | ||
|
|
975c7bc785 | ||
|
|
9a1295d4f6 | ||
|
|
256fdfd0db | ||
|
|
4cf2bf5fef | ||
|
|
cae74bd051 | ||
|
|
05a3786e23 | ||
|
|
0fa051a59d | ||
|
|
1378a1ff68 | ||
|
|
5ad093cb6a | ||
|
|
c114cf4029 | ||
|
|
98407c2314 | ||
|
|
03da7dc994 | ||
|
|
65e14c6176 | ||
|
|
9fa79b3a5f | ||
|
|
c90222d32e | ||
|
|
d084b41929 | ||
|
|
65e78014fa | ||
|
|
d693800eb3 | ||
|
|
12d5c68f98 | ||
|
|
4ab0b1f4b2 | ||
|
|
ec1e359621 | ||
|
|
44fb13ddd7 | ||
|
|
4fd4c5bbed | ||
|
|
9157effdb3 | ||
|
|
a1d31566ed | ||
|
|
dcde3aa811 | ||
|
|
30b2820a8c | ||
|
|
bb561e2650 | ||
|
|
7cdf397a01 | ||
|
|
44116b805b | ||
|
|
e93c27910d | ||
|
|
16428cace4 | ||
|
|
f48dabaa1a | ||
|
|
7ff90cb81e | ||
|
|
3a53cc4c00 | ||
|
|
ea6c50b2b8 | ||
|
|
6d93f7b388 | ||
|
|
ebc0139559 | ||
|
|
01c07e34e4 | ||
|
|
c89b94aa3b | ||
|
|
01e2977a13 | ||
|
|
41354cb2c1 | ||
|
|
530f9d3e11 | ||
|
|
c965c904bc | ||
|
|
a621141d76 | ||
|
|
0e1fbd7dfc | ||
|
|
d527ae2db0 | ||
|
|
b9261aa4c1 | ||
|
|
41dd1fa80b | ||
|
|
27efdf9b8e | ||
|
|
83068b33e9 | ||
|
|
769d9b0517 | ||
|
|
b0ffe5ed7e | ||
|
|
53dabbd955 | ||
|
|
a036a1c58c | ||
|
|
f4f47258eb | ||
|
|
7e605bb1f3 | ||
|
|
469ac44ff5 | ||
|
|
ea0045580c | ||
|
|
b84bf1826b | ||
|
|
a4fb2edfc2 | ||
|
|
06c5a1c2ba | ||
|
|
c67a0cd3ce | ||
|
|
48e11a243f | ||
|
|
b85423b39f | ||
|
|
b698ffbf45 | ||
|
|
de904698d8 | ||
|
|
a026073c41 | ||
|
|
7c8180dcb4 | ||
|
|
da3e101c50 | ||
|
|
7605d228f2 | ||
|
|
3063d74ab9 | ||
|
|
2a4e3fc0cd | ||
|
|
7cc6d63d40 | ||
|
|
d574bbc521 | ||
|
|
6388a7272b | ||
|
|
cd358888d8 | ||
|
|
f427f2324b | ||
|
|
d62285ba22 | ||
|
|
04575ff237 | ||
|
|
34a5e17cab | ||
|
|
759a800874 | ||
|
|
c5ca74e2a9 | ||
|
|
0e4a523757 | ||
|
|
733b48ab2d | ||
|
|
4bf6ecce9d | ||
|
|
f7742a0ba1 | ||
|
|
b897e950bb | ||
|
|
69c92ab908 | ||
|
|
10e1612fd4 | ||
|
|
282a2798c7 | ||
|
|
31b89adb03 | ||
|
|
793787bc66 | ||
|
|
17710122af | ||
|
|
1173884769 | ||
|
|
1c40b3fd6d | ||
|
|
2506ac799b | ||
|
|
905ba921b1 | ||
|
|
336b51eac7 | ||
|
|
b71a8dec3d | ||
|
|
1058156953 | ||
|
|
edbc10c892 | ||
|
|
4470d52326 | ||
|
|
b110f00561 | ||
|
|
f3f8baebba | ||
|
|
d330e0e7e6 | ||
|
|
5cf888930f | ||
|
|
9d75d38bbd | ||
|
|
8a45dae3f7 | ||
|
|
6110c82106 | ||
|
|
d0e2041b10 | ||
|
|
edce59d238 | ||
|
|
7f75d852c1 | ||
|
|
2683af7d28 | ||
|
|
4223720010 | ||
|
|
1b4508fea7 | ||
|
|
776fa09279 | ||
|
|
5c200aa60d | ||
|
|
9fc6c5f6c8 | ||
|
|
7e06cd4a77 | ||
|
|
c43191d97b | ||
|
|
5706b5eb81 | ||
|
|
5eed930997 | ||
|
|
35e5e50508 | ||
|
|
e88a3d0712 | ||
|
|
13b64af5b2 | ||
|
|
9804c6a729 | ||
|
|
ea3a69cf53 | ||
|
|
24987fa9ec | ||
|
|
937d415cc2 | ||
|
|
9196154207 | ||
|
|
c907b2aac2 | ||
|
|
b5a9dfa7ec | ||
|
|
113c77b416 | ||
|
|
cad5444400 | ||
|
|
b2b350e4d0 | ||
|
|
80d5d62852 | ||
|
|
527082b108 | ||
|
|
75f8833c1a | ||
|
|
99d1f3f28b | ||
|
|
4066cfe011 | ||
|
|
e5f8b06af1 | ||
|
|
485b5a238d | ||
|
|
c42ee6d6e2 | ||
|
|
1fb2fd0f50 | ||
|
|
0fce4adfc5 | ||
|
|
b59086c808 | ||
|
|
fe91463652 | ||
|
|
b9065db109 | ||
|
|
d13da295ed | ||
|
|
0291389c3b | ||
|
|
f417f518cb | ||
|
|
f69f99a209 | ||
|
|
31c4fd7c07 | ||
|
|
613aadd775 | ||
|
|
0f969b4be4 | ||
|
|
f7ac1015b2 | ||
|
|
63500e17f2 | ||
|
|
d7c5d4a03d | ||
|
|
8384c55cce | ||
|
|
be947d1086 | ||
|
|
3924bb2ede | ||
|
|
2e3003c2fc | ||
|
|
5ec15ba0a2 | ||
|
|
c7ccf5c5d7 | ||
|
|
9e8c81a1a6 | ||
|
|
c563e2547f | ||
|
|
00cb697bc7 | ||
|
|
a6a0560059 | ||
|
|
55fa5977c2 | ||
|
|
8b4bc1bc97 | ||
|
|
df403ccbc6 | ||
|
|
1f490d2aae | ||
|
|
1b766b6369 | ||
|
|
3f54da98f8 | ||
|
|
05b98c0f8b | ||
|
|
928e63620b | ||
|
|
ea9b1eb88e | ||
|
|
83a88252e2 | ||
|
|
7a61c19135 | ||
|
|
a2f87f304c | ||
|
|
f9f24d2ad2 | ||
|
|
ed3197a7fd | ||
|
|
772a88e98f | ||
|
|
e22a7f46ad | ||
|
|
f890f2f460 | ||
|
|
e9c17e12dc | ||
|
|
4b908e3024 | ||
|
|
90fd2b5da0 | ||
|
|
d7b4360f11 | ||
|
|
df7011167c | ||
|
|
28a785acb0 | ||
|
|
3ee557bfbe | ||
|
|
af94255166 | ||
|
|
4a0dea3f75 | ||
|
|
6a42bc9655 | ||
|
|
c6c8a7f6b7 | ||
|
|
133dd0e26d | ||
|
|
815339272f | ||
|
|
9c1f340029 | ||
|
|
b72ea9608d |
@@ -6,40 +6,20 @@
|
||||
"fixed": [
|
||||
[
|
||||
"cojson",
|
||||
"cojson-storage",
|
||||
"cojson-core-wasm",
|
||||
"cojson-storage-indexeddb",
|
||||
"cojson-storage-sqlite",
|
||||
"cojson-transport-ws",
|
||||
"jazz-browser",
|
||||
"jazz-auth-clerk",
|
||||
"jazz-auth-betterauth",
|
||||
"jazz-betterauth-client-plugin",
|
||||
"jazz-betterauth-server-plugin",
|
||||
"jazz-react-auth-betterauth",
|
||||
"jazz-browser-media-images",
|
||||
"jazz-expo",
|
||||
"jazz-inspector",
|
||||
"jazz-inspector-element",
|
||||
"jazz-nodejs",
|
||||
"jazz-react",
|
||||
"jazz-react-core",
|
||||
"jazz-react-auth-clerk",
|
||||
"jazz-react-native-core",
|
||||
"jazz-react-native",
|
||||
"jazz-react-native-media-images",
|
||||
"jazz-richtext-prosemirror",
|
||||
"jazz-richtext-tiptap",
|
||||
"jazz-run",
|
||||
"jazz-svelte",
|
||||
"jazz-tools",
|
||||
"jazz-vue"
|
||||
"community-jazz-vue"
|
||||
]
|
||||
],
|
||||
"access": "public",
|
||||
"baseBranch": "main",
|
||||
"updateInternalDependencies": "patch",
|
||||
"ignore": [],
|
||||
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
|
||||
"onlyUpdatePeerDependentsWhenOutOfRange": true
|
||||
}
|
||||
"updateInternalDependencies": "minor"
|
||||
}
|
||||
|
||||
5
.changeset/lucky-wasps-rhyme.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"jazz-tools": patch
|
||||
---
|
||||
|
||||
Explicit loadAs in CoList.upsertUnique to use it without loaded context
|
||||
8
.changeset/popular-mangos-run.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"cojson": patch
|
||||
---
|
||||
|
||||
Fix admin permission downgrade to writeOnly
|
||||
- Allow admin to self-downgrade to writeOnly
|
||||
- Prevent admin from downgrading other admins to writeOnly
|
||||
|
||||
5
.changeset/tall-eels-brush.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"cojson": patch
|
||||
---
|
||||
|
||||
Skip agent resolution when skipVerify is true
|
||||
8
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
./packages @garden-co/framework
|
||||
./tests @garden-co/framework
|
||||
./packages/quint-ui @garden-co/ui
|
||||
|
||||
./homepage @garden-co/ui
|
||||
./homepage/homepage/content/docs @garden-co/docs
|
||||
./starters @garden-co/docs
|
||||
./examples @garden-co/docs @garden-co/ui
|
||||
23
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# Description
|
||||
<!-- Please include a summary of the change and which issue is fixed -->
|
||||
<!-- Please also include relevant motivation and context -->
|
||||
<!-- Include any links to documentation like RFC’s if necessary -->
|
||||
<!-- Add a link to to relevant preview environments or anything that would simplify visual review process -->
|
||||
<!-- Supplemental screenshots and video are encouraged, but the primary description should be in text -->
|
||||
|
||||
## Manual testing instructions
|
||||
|
||||
<!-- Add any actions required to manually test the changes -->
|
||||
|
||||
## Tests
|
||||
|
||||
- [ ] Tests have been added and/or updated
|
||||
- [ ] Tests have not been updated, because: <!-- Insert reason for not updating tests here -->
|
||||
- [ ] I need help with writing tests
|
||||
|
||||
|
||||
## Checklist
|
||||
|
||||
- [ ] I've updated the part of the docs that are affected the PR changes
|
||||
- [ ] I've generated a changeset, if a version bump is required
|
||||
- [ ] I've updated the jsDoc comments to the public APIs I've modified, or added them when missing
|
||||
31
.github/workflows/build-examples.yaml
vendored
@@ -1,31 +0,0 @@
|
||||
name: Build Examples
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
build-examples:
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
||||
strategy:
|
||||
matrix:
|
||||
example: [
|
||||
"passkey-svelte",
|
||||
"chat-svelte",
|
||||
"file-share-svelte",
|
||||
]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Setup Source Code
|
||||
uses: ./.github/actions/source-code/
|
||||
|
||||
- name: Pnpm Build
|
||||
run: |
|
||||
pnpm install
|
||||
pnpm turbo build;
|
||||
working-directory: ./examples/${{ matrix.example }}
|
||||
16
.github/workflows/code-quality.yml
vendored
@@ -1,21 +1,27 @@
|
||||
name: Code quality
|
||||
|
||||
concurrency:
|
||||
# For pushes, this lets concurrent runs happen, so each push gets a result.
|
||||
# But for other events (e.g. PRs), we can cancel the previous runs.
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
pull_request:
|
||||
|
||||
|
||||
jobs:
|
||||
quality:
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
||||
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Biome
|
||||
uses: biomejs/setup-biome@v2
|
||||
with:
|
||||
version: latest
|
||||
version: 2.1.3
|
||||
- name: Run Biome
|
||||
run: biome ci .
|
||||
|
||||
- name: Check Catalog Dependencies
|
||||
run: node scripts/check-catalog-deps.js
|
||||
|
||||
77
.github/workflows/create-jazz-app.yml
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
name: Test `create-jazz-app` Distribution
|
||||
|
||||
concurrency:
|
||||
# For pushes, this lets concurrent runs happen, so each push gets a result.
|
||||
# But for other events (e.g. PRs), we can cancel the previous runs.
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
paths:
|
||||
- 'packages/create-jazz-app/**'
|
||||
|
||||
jobs:
|
||||
test-create-jazz-app-distribution:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Source Code
|
||||
uses: ./.github/actions/source-code/
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Build create-jazz-app
|
||||
run: pnpm build
|
||||
working-directory: packages/create-jazz-app
|
||||
|
||||
- name: Pack create-jazz-app
|
||||
run: pnpm pack
|
||||
working-directory: packages/create-jazz-app
|
||||
|
||||
- name: Create test directory
|
||||
run: mkdir -p /tmp/test-create-jazz-app
|
||||
|
||||
- name: Initialize test package
|
||||
run: |
|
||||
cd /tmp/test-create-jazz-app
|
||||
bun init -y
|
||||
|
||||
- name: Install packed create-jazz-app
|
||||
run: |
|
||||
cd /tmp/test-create-jazz-app
|
||||
bun install ${{ github.workspace }}/packages/create-jazz-app/create-jazz-app-*.tgz
|
||||
|
||||
- name: Test basic functionality
|
||||
run: |
|
||||
cd /tmp/test-create-jazz-app
|
||||
bunx create-jazz-app --help
|
||||
|
||||
- name: Create test project and validate catalog resolution
|
||||
run: |
|
||||
cd /tmp/test-create-jazz-app
|
||||
mkdir test-project
|
||||
cd test-project
|
||||
echo -e "\n\n\n\n\n\n\n\n" | bunx create-jazz-app . --framework react --starter react-passkey-auth --package-manager bun --git false
|
||||
|
||||
- name: Validate no unresolved catalog references
|
||||
run: |
|
||||
cd /tmp/test-create-jazz-app/test-project
|
||||
# Check for unresolved catalog: references in package.json
|
||||
if grep -r "catalog:" package.json; then
|
||||
echo "❌ Found unresolved catalog: references in generated project"
|
||||
exit 1
|
||||
fi
|
||||
# Check for unresolved workspace: references
|
||||
if grep -r "workspace:" package.json; then
|
||||
echo "❌ Found unresolved workspace: references in generated project"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ All catalog and workspace references resolved successfully"
|
||||
9
.github/workflows/e2e-rn-test.yml
vendored
@@ -1,5 +1,11 @@
|
||||
name: End-to-End Tests for React Native
|
||||
|
||||
concurrency:
|
||||
# For pushes, this lets concurrent runs happen, so each push gets a result.
|
||||
# But for other events (e.g. PRs), we can cancel the previous runs.
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
@@ -60,7 +66,8 @@ jobs:
|
||||
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-metrics
|
||||
disable-animations: true
|
||||
working-directory: ./examples/chat-rn-expo/
|
||||
script: ./test/e2e/run.sh
|
||||
# killall due to this issue: https://github.com/ReactiveCircus/android-emulator-runner/issues/385
|
||||
script: ./test/e2e/run.sh && ( killall -INT crashpad_handler || true )
|
||||
|
||||
- name: Copy Maestro Output
|
||||
if: steps.e2e_test.outcome != 'success'
|
||||
|
||||
8
.github/workflows/jazz-run.yml
vendored
@@ -1,5 +1,11 @@
|
||||
name: Jazz Run Tests
|
||||
|
||||
concurrency:
|
||||
# For pushes, this lets concurrent runs happen, so each push gets a result.
|
||||
# But for other events (e.g. PRs), we can cancel the previous runs.
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
@@ -8,7 +14,7 @@ on:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2404
|
||||
timeout-minutes: 5
|
||||
|
||||
steps:
|
||||
|
||||
49
.github/workflows/playwright-homepage.yml
vendored
@@ -1,49 +0,0 @@
|
||||
name: Playwright Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
||||
strategy:
|
||||
matrix:
|
||||
project: ["homepage/homepage"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Setup Source Code
|
||||
uses: ./.github/actions/source-code/
|
||||
|
||||
- name: Install root dependencies
|
||||
run: pnpm install && pnpm turbo build
|
||||
|
||||
- name: Install project dependencies
|
||||
run: pnpm install
|
||||
working-directory: ./${{ matrix.project }}
|
||||
|
||||
- name: Pnpm Build
|
||||
run: pnpm turbo build
|
||||
working-directory: ./${{ matrix.project }}
|
||||
|
||||
- name: Install Playwright Browsers
|
||||
run: pnpm exec playwright install
|
||||
working-directory: ./${{ matrix.project }}
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: pnpm exec playwright test
|
||||
working-directory: ./${{ matrix.project }}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: ${{ hashFiles(format('{0}/package.json', matrix.project)) }}-playwright-report
|
||||
path: ./${{ matrix.project }}/playwright-report/
|
||||
retention-days: 30
|
||||
168
.github/workflows/playwright.yml
vendored
@@ -1,5 +1,11 @@
|
||||
name: Playwright Tests
|
||||
|
||||
concurrency:
|
||||
# For pushes, this lets concurrent runs happen, so each push gets a result.
|
||||
# But for other events (e.g. PRs), we can cancel the previous runs.
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
@@ -9,25 +15,11 @@ on:
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2404
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
project: [
|
||||
"tests/e2e",
|
||||
"examples/chat",
|
||||
"examples/clerk",
|
||||
"examples/betterauth",
|
||||
"examples/file-share-svelte",
|
||||
"examples/form",
|
||||
"examples/inspector",
|
||||
"examples/music-player",
|
||||
"examples/organization",
|
||||
"examples/pets",
|
||||
"starters/react-passkey-auth",
|
||||
"starters/svelte-passkey-auth",
|
||||
"packages/jazz-svelte"
|
||||
]
|
||||
shard: ["1/2", "2/2"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -37,25 +29,131 @@ jobs:
|
||||
- name: Setup Source Code
|
||||
uses: ./.github/actions/source-code/
|
||||
|
||||
- name: Pnpm Build
|
||||
run: |
|
||||
if [ -f .env.test ]; then
|
||||
cp .env.test .env
|
||||
fi
|
||||
pnpm turbo build
|
||||
working-directory: ./${{ matrix.project }}
|
||||
|
||||
- name: Install Playwright Browsers
|
||||
run: pnpm exec playwright install
|
||||
working-directory: ./${{ matrix.project }}
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: pnpm exec playwright test
|
||||
working-directory: ./${{ matrix.project }}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: ${{ hashFiles(format('{0}/package.json', matrix.project)) }}-playwright-report
|
||||
path: ./${{ matrix.project }}/playwright-report/
|
||||
retention-days: 30
|
||||
- name: Run Playwright tests for shard ${{ matrix.shard }}
|
||||
run: |
|
||||
# Parse shard information (e.g., "1/2" -> shard_num=1, total_shards=2)
|
||||
IFS='/' read -r shard_num total_shards <<< "${{ matrix.shard }}"
|
||||
shard_index=$((shard_num - 1)) # Convert to 0-based index
|
||||
|
||||
# Debug: Print parsed values
|
||||
echo "Parsed shard_num: $shard_num"
|
||||
echo "Parsed total_shards: $total_shards"
|
||||
echo "Calculated shard_index: $shard_index"
|
||||
|
||||
# Define all projects to test
|
||||
all_projects=(
|
||||
"tests/e2e"
|
||||
"examples/chat"
|
||||
"examples/chat-svelte"
|
||||
"examples/community-clerk-vue"
|
||||
"examples/clerk"
|
||||
"examples/betterauth"
|
||||
"examples/file-share-svelte"
|
||||
"examples/form"
|
||||
"examples/inspector"
|
||||
"examples/music-player"
|
||||
"examples/organization"
|
||||
"examples/server-worker-http"
|
||||
"starters/react-passkey-auth"
|
||||
"starters/svelte-passkey-auth"
|
||||
"tests/jazz-svelte"
|
||||
)
|
||||
|
||||
# Calculate which projects this shard should run
|
||||
shard_projects=()
|
||||
for i in "${!all_projects[@]}"; do
|
||||
if [ $((i % total_shards)) -eq $shard_index ]; then
|
||||
shard_projects+=("${all_projects[i]}")
|
||||
fi
|
||||
done
|
||||
|
||||
# Track project results
|
||||
overall_exit_code=0
|
||||
failed_projects=()
|
||||
passed_projects=()
|
||||
|
||||
echo "=== Running tests for shard ${{ matrix.shard }} ==="
|
||||
echo "Projects in this shard:"
|
||||
printf '%s\n' "${shard_projects[@]}"
|
||||
echo
|
||||
|
||||
# Run tests for each project
|
||||
for project in "${shard_projects[@]}"; do
|
||||
echo "=== Testing project: $project ==="
|
||||
|
||||
# Check if project directory exists
|
||||
if [ ! -d "$project" ]; then
|
||||
echo "❌ FAILED: Project directory $project does not exist"
|
||||
failed_projects+=("$project (directory not found)")
|
||||
overall_exit_code=1
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if project has package.json
|
||||
if [ ! -f "$project/package.json" ]; then
|
||||
echo "❌ FAILED: No package.json found in $project"
|
||||
failed_projects+=("$project (no package.json)")
|
||||
overall_exit_code=1
|
||||
continue
|
||||
fi
|
||||
|
||||
# Build the project
|
||||
echo "🔨 Building $project..."
|
||||
cd "$project"
|
||||
|
||||
if [ -f .env.test ]; then
|
||||
cp .env.test .env
|
||||
fi
|
||||
|
||||
if ! pnpm turbo build; then
|
||||
echo "❌ BUILD FAILED: $project"
|
||||
failed_projects+=("$project (build failed)")
|
||||
overall_exit_code=1
|
||||
cd - > /dev/null
|
||||
continue
|
||||
fi
|
||||
|
||||
# Run Playwright tests
|
||||
echo "🧪 Running Playwright tests for $project..."
|
||||
if ! pnpm exec playwright test; then
|
||||
echo "❌ TESTS FAILED: $project"
|
||||
failed_projects+=("$project (tests failed)")
|
||||
overall_exit_code=1
|
||||
else
|
||||
echo "✅ TESTS PASSED: $project"
|
||||
passed_projects+=("$project")
|
||||
fi
|
||||
|
||||
cd - > /dev/null
|
||||
echo "=== Finished testing $project ==="
|
||||
echo
|
||||
done
|
||||
|
||||
# Print summary report
|
||||
echo "=========================================="
|
||||
echo "📊 TEST SUMMARY FOR SHARD ${{ matrix.shard }}"
|
||||
echo "=========================================="
|
||||
|
||||
if [ ${#passed_projects[@]} -gt 0 ]; then
|
||||
echo "✅ PASSED (${#passed_projects[@]}):"
|
||||
printf ' - %s\n' "${passed_projects[@]}"
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ ${#failed_projects[@]} -gt 0 ]; then
|
||||
echo "❌ FAILED (${#failed_projects[@]}):"
|
||||
printf ' - %s\n' "${failed_projects[@]}"
|
||||
echo
|
||||
fi
|
||||
|
||||
|
||||
echo "Total projects in shard: ${#shard_projects[@]}"
|
||||
echo "Passed: ${#passed_projects[@]}"
|
||||
echo "Failed: ${#failed_projects[@]}"
|
||||
echo "=========================================="
|
||||
|
||||
# Exit with overall status
|
||||
exit $overall_exit_code
|
||||
|
||||
7
.github/workflows/pre-release.yml
vendored
@@ -1,4 +1,11 @@
|
||||
name: Pre-Publish tagged Pull Requests
|
||||
|
||||
concurrency:
|
||||
# For pushes, this lets concurrent runs happen, so each push gets a result.
|
||||
# But for other events (e.g. PRs), we can cancel the previous runs.
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, labeled]
|
||||
|
||||
2
.github/workflows/release.yml
vendored
@@ -17,7 +17,7 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2404
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
8
.github/workflows/unit-test.yml
vendored
@@ -1,5 +1,11 @@
|
||||
name: Unit Tests
|
||||
|
||||
concurrency:
|
||||
# For pushes, this lets concurrent runs happen, so each push gets a result.
|
||||
# But for other events (e.g. PRs), we can cancel the previous runs.
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
@@ -9,7 +15,7 @@ on:
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
||||
runs-on: blacksmith-4vcpu-ubuntu-2404
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
||||
@@ -63,7 +63,7 @@ You'll need Node.js 22.x installed (we're working on support for 23.x), and pnpm
|
||||
4. **Build the packages**:
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
pnpm build:packages
|
||||
```
|
||||
|
||||
5. **Run tests** to verify everything is working:
|
||||
|
||||
171
bench/comap.create.bench.ts
Normal file
@@ -0,0 +1,171 @@
|
||||
import { describe, bench } from "vitest";
|
||||
import * as tools from "jazz-tools";
|
||||
import * as toolsLatest from "jazz-tools-latest";
|
||||
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
||||
import { WasmCrypto as WasmCryptoLatest } from "cojson-latest/crypto/WasmCrypto";
|
||||
import { PureJSCrypto } from "cojson/crypto/PureJSCrypto";
|
||||
import { PureJSCrypto as PureJSCryptoLatest } from "cojson-latest/crypto/PureJSCrypto";
|
||||
|
||||
const sampleReactions = ["👍", "❤️", "😄", "🎉"];
|
||||
const sampleHiddenIn = ["user1", "user2", "user3"];
|
||||
|
||||
// Define the schemas based on the provided Message schema
|
||||
async function createSchema(
|
||||
tools: typeof toolsLatest,
|
||||
WasmCrypto: typeof WasmCryptoLatest,
|
||||
) {
|
||||
const Embed = tools.co.map({
|
||||
url: tools.z.string(),
|
||||
title: tools.z.string().optional(),
|
||||
description: tools.z.string().optional(),
|
||||
image: tools.z.string().optional(),
|
||||
});
|
||||
|
||||
const Message = tools.co.map({
|
||||
content: tools.z.string(),
|
||||
createdAt: tools.z.date(),
|
||||
updatedAt: tools.z.date(),
|
||||
hiddenIn: tools.co.list(tools.z.string()),
|
||||
replyTo: tools.z.string().optional(),
|
||||
reactions: tools.co.list(tools.z.string()),
|
||||
softDeleted: tools.z.boolean().optional(),
|
||||
embeds: tools.co.optional(tools.co.list(Embed)),
|
||||
author: tools.z.string().optional(),
|
||||
threadId: tools.z.string().optional(),
|
||||
});
|
||||
|
||||
const ctx = await tools.createJazzContextForNewAccount({
|
||||
creationProps: {
|
||||
name: "Test Account",
|
||||
},
|
||||
// @ts-expect-error
|
||||
crypto: await WasmCrypto.create(),
|
||||
});
|
||||
|
||||
return {
|
||||
Message,
|
||||
sampleReactions,
|
||||
sampleHiddenIn,
|
||||
Group: tools.Group,
|
||||
account: ctx.account,
|
||||
};
|
||||
}
|
||||
|
||||
const PUREJS = false;
|
||||
|
||||
// @ts-expect-error
|
||||
const schema = await createSchema(tools, PUREJS ? PureJSCrypto : WasmCrypto);
|
||||
const schemaLatest = await createSchema(
|
||||
toolsLatest,
|
||||
// @ts-expect-error
|
||||
PUREJS ? PureJSCryptoLatest : WasmCryptoLatest,
|
||||
);
|
||||
|
||||
const message = schema.Message.create(
|
||||
{
|
||||
content: "A".repeat(1024),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
hiddenIn: sampleHiddenIn,
|
||||
reactions: sampleReactions,
|
||||
author: "user123",
|
||||
},
|
||||
schema.Group.create(schema.account).makePublic(),
|
||||
);
|
||||
|
||||
const content = await tools.exportCoValue(schema.Message, message.id, {
|
||||
// @ts-expect-error
|
||||
loadAs: schema.account,
|
||||
});
|
||||
tools.importContentPieces(content ?? [], schema.account as any);
|
||||
toolsLatest.importContentPieces(content ?? [], schemaLatest.account);
|
||||
schema.account._raw.core.node.internalDeleteCoValue(message.id as any);
|
||||
schemaLatest.account._raw.core.node.internalDeleteCoValue(message.id as any);
|
||||
|
||||
describe("Message.create", () => {
|
||||
bench(
|
||||
"current version",
|
||||
() => {
|
||||
schema.Message.create(
|
||||
{
|
||||
content: "A".repeat(1024),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
hiddenIn: sampleHiddenIn,
|
||||
reactions: sampleReactions,
|
||||
author: "user123",
|
||||
},
|
||||
schema.Group.create(schema.account),
|
||||
);
|
||||
},
|
||||
{ iterations: 1000 },
|
||||
);
|
||||
|
||||
bench(
|
||||
"Jazz 0.17.9",
|
||||
() => {
|
||||
schemaLatest.Message.create(
|
||||
{
|
||||
content: "A".repeat(1024),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
hiddenIn: sampleHiddenIn,
|
||||
reactions: sampleReactions,
|
||||
author: "user123",
|
||||
},
|
||||
schemaLatest.Group.create(schemaLatest.account),
|
||||
);
|
||||
},
|
||||
{ iterations: 1000 },
|
||||
);
|
||||
});
|
||||
|
||||
describe("Message import", () => {
|
||||
bench(
|
||||
"current version",
|
||||
() => {
|
||||
tools.importContentPieces(content ?? [], schema.account as any);
|
||||
schema.account._raw.core.node.internalDeleteCoValue(message.id as any);
|
||||
},
|
||||
{ iterations: 5000 },
|
||||
);
|
||||
|
||||
bench(
|
||||
"Jazz 0.17.9",
|
||||
() => {
|
||||
toolsLatest.importContentPieces(content ?? [], schemaLatest.account);
|
||||
schemaLatest.account._raw.core.node.internalDeleteCoValue(
|
||||
message.id as any,
|
||||
);
|
||||
},
|
||||
{ iterations: 5000 },
|
||||
);
|
||||
});
|
||||
|
||||
describe("import+ decrypt", () => {
|
||||
bench(
|
||||
"current version",
|
||||
() => {
|
||||
tools.importContentPieces(content ?? [], schema.account as any);
|
||||
|
||||
const node = schema.account._raw.core.node;
|
||||
|
||||
node.expectCoValueLoaded(message.id as any).getCurrentContent();
|
||||
node.internalDeleteCoValue(message.id as any);
|
||||
},
|
||||
{ iterations: 5000 },
|
||||
);
|
||||
|
||||
bench(
|
||||
"Jazz 0.17.9",
|
||||
() => {
|
||||
toolsLatest.importContentPieces(content ?? [], schemaLatest.account);
|
||||
|
||||
const node = schemaLatest.account._raw.core.node;
|
||||
|
||||
node.expectCoValueLoaded(message.id as any).getCurrentContent();
|
||||
node.internalDeleteCoValue(message.id as any);
|
||||
},
|
||||
{ iterations: 5000 },
|
||||
);
|
||||
});
|
||||
14
bench/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "jazz-tools-benchmark",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"cojson": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"cojson-latest": "npm:cojson@0.17.9",
|
||||
"jazz-tools-latest": "npm:jazz-tools@0.17.9"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "vitest bench"
|
||||
}
|
||||
}
|
||||
7
bench/vitest.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineProject } from "vitest/config";
|
||||
|
||||
export default defineProject({
|
||||
test: {
|
||||
name: "bench",
|
||||
},
|
||||
});
|
||||
73
biome.json
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.1.3/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
@@ -7,39 +7,36 @@
|
||||
},
|
||||
"files": {
|
||||
"ignoreUnknown": false,
|
||||
"ignore": [
|
||||
"jazz-tools.json",
|
||||
"**/ios/**",
|
||||
"**/android/**",
|
||||
"packages/jazz-svelte/**",
|
||||
"examples/*svelte*/**",
|
||||
"starters/*svelte*/**",
|
||||
"examples/jazz-paper-scissors/src/routeTree.gen.ts",
|
||||
"homepage/homepage/**",
|
||||
"**/package.json"
|
||||
"includes": [
|
||||
"**",
|
||||
"!crates/**",
|
||||
"!**/jazz-tools.json",
|
||||
"!**/ios/**",
|
||||
"!**/android/**",
|
||||
"!**/tests/jazz-svelte/src/**",
|
||||
"!**/examples/**/*svelte*/**",
|
||||
"!**/starters/**/*svelte*/**",
|
||||
"!**/examples/server-worker-inbox/src/routeTree.gen.ts",
|
||||
"!**/homepage/homepage/**",
|
||||
"!**/package.json",
|
||||
"!**/*svelte*/**"
|
||||
]
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"indentStyle": "space"
|
||||
},
|
||||
"organizeImports": {
|
||||
"enabled": true
|
||||
},
|
||||
"assist": { "actions": { "source": { "organizeImports": "off" } } },
|
||||
"linter": {
|
||||
"enabled": false,
|
||||
"rules": {
|
||||
"recommended": true,
|
||||
"correctness": {
|
||||
"useExhaustiveDependencies": "off",
|
||||
"useImportExtensions": {
|
||||
"level": "error",
|
||||
"options": {
|
||||
"suggestedExtensions": {
|
||||
"ts": {
|
||||
"module": "js",
|
||||
"component": "jsx"
|
||||
}
|
||||
}
|
||||
"forceJsExtensions": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,16 +44,7 @@
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"include": ["packages/**/src/**"],
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"include": ["packages/cojson-storage*/**", "cojson-transport-ws/**"],
|
||||
"includes": ["packages/community-jazz-vue/src/**"],
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
@@ -65,7 +53,28 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"include": ["**/tests/**"],
|
||||
"includes": ["**/packages/**/src/**"],
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"includes": [
|
||||
"**/packages/cojson/src/storage/**/*/**",
|
||||
"**/cojson-transport-ws/**"
|
||||
],
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"includes": ["**/tests/**"],
|
||||
"linter": {
|
||||
"rules": {
|
||||
"correctness": {
|
||||
@@ -75,7 +84,7 @@
|
||||
"noNonNullAssertion": "off"
|
||||
},
|
||||
"suspicious": {
|
||||
"noExplicitAny": "info"
|
||||
"noExplicitAny": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
crates/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Rust
|
||||
/target
|
||||
|
||||
# Test artifacts
|
||||
lzy/compressed_66k.lzy
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
1164
crates/Cargo.lock
generated
Normal file
7
crates/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"lzy",
|
||||
"cojson-core",
|
||||
"cojson-core-wasm",
|
||||
]
|
||||
3
crates/cojson-core-wasm/CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# cojson-core-wasm
|
||||
|
||||
## 0.17.10
|
||||
29
crates/cojson-core-wasm/Cargo.toml
Normal file
@@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "cojson-core-wasm"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
cojson-core = { path = "../cojson-core" }
|
||||
wasm-bindgen = "0.2"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
ed25519-dalek = { version = "2.2.0", default-features = false, features = ["rand_core"] }
|
||||
serde_json = "1.0"
|
||||
serde-wasm-bindgen = "0.6"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
js-sys = "0.3"
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
thiserror = "1.0"
|
||||
hex = "0.4"
|
||||
blake3 = "1.5"
|
||||
x25519-dalek = { version = "2.0", features = ["getrandom", "static_secrets"] }
|
||||
crypto_secretbox = { version = "0.1.1", features = ["getrandom"] }
|
||||
salsa20 = "0.10.2"
|
||||
rand = "0.8"
|
||||
bs58 = "0.5"
|
||||
|
||||
[features]
|
||||
default = ["console_error_panic_hook"]
|
||||
26
crates/cojson-core-wasm/build.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
|
||||
mkdirSync("./public", { recursive: true });
|
||||
|
||||
const wasm = readFileSync("./pkg/cojson_core_wasm_bg.wasm");
|
||||
|
||||
writeFileSync(
|
||||
"./public/cojson_core_wasm.wasm.js",
|
||||
`export const data = "data:application/wasm;base64,${wasm.toString("base64")}";`,
|
||||
);
|
||||
writeFileSync(
|
||||
"./public/cojson_core_wasm.wasm.d.ts",
|
||||
"export const data: string;",
|
||||
);
|
||||
|
||||
const glueJs = readFileSync("./pkg/cojson_core_wasm.js", "utf8").replace(
|
||||
"module_or_path = new URL('cojson_core_wasm_bg.wasm', import.meta.url);",
|
||||
"throw new Error();",
|
||||
);
|
||||
|
||||
writeFileSync("./public/cojson_core_wasm.js", glueJs);
|
||||
|
||||
writeFileSync(
|
||||
"./public/cojson_core_wasm.d.ts",
|
||||
readFileSync("./pkg/cojson_core_wasm.d.ts", "utf8"),
|
||||
);
|
||||
3
crates/cojson-core-wasm/index.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./public/cojson_core_wasm.js";
|
||||
|
||||
export async function initialize(): Promise<void>;
|
||||
8
crates/cojson-core-wasm/index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export * from "./public/cojson_core_wasm.js";
|
||||
|
||||
import __wbg_init from "./public/cojson_core_wasm.js";
|
||||
import { data } from "./public/cojson_core_wasm.wasm.js";
|
||||
|
||||
export async function initialize() {
|
||||
return await __wbg_init({ module_or_path: data });
|
||||
}
|
||||
22
crates/cojson-core-wasm/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "cojson-core-wasm",
|
||||
"type": "module",
|
||||
"version": "0.17.10",
|
||||
"files": [
|
||||
"public/cojson_core_wasm.js",
|
||||
"public/cojson_core_wasm.d.ts",
|
||||
"public/cojson_core_wasm.wasm.js",
|
||||
"public/cojson_core_wasm.wasm.d.ts",
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"build:wasm": "wasm-pack build --release --target web && node build.js",
|
||||
"build:dev": "wasm-pack build --dev --target web && node build.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"wasm-pack": "^0.13.1"
|
||||
}
|
||||
}
|
||||
291
crates/cojson-core-wasm/public/cojson_core_wasm.d.ts
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* WASM-exposed function for XSalsa20 encryption without authentication.
|
||||
* - `key`: 32-byte key for encryption
|
||||
* - `nonce_material`: Raw bytes used to generate a 24-byte nonce via BLAKE3
|
||||
* - `plaintext`: Raw bytes to encrypt
|
||||
* Returns the encrypted bytes or throws a JsError if encryption fails.
|
||||
* Note: This function does not provide authentication. Use encrypt_xsalsa20_poly1305 for authenticated encryption.
|
||||
*/
|
||||
export function encrypt_xsalsa20(key: Uint8Array, nonce_material: Uint8Array, plaintext: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function for XSalsa20 decryption without authentication.
|
||||
* - `key`: 32-byte key for decryption (must match encryption key)
|
||||
* - `nonce_material`: Raw bytes used to generate a 24-byte nonce (must match encryption)
|
||||
* - `ciphertext`: Encrypted bytes to decrypt
|
||||
* Returns the decrypted bytes or throws a JsError if decryption fails.
|
||||
* Note: This function does not provide authentication. Use decrypt_xsalsa20_poly1305 for authenticated decryption.
|
||||
*/
|
||||
export function decrypt_xsalsa20(key: Uint8Array, nonce_material: Uint8Array, ciphertext: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* Generate a new Ed25519 signing key using secure random number generation.
|
||||
* Returns 32 bytes of raw key material suitable for use with other Ed25519 functions.
|
||||
*/
|
||||
export function new_ed25519_signing_key(): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to derive an Ed25519 verifying key from a signing key.
|
||||
* - `signing_key`: 32 bytes of signing key material
|
||||
* Returns 32 bytes of verifying key material or throws JsError if key is invalid.
|
||||
*/
|
||||
export function ed25519_verifying_key(signing_key: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to sign a message using Ed25519.
|
||||
* - `signing_key`: 32 bytes of signing key material
|
||||
* - `message`: Raw bytes to sign
|
||||
* Returns 64 bytes of signature material or throws JsError if signing fails.
|
||||
*/
|
||||
export function ed25519_sign(signing_key: Uint8Array, message: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to verify an Ed25519 signature.
|
||||
* - `verifying_key`: 32 bytes of verifying key material
|
||||
* - `message`: Raw bytes that were signed
|
||||
* - `signature`: 64 bytes of signature material
|
||||
* Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
|
||||
*/
|
||||
export function ed25519_verify(verifying_key: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
||||
/**
|
||||
* WASM-exposed function to validate and copy Ed25519 signing key bytes.
|
||||
* - `bytes`: 32 bytes of signing key material to validate
|
||||
* Returns the same 32 bytes if valid or throws JsError if invalid.
|
||||
*/
|
||||
export function ed25519_signing_key_from_bytes(bytes: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to derive the public key from an Ed25519 signing key.
|
||||
* - `signing_key`: 32 bytes of signing key material
|
||||
* Returns 32 bytes of public key material or throws JsError if key is invalid.
|
||||
*/
|
||||
export function ed25519_signing_key_to_public(signing_key: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to sign a message with an Ed25519 signing key.
|
||||
* - `signing_key`: 32 bytes of signing key material
|
||||
* - `message`: Raw bytes to sign
|
||||
* Returns 64 bytes of signature material or throws JsError if signing fails.
|
||||
*/
|
||||
export function ed25519_signing_key_sign(signing_key: Uint8Array, message: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to validate and copy Ed25519 verifying key bytes.
|
||||
* - `bytes`: 32 bytes of verifying key material to validate
|
||||
* Returns the same 32 bytes if valid or throws JsError if invalid.
|
||||
*/
|
||||
export function ed25519_verifying_key_from_bytes(bytes: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to validate and copy Ed25519 signature bytes.
|
||||
* - `bytes`: 64 bytes of signature material to validate
|
||||
* Returns the same 64 bytes if valid or throws JsError if invalid.
|
||||
*/
|
||||
export function ed25519_signature_from_bytes(bytes: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to sign a message using Ed25519.
|
||||
* - `message`: Raw bytes to sign
|
||||
* - `secret`: Raw Ed25519 signing key bytes
|
||||
* Returns base58-encoded signature with "signature_z" prefix or throws JsError if signing fails.
|
||||
*/
|
||||
export function sign(message: Uint8Array, secret: Uint8Array): string;
|
||||
/**
|
||||
* WASM-exposed function to verify an Ed25519 signature.
|
||||
* - `signature`: Raw signature bytes
|
||||
* - `message`: Raw bytes that were signed
|
||||
* - `id`: Raw Ed25519 verifying key bytes
|
||||
* Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
|
||||
*/
|
||||
export function verify(signature: Uint8Array, message: Uint8Array, id: Uint8Array): boolean;
|
||||
/**
|
||||
* WASM-exposed function to derive a signer ID from a signing key.
|
||||
* - `secret`: Raw Ed25519 signing key bytes
|
||||
* Returns base58-encoded verifying key with "signer_z" prefix or throws JsError if derivation fails.
|
||||
*/
|
||||
export function get_signer_id(secret: Uint8Array): string;
|
||||
/**
|
||||
* Generate a 24-byte nonce from input material using BLAKE3.
|
||||
* - `nonce_material`: Raw bytes to derive the nonce from
|
||||
* Returns 24 bytes suitable for use as a nonce in cryptographic operations.
|
||||
* This function is deterministic - the same input will produce the same nonce.
|
||||
*/
|
||||
export function generate_nonce(nonce_material: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* Hash data once using BLAKE3.
|
||||
* - `data`: Raw bytes to hash
|
||||
* Returns 32 bytes of hash output.
|
||||
* This is the simplest way to compute a BLAKE3 hash of a single piece of data.
|
||||
*/
|
||||
export function blake3_hash_once(data: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* Hash data once using BLAKE3 with a context prefix.
|
||||
* - `data`: Raw bytes to hash
|
||||
* - `context`: Context bytes to prefix to the data
|
||||
* Returns 32 bytes of hash output.
|
||||
* This is useful for domain separation - the same data hashed with different contexts will produce different outputs.
|
||||
*/
|
||||
export function blake3_hash_once_with_context(data: Uint8Array, context: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* Get an empty BLAKE3 state for incremental hashing.
|
||||
* Returns a new Blake3Hasher instance for incremental hashing.
|
||||
*/
|
||||
export function blake3_empty_state(): Blake3Hasher;
|
||||
/**
|
||||
* Update a BLAKE3 state with new data for incremental hashing.
|
||||
* - `state`: Current Blake3Hasher instance
|
||||
* - `data`: New data to incorporate into the hash
|
||||
* Returns the updated Blake3Hasher.
|
||||
*/
|
||||
export function blake3_update_state(state: Blake3Hasher, data: Uint8Array): void;
|
||||
/**
|
||||
* Get the final hash from a BLAKE3 state.
|
||||
* - `state`: The Blake3Hasher to finalize
|
||||
* Returns 32 bytes of hash output.
|
||||
* This finalizes an incremental hashing operation.
|
||||
*/
|
||||
export function blake3_digest_for_state(state: Blake3Hasher): Uint8Array;
|
||||
/**
|
||||
* Generate a new X25519 private key using secure random number generation.
|
||||
* Returns 32 bytes of raw key material suitable for use with other X25519 functions.
|
||||
* This key can be reused for multiple Diffie-Hellman exchanges.
|
||||
*/
|
||||
export function new_x25519_private_key(): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to derive an X25519 public key from a private key.
|
||||
* - `private_key`: 32 bytes of private key material
|
||||
* Returns 32 bytes of public key material or throws JsError if key is invalid.
|
||||
*/
|
||||
export function x25519_public_key(private_key: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to perform X25519 Diffie-Hellman key exchange.
|
||||
* - `private_key`: 32 bytes of private key material
|
||||
* - `public_key`: 32 bytes of public key material
|
||||
* Returns 32 bytes of shared secret material or throws JsError if key exchange fails.
|
||||
*/
|
||||
export function x25519_diffie_hellman(private_key: Uint8Array, public_key: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to derive a sealer ID from a sealer secret.
|
||||
* - `secret`: Raw bytes of the sealer secret
|
||||
* Returns a base58-encoded sealer ID with "sealer_z" prefix or throws JsError if derivation fails.
|
||||
*/
|
||||
export function get_sealer_id(secret: Uint8Array): string;
|
||||
/**
|
||||
* WASM-exposed function for sealing a message using X25519 + XSalsa20-Poly1305.
|
||||
* Provides authenticated encryption with perfect forward secrecy.
|
||||
* - `message`: Raw bytes to seal
|
||||
* - `sender_secret`: Base58-encoded sender's private key with "sealerSecret_z" prefix
|
||||
* - `recipient_id`: Base58-encoded recipient's public key with "sealer_z" prefix
|
||||
* - `nonce_material`: Raw bytes used to generate the nonce
|
||||
* Returns sealed bytes or throws JsError if sealing fails.
|
||||
*/
|
||||
export function seal(message: Uint8Array, sender_secret: string, recipient_id: string, nonce_material: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function for unsealing a message using X25519 + XSalsa20-Poly1305.
|
||||
* Provides authenticated decryption with perfect forward secrecy.
|
||||
* - `sealed_message`: The sealed bytes to decrypt
|
||||
* - `recipient_secret`: Base58-encoded recipient's private key with "sealerSecret_z" prefix
|
||||
* - `sender_id`: Base58-encoded sender's public key with "sealer_z" prefix
|
||||
* - `nonce_material`: Raw bytes used to generate the nonce (must match sealing)
|
||||
* Returns unsealed bytes or throws JsError if unsealing fails.
|
||||
*/
|
||||
export function unseal(sealed_message: Uint8Array, recipient_secret: string, sender_id: string, nonce_material: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to encrypt bytes with a key secret and nonce material.
|
||||
* - `value`: The raw bytes to encrypt
|
||||
* - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
|
||||
* - `nonce_material`: Raw bytes used to generate the nonce
|
||||
* Returns the encrypted bytes or throws a JsError if encryption fails.
|
||||
*/
|
||||
export function encrypt(value: Uint8Array, key_secret: string, nonce_material: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* WASM-exposed function to decrypt bytes with a key secret and nonce material.
|
||||
* - `ciphertext`: The encrypted bytes to decrypt
|
||||
* - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
|
||||
* - `nonce_material`: Raw bytes used to generate the nonce (must match encryption)
|
||||
* Returns the decrypted bytes or throws a JsError if decryption fails.
|
||||
*/
|
||||
export function decrypt(ciphertext: Uint8Array, key_secret: string, nonce_material: Uint8Array): Uint8Array;
|
||||
export class Blake3Hasher {
|
||||
free(): void;
|
||||
constructor();
|
||||
update(data: Uint8Array): void;
|
||||
finalize(): Uint8Array;
|
||||
clone(): Blake3Hasher;
|
||||
}
|
||||
export class SessionLog {
|
||||
free(): void;
|
||||
constructor(co_id: string, session_id: string, signer_id?: string | null);
|
||||
clone(): SessionLog;
|
||||
tryAdd(transactions_json: string[], new_signature_str: string, skip_verify: boolean): void;
|
||||
addNewPrivateTransaction(changes_json: string, signer_secret: string, encryption_key: string, key_id: string, made_at: number): string;
|
||||
addNewTrustingTransaction(changes_json: string, signer_secret: string, made_at: number): string;
|
||||
decryptNextTransactionChangesJson(tx_index: number, encryption_key: string): string;
|
||||
}
|
||||
|
||||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||
|
||||
export interface InitOutput {
|
||||
readonly memory: WebAssembly.Memory;
|
||||
readonly decrypt_xsalsa20: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
||||
readonly encrypt_xsalsa20: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
||||
readonly __wbg_sessionlog_free: (a: number, b: number) => void;
|
||||
readonly sessionlog_new: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
||||
readonly sessionlog_clone: (a: number) => number;
|
||||
readonly sessionlog_tryAdd: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
||||
readonly sessionlog_addNewPrivateTransaction: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number, number];
|
||||
readonly sessionlog_addNewTrustingTransaction: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
||||
readonly sessionlog_decryptNextTransactionChangesJson: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
||||
readonly new_ed25519_signing_key: () => [number, number];
|
||||
readonly ed25519_sign: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
||||
readonly ed25519_verify: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
||||
readonly ed25519_signing_key_from_bytes: (a: number, b: number) => [number, number, number, number];
|
||||
readonly ed25519_signing_key_to_public: (a: number, b: number) => [number, number, number, number];
|
||||
readonly ed25519_verifying_key_from_bytes: (a: number, b: number) => [number, number, number, number];
|
||||
readonly ed25519_signature_from_bytes: (a: number, b: number) => [number, number, number, number];
|
||||
readonly ed25519_verifying_key: (a: number, b: number) => [number, number, number, number];
|
||||
readonly ed25519_signing_key_sign: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
||||
readonly sign: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
||||
readonly verify: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
||||
readonly get_signer_id: (a: number, b: number) => [number, number, number, number];
|
||||
readonly generate_nonce: (a: number, b: number) => [number, number];
|
||||
readonly blake3_hash_once: (a: number, b: number) => [number, number];
|
||||
readonly blake3_hash_once_with_context: (a: number, b: number, c: number, d: number) => [number, number];
|
||||
readonly __wbg_blake3hasher_free: (a: number, b: number) => void;
|
||||
readonly blake3hasher_finalize: (a: number) => [number, number];
|
||||
readonly blake3hasher_clone: (a: number) => number;
|
||||
readonly blake3_empty_state: () => number;
|
||||
readonly blake3_update_state: (a: number, b: number, c: number) => void;
|
||||
readonly blake3_digest_for_state: (a: number) => [number, number];
|
||||
readonly blake3hasher_update: (a: number, b: number, c: number) => void;
|
||||
readonly blake3hasher_new: () => number;
|
||||
readonly new_x25519_private_key: () => [number, number];
|
||||
readonly x25519_public_key: (a: number, b: number) => [number, number, number, number];
|
||||
readonly x25519_diffie_hellman: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
||||
readonly get_sealer_id: (a: number, b: number) => [number, number, number, number];
|
||||
readonly seal: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
|
||||
readonly unseal: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
|
||||
readonly encrypt: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
||||
readonly decrypt: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
||||
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
||||
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
||||
readonly __wbindgen_exn_store: (a: number) => void;
|
||||
readonly __externref_table_alloc: () => number;
|
||||
readonly __wbindgen_export_4: WebAssembly.Table;
|
||||
readonly __externref_table_dealloc: (a: number) => void;
|
||||
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
||||
readonly __wbindgen_start: () => void;
|
||||
}
|
||||
|
||||
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
||||
/**
|
||||
* Instantiates the given `module`, which can either be bytes or
|
||||
* a precompiled `WebAssembly.Module`.
|
||||
*
|
||||
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {InitOutput}
|
||||
*/
|
||||
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
||||
|
||||
/**
|
||||
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
||||
* for everything else, calls `WebAssembly.instantiate` directly.
|
||||
*
|
||||
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {Promise<InitOutput>}
|
||||
*/
|
||||
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
||||
1280
crates/cojson-core-wasm/public/cojson_core_wasm.js
Normal file
1
crates/cojson-core-wasm/public/cojson_core_wasm.wasm.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export const data: string;
|
||||
1
crates/cojson-core-wasm/public/cojson_core_wasm.wasm.js
Normal file
240
crates/cojson-core-wasm/src/crypto/ed25519.rs
Normal file
@@ -0,0 +1,240 @@
|
||||
use crate::error::CryptoError;
|
||||
use ed25519_dalek::{Signer, SigningKey, Verifier, VerifyingKey};
|
||||
use rand::rngs::OsRng;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Generate a new Ed25519 signing key using secure random number generation.
|
||||
/// Returns 32 bytes of raw key material suitable for use with other Ed25519 functions.
|
||||
#[wasm_bindgen]
|
||||
pub fn new_ed25519_signing_key() -> Box<[u8]> {
|
||||
let mut rng = OsRng;
|
||||
let signing_key = SigningKey::generate(&mut rng);
|
||||
signing_key.to_bytes().into()
|
||||
}
|
||||
|
||||
/// Internal function to derive an Ed25519 verifying key from a signing key.
|
||||
/// Takes 32 bytes of signing key material and returns 32 bytes of verifying key material.
|
||||
/// Returns CryptoError if the key length is invalid.
|
||||
pub(crate) fn ed25519_verifying_key_internal(signing_key: &[u8]) -> Result<Box<[u8]>, CryptoError> {
|
||||
let key_bytes: [u8; 32] = signing_key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, signing_key.len()))?;
|
||||
let signing_key = SigningKey::from_bytes(&key_bytes);
|
||||
Ok(signing_key.verifying_key().to_bytes().into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to derive an Ed25519 verifying key from a signing key.
|
||||
/// - `signing_key`: 32 bytes of signing key material
|
||||
/// Returns 32 bytes of verifying key material or throws JsError if key is invalid.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_verifying_key(signing_key: &[u8]) -> Result<Box<[u8]>, JsError> {
|
||||
ed25519_verifying_key_internal(signing_key).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
/// Internal function to sign a message using Ed25519.
|
||||
/// Takes 32 bytes of signing key material and arbitrary message bytes.
|
||||
/// Returns 64 bytes of signature material or CryptoError if key is invalid.
|
||||
pub(crate) fn ed25519_sign_internal(
|
||||
signing_key: &[u8],
|
||||
message: &[u8],
|
||||
) -> Result<[u8; 64], CryptoError> {
|
||||
let key_bytes: [u8; 32] = signing_key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, signing_key.len()))?;
|
||||
let signing_key = SigningKey::from_bytes(&key_bytes);
|
||||
Ok(signing_key.sign(message).to_bytes())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to sign a message using Ed25519.
|
||||
/// - `signing_key`: 32 bytes of signing key material
|
||||
/// - `message`: Raw bytes to sign
|
||||
/// Returns 64 bytes of signature material or throws JsError if signing fails.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_sign(signing_key: &[u8], message: &[u8]) -> Result<Box<[u8]>, JsError> {
|
||||
Ok(ed25519_sign_internal(signing_key, message)?.into())
|
||||
}
|
||||
|
||||
/// Internal function to verify an Ed25519 signature.
|
||||
/// - `verifying_key`: 32 bytes of verifying key material
|
||||
/// - `message`: Raw bytes that were signed
|
||||
/// - `signature`: 64 bytes of signature material
|
||||
/// Returns true if signature is valid, false otherwise, or CryptoError if key/signature format is invalid.
|
||||
pub(crate) fn ed25519_verify_internal(
|
||||
verifying_key: &[u8],
|
||||
message: &[u8],
|
||||
signature: &[u8],
|
||||
) -> Result<bool, CryptoError> {
|
||||
let key_bytes: [u8; 32] = verifying_key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, verifying_key.len()))?;
|
||||
let verifying_key = VerifyingKey::from_bytes(&key_bytes)
|
||||
.map_err(|e| CryptoError::InvalidVerifyingKey(e.to_string()))?;
|
||||
|
||||
let sig_bytes: [u8; 64] = signature
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidSignatureLength)?;
|
||||
let signature = ed25519_dalek::Signature::from_bytes(&sig_bytes);
|
||||
|
||||
Ok(verifying_key.verify(message, &signature).is_ok())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to verify an Ed25519 signature.
|
||||
/// - `verifying_key`: 32 bytes of verifying key material
|
||||
/// - `message`: Raw bytes that were signed
|
||||
/// - `signature`: 64 bytes of signature material
|
||||
/// Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_verify(
|
||||
verifying_key: &[u8],
|
||||
message: &[u8],
|
||||
signature: &[u8],
|
||||
) -> Result<bool, JsError> {
|
||||
ed25519_verify_internal(verifying_key, message, signature)
|
||||
.map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
/// WASM-exposed function to validate and copy Ed25519 signing key bytes.
|
||||
/// - `bytes`: 32 bytes of signing key material to validate
|
||||
/// Returns the same 32 bytes if valid or throws JsError if invalid.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_signing_key_from_bytes(bytes: &[u8]) -> Result<Box<[u8]>, JsError> {
|
||||
let key_bytes: [u8; 32] = bytes
|
||||
.try_into()
|
||||
.map_err(|_| JsError::new("Invalid signing key length"))?;
|
||||
Ok(key_bytes.into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to derive the public key from an Ed25519 signing key.
|
||||
/// - `signing_key`: 32 bytes of signing key material
|
||||
/// Returns 32 bytes of public key material or throws JsError if key is invalid.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_signing_key_to_public(signing_key: &[u8]) -> Result<Box<[u8]>, JsError> {
|
||||
ed25519_verifying_key_internal(signing_key).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
/// WASM-exposed function to sign a message with an Ed25519 signing key.
|
||||
/// - `signing_key`: 32 bytes of signing key material
|
||||
/// - `message`: Raw bytes to sign
|
||||
/// Returns 64 bytes of signature material or throws JsError if signing fails.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_signing_key_sign(signing_key: &[u8], message: &[u8]) -> Result<Box<[u8]>, JsError> {
|
||||
Ok(ed25519_sign_internal(signing_key, message)?.into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to validate and copy Ed25519 verifying key bytes.
|
||||
/// - `bytes`: 32 bytes of verifying key material to validate
|
||||
/// Returns the same 32 bytes if valid or throws JsError if invalid.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_verifying_key_from_bytes(bytes: &[u8]) -> Result<Box<[u8]>, JsError> {
|
||||
let key_bytes: [u8; 32] = bytes
|
||||
.try_into()
|
||||
.map_err(|_| JsError::new("Invalid verifying key length"))?;
|
||||
Ok(key_bytes.into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to validate and copy Ed25519 signature bytes.
|
||||
/// - `bytes`: 64 bytes of signature material to validate
|
||||
/// Returns the same 64 bytes if valid or throws JsError if invalid.
|
||||
#[wasm_bindgen]
|
||||
pub fn ed25519_signature_from_bytes(bytes: &[u8]) -> Result<Box<[u8]>, JsError> {
|
||||
let sig_bytes: [u8; 64] = bytes
|
||||
.try_into()
|
||||
.map_err(|_| JsError::new("Invalid signature length"))?;
|
||||
Ok(sig_bytes.into())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_ed25519_key_generation_and_signing() {
|
||||
// Test key generation
|
||||
let signing_key = new_ed25519_signing_key();
|
||||
assert_eq!(signing_key.len(), 32, "Signing key should be 32 bytes");
|
||||
|
||||
// Test verifying key derivation
|
||||
let verifying_key = ed25519_verifying_key_internal(&signing_key).unwrap();
|
||||
assert_eq!(verifying_key.len(), 32, "Verifying key should be 32 bytes");
|
||||
|
||||
// Test that different signing keys produce different verifying keys
|
||||
let signing_key2 = new_ed25519_signing_key();
|
||||
let verifying_key2 = ed25519_verifying_key_internal(&signing_key2).unwrap();
|
||||
assert_ne!(
|
||||
verifying_key, verifying_key2,
|
||||
"Different signing keys should produce different verifying keys"
|
||||
);
|
||||
|
||||
// Test signing and verification
|
||||
let message = b"Test message";
|
||||
let signature = ed25519_sign_internal(&signing_key, message).unwrap();
|
||||
assert_eq!(signature.len(), 64, "Signature should be 64 bytes");
|
||||
|
||||
// Test successful verification
|
||||
let verification_result =
|
||||
ed25519_verify_internal(&verifying_key, message, &signature).unwrap();
|
||||
assert!(
|
||||
verification_result,
|
||||
"Valid signature should verify successfully"
|
||||
);
|
||||
|
||||
// Test verification with wrong message
|
||||
let wrong_message = b"Wrong message";
|
||||
let wrong_verification =
|
||||
ed25519_verify_internal(&verifying_key, wrong_message, &signature).unwrap();
|
||||
assert!(
|
||||
!wrong_verification,
|
||||
"Signature should not verify with wrong message"
|
||||
);
|
||||
|
||||
// Test verification with wrong key
|
||||
let wrong_verification =
|
||||
ed25519_verify_internal(&verifying_key2, message, &signature).unwrap();
|
||||
assert!(
|
||||
!wrong_verification,
|
||||
"Signature should not verify with wrong key"
|
||||
);
|
||||
|
||||
// Test verification with tampered signature
|
||||
let mut tampered_signature = signature.clone();
|
||||
tampered_signature[0] ^= 1;
|
||||
let wrong_verification =
|
||||
ed25519_verify_internal(&verifying_key, message, &tampered_signature).unwrap();
|
||||
assert!(!wrong_verification, "Tampered signature should not verify");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ed25519_error_cases() {
|
||||
// Test invalid signing key length
|
||||
let invalid_signing_key = vec![0u8; 31]; // Too short
|
||||
let result = ed25519_verifying_key_internal(&invalid_signing_key);
|
||||
assert!(result.is_err());
|
||||
let result = ed25519_sign_internal(&invalid_signing_key, b"test");
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test invalid verifying key length
|
||||
let invalid_verifying_key = vec![0u8; 31]; // Too short
|
||||
let valid_signing_key = new_ed25519_signing_key();
|
||||
let valid_signature = ed25519_sign_internal(&valid_signing_key, b"test").unwrap();
|
||||
let result = ed25519_verify_internal(&invalid_verifying_key, b"test", &valid_signature);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test invalid signature length
|
||||
let valid_verifying_key = ed25519_verifying_key_internal(&valid_signing_key).unwrap();
|
||||
let invalid_signature = vec![0u8; 63]; // Too short
|
||||
let result = ed25519_verify_internal(&valid_verifying_key, b"test", &invalid_signature);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with too long keys
|
||||
let too_long_key = vec![0u8; 33]; // Too long
|
||||
let result = ed25519_verifying_key_internal(&too_long_key);
|
||||
assert!(result.is_err());
|
||||
let result = ed25519_sign_internal(&too_long_key, b"test");
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with too long signature
|
||||
let too_long_signature = vec![0u8; 65]; // Too long
|
||||
let result = ed25519_verify_internal(&valid_verifying_key, b"test", &too_long_signature);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
113
crates/cojson-core-wasm/src/crypto/encrypt.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
use crate::error::CryptoError;
|
||||
use crate::hash::blake3::generate_nonce;
|
||||
use bs58;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Internal function to encrypt bytes with a key secret and nonce material.
|
||||
/// Takes a base58-encoded key secret with "keySecret_z" prefix and raw nonce material.
|
||||
/// Returns the encrypted bytes or a CryptoError if the key format is invalid.
|
||||
pub fn encrypt_internal(
|
||||
plaintext: &[u8],
|
||||
key_secret: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Box<[u8]>, CryptoError> {
|
||||
// Decode the base58 key secret (removing the "keySecret_z" prefix)
|
||||
let key_secret = key_secret
|
||||
.strip_prefix("keySecret_z")
|
||||
.ok_or(CryptoError::InvalidPrefix("key secret", "keySecret_z"))?;
|
||||
let key = bs58::decode(key_secret)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
// Generate nonce from nonce material
|
||||
let nonce = generate_nonce(nonce_material);
|
||||
|
||||
// Encrypt using XSalsa20
|
||||
Ok(super::xsalsa20::encrypt_xsalsa20_raw_internal(&key, &nonce, plaintext)?.into())
|
||||
}
|
||||
|
||||
/// Internal function to decrypt bytes with a key secret and nonce material.
|
||||
/// Takes a base58-encoded key secret with "keySecret_z" prefix and raw nonce material.
|
||||
/// Returns the decrypted bytes or a CryptoError if the key format is invalid.
|
||||
pub fn decrypt_internal(
|
||||
ciphertext: &[u8],
|
||||
key_secret: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Box<[u8]>, CryptoError> {
|
||||
// Decode the base58 key secret (removing the "keySecret_z" prefix)
|
||||
let key_secret = key_secret
|
||||
.strip_prefix("keySecret_z")
|
||||
.ok_or(CryptoError::InvalidPrefix("key secret", "keySecret_z"))?;
|
||||
let key = bs58::decode(key_secret)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
// Generate nonce from nonce material
|
||||
let nonce = generate_nonce(nonce_material);
|
||||
|
||||
// Decrypt using XSalsa20
|
||||
Ok(super::xsalsa20::decrypt_xsalsa20_raw_internal(&key, &nonce, ciphertext)?.into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to encrypt bytes with a key secret and nonce material.
|
||||
/// - `value`: The raw bytes to encrypt
|
||||
/// - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
|
||||
/// - `nonce_material`: Raw bytes used to generate the nonce
|
||||
/// Returns the encrypted bytes or throws a JsError if encryption fails.
|
||||
#[wasm_bindgen(js_name = encrypt)]
|
||||
pub fn encrypt(
|
||||
value: &[u8],
|
||||
key_secret: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Box<[u8]>, JsError> {
|
||||
encrypt_internal(value, key_secret, nonce_material).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
/// WASM-exposed function to decrypt bytes with a key secret and nonce material.
|
||||
/// - `ciphertext`: The encrypted bytes to decrypt
|
||||
/// - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
|
||||
/// - `nonce_material`: Raw bytes used to generate the nonce (must match encryption)
|
||||
/// Returns the decrypted bytes or throws a JsError if decryption fails.
|
||||
#[wasm_bindgen(js_name = decrypt)]
|
||||
pub fn decrypt(
|
||||
ciphertext: &[u8],
|
||||
key_secret: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Box<[u8]>, JsError> {
|
||||
Ok(decrypt_internal(ciphertext, key_secret, nonce_material)?.into())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_encrypt_decrypt() {
|
||||
// Test data
|
||||
let plaintext = b"Hello, World!";
|
||||
let key_secret = "keySecret_z11111111111111111111111111111111"; // Example base58 encoded key
|
||||
let nonce_material = b"test_nonce_material";
|
||||
|
||||
// Test encryption
|
||||
let ciphertext = encrypt_internal(plaintext, key_secret, nonce_material).unwrap();
|
||||
assert!(!ciphertext.is_empty());
|
||||
|
||||
// Test decryption
|
||||
let decrypted = decrypt_internal(&ciphertext, key_secret, nonce_material).unwrap();
|
||||
assert_eq!(&*decrypted, plaintext);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_key_secret() {
|
||||
let plaintext = b"test";
|
||||
let nonce_material = b"nonce";
|
||||
|
||||
// Test with invalid key secret format
|
||||
let result = encrypt_internal(plaintext, "invalid_key", nonce_material);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with invalid base58 encoding
|
||||
let result = encrypt_internal(plaintext, "keySecret_z!!!!", nonce_material);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
200
crates/cojson-core-wasm/src/crypto/seal.rs
Normal file
@@ -0,0 +1,200 @@
|
||||
use crate::crypto::x25519::x25519_diffie_hellman_internal;
|
||||
use crate::crypto::xsalsa20::{decrypt_xsalsa20_poly1305, encrypt_xsalsa20_poly1305};
|
||||
use crate::error::CryptoError;
|
||||
use crate::hash::blake3::generate_nonce;
|
||||
use bs58;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Internal function to seal a message using X25519 + XSalsa20-Poly1305.
|
||||
/// - `message`: Raw bytes to seal
|
||||
/// - `sender_secret`: Base58-encoded sender's private key with "sealerSecret_z" prefix
|
||||
/// - `recipient_id`: Base58-encoded recipient's public key with "sealer_z" prefix
|
||||
/// - `nonce_material`: Raw bytes used to generate the nonce
|
||||
/// Returns sealed bytes or CryptoError if key formats are invalid.
|
||||
///
|
||||
/// The sealing process:
|
||||
/// 1. Decode base58 keys and validate prefixes
|
||||
/// 2. Generate shared secret using X25519 key exchange
|
||||
/// 3. Generate nonce from nonce material using BLAKE3
|
||||
/// 4. Encrypt message using XSalsa20-Poly1305 with the shared secret
|
||||
pub fn seal_internal(
|
||||
message: &[u8],
|
||||
sender_secret: &str,
|
||||
recipient_id: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Vec<u8>, CryptoError> {
|
||||
// Decode the base58 sender secret (removing the "sealerSecret_z" prefix)
|
||||
let sender_secret =
|
||||
sender_secret
|
||||
.strip_prefix("sealerSecret_z")
|
||||
.ok_or(CryptoError::InvalidPrefix(
|
||||
"sealer secret",
|
||||
"sealerSecret_z",
|
||||
))?;
|
||||
let sender_private_key = bs58::decode(sender_secret)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
// Decode the base58 recipient ID (removing the "sealer_z" prefix)
|
||||
let recipient_id = recipient_id
|
||||
.strip_prefix("sealer_z")
|
||||
.ok_or(CryptoError::InvalidPrefix("sealer ID", "sealer_z"))?;
|
||||
let recipient_public_key = bs58::decode(recipient_id)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
let nonce = generate_nonce(nonce_material);
|
||||
|
||||
// Generate shared secret using X25519
|
||||
let shared_secret = x25519_diffie_hellman_internal(&sender_private_key, &recipient_public_key)?;
|
||||
|
||||
// Encrypt message using XSalsa20-Poly1305
|
||||
Ok(encrypt_xsalsa20_poly1305(&shared_secret, &nonce, message)?.into())
|
||||
}
|
||||
|
||||
/// Internal function to unseal a message using X25519 + XSalsa20-Poly1305.
|
||||
/// - `sealed_message`: The sealed bytes to decrypt
|
||||
/// - `recipient_secret`: Base58-encoded recipient's private key with "sealerSecret_z" prefix
|
||||
/// - `sender_id`: Base58-encoded sender's public key with "sealer_z" prefix
|
||||
/// - `nonce_material`: Raw bytes used to generate the nonce (must match sealing)
|
||||
/// Returns unsealed bytes or CryptoError if key formats are invalid or authentication fails.
|
||||
///
|
||||
/// The unsealing process:
|
||||
/// 1. Decode base58 keys and validate prefixes
|
||||
/// 2. Generate shared secret using X25519 key exchange
|
||||
/// 3. Generate nonce from nonce material using BLAKE3
|
||||
/// 4. Decrypt and authenticate message using XSalsa20-Poly1305 with the shared secret
|
||||
fn unseal_internal(
|
||||
sealed_message: &[u8],
|
||||
recipient_secret: &str,
|
||||
sender_id: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Box<[u8]>, CryptoError> {
|
||||
// Decode the base58 recipient secret (removing the "sealerSecret_z" prefix)
|
||||
let recipient_secret =
|
||||
recipient_secret
|
||||
.strip_prefix("sealerSecret_z")
|
||||
.ok_or(CryptoError::InvalidPrefix(
|
||||
"sealer secret",
|
||||
"sealerSecret_z",
|
||||
))?;
|
||||
let recipient_private_key = bs58::decode(recipient_secret)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
// Decode the base58 sender ID (removing the "sealer_z" prefix)
|
||||
let sender_id = sender_id
|
||||
.strip_prefix("sealer_z")
|
||||
.ok_or(CryptoError::InvalidPrefix("sealer ID", "sealer_z"))?;
|
||||
let sender_public_key = bs58::decode(sender_id)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
let nonce = generate_nonce(nonce_material);
|
||||
|
||||
// Generate shared secret using X25519
|
||||
let shared_secret = x25519_diffie_hellman_internal(&recipient_private_key, &sender_public_key)?;
|
||||
|
||||
// Decrypt message using XSalsa20-Poly1305
|
||||
Ok(decrypt_xsalsa20_poly1305(&shared_secret, &nonce, sealed_message)?.into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function for sealing a message using X25519 + XSalsa20-Poly1305.
|
||||
/// Provides authenticated encryption with perfect forward secrecy.
|
||||
/// - `message`: Raw bytes to seal
|
||||
/// - `sender_secret`: Base58-encoded sender's private key with "sealerSecret_z" prefix
|
||||
/// - `recipient_id`: Base58-encoded recipient's public key with "sealer_z" prefix
|
||||
/// - `nonce_material`: Raw bytes used to generate the nonce
|
||||
/// Returns sealed bytes or throws JsError if sealing fails.
|
||||
#[wasm_bindgen(js_name = seal)]
|
||||
pub fn seal(
|
||||
message: &[u8],
|
||||
sender_secret: &str,
|
||||
recipient_id: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Box<[u8]>, JsError> {
|
||||
Ok(seal_internal(message, sender_secret, recipient_id, nonce_material)?.into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function for unsealing a message using X25519 + XSalsa20-Poly1305.
|
||||
/// Provides authenticated decryption with perfect forward secrecy.
|
||||
/// - `sealed_message`: The sealed bytes to decrypt
|
||||
/// - `recipient_secret`: Base58-encoded recipient's private key with "sealerSecret_z" prefix
|
||||
/// - `sender_id`: Base58-encoded sender's public key with "sealer_z" prefix
|
||||
/// - `nonce_material`: Raw bytes used to generate the nonce (must match sealing)
|
||||
/// Returns unsealed bytes or throws JsError if unsealing fails.
|
||||
#[wasm_bindgen(js_name = unseal)]
|
||||
pub fn unseal(
|
||||
sealed_message: &[u8],
|
||||
recipient_secret: &str,
|
||||
sender_id: &str,
|
||||
nonce_material: &[u8],
|
||||
) -> Result<Box<[u8]>, JsError> {
|
||||
Ok(unseal_internal(sealed_message, recipient_secret, sender_id, nonce_material)?.into())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::crypto::x25519::{new_x25519_private_key, x25519_public_key_internal};
|
||||
|
||||
#[test]
|
||||
fn test_seal_unseal() {
|
||||
// Generate real keys
|
||||
let sender_private = new_x25519_private_key();
|
||||
let sender_public = x25519_public_key_internal(&sender_private).unwrap();
|
||||
|
||||
// Encode keys with proper prefixes
|
||||
let sender_secret = format!(
|
||||
"sealerSecret_z{}",
|
||||
bs58::encode(&sender_private).into_string()
|
||||
);
|
||||
let recipient_id = format!("sealer_z{}", bs58::encode(&sender_public).into_string());
|
||||
|
||||
// Test data
|
||||
let message = b"Secret message";
|
||||
let nonce_material = b"test_nonce_material";
|
||||
|
||||
// Test sealing
|
||||
let sealed = seal_internal(message, &sender_secret, &recipient_id, nonce_material).unwrap();
|
||||
assert!(!sealed.is_empty());
|
||||
|
||||
// Test unsealing (using same keys since it's a test)
|
||||
let unsealed =
|
||||
unseal_internal(&sealed, &sender_secret, &recipient_id, nonce_material).unwrap();
|
||||
assert_eq!(&*unsealed, message);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_keys() {
|
||||
let message = b"test";
|
||||
let nonce_material = b"nonce";
|
||||
|
||||
// Test with invalid sender secret format
|
||||
let result = seal_internal(
|
||||
message,
|
||||
"invalid_key",
|
||||
"sealer_z22222222222222222222222222222222",
|
||||
nonce_material,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with invalid recipient ID format
|
||||
let result = seal_internal(
|
||||
message,
|
||||
"sealerSecret_z11111111111111111111111111111111",
|
||||
"invalid_key",
|
||||
nonce_material,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with invalid base58 encoding
|
||||
let result = seal_internal(
|
||||
message,
|
||||
"sealerSecret_z!!!!",
|
||||
"sealer_z22222222222222222222222222222222",
|
||||
nonce_material,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
184
crates/cojson-core-wasm/src/crypto/sign.rs
Normal file
@@ -0,0 +1,184 @@
|
||||
use crate::crypto::ed25519::{
|
||||
ed25519_sign_internal, ed25519_verify_internal, ed25519_verifying_key_internal,
|
||||
};
|
||||
use crate::error::CryptoError;
|
||||
use bs58;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Internal function to sign a message using Ed25519.
|
||||
/// - `message`: Raw bytes to sign
|
||||
/// - `secret`: Base58-encoded signing key with "signerSecret_z" prefix
|
||||
/// Returns base58-encoded signature with "signature_z" prefix or error string.
|
||||
pub fn sign_internal(message: &[u8], secret: &str) -> Result<String, CryptoError> {
|
||||
let secret_bytes = bs58::decode(secret.strip_prefix("signerSecret_z").ok_or(
|
||||
CryptoError::InvalidPrefix("signer secret", "signerSecret_z"),
|
||||
)?)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
let signature = ed25519_sign_internal(&secret_bytes, message)
|
||||
.map_err(|e| CryptoError::InvalidVerifyingKey(e.to_string()))?;
|
||||
Ok(format!(
|
||||
"signature_z{}",
|
||||
bs58::encode(signature).into_string()
|
||||
))
|
||||
}
|
||||
|
||||
/// Internal function to verify an Ed25519 signature.
|
||||
/// - `signature`: Base58-encoded signature with "signature_z" prefix
|
||||
/// - `message`: Raw bytes that were signed
|
||||
/// - `id`: Base58-encoded verifying key with "signer_z" prefix
|
||||
/// Returns true if signature is valid, false otherwise, or error string if formats are invalid.
|
||||
pub fn verify_internal(signature: &str, message: &[u8], id: &str) -> Result<bool, CryptoError> {
|
||||
let signature_bytes = bs58::decode(
|
||||
signature
|
||||
.strip_prefix("signature_z")
|
||||
.ok_or(CryptoError::InvalidPrefix("signature_z", "signature"))?,
|
||||
)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
let verifying_key = bs58::decode(
|
||||
id.strip_prefix("signer_z")
|
||||
.ok_or(CryptoError::InvalidPrefix("signer_z", "signer ID"))?,
|
||||
)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
ed25519_verify_internal(&verifying_key, message, &signature_bytes)
|
||||
.map_err(|e| CryptoError::InvalidVerifyingKey(e.to_string()))
|
||||
}
|
||||
|
||||
/// Internal function to derive a signer ID from a signing key.
|
||||
/// - `secret`: Base58-encoded signing key with "signerSecret_z" prefix
|
||||
/// Returns base58-encoded verifying key with "signer_z" prefix or error string.
|
||||
pub fn get_signer_id_internal(secret: &str) -> Result<String, CryptoError> {
|
||||
let secret_bytes = bs58::decode(secret.strip_prefix("signerSecret_z").ok_or(
|
||||
CryptoError::InvalidPrefix("signerSecret_z", "signer secret"),
|
||||
)?)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
let verifying_key = ed25519_verifying_key_internal(&secret_bytes)
|
||||
.map_err(|e| CryptoError::InvalidVerifyingKey(e.to_string()))?;
|
||||
|
||||
Ok(format!(
|
||||
"signer_z{}",
|
||||
bs58::encode(verifying_key).into_string()
|
||||
))
|
||||
}
|
||||
|
||||
/// WASM-exposed function to sign a message using Ed25519.
|
||||
/// - `message`: Raw bytes to sign
|
||||
/// - `secret`: Raw Ed25519 signing key bytes
|
||||
/// Returns base58-encoded signature with "signature_z" prefix or throws JsError if signing fails.
|
||||
#[wasm_bindgen(js_name = sign)]
|
||||
pub fn sign(message: &[u8], secret: &[u8]) -> Result<String, JsError> {
|
||||
let secret_str = std::str::from_utf8(secret)
|
||||
.map_err(|e| JsError::new(&format!("Invalid UTF-8 in secret: {:?}", e)))?;
|
||||
sign_internal(message, secret_str).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
/// WASM-exposed function to verify an Ed25519 signature.
|
||||
/// - `signature`: Raw signature bytes
|
||||
/// - `message`: Raw bytes that were signed
|
||||
/// - `id`: Raw Ed25519 verifying key bytes
|
||||
/// Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
|
||||
#[wasm_bindgen(js_name = verify)]
|
||||
pub fn verify(signature: &[u8], message: &[u8], id: &[u8]) -> Result<bool, JsError> {
|
||||
let signature_str = std::str::from_utf8(signature)
|
||||
.map_err(|e| JsError::new(&format!("Invalid UTF-8 in signature: {:?}", e)))?;
|
||||
let id_str = std::str::from_utf8(id)
|
||||
.map_err(|e| JsError::new(&format!("Invalid UTF-8 in id: {:?}", e)))?;
|
||||
verify_internal(signature_str, message, id_str).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
/// WASM-exposed function to derive a signer ID from a signing key.
|
||||
/// - `secret`: Raw Ed25519 signing key bytes
|
||||
/// Returns base58-encoded verifying key with "signer_z" prefix or throws JsError if derivation fails.
|
||||
#[wasm_bindgen(js_name = get_signer_id)]
|
||||
pub fn get_signer_id(secret: &[u8]) -> Result<String, JsError> {
|
||||
let secret_str = std::str::from_utf8(secret)
|
||||
.map_err(|e| JsError::new(&format!("Invalid UTF-8 in secret: {:?}", e)))?;
|
||||
get_signer_id_internal(secret_str).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::crypto::ed25519::new_ed25519_signing_key;
|
||||
|
||||
#[test]
|
||||
fn test_sign_and_verify() {
|
||||
let message = b"hello world";
|
||||
|
||||
// Create a test signing key
|
||||
let signing_key = new_ed25519_signing_key();
|
||||
let secret = format!("signerSecret_z{}", bs58::encode(&signing_key).into_string());
|
||||
|
||||
// Sign the message
|
||||
let signature = sign_internal(message, &secret).unwrap();
|
||||
|
||||
// Get the public key for verification
|
||||
let secret_bytes = bs58::decode(secret.strip_prefix("signerSecret_z").unwrap())
|
||||
.into_vec()
|
||||
.unwrap();
|
||||
let verifying_key = ed25519_verifying_key_internal(&secret_bytes).unwrap();
|
||||
let signer_id = format!("signer_z{}", bs58::encode(&verifying_key).into_string());
|
||||
|
||||
// Verify the signature
|
||||
assert!(verify_internal(&signature, message, &signer_id).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_inputs() {
|
||||
let message = b"hello world";
|
||||
|
||||
// Test invalid base58 in secret
|
||||
let result = sign_internal(message, "signerSecret_z!!!invalid!!!");
|
||||
assert!(matches!(result, Err(CryptoError::Base58Error(_))));
|
||||
|
||||
// Test invalid signature format
|
||||
let result = verify_internal("not_a_signature", message, "signer_z123");
|
||||
assert!(matches!(
|
||||
result,
|
||||
Err(CryptoError::InvalidPrefix("signature_z", "signature"))
|
||||
));
|
||||
|
||||
// Test invalid signer ID format
|
||||
let result = verify_internal("signature_z123", message, "not_a_signer");
|
||||
assert!(matches!(
|
||||
result,
|
||||
Err(CryptoError::InvalidPrefix("signer_z", "signer ID"))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_signer_id() {
|
||||
// Create a test signing key
|
||||
let signing_key = new_ed25519_signing_key();
|
||||
let secret = format!("signerSecret_z{}", bs58::encode(&signing_key).into_string());
|
||||
|
||||
// Get signer ID
|
||||
let signer_id = get_signer_id_internal(&secret).unwrap();
|
||||
assert!(signer_id.starts_with("signer_z"));
|
||||
|
||||
// Test that same secret produces same ID
|
||||
let signer_id2 = get_signer_id_internal(&secret).unwrap();
|
||||
assert_eq!(signer_id, signer_id2);
|
||||
|
||||
// Test invalid secret format
|
||||
let result = get_signer_id_internal("invalid_secret");
|
||||
assert!(matches!(
|
||||
result,
|
||||
Err(CryptoError::InvalidPrefix(
|
||||
"signerSecret_z",
|
||||
"signer secret"
|
||||
))
|
||||
));
|
||||
|
||||
// Test invalid base58
|
||||
let result = get_signer_id_internal("signerSecret_z!!!invalid!!!");
|
||||
assert!(matches!(result, Err(CryptoError::Base58Error(_))));
|
||||
}
|
||||
}
|
||||
168
crates/cojson-core-wasm/src/crypto/x25519.rs
Normal file
@@ -0,0 +1,168 @@
|
||||
use crate::error::CryptoError;
|
||||
use bs58;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use x25519_dalek::{PublicKey, StaticSecret};
|
||||
|
||||
/// Generate a new X25519 private key using secure random number generation.
|
||||
/// Returns 32 bytes of raw key material suitable for use with other X25519 functions.
|
||||
/// This key can be reused for multiple Diffie-Hellman exchanges.
|
||||
#[wasm_bindgen]
|
||||
pub fn new_x25519_private_key() -> Vec<u8> {
|
||||
let secret = StaticSecret::random();
|
||||
secret.to_bytes().to_vec()
|
||||
}
|
||||
|
||||
/// Internal function to derive an X25519 public key from a private key.
|
||||
/// Takes 32 bytes of private key material and returns 32 bytes of public key material.
|
||||
/// Returns CryptoError if the key length is invalid.
|
||||
pub(crate) fn x25519_public_key_internal(private_key: &[u8]) -> Result<[u8; 32], CryptoError> {
|
||||
let bytes: [u8; 32] = private_key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, private_key.len()))?;
|
||||
let secret = StaticSecret::from(bytes);
|
||||
Ok(PublicKey::from(&secret).to_bytes())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to derive an X25519 public key from a private key.
|
||||
/// - `private_key`: 32 bytes of private key material
|
||||
/// Returns 32 bytes of public key material or throws JsError if key is invalid.
|
||||
#[wasm_bindgen]
|
||||
pub fn x25519_public_key(private_key: &[u8]) -> Result<Vec<u8>, JsError> {
|
||||
Ok(x25519_public_key_internal(private_key)?.to_vec())
|
||||
}
|
||||
|
||||
/// Internal function to perform X25519 Diffie-Hellman key exchange.
|
||||
/// Takes 32 bytes each of private and public key material.
|
||||
/// Returns 32 bytes of shared secret material or CryptoError if key lengths are invalid.
|
||||
pub(crate) fn x25519_diffie_hellman_internal(
|
||||
private_key: &[u8],
|
||||
public_key: &[u8],
|
||||
) -> Result<[u8; 32], CryptoError> {
|
||||
let private_bytes: [u8; 32] = private_key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, private_key.len()))?;
|
||||
let public_bytes: [u8; 32] = public_key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, public_key.len()))?;
|
||||
let secret = StaticSecret::from(private_bytes);
|
||||
let public = PublicKey::from(public_bytes);
|
||||
Ok(secret.diffie_hellman(&public).to_bytes())
|
||||
}
|
||||
|
||||
/// WASM-exposed function to perform X25519 Diffie-Hellman key exchange.
|
||||
/// - `private_key`: 32 bytes of private key material
|
||||
/// - `public_key`: 32 bytes of public key material
|
||||
/// Returns 32 bytes of shared secret material or throws JsError if key exchange fails.
|
||||
#[wasm_bindgen]
|
||||
pub fn x25519_diffie_hellman(private_key: &[u8], public_key: &[u8]) -> Result<Vec<u8>, JsError> {
|
||||
Ok(x25519_diffie_hellman_internal(private_key, public_key)?.to_vec())
|
||||
}
|
||||
|
||||
/// Internal function to derive a sealer ID from a sealer secret.
|
||||
/// Takes a base58-encoded sealer secret with "sealerSecret_z" prefix.
|
||||
/// Returns a base58-encoded sealer ID with "sealer_z" prefix or error string if format is invalid.
|
||||
pub fn get_sealer_id_internal(secret: &str) -> Result<String, CryptoError> {
|
||||
let private_bytes = bs58::decode(secret.strip_prefix("sealerSecret_z").ok_or(
|
||||
CryptoError::InvalidPrefix("sealerSecret_z", "sealer secret"),
|
||||
)?)
|
||||
.into_vec()
|
||||
.map_err(|e| CryptoError::Base58Error(e.to_string()))?;
|
||||
|
||||
let public_bytes = x25519_public_key_internal(&private_bytes)
|
||||
.map_err(|e| CryptoError::InvalidPublicKey(e.to_string()))?;
|
||||
|
||||
Ok(format!(
|
||||
"sealer_z{}",
|
||||
bs58::encode(public_bytes).into_string()
|
||||
))
|
||||
}
|
||||
|
||||
/// WASM-exposed function to derive a sealer ID from a sealer secret.
|
||||
/// - `secret`: Raw bytes of the sealer secret
|
||||
/// Returns a base58-encoded sealer ID with "sealer_z" prefix or throws JsError if derivation fails.
|
||||
#[wasm_bindgen]
|
||||
pub fn get_sealer_id(secret: &[u8]) -> Result<String, JsError> {
|
||||
let secret_str = std::str::from_utf8(secret)
|
||||
.map_err(|e| JsError::new(&format!("Invalid UTF-8 in secret: {:?}", e)))?;
|
||||
get_sealer_id_internal(secret_str).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_x25519_key_generation() {
|
||||
// Test that we get the correct length keys
|
||||
let private_key = new_x25519_private_key();
|
||||
assert_eq!(private_key.len(), 32);
|
||||
|
||||
// Test that public key generation works and produces correct length
|
||||
let public_key = x25519_public_key_internal(&private_key).unwrap();
|
||||
assert_eq!(public_key.len(), 32);
|
||||
|
||||
// Test that different private keys produce different public keys
|
||||
let private_key2 = new_x25519_private_key();
|
||||
let public_key2 = x25519_public_key_internal(&private_key2).unwrap();
|
||||
assert_ne!(public_key, public_key2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_x25519_key_exchange() {
|
||||
// Generate sender's keypair
|
||||
let sender_private = new_x25519_private_key();
|
||||
let sender_public = x25519_public_key_internal(&sender_private).unwrap();
|
||||
|
||||
// Generate recipient's keypair
|
||||
let recipient_private = new_x25519_private_key();
|
||||
let recipient_public = x25519_public_key_internal(&recipient_private).unwrap();
|
||||
|
||||
// Test properties we expect from the shared secret
|
||||
let shared_secret1 =
|
||||
x25519_diffie_hellman_internal(&sender_private, &recipient_public).unwrap();
|
||||
let shared_secret2 =
|
||||
x25519_diffie_hellman_internal(&recipient_private, &sender_public).unwrap();
|
||||
|
||||
// Both sides should arrive at the same shared secret
|
||||
assert_eq!(shared_secret1, shared_secret2);
|
||||
|
||||
// Shared secret should be 32 bytes
|
||||
assert_eq!(shared_secret1.len(), 32);
|
||||
|
||||
// Different recipient should produce different shared secret
|
||||
let other_recipient_private = new_x25519_private_key();
|
||||
let other_recipient_public = x25519_public_key_internal(&other_recipient_private).unwrap();
|
||||
let different_shared_secret =
|
||||
x25519_diffie_hellman_internal(&sender_private, &other_recipient_public).unwrap();
|
||||
assert_ne!(shared_secret1, different_shared_secret);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_sealer_id() {
|
||||
// Create a test private key
|
||||
let private_key = new_x25519_private_key();
|
||||
let secret = format!("sealerSecret_z{}", bs58::encode(&private_key).into_string());
|
||||
|
||||
// Get sealer ID
|
||||
let sealer_id = get_sealer_id_internal(&secret).unwrap();
|
||||
assert!(sealer_id.starts_with("sealer_z"));
|
||||
|
||||
// Test that same secret produces same ID
|
||||
let sealer_id2 = get_sealer_id_internal(&secret).unwrap();
|
||||
assert_eq!(sealer_id, sealer_id2);
|
||||
|
||||
// Test invalid secret format
|
||||
let result = get_sealer_id_internal("invalid_secret");
|
||||
assert!(matches!(
|
||||
result,
|
||||
Err(CryptoError::InvalidPrefix(
|
||||
"sealerSecret_z",
|
||||
"sealer secret"
|
||||
))
|
||||
));
|
||||
|
||||
// Test invalid base58
|
||||
let result = get_sealer_id_internal("sealerSecret_z!!!invalid!!!");
|
||||
assert!(matches!(result, Err(CryptoError::Base58Error(_))));
|
||||
}
|
||||
}
|
||||
256
crates/cojson-core-wasm/src/crypto/xsalsa20.rs
Normal file
@@ -0,0 +1,256 @@
|
||||
use crate::error::CryptoError;
|
||||
use crate::hash::blake3::generate_nonce;
|
||||
use crypto_secretbox::{
|
||||
aead::{Aead, KeyInit},
|
||||
XSalsa20Poly1305,
|
||||
};
|
||||
use salsa20::cipher::{KeyIvInit, StreamCipher};
|
||||
use salsa20::XSalsa20;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// WASM-exposed function for XSalsa20 encryption without authentication.
|
||||
/// - `key`: 32-byte key for encryption
|
||||
/// - `nonce_material`: Raw bytes used to generate a 24-byte nonce via BLAKE3
|
||||
/// - `plaintext`: Raw bytes to encrypt
|
||||
/// Returns the encrypted bytes or throws a JsError if encryption fails.
|
||||
/// Note: This function does not provide authentication. Use encrypt_xsalsa20_poly1305 for authenticated encryption.
|
||||
#[wasm_bindgen]
|
||||
pub fn encrypt_xsalsa20(
|
||||
key: &[u8],
|
||||
nonce_material: &[u8],
|
||||
plaintext: &[u8],
|
||||
) -> Result<Box<[u8]>, JsError> {
|
||||
let nonce = generate_nonce(nonce_material);
|
||||
Ok(encrypt_xsalsa20_raw_internal(key, &nonce, plaintext)?.into())
|
||||
}
|
||||
|
||||
/// WASM-exposed function for XSalsa20 decryption without authentication.
|
||||
/// - `key`: 32-byte key for decryption (must match encryption key)
|
||||
/// - `nonce_material`: Raw bytes used to generate a 24-byte nonce (must match encryption)
|
||||
/// - `ciphertext`: Encrypted bytes to decrypt
|
||||
/// Returns the decrypted bytes or throws a JsError if decryption fails.
|
||||
/// Note: This function does not provide authentication. Use decrypt_xsalsa20_poly1305 for authenticated decryption.
|
||||
#[wasm_bindgen]
|
||||
pub fn decrypt_xsalsa20(
|
||||
key: &[u8],
|
||||
nonce_material: &[u8],
|
||||
ciphertext: &[u8],
|
||||
) -> Result<Box<[u8]>, JsError> {
|
||||
let nonce = generate_nonce(nonce_material);
|
||||
Ok(decrypt_xsalsa20_raw_internal(key, &nonce, ciphertext)?.into())
|
||||
}
|
||||
|
||||
/// Internal function for raw XSalsa20 encryption without nonce generation.
|
||||
/// Takes a 32-byte key and 24-byte nonce directly.
|
||||
/// Returns encrypted bytes or CryptoError if key/nonce lengths are invalid.
|
||||
pub fn encrypt_xsalsa20_raw_internal(
|
||||
key: &[u8],
|
||||
nonce: &[u8],
|
||||
plaintext: &[u8],
|
||||
) -> Result<Box<[u8]>, CryptoError> {
|
||||
// Key must be 32 bytes
|
||||
let key_bytes: [u8; 32] = key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, key.len()))?;
|
||||
// Nonce must be 24 bytes
|
||||
let nonce_bytes: [u8; 24] = nonce
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidNonceLength)?;
|
||||
|
||||
// Create cipher instance and encrypt
|
||||
let mut cipher = XSalsa20::new_from_slices(&key_bytes, &nonce_bytes)
|
||||
.map_err(|_| CryptoError::CipherError)?;
|
||||
let mut buffer = plaintext.to_vec();
|
||||
cipher.apply_keystream(&mut buffer);
|
||||
Ok(buffer.into_boxed_slice())
|
||||
}
|
||||
|
||||
/// Internal function for raw XSalsa20 decryption without nonce generation.
|
||||
/// Takes a 32-byte key and 24-byte nonce directly.
|
||||
/// Returns decrypted bytes or CryptoError if key/nonce lengths are invalid.
|
||||
pub fn decrypt_xsalsa20_raw_internal(
|
||||
key: &[u8],
|
||||
nonce: &[u8],
|
||||
ciphertext: &[u8],
|
||||
) -> Result<Box<[u8]>, CryptoError> {
|
||||
// Key must be 32 bytes
|
||||
let key_bytes: [u8; 32] = key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, key.len()))?;
|
||||
// Nonce must be 24 bytes
|
||||
let nonce_bytes: [u8; 24] = nonce
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidNonceLength)?;
|
||||
|
||||
// Create cipher instance and decrypt (XSalsa20 is symmetric)
|
||||
let mut cipher = XSalsa20::new_from_slices(&key_bytes, &nonce_bytes)
|
||||
.map_err(|_| CryptoError::CipherError)?;
|
||||
let mut buffer = ciphertext.to_vec();
|
||||
cipher.apply_keystream(&mut buffer);
|
||||
Ok(buffer.into_boxed_slice())
|
||||
}
|
||||
|
||||
/// XSalsa20-Poly1305 encryption
|
||||
pub fn encrypt_xsalsa20_poly1305(
|
||||
key: &[u8],
|
||||
nonce: &[u8],
|
||||
plaintext: &[u8],
|
||||
) -> Result<Box<[u8]>, CryptoError> {
|
||||
// Key must be 32 bytes
|
||||
let key_bytes: [u8; 32] = key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, key.len()))?;
|
||||
// Nonce must be 24 bytes
|
||||
let nonce_bytes: [u8; 24] = nonce
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidNonceLength)?;
|
||||
|
||||
// Create cipher instance
|
||||
let cipher = XSalsa20Poly1305::new(&key_bytes.into());
|
||||
|
||||
// Encrypt the plaintext
|
||||
cipher
|
||||
.encrypt(&nonce_bytes.into(), plaintext)
|
||||
.map(|v| v.into_boxed_slice())
|
||||
.map_err(|_| CryptoError::WrongTag)
|
||||
}
|
||||
|
||||
/// XSalsa20-Poly1305 decryption
|
||||
pub fn decrypt_xsalsa20_poly1305(
|
||||
key: &[u8],
|
||||
nonce: &[u8],
|
||||
ciphertext: &[u8],
|
||||
) -> Result<Box<[u8]>, CryptoError> {
|
||||
// Key must be 32 bytes
|
||||
let key_bytes: [u8; 32] = key
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidKeyLength(32, key.len()))?;
|
||||
// Nonce must be 24 bytes
|
||||
let nonce_bytes: [u8; 24] = nonce
|
||||
.try_into()
|
||||
.map_err(|_| CryptoError::InvalidNonceLength)?;
|
||||
|
||||
// Create cipher instance
|
||||
let cipher = XSalsa20Poly1305::new(&key_bytes.into());
|
||||
|
||||
// Decrypt the ciphertext
|
||||
cipher
|
||||
.decrypt(&nonce_bytes.into(), ciphertext)
|
||||
.map(|v| v.into_boxed_slice())
|
||||
.map_err(|_| CryptoError::WrongTag)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_xsalsa20() {
|
||||
// Test vectors
|
||||
let key = [0u8; 32]; // All zeros key
|
||||
let nonce = [0u8; 24]; // All zeros nonce
|
||||
let plaintext = b"Hello, World!";
|
||||
|
||||
// Test encryption
|
||||
let ciphertext = encrypt_xsalsa20_raw_internal(&key, &nonce, plaintext).unwrap();
|
||||
assert_ne!(&*ciphertext, plaintext); // Ciphertext should be different from plaintext
|
||||
|
||||
// Test decryption
|
||||
let decrypted = decrypt_xsalsa20_raw_internal(&key, &nonce, &ciphertext).unwrap();
|
||||
assert_eq!(&*decrypted, plaintext);
|
||||
|
||||
// Test that different nonce produces different ciphertext
|
||||
let nonce2 = [1u8; 24];
|
||||
let ciphertext2 = encrypt_xsalsa20_raw_internal(&key, &nonce2, plaintext).unwrap();
|
||||
assert_ne!(ciphertext, ciphertext2);
|
||||
|
||||
// Test that different key produces different ciphertext
|
||||
let key2 = [1u8; 32];
|
||||
let ciphertext3 = encrypt_xsalsa20_raw_internal(&key2, &nonce, plaintext).unwrap();
|
||||
assert_ne!(ciphertext, ciphertext3);
|
||||
|
||||
// Test invalid key length
|
||||
assert!(encrypt_xsalsa20_raw_internal(&key[..31], &nonce, plaintext).is_err());
|
||||
assert!(decrypt_xsalsa20_raw_internal(&key[..31], &nonce, &ciphertext).is_err());
|
||||
|
||||
// Test invalid nonce length
|
||||
assert!(encrypt_xsalsa20_raw_internal(&key, &nonce[..23], plaintext).is_err());
|
||||
assert!(decrypt_xsalsa20_raw_internal(&key, &nonce[..23], &ciphertext).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_xsalsa20_error_handling() {
|
||||
let key = [0u8; 32];
|
||||
let nonce = [0u8; 24];
|
||||
let plaintext = b"test message";
|
||||
|
||||
// Test encryption with invalid key length
|
||||
let invalid_key = vec![0u8; 31]; // Too short
|
||||
let result = encrypt_xsalsa20_raw_internal(&invalid_key, &nonce, plaintext);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with too long key
|
||||
let too_long_key = vec![0u8; 33]; // Too long
|
||||
let result = encrypt_xsalsa20_raw_internal(&too_long_key, &nonce, plaintext);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test decryption with invalid key length
|
||||
let ciphertext = encrypt_xsalsa20_raw_internal(&key, &nonce, plaintext).unwrap();
|
||||
let result = decrypt_xsalsa20_raw_internal(&invalid_key, &nonce, &ciphertext);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test decryption with too long key
|
||||
let result = decrypt_xsalsa20_raw_internal(&too_long_key, &nonce, &ciphertext);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with invalid nonce length
|
||||
let invalid_nonce = vec![0u8; 23]; // Too short
|
||||
let result = encrypt_xsalsa20_raw_internal(&key, &invalid_nonce, plaintext);
|
||||
assert!(result.is_err());
|
||||
let result = decrypt_xsalsa20_raw_internal(&key, &invalid_nonce, &ciphertext);
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test with too long nonce
|
||||
let too_long_nonce = vec![0u8; 25]; // Too long
|
||||
let result = encrypt_xsalsa20_raw_internal(&key, &too_long_nonce, plaintext);
|
||||
assert!(result.is_err());
|
||||
let result = decrypt_xsalsa20_raw_internal(&key, &too_long_nonce, &ciphertext);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_xsalsa20_poly1305() {
|
||||
let key = [0u8; 32]; // All zeros key
|
||||
let nonce = [0u8; 24]; // All zeros nonce
|
||||
let plaintext = b"Hello, World!";
|
||||
|
||||
// Test encryption
|
||||
let ciphertext = encrypt_xsalsa20_poly1305(&key, &nonce, plaintext).unwrap();
|
||||
assert!(ciphertext.len() > plaintext.len()); // Should include authentication tag
|
||||
|
||||
// Test decryption
|
||||
let decrypted = decrypt_xsalsa20_poly1305(&key, &nonce, &ciphertext).unwrap();
|
||||
assert_eq!(&*decrypted, plaintext);
|
||||
|
||||
// Test that different nonce produces different ciphertext
|
||||
let nonce2 = [1u8; 24];
|
||||
let ciphertext2 = encrypt_xsalsa20_poly1305(&key, &nonce2, plaintext).unwrap();
|
||||
assert_ne!(ciphertext, ciphertext2);
|
||||
|
||||
// Test that different key produces different ciphertext
|
||||
let key2 = [1u8; 32];
|
||||
let ciphertext3 = encrypt_xsalsa20_poly1305(&key2, &nonce, plaintext).unwrap();
|
||||
assert_ne!(ciphertext, ciphertext3);
|
||||
|
||||
// Test that decryption fails with wrong key
|
||||
assert!(decrypt_xsalsa20_poly1305(&key2, &nonce, &ciphertext).is_err());
|
||||
|
||||
// Test that decryption fails with wrong nonce
|
||||
assert!(decrypt_xsalsa20_poly1305(&key, &nonce2, &ciphertext).is_err());
|
||||
|
||||
// Test that decryption fails with tampered ciphertext
|
||||
let mut tampered = ciphertext.clone();
|
||||
tampered[0] ^= 1;
|
||||
assert!(decrypt_xsalsa20_poly1305(&key, &nonce, &tampered).is_err());
|
||||
}
|
||||
}
|
||||
43
crates/cojson-core-wasm/src/error.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CryptoError {
|
||||
InvalidKeyLength(usize, usize),
|
||||
InvalidNonceLength,
|
||||
InvalidSealerSecretFormat,
|
||||
InvalidSignatureLength,
|
||||
InvalidVerifyingKey(String),
|
||||
InvalidPublicKey(String),
|
||||
WrongTag,
|
||||
CipherError,
|
||||
InvalidPrefix(&'static str, &'static str),
|
||||
Base58Error(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for CryptoError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
CryptoError::InvalidKeyLength(expected, actual) => {
|
||||
write!(f, "Invalid key length (expected {expected}, got {actual})")
|
||||
}
|
||||
CryptoError::InvalidNonceLength => write!(f, "Invalid nonce length"),
|
||||
CryptoError::InvalidSealerSecretFormat => {
|
||||
write!(
|
||||
f,
|
||||
"Invalid sealer secret format: must start with 'sealerSecret_z'"
|
||||
)
|
||||
}
|
||||
CryptoError::InvalidSignatureLength => write!(f, "Invalid signature length"),
|
||||
CryptoError::InvalidVerifyingKey(e) => write!(f, "Invalid verifying key: {}", e),
|
||||
CryptoError::InvalidPublicKey(e) => write!(f, "Invalid public key: {}", e),
|
||||
CryptoError::WrongTag => write!(f, "Wrong tag"),
|
||||
CryptoError::CipherError => write!(f, "Failed to create cipher"),
|
||||
CryptoError::InvalidPrefix(prefix, field) => {
|
||||
write!(f, "Invalid {} format: must start with '{}'", field, prefix)
|
||||
}
|
||||
CryptoError::Base58Error(e) => write!(f, "Invalid base58: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CryptoError {}
|
||||
218
crates/cojson-core-wasm/src/hash/blake3.rs
Normal file
@@ -0,0 +1,218 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Generate a 24-byte nonce from input material using BLAKE3.
|
||||
/// - `nonce_material`: Raw bytes to derive the nonce from
|
||||
/// Returns 24 bytes suitable for use as a nonce in cryptographic operations.
|
||||
/// This function is deterministic - the same input will produce the same nonce.
|
||||
#[wasm_bindgen]
|
||||
pub fn generate_nonce(nonce_material: &[u8]) -> Box<[u8]> {
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
hasher.update(nonce_material);
|
||||
hasher.finalize().as_bytes()[..24].into()
|
||||
}
|
||||
|
||||
/// Hash data once using BLAKE3.
|
||||
/// - `data`: Raw bytes to hash
|
||||
/// Returns 32 bytes of hash output.
|
||||
/// This is the simplest way to compute a BLAKE3 hash of a single piece of data.
|
||||
#[wasm_bindgen]
|
||||
pub fn blake3_hash_once(data: &[u8]) -> Box<[u8]> {
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
hasher.update(data);
|
||||
hasher.finalize().as_bytes().to_vec().into_boxed_slice()
|
||||
}
|
||||
|
||||
/// Hash data once using BLAKE3 with a context prefix.
|
||||
/// - `data`: Raw bytes to hash
|
||||
/// - `context`: Context bytes to prefix to the data
|
||||
/// Returns 32 bytes of hash output.
|
||||
/// This is useful for domain separation - the same data hashed with different contexts will produce different outputs.
|
||||
#[wasm_bindgen]
|
||||
pub fn blake3_hash_once_with_context(data: &[u8], context: &[u8]) -> Box<[u8]> {
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
hasher.update(context);
|
||||
hasher.update(data);
|
||||
hasher.finalize().as_bytes().to_vec().into_boxed_slice()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Blake3Hasher(blake3::Hasher);
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Blake3Hasher {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Self {
|
||||
Blake3Hasher(blake3::Hasher::new())
|
||||
}
|
||||
|
||||
pub fn update(&mut self, data: &[u8]) {
|
||||
self.0.update(data);
|
||||
}
|
||||
|
||||
pub fn finalize(&self) -> Box<[u8]> {
|
||||
self.0.finalize().as_bytes().to_vec().into_boxed_slice()
|
||||
}
|
||||
|
||||
pub fn clone(&self) -> Self {
|
||||
// The blake3::Hasher type implements Clone
|
||||
Blake3Hasher(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an empty BLAKE3 state for incremental hashing.
|
||||
/// Returns a new Blake3Hasher instance for incremental hashing.
|
||||
#[wasm_bindgen]
|
||||
pub fn blake3_empty_state() -> Blake3Hasher {
|
||||
Blake3Hasher::new()
|
||||
}
|
||||
|
||||
/// Update a BLAKE3 state with new data for incremental hashing.
|
||||
/// - `state`: Current Blake3Hasher instance
|
||||
/// - `data`: New data to incorporate into the hash
|
||||
/// Returns the updated Blake3Hasher.
|
||||
#[wasm_bindgen]
|
||||
pub fn blake3_update_state(state: &mut Blake3Hasher, data: &[u8]) {
|
||||
state.update(data);
|
||||
}
|
||||
|
||||
/// Get the final hash from a BLAKE3 state.
|
||||
/// - `state`: The Blake3Hasher to finalize
|
||||
/// Returns 32 bytes of hash output.
|
||||
/// This finalizes an incremental hashing operation.
|
||||
#[wasm_bindgen]
|
||||
pub fn blake3_digest_for_state(state: Blake3Hasher) -> Box<[u8]> {
|
||||
state.finalize()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_nonce_generation() {
|
||||
let input = b"test input";
|
||||
let nonce = generate_nonce(input);
|
||||
assert_eq!(nonce.len(), 24);
|
||||
|
||||
// Same input should produce same nonce
|
||||
let nonce2 = generate_nonce(input);
|
||||
assert_eq!(nonce, nonce2);
|
||||
|
||||
// Different input should produce different nonce
|
||||
let nonce3 = generate_nonce(b"different input");
|
||||
assert_ne!(nonce, nonce3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blake3_hash_once() {
|
||||
let input = b"test input";
|
||||
let hash = blake3_hash_once(input);
|
||||
|
||||
// BLAKE3 produces 32-byte hashes
|
||||
assert_eq!(hash.len(), 32);
|
||||
|
||||
// Same input should produce same hash
|
||||
let hash2 = blake3_hash_once(input);
|
||||
assert_eq!(hash, hash2);
|
||||
|
||||
// Different input should produce different hash
|
||||
let hash3 = blake3_hash_once(b"different input");
|
||||
assert_ne!(hash, hash3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blake3_hash_once_with_context() {
|
||||
let input = b"test input";
|
||||
let context = b"test context";
|
||||
let hash = blake3_hash_once_with_context(input, context);
|
||||
|
||||
// BLAKE3 produces 32-byte hashes
|
||||
assert_eq!(hash.len(), 32);
|
||||
|
||||
// Same input and context should produce same hash
|
||||
let hash2 = blake3_hash_once_with_context(input, context);
|
||||
assert_eq!(hash, hash2);
|
||||
|
||||
// Different input should produce different hash
|
||||
let hash3 = blake3_hash_once_with_context(b"different input", context);
|
||||
assert_ne!(hash, hash3);
|
||||
|
||||
// Different context should produce different hash
|
||||
let hash4 = blake3_hash_once_with_context(input, b"different context");
|
||||
assert_ne!(hash, hash4);
|
||||
|
||||
// Hash with context should be different from hash without context
|
||||
let hash_no_context = blake3_hash_once(input);
|
||||
assert_ne!(hash, hash_no_context);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blake3_incremental() {
|
||||
// Initial state
|
||||
let mut state = blake3_empty_state();
|
||||
|
||||
// First update with [1,2,3,4,5]
|
||||
let data1 = &[1u8, 2, 3, 4, 5];
|
||||
blake3_update_state(&mut state, data1);
|
||||
|
||||
// Check that this matches a direct hash
|
||||
let direct_hash = blake3_hash_once(data1);
|
||||
let state_hash = state.finalize();
|
||||
assert_eq!(
|
||||
state_hash, direct_hash,
|
||||
"First update should match direct hash"
|
||||
);
|
||||
|
||||
// Create new state for second test
|
||||
let mut state = blake3_empty_state();
|
||||
blake3_update_state(&mut state, data1);
|
||||
|
||||
// Verify the exact expected hash from the TypeScript test for the first update
|
||||
let expected_first_hash = [
|
||||
2, 79, 103, 192, 66, 90, 61, 192, 47, 186, 245, 140, 185, 61, 229, 19, 46, 61, 117,
|
||||
197, 25, 250, 160, 186, 218, 33, 73, 29, 136, 201, 112, 87,
|
||||
]
|
||||
.to_vec()
|
||||
.into_boxed_slice();
|
||||
assert_eq!(
|
||||
state.finalize(),
|
||||
expected_first_hash,
|
||||
"First update should match expected hash"
|
||||
);
|
||||
|
||||
// Test with two updates
|
||||
let mut state = blake3_empty_state();
|
||||
let data1 = &[1u8, 2, 3, 4, 5];
|
||||
let data2 = &[6u8, 7, 8, 9, 10];
|
||||
blake3_update_state(&mut state, data1);
|
||||
blake3_update_state(&mut state, data2);
|
||||
|
||||
// Compare with a single hash of all data
|
||||
let mut all_data = Vec::new();
|
||||
all_data.extend_from_slice(data1);
|
||||
all_data.extend_from_slice(data2);
|
||||
let direct_hash_all = blake3_hash_once(&all_data);
|
||||
assert_eq!(
|
||||
state.finalize(),
|
||||
direct_hash_all,
|
||||
"Final state should match direct hash of all data"
|
||||
);
|
||||
|
||||
// Test final hash matches expected value
|
||||
let mut state = blake3_empty_state();
|
||||
blake3_update_state(&mut state, data1);
|
||||
blake3_update_state(&mut state, data2);
|
||||
|
||||
let expected_final_hash = [
|
||||
165, 131, 141, 69, 2, 69, 39, 236, 196, 244, 180, 213, 147, 124, 222, 39, 68, 223, 54,
|
||||
176, 242, 97, 200, 101, 204, 79, 21, 233, 56, 51, 1, 199,
|
||||
]
|
||||
.to_vec()
|
||||
.into_boxed_slice();
|
||||
assert_eq!(
|
||||
state.finalize(),
|
||||
expected_final_hash,
|
||||
"Final state should match expected hash"
|
||||
);
|
||||
}
|
||||
}
|
||||
165
crates/cojson-core-wasm/src/lib.rs
Normal file
@@ -0,0 +1,165 @@
|
||||
use cojson_core::{
|
||||
CoID, CoJsonCoreError, KeyID, KeySecret, SessionID, SessionLogInternal, Signature, SignerID, SignerSecret, TransactionMode
|
||||
};
|
||||
use serde_json::value::RawValue;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
mod error;
|
||||
pub use error::CryptoError;
|
||||
|
||||
pub mod hash {
|
||||
pub mod blake3;
|
||||
pub use blake3::*;
|
||||
}
|
||||
|
||||
pub mod crypto {
|
||||
pub mod ed25519;
|
||||
pub mod encrypt;
|
||||
pub mod seal;
|
||||
pub mod sign;
|
||||
pub mod x25519;
|
||||
pub mod xsalsa20;
|
||||
|
||||
pub use ed25519::*;
|
||||
pub use encrypt::*;
|
||||
pub use seal::*;
|
||||
pub use sign::*;
|
||||
pub use x25519::*;
|
||||
pub use xsalsa20::*;
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum CojsonCoreWasmError {
|
||||
#[error(transparent)]
|
||||
CoJson(#[from] CoJsonCoreError),
|
||||
#[error(transparent)]
|
||||
Serde(#[from] serde_json::Error),
|
||||
#[error(transparent)]
|
||||
SerdeWasmBindgen(#[from] serde_wasm_bindgen::Error),
|
||||
#[error("JsValue Error: {0:?}")]
|
||||
Js(JsValue),
|
||||
}
|
||||
|
||||
impl From<CojsonCoreWasmError> for JsValue {
|
||||
fn from(err: CojsonCoreWasmError) -> Self {
|
||||
JsValue::from_str(&err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Clone)]
|
||||
pub struct SessionLog {
|
||||
internal: SessionLogInternal,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct PrivateTransactionResult {
|
||||
signature: String,
|
||||
encrypted_changes: String,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl SessionLog {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(co_id: String, session_id: String, signer_id: Option<String>) -> SessionLog {
|
||||
let co_id = CoID(co_id);
|
||||
let session_id = SessionID(session_id);
|
||||
let signer_id = signer_id.map(|id| SignerID(id));
|
||||
|
||||
let internal = SessionLogInternal::new(co_id, session_id, signer_id);
|
||||
|
||||
SessionLog { internal }
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = clone)]
|
||||
pub fn clone_js(&self) -> SessionLog {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = tryAdd)]
|
||||
pub fn try_add(
|
||||
&mut self,
|
||||
transactions_json: Vec<String>,
|
||||
new_signature_str: String,
|
||||
skip_verify: bool,
|
||||
) -> Result<(), CojsonCoreWasmError> {
|
||||
let transactions: Vec<Box<RawValue>> = transactions_json
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
serde_json::from_str(&s).map_err(|e| {
|
||||
CojsonCoreWasmError::Js(JsValue::from(format!(
|
||||
"Failed to parse transaction string: {}",
|
||||
e
|
||||
)))
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
let new_signature = Signature(new_signature_str);
|
||||
|
||||
self.internal
|
||||
.try_add(transactions, &new_signature, skip_verify)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = addNewPrivateTransaction)]
|
||||
pub fn add_new_private_transaction(
|
||||
&mut self,
|
||||
changes_json: &str,
|
||||
signer_secret: String,
|
||||
encryption_key: String,
|
||||
key_id: String,
|
||||
made_at: f64,
|
||||
) -> Result<String, CojsonCoreWasmError> {
|
||||
let (signature, transaction) = self.internal.add_new_transaction(
|
||||
changes_json,
|
||||
TransactionMode::Private{key_id: KeyID(key_id), key_secret: KeySecret(encryption_key)},
|
||||
&SignerSecret(signer_secret),
|
||||
made_at as u64,
|
||||
);
|
||||
|
||||
// Extract encrypted_changes from the private transaction
|
||||
let encrypted_changes = match transaction {
|
||||
cojson_core::Transaction::Private(private_tx) => private_tx.encrypted_changes.value,
|
||||
_ => return Err(CojsonCoreWasmError::Js(JsValue::from_str("Expected private transaction"))),
|
||||
};
|
||||
|
||||
let result = PrivateTransactionResult{
|
||||
signature: signature.0,
|
||||
encrypted_changes,
|
||||
};
|
||||
|
||||
Ok(serde_json::to_string(&result)?)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = addNewTrustingTransaction)]
|
||||
pub fn add_new_trusting_transaction(
|
||||
&mut self,
|
||||
changes_json: &str,
|
||||
signer_secret: String,
|
||||
made_at: f64,
|
||||
) -> Result<String, CojsonCoreWasmError> {
|
||||
let (signature, _) = self.internal.add_new_transaction(
|
||||
changes_json,
|
||||
TransactionMode::Trusting,
|
||||
&SignerSecret(signer_secret),
|
||||
made_at as u64,
|
||||
);
|
||||
|
||||
Ok(signature.0)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = decryptNextTransactionChangesJson)]
|
||||
pub fn decrypt_next_transaction_changes_json(
|
||||
&self,
|
||||
tx_index: u32,
|
||||
encryption_key: String,
|
||||
) -> Result<String, CojsonCoreWasmError> {
|
||||
Ok(self
|
||||
.internal
|
||||
.decrypt_next_transaction_changes_json(tx_index, KeySecret(encryption_key))?)
|
||||
}
|
||||
}
|
||||
18
crates/cojson-core/Cargo.toml
Normal file
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "cojson-core"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
lzy = { path = "../lzy", optional = true }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0", features = ["raw_value"] }
|
||||
ed25519-dalek = { version = "2.2.0", features = ["rand_core"] }
|
||||
bs58 = "0.5.1"
|
||||
blake3 = "1.5.1"
|
||||
salsa20 = "0.10.2"
|
||||
base64 = "0.22.1"
|
||||
thiserror = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
rand_core = { version = "0.6", features = ["getrandom"] }
|
||||
8
crates/cojson-core/data/multiTxSession.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"coID": "co_zUsz4gkwCCWqMXa4LHXdwyAkVK3",
|
||||
"signerID":"signer_z3FdM2ucYXUkbJQgPRf8R4Di6exd2sNPVaHaJHhQ8WAqi",
|
||||
"knownKeys":[],
|
||||
"exampleBase": {
|
||||
"co_zkNajJ1BhLzR962jpzvXxx917ZB_session_zXzrQLTtp8rR":{"transactions":[{"changes":"[{\"key\":\"co_zkNajJ1BhLzR962jpzvXxx917ZB\",\"op\":\"set\",\"value\":\"admin\"}]","madeAt":1750685354142,"privacy":"trusting"},{"changes":"[{\"key\":\"key_z268nqpkZYFFWPoGzL_for_co_zkNajJ1BhLzR962jpzvXxx917ZB\",\"op\":\"set\",\"value\":\"sealed_UmZaEEzCUrP3Q-t2KrN00keV66wzA4LWadqhEmw0jlku5frSW2QyXUY3zYIC_XLig6BDS9rcZZdTm3CwnLjTPzp9hgd9TlJLf_Q==\"}]","madeAt":1750685354142,"privacy":"trusting"},{"changes":"[{\"key\":\"readKey\",\"op\":\"set\",\"value\":\"key_z268nqpkZYFFWPoGzL\"}]","madeAt":1750685354143,"privacy":"trusting"},{"changes":"[{\"key\":\"everyone\",\"op\":\"set\",\"value\":\"writer\"}]","madeAt":1750685354143,"privacy":"trusting"},{"changes":"[{\"key\":\"key_z268nqpkZYFFWPoGzL_for_everyone\",\"op\":\"set\",\"value\":\"keySecret_zHRFDaEsnpYSZh6rUAvXS8uUrKCxJAzeBPSSaVU1r9RZY\"}]","madeAt":1750685354143,"privacy":"trusting"}],"lastHash":"hash_z5j1DUZjBiTKm5XnLi8ZrNPV3P7zGuXnMNCZfh2qGXGC7","streamingHash":{"state":{"__wbg_ptr":1127736},"crypto":{}},"lastSignature":"signature_z4LoRVDLnJBfAzHvRn3avgK4RVBd7iAfqUMJdpDEtV8HGLKGAqLyweBkNp8jggcNUQZatrMeU9tdc31ct9qxw7rib","signatureAfter":{}}
|
||||
}
|
||||
}
|
||||
6
crates/cojson-core/data/singleTxSession.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"coID": "co_zWnX74VrMP3n3dkm9wZVPszfiCw",
|
||||
"signerID":"signer_z3FdM2ucYXUkbJQgPRf8R4Di6exd2sNPVaHaJHhQ8WAqi",
|
||||
"knownKeys":[{"secret":"keySecret_zHRFDaEsnpYSZh6rUAvXS8uUrKCxJAzeBPSSaVU1r9RZY","id":"key_z268nqpkZYFFWPoGzL"}],
|
||||
"exampleBase":{"co_zkNajJ1BhLzR962jpzvXxx917ZB_session_zXzrQLTtp8rR":{"transactions":[{"encryptedChanges":"encrypted_UxN_r7X7p-3GUE3GRGRO4NfIhEUvB01m-HaSSipRRrUsTmNBW9dZ-pkAk-NoVP_iEB0moLFbG9GDq9U9S-rUDfSPcaWCJtpE=","keyUsed":"key_z268nqpkZYFFWPoGzL","madeAt":1750685368555,"privacy":"private"}],"lastHash":"hash_zJCdoTRgDuFdUK2XogR7qgNnxezfYAVih3qve2UV65L5X","streamingHash":{"state":{"__wbg_ptr":1129680},"crypto":{}},"lastSignature":"signature_z3UErpugJAqDEYKgzUhs88xBMohzmaL228PgkNhEomf6AeVr7NYNxY17iUoCmPQTpGJNqYPo3y82mGX4oWBhkqN4y","signatureAfter":{}}}
|
||||
}
|
||||
689
crates/cojson-core/src/lib.rs
Normal file
@@ -0,0 +1,689 @@
|
||||
use base64::{engine::general_purpose::URL_SAFE, Engine as _};
|
||||
use bs58;
|
||||
use ed25519_dalek::{Signature as Ed25519Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
||||
use salsa20::{
|
||||
cipher::{KeyIvInit, StreamCipher},
|
||||
XSalsa20,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{value::RawValue, Number, Value as JsonValue};
|
||||
use thiserror::Error;
|
||||
|
||||
// Re-export lzy for convenience
|
||||
#[cfg(feature = "lzy")]
|
||||
pub use lzy;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct SessionID(pub String);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct SignerID(pub String);
|
||||
|
||||
impl From<VerifyingKey> for SignerID {
|
||||
fn from(key: VerifyingKey) -> Self {
|
||||
SignerID(format!(
|
||||
"signer_z{}",
|
||||
bs58::encode(key.to_bytes()).into_string()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct SignerSecret(pub String);
|
||||
|
||||
impl From<SigningKey> for SignerSecret {
|
||||
fn from(key: SigningKey) -> Self {
|
||||
SignerSecret(format!(
|
||||
"signerSecret_z{}",
|
||||
bs58::encode(key.to_bytes()).into_string()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<SigningKey> for &SignerSecret {
|
||||
fn into(self) -> SigningKey {
|
||||
let key_bytes = decode_z(&self.0).expect("Invalid key secret");
|
||||
SigningKey::from_bytes(&key_bytes.try_into().expect("Invalid key secret length"))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Signature(pub String);
|
||||
|
||||
impl From<Ed25519Signature> for Signature {
|
||||
fn from(signature: Ed25519Signature) -> Self {
|
||||
Signature(format!(
|
||||
"signature_z{}",
|
||||
bs58::encode(signature.to_bytes()).into_string()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Ed25519Signature> for &Signature {
|
||||
fn into(self) -> Ed25519Signature {
|
||||
let signature_bytes = decode_z(&self.0).expect("Invalid signature");
|
||||
Ed25519Signature::from_bytes(
|
||||
&signature_bytes
|
||||
.try_into()
|
||||
.expect("Invalid signature length"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Hash(pub String);
|
||||
|
||||
impl From<blake3::Hash> for Hash {
|
||||
fn from(hash: blake3::Hash) -> Self {
|
||||
Hash(format!("hash_z{}", bs58::encode(hash.as_bytes()).into_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct KeyID(pub String);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct KeySecret(pub String);
|
||||
|
||||
impl Into<[u8; 32]> for &KeySecret {
|
||||
fn into(self) -> [u8; 32] {
|
||||
let key_bytes = decode_z(&self.0).expect("Invalid key secret");
|
||||
key_bytes.try_into().expect("Invalid key secret length")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct CoID(pub String);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TransactionID {
|
||||
#[serde(rename = "sessionID")]
|
||||
pub session_id: SessionID,
|
||||
#[serde(rename = "txIndex")]
|
||||
pub tx_index: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Encrypted<T> {
|
||||
pub value: String,
|
||||
_phantom: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PrivateTransaction {
|
||||
#[serde(rename = "encryptedChanges")]
|
||||
pub encrypted_changes: Encrypted<JsonValue>,
|
||||
#[serde(rename = "keyUsed")]
|
||||
pub key_used: KeyID,
|
||||
#[serde(rename = "madeAt")]
|
||||
pub made_at: Number,
|
||||
pub privacy: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TrustingTransaction {
|
||||
pub changes: String,
|
||||
#[serde(rename = "madeAt")]
|
||||
pub made_at: Number,
|
||||
pub privacy: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Transaction {
|
||||
Private(PrivateTransaction),
|
||||
Trusting(TrustingTransaction),
|
||||
}
|
||||
|
||||
pub enum TransactionMode {
|
||||
Private {
|
||||
key_id: KeyID,
|
||||
key_secret: KeySecret,
|
||||
},
|
||||
Trusting,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum CoJsonCoreError {
|
||||
#[error("Transaction not found at index {0}")]
|
||||
TransactionNotFound(u32),
|
||||
|
||||
#[error("Invalid encrypted prefix in transaction")]
|
||||
InvalidEncryptedPrefix,
|
||||
|
||||
#[error("Base64 decoding failed")]
|
||||
Base64Decode(#[from] base64::DecodeError),
|
||||
|
||||
#[error("UTF-8 conversion failed")]
|
||||
Utf8(#[from] std::string::FromUtf8Error),
|
||||
|
||||
#[error("JSON deserialization failed")]
|
||||
Json(#[from] serde_json::Error),
|
||||
|
||||
#[error("Signature verification failed: (hash: {0})")]
|
||||
SignatureVerification(String),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SessionLogInternal {
|
||||
co_id: CoID,
|
||||
session_id: SessionID,
|
||||
public_key: Option<VerifyingKey>,
|
||||
hasher: blake3::Hasher,
|
||||
transactions_json: Vec<String>,
|
||||
last_signature: Option<Signature>,
|
||||
}
|
||||
|
||||
impl SessionLogInternal {
|
||||
pub fn new(co_id: CoID, session_id: SessionID, signer_id: Option<SignerID>) -> Self {
|
||||
let hasher = blake3::Hasher::new();
|
||||
|
||||
let public_key = match signer_id {
|
||||
Some(signer_id) => Some(VerifyingKey::try_from(
|
||||
decode_z(&signer_id.0)
|
||||
.expect("Invalid public key")
|
||||
.as_slice(),
|
||||
)
|
||||
.expect("Invalid public key")),
|
||||
None => None,
|
||||
};
|
||||
|
||||
Self {
|
||||
co_id,
|
||||
session_id,
|
||||
public_key,
|
||||
hasher,
|
||||
transactions_json: Vec::new(),
|
||||
last_signature: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transactions_json(&self) -> &Vec<String> {
|
||||
&self.transactions_json
|
||||
}
|
||||
|
||||
pub fn last_signature(&self) -> Option<&Signature> {
|
||||
self.last_signature.as_ref()
|
||||
}
|
||||
|
||||
fn expected_hash_after(&self, transactions: &[Box<RawValue>]) -> blake3::Hasher {
|
||||
let mut hasher = self.hasher.clone();
|
||||
for tx in transactions {
|
||||
hasher.update(tx.get().as_bytes());
|
||||
}
|
||||
|
||||
hasher
|
||||
}
|
||||
|
||||
pub fn try_add(
|
||||
&mut self,
|
||||
transactions: Vec<Box<RawValue>>,
|
||||
new_signature: &Signature,
|
||||
skip_verify: bool,
|
||||
) -> Result<(), CoJsonCoreError> {
|
||||
if !skip_verify {
|
||||
let hasher = self.expected_hash_after(&transactions);
|
||||
let new_hash_encoded_stringified = format!(
|
||||
"\"hash_z{}\"",
|
||||
bs58::encode(hasher.finalize().as_bytes()).into_string()
|
||||
);
|
||||
|
||||
if let Some(public_key) = self.public_key {
|
||||
match public_key.verify(
|
||||
new_hash_encoded_stringified.as_bytes(),
|
||||
&(new_signature).into(),
|
||||
) {
|
||||
Ok(()) => {}
|
||||
Err(_) => {
|
||||
return Err(CoJsonCoreError::SignatureVerification(
|
||||
new_hash_encoded_stringified.replace("\"", ""),
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(CoJsonCoreError::SignatureVerification(
|
||||
new_hash_encoded_stringified.replace("\"", ""),
|
||||
));
|
||||
}
|
||||
|
||||
self.hasher = hasher;
|
||||
}
|
||||
|
||||
for tx in transactions {
|
||||
self.transactions_json.push(tx.get().to_string());
|
||||
}
|
||||
|
||||
self.last_signature = Some(new_signature.clone());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_new_transaction(
|
||||
&mut self,
|
||||
changes_json: &str,
|
||||
mode: TransactionMode,
|
||||
signer_secret: &SignerSecret,
|
||||
made_at: u64,
|
||||
) -> (Signature, Transaction) {
|
||||
let new_tx = match mode {
|
||||
TransactionMode::Private { key_id, key_secret } => {
|
||||
let tx_index = self.transactions_json.len() as u32;
|
||||
|
||||
let nonce_material = JsonValue::Object(serde_json::Map::from_iter(vec![
|
||||
("in".to_string(), JsonValue::String(self.co_id.0.clone())),
|
||||
(
|
||||
"tx".to_string(),
|
||||
serde_json::to_value(TransactionID {
|
||||
session_id: self.session_id.clone(),
|
||||
tx_index,
|
||||
})
|
||||
.unwrap(),
|
||||
),
|
||||
]));
|
||||
|
||||
let nonce = self.generate_json_nonce(&nonce_material);
|
||||
|
||||
let secret_key_bytes: [u8; 32] = (&key_secret).into();
|
||||
|
||||
let mut ciphertext = changes_json.as_bytes().to_vec();
|
||||
let mut cipher = XSalsa20::new(&secret_key_bytes.into(), &nonce.into());
|
||||
cipher.apply_keystream(&mut ciphertext);
|
||||
let encrypted_str = format!("encrypted_U{}", URL_SAFE.encode(&ciphertext));
|
||||
|
||||
Transaction::Private(PrivateTransaction {
|
||||
encrypted_changes: Encrypted {
|
||||
value: encrypted_str,
|
||||
_phantom: std::marker::PhantomData,
|
||||
},
|
||||
key_used: key_id.clone(),
|
||||
made_at: Number::from(made_at),
|
||||
privacy: "private".to_string(),
|
||||
})
|
||||
}
|
||||
TransactionMode::Trusting => Transaction::Trusting(TrustingTransaction {
|
||||
changes: changes_json.to_string(),
|
||||
made_at: Number::from(made_at),
|
||||
privacy: "trusting".to_string(),
|
||||
}),
|
||||
};
|
||||
|
||||
let tx_json = serde_json::to_string(&new_tx).unwrap();
|
||||
self.hasher.update(tx_json.as_bytes());
|
||||
self.transactions_json.push(tx_json);
|
||||
|
||||
let new_hash = self.hasher.finalize();
|
||||
let new_hash_encoded_stringified = format!("\"hash_z{}\"", bs58::encode(new_hash.as_bytes()).into_string());
|
||||
let signing_key: SigningKey = signer_secret.into();
|
||||
let new_signature: Signature = signing_key.sign(new_hash_encoded_stringified.as_bytes()).into();
|
||||
|
||||
self.last_signature = Some(new_signature.clone());
|
||||
|
||||
(new_signature, new_tx)
|
||||
}
|
||||
|
||||
pub fn decrypt_next_transaction_changes_json(
|
||||
&self,
|
||||
tx_index: u32,
|
||||
key_secret: KeySecret,
|
||||
) -> Result<String, CoJsonCoreError> {
|
||||
let tx_json = self
|
||||
.transactions_json
|
||||
.get(tx_index as usize)
|
||||
.ok_or(CoJsonCoreError::TransactionNotFound(tx_index))?;
|
||||
let tx: Transaction = serde_json::from_str(tx_json)?;
|
||||
|
||||
match tx {
|
||||
Transaction::Private(private_tx) => {
|
||||
let nonce_material = JsonValue::Object(serde_json::Map::from_iter(vec![
|
||||
("in".to_string(), JsonValue::String(self.co_id.0.clone())),
|
||||
(
|
||||
"tx".to_string(),
|
||||
serde_json::to_value(TransactionID {
|
||||
session_id: self.session_id.clone(),
|
||||
tx_index,
|
||||
})?,
|
||||
),
|
||||
]));
|
||||
|
||||
let nonce = self.generate_json_nonce(&nonce_material);
|
||||
|
||||
let encrypted_val = private_tx.encrypted_changes.value;
|
||||
let prefix = "encrypted_U";
|
||||
if !encrypted_val.starts_with(prefix) {
|
||||
return Err(CoJsonCoreError::InvalidEncryptedPrefix);
|
||||
}
|
||||
|
||||
let ciphertext_b64 = &encrypted_val[prefix.len()..];
|
||||
let mut ciphertext = URL_SAFE.decode(ciphertext_b64)?;
|
||||
|
||||
let secret_key_bytes: [u8; 32] = (&key_secret).into();
|
||||
let mut cipher = XSalsa20::new((&secret_key_bytes).into(), &nonce.into());
|
||||
cipher.apply_keystream(&mut ciphertext);
|
||||
|
||||
Ok(String::from_utf8(ciphertext)?)
|
||||
}
|
||||
Transaction::Trusting(trusting_tx) => Ok(trusting_tx.changes),
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_nonce(&self, material: &[u8]) -> [u8; 24] {
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
hasher.update(material);
|
||||
let mut output = [0u8; 24];
|
||||
let mut output_reader = hasher.finalize_xof();
|
||||
output_reader.fill(&mut output);
|
||||
output
|
||||
}
|
||||
|
||||
fn generate_json_nonce(&self, material: &JsonValue) -> [u8; 24] {
|
||||
let stable_json = serde_json::to_string(&material).unwrap();
|
||||
self.generate_nonce(stable_json.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_z(value: &str) -> Result<Vec<u8>, String> {
|
||||
let prefix_end = value.find("_z").ok_or("Invalid prefix")? + 2;
|
||||
bs58::decode(&value[prefix_end..])
|
||||
.into_vec()
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rand_core::OsRng;
|
||||
use std::{collections::HashMap, fs};
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let mut csprng = OsRng;
|
||||
let signing_key = SigningKey::generate(&mut csprng);
|
||||
let verifying_key = signing_key.verifying_key();
|
||||
|
||||
let session = SessionLogInternal::new(
|
||||
CoID("co_test1".to_string()),
|
||||
SessionID("session_test1".to_string()),
|
||||
verifying_key.into(),
|
||||
);
|
||||
|
||||
assert!(session.last_signature.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_from_example_json() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct TestSession<'a> {
|
||||
last_signature: Signature,
|
||||
#[serde(borrow)]
|
||||
transactions: Vec<&'a RawValue>,
|
||||
last_hash: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Root<'a> {
|
||||
#[serde(borrow)]
|
||||
example_base: HashMap<String, TestSession<'a>>,
|
||||
#[serde(rename = "signerID")]
|
||||
signer_id: SignerID,
|
||||
}
|
||||
|
||||
let data = fs::read_to_string("data/singleTxSession.json")
|
||||
.expect("Unable to read singleTxSession.json");
|
||||
let root: Root = serde_json::from_str(&data).unwrap();
|
||||
|
||||
let (session_id_str, example) = root.example_base.into_iter().next().unwrap();
|
||||
let session_id = SessionID(session_id_str.clone());
|
||||
let co_id = CoID(
|
||||
session_id_str
|
||||
.split("_session_")
|
||||
.next()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let mut session = SessionLogInternal::new(co_id, session_id, root.signer_id);
|
||||
|
||||
let new_signature = example.last_signature;
|
||||
|
||||
let result = session.try_add(
|
||||
vec![example.transactions[0].to_owned()],
|
||||
&new_signature,
|
||||
false,
|
||||
);
|
||||
|
||||
match result {
|
||||
Ok(returned_final_hash) => {
|
||||
let final_hash = session.hasher.finalize();
|
||||
let final_hash_encoded = format!(
|
||||
"hash_z{}",
|
||||
bs58::encode(final_hash.as_bytes()).into_string()
|
||||
);
|
||||
|
||||
assert_eq!(final_hash_encoded, example.last_hash);
|
||||
assert_eq!(session.last_signature, Some(new_signature));
|
||||
}
|
||||
Err(CoJsonCoreError::SignatureVerification(new_hash_encoded)) => {
|
||||
assert_eq!(new_hash_encoded, example.last_hash);
|
||||
panic!("Signature verification failed despite same hash");
|
||||
}
|
||||
Err(e) => {
|
||||
panic!("Unexpected error: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_from_example_json_multi_tx() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct TestSession<'a> {
|
||||
last_signature: Signature,
|
||||
#[serde(borrow)]
|
||||
transactions: Vec<&'a RawValue>,
|
||||
last_hash: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Root<'a> {
|
||||
#[serde(borrow)]
|
||||
example_base: HashMap<String, TestSession<'a>>,
|
||||
#[serde(rename = "signerID")]
|
||||
signer_id: SignerID,
|
||||
}
|
||||
|
||||
let data = fs::read_to_string("data/multiTxSession.json")
|
||||
.expect("Unable to read multiTxSession.json");
|
||||
let root: Root = serde_json::from_str(&data).unwrap();
|
||||
|
||||
let (session_id_str, example) = root.example_base.into_iter().next().unwrap();
|
||||
let session_id = SessionID(session_id_str.clone());
|
||||
let co_id = CoID(
|
||||
session_id_str
|
||||
.split("_session_")
|
||||
.next()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let mut session = SessionLogInternal::new(co_id, session_id, root.signer_id);
|
||||
|
||||
let new_signature = example.last_signature;
|
||||
|
||||
let result = session.try_add(
|
||||
example.transactions.into_iter().map(|tx| tx.to_owned()).collect(),
|
||||
&new_signature,
|
||||
false,
|
||||
);
|
||||
|
||||
match result {
|
||||
Ok(returned_final_hash) => {
|
||||
let final_hash = session.hasher.finalize();
|
||||
let final_hash_encoded = format!(
|
||||
"hash_z{}",
|
||||
bs58::encode(final_hash.as_bytes()).into_string()
|
||||
);
|
||||
|
||||
assert_eq!(final_hash_encoded, example.last_hash);
|
||||
assert_eq!(session.last_signature, Some(new_signature));
|
||||
}
|
||||
Err(CoJsonCoreError::SignatureVerification(new_hash_encoded)) => {
|
||||
assert_eq!(new_hash_encoded, example.last_hash);
|
||||
panic!("Signature verification failed despite same hash");
|
||||
}
|
||||
Err(e) => {
|
||||
panic!("Unexpected error: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_new_transaction() {
|
||||
// Load the example data to get all the pieces we need
|
||||
let data = fs::read_to_string("data/singleTxSession.json")
|
||||
.expect("Unable to read singleTxSession.json");
|
||||
let root: serde_json::Value = serde_json::from_str(&data).unwrap();
|
||||
let session_data =
|
||||
&root["exampleBase"]["co_zkNajJ1BhLzR962jpzvXxx917ZB_session_zXzrQLTtp8rR"];
|
||||
let tx_from_example = &session_data["transactions"][0];
|
||||
let known_key = &root["knownKeys"][0];
|
||||
|
||||
// Since we don't have the original private key, we generate a new one for this test.
|
||||
let mut csprng = OsRng;
|
||||
let signing_key = SigningKey::generate(&mut csprng);
|
||||
let public_key = signing_key.verifying_key();
|
||||
|
||||
// Initialize an empty session
|
||||
let mut session = SessionLogInternal::new(
|
||||
CoID(root["coID"].as_str().unwrap().to_string()),
|
||||
SessionID("co_zkNajJ1BhLzR962jpzvXxx917ZB_session_zXzrQLTtp8rR".to_string()),
|
||||
public_key.into(),
|
||||
);
|
||||
|
||||
// The plaintext changes we want to add
|
||||
let changes_json =
|
||||
r#"[{"after":"start","op":"app","value":"co_zMphsnYN6GU8nn2HDY5suvyGufY"}]"#;
|
||||
|
||||
// Extract all the necessary components from the example data
|
||||
let key_secret = KeySecret(known_key["secret"].as_str().unwrap().to_string());
|
||||
let key_id = KeyID(known_key["id"].as_str().unwrap().to_string());
|
||||
let made_at = tx_from_example["madeAt"].as_u64().unwrap();
|
||||
|
||||
// Call the function we are testing
|
||||
let (new_signature, _new_tx) = session.add_new_transaction(
|
||||
changes_json,
|
||||
TransactionMode::Private {
|
||||
key_id: key_id,
|
||||
key_secret: key_secret,
|
||||
},
|
||||
&signing_key.into(),
|
||||
made_at,
|
||||
);
|
||||
|
||||
// 1. Check that the transaction we created matches the one in the file
|
||||
let created_tx_json = &session.transactions_json[0];
|
||||
let expected_tx_json = serde_json::to_string(tx_from_example).unwrap();
|
||||
assert_eq!(created_tx_json, &expected_tx_json);
|
||||
|
||||
// 2. Check that the final hash of the session matches the one in the file
|
||||
let final_hash = session.hasher.finalize();
|
||||
let final_hash_encoded = format!(
|
||||
"hash_z{}",
|
||||
bs58::encode(final_hash.as_bytes()).into_string()
|
||||
);
|
||||
assert_eq!(
|
||||
final_hash_encoded,
|
||||
session_data["lastHash"].as_str().unwrap()
|
||||
);
|
||||
|
||||
let final_hash_encoded_stringified = format!(
|
||||
"\"{}\"",
|
||||
final_hash_encoded
|
||||
);
|
||||
|
||||
// 3. Check that the signature is valid for our generated key
|
||||
assert!(session
|
||||
.public_key
|
||||
.verify(final_hash_encoded_stringified.as_bytes(), &(&new_signature).into())
|
||||
.is_ok());
|
||||
assert_eq!(session.last_signature, Some(new_signature));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decrypt_from_example_json() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct KnownKey {
|
||||
secret: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(bound(deserialize = "'de: 'a"))]
|
||||
struct TestSession<'a> {
|
||||
last_signature: String,
|
||||
#[serde(borrow)]
|
||||
transactions: Vec<&'a RawValue>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(bound(deserialize = "'de: 'a"))]
|
||||
struct Root<'a> {
|
||||
#[serde(borrow)]
|
||||
example_base: HashMap<String, TestSession<'a>>,
|
||||
#[serde(rename = "signerID")]
|
||||
signer_id: SignerID,
|
||||
known_keys: Vec<KnownKey>,
|
||||
#[serde(rename = "coID")]
|
||||
co_id: CoID,
|
||||
}
|
||||
|
||||
let data = fs::read_to_string("data/singleTxSession.json")
|
||||
.expect("Unable to read singleTxSession.json");
|
||||
let root: Root = serde_json::from_str(&data).unwrap();
|
||||
|
||||
let (session_id_str, example) = root.example_base.into_iter().next().unwrap();
|
||||
let session_id = SessionID(session_id_str.clone());
|
||||
|
||||
let public_key =
|
||||
VerifyingKey::from_bytes(&decode_z(&root.signer_id.0).unwrap().try_into().unwrap())
|
||||
.unwrap();
|
||||
|
||||
let mut session = SessionLogInternal::new(root.co_id, session_id, public_key.into());
|
||||
|
||||
let new_signature = Signature(example.last_signature);
|
||||
|
||||
session
|
||||
.try_add(
|
||||
example
|
||||
.transactions
|
||||
.into_iter()
|
||||
.map(|v| v.to_owned())
|
||||
.collect(),
|
||||
&new_signature,
|
||||
true, // Skipping verification because we don't have the right initial state
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let key_secret = KeySecret(root.known_keys[0].secret.clone());
|
||||
|
||||
let decrypted = session
|
||||
.decrypt_next_transaction_changes_json(0, key_secret)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
decrypted,
|
||||
r#"[{"after":"start","op":"app","value":"co_zMphsnYN6GU8nn2HDY5suvyGufY"}]"#
|
||||
);
|
||||
}
|
||||
}
|
||||
15
crates/lzy/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "lzy"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.5", features = ["html_reports"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
[[bench]]
|
||||
name = "compression_benchmark"
|
||||
harness = false
|
||||
36
crates/lzy/benches/compression_benchmark.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
|
||||
use lzy::{compress, decompress};
|
||||
use std::fs;
|
||||
use std::time::Duration;
|
||||
|
||||
fn compression_benchmark(c: &mut Criterion) {
|
||||
let data = fs::read("data/compression_66k_JSON.txt").expect("Failed to read benchmark data");
|
||||
|
||||
let mut group = c.benchmark_group("LZY Compression");
|
||||
group.measurement_time(Duration::from_secs(10));
|
||||
group.sample_size(10);
|
||||
group.throughput(Throughput::Bytes(data.len() as u64));
|
||||
|
||||
let compressed = compress(&data);
|
||||
let compression_ratio = compressed.len() as f64 / data.len() as f64;
|
||||
println!(
|
||||
"Compression ratio (compressed/original): {:.4} ({} / {} bytes)",
|
||||
compression_ratio,
|
||||
compressed.len(),
|
||||
data.len()
|
||||
);
|
||||
|
||||
group.bench_function("compress", |b| {
|
||||
b.iter(|| compress(black_box(&data)))
|
||||
});
|
||||
|
||||
let decompressed = decompress(&compressed).unwrap();
|
||||
assert_eq!(data, decompressed);
|
||||
|
||||
group.bench_function("decompress", |b| {
|
||||
b.iter(|| decompress(black_box(&compressed)))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, compression_benchmark);
|
||||
criterion_main!(benches);
|
||||
59
crates/lzy/data/compression_66k_JSON.txt
Normal file
348
crates/lzy/src/lib.rs
Normal file
@@ -0,0 +1,348 @@
|
||||
const MIN_MATCH_LEN: usize = 4;
|
||||
const MAX_MATCH_LEN: usize = 15 + 3;
|
||||
const MAX_LITERALS: usize = 15;
|
||||
const HASH_LOG: u32 = 16;
|
||||
const HASH_TABLE_SIZE: usize = 1 << HASH_LOG;
|
||||
|
||||
fn hash(data: &[u8]) -> usize {
|
||||
const KNUTH_MULT_PRIME: u32 = 2654435761;
|
||||
let val = u32::from_le_bytes(data.try_into().unwrap());
|
||||
((val.wrapping_mul(KNUTH_MULT_PRIME)) >> (32 - HASH_LOG)) as usize
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum DecompressionError {
|
||||
InvalidToken,
|
||||
UnexpectedEof,
|
||||
}
|
||||
|
||||
pub fn decompress(input: &[u8]) -> Result<Vec<u8>, DecompressionError> {
|
||||
let mut decompressed = Vec::with_capacity(input.len() * 2);
|
||||
let mut i = 0;
|
||||
|
||||
while i < input.len() {
|
||||
let token = input[i];
|
||||
i += 1;
|
||||
|
||||
let literal_len = (token >> 4) as usize;
|
||||
let match_len_token = (token & 0x0F) as usize;
|
||||
|
||||
if i + literal_len > input.len() {
|
||||
return Err(DecompressionError::UnexpectedEof);
|
||||
}
|
||||
decompressed.extend_from_slice(&input[i..i + literal_len]);
|
||||
i += literal_len;
|
||||
|
||||
if match_len_token > 0 {
|
||||
if i + 2 > input.len() {
|
||||
return Err(DecompressionError::UnexpectedEof);
|
||||
}
|
||||
|
||||
let offset = u16::from_le_bytes([input[i], input[i + 1]]) as usize;
|
||||
i += 2;
|
||||
|
||||
if offset == 0 || offset > decompressed.len() {
|
||||
return Err(DecompressionError::InvalidToken);
|
||||
}
|
||||
|
||||
let match_len = match_len_token + 3;
|
||||
let match_start = decompressed.len() - offset;
|
||||
|
||||
for k in 0..match_len {
|
||||
decompressed.push(decompressed[match_start + k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(decompressed)
|
||||
}
|
||||
|
||||
pub fn compress(input: &[u8]) -> Vec<u8> {
|
||||
let mut compressor = Compressor::new();
|
||||
compressor.compress_chunk(input)
|
||||
}
|
||||
|
||||
fn emit_sequence(out: &mut Vec<u8>, mut literals: &[u8], match_len: usize, offset: u16) {
|
||||
while literals.len() > MAX_LITERALS {
|
||||
let token = (MAX_LITERALS as u8) << 4;
|
||||
out.push(token);
|
||||
out.extend_from_slice(&literals[..MAX_LITERALS]);
|
||||
literals = &literals[MAX_LITERALS..];
|
||||
}
|
||||
|
||||
let lit_len_token = literals.len() as u8;
|
||||
let match_len_token = if match_len > 0 {
|
||||
(match_len - 3) as u8
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let token = lit_len_token << 4 | match_len_token;
|
||||
out.push(token);
|
||||
out.extend_from_slice(literals);
|
||||
|
||||
if match_len > 0 {
|
||||
out.extend_from_slice(&offset.to_le_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Compressor {
|
||||
hash_table: Vec<u32>,
|
||||
history: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Compressor {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
hash_table: vec![0; HASH_TABLE_SIZE],
|
||||
history: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compress_chunk(&mut self, chunk: &[u8]) -> Vec<u8> {
|
||||
let mut compressed_chunk = Vec::new();
|
||||
|
||||
let chunk_start_cursor = self.history.len();
|
||||
self.history.extend_from_slice(chunk);
|
||||
|
||||
let mut cursor = chunk_start_cursor;
|
||||
let mut literal_anchor = chunk_start_cursor;
|
||||
|
||||
while cursor < self.history.len() {
|
||||
let mut best_match: Option<(u16, usize)> = None;
|
||||
|
||||
if self.history.len() - cursor >= MIN_MATCH_LEN {
|
||||
let h = hash(&self.history[cursor..cursor + 4]);
|
||||
let match_pos = self.hash_table[h] as usize;
|
||||
|
||||
if match_pos < cursor && cursor - match_pos < u16::MAX as usize {
|
||||
if self.history.get(match_pos..match_pos + MIN_MATCH_LEN) == Some(&self.history[cursor..cursor + MIN_MATCH_LEN]) {
|
||||
let mut match_len = MIN_MATCH_LEN;
|
||||
while cursor + match_len < self.history.len()
|
||||
&& match_len < MAX_MATCH_LEN
|
||||
&& self.history.get(match_pos + match_len) == self.history.get(cursor + match_len)
|
||||
{
|
||||
match_len += 1;
|
||||
}
|
||||
best_match = Some(((cursor - match_pos) as u16, match_len));
|
||||
}
|
||||
}
|
||||
self.hash_table[h] = cursor as u32;
|
||||
}
|
||||
|
||||
if let Some((offset, match_len)) = best_match {
|
||||
let literals = &self.history[literal_anchor..cursor];
|
||||
emit_sequence(&mut compressed_chunk, literals, match_len, offset);
|
||||
cursor += match_len;
|
||||
literal_anchor = cursor;
|
||||
} else {
|
||||
cursor += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if literal_anchor < cursor {
|
||||
let literals = &self.history[literal_anchor..cursor];
|
||||
emit_sequence(&mut compressed_chunk, literals, 0, 0);
|
||||
}
|
||||
|
||||
compressed_chunk
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_simple_roundtrip() {
|
||||
let data = b"hello world, hello people";
|
||||
let compressed = compress(data);
|
||||
println!("Compressed '{}': {:x?}", std::str::from_utf8(data).unwrap(), compressed);
|
||||
let decompressed = decompress(&compressed).unwrap();
|
||||
assert_eq!(data, decompressed.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_long_literals() {
|
||||
let data = b"abcdefghijklmnopqrstuvwxyz";
|
||||
let compressed = compress(data);
|
||||
println!("Compressed '{}': {:x?}", std::str::from_utf8(data).unwrap(), compressed);
|
||||
let decompressed = decompress(&compressed).unwrap();
|
||||
assert_eq!(data, decompressed.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decompress_empty() {
|
||||
let data = b"";
|
||||
let compressed = compress(data);
|
||||
assert!(compressed.is_empty());
|
||||
let decompressed = decompress(&compressed).unwrap();
|
||||
assert_eq!(data, decompressed.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overlapping_match() {
|
||||
let data = b"abcdeabcdeabcdeabcde"; // repeating sequence
|
||||
let compressed = compress(data);
|
||||
println!("Compressed '{}': {:x?}", std::str::from_utf8(data).unwrap(), compressed);
|
||||
let decompressed = decompress(&compressed).unwrap();
|
||||
assert_eq!(data, decompressed.as_slice());
|
||||
|
||||
let data2 = b"abababababababababab";
|
||||
let compressed2 = compress(data2);
|
||||
println!("Compressed '{}': {:x?}", std::str::from_utf8(data2).unwrap(), compressed2);
|
||||
let decompressed2 = decompress(&compressed2).unwrap();
|
||||
assert_eq!(data2, decompressed2.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_roundtrip() {
|
||||
let data = std::fs::read("data/compression_66k_JSON.txt").unwrap();
|
||||
let compressed = compress(&data);
|
||||
std::fs::write("compressed_66k.lzy", &compressed).unwrap();
|
||||
let decompressed = decompress(&compressed).unwrap();
|
||||
assert_eq!(data, decompressed.as_slice());
|
||||
}
|
||||
|
||||
mod crdt_helpers {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct After {
|
||||
pub session_id: String,
|
||||
pub tx_index: u32,
|
||||
pub change_idx: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Transaction {
|
||||
pub op: String,
|
||||
pub value: String,
|
||||
pub after: After,
|
||||
}
|
||||
|
||||
pub fn generate_transactions(text: &str, session_id: &str) -> Vec<String> {
|
||||
let mut transactions = Vec::new();
|
||||
for (i, c) in text.chars().enumerate() {
|
||||
let tx = Transaction {
|
||||
op: "app".to_string(),
|
||||
value: c.to_string(),
|
||||
after: After {
|
||||
session_id: session_id.to_string(),
|
||||
tx_index: i as u32,
|
||||
change_idx: 0,
|
||||
},
|
||||
};
|
||||
transactions.push(serde_json::to_string(&tx).unwrap());
|
||||
}
|
||||
transactions
|
||||
}
|
||||
|
||||
pub fn generate_shorthand_transactions(text: &str) -> Vec<String> {
|
||||
let mut transactions = Vec::new();
|
||||
for c in text.chars() {
|
||||
transactions.push(serde_json::to_string(&c.to_string()).unwrap());
|
||||
}
|
||||
transactions
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_crdt_transaction_generation() {
|
||||
let sample_text = "This is a sample text for our CRDT simulation. \
|
||||
It should be long enough to see some interesting compression results later on. \
|
||||
Let's add another sentence to make it a bit more substantial.";
|
||||
|
||||
let session_id = "co_zRtnoNffeMHge9wvyL5mK1RWbdz_session_zKvAVFSV5cqW";
|
||||
let transactions = crdt_helpers::generate_transactions(sample_text, session_id);
|
||||
|
||||
println!("--- Generated CRDT Transactions ---");
|
||||
for tx in &transactions {
|
||||
println!("{}", tx);
|
||||
}
|
||||
println!("--- End of CRDT Transactions ---");
|
||||
|
||||
assert!(!transactions.is_empty());
|
||||
assert_eq!(transactions.len(), sample_text.chars().count());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_crdt_chunked_compression() {
|
||||
let sample_text = "This is a sample text for our CRDT simulation. \
|
||||
It should be long enough to see some interesting compression results later on. \
|
||||
Let's add another sentence to make it a bit more substantial.";
|
||||
|
||||
let session_id = "co_zRtnoNffeMHge9wvyL5mK1RWbdz_session_zKvAVFSV5cqW";
|
||||
let transactions_json = crdt_helpers::generate_transactions(sample_text, session_id);
|
||||
|
||||
let mut compressor = Compressor::new();
|
||||
let mut compressed_log = Vec::new();
|
||||
let mut total_json_len = 0;
|
||||
|
||||
for tx_json in &transactions_json {
|
||||
let compressed_chunk = compressor.compress_chunk(tx_json.as_bytes());
|
||||
compressed_log.extend_from_slice(&compressed_chunk);
|
||||
total_json_len += tx_json.len();
|
||||
}
|
||||
|
||||
let decompressed = decompress(&compressed_log).unwrap();
|
||||
|
||||
// Verify roundtrip
|
||||
let original_log_concatenated = transactions_json.join("");
|
||||
assert_eq!(decompressed, original_log_concatenated.as_bytes());
|
||||
|
||||
let plaintext_len = sample_text.len();
|
||||
let compressed_len = compressed_log.len();
|
||||
|
||||
let compression_ratio = compressed_len as f64 / total_json_len as f64;
|
||||
let overhead_ratio = compressed_len as f64 / plaintext_len as f64;
|
||||
|
||||
println!("\n--- CRDT Chunked Compression Test ---");
|
||||
println!("Plaintext size: {} bytes", plaintext_len);
|
||||
println!("Total JSON size: {} bytes", total_json_len);
|
||||
println!("Compressed log size: {} bytes", compressed_len);
|
||||
println!("Compression ratio (compressed/json): {:.4}", compression_ratio);
|
||||
println!("Overhead ratio (compressed/plaintext): {:.4}", overhead_ratio);
|
||||
println!("--- End of Test ---");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_crdt_shorthand_compression() {
|
||||
let sample_text = "This is a sample text for our CRDT simulation. \
|
||||
It should be long enough to see some interesting compression results later on. \
|
||||
Let's add another sentence to make it a bit more substantial.";
|
||||
|
||||
let transactions_json = crdt_helpers::generate_shorthand_transactions(sample_text);
|
||||
|
||||
let mut compressor = Compressor::new();
|
||||
let mut compressed_log = Vec::new();
|
||||
let mut total_json_len = 0;
|
||||
|
||||
for tx_json in &transactions_json {
|
||||
let compressed_chunk = compressor.compress_chunk(tx_json.as_bytes());
|
||||
compressed_log.extend_from_slice(&compressed_chunk);
|
||||
total_json_len += tx_json.len();
|
||||
}
|
||||
|
||||
let decompressed = decompress(&compressed_log).unwrap();
|
||||
|
||||
// Verify roundtrip
|
||||
let original_log_concatenated = transactions_json.join("");
|
||||
assert_eq!(decompressed, original_log_concatenated.as_bytes());
|
||||
|
||||
let plaintext_len = sample_text.len();
|
||||
let compressed_len = compressed_log.len();
|
||||
|
||||
let compression_ratio = compressed_len as f64 / total_json_len as f64;
|
||||
let overhead_ratio = compressed_len as f64 / plaintext_len as f64;
|
||||
|
||||
println!("\n--- CRDT Shorthand Compression Test ---");
|
||||
println!("Plaintext size: {} bytes", plaintext_len);
|
||||
println!("Total JSON size: {} bytes", total_json_len);
|
||||
println!("Compressed log size: {} bytes", compressed_len);
|
||||
println!("Compression ratio (compressed/json): {:.4}", compression_ratio);
|
||||
println!("Overhead ratio (compressed/plaintext): {:.4}", overhead_ratio);
|
||||
println!("--- End of Test ---");
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,48 @@
|
||||
{
|
||||
"name": "betterauth",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"format-and-lint": "biome check .",
|
||||
"format-and-lint:fix": "biome check . --write",
|
||||
"test:e2e": "playwright test",
|
||||
"test:e2e:ui": "playwright test --ui",
|
||||
"email": "email dev --dir src/components/emails"
|
||||
},
|
||||
"dependencies": {
|
||||
"@icons-pack/react-simple-icons": "^12.8.0",
|
||||
"@radix-ui/react-label": "^2.1.6",
|
||||
"@radix-ui/react-slot": "^1.2.2",
|
||||
"better-auth": "^1.2.4",
|
||||
"better-sqlite3": "^11.9.1",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"jazz-betterauth-client-plugin": "workspace:*",
|
||||
"jazz-betterauth-server-plugin": "workspace:*",
|
||||
"jazz-inspector": "workspace:*",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-react-auth-betterauth": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"lucide-react": "^0.510.0",
|
||||
"next": "15.3.2",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0",
|
||||
"sonner": "^2.0.3",
|
||||
"tailwind-merge": "^3.3.0",
|
||||
"tw-animate-css": "^1.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@playwright/test": "^1.50.1",
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"react-email": "^4.0.11",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
"name": "betterauth",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"format-and-lint": "biome check .",
|
||||
"format-and-lint:fix": "biome check . --write",
|
||||
"test:e2e": "playwright test",
|
||||
"test:e2e:ui": "playwright test --ui",
|
||||
"email": "email dev --dir src/components/emails"
|
||||
},
|
||||
"dependencies": {
|
||||
"@icons-pack/react-simple-icons": "^12.8.0",
|
||||
"@radix-ui/react-label": "^2.1.6",
|
||||
"@radix-ui/react-slot": "^1.2.2",
|
||||
"better-auth": "^1.2.4",
|
||||
"better-sqlite3": "^11.9.1",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"jazz-react-auth-betterauth": "workspace:*",
|
||||
"jazz-betterauth-client-plugin": "workspace:*",
|
||||
"jazz-betterauth-server-plugin": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"lucide-react": "^0.510.0",
|
||||
"next": "15.3.2",
|
||||
"react": "catalog:react",
|
||||
"react-dom": "catalog:react",
|
||||
"sonner": "^2.0.3",
|
||||
"tailwind-merge": "^3.3.0",
|
||||
"tw-animate-css": "^1.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "catalog:default",
|
||||
"@playwright/test": "^1.50.1",
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "catalog:react",
|
||||
"@types/react-dom": "catalog:react",
|
||||
"react-email": "^4.0.11",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "catalog:default"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAccount } from "jazz-react";
|
||||
import { Account } from "jazz-tools";
|
||||
import { useAccount } from "jazz-tools/react";
|
||||
import {
|
||||
AppWindowMacIcon,
|
||||
FileTextIcon,
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { JazzProvider } from "jazz-react";
|
||||
import { AuthProvider } from "jazz-react-auth-betterauth";
|
||||
import { JazzReactProvider } from "jazz-tools/react";
|
||||
import { type ReactNode, lazy } from "react";
|
||||
|
||||
const JazzDevTools =
|
||||
process.env.NODE_ENV === "production"
|
||||
? () => null
|
||||
: lazy(() =>
|
||||
import("jazz-inspector").then((res) => ({
|
||||
import("jazz-tools/inspector").then((res) => ({
|
||||
default: res.JazzInspector,
|
||||
})),
|
||||
);
|
||||
|
||||
export function JazzAndAuth({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<JazzProvider
|
||||
<JazzReactProvider
|
||||
sync={{
|
||||
peer: "wss://cloud.jazz.tools/?key=betterauth-example@garden.co",
|
||||
}}
|
||||
@@ -28,6 +28,6 @@ export function JazzAndAuth({ children }: { children: ReactNode }) {
|
||||
{children}
|
||||
</AuthProvider>
|
||||
<JazzDevTools />
|
||||
</JazzProvider>
|
||||
</JazzReactProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAccount, useIsAuthenticated } from "jazz-react";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import { Account } from "jazz-tools";
|
||||
import { useAccount, useIsAuthenticated } from "jazz-tools/react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useCallback } from "react";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAccount, useIsAuthenticated } from "jazz-react";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import { useAccount, useIsAuthenticated } from "jazz-tools/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
|
||||
23
examples/chat-rn-expo-clerk/.gitignore
vendored
@@ -1,23 +0,0 @@
|
||||
node_modules/
|
||||
.expo/
|
||||
dist/
|
||||
npm-debug.*
|
||||
*.jks
|
||||
*.p8
|
||||
*.p12
|
||||
*.key
|
||||
*.mobileprovision
|
||||
*.orig.*
|
||||
web-build/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
ios
|
||||
android
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.test
|
||||
@@ -1,27 +0,0 @@
|
||||
# 🎷 Jazz + Expo + `expo-router` + Clerk Auth
|
||||
|
||||
## 🚀 How to Run
|
||||
|
||||
### 1. Inside the Workspace Root
|
||||
|
||||
First, install dependencies and build the project:
|
||||
|
||||
```bash
|
||||
pnpm i
|
||||
mv .env.example .env
|
||||
pnpm run build
|
||||
```
|
||||
|
||||
Don't forget to update `VITE_CLERK_PUBLISHABLE_KEY` in `.env` with your [Publishable Key](https://clerk.com/docs/deployments/clerk-environment-variables#clerk-publishable-and-secret-keys) from Clerk.
|
||||
|
||||
### 2. Inside the `examples/chat-rn-expo-clerk` Directory
|
||||
|
||||
Next, navigate to the specific example project and run the following commands:
|
||||
|
||||
```bash
|
||||
pnpm expo prebuild
|
||||
pnpx pod-install
|
||||
pnpm expo run:ios
|
||||
```
|
||||
|
||||
This will set up and launch the app on iOS. For Android, you can replace the last command with `pnpm expo run:android`.
|
||||
@@ -1,45 +0,0 @@
|
||||
{
|
||||
"expo": {
|
||||
"name": "jazz-chat-rn-expo-clerk",
|
||||
"scheme": "jazz-chat-rn-expo-clerk",
|
||||
"slug": "jazz-chat-rn-expo-clerk",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/images/icon.png",
|
||||
"userInterfaceStyle": "light",
|
||||
"splash": {
|
||||
"image": "./assets/images/splash.png",
|
||||
"resizeMode": "contain",
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"ios": {
|
||||
"supportsTablet": true,
|
||||
"bundleIdentifier": "com.jazz.chatrnclerk"
|
||||
},
|
||||
"android": {
|
||||
"adaptiveIcon": {
|
||||
"foregroundImage": "./assets/images/adaptive-icon.png",
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"package": "com.jazz.chatrnclerk"
|
||||
},
|
||||
"newArchEnabled": true,
|
||||
"plugins": [
|
||||
"expo-secure-store",
|
||||
"expo-font",
|
||||
"expo-router",
|
||||
"expo-sqlite",
|
||||
[
|
||||
"expo-image-picker",
|
||||
{
|
||||
"photosPermission": "The app accesses your photos to let you share them with your friends."
|
||||
}
|
||||
]
|
||||
],
|
||||
"extra": {
|
||||
"eas": {
|
||||
"projectId": "ca3d46e5-a10a-47ec-9d77-3b841e1c62d4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { Redirect, Stack } from "expo-router";
|
||||
import { useIsAuthenticated } from "jazz-expo";
|
||||
import React from "react";
|
||||
|
||||
export default function HomeLayout() {
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Redirect href={"/chat"} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack screenOptions={{ headerShown: false, headerBackVisible: true }} />
|
||||
);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { SignedOut } from "@clerk/clerk-expo";
|
||||
import { Link } from "expo-router";
|
||||
import React from "react";
|
||||
import { Text, View } from "react-native";
|
||||
|
||||
export default function HomePage() {
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center bg-gray-100 p-6">
|
||||
<SignedOut>
|
||||
<View className="bg-white p-6 rounded-lg shadow-lg w-11/12 max-w-md">
|
||||
<Text className="text-2xl font-bold text-center text-gray-900 mb-4">
|
||||
Jazz 🤝 Clerk 🤝 Expo
|
||||
</Text>
|
||||
<Link href="/sign-in" className="mb-4">
|
||||
<Text className="text-center text-blue-600 underline text-lg">
|
||||
Sign In
|
||||
</Text>
|
||||
</Link>
|
||||
<Link href="/sign-in-oauth" className="mb-4">
|
||||
<Text className="text-center text-blue-600 underline text-lg">
|
||||
Sign In OAuth
|
||||
</Text>
|
||||
</Link>
|
||||
<Link href="/sign-up">
|
||||
<Text className="text-center text-blue-600 underline text-lg">
|
||||
Sign Up
|
||||
</Text>
|
||||
</Link>
|
||||
</View>
|
||||
</SignedOut>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Redirect, Stack } from "expo-router";
|
||||
import { useIsAuthenticated } from "jazz-expo";
|
||||
|
||||
export default function UnAuthenticatedLayout() {
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Redirect href={"/chat"} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack
|
||||
screenOptions={{
|
||||
headerShown: true,
|
||||
headerBackVisible: true,
|
||||
headerTitle: "",
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
import { useOAuth } from "@clerk/clerk-expo";
|
||||
import * as Linking from "expo-linking";
|
||||
import { Link } from "expo-router";
|
||||
import * as WebBrowser from "expo-web-browser";
|
||||
import React from "react";
|
||||
import { Text, TouchableOpacity, View } from "react-native";
|
||||
|
||||
export const useWarmUpBrowser = () => {
|
||||
React.useEffect(() => {
|
||||
// Warm up the android browser to improve UX
|
||||
// https://docs.expo.dev/guides/authentication/#improving-user-experience
|
||||
void WebBrowser.warmUpAsync();
|
||||
return () => {
|
||||
void WebBrowser.coolDownAsync();
|
||||
};
|
||||
}, []);
|
||||
};
|
||||
|
||||
WebBrowser.maybeCompleteAuthSession();
|
||||
|
||||
const SignInWithOAuth = () => {
|
||||
useWarmUpBrowser();
|
||||
|
||||
const { startOAuthFlow } = useOAuth({ strategy: "oauth_google" });
|
||||
|
||||
const onPress = React.useCallback(async () => {
|
||||
try {
|
||||
const { createdSessionId, signIn, signUp, setActive } =
|
||||
await startOAuthFlow({
|
||||
redirectUrl: Linking.createURL("/", {
|
||||
scheme: "jazz-chat-rn-expo-clerk",
|
||||
}),
|
||||
});
|
||||
|
||||
if (createdSessionId) {
|
||||
setActive!({ session: createdSessionId });
|
||||
} else {
|
||||
// Use signIn or signUp for next steps such as MFA
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("OAuth error", err);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center bg-gray-50 p-6">
|
||||
<View className="bg-white w-11/12 max-w-md p-8 rounded-lg shadow-lg items-center">
|
||||
<TouchableOpacity
|
||||
onPress={onPress}
|
||||
className="w-full bg-red-500 py-3 rounded-lg flex items-center justify-center"
|
||||
>
|
||||
<Text className="text-white text-lg font-semibold">
|
||||
Sign in with Google
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<Link href="/" className="mt-4">
|
||||
<Text className="text-blue-600 text-lg font-semibold underline mb-6">
|
||||
Back to Home
|
||||
</Text>
|
||||
</Link>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
export default SignInWithOAuth;
|
||||
@@ -1,79 +0,0 @@
|
||||
import { useSignIn } from "@clerk/clerk-expo";
|
||||
import { Link } from "expo-router";
|
||||
import React from "react";
|
||||
import { Text, TextInput, TouchableOpacity, View } from "react-native";
|
||||
|
||||
export default function SignInPage() {
|
||||
const { signIn, setActive, isLoaded } = useSignIn();
|
||||
const [emailAddress, setEmailAddress] = React.useState("");
|
||||
const [password, setPassword] = React.useState("");
|
||||
const [errorMessage, setErrorMessage] = React.useState("");
|
||||
|
||||
const onSignInPress = React.useCallback(async () => {
|
||||
if (!isLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
setErrorMessage("");
|
||||
|
||||
try {
|
||||
const signInAttempt = await signIn.create({
|
||||
identifier: emailAddress,
|
||||
password,
|
||||
});
|
||||
|
||||
if (signInAttempt.status === "complete") {
|
||||
await setActive({ session: signInAttempt.createdSessionId });
|
||||
} else {
|
||||
console.error(JSON.stringify(signInAttempt, null, 2));
|
||||
setErrorMessage("Invalid credentials. Please try again.");
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(JSON.stringify(err, null, 2));
|
||||
if (err.errors && err.errors[0]?.message) {
|
||||
setErrorMessage(err.errors[0].message);
|
||||
} else {
|
||||
setErrorMessage("An unexpected error occurred. Please try again.");
|
||||
}
|
||||
}
|
||||
}, [isLoaded, emailAddress, password]);
|
||||
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center bg-gray-50 p-6">
|
||||
<View className="bg-white w-11/12 max-w-md p-8 rounded-lg shadow-md">
|
||||
<Text className="text-3xl font-bold text-center text-gray-800 mb-6">
|
||||
Sign In
|
||||
</Text>
|
||||
{errorMessage ? (
|
||||
<Text className="text-red-500 text-center mb-4">{errorMessage}</Text>
|
||||
) : null}
|
||||
<TextInput
|
||||
autoCapitalize="none"
|
||||
value={emailAddress}
|
||||
placeholder="Email..."
|
||||
onChangeText={(emailAddress) => setEmailAddress(emailAddress)}
|
||||
className="w-full h-12 mb-4 px-4 bg-gray-100 border border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none"
|
||||
/>
|
||||
<TextInput
|
||||
value={password}
|
||||
placeholder="Password..."
|
||||
secureTextEntry={true}
|
||||
onChangeText={(password) => setPassword(password)}
|
||||
className="w-full h-12 mb-6 px-4 bg-gray-100 border border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none"
|
||||
/>
|
||||
<TouchableOpacity
|
||||
onPress={onSignInPress}
|
||||
className="w-full h-12 bg-blue-600 rounded-lg flex items-center justify-center"
|
||||
>
|
||||
<Text className="text-white text-lg font-semibold">Sign In</Text>
|
||||
</TouchableOpacity>
|
||||
<View className="flex-row items-center justify-center mt-4">
|
||||
<Text className="text-gray-600">Don't have an account?</Text>
|
||||
<Link href="/sign-up">
|
||||
<Text className="text-blue-500 ml-2 font-semibold">Sign up</Text>
|
||||
</Link>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
import { useSignUp } from "@clerk/clerk-expo";
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import * as React from "react";
|
||||
import { Text, TextInput, TouchableOpacity, View } from "react-native";
|
||||
|
||||
export default function SignUpPage() {
|
||||
const { isLoaded, signUp, setActive } = useSignUp();
|
||||
|
||||
const [emailAddress, setEmailAddress] = React.useState("");
|
||||
const [password, setPassword] = React.useState("");
|
||||
const [pendingVerification, setPendingVerification] = React.useState(false);
|
||||
const [code, setCode] = React.useState("");
|
||||
const [errorMessage, setErrorMessage] = React.useState("");
|
||||
const navigation = useNavigation();
|
||||
|
||||
const onSignUpPress = async () => {
|
||||
if (!isLoaded) return;
|
||||
|
||||
setErrorMessage("");
|
||||
|
||||
try {
|
||||
await signUp.create({
|
||||
emailAddress,
|
||||
password,
|
||||
});
|
||||
|
||||
await signUp.prepareEmailAddressVerification({
|
||||
strategy: "email_code",
|
||||
});
|
||||
|
||||
setPendingVerification(true);
|
||||
} catch (err: any) {
|
||||
console.error(JSON.stringify(err, null, 2));
|
||||
if (err.errors && err.errors[0]?.message) {
|
||||
setErrorMessage(err.errors[0].message);
|
||||
} else {
|
||||
setErrorMessage("An unexpected error occurred. Please try again.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onPressVerify = async () => {
|
||||
if (!isLoaded) return;
|
||||
|
||||
setErrorMessage("");
|
||||
|
||||
try {
|
||||
const completeSignUp = await signUp.attemptEmailAddressVerification({
|
||||
code,
|
||||
});
|
||||
|
||||
if (completeSignUp.status === "complete") {
|
||||
await setActive({ session: completeSignUp.createdSessionId });
|
||||
} else {
|
||||
console.error(JSON.stringify(completeSignUp, null, 2));
|
||||
setErrorMessage("Failed to verify. Please check your code.");
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(JSON.stringify(err, null, 2));
|
||||
setErrorMessage("Invalid verification code. Please try again.");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center bg-gray-50 p-6">
|
||||
<View className="bg-white w-11/12 max-w-md p-8 rounded-lg shadow-lg">
|
||||
<Text className="text-3xl font-bold text-center text-gray-800 mb-6">
|
||||
{pendingVerification ? "Verify Email" : "Sign Up"}
|
||||
</Text>
|
||||
{errorMessage ? (
|
||||
<Text className="text-red-500 text-center mb-4">{errorMessage}</Text>
|
||||
) : null}
|
||||
|
||||
{!pendingVerification && (
|
||||
<>
|
||||
<TextInput
|
||||
autoCapitalize="none"
|
||||
value={emailAddress}
|
||||
placeholder="Email..."
|
||||
onChangeText={(email) => setEmailAddress(email)}
|
||||
className="w-full h-12 mb-4 px-4 bg-gray-100 border border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none"
|
||||
/>
|
||||
<TextInput
|
||||
value={password}
|
||||
placeholder="Password..."
|
||||
secureTextEntry={true}
|
||||
onChangeText={(password) => setPassword(password)}
|
||||
className="w-full h-12 mb-6 px-4 bg-gray-100 border border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none"
|
||||
/>
|
||||
<TouchableOpacity
|
||||
onPress={onSignUpPress}
|
||||
className="w-full h-12 bg-blue-600 rounded-lg flex justify-center items-center mb-4"
|
||||
>
|
||||
<Text className="text-white text-lg font-semibold">Sign Up</Text>
|
||||
</TouchableOpacity>
|
||||
</>
|
||||
)}
|
||||
|
||||
{pendingVerification && (
|
||||
<>
|
||||
<TextInput
|
||||
value={code}
|
||||
placeholder="Verification Code..."
|
||||
onChangeText={(code) => setCode(code)}
|
||||
className="w-full h-12 mb-4 px-4 bg-gray-100 border border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none"
|
||||
/>
|
||||
<TouchableOpacity
|
||||
onPress={onPressVerify}
|
||||
className="w-full h-12 bg-green-600 rounded-lg flex justify-center items-center mb-4"
|
||||
>
|
||||
<Text className="text-white text-lg font-semibold">
|
||||
Verify Email
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
import { ScrollViewStyleReset } from "expo-router/html";
|
||||
import { type PropsWithChildren } from "react";
|
||||
|
||||
/**
|
||||
* This file is web-only and used to configure the root HTML for every web page during static rendering.
|
||||
* The contents of this function only run in Node.js environments and do not have access to the DOM or browser APIs.
|
||||
*/
|
||||
export default function Root({ children }: PropsWithChildren) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, shrink-to-fit=no"
|
||||
/>
|
||||
|
||||
{/*
|
||||
Disable body scrolling on web. This makes ScrollView components work closer to how they do on native.
|
||||
However, body scrolling is often nice to have for mobile web. If you want to enable it, remove this line.
|
||||
*/}
|
||||
<ScrollViewStyleReset />
|
||||
|
||||
{/* Using raw CSS styles as an escape-hatch to ensure the background color never flickers in dark-mode. */}
|
||||
<style dangerouslySetInnerHTML={{ __html: responsiveBackground }} />
|
||||
{/* Add any additional <head> elements that you want globally available on web... */}
|
||||
</head>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
const responsiveBackground = `
|
||||
body {
|
||||
background-color: #fff;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
background-color: #000;
|
||||
}
|
||||
}`;
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Link, Stack } from "expo-router";
|
||||
import { StyleSheet, Text, View } from "react-native";
|
||||
|
||||
export default function NotFoundScreen() {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ title: "Oops!" }} />
|
||||
<View style={styles.container}>
|
||||
<Text>This screen doesn't exist.</Text>
|
||||
<Link href="/" style={styles.link}>
|
||||
<Text>Go to home screen!</Text>
|
||||
</Link>
|
||||
</View>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
padding: 20,
|
||||
},
|
||||
link: {
|
||||
marginTop: 15,
|
||||
paddingVertical: 15,
|
||||
},
|
||||
});
|
||||
@@ -1,71 +0,0 @@
|
||||
import "../global.css";
|
||||
import { ClerkLoaded, ClerkProvider } from "@clerk/clerk-expo";
|
||||
import { secureStore } from "@clerk/clerk-expo/secure-store";
|
||||
import { useFonts } from "expo-font";
|
||||
import { Slot, useRouter, useSegments } from "expo-router";
|
||||
import * as SplashScreen from "expo-splash-screen";
|
||||
import { useIsAuthenticated, useJazzContext } from "jazz-expo";
|
||||
import React, { useEffect } from "react";
|
||||
import { tokenCache } from "../cache";
|
||||
import { JazzAndAuth } from "../src/auth-context";
|
||||
|
||||
SplashScreen.preventAutoHideAsync();
|
||||
|
||||
function InitialLayout() {
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
const segments = useSegments();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const inAuthGroup = segments[0] === "(auth)";
|
||||
|
||||
if (isAuthenticated && inAuthGroup) {
|
||||
router.replace("/chat");
|
||||
} else if (!isAuthenticated && !inAuthGroup) {
|
||||
router.replace("/");
|
||||
}
|
||||
|
||||
SplashScreen.hideAsync();
|
||||
}, [isAuthenticated, segments, router]);
|
||||
|
||||
return <Slot />;
|
||||
}
|
||||
|
||||
export default function RootLayout() {
|
||||
const [fontsLoaded] = useFonts({
|
||||
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
|
||||
});
|
||||
|
||||
const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY;
|
||||
|
||||
if (!publishableKey) {
|
||||
throw new Error(
|
||||
"Missing Publishable Key. Please set EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY in your .env",
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (fontsLoaded) {
|
||||
} else {
|
||||
SplashScreen.preventAutoHideAsync();
|
||||
}
|
||||
}, [fontsLoaded]);
|
||||
|
||||
if (!fontsLoaded) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ClerkProvider
|
||||
tokenCache={tokenCache}
|
||||
publishableKey={publishableKey}
|
||||
__experimental_resourceCache={secureStore}
|
||||
>
|
||||
<ClerkLoaded>
|
||||
<JazzAndAuth>
|
||||
<InitialLayout />
|
||||
</JazzAndAuth>
|
||||
</ClerkLoaded>
|
||||
</ClerkProvider>
|
||||
);
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
import { Chat, Message } from "@/src/schema";
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import clsx from "clsx";
|
||||
import * as Clipboard from "expo-clipboard";
|
||||
import * as ImagePicker from "expo-image-picker";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { useAccount, useCoState } from "jazz-expo";
|
||||
import { ProgressiveImg } from "jazz-expo";
|
||||
import { createImage } from "jazz-react-native-media-images";
|
||||
import { CoPlainText, Group, Loaded } from "jazz-tools";
|
||||
import { useEffect, useLayoutEffect, useState } from "react";
|
||||
import React, {
|
||||
SafeAreaView,
|
||||
View,
|
||||
Text,
|
||||
Alert,
|
||||
TouchableOpacity,
|
||||
FlatList,
|
||||
KeyboardAvoidingView,
|
||||
TextInput,
|
||||
Button,
|
||||
Image,
|
||||
ActivityIndicator,
|
||||
} from "react-native";
|
||||
|
||||
export default function Conversation() {
|
||||
const { chatId } = useLocalSearchParams();
|
||||
const { me } = useAccount();
|
||||
const [chat, setChat] = useState<Loaded<typeof Chat>>();
|
||||
const [message, setMessage] = useState("");
|
||||
const loadedChat = useCoState(Chat, chat?.id, { resolve: { $each: true } });
|
||||
const navigation = useNavigation();
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (chat) return;
|
||||
if (chatId === "new") {
|
||||
createChat();
|
||||
} else {
|
||||
loadChat(chatId as string);
|
||||
}
|
||||
}, [chat]);
|
||||
|
||||
// Effect to dynamically set header options
|
||||
useLayoutEffect(() => {
|
||||
navigation.setOptions({
|
||||
headerTitle: "Chat",
|
||||
headerRight: () =>
|
||||
chat ? (
|
||||
<Button
|
||||
onPress={() => {
|
||||
if (chat?.id) {
|
||||
Clipboard.setStringAsync(
|
||||
`https://chat.jazz.tools/#/chat/${chat.id}`,
|
||||
);
|
||||
Alert.alert("Copied to clipboard", `Chat ID: ${chat.id}`);
|
||||
}
|
||||
}}
|
||||
title="Share"
|
||||
/>
|
||||
) : null,
|
||||
});
|
||||
}, [navigation, chat]);
|
||||
|
||||
const createChat = () => {
|
||||
const group = Group.create({ owner: me });
|
||||
group.addMember("everyone", "writer");
|
||||
const chat = Chat.create([], { owner: group });
|
||||
setChat(chat);
|
||||
};
|
||||
|
||||
const loadChat = async (chatId: string) => {
|
||||
try {
|
||||
const chat = await Chat.load(chatId);
|
||||
if (chat) setChat(chat);
|
||||
} catch (error) {
|
||||
console.log("Error loading chat", error);
|
||||
Alert.alert("Error", `Error loading chat: ${error}`);
|
||||
}
|
||||
};
|
||||
|
||||
const sendMessage = () => {
|
||||
if (!chat) return;
|
||||
if (message.trim()) {
|
||||
chat.push(
|
||||
Message.create(
|
||||
{ text: CoPlainText.create(message, chat._owner) },
|
||||
chat._owner,
|
||||
),
|
||||
);
|
||||
setMessage("");
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageUpload = async () => {
|
||||
try {
|
||||
const result = await ImagePicker.launchImageLibraryAsync({
|
||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||
base64: true,
|
||||
quality: 0.7,
|
||||
});
|
||||
|
||||
if (!result.canceled && result.assets[0].base64 && chat) {
|
||||
setIsUploading(true);
|
||||
const base64Uri = `data:image/jpeg;base64,${result.assets[0].base64}`;
|
||||
|
||||
const image = await createImage(base64Uri, {
|
||||
owner: chat._owner,
|
||||
maxSize: 2048,
|
||||
});
|
||||
|
||||
chat.push(
|
||||
Message.create(
|
||||
{ text: CoPlainText.create("", chat._owner), image },
|
||||
chat._owner,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
Alert.alert("Error", "Failed to upload image");
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const renderMessageItem = ({ item }: { item: Loaded<typeof Message> }) => {
|
||||
const isMe = item._edits.text?.by?.isMe;
|
||||
return (
|
||||
<View
|
||||
className={clsx(
|
||||
`rounded-xl px-3 py-2 max-w-[75%] my-1`,
|
||||
isMe ? `bg-blue-500 self-end` : `bg-gray-200 self-start`,
|
||||
)}
|
||||
>
|
||||
{!isMe ? (
|
||||
<Text
|
||||
className={clsx(
|
||||
`text-xs text-gray-500 mb-1`,
|
||||
isMe ? "text-right" : "text-left",
|
||||
)}
|
||||
>
|
||||
{item._edits.text?.by?.profile?.name}
|
||||
</Text>
|
||||
) : null}
|
||||
<View
|
||||
className={clsx(
|
||||
"flex relative items-end justify-between",
|
||||
isMe ? "flex-row" : "flex-row",
|
||||
)}
|
||||
>
|
||||
{item.image && (
|
||||
<ProgressiveImg image={item.image} maxWidth={1024}>
|
||||
{({ src, res, originalSize }) => (
|
||||
<Image
|
||||
source={{ uri: src }}
|
||||
className="w-48 h-48 rounded-lg mb-2"
|
||||
resizeMode="cover"
|
||||
/>
|
||||
)}
|
||||
</ProgressiveImg>
|
||||
)}
|
||||
{item.text && (
|
||||
<Text
|
||||
className={clsx(
|
||||
!isMe ? "text-black" : "text-gray-200",
|
||||
`text-md max-w-[85%]`,
|
||||
)}
|
||||
>
|
||||
{item.text}
|
||||
</Text>
|
||||
)}
|
||||
<Text
|
||||
className={clsx(
|
||||
"text-[10px] text-right ml-2",
|
||||
!isMe ? "mt-2 text-gray-500" : "mt-1 text-gray-200",
|
||||
)}
|
||||
>
|
||||
{item._edits.text?.madeAt?.getHours().toString().padStart(2, "0")}:
|
||||
{item._edits.text?.madeAt?.getMinutes().toString().padStart(2, "0")}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-gray-50">
|
||||
<FlatList
|
||||
contentContainerStyle={{
|
||||
flexGrow: 1,
|
||||
paddingVertical: 10,
|
||||
paddingHorizontal: 8,
|
||||
}}
|
||||
className="flex"
|
||||
data={loadedChat}
|
||||
keyExtractor={(item) => item.id}
|
||||
renderItem={renderMessageItem}
|
||||
/>
|
||||
<KeyboardAvoidingView
|
||||
keyboardVerticalOffset={110}
|
||||
behavior="padding"
|
||||
className="p-3 bg-white border-t border-gray-300"
|
||||
>
|
||||
<SafeAreaView className="flex-row items-center gap-2">
|
||||
<TouchableOpacity
|
||||
onPress={handleImageUpload}
|
||||
disabled={isUploading}
|
||||
className="h-10 w-10 items-center justify-center"
|
||||
>
|
||||
{isUploading ? (
|
||||
<ActivityIndicator size="small" color="#0000ff" />
|
||||
) : (
|
||||
<Text className="text-2xl">🖼️</Text>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
<TextInput
|
||||
className="flex-1 rounded-full h-10 px-4 bg-gray-100 border border-gray-300 focus:border-blue-500 focus:bg-white"
|
||||
value={message}
|
||||
onChangeText={setMessage}
|
||||
placeholder="Type a message..."
|
||||
textAlignVertical="center"
|
||||
onSubmitEditing={sendMessage}
|
||||
/>
|
||||
<TouchableOpacity
|
||||
onPress={sendMessage}
|
||||
className="bg-blue-500 rounded-full h-10 w-10 items-center justify-center"
|
||||
>
|
||||
<Text className="text-white text-xl">↑</Text>
|
||||
</TouchableOpacity>
|
||||
</SafeAreaView>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Stack } from "expo-router";
|
||||
import React from "react";
|
||||
|
||||
export default function ChatLayout() {
|
||||
return (
|
||||
<Stack
|
||||
screenOptions={{
|
||||
headerShown: true,
|
||||
headerBackVisible: true,
|
||||
headerTitle: "",
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import { useRouter } from "expo-router";
|
||||
import { ID } from "jazz-tools";
|
||||
import { useLayoutEffect } from "react";
|
||||
import React, {
|
||||
Button,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
Alert,
|
||||
} from "react-native";
|
||||
|
||||
import { useUser } from "@clerk/clerk-expo";
|
||||
import { useAccount } from "jazz-expo";
|
||||
import { Chat } from "../../src/schema";
|
||||
|
||||
export default function ChatScreen() {
|
||||
const { logOut } = useAccount();
|
||||
const router = useRouter();
|
||||
const navigation = useNavigation();
|
||||
const { user } = useUser();
|
||||
|
||||
function handleLogOut() {
|
||||
logOut();
|
||||
router.navigate("/");
|
||||
}
|
||||
|
||||
useLayoutEffect(() => {
|
||||
navigation.setOptions({
|
||||
headerTitle: "Chat",
|
||||
headerRight: () => <Button onPress={handleLogOut} title="Logout" />,
|
||||
});
|
||||
}, [navigation]);
|
||||
|
||||
const loadChat = async (chatId: string | "new") => {
|
||||
router.navigate(`/chat/${chatId}`);
|
||||
};
|
||||
|
||||
const joinChat = () => {
|
||||
Alert.prompt(
|
||||
"Join Chat",
|
||||
"Enter the Chat ID (example: co_zBGEHYvRfGuT2YSBraY3njGjnde)",
|
||||
[
|
||||
{
|
||||
text: "Cancel",
|
||||
style: "cancel",
|
||||
},
|
||||
{
|
||||
text: "Join",
|
||||
onPress: (chatId) => {
|
||||
if (chatId) {
|
||||
loadChat(chatId);
|
||||
} else {
|
||||
Alert.alert("Error", "Chat ID cannot be empty.");
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
"plain-text",
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-gray-50">
|
||||
<View className="flex-1 justify-center items-center px-6">
|
||||
<View className="w-full max-w-sm bg-white p-8 rounded-lg shadow-lg">
|
||||
<Text className="text-xl font-semibold text-gray-800">
|
||||
Welcome, {user?.emailAddresses[0].emailAddress}
|
||||
</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => loadChat("new")}
|
||||
className="w-full bg-blue-600 py-4 rounded-md mb-4 mt-4"
|
||||
>
|
||||
<Text className="text-white text-lg font-semibold text-center">
|
||||
Start New Chat
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
onPress={joinChat}
|
||||
className="w-full bg-green-500 py-4 rounded-md"
|
||||
>
|
||||
<Text className="text-white text-lg font-semibold text-center">
|
||||
Join Chat
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 313 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 46 KiB |
@@ -1,9 +0,0 @@
|
||||
module.exports = function (api) {
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: [
|
||||
["babel-preset-expo", { jsxImportSource: "nativewind" }],
|
||||
"nativewind/babel",
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import * as SecureStore from "expo-secure-store";
|
||||
import { Platform } from "react-native";
|
||||
|
||||
export interface TokenCache {
|
||||
getToken: (key: string) => Promise<string | undefined | null>;
|
||||
saveToken: (key: string, token: string) => Promise<void>;
|
||||
clearToken: (key: string) => void;
|
||||
}
|
||||
|
||||
const createTokenCache = (): TokenCache => {
|
||||
return {
|
||||
getToken: async (key: string) => {
|
||||
try {
|
||||
const item = await SecureStore.getItemAsync(key);
|
||||
if (item) {
|
||||
console.log(`${key} was used 🔐 \n`);
|
||||
} else {
|
||||
console.log("No values stored under key: " + key);
|
||||
}
|
||||
return item;
|
||||
} catch (error) {
|
||||
console.error("secure store get item error: ", error);
|
||||
await SecureStore.deleteItemAsync(key);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
saveToken: (key: string, token: string) => {
|
||||
return SecureStore.setItemAsync(key, token);
|
||||
},
|
||||
clearToken: (key: string) => {
|
||||
return SecureStore.deleteItemAsync(key);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// SecureStore is not supported on the web
|
||||
// https://github.com/expo/expo/issues/7744#issuecomment-611093485
|
||||
export const tokenCache =
|
||||
Platform.OS !== "web" ? createTokenCache() : undefined;
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"cli": {
|
||||
"version": ">= 12.5.1",
|
||||
"appVersionSource": "remote"
|
||||
},
|
||||
"build": {
|
||||
"development": {
|
||||
"developmentClient": true,
|
||||
"distribution": "internal"
|
||||
},
|
||||
"ios-simulator": {
|
||||
"extends": "development",
|
||||
"ios": {
|
||||
"simulator": true
|
||||
}
|
||||
},
|
||||
"preview": {
|
||||
"distribution": "internal"
|
||||
},
|
||||
"production": {
|
||||
"autoIncrement": true
|
||||
}
|
||||
},
|
||||
"submit": {
|
||||
"production": {}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@@ -1,2 +0,0 @@
|
||||
import "./polyfills";
|
||||
import "expo-router/entry";
|
||||
@@ -1,35 +0,0 @@
|
||||
// Learn more https://docs.expo.dev/guides/monorepos
|
||||
const { getDefaultConfig } = require("expo/metro-config");
|
||||
const { withNativeWind } = require("nativewind/metro");
|
||||
const { FileStore } = require("metro-cache");
|
||||
const path = require("path");
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const projectRoot = __dirname;
|
||||
const workspaceRoot = path.resolve(projectRoot, "../..");
|
||||
|
||||
const config = getDefaultConfig(projectRoot);
|
||||
|
||||
// Since we are using pnpm, we have to setup the monorepo manually for Metro
|
||||
// #1 - Watch all files in the monorepo
|
||||
config.watchFolders = [workspaceRoot];
|
||||
// #2 - Try resolving with project modules first, then workspace modules
|
||||
config.resolver.nodeModulesPaths = [
|
||||
path.resolve(projectRoot, "node_modules"),
|
||||
path.resolve(workspaceRoot, "node_modules"),
|
||||
];
|
||||
config.resolver.sourceExts = ["mjs", "js", "json", "ts", "tsx"];
|
||||
config.resolver.requireCycleIgnorePatterns = [
|
||||
/(^|\/|\\)node_modules($|\/|\\)/,
|
||||
/(^|\/|\\)packages($|\/|\\)/,
|
||||
];
|
||||
|
||||
// Use turborepo to restore the cache when possible
|
||||
config.cacheStores = [
|
||||
new FileStore({
|
||||
root: path.join(projectRoot, "node_modules", ".cache", "metro"),
|
||||
}),
|
||||
];
|
||||
|
||||
// module.exports = config;
|
||||
module.exports = withNativeWind(config, { input: "./global.css" });
|
||||
@@ -1 +0,0 @@
|
||||
/// <reference types="nativewind/types" />
|
||||
@@ -1,65 +0,0 @@
|
||||
{
|
||||
"name": "chat-rn-expo-clerk",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
"start": "expo start",
|
||||
"format-and-lint": "biome check .",
|
||||
"format-and-lint:fix": "biome check . --write",
|
||||
"android": "expo run:android",
|
||||
"ios": "expo prebuild && pnpx pod-install && expo run:ios",
|
||||
"web": "expo start --web",
|
||||
"run:ios": "pnpm expo prebuild && npx pod-install && pnpm expo run:ios"
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/core-asynciterator-polyfill": "^1.0.2",
|
||||
"@bacons/text-decoder": "0.0.0",
|
||||
"@bam.tech/react-native-image-resizer": "^3.0.11",
|
||||
"@clerk/clerk-expo": "^2.2.21",
|
||||
"@expo/vector-icons": "^14.1.0",
|
||||
"@react-native-community/netinfo": "11.4.1",
|
||||
"@react-navigation/native": "7.0.19",
|
||||
"@react-navigation/native-stack": "7.2.1",
|
||||
"clsx": "^2.0.0",
|
||||
"expo": "^53.0.8",
|
||||
"expo-build-properties": "~0.14.6",
|
||||
"expo-clipboard": "~7.1.4",
|
||||
"expo-constants": "~17.1.6",
|
||||
"expo-crypto": "~14.1.4",
|
||||
"expo-dev-client": "~5.1.8",
|
||||
"expo-file-system": "^18.1.9",
|
||||
"expo-font": "~13.3.1",
|
||||
"expo-image-picker": "~16.1.4",
|
||||
"expo-linking": "~7.1.4",
|
||||
"expo-router": "~5.0.6",
|
||||
"expo-secure-store": "~14.2.3",
|
||||
"expo-splash-screen": "~0.30.8",
|
||||
"expo-sqlite": "15.2.9",
|
||||
"expo-status-bar": "~2.2.3",
|
||||
"expo-web-browser": "~14.1.6",
|
||||
"jazz-expo": "workspace:*",
|
||||
"jazz-react-native-media-images": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"nativewind": "^4.1.21",
|
||||
"react": "19.0.0",
|
||||
"react-dom": "19.0.0",
|
||||
"react-native": "0.79.2",
|
||||
"react-native-gesture-handler": "~2.24.0",
|
||||
"react-native-get-random-values": "^1.11.0",
|
||||
"react-native-reanimated": "~3.17.5",
|
||||
"react-native-safe-area-context": "5.4.0",
|
||||
"react-native-screens": "4.10.0",
|
||||
"react-native-url-polyfill": "^2.0.0",
|
||||
"react-native-web": "~0.20.0",
|
||||
"readable-stream": "4.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.25.2",
|
||||
"@types/react": "~19.0.14",
|
||||
"@types/react-test-renderer": "^19.0.0",
|
||||
"react-test-renderer": "18.3.1",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "5.8.3"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export const apiKey = "chat-rn-expo-clerk-example-jazz@garden.co";
|
||||
@@ -1,19 +0,0 @@
|
||||
import { useClerk } from "@clerk/clerk-expo";
|
||||
import { JazzProviderWithClerk } from "jazz-expo/auth/clerk";
|
||||
import React, { PropsWithChildren } from "react";
|
||||
import { apiKey } from "./apiKey";
|
||||
|
||||
export function JazzAndAuth({ children }: PropsWithChildren) {
|
||||
const clerk = useClerk();
|
||||
|
||||
return (
|
||||
<JazzProviderWithClerk
|
||||
clerk={clerk}
|
||||
sync={{
|
||||
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</JazzProviderWithClerk>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
// NOTE: Update this to include the paths to all of your component files.
|
||||
content: [
|
||||
"./app/**/*.{js,jsx,ts,tsx}",
|
||||
"./components/**/*.{js,jsx,ts,tsx}",
|
||||
"./src/**/*.{js,jsx,ts,tsx}",
|
||||
],
|
||||
presets: [require("nativewind/preset")],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"extends": "expo/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler",
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx", "nativewind-env.d.ts"]
|
||||
}
|
||||
@@ -13,15 +13,13 @@
|
||||
"@bacons/text-decoder": "^0.0.0",
|
||||
"@bam.tech/react-native-image-resizer": "^3.0.11",
|
||||
"@react-native-community/netinfo": "11.4.1",
|
||||
"expo": "~53.0.9",
|
||||
"expo-clipboard": "^7.1.4",
|
||||
"expo-secure-store": "~14.2.3",
|
||||
"expo-sqlite": "~15.2.10",
|
||||
"expo-status-bar": "~2.2.3",
|
||||
"jazz-expo": "workspace:*",
|
||||
"expo": "catalog:expo",
|
||||
"expo-clipboard": "catalog:expo",
|
||||
"expo-secure-store": "catalog:expo",
|
||||
"expo-sqlite": "catalog:expo",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "19.0.0",
|
||||
"react-native": "0.79.2",
|
||||
"react": "catalog:expo",
|
||||
"react-native": "catalog:expo",
|
||||
"react-native-get-random-values": "^1.11.0",
|
||||
"readable-stream": "^4.7.0"
|
||||
},
|
||||
@@ -31,4 +29,4 @@
|
||||
"typescript": "~5.8.3"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { JazzProvider } from "jazz-expo";
|
||||
import { JazzExpoProvider } from "jazz-tools/expo";
|
||||
import React, { StrictMode } from "react";
|
||||
import { apiKey } from "./apiKey";
|
||||
import ChatScreen from "./chat";
|
||||
@@ -6,13 +6,13 @@ import ChatScreen from "./chat";
|
||||
export default function App() {
|
||||
return (
|
||||
<StrictMode>
|
||||
<JazzProvider
|
||||
<JazzExpoProvider
|
||||
sync={{
|
||||
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
|
||||
}}
|
||||
>
|
||||
<ChatScreen />
|
||||
</JazzProvider>
|
||||
</JazzExpoProvider>
|
||||
</StrictMode>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import React, {
|
||||
StyleSheet,
|
||||
} from "react-native";
|
||||
|
||||
import { useAccount, useCoState } from "jazz-expo";
|
||||
import { useAccount, useCoState } from "jazz-tools/expo";
|
||||
import { Chat, Message } from "./schema";
|
||||
|
||||
export default function ChatScreen() {
|
||||
|
||||
@@ -11,11 +11,11 @@ react {
|
||||
// The root of your project, i.e. where "package.json" lives. Default is '../..'
|
||||
// root = file("../../")
|
||||
// The folder where the react-native NPM package is. Default is ../../node_modules/react-native
|
||||
// reactNativeDir = file("../../node_modules/react-native")
|
||||
reactNativeDir = file("../../../../node_modules/react-native")
|
||||
// The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
|
||||
// codegenDir = file("../../node_modules/@react-native/codegen")
|
||||
codegenDir = file("../../../../node_modules/@react-native/codegen")
|
||||
// The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
|
||||
// cliFile = file("../../node_modules/react-native/cli.js")
|
||||
cliFile = file("../../../../node_modules/react-native/cli.js")
|
||||
|
||||
/* Variants */
|
||||
// The list of variants to that are debuggable. For those we're going to
|
||||
@@ -63,14 +63,14 @@ def enableProguardInReleaseBuilds = false
|
||||
* The preferred build flavor of JavaScriptCore (JSC)
|
||||
*
|
||||
* For example, to use the international variant, you can use:
|
||||
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
|
||||
* `def jscFlavor = io.github.react-native-community:jsc-android-intl:2026004.+`
|
||||
*
|
||||
* The international variant includes ICU i18n library and necessary data
|
||||
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
|
||||
* give correct results when using with locales other than en-US. Note that
|
||||
* this variant is about 6MiB larger per architecture than default.
|
||||
*/
|
||||
def jscFlavor = 'org.webkit:android-jsc:+'
|
||||
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'
|
||||
|
||||
android {
|
||||
ndkVersion rootProject.ext.ndkVersion
|
||||
|
||||
@@ -4,13 +4,11 @@ import android.app.Application
|
||||
import com.facebook.react.PackageList
|
||||
import com.facebook.react.ReactApplication
|
||||
import com.facebook.react.ReactHost
|
||||
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
||||
import com.facebook.react.ReactNativeHost
|
||||
import com.facebook.react.ReactPackage
|
||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
|
||||
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
||||
import com.facebook.react.defaults.DefaultReactNativeHost
|
||||
import com.facebook.react.soloader.OpenSourceMergedSoMapping
|
||||
import com.facebook.soloader.SoLoader
|
||||
|
||||
class MainApplication : Application(), ReactApplication {
|
||||
|
||||
@@ -35,10 +33,6 @@ class MainApplication : Application(), ReactApplication {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
SoLoader.init(this, OpenSourceMergedSoMapping)
|
||||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
||||
// If you opted-in for the New Architecture, we load the native entry point for this app.
|
||||
load()
|
||||
}
|
||||
loadReactNative(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ buildscript {
|
||||
buildToolsVersion = "35.0.0"
|
||||
minSdkVersion = 24
|
||||
compileSdkVersion = 35
|
||||
targetSdkVersion = 34
|
||||
ndkVersion = "26.1.10909125"
|
||||
kotlinVersion = "1.9.25"
|
||||
targetSdkVersion = 35
|
||||
ndkVersion = "27.1.12297006"
|
||||
kotlinVersion = "2.1.20"
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
|
||||