Skip to content

Instantly share code, notes, and snippets.

@assafmo
Created June 27, 2024 17:54
Show Gist options
  • Save assafmo/4d28c462d77fa4c2755b9bfb0e025980 to your computer and use it in GitHub Desktop.
Save assafmo/4d28c462d77fa4c2755b9bfb0e025980 to your computer and use it in GitHub Desktop.
import { fromBase64, fromHex, toBase64, toHex } from "secretjs";
import { TxRaw } from "secretjs/dist/protobuf/cosmos/tx/v1beta1/tx";
import { sha256 } from "@noble/hashes/sha256";
async function main() {
const txhash =
"2b324cd8d36ace2ff1d26145df2109bbaec9d508aa465d36ff88fcd72aa985a8".toUpperCase();
const tcpStream = fromHex(
[
"00002e0104000000058386c104a66087452742f18d055d25aa42d949aa4afdc3195230afb8b677310ac622a738d25426ed07275fc0bfbe0000050000000000050000000000000000000100000005",
"0000210104000000078386c104996087452742e9f2bf70c6548c2bee2d9dcc42b1b8d4db40d25fc0bfbe0002270000000000070000000222129f040ab8030ab1030a242f636f736d7761736d2e7761736d2e76312e4d736745786563757465436f6e74726163741288030a2b7761736d3133337868383339666a6e3977787a6736766863303337306c63656d383933397a723875753435123f7761736d316e633574617461667636657971376c6c6b7232677635306666396532326d6e66373071676a6c763733376b746d7434657377727172356a3268741a97027b22616e6e6f756e6365223a7b2276616c696461746f72223a2266643435636437303239303036623265366337383762653732663064616433396333333233643938222c2273746f726167655f6c6f636174696f6e223a2266696c653a2f2f2f6574632f76616c696461746f722f6c6f63616c7761736d642f636865636b706f696e74222c227369676e6174757265223a2232316639313665306139333830623438646566303137636137376161643831663536313866386361323130376638303731653130323235353761656464343633373531393331396561333762636134646534643435326434366134663536396439353030396663343137316134633033393035316136393963663736333835303162227d7d18eae90a12600a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103c4c384f84167e435d8559463050e5799ac658a96a6a504c7f293e79eb89e2bab12040a0208011826120c0a0a0a05757761736d1201301a00000000000100000007",
"00002301040000000f8386c1049b6087452742e9f2bf70c6548c2bee2d9dcc42b176c38e420d09dfe7c0bfbe00027200000000000f000000026d0ae8040ab8030ab1030a242f636f736d7761736d2e7761736d2e76312e4d736745786563757465436f6e74726163741288030a2b7761736d3133337868383339666a6e3977787a6736766863303337306c63656d383933397a723875753435123f7761736d316e633574617461667636657971376c6c6b7232677635306666396532326d6e66373071676a6c763733376b746d7434657377727172356a3268741a97027b22616e6e6f756e6365223a7b2276616c696461746f72223a2266643435636437303239303036623265366337383762653732663064616433396333333233643938222c2273746f726167655f6c6f636174696f6e223a2266696c653a2f2f2f6574632f76616c696461746f722f6c6f63616c7761736d642f636865636b706f696e74222c227369676e6174757265223a2232316639313665306139333830623438646566303137636137376161643831663536313866386361323130376638303731653130323235353761656464343633373531393331396561333762636134646534643435326434366134663536396439353030396663343137316134633033393035316136393963663736333835303162227d7d18eae90a12690a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103c4c384f84167e435d8559463050e5799ac658a96a6a504c7f293e79eb89e2bab12040a020801182612150a0f0a05757761736d120631353232353310bda5091a40f0a395ce37da4b959795cced3558c52e80e63972bf4bbb9cf826986b300301f50673b009cd7a3be9224c8aec846d23a5a1fde8f7d4562aae36f52efc15a39448100200000000010000000f",
].join("")
);
for (let i = 0; i < tcpStream.length; i++) {
for (let j = tcpStream.length; j > i; j--) {
const bytes = tcpStream.slice(i, j);
const hash = sha256(bytes);
const hashHex = toHex(hash).toUpperCase();
if (hashHex === txhash) {
console.log(toBase64(bytes));
return;
}
}
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment