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

@krebitdao/reputation-passport

v1.0.9

Published

Krebit SDK for Verified Credentials

Downloads

32

Readme

reputation-passport

Krebit Reputation Passport SDK

Docs

This repository hosts the Krebit Reputation Passport sdk, based on W3C Ethereum EIP712 Signature 2021 Draft.

It provides functions for creating off-chain Verifiable-Credentials in Ceramic that can be verified on-chain with krebit-contracts.

Overview

Installation

$ npm install -s @krebitdao/reputation-passport

Read-Only Passport

import krebit from '@krebitdao/reputation-passport';

const passport = new krebit.core.Passport({
  ceramicUrl: 'https://ceramic-clay.3boxlabs.com'
});
passport.read(address);

const profile = await passport.getProfile();
console.log('profile: ', profile);

const credentials = await passport.getCredentials();
console.log('credentials: ', credentials);

const reputation = await passport.getReputation();
console.log('reputation: ', reputation);

const stamps = await passport.getStamps(10, 'DigitalProperty');
console.log('stamps: ', stamps);

Initialize Ethereum Provider

import krebit from '@krebitdao/reputation-passport';

// Example on Browser:
const connectWeb3 = async () => {
  if (!window) return;
  const ethereum = (window as any).ethereum;

  if (!ethereum) return;

  const addresses = await ethereum.request({
    method: 'eth_requestAccounts'
  });
  const address = addresses[0];
  const ethProvider = await Krebit.lib.ethereum.getWeb3Provider();
  const wallet = ethProvider.getSigner();
  return { address, wallet, ethProvider };
};

// NODE JS Example:
export const connect = async () => {
  try {
    const ethProvider = Krebit.lib.ethereum.getProvider();

    let wallet: ethers.Wallet;

    try {
      // Create wallet from ethereum seed
      const unlockedWallet = ethers.Wallet.fromMnemonic(SERVER_ETHEREUM_SEED);
      // Connect wallet with provider for signing the transaction
      wallet = unlockedWallet.connect(ethProvider);
    } catch (error) {
      console.error('Failed to use local Wallet: ', error);
    }
    if (wallet && wallet.address) {
      console.log('address: ', wallet.address);
      ethProvider.setWallet(wallet);
      return { wallet, ethProvider };
    }
    return undefined;
  } catch (error) {
    throw new Error(error);
  }
};

Initialize Issuer

import krebit from '@krebitdao/reputation-passport';
const { wallet, ethProvider } = await connect();

const Issuer = new krebit.core.Krebit({
  wallet,
  ethProvider,
  network: 'mumbai',
  address: wallet.address,
  ceramicUrl: 'https://ceramic-clay.3boxlabs.com'
});
const did = await Issuer.connect();

Issue Credential

const getClaim = async (toAddress: string) => {
  const badgeValue = {
    communityId: 'My Community',
    name: 'Community Badge Name',
    imageUrl: 'ipfs://asdf',
    description: 'Badge for users that meet some criteria',
    skills: [{ skillId: 'participation', score: 100 }],
    xp: '1'
  };

  const expirationDate = new Date();
  const expiresYears = 3;
  expirationDate.setFullYear(expirationDate.getFullYear() + expiresYears);
  console.log('expirationDate: ', expirationDate);

  const claim = {
    id: `quest-123`,
    ethereumAddress: toAddress,
    did: `did:pkh:eip155:1:${toAddress}`
    type: 'questBadge',
    value: badgeValue,
    tags: ['quest', 'badge', 'Community'],
    typeSchema: 'https://github.com/KrebitDAO/schemas/questBadge',
    expirationDate: new Date(expirationDate).toISOString()
  };
};

const claim = await getClaim(toAddress);
const issuedCredential = await Issuer.issue(claim);

Verify Credential

console.log(
  'Verifying credential:',
  await Issuer.checkCredential(issuedCredential)
);

Add Credential to My Passport

import krebit from '@krebitdao/reputation-passport';
const { wallet, ethProvider } = await connectWeb3();

const passport = new krebit.core.Passport({
  ethProvider: ethProvider.provider,
  address,
  ceramicUrl: 'https://ceramic-clay.3boxlabs.com'
});
await passport.connect();

const addedCredentialId = await passport.addCredential(issuedCredential);
console.log('addedCredentialId: ', addedCredentialId);

Issue Ecrypted Credential

With Lit protocol:

import krebit from '@krebitdao/reputation-passport';
import LitJsSdk from "@lit-protocol/sdk-browser"; // Added Lit

const { wallet, ethProvider } = await connectWeb3();

const Issuer = new krebit.core.Krebit({
        wallet,
        ethProvider: ethProvider.provider,
        address,
        ceramicUrl: 'https://ceramic-clay.3boxlabs.com',
        litSdk: LitJsSdk // Added Lit
      });

const getEncryptedClaim = async (toAddress: string) => {
  const privateValue = {
    secretValue: 'My Secret',
  };

  const expirationDate = new Date();
  const expiresYears = 3;
  expirationDate.setFullYear(expirationDate.getFullYear() + expiresYears);
  console.log('expirationDate: ', expirationDate);

  const claim = {
    id: `custom-123`,
    ethereumAddress: toAddress,
    type: 'custom',
    value: privateValue,
    tags: ['tag1', 'tag2'],
    typeSchema: '<type url>',
    expirationDate: new Date(expirationDate).toISOString()
    encrypt: 'lit' as 'lit' // Added Lit
  };
};

const claim = await getEncryptedClaim(toAddress);
const issuedCredential = await Issuer.issue(claim);

Decrypt Credential

const decrypted = await Issuer.decryptClaim(issuedCredential);
console.log('Decrypted:', decrypted);

Learn More

The guides in the docs site will teach about different concepts of the Krebit Protocol.

Contribute

Krebit Protocol exists thanks to its contributors. There are many ways you can participate and help build public goods. Check out the Krebit Gitcoin Grants!

License

Krebit Reputation Passport is released under the ISC License.