From 42230659c1a512b82581a6733de9facfa5afca0d Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Thu, 19 Jan 2023 16:18:19 -0500 Subject: [PATCH] testing clarity and commented alternate CID generation --- .gitignore | 1 + src/messages/registry.ts | 4 +--- src/util.test.ts | 2 +- src/util.ts | 18 +++++++++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 9c97bbd..44698fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules dist .env +.idea/ \ No newline at end of file diff --git a/src/messages/registry.ts b/src/messages/registry.ts index 7ad4a32..3188ffb 100644 --- a/src/messages/registry.ts +++ b/src/messages/registry.ts @@ -75,12 +75,10 @@ export const parseMsgSetRecordResponse = (data: string) => { const responseBytes = Buffer.from(data, 'hex') // TODO: Decode response using protobuf. - // const msgSetRecordResponse = nameserviceTx.vulcanize.nameservice.v1beta1.MsgSetRecordResponse.deserialize(responseBytes); + // const msgSetRecordResponse = registryTx.vulcanize.registry.v1beta1.MsgSetRecordResponse.deserialize(responseBytes); // return msgSetRecordResponse.toObject(); - // Workaround as proto based decoding is not working. const [_, id] = responseBytes.toString().split(';') - return { id } } diff --git a/src/util.test.ts b/src/util.test.ts index df58da1..06824e5 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -25,7 +25,7 @@ const utilTests = () => { await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee); // Create watcher. - watcher = await getBaseConfig(WATCHER_YML_PATH); + watcher = await getBaseConfig(WATCHER_YML_PATH); //this overwrites version to 0.0.1 const result = await registry.setRecord( { privateKey, diff --git a/src/util.ts b/src/util.ts index e69a78d..7c2fbe5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -2,6 +2,8 @@ import * as Block from 'multiformats/block' import { sha256 as hasher } from 'multiformats/hashes/sha2' import * as dagCBOR from '@ipld/dag-cbor' import * as dagJSON from '@ipld/dag-json' +//import { CID } from 'multiformats/cid' +//import * as json from 'multiformats/codecs/json' /** * Utils @@ -86,15 +88,29 @@ export class Util { * Get record content ID. */ static async getContentId(record: any) { + //this encode/decode does nothing, afaict const serialized = dagJSON.encode(record) const recordData = dagJSON.decode(serialized) - + //these are for version 0.0.1 of watcher.yml test data: + //const dside = {"build_artifact_cid":"QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9","repo_registration_record_cid":"QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D","tls_cert_cid":"QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR","type":"WebsiteRegistrationRecord","url":"https://cerc.io","version":"0.0.1"} + //bafyreiek4hnoqmits66bjyxswapplweuoqe4en2ux6u772o4y3askpd3ny is the CBOR encoding w/ sha 256 hasher + //bafyreifalhff7dp6o4hd573b5zdbbnl2wml5q2nrms474lrzp7dgptwxkm is expected DAG-CBOR w/ sha 256 hasher + //bafyreihpfkdvib5muloxlj5b3tgdwibjdcu3zdsuhyft33z7gtgnlzlkpm is CBOR??? encoding of empty json payload. const block = await Block.encode({ value: recordData, codec: dagCBOR, hasher }) + //manual CID construction + //const dbytes = dagCBOR.encode(dside) + //console.log("BYTES: " + dbytes) + //const hash = await hasher.digest(dbytes) + //console.log("HASH: " + hash) + //const cid = CID.create(1, dagCBOR.code, hash) + + //console.log("TEST CID: " + cid.toString()) + return block.cid.toString(); } }