zklicensing 0.1.0-beta.3 → 0.1.0-beta.4

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 (157) hide show
  1. package/README.md +212 -83
  2. package/build/appsLookup.d.ts +14 -0
  3. package/build/appsLookup.d.ts.map +1 -0
  4. package/build/appsLookup.js +12 -0
  5. package/build/appsLookup.js.map +1 -0
  6. package/build/archiveBootstrap.d.ts +15 -1
  7. package/build/archiveBootstrap.d.ts.map +1 -1
  8. package/build/archiveBootstrap.js +61 -8
  9. package/build/archiveBootstrap.js.map +1 -1
  10. package/build/bindClient.d.ts +51 -0
  11. package/build/bindClient.d.ts.map +1 -0
  12. package/build/bindClient.js +115 -0
  13. package/build/bindClient.js.map +1 -0
  14. package/build/buyClient.d.ts +8 -3
  15. package/build/buyClient.d.ts.map +1 -1
  16. package/build/buyClient.js +25 -13
  17. package/build/buyClient.js.map +1 -1
  18. package/build/contractInterface.d.ts +11 -5
  19. package/build/contractInterface.d.ts.map +1 -1
  20. package/build/contractInterface.js +81 -16
  21. package/build/contractInterface.js.map +1 -1
  22. package/build/deviceIdentity.d.ts +68 -0
  23. package/build/deviceIdentity.d.ts.map +1 -0
  24. package/build/deviceIdentity.js +209 -0
  25. package/build/deviceIdentity.js.map +1 -0
  26. package/build/generationClient.d.ts +1 -0
  27. package/build/generationClient.d.ts.map +1 -1
  28. package/build/generationClient.js +1 -1
  29. package/build/generationClient.js.map +1 -1
  30. package/build/index.d.ts +27 -37
  31. package/build/index.d.ts.map +1 -1
  32. package/build/index.js +84 -115
  33. package/build/index.js.map +1 -1
  34. package/build/licenseLeaf.d.ts +76 -0
  35. package/build/licenseLeaf.d.ts.map +1 -0
  36. package/build/licenseLeaf.js +189 -0
  37. package/build/licenseLeaf.js.map +1 -0
  38. package/build/licenseRecord.d.ts +10 -1
  39. package/build/licenseRecord.d.ts.map +1 -1
  40. package/build/licenseRecord.js.map +1 -1
  41. package/build/licenseStore.d.ts +16 -1
  42. package/build/licenseStore.d.ts.map +1 -1
  43. package/build/licenseStore.js +163 -5
  44. package/build/licenseStore.js.map +1 -1
  45. package/build/manifestVerify.d.ts.map +1 -1
  46. package/build/manifestVerify.js +7 -2
  47. package/build/manifestVerify.js.map +1 -1
  48. package/build/migrateClient.d.ts +1 -0
  49. package/build/migrateClient.d.ts.map +1 -1
  50. package/build/migrateClient.js +1 -0
  51. package/build/migrateClient.js.map +1 -1
  52. package/build/onChainRoot.d.ts +67 -0
  53. package/build/onChainRoot.d.ts.map +1 -0
  54. package/build/onChainRoot.js +87 -0
  55. package/build/onChainRoot.js.map +1 -0
  56. package/build/ownershipLicenseHash.d.ts +25 -0
  57. package/build/ownershipLicenseHash.d.ts.map +1 -0
  58. package/build/ownershipLicenseHash.js +29 -0
  59. package/build/ownershipLicenseHash.js.map +1 -0
  60. package/build/ownershipSignature.d.ts +122 -0
  61. package/build/ownershipSignature.d.ts.map +1 -0
  62. package/build/ownershipSignature.js +244 -0
  63. package/build/ownershipSignature.js.map +1 -0
  64. package/build/proveErrors.d.ts +7 -7
  65. package/build/proveErrors.js +7 -7
  66. package/build/refundClient.d.ts +2 -11
  67. package/build/refundClient.d.ts.map +1 -1
  68. package/build/refundClient.js +34 -16
  69. package/build/refundClient.js.map +1 -1
  70. package/build/renewClient.d.ts +3 -1
  71. package/build/renewClient.d.ts.map +1 -1
  72. package/build/renewClient.js +2 -1
  73. package/build/renewClient.js.map +1 -1
  74. package/build/seatName.d.ts +8 -0
  75. package/build/seatName.d.ts.map +1 -0
  76. package/build/seatName.js +136 -0
  77. package/build/seatName.js.map +1 -0
  78. package/build/statsClient.d.ts +19 -4
  79. package/build/statsClient.d.ts.map +1 -1
  80. package/build/statsClient.js +14 -4
  81. package/build/statsClient.js.map +1 -1
  82. package/build/trustAnchorVerify.d.ts +48 -0
  83. package/build/trustAnchorVerify.d.ts.map +1 -0
  84. package/build/trustAnchorVerify.js +431 -0
  85. package/build/trustAnchorVerify.js.map +1 -0
  86. package/build/trustAnchorVerifyCli.d.ts +35 -0
  87. package/build/trustAnchorVerifyCli.d.ts.map +1 -0
  88. package/build/trustAnchorVerifyCli.js +177 -0
  89. package/build/trustAnchorVerifyCli.js.map +1 -0
  90. package/build/unbindClient.d.ts +56 -0
  91. package/build/unbindClient.d.ts.map +1 -0
  92. package/build/unbindClient.js +113 -0
  93. package/build/unbindClient.js.map +1 -0
  94. package/build/vendorAccountClient.d.ts +1 -0
  95. package/build/vendorAccountClient.d.ts.map +1 -1
  96. package/build/vendorAccountClient.js +4 -1
  97. package/build/vendorAccountClient.js.map +1 -1
  98. package/build/verifyCore.d.ts +1 -1
  99. package/build/verifyCore.d.ts.map +1 -1
  100. package/build/verifyCore.js +10 -3
  101. package/build/verifyCore.js.map +1 -1
  102. package/build/verifyOffline.d.ts +85 -0
  103. package/build/verifyOffline.d.ts.map +1 -0
  104. package/build/verifyOffline.js +139 -0
  105. package/build/verifyOffline.js.map +1 -0
  106. package/build/verifyService.js +581 -454
  107. package/build/verifyService.js.map +1 -1
  108. package/build/verifyWithAncestors.d.ts +18 -0
  109. package/build/verifyWithAncestors.d.ts.map +1 -0
  110. package/build/verifyWithAncestors.js +119 -0
  111. package/build/verifyWithAncestors.js.map +1 -0
  112. package/package.json +40 -11
  113. package/src/appsLookup.ts +48 -0
  114. package/src/archiveBootstrap.ts +71 -14
  115. package/src/bindClient.ts +175 -0
  116. package/src/buyClient.ts +67 -22
  117. package/src/contractInterface.d.ts +11 -5
  118. package/src/contractInterface.ts +105 -34
  119. package/src/deviceIdentity.ts +249 -0
  120. package/src/generationClient.ts +2 -1
  121. package/src/index.ts +128 -191
  122. package/src/licenseLeaf.ts +221 -0
  123. package/src/licenseRecord.ts +19 -2
  124. package/src/licenseStore.ts +186 -6
  125. package/src/manifestVerify.ts +7 -2
  126. package/src/migrateClient.ts +2 -0
  127. package/src/onChainRoot.ts +107 -0
  128. package/src/ownershipLicenseHash.ts +31 -0
  129. package/src/ownershipSignature.ts +354 -0
  130. package/src/proveErrors.ts +7 -7
  131. package/src/refundClient.ts +27 -13
  132. package/src/renewClient.ts +7 -2
  133. package/src/seatName.ts +165 -0
  134. package/src/statsClient.ts +54 -9
  135. package/src/trustAnchorVerify.ts +548 -0
  136. package/src/trustAnchorVerifyCli.ts +179 -0
  137. package/src/unbindClient.ts +149 -0
  138. package/src/vendorAccountClient.ts +9 -5
  139. package/src/verifyCore.ts +11 -3
  140. package/src/verifyOffline.ts +212 -0
  141. package/src/verifyService.ts +658 -488
  142. package/src/verifyWithAncestors.ts +153 -0
  143. package/build/licenseProof.d.ts +0 -26
  144. package/build/licenseProof.d.ts.map +0 -1
  145. package/build/licenseProof.js +0 -41
  146. package/build/licenseProof.js.map +0 -1
  147. package/build/ownership.d.ts +0 -34
  148. package/build/ownership.d.ts.map +0 -1
  149. package/build/ownership.js +0 -147
  150. package/build/ownership.js.map +0 -1
  151. package/build/proveRetry.d.ts +0 -38
  152. package/build/proveRetry.d.ts.map +0 -1
  153. package/build/proveRetry.js +0 -89
  154. package/build/proveRetry.js.map +0 -1
  155. package/src/licenseProof.d.ts +0 -26
  156. package/src/licenseProof.ts +0 -48
  157. package/src/ownership.ts +0 -198
