Fetching block from Cosmos/Osmosis blockchain. Convert bytes to string then decrypt string

213 Views Asked by At

I am trying to fetch data like block_hash from Osmosis chain. The problem is I am getting a Uint8Array that I cannot actually convert to readable string/hash.

Response I get from my js app:

blockId: {
    hash: Uint8Array(32) [
       91, 215, 254, 180,  87, 180, 160, 121,
       12,  47, 235,  35, 219, 203,  27,  45,
      102, 213,  50,  40,  54, 194,  33,  28,
      231, 139, 216, 246,  45,  73,  58, 188
    ],
    partSetHeader: { total: 2, hash: [Uint8Array] }
}
  

Response I get from Postman:

"block_id": {
   "hash": "mHyghR6nW+Mb+2SZ5DYTw6xfLO+IlrMW3vMh9nXo394=",
   "part_set_header": {
      "total": 2,
      "hash": "u78nOYgp5bAZXmymTBFPbNIPxI+1NuRhi+I32Z5pSKY="
   }
}

First I can't convert the Uint8Array to anything readable because when I try it with this code:

const string = new TextDecoder().decode(hash);
console.log(string);

I get this:

ڨ9�$Օka�
�Ց���ewf�§�qA�♥߂��

Also mHyghR6nW+Mb+2SZ5DYTw6xfLO+IlrMW3vMh9nXo394= is definitely not a valid blockchain transaction hash

A valid one looks like this: BE2E8DFB4489D0349C78BC30D14802DE88FDF581F8DB6B6FAFA9EB6157646C07

Do you have any ideas is this any kind of encryption and if so how can I decrypt it?

Thank you very much in advance!

1

There are 1 best solutions below

0
On

Use below mentioned code to convert blockhash into valid one /

const blockId="u78nOYgp5bAZXmymTBFPbNIPxI+1NuRhi+I32Z5pSKY=";
console.log(Buffer.from(blockId,'base64').toString("hex"))