@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.
Files changed (74) hide show
  1. package/README.md +138 -17
  2. package/dist/api/mock.d.ts +4 -0
  3. package/dist/api/mock.d.ts.map +1 -1
  4. package/dist/api/pay-api.d.ts +9 -4
  5. package/dist/api/pay-api.d.ts.map +1 -1
  6. package/dist/core/config.d.ts.map +1 -1
  7. package/dist/core/extenshi-pay.d.ts +60 -5
  8. package/dist/core/extenshi-pay.d.ts.map +1 -1
  9. package/dist/core/index.d.ts +3 -1
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/storage.d.ts +6 -0
  12. package/dist/core/storage.d.ts.map +1 -1
  13. package/dist/core.d.mts +271 -26
  14. package/dist/core.d.ts +271 -26
  15. package/dist/core.js +589 -49
  16. package/dist/core.js.map +1 -1
  17. package/dist/core.mjs +584 -50
  18. package/dist/core.mjs.map +1 -1
  19. package/dist/extenshi-pay-lite.js +577 -49
  20. package/dist/extenshi-pay-lite.js.map +1 -1
  21. package/dist/extenshi-pay-lite.min.js +3 -3
  22. package/dist/extenshi-pay-lite.min.js.map +1 -1
  23. package/dist/extenshi-pay-lite.mjs +577 -49
  24. package/dist/extenshi-pay-lite.mjs.map +1 -1
  25. package/dist/extenshi-pay.cjs.js +694 -61
  26. package/dist/extenshi-pay.cjs.js.map +1 -1
  27. package/dist/extenshi-pay.d.ts +11 -1
  28. package/dist/extenshi-pay.d.ts.map +1 -1
  29. package/dist/extenshi-pay.js +694 -61
  30. package/dist/extenshi-pay.js.map +1 -1
  31. package/dist/extenshi-pay.min.js +3 -3
  32. package/dist/extenshi-pay.min.js.map +1 -1
  33. package/dist/extenshi-pay.min.mjs +3 -3
  34. package/dist/extenshi-pay.min.mjs.map +1 -1
  35. package/dist/extenshi-pay.mjs +689 -62
  36. package/dist/extenshi-pay.mjs.map +1 -1
  37. package/dist/index.d.mts +288 -26
  38. package/dist/index.d.ts +288 -26
  39. package/dist/lite.d.mts +214 -13
  40. package/dist/lite.d.ts +214 -13
  41. package/dist/lite.d.ts.map +1 -1
  42. package/dist/payment/cloud-backup.d.ts +35 -0
  43. package/dist/payment/cloud-backup.d.ts.map +1 -0
  44. package/dist/payment/entitlement.d.ts +21 -5
  45. package/dist/payment/entitlement.d.ts.map +1 -1
  46. package/dist/payment/recovery.d.ts +4 -2
  47. package/dist/payment/recovery.d.ts.map +1 -1
  48. package/dist/payment/signature.d.ts +29 -3
  49. package/dist/payment/signature.d.ts.map +1 -1
  50. package/dist/payment/trial.d.ts +55 -0
  51. package/dist/payment/trial.d.ts.map +1 -0
  52. package/dist/paywall/i18n.d.ts +3 -0
  53. package/dist/paywall/i18n.d.ts.map +1 -1
  54. package/dist/paywall/renderer.d.ts +7 -0
  55. package/dist/paywall/renderer.d.ts.map +1 -1
  56. package/dist/paywall.d.mts +7 -0
  57. package/dist/paywall.d.ts +7 -0
  58. package/dist/paywall.js +54 -14
  59. package/dist/paywall.js.map +1 -1
  60. package/dist/paywall.mjs +54 -14
  61. package/dist/paywall.mjs.map +1 -1
  62. package/dist/types/config.d.ts +27 -1
  63. package/dist/types/config.d.ts.map +1 -1
  64. package/dist/types/contract.d.ts +36 -0
  65. package/dist/types/contract.d.ts.map +1 -1
  66. package/dist/types/entitlement.d.ts +39 -1
  67. package/dist/types/entitlement.d.ts.map +1 -1
  68. package/dist/types/events.d.ts +5 -1
  69. package/dist/types/events.d.ts.map +1 -1
  70. package/dist/types/paywall.d.ts +10 -0
  71. package/dist/types/paywall.d.ts.map +1 -1
  72. package/dist/version.d.ts +1 -1
  73. package/dist/version.d.ts.map +1 -1
  74. package/package.json +3 -2
package/dist/core.d.ts CHANGED
@@ -49,6 +49,7 @@ interface PayOfferDto {
49
49
  description: string | null;
50
50
  features: string[];
51
51
  }
