@energyweb/credential-governance
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

Energy Web Foundation Logo

Credential Governance

Description

This package consists of EVM smart contract related to EnergyWeb Name Service and libraries to resolve / read namespaces & defintions.

@energyweb/credential-governance is a typescript module.

{credential-governance} is a component of the Energy Web Decentralized Operating System

Usage

DomainReader

The DomainReader class can be used as shown to read a domain definition.

import {
  DomainReader,
  VOLTA_ENS_REGISTRY_ADDRESS,
} from "@energyweb/credential-governance";
import { providers, utils } from "ethers";

(async () => {
  const provider = new providers.JsonRpcProvider(
    "https://volta-rpc.energyweb.org"
  );
  const reader = new DomainReader({
    ensRegistryAddress: VOLTA_ENS_REGISTRY_ADDRESS,
    provider,
  });
  const roleDefinition = await reader.read({
    node: utils.namehash("manufacturer.roles.flex.apps.exampleco.iam.ewc"),
  });
})();

DomainTransactionFactoryV2

The DomainTransactionFactory class can be used to add and update definitions specific to namespaces.

import {
  DomainTransactionFactoryV2,
  VOLTA_RESOLVER_V2_ADDRESS,
} from "@energyweb/credential-governance";

(async () => {
  const domainTransactionFactory = new DomainTransactionFactoryV2({
    domainResolverAddress: VOLTA_RESOLVER_V2_ADDRESS,
  });

  const domain = 'sampleDomain';
  const role: IRoleDefinitionV2 = {
    requestorFields: [
      {
        fieldType: 'fieldType',
        label: 'label',
        required: true,
        minLength: 5,
        minDate: new Date(),
        maxDate: new Date(),
      },
    ],
    issuer: {
      issuerType: 'DID',
      did: [`did:ethr:volta:0x7aA65E31d404A8857BA083f6195757a730b51CFe`],
    },
    revoker: {
      revokerType: 'DID',
      did: [`did:ethr:volta:0x7aA65E31d404A8857BA083f6195757a730b51CFe`],
    },
    metadata: [],
    roleName: 'myRole1',
    roleType: 'sample',
    version: 1,
    enrolmentPreconditions: [],
  };

  const call = domainDefTxFactoryV2.newRole({
    domain: domain,
    roleDefinition: role,
  });
  await (await owner.sendTransaction(call)).wait();
})();

Contract Descriptions

RoleDefinitionResolverV2.sol

This is an implementation of an ENS resolver that represents a role definition. It extends the ENS Public Resolver with additional resolver profiles, specifically for the use case of issuance, revocation and verify role claims using a smart contract. In other words, this custom ENS resolver allows some properties of a role definition to be (usefully) readable by another smart contract.

DomainNotifier.sol

This EVM contracts notifies the updation of ENS namespaces resolved data.

Installation

This is a Node.js module available through the npm registry.

Requirements

Before installing, download and install Node.js. Node.js 16.10.0 or higher is required.

Installation is done using the following commands:

$ npm install

Build

$ npm run build

Run

$ npm run start

Testing

Unit Tests

$ npm run test-rpc

/@energyweb/credential-governance/

    Package Sidebar

    Install

    npm i @energyweb/credential-governance

    Weekly Downloads

    66

    Version

    2.2.0

    License

    GPL-3.0-or-later

    Unpacked Size

    11 MB

    Total Files

    73

    Last publish

    Collaborators

    • kyleiankian
    • energywebdev
    • aznagy
    • bagaric
    • pkosin
    • drgorb
    • kroy
    • manihagh