Skip to content

Commit aa70b63

Browse files
author
A.P.A. Slaa
committed
fix(npm): added examples and fixed mismatch in package.json
1 parent ff19e3c commit aa70b63

6 files changed

Lines changed: 100 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,20 @@ natural syntax.
2929
```typescript
3030
import {openssl} from '@sourceregistry/node-openssl';
3131

32+
3233
async function main() {
3334
// Generate a 2048-bit RSA private key
3435
const key = await openssl`genpkey -algorithm RSA -outform PEM -pkeyopt rsa_keygen_bits:2048`.one();
3536
console.log('Private Key:\n', key.data);
3637
console.log('SHA-256:', key.sha256);
3738

3839
// Generate a self-signed certificate
39-
const cert = await openssl`req -x509 -new -key <(echo "${key.data}") -subj "/CN=localhost" -days 365 -outform PEM`.one();
40+
const cert = await openssl`req -x509 -new -key ${key} -subj "/CN=localhost" -days 365 -outform PEM`.one();
4041
console.log('Certificate:\n', cert.data);
4142
console.log('Is Certificate Chain?', cert.isChain);
4243
}
4344

44-
main();
45+
main().catch(console.error);
4546
```
4647

4748
### Working with Output Buffers

examples/digest-sha256.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {openssl} from "../src";
2+
3+
async function main() {
4+
//Digest buffer and output digest;
5+
const data = Buffer.from("Helloworld")
6+
const digested = await openssl`dgst -sha256 ${data}`.one();
7+
console.log(digested.toString('utf-8').split("=")[1].trim()) //(Not ideal yet)
8+
}
9+
10+
main().catch(console.error);

examples/server-cert.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {openssl} from "../src";
2+
3+
async function main() {
4+
// Generate a 2048-bit RSA private key
5+
const key = await openssl`genpkey -algorithm RSA -outform PEM -pkeyopt rsa_keygen_bits:2048`.one();
6+
console.log('Private Key:\n', key.data);
7+
console.log('SHA-256:', key.sha256);
8+
9+
// Generate a self-signed certificate
10+
const cert = await openssl`req -x509 -new -key ${key} -subj "/CN=localhost" -days 365 -outform PEM`.one();
11+
console.log('Certificate:\n', cert.data);
12+
console.log('Is Certificate Chain?', cert.isChain);
13+
}
14+
15+
main().catch(console.error);

examples/version.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {openssl} from "../src";
2+
3+
console.log(openssl.version)

package-lock.json

Lines changed: 50 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,30 @@
1818
"dev": "vite",
1919
"build": "tsc && vite build",
2020
"preview": "vite preview",
21-
"test": "vitest"
21+
"test": "vitest",
22+
"example::server-cert": "tsx examples/server-cert.ts",
23+
"example::version": "tsx examples/version",
24+
"example::digest-sha256": "tsx examples/digest-sha256"
2225
},
2326
"repository": {
2427
"type": "git",
2528
"url": "git+https://github.com/SourceRegistry/node-openssl.git"
2629
},
27-
"keywords": [],
30+
"keywords": [
31+
"openssl",
32+
"ssl",
33+
"cert",
34+
"pem",
35+
"key",
36+
"privatekey",
37+
"publickey",
38+
"certificate",
39+
"certificates",
40+
"chain",
41+
"https"
42+
],
2843
"author": "A.P.A. Slaa (a.p.a.slaa@projectsource.nl)",
29-
"license": "ISC",
44+
"license": "Apache-2.0",
3045
"type": "module",
3146
"bugs": {
3247
"url": "https://github.com/SourceRegistry/node-openssl/issues"
@@ -41,6 +56,7 @@
4156
"vite": "^7.1.3",
4257
"vite-plugin-dts": "^4.5.4",
4358
"vitest": "^3.2.4",
59+
"tsx": "^4.20.4",
4460
"@semantic-release/commit-analyzer": "^13.0.1",
4561
"@semantic-release/release-notes-generator": "^14.0.3",
4662
"@semantic-release/changelog": "^6.0.3",

0 commit comments

Comments
 (0)