52
+ declare const PAY_REGIONAL_ACCESS_SKU = "@regional-free";
52
53
  interface PayOfferResponse {
53
54
  /** Optional during rolling upgrades; never infer this from the project name. */
54
55
  seller?: PaySellerPublic | null;
@@ -100,6 +101,16 @@ interface PayEntitlementItem {
100
101
  expiresAt: string | null;
101
102
  features: string[];
102
103
  }
104
+ /**
105
+ * The installation's free trial on the server clock: one per installation per application,
106
+ * started at its first license read. Absent when the application has no trial.
107
+ */
108
+ interface PayTrial {
109
+ /** ISO time of the first license read while the application had a trial. */
110
+ startedAt: string;
111
+ /** ISO `startedAt` plus the application's current trial length. */
112
+ endsAt: string;
113
+ }
103
114
  interface PayEntitlementPayload {
104
115
  v: typeof PAY_CONTRACT_VERSION;
105
116
  /** Signed application scope; prevents moving a grant to another application. */
@@ -108,6 +119,10 @@ interface PayEntitlementPayload {
108
119
  entitlements: PayEntitlementItem[];
109
120
  /** ISO timestamp the projection was computed at; the SDK uses it for cache age. */
110
121
  issuedAt: string;
122
+ /** Optional: only for an application with a trial, and absent from older servers. */
123
+ trial?: PayTrial;
124
+ /** Optional: seconds of offline access after `issuedAt`; absent from older servers (48 hours). */
125
+ offlineSeconds?: number;
111
126
  }
112
127
  interface SignedEntitlement {
113
128
  payload: PayEntitlementPayload;
@@ -161,12 +176,33 @@ interface PayRestoreSessionResponse {
161
176
  expiresAt: string;
162
177
  url: string;
163
178
  }
179
+ /**
180
+ * `storage`: the buyer turns on the cloud copy of the extension's settings. The
181
+ * hosted page shows the storage disclosure; the claim records consent. Additive:
182
+ * a session without a purpose is a plain restore.
183
+ */
184
+ declare const PAY_RESTORE_PURPOSES: readonly ["restore", "storage"];
185
+ type PayRestorePurpose = (typeof PAY_RESTORE_PURPOSES)[number];
186
+ /**
187
+ * Outcome for the cloud copy of settings, present in a complete claim only when
188
+ * the application offers it. A token is returned once; a retried claim rotates it.
189
+ */
190
+ type PayStorageGrant = {
191
+ state: 'granted';
192
+ token: string;
193
+ } | {
194
+ state: 'unavailable';
195
+ reason: 'NO_CONSENT' | 'LICENSE_REQUIRED';
196
+ };
197
+ /** From `shared-types/storage.ts`: `est_` + 32 random bytes, base64url. */
198
+ declare const STORAGE_TOKEN_RE: RegExp;
164
199
  type PayRestoreClaimResponse = {
165
200
  state: 'pending';
166
201
  } | {
167
202
  state: 'complete';
168
203
  endUserRef: string;
169
204
  entitlement: SignedEntitlement;
205
+ storage?: PayStorageGrant;
170
206
  };
171
207
  /** A project-scoped billing profile; provider identifiers are never exposed. */
172
208
  interface PayPortalAccount {
@@ -253,6 +289,20 @@ interface MockData {
253
289
  * paywall previews the checkbox). `null` previews a seller outside the EEA/UK.
254
290
  */
255
291
  withdrawalWaiver?: PayWithdrawalWaiver | null;
292
+ /**
293
+ * Seller details for the paywall, the license panel and the waiver text.
294
+ * Omitted, the offer carries none (as from an older server); `null`
295
+ * previews a seller without public details, so the paywall disables purchase.
296
+ */
297
+ seller?: PaySellerPublic | null;
298
+ /**
299
+ * Previews a server trial: `days` long, started at `startedAt` (default: when the mock is
300
+ * created). Omitted, the mock application has no trial.
301
+ */
302
+ trial?: {
303
+ days: number;
304
+ startedAt?: string;
305
+ };
256
306
  }
257
307
  interface ExtenshiPayConfig {
258
308
  /** `pk_ext_` + 32 hex characters, from the project's Monetization tab. */
@@ -274,6 +324,15 @@ interface ExtenshiPayConfig {
274
324
  onReady?: () => void;
275
325
  onError?: (error: ExtenshiPayError) => void;
276
326
  theme?: ThemeConfig;
327
+ /** Days before the trial's end that `trial:ending` fires (default 2; 0 turns it off). */
328
+ trialEndingDays?: number;
329
+ /**
330
+ * Keep the trial's start date in `storage.sync` and send it back on license checks, so
331
+ * other devices on the same synced browser account share the trial (default true).
332
+ * Only the date is synced, never the installation id. A reinstall still restarts the
333
+ * trial: uninstalling clears `storage.sync`.
334
+ */
335
+ syncTrialStart?: boolean;
277
336
  }
278
337
  interface ResolvedConfig {
279
338
  publishableKey: string;
@@ -287,10 +346,13 @@ interface ResolvedConfig {
287
346
  mock: boolean;
288
347
  mockData: MockData | null;
289
348
  theme: ThemeConfig;
349
+ trialEndingDays: number;
350
+ syncTrialStart: boolean;
290
351
  }
291
352
  declare const DEFAULT_API_URL = "https://bff.extenshi.io";
292
353
  declare const DEFAULT_CACHE_TTL_MS: number;
293
354
  declare const MAX_CACHE_TTL_MS: number;
355
+ declare const DEFAULT_TRIAL_ENDING_DAYS = 2;
294
356
 
295
357
  type PaywallMode = 'modal' | 'inline' | 'sidebar' | 'fullscreen' | 'minimal';
296
358
  /**
@@ -350,6 +412,16 @@ interface PaywallOptions {
350
412
  onUpgrade?: (sku: string, consent?: UpgradeConsent) => void;
351
413
  onClose?: () => void;
352
414
  }
415
+ /** `showTrialEnded()`: the paywall with the trial-ended heading, plus an optional feedback button. */
416
+ interface TrialEndedOptions extends PaywallOptions {
417
+ /**
418
+ * Your feedback form (HTTPS). The SDK opens it with `src=trial_end` added and nothing that
419
+ * identifies the installation. Any other URL is left out and reported through `error`.
420
+ */
421
+ feedbackFormUrl?: string;
422
+ /** Label of the feedback button (default: "Share feedback" in the user's language). */
423
+ feedbackLabel?: string;
424
+ }
353
425
 
354
426
  type EntitlementSource = 'network' | 'cache' | 'mock' | 'none';
355
427
  /** The SDK's view of the server projection, with `expiresAt` applied locally. */
@@ -357,6 +429,8 @@ interface Entitlement {
357
429
  items: PayEntitlementItem[];
358
430
  /** Union of `features[]` over active/grace items. */
359
431
  features: string[];
432
+ /** Signed expiry of regional free access, independent of any purchase. */
433
+ regionalFreeUntil?: number;
360
434
  /** True only when the Ed25519 signature was checked against the project's key. */
361
435
  verified: boolean;
362
436
  issuedAt: string | null;
@@ -366,8 +440,33 @@ interface Entitlement {
366
440
  requiresOnlineCheck?: boolean;
367
441
  /** Local offline-access deadline; null for mock mode or no cached license. */
368
442
  offlineUntil?: number | null;
443
+ /**
444
+ * Set when the device clock differed from the server's by more than 5 minutes at the last
445
+ * license check. With `requiresOnlineCheck` on a connected device, ask the user to correct
446
+ * the date and time instead of asking them to connect.
447
+ */
448
+ clockSkew?: ClockSkew | null;
369
449
  source: EntitlementSource;
370
450
  }
451
+ interface ClockSkew {
452
+ /** `ahead`: the device clock is later than the server's. */
453
+ direction: 'ahead' | 'behind';
454
+ /** Size of the difference in milliseconds. */
455
+ ms: number;
456
+ }
457
+ /** `getTrial()`: the free trial from the verified license, on the server's clock. */
458
+ interface TrialState {
459
+ /** True while the trial runs and the license was checked within the last 48 hours, as for paid access. */
460
+ active: boolean;
461
+ /** ISO time of the installation's first license check while the application had a trial. */
462
+ startedAt: string;
463
+ /** ISO time the trial ends. */
464
+ endsAt: string;
465
+ /** Whole days left, rounded up; 0 once the trial has ended. */
466
+ daysLeft: number;
467
+ /** The trial has days left but the license was not checked within 48 hours: connect to resume it. */
468
+ requiresOnlineCheck: boolean;
469
+ }
371
470
  interface GetEntitlementOptions {
372
471
  /** Skip the cache TTL and hit the network. */
373
472
  force?: boolean;
@@ -423,10 +522,21 @@ interface RestoreOptions {
423
522
  pollIntervalMs?: number;
424
523
  signal?: AbortSignal;
425
524
  openUrl?: (url: string) => void | Promise<void>;
525
+ /**
526
+ * `storage` also turns on the cloud copy of settings: the hosted page shows
527
+ * the storage disclosure first. `enableCloudBackup()` passes it. Default: a plain restore.
528
+ */
529
+ purpose?: PayRestorePurpose;
426
530
  }
531
+ /**
532
+ * The cloud copy of settings after a completed restore: `on` (the token is
533
+ * stored), or why it is off. Absent when the application does not offer it.
534
+ */
535
+ type CloudBackupState = 'on' | 'no_consent' | 'license_required';
427
536
  type RestoreResult = {
428
537
  state: 'complete';
429
538
  entitlement: Entitlement;
539
+ cloudBackup?: CloudBackupState;
430
540
  } | {
431
541
  state: 'timeout' | 'expired' | 'canceled';
432
542
  };
@@ -514,11 +624,15 @@ declare class MockTransport implements Transport {
514
624
  private readonly checkoutEnabled;
515
625
  private readonly claimAfterPolls;
516
626
  private readonly withdrawalWaiver;
627
+ private readonly seller;
628
+ private trial;
517
629
  readonly sessions: Map<string, MockSession>;
518
630
  constructor(data?: MockData);
519
631
  call<T>(procedure: string, _kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
520
632
  /** Test/dev helpers. */
521
633
  setEntitlements(items: PayEntitlementItem[]): void;
634
+ /** Previews a server trial of `days` from `startedAt` (default now); `null` removes it. */
635
+ setTrial(days: number | null, startedAt?: string): void;
522
636
  cancelSession(sessionId: string): void;
523
637
  expireSession(sessionId: string): void;
524
638
  private offerResponse;
@@ -534,8 +648,12 @@ declare class PayApi {
534
648
  private readonly transport;
535
649
  private readonly publishableKey;
536
650
  constructor(transport: Transport, publishableKey: string);
537
- /** `locale` opens the hosted recovery page (and its email) in the user's language. */
538
- createRestoreSession(claimChallenge: string, locale?: string | null): Promise<PayRestoreSessionResponse>;
651
+ /**
652
+ * `locale` opens the hosted recovery page (and its email) in the user's language.
653
+ * `purpose` is sent only for `storage`: a plain restore keeps the request older
654
+ * BFFs know, and their non-strict zod input strips the key anyway.
655
+ */
656
+ createRestoreSession(claimChallenge: string, locale?: string | null, purpose?: PayRestorePurpose): Promise<PayRestoreSessionResponse>;
539
657
  claimRestoreSession(sessionId: string, claimSecret: string): Promise<PayRestoreClaimResponse>;
540
658
  getOffer(locale?: string | null): Promise<PayOfferResponse>;
541
659
  /**
@@ -545,7 +663,8 @@ declare class PayApi {
545
663
  */
546
664
  createCheckout(sku: string, endUserRef: string, locale?: string | null, withdrawalWaiver?: WithdrawalWaiverConsent): Promise<PayCheckoutSession>;
547
665
  claimSession(sessionId: string, endUserRef: string): Promise<PayCheckoutClaim>;
548
- getEntitlement(endUserRef: string): Promise<SignedEntitlement>;
666
+ /** `trialStartedHint`: the trial start kept in storage.sync; the server only lets it move a start earlier. */
667
+ getEntitlement(endUserRef: string, trialStartedHint?: string | null): Promise<SignedEntitlement>;
549
668
  getPortalUrl(endUserRef: string, customerId?: string, locale?: string | null): Promise<PayPortalResponse>;
550
669
  }
551
670
 
@@ -588,6 +707,12 @@ declare class MemoryStorage implements StorageAdapter {
588
707
  set(key: string, value: unknown): Promise<void>;
589
708
  remove(key: string): Promise<void>;
590
709
  }
710
+ /**
711
+ * The browser's synced storage (`storage.sync`), or null outside an extension. The SDK keeps
712
+ * only the trial start there (never `endUserRef`), so devices on one synced account share the
713
+ * trial. Uninstalling clears it from the account, so it does not survive a reinstall.
714
+ */
715
+ declare function createSyncStorage(): StorageAdapter | null;
591
716
  declare function createStorage(): StorageAdapter;
592
717
 
593
718
  interface ExtenshiPayEvents {
@@ -613,6 +738,10 @@ interface ExtenshiPayEvents {
613
738
  sku: string;
614
739
  sessionId: string;
615
740
  };
741
+ /** Once per installation and trial, `trialEndingDays` before the end, while the user has no paid access. */
742
+ 'trial:ending': TrialState;
743
+ /** Once per installation and trial, when it has ended, while the user has no paid access. */
744
+ 'trial:ended': TrialState;
616
745
  error: ExtenshiPayError;
617
746
  }
618
747
  type ExtenshiPayEventName = keyof ExtenshiPayEvents;
@@ -659,13 +788,72 @@ declare class CheckoutManager {
659
788
  private settle;
660
789
  }
661
790
 
791
+ /**
792
+ * Cloud copy of the extension's settings (`@extenshi/storage`). Pay owns the
793
+ * token: only a verified restore claim issues it; this module keeps it in the
794
+ * SDK's storage (`storage.local`) and revokes it. `@extenshi/storage` reads it
795
+ * through `cloudBackupToken()`. The token is never logged and never answered to
796
+ * a content script: route those calls to the background.
797
+ */
798
+
799
+ interface CloudBackupOptions {
800
+ storage: StorageAdapter;
801
+ publishableKey: string;
802
+ apiUrl: string;
803
+ fetch?: typeof fetch;
804
+ /** Mock mode: forget the token locally, never call the network. */
805
+ mock?: boolean;
806
+ }
807
+ declare class CloudBackup {
808
+ private readonly options;
809
+ private readonly fetchImpl;
810
+ constructor(options: CloudBackupOptions);
811
+ get storageKey(): string;
812
+ /** Stores or clears the token from a verified claim. Never throws: the licence is already restored. */
813
+ accept(grant: PayStorageGrant | undefined): Promise<CloudBackupState | undefined>;
814
+ token(): Promise<string | null>;
815
+ /** Revokes this installation's token. A token the server no longer knows (401) is forgotten too. */
816
+ disable(): Promise<void>;
817
+ /** Deletes the buyer's cloud copy and turns the backup off on every device. */
818
+ delete(): Promise<void>;
819
+ private assertTrustedContext;
820
+ private throwUnlessOk;
821
+ private request;
822
+ }
823
+
824
+ /**
825
+ * Ed25519 verification of the entitlement projection.
826
+ *
827
+ * Tamper resistance, not DRM. Callers must deny access for both invalid and
828
+ * unverified envelopes outside explicit mocks.
829
+ *
830
+ * Which keys are trusted, in order (`PublicKeySource`, built in core/extenshi-pay.ts):
831
+ * 1. the key the server returned over HTTPS in this session;
832
+ * 2. the bundled `entitlementPublicKey`, when the developer configured one. It pins
833
+ * verification without a round-trip: a key read from extension storage is then never used;
834
+ * 3. without a bundled key, the server key saved in `storage.local` next to the
835
+ * license cache, so a restart with no network can still verify the cache.
836
+ * When none of them verifies an envelope the server is asked for its current key once
837
+ * (a rotated key), and that answer decides.
838
+ */
839
+
840
+ type SignatureVerdict = 'valid' | 'invalid' | 'unverified';
841
+ declare function base64ToBytes(base64: string): Uint8Array<ArrayBuffer>;
842
+ declare function verifyEntitlementSignature(envelope: SignedEntitlement, publicKeyBase64: string | null): Promise<SignatureVerdict>;
843
+ interface PublicKeySource {
844
+ /** Keys trusted without a round-trip, in the order above. */
845
+ known(): Promise<string[]>;
846
+ /** The server's current key, fetched now; null when the server signs nothing. Rejects when unreachable. */
847
+ fetchCurrent(): Promise<string | null>;
848
+ }
849
+
662
850
  /**
663
851
  * Entitlement cache + refresh.
664
852
  *
665
853
  * The cached envelope is a cache OF the server projection, never a second
666
854
  * source of truth: it is verified when stored and re-verified on load (once
667
855
  * the project's public key is known), served without a round-trip while the
668
- * TTL holds, served for up to 48 hours after signed issuance when the network is down, and expired
856
+ * TTL holds, served after signed issuance for the signed `offlineSeconds` (48 hours when absent) when the network is down, and expired
669
857
  * locally by `expiresAt`. Background refresh polls at most every 15 minutes
670
858
  * and backs off exponentially on errors.
671
859
  */
@@ -679,9 +867,13 @@ interface EntitlementManagerOptions {
679
867
  cacheTtlMs: number;
680
868
  source?: EntitlementSource;
681
869
  getEndUserRef: () => Promise<string>;
682
- /** Base64 raw Ed25519 public key from `getOffer`, or null when unknown/unsigned. */
683
- getPublicKey: () => Promise<string | null>;
870
+ /** The trusted Ed25519 keys, in order, and how to ask the server for its current one. */
871
+ keys: PublicKeySource;
684
872
  onChange?: (entitlement: Entitlement) => void;
873
+ /** After every accepted envelope, changed or not (the trial is not part of `onChange`). */
874
+ onAccepted?: () => void;
875
+ /** The synced trial start to send with a refresh; null when there is none. */
876
+ getTrialStartHint?: () => Promise<string | null>;
685
877
  onError?: (error: ExtenshiPayError) => void;
686
878
  now?: () => number;
687
879
  }
@@ -689,6 +881,8 @@ declare class EntitlementManager {
689
881
  private readonly options;
690
882
  private held;
691
883
  private inflight;
884
+ /** Device clock against the server's at the last license check; null within 5 minutes. */
885
+ private clockSkew;
692
886
  private timer;
693
887
  private refreshGeneration;
694
888
  private deadlineTimer;
@@ -705,7 +899,11 @@ declare class EntitlementManager {
705
899
  load(): Promise<Entitlement | null>;
706
900
  /** Re-checks the loaded envelope against the project's key; discards it when the signature is invalid. */
707
901
  reverify(): Promise<void>;
902
+ /** The key the held license was verified with; null when there is none or it is unverified. */
903
+ get verifiedKey(): string | null;
708
904
  getCached(): Entitlement | null;
905
+ /** The server trial in the held license; null without one, or while the license is unverified. */
906
+ getTrial(): TrialState | null;
709
907
  isFresh(): boolean;
710
908
  get(options?: {
711
909
  force?: boolean;
@@ -721,11 +919,13 @@ declare class EntitlementManager {
721
919
  stopAutoRefresh(): void;
722
920
  private scheduleDeadline;
723
921
  private schedule;
724
- private safePublicKey;
922
+ private measureClockSkew;
725
923
  private discard;
726
924
  private fingerprint;
727
925
  private notifyIfChanged;
728
926
  private offlineDeadline;
927
+ /** The signed allowance of the held license, or 48 hours when it names none. */
928
+ private offlineAgeMs;
729
929
  private snapshot;
730
930
  }
731
931
 
@@ -751,6 +951,8 @@ interface RecoveryManagerOptions {
751
951
  storage: StorageAdapter;
752
952
  publishableKey: string;
753
953
  onComplete: (endUserRef: string, envelope: SignedEntitlement) => Promise<Entitlement>;
954
+ /** Runs after `onComplete` accepted the entitlement, with the claim's storage grant (if any). */
955
+ onStorageGrant?: (grant: PayStorageGrant | undefined) => Promise<CloudBackupState | undefined>;
754
956
  openUrl?: (url: string) => void | Promise<void>;
755
957
  now?: () => number;
756
958
  }
@@ -768,18 +970,6 @@ declare class RecoveryManager {
768
970
  private poll;
769
971
  }
770
972
 
771
- /**
772
- * Ed25519 verification of the entitlement projection.
773
- *
774
- * Tamper resistance, not DRM. Trust comes from the developer's bundled key or
775
- * a key fetched over HTTPS, never from editable extension storage. Callers must
776
- * deny access for both invalid and unverified envelopes outside explicit mocks.
777
- */
778
-
779
- type SignatureVerdict = 'valid' | 'invalid' | 'unverified';
780
- declare function base64ToBytes(base64: string): Uint8Array<ArrayBuffer>;
781
- declare function verifyEntitlementSignature(envelope: SignedEntitlement, publicKeyBase64: string | null): Promise<SignatureVerdict>;
782
-
783
973
  declare class Logger {
784
974
  private level;
785
975
  private readonly prefix;
@@ -796,7 +986,7 @@ declare class Logger {
796
986
  declare const logger: Logger;
797
987
 
798
988
  /** Kept in sync with package.json by tests/unit/version.test.ts. */
799
- declare const VERSION = "0.9.0";
989
+ declare const VERSION = "0.12.0";
800
990
 
801
991
  /** Same shape the BFF accepts (`en`, `de-DE`, `zh-Hant`). */
802
992
  declare const LOCALE_RE: RegExp;
@@ -818,13 +1008,17 @@ declare class EventEmitter<Events extends object> {
818
1008
  * extends it with `getOffer()` / `showPaywall()`.
819
1009
  *
820
1010
  * Data that leaves the extension: `publishableKey`, `endUserRef`, `sku`,
821
- * `locale` and checkout session IDs. Explicit recovery also sends its session ID,
822
- * challenge and claim secret (POST body). Email stays on the hosted page.
1011
+ * `locale`, checkout session IDs and, with a server trial, the trial start date
1012
+ * the server issued (`trialStartedHint`, kept in storage.sync). Explicit recovery also sends its session ID,
1013
+ * challenge and claim secret (POST body). Email stays on the hosted page. With cloud backup, the
1014
+ * storage token goes only to `/v1/storage` (as a bearer), never in a message to a content script.
823
1015
  */
824
1016
 
825
1017
  /** Injection points for tests and unusual hosts. */
826
1018
  interface ExtenshiPayDeps {
827
1019
  storage?: StorageAdapter;
1020
+ /** Where the trial start is synced (default `storage.sync`); null turns syncing off. */
1021
+ syncStorage?: StorageAdapter | null;
828
1022
  /** Trusted extension-only storage; never share this adapter with content scripts. */
829
1023
  recoveryStorage?: StorageAdapter;
830
1024
  transport?: Transport;
@@ -833,7 +1027,7 @@ interface ExtenshiPayDeps {
833
1027
  now?: () => number;
834
1028
  }
835
1029
  declare class ExtenshiPayLite {
836
- static readonly version = "0.9.0";
1030
+ static readonly version = "0.12.0";
837
1031
  protected readonly config: ResolvedConfig;
838
1032
  protected readonly emitter: EventEmitter<ExtenshiPayEvents>;
839
1033
  protected readonly storage: StorageAdapter;
@@ -841,11 +1035,21 @@ declare class ExtenshiPayLite {
841
1035
  protected readonly entitlements: EntitlementManager;
842
1036
  protected readonly checkout: CheckoutManager;
843
1037
  protected readonly recovery: RecoveryManager;
1038
+ private readonly backup;
1039
+ /** `deps.openUrl`, for tabs the full SDK opens outside checkout and recovery. */
1040
+ protected readonly openUrl: ((url: string) => void | Promise<void>) | undefined;
1041
+ private readonly trial;
1042
+ /** storage.sync for the trial start; null when off, in mock mode, or outside an extension. */
1043
+ private readonly syncStorage;
844
1044
  private readonly now;
845
1045
  private endUserRef;
846
1046
  private endUserRefPromise;
847
1047
  private offer;
848
1048
  private offerInflight;
1049
+ /** The signing key the server returned in this session; never one read from storage. */
1050
+ private serverKey;
1051
+ /** Trust order for license signatures; see payment/signature.ts. */
1052
+ private readonly keys;
849
1053
  private readyPromise;
850
1054
  private destroyed;
851
1055
  constructor(config: ExtenshiPayConfig, deps?: ExtenshiPayDeps);
@@ -862,6 +1066,13 @@ declare class ExtenshiPayLite {
862
1066
  getEndUserRef(): Promise<string>;
863
1067
  getCachedEntitlement(): Entitlement | null;
864
1068
  getEntitlement(options?: GetEntitlementOptions): Promise<Entitlement>;
1069
+ /**
1070
+ * The free trial the application set on the server, from the verified license, or null when
1071
+ * there is none (or the license could not be verified yet). Answers offline from the cached
1072
+ * license; like paid access, `active` needs a license check within 48 hours. `isPaid()` and
1073
+ * `hasFeature()` do not include the trial: grant trial access with `(await getTrial())?.active`.
1074
+ */
1075
+ getTrial(options?: GetEntitlementOptions): Promise<TrialState | null>;
865
1076
  /** True when any active/grace entitlement exists, or the given `sku` is active/grace. */
866
1077
  isPaid(sku?: string): Promise<boolean>;
867
1078
  hasFeature(feature: string): Promise<boolean>;
@@ -893,6 +1104,23 @@ declare class ExtenshiPayLite {
893
1104
  openCheckout(sku: string, options?: CheckoutOptions): Promise<CheckoutResult>;
894
1105
  /** Opens email verification on the hosted page. No email is collected inside the extension. */
895
1106
  restorePurchase(options?: RestoreOptions): Promise<RestoreResult>;
1107
+ /**
1108
+ * Turns on the cloud copy of the extension's settings (`@extenshi/storage`): the
1109
+ * hosted restore page shows the storage disclosure and the buyer confirms with
1110
+ * the code from the purchase email. `cloudBackup` in the result says whether it is
1111
+ * on. Buyers only; consent is recorded by the server.
1112
+ */
1113
+ enableCloudBackup(options?: Omit<RestoreOptions, 'purpose'>): Promise<RestoreResult>;
1114
+ /**
1115
+ * The storage token for `ExtenshiStorage.create({ cloud: { getToken } })`, or null
1116
+ * while cloud backup is off on this installation. Extension pages and background
1117
+ * only: it rejects in a content script, and must never be sent to one.
1118
+ */
1119
+ cloudBackupToken(): Promise<string | null>;
1120
+ /** Turns cloud backup off on this installation: revokes its token. The cloud copy stays. */
1121
+ disableCloudBackup(): Promise<void>;
1122
+ /** Deletes the buyer's cloud copy and turns cloud backup off on every installation. */
1123
+ deleteCloudBackup(): Promise<void>;
896
1124
  /** Read-only license view. Entitlements retain cache/signature/offline semantics. */
897
1125
  getLicenseSummary(options?: GetEntitlementOptions): Promise<LicenseSummary>;
898
1126
  /** Opens the provider's self-service portal; resolves null when the provider has none. */
@@ -906,7 +1134,24 @@ declare class ExtenshiPayLite {
906
1134
  destroy(): void;
907
1135
  /** Offer + signing key. Public in the full SDK (`getOffer`), internal here. */
908
1136
  protected fetchOffer(force?: boolean): Promise<PayOfferResponse>;
909
- private getPublicKey;
1137
+ private get serverKeyStorageKey();
1138
+ private readSavedServerKey;
1139
+ /**
1140
+ * Keeps the server's key next to the license cache so a restart with no network can verify it.
1141
+ * Not with a bundled key: that one already covers the restart, and storage stays untrusted.
1142
+ */
1143
+ private rememberServerKey;
1144
+ /**
1145
+ * A license verified with the saved key alone is checked against the server once per start:
1146
+ * when the server's key differs (rotation, or an edited storage) the license is fetched again,
1147
+ * and dropped if it does not verify. Offline, the saved key stands until `offlineUntil`.
1148
+ */
1149
+ private confirmSavedServerKey;
1150
+ private get trialStartKey();
1151
+ /** The synced trial start, or null (none, malformed, or storage.sync unavailable). */
1152
+ private readTrialStartHint;
1153
+ /** Syncs the verified trial start, keeping the earliest one seen. Never the installation id. */
1154
+ private rememberTrialStart;
910
1155
  protected reportError(error: unknown): ExtenshiPayError;
911
1156
  }
912
1157
 
@@ -923,5 +1168,5 @@ declare const END_USER_REF_STORAGE_KEY = "extenshi-pay:endUserRef";
923
1168
  declare function mintEndUserRef(): string;
924
1169
  declare function getOrCreateEndUserRef(storage: StorageAdapter): Promise<string>;
925
1170
 
926
- export { CHECKOUT_POLL_INTERVAL_MS, CHECKOUT_TIMEOUT_MS, CheckoutManager, DEFAULT_API_URL, DEFAULT_CACHE_TTL_MS, EMPTY_ENTITLEMENT, END_USER_REF_STORAGE_KEY, ERROR_CODES, EntitlementManager, EventEmitter, ExtenshiPayError, ExtenshiPayLite, ExtensionStorage, HttpTransport, LOCALE_RE, LocalStorageAdapter, Logger, MAX_CACHE_TTL_MS, MAX_REFRESH_BACKOFF_MS, MIN_REFRESH_INTERVAL_MS, MemoryStorage, MockTransport, PAY_CONTRACT_VERSION, PAY_CURRENCIES, PAY_END_USER_REF_RE, PAY_ENTITLEMENT_STATUSES, PAY_ERRORS, PAY_GATEWAYS, PAY_OFFER_INTERVALS, PAY_OFFER_KINDS, PAY_PUBLISHABLE_KEY_HEX_LENGTH, PAY_PUBLISHABLE_KEY_PREFIX, PAY_SKU_RE, PAY_WITHDRAWAL_WAIVER_VERSION, PayApi, RecoveryManager, TRPC_PATH, VERSION, applyLocalExpiry, base64ToBytes, canonicalJson, checkFeatures, collectFeatures, createRecoveryStorage, createStorage, getOrCreateEndUserRef, hasFeature, isEntitled, isLive, isPayPublishableKey, logger, mintEndUserRef, openInNewTab, resolveConfig, trpcErrorToPayError, verifyEntitlementSignature };
927
- export type { CheckoutManagerOptions, CheckoutOptions, CheckoutResult, CheckoutState, CustomerPortalOptions, Entitlement, EntitlementManagerOptions, EntitlementSource, Environment, ErrorCode, ExtenshiPayConfig, ExtenshiPayDeps, ExtenshiPayErrorOptions, ExtenshiPayEventName, ExtenshiPayEvents, GetEntitlementOptions, HttpTransportOptions, LicenseSummary, Listener, LogLevel, MockData, PayCheckoutClaim, PayCheckoutSession, PayCurrency, PayEntitlementItem, PayEntitlementPayload, PayEntitlementStatus, PayErrorCode, PayGatewayId, PayOfferDto, PayOfferInterval, PayOfferKind, PayOfferResponse, PayPortalAccount, PayPortalResponse, PayRestoreClaimResponse, PayRestoreSessionResponse, PaySellerPublic, PayWithdrawalWaiver, PaywallMode, PaywallOptions, PaywallStrings, ProcedureKind, RecoveryManagerOptions, RequireFeatureOptions, ResolvedConfig, RestoreOptions, RestoreResult, SignatureVerdict, SignedEntitlement, StorageAdapter, ThemeConfig, Transport, UpgradeConsent, WithdrawalWaiverConsent };
1171
+ export { CHECKOUT_POLL_INTERVAL_MS, CHECKOUT_TIMEOUT_MS, CheckoutManager, CloudBackup, DEFAULT_API_URL, DEFAULT_CACHE_TTL_MS, DEFAULT_TRIAL_ENDING_DAYS, EMPTY_ENTITLEMENT, END_USER_REF_STORAGE_KEY, ERROR_CODES, EntitlementManager, EventEmitter, ExtenshiPayError, ExtenshiPayLite, ExtensionStorage, HttpTransport, LOCALE_RE, LocalStorageAdapter, Logger, MAX_CACHE_TTL_MS, MAX_REFRESH_BACKOFF_MS, MIN_REFRESH_INTERVAL_MS, MemoryStorage, MockTransport, PAY_CONTRACT_VERSION, PAY_CURRENCIES, PAY_END_USER_REF_RE, PAY_ENTITLEMENT_STATUSES, PAY_ERRORS, PAY_GATEWAYS, PAY_OFFER_INTERVALS, PAY_OFFER_KINDS, PAY_PUBLISHABLE_KEY_HEX_LENGTH, PAY_PUBLISHABLE_KEY_PREFIX, PAY_REGIONAL_ACCESS_SKU, PAY_RESTORE_PURPOSES, PAY_SKU_RE, PAY_WITHDRAWAL_WAIVER_VERSION, PayApi, RecoveryManager, STORAGE_TOKEN_RE, TRPC_PATH, VERSION, applyLocalExpiry, base64ToBytes, canonicalJson, checkFeatures, collectFeatures, createRecoveryStorage, createStorage, createSyncStorage, getOrCreateEndUserRef, hasFeature, isEntitled, isLive, isPayPublishableKey, logger, mintEndUserRef, openInNewTab, resolveConfig, trpcErrorToPayError, verifyEntitlementSignature };
1172
+ export type { CheckoutManagerOptions, CheckoutOptions, CheckoutResult, CheckoutState, ClockSkew, CloudBackupOptions, CloudBackupState, CustomerPortalOptions, Entitlement, EntitlementManagerOptions, EntitlementSource, Environment, ErrorCode, ExtenshiPayConfig, ExtenshiPayDeps, ExtenshiPayErrorOptions, ExtenshiPayEventName, ExtenshiPayEvents, GetEntitlementOptions, HttpTransportOptions, LicenseSummary, Listener, LogLevel, MockData, PayCheckoutClaim, PayCheckoutSession, PayCurrency, PayEntitlementItem, PayEntitlementPayload, PayEntitlementStatus, PayErrorCode, PayGatewayId, PayOfferDto, PayOfferInterval, PayOfferKind, PayOfferResponse, PayPortalAccount, PayPortalResponse, PayRestoreClaimResponse, PayRestorePurpose, PayRestoreSessionResponse, PaySellerPublic, PayStorageGrant, PayTrial, PayWithdrawalWaiver, PaywallMode, PaywallOptions, PaywallStrings, ProcedureKind, RecoveryManagerOptions, RequireFeatureOptions, ResolvedConfig, RestoreOptions, RestoreResult, SignatureVerdict, SignedEntitlement, StorageAdapter, ThemeConfig, Transport, TrialEndedOptions, TrialState, UpgradeConsent, WithdrawalWaiverConsent };