package/build/index.d.ts CHANGED
@@ -1,60 +1,39 @@
1
1
  /**
2
2
  * verifyLicense — client SDK.
3
3
  *
4
- * Calls the keeper's GET /verify until the on-chain refund window for the
5
- * license has closed; from that point on returns from a local anchor and
6
- * never touches the network again. The refund-window decision is server-
7
- * side: the keeper returns `refundWindowClosed: boolean` on its /verify
8
- * response, computed from its own record of `purchaseSlot + REFUND_WINDOW_N`
9
- * against the on-chain `currentSlot`. The SDK gates anchor writes on that
10
- * boolean and never trusts a `purchaseSlot` supplied by the local proof
11
- * file, so a user who forges their proof metadata cannot force the offline
12
- * branch prematurely.
4
+ * Calls the licensing service's GET /verify until the on-chain refund
5
+ * window for the license has closed; from that point on returns from a
6
+ * local anchor and never touches the network again. The refund-window
7
+ * decision is server-side: the service returns `refundWindowClosed:
8
+ * boolean` on its /verify response, computed from its own record of
9
+ * `purchaseSlot + REFUND_WINDOW_N` against the on-chain `currentSlot`.
10
+ * The SDK gates anchor writes on that boolean and never trusts a
11
+ * `purchaseSlot` supplied by the local proof file, so a user who forges
12
+ * their proof metadata cannot force the offline branch prematurely.
13
13
  *
14
14
  * Anchor purity: every field persisted in the Anchor derives from the
15
- * keeper's /verify response — `anchoredSlot`, `expirySlot`, `ownership`.
16
- * The only client-supplied input to the offline branch is
17
- * `proof.expirySlot`, used solely as the loadAnchor binding key. A
18
- * tampered proof file therefore never gets a wrong answer; it gets no
19
- * offline branch at all and falls through to the keeper on every call.
15
+ * service's /verify response — `anchoredSlot`, `expirySlot`. The only
16
+ * client-supplied input to the offline branch is `proof.expirySlot`,
17
+ * used solely as the loadAnchor binding key. A tampered proof file
18
+ * therefore never gets a wrong answer; it gets no offline branch at all
19
+ * and falls through to the licensing service on every call.
20
20
  */
21
21
  import { REFUND_WINDOW_N, GRACE_PERIOD_N } from './contractInterface.js';
22
22
  declare const MS_PER_SLOT = 90000;
23
+ export declare const DEFAULT_VERIFIER_URL = "https://zklicensing.com/api/verify";
23
24
  export interface Storage {
24
25
  getItem(key: string): string | null;
25
26
  setItem(key: string, value: string): void;
26
27
  }
27
- export interface ActivationRecord {
28
- token: string;
29
- expiresAt: number;
30
- secretHash?: string;
31
- }
32
- export declare function loadActivation(storage: Storage, zkAppAddress: string, licenseHash: string, nowMs?: number): ActivationRecord | null;
33
- export declare function saveActivation(storage: Storage, zkAppAddress: string, licenseHash: string, rec: ActivationRecord): void;
34
28
  export interface ProofInput {
35
29
  licenseHash: string;
36
30
  zkAppAddress: string;
37
31
  expirySlot: number;
38
- verifierUrl?: string;
39
32
  }
40
- /**
41
- * Callback that proves an OwnershipChallenge using a stored secretHash.
42
- * Callers wire this up with their own o1js + LicenseProof imports so the SDK
43
- * stays dependency-free for the verify-only path. Return value is the
44
- * `proof.toJSON()` payload the verifier's POST /respond expects.
45
- */
46
- export type TokenProver = (input: {
47
- licenseHash: string;
48
- nonce: string;
49
- secretHash: string;
50
- }) => Promise<unknown>;
51
33
  export interface VerifyOptions {
52
- verifierUrl?: string;
53
34
  storage?: Storage | null;
54
35
  fetcher?: typeof fetch;
55
36
  now?: () => number;
56
- prover?: TokenProver;
57
- secretHash?: string;
58
37
  }
59
38
  export interface VerifyResult {
60
39
  valid: boolean;
@@ -65,8 +44,19 @@ export interface VerifyResult {
65
44
  remainingDays: number;
66
45
  reason: string | null;
67
46
  source: 'offline' | 'chain';
68
- ownership: 'verified' | 'unverified';
69
47
  }
70
48
  export declare function verifyLicense(proof: ProofInput, options?: VerifyOptions): Promise<VerifyResult>;
71
49
  export { REFUND_WINDOW_N, GRACE_PERIOD_N, MS_PER_SLOT };
50
+ export { proveBind, confirmBind } from './bindClient.js';
51
+ export type { ProveBindRequest, ProveBindResponse, ConfirmBindRequest, } from './bindClient.js';
52
+ export { proveUnbind, confirmUnbind } from './unbindClient.js';
53
+ export type { ProveUnbindRequest, ProveUnbindResponse, ConfirmUnbindRequest, } from './unbindClient.js';
54
+ export { getOrCreateDeviceIdentity, computeDeviceCommitment, } from './deviceIdentity.js';
55
+ export type { DeviceIdentity } from './deviceIdentity.js';
56
+ export { verifyOffline, deviceCommitmentFromFields } from './verifyOffline.js';
57
+ export type { VerifyOfflineInput, VerifyOfflineResult, DeviceSlotSnapshot, } from './verifyOffline.js';
58
+ export { fetchOnChainLicensesRoot, DEFAULT_MINA_GRAPHQL_URLS } from './onChainRoot.js';
59
+ export type { FetchOnChainLicensesRootInput, NetworkName } from './onChainRoot.js';
60
+ export { seatNameFor, SEAT_NAME_COMBINATIONS } from './seatName.js';
61
+ export type { SeatNameInput } from './seatName.js';
72
62
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,eAAe,EACf,cAAc,EAGf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EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
package/build/index.js CHANGED
@@ -3,52 +3,41 @@
3
3
  /**
4
4
  * verifyLicense — client SDK.
5
5
  *
6
- * Calls the keeper's GET /verify until the on-chain refund window for the
7
- * license has closed; from that point on returns from a local anchor and
8
- * never touches the network again. The refund-window decision is server-
9
- * side: the keeper returns `refundWindowClosed: boolean` on its /verify
10
- * response, computed from its own record of `purchaseSlot + REFUND_WINDOW_N`
11
- * against the on-chain `currentSlot`. The SDK gates anchor writes on that
12
- * boolean and never trusts a `purchaseSlot` supplied by the local proof
13
- * file, so a user who forges their proof metadata cannot force the offline
14
- * branch prematurely.
6
+ * Calls the licensing service's GET /verify until the on-chain refund
7
+ * window for the license has closed; from that point on returns from a
8
+ * local anchor and never touches the network again. The refund-window
9
+ * decision is server-side: the service returns `refundWindowClosed:
10
+ * boolean` on its /verify response, computed from its own record of
11
+ * `purchaseSlot + REFUND_WINDOW_N` against the on-chain `currentSlot`.
12
+ * The SDK gates anchor writes on that boolean and never trusts a
13
+ * `purchaseSlot` supplied by the local proof file, so a user who forges
14
+ * their proof metadata cannot force the offline branch prematurely.
15
15
  *
16
16
  * Anchor purity: every field persisted in the Anchor derives from the
17
- * keeper's /verify response — `anchoredSlot`, `expirySlot`, `ownership`.
18
- * The only client-supplied input to the offline branch is
19
- * `proof.expirySlot`, used solely as the loadAnchor binding key. A
20
- * tampered proof file therefore never gets a wrong answer; it gets no
21
- * offline branch at all and falls through to the keeper on every call.
17
+ * service's /verify response — `anchoredSlot`, `expirySlot`. The only
18
+ * client-supplied input to the offline branch is `proof.expirySlot`,
19
+ * used solely as the loadAnchor binding key. A tampered proof file
20
+ * therefore never gets a wrong answer; it gets no offline branch at all
21
+ * and falls through to the licensing service on every call.
22
22
  */
23
23
  import { REFUND_WINDOW_N, GRACE_PERIOD_N, MS_PER_SLOT_N, SLOTS_PER_DAY_N, } from './contractInterface.js';
24
24
  const MS_PER_SLOT = MS_PER_SLOT_N;
25
25
  const SLOTS_PER_DAY = SLOTS_PER_DAY_N;
26
+ // The one and only verify endpoint. Every issued license routes here
27
+ // regardless of network — the platform verifier resolves devnet vs
28
+ // mainnet from the zkAppAddress (each deployment is unique per network).
29
+ // Tests inject a mock via VerifyOptions.fetcher, not by rewriting this URL.
30
+ export const DEFAULT_VERIFIER_URL = 'https://zklicensing.com/api/verify';
31
+ // Anchor records are keyed by (zkAppAddress, licenseHash). zkAppAddress
32
+ // is generation-scoped by construction: each hardfork migration deploys
33
+ // the LicensingApp at a fresh address (see keeper's finalizeRedeploy
34
+ // and AppRecord.deploymentHistory[]), so keying on it implicitly
35
+ // captures generation. An anchor written pre-migration is orphaned by
36
+ // the new address on next verify and re-created cleanly — no
37
+ // cross-generation carry-over.
26
38
  const ANCHOR_KEY_PREFIX = 'zklic_anchor_';
27
- const ACTIVATION_KEY_PREFIX = 'zklic_activation_';
28
- function activationKey(zkAppAddress, licenseHash) {
29
- return `${ACTIVATION_KEY_PREFIX}${zkAppAddress}_${licenseHash}`;
30
- }
31
- export function loadActivation(storage, zkAppAddress, licenseHash, nowMs = Date.now()) {
32
- try {
33
- const raw = storage.getItem(activationKey(zkAppAddress, licenseHash));
34
- if (!raw)
35
- return null;
36
- const rec = JSON.parse(raw);
37
- if (nowMs > rec.expiresAt)
38
- return null;
39
- return rec;
40
- }
41
- catch {
42
- return null;
43
- }
44
- }
45
- export function saveActivation(storage, zkAppAddress, licenseHash, rec) {
46
- try {
47
- storage.setItem(activationKey(zkAppAddress, licenseHash), JSON.stringify(rec));
48
- }
49
- catch {
50
- /* quota / read-only — non-fatal */
51
- }
39
+ function anchorKey(zkAppAddress, licenseHash) {
40
+ return `${ANCHOR_KEY_PREFIX}${zkAppAddress}_${licenseHash}`;
52
41
  }
53
42
  function defaultStorage() {
54
43
  if (typeof globalThis !== 'undefined' && globalThis.localStorage) {
@@ -56,19 +45,20 @@ function defaultStorage() {
56
45
  }
57
46
  return null;
58
47
  }
59
- function loadAnchor(storage, licenseHash, expirySlot) {
48
+ function loadAnchor(storage, zkAppAddress, licenseHash, expirySlot) {
60
49
  try {
61
- const raw = storage.getItem(ANCHOR_KEY_PREFIX + licenseHash);
50
+ const raw = storage.getItem(anchorKey(zkAppAddress, licenseHash));
62
51
  if (!raw)
63
52
  return null;
64
53
  const a = JSON.parse(raw);
65
- // `a.expirySlot` is the KEEPER's value captured at anchor time; the
66
- // `expirySlot` argument is the LOCAL proof file's value. Match ⇒ local
67
- // file agrees with chain truth as of anchoring ⇒ offline is safe.
68
- // Mismatch has two honest meanings:
54
+ // `a.expirySlot` is the SERVICE's value captured at anchor time;
55
+ // the `expirySlot` argument is the LOCAL proof file's value. Match
56
+ // ⇒ local file agrees with chain truth as of anchoring ⇒ offline is
57
+ // safe. Mismatch has two honest meanings:
69
58
  // - renewal: chain moved, local file updated ⇒ re-anchor via chain check
70
- // - forgery: local file edited ⇒ every call falls through to the keeper,
71
- // which reports truth. The forger gets no offline branch at all.
59
+ // - forgery: local file edited ⇒ every call falls through to the
60
+ // licensing service, which reports truth. The forger gets no
61
+ // offline branch at all.
72
62
  if (a.expirySlot !== expirySlot)
73
63
  return null;
74
64
  return a;
@@ -77,9 +67,9 @@ function loadAnchor(storage, licenseHash, expirySlot) {
77
67
  return null;
78
68
  }
79
69
  }
80
- function saveAnchor(storage, licenseHash, anchor) {
70
+ function saveAnchor(storage, zkAppAddress, licenseHash, anchor) {
81
71
  try {
82
- storage.setItem(ANCHOR_KEY_PREFIX + licenseHash, JSON.stringify(anchor));
72
+ storage.setItem(anchorKey(zkAppAddress, licenseHash), JSON.stringify(anchor));
83
73
  }
84
74
  catch {
85
75
  // Storage may be full or read-only; the offline path simply won't activate.
@@ -90,39 +80,6 @@ function computeRemainingDays(expirySlot, currentSlot) {
90
80
  return 0;
91
81
  return Math.floor((expirySlot - currentSlot) / SLOTS_PER_DAY);
92
82
  }
93
- // Renew the activation token when within this window of expiry. Picked so
94
- // that a daily verify call has many chances to refresh before the token dies.
95
- const TOKEN_RENEW_THRESHOLD_MS = 24 * 60 * 60 * 1000;
96
- async function tryActivate(storage, zkAppAddress, licenseHash, current, bootstrapSecretHash, prover, verifierUrl, fetcher, nowMs) {
97
- const secretHash = current?.secretHash ?? bootstrapSecretHash;
98
- if (!secretHash)
99
- return current;
100
- // Existing token still fresh — nothing to do.
101
- if (current?.token && current.expiresAt - nowMs > TOKEN_RENEW_THRESHOLD_MS)
102
- return current;
103
- try {
104
- const base = verifierUrl.replace(/\/+$/, '');
105
- const challengeResp = await fetcher(`${base}/challenge?licenseHash=${encodeURIComponent(licenseHash)}`);
106
- if (!challengeResp.ok)
107
- return current;
108
- const { nonce } = (await challengeResp.json());
109
- const proofJson = await prover({ licenseHash, nonce, secretHash });
110
- const respondResp = await fetcher(`${base}/respond`, {
111
- method: 'POST',
112
- headers: { 'Content-Type': 'application/json' },
113
- body: JSON.stringify({ zkAppAddress, proof: proofJson }),
114
- });
115
- if (!respondResp.ok)
116
- return current;
117
- const { token, expiresAt } = (await respondResp.json());
118
- const next = { token, expiresAt, secretHash };
119
- saveActivation(storage, zkAppAddress, licenseHash, next);
120
- return next;
121
- }
122
- catch {
123
- return current;
124
- }
125
- }
126
83
  function offlineCheck(anchor, nowMs) {
127
84
  const elapsedSlots = Math.max(0, Math.floor((nowMs - anchor.anchoredAtMs) / MS_PER_SLOT));
128
85
  const estCurrentSlot = anchor.anchoredSlot + elapsedSlots;
@@ -142,20 +99,18 @@ function offlineCheck(anchor, nowMs) {
142
99
  ? 'License is in grace period — renew to avoid interruption'
143
100
  : null,
144
101
  source: 'offline',
145
- ownership: anchor.ownership,
146
102
  };
147
103
  }
148
104
  export async function verifyLicense(proof, options = {}) {
149
105
  const storage = options.storage === null ? null : options.storage ?? defaultStorage();
150
106
  const fetcher = options.fetcher ?? (typeof fetch !== 'undefined' ? fetch : undefined);
151
107
  const nowFn = options.now ?? (() => Date.now());
152
- const verifierUrl = options.verifierUrl ?? proof.verifierUrl;
153
108
  if (storage) {
154
- const anchor = loadAnchor(storage, proof.licenseHash, proof.expirySlot);
109
+ const anchor = loadAnchor(storage, proof.zkAppAddress, proof.licenseHash, proof.expirySlot);
155
110
  if (anchor)
156
111
  return offlineCheck(anchor, nowFn());
157
112
  }
158
- if (!verifierUrl || !fetcher) {
113
+ if (!fetcher) {
159
114
  return {
160
115
  valid: false,
161
116
  expirySlot: proof.expirySlot,
@@ -163,24 +118,13 @@ export async function verifyLicense(proof, options = {}) {
163
118
  currentSlot: 0,
164
119
  inGracePeriod: false,
165
120
  remainingDays: 0,
166
- reason: 'No verifier URL or fetcher available; cannot verify',
121
+ reason: 'No fetch implementation available; cannot verify',
167
122
  source: 'chain',
168
- ownership: 'unverified',
169
123
  };
170
124
  }
171
- let activation = storage
172
- ? loadActivation(storage, proof.zkAppAddress, proof.licenseHash, nowFn())
173
- : null;
174
- if (storage && options.prover && (activation || options.secretHash)) {
175
- activation = await tryActivate(storage, proof.zkAppAddress, proof.licenseHash, activation, options.secretHash, options.prover, verifierUrl, fetcher, nowFn());
176
- }
177
- const tokenParam = activation?.token
178
- ? `&token=${encodeURIComponent(activation.token)}`
179
- : '';
180
- const url = `${verifierUrl.replace(/\/+$/, '')}` +
125
+ const url = `${DEFAULT_VERIFIER_URL}` +
181
126
  `?licenseHash=${encodeURIComponent(proof.licenseHash)}` +
182
- `&zkAppAddress=${encodeURIComponent(proof.zkAppAddress)}` +
183
- tokenParam;
127
+ `&zkAppAddress=${encodeURIComponent(proof.zkAppAddress)}`;
184
128
  let data;
185
129
  try {
186
130
  const resp = await fetcher(url);
@@ -194,7 +138,6 @@ export async function verifyLicense(proof, options = {}) {
194
138
  remainingDays: 0,
195
139
  reason: `Verification request failed (HTTP ${resp.status})`,
196
140
  source: 'chain',
197
- ownership: 'unverified',
198
141
  };
199
142
  }
200
143
  data = await resp.json();
@@ -209,13 +152,12 @@ export async function verifyLicense(proof, options = {}) {
209
152
  remainingDays: 0,
210
153
  reason: err?.message ?? 'Verification request errored',
211
154
  source: 'chain',
212
- ownership: 'unverified',
213
155
  };
214
156
  }
215
- // Keeper's authoritative expiry, or null if the response omits it. Only
216
- // the null-safe form may be written into the anchor; the chain-result
217
- // display value below falls back to the local proof file for user-facing
218
- // fields, which is safe (display only).
157
+ // Service's authoritative expiry, or null if the response omits it.
158
+ // Only the null-safe form may be written into the anchor; the
159
+ // chain-result display value below falls back to the local proof file
160
+ // for user-facing fields, which is safe (display only).
219
161
  const respExpirySlotStrict = typeof data.expirySlot === 'number' ? data.expirySlot : null;
220
162
  const respExpirySlot = respExpirySlotStrict ?? proof.expirySlot;
221
163
  const respCurrentSlot = typeof data.currentSlot === 'number' ? data.currentSlot : 0;
@@ -230,24 +172,23 @@ export async function verifyLicense(proof, options = {}) {
230
172
  : computeRemainingDays(respExpirySlot, respCurrentSlot),
231
173
  reason: data.reason ?? null,
232
174
  source: 'chain',
233
- ownership: data.ownership === 'verified' ? 'verified' : 'unverified',
234
175
  };
235
- // Anchor gate uses the keeper's own refund-window decision. The keeper
236
- // knows the true purchaseSlot (stored in its LicenseRecord) and the true
237
- // currentSlot; the SDK never trusts a purchaseSlot or expirySlot supplied
238
- // by the local proof file, since that file is client-writable and could
239
- // be forged. If the keeper omits `expirySlot`, we fail-closed on the
240
- // offline path — no anchor written, subsequent calls stay online.
176
+ // Anchor gate uses the service's own refund-window decision. The
177
+ // service knows the true purchaseSlot (stored in its LicenseRecord)
178
+ // and the true currentSlot; the SDK never trusts a purchaseSlot or
179
+ // expirySlot supplied by the local proof file, since that file is
180
+ // client-writable and could be forged. If the service omits
181
+ // `expirySlot`, we fail-closed on the offline path — no anchor
182
+ // written, subsequent calls stay online.
241
183
  if (storage &&
242
184
  result.valid &&
243
185
  data.refundWindowClosed === true &&
244
186
  typeof data.currentSlot === 'number' &&
245
187
  respExpirySlotStrict !== null) {
246
- saveAnchor(storage, proof.licenseHash, {
188
+ saveAnchor(storage, proof.zkAppAddress, proof.licenseHash, {
247
189
  anchoredSlot: data.currentSlot,
248
190
  anchoredAtMs: nowFn(),
249
191
  expirySlot: respExpirySlotStrict,
250
- ownership: result.ownership,
251
192
  });
252
193
  }
253
194
  return result;
@@ -255,4 +196,32 @@ export async function verifyLicense(proof, options = {}) {
255
196
  // Re-exported so tests and downstream tooling can reference the same values
256
197
  // the SDK uses internally without re-deriving them.
257
198
  export { REFUND_WINDOW_N, GRACE_PERIOD_N, MS_PER_SLOT };
199
+ // Non-custodial device binding surface. Re-exported at the
200
+ // barrel alongside buy / renew / refund so vendor SDK integrators can
201
+ // pull the whole family from a single import path. Each also has its
202
+ // own package subpath (`zklicensing/bind`, `zklicensing/unbind`,
203
+ // `zklicensing/device-identity`) to match the buy / renew / refund
204
+ // convention.
205
+ export { proveBind, confirmBind } from './bindClient.js';
206
+ export { proveUnbind, confirmUnbind } from './unbindClient.js';
207
+ export { getOrCreateDeviceIdentity, computeDeviceCommitment, } from './deviceIdentity.js';
208
+ // Offline device-binding verifier. Vendors reconstruct the
209
+ // LicenseLeaf from a synced snapshot, verify the leaf hash against the
210
+ // last-known licensesRoot, and confirm the caller's device commitment
211
+ // appears in `occupied[]`. Also available at the `zklicensing/verify-offline`
212
+ // subpath for callers that want to minimize their imported surface.
213
+ export { verifyOffline, deviceCommitmentFromFields } from './verifyOffline.js';
214
+ // Non-custodial trust anchor for `verifyOffline`. Reads the live
215
+ // `licensesRoot` (zkapp.appState[0]) directly from Mina — pair it with
216
+ // `verifyOffline` when you do not want to trust the licensing service's
217
+ // reported root. Also available at the `zklicensing/on-chain-root`
218
+ // subpath. o1js is imported lazily so callers that skip this helper
219
+ // don't pay the o1js dep cost at load time.
220
+ export { fetchOnChainLicensesRoot, DEFAULT_MINA_GRAPHQL_URLS } from './onChainRoot.js';
221
+ // Human-readable seat names for the device-binding UI ("Silent Otter",
222
+ // "Curious Panda"). Deterministic in `licenseHash + slotIndex + boundAtSlot`,
223
+ // so every viewer of the same license computes the same name per slot
224
+ // without a naming sidecar. Also available at the `zklicensing/seat-name`
225
+ // subpath.
226
+ export { seatNameFor, SEAT_NAME_COMBINATIONS } from './seatName.js';
258
227
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,eAAe,EACf,cAAc,EACd,aAAa,EACb,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAC1C,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAelD,SAAS,aAAa,CAAC,YAAoB,EAAE,WAAmB;IAC9D,OAAO,GAAG,qBAAqB,GAAG,YAAY,IAAI,WAAW,EAAE,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,YAAoB,EACpB,WAAmB,EACnB,QAAgB,IAAI,CAAC,GAAG,EAAE;IAE1B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAqB,CAAC;QAChD,IAAI,KAAK,GAAG,GAAG,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC;QACvC,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,YAAoB,EACpB,WAAmB,EACnB,GAAqB;IAErB,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,YAAY,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M,oBAAoB,CAAC;AAO/E,iEAAiE;AACjE,uEAAuE;AACvE,wEAAwE;AACxE,mEAAmE;AACnE,oEAAoE;AACpE,4CAA4C;AAC5C,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAGvF,uEAAuE;AACvE,8EAA8E;AAC9E,sEAAsE;AACtE,0EAA0E;AAC1E,WAAW;AACX,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * licenseLeaf.ts
3
+ *
4
+ * On-chain leaf value stored at every occupied `licensesRoot` slot. Bundles
5
+ * the license expiry with the device-binding state (cap, slot commitments,
6
+ * fill counter) so a single tree lookup returns everything a verifier or a
7
+ * `/prove/bind` call needs.
8
+ *
9
+ * Wire shape (in order of hash preimage):
10
+ * licenseHash Field the tree key, also carried in the leaf
11
+ * so a stolen witness can't be re-pointed
12
+ * at another entry. Doubles as the owner-
13
+ * pubkey commitment — buyLicense asserts
14
+ * licenseHash == Poseidon(pk.x, pk.isOdd)
15
+ * so bind/unbind's ownership check reads
16
+ * the same field as the tree key. Storing
17
+ * them separately would be pure redundancy.
18
+ * expirySlot UInt32→Field UInt32 packed into a Field
19
+ * cap UInt32→Field 0 disables /prove/bind; ≤DEVICE_SLOT_CAP
20
+ * (kept as UInt32 in-circuit because o1js's
21
+ * provable types don't include UInt8)
22
+ * deviceSlotsRoot Field Poseidon fold over the 10 slot fields
23
+ * below (2 fields × DEVICE_SLOT_CAP)
24
+ * deviceSlotsFilled UInt32→Field how many of the DEVICE_SLOT_CAP slots
25
+ * are currently non-empty — carried
26
+ * alongside the fold so `bind()` can do
27
+ * a cheap "cap - filled > 0" check
28
+ * without re-summing the array
29
+ *
30
+ * DEVICE_SLOT_CAP is fixed at 5 so the slot arrays have a size known to the
31
+ * circuit at compile time. `cap` in the leaf may be smaller — it's a
32
+ * per-license limit; slots [cap..DEVICE_SLOT_CAP) must always stay empty
33
+ * (Field(0)) and `bind()` rejects any write to them. `cap = 0` disables
34
+ * binding entirely; `bind()` rejects immediately without ever touching a
35
+ * slot.
36
+ *
37
+ * Slot encoding (fields carried in the fold, per slot i):
38
+ * occupied[i] Field 0 (empty) or Poseidon(devicePubKeyHash)
39
+ * freedAt[i] Field packed (boundAtSlot << 32) | freedAtSlot; both
40
+ * are UInt32-range Mina slot numbers. On a fresh
41
+ * empty slot both halves are 0. On bind, boundAt
42
+ * gets the current slot and freedAt stays 0. On
43
+ * unbind, freedAt gets the current slot (boundAt
44
+ * is preserved for audit / cooldown math).
45
+ *
46
+ * The struct + helpers live in the SDK (not the circuit package) so both
47
+ * the on-chain `@method` bodies AND the off-chain keeper / verifier /
48
+ * dashboards can share a single source of truth for the leaf hash. The
49
+ * circuit re-exports them from `LicensingApp.ts` so existing consumers
50
+ * that import from there keep working.
51
+ */
52
+ import { Field, PublicKey, UInt32 } from 'o1js';
53
+ import type { LicenseRecord } from './licenseRecord.js';
54
+ export declare const DEVICE_SLOT_CAP_N = 5;
55
+ export declare const DEVICE_SLOT_CAP: UInt32;
56
+ export declare const EMPTY_DEVICE_SLOTS_ROOT: Field;
57
+ export declare function ownerPubKeyHash(pub: PublicKey): Field;
58
+ export declare function packSlotTimes(boundAtSlot: UInt32, freedAtSlot: UInt32): Field;
59
+ export declare function unpackSlotTimes(packed: Field): {
60
+ boundAtSlot: UInt32;
61
+ freedAtSlot: UInt32;
62
+ };
63
+ export declare function computeDeviceSlotsRoot(occupied: Field[], freedAt: Field[]): Field;
64
+ export declare const DeviceSlot: any;
65
+ export type DeviceSlot = any;
66
+ export declare function emptyDeviceSlot(): DeviceSlot;
67
+ export declare const DeviceSlots: any;
68
+ export type DeviceSlots = any;
69
+ export declare function emptyDeviceSlots(): DeviceSlots;
70
+ export declare function deviceSlotsHash(ds: DeviceSlots): Field;
71
+ export declare const LicenseLeaf: any;
72
+ export type LicenseLeaf = any;
73
+ export declare function leafHash(leaf: LicenseLeaf): Field;
74
+ export declare function freshLeaf(licenseHash: Field, expirySlot: UInt32, cap: UInt32): LicenseLeaf;
75
+ export declare function leafFromRecord(record: LicenseRecord): LicenseLeaf;
76
+ //# sourceMappingURL=licenseLeaf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"licenseLeaf.d.ts","sourceRoot":"","sources":["../src/licenseLeaf.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAE,KAAK,EAAsB,SAAS,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMxD,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,eAAe,QAAiC,CAAC;AAK9D,eAAO,MAAM,uBAAuB,EAAE,KAErC,CAAC;AAOF,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS,GAAG,KAAK,CAErD;AASD,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,KAAK,CAE7E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAQ3F;AAMD,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,KAAK,EAAE,EACjB,OAAO,EAAG,KAAK,EAAE,GAChB,KAAK,CAYP;AAYD,eAAO,MAAM,UAAU,EAAE,GAGvB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC;AAE7B,wBAAgB,eAAe,IAAI,UAAU,CAE5C;AAID,eAAO,MAAM,WAAW,EAAE,GAExB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,GAAG,CAAC;AAE9B,wBAAgB,gBAAgB,IAAI,WAAW,CAI9C;AAKD,wBAAgB,eAAe,CAAC,EAAE,EAAE,WAAW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