@stryke/crypto 0.5.44 → 0.6.1

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 (95) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cloudflare.cjs +960 -0
  3. package/dist/cloudflare.d.cts +251 -0
  4. package/dist/cloudflare.d.cts.map +1 -0
  5. package/dist/cloudflare.d.mts +251 -0
  6. package/dist/cloudflare.d.mts.map +1 -0
  7. package/dist/cloudflare.mjs +942 -0
  8. package/dist/cloudflare.mjs.map +1 -0
  9. package/dist/index.cjs +16 -12
  10. package/dist/index.d.cts +2 -4
  11. package/dist/index.d.mts +2 -4
  12. package/dist/index.mjs +2 -4
  13. package/dist/neutral-BISXAuIW.cjs +868 -0
  14. package/dist/{encryption.d.mts → neutral-BJmyEdJq.d.mts} +77 -2
  15. package/dist/neutral-BJmyEdJq.d.mts.map +1 -0
  16. package/dist/neutral-BtZoJSl-.mjs +779 -0
  17. package/dist/neutral-BtZoJSl-.mjs.map +1 -0
  18. package/dist/{encryption.d.cts → neutral-CW6EXiYo.d.cts} +77 -2
  19. package/dist/neutral-CW6EXiYo.d.cts.map +1 -0
  20. package/dist/neutral.cjs +16 -16
  21. package/dist/neutral.d.cts +2 -4
  22. package/dist/neutral.d.mts +2 -4
  23. package/dist/neutral.mjs +2 -4
  24. package/dist/node.cjs +663 -0
  25. package/dist/node.d.cts +117 -0
  26. package/dist/node.d.cts.map +1 -0
  27. package/dist/node.d.mts +117 -0
  28. package/dist/node.d.mts.map +1 -0
  29. package/dist/node.mjs +654 -0
  30. package/dist/node.mjs.map +1 -0
  31. package/package.json +55 -20
  32. package/dist/base-64.cjs +0 -440
  33. package/dist/base-64.d.cts +0 -40
  34. package/dist/base-64.d.cts.map +0 -1
  35. package/dist/base-64.d.mts +0 -40
  36. package/dist/base-64.d.mts.map +0 -1
  37. package/dist/base-64.mjs +0 -438
  38. package/dist/base-64.mjs.map +0 -1
  39. package/dist/convert/src/array-buffer-to-string.cjs +0 -19
  40. package/dist/convert/src/array-buffer-to-string.mjs +0 -19
  41. package/dist/convert/src/array-buffer-to-string.mjs.map +0 -1
  42. package/dist/convert/src/neutral.cjs +0 -7
  43. package/dist/convert/src/neutral.mjs +0 -9
  44. package/dist/convert/src/parse-type-definition.cjs +0 -1
  45. package/dist/convert/src/parse-type-definition.mjs +0 -3
  46. package/dist/convert/src/string-to-uint8-array.cjs +0 -24
  47. package/dist/convert/src/string-to-uint8-array.mjs +0 -23
  48. package/dist/convert/src/string-to-uint8-array.mjs.map +0 -1
  49. package/dist/convert/src/string-to-utf8-array.cjs +0 -15
  50. package/dist/convert/src/string-to-utf8-array.mjs +0 -15
  51. package/dist/convert/src/string-to-utf8-array.mjs.map +0 -1
  52. package/dist/convert/src/uint8-array-to-stream.cjs +0 -22
  53. package/dist/convert/src/uint8-array-to-stream.mjs +0 -22
  54. package/dist/convert/src/uint8-array-to-stream.mjs.map +0 -1
  55. package/dist/convert/src/uint8-array-to-string.cjs +0 -15
  56. package/dist/convert/src/uint8-array-to-string.mjs +0 -16
  57. package/dist/convert/src/uint8-array-to-string.mjs.map +0 -1
  58. package/dist/convert/src/utf8-array-to-string.cjs +0 -15
  59. package/dist/convert/src/utf8-array-to-string.mjs +0 -15
  60. package/dist/convert/src/utf8-array-to-string.mjs.map +0 -1
  61. package/dist/encryption.cjs +0 -134
  62. package/dist/encryption.d.cts.map +0 -1
  63. package/dist/encryption.d.mts.map +0 -1
  64. package/dist/encryption.mjs +0 -129
  65. package/dist/encryption.mjs.map +0 -1
  66. package/dist/encryption.node.cjs +0 -63
  67. package/dist/encryption.node.d.cts +0 -42
  68. package/dist/encryption.node.d.cts.map +0 -1
  69. package/dist/encryption.node.d.mts +0 -42
  70. package/dist/encryption.node.d.mts.map +0 -1
  71. package/dist/encryption.node.mjs +0 -62
  72. package/dist/encryption.node.mjs.map +0 -1
  73. package/dist/hex.cjs +0 -62
  74. package/dist/hex.d.cts +0 -18
  75. package/dist/hex.d.cts.map +0 -1
  76. package/dist/hex.d.mts +0 -18
  77. package/dist/hex.d.mts.map +0 -1
  78. package/dist/hex.mjs +0 -61
  79. package/dist/hex.mjs.map +0 -1
  80. package/dist/type-checks/src/index.cjs +0 -5
  81. package/dist/type-checks/src/index.mjs +0 -7
  82. package/dist/type-checks/src/is-buffer.cjs +0 -12
  83. package/dist/type-checks/src/is-buffer.mjs +0 -12
  84. package/dist/type-checks/src/is-buffer.mjs.map +0 -1
  85. package/dist/type-checks/src/is-collection.cjs +0 -1
  86. package/dist/type-checks/src/is-collection.mjs +0 -3
  87. package/dist/type-checks/src/is-string.cjs +0 -12
  88. package/dist/type-checks/src/is-string.mjs +0 -12
  89. package/dist/type-checks/src/is-string.mjs.map +0 -1
  90. package/dist/type-checks/src/is-undefined.cjs +0 -8
  91. package/dist/type-checks/src/is-undefined.mjs +0 -8
  92. package/dist/type-checks/src/is-undefined.mjs.map +0 -1
  93. package/dist/type-checks/src/type-detect.cjs +0 -15
  94. package/dist/type-checks/src/type-detect.mjs +0 -17
  95. package/dist/type-checks/src/type-detect.mjs.map +0 -1
