NovaCrypto / BIP39

Java Microlibrary implementation of BIP0039
https://novacrypto.github.io/BIP39
GNU General Public License v3.0
92 stars 34 forks source link

Error encounter ->lass io.github.novacrypto.hashing.Sha256$1 cannot access its superinterface io.github.novacrypto.toruntime.CheckedExceptionToRuntime$Func #36

Closed jiangbubai closed 6 years ago

jiangbubai commented 6 years ago

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)

westonal commented 6 years ago

Hi, sorry for the delay. I've just tested it on a fresh Android app, I added just this dependency:

implementation 'io.github.novacrypto:BIP39:0.1.9'

And was able to create a mnemonic and a seed without issue.

Then I tried in an IntelliJ gradle project:

group 'com.example'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile 'io.github.novacrypto:BIP39:0.1.9'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
import io.github.novacrypto.bip39.MnemonicGenerator;
import io.github.novacrypto.bip39.SeedCalculator;
import io.github.novacrypto.bip39.Words;
import io.github.novacrypto.bip39.wordlists.English;

import java.security.SecureRandom;

public final class Main {

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        byte[] entropy = new byte[Words.TWELVE.byteLength()];
        new SecureRandom().nextBytes(entropy);
        new MnemonicGenerator(English.INSTANCE)
                .createMnemonic(entropy, sb::append);
        final String mnemonic = sb.toString();
        System.out.println("Mnemonic: " + mnemonic);

        byte[] seed = new SeedCalculator()
                .calculateSeed(mnemonic, "");

        System.out.println("Seed length: " + seed.length);
    }
}
Mnemonic: auction divert trial wrestle guess valley witness bounce allow prison drama soccer
Seed length: 64

It works absolutely fine, so you will need to provide more information. What does your gradle look like, are you even using gradle etc? It's as though your setup is missing a transitive dependency somehow.

jiangbubai commented 6 years ago

@westonal sorry about this issue, It works well. I just tested in a non maven and non gradle project before by added libs to the project and occoured such exception. When I converted to maven project and use jcenter repository,nothing going wrong.Thanks for your help.

westonal commented 6 years ago

Yes it has some transitive dependencies so you need more than just one jar if doing it manually. But gradle or even pom file is way to go.