public LNCloseAMessage (Sha256Hash channelHash, Collection<TransactionSignature> signatureList, float feePerByte) { this.channelHash = channelHash.getBytes(); this.signatureList = signatureList.stream().map(TransactionSignature::encodeToBitcoin).collect(Collectors.toList()); this.feePerByte = feePerByte; }
private byte[] getTxKey(KeyType keytype, Sha256Hash hash, int index) { byte[] key = new byte[37]; key[0] = (byte) keytype.ordinal(); System.arraycopy(hash.getBytes(), 0, key, 1, 32); byte[] heightBytes = ByteBuffer.allocate(4).putInt(index).array(); System.arraycopy(heightBytes, 0, key, 33, 4); return key; }
private byte[] getTxKey(KeyType keytype, Sha256Hash hash) { byte[] key = new byte[33]; key[0] = (byte) keytype.ordinal(); System.arraycopy(hash.getBytes(), 0, key, 1, 32); return key; }
private String getFingerprint(byte[] b) { String inputFingerprint; inputFingerprint = Hex.toHexString(Arrays.copyOf(Sha256Hash.create(b).getBytes(), 4)); return inputFingerprint; }
private String getFingerprint(byte[] b) { String inputFingerprint; inputFingerprint = Hex.toHexString(Arrays.copyOf(Sha256Hash.create(b).getBytes(), 4)); return inputFingerprint; }
/** * Verifies the given R/S pair (signature) against a hash using the public key. */ public boolean verify(Sha256Hash sigHash, ECDSASignature signature) { return ECKey.verify(sigHash.getBytes(), signature, getPubKey()); }
@Override @Nullable public synchronized StoredBlock get(Sha256Hash hash) throws BlockStoreException { byte[] bits = db.get(hash.getBytes()); if (bits == null) return null; return StoredBlock.deserializeCompact(context.getParams(), ByteBuffer.wrap(bits)); }
@Override @Nullable public synchronized StoredBlock get(Sha256Hash hash) throws BlockStoreException { byte[] bits = db.get(hash.getBytes()); if (bits == null) return null; return StoredBlock.deserializeCompact(context.getParams(), ByteBuffer.wrap(bits)); }
/** * Verifies the given R/S pair (signature) against a hash using the public key. */ public boolean verify(Sha256Hash sigHash, ECDSASignature signature) { return ECKey.verify(sigHash.getBytes(), signature, getPubKey()); }
@Override public synchronized void put(StoredBlock block) throws BlockStoreException { buffer.clear(); block.serializeCompact(buffer); db.put(block.getHeader().getHash().getBytes(), buffer.array()); }
@Override public synchronized void put(StoredBlock block) throws BlockStoreException { buffer.clear(); block.serializeCompact(buffer); db.put(block.getHeader().getHash().getBytes(), buffer.array()); }
@Override public synchronized void put(StoredBlock block) throws BlockStoreException { buffer.clear(); block.serializeCompact(buffer); db.put(block.getHeader().getHash().getBytes(), buffer.array()); }
public ECKey decrypt(String passphrase) throws BadPassphraseException { String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC); ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase); Sha256Hash hash = Sha256Hash.twiceOf(key.toAddress(params).toString().getBytes(Charsets.US_ASCII)); byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4); if (!Arrays.equals(actualAddressHash, addressHash)) throw new BadPassphraseException(); return key; }
public ECKey decrypt(String passphrase) throws BadPassphraseException { String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC); ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase); Sha256Hash hash = Sha256Hash.twiceOf(key.toAddress(params).toString().getBytes(Charsets.US_ASCII)); byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4); if (!Arrays.equals(actualAddressHash, addressHash)) throw new BadPassphraseException(); return key; }
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { final MappedByteBuffer buffer = this.buffer; if (buffer == null) throw new BlockStoreException("Store closed"); lock.lock(); try { lastChainHead = chainHead; byte[] headHash = chainHead.getHeader().getHash().getBytes(); buffer.position(8); buffer.put(headHash); } finally { lock.unlock(); } }
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { final MappedByteBuffer buffer = this.buffer; if (buffer == null) throw new BlockStoreException("Store closed"); lock.lock(); try { lastChainHead = chainHead; byte[] headHash = chainHead.getHeader().getHash().getBytes(); buffer.position(8); buffer.put(headHash); } finally { lock.unlock(); } }
/** * Verifies the given R/S pair (signature) against a hash using the public key, and throws an exception * if the signature doesn't match * @throws java.security.SignatureException if the signature does not match. */ public void verifyOrThrow(Sha256Hash sigHash, ECDSASignature signature) throws SignatureException { if (!ECKey.verify(sigHash.getBytes(), signature, getPubKey())) throw new SignatureException(); }
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { final MappedByteBuffer buffer = this.buffer; if (buffer == null) throw new BlockStoreException("Store closed"); lock.lock(); try { lastChainHead = chainHead; byte[] headHash = chainHead.getHeader().getHash().getBytes(); buffer.position(8); buffer.put(headHash); } finally { lock.unlock(); } }
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.chainHeadHash = hash; this.chainHeadBlock = chainHead; batchPut(getKey(KeyType.CHAIN_HEAD_SETTING), hash.getBytes()); if (instrument) endMethod("setChainHead"); }
private static Protos.UnspentOutput makeUTXOProto(OutPointOutput utxo) { Protos.UnspentOutput.Builder utxoBuilder = Protos.UnspentOutput.newBuilder(); utxoBuilder.setOutPointHash(ByteString.copyFrom(utxo.getTxHash().getBytes())); utxoBuilder.setOutPointIndex((int) utxo.getIndex()); utxoBuilder.setScriptBytes(ByteString.copyFrom(utxo.getScriptBytes())); utxoBuilder.setValue(utxo.getValueLong()); if (utxo.isGenerated()) utxoBuilder.setIsGenerated(true); return utxoBuilder.build(); }