libp2p-crypto

  • Version 0.21.2
  • Published
  • 328 kB
  • 8 dependencies
  • MIT license

Install

npm i libp2p-crypto
yarn add libp2p-crypto
pnpm add libp2p-crypto

Overview

Crypto primitives for libp2p

Index

Functions

function pbkdf2

pbkdf2: (
password: string | Uint8Array,
salt: string | Uint8Array,
iterations: number,
keySize: number,
hash: string
) => Uint8Array;
  • Computes the Password-Based Key Derivation Function 2.

    Parameter password

    The password.

    Parameter salt

    The salt.

    Parameter iterations

    Number of iterations to use.

    Parameter keySize

    The size of the output key in bytes.

    Parameter hash

    The hash name ('sha1', 'sha2-512, ...)

function randomBytes

randomBytes: (number: number) => Uint8Array;
  • Generates a Uint8Array populated by random bytes.

    Parameter The

    size of the random bytes Uint8Array.

Interfaces

interface Keystretcher

interface Keystretcher {}

    property cipherKey

    cipherKey: Uint8Array;

      property iv

      iv: Uint8Array;

        property macKey

        macKey: Uint8Array;

          call signature

          (res: Uint8Array): Keystretcher;

            interface PrivateKey

            interface PrivateKey {}
            • Generic private key interface.

            property bytes

            readonly bytes: Uint8Array;

              property equals

              equals: (key: PrivateKey) => boolean;

                property export

                export: (password: string, format?: 'pkcs-8' | string) => Promise<string>;
                • Exports the password protected key in the format specified.

                property hash

                hash: () => Promise<Uint8Array>;

                  property id

                  id: () => Promise<string>;
                  • Gets the ID of the key.

                    The key id is the base58 encoding of the SHA-256 multihash of its public key. The public key is a protobuf encoding containing a type and the DER encoding of the PKCS SubjectPublicKeyInfo.

                  property marshal

                  marshal: () => Uint8Array;

                    property public

                    readonly public: PublicKey;

                      property sign

                      sign: (data: Uint8Array) => Promise<Uint8Array>;

                        interface PublicKey

                        interface PublicKey {}
                        • Generic public key interface.

                        property bytes

                        readonly bytes: Uint8Array;

                          property equals

                          equals: (key: PublicKey) => boolean;

                            property hash

                            hash: () => Promise<Uint8Array>;

                              property marshal

                              marshal: () => Uint8Array;

                                property verify

                                verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>;

                                  interface StretchPair

                                  interface StretchPair {}

                                    property k1

                                    k1: Keystretcher;

                                      property k2

                                      k2: Keystretcher;

                                        Type Aliases

                                        type CipherType

                                        type CipherType = 'AES-128' | 'AES-256' | 'Blowfish';
                                        • Supported cipher types.

                                        type CurveType

                                        type CurveType = 'P-256' | 'P-384' | 'P-521';
                                        • Supported curve types.

                                        type HashType

                                        type HashType = 'SHA1' | 'SHA256' | 'SHA512';
                                        • Maps an IPFS hash name to its node-forge equivalent. See https://github.com/multiformats/multihash/blob/master/hashtable.csv

                                        type KeyType

                                        type KeyType = 'Ed25519' | 'RSA' | 'secp256k1';
                                        • Supported key types.

                                        Namespaces

                                        namespace aes

                                        namespace aes {}
                                        • Exposes an interface to AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197. This uses CTR mode.

                                        function create

                                        create: (key: Uint8Array, iv: Uint8Array) => Promise<Cipher>;
                                        • Create a new AES Cipher.

                                          Parameter key

                                          The key, if length 16 then AES 128 is used. For length 32, AES 256 is used.

                                          Parameter iv

                                          Must have length 16.

                                        interface Cipher

                                        interface Cipher {}
                                        • AES Cipher in CTR mode.

                                        method decrypt

                                        decrypt: (data: Uint8Array) => Promise<Uint8Array>;

                                          method encrypt

                                          encrypt: (data: Uint8Array) => Promise<Uint8Array>;

                                            namespace hmac

                                            namespace hmac {}
                                            • Exposes an interface to the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message. The receiver verifies the hash by recomputing it using the same key.

                                            function create

                                            create: (
                                            hash: 'SHA1' | 'SHA256' | 'SHA512' | string,
                                            secret: Uint8Array
                                            ) => Promise<Digest>;
                                            • Create a new HMAC Digest.

                                            interface Digest

                                            interface Digest {}
                                            • HMAC Digest.

                                            property length

                                            length: 20 | 32 | 64 | number;

                                              method digest

                                              digest: (data: Uint8Array) => Promise<Uint8Array>;

                                                namespace keys

                                                namespace keys {}
                                                • Exposes an interface to various cryptographic key generation routines. Currently the 'RSA' and 'ed25519' types are supported, although ed25519 keys support only signing and verification of messages. For encryption / decryption support, RSA keys should be used. Installing the libp2p-crypto-secp256k1 module adds support for the 'secp256k1' type, which supports ECDSA signatures using the secp256k1 elliptic curve popularized by Bitcoin. This module is not installed by default, and should be explicitly depended on if your project requires secp256k1 support.

                                                variable keysPBM

                                                const keysPBM: any;

                                                  function generateEphemeralKeyPair

                                                  generateEphemeralKeyPair: (
                                                  curve: CurveType | string
                                                  ) => Promise<{
                                                  key: Uint8Array;
                                                  genSharedKey: (theirPub: Uint8Array, forcePrivate?: any) => Promise<Uint8Array>;
                                                  }>;
                                                  • Generates an ephemeral public key and returns a function that will compute the shared secret key. Focuses only on ECDH now, but can be made more general in the future.

                                                    Parameter curve

                                                    The curve to use. One of 'P-256', 'P-384', 'P-521' is currently supported.

                                                  function generateKeyPair

                                                  generateKeyPair: {
                                                  (type: KeyType | string, bits: number): Promise<PrivateKey>;
                                                  (type: 'Ed25519'): Promise<supportedKeys.ed25519.Ed25519PrivateKey>;
                                                  (type: 'RSA', bits: number): Promise<supportedKeys.rsa.RsaPrivateKey>;
                                                  (type: 'secp256k1'): Promise<supportedKeys.secp256k1.Secp256k1PrivateKey>;
                                                  };
                                                  • Generates a keypair of the given type and bitsize.

                                                    Parameter type

                                                    One of the supported key types.

                                                    Parameter bits

                                                    Number of bits. Minimum of 1024.

                                                  function generateKeyPairFromSeed

                                                  generateKeyPairFromSeed: {
                                                  (type: KeyType | string, seed: Uint8Array, bits: number): Promise<PrivateKey>;
                                                  (
                                                  type: 'Ed25519',
                                                  seed: Uint8Array,
                                                  bits: number
                                                  ): Promise<supportedKeys.ed25519.Ed25519PrivateKey>;
                                                  };
                                                  • Generates a keypair of the given type and bitsize.

                                                    Parameter type

                                                    One of the supported key types. Currently only 'Ed25519' is supported.

                                                    Parameter seed

                                                    A 32 byte uint8array.

                                                    Parameter bits

                                                    Number of bits. Minimum of 1024.

                                                  function import

                                                  import: (pem: string, password: string, format?: string) => Promise<supportedKeys.rsa.RsaPrivateKey>
                                                  • Converts a PEM password protected private key into its representative object.

                                                    Parameter pem

                                                    Password protected private key in PEM format.

                                                    Parameter password

                                                    The password used to protect the key.

                                                  function keyStretcher

                                                  keyStretcher: (
                                                  cipherType: CipherType | string,
                                                  hashType: HashType | string,
                                                  secret: Uint8Array | string
                                                  ) => Promise<StretchPair>;
                                                  • Generates a set of keys for each party by stretching the shared key.

                                                    Parameter cipherType

                                                    The cipher type to use. One of 'AES-128', 'AES-256', or 'Blowfish'

                                                    Parameter hashType

                                                    The hash type to use. One of 'SHA1', 'SHA2256', or 'SHA2512'.

                                                    Parameter secret

                                                    The shared key secret.

                                                  function marshalPrivateKey

                                                  marshalPrivateKey: (key: PrivateKey, type?: KeyType | string) => Uint8Array;
                                                  • Converts a private key object into a protobuf serialized private key.

                                                    Parameter key

                                                    An RSA, Ed25519, or Secp256k1 private key object.

                                                    Parameter type

                                                    One of the supported key types.

                                                  function marshalPublicKey

                                                  marshalPublicKey: (key: PublicKey, type?: KeyType | string) => Uint8Array;
                                                  • Converts a public key object into a protobuf serialized public key.

                                                    Parameter key

                                                    An RSA, Ed25519, or Secp256k1 public key object.

                                                    Parameter type

                                                    One of the supported key types.

                                                  function unmarshalPrivateKey

                                                  unmarshalPrivateKey: (buf: Uint8Array) => Promise<PrivateKey>;
                                                  • Converts a protobuf serialized private key into its representative object.

                                                    Parameter buf

                                                    The protobuf serialized private key.

                                                  function unmarshalPublicKey

                                                  unmarshalPublicKey: (buf: Uint8Array) => PublicKey;
                                                  • Converts a protobuf serialized public key into its representative object.

                                                    Parameter buf

                                                    The protobuf serialized public key.

                                                  namespace keys.supportedKeys

                                                  namespace keys.supportedKeys {}

                                                    namespace keys.supportedKeys.ed25519

                                                    namespace keys.supportedKeys.ed25519 {}

                                                      function generateKeyPair

                                                      generateKeyPair: () => Promise<Ed25519PrivateKey>;

                                                        function generateKeyPairFromSeed

                                                        generateKeyPairFromSeed: (seed: Uint8Array) => Promise<Ed25519PrivateKey>;

                                                          function unmarshalEd25519PrivateKey

                                                          unmarshalEd25519PrivateKey: (buf: Uint8Array) => Promise<Ed25519PrivateKey>;

                                                            function unmarshalEd25519PublicKey

                                                            unmarshalEd25519PublicKey: (buf: Uint8Array) => Ed25519PublicKey;

                                                              class Ed25519PrivateKey

                                                              class Ed25519PrivateKey implements PrivateKey {}

                                                                constructor

                                                                constructor(key: Uint8Array, publicKey: Uint8Array);

                                                                  property bytes

                                                                  readonly bytes: Uint8Array;

                                                                    property public

                                                                    readonly public: Ed25519PublicKey;

                                                                      method equals

                                                                      equals: (key: PrivateKey) => boolean;

                                                                        method export

                                                                        export: (password: string, format?: string) => Promise<string>;

                                                                          method hash

                                                                          hash: () => Promise<Uint8Array>;

                                                                            method id

                                                                            id: () => Promise<string>;

                                                                              method marshal

                                                                              marshal: () => Uint8Array;

                                                                                method sign

                                                                                sign: (data: Uint8Array) => Promise<Uint8Array>;

                                                                                  class Ed25519PublicKey

                                                                                  class Ed25519PublicKey implements PublicKey {}

                                                                                    constructor

                                                                                    constructor(key: Uint8Array);

                                                                                      property bytes

                                                                                      readonly bytes: Uint8Array;

                                                                                        method encrypt

                                                                                        encrypt: (bytes: Uint8Array) => Uint8Array;

                                                                                          method equals

                                                                                          equals: (key: PublicKey) => boolean;

                                                                                            method hash

                                                                                            hash: () => Promise<Uint8Array>;

                                                                                              method marshal

                                                                                              marshal: () => Uint8Array;

                                                                                                method verify

                                                                                                verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>;

                                                                                                  namespace keys.supportedKeys.rsa

                                                                                                  namespace keys.supportedKeys.rsa {}

                                                                                                    function fromJwk

                                                                                                    fromJwk: (jwk: Uint8Array) => Promise<RsaPrivateKey>;

                                                                                                      function generateKeyPair

                                                                                                      generateKeyPair: (bits: number) => Promise<RsaPrivateKey>;

                                                                                                        function unmarshalRsaPrivateKey

                                                                                                        unmarshalRsaPrivateKey: (buf: Uint8Array) => Promise<RsaPrivateKey>;

                                                                                                          function unmarshalRsaPublicKey

                                                                                                          unmarshalRsaPublicKey: (buf: Uint8Array) => RsaPublicKey;

                                                                                                            class RsaPrivateKey

                                                                                                            class RsaPrivateKey implements PrivateKey {}

                                                                                                              constructor

                                                                                                              constructor(key: any, publicKey: Uint8Array);

                                                                                                                property bytes

                                                                                                                readonly bytes: Uint8Array;

                                                                                                                  property public

                                                                                                                  readonly public: RsaPublicKey;

                                                                                                                    method decrypt

                                                                                                                    decrypt: (bytes: Uint8Array) => Uint8Array;

                                                                                                                      method equals

                                                                                                                      equals: (key: PrivateKey) => boolean;

                                                                                                                        method export

                                                                                                                        export: (password: string, format?: string) => Promise<string>;

                                                                                                                          method genSecret

                                                                                                                          genSecret: () => Uint8Array;

                                                                                                                            method hash

                                                                                                                            hash: () => Promise<Uint8Array>;

                                                                                                                              method id

                                                                                                                              id: () => Promise<string>;

                                                                                                                                method marshal

                                                                                                                                marshal: () => Uint8Array;

                                                                                                                                  method sign

                                                                                                                                  sign: (data: Uint8Array) => Promise<Uint8Array>;

                                                                                                                                    class RsaPublicKey

                                                                                                                                    class RsaPublicKey implements PublicKey {}

                                                                                                                                      constructor

                                                                                                                                      constructor(key: Uint8Array);

                                                                                                                                        property bytes

                                                                                                                                        readonly bytes: Uint8Array;

                                                                                                                                          method encrypt

                                                                                                                                          encrypt: (bytes: Uint8Array) => Uint8Array;

                                                                                                                                            method equals

                                                                                                                                            equals: (key: PublicKey) => boolean;

                                                                                                                                              method hash

                                                                                                                                              hash: () => Promise<Uint8Array>;

                                                                                                                                                method marshal

                                                                                                                                                marshal: () => Uint8Array;

                                                                                                                                                  method verify

                                                                                                                                                  verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>;

                                                                                                                                                    namespace keys.supportedKeys.secp256k1

                                                                                                                                                    namespace keys.supportedKeys.secp256k1 {}

                                                                                                                                                      function generateKeyPair

                                                                                                                                                      generateKeyPair: () => Promise<Secp256k1PrivateKey>;

                                                                                                                                                        function unmarshalSecp256k1PrivateKey

                                                                                                                                                        unmarshalSecp256k1PrivateKey: (
                                                                                                                                                        bytes: Uint8Array
                                                                                                                                                        ) => Promise<Secp256k1PrivateKey>;

                                                                                                                                                          function unmarshalSecp256k1PublicKey

                                                                                                                                                          unmarshalSecp256k1PublicKey: (bytes: Uint8Array) => Secp256k1PublicKey;

                                                                                                                                                            class Secp256k1PrivateKey

                                                                                                                                                            class Secp256k1PrivateKey implements PrivateKey {}

                                                                                                                                                              constructor

                                                                                                                                                              constructor(key: Uint8Array, publicKey: Uint8Array);

                                                                                                                                                                property bytes

                                                                                                                                                                readonly bytes: Uint8Array;

                                                                                                                                                                  property public

                                                                                                                                                                  readonly public: Secp256k1PublicKey;

                                                                                                                                                                    method equals

                                                                                                                                                                    equals: (key: PrivateKey) => boolean;

                                                                                                                                                                      method export

                                                                                                                                                                      export: (password: string, format?: string) => Promise<string>;

                                                                                                                                                                        method hash

                                                                                                                                                                        hash: () => Promise<Uint8Array>;

                                                                                                                                                                          method id

                                                                                                                                                                          id: () => Promise<string>;

                                                                                                                                                                            method marshal

                                                                                                                                                                            marshal: () => Uint8Array;

                                                                                                                                                                              method sign

                                                                                                                                                                              sign: (data: Uint8Array) => Promise<Uint8Array>;

                                                                                                                                                                                class Secp256k1PublicKey

                                                                                                                                                                                class Secp256k1PublicKey implements PublicKey {}

                                                                                                                                                                                  constructor

                                                                                                                                                                                  constructor(key: Uint8Array);

                                                                                                                                                                                    property bytes

                                                                                                                                                                                    readonly bytes: Uint8Array;

                                                                                                                                                                                      method encrypt

                                                                                                                                                                                      encrypt: (bytes: Uint8Array) => Uint8Array;

                                                                                                                                                                                        method equals

                                                                                                                                                                                        equals: (key: PublicKey) => boolean;

                                                                                                                                                                                          method hash

                                                                                                                                                                                          hash: () => Promise<Uint8Array>;

                                                                                                                                                                                            method marshal

                                                                                                                                                                                            marshal: () => Uint8Array;

                                                                                                                                                                                              method verify

                                                                                                                                                                                              verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>;

                                                                                                                                                                                                Package Files (1)

                                                                                                                                                                                                Dependencies (8)

                                                                                                                                                                                                Dev Dependencies (5)

                                                                                                                                                                                                Peer Dependencies (0)

                                                                                                                                                                                                No peer dependencies.

                                                                                                                                                                                                Badge

                                                                                                                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/libp2p-crypto.

                                                                                                                                                                                                • Markdown
                                                                                                                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/libp2p-crypto)
                                                                                                                                                                                                • HTML
                                                                                                                                                                                                  <a href="https://www.jsdocs.io/package/libp2p-crypto"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>