test
Wednesday, June 19, 2024
HomeBitcoinbitcoinjs - Self-importance address- Merging cut up keys - addition and multiplication...

bitcoinjs – Self-importance address- Merging cut up keys – addition and multiplication of two elliptic curves


Whats up expensive hackerplebs,

i attempt to refactor js code for merging cut up keys to get a privKey for an arrogance handle.
For higher learn/understanding, for up to date packages (bitcoinjs-lib) and perhaps integrations into wallets. Right here is the code i need to refactoring https://github.com/sashmaaan/VanityAddressMerger/blob/grasp/src/sashmaaan.vmerge.js

given: vanityAddress, privkey, partialPrivkey

There are 6 circumstances/mathematical operations i’ve recognized to get the correct privatekey, and it ought to return 18 combined-privatekeys, however i get 23 then i attempt to discover the one with the correct derived handle that’s the identical because the vanityAddress.

So i feel there have to be one thing fallacious with the constants n or lambda1 and lambda2, or negatiation of the bigints.

import * as bitcoin from "bitcoinjs-lib";
import { ECPairFactory } from 'ecpair';
import * as ecc from 'tiny-secp256k1';

const ECPair = ECPairFactory(ecc);
import bigInt from "big-integer";
const orderBigInt = bigInt('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 16);
const n = bigInt("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16);

const lambdaKey = bigInt('5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72', 16)
/* const lambdaKeyBuffer =  Buffer.from(lambdaBigInt, 'hex');
const lambdaKey = ECPair.fromPrivateKey(lambdaKeyBuffer); */
const lambda2Key = bigInt('ac9c52b33fa3cf1f5ad9e3fd77ed9ba4a880b9fc8ec739c2e0cfc810b51283ce', 16)
/* const lambdaKeyBuffer2 = Buffer.from(lambdaBigInt2, 'hex');
const lambda2Key = ECPair.fromPrivateKey(lambdaKeyBuffer2);
 */

operate mergeKeys(addr, privKey, partialPrivKey) {
    if (privKey === partialPrivKey) {
        throw new Error('Personal non-public key and partial non-public key are the identical');
    }

    if (!privKey || !partialPrivKey) {
        throw new Error('One of many non-public keys is null');
    }

    const ownKeyPair = ECPair.fromWIF(privKey);
    const partialKeyPair = ECPair.fromWIF(partialPrivKey);
    const ownKey = bigInt(ownKeyPair.privateKey.toString('hex'), 16);
    const partPrivKey = bigInt(partialKeyPair.privateKey.toString('hex'), 16);

    const keyPairs = [ownKey, partPrivKey];
    operate negateKey(key) {
        return n.subtract(key).mod(n);
    }

    // Strive merging non-public keys each methods (addition and multiplication)
    for (const keyPair2 of keyPairs) {
        for (const keyPair1 of keyPairs) {
            // No sym, no endo
            const mergedPrivateKey1 = keyPair1.add(keyPair2).mod(n);
            const privateKeyHex1 = mergedPrivateKey1.toString(16).padStart(64, '0');
            const privateKeyBuffer1 = Buffer.from(privateKeyHex1, 'hex');
            const mergedKeyPair1 = ECPair.fromPrivateKey(privateKeyBuffer1, { community: bitcoin.networks.bitcoin });
            console.log(mergedKeyPair1.toWIF(), 1)

            // No sym, endo 1
            const mergedPrivateKey2 = keyPair1.multiply(lambdaKey).mod(n).add(keyPair2).mod(n);
            const privateKeyHex2 = mergedPrivateKey2.toString(16).padStart(64, '0');
            const privateKeyBuffer2 = Buffer.from(privateKeyHex2, 'hex');
            const mergedKeyPair2 = ECPair.fromPrivateKey(privateKeyBuffer2, { community: bitcoin.networks.bitcoin });
            console.log(mergedKeyPair2.toWIF(), 2)

            // No sym, endo 2
            const mergedPrivateKey3 = keyPair1.multiply(lambda2Key).mod(n).add(keyPair2).mod(n);
            const privateKeyHex3 = mergedPrivateKey3.toString(16).padStart(64, '0');
            const privateKeyBuffer3 = Buffer.from(privateKeyHex3, 'hex');
            const mergedKeyPair3 = ECPair.fromPrivateKey(privateKeyBuffer3, { community: bitcoin.networks.bitcoin });
            console.log(mergedKeyPair3.toWIF(), 3)

            // Symmetric, no endo
            let mergedPrivateKey4 = negateKey(keyPair1).negate().add(keyPair2).mod(n)
            mergedPrivateKey4 = negateKey(mergedPrivateKey4)
            //mergedPrivateKey4 = negate(mergedPrivateKey4)
            const privateKeyHex4 = mergedPrivateKey4.toString(16).padStart(64, '0');
            const privateKeyBuffer4 = Buffer.from(privateKeyHex4, 'hex');
            const mergedKeyPair4 = ECPair.fromPrivateKey(privateKeyBuffer4, { community: bitcoin.networks.bitcoin });
            console.log(mergedKeyPair4.toWIF(), 4)

            // Symmetric, endo 1
            const mergedPrivateKey5 = keyPair1.multiply(lambdaKey).mod(n).negate().add(orderBigInt).add(keyPair2).mod(n);
            const privateKeyHex5 = mergedPrivateKey5.toString(16).padStart(64, '0');
            const privateKeyBuffer5 = Buffer.from(privateKeyHex5, 'hex');
            const mergedKeyPair5 = ECPair.fromPrivateKey(privateKeyBuffer5, { community: bitcoin.networks.bitcoin });
            console.log(mergedKeyPair5.toWIF(), 5)

            // Symmetric, endo 2
            const mergedPrivateKey6 = keyPair1.multiply(lambda2Key).mod(n).negate().add(orderBigInt).add(keyPair2).mod(n);
            const privateKeyHex6 = mergedPrivateKey6.toString(16).padStart(64, '0');
            const privateKeyBuffer6 = Buffer.from(privateKeyHex6, 'hex');
            const mergedKeyPair6 = ECPair.fromPrivateKey(privateKeyBuffer6, { community: bitcoin.networks.bitcoin });
            console.log(mergedKeyPair6.toWIF(), 6)

            // Generate addresses for every merged key pair
            const address1 = getAddressFromKeyType(addr.charAt(0), mergedKeyPair1);
            const address2 = getAddressFromKeyType(addr.charAt(0), mergedKeyPair2);
            const address3 = getAddressFromKeyType(addr.charAt(0), mergedKeyPair3);
            const address4 = getAddressFromKeyType(addr.charAt(0), mergedKeyPair4);
            const address5 = getAddressFromKeyType(addr.charAt(0), mergedKeyPair5);
            const address6 = getAddressFromKeyType(addr.charAt(0), mergedKeyPair6);

            // Test if any of the addresses match the goal handle
            if (addr === address1) return mergedKeyPair1.toWIF();
            if (addr === address2) return mergedKeyPair2.toWIF();
            if (addr === address3) return mergedKeyPair3.toWIF();
            if (addr === address4) return mergedKeyPair4.toWIF();
            if (addr === address5) return mergedKeyPair5.toWIF();
            if (addr === address6) return mergedKeyPair6.toWIF();
        }
    }

    //throw new Error('Did not discover a legitimate merged non-public key.');
}

operate getAddressFromKeyType(keyType, keyPair) {
    swap (keyType) {
        case "1":
            const addr = bitcoin.funds.p2pkh({ pubkey: keyPair.publicKey, community: bitcoin.networks.bitcoin }).handle;
            return addr
        case "3":
            return bitcoin.funds.p2sh({ redeem: bitcoin.funds.p2wpkh({ pubkey: keyPair.publicKey }), community: bitcoin.networks.bitcoin }).handle;
        case "b":
        case "B":
            return bitcoin.funds.p2wpkh({ pubkey: keyPair.publicKey, community: bitcoin.networks.bitcoin }).handle;
        default:
            return null;
    }
}

const addr="1btcxcVyqf8jfkscQmYPBGRurZQG8PMtb";
const privKey = 'KzNCSsMnhf34GBt91tSbgDAC2YKt6cuX2XDiRzZtC487koBUHh5N';
const partialPrivKey = 'Kyc35db3dauFrVLSDYWgmrqAQCEcPf1Xnkv9QbGWYboE3FkV7rMv';

//anticipated non-public key: L53BPaiJWm3wJ4APYRzHo6sTUTYc76YY7Kx6ScyTBRkrYJ1My3S4
// mergeKeys(addr, privKey, partialPrivKey);
strive {
    const mergedPrivateKey = mergeKeys(addr, privKey, partialPrivKey);
    console.log('Merged Non-public Key (WIF Compressed):', mergedPrivateKey);
} catch (error) {
    console.error('Error:', error.message, error)
}```


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments