@korajs/core 1.0.0-beta.0 → 1.0.0-beta.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/dist/bindings/index.d.cts +2 -2
- package/dist/bindings/index.d.ts +2 -2
- package/dist/{build-scope-map-BIeawJzC.d.cts → build-scope-map-DtTr9C7A.d.cts} +1 -1
- package/dist/{build-scope-map-DOf4JLTh.d.ts → build-scope-map-DvOHbYjn.d.ts} +1 -1
- package/dist/{events-BynBOsO3.d.cts → events-CqDkr1LN.d.cts} +101 -2
- package/dist/{events-BynBOsO3.d.ts → events-CqDkr1LN.d.ts} +101 -2
- package/dist/index.cjs +528 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +141 -6
- package/dist/index.d.ts +141 -6
- package/dist/index.js +516 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/{operation-D5WOZYvy.d.ts → operation-BJtu18Fi.d.ts} +1 -1
- package/dist/{operation-BpZlYSpe.d.cts → operation-CFoY-ZmB.d.cts} +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as RandomSource, A as AtomicOpType, a as AtomicOp, F as FieldBuilder,
|
|
2
|
-
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder,
|
|
3
|
-
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-
|
|
4
|
-
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-
|
|
1
|
+
import { R as RandomSource, B as BlobRef, C as CollectionDefinition, A as AtomicOpType, a as AtomicOp, F as FieldBuilder, b as CustomResolver, M as MigrationDefinition, S as SchemaDefinition, c as RelationDefinition, O as OperationType, E as EnumFieldBuilder, J as JsonFieldBuilder, d as ArrayFieldBuilder, e as FieldKind, f as Operation, V as VersionVector, g as MigrationStep, h as StateMachineConstraint, T as TransitionMap, i as TransitionValidationResult } from './events-CqDkr1LN.cjs';
|
|
2
|
+
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder, D as SecretMode, G as SequenceConfig, I as StateMachineDefinition, L as SyncDiagnosticsSnapshot, N as SyncRuleDefinition, P as TimeSource, Q as migrate, U as t } from './events-CqDkr1LN.cjs';
|
|
3
|
+
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-CFoY-ZmB.cjs';
|
|
4
|
+
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-DtTr9C7A.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Base error class for all Kora errors.
|
|
@@ -161,6 +161,137 @@ declare function extractTimestamp(uuid: string): number;
|
|
|
161
161
|
*/
|
|
162
162
|
declare function isValidUUIDv7(uuid: string): boolean;
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Compute the hex-encoded SHA-256 content hash of a byte buffer.
|
|
166
|
+
*
|
|
167
|
+
* This is the content address of a blob: identical bytes always hash to the same
|
|
168
|
+
* value, which is what lets the blob store deduplicate content and lets a peer
|
|
169
|
+
* skip transferring bytes it already holds.
|
|
170
|
+
*
|
|
171
|
+
* @param bytes - The binary content to hash
|
|
172
|
+
* @returns The hex-encoded SHA-256 hash
|
|
173
|
+
*/
|
|
174
|
+
declare function hashBlob(bytes: Uint8Array): Promise<string>;
|
|
175
|
+
/** Optional metadata carried alongside a blob reference. */
|
|
176
|
+
interface BlobRefMetadata {
|
|
177
|
+
mimeType?: string;
|
|
178
|
+
filename?: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a content-addressed {@link BlobRef} for a byte buffer.
|
|
182
|
+
*
|
|
183
|
+
* @param bytes - The binary content
|
|
184
|
+
* @param metadata - Optional MIME type and filename
|
|
185
|
+
* @returns A reference carrying the content hash, size, and metadata
|
|
186
|
+
*/
|
|
187
|
+
declare function createBlobRef(bytes: Uint8Array, metadata?: BlobRefMetadata): Promise<BlobRef>;
|
|
188
|
+
/**
|
|
189
|
+
* Type guard: whether a value is a structurally valid {@link BlobRef}.
|
|
190
|
+
*
|
|
191
|
+
* Validates the shape only (a non-empty hex hash and a non-negative size); it
|
|
192
|
+
* does not verify that the bytes behind the hash exist or match. Integrity
|
|
193
|
+
* verification against the actual bytes happens in the blob store on read.
|
|
194
|
+
*/
|
|
195
|
+
declare function isBlobRef(value: unknown): value is BlobRef;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Field-level cryptography for `secret` fields.
|
|
199
|
+
*
|
|
200
|
+
* Two protection modes, matching the two ways secrets are used:
|
|
201
|
+
* - `encrypted`: reversible AES-256-GCM (tokens, API keys — decrypt to use).
|
|
202
|
+
* - `hashed`: one-way PBKDF2-SHA-256 with a random salt (passwords — verify only).
|
|
203
|
+
*
|
|
204
|
+
* These primitives use only the standard WebCrypto API so they live in
|
|
205
|
+
* `@korajs/core` with no dependency on `@korajs/auth`; a `secret` field is
|
|
206
|
+
* therefore self-contained. Higher-level key management composes on top.
|
|
207
|
+
*/
|
|
208
|
+
/**
|
|
209
|
+
* Encrypt a secret's plaintext with AES-256-GCM under a key derived from
|
|
210
|
+
* `secretKey`. The returned string bundles the salt, IV, and ciphertext (all hex,
|
|
211
|
+
* dot-separated) so it is self-describing and safe to store and sync.
|
|
212
|
+
*
|
|
213
|
+
* @param plaintext - The secret value to protect
|
|
214
|
+
* @param secretKey - The key material (from a key provider), never stored
|
|
215
|
+
* @returns An opaque `v1.salt.iv.ciphertext` string
|
|
216
|
+
*/
|
|
217
|
+
declare function encryptSecret(plaintext: string, secretKey: string): Promise<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Decrypt a value produced by {@link encryptSecret} with the same key.
|
|
220
|
+
*
|
|
221
|
+
* @param encrypted - The `v1.salt.iv.ciphertext` string
|
|
222
|
+
* @param secretKey - The key material used to encrypt
|
|
223
|
+
* @returns The original plaintext
|
|
224
|
+
* @throws If the format is invalid or the key is wrong (GCM auth failure)
|
|
225
|
+
*/
|
|
226
|
+
declare function decryptSecret(encrypted: string, secretKey: string): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* One-way hash a secret (a password) with PBKDF2-SHA-256 and a random salt.
|
|
229
|
+
* The result bundles the salt and hash so {@link verifySecret} needs nothing
|
|
230
|
+
* else. There is no way to recover the plaintext from the result.
|
|
231
|
+
*
|
|
232
|
+
* @param plaintext - The secret value to hash
|
|
233
|
+
* @returns An opaque `v1.salt.hash` string
|
|
234
|
+
*/
|
|
235
|
+
declare function hashSecret(plaintext: string): Promise<string>;
|
|
236
|
+
/**
|
|
237
|
+
* Verify a plaintext against a value produced by {@link hashSecret}, in constant
|
|
238
|
+
* time with respect to the stored hash.
|
|
239
|
+
*
|
|
240
|
+
* @param plaintext - The candidate secret
|
|
241
|
+
* @param stored - The `v1.salt.hash` string
|
|
242
|
+
* @returns Whether the plaintext matches
|
|
243
|
+
*/
|
|
244
|
+
declare function verifySecret(plaintext: string, stored: string): Promise<boolean>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Provider of the key material used to encrypt reversible (`encrypted`) secret
|
|
248
|
+
* fields. Called at write and reveal time so the key can be loaded lazily (for
|
|
249
|
+
* example derived from a user passphrase after unlock). Returns undefined when
|
|
250
|
+
* no key is available.
|
|
251
|
+
*/
|
|
252
|
+
type SecretKeyProvider = () => string | undefined | Promise<string | undefined>;
|
|
253
|
+
/** Thrown when an `encrypted` secret field is written or read without a key. */
|
|
254
|
+
declare class MissingSecretKeyError extends Error {
|
|
255
|
+
readonly field: string;
|
|
256
|
+
constructor(field: string);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Transform the secret fields of a record's write payload into their at-rest
|
|
260
|
+
* form BEFORE the operation is created, so plaintext never enters the operation
|
|
261
|
+
* log, the store, or the sync stream.
|
|
262
|
+
*
|
|
263
|
+
* - `hashed` fields become a one-way salted hash.
|
|
264
|
+
* - `encrypted` fields become ciphertext (requires a key).
|
|
265
|
+
*
|
|
266
|
+
* Non-secret fields, and secret fields not present in `data`, are passed through
|
|
267
|
+
* untouched. Null/undefined secret values are left as-is (nothing to protect).
|
|
268
|
+
*
|
|
269
|
+
* @param data - The validated write payload (plaintext secret values)
|
|
270
|
+
* @param collectionDef - The collection definition (for field kinds/modes)
|
|
271
|
+
* @param keyProvider - Supplies the encryption key for `encrypted` fields
|
|
272
|
+
* @returns A new payload with secret fields replaced by their at-rest form
|
|
273
|
+
*/
|
|
274
|
+
declare function transformSecretFieldsForWrite(data: Record<string, unknown>, collectionDef: CollectionDefinition, keyProvider?: SecretKeyProvider): Promise<Record<string, unknown>>;
|
|
275
|
+
/**
|
|
276
|
+
* Reveal the plaintext of an `encrypted` secret field's stored value. Throws for
|
|
277
|
+
* `hashed` fields, which are one-way and cannot be revealed.
|
|
278
|
+
*
|
|
279
|
+
* @param storedValue - The at-rest value (ciphertext)
|
|
280
|
+
* @param mode - The field's secret mode
|
|
281
|
+
* @param keyProvider - Supplies the decryption key
|
|
282
|
+
* @param field - Field name (for error messages)
|
|
283
|
+
* @returns The decrypted plaintext
|
|
284
|
+
*/
|
|
285
|
+
declare function revealSecret(storedValue: string, mode: 'hashed' | 'encrypted', keyProvider: SecretKeyProvider | undefined, field?: string): Promise<string>;
|
|
286
|
+
/**
|
|
287
|
+
* Verify a plaintext candidate against a `hashed` secret field's stored value.
|
|
288
|
+
*
|
|
289
|
+
* @param candidate - The plaintext to check (for example a login password)
|
|
290
|
+
* @param storedValue - The stored one-way hash
|
|
291
|
+
* @returns Whether the candidate matches
|
|
292
|
+
*/
|
|
293
|
+
declare function verifySecretValue(candidate: string, storedValue: string): Promise<boolean>;
|
|
294
|
+
|
|
164
295
|
/**
|
|
165
296
|
* Outcome of applying a single operation to materialized storage (local or remote).
|
|
166
297
|
*/
|
|
@@ -508,12 +639,16 @@ interface FieldKindToType {
|
|
|
508
639
|
richtext: string;
|
|
509
640
|
enum: string;
|
|
510
641
|
array: unknown[];
|
|
642
|
+
object: Record<string, unknown>;
|
|
643
|
+
json: unknown;
|
|
644
|
+
blob: BlobRef;
|
|
645
|
+
secret: string;
|
|
511
646
|
}
|
|
512
647
|
/**
|
|
513
648
|
* Infers the TypeScript type for a single field descriptor or builder.
|
|
514
649
|
* Supports both FieldBuilder (class instances) and FieldDescriptor (compiled objects).
|
|
515
650
|
*/
|
|
516
|
-
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
651
|
+
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends JsonFieldBuilder<infer T, any, any> ? T : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
517
652
|
kind: 'enum';
|
|
518
653
|
enumValues: infer V;
|
|
519
654
|
} ? V extends readonly (infer S)[] ? S : string : F extends {
|
|
@@ -910,4 +1045,4 @@ interface ProtoOutput {
|
|
|
910
1045
|
*/
|
|
911
1046
|
declare function generateProtoDefinitions(schema: SchemaDefinition): ProtoOutput;
|
|
912
1047
|
|
|
913
|
-
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createReversibleMigration, createVersionVector, decodeBytesFromOpData, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, isApplyFailure, isAtomicOp, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, resolveAtomicOp, rollbackStepsToSQL, serializeVector, toAtomicOp, validateRecord, validateTransition, vectorsEqual };
|
|
1048
|
+
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, BlobRef, type BlobRefMetadata, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, MissingSecretKeyError, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, type SecretKeyProvider, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createBlobRef, createReversibleMigration, createVersionVector, decodeBytesFromOpData, decryptSecret, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, encryptSecret, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, hashBlob, hashSecret, isApplyFailure, isAtomicOp, isBlobRef, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, resolveAtomicOp, revealSecret, rollbackStepsToSQL, serializeVector, toAtomicOp, transformSecretFieldsForWrite, validateRecord, validateTransition, vectorsEqual, verifySecret, verifySecretValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as RandomSource, A as AtomicOpType, a as AtomicOp, F as FieldBuilder,
|
|
2
|
-
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder,
|
|
3
|
-
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-
|
|
4
|
-
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-
|
|
1
|
+
import { R as RandomSource, B as BlobRef, C as CollectionDefinition, A as AtomicOpType, a as AtomicOp, F as FieldBuilder, b as CustomResolver, M as MigrationDefinition, S as SchemaDefinition, c as RelationDefinition, O as OperationType, E as EnumFieldBuilder, J as JsonFieldBuilder, d as ArrayFieldBuilder, e as FieldKind, f as Operation, V as VersionVector, g as MigrationStep, h as StateMachineConstraint, T as TransitionMap, i as TransitionValidationResult } from './events-CqDkr1LN.js';
|
|
2
|
+
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder, D as SecretMode, G as SequenceConfig, I as StateMachineDefinition, L as SyncDiagnosticsSnapshot, N as SyncRuleDefinition, P as TimeSource, Q as migrate, U as t } from './events-CqDkr1LN.js';
|
|
3
|
+
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-BJtu18Fi.js';
|
|
4
|
+
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-DvOHbYjn.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Base error class for all Kora errors.
|
|
@@ -161,6 +161,137 @@ declare function extractTimestamp(uuid: string): number;
|
|
|
161
161
|
*/
|
|
162
162
|
declare function isValidUUIDv7(uuid: string): boolean;
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Compute the hex-encoded SHA-256 content hash of a byte buffer.
|
|
166
|
+
*
|
|
167
|
+
* This is the content address of a blob: identical bytes always hash to the same
|
|
168
|
+
* value, which is what lets the blob store deduplicate content and lets a peer
|
|
169
|
+
* skip transferring bytes it already holds.
|
|
170
|
+
*
|
|
171
|
+
* @param bytes - The binary content to hash
|
|
172
|
+
* @returns The hex-encoded SHA-256 hash
|
|
173
|
+
*/
|
|
174
|
+
declare function hashBlob(bytes: Uint8Array): Promise<string>;
|
|
175
|
+
/** Optional metadata carried alongside a blob reference. */
|
|
176
|
+
interface BlobRefMetadata {
|
|
177
|
+
mimeType?: string;
|
|
178
|
+
filename?: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a content-addressed {@link BlobRef} for a byte buffer.
|
|
182
|
+
*
|
|
183
|
+
* @param bytes - The binary content
|
|
184
|
+
* @param metadata - Optional MIME type and filename
|
|
185
|
+
* @returns A reference carrying the content hash, size, and metadata
|
|
186
|
+
*/
|
|
187
|
+
declare function createBlobRef(bytes: Uint8Array, metadata?: BlobRefMetadata): Promise<BlobRef>;
|
|
188
|
+
/**
|
|
189
|
+
* Type guard: whether a value is a structurally valid {@link BlobRef}.
|
|
190
|
+
*
|
|
191
|
+
* Validates the shape only (a non-empty hex hash and a non-negative size); it
|
|
192
|
+
* does not verify that the bytes behind the hash exist or match. Integrity
|
|
193
|
+
* verification against the actual bytes happens in the blob store on read.
|
|
194
|
+
*/
|
|
195
|
+
declare function isBlobRef(value: unknown): value is BlobRef;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Field-level cryptography for `secret` fields.
|
|
199
|
+
*
|
|
200
|
+
* Two protection modes, matching the two ways secrets are used:
|
|
201
|
+
* - `encrypted`: reversible AES-256-GCM (tokens, API keys — decrypt to use).
|
|
202
|
+
* - `hashed`: one-way PBKDF2-SHA-256 with a random salt (passwords — verify only).
|
|
203
|
+
*
|
|
204
|
+
* These primitives use only the standard WebCrypto API so they live in
|
|
205
|
+
* `@korajs/core` with no dependency on `@korajs/auth`; a `secret` field is
|
|
206
|
+
* therefore self-contained. Higher-level key management composes on top.
|
|
207
|
+
*/
|
|
208
|
+
/**
|
|
209
|
+
* Encrypt a secret's plaintext with AES-256-GCM under a key derived from
|
|
210
|
+
* `secretKey`. The returned string bundles the salt, IV, and ciphertext (all hex,
|
|
211
|
+
* dot-separated) so it is self-describing and safe to store and sync.
|
|
212
|
+
*
|
|
213
|
+
* @param plaintext - The secret value to protect
|
|
214
|
+
* @param secretKey - The key material (from a key provider), never stored
|
|
215
|
+
* @returns An opaque `v1.salt.iv.ciphertext` string
|
|
216
|
+
*/
|
|
217
|
+
declare function encryptSecret(plaintext: string, secretKey: string): Promise<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Decrypt a value produced by {@link encryptSecret} with the same key.
|
|
220
|
+
*
|
|
221
|
+
* @param encrypted - The `v1.salt.iv.ciphertext` string
|
|
222
|
+
* @param secretKey - The key material used to encrypt
|
|
223
|
+
* @returns The original plaintext
|
|
224
|
+
* @throws If the format is invalid or the key is wrong (GCM auth failure)
|
|
225
|
+
*/
|
|
226
|
+
declare function decryptSecret(encrypted: string, secretKey: string): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* One-way hash a secret (a password) with PBKDF2-SHA-256 and a random salt.
|
|
229
|
+
* The result bundles the salt and hash so {@link verifySecret} needs nothing
|
|
230
|
+
* else. There is no way to recover the plaintext from the result.
|
|
231
|
+
*
|
|
232
|
+
* @param plaintext - The secret value to hash
|
|
233
|
+
* @returns An opaque `v1.salt.hash` string
|
|
234
|
+
*/
|
|
235
|
+
declare function hashSecret(plaintext: string): Promise<string>;
|
|
236
|
+
/**
|
|
237
|
+
* Verify a plaintext against a value produced by {@link hashSecret}, in constant
|
|
238
|
+
* time with respect to the stored hash.
|
|
239
|
+
*
|
|
240
|
+
* @param plaintext - The candidate secret
|
|
241
|
+
* @param stored - The `v1.salt.hash` string
|
|
242
|
+
* @returns Whether the plaintext matches
|
|
243
|
+
*/
|
|
244
|
+
declare function verifySecret(plaintext: string, stored: string): Promise<boolean>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Provider of the key material used to encrypt reversible (`encrypted`) secret
|
|
248
|
+
* fields. Called at write and reveal time so the key can be loaded lazily (for
|
|
249
|
+
* example derived from a user passphrase after unlock). Returns undefined when
|
|
250
|
+
* no key is available.
|
|
251
|
+
*/
|
|
252
|
+
type SecretKeyProvider = () => string | undefined | Promise<string | undefined>;
|
|
253
|
+
/** Thrown when an `encrypted` secret field is written or read without a key. */
|
|
254
|
+
declare class MissingSecretKeyError extends Error {
|
|
255
|
+
readonly field: string;
|
|
256
|
+
constructor(field: string);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Transform the secret fields of a record's write payload into their at-rest
|
|
260
|
+
* form BEFORE the operation is created, so plaintext never enters the operation
|
|
261
|
+
* log, the store, or the sync stream.
|
|
262
|
+
*
|
|
263
|
+
* - `hashed` fields become a one-way salted hash.
|
|
264
|
+
* - `encrypted` fields become ciphertext (requires a key).
|
|
265
|
+
*
|
|
266
|
+
* Non-secret fields, and secret fields not present in `data`, are passed through
|
|
267
|
+
* untouched. Null/undefined secret values are left as-is (nothing to protect).
|
|
268
|
+
*
|
|
269
|
+
* @param data - The validated write payload (plaintext secret values)
|
|
270
|
+
* @param collectionDef - The collection definition (for field kinds/modes)
|
|
271
|
+
* @param keyProvider - Supplies the encryption key for `encrypted` fields
|
|
272
|
+
* @returns A new payload with secret fields replaced by their at-rest form
|
|
273
|
+
*/
|
|
274
|
+
declare function transformSecretFieldsForWrite(data: Record<string, unknown>, collectionDef: CollectionDefinition, keyProvider?: SecretKeyProvider): Promise<Record<string, unknown>>;
|
|
275
|
+
/**
|
|
276
|
+
* Reveal the plaintext of an `encrypted` secret field's stored value. Throws for
|
|
277
|
+
* `hashed` fields, which are one-way and cannot be revealed.
|
|
278
|
+
*
|
|
279
|
+
* @param storedValue - The at-rest value (ciphertext)
|
|
280
|
+
* @param mode - The field's secret mode
|
|
281
|
+
* @param keyProvider - Supplies the decryption key
|
|
282
|
+
* @param field - Field name (for error messages)
|
|
283
|
+
* @returns The decrypted plaintext
|
|
284
|
+
*/
|
|
285
|
+
declare function revealSecret(storedValue: string, mode: 'hashed' | 'encrypted', keyProvider: SecretKeyProvider | undefined, field?: string): Promise<string>;
|
|
286
|
+
/**
|
|
287
|
+
* Verify a plaintext candidate against a `hashed` secret field's stored value.
|
|
288
|
+
*
|
|
289
|
+
* @param candidate - The plaintext to check (for example a login password)
|
|
290
|
+
* @param storedValue - The stored one-way hash
|
|
291
|
+
* @returns Whether the candidate matches
|
|
292
|
+
*/
|
|
293
|
+
declare function verifySecretValue(candidate: string, storedValue: string): Promise<boolean>;
|
|
294
|
+
|
|
164
295
|
/**
|
|
165
296
|
* Outcome of applying a single operation to materialized storage (local or remote).
|
|
166
297
|
*/
|
|
@@ -508,12 +639,16 @@ interface FieldKindToType {
|
|
|
508
639
|
richtext: string;
|
|
509
640
|
enum: string;
|
|
510
641
|
array: unknown[];
|
|
642
|
+
object: Record<string, unknown>;
|
|
643
|
+
json: unknown;
|
|
644
|
+
blob: BlobRef;
|
|
645
|
+
secret: string;
|
|
511
646
|
}
|
|
512
647
|
/**
|
|
513
648
|
* Infers the TypeScript type for a single field descriptor or builder.
|
|
514
649
|
* Supports both FieldBuilder (class instances) and FieldDescriptor (compiled objects).
|
|
515
650
|
*/
|
|
516
|
-
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
651
|
+
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends JsonFieldBuilder<infer T, any, any> ? T : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
517
652
|
kind: 'enum';
|
|
518
653
|
enumValues: infer V;
|
|
519
654
|
} ? V extends readonly (infer S)[] ? S : string : F extends {
|
|
@@ -910,4 +1045,4 @@ interface ProtoOutput {
|
|
|
910
1045
|
*/
|
|
911
1046
|
declare function generateProtoDefinitions(schema: SchemaDefinition): ProtoOutput;
|
|
912
1047
|
|
|
913
|
-
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createReversibleMigration, createVersionVector, decodeBytesFromOpData, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, isApplyFailure, isAtomicOp, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, resolveAtomicOp, rollbackStepsToSQL, serializeVector, toAtomicOp, validateRecord, validateTransition, vectorsEqual };
|
|
1048
|
+
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, BlobRef, type BlobRefMetadata, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, MissingSecretKeyError, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, type SecretKeyProvider, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createBlobRef, createReversibleMigration, createVersionVector, decodeBytesFromOpData, decryptSecret, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, encryptSecret, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, hashBlob, hashSecret, isApplyFailure, isAtomicOp, isBlobRef, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, resolveAtomicOp, revealSecret, rollbackStepsToSQL, serializeVector, toAtomicOp, transformSecretFieldsForWrite, validateRecord, validateTransition, vectorsEqual, verifySecret, verifySecretValue };
|