novacrypto / bip39 Goto Github PK
View Code? Open in Web Editor NEWJava Microlibrary implementation of BIP0039
Home Page: https://novacrypto.github.io/BIP39
License: GNU General Public License v3.0
Java Microlibrary implementation of BIP0039
Home Page: https://novacrypto.github.io/BIP39
License: GNU General Public License v3.0
Quoting BIP 39:
HMAC-SHA512 is used as the pseudo-random function.
Quoting SeedCalculator.java:38:
private final PBKDF2WithHmacSHA256 hashAlgorithm;
public SeedCalculator(PBKDF2WithHmacSHA256 hashAlgorithm) {
this.hashAlgorithm = hashAlgorithm;
}
On a two-minute glance through the code, I had an understandable reaction. Then, I reached for grep
and found these:
JavaxPBKDF2WithHmacSHA256.java:36:
public enum JavaxPBKDF2WithHmacSHA256 implements PBKDF2WithHmacSHA256 {
INSTANCE;
private SecretKeyFactory skf = getPbkdf2WithHmacSHA512();
@Override
public byte[] hash(char[] chars, byte[] salt) {
final PBEKeySpec spec = new PBEKeySpec(chars, salt, 2048, 512);
SpongyCastlePBKDF2WithHmacSHA256.java:32:
public enum SpongyCastlePBKDF2WithHmacSHA256 implements PBKDF2WithHmacSHA256 {
INSTANCE;
@Override
public byte[] hash(char[] chars, byte[] salt) {
PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(new SHA512Digest());
I am still not sure how it all fits together. But I suggest it may be kinder to code reviewers to not misidentify the PRF in variable names. Or perhaps you wish to test whether readers be paying attention? [g]
May throw word not found, that would actually be found if normalized.
when i use
f=fc534ee49d7d44f7942996f13ba11372f939e5fcc02dd89eb4fdd23e4dcdb134
new MnemonicGenerator(wordList)
.createMnemonic(f, sb::append);
i got "wisdom omit rice depend stairs knock expose crazy van tackle dynamic tourist near very vessel aisle sudden volcano disorder piece tooth traffic shadow mother" total 24 words,
i wannn 12 word. like METAMASK
thank you
What's wrong with this mnemonic generated by Electrum LTC 2.8.3.5:
despair neck garden cabbage one bless help lamp marriage can mushroom moon
https://iancoleman.github.io/bip39/ doesn't like it.
Interested which side of the fence this library falls on.
We're using this library in our react-native app. While building the app, we recently encountered following issue described below.
It was resolved after adding jcenter()
in repositories
as this library only seems to be available there only (refer this)
Since jcenter
is deprecated & not recommended to use, is there any other repository from where we can fetch this library during build time or any long term fix for the same?
> Could not find io.github.novacrypto:BIP39:2019.01.27.
Searched in the following locations:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
6 actionable tasks: 6 executed
- https://repo.maven.apache.org/maven2/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- file:/home/runner/.m2/repository/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- file:/home/runner/work/leap-cosmos-mobile/leap-cosmos-mobile/node_modules/react-native/android/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- file:/home/runner/work/leap-cosmos-mobile/leap-cosmos-mobile/node_modules/jsc-android/dist/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- file:/home/runner/work/leap-cosmos-mobile/leap-cosmos-mobile/node_modules/detox/Detox-android/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- https://dl.google.com/dl/android/maven2/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- https://www.jitpack.io/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- https://maven.google.com/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
- https://plugins.gradle.org/m2/io/github/novacrypto/BIP39/2019.01.27/BIP39-2019.01.27.pom
Required by:
project :app
Also sharing build.gradle
below for reference.
buildscript {
...
repositories {
google()
maven {
url 'https://maven.fabric.io/public'
}
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.3")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath("com.google.gms:google-services:4.3.15")
classpath 'io.fabric.tools:gradle:1.28.1'
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
maven {
url("$rootDir/../node_modules/detox/Detox-android")
}
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup "com.facebook.react"
}
}
google()
maven { url 'https://www.jitpack.io' }
maven {
url 'https://maven.google.com'
}
gradlePluginPortal()
}
configurations.all {
resolutionStrategy {
// Remove this override in 0.65+, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
exclude module:'bcprov-jdk15on'
}
}
...
The method for splitting the string and looking up the words can be simplified.
As seen in other projects, a search and replace could accidentally modify a word in a word list.
https://github.com/litecoin-foundation/loafwallet-android/issues/33
JDK1.8.0_121
Intellij IDEA
Without Andriod development environment
class io.github.novacrypto.hashing.Sha256$1 cannot access its superinterface io.github.novacrypto.toruntime.CheckedExceptionToRuntime$Func at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at io.github.novacrypto.hashing.Sha256.sha256(Sha256.java:57) at io.github.novacrypto.hashing.Sha256.sha256(Sha256.java:40) at io.github.novacrypto.hashing.Sha256.sha256(Sha256.java:36) at io.github.novacrypto.bip39.MnemonicGenerator.firstByteOfSha256(MnemonicGenerator.java:120) at io.github.novacrypto.bip39.MnemonicGenerator.wordIndexes(MnemonicGenerator.java:104) at io.github.novacrypto.bip39.MnemonicGenerator.createMnemonic(MnemonicGenerator.java:81)
Starting from May 1, 2021 JCenter will stop working. Can you please publish the library to MavenCentral?
Possible alternatives
JitPack
GitHub Packages
We already do this, if the client has the words chosen from the dictionary and can provide the indexes into the dictionary, it would save client combining, then library normalizing, splitting to a list, and finding the indexes. Plus it would avoid the client handling WordNotFoundException
and UnexpectedWhiteSpaceException
.
Possibly allow a relaxation of this rule option.
Currently, it causes a word not found ""
exception, which is not very helpful.
How to get private key in the project?
public byte[] calculateSeed(String mnemonic, String passphrase) {
This should be able to take CharSequence
but the normalizer is insisting we have String
input.
I tried the example "Using a StringBuilder" and got "Exception in thread "main" java.lang.NoClassDefFoundError: io/github/novacrypto/hashing/Sha256".
MnemonicGenerator has an import of io.github.novacrypto.hashing.Sha256, but there is no such package as io.github.novacrypto.hashing.
On Android < 26
Caused by: java.lang.RuntimeException: java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA512 implementation not found
at io.github.novacrypto.toruntime.CheckedExceptionToRuntime.toRuntime(CheckedExceptionToRuntime.java:48)
at io.github.novacrypto.bip39.SeedCalculator.getPbkdf2WithHmacSHA512(SeedCalculator.java:91)
at io.github.novacrypto.bip39.SeedCalculator.<init>(SeedCalculator.java:40)
See: https://developer.android.com/reference/javax/crypto/SecretKeyFactory.html
Hello, I am very happy to use your powerful encryption library, but when I was testing the demo example on this page (https://iancoleman.io/bip39/#english), I encountered a problem: From Derived Addresses Title,
In the Table tab , how to generate different addresses, public keys, and private keys according to different Derived Paths. When I use the BIP39 library, I don’t know how to implement it. cloud you give me a java demo? Because the page is implemented through the javascript lib, but how to implement the java BIP39 library, I read all the unit tests and don’t know how to write the code, so I need your help. thanks!
link:
https://github.com/NovaCrypto/BIP39
https://iancoleman.io/bip39/#english
Currently, only English and Japanese are tested and supported.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.