예제 #1
0
  /**
   * Creates an MnemonicCode object, initializing with words read from the supplied input stream. If
   * a wordListDigest is supplied the digest of the words will be checked.
   */
  public MnemonicCode(InputStream wordstream, String wordListDigest)
      throws IOException, IllegalArgumentException {
    BufferedReader br = new BufferedReader(new InputStreamReader(wordstream, "UTF-8"));
    this.wordList = new ArrayList<String>(2048);
    MessageDigest md;
    try {
      md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException ex) {
      throw new RuntimeException(ex); // Can't happen.
    }
    String word;
    while ((word = br.readLine()) != null) {
      md.update(word.getBytes());
      this.wordList.add(word);
    }
    br.close();

    if (this.wordList.size() != 2048)
      throw new IllegalArgumentException("input stream did not contain 2048 words");

    // If a wordListDigest is supplied check to make sure it matches.
    if (wordListDigest != null) {
      byte[] digest = md.digest();
      String hexdigest = HEX.encode(digest);
      if (!hexdigest.equals(wordListDigest))
        throw new IllegalArgumentException("wordlist digest mismatch");
    }
  }
예제 #2
0
 @Override
 public String toString() {
   final ToStringHelper helper = Objects.toStringHelper(this).omitNullValues();
   helper.add("pub", Utils.HEX.encode(pub.getEncoded()));
   helper.add("chainCode", HEX.encode(chainCode));
   helper.add("path", getPathAsString());
   if (creationTimeSeconds > 0) helper.add("creationTimeSeconds", creationTimeSeconds);
   helper.add("isEncrypted", isEncrypted());
   helper.add("isPubKeyOnly", isPubKeyOnly());
   return helper.toString();
 }
예제 #3
0
 @Override
 public String toString() {
   return HEX.encode(key);
 }