@stryke/crypto 0.5.14 → 0.5.22

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +232 -0
  2. package/README.md +31 -25
  3. package/dist/{base-64.d.ts → base-64-B1YDs-zl.d.cts} +8 -4
  4. package/dist/base-64-B1YDs-zl.d.cts.map +1 -0
  5. package/dist/base-64-Bh0chPX9.cjs +1 -0
  6. package/dist/base-64-D3iUgxLe.d.mts +40 -0
  7. package/dist/base-64-D3iUgxLe.d.mts.map +1 -0
  8. package/dist/base-64-n6I9tGzK.mjs +2 -0
  9. package/dist/base-64-n6I9tGzK.mjs.map +1 -0
  10. package/dist/base-64.cjs +1 -79
  11. package/dist/base-64.d.cts +2 -0
  12. package/dist/base-64.d.mts +2 -0
  13. package/dist/base-64.mjs +1 -1
  14. package/dist/encryption-CchoDEon.mjs +2 -0
  15. package/dist/encryption-CchoDEon.mjs.map +1 -0
  16. package/dist/{encryption.d.ts → encryption-Dw19bezD.d.cts} +11 -7
  17. package/dist/encryption-Dw19bezD.d.cts.map +1 -0
  18. package/dist/encryption-HwrvWUAF.cjs +1 -0
  19. package/dist/encryption-yC-pEQ14.d.mts +82 -0
  20. package/dist/encryption-yC-pEQ14.d.mts.map +1 -0
  21. package/dist/encryption.cjs +1 -60
  22. package/dist/encryption.d.cts +2 -0
  23. package/dist/encryption.d.mts +2 -0
  24. package/dist/encryption.mjs +1 -1
  25. package/dist/encryption.node-BLOlwsYV.mjs +2 -0
  26. package/dist/encryption.node-BLOlwsYV.mjs.map +1 -0
  27. package/dist/{encryption.node.d.ts → encryption.node-CyYXMEWi.d.cts} +11 -5
  28. package/dist/encryption.node-CyYXMEWi.d.cts.map +1 -0
  29. package/dist/encryption.node-DCO-i6QP.cjs +1 -0
  30. package/dist/encryption.node-pNNijU1t.d.mts +42 -0
  31. package/dist/encryption.node-pNNijU1t.d.mts.map +1 -0
  32. package/dist/encryption.node.cjs +1 -34
  33. package/dist/encryption.node.d.cts +2 -0
  34. package/dist/encryption.node.d.mts +2 -0
  35. package/dist/encryption.node.mjs +1 -1
  36. package/dist/{hex.d.ts → hex-BaOs3VLq.d.cts} +6 -2
  37. package/dist/hex-BaOs3VLq.d.cts.map +1 -0
  38. package/dist/hex-C1p5VuEv.mjs +2 -0
  39. package/dist/hex-C1p5VuEv.mjs.map +1 -0
  40. package/dist/hex-CDXtL048.cjs +1 -0
  41. package/dist/hex-eot11JTh.d.mts +18 -0
  42. package/dist/hex-eot11JTh.d.mts.map +1 -0
  43. package/dist/hex.cjs +1 -47
  44. package/dist/hex.d.cts +2 -0
  45. package/dist/hex.d.mts +2 -0
  46. package/dist/hex.mjs +1 -1
  47. package/dist/index.cjs +1 -38
  48. package/dist/index.d.cts +4 -0
  49. package/dist/index.d.mts +4 -0
  50. package/dist/index.mjs +1 -1
  51. package/dist/neutral.cjs +1 -38
  52. package/dist/neutral.d.cts +4 -0
  53. package/dist/neutral.d.mts +4 -0
  54. package/dist/neutral.mjs +1 -1
  55. package/package.json +24 -125
  56. package/dist/index.d.ts +0 -3
  57. package/dist/neutral.d.ts +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-CchoDEon.mjs","names":[],"sources":["../src/encryption.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n base64StringToUint8Array,\n concatUint8Array,\n stringToUtf8Array,\n uint8ArrayToString,\n utf8ArrayToString\n} from \"@stryke/convert/neutral\";\nimport { decodeBase64, encodeBase64 } from \"./base-64\";\nimport { decodeHex, encodeHex } from \"./hex\";\n\n/**\n * Creates a CryptoKey object that can be used to encrypt any string.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey\n *\n * @returns A promise that resolves to a CryptoKey object that can be used to encrypt and decrypt strings.\n */\nexport async function createKey(): Promise<CryptoKey> {\n return crypto.subtle.generateKey(\n {\n name: \"AES-GCM\",\n length: 256\n },\n true,\n [\"encrypt\", \"decrypt\"]\n );\n}\n\n/**\n * Encodes a CryptoKey to base64 string, so that it can be embedded in JSON / JavaScript\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/exportKey\n *\n * @param key - The CryptoKey to encode\n * @returns A promise that resolves to a base64 string representing the key\n */\nexport async function encodeKey(key: CryptoKey): Promise<string> {\n const exported = await crypto.subtle.exportKey(\"raw\", key);\n\n return encodeBase64(new Uint8Array(exported)).toString();\n}\n\n/**\n * Decodes a base64 string into bytes and then imports the key.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey\n *\n * @param encoded - The base64 encoded key\n * @returns A promise that resolves to a CryptoKey object that can be used to encrypt and decrypt strings\n */\nexport async function decodeKey(encoded: string): Promise<CryptoKey> {\n const bytes = decodeBase64(encoded);\n\n return crypto.subtle.importKey(\n \"raw\",\n bytes.buffer as ArrayBuffer,\n \"AES-GCM\",\n true,\n [\"encrypt\", \"decrypt\"]\n );\n}\n\n// The length of the initialization vector\n// See https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams\nconst IV_LENGTH = 24;\n\n/**\n * Using a CryptoKey, use AES-GCM to encrypt a string into a base64 string.\n *\n * @remarks\n * The initialization vector is randomly generated and prepended to the encrypted string. The IV is required for decryption, so it must be stored alongside the encrypted data.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt\n *\n * @param key - The CryptoKey to use for encryption\n * @param plaintext - The plaintext string to encrypt\n * @returns A promise that resolves to a base64 string representing the encrypted data\n */\nexport async function encrypt(\n key: CryptoKey,\n plaintext: string\n): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH / 2));\n const encrypted = await crypto.subtle.encrypt(\n {\n name: \"AES-GCM\",\n iv: iv as Uint8Array<ArrayBuffer>\n },\n key,\n stringToUtf8Array(plaintext) as BufferSource\n );\n\n // iv is 12, hex brings it to 24\n return encodeHex(iv) + encodeBase64(new Uint8Array(encrypted));\n}\n\n/**\n * Takes a base64 encoded string, decodes it and returns the AES-GCM decrypted text.\n *\n * @remarks\n * The initialization vector is expected to be prepended to the encrypted string. The IV is required for decryption, so it must be extracted from the start of the string.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/decrypt\n *\n * @param key - The CryptoKey to use for decryption\n * @param encrypted - The encrypted base64 encoded string to decrypt\n * @returns A promise that resolves to the decrypted string\n */\nexport async function decrypt(\n key: CryptoKey,\n encrypted: string\n): Promise<string> {\n const decrypted = await crypto.subtle.decrypt(\n {\n name: \"AES-GCM\",\n iv: decodeHex(encrypted.slice(0, IV_LENGTH)) as Uint8Array<ArrayBuffer>\n },\n key,\n decodeBase64(encrypted.slice(IV_LENGTH)) as BufferSource\n );\n\n return utf8ArrayToString(decrypted);\n}\n\n/**\n * Encrypts a buffer using AES-GCM with a given CryptoKey.\n *\n * @remarks\n * The initialization vector (IV) is randomly generated and prepended to the encrypted data. The resulting data is then encoded as a base64 string for easy storage/transmission.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt\n *\n * @param key - The CryptoKey to use for encryption\n * @param buffer - The buffer to encrypt\n * @returns A promise that resolves to a base64 string representing the encrypted data\n */\nexport async function encryptBuffer(\n key: CryptoKey,\n buffer: BufferSource\n): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(16));\n const encrypted = await crypto.subtle.encrypt(\n {\n name: \"AES-GCM\",\n iv\n },\n key,\n buffer\n );\n\n return uint8ArrayToString(concatUint8Array([iv, new Uint8Array(encrypted)]));\n}\n\n/**\n * Decrypts a buffer using AES-GCM with a given CryptoKey.\n *\n * @remarks\n * The initialization vector (IV) is expected to be prepended to the encrypted data. The IV is required for decryption, so it must be extracted from the start of the buffer.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/decrypt\n *\n * @param key - The CryptoKey to use for decryption\n * @param encrypted - The encrypted base64 encoded string to decrypt\n * @returns A promise that resolves to the decrypted string\n */\nexport async function decryptBuffer(\n key: CryptoKey,\n encrypted: string\n): Promise<ArrayBuffer> {\n const concatenated = base64StringToUint8Array(encrypted);\n\n return crypto.subtle.decrypt(\n {\n name: \"AES-GCM\",\n iv: concatenated.slice(0, 16)\n },\n key,\n concatenated.slice(16)\n );\n}\n"],"mappings":"mIAmCA,eAAsB,GAAgC,CACpD,OAAO,OAAO,OAAO,YACnB,CACE,KAAM,UACN,OAAQ,IACT,CACD,GACA,CAAC,UAAW,UAAU,CACvB,CAWH,eAAsB,EAAU,EAAiC,CAC/D,IAAM,EAAW,MAAM,OAAO,OAAO,UAAU,MAAO,EAAI,CAE1D,OAAO,EAAa,IAAI,WAAW,EAAS,CAAC,CAAC,UAAU,CAW1D,eAAsB,EAAU,EAAqC,CACnE,IAAM,EAAQ,EAAa,EAAQ,CAEnC,OAAO,OAAO,OAAO,UACnB,MACA,EAAM,OACN,UACA,GACA,CAAC,UAAW,UAAU,CACvB,CAmBH,eAAsB,EACpB,EACA,EACiB,CACjB,IAAM,EAAK,OAAO,gBAAgB,IAAI,WAAW,GAAY,EAAE,CAAC,CAC1D,EAAY,MAAM,OAAO,OAAO,QACpC,CACE,KAAM,UACF,KACL,CACD,EACA,EAAkB,EAAU,CAC7B,CAGD,OAAO,EAAU,EAAG,CAAG,EAAa,IAAI,WAAW,EAAU,CAAC,CAehE,eAAsB,EACpB,EACA,EACiB,CAUjB,OAAO,EATW,MAAM,OAAO,OAAO,QACpC,CACE,KAAM,UACN,GAAI,EAAU,EAAU,MAAM,EAAG,GAAU,CAAC,CAC7C,CACD,EACA,EAAa,EAAU,MAAM,GAAU,CAAC,CACzC,CAEkC,CAerC,eAAsB,EACpB,EACA,EACiB,CACjB,IAAM,EAAK,OAAO,gBAAgB,IAAI,WAAW,GAAG,CAAC,CAC/C,EAAY,MAAM,OAAO,OAAO,QACpC,CACE,KAAM,UACN,KACD,CACD,EACA,EACD,CAED,OAAO,EAAmB,EAAiB,CAAC,EAAI,IAAI,WAAW,EAAU,CAAC,CAAC,CAAC,CAe9E,eAAsB,EACpB,EACA,EACsB,CACtB,IAAM,EAAe,EAAyB,EAAU,CAExD,OAAO,OAAO,OAAO,QACnB,CACE,KAAM,UACN,GAAI,EAAa,MAAM,EAAG,GAAG,CAC9B,CACD,EACA,EAAa,MAAM,GAAG,CACvB"}
