Hub JS Package

Hub JS Package

  • Users
  • Buckets
  • Threads
  • Textile Docs

›Public 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 > PublicKey

PublicKey class

Default implementation of the Public interface, with encryption support. In theory, RSA, ed25519, and secp256k1 key types (and more) should be supported, although currently only ed25519 has full verify and encrypt capabilities.

Signature:

export declare class PublicKey implements Public 

Implements: Public

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)(pubKey, type)Constructs a new instance of the PublicKey class

Properties

PropertyModifiersTypeDescription
bytesUint8ArrayReturn the protobuf-encoded bytes of this public key.
pubKeyUint8Array
typestring

Methods

MethodModifiersDescription
encrypt(data)Encrypt the given data using this public key.
fromString(str)staticCreate a PublicKey from the result of calling toString().
toString()Return the base32-encoded multibase string of the bytes of this public key. Useful for encoding the key for sharing etc.
verify(data, signature)Verifies the signature for the data and returns true if verification succeeded or false if it failed.
← PrivateKey.fromRawEd25519Seed() methodNext →
  • PublicKey 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