zklicensing 0.1.0-beta.2 → 0.1.0-beta.21

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 (317) hide show
  1. package/README.md +417 -201
  2. package/build/agent.d.ts +371 -0
  3. package/build/agent.d.ts.map +1 -0
  4. package/build/agent.js +553 -0
  5. package/build/agent.js.map +1 -0
  6. package/build/agentActions.d.ts +841 -0
  7. package/build/agentActions.d.ts.map +1 -0
  8. package/build/agentActions.js +581 -0
  9. package/build/agentActions.js.map +1 -0
  10. package/build/agentRecord.d.ts +83 -0
  11. package/build/agentRecord.d.ts.map +1 -0
  12. package/build/agentRecord.js +69 -0
  13. package/build/agentRecord.js.map +1 -0
  14. package/build/agentVendor.d.ts +220 -0
  15. package/build/agentVendor.d.ts.map +1 -0
  16. package/build/agentVendor.js +306 -0
  17. package/build/agentVendor.js.map +1 -0
  18. package/build/appsLookup.d.ts +14 -0
  19. package/build/appsLookup.d.ts.map +1 -0
  20. package/build/appsLookup.js +12 -0
  21. package/build/appsLookup.js.map +1 -0
  22. package/build/archiveBootstrap.d.ts +31 -5
  23. package/build/archiveBootstrap.d.ts.map +1 -0
  24. package/build/archiveBootstrap.js +140 -47
  25. package/build/archiveBootstrap.js.map +1 -0
  26. package/build/atomicJson.d.ts +5 -0
  27. package/build/atomicJson.d.ts.map +1 -0
  28. package/build/atomicJson.js +55 -0
  29. package/build/atomicJson.js.map +1 -0
  30. package/build/bindClient.d.ts +85 -0
  31. package/build/bindClient.d.ts.map +1 -0
  32. package/build/bindClient.js +187 -0
  33. package/build/bindClient.js.map +1 -0
  34. package/build/buyClient.d.ts +27 -4
  35. package/build/buyClient.d.ts.map +1 -0
  36. package/build/buyClient.js +72 -26
  37. package/build/buyClient.js.map +1 -0
  38. package/build/chainHead.d.ts +61 -0
  39. package/build/chainHead.d.ts.map +1 -0
  40. package/build/chainHead.js +88 -0
  41. package/build/chainHead.js.map +1 -0
  42. package/build/compactMerkleMap.d.ts +72 -0
  43. package/build/compactMerkleMap.d.ts.map +1 -0
  44. package/build/compactMerkleMap.js +224 -0
  45. package/build/compactMerkleMap.js.map +1 -0
  46. package/build/contractInterface.d.ts +191 -51
  47. package/build/contractInterface.d.ts.map +1 -0
  48. package/build/contractInterface.js +234 -43
  49. package/build/contractInterface.js.map +1 -0
  50. package/build/contractTypes.d.ts +9 -0
  51. package/build/contractTypes.d.ts.map +1 -0
  52. package/build/contractTypes.js +28 -0
  53. package/build/contractTypes.js.map +1 -0
  54. package/build/countryStats.d.ts +12 -3
  55. package/build/countryStats.d.ts.map +1 -0
  56. package/build/countryStats.js +87 -23
  57. package/build/countryStats.js.map +1 -0
  58. package/build/deployClient.d.ts +138 -24
  59. package/build/deployClient.d.ts.map +1 -0
  60. package/build/deployClient.js +91 -31
  61. package/build/deployClient.js.map +1 -0
  62. package/build/deviceIdentity.d.ts +68 -0
  63. package/build/deviceIdentity.d.ts.map +1 -0
  64. package/build/deviceIdentity.js +209 -0
  65. package/build/deviceIdentity.js.map +1 -0
  66. package/build/freezeClient.d.ts +26 -6
  67. package/build/freezeClient.d.ts.map +1 -0
  68. package/build/freezeClient.js +30 -6
  69. package/build/freezeClient.js.map +1 -0
  70. package/build/generationClient.d.ts +6 -3
  71. package/build/generationClient.d.ts.map +1 -0
  72. package/build/generationClient.js +25 -38
  73. package/build/generationClient.js.map +1 -0
  74. package/build/holderSecret.d.ts +70 -0
  75. package/build/holderSecret.d.ts.map +1 -0
  76. package/build/holderSecret.js +76 -0
  77. package/build/holderSecret.js.map +1 -0
  78. package/build/index.d.ts +38 -38
  79. package/build/index.d.ts.map +1 -0
  80. package/build/index.js +97 -121
  81. package/build/index.js.map +1 -0
  82. package/build/keysClient.d.ts +142 -0
  83. package/build/keysClient.d.ts.map +1 -0
  84. package/build/keysClient.js +109 -0
  85. package/build/keysClient.js.map +1 -0
  86. package/build/licenseLeaf.d.ts +76 -0
  87. package/build/licenseLeaf.d.ts.map +1 -0
  88. package/build/licenseLeaf.js +189 -0
  89. package/build/licenseLeaf.js.map +1 -0
  90. package/build/licenseRecord.d.ts +68 -5
  91. package/build/licenseRecord.d.ts.map +1 -0
  92. package/build/licenseRecord.js +26 -1
  93. package/build/licenseRecord.js.map +1 -0
  94. package/build/licenseStore.d.ts +81 -4
  95. package/build/licenseStore.d.ts.map +1 -0
  96. package/build/licenseStore.js +400 -30
  97. package/build/licenseStore.js.map +1 -0
  98. package/build/licenseTrustless.d.ts +43 -0
  99. package/build/licenseTrustless.d.ts.map +1 -0
  100. package/build/licenseTrustless.js +180 -0
  101. package/build/licenseTrustless.js.map +1 -0
  102. package/build/manifestVerify.d.ts +29 -1
  103. package/build/manifestVerify.d.ts.map +1 -0
  104. package/build/manifestVerify.js +46 -4
  105. package/build/manifestVerify.js.map +1 -0
  106. package/build/minaPriceHistory.d.ts +9 -0
  107. package/build/minaPriceHistory.d.ts.map +1 -0
  108. package/build/minaPriceHistory.js +152 -0
  109. package/build/minaPriceHistory.js.map +1 -0
  110. package/build/onChainRoot.d.ts +60 -0
  111. package/build/onChainRoot.d.ts.map +1 -0
  112. package/build/onChainRoot.js +74 -0
  113. package/build/onChainRoot.js.map +1 -0
  114. package/build/ownershipLicenseHash.d.ts +25 -0
  115. package/build/ownershipLicenseHash.d.ts.map +1 -0
  116. package/build/ownershipLicenseHash.js +29 -0
  117. package/build/ownershipLicenseHash.js.map +1 -0
  118. package/build/ownershipSignature.d.ts +153 -0
  119. package/build/ownershipSignature.d.ts.map +1 -0
  120. package/build/ownershipSignature.js +297 -0
  121. package/build/ownershipSignature.js.map +1 -0
  122. package/build/permitCheckFlow.d.ts +155 -0
  123. package/build/permitCheckFlow.d.ts.map +1 -0
  124. package/build/permitCheckFlow.js +196 -0
  125. package/build/permitCheckFlow.js.map +1 -0
  126. package/build/permitDescribe.d.ts +124 -0
  127. package/build/permitDescribe.d.ts.map +1 -0
  128. package/build/permitDescribe.js +324 -0
  129. package/build/permitDescribe.js.map +1 -0
  130. package/build/permitInterface.d.ts +85 -0
  131. package/build/permitInterface.d.ts.map +1 -0
  132. package/build/permitInterface.js +121 -0
  133. package/build/permitInterface.js.map +1 -0
  134. package/build/permitMessages.d.ts +313 -0
  135. package/build/permitMessages.d.ts.map +1 -0
  136. package/build/permitMessages.js +462 -0
  137. package/build/permitMessages.js.map +1 -0
  138. package/build/permitProof.d.ts +108 -0
  139. package/build/permitProof.d.ts.map +1 -0
  140. package/build/permitProof.js +202 -0
  141. package/build/permitProof.js.map +1 -0
  142. package/build/permitRegistryRebuild.d.ts +166 -0
  143. package/build/permitRegistryRebuild.d.ts.map +1 -0
  144. package/build/permitRegistryRebuild.js +347 -0
  145. package/build/permitRegistryRebuild.js.map +1 -0
  146. package/build/permitTree.d.ts +88 -0
  147. package/build/permitTree.d.ts.map +1 -0
  148. package/build/permitTree.js +230 -0
  149. package/build/permitTree.js.map +1 -0
  150. package/build/permitsClient.d.ts +680 -0
  151. package/build/permitsClient.d.ts.map +1 -0
  152. package/build/permitsClient.js +597 -0
  153. package/build/permitsClient.js.map +1 -0
  154. package/build/proveErrors.d.ts +50 -0
  155. package/build/proveErrors.d.ts.map +1 -0
  156. package/build/proveErrors.js +76 -0
  157. package/build/proveErrors.js.map +1 -0
  158. package/build/receipt.d.ts +95 -0
  159. package/build/receipt.d.ts.map +1 -0
  160. package/build/receipt.js +84 -0
  161. package/build/receipt.js.map +1 -0
  162. package/build/refundClient.d.ts +7 -12
  163. package/build/refundClient.d.ts.map +1 -0
  164. package/build/refundClient.js +52 -21
  165. package/build/refundClient.js.map +1 -0
  166. package/build/registryTrustVerify.d.ts +78 -0
  167. package/build/registryTrustVerify.d.ts.map +1 -0
  168. package/build/registryTrustVerify.js +129 -0
  169. package/build/registryTrustVerify.js.map +1 -0
  170. package/build/releaseClient.d.ts +26 -0
  171. package/build/releaseClient.d.ts.map +1 -0
  172. package/build/releaseClient.js +65 -0
  173. package/build/releaseClient.js.map +1 -0
  174. package/build/renewClient.d.ts +28 -2
  175. package/build/renewClient.d.ts.map +1 -0
  176. package/build/renewClient.js +31 -27
  177. package/build/renewClient.js.map +1 -0
  178. package/build/seatName.d.ts +8 -0
  179. package/build/seatName.d.ts.map +1 -0
  180. package/build/seatName.js +136 -0
  181. package/build/seatName.js.map +1 -0
  182. package/build/slotConstants.d.ts +15 -0
  183. package/build/slotConstants.d.ts.map +1 -0
  184. package/build/slotConstants.js +17 -0
  185. package/build/slotConstants.js.map +1 -0
  186. package/build/statsClient.d.ts +61 -7
  187. package/build/statsClient.d.ts.map +1 -0
  188. package/build/statsClient.js +44 -5
  189. package/build/statsClient.js.map +1 -0
  190. package/build/successorChain.d.ts +35 -0
  191. package/build/successorChain.d.ts.map +1 -0
  192. package/build/successorChain.js +69 -0
  193. package/build/successorChain.js.map +1 -0
  194. package/build/taxId.d.ts +44 -0
  195. package/build/taxId.d.ts.map +1 -0
  196. package/build/taxId.js +212 -0
  197. package/build/taxId.js.map +1 -0
  198. package/build/trustAnchorVerify.d.ts +49 -0
  199. package/build/trustAnchorVerify.d.ts.map +1 -0
  200. package/build/trustAnchorVerify.js +432 -0
  201. package/build/trustAnchorVerify.js.map +1 -0
  202. package/build/trustAnchorVerifyCli.d.ts +45 -0
  203. package/build/trustAnchorVerifyCli.d.ts.map +1 -0
  204. package/build/trustAnchorVerifyCli.js +235 -0
  205. package/build/trustAnchorVerifyCli.js.map +1 -0
  206. package/build/txBroadcastClient.d.ts +26 -0
  207. package/build/txBroadcastClient.d.ts.map +1 -0
  208. package/build/txBroadcastClient.js +20 -0
  209. package/build/txBroadcastClient.js.map +1 -0
  210. package/build/unbindClient.d.ts +77 -0
  211. package/build/unbindClient.d.ts.map +1 -0
  212. package/build/unbindClient.js +169 -0
  213. package/build/unbindClient.js.map +1 -0
  214. package/build/units.d.ts +28 -0
  215. package/build/units.d.ts.map +1 -0
  216. package/build/units.js +65 -0
  217. package/build/units.js.map +1 -0
  218. package/build/vatRates.d.ts +54 -0
  219. package/build/vatRates.d.ts.map +1 -0
  220. package/build/vatRates.js +82 -0
  221. package/build/vatRates.js.map +1 -0
  222. package/build/vatRatesData.d.ts +5 -0
  223. package/build/vatRatesData.d.ts.map +1 -0
  224. package/build/vatRatesData.js +42 -0
  225. package/build/vatRatesData.js.map +1 -0
  226. package/build/vendorAccountClient.d.ts +66 -0
  227. package/build/vendorAccountClient.d.ts.map +1 -0
  228. package/build/vendorAccountClient.js +47 -0
  229. package/build/vendorAccountClient.js.map +1 -0
  230. package/build/verifyCore.d.ts +4 -1
  231. package/build/verifyCore.d.ts.map +1 -0
  232. package/build/verifyCore.js +21 -10
  233. package/build/verifyCore.js.map +1 -0
  234. package/build/verifyOffline.d.ts +85 -0
  235. package/build/verifyOffline.d.ts.map +1 -0
  236. package/build/verifyOffline.js +139 -0
  237. package/build/verifyOffline.js.map +1 -0
  238. package/build/verifyService.d.ts.map +1 -0
  239. package/build/verifyService.js +571 -501
  240. package/build/verifyService.js.map +1 -0
  241. package/build/verifyWithAncestors.d.ts +19 -0
  242. package/build/verifyWithAncestors.d.ts.map +1 -0
  243. package/build/verifyWithAncestors.js +127 -0
  244. package/build/verifyWithAncestors.js.map +1 -0
  245. package/build/zipToState.d.ts +2 -0
  246. package/build/zipToState.d.ts.map +1 -0
  247. package/build/zipToState.js +94 -0
  248. package/build/zipToState.js.map +1 -0
  249. package/package.json +141 -16
  250. package/src/agent.ts +682 -0
  251. package/src/agentActions.ts +637 -0
  252. package/src/agentRecord.ts +121 -0
  253. package/src/agentVendor.ts +356 -0
  254. package/src/appsLookup.ts +48 -0
  255. package/src/archiveBootstrap.ts +386 -0
  256. package/src/atomicJson.ts +53 -0
  257. package/src/bindClient.ts +297 -0
  258. package/src/buyClient.ts +344 -0
  259. package/src/chainHead.ts +106 -0
  260. package/src/compactMerkleMap.ts +222 -0
  261. package/src/contractInterface.ts +465 -0
  262. package/src/contractTypes.ts +31 -0
  263. package/src/countryStats.ts +200 -0
  264. package/src/deployClient.ts +517 -0
  265. package/src/deviceIdentity.ts +249 -0
  266. package/src/freezeClient.ts +162 -0
  267. package/src/generationClient.ts +145 -0
  268. package/src/holderSecret.ts +91 -0
  269. package/src/index.ts +362 -0
  270. package/src/keysClient.ts +135 -0
  271. package/src/licenseLeaf.ts +221 -0
  272. package/src/licenseRecord.ts +190 -0
  273. package/src/licenseStore.ts +767 -0
  274. package/src/licenseTrustless.ts +207 -0
  275. package/src/manifestVerify.ts +164 -0
  276. package/src/minaPriceHistory.ts +166 -0
  277. package/src/onChainRoot.ts +90 -0
  278. package/src/ownershipLicenseHash.ts +31 -0
  279. package/src/ownershipSignature.ts +421 -0
  280. package/src/permitCheckFlow.ts +227 -0
  281. package/src/permitDescribe.ts +362 -0
  282. package/src/permitInterface.ts +146 -0
  283. package/src/permitMessages.ts +572 -0
  284. package/src/permitProof.ts +230 -0
  285. package/src/permitRegistryRebuild.ts +423 -0
  286. package/src/permitTree.ts +232 -0
  287. package/src/permitsClient.ts +746 -0
  288. package/src/proveErrors.ts +98 -0
  289. package/src/receipt.ts +156 -0
  290. package/src/refundClient.ts +177 -0
  291. package/src/registryTrustVerify.ts +192 -0
  292. package/src/releaseClient.ts +101 -0
  293. package/src/renewClient.ts +234 -0
  294. package/src/seatName.ts +165 -0
  295. package/src/slotConstants.ts +18 -0
  296. package/src/statsClient.ts +249 -0
  297. package/src/successorChain.ts +87 -0
  298. package/src/taxId.ts +227 -0
  299. package/src/trustAnchorVerify.ts +550 -0
  300. package/src/trustAnchorVerifyCli.ts +234 -0
  301. package/src/txBroadcastClient.ts +48 -0
  302. package/src/unbindClient.ts +233 -0
  303. package/src/units.ts +74 -0
  304. package/src/vatRates.ts +100 -0
  305. package/src/vatRatesData.ts +43 -0
  306. package/src/vendorAccountClient.ts +120 -0
  307. package/src/verifyCore.ts +100 -0
  308. package/src/verifyOffline.ts +212 -0
  309. package/src/verifyService.ts +982 -0
  310. package/src/verifyWithAncestors.ts +163 -0
  311. package/src/zipToState.ts +94 -0
  312. package/build/licenseProof.d.ts +0 -26
  313. package/build/licenseProof.js +0 -41
  314. package/build/migrateClient.d.ts +0 -43
  315. package/build/migrateClient.js +0 -47
  316. package/build/ownership.d.ts +0 -34
  317. package/build/ownership.js +0 -147