@@ -1,3 +1,4 @@
1
+ //#region src/encryption.d.ts
1
2
  /**
2
3
  * Creates a CryptoKey object that can be used to encrypt any string.
3
4
  *
@@ -5,7 +6,7 @@
5
6
  *
6
7
  * @returns A promise that resolves to a CryptoKey object that can be used to encrypt and decrypt strings.
7
8
  */
8
- export declare function createKey(): Promise<CryptoKey>;
9
+ declare function createKey(): Promise<CryptoKey>;
9
10
  /**
10
11
  * Encodes a CryptoKey to base64 string, so that it can be embedded in JSON / JavaScript
11
12
  *
@@ -14,7 +15,7 @@ export declare function createKey(): Promise<CryptoKey>;
14
15
  * @param key - The CryptoKey to encode
15
16
  * @returns A promise that resolves to a base64 string representing the key
16
17
  */
17
- export declare function encodeKey(key: CryptoKey): Promise<string>;
18
+ declare function encodeKey(key: CryptoKey): Promise<string>;
18
19
  /**
19
20
  * Decodes a base64 string into bytes and then imports the key.
20
21
  *
@@ -23,7 +24,7 @@ export declare function encodeKey(key: CryptoKey): Promise<string>;
23
24
  * @param encoded - The base64 encoded key
24
25
  * @returns A promise that resolves to a CryptoKey object that can be used to encrypt and decrypt strings
25
26
  */
26
- export declare function decodeKey(encoded: string): Promise<CryptoKey>;
27
+ declare function decodeKey(encoded: string): Promise<CryptoKey>;
27
28
  /**
28
29
  * Using a CryptoKey, use AES-GCM to encrypt a string into a base64 string.
29
30
  *
@@ -36,7 +37,7 @@ export declare function decodeKey(encoded: string): Promise<CryptoKey>;
36
37
  * @param plaintext - The plaintext string to encrypt
37
38
  * @returns A promise that resolves to a base64 string representing the encrypted data
38
39
  */
39
- export declare function encrypt(key: CryptoKey, plaintext: string): Promise<string>;
40
+ declare function encrypt(key: CryptoKey, plaintext: string): Promise<string>;
40
41
  /**
41
42
  * Takes a base64 encoded string, decodes it and returns the AES-GCM decrypted text.
42
43
  *
@@ -49,7 +50,7 @@ export declare function encrypt(key: CryptoKey, plaintext: string): Promise<stri
49
50
  * @param encrypted - The encrypted base64 encoded string to decrypt
50
51
  * @returns A promise that resolves to the decrypted string
51
52
  */
52
- export declare function decrypt(key: CryptoKey, encrypted: string): Promise<string>;
53
+ declare function decrypt(key: CryptoKey, encrypted: string): Promise<string>;
53
54
  /**
54
55
  * Encrypts a buffer using AES-GCM with a given CryptoKey.
55
56
  *
@@ -62,7 +63,7 @@ export declare function decrypt(key: CryptoKey, encrypted: string): Promise<stri
62
63
  * @param buffer - The buffer to encrypt
63
64
  * @returns A promise that resolves to a base64 string representing the encrypted data
64
65
  */
