|
1 | 1 | import chalk from "chalk"; |
2 | 2 | import type { Ora } from "ora"; |
3 | 3 | import { namehash, type Address, type Hex, zeroAddress, checksumAddress } from "viem"; |
4 | | -import { decode, encode, getCodec, cidForWeb } from "@ensdomains/content-hash"; |
5 | 4 | import type { PolkadotSigner } from "polkadot-api"; |
6 | 5 | import type { ReviveClientWrapper } from "../client/polkadotClient"; |
7 | 6 | import { CONTRACTS, DOTNS_REGISTRY_ABI, DOTNS_CONTENT_RESOLVER_ABI } from "../utils/constants"; |
8 | 7 | import { performContractCall, submitContractTransaction } from "../utils/contractInteractions"; |
| 8 | +import { decodeIpfsContenthash, encodeIpfsContenthash } from "../bulletin/cid"; |
9 | 9 |
|
10 | 10 | function decodeContenthashToCid(contenthash: Hex): string { |
11 | 11 | if (contenthash === "0x" || contenthash === "0x0" || contenthash.length < 6) { |
12 | 12 | return "No CID set"; |
13 | 13 | } |
14 | 14 |
|
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}`; |
28 | 17 | } |
29 | 18 |
|
30 | 19 | 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; |
38 | 22 | } |
39 | 23 |
|
40 | 24 | export async function viewDomainContentHash( |
|
0 commit comments