New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

key-utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-utils

A WebCrypto key utility which can convert keys between ECDH & ECDSA right now - more functions to be discovered and added

  • 0.5.4
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

key-utils

A WebCrypto key utility which can convert keys between ECDH & ECDSA right now - more functions to be discovered and added

Motivation

In many situations (esp. blockchain related ones), we need to maintain ONE keypair for both key agreement (ECDH) / secured data exchanging (ECIES) and certification (ECDSA) purposes, which is also practical theoretically, but the encapsulation of WebCrypto makes it very hard to realize. This is some kind of polyfill to enable the very niche usage.

CAUTION

Some people argue that this usage will compromise the security, so please DO ensure that your usage is unavoidable or secured enough before use this utility.

Usage

Add the reference in HTML file

...
<script src="/your/path/to/key-utils.js"></script>
...

Now you can use this utility in your JavaScript code

let xkp = await crypto.subtle.generateKey({
		name: 'ECDH',
		namedCurve: 'P-256'
	},
	true,
	['deriveBits', 'deriveKey']
);
// By definition, you can use xkp for key agreement/data exchange

// Below code shows that how the same EC keys can be used for sign/verify with the help of this utility
let dkp = await keyUtils.ecdhToEcdsa(xkp);
let message = new TextEncoder('utf-8').encode('The message you want to sign');
let sig = await crypto.subtle.sign({
		name: 'ECDSA',
		hash: {name: 'SHA-256'}
	}, dkp.privateKey, message
);

let result = await crypto.subtle.verify({
		name: 'ECDSA',
		hash: {name: 'SHA-256'}
	}, dkp.publicKey, sig, message
);
console.log(result);

Dependencies

Browser with ES5 support

License

Written in 2018 by tibetty xihua.duan@gmail.com

Keywords

FAQs

Package last updated on 18 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc