Hub JS Package

Hub JS Package

  • Users
  • Buckets
  • Threads
  • Textile Docs

›Private Key Class

Users API

  • Users.getUsage() method
  • Users.setupMailbox() method
  • Users.getMailboxID() method
  • Users.sendMessage() method
  • Users.watchInbox() method
  • Users.watchSentbox() method
  • Users.listSentboxMessages() method
  • Users.deleteSentboxMessage() method
  • Users.listInboxMessages() method
  • Users.readInboxMessage() method
  • Users.deleteInboxMessage() method
  • Users.listThreads() method
  • Users.getThread() method
  • Users.copyAuth() method
  • Users.withUserAuth() method
  • Users.withKeyInfo() method
  • Users.getToken() method
  • Users.getTokenChallenge() method
  • Users.setToken() method
  • Users.withThread() method

Types

  • GetThreadResponse interface
  • InboxListOptions interface
  • MailboxEvent interface
  • MailboxEventType enum
  • PushPathResult interface
  • PushPathsResult interface
  • SentboxListOptions interface
  • UserMessage interface
  • UsageOptions interface
  • GetUsageResponse interface

Identity interfaces

  • Identity interface
  • Identity.public property
  • Identity.sign() method
  • Private interface
  • Public interface
  • Public.bytes property
  • Public.verify() method

Private Key Class

  • PrivateKey class
  • PrivateKey.bytes property
  • PrivateKey.canSign() method
  • PrivateKey.decrypt() method
  • PrivateKey.fromRandom() method
  • PrivateKey.fromString() method
  • PrivateKey.privKey property
  • PrivateKey.pubKey property
  • PrivateKey.public property
  • PrivateKey.sign() method
  • PrivateKey.seed property
  • PrivateKey.toString() method
  • PrivateKey.type property
  • PrivateKey.fromRawEd25519Seed() method

Public Key Class

  • PublicKey class
  • PublicKey.fromString() method
  • PublicKey.toString() method
  • PublicKey.verify() method
  • PublicKey.encrypt() method
  • PublicKey.bytes property
  • PublicKey.type property
  • PublicKey.pubKey property

@textile/hub > PrivateKey

PrivateKey class

Default implementation of the Private interface, with decryption support. In theory, RSA, ed25519, and secp256k1 key types (and more) should be supported, although currently only ed25519 has full sign and decrypt capabilities.

Signature:

export declare class PrivateKey implements Private 

Implements: Private

Example 1

Create a private key, extract the public key string

import { PrivateKey } from '@textile/hub'

function example() {
  const identity = PrivateKey.fromRandom()
  const publicKey = identity.public.toString()
  return publicKey
}

Example 2

Encrypt a message using another person's public key (string)

import { PublicKey } from '@textile/hub'

async function example(publicKey: string) {
  const recipient = PublicKey.fromString(publicKey)
  const msg = new TextEncoder().encode('howdy!')
  const ciphertext = await recipient.encrypt(msg)
  return ciphertext
}

Example 3

Decrypt a message sent to the local user with their private key

import { PrivateKey } from '@textile/hub'

async function example(identity: PrivateKey, ciphertext: Uint8Array) {
  const plaintext = await identity.decrypt(ciphertext)
  return plaintext
}

Example 4

Encrypt the local user's own message for later reading.

import { PrivateKey } from '@textile/hub'

async function example(identity: PrivateKey) {
  const msg = new TextEncoder().encode('private message!')
  const ciphertext = await identity.public.encrypt(msg)
  return ciphertext // can only be decrypted by the local user
}

Constructors

ConstructorModifiersDescription
(constructor)(secretKey, type)Constructor

Properties

PropertyModifiersTypeDescription
bytesUint8ArrayReturn the protobuf-encoded bytes of this private key.
privKeyUint8ArrayThe raw private key bytes.
pubKeyUint8ArrayThe raw public key bytes.
publicPublicKeyGet the public key associated with this identity.
seedUint8ArrayThe raw 32-byte secret seed
typestring

Methods

MethodModifiersDescription
canSign()Returns true if this key contains a secret key and can sign.
decrypt(ciphertext)Decrypt the given ciphertext using this private key.
fromRandom()staticCreate a random PrivateKey.
fromRawEd25519Seed(rawSeed)staticCreates a new PrivateKey from ed25519 secret key seed raw bytes.
fromString(str)staticCreate a PrivateKey from the result of calling toString().
sign(data)Sign the message using this private key and return the signature.
toString()Return the base32-encoded multibase string of the bytes of this private key. Useful for encoding the key for sharing etc.
← Public.verify() methodPrivateKey.bytes property →
  • PrivateKey class
  • Example 1
  • Example 2
  • Example 3
  • Example 4
  • Constructors
  • Properties
  • Methods
Hub JS Package
Docs
Getting StartedThreadDBBuckets
Resources
All DocumentationProject SlackBlog
More
GitHubStar
Follow @textileio