@@ -0,0 +1,117 @@
1
+ import { BinaryLike, KeyObject } from "node:crypto";
2
+
3
+ //#region src/base-64.d.ts
4
+
5
+ /**
6
+ * Encodes a Uint8Array into a Base64 encoded Uint8Array.
7
+ *
8
+ * @credit https://github.com/hi-ogawa/js-utils
9
+ *
10
+ * @param input - The input Uint8Array or string to encode.
11
+ * @returns The Base64 encoded Uint8Array.
12
+ */
13
+ declare function encodeBase64(input: Uint8Array | string): string;
14
+ /**
15
+ * Decodes a Base64 encoded Uint8Array into a Uint8Array.
16
+ *
17
+ * @credit https://github.com/hi-ogawa/js-utils
18
+ *
19
+ * @param input - The Base64 encoded Uint8Array or string to decode.
20
+ * @returns The decoded Uint8Array.
21
+ */
22
+ declare function decodeBase64(input: Uint8Array | string): Uint8Array;
23
+ /**
24
+ * Converts a Base64 encoded string to a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string.
25
+ *
26
+ * @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
27
+ *
28
+ * @param base64 - The Base64 encoded string to convert.
29
+ * @returns The Base64url encoded string.
30
+ */
31
+ declare function base64UrlEncode(base64: Uint8Array): string;
32
+ /**
33
+ * Converts a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string to a Base64 encoded string.
34
+ *
35
+ * @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
36
+ *
37
+ * @param base64url - The Base64url encoded string to convert.
38
+ * @returns The Base64 encoded string.
39
+ */
40
+ declare function base64UrlDecode(base64url: string): Uint8Array;
41
+ //#endregion
42
+ //#region src/encryption.node.d.ts
43
+ /**
44
+ * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
45
+ *
46
+ * @param key - The key to use when creating the \`KeyObject\`.
47
+ * @returns The new \`KeyObject\`.
48
+ */
49
+ declare function createKey(key: NodeJS.ArrayBufferView): KeyObject;
50
+ /**
51
+ * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
52
+ *
53
+ * @param key - The key to use. If \`key\` is a \`Buffer\`, \`TypedArray\`, or \`DataView\`, the \`encoding\` argument is ignored.
54
+ * @param encoding - The \`encoding\` of the \`key\` string. Must be one of \`'utf8'\`, \`'utf16le'\`, \`'latin1'\`, or \`'base64'\`. Default is \`'utf8'\`.
55
+ * @returns The new \`KeyObject\`.
56
+ */
57
+ declare function createKey(key: string, encoding: BufferEncoding): KeyObject;
58
+ /**
59
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
60
+ *
61
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
62
+ *
63
+ * @param secret - The secret key used for encryption.
64
+ * @param plaintext - The data to encrypt.
65
+ * @returns The encrypted data.
66
+ */
67
+ declare function encrypt(secret: BinaryLike, plaintext: string): string;
68
+ /**
69
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
70
+ *
71
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
72
+ *
73
+ * @param secret - The secret key used for decryption.
74
+ * @param encrypted - The encrypted data to decrypt.
75
+ * @returns The decrypted data.
76
+ */
77
+ declare function decrypt(secret: BinaryLike, encrypted: string): string;
78
+ //#endregion
79
+ //#region src/hex.d.ts
80
+ /**
81
+ * Encodes a Uint8Array into a hexadecimal string.
82
+ *
83
+ * @param input - The input Uint8Array.
84
+ * @returns The hexadecimal string.
85
+ */
86
+ declare function encodeHex(input: Uint8Array): string;
87
+ /**
88
+ * Encodes a Uint8Array into an uppercase hexadecimal string.
89
+ *
90
+ * @param input - The input Uint8Array.
91
+ * @returns The uppercase hexadecimal string.
92
+ */
93
+ declare function decodeHex(input: string): Uint8Array;
94
+ //#endregion
95
+ //#region src/random.d.ts
96
+ /**
97
+ * Generate a random byte array of the specified length using the Web Crypto API.
98
+ *
99
+ * @param length - The length of the random byte array to generate (default is 32 bytes)
100
+ * @returns A Uint8Array containing random bytes of the specified length
101
+ */
102
+ declare function generateRandomBytes(length?: number): Uint8Array;
103
+ /**
104
+ * Generate a random string of the specified length using characters A-Z, a-z, and 0-9 for CSRF tokens, etc.
105
+ *
106
+ * @remarks
107
+ * This function uses the Web Crypto API's `crypto.getRandomValues` to generate secure random bytes,
108
+ * and then maps those bytes to characters in the specified character set. It uses rejection sampling
109
+ * to ensure a uniform distribution of characters without modulo bias.
110
+ *
111
+ * @param length - The length of the random string to generate (default is 32 characters)
112
+ * @returns A random string of the specified length
113
+ */
114
+ declare function generateRandomString(length?: number): string;
115
+ //#endregion
116
+ export { base64UrlDecode, base64UrlEncode, createKey, decodeBase64, decodeHex, decrypt, encodeBase64, encodeHex, encrypt, generateRandomBytes, generateRandomString };
117
+ //# sourceMappingURL=node.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.cts","names":[],"sources":["../src/base-64.ts","../src/encryption.node.ts","../src/hex.ts","../src/random.ts"],"sourcesContent":[],"mappings":";;;;;;;AAoEA;AAmDA;AAkFA;AAeA;;iBApJgB,YAAA,QAAoB;;ACvBpC;AASA;AA2BA;AA4CA;;;;AC3EgB,iBFqEA,YAAA,CErEiB,KAAU,EFqEP,UErEO,GAAA,MAAA,CAAA,EFqEe,UErEf;AAe3C;;;;ACzCA;AAeA;;;iBHkKgB,eAAA,SAAwB;;;;;;;;;iBAexB,eAAA,qBAAoC;;;;;AApJpD;AAmDA;AAkFA;AAeA;iBC3KgB,SAAA,MAAe,MAAA,CAAO,kBAAkB;;;AAAxD;AASA;AA2BA;AA4CA;;iBAvEgB,SAAA,wBAAiC,iBAAiB;;ACJlE;AAeA;;;;ACzCA;AAeA;;iBF0CgB,OAAA,SAAgB;;;;;;;;;;iBA4ChB,OAAA,SAAgB;;;;;;ADzDhC;AAmDA;AAkFA;AAegB,iBEtKA,SAAA,CFsKoC,KAAA,EEtKnB,UFsK6B,CAAA,EAAA,MAAA;;;;AC3K9D;AASA;AA2BA;AA4CgB,iBC5DA,SAAA,CD4DgB,KAAU,EAAA,MAAA,CAAA,EC5DA,UD4DA;;;;;;ADzD1C;AAmDA;AAkFA;AAegB,iBGhMA,mBAAA,CHgMoC,MAAU,CAAA,EAAA,MAAA,CAAA,EGhMJ,UHgMI;;;;AC3K9D;AASA;AA2BA;AA4CA;;;;AC3EA;AAegB,iBC1BA,oBAAA,CD0BoC,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA"}
@@ -0,0 +1,117 @@
1
+ import { BinaryLike, KeyObject } from "node:crypto";
2
+
3
+ //#region src/base-64.d.ts
4
+
5
+ /**
6
+ * Encodes a Uint8Array into a Base64 encoded Uint8Array.
7
+ *
8
+ * @credit https://github.com/hi-ogawa/js-utils
9
+ *
10
+ * @param input - The input Uint8Array or string to encode.
11
+ * @returns The Base64 encoded Uint8Array.
12
+ */
13
+ declare function encodeBase64(input: Uint8Array | string): string;
14
+ /**
15
+ * Decodes a Base64 encoded Uint8Array into a Uint8Array.
16
+ *
17
+ * @credit https://github.com/hi-ogawa/js-utils
18
+ *
19
+ * @param input - The Base64 encoded Uint8Array or string to decode.
20
+ * @returns The decoded Uint8Array.
21
+ */
22
+ declare function decodeBase64(input: Uint8Array | string): Uint8Array;
23
+ /**
24
+ * Converts a Base64 encoded string to a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string.
25
+ *
26
+ * @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
27
+ *
28
+ * @param base64 - The Base64 encoded string to convert.
29
+ * @returns The Base64url encoded string.
30
+ */
31
+ declare function base64UrlEncode(base64: Uint8Array): string;
32
+ /**
33
+ * Converts a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string to a Base64 encoded string.
34
+ *
35
+ * @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
36
+ *
37
+ * @param base64url - The Base64url encoded string to convert.
38
+ * @returns The Base64 encoded string.
39
+ */
40
+ declare function base64UrlDecode(base64url: string): Uint8Array;
41
+ //#endregion
42
+ //#region src/encryption.node.d.ts
43
+ /**
44
+ * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
45
+ *
46
+ * @param key - The key to use when creating the \`KeyObject\`.
47
+ * @returns The new \`KeyObject\`.
48
+ */
49
+ declare function createKey(key: NodeJS.ArrayBufferView): KeyObject;
50
+ /**
51
+ * Creates and returns a new key object containing a secret key for symmetric encryption or \`Hmac\`.
52
+ *
53
+ * @param key - The key to use. If \`key\` is a \`Buffer\`, \`TypedArray\`, or \`DataView\`, the \`encoding\` argument is ignored.
54
+ * @param encoding - The \`encoding\` of the \`key\` string. Must be one of \`'utf8'\`, \`'utf16le'\`, \`'latin1'\`, or \`'base64'\`. Default is \`'utf8'\`.
55
+ * @returns The new \`KeyObject\`.
56
+ */
57
+ declare function createKey(key: string, encoding: BufferEncoding): KeyObject;
58
+ /**
59
+ * Symmetrically encrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
60
+ *
61
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
62
+ *
63
+ * @param secret - The secret key used for encryption.
64
+ * @param plaintext - The data to encrypt.
65
+ * @returns The encrypted data.
66
+ */
67
+ declare function encrypt(secret: BinaryLike, plaintext: string): string;
68
+ /**
69
+ * Symmetrically decrypts data using the [ChaCha20-Poly1305](https://en.wikipedia.org/wiki/ChaCha20-Poly1305) cipher.
70
+ *
71
+ * @see https://en.wikipedia.org/wiki/ChaCha20-Poly1305
72
+ *
73
+ * @param secret - The secret key used for decryption.
74
+ * @param encrypted - The encrypted data to decrypt.
75
+ * @returns The decrypted data.
76
+ */
77
+ declare function decrypt(secret: BinaryLike, encrypted: string): string;
78
+ //#endregion
79
+ //#region src/hex.d.ts
80
+ /**
81
+ * Encodes a Uint8Array into a hexadecimal string.
82
+ *
83
+ * @param input - The input Uint8Array.
84
+ * @returns The hexadecimal string.
85
+ */
86
+ declare function encodeHex(input: Uint8Array): string;
87
+ /**
88
+ * Encodes a Uint8Array into an uppercase hexadecimal string.
89
+ *
90
+ * @param input - The input Uint8Array.
91
+ * @returns The uppercase hexadecimal string.
92
+ */
93
+ declare function decodeHex(input: string): Uint8Array;
94
+ //#endregion
95
+ //#region src/random.d.ts
96
+ /**
97
+ * Generate a random byte array of the specified length using the Web Crypto API.
98
+ *
99
+ * @param length - The length of the random byte array to generate (default is 32 bytes)
100
+ * @returns A Uint8Array containing random bytes of the specified length
101
+ */
102
+ declare function generateRandomBytes(length?: number): Uint8Array;
103
+ /**
104
+ * Generate a random string of the specified length using characters A-Z, a-z, and 0-9 for CSRF tokens, etc.
105
+ *
106
+ * @remarks
107
+ * This function uses the Web Crypto API's `crypto.getRandomValues` to generate secure random bytes,
108
+ * and then maps those bytes to characters in the specified character set. It uses rejection sampling
109
+ * to ensure a uniform distribution of characters without modulo bias.
110
+ *
111
+ * @param length - The length of the random string to generate (default is 32 characters)
112
+ * @returns A random string of the specified length
113
+ */
114
+ declare function generateRandomString(length?: number): string;
115
+ //#endregion
116
+ export { base64UrlDecode, base64UrlEncode, createKey, decodeBase64, decodeHex, decrypt, encodeBase64, encodeHex, encrypt, generateRandomBytes, generateRandomString };
117
+ //# sourceMappingURL=node.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.mts","names":[],"sources":["../src/base-64.ts","../src/encryption.node.ts","../src/hex.ts","../src/random.ts"],"sourcesContent":[],"mappings":";;;;;;;AAoEA;AAmDA;AAkFA;AAeA;;iBApJgB,YAAA,QAAoB;;ACvBpC;AASA;AA2BA;AA4CA;;;;AC3EgB,iBFqEA,YAAA,CErEiB,KAAU,EFqEP,UErEO,GAAA,MAAA,CAAA,EFqEe,UErEf;AAe3C;;;;ACzCA;AAeA;;;iBHkKgB,eAAA,SAAwB;;;;;;;;;iBAexB,eAAA,qBAAoC;;;;;AApJpD;AAmDA;AAkFA;AAeA;iBC3KgB,SAAA,MAAe,MAAA,CAAO,kBAAkB;;;AAAxD;AASA;AA2BA;AA4CA;;iBAvEgB,SAAA,wBAAiC,iBAAiB;;ACJlE;AAeA;;;;ACzCA;AAeA;;iBF0CgB,OAAA,SAAgB;;;;;;;;;;iBA4ChB,OAAA,SAAgB;;;;;;ADzDhC;AAmDA;AAkFA;AAegB,iBEtKA,SAAA,CFsKoC,KAAA,EEtKnB,UFsK6B,CAAA,EAAA,MAAA;;;;AC3K9D;AASA;AA2BA;AA4CgB,iBC5DA,SAAA,CD4DgB,KAAU,EAAA,MAAA,CAAA,EC5DA,UD4DA;;;;;;ADzD1C;AAmDA;AAkFA;AAegB,iBGhMA,mBAAA,CHgM8C,MAAA,CAAA,EAAA,MAAA,CAAA,EGhMJ,UHgMI;;;;AC3K9D;AASA;AA2BA;AA4CA;;;;AC3EA;AAegB,iBC1BA,oBAAA,CD0BoC,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA"}