@de-otio/chaoskb-client 0.3.6 → 0.3.7
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/cli/bootstrap.d.ts +11 -3
- package/dist/cli/bootstrap.d.ts.map +1 -1
- package/dist/cli/bootstrap.js +181 -126
- package/dist/cli/bootstrap.js.map +1 -1
- package/dist/cli/commands/config.d.ts +7 -4
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/config.js +161 -134
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/devices.d.ts.map +1 -1
- package/dist/cli/commands/devices.js +58 -33
- package/dist/cli/commands/devices.js.map +1 -1
- package/dist/cli/commands/export.d.ts.map +1 -1
- package/dist/cli/commands/export.js +6 -9
- package/dist/cli/commands/export.js.map +1 -1
- package/dist/cli/commands/import.js +1 -1
- package/dist/cli/commands/import.js.map +1 -1
- package/dist/cli/commands/projects.d.ts.map +1 -1
- package/dist/cli/commands/projects.js +33 -10
- package/dist/cli/commands/projects.js.map +1 -1
- package/dist/cli/commands/rotate-key.d.ts +3 -3
- package/dist/cli/commands/rotate-key.d.ts.map +1 -1
- package/dist/cli/commands/rotate-key.js +88 -35
- package/dist/cli/commands/rotate-key.js.map +1 -1
- package/dist/cli/commands/setup-sync.d.ts.map +1 -1
- package/dist/cli/commands/setup-sync.js +22 -4
- package/dist/cli/commands/setup-sync.js.map +1 -1
- package/dist/cli/mcp-server.d.ts.map +1 -1
- package/dist/cli/mcp-server.js +90 -42
- package/dist/cli/mcp-server.js.map +1 -1
- package/dist/crypto/aad.d.ts +2 -5
- package/dist/crypto/aad.d.ts.map +1 -1
- package/dist/crypto/aad.js +2 -8
- package/dist/crypto/aad.js.map +1 -1
- package/dist/crypto/aead.d.ts +8 -16
- package/dist/crypto/aead.d.ts.map +1 -1
- package/dist/crypto/aead.js +10 -36
- package/dist/crypto/aead.js.map +1 -1
- package/dist/crypto/blob-id.d.ts +2 -3
- package/dist/crypto/blob-id.d.ts.map +1 -1
- package/dist/crypto/blob-id.js +2 -30
- package/dist/crypto/blob-id.js.map +1 -1
- package/dist/crypto/canonical-json.d.ts +5 -3
- package/dist/crypto/canonical-json.d.ts.map +1 -1
- package/dist/crypto/canonical-json.js +5 -85
- package/dist/crypto/canonical-json.js.map +1 -1
- package/dist/crypto/commitment.d.ts +3 -9
- package/dist/crypto/commitment.d.ts.map +1 -1
- package/dist/crypto/commitment.js +3 -27
- package/dist/crypto/commitment.js.map +1 -1
- package/dist/crypto/encryption-service.d.ts +3 -0
- package/dist/crypto/encryption-service.d.ts.map +1 -1
- package/dist/crypto/encryption-service.js +10 -6
- package/dist/crypto/encryption-service.js.map +1 -1
- package/dist/crypto/envelope-cbor.d.ts +4 -34
- package/dist/crypto/envelope-cbor.d.ts.map +1 -1
- package/dist/crypto/envelope-cbor.js +4 -121
- package/dist/crypto/envelope-cbor.js.map +1 -1
- package/dist/crypto/envelope.d.ts +1 -31
- package/dist/crypto/envelope.d.ts.map +1 -1
- package/dist/crypto/envelope.js +31 -137
- package/dist/crypto/envelope.js.map +1 -1
- package/dist/crypto/hkdf.d.ts +7 -11
- package/dist/crypto/hkdf.d.ts.map +1 -1
- package/dist/crypto/hkdf.js +9 -18
- package/dist/crypto/hkdf.js.map +1 -1
- package/dist/crypto/index.d.ts +9 -4
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js +9 -4
- package/dist/crypto/index.js.map +1 -1
- package/dist/crypto/ssh-keys.d.ts +17 -10
- package/dist/crypto/ssh-keys.d.ts.map +1 -1
- package/dist/crypto/ssh-keys.js +28 -108
- package/dist/crypto/ssh-keys.js.map +1 -1
- package/dist/crypto/types.d.ts +18 -88
- package/dist/crypto/types.d.ts.map +1 -1
- package/dist/crypto/types.js +3 -0
- package/dist/crypto/types.js.map +1 -1
- package/dist/pipeline/content-pipeline.d.ts.map +1 -1
- package/dist/pipeline/content-pipeline.js +19 -3
- package/dist/pipeline/content-pipeline.js.map +1 -1
- package/dist/pipeline/extract.d.ts +8 -0
- package/dist/pipeline/extract.d.ts.map +1 -1
- package/dist/pipeline/extract.js +15 -4
- package/dist/pipeline/extract.js.map +1 -1
- package/dist/pipeline/fetch-browser.d.ts +29 -0
- package/dist/pipeline/fetch-browser.d.ts.map +1 -0
- package/dist/pipeline/fetch-browser.js +98 -0
- package/dist/pipeline/fetch-browser.js.map +1 -0
- package/package.json +4 -1
- package/dist/crypto/argon2.d.ts +0 -11
- package/dist/crypto/argon2.d.ts.map +0 -1
- package/dist/crypto/argon2.js +0 -33
- package/dist/crypto/argon2.js.map +0 -1
- package/dist/crypto/invite.d.ts +0 -31
- package/dist/crypto/invite.d.ts.map +0 -1
- package/dist/crypto/invite.js +0 -139
- package/dist/crypto/invite.js.map +0 -1
- package/dist/crypto/keyring.d.ts +0 -37
- package/dist/crypto/keyring.d.ts.map +0 -1
- package/dist/crypto/keyring.js +0 -219
- package/dist/crypto/keyring.js.map +0 -1
- package/dist/crypto/known-keys.d.ts +0 -34
- package/dist/crypto/known-keys.d.ts.map +0 -1
- package/dist/crypto/known-keys.js +0 -114
- package/dist/crypto/known-keys.js.map +0 -1
- package/dist/crypto/project-keys.d.ts +0 -26
- package/dist/crypto/project-keys.d.ts.map +0 -1
- package/dist/crypto/project-keys.js +0 -69
- package/dist/crypto/project-keys.js.map +0 -1
- package/dist/crypto/secure-buffer.d.ts +0 -31
- package/dist/crypto/secure-buffer.d.ts.map +0 -1
- package/dist/crypto/secure-buffer.js +0 -61
- package/dist/crypto/secure-buffer.js.map +0 -1
- package/dist/crypto/tiers/enhanced.d.ts +0 -25
- package/dist/crypto/tiers/enhanced.d.ts.map +0 -1
- package/dist/crypto/tiers/enhanced.js +0 -56
- package/dist/crypto/tiers/enhanced.js.map +0 -1
- package/dist/crypto/tiers/maximum.d.ts +0 -19
- package/dist/crypto/tiers/maximum.d.ts.map +0 -1
- package/dist/crypto/tiers/maximum.js +0 -25
- package/dist/crypto/tiers/maximum.js.map +0 -1
- package/dist/crypto/tiers/standard.d.ts +0 -27
- package/dist/crypto/tiers/standard.d.ts.map +0 -1
- package/dist/crypto/tiers/standard.js +0 -155
- package/dist/crypto/tiers/standard.js.map +0 -1
|
@@ -1,30 +1,6 @@
|
|
|
1
|
-
import * as crypto from 'node:crypto';
|
|
2
|
-
import { hmac } from '@noble/hashes/hmac.js';
|
|
3
|
-
import { sha256 } from '@noble/hashes/sha2.js';
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* where blobIdBytes is the UTF-8 encoding of the blob ID string.
|
|
2
|
+
* Re-export of HMAC-SHA256 key-commitment primitives from
|
|
3
|
+
* `@de-otio/crypto-envelope/primitives`.
|
|
8
4
|
*/
|
|
9
|
-
export
|
|
10
|
-
const blobIdBytes = new TextEncoder().encode(blobId);
|
|
11
|
-
const message = new Uint8Array(blobIdBytes.length + rawCt.length);
|
|
12
|
-
message.set(blobIdBytes, 0);
|
|
13
|
-
message.set(rawCt, blobIdBytes.length);
|
|
14
|
-
return hmac(sha256, commitKey, message);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Verify a key commitment using constant-time comparison.
|
|
18
|
-
* Returns true if the commitment is valid.
|
|
19
|
-
*/
|
|
20
|
-
export function verifyCommitment(commitKey, blobId, rawCt, expected) {
|
|
21
|
-
const computed = computeCommitment(commitKey, blobId, rawCt);
|
|
22
|
-
return constantTimeEqual(computed, expected);
|
|
23
|
-
}
|
|
24
|
-
function constantTimeEqual(a, b) {
|
|
25
|
-
if (a.length !== b.length) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return crypto.timingSafeEqual(a, b);
|
|
29
|
-
}
|
|
5
|
+
export { computeCommitment, verifyCommitment, } from '@de-otio/crypto-envelope/primitives';
|
|
30
6
|
//# sourceMappingURL=commitment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commitment.js","sourceRoot":"","sources":["../../crypto/commitment.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"commitment.js","sourceRoot":"","sources":["../../crypto/commitment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,qCAAqC,CAAC"}
|
|
@@ -3,6 +3,9 @@ import type { DerivedKeySet, DecryptResult, EncryptResult, Envelope, IEncryption
|
|
|
3
3
|
* Concrete implementation of IEncryptionService.
|
|
4
4
|
*
|
|
5
5
|
* Wraps the standalone crypto functions into a single injectable service.
|
|
6
|
+
* Scope: chaoskb's knowledge-base blob pipeline (source/chunk/canary
|
|
7
|
+
* envelopes). Master-key wrapping, passphrase KDF, project keys, and
|
|
8
|
+
* device/invite flows live in `@de-otio/keyring`.
|
|
6
9
|
*/
|
|
7
10
|
export declare class EncryptionService implements IEncryptionService {
|
|
8
11
|
/** Generate a new random 32-byte master key in a SecureBuffer. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption-service.d.ts","sourceRoot":"","sources":["../../crypto/encryption-service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACb,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,KAAK,EACL,OAAO,EACR,MAAM,YAAY,CAAC;AAEpB
|
|
1
|
+
{"version":3,"file":"encryption-service.d.ts","sourceRoot":"","sources":["../../crypto/encryption-service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACb,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,KAAK,EACL,OAAO,EACR,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;IAC1D,kEAAkE;IAClE,iBAAiB,IAAI,aAAa;IASlC,4DAA4D;IAC5D,UAAU,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,aAAa;IAItE,0CAA0C;IAC1C,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,CAAC,EAAE,KAAK,GAAG,aAAa;IAI1E,0CAA0C;IAC1C,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,aAAa,GAAG,aAAa;IAI/D,sDAAsD;IACtD,cAAc,IAAI,MAAM;CAGzB"}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { SecureBuffer } from '@de-otio/crypto-envelope';
|
|
2
3
|
import { generateBlobId } from './blob-id.js';
|
|
3
4
|
import { encryptPayload, decryptEnvelope } from './envelope.js';
|
|
4
5
|
import { deriveKeySet } from './hkdf.js';
|
|
5
|
-
import { SecureBuffer } from './secure-buffer.js';
|
|
6
6
|
/**
|
|
7
7
|
* Concrete implementation of IEncryptionService.
|
|
8
8
|
*
|
|
9
9
|
* Wraps the standalone crypto functions into a single injectable service.
|
|
10
|
+
* Scope: chaoskb's knowledge-base blob pipeline (source/chunk/canary
|
|
11
|
+
* envelopes). Master-key wrapping, passphrase KDF, project keys, and
|
|
12
|
+
* device/invite flows live in `@de-otio/keyring`.
|
|
10
13
|
*/
|
|
11
14
|
export class EncryptionService {
|
|
12
15
|
/** Generate a new random 32-byte master key in a SecureBuffer. */
|
|
13
16
|
generateMasterKey() {
|
|
14
|
-
const sb = SecureBuffer.alloc(32);
|
|
15
17
|
const tmp = randomBytes(32);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
try {
|
|
19
|
+
return SecureBuffer.from(Buffer.from(tmp));
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
tmp.fill(0);
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
25
|
/** Derive all subkeys from a master key via HKDF-SHA256. */
|
|
22
26
|
deriveKeys(masterKey, salt) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption-service.js","sourceRoot":"","sources":["../../crypto/encryption-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"encryption-service.js","sourceRoot":"","sources":["../../crypto/encryption-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAYzC;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAC5B,kEAAkE;IAClE,iBAAiB;QACf,MAAM,GAAG,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC;YACH,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC7C,CAAC;gBAAS,CAAC;YACT,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,CAAC;IACH,CAAC;IAED,4DAA4D;IAC5D,UAAU,CAAC,SAAwB,EAAE,IAAiB;QACpD,OAAO,YAAY,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,0CAA0C;IAC1C,OAAO,CAAC,OAAgB,EAAE,IAAmB,EAAE,GAAW;QACxD,OAAO,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC;IAED,0CAA0C;IAC1C,OAAO,CAAC,QAAkB,EAAE,IAAmB;QAC7C,OAAO,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,sDAAsD;IACtD,cAAc;QACZ,OAAO,cAAc,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -1,37 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CBOR
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* instead of base64, saving ~33% size overhead on the ciphertext field.
|
|
6
|
-
*
|
|
7
|
-
* Backward compatibility: can read both v1 (JSON) and v2 (CBOR) envelopes.
|
|
2
|
+
* chaoskb's CBOR envelope helpers, aliased to the `@de-otio/crypto-envelope`
|
|
3
|
+
* implementations. Preserves the historical chaoskb names
|
|
4
|
+
* (`serializeEnvelopeCBOR`, `deserializeEnvelope`).
|
|
8
5
|
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Serialize an envelope to CBOR binary format (v2).
|
|
12
|
-
*
|
|
13
|
-
* @param envelope - A v2 envelope with raw binary ct and commit.
|
|
14
|
-
* @returns CBOR-encoded bytes.
|
|
15
|
-
*/
|
|
16
|
-
export declare function serializeEnvelopeCBOR(envelope: EnvelopeV2): Uint8Array;
|
|
17
|
-
/**
|
|
18
|
-
* Deserialize bytes into an envelope, auto-detecting the format.
|
|
19
|
-
*
|
|
20
|
-
* - If bytes start with "CKB" magic header, decode as CBOR (v2)
|
|
21
|
-
* - If bytes start with '{', decode as JSON (v1)
|
|
22
|
-
*
|
|
23
|
-
* @param bytes - Raw envelope bytes.
|
|
24
|
-
* @returns Parsed envelope (v1 or v2).
|
|
25
|
-
*/
|
|
26
|
-
export declare function deserializeEnvelope(bytes: Uint8Array): AnyEnvelope;
|
|
27
|
-
/**
|
|
28
|
-
* Convert a v1 (JSON) envelope to a v2 (CBOR) envelope.
|
|
29
|
-
* Decodes base64 fields to raw binary.
|
|
30
|
-
*/
|
|
31
|
-
export declare function upgradeToV2(v1: Envelope): EnvelopeV2;
|
|
32
|
-
/**
|
|
33
|
-
* Convert a v2 (CBOR) envelope back to v1 (JSON) format.
|
|
34
|
-
* Encodes binary fields as base64.
|
|
35
|
-
*/
|
|
36
|
-
export declare function downgradeToV1(v2: EnvelopeV2): Envelope;
|
|
6
|
+
export { serializeV2 as serializeEnvelopeCBOR, deserialize as deserializeEnvelope, upgradeToV2, downgradeToV1, } from '@de-otio/crypto-envelope';
|
|
37
7
|
//# sourceMappingURL=envelope-cbor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope-cbor.d.ts","sourceRoot":"","sources":["../../crypto/envelope-cbor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"envelope-cbor.d.ts","sourceRoot":"","sources":["../../crypto/envelope-cbor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,WAAW,IAAI,qBAAqB,EACpC,WAAW,IAAI,mBAAmB,EAClC,WAAW,EACX,aAAa,GACd,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,124 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CBOR
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* instead of base64, saving ~33% size overhead on the ciphertext field.
|
|
6
|
-
*
|
|
7
|
-
* Backward compatibility: can read both v1 (JSON) and v2 (CBOR) envelopes.
|
|
2
|
+
* chaoskb's CBOR envelope helpers, aliased to the `@de-otio/crypto-envelope`
|
|
3
|
+
* implementations. Preserves the historical chaoskb names
|
|
4
|
+
* (`serializeEnvelopeCBOR`, `deserializeEnvelope`).
|
|
8
5
|
*/
|
|
9
|
-
|
|
10
|
-
/** CBOR tag used to identify ChaosKB envelopes (arbitrary, in private range). */
|
|
11
|
-
const CHAOSKB_CBOR_MAGIC = new Uint8Array([0x43, 0x4b, 0x42]); // "CKB"
|
|
12
|
-
/**
|
|
13
|
-
* Serialize an envelope to CBOR binary format (v2).
|
|
14
|
-
*
|
|
15
|
-
* @param envelope - A v2 envelope with raw binary ct and commit.
|
|
16
|
-
* @returns CBOR-encoded bytes.
|
|
17
|
-
*/
|
|
18
|
-
export function serializeEnvelopeCBOR(envelope) {
|
|
19
|
-
const cborPayload = {
|
|
20
|
-
v: envelope.v,
|
|
21
|
-
id: envelope.id,
|
|
22
|
-
ts: envelope.ts,
|
|
23
|
-
enc: {
|
|
24
|
-
alg: envelope.enc.alg,
|
|
25
|
-
kid: envelope.enc.kid,
|
|
26
|
-
ct: envelope.enc.ct,
|
|
27
|
-
commit: envelope.enc.commit,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
const cborBytes = encode(cborPayload);
|
|
31
|
-
// Prepend magic header so we can distinguish CBOR from JSON
|
|
32
|
-
const result = new Uint8Array(CHAOSKB_CBOR_MAGIC.length + cborBytes.length);
|
|
33
|
-
result.set(CHAOSKB_CBOR_MAGIC, 0);
|
|
34
|
-
result.set(cborBytes, CHAOSKB_CBOR_MAGIC.length);
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Deserialize bytes into an envelope, auto-detecting the format.
|
|
39
|
-
*
|
|
40
|
-
* - If bytes start with "CKB" magic header, decode as CBOR (v2)
|
|
41
|
-
* - If bytes start with '{', decode as JSON (v1)
|
|
42
|
-
*
|
|
43
|
-
* @param bytes - Raw envelope bytes.
|
|
44
|
-
* @returns Parsed envelope (v1 or v2).
|
|
45
|
-
*/
|
|
46
|
-
export function deserializeEnvelope(bytes) {
|
|
47
|
-
// Check for CBOR magic header
|
|
48
|
-
if (bytes.length >= CHAOSKB_CBOR_MAGIC.length &&
|
|
49
|
-
bytes[0] === CHAOSKB_CBOR_MAGIC[0] &&
|
|
50
|
-
bytes[1] === CHAOSKB_CBOR_MAGIC[1] &&
|
|
51
|
-
bytes[2] === CHAOSKB_CBOR_MAGIC[2]) {
|
|
52
|
-
return deserializeCBOR(bytes.subarray(CHAOSKB_CBOR_MAGIC.length));
|
|
53
|
-
}
|
|
54
|
-
// Try JSON (v1)
|
|
55
|
-
return deserializeJSON(bytes);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Decode CBOR bytes into a v2 envelope.
|
|
59
|
-
*/
|
|
60
|
-
function deserializeCBOR(cborBytes) {
|
|
61
|
-
const parsed = decode(cborBytes);
|
|
62
|
-
if (parsed.v !== 2) {
|
|
63
|
-
throw new Error(`CBOR envelope has unexpected version: ${parsed.v}`);
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
v: 2,
|
|
67
|
-
id: parsed.id,
|
|
68
|
-
ts: parsed.ts,
|
|
69
|
-
enc: {
|
|
70
|
-
alg: parsed.enc.alg,
|
|
71
|
-
kid: parsed.enc.kid,
|
|
72
|
-
ct: new Uint8Array(parsed.enc.ct),
|
|
73
|
-
commit: new Uint8Array(parsed.enc.commit),
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Decode JSON bytes into a v1 envelope.
|
|
79
|
-
*/
|
|
80
|
-
function deserializeJSON(bytes) {
|
|
81
|
-
const json = new TextDecoder().decode(bytes);
|
|
82
|
-
const parsed = JSON.parse(json);
|
|
83
|
-
if (parsed.v !== 1) {
|
|
84
|
-
throw new Error(`JSON envelope has unexpected version: ${parsed.v}`);
|
|
85
|
-
}
|
|
86
|
-
return parsed;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Convert a v1 (JSON) envelope to a v2 (CBOR) envelope.
|
|
90
|
-
* Decodes base64 fields to raw binary.
|
|
91
|
-
*/
|
|
92
|
-
export function upgradeToV2(v1) {
|
|
93
|
-
return {
|
|
94
|
-
v: 2,
|
|
95
|
-
id: v1.id,
|
|
96
|
-
ts: v1.ts,
|
|
97
|
-
enc: {
|
|
98
|
-
alg: v1.enc.alg,
|
|
99
|
-
kid: v1.enc.kid,
|
|
100
|
-
ct: new Uint8Array(Buffer.from(v1.enc.ct, 'base64')),
|
|
101
|
-
commit: new Uint8Array(Buffer.from(v1.enc.commit, 'base64')),
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Convert a v2 (CBOR) envelope back to v1 (JSON) format.
|
|
107
|
-
* Encodes binary fields as base64.
|
|
108
|
-
*/
|
|
109
|
-
export function downgradeToV1(v2) {
|
|
110
|
-
const ctBase64 = Buffer.from(v2.enc.ct).toString('base64');
|
|
111
|
-
return {
|
|
112
|
-
v: 1,
|
|
113
|
-
id: v2.id,
|
|
114
|
-
ts: v2.ts,
|
|
115
|
-
enc: {
|
|
116
|
-
alg: v2.enc.alg,
|
|
117
|
-
kid: v2.enc.kid,
|
|
118
|
-
ct: ctBase64,
|
|
119
|
-
'ct.len': v2.enc.ct.length,
|
|
120
|
-
commit: Buffer.from(v2.enc.commit).toString('base64'),
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
6
|
+
export { serializeV2 as serializeEnvelopeCBOR, deserialize as deserializeEnvelope, upgradeToV2, downgradeToV1, } from '@de-otio/crypto-envelope';
|
|
124
7
|
//# sourceMappingURL=envelope-cbor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope-cbor.js","sourceRoot":"","sources":["../../crypto/envelope-cbor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"envelope-cbor.js","sourceRoot":"","sources":["../../crypto/envelope-cbor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,WAAW,IAAI,qBAAqB,EACpC,WAAW,IAAI,mBAAmB,EAClC,WAAW,EACX,aAAa,GACd,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,34 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* Encrypt a payload into an envelope (v1).
|
|
4
|
-
*
|
|
5
|
-
* Steps per the envelope spec:
|
|
6
|
-
* 1. Serialize payload to canonical JSON, convert to UTF-8 bytes
|
|
7
|
-
* 2. Generate blob ID
|
|
8
|
-
* 3. Select key by kid (default CEK)
|
|
9
|
-
* 4. Construct AAD
|
|
10
|
-
* 5. Encrypt with AEAD
|
|
11
|
-
* 6. Concatenate: rawCt = nonce || ciphertext || tag
|
|
12
|
-
* 7. Compute commitment: HMAC-SHA256(commitKey, blobId || rawCt)
|
|
13
|
-
* 8. Verify-after-encrypt: decrypt rawCt, compare with original plaintext
|
|
14
|
-
* 9. Base64-encode ct and commit
|
|
15
|
-
* 10. Assemble Envelope object
|
|
16
|
-
* 11. Return EncryptResult with envelope and serialized JSON bytes
|
|
17
|
-
*/
|
|
1
|
+
import type { DecryptResult, DerivedKeySet, EncryptResult, Envelope, KeyId, Payload } from './types.js';
|
|
18
2
|
export declare function encryptPayload(payload: Payload, keys: DerivedKeySet, kid?: KeyId): EncryptResult;
|
|
19
|
-
/**
|
|
20
|
-
* Decrypt an envelope into a payload.
|
|
21
|
-
*
|
|
22
|
-
* Steps per the envelope spec:
|
|
23
|
-
* 1. Check v == 1
|
|
24
|
-
* 2. Base64-decode ct
|
|
25
|
-
* 3. Verify ct.len matches decoded length
|
|
26
|
-
* 4. Verify key commitment
|
|
27
|
-
* 5. Construct AAD
|
|
28
|
-
* 6. Split rawCt into nonce, ciphertext, tag
|
|
29
|
-
* 7. Decrypt
|
|
30
|
-
* 8. Parse plaintext as JSON, validate type field
|
|
31
|
-
* 9. Return DecryptResult
|
|
32
|
-
*/
|
|
33
3
|
export declare function decryptEnvelope(envelope: Envelope, keys: DerivedKeySet): DecryptResult;
|
|
34
4
|
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../crypto/envelope.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../crypto/envelope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACb,QAAQ,EACR,KAAK,EACL,OAAO,EACR,MAAM,YAAY,CAAC;AA0BpB,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,aAAa,EACnB,GAAG,GAAE,KAAa,GACjB,aAAa,CAUf;AASD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,aAAa,GAAG,aAAa,CAmBtF"}
|
package/dist/crypto/envelope.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { aeadDecrypt, aeadEncrypt } from './aead.js';
|
|
3
|
-
import { constructAAD } from './aad.js';
|
|
4
|
-
import { generateBlobId } from './blob-id.js';
|
|
5
|
-
import { canonicalJson } from './canonical-json.js';
|
|
6
|
-
import { computeCommitment, verifyCommitment } from './commitment.js';
|
|
7
|
-
// Algorithm parameters: nonce size and tag size
|
|
8
|
-
const ALG_PARAMS = {
|
|
9
|
-
'XChaCha20-Poly1305': { nonceSize: 24, tagSize: 16 },
|
|
10
|
-
'AES-256-GCM': { nonceSize: 12, tagSize: 16 },
|
|
11
|
-
};
|
|
1
|
+
import { decryptV1, encryptV1 } from '@de-otio/crypto-envelope';
|
|
12
2
|
/**
|
|
13
|
-
*
|
|
3
|
+
* chaoskb's envelope API, adapted to delegate to `@de-otio/crypto-envelope`.
|
|
4
|
+
*
|
|
5
|
+
* The package takes explicit `cek` and `commitKey` bytes; chaoskb's callers
|
|
6
|
+
* still pass a `DerivedKeySet` and a `KeyId`, so this adapter unpacks the
|
|
7
|
+
* right key by `kid` and validates the chaoskb-specific payload type on
|
|
8
|
+
* decrypt.
|
|
14
9
|
*/
|
|
15
10
|
function getKey(keys, kid) {
|
|
16
11
|
switch (kid) {
|
|
@@ -20,137 +15,36 @@ function getKey(keys, kid) {
|
|
|
20
15
|
return new Uint8Array(keys.metadataKey.buffer);
|
|
21
16
|
case 'EEK':
|
|
22
17
|
return new Uint8Array(keys.embeddingKey.buffer);
|
|
23
|
-
default:
|
|
24
|
-
|
|
18
|
+
default: {
|
|
19
|
+
const _exhaustive = kid;
|
|
20
|
+
throw new Error(`Unknown key identifier: ${_exhaustive}`);
|
|
21
|
+
}
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Encrypt a payload into an envelope (v1).
|
|
29
|
-
*
|
|
30
|
-
* Steps per the envelope spec:
|
|
31
|
-
* 1. Serialize payload to canonical JSON, convert to UTF-8 bytes
|
|
32
|
-
* 2. Generate blob ID
|
|
33
|
-
* 3. Select key by kid (default CEK)
|
|
34
|
-
* 4. Construct AAD
|
|
35
|
-
* 5. Encrypt with AEAD
|
|
36
|
-
* 6. Concatenate: rawCt = nonce || ciphertext || tag
|
|
37
|
-
* 7. Compute commitment: HMAC-SHA256(commitKey, blobId || rawCt)
|
|
38
|
-
* 8. Verify-after-encrypt: decrypt rawCt, compare with original plaintext
|
|
39
|
-
* 9. Base64-encode ct and commit
|
|
40
|
-
* 10. Assemble Envelope object
|
|
41
|
-
* 11. Return EncryptResult with envelope and serialized JSON bytes
|
|
42
|
-
*/
|
|
43
24
|
export function encryptPayload(payload, keys, kid = 'CEK') {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const encKey = getKey(keys, kid);
|
|
52
|
-
// 4. Construct AAD
|
|
53
|
-
const aad = constructAAD(alg, blobId, kid, 1);
|
|
54
|
-
// 5. Encrypt
|
|
55
|
-
const { nonce, ciphertext, tag } = aeadEncrypt(encKey, plaintextBytes, aad);
|
|
56
|
-
// 6. Concatenate: rawCt = nonce || ciphertext || tag
|
|
57
|
-
const rawCt = new Uint8Array(nonce.length + ciphertext.length + tag.length);
|
|
58
|
-
rawCt.set(nonce, 0);
|
|
59
|
-
rawCt.set(ciphertext, nonce.length);
|
|
60
|
-
rawCt.set(tag, nonce.length + ciphertext.length);
|
|
61
|
-
// 7. Compute key commitment
|
|
62
|
-
const commitKey = new Uint8Array(keys.commitKey.buffer);
|
|
63
|
-
const commitment = computeCommitment(commitKey, blobId, rawCt);
|
|
64
|
-
// 8. Verify-after-encrypt: decrypt and compare
|
|
65
|
-
const recovered = aeadDecrypt(encKey, nonce, ciphertext, tag, aad);
|
|
66
|
-
if (!constantTimeEqual(recovered, plaintextBytes)) {
|
|
67
|
-
throw new Error('Verify-after-encrypt failed: decrypted plaintext does not match original');
|
|
68
|
-
}
|
|
69
|
-
// 9. Base64-encode
|
|
70
|
-
const ctBase64 = Buffer.from(rawCt).toString('base64');
|
|
71
|
-
const commitBase64 = Buffer.from(commitment).toString('base64');
|
|
72
|
-
// 10. Assemble envelope
|
|
73
|
-
const envelope = {
|
|
74
|
-
v: 1,
|
|
75
|
-
id: blobId,
|
|
76
|
-
ts: new Date().toISOString(),
|
|
77
|
-
enc: {
|
|
78
|
-
alg,
|
|
79
|
-
kid,
|
|
80
|
-
ct: ctBase64,
|
|
81
|
-
'ct.len': rawCt.length,
|
|
82
|
-
commit: commitBase64,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
// 11. Serialize envelope to bytes
|
|
86
|
-
const envelopeJson = JSON.stringify(envelope);
|
|
87
|
-
const bytes = new TextEncoder().encode(envelopeJson);
|
|
25
|
+
const envelope = encryptV1({
|
|
26
|
+
payload: payload,
|
|
27
|
+
cek: getKey(keys, kid),
|
|
28
|
+
commitKey: new Uint8Array(keys.commitKey.buffer),
|
|
29
|
+
kid,
|
|
30
|
+
});
|
|
31
|
+
const bytes = new TextEncoder().encode(JSON.stringify(envelope));
|
|
88
32
|
return { envelope, bytes };
|
|
89
33
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* Steps per the envelope spec:
|
|
94
|
-
* 1. Check v == 1
|
|
95
|
-
* 2. Base64-decode ct
|
|
96
|
-
* 3. Verify ct.len matches decoded length
|
|
97
|
-
* 4. Verify key commitment
|
|
98
|
-
* 5. Construct AAD
|
|
99
|
-
* 6. Split rawCt into nonce, ciphertext, tag
|
|
100
|
-
* 7. Decrypt
|
|
101
|
-
* 8. Parse plaintext as JSON, validate type field
|
|
102
|
-
* 9. Return DecryptResult
|
|
103
|
-
*/
|
|
104
|
-
export function decryptEnvelope(envelope, keys) {
|
|
105
|
-
// 1. Check version
|
|
106
|
-
if (envelope.v !== 1) {
|
|
107
|
-
throw new Error(`Unsupported envelope version: ${envelope.v}. Please update the app.`);
|
|
108
|
-
}
|
|
109
|
-
const alg = envelope.enc.alg;
|
|
110
|
-
const params = ALG_PARAMS[alg];
|
|
111
|
-
if (!params) {
|
|
112
|
-
throw new Error(`Unsupported algorithm: ${alg}`);
|
|
113
|
-
}
|
|
114
|
-
// 2. Base64-decode ct
|
|
115
|
-
const rawCt = new Uint8Array(Buffer.from(envelope.enc.ct, 'base64'));
|
|
116
|
-
// Verify minimum length
|
|
117
|
-
const minLength = params.nonceSize + params.tagSize + 1;
|
|
118
|
-
if (rawCt.length < minLength) {
|
|
119
|
-
throw new Error(`Truncated ciphertext: expected at least ${minLength} bytes, got ${rawCt.length}`);
|
|
120
|
-
}
|
|
121
|
-
// 3. Verify ct.len
|
|
122
|
-
if (envelope.enc['ct.len'] !== undefined && rawCt.length !== envelope.enc['ct.len']) {
|
|
123
|
-
throw new Error(`Ciphertext length mismatch: ct.len=${envelope.enc['ct.len']}, actual=${rawCt.length}`);
|
|
34
|
+
function toKeyId(kid) {
|
|
35
|
+
if (kid === 'CEK' || kid === 'MEK' || kid === 'EEK') {
|
|
36
|
+
return kid;
|
|
124
37
|
}
|
|
125
|
-
|
|
126
|
-
const commitKey = new Uint8Array(keys.commitKey.buffer);
|
|
127
|
-
const expectedCommit = new Uint8Array(Buffer.from(envelope.enc.commit, 'base64'));
|
|
128
|
-
if (!verifyCommitment(commitKey, envelope.id, rawCt, expectedCommit)) {
|
|
129
|
-
throw new Error('Key commitment verification failed');
|
|
130
|
-
}
|
|
131
|
-
// 5. Construct AAD
|
|
132
|
-
const aad = constructAAD(alg, envelope.id, envelope.enc.kid, envelope.v);
|
|
133
|
-
// 6. Split rawCt into nonce, ciphertext, tag
|
|
134
|
-
const nonce = rawCt.slice(0, params.nonceSize);
|
|
135
|
-
const ciphertext = rawCt.slice(params.nonceSize, rawCt.length - params.tagSize);
|
|
136
|
-
const tag = rawCt.slice(rawCt.length - params.tagSize);
|
|
137
|
-
// 7. Decrypt
|
|
138
|
-
const encKey = getKey(keys, envelope.enc.kid);
|
|
139
|
-
const plaintext = aeadDecrypt(encKey, nonce, ciphertext, tag, aad);
|
|
140
|
-
// 8. Parse plaintext as JSON
|
|
141
|
-
const json = new TextDecoder().decode(plaintext);
|
|
142
|
-
const payload = JSON.parse(json);
|
|
143
|
-
// Validate type field exists
|
|
144
|
-
if (!payload.type || !['source', 'chunk', 'canary'].includes(payload.type)) {
|
|
145
|
-
throw new Error(`Invalid payload type: ${payload.type}`);
|
|
146
|
-
}
|
|
147
|
-
// 9. Return result
|
|
148
|
-
return { payload, envelope };
|
|
38
|
+
throw new Error(`Unknown key identifier: ${kid}`);
|
|
149
39
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
40
|
+
export function decryptEnvelope(envelope, keys) {
|
|
41
|
+
const plaintext = decryptV1(envelope, getKey(keys, toKeyId(envelope.enc.kid)), new Uint8Array(keys.commitKey.buffer));
|
|
42
|
+
// chaoskb-specific payload-type validation — the generic envelope
|
|
43
|
+
// package doesn't know which payload shapes chaoskb considers valid.
|
|
44
|
+
if (!plaintext.type ||
|
|
45
|
+
!['source', 'chunk', 'canary'].includes(plaintext.type)) {
|
|
46
|
+
throw new Error(`Invalid payload type: ${plaintext.type}`);
|
|
47
|
+
}
|
|
48
|
+
return { payload: plaintext, envelope };
|
|
155
49
|
}
|
|
156
50
|
//# sourceMappingURL=envelope.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../crypto/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../crypto/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAUhE;;;;;;;GAOG;AAEH,SAAS,MAAM,CAAC,IAAmB,EAAE,GAAU;IAC7C,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,KAAK;YACR,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAChD,KAAK,KAAK;YACR,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACjD,KAAK,KAAK;YACR,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,WAAW,GAAU,GAAG,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,2BAA2B,WAAW,EAAE,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,IAAmB,EACnB,MAAa,KAAK;IAElB,MAAM,QAAQ,GAAG,SAAS,CAAC;QACzB,OAAO,EAAE,OAA6C;QACtD,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC;QACtB,SAAS,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;QAChD,GAAG;KACJ,CAAa,CAAC;IAEf,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,SAAS,OAAO,CAAC,GAAW;IAC1B,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;QACpD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAkB,EAAE,IAAmB;IACrE,MAAM,SAAS,GAAG,SAAS,CACzB,QAAQ,EACR,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EACvC,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAChB,CAAC;IAExB,kEAAkE;IAClE,qEAAqE;IACrE,IACE,CAAC,SAAS,CAAC,IAAI;QACf,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EACvD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,yBAA0B,SAAgD,CAAC,IAAI,EAAE,CAClF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
|
package/dist/crypto/hkdf.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
+
import { deriveKey } from '@de-otio/crypto-envelope/primitives';
|
|
1
2
|
import type { DerivedKeySet } from './types.js';
|
|
3
|
+
export { deriveKey };
|
|
2
4
|
/**
|
|
3
|
-
* Derive a key
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export declare function deriveKey(ikm: Uint8Array, info: string, salt?: Uint8Array, length?: number): Uint8Array;
|
|
10
|
-
/**
|
|
11
|
-
* Derive the complete set of subkeys from a master key.
|
|
12
|
-
* Returns SecureBuffer-wrapped keys for:
|
|
13
|
-
* CEK (content), MEK (metadata), EEK (embedding), CKY (commit)
|
|
5
|
+
* Derive the four chaoskb subkeys from a master key via HKDF-SHA256.
|
|
6
|
+
*
|
|
7
|
+
* Info strings are chaoskb-specific and MUST NOT change — every encrypted
|
|
8
|
+
* blob on disk was bound to these labels at encrypt time, and changing them
|
|
9
|
+
* would mean no existing envelope could decrypt.
|
|
14
10
|
*/
|
|
15
11
|
export declare function deriveKeySet(masterKey: Uint8Array, salt?: Uint8Array): DerivedKeySet;
|
|
16
12
|
//# sourceMappingURL=hkdf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../crypto/hkdf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../crypto/hkdf.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,aAAa,CAYpF"}
|
package/dist/crypto/hkdf.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { SecureBuffer } from '@de-otio/crypto-envelope';
|
|
2
|
+
import { deriveKey } from '@de-otio/crypto-envelope/primitives';
|
|
3
|
+
// Re-export `deriveKey` so callers that import it from this module keep working.
|
|
4
|
+
export { deriveKey };
|
|
5
5
|
/**
|
|
6
|
-
* Derive a key
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export function deriveKey(ikm, info, salt, length) {
|
|
13
|
-
const infoBytes = new TextEncoder().encode(info);
|
|
14
|
-
return hkdf(sha256, ikm, salt ?? new Uint8Array(0), infoBytes, length ?? DEFAULT_KEY_LENGTH);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Derive the complete set of subkeys from a master key.
|
|
18
|
-
* Returns SecureBuffer-wrapped keys for:
|
|
19
|
-
* CEK (content), MEK (metadata), EEK (embedding), CKY (commit)
|
|
6
|
+
* Derive the four chaoskb subkeys from a master key via HKDF-SHA256.
|
|
7
|
+
*
|
|
8
|
+
* Info strings are chaoskb-specific and MUST NOT change — every encrypted
|
|
9
|
+
* blob on disk was bound to these labels at encrypt time, and changing them
|
|
10
|
+
* would mean no existing envelope could decrypt.
|
|
20
11
|
*/
|
|
21
12
|
export function deriveKeySet(masterKey, salt) {
|
|
22
13
|
const cekBytes = deriveKey(masterKey, 'chaoskb-content', salt);
|
package/dist/crypto/hkdf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../../crypto/hkdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../../crypto/hkdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAIhE,iFAAiF;AACjF,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,SAAqB,EAAE,IAAiB;IACnE,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;IAE9D,OAAO;QACL,UAAU,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpD,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrD,YAAY,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtD,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACpD,CAAC;AACJ,CAAC"}
|
package/dist/crypto/index.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chaoskb crypto module — knowledge-base blob primitives.
|
|
3
|
+
*
|
|
4
|
+
* Key-lifecycle (master-key wrapping, tiers, project keys, invites,
|
|
5
|
+
* TOFU pinning) lives in `@de-otio/keyring`. Pre-existing re-exports
|
|
6
|
+
* of those modules have been removed.
|
|
7
|
+
*/
|
|
1
8
|
export * from './types.js';
|
|
2
|
-
export { SecureBuffer } from '
|
|
9
|
+
export { SecureBuffer } from '@de-otio/crypto-envelope';
|
|
3
10
|
export { canonicalJson } from './canonical-json.js';
|
|
4
11
|
export { generateBlobId } from './blob-id.js';
|
|
5
12
|
export { aeadEncrypt, aeadDecrypt } from './aead.js';
|
|
6
13
|
export { deriveKey, deriveKeySet } from './hkdf.js';
|
|
7
|
-
export { deriveFromPassphrase as argon2Derive } from '
|
|
14
|
+
export { deriveFromPassphrase as argon2Derive } from '@de-otio/crypto-envelope/primitives';
|
|
8
15
|
export { constructAAD } from './aad.js';
|
|
9
16
|
export { computeCommitment, verifyCommitment } from './commitment.js';
|
|
10
17
|
export { encryptPayload, decryptEnvelope } from './envelope.js';
|
|
11
18
|
export { parseSSHPublicKey, ed25519ToX25519PublicKey, ed25519ToX25519SecretKey } from './ssh-keys.js';
|
|
12
19
|
export { EncryptionService } from './encryption-service.js';
|
|
13
|
-
export { KeyringService } from './keyring.js';
|
|
14
|
-
export { createProjectKey, unwrapProjectKey } from './project-keys.js';
|
|
15
20
|
//# sourceMappingURL=index.d.ts.map
|