@extenshi/pay 0.9.0 → 0.11.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 +128 -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 +268 -26
- package/dist/core.d.ts +268 -26
- package/dist/core.js +566 -44
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +562 -45
- package/dist/core.mjs.map +1 -1
- package/dist/extenshi-pay-lite.js +555 -44
- 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 +555 -44
- package/dist/extenshi-pay-lite.mjs.map +1 -1
- package/dist/extenshi-pay.cjs.js +670 -57
- 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 +670 -57
- 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 +666 -58
- package/dist/extenshi-pay.mjs.map +1 -1
- package/dist/index.d.mts +285 -26
- package/dist/index.d.ts +285 -26
- package/dist/lite.d.mts +212 -13
- package/dist/lite.d.ts +212 -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 +35 -0
- package/dist/types/contract.d.ts.map +1 -1
- package/dist/types/entitlement.d.ts +37 -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';
|
|
@@ -328,8 +386,33 @@ interface Entitlement {
|
|
|
328
386
|
requiresOnlineCheck?: boolean;
|
|
329
387
|
/** Local offline-access deadline; null for mock mode or no cached license. */
|
|
330
388
|
offlineUntil?: number | null;
|
|
389
|
+
/**
|
|
390
|
+
* Set when the device clock differed from the server's by more than 5 minutes at the last
|
|
391
|
+
* license check. With `requiresOnlineCheck` on a connected device, ask the user to correct
|
|
392
|
+
* the date and time instead of asking them to connect.
|
|
393
|
+
*/
|
|
394
|
+
clockSkew?: ClockSkew | null;
|
|
331
395
|
source: EntitlementSource;
|
|
332
396
|
}
|
|
397
|
+
interface ClockSkew {
|
|
398
|
+
/** `ahead`: the device clock is later than the server's. */
|
|
399
|
+
direction: 'ahead' | 'behind';
|
|
400
|
+
/** Size of the difference in milliseconds. */
|
|
401
|
+
ms: number;
|
|
402
|
+
}
|
|
403
|
+
/** `getTrial()`: the free trial from the verified license, on the server's clock. */
|
|
404
|
+
interface TrialState {
|
|
405
|
+
/** True while the trial runs and the license was checked within the last 48 hours, as for paid access. */
|
|
406
|
+
active: boolean;
|
|
407
|
+
/** ISO time of the installation's first license check while the application had a trial. */
|
|
408
|
+
startedAt: string;
|
|
409
|
+
/** ISO time the trial ends. */
|
|
410
|
+
endsAt: string;
|
|
411
|
+
/** Whole days left, rounded up; 0 once the trial has ended. */
|
|
412
|
+
daysLeft: number;
|
|
413
|
+
/** The trial has days left but the license was not checked within 48 hours: connect to resume it. */
|
|
414
|
+
requiresOnlineCheck: boolean;
|
|
415
|
+
}
|
|
333
416
|
interface GetEntitlementOptions {
|
|
334
417
|
/** Skip the cache TTL and hit the network. */
|
|
335
418
|
force?: boolean;
|
|
@@ -385,10 +468,21 @@ interface RestoreOptions {
|
|
|
385
468
|
pollIntervalMs?: number;
|
|
386
469
|
signal?: AbortSignal;
|
|
387
470
|
openUrl?: (url: string) => void | Promise<void>;
|
|
471
|
+
/**
|
|
472
|
+
* `storage` also turns on the cloud copy of settings: the hosted page shows
|
|
473
|
+
* the storage disclosure first. `enableCloudBackup()` passes it. Default: a plain restore.
|
|
474
|
+
*/
|
|
475
|
+
purpose?: PayRestorePurpose;
|
|
388
476
|
}
|
|
477
|
+
/**
|
|
478
|
+
* The cloud copy of settings after a completed restore: `on` (the token is
|
|
479
|
+
* stored), or why it is off. Absent when the application does not offer it.
|
|
480
|
+
*/
|
|
481
|
+
type CloudBackupState = 'on' | 'no_consent' | 'license_required';
|
|
389
482
|
type RestoreResult = {
|
|
390
483
|
state: 'complete';
|
|
391
484
|
entitlement: Entitlement;
|
|
485
|
+
cloudBackup?: CloudBackupState;
|
|
392
486
|
} | {
|
|
393
487
|
state: 'timeout' | 'expired' | 'canceled';
|
|
394
488
|
};
|
|
@@ -440,11 +534,15 @@ declare class MockTransport implements Transport {
|
|
|
440
534
|
private readonly checkoutEnabled;
|
|
441
535
|
private readonly claimAfterPolls;
|
|
442
536
|
private readonly withdrawalWaiver;
|
|
537
|
+
private readonly seller;
|
|
538
|
+
private trial;
|
|
443
539
|
readonly sessions: Map<string, MockSession>;
|
|
444
540
|
constructor(data?: MockData);
|
|
445
541
|
call<T>(procedure: string, _kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
|
|
446
542
|
/** Test/dev helpers. */
|
|
447
543
|
setEntitlements(items: PayEntitlementItem[]): void;
|
|
544
|
+
/** Previews a server trial of `days` from `startedAt` (default now); `null` removes it. */
|
|
545
|
+
setTrial(days: number | null, startedAt?: string): void;
|
|
448
546
|
cancelSession(sessionId: string): void;
|
|
449
547
|
expireSession(sessionId: string): void;
|
|
450
548
|
private offerResponse;
|
|
@@ -460,8 +558,12 @@ declare class PayApi {
|
|
|
460
558
|
private readonly transport;
|
|
461
559
|
private readonly publishableKey;
|
|
462
560
|
constructor(transport: Transport, publishableKey: string);
|
|
463
|
-
/**
|
|
464
|
-
|
|
561
|
+
/**
|
|
562
|
+
* `locale` opens the hosted recovery page (and its email) in the user's language.
|
|
563
|
+
* `purpose` is sent only for `storage`: a plain restore keeps the request older
|
|
564
|
+
* BFFs know, and their non-strict zod input strips the key anyway.
|
|
565
|
+
*/
|
|
566
|
+
createRestoreSession(claimChallenge: string, locale?: string | null, purpose?: PayRestorePurpose): Promise<PayRestoreSessionResponse>;
|
|
465
567
|
claimRestoreSession(sessionId: string, claimSecret: string): Promise<PayRestoreClaimResponse>;
|
|
466
568
|
getOffer(locale?: string | null): Promise<PayOfferResponse>;
|
|
467
569
|
/**
|
|
@@ -471,7 +573,8 @@ declare class PayApi {
|
|
|
471
573
|
*/
|
|
472
574
|
createCheckout(sku: string, endUserRef: string, locale?: string | null, withdrawalWaiver?: WithdrawalWaiverConsent): Promise<PayCheckoutSession>;
|
|
473
575
|
claimSession(sessionId: string, endUserRef: string): Promise<PayCheckoutClaim>;
|
|
474
|
-
|
|
576
|
+
/** `trialStartedHint`: the trial start kept in storage.sync; the server only lets it move a start earlier. */
|
|
577
|
+
getEntitlement(endUserRef: string, trialStartedHint?: string | null): Promise<SignedEntitlement>;
|
|
475
578
|
getPortalUrl(endUserRef: string, customerId?: string, locale?: string | null): Promise<PayPortalResponse>;
|
|
476
579
|
}
|
|
477
580
|
|
|
@@ -512,6 +615,10 @@ interface ExtenshiPayEvents {
|
|
|
512
615
|
sku: string;
|
|
513
616
|
sessionId: string;
|
|
514
617
|
};
|
|
618
|
+
/** Once per installation and trial, `trialEndingDays` before the end, while the user has no paid access. */
|
|
619
|
+
'trial:ending': TrialState;
|
|
620
|
+
/** Once per installation and trial, when it has ended, while the user has no paid access. */
|
|
621
|
+
'trial:ended': TrialState;
|
|
515
622
|
error: ExtenshiPayError;
|
|
516
623
|
}
|
|
517
624
|
type ExtenshiPayEventName = keyof ExtenshiPayEvents;
|
|
@@ -555,13 +662,36 @@ declare class CheckoutManager {
|
|
|
555
662
|
private settle;
|
|
556
663
|
}
|
|
557
664
|
|
|
665
|
+
/**
|
|
666
|
+
* Ed25519 verification of the entitlement projection.
|
|
667
|
+
*
|
|
668
|
+
* Tamper resistance, not DRM. Callers must deny access for both invalid and
|
|
669
|
+
* unverified envelopes outside explicit mocks.
|
|
670
|
+
*
|
|
671
|
+
* Which keys are trusted, in order (`PublicKeySource`, built in core/extenshi-pay.ts):
|
|
672
|
+
* 1. the key the server returned over HTTPS in this session;
|
|
673
|
+
* 2. the bundled `entitlementPublicKey`, when the developer configured one. It pins
|
|
674
|
+
* verification without a round-trip: a key read from extension storage is then never used;
|
|
675
|
+
* 3. without a bundled key, the server key saved in `storage.local` next to the
|
|
676
|
+
* license cache, so a restart with no network can still verify the cache.
|
|
677
|
+
* When none of them verifies an envelope the server is asked for its current key once
|
|
678
|
+
* (a rotated key), and that answer decides.
|
|
679
|
+
*/
|
|
680
|
+
|
|
681
|
+
interface PublicKeySource {
|
|
682
|
+
/** Keys trusted without a round-trip, in the order above. */
|
|
683
|
+
known(): Promise<string[]>;
|
|
684
|
+
/** The server's current key, fetched now; null when the server signs nothing. Rejects when unreachable. */
|
|
685
|
+
fetchCurrent(): Promise<string | null>;
|
|
686
|
+
}
|
|
687
|
+
|
|
558
688
|
/**
|
|
559
689
|
* Entitlement cache + refresh.
|
|
560
690
|
*
|
|
561
691
|
* The cached envelope is a cache OF the server projection, never a second
|
|
562
692
|
* source of truth: it is verified when stored and re-verified on load (once
|
|
563
693
|
* the project's public key is known), served without a round-trip while the
|
|
564
|
-
* TTL holds, served for
|
|
694
|
+
* TTL holds, served after signed issuance for the signed `offlineSeconds` (48 hours when absent) when the network is down, and expired
|
|
565
695
|
* locally by `expiresAt`. Background refresh polls at most every 15 minutes
|
|
566
696
|
* and backs off exponentially on errors.
|
|
567
697
|
*/
|
|
@@ -573,9 +703,13 @@ interface EntitlementManagerOptions {
|
|
|
573
703
|
cacheTtlMs: number;
|
|
574
704
|
source?: EntitlementSource;
|
|
575
705
|
getEndUserRef: () => Promise<string>;
|
|
576
|
-
/**
|
|
577
|
-
|
|
706
|
+
/** The trusted Ed25519 keys, in order, and how to ask the server for its current one. */
|
|
707
|
+
keys: PublicKeySource;
|
|
578
708
|
onChange?: (entitlement: Entitlement) => void;
|
|
709
|
+
/** After every accepted envelope, changed or not (the trial is not part of `onChange`). */
|
|
710
|
+
onAccepted?: () => void;
|
|
711
|
+
/** The synced trial start to send with a refresh; null when there is none. */
|
|
712
|
+
getTrialStartHint?: () => Promise<string | null>;
|
|
579
713
|
onError?: (error: ExtenshiPayError) => void;
|
|
580
714
|
now?: () => number;
|
|
581
715
|
}
|
|
@@ -583,6 +717,8 @@ declare class EntitlementManager {
|
|
|
583
717
|
private readonly options;
|
|
584
718
|
private held;
|
|
585
719
|
private inflight;
|
|
720
|
+
/** Device clock against the server's at the last license check; null within 5 minutes. */
|
|
721
|
+
private clockSkew;
|
|
586
722
|
private timer;
|
|
587
723
|
private refreshGeneration;
|
|
588
724
|
private deadlineTimer;
|
|
@@ -599,7 +735,11 @@ declare class EntitlementManager {
|
|
|
599
735
|
load(): Promise<Entitlement | null>;
|
|
600
736
|
/** Re-checks the loaded envelope against the project's key; discards it when the signature is invalid. */
|
|
601
737
|
reverify(): Promise<void>;
|
|
738
|
+
/** The key the held license was verified with; null when there is none or it is unverified. */
|
|
739
|
+
get verifiedKey(): string | null;
|
|
602
740
|
getCached(): Entitlement | null;
|
|
741
|
+
/** The server trial in the held license; null without one, or while the license is unverified. */
|
|
742
|
+
getTrial(): TrialState | null;
|
|
603
743
|
isFresh(): boolean;
|
|
604
744
|
get(options?: {
|
|
605
745
|
force?: boolean;
|
|
@@ -615,11 +755,13 @@ declare class EntitlementManager {
|
|
|
615
755
|
stopAutoRefresh(): void;
|
|
616
756
|
private scheduleDeadline;
|
|
617
757
|
private schedule;
|
|
618
|
-
private
|
|
758
|
+
private measureClockSkew;
|
|
619
759
|
private discard;
|
|
620
760
|
private fingerprint;
|
|
621
761
|
private notifyIfChanged;
|
|
622
762
|
private offlineDeadline;
|
|
763
|
+
/** The signed allowance of the held license, or 48 hours when it names none. */
|
|
764
|
+
private offlineAgeMs;
|
|
623
765
|
private snapshot;
|
|
624
766
|
}
|
|
625
767
|
|
|
@@ -632,6 +774,8 @@ interface RecoveryManagerOptions {
|
|
|
632
774
|
storage: StorageAdapter;
|
|
633
775
|
publishableKey: string;
|
|
634
776
|
onComplete: (endUserRef: string, envelope: SignedEntitlement) => Promise<Entitlement>;
|
|
777
|
+
/** Runs after `onComplete` accepted the entitlement, with the claim's storage grant (if any). */
|
|
778
|
+
onStorageGrant?: (grant: PayStorageGrant | undefined) => Promise<CloudBackupState | undefined>;
|
|
635
779
|
openUrl?: (url: string) => void | Promise<void>;
|
|
636
780
|
now?: () => number;
|
|
637
781
|
}
|
|
@@ -665,13 +809,17 @@ declare class EventEmitter<Events extends object> {
|
|
|
665
809
|
* extends it with `getOffer()` / `showPaywall()`.
|
|
666
810
|
*
|
|
667
811
|
* Data that leaves the extension: `publishableKey`, `endUserRef`, `sku`,
|
|
668
|
-
* `locale
|
|
669
|
-
*
|
|
812
|
+
* `locale`, checkout session IDs and, with a server trial, the trial start date
|
|
813
|
+
* the server issued (`trialStartedHint`, kept in storage.sync). Explicit recovery also sends its session ID,
|
|
814
|
+
* challenge and claim secret (POST body). Email stays on the hosted page. With cloud backup, the
|
|
815
|
+
* storage token goes only to `/v1/storage` (as a bearer), never in a message to a content script.
|
|
670
816
|
*/
|
|
671
817
|
|
|
672
818
|
/** Injection points for tests and unusual hosts. */
|
|
673
819
|
interface ExtenshiPayDeps {
|
|
674
820
|
storage?: StorageAdapter;
|
|
821
|
+
/** Where the trial start is synced (default `storage.sync`); null turns syncing off. */
|
|
822
|
+
syncStorage?: StorageAdapter | null;
|
|
675
823
|
/** Trusted extension-only storage; never share this adapter with content scripts. */
|
|
676
824
|
recoveryStorage?: StorageAdapter;
|
|
677
825
|
transport?: Transport;
|
|
@@ -680,7 +828,7 @@ interface ExtenshiPayDeps {
|
|
|
680
828
|
now?: () => number;
|
|
681
829
|
}
|
|
682
830
|
declare class ExtenshiPayLite {
|
|
683
|
-
static readonly version = "0.
|
|
831
|
+
static readonly version = "0.11.0";
|
|
684
832
|
protected readonly config: ResolvedConfig;
|
|
685
833
|
protected readonly emitter: EventEmitter<ExtenshiPayEvents>;
|
|
686
834
|
protected readonly storage: StorageAdapter;
|
|
@@ -688,11 +836,21 @@ declare class ExtenshiPayLite {
|
|
|
688
836
|
protected readonly entitlements: EntitlementManager;
|
|
689
837
|
protected readonly checkout: CheckoutManager;
|
|
690
838
|
protected readonly recovery: RecoveryManager;
|
|
839
|
+
private readonly backup;
|
|
840
|
+
/** `deps.openUrl`, for tabs the full SDK opens outside checkout and recovery. */
|
|
841
|
+
protected readonly openUrl: ((url: string) => void | Promise<void>) | undefined;
|
|
842
|
+
private readonly trial;
|
|
843
|
+
/** storage.sync for the trial start; null when off, in mock mode, or outside an extension. */
|
|
844
|
+
private readonly syncStorage;
|
|
691
845
|
private readonly now;
|
|
692
846
|
private endUserRef;
|
|
693
847
|
private endUserRefPromise;
|
|
694
848
|
private offer;
|
|
695
849
|
private offerInflight;
|
|
850
|
+
/** The signing key the server returned in this session; never one read from storage. */
|
|
851
|
+
private serverKey;
|
|
852
|
+
/** Trust order for license signatures; see payment/signature.ts. */
|
|
853
|
+
private readonly keys;
|
|
696
854
|
private readyPromise;
|
|
697
855
|
private destroyed;
|
|
698
856
|
constructor(config: ExtenshiPayConfig, deps?: ExtenshiPayDeps);
|
|
@@ -709,6 +867,13 @@ declare class ExtenshiPayLite {
|
|
|
709
867
|
getEndUserRef(): Promise<string>;
|
|
710
868
|
getCachedEntitlement(): Entitlement | null;
|
|
711
869
|
getEntitlement(options?: GetEntitlementOptions): Promise<Entitlement>;
|
|
870
|
+
/**
|
|
871
|
+
* The free trial the application set on the server, from the verified license, or null when
|
|
872
|
+
* there is none (or the license could not be verified yet). Answers offline from the cached
|
|
873
|
+
* license; like paid access, `active` needs a license check within 48 hours. `isPaid()` and
|
|
874
|
+
* `hasFeature()` do not include the trial: grant trial access with `(await getTrial())?.active`.
|
|
875
|
+
*/
|
|
876
|
+
getTrial(options?: GetEntitlementOptions): Promise<TrialState | null>;
|
|
712
877
|
/** True when any active/grace entitlement exists, or the given `sku` is active/grace. */
|
|
713
878
|
isPaid(sku?: string): Promise<boolean>;
|
|
714
879
|
hasFeature(feature: string): Promise<boolean>;
|
|
@@ -740,6 +905,23 @@ declare class ExtenshiPayLite {
|
|
|
740
905
|
openCheckout(sku: string, options?: CheckoutOptions): Promise<CheckoutResult>;
|
|
741
906
|
/** Opens email verification on the hosted page. No email is collected inside the extension. */
|
|
742
907
|
restorePurchase(options?: RestoreOptions): Promise<RestoreResult>;
|
|
908
|
+
/**
|
|
909
|
+
* Turns on the cloud copy of the extension's settings (`@extenshi/storage`): the
|
|
910
|
+
* hosted restore page shows the storage disclosure and the buyer confirms with
|
|
911
|
+
* the code from the purchase email. `cloudBackup` in the result says whether it is
|
|
912
|
+
* on. Buyers only; consent is recorded by the server.
|
|
913
|
+
*/
|
|
914
|
+
enableCloudBackup(options?: Omit<RestoreOptions, 'purpose'>): Promise<RestoreResult>;
|
|
915
|
+
/**
|
|
916
|
+
* The storage token for `ExtenshiStorage.create({ cloud: { getToken } })`, or null
|
|
917
|
+
* while cloud backup is off on this installation. Extension pages and background
|
|
918
|
+
* only: it rejects in a content script, and must never be sent to one.
|
|
919
|
+
*/
|
|
920
|
+
cloudBackupToken(): Promise<string | null>;
|
|
921
|
+
/** Turns cloud backup off on this installation: revokes its token. The cloud copy stays. */
|
|
922
|
+
disableCloudBackup(): Promise<void>;
|
|
923
|
+
/** Deletes the buyer's cloud copy and turns cloud backup off on every installation. */
|
|
924
|
+
deleteCloudBackup(): Promise<void>;
|
|
743
925
|
/** Read-only license view. Entitlements retain cache/signature/offline semantics. */
|
|
744
926
|
getLicenseSummary(options?: GetEntitlementOptions): Promise<LicenseSummary>;
|
|
745
927
|
/** Opens the provider's self-service portal; resolves null when the provider has none. */
|
|
@@ -753,12 +935,29 @@ declare class ExtenshiPayLite {
|
|
|
753
935
|
destroy(): void;
|
|
754
936
|
/** Offer + signing key. Public in the full SDK (`getOffer`), internal here. */
|
|
755
937
|
protected fetchOffer(force?: boolean): Promise<PayOfferResponse>;
|
|
756
|
-
private
|
|
938
|
+
private get serverKeyStorageKey();
|
|
939
|
+
private readSavedServerKey;
|
|
940
|
+
/**
|
|
941
|
+
* Keeps the server's key next to the license cache so a restart with no network can verify it.
|
|
942
|
+
* Not with a bundled key: that one already covers the restart, and storage stays untrusted.
|
|
943
|
+
*/
|
|
944
|
+
private rememberServerKey;
|
|
945
|
+
/**
|
|
946
|
+
* A license verified with the saved key alone is checked against the server once per start:
|
|
947
|
+
* when the server's key differs (rotation, or an edited storage) the license is fetched again,
|
|
948
|
+
* and dropped if it does not verify. Offline, the saved key stands until `offlineUntil`.
|
|
949
|
+
*/
|
|
950
|
+
private confirmSavedServerKey;
|
|
951
|
+
private get trialStartKey();
|
|
952
|
+
/** The synced trial start, or null (none, malformed, or storage.sync unavailable). */
|
|
953
|
+
private readTrialStartHint;
|
|
954
|
+
/** Syncs the verified trial start, keeping the earliest one seen. Never the installation id. */
|
|
955
|
+
private rememberTrialStart;
|
|
757
956
|
protected reportError(error: unknown): ExtenshiPayError;
|
|
758
957
|
}
|
|
759
958
|
|
|
760
959
|
/** Kept in sync with package.json by tests/unit/version.test.ts. */
|
|
761
|
-
declare const VERSION = "0.
|
|
960
|
+
declare const VERSION = "0.11.0";
|
|
762
961
|
|
|
763
962
|
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 };
|
|
963
|
+
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,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,eAAe,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACjE,YAAY,EACX,eAAe,EACf,cAAc,EACd,aAAa,EACb,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,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,WAAW,EACX,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"}
|
|
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,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,eAAe,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,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,EAAiB,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"entitlement.d.ts","sourceRoot":"","sources":["../../src/payment/entitlement.ts"],"names":[],"mappings":"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"}
|
|
@@ -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,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAM3G,gGAAgG;AAChG,wBAAgB,qBAAqB,IAAI,cAAc,CAOtD;AAOD,MAAM,WAAW,sBAAsB;IACtC,GAAG,EAAE,MAAM,CAAA;IACX,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,OAAO,EAAE,cAAc,CAAA;IACvB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;IACrF,iGAAiG;IACjG,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,KAAK,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAA;IAC9F,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/C,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAClB;AAED,qBAAa,eAAe;IAIf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,IAAI,CAA4B;gBACX,OAAO,EAAE,sBAAsB;IAC5D,IAAI,UAAU,IAAI,MAAM,CAEvB;IACD,QAAQ,IAAI,OAAO;IAGnB,IAAI,IAAI,IAAI;IAKN,IAAI,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IA4C1D,aAAa,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;YAsBtC,IAAI;CAkDlB"}
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ed25519 verification of the entitlement projection.
|
|
3
3
|
*
|
|
4
|
-
* Tamper resistance, not DRM.
|
|
5
|
-
*
|
|
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"}
|