-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpro.d.ts
More file actions
289 lines (259 loc) · 10.2 KB
/
Copy pathpro.d.ts
File metadata and controls
289 lines (259 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/// <reference path="../shared.d.ts" />;
declare module 'libsession_util_nodejs' {
type WithProRotatingEd25519PrivKey = { proRotatingEd25519PrivKey: string | null };
type WithProBackendPubkey = {
/**
* HexString
*/
proBackendPubkeyHex: string;
};
type ProStatus = 'ValidOrExpired' | 'Invalid';
type WithProProfileBitset = { proProfileBitset: bigint };
type WithProMessageBitset = { proMessageBitset: bigint };
/**
* base64 of the proof's revocation tag (historically the "gen index hash")
*/
type WithRevocationTag = { revocationTagB64: string };
type WithTicket = { ticket: number };
type WithUnixTsMs = {
unixTsMs: number;
};
type ProProof = WithRevocationTag & {
version: number;
/**
* HexString, 64 chars
*/
rotatingPubkeyHex: string;
expiryMs: number;
/**
* signature of the pro proof provided by the backend (hex)
* 64 bytes, 128 chars
*/
signatureHex: string;
};
type WithRotatingPrivKeyHex = {
/**
* 64 bytes, 128 chars
*/
rotatingPrivKeyHex: string;
};
type WithRotatingSeedHex = {
/**
* 32 bytes, 64 chars
*/
rotatingSeedHex: string;
};
type ProConfig = WithRotatingPrivKeyHex & {
proProof: ProProof;
};
type ProConfigSet = WithRotatingSeedHex & {
proProof: Omit<ProProof, 'rotatingPubkeyHex'>;
};
/**
* General (non per-provider) Pro URLs. These are libsession-owned constants (not translation data)
* still surfaced via LIBSESSION_PRO_URLS. Per-provider URLs are fetched via ProWrapper.providerUrls().
*/
export type ProBackendUrlsType = {
roadmap: string;
privacy_policy: string;
terms_of_service: string;
pro_access_not_found: string;
support_url: string;
};
/**
* Per-provider support/management URLs, looked up by provider slug via ProWrapper.providerUrls().
* `null` for a provider with no applicable URLs (unknown slug, or e.g. rangeproof).
*/
type ProviderUrls = {
refundPlatformUrl: string;
refundSupportUrl: string;
refundStatusUrl: string;
updateSubscriptionUrl: string;
cancelSubscriptionUrl: string;
};
type WithMasterPrivKeyHex = { masterPrivKeyHex: string };
/**
* A request to POST to the Session Pro backend. libsession owns the endpoint<->body pairing.
*/
type ProRequest = {
/**
* Endpoint path relative to the backend base URL, e.g. "generate_pro_proof".
*/
endpoint: string;
/**
* The value to send as the request's `Content-Type` header — relay verbatim; do not assume a format.
*/
contentType: string;
/**
* The opaque request payload to POST. Relay it untouched — do not parse, inspect, or modify it.
*/
body: string;
};
/**
* A parsed backend response (§5). Check `status === 'ok'` before using the typed payload.
*/
type WithProResponseHeader = {
/**
* Outcome category (closed set): 'ok' = success; 'fail' = client input / precondition rejected;
* 'error' = backend fault (retryable).
*/
status: 'ok' | 'fail' | 'error';
/**
* On non-'ok', a stable machine slug (spec §5.1) — map known ones to a localized string, fall back
* to `error` for an unrecognized slug. null on success.
*/
errorCode: string | null;
/**
* On non-'ok', an English diagnostic — NOT user-facing (show only when the slug has no i18n entry);
* always safe to log. null on success.
*/
error: string | null;
};
type GenerateProProofResponse = WithProResponseHeader & {
proof: ProProof;
/**
* Advisory account (subscription) expiry (ms) — grace-inclusive true entitlement end; present on
* a successful proof and on a `subscription_expired` failure (a past value), null otherwise.
* Distinct from the proof's own clamped expiry; unsigned / not-in-M — use for the "Pro until X"
* display and to refresh the cached access expiry (`E`), never for entitlement gating.
*/
accountExpiryMs: number | null;
};
type ProRevocationItem = WithRevocationTag & {
/**
* A matching proof is revoked once the client clock reaches this unix instant (milliseconds).
*/
effectiveMs: number;
};
type GetProRevocationsResponse = WithProResponseHeader & {
ticket: number;
/**
* Absolute unix instant (ms) at which to next poll the revocation list — already `now + retry_in`
* (libsession clamps the delay to a sane range), so callers can feed it straight to a next-run
* scheduler without any arithmetic.
*/
retryAtMs: number;
/**
* Duration (ms) to retain each item after first seeing it — applied per item as `seenAt + retainForMs`
* (memory-only aging); stays a duration since each item is seen at a different time.
*/
retainForMs: number;
items: Array<ProRevocationItem>;
};
/**
* A single Pro payment item. `status` is the numeric payment-status enum
* (0=Nil,1=Unredeemed,2=Redeemed,3=Expired,4=Revoked). provider/plan are opaque wire slugs.
*/
type ProPaymentItem = {
/**
* Opaque payment-status code slug: "unredeemed"/"redeemed"/"expired"/"revoked" (unknowns pass through).
*/
status: string;
/**
* Parsed billing period (libsession parses the closed `plan` grammar, §1). `planUnit` is
* one of "second"/"day"/"week"/"month"/"year"/"lifetime" (preserved as transmitted, not
* canonicalized). `planCount` is >= 1 for periodic units and 0 for "lifetime". Client localizes.
*/
planCount: number;
planUnit: string;
/**
* Provider slug, e.g. "google_play"/"app_store" (opaque).
*/
paymentProvider: string;
autoRenewing: boolean;
purchasedTsMs: number;
revokedTsMs: number;
redeemedTsMs: number;
expiryTsMs: number;
gracePeriodDurationMs: number;
platformRefundExpiryTsMs: number;
/**
* Opaque payment identifier (confidential).
*/
paymentId: string;
};
// NOTE: session-desktop persists this shape verbatim to local storage and reads it back cast to this
// type (getProStatusFromStorage). The glue and desktop ship in lockstep so a single build can't
// drift, but an older build's cache can. If you add a REQUIRED field here, the desktop read side needs
// a transition (drop the stale cache, or treat the field as optional there) — see the reminder at
// getProStatusFromStorage in session-desktop. Adding OPTIONAL fields is always safe.
type GetProStatusResponse = WithProResponseHeader & {
/**
* Opaque account-status code slug: "never"/"active"/"expired" (unknowns pass through).
*/
userStatus: string;
/**
* numeric error-report enum (0=Success,1=GenericError)
*/
errorReport: number;
autoRenewing: boolean;
expiryMs: number;
gracePeriodDurationMs: number;
/** The single most-recent payment, or null when the account has no payments. (Full history is a
* separate library-only query — not wired.) */
latestPayment: ProPaymentItem | null;
};
type ProWrapper = {
proFeaturesForMessage: (args: { codepointCount: number }) => WithProMessageBitset & {
status: 'SUCCESS' | 'EXCEEDS_CHARACTER_LIMIT';
};
proProofRequest: (
args: WithMasterPrivKeyHex & WithRotatingPrivKeyHex & WithUnixTsMs
) => ProRequest;
/**
* @param ticket: 64-bit monotonic revocation-list iteration. Set to 0 if unknown; otherwise use
* the latest known `ticket` from a prior GetProRevocationsResponse so the backend may omit an
* unchanged list.
*/
proRevocationsRequest: (args: WithTicket) => ProRequest;
proStatusRequest: (args: WithMasterPrivKeyHex & WithUnixTsMs) => ProRequest;
/**
* Parse a backend reply. The `body` is the RAW response bytes relayed from the network — the wire
* format is a libsession<->backend contract, so the client never parses it; libsession does, and
* returns these typed structs. (parseProProofResponse covers add-payment + generate-proof.)
*/
parseProProofResponse: (args: { body: Uint8Array }) => GenerateProProofResponse;
parseRevocationsResponse: (args: { body: Uint8Array }) => GetProRevocationsResponse;
parseProStatusResponse: (args: { body: Uint8Array }) => GetProStatusResponse;
/**
* Support/management URLs for a provider slug, or null if none apply.
*/
providerUrls: (args: { code: string }) => ProviderUrls | null;
/**
* The purchasable payment-provider slugs to surface to users (single source of truth in
* libsession; excludes non-purchasable providers like rangeproof). Order is not significant — the
* caller applies its own ordering and skips slugs it has no display translation for.
*/
visiblePlatforms: () => Array<string>;
};
export type ProActionsCalls = MakeWrapperActionCalls<ProWrapper>;
/**
* To be used inside the web worker only (calls are synchronous and won't work asynchronously)
*/
export class ProWrapperNode {
public static proFeaturesForMessage: ProWrapper['proFeaturesForMessage'];
public static proProofRequest: ProWrapper['proProofRequest'];
public static proRevocationsRequest: ProWrapper['proRevocationsRequest'];
public static proStatusRequest: ProWrapper['proStatusRequest'];
public static parseProProofResponse: ProWrapper['parseProProofResponse'];
public static parseRevocationsResponse: ProWrapper['parseRevocationsResponse'];
public static parseProStatusResponse: ProWrapper['parseProStatusResponse'];
public static providerUrls: ProWrapper['providerUrls'];
public static visiblePlatforms: ProWrapper['visiblePlatforms'];
}
/**
* Those actions are used internally for the web worker communication.
* You should never need to import them in Session directly
* You will need to add an entry here if you add a new function
*/
export type ProActionsType =
| MakeActionCall<ProWrapper, 'proFeaturesForMessage'>
| MakeActionCall<ProWrapper, 'proProofRequest'>
| MakeActionCall<ProWrapper, 'proRevocationsRequest'>
| MakeActionCall<ProWrapper, 'proStatusRequest'>
| MakeActionCall<ProWrapper, 'parseProProofResponse'>
| MakeActionCall<ProWrapper, 'parseRevocationsResponse'>
| MakeActionCall<ProWrapper, 'parseProStatusResponse'>
| MakeActionCall<ProWrapper, 'providerUrls'>
| MakeActionCall<ProWrapper, 'visiblePlatforms'>;
}