Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UserSession

Represents an instance of a signed in user for a particular app.

A signed in user has access to two major pieces of information about the user, the user's private key for that app and the location of the user's gaia storage bucket for the app.

A user can be signed in either directly through the interactive sign in process or by directly providing the app private key.

Hierarchy

  • UserSession

Index

Constructors

constructor

Properties

appConfig

appConfig: AppConfig

store

Methods

decryptContent

  • decryptContent(content: string, options?: object): string | Buffer
  • Decrypts data encrypted with encryptContent with the transit private key.

    Parameters

    • content: string

      encrypted content.

    • Optional options: object
      • Optional privateKey?: string

        the hex string of the ECDSA private key to use for decryption. If not provided, will use user's appPrivateKey.

    Returns string | Buffer

    decrypted content.

deleteFile

  • deleteFile(path: string): void
  • Deletes the specified file from the app's data store. Currently not implemented.

    Parameters

    • path: string

      the path to the file to delete

    Returns void

    that resolves when the file has been removed or rejects with an error

encryptContent

  • encryptContent(content: string | Buffer, options?: object): string
  • Encrypts the data provided with the app public key.

    Parameters

    • content: string | Buffer

      data to encrypt

    • Optional options: object
      • Optional publicKey?: string

        the hex string of the ECDSA public key to use for encryption. If not provided, will use user's appPrivateKey.

    Returns string

    Stringified ciphertext object

generateAndStoreTransitKey

  • generateAndStoreTransitKey(): string
  • Generates a ECDSA keypair to use as the ephemeral app transit private key and store in the session

    Returns string

    the hex encoded private key

getAuthResponseToken

  • getAuthResponseToken(): string
  • Retrieve the authentication token from the URL query

    Returns string

    the authentication token if it exists otherwise null

getFile

  • getFile(path: string, options?: storage.GetFileOptions): Promise<string | ArrayBuffer>
  • Retrieves the specified file from the app's data store.

    Parameters

    • path: string

      the path to the file to read

    • Optional options: storage.GetFileOptions

    Returns Promise<string | ArrayBuffer>

    that resolves to the raw data in the file or rejects with an error

getFileUrl

  • getFileUrl(path: string, options?: object): Promise<string>
  • Get the URL for reading a file from an app's data store.

    Parameters

    • path: string

      the path to the file to read

    • Optional options: object
      • Optional app?: string

        the app to lookup for multi-player storage - defaults to current origin

      • Optional username?: string

        the Blockstack ID to lookup for multi-player storage

      • Optional zoneFileLookupURL?: string

    Returns Promise<string>

    that resolves to the URL or rejects with an error

getOrSetLocalGaiaHubConnection

handlePendingSignIn

  • handlePendingSignIn(authResponseToken?: string): Promise<UserData>
  • Try to process any pending sign in request by returning a Promise that resolves to the user data object if the sign in succeeds.

    Parameters

    • Default value authResponseToken: string = this.getAuthResponseToken()

      the signed authentication response token

    Returns Promise<UserData>

    that resolves to the user data object if successful and rejects if handling the sign in request fails or there was no pending sign in request.

isSignInPending

  • isSignInPending(): boolean
  • Check if there is a authentication request that hasn't been handled.

    Returns boolean

    true if there is a pending sign in, otherwise false

isUserSignedIn

  • isUserSignedIn(): boolean
  • Check if a user is currently signed in.

    Returns boolean

    true if the user is signed in, false if not.

listFiles

  • listFiles(callback: function): Promise<number>
  • List the set of files in this application's Gaia storage bucket.

    Parameters

    • callback: function

      a callback to invoke on each named file that returns true to continue the listing operation or false to end it

        • (name: string): boolean
        • Parameters

          • name: string

          Returns boolean

    Returns Promise<number>

    that resolves to the number of files listed

loadUserData

makeAuthRequest

  • makeAuthRequest(transitKey?: string, redirectURI?: string, manifestURI?: string, scopes?: string[], appDomain?: string, expiresAt?: number, extraParams?: any): string
  • Generates an authentication request that can be sent to the Blockstack browser for the user to approve sign in. This authentication request can then be used for sign in by passing it to the redirectToSignInWithAuthRequest method.

    Note: This method should only be used if you want to roll your own authentication flow. Typically you'd use redirectToSignIn which takes care of this under the hood.

    Parameters

    • Optional transitKey: string

      hex-encoded transit key

    • Optional redirectURI: string
    • Optional manifestURI: string
    • Optional scopes: string[]
    • Optional appDomain: string
    • Default value expiresAt: number = nextHour().getTime()

      the time at which this request is no longer valid

    • Default value extraParams: any = {}

      Any extra parameters you'd like to pass to the authenticator. Use this to pass options that aren't part of the Blockstack auth spec, but might be supported by special authenticators.

    Returns string

    the authentication request

putFile

  • putFile(path: string, content: string | Buffer, options?: storage.PutFileOptions): Promise<string>
  • Stores the data provided in the app's data store to to the file specified.

    Parameters

    • path: string

      the path to store the data in

    • content: string | Buffer

      the data to store in the file

    • Optional options: storage.PutFileOptions

    Returns Promise<string>

    that resolves if the operation succeed and rejects if it failed

redirectToSignIn

  • redirectToSignIn(redirectURI?: string, manifestURI?: string, scopes?: string[]): void
  • Generates an authentication request and redirects the user to the Blockstack browser to approve the sign in request.

    Please note that this requires that the web browser properly handles the blockstack: URL protocol handler.

    Most applications should use this method for sign in unless they require more fine grained control over how the authentication request is generated. If your app falls into this category, use generateAndStoreTransitKey, makeAuthRequest, and redirectToSignInWithAuthRequest to build your own sign in process.

    Parameters

    • Optional redirectURI: string
    • Optional manifestURI: string
    • Optional scopes: string[]

    Returns void

redirectToSignInWithAuthRequest

  • redirectToSignInWithAuthRequest(authRequest?: string, blockstackIDHost?: string): void
  • Redirects the user to the Blockstack browser to approve the sign in request given.

    The user is redirected to the authenticator URL specified in the AppConfig if the blockstack: protocol handler is not detected. Please note that the protocol handler detection does not work on all browsers.

    Parameters

    • Optional authRequest: string

      the authentication request generated by makeAuthRequest

    • Optional blockstackIDHost: string

    Returns void

Private setLocalGaiaHubConnection

  • These two functions are app-specific connections to gaia hub, they read the user data object for information on setting up a hub connection, and store the hub config to localstorage

    Returns Promise<GaiaHubConfig>

    that resolves to the new gaia hub connection

signUserOut

  • signUserOut(redirectURL?: string): void
  • Sign the user out and optionally redirect to given location.

    Parameters

    • Optional redirectURL: string

      Location to redirect user to after sign out. Only used in environments with window available

    Returns void

Generated using TypeDoc