@libp2p/keychain
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -1,5 +0,4 @@ | ||
import { CMS } from './cms.js'; | ||
import type { PeerId } from '@libp2p/interface-peer-id'; | ||
import type { Datastore } from 'interface-datastore'; | ||
import type { KeyTypes } from '@libp2p/crypto/keys'; | ||
import type { KeyChain, KeyInfo, KeyType } from '@libp2p/interface-keychain'; | ||
export interface DEKConfig { | ||
@@ -15,15 +14,2 @@ hash: string; | ||
} | ||
/** | ||
* Information about a key. | ||
*/ | ||
export interface KeyInfo { | ||
/** | ||
* The universally unique key id | ||
*/ | ||
id: string; | ||
/** | ||
* The local key name. | ||
*/ | ||
name: string; | ||
} | ||
export interface KeyChainComponents { | ||
@@ -40,3 +26,3 @@ datastore: Datastore; | ||
*/ | ||
export declare class KeyChain { | ||
export declare class DefaultKeyChain implements KeyChain { | ||
private readonly components; | ||
@@ -49,11 +35,2 @@ private readonly init; | ||
/** | ||
* Gets an object that can encrypt/decrypt protected data | ||
* using the Cryptographic Message Syntax (CMS). | ||
* | ||
* CMS describes an encapsulation syntax for data protection. It | ||
* is used to digitally sign, digest, authenticate, or encrypt | ||
* arbitrary message content | ||
*/ | ||
get cms(): CMS; | ||
/** | ||
* Generates the options for a keychain. A random salt is produced. | ||
@@ -85,3 +62,3 @@ * | ||
*/ | ||
createKey(name: string, type: KeyTypes, size?: number): Promise<KeyInfo>; | ||
createKey(name: string, type: KeyType, size?: number): Promise<KeyInfo>; | ||
/** | ||
@@ -88,0 +65,0 @@ * List all the keys. |
@@ -6,3 +6,2 @@ /* eslint max-nested-callbacks: ["error", 5] */ | ||
import { Key } from 'interface-datastore/key'; | ||
import { CMS } from './cms.js'; | ||
import errCode from 'err-code'; | ||
@@ -75,3 +74,3 @@ import { codes } from './errors.js'; | ||
*/ | ||
export class KeyChain { | ||
export class DefaultKeyChain { | ||
/** | ||
@@ -102,18 +101,2 @@ * Creates a new instance of a key chain | ||
/** | ||
* Gets an object that can encrypt/decrypt protected data | ||
* using the Cryptographic Message Syntax (CMS). | ||
* | ||
* CMS describes an encapsulation syntax for data protection. It | ||
* is used to digitally sign, digest, authenticate, or encrypt | ||
* arbitrary message content | ||
*/ | ||
get cms() { | ||
const cached = privates.get(this); | ||
if (cached == null) { | ||
throw errCode(new Error('dek missing'), codes.ERR_INVALID_PARAMETERS); | ||
} | ||
const dek = cached.dek; | ||
return new CMS(this, dek); | ||
} | ||
/** | ||
* Generates the options for a keychain. A random salt is produced. | ||
@@ -120,0 +103,0 @@ * |
@@ -1,11 +0,2 @@ | ||
import 'node-forge/lib/x509.js'; | ||
/** | ||
* Gets a self-signed X.509 certificate for the key. | ||
* | ||
* The output Uint8Array contains the PKCS #7 message in DER. | ||
* | ||
* TODO: move to libp2p-crypto package | ||
*/ | ||
export declare const certificateForKey: (key: any, privateKey: forge.pki.rsa.PrivateKey) => any; | ||
/** | ||
* Finds the first item in a collection that is matched in the | ||
@@ -12,0 +3,0 @@ * `asyncCompare` function. |
@@ -1,64 +0,2 @@ | ||
import 'node-forge/lib/x509.js'; | ||
// @ts-expect-error types are missing | ||
import forge from 'node-forge/lib/forge.js'; | ||
const pki = forge.pki; | ||
/** | ||
* Gets a self-signed X.509 certificate for the key. | ||
* | ||
* The output Uint8Array contains the PKCS #7 message in DER. | ||
* | ||
* TODO: move to libp2p-crypto package | ||
*/ | ||
export const certificateForKey = (key, privateKey) => { | ||
const publicKey = pki.rsa.setPublicKey(privateKey.n, privateKey.e); | ||
const cert = pki.createCertificate(); | ||
cert.publicKey = publicKey; | ||
cert.serialNumber = '01'; | ||
cert.validity.notBefore = new Date(); | ||
cert.validity.notAfter = new Date(); | ||
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 10); // eslint-disable-line @typescript-eslint/restrict-plus-operands | ||
const attrs = [{ | ||
name: 'organizationName', | ||
value: 'ipfs' | ||
}, { | ||
shortName: 'OU', | ||
value: 'keystore' | ||
}, { | ||
name: 'commonName', | ||
value: key.id | ||
}]; | ||
cert.setSubject(attrs); | ||
cert.setIssuer(attrs); | ||
cert.setExtensions([{ | ||
name: 'basicConstraints', | ||
cA: true | ||
}, { | ||
name: 'keyUsage', | ||
keyCertSign: true, | ||
digitalSignature: true, | ||
nonRepudiation: true, | ||
keyEncipherment: true, | ||
dataEncipherment: true | ||
}, { | ||
name: 'extKeyUsage', | ||
serverAuth: true, | ||
clientAuth: true, | ||
codeSigning: true, | ||
emailProtection: true, | ||
timeStamping: true | ||
}, { | ||
name: 'nsCertType', | ||
client: true, | ||
server: true, | ||
email: true, | ||
objsign: true, | ||
sslCA: true, | ||
emailCA: true, | ||
objCA: true | ||
}]); | ||
// self-sign certificate | ||
cert.sign(privateKey); | ||
return cert; | ||
}; | ||
/** | ||
* Finds the first item in a collection that is matched in the | ||
@@ -65,0 +3,0 @@ * `asyncCompare` function. |
{ | ||
"name": "@libp2p/keychain", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Key management and cryptographically protected messages", | ||
@@ -148,2 +148,3 @@ "license": "Apache-2.0 OR MIT", | ||
"@libp2p/crypto": "^1.0.11", | ||
"@libp2p/interface-keychain": "^2.0.3", | ||
"@libp2p/interface-peer-id": "^2.0.1", | ||
@@ -155,3 +156,2 @@ "@libp2p/logger": "^2.0.5", | ||
"merge-options": "^3.0.4", | ||
"node-forge": "^1.3.1", | ||
"sanitize-filename": "^1.6.3", | ||
@@ -158,0 +158,0 @@ "uint8arrays": "^4.0.3" |
@@ -7,3 +7,2 @@ /* eslint max-nested-callbacks: ["error", 5] */ | ||
import { Key } from 'interface-datastore/key' | ||
import { CMS } from './cms.js' | ||
import errCode from 'err-code' | ||
@@ -18,3 +17,3 @@ import { codes } from './errors.js' | ||
import { peerIdFromKeys } from '@libp2p/peer-id' | ||
import type { KeyTypes } from '@libp2p/crypto/keys' | ||
import type { KeyChain, KeyInfo, KeyType } from '@libp2p/interface-keychain' | ||
@@ -35,17 +34,2 @@ const log = logger('libp2p:keychain') | ||
/** | ||
* Information about a key. | ||
*/ | ||
export interface KeyInfo { | ||
/** | ||
* The universally unique key id | ||
*/ | ||
id: string | ||
/** | ||
* The local key name. | ||
*/ | ||
name: string | ||
} | ||
const keyPrefix = '/pkcs8/' | ||
@@ -122,3 +106,3 @@ const infoPrefix = '/info/' | ||
*/ | ||
export class KeyChain { | ||
export class DefaultKeyChain implements KeyChain { | ||
private readonly components: KeyChainComponents | ||
@@ -161,22 +145,2 @@ private readonly init: KeyChainInit | ||
/** | ||
* Gets an object that can encrypt/decrypt protected data | ||
* using the Cryptographic Message Syntax (CMS). | ||
* | ||
* CMS describes an encapsulation syntax for data protection. It | ||
* is used to digitally sign, digest, authenticate, or encrypt | ||
* arbitrary message content | ||
*/ | ||
get cms () { | ||
const cached = privates.get(this) | ||
if (cached == null) { | ||
throw errCode(new Error('dek missing'), codes.ERR_INVALID_PARAMETERS) | ||
} | ||
const dek = cached.dek | ||
return new CMS(this, dek) | ||
} | ||
/** | ||
* Generates the options for a keychain. A random salt is produced. | ||
@@ -210,3 +174,3 @@ * | ||
*/ | ||
async createKey (name: string, type: KeyTypes, size = 2048): Promise<KeyInfo> { | ||
async createKey (name: string, type: KeyType, size = 2048): Promise<KeyInfo> { | ||
if (!validateKeyName(name) || name === 'self') { | ||
@@ -213,0 +177,0 @@ await randomDelay() |
@@ -1,68 +0,2 @@ | ||
import 'node-forge/lib/x509.js' | ||
// @ts-expect-error types are missing | ||
import forge from 'node-forge/lib/forge.js' | ||
const pki = forge.pki | ||
/** | ||
* Gets a self-signed X.509 certificate for the key. | ||
* | ||
* The output Uint8Array contains the PKCS #7 message in DER. | ||
* | ||
* TODO: move to libp2p-crypto package | ||
*/ | ||
export const certificateForKey = (key: any, privateKey: forge.pki.rsa.PrivateKey) => { | ||
const publicKey = pki.rsa.setPublicKey(privateKey.n, privateKey.e) | ||
const cert = pki.createCertificate() | ||
cert.publicKey = publicKey | ||
cert.serialNumber = '01' | ||
cert.validity.notBefore = new Date() | ||
cert.validity.notAfter = new Date() | ||
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 10) // eslint-disable-line @typescript-eslint/restrict-plus-operands | ||
const attrs = [{ | ||
name: 'organizationName', | ||
value: 'ipfs' | ||
}, { | ||
shortName: 'OU', | ||
value: 'keystore' | ||
}, { | ||
name: 'commonName', | ||
value: key.id | ||
}] | ||
cert.setSubject(attrs) | ||
cert.setIssuer(attrs) | ||
cert.setExtensions([{ | ||
name: 'basicConstraints', | ||
cA: true | ||
}, { | ||
name: 'keyUsage', | ||
keyCertSign: true, | ||
digitalSignature: true, | ||
nonRepudiation: true, | ||
keyEncipherment: true, | ||
dataEncipherment: true | ||
}, { | ||
name: 'extKeyUsage', | ||
serverAuth: true, | ||
clientAuth: true, | ||
codeSigning: true, | ||
emailProtection: true, | ||
timeStamping: true | ||
}, { | ||
name: 'nsCertType', | ||
client: true, | ||
server: true, | ||
email: true, | ||
objsign: true, | ||
sslCA: true, | ||
emailCA: true, | ||
objCA: true | ||
}]) | ||
// self-sign certificate | ||
cert.sign(privateKey) | ||
return cert | ||
} | ||
/** | ||
* Finds the first item in a collection that is matched in the | ||
@@ -69,0 +3,0 @@ * `asyncCompare` function. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
327919
19
2215
+ Added@libp2p/interface-keychain@2.0.5(transitive)
- Removednode-forge@^1.3.1