Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to public npm. #1

Merged
merged 20 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2d5fba0
Added testing with vitest against juce implementation with cmake.
ianacaburian Sep 25, 2024
2b9e7fe
Added basic readme instructions.
ianacaburian Sep 25, 2024
db8e73a
Fixed readme > usage.
ianacaburian Sep 25, 2024
f9a67b8
Refined project testing structure.
ianacaburian Sep 26, 2024
edeebe7
Drafted loadBigintFromUTF8 covering base case that excludes special c…
ianacaburian Sep 26, 2024
f24d73f
Util loadBigintFromUTF8 done. Tested OK with 1000 random inputs.
ianacaburian Sep 27, 2024
3e9751e
Improved loadBigintFromUTF8 bypassing intermediate strings. Upgraded …
ianacaburian Sep 27, 2024
291212d
Added createKeyFileContentLine. Tested with 1000 runs OK. Updated doc…
ianacaburian Sep 28, 2024
aa71592
Added encryptBigint with naive math. WIP as base case failing.
ianacaburian Sep 28, 2024
b71b901
Added JuceBigInteger with divideBy testing OK.
ianacaburian Sep 29, 2024
87838b1
Added jsbn for mod pow in exponentModulo. Discovered bug in juce BigI…
ianacaburian Sep 30, 2024
df41349
Added exponentModulo with juce fork fixing issue #1431. Tested with 1…
ianacaburian Sep 30, 2024
92ba48c
Update README.md
ianacaburian Sep 30, 2024
e65600f
Added JuceRSAKey with applyToValue testing OK. Bumped to v0.0.6
ianacaburian Oct 2, 2024
cb28ebd
Added JuceKeyGeneration. Restructured project. Bumped to v0.0.7
ianacaburian Oct 2, 2024
bec5243
Added key gen and file util tests. Bumped to v0.0.8
ianacaburian Oct 2, 2024
3336e24
Added expiring key gen tests. Basic tests OK. Bumped to v0.0.9
ianacaburian Oct 3, 2024
ebf4f71
Added formatting to sort import statements. Ready for alpha testing. …
ianacaburian Oct 3, 2024
01c9d8b
Added gh action workflow to build and test.
ianacaburian Oct 3, 2024
314e48e
Added npm install.
ianacaburian Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: build

on:
workflow_dispatch:
pull_request:
branches: ['master']

env:
HOMEBREW_NO_INSTALL_CLEANUP: 1

jobs:
build_and_test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- name: macOS
os: macos-14

steps:
- name: Installing OSX utils
if: ${{ matrix.name == 'macOS' }}
run: brew install osxutils

- name: Checking out code
uses: actions/checkout@v3
with:
submodules: true

- name: Install dependencies
run: npm install

- name: Lint, install tests, and build package.
run: npm run build

- name: Perform single test run.
run: npm run test run
18 changes: 18 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.cache
.next
.build
CHANGELOG.md
.contentlayer
coverage
postgres/migrations
dist
*.log
node_modules
.package-lock.json
package.json
pnpm-lock.yaml
public
*.sql
.yarn
*.html
tsconfig.json
22 changes: 19 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"semi": false,
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
"trailingComma": "none",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"printWidth": 80,
"tabWidth": 4
"jsxSingleQuote": true,
"proseWrap": "always",
"arrowParens": "avoid",
"importOrder": [
"",
"<BUILTIN_MODULES>",
"^react/(.*)$|^react$",
"^next/(.*)$|^next$",
"<THIRD_PARTY_MODULES>",
"",
"^(lib|app)(/.*)$",
"^[.]",
"",
".css$"
],
"importOrderParserPlugins": ["typescript", "jsx", "decorators-legacy"]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"istream": "cpp"
}
}
111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,112 @@
# generate-key-file

Provides juce_KeyGeneration::generateKeyFile() for javascript.
Ports juce_KeyGeneration::generateKeyFile() to node.

# Installation

```
npm i @ianacaburian/generate-key-file
```

# Usage

### `generateKeyFile(params: GenerateKeyFileParams, date: Date = new Date()) => string`

```
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'
})
```

- 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
*/
```

- Returns the <key> 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).

### `generateExpiringKeyFile(params: GenerateExpiringKeyFileParams, date: Date = new Date()) => string`

```
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
})
```

- 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
*/
```

- Returns the <key> 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).

# 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 clean:test # Clean test build.
npm run open:test/console # Open test/console project in Xcode.
npm run install:test/console # 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.
```
41 changes: 41 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pluginJs from '@eslint/js'
import prettierConfig from 'eslint-config-prettier'
import prettierPlugin from 'eslint-plugin-prettier'
import globals from 'globals'
import tseslint from 'typescript-eslint'

export default [
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
files: ['**/*.{js,mjs,cjs,ts}'],
ignores: [
'dist/**',
'test/**',
'.cache/**',
'public/**',
'node_modules/**',
'*.esm.js'
],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
},
globals: {
...globals.browser
}
},
plugins: {
'@typescript-eslint': tseslint.plugin,
prettier: prettierPlugin
},
rules: {
...tseslint.configs.recommended.rules,
...prettierConfig.rules,
...prettierPlugin.configs.recommended.rules,
'@typescript-eslint/no-unused-vars': 'off'
}
}
]
Loading
Loading