65
- export declare function encryptBuffer(key: CryptoKey, buffer: BufferSource): Promise<string>;
66
+ declare function encryptBuffer(key: CryptoKey, buffer: BufferSource): Promise<string>;
66
67
  /**
67
68
  * Decrypts a buffer using AES-GCM with a given CryptoKey.
68
69
  *
@@ -75,4 +76,7 @@ export declare function encryptBuffer(key: CryptoKey, buffer: BufferSource): Pro
75
76
  * @param encrypted - The encrypted base64 encoded string to decrypt
76
77
  * @returns A promise that resolves to the decrypted string
77
78
  */
78
- export declare function decryptBuffer(key: CryptoKey, encrypted: string): Promise<ArrayBuffer>;
79
+ declare function decryptBuffer(key: CryptoKey, encrypted: string): Promise<ArrayBuffer>;
80
+ //#endregion
81
+ export { encodeKey as a, decryptBuffer as i, decodeKey as n, encrypt as o, decrypt as r, encryptBuffer as s, createKey as t };
82
+ //# sourceMappingURL=encryption-Dw19bezD.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-Dw19bezD.d.cts","names":[],"sources":["../src/encryption.ts"],"sourcesContent":[],"mappings":";;AAmCA;AAmBA;AAcA;AA4BA;AA8BA;AA4BA;AACO,iBAxHe,SAAA,CAAA,CAwHf,EAxH4B,OAwH5B,CAxHoC,SAwHpC,CAAA;;;;AA4BP;;;;;iBAjIsB,SAAA,MAAe,YAAY;;;;;;;;;iBAc3B,SAAA,mBAA4B,QAAQ;;;;;;;;;;;;;iBA4BpC,OAAA,MACf,+BAEJ;;;;;;;;;;;;;iBA2BmB,OAAA,MACf,+BAEJ;;;;;;;;;;;;;iBAyBmB,aAAA,MACf,mBACG,eACP;;;;;;;;;;;;;iBA0BmB,aAAA,MACf,+BAEJ,QAAQ"}
@@ -0,0 +1 @@
1
+ const e=require(`./base-64-Bh0chPX9.cjs`),t=require(`./hex-CDXtL048.cjs`);async function n(){return crypto.subtle.generateKey({name:`AES-GCM`,length:256},!0,[`encrypt`,`decrypt`])}async function r(t){let n=await crypto.subtle.exportKey(`raw`,t);return e.i(new Uint8Array(n)).toString()}async function i(t){let n=e.r(t);return crypto.subtle.importKey(`raw`,n.buffer,`AES-GCM`,!0,[`encrypt`,`decrypt`])}const a=24;async function o(n,r){let i=crypto.getRandomValues(new Uint8Array(24/2)),a=await crypto.subtle.encrypt({name:`AES-GCM`,iv:i},n,e.c(r));return t.n(i)+e.i(new Uint8Array(a))}async function s(n,r){return e.a(await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.t(r.slice(0,24))},n,e.r(r.slice(24))))}async function c(t,n){let r=crypto.getRandomValues(new Uint8Array(16)),i=await crypto.subtle.encrypt({name:`AES-GCM`,iv:r},t,n);return e.o(e.s([r,new Uint8Array(i)]))}async function l(t,n){let r=e.l(n);return crypto.subtle.decrypt({name:`AES-GCM`,iv:r.slice(0,16)},t,r.slice(16))}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
@@ -0,0 +1,82 @@
1
+ //#region src/encryption.d.ts
2
+ /**
3
+ * Creates a CryptoKey object that can be used to encrypt any string.
4
+ *
5
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
6
+ *
7
+ * @returns A promise that resolves to a CryptoKey object that can be used to encrypt and decrypt strings.
8
+ */
9
+ declare function createKey(): Promise<CryptoKey>;
10
+ /**
11
+ * Encodes a CryptoKey to base64 string, so that it can be embedded in JSON / JavaScript
12
+ *
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/exportKey
14
+ *
15
+ * @param key - The CryptoKey to encode
16
+ * @returns A promise that resolves to a base64 string representing the key
17
+ */
18
+ declare function encodeKey(key: CryptoKey): Promise<string>;
19
+ /**
20
+ * Decodes a base64 string into bytes and then imports the key.
21
+ *
22
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
23
+ *
24
+ * @param encoded - The base64 encoded key
25
+ * @returns A promise that resolves to a CryptoKey object that can be used to encrypt and decrypt strings
26
+ */
27
+ declare function decodeKey(encoded: string): Promise<CryptoKey>;
28
+ /**
29
+ * Using a CryptoKey, use AES-GCM to encrypt a string into a base64 string.
30
+ *
31
+ * @remarks
32
+ * The initialization vector is randomly generated and prepended to the encrypted string. The IV is required for decryption, so it must be stored alongside the encrypted data.
33
+ *
34
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt
35
+ *
36
+ * @param key - The CryptoKey to use for encryption
37
+ * @param plaintext - The plaintext string to encrypt
38
+ * @returns A promise that resolves to a base64 string representing the encrypted data
39
+ */
40
+ declare function encrypt(key: CryptoKey, plaintext: string): Promise<string>;
41
+ /**
42
+ * Takes a base64 encoded string, decodes it and returns the AES-GCM decrypted text.
43
+ *
44
+ * @remarks
45
+ * The initialization vector is expected to be prepended to the encrypted string. The IV is required for decryption, so it must be extracted from the start of the string.
46
+ *
47
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/decrypt
48
+ *
49
+ * @param key - The CryptoKey to use for decryption
50
+ * @param encrypted - The encrypted base64 encoded string to decrypt
51
+ * @returns A promise that resolves to the decrypted string
52
+ */
53
+ declare function decrypt(key: CryptoKey, encrypted: string): Promise<string>;
54
+ /**
55
+ * Encrypts a buffer using AES-GCM with a given CryptoKey.
56
+ *
57
+ * @remarks
58
+ * The initialization vector (IV) is randomly generated and prepended to the encrypted data. The resulting data is then encoded as a base64 string for easy storage/transmission.
59
+ *
60
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt
61
+ *
62
+ * @param key - The CryptoKey to use for encryption
63
+ * @param buffer - The buffer to encrypt
64
+ * @returns A promise that resolves to a base64 string representing the encrypted data
65
+ */
66
+ declare function encryptBuffer(key: CryptoKey, buffer: BufferSource): Promise<string>;
67
+ /**
68
+ * Decrypts a buffer using AES-GCM with a given CryptoKey.
69
+ *
70
+ * @remarks
71
+ * The initialization vector (IV) is expected to be prepended to the encrypted data. The IV is required for decryption, so it must be extracted from the start of the buffer.
72
+ *
73
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/decrypt
74
+ *
75
+ * @param key - The CryptoKey to use for decryption
76
+ * @param encrypted - The encrypted base64 encoded string to decrypt
77
+ * @returns A promise that resolves to the decrypted string
78
+ */
79
+ declare function decryptBuffer(key: CryptoKey, encrypted: string): Promise<ArrayBuffer>;
80
+ //#endregion
81
+ export { encodeKey as a, decryptBuffer as i, decodeKey as n, encrypt as o, decrypt as r, encryptBuffer as s, createKey as t };
82
+ //# sourceMappingURL=encryption-yC-pEQ14.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-yC-pEQ14.d.mts","names":[],"sources":["../src/encryption.ts"],"sourcesContent":[],"mappings":";;AAmCA;AAmBA;AAcA;AA4BA;AA8BA;AA4BA;AACO,iBAxHe,SAAA,CAAA,CAwHf,EAxH4B,OAwH5B,CAxHoC,SAwHpC,CAAA;;;;AA4BP;;;;;iBAjIsB,SAAA,MAAe,YAAY;;;;;;;;;iBAc3B,SAAA,mBAA4B,QAAQ;;;;;;;;;;;;;iBA4BpC,OAAA,MACf,+BAEJ;;;;;;;;;;;;;iBA2BmB,OAAA,MACf,+BAEJ;;;;;;;;;;;;;iBAyBmB,aAAA,MACf,mBACG,eACP;;;;;;;;;;;;;iBA0BmB,aAAA,MACf,+BAEJ,QAAQ"}
@@ -1,60 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createKey = createKey;
7
- exports.decodeKey = decodeKey;
8
- exports.decrypt = decrypt;
9
- exports.decryptBuffer = decryptBuffer;
10
- exports.encodeKey = encodeKey;
11
- exports.encrypt = encrypt;
12
- exports.encryptBuffer = encryptBuffer;
13
- var _neutral = require("@stryke/convert/neutral");
14
- var _base = require("./base-64.cjs");
15
- var _hex = require("./hex.cjs");
16
- async function createKey() {
17
- return crypto.subtle.generateKey({
18
- name: "AES-GCM",
19
- length: 256
20
- }, !0, ["encrypt", "decrypt"]);
21
- }
22
- async function encodeKey(e) {
23
- const r = await crypto.subtle.exportKey("raw", e);
24
- return (0, _base.encodeBase64)(new Uint8Array(r)).toString();
25
- }
26
- async function decodeKey(e) {
27
- const r = (0, _base.decodeBase64)(e);
28
- return crypto.subtle.importKey("raw", r.buffer, "AES-GCM", !0, ["encrypt", "decrypt"]);
29
- }
30
- const o = 24;
31
- async function encrypt(e, r) {
32
- const t = crypto.getRandomValues(new Uint8Array(o / 2)),
33
- n = await crypto.subtle.encrypt({
34
- name: "AES-GCM",
35
- iv: t
36
- }, e, (0, _neutral.stringToUtf8Array)(r));
37
- return (0, _hex.encodeHex)(t) + (0, _base.encodeBase64)(new Uint8Array(n));
38
- }
39
- async function decrypt(e, r) {
40
- const t = await crypto.subtle.decrypt({
41
- name: "AES-GCM",
42
- iv: (0, _hex.decodeHex)(r.slice(0, o))
43
- }, e, (0, _base.decodeBase64)(r.slice(o)));
44
- return (0, _neutral.utf8ArrayToString)(t);
45
- }
46
- async function encryptBuffer(e, r) {
47
- const t = crypto.getRandomValues(new Uint8Array(16)),
48
- n = await crypto.subtle.encrypt({
49
- name: "AES-GCM",
50
- iv: t
51
- }, e, r);
52
- return (0, _neutral.uint8ArrayToString)((0, _neutral.concatUint8Array)([t, new Uint8Array(n)]));
53
- }
54
- async function decryptBuffer(e, r) {
55
- const t = (0, _neutral.base64StringToUint8Array)(r);
56
- return crypto.subtle.decrypt({
57
- name: "AES-GCM",
58
- iv: t.slice(0, 16)
59
- }, e, t.slice(16));
60
- }
1
+ require(`./base-64-Bh0chPX9.cjs`);const e=require(`./encryption-HwrvWUAF.cjs`);exports.createKey=e.t,exports.decodeKey=e.n,exports.decrypt=e.r,exports.decryptBuffer=e.i,exports.encodeKey=e.a,exports.encrypt=e.o,exports.encryptBuffer=e.s;
@@ -0,0 +1,2 @@
1
+ import { a as encodeKey, i as decryptBuffer, n as decodeKey, o as encrypt, r as decrypt, s as encryptBuffer, t as createKey } from "./encryption-Dw19bezD.cjs";
2
+ export { createKey, decodeKey, decrypt, decryptBuffer, encodeKey, encrypt, encryptBuffer };
@@ -0,0 +1,2 @@
1
+ import { a as encodeKey, i as decryptBuffer, n as decodeKey, o as encrypt, r as decrypt, s as encryptBuffer, t as createKey } from "./encryption-yC-pEQ14.mjs";
2
+ export { createKey, decodeKey, decrypt, decryptBuffer, encodeKey, encrypt, encryptBuffer };
@@ -1 +1 @@
1
- import{base64StringToUint8Array as i,concatUint8Array as s,stringToUtf8Array as a,uint8ArrayToString as p,utf8ArrayToString as u}from"@stryke/convert/neutral";import{decodeBase64 as y,encodeBase64 as c}from"./base-64";import{decodeHex as f,encodeHex as d}from"./hex";export async function createKey(){return crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}export async function encodeKey(e){const r=await crypto.subtle.exportKey("raw",e);return c(new Uint8Array(r)).toString()}export async function decodeKey(e){const r=y(e);return crypto.subtle.importKey("raw",r.buffer,"AES-GCM",!0,["encrypt","decrypt"])}const o=24;export async function encrypt(e,r){const t=crypto.getRandomValues(new Uint8Array(o/2)),n=await crypto.subtle.encrypt({name:"AES-GCM",iv:t},e,a(r));return d(t)+c(new Uint8Array(n))}export async function decrypt(e,r){const t=await crypto.subtle.decrypt({name:"AES-GCM",iv:f(r.slice(0,o))},e,y(r.slice(o)));return u(t)}export async function encryptBuffer(e,r){const t=crypto.getRandomValues(new Uint8Array(16)),n=await crypto.subtle.encrypt({name:"AES-GCM",iv:t},e,r);return p(s([t,new Uint8Array(n)]))}export async function decryptBuffer(e,r){const t=i(r);return crypto.subtle.decrypt({name:"AES-GCM",iv:t.slice(0,16)},e,t.slice(16))}
1
+ import"./base-64-n6I9tGzK.mjs";import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"./encryption-CchoDEon.mjs";export{o as createKey,n as decodeKey,i as decrypt,t as decryptBuffer,e as encodeKey,r as encrypt,a as encryptBuffer};
@@ -0,0 +1,2 @@
1
+ import{Buffer as e}from"node:buffer";import{createCipheriv as t,createDecipheriv as n,createSecretKey as r,pbkdf2Sync as i,randomBytes as a}from"node:crypto";const o=`chacha20-poly1305`,s=1e5;function c(e,t){return typeof e==`string`?r(e,t):r(e)}function l(n,r){let c=i(n,a(64),s,32,`sha512`),l=a(16),u=a(64),d=t(o,c,a(16)),f=e.concat([d.update(r,`utf8`),d.final()]),p=d.getAuthTag();return e.concat([u,l,p,f]).toString(`hex`)}function u(t,r){let a=e.from(r,`hex`),c=n(o,i(t,a.slice(0,64),s,32,`sha512`),a.slice(64,80));return c.setAuthTag(a.slice(80,96)),c.update(a.slice(96))+c.final(`utf8`)}export{u as n,l as r,c as t};
2
+ //# sourceMappingURL=encryption.node-BLOlwsYV.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.node-BLOlwsYV.mjs","names":[],"sources":["../src/encryption.node.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Buffer } from \"node:buffer\";\nimport type { BinaryLike, KeyObject } from \"node:crypto\";\nimport {\n createCipheriv,\n createDecipheriv,\n createSecretKey,\n pbkdf2Sync,\n randomBytes\n} from \"node:crypto\";\n\n// Background:\n// https://security.stackexchange.com/questions/184305/why-would-i-ever-use-aes-256-cbc-if-aes-256-gcm-is-more-secure\n\nconst CIPHER_ALGORITHM = \"chacha20-poly1305\";\nconst CIPHER_KEY_LENGTH = 32; // https://stackoverflow.com/a/28307668/4397028\nconst CIPHER_IV_LENGTH = 16; // https://stackoverflow.com/a/28307668/4397028\nconst CIPHER_TAG_LENGTH = 16;\nconst CIPHER_SALT_LENGTH = 64;\n\nconst PBKDF2_ITERATIONS = 100_000; // https://support.1password.com/pbkdf2/\n\n/**\n * Creates and returns a new key object containing a secret key for symmetric encryption or \\`Hmac\\`.\n *\n * @param key - The key to use when creating the \\`KeyObject\\`.\n * @returns The new \\`KeyObject\\`.\n */\nexport function createKey(key: NodeJS.ArrayBufferView): KeyObject;\n\n/**\n * Creates and returns a new key object containing a secret key for symmetric encryption or \\`Hmac\\`.\n *\n * @param key - The key to use. If \\`key\\` is a \\`Buffer\\`, \\`TypedArray\\`, or \\`DataView\\`, the \\`encoding\\` argument is ignored.\n * @param encoding - The \\`encoding\\` of the \\`key\\` string. Must be one of \\`'utf8'\\`, \\`'utf16le'\\`, \\`'latin1'\\`, or \\`'base64'\\`. Default is \\`'utf8'\\`.\n * @returns The new \\`KeyObject\\`.\n */\nexport function createKey(key: string, encoding: BufferEncoding): KeyObject;\n\n/**\n * Creates and returns a new key object containing a secret key for symmetric encryption or \\`Hmac\\`.\n *\n * @param key - The key to use. If \\`key\\` is a \\`Buffer\\`, \\`TypedArray\\`, or \\`DataView\\`, the \\`encoding\\` argument is ignored.\n * @param encoding - The \\`encoding\\` of the \\`key\\` string. Must be one of \\`'utf8'\\`, \\`'utf16le'\\`, \\`'latin1'\\`, or \\`'base64'\\`. Default is \\`'utf8'\\`.\n * @returns The new \\`KeyObject\\`.\n */\nexport function createKey(\n key: string | NodeJS.ArrayBufferView,\n encoding?: BufferEncoding\n): KeyObject {\n return typeof key === \"string\"\n ? createSecretKey(key, encoding!)\n : createSecretKey(key);\n}\n\n/**\n * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param secret - The secret key used for encryption.\n * @param plaintext - The data to encrypt.\n * @returns The encrypted data.\n */\nexport function encrypt(secret: BinaryLike, plaintext: string): string {\n // https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2sync_password_salt_iterations_keylen_digest\n const key = pbkdf2Sync(\n secret,\n randomBytes(CIPHER_SALT_LENGTH),\n PBKDF2_ITERATIONS,\n CIPHER_KEY_LENGTH,\n \"sha512\"\n );\n\n const iv = randomBytes(CIPHER_IV_LENGTH);\n const salt = randomBytes(CIPHER_SALT_LENGTH);\n\n const cipher = createCipheriv(\n CIPHER_ALGORITHM,\n key,\n randomBytes(CIPHER_IV_LENGTH)\n );\n const encrypted = Buffer.concat([\n cipher.update(plaintext, \"utf8\"),\n cipher.final()\n ]);\n\n // https://nodejs.org/api/crypto.html#crypto_cipher_getauthtag\n const tag = cipher.getAuthTag();\n\n return Buffer.concat([\n // Data as required by: https://nodejs.org/api/crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv_options\n salt, // Salt for Key: https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2sync_password_salt_iterations_keylen_digest\n iv, // IV: https://nodejs.org/api/crypto.html#crypto_class_decipher\n tag, // Tag: https://nodejs.org/api/crypto.html#crypto_decipher_setauthtag_buffer\n encrypted\n ]).toString(\"hex\");\n}\n\n/**\n * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.\n *\n * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305\n *\n * @param secret - The secret key used for decryption.\n * @param encrypted - The encrypted data to decrypt.\n * @returns The decrypted data.\n */\nexport function decrypt(secret: BinaryLike, encrypted: string): string {\n const buffer = Buffer.from(encrypted, \"hex\");\n\n // https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2sync_password_salt_iterations_keylen_digest\n const key = pbkdf2Sync(\n secret,\n buffer.slice(0, CIPHER_SALT_LENGTH),\n PBKDF2_ITERATIONS,\n CIPHER_KEY_LENGTH,\n \"sha512\"\n );\n\n const decipher = createDecipheriv(\n CIPHER_ALGORITHM,\n key,\n buffer.slice(CIPHER_SALT_LENGTH, CIPHER_SALT_LENGTH + CIPHER_IV_LENGTH)\n );\n decipher.setAuthTag(\n buffer.slice(\n CIPHER_SALT_LENGTH + CIPHER_IV_LENGTH,\n CIPHER_SALT_LENGTH + CIPHER_IV_LENGTH + CIPHER_TAG_LENGTH\n )\n );\n\n return (\n // eslint-disable-next-line ts/restrict-plus-operands\n decipher.update(\n buffer.slice(CIPHER_SALT_LENGTH + CIPHER_IV_LENGTH + CIPHER_TAG_LENGTH)\n ) + decipher.final(\"utf8\")\n );\n}\n"],"mappings":"8JA+BA,MAAM,EAAmB,oBAMnB,EAAoB,IA0B1B,SAAgB,EACd,EACA,EACW,CACX,OAAO,OAAO,GAAQ,SAClB,EAAgB,EAAK,EAAU,CAC/B,EAAgB,EAAI,CAY1B,SAAgB,EAAQ,EAAoB,EAA2B,CAErE,IAAM,EAAM,EACV,EACA,EAAY,GAAmB,CAC/B,EACA,GACA,SACD,CAEK,EAAK,EAAY,GAAiB,CAClC,EAAO,EAAY,GAAmB,CAEtC,EAAS,EACb,EACA,EACA,EAAY,GAAiB,CAC9B,CACK,EAAY,EAAO,OAAO,CAC9B,EAAO,OAAO,EAAW,OAAO,CAChC,EAAO,OAAO,CACf,CAAC,CAGI,EAAM,EAAO,YAAY,CAE/B,OAAO,EAAO,OAAO,CAEnB,EACA,EACA,EACA,EACD,CAAC,CAAC,SAAS,MAAM,CAYpB,SAAgB,EAAQ,EAAoB,EAA2B,CACrE,IAAM,EAAS,EAAO,KAAK,EAAW,MAAM,CAWtC,EAAW,EACf,EATU,EACV,EACA,EAAO,MAAM,EAAG,GAAmB,CACnC,EACA,GACA,SACD,CAKC,EAAO,MAAM,GAAoB,GAAsC,CACxE,CAQD,OAPA,EAAS,WACP,EAAO,MACL,GACA,GACD,CACF,CAIC,EAAS,OACP,EAAO,MAAM,GAA0D,CACxE,CAAG,EAAS,MAAM,OAAO"}
@@ -1,11 +1,14 @@
1
- import type { BinaryLike, KeyObject } from "node:crypto";
1
+ import { BinaryLike, KeyObject } from "node:crypto";
2
+
3
+ //#region src/encryption.node.d.ts
4
+
2
5
  /**
3
6
  * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
4
7
  *
5
8
  * @param key - The key to use when creating the \`KeyObject\`.
6
9
  * @returns The new \`KeyObject\`.
7
10
  */
