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

react-native-secp256k1-urnm

v0.1.1

Published

This module provides native bindings to bitcoin-core/secp256k1 for React Native.

Downloads

4

Readme

react-native-secp256k1-urnm

This module provides native bindings to bitcoin-core/secp256k1 for React Native.

Demo

Example test cases Example test cases GIF

Installation

Npm

npm install react-native-secp256k1-urnm

Yarn

yarn add react-native-secp256k1-urnm

Usage

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);
});

API

Base methods

import * as secp256k1 from 'react-native-secp256k1-urnm';

| 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. |

Ext methods

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 |

Utils methods

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 |

Base64 methods

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. |

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