@push.rocks/smartcrypto 2.4.0 → 2.5.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/dist_ts/00_commitinfo_data.js +1 -1
- package/package.json +4 -2
- package/readme.md +20 -2
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartcrypto',
|
|
6
|
-
version: '2.
|
|
6
|
+
version: '2.5.0',
|
|
7
7
|
description: 'A library providing easy methods for cryptographic operations, including key pair generation.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx5QkFBeUI7SUFDL0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLCtGQUErRjtDQUM3RyxDQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartcrypto",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A library providing easy methods for cryptographic operations, including key pair generation.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
|
7
7
|
"typings": "dist_ts/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./dist_ts/index.js",
|
|
10
|
+
"./hash": "./dist_ts/smartcrypto.hash.js",
|
|
10
11
|
"./node": "./dist_ts_node/index.js"
|
|
11
12
|
},
|
|
12
13
|
"author": "Task Venture Capital GmbH",
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"devDependencies": {
|
|
15
|
-
"@git.zone/tsbuild": "^5.
|
|
16
|
+
"@git.zone/tsbuild": "^5.1.0",
|
|
16
17
|
"@git.zone/tsrun": "^3.0.2",
|
|
17
18
|
"@git.zone/tstest": "^6.3.2",
|
|
18
19
|
"@types/node": "^26.6.2"
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"last 1 chrome versions"
|
|
41
42
|
],
|
|
42
43
|
"type": "module",
|
|
44
|
+
"sideEffects": false,
|
|
43
45
|
"keywords": [
|
|
44
46
|
"cryptography",
|
|
45
47
|
"encryption",
|
package/readme.md
CHANGED
|
@@ -141,6 +141,22 @@ const streamDigest = await sha256FromStream(response.body!);
|
|
|
141
141
|
|
|
142
142
|
`createSha256Hasher()` returns an `ISha256Hasher`. `update()` accepts `ArrayBuffer` or `Uint8Array` values and returns the hasher for chaining; `digest()` finalizes it, and any later `update()` or `digest()` call fails with `INVALID_STATE`. `sha256FromStream()` reads a `ReadableStream<Uint8Array>` chunk by chunk with bounded memory and always releases the reader lock; a non-byte chunk cancels the stream and fails with `INVALID_ARGUMENT`, and a source error is rethrown unchanged.
|
|
143
143
|
|
|
144
|
+
### Hashing Entry
|
|
145
|
+
|
|
146
|
+
`@push.rocks/smartcrypto/hash` exports exactly the package-entry hashing functions and `ISha256Hasher`, and its module graph contains no third-party code. Use it in browser code that reaches the hashing functions through a re-exported namespace, such as a `plugins.ts` import hub:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// plugins.ts
|
|
150
|
+
import * as smartcrypto from '@push.rocks/smartcrypto/hash';
|
|
151
|
+
export { smartcrypto };
|
|
152
|
+
|
|
153
|
+
// elsewhere
|
|
154
|
+
import * as plugins from './plugins.js';
|
|
155
|
+
const digest = plugins.smartcrypto.createSha256Hasher().update(bytes).digest();
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
esbuild does not tree-shake a namespace that is re-exported and then read through two property accesses (`plugins.smartcrypto.createSha256Hasher`); it keeps every export of the imported module. Through the package entry that includes the `nodeForge` export and therefore all of `node-forge` (about 310 KB minified); through `/hash` the same pattern stays a few kilobytes. Named imports from the package entry are tree-shaken either way.
|
|
159
|
+
|
|
144
160
|
### Node.js Entry
|
|
145
161
|
|
|
146
162
|
`@push.rocks/smartcrypto/node` exports the same hashing functions backed by `node:crypto`, plus file and MD5 hashing. It runs in Node.js and Deno.
|
|
@@ -162,7 +178,7 @@ const checksum = await md5FromString('legacy payload');
|
|
|
162
178
|
|
|
163
179
|
`sha256FromStream()` here accepts a Node.js `Readable` or a WHATWG `ReadableStream<Uint8Array>`. Node.js readables may emit bytes or strings (hashed as UTF-8); any other chunk fails with `INVALID_ARGUMENT` and destroys the stream. `sha256FromFile()` streams the file, so file-system errors such as `ENOENT` are rethrown unchanged. MD5 is cryptographically broken; use `md5FromString()` only for checksums that an external protocol requires.
|
|
164
180
|
|
|
165
|
-
| Function | `@push.rocks/smartcrypto` | `@push.rocks/smartcrypto/node` |
|
|
181
|
+
| Function | `@push.rocks/smartcrypto` and `/hash` | `@push.rocks/smartcrypto/node` |
|
|
166
182
|
|---|---|---|
|
|
167
183
|
| `sha256FromString(string)` | WebCrypto | `node:crypto` |
|
|
168
184
|
| `sha256FromStringSync(string)` | built-in SHA-256 | `node:crypto` |
|
|
@@ -211,6 +227,8 @@ Passphrases are asymmetric between export and import: `toEncryptedPemString('')`
|
|
|
211
227
|
|
|
212
228
|
The WebCrypto APIs, including encrypted private-key PEMs, and the package-entry hashing functions are tested with Node.js 22 and current Chromium. Browsers require a secure context for WebCrypto. The `@push.rocks/smartcrypto/node` entry is tested with Node.js 22 and Deno.
|
|
213
229
|
|
|
230
|
+
The package declares `"sideEffects": false`, and no module does work at import time. Browser bundlers such as esbuild, Rollup, Rolldown and webpack therefore keep only what a bundle imports: a bundle that uses only the hashing functions stays a few kilobytes and does not include `node-forge`, which only the RSA APIs, encrypted private-key PEMs and the `nodeForge` export load.
|
|
231
|
+
|
|
214
232
|
## Migration from @push.rocks/smartkey
|
|
215
233
|
|
|
216
234
|
`@push.rocks/smartkey` is deprecated; RSA key pairs and passphrase-encrypted private keys live in this package.
|
|
@@ -225,7 +243,7 @@ The WebCrypto APIs, including encrypted private-key PEMs, and the package-entry
|
|
|
225
243
|
|
|
226
244
|
## Migration from @push.rocks/smarthash
|
|
227
245
|
|
|
228
|
-
`@push.rocks/smarthash` is deprecated; its hashing functions live in this package with the same names and byte-identical digests. Node.js code imports from `@push.rocks/smartcrypto/node`, browser code (formerly `@push.rocks/smarthash/web`) from `@push.rocks/smartcrypto
|
|
246
|
+
`@push.rocks/smarthash` is deprecated; its hashing functions live in this package with the same names and byte-identical digests. Node.js code imports from `@push.rocks/smartcrypto/node`, browser code (formerly `@push.rocks/smarthash/web`) from `@push.rocks/smartcrypto`, or from `@push.rocks/smartcrypto/hash` when it re-exports the import as a namespace (see [Hashing Entry](#hashing-entry)).
|
|
229
247
|
|
|
230
248
|
| `@push.rocks/smarthash` | `@push.rocks/smartcrypto` |
|
|
231
249
|
|---|---|
|