zodor-protocol-web3
Version:
SDK to interact with zodor protocol
70 lines • 3.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IdentityRegistry = void 0;
const ethers_1 = require("ethers");
const IdentityRegistry_json_1 = __importDefault(require("../abi/IdentityRegistry.json"));
const ContractFactory_1 = require("../factories/ContractFactory");
const utils_1 = require("../utils");
const WalletFactory_1 = require("../factories/WalletFactory");
class IdentityRegistry {
contract;
network;
constructor(options) {
const { network, contractRunner, privateKey, customRpcUrl } = options;
const contractAddress = (0, utils_1.getContractAddresses)(network).IdentityRegistryContractAddress;
if (!network)
throw new Error('network is required');
if (contractRunner) {
const contractFactory = new ContractFactory_1.ContractFactory();
this.contract = contractFactory.createContract(contractAddress, IdentityRegistry_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, IdentityRegistry_json_1.default.abi, wallet || rpcProvider);
}
this.network = network;
}
async createIdentity(options) {
const { walletAddress, taxDomicile, jurisdiction, category } = options;
const abiCoder = ethers_1.AbiCoder.defaultAbiCoder();
const jurisdictionCode = (0, ethers_1.keccak256)(abiCoder.encode(['string'], [jurisdiction]));
const domicile = (0, ethers_1.keccak256)(abiCoder.encode(['string'], [taxDomicile]));
const registerIdentityTx = await this.contract.registerIdentity(walletAddress, jurisdictionCode, domicile, category);
return registerIdentityTx;
}
async isIdentityVerifed(walletAddress) {
return await this.contract.isVerified(walletAddress);
}
async getEntityCategory(walletAddress) {
const category = await this.contract.getEntityCategory(walletAddress);
return Number(category);
}
async getEntityJurisdiction(walletAddress) {
return await this.contract.getEntityJurisdiction(walletAddress);
}
async updateRiskScore(walletAddress, score) {
return await this.contract.updateRiskScore(walletAddress, score);
}
async addJurisdiction(walletAddress, jurisdiction) {
const abiCoder = ethers_1.AbiCoder.defaultAbiCoder();
const jurisdictionCode = (0, ethers_1.keccak256)(abiCoder.encode(['string'], [jurisdiction]));
return await this.contract.addJurisdiction(walletAddress, jurisdictionCode);
}
async restrictIdentity(walletAddress, reason, status) {
return await this.contract.restrictIdentity(walletAddress, status, reason);
}
async blacklistAddress(walletAddress) {
return await this.contract.blacklistAddress(walletAddress);
}
}
exports.IdentityRegistry = IdentityRegistry;
//# sourceMappingURL=identityregistry.js.map