@extenshi/pay 0.9.0 → 0.12.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 +138 -17
- package/dist/api/mock.d.ts +4 -0
- package/dist/api/mock.d.ts.map +1 -1
- package/dist/api/pay-api.d.ts +9 -4
- package/dist/api/pay-api.d.ts.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/extenshi-pay.d.ts +60 -5
- package/dist/core/extenshi-pay.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/storage.d.ts +6 -0
- package/dist/core/storage.d.ts.map +1 -1
- package/dist/core.d.mts +271 -26
- package/dist/core.d.ts +271 -26
- package/dist/core.js +589 -49
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +584 -50
- package/dist/core.mjs.map +1 -1
- package/dist/extenshi-pay-lite.js +577 -49
- package/dist/extenshi-pay-lite.js.map +1 -1
- package/dist/extenshi-pay-lite.min.js +3 -3
- package/dist/extenshi-pay-lite.min.js.map +1 -1
- package/dist/extenshi-pay-lite.mjs +577 -49
- package/dist/extenshi-pay-lite.mjs.map +1 -1
- package/dist/extenshi-pay.cjs.js +694 -61
- package/dist/extenshi-pay.cjs.js.map +1 -1
- package/dist/extenshi-pay.d.ts +11 -1
- package/dist/extenshi-pay.d.ts.map +1 -1
- package/dist/extenshi-pay.js +694 -61
- package/dist/extenshi-pay.js.map +1 -1
- package/dist/extenshi-pay.min.js +3 -3
- package/dist/extenshi-pay.min.js.map +1 -1
- package/dist/extenshi-pay.min.mjs +3 -3
- package/dist/extenshi-pay.min.mjs.map +1 -1
- package/dist/extenshi-pay.mjs +689 -62
- package/dist/extenshi-pay.mjs.map +1 -1
- package/dist/index.d.mts +288 -26
- package/dist/index.d.ts +288 -26
- package/dist/lite.d.mts +214 -13
- package/dist/lite.d.ts +214 -13
- package/dist/lite.d.ts.map +1 -1
- package/dist/payment/cloud-backup.d.ts +35 -0
- package/dist/payment/cloud-backup.d.ts.map +1 -0
- package/dist/payment/entitlement.d.ts +21 -5
- package/dist/payment/entitlement.d.ts.map +1 -1
- package/dist/payment/recovery.d.ts +4 -2
- package/dist/payment/recovery.d.ts.map +1 -1
- package/dist/payment/signature.d.ts +29 -3
- package/dist/payment/signature.d.ts.map +1 -1
- package/dist/payment/trial.d.ts +55 -0
- package/dist/payment/trial.d.ts.map +1 -0
- package/dist/paywall/i18n.d.ts +3 -0
- package/dist/paywall/i18n.d.ts.map +1 -1
- package/dist/paywall/renderer.d.ts +7 -0
- package/dist/paywall/renderer.d.ts.map +1 -1
- package/dist/paywall.d.mts +7 -0
- package/dist/paywall.d.ts +7 -0
- package/dist/paywall.js +54 -14
- package/dist/paywall.js.map +1 -1
- package/dist/paywall.mjs +54 -14
- package/dist/paywall.mjs.map +1 -1
- package/dist/types/config.d.ts +27 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/contract.d.ts +36 -0
- package/dist/types/contract.d.ts.map +1 -1
- package/dist/types/entitlement.d.ts +39 -1
- package/dist/types/entitlement.d.ts.map +1 -1
- package/dist/types/events.d.ts +5 -1
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/paywall.d.ts +10 -0
- package/dist/types/paywall.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/lite.d.ts
CHANGED
|
@@ -90,6 +90,16 @@ interface PayEntitlementItem {
|
|
|
90
90
|
expiresAt: string | null;
|
|
91
91
|
features: string[];
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The installation's free trial on the server clock: one per installation per application,
|
|
95
|
+
* started at its first license read. Absent when the application has no trial.
|
|
96
|
+
*/
|
|
97
|
+
interface PayTrial {
|
|
98
|
+
/** ISO time of the first license read while the application had a trial. */
|
|
99
|
+
startedAt: string;
|
|
100
|
+
/** ISO `startedAt` plus the application's current trial length. */
|
|
101
|
+
endsAt: string;
|
|
102
|
+
}
|
|
93
103
|
interface PayEntitlementPayload {
|
|
94
104
|
v: typeof PAY_CONTRACT_VERSION;
|
|
95
105
|
/** Signed application scope; prevents moving a grant to another application. */
|
|
@@ -98,6 +108,10 @@ interface PayEntitlementPayload {
|
|
|
98
108
|
entitlements: PayEntitlementItem[];
|
|
99
109
|
/** ISO timestamp the projection was computed at; the SDK uses it for cache age. */
|
|
100
110
|
issuedAt: string;
|
|
111
|
+
/** Optional: only for an application with a trial, and absent from older servers. */
|
|
112
|
+
trial?: PayTrial;
|
|
113
|
+
/** Optional: seconds of offline access after `issuedAt`; absent from older servers (48 hours). */
|
|
114
|
+
offlineSeconds?: number;
|
|
101
115
|
}
|
|
102
116
|
interface SignedEntitlement {
|
|
103
117
|
payload: PayEntitlementPayload;
|
|
@@ -126,12 +140,31 @@ interface PayRestoreSessionResponse {
|
|
|
126
140
|
expiresAt: string;
|
|
127
141
|
url: string;
|
|
128
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* `storage`: the buyer turns on the cloud copy of the extension's settings. The
|
|
145
|
+
* hosted page shows the storage disclosure; the claim records consent. Additive:
|
|
146
|
+
* a session without a purpose is a plain restore.
|
|
147
|
+
*/
|
|
148
|
+
declare const PAY_RESTORE_PURPOSES: readonly ["restore", "storage"];
|
|
149
|
+
type PayRestorePurpose = (typeof PAY_RESTORE_PURPOSES)[number];
|
|
150
|
+
/**
|
|
151
|
+
* Outcome for the cloud copy of settings, present in a complete claim only when
|
|
152
|
+
* the application offers it. A token is returned once; a retried claim rotates it.
|
|
153
|
+
*/
|
|
154
|
+
type PayStorageGrant = {
|
|
155
|
+
state: 'granted';
|
|
156
|
+
token: string;
|
|
157
|
+
} | {
|
|
158
|
+
state: 'unavailable';
|
|
159
|
+
reason: 'NO_CONSENT' | 'LICENSE_REQUIRED';
|
|
160
|
+
};
|
|
129
161
|
type PayRestoreClaimResponse = {
|
|
130
162
|
state: 'pending';
|
|
131
163
|
} | {
|
|
132
164
|
state: 'complete';
|
|
133
165
|
endUserRef: string;
|
|
134
166
|
entitlement: SignedEntitlement;
|
|
167
|
+
storage?: PayStorageGrant;
|
|
135
168
|
};
|
|
136
169
|
/** A project-scoped billing profile; provider identifiers are never exposed. */
|
|
137
170
|
interface PayPortalAccount {
|
|
@@ -218,6 +251,20 @@ interface MockData {
|
|
|
218
251
|
* paywall previews the checkbox). `null` previews a seller outside the EEA/UK.
|
|
219
252
|
*/
|
|
220
253
|
withdrawalWaiver?: PayWithdrawalWaiver | null;
|
|
254
|
+
/**
|
|
255
|
+
* Seller details for the paywall, the license panel and the waiver text.
|
|
256
|
+
* Omitted, the offer carries none (as from an older server); `null`
|
|
257
|
+
* previews a seller without public details, so the paywall disables purchase.
|
|
258
|
+
*/
|
|
259
|
+
seller?: PaySellerPublic | null;
|
|
260
|
+
/**
|
|
261
|
+
* Previews a server trial: `days` long, started at `startedAt` (default: when the mock is
|
|
262
|
+
* created). Omitted, the mock application has no trial.
|
|
263
|
+
*/
|
|
264
|
+
trial?: {
|
|
265
|
+
days: number;
|
|
266
|
+
startedAt?: string;
|
|
267
|
+
};
|
|
221
268
|
}
|
|
222
269
|
interface ExtenshiPayConfig {
|
|
223
270
|
/** `pk_ext_` + 32 hex characters, from the project's Monetization tab. */
|
|
@@ -239,6 +286,15 @@ interface ExtenshiPayConfig {
|
|
|
239
286
|
onReady?: () => void;
|
|
240
287
|
onError?: (error: ExtenshiPayError) => void;
|
|
241
288
|
theme?: ThemeConfig;
|
|
289
|
+
/** Days before the trial's end that `trial:ending` fires (default 2; 0 turns it off). */
|
|
290
|
+
trialEndingDays?: number;
|
|
291
|
+
/**
|
|
292
|
+
* Keep the trial's start date in `storage.sync` and send it back on license checks, so
|
|
293
|
+
* other devices on the same synced browser account share the trial (default true).
|
|
294
|
+
* Only the date is synced, never the installation id. A reinstall still restarts the
|
|
295
|
+
* trial: uninstalling clears `storage.sync`.
|
|
296
|
+
*/
|
|
297
|
+
syncTrialStart?: boolean;
|
|
242
298
|
}
|
|
243
299
|
interface ResolvedConfig {
|
|
244
300
|
publishableKey: string;
|
|
@@ -252,6 +308,8 @@ interface ResolvedConfig {
|
|
|
252
308
|
mock: boolean;
|
|
253
309
|
mockData: MockData | null;
|
|
254
310
|
theme: ThemeConfig;
|
|
311
|
+
trialEndingDays: number;
|
|
312
|
+
syncTrialStart: boolean;
|
|
255
313
|
}
|
|
256
314
|
|
|
257
315
|
type PaywallMode = 'modal' | 'inline' | 'sidebar' | 'fullscreen' | 'minimal';
|
|
@@ -319,6 +377,8 @@ interface Entitlement {
|
|
|
319
377
|
items: PayEntitlementItem[];
|
|
320
378
|
/** Union of `features[]` over active/grace items. */
|
|
321
379
|
features: string[];
|
|
380
|
+
/** Signed expiry of regional free access, independent of any purchase. */
|
|
381
|
+
regionalFreeUntil?: number;
|
|
322
382
|
/** True only when the Ed25519 signature was checked against the project's key. */
|
|
323
383
|
verified: boolean;
|
|
324
384
|
issuedAt: string | null;
|
|
@@ -328,8 +388,33 @@ interface Entitlement {
|
|
|
328
388
|
requiresOnlineCheck?: boolean;
|
|
329
389
|
/** Local offline-access deadline; null for mock mode or no cached license. */
|
|
330
390
|
offlineUntil?: number | null;
|
|
391
|
+
/**
|
|
392
|
+
* Set when the device clock differed from the server's by more than 5 minutes at the last
|
|
393
|
+
* license check. With `requiresOnlineCheck` on a connected device, ask the user to correct
|
|
394
|
+
* the date and time instead of asking them to connect.
|
|
395
|
+
*/
|
|
396
|
+
clockSkew?: ClockSkew | null;
|
|
331
397
|
source: EntitlementSource;
|
|
332
398
|
}
|
|
399
|
+
interface ClockSkew {
|
|
400
|
+
/** `ahead`: the device clock is later than the server's. */
|
|
401
|
+
direction: 'ahead' | 'behind';
|
|
402
|
+
/** Size of the difference in milliseconds. */
|
|
403
|
+
ms: number;
|
|
404
|
+
}
|
|
405
|
+
/** `getTrial()`: the free trial from the verified license, on the server's clock. */
|
|
406
|
+
interface TrialState {
|
|
407
|
+
/** True while the trial runs and the license was checked within the last 48 hours, as for paid access. */
|
|
408
|
+
active: boolean;
|
|
409
|
+
/** ISO time of the installation's first license check while the application had a trial. */
|
|
410
|
+
startedAt: string;
|
|
411
|
+
/** ISO time the trial ends. */
|
|
412
|
+
endsAt: string;
|
|
413
|
+
/** Whole days left, rounded up; 0 once the trial has ended. */
|
|
414
|
+
daysLeft: number;
|
|
415
|
+
/** The trial has days left but the license was not checked within 48 hours: connect to resume it. */
|
|
416
|
+
requiresOnlineCheck: boolean;
|
|
417
|
+
}
|
|
333
418
|
interface GetEntitlementOptions {
|
|
334
419
|
/** Skip the cache TTL and hit the network. */
|
|
335
420
|
force?: boolean;
|
|
@@ -385,10 +470,21 @@ interface RestoreOptions {
|
|
|
385
470
|
pollIntervalMs?: number;
|
|
386
471
|
signal?: AbortSignal;
|
|
387
472
|
openUrl?: (url: string) => void | Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* `storage` also turns on the cloud copy of settings: the hosted page shows
|
|
475
|
+
* the storage disclosure first. `enableCloudBackup()` passes it. Default: a plain restore.
|
|
476
|
+
*/
|
|
477
|
+
purpose?: PayRestorePurpose;
|
|
388
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* The cloud copy of settings after a completed restore: `on` (the token is
|
|
481
|
+
* stored), or why it is off. Absent when the application does not offer it.
|
|
482
|
+
*/
|
|
483
|
+
type CloudBackupState = 'on' | 'no_consent' | 'license_required';
|
|
389
484
|
type RestoreResult = {
|
|
390
485
|
state: 'complete';
|
|
391
486
|
entitlement: Entitlement;
|
|
487
|
+
cloudBackup?: CloudBackupState;
|
|
392
488
|
} | {
|
|
393
489
|
state: 'timeout' | 'expired' | 'canceled';
|
|
394
490
|
};
|
|
@@ -440,11 +536,15 @@ declare class MockTransport implements Transport {
|
|
|
440
536
|
private readonly checkoutEnabled;
|
|
441
537
|
private readonly claimAfterPolls;
|
|
442
538
|
private readonly withdrawalWaiver;
|
|
539
|
+
private readonly seller;
|
|
540
|
+
private trial;
|
|
443
541
|
readonly sessions: Map<string, MockSession>;
|
|
444
542
|
constructor(data?: MockData);
|
|
445
543
|
call<T>(procedure: string, _kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
|
|
446
544
|
/** Test/dev helpers. */
|
|
447
545
|
setEntitlements(items: PayEntitlementItem[]): void;
|
|
546
|
+
/** Previews a server trial of `days` from `startedAt` (default now); `null` removes it. */
|
|
547
|
+
setTrial(days: number | null, startedAt?: string): void;
|
|
448
548
|
cancelSession(sessionId: string): void;
|
|
449
549
|
expireSession(sessionId: string): void;
|
|
450
550
|
private offerResponse;
|
|
@@ -460,8 +560,12 @@ declare class PayApi {
|
|
|
460
560
|
private readonly transport;
|
|
461
561
|
private readonly publishableKey;
|
|
462
562
|
constructor(transport: Transport, publishableKey: string);
|
|
463
|
-
/**
|
|
464
|
-
|
|
563
|
+
/**
|
|
564
|
+
* `locale` opens the hosted recovery page (and its email) in the user's language.
|
|
565
|
+
* `purpose` is sent only for `storage`: a plain restore keeps the request older
|
|
566
|
+
* BFFs know, and their non-strict zod input strips the key anyway.
|
|
567
|
+
*/
|
|
568
|
+
createRestoreSession(claimChallenge: string, locale?: string | null, purpose?: PayRestorePurpose): Promise<PayRestoreSessionResponse>;
|
|
465
569
|
claimRestoreSession(sessionId: string, claimSecret: string): Promise<PayRestoreClaimResponse>;
|
|
466
570
|
getOffer(locale?: string | null): Promise<PayOfferResponse>;
|
|
467
571
|
/**
|
|
@@ -471,7 +575,8 @@ declare class PayApi {
|
|
|
471
575
|
*/
|
|
472
576
|
createCheckout(sku: string, endUserRef: string, locale?: string | null, withdrawalWaiver?: WithdrawalWaiverConsent): Promise<PayCheckoutSession>;
|
|
473
577
|
claimSession(sessionId: string, endUserRef: string): Promise<PayCheckoutClaim>;
|
|
474
|
-
|
|
578
|
+
/** `trialStartedHint`: the trial start kept in storage.sync; the server only lets it move a start earlier. */
|
|
579
|
+
getEntitlement(endUserRef: string, trialStartedHint?: string | null): Promise<SignedEntitlement>;
|
|
475
580
|
getPortalUrl(endUserRef: string, customerId?: string, locale?: string | null): Promise<PayPortalResponse>;
|
|
476
581
|
}
|
|
477
582
|
|
|
@@ -512,6 +617,10 @@ interface ExtenshiPayEvents {
|
|
|
512
617
|
sku: string;
|
|
513
618
|
sessionId: string;
|
|
514
619
|
};
|
|
620
|
+
/** Once per installation and trial, `trialEndingDays` before the end, while the user has no paid access. */
|
|
621
|
+
'trial:ending': TrialState;
|
|
622
|
+
/** Once per installation and trial, when it has ended, while the user has no paid access. */
|
|
623
|
+
'trial:ended': TrialState;
|
|
515
624
|
error: ExtenshiPayError;
|
|
516
625
|
}
|
|
517
626
|
type ExtenshiPayEventName = keyof ExtenshiPayEvents;
|
|
@@ -555,13 +664,36 @@ declare class CheckoutManager {
|
|
|
555
664
|
private settle;
|
|
556
665
|
}
|
|
557
666
|
|
|
667
|
+
/**
|
|
668
|
+
* Ed25519 verification of the entitlement projection.
|
|
669
|
+
*
|
|
670
|
+
* Tamper resistance, not DRM. Callers must deny access for both invalid and
|
|
671
|
+
* unverified envelopes outside explicit mocks.
|
|
672
|
+
*
|
|
673
|
+
* Which keys are trusted, in order (`PublicKeySource`, built in core/extenshi-pay.ts):
|
|
674
|
+
* 1. the key the server returned over HTTPS in this session;
|
|
675
|
+
* 2. the bundled `entitlementPublicKey`, when the developer configured one. It pins
|
|
676
|
+
* verification without a round-trip: a key read from extension storage is then never used;
|
|
677
|
+
* 3. without a bundled key, the server key saved in `storage.local` next to the
|
|
678
|
+
* license cache, so a restart with no network can still verify the cache.
|
|
679
|
+
* When none of them verifies an envelope the server is asked for its current key once
|
|
680
|
+
* (a rotated key), and that answer decides.
|
|
681
|
+
*/
|
|
682
|
+
|
|
683
|
+
interface PublicKeySource {
|
|
684
|
+
/** Keys trusted without a round-trip, in the order above. */
|
|
685
|
+
known(): Promise<string[]>;
|
|
686
|
+
/** The server's current key, fetched now; null when the server signs nothing. Rejects when unreachable. */
|
|
687
|
+
fetchCurrent(): Promise<string | null>;
|
|
688
|
+
}
|
|
689
|
+
|
|
558
690
|
/**
|
|
559
691
|
* Entitlement cache + refresh.
|
|
560
692
|
*
|
|
561
693
|
* The cached envelope is a cache OF the server projection, never a second
|
|
562
694
|
* source of truth: it is verified when stored and re-verified on load (once
|
|
563
695
|
* the project's public key is known), served without a round-trip while the
|
|
564
|
-
* TTL holds, served for
|
|
696
|
+
* TTL holds, served after signed issuance for the signed `offlineSeconds` (48 hours when absent) when the network is down, and expired
|
|
565
697
|
* locally by `expiresAt`. Background refresh polls at most every 15 minutes
|
|
566
698
|
* and backs off exponentially on errors.
|
|
567
699
|
*/
|
|
@@ -573,9 +705,13 @@ interface EntitlementManagerOptions {
|
|
|
573
705
|
cacheTtlMs: number;
|
|
574
706
|
source?: EntitlementSource;
|
|
575
707
|
getEndUserRef: () => Promise<string>;
|
|
576
|
-
/**
|
|
577
|
-
|
|
708
|
+
/** The trusted Ed25519 keys, in order, and how to ask the server for its current one. */
|
|
709
|
+
keys: PublicKeySource;
|
|
578
710
|
onChange?: (entitlement: Entitlement) => void;
|
|
711
|
+
/** After every accepted envelope, changed or not (the trial is not part of `onChange`). */
|
|
712
|
+
onAccepted?: () => void;
|
|
713
|
+
/** The synced trial start to send with a refresh; null when there is none. */
|
|
714
|
+
getTrialStartHint?: () => Promise<string | null>;
|
|
579
715
|
onError?: (error: ExtenshiPayError) => void;
|
|
580
716
|
now?: () => number;
|
|
581
717
|
}
|
|
@@ -583,6 +719,8 @@ declare class EntitlementManager {
|
|
|
583
719
|
private readonly options;
|
|
584
720
|
private held;
|
|
585
721
|
private inflight;
|
|
722
|
+
/** Device clock against the server's at the last license check; null within 5 minutes. */
|
|
723
|
+
private clockSkew;
|
|
586
724
|
private timer;
|
|
587
725
|
private refreshGeneration;
|
|
588
726
|
private deadlineTimer;
|
|
@@ -599,7 +737,11 @@ declare class EntitlementManager {
|
|
|
599
737
|
load(): Promise<Entitlement | null>;
|
|
600
738
|
/** Re-checks the loaded envelope against the project's key; discards it when the signature is invalid. */
|
|
601
739
|
reverify(): Promise<void>;
|
|
740
|
+
/** The key the held license was verified with; null when there is none or it is unverified. */
|
|
741
|
+
get verifiedKey(): string | null;
|
|
602
742
|
getCached(): Entitlement | null;
|
|
743
|
+
/** The server trial in the held license; null without one, or while the license is unverified. */
|
|
744
|
+
getTrial(): TrialState | null;
|
|
603
745
|
isFresh(): boolean;
|
|
604
746
|
get(options?: {
|
|
605
747
|
force?: boolean;
|
|
@@ -615,11 +757,13 @@ declare class EntitlementManager {
|
|
|
615
757
|
stopAutoRefresh(): void;
|
|
616
758
|
private scheduleDeadline;
|
|
617
759
|
private schedule;
|
|
618
|
-
private
|
|
760
|
+
private measureClockSkew;
|
|
619
761
|
private discard;
|
|
620
762
|
private fingerprint;
|
|
621
763
|
private notifyIfChanged;
|
|
622
764
|
private offlineDeadline;
|
|
765
|
+
/** The signed allowance of the held license, or 48 hours when it names none. */
|
|
766
|
+
private offlineAgeMs;
|
|
623
767
|
private snapshot;
|
|
624
768
|
}
|
|
625
769
|
|
|
@@ -632,6 +776,8 @@ interface RecoveryManagerOptions {
|
|
|
632
776
|
storage: StorageAdapter;
|
|
633
777
|
publishableKey: string;
|
|
634
778
|
onComplete: (endUserRef: string, envelope: SignedEntitlement) => Promise<Entitlement>;
|
|
779
|
+
/** Runs after `onComplete` accepted the entitlement, with the claim's storage grant (if any). */
|
|
780
|
+
onStorageGrant?: (grant: PayStorageGrant | undefined) => Promise<CloudBackupState | undefined>;
|
|
635
781
|
openUrl?: (url: string) => void | Promise<void>;
|
|
636
782
|
now?: () => number;
|
|
637
783
|
}
|
|
@@ -665,13 +811,17 @@ declare class EventEmitter<Events extends object> {
|
|
|
665
811
|
* extends it with `getOffer()` / `showPaywall()`.
|
|
666
812
|
*
|
|
667
813
|
* Data that leaves the extension: `publishableKey`, `endUserRef`, `sku`,
|
|
668
|
-
* `locale
|
|
669
|
-
*
|
|
814
|
+
* `locale`, checkout session IDs and, with a server trial, the trial start date
|
|
815
|
+
* the server issued (`trialStartedHint`, kept in storage.sync). Explicit recovery also sends its session ID,
|
|
816
|
+
* challenge and claim secret (POST body). Email stays on the hosted page. With cloud backup, the
|
|
817
|
+
* storage token goes only to `/v1/storage` (as a bearer), never in a message to a content script.
|
|
670
818
|
*/
|
|
671
819
|
|
|
672
820
|
/** Injection points for tests and unusual hosts. */
|
|
673
821
|
interface ExtenshiPayDeps {
|
|
674
822
|
storage?: StorageAdapter;
|
|
823
|
+
/** Where the trial start is synced (default `storage.sync`); null turns syncing off. */
|
|
824
|
+
syncStorage?: StorageAdapter | null;
|
|
675
825
|
/** Trusted extension-only storage; never share this adapter with content scripts. */
|
|
676
826
|
recoveryStorage?: StorageAdapter;
|
|
677
827
|
transport?: Transport;
|
|
@@ -680,7 +830,7 @@ interface ExtenshiPayDeps {
|
|
|
680
830
|
now?: () => number;
|
|
681
831
|
}
|
|
682
832
|
declare class ExtenshiPayLite {
|
|
683
|
-
static readonly version = "0.
|
|
833
|
+
static readonly version = "0.12.0";
|
|
684
834
|
protected readonly config: ResolvedConfig;
|
|
685
835
|
protected readonly emitter: EventEmitter<ExtenshiPayEvents>;
|
|
686
836
|
protected readonly storage: StorageAdapter;
|
|
@@ -688,11 +838,21 @@ declare class ExtenshiPayLite {
|
|
|
688
838
|
protected readonly entitlements: EntitlementManager;
|
|
689
839
|
protected readonly checkout: CheckoutManager;
|
|
690
840
|
protected readonly recovery: RecoveryManager;
|
|
841
|
+
private readonly backup;
|
|
842
|
+
/** `deps.openUrl`, for tabs the full SDK opens outside checkout and recovery. */
|
|
843
|
+
protected readonly openUrl: ((url: string) => void | Promise<void>) | undefined;
|
|
844
|
+
private readonly trial;
|
|
845
|
+
/** storage.sync for the trial start; null when off, in mock mode, or outside an extension. */
|
|
846
|
+
private readonly syncStorage;
|
|
691
847
|
private readonly now;
|
|
692
848
|
private endUserRef;
|
|
693
849
|
private endUserRefPromise;
|
|
694
850
|
private offer;
|
|
695
851
|
private offerInflight;
|
|
852
|
+
/** The signing key the server returned in this session; never one read from storage. */
|
|
853
|
+
private serverKey;
|
|
854
|
+
/** Trust order for license signatures; see payment/signature.ts. */
|
|
855
|
+
private readonly keys;
|
|
696
856
|
private readyPromise;
|
|
697
857
|
private destroyed;
|
|
698
858
|
constructor(config: ExtenshiPayConfig, deps?: ExtenshiPayDeps);
|
|
@@ -709,6 +869,13 @@ declare class ExtenshiPayLite {
|
|
|
709
869
|
getEndUserRef(): Promise<string>;
|
|
710
870
|
getCachedEntitlement(): Entitlement | null;
|
|
711
871
|
getEntitlement(options?: GetEntitlementOptions): Promise<Entitlement>;
|
|
872
|
+
/**
|
|
873
|
+
* The free trial the application set on the server, from the verified license, or null when
|
|
874
|
+
* there is none (or the license could not be verified yet). Answers offline from the cached
|
|
875
|
+
* license; like paid access, `active` needs a license check within 48 hours. `isPaid()` and
|
|
876
|
+
* `hasFeature()` do not include the trial: grant trial access with `(await getTrial())?.active`.
|
|
877
|
+
*/
|
|
878
|
+
getTrial(options?: GetEntitlementOptions): Promise<TrialState | null>;
|
|
712
879
|
/** True when any active/grace entitlement exists, or the given `sku` is active/grace. */
|
|
713
880
|
isPaid(sku?: string): Promise<boolean>;
|
|
714
881
|
hasFeature(feature: string): Promise<boolean>;
|
|
@@ -740,6 +907,23 @@ declare class ExtenshiPayLite {
|
|
|
740
907
|
openCheckout(sku: string, options?: CheckoutOptions): Promise<CheckoutResult>;
|
|
741
908
|
/** Opens email verification on the hosted page. No email is collected inside the extension. */
|
|
742
909
|
restorePurchase(options?: RestoreOptions): Promise<RestoreResult>;
|
|
910
|
+
/**
|
|
911
|
+
* Turns on the cloud copy of the extension's settings (`@extenshi/storage`): the
|
|
912
|
+
* hosted restore page shows the storage disclosure and the buyer confirms with
|
|
913
|
+
* the code from the purchase email. `cloudBackup` in the result says whether it is
|
|
914
|
+
* on. Buyers only; consent is recorded by the server.
|
|
915
|
+
*/
|
|
916
|
+
enableCloudBackup(options?: Omit<RestoreOptions, 'purpose'>): Promise<RestoreResult>;
|
|
917
|
+
/**
|
|
918
|
+
* The storage token for `ExtenshiStorage.create({ cloud: { getToken } })`, or null
|
|
919
|
+
* while cloud backup is off on this installation. Extension pages and background
|
|
920
|
+
* only: it rejects in a content script, and must never be sent to one.
|
|
921
|
+
*/
|
|
922
|
+
cloudBackupToken(): Promise<string | null>;
|
|
923
|
+
/** Turns cloud backup off on this installation: revokes its token. The cloud copy stays. */
|
|
924
|
+
disableCloudBackup(): Promise<void>;
|
|
925
|
+
/** Deletes the buyer's cloud copy and turns cloud backup off on every installation. */
|
|
926
|
+
deleteCloudBackup(): Promise<void>;
|
|
743
927
|
/** Read-only license view. Entitlements retain cache/signature/offline semantics. */
|
|
744
928
|
getLicenseSummary(options?: GetEntitlementOptions): Promise<LicenseSummary>;
|
|
745
929
|
/** Opens the provider's self-service portal; resolves null when the provider has none. */
|
|
@@ -753,12 +937,29 @@ declare class ExtenshiPayLite {
|
|
|
753
937
|
destroy(): void;
|
|
754
938
|
/** Offer + signing key. Public in the full SDK (`getOffer`), internal here. */
|
|
755
939
|
protected fetchOffer(force?: boolean): Promise<PayOfferResponse>;
|
|
756
|
-
private
|
|
940
|
+
private get serverKeyStorageKey();
|
|
941
|
+
private readSavedServerKey;
|
|
942
|
+
/**
|
|
943
|
+
* Keeps the server's key next to the license cache so a restart with no network can verify it.
|
|
944
|
+
* Not with a bundled key: that one already covers the restart, and storage stays untrusted.
|
|
945
|
+
*/
|
|
946
|
+
private rememberServerKey;
|
|
947
|
+
/**
|
|
948
|
+
* A license verified with the saved key alone is checked against the server once per start:
|
|
949
|
+
* when the server's key differs (rotation, or an edited storage) the license is fetched again,
|
|
950
|
+
* and dropped if it does not verify. Offline, the saved key stands until `offlineUntil`.
|
|
951
|
+
*/
|
|
952
|
+
private confirmSavedServerKey;
|
|
953
|
+
private get trialStartKey();
|
|
954
|
+
/** The synced trial start, or null (none, malformed, or storage.sync unavailable). */
|
|
955
|
+
private readTrialStartHint;
|
|
956
|
+
/** Syncs the verified trial start, keeping the earliest one seen. Never the installation id. */
|
|
957
|
+
private rememberTrialStart;
|
|
757
958
|
protected reportError(error: unknown): ExtenshiPayError;
|
|
758
959
|
}
|
|
759
960
|
|
|
760
961
|
/** Kept in sync with package.json by tests/unit/version.test.ts. */
|
|
761
|
-
declare const VERSION = "0.
|
|
962
|
+
declare const VERSION = "0.12.0";
|
|
762
963
|
|
|
763
964
|
export { ERROR_CODES, ExtenshiPayLite as ExtenshiPay, ExtenshiPayError, ExtenshiPayLite, MockTransport, PAY_WITHDRAWAL_WAIVER_VERSION, VERSION, ExtenshiPayLite as default };
|
|
764
|
-
export type { CheckoutOptions, CheckoutResult, CheckoutState, CustomerPortalOptions, Entitlement, EntitlementSource, ErrorCode, ExtenshiPayConfig, ExtenshiPayDeps, ExtenshiPayEventName, ExtenshiPayEvents, GetEntitlementOptions, LicenseSummary, MockData, PayEntitlementItem, PayEntitlementStatus, PayOfferDto, PayPortalAccount, PayPortalResponse, PaySellerPublic, PayWithdrawalWaiver, RequireFeatureOptions, RestoreOptions, RestoreResult, StorageAdapter, ThemeConfig, Transport, WithdrawalWaiverConsent };
|
|
965
|
+
export type { CheckoutOptions, CheckoutResult, CheckoutState, ClockSkew, CloudBackupState, CustomerPortalOptions, Entitlement, EntitlementSource, ErrorCode, ExtenshiPayConfig, ExtenshiPayDeps, ExtenshiPayEventName, ExtenshiPayEvents, GetEntitlementOptions, LicenseSummary, MockData, PayEntitlementItem, PayEntitlementStatus, PayOfferDto, PayPortalAccount, PayPortalResponse, PayRestorePurpose, PaySellerPublic, PayStorageGrant, PayWithdrawalWaiver, RequireFeatureOptions, RestoreOptions, RestoreResult, StorageAdapter, ThemeConfig, Transport, TrialState, WithdrawalWaiverConsent };
|
package/dist/lite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lite.d.ts","sourceRoot":"","sources":["../src/lite.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,YAA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,CAAA;AACjE,YAAY,EACX,eAAe,EACf,cAAc,EACd,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,QAAQ,EACR,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,WAAW,EACX,UAAU,EACV,uBAAuB,GACvB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,eAAe,eAAe,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloud copy of the extension's settings (`@extenshi/storage`). Pay owns the
|
|
3
|
+
* token: only a verified restore claim issues it; this module keeps it in the
|
|
4
|
+
* SDK's storage (`storage.local`) and revokes it. `@extenshi/storage` reads it
|
|
5
|
+
* through `cloudBackupToken()`. The token is never logged and never answered to
|
|
6
|
+
* a content script: route those calls to the background.
|
|
7
|
+
*/
|
|
8
|
+
import type { StorageAdapter } from '../core/storage.js';
|
|
9
|
+
import { type PayStorageGrant } from '../types/contract.js';
|
|
10
|
+
import type { CloudBackupState } from '../types/entitlement.js';
|
|
11
|
+
export interface CloudBackupOptions {
|
|
12
|
+
storage: StorageAdapter;
|
|
13
|
+
publishableKey: string;
|
|
14
|
+
apiUrl: string;
|
|
15
|
+
fetch?: typeof fetch;
|
|
16
|
+
/** Mock mode: forget the token locally, never call the network. */
|
|
17
|
+
mock?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class CloudBackup {
|
|
20
|
+
private readonly options;
|
|
21
|
+
private readonly fetchImpl;
|
|
22
|
+
constructor(options: CloudBackupOptions);
|
|
23
|
+
get storageKey(): string;
|
|
24
|
+
/** Stores or clears the token from a verified claim. Never throws: the licence is already restored. */
|
|
25
|
+
accept(grant: PayStorageGrant | undefined): Promise<CloudBackupState | undefined>;
|
|
26
|
+
token(): Promise<string | null>;
|
|
27
|
+
/** Revokes this installation's token. A token the server no longer knows (401) is forgotten too. */
|
|
28
|
+
disable(): Promise<void>;
|
|
29
|
+
/** Deletes the buyer's cloud copy and turns the backup off on every device. */
|
|
30
|
+
delete(): Promise<void>;
|
|
31
|
+
private assertTrustedContext;
|
|
32
|
+
private throwUnlessOk;
|
|
33
|
+
private request;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=cloud-backup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-backup.d.ts","sourceRoot":"","sources":["../../src/payment/cloud-backup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAM/D,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,cAAc,CAAA;IACvB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IACpB,mEAAmE;IACnE,IAAI,CAAC,EAAE,OAAO,CAAA;CACd;AAWD,qBAAa,WAAW;IAGX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;gBAEX,OAAO,EAAE,kBAAkB;IAIxD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,uGAAuG;IACjG,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAkBjF,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAMrC,oGAAoG;IAC9F,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAU9B,+EAA+E;IACzE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAuB7B,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,aAAa;YASP,OAAO;CAmBrB"}
|
|
@@ -4,18 +4,22 @@
|
|
|
4
4
|
* The cached envelope is a cache OF the server projection, never a second
|
|
5
5
|
* source of truth: it is verified when stored and re-verified on load (once
|
|
6
6
|
* the project's public key is known), served without a round-trip while the
|
|
7
|
-
* TTL holds, served for
|
|
7
|
+
* TTL holds, served after signed issuance for the signed `offlineSeconds` (48 hours when absent) when the network is down, and expired
|
|
8
8
|
* locally by `expiresAt`. Background refresh polls at most every 15 minutes
|
|
9
9
|
* and backs off exponentially on errors.
|
|
10
10
|
*/
|
|
11
11
|
import type { PayApi } from '../api/pay-api.js';
|
|
12
12
|
import type { StorageAdapter } from '../core/storage.js';
|
|
13
13
|
import { type SignedEntitlement } from '../types/contract.js';
|
|
14
|
-
import type { Entitlement, EntitlementSource } from '../types/entitlement.js';
|
|
14
|
+
import type { Entitlement, EntitlementSource, TrialState } from '../types/entitlement.js';
|
|
15
15
|
import { ExtenshiPayError } from '../types/errors.js';
|
|
16
|
+
import { type PublicKeySource } from './signature.js';
|
|
16
17
|
export declare const MIN_REFRESH_INTERVAL_MS: number;
|
|
17
18
|
export declare const MAX_REFRESH_BACKOFF_MS: number;
|
|
19
|
+
/** Offline allowance when the signed license names none (older servers and caches). */
|
|
18
20
|
export declare const MAX_OFFLINE_AGE_MS: number;
|
|
21
|
+
/** Ceiling for a signed `offlineSeconds`. */
|
|
22
|
+
export declare const MAX_SIGNED_OFFLINE_AGE_MS: number;
|
|
19
23
|
export declare const MAX_CLOCK_SKEW_MS: number;
|
|
20
24
|
export interface EntitlementManagerOptions {
|
|
21
25
|
api: PayApi;
|
|
@@ -24,9 +28,13 @@ export interface EntitlementManagerOptions {
|
|
|
24
28
|
cacheTtlMs: number;
|
|
25
29
|
source?: EntitlementSource;
|
|
26
30
|
getEndUserRef: () => Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
|
|
31
|
+
/** The trusted Ed25519 keys, in order, and how to ask the server for its current one. */
|
|
32
|
+
keys: PublicKeySource;
|
|
29
33
|
onChange?: (entitlement: Entitlement) => void;
|
|
34
|
+
/** After every accepted envelope, changed or not (the trial is not part of `onChange`). */
|
|
35
|
+
onAccepted?: () => void;
|
|
36
|
+
/** The synced trial start to send with a refresh; null when there is none. */
|
|
37
|
+
getTrialStartHint?: () => Promise<string | null>;
|
|
30
38
|
onError?: (error: ExtenshiPayError) => void;
|
|
31
39
|
now?: () => number;
|
|
32
40
|
}
|
|
@@ -34,6 +42,8 @@ export declare class EntitlementManager {
|
|
|
34
42
|
private readonly options;
|
|
35
43
|
private held;
|
|
36
44
|
private inflight;
|
|
45
|
+
/** Device clock against the server's at the last license check; null within 5 minutes. */
|
|
46
|
+
private clockSkew;
|
|
37
47
|
private timer;
|
|
38
48
|
private refreshGeneration;
|
|
39
49
|
private deadlineTimer;
|
|
@@ -50,7 +60,11 @@ export declare class EntitlementManager {
|
|
|
50
60
|
load(): Promise<Entitlement | null>;
|
|
51
61
|
/** Re-checks the loaded envelope against the project's key; discards it when the signature is invalid. */
|
|
52
62
|
reverify(): Promise<void>;
|
|
63
|
+
/** The key the held license was verified with; null when there is none or it is unverified. */
|
|
64
|
+
get verifiedKey(): string | null;
|
|
53
65
|
getCached(): Entitlement | null;
|
|
66
|
+
/** The server trial in the held license; null without one, or while the license is unverified. */
|
|
67
|
+
getTrial(): TrialState | null;
|
|
54
68
|
isFresh(): boolean;
|
|
55
69
|
get(options?: {
|
|
56
70
|
force?: boolean;
|
|
@@ -66,11 +80,13 @@ export declare class EntitlementManager {
|
|
|
66
80
|
stopAutoRefresh(): void;
|
|
67
81
|
private scheduleDeadline;
|
|
68
82
|
private schedule;
|
|
69
|
-
private
|
|
83
|
+
private measureClockSkew;
|
|
70
84
|
private discard;
|
|
71
85
|
private fingerprint;
|
|
72
86
|
private notifyIfChanged;
|
|
73
87
|
private offlineDeadline;
|
|
88
|
+
/** The signed allowance of the held license, or 48 hours when it names none. */
|
|
89
|
+
private offlineAgeMs;
|
|
74
90
|
private snapshot;
|
|
75
91
|
}
|
|
76
92
|
//# sourceMappingURL=entitlement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entitlement.d.ts","sourceRoot":"","sources":["../../src/payment/entitlement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"entitlement.d.ts","sourceRoot":"","sources":["../../src/payment/entitlement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAA0C,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACrG,OAAO,KAAK,EAAa,WAAW,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpG,OAAO,EAAe,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGlE,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,gBAAgB,CAAA;AAGrE,eAAO,MAAM,uBAAuB,QAAiB,CAAA;AACrD,eAAO,MAAM,sBAAsB,QAAqB,CAAA;AACxD,uFAAuF;AACvF,eAAO,MAAM,kBAAkB,QAAsB,CAAA;AACrD,6CAA6C;AAC7C,eAAO,MAAM,yBAAyB,QAA4B,CAAA;AAIlE,eAAO,MAAM,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M,CAIvB;IAED,gFAAgF;IAC1E,IAAI,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAgCzC,0GAA0G;IACpG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB/B,+FAA+F;IAC/F,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,SAAS,IAAI,WAAW,GAAG,IAAI;IAI/B,kGAAkG;IAClG,QAAQ,IAAI,UAAU,GAAG,IAAI;IAe7B,OAAO,IAAI,OAAO;IASZ,GAAG,CAAC,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAelE,uEAAuE;IACvE,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IAc/B,qFAAqF;IAC/E,MAAM,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,GAAE,iBAA+B,GAAG,OAAO,CAAC,WAAW,CAAC;IAqDxG,oEAAoE;IAC9D,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,gBAAgB,CAAC,UAAU,GAAE,MAAmE,GAAG,IAAI;IASvG,eAAe,IAAI,IAAI;IAUvB,OAAO,CAAC,gBAAgB;IAwBxB,OAAO,CAAC,QAAQ;IAoBhB,OAAO,CAAC,gBAAgB;YAQV,OAAO;IAOrB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,eAAe;IAQvB,gFAAgF;IAChF,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,QAAQ;CA6ChB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Email stays on the hosted page. Only this extension context holds the claim secret. */
|
|
2
2
|
import type { PayApi } from '../api/pay-api.js';
|
|
3
3
|
import type { StorageAdapter } from '../core/storage.js';
|
|
4
|
-
import type { SignedEntitlement } from '../types/contract.js';
|
|
5
|
-
import type { Entitlement, RestoreOptions, RestoreResult } from '../types/entitlement.js';
|
|
4
|
+
import type { PayStorageGrant, SignedEntitlement } from '../types/contract.js';
|
|
5
|
+
import type { CloudBackupState, Entitlement, RestoreOptions, RestoreResult } from '../types/entitlement.js';
|
|
6
6
|
/** storage.local is exposed to content scripts by default. Never put a recovery proof there. */
|
|
7
7
|
export declare function createRecoveryStorage(): StorageAdapter;
|
|
8
8
|
export interface RecoveryManagerOptions {
|
|
@@ -12,6 +12,8 @@ export interface RecoveryManagerOptions {
|
|
|
12
12
|
storage: StorageAdapter;
|
|
13
13
|
publishableKey: string;
|
|
14
14
|
onComplete: (endUserRef: string, envelope: SignedEntitlement) => Promise<Entitlement>;
|
|
15
|
+
/** Runs after `onComplete` accepted the entitlement, with the claim's storage grant (if any). */
|
|
16
|
+
onStorageGrant?: (grant: PayStorageGrant | undefined) => Promise<CloudBackupState | undefined>;
|
|
15
17
|
openUrl?: (url: string) => void | Promise<void>;
|
|
16
18
|
now?: () => number;
|
|
17
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../src/payment/recovery.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../src/payment/recovery.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,KAAK,EAAE,gBAAgB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6
|
-
*
|
|
4
|
+
* Tamper resistance, not DRM. Callers must deny access for both invalid and
|
|
5
|
+
* unverified envelopes outside explicit mocks.
|
|
6
|
+
*
|
|
7
|
+
* Which keys are trusted, in order (`PublicKeySource`, built in core/extenshi-pay.ts):
|
|
8
|
+
* 1. the key the server returned over HTTPS in this session;
|
|
9
|
+
* 2. the bundled `entitlementPublicKey`, when the developer configured one. It pins
|
|
10
|
+
* verification without a round-trip: a key read from extension storage is then never used;
|
|
11
|
+
* 3. without a bundled key, the server key saved in `storage.local` next to the
|
|
12
|
+
* license cache, so a restart with no network can still verify the cache.
|
|
13
|
+
* When none of them verifies an envelope the server is asked for its current key once
|
|
14
|
+
* (a rotated key), and that answer decides.
|
|
7
15
|
*/
|
|
8
16
|
import { type SignedEntitlement } from '../types/contract.js';
|
|
9
17
|
export type SignatureVerdict = 'valid' | 'invalid' | 'unverified';
|
|
10
18
|
export declare function base64ToBytes(base64: string): Uint8Array<ArrayBuffer>;
|
|
11
19
|
export declare function verifyEntitlementSignature(envelope: SignedEntitlement, publicKeyBase64: string | null): Promise<SignatureVerdict>;
|
|
20
|
+
export declare const PUBLIC_KEY_RE: RegExp;
|
|
21
|
+
export interface PublicKeySource {
|
|
22
|
+
/** Keys trusted without a round-trip, in the order above. */
|
|
23
|
+
known(): Promise<string[]>;
|
|
24
|
+
/** The server's current key, fetched now; null when the server signs nothing. Rejects when unreachable. */
|
|
25
|
+
fetchCurrent(): Promise<string | null>;
|
|
26
|
+
}
|
|
27
|
+
export interface KeyedVerdict {
|
|
28
|
+
verdict: SignatureVerdict;
|
|
29
|
+
/** The key that verified the envelope; null unless `verdict` is `valid`. */
|
|
30
|
+
key: string | null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `invalid` only when the server's current key was checked too (or the envelope carries no
|
|
34
|
+
* signature at all). A mismatch against known keys while the server is unreachable is
|
|
35
|
+
* `unverified`: it may be a rotated key, and no paid access is granted either way.
|
|
36
|
+
*/
|
|
37
|
+
export declare function verifyWithKeys(envelope: SignedEntitlement, source: PublicKeySource): Promise<KeyedVerdict>;
|
|
12
38
|
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/payment/signature.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/payment/signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE5E,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,CAAA;AAEjE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAKrE;AAED,wBAAsB,0BAA0B,CAC/C,QAAQ,EAAE,iBAAiB,EAC3B,eAAe,EAAE,MAAM,GAAG,IAAI,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAsB3B;AAED,eAAO,MAAM,aAAa,QAAyB,CAAA;AAEnD,MAAM,WAAW,eAAe;IAC/B,6DAA6D;IAC7D,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC1B,2GAA2G;IAC3G,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CACtC;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,gBAAgB,CAAA;IACzB,4EAA4E;IAC5E,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAClB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CACnC,QAAQ,EAAE,iBAAiB,EAC3B,MAAM,EAAE,eAAe,GACrB,OAAO,CAAC,YAAY,CAAC,CAyBvB"}
|