@git-stunts/git-cas 5.2.1 → 5.2.4
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/CHANGELOG.md +52 -0
- package/README.md +24 -0
- package/bin/actions.js +24 -7
- package/bin/git-cas.js +78 -30
- package/bin/ui/context.js +13 -0
- package/bin/ui/dashboard-cmds.js +14 -6
- package/bin/ui/dashboard-view.js +55 -6
- package/bin/ui/dashboard.js +109 -7
- package/bin/ui/encryption-card.js +2 -2
- package/bin/ui/heatmap.js +20 -2
- package/bin/ui/history-timeline.js +8 -6
- package/bin/ui/manifest-view.js +37 -8
- package/bin/ui/progress.js +60 -38
- package/index.d.ts +5 -1
- package/index.js +47 -215
- package/package.json +2 -1
- package/src/domain/helpers/buildKdfMetadata.js +18 -0
- package/src/domain/services/CasService.d.ts +1 -1
- package/src/domain/services/CasService.js +38 -213
- package/src/domain/services/KeyResolver.js +220 -0
- package/src/domain/services/Semaphore.js +2 -2
- package/src/domain/services/VaultService.js +49 -27
- package/src/domain/services/rotateVaultPassphrase.js +143 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +38 -6
- package/src/infrastructure/adapters/EventEmitterObserver.js +19 -7
- package/src/infrastructure/adapters/FileIOHelper.js +64 -0
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +21 -5
- package/src/infrastructure/adapters/GitRefAdapter.js +27 -5
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +38 -7
- package/src/infrastructure/adapters/SilentObserver.js +15 -0
- package/src/infrastructure/adapters/StatsCollector.js +15 -1
- package/src/infrastructure/adapters/WebCryptoAdapter.js +68 -18
- package/src/infrastructure/adapters/createCryptoAdapter.js +25 -0
- package/src/infrastructure/chunkers/FixedChunker.js +5 -1
- package/src/infrastructure/chunkers/resolveChunker.js +45 -0
- package/src/infrastructure/codecs/CborCodec.js +11 -3
- package/src/infrastructure/codecs/JsonCodec.js +10 -2
- package/src/ports/CodecPort.js +3 -3
- package/src/ports/CryptoPort.js +56 -23
- package/src/ports/GitPersistencePort.js +4 -4
- package/src/ports/GitRefPort.js +10 -10
- package/src/types/ambient.d.ts +37 -0
package/src/ports/CryptoPort.js
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
import CasError from '../domain/errors/CasError.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Encryption metadata returned by AES-256-GCM operations.
|
|
5
|
+
* @typedef {Object} EncryptionMeta
|
|
6
|
+
* @property {string} algorithm - Cipher algorithm identifier (e.g. `'aes-256-gcm'`).
|
|
7
|
+
* @property {string} nonce - Base64-encoded 12-byte nonce.
|
|
8
|
+
* @property {string} tag - Base64-encoded 16-byte GCM authentication tag.
|
|
9
|
+
* @property {boolean} encrypted - Whether the data is encrypted.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* KDF parameter set stored alongside derived keys.
|
|
14
|
+
* @typedef {Object} KdfParamSet
|
|
15
|
+
* @property {'pbkdf2'|'scrypt'} algorithm - KDF algorithm.
|
|
16
|
+
* @property {string} salt - Base64-encoded salt.
|
|
17
|
+
* @property {number} [iterations] - PBKDF2 iterations (present when algorithm is pbkdf2).
|
|
18
|
+
* @property {number} [cost] - scrypt cost N (present when algorithm is scrypt).
|
|
19
|
+
* @property {number} [blockSize] - scrypt block size r.
|
|
20
|
+
* @property {number} [parallelization] - scrypt parallelization p.
|
|
21
|
+
* @property {number} keyLength - Derived key length in bytes.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Normalized KDF options passed to `_doDeriveKey`.
|
|
26
|
+
* @typedef {Object} DeriveKeyParams
|
|
27
|
+
* @property {string} algorithm - KDF algorithm.
|
|
28
|
+
* @property {number} iterations - PBKDF2 iteration count.
|
|
29
|
+
* @property {number} cost - scrypt cost (N).
|
|
30
|
+
* @property {number} blockSize - scrypt block size (r).
|
|
31
|
+
* @property {number} parallelization - scrypt parallelization (p).
|
|
32
|
+
* @property {number} keyLength - Derived key length in bytes.
|
|
33
|
+
*/
|
|
34
|
+
|
|
3
35
|
/**
|
|
4
36
|
* Abstract port for cryptographic operations (hashing, random bytes, AES-256-GCM).
|
|
5
37
|
* @abstract
|
|
@@ -7,8 +39,8 @@ import CasError from '../domain/errors/CasError.js';
|
|
|
7
39
|
export default class CryptoPort {
|
|
8
40
|
/**
|
|
9
41
|
* Returns the SHA-256 hex digest of a buffer.
|
|
10
|
-
* @param {Buffer}
|
|
11
|
-
* @returns {string} 64-char hex digest
|
|
42
|
+
* @param {Buffer|Uint8Array} _buf - Data to hash.
|
|
43
|
+
* @returns {Promise<string>} 64-char hex digest.
|
|
12
44
|
*/
|
|
13
45
|
sha256(_buf) {
|
|
14
46
|
throw new Error('Not implemented');
|
|
@@ -16,8 +48,8 @@ export default class CryptoPort {
|
|
|
16
48
|
|
|
17
49
|
/**
|
|
18
50
|
* Returns a Buffer of n cryptographically random bytes.
|
|
19
|
-
* @param {number}
|
|
20
|
-
* @returns {Buffer}
|
|
51
|
+
* @param {number} _n - Number of random bytes.
|
|
52
|
+
* @returns {Buffer|Uint8Array}
|
|
21
53
|
*/
|
|
22
54
|
randomBytes(_n) {
|
|
23
55
|
throw new Error('Not implemented');
|
|
@@ -25,9 +57,9 @@ export default class CryptoPort {
|
|
|
25
57
|
|
|
26
58
|
/**
|
|
27
59
|
* Encrypts a buffer using AES-256-GCM.
|
|
28
|
-
* @param {Buffer}
|
|
29
|
-
* @param {Buffer}
|
|
30
|
-
* @returns {{ buf: Buffer, meta: {
|
|
60
|
+
* @param {Buffer|Uint8Array} _buffer - Plaintext to encrypt.
|
|
61
|
+
* @param {Buffer|Uint8Array} _key - 32-byte encryption key.
|
|
62
|
+
* @returns {{ buf: Buffer, meta: EncryptionMeta }|Promise<{ buf: Buffer, meta: EncryptionMeta }>}
|
|
31
63
|
*/
|
|
32
64
|
encryptBuffer(_buffer, _key) {
|
|
33
65
|
throw new Error('Not implemented');
|
|
@@ -35,11 +67,11 @@ export default class CryptoPort {
|
|
|
35
67
|
|
|
36
68
|
/**
|
|
37
69
|
* Decrypts a buffer using AES-256-GCM.
|
|
38
|
-
* @param {Buffer}
|
|
39
|
-
* @param {Buffer}
|
|
40
|
-
* @param {
|
|
41
|
-
* @returns {Buffer}
|
|
42
|
-
* @throws on authentication failure
|
|
70
|
+
* @param {Buffer|Uint8Array} _buffer - Ciphertext to decrypt.
|
|
71
|
+
* @param {Buffer|Uint8Array} _key - 32-byte encryption key.
|
|
72
|
+
* @param {EncryptionMeta} _meta - Encryption metadata from the encrypt operation.
|
|
73
|
+
* @returns {Buffer|Promise<Buffer>}
|
|
74
|
+
* @throws on authentication failure.
|
|
43
75
|
*/
|
|
44
76
|
decryptBuffer(_buffer, _key, _meta) {
|
|
45
77
|
throw new Error('Not implemented');
|
|
@@ -47,8 +79,8 @@ export default class CryptoPort {
|
|
|
47
79
|
|
|
48
80
|
/**
|
|
49
81
|
* Creates a streaming encryption context.
|
|
50
|
-
* @param {Buffer}
|
|
51
|
-
* @returns {{ encrypt: (source: AsyncIterable<Buffer>) => AsyncIterable<Buffer>, finalize: () =>
|
|
82
|
+
* @param {Buffer|Uint8Array} _key - 32-byte encryption key.
|
|
83
|
+
* @returns {{ encrypt: (source: AsyncIterable<Buffer>) => AsyncIterable<Buffer>, finalize: () => EncryptionMeta }}
|
|
52
84
|
*/
|
|
53
85
|
createEncryptionStream(_key) {
|
|
54
86
|
throw new Error('Not implemented');
|
|
@@ -62,14 +94,14 @@ export default class CryptoPort {
|
|
|
62
94
|
*
|
|
63
95
|
* @param {Object} options
|
|
64
96
|
* @param {string} options.passphrase - The passphrase to derive a key from.
|
|
65
|
-
* @param {Buffer} [options.salt] - Salt for the KDF (random if omitted).
|
|
97
|
+
* @param {Buffer|Uint8Array} [options.salt] - Salt for the KDF (random if omitted).
|
|
66
98
|
* @param {'pbkdf2'|'scrypt'} [options.algorithm='pbkdf2'] - KDF algorithm.
|
|
67
99
|
* @param {number} [options.iterations=100000] - PBKDF2 iteration count.
|
|
68
100
|
* @param {number} [options.cost=16384] - scrypt cost parameter (N).
|
|
69
101
|
* @param {number} [options.blockSize=8] - scrypt block size (r).
|
|
70
102
|
* @param {number} [options.parallelization=1] - scrypt parallelization (p).
|
|
71
103
|
* @param {number} [options.keyLength=32] - Derived key length in bytes.
|
|
72
|
-
* @returns {Promise<{ key: Buffer, salt: Buffer, params:
|
|
104
|
+
* @returns {Promise<{ key: Buffer, salt: Buffer, params: KdfParamSet }>}
|
|
73
105
|
*/
|
|
74
106
|
async deriveKey({
|
|
75
107
|
passphrase,
|
|
@@ -83,6 +115,7 @@ export default class CryptoPort {
|
|
|
83
115
|
}) {
|
|
84
116
|
const saltBuf = salt || this.randomBytes(32);
|
|
85
117
|
|
|
118
|
+
/** @type {KdfParamSet} */
|
|
86
119
|
const params = {
|
|
87
120
|
algorithm,
|
|
88
121
|
salt: Buffer.from(saltBuf).toString('base64'),
|
|
@@ -114,9 +147,9 @@ export default class CryptoPort {
|
|
|
114
147
|
/**
|
|
115
148
|
* Adapter-specific key derivation. Override in subclasses.
|
|
116
149
|
* @abstract
|
|
117
|
-
* @param {string} passphrase
|
|
118
|
-
* @param {Buffer|Uint8Array}
|
|
119
|
-
* @param {
|
|
150
|
+
* @param {string} _passphrase - The passphrase.
|
|
151
|
+
* @param {Buffer|Uint8Array} _saltBuf - Salt bytes.
|
|
152
|
+
* @param {DeriveKeyParams} _params - Normalized KDF parameters.
|
|
120
153
|
* @returns {Promise<Buffer|Uint8Array>} Derived key bytes.
|
|
121
154
|
*/
|
|
122
155
|
async _doDeriveKey(_passphrase, _saltBuf, _params) {
|
|
@@ -125,9 +158,9 @@ export default class CryptoPort {
|
|
|
125
158
|
|
|
126
159
|
/**
|
|
127
160
|
* Validates that a key is a 32-byte Buffer or Uint8Array.
|
|
128
|
-
* @param {Buffer|Uint8Array} key
|
|
129
|
-
* @throws {CasError} INVALID_KEY_TYPE if key is not a Buffer or Uint8Array
|
|
130
|
-
* @throws {CasError} INVALID_KEY_LENGTH if key is not 32 bytes
|
|
161
|
+
* @param {Buffer|Uint8Array} key - Key to validate.
|
|
162
|
+
* @throws {CasError} INVALID_KEY_TYPE if key is not a Buffer or Uint8Array.
|
|
163
|
+
* @throws {CasError} INVALID_KEY_LENGTH if key is not 32 bytes.
|
|
131
164
|
*/
|
|
132
165
|
_validateKey(key) {
|
|
133
166
|
if (!globalThis.Buffer?.isBuffer(key) && !(key instanceof Uint8Array)) {
|
|
@@ -149,7 +182,7 @@ export default class CryptoPort {
|
|
|
149
182
|
* Builds the encryption metadata object from base64-encoded nonce and tag.
|
|
150
183
|
* @param {string} nonce64 - Base64-encoded 12-byte AES-GCM nonce.
|
|
151
184
|
* @param {string} tag64 - Base64-encoded 16-byte GCM authentication tag.
|
|
152
|
-
* @returns {
|
|
185
|
+
* @returns {EncryptionMeta}
|
|
153
186
|
*/
|
|
154
187
|
_buildMeta(nonce64, tag64) {
|
|
155
188
|
return {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export default class GitPersistencePort {
|
|
6
6
|
/**
|
|
7
7
|
* Writes content as a Git blob object.
|
|
8
|
-
* @param {Buffer|string}
|
|
8
|
+
* @param {Buffer|string} _content - Data to store.
|
|
9
9
|
* @returns {Promise<string>} The Git OID of the stored blob.
|
|
10
10
|
*/
|
|
11
11
|
async writeBlob(_content) {
|
|
@@ -14,7 +14,7 @@ export default class GitPersistencePort {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Creates a Git tree object from formatted entries.
|
|
17
|
-
* @param {string[]}
|
|
17
|
+
* @param {string[]} _entries - Lines in `git mktree` format.
|
|
18
18
|
* @returns {Promise<string>} The Git OID of the created tree.
|
|
19
19
|
*/
|
|
20
20
|
async writeTree(_entries) {
|
|
@@ -23,7 +23,7 @@ export default class GitPersistencePort {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Reads a Git blob by its OID.
|
|
26
|
-
* @param {string}
|
|
26
|
+
* @param {string} _oid - Git object ID.
|
|
27
27
|
* @returns {Promise<Buffer>} The blob content.
|
|
28
28
|
*/
|
|
29
29
|
async readBlob(_oid) {
|
|
@@ -32,7 +32,7 @@ export default class GitPersistencePort {
|
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Reads and parses a Git tree object.
|
|
35
|
-
* @param {string}
|
|
35
|
+
* @param {string} _treeOid - Git tree OID.
|
|
36
36
|
* @returns {Promise<Array<{ mode: string, type: string, oid: string, name: string }>>} Parsed tree entries.
|
|
37
37
|
*/
|
|
38
38
|
async readTree(_treeOid) {
|
package/src/ports/GitRefPort.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export default class GitRefPort {
|
|
6
6
|
/**
|
|
7
7
|
* Resolves a Git ref to its commit OID.
|
|
8
|
-
* @param {string}
|
|
8
|
+
* @param {string} _ref - Git ref (e.g. 'refs/cas/vault').
|
|
9
9
|
* @returns {Promise<string>} The commit OID.
|
|
10
10
|
* @throws If the ref does not exist.
|
|
11
11
|
*/
|
|
@@ -15,7 +15,7 @@ export default class GitRefPort {
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Resolves the tree OID from a commit OID.
|
|
18
|
-
* @param {string}
|
|
18
|
+
* @param {string} _commitOid - Git commit OID.
|
|
19
19
|
* @returns {Promise<string>} The tree OID.
|
|
20
20
|
*/
|
|
21
21
|
async resolveTree(_commitOid) {
|
|
@@ -24,10 +24,10 @@ export default class GitRefPort {
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Creates a Git commit object.
|
|
27
|
-
* @param {Object}
|
|
28
|
-
* @param {string}
|
|
29
|
-
* @param {string|null} [
|
|
30
|
-
* @param {string}
|
|
27
|
+
* @param {Object} _options
|
|
28
|
+
* @param {string} _options.treeOid - Tree OID for the commit.
|
|
29
|
+
* @param {string|null} [_options.parentOid] - Parent commit OID (null for root commit).
|
|
30
|
+
* @param {string} _options.message - Commit message.
|
|
31
31
|
* @returns {Promise<string>} The new commit OID.
|
|
32
32
|
*/
|
|
33
33
|
async createCommit(_options) {
|
|
@@ -36,10 +36,10 @@ export default class GitRefPort {
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Atomically updates a Git ref with optional CAS (compare-and-swap) semantics.
|
|
39
|
-
* @param {Object}
|
|
40
|
-
* @param {string}
|
|
41
|
-
* @param {string}
|
|
42
|
-
* @param {string|null} [
|
|
39
|
+
* @param {Object} _options
|
|
40
|
+
* @param {string} _options.ref - Git ref to update.
|
|
41
|
+
* @param {string} _options.newOid - New OID to set.
|
|
42
|
+
* @param {string|null} [_options.expectedOldOid] - Expected current OID for CAS.
|
|
43
43
|
* @returns {Promise<void>}
|
|
44
44
|
*/
|
|
45
45
|
async updateRef(_options) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient module declarations for dependencies that lack type definitions.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare module '@git-stunts/plumbing' {
|
|
6
|
+
interface ExecuteOptions {
|
|
7
|
+
args: string[];
|
|
8
|
+
input?: string | Buffer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface StreamResult {
|
|
12
|
+
collect(options?: { asString?: boolean }): Promise<Uint8Array>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ShellRunner {
|
|
16
|
+
run(command: string, args: string[], options?: Record<string, unknown>): Promise<unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class ShellRunnerFactory {
|
|
20
|
+
static create(options?: Record<string, unknown>): ShellRunner;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default class GitPlumbing {
|
|
24
|
+
constructor(options: { runner: ShellRunner; cwd?: string });
|
|
25
|
+
execute(options: ExecuteOptions): Promise<string>;
|
|
26
|
+
executeStream(options: ExecuteOptions): Promise<StreamResult>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare module 'bun' {
|
|
31
|
+
export class CryptoHasher {
|
|
32
|
+
constructor(algorithm: string);
|
|
33
|
+
update(data: Buffer | Uint8Array | string): this;
|
|
34
|
+
digest(encoding: 'hex'): string;
|
|
35
|
+
digest(): Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
}
|