npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lagoware/capacitor-key-manager

v0.1.1

Published

Utilize and store encryption and signing keys

Downloads

71

Readme

@lagoware/capacitor-key-manager

Utilize and store encryption and signing keys.

  • [x] Android
  • [x] Web
  • [ ] iOS (PRs welcome)

Key Storage

Android

Keys are stored in the Android Key Store.

Web

Keys are stored as non-extractable Web Crypto keys in an IndexedDB database. Please note that your keys may be at risk of eviction by the browser unless your app successfully requests persistent storage.

Install

npm install @lagoware/capacitor-key-manager
npx cap sync

API

checkAliasExists(...)

checkAliasExists(options: { keyAlias: string; }) => Promise<{ aliasExists: boolean; }>

Checks if a key or key pair exists in the key store under the provided alias.

| Param | Type | | ------------- | ---------------------------------- | | options | { keyAlias: string; } |

Returns: Promise<{ aliasExists: boolean; }>


generateKey(...)

generateKey(options: { keyAlias: string; }) => Promise<void>

Generates a key that can be used for symmetric encryption / decryption. The underlying key material cannot be recovered, therefore encryption / decryption will only be possible on this device.

| Param | Type | | ------------- | ---------------------------------- | | options | { keyAlias: string; } |


generateRecoverableSignatureKeyPair(...)

generateRecoverableSignatureKeyPair(options: { password: string; salt?: string; }) => Promise<{ recoverableKeyPair: RecoverableKeyPair; }>

Generates a key pair that can be used for signing and verifying strings. The private key will be encrypted with the provided password and if provided, (base64-encoded) salt (otherwise a random salt will be generated). The generated key pair is returned in a structure of base64-encoded strings that may later be used to recover the key into the key store.

| Param | Type | | ------------- | ------------------------------------------------- | | options | { password: string; salt?: string; } |

Returns: Promise<{ recoverableKeyPair: RecoverableKeyPair; }>


generateRecoverableAgreementKeyPair(...)

generateRecoverableAgreementKeyPair(options: { password: string; salt?: string; }) => Promise<{ recoverableKeyPair: RecoverableKeyPair; }>

Generates a key pair that can be used for deriving key agreement secrets. The private key will be encrypted with the provided password and if provided, (base64-encoded) salt (otherwise a random salt will be generated). The generated key pair is returned in a structure of base64-encoded strings that may later be used to recover the key into the key store.

| Param | Type | | ------------- | ------------------------------------------------- | | options | { password: string; salt?: string; } |

Returns: Promise<{ recoverableKeyPair: RecoverableKeyPair; }>


generateRecoverableKey(...)

generateRecoverableKey(options: { password: string; salt?: string; }) => Promise<{ recoverableKey: RecoverableKey; }>

Generates a key that can be used for symmetrical encryption / decryption. The key will be encrypted with the provided password and if provided, (base64-encoded) salt (otherwise a random salt will be generated). The generated key is returned as a structure of base64-encoded strings that may later be used to recover the key into the key store.

| Param | Type | | ------------- | ------------------------------------------------- | | options | { password: string; salt?: string; } |

Returns: Promise<{ recoverableKey: RecoverableKey; }>


importPublicSignatureKey(...)

importPublicSignatureKey(options: { alias: string; publicKey: string; }) => Promise<void>

Imports a public key into the key store. The key may then be used for verifying signatures. The key is expected to be in base64-encoded spki format.

| Param | Type | | ------------- | -------------------------------------------------- | | options | { alias: string; publicKey: string; } |


importPublicAgreementKey(...)

importPublicAgreementKey(options: { alias: string; publicKey: string; }) => Promise<void>

Imports a public key into the key store. The key may then be used to derive key agreement secrets. The key is expected to be in base64-encoded spki format.

| Param | Type | | ------------- | -------------------------------------------------- | | options | { alias: string; publicKey: string; } |


reWrapSignatureKeyPair(...)

reWrapSignatureKeyPair(options: { currentPassword: string; newPassword: string; newSalt?: string; recoverableKeyPair: RecoverableKeyPair; }) => Promise<{ recoverableKeyPair: RecoverableKeyPair; }>

Re-wraps a recoverable signature key pair with a new password.

| Param | Type | | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | options | { currentPassword: string; newPassword: string; newSalt?: string; recoverableKeyPair: RecoverableKeyPair; } |

Returns: Promise<{ recoverableKeyPair: RecoverableKeyPair; }>


reWrapAgreementKeyPair(...)

reWrapAgreementKeyPair(options: { currentPassword: string; newPassword: string; newSalt?: string; recoverableKeyPair: RecoverableKeyPair; }) => Promise<{ recoverableKeyPair: RecoverableKeyPair; }>

Re-wraps a recoverable agreement key pair with a new password.

| Param | Type | | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | options | { currentPassword: string; newPassword: string; newSalt?: string; recoverableKeyPair: RecoverableKeyPair; } |

Returns: Promise<{ recoverableKeyPair: RecoverableKeyPair; }>


