@celljs/ta-relay 4.18.0 → 4.19.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/esm/common/index.d.ts +3 -0
- package/esm/common/index.js +3 -0
- package/esm/common/relay-account-client.d.ts +138 -0
- package/esm/common/relay-account-client.js +338 -0
- package/esm/common/relay-account.d.ts +137 -0
- package/esm/common/relay-account.js +122 -0
- package/esm/common/relay-accounts.d.ts +107 -0
- package/esm/common/relay-accounts.js +393 -0
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/relay-server-accounts.d.ts +16 -0
- package/esm/node/relay-server-accounts.js +54 -0
- package/esm/node/relay-server.d.ts +5 -0
- package/esm/node/relay-server.js +7 -0
- package/esm/node/relay-store.d.ts +3 -1
- package/esm/node/relay-store.js +1 -0
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.js +3 -0
- package/lib/common/relay-account-client.d.ts +139 -0
- package/lib/common/relay-account-client.js +343 -0
- package/lib/common/relay-account.d.ts +138 -0
- package/lib/common/relay-account.js +125 -0
- package/lib/common/relay-accounts.d.ts +108 -0
- package/lib/common/relay-accounts.js +401 -0
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/relay-server-accounts.d.ts +17 -0
- package/lib/node/relay-server-accounts.js +58 -0
- package/lib/node/relay-server.d.ts +5 -0
- package/lib/node/relay-server.js +7 -0
- package/lib/node/relay-store.d.ts +3 -1
- package/lib/node/relay-store.js +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type RelayIdentity } from './relay-identity';
|
|
2
|
+
/** The account service of a relay or a gateway (docs/design/ta-account.md): the devices of one user, and their mail. */
|
|
3
|
+
export declare const RELAY_ACCOUNT_PATH = "/v1/account/";
|
|
4
|
+
/** Devices of an account at most, removed ones aside: `RELAY_ACCOUNT_MAX_DEVICES` of the service changes it. */
|
|
5
|
+
export declare const RELAY_ACCOUNT_MAX_DEVICES = 20;
|
|
6
|
+
/** A device seen within this is online: computers say they are there every minute. */
|
|
7
|
+
export declare const RELAY_ACCOUNT_ONLINE_MS: number;
|
|
8
|
+
export type AccountDeviceKind = 'computer' | 'phone' | 'browser';
|
|
9
|
+
export interface AccountName {
|
|
10
|
+
/** `github:<id>`, `iam:<user>`: the provider and who the user is there. */
|
|
11
|
+
id: string;
|
|
12
|
+
/** What the user is called there, to show. */
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
/** One device of the user, as the service keeps it: public keys only. */
|
|
16
|
+
export interface AccountDevice {
|
|
17
|
+
/** RelayIdentityUtil.id of its keys: its own keys, not the identity others know the user by. */
|
|
18
|
+
id: string;
|
|
19
|
+
kind: AccountDeviceKind;
|
|
20
|
+
name: string;
|
|
21
|
+
/** ECDSA P-256, raw base64url. */
|
|
22
|
+
sign: string;
|
|
23
|
+
/** ECDH P-256, raw base64url. */
|
|
24
|
+
box: string;
|
|
25
|
+
/** A computer: the relay it hangs on and its host id there. */
|
|
26
|
+
host?: {
|
|
27
|
+
relay: string;
|
|
28
|
+
id: string;
|
|
29
|
+
};
|
|
30
|
+
/** The first device of the account: in without anyone letting it in. */
|
|
31
|
+
root?: true;
|
|
32
|
+
/** Let in by a device of the account: its id and signature of AccountCircle.text. */
|
|
33
|
+
endorsement?: {
|
|
34
|
+
by: string;
|
|
35
|
+
signature: string;
|
|
36
|
+
};
|
|
37
|
+
/** Removed: by which device, with its signature of AccountCircle.removal, when. Kept, so that what it signed can still be told apart. */
|
|
38
|
+
removed?: {
|
|
39
|
+
by?: string;
|
|
40
|
+
signature?: string;
|
|
41
|
+
at: number;
|
|
42
|
+
};
|
|
43
|
+
addedAt: number;
|
|
44
|
+
seenAt: number;
|
|
45
|
+
}
|
|
46
|
+
export interface AccountRoster {
|
|
47
|
+
account: AccountName;
|
|
48
|
+
devices: AccountDevice[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* What a device is sent by another, sealed for it alone and signed by the sender: whom it trusts (`circle`), a way into a
|
|
52
|
+
* computer (`pairing`), or what a package of Ta says to the same package on another computer (`package`, by `topic`).
|
|
53
|
+
*/
|
|
54
|
+
export type AccountMailKind = 'circle' | 'pairing' | 'package';
|
|
55
|
+
export interface AccountMail {
|
|
56
|
+
from: string;
|
|
57
|
+
to: string;
|
|
58
|
+
kind: AccountMailKind;
|
|
59
|
+
/** Of a `package` mail: the package and what about, one mail kept of each. */
|
|
60
|
+
topic?: string;
|
|
61
|
+
sealed: string;
|
|
62
|
+
signature: string;
|
|
63
|
+
at: number;
|
|
64
|
+
}
|
|
65
|
+
/** What a device asks of its account, with its token (RelayAccounts). */
|
|
66
|
+
export interface AccountCalls {
|
|
67
|
+
roster(device?: string): Promise<AccountRoster>;
|
|
68
|
+
/** Adds the device, or says it is there again (its name, its host). */
|
|
69
|
+
join(device: Pick<AccountDevice, 'id' | 'kind' | 'name' | 'sign' | 'box' | 'host'>): Promise<AccountRoster>;
|
|
70
|
+
endorse(id: string, by: string, signature: string): Promise<AccountRoster>;
|
|
71
|
+
/** Removes `id`, said by `by` (a device let in, or `id` itself) with its signature of AccountCircle.removal. */
|
|
72
|
+
remove(id: string, by: string, signature: string): Promise<AccountRoster>;
|
|
73
|
+
send(mail: Omit<AccountMail, 'at'>): Promise<void>;
|
|
74
|
+
mail(to: string): Promise<AccountMail[]>;
|
|
75
|
+
signOut(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export type AccountCallName = keyof AccountCalls;
|
|
78
|
+
export declare const ACCOUNT_CALLS: readonly AccountCallName[];
|
|
79
|
+
/** A sign-in begun: open `url`, enter `code`; `handle` is what the device polls with. */
|
|
80
|
+
export interface AccountSignInStart {
|
|
81
|
+
handle: string;
|
|
82
|
+
code: string;
|
|
83
|
+
url: string;
|
|
84
|
+
interval: number;
|
|
85
|
+
expiresIn: number;
|
|
86
|
+
}
|
|
87
|
+
export type AccountSignInPoll = {
|
|
88
|
+
status: 'pending';
|
|
89
|
+
} | {
|
|
90
|
+
status: 'done';
|
|
91
|
+
token: string;
|
|
92
|
+
account: AccountName;
|
|
93
|
+
} | {
|
|
94
|
+
status: 'failed';
|
|
95
|
+
error: string;
|
|
96
|
+
};
|
|
97
|
+
/** What a device keeps of the devices it trusts (docs/design/ta-account.md 5). */
|
|
98
|
+
export interface AccountCircleState {
|
|
99
|
+
trusted: Record<string, {
|
|
100
|
+
sign: string;
|
|
101
|
+
box: string;
|
|
102
|
+
}>;
|
|
103
|
+
/** Removed once: never trusted again, whatever the service says later. */
|
|
104
|
+
removed: string[];
|
|
105
|
+
}
|
|
106
|
+
/** The trust of the devices of an account, kept by each device: the service holds keys, never says who to trust. */
|
|
107
|
+
export declare namespace AccountCircle {
|
|
108
|
+
/** What a device signs to let another in. */
|
|
109
|
+
function text(account: string, device: Pick<AccountDevice, 'id' | 'kind' | 'sign' | 'box'>): string;
|
|
110
|
+
/** Six digits both devices show, the user checks they are the same: they come from the keys of the new one. */
|
|
111
|
+
function code(device: Pick<AccountDevice, 'sign' | 'box'>): Promise<string>;
|
|
112
|
+
function live(device: AccountDevice): boolean;
|
|
113
|
+
/** In, by the service: the first one, or let in by someone. Who trusts it is each device's own. */
|
|
114
|
+
function admitted(device: AccountDevice): boolean;
|
|
115
|
+
/** Waiting for a device of the account to let it in. */
|
|
116
|
+
function waiting(device: AccountDevice): boolean;
|
|
117
|
+
/** A device trusting itself alone: the first one, or one not let in yet. */
|
|
118
|
+
function alone(self: Pick<AccountDevice, 'id' | 'sign' | 'box'>): AccountCircleState;
|
|
119
|
+
/**
|
|
120
|
+
* Who to trust now: those trusted before and not removed, and those a trusted device let in with a good signature,
|
|
121
|
+
* until no more. A device the service adds without a signature of one of them is never trusted.
|
|
122
|
+
*/
|
|
123
|
+
function update(state: AccountCircleState, roster: AccountRoster): Promise<AccountCircleState>;
|
|
124
|
+
function endorse(self: RelayIdentity, account: string, device: AccountDevice): Promise<string>;
|
|
125
|
+
/** What a device signs to remove one of the account, itself or another. */
|
|
126
|
+
function removal(account: string, id: string): string;
|
|
127
|
+
function remove(self: RelayIdentity, account: string, id: string): Promise<string>;
|
|
128
|
+
/** `value` sealed for `to` and signed by `self`: the service carries it, never reads it. */
|
|
129
|
+
function seal(self: RelayIdentity, to: Pick<AccountDevice, 'id' | 'box'>, kind: AccountMailKind, value: unknown, topic?: string): Promise<Omit<AccountMail, 'at'>>;
|
|
130
|
+
/** What `mail` holds, when it is for `self` and signed by `sender`; undefined otherwise. */
|
|
131
|
+
function open<T>(self: RelayIdentity, sender: {
|
|
132
|
+
sign: string;
|
|
133
|
+
box: string;
|
|
134
|
+
}, mail: AccountMail): Promise<T | undefined>;
|
|
135
|
+
/** Whether a device is online, from when it was last there. */
|
|
136
|
+
function online(device: AccountDevice, now?: number): boolean;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=relay-account.d.ts.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountCircle = exports.ACCOUNT_CALLS = exports.RELAY_ACCOUNT_ONLINE_MS = exports.RELAY_ACCOUNT_MAX_DEVICES = exports.RELAY_ACCOUNT_PATH = void 0;
|
|
4
|
+
const relay_bytes_1 = require("./relay-bytes");
|
|
5
|
+
const relay_identity_1 = require("./relay-identity");
|
|
6
|
+
/** The account service of a relay or a gateway (docs/design/ta-account.md): the devices of one user, and their mail. */
|
|
7
|
+
exports.RELAY_ACCOUNT_PATH = '/v1/account/';
|
|
8
|
+
/** Devices of an account at most, removed ones aside: `RELAY_ACCOUNT_MAX_DEVICES` of the service changes it. */
|
|
9
|
+
exports.RELAY_ACCOUNT_MAX_DEVICES = 20;
|
|
10
|
+
/** A device seen within this is online: computers say they are there every minute. */
|
|
11
|
+
exports.RELAY_ACCOUNT_ONLINE_MS = 3 * 60000;
|
|
12
|
+
exports.ACCOUNT_CALLS = ['roster', 'join', 'endorse', 'remove', 'send', 'mail', 'signOut'];
|
|
13
|
+
/** The trust of the devices of an account, kept by each device: the service holds keys, never says who to trust. */
|
|
14
|
+
var AccountCircle;
|
|
15
|
+
(function (AccountCircle) {
|
|
16
|
+
/** What a device signs to let another in. */
|
|
17
|
+
function text(account, device) {
|
|
18
|
+
return ['ta-account-device', account, device.id, device.kind, device.sign, device.box].join('\n');
|
|
19
|
+
}
|
|
20
|
+
AccountCircle.text = text;
|
|
21
|
+
/** Six digits both devices show, the user checks they are the same: they come from the keys of the new one. */
|
|
22
|
+
async function code(device) {
|
|
23
|
+
const digest = await relay_identity_1.RelayKeys.sha256(relay_bytes_1.RelayBytes.concat(relay_bytes_1.RelayBytes.fromBase64(device.sign), relay_bytes_1.RelayBytes.fromBase64(device.box)));
|
|
24
|
+
const number = ((digest[0] << 24) | (digest[1] << 16) | (digest[2] << 8) | digest[3]) >>> 0;
|
|
25
|
+
return String(number % 1000000).padStart(6, '0');
|
|
26
|
+
}
|
|
27
|
+
AccountCircle.code = code;
|
|
28
|
+
function live(device) {
|
|
29
|
+
return !device.removed;
|
|
30
|
+
}
|
|
31
|
+
AccountCircle.live = live;
|
|
32
|
+
/** In, by the service: the first one, or let in by someone. Who trusts it is each device's own. */
|
|
33
|
+
function admitted(device) {
|
|
34
|
+
return live(device) && (!!device.root || !!device.endorsement);
|
|
35
|
+
}
|
|
36
|
+
AccountCircle.admitted = admitted;
|
|
37
|
+
/** Waiting for a device of the account to let it in. */
|
|
38
|
+
function waiting(device) {
|
|
39
|
+
return live(device) && !device.root && !device.endorsement;
|
|
40
|
+
}
|
|
41
|
+
AccountCircle.waiting = waiting;
|
|
42
|
+
/** A device trusting itself alone: the first one, or one not let in yet. */
|
|
43
|
+
function alone(self) {
|
|
44
|
+
return { trusted: { [self.id]: { sign: self.sign, box: self.box } }, removed: [] };
|
|
45
|
+
}
|
|
46
|
+
AccountCircle.alone = alone;
|
|
47
|
+
/**
|
|
48
|
+
* Who to trust now: those trusted before and not removed, and those a trusted device let in with a good signature,
|
|
49
|
+
* until no more. A device the service adds without a signature of one of them is never trusted.
|
|
50
|
+
*/
|
|
51
|
+
async function update(state, roster) {
|
|
52
|
+
const removed = new Set(state.removed);
|
|
53
|
+
for (const device of roster.devices) {
|
|
54
|
+
if (device.removed && state.trusted[device.id]) {
|
|
55
|
+
removed.add(device.id);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const trusted = {};
|
|
59
|
+
for (const [id, keys] of Object.entries(state.trusted)) {
|
|
60
|
+
if (!removed.has(id)) {
|
|
61
|
+
trusted[id] = keys;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (let added = true; added;) {
|
|
65
|
+
added = false;
|
|
66
|
+
for (const device of roster.devices) {
|
|
67
|
+
if (trusted[device.id] || removed.has(device.id) || !live(device) || !device.endorsement || !trusted[device.endorsement.by]) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (await relay_identity_1.RelayIdentityUtil.verify(trusted[device.endorsement.by].sign, text(roster.account.id, device), device.endorsement.signature)) {
|
|
71
|
+
trusted[device.id] = { sign: device.sign, box: device.box };
|
|
72
|
+
added = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { trusted, removed: [...removed] };
|
|
77
|
+
}
|
|
78
|
+
AccountCircle.update = update;
|
|
79
|
+
function endorse(self, account, device) {
|
|
80
|
+
return relay_identity_1.RelayIdentityUtil.sign(self, text(account, device));
|
|
81
|
+
}
|
|
82
|
+
AccountCircle.endorse = endorse;
|
|
83
|
+
/** What a device signs to remove one of the account, itself or another. */
|
|
84
|
+
function removal(account, id) {
|
|
85
|
+
return ['ta-account-remove', account, id].join('\n');
|
|
86
|
+
}
|
|
87
|
+
AccountCircle.removal = removal;
|
|
88
|
+
function remove(self, account, id) {
|
|
89
|
+
return relay_identity_1.RelayIdentityUtil.sign(self, removal(account, id));
|
|
90
|
+
}
|
|
91
|
+
AccountCircle.remove = remove;
|
|
92
|
+
function mailText(mail) {
|
|
93
|
+
var _a;
|
|
94
|
+
return ['ta-account-mail', mail.from, mail.to, mail.kind, (_a = mail.topic) !== null && _a !== void 0 ? _a : '', mail.sealed].join('\n');
|
|
95
|
+
}
|
|
96
|
+
async function key(self, otherBox, from, to) {
|
|
97
|
+
return relay_identity_1.RelayKeys.aesKey(await relay_identity_1.RelayIdentityUtil.agree(self, otherBox, `${from}>${to}`, 'ta-account-mail'));
|
|
98
|
+
}
|
|
99
|
+
/** `value` sealed for `to` and signed by `self`: the service carries it, never reads it. */
|
|
100
|
+
async function seal(self, to, kind, value, topic) {
|
|
101
|
+
const sealed = await relay_identity_1.RelayKeys.seal(await key(self, to.box, self.id, to.id), JSON.stringify(value));
|
|
102
|
+
const mail = { from: self.id, to: to.id, kind, ...(topic ? { topic } : {}), sealed };
|
|
103
|
+
return { ...mail, signature: await relay_identity_1.RelayIdentityUtil.sign(self, mailText(mail)) };
|
|
104
|
+
}
|
|
105
|
+
AccountCircle.seal = seal;
|
|
106
|
+
/** What `mail` holds, when it is for `self` and signed by `sender`; undefined otherwise. */
|
|
107
|
+
async function open(self, sender, mail) {
|
|
108
|
+
if (mail.to !== self.id || !(await relay_identity_1.RelayIdentityUtil.verify(sender.sign, mailText(mail), mail.signature))) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(await relay_identity_1.RelayKeys.open(await key(self, sender.box, mail.from, mail.to), mail.sealed));
|
|
113
|
+
}
|
|
114
|
+
catch (_a) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
AccountCircle.open = open;
|
|
119
|
+
/** Whether a device is online, from when it was last there. */
|
|
120
|
+
function online(device, now = Date.now()) {
|
|
121
|
+
return live(device) && now - device.seenAt < exports.RELAY_ACCOUNT_ONLINE_MS;
|
|
122
|
+
}
|
|
123
|
+
AccountCircle.online = online;
|
|
124
|
+
})(AccountCircle || (exports.AccountCircle = AccountCircle = {}));
|
|
125
|
+
//# sourceMappingURL=relay-account.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type AccountCallName, type AccountDevice, type AccountMail, type AccountName, type AccountRoster, type AccountSignInPoll, type AccountSignInStart } from './relay-account';
|
|
2
|
+
import type { RelayHubStorage } from './relay-hub';
|
|
3
|
+
/** Refused, with the HTTP status it answers with. */
|
|
4
|
+
export declare class RelayAccountError extends Error {
|
|
5
|
+
readonly status: number;
|
|
6
|
+
constructor(status: number, message: string);
|
|
7
|
+
}
|
|
8
|
+
/** What the handler asks the book of one account: a call of a device, or a token to issue once a sign-in is done. */
|
|
9
|
+
export type RelayAccountBookRequest = {
|
|
10
|
+
op: 'issue';
|
|
11
|
+
account: AccountName;
|
|
12
|
+
hash: string;
|
|
13
|
+
} | {
|
|
14
|
+
op: AccountCallName;
|
|
15
|
+
args: unknown[];
|
|
16
|
+
hash?: string;
|
|
17
|
+
account?: AccountName;
|
|
18
|
+
max?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The devices and mail of one account, in the storage a Durable Object or `ta relay` gives it: public keys, sealed
|
|
22
|
+
* mail and hashes of tokens only (docs/design/ta-account.md 3).
|
|
23
|
+
*/
|
|
24
|
+
export declare class RelayAccountBook {
|
|
25
|
+
protected readonly storage: RelayHubStorage;
|
|
26
|
+
constructor(storage: RelayHubStorage);
|
|
27
|
+
handle(request: RelayAccountBookRequest, now?: number): Promise<unknown>;
|
|
28
|
+
protected issue(account: AccountName, hash: string, now: number): Promise<void>;
|
|
29
|
+
/** Whether anyone signed in to this account: a book of a forged token holds nothing. */
|
|
30
|
+
signedIn(): Promise<boolean>;
|
|
31
|
+
protected account(): Promise<AccountName>;
|
|
32
|
+
protected devices(): Promise<AccountDevice[]>;
|
|
33
|
+
protected device(id: string): Promise<AccountDevice>;
|
|
34
|
+
protected roster(seen: unknown, now: number): Promise<AccountRoster>;
|
|
35
|
+
protected join(input: AccountDevice, max: number, now: number): Promise<AccountRoster>;
|
|
36
|
+
protected endorse(id: string, by: string, signature: string, now: number): Promise<AccountRoster>;
|
|
37
|
+
/** By a device let in, or the device itself, with its signature: a token alone removes nothing. */
|
|
38
|
+
protected remove(id: string, by: string, signature: string, now: number): Promise<AccountRoster>;
|
|
39
|
+
protected send(mail: AccountMail, now: number): Promise<void>;
|
|
40
|
+
protected mail(to: string): Promise<AccountMail[]>;
|
|
41
|
+
}
|
|
42
|
+
/** A way to sign in to accounts of a relay, as the device flow of RFC 8628: the relay asks, the user says yes elsewhere. */
|
|
43
|
+
export interface RelayAccountProvider {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
start(): Promise<AccountSignInStart>;
|
|
47
|
+
poll(handle: string): Promise<AccountName | 'pending' | 'slowDown'>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* GitHub's device flow, for Ta's own OAuth app: a client id is public and the flow needs no secret. The device code is
|
|
51
|
+
* the handle: the device that began the sign-in holds it, as RFC 8628 has it; the relay keeps nothing of it.
|
|
52
|
+
*/
|
|
53
|
+
export declare class RelayGitHubAccounts implements RelayAccountProvider {
|
|
54
|
+
protected readonly clientId: string;
|
|
55
|
+
protected readonly site: string;
|
|
56
|
+
protected readonly api: string;
|
|
57
|
+
readonly id = "github";
|
|
58
|
+
readonly name = "GitHub";
|
|
59
|
+
static readonly CLIENT_ID = "Ov23lip46sRQDlDM1xt7";
|
|
60
|
+
constructor(clientId?: string, site?: string, api?: string);
|
|
61
|
+
protected post<T>(path: string, form: Record<string, string>): Promise<T>;
|
|
62
|
+
start(): Promise<AccountSignInStart>;
|
|
63
|
+
poll(handle: string): Promise<AccountName | 'pending' | 'slowDown'>;
|
|
64
|
+
}
|
|
65
|
+
export interface RelayAccountsOptions {
|
|
66
|
+
/** The book of an account, where its requests go one after another. */
|
|
67
|
+
book(account: string): {
|
|
68
|
+
handle(request: RelayAccountBookRequest): Promise<unknown>;
|
|
69
|
+
};
|
|
70
|
+
providers: RelayAccountProvider[];
|
|
71
|
+
/**
|
|
72
|
+
* A gateway: who the bearer is, by a token of its own sign-in. Without it the service issues tokens of its own, once
|
|
73
|
+
* a provider says who signed in.
|
|
74
|
+
*/
|
|
75
|
+
authenticate?(token: string): Promise<AccountName | undefined>;
|
|
76
|
+
maxDevices?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The account service over HTTP, the same in a Worker, `ta relay` and a gateway: `/v1/account/sign-in`,
|
|
80
|
+
* `/v1/account/sign-in/poll`, `/v1/account/providers` and `/v1/account/call`. Tokens go in a header, never a
|
|
81
|
+
* cookie, so any page may call it.
|
|
82
|
+
*/
|
|
83
|
+
export declare class RelayAccounts {
|
|
84
|
+
protected readonly options: RelayAccountsOptions;
|
|
85
|
+
constructor(options: RelayAccountsOptions);
|
|
86
|
+
static json(value: unknown, status?: number): Response;
|
|
87
|
+
/** `<account id, base64url>.<secret>`: the account it is of, and what only its holder knows. */
|
|
88
|
+
static token(account: string): string;
|
|
89
|
+
static accountOf(token: string): string | undefined;
|
|
90
|
+
handle(request: Request): Promise<Response>;
|
|
91
|
+
protected provider(id: unknown): RelayAccountProvider;
|
|
92
|
+
protected poll(id: unknown, handle: unknown): Promise<AccountSignInPoll>;
|
|
93
|
+
protected call(authorization: string, op: unknown, args: unknown): Promise<unknown>;
|
|
94
|
+
}
|
|
95
|
+
/** The books of a `ta relay` or a gateway, in one process: the requests of one account one after another. */
|
|
96
|
+
export declare class RelayAccountBooks {
|
|
97
|
+
protected readonly storage: (account: string) => RelayHubStorage;
|
|
98
|
+
/** Any token names an account: a book that holds none once its requests are done is not kept. */
|
|
99
|
+
protected readonly books: Map<string, {
|
|
100
|
+
book: RelayAccountBook;
|
|
101
|
+
chain: Promise<unknown>;
|
|
102
|
+
}>;
|
|
103
|
+
constructor(storage: (account: string) => RelayHubStorage);
|
|
104
|
+
book(account: string): {
|
|
105
|
+
handle(request: RelayAccountBookRequest): Promise<unknown>;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=relay-accounts.d.ts.map
|