Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
A Javascript library for generating and performing common operations on Linked Data cryptographic key pairs.
A Javascript library for generating and performing common operations on Linked Data cryptographic key pairs.
See also (related specs):
crypto-ld
versions 4+
)This library provides general Linked Data cryptographic key generation functionality, but does not support any individual key type by default.
To use it, you must install individual driver libraries for each cryptographic key type. The following libraries are currently supported.
Type | Crypto Suite | Library | Usage |
---|---|---|---|
Ed25519 | Ed25519VerificationKey2020 (recommended), Ed25519VerificationKey2018 (legacy) | ed25519-verification-key-2020 >=1.0 (recommended), ed25519-verification-key-2018 >=2.0 (legacy) | Signatures, VCs, zCaps, DIDAuth |
X25519/Curve25519 | X25519KeyAgreementKey2019 | x25519-key-agreement-key-2019 >=4.0 | ECDH key agreement, JWE/CWE encryption with minimal-cipher |
Secp256k1 | EcdsaSecp256k1VerificationKey2019 | ecdsa-secp256k1-verification-key-2019 | Signatures, VCs, zCaps, DIDAuth, HD Wallets |
crypto-ld
versions <=3
)In the previous version (v3.x) of crypto-ld
, the RSA and Ed25519 suites were
bundled with crypto-ld
(as opposed to residing in standalone packages).
For previous usage instructions of bundled RSA, Ed25519 and standalone
Curve25519/x25519-key-pair
type keys, see the README for crypto-ld
v3.9.
For digital signatures using the
jsonld-signatures
,
signing of Verifiable Credentials using vc-js
,
authorization capabilities, and DIDAuth operations:
For key agreement protocols for encryption operations:
minimal-cipher
library.As with most security- and cryptography-related tools, the overall security of your system will largely depend on your design decisions.
To install locally (for development):
git clone https://github.com/digitalbazaar/crypto-ld.git
cd crypto-ld
npm install
In order to use this library, you will need to import and install driver
libraries for key types you'll be working with via the use()
method.
To use the library with one or more supported suites:
import {Ed25519VerificationKey2020} from '@digitalbazaar/ed25519-verification-key-2020';
import {X25519KeyAgreementKey2020} from '@digitalbazaar/x25519-key-agreement-key-2020';
import {CryptoLD} from 'crypto-ld';
const cryptoLd = new CryptoLD();
cryptoLd.use(Ed25519VerificationKey2020);
cryptoLd.use(X25519KeyAgreementKey2020);
const edKeyPair = await cryptoLd.generate({type: 'Ed25519VerificationKey2020'});
To generate a new public/private key pair: cryptoLd.generate(options)
:
{string} [type]
Suite name, required.{string} [controller]
Optional controller URI or DID to initialize the
generated key. (This will also init the key id.){string} [seed]
Optional deterministic seed value (only supported by some
key types, such as ed25519
) from which to generate the key.To create an instance of a public/private key pair from data imported from
storage, use cryptoLd.from()
:
const serializedKeyPair = { ... };
const keyPair = await cryptoLd.from(serializedKeyPair);
Note that only installed key types are supported, if you try to create a
key pair via from()
for an unsupported type, an error will be thrown.
The full range of operations will depend on key type. Here are some common operations supported by all key types.
To export just the public key of a pair - use export()
:
keyPair.export({publicKey: true});
// ->
{
type: 'Ed25519VerificationKey2020',
id: 'did:example:1234#z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3',
controller: 'did:example:1234',
publicKeyMultibase: 'zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf'
}
To export the full key pair, including private key (warning: this should be a carefully considered operation, best left to dedicated Key Management Systems):
keyPair.export({publicKey: true, privateKey: true});
// ->
{
type: 'Ed25519VerificationKey2020',
id: 'did:example:1234#z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3',
controller: 'did:example:1234',
publicKeyMultibase: 'zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf',
privateKeyMultibase: 'z4E7Q4neNHwv3pXUNzUjzc6TTYspqn9Aw6vakpRKpbVrCzwKWD4hQDHnxuhfrTaMjnR8BTp9NeUvJiwJoSUM6xHAZ'
}
To generate a fingerprint:
keyPair.fingerprint();
// ->
'z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3'
To verify a fingerprint:
keyPair.verifyFingerprint({
fingerprint: 'z6MkszZtxCmA2Ce4vUV132PCuLQmwnaDD5mw2L23fGNnsiX3'
});
// ->
{ valid: true }
For key pairs that are related to signature and verification (that extend from
the LDVerifierKeyPair
class), two additional operations must be supported:
In order to perform a cryptographic signature, you need to create a sign
function, and then invoke it.
const keyPair = await cryptoLd.generate({type: 'Ed25519VerificationKey2020'});
const {sign} = keyPair.signer();
const data = 'test data to sign';
const signatureValue = await sign({data});
In order to verify a cryptographic signature, you need to create a verify
function, and then invoke it (passing it the data to verify, and the signature).
const keyPair = await cryptoLd.generate({type: 'Ed25519VerificationKey2020'});
const {verify} = keyPair.verifier();
const {valid} = await verify({data, signature});
See the contribute file!
PRs accepted.
If editing the Readme, please conform to the standard-readme specification.
Commercial support for this library is available upon request from Digital Bazaar: support@digitalbazaar.com
New BSD License (3-clause) © Digital Bazaar
FAQs
A Javascript library for generating and performing common operations on Linked Data cryptographic key pairs.
We found that crypto-ld demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.