Skip to content

Commit

Permalink
Used Hex for raw transaction vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Oct 20, 2023
1 parent 887d8ff commit 4108de6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 63 deletions.
28 changes: 14 additions & 14 deletions typescript/src/lib/bitcoin/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,26 @@ export type BitcoinUtxo = BitcoinTxOutpoint & {
*/
export interface BitcoinRawTxVectors {
/**
* Transaction version as an un-prefixed hex string.
* Transaction version as a hex string.
*/
version: string
version: Hex

/**
* All transaction's inputs prepended by the number of transaction inputs,
* as an un-prefixed hex string.
* as a hex string.
*/
inputs: string
inputs: Hex

/**
* All transaction's outputs prepended by the number of transaction outputs,
* as an un-prefixed hex string.
* as a hex string.
*/
outputs: string
outputs: Hex

/**
* Transaction locktime as an un-prefixed hex string.
* Transaction locktime as a hex string.
*/
locktime: string
locktime: Hex
}

/**
Expand All @@ -133,11 +133,11 @@ export interface BitcoinRawTxVectors {
export function extractBitcoinRawTxVectors(
rawTransaction: BitcoinRawTx
): BitcoinRawTxVectors {
const toHex = (bufferWriter: any): string => {
return bufferWriter.render().toString("hex")
const toHex = (bufferWriter: any): Hex => {
return Hex.from(bufferWriter.render())
}

const getTxInputVector = (tx: Tx): string => {
const getTxInputVector = (tx: Tx): Hex => {
const buffer = bufio.write()
buffer.writeVarint(tx.ins.length)
tx.ins.forEach((input) => {
Expand All @@ -149,7 +149,7 @@ export function extractBitcoinRawTxVectors(
return toHex(buffer)
}

const getTxOutputVector = (tx: Tx): string => {
const getTxOutputVector = (tx: Tx): Hex => {
const buffer = bufio.write()
buffer.writeVarint(tx.outs.length)
tx.outs.forEach((output) => {
Expand All @@ -159,13 +159,13 @@ export function extractBitcoinRawTxVectors(
return toHex(buffer)
}

const getTxVersion = (tx: Tx): string => {
const getTxVersion = (tx: Tx): Hex => {
const buffer = bufio.write()
buffer.writeU32(tx.version)
return toHex(buffer)
}

const getTxLocktime = (tx: Tx): string => {
const getTxLocktime = (tx: Tx): Hex => {
const buffer = bufio.write()
buffer.writeU32(tx.locktime)
return toHex(buffer)
Expand Down
16 changes: 8 additions & 8 deletions typescript/src/lib/ethereum/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,18 @@ export class EthereumBridge
vault?: ChainIdentifier
): Promise<string> {
const depositTxParam = {
version: `0x${depositTx.version}`,
inputVector: `0x${depositTx.inputs}`,
outputVector: `0x${depositTx.outputs}`,
locktime: `0x${depositTx.locktime}`,
version: depositTx.version.toPrefixedString(),
inputVector: depositTx.inputs.toPrefixedString(),
outputVector: depositTx.outputs.toPrefixedString(),
locktime: depositTx.locktime.toPrefixedString(),
}

const revealParam = {
fundingOutputIndex: depositOutputIndex,
blindingFactor: `0x${deposit.blindingFactor}`,
walletPubKeyHash: `0x${deposit.walletPublicKeyHash}`,
refundPubKeyHash: `0x${deposit.refundPublicKeyHash}`,
refundLocktime: `0x${deposit.refundLocktime}`,
blindingFactor: deposit.blindingFactor.toPrefixedString(),
walletPubKeyHash: deposit.walletPublicKeyHash.toPrefixedString(),
refundPubKeyHash: deposit.refundPublicKeyHash.toPrefixedString(),
refundLocktime: deposit.refundLocktime.toPrefixedString(),
vault: vault ? `0x${vault.identifierHex}` : constants.AddressZero,
}

Expand Down
32 changes: 17 additions & 15 deletions typescript/test/data/deposit-sweep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,22 +566,24 @@ export const depositSweepProof: DepositSweepProofTestData = {
},
expectedSweepProof: {
sweepTx: {
version: "01000000",
inputs:
version: Hex.from("01000000"),
inputs: Hex.from(
"048f99b22593afdc4e3c08c7821151e801b2e9a16bf307c087a1b8c1f8459e4dea0" +
"0000000c9483045022100bb54f2717647b2f2c5370b5f12b55e27f97a6e2009dcd2" +
"1fca08527df949e1fd022058bc3cd1dd739b89b9e4cda43b13bc59cfb15663b80cb" +
"fa3edb4539107bba35d012103989d253b17a6a0f41838b84ff0d20e8898f9d7b1a9" +
"8f2564da4cc29dcf8581d94c5c14934b98637ca318a4d6e7ca6ffd1690b8e77df63" +
"77508f9f0c90d000395237576a9148db50eb52063ea9d98b3eac91489a90f738986" +
"f68763ac6776a914e257eccafbc07c381642ce6e7e55120fb077fbed8804e025016" +
"2b175ac68fffffffffd337f1abd32f17566e17a3606714d981bb8982339805ebb84" +
"c881174cff44c80000000000ffffffff73a486cf5ca706f513b6bf170ed0e7465d5" +
"bbe2968b4c2a9a207ac0ebc68c5440000000000ffffffff78439e510ac6b659b529" +
"a608611a77ca05f00ca050648212e16447460ec048f50000000000ffffffff",
outputs:
"01789b0000000000001600148db50eb52063ea9d98b3eac91489a90f738986f6",
locktime: "00000000",
"0000000c9483045022100bb54f2717647b2f2c5370b5f12b55e27f97a6e2009dcd2" +
"1fca08527df949e1fd022058bc3cd1dd739b89b9e4cda43b13bc59cfb15663b80cb" +
"fa3edb4539107bba35d012103989d253b17a6a0f41838b84ff0d20e8898f9d7b1a9" +
"8f2564da4cc29dcf8581d94c5c14934b98637ca318a4d6e7ca6ffd1690b8e77df63" +
"77508f9f0c90d000395237576a9148db50eb52063ea9d98b3eac91489a90f738986" +
"f68763ac6776a914e257eccafbc07c381642ce6e7e55120fb077fbed8804e025016" +
"2b175ac68fffffffffd337f1abd32f17566e17a3606714d981bb8982339805ebb84" +
"c881174cff44c80000000000ffffffff73a486cf5ca706f513b6bf170ed0e7465d5" +
"bbe2968b4c2a9a207ac0ebc68c5440000000000ffffffff78439e510ac6b659b529" +
"a608611a77ca05f00ca050648212e16447460ec048f50000000000ffffffff"
),
outputs: Hex.from(
"01789b0000000000001600148db50eb52063ea9d98b3eac91489a90f738986f6"
),
locktime: Hex.from("00000000"),
},
sweepProof: {
merkleProof: Hex.from(
Expand Down
22 changes: 12 additions & 10 deletions typescript/test/data/redemption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,20 @@ export const redemptionProof: RedemptionProofTestData = {
},
expectedRedemptionProof: {
redemptionTx: {
version: "01000000",
inputs:
version: Hex.from("01000000"),
inputs: Hex.from(
"01e30b907d077893bd0ed819c66644027b1dd30e4d3f68bc51da7933f75bbb283d0" +
"100000000ffffffff",
outputs:
"100000000ffffffff"
),
outputs: Hex.from(
"051c3e0000000000001976a9144130879211c54df460e484ddf9aac009cb38ee748" +
"8ac242c0000000000001600144130879211c54df460e484ddf9aac009cb38ee74ac" +
"2600000000000017a9143ec459d0f3c29286ae5df5fcc421e2786024277e8764320" +
"0000000000022002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf" +
"08f98cbf04ca96ccfb1400000000001600148db50eb52063ea9d98b3eac91489a90" +
"f738986f6",
locktime: "00000000",
"8ac242c0000000000001600144130879211c54df460e484ddf9aac009cb38ee74ac" +
"2600000000000017a9143ec459d0f3c29286ae5df5fcc421e2786024277e8764320" +
"0000000000022002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf" +
"08f98cbf04ca96ccfb1400000000001600148db50eb52063ea9d98b3eac91489a90" +
"f738986f6"
),
locktime: Hex.from("00000000"),
},
redemptionProof: {
merkleProof: Hex.from(
Expand Down
8 changes: 4 additions & 4 deletions typescript/test/lib/bitcoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ describe("Bitcoin", () => {
depositSweepWithNoMainUtxoAndWitnessOutput.expectedSweep.transaction
const decomposedTransaction = extractBitcoinRawTxVectors(rawTransaction)

expect(decomposedTransaction.version).to.be.equal("01000000")
expect(decomposedTransaction.inputs).to.be.equal(
expect(decomposedTransaction.version.toString()).to.be.equal("01000000")
expect(decomposedTransaction.inputs.toString()).to.be.equal(
"02bc187be612bc3db8cfcdec56b75e9bc0262ab6eacfe27cc1a699bacd53e3d07400" +
"000000c948304502210089a89aaf3fec97ac9ffa91cdff59829f0cb3ef852a468153" +
"e2c0e2b473466d2e022072902bb923ef016ac52e941ced78f816bf27991c2b73211e" +
Expand All @@ -891,10 +891,10 @@ describe("Bitcoin", () => {
"68ffffffffdc557e737b6688c5712649b86f7757a722dc3d42786f23b2fa826394df" +
"ec545c0000000000ffffffff"
)
expect(decomposedTransaction.outputs).to.be.equal(
expect(decomposedTransaction.outputs.toString()).to.be.equal(
"01488a0000000000001600148db50eb52063ea9d98b3eac91489a90f738986f6"
)
expect(decomposedTransaction.locktime).to.be.equal("00000000")
expect(decomposedTransaction.locktime.toString()).to.be.equal("00000000")
})
})

Expand Down
24 changes: 12 additions & 12 deletions typescript/test/lib/ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ describe("Ethereum", () => {
await bridgeHandle.revealDeposit(
// Just short byte strings for clarity.
{
version: "00000000",
inputs: "11111111",
outputs: "22222222",
locktime: "33333333",
version: Hex.from("00000000"),
inputs: Hex.from("11111111"),
outputs: Hex.from("22222222"),
locktime: Hex.from("33333333"),
},
2,
{
Expand Down Expand Up @@ -192,10 +192,10 @@ describe("Ethereum", () => {

await bridgeHandle.submitDepositSweepProof(
{
version: "00000000",
inputs: "11111111",
outputs: "22222222",
locktime: "33333333",
version: Hex.from("00000000"),
inputs: Hex.from("11111111"),
outputs: Hex.from("22222222"),
locktime: Hex.from("33333333"),
},
{
merkleProof: Hex.from("44444444"),
Expand Down Expand Up @@ -290,10 +290,10 @@ describe("Ethereum", () => {

await bridgeHandle.submitRedemptionProof(
{
version: "00000000",
inputs: "11111111",
outputs: "22222222",
locktime: "33333333",
version: Hex.from("00000000"),
inputs: Hex.from("11111111"),
outputs: Hex.from("22222222"),
locktime: Hex.from("33333333"),
},
{
merkleProof: Hex.from("44444444"),
Expand Down

0 comments on commit 4108de6

Please sign in to comment.