https://github.com/ianacaburian/generate-key-file
Ports juce_KeyGeneration::generateKeyFile() to node.
https://github.com/ianacaburian/generate-key-file
auth cmake cpp20 cryptography juce keyfile nodejs npm rsa typescript
Last synced: about 1 year ago
JSON representation
Ports juce_KeyGeneration::generateKeyFile() to node.
- Host: GitHub
- URL: https://github.com/ianacaburian/generate-key-file
- Owner: ianacaburian
- License: mit
- Created: 2024-09-25T15:40:55.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2024-10-11T07:16:19.000Z (over 1 year ago)
- Last Synced: 2024-10-11T07:56:09.681Z (over 1 year ago)
- Topics: auth, cmake, cpp20, cryptography, juce, keyfile, nodejs, npm, rsa, typescript
- Language: TypeScript
- Homepage:
- Size: 15.3 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# generate-key-file
Ports juce_KeyGeneration::generateKeyFile() to node.
[](https://github.com/ianacaburian/generate-key-file/actions)
[](https://www.npmjs.com/package/@ianacaburian/generate-key-file)
[](https://twitter.com/intent/tweet?text=Need%20to%20auth%20a%20JUCE%20app%20in%20nodejs%20%3F%20Check%20out%20generate-key-file%20by%20%40ianacaburian%20%20&url=https%3A%2F%2Fgithub.com%2Fianacaburian%2Fgenerate-key-file)
## Installation
```
npm i @ianacaburian/generate-key-file
```
## Usage
### `generateKeyFile`
- Signature:
```
generateKeyFile(params: GenerateKeyFileParams, date: Date = new Date()) => string
```
- Example:
```
import { generateKeyFile } from '@ianacaburian/generate-key-file'
const keyFileContent = generateKeyFile({
userName: 'Ian',
userEmail: 'ian@email.com',
machineNumbers: '123',
appName: 'app-name-or-product-id',
privateKey: 'comma-sep-private-key'
})
```
- Returns the string value to be used in the XML response for decryption
by the client.
- Throws ZodError for invalid params -- see
[zod](https://github.com/colinhacks/zod).
- From juce_KeyFileGeneration.h:
```
/**
Generates the content of a key-file which can be sent to a user's machine to
unlock a product.
The returned value is a block of text containing an RSA-encoded block, followed
by some human-readable details. If you pass this block of text to
OnlineUnlockStatus::applyKeyFile(), it will decrypt it, and if the
key matches and the machine numbers match, it will unlock that machine.
Typically the way you'd use this on a server would be to build a small executable
that simply calls this method and prints the result, so that the webserver can
use this as a reply to the product's auto-registration mechanism. The
keyGenerationAppMain() function is an example of how to build such a function.
@see OnlineUnlockStatus
*/
```
### `generateExpiringKeyFile`
- Signature:
```
generateExpiringKeyFile(params: GenerateExpiringKeyFileParams, date: Date = new Date()) => string
```
- Example:
```
import { generateExpiringKeyFile } from '@ianacaburian/generate-key-file'
const oneDayFromNow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000)
const expiringKeyFileContent = generateExpiringKeyFile({
userName: 'Ian',
userEmail: 'ian@email.com',
machineNumbers: '123',
appName: 'app-name-or-product-id',
privateKey: 'comma-sep-private-key'
expiryTime: oneDayFromNow
})
```
- Returns the string value to be used in the XML response for decryption
by the client.
- Throws ZodError for invalid params -- see
[zod](https://github.com/colinhacks/zod).
- From juce_KeyFileGeneration.h:
```
/** Similar to the above key file generation method but with an expiry time.
You must supply a Time after which this key file should no longer be considered as active.
N.B. when an app is unlocked with an expiring key file, OnlineUnlockStatus::isUnlocked will
still return false. You must then check OnlineUnlockStatus::getExpiryTime to see if this
expiring key file is still in date and act accordingly.
@see OnlineUnlockStatus
*/
```
## Development
```
npm run clean # Clean dist and test builds (inc test bins).
npm run lint # Lint the src dir.
npm run build # Lint, install tests, and build package.
```
### Testing
```
npm run test # Start vitest to run all tests.
npm run test -- -t "divideBy" # Start vitest to run one test.
npm run cm:clean # Clean test build.
npm run cm:open # Open test/console project in Xcode.
npm run cm:install # Build and install the test/console bins.
```
- Optional: Set "FC_NUM_RUMS" (default=1) to specify how many times to run
each (randomly generated) propery-based test -- see
[fast-check](https://github.com/dubzzz/fast-check).
```
FC_NUM_RUNS=1000 npm run test # Run each fc test 1000 times.
```
- Optional: Set "FC_SEED" (default=1) to specify the seed for each fc test.
```
FC_SEED=2 npm run test # Run each fc test with seed=2.
```