npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@civic/gateway-protocol-eth

v0.0.5

Published

Civic Gateway Tokens ethereum smart contracts

Downloads

6

Readme

Civic Gateway Tokens on Ethereum blockchain

This repository contains set of Ethereum smart contracts for Civic On-chain Identity Gateway token system.

Gateway tokens allows Ethereum DeFi projects to validate that their users successfully completed KYC, with regulations and guidances from FATF, US OFAC, US OCC BSA and others.

Quick Start

  1. Use established node version by running nvm use
  2. Install repository dependencies by running yarn install
  3. Run yarn build to compile smart contracts
  4. Execute yarn test to run the tests.

Static analysis

Additionally, you can perform static analysis for well-known code issues and vulnerabilities using Slither.

pip3 install slither-analyzer
yarn analyze

Environment variables

Please refer to .env.example and create .env to provide secret info such as private keys, Infura ID. Private keys are used in order to deploy smart contracts on one of the Ethereum networks.

Compile

To compile smart contracts, type hardhat compile. Use --force option to recompile everything if needed.

The compiled output is a json file called Artifacts and saved in ./build/contracts directory per contract basis. ABI and bytecode associated with the smart contract will be saved in the json file.

Deployment

In order to deploy the protocol please execute yarn deploy <NETWORK> command and replace with the network you want to deploy the protocol.

For example yarn deploy hardhat will deploy the protocol on the local hardhat version of the ethereum blockchain.

After the successful deployment you'll be able to find the deployment result in the deployments folder.

Integration

To integrate Gateway in your smart contract:

First, import the contract dependencies:

npm install @civic/gateway-protocol-eth

Then, in your smart contract, inherit the Gated contract, and add the gated modifier to any function.

The function can only be called by a msg.sender that has a valid gateway token.

import '@civic/gateway-protocol-eth/contracts/Gated.sol';

// Your contract
contract MyContract is Gated {
  constructor(address gatewayTokenContract, uint256 gatekeeperNetwork) Gated(gatewayTokenContract, gatekeeperNetwork) {}

  function myFunction() external gated {}
}

If you want more control over the verification process on-chain, you can use the following code instead of the Gated contract:

import "@civic/gateway-protocol-eth/contracts/interfaces/IGatewayTokenVerifier.sol";

...
IGatewayTokenVerifier verifier = IGatewayTokenVerifier(gatewayTokenContract);
if (!verifier.verifyToken(addressToVerify, gatekeeperNetwork)) {
// some logic
}

Creating a Gatekeeper Network

This section describes how to create a Gatekeeper Network (GKN) and add Gatekeepers to it. It uses ethers to interact with the smart contracts.

// check slot ID availability
const slotId = ...; // select a slot ID
const network = await gatewayToken.getNetwork(slotId);

// create a gatekeeper network, owned by the wallet (the wallet is the network authority)
await gatewayToken.connect(wallet).createNetwork(slotId, 'My Gatekeeper Network', false, ZERO_ADDRESS);

// create a gatekeeper network, owned by a DAO
await gatewayToken.connect(wallet).createNetwork(slotId, 'My Gatekeeper Network', true, DAO_ADDRESS);

Adding a Gatekeeper to the GKN

// add a gatekeeper to the network
await gatewayToken.connect(wallet).addGatekeeper(gatekeeperAddress, slotId);

Setting a network feature

Only one network feature is available:

  • removeGatekeeperInvalidatesTokensFeature - if set, removing a gatekeeper from the network will invalidate all gateway tokens issued by the network.
const removeGatekeeperInvalidatesTokensFeature = 0;
const mask = 1 << removeGatekeeperInvalidatesTokensFeature;

// will be false
await gatewayToken.networkHasFeature(slotId, removeGatekeeperInvalidatesTokensFeature);

await gatewayToken.connect(identityCom).setNetworkFeatures(slotId, mask);

// will be true
await gatewayToken.networkHasFeature(slotId, removeGatekeeperInvalidatesTokensFeature);