0.7.2 • Published 10 months ago

@civic/civic-sign v0.7.2

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

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

MethodDescriptionReturns
createWithSolanaWalletcreate an instance of CivicSign with an instance of a SolanaWalletAdapterCivicSignProve
createWithEthereumWalletcreate an instance of CivicSign with an instance of a EthereumGatewayWalletCivicSignProve
createWithSolanaInIframecreate an instance of CivicSign for communicating with a remote instance of a Solana WalletCivicSignProve
createWithEthereumInIframecreate an instance of CivicSign for communicating with a remote instance of an Ethereum WalletCivicSignProve

Public Methods availabe from CivicSignProve

MethodDescriptionReturns
requestDidrequests a DID from a wallet instance or remotelyPromise
requestProofrequests a proof to be signed either through a wallet instance or remotelyPromise
signMessagerequests the user to sign a messagePromise

Verifying a proof

MethodDescriptionReturns
verifyverify a proof that was returned from requestProof is validPromise

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.

0.7.2-beta.0

10 months ago

0.7.2

10 months ago

0.7.1

10 months ago

0.7.1-beta.0

11 months ago

0.7.1-beta.1

11 months ago

0.6.4-alpha.0

12 months ago

0.6.0-beta.8

1 year ago

0.6.0-beta.7

1 year ago

0.6.0-beta.9

1 year ago

0.6.0-beta.4

1 year ago

0.6.0-beta.3

1 year ago

0.6.0-beta.6

1 year ago

0.6.0-beta.5

1 year ago

0.6.0-beta.0

1 year ago

0.6.0-beta.2

1 year ago

0.6.0-beta.1

1 year ago

0.7.0

11 months ago

0.6.0-beta.17

1 year ago

0.6.0-beta.16

1 year ago

0.6.0-beta.19

1 year ago

0.6.0-beta.18

1 year ago

0.6.0-beta.13

1 year ago

0.6.0-beta.12

1 year ago

0.6.0-beta.15

1 year ago

0.6.0-beta.14

1 year ago

0.6.0-beta.11

1 year ago

0.6.0-beta.10

1 year ago

0.6.3-alpha.0

12 months ago

0.6.0-beta.24

1 year ago

0.6.0-beta.23

1 year ago

0.6.0-beta.26

1 year ago

0.6.0-beta.25

1 year ago

0.6.0-beta.20

1 year ago

0.6.0-beta.22

1 year ago

0.6.0-beta.21

1 year ago

0.7.0-alpha.1

11 months ago

0.7.0-alpha.0

11 months ago

0.7.0-alpha.3

11 months ago

0.7.0-alpha.2

11 months ago

0.7.0-alpha.5

11 months ago

0.6.2-alpha.0

12 months ago

0.7.0-alpha.4

11 months ago

0.5.1

1 year ago

0.6.3

12 months ago

0.6.2

12 months ago

0.6.4

12 months ago

0.6.1

12 months ago

0.6.0

1 year ago

0.5.0

2 years ago

0.5.0-beta.5

2 years ago

0.3.0-beta.2

2 years ago

0.3.0-beta.3

2 years ago

0.3.0

2 years ago

0.3.0-beta.0

2 years ago

0.3.0-beta.1

2 years ago

0.4.0-beta.1

2 years ago

0.5.0-beta.1

2 years ago

0.5.0-beta.0

2 years ago

0.5.0-beta.4

2 years ago

0.5.0-beta.2

2 years ago

0.4.0

2 years ago

0.1.4-beta.2

2 years ago

0.2.1-beta.0

2 years ago

0.2.0-beta.6

2 years ago

0.2.0-beta.5

2 years ago

0.2.0-beta.4

2 years ago

0.2.0-beta.9

2 years ago

0.2.0-beta.8

2 years ago

0.2.0

2 years ago

0.2.0-beta.7

2 years ago

0.2.0-beta.10

2 years ago

0.1.4-beta.0

2 years ago

0.1.4-beta.1

2 years ago

0.2.0-beta.2

2 years ago

0.2.0-beta.1

2 years ago

0.2.0-beta.3

2 years ago

0.1.1-beta.2

2 years ago

0.1.3-beta.1

2 years ago

0.1.1-beta.1

2 years ago

0.1.1-beta.0

2 years ago

0.1.1-beta.4

2 years ago

0.1.1-beta.3

2 years ago

0.1.3-beta.0

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.23-beta.2

2 years ago

0.0.23-beta.3

2 years ago

0.1.3

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.20-beta.0

2 years ago

0.0.23-beta.1

2 years ago

0.0.19-beta.0

2 years ago

0.0.19-beta.1

2 years ago

0.0.19-beta.2

2 years ago

0.0.19

2 years ago

0.0.18-beta.0

3 years ago

0.0.16-alpha.0

3 years ago

0.0.17

3 years ago

0.0.15

3 years ago

0.0.15-beta.1

3 years ago

0.0.15-beta.0

3 years ago

0.0.14

3 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago