Options
All
  • Public
  • Public/Protected
  • All
Menu

@stacks/profile

Functions for manipulating user profiles.

Installation

npm install @stacks/profile

Index

Functions

extractProfile

  • extractProfile(token: string, publicKeyOrAddress?: string | null): Record<string, any>
  • Extracts a profile from an encoded token and optionally verifies it, if publicKeyOrAddress is provided.

    throws

    {Error} - if the token isn't signed by the provided publicKeyOrAddress

    Parameters

    • token: string

      the token to be extracted

    • publicKeyOrAddress: string | null = null

      the public key or address of the keypair that is thought to have signed the token

    Returns Record<string, any>

    • the profile extracted from the encoded token

signProfileToken

  • signProfileToken(profile: any, privateKey: string, subject?: any, issuer?: any, signingAlgorithm?: string, issuedAt?: Date, expiresAt?: Date): string
  • Signs a profile token

    Parameters

    • profile: any

      the JSON of the profile to be signed

    • privateKey: string

      the signing private key

    • Optional subject: any

      the entity that the information is about

    • Optional issuer: any

      the entity that is issuing the token

    • signingAlgorithm: string = 'ES256K'

      the signing algorithm to use

    • issuedAt: Date = ...

      the time of issuance of the token

    • expiresAt: Date = ...

      the time of expiration of the token

    Returns string

    • the signed profile token

verifyProfileToken

  • verifyProfileToken(token: string, publicKeyOrAddress: string): TokenInterface
  • Verifies a profile token

    throws

    {Error} - throws an error if token verification fails

    Parameters

    • token: string

      the token to be verified

    • publicKeyOrAddress: string

      the public key or address of the keypair that is thought to have signed the token

    Returns TokenInterface

    • the verified, decoded profile token

wrapProfileToken

  • wrapProfileToken(token: string): { decodedToken: TokenInterface; token: string }
  • Wraps a token for a profile token file

    Parameters

    • token: string

      the token to be wrapped

    Returns { decodedToken: TokenInterface; token: string }

    • including token and decodedToken
    • decodedToken: TokenInterface
    • token: string

Generated using TypeDoc