@geekmidas/constructs 10.0.0-alpha.45 → 10.0.0-alpha.47
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/adaptors/testing.cjs +1 -1
- package/dist/adaptors/testing.mjs +1 -1
- package/dist/cipher-C1lEFX63.mjs +225 -0
- package/dist/cipher-C1lEFX63.mjs.map +1 -0
- package/dist/cipher-CVxfwLjk.cjs +332 -0
- package/dist/cipher-CVxfwLjk.cjs.map +1 -0
- package/dist/encryption.cjs +96 -0
- package/dist/encryption.cjs.map +1 -0
- package/dist/encryption.d.cts +117 -0
- package/dist/encryption.d.cts.map +1 -0
- package/dist/encryption.d.mts +117 -0
- package/dist/encryption.d.mts.map +1 -0
- package/dist/encryption.mjs +83 -0
- package/dist/encryption.mjs.map +1 -0
- package/dist/kms-B-Hm3d5r.cjs +85 -0
- package/dist/kms-B-Hm3d5r.cjs.map +1 -0
- package/dist/kms-BdUlMJEZ.mjs +85 -0
- package/dist/kms-BdUlMJEZ.mjs.map +1 -0
- package/dist/mobile-app.cjs +3 -0
- package/dist/mobile-app.cjs.map +1 -1
- package/dist/mobile-app.d.cts.map +1 -1
- package/dist/mobile-app.d.mts.map +1 -1
- package/dist/mobile-app.mjs +3 -0
- package/dist/mobile-app.mjs.map +1 -1
- package/package.json +46 -31
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_cipher = require("./cipher-CVxfwLjk.cjs");
|
|
3
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
4
|
+
//#region src/encryption.ts
|
|
5
|
+
/**
|
|
6
|
+
* `Encryption` — a key that encrypts what the application stores.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* export const pii = new Encryption('Pii');
|
|
10
|
+
*
|
|
11
|
+
* // an endpoint that `.dependsOn([pii])`
|
|
12
|
+
* const email = await services.pii.encrypt(body.email);
|
|
13
|
+
* const emailIndex = await services.pii.index(body.email);
|
|
14
|
+
* await db.insertInto('users').values({ email, emailIndex }).execute();
|
|
15
|
+
*
|
|
16
|
+
* // and to find them again, without decrypting a column
|
|
17
|
+
* db.selectFrom('users').where('emailIndex', '=', await services.pii.index(q));
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The app names no cipher and holds no key. The construct provides one URL,
|
|
21
|
+
* `<ID>_URL`, and its scheme picks the backend the way a queue's connection
|
|
22
|
+
* string picks its broker:
|
|
23
|
+
*
|
|
24
|
+
* - **AWS** — `kms://`: envelope encryption under a KMS key that rotates
|
|
25
|
+
* yearly, and a KMS HMAC key for the index. Only a function that depends on
|
|
26
|
+
* the construct is granted either key.
|
|
27
|
+
* - **Server, local, tests** — `aes256gcm://`: a keyring the process holds.
|
|
28
|
+
* Derived locally, so `gkm dev` and `gkm test` need nothing set; generated
|
|
29
|
+
* into a server stage's secrets on its first deploy, and rotated there with
|
|
30
|
+
* `gkm encryption:rotate`.
|
|
31
|
+
*
|
|
32
|
+
* Every ciphertext names the key that wrote it, so a rotated key still opens
|
|
33
|
+
* what it wrote. Retiring one is explicit — `reencrypt` the column, then
|
|
34
|
+
* `gkm encryption:retire` — and a value still under an old key says so when it
|
|
35
|
+
* is decrypted, once per key per process.
|
|
36
|
+
*/
|
|
37
|
+
var Encryption = class {
|
|
38
|
+
id;
|
|
39
|
+
service;
|
|
40
|
+
/**
|
|
41
|
+
* Declared once and read by both `declare()` and `connect()`, so the key the
|
|
42
|
+
* target publishes and the key the client reads cannot drift.
|
|
43
|
+
*/
|
|
44
|
+
key;
|
|
45
|
+
/**
|
|
46
|
+
* One cipher per process, held as the promise: a keyring is parsed once and
|
|
47
|
+
* a KMS client is built once, however many handlers register it at once.
|
|
48
|
+
*/
|
|
49
|
+
cipher;
|
|
50
|
+
constructor(id) {
|
|
51
|
+
const canonical = (0, _geekmidas_manifest.canonicalId)(id);
|
|
52
|
+
this.id = canonical;
|
|
53
|
+
this.key = (0, _geekmidas_manifest.provideKey)(canonical, "url");
|
|
54
|
+
this.service = {
|
|
55
|
+
serviceName: (0, _geekmidas_manifest.serviceKey)(canonical),
|
|
56
|
+
register: (options) => this.connect(options)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
declare() {
|
|
60
|
+
return [{
|
|
61
|
+
kind: "encryption",
|
|
62
|
+
id: this.id,
|
|
63
|
+
provides: [this.key]
|
|
64
|
+
}];
|
|
65
|
+
}
|
|
66
|
+
connect(options) {
|
|
67
|
+
this.cipher ??= this.open(options);
|
|
68
|
+
return this.cipher;
|
|
69
|
+
}
|
|
70
|
+
async open(options) {
|
|
71
|
+
const { url } = options.envParser.create((get) => ({ url: get(this.key).string() })).parse();
|
|
72
|
+
const scheme = url.slice(0, url.indexOf(":") + 1);
|
|
73
|
+
if (scheme === "aes256gcm:") return require_cipher.keyringCipher(this.id, url, (stale, current) => console.warn(`${this.id} decrypted a value still under '${stale}' (current: '${current}'). reencrypt it, and retire '${stale}' once nothing is left under it.`));
|
|
74
|
+
if (scheme === _geekmidas_manifest.KMS_SCHEME) {
|
|
75
|
+
const { kmsCipher } = await Promise.resolve().then(() => require("./kms-B-Hm3d5r.cjs"));
|
|
76
|
+
return kmsCipher(this.id, url);
|
|
77
|
+
}
|
|
78
|
+
throw new require_cipher.UnknownEncryptionScheme(this.id, scheme);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
exports.CiphertextMalformed = require_cipher.CiphertextMalformed;
|
|
83
|
+
exports.CiphertextNotAuthentic = require_cipher.CiphertextNotAuthentic;
|
|
84
|
+
exports.CurrentKeyCannotRetire = require_cipher.CurrentKeyCannotRetire;
|
|
85
|
+
exports.Encryption = Encryption;
|
|
86
|
+
exports.EncryptionKeyRetired = require_cipher.EncryptionKeyRetired;
|
|
87
|
+
exports.EncryptionUrlInvalid = require_cipher.EncryptionUrlInvalid;
|
|
88
|
+
exports.UnknownEncryptionScheme = require_cipher.UnknownEncryptionScheme;
|
|
89
|
+
exports.formatKeyring = require_cipher.formatKeyring;
|
|
90
|
+
exports.generateKeyring = require_cipher.generateKeyring;
|
|
91
|
+
exports.keyringCipher = require_cipher.keyringCipher;
|
|
92
|
+
exports.parseKeyring = require_cipher.parseKeyring;
|
|
93
|
+
exports.retireKey = require_cipher.retireKey;
|
|
94
|
+
exports.rotateKeyring = require_cipher.rotateKeyring;
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=encryption.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.cjs","names":["canonicalId","provideKey","serviceKey","keyringCipher","KMS_SCHEME","UnknownEncryptionScheme"],"sources":["../src/encryption.ts"],"sourcesContent":["/**\n * `Encryption` — a key that encrypts what the application stores.\n *\n * ```ts\n * export const pii = new Encryption('Pii');\n *\n * // an endpoint that `.dependsOn([pii])`\n * const email = await services.pii.encrypt(body.email);\n * const emailIndex = await services.pii.index(body.email);\n * await db.insertInto('users').values({ email, emailIndex }).execute();\n *\n * // and to find them again, without decrypting a column\n * db.selectFrom('users').where('emailIndex', '=', await services.pii.index(q));\n * ```\n *\n * The app names no cipher and holds no key. The construct provides one URL,\n * `<ID>_URL`, and its scheme picks the backend the way a queue's connection\n * string picks its broker:\n *\n * - **AWS** — `kms://`: envelope encryption under a KMS key that rotates\n * yearly, and a KMS HMAC key for the index. Only a function that depends on\n * the construct is granted either key.\n * - **Server, local, tests** — `aes256gcm://`: a keyring the process holds.\n * Derived locally, so `gkm dev` and `gkm test` need nothing set; generated\n * into a server stage's secrets on its first deploy, and rotated there with\n * `gkm encryption:rotate`.\n *\n * Every ciphertext names the key that wrote it, so a rotated key still opens\n * what it wrote. Retiring one is explicit — `reencrypt` the column, then\n * `gkm encryption:retire` — and a value still under an old key says so when it\n * is decrypted, once per key per process.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tKMS_SCHEME,\n\tprovideKey,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { Construct } from './construct-interface';\nimport {\n\ttype Cipher,\n\tkeyringCipher,\n\tLOCAL_SCHEME,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nexport type { Cipher } from './encryption/cipher';\nexport {\n\tCiphertextMalformed,\n\tCiphertextNotAuthentic,\n\tCurrentKeyCannotRetire,\n\tEncryptionKeyRetired,\n\tEncryptionUrlInvalid,\n\tformatKeyring,\n\tgenerateKeyring,\n\ttype Keyring,\n\tkeyringCipher,\n\tparseKeyring,\n\tretireKey,\n\trotateKeyring,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nexport class Encryption<TName extends string = string>\n\timplements Construct<TName, Cipher>\n{\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, Cipher>;\n\n\t/**\n\t * Declared once and read by both `declare()` and `connect()`, so the key the\n\t * target publishes and the key the client reads cannot drift.\n\t */\n\tprivate readonly key: string;\n\n\t/**\n\t * One cipher per process, held as the promise: a keyring is parsed once and\n\t * a KMS client is built once, however many handlers register it at once.\n\t */\n\tprivate cipher?: Promise<Cipher>;\n\n\tconstructor(id: ConstructName<TName>) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.key = provideKey(canonical, 'url');\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (options) => this.connect(options),\n\t\t};\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [{ kind: 'encryption', id: this.id, provides: [this.key] }];\n\t}\n\n\tprivate connect(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tthis.cipher ??= this.open(options);\n\t\treturn this.cipher;\n\t}\n\n\tprivate async open(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tconst { url } = options.envParser\n\t\t\t.create((get) => ({ url: get(this.key).string() }))\n\t\t\t.parse();\n\t\tconst scheme = url.slice(0, url.indexOf(':') + 1);\n\n\t\tif (scheme === LOCAL_SCHEME) {\n\t\t\treturn keyringCipher(this.id, url, (stale, current) =>\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${this.id} decrypted a value still under '${stale}' (current: '${current}'). reencrypt it, and retire '${stale}' once nothing is left under it.`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tif (scheme === KMS_SCHEME) {\n\t\t\t// Loaded only here, so a project that never deploys to AWS never\n\t\t\t// needs `@aws-sdk/client-kms` installed.\n\t\t\tconst { kmsCipher } = await import('./encryption/kms');\n\t\t\treturn kmsCipher(this.id, url);\n\t\t}\n\n\t\tthrow new UnknownEncryptionScheme(this.id, scheme);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,IAAa,aAAb,MAEA;CACC;CACA;;;;;CAMA;;;;;CAMA;CAEA,YAAY,IAA0B;EACrC,MAAM,aAAA,GAAYA,oBAAAA,YAAAA,CAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,OAAA,GAAMC,oBAAAA,WAAAA,CAAW,WAAW,KAAK;EAGtC,KAAK,UAAU;GACd,cAAA,GAAaC,oBAAAA,WAAAA,CAAW,SAAS;GACjC,WAAW,YAAY,KAAK,QAAQ,OAAO;EAC5C;CACD;CAEA,UAAyB;EACxB,OAAO,CAAC;GAAE,MAAM;GAAc,IAAI,KAAK;GAAI,UAAU,CAAC,KAAK,GAAG;EAAE,CAAC;CAClE;CAEA,QAAgB,SAAkD;EACjE,KAAK,WAAW,KAAK,KAAK,OAAO;EACjC,OAAO,KAAK;CACb;CAEA,MAAc,KAAK,SAAkD;EACpE,MAAM,EAAE,QAAQ,QAAQ,UACtB,QAAQ,SAAS,EAAE,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAClD,MAAM;EACR,MAAM,SAAS,IAAI,MAAM,GAAG,IAAI,QAAQ,GAAG,IAAI,CAAC;EAEhD,IAAI,WAAA,cACH,OAAOC,eAAAA,cAAc,KAAK,IAAI,MAAM,OAAO,YAC1C,QAAQ,KACP,GAAG,KAAK,GAAG,kCAAkC,MAAM,eAAe,QAAQ,gCAAgC,MAAM,iCACjH,CACD;EAGD,IAAI,WAAWC,oBAAAA,YAAY;GAG1B,MAAM,EAAE,cAAc,MAAA,QAAA,QAAA,CAAA,CAAA,WAAA,QAAM,oBAAA,CAAA;GAC5B,OAAO,UAAU,KAAK,IAAI,GAAG;EAC9B;EAEA,MAAM,IAAIC,eAAAA,wBAAwB,KAAK,IAAI,MAAM;CAClD;AACD"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { n as Construct } from "./construct-interface-B1AfqRl4.cjs";
|
|
2
|
+
import { Service } from "@geekmidas/services";
|
|
3
|
+
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
4
|
+
//#region src/encryption/cipher.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The cipher behind an `Encryption` construct, and the format it writes.
|
|
7
|
+
*
|
|
8
|
+
* Every ciphertext names the key that wrote it — `gkm1.<keyId>.<payload>` — so
|
|
9
|
+
* `decrypt` never has to guess, a rotated key still opens what it wrote, and
|
|
10
|
+
* retiring a key is a decision made against data rather than a hope. The
|
|
11
|
+
* format version leads, so the day it has to change, both can be read.
|
|
12
|
+
*
|
|
13
|
+
* Two backends, picked by the scheme of the construct's URL, the way a queue's
|
|
14
|
+
* connection string picks its broker:
|
|
15
|
+
*
|
|
16
|
+
* - `aes256gcm://` — a keyring this process holds: AES-256-GCM with the newest
|
|
17
|
+
* key, HMAC-SHA256 for the blind index. Local, test and server stages.
|
|
18
|
+
* - `kms://` — envelope encryption under an AWS KMS key, and a KMS HMAC key for
|
|
19
|
+
* the index. The key material never leaves KMS. See `./kms`.
|
|
20
|
+
*/
|
|
21
|
+
/** What a handler is given: `services.pii.encrypt(…)` and the rest. */
|
|
22
|
+
interface Cipher {
|
|
23
|
+
/** Plaintext in, a self-describing ciphertext string out. */
|
|
24
|
+
encrypt(plaintext: string): Promise<string>;
|
|
25
|
+
/** Opens any ciphertext this construct wrote, under whichever key wrote it. */
|
|
26
|
+
decrypt(ciphertext: string): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* A blind index: the same value always gives the same string, so an
|
|
29
|
+
* encrypted column can still be looked up by an indexed column beside it.
|
|
30
|
+
*
|
|
31
|
+
* Deterministic on purpose, which is also why its key never rotates — a
|
|
32
|
+
* rotated index key would make every stored index miss.
|
|
33
|
+
*/
|
|
34
|
+
index(value: string): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* The same plaintext under the current key — what a sweep runs over a
|
|
37
|
+
* column before an old key is retired. Unchanged when it is already current.
|
|
38
|
+
*/
|
|
39
|
+
reencrypt(ciphertext: string): Promise<string>;
|
|
40
|
+
}
|
|
41
|
+
export declare class EncryptionUrlInvalid extends Error {
|
|
42
|
+
readonly construct: string;
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
constructor(construct: string, reason: string);
|
|
45
|
+
}
|
|
46
|
+
export declare class UnknownEncryptionScheme extends Error {
|
|
47
|
+
readonly construct: string;
|
|
48
|
+
readonly scheme: string;
|
|
49
|
+
constructor(construct: string, scheme: string);
|
|
50
|
+
}
|
|
51
|
+
export declare class CiphertextMalformed extends Error {
|
|
52
|
+
readonly construct: string;
|
|
53
|
+
constructor(construct: string);
|
|
54
|
+
}
|
|
55
|
+
export declare class EncryptionKeyRetired extends Error {
|
|
56
|
+
readonly construct: string;
|
|
57
|
+
readonly keyId: string;
|
|
58
|
+
constructor(construct: string, keyId: string);
|
|
59
|
+
}
|
|
60
|
+
export declare class CiphertextNotAuthentic extends Error {
|
|
61
|
+
readonly construct: string;
|
|
62
|
+
constructor(construct: string);
|
|
63
|
+
}
|
|
64
|
+
export declare class CurrentKeyCannotRetire extends Error {
|
|
65
|
+
readonly construct: string;
|
|
66
|
+
readonly keyId: string;
|
|
67
|
+
constructor(construct: string, keyId: string);
|
|
68
|
+
}
|
|
69
|
+
/** A local keyring: newest key first, and the index key that never rotates. */
|
|
70
|
+
interface Keyring {
|
|
71
|
+
keys: {
|
|
72
|
+
id: string;
|
|
73
|
+
key: Buffer;
|
|
74
|
+
}[];
|
|
75
|
+
index: Buffer;
|
|
76
|
+
}
|
|
77
|
+
/** Parse `aes256gcm://local?keys=k2.<key>,k1.<key>&index=<key>`. */
|
|
78
|
+
export declare function parseKeyring(construct: string, url: string): Keyring;
|
|
79
|
+
export declare function formatKeyring(keyring: Keyring): string;
|
|
80
|
+
/** A keyring with one fresh key, `k1`, and a fresh index key. */
|
|
81
|
+
export declare function generateKeyring(): string;
|
|
82
|
+
/**
|
|
83
|
+
* The keyring with a new current key in front, and every older one kept.
|
|
84
|
+
*
|
|
85
|
+
* Nothing is dropped: what the old keys wrote still has to open until a sweep
|
|
86
|
+
* has re-encrypted it — see {@link retireKey}.
|
|
87
|
+
*/
|
|
88
|
+
export declare function rotateKeyring(construct: string, url: string): string;
|
|
89
|
+
/** The keyring without `keyId`, which must not be the current key. */
|
|
90
|
+
export declare function retireKey(construct: string, url: string, keyId: string): string;
|
|
91
|
+
/** Says, once per key per process, that a value is still under an old key. */
|
|
92
|
+
type StaleKeyReporter = (keyId: string, current: string) => void;
|
|
93
|
+
/** The `aes256gcm://` cipher: a keyring held in process. */
|
|
94
|
+
export declare function keyringCipher(construct: string, url: string, onStaleKey?: StaleKeyReporter): Cipher;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/encryption.d.ts
|
|
97
|
+
export declare class Encryption<TName extends string = string> implements Construct<TName, Cipher> {
|
|
98
|
+
readonly id: TName;
|
|
99
|
+
readonly service: Service<Uncapitalize<TName>, Cipher>;
|
|
100
|
+
/**
|
|
101
|
+
* Declared once and read by both `declare()` and `connect()`, so the key the
|
|
102
|
+
* target publishes and the key the client reads cannot drift.
|
|
103
|
+
*/
|
|
104
|
+
private readonly key;
|
|
105
|
+
/**
|
|
106
|
+
* One cipher per process, held as the promise: a keyring is parsed once and
|
|
107
|
+
* a KMS client is built once, however many handlers register it at once.
|
|
108
|
+
*/
|
|
109
|
+
private cipher?;
|
|
110
|
+
constructor(id: ConstructName<TName>);
|
|
111
|
+
declare(): Declaration[];
|
|
112
|
+
private connect;
|
|
113
|
+
private open;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export type { Cipher, Keyring };
|
|
117
|
+
//# sourceMappingURL=encryption.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.cts","names":[],"sources":["../src/encryption/cipher.ts","../src/encryption.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;UAyBiB;;EAEhB,QAAQ,oBAAoB;;EAE5B,QAAQ,qBAAqB;;;;;;;;EAQ7B,MAAM,gBAAgB;;;;;EAKtB,UAAU,qBAAqB;;qBAanB,6BAA6B;WAE/B;WACA;EAFV,YACU,mBACA;;qBASE,gCAAgC;WAElC;WACA;EAFV,YACU,mBACA;;qBASE,4BAA4B;WACnB;EAArB,YAAqB;;qBAQT,6BAA6B;WAE/B;WACA;EAFV,YACU,mBACA;;qBASE,+BAA+B;WACtB;EAArB,YAAqB;;qBAQT,+BAA+B;WAEjC;WACA;EAFV,YACU,mBACA;;;UAuEM;EAChB;IAAQ;IAAY,KAAK;;EACzB,OAAO;;;wBAIQ,aAAa,mBAAmB,cAAc;wBAqC9C,cAAc,SAAS;;wBAQvB;;;;;;;wBAaA,cAAc,mBAAmB;;wBAYjC,UACf,mBACA,aACA;;KAiBW,oBAAoB,eAAe;;wBAG/B,cACf,mBACA,aACA,aAAY,mBACV;;;qBC3NU,WAAW,0CACZ,UAAU,OAAO;WAEnB,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQ;;;;;mBAM9B;;;;;UAMT;EAER,YAAY,IAAI,cAAc;EAa9B,WAAW;UAIH;UAKM"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { n as Construct } from "./construct-interface-DluK3_da.mjs";
|
|
2
|
+
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
3
|
+
import { Service } from "@geekmidas/services";
|
|
4
|
+
//#region src/encryption/cipher.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The cipher behind an `Encryption` construct, and the format it writes.
|
|
7
|
+
*
|
|
8
|
+
* Every ciphertext names the key that wrote it — `gkm1.<keyId>.<payload>` — so
|
|
9
|
+
* `decrypt` never has to guess, a rotated key still opens what it wrote, and
|
|
10
|
+
* retiring a key is a decision made against data rather than a hope. The
|
|
11
|
+
* format version leads, so the day it has to change, both can be read.
|
|
12
|
+
*
|
|
13
|
+
* Two backends, picked by the scheme of the construct's URL, the way a queue's
|
|
14
|
+
* connection string picks its broker:
|
|
15
|
+
*
|
|
16
|
+
* - `aes256gcm://` — a keyring this process holds: AES-256-GCM with the newest
|
|
17
|
+
* key, HMAC-SHA256 for the blind index. Local, test and server stages.
|
|
18
|
+
* - `kms://` — envelope encryption under an AWS KMS key, and a KMS HMAC key for
|
|
19
|
+
* the index. The key material never leaves KMS. See `./kms`.
|
|
20
|
+
*/
|
|
21
|
+
/** What a handler is given: `services.pii.encrypt(…)` and the rest. */
|
|
22
|
+
interface Cipher {
|
|
23
|
+
/** Plaintext in, a self-describing ciphertext string out. */
|
|
24
|
+
encrypt(plaintext: string): Promise<string>;
|
|
25
|
+
/** Opens any ciphertext this construct wrote, under whichever key wrote it. */
|
|
26
|
+
decrypt(ciphertext: string): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* A blind index: the same value always gives the same string, so an
|
|
29
|
+
* encrypted column can still be looked up by an indexed column beside it.
|
|
30
|
+
*
|
|
31
|
+
* Deterministic on purpose, which is also why its key never rotates — a
|
|
32
|
+
* rotated index key would make every stored index miss.
|
|
33
|
+
*/
|
|
34
|
+
index(value: string): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* The same plaintext under the current key — what a sweep runs over a
|
|
37
|
+
* column before an old key is retired. Unchanged when it is already current.
|
|
38
|
+
*/
|
|
39
|
+
reencrypt(ciphertext: string): Promise<string>;
|
|
40
|
+
}
|
|
41
|
+
export declare class EncryptionUrlInvalid extends Error {
|
|
42
|
+
readonly construct: string;
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
constructor(construct: string, reason: string);
|
|
45
|
+
}
|
|
46
|
+
export declare class UnknownEncryptionScheme extends Error {
|
|
47
|
+
readonly construct: string;
|
|
48
|
+
readonly scheme: string;
|
|
49
|
+
constructor(construct: string, scheme: string);
|
|
50
|
+
}
|
|
51
|
+
export declare class CiphertextMalformed extends Error {
|
|
52
|
+
readonly construct: string;
|
|
53
|
+
constructor(construct: string);
|
|
54
|
+
}
|
|
55
|
+
export declare class EncryptionKeyRetired extends Error {
|
|
56
|
+
readonly construct: string;
|
|
57
|
+
readonly keyId: string;
|
|
58
|
+
constructor(construct: string, keyId: string);
|
|
59
|
+
}
|
|
60
|
+
export declare class CiphertextNotAuthentic extends Error {
|
|
61
|
+
readonly construct: string;
|
|
62
|
+
constructor(construct: string);
|
|
63
|
+
}
|
|
64
|
+
export declare class CurrentKeyCannotRetire extends Error {
|
|
65
|
+
readonly construct: string;
|
|
66
|
+
readonly keyId: string;
|
|
67
|
+
constructor(construct: string, keyId: string);
|
|
68
|
+
}
|
|
69
|
+
/** A local keyring: newest key first, and the index key that never rotates. */
|
|
70
|
+
interface Keyring {
|
|
71
|
+
keys: {
|
|
72
|
+
id: string;
|
|
73
|
+
key: Buffer;
|
|
74
|
+
}[];
|
|
75
|
+
index: Buffer;
|
|
76
|
+
}
|
|
77
|
+
/** Parse `aes256gcm://local?keys=k2.<key>,k1.<key>&index=<key>`. */
|
|
78
|
+
export declare function parseKeyring(construct: string, url: string): Keyring;
|
|
79
|
+
export declare function formatKeyring(keyring: Keyring): string;
|
|
80
|
+
/** A keyring with one fresh key, `k1`, and a fresh index key. */
|
|
81
|
+
export declare function generateKeyring(): string;
|
|
82
|
+
/**
|
|
83
|
+
* The keyring with a new current key in front, and every older one kept.
|
|
84
|
+
*
|
|
85
|
+
* Nothing is dropped: what the old keys wrote still has to open until a sweep
|
|
86
|
+
* has re-encrypted it — see {@link retireKey}.
|
|
87
|
+
*/
|
|
88
|
+
export declare function rotateKeyring(construct: string, url: string): string;
|
|
89
|
+
/** The keyring without `keyId`, which must not be the current key. */
|
|
90
|
+
export declare function retireKey(construct: string, url: string, keyId: string): string;
|
|
91
|
+
/** Says, once per key per process, that a value is still under an old key. */
|
|
92
|
+
type StaleKeyReporter = (keyId: string, current: string) => void;
|
|
93
|
+
/** The `aes256gcm://` cipher: a keyring held in process. */
|
|
94
|
+
export declare function keyringCipher(construct: string, url: string, onStaleKey?: StaleKeyReporter): Cipher;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/encryption.d.ts
|
|
97
|
+
export declare class Encryption<TName extends string = string> implements Construct<TName, Cipher> {
|
|
98
|
+
readonly id: TName;
|
|
99
|
+
readonly service: Service<Uncapitalize<TName>, Cipher>;
|
|
100
|
+
/**
|
|
101
|
+
* Declared once and read by both `declare()` and `connect()`, so the key the
|
|
102
|
+
* target publishes and the key the client reads cannot drift.
|
|
103
|
+
*/
|
|
104
|
+
private readonly key;
|
|
105
|
+
/**
|
|
106
|
+
* One cipher per process, held as the promise: a keyring is parsed once and
|
|
107
|
+
* a KMS client is built once, however many handlers register it at once.
|
|
108
|
+
*/
|
|
109
|
+
private cipher?;
|
|
110
|
+
constructor(id: ConstructName<TName>);
|
|
111
|
+
declare(): Declaration[];
|
|
112
|
+
private connect;
|
|
113
|
+
private open;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export type { Cipher, Keyring };
|
|
117
|
+
//# sourceMappingURL=encryption.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.mts","names":[],"sources":["../src/encryption/cipher.ts","../src/encryption.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;UAyBiB;;EAEhB,QAAQ,oBAAoB;;EAE5B,QAAQ,qBAAqB;;;;;;;;EAQ7B,MAAM,gBAAgB;;;;;EAKtB,UAAU,qBAAqB;;qBAanB,6BAA6B;WAE/B;WACA;EAFV,YACU,mBACA;;qBASE,gCAAgC;WAElC;WACA;EAFV,YACU,mBACA;;qBASE,4BAA4B;WACnB;EAArB,YAAqB;;qBAQT,6BAA6B;WAE/B;WACA;EAFV,YACU,mBACA;;qBASE,+BAA+B;WACtB;EAArB,YAAqB;;qBAQT,+BAA+B;WAEjC;WACA;EAFV,YACU,mBACA;;;UAuEM;EAChB;IAAQ;IAAY,KAAK;;EACzB,OAAO;;;wBAIQ,aAAa,mBAAmB,cAAc;wBAqC9C,cAAc,SAAS;;wBAQvB;;;;;;;wBAaA,cAAc,mBAAmB;;wBAYjC,UACf,mBACA,aACA;;KAiBW,oBAAoB,eAAe;;wBAG/B,cACf,mBACA,aACA,aAAY,mBACV;;;qBC3NU,WAAW,0CACZ,UAAU,OAAO;WAEnB,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQ;;;;;mBAM9B;;;;;UAMT;EAER,YAAY,IAAI,cAAc;EAa9B,WAAW;UAIH;UAKM"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { _ as rotateKeyring, a as EncryptionUrlInvalid, d as generateKeyring, f as keyringCipher, g as retireKey, h as parseKeyring, i as EncryptionKeyRetired, n as CiphertextNotAuthentic, r as CurrentKeyCannotRetire, s as UnknownEncryptionScheme, t as CiphertextMalformed, u as formatKeyring } from "./cipher-C1lEFX63.mjs";
|
|
2
|
+
import { KMS_SCHEME, canonicalId, provideKey, serviceKey } from "@geekmidas/manifest";
|
|
3
|
+
//#region src/encryption.ts
|
|
4
|
+
/**
|
|
5
|
+
* `Encryption` — a key that encrypts what the application stores.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* export const pii = new Encryption('Pii');
|
|
9
|
+
*
|
|
10
|
+
* // an endpoint that `.dependsOn([pii])`
|
|
11
|
+
* const email = await services.pii.encrypt(body.email);
|
|
12
|
+
* const emailIndex = await services.pii.index(body.email);
|
|
13
|
+
* await db.insertInto('users').values({ email, emailIndex }).execute();
|
|
14
|
+
*
|
|
15
|
+
* // and to find them again, without decrypting a column
|
|
16
|
+
* db.selectFrom('users').where('emailIndex', '=', await services.pii.index(q));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* The app names no cipher and holds no key. The construct provides one URL,
|
|
20
|
+
* `<ID>_URL`, and its scheme picks the backend the way a queue's connection
|
|
21
|
+
* string picks its broker:
|
|
22
|
+
*
|
|
23
|
+
* - **AWS** — `kms://`: envelope encryption under a KMS key that rotates
|
|
24
|
+
* yearly, and a KMS HMAC key for the index. Only a function that depends on
|
|
25
|
+
* the construct is granted either key.
|
|
26
|
+
* - **Server, local, tests** — `aes256gcm://`: a keyring the process holds.
|
|
27
|
+
* Derived locally, so `gkm dev` and `gkm test` need nothing set; generated
|
|
28
|
+
* into a server stage's secrets on its first deploy, and rotated there with
|
|
29
|
+
* `gkm encryption:rotate`.
|
|
30
|
+
*
|
|
31
|
+
* Every ciphertext names the key that wrote it, so a rotated key still opens
|
|
32
|
+
* what it wrote. Retiring one is explicit — `reencrypt` the column, then
|
|
33
|
+
* `gkm encryption:retire` — and a value still under an old key says so when it
|
|
34
|
+
* is decrypted, once per key per process.
|
|
35
|
+
*/
|
|
36
|
+
var Encryption = class {
|
|
37
|
+
id;
|
|
38
|
+
service;
|
|
39
|
+
/**
|
|
40
|
+
* Declared once and read by both `declare()` and `connect()`, so the key the
|
|
41
|
+
* target publishes and the key the client reads cannot drift.
|
|
42
|
+
*/
|
|
43
|
+
key;
|
|
44
|
+
/**
|
|
45
|
+
* One cipher per process, held as the promise: a keyring is parsed once and
|
|
46
|
+
* a KMS client is built once, however many handlers register it at once.
|
|
47
|
+
*/
|
|
48
|
+
cipher;
|
|
49
|
+
constructor(id) {
|
|
50
|
+
const canonical = canonicalId(id);
|
|
51
|
+
this.id = canonical;
|
|
52
|
+
this.key = provideKey(canonical, "url");
|
|
53
|
+
this.service = {
|
|
54
|
+
serviceName: serviceKey(canonical),
|
|
55
|
+
register: (options) => this.connect(options)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
declare() {
|
|
59
|
+
return [{
|
|
60
|
+
kind: "encryption",
|
|
61
|
+
id: this.id,
|
|
62
|
+
provides: [this.key]
|
|
63
|
+
}];
|
|
64
|
+
}
|
|
65
|
+
connect(options) {
|
|
66
|
+
this.cipher ??= this.open(options);
|
|
67
|
+
return this.cipher;
|
|
68
|
+
}
|
|
69
|
+
async open(options) {
|
|
70
|
+
const { url } = options.envParser.create((get) => ({ url: get(this.key).string() })).parse();
|
|
71
|
+
const scheme = url.slice(0, url.indexOf(":") + 1);
|
|
72
|
+
if (scheme === "aes256gcm:") return keyringCipher(this.id, url, (stale, current) => console.warn(`${this.id} decrypted a value still under '${stale}' (current: '${current}'). reencrypt it, and retire '${stale}' once nothing is left under it.`));
|
|
73
|
+
if (scheme === KMS_SCHEME) {
|
|
74
|
+
const { kmsCipher } = await import("./kms-BdUlMJEZ.mjs");
|
|
75
|
+
return kmsCipher(this.id, url);
|
|
76
|
+
}
|
|
77
|
+
throw new UnknownEncryptionScheme(this.id, scheme);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { CiphertextMalformed, CiphertextNotAuthentic, CurrentKeyCannotRetire, Encryption, EncryptionKeyRetired, EncryptionUrlInvalid, UnknownEncryptionScheme, formatKeyring, generateKeyring, keyringCipher, parseKeyring, retireKey, rotateKeyring };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=encryption.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.mjs","names":[],"sources":["../src/encryption.ts"],"sourcesContent":["/**\n * `Encryption` — a key that encrypts what the application stores.\n *\n * ```ts\n * export const pii = new Encryption('Pii');\n *\n * // an endpoint that `.dependsOn([pii])`\n * const email = await services.pii.encrypt(body.email);\n * const emailIndex = await services.pii.index(body.email);\n * await db.insertInto('users').values({ email, emailIndex }).execute();\n *\n * // and to find them again, without decrypting a column\n * db.selectFrom('users').where('emailIndex', '=', await services.pii.index(q));\n * ```\n *\n * The app names no cipher and holds no key. The construct provides one URL,\n * `<ID>_URL`, and its scheme picks the backend the way a queue's connection\n * string picks its broker:\n *\n * - **AWS** — `kms://`: envelope encryption under a KMS key that rotates\n * yearly, and a KMS HMAC key for the index. Only a function that depends on\n * the construct is granted either key.\n * - **Server, local, tests** — `aes256gcm://`: a keyring the process holds.\n * Derived locally, so `gkm dev` and `gkm test` need nothing set; generated\n * into a server stage's secrets on its first deploy, and rotated there with\n * `gkm encryption:rotate`.\n *\n * Every ciphertext names the key that wrote it, so a rotated key still opens\n * what it wrote. Retiring one is explicit — `reencrypt` the column, then\n * `gkm encryption:retire` — and a value still under an old key says so when it\n * is decrypted, once per key per process.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tKMS_SCHEME,\n\tprovideKey,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { Construct } from './construct-interface';\nimport {\n\ttype Cipher,\n\tkeyringCipher,\n\tLOCAL_SCHEME,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nexport type { Cipher } from './encryption/cipher';\nexport {\n\tCiphertextMalformed,\n\tCiphertextNotAuthentic,\n\tCurrentKeyCannotRetire,\n\tEncryptionKeyRetired,\n\tEncryptionUrlInvalid,\n\tformatKeyring,\n\tgenerateKeyring,\n\ttype Keyring,\n\tkeyringCipher,\n\tparseKeyring,\n\tretireKey,\n\trotateKeyring,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nexport class Encryption<TName extends string = string>\n\timplements Construct<TName, Cipher>\n{\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, Cipher>;\n\n\t/**\n\t * Declared once and read by both `declare()` and `connect()`, so the key the\n\t * target publishes and the key the client reads cannot drift.\n\t */\n\tprivate readonly key: string;\n\n\t/**\n\t * One cipher per process, held as the promise: a keyring is parsed once and\n\t * a KMS client is built once, however many handlers register it at once.\n\t */\n\tprivate cipher?: Promise<Cipher>;\n\n\tconstructor(id: ConstructName<TName>) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.key = provideKey(canonical, 'url');\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (options) => this.connect(options),\n\t\t};\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [{ kind: 'encryption', id: this.id, provides: [this.key] }];\n\t}\n\n\tprivate connect(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tthis.cipher ??= this.open(options);\n\t\treturn this.cipher;\n\t}\n\n\tprivate async open(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tconst { url } = options.envParser\n\t\t\t.create((get) => ({ url: get(this.key).string() }))\n\t\t\t.parse();\n\t\tconst scheme = url.slice(0, url.indexOf(':') + 1);\n\n\t\tif (scheme === LOCAL_SCHEME) {\n\t\t\treturn keyringCipher(this.id, url, (stale, current) =>\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${this.id} decrypted a value still under '${stale}' (current: '${current}'). reencrypt it, and retire '${stale}' once nothing is left under it.`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tif (scheme === KMS_SCHEME) {\n\t\t\t// Loaded only here, so a project that never deploys to AWS never\n\t\t\t// needs `@aws-sdk/client-kms` installed.\n\t\t\tconst { kmsCipher } = await import('./encryption/kms');\n\t\t\treturn kmsCipher(this.id, url);\n\t\t}\n\n\t\tthrow new UnknownEncryptionScheme(this.id, scheme);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,IAAa,aAAb,MAEA;CACC;CACA;;;;;CAMA;;;;;CAMA;CAEA,YAAY,IAA0B;EACrC,MAAM,YAAY,YAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,MAAM,WAAW,WAAW,KAAK;EAGtC,KAAK,UAAU;GACd,aAAa,WAAW,SAAS;GACjC,WAAW,YAAY,KAAK,QAAQ,OAAO;EAC5C;CACD;CAEA,UAAyB;EACxB,OAAO,CAAC;GAAE,MAAM;GAAc,IAAI,KAAK;GAAI,UAAU,CAAC,KAAK,GAAG;EAAE,CAAC;CAClE;CAEA,QAAgB,SAAkD;EACjE,KAAK,WAAW,KAAK,KAAK,OAAO;EACjC,OAAO,KAAK;CACb;CAEA,MAAc,KAAK,SAAkD;EACpE,MAAM,EAAE,QAAQ,QAAQ,UACtB,QAAQ,SAAS,EAAE,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAClD,MAAM;EACR,MAAM,SAAS,IAAI,MAAM,GAAG,IAAI,QAAQ,GAAG,IAAI,CAAC;EAEhD,IAAI,WAAA,cACH,OAAO,cAAc,KAAK,IAAI,MAAM,OAAO,YAC1C,QAAQ,KACP,GAAG,KAAK,GAAG,kCAAkC,MAAM,eAAe,QAAQ,gCAAgC,MAAM,iCACjH,CACD;EAGD,IAAI,WAAW,YAAY;GAG1B,MAAM,EAAE,cAAc,MAAM,OAAO;GACnC,OAAO,UAAU,KAAK,IAAI,GAAG;EAC9B;EAEA,MAAM,IAAI,wBAAwB,KAAK,IAAI,MAAM;CAClD;AACD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const require_cipher = require("./cipher-CVxfwLjk.cjs");
|
|
2
|
+
let _aws_sdk_client_kms = require("@aws-sdk/client-kms");
|
|
3
|
+
//#region src/encryption/kms.ts
|
|
4
|
+
/**
|
|
5
|
+
* The `kms://` cipher: envelope encryption under an AWS KMS key.
|
|
6
|
+
*
|
|
7
|
+
* Each `encrypt` asks KMS for a fresh data key, seals the plaintext with it
|
|
8
|
+
* locally, and stores the data key *as KMS encrypted it* beside the data. The
|
|
9
|
+
* plaintext data key is used once and dropped, and the master key never leaves
|
|
10
|
+
* KMS — every decrypt is a KMS call IAM can refuse and CloudTrail records.
|
|
11
|
+
*
|
|
12
|
+
* Rotation is KMS's: it keeps every backing version of the key, and the
|
|
13
|
+
* encrypted data key names the one that wrapped it, so nothing here tracks a
|
|
14
|
+
* version and `reencrypt` has nothing to move. The ciphertext's key field is
|
|
15
|
+
* `kms` for that reason.
|
|
16
|
+
*
|
|
17
|
+
* The blind index is a KMS HMAC key's `GenerateMac`: deterministic, and the
|
|
18
|
+
* key is as unextractable as the encryption key.
|
|
19
|
+
*
|
|
20
|
+
* In its own module, loaded only when a URL says `kms://`, so a project that
|
|
21
|
+
* never deploys to AWS never needs `@aws-sdk/client-kms` installed.
|
|
22
|
+
*/
|
|
23
|
+
/** The ciphertext's key field: the version lives inside KMS's own blob. */
|
|
24
|
+
const KMS_KEY_ID = "kms";
|
|
25
|
+
function kmsCipher(construct, url) {
|
|
26
|
+
const parsed = new URL(url);
|
|
27
|
+
const region = parsed.hostname;
|
|
28
|
+
const keyId = parsed.searchParams.get("key");
|
|
29
|
+
const indexKeyId = parsed.searchParams.get("index");
|
|
30
|
+
if (!region || !keyId || !indexKeyId) throw new require_cipher.EncryptionUrlInvalid(construct, "a kms:// URL names a region, a key and an index key");
|
|
31
|
+
const endpoint = parsed.searchParams.get("endpoint");
|
|
32
|
+
const kms = new _aws_sdk_client_kms.KMSClient({
|
|
33
|
+
region,
|
|
34
|
+
...endpoint ? { endpoint } : {}
|
|
35
|
+
});
|
|
36
|
+
const context = { construct };
|
|
37
|
+
const aad = require_cipher.associatedData(construct, KMS_KEY_ID);
|
|
38
|
+
return {
|
|
39
|
+
async encrypt(plaintext) {
|
|
40
|
+
const dataKey = await kms.send(new _aws_sdk_client_kms.GenerateDataKeyCommand({
|
|
41
|
+
KeyId: keyId,
|
|
42
|
+
KeySpec: "AES_256",
|
|
43
|
+
EncryptionContext: context
|
|
44
|
+
}));
|
|
45
|
+
const wrapped = Buffer.from(dataKey.CiphertextBlob);
|
|
46
|
+
const sealed = require_cipher.seal(Buffer.from(dataKey.Plaintext), Buffer.from(plaintext, "utf8"), aad);
|
|
47
|
+
const length = Buffer.alloc(2);
|
|
48
|
+
length.writeUInt16BE(wrapped.length);
|
|
49
|
+
return require_cipher.formatCiphertext(KMS_KEY_ID, Buffer.concat([
|
|
50
|
+
length,
|
|
51
|
+
wrapped,
|
|
52
|
+
sealed
|
|
53
|
+
]));
|
|
54
|
+
},
|
|
55
|
+
async decrypt(ciphertext) {
|
|
56
|
+
const { payload } = require_cipher.parseCiphertext(construct, ciphertext);
|
|
57
|
+
const length = payload.length >= 2 ? payload.readUInt16BE(0) : 0;
|
|
58
|
+
const wrapped = payload.subarray(2, 2 + length);
|
|
59
|
+
if (!length || wrapped.length !== length) throw new require_cipher.CiphertextNotAuthentic(construct);
|
|
60
|
+
const dataKey = await kms.send(new _aws_sdk_client_kms.DecryptCommand({
|
|
61
|
+
CiphertextBlob: wrapped,
|
|
62
|
+
EncryptionContext: context
|
|
63
|
+
}));
|
|
64
|
+
const plaintext = require_cipher.open(Buffer.from(dataKey.Plaintext), payload.subarray(2 + length), aad);
|
|
65
|
+
if (!plaintext) throw new require_cipher.CiphertextNotAuthentic(construct);
|
|
66
|
+
return plaintext.toString("utf8");
|
|
67
|
+
},
|
|
68
|
+
async index(value) {
|
|
69
|
+
const { Mac } = await kms.send(new _aws_sdk_client_kms.GenerateMacCommand({
|
|
70
|
+
KeyId: indexKeyId,
|
|
71
|
+
MacAlgorithm: "HMAC_SHA_256",
|
|
72
|
+
Message: Buffer.from(value, "utf8")
|
|
73
|
+
}));
|
|
74
|
+
return Buffer.from(Mac).toString("base64url");
|
|
75
|
+
},
|
|
76
|
+
async reencrypt(ciphertext) {
|
|
77
|
+
require_cipher.parseCiphertext(construct, ciphertext);
|
|
78
|
+
return ciphertext;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
exports.kmsCipher = kmsCipher;
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=kms-B-Hm3d5r.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kms-B-Hm3d5r.cjs","names":["EncryptionUrlInvalid","KMSClient","associatedData","GenerateDataKeyCommand","seal","formatCiphertext","parseCiphertext","CiphertextNotAuthentic","DecryptCommand","open","GenerateMacCommand"],"sources":["../src/encryption/kms.ts"],"sourcesContent":["/**\n * The `kms://` cipher: envelope encryption under an AWS KMS key.\n *\n * Each `encrypt` asks KMS for a fresh data key, seals the plaintext with it\n * locally, and stores the data key *as KMS encrypted it* beside the data. The\n * plaintext data key is used once and dropped, and the master key never leaves\n * KMS — every decrypt is a KMS call IAM can refuse and CloudTrail records.\n *\n * Rotation is KMS's: it keeps every backing version of the key, and the\n * encrypted data key names the one that wrapped it, so nothing here tracks a\n * version and `reencrypt` has nothing to move. The ciphertext's key field is\n * `kms` for that reason.\n *\n * The blind index is a KMS HMAC key's `GenerateMac`: deterministic, and the\n * key is as unextractable as the encryption key.\n *\n * In its own module, loaded only when a URL says `kms://`, so a project that\n * never deploys to AWS never needs `@aws-sdk/client-kms` installed.\n */\n\nimport {\n\tDecryptCommand,\n\tGenerateDataKeyCommand,\n\tGenerateMacCommand,\n\tKMSClient,\n} from '@aws-sdk/client-kms';\nimport {\n\tassociatedData,\n\ttype Cipher,\n\tCiphertextNotAuthentic,\n\tEncryptionUrlInvalid,\n\tformatCiphertext,\n\topen,\n\tparseCiphertext,\n\tseal,\n} from './cipher';\n\n/** The ciphertext's key field: the version lives inside KMS's own blob. */\nconst KMS_KEY_ID = 'kms';\n\nexport function kmsCipher(construct: string, url: string): Cipher {\n\tconst parsed = new URL(url);\n\tconst region = parsed.hostname;\n\tconst keyId = parsed.searchParams.get('key');\n\tconst indexKeyId = parsed.searchParams.get('index');\n\tif (!region || !keyId || !indexKeyId) {\n\t\tthrow new EncryptionUrlInvalid(\n\t\t\tconstruct,\n\t\t\t'a kms:// URL names a region, a key and an index key',\n\t\t);\n\t}\n\n\tconst endpoint = parsed.searchParams.get('endpoint');\n\t// Credentials are not part of the address: the default chain — a Lambda's\n\t// role deployed, the environment against an emulator.\n\tconst kms = new KMSClient({ region, ...(endpoint ? { endpoint } : {}) });\n\t// What KMS checks on every decrypt, and what CloudTrail shows each call was\n\t// for — a data key minted for one construct will not open for another.\n\tconst context = { construct };\n\tconst aad = associatedData(construct, KMS_KEY_ID);\n\n\treturn {\n\t\tasync encrypt(plaintext) {\n\t\t\tconst dataKey = await kms.send(\n\t\t\t\tnew GenerateDataKeyCommand({\n\t\t\t\t\tKeyId: keyId,\n\t\t\t\t\tKeySpec: 'AES_256',\n\t\t\t\t\tEncryptionContext: context,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst wrapped = Buffer.from(dataKey.CiphertextBlob!);\n\t\t\tconst sealed = seal(\n\t\t\t\tBuffer.from(dataKey.Plaintext!),\n\t\t\t\tBuffer.from(plaintext, 'utf8'),\n\t\t\t\taad,\n\t\t\t);\n\n\t\t\tconst length = Buffer.alloc(2);\n\t\t\tlength.writeUInt16BE(wrapped.length);\n\t\t\treturn formatCiphertext(\n\t\t\t\tKMS_KEY_ID,\n\t\t\t\tBuffer.concat([length, wrapped, sealed]),\n\t\t\t);\n\t\t},\n\n\t\tasync decrypt(ciphertext) {\n\t\t\tconst { payload } = parseCiphertext(construct, ciphertext);\n\t\t\tconst length = payload.length >= 2 ? payload.readUInt16BE(0) : 0;\n\t\t\tconst wrapped = payload.subarray(2, 2 + length);\n\t\t\tif (!length || wrapped.length !== length) {\n\t\t\t\tthrow new CiphertextNotAuthentic(construct);\n\t\t\t}\n\n\t\t\tconst dataKey = await kms.send(\n\t\t\t\tnew DecryptCommand({\n\t\t\t\t\tCiphertextBlob: wrapped,\n\t\t\t\t\tEncryptionContext: context,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst plaintext = open(\n\t\t\t\tBuffer.from(dataKey.Plaintext!),\n\t\t\t\tpayload.subarray(2 + length),\n\t\t\t\taad,\n\t\t\t);\n\t\t\tif (!plaintext) throw new CiphertextNotAuthentic(construct);\n\n\t\t\treturn plaintext.toString('utf8');\n\t\t},\n\n\t\tasync index(value) {\n\t\t\tconst { Mac } = await kms.send(\n\t\t\t\tnew GenerateMacCommand({\n\t\t\t\t\tKeyId: indexKeyId,\n\t\t\t\t\tMacAlgorithm: 'HMAC_SHA_256',\n\t\t\t\t\tMessage: Buffer.from(value, 'utf8'),\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn Buffer.from(Mac!).toString('base64url');\n\t\t},\n\n\t\t// KMS keeps every version it rotated through, so a value is never under\n\t\t// a key that could be retired from under it.\n\t\tasync reencrypt(ciphertext) {\n\t\t\tparseCiphertext(construct, ciphertext);\n\t\t\treturn ciphertext;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,aAAa;AAEnB,SAAgB,UAAU,WAAmB,KAAqB;CACjE,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,MAAM,SAAS,OAAO;CACtB,MAAM,QAAQ,OAAO,aAAa,IAAI,KAAK;CAC3C,MAAM,aAAa,OAAO,aAAa,IAAI,OAAO;CAClD,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,YACzB,MAAM,IAAIA,eAAAA,qBACT,WACA,qDACD;CAGD,MAAM,WAAW,OAAO,aAAa,IAAI,UAAU;CAGnD,MAAM,MAAM,IAAIC,oBAAAA,UAAU;EAAE;EAAQ,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;CAAG,CAAC;CAGvE,MAAM,UAAU,EAAE,UAAU;CAC5B,MAAM,MAAMC,eAAAA,eAAe,WAAW,UAAU;CAEhD,OAAO;EACN,MAAM,QAAQ,WAAW;GACxB,MAAM,UAAU,MAAM,IAAI,KACzB,IAAIC,oBAAAA,uBAAuB;IAC1B,OAAO;IACP,SAAS;IACT,mBAAmB;GACpB,CAAC,CACF;GACA,MAAM,UAAU,OAAO,KAAK,QAAQ,cAAe;GACnD,MAAM,SAASC,eAAAA,KACd,OAAO,KAAK,QAAQ,SAAU,GAC9B,OAAO,KAAK,WAAW,MAAM,GAC7B,GACD;GAEA,MAAM,SAAS,OAAO,MAAM,CAAC;GAC7B,OAAO,cAAc,QAAQ,MAAM;GACnC,OAAOC,eAAAA,iBACN,YACA,OAAO,OAAO;IAAC;IAAQ;IAAS;GAAM,CAAC,CACxC;EACD;EAEA,MAAM,QAAQ,YAAY;GACzB,MAAM,EAAE,YAAYC,eAAAA,gBAAgB,WAAW,UAAU;GACzD,MAAM,SAAS,QAAQ,UAAU,IAAI,QAAQ,aAAa,CAAC,IAAI;GAC/D,MAAM,UAAU,QAAQ,SAAS,GAAG,IAAI,MAAM;GAC9C,IAAI,CAAC,UAAU,QAAQ,WAAW,QACjC,MAAM,IAAIC,eAAAA,uBAAuB,SAAS;GAG3C,MAAM,UAAU,MAAM,IAAI,KACzB,IAAIC,oBAAAA,eAAe;IAClB,gBAAgB;IAChB,mBAAmB;GACpB,CAAC,CACF;GACA,MAAM,YAAYC,eAAAA,KACjB,OAAO,KAAK,QAAQ,SAAU,GAC9B,QAAQ,SAAS,IAAI,MAAM,GAC3B,GACD;GACA,IAAI,CAAC,WAAW,MAAM,IAAIF,eAAAA,uBAAuB,SAAS;GAE1D,OAAO,UAAU,SAAS,MAAM;EACjC;EAEA,MAAM,MAAM,OAAO;GAClB,MAAM,EAAE,QAAQ,MAAM,IAAI,KACzB,IAAIG,oBAAAA,mBAAmB;IACtB,OAAO;IACP,cAAc;IACd,SAAS,OAAO,KAAK,OAAO,MAAM;GACnC,CAAC,CACF;GACA,OAAO,OAAO,KAAK,GAAI,CAAC,CAAC,SAAS,WAAW;EAC9C;EAIA,MAAM,UAAU,YAAY;GAC3B,eAAA,gBAAgB,WAAW,UAAU;GACrC,OAAO;EACR;CACD;AACD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { a as EncryptionUrlInvalid, c as associatedData, l as formatCiphertext, m as parseCiphertext, n as CiphertextNotAuthentic, p as open, v as seal } from "./cipher-C1lEFX63.mjs";
|
|
2
|
+
import { DecryptCommand, GenerateDataKeyCommand, GenerateMacCommand, KMSClient } from "@aws-sdk/client-kms";
|
|
3
|
+
//#region src/encryption/kms.ts
|
|
4
|
+
/**
|
|
5
|
+
* The `kms://` cipher: envelope encryption under an AWS KMS key.
|
|
6
|
+
*
|
|
7
|
+
* Each `encrypt` asks KMS for a fresh data key, seals the plaintext with it
|
|
8
|
+
* locally, and stores the data key *as KMS encrypted it* beside the data. The
|
|
9
|
+
* plaintext data key is used once and dropped, and the master key never leaves
|
|
10
|
+
* KMS — every decrypt is a KMS call IAM can refuse and CloudTrail records.
|
|
11
|
+
*
|
|
12
|
+
* Rotation is KMS's: it keeps every backing version of the key, and the
|
|
13
|
+
* encrypted data key names the one that wrapped it, so nothing here tracks a
|
|
14
|
+
* version and `reencrypt` has nothing to move. The ciphertext's key field is
|
|
15
|
+
* `kms` for that reason.
|
|
16
|
+
*
|
|
17
|
+
* The blind index is a KMS HMAC key's `GenerateMac`: deterministic, and the
|
|
18
|
+
* key is as unextractable as the encryption key.
|
|
19
|
+
*
|
|
20
|
+
* In its own module, loaded only when a URL says `kms://`, so a project that
|
|
21
|
+
* never deploys to AWS never needs `@aws-sdk/client-kms` installed.
|
|
22
|
+
*/
|
|
23
|
+
/** The ciphertext's key field: the version lives inside KMS's own blob. */
|
|
24
|
+
const KMS_KEY_ID = "kms";
|
|
25
|
+
function kmsCipher(construct, url) {
|
|
26
|
+
const parsed = new URL(url);
|
|
27
|
+
const region = parsed.hostname;
|
|
28
|
+
const keyId = parsed.searchParams.get("key");
|
|
29
|
+
const indexKeyId = parsed.searchParams.get("index");
|
|
30
|
+
if (!region || !keyId || !indexKeyId) throw new EncryptionUrlInvalid(construct, "a kms:// URL names a region, a key and an index key");
|
|
31
|
+
const endpoint = parsed.searchParams.get("endpoint");
|
|
32
|
+
const kms = new KMSClient({
|
|
33
|
+
region,
|
|
34
|
+
...endpoint ? { endpoint } : {}
|
|
35
|
+
});
|
|
36
|
+
const context = { construct };
|
|
37
|
+
const aad = associatedData(construct, KMS_KEY_ID);
|
|
38
|
+
return {
|
|
39
|
+
async encrypt(plaintext) {
|
|
40
|
+
const dataKey = await kms.send(new GenerateDataKeyCommand({
|
|
41
|
+
KeyId: keyId,
|
|
42
|
+
KeySpec: "AES_256",
|
|
43
|
+
EncryptionContext: context
|
|
44
|
+
}));
|
|
45
|
+
const wrapped = Buffer.from(dataKey.CiphertextBlob);
|
|
46
|
+
const sealed = seal(Buffer.from(dataKey.Plaintext), Buffer.from(plaintext, "utf8"), aad);
|
|
47
|
+
const length = Buffer.alloc(2);
|
|
48
|
+
length.writeUInt16BE(wrapped.length);
|
|
49
|
+
return formatCiphertext(KMS_KEY_ID, Buffer.concat([
|
|
50
|
+
length,
|
|
51
|
+
wrapped,
|
|
52
|
+
sealed
|
|
53
|
+
]));
|
|
54
|
+
},
|
|
55
|
+
async decrypt(ciphertext) {
|
|
56
|
+
const { payload } = parseCiphertext(construct, ciphertext);
|
|
57
|
+
const length = payload.length >= 2 ? payload.readUInt16BE(0) : 0;
|
|
58
|
+
const wrapped = payload.subarray(2, 2 + length);
|
|
59
|
+
if (!length || wrapped.length !== length) throw new CiphertextNotAuthentic(construct);
|
|
60
|
+
const dataKey = await kms.send(new DecryptCommand({
|
|
61
|
+
CiphertextBlob: wrapped,
|
|
62
|
+
EncryptionContext: context
|
|
63
|
+
}));
|
|
64
|
+
const plaintext = open(Buffer.from(dataKey.Plaintext), payload.subarray(2 + length), aad);
|
|
65
|
+
if (!plaintext) throw new CiphertextNotAuthentic(construct);
|
|
66
|
+
return plaintext.toString("utf8");
|
|
67
|
+
},
|
|
68
|
+
async index(value) {
|
|
69
|
+
const { Mac } = await kms.send(new GenerateMacCommand({
|
|
70
|
+
KeyId: indexKeyId,
|
|
71
|
+
MacAlgorithm: "HMAC_SHA_256",
|
|
72
|
+
Message: Buffer.from(value, "utf8")
|
|
73
|
+
}));
|
|
74
|
+
return Buffer.from(Mac).toString("base64url");
|
|
75
|
+
},
|
|
76
|
+
async reencrypt(ciphertext) {
|
|
77
|
+
parseCiphertext(construct, ciphertext);
|
|
78
|
+
return ciphertext;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { kmsCipher };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=kms-BdUlMJEZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kms-BdUlMJEZ.mjs","names":[],"sources":["../src/encryption/kms.ts"],"sourcesContent":["/**\n * The `kms://` cipher: envelope encryption under an AWS KMS key.\n *\n * Each `encrypt` asks KMS for a fresh data key, seals the plaintext with it\n * locally, and stores the data key *as KMS encrypted it* beside the data. The\n * plaintext data key is used once and dropped, and the master key never leaves\n * KMS — every decrypt is a KMS call IAM can refuse and CloudTrail records.\n *\n * Rotation is KMS's: it keeps every backing version of the key, and the\n * encrypted data key names the one that wrapped it, so nothing here tracks a\n * version and `reencrypt` has nothing to move. The ciphertext's key field is\n * `kms` for that reason.\n *\n * The blind index is a KMS HMAC key's `GenerateMac`: deterministic, and the\n * key is as unextractable as the encryption key.\n *\n * In its own module, loaded only when a URL says `kms://`, so a project that\n * never deploys to AWS never needs `@aws-sdk/client-kms` installed.\n */\n\nimport {\n\tDecryptCommand,\n\tGenerateDataKeyCommand,\n\tGenerateMacCommand,\n\tKMSClient,\n} from '@aws-sdk/client-kms';\nimport {\n\tassociatedData,\n\ttype Cipher,\n\tCiphertextNotAuthentic,\n\tEncryptionUrlInvalid,\n\tformatCiphertext,\n\topen,\n\tparseCiphertext,\n\tseal,\n} from './cipher';\n\n/** The ciphertext's key field: the version lives inside KMS's own blob. */\nconst KMS_KEY_ID = 'kms';\n\nexport function kmsCipher(construct: string, url: string): Cipher {\n\tconst parsed = new URL(url);\n\tconst region = parsed.hostname;\n\tconst keyId = parsed.searchParams.get('key');\n\tconst indexKeyId = parsed.searchParams.get('index');\n\tif (!region || !keyId || !indexKeyId) {\n\t\tthrow new EncryptionUrlInvalid(\n\t\t\tconstruct,\n\t\t\t'a kms:// URL names a region, a key and an index key',\n\t\t);\n\t}\n\n\tconst endpoint = parsed.searchParams.get('endpoint');\n\t// Credentials are not part of the address: the default chain — a Lambda's\n\t// role deployed, the environment against an emulator.\n\tconst kms = new KMSClient({ region, ...(endpoint ? { endpoint } : {}) });\n\t// What KMS checks on every decrypt, and what CloudTrail shows each call was\n\t// for — a data key minted for one construct will not open for another.\n\tconst context = { construct };\n\tconst aad = associatedData(construct, KMS_KEY_ID);\n\n\treturn {\n\t\tasync encrypt(plaintext) {\n\t\t\tconst dataKey = await kms.send(\n\t\t\t\tnew GenerateDataKeyCommand({\n\t\t\t\t\tKeyId: keyId,\n\t\t\t\t\tKeySpec: 'AES_256',\n\t\t\t\t\tEncryptionContext: context,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst wrapped = Buffer.from(dataKey.CiphertextBlob!);\n\t\t\tconst sealed = seal(\n\t\t\t\tBuffer.from(dataKey.Plaintext!),\n\t\t\t\tBuffer.from(plaintext, 'utf8'),\n\t\t\t\taad,\n\t\t\t);\n\n\t\t\tconst length = Buffer.alloc(2);\n\t\t\tlength.writeUInt16BE(wrapped.length);\n\t\t\treturn formatCiphertext(\n\t\t\t\tKMS_KEY_ID,\n\t\t\t\tBuffer.concat([length, wrapped, sealed]),\n\t\t\t);\n\t\t},\n\n\t\tasync decrypt(ciphertext) {\n\t\t\tconst { payload } = parseCiphertext(construct, ciphertext);\n\t\t\tconst length = payload.length >= 2 ? payload.readUInt16BE(0) : 0;\n\t\t\tconst wrapped = payload.subarray(2, 2 + length);\n\t\t\tif (!length || wrapped.length !== length) {\n\t\t\t\tthrow new CiphertextNotAuthentic(construct);\n\t\t\t}\n\n\t\t\tconst dataKey = await kms.send(\n\t\t\t\tnew DecryptCommand({\n\t\t\t\t\tCiphertextBlob: wrapped,\n\t\t\t\t\tEncryptionContext: context,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst plaintext = open(\n\t\t\t\tBuffer.from(dataKey.Plaintext!),\n\t\t\t\tpayload.subarray(2 + length),\n\t\t\t\taad,\n\t\t\t);\n\t\t\tif (!plaintext) throw new CiphertextNotAuthentic(construct);\n\n\t\t\treturn plaintext.toString('utf8');\n\t\t},\n\n\t\tasync index(value) {\n\t\t\tconst { Mac } = await kms.send(\n\t\t\t\tnew GenerateMacCommand({\n\t\t\t\t\tKeyId: indexKeyId,\n\t\t\t\t\tMacAlgorithm: 'HMAC_SHA_256',\n\t\t\t\t\tMessage: Buffer.from(value, 'utf8'),\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn Buffer.from(Mac!).toString('base64url');\n\t\t},\n\n\t\t// KMS keeps every version it rotated through, so a value is never under\n\t\t// a key that could be retired from under it.\n\t\tasync reencrypt(ciphertext) {\n\t\t\tparseCiphertext(construct, ciphertext);\n\t\t\treturn ciphertext;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,aAAa;AAEnB,SAAgB,UAAU,WAAmB,KAAqB;CACjE,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,MAAM,SAAS,OAAO;CACtB,MAAM,QAAQ,OAAO,aAAa,IAAI,KAAK;CAC3C,MAAM,aAAa,OAAO,aAAa,IAAI,OAAO;CAClD,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,YACzB,MAAM,IAAI,qBACT,WACA,qDACD;CAGD,MAAM,WAAW,OAAO,aAAa,IAAI,UAAU;CAGnD,MAAM,MAAM,IAAI,UAAU;EAAE;EAAQ,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;CAAG,CAAC;CAGvE,MAAM,UAAU,EAAE,UAAU;CAC5B,MAAM,MAAM,eAAe,WAAW,UAAU;CAEhD,OAAO;EACN,MAAM,QAAQ,WAAW;GACxB,MAAM,UAAU,MAAM,IAAI,KACzB,IAAI,uBAAuB;IAC1B,OAAO;IACP,SAAS;IACT,mBAAmB;GACpB,CAAC,CACF;GACA,MAAM,UAAU,OAAO,KAAK,QAAQ,cAAe;GACnD,MAAM,SAAS,KACd,OAAO,KAAK,QAAQ,SAAU,GAC9B,OAAO,KAAK,WAAW,MAAM,GAC7B,GACD;GAEA,MAAM,SAAS,OAAO,MAAM,CAAC;GAC7B,OAAO,cAAc,QAAQ,MAAM;GACnC,OAAO,iBACN,YACA,OAAO,OAAO;IAAC;IAAQ;IAAS;GAAM,CAAC,CACxC;EACD;EAEA,MAAM,QAAQ,YAAY;GACzB,MAAM,EAAE,YAAY,gBAAgB,WAAW,UAAU;GACzD,MAAM,SAAS,QAAQ,UAAU,IAAI,QAAQ,aAAa,CAAC,IAAI;GAC/D,MAAM,UAAU,QAAQ,SAAS,GAAG,IAAI,MAAM;GAC9C,IAAI,CAAC,UAAU,QAAQ,WAAW,QACjC,MAAM,IAAI,uBAAuB,SAAS;GAG3C,MAAM,UAAU,MAAM,IAAI,KACzB,IAAI,eAAe;IAClB,gBAAgB;IAChB,mBAAmB;GACpB,CAAC,CACF;GACA,MAAM,YAAY,KACjB,OAAO,KAAK,QAAQ,SAAU,GAC9B,QAAQ,SAAS,IAAI,MAAM,GAC3B,GACD;GACA,IAAI,CAAC,WAAW,MAAM,IAAI,uBAAuB,SAAS;GAE1D,OAAO,UAAU,SAAS,MAAM;EACjC;EAEA,MAAM,MAAM,OAAO;GAClB,MAAM,EAAE,QAAQ,MAAM,IAAI,KACzB,IAAI,mBAAmB;IACtB,OAAO;IACP,cAAc;IACd,SAAS,OAAO,KAAK,OAAO,MAAM;GACnC,CAAC,CACF;GACA,OAAO,OAAO,KAAK,GAAI,CAAC,CAAC,SAAS,WAAW;EAC9C;EAIA,MAAM,UAAU,YAAY;GAC3B,gBAAgB,WAAW,UAAU;GACrC,OAAO;EACR;CACD;AACD"}
|