Java Code Examples for org.bitcoinj.core.ECKey#signMessage()

The following examples show how to use org.bitcoinj.core.ECKey#signMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProofOfBurnService.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public Optional<String> sign(String proofOfBurnTxId, String message) {
    byte[] pubKey = getPubKey(proofOfBurnTxId);
    ECKey key = bsqWalletService.findKeyFromPubKey(pubKey);
    if (key == null)
        return Optional.empty();

    try {
        String signatureBase64 = bsqWalletService.isEncrypted()
                ? key.signMessage(message, bsqWalletService.getAesKey())
                : key.signMessage(message);
        return Optional.of(signatureBase64);
    } catch (Throwable t) {
        log.error(t.toString());
        t.printStackTrace();
        return Optional.empty();
    }
}
 
Example 2
Source File: SignedWitnessService.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public void signAccountAgeWitness(Coin tradeAmount,
                                  AccountAgeWitness accountAgeWitness,
                                  ECKey key,
                                  PublicKey peersPubKey) {
    if (isSignedAccountAgeWitness(accountAgeWitness)) {
        log.warn("Arbitrator trying to sign already signed accountagewitness {}", accountAgeWitness.toString());
        return;
    }

    String accountAgeWitnessHashAsHex = Utilities.encodeToHex(accountAgeWitness.getHash());
    String signatureBase64 = key.signMessage(accountAgeWitnessHashAsHex);
    SignedWitness signedWitness = new SignedWitness(SignedWitness.VerificationMethod.ARBITRATOR,
            accountAgeWitness.getHash(),
            signatureBase64.getBytes(Charsets.UTF_8),
            key.getPubKey(),
            peersPubKey.getEncoded(),
            new Date().getTime(),
            tradeAmount.value);
    publishSignedWitness(signedWitness);
    log.info("Arbitrator signed witness {}", signedWitness.toString());
}
 
Example 3
Source File: SignedWitnessServiceTest.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testIsValidAccountAgeWitnessLongLoop() throws Exception {
    AccountAgeWitness aew = null;
    KeyPair signerKeyPair;
    KeyPair signedKeyPair = Sig.generateKeyPair();
    int iterations = 1002;
    for (int i = 0; i < iterations; i++) {
        byte[] accountDataHash = org.bitcoinj.core.Utils.sha256hash160(String.valueOf(i).getBytes(Charsets.UTF_8));
        long accountCreationTime = getTodayMinusNDays((iterations - i) * (SignedWitnessService.SIGNER_AGE_DAYS + 1));
        aew = new AccountAgeWitness(accountDataHash, accountCreationTime);
        String accountDataHashAsHexString = Utilities.encodeToHex(accountDataHash);
        byte[] signature;
        byte[] signerPubKey;
        if (i == 0) {
            // use arbitrator key
            ECKey arbitratorKey = new ECKey();
            signedKeyPair = Sig.generateKeyPair();
            String signature1String = arbitratorKey.signMessage(accountDataHashAsHexString);
            signature = signature1String.getBytes(Charsets.UTF_8);
            signerPubKey = arbitratorKey.getPubKey();
        } else {
            signerKeyPair = signedKeyPair;
            signedKeyPair = Sig.generateKeyPair();
            signature = Sig.sign(signedKeyPair.getPrivate(), accountDataHashAsHexString.getBytes(Charsets.UTF_8));
            signerPubKey = Sig.getPublicKeyBytes(signerKeyPair.getPublic());
        }
        byte[] witnessOwnerPubKey = Sig.getPublicKeyBytes(signedKeyPair.getPublic());
        long date = getTodayMinusNDays((iterations - i) * (SignedWitnessService.SIGNER_AGE_DAYS + 1));
        SignedWitness sw = new SignedWitness(i == 0 ? ARBITRATOR : TRADE, accountDataHash, signature, signerPubKey, witnessOwnerPubKey, date, tradeAmount1);
        signedWitnessService.addToMap(sw);
    }
    assertFalse(signedWitnessService.isSignerAccountAgeWitness(aew));
}
 
Example 4
Source File: ArbitratorManager.java    From bisq-core with GNU Affero General Public License v3.0 4 votes vote down vote up
public String signStorageSignaturePubKey(ECKey key) {
    String keyToSignAsHex = Utils.HEX.encode(keyRing.getPubKeyRing().getSignaturePubKey().getEncoded());
    return key.signMessage(keyToSignAsHex);
}
 
Example 5
Source File: DisputeAgentManager.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
public String signStorageSignaturePubKey(ECKey key) {
    String keyToSignAsHex = Utils.HEX.encode(keyRing.getPubKeyRing().getSignaturePubKey().getEncoded());
    return key.signMessage(keyToSignAsHex);
}