cojson 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/account.d.ts +1 -1
  2. package/dist/account.js +1 -1
  3. package/dist/account.js.map +1 -1
  4. package/dist/coValue.d.ts +3 -2
  5. package/dist/coValue.js +10 -9
  6. package/dist/coValue.js.map +1 -1
  7. package/dist/contentTypes/coMap.d.ts +2 -2
  8. package/dist/contentTypes/coMap.js +6 -6
  9. package/dist/contentTypes/coMap.js.map +1 -1
  10. package/dist/index.d.ts +5 -2
  11. package/dist/index.js +3 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/node.d.ts +2 -1
  14. package/dist/node.js +43 -3
  15. package/dist/node.js.map +1 -1
  16. package/dist/permissions.d.ts +4 -32
  17. package/dist/permissions.js +42 -106
  18. package/dist/permissions.js.map +1 -1
  19. package/dist/team.d.ts +35 -0
  20. package/dist/team.js +110 -0
  21. package/dist/team.js.map +1 -0
  22. package/dist/testUtils.d.ts +2 -2
  23. package/dist/testUtils.js +1 -1
  24. package/dist/testUtils.js.map +1 -1
  25. package/package.json +2 -2
  26. package/src/account.ts +1 -1
  27. package/src/coValue.ts +10 -11
  28. package/src/contentTypes/coMap.ts +8 -8
  29. package/src/crypto.test.ts +10 -9
  30. package/src/index.ts +5 -0
  31. package/src/node.ts +113 -11
  32. package/src/permissions.test.ts +503 -3
  33. package/src/permissions.ts +70 -206
  34. package/src/sync.test.ts +8 -8
  35. package/src/team.ts +225 -0
  36. package/src/testUtils.ts +1 -1
  37. package/tsconfig.json +1 -0
  38. package/dist/account.test.d.ts +0 -1
  39. package/dist/account.test.js +0 -40
  40. package/dist/account.test.js.map +0 -1
  41. package/dist/coValue.test.d.ts +0 -1
  42. package/dist/coValue.test.js +0 -78
  43. package/dist/coValue.test.js.map +0 -1
  44. package/dist/contentType.test.d.ts +0 -1
  45. package/dist/contentType.test.js +0 -145
  46. package/dist/contentType.test.js.map +0 -1
  47. package/dist/crypto.test.d.ts +0 -1
  48. package/dist/crypto.test.js +0 -111
  49. package/dist/crypto.test.js.map +0 -1
  50. package/dist/permissions.test.d.ts +0 -1
  51. package/dist/permissions.test.js +0 -711
  52. package/dist/permissions.test.js.map +0 -1
  53. package/dist/sync.test.d.ts +0 -1
  54. package/dist/sync.test.js +0 -827
  55. package/dist/sync.test.js.map +0 -1
@@ -1,13 +1,15 @@
1
1
  import { newRandomSessionID } from "./coValue.js";
2
- import { LocalNode } from "./node.js";
3
2
  import { expectMap } from "./contentType.js";
4
- import { expectTeamContent } from "./permissions.js";
3
+ import { Team, expectTeamContent } from "./team.js";
5
4
  import {
6
5
  createdNowUnique,
7
- getSealerID,
8
6
  newRandomKeySecret,
9
7
  seal,
10
8
  encryptKeySecret,
9
+ newRandomAgentSecret,
10
+ getAgentID,
11
+ getAgentSealerSecret,
12
+ getAgentSealerID,
11
13
  } from "./crypto.js";
