tiny-essentials 1.2.0 โ 1.3.0
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/README.md +3 -3
- package/dist/TinyBasicsEs.js +51 -14
- package/dist/TinyBasicsEs.min.js +1 -1
- package/dist/TinyEssentials.js +2372 -77014
- package/dist/TinyEssentials.min.js +1 -1
- package/dist/TinyEssentials.min.js.LICENSE.txt +0 -2
- package/dist/TinyLevelUp.js +9 -9
- package/dist/legacy/crypto/decrypt.cjs +1 -0
- package/dist/legacy/crypto/decrypt.mjs +1 -0
- package/dist/legacy/crypto/default.cjs +2 -0
- package/dist/legacy/crypto/default.mjs +1 -0
- package/dist/legacy/crypto/encrypt.cjs +2 -1
- package/dist/legacy/crypto/encrypt.mjs +1 -0
- package/dist/legacy/crypto/index.cjs +1 -1
- package/dist/legacy/crypto/index.mjs +1 -0
- package/dist/legacy/firebase/cookieSession.cjs +2 -0
- package/dist/legacy/firebase/cookieSession.mjs +1 -0
- package/dist/legacy/firebase/database/index.cjs +3 -0
- package/dist/legacy/firebase/database/index.mjs +1 -0
- package/dist/legacy/firebase/database/presence.cjs +3 -0
- package/dist/legacy/firebase/database/presence.mjs +1 -0
- package/dist/legacy/firebase/database/saveAsync.cjs +2 -0
- package/dist/legacy/firebase/database/saveAsync.mjs +1 -0
- package/dist/legacy/firebase/databaseEscape.cjs +3 -0
- package/dist/legacy/firebase/databaseEscape.mjs +1 -0
- package/dist/legacy/firebase/databaseLogger.cjs +3 -0
- package/dist/legacy/firebase/databaseLogger.mjs +1 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.cjs +3 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getToken.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getToken.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getUser.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getUser.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.mjs +1 -0
- package/dist/legacy/firebase/discord/api/index.cjs +3 -0
- package/dist/legacy/firebase/discord/api/index.mjs +1 -0
- package/dist/legacy/firebase/discord/api/refreshToken.cjs +3 -0
- package/dist/legacy/firebase/discord/api/refreshToken.mjs +1 -0
- package/dist/legacy/firebase/discord/api/revokeToken.cjs +3 -0
- package/dist/legacy/firebase/discord/api/revokeToken.mjs +1 -0
- package/dist/legacy/firebase/discord/config.cjs +2 -0
- package/dist/legacy/firebase/discord/config.mjs +1 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.cjs +3 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.mjs +1 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.cjs +2 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.mjs +1 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.cjs +2 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.mjs +1 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.cjs +3 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.mjs +1 -0
- package/dist/legacy/firebase/discord/get/cookie-session.cjs +3 -0
- package/dist/legacy/firebase/discord/get/cookie-session.mjs +1 -0
- package/dist/legacy/firebase/discord/get/credentials.cjs +2 -0
- package/dist/legacy/firebase/discord/get/credentials.mjs +1 -0
- package/dist/legacy/firebase/discord/get/errorValidator.cjs +3 -0
- package/dist/legacy/firebase/discord/get/errorValidator.mjs +1 -0
- package/dist/legacy/firebase/discord/get/index.cjs +3 -0
- package/dist/legacy/firebase/discord/get/index.mjs +1 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.cjs +3 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.mjs +1 -0
- package/dist/legacy/firebase/discord/http/index.cjs +3 -0
- package/dist/legacy/firebase/discord/http/index.mjs +1 -0
- package/dist/legacy/firebase/discord/http/login.cjs +3 -0
- package/dist/legacy/firebase/discord/http/login.mjs +1 -0
- package/dist/legacy/firebase/discord/http/logout.cjs +3 -0
- package/dist/legacy/firebase/discord/http/logout.mjs +1 -0
- package/dist/legacy/firebase/discord/http/redirect.cjs +3 -0
- package/dist/legacy/firebase/discord/http/redirect.mjs +1 -0
- package/dist/legacy/firebase/discord/http/refreshToken.cjs +3 -0
- package/dist/legacy/firebase/discord/http/refreshToken.mjs +1 -0
- package/dist/legacy/firebase/discord/index.cjs +3 -0
- package/dist/legacy/firebase/discord/index.mjs +1 -0
- package/dist/legacy/firebase/discord/template/cookie-session.cjs +3 -0
- package/dist/legacy/firebase/discord/template/cookie-session.mjs +1 -0
- package/dist/legacy/firebase/domainRedirect.cjs +2 -0
- package/dist/legacy/firebase/domainRedirect.mjs +1 -0
- package/dist/legacy/firebase/escape.cjs +2 -0
- package/dist/legacy/firebase/escape.mjs +1 -0
- package/dist/legacy/firebase/getDBAsync.cjs +2 -0
- package/dist/legacy/firebase/getDBAsync.mjs +1 -0
- package/dist/legacy/firebase/getDBData.cjs +3 -0
- package/dist/legacy/firebase/getDBData.mjs +1 -0
- package/dist/legacy/firebase/getDBValue.cjs +2 -0
- package/dist/legacy/firebase/getDBValue.mjs +1 -0
- package/dist/legacy/firebase/index.cjs +3 -0
- package/dist/legacy/firebase/index.mjs +1 -0
- package/dist/legacy/firebase/isEmulator.cjs +2 -0
- package/dist/legacy/firebase/isEmulator.mjs +1 -0
- package/dist/legacy/firebase/logger.cjs +3 -0
- package/dist/legacy/firebase/logger.mjs +1 -0
- package/dist/legacy/firebase/mySQL.cjs +3 -0
- package/dist/legacy/firebase/mySQL.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/create.cjs +2 -0
- package/dist/legacy/firebase/mysqlConnector/create.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/index.cjs +3 -0
- package/dist/legacy/firebase/mysqlConnector/index.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.cjs +2 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.cjs +2 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +3 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.mjs +1 -0
- package/dist/legacy/firebase/transactionDBAsync.cjs +2 -0
- package/dist/legacy/firebase/transactionDBAsync.mjs +1 -0
- package/dist/legacy/get/countObj.cjs +3 -0
- package/dist/legacy/get/countObj.mjs +1 -0
- package/dist/legacy/get/decimalColor.cjs +3 -0
- package/dist/legacy/get/decimalColor.mjs +1 -0
- package/dist/legacy/get/objType.cjs +2 -0
- package/dist/legacy/get/objType.mjs +1 -0
- package/dist/legacy/get/pagination.cjs +3 -0
- package/dist/legacy/get/pagination.mjs +1 -0
- package/dist/legacy/get/queryUrlByName.cjs +2 -0
- package/dist/legacy/get/queryUrlByName.mjs +1 -0
- package/dist/legacy/get/queryUrlJSON.cjs +2 -0
- package/dist/legacy/get/queryUrlJSON.mjs +1 -0
- package/dist/legacy/get/super_string_filter.cjs +3 -0
- package/dist/legacy/get/super_string_filter.mjs +1 -0
- package/dist/legacy/get/versionCheck.cjs +2 -1
- package/dist/legacy/get/versionCheck.mjs +1 -0
- package/dist/legacy/http/HTTP-1.0.cjs +2 -0
- package/dist/legacy/http/HTTP-1.0.mjs +1 -0
- package/dist/legacy/http/auth.cjs +2 -0
- package/dist/legacy/http/auth.mjs +1 -0
- package/dist/legacy/http/check_domain.cjs +2 -0
- package/dist/legacy/http/check_domain.mjs +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +2 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +1 -0
- package/dist/legacy/http/domainValidator.cjs +3 -0
- package/dist/legacy/http/domainValidator.mjs +1 -0
- package/dist/legacy/http/errorsCallback.cjs +2 -0
- package/dist/legacy/http/errorsCallback.mjs +1 -0
- package/dist/legacy/http/fetch/json.cjs +3 -0
- package/dist/legacy/http/fetch/json.mjs +1 -0
- package/dist/legacy/http/fetch/text.cjs +3 -0
- package/dist/legacy/http/fetch/text.mjs +1 -0
- package/dist/legacy/http/fileCache.cjs +3 -0
- package/dist/legacy/http/fileCache.mjs +1 -0
- package/dist/legacy/http/getDomainURL.cjs +3 -0
- package/dist/legacy/http/getDomainURL.mjs +1 -0
- package/dist/legacy/http/userIP.cjs +3 -0
- package/dist/legacy/http/userIP.mjs +1 -0
- package/dist/legacy/index.cjs +3 -0
- package/dist/legacy/index.mjs +1 -0
- package/dist/legacy/libs/arraySortPositions.cjs +2 -0
- package/dist/legacy/libs/arraySortPositions.mjs +1 -0
- package/dist/legacy/libs/capitalize.cjs +2 -0
- package/dist/legacy/libs/capitalize.mjs +1 -0
- package/dist/legacy/libs/convertBytes.cjs +2 -0
- package/dist/legacy/libs/convertBytes.mjs +1 -0
- package/dist/legacy/libs/custom_module_loader.cjs +3 -0
- package/dist/legacy/libs/custom_module_loader.mjs +1 -0
- package/dist/legacy/libs/dice.cjs +2 -0
- package/dist/legacy/libs/dice.mjs +1 -0
- package/dist/legacy/libs/markdown.cjs +2 -0
- package/dist/legacy/libs/markdown.mjs +1 -0
- package/dist/legacy/libs/percentage.cjs +2 -0
- package/dist/legacy/libs/percentage.mjs +1 -0
- package/dist/legacy/libs/regex/getLetter.cjs +2 -0
- package/dist/legacy/libs/regex/getLetter.mjs +1 -0
- package/dist/legacy/libs/replaceAsync.cjs +3 -0
- package/dist/legacy/libs/replaceAsync.mjs +3 -0
- package/dist/legacy/libs/rule3.cjs +2 -0
- package/dist/legacy/libs/rule3.mjs +1 -0
- package/dist/legacy/libs/userLevel.cjs +9 -9
- package/dist/legacy/libs/userLevel.d.mts +39 -16
- package/dist/legacy/libs/userLevel.mjs +9 -9
- package/dist/legacy/momentjs/getAge.cjs +3 -0
- package/dist/legacy/momentjs/getAge.mjs +1 -0
- package/dist/legacy/momentjs/index.cjs +1 -1
- package/dist/legacy/momentjs/index.mjs +1 -0
- package/dist/legacy/momentjs/timeDuration.cjs +3 -0
- package/dist/legacy/momentjs/timeDuration.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/index.cjs +1 -1
- package/dist/legacy/socket.io/antiFlood/index.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +3 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +3 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +1 -0
- package/dist/legacy/socket.io/cookie-session.cjs +2 -0
- package/dist/legacy/socket.io/cookie-session.mjs +1 -0
- package/dist/legacy/socket.io/discord.cjs +3 -0
- package/dist/legacy/socket.io/discord.mjs +1 -0
- package/dist/legacy/socket.io/index.cjs +3 -0
- package/dist/legacy/socket.io/index.mjs +1 -0
- package/dist/v1/basics/clock.cjs +43 -13
- package/dist/v1/basics/clock.mjs +31 -13
- package/dist/v1/basics/objFilter.cjs +4 -0
- package/dist/v1/basics/objFilter.mjs +3 -0
- package/dist/v1/basics/simpleMath.cjs +1 -1
- package/dist/v1/basics/simpleMath.mjs +1 -1
- package/dist/v1/index.cjs +0 -4
- package/dist/v1/index.d.mts +1 -3
- package/dist/v1/index.mjs +1 -3
- package/docs/README.md +1 -11
- package/package.json +2 -5
- package/dist/TinyCertCrypto.js +0 -76229
- package/dist/TinyCertCrypto.min.js +0 -2
- package/dist/TinyCertCrypto.min.js.LICENSE.txt +0 -10
- package/dist/TinyCrypto.js +0 -48115
- package/dist/TinyCrypto.min.js +0 -2
- package/dist/TinyCrypto.min.js.LICENSE.txt +0 -10
- package/dist/v1/build/TinyCertCrypto.cjs +0 -7
- package/dist/v1/build/TinyCertCrypto.d.mts +0 -2
- package/dist/v1/build/TinyCertCrypto.mjs +0 -2
- package/dist/v1/build/TinyCrypto.cjs +0 -7
- package/dist/v1/build/TinyCrypto.d.mts +0 -2
- package/dist/v1/build/TinyCrypto.mjs +0 -2
- package/dist/v1/libs/TinyCertCrypto.cjs +0 -514
- package/dist/v1/libs/TinyCertCrypto.d.mts +0 -191
- package/dist/v1/libs/TinyCertCrypto.mjs +0 -450
- package/dist/v1/libs/TinyCrypto.cjs +0 -603
- package/dist/v1/libs/TinyCrypto.d.mts +0 -268
- package/dist/v1/libs/TinyCrypto.mjs +0 -581
- package/docs/libs/TinyCertCrypto.md +0 -202
- package/docs/libs/TinyCrypto.md +0 -177
- package/webpack.config.mjs +0 -69
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
# โจ Tiny Cert Crypto
|
|
2
|
-
|
|
3
|
-
A lightweight ๐ utility for managing, generating, and handling **X.509 certificates** and **RSA key pairs**.
|
|
4
|
-
Built with flexibility in mind โ runs seamlessly in both **Node.js** and **browser** environments! ๐
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## ๐ฆ Features
|
|
9
|
-
|
|
10
|
-
- ๐ ๏ธ RSA key pair generation (**Node.js only**)
|
|
11
|
-
- ๐งพ Self-signed X.509 certificate creation
|
|
12
|
-
- ๐งฌ Support for PEM-based ๐ public/private keys and certificates
|
|
13
|
-
- ๐ง JSON encryption & decryption using Base64 encoding
|
|
14
|
-
- ๐ต๏ธ Metadata extraction from certificates (issuer, subject, validity, etc.)
|
|
15
|
-
- ๐ Flexible key loading: from memory, local files (Node.js), or URLs (browser)
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## ๐ Getting Started
|
|
20
|
-
|
|
21
|
-
### ๐ Constructor
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
const instance = new TinyCertCrypto({
|
|
25
|
-
publicCertPath: 'cert.pem', // Path to public cert (Node.js)
|
|
26
|
-
privateKeyPath: 'key.pem', // Path to private key (Node.js)
|
|
27
|
-
publicCertBuffer: null, // String or Buffer in memory (Node.js/browser)
|
|
28
|
-
privateKeyBuffer: null, // String or Buffer in memory (Node.js/browser)
|
|
29
|
-
cryptoType: 'RSA-OAEP', // Encryption algorithm (default: 'RSA-OAEP')
|
|
30
|
-
});
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
> ๐ In **browser environments**, at least `publicCertPath` or `publicCertBuffer` must be provided.
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## ๐งช Core Methods
|
|
38
|
-
|
|
39
|
-
### ๐ง `async init()`
|
|
40
|
-
Initializes the certificate and key system from files, memory buffers, or URLs.
|
|
41
|
-
|
|
42
|
-
- Loads the public certificate/key.
|
|
43
|
-
- Optionally loads the private key.
|
|
44
|
-
- Detects whether youโre running in Node.js or the browser and adjusts behavior accordingly.
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
### ๐ `extractCertMetadata()`
|
|
49
|
-
Returns parsed metadata from the loaded certificate.
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
{
|
|
53
|
-
subject: { names: {}, shortNames: {}, raw: "CN=example.com,O=MyOrg" },
|
|
54
|
-
issuer: { names: {}, shortNames: {}, raw: "CN=example.com,O=MyOrg" },
|
|
55
|
-
serialNumber: '...',
|
|
56
|
-
validFrom: Date,
|
|
57
|
-
validTo: Date
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
### ๐ก๏ธ `encryptJson(jsonObject)`
|
|
64
|
-
Encrypts a JavaScript object using the loaded **public key**, returning a **Base64-encoded string**.
|
|
65
|
-
|
|
66
|
-
```js
|
|
67
|
-
const encrypted = instance.encryptJson({ hello: "world" });
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
### ๐ `decryptToJson(base64String)`
|
|
73
|
-
Decrypts a Base64 string using the **private key**, returning the original JSON object.
|
|
74
|
-
|
|
75
|
-
```js
|
|
76
|
-
const json = instance.decryptToJson(encrypted);
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
### ๐ `hasKeys()`
|
|
82
|
-
Returns `true` if both `publicKey` and `privateKey` are loaded.
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
### ๐ `hasCert()`
|
|
87
|
-
Returns `true` if a certificate (`publicCert`) is loaded.
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
### โป๏ธ `reset()`
|
|
92
|
-
Resets the internal state, clearing:
|
|
93
|
-
- `publicKey`
|
|
94
|
-
- `privateKey`
|
|
95
|
-
- `publicCert`
|
|
96
|
-
- `metadata`
|
|
97
|
-
- `source`
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
### ๐ฆ `fetchNodeForge()` & `getNodeForge()`
|
|
102
|
-
Handles lazy-loading and reuse of the `node-forge` module.
|
|
103
|
-
|
|
104
|
-
Use if you want to access Forge directly without importing it yourself:
|
|
105
|
-
|
|
106
|
-
```js
|
|
107
|
-
const forge = await instance.fetchNodeForge();
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## ๐ง Internals & Design
|
|
113
|
-
|
|
114
|
-
- ๐ Uses regular expressions to detect PEM types (`CERTIFICATE`, `PUBLIC KEY`, `PRIVATE KEY`)
|
|
115
|
-
- ๐งช Automatically parses PEM buffers and files depending on the runtime
|
|
116
|
-
- ๐ Encrypts data with the selected algorithm (`RSA-OAEP`, etc.)
|
|
117
|
-
- ๐งฌ X.509 certificate metadata extraction is done via `node-forge`
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## ๐งฐ Requirements
|
|
122
|
-
|
|
123
|
-
| Environment | Requirement |
|
|
124
|
-
|-------------|--------------------|
|
|
125
|
-
| Node.js | `node-forge` |
|
|
126
|
-
| Browser | Works with native `fetch()` and `TextDecoder` |
|
|
127
|
-
|
|
128
|
-
---
|
|
129
|
-
|
|
130
|
-
## ๐บ Example Use Case
|
|
131
|
-
|
|
132
|
-
```js
|
|
133
|
-
const crypto = new TinyCertCrypto({ publicCertPath: 'cert.pem', privateKeyPath: 'key.pem' });
|
|
134
|
-
await crypto.init();
|
|
135
|
-
|
|
136
|
-
const data = { secret: 'I love ponies' };
|
|
137
|
-
const encrypted = crypto.encryptJson(data);
|
|
138
|
-
const decrypted = crypto.decryptToJson(encrypted);
|
|
139
|
-
|
|
140
|
-
console.log(decrypted); // { secret: 'I love ponies' }
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
### ๐งพ `async generateX509Cert(subjectFields, options = {})`
|
|
146
|
-
Generates a new **RSA key pair** and a **self-signed X.509 certificate** using the provided subject information.
|
|
147
|
-
|
|
148
|
-
๐ This is ideal for internal services, development environments, or cryptographic testing tools where a trusted CA is not required.
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
**๐งฌ Parameters:**
|
|
153
|
-
|
|
154
|
-
- `subjectFields` (`Object`) โ Describes the identity fields that will be embedded into the certificate's subject and issuer:
|
|
155
|
-
- Common fields include:
|
|
156
|
-
- `CN`: Common Name (e.g. domain or hostname)
|
|
157
|
-
- `O`: Organization Name
|
|
158
|
-
- `OU`: Organizational Unit
|
|
159
|
-
- `L`: Locality (City)
|
|
160
|
-
- `ST`: State or Province
|
|
161
|
-
- `C`: Country (2-letter code)
|
|
162
|
-
- `emailAddress`: Optional email field
|
|
163
|
-
|
|
164
|
-
- `options` (`Object`) โ Optional configuration:
|
|
165
|
-
- `keySize` (`number`) โ RSA key size in bits (default: `2048`)
|
|
166
|
-
- `validityInYears` (`number`) โ Certificate validity period (default: `1`)
|
|
167
|
-
- `randomBytesLength` (`number`) โ Length of the serial number (default: `16`)
|
|
168
|
-
- `digestAlgorithm` (`string`) โ Digest algorithm used to sign the certificate (default: `'sha256'`)
|
|
169
|
-
- `forgeInstance` (`object`) โ Optionally inject a specific instance of `node-forge`
|
|
170
|
-
- `cryptoType` (`string`) โ Encryption scheme used for later operations (e.g., `'RSA-OAEP'`, `'RSAES-PKCS1-V1_5'`)
|
|
171
|
-
|
|
172
|
-
---
|
|
173
|
-
|
|
174
|
-
**โ
Returns:**
|
|
175
|
-
|
|
176
|
-
An object containing all the generated artifacts:
|
|
177
|
-
|
|
178
|
-
```js
|
|
179
|
-
{
|
|
180
|
-
publicKey: '-----BEGIN PUBLIC KEY-----...',
|
|
181
|
-
privateKey: '-----BEGIN PRIVATE KEY-----...',
|
|
182
|
-
cert: '-----BEGIN CERTIFICATE-----...'
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
- `publicKey`: The newly generated **PEM-encoded RSA public key**
|
|
187
|
-
- `privateKey`: The corresponding **PEM-encoded RSA private key**
|
|
188
|
-
- `cert`: A **PEM-encoded X.509 certificate** that is **self-signed** with the private key and matches the provided subject
|
|
189
|
-
|
|
190
|
-
---
|
|
191
|
-
|
|
192
|
-
**๐ Notes:**
|
|
193
|
-
|
|
194
|
-
- ๐ The `subject` and `issuer` of the certificate are the same (self-signed).
|
|
195
|
-
- โณ The certificate `validFrom` is set to the current date, and `validTo` is based on the `validityInYears` option.
|
|
196
|
-
- ๐ข A secure random `serialNumber` is generated using `crypto.randomBytes`.
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
**โ ๏ธ Availability:**
|
|
201
|
-
|
|
202
|
-
> This method is only available in **Node.js environments** due to its dependency on the native `crypto` module and synchronous file access via `fs`.
|
package/docs/libs/TinyCrypto.md
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
# ๐ Tiny Crypto
|
|
2
|
-
|
|
3
|
-
**Tiny Crypto** is a flexible and browser-compatible encryption utility class built for AES-256-GCM encryption with full support for serialization and deserialization of complex JavaScript data types.
|
|
4
|
-
|
|
5
|
-
Whether you're in Node.js or a browser, Tiny Crypto helps you easily encrypt/decrypt values, save/load configurations, and keep your secrets safe โ all while supporting real-world usage like RegExp, Date, Buffer, and even DOM elements (in browsers only)!
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## โจ Features
|
|
10
|
-
|
|
11
|
-
- ๐ AES-256-GCM symmetric encryption
|
|
12
|
-
- ๐ง Automatic serialization of complex types (Date, RegExp, Set, Map, etc.)
|
|
13
|
-
- ๐ค Save and load keys/configs from files
|
|
14
|
-
- ๐ Works in both **Node.js** and **Browsers**
|
|
15
|
-
- โ ๏ธ Type validation on decryption
|
|
16
|
-
- ๐พ Smart support for file APIs (e.g. `FileReader` in browser, `fs` in Node)
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## ๐ Getting Started
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
const crypto = new TinyCrypto();
|
|
24
|
-
|
|
25
|
-
// Encrypt some data
|
|
26
|
-
const { encrypted, iv, authTag } = crypto.encrypt({ hello: 'world' });
|
|
27
|
-
|
|
28
|
-
// Decrypt it back
|
|
29
|
-
const decrypted = crypto.decrypt({ encrypted, iv, authTag });
|
|
30
|
-
|
|
31
|
-
console.log(decrypted); // { hello: 'world' }
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## ๐ง Supported Data Types
|
|
37
|
-
|
|
38
|
-
When you encrypt a value, its type is recorded and restored when decrypted.
|
|
39
|
-
|
|
40
|
-
Supports:
|
|
41
|
-
|
|
42
|
-
- `String`, `Number`, `Boolean`, `BigInt`, `Null`, `Undefined`
|
|
43
|
-
- `Array`, `Object`, `Map`, `Set`, `Buffer`
|
|
44
|
-
- `RegExp`, `Date`, `Symbol`
|
|
45
|
-
- `HTMLElement` _(browser only)_
|
|
46
|
-
|
|
47
|
-
Does NOT support:
|
|
48
|
-
|
|
49
|
-
- `Function`, `Promise`, `WeakMap`, `WeakSet` โ โ Will throw!
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## ๐ง API
|
|
54
|
-
|
|
55
|
-
### `constructor(options)`
|
|
56
|
-
|
|
57
|
-
| Option | Type | Default | Description |
|
|
58
|
-
| ---------------- | ------ | --------------- | --------------------------------- |
|
|
59
|
-
| `algorithm` | string | `'aes-256-gcm'` | AES algorithm used for encryption |
|
|
60
|
-
| `key` | Buffer | auto-generated | The secret key to use (32 bytes) |
|
|
61
|
-
| `outputEncoding` | string | `'hex'` | Encoding used for outputs |
|
|
62
|
-
| `inputEncoding` | string | `'utf8'` | Encoding used for plain data |
|
|
63
|
-
| `authTagLength` | number | `16` | GCM auth tag length |
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
### `encrypt(data, iv?)`
|
|
68
|
-
|
|
69
|
-
Encrypts a value and returns an object with `{ iv, encrypted, authTag }`.
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
const result = crypto.encrypt('Hello!');
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
### `decrypt({ iv, encrypted, authTag }, expectedType?)`
|
|
78
|
-
|
|
79
|
-
Decrypts a previously encrypted value and returns the original data. You can optionally pass an `expectedType` to validate it.
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
const plain = crypto.decrypt(result, 'string');
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
### `getTypeFromEncrypted({ iv, encrypted, authTag })`
|
|
88
|
-
|
|
89
|
-
Returns the type name of the encrypted data without fully decrypting it.
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
### `generateKey(length = 32)`
|
|
94
|
-
|
|
95
|
-
Generates a secure random key. Default: 32 bytes (AES-256).
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
### `generateIV(length = 12)`
|
|
100
|
-
|
|
101
|
-
Generates a secure random IV. Default: 12 bytes (GCM standard).
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
### `saveKeyToFile(filename = 'secret.key')`
|
|
106
|
-
|
|
107
|
-
Saves the current key to a file (browser: prompts download).
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
### `loadKeyFromFile(file)`
|
|
112
|
-
|
|
113
|
-
Loads a key from a file (browser: File object, Node: file path).
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
### `saveConfigToFile(filename = 'crypto-config.json')`
|
|
118
|
-
|
|
119
|
-
Saves the current configuration as JSON.
|
|
120
|
-
|
|
121
|
-
---
|
|
122
|
-
|
|
123
|
-
### `loadConfigFromFile(file)`
|
|
124
|
-
|
|
125
|
-
Loads configuration from a JSON file.
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
### `exportConfig()`
|
|
130
|
-
|
|
131
|
-
Returns an object with the current settings:
|
|
132
|
-
|
|
133
|
-
```json
|
|
134
|
-
{
|
|
135
|
-
"algorithm": "aes-256-gcm",
|
|
136
|
-
"outputEncoding": "hex",
|
|
137
|
-
"inputEncoding": "utf8",
|
|
138
|
-
"authTagLength": 16,
|
|
139
|
-
"key": "..."
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
### `importConfig(config)`
|
|
146
|
-
|
|
147
|
-
Applies a configuration object. Throws if invalid types are provided.
|
|
148
|
-
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
## ๐งช Type Validation
|
|
152
|
-
|
|
153
|
-
You can ensure the decrypted value matches the original type:
|
|
154
|
-
|
|
155
|
-
```js
|
|
156
|
-
crypto.decrypt(result, 'map'); // โ
|
|
157
|
-
crypto.decrypt(result, 'set'); // โ throws if type mismatch
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
## โ Errors You Might See
|
|
163
|
-
|
|
164
|
-
- `Unsupported data type for encryption: Function`
|
|
165
|
-
- `Type mismatch: expected Map, but got Set`
|
|
166
|
-
- `Invalid config JSON file`
|
|
167
|
-
- `HTMLElement deserialization is only supported in browsers`
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## ๐ก๏ธ Security Notice
|
|
172
|
-
|
|
173
|
-
This utility is for learning and light usage. For production, ensure:
|
|
174
|
-
|
|
175
|
-
- Proper key management (use secure vaults)
|
|
176
|
-
- Safe IV reuse (IVs must be unique per encryption)
|
|
177
|
-
- Your platform's crypto standards are followed
|
package/webpack.config.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
import webpack from 'webpack';
|
|
4
|
-
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
|
|
9
|
-
// Add modules
|
|
10
|
-
const modules = [];
|
|
11
|
-
const addModule = (entry, library, isClass = false) => {
|
|
12
|
-
const baseConfig = {
|
|
13
|
-
entry,
|
|
14
|
-
output: {
|
|
15
|
-
path: path.resolve(__dirname, 'dist'),
|
|
16
|
-
library,
|
|
17
|
-
libraryTarget: 'window',
|
|
18
|
-
libraryExport: isClass ? library : undefined,
|
|
19
|
-
},
|
|
20
|
-
optimization: {
|
|
21
|
-
runtimeChunk: false,
|
|
22
|
-
splitChunks: false,
|
|
23
|
-
},
|
|
24
|
-
plugins: [
|
|
25
|
-
new NodePolyfillPlugin(),
|
|
26
|
-
new webpack.ProvidePlugin({
|
|
27
|
-
process: 'process/browser',
|
|
28
|
-
}),
|
|
29
|
-
],
|
|
30
|
-
};
|
|
31
|
-
modules.push(
|
|
32
|
-
// Non-minified version
|
|
33
|
-
{
|
|
34
|
-
...baseConfig,
|
|
35
|
-
mode: 'development',
|
|
36
|
-
output: {
|
|
37
|
-
...baseConfig.output,
|
|
38
|
-
filename: `${library}.js`,
|
|
39
|
-
},
|
|
40
|
-
optimization: {
|
|
41
|
-
...baseConfig.optimization,
|
|
42
|
-
minimize: false,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
// Minified version
|
|
46
|
-
{
|
|
47
|
-
...baseConfig,
|
|
48
|
-
mode: 'production',
|
|
49
|
-
output: {
|
|
50
|
-
...baseConfig.output,
|
|
51
|
-
filename: `${library}.min.js`,
|
|
52
|
-
},
|
|
53
|
-
optimization: {
|
|
54
|
-
...baseConfig.optimization,
|
|
55
|
-
minimize: true,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Main
|
|
62
|
-
addModule('./src/v1/index.mjs', 'TinyEssentials');
|
|
63
|
-
addModule('./src/v1/basics/index.mjs', 'TinyBasicsEs');
|
|
64
|
-
|
|
65
|
-
addModule('./src/v1/build/TinyLevelUp.mjs', 'TinyLevelUp', true);
|
|
66
|
-
addModule('./src/v1/build/TinyCertCrypto.mjs', 'TinyCertCrypto', true);
|
|
67
|
-
addModule('./src/v1/build/TinyCrypto.mjs', 'TinyCrypto', true);
|
|
68
|
-
|
|
69
|
-
export default modules;
|