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

react-native-mnemonic-key

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-mnemonic-key

Native Android and iOS implementation of MnemonicKey for React Native

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
increased by45.45%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-mnemonic-key

This library provides RNMnemonicKey, a native Android and iOS implementation of Terra.js's MnemonicKey, made available for React Native. This significantly improves performance and compatibility in mobile apps.

Installation

Install to your React Native app's package.json:

$ yarn add react-native-mnemonic-key

Android Setup

You may need to set multiDexEnabled true in your Android app's build.gradle:

// android/app/build.gradle
android {
    ...
    defaultConfig {
        applicationId "com.example.reactnativemnemonickey"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true // ADD THIS LINE
    }
}

Adding to iOS

You may need to modify your iOS app's Podfile to enable Modular Headers for TrezorCrypto.

# ios/Podfile
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'

target 'demo' do
  use_unimodules!
  config = use_native_modules!

  use_react_native!(:path => config["reactNativePath"])
  pod 'TrezorCrypto', :modular_headers => true # ADD THIS LINE
end

Then run in your React Native iOS app's ios/ directory:

$ pod install

Usage

A full example demo app is available inside /example.

The usage is nearly identical to Terra.js's MnemonicKey, with the exception that RNMnemonicKey cannot be instantiated with new. You must use the static factory method RNMnemonicKey.create, which returns a Promise<RNMnemonicKey>.

// NOT ALLOWED!
// new RNMnemonicKey({ ...options })

// RIGHT WAY
RNMnemonicKey.create({ ...options }).then((rnmk) => terra.wallet(rnmk));

Demo

For your convenience, a full example demo app is provided as a reference inside /example.

# Run iOS Demo
$ yarn example ios

# Run Android Demo
$ yarn example android
import * as React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { RNMnemonicKey } from 'react-native-mnemonic-key';

export default function App() {
  const [result, setResult] = React.useState<RNMnemonicKey | undefined>();

  React.useEffect(() => {
    RNMnemonicKey.create({
      mnemonic:
        'satisfy adjust timber high purchase tuition stool faith fine install that you unaware feed domain license impose boss human eager hat rent enjoy dawn',
      coinType: 118,
      account: 5,
      index: 32,
    }).then(setResult);
  }, []);

  return (
    <View style={styles.container}>
      <Text>Address: {result?.accAddress}</Text>
      <Text>ValAddress: {result?.valAddress}</Text>
      <Text>Mnemonic: {result?.mnemonic}</Text>
      <Text>PrivateKey: {result?.privateKey.toString('hex')}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  box: {
    width: 60,
    height: 60,
    marginVertical: 20,
  },
});

demo

License

This software is licensed under the MIT license. See LICENSE for full disclosure.

© 2021 Terraform Labs, PTE.

Keywords

FAQs

Package last updated on 22 Jan 2021

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