8
- export declare function createKey(key: NodeJS.ArrayBufferView): KeyObject;
11
+ declare function createKey(key: NodeJS.ArrayBufferView): KeyObject;
9
12
  /**
10
13
  * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
11
14
  *
@@ -13,7 +16,7 @@ export declare function createKey(key: NodeJS.ArrayBufferView): KeyObject;
13
16
  * @param encoding - The \`encoding\` of the \`key\` string. Must be one of \`'utf8'\`, \`'utf16le'\`, \`'latin1'\`, or \`'base64'\`. Default is \`'utf8'\`.
14
17
  * @returns The new \`KeyObject\`.
15
18
  */
16
- export declare function createKey(key: string, encoding: BufferEncoding): KeyObject;
19
+ declare function createKey(key: string, encoding: BufferEncoding): KeyObject;
17
20
  /**
18
21
  * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
19
22
  *
@@ -23,7 +26,7 @@ export declare function createKey(key: string, encoding: BufferEncoding): KeyObj
23
26
  * @param plaintext - The data to encrypt.
24
27
  * @returns The encrypted data.
25
28
  */
26
- export declare function encrypt(secret: BinaryLike, plaintext: string): string;
29
+ declare function encrypt(secret: BinaryLike, plaintext: string): string;
27
30
  /**
28
31
  * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
29
32
  *
@@ -33,4 +36,7 @@ export declare function encrypt(secret: BinaryLike, plaintext: string): string;
33
36
  * @param encrypted - The encrypted data to decrypt.
34
37
  * @returns The decrypted data.
35
38
  */
