Skip to content

Commit

Permalink
fix: bundle summary in bsync runtime (#145)
Browse files Browse the repository at this point in the history
* fix: bundle summary in bsync runtime
  • Loading branch information
troykessler authored Jul 23, 2024
1 parent 503281c commit 424aac0
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions integrations/tendermint-bsync/src/utils/merkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,5 @@ import { dataItemToSha256, generateMerkleRoot } from '@kyvejs/sdk';
// results (only two leafs) and the key of the data item. This allows the
// Trustless API to serve block and block results independently.
export function createHashesFromTendermintBundle(bundle: any[]): Uint8Array[] {
return bundle.map((dataItem) => {
const blockHashes: Uint8Array[] = [
dataItemToSha256(dataItem.value?.block),
dataItemToSha256(dataItem.value?.block_results),
];

const merkleRoot: Uint8Array = generateMerkleRoot(blockHashes);

return tendermintDataItemToSha256(dataItem.key, merkleRoot);
});
}

function tendermintDataItemToSha256(
key: string,
merkleRoot: Uint8Array
): Uint8Array {
const keyBytes = crypto.sha256(Buffer.from(key, 'utf-8'));

const combined = Buffer.concat([keyBytes, merkleRoot]);

return crypto.sha256(combined);
return bundle.map((dataItem) => dataItemToSha256(dataItem));
}

0 comments on commit 424aac0

Please sign in to comment.