@@ -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
  function baseUrl(url) {
4
4
  return url.replace(/\/+$/, '');
5
5
  }
@@ -12,13 +12,13 @@ async function readJsonError(resp) {
12
12
  catch { /* body wasn't JSON */ }
13
13
  return `HTTP ${resp.status}`;
14
14
  }
15
- // POST /prove/deploy — keeper generates the throwaway zkApp keypair, assembles
16
- // the deploy+initialize tx, proves it, and signs the zkApp AccountUpdate with
17
- // the throwaway key. The caller forwards `provenTxJson` to the vendor's wallet
18
- // for the fee-payer signature.
15
+ // POST /prove/deploy — the backend generates the throwaway zkApp keypair,
16
+ // assembles the deploy+initialize tx, proves it, and signs the zkApp
17
+ // AccountUpdate with the throwaway key. The caller forwards `provenTxJson` to
18
+ // the vendor's wallet for the fee-payer signature.
19
19
  //
20
- // At least one of the three prices must be > 0 (enforced by the keeper *and*
21
- // by the circuit's `initialize()`).
20
+ // At least one of the four tier prices must be > 0 (enforced by the backend
21
+ // *and* by the circuit's `initialize()`).
22
22
  export async function proveDeploy(req) {
23
23
  const fetcher = req.fetcher ?? fetch;
24
24
  const resp = await fetcher(`${baseUrl(req.keeperUrl)}/prove/deploy`, {
@@ -31,14 +31,20 @@ export async function proveDeploy(req) {
31
31
  priceMonthlyMina: req.priceMonthlyMina,
32
32
  priceYearlyMina: req.priceYearlyMina,
33
33
  priceFiveYearMina: req.priceFiveYearMina,
34
+ pricePerpetualMina: req.pricePerpetualMina,
35
+ deviceCap: req.deviceCap,
36
+ ...(req.forkActivationSlot !== undefined ? { forkActivationSlot: req.forkActivationSlot } : {}),
37
+ ...(req.network ? { network: req.network } : {}),
38
+ ...(req.website ? { website: req.website } : {}),
39
+ ...(req.payoutAddress ? { payoutAddress: req.payoutAddress } : {}),
34
40
  }),
35
41
  });