36
- export declare function decrypt(secret: BinaryLike, encrypted: string): string;
39
+ declare function decrypt(secret: BinaryLike, encrypted: string): string;
40
+ //#endregion
41
+ export { decrypt as n, encrypt as r, createKey as t };
42
+ //# sourceMappingURL=encryption.node-CyYXMEWi.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.node-CyYXMEWi.d.cts","names":[],"sources":["../src/encryption.node.ts"],"sourcesContent":[],"mappings":";;;;;;AA6CA;AASA;AA2BA;AA4CA;iBAhFgB,SAAA,MAAe,MAAA,CAAO,kBAAkB;;;;;;;;iBASxC,SAAA,wBAAiC,iBAAiB;;;;;;;;;;iBA2BlD,OAAA,SAAgB;;;;;;;;;;iBA4ChB,OAAA,SAAgB"}
@@ -0,0 +1 @@
1
+ let e=require(`node:buffer`),t=require(`node:crypto`);const n=`chacha20-poly1305`,r=32,i=16,a=16,o=64,s=1e5;function c(e,n){return typeof e==`string`?(0,t.createSecretKey)(e,n):(0,t.createSecretKey)(e)}function l(r,i){let a=(0,t.pbkdf2Sync)(r,(0,t.randomBytes)(64),s,32,`sha512`),o=(0,t.randomBytes)(16),c=(0,t.randomBytes)(64),l=(0,t.createCipheriv)(n,a,(0,t.randomBytes)(16)),u=e.Buffer.concat([l.update(i,`utf8`),l.final()]),d=l.getAuthTag();return e.Buffer.concat([c,o,d,u]).toString(`hex`)}function u(r,i){let a=e.Buffer.from(i,`hex`),o=(0,t.createDecipheriv)(n,(0,t.pbkdf2Sync)(r,a.slice(0,64),s,32,`sha512`),a.slice(64,80));return o.setAuthTag(a.slice(80,96)),o.update(a.slice(96))+o.final(`utf8`)}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
@@ -0,0 +1,42 @@
1
+ import { BinaryLike, KeyObject } from "node:crypto";
2
+
3
+ //#region src/encryption.node.d.ts
4
+
5
+ /**
6
+ * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
7
+ *
8
+ * @param key - The key to use when creating the \`KeyObject\`.
9
+ * @returns The new \`KeyObject\`.
10
+ */
11
+ declare function createKey(key: NodeJS.ArrayBufferView): KeyObject;
12
+ /**
13
+ * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
14
+ *
15
+ * @param key - The key to use. If \`key\` is a \`Buffer\`, \`TypedArray\`, or \`DataView\`, the \`encoding\` argument is ignored.
16
+ * @param encoding - The \`encoding\` of the \`key\` string. Must be one of \`'utf8'\`, \`'utf16le'\`, \`'latin1'\`, or \`'base64'\`. Default is \`'utf8'\`.
17
+ * @returns The new \`KeyObject\`.
18
+ */
19
+ declare function createKey(key: string, encoding: BufferEncoding): KeyObject;
20
+ /**
21
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
22
+ *
23
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
24
+ *
25
+ * @param secret - The secret key used for encryption.
26
+ * @param plaintext - The data to encrypt.
27
+ * @returns The encrypted data.
28
+ */
29
+ declare function encrypt(secret: BinaryLike, plaintext: string): string;
30
+ /**
31
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
32
+ *
33
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
34
+ *
35
+ * @param secret - The secret key used for decryption.
36
+ * @param encrypted - The encrypted data to decrypt.
37
+ * @returns The decrypted data.
38
+ */
39
+ declare function decrypt(secret: BinaryLike, encrypted: string): string;
40
+ //#endregion
41
+ export { decrypt as n, encrypt as r, createKey as t };
42
+ //# sourceMappingURL=encryption.node-pNNijU1t.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.node-pNNijU1t.d.mts","names":[],"sources":["../src/encryption.node.ts"],"sourcesContent":[],"mappings":";;;;;;AA6CA;AASA;AA2BA;AA4CA;iBAhFgB,SAAA,MAAe,MAAA,CAAO,kBAAkB;;;;;;;;iBASxC,SAAA,wBAAiC,iBAAiB;;;;;;;;;;iBA2BlD,OAAA,SAAgB;;;;;;;;;;iBA4ChB,OAAA,SAAgB"}
@@ -1,34 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createKey = createKey;
7
- exports.decrypt = decrypt;
8
- exports.encrypt = encrypt;
9
- var _nodeBuffer = require("node:buffer");
10
- var _nodeCrypto = require("node:crypto");
11
- const u = "chacha20-poly1305",
12
- g = 32,
13
- n = 16,
14
- d = 16,
15
- e = 64,
16
- E = 1e5;
17
- function createKey(t, c) {
18
- return typeof t == "string" ? (0, _nodeCrypto.createSecretKey)(t, c) : (0, _nodeCrypto.createSecretKey)(t);
19
- }
20
- function encrypt(t, c) {
21
- const r = (0, _nodeCrypto.pbkdf2Sync)(t, (0, _nodeCrypto.randomBytes)(e), E, g, "sha512"),
22
- s = (0, _nodeCrypto.randomBytes)(n),
23
- o = (0, _nodeCrypto.randomBytes)(e),
24
- f = (0, _nodeCrypto.createCipheriv)(u, r, (0, _nodeCrypto.randomBytes)(n)),
25
- h = _nodeBuffer.Buffer.concat([f.update(c, "utf8"), f.final()]),
26
- T = f.getAuthTag();
27
- return _nodeBuffer.Buffer.concat([o, s, T, h]).toString("hex");
28
- }
29
- function decrypt(t, c) {
30
- const r = _nodeBuffer.Buffer.from(c, "hex"),
31
- s = (0, _nodeCrypto.pbkdf2Sync)(t, r.slice(0, e), E, g, "sha512"),
32
- o = (0, _nodeCrypto.createDecipheriv)(u, s, r.slice(e, e + n));
33
- return o.setAuthTag(r.slice(e + n, e + n + d)), o.update(r.slice(e + n + d)) + o.final("utf8");
34
- }
1
+ const e=require(`./encryption.node-DCO-i6QP.cjs`);exports.createKey=e.t,exports.decrypt=e.n,exports.encrypt=e.r;
@@ -0,0 +1,2 @@
1
+ import { n as decrypt, r as encrypt, t as createKey } from "./encryption.node-CyYXMEWi.cjs";
2
+ export { createKey, decrypt, encrypt };
@@ -0,0 +1,2 @@
1
+ import { n as decrypt, r as encrypt, t as createKey } from "./encryption.node-pNNijU1t.mjs";
2
+ export { createKey, decrypt, encrypt };
@@ -1 +1 @@
1
- import{Buffer as a}from"node:buffer";import{createCipheriv as _,createDecipheriv as B,createSecretKey as y,pbkdf2Sync as p,randomBytes as i}from"node:crypto";const u="chacha20-poly1305",g=32,n=16,d=16,e=64,E=1e5;export function createKey(t,c){return typeof t=="string"?y(t,c):y(t)}export function encrypt(t,c){const r=p(t,i(e),E,g,"sha512"),s=i(n),o=i(e),f=_(u,r,i(n)),h=a.concat([f.update(c,"utf8"),f.final()]),T=f.getAuthTag();return a.concat([o,s,T,h]).toString("hex")}export function decrypt(t,c){const r=a.from(c,"hex"),s=p(t,r.slice(0,e),E,g,"sha512"),o=B(u,s,r.slice(e,e+n));return o.setAuthTag(r.slice(e+n,e+n+d)),o.update(r.slice(e+n+d))+o.final("utf8")}
1
+ import{n as e,r as t,t as n}from"./encryption.node-BLOlwsYV.mjs";export{n as createKey,e as decrypt,t as encrypt};
@@ -1,14 +1,18 @@
1
+ //#region src/hex.d.ts
1
2
  /**
2
3
  * Encodes a Uint8Array into a hexadecimal string.
3
4
  *
4
5
  * @param input - The input Uint8Array.
5
6
  * @returns The hexadecimal string.
6
7
  */
7
- export declare function encodeHex(input: Uint8Array): string;
8
+ declare function encodeHex(input: Uint8Array): string;
8
9
  /**
9
10
  * Encodes a Uint8Array into an uppercase hexadecimal string.
10
11
  *
11
12
  * @param input - The input Uint8Array.
12
13
  * @returns The uppercase hexadecimal string.
13
14
  */
14
- export declare function decodeHex(input: string): Uint8Array;
15
+ declare function decodeHex(input: string): Uint8Array;
16
+ //#endregion
17
+ export { encodeHex as n, decodeHex as t };
18
+ //# sourceMappingURL=hex-BaOs3VLq.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-BaOs3VLq.d.cts","names":[],"sources":["../src/hex.ts"],"sourcesContent":[],"mappings":";;AAkDA;AAeA;;;;iBAfgB,SAAA,QAAiB;;;;;;;iBAejB,SAAA,iBAA0B"}
@@ -0,0 +1,2 @@
1
+ const e=`0123456789ABCDEF`,t={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};function n(t){let n=``;for(let r=0;r<t.length;r++)n+=e[t[r]>>4],n+=e[t[r]&15];return n}function r(e){if(e.length%2!=0)throw Error(`Invalid hex string`);let n=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2){if(!(e[r]in t)||!(e[r+1]in t))throw Error(`Invalid character`);n[r/2]|=t[e[r]]<<4,n[r/2]|=t[e[r+1]]}return n}export{n,r as t};
2
+ //# sourceMappingURL=hex-C1p5VuEv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-C1p5VuEv.mjs","names":["DECODE_MAP: Record<string, number>"],"sources":["../src/hex.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nconst ALPHABET = \"0123456789ABCDEF\";\nconst DECODE_MAP: Record<string, number> = {\n \"0\": 0,\n \"1\": 1,\n \"2\": 2,\n \"3\": 3,\n \"4\": 4,\n \"5\": 5,\n \"6\": 6,\n \"7\": 7,\n \"8\": 8,\n \"9\": 9,\n a: 10,\n A: 10,\n b: 11,\n B: 11,\n c: 12,\n C: 12,\n d: 13,\n D: 13,\n e: 14,\n E: 14,\n f: 15,\n F: 15\n};\n\n/**\n * Encodes a Uint8Array into a hexadecimal string.\n *\n * @param input - The input Uint8Array.\n * @returns The hexadecimal string.\n */\nexport function encodeHex(input: Uint8Array): string {\n let result = \"\";\n for (let i = 0; i < input.length; i++) {\n result += ALPHABET[input[i]! >> 4];\n result += ALPHABET[input[i]! & 0x0f];\n }\n return result;\n}\n\n/**\n * Encodes a Uint8Array into an uppercase hexadecimal string.\n *\n * @param input - The input Uint8Array.\n * @returns The uppercase hexadecimal string.\n */\nexport function decodeHex(input: string): Uint8Array {\n if (input.length % 2 !== 0) {\n throw new Error(\"Invalid hex string\");\n }\n const result = new Uint8Array(input.length / 2);\n for (let i = 0; i < input.length; i += 2) {\n if (!(input[i]! in DECODE_MAP)) {\n throw new Error(\"Invalid character\");\n }\n if (!(input[i + 1]! in DECODE_MAP)) {\n throw new Error(\"Invalid character\");\n }\n result[i / 2]! |= DECODE_MAP[input[i]!]! << 4;\n result[i / 2]! |= DECODE_MAP[input[i + 1]!]!;\n }\n return result;\n}\n"],"mappings":"AAkBA,MAAM,EAAW,mBACXA,EAAqC,CACzC,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAK,EACL,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACJ,CAQD,SAAgB,EAAU,EAA2B,CACnD,IAAI,EAAS,GACb,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,GAAU,EAAS,EAAM,IAAO,GAChC,GAAU,EAAS,EAAM,GAAM,IAEjC,OAAO,EAST,SAAgB,EAAU,EAA2B,CACnD,GAAI,EAAM,OAAS,GAAM,EACvB,MAAU,MAAM,qBAAqB,CAEvC,IAAM,EAAS,IAAI,WAAW,EAAM,OAAS,EAAE,CAC/C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,GAAK,EAAG,CAIxC,GAHI,EAAE,EAAM,KAAO,IAGf,EAAE,EAAM,EAAI,KAAO,GACrB,MAAU,MAAM,oBAAoB,CAEtC,EAAO,EAAI,IAAO,EAAW,EAAM,KAAS,EAC5C,EAAO,EAAI,IAAO,EAAW,EAAM,EAAI,IAEzC,OAAO"}
@@ -0,0 +1 @@
1
+ const e=`0123456789ABCDEF`,t={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};function n(t){let n=``;for(let r=0;r<t.length;r++)n+=e[t[r]>>4],n+=e[t[r]&15];return n}function r(e){if(e.length%2!=0)throw Error(`Invalid hex string`);let n=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2){if(!(e[r]in t)||!(e[r+1]in t))throw Error(`Invalid character`);n[r/2]|=t[e[r]]<<4,n[r/2]|=t[e[r+1]]}return n}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
@@ -0,0 +1,18 @@
1
+ //#region src/hex.d.ts
2
+ /**
3
+ * Encodes a Uint8Array into a hexadecimal string.
4
+ *
5
+ * @param input - The input Uint8Array.
6
+ * @returns The hexadecimal string.
7
+ */
8
+ declare function encodeHex(input: Uint8Array): string;
9
+ /**
10
+ * Encodes a Uint8Array into an uppercase hexadecimal string.
11
+ *
12
+ * @param input - The input Uint8Array.
13
+ * @returns The uppercase hexadecimal string.
14
+ */
15
+ declare function decodeHex(input: string): Uint8Array;
16
+ //#endregion
17
+ export { encodeHex as n, decodeHex as t };
18
+ //# sourceMappingURL=hex-eot11JTh.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-eot11JTh.d.mts","names":[],"sources":["../src/hex.ts"],"sourcesContent":[],"mappings":";;AAkDA;AAeA;;;;iBAfgB,SAAA,QAAiB;;;;;;;iBAejB,SAAA,iBAA0B"}
package/dist/hex.cjs CHANGED
@@ -1,47 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.decodeHex = decodeHex;
7
- exports.encodeHex = encodeHex;
8
- const o = "0123456789ABCDEF",
9
- t = {
10
- 0: 0,
11
- 1: 1,
12
- 2: 2,
13
- 3: 3,
14
- 4: 4,
15
- 5: 5,
16
- 6: 6,
17
- 7: 7,
18
- 8: 8,
19
- 9: 9,
20
- a: 10,
21
- A: 10,
22
- b: 11,
23
- B: 11,
24
- c: 12,
25
- C: 12,
26
- d: 13,
27
- D: 13,
28
- e: 14,
29
- E: 14,
30
- f: 15,
31
- F: 15
32
- };
33
- function encodeHex(e) {
34
- let n = "";
35
- for (let r = 0; r < e.length; r++) n += o[e[r] >> 4], n += o[e[r] & 15];
36
- return n;
37
- }
38
- function decodeHex(e) {
39
- if (e.length % 2 !== 0) throw new Error("Invalid hex string");
40
- const n = new Uint8Array(e.length / 2);
41
- for (let r = 0; r < e.length; r += 2) {
42
- if (!(e[r] in t)) throw new Error("Invalid character");
43
- if (!(e[r + 1] in t)) throw new Error("Invalid character");
44
- n[r / 2] |= t[e[r]] << 4, n[r / 2] |= t[e[r + 1]];
45
- }
46
- return n;
47
- }
1
+ const e=require(`./hex-CDXtL048.cjs`);exports.decodeHex=e.t,exports.encodeHex=e.n;
package/dist/hex.d.cts ADDED
@@ -0,0 +1,2 @@
1
+ import { n as encodeHex, t as decodeHex } from "./hex-BaOs3VLq.cjs";
2
+ export { decodeHex, encodeHex };
package/dist/hex.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { n as encodeHex, t as decodeHex } from "./hex-eot11JTh.mjs";
2
+ export { decodeHex, encodeHex };
package/dist/hex.mjs CHANGED
@@ -1 +1 @@
1
- const o="0123456789ABCDEF",t={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};export function encodeHex(e){let n="";for(let r=0;r<e.length;r++)n+=o[e[r]>>4],n+=o[e[r]&15];return n}export function decodeHex(e){if(e.length%2!==0)throw new Error("Invalid hex string");const n=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2){if(!(e[r]in t))throw new Error("Invalid character");if(!(e[r+1]in t))throw new Error("Invalid character");n[r/2]|=t[e[r]]<<4,n[r/2]|=t[e[r+1]]}return n}
1
+ import{n as e,t}from"./hex-C1p5VuEv.mjs";export{t as decodeHex,e as encodeHex};
package/dist/index.cjs CHANGED
@@ -1,38 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _base = require("./base-64.cjs");
7
- Object.keys(_base).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _base[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _base[key];
14
- }
15
- });
16
- });
17
- var _encryption = require("./encryption.node.cjs");
18
- Object.keys(_encryption).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _encryption[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _encryption[key];
25
- }
26
- });
27
- });
28
- var _hex = require("./hex.cjs");
29
- Object.keys(_hex).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _hex[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _hex[key];
36
- }
37
- });
38
- });
1
+ const e=require(`./base-64-Bh0chPX9.cjs`),t=require(`./encryption.node-DCO-i6QP.cjs`),n=require(`./hex-CDXtL048.cjs`);exports.base64FromBase64url=e.t,exports.base64ToBase64url=e.n,exports.createKey=t.t,exports.decodeBase64=e.r,exports.decodeHex=n.t,exports.decrypt=t.n,exports.encodeBase64=e.i,exports.encodeHex=n.n,exports.encrypt=t.r;
@@ -0,0 +1,4 @@
1
+ import { i as encodeBase64, n as base64ToBase64url, r as decodeBase64, t as base64FromBase64url } from "./base-64-B1YDs-zl.cjs";
2
+ import { n as decrypt, r as encrypt, t as createKey } from "./encryption.node-CyYXMEWi.cjs";
3
+ import { n as encodeHex, t as decodeHex } from "./hex-BaOs3VLq.cjs";
4
+ export { base64FromBase64url, base64ToBase64url, createKey, decodeBase64, decodeHex, decrypt, encodeBase64, encodeHex, encrypt };
@@ -0,0 +1,4 @@
1
+ import { i as encodeBase64, n as base64ToBase64url, r as decodeBase64, t as base64FromBase64url } from "./base-64-D3iUgxLe.mjs";
2
+ import { n as decrypt, r as encrypt, t as createKey } from "./encryption.node-pNNijU1t.mjs";
3
+ import { n as encodeHex, t as decodeHex } from "./hex-eot11JTh.mjs";
4
+ export { base64FromBase64url, base64ToBase64url, createKey, decodeBase64, decodeHex, decrypt, encodeBase64, encodeHex, encrypt };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./base-64";export*from"./encryption.node";export*from"./hex";
1
+ import{i as e,n as t,r as n,t as r}from"./base-64-n6I9tGzK.mjs";import{n as i,r as a,t as o}from"./encryption.node-BLOlwsYV.mjs";import{n as s,t as c}from"./hex-C1p5VuEv.mjs";export{r as base64FromBase64url,t as base64ToBase64url,o as createKey,n as decodeBase64,c as decodeHex,i as decrypt,e as encodeBase64,s as encodeHex,a as encrypt};