@push.rocks/smartsecret 1.4.0 → 1.6.0

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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@push.rocks/smartsecret",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "private": false,
5
- "description": "OS-backed secret storage plus strict Linux kernel-keyring and envelope APIs for Node.js.",
5
+ "description": "OS-backed secret storage plus strict Linux kernel-keyring, sealed-file, and envelope APIs for Node.js.",
6
6
  "main": "dist_ts/index.js",
7
7
  "typings": "dist_ts/index.d.ts",
8
8
  "type": "module",
@@ -31,9 +31,9 @@
31
31
  "devDependencies": {
32
32
  "@git.zone/tsbuild": "^4.4.2",
33
33
  "@git.zone/tsrun": "^2.0.6",
34
- "@git.zone/tsrust": "^1.7.0",
34
+ "@git.zone/tsrust": "^1.8.0",
35
35
  "@git.zone/tstest": "^4.0.0",
36
- "@types/node": "^26.1.2"
36
+ "@types/node": "^26.2.0"
37
37
  },
38
38
  "files": [
39
39
  "ts/**/*",
@@ -53,8 +53,8 @@
53
53
  ],
54
54
  "dependencies": {
55
55
  "@push.rocks/smartcrypto": "^2.2.0",
56
- "@push.rocks/smartipc": "^2.4.1",
57
- "@push.rocks/smartrust": "^1.6.0"
56
+ "@push.rocks/smartipc": "^2.4.2",
57
+ "@push.rocks/smartrust": "^1.7.0"
58
58
  },
59
59
  "scripts": {
60
60
  "test": "(tstest test/ --verbose)",
package/readme.hints.md CHANGED
@@ -24,7 +24,24 @@
24
24
  - No shell, PATH lookup, environment override, Secret Service, or filesystem secret fallback
25
25
  - Generic values are framed and limited to 0..16384 bytes; service/account names are valid scalar UTF-8 strings of 1..1024 bytes
26
26
  - Persistent-root service rings are revalidated on every operation; process keyring ownership is staging-only
27
+ - Generic entry moves publish and verify the exact framed value at the destination before invalidating the source
27
28
  - Service-wide SmartIPC NamedMutex plus a single monotonic 1..60000 ms deadline bounds cooperating cross-process access
28
29
  - Any post-dispatch mutation ambiguity or worker integrity failure terminates and poisons the store
29
30
  - DevIdP v1 migration is opaque, receipt-bound, keyutils-only, and requires a quiescent legacy writer
30
31
  - Same-UID readability and kernel expiry/reboot behavior are part of the security model
32
+
33
+ ## SmartSecret Sealed File Store
34
+ - Composes a caller-owned SmartSecretKernelStore; it never owns or closes the kernel worker
35
+ - Stores one 32-byte master key per service/store/directory identity in the kernel keyring
36
+ - Stores only strict AES-256-GCM envelopes in a caller-owned private directory
37
+ - A non-secret manifest fingerprints the master key; missing kernel material never creates a replacement silently
38
+ - Explicit reset is destructive and removes only store-owned manifest, entry, and temporary files
39
+ - All identities targeting the same directory share one mutex; reset verifies any manifest identity before deletion
40
+ - Relocation locks both paths in deterministic order, atomically renames on one filesystem, fsyncs both parents, and rebinds the unchanged master key
41
+ - Relocation is idempotent after its own interrupted rename through an inode-bound receipt; arbitrary external moves are rejected
42
+ - Callers must persist an exact-path relocation intent before invocation and retain it after every error because the directory may already be at the destination
43
+ - While an intent or receipt may remain, recovery must retry relocate with the same paths instead of creating or resetting either location
44
+ - Source writers must be quiescent and the retired source must not be initialized again
45
+ - Directory traversal and store I/O are anchored to open descriptors; ancestors, final components, owners, modes, and O_NOFOLLOW are validated
46
+ - A 64-operation admission cap and one 60-second monotonic queue-plus-mutex deadline bound retained operation inputs
47
+ - Filesystem isolation assumes other processes under the same UID are trusted, matching the kernel-keyring boundary
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @push.rocks/smartsecret
2
2
 
3
- OS-backed secret storage plus strict Linux kernel-keyring and envelope APIs for Node.js.
3
+ OS-backed secret storage plus strict Linux kernel-keyring, sealed-file, and envelope APIs for Node.js.
4
4
 
5
5
  ## Issue Reporting and Security
6
6
 
@@ -195,7 +195,7 @@ try {
195
195
 
196
196
  Service and account strings must contain valid Unicode scalar values and encode to 1 through 1,024 UTF-8 bytes. Values may contain 0 through 16,384 bytes. The stored value is framed with a fixed version and exact length before publication. Existing service rings and entries are accepted only when their type, description, owner, and private permissions match the package contract. Kernel per-user quotas may still reject writes before this per-entry limit is reached; the store reports the kernel failure and never falls back to filesystem storage.
197
197
 
198
- `setEntry()` copies its input before dispatch, and `getEntry()` returns a fresh byte array. The caller still owns its input and returned copies and should wipe them when no longer needed. JavaScript and operating-system buffers can retain additional copies, so this remains best-effort zeroization rather than guaranteed memory erasure.
198
+ `setEntry()` copies its input before dispatch, and `getEntry()` returns a fresh byte array. `moveEntry()` moves one exact framed entry to another account under the same service-wide lease: it verifies the destination before invalidating the source, and matching source/destination values converge to the destination. A differing destination rejects with `TARGET_CONFLICT`. When the source is already absent, `alreadyMoved` reports only that a structurally valid destination entry exists; callers that did not observe the original source must independently bind the destination value to their durable state. The caller still owns its input and returned copies and should wipe them when no longer needed. JavaScript and operating-system buffers can retain additional copies, so this remains best-effort zeroization rather than guaranteed memory erasure.
199
199
 
200
200
  The store uses one persistent-user-owned service ring and stages unpublished objects in the process keyring. An inherited session link is preserved and revalidated, but it cannot override or conflict with the persistent root. A revoked inherited session keyring, which can remain after PAM logout, is treated as absent because it is optional and unusable; any failure to establish or validate the required process and persistent roots still fails closed. Publication is verified before staging ownership is removed. Every operation also acquires a service-wide `NamedMutex`, which coordinates cooperating processes running as the same OS identity on the same machine.
201
201
 
@@ -205,6 +205,47 @@ Kernel keyring permissions are an isolation boundary between OS identities, not
205
205
 
206
206
  Operation timeouts default to 5 seconds and may be set from 1 through 60,000 milliseconds. A timeout or abort covers queueing, mutex acquisition, and the worker request under one monotonic deadline. If a mutating request is interrupted after dispatch, or publication/release cannot be confirmed, the store rejects with a `SmartSecretKernelStoreError` whose code is `MUTATION_OUTCOME_UNKNOWN`, terminates the worker, and remains poisoned. Read-side worker integrity failures also poison and terminate the store. Always await `close()`; it waits for already-reserved operations and confirms worker termination.
207
207
 
208
+ ### Sealed file store
209
+
210
+ `SmartSecretSealedFileStore` is a Linux-only API that composes a caller-owned `SmartSecretKernelStore` for data sets that exceed the kernel's per-user key quota. It stores one 32-byte master key in the kernel keyring and one authenticated AES-256-GCM envelope per account in a dedicated private directory supplied by the caller.
211
+
212
+ ```typescript
213
+ import {
214
+ SmartSecretKernelStore,
215
+ SmartSecretSealedFileStore,
216
+ } from '@push.rocks/smartsecret';
217
+
218
+ const kernelStore = await SmartSecretKernelStore.create({
219
+ service: 'example.application',
220
+ });
221
+ try {
222
+ const sealedStore = await SmartSecretSealedFileStore.create({
223
+ kernelStore,
224
+ storeId: 'oauth-credentials',
225
+ directoryPath: '/absolute/private/application/directory/credentials',
226
+ });
227
+ try {
228
+ await sealedStore.setEntry('account-a', new TextEncoder().encode('secret'));
229
+ const value = await sealedStore.getEntry('account-a');
230
+ value?.fill(0);
231
+ } finally {
232
+ await sealedStore.close();
233
+ }
234
+ } finally {
235
+ await kernelStore.close();
236
+ }
237
+ ```
238
+
239
+ The directory is required to be owned by the effective user and mode `0700`; envelope and manifest files are mode `0600`. Every directory component must be owned by root or the effective user and must not be group- or world-writable, except for root-owned sticky directories such as `/tmp`. Directory traversal, creation, and store I/O are anchored to open directory descriptors, and final components use `O_NOFOLLOW`. Writes use random exclusive temporary files, file and directory `fsync`, and atomic replacement. Reads reject unexpected owners or permissions, malformed envelopes, identity mismatches, oversized ciphertext, and authentication failures. The filesystem boundary, like the kernel keyring, trusts other processes running under the same UID.
240
+
241
+ The non-secret manifest binds the directory to the kernel master-key fingerprint. If the kernel key is lost or expires while any manifest, envelope, or temporary artifact remains, `create()` fails with `MASTER_KEY_UNAVAILABLE` and never silently generates a replacement. `SmartSecretSealedFileStore.reset()` is an explicit destructive recovery operation: after verifying any existing manifest belongs to the requested service and store ID, it removes only the store-owned manifest, envelope, and temporary files, removes the old kernel entry if present, and creates a new empty store.
242
+
243
+ `SmartSecretSealedFileStore.relocate()` moves an initialized store to another absolute path on the same filesystem and rebinds the exact master key to the destination path-derived account. It never decrypts or rewrites the manifest or envelopes. Both private parent directories must already exist, while the destination store directory must not exist before the first attempt. The operation locks both paths in deterministic order, writes an inode- and request-bound relocation receipt, atomically renames the directory, fsyncs both parents, moves the kernel entry, removes the receipt, and returns a ready destination store. The receipt allows the same call to resume its own interrupted rename; arbitrary external moves and copied destinations are rejected. A completed call remains idempotent because the destination key is verified against the unchanged manifest.
244
+
245
+ The caller must durably record the exact service, store ID, source path, and destination path before quiescing writers and calling `relocate()`. Preserve that intent after every rejected call: `KERNEL_UNAVAILABLE`, `FILESYSTEM_FAILED`, master-key errors, and `MUTATION_OUTCOME_UNKNOWN` can all be reported after the directory was renamed, so an error code does not establish which path currently exists. Recovery must call `relocate()` again with the same path pair; create a fresh kernel store first when the prior store was poisoned or its worker integrity is uncertain. Do not call `create()` or `reset()` at either path while the intent or relocation receipt may remain, and never initialize a new store at the retired source path. Clear the caller-owned intent only after `relocate()` returns a ready destination store and the application has durably committed the destination as authoritative.
246
+
247
+ Each store instance admits at most 64 operations at once. Each admitted operation has one 60-second monotonic deadline covering the local operation queue and cross-process mutex acquisition. The mutex is directory-wide, so different service or store identities targeting the same directory serialize with each other. Work already running after mutex acquisition is not interrupted by that admission deadline. `close()` rejects new operations, drains admitted operations, and then best-effort wipes the retained master-key copy.
248
+
208
249
  ### DevIdP v1 keyutils migration
209
250
 
210
251
  The two `DevIdP` migration methods are intentionally narrow. They are available only on a store created with service `global.idp.devidp` and accept only accounts matching `v1:[a-f0-9]{64}`:
@@ -282,11 +323,79 @@ SmartSecretKernelStore.create(
282
323
  | `getEntry` | `(account: string, options?) => Promise<Uint8Array \| null>` | Read a copied raw value or return `null` when absent |
283
324
  | `setEntry` | `(account: string, value: Uint8Array, options?) => Promise<void>` | Create or replace one framed entry |
284
325
  | `deleteEntry` | `(account: string, options?) => Promise<boolean>` | Delete an entry and report whether it existed |
326
+ | `moveEntry` | `(sourceAccount: string, destinationAccount: string, options?) => Promise<'moved' \| 'alreadyMoved' \| 'sourceAbsent'>` | Idempotently move one exact framed entry without exposing its value |
285
327
  | `readDevIdpV1Legacy` | `(account: string, options?) => Promise<IDevIdpV1LegacyRead \| null>` | Read one verified, opaque keyutils legacy value |
286
328
  | `deleteDevIdpV1Legacy` | `(receipt, options?) => Promise<'deleted' \| 'alreadyAbsent'>` | Revalidate and consume one legacy receipt |
287
329
  | `close` | `() => Promise<void>` | Wait for reserved operations and confirm worker termination |
288
330
 
289
- Operation options contain optional `timeoutMs` and `signal: AbortSignal` properties. Failures are code-only `SmartSecretKernelStoreError` instances. Stable codes distinguish invalid input, unsupported runtime, unavailable kernel/worker/mutex resources, root conflicts, corrupt entries, changed migration sources, pre-dispatch aborts/timeouts, unknown mutation outcomes, poisoned/closed lifecycle state, and worker integrity failures. Secret values and underlying causes are never retained on these errors.
331
+ Operation options contain optional `timeoutMs` and `signal: AbortSignal` properties. Failures are code-only `SmartSecretKernelStoreError` instances. Stable codes distinguish invalid input, unsupported runtime, unavailable kernel/worker/mutex resources, root conflicts, corrupt entries, changed sources, target conflicts, pre-dispatch aborts/timeouts, unknown mutation outcomes, poisoned/closed lifecycle state, and worker integrity failures. Secret values and underlying causes are never retained on these errors.
332
+
333
+ ### `SmartSecretSealedFileStore`
334
+
335
+ Create a sealed store with a caller-owned kernel store and a dedicated absolute private directory:
336
+
337
+ ```typescript
338
+ SmartSecretSealedFileStore.create(
339
+ options: ISmartSecretSealedFileStoreOptions,
340
+ ): Promise<SmartSecretSealedFileStore>
341
+ ```
342
+
343
+ This API is available only on Linux. `directoryPath` must be an absolute normalized path. The exported options and kernel-store contract are:
344
+
345
+ ```typescript
346
+ interface ISmartSecretSealedFileKernelStore {
347
+ readonly service: string;
348
+ getEntry(
349
+ account: string,
350
+ options?: ISmartSecretKernelOperationOptions,
351
+ ): Promise<Uint8Array | null>;
352
+ setEntry(
353
+ account: string,
354
+ value: Uint8Array,
355
+ options?: ISmartSecretKernelOperationOptions,
356
+ ): Promise<void>;
357
+ deleteEntry(
358
+ account: string,
359
+ options?: ISmartSecretKernelOperationOptions,
360
+ ): Promise<boolean>;
361
+ }
362
+
363
+ interface ISmartSecretSealedFileStoreOptions {
364
+ kernelStore: ISmartSecretSealedFileKernelStore;
365
+ storeId: string;
366
+ directoryPath: string;
367
+ }
368
+
369
+ interface ISmartSecretSealedFileRelocationKernelStore
370
+ extends ISmartSecretSealedFileKernelStore {
371
+ moveEntry(
372
+ sourceAccount: string,
373
+ destinationAccount: string,
374
+ options?: ISmartSecretKernelOperationOptions,
375
+ ): Promise<'moved' | 'alreadyMoved' | 'sourceAbsent'>;
376
+ }
377
+
378
+ interface ISmartSecretSealedFileStoreRelocationOptions {
379
+ kernelStore: ISmartSecretSealedFileRelocationKernelStore;
380
+ storeId: string;
381
+ sourceDirectoryPath: string;
382
+ destinationDirectoryPath: string;
383
+ }
384
+ ```
385
+
386
+ Instances expose readonly `service`, `storeId`, and `directoryPath` properties. The exported `smartSecretSealedFileMaximumEntryBytes` constant is `524288`.
387
+
388
+ | Method | Signature | Description |
389
+ | --- | --- | --- |
390
+ | `create` | `(options) => Promise<SmartSecretSealedFileStore>` | Open or initialize a store without replacing missing key material |
391
+ | `relocate` | `(options) => Promise<SmartSecretSealedFileStore>` | Move one initialized store, rebind its exact master key, and resume completed or interrupted moves |
392
+ | `reset` | `(options) => Promise<SmartSecretSealedFileStore>` | Destructively discard store-owned ciphertext and create a new empty store |
393
+ | `getEntry` | `(account: string) => Promise<Uint8Array \| null>` | Authenticate and decrypt a copied value or return `null` when absent |
394
+ | `setEntry` | `(account: string, value: Uint8Array) => Promise<void>` | Atomically encrypt and replace an entry up to 524,288 bytes |
395
+ | `deleteEntry` | `(account: string) => Promise<boolean>` | Delete an encrypted entry and report whether it existed |
396
+ | `close` | `() => Promise<void>` | Drain admitted operations and best-effort wipe the retained master-key copy |
397
+
398
+ Failures are code-only `SmartSecretSealedFileStoreError` instances. `TSmartSecretSealedFileStoreErrorCode` is the exact union `AUTHENTICATION_FAILED | ENVELOPE_INVALID | FILESYSTEM_FAILED | INVALID_ARGUMENT | KERNEL_UNAVAILABLE | MASTER_KEY_CONFLICT | MASTER_KEY_UNAVAILABLE | MUTATION_OUTCOME_UNKNOWN | MUTEX_FAILED | OPERATION_LIMIT_REACHED | SIZE_LIMIT_EXCEEDED | STORE_CLOSED`. `ISmartSecretSealedFileStoreErrorJson` describes the stable `{ name, code, message }` JSON and inspection shape. The caller retains ownership of the kernel store and must close it separately.
290
399
 
291
400
  ### Types
292
401
 
@@ -351,7 +460,7 @@ Both paths can be influenced by providing a custom `vaultPath` in the constructo
351
460
 
352
461
  ## License and Legal Information
353
462
 
354
- This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.
463
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository [license file](./license).
355
464
 
356
465
  The packaged Linux kernel worker contains statically linked third-party Rust components. Their copyright and license notices are reproduced in [third-party-notices.md](./third-party-notices.md).
357
466
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartsecret',
6
- version: '1.4.0',
7
- description: 'OS-backed secret storage plus strict Linux kernel-keyring and envelope APIs for Node.js.'
6
+ version: '1.6.0',
7
+ description: 'OS-backed secret storage plus strict Linux kernel-keyring, sealed-file, and envelope APIs for Node.js.'
8
8
  }
package/ts/index.ts CHANGED
@@ -19,3 +19,9 @@ export type {
19
19
  ISmartSecretKernelStoreErrorJson,
20
20
  TSmartSecretKernelStoreErrorCode,
21
21
  } from './smartsecret.kernel.error.js';
22
+ export * from './smartsecret.sealedfile.js';
23
+ export { SmartSecretSealedFileStoreError } from './smartsecret.sealedfile.error.js';
24
+ export type {
25
+ ISmartSecretSealedFileStoreErrorJson,
26
+ TSmartSecretSealedFileStoreErrorCode,
27
+ } from './smartsecret.sealedfile.error.js';
@@ -11,6 +11,7 @@ export type TSmartSecretKernelStoreErrorCode =
11
11
  | 'SOURCE_CHANGED'
12
12
  | 'STORE_CLOSED'
13
13
  | 'STORE_POISONED'
14
+ | 'TARGET_CONFLICT'
14
15
  | 'UNSUPPORTED_RUNTIME'
15
16
  | 'WORKER_INTEGRITY_FAILED'
16
17
  | 'WORKER_UNAVAILABLE';
@@ -35,6 +36,7 @@ const errorCodes = new Set<TSmartSecretKernelStoreErrorCode>([
35
36
  'SOURCE_CHANGED',
36
37
  'STORE_CLOSED',
37
38
  'STORE_POISONED',
39
+ 'TARGET_CONFLICT',
38
40
  'UNSUPPORTED_RUNTIME',
39
41
  'WORKER_INTEGRITY_FAILED',
40
42
  'WORKER_UNAVAILABLE',
@@ -32,7 +32,8 @@ export type TSmartSecretKernelDomainErrorCode =
32
32
  | 'KERNEL_UNAVAILABLE'
33
33
  | 'MUTATION_OUTCOME_UNKNOWN'
34
34
  | 'ROOT_CONFLICT'
35
- | 'SOURCE_CHANGED';
35
+ | 'SOURCE_CHANGED'
36
+ | 'TARGET_CONFLICT';
36
37
 
37
38
  export interface ISmartSecretKernelDomainErrorResult {
38
39
  outcome: 'domainError';
@@ -86,6 +87,17 @@ export type TSmartSecretKernelDeleteResult =
86
87
  | ISmartSecretKernelDomainErrorResult
87
88
  | ISmartSecretKernelDeleteSuccess;
88
89
 
90
+ export type TSmartSecretKernelMoveStatus = 'moved' | 'alreadyMoved' | 'sourceAbsent';
91
+
92
+ export interface ISmartSecretKernelMoveSuccess {
93
+ outcome: 'success';
94
+ status: TSmartSecretKernelMoveStatus;
95
+ }
96
+
97
+ export type TSmartSecretKernelMoveResult =
98
+ | ISmartSecretKernelDomainErrorResult
99
+ | ISmartSecretKernelMoveSuccess;
100
+
89
101
  export interface ISmartSecretKernelLegacySuccessAbsent {
90
102
  outcome: 'success';
91
103
  found: false;
@@ -142,6 +154,10 @@ export type TSmartSecretKernelCommands = {
142
154
  params: { description: string };
143
155
  result: TSmartSecretKernelDeleteResult;
144
156
  };
157
+ moveEntry: {
158
+ params: { sourceDescription: string; destinationDescription: string };
159
+ result: TSmartSecretKernelMoveResult;
160
+ };
145
161
  readDevIdpV1Legacy: {
146
162
  params: { account: string };
147
163
  result: TSmartSecretKernelLegacyReadResult;
@@ -159,6 +175,7 @@ const domainErrorCodes: ReadonlySet<string> = new Set([
159
175
  'MUTATION_OUTCOME_UNKNOWN',
160
176
  'ROOT_CONFLICT',
161
177
  'SOURCE_CHANGED',
178
+ 'TARGET_CONFLICT',
162
179
  ]);
163
180
 
164
181
  const isSmartSecretKernelDomainErrorCode = (
@@ -539,6 +556,28 @@ export const parseSmartSecretKernelDeleteResult = (
539
556
  return { kind: 'success', deleted: result.deleted };
540
557
  };
541
558
 
559
+ export const parseSmartSecretKernelMoveResult = (
560
+ valueArg: unknown,
561
+ ):
562
+ | { kind: 'domainError'; domainError: ISmartSecretKernelDomainErrorResult }
563
+ | { kind: 'success'; status: TSmartSecretKernelMoveStatus } => {
564
+ const value = requireResultObject(valueArg);
565
+ const domainError = parseDomainError(value);
566
+ if (domainError) return { kind: 'domainError', domainError };
567
+ const result = requireExactObject(value, ['outcome', 'status'], false);
568
+ if (
569
+ result.outcome !== 'success'
570
+ || (
571
+ result.status !== 'moved'
572
+ && result.status !== 'alreadyMoved'
573
+ && result.status !== 'sourceAbsent'
574
+ )
575
+ ) {
576
+ throw createSmartSecretKernelStoreError('WORKER_INTEGRITY_FAILED');
577
+ }
578
+ return { kind: 'success', status: result.status };
579
+ };
580
+
542
581
  export type TParsedSmartSecretKernelLegacyRead =
543
582
  | { kind: 'domainError'; domainError: ISmartSecretKernelDomainErrorResult }
544
583
  | { kind: 'success'; found: false }
@@ -17,6 +17,7 @@ import {
17
17
  parseSmartSecretKernelGetResult,
18
18
  parseSmartSecretKernelLegacyDeleteResult,
19
19
  parseSmartSecretKernelLegacyReadResult,
20
+ parseSmartSecretKernelMoveResult,
20
21
  parseSmartSecretKernelSetResult,
21
22
  smartSecretKernelDefaultTimeoutMs,
22
23
  smartSecretKernelLegacyService,
@@ -27,12 +28,14 @@ import {
27
28
  type ISmartSecretKernelOperationOptions,
28
29
  type ISmartSecretKernelStoreOptions,
29
30
  type TSmartSecretKernelCommands,
31
+ type TSmartSecretKernelMoveStatus,
30
32
  } from './smartsecret.kernel.protocol.js';
31
33
  import { isSupportedSmartSecretKernelRuntime } from './smartsecret.kernel.runtime.js';
32
34
 
33
35
  export type {
34
36
  ISmartSecretKernelOperationOptions,
35
37
  ISmartSecretKernelStoreOptions,
38
+ TSmartSecretKernelMoveStatus,
36
39
  } from './smartsecret.kernel.protocol.js';
37
40
 
38
41
  const legacyReceiptBrand = Symbol('SmartSecretDevIdpV1LegacyReceipt');
@@ -280,6 +283,38 @@ export class SmartSecretKernelStore {
280
283
  }));
281
284
  }
282
285
 
286
+ public moveEntry(
287
+ sourceAccountArg: string,
288
+ destinationAccountArg: string,
289
+ optionsArg?: ISmartSecretKernelOperationOptions,
290
+ ): Promise<TSmartSecretKernelMoveStatus> {
291
+ const sourceAccount = normalizeSmartSecretKernelAccount(sourceAccountArg);
292
+ const destinationAccount = normalizeSmartSecretKernelAccount(destinationAccountArg);
293
+ if (sourceAccount === destinationAccount) {
294
+ throw createSmartSecretKernelStoreError('INVALID_ARGUMENT');
295
+ }
296
+ const options = normalizeSmartSecretKernelOperationOptions(optionsArg);
297
+ const context = createOperationContext(options, true);
298
+ const sourceDescription = deriveSmartSecretKernelEntryDescription(this.service, sourceAccount);
299
+ const destinationDescription = deriveSmartSecretKernelEntryDescription(
300
+ this.service,
301
+ destinationAccount,
302
+ );
303
+ return this.reserveOperation(context, () => this.withKernelLease(context, async () => {
304
+ const parsed = await this.dispatchMutation(context, async (requestOptionsArg) =>
305
+ parseSmartSecretKernelMoveResult(await this.bridge.sendCommand(
306
+ 'moveEntry',
307
+ { sourceDescription, destinationDescription },
308
+ requestOptionsArg,
309
+ ))
310
+ );
311
+ if (parsed.kind === 'domainError') {
312
+ return this.throwDomainError(parsed.domainError, context);
313
+ }
314
+ return parsed.status;
315
+ }));
316
+ }
317
+
283
318
  public readDevIdpV1Legacy(
284
319
  accountArg: string,
285
320
  optionsArg?: ISmartSecretKernelOperationOptions,
@@ -630,6 +665,9 @@ export class SmartSecretKernelStore {
630
665
  if (domainErrorArg.code === 'SOURCE_CHANGED') {
631
666
  throw createSmartSecretKernelStoreError('SOURCE_CHANGED');
632
667
  }
668
+ if (domainErrorArg.code === 'TARGET_CONFLICT') {
669
+ throw createSmartSecretKernelStoreError('TARGET_CONFLICT');
670
+ }
633
671
  if (
634
672
  domainErrorArg.code === 'MUTATION_OUTCOME_UNKNOWN'
635
673
  && contextArg.mutation
@@ -0,0 +1,72 @@
1
+ export type TSmartSecretSealedFileStoreErrorCode =
2
+ | 'AUTHENTICATION_FAILED'
3
+ | 'ENVELOPE_INVALID'
4
+ | 'FILESYSTEM_FAILED'
5
+ | 'INVALID_ARGUMENT'
6
+ | 'KERNEL_UNAVAILABLE'
7
+ | 'MASTER_KEY_CONFLICT'
8
+ | 'MASTER_KEY_UNAVAILABLE'
9
+ | 'MUTATION_OUTCOME_UNKNOWN'
10
+ | 'MUTEX_FAILED'
11
+ | 'OPERATION_LIMIT_REACHED'
12
+ | 'SIZE_LIMIT_EXCEEDED'
13
+ | 'STORE_CLOSED';
14
+
15
+ export interface ISmartSecretSealedFileStoreErrorJson {
16
+ name: 'SmartSecretSealedFileStoreError';
17
+ code: TSmartSecretSealedFileStoreErrorCode;
18
+ message: string;
19
+ }
20
+
21
+ const inspectSymbol = Symbol.for('nodejs.util.inspect.custom');
22
+ const errorCodes = new Set<TSmartSecretSealedFileStoreErrorCode>([
23
+ 'AUTHENTICATION_FAILED',
24
+ 'ENVELOPE_INVALID',
25
+ 'FILESYSTEM_FAILED',
26
+ 'INVALID_ARGUMENT',
27
+ 'KERNEL_UNAVAILABLE',
28
+ 'MASTER_KEY_CONFLICT',
29
+ 'MASTER_KEY_UNAVAILABLE',
30
+ 'MUTATION_OUTCOME_UNKNOWN',
31
+ 'MUTEX_FAILED',
32
+ 'OPERATION_LIMIT_REACHED',
33
+ 'SIZE_LIMIT_EXCEEDED',
34
+ 'STORE_CLOSED',
35
+ ]);
36
+
37
+ /** A code-only error that intentionally retains no secret values or causes. */
38
+ export class SmartSecretSealedFileStoreError extends Error {
39
+ public readonly code: TSmartSecretSealedFileStoreErrorCode;
40
+ public readonly cause: undefined;
41
+
42
+ constructor(codeArg: TSmartSecretSealedFileStoreErrorCode) {
43
+ const code = errorCodes.has(codeArg) ? codeArg : 'INVALID_ARGUMENT';
44
+ const message = `SmartSecret sealed file store operation failed (${code}).`;
45
+ super(message);
46
+ this.name = 'SmartSecretSealedFileStoreError';
47
+ this.code = code;
48
+ this.stack = `${this.name}: ${message}`;
49
+ Object.defineProperty(this, 'cause', {
50
+ configurable: false,
51
+ enumerable: false,
52
+ value: undefined,
53
+ writable: false,
54
+ });
55
+ }
56
+
57
+ public toJSON(): ISmartSecretSealedFileStoreErrorJson {
58
+ return {
59
+ name: 'SmartSecretSealedFileStoreError',
60
+ code: this.code,
61
+ message: this.message,
62
+ };
63
+ }
64
+
65
+ public [inspectSymbol](): ISmartSecretSealedFileStoreErrorJson {
66
+ return this.toJSON();
67
+ }
68
+ }
69
+
70
+ export const createSmartSecretSealedFileStoreError = (
71
+ codeArg: TSmartSecretSealedFileStoreErrorCode,
72
+ ): SmartSecretSealedFileStoreError => new SmartSecretSealedFileStoreError(codeArg);