Skip to content

Commit

Permalink
Improve APIs and initial functionality (#13)
Browse files Browse the repository at this point in the history
* Improvements

* Cleanup

* working

* cleanup and update docs

* Add changeset

* cleanup

* add electron as a peer dependency
  • Loading branch information
WyattMufson authored Aug 26, 2024
1 parent 2d54c24 commit 14dabf8
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 272 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-flies-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-passkey': minor
---

Greatly simplify api, major fixes to functionality
23 changes: 7 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,20 @@ Native module for electron applications to use passkey funcitonality in macOS ap
```js
import { ipcRenderer } from 'electron';

navigator.credentials.create = function (options) {
return ipcRenderer.invoke('webauthn-create', options);
};
navigator.credentials.create = (options) =>
Passkey.getInstance().attachCreateToRenderer(ipcRenderer, options);

navigator.credentials.get = function (options) {
return ipcRenderer.invoke('webauthn-get', options);
};
navigator.credentials.get = (options) =>
Passkey.getInstance().attachGetToRenderer(ipcRenderer, options);
```

2) Forward calls in main process

```js
import { ipcMain } from 'electron';
import Passkey from 'electron-passkey';

Passkey.getInstance().init('domain.com');

ipcMain.handle('webauthn-create', (event, options) => {
return Passkey.getInstance().handlePasskeyCreate(options);
});

ipcMain.handle('webauthn-get', (event, options) => {
return Passkey.getInstance().handlePasskeyGet(options);
});
Passkey.getInstance().attachHandlersToMain('domain.com', ipcMain);
```

### Entitlements Setup
Expand All @@ -54,7 +45,7 @@ ipcMain.handle('webauthn-get', (event, options) => {
</array>
```
7) Check to see if your AASA is being cached by the Apple CDN at `https://app-site-association.cdn-apple.com/a/v1/DOMAIN`
8) Make sure to call `Passkey.getInstance().init()` and pass in your domain
8) Make sure to pass in your domain to `attachHandlersToMain()`
9) Build your electron application and sign it

### Deployments
Expand Down
193 changes: 107 additions & 86 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,107 +1,128 @@
import promise from "eslint-plugin-promise";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import promise from 'eslint-plugin-promise';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import importPlugin from 'eslint-plugin-import';
import { FlatCompat } from "@eslint/eslintrc";
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [{
ignores: ["**/build/", "**/dist/", "**/prebuilds/", '**/*.config.*'],
}, ...compat.extends(
"airbnb-base",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"eslint:recommended",
), {
export default [
{
ignores: ['**/build/', '**/dist/', '**/prebuilds/', '**/*.config.*'],
},
...compat.extends(
'airbnb-base',
'plugin:prettier/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'eslint:recommended',
),
{
files: ['**/*.js', '**/*.ts', '**/*.mjs'],
plugins: {
promise,
importPlugin,
promise,
import: importPlugin,
},

languageOptions: {
globals: {
navigator: 'readonly',
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
ecmaVersion: 2020,
sourceType: "module",
},
},

parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: __dirname,
createDefaultProgram: true,
},
languageOptions: {
globals: {
navigator: 'readonly',
window: 'readonly',
},
ecmaVersion: 2020,
sourceType: 'module',

parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
createDefaultProgram: true,
},
},

rules: {
"import/no-named-as-default": "off",
"import/no-named-as-default-member": "off",
"@typescript-eslint/no-require-imports": "off",
"import/newline-after-import": "off",
"import/no-amd": "off",
"import/no-mutable-exports": "off",
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "error",
"no-console": "off",
"max-len": "off",
"no-await-in-loop": "off",
"no-async-promise-executor": "error",
"promise/always-return": "off",
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/catch-or-return": "error",
"promise/no-native": "off",
"promise/no-nesting": "off",
"promise/no-promise-in-callback": "off",
"promise/no-callback-in-promise": "off",
"promise/avoid-new": "off",
"promise/no-new-statics": "error",
"promise/no-return-in-finally": "warn",
"promise/valid-params": "warn",
"no-bitwise": "off",
"no-underscore-dangle": "off",
"no-throw-literal": "off",
"no-case-declarations": "off",
"function-paren-newline": "off",
"default-param-last": "off",
"comma-dangle": "off",
"compat/compat": "off",
"operator-linebreak": "off",
"class-methods-use-this": "off",
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-alert": "off",
"jsx-a11y/label-has-associated-control": "off",
"no-continue": "off",
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'@typescript-eslint/no-require-imports': 'off',
'import/newline-after-import': 'off',
'import/no-amd': 'off',
'import/no-mutable-exports': 'off',
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': 'error',
'no-console': 'off',
'max-len': 'off',
'no-await-in-loop': 'off',
'no-async-promise-executor': 'error',
'promise/always-return': 'off',
'promise/no-return-wrap': 'error',
'promise/param-names': 'error',
'promise/catch-or-return': 'error',
'promise/no-native': 'off',
'promise/no-nesting': 'off',
'promise/no-promise-in-callback': 'off',
'promise/no-callback-in-promise': 'off',
'promise/avoid-new': 'off',
'promise/no-new-statics': 'error',
'promise/no-return-in-finally': 'warn',
'promise/valid-params': 'warn',
'no-bitwise': 'off',
'no-underscore-dangle': 'off',
'no-throw-literal': 'off',
'no-case-declarations': 'off',
'function-paren-newline': 'off',
'default-param-last': 'off',
'comma-dangle': 'off',
'compat/compat': 'off',
'operator-linebreak': 'off',
'class-methods-use-this': 'off',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-alert': 'off',
'jsx-a11y/label-has-associated-control': 'off',
'no-continue': 'off',

"import/extensions": ["error", "ignorePackages", {
js: "never",
jsx: "never",
ts: "never",
tsx: "never",
}],
'import/extensions': [
'error',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],

"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"no-param-reassign": "off",
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'no-param-reassign': 'off',

"@typescript-eslint/member-ordering": ["error", {
classes: "never",
interfaces: ["field", "signature", "method", "constructor"],
}],
'@typescript-eslint/member-ordering': [
'error',
{
classes: 'never',
interfaces: ['field', 'signature', 'method', 'constructor'],
},
],

"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
},
}];
},
];
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"eslint": "9.9.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-lit": "1.14.0",
"eslint-plugin-prettier": "5.2.1",
Expand All @@ -42,6 +43,9 @@
"prettier": "3.3.3",
"typescript": "5.5.4"
},
"peerDependencies": {
"electron": "^31.4.0"
},
"dependencies": {
"node-addon-api": "^8.1.0",
"node-gyp": "10.2.0",
Expand Down
Loading

0 comments on commit 14dabf8

Please sign in to comment.