javascript - 两个 TX 的双哈希

我希望对两个 tx 进行双重哈希处理,以便构建 merkle tree

这个

const bsv = require("bsv");
var tx1 = '3a459eab5f0cf8394a21e04d2ed3b2beeaa59795912e20b9c680e9db74dfb18c';
var tx2 = 'be38f46f0eccba72416aed715851fd07b881ffb7928b7622847314588e06a6b7';

bsv.crypto.Hash.sha256sha256(Buffer.concat(
    [ tx1, tx2 ].map( v => Buffer.from(v, 'hex') )
)).toString('hex');

给了我

215f8397a3090a0bc8f4a2e98609a10d55fc7b939fa1ecf9803df20b1ee089a2

但应该是

13a3595f2610c8e4d727130daade66c772fdec4bd2463d773fd0f85c20ced32d

如何得到正确的结果?

最佳答案

作为pointed out在继续使用 concat() 和双哈希之前,您需要先将 tx 哈希转换为小端。

因为您使用的是 Buffer,所以这可以通过 .reverse() 有效地完成,

const bsv = require("bsv");
var tx1 = '3a459eab5f0cf8394a21e04d2ed3b2beeaa59795912e20b9c680e9db74dfb18c';
var tx2 = 'be38f46f0eccba72416aed715851fd07b881ffb7928b7622847314588e06a6b7';

bsv.crypto.Hash.sha256sha256(Buffer.concat(
    [ tx1, tx2 ].map( v => Buffer.from(v, 'hex').reverse() )
)).reverse().toString('hex');

https://stackoverflow.com/questions/68221837/

相关文章:

postgresql - 为什么我的 PostgreSQL 在 CURRENT_TIMESTAMP

javascript - 使用 react-hook-form 重置功能时,Material-UI

python - 如何在 python 中循环函数 def,直到我写下数字 0

html - Bootstrap 警报按钮设计已关闭,单击时不会关闭

arrays - 通过在 c 中迭代打印字符

python - Jinja2模板,去掉回车

common-lisp - 为什么在这种情况下 find 函数返回 NIL?

r - 从向量中提取重复 n 次的元素 (R)

javascript - 一个数组中的字符串在另一个数组中存在多少次?

r - 根据列中的值创建新行?