What is hex_bytes in Signature?

We’re trying to build a TS client that can use the Construction API with Rosetta-Bitcoin to submit a transaction. On the step to send a request to combine, we’re having trouble figuring out what hex_bytes is in Signature.

const btcKeys = <BTC_KEYS>
const address = <ADDRESS>
const payloadsResponse = <RES_FROM_PAYLOADS_ENDPOINT>

const signingPayload = {
    hex_bytes: btcKeys.sign(Buffer.from(payloadsRes.payloads[0].hex_bytes, 'hex')).toString('hex'),
    account_identifier: {
        address: address,
    },
    signature_type: 'ecdsa',
}

const combineBody = {
    network_identifier: <BTC_TESTNET_NETWORK>,
    unsigned_transaction: payloadsRes.unsigned_transaction,
    signatures: [
        {
            hex_bytes: <'what is this?'> // <!-- question is, what to put here?,
            signing_payload: signingPayload,
            public_key: {
                hex_bytes: btcKeys.publicKey.toString('hex'),
                curve_type: "secp256k1"
            },
            signature_type: 'ecdsa',
        }
    ]
}

On the Signature page of the docs, there is no description for hex_bytes. Would it be signing the payloadsRes.unsigned_transaction? For example btcKeys.sign(Buffer.from(payloadsRes.unsigned_transaction)).toString('hex')?

VERY VERY COOL! :rocket: :rocket:

Clearly this is a point of confusion! Someone asked the IDENTICAL question on the rosetta-ethereum repo a few days ago:

I left a pretty detailed response on the linked issue that should unblock you. If you have any follow-up questions, I’m happy to answer them!

Avoiding Potential Confusion

In the linked issue I refer to types.EcdsaRecovery as the SignatureType (as it is discussing Ethereum), however, the SignatureType for Bitcoin is types.Ecdsa.

In the context of your example, signature.hex_bytes is sign(signingPayload.hex_bytes) where sign is performed by the key backing signingPayload.account_identifier. signingPayload.hex_bytes will be provided to you in the response from the /construction/payloads endpoint and should not be overwritten.

From what I can tell, you could fix your example by moving btcKeys.sign(Buffer.from(payloadsRes.payloads[0].hex_bytes, 'hex')).toString('hex') to your <'what is this?'> field and setting signatures[0].signing_payload to be payloadsRes.payloads[0]. Something like this:

const combineBody = {
    network_identifier: <BTC_TESTNET_NETWORK>,
    unsigned_transaction: payloadsRes.unsigned_transaction,
    signatures: [
        {
            hex_bytes: btcKeys.sign(Buffer.from(payloadsRes.payloads[0].hex_bytes, 'hex')).toString('hex'),
            signing_payload: payloadsRes.payloads[0],
            public_key: {
                hex_bytes: btcKeys.publicKey.toString('hex'),
                curve_type: "secp256k1"
            },
            signature_type: 'ecdsa',
        }
    ]
}
1 Like

That cleared it up for me, thanks!

1 Like