zklicensing 0.1.0-beta.2 → 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 (173) hide show
  1. package/README.md +335 -97
  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 -0
  8. package/build/archiveBootstrap.js +62 -9
  9. package/build/archiveBootstrap.js.map +1 -0
  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 +10 -3
  15. package/build/buyClient.d.ts.map +1 -0
  16. package/build/buyClient.js +33 -15
  17. package/build/buyClient.js.map +1 -0
  18. package/build/contractInterface.d.ts +11 -5
  19. package/build/contractInterface.d.ts.map +1 -0
  20. package/build/contractInterface.js +82 -17
  21. package/build/contractInterface.js.map +1 -0
  22. package/build/countryStats.d.ts +6 -1
  23. package/build/countryStats.d.ts.map +1 -0
  24. package/build/countryStats.js +33 -9
  25. package/build/countryStats.js.map +1 -0
  26. package/build/deployClient.d.ts.map +1 -0
  27. package/build/deployClient.js +1 -1
  28. package/build/deployClient.js.map +1 -0
  29. package/build/deviceIdentity.d.ts +68 -0
  30. package/build/deviceIdentity.d.ts.map +1 -0
  31. package/build/deviceIdentity.js +209 -0
  32. package/build/deviceIdentity.js.map +1 -0
  33. package/build/freezeClient.d.ts.map +1 -0
  34. package/build/freezeClient.js +1 -1
  35. package/build/freezeClient.js.map +1 -0
  36. package/build/generationClient.d.ts +1 -0
  37. package/build/generationClient.d.ts.map +1 -0
  38. package/build/generationClient.js +2 -2
  39. package/build/generationClient.js.map +1 -0
  40. package/build/index.d.ts +27 -37
  41. package/build/index.d.ts.map +1 -0
  42. package/build/index.js +85 -116
  43. package/build/index.js.map +1 -0
  44. package/build/licenseLeaf.d.ts +76 -0
  45. package/build/licenseLeaf.d.ts.map +1 -0
  46. package/build/licenseLeaf.js +189 -0
  47. package/build/licenseLeaf.js.map +1 -0
  48. package/build/licenseRecord.d.ts +20 -1
  49. package/build/licenseRecord.d.ts.map +1 -0
  50. package/build/licenseRecord.js +1 -1
  51. package/build/licenseRecord.js.map +1 -0
  52. package/build/licenseStore.d.ts +17 -2
  53. package/build/licenseStore.d.ts.map +1 -0
  54. package/build/licenseStore.js +167 -7
  55. package/build/licenseStore.js.map +1 -0
  56. package/build/manifestVerify.d.ts.map +1 -0
  57. package/build/manifestVerify.js +8 -3
  58. package/build/manifestVerify.js.map +1 -0
  59. package/build/migrateClient.d.ts +6 -21
  60. package/build/migrateClient.d.ts.map +1 -0
  61. package/build/migrateClient.js +30 -17
  62. package/build/migrateClient.js.map +1 -0
  63. package/build/onChainRoot.d.ts +67 -0
  64. package/build/onChainRoot.d.ts.map +1 -0
  65. package/build/onChainRoot.js +87 -0
  66. package/build/onChainRoot.js.map +1 -0
  67. package/build/ownershipLicenseHash.d.ts +25 -0
  68. package/build/ownershipLicenseHash.d.ts.map +1 -0
  69. package/build/ownershipLicenseHash.js +29 -0
  70. package/build/ownershipLicenseHash.js.map +1 -0
  71. package/build/ownershipSignature.d.ts +122 -0
  72. package/build/ownershipSignature.d.ts.map +1 -0
  73. package/build/ownershipSignature.js +244 -0
  74. package/build/ownershipSignature.js.map +1 -0
  75. package/build/proveErrors.d.ts +35 -0
  76. package/build/proveErrors.d.ts.map +1 -0
  77. package/build/proveErrors.js +49 -0
  78. package/build/proveErrors.js.map +1 -0
  79. package/build/refundClient.d.ts +2 -11
  80. package/build/refundClient.d.ts.map +1 -0
  81. package/build/refundClient.js +35 -17
  82. package/build/refundClient.js.map +1 -0
  83. package/build/renewClient.d.ts +4 -1
  84. package/build/renewClient.d.ts.map +1 -0
  85. package/build/renewClient.js +11 -4
  86. package/build/renewClient.js.map +1 -0
  87. package/build/seatName.d.ts +8 -0
  88. package/build/seatName.d.ts.map +1 -0
  89. package/build/seatName.js +136 -0
  90. package/build/seatName.js.map +1 -0
  91. package/build/statsClient.d.ts +47 -4
  92. package/build/statsClient.d.ts.map +1 -0
  93. package/build/statsClient.js +44 -5
  94. package/build/statsClient.js.map +1 -0
  95. package/build/trustAnchorVerify.d.ts +48 -0
  96. package/build/trustAnchorVerify.d.ts.map +1 -0
  97. package/build/trustAnchorVerify.js +431 -0
  98. package/build/trustAnchorVerify.js.map +1 -0
  99. package/build/trustAnchorVerifyCli.d.ts +35 -0
  100. package/build/trustAnchorVerifyCli.d.ts.map +1 -0
  101. package/build/trustAnchorVerifyCli.js +177 -0
  102. package/build/trustAnchorVerifyCli.js.map +1 -0
  103. package/build/txBroadcastClient.d.ts +26 -0
  104. package/build/txBroadcastClient.d.ts.map +1 -0
  105. package/build/txBroadcastClient.js +20 -0
  106. package/build/txBroadcastClient.js.map +1 -0
  107. package/build/unbindClient.d.ts +56 -0
  108. package/build/unbindClient.d.ts.map +1 -0
  109. package/build/unbindClient.js +113 -0
  110. package/build/unbindClient.js.map +1 -0
  111. package/build/vendorAccountClient.d.ts +56 -0
  112. package/build/vendorAccountClient.d.ts.map +1 -0
  113. package/build/vendorAccountClient.js +47 -0
  114. package/build/vendorAccountClient.js.map +1 -0
  115. package/build/verifyCore.d.ts +1 -1
  116. package/build/verifyCore.d.ts.map +1 -0
  117. package/build/verifyCore.js +11 -4
  118. package/build/verifyCore.js.map +1 -0
  119. package/build/verifyOffline.d.ts +85 -0
  120. package/build/verifyOffline.d.ts.map +1 -0
  121. package/build/verifyOffline.js +139 -0
  122. package/build/verifyOffline.js.map +1 -0
  123. package/build/verifyService.d.ts.map +1 -0
  124. package/build/verifyService.js +582 -455
  125. package/build/verifyService.js.map +1 -0
  126. package/build/verifyWithAncestors.d.ts +18 -0
  127. package/build/verifyWithAncestors.d.ts.map +1 -0
  128. package/build/verifyWithAncestors.js +119 -0
  129. package/build/verifyWithAncestors.js.map +1 -0
  130. package/build/zipToState.d.ts +2 -0
  131. package/build/zipToState.d.ts.map +1 -0
  132. package/build/zipToState.js +94 -0
  133. package/build/zipToState.js.map +1 -0
  134. package/package.json +57 -13
  135. package/src/appsLookup.ts +48 -0
  136. package/src/archiveBootstrap.ts +342 -0
  137. package/src/bindClient.ts +175 -0
  138. package/src/buyClient.ts +304 -0
  139. package/src/contractInterface.d.ts +61 -0
  140. package/src/contractInterface.ts +313 -0
  141. package/src/countryStats.ts +171 -0
  142. package/src/deployClient.ts +388 -0
  143. package/src/deviceIdentity.ts +249 -0
  144. package/src/freezeClient.ts +117 -0
  145. package/src/generationClient.ts +165 -0
  146. package/src/index.ts +329 -0
  147. package/src/licenseLeaf.ts +221 -0
  148. package/src/licenseRecord.ts +108 -0
  149. package/src/licenseStore.ts +538 -0
  150. package/src/manifestVerify.ts +111 -0
  151. package/src/migrateClient.ts +84 -0
  152. package/src/onChainRoot.ts +107 -0
  153. package/src/ownershipLicenseHash.ts +31 -0
  154. package/src/ownershipSignature.ts +354 -0
  155. package/src/proveErrors.ts +70 -0
  156. package/src/refundClient.ts +158 -0
  157. package/src/renewClient.ts +214 -0
  158. package/src/seatName.ts +165 -0
  159. package/src/statsClient.ts +235 -0
  160. package/src/trustAnchorVerify.ts +548 -0
  161. package/src/trustAnchorVerifyCli.ts +179 -0
  162. package/src/txBroadcastClient.ts +48 -0
  163. package/src/unbindClient.ts +149 -0
  164. package/src/vendorAccountClient.ts +110 -0
  165. package/src/verifyCore.ts +92 -0
  166. package/src/verifyOffline.ts +212 -0
  167. package/src/verifyService.ts +969 -0
  168. package/src/verifyWithAncestors.ts +153 -0
  169. package/src/zipToState.ts +94 -0
  170. package/build/licenseProof.d.ts +0 -26
  171. package/build/licenseProof.js +0 -41
  172. package/build/ownership.d.ts +0 -34
  173. package/build/ownership.js +0 -147
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env node
2
+ // Copyright (c) 2025-2026 zkLicensing project developers
3
+ // SPDX-License-Identifier: BUSL-1.1
4
+ /**
5
+ * trustAnchorVerifyCli.ts
6
+ *
7
+ * Command-line front-end for verifyTrustAnchor(). Ships as the `zklicensing-verify-trust`
8
+ * bin — the sibling of `zklicensing-verify` (which is the verifyService HTTP daemon).
9
+ *
10
+ * Usage:
11
+ * zklicensing-verify-trust \
12
+ * --origin https://store.example.com \
13
+ * --address B62q... \
14
+ * --pinned-key <base64-ed25519-pubkey> \
15
+ * [--mina-graphql https://api.minascan.io/node/mainnet/v1/graphql] \
16
+ * [--mina-network-id mainnet|testnet|devnet] \
17
+ * [--skip-chain-checks] \
18
+ * [--json]
19
+ *
20
+ * The manifest lives at `<origin>/.well-known/zklicensing/<address>.json` —
21
+ * one file per generation address, all signed by the same platform key. The
22
+ * appId is read out of the signed payload; callers never need to know it
23
+ * out-of-band, which lets buyers verify from just the address their wallet
24
+ * shows them (including addresses for retired generations).
25
+ *
26
+ * Exit codes:
27
+ * 0 — every finding passed
28
+ * 1 — one or more findings failed
29
+ * 2 — invalid arguments
30
+ *
31
+ * --pinned-key is required and may be repeated; the CLI ships NO baked-in
32
+ * pin. Source it from https://zklicensing.com/trustanchor.html (published
33
+ * next to each generation's VK hash). See the SDK README for details.
34
+ */
35
+ import { verifyTrustAnchor } from './trustAnchorVerify.js';
36
+ const DEFAULT_MAINNET_GRAPHQL = 'https://api.minascan.io/node/mainnet/v1/graphql';
37
+ function usage() {
38
+ return [
39
+ 'zklicensing-verify-trust — verify a vendor page + on-chain zkApp mutually bind',
40
+ '',
41
+ 'Required:',
42
+ ' --origin <url> Vendor origin (https://...)',
43
+ ' --address <B62q...> zkApp address (the address your wallet shows you)',
44
+ ' --pinned-key <b64> Platform manifest pubkey (repeatable during rotation)',
45
+ '',
46
+ 'Optional:',
47
+ ` --mina-graphql <url> Mina GraphQL endpoint (default: ${DEFAULT_MAINNET_GRAPHQL})`,
48
+ ' --mina-network-id <id> mainnet | testnet | devnet (default: mainnet)',
49
+ ' --skip-chain-checks Manifest-only audit — no o1js chain reads',
50
+ ' --cross-check Also verify vendor manifest matches the',
51
+ ' zkLicensing backend record at',
52
+ ' https://zklicensing.com/apps/by-address/<address>',
53
+ ' --json Emit TrustAnchorReport as JSON on stdout',
54
+ '',
55
+ 'Exit: 0 all-ok · 1 any check failed · 2 bad args',
56
+ ].join('\n');
57
+ }
58
+ function parseArgs(argv) {
59
+ const args = {
60
+ pinnedKeys: [],
61
+ minaGraphql: DEFAULT_MAINNET_GRAPHQL,
62
+ minaNetworkId: 'mainnet',
63
+ skipChainChecks: false,
64
+ crossCheck: false,
65
+ json: false,
66
+ help: false,
67
+ };
68
+ for (let i = 0; i < argv.length; i++) {
69
+ const a = argv[i];
70
+ const next = () => {
71
+ const v = argv[++i];
72
+ if (v === undefined)
73
+ throw new Error(`missing value for ${a}`);
74
+ return v;
75
+ };
76
+ switch (a) {
77
+ case '--origin':
78
+ args.origin = next();
79
+ break;
80
+ case '--address':
81
+ args.address = next();
82
+ break;
83
+ case '--pinned-key':
84
+ args.pinnedKeys.push(next());
85
+ break;
86
+ case '--mina-graphql':
87
+ args.minaGraphql = next();
88
+ break;
89
+ case '--mina-network-id': {
90
+ const v = next();
91
+ if (v !== 'mainnet' && v !== 'testnet' && v !== 'devnet') {
92
+ throw new Error(`--mina-network-id must be mainnet|testnet|devnet, got "${v}"`);
93
+ }
94
+ args.minaNetworkId = v;
95
+ break;
96
+ }
97
+ case '--skip-chain-checks':
98
+ args.skipChainChecks = true;
99
+ break;
100
+ case '--cross-check':
101
+ args.crossCheck = true;
102
+ break;
103
+ case '--json':
104
+ args.json = true;
105
+ break;
106
+ case '-h':
107
+ case '--help':
108
+ args.help = true;
109
+ break;
110
+ default: throw new Error(`unknown argument: ${a}`);
111
+ }
112
+ }
113
+ return args;
114
+ }
115
+ function formatHuman(report) {
116
+ const lines = [];
117
+ const banner = report.ok ? 'TRUST ANCHOR VERIFIED' : 'TRUST ANCHOR FAILED';
118
+ lines.push(banner);
119
+ lines.push(` origin: ${report.origin}`);
120
+ lines.push(` address: ${report.address}`);
121
+ if (report.appId)
122
+ lines.push(` appId: ${report.appId}`);
123
+ if (report.generation !== undefined)
124
+ lines.push(` generation: ${report.generation}`);
125
+ lines.push('');
126
+ for (const f of report.findings) {
127
+ const mark = f.ok ? '[ok] ' : '[FAIL]';
128
+ lines.push(` ${mark} ${f.name} — ${f.detail}`);
129
+ }
130
+ return lines.join('\n');
131
+ }
132
+ async function main() {
133
+ let args;
134
+ try {
135
+ args = parseArgs(process.argv.slice(2));
136
+ }
137
+ catch (err) {
138
+ process.stderr.write(`${err.message}\n\n${usage()}\n`);
139
+ return 2;
140
+ }
141
+ if (args.help) {
142
+ process.stdout.write(`${usage()}\n`);
143
+ return 0;
144
+ }
145
+ const missing = [];
146
+ if (!args.origin)
147
+ missing.push('--origin');
148
+ if (!args.address)
149
+ missing.push('--address');
150
+ if (args.pinnedKeys.length === 0)
151
+ missing.push('--pinned-key');
152
+ if (missing.length > 0) {
153
+ process.stderr.write(`missing required argument(s): ${missing.join(', ')}\n\n${usage()}\n`);
154
+ return 2;
155
+ }
156
+ const report = await verifyTrustAnchor({
157
+ origin: args.origin,
158
+ address: args.address,
159
+ pinnedPublicKeysBase64: args.pinnedKeys,
160
+ minaGraphqlUrl: args.minaGraphql,
161
+ minaNetworkId: args.minaNetworkId,
162
+ skipChainChecks: args.skipChainChecks,
163
+ crossCheck: args.crossCheck,
164
+ });
165
+ if (args.json) {
166
+ process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
167
+ }
168
+ else {
169
+ process.stdout.write(`${formatHuman(report)}\n`);
170
+ }
171
+ return report.ok ? 0 : 1;
172
+ }
173
+ main().then((code) => process.exit(code), (err) => {
174
+ process.stderr.write(`unexpected error: ${err?.stack ?? err}\n`);
175
+ process.exit(1);
176
+ });
177
+ //# sourceMappingURL=trustAnchorVerifyCli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorVerifyCli.js","sourceRoot":"","sources":["../src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,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,IAAI,EAAE,CAAC,IAAI,CACT,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5B,CAAC,GAAG,EAAE,EAAE;IACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CACF,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * txBroadcastClient.ts
3
+ *
4
+ * Small helper for POST /tx-broadcast. Called by the buy/renew/migrate
5
+ * flows immediately after the buyer's wallet returns a txHash — signals
6
+ * the keeper to extend the app's in-flight slot from the short signing-TTL
7
+ * to the longer landing-TTL, so concurrent buyers on the same app don't
8
+ * think the slot has expired while an honest signed tx is still in the
9
+ * mempool.
10
+ *
11
+ * Fire-and-forget by design: this is a tightening signal, not a
12
+ * correctness dependency. Land-clear in the buy-watcher and the
13
+ * signing-TTL both remain live regardless of whether this call succeeds.
14
+ * Failures are swallowed with an optional log callback so a network blip
15
+ * doesn't surface as a confusing error mid-checkout.
16
+ */
17
+ export type NotifyBroadcastRequest = {
18
+ keeperUrl: string;
19
+ appId: string;
20
+ txHash: string;
21
+ fetcher?: typeof fetch;
22
+ signal?: AbortSignal;
23
+ onError?: (err: unknown) => void;
24
+ };
25
+ export declare function notifyBroadcast(req: NotifyBroadcastRequest): Promise<void>;
26
+ //# sourceMappingURL=txBroadcastClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"txBroadcastClient.d.ts","sourceRoot":"","sources":["../src/txBroadcastClient.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAM,MAAM,CAAC;IAClB,MAAM,EAAK,MAAM,CAAC;IAClB,OAAO,CAAC,EAAG,OAAO,KAAK,CAAC;IACxB,MAAM,CAAC,EAAI,WAAW,CAAC;IAGvB,OAAO,CAAC,EAAG,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CACnC,CAAC;AAMF,wBAAsB,eAAe,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAYhF"}
@@ -0,0 +1,20 @@
1
+ // Copyright (c) 2025-2026 zkLicensing project developers
2
+ // SPDX-License-Identifier: BUSL-1.1
3
+ function baseUrl(url) {
4
+ return url.replace(/\/+$/, '');
5
+ }
6
+ export async function notifyBroadcast(req) {
7
+ const fetcher = req.fetcher ?? fetch;
8
+ try {
9
+ await fetcher(`${baseUrl(req.keeperUrl)}/tx-broadcast`, {
10
+ method: 'POST',
11
+ headers: { 'Content-Type': 'application/json' },
12
+ signal: req.signal,
13
+ body: JSON.stringify({ appId: req.appId, txHash: req.txHash }),
14
+ });
15
+ }
16
+ catch (err) {
17
+ req.onError?.(err);
18
+ }
19
+ }
20
+ //# sourceMappingURL=txBroadcastClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"txBroadcastClient.js","sourceRoot":"","sources":["../src/txBroadcastClient.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AA8BpC,SAAS,OAAO,CAAC,GAAW;IAC1B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAA2B;IAC/D,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE;YACtD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;SAC/D,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * unbindClient.ts
3
+ *
4
+ * Browser-safe client for the non-custodial device-unbinding flow.
5
+ * Mirrors `bindClient.ts` in shape: signs the unbind message with
6
+ * TAG_UNBINDING, POSTs to /prove/unbind, then /confirm/unbind after
7
+ * the wallet returns a txHash.
8
+ *
9
+ * Notable asymmetry with bind: the unbind message shape carries the
10
+ * deviceCommitment position too, but the backend and circuit both
11
+ * hard-code it to `Field(0)` (the "not about any specific new
12
+ * device" sentinel — the message is about freeing a slot, not
13
+ * introducing a new device). The SDK matches by omitting
14
+ * deviceCommitment from the request and using "0" when computing
15
+ * the signature preimage.
16
+ *
17
+ * Non-custodial invariant: the signature is re-verified in-circuit
18
+ * against the leaf's `licenseHash` (which IS the owner-pubkey
19
+ * commitment — the circuit asserts equality at buy time), so no
20
+ * backend / vendor can unilaterally kick a device — only the
21
+ * passphrase holder can.
22
+ * A user who lost the physical device but still has the passphrase
23
+ * can unbind the missing device's slot from any device that holds
24
+ * the ownership key (the "remote log-off" case).
25
+ */
26
+ import { PrivateKey } from 'o1js';
27
+ export type ProveUnbindRequest = {
28
+ keeperUrl: string;
29
+ network: 'devnet' | 'mainnet';
30
+ zkAppAddress: string;
31
+ licenseHash: string;
32
+ ownerPrivateKey: PrivateKey;
33
+ slotIndex: number;
34
+ buyerAddress: string;
35
+ nonce?: string;
36
+ fetcher?: typeof fetch;
37
+ signal?: AbortSignal;
38
+ };
39
+ export type ProveUnbindResponse = {
40
+ provenTxJson: string;
41
+ licenseHash: string;
42
+ slotIndex: number;
43
+ };
44
+ export type ConfirmUnbindRequest = {
45
+ keeperUrl: string;
46
+ zkAppAddress: string;
47
+ licenseHash: string;
48
+ txHash: string;
49
+ fetcher?: typeof fetch;
50
+ signal?: AbortSignal;
51
+ };
52
+ export declare function proveUnbind(req: ProveUnbindRequest): Promise<ProveUnbindResponse>;
53
+ export declare function confirmUnbind(req: ConfirmUnbindRequest): Promise<{
54
+ ok: true;
55
+ }>;
56
+ //# sourceMappingURL=unbindClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbindClient.d.ts","sourceRoot":"","sources":["../src/unbindClient.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAS,UAAU,EAAwB,MAAM,MAAM,CAAC;AAI/D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAQ,MAAM,CAAC;IACxB,OAAO,EAAU,QAAQ,GAAG,SAAS,CAAC;IACtC,YAAY,EAAK,MAAM,CAAC;IACxB,WAAW,EAAM,MAAM,CAAC;IACxB,eAAe,EAAE,UAAU,CAAC;IAE5B,SAAS,EAAQ,MAAM,CAAC;IACxB,YAAY,EAAK,MAAM,CAAC;IAGxB,KAAK,CAAC,EAAW,MAAM,CAAC;IACxB,OAAO,CAAC,EAAS,OAAO,KAAK,CAAC;IAC9B,MAAM,CAAC,EAAU,WAAW,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAG,MAAM,CAAC;IACrB,SAAS,EAAK,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAK,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAG,MAAM,CAAC;IACrB,MAAM,EAAQ,MAAM,CAAC;IACrB,OAAO,CAAC,EAAM,OAAO,KAAK,CAAC;IAC3B,MAAM,CAAC,EAAO,WAAW,CAAC;CAC3B,CAAC;AAgCF,wBAAsB,WAAW,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAqCvF;AAGD,wBAAsB,aAAa,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,CAcpF"}
@@ -0,0 +1,113 @@
1
+ // Copyright (c) 2025-2026 zkLicensing project developers
2
+ // SPDX-License-Identifier: BUSL-1.1
3
+ /**
4
+ * unbindClient.ts
5
+ *
6
+ * Browser-safe client for the non-custodial device-unbinding flow.
7
+ * Mirrors `bindClient.ts` in shape: signs the unbind message with
8
+ * TAG_UNBINDING, POSTs to /prove/unbind, then /confirm/unbind after
9
+ * the wallet returns a txHash.
10
+ *
11
+ * Notable asymmetry with bind: the unbind message shape carries the
12
+ * deviceCommitment position too, but the backend and circuit both
13
+ * hard-code it to `Field(0)` (the "not about any specific new
14
+ * device" sentinel — the message is about freeing a slot, not
15
+ * introducing a new device). The SDK matches by omitting
16
+ * deviceCommitment from the request and using "0" when computing
17
+ * the signature preimage.
18
+ *
19
+ * Non-custodial invariant: the signature is re-verified in-circuit
20
+ * against the leaf's `licenseHash` (which IS the owner-pubkey
21
+ * commitment — the circuit asserts equality at buy time), so no
22
+ * backend / vendor can unilaterally kick a device — only the
23
+ * passphrase holder can.
24
+ * A user who lost the physical device but still has the passphrase
25
+ * can unbind the missing device's slot from any device that holds
26
+ * the ownership key (the "remote log-off" case).
27
+ */
28
+ import { Field } from 'o1js';
29
+ import { readErrorBody, tryQueueBusyFromBody } from './proveErrors.js';
30
+ import { encodePublicKey, encodeSignature, signUnbinding } from './ownershipSignature.js';
31
+ function baseUrl(url) {
32
+ return url.replace(/\/+$/, '');
33
+ }
34
+ async function readJsonError(resp) {
35
+ try {
36
+ const body = await resp.json();
37
+ if (typeof body.error === 'string')
38
+ return body.error;
39
+ }
40
+ catch { /* body wasn't JSON */ }
41
+ return `HTTP ${resp.status}`;
42
+ }
43
+ function freshNonce() {
44
+ const crypto = globalThis.crypto;
45
+ if (!crypto?.getRandomValues) {
46
+ throw new Error('crypto.getRandomValues unavailable — unbindClient requires Node ≥ 20 or a modern browser');
47
+ }
48
+ const bytes = new Uint8Array(16); // 128 bits
49
+ crypto.getRandomValues(bytes);
50
+ let n = 0n;
51
+ for (const b of bytes)
52
+ n = (n << 8n) | BigInt(b);
53
+ return Field(n).toString();
54
+ }
55
+ // POST /prove/unbind — same retry contract as /prove/bind. Returns
56
+ // 409 `ProveQueueBusyError` when another root-mutating tx for the
57
+ // same app is in flight; the caller retries with the server-supplied
58
+ // `retryAfterMs` cadence.
59
+ export async function proveUnbind(req) {
60
+ const fetcher = req.fetcher ?? fetch;
61
+ const nonce = req.nonce ?? freshNonce();
62
+ const ownerPubKey = req.ownerPrivateKey.toPublicKey();
63
+ // deviceCommitment=0 for the preimage — matches TAG_UNBINDING's
64
+ // circuit-side check (see verifyUnbinding / bindingLikeFields in
65
+ // ownershipSignature.ts).
66
+ const ownerSig = signUnbinding(req.ownerPrivateKey, {
67
+ licenseHash: req.licenseHash,
68
+ deviceCommitment: '0',
69
+ slotIndex: req.slotIndex,
70
+ nonce,
71
+ });
72
+ const resp = await fetcher(`${baseUrl(req.keeperUrl)}/prove/unbind`, {
73
+ method: 'POST',
74
+ headers: { 'Content-Type': 'application/json' },
75
+ signal: req.signal,
76
+ body: JSON.stringify({
77
+ licenseHash: req.licenseHash,
78
+ buyerAddress: req.buyerAddress,
79
+ zkAppAddress: req.zkAppAddress,
80
+ network: req.network,
81
+ ownerPubKey: encodePublicKey(ownerPubKey),
82
+ ownerSig: encodeSignature(ownerSig),
83
+ slotIndex: req.slotIndex,
84
+ nonce,
85
+ }),
86
+ });
87
+ if (!resp.ok) {
88
+ const parsed = await readErrorBody(resp);
89
+ const queueBusy = tryQueueBusyFromBody(parsed);
90
+ if (queueBusy)
91
+ throw queueBusy;
92
+ throw new Error(parsed.message);
93
+ }
94
+ return await resp.json();
95
+ }
96
+ // POST /confirm/unbind — pass-through no-op mirror of /confirm/bind.
97
+ export async function confirmUnbind(req) {
98
+ const fetcher = req.fetcher ?? fetch;
99
+ const resp = await fetcher(`${baseUrl(req.keeperUrl)}/confirm/unbind`, {
100
+ method: 'POST',
101
+ headers: { 'Content-Type': 'application/json' },
102
+ signal: req.signal,
103
+ body: JSON.stringify({
104
+ zkAppAddress: req.zkAppAddress,
105
+ licenseHash: req.licenseHash,
106
+ txHash: req.txHash,
107
+ }),
108
+ });
109
+ if (!resp.ok)
110
+ throw new Error(await readJsonError(resp));
111
+ return { ok: true };
112
+ }
113
+ //# sourceMappingURL=unbindClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbindClient.js","sourceRoot":"","sources":["../src/unbindClient.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,KAAK,EAAoC,MAAM,MAAM,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAiC1F,SAAS,OAAO,CAAC,GAAW;IAC1B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,IAAc;IACzC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAA6B,CAAC;QAC1D,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC;IAClC,OAAO,QAAQ,IAAI,CAAC,MAAM,E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G,CAAC,MAAM;SACzB,CAAC;KACH,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * vendorAccountClient.ts
3
+ *
4
+ * Browser-safe client for the vendor's shared legal/billing block —
5
+ * the fields that must stay consistent across every app registered by
6
+ * one vendor wallet (legal entity name, billing country and address,
7
+ * VAT id, company registry). One PATCH updates all of the vendor's
8
+ * apps atomically on the keeper, so a legal-entity rename or address
9
+ * move doesn't leave old apps advertising stale CRD Art. 6 disclosures.
10
+ *
11
+ * Signature covers the vendor address, mirroring the "sign the
12
+ * resource id" pattern PUT /apps/:appId uses. The keeper verifies
13
+ * against the on-chain vendor recorded on the app records.
14
+ */
15
+ export type VendorLegalBlock = {
16
+ country?: string;
17
+ legalName?: string;
18
+ billingAddress?: {
19
+ line1: string;
20
+ line2?: string;
21
+ city: string;
22
+ postalCode: string;
23
+ };
24
+ invoiceEmail?: string;
25
+ vatId?: string;
26
+ companyRegistrationRegistry?: string;
27
+ companyRegistrationNumber?: string;
28
+ };
29
+ export type GetVendorLegalRequest = {
30
+ keeperUrl: string;
31
+ vendorAddress: string;
32
+ vendorSessionToken: string;
33
+ fetcher?: typeof fetch;
34
+ signal?: AbortSignal;
35
+ };
36
+ export type GetVendorLegalResponse = {
37
+ legal: VendorLegalBlock | null;
38
+ };
39
+ export type UpdateVendorLegalRequest = {
40
+ keeperUrl: string;
41
+ vendorAddress: string;
42
+ signature: {
43
+ field: string;
44
+ scalar: string;
45
+ };
46
+ payload: VendorLegalBlock;
47
+ fetcher?: typeof fetch;
48
+ signal?: AbortSignal;
49
+ };
50
+ export type UpdateVendorLegalResponse = {
51
+ ok: true;
52
+ appsUpdated: number;
53
+ };
54
+ export declare function getVendorLegal(req: GetVendorLegalRequest): Promise<GetVendorLegalResponse>;
55
+ export declare function updateVendorLegal(req: UpdateVendorLegalRequest): Promise<UpdateVendorLegalResponse>;
56
+ //# sourceMappingURL=vendorAccountClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vendorAccountClient.d.ts","sourceRoot":"","sources":["../src/vendorAccountClient.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAW,MAAM,CAAC;IAC3B,aAAa,EAAO,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAY,OAAO,KAAK,CAAC;IACjC,MAAM,CAAC,EAAa,WAAW,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IAGnC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAM,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAM;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,OAAO,EAAQ,gBAAgB,CAAC;IAChC,OAAO,CAAC,EAAO,OAAO,KAAK,CAAC;IAC5B,MAAM,CAAC,EAAQ,WAAW,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,EAAW,IAAI,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAgBF,wBAAsB,cAAc,CAAC,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAWhG;AAOD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAgBzG"}
@@ -0,0 +1,47 @@
1
+ // Copyright (c) 2025-2026 zkLicensing project developers
2
+ // SPDX-License-Identifier: BUSL-1.1
3
+ function baseUrl(url) {
4
+ return url.replace(/\/+$/, '');
5
+ }
6
+ async function readJsonError(resp) {
7
+ try {
8
+ const body = await resp.json();
9
+ if (typeof body.error === 'string')
10
+ return body.error;
11
+ }
12
+ catch { /* body wasn't JSON */ }
13
+ return `HTTP ${resp.status}`;
14
+ }
15
+ // GET /vendors/:address/legal — fetch the shared legal block for a wallet.
16
+ // Returns `{ legal: null }` for wallets with no registered apps.
17
+ export async function getVendorLegal(req) {
18
+ const fetcher = req.fetcher ?? fetch;
19
+ const resp = await fetcher(`${baseUrl(req.keeperUrl)}/vendors/${encodeURIComponent(req.vendorAddress)}/legal`, {
20
+ signal: req.signal,
21
+ headers: { Authorization: `VendorSession ${req.vendorSessionToken}` },
22
+ });
23
+ if (!resp.ok)
24
+ throw new Error(await readJsonError(resp));
25
+ return await resp.json();
26
+ }
27
+ // PATCH /vendors/:address/legal — updates the block on EVERY app the vendor
28
+ // owns in a single atomic sweep. Bypasses the pendingEdit staging that
29
+ // per-app metadata edits go through; legal fields are factual (not
30
+ // marketing copy) so admin review doesn't gain anything and staleness
31
+ // hurts CRD Art. 6 compliance.
32
+ export async function updateVendorLegal(req) {
33
+ const fetcher = req.fetcher ?? fetch;
34
+ const resp = await fetcher(`${baseUrl(req.keeperUrl)}/vendors/${encodeURIComponent(req.vendorAddress)}/legal`, {
35
+ method: 'PATCH',
36
+ headers: { 'Content-Type': 'application/json' },
37
+ signal: req.signal,
38
+ body: JSON.stringify({
39
+ signature: req.signature,
40
+ payload: req.payload,
41
+ }),
42
+ });
43
+ if (!resp.ok)
44
+ throw new Error(await readJsonError(resp));
45
+ return await resp.json();
46
+ }
47
+ //# sourceMappingURL=vendorAccountClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vendorAccountClient.js","sourceRoot":"","sources":["../src/vendorAccountClient.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AA4DpC,SAAS,OAAO,CAAC,GAAW;IAC1B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,IAAc;IACzC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAA6B,CAAC;QAC1D,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC;IAClC,OAAO,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;AAC/B,CAAC;AAED,2EAA2E;AAC3E,iEAAiE;AACjE,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAA0B;IAC7D,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,OAAO,CACxB,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,EAClF;QACE,MAAM,EAAG,GAAG,CAAC,MAAM;QACnB,OAAO,EAAE,EAAE,aAAa,EAAE,iBAAiB,GAAG,CAAC,kBAAkB,EAAE,EAAE;KACtE,CACF,CAAC;IACF,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,OAAO,MAAM,IAAI,CAAC,IAAI,EAA4B,CAAC;AACrD,CAAC;AAED,4EAA4E;AAC5E,uEAAuE;AACvE,mEAAmE;AACnE,sEAAsE;AACtE,+BAA+B;AAC/B,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAA6B;IACnE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,OAAO,CACxB,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,EAClF;QACE,MAAM,EAAG,OAAO;QAChB,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,MAAM,EAAG,GAAG,CAAC,MAAM;QACnB,IAAI,EAAK,IAAI,CAAC,SAAS,CAAC;YACtB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,OAAO,EAAI,GAAG,CAAC,OAAO;SACvB,CAAC;KACH,CACF,CAAC;IACF,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,OAAO,MAAM,IAAI,CAAC,IAAI,EAA+B,CAAC;AACxD,CAAC"}
@@ -11,7 +11,7 @@ export type VerifyResponse = {
11
11
  * Core license verification.
12
12
  *
13
13
  * @param zkAppAddress - app address (composite key with licenseHash)
14
- * @param licenseHash - Poseidon.hash([secretHash]) as a field string
14
+ * @param licenseHash - Poseidon hash of the buyer's Ed25519 pubkey (see ownershipLicenseHash.ts) as a field string
15
15
  * @param records - current off-chain license records (from licenseStore)
16
16
  * @param onChainRoot - zkApp appState[0] fetched from Mina
17
17
  * @param currentSlot - current blockchain slot (globalSlotSinceGenesis)
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyCore.d.ts","sourceRoot":"","sources":["../src/verifyCore.ts"],"names":[],"mappings":"AAYA,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGjE,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IAIvB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAOF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,cAAc,CA4CjB"}
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) 2025-2026 zkLicensing project developers
2
- // All rights reserved.
2
+ // SPDX-License-Identifier: BUSL-1.1
3
3
  /**
4
4
  * verifyCore.ts
5
5
  *
@@ -19,7 +19,7 @@ function computeRemainingDays(expirySlot, currentSlot) {
19
19
  * Core license verification.
20
20
  *
21
21
  * @param zkAppAddress - app address (composite key with licenseHash)
22
- * @param licenseHash - Poseidon.hash([secretHash]) as a field string
22
+ * @param licenseHash - Poseidon hash of the buyer's Ed25519 pubkey (see ownershipLicenseHash.ts) as a field string
23
23
  * @param records - current off-chain license records (from licenseStore)
24
24
  * @param onChainRoot - zkApp appState[0] fetched from Mina
25
25
  * @param currentSlot - current blockchain slot (globalSlotSinceGenesis)
@@ -34,10 +34,17 @@ export function verifyLicenseCore(params) {
34
34
  if (computedRoot.toString() !== onChainRoot) {
35
35
  return { valid: false, expiresAt: null, expirySlot: 0, inGracePeriod: false, remainingDays: 0, reason: 'License state does not match on-chain root' };
36
36
  }
37
+ // Post-LicenseLeaf: the map value is `leaf.hash()`, not raw expirySlot.
38
+ // Empty slots still hash to Field(0). Look up the record to recover
39
+ // expirySlot; `buildMap` excludes refunded/empty entries, so a missing
40
+ // record here means either "never bought" or "refunded" (record kept but
41
+ // expirySlot cleared to 0).
42
+ const record = records.find(r => r.zkAppAddress === zkAppAddress && r.licenseHash === licenseHash);
37
43
  if (currentValue === '0') {
38
- return { valid: false, expiresAt: null, expirySlot: 0, inGracePeriod: false, remainingDays: 0, reason: 'License has been refunded' };
44
+ const reason = record?.refunded ? 'License has been refunded' : 'License not found';
45
+ return { valid: false, expiresAt: null, expirySlot: 0, inGracePeriod: false, remainingDays: 0, reason };
39
46
  }
40
- const expirySlot = Number(currentValue);
47
+ const expirySlot = record?.expirySlot ?? 0;
41
48
  const inGracePeriod = currentSlot > expirySlot && currentSlot <= expirySlot + GRACE_PERIOD_N;
42
49
  const expired = currentSlot > expirySlot + GRACE_PERIOD_N;
43
50
  const expiresAt = new Date(Date.now() + (expirySlot - currentSlot) * MS_PER_SLOT_N).toISOString();
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyCore.js","sourceRoot":"","sources":["../src/verifyCore.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAsB,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAcxF,SAAS,oBAAoB,CAAC,UAAkB,EAAE,WAAmB;IACnE,IAAI,UAAU,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;GAQG;AACH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