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/civic-sign

v0.7.2

Published

An abstraction around proof of ownership using DIDs

Downloads

1,023

Readme

CivicSign

The intention of this library is to provide an abstraction layer for retrieving a user’s DID and publicKey, as well as requesting proof by signing a message or transaction and finally verifying the proof is valid.

The following diagram can be used as reference in order to illustrate how the library will be used between the different Civic systems.

Getting Started with Solana

import { CivicSignProveFactory } from '@civic/civic-sign';
import { Keypair, Transaction } from '@solana/web3.js';

const keys = Keypair.generate();

const wallet: SolanaWalletAdapter = {
    publicKey: keys.publicKey,
    signTransaction: (transaction: Transaction) => {
        transaction.sign(keys);
        return Promise.resolve(transaction);
    },
};

const { requestDid, requestProof, verify } = CivicSignProveFactory.createWithSolanaWallet(wallet);
const { did } = requestDid();
const signedProof = requestProof();
const verifiedProofResult = verifyProof(signedProof, did);

console.log(did, signedProof, verifiedProofResult);

Getting Started with Ethereum

import { CivicSignProveFactory } from '@civic/civic-sign';
import { Wallet } from 'ethers';

const wallet = Wallet.createRandom();
const walletAdapter = {
    ...wallet,
    signTypedData: (domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: EthPowoMessage) => {
        return wallet._signTypedData(domain, types, value);
    },
    verifierAddress: 'verifierAddress',
};

const { requestDid, requestProof, verify } = CivicSignProveFactory.createWithEthereumWallet(walletAdapter);
const { did } = requestDid();
const signedProof = requestProof();
const verifiedProofResult = verifyProof(signedProof);

console.log(did, signedProof, verifiedProofResult);

Getting Started with ICP

import { CivicSignProveFactory } from '@civic/civic-sign';

const wallet = {
      principal:
        "example-principal",
    };

const { requestDid, requestProof, verify } = CivicSignProveFactory.createWithICPWallet(wallet);

const { did } = requestDid();
const signedProof = requestProof();
const verifiedProofResult = verifyProof(signedProof);

console.log(did, signedProof, verifiedProofResult);

Public Api

CivicSign has the following public Api methods available. Please refer to the docs for additional information available in the project.

Instantiating an instance with CivicSignProveFactory

| Method | Description | Returns | ------------- | ------------------------------------------------------------ | ----------------------------------------- | createWithSolanaWallet | create an instance of CivicSign with an instance of a SolanaWalletAdapter | CivicSignProve | | createWithEthereumWallet | create an instance of CivicSign with an instance of a EthereumGatewayWallet | CivicSignProve | | createWithSolanaInIframe | create an instance of CivicSign for communicating with a remote instance of a Solana Wallet | CivicSignProve | | createWithEthereumInIframe | create an instance of CivicSign for communicating with a remote instance of an Ethereum Wallet | CivicSignProve |

Public Methods availabe from CivicSignProve

| Method | Description | Returns | ------------- | ------------------------------------------------------------ | ----------------------------------------- | requestDid | requests a DID from a wallet instance or remotely | Promise | | requestProof | requests a proof to be signed either through a wallet instance or remotely | Promise | | signMessage | requests the user to sign a message | Promise |

Verifying a proof

| Method | Description | Returns | ------------- | ------------------------------------------------------------ | ----------------------------------------- | verify | verify a proof that was returned from requestProof is valid | Promise

Checking wallet DID ownership

To check whether a given wallet owns a given DID:

import { walletOwnsDID } from '@civic/civic-sign';

const walletAddress = '016752701213E0D5Ee093A355c4d8e16b15525177e3C97DB5F9E2AC7C69F5Bfd52';
const did = 'did:key:z6MkmQaws5ASXmntxzybdK4piNKTFQh17cJK3JEURfhbMX2Z';
const doesWalletOwnDid = await walletOwnsDID(walletAddress, did);

This will:

  • resolve the DID
  • Get all authorized keys on the DID document (i.e. VerificationMethods that appear in the capabilityInvocations or authentication lists )
  • For each of those keys, check if they match the given wallet address by asking chain-specific conversion code for each of the supported chains.
  • If there are any matches, return true.

Building the library

Contributing

The following commands are availabe when contriburing to the project.

yarn lint

Checks that the project lints successfully. This automatically gets run before building the project.

yarn test

Checks that all unit and integration tests pass. This automatically gets run before building the project.

yarn generateDocs

Generate docs based on the available types in the project.

yarn publish

Published a new version of the CivicSign library to NPM. Running the command will build the dist folder before continuing to publish.