@axiom-crypto/tools
Version:
Useful data, field, and byte manipulation tools for Axiom.
31 lines (30 loc) • 1.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IpfsClient = void 0;
const bs58_1 = __importDefault(require("bs58"));
class IpfsClient {
constructor(name) {
this.name = name;
}
// Convert bytes32 to CIDv0
// @param bytes32Hex - IPFS hash in bytes32
// @returns - IPFS hash in CIDv0
convertIpfsCidToBytes32(ipfsCid) {
return '0x' + Buffer.from(bs58_1.default.decode(ipfsCid).slice(2)).toString('hex');
}
// Convert CIDv0 to bytes32
// @param bytes32Hex - IPFS hash in bytes32
// @returns - IPFS hash in CIDv0
convertBytes32ToIpfsCid(bytes32Hex) {
return bs58_1.default.encode(Buffer.from('1220' + bytes32Hex.slice(2), 'hex'));
}
// Get the name of the IPFS client
// @returns - IPFS client name
getName() {
return this.name;
}
}
exports.IpfsClient = IpfsClient;