Skip to content

Commit 22f2706

Browse files
authored
feat(cli): fix issue with content hash handling (#9)
1 parent c05d51e commit 22f2706

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

packages/cli/src/commands/contentHash.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
11
import chalk from "chalk";
22
import type { Ora } from "ora";
33
import { namehash, type Address, type Hex, zeroAddress, checksumAddress } from "viem";
4-
import { decode, encode, getCodec, cidForWeb } from "@ensdomains/content-hash";
54
import type { PolkadotSigner } from "polkadot-api";
65
import type { ReviveClientWrapper } from "../client/polkadotClient";
76
import { CONTRACTS, DOTNS_REGISTRY_ABI, DOTNS_CONTENT_RESOLVER_ABI } from "../utils/constants";
87
import { performContractCall, submitContractTransaction } from "../utils/contractInteractions";
8+
import { decodeIpfsContenthash, encodeIpfsContenthash } from "../bulletin/cid";
99

1010
function decodeContenthashToCid(contenthash: Hex): string {
1111
if (contenthash === "0x" || contenthash === "0x0" || contenthash.length < 6) {
1212
return "No CID set";
1313
}
1414

15-
try {
16-
const codec = getCodec(contenthash);
17-
18-
if (codec !== "ipfs") {
19-
return `Unsupported codec: ${codec}`;
20-
}
21-
22-
const decoded = decode(contenthash);
23-
return cidForWeb(decoded);
24-
} catch (error) {
25-
console.error("Error decoding contenthash:", error);
26-
return `Unable to decode: ${contenthash}`;
27-
}
15+
const cid = decodeIpfsContenthash(contenthash);
16+
return cid ?? `Unable to decode: ${contenthash}`;
2817
}
2918

3019
function encodeCidToContenthash(cidString: string): Hex {
31-
try {
32-
const encoded = encode("ipfs", cidString);
33-
return `0x${encoded}` as Hex;
34-
} catch (error) {
35-
console.error("Error encoding CID to contenthash:", error);
36-
throw new Error(`Invalid CID: ${cidString}`);
37-
}
20+
const encoded = encodeIpfsContenthash(cidString);
21+
return `0x${encoded}` as Hex;
3822
}
3923

4024
export async function viewDomainContentHash(

0 commit comments

Comments
 (0)