@kokuin/vault 0.7.0 → 0.7.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 +16 -0
- package/lib/record-types.d.ts +3 -3
- package/lib/record-types.js +30 -8
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -163,3 +163,19 @@ Existing params objects also flatten their options fields:
|
|
|
163
163
|
| Existing params type | Updated params type | Field migration |
|
|
164
164
|
| --- | --- | --- |
|
|
165
165
|
| `DecodedAsParams` | `DecodedAsParams` | `Nested options fields → top-level fields` |
|
|
166
|
+
|
|
167
|
+
## Cooperative yielding
|
|
168
|
+
|
|
169
|
+
`vaultRecordTypes`, `vaultKeyVersionReader`, and `vaultProofAuthorizer` accept `yield?: boolean` from `@kokuin/token` (`YieldOptions`).
|
|
170
|
+
Their policies forward it through stored-record and introducing-op verification.
|
|
171
|
+
Factory options are captured when created.
|
|
172
|
+
|
|
173
|
+
`yield: false` skips cooperative timers for these signing and verification paths.
|
|
174
|
+
Record `authorize` and `visibleTo` hooks prefer per-call `ctx.yield` over the construction policy.
|
|
175
|
+
Omitting the option preserves the construction policy, default yielding and all cryptographic checks.
|
|
176
|
+
Callers must yield between transactions when disabling yields inside a transaction.
|
|
177
|
+
|
|
178
|
+
Store adapters may provide a `yield` accessor alongside their scoped `methods` accessor to
|
|
179
|
+
`vaultRecordTypes`, `vaultKeyVersionReader` and `vaultProofAuthorizer`. The accessor follows
|
|
180
|
+
the active store scope; ordinary boolean options are captured when the factory is called.
|
|
181
|
+
This lets store-owned transactions suppress cooperative timers without changing any checks.
|
package/lib/record-types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RecordKey, RecordStoreAdapter, RecordTypeDefinition, SignedRecord, VerifiedRecordOp, VisibilityContext } from '@kokuin/records';
|
|
2
|
-
import type { CryptoOptions, MethodRegistry } from '@kokuin/token';
|
|
2
|
+
import type { CryptoOptions, MethodRegistry, YieldOptions } from '@kokuin/token';
|
|
3
3
|
export type CredentialRecordReadPort = Pick<RecordStoreAdapter, 'get' | 'getMany' | 'list'>;
|
|
4
4
|
export type CredentialAuthorityRequest = {
|
|
5
5
|
source: 'record';
|
|
@@ -30,7 +30,7 @@ export type VaultRecordHooks = {
|
|
|
30
30
|
/** Must resolve ports bound to this adapter's transaction, including routed adapters. */
|
|
31
31
|
portsFor(store: RecordStoreAdapter): VaultRecordPorts;
|
|
32
32
|
};
|
|
33
|
-
export type VaultRecordTypeParams = VaultRecordHooks & CryptoOptions & {
|
|
33
|
+
export type VaultRecordTypeParams = VaultRecordHooks & CryptoOptions & YieldOptions & {
|
|
34
34
|
opKind: string;
|
|
35
35
|
methods?: MethodRegistry;
|
|
36
36
|
};
|
|
@@ -41,7 +41,7 @@ export declare function vaultHolderTypes(types: ReadonlyMap<string, RecordTypeDe
|
|
|
41
41
|
/** Read a live, owner-qualified key version in the explicit replay domain. */
|
|
42
42
|
export type VaultKeyVersionReaderParams = {
|
|
43
43
|
store: RecordStoreAdapter;
|
|
44
|
-
} & Pick<VaultRecordTypeParams, 'opKind' | 'methods' | 'crypto'>;
|
|
44
|
+
} & Pick<VaultRecordTypeParams, 'opKind' | 'methods' | 'crypto' | 'yield'>;
|
|
45
45
|
export declare function vaultKeyVersionReader(input: VaultKeyVersionReaderParams): VisibilityContext['currentKeyVersion'];
|
|
46
46
|
/** Proofs retain consumer authority checks but are never addressed to the local receiver. */
|
|
47
47
|
export type VaultProofAuthorizerParams = {
|
package/lib/record-types.js
CHANGED
|
@@ -161,7 +161,8 @@ async function keyOwnerMatches(params, op, ctx) {
|
|
|
161
161
|
record,
|
|
162
162
|
opKind: params.opKind,
|
|
163
163
|
methods: params.methods,
|
|
164
|
-
crypto: params?.crypto
|
|
164
|
+
crypto: params?.crypto,
|
|
165
|
+
yield: params.yield
|
|
165
166
|
});
|
|
166
167
|
}));
|
|
167
168
|
for (const key of keys){
|
|
@@ -211,7 +212,8 @@ async function authorizeBranch(params, op, ctx) {
|
|
|
211
212
|
opJWT: payload.opJWT,
|
|
212
213
|
opKind: params.opKind,
|
|
213
214
|
methods: params.methods,
|
|
214
|
-
crypto: params?.crypto
|
|
215
|
+
crypto: params?.crypto,
|
|
216
|
+
yield: params.yield
|
|
215
217
|
});
|
|
216
218
|
const key = introducing === null ? null : await vaultRecordMeta({
|
|
217
219
|
...params,
|
|
@@ -255,6 +257,7 @@ async function authorizeBranch(params, op, ctx) {
|
|
|
255
257
|
}));
|
|
256
258
|
}
|
|
257
259
|
function createType(type, params, bindReceiver = true) {
|
|
260
|
+
const capturedParams = params;
|
|
258
261
|
const definition = {
|
|
259
262
|
type,
|
|
260
263
|
policy: type === KEY ? {
|
|
@@ -277,12 +280,17 @@ function createType(type, params, bindReceiver = true) {
|
|
|
277
280
|
precheck: async ({ op })=>await validStructure(type, op, params),
|
|
278
281
|
dependencies: ({ record: _record, op })=>dependencies(type, op),
|
|
279
282
|
async authorize ({ op, ctx }) {
|
|
283
|
+
const params = {
|
|
284
|
+
...capturedParams,
|
|
285
|
+
yield: ctx.yield ?? capturedParams.yield
|
|
286
|
+
};
|
|
280
287
|
// Enforce the factory's replay domain even when the engine is misconfigured.
|
|
281
288
|
const checked = await verifySignedRecord({
|
|
282
289
|
record: ctx.record,
|
|
283
290
|
opKind: params.opKind,
|
|
284
291
|
methods: params.methods,
|
|
285
|
-
crypto: params?.crypto
|
|
292
|
+
crypto: params?.crypto,
|
|
293
|
+
yield: params.yield
|
|
286
294
|
});
|
|
287
295
|
if (checked === null || checked.opHash !== op.opHash) return false;
|
|
288
296
|
if (!await validStructure(type, op, params) || !await recordPayloadMatches({
|
|
@@ -324,12 +332,17 @@ function createType(type, params, bindReceiver = true) {
|
|
|
324
332
|
}));
|
|
325
333
|
},
|
|
326
334
|
async visibleTo ({ record, ctx }) {
|
|
335
|
+
const params = {
|
|
336
|
+
...capturedParams,
|
|
337
|
+
yield: ctx.yield ?? capturedParams.yield
|
|
338
|
+
};
|
|
327
339
|
if (ctx.opKind !== params.opKind) return false;
|
|
328
340
|
const op = await verifySignedRecord({
|
|
329
341
|
record,
|
|
330
342
|
opKind: params.opKind,
|
|
331
343
|
methods: params.methods,
|
|
332
|
-
crypto: params?.crypto
|
|
344
|
+
crypto: params?.crypto,
|
|
345
|
+
yield: params.yield
|
|
333
346
|
});
|
|
334
347
|
if (op === null || !await validStructure(type, op, params) || !await recordPayloadMatches({
|
|
335
348
|
...params,
|
|
@@ -370,7 +383,8 @@ function createType(type, params, bindReceiver = true) {
|
|
|
370
383
|
record,
|
|
371
384
|
opKind: params.opKind,
|
|
372
385
|
methods: params.methods,
|
|
373
|
-
crypto: params?.crypto
|
|
386
|
+
crypto: params?.crypto,
|
|
387
|
+
yield: params.yield
|
|
374
388
|
});
|
|
375
389
|
}));
|
|
376
390
|
for (const op of ops){
|
|
@@ -406,7 +420,8 @@ function createType(type, params, bindReceiver = true) {
|
|
|
406
420
|
record,
|
|
407
421
|
opKind: params.opKind,
|
|
408
422
|
methods: params.methods,
|
|
409
|
-
crypto: params?.crypto
|
|
423
|
+
crypto: params?.crypto,
|
|
424
|
+
yield: params.yield
|
|
410
425
|
});
|
|
411
426
|
if (op === null) throw new Error('Applied record signature is invalid');
|
|
412
427
|
await params.portsFor(store).dropRevokedWrappings({
|
|
@@ -419,6 +434,8 @@ function createType(type, params, bindReceiver = true) {
|
|
|
419
434
|
}
|
|
420
435
|
function captureParams(input) {
|
|
421
436
|
const getter = Object.getOwnPropertyDescriptor(input, 'methods')?.get;
|
|
437
|
+
const yieldGetter = Object.getOwnPropertyDescriptor(input, 'yield')?.get;
|
|
438
|
+
const yieldPolicy = input.yield;
|
|
422
439
|
const methods = input.methods?.map((method)=>{
|
|
423
440
|
return {
|
|
424
441
|
...method,
|
|
@@ -431,6 +448,9 @@ function captureParams(input) {
|
|
|
431
448
|
return {
|
|
432
449
|
...input,
|
|
433
450
|
crypto: input.crypto ?? nobleCrypto,
|
|
451
|
+
get yield () {
|
|
452
|
+
return yieldGetter === undefined ? yieldPolicy : yieldGetter.call(input);
|
|
453
|
+
},
|
|
434
454
|
// Store adapters supply an accessor bound to their current transaction.
|
|
435
455
|
get methods () {
|
|
436
456
|
return getter === undefined ? methods : getter.call(input);
|
|
@@ -468,7 +488,8 @@ export function vaultKeyVersionReader(input) {
|
|
|
468
488
|
record: copy,
|
|
469
489
|
opKind: params.opKind,
|
|
470
490
|
methods: params.methods,
|
|
471
|
-
crypto: params?.crypto
|
|
491
|
+
crypto: params?.crypto,
|
|
492
|
+
yield: params.yield
|
|
472
493
|
});
|
|
473
494
|
const meta = op === null ? null : await vaultRecordMeta({
|
|
474
495
|
...params,
|
|
@@ -488,7 +509,8 @@ export function vaultProofAuthorizer(input) {
|
|
|
488
509
|
record,
|
|
489
510
|
opKind: params.opKind,
|
|
490
511
|
methods: params.methods,
|
|
491
|
-
crypto: params?.crypto
|
|
512
|
+
crypto: params?.crypto,
|
|
513
|
+
yield: params.yield
|
|
492
514
|
});
|
|
493
515
|
if (op === null) return false;
|
|
494
516
|
return await wrapping.authorize({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokuin/vault",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Database-free content keys, ordered factor wrapping and authenticated byte encryption",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vault",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"lib/*"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@kokuin/crypto": "^0.7.
|
|
28
|
-
"@kokuin/jwe": "^0.7.
|
|
29
|
-
"@kokuin/records": "^0.7.
|
|
30
|
-
"@kokuin/token": "^0.7.
|
|
27
|
+
"@kokuin/crypto": "^0.7.1",
|
|
28
|
+
"@kokuin/jwe": "^0.7.1",
|
|
29
|
+
"@kokuin/records": "^0.7.2",
|
|
30
|
+
"@kokuin/token": "^0.7.1",
|
|
31
31
|
"@noble/ciphers": "^2.4.0",
|
|
32
32
|
"@noble/hashes": "^2.4.0",
|
|
33
33
|
"@sozai/codec": "^0.4.4",
|
|
34
|
-
"@sozai/hlc": "^0.1.
|
|
34
|
+
"@sozai/hlc": "^0.1.1",
|
|
35
35
|
"@sozai/json": "^0.3.0",
|
|
36
36
|
"@sozai/runtime": "^0.1.0"
|
|
37
37
|
},
|