ai didi

javascript - 两个 TX 的双哈希

转载 作者:行者123 更新时间:2023-12-05 09:32:17 24 4
gpt4 key购买 nike

我希望对两个 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');

关于javascript - 两个 TX 的双哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68221837/

24 4 0
文章推荐: rust - 为什么 Rust 中原始类型之间没有隐式类型转换(强制转换)
文章推荐: javascript - Js 文件作为 cypress 中的夹具未加载
文章推荐: html - Bootstrap 警报按钮设计已关闭,单击时不会关闭
文章推荐: python - Jinja2模板,去掉回车
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com