AddressIndex(final Change change, final int addressIndex) { if (isHardened(addressIndex)) throw new IllegalArgumentException(); this.change = change; this.addressIndex = addressIndex; string = String.format("%s/%d", change, addressIndex); }
switch (c) { case '\'': buffer = hard(buffer); break; case '/': throw new IllegalArgumentException("Illegal character in path: " + c); buffer += c - '0'; if (isHardened(buffer)) throw new IllegalArgumentException("Index number too large");
@Override public <Node> Node derive(final Node root, final Account account, final CkdFunction<Node> ckdFunction) { final CoinType coinType = account.getParent(); final Purpose purpose = coinType.getParent(); return ckdFunction.deriveChildKey( ckdFunction.deriveChildKey( ckdFunction.deriveChildKey(root, hard(purpose.getValue())), hard(coinType.getValue())), hard(account.getValue())); } }
@Override public <Node> Node derive(final Node root, final AddressIndex addressIndex, final CkdFunction<Node> ckdFunction) { final Change change = addressIndex.getParent(); final Account account = change.getParent(); final CoinType coinType = account.getParent(); final Purpose purpose = coinType.getParent(); return ckdFunction.deriveChildKey( ckdFunction.deriveChildKey( ckdFunction.deriveChildKey( ckdFunction.deriveChildKey( ckdFunction.deriveChildKey(root, hard(purpose.getValue())), hard(coinType.getValue())), hard(account.getValue())), change.getValue()), addressIndex.getValue()); } }
CoinType(final Purpose purpose, final int coinType) { if (isHardened(coinType)) throw new IllegalArgumentException(); this.purpose = purpose; this.coinType = coinType; string = String.format("%s/%d'", purpose, coinType); }
Purpose(final M m, final int purpose) { this.m = m; if (purpose == 0 || isHardened(purpose)) throw new IllegalArgumentException(); this.purpose = purpose; toString = String.format("%s/%d'", m, purpose); }
Account(final CoinType coinType, final int account) { if (isHardened(account)) throw new IllegalArgumentException(); this.coinType = coinType; this.account = account; string = String.format("%s/%d'", coinType, account); }
final ByteArrayWriter writer = new ByteArrayWriter(data); if (isHardened(index)) { writer.concat((byte) 0); writer.concat(hdKey.getKey(), 32);
final ByteArrayWriter writer = new ByteArrayWriter(data); if (isHardened(index)) { writer.concat((byte) 0); writer.concat(hdKey.getKey(), 32);
final ByteArrayWriter writer = new ByteArrayWriter(data); if (isHardened(index)) { writer.concat((byte) 0); writer.concat(hdKey.getKey(), 32);
@Override public ExtendedPublicKey cKDpub(final int index) { if (isHardened(index)) throw new IllegalCKDCall("Cannot derive a hardened key from a public key"); final HdKey parent = this.hdKey; final byte[] kPar = parent.getKey(); final byte[] data = new byte[37]; final ByteArrayWriter writer = new ByteArrayWriter(data); writer.concat(kPar, 33); writer.concatSer32(index); final byte[] I = hmacSha512(parent.getChainCode(), data); final byte[] Il = head32(I); final byte[] Ir = tail32(I); final BigInteger parse256_Il = parse256(Il); final ECPoint ki = gMultiplyAndAddPoint(parse256_Il, kPar); if (parse256_Il.compareTo(n()) >= 0 || ki.isInfinity()) { return cKDpub(index + 1); } final byte[] key = pointSerP(ki); return new ExtendedPublicKey(new HdKey.Builder() .network(parent.getNetwork()) .neutered(true) .depth(parent.depth() + 1) .parentFingerprint(parent.calculateFingerPrint()) .key(key) .chainCode(Ir) .childNumber(index) .build()); }
@Override public ExtendedPublicKey cKDpub(final int index) { if (isHardened(index)) { return null; } final HdKey parent = this.hdKey; final byte[] kPar = parent.getKey(); final byte[] data = new byte[37]; final ByteArrayWriter writer = new ByteArrayWriter(data); writer.concat(kPar, 33); writer.concatSer32(index); final byte[] I = hmacSha512(parent.getChainCode(), data); final byte[] Il = head32(I); final byte[] Ir = tail32(I); final BigInteger parse256_Il = parse256(Il); final ECPoint ki = gMultiplyAndAddPoint(parse256_Il, kPar); if (parse256_Il.compareTo(n()) >= 0 || ki.isInfinity()) { return cKDpub(index + 1); } final byte[] key = pointSerP(ki); return new ExtendedPublicKey(new HdKey.Builder() .network(parent.getNetwork()) .neutered(true) .depth(parent.depth() + 1) .parentFingerprint(parent.calculateFingerPrint()) .key(key) .chainCode(Ir) .childNumber(index) .build()); }
@Override public ExtendedPublicKey cKDpub(final int index) { if (isHardened(index)) { return null; } final HdKey parent = this.hdKey; final byte[] kPar = parent.getKey(); final byte[] data = new byte[37]; final ByteArrayWriter writer = new ByteArrayWriter(data); writer.concat(kPar, 33); writer.concatSer32(index); final byte[] I = hmacSha512(parent.getChainCode(), data); final byte[] Il = head32(I); final byte[] Ir = tail32(I); final BigInteger parse256_Il = parse256(Il); final ECPoint ki = gMultiplyAndAddPoint(parse256_Il, kPar); if (parse256_Il.compareTo(n()) >= 0 || ki.isInfinity()) { return cKDpub(index + 1); } final byte[] key = pointSerP(ki); return new ExtendedPublicKey(new HdKey.Builder() .network(parent.getNetwork()) .neutered(true) .depth(parent.depth() + 1) .parentFingerprint(parent.calculateFingerPrint()) .key(key) .chainCode(Ir) .childNumber(index) .build()); }