@minca/core 0.3.1 → 0.4.0
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/README.md +2 -2
- package/dist/{session → hosting}/hosting.d.ts +1 -1
- package/dist/{session → hosting}/hosting.d.ts.map +1 -1
- package/dist/{session → hosting}/hosting.js.map +1 -1
- package/dist/index.d.ts +20 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -19
- package/dist/index.js.map +1 -1
- package/dist/network/mesh.d.ts.map +1 -1
- package/dist/network/mesh.js +13 -3
- package/dist/network/mesh.js.map +1 -1
- package/dist/network/network-manager.d.ts +5 -0
- package/dist/network/network-manager.d.ts.map +1 -1
- package/dist/network/network-manager.js +3 -0
- package/dist/network/network-manager.js.map +1 -1
- package/dist/network/peer-auth.d.ts +17 -5
- package/dist/network/peer-auth.d.ts.map +1 -1
- package/dist/network/peer-auth.js +19 -9
- package/dist/network/peer-auth.js.map +1 -1
- package/dist/network/rtc-transport.d.ts.map +1 -1
- package/dist/network/rtc-transport.js +1 -0
- package/dist/network/rtc-transport.js.map +1 -1
- package/dist/network/transport.d.ts +12 -0
- package/dist/network/transport.d.ts.map +1 -1
- package/dist/network/ws-transport.d.ts +1 -1
- package/dist/network/ws-transport.d.ts.map +1 -1
- package/dist/network/ws-transport.js +14 -4
- package/dist/network/ws-transport.js.map +1 -1
- package/dist/node/index.d.ts +1 -5
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +0 -3
- package/dist/node/index.js.map +1 -1
- package/dist/node/node-hosting.js +1 -1
- package/dist/node/node-records.js +1 -1
- package/dist/node/node-records.js.map +1 -1
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +18 -0
- package/dist/node/node.js.map +1 -1
- package/dist/node/space-mirrors.d.ts +1 -1
- package/dist/node/space-mirrors.d.ts.map +1 -1
- package/dist/node/space-mirrors.js +17 -5
- package/dist/node/space-mirrors.js.map +1 -1
- package/dist/node/space-peers.d.ts +2 -0
- package/dist/node/space-peers.d.ts.map +1 -1
- package/dist/node/space-peers.js +41 -8
- package/dist/node/space-peers.js.map +1 -1
- package/dist/node/space-runtime.d.ts +4 -2
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +3 -2
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/space-standing.d.ts.map +1 -1
- package/dist/node/space-standing.js +12 -38
- package/dist/node/space-standing.js.map +1 -1
- package/dist/node/space-warrants.js +1 -1
- package/dist/node/space-warrants.js.map +1 -1
- package/dist/node/space-writing.d.ts.map +1 -1
- package/dist/node/space-writing.js +12 -32
- package/dist/node/space-writing.js.map +1 -1
- package/dist/node/stores.d.ts +2 -58
- package/dist/node/stores.d.ts.map +1 -1
- package/dist/node/stores.js +1 -74
- package/dist/node/stores.js.map +1 -1
- package/dist/node/types.d.ts +3 -3
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/writer-keys.d.ts +15 -14
- package/dist/node/writer-keys.d.ts.map +1 -1
- package/dist/node/writer-keys.js +3 -113
- package/dist/node/writer-keys.js.map +1 -1
- package/dist/records/key.d.ts +16 -19
- package/dist/records/key.d.ts.map +1 -1
- package/dist/records/key.js +53 -45
- package/dist/records/key.js.map +1 -1
- package/dist/records/rules.d.ts +1 -1
- package/dist/records/rules.d.ts.map +1 -1
- package/dist/records/rules.js +6 -4
- package/dist/records/rules.js.map +1 -1
- package/dist/storage/body-cache.d.ts +6 -3
- package/dist/storage/body-cache.d.ts.map +1 -1
- package/dist/storage/body-cache.js +37 -14
- package/dist/storage/body-cache.js.map +1 -1
- package/dist/storage/mirror.d.ts.map +1 -1
- package/dist/storage/mirror.js +35 -16
- package/dist/storage/mirror.js.map +1 -1
- package/dist/storage/segment.d.ts +6 -2
- package/dist/storage/segment.d.ts.map +1 -1
- package/dist/storage/segment.js +8 -4
- package/dist/storage/segment.js.map +1 -1
- package/dist/storage/shared-store.d.ts +32 -0
- package/dist/storage/shared-store.d.ts.map +1 -0
- package/dist/storage/{folder-reconcile.js → shared-store.js} +15 -15
- package/dist/storage/shared-store.js.map +1 -0
- package/dist/storage/storage-provider.d.ts +0 -9
- package/dist/storage/storage-provider.d.ts.map +1 -1
- package/dist/storage/storage-provider.js +8 -8
- package/dist/storage/storage-provider.js.map +1 -1
- package/dist/sync/sync-engine.d.ts +7 -0
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +179 -47
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +1 -1
- package/dist/sync/sync-messages.js +1 -1
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -5
- package/dist/utils/index.js.map +1 -1
- package/docs/README.md +3 -2
- package/docs/building-an-app.md +2 -2
- package/docs/node.md +24 -20
- package/docs/query-format.md +6 -5
- package/docs/records-and-queries.md +12 -13
- package/docs/storage.md +41 -15
- package/package.json +10 -19
- package/dist/identity/account-store.d.ts +0 -83
- package/dist/identity/account-store.d.ts.map +0 -1
- package/dist/identity/account-store.js +0 -234
- package/dist/identity/account-store.js.map +0 -1
- package/dist/identity/device-key.d.ts +0 -26
- package/dist/identity/device-key.d.ts.map +0 -1
- package/dist/identity/device-key.js +0 -48
- package/dist/identity/device-key.js.map +0 -1
- package/dist/identity/idb.d.ts +0 -19
- package/dist/identity/idb.d.ts.map +0 -1
- package/dist/identity/idb.js +0 -56
- package/dist/identity/idb.js.map +0 -1
- package/dist/node/worker.d.ts +0 -91
- package/dist/node/worker.d.ts.map +0 -1
- package/dist/node/worker.js +0 -344
- package/dist/node/worker.js.map +0 -1
- package/dist/node-worker.d.ts +0 -2
- package/dist/node-worker.d.ts.map +0 -1
- package/dist/node-worker.js +0 -16
- package/dist/node-worker.js.map +0 -1
- package/dist/session/account-hint.d.ts +0 -13
- package/dist/session/account-hint.d.ts.map +0 -1
- package/dist/session/account-hint.js +0 -54
- package/dist/session/account-hint.js.map +0 -1
- package/dist/session/channel-room.d.ts +0 -26
- package/dist/session/channel-room.d.ts.map +0 -1
- package/dist/session/channel-room.js +0 -56
- package/dist/session/channel-room.js.map +0 -1
- package/dist/session/connect-code.d.ts +0 -127
- package/dist/session/connect-code.d.ts.map +0 -1
- package/dist/session/connect-code.js +0 -408
- package/dist/session/connect-code.js.map +0 -1
- package/dist/session/connect.d.ts +0 -393
- package/dist/session/connect.d.ts.map +0 -1
- package/dist/session/connect.js +0 -587
- package/dist/session/connect.js.map +0 -1
- package/dist/session/connection.d.ts +0 -141
- package/dist/session/connection.d.ts.map +0 -1
- package/dist/session/connection.js +0 -344
- package/dist/session/connection.js.map +0 -1
- package/dist/session/index.d.ts +0 -24
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -18
- package/dist/session/index.js.map +0 -1
- package/dist/session/pairing.d.ts +0 -97
- package/dist/session/pairing.d.ts.map +0 -1
- package/dist/session/pairing.js +0 -251
- package/dist/session/pairing.js.map +0 -1
- package/dist/session/places.d.ts +0 -71
- package/dist/session/places.d.ts.map +0 -1
- package/dist/session/places.js +0 -130
- package/dist/session/places.js.map +0 -1
- package/dist/session/popup.d.ts +0 -13
- package/dist/session/popup.d.ts.map +0 -1
- package/dist/session/popup.js +0 -23
- package/dist/session/popup.js.map +0 -1
- package/dist/session/stay-signed-in.d.ts +0 -48
- package/dist/session/stay-signed-in.d.ts.map +0 -1
- package/dist/session/stay-signed-in.js +0 -141
- package/dist/session/stay-signed-in.js.map +0 -1
- package/dist/storage/blob/directory.d.ts +0 -14
- package/dist/storage/blob/directory.d.ts.map +0 -1
- package/dist/storage/blob/directory.js +0 -87
- package/dist/storage/blob/directory.js.map +0 -1
- package/dist/storage/blob/memory.d.ts +0 -6
- package/dist/storage/blob/memory.d.ts.map +0 -1
- package/dist/storage/blob/memory.js +0 -20
- package/dist/storage/blob/memory.js.map +0 -1
- package/dist/storage/blob/s3.d.ts +0 -16
- package/dist/storage/blob/s3.d.ts.map +0 -1
- package/dist/storage/blob/s3.js +0 -91
- package/dist/storage/blob/s3.js.map +0 -1
- package/dist/storage/directory-access.d.ts +0 -36
- package/dist/storage/directory-access.d.ts.map +0 -1
- package/dist/storage/directory-access.js +0 -89
- package/dist/storage/directory-access.js.map +0 -1
- package/dist/storage/folder-adapter.d.ts +0 -100
- package/dist/storage/folder-adapter.d.ts.map +0 -1
- package/dist/storage/folder-adapter.js +0 -232
- package/dist/storage/folder-adapter.js.map +0 -1
- package/dist/storage/folder-reconcile.d.ts +0 -33
- package/dist/storage/folder-reconcile.d.ts.map +0 -1
- package/dist/storage/folder-reconcile.js.map +0 -1
- package/dist/storage/index.d.ts +0 -6
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js +0 -5
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/indexeddb-adapter.d.ts +0 -8
- package/dist/storage/indexeddb-adapter.d.ts.map +0 -1
- package/dist/storage/indexeddb-adapter.js +0 -128
- package/dist/storage/indexeddb-adapter.js.map +0 -1
- package/dist/storage/sqlite-adapter.d.ts +0 -57
- package/dist/storage/sqlite-adapter.d.ts.map +0 -1
- package/dist/storage/sqlite-adapter.js +0 -213
- package/dist/storage/sqlite-adapter.js.map +0 -1
- /package/dist/{session → hosting}/hosting.js +0 -0
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module session/pairing
|
|
3
|
-
* Handing an account to a phone. The desktop shows a QR code whose link
|
|
4
|
-
* carries a one-time secret and a relay. Both sides meet in a room named after
|
|
5
|
-
* the secret, swap ephemeral keys (the phone commits to its key first), and
|
|
6
|
-
* show the same six digits. Once the person says they match, the desktop sends
|
|
7
|
-
* the seed and the spaces, sealed for this exchange only. Afterwards the phone
|
|
8
|
-
* is a full peer and never needs the desktop again.
|
|
9
|
-
*/
|
|
10
|
-
import type { PeerTransport } from '../network/transport.js';
|
|
11
|
-
import { type PairingTicket } from '../identity/pairing.js';
|
|
12
|
-
/** What the desktop hands over */
|
|
13
|
-
export interface Handover {
|
|
14
|
-
readonly seed: Uint8Array;
|
|
15
|
-
readonly spaces: ReadonlyArray<string>;
|
|
16
|
-
}
|
|
17
|
-
export type PairingStage = {
|
|
18
|
-
readonly kind: 'waiting';
|
|
19
|
-
}
|
|
20
|
-
/** The phone's side: show the code, and wait for the person to confirm on the computer */
|
|
21
|
-
| {
|
|
22
|
-
readonly kind: 'confirm';
|
|
23
|
-
readonly code: string;
|
|
24
|
-
}
|
|
25
|
-
/** The desktop's side: show the code and ask whether the phone shows the same */
|
|
26
|
-
| {
|
|
27
|
-
readonly kind: 'compare';
|
|
28
|
-
readonly code: string;
|
|
29
|
-
readonly same: () => void;
|
|
30
|
-
readonly different: () => void;
|
|
31
|
-
}
|
|
32
|
-
/** The desktop sealing the account; on the phone, signing in with what arrived */
|
|
33
|
-
| {
|
|
34
|
-
readonly kind: 'sending';
|
|
35
|
-
}
|
|
36
|
-
/** The phone's side: joining the spaces that came with the account, one at a time */
|
|
37
|
-
| {
|
|
38
|
-
readonly kind: 'joining';
|
|
39
|
-
readonly joined: number;
|
|
40
|
-
readonly total: number;
|
|
41
|
-
} | {
|
|
42
|
-
readonly kind: 'sent';
|
|
43
|
-
readonly spaces: number;
|
|
44
|
-
} | {
|
|
45
|
-
readonly kind: 'received';
|
|
46
|
-
readonly spaces: number;
|
|
47
|
-
} | {
|
|
48
|
-
readonly kind: 'failed';
|
|
49
|
-
readonly reason: string;
|
|
50
|
-
};
|
|
51
|
-
/** A pairing offer the desktop is currently making */
|
|
52
|
-
export interface PairingOffer {
|
|
53
|
-
/** The link the QR code encodes */
|
|
54
|
-
readonly url: string;
|
|
55
|
-
/** Stops listening. The link stops working for anyone still holding it. */
|
|
56
|
-
stop(): void;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Starts offering an account to a phone; the first relay goes in the link.
|
|
60
|
-
*
|
|
61
|
-
* One offer serves one phone: the first that commits is the only one answered.
|
|
62
|
-
* The code stops working after `ttlMs` if no phone has used it, and as soon as
|
|
63
|
-
* one has.
|
|
64
|
-
*/
|
|
65
|
-
export declare function offerToPhone(params: {
|
|
66
|
-
readonly seed: Uint8Array;
|
|
67
|
-
/**
|
|
68
|
-
* An invite to every space the account holds. Invites carry everything a
|
|
69
|
-
* peer needs to open a space, the key of a private one included.
|
|
70
|
-
*/
|
|
71
|
-
readonly invites: () => Promise<ReadonlyArray<string>>;
|
|
72
|
-
readonly relays: ReadonlyArray<string>;
|
|
73
|
-
readonly link: string;
|
|
74
|
-
readonly ttlMs?: number;
|
|
75
|
-
readonly transport?: (did: string) => PeerTransport;
|
|
76
|
-
}, onStage: (stage: PairingStage) => void): Promise<PairingOffer>;
|
|
77
|
-
/** The pairing link in this page's URL, if the phone arrived from a QR code. */
|
|
78
|
-
export declare function readPairingTicket(): PairingTicket | null;
|
|
79
|
-
/** Drops the pairing link from the address bar once it has been used. */
|
|
80
|
-
export declare function clearPairingTicket(): void;
|
|
81
|
-
/**
|
|
82
|
-
* The phone's side: meets the desktop, shows the code (`confirm`), and
|
|
83
|
-
* resolves with the account and its spaces once the person confirms on the
|
|
84
|
-
* computer.
|
|
85
|
-
* @throws When the desktop does not answer, the person says the codes differ,
|
|
86
|
-
* or what arrives is not a handover
|
|
87
|
-
*/
|
|
88
|
-
export declare function receiveFromDesktop(ticket: PairingTicket, onStage: (stage: PairingStage) => void, options?: {
|
|
89
|
-
/** How long to wait for the computer to answer at all. Default 60 s. */
|
|
90
|
-
readonly findTimeoutMs?: number;
|
|
91
|
-
/** How long the person has to compare the codes. Default 10 minutes. */
|
|
92
|
-
readonly confirmTimeoutMs?: number;
|
|
93
|
-
readonly transport?: (did: string) => PeerTransport;
|
|
94
|
-
/** Stops it: the phone leaves the room, and the promise rejects. */
|
|
95
|
-
readonly signal?: AbortSignal;
|
|
96
|
-
}): Promise<Handover>;
|
|
97
|
-
//# sourceMappingURL=pairing.d.ts.map
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,CAAC;IACpD,oEAAoE;IACpE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC1B,GACL,OAAO,CAAC,QAAQ,CAAC,CAsFnB"}
|
package/dist/session/pairing.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import { channelKeyPair, deriveChannel, PAIRING_CHANNEL } from '../identity/channel.js';
|
|
2
|
-
import { decodePairingTicket, encodePairingTicket, newPairingSecret, pairingCode, pairingCommitment, } from '../identity/pairing.js';
|
|
3
|
-
import { RECOVERY_SEED_BYTES } from '../identity/recovery-code.js';
|
|
4
|
-
import { base64UrlDecode, base64UrlEncode } from '../utils/encoding.js';
|
|
5
|
-
import { isObject } from '../utils/guards.js';
|
|
6
|
-
import { bytesField, meetOnChannel } from './channel-room.js';
|
|
7
|
-
/** Messages in a pairing room, in the order they are sent */
|
|
8
|
-
const COMMIT = 'pair:commit';
|
|
9
|
-
const KEY = 'pair:key';
|
|
10
|
-
const REVEAL = 'pair:reveal';
|
|
11
|
-
const HANDOVER = 'pair:handover';
|
|
12
|
-
const DONE = 'pair:done';
|
|
13
|
-
/** How long a code on screen works before a phone uses it. Default for `offerToPhone`. */
|
|
14
|
-
const OFFER_TTL_MS = 2 * 60_000;
|
|
15
|
-
const failure = (error, fallback) => ({
|
|
16
|
-
kind: 'failed',
|
|
17
|
-
reason: error instanceof Error ? error.message : fallback,
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* Starts offering an account to a phone; the first relay goes in the link.
|
|
21
|
-
*
|
|
22
|
-
* One offer serves one phone: the first that commits is the only one answered.
|
|
23
|
-
* The code stops working after `ttlMs` if no phone has used it, and as soon as
|
|
24
|
-
* one has.
|
|
25
|
-
*/
|
|
26
|
-
export async function offerToPhone(params, onStage) {
|
|
27
|
-
const { seed, relays } = params;
|
|
28
|
-
const relay = relays[0];
|
|
29
|
-
if (!relay && !params.transport)
|
|
30
|
-
throw new Error('Pairing needs a relay, and none is configured.');
|
|
31
|
-
const secret = newPairingSecret();
|
|
32
|
-
const ticket = { v: 2, secret: base64UrlEncode(secret), relay: relay ?? '' };
|
|
33
|
-
const url = `${params.link}#pair=${encodePairingTicket(ticket)}`;
|
|
34
|
-
const room = await meetOnChannel(PAIRING_CHANNEL, { relays, transport: params.transport }, secret);
|
|
35
|
-
const mine = await channelKeyPair();
|
|
36
|
-
let phone = null;
|
|
37
|
-
let channel = null;
|
|
38
|
-
let settled = false;
|
|
39
|
-
const finish = (stage) => {
|
|
40
|
-
if (settled)
|
|
41
|
-
return;
|
|
42
|
-
settled = true;
|
|
43
|
-
globalThis.clearTimeout(expiry);
|
|
44
|
-
room.leave();
|
|
45
|
-
onStage(stage);
|
|
46
|
-
};
|
|
47
|
-
const expiry = globalThis.setTimeout(() => finish({ kind: 'failed', reason: 'The code expired. Show a new one.' }), params.ttlMs ?? OFFER_TTL_MS);
|
|
48
|
-
const handOver = async (peer, open) => {
|
|
49
|
-
if (settled)
|
|
50
|
-
return;
|
|
51
|
-
onStage({ kind: 'sending' });
|
|
52
|
-
try {
|
|
53
|
-
const spaces = await params.invites();
|
|
54
|
-
await room.seal(peer, HANDOVER, open, { seed: base64UrlEncode(seed), spaces });
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
finish(failure(error, 'Handover failed'));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
/** The first phone to commit spends the code: nobody after it is answered */
|
|
61
|
-
const onCommit = (message) => {
|
|
62
|
-
const commit = bytesField(message, 'commit');
|
|
63
|
-
if (!commit)
|
|
64
|
-
return;
|
|
65
|
-
phone = { peer: message.from, commit: base64UrlEncode(commit) };
|
|
66
|
-
globalThis.clearTimeout(expiry);
|
|
67
|
-
room.send(message.from, KEY, { key: base64UrlEncode(mine.point) });
|
|
68
|
-
};
|
|
69
|
-
const onReveal = async (message, { peer, commit }) => {
|
|
70
|
-
const point = bytesField(message, 'key');
|
|
71
|
-
if (!point || (await pairingCommitment(point)) !== commit) {
|
|
72
|
-
finish({ kind: 'failed', reason: 'The phone did not pair cleanly. Show a new code.' });
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
try {
|
|
76
|
-
const open = await deriveChannel({
|
|
77
|
-
kind: PAIRING_CHANNEL,
|
|
78
|
-
secret,
|
|
79
|
-
privateKey: mine.privateKey,
|
|
80
|
-
offer: mine.point,
|
|
81
|
-
join: point,
|
|
82
|
-
side: 'offer',
|
|
83
|
-
});
|
|
84
|
-
channel = open;
|
|
85
|
-
onStage({
|
|
86
|
-
kind: 'compare',
|
|
87
|
-
code: await pairingCode(open),
|
|
88
|
-
same: () => void handOver(peer, open),
|
|
89
|
-
different: () => finish({
|
|
90
|
-
kind: 'failed',
|
|
91
|
-
reason: 'The codes did not match, so nothing was sent. Show a new code to try again.',
|
|
92
|
-
}),
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
finish(failure(error, 'The phone did not pair cleanly.'));
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const onDone = async (message, open) => {
|
|
100
|
-
const said = await room.open(message, open);
|
|
101
|
-
if (isObject(said) && typeof said.spaces === 'number')
|
|
102
|
-
finish({ kind: 'sent', spaces: said.spaces });
|
|
103
|
-
};
|
|
104
|
-
room.net.on('message', (message) => {
|
|
105
|
-
if (settled)
|
|
106
|
-
return;
|
|
107
|
-
const fromPhone = phone !== null && message.from === phone.peer;
|
|
108
|
-
if (message.type === COMMIT && !phone)
|
|
109
|
-
onCommit(message);
|
|
110
|
-
else if (message.type === REVEAL && phone && fromPhone && !channel)
|
|
111
|
-
void onReveal(message, phone);
|
|
112
|
-
else if (message.type === DONE && channel && fromPhone)
|
|
113
|
-
void onDone(message, channel);
|
|
114
|
-
});
|
|
115
|
-
room.net.on('error', () => {
|
|
116
|
-
if (!room.net.isConnected())
|
|
117
|
-
finish({ kind: 'failed', reason: 'Could not reach the relay from this page.' });
|
|
118
|
-
});
|
|
119
|
-
onStage({ kind: 'waiting' });
|
|
120
|
-
await room.net.connect();
|
|
121
|
-
return {
|
|
122
|
-
url,
|
|
123
|
-
stop: () => {
|
|
124
|
-
settled = true;
|
|
125
|
-
globalThis.clearTimeout(expiry);
|
|
126
|
-
room.net.disconnect();
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/** The pairing link in this page's URL, if the phone arrived from a QR code. */
|
|
131
|
-
export function readPairingTicket() {
|
|
132
|
-
const match = /[#&]pair=([^&]+)/.exec(globalThis.location?.hash ?? '');
|
|
133
|
-
if (!match?.[1])
|
|
134
|
-
return null;
|
|
135
|
-
try {
|
|
136
|
-
return decodePairingTicket(match[1]);
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/** Drops the pairing link from the address bar once it has been used. */
|
|
143
|
-
export function clearPairingTicket() {
|
|
144
|
-
if (!globalThis.location || !globalThis.history)
|
|
145
|
-
return;
|
|
146
|
-
globalThis.history.replaceState(null, '', globalThis.location.pathname + globalThis.location.search);
|
|
147
|
-
}
|
|
148
|
-
function readHandover(value) {
|
|
149
|
-
if (!isObject(value) || typeof value.seed !== 'string')
|
|
150
|
-
return null;
|
|
151
|
-
if (!Array.isArray(value.spaces) || !value.spaces.every((s) => typeof s === 'string'))
|
|
152
|
-
return null;
|
|
153
|
-
try {
|
|
154
|
-
const seed = base64UrlDecode(value.seed);
|
|
155
|
-
return seed.length === RECOVERY_SEED_BYTES ? { seed, spaces: value.spaces } : null;
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The phone's side: meets the desktop, shows the code (`confirm`), and
|
|
163
|
-
* resolves with the account and its spaces once the person confirms on the
|
|
164
|
-
* computer.
|
|
165
|
-
* @throws When the desktop does not answer, the person says the codes differ,
|
|
166
|
-
* or what arrives is not a handover
|
|
167
|
-
*/
|
|
168
|
-
export async function receiveFromDesktop(ticket, onStage, options = {}) {
|
|
169
|
-
const secret = base64UrlDecode(ticket.secret);
|
|
170
|
-
// The relay in the ticket: the computer showing the code is on it, and the
|
|
171
|
-
// phone has no configuration.
|
|
172
|
-
const network = { relays: [ticket.relay], transport: options.transport };
|
|
173
|
-
const room = await meetOnChannel(PAIRING_CHANNEL, network, secret);
|
|
174
|
-
const mine = await channelKeyPair();
|
|
175
|
-
const commit = await pairingCommitment(mine.point);
|
|
176
|
-
return new Promise((resolve, reject) => {
|
|
177
|
-
let desktop = null;
|
|
178
|
-
let channel = null;
|
|
179
|
-
let settled = false;
|
|
180
|
-
let timer;
|
|
181
|
-
const settle = (done) => {
|
|
182
|
-
if (settled)
|
|
183
|
-
return;
|
|
184
|
-
settled = true;
|
|
185
|
-
globalThis.clearTimeout(timer);
|
|
186
|
-
room.leave();
|
|
187
|
-
done();
|
|
188
|
-
};
|
|
189
|
-
const fail = (reason) => settle(() => reject(new Error(reason)));
|
|
190
|
-
const wait = (ms, reason) => {
|
|
191
|
-
globalThis.clearTimeout(timer);
|
|
192
|
-
timer = globalThis.setTimeout(() => fail(reason), ms);
|
|
193
|
-
};
|
|
194
|
-
room.net.on('peer-connected', (peer) => {
|
|
195
|
-
if (!desktop)
|
|
196
|
-
room.send(peer.did, COMMIT, { commit });
|
|
197
|
-
});
|
|
198
|
-
const onKey = async (message) => {
|
|
199
|
-
const point = bytesField(message, 'key');
|
|
200
|
-
if (!point)
|
|
201
|
-
return;
|
|
202
|
-
try {
|
|
203
|
-
const open = await deriveChannel({
|
|
204
|
-
kind: PAIRING_CHANNEL,
|
|
205
|
-
secret,
|
|
206
|
-
privateKey: mine.privateKey,
|
|
207
|
-
offer: point,
|
|
208
|
-
join: mine.point,
|
|
209
|
-
side: 'join',
|
|
210
|
-
});
|
|
211
|
-
const code = await pairingCode(open);
|
|
212
|
-
desktop = message.from;
|
|
213
|
-
channel = open;
|
|
214
|
-
room.send(message.from, REVEAL, { key: base64UrlEncode(mine.point) });
|
|
215
|
-
onStage({ kind: 'confirm', code });
|
|
216
|
-
wait(options.confirmTimeoutMs ?? 10 * 60_000, 'Nobody confirmed the code on the computer. Show a new code to try again.');
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
fail(error instanceof Error ? error.message : 'The computer did not pair cleanly.');
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
const onHandover = async (message, open) => {
|
|
223
|
-
const handover = readHandover(await room.open(message, open));
|
|
224
|
-
// Stopped while it opened: the room is left, and the computer is told nothing.
|
|
225
|
-
if (settled) {
|
|
226
|
-
handover?.seed.fill(0);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (!handover)
|
|
230
|
-
return fail('That handover could not be read.');
|
|
231
|
-
// So the computer can say it arrived, and stop showing the code.
|
|
232
|
-
await room.seal(message.from, DONE, open, { spaces: handover.spaces.length });
|
|
233
|
-
settle(() => resolve(handover));
|
|
234
|
-
};
|
|
235
|
-
room.net.on('message', (message) => {
|
|
236
|
-
if (settled)
|
|
237
|
-
return;
|
|
238
|
-
if (message.type === KEY && !desktop)
|
|
239
|
-
void onKey(message);
|
|
240
|
-
else if (message.type === HANDOVER && channel && message.from === desktop)
|
|
241
|
-
void onHandover(message, channel);
|
|
242
|
-
});
|
|
243
|
-
if (options.signal?.aborted)
|
|
244
|
-
return fail('Pairing stopped.');
|
|
245
|
-
options.signal?.addEventListener('abort', () => fail('Pairing stopped.'), { once: true });
|
|
246
|
-
onStage({ kind: 'waiting' });
|
|
247
|
-
wait(options.findTimeoutMs ?? 60_000, 'The computer did not answer. Check the code is still showing, and that both devices are online.');
|
|
248
|
-
room.net.connect().catch(() => fail('Could not reach the relay from this phone.'));
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
//# sourceMappingURL=pairing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pairing.js","sourceRoot":"","sources":["../../src/session/pairing.ts"],"names":[],"mappings":"AAUA,OA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CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/session/places.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { AccountStore, AccountSummary } from '../identity/account-store.js';
|
|
2
|
-
import { type StoreFactory, type WorkerStores } from '../node/stores.js';
|
|
3
|
-
import type { DirectoryHandleLike } from '../storage/folder-adapter.js';
|
|
4
|
-
/** Where accounts and their data are kept */
|
|
5
|
-
export interface Place {
|
|
6
|
-
readonly kind: 'folder' | 'browser';
|
|
7
|
-
readonly store: AccountStore;
|
|
8
|
-
/** The folder, when there is one — for its name, and for opening stores */
|
|
9
|
-
readonly directory: DirectoryHandleLike | null;
|
|
10
|
-
}
|
|
11
|
-
/** What a pod holds, for deciding what to do before switching to it */
|
|
12
|
-
export interface PodContents {
|
|
13
|
-
/** This account's copy in the pod, when it has one */
|
|
14
|
-
readonly account: AccountSummary | null;
|
|
15
|
-
/** Other accounts in the pod — never touched by a move */
|
|
16
|
-
readonly others: number;
|
|
17
|
-
/** It is the pod already in use */
|
|
18
|
-
readonly same: boolean;
|
|
19
|
-
}
|
|
20
|
-
/** Accounts kept in this browser. Always available; never shared with another site. */
|
|
21
|
-
export declare function browserPlace(): Promise<Place>;
|
|
22
|
-
/**
|
|
23
|
-
* Asks for a pod without switching to it — so a signed-in person can be asked
|
|
24
|
-
* what should happen to their data first. Must be called from a click.
|
|
25
|
-
*/
|
|
26
|
-
export declare function pickPod(): Promise<Place>;
|
|
27
|
-
/** Remembers a pod as the one this site opens next time. */
|
|
28
|
-
export declare function rememberPod(pod: Place): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Re-opens the pod this site used last.
|
|
31
|
-
*
|
|
32
|
-
* @param request Whether to prompt for permission. Needs a click when true; use
|
|
33
|
-
* false on page load to find out whether a button has to be shown.
|
|
34
|
-
* @returns The pod, or null when there is none or access was declined
|
|
35
|
-
*/
|
|
36
|
-
export declare function recallPod(request: boolean): Promise<Place | null>;
|
|
37
|
-
/**
|
|
38
|
-
* The name of the pod this site used last, when it needs a click to open
|
|
39
|
-
* again (the browser keeps no permission between visits unless asked to).
|
|
40
|
-
*/
|
|
41
|
-
export declare function podToReopen(): Promise<string | null>;
|
|
42
|
-
/** Stops using the pod. Nothing in it is touched. */
|
|
43
|
-
export declare function forgetPod(): Promise<void>;
|
|
44
|
-
/** Every account in a place, most recently used first. */
|
|
45
|
-
export declare function listAccounts(place: Place): Promise<ReadonlyArray<AccountSummary>>;
|
|
46
|
-
/** What a pod holds of this account and others, and whether it is the one in use. */
|
|
47
|
-
export declare function inspectPod(pod: Place, current: Place, did: string): Promise<PodContents>;
|
|
48
|
-
/**
|
|
49
|
-
* The stores for one account.
|
|
50
|
-
*
|
|
51
|
-
* Paths are account-scoped either way, so two accounts in one browser never
|
|
52
|
-
* share a store, the same way two accounts in one folder never share a subtree.
|
|
53
|
-
* A pod's registry is sealed under the account's local key, so someone who copies the
|
|
54
|
-
* folder cannot read the private spaces in it.
|
|
55
|
-
*
|
|
56
|
-
* @param folder The unlocked pod and its local key, when the account lives in one
|
|
57
|
-
*/
|
|
58
|
-
export declare function storesFor(account: AccountSummary, folder?: {
|
|
59
|
-
readonly directory: DirectoryHandleLike;
|
|
60
|
-
readonly localKey: CryptoKey;
|
|
61
|
-
/** Where this device keeps a pod's own stores; default this origin's IndexedDB (`folderStores`) */
|
|
62
|
-
readonly local?: StoreFactory;
|
|
63
|
-
}): StoreFactory;
|
|
64
|
-
/** The same stores as {@link storesFor}, said as data, for a node in a worker to open */
|
|
65
|
-
export declare function describeStores(account: AccountSummary, folder?: {
|
|
66
|
-
readonly directory: DirectoryHandleLike;
|
|
67
|
-
readonly localKey: CryptoKey;
|
|
68
|
-
}): WorkerStores;
|
|
69
|
-
/** Deletes the IndexedDB databases an account kept in this browser, or every one whose name starts with a prefix. */
|
|
70
|
-
export declare function deleteBrowserData(account: AccountSummary | string): Promise<void>;
|
|
71
|
-
//# sourceMappingURL=places.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"places.d.ts","sourceRoot":"","sources":["../../src/session/places.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAQjF,OAAO,EAA8B,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE,6CAA6C;AAC7C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;CAChD;AAED,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IACxC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mCAAmC;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,uFAAuF;AACvF,wBAAsB,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,CAEnD;AAOD;;;GAGG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAE9C;AAED,4DAA4D;AAC5D,wBAAsB,WAAW,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAKvE;AAED;;;GAGG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAK1D;AAED,qDAAqD;AACrD,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED,0DAA0D;AAC1D,wBAAsB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAEvF;AAED,qFAAqF;AACrF,wBAAsB,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAO9F;AAOD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,cAAc,EACvB,MAAM,CAAC,EAAE;IACP,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,mGAAmG;IACnG,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;CAC/B,GACA,YAAY,CAQd;AAED,yFAAyF;AACzF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,cAAc,EACvB,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,GACjF,YAAY,CAId;AAED,qHAAqH;AACrH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOvF"}
|
package/dist/session/places.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module session/places
|
|
3
|
-
* Where accounts and their data are kept: a pod, or this browser.
|
|
4
|
-
*
|
|
5
|
-
* Two questions a sign-in flow keeps apart:
|
|
6
|
-
*
|
|
7
|
-
* - **Where does my data live?** A folder you picked (a *pod*), or this
|
|
8
|
-
* browser. That is a place.
|
|
9
|
-
* - **Who am I?** An account in that place. A place can hold several.
|
|
10
|
-
*/
|
|
11
|
-
import { createBrowserAccountStore, createFolderAccountStore } from '../identity/account-store.js';
|
|
12
|
-
import { forgetDataFolder, ensureFolderPermission, pickDataFolder, recallDataFolder, rememberDataFolder, } from '../storage/directory-access.js';
|
|
13
|
-
import { folderStores, workerStores } from '../node/stores.js';
|
|
14
|
-
/** Accounts kept in this browser. Always available; never shared with another site. */
|
|
15
|
-
export async function browserPlace() {
|
|
16
|
-
return { kind: 'browser', store: await createBrowserAccountStore(), directory: null };
|
|
17
|
-
}
|
|
18
|
-
/** Wraps a folder as a place. */
|
|
19
|
-
function folderPlace(directory) {
|
|
20
|
-
return { kind: 'folder', store: createFolderAccountStore(directory), directory };
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Asks for a pod without switching to it — so a signed-in person can be asked
|
|
24
|
-
* what should happen to their data first. Must be called from a click.
|
|
25
|
-
*/
|
|
26
|
-
export async function pickPod() {
|
|
27
|
-
return folderPlace(await pickDataFolder({ id: 'minca-pod' }));
|
|
28
|
-
}
|
|
29
|
-
/** Remembers a pod as the one this site opens next time. */
|
|
30
|
-
export async function rememberPod(pod) {
|
|
31
|
-
if (!pod.directory)
|
|
32
|
-
throw new Error('That is not a folder.');
|
|
33
|
-
await rememberDataFolder(pod.directory);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Re-opens the pod this site used last.
|
|
37
|
-
*
|
|
38
|
-
* @param request Whether to prompt for permission. Needs a click when true; use
|
|
39
|
-
* false on page load to find out whether a button has to be shown.
|
|
40
|
-
* @returns The pod, or null when there is none or access was declined
|
|
41
|
-
*/
|
|
42
|
-
export async function recallPod(request) {
|
|
43
|
-
const directory = await recallDataFolder();
|
|
44
|
-
if (!directory)
|
|
45
|
-
return null;
|
|
46
|
-
if (!(await ensureFolderPermission(directory, { request })))
|
|
47
|
-
return null;
|
|
48
|
-
return folderPlace(directory);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The name of the pod this site used last, when it needs a click to open
|
|
52
|
-
* again (the browser keeps no permission between visits unless asked to).
|
|
53
|
-
*/
|
|
54
|
-
export async function podToReopen() {
|
|
55
|
-
const directory = await recallDataFolder();
|
|
56
|
-
if (!directory)
|
|
57
|
-
return null;
|
|
58
|
-
if (await ensureFolderPermission(directory, { request: false }))
|
|
59
|
-
return null;
|
|
60
|
-
return directory.name;
|
|
61
|
-
}
|
|
62
|
-
/** Stops using the pod. Nothing in it is touched. */
|
|
63
|
-
export async function forgetPod() {
|
|
64
|
-
await forgetDataFolder();
|
|
65
|
-
}
|
|
66
|
-
/** Every account in a place, most recently used first. */
|
|
67
|
-
export async function listAccounts(place) {
|
|
68
|
-
return place.store.list();
|
|
69
|
-
}
|
|
70
|
-
/** What a pod holds of this account and others, and whether it is the one in use. */
|
|
71
|
-
export async function inspectPod(pod, current, did) {
|
|
72
|
-
const accounts = await listAccounts(pod);
|
|
73
|
-
return {
|
|
74
|
-
account: accounts.find((account) => account.did === did) ?? null,
|
|
75
|
-
others: accounts.filter((account) => account.did !== did).length,
|
|
76
|
-
same: current.kind === 'folder' && (await sameFolder(pod.directory, current.directory)),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
async function sameFolder(a, b) {
|
|
80
|
-
if (!a || !b || !canCompare(a))
|
|
81
|
-
return false;
|
|
82
|
-
return (await a.isSameEntry(b).catch(() => false)) === true;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* The stores for one account.
|
|
86
|
-
*
|
|
87
|
-
* Paths are account-scoped either way, so two accounts in one browser never
|
|
88
|
-
* share a store, the same way two accounts in one folder never share a subtree.
|
|
89
|
-
* A pod's registry is sealed under the account's local key, so someone who copies the
|
|
90
|
-
* folder cannot read the private spaces in it.
|
|
91
|
-
*
|
|
92
|
-
* @param folder The unlocked pod and its local key, when the account lives in one
|
|
93
|
-
*/
|
|
94
|
-
export function storesFor(account, folder) {
|
|
95
|
-
return folder?.local
|
|
96
|
-
? folderStores(folder.directory, {
|
|
97
|
-
basePath: account.dataPath,
|
|
98
|
-
localKey: folder.localKey,
|
|
99
|
-
local: folder.local,
|
|
100
|
-
})
|
|
101
|
-
: workerStores(describeStores(account, folder));
|
|
102
|
-
}
|
|
103
|
-
/** The same stores as {@link storesFor}, said as data, for a node in a worker to open */
|
|
104
|
-
export function describeStores(account, folder) {
|
|
105
|
-
return folder
|
|
106
|
-
? { directory: folder.directory, basePath: account.dataPath, localKey: folder.localKey }
|
|
107
|
-
: { indexedDB: databaseName(account) };
|
|
108
|
-
}
|
|
109
|
-
/** Deletes the IndexedDB databases an account kept in this browser, or every one whose name starts with a prefix. */
|
|
110
|
-
export async function deleteBrowserData(account) {
|
|
111
|
-
const prefix = typeof account === 'string' ? account : databaseName(account);
|
|
112
|
-
const databases = (await globalThis.indexedDB?.databases?.()) ?? [];
|
|
113
|
-
const names = databases
|
|
114
|
-
.map((db) => db.name)
|
|
115
|
-
.filter((name) => name?.startsWith(prefix) === true);
|
|
116
|
-
await Promise.all(names.map(deleteDatabase));
|
|
117
|
-
}
|
|
118
|
-
const databaseName = (account) => `minca:${account.dataPath.replace(/\//g, ':')}`;
|
|
119
|
-
/** Deletes one database, settling however the browser answers */
|
|
120
|
-
function deleteDatabase(name) {
|
|
121
|
-
return new Promise((resolve) => {
|
|
122
|
-
const request = globalThis.indexedDB.deleteDatabase(name);
|
|
123
|
-
request.onsuccess = request.onerror = request.onblocked = () => resolve();
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
/** `FileSystemHandle.isSameEntry`, which not every handle a test or an older browser gives has */
|
|
127
|
-
function canCompare(handle) {
|
|
128
|
-
return 'isSameEntry' in handle && typeof handle.isSameEntry === 'function';
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=places.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"places.js","sourceRoot":"","sources":["../../src/session/places.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE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AAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;IACvE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,OAAuB,EAAE,EAAE,CAAC,SAAS,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;AAElG,iEAAiE;AACjE,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC1D,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC;AAED,kGAAkG;AAClG,SAAS,UAAU,CAAC,MAAc;IAChC,OAAO,aAAa,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,WAAW,KAAK,UAAU,CAAC;AAC7E,CAAC"}
|
package/dist/session/popup.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module session/popup
|
|
3
|
-
* Where a window opened over a page goes, as sign-in windows do: its size, and
|
|
4
|
-
* the middle of the browser window it was opened from. Given a size alone, a
|
|
5
|
-
* browser puts it wherever it likes, often in the screen's top left corner.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* The features for `window.open` that make a popup of this size, centred on the
|
|
9
|
-
* window it opens from. Off a browser, where there is no window to centre on,
|
|
10
|
-
* just the size.
|
|
11
|
-
*/
|
|
12
|
-
export declare function popupFeatures(width: number, height: number): string;
|
|
13
|
-
//# sourceMappingURL=popup.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"popup.d.ts","sourceRoot":"","sources":["../../src/session/popup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAUnE"}
|
package/dist/session/popup.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module session/popup
|
|
3
|
-
* Where a window opened over a page goes, as sign-in windows do: its size, and
|
|
4
|
-
* the middle of the browser window it was opened from. Given a size alone, a
|
|
5
|
-
* browser puts it wherever it likes, often in the screen's top left corner.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* The features for `window.open` that make a popup of this size, centred on the
|
|
9
|
-
* window it opens from. Off a browser, where there is no window to centre on,
|
|
10
|
-
* just the size.
|
|
11
|
-
*/
|
|
12
|
-
export function popupFeatures(width, height) {
|
|
13
|
-
const size = `popup,width=${width},height=${height}`;
|
|
14
|
-
const { screenX, screenY, outerWidth, outerHeight } = globalThis;
|
|
15
|
-
if (![screenX, screenY, outerWidth, outerHeight].every((n) => typeof n === 'number' && Number.isFinite(n)))
|
|
16
|
-
return size;
|
|
17
|
-
// Not clamped at 0: a screen left of or above the main one has negative coordinates, and the
|
|
18
|
-
// browser keeps a window on its screen itself.
|
|
19
|
-
const left = Math.round(screenX + (outerWidth - width) / 2);
|
|
20
|
-
const top = Math.round(screenY + (outerHeight - height) / 2);
|
|
21
|
-
return `${size},left=${left},top=${top}`;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=popup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"popup.js","sourceRoot":"","sources":["../../src/session/popup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,MAAc;IACzD,MAAM,IAAI,GAAG,eAAe,KAAK,WAAW,MAAM,EAAE,CAAC;IACrD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;IACjE,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACxG,OAAO,IAAI,CAAC;IACd,6FAA6F;IAC7F,+CAA+C;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,GAAG,IAAI,SAAS,IAAI,QAAQ,GAAG,EAAE,CAAC;AAC3C,CAAC"}
|