12
14
  import {
13
15
  newTeam,
@@ -15,6 +17,7 @@ import {
15
17
  teamWithTwoAdmins,
16
18
  teamWithTwoAdminsHighLevel,
17
19
  } from "./testUtils.js";
20
+ import { AnonymousControlledAccount } from "./index.js";
18
21
 
19
22
  test("Initial admin can add another admin to a team", () => {
20
23
  teamWithTwoAdmins();
@@ -1265,3 +1268,500 @@ test("Can create two owned objects in the same team and they will have different
1265
1268
 
1266
1269
  expect(childObject1.id).not.toEqual(childObject2.id);
1267
1270
  });
1271
+
1272
+ test("Admins can create an adminInvite, which can add an admin", () => {
1273
+ const { node, team, admin } = newTeam();
1274
+
1275
+ const inviteSecret = newRandomAgentSecret();
1276
+ const inviteID = getAgentID(inviteSecret);
1277
+
1278
+ expectTeamContent(team.getCurrentContent()).edit((editable) => {
1279
+ const { secret: readKey, id: readKeyID } = newRandomKeySecret();
1280
+ const revelation = seal(
1281
+ readKey,
1282
+ admin.currentSealerSecret(),
1283
+ admin.currentSealerID(),
1284
+ {
1285
+ in: team.id,
1286
+ tx: team.nextTransactionID(),
1287
+ }
1288
+ );
1289
+
1290
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1291
+ editable.set("readKey", readKeyID, "trusting");
1292
+
1293
+ editable.set(inviteID, "adminInvite", "trusting");
1294
+
1295
+ expect(editable.get(inviteID)).toEqual("adminInvite");
1296
+
1297
+ const revelationForInvite = seal(
1298
+ readKey,
1299
+ admin.currentSealerSecret(),
1300
+ getAgentSealerID(inviteID),
1301
+ {
1302
+ in: team.id,
1303
+ tx: team.nextTransactionID(),
1304
+ }
1305
+ );
1306
+
1307
+ editable.set(
1308
+ `${readKeyID}_for_${inviteID}`,
1309
+ revelationForInvite,
1310
+ "trusting"
1311
+ );
1312
+ });
1313
+
1314
+ const teamAsInvite = team.testWithDifferentAccount(
1315
+ new AnonymousControlledAccount(inviteSecret),
1316
+ newRandomSessionID(inviteID)
1317
+ );
1318
+
1319
+ const invitedAdminSecret = newRandomAgentSecret();
1320
+ const invitedAdminID = getAgentID(invitedAdminSecret);
1321
+
1322
+ expectTeamContent(teamAsInvite.getCurrentContent()).edit((editable) => {
1323
+ editable.set(invitedAdminID, "admin", "trusting");
1324
+
1325
+ expect(editable.get(invitedAdminID)).toEqual("admin");
1326
+
1327
+ const readKey = teamAsInvite.getCurrentReadKey();
1328
+
1329
+ expect(readKey.secret).toBeDefined();
1330
+
1331
+ const revelation = seal(
1332
+ readKey.secret!,
1333
+ getAgentSealerSecret(invitedAdminSecret),
1334
+ getAgentSealerID(invitedAdminID),
1335
+ {
1336
+ in: team.id,
1337
+ tx: team.nextTransactionID(),
1338
+ }
1339
+ );
1340
+
1341
+ editable.set(
1342
+ `${readKey.id}_for_${invitedAdminID}`,
1343
+ revelation,
1344
+ "trusting"
1345
+ );
1346
+
1347
+ expect(editable.get(`${readKey.id}_for_${invitedAdminID}`)).toEqual(
1348
+ revelation
1349
+ );
1350
+ });
1351
+ });
1352
+
1353
+ test("Admins can create an adminInvite, which can add an admin (high-level)", async () => {
1354
+ const { node, team, admin } = newTeamHighLevel();
1355
+
1356
+ const inviteSecret = team.createInvite("admin");
1357
+
1358
+ const invitedAdminSecret = newRandomAgentSecret();
1359
+ const invitedAdminID = getAgentID(invitedAdminSecret);
1360
+
1361
+ const nodeAsInvitedAdmin = node.testWithDifferentAccount(
1362
+ new AnonymousControlledAccount(invitedAdminSecret),
1363
+ newRandomSessionID(invitedAdminID)
1364
+ );
1365
+
1366
+ await nodeAsInvitedAdmin.acceptInvite(team.id, inviteSecret);
1367
+
1368
+ const thirdAdmin = newRandomAgentSecret();
1369
+ const thirdAdminID = getAgentID(thirdAdmin);
1370
+
1371
+ const teamAsInvitedAdmin = new Team(
1372
+ await nodeAsInvitedAdmin.load(team.id),
1373
+ nodeAsInvitedAdmin
1374
+ );
1375
+
1376
+ expect(teamAsInvitedAdmin.teamMap.get(invitedAdminID)).toEqual("admin");
1377
+ expect(
1378
+ teamAsInvitedAdmin.teamMap.coValue.getCurrentReadKey().secret
1379
+ ).toBeDefined();
1380
+
1381
+ teamAsInvitedAdmin.addMember(thirdAdminID, "admin");
1382
+
1383
+ expect(teamAsInvitedAdmin.teamMap.get(thirdAdminID)).toEqual("admin");
1384
+ });
1385
+
1386
+ test("Admins can create a writerInvite, which can add a writer", () => {
1387
+ const { node, team, admin } = newTeam();
1388
+
1389
+ const inviteSecret = newRandomAgentSecret();
1390
+ const inviteID = getAgentID(inviteSecret);
1391
+
1392
+ expectTeamContent(team.getCurrentContent()).edit((editable) => {
1393
+ const { secret: readKey, id: readKeyID } = newRandomKeySecret();
1394
+ const revelation = seal(
1395
+ readKey,
1396
+ admin.currentSealerSecret(),
1397
+ admin.currentSealerID(),
1398
+ {
1399
+ in: team.id,
1400
+ tx: team.nextTransactionID(),
1401
+ }
1402
+ );
1403
+
1404
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1405
+ editable.set("readKey", readKeyID, "trusting");
1406
+
1407
+ editable.set(inviteID, "writerInvite", "trusting");
1408
+
1409
+ expect(editable.get(inviteID)).toEqual("writerInvite");
1410
+
1411
+ const revelationForInvite = seal(
1412
+ readKey,
1413
+ admin.currentSealerSecret(),
1414
+ getAgentSealerID(inviteID),
1415
+ {
1416
+ in: team.id,
1417
+ tx: team.nextTransactionID(),
1418
+ }
1419
+ );
1420
+
1421
+ editable.set(
1422
+ `${readKeyID}_for_${inviteID}`,
1423
+ revelationForInvite,
1424
+ "trusting"
1425
+ );
1426
+ });
1427
+
1428
+ const teamAsInvite = team.testWithDifferentAccount(
1429
+ new AnonymousControlledAccount(inviteSecret),
1430
+ newRandomSessionID(inviteID)
1431
+ );
1432
+
1433
+ const invitedWriterSecret = newRandomAgentSecret();
1434
+ const invitedWriterID = getAgentID(invitedWriterSecret);
1435
+
1436
+ expectTeamContent(teamAsInvite.getCurrentContent()).edit((editable) => {
1437
+ editable.set(invitedWriterID, "writer", "trusting");
1438
+
1439
+ expect(editable.get(invitedWriterID)).toEqual("writer");
1440
+
1441
+ const readKey = teamAsInvite.getCurrentReadKey();
1442
+
1443
+ expect(readKey.secret).toBeDefined();
1444
+
1445
+ const revelation = seal(
1446
+ readKey.secret!,
1447
+ getAgentSealerSecret(invitedWriterSecret),
1448
+ getAgentSealerID(invitedWriterID),
1449
+ {
1450
+ in: team.id,
1451
+ tx: team.nextTransactionID(),
1452
+ }
1453
+ );
1454
+
1455
+ editable.set(
1456
+ `${readKey.id}_for_${invitedWriterID}`,
1457
+ revelation,
1458
+ "trusting"
1459
+ );
1460
+
1461
+ expect(editable.get(`${readKey.id}_for_${invitedWriterID}`)).toEqual(
1462
+ revelation
1463
+ );
1464
+ });
1465
+ });
1466
+
1467
+ test("Admins can create a writerInvite, which can add a writer (high-level)", async () => {
1468
+ const { node, team, admin } = newTeamHighLevel();
1469
+
1470
+ const inviteSecret = team.createInvite("writer");
1471
+
1472
+ const invitedWriterSecret = newRandomAgentSecret();
1473
+ const invitedWriterID = getAgentID(invitedWriterSecret);
1474
+
1475
+ const nodeAsInvitedWriter = node.testWithDifferentAccount(
1476
+ new AnonymousControlledAccount(invitedWriterSecret),
1477
+ newRandomSessionID(invitedWriterID)
1478
+ );
1479
+
1480
+ await nodeAsInvitedWriter.acceptInvite(team.id, inviteSecret);
1481
+
1482
+ const teamAsInvitedWriter = new Team(
1483
+ await nodeAsInvitedWriter.load(team.id),
1484
+ nodeAsInvitedWriter
1485
+ );
1486
+
1487
+ expect(teamAsInvitedWriter.teamMap.get(invitedWriterID)).toEqual("writer");
1488
+ expect(
1489
+ teamAsInvitedWriter.teamMap.coValue.getCurrentReadKey().secret
1490
+ ).toBeDefined();
1491
+ });
1492
+
1493
+
1494
+ test("Admins can create a readerInvite, which can add a reader", () => {
1495
+ const { node, team, admin } = newTeam();
1496
+
1497
+ const inviteSecret = newRandomAgentSecret();
1498
+ const inviteID = getAgentID(inviteSecret);
1499
+
1500
+ expectTeamContent(team.getCurrentContent()).edit((editable) => {
1501
+ const { secret: readKey, id: readKeyID } = newRandomKeySecret();
1502
+ const revelation = seal(
1503
+ readKey,
1504
+ admin.currentSealerSecret(),
1505
+ admin.currentSealerID(),
1506
+ {
1507
+ in: team.id,
1508
+ tx: team.nextTransactionID(),
1509
+ }
1510
+ );
1511
+
1512
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1513
+ editable.set("readKey", readKeyID, "trusting");
1514
+
1515
+ editable.set(inviteID, "readerInvite", "trusting");
1516
+
1517
+ expect(editable.get(inviteID)).toEqual("readerInvite");
1518
+
1519
+ const revelationForInvite = seal(
1520
+ readKey,
1521
+ admin.currentSealerSecret(),
1522
+ getAgentSealerID(inviteID),
1523
+ {
1524
+ in: team.id,
1525
+ tx: team.nextTransactionID(),
1526
+ }
1527
+ );
1528
+
1529
+ editable.set(
1530
+ `${readKeyID}_for_${inviteID}`,
1531
+ revelationForInvite,
1532
+ "trusting"
1533
+ );
1534
+ });
1535
+
1536
+ const teamAsInvite = team.testWithDifferentAccount(
1537
+ new AnonymousControlledAccount(inviteSecret),
1538
+ newRandomSessionID(inviteID)
1539
+ );
1540
+
1541
+ const invitedReaderSecret = newRandomAgentSecret();
1542
+ const invitedReaderID = getAgentID(invitedReaderSecret);
1543
+
1544
+ expectTeamContent(teamAsInvite.getCurrentContent()).edit((editable) => {
1545
+ editable.set(invitedReaderID, "reader", "trusting");
1546
+
1547
+ expect(editable.get(invitedReaderID)).toEqual("reader");
1548
+
1549
+ const readKey = teamAsInvite.getCurrentReadKey();
1550
+
1551
+ expect(readKey.secret).toBeDefined();
1552
+
1553
+ const revelation = seal(
1554
+ readKey.secret!,
1555
+ getAgentSealerSecret(invitedReaderSecret),
1556
+ getAgentSealerID(invitedReaderID),
1557
+ {
1558
+ in: team.id,
1559
+ tx: team.nextTransactionID(),
1560
+ }
1561
+ );
1562
+
1563
+ editable.set(
1564
+ `${readKey.id}_for_${invitedReaderID}`,
1565
+ revelation,
1566
+ "trusting"
1567
+ );
1568
+
1569
+ expect(editable.get(`${readKey.id}_for_${invitedReaderID}`)).toEqual(
1570
+ revelation
1571
+ );
1572
+ });
1573
+ });
1574
+
1575
+ test("Admins can create a readerInvite, which can add a reader (high-level)", async () => {
1576
+ const { node, team, admin } = newTeamHighLevel();
1577
+
1578
+ const inviteSecret = team.createInvite("reader");
1579
+
1580
+ const invitedReaderSecret = newRandomAgentSecret();
1581
+ const invitedReaderID = getAgentID(invitedReaderSecret);
1582
+
1583
+ const nodeAsInvitedReader = node.testWithDifferentAccount(
1584
+ new AnonymousControlledAccount(invitedReaderSecret),
1585
+ newRandomSessionID(invitedReaderID)
1586
+ );
1587
+
1588
+ await nodeAsInvitedReader.acceptInvite(team.id, inviteSecret);
1589
+
1590
+ const teamAsInvitedReader = new Team(
1591
+ await nodeAsInvitedReader.load(team.id),
1592
+ nodeAsInvitedReader
1593
+ );
1594
+
1595
+ expect(teamAsInvitedReader.teamMap.get(invitedReaderID)).toEqual("reader");
1596
+ expect(
1597
+ teamAsInvitedReader.teamMap.coValue.getCurrentReadKey().secret
1598
+ ).toBeDefined();
1599
+ });
1600
+
1601
+ test("WriterInvites can not invite admins", () => {
1602
+ const { node, team, admin } = newTeam();
1603
+
1604
+ const inviteSecret = newRandomAgentSecret();
1605
+ const inviteID = getAgentID(inviteSecret);
1606
+
1607
+ expectTeamContent(team.getCurrentContent()).edit((editable) => {
1608
+ const { secret: readKey, id: readKeyID } = newRandomKeySecret();
1609
+ const revelation = seal(
1610
+ readKey,
1611
+ admin.currentSealerSecret(),
1612
+ admin.currentSealerID(),
1613
+ {
1614
+ in: team.id,
1615
+ tx: team.nextTransactionID(),
1616
+ }
1617
+ );
1618
+
1619
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1620
+ editable.set("readKey", readKeyID, "trusting");
1621
+
1622
+ editable.set(inviteID, "writerInvite", "trusting");
1623
+
1624
+ expect(editable.get(inviteID)).toEqual("writerInvite");
1625
+
1626
+ const revelationForInvite = seal(
1627
+ readKey,
1628
+ admin.currentSealerSecret(),
1629
+ getAgentSealerID(inviteID),
1630
+ {
1631
+ in: team.id,
1632
+ tx: team.nextTransactionID(),
1633
+ }
1634
+ );
1635
+
1636
+ editable.set(
1637
+ `${readKeyID}_for_${inviteID}`,
1638
+ revelationForInvite,
1639
+ "trusting"
1640
+ );
1641
+ });
1642
+
1643
+ const teamAsInvite = team.testWithDifferentAccount(
1644
+ new AnonymousControlledAccount(inviteSecret),
1645
+ newRandomSessionID(inviteID)
1646
+ );
1647
+
1648
+ const invitedAdminSecret = newRandomAgentSecret();
1649
+ const invitedAdminID = getAgentID(invitedAdminSecret);
1650
+
1651
+ expectTeamContent(teamAsInvite.getCurrentContent()).edit((editable) => {
1652
+ editable.set(invitedAdminID, "admin", "trusting");
1653
+ expect(editable.get(invitedAdminID)).toBeUndefined();
1654
+ });
1655
+ });
1656
+
1657
+ test("ReaderInvites can not invite admins", () => {
1658
+ const { node, team, admin } = newTeam();
1659
+
1660
+ const inviteSecret = newRandomAgentSecret();
1661
+ const inviteID = getAgentID(inviteSecret);
1662
+
1663
+ expectTeamContent(team.getCurrentContent()).edit((editable) => {
1664
+ const { secret: readKey, id: readKeyID } = newRandomKeySecret();
1665
+ const revelation = seal(
1666
+ readKey,
1667
+ admin.currentSealerSecret(),
1668
+ admin.currentSealerID(),
1669
+ {
1670
+ in: team.id,
1671
+ tx: team.nextTransactionID(),
1672
+ }
1673
+ );
1674
+
1675
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1676
+ editable.set("readKey", readKeyID, "trusting");
1677
+
1678
+ editable.set(inviteID, "readerInvite", "trusting");
1679
+
1680
+ expect(editable.get(inviteID)).toEqual("readerInvite");
1681
+
1682
+ const revelationForInvite = seal(
1683
+ readKey,
1684
+ admin.currentSealerSecret(),
1685
+ getAgentSealerID(inviteID),
1686
+ {
1687
+ in: team.id,
1688
+ tx: team.nextTransactionID(),
1689
+ }
1690
+ );
1691
+
1692
+ editable.set(
1693
+ `${readKeyID}_for_${inviteID}`,
1694
+ revelationForInvite,
1695
+ "trusting"
1696
+ );
1697
+ });
1698
+
1699
+ const teamAsInvite = team.testWithDifferentAccount(
1700
+ new AnonymousControlledAccount(inviteSecret),
1701
+ newRandomSessionID(inviteID)
1702
+ );
1703
+
1704
+ const invitedAdminSecret = newRandomAgentSecret();
1705
+ const invitedAdminID = getAgentID(invitedAdminSecret);
1706
+
1707
+ expectTeamContent(teamAsInvite.getCurrentContent()).edit((editable) => {
1708
+ editable.set(invitedAdminID, "admin", "trusting");
1709
+ expect(editable.get(invitedAdminID)).toBeUndefined();
1710
+ });
1711
+ });
1712
+
1713
+ test("ReaderInvites can not invite writers", () => {
1714
+ const { node, team, admin } = newTeam();
1715
+
1716
+ const inviteSecret = newRandomAgentSecret();
1717
+ const inviteID = getAgentID(inviteSecret);
1718
+
1719
+ expectTeamContent(team.getCurrentContent()).edit((editable) => {
1720
+ const { secret: readKey, id: readKeyID } = newRandomKeySecret();
1721
+ const revelation = seal(
1722
+ readKey,
1723
+ admin.currentSealerSecret(),
1724
+ admin.currentSealerID(),
1725
+ {
1726
+ in: team.id,
1727
+ tx: team.nextTransactionID(),
1728
+ }
1729
+ );
1730
+
1731
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1732
+ editable.set("readKey", readKeyID, "trusting");
1733
+
1734
+ editable.set(inviteID, "readerInvite", "trusting");
1735
+
1736
+ expect(editable.get(inviteID)).toEqual("readerInvite");
1737
+
1738
+ const revelationForInvite = seal(
1739
+ readKey,
1740
+ admin.currentSealerSecret(),
1741
+ getAgentSealerID(inviteID),
1742
+ {
1743
+ in: team.id,
1744
+ tx: team.nextTransactionID(),
1745
+ }
1746
+ );
1747
+
1748
+ editable.set(
1749
+ `${readKeyID}_for_${inviteID}`,
1750
+ revelationForInvite,
1751
+ "trusting"
1752
+ );
1753
+ });
1754
+
1755
+ const teamAsInvite = team.testWithDifferentAccount(
1756
+ new AnonymousControlledAccount(inviteSecret),
1757
+ newRandomSessionID(inviteID)
1758
+ );
1759
+
1760
+ const invitedWriterSecret = newRandomAgentSecret();
1761
+ const invitedWriterID = getAgentID(invitedWriterSecret);
1762
+
1763
+ expectTeamContent(teamAsInvite.getCurrentContent()).edit((editable) => {
1764
+ editable.set(invitedWriterID, "writer", "trusting");
1765
+ expect(editable.get(invitedWriterID)).toBeUndefined();
1766
+ });
1767
+ });