36
42
  if (!resp.ok)
37
43
  throw new Error(await readJsonError(resp));
38
44
  return await resp.json();
39
45
  }
40
- // Polls GET /deploy/status until it returns a terminal state ('confirmed' or
41
- // 'failed') or the timeout fires. 'unknown' means the keeper hasn't seen the
46
+ // Polls GET /deploy/status until it returns a terminal state ('landed' or
47
+ // 'timeout') or the timeout fires. 'unknown' means the backend hasn't seen the
42
48
  // tx yet (register step not called or watch not armed).
43
49
  export async function pollDeployStatus(opts) {
44
50
  const fetcher = opts.fetcher ?? fetch;
@@ -57,7 +63,7 @@ export async function pollDeployStatus(opts) {
57
63
  }
58
64
  catch { /* transient network — try again on next tick */ }
59
65
  opts.onTick?.(status);
60
- if (status.status === 'confirmed' || status.status === 'failed')
66
+ if (status.status === 'landed' || status.status === 'timeout')
61
67
  return status;
62
68
  if (Date.now() >= deadline)
63
69
  return status;
@@ -70,34 +76,50 @@ function adminHeaders(token) {
70
76
  'Authorization': `Bearer ${token}`,
71
77
  };
72
78
  }
73
- // POST /admin/redeploy/:appId — one-shot migration for a single app. Rejects
74
- // with a descriptive error if any keeper-side guard fails (409) or the deploy
75
- // itself throws (500). The returned `zkAppAddress` is the *new* v2 address; the
76
- // old one stays on chain but is no longer referenced by keeper records.
79
+ // POST /admin/redeploy/:appId — the next redeploy step for a single app.
80
+ // Rejects with a descriptive error if any backend guard fails (409) or the
81
+ // transaction itself throws (500). After a deploy step the returned
82
+ // `zkAppAddress` is the successor's; the old one stays on chain, retired.
77
83
  export async function redeployApp(req) {
78
84
  const fetcher = req.fetcher ?? fetch;
79
85
  const resp = await fetcher(`${baseUrl(req.keeperUrl)}/admin/redeploy/${encodeURIComponent(req.appId)}`, {
80
86
  method: 'POST',
81
87
  headers: adminHeaders(req.adminToken),
82
88
  signal: req.signal,
83
- body: JSON.stringify(req.force ? { force: true } : {}),
89
+ body: JSON.stringify({
90
+ ...(req.network ? { network: req.network } : {}),
91
+ ...(req.retireSignature ? { retireSignature: req.retireSignature } : {}),
92
+ ...(req.feePayer ? { feePayer: req.feePayer } : {}),
93
+ ...(req.force ? { force: true } : {}),
94
+ }),
95
+ });
96
+ if (!resp.ok)
97
+ throw new Error(await readJsonError(resp));
98
+ return await resp.json();
99
+ }
100
+ // POST /admin/redeploy/:appId/register — the admin wallet sent the proved
101
+ // step: a retire is marked on the app; a deploy is watched until it lands,
102
+ // then the app moves to its successor.
103
+ export async function registerAdminRedeploy(req) {
104
+ const resp = await (req.fetcher ?? fetch)(`${baseUrl(req.keeperUrl)}/admin/redeploy/${encodeURIComponent(req.appId)}/register`, {
105
+ method: 'POST', headers: adminHeaders(req.adminToken), signal: req.signal,
106
+ body: JSON.stringify({ redeployId: req.redeployId, txHash: req.txHash }),
84
107
  });
85
108
  if (!resp.ok)
86
109
  throw new Error(await readJsonError(resp));
87
110
  return await resp.json();
88
111
  }
89
- // POST /admin/redeploy-all — iterate every registered app and attempt migration.
90
- // Idempotent: apps already migrated surface as ok:false with a clear error, so
91
- // a rerun after a partial failure retries only the remaining ones. Callers
92
- // should inspect `results` for per-app outcomes rather than relying on the
93
- // top-level `ok`, which is always true unless the whole request failed.
112
+ // POST /admin/redeploy-all — raises every eligible app's retirement gate at
113
+ // once (one shared drain) and reports each app's next step; the admin wallet
114
+ // then takes them one app at a time with redeployApp (it signs and pays).
115
+ // Apps that can't be redeployed surface as ok:false with the reason.
94
116
  export async function redeployAll(req) {
95
117
  const fetcher = req.fetcher ?? fetch;
96
118
  const resp = await fetcher(`${baseUrl(req.keeperUrl)}/admin/redeploy-all`, {
97
119
  method: 'POST',
98
120
  headers: adminHeaders(req.adminToken),
99
121
  signal: req.signal,
100
- body: JSON.stringify(req.force ? { force: true } : {}),
122
+ body: JSON.stringify(req.network ? { network: req.network } : {}),
101
123
  });
102
124
  if (!resp.ok)
103
125
  throw new Error(await readJsonError(resp));
@@ -109,7 +131,7 @@ export async function redeployAll(req) {
109
131
  // known app failing individual guards).
110
132
  export async function fetchVendorRedeployPreflight(opts) {
111
133
  const fetcher = opts.fetcher ?? fetch;
112
- const resp = await fetcher(`${baseUrl(opts.keeperUrl)}/vendor/redeploy/${encodeURIComponent(opts.appId)}/preflight`, {
134
+ const resp = await fetcher(`${baseUrl(opts.keeperUrl)}/vendor/redeploy/${encodeURIComponent(opts.appId)}/preflight?network=${opts.network}`, {
113
135
  signal: opts.signal,
114
136
  });
115
137
  if (!resp.ok)
@@ -121,18 +143,16 @@ export async function fetchVendorRedeployPreflight(opts) {
121
143
  // consumed on /prove.
122
144
  export async function getVendorRedeployChallenge(opts) {
123
145
  const fetcher = opts.fetcher ?? fetch;
124
- const resp = await fetcher(`${baseUrl(opts.keeperUrl)}/vendor/redeploy/${encodeURIComponent(opts.appId)}/challenge`, {
146
+ const resp = await fetcher(`${baseUrl(opts.keeperUrl)}/vendor/redeploy/${encodeURIComponent(opts.appId)}/challenge?network=${opts.network}`, {
125
147
  signal: opts.signal,
126
148
  });
127
149
  if (!resp.ok)
128
150
  throw new Error(await readJsonError(resp));
129
151
  return await resp.json();
130
152
  }
131
- // POST /vendor/redeploy/:appId/prove — keeper verifies the nonce + signature
132
- // against the on-chain vendor of the app, runs all redeploy guards, generates
133
- // a throwaway zkApp keypair, builds and proves the deploy+initialize tx, and
134
- // signs the zkApp AU with the throwaway key. Returns the tx JSON for the
135
- // vendor's wallet to add the fee-payer signature and broadcast.
153
+ // POST /vendor/redeploy/:appId/prove — the backend verifies the nonce +
154
+ // signature against the on-chain vendor of the app and runs all redeploy
155
+ // guards, then answers with the next step (see the flow above).
136
156
  export async function proveVendorRedeploy(req) {
137
157
  const fetcher = req.fetcher ?? fetch;
138
158
  const resp = await fetcher(`${baseUrl(req.keeperUrl)}/vendor/redeploy/${encodeURIComponent(req.appId)}/prove`, {
@@ -143,20 +163,60 @@ export async function proveVendorRedeploy(req) {
143
163
  nonce: req.nonce,
144
164
  signature: req.signature,
145
165
  senderPublicKey: req.senderPublicKey,
146
- ...(req.force ? { force: true } : {}),
166
+ ...(req.retireSignature ? { retireSignature: req.retireSignature } : {}),
147
167
  }),
148
168
  });
149
169
  if (!resp.ok)
150
170
  throw new Error(await readJsonError(resp));
151
171
  return await resp.json();
152
172
  }
153
- // POST /vendor/redeploy/:appId/register — arm the keeper's deploy-watcher on
154
- // the new address. On confirmation the keeper mutates AppRecord to promote
173
+ // POST /vendor/redeploy/:appId/register — arm the backend's deploy-watcher on
174
+ // the new address. On confirmation the backend mutates AppRecord to promote
155
175
  // the new deployment (push old to deploymentHistory[], overwrite live fields,
156
176
  // clear event-sync cursors). Idempotent to duplicate calls (the watcher
157
177
  // checks whether one is already armed for the address). Poll GET
158
178
  // /deploy/status?zkAppAddress=<new> — or use pollDeployStatus — for landing
159
179
  // progress, same as first-time deploys.
180
+ // POST /vendor/redeploy/:appId/cancel — calls off the vendor's redeploy
181
+ // (gate, drain) before the app is retired on chain. A fresh signed challenge.
182
+ export async function cancelVendorRedeploy(req) {
183
+ const fetcher = req.fetcher ?? fetch;
184
+ const resp = await fetcher(`${baseUrl(req.keeperUrl)}/vendor/redeploy/${encodeURIComponent(req.appId)}/cancel`, {
185
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, signal: req.signal,
186
+ body: JSON.stringify({ nonce: req.nonce, signature: req.signature }),
187
+ });
188
+ if (!resp.ok)
189
+ throw new Error(await readJsonError(resp));
190
+ return await resp.json();
191
+ }
192
+ // POST /admin/redeploy/:appId/drain — the platform starts a redeploy of an
193
+ // app with purchases in escrow: new purchases pause until it is empty.
194
+ export async function startRedeployDrain(req) {
195
+ const resp = await (req.fetcher ?? fetch)(`${baseUrl(req.keeperUrl)}/admin/redeploy/${encodeURIComponent(req.appId)}/drain`, {
196
+ method: 'POST', headers: adminHeaders(req.adminToken), body: JSON.stringify({ network: req.network }),
197
+ });
198
+ if (!resp.ok)
199
+ throw new Error(await readJsonError(resp));
200
+ return await resp.json();
201
+ }
202
+ // POST /admin/redeploy/:appId/cancel — calls off a redeploy or drain not yet retired on chain.
203
+ export async function cancelRedeploy(req) {
204
+ const resp = await (req.fetcher ?? fetch)(`${baseUrl(req.keeperUrl)}/admin/redeploy/${encodeURIComponent(req.appId)}/cancel`, {
205
+ method: 'POST', headers: adminHeaders(req.adminToken), body: JSON.stringify({ network: req.network }),
206
+ });
207
+ if (!resp.ok)
208
+ throw new Error(await readJsonError(resp));
209
+ return await resp.json();
210
+ }
211
+ // POST /admin/redeploy-notice — ahead of an announced hard fork, emails the vendors of live apps.
212
+ export async function sendRedeployNotices(req) {
213
+ const resp = await (req.fetcher ?? fetch)(`${baseUrl(req.keeperUrl)}/admin/redeploy-notice`, {
214
+ method: 'POST', headers: adminHeaders(req.adminToken), body: JSON.stringify({ network: req.network }),
215
+ });
216
+ if (!resp.ok)
217
+ throw new Error(await readJsonError(resp));
218
+ return await resp.json();
219
+ }
160
220
  export async function registerVendorRedeploy(req) {
161
221
  const fetcher = req.fetcher ?? fetch;
162
222
  const resp = await fetcher(`${baseUrl(req.keeperUrl)}/vendor/redeploy/${encodeURIComponent(req.appId)}/register`, {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployClient.js","sourceRoot":"","sources":["../src/deployClient.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAyEpC,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,0EAA0E;AAC1E,qEAAqE;AACrE,8EAA8E;AAC9E,mDAAmD;A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IACH,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,OAAO,MAAM,IAAI,CAAC,IAAI,EAAkE,CAAC;AAC3F,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,GAAkC;IAC7E,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE;QAChH,MAAM,EAAG,MAAM;QACf,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,MAAM,EAAG,GAAG,CAAC,MAAM;QACnB,IAAI,EAAK,IAAI,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;KAC5E,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,OAAO,MAAM,IAAI,CAAC,IAAI,EAA6C,CAAC;AACtE,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * deviceIdentity.ts
3
+ *
4
+ * Per-install Pallas Schnorr keypair used to identify a device to the
5
+ * non-custodial binding flow. `getOrCreateDeviceIdentity(storageKey)`
6
+ * returns a stable keypair for the caller's storage key: created on
7
+ * first call, loaded verbatim on every subsequent call.
8
+ *
9
+ * The `deviceCommitment` this module exposes matches the on-chain
10
+ * `occupied[i]` field shape written by `LicensingApp.bind()` — it's
11
+ * `Poseidon([pk.x, pk.isOdd.toField()])` over the device's Pallas
12
+ * pubkey (see `ownerPubKeyHash` in ./licenseLeaf.ts for the identical
13
+ * shape applied to the ownership pubkey). Callers pass the commitment
14
+ * to `proveBind` and to the ownership signature; the raw device pubkey
15
+ * itself never crosses the wire.
16
+ *
17
+ * Storage tradeoffs (documented up front — the plan's original
18
+ * assumption was WebCrypto extractable=false, which only applies to
19
+ * WebCrypto-native primitives):
20
+ *
21
+ * Browser path — IndexedDB.
22
+ * Pallas is not a WebCrypto primitive, so we cannot store the
23
+ * private key as a non-extractable CryptoKey. The private key is
24
+ * persisted as its Mina canonical base58 encoding. An adversary
25
+ * with access to the browser profile (malware running as the user,
26
+ * evil browser extension) can read it. This matches the trust
27
+ * model of every other browser-persisted secret today (bearer
28
+ * cookies, IndexedDB tokens); binding to a fresh device after
29
+ * compromise is a keypair regen + one on-chain bind — no funds
30
+ * at risk, only slot churn. Users who want stronger storage can
31
+ * wipe the storageKey between sessions and re-bind on demand.
32
+ *
33
+ * Node / Electron path — keytar (OS keychain).
34
+ * `keytar` is loaded lazily and marked as an optional peer
35
+ * dependency in package.json so the browser bundle isn't dragged
36
+ * into installing native bindings it can't use. If keytar is
37
+ * unavailable at runtime, the SDK throws with a clear message
38
+ * rather than falling back to plaintext-on-disk.
39
+ *
40
+ * The keypair is Pallas-scalar-random, NOT passphrase-derived — the
41
+ * device identity is meant to survive a passphrase reset (the user
42
+ * can re-derive their ownership key from the passphrase, then unbind
43
+ * / rebind existing device slots without re-installing the app).
44
+ */
45
+ import { PrivateKey, PublicKey } from 'o1js';
46
+ export type DeviceIdentity = {
47
+ devicePrivateKey: PrivateKey;
48
+ devicePubKey: PublicKey;
49
+ deviceCommitment: string;
50
+ };
51
+ /**
52
+ * Compute the on-chain-shaped device commitment from a Pallas pubkey.
53
+ * Exported so tests and downstream tooling can re-derive it without
54
+ * re-instantiating the whole DeviceIdentity.
55
+ */
56
+ export declare function computeDeviceCommitment(devicePubKey: PublicKey): string;
57
+ /**
58
+ * Load an existing device keypair for `storageKey`, or create + persist
59
+ * a fresh one on first call. Idempotent across every subsequent call
60
+ * for the same key on the same install.
61
+ *
62
+ * The `storageKey` should be per-app (e.g. the vendor's app short
63
+ * name or its `appId`), so a single browser profile / OS user account
64
+ * can hold distinct device identities for distinct vendors without
65
+ * cross-contamination.
66
+ */
67
+ export declare function getOrCreateDeviceIdentity(storageKey: string): Promise<DeviceIdentity>;
68
+ //# sourceMappingURL=deviceIdentity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceIdentity.d.ts","sourceRoot":"","sources":["../src/deviceIdentity.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAY,MAAM,MAAM,CAAC;AAgBvD,MAAM,MAAM,cAAc,GAAG;IAC3B,gBAAgB,EAAE,UAAU,CAAC;IAC7B,YAAY,EAAM,SAAS,CAAC;IAK5B,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,SAAS,GAAG,MAAM,CAEvE;AAsID;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAuB3F"}
@@ -0,0 +1,209 @@
1
+ // Copyright (c) 2025-2026 zkLicensing project developers
2
+ // SPDX-License-Identifier: BUSL-1.1
3
+ /**
4
+ * deviceIdentity.ts
5
+ *
6
+ * Per-install Pallas Schnorr keypair used to identify a device to the
7
+ * non-custodial binding flow. `getOrCreateDeviceIdentity(storageKey)`
8
+ * returns a stable keypair for the caller's storage key: created on
9
+ * first call, loaded verbatim on every subsequent call.
10
+ *
11
+ * The `deviceCommitment` this module exposes matches the on-chain
12
+ * `occupied[i]` field shape written by `LicensingApp.bind()` — it's
13
+ * `Poseidon([pk.x, pk.isOdd.toField()])` over the device's Pallas
14
+ * pubkey (see `ownerPubKeyHash` in ./licenseLeaf.ts for the identical
15
+ * shape applied to the ownership pubkey). Callers pass the commitment
16
+ * to `proveBind` and to the ownership signature; the raw device pubkey
17
+ * itself never crosses the wire.
18
+ *
19
+ * Storage tradeoffs (documented up front — the plan's original
20
+ * assumption was WebCrypto extractable=false, which only applies to
21
+ * WebCrypto-native primitives):
22
+ *
23
+ * Browser path — IndexedDB.
24
+ * Pallas is not a WebCrypto primitive, so we cannot store the
25
+ * private key as a non-extractable CryptoKey. The private key is
26
+ * persisted as its Mina canonical base58 encoding. An adversary
27
+ * with access to the browser profile (malware running as the user,
28
+ * evil browser extension) can read it. This matches the trust
29
+ * model of every other browser-persisted secret today (bearer
30
+ * cookies, IndexedDB tokens); binding to a fresh device after
31
+ * compromise is a keypair regen + one on-chain bind — no funds
32
+ * at risk, only slot churn. Users who want stronger storage can
33
+ * wipe the storageKey between sessions and re-bind on demand.
34
+ *
35
+ * Node / Electron path — keytar (OS keychain).
36
+ * `keytar` is loaded lazily and marked as an optional peer
37
+ * dependency in package.json so the browser bundle isn't dragged
38
+ * into installing native bindings it can't use. If keytar is
39
+ * unavailable at runtime, the SDK throws with a clear message
40
+ * rather than falling back to plaintext-on-disk.
41
+ *
42
+ * The keypair is Pallas-scalar-random, NOT passphrase-derived — the
43
+ * device identity is meant to survive a passphrase reset (the user
44
+ * can re-derive their ownership key from the passphrase, then unbind
45
+ * / rebind existing device slots without re-installing the app).
46
+ */
47
+ import { PrivateKey, Poseidon } from 'o1js';
48
+ // ── Storage key namespacing ───────────────────────────────────────
49
+ // All device identities live under this shared prefix in whatever
50
+ // backing store is chosen. Callers pass a per-app / per-installation
51
+ // suffix (e.g. the app's short name) so a single browser profile can
52
+ // hold distinct device identities for distinct vendors' apps.
53
+ const STORAGE_PREFIX = 'zklic_device_';
54
+ function namespaced(storageKey) {
55
+ return `${STORAGE_PREFIX}${storageKey}`;
56
+ }
57
+ /**
58
+ * Compute the on-chain-shaped device commitment from a Pallas pubkey.
59
+ * Exported so tests and downstream tooling can re-derive it without
60
+ * re-instantiating the whole DeviceIdentity.
61
+ */
62
+ export function computeDeviceCommitment(devicePubKey) {
63
+ return Poseidon.hash([devicePubKey.x, devicePubKey.isOdd.toField()]).toString();
64
+ }
65
+ function buildIdentity(privateKey) {
66
+ const devicePubKey = privateKey.toPublicKey();
67
+ return {
68
+ devicePrivateKey: privateKey,
69
+ devicePubKey,
70
+ deviceCommitment: computeDeviceCommitment(devicePubKey),
71
+ };
72
+ }
73
+ // ── Environment detection ─────────────────────────────────────────
74
+ function hasIndexedDB() {
75
+ return typeof globalThis !== 'undefined'
76
+ && typeof globalThis.indexedDB !== 'undefined';
77
+ }
78
+ function isNodeLike() {
79
+ // Node exposes `process.versions.node`; Deno/Bun don't (their
80
+ // process shims omit this key). Browsers have no `process` global
81
+ // unless something's polyfilled it, but the indexedDB branch runs
82
+ // first so that ordering is fine.
83
+ return typeof globalThis.process !== 'undefined'
84
+ && typeof globalThis.process?.versions?.node === 'string';
85
+ }
86
+ // ── IndexedDB backing store (browser) ─────────────────────────────
87
+ // Small promisified wrapper — no third-party idb library, to keep the
88
+ // SDK dependency surface minimal. Single key/value store; the whole
89
+ // database is one object store with `storageKey` as the key.
90
+ const IDB_DB_NAME = 'zklicensing';
91
+ const IDB_STORE_NAME = 'device_identities';
92
+ const IDB_VERSION = 1;
93
+ function openIdb() {
94
+ return new Promise((resolve, reject) => {
95
+ const req = globalThis.indexedDB.open(IDB_DB_NAME, IDB_VERSION);
96
+ req.onupgradeneeded = () => {
97
+ const db = req.result;
98
+ if (!db.objectStoreNames.contains(IDB_STORE_NAME)) {
99
+ db.createObjectStore(IDB_STORE_NAME);
100
+ }
101
+ };
102
+ req.onsuccess = () => resolve(req.result);
103
+ req.onerror = () => reject(req.error ?? new Error('IndexedDB open failed'));
104
+ });
105
+ }
106
+ async function idbGet(key) {
107
+ const db = await openIdb();
108
+ try {
109
+ return await new Promise((resolve, reject) => {
110
+ const tx = db.transaction(IDB_STORE_NAME, 'readonly');
111
+ const store = tx.objectStore(IDB_STORE_NAME);
112
+ const req = store.get(key);
113
+ req.onsuccess = () => resolve(req.result ?? null);
114
+ req.onerror = () => reject(req.error ?? new Error('IndexedDB get failed'));
115
+ });
116
+ }
117
+ finally {
118
+ db.close();
119
+ }
120
+ }
121
+ async function idbPut(key, value) {
122
+ const db = await openIdb();
123
+ try {
124
+ await new Promise((resolve, reject) => {
125
+ const tx = db.transaction(IDB_STORE_NAME, 'readwrite');
126
+ const store = tx.objectStore(IDB_STORE_NAME);
127
+ const req = store.put(value, key);
128
+ req.onsuccess = () => resolve();
129
+ req.onerror = () => reject(req.error ?? new Error('IndexedDB put failed'));
130
+ });
131
+ }
132
+ finally {
133
+ db.close();
134
+ }
135
+ }
136
+ // ── keytar backing store (Node / Electron) ────────────────────────
137
+ // Loaded via dynamic import so a browser bundler doesn't try to
138
+ // resolve the native module. If keytar isn't installed we throw with
139
+ // a message that tells the caller which optional peer dep to add,
140
+ // rather than silently persisting to plaintext.
141
+ async function loadKeytar() {
142
+ try {
143
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
+ return await Function('return import("keytar")')();
145
+ }
146
+ catch {
147
+ throw new Error('deviceIdentity requires the optional peer dependency `keytar` in Node/Electron. ' +
148
+ 'Install it with `npm i keytar` alongside the zklicensing SDK.');
149
+ }
150
+ }
151
+ // keytar's shape: getPassword(service, account) / setPassword(service, account, value).
152
+ // We use a single service name and let `storageKey` be the account, so
153
+ // multiple apps under the same node install can coexist under distinct
154
+ // storage keys without stomping each other.
155
+ const KEYTAR_SERVICE = 'zklicensing-device-identity';
156
+ async function keytarGet(key) {
157
+ const keytar = await loadKeytar();
158
+ const mod = (keytar.default ?? keytar);
159
+ return mod.getPassword(KEYTAR_SERVICE, key);
160
+ }
161
+ async function keytarPut(key, value) {
162
+ const keytar = await loadKeytar();
163
+ const mod = (keytar.default ?? keytar);
164
+ await mod.setPassword(KEYTAR_SERVICE, key, value);
165
+ }
166
+ function pickBackend() {
167
+ if (hasIndexedDB())
168
+ return { get: idbGet, put: idbPut };
169
+ if (isNodeLike())
170
+ return { get: keytarGet, put: keytarPut };
171
+ throw new Error('deviceIdentity: no suitable storage backend detected. ' +
172
+ 'Expected IndexedDB in the browser or a Node/Electron runtime with `keytar` installed.');
173
+ }
174
+ // ── Public API ────────────────────────────────────────────────────
175
+ /**
176
+ * Load an existing device keypair for `storageKey`, or create + persist
177
+ * a fresh one on first call. Idempotent across every subsequent call
178
+ * for the same key on the same install.
179
+ *
180
+ * The `storageKey` should be per-app (e.g. the vendor's app short
181
+ * name or its `appId`), so a single browser profile / OS user account
182
+ * can hold distinct device identities for distinct vendors without
183
+ * cross-contamination.
184
+ */
185
+ export async function getOrCreateDeviceIdentity(storageKey) {
186
+ if (!storageKey || typeof storageKey !== 'string') {
187
+ throw new Error('getOrCreateDeviceIdentity: storageKey must be a non-empty string');
188
+ }
189
+ const backend = pickBackend();
190
+ const key = namespaced(storageKey);
191
+ const existing = await backend.get(key);
192
+ if (existing) {
193
+ try {
194
+ const privateKey = PrivateKey.fromBase58(existing);
195
+ return buildIdentity(privateKey);
196
+ }
197
+ catch {
198
+ // Corrupt persisted value — fall through and mint a fresh key,
199
+ // overwriting the bad blob. Losing a device identity here is
200
+ // recoverable: the caller re-binds the new keypair and unbinds
201
+ // the old slot from any other device that still has the
202
+ // ownership key.
203
+ }
204
+ }
205
+ const privateKey = PrivateKey.random();
206
+ await backend.put(key, privateKey.toBase58());
207
+ return buildIdentity(privateKey);
208
+ }
209
+ //# sourceMappingURL=deviceIdentity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceIdentity.js","sourceRoot":"","sources":["../src/deviceIdentity.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,UAAU,EAAa,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEvD,qEAAqE;AAErE,kEAAkE;AAClE,qEAAqE;AACrE,qEAAqE;AACrE,8DAA8D;AAC9D,MAAM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+DAA+D;YAC/D,6DAA6D;YAC7D,+DAA+D;YAC/D,wDAAwD;YACxD,iBAAiB;QACnB,CAAC;IACH,CAAC;IACD,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;IACvC,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9C,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC"}
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * freezeClient.ts
3
3
  *
4
- * Client-side view of the keeper's sales-freeze schedule. A freeze is set
4
+ * Client-side view of the backend's sales-freeze schedule. A freeze is set
5
5
  * ahead of a hardfork so every open escrow window can drain (refund or
6
- * release) before v1 → v2 migration. Once past the freeze slot the keeper
6
+ * release) before v1 → v2 migration. Once past the freeze slot the backend
7
7
  * refuses new buys and renewals; refunds and verify remain open.
8
8
  *
9
9
  * Resolution order for buy/renew clients that want to know the current
@@ -12,17 +12,36 @@
12
12
  * constant, or pulled from the vendor's own env at boot).
13
13
  * 2. `process.env.FREEZE_AFTER_SLOT` when running under Node (server-side
14
14
  * integrators / CLIs).
15
- * 3. Keeper's own `/health` payload — the authoritative source of truth.
15
+ * 3. Backend's own `/health` payload — the authoritative source of truth.
16
16
  *
17
17
  * A `freezeAfterSlot` of 0 / null / undefined means "no freeze scheduled".
18
18
  */
19
- export type KeeperHealth = {
20
- status: string;
21
- network: string;
19
+ export type NetworkHealth = {
20
+ graphqlUrl?: string;
21
+ archiveUrl?: string;
22
22
  slot: number;
23
23
  salesFrozen: boolean;
24
24
  freezeAfterSlot: number | null;
25
25
  };
26
+ export type KeeperHealth = {
27
+ status: string;
28
+ devnet?: NetworkHealth;
29
+ mainnet?: NetworkHealth;
30
+ /** @deprecated legacy flat shape */
31
+ network?: string;
32
+ /** @deprecated legacy flat shape */
33
+ slot?: number;
34
+ /** @deprecated legacy flat shape */
35
+ salesFrozen?: boolean;
36
+ /** @deprecated legacy flat shape */
37
+ freezeAfterSlot?: number | null;
38
+ };
39
+ /**
40
+ * The health block for `network`. Without a network: the only configured
41
+ * one, or null when several are configured (ambiguous). Falls back to the
42
+ * legacy flat shape.
43
+ */
44
+ export declare function pickNetworkHealth(health: KeeperHealth, network?: 'devnet' | 'mainnet'): NetworkHealth | null;
26
45
  export type FreezeState = {
27
46
  salesFrozen: boolean;
28
47
  freezeAfterSlot: number | null;
@@ -36,6 +55,7 @@ export type GetKeeperHealthOptions = {
36
55
  export declare function getKeeperHealth(opts: GetKeeperHealthOptions): Promise<KeeperHealth>;
37
56
  export type ResolveFreezeStateOptions = {
38
57
  keeperUrl: string;
58
+ network?: 'devnet' | 'mainnet';
39
59
  freezeAfterSlot?: number | null;
40
60
  fetcher?: typeof fetch;
41
61
  signal?: AbortSignal;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freezeClient.d.ts","sourceRoot":"","sources":["../src/freezeClient.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,CAAC,EAAM,MAAM,CAAC;IACxB,UAAU,CAAC,EAAM,MAAM,CAAC;IACxB,IAAI,EAAa,MAAM,CAAC;IACxB,WAAW,EAAM,OAAO,CAAC;IACzB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAOF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAY,MAAM,CAAC;IACzB,MAAM,CAAC,EAAW,aAAa,CAAC;IAChC,OAAO,CAAC,EAAU,aAAa,CAAC;IAChC,oCAAoC;IACpC,OAAO,CAAC,EAAU,MAAM,CAAC;IACzB,oCAAoC;IACpC,IAAI,CAAC,EAAa,MAAM,CAAC;IACzB,oCAAoC;IACpC,WAAW,CAAC,EAAM,OAAO,CAAC;IAC1B,oCAAoC;IACpC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,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