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

@selfkey/agent

v0.0.4

Published

Node js lib for selfkey ssi agent

Downloads

50

Readme

Selfkey Agent

A Selfkey SSI agent library. Utilizes heavily the veramo framework and did-jwt-vc library

For storage typeorm is used.

Usage

yarn add @selfkey/agent

Agent example:

const Entities = require('@selfkey/agent/lib/entities').default;
const SelfkeyAgent = require('@selfkey/agent').default;
const {createConnection} = require('typeorm');


async function main(){
    const infuraId = 'INSERT PROJECT ID';

    const dbConnection = createConnection({
        type: 'sqlite',
        database: 'db.sqlite',
        synchronize: true,
        logging: ['error', 'info', 'warn'],
        entities: Entities
    });

    const kmsKey = await SelfkeyAgent.generateKMSKey();

    const agent = new SelfkeyAgent({
            dbConnection,
            infuraId,
            kmsKey,
            agentName: 'example.com,
            didProvider: 'did:web'
        });

    const did = await agent.ensureAgentDID();
    // 'did:web:example.com

    const didDoc = await agent.generateDIDDoc(did);
    /*
    {
      "@context": "https://w3id.org/did/v1",
      "id": "did:web:example.com",
      "publicKey": [
        {
          "id": "did:web:example.com#0409e2da3624c81b9116c9da841b786cef96b7f4af09107d11c16b39fc5607bbf12be877b6fa7e8c570b3fa736e2d98958981403acba77130ce401ef9056bad5ca",
          "type": "Secp256k1VerificationKey2018",
          "controller": "did:web:example.com",
          "publicKeyHex": "0409e2da3624c81b9116c9da841b786cef96b7f4af09107d11c16b39fc5607bbf12be877b6fa7e8c570b3fa736e2d98958981403acba77130ce401ef9056bad5ca"
        }
      ],
      "authentication": [
        {
          "id": "did:web:example.com#0409e2da3624c81b9116c9da841b786cef96b7f4af09107d11c16b39fc5607bbf12be877b6fa7e8c570b3fa736e2d98958981403acba77130ce401ef9056bad5ca",
          "type": "Secp256k1SignatureAuthentication2018",
          "publicKey": "did:web:example.com#0409e2da3624c81b9116c9da841b786cef96b7f4af09107d11c16b39fc5607bbf12be877b6fa7e8c570b3fa736e2d98958981403acba77130ce401ef9056bad5ca",
          "controller": "did:web:example.com"
        }
      ],
      "service": []
    }
    */

   const credentialSubject = {
       firstName: 'First',
       lastName: 'Last',
       nationality: 'Armenia',
       id: 'did:ethr:0xsdasda2dsadasdas...'
   };

   const credential = await agent.issueCredential({credentialSubject});

   const verifiedCredential = await agent.verifyCredential(credential);

   const presentation = await agent.issuePresentation([credential], 'did:web:verifier.com');

   // agent with did 'did:web:verifier.com'

   await agent.verifyPresentation(presentation);

}

Binary

When installing the library, a script executable will be installed as well into node_modules/.bin

You can generate a Secret Box private key with it

sagent-gen-pk

API

interface ISelfkeyAgentOptions {
    dbConnection: Promise<Connection>;
    infuraId?: string;
    kmsKey?: string;
    kmsName?: string;
    agentName?: string;
    didProvider: 'did:web' | 'did:ethr' | 'did:ethr:ropsten';
}
interface IUnsignedCredential {
    '@context'?: string[];
    id?: string;
    type?: string[];
    issuer?: { id: string; [x: string]: any };
    issuanceDate?: string;
    expirationDate?: string;
    credentialSubject: {
        id?: string;
        [x: string]: any;
    };
    credentialStatus?: {
        id: string;
        type: string;
    };
    [x: string]: any;
}
constructor(private options: ISelfkeyAgentOptions)
static async generateKMSKey(): string

Generates a private key that can be used as an input for KMS Secret Box

Used in the sagent-gen-pk bin script.

async importIdentifier(identifier: IIdentifier)

Pass trough function for veramo import method

https://github.com/uport-project/veramo/blob/358208519d019d7d90cbefb98911979376c7c056/packages/data-store/src/identifier/did-store.ts#L67

Allows to import an existing identifier to the agent.

If you are importing main agent identifier, please specify the alias options the same as agentName as provided in constructor.

If no agent name was provided, specify the default selfkey-agent

async ensureAgentDID(options?: object)

Returns agent did. If no existing did found, creates a new one.

Please make sure to use importIdentifier before calling this function if you want to use an existing key for your agent.

sync getAgentDIDDocument(options?: object): Promise<DIDDocument | null>

Generates a DID document for the agent

async resolveDIDDoc(didUrl: string): Promise<DIDDocument | null>

Uses DID resolver to resolve a DID doc

async generateDIDDoc(did: string): Promise<DIDDocument | null>

Generates a DID doc for a did that is stored in the local store. Useful for generating DID Documents for non resolvable DID's

async issueCredential(
        credential: IUnsignedCredential,
        options: {
            save?: boolean;
            proofFormat?: string;
        } = { save: false, proofFormat: 'JWT' }
    ): Promise<VerifiableCredential>

Issues a new JWT Verifiable credential

async issuePresentation(
        credentials: VerifiableCredential[],
        verifierDID: string,
        holderDid?: string,
        options?: { save: boolean }
    ): Promise<VerifiablePresentation>

Issues a new JWT verifiable presentation

async verifyCredential(
        vc: string | VerifiableCredential,
        options?: object
    ): Promise<VerifiedCredential>

Verifies a JWT verifiable credential. A VC object or a JWT string can be provided

async verifyPresentation(
        vp: string | VerifiablePresentation,
        options?: object
    ): Promise<VerifiedPresentation>

Verifies a JWT verifiable presentation. A VP object or a JWT string can be provided

async listCredentials(): Promise<UniqueVerifiableCredential[]>

List all credentials stored in local store

async listCredentialsForSubjectId(id: string): Promise<UniqueVerifiableCredential[]>

Lists credentials from local store filtered by subject id

async listCredentialsForIssuerId(id: string | string[]): Promise<UniqueVerifiableCredential[]>

Lists credentials from local store filtered by issuer id

Tests

From monorepo root directory run jest agent

NOTE: verify presentation / credential tests might fail sporadically because they rely on network requests to resolve DID. They should be mocked instead.

Deploy

Navigate to packages/agent

Run yarn version to update the package version

Run git push --tags to push the new version and tag to the github repo

Then run yarn publish to publish the new version to npm

TODO: Deploy process should happen automatically from CI. Also, versioning and deploy should be managed by lerna on the root of the monorepo.