Introduction
Welcome to the documentation for SECP256k1 wrapper for React Native. This wrapper provides an easy-to-use interface for working with the SECP256k1 elliptic curve cryptography library in React Native applications.
Installation
To install SECP256k1 wrapper for React Native, follow these steps:
- Open your project in a terminal.
- Run the command
npm install secp256k1wrapperforrn
to install the wrapper package. - Link the package to your React Native project by running
react-native link secp256k1wrapperforrn
. - You are now ready to use SECP256k1 wrapper in your React Native application!
Usage
SECP256k1 wrapper for React Native provides the following functionality:
Generating a Random Private Key
To generate a random private key, use the following code:
// Import the wrapper
import SECP256k1Wrapper from 'secp256k1wrapperforrn';
// Generate a random private key
const privateKey = SECP256k1Wrapper.generatePrivateKey();
// Use the private key in your application
console.log(privateKey);
Deriving the Public Key from a Private Key
To derive the public key from a private key, use the following code:
// Import the wrapper
import SECP256k1Wrapper from 'secp256k1wrapperforrn';
// Get the private key
const privateKey = '...'; // Replace with your actual private key
// Derive the public key
const publicKey = SECP256k1Wrapper.derivePublicKey(privateKey);
// Use the public key in your application
console.log(publicKey);
Signing a Message with a Private Key
To sign a message with a private key, use the following code:
// Import the wrapper
import SECP256k1Wrapper from 'secp256k1wrapperforrn';
// Get the private key
const privateKey = '...'; // Replace with your actual private key
// Sign a message
const message = '...'; // Replace with your message
const signature = SECP256k1Wrapper.signMessage(privateKey, message);
// Use the signature in your application
console.log(signature);
Verifying a Signature with a Public Key
To verify a signature with a public key, use the following code:
// Import the wrapper
import SECP256k1Wrapper from 'secp256k1wrapperforrn';
// Get the public key
const publicKey = '...'; // Replace with your actual public key
// Verify a signature
const message = '...'; // Replace with the original message
const signature = '...'; // Replace with the signature
const isValid = SECP256k1Wrapper.verifySignature(publicKey, message, signature);
// Use the validity result in your application
console.log(isValid);
Conclusion
Congratulations! You have successfully learned how to use the SECP256k1 wrapper for React Native. You can now work with random private keys, derive public keys, sign messages, and verify signatures in your React Native applications.