zodor-protocol-web3
Version:
SDK to interact with zodor protocol
60 lines • 3.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClaimRegistry = void 0;
const ethers_1 = require("ethers");
const ClaimRegistry_json_1 = __importDefault(require("../abi/ClaimRegistry.json"));
const ContractFactory_1 = require("../factories/ContractFactory");
const utils_1 = require("../utils");
const WalletFactory_1 = require("../factories/WalletFactory");
class ClaimRegistry {
contract;
network;
constructor(options) {
const { network, contractRunner, privateKey, customRpcUrl } = options;
const contractAddress = (0, utils_1.getContractAddresses)(network).ClaimRegistryContractAddress;
if (!network)
throw new Error('network is required');
if (contractRunner) {
const contractFactory = new ContractFactory_1.ContractFactory();
this.contract = contractFactory.createContract(contractAddress, ClaimRegistry_json_1.default.abi, contractRunner);
}
else {
const rpcProvider = (0, utils_1.getRpcProvider)(network, customRpcUrl);
let wallet;
if (privateKey) {
const walletFactory = new WalletFactory_1.WalletFactory(rpcProvider);
wallet = walletFactory.createWallet(privateKey);
}
const contractFactory = new ContractFactory_1.ContractFactory();
this.contract = contractFactory.createContract(contractAddress, ClaimRegistry_json_1.default.abi, wallet || rpcProvider);
}
this.network = network;
}
async addClaim(options) {
const { walletAddress, type, data, expirationTime, proofHash = '0x', issuer } = options;
const claimType = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(type));
const identifier = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(issuer));
return await this.contract.addClaim(walletAddress, claimType, identifier, data, expirationTime, proofHash);
}
async revokeClaim(walletAddress, type, reason) {
const claimType = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(type));
return await this.contract.revokeClaim(walletAddress, claimType, reason);
}
async renewClaim(walletAddress, type, newExpiration) {
const claimType = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(type));
return await this.contract.renewClaim(walletAddress, claimType, newExpiration);
}
async verifyClaim(walletAddress, type) {
const claimType = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(type));
return await this.contract.verifyClaim(walletAddress, claimType);
}
async addClaimType(type) {
const claimType = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(type));
return await this.contract.addClaimType(claimType);
}
}
exports.ClaimRegistry = ClaimRegistry;
//# sourceMappingURL=claimRegistry.js.map