Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@perfood/capacitor-crypto-api

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@perfood/capacitor-crypto-api

Capacitor plugin that uses Secure Enclave (iOS) or StrongBox/TEE (Android) to generate key-pairs and sign data.

  • 1.0.0-0
  • beta
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
58
increased by152.17%
Maintainers
0
Weekly downloads
 
Created
Source

@perfood/capacitor-crypto-api

This is a capacitor plugin that provides a simple API to generate key-pairs in the Secure Enclave (iOS) or StrongBox/TEE (Android) and use them to sign and verify data.

Limitations of the Secure Enclave (iOS)

"Works only with NIST P-256 elliptic curve keys. These keys can only be used for creating and verifying cryptographic signatures, or for elliptic curve Diffie-Hellman key exchange (and by extension, symmetric encryption)." - Apple Developer Documentation

Since the Secure Enclave only supports the NIST P-256 elliptic curve, only ECDSA is supported. ECDH is not supported, but may be supported in the future. PRs are welcome.

Format of the signature

Secure Enclave (iOS) and StrongBox/TEE (Android) return the signature in ASN.1 DER format. The WebCrypto API returns the signature in raw (IEEE P1363) format.

This plugin has the functions derToP1363 and p1363ToDer to convert the signature from ASN.1 DER to raw (IEEE P1363) format and vice versa.

For development

The plugin also uses the WebCrypto API to generate key-pairs in the browser and use them to sign and verify data. The key-pairs are stored in the browser's local storage.

WebCrypto API is only available in secure contexts (https)

Use Case

This can be used to realize a 2-factor-authentication mechanism, where the private-key is stored in the Secure Enclave (iOS) or StrongBox/TEE (Android) and the public-key is stored on the server.

The server creates a challenge and sends it to the client. The client signs the challenge with the private-key and sends the signed data back to the server.

The server can then verify the signature of the data with the public-key and be sure that the data was signed by the private-key.

There is an example in the example directory.

Install

npm install @perfood/capacitor-crypto-api
npx cap sync

API

list()

list() => Promise<ListResponse>

Returns all key-pair tags that are available in the Secure Enclave (iOS) or StrongBox/TEE (Android).

Returns: Promise<ListResponse>


generateKey(...)

generateKey(options: GenerateKeyOptions) => Promise<GenerateKeyResponse>

Generates a key-pair in the Secure Enclave (iOS) or StrongBox/TEE (Android), tags it for alter referencing and returns the public-key only, since the private-key is protected and can't be extracted.

ParamType
optionsGenerateKeyOptions

Returns: Promise<GenerateKeyResponse>

Since: 1.0.0


loadKey(...)

loadKey(options: LoadKeyOptions) => Promise<LoadKeyResponse>

Loads the public-key from the Secure Enclave (iOS) or StrongBox/TEE (Android).

ParamType
optionsLoadKeyOptions

Returns: Promise<LoadKeyResponse>

Since: 1.0.0


deleteKey(...)

deleteKey(options: DeleteKeyOptions) => Promise<void>

Deletes the key-pair from the Secure Enclave (iOS) or StrongBox/TEE (Android).

ParamType
optionsDeleteKeyOptions

Since: 1.0.0


sign(...)

sign(options: SignOptions) => Promise<SignResponse>

Signs the data in the Secure Enclave (iOS) or StrongBox/TEE (Android). Uses the private-key associated with the tag.

Only ECDSA is supported.

ParamType
optionsSignOptions

Returns: Promise<SignResponse>

Since: 1.0.0


verify(...)

verify(options: VerifyOptions) => Promise<VerifyResponse>

Verifies the signature of the data with the foreign public-key.

Only ECDSA is supported.

ParamType
optionsVerifyOptions

Returns: Promise<VerifyResponse>

Since: 1.0.0


Interfaces

ListResponse
PropTypeDescription
liststring[]The key-pair tags.
GenerateKeyResponse
PropTypeDescription
publicKeystringThe public-key in base64 format.
GenerateKeyOptions
PropTypeDescription
tagstringThe key-pair tag.
LoadKeyResponse
PropTypeDescription
publicKeystringThe public-key in base64 format.
LoadKeyOptions
PropTypeDescription
tagstringThe key-pair tag.
DeleteKeyOptions
PropTypeDescription
tagstringThe key-pair tag.
SignResponse
PropTypeDescription
signaturestringThe signature in base64 format.
SignOptions
PropTypeDescription
tagstringThe key-pair tag.
datastringThe data to sign.
VerifyResponse
PropTypeDescription
verifiedbooleanWhether the signature is verified.
VerifyOptions
PropTypeDescription
foreignPublicKeystringThe foreign public-key in base64 format.
datastringThe signed data.
signaturestringThe signature in base64 format.

Keywords

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc