Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @textile/threads-crypto

Threads Crypto (threads-crypto)

A set of crypto tools for use with Textile's Threads protocol & database

Textile License npm (scoped)

This sub-package is part of js-threads. See the top-level documentation for details.

Note: This is a "fork" of js-libp2p-crypto intended to run a minimal set of crypto functions in multiple Javascript environements, including browsers, Node, and React Native.

Index

References

CipherType

Re-exports CipherType

CurveType

Re-exports CurveType

HashType

Re-exports HashType

PrivateKey

Re-exports PrivateKey

PublicKey

Re-exports PublicKey

aes

Re-exports aes

keys

Re-exports keys

multihash

Re-exports multihash

sha256

Re-exports sha256

sha256Multihash

Re-exports sha256Multihash

Type aliases

CipherType

CipherType: "AES-128" | "AES-256" | "Blowfish"

Supported cipher types.

CurveType

CurveType: "P-256" | "P-384" | "P-521"

Supported curve types.

HashType

HashType: "SHA1" | "SHA256" | "SHA512"

Maps an IPFS hash name to its node-forge equivalent. See https://github.com/multiformats/multihash/blob/master/hashtable.csv

Variables

Const keyTypeError

keyTypeError: Error = new Error("Unsupported key type.")

Exposes an interface to various cryptographic key generation routines. Currently the 'ed25519' types are supported, although ed25519 keys support only signing and verification of messages.

Functions

decodePrivateKey

  • decodePrivateKey(binary: Uint8Array): PrivateKey

decodePublicKey

  • decodePublicKey(binary: Uint8Array): PublicKey

encodePrivateKey

  • encodePrivateKey(message: PrivateKey): Uint8Array

encodePublicKey

  • encodePublicKey(message: PublicKey): Uint8Array

ensureKey

  • ensureKey(key: Uint8Array, length: number): Uint8Array

generateKeyPair

Const generateKeyPair

  • generateKeyPair(type: "Ed25519", bytesLength?: undefined | number): Promise<PrivateKey>

Const marshalPrivateKey

  • marshalPrivateKey(key: PrivateKey, type?: string): Uint8Array

Const marshalPublicKey

  • marshalPublicKey(key: PublicKey, type?: string): Uint8Array
  • Converts a public key object into a protobuf serialized public key

    Parameters

    • key: PublicKey

      public key.

    • Default value type: string = "ED25519"

      key type. Currently only ED25519 is supported.

    Returns Uint8Array

multihash

  • multihash(digest: Uint8Array, code: number, length?: undefined | number): Uint8Array
  • Parameters

    • digest: Uint8Array
    • code: number
    • Optional length: undefined | number

    Returns Uint8Array

Const randomBytes

  • randomBytes(byteLength: number): Uint8Array

sha256Multihash

  • sha256Multihash(bytes: Uint8Array): Uint8Array
  • Basic multihash implementation that only supports sha256.

    Parameters

    • bytes: Uint8Array

      The bytes to wrap with multihash.

    Returns Uint8Array

unmarshalEd25519PrivateKey

unmarshalEd25519PublicKey

Const unmarshalPrivateKey

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

    Parameters

    • buf: Uint8Array

      The input key bytes.

    Returns Promise<PrivateKey>

Const unmarshalPublicKey

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

    Parameters

    • buf: Uint8Array

      The input key bytes.

    Returns PublicKey

Object literals

Const constants

constants: object

HASH_BYTE_LENGTH

HASH_BYTE_LENGTH: number = 64

PRIVATE_KEY_BYTE_LENGTH

PRIVATE_KEY_BYTE_LENGTH: number = 32

PUBLIC_KEY_BYTE_LENGTH

PUBLIC_KEY_BYTE_LENGTH: number = 32

SEED_BYTE_LENGTH

SEED_BYTE_LENGTH: number = 32

SIGN_BYTE_LENGTH

SIGN_BYTE_LENGTH: number = 64

Const decodeKeyType

decodeKeyType: object

0

0: RSA = KeyType.RSA

1

1: Ed25519 = KeyType.Ed25519

2

2: Secp256k1 = KeyType.Secp256k1

Const encodeKeyType

encodeKeyType: object

Ed25519

Ed25519: number = 1

RSA

RSA: number = 0

Secp256k1

Secp256k1: number = 2

Const supportedKeys

supportedKeys: object

ed25519

ed25519: "/home/runner/work/js-threads/js-threads/packages/crypto/src/ed25519"

Const verify

verify: object

data

data: number[] = [104,101,108,108,111,33,32,97,110,100,32,119,101,108,99,111,109,101,32,116,111,32,115,111,109,101,32,97,119,101,115,111,109,101,32,99,114,121,112,116,111,32,112,114,105,109,105,116,105,118,101,115,]

privateKey

privateKey: number[] = [8,1,18,64,155,239,222,118,236,90,110,88,231,141,170,117,219,216,115,244,80,92,16,6,157,157,98,66,170,177,118,240,205,191,49,82,158,27,235,18,133,243,1,53,246,180,14,66,126,27,227,227,23,97,244,26,80,224,222,221,17,195,6,224,217,170,231,139,]

publicKey

publicKey: number[] = [8,1,18,32,158,27,235,18,133,243,1,53,246,180,14,66,126,27,227,227,23,97,244,26,80,224,222,221,17,195,6,224,217,170,231,139,]

signature

signature: number[] = [19,82,7,49,108,87,8,98,51,59,87,233,67,123,130,208,219,216,117,183,252,7,132,136,94,234,82,226,103,183,133,12,212,111,184,156,83,107,172,3,124,19,198,155,40,108,201,127,18,34,108,213,239,52,97,19,166,186,55,95,29,72,164,5,]