Blockcert-verifier explorerAPI

Question for the demo/explorer-api.html folder in blockcert-verifier, is the jsonResponse the response from the api call? and does the jsonResponse format is equal to what they return when doing it manually (for example, i test etherscan api in the post man and it returns the json. Does the return json equals the jsonResponse?)

The parsingFunction is the code you need to create to read the answer from the explorer api (etherscan for instance). It is called with the parameters defined in the example/readme, which should be sufficient for you to get the data you need from the server.
You need to return the object answer from this function as defined, otherwise the code might not work as expected. I think the object is exposed in typescript to help you with that.

I tried to set the variable according to what my explorer api returns, but it stucks in Trying to access issuing address when txData not available yet. Did you run the 'verify' method yet?. Here is my parsing function

parsingFunction: (jsonResponse)=>{
const time = timestampToDateObject(jsonResponse[“timestamp”]);
const issuingAddress = jsonResponse[“from”];
const remoteHash=jsonResponse[“hash”];
const revokedAddresses = [“0x88d2a0d90b290d7233045e364501f9dd8b3680cf”];
return {

and here is what my explorer api return:

“to”: “0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead”,
“timestamp”: “2021-11-03T10:30:56.000Z”,
“from”: “0x88d2a0d90b290d7233045e364501f9dd8b3680cf”,
“inputBytes”: “0xa7b75ae9977d40f196dbaf5018312d31340057d64cd30fc5761c220044e03b11”,
“gasProvided”: 25000,
“blockNumber”: 73589,
“blockHash”: “0xeb313cae9c42cd76f8bc2780f65c7eee41fea33d9e352b8ce1334dcb938030b5”,
“private”: true,
“status”: “success”,
“nextHash”: null,
“previousHash”: “0x2f1f4cc5e46d48f727b76657b8dee43fbd2d3cda6b24def34eb95c101eb716de”,
“index”: 0,
“hash”: “0xb7bbcbb1bae1977f134846193b222e2a839434281fc11f2ac976dd16972e6a79”

The error you are seeing is coming from here:

And this is where we set txData: cert-verifier-js/verifier.ts at a1b7bc33fb6973d105a9b5e8aa8e04a6976d8d4b · blockchain-certificates/cert-verifier-js · GitHub as a response from the explorer lookup (and thus your function). I am not sure what’s happening, you will need to investigate, but basically this.txData is not being set as it should.

it seems that the remotehash const in explorerAPI needs to have the prefixes removed. i used stripHashPrefix(jsonResponse["hash"], BLOCKCHAINS.ethereum.prefixes) (EDIT: nvm without this it works, just simple const remoteHash=jsonResponse.hash) but it still shows error, so i decided to manually input the hash without eth prefix and it works. Now the next problem is the issuer id that is in the certificate uses http, but when the blockcert-verifier open the issuer id, it uses https

Is it always going to be http? Ideally this profile would be hosted on https.
At low level there is an option on the request service to force the http request, but there is no easy way to require that externally.
I think we upgrade the request to https mostly because some profiles are hosted on github and they deny any non https request, even on documents that were initially linked to with http

The issuer id .json is now already on https, now im getting an error with the strip hash prefix in const remoteHash=stripHashPrefix(jsonResponse.inputBytes,BLOCKCHAINS.ethmain.prefixes); using it will break the explorer api and therefore uses the other api.
with strip hash prefix:


merkle root error is because the remote hash’s prefix not being stripped

So I am not sure of how things are pieced together in your code and that means I cannot give you a proper response.

did you try and take a look at what is being done here: explorer-lookup/blockcypher.ts at master · blockchain-certificates/explorer-lookup · GitHub

All in all, I believe you are trying to access a function that’s undefined in your context, stripHashPrefix. I suggest you take that function from there: explorer-lookup/stripHashPrefix.ts at master · blockchain-certificates/explorer-lookup · GitHub and declare it in the context of the your parsingFunction. Beware of the typescript annotations, you will want to run a pure js function.

I declared the stripHashPrefix function top of it, checked with online javascript compiler, and the output is correct, but somehow i still got Merkle root does not match remote hash. If i put it manually const remoteHash = "bba86d20957583b9912419f59d943e0bacf2e56c856d35d2ea9626339a4f1adf", it passes the test, but it gives error in checking authenticity:

My whole code is basically just the const explorerApi and the added stripHashPrefix function on top of it:

const explorerAPI = {

        //serviceName: 'etherscan',
        priority: 0,
        parsingFunction: (jsonResponse)=>{
             const time =  jsonResponse.timestamp;
            //const time = timestampToDateObject("2021-11-03T10:30:56.000Z");
            const time = new Date(parseInt(jsonResponse.timestamp, 16) * 1000);
            // const time = jsonResponse.timestamp;
            const issuingAddress= jsonResponse.from;
            //const issuingAddress = "0x88d2a0d90b290d7233045e364501f9dd8b3680cf";

            //const remoteHash = stripHashPrefix(jsonResponse.hash,BLOCKCHAINS.ethmain.prefixes);
           const remoteHash = "bba86d20957583b9912419f59d943e0bacf2e56c856d35d2ea9626339a4f1adf";

            return {

edit: is there a way to debug the const in explorer api so i can know whether the const is set or not?
more edit: using alert, i tried to print out the constant. remote hash is undefined, time is undefined, and issuing address is undefined
more edit: this is what the jsonResponse contains: {“jsonResponse”:{“requestId”:“4yw4lhtsc9”,“errorMessage”:“Internal error”},“chain”:“ethmain”,“key”:"",“keyPropertyName”:"",“serviceURL”:“{transaction_id}",“chainType”:“eth”,"priority”:1}

Ok there are many things to see.
First off:

Similarly to stripHashPrefix function, this is not available as a global variable and as such not available in your context. I suggest that you hardcode this value in your function: 0x.

To debug you can put some console.log in your code, this will be a bit more elegant and customisable than alert.

Apparently your server might be encountering an error.

Using your browser console (in the network or xhr tab), you should also make sure the API call is made with the correct value for the transaction.

I checked the api call from inspect element. It’s 200 success with the json content from my server. I have added the cors as well.

The error is from printing the jsonResponse in explorerAPI. Console.log doesn’t seem to appear in the console in firefox

Alright i found out my probelm yesterday, it seems the api server that i’ve been calling is off, so i need to turn it on. The object returned in the const explorerApi has nested jsonResponse inside, so i need to get the varible inside it by using:
const time = dateToUnixTimestamp(jsonResponse.jsonResponse.timestamp)
const issuingAddress= jsonResponse.jsonResponse.from
const remoteHash=stripHashPrefix(jsonResponse.jsonResponse.inputBytes,['0x'])

1 Like