"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubgraphDeploymentID = exports.SubgraphName = void 0;
const ethers_1 = require("ethers");
const bs58_1 = __importDefault(require("bs58"));
class SubgraphName {
    constructor(name) {
        this.kind = 'name';
        this.value = name;
    }
    toString() {
        return this.value;
    }
}
exports.SubgraphName = SubgraphName;
// Security: Input validation
const bytes32Check = /^0x[0-9a-f]{64}$/;
const multiHashCheck = /^Qm[1-9a-km-zA-HJ-NP-Z]{44}$/;
class SubgraphDeploymentID {
    constructor(id) {
        this.kind = 'deployment-id';
        let value;
        // Security: Input validation
        if (multiHashCheck.test(id)) {
            value = ethers_1.utils.hexlify(bs58_1.default.decode(id).slice(2));
        }
        else if (bytes32Check.test(id)) {
            value = id;
        }
        if (value != null) {
            this.value = value;
        }
        else {
            throw new Error(`Invalid subgraph deployment ID: ${id}`);
        }
    }
    toString() {
        return this.value;
    }
    get display() {
        return {
            bytes32: this.bytes32,
            ipfsHash: this.ipfsHash,
        };
    }
    get bytes32() {
        return this.value;
    }
    get ipfsHash() {
        return bs58_1.default.encode([0x12, 0x20, ...ethers_1.utils.arrayify(this.value)]);
    }
}
exports.SubgraphDeploymentID = SubgraphDeploymentID;
//# sourceMappingURL=index.js.map