@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 CHANGED
@@ -36,7 +36,6 @@ pnpm add jose@^5
36
36
  - `AUTH_PROOF_DEVICE_SESSION_SECRET`
37
37
  - `AUTH_PROOF_DEVICE_SESSION_TTL_SECONDS`
38
38
  - `AUTH_PROOF_TIME_TOLERANCE_SECONDS`
39
- - `AUTH_PROOF_SHADOW_BLOCK_MISSING_PROOF=0|1`
40
39
 
41
40
  服务端应在启动阶段调用 `resolveProofServerConfig()`:
42
41
 
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 = async () => {
166
- const pendingKey = proofKeyPromise
167
- proofKeyPromise = null
168
- await pendingKey?.catch(() => undefined)
169
- if (!globalThis.indexedDB) return
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
- const database = await openDatabase()
172
- try {
173
- await new Promise((resolve, reject) => {
174
- const transaction = database.transaction(storeName, 'readwrite')
175
- transaction.objectStore(storeName).delete(recordId)
176
- transaction.oncomplete = () => resolve()
177
- transaction.onerror = () => reject(new Error('request_proof_reset_failed'))
178
- transaction.onabort = () => reject(new Error('request_proof_reset_failed'))
179
- })
180
- } finally {
181
- database.close()
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travelclw/proof-protocol",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Framework-independent browser and Node.js request Proof protocol",
5
5
  "license": "MIT",
6
6
  "author": "travelclw",
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