This module provides native bindings to bitcoin-core/secp256k1 for React Native.
npm install react-native-secp256k1-urnm
yarn add react-native-secp256k1-urnm
import * as secp256k1 from 'react-native-secp256k1-urnm';
import { utils } from 'react-native-secp256k1-urnm';
async function main() {
const privAbase64 = await secp256k1.ext.generateKey();
const privBbase64 = await secp256k1.ext.generateKey();
const privA = utils.decodeBase64(privAbase64);
const privB = utils.decodeBase64(privBbase64);
const pubA = await secp256k1.computePubkey(privA, true);
const pubB = await secp256k1.computePubkey(privB, true);
// sign verify
const data = utils.decodeBase64("1H1SJuGwoSFTqNI8wvVWEdGRpBvTnzLckoZ1QTF7gI0");
const sigA = await secp256k1.sign(data, privA);
console.log("verify: ", await secp256k1.verify(data, sigA, pubA));
const pubABase64 = utils.encodeBase64(pubA);
const pubBBase64 = utils.encodeBase64(pubB);
// ecdh && aes256
const encryped1 = await secp256k1.ext.encryptECDH(privAbase64, pubBBase64, "Hello World");
const decryped1 = await secp256k1.ext.decryptECDH(privBbase64, pubABase64, encryped1);
console.log(decryped1);
}
main().then(() => {
console.log("Done");
}).catch((err) => {
console.error(err);
});
import * as secp256k1 from 'react-native-secp256k1-urnm';
- Functions work with Uint8Array.
Method | Params | Return type | Description |
---|---|---|---|
verify(sig: Unit8Array, mes32: Unit8Array, pubkey: Unit8Array) |
sig : signature, mes32 : message to verify, pubkey : Unit8Array |
Promise<boolean> | Verify an ECDSA signature. |
sign(msg32: Unit8Array, privKey: Unit8Array) |
sig : signature, privKey : Unit8Array |
Promise<Unit8Array> | Create an ECDSA signature. |
privateKeyVerify(privKey: Unit8Array) |
privKey : Unit8Array |
Promise<boolean> | Verify a private key. |
publicKeyCreate(privKey: Uint8Array, compressed?: boolean) |
privKey : Unit8Array, compressed : boolean |
Promise<Unit8Array> | Compute the public key for a secret key. |
privateKeyTweakAdd(privKey: Unit8Array, tweak: Unit8Array) |
privKey : Unit8Array, tweak : Unit8Array |
Promise<Uint8Array> | Tweak a private key in place by adding tweak to it. |
privateKeyTweakMul(privKey: Unit8Array, tweak: Unit8Array) |
privKey : Unit8Array, tweak : Unit8Array |
Promise<Uint8Array> | Tweak a private key in place by multiplying it by a tweak. |
pubKeyTweakAdd(pubKey: Unit8Array, tweak: Unit8Array) |
pubKey : Unit8Array, tweak : Unit8Array |
Promise<Uint8Array> | Tweak a public key by adding tweak times the generator to it. |
pubKeyTweakMul(pubKey: Unit8Array, tweak: Unit8Array) |
pubKey : Unit8Array, tweak : Unit8Array |
Promise<Uint8Array> | Tweak a public key by multiplying it by a tweak value. |
createECDHSecret(privKey: Unit8Array, pubKey: Unit8Array) |
privKey : Unit8Array, pubKey : Unit8Array |
Promise<Uint8Array> | Compute an EC Diffie-Hellman secret in constant time. |
import { ext } from 'react-native-secp256k1-urnm';
Method | Params | Return type | Description |
---|---|---|---|
generateKey() | Promise<base64 string> | Create a random private key | |
encryptECDH(privKey: string, pubKey: string, data: string) |
privKey : base64 string, pubKey : base64 string, data : base64 string |
Promise<base64 string> | Encrypt data an EC Diffie-Hellman |
decryptECDH(privKey: string, pubKey: string, data: string) |
privKey : base64 string, pubKey : base64 string, data : base64 string |
Promise<base64 string> | Decrypt data an EC Diffie-Hellman |
import { utils } from 'react-native-secp256k1-urnm';
Method | Params | Return type | Description |
---|---|---|---|
encodeBase64(data: Uint8Array) |
data : Uint8Array |
base64 string | Provide @stablelib/base64 encode function |
decodeBase64(base64: string) |
data : base64 string |
Uint8Array | Provide @stablelib/base64 decode function |
encodeHex(data: Uint8Array) |
data : Uint8Array |
base64 string | Provide @stablelib/hex encode function |
decodeHex(base64: string) |
data : base64 string |
Uint8Array | Provide @stablelib/hex decode function |
encodeBase64WithoutPadding(data: Uint8Array) |
data : Uint8Array |
base64 string | Encode Unit8Array to base64 string without paddings(= ). Used @stablelib/base64 . |
decodeBase64WithoutPadding(base64: string) |
data : base64 string |
Uint8Array | Decode Unit8Array to base64 string without paddings(= ). Used @stablelib/base64 . |
removeBase64Padding(base64: string) |
data : base64 string |
base64 string | Remove paddings(= ) from base64 string |
addBase64Padding(base64: string) |
data : base64 string |
base64 string | Add paddings(= ) to base64 string |
import { base64 } from 'react-native-secp256k1-urnm';
Method | Params | Return type | Description |
---|---|---|---|
verify(sig: string, mes32: string, pubkey: string) |
sig : base64 string, mes32 : base64 string, pubkey : base64 string |
Promise<boolean> | Verify an ECDSA signature. |
sign(msg32: string, privKey: string) |
sig : base64 string, privKey : base64 string |
Promise<base64 string> | Create an ECDSA signature. |
privateKeyVerify(privKey: string) |
privKey : base64 string |
Promise<boolean> | Verify a private key. |
publicKeyCreate(privKey: string, compressed?: boolean) |
privKey : base64 string, compressed : boolean |
Promise<base64 string> | Compute the public key for a secret key. |
privateKeyTweakAdd(privKey: string, tweak: string) |
privKey : base64 string, tweak : base64 string |
Promise<base64 string> | Tweak a private key in place by adding tweak to it. |
privateKeyTweakMul(privKey: string, tweak: string) |
privKey : base64 string, tweak : base64 string |
Promise<base64 string> | Tweak a private key in place by multiplying it by a tweak. |
pubKeyTweakAdd(pubKey: string, tweak: string) |
pubKey : base64 string, tweak : base64 string |
Promise<base64 string> | Tweak a public key by adding tweak times the generator to it. |
pubKeyTweakMul(pubKey: string, tweak: string) |
pubKey : base64 string, tweak : base64 string |
Promise<base64 string> | Tweak a public key by multiplying it by a tweak value. |
createECDHSecret(privKey: string, pubKey: string) |
privKey : base64 string, pubKey : base64 string |
Promise<base64 string> | Compute an EC Diffie-Hellman secret in constant time. |
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library