@travelclw/proof-protocol 0.1.0 → 0.1.1
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 +0 -1
- package/browser.js +29 -17
- package/node.d.ts +0 -2
- package/package.json +1 -1
- package/server.js +0 -20
package/README.md
CHANGED
package/browser.js
CHANGED
|
@@ -59,6 +59,7 @@ const createBrowserProofClient = options => {
|
|
|
59
59
|
const recordId = String(options?.recordId || 'request-proof-key').trim()
|
|
60
60
|
const required = () => isRequestProofRequired(options?.required?.())
|
|
61
61
|
let proofKeyPromise = null
|
|
62
|
+
let resetPromise = null
|
|
62
63
|
|
|
63
64
|
if (!databaseName || !storeName || !recordId) {
|
|
64
65
|
throw new Error('request_proof_storage_failed')
|
|
@@ -150,7 +151,9 @@ const createBrowserProofClient = options => {
|
|
|
150
151
|
|
|
151
152
|
const getOrCreateKey = () => {
|
|
152
153
|
if (!proofKeyPromise) {
|
|
154
|
+
const pendingReset = resetPromise
|
|
153
155
|
proofKeyPromise = (async () => {
|
|
156
|
+
await pendingReset
|
|
154
157
|
const storedKey = await readStoredKey()
|
|
155
158
|
if (isStoredKeyValid(storedKey)) return storedKey
|
|
156
159
|
return storeIfAbsent(await generateCandidate())
|
|
@@ -162,24 +165,33 @@ const createBrowserProofClient = options => {
|
|
|
162
165
|
return proofKeyPromise
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
const reset =
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
const reset = () => {
|
|
169
|
+
const pendingReset = resetPromise
|
|
170
|
+
const operation = (async () => {
|
|
171
|
+
const pendingKey = proofKeyPromise
|
|
172
|
+
proofKeyPromise = null
|
|
173
|
+
await pendingReset?.catch(() => undefined)
|
|
174
|
+
await pendingKey?.catch(() => undefined)
|
|
175
|
+
if (!globalThis.indexedDB) return
|
|
170
176
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
const database = await openDatabase()
|
|
178
|
+
try {
|
|
179
|
+
await new Promise((resolve, reject) => {
|
|
180
|
+
const transaction = database.transaction(storeName, 'readwrite')
|
|
181
|
+
transaction.objectStore(storeName).delete(recordId)
|
|
182
|
+
transaction.oncomplete = () => resolve()
|
|
183
|
+
transaction.onerror = () => reject(new Error('request_proof_reset_failed'))
|
|
184
|
+
transaction.onabort = () => reject(new Error('request_proof_reset_failed'))
|
|
185
|
+
})
|
|
186
|
+
} finally {
|
|
187
|
+
database.close()
|
|
188
|
+
}
|
|
189
|
+
})()
|
|
190
|
+
|
|
191
|
+
resetPromise = operation
|
|
192
|
+
return operation.finally(() => {
|
|
193
|
+
if (resetPromise === operation) resetPromise = null
|
|
194
|
+
})
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
const getRegistration = async () => {
|
package/node.d.ts
CHANGED
|
@@ -41,7 +41,6 @@ export type ProofServerConfig = {
|
|
|
41
41
|
deviceSessionSecret: string
|
|
42
42
|
deviceSessionTtlSeconds: number
|
|
43
43
|
timeToleranceSeconds: number
|
|
44
|
-
shadowBlockMissingProof: boolean
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
export const REQUEST_PROOF_REASON_TEXT: Readonly<Record<string, string>>
|
|
@@ -72,7 +71,6 @@ export function resolveProofServerConfig(options?: {
|
|
|
72
71
|
deviceSessionSecret?: string
|
|
73
72
|
deviceSessionTtlSeconds?: number
|
|
74
73
|
timeToleranceSeconds?: number
|
|
75
|
-
shadowBlockMissingProof?: boolean
|
|
76
74
|
}): ProofServerConfig
|
|
77
75
|
|
|
78
76
|
export { RequestProofValidationError } from './core'
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -238,15 +238,6 @@ const integerSetting = (value, fallback, name, minimum, maximum) => {
|
|
|
238
238
|
return parsed
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
const booleanSetting = (value, fallback, name) => {
|
|
242
|
-
if (value === undefined || String(value).trim() === '') return fallback
|
|
243
|
-
const normalized = String(value).trim()
|
|
244
|
-
if (normalized !== '0' && normalized !== '1') {
|
|
245
|
-
throw new Error(`${name} must be 0 or 1`)
|
|
246
|
-
}
|
|
247
|
-
return normalized === '1'
|
|
248
|
-
}
|
|
249
|
-
|
|
250
241
|
const resolveProofServerConfig = options => {
|
|
251
242
|
const env = options?.env ?? (typeof process !== 'undefined' ? process.env : {})
|
|
252
243
|
const mode = normalizeProofMode(readOverride(env, 'AUTH_PROOF_MODE', options?.mode))
|
|
@@ -270,16 +261,6 @@ const resolveProofServerConfig = options => {
|
|
|
270
261
|
30,
|
|
271
262
|
DEFAULT_REQUEST_PROOF_TIME_TOLERANCE_SECONDS,
|
|
272
263
|
)
|
|
273
|
-
const shadowBlockMissingProof = booleanSetting(
|
|
274
|
-
readOverride(
|
|
275
|
-
env,
|
|
276
|
-
'AUTH_PROOF_SHADOW_BLOCK_MISSING_PROOF',
|
|
277
|
-
options?.shadowBlockMissingProof ? '1' : '0',
|
|
278
|
-
),
|
|
279
|
-
false,
|
|
280
|
-
'AUTH_PROOF_SHADOW_BLOCK_MISSING_PROOF',
|
|
281
|
-
)
|
|
282
|
-
|
|
283
264
|
if (mode !== 'off' && deviceSessionSecret.length < 32) {
|
|
284
265
|
throw new Error(
|
|
285
266
|
'AUTH_PROOF_DEVICE_SESSION_SECRET is required when AUTH_PROOF_MODE is shadow or enforce and must contain at least 32 characters',
|
|
@@ -290,7 +271,6 @@ const resolveProofServerConfig = options => {
|
|
|
290
271
|
deviceSessionSecret,
|
|
291
272
|
deviceSessionTtlSeconds,
|
|
292
273
|
timeToleranceSeconds,
|
|
293
|
-
shadowBlockMissingProof,
|
|
294
274
|
}
|
|
295
275
|
}
|
|
296
276
|
|