reWrapKey(...)

reWrapKey(options: { currentPassword: string; newPassword: string; newSalt?: string; recoverableKey: RecoverableKey; }) => Promise<{ recoverableKey: RecoverableKey; }>

Re-wraps a recoverable key with a new password.

| Param | Type | | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | options | { currentPassword: string; newPassword: string; newSalt?: string; recoverableKey: RecoverableKey; } |

Returns: Promise<{ recoverableKey: RecoverableKey; }>


recoverKey(...)

recoverKey(options: { alias: string; recoverableKey: RecoverableKey; password: string; }) => Promise<void>

Imports a previously-generated recoverable key into the key store. If the provided password matches the password used when the key was generated, it will be decrypted and saved into the key store. It may then be used to encrypt and decrypt values.

| Param | Type | | ------------- | --------------------------------------------------------------------------------------------------------------- | | options | { alias: string; recoverableKey: RecoverableKey; password: string; } |


recoverSignatureKeyPair(...)

recoverSignatureKeyPair(options: { alias: string; recoverableKeyPair: RecoverableKeyPair; password: string; }) => Promise<void>

Imports a previously-generated recoverable signature key pair into the key store. If the provided password matches the password used when the key pair was generated, it will be decrypted and saved into the key store. It may then be used to sign and verify signatures.

| Param | Type | | ------------- | --------------------------------------------------------------------------------------------------------------------------- | | options | { alias: string; recoverableKeyPair: RecoverableKeyPair; password: string; } |


recoverAgreementKeyPair(...)

recoverAgreementKeyPair(options: { alias: string; recoverableKeyPair: RecoverableKeyPair; password: string; }) => Promise<void>

Imports a previously-generated recoverable agreement key pair into the key store. If the provided password matches the password used when the key pair was generated, it will be decrypted and saved into the key store. It may then be used to derive key agreement secrets.

| Param | Type | | ------------- | --------------------------------------------------------------------------------------------------------------------------- | | options | { alias: string; recoverableKeyPair: RecoverableKeyPair; password: string; } |


encrypt(...)

encrypt(options: { keyAlias: string; cleartext: string; }) => Promise<{ encryptedMessage: EncryptedMessage; }>

Encrypts a string with a previously generated / recovered key. The encrypted string is returned in a structure of base64-encoded strings.

| Param | Type | | ------------- | ----------------------------------------------------- | | options | { keyAlias: string; cleartext: string; } |

Returns: Promise<{ encryptedMessage: EncryptedMessage; }>


decrypt(...)

decrypt(options: { keyAlias: string; encryptedMessage: EncryptedMessage; }) => Promise<{ cleartext: string; }>

Decrypts a string with a previously generated / recovered key.

| Param | Type | | ------------- | ------------------------------------------------------------------------------------------------------ | | options | { keyAlias: string; encryptedMessage: EncryptedMessage; } |

Returns: Promise<{ cleartext: string; }>


encryptWithAgreedKey(...)

encryptWithAgreedKey(options: { privateKeyAlias: string; publicKeyAlias: string; cleartext: string; info?: string; }) => Promise<{ encryptedMessage: EncryptedMessage; }>

Encrypts a string with a key derived from the provided private and public agreement keys. If info parameter is provided, it will be used to further derive the key before encryption.

| Param | Type | | ------------- | --------------------------------------------------------------------------------------------------- | | options | { privateKeyAlias: string; publicKeyAlias: string; cleartext: string; info?: string; } |

Returns: Promise<{ encryptedMessage: EncryptedMessage; }>


decryptWithAgreedKey(...)

decryptWithAgreedKey(options: { privateKeyAlias: string; publicKeyAlias: string; encryptedMessage: EncryptedMessage; info?: string; }) => Promise<{ cleartext: string; }>

Decrypts a string with a key derived from the provided private and public agreement keys. If info parameter is provided, it will be used to further derive the key before decryption.

| Param | Type | | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | options | { privateKeyAlias: string; publicKeyAlias: string; encryptedMessage: EncryptedMessage; info?: string; } |

Returns: Promise<{ cleartext: string; }>


sign(...)

sign(options: { keyAlias: string; cleartext: string; }) => Promise<{ signature: string; }>

Signs a string with a previously generated / recovered signature key pair.

| Param | Type | | ------------- | ----------------------------------------------------- | | options | { keyAlias: string; cleartext: string; } |

Returns: Promise<{ signature: string; }>


verify(...)

verify(options: { keyAlias: string; cleartext: string; signature: string; }) => Promise<{ isValid: boolean; }>

Verifies a signature with a previously generated / recovered signature key pair or imported public key.

| Param | Type | | ------------- | ------------------------------------------------------------------------ | | options | { keyAlias: string; cleartext: string; signature: string; } |

Returns: Promise<{ isValid: boolean; }>


Type Aliases

RecoverableKeyPair

{ privateKey: RecoverableKey, publicKey: string }

RecoverableKey

EncryptedMessage & { salt: string }

EncryptedMessage

{ ciphertext: string, iv: string }