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

@onomy/jsi-rn-wallet-core

v0.1.0

Published

JSI wrapper around wallet-core

Downloads

531

Readme

Installation

yarn add jsi-rn-wallet-core

Supported currencies

  • Ethereum
  • Cosmos

Usage

Import package once as early as possible, it installs global types, and on android it installs bindings in a safe way.

Afterwards, you can access a global WalletCore variable anywhere in your code.

import 'jsi-rn-wallet-core';

API

const { mnemonic, seed } = WalletCore.createWallet(128, '');

Creates a new wallet.

** SAMPLE METHOD ** Meant only to test creating a wallet, not meant to be used production

  • strength number - Strength of the secret seed. Possible options are 128 or 256.
  • passphrase string (optional) - Used to scramble the seed
  • Returns
    • mnemonic string - the recovery phrase of the wallet
    • seed string - hex seed of the wallet. Can also be used to import.
const { mnemonic, seed } = WalletCore.importWalletFromMnemonic({
  mnemonic:
    'ripple scissors kick mammal hire column oak again sun offer wealth tomorrow wagon turn fatal',
  passphrase: '',
  promptTitle: 'Unlock your device',
  promptSubtitle: 'Please authenticate to unlock your wallet',
  useBiometrics: true,
});

Import a wallet from a mnemonic recovery phrase. This will also load the wallet into local memory so that it can be used for creating addresses and/or signing transactions. The loaded wallet seed will also be securely stored on the device so it can be loaded (will require user authentication via passcode/biometrics).

  • params object - contains the possible params
    • mnemonic string - Recovery phrase
    • passphrase string (optional) - The passphrase used when creating the wallet (if applicable)
    • promptTitle string (optional) - The title for the native dialog when requesting biometric authentication
    • promptSubtitle string (optional) - The subtitle for the native dialog when requesting biometric authentication
    • useBiometrics boolean (optional) (default: false) - Lock the seed behind biometric authentication
  • Returns
    • mnemonic string - the recovery phrase of the wallet
    • seed string - hex seed of the wallet. Can also be used to import.
const { mnemonic, seed } = WalletCore.importWalletFromEntropy({
  entropy: '<ENTROPY_STRING>',
  passphrase: '',
  promptTitle: 'Unlock your device',
  promptSubtitle: 'Please authenticate to unlock your wallet',
  useBiometrics: true,
});

Import a wallet from a entropy string seed. This will also load the wallet into local memory so that it can be used for creating addresses and/or signing transactions. The loaded wallet seed will also be securely stored on the device so it can be loaded (will require user authentication via passcode/biometrics).

  • params object - contains the possible params
    • entropy string - Recovery phrase
    • passphrase string (optional) - The passphrase used when creating the wallet (if applicable)
    • promptTitle string (optional) - The title for the native dialog when requesting biometric authentication
    • promptSubtitle string (optional) - The subtitle for the native dialog when requesting biometric authentication
    • useBiometrics boolean (optional) (default: false) - Lock the seed behind biometric authentication
  • Returns
    • mnemonic string - the recovery phrase of the wallet
    • seed string - hex seed of the wallet. Can also be used to import.
const { mnemonic, seed } = WalletCore.loadWalletFromStorage({
  passphrase: '',
  promptTitle: 'Unlock Wallet',
  promptSubtitle: 'Please authenticate to use your wallet',
  useBiometrics: true,
});

Load a wallet into memory from a stored seed.

  • params object - contains the possible params
    • passphrase string (optional) - The passphrase used when creating the wallet (if applicable)
    • promptTitle string (optional) - The title for the native dialog when requesting biometric authentication
    • promptSubtitle string (optional) - The subtitle for the native dialog when requesting biometric authentication
    • useBiometrics boolean (optional) (default: false) - Lock the seed behind biometric authentication, if you imported a wallet with the useBiometrics flag, you need to set it here too in order to be able to load it
  • Returns
    • mnemonic string - the recovery phrase of the wallet
    • seed string - hex seed of the wallet. Can also be used to import.
const address = WalletCore.getAddressForCoin('ethereum');

Generate and retrieve the default address for a coin. The address is generated using the default derivation path of a coin.

  • coin string - The coin type
  • Returns
    • address string - The public key of the address
const { address, privateKey } = WalletCore.getAccount(
  'ethereum',
  "m/44'/60'/1'/0/0"
);

Generate an address using a custom derivation path.

  • coin string - The coin type
  • derivationPath string - Derivation path to be used when generating the address
  • Returns
    • address string - The correspoding public address
    • publicKey string - The public key
const transactionHash = WalletCore.signTransactionForCoin(
  'ethereum',
  JSON.stringify({
    chainID: '0x01',
    amount: '0x0348bca5a16000',
    nonce: '0x00',
    toAddress: '0xC37054b3b48C3317082E7ba872d7753D13da4986',
    privateKeyDerivationPath: "m/44'/60'/1'/0/0", // optional - otherwise default address is used
  })
);

Generate and retrieve the default address for a coin. The address is generated using the default derivation path of a coin.

  • coinType string - The coin type
  • input string the payload to be signed, stringified JSON or raw byte protobuf
  • Returns transactionHash string - the hash of the signed data
const transactionHash = WalletCore.signData(
  'ethereum',
  'XXXXX',
  "m/44'/60'/1'/0/0"
);

Generic sign function for any raw data byta array.

  • coinType string - The coin type
  • payload string - raw bytes to sign
  • derivationPath string (optional) - Derivation path to use to get private key
  • Returns transactionHash string - the hash of the signed data
const mnemonic = WalletCore.getCurrentWalletMnemonic();

Gets the current loaded wallet mnemonic.

const biometricsState = WalletCore.getBiometricsState();

Get device's biometrics state

  • Returns biometrics state enum
    • available: device supports biometrics and is ready to authenticate
    • available_locked: device supports biometrics but is locked (e.g. too many failed attempts should trigger this state) (iOS only)
    • unavailable: device does not support biometrics or supports them but they are not enabled
WalletCore.deleteWallet({
  promptTitle: 'Unlock wallet',
  promptSubtitle: 'Please unlock your wallet',
  useBiometrics: true,
});

Cleanup any previously loaded wallet from persistent storage and memory.

  • params object - contains the possible params
    • promptTitle string (optional) - The title for the native dialog when requesting biometric authentication
    • promptSubtitle string (optional) - The subtitle for the native dialog when requesting biometric authentication
    • useBiometrics boolean (optional) (default: false) - If you imported a wallet with the useBiometrics flag, you need to set it here too in order to be able to load it
WalletCore.cleanup();

Cleanup any previously loaded wallet from memory and also deletes any stored seed.

WalletCore.transferEntropyToBiometricsStorage();

Transfers any seed stored without biometric security to require biometric authentication.

WalletCore.transferEntropyToNormalStorage();

Transfers any seed stored with biometric security to NOT require biometric authentication.

Android Instructions

Once you add this library to your Android project you might get some errors, you need to modify the android compilation process a bit.

The underlaying C++ wallet-core library depends on the C++ STL, this might cause some Android error not being able to select a c++_shared library.

On the apps build.gradle (android/app/build.gradle), you can force the gradle build process to just pick one.

packagingOptions {
  pickFirst 'lib/x86/libc++_shared.so'
  pickFirst 'lib/x86_64/libc++_shared.so'
  pickFirst 'lib/armeabi-v7a/libc++_shared.so'
  pickFirst 'lib/arm64-v8a/libc++_shared.so'
  pickFirst 'lib/x86/libTrustWalletCore.so'
  pickFirst 'lib/x86_64/libTrustWalletCore.so'
  pickFirst 'lib/armeabi-v7a/libTrustWalletCore.so'
  pickFirst 'lib/arm64-v8a/libTrustWalletCore.so'
}

Updating Wallet-Core embedded .AAR

brew install boost
brew install cmake

git clone [email protected]:trustwallet/wallet-core.git
cd wallet-core

You need to modify the build gradle file to add prefab functionality (exposes C++ symbols to Android C++ builds)
It is also necessary to modify the CMakeLists to expose the generated symbols
There is a patch file in the /scripts directory in this repo with the changes you need to make

Then generate the .AAR file (from the `android` folder) with:

./bootstrap.sh # Generates all the protobuf classes and what not
BOOST_INCLUDEDIR=/opt/homebrew/Cellar/boost/1.78.0_1/include ./gradlew build

Then place the generated aar on this repo under android/libs/

You can then try to compile the example app
cd example && yarn android

Contributing

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

License

MIT