Giter Club home page Giter Club logo

lds-ecdsa-secp256k1-2019.js's Introduction

EcdsaSecp256k1Signature2019

This library is no longer maintained, please use JsonWebSignature2020 instead.

Build Status codecov

๐Ÿšง This library is experimental / under development / not audited. Use at your own risk.

This project relies on:

Usage

Install

npm i @transmute/lds-ecdsa-secp256k1-2019 --save

Issue and Verify with vc-js

const {
  EcdsaSecp256k1KeyClass2019,
  EcdsaSecp256k1Signature2019,
  defaultDocumentLoader,
} = require('@transmute/lds-ecdsa-secp256k1-2019');

const vc = require('vc-js');

const key = new EcdsaSecp256k1KeyClass2019({
  id:
    'did:elem:EiChaglAoJaBq7bGWp6bA5PAQKaOTzVHVXIlJqyQbljfmg#qfknmVDhMi3Uc190IHBRfBRqMgbEEBRzWOj1E9EmzwM',
  controller: 'did:elem:EiChaglAoJaBq7bGWp6bA5PAQKaOTzVHVXIlJqyQbljfmg',
  privateKeyJwk: {
    kty: 'EC',
    crv: 'secp256k1',
    d: 'wNZx20zCHoOehqaBOFsdLELabfv8sX0612PnuAiyc-g',
    x: 'NbASvplLIO_XTzP9R69a3MuqOO0DQw2LGnhJjirpd4w',
    y: 'EiZOvo9JWPz1yGlNNW66IV8uA44EQP_Yv_E7OZl1NG0',
    kid: 'qfknmVDhMi3Uc190IHBRfBRqMgbEEBRzWOj1E9EmzwM',
  },
});

const suite = new EcdsaSecp256k1Signature2019({
  key,
});

// Sample unsigned credential
const credential = {
  '@context': [
    'https://www.w3.org/2018/credentials/v1',
    'https://www.w3.org/2018/credentials/examples/v1',
  ],
  id: 'https://example.com/credentials/1872',
  type: ['VerifiableCredential', 'AlumniCredential'],
  issuer: key.controller,
  issuanceDate: '2010-01-01T19:23:24Z',
  credentialSubject: {
    id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
    alumniOf: 'Example University',
  },
};

const signedVC = await vc.issue({ credential, suite });
const result = await vc.verify({
  credential: signedVC,
  suite,
  documentLoader: defaultDocumentLoader,
});
```

### Sign

```ts
const jsigs = require('jsonld-signatures');

const { AssertionProofPurpose } = jsigs.purposes;

const {
  EcdsaSecp256k1KeyClass2019,
  EcdsaSecp256k1Signature2019,
  defaultDocumentLoader,
} = require('@transmute/lds-ecdsa-secp256k1-2019');

const key = new EcdsaSecp256k1KeyClass2019({
  id:
    'did:elem:EiChaglAoJaBq7bGWp6bA5PAQKaOTzVHVXIlJqyQbljfmg#qfknmVDhMi3Uc190IHBRfBRqMgbEEBRzWOj1E9EmzwM',
  controller: 'did:elem:EiChaglAoJaBq7bGWp6bA5PAQKaOTzVHVXIlJqyQbljfmg',
  privateKeyJwk: {
    kty: 'EC',
    crv: 'secp256k1',
    d: 'wNZx20zCHoOehqaBOFsdLELabfv8sX0612PnuAiyc-g',
    x: 'NbASvplLIO_XTzP9R69a3MuqOO0DQw2LGnhJjirpd4w',
    y: 'EiZOvo9JWPz1yGlNNW66IV8uA44EQP_Yv_E7OZl1NG0',
    kid: 'qfknmVDhMi3Uc190IHBRfBRqMgbEEBRzWOj1E9EmzwM',
  },
});
const signed = await jsigs.sign(
  {
    '@context': [
      {
        schema: 'http://schema.org/',
        name: 'schema:name',
        homepage: 'schema:url',
        image: 'schema:image',
      },
    ],
    name: 'Manu Sporny',
    homepage: 'https://manu.sporny.org/',
    image: 'https://manu.sporny.org/images/manu.png',
  },
  {
    compactProof: false,
    documentLoader: defaultDocumentLoader,
    purpose: new AssertionProofPurpose(),
    suite: new EcdsaSecp256k1Signature2019({
      key,
    }),
  }
);
// see verify for example.

Verify

const res = await jsigs.verify(signed, {
  suite: new EcdsaSecp256k1Signature2019({
    key,
  }),

  compactProof: false,
  documentLoader: defaultDocumentLoader,
  purpose: new AssertionProofPurpose(),
});
// Leave for development purposes
if (!res.verified) {
  // tslint:disable-next-line:no-console
  console.log(res);
}
expect(res.verified).toBe(true);

Motivation

ES256K is currently a DRAFT, however, it has been implemented and is being used by companies. Node 12 supports ES256K out of the box, but browser support requires custom implementations. This library attempts to provide a Node/Web implementation of ES256K as well as a JSON-LD Signature Suite, EcdsaSecp256k1Signature2019, built on detached ES256K JWS according to rfc7797.

Our approach is based on lds-ed25519-2018 and jsonld-signatures.

Development

This monorepo uses lerna, most of the scripts in the root directory just call lerna.

npm i
npm run build
npm run test
npm run coverage
npm run docs

Releases

npm run release

lds-ecdsa-secp256k1-2019.js's People

Contributors

dependabot[bot] avatar jacehensley avatar or13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lds-ecdsa-secp256k1-2019.js's Issues

Add to jsonld-signatures

I think they are going to restructure it to be lighter more plugin oriented, it would be awesome to have multiple implementations of the signature suite that are interoperable. Or at least be able to use this suite in any software that uses jsonld-signatures.

digitalbazaar/jsonld-signatures#74

jsonld lib is slow

When running npm t -- src/__tests__/lds-ecdsa-secp256k1-2019.spec.js on my machine, I see that every .compact() or canonize() call takes between 1 and 2 seconds to finish, even with tiny payloads.

Worth investigating

Agree on signature encoding

We need to decide if the signatureValue is valid jws.

IMO it should be, but questions surrounding support for secp256k1 in jose, remain.

Examples, Command-Line Details, Webapp, and/or Shell Script Harness?

For those of use who are not Javascript devs, but wish to either leverage this library to create working example valid documents, for testing for conformance, or to test our own non-Javascript implementations, I would really like to see:

a) An examples folder, with keys, input and the resulting output, in sufficient detail that node and javascript are not required to test against.

b) Either details in the documentation of how to generate the examples in a completely from the command-line, or shell scripts to do the same.

c) A webapp doing the signing locally that can test with given WIF and HEX private keys.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.