0.2.2 • Published 1 year ago

@shadowsheep/io-react-native-crypto v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@shadowsheep/io-react-native-crypto

Module to generate and sign with crypto keys backed on device security hardware on react-native platform.

Installation

yarn add @shadowsheep/io-react-native-crypto

Usage

Generate a key

import { generate } from '@shadowsheep/io-react-native-crypto';

// ...

try {
  const result = await generate('PERSONAL_KEYTAG');
} catch (e) {
  const {message, userInfo} = e as CryptoError;
}
// result is the JWK of the generated public key

Sign a message

import { sign } from '@shadowsheep/io-react-native-crypto';

// ...

try {
  const result = await sign('A valid message to sign', 'PERSONAL_KEYTAG');
} catch (e) {
  const {message, userInfo} = e as CryptoError;
}
// result is the Base64 string representation of the signature.

Retrieve the public key

import { getPublicKey } from '@shadowsheep/io-react-native-crypto';

// ...

try {
  const result = await getPublicKey('PERSONAL_KEYTAG');
} catch (e) {
  const {message, userInfo} = e as CryptoError;
}
// result is the JWK of the generated public key, error if no key has been yet generated

Delete the key

import { deleteKey } from '@shadowsheep/io-react-native-crypto';

// ...

try {
  await deleteKey('PERSONAL_KEYTAG');
} catch (e) {
  const {message, userInfo} = e as CryptoError;
}
// no result is provided, error if no key has been found for the specified keytag

Types

TypeNameDescription
ECKeyThe JWK representation of an Elliptic Curve public key
RSAKeyThe JWK representation of an RSA public key
PublicKeyType of the returned public key, may be either a RSAKey or a ECKey
CryptoErrorThis type defines the error returned by the generation of a key or signing a message it is composed by an error code and by an additional information object

Error Codes

TypeNamePlatformDescription
KEY_ALREADY_EXISTSiOS/AndroidThe key you're trying to generate already exists
UNSUPPORTED_DEVICEiOS/AndroidDevice doesn't support hardware backed keys
WRONG_KEY_CONFIGURATIONiOS/AndroidThe key configuration has not been correctly defined
PUBLIC_KEY_NOT_FOUNDiOS/AndroidThe public key is missing for a specific keyTag
PUBLIC_KEY_DELETION_ERRORiOS/AndroidAn error occurred while deleting the public key
API_LEVEL_NOT_SUPPORTEDAndroidThe current API Level doesn't support the hardware baked key generation
KEYSTORE_LOAD_FAILEDAndroidIt was not possible to load or store data on the Keystore
KEYCHAIN_LOAD_FAILEDiOSIt was not possible to load or store data on the Keychain
UNABLE_TO_SIGNiOS/AndroidIt was not possible to sign the given string
INVALID_UTF8_ENCODINGiOS/AndroidThe encoded string doesn't respect the valid encoding format
INVALID_SIGN_ALGORITHMAndroidThe sign algorithm was not valid
UNKNOWN_EXCEPTIONAndroidUnexpected error
THREADING_ERRORiOSUnexpected error

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library