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.
- package/README.md +212 -83
- package/build/appsLookup.d.ts +14 -0
- package/build/appsLookup.d.ts.map +1 -0
- package/build/appsLookup.js +12 -0
- package/build/appsLookup.js.map +1 -0
- package/build/archiveBootstrap.d.ts +15 -1
- package/build/archiveBootstrap.d.ts.map +1 -1
- package/build/archiveBootstrap.js +61 -8
- package/build/archiveBootstrap.js.map +1 -1
- package/build/bindClient.d.ts +51 -0
- package/build/bindClient.d.ts.map +1 -0
- package/build/bindClient.js +115 -0
- package/build/bindClient.js.map +1 -0
- package/build/buyClient.d.ts +8 -3
- package/build/buyClient.d.ts.map +1 -1
- package/build/buyClient.js +25 -13
- package/build/buyClient.js.map +1 -1
- package/build/contractInterface.d.ts +11 -5
- package/build/contractInterface.d.ts.map +1 -1
- package/build/contractInterface.js +81 -16
- package/build/contractInterface.js.map +1 -1
- package/build/deviceIdentity.d.ts +68 -0
- package/build/deviceIdentity.d.ts.map +1 -0
- package/build/deviceIdentity.js +209 -0
- package/build/deviceIdentity.js.map +1 -0
- package/build/generationClient.d.ts +1 -0
- package/build/generationClient.d.ts.map +1 -1
- package/build/generationClient.js +1 -1
- package/build/generationClient.js.map +1 -1
- package/build/index.d.ts +27 -37
- package/build/index.d.ts.map +1 -1
- package/build/index.js +84 -115
- package/build/index.js.map +1 -1
- package/build/licenseLeaf.d.ts +76 -0
- package/build/licenseLeaf.d.ts.map +1 -0
- package/build/licenseLeaf.js +189 -0
- package/build/licenseLeaf.js.map +1 -0
- package/build/licenseRecord.d.ts +10 -1
- package/build/licenseRecord.d.ts.map +1 -1
- package/build/licenseRecord.js.map +1 -1
- package/build/licenseStore.d.ts +16 -1
- package/build/licenseStore.d.ts.map +1 -1
- package/build/licenseStore.js +163 -5
- package/build/licenseStore.js.map +1 -1
- package/build/manifestVerify.d.ts.map +1 -1
- package/build/manifestVerify.js +7 -2
- package/build/manifestVerify.js.map +1 -1
- package/build/migrateClient.d.ts +1 -0
- package/build/migrateClient.d.ts.map +1 -1
- package/build/migrateClient.js +1 -0
- package/build/migrateClient.js.map +1 -1
- package/build/onChainRoot.d.ts +67 -0
- package/build/onChainRoot.d.ts.map +1 -0
- package/build/onChainRoot.js +87 -0
- package/build/onChainRoot.js.map +1 -0
- package/build/ownershipLicenseHash.d.ts +25 -0
- package/build/ownershipLicenseHash.d.ts.map +1 -0
- package/build/ownershipLicenseHash.js +29 -0
- package/build/ownershipLicenseHash.js.map +1 -0
- package/build/ownershipSignature.d.ts +122 -0
- package/build/ownershipSignature.d.ts.map +1 -0
- package/build/ownershipSignature.js +244 -0
- package/build/ownershipSignature.js.map +1 -0
- package/build/proveErrors.d.ts +7 -7
- package/build/proveErrors.js +7 -7
- package/build/refundClient.d.ts +2 -11
- package/build/refundClient.d.ts.map +1 -1
- package/build/refundClient.js +34 -16
- package/build/refundClient.js.map +1 -1
- package/build/renewClient.d.ts +3 -1
- package/build/renewClient.d.ts.map +1 -1
- package/build/renewClient.js +2 -1
- package/build/renewClient.js.map +1 -1
- package/build/seatName.d.ts +8 -0
- package/build/seatName.d.ts.map +1 -0
- package/build/seatName.js +136 -0
- package/build/seatName.js.map +1 -0
- package/build/statsClient.d.ts +19 -4
- package/build/statsClient.d.ts.map +1 -1
- package/build/statsClient.js +14 -4
- package/build/statsClient.js.map +1 -1
- package/build/trustAnchorVerify.d.ts +48 -0
- package/build/trustAnchorVerify.d.ts.map +1 -0
- package/build/trustAnchorVerify.js +431 -0
- package/build/trustAnchorVerify.js.map +1 -0
- package/build/trustAnchorVerifyCli.d.ts +35 -0
- package/build/trustAnchorVerifyCli.d.ts.map +1 -0
- package/build/trustAnchorVerifyCli.js +177 -0
- package/build/trustAnchorVerifyCli.js.map +1 -0
- package/build/unbindClient.d.ts +56 -0
- package/build/unbindClient.d.ts.map +1 -0
- package/build/unbindClient.js +113 -0
- package/build/unbindClient.js.map +1 -0
- package/build/vendorAccountClient.d.ts +1 -0
- package/build/vendorAccountClient.d.ts.map +1 -1
- package/build/vendorAccountClient.js +4 -1
- package/build/vendorAccountClient.js.map +1 -1
- package/build/verifyCore.d.ts +1 -1
- package/build/verifyCore.d.ts.map +1 -1
- package/build/verifyCore.js +10 -3
- package/build/verifyCore.js.map +1 -1
- package/build/verifyOffline.d.ts +85 -0
- package/build/verifyOffline.d.ts.map +1 -0
- package/build/verifyOffline.js +139 -0
- package/build/verifyOffline.js.map +1 -0
- package/build/verifyService.js +581 -454
- package/build/verifyService.js.map +1 -1
- package/build/verifyWithAncestors.d.ts +18 -0
- package/build/verifyWithAncestors.d.ts.map +1 -0
- package/build/verifyWithAncestors.js +119 -0
- package/build/verifyWithAncestors.js.map +1 -0
- package/package.json +40 -11
- package/src/appsLookup.ts +48 -0
- package/src/archiveBootstrap.ts +71 -14
- package/src/bindClient.ts +175 -0
- package/src/buyClient.ts +67 -22
- package/src/contractInterface.d.ts +11 -5
- package/src/contractInterface.ts +105 -34
- package/src/deviceIdentity.ts +249 -0
- package/src/generationClient.ts +2 -1
- package/src/index.ts +128 -191
- package/src/licenseLeaf.ts +221 -0
- package/src/licenseRecord.ts +19 -2
- package/src/licenseStore.ts +186 -6
- package/src/manifestVerify.ts +7 -2
- package/src/migrateClient.ts +2 -0
- package/src/onChainRoot.ts +107 -0
- package/src/ownershipLicenseHash.ts +31 -0
- package/src/ownershipSignature.ts +354 -0
- package/src/proveErrors.ts +7 -7
- package/src/refundClient.ts +27 -13
- package/src/renewClient.ts +7 -2
- package/src/seatName.ts +165 -0
- package/src/statsClient.ts +54 -9
- package/src/trustAnchorVerify.ts +548 -0
- package/src/trustAnchorVerifyCli.ts +179 -0
- package/src/unbindClient.ts +149 -0
- package/src/vendorAccountClient.ts +9 -5
- package/src/verifyCore.ts +11 -3
- package/src/verifyOffline.ts +212 -0
- package/src/verifyService.ts +658 -488
- package/src/verifyWithAncestors.ts +153 -0
- package/build/licenseProof.d.ts +0 -26
- package/build/licenseProof.d.ts.map +0 -1
- package/build/licenseProof.js +0 -41
- package/build/licenseProof.js.map +0 -1
- package/build/ownership.d.ts +0 -34
- package/build/ownership.d.ts.map +0 -1
- package/build/ownership.js +0 -147
- package/build/ownership.js.map +0 -1
- package/build/proveRetry.d.ts +0 -38
- package/build/proveRetry.d.ts.map +0 -1
- package/build/proveRetry.js +0 -89
- package/build/proveRetry.js.map +0 -1
- package/src/licenseProof.d.ts +0 -26
- package/src/licenseProof.ts +0 -48
- package/src/ownership.ts +0 -198
|
@@ -12,12 +12,9 @@
|
|
|
12
12
|
* about durations are published here so a public verify service can replay
|
|
13
13
|
* the archive without pulling in the contract source.
|
|
14
14
|
*
|
|
15
|
-
* `CANONICAL_VK_HASH`
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* challenge/response `ZkProgram`), respectively. Both are hand-maintained
|
|
19
|
-
* constants — bump them whenever the corresponding circuit changes and
|
|
20
|
-
* rerun the keeper's boot assertion (see zklicensing-app/src/keeperService.ts)
|
|
15
|
+
* `CANONICAL_VK_HASH` is the verification-key hash of the published
|
|
16
|
+
* `LicensingApp` circuit. Bump it whenever the on-chain zkApp changes
|
|
17
|
+
* and rerun the keeper's boot assertion (see zklicensing-app/src/keeperService.ts)
|
|
21
18
|
* / the verify service's `ensureCompiled()` check to catch drift.
|
|
22
19
|
*/
|
|
23
20
|
import { declareState, fetchAccount, Field, PublicKey, SmartContract, Struct, UInt32, UInt64, MerkleMap } from 'o1js';
|
|
@@ -33,12 +30,27 @@ import { declareState, fetchAccount, Field, PublicKey, SmartContract, Struct, UI
|
|
|
33
30
|
// The clean alternative — `export class X extends Struct({...}) {}` as the
|
|
34
31
|
// mina-fungible-token repo does — only works when o1js sits inside rootDir,
|
|
35
32
|
// which a workspace member can't guarantee.
|
|
33
|
+
// `cap` is carried so that a keeper reconstructing the license from archive
|
|
34
|
+
// events (e.g. after losing its in-memory intent map to a restart) can
|
|
35
|
+
// rehydrate the exact LicenseLeaf that was committed on-chain. Without it,
|
|
36
|
+
// leafFromRecord() would default cap to UInt32.zero and every follow-up
|
|
37
|
+
// root-mutating proof (renew, refund, bind, unbind, migrate) would fail the
|
|
38
|
+
// in-circuit hash check.
|
|
39
|
+
//
|
|
40
|
+
// `deviceSlotsRoot` / `deviceSlotsFilled` are omitted deliberately: at issue
|
|
41
|
+
// time they are always EMPTY_DEVICE_SLOTS_ROOT / 0. The keeper's rehydration
|
|
42
|
+
// uses those defaults, matching the leaf the circuit wrote.
|
|
43
|
+
//
|
|
44
|
+
// The leaf carries no separate ownerPubKeyHash — `licenseHash` IS the owner-
|
|
45
|
+
// pubkey commitment (buyLicense asserts them equal), so it doesn't need to
|
|
46
|
+
// ride in the event either.
|
|
36
47
|
export const LicenseIssuedEvent = Struct({
|
|
37
48
|
licenseHash: Field,
|
|
38
49
|
buyer: PublicKey,
|
|
39
50
|
amount: UInt64,
|
|
40
51
|
slot: UInt32,
|
|
41
52
|
expirySlot: UInt32,
|
|
53
|
+
cap: UInt32,
|
|
42
54
|
});
|
|
43
55
|
export const ExpiryUpdateEvent = Struct({
|
|
44
56
|
licenseHash: Field,
|
|
@@ -48,6 +60,7 @@ export const PriceUpdatedEvent = Struct({
|
|
|
48
60
|
priceMonthly: UInt64,
|
|
49
61
|
priceYearly: UInt64,
|
|
50
62
|
priceFiveYear: UInt64,
|
|
63
|
+
pricePerpetual: UInt64,
|
|
51
64
|
});
|
|
52
65
|
export const AppCreatedEvent = Struct({
|
|
53
66
|
vendor: PublicKey,
|
|
@@ -59,10 +72,53 @@ export const AppCreatedEvent = Struct({
|
|
|
59
72
|
// licensesRoot entry; `ancestorGen` is the generation index the migration
|
|
60
73
|
// resolved against (needed so archive replay and auditors can trace which
|
|
61
74
|
// frozen root supplied the entry — skip-generation migrations are one-hop).
|
|
75
|
+
// Migration copies the ancestor leaf verbatim, so a destination keeper that
|
|
76
|
+
// only sees `licenseMigrated` (never saw the original `licenseIssued` on the
|
|
77
|
+
// ancestor deployment) needs every leaf field to rehydrate correctly. Unlike
|
|
78
|
+
// LicenseIssuedEvent, `deviceSlotsRoot` and `deviceSlotsFilled` are included
|
|
79
|
+
// here because a migrated license may carry pre-existing bindings from its
|
|
80
|
+
// ancestor deployment.
|
|
62
81
|
export const LicenseMigratedEvent = Struct({
|
|
63
82
|
licenseHash: Field,
|
|
64
83
|
expirySlot: UInt32,
|
|
65
84
|
ancestorGen: UInt32,
|
|
85
|
+
cap: UInt32,
|
|
86
|
+
deviceSlotsRoot: Field,
|
|
87
|
+
deviceSlotsFilled: UInt32,
|
|
88
|
+
});
|
|
89
|
+
// Emitted by `bind` when the buyer's device commitment lands in a slot on
|
|
90
|
+
// their license leaf. `deviceCommitment = Poseidon(devicePubKeyHash)` — the
|
|
91
|
+
// raw pubkey is never revealed. `slotIndex` is 0-based within the license's
|
|
92
|
+
// fixed-size slot array (see DEVICE_SLOT_CAP).
|
|
93
|
+
//
|
|
94
|
+
// `boundAtSlot` carries the circuit's proof-time `globalSlotSinceGenesis` —
|
|
95
|
+
// the exact value packed into the leaf's `freedAt` via `packSlotTimes(
|
|
96
|
+
// currentSlot, 0)`. Off-chain keepers rebuilding `deviceSlotsRoot` MUST use
|
|
97
|
+
// this, not the block's globalSlot: the tx's precondition allows any block
|
|
98
|
+
// slot within TOLERANCE_WINDOW of proof time, so block-slot != proof-slot in
|
|
99
|
+
// the general case, and any mismatch flips the packed field, the leaf hash,
|
|
100
|
+
// and the aggregate `licensesRoot`. Follows the same pattern as
|
|
101
|
+
// `LicenseIssuedEvent.slot`.
|
|
102
|
+
export const DeviceBoundEvent = Struct({
|
|
103
|
+
licenseHash: Field,
|
|
104
|
+
slotIndex: UInt32,
|
|
105
|
+
deviceCommitment: Field,
|
|
106
|
+
boundAtSlot: UInt32,
|
|
107
|
+
});
|
|
108
|
+
// Emitted by `unbind` when a slot is freed. `slotIndex` stays occupied in the
|
|
109
|
+
// array (`slotFreedAt` stamp stays set) so the cooldown timer starts; the
|
|
110
|
+
// slot's `occupied` field goes to Field(0). Any device holding the license's
|
|
111
|
+
// ownership key can trigger this — remote log-off is by design.
|
|
112
|
+
//
|
|
113
|
+
// `freedAtSlot` carries the circuit's proof-time `globalSlotSinceGenesis` —
|
|
114
|
+
// the value packed into the leaf's `freedAt` via `packSlotTimes(preservedBound,
|
|
115
|
+
// currentSlot)`. Same off-chain reconstruction reason as `DeviceBoundEvent.
|
|
116
|
+
// boundAtSlot`. The preserved `boundAtSlot` is not re-emitted; keeper reads
|
|
117
|
+
// it from its own record (which still has the earlier bind's stamp).
|
|
118
|
+
export const DeviceUnboundEvent = Struct({
|
|
119
|
+
licenseHash: Field,
|
|
120
|
+
slotIndex: UInt32,
|
|
121
|
+
freedAtSlot: UInt32,
|
|
66
122
|
});
|
|
67
123
|
// ------------------------------------------------------------
|
|
68
124
|
// CONSTANTS (slot math — 90 s/slot after Mesa upgrade)
|
|
@@ -70,6 +126,7 @@ export const LicenseMigratedEvent = Struct({
|
|
|
70
126
|
export const MONTHLY_SLOTS_N = 28_800; // 30 days × 24 × 40
|
|
71
127
|
export const ONE_YEAR_SLOTS_N = 350_640; // 365.25 days × 24 × 40 (Julian year)
|
|
72
128
|
export const FIVE_YEAR_SLOTS_N = 1_753_200; // 5 × ONE_YEAR_SLOTS_N
|
|
129
|
+
export const PERPETUAL_SLOTS_N = 350_640_000; // 1000 × ONE_YEAR_SLOTS_N ("perpetual — until vendor sunset")
|
|
73
130
|
export const REFUND_WINDOW_N = 13_440;
|
|
74
131
|
export const GRACE_PERIOD_N = 6_720;
|
|
75
132
|
export const MS_PER_SLOT_N = 90_000; // Mesa slot duration in ms
|
|
@@ -87,8 +144,8 @@ export const EMPTY_ROOT = new MerkleMap().getRoot();
|
|
|
87
144
|
// ------------------------------------------------------------
|
|
88
145
|
// DURATION HELPERS
|
|
89
146
|
// ------------------------------------------------------------
|
|
90
|
-
export const DURATION_LABELS = ['1 Month', '1 Year', '5 Years'];
|
|
91
|
-
export const DURATION_INDEX = { '1 Month': 0, '1 Year': 1, '5 Years': 2 };
|
|
147
|
+
export const DURATION_LABELS = ['1 Month', '1 Year', '5 Years', 'Perpetual'];
|
|
148
|
+
export const DURATION_INDEX = { '1 Month': 0, '1 Year': 1, '5 Years': 2, 'Perpetual': 3 };
|
|
92
149
|
export function durationSlotsFromLabel(label) {
|
|
93
150
|
if (label === '1 Month')
|
|
94
151
|
return MONTHLY_SLOTS_N;
|
|
@@ -96,6 +153,8 @@ export function durationSlotsFromLabel(label) {
|
|
|
96
153
|
return ONE_YEAR_SLOTS_N;
|
|
97
154
|
if (label === '5 Years')
|
|
98
155
|
return FIVE_YEAR_SLOTS_N;
|
|
156
|
+
if (label === 'Perpetual')
|
|
157
|
+
return PERPETUAL_SLOTS_N;
|
|
99
158
|
return null;
|
|
100
159
|
}
|
|
101
160
|
export function durationIndexFromLabel(label) {
|
|
@@ -105,6 +164,8 @@ export function durationIndexFromLabel(label) {
|
|
|
105
164
|
return 1;
|
|
106
165
|
if (label === '5 Years')
|
|
107
166
|
return 2;
|
|
167
|
+
if (label === 'Perpetual')
|
|
168
|
+
return 3;
|
|
108
169
|
return null;
|
|
109
170
|
}
|
|
110
171
|
export function durationLabelFromIndex(idx) {
|
|
@@ -127,12 +188,14 @@ export class LicensingAppEventsContract extends SmartContract {
|
|
|
127
188
|
refundIssued: Field,
|
|
128
189
|
fundsReleased: Field,
|
|
129
190
|
priceUpdated: PriceUpdatedEvent,
|
|
191
|
+
deviceBound: DeviceBoundEvent,
|
|
192
|
+
deviceUnbound: DeviceUnboundEvent,
|
|
130
193
|
};
|
|
131
194
|
}
|
|
132
195
|
// State-slot layout mirrors LicensingApp's declareState(). Read-only from here
|
|
133
196
|
// — no @method bodies exist. Consumers use `.version.get()`, `.licensesRoot.get()`
|
|
134
|
-
// etc. after fetchAccount(). `pricesPacked` is a single Field with the
|
|
135
|
-
//
|
|
197
|
+
// etc. after fetchAccount(). `pricesPacked` is a single Field with the four
|
|
198
|
+
// 63-bit tier prices packed as [pM | pY<<63 | pF<<126 | pP<<189]; unpack with
|
|
136
199
|
// `unpackPrices` if you need the individual tiers off-chain.
|
|
137
200
|
declareState(LicensingAppEventsContract, {
|
|
138
201
|
licensesRoot: Field,
|
|
@@ -144,14 +207,17 @@ declareState(LicensingAppEventsContract, {
|
|
|
144
207
|
});
|
|
145
208
|
// Off-chain mirror of the in-circuit price packing (see LicensingApp.ts). Kept
|
|
146
209
|
// here so the events service can decode `pricesPacked` slots without pulling
|
|
147
|
-
// the private contract source.
|
|
210
|
+
// the private contract source. Layout: four 63-bit tiers = 252 bits, fits in
|
|
211
|
+
// the ~254-bit Field. Each tier's high bit is unused — a UInt64 written by
|
|
212
|
+
// packPrices is range-checked to 63 bits in circuit.
|
|
148
213
|
export function unpackPrices(packed) {
|
|
149
214
|
const raw = packed.toBigInt();
|
|
150
|
-
const mask = (1n <<
|
|
215
|
+
const mask = (1n << 63n) - 1n;
|
|
151
216
|
return {
|
|
152
217
|
priceMonthly: UInt64.from(raw & mask),
|
|
153
|
-
priceYearly: UInt64.from((raw >>
|
|
154
|
-
priceFiveYear: UInt64.from((raw >>
|
|
218
|
+
priceYearly: UInt64.from((raw >> 63n) & mask),
|
|
219
|
+
priceFiveYear: UInt64.from((raw >> 126n) & mask),
|
|
220
|
+
pricePerpetual: UInt64.from((raw >> 189n) & mask),
|
|
155
221
|
};
|
|
156
222
|
}
|
|
157
223
|
// ------------------------------------------------------------
|
|
@@ -204,10 +270,9 @@ export async function fetchLicensingAppVersion(zkAppAddress) {
|
|
|
204
270
|
// boot-assert are unchanged.
|
|
205
271
|
// ------------------------------------------------------------
|
|
206
272
|
export const CANONICAL_VK_HASHES = {
|
|
207
|
-
1: '
|
|
273
|
+
1: '10361895475617514346344501316555182806545828598248691756333156231763191857993',
|
|
208
274
|
// 2: '…' — append at each hardfork migration, never delete.
|
|
209
275
|
};
|
|
210
276
|
export const CURRENT_GENERATION = 1;
|
|
211
277
|
export const CANONICAL_VK_HASH = CANONICAL_VK_HASHES[CURRENT_GENERATION];
|
|
212
|
-
export const CANONICAL_LICENSE_PROOF_VK_HASH = '6592142093294558010952934797827640785154417146015648013584661926355710165692';
|
|
213
278
|
//# sourceMappingURL=contractInterface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractInterface.js","sourceRoot":"","sources":["../src/contractInterface.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC
|
|
1
|
+
{"version":3,"file":"contractInterface.js","sourceRoot":"","sources":["../src/contractInterface.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtH,+DAA+D;AAC/D,gBAAgB;AAChB,+DAA+D;AAE/D,0EAA0E;AAC1E,0EAA0E;AAC1E,0EAA0E;AAC1E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,4CAA4C;AAE5C,4EAA4E;AAC5E,uEAAuE;AACvE,2EAA2E;AAC3E,wEAAwE;AACxE,4EAA4E;AAC5E,yBAAyB;AACzB,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,4DAA4D;AAC5D,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,4BAA4B;AAC5B,MAAM,CAAC,MAAM,kBAAkB,GAAQ,MAAM,CAAC;IAC5C,WAAW,EAAE,KAAK;IAClB,KAAK,EAAQ,SAAS;IACtB,MAAM,EAAO,MAAM;IACnB,IAAI,EAAS,MAAM;IACnB,UAAU,EAAG,MAAM;IACnB,GAAG,EAAU,MAAM;CACpB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,iBAAiB,GAAQ,MAAM,CAAC;IAC3C,WAAW,EAAE,KAAK;IA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,YAAY,CAAC,CAAC;IAC/C,MAAM,YAAY,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAQ,IAAI,0BAA0B,CAAC,GAAG,CAAC,CAAC;IAC1D,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,+DAA+D;AAC/D,sBAAsB;AACtB,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,6EAA6E;AAC7E,uEAAuE;AACvE,yEAAyE;AACzE,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,EAAE;AACF,SAAS;AACT,wEAAwE;AACxE,8BAA8B;AAC9B,kEAAkE;AAClE,6EAA6E;AAC7E,iCAAiC;AACjC,+DAA+D;AAE/D,MAAM,CAAC,MAAM,mBAAmB,GAAqC;IACnE,CAAC,EAAE,+EAA+E;IAClF,4DAA4D;CAC7D,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAW,CAAC,CAAC;AAE5C,MAAM,CAAC,MAAM,iBAAiB,GAAW,mBAAmB,CAAC,kBAAkB,CAAC,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,cAAc,GAAG,eAAe,CAAC;AAEvC,SAAS,UAAU,CAAC,UAAkB;IACpC,OAAO,GAAG,cAAc,GAAG,UAAU,EAAE,CAAC;AAC1C,CAAC;AAcD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,YAAuB;IAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAClF,CAAC;AAED,SAAS,aAAa,CAAC,UAAsB;IAC3C,MAAM,YAAY,GAA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
17
|
keeperUrl: string;
|
|
18
|
+
network: 'devnet' | 'mainnet';
|
|
18
19
|
appId: string;
|
|
19
20
|
/** Base64-encoded Ed25519 public keys pinned by the caller. Empty ⇒ verified:false. */
|
|
20
21
|
pinnedPublicKeysBase64: readonly string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generationClient.d.ts","sourceRoot":"","sources":["../src/generationClient.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAW,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAQ,SAAS,GAAG,MAAM,CAAC;IACjC,UAAU,CAAC,EAAG,MAAM,CAAC;IACrB,UAAU,CAAC,EAAG,MAAM,CAAC;IACrB,SAAS,CAAC,EAAI,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,sGAAsG;IACtG,OAAO,EAAM,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,qEAAqE;IACrE,QAAQ,EAAK,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAK,MAAM,CAAC;IACjB,uFAAuF;IACvF,sBAAsB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,MAAM,CAAC,EAAG,WAAW,CAAC;CACvB;AAED,MAAM,WAAW,+BAA+B;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB,uFAAuF;IACvF,sBAAsB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,MAAM,CAAC,EAAG,WAAW,CAAC;CACvB;AA6CD;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,sBAAsB,GAAG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OAAO,CAAC,cAAc,CAAC,CAc9F;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,+BAA+B,GACnC,OAAO,CAAC,cAAc,CAAC,CAmBzB"}
|
|
@@ -61,7 +61,7 @@ async function verifyAndProject(parsed, pinnedPublicKeysBase64) {
|
|
|
61
61
|
*/
|
|
62
62
|
export async function fetchGenerationInfo(req) {
|
|
63
63
|
const fetcher = req.fetcher ?? fetch;
|
|
64
|
-
const resp = await fetcher(`${baseUrl(req.keeperUrl)}/apps/${encodeURIComponent(req.appId)}`, {
|
|
64
|
+
const resp = await fetcher(`${baseUrl(req.keeperUrl)}/apps/${encodeURIComponent(req.appId)}?network=${req.network}`, {
|
|
65
65
|
method: 'GET',
|
|
66
66
|
signal: req.signal,
|
|
67
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generationClient.js","sourceRoot":"","sources":["../src/generationClient.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"generationClient.js","sourceRoot":"","sources":["../src/generationClient.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,oCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAuC9D,SAAS,OAAO,CAAC,GAAW;IAC1B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC;AAUD,SAAS,mBAAmB,CAAC,IAA6B;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC;IACjC,OAAO;QACL,OAAO,EAAM,OAAO,IAAI,CAAC,OAAO,KAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAG,CAAC,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