1.0.1 • Published 10 months ago

@ianacaburian/generate-key-file v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

generate-key-file

Ports juce_KeyGeneration::generateKeyFile() to node.

GitHub Actions Workflow Status NPM Version X (formerly Twitter) URL

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.
  • 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.
  • 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.
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.
1.0.1

10 months ago

1.0.0

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago