An open API service indexing awesome lists of open source software.

https://github.com/mikescops/node-native-keychain

🔐 Node.js native macos keychain module written in Swift
https://github.com/mikescops/node-native-keychain

keychain koffi macos napi node nodejs

Last synced: 2 months ago
JSON representation

🔐 Node.js native macos keychain module written in Swift

Awesome Lists containing this project

README

          

# Node Native Keychain

![GitHub package.json version](https://img.shields.io/github/package-json/v/mikescops/node-native-keychain)
![npm](https://img.shields.io/npm/v/native-keychain)
![npm](https://img.shields.io/npm/dw/native-keychain)
![GitHub](https://img.shields.io/github/license/mikescops/node-native-keychain)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/mikescops/node-native-keychain/pr-validation.yml)

This is a TypeScript library to store and retrieve secure information from the macos keychain. It is a wrapper around the native keychain APIs on macOS built in Swift and bindings with Koffi.

## Installation

```bash
npm install native-keychain
```

## Usage

> **Note:** For the moment, we only store [Generic passwords](https://developer.apple.com/documentation/security/ksecclassgenericpassword) in the keychain.

```typescript
import * as keychain from 'native-keychain';

keychain.setPassword({
service: 'my-service',
account: 'my-account',
password: 'my-password'
});

const secret = await keychain.getPassword({
service: 'my-service',
account: 'my-account',
requireBiometrics: true
}); // 'my-password'
```

## Available methods

| Method | Description | Output |
| ------------------------------- | -------------------------------------- | ------------------ |
| `getPassword` | Retrieve a password from the keychain. | `Promise` |
| `setPassword` | Store a password in the keychain. | `void` |
| `deletePassword` | Delete a password from the keychain. | `void` |
| `isBiometricsSupported` | Check if biometrics is supported. | `boolean` |
| `requestBiometricsVerification` | Request biometrics verification. | `Promise` |

## Development

### Running Tests

```bash
npm run test
```

**Note:** The tests require user interaction for biometric authentication. When prompted, please authenticate using Touch ID, Face ID, or your system password to complete the biometric verification tests.

The test suite includes:

- Biometric support verification
- Password storage and retrieval with accounts
- Biometric-protected password operations
- Cleanup and error handling

### Building

```bash
npm run build
```

### Linting

```bash
npm run lint
```

## Maintainer

| [![twitter/mikescops](https://avatars0.githubusercontent.com/u/4266283?s=100&v=4)](https://pixelswap.fr 'Personal Website') |
| --------------------------------------------------------------------------------------------------------------------------- |
| [Corentin Mors](https://pixelswap.fr/) |