@stryke/crypto 0.5.25 → 0.5.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/base-64.cjs +1 -1
- package/dist/base-64.d.cts +40 -2
- package/dist/base-64.d.cts.map +1 -0
- package/dist/base-64.d.mts +40 -2
- package/dist/base-64.d.mts.map +1 -0
- package/dist/base-64.mjs +2 -1
- package/dist/base-64.mjs.map +1 -0
- package/dist/convert/src/array-buffer-to-string.cjs +1 -0
- package/dist/convert/src/array-buffer-to-string.mjs +2 -0
- package/dist/convert/src/array-buffer-to-string.mjs.map +1 -0
- package/dist/convert/src/neutral.cjs +1 -0
- package/dist/convert/src/neutral.mjs +1 -0
- package/dist/convert/src/parse-type-definition.cjs +1 -0
- package/dist/convert/src/parse-type-definition.mjs +1 -0
- package/dist/convert/src/string-to-uint8-array.cjs +1 -0
- package/dist/convert/src/string-to-uint8-array.mjs +2 -0
- package/dist/convert/src/string-to-uint8-array.mjs.map +1 -0
- package/dist/convert/src/string-to-utf8-array.cjs +1 -0
- package/dist/convert/src/string-to-utf8-array.mjs +2 -0
- package/dist/convert/src/string-to-utf8-array.mjs.map +1 -0
- package/dist/convert/src/uint8-array-to-stream.cjs +1 -0
- package/dist/convert/src/uint8-array-to-stream.mjs +2 -0
- package/dist/convert/src/uint8-array-to-stream.mjs.map +1 -0
- package/dist/convert/src/uint8-array-to-string.cjs +1 -0
- package/dist/convert/src/uint8-array-to-string.mjs +2 -0
- package/dist/convert/src/uint8-array-to-string.mjs.map +1 -0
- package/dist/convert/src/utf8-array-to-string.cjs +1 -0
- package/dist/convert/src/utf8-array-to-string.mjs +2 -0
- package/dist/convert/src/utf8-array-to-string.mjs.map +1 -0
- package/dist/encryption.cjs +1 -1
- package/dist/encryption.d.cts +82 -2
- package/dist/encryption.d.cts.map +1 -0
- package/dist/encryption.d.mts +82 -2
- package/dist/encryption.d.mts.map +1 -0
- package/dist/encryption.mjs +2 -1
- package/dist/encryption.mjs.map +1 -0
- package/dist/encryption.node.cjs +1 -1
- package/dist/encryption.node.d.cts +42 -2
- package/dist/encryption.node.d.cts.map +1 -0
- package/dist/encryption.node.d.mts +42 -2
- package/dist/encryption.node.d.mts.map +1 -0
- package/dist/encryption.node.mjs +2 -1
- package/dist/encryption.node.mjs.map +1 -0
- package/dist/hex.cjs +1 -1
- package/dist/hex.d.cts +18 -2
- package/dist/hex.d.cts.map +1 -0
- package/dist/hex.d.mts +18 -2
- package/dist/hex.d.mts.map +1 -0
- package/dist/hex.mjs +2 -1
- package/dist/hex.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/neutral.cjs +1 -1
- package/dist/neutral.d.cts +3 -3
- package/dist/neutral.d.mts +3 -3
- package/dist/neutral.mjs +1 -1
- package/dist/type-checks/src/index.cjs +1 -0
- package/dist/type-checks/src/index.mjs +1 -0
- package/dist/type-checks/src/is-buffer.cjs +1 -0
- package/dist/type-checks/src/is-buffer.mjs +2 -0
- package/dist/type-checks/src/is-buffer.mjs.map +1 -0
- package/dist/type-checks/src/is-collection.cjs +1 -0
- package/dist/type-checks/src/is-collection.mjs +1 -0
- package/dist/type-checks/src/is-string.cjs +1 -0
- package/dist/type-checks/src/is-string.mjs +2 -0
- package/dist/type-checks/src/is-string.mjs.map +1 -0
- package/dist/type-checks/src/is-undefined.cjs +1 -0
- package/dist/type-checks/src/is-undefined.mjs +2 -0
- package/dist/type-checks/src/is-undefined.mjs.map +1 -0
- package/dist/type-checks/src/type-detect.cjs +1 -0
- package/dist/type-checks/src/type-detect.mjs +2 -0
- package/dist/type-checks/src/type-detect.mjs.map +1 -0
- package/package.json +5 -5
- package/dist/base-64-B1YDs-zl.d.cts +0 -40
- package/dist/base-64-B1YDs-zl.d.cts.map +0 -1
- package/dist/base-64-Bh0chPX9.cjs +0 -1
- package/dist/base-64-D3iUgxLe.d.mts +0 -40
- package/dist/base-64-D3iUgxLe.d.mts.map +0 -1
- package/dist/base-64-n6I9tGzK.mjs +0 -2
- package/dist/base-64-n6I9tGzK.mjs.map +0 -1
- package/dist/encryption-CchoDEon.mjs +0 -2
- package/dist/encryption-CchoDEon.mjs.map +0 -1
- package/dist/encryption-Dw19bezD.d.cts +0 -82
- package/dist/encryption-Dw19bezD.d.cts.map +0 -1
- package/dist/encryption-HwrvWUAF.cjs +0 -1
- package/dist/encryption-yC-pEQ14.d.mts +0 -82
- package/dist/encryption-yC-pEQ14.d.mts.map +0 -1
- package/dist/encryption.node-BLOlwsYV.mjs +0 -2
- package/dist/encryption.node-BLOlwsYV.mjs.map +0 -1
- package/dist/encryption.node-CyYXMEWi.d.cts +0 -42
- package/dist/encryption.node-CyYXMEWi.d.cts.map +0 -1
- package/dist/encryption.node-DCO-i6QP.cjs +0 -1
- package/dist/encryption.node-pNNijU1t.d.mts +0 -42
- package/dist/encryption.node-pNNijU1t.d.mts.map +0 -1
- package/dist/hex-BaOs3VLq.d.cts +0 -18
- package/dist/hex-BaOs3VLq.d.cts.map +0 -1
- package/dist/hex-C1p5VuEv.mjs +0 -2
- package/dist/hex-C1p5VuEv.mjs.map +0 -1
- package/dist/hex-CDXtL048.cjs +0 -1
- package/dist/hex-eot11JTh.d.mts +0 -18
- package/dist/hex-eot11JTh.d.mts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - Crypto
|
|
4
4
|
|
|
5
|
+
## [0.5.26](https://github.com/storm-software/stryke/releases/tag/crypto%400.5.26) (12/17/2025)
|
|
6
|
+
|
|
7
|
+
### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated **type-checks** to **v0.5.10**
|
|
10
|
+
- Updated **convert** to **v0.6.25**
|
|
11
|
+
|
|
12
|
+
## [0.5.25](https://github.com/storm-software/stryke/releases/tag/crypto%400.5.25) (12/08/2025)
|
|
13
|
+
|
|
14
|
+
### Updated Dependencies
|
|
15
|
+
|
|
16
|
+
- Updated **type-checks** to **v0.5.9**
|
|
17
|
+
- Updated **convert** to **v0.6.24**
|
|
18
|
+
|
|
5
19
|
## [0.5.24](https://github.com/storm-software/stryke/releases/tag/crypto%400.5.24) (12/08/2025)
|
|
6
20
|
|
|
7
21
|
### Updated Dependencies
|
package/dist/base-64.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./type-checks/src/is-undefined.cjs`),t=require(`./type-checks/src/is-string.cjs`),n=require(`./convert/src/string-to-uint8-array.cjs`),r=require(`./convert/src/utf8-array-to-string.cjs`);require(`./convert/src/neutral.cjs`);const i=new Uint8Array([65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47]),a=61,o=new Uint8Array([100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,62,100,100,100,63,52,53,54,55,56,57,58,59,60,61,100,100,100,100,100,100,100,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,100,100,100,100,100,100,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100]);function s(e){t.isString(e)&&(e=n.stringToUint8Array(e));let a=e.length,o=new Uint8Array(Math.ceil(a/3)*4),s=Math.floor(a/3);for(let t=0;t<s;t++){let n=e[3*t+0]<<16|e[3*t+1]<<8|e[3*t+2];o[4*t+0]=i[n>>18&63],o[4*t+1]=i[n>>12&63],o[4*t+2]=i[n>>6&63],o[4*t+3]=i[n>>0&63]}let c=s;switch(a%3){case 1:{let t=e[3*c+0]<<16;o[4*c+0]=i[t>>18&63],o[4*c+1]=i[t>>12&63],o[4*c+2]=61,o[4*c+3]=61;break}case 2:{let t=e[3*c+0]<<16|e[3*c+1]<<8;o[4*c+0]=i[t>>18&63],o[4*c+1]=i[t>>12&63],o[4*c+2]=i[t>>6&63],o[4*c+3]=61;break}}return r.utf8ArrayToString(o)}function c(r){t.isString(r)&&(r=n.stringToUint8Array(r));let i=r.length;if(i%4!=0)throw Error(`invalid length`);let a=0;for(;a<2&&a<r.length&&r[r.length-1-a]===61;)a++;for(let t=0;t<r.length-a;t++)if(e.isUndefined(r[t])||e.isUndefined(o[r[t]])||o[r[t]]>=64)throw Error(`invalid data`);let s=Math.floor((i-a)/4),c=3*s+(3-a)%3,l=new Uint8Array(c);for(let e=0;e<s;e++){let t=o[r[4*e+0]]<<18|o[r[4*e+1]]<<12|o[r[4*e+2]]<<6|o[r[4*e+3]]<<0;l[3*e]=t>>16&255,l[3*e+1]=t>>8&255,l[3*e+2]=t>>0&255}let u=s;switch(c%3){case 1:{let e=o[r[4*u+0]]<<18|o[r[4*u+1]]<<12;l[3*u]=e>>16&255;break}case 2:{let e=o[r[4*u+0]]<<18|o[r[4*u+1]]<<12|o[r[4*u+2]]<<6;l[3*u]=e>>16&255,l[3*u+1]=e>>8&255;break}}return l}function l(e){return e.replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function u(e){return e.replace(/-/g,`+`).replace(/_/g,`/`)+`=`.repeat((4-e.length%4)%4)}exports.base64FromBase64url=u,exports.base64ToBase64url=l,exports.decodeBase64=c,exports.encodeBase64=s;
|
package/dist/base-64.d.cts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/base-64.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Encodes a Uint8Array into a Base64 encoded Uint8Array.
|
|
4
|
+
*
|
|
5
|
+
* @credit https://github.com/hi-ogawa/js-utils
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input Uint8Array or string to encode.
|
|
8
|
+
* @returns The Base64 encoded Uint8Array.
|
|
9
|
+
*/
|
|
10
|
+
declare function encodeBase64(input: Uint8Array | string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Decodes a Base64 encoded Uint8Array into a Uint8Array.
|
|
13
|
+
*
|
|
14
|
+
* @credit https://github.com/hi-ogawa/js-utils
|
|
15
|
+
*
|
|
16
|
+
* @param input - The Base64 encoded Uint8Array or string to decode.
|
|
17
|
+
* @returns The decoded Uint8Array.
|
|
18
|
+
*/
|
|
19
|
+
declare function decodeBase64(input: Uint8Array | string): Uint8Array;
|
|
20
|
+
/**
|
|
21
|
+
* Converts a Base64 encoded string to a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string.
|
|
22
|
+
*
|
|
23
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
|
|
24
|
+
*
|
|
25
|
+
* @param base64 - The Base64 encoded string to convert.
|
|
26
|
+
* @returns The Base64url encoded string.
|
|
27
|
+
*/
|
|
28
|
+
declare function base64ToBase64url(base64: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Converts a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string to a Base64 encoded string.
|
|
31
|
+
*
|
|
32
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
|
|
33
|
+
*
|
|
34
|
+
* @param base64url - The Base64url encoded string to convert.
|
|
35
|
+
* @returns The Base64 encoded string.
|
|
36
|
+
*/
|
|
37
|
+
declare function base64FromBase64url(base64url: string): string;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { base64FromBase64url, base64ToBase64url, decodeBase64, encodeBase64 };
|
|
40
|
+
//# sourceMappingURL=base-64.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-64.d.cts","names":[],"sources":["../src/base-64.ts"],"sourcesContent":[],"mappings":";;AAoEA;AAmDA;AAkFA;AAYA;;;;iBAjJgB,YAAA,QAAoB;;;;;;;;;iBAmDpB,YAAA,QAAoB,sBAAsB;;;;;;;;;iBAkF1C,iBAAA;;;;;;;;;iBAYA,mBAAA"}
|
package/dist/base-64.d.mts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/base-64.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Encodes a Uint8Array into a Base64 encoded Uint8Array.
|
|
4
|
+
*
|
|
5
|
+
* @credit https://github.com/hi-ogawa/js-utils
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input Uint8Array or string to encode.
|
|
8
|
+
* @returns The Base64 encoded Uint8Array.
|
|
9
|
+
*/
|
|
10
|
+
declare function encodeBase64(input: Uint8Array | string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Decodes a Base64 encoded Uint8Array into a Uint8Array.
|
|
13
|
+
*
|
|
14
|
+
* @credit https://github.com/hi-ogawa/js-utils
|
|
15
|
+
*
|
|
16
|
+
* @param input - The Base64 encoded Uint8Array or string to decode.
|
|
17
|
+
* @returns The decoded Uint8Array.
|
|
18
|
+
*/
|
|
19
|
+
declare function decodeBase64(input: Uint8Array | string): Uint8Array;
|
|
20
|
+
/**
|
|
21
|
+
* Converts a Base64 encoded string to a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string.
|
|
22
|
+
*
|
|
23
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
|
|
24
|
+
*
|
|
25
|
+
* @param base64 - The Base64 encoded string to convert.
|
|
26
|
+
* @returns The Base64url encoded string.
|
|
27
|
+
*/
|
|
28
|
+
declare function base64ToBase64url(base64: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Converts a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string to a Base64 encoded string.
|
|
31
|
+
*
|
|
32
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
|
|
33
|
+
*
|
|
34
|
+
* @param base64url - The Base64url encoded string to convert.
|
|
35
|
+
* @returns The Base64 encoded string.
|
|
36
|
+
*/
|
|
37
|
+
declare function base64FromBase64url(base64url: string): string;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { base64FromBase64url, base64ToBase64url, decodeBase64, encodeBase64 };
|
|
40
|
+
//# sourceMappingURL=base-64.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-64.d.mts","names":[],"sources":["../src/base-64.ts"],"sourcesContent":[],"mappings":";;AAoEA;AAmDA;AAkFA;AAYA;;;;iBAjJgB,YAAA,QAAoB;;;;;;;;;iBAmDpB,YAAA,QAAoB,sBAAsB;;;;;;;;;iBAkF1C,iBAAA;;;;;;;;;iBAYA,mBAAA"}
|
package/dist/base-64.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isUndefined as e}from"./type-checks/src/is-undefined.mjs";import{isString as t}from"./type-checks/src/is-string.mjs";import{stringToUint8Array as n}from"./convert/src/string-to-uint8-array.mjs";import{utf8ArrayToString as r}from"./convert/src/utf8-array-to-string.mjs";import"./convert/src/neutral.mjs";const i=new Uint8Array([65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47]),a=new Uint8Array([100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,62,100,100,100,63,52,53,54,55,56,57,58,59,60,61,100,100,100,100,100,100,100,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,100,100,100,100,100,100,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100]);function o(e){t(e)&&(e=n(e));let a=e.length,o=new Uint8Array(Math.ceil(a/3)*4),s=Math.floor(a/3);for(let t=0;t<s;t++){let n=e[3*t+0]<<16|e[3*t+1]<<8|e[3*t+2];o[4*t+0]=i[n>>18&63],o[4*t+1]=i[n>>12&63],o[4*t+2]=i[n>>6&63],o[4*t+3]=i[n>>0&63]}let c=s;switch(a%3){case 1:{let t=e[3*c+0]<<16;o[4*c+0]=i[t>>18&63],o[4*c+1]=i[t>>12&63],o[4*c+2]=61,o[4*c+3]=61;break}case 2:{let t=e[3*c+0]<<16|e[3*c+1]<<8;o[4*c+0]=i[t>>18&63],o[4*c+1]=i[t>>12&63],o[4*c+2]=i[t>>6&63],o[4*c+3]=61;break}}return r(o)}function s(r){t(r)&&(r=n(r));let i=r.length;if(i%4!=0)throw Error(`invalid length`);let o=0;for(;o<2&&o<r.length&&r[r.length-1-o]===61;)o++;for(let t=0;t<r.length-o;t++)if(e(r[t])||e(a[r[t]])||a[r[t]]>=64)throw Error(`invalid data`);let s=Math.floor((i-o)/4),c=3*s+(3-o)%3,l=new Uint8Array(c);for(let e=0;e<s;e++){let t=a[r[4*e+0]]<<18|a[r[4*e+1]]<<12|a[r[4*e+2]]<<6|a[r[4*e+3]]<<0;l[3*e]=t>>16&255,l[3*e+1]=t>>8&255,l[3*e+2]=t>>0&255}let u=s;switch(c%3){case 1:{let e=a[r[4*u+0]]<<18|a[r[4*u+1]]<<12;l[3*u]=e>>16&255;break}case 2:{let e=a[r[4*u+0]]<<18|a[r[4*u+1]]<<12|a[r[4*u+2]]<<6;l[3*u]=e>>16&255,l[3*u+1]=e>>8&255;break}}return l}function c(e){return e.replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function l(e){return e.replace(/-/g,`+`).replace(/_/g,`/`)+`=`.repeat((4-e.length%4)%4)}export{l as base64FromBase64url,c as base64ToBase64url,s as decodeBase64,o as encodeBase64};
|
|
2
|
+
//# sourceMappingURL=base-64.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-64.mjs","names":["i"],"sources":["../src/base-64.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 { stringToUint8Array } from \"@stryke/convert/neutral\";\nimport { utf8ArrayToString } from \"@stryke/convert/utf8-array-to-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\n\n// map 6 bits [0, 64) into ascii byte (8 bits)\n// generated by\n// Array.from(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\", c => c.charCodeAt(0))\n// biome-ignore format:\nconst ENCODE_MAP = new Uint8Array([\n 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,\n 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,\n 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,\n 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47\n]);\n\n// \"=\".codePointAt(0)\nconst ENCODE_PAD = 61;\n\n// inverse of ENCODE_MAP\n// generated by\n// ENCODE_MAP.reduce((acc, v, i) => { acc[v] = i; return acc }, Array(255).fill(100))\n// biome-ignore format:\nconst DECODE_MAP = new Uint8Array([\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 62, 100, 100,\n 100, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 100, 100, 100, 100, 100, 100,\n 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\n 21, 22, 23, 24, 25, 100, 100, 100, 100, 100, 100, 26, 27, 28, 29, 30, 31, 32,\n 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100\n]);\n\n/**\n * Encodes a Uint8Array into a Base64 encoded Uint8Array.\n *\n * @credit https://github.com/hi-ogawa/js-utils\n *\n * @param input - The input Uint8Array or string to encode.\n * @returns The Base64 encoded Uint8Array.\n */\nexport function encodeBase64(input: Uint8Array | string): string {\n if (isString(input)) {\n input = stringToUint8Array(input);\n }\n\n const xLen = input.length;\n const result = new Uint8Array(Math.ceil(xLen / 3) * 4);\n const chunkLen = Math.floor(xLen / 3);\n\n // encode complete chunks\n for (let i = 0; i < chunkLen; i++) {\n const chunk =\n (input[3 * i + 0]! << 16) | (input[3 * i + 1]! << 8) | input[3 * i + 2]!;\n result[4 * i + 0] = ENCODE_MAP[(chunk >> 18) & 0b111111]!;\n result[4 * i + 1] = ENCODE_MAP[(chunk >> 12) & 0b111111]!;\n result[4 * i + 2] = ENCODE_MAP[(chunk >> 6) & 0b111111]!;\n result[4 * i + 3] = ENCODE_MAP[(chunk >> 0) & 0b111111]!;\n }\n\n // encode partial chunk with padding\n const i = chunkLen;\n switch (xLen % 3) {\n case 1: {\n const chunk = input[3 * i + 0]! << 16;\n result[4 * i + 0] = ENCODE_MAP[(chunk >> 18) & 0b111111]!;\n result[4 * i + 1] = ENCODE_MAP[(chunk >> 12) & 0b111111]!;\n result[4 * i + 2] = ENCODE_PAD;\n result[4 * i + 3] = ENCODE_PAD;\n break;\n }\n case 2: {\n const chunk = (input[3 * i + 0]! << 16) | (input[3 * i + 1]! << 8);\n result[4 * i + 0] = ENCODE_MAP[(chunk >> 18) & 0b111111]!;\n result[4 * i + 1] = ENCODE_MAP[(chunk >> 12) & 0b111111]!;\n result[4 * i + 2] = ENCODE_MAP[(chunk >> 6) & 0b111111]!;\n result[4 * i + 3] = ENCODE_PAD;\n break;\n }\n }\n\n return utf8ArrayToString(result);\n}\n\n/**\n * Decodes a Base64 encoded Uint8Array into a Uint8Array.\n *\n * @credit https://github.com/hi-ogawa/js-utils\n *\n * @param input - The Base64 encoded Uint8Array or string to decode.\n * @returns The decoded Uint8Array.\n */\nexport function decodeBase64(input: Uint8Array | string): Uint8Array {\n if (isString(input)) {\n input = stringToUint8Array(input);\n }\n\n const yLen = input.length;\n\n // validate length\n if (yLen % 4 !== 0) {\n throw new Error(\"invalid length\");\n }\n\n // get padding length\n let padLen = 0;\n while (\n padLen < 2 &&\n padLen < input.length &&\n input[input.length - 1 - padLen] === ENCODE_PAD\n ) {\n padLen++;\n }\n\n // validate encoding\n for (let i = 0; i < input.length - padLen; i++) {\n if (\n isUndefined(input[i]) ||\n isUndefined(DECODE_MAP[input[i]!]) ||\n DECODE_MAP[input[i]!]! >= 64\n ) {\n throw new Error(\"invalid data\");\n }\n }\n\n // validate encoding\n const chunkLen = Math.floor((yLen - padLen) / 4);\n const xLen = 3 * chunkLen + ((3 - padLen) % 3);\n const result = new Uint8Array(xLen);\n\n // decode complete chunks\n for (let i = 0; i < chunkLen; i++) {\n const chunk =\n (DECODE_MAP[input[4 * i + 0]!]! << 18) |\n (DECODE_MAP[input[4 * i + 1]!]! << 12) |\n (DECODE_MAP[input[4 * i + 2]!]! << 6) |\n (DECODE_MAP[input[4 * i + 3]!]! << 0);\n result[3 * i] = (chunk >> 16) & 0xff;\n result[3 * i + 1] = (chunk >> 8) & 0xff;\n result[3 * i + 2] = (chunk >> 0) & 0xff;\n }\n\n // decode partial chunk\n const i = chunkLen;\n switch (xLen % 3) {\n case 1: {\n const chunk =\n (DECODE_MAP[input[4 * i + 0]!]! << 18) |\n (DECODE_MAP[input[4 * i + 1]!]! << 12);\n result[3 * i] = (chunk >> 16) & 0xff;\n break;\n }\n case 2: {\n const chunk =\n (DECODE_MAP[input[4 * i + 0]!]! << 18) |\n (DECODE_MAP[input[4 * i + 1]!]! << 12) |\n (DECODE_MAP[input[4 * i + 2]!]! << 6);\n result[3 * i] = (chunk >> 16) & 0xff;\n result[3 * i + 1] = (chunk >> 8) & 0xff;\n break;\n }\n }\n\n return result;\n}\n\n/**\n * Converts a Base64 encoded string to a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string.\n *\n * @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C\n *\n * @param base64 - The Base64 encoded string to convert.\n * @returns The Base64url encoded string.\n */\nexport function base64ToBase64url(base64: string): string {\n return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/g, \"\");\n}\n\n/**\n * Converts a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string to a Base64 encoded string.\n *\n * @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C\n *\n * @param base64url - The Base64url encoded string to convert.\n * @returns The Base64 encoded string.\n */\nexport function base64FromBase64url(base64url: string): string {\n return (\n base64url.replace(/-/g, \"+\").replace(/_/g, \"/\") +\n \"=\".repeat((4 - (base64url.length % 4)) % 4)\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=t.byteLength;if(n<65535)return String.fromCharCode.apply(null,t);let r=``;for(let e=0;e<n;e++)r+=String.fromCharCode(t[e]);return r}exports.arrayBufferToString=e;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=t.byteLength;if(n<65535)return String.fromCharCode.apply(null,t);let r=``;for(let e=0;e<n;e++)r+=String.fromCharCode(t[e]);return r}export{e as arrayBufferToString};
|
|
2
|
+
//# sourceMappingURL=array-buffer-to-string.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-buffer-to-string.mjs","names":[],"sources":["../../../../convert/src/array-buffer-to-string.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\n/**\n * Convert an ArrayBuffer or Uint8Array to a string\n *\n * @param buffer - The ArrayBuffer or Uint8Array to convert\n * @returns The converted string\n */\nexport function arrayBufferToString(\n buffer: ArrayBuffer | ArrayBufferLike | Uint8Array\n): string {\n const bytes =\n buffer instanceof Uint8Array\n ? buffer\n : new Uint8Array(buffer as ArrayBufferLike);\n const len = bytes.byteLength;\n if (len < 65535) {\n return String.fromCharCode.apply(null, bytes as unknown as number[]);\n }\n let binary = \"\";\n for (let i = 0; i < len; i++) {\n binary += String.fromCharCode(bytes[i]!);\n }\n return binary;\n}\n"],"mappings":"AAwBA,SAAgB,EACd,EACQ,CACR,IAAM,EACJ,aAAkB,WACd,EACA,IAAI,WAAW,EAA0B,CACzC,EAAM,EAAM,WAClB,GAAI,EAAM,MACR,OAAO,OAAO,aAAa,MAAM,KAAM,EAA6B,CAEtE,IAAI,EAAS,GACb,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,IACvB,GAAU,OAAO,aAAa,EAAM,GAAI,CAE1C,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./array-buffer-to-string.cjs`);require(`./parse-type-definition.cjs`);const t=require(`./string-to-uint8-array.cjs`),n=require(`./string-to-utf8-array.cjs`),r=require(`./uint8-array-to-stream.cjs`),i=require(`./uint8-array-to-string.cjs`),a=require(`./utf8-array-to-string.cjs`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{arrayBufferToString as e}from"./array-buffer-to-string.mjs";import"./parse-type-definition.mjs";import{base64StringToUint8Array as t,stringToUint8Array as n}from"./string-to-uint8-array.mjs";import{stringToUtf8Array as r}from"./string-to-utf8-array.mjs";import{concatUint8Array as i}from"./uint8-array-to-stream.mjs";import{uint8ArrayToString as a}from"./uint8-array-to-string.mjs";import{utf8ArrayToString as o}from"./utf8-array-to-string.mjs";export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`../../type-checks/src/index.cjs`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../../type-checks/src/index.mjs";export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return Uint8Array.from([...encodeURIComponent(e)].map(e=>e.codePointAt(0)))}function t(t){return e(atob(t))}exports.base64StringToUint8Array=t,exports.stringToUint8Array=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-to-uint8-array.mjs","names":[],"sources":["../../../../convert/src/string-to-uint8-array.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\n/**\n * Convert a string to Uint8Array\n *\n * @param text - The text to convert\n * @returns The converted Uint8Array\n */\nexport function stringToUint8Array(text: string): Uint8Array {\n return Uint8Array.from(\n [...encodeURIComponent(text)].map(letter => letter.codePointAt(0)!)\n );\n}\n\n/**\n * Convert a binary string to Uint8Array\n *\n * @param binary - The binary string to convert\n * @returns The converted Uint8Array\n */\nexport function binaryStringToUint8Array(binary: string): Uint8Array {\n const len = binary.length;\n const arr = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n arr[i] = binary.charCodeAt(i);\n }\n return arr;\n}\n\n/**\n * Convert a base64 string to a Uint8Array\n *\n * @param data - The base64 string to convert\n * @returns The converted Uint8Array\n */\nexport function base64StringToUint8Array(data: string): Uint8Array {\n return stringToUint8Array(atob(data));\n}\n"],"mappings":"AAwBA,SAAgB,EAAmB,EAA0B,CAC3D,OAAO,WAAW,KAChB,CAAC,GAAG,mBAAmB,EAAK,CAAC,CAAC,IAAI,GAAU,EAAO,YAAY,EAAE,CAAE,CACpE,CAwBH,SAAgB,EAAyB,EAA0B,CACjE,OAAO,EAAmB,KAAK,EAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=new TextEncoder;function t(t){return e.encode(t)}exports.stringToUtf8Array=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-to-utf8-array.mjs","names":[],"sources":["../../../../convert/src/string-to-utf8-array.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 encoder = new TextEncoder();\n\n/**\n * Convert a string to a utf-8 array\n *\n * @param input - The string to convert\n * @returns The converted utf-8 array\n */\nexport function stringToUtf8Array(input: string): Uint8Array {\n return encoder.encode(input);\n}\n"],"mappings":"AAkBA,MAAM,EAAU,IAAI,YAQpB,SAAgB,EAAkB,EAA2B,CAC3D,OAAO,EAAQ,OAAO,EAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}exports.concatUint8Array=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint8-array-to-stream.mjs","names":[],"sources":["../../../../convert/src/uint8-array-to-stream.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\n/**\n * Convert a Uint8Array to a ReadableStream\n *\n * @param data - The Uint8Array to convert\n * @returns The converted ReadableStream\n */\nexport function uint8ArrayToStream(\n data: Uint8Array\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n start(controller) {\n controller.enqueue(data);\n controller.close();\n }\n });\n}\n\n/**\n * Concatenate an array of Uint8Array chunks into a single Uint8Array\n *\n * @param chunks - Array of Uint8Array chunks to concatenate\n * @returns The concatenated Uint8Array\n */\nexport function concatUint8Array(chunks: Uint8Array[]): Uint8Array {\n let total = 0;\n for (const chunk of chunks) {\n total += chunk.length;\n }\n const result = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n result.set(chunk, offset);\n offset += chunk.length;\n }\n return result;\n}\n\n/**\n * Concatenate a ReadableStream of Uint8Array chunks into a single Uint8Array\n *\n * @param stream - The ReadableStream of Uint8Array chunks to concatenate\n * @returns A promise that resolves to the concatenated Uint8Array\n */\nexport async function concatUint8ArrayStream(\n stream: ReadableStream<Uint8Array>\n): Promise<Uint8Array> {\n const chunks: Uint8Array[] = [];\n await stream.pipeTo(\n new WritableStream({\n write(chunk) {\n chunks.push(chunk);\n }\n })\n );\n\n return concatUint8Array(chunks);\n}\n"],"mappings":"AAyCA,SAAgB,EAAiB,EAAkC,CACjE,IAAI,EAAQ,EACZ,IAAK,IAAM,KAAS,EAClB,GAAS,EAAM,OAEjB,IAAM,EAAS,IAAI,WAAW,EAAM,CAChC,EAAS,EACb,IAAK,IAAM,KAAS,EAClB,EAAO,IAAI,EAAO,EAAO,CACzB,GAAU,EAAM,OAElB,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./array-buffer-to-string.cjs`);function t(t){return btoa(e.arrayBufferToString(t))}exports.uint8ArrayToString=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint8-array-to-string.mjs","names":[],"sources":["../../../../convert/src/uint8-array-to-string.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 { arrayBufferToString } from \"./array-buffer-to-string\";\n\n/**\n * Convert a Uint8Array to a base64 string\n *\n * @param buffer - The Uint8Array to convert\n * @returns The converted base64 string\n */\nexport function uint8ArrayToString(buffer: Uint8Array): string {\n return btoa(arrayBufferToString(buffer));\n}\n"],"mappings":"mEA0BA,SAAgB,EAAmB,EAA4B,CAC7D,OAAO,KAAK,EAAoB,EAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=new TextDecoder;function t(t){return e.decode(t)}exports.utf8ArrayToString=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8-array-to-string.mjs","names":[],"sources":["../../../../convert/src/utf8-array-to-string.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 decoder = new TextDecoder();\n\n/**\n * Convert a utf-8 array to string\n *\n * @param input - Utf-8 Array\n * @returns The converted string\n */\nexport function utf8ArrayToString(\n input: NodeJS.ArrayBufferView | ArrayBuffer\n): string {\n return decoder.decode(input);\n}\n"],"mappings":"AAkBA,MAAM,EAAU,IAAI,YAQpB,SAAgB,EACd,EACQ,CACR,OAAO,EAAQ,OAAO,EAAM"}
|
package/dist/encryption.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./
|
|
1
|
+
const e=require(`./convert/src/string-to-uint8-array.cjs`),t=require(`./convert/src/string-to-utf8-array.cjs`),n=require(`./convert/src/uint8-array-to-stream.cjs`),r=require(`./convert/src/uint8-array-to-string.cjs`),i=require(`./convert/src/utf8-array-to-string.cjs`);require(`./convert/src/neutral.cjs`);const a=require(`./base-64.cjs`),o=require(`./hex.cjs`);async function s(){return crypto.subtle.generateKey({name:`AES-GCM`,length:256},!0,[`encrypt`,`decrypt`])}async function c(e){let t=await crypto.subtle.exportKey(`raw`,e);return a.encodeBase64(new Uint8Array(t)).toString()}async function l(e){let t=a.decodeBase64(e);return crypto.subtle.importKey(`raw`,t.buffer,`AES-GCM`,!0,[`encrypt`,`decrypt`])}const u=24;async function d(e,n){let r=crypto.getRandomValues(new Uint8Array(24/2)),i=await crypto.subtle.encrypt({name:`AES-GCM`,iv:r},e,t.stringToUtf8Array(n));return o.encodeHex(r)+a.encodeBase64(new Uint8Array(i))}async function f(e,t){return i.utf8ArrayToString(await crypto.subtle.decrypt({name:`AES-GCM`,iv:o.decodeHex(t.slice(0,24))},e,a.decodeBase64(t.slice(24))))}async function p(e,t){let i=crypto.getRandomValues(new Uint8Array(16)),a=await crypto.subtle.encrypt({name:`AES-GCM`,iv:i},e,t);return r.uint8ArrayToString(n.concatUint8Array([i,new Uint8Array(a)]))}async function m(t,n){let r=e.base64StringToUint8Array(n);return crypto.subtle.decrypt({name:`AES-GCM`,iv:r.slice(0,16)},t,r.slice(16))}exports.createKey=s,exports.decodeKey=l,exports.decrypt=f,exports.decryptBuffer=m,exports.encodeKey=c,exports.encrypt=d,exports.encryptBuffer=p;
|
package/dist/encryption.d.cts
CHANGED
|
@@ -1,2 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { createKey, decodeKey, decrypt, decryptBuffer, encodeKey, encrypt, encryptBuffer };
|
|
82
|
+
//# sourceMappingURL=encryption.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.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"}
|
package/dist/encryption.d.mts
CHANGED
|
@@ -1,2 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { createKey, decodeKey, decrypt, decryptBuffer, encodeKey, encrypt, encryptBuffer };
|
|
82
|
+
//# sourceMappingURL=encryption.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.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"}
|
package/dist/encryption.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"./
|
|
1
|
+
import{base64StringToUint8Array as e}from"./convert/src/string-to-uint8-array.mjs";import{stringToUtf8Array as t}from"./convert/src/string-to-utf8-array.mjs";import{concatUint8Array as n}from"./convert/src/uint8-array-to-stream.mjs";import{uint8ArrayToString as r}from"./convert/src/uint8-array-to-string.mjs";import{utf8ArrayToString as i}from"./convert/src/utf8-array-to-string.mjs";import"./convert/src/neutral.mjs";import{decodeBase64 as a,encodeBase64 as o}from"./base-64.mjs";import{decodeHex as s,encodeHex as c}from"./hex.mjs";async function l(){return crypto.subtle.generateKey({name:`AES-GCM`,length:256},!0,[`encrypt`,`decrypt`])}async function u(e){let t=await crypto.subtle.exportKey(`raw`,e);return o(new Uint8Array(t)).toString()}async function d(e){let t=a(e);return crypto.subtle.importKey(`raw`,t.buffer,`AES-GCM`,!0,[`encrypt`,`decrypt`])}async function f(e,n){let r=crypto.getRandomValues(new Uint8Array(24/2)),i=await crypto.subtle.encrypt({name:`AES-GCM`,iv:r},e,t(n));return c(r)+o(new Uint8Array(i))}async function p(e,t){return i(await crypto.subtle.decrypt({name:`AES-GCM`,iv:s(t.slice(0,24))},e,a(t.slice(24))))}async function m(e,t){let i=crypto.getRandomValues(new Uint8Array(16)),a=await crypto.subtle.encrypt({name:`AES-GCM`,iv:i},e,t);return r(n([i,new Uint8Array(a)]))}async function h(t,n){let r=e(n);return crypto.subtle.decrypt({name:`AES-GCM`,iv:r.slice(0,16)},t,r.slice(16))}export{l as createKey,d as decodeKey,p as decrypt,h as decryptBuffer,u as encodeKey,f as encrypt,m as encryptBuffer};
|
|
2
|
+
//# sourceMappingURL=encryption.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.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":"uhBAmCA,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"}
|
package/dist/encryption.node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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`)}exports.createKey=c,exports.decrypt=u,exports.encrypt=l;
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 { createKey, decrypt, encrypt };
|
|
42
|
+
//# sourceMappingURL=encryption.node.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.node.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"}
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 { createKey, decrypt, encrypt };
|
|
42
|
+
//# sourceMappingURL=encryption.node.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.node.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"}
|
package/dist/encryption.node.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
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{c as createKey,u as decrypt,l as encrypt};
|
|
2
|
+
//# sourceMappingURL=encryption.node.mjs.map
|