@dxos/client-services 0.4.10-main.3aa8c1b → 0.4.10-main.3acb4a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-SETGCXWR.mjs → chunk-KZV2TSO3.mjs} +530 -414
- package/dist/lib/browser/chunk-KZV2TSO3.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -3
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +9 -4
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-CFWIMM3Q.cjs → chunk-PSSHMS2R.cjs} +537 -422
- package/dist/lib/node/chunk-PSSHMS2R.cjs.map +7 -0
- package/dist/lib/node/index.cjs +45 -43
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +14 -9
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/indexing/util.d.ts +2 -1
- package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/index.d.ts +1 -0
- package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +42 -0
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +2 -0
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +4 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +3 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +34 -34
- package/src/packlets/indexing/util.ts +15 -8
- package/src/packlets/invitations/index.ts +1 -0
- package/src/packlets/invitations/invitation-extension.ts +28 -1
- package/src/packlets/invitations/invitations-handler.ts +74 -34
- package/src/packlets/invitations/invitations-manager.ts +197 -0
- package/src/packlets/invitations/invitations-service.ts +21 -168
- package/src/packlets/services/automerge-host.test.ts +10 -4
- package/src/packlets/services/service-context.test.ts +4 -1
- package/src/packlets/services/service-context.ts +16 -3
- package/src/packlets/services/service-host.ts +25 -18
- package/src/packlets/spaces/data-space-manager.test.ts +4 -4
- package/src/packlets/spaces/data-space.ts +1 -1
- package/src/packlets/storage/level.ts +1 -1
- package/src/packlets/testing/test-builder.ts +20 -4
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-SETGCXWR.mjs.map +0 -7
- package/dist/lib/node/chunk-CFWIMM3Q.cjs.map +0 -7
|
@@ -1282,6 +1282,7 @@ import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Tri
|
|
|
1282
1282
|
import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT } from "@dxos/client-protocol";
|
|
1283
1283
|
import { Context as Context5 } from "@dxos/context";
|
|
1284
1284
|
import { generatePasscode } from "@dxos/credentials";
|
|
1285
|
+
import { createKeyPair, sign } from "@dxos/crypto";
|
|
1285
1286
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1286
1287
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1287
1288
|
import { log as log5 } from "@dxos/log";
|
|
@@ -1293,6 +1294,7 @@ import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protoco
|
|
|
1293
1294
|
// packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
|
|
1294
1295
|
import { Trigger as Trigger2 } from "@dxos/async";
|
|
1295
1296
|
import { cancelWithContext, Context as Context4 } from "@dxos/context";
|
|
1297
|
+
import { randomBytes, verify } from "@dxos/crypto";
|
|
1296
1298
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1297
1299
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1298
1300
|
import { log as log4 } from "@dxos/log";
|
|
@@ -1316,6 +1318,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1316
1318
|
this._callbacks = _callbacks;
|
|
1317
1319
|
this._ctx = new Context4();
|
|
1318
1320
|
this._remoteOptionsTrigger = new Trigger2();
|
|
1321
|
+
this._challenge = void 0;
|
|
1319
1322
|
this.invitation = void 0;
|
|
1320
1323
|
this.guestProfile = void 0;
|
|
1321
1324
|
this.authenticationPassed = false;
|
|
@@ -1330,7 +1333,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1330
1333
|
options: async (options) => {
|
|
1331
1334
|
invariant5(!this._remoteOptions, "Remote options already set.", {
|
|
1332
1335
|
F: __dxlog_file6,
|
|
1333
|
-
L:
|
|
1336
|
+
L: 90,
|
|
1334
1337
|
S: this,
|
|
1335
1338
|
A: [
|
|
1336
1339
|
"!this._remoteOptions",
|
|
@@ -1347,7 +1350,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1347
1350
|
id: traceId
|
|
1348
1351
|
}), {
|
|
1349
1352
|
F: __dxlog_file6,
|
|
1350
|
-
L:
|
|
1353
|
+
L: 99,
|
|
1351
1354
|
S: this,
|
|
1352
1355
|
C: (f, a) => f(...a)
|
|
1353
1356
|
});
|
|
@@ -1357,7 +1360,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1357
1360
|
invitationId
|
|
1358
1361
|
}, {
|
|
1359
1362
|
F: __dxlog_file6,
|
|
1360
|
-
L:
|
|
1363
|
+
L: 103,
|
|
1361
1364
|
S: this,
|
|
1362
1365
|
C: (f, a) => f(...a)
|
|
1363
1366
|
});
|
|
@@ -1371,7 +1374,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1371
1374
|
guestProfile: profile
|
|
1372
1375
|
}, {
|
|
1373
1376
|
F: __dxlog_file6,
|
|
1374
|
-
L:
|
|
1377
|
+
L: 112,
|
|
1375
1378
|
S: this,
|
|
1376
1379
|
C: (f, a) => f(...a)
|
|
1377
1380
|
});
|
|
@@ -1380,25 +1383,27 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1380
1383
|
...this.invitation,
|
|
1381
1384
|
state: Invitation2.State.READY_FOR_AUTHENTICATION
|
|
1382
1385
|
});
|
|
1386
|
+
this._challenge = this.invitation.authMethod === Invitation2.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
|
|
1383
1387
|
log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
|
|
1384
1388
|
id: traceId
|
|
1385
1389
|
}), {
|
|
1386
1390
|
F: __dxlog_file6,
|
|
1387
|
-
L:
|
|
1391
|
+
L: 122,
|
|
1388
1392
|
S: this,
|
|
1389
1393
|
C: (f, a) => f(...a)
|
|
1390
1394
|
});
|
|
1391
1395
|
return {
|
|
1392
|
-
authMethod: this.invitation.authMethod
|
|
1396
|
+
authMethod: this.invitation.authMethod,
|
|
1397
|
+
challenge: this._challenge
|
|
1393
1398
|
};
|
|
1394
1399
|
},
|
|
1395
|
-
authenticate: async ({ authCode: code }) => {
|
|
1400
|
+
authenticate: async ({ authCode: code, signedChallenge }) => {
|
|
1396
1401
|
const traceId = PublicKey5.random().toHex();
|
|
1397
1402
|
log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
|
|
1398
1403
|
id: traceId
|
|
1399
1404
|
}), {
|
|
1400
1405
|
F: __dxlog_file6,
|
|
1401
|
-
L:
|
|
1406
|
+
L: 131,
|
|
1402
1407
|
S: this,
|
|
1403
1408
|
C: (f, a) => f(...a)
|
|
1404
1409
|
});
|
|
@@ -1406,14 +1411,14 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1406
1411
|
authCode: code
|
|
1407
1412
|
}, {
|
|
1408
1413
|
F: __dxlog_file6,
|
|
1409
|
-
L:
|
|
1414
|
+
L: 132,
|
|
1410
1415
|
S: this,
|
|
1411
1416
|
C: (f, a) => f(...a)
|
|
1412
1417
|
});
|
|
1413
1418
|
let status = AuthenticationResponse.Status.OK;
|
|
1414
1419
|
invariant5(this.invitation, "Invitation is not set.", {
|
|
1415
1420
|
F: __dxlog_file6,
|
|
1416
|
-
L:
|
|
1421
|
+
L: 135,
|
|
1417
1422
|
S: this,
|
|
1418
1423
|
A: [
|
|
1419
1424
|
"this.invitation",
|
|
@@ -1424,7 +1429,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1424
1429
|
case Invitation2.AuthMethod.NONE: {
|
|
1425
1430
|
log4("authentication not required", void 0, {
|
|
1426
1431
|
F: __dxlog_file6,
|
|
1427
|
-
L:
|
|
1432
|
+
L: 138,
|
|
1428
1433
|
S: this,
|
|
1429
1434
|
C: (f, a) => f(...a)
|
|
1430
1435
|
});
|
|
@@ -1444,12 +1449,25 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1444
1449
|
}
|
|
1445
1450
|
break;
|
|
1446
1451
|
}
|
|
1452
|
+
case Invitation2.AuthMethod.KNOWN_PUBLIC_KEY: {
|
|
1453
|
+
if (!this.invitation.guestKeypair) {
|
|
1454
|
+
status = AuthenticationResponse.Status.INTERNAL_ERROR;
|
|
1455
|
+
break;
|
|
1456
|
+
}
|
|
1457
|
+
const isSignatureValid = this._challenge && verify(this._challenge, Buffer.from(signedChallenge ?? []), this.invitation.guestKeypair.publicKey.asBuffer());
|
|
1458
|
+
if (isSignatureValid) {
|
|
1459
|
+
this.authenticationPassed = true;
|
|
1460
|
+
} else {
|
|
1461
|
+
status = AuthenticationResponse.Status.INVALID_SIGNATURE;
|
|
1462
|
+
}
|
|
1463
|
+
break;
|
|
1464
|
+
}
|
|
1447
1465
|
default: {
|
|
1448
1466
|
log4.error("invalid authentication method", {
|
|
1449
1467
|
authMethod: this.invitation.authMethod
|
|
1450
1468
|
}, {
|
|
1451
1469
|
F: __dxlog_file6,
|
|
1452
|
-
L:
|
|
1470
|
+
L: 176,
|
|
1453
1471
|
S: this,
|
|
1454
1472
|
C: (f, a) => f(...a)
|
|
1455
1473
|
});
|
|
@@ -1464,7 +1482,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1464
1482
|
}
|
|
1465
1483
|
}), {
|
|
1466
1484
|
F: __dxlog_file6,
|
|
1467
|
-
L:
|
|
1485
|
+
L: 182,
|
|
1468
1486
|
S: this,
|
|
1469
1487
|
C: (f, a) => f(...a)
|
|
1470
1488
|
});
|
|
@@ -1478,14 +1496,14 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1478
1496
|
id: traceId
|
|
1479
1497
|
}), {
|
|
1480
1498
|
F: __dxlog_file6,
|
|
1481
|
-
L:
|
|
1499
|
+
L: 188,
|
|
1482
1500
|
S: this,
|
|
1483
1501
|
C: (f, a) => f(...a)
|
|
1484
1502
|
});
|
|
1485
1503
|
try {
|
|
1486
1504
|
invariant5(this.invitation, "Invitation is not set.", {
|
|
1487
1505
|
F: __dxlog_file6,
|
|
1488
|
-
L:
|
|
1506
|
+
L: 191,
|
|
1489
1507
|
S: this,
|
|
1490
1508
|
A: [
|
|
1491
1509
|
"this.invitation",
|
|
@@ -1500,7 +1518,7 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1500
1518
|
id: traceId
|
|
1501
1519
|
}), {
|
|
1502
1520
|
F: __dxlog_file6,
|
|
1503
|
-
L:
|
|
1521
|
+
L: 199,
|
|
1504
1522
|
S: this,
|
|
1505
1523
|
C: (f, a) => f(...a)
|
|
1506
1524
|
});
|
|
@@ -1557,7 +1575,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1557
1575
|
options: async (options) => {
|
|
1558
1576
|
invariant5(!this._remoteOptions, "Remote options already set.", {
|
|
1559
1577
|
F: __dxlog_file6,
|
|
1560
|
-
L:
|
|
1578
|
+
L: 266,
|
|
1561
1579
|
S: this,
|
|
1562
1580
|
A: [
|
|
1563
1581
|
"!this._remoteOptions",
|
|
@@ -1584,7 +1602,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1584
1602
|
try {
|
|
1585
1603
|
log4("begin options", void 0, {
|
|
1586
1604
|
F: __dxlog_file6,
|
|
1587
|
-
L:
|
|
1605
|
+
L: 287,
|
|
1588
1606
|
S: this,
|
|
1589
1607
|
C: (f, a) => f(...a)
|
|
1590
1608
|
});
|
|
@@ -1596,7 +1614,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1596
1614
|
}));
|
|
1597
1615
|
log4("end options", void 0, {
|
|
1598
1616
|
F: __dxlog_file6,
|
|
1599
|
-
L:
|
|
1617
|
+
L: 290,
|
|
1600
1618
|
S: this,
|
|
1601
1619
|
C: (f, a) => f(...a)
|
|
1602
1620
|
});
|
|
@@ -1610,7 +1628,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1610
1628
|
} catch (err) {
|
|
1611
1629
|
log4("openError", err, {
|
|
1612
1630
|
F: __dxlog_file6,
|
|
1613
|
-
L:
|
|
1631
|
+
L: 300,
|
|
1614
1632
|
S: this,
|
|
1615
1633
|
C: (f, a) => f(...a)
|
|
1616
1634
|
});
|
|
@@ -1620,7 +1638,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1620
1638
|
async onClose() {
|
|
1621
1639
|
log4("onClose", void 0, {
|
|
1622
1640
|
F: __dxlog_file6,
|
|
1623
|
-
L:
|
|
1641
|
+
L: 306,
|
|
1624
1642
|
S: this,
|
|
1625
1643
|
C: (f, a) => f(...a)
|
|
1626
1644
|
});
|
|
@@ -1639,11 +1657,11 @@ var InvitationsHandler = class {
|
|
|
1639
1657
|
this._networkManager = _networkManager;
|
|
1640
1658
|
}
|
|
1641
1659
|
createInvitation(protocol, options) {
|
|
1642
|
-
const { invitationId = PublicKey6.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey6.random(), persistent =
|
|
1660
|
+
const { invitationId = PublicKey6.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey6.random(), persistent = options?.authMethod !== Invitation3.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
|
|
1643
1661
|
const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
|
|
1644
1662
|
invariant6(protocol, void 0, {
|
|
1645
1663
|
F: __dxlog_file7,
|
|
1646
|
-
L:
|
|
1664
|
+
L: 87,
|
|
1647
1665
|
S: this,
|
|
1648
1666
|
A: [
|
|
1649
1667
|
"protocol",
|
|
@@ -1658,9 +1676,11 @@ var InvitationsHandler = class {
|
|
|
1658
1676
|
swarmKey,
|
|
1659
1677
|
authCode,
|
|
1660
1678
|
timeout,
|
|
1661
|
-
persistent,
|
|
1679
|
+
persistent: persistent && type !== Invitation3.Type.DELEGATED,
|
|
1680
|
+
guestKeypair: guestKeypair ?? (authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
|
|
1662
1681
|
created,
|
|
1663
1682
|
lifetime,
|
|
1683
|
+
multiUse,
|
|
1664
1684
|
...protocol.getInvitationContext()
|
|
1665
1685
|
};
|
|
1666
1686
|
const stream = new PushStream();
|
|
@@ -1675,7 +1695,7 @@ var InvitationsHandler = class {
|
|
|
1675
1695
|
...protocol.toJSON()
|
|
1676
1696
|
}, {
|
|
1677
1697
|
F: __dxlog_file7,
|
|
1678
|
-
L:
|
|
1698
|
+
L: 115,
|
|
1679
1699
|
S: this,
|
|
1680
1700
|
C: (f, a) => f(...a)
|
|
1681
1701
|
});
|
|
@@ -1700,7 +1720,7 @@ var InvitationsHandler = class {
|
|
|
1700
1720
|
const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
|
|
1701
1721
|
invariant6(deviceKey, void 0, {
|
|
1702
1722
|
F: __dxlog_file7,
|
|
1703
|
-
L:
|
|
1723
|
+
L: 136,
|
|
1704
1724
|
S: this,
|
|
1705
1725
|
A: [
|
|
1706
1726
|
"deviceKey",
|
|
@@ -1723,7 +1743,7 @@ var InvitationsHandler = class {
|
|
|
1723
1743
|
id: traceId
|
|
1724
1744
|
}), {
|
|
1725
1745
|
F: __dxlog_file7,
|
|
1726
|
-
L:
|
|
1746
|
+
L: 154,
|
|
1727
1747
|
S: this,
|
|
1728
1748
|
C: (f, a) => f(...a)
|
|
1729
1749
|
});
|
|
@@ -1731,7 +1751,7 @@ var InvitationsHandler = class {
|
|
|
1731
1751
|
...protocol.toJSON()
|
|
1732
1752
|
}, {
|
|
1733
1753
|
F: __dxlog_file7,
|
|
1734
|
-
L:
|
|
1754
|
+
L: 155,
|
|
1735
1755
|
S: this,
|
|
1736
1756
|
C: (f, a) => f(...a)
|
|
1737
1757
|
});
|
|
@@ -1747,7 +1767,7 @@ var InvitationsHandler = class {
|
|
|
1747
1767
|
...protocol.toJSON()
|
|
1748
1768
|
}, {
|
|
1749
1769
|
F: __dxlog_file7,
|
|
1750
|
-
L:
|
|
1770
|
+
L: 158,
|
|
1751
1771
|
S: this,
|
|
1752
1772
|
C: (f, a) => f(...a)
|
|
1753
1773
|
});
|
|
@@ -1759,7 +1779,7 @@ var InvitationsHandler = class {
|
|
|
1759
1779
|
id: traceId
|
|
1760
1780
|
}), {
|
|
1761
1781
|
F: __dxlog_file7,
|
|
1762
|
-
L:
|
|
1782
|
+
L: 160,
|
|
1763
1783
|
S: this,
|
|
1764
1784
|
C: (f, a) => f(...a)
|
|
1765
1785
|
});
|
|
@@ -1769,7 +1789,7 @@ var InvitationsHandler = class {
|
|
|
1769
1789
|
...protocol.toJSON()
|
|
1770
1790
|
}, {
|
|
1771
1791
|
F: __dxlog_file7,
|
|
1772
|
-
L:
|
|
1792
|
+
L: 163,
|
|
1773
1793
|
S: this,
|
|
1774
1794
|
C: (f, a) => f(...a)
|
|
1775
1795
|
});
|
|
@@ -1780,7 +1800,7 @@ var InvitationsHandler = class {
|
|
|
1780
1800
|
} else {
|
|
1781
1801
|
log5.error("failed", err, {
|
|
1782
1802
|
F: __dxlog_file7,
|
|
1783
|
-
L:
|
|
1803
|
+
L: 166,
|
|
1784
1804
|
S: this,
|
|
1785
1805
|
C: (f, a) => f(...a)
|
|
1786
1806
|
});
|
|
@@ -1791,12 +1811,12 @@ var InvitationsHandler = class {
|
|
|
1791
1811
|
error: err
|
|
1792
1812
|
}), {
|
|
1793
1813
|
F: __dxlog_file7,
|
|
1794
|
-
L:
|
|
1814
|
+
L: 169,
|
|
1795
1815
|
S: this,
|
|
1796
1816
|
C: (f, a) => f(...a)
|
|
1797
1817
|
});
|
|
1798
1818
|
} finally {
|
|
1799
|
-
if (
|
|
1819
|
+
if (!multiUse) {
|
|
1800
1820
|
await swarmConnection.close();
|
|
1801
1821
|
await ctx.dispose();
|
|
1802
1822
|
}
|
|
@@ -1812,7 +1832,7 @@ var InvitationsHandler = class {
|
|
|
1812
1832
|
...protocol.toJSON()
|
|
1813
1833
|
}, {
|
|
1814
1834
|
F: __dxlog_file7,
|
|
1815
|
-
L:
|
|
1835
|
+
L: 184,
|
|
1816
1836
|
S: this,
|
|
1817
1837
|
C: (f, a) => f(...a)
|
|
1818
1838
|
});
|
|
@@ -1823,7 +1843,7 @@ var InvitationsHandler = class {
|
|
|
1823
1843
|
} else {
|
|
1824
1844
|
log5.error("failed", err, {
|
|
1825
1845
|
F: __dxlog_file7,
|
|
1826
|
-
L:
|
|
1846
|
+
L: 187,
|
|
1827
1847
|
S: this,
|
|
1828
1848
|
C: (f, a) => f(...a)
|
|
1829
1849
|
});
|
|
@@ -1833,11 +1853,11 @@ var InvitationsHandler = class {
|
|
|
1833
1853
|
});
|
|
1834
1854
|
return extension;
|
|
1835
1855
|
};
|
|
1836
|
-
if (invitation.lifetime && invitation.created
|
|
1856
|
+
if (invitation.lifetime && invitation.created) {
|
|
1837
1857
|
if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
|
|
1838
1858
|
log5.warn("invitation has already expired", void 0, {
|
|
1839
1859
|
F: __dxlog_file7,
|
|
1840
|
-
L:
|
|
1860
|
+
L: 198,
|
|
1841
1861
|
S: this,
|
|
1842
1862
|
C: (f, a) => f(...a)
|
|
1843
1863
|
});
|
|
@@ -1888,7 +1908,7 @@ var InvitationsHandler = class {
|
|
|
1888
1908
|
const { timeout = INVITATION_TIMEOUT } = invitation;
|
|
1889
1909
|
invariant6(protocol, void 0, {
|
|
1890
1910
|
F: __dxlog_file7,
|
|
1891
|
-
L:
|
|
1911
|
+
L: 252,
|
|
1892
1912
|
S: this,
|
|
1893
1913
|
A: [
|
|
1894
1914
|
"protocol",
|
|
@@ -1898,7 +1918,7 @@ var InvitationsHandler = class {
|
|
|
1898
1918
|
if (deviceProfile) {
|
|
1899
1919
|
invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
1900
1920
|
F: __dxlog_file7,
|
|
1901
|
-
L:
|
|
1921
|
+
L: 255,
|
|
1902
1922
|
S: this,
|
|
1903
1923
|
A: [
|
|
1904
1924
|
"invitation.kind === Invitation.Kind.DEVICE",
|
|
@@ -1913,7 +1933,7 @@ var InvitationsHandler = class {
|
|
|
1913
1933
|
const setState = (newData) => {
|
|
1914
1934
|
invariant6(newData.state !== void 0, void 0, {
|
|
1915
1935
|
F: __dxlog_file7,
|
|
1916
|
-
L:
|
|
1936
|
+
L: 266,
|
|
1917
1937
|
S: this,
|
|
1918
1938
|
A: [
|
|
1919
1939
|
"newData.state !== undefined",
|
|
@@ -1933,7 +1953,7 @@ var InvitationsHandler = class {
|
|
|
1933
1953
|
...protocol.toJSON()
|
|
1934
1954
|
}, {
|
|
1935
1955
|
F: __dxlog_file7,
|
|
1936
|
-
L:
|
|
1956
|
+
L: 274,
|
|
1937
1957
|
S: this,
|
|
1938
1958
|
C: (f, a) => f(...a)
|
|
1939
1959
|
});
|
|
@@ -1943,7 +1963,7 @@ var InvitationsHandler = class {
|
|
|
1943
1963
|
} else {
|
|
1944
1964
|
log5.warn("auth failed", err, {
|
|
1945
1965
|
F: __dxlog_file7,
|
|
1946
|
-
L:
|
|
1966
|
+
L: 277,
|
|
1947
1967
|
S: this,
|
|
1948
1968
|
C: (f, a) => f(...a)
|
|
1949
1969
|
});
|
|
@@ -1957,7 +1977,7 @@ var InvitationsHandler = class {
|
|
|
1957
1977
|
...protocol.toJSON()
|
|
1958
1978
|
}, {
|
|
1959
1979
|
F: __dxlog_file7,
|
|
1960
|
-
L:
|
|
1980
|
+
L: 285,
|
|
1961
1981
|
S: this,
|
|
1962
1982
|
C: (f, a) => f(...a)
|
|
1963
1983
|
});
|
|
@@ -1972,7 +1992,7 @@ var InvitationsHandler = class {
|
|
|
1972
1992
|
currentState
|
|
1973
1993
|
}, {
|
|
1974
1994
|
F: __dxlog_file7,
|
|
1975
|
-
L:
|
|
1995
|
+
L: 295,
|
|
1976
1996
|
S: this,
|
|
1977
1997
|
C: (f, a) => f(...a)
|
|
1978
1998
|
});
|
|
@@ -1987,7 +2007,7 @@ var InvitationsHandler = class {
|
|
|
1987
2007
|
id: traceId
|
|
1988
2008
|
}), {
|
|
1989
2009
|
F: __dxlog_file7,
|
|
1990
|
-
L:
|
|
2010
|
+
L: 304,
|
|
1991
2011
|
S: this,
|
|
1992
2012
|
C: (f, a) => f(...a)
|
|
1993
2013
|
});
|
|
@@ -1999,7 +2019,7 @@ var InvitationsHandler = class {
|
|
|
1999
2019
|
...protocol.toJSON()
|
|
2000
2020
|
}, {
|
|
2001
2021
|
F: __dxlog_file7,
|
|
2002
|
-
L:
|
|
2022
|
+
L: 312,
|
|
2003
2023
|
S: this,
|
|
2004
2024
|
C: (f, a) => f(...a)
|
|
2005
2025
|
});
|
|
@@ -2010,7 +2030,7 @@ var InvitationsHandler = class {
|
|
|
2010
2030
|
...protocol.toJSON()
|
|
2011
2031
|
}, {
|
|
2012
2032
|
F: __dxlog_file7,
|
|
2013
|
-
L:
|
|
2033
|
+
L: 316,
|
|
2014
2034
|
S: this,
|
|
2015
2035
|
C: (f, a) => f(...a)
|
|
2016
2036
|
});
|
|
@@ -2020,62 +2040,28 @@ var InvitationsHandler = class {
|
|
|
2020
2040
|
response: introductionResponse
|
|
2021
2041
|
}, {
|
|
2022
2042
|
F: __dxlog_file7,
|
|
2023
|
-
L:
|
|
2043
|
+
L: 320,
|
|
2024
2044
|
S: this,
|
|
2025
2045
|
C: (f, a) => f(...a)
|
|
2026
2046
|
});
|
|
2027
2047
|
invitation.authMethod = introductionResponse.authMethod;
|
|
2028
2048
|
if (isAuthenticationRequired(invitation)) {
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
state: Invitation3.State.READY_FOR_AUTHENTICATION
|
|
2038
|
-
});
|
|
2039
|
-
const authCode = await authenticated.wait({
|
|
2040
|
-
timeout
|
|
2041
|
-
});
|
|
2042
|
-
log5("sending authentication request", void 0, {
|
|
2043
|
-
F: __dxlog_file7,
|
|
2044
|
-
L: 325,
|
|
2045
|
-
S: this,
|
|
2046
|
-
C: (f, a) => f(...a)
|
|
2047
|
-
});
|
|
2048
|
-
setState({
|
|
2049
|
-
state: Invitation3.State.AUTHENTICATING
|
|
2050
|
-
});
|
|
2051
|
-
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
2052
|
-
authCode
|
|
2053
|
-
});
|
|
2054
|
-
if (response.status === void 0 || response.status === AuthenticationResponse2.Status.OK) {
|
|
2049
|
+
switch (invitation.authMethod) {
|
|
2050
|
+
case Invitation3.AuthMethod.SHARED_SECRET:
|
|
2051
|
+
await this._handleGuestOtpAuth(extension, setState, authenticated, {
|
|
2052
|
+
timeout
|
|
2053
|
+
});
|
|
2054
|
+
break;
|
|
2055
|
+
case Invitation3.AuthMethod.KNOWN_PUBLIC_KEY:
|
|
2056
|
+
await this._handleGuestKpkAuth(extension, setState, invitation, introductionResponse);
|
|
2055
2057
|
break;
|
|
2056
|
-
}
|
|
2057
|
-
if (response.status === AuthenticationResponse2.Status.INVALID_OTP) {
|
|
2058
|
-
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
2059
|
-
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
2060
|
-
} else {
|
|
2061
|
-
log5("retrying invalid code", {
|
|
2062
|
-
attempt
|
|
2063
|
-
}, {
|
|
2064
|
-
F: __dxlog_file7,
|
|
2065
|
-
L: 336,
|
|
2066
|
-
S: this,
|
|
2067
|
-
C: (f, a) => f(...a)
|
|
2068
|
-
});
|
|
2069
|
-
authenticated.reset();
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
2058
|
}
|
|
2073
2059
|
}
|
|
2074
2060
|
log5("request admission", {
|
|
2075
2061
|
...protocol.toJSON()
|
|
2076
2062
|
}, {
|
|
2077
2063
|
F: __dxlog_file7,
|
|
2078
|
-
L:
|
|
2064
|
+
L: 336,
|
|
2079
2065
|
S: this,
|
|
2080
2066
|
C: (f, a) => f(...a)
|
|
2081
2067
|
});
|
|
@@ -2087,7 +2073,7 @@ var InvitationsHandler = class {
|
|
|
2087
2073
|
...protocol.toJSON()
|
|
2088
2074
|
}, {
|
|
2089
2075
|
F: __dxlog_file7,
|
|
2090
|
-
L:
|
|
2076
|
+
L: 347,
|
|
2091
2077
|
S: this,
|
|
2092
2078
|
C: (f, a) => f(...a)
|
|
2093
2079
|
});
|
|
@@ -2100,7 +2086,7 @@ var InvitationsHandler = class {
|
|
|
2100
2086
|
id: traceId
|
|
2101
2087
|
}), {
|
|
2102
2088
|
F: __dxlog_file7,
|
|
2103
|
-
L:
|
|
2089
|
+
L: 349,
|
|
2104
2090
|
S: this,
|
|
2105
2091
|
C: (f, a) => f(...a)
|
|
2106
2092
|
});
|
|
@@ -2110,7 +2096,7 @@ var InvitationsHandler = class {
|
|
|
2110
2096
|
...protocol.toJSON()
|
|
2111
2097
|
}, {
|
|
2112
2098
|
F: __dxlog_file7,
|
|
2113
|
-
L:
|
|
2099
|
+
L: 352,
|
|
2114
2100
|
S: this,
|
|
2115
2101
|
C: (f, a) => f(...a)
|
|
2116
2102
|
});
|
|
@@ -2120,7 +2106,7 @@ var InvitationsHandler = class {
|
|
|
2120
2106
|
} else {
|
|
2121
2107
|
log5("auth failed", err, {
|
|
2122
2108
|
F: __dxlog_file7,
|
|
2123
|
-
L:
|
|
2109
|
+
L: 355,
|
|
2124
2110
|
S: this,
|
|
2125
2111
|
C: (f, a) => f(...a)
|
|
2126
2112
|
});
|
|
@@ -2131,7 +2117,7 @@ var InvitationsHandler = class {
|
|
|
2131
2117
|
error: err
|
|
2132
2118
|
}), {
|
|
2133
2119
|
F: __dxlog_file7,
|
|
2134
|
-
L:
|
|
2120
|
+
L: 358,
|
|
2135
2121
|
S: this,
|
|
2136
2122
|
C: (f, a) => f(...a)
|
|
2137
2123
|
});
|
|
@@ -2149,7 +2135,7 @@ var InvitationsHandler = class {
|
|
|
2149
2135
|
...protocol.toJSON()
|
|
2150
2136
|
}, {
|
|
2151
2137
|
F: __dxlog_file7,
|
|
2152
|
-
L:
|
|
2138
|
+
L: 369,
|
|
2153
2139
|
S: this,
|
|
2154
2140
|
C: (f, a) => f(...a)
|
|
2155
2141
|
});
|
|
@@ -2159,7 +2145,7 @@ var InvitationsHandler = class {
|
|
|
2159
2145
|
} else {
|
|
2160
2146
|
log5("auth failed", err, {
|
|
2161
2147
|
F: __dxlog_file7,
|
|
2162
|
-
L:
|
|
2148
|
+
L: 372,
|
|
2163
2149
|
S: this,
|
|
2164
2150
|
C: (f, a) => f(...a)
|
|
2165
2151
|
});
|
|
@@ -2176,7 +2162,7 @@ var InvitationsHandler = class {
|
|
|
2176
2162
|
} else {
|
|
2177
2163
|
invariant6(invitation.swarmKey, void 0, {
|
|
2178
2164
|
F: __dxlog_file7,
|
|
2179
|
-
L:
|
|
2165
|
+
L: 386,
|
|
2180
2166
|
S: this,
|
|
2181
2167
|
A: [
|
|
2182
2168
|
"invitation.swarmKey",
|
|
@@ -2214,206 +2200,115 @@ var InvitationsHandler = class {
|
|
|
2214
2200
|
});
|
|
2215
2201
|
return observable;
|
|
2216
2202
|
}
|
|
2203
|
+
async _handleGuestOtpAuth(extension, setState, authenticated, options) {
|
|
2204
|
+
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
2205
|
+
log5("guest waiting for authentication code...", void 0, {
|
|
2206
|
+
F: __dxlog_file7,
|
|
2207
|
+
L: 426,
|
|
2208
|
+
S: this,
|
|
2209
|
+
C: (f, a) => f(...a)
|
|
2210
|
+
});
|
|
2211
|
+
setState({
|
|
2212
|
+
state: Invitation3.State.READY_FOR_AUTHENTICATION
|
|
2213
|
+
});
|
|
2214
|
+
const authCode = await authenticated.wait(options);
|
|
2215
|
+
log5("sending authentication request", void 0, {
|
|
2216
|
+
F: __dxlog_file7,
|
|
2217
|
+
L: 430,
|
|
2218
|
+
S: this,
|
|
2219
|
+
C: (f, a) => f(...a)
|
|
2220
|
+
});
|
|
2221
|
+
setState({
|
|
2222
|
+
state: Invitation3.State.AUTHENTICATING
|
|
2223
|
+
});
|
|
2224
|
+
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
2225
|
+
authCode
|
|
2226
|
+
});
|
|
2227
|
+
if (response.status === void 0 || response.status === AuthenticationResponse2.Status.OK) {
|
|
2228
|
+
break;
|
|
2229
|
+
}
|
|
2230
|
+
if (response.status === AuthenticationResponse2.Status.INVALID_OTP) {
|
|
2231
|
+
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
2232
|
+
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
2233
|
+
} else {
|
|
2234
|
+
log5("retrying invalid code", {
|
|
2235
|
+
attempt
|
|
2236
|
+
}, {
|
|
2237
|
+
F: __dxlog_file7,
|
|
2238
|
+
L: 441,
|
|
2239
|
+
S: this,
|
|
2240
|
+
C: (f, a) => f(...a)
|
|
2241
|
+
});
|
|
2242
|
+
authenticated.reset();
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
async _handleGuestKpkAuth(extension, setState, invitation, introductionResponse) {
|
|
2248
|
+
if (invitation.guestKeypair?.privateKey == null) {
|
|
2249
|
+
throw new Error("keypair missing in the invitation");
|
|
2250
|
+
}
|
|
2251
|
+
if (introductionResponse.challenge == null) {
|
|
2252
|
+
throw new Error("challenge missing in the introduction");
|
|
2253
|
+
}
|
|
2254
|
+
log5("sending authentication request", void 0, {
|
|
2255
|
+
F: __dxlog_file7,
|
|
2256
|
+
L: 460,
|
|
2257
|
+
S: this,
|
|
2258
|
+
C: (f, a) => f(...a)
|
|
2259
|
+
});
|
|
2260
|
+
setState({
|
|
2261
|
+
state: Invitation3.State.AUTHENTICATING
|
|
2262
|
+
});
|
|
2263
|
+
const signature = sign(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
|
|
2264
|
+
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
2265
|
+
signedChallenge: signature
|
|
2266
|
+
});
|
|
2267
|
+
if (response.status !== AuthenticationResponse2.Status.OK) {
|
|
2268
|
+
throw new Error(`Authentication failed with code: ${response.status}`);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2217
2271
|
};
|
|
2218
|
-
var
|
|
2219
|
-
|
|
2272
|
+
var createAdmissionKeypair = () => {
|
|
2273
|
+
const keypair = createKeyPair();
|
|
2274
|
+
return {
|
|
2275
|
+
publicKey: PublicKey6.from(keypair.publicKey),
|
|
2276
|
+
privateKey: keypair.secretKey
|
|
2277
|
+
};
|
|
2220
2278
|
};
|
|
2221
2279
|
|
|
2222
2280
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
2223
|
-
import { Event as Event3, scheduleTask as scheduleTask3 } from "@dxos/async";
|
|
2224
2281
|
import { Stream as Stream8 } from "@dxos/codec-protobuf";
|
|
2225
|
-
import {
|
|
2226
|
-
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2227
|
-
import { log as log6 } from "@dxos/log";
|
|
2228
|
-
import { Invitation as Invitation4, QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
|
|
2229
|
-
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
|
|
2282
|
+
import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
|
|
2230
2283
|
var InvitationsServiceImpl = class {
|
|
2231
|
-
constructor(
|
|
2232
|
-
this.
|
|
2233
|
-
this._getHandler = _getHandler;
|
|
2234
|
-
this._metadataStore = _metadataStore;
|
|
2235
|
-
this._createInvitations = /* @__PURE__ */ new Map();
|
|
2236
|
-
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
2237
|
-
this._invitationCreated = new Event3();
|
|
2238
|
-
this._invitationAccepted = new Event3();
|
|
2239
|
-
this._removedCreated = new Event3();
|
|
2240
|
-
this._removedAccepted = new Event3();
|
|
2241
|
-
this._saved = new Event3();
|
|
2242
|
-
this._persistentInvitationsLoadedEvent = new Event3();
|
|
2243
|
-
this._persistentInvitationsLoaded = false;
|
|
2284
|
+
constructor(_invitationsManager) {
|
|
2285
|
+
this._invitationsManager = _invitationsManager;
|
|
2244
2286
|
}
|
|
2245
2287
|
// TODO(burdon): Guest/host label.
|
|
2246
2288
|
getLoggingContext() {
|
|
2247
2289
|
return {};
|
|
2248
2290
|
}
|
|
2249
2291
|
createInvitation(options) {
|
|
2250
|
-
|
|
2251
|
-
const savePersistentInvitationCtx = new Context6();
|
|
2252
|
-
const existingInvitation = this._createInvitations.get(options.invitationId);
|
|
2253
|
-
if (existingInvitation) {
|
|
2254
|
-
invitation = existingInvitation;
|
|
2255
|
-
} else {
|
|
2256
|
-
const handler = this._getHandler(options);
|
|
2257
|
-
invitation = this._invitationsHandler.createInvitation(handler, options);
|
|
2258
|
-
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
2259
|
-
this._invitationCreated.emit(invitation.get());
|
|
2260
|
-
}
|
|
2292
|
+
const invitation = this._invitationsManager.createInvitation(options);
|
|
2261
2293
|
return new Stream8(({ next, close }) => {
|
|
2262
|
-
|
|
2263
|
-
scheduleTask3(savePersistentInvitationCtx, async () => {
|
|
2264
|
-
try {
|
|
2265
|
-
await this._metadataStore.addInvitation(invitation.get());
|
|
2266
|
-
this._saved.emit(invitation.get());
|
|
2267
|
-
} catch (err) {
|
|
2268
|
-
close(err);
|
|
2269
|
-
}
|
|
2270
|
-
});
|
|
2271
|
-
}
|
|
2272
|
-
invitation.subscribe((invitation2) => {
|
|
2273
|
-
next(invitation2);
|
|
2274
|
-
}, async (err) => {
|
|
2275
|
-
await savePersistentInvitationCtx.dispose();
|
|
2276
|
-
close(err);
|
|
2277
|
-
}, async () => {
|
|
2278
|
-
close();
|
|
2279
|
-
if (invitation.get().persistent) {
|
|
2280
|
-
await savePersistentInvitationCtx.dispose();
|
|
2281
|
-
await this._metadataStore.removeInvitation(invitation.get().invitationId);
|
|
2282
|
-
}
|
|
2283
|
-
this._createInvitations.delete(invitation.get().invitationId);
|
|
2284
|
-
if (invitation.get().type !== Invitation4.Type.MULTIUSE) {
|
|
2285
|
-
this._removedCreated.emit(invitation.get());
|
|
2286
|
-
}
|
|
2287
|
-
});
|
|
2294
|
+
invitation.subscribe(next, close, close);
|
|
2288
2295
|
});
|
|
2289
2296
|
}
|
|
2290
|
-
|
|
2291
|
-
const
|
|
2292
|
-
const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
|
|
2293
|
-
const cInvitations = freshInvitations.map((persistentInvitation) => {
|
|
2294
|
-
invariant7(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
2295
|
-
F: __dxlog_file8,
|
|
2296
|
-
L: 109,
|
|
2297
|
-
S: this,
|
|
2298
|
-
A: [
|
|
2299
|
-
"!this._createInvitations.get(persistentInvitation.invitationId)",
|
|
2300
|
-
"'invitation already exists'"
|
|
2301
|
-
]
|
|
2302
|
-
});
|
|
2303
|
-
const handler = this._getHandler(persistentInvitation);
|
|
2304
|
-
const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
|
|
2305
|
-
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
2306
|
-
this._invitationCreated.emit(invitation.get());
|
|
2307
|
-
return persistentInvitation;
|
|
2308
|
-
});
|
|
2309
|
-
this._persistentInvitationsLoadedEvent.emit();
|
|
2310
|
-
this._persistentInvitationsLoaded = true;
|
|
2311
|
-
return {
|
|
2312
|
-
invitations: cInvitations
|
|
2313
|
-
};
|
|
2314
|
-
}
|
|
2315
|
-
acceptInvitation({ invitation: options, deviceProfile }) {
|
|
2316
|
-
let invitation;
|
|
2317
|
-
if (deviceProfile) {
|
|
2318
|
-
invariant7(options.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
2319
|
-
F: __dxlog_file8,
|
|
2320
|
-
L: 127,
|
|
2321
|
-
S: this,
|
|
2322
|
-
A: [
|
|
2323
|
-
"options.kind === Invitation.Kind.DEVICE",
|
|
2324
|
-
"'deviceProfile provided for non-device invitation'"
|
|
2325
|
-
]
|
|
2326
|
-
});
|
|
2327
|
-
}
|
|
2328
|
-
const existingInvitation = this._acceptInvitations.get(options.invitationId);
|
|
2329
|
-
if (existingInvitation) {
|
|
2330
|
-
invitation = existingInvitation;
|
|
2331
|
-
} else {
|
|
2332
|
-
const handler = this._getHandler(options);
|
|
2333
|
-
invitation = this._invitationsHandler.acceptInvitation(handler, options, deviceProfile);
|
|
2334
|
-
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
2335
|
-
this._invitationAccepted.emit(invitation.get());
|
|
2336
|
-
}
|
|
2297
|
+
acceptInvitation(request) {
|
|
2298
|
+
const invitation = this._invitationsManager.acceptInvitation(request);
|
|
2337
2299
|
return new Stream8(({ next, close }) => {
|
|
2338
|
-
invitation.subscribe(
|
|
2339
|
-
next(invitation2);
|
|
2340
|
-
}, (err) => {
|
|
2341
|
-
close(err);
|
|
2342
|
-
}, () => {
|
|
2343
|
-
close();
|
|
2344
|
-
this._acceptInvitations.delete(invitation.get().invitationId);
|
|
2345
|
-
if (invitation.get().type !== Invitation4.Type.MULTIUSE) {
|
|
2346
|
-
this._removedAccepted.emit(invitation.get());
|
|
2347
|
-
}
|
|
2348
|
-
});
|
|
2300
|
+
invitation.subscribe(next, close, close);
|
|
2349
2301
|
});
|
|
2350
2302
|
}
|
|
2351
|
-
async authenticate(
|
|
2352
|
-
|
|
2353
|
-
F: __dxlog_file8,
|
|
2354
|
-
L: 160,
|
|
2355
|
-
S: this,
|
|
2356
|
-
C: (f, a) => f(...a)
|
|
2357
|
-
});
|
|
2358
|
-
invariant7(invitationId, void 0, {
|
|
2359
|
-
F: __dxlog_file8,
|
|
2360
|
-
L: 161,
|
|
2361
|
-
S: this,
|
|
2362
|
-
A: [
|
|
2363
|
-
"invitationId",
|
|
2364
|
-
""
|
|
2365
|
-
]
|
|
2366
|
-
});
|
|
2367
|
-
const observable = this._acceptInvitations.get(invitationId);
|
|
2368
|
-
if (!observable) {
|
|
2369
|
-
log6.warn("invalid invitation", {
|
|
2370
|
-
invitationId
|
|
2371
|
-
}, {
|
|
2372
|
-
F: __dxlog_file8,
|
|
2373
|
-
L: 164,
|
|
2374
|
-
S: this,
|
|
2375
|
-
C: (f, a) => f(...a)
|
|
2376
|
-
});
|
|
2377
|
-
} else {
|
|
2378
|
-
await observable.authenticate(authCode);
|
|
2379
|
-
}
|
|
2303
|
+
async authenticate(request) {
|
|
2304
|
+
return this._invitationsManager.authenticate(request);
|
|
2380
2305
|
}
|
|
2381
|
-
async cancelInvitation(
|
|
2382
|
-
|
|
2383
|
-
invitationId
|
|
2384
|
-
}, {
|
|
2385
|
-
F: __dxlog_file8,
|
|
2386
|
-
L: 171,
|
|
2387
|
-
S: this,
|
|
2388
|
-
C: (f, a) => f(...a)
|
|
2389
|
-
});
|
|
2390
|
-
invariant7(invitationId, void 0, {
|
|
2391
|
-
F: __dxlog_file8,
|
|
2392
|
-
L: 172,
|
|
2393
|
-
S: this,
|
|
2394
|
-
A: [
|
|
2395
|
-
"invitationId",
|
|
2396
|
-
""
|
|
2397
|
-
]
|
|
2398
|
-
});
|
|
2399
|
-
const created = this._createInvitations.get(invitationId);
|
|
2400
|
-
const accepted = this._acceptInvitations.get(invitationId);
|
|
2401
|
-
if (created) {
|
|
2402
|
-
await created.cancel();
|
|
2403
|
-
this._createInvitations.delete(invitationId);
|
|
2404
|
-
this._removedCreated.emit(created.get());
|
|
2405
|
-
if (created.get().persistent) {
|
|
2406
|
-
await this._metadataStore.removeInvitation(created.get().invitationId);
|
|
2407
|
-
}
|
|
2408
|
-
} else if (accepted) {
|
|
2409
|
-
await accepted.cancel();
|
|
2410
|
-
this._acceptInvitations.delete(invitationId);
|
|
2411
|
-
this._removedAccepted.emit(accepted.get());
|
|
2412
|
-
}
|
|
2306
|
+
async cancelInvitation(request) {
|
|
2307
|
+
return this._invitationsManager.cancelInvitation(request);
|
|
2413
2308
|
}
|
|
2414
2309
|
queryInvitations() {
|
|
2415
2310
|
return new Stream8(({ next, ctx }) => {
|
|
2416
|
-
this.
|
|
2311
|
+
this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
|
|
2417
2312
|
next({
|
|
2418
2313
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2419
2314
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
@@ -2422,7 +2317,7 @@ var InvitationsServiceImpl = class {
|
|
|
2422
2317
|
]
|
|
2423
2318
|
});
|
|
2424
2319
|
});
|
|
2425
|
-
this.
|
|
2320
|
+
this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
|
|
2426
2321
|
next({
|
|
2427
2322
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2428
2323
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
@@ -2431,7 +2326,7 @@ var InvitationsServiceImpl = class {
|
|
|
2431
2326
|
]
|
|
2432
2327
|
});
|
|
2433
2328
|
});
|
|
2434
|
-
this.
|
|
2329
|
+
this._invitationsManager.removedCreated.on(ctx, (invitation) => {
|
|
2435
2330
|
next({
|
|
2436
2331
|
action: QueryInvitationsResponse.Action.REMOVED,
|
|
2437
2332
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
@@ -2440,7 +2335,7 @@ var InvitationsServiceImpl = class {
|
|
|
2440
2335
|
]
|
|
2441
2336
|
});
|
|
2442
2337
|
});
|
|
2443
|
-
this.
|
|
2338
|
+
this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
|
|
2444
2339
|
next({
|
|
2445
2340
|
action: QueryInvitationsResponse.Action.REMOVED,
|
|
2446
2341
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
@@ -2449,7 +2344,7 @@ var InvitationsServiceImpl = class {
|
|
|
2449
2344
|
]
|
|
2450
2345
|
});
|
|
2451
2346
|
});
|
|
2452
|
-
this.
|
|
2347
|
+
this._invitationsManager.saved.on(ctx, (invitation) => {
|
|
2453
2348
|
next({
|
|
2454
2349
|
action: QueryInvitationsResponse.Action.SAVED,
|
|
2455
2350
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
@@ -2461,28 +2356,21 @@ var InvitationsServiceImpl = class {
|
|
|
2461
2356
|
next({
|
|
2462
2357
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2463
2358
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
2464
|
-
invitations:
|
|
2359
|
+
invitations: this._invitationsManager.getCreatedInvitations(),
|
|
2465
2360
|
existing: true
|
|
2466
2361
|
});
|
|
2467
2362
|
next({
|
|
2468
2363
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
2469
2364
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
2470
|
-
invitations:
|
|
2365
|
+
invitations: this._invitationsManager.getAcceptedInvitations(),
|
|
2471
2366
|
existing: true
|
|
2472
2367
|
});
|
|
2473
|
-
|
|
2368
|
+
this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
|
|
2474
2369
|
next({
|
|
2475
2370
|
action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
|
|
2476
2371
|
type: QueryInvitationsResponse.Type.CREATED
|
|
2477
2372
|
});
|
|
2478
|
-
}
|
|
2479
|
-
this._persistentInvitationsLoadedEvent.on(ctx, () => {
|
|
2480
|
-
next({
|
|
2481
|
-
action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
|
|
2482
|
-
type: QueryInvitationsResponse.Type.CREATED
|
|
2483
|
-
});
|
|
2484
|
-
});
|
|
2485
|
-
}
|
|
2373
|
+
});
|
|
2486
2374
|
});
|
|
2487
2375
|
}
|
|
2488
2376
|
};
|
|
@@ -2490,11 +2378,11 @@ var InvitationsServiceImpl = class {
|
|
|
2490
2378
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
2491
2379
|
import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
|
|
2492
2380
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
2493
|
-
import { invariant as
|
|
2494
|
-
import { log as
|
|
2381
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2382
|
+
import { log as log6 } from "@dxos/log";
|
|
2495
2383
|
import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
|
|
2496
|
-
import { Invitation as
|
|
2497
|
-
var
|
|
2384
|
+
import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2385
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
2498
2386
|
var SpaceInvitationProtocol = class {
|
|
2499
2387
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2500
2388
|
this._spaceManager = _spaceManager;
|
|
@@ -2510,13 +2398,13 @@ var SpaceInvitationProtocol = class {
|
|
|
2510
2398
|
}
|
|
2511
2399
|
getInvitationContext() {
|
|
2512
2400
|
return {
|
|
2513
|
-
kind:
|
|
2401
|
+
kind: Invitation4.Kind.SPACE,
|
|
2514
2402
|
spaceKey: this._spaceKey
|
|
2515
2403
|
};
|
|
2516
2404
|
}
|
|
2517
2405
|
async admit(request, guestProfile) {
|
|
2518
|
-
|
|
2519
|
-
F:
|
|
2406
|
+
invariant7(this._spaceKey, void 0, {
|
|
2407
|
+
F: __dxlog_file8,
|
|
2520
2408
|
L: 47,
|
|
2521
2409
|
S: this,
|
|
2522
2410
|
A: [
|
|
@@ -2525,8 +2413,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2525
2413
|
]
|
|
2526
2414
|
});
|
|
2527
2415
|
const space = await this._spaceManager.spaces.get(this._spaceKey);
|
|
2528
|
-
|
|
2529
|
-
F:
|
|
2416
|
+
invariant7(space, void 0, {
|
|
2417
|
+
F: __dxlog_file8,
|
|
2530
2418
|
L: 49,
|
|
2531
2419
|
S: this,
|
|
2532
2420
|
A: [
|
|
@@ -2534,8 +2422,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2534
2422
|
""
|
|
2535
2423
|
]
|
|
2536
2424
|
});
|
|
2537
|
-
|
|
2538
|
-
F:
|
|
2425
|
+
invariant7(request.space, void 0, {
|
|
2426
|
+
F: __dxlog_file8,
|
|
2539
2427
|
L: 51,
|
|
2540
2428
|
S: this,
|
|
2541
2429
|
A: [
|
|
@@ -2544,18 +2432,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2544
2432
|
]
|
|
2545
2433
|
});
|
|
2546
2434
|
const { identityKey, deviceKey } = request.space;
|
|
2547
|
-
|
|
2435
|
+
log6("writing guest credentials", {
|
|
2548
2436
|
host: this._signingContext.deviceKey,
|
|
2549
2437
|
guest: deviceKey
|
|
2550
2438
|
}, {
|
|
2551
|
-
F:
|
|
2439
|
+
F: __dxlog_file8,
|
|
2552
2440
|
L: 54,
|
|
2553
2441
|
S: this,
|
|
2554
2442
|
C: (f, a) => f(...a)
|
|
2555
2443
|
});
|
|
2556
2444
|
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
|
|
2557
|
-
|
|
2558
|
-
F:
|
|
2445
|
+
invariant7(credentials[0].credential, void 0, {
|
|
2446
|
+
F: __dxlog_file8,
|
|
2559
2447
|
L: 65,
|
|
2560
2448
|
S: this,
|
|
2561
2449
|
A: [
|
|
@@ -2564,8 +2452,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2564
2452
|
]
|
|
2565
2453
|
});
|
|
2566
2454
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2567
|
-
|
|
2568
|
-
F:
|
|
2455
|
+
invariant7(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2456
|
+
F: __dxlog_file8,
|
|
2569
2457
|
L: 67,
|
|
2570
2458
|
S: this,
|
|
2571
2459
|
A: [
|
|
@@ -2604,8 +2492,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2604
2492
|
};
|
|
2605
2493
|
}
|
|
2606
2494
|
async accept(response) {
|
|
2607
|
-
|
|
2608
|
-
F:
|
|
2495
|
+
invariant7(response.space, void 0, {
|
|
2496
|
+
F: __dxlog_file8,
|
|
2609
2497
|
L: 107,
|
|
2610
2498
|
S: this,
|
|
2611
2499
|
A: [
|
|
@@ -2615,8 +2503,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2615
2503
|
});
|
|
2616
2504
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
2617
2505
|
const assertion = getCredentialAssertion(credential);
|
|
2618
|
-
|
|
2619
|
-
F:
|
|
2506
|
+
invariant7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
2507
|
+
F: __dxlog_file8,
|
|
2620
2508
|
L: 110,
|
|
2621
2509
|
S: this,
|
|
2622
2510
|
A: [
|
|
@@ -2624,8 +2512,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2624
2512
|
"'Invalid credential'"
|
|
2625
2513
|
]
|
|
2626
2514
|
});
|
|
2627
|
-
|
|
2628
|
-
F:
|
|
2515
|
+
invariant7(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
2516
|
+
F: __dxlog_file8,
|
|
2629
2517
|
L: 111,
|
|
2630
2518
|
S: this,
|
|
2631
2519
|
A: [
|
|
@@ -2649,6 +2537,227 @@ var SpaceInvitationProtocol = class {
|
|
|
2649
2537
|
}
|
|
2650
2538
|
};
|
|
2651
2539
|
|
|
2540
|
+
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
2541
|
+
import { Event as Event3 } from "@dxos/async";
|
|
2542
|
+
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
2543
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2544
|
+
import { log as log7 } from "@dxos/log";
|
|
2545
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
2546
|
+
var InvitationsManager = class {
|
|
2547
|
+
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
2548
|
+
this._invitationsHandler = _invitationsHandler;
|
|
2549
|
+
this._getHandler = _getHandler;
|
|
2550
|
+
this._metadataStore = _metadataStore;
|
|
2551
|
+
this._createInvitations = /* @__PURE__ */ new Map();
|
|
2552
|
+
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
2553
|
+
this.invitationCreated = new Event3();
|
|
2554
|
+
this.invitationAccepted = new Event3();
|
|
2555
|
+
this.removedCreated = new Event3();
|
|
2556
|
+
this.removedAccepted = new Event3();
|
|
2557
|
+
this.saved = new Event3();
|
|
2558
|
+
this._persistentInvitationsLoadedEvent = new Event3();
|
|
2559
|
+
this._persistentInvitationsLoaded = false;
|
|
2560
|
+
}
|
|
2561
|
+
createInvitation(options) {
|
|
2562
|
+
const existingInvitation = this._createInvitations.get(options.invitationId);
|
|
2563
|
+
if (existingInvitation) {
|
|
2564
|
+
return existingInvitation;
|
|
2565
|
+
}
|
|
2566
|
+
const handler = this._getHandler(options);
|
|
2567
|
+
const invitation = this._invitationsHandler.createInvitation(handler, options);
|
|
2568
|
+
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
2569
|
+
this.invitationCreated.emit(invitation.get());
|
|
2570
|
+
const saveInvitationTask = invitation.get().persistent ? this._safePersistInBackground(invitation) : Promise.resolve();
|
|
2571
|
+
this._onInvitationComplete(invitation, async () => {
|
|
2572
|
+
this._createInvitations.delete(invitation.get().invitationId);
|
|
2573
|
+
this.removedCreated.emit(invitation.get());
|
|
2574
|
+
if (invitation.get().persistent) {
|
|
2575
|
+
await saveInvitationTask;
|
|
2576
|
+
await this._safeDeleteInvitation(invitation.get());
|
|
2577
|
+
}
|
|
2578
|
+
});
|
|
2579
|
+
return invitation;
|
|
2580
|
+
}
|
|
2581
|
+
async loadPersistentInvitations() {
|
|
2582
|
+
if (this._persistentInvitationsLoaded) {
|
|
2583
|
+
const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
|
|
2584
|
+
return {
|
|
2585
|
+
invitations
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
try {
|
|
2589
|
+
const persistentInvitations = this._metadataStore.getInvitations();
|
|
2590
|
+
const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
|
|
2591
|
+
const cInvitations = freshInvitations.map((persistentInvitation) => {
|
|
2592
|
+
invariant8(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
2593
|
+
F: __dxlog_file9,
|
|
2594
|
+
L: 82,
|
|
2595
|
+
S: this,
|
|
2596
|
+
A: [
|
|
2597
|
+
"!this._createInvitations.get(persistentInvitation.invitationId)",
|
|
2598
|
+
"'invitation already exists'"
|
|
2599
|
+
]
|
|
2600
|
+
});
|
|
2601
|
+
return this.createInvitation({
|
|
2602
|
+
...persistentInvitation,
|
|
2603
|
+
persistent: false
|
|
2604
|
+
}).get();
|
|
2605
|
+
});
|
|
2606
|
+
return {
|
|
2607
|
+
invitations: cInvitations
|
|
2608
|
+
};
|
|
2609
|
+
} catch (err) {
|
|
2610
|
+
log7.catch(err, void 0, {
|
|
2611
|
+
F: __dxlog_file9,
|
|
2612
|
+
L: 88,
|
|
2613
|
+
S: this,
|
|
2614
|
+
C: (f, a) => f(...a)
|
|
2615
|
+
});
|
|
2616
|
+
return {
|
|
2617
|
+
invitations: []
|
|
2618
|
+
};
|
|
2619
|
+
} finally {
|
|
2620
|
+
this._persistentInvitationsLoadedEvent.emit();
|
|
2621
|
+
this._persistentInvitationsLoaded = true;
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
acceptInvitation(request) {
|
|
2625
|
+
const options = request.invitation;
|
|
2626
|
+
const existingInvitation = this._acceptInvitations.get(options.invitationId);
|
|
2627
|
+
if (existingInvitation) {
|
|
2628
|
+
return existingInvitation;
|
|
2629
|
+
}
|
|
2630
|
+
const handler = this._getHandler(options);
|
|
2631
|
+
const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
|
|
2632
|
+
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
2633
|
+
this.invitationAccepted.emit(invitation.get());
|
|
2634
|
+
this._onInvitationComplete(invitation, () => {
|
|
2635
|
+
this._acceptInvitations.delete(invitation.get().invitationId);
|
|
2636
|
+
this.removedAccepted.emit(invitation.get());
|
|
2637
|
+
});
|
|
2638
|
+
return invitation;
|
|
2639
|
+
}
|
|
2640
|
+
async authenticate({ invitationId, authCode }) {
|
|
2641
|
+
log7("authenticating...", void 0, {
|
|
2642
|
+
F: __dxlog_file9,
|
|
2643
|
+
L: 117,
|
|
2644
|
+
S: this,
|
|
2645
|
+
C: (f, a) => f(...a)
|
|
2646
|
+
});
|
|
2647
|
+
invariant8(invitationId, void 0, {
|
|
2648
|
+
F: __dxlog_file9,
|
|
2649
|
+
L: 118,
|
|
2650
|
+
S: this,
|
|
2651
|
+
A: [
|
|
2652
|
+
"invitationId",
|
|
2653
|
+
""
|
|
2654
|
+
]
|
|
2655
|
+
});
|
|
2656
|
+
const observable = this._acceptInvitations.get(invitationId);
|
|
2657
|
+
if (!observable) {
|
|
2658
|
+
log7.warn("invalid invitation", {
|
|
2659
|
+
invitationId
|
|
2660
|
+
}, {
|
|
2661
|
+
F: __dxlog_file9,
|
|
2662
|
+
L: 121,
|
|
2663
|
+
S: this,
|
|
2664
|
+
C: (f, a) => f(...a)
|
|
2665
|
+
});
|
|
2666
|
+
} else {
|
|
2667
|
+
await observable.authenticate(authCode);
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
async cancelInvitation({ invitationId }) {
|
|
2671
|
+
log7("cancelInvitation...", {
|
|
2672
|
+
invitationId
|
|
2673
|
+
}, {
|
|
2674
|
+
F: __dxlog_file9,
|
|
2675
|
+
L: 128,
|
|
2676
|
+
S: this,
|
|
2677
|
+
C: (f, a) => f(...a)
|
|
2678
|
+
});
|
|
2679
|
+
invariant8(invitationId, void 0, {
|
|
2680
|
+
F: __dxlog_file9,
|
|
2681
|
+
L: 129,
|
|
2682
|
+
S: this,
|
|
2683
|
+
A: [
|
|
2684
|
+
"invitationId",
|
|
2685
|
+
""
|
|
2686
|
+
]
|
|
2687
|
+
});
|
|
2688
|
+
const created = this._createInvitations.get(invitationId);
|
|
2689
|
+
if (created) {
|
|
2690
|
+
if (created.get().persistent) {
|
|
2691
|
+
await this._metadataStore.removeInvitation(invitationId);
|
|
2692
|
+
}
|
|
2693
|
+
await created.cancel();
|
|
2694
|
+
this._createInvitations.delete(invitationId);
|
|
2695
|
+
this.removedCreated.emit(created.get());
|
|
2696
|
+
return;
|
|
2697
|
+
}
|
|
2698
|
+
const accepted = this._acceptInvitations.get(invitationId);
|
|
2699
|
+
if (accepted) {
|
|
2700
|
+
await accepted.cancel();
|
|
2701
|
+
this._acceptInvitations.delete(invitationId);
|
|
2702
|
+
this.removedAccepted.emit(accepted.get());
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
getCreatedInvitations() {
|
|
2706
|
+
return [
|
|
2707
|
+
...this._createInvitations.values()
|
|
2708
|
+
].map((i) => i.get());
|
|
2709
|
+
}
|
|
2710
|
+
getAcceptedInvitations() {
|
|
2711
|
+
return [
|
|
2712
|
+
...this._acceptInvitations.values()
|
|
2713
|
+
].map((i) => i.get());
|
|
2714
|
+
}
|
|
2715
|
+
onPersistentInvitationsLoaded(ctx, callback) {
|
|
2716
|
+
if (this._persistentInvitationsLoaded) {
|
|
2717
|
+
callback();
|
|
2718
|
+
} else {
|
|
2719
|
+
this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
_safePersistInBackground(invitation) {
|
|
2723
|
+
return new Promise((resolve) => {
|
|
2724
|
+
setTimeout(async () => {
|
|
2725
|
+
try {
|
|
2726
|
+
await this._metadataStore.addInvitation(invitation.get());
|
|
2727
|
+
this.saved.emit(invitation.get());
|
|
2728
|
+
} catch (err) {
|
|
2729
|
+
log7.catch(err, void 0, {
|
|
2730
|
+
F: __dxlog_file9,
|
|
2731
|
+
L: 173,
|
|
2732
|
+
S: this,
|
|
2733
|
+
C: (f, a) => f(...a)
|
|
2734
|
+
});
|
|
2735
|
+
await invitation.cancel();
|
|
2736
|
+
} finally {
|
|
2737
|
+
resolve();
|
|
2738
|
+
}
|
|
2739
|
+
});
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
async _safeDeleteInvitation(invitation) {
|
|
2743
|
+
try {
|
|
2744
|
+
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
2745
|
+
} catch (err) {
|
|
2746
|
+
log7.catch(err, void 0, {
|
|
2747
|
+
F: __dxlog_file9,
|
|
2748
|
+
L: 186,
|
|
2749
|
+
S: this,
|
|
2750
|
+
C: (f, a) => f(...a)
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
_onInvitationComplete(invitation, callback) {
|
|
2755
|
+
invitation.subscribe(() => {
|
|
2756
|
+
}, () => {
|
|
2757
|
+
}, callback);
|
|
2758
|
+
}
|
|
2759
|
+
};
|
|
2760
|
+
|
|
2652
2761
|
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
2653
2762
|
import { Stream as Stream9 } from "@dxos/codec-protobuf";
|
|
2654
2763
|
import { raise } from "@dxos/debug";
|
|
@@ -2731,13 +2840,13 @@ ClientRpcServer = _ts_decorate3([
|
|
|
2731
2840
|
], ClientRpcServer);
|
|
2732
2841
|
|
|
2733
2842
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2734
|
-
import { Event as Event6, asyncTimeout, scheduleTask as
|
|
2843
|
+
import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
|
|
2735
2844
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
2736
|
-
import { cancelWithContext as cancelWithContext2, Context as
|
|
2845
|
+
import { cancelWithContext as cancelWithContext2, Context as Context7, ContextDisposedError } from "@dxos/context";
|
|
2737
2846
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
2738
|
-
import { TYPE_PROPERTIES } from "@dxos/echo-db";
|
|
2739
2847
|
import { createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
2740
2848
|
import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
|
|
2849
|
+
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
2741
2850
|
import { failedInvariant, invariant as invariant10 } from "@dxos/invariant";
|
|
2742
2851
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2743
2852
|
import { log as log9 } from "@dxos/log";
|
|
@@ -2787,8 +2896,8 @@ var AutomergeSpaceState = class {
|
|
|
2787
2896
|
};
|
|
2788
2897
|
|
|
2789
2898
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
2790
|
-
import { DeferredTask, Event as Event5, scheduleTask as
|
|
2791
|
-
import { Context as
|
|
2899
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
|
|
2900
|
+
import { Context as Context6, rejectOnDispose } from "@dxos/context";
|
|
2792
2901
|
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2793
2902
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2794
2903
|
import { log as log8 } from "@dxos/log";
|
|
@@ -2802,7 +2911,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
|
2802
2911
|
var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
|
|
2803
2912
|
var NotarizationPlugin = class {
|
|
2804
2913
|
constructor() {
|
|
2805
|
-
this._ctx = new
|
|
2914
|
+
this._ctx = new Context6();
|
|
2806
2915
|
this._extensionOpened = new Event5();
|
|
2807
2916
|
this._extensions = /* @__PURE__ */ new Set();
|
|
2808
2917
|
this._processedCredentials = new ComplexSet2(PublicKey7.hash);
|
|
@@ -2854,7 +2963,7 @@ var NotarizationPlugin = class {
|
|
|
2854
2963
|
});
|
|
2855
2964
|
opCtx?.onDispose(() => ctx.dispose());
|
|
2856
2965
|
if (timeout !== 0) {
|
|
2857
|
-
|
|
2966
|
+
scheduleTask3(ctx, () => {
|
|
2858
2967
|
log8.warn("Notarization timeout", {
|
|
2859
2968
|
timeout,
|
|
2860
2969
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
@@ -2888,7 +2997,7 @@ var NotarizationPlugin = class {
|
|
|
2888
2997
|
C: (f, a) => f(...a)
|
|
2889
2998
|
});
|
|
2890
2999
|
peersTried.clear();
|
|
2891
|
-
|
|
3000
|
+
scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
|
|
2892
3001
|
return;
|
|
2893
3002
|
}
|
|
2894
3003
|
peersTried.add(peer);
|
|
@@ -3068,7 +3177,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3068
3177
|
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
3069
3178
|
var DataSpace = class {
|
|
3070
3179
|
constructor(params) {
|
|
3071
|
-
this._ctx = new
|
|
3180
|
+
this._ctx = new Context7();
|
|
3072
3181
|
this._notarizationPlugin = new NotarizationPlugin();
|
|
3073
3182
|
this._cache = void 0;
|
|
3074
3183
|
// TODO(dmaretskyi): Move into Space?
|
|
@@ -3145,7 +3254,7 @@ var DataSpace = class {
|
|
|
3145
3254
|
await this._notarizationPlugin.open();
|
|
3146
3255
|
await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
|
|
3147
3256
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
3148
|
-
await this._inner.open(new
|
|
3257
|
+
await this._inner.open(new Context7());
|
|
3149
3258
|
this._state = SpaceState.CONTROL_ONLY;
|
|
3150
3259
|
log9("new state", {
|
|
3151
3260
|
state: SpaceState[this._state]
|
|
@@ -3174,7 +3283,7 @@ var DataSpace = class {
|
|
|
3174
3283
|
C: (f, a) => f(...a)
|
|
3175
3284
|
});
|
|
3176
3285
|
await this._ctx.dispose();
|
|
3177
|
-
this._ctx = new
|
|
3286
|
+
this._ctx = new Context7();
|
|
3178
3287
|
await this.authVerifier.close();
|
|
3179
3288
|
await this._inner.close();
|
|
3180
3289
|
await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
|
|
@@ -3193,7 +3302,7 @@ var DataSpace = class {
|
|
|
3193
3302
|
* Initialize the data pipeline in a separate task.
|
|
3194
3303
|
*/
|
|
3195
3304
|
initializeDataPipelineAsync() {
|
|
3196
|
-
|
|
3305
|
+
scheduleTask4(this._ctx, async () => {
|
|
3197
3306
|
try {
|
|
3198
3307
|
this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
|
|
3199
3308
|
await this.initializeDataPipeline();
|
|
@@ -3595,7 +3704,7 @@ DataSpace = _ts_decorate4([
|
|
|
3595
3704
|
|
|
3596
3705
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
3597
3706
|
import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
3598
|
-
import { Context as
|
|
3707
|
+
import { Context as Context8, cancelWithContext as cancelWithContext3 } from "@dxos/context";
|
|
3599
3708
|
import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
3600
3709
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3601
3710
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
@@ -3697,7 +3806,7 @@ var DataSpaceManager = class {
|
|
|
3697
3806
|
this._signingContext = _signingContext;
|
|
3698
3807
|
this._feedStore = _feedStore;
|
|
3699
3808
|
this._automergeHost = _automergeHost;
|
|
3700
|
-
this._ctx = new
|
|
3809
|
+
this._ctx = new Context8();
|
|
3701
3810
|
this.updated = new Event7();
|
|
3702
3811
|
this._spaces = new ComplexMap3(PublicKey9.hash);
|
|
3703
3812
|
this._isOpen = false;
|
|
@@ -4018,7 +4127,7 @@ DataSpaceManager = _ts_decorate5([
|
|
|
4018
4127
|
], DataSpaceManager);
|
|
4019
4128
|
|
|
4020
4129
|
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
4021
|
-
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as
|
|
4130
|
+
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
|
|
4022
4131
|
import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
4023
4132
|
import { raise as raise2 } from "@dxos/debug";
|
|
4024
4133
|
import { invariant as invariant12 } from "@dxos/invariant";
|
|
@@ -4075,7 +4184,7 @@ var SpacesServiceImpl = class {
|
|
|
4075
4184
|
}, {
|
|
4076
4185
|
maxFrequency: false ? void 0 : 2
|
|
4077
4186
|
});
|
|
4078
|
-
|
|
4187
|
+
scheduleTask5(ctx, async () => {
|
|
4079
4188
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4080
4189
|
const subscriptions = new EventSubscriptions2();
|
|
4081
4190
|
ctx.onDispose(() => subscriptions.clear());
|
|
@@ -4109,7 +4218,7 @@ var SpacesServiceImpl = class {
|
|
|
4109
4218
|
}
|
|
4110
4219
|
subscribeMessages({ spaceKey, channel }) {
|
|
4111
4220
|
return new Stream10(({ ctx, next }) => {
|
|
4112
|
-
|
|
4221
|
+
scheduleTask5(ctx, async () => {
|
|
4113
4222
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4114
4223
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
|
|
4115
4224
|
const handle = space.listen(getChannelId(channel), (message) => {
|
|
@@ -4128,7 +4237,7 @@ var SpacesServiceImpl = class {
|
|
|
4128
4237
|
}
|
|
4129
4238
|
};
|
|
4130
4239
|
ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
|
|
4131
|
-
|
|
4240
|
+
scheduleTask5(ctx, async () => {
|
|
4132
4241
|
await space.spaceState.addCredentialProcessor(processor);
|
|
4133
4242
|
if (noTail) {
|
|
4134
4243
|
close();
|
|
@@ -4236,25 +4345,24 @@ var getChannelId = (channel) => `user-channel/${channel}`;
|
|
|
4236
4345
|
|
|
4237
4346
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
4238
4347
|
import { Trigger as Trigger5 } from "@dxos/async";
|
|
4239
|
-
import { Context as
|
|
4348
|
+
import { Context as Context9, Resource } from "@dxos/context";
|
|
4240
4349
|
import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
|
|
4241
4350
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
4242
4351
|
import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
4243
4352
|
import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
4244
|
-
import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
|
|
4353
|
+
import { IndexMetadataStore, IndexStore, Indexer, createStorageCallbacks } from "@dxos/indexing";
|
|
4245
4354
|
import { invariant as invariant13 } from "@dxos/invariant";
|
|
4246
4355
|
import { Keyring } from "@dxos/keyring";
|
|
4247
4356
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
4248
4357
|
import { log as log12 } from "@dxos/log";
|
|
4249
4358
|
import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
|
|
4250
|
-
import { Invitation as
|
|
4359
|
+
import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4251
4360
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
4252
4361
|
import { trace as Trace2 } from "@dxos/tracing";
|
|
4253
4362
|
import { safeInstanceof } from "@dxos/util";
|
|
4254
4363
|
|
|
4255
4364
|
// packages/sdk/client-services/src/packlets/indexing/util.ts
|
|
4256
4365
|
import { getHeads } from "@dxos/automerge/automerge";
|
|
4257
|
-
import { warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
|
|
4258
4366
|
import { idCodec } from "@dxos/protocols";
|
|
4259
4367
|
var createSelectedDocumentsIterator = (automergeHost) => (
|
|
4260
4368
|
/**
|
|
@@ -4265,8 +4373,10 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
4265
4373
|
async function* loadDocuments(ids) {
|
|
4266
4374
|
for (const id of ids) {
|
|
4267
4375
|
const { documentId, objectId } = idCodec.decode(id);
|
|
4268
|
-
const handle = automergeHost.repo.find(documentId);
|
|
4269
|
-
|
|
4376
|
+
const handle = automergeHost.repo.handles[documentId] ?? automergeHost.repo.find(documentId);
|
|
4377
|
+
if (!handle.isReady()) {
|
|
4378
|
+
await handle.whenReady();
|
|
4379
|
+
}
|
|
4270
4380
|
const doc = handle.docSync();
|
|
4271
4381
|
const hash = getHeads(doc).join("");
|
|
4272
4382
|
yield doc.objects?.[objectId] ? [
|
|
@@ -4291,7 +4401,9 @@ var createDocumentsIterator = (automergeHost) => (
|
|
|
4291
4401
|
if (visited.has(handle.documentId)) {
|
|
4292
4402
|
return;
|
|
4293
4403
|
}
|
|
4294
|
-
|
|
4404
|
+
if (!handle.isReady()) {
|
|
4405
|
+
await handle.whenReady();
|
|
4406
|
+
}
|
|
4295
4407
|
const doc = handle.docSync();
|
|
4296
4408
|
const heads = getHeads(doc);
|
|
4297
4409
|
if (doc.objects) {
|
|
@@ -4311,7 +4423,7 @@ var createDocumentsIterator = (automergeHost) => (
|
|
|
4311
4423
|
if (visited.has(id)) {
|
|
4312
4424
|
continue;
|
|
4313
4425
|
}
|
|
4314
|
-
const linkHandle = automergeHost.repo.find(id);
|
|
4426
|
+
const linkHandle = automergeHost.repo.handles[id] ?? automergeHost.repo.find(id);
|
|
4315
4427
|
for await (const result of getObjectsFromHandle(linkHandle)) {
|
|
4316
4428
|
yield result;
|
|
4317
4429
|
}
|
|
@@ -4381,24 +4493,29 @@ var ServiceContext = class extends Resource {
|
|
|
4381
4493
|
});
|
|
4382
4494
|
this.automergeHost = new AutomergeHost({
|
|
4383
4495
|
directory: storage.createDirectory("automerge"),
|
|
4384
|
-
|
|
4496
|
+
db: level.sublevel("automerge"),
|
|
4497
|
+
storageCallbacks: createStorageCallbacks({
|
|
4498
|
+
host: () => this.automergeHost,
|
|
4499
|
+
metadata: this.indexMetadata
|
|
4500
|
+
})
|
|
4385
4501
|
});
|
|
4386
4502
|
this.indexer = new Indexer({
|
|
4387
4503
|
indexStore: new IndexStore({
|
|
4388
|
-
|
|
4504
|
+
db: level.sublevel("index-storage")
|
|
4389
4505
|
}),
|
|
4390
4506
|
metadataStore: this.indexMetadata,
|
|
4391
4507
|
loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
|
|
4392
4508
|
getAllDocuments: createDocumentsIterator(this.automergeHost)
|
|
4393
4509
|
});
|
|
4394
4510
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
4395
|
-
this.
|
|
4511
|
+
this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
|
|
4512
|
+
this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
|
|
4396
4513
|
}
|
|
4397
4514
|
async _open(ctx) {
|
|
4398
4515
|
await this._checkStorageVersion();
|
|
4399
4516
|
log12("opening...", void 0, {
|
|
4400
4517
|
F: __dxlog_file14,
|
|
4401
|
-
L:
|
|
4518
|
+
L: 164,
|
|
4402
4519
|
S: this,
|
|
4403
4520
|
C: (f, a) => f(...a)
|
|
4404
4521
|
});
|
|
@@ -4406,29 +4523,39 @@ var ServiceContext = class extends Resource {
|
|
|
4406
4523
|
id: this._instanceId
|
|
4407
4524
|
}), {
|
|
4408
4525
|
F: __dxlog_file14,
|
|
4409
|
-
L:
|
|
4526
|
+
L: 165,
|
|
4410
4527
|
S: this,
|
|
4411
4528
|
C: (f, a) => f(...a)
|
|
4412
4529
|
});
|
|
4413
4530
|
await this.signalManager.open();
|
|
4414
4531
|
await this.networkManager.open();
|
|
4532
|
+
await this.automergeHost.open();
|
|
4415
4533
|
await this.metadataStore.load();
|
|
4416
4534
|
await this.spaceManager.open();
|
|
4417
4535
|
await this.identityManager.open(ctx);
|
|
4418
4536
|
if (this.identityManager.identity) {
|
|
4419
4537
|
await this._initialize(ctx);
|
|
4420
4538
|
}
|
|
4539
|
+
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
4540
|
+
log12("loaded persistent invitations", {
|
|
4541
|
+
count: loadedInvitations.invitations?.length
|
|
4542
|
+
}, {
|
|
4543
|
+
F: __dxlog_file14,
|
|
4544
|
+
L: 178,
|
|
4545
|
+
S: this,
|
|
4546
|
+
C: (f, a) => f(...a)
|
|
4547
|
+
});
|
|
4421
4548
|
log12.trace("dxos.sdk.service-context.open", trace8.end({
|
|
4422
4549
|
id: this._instanceId
|
|
4423
4550
|
}), {
|
|
4424
4551
|
F: __dxlog_file14,
|
|
4425
|
-
L:
|
|
4552
|
+
L: 180,
|
|
4426
4553
|
S: this,
|
|
4427
4554
|
C: (f, a) => f(...a)
|
|
4428
4555
|
});
|
|
4429
4556
|
log12("opened", void 0, {
|
|
4430
4557
|
F: __dxlog_file14,
|
|
4431
|
-
L:
|
|
4558
|
+
L: 181,
|
|
4432
4559
|
S: this,
|
|
4433
4560
|
C: (f, a) => f(...a)
|
|
4434
4561
|
});
|
|
@@ -4436,7 +4563,7 @@ var ServiceContext = class extends Resource {
|
|
|
4436
4563
|
async _close() {
|
|
4437
4564
|
log12("closing...", void 0, {
|
|
4438
4565
|
F: __dxlog_file14,
|
|
4439
|
-
L:
|
|
4566
|
+
L: 185,
|
|
4440
4567
|
S: this,
|
|
4441
4568
|
C: (f, a) => f(...a)
|
|
4442
4569
|
});
|
|
@@ -4454,21 +4581,21 @@ var ServiceContext = class extends Resource {
|
|
|
4454
4581
|
await this.indexer.destroy();
|
|
4455
4582
|
log12("closed", void 0, {
|
|
4456
4583
|
F: __dxlog_file14,
|
|
4457
|
-
L:
|
|
4584
|
+
L: 198,
|
|
4458
4585
|
S: this,
|
|
4459
4586
|
C: (f, a) => f(...a)
|
|
4460
4587
|
});
|
|
4461
4588
|
}
|
|
4462
4589
|
async createIdentity(params = {}) {
|
|
4463
4590
|
const identity = await this.identityManager.createIdentity(params);
|
|
4464
|
-
await this._initialize(new
|
|
4591
|
+
await this._initialize(new Context9());
|
|
4465
4592
|
return identity;
|
|
4466
4593
|
}
|
|
4467
4594
|
getInvitationHandler(invitation) {
|
|
4468
4595
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
4469
4596
|
invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
4470
4597
|
F: __dxlog_file14,
|
|
4471
|
-
L:
|
|
4598
|
+
L: 209,
|
|
4472
4599
|
S: this,
|
|
4473
4600
|
A: [
|
|
4474
4601
|
"factory",
|
|
@@ -4487,7 +4614,7 @@ var ServiceContext = class extends Resource {
|
|
|
4487
4614
|
}
|
|
4488
4615
|
async _acceptIdentity(params) {
|
|
4489
4616
|
const identity = await this.identityManager.acceptIdentity(params);
|
|
4490
|
-
await this._initialize(new
|
|
4617
|
+
await this._initialize(new Context9());
|
|
4491
4618
|
return identity;
|
|
4492
4619
|
}
|
|
4493
4620
|
async _checkStorageVersion() {
|
|
@@ -4500,7 +4627,7 @@ var ServiceContext = class extends Resource {
|
|
|
4500
4627
|
async _initialize(ctx) {
|
|
4501
4628
|
log12("initializing spaces...", void 0, {
|
|
4502
4629
|
F: __dxlog_file14,
|
|
4503
|
-
L:
|
|
4630
|
+
L: 240,
|
|
4504
4631
|
S: this,
|
|
4505
4632
|
C: (f, a) => f(...a)
|
|
4506
4633
|
});
|
|
@@ -4520,10 +4647,10 @@ var ServiceContext = class extends Resource {
|
|
|
4520
4647
|
};
|
|
4521
4648
|
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
|
|
4522
4649
|
await this.dataSpaceManager.open();
|
|
4523
|
-
this._handlerFactories.set(
|
|
4650
|
+
this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
|
|
4524
4651
|
invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
4525
4652
|
F: __dxlog_file14,
|
|
4526
|
-
L:
|
|
4653
|
+
L: 264,
|
|
4527
4654
|
S: this,
|
|
4528
4655
|
A: [
|
|
4529
4656
|
"this.dataSpaceManager",
|
|
@@ -4547,7 +4674,7 @@ var ServiceContext = class extends Resource {
|
|
|
4547
4674
|
details: assertion
|
|
4548
4675
|
}, {
|
|
4549
4676
|
F: __dxlog_file14,
|
|
4550
|
-
L:
|
|
4677
|
+
L: 280,
|
|
4551
4678
|
S: this,
|
|
4552
4679
|
C: (f, a) => f(...a)
|
|
4553
4680
|
});
|
|
@@ -4558,7 +4685,7 @@ var ServiceContext = class extends Resource {
|
|
|
4558
4685
|
details: assertion
|
|
4559
4686
|
}, {
|
|
4560
4687
|
F: __dxlog_file14,
|
|
4561
|
-
L:
|
|
4688
|
+
L: 284,
|
|
4562
4689
|
S: this,
|
|
4563
4690
|
C: (f, a) => f(...a)
|
|
4564
4691
|
});
|
|
@@ -4569,7 +4696,7 @@ var ServiceContext = class extends Resource {
|
|
|
4569
4696
|
details: assertion
|
|
4570
4697
|
}, {
|
|
4571
4698
|
F: __dxlog_file14,
|
|
4572
|
-
L:
|
|
4699
|
+
L: 289,
|
|
4573
4700
|
S: this,
|
|
4574
4701
|
C: (f, a) => f(...a)
|
|
4575
4702
|
});
|
|
@@ -4580,7 +4707,7 @@ var ServiceContext = class extends Resource {
|
|
|
4580
4707
|
} catch (err) {
|
|
4581
4708
|
log12.catch(err, void 0, {
|
|
4582
4709
|
F: __dxlog_file14,
|
|
4583
|
-
L:
|
|
4710
|
+
L: 295,
|
|
4584
4711
|
S: this,
|
|
4585
4712
|
C: (f, a) => f(...a)
|
|
4586
4713
|
});
|
|
@@ -4634,7 +4761,7 @@ import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/s
|
|
|
4634
4761
|
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
4635
4762
|
|
|
4636
4763
|
// packages/sdk/client-services/src/version.ts
|
|
4637
|
-
var DXOS_VERSION = "0.4.10-main.
|
|
4764
|
+
var DXOS_VERSION = "0.4.10-main.3acb4a8";
|
|
4638
4765
|
|
|
4639
4766
|
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
4640
4767
|
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -4877,10 +5004,10 @@ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
|
|
|
4877
5004
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
4878
5005
|
import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
|
|
4879
5006
|
import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
|
|
4880
|
-
import { Context as
|
|
5007
|
+
import { Context as Context10 } from "@dxos/context";
|
|
4881
5008
|
import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
|
|
4882
|
-
import
|
|
4883
|
-
import {
|
|
5009
|
+
import { getTypeReference } from "@dxos/echo-schema";
|
|
5010
|
+
import { QueryServiceImpl } from "@dxos/indexing";
|
|
4884
5011
|
import { invariant as invariant16 } from "@dxos/invariant";
|
|
4885
5012
|
import { PublicKey as PublicKey13 } from "@dxos/keys";
|
|
4886
5013
|
import { log as log16 } from "@dxos/log";
|
|
@@ -5323,7 +5450,7 @@ import path from "@dxos/node-std/path";
|
|
|
5323
5450
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5324
5451
|
var createLevel = async (config) => {
|
|
5325
5452
|
const persistent = isPersistent(config);
|
|
5326
|
-
const storagePath = persistent ? getRootPath(config)
|
|
5453
|
+
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey12.random().toHex()}`;
|
|
5327
5454
|
const level = new Level(storagePath);
|
|
5328
5455
|
await level.open();
|
|
5329
5456
|
return level;
|
|
@@ -5404,6 +5531,7 @@ var ClientServicesHost = class {
|
|
|
5404
5531
|
transportFactory,
|
|
5405
5532
|
signalManager,
|
|
5406
5533
|
storage,
|
|
5534
|
+
level,
|
|
5407
5535
|
// TODO(wittjosiah): Turn this on by default.
|
|
5408
5536
|
lockKey,
|
|
5409
5537
|
callbacks,
|
|
@@ -5414,6 +5542,7 @@ var ClientServicesHost = class {
|
|
|
5414
5542
|
this._opening = false;
|
|
5415
5543
|
this._open = false;
|
|
5416
5544
|
this._storage = storage;
|
|
5545
|
+
this._level = level;
|
|
5417
5546
|
this._callbacks = callbacks;
|
|
5418
5547
|
this._runtimeParams = runtimeParams;
|
|
5419
5548
|
if (config) {
|
|
@@ -5428,7 +5557,7 @@ var ClientServicesHost = class {
|
|
|
5428
5557
|
lockKey,
|
|
5429
5558
|
onAcquire: () => {
|
|
5430
5559
|
if (!this._opening) {
|
|
5431
|
-
void this.open(new
|
|
5560
|
+
void this.open(new Context10());
|
|
5432
5561
|
}
|
|
5433
5562
|
},
|
|
5434
5563
|
onRelease: () => this.close()
|
|
@@ -5485,7 +5614,7 @@ var ClientServicesHost = class {
|
|
|
5485
5614
|
initialize({ config, ...options }) {
|
|
5486
5615
|
invariant16(!this._open, "service host is open", {
|
|
5487
5616
|
F: __dxlog_file19,
|
|
5488
|
-
L:
|
|
5617
|
+
L: 198,
|
|
5489
5618
|
S: this,
|
|
5490
5619
|
A: [
|
|
5491
5620
|
"!this._open",
|
|
@@ -5494,14 +5623,14 @@ var ClientServicesHost = class {
|
|
|
5494
5623
|
});
|
|
5495
5624
|
log16("initializing...", void 0, {
|
|
5496
5625
|
F: __dxlog_file19,
|
|
5497
|
-
L:
|
|
5626
|
+
L: 199,
|
|
5498
5627
|
S: this,
|
|
5499
5628
|
C: (f, a) => f(...a)
|
|
5500
5629
|
});
|
|
5501
5630
|
if (config) {
|
|
5502
5631
|
invariant16(!this._config, "config already set", {
|
|
5503
5632
|
F: __dxlog_file19,
|
|
5504
|
-
L:
|
|
5633
|
+
L: 202,
|
|
5505
5634
|
S: this,
|
|
5506
5635
|
A: [
|
|
5507
5636
|
"!this._config",
|
|
@@ -5516,7 +5645,7 @@ var ClientServicesHost = class {
|
|
|
5516
5645
|
if (!options.signalManager) {
|
|
5517
5646
|
log16.warn("running signaling without telemetry metadata.", void 0, {
|
|
5518
5647
|
F: __dxlog_file19,
|
|
5519
|
-
L:
|
|
5648
|
+
L: 210,
|
|
5520
5649
|
S: this,
|
|
5521
5650
|
C: (f, a) => f(...a)
|
|
5522
5651
|
});
|
|
@@ -5527,7 +5656,7 @@ var ClientServicesHost = class {
|
|
|
5527
5656
|
this._signalManager = signalManager;
|
|
5528
5657
|
invariant16(!this._networkManager, "network manager already set", {
|
|
5529
5658
|
F: __dxlog_file19,
|
|
5530
|
-
L:
|
|
5659
|
+
L: 221,
|
|
5531
5660
|
S: this,
|
|
5532
5661
|
A: [
|
|
5533
5662
|
"!this._networkManager",
|
|
@@ -5541,7 +5670,7 @@ var ClientServicesHost = class {
|
|
|
5541
5670
|
});
|
|
5542
5671
|
log16("initialized", void 0, {
|
|
5543
5672
|
F: __dxlog_file19,
|
|
5544
|
-
L:
|
|
5673
|
+
L: 228,
|
|
5545
5674
|
S: this,
|
|
5546
5675
|
C: (f, a) => f(...a)
|
|
5547
5676
|
});
|
|
@@ -5555,13 +5684,13 @@ var ClientServicesHost = class {
|
|
|
5555
5684
|
id: traceId
|
|
5556
5685
|
}), {
|
|
5557
5686
|
F: __dxlog_file19,
|
|
5558
|
-
L:
|
|
5687
|
+
L: 239,
|
|
5559
5688
|
S: this,
|
|
5560
5689
|
C: (f, a) => f(...a)
|
|
5561
5690
|
});
|
|
5562
5691
|
invariant16(this._config, "config not set", {
|
|
5563
5692
|
F: __dxlog_file19,
|
|
5564
|
-
L:
|
|
5693
|
+
L: 241,
|
|
5565
5694
|
S: this,
|
|
5566
5695
|
A: [
|
|
5567
5696
|
"this._config",
|
|
@@ -5570,7 +5699,7 @@ var ClientServicesHost = class {
|
|
|
5570
5699
|
});
|
|
5571
5700
|
invariant16(this._storage, "storage not set", {
|
|
5572
5701
|
F: __dxlog_file19,
|
|
5573
|
-
L:
|
|
5702
|
+
L: 242,
|
|
5574
5703
|
S: this,
|
|
5575
5704
|
A: [
|
|
5576
5705
|
"this._storage",
|
|
@@ -5579,7 +5708,7 @@ var ClientServicesHost = class {
|
|
|
5579
5708
|
});
|
|
5580
5709
|
invariant16(this._signalManager, "signal manager not set", {
|
|
5581
5710
|
F: __dxlog_file19,
|
|
5582
|
-
L:
|
|
5711
|
+
L: 243,
|
|
5583
5712
|
S: this,
|
|
5584
5713
|
A: [
|
|
5585
5714
|
"this._signalManager",
|
|
@@ -5588,7 +5717,7 @@ var ClientServicesHost = class {
|
|
|
5588
5717
|
});
|
|
5589
5718
|
invariant16(this._networkManager, "network manager not set", {
|
|
5590
5719
|
F: __dxlog_file19,
|
|
5591
|
-
L:
|
|
5720
|
+
L: 244,
|
|
5592
5721
|
S: this,
|
|
5593
5722
|
A: [
|
|
5594
5723
|
"this._networkManager",
|
|
@@ -5600,30 +5729,33 @@ var ClientServicesHost = class {
|
|
|
5600
5729
|
lockKey: this._resourceLock?.lockKey
|
|
5601
5730
|
}, {
|
|
5602
5731
|
F: __dxlog_file19,
|
|
5603
|
-
L:
|
|
5732
|
+
L: 247,
|
|
5604
5733
|
S: this,
|
|
5605
5734
|
C: (f, a) => f(...a)
|
|
5606
5735
|
});
|
|
5607
5736
|
if (!this._level) {
|
|
5608
5737
|
this._level = await createLevel(this._config.get("runtime.client.storage", {}));
|
|
5609
5738
|
}
|
|
5739
|
+
await this._level.open();
|
|
5610
5740
|
await this._resourceLock?.acquire();
|
|
5611
5741
|
await this._loggingService.open();
|
|
5612
5742
|
this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
|
|
5743
|
+
this._queryService = new QueryServiceImpl({
|
|
5744
|
+
indexer: this._serviceContext.indexer,
|
|
5745
|
+
automergeHost: this._serviceContext.automergeHost
|
|
5746
|
+
});
|
|
5747
|
+
await this._queryService.open(ctx);
|
|
5613
5748
|
this._serviceRegistry.setServices({
|
|
5614
5749
|
SystemService: this._systemService,
|
|
5615
5750
|
IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
|
|
5616
|
-
InvitationsService: new InvitationsServiceImpl(this._serviceContext.
|
|
5751
|
+
InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
|
|
5617
5752
|
DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
|
|
5618
5753
|
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
|
|
5619
5754
|
await this._serviceContext.initialized.wait();
|
|
5620
5755
|
return this._serviceContext.dataSpaceManager;
|
|
5621
5756
|
}),
|
|
5622
5757
|
DataService: new DataServiceImpl(this._serviceContext.automergeHost),
|
|
5623
|
-
|
|
5624
|
-
indexer: this._serviceContext.indexer,
|
|
5625
|
-
automergeHost: this._serviceContext.automergeHost
|
|
5626
|
-
}),
|
|
5758
|
+
QueryService: this._queryService,
|
|
5627
5759
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
5628
5760
|
LoggingService: this._loggingService,
|
|
5629
5761
|
TracingService: this._tracingService,
|
|
@@ -5635,24 +5767,6 @@ var ClientServicesHost = class {
|
|
|
5635
5767
|
})
|
|
5636
5768
|
});
|
|
5637
5769
|
await this._serviceContext.open(ctx);
|
|
5638
|
-
invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
|
|
5639
|
-
F: __dxlog_file19,
|
|
5640
|
-
L: 303,
|
|
5641
|
-
S: this,
|
|
5642
|
-
A: [
|
|
5643
|
-
"this.serviceRegistry.services.InvitationsService",
|
|
5644
|
-
""
|
|
5645
|
-
]
|
|
5646
|
-
});
|
|
5647
|
-
const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
|
|
5648
|
-
log16("loaded persistent invitations", {
|
|
5649
|
-
count: loadedInvitations.invitations?.length
|
|
5650
|
-
}, {
|
|
5651
|
-
F: __dxlog_file19,
|
|
5652
|
-
L: 306,
|
|
5653
|
-
S: this,
|
|
5654
|
-
C: (f, a) => f(...a)
|
|
5655
|
-
});
|
|
5656
5770
|
const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
|
|
5657
5771
|
if (devtoolsProxy) {
|
|
5658
5772
|
this._devtoolsProxy = new WebsocketRpcClient({
|
|
@@ -5672,7 +5786,7 @@ var ClientServicesHost = class {
|
|
|
5672
5786
|
deviceKey
|
|
5673
5787
|
}, {
|
|
5674
5788
|
F: __dxlog_file19,
|
|
5675
|
-
L:
|
|
5789
|
+
L: 330,
|
|
5676
5790
|
S: this,
|
|
5677
5791
|
C: (f, a) => f(...a)
|
|
5678
5792
|
});
|
|
@@ -5680,7 +5794,7 @@ var ClientServicesHost = class {
|
|
|
5680
5794
|
id: traceId
|
|
5681
5795
|
}), {
|
|
5682
5796
|
F: __dxlog_file19,
|
|
5683
|
-
L:
|
|
5797
|
+
L: 331,
|
|
5684
5798
|
S: this,
|
|
5685
5799
|
C: (f, a) => f(...a)
|
|
5686
5800
|
});
|
|
@@ -5694,7 +5808,7 @@ var ClientServicesHost = class {
|
|
|
5694
5808
|
deviceKey
|
|
5695
5809
|
}, {
|
|
5696
5810
|
F: __dxlog_file19,
|
|
5697
|
-
L:
|
|
5811
|
+
L: 342,
|
|
5698
5812
|
S: this,
|
|
5699
5813
|
C: (f, a) => f(...a)
|
|
5700
5814
|
});
|
|
@@ -5704,6 +5818,7 @@ var ClientServicesHost = class {
|
|
|
5704
5818
|
SystemService: this._systemService
|
|
5705
5819
|
});
|
|
5706
5820
|
await this._loggingService.close();
|
|
5821
|
+
await this._queryService.close();
|
|
5707
5822
|
await this._serviceContext.close();
|
|
5708
5823
|
await this._level?.close();
|
|
5709
5824
|
this._open = false;
|
|
@@ -5712,7 +5827,7 @@ var ClientServicesHost = class {
|
|
|
5712
5827
|
deviceKey
|
|
5713
5828
|
}, {
|
|
5714
5829
|
F: __dxlog_file19,
|
|
5715
|
-
L:
|
|
5830
|
+
L: 352,
|
|
5716
5831
|
S: this,
|
|
5717
5832
|
C: (f, a) => f(...a)
|
|
5718
5833
|
});
|
|
@@ -5723,13 +5838,13 @@ var ClientServicesHost = class {
|
|
|
5723
5838
|
id: traceId
|
|
5724
5839
|
}), {
|
|
5725
5840
|
F: __dxlog_file19,
|
|
5726
|
-
L:
|
|
5841
|
+
L: 357,
|
|
5727
5842
|
S: this,
|
|
5728
5843
|
C: (f, a) => f(...a)
|
|
5729
5844
|
});
|
|
5730
5845
|
log16("resetting...", void 0, {
|
|
5731
5846
|
F: __dxlog_file19,
|
|
5732
|
-
L:
|
|
5847
|
+
L: 359,
|
|
5733
5848
|
S: this,
|
|
5734
5849
|
C: (f, a) => f(...a)
|
|
5735
5850
|
});
|
|
@@ -5737,7 +5852,7 @@ var ClientServicesHost = class {
|
|
|
5737
5852
|
await this._storage.reset();
|
|
5738
5853
|
log16("reset", void 0, {
|
|
5739
5854
|
F: __dxlog_file19,
|
|
5740
|
-
L:
|
|
5855
|
+
L: 362,
|
|
5741
5856
|
S: this,
|
|
5742
5857
|
C: (f, a) => f(...a)
|
|
5743
5858
|
});
|
|
@@ -5745,7 +5860,7 @@ var ClientServicesHost = class {
|
|
|
5745
5860
|
id: traceId
|
|
5746
5861
|
}), {
|
|
5747
5862
|
F: __dxlog_file19,
|
|
5748
|
-
L:
|
|
5863
|
+
L: 363,
|
|
5749
5864
|
S: this,
|
|
5750
5865
|
C: (f, a) => f(...a)
|
|
5751
5866
|
});
|
|
@@ -5758,7 +5873,7 @@ var ClientServicesHost = class {
|
|
|
5758
5873
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
5759
5874
|
invariant16(automergeIndex, void 0, {
|
|
5760
5875
|
F: __dxlog_file19,
|
|
5761
|
-
L:
|
|
5876
|
+
L: 375,
|
|
5762
5877
|
S: this,
|
|
5763
5878
|
A: [
|
|
5764
5879
|
"automergeIndex",
|
|
@@ -5769,7 +5884,7 @@ var ClientServicesHost = class {
|
|
|
5769
5884
|
await document.whenReady();
|
|
5770
5885
|
const properties = {
|
|
5771
5886
|
system: {
|
|
5772
|
-
type: encodeReference(
|
|
5887
|
+
type: encodeReference(getTypeReference(Properties))
|
|
5773
5888
|
},
|
|
5774
5889
|
data: {
|
|
5775
5890
|
[defaultKey]: identity.identityKey.toHex()
|
|
@@ -5864,9 +5979,10 @@ export {
|
|
|
5864
5979
|
IdentityServiceImpl,
|
|
5865
5980
|
DeviceInvitationProtocol,
|
|
5866
5981
|
InvitationsHandler,
|
|
5867
|
-
|
|
5982
|
+
createAdmissionKeypair,
|
|
5868
5983
|
InvitationsServiceImpl,
|
|
5869
5984
|
SpaceInvitationProtocol,
|
|
5985
|
+
InvitationsManager,
|
|
5870
5986
|
ClientRpcServer,
|
|
5871
5987
|
DataSpace,
|
|
5872
5988
|
DataSpaceManager,
|
|
@@ -5884,4 +6000,4 @@ export {
|
|
|
5884
6000
|
ClientServicesHost,
|
|
5885
6001
|
ClientServicesProviderResource
|
|
5886
6002
|
};
|
|
5887
|
-
//# sourceMappingURL=chunk-
|
|
6003
|
+
//# sourceMappingURL=chunk-KZV2TSO3.mjs.map
|