UNPKG

@handcash/handcash-connect

Version:
128 lines (127 loc) 5.3 kB
import { KeyPair } from './types/bsv'; import HandCashCloudAccount from './handcash_cloud_account'; import Environments from './environments'; import HandCashConnectService from './api/handcash_connect_service'; import { UserPublicProfile } from './types/account'; import { WebhookPayload } from './types/events'; import { QueryParams } from './types/http'; type Params = { appId: string; appSecret: string; env?: (typeof Environments)['prod']; }; /** * * HandCashConnect is the main class of the HandCash Connect SDK. * It is used to create a HandCashConnect instance, which is used to authenticate users, get their data and make payments. * * @param {string} appId - The app id of your app. You get it from your developer dashboard. * @param {string} appSecret - The app secret of your app. You get it from your developer dashboard. * @param {Object} [env] - Optional: The environment to use. Defaults to prod. * @param {string} env.apiEndpoint - The API url to use. * @param {string} env.clientUrl - The client url to use. * @param {string} env.trustholderEndpoint - The trustholder url to use. * */ export default class HandCashConnect { appId: string; appSecret: string; handCashConnectService: HandCashConnectService; env: (typeof Environments)['prod']; constructor({ appId, appSecret, env }: Params); /** * * Generates the OAuth URL to redirect the user to HandCash. * * @param {Object} queryParameters - Query parameters to be added to the URL. * * @returns {string} redirectionUrl - The URL to redirect the user to. * * */ getRedirectionUrl(queryParameters?: QueryParams): string; /** * * Gets the URL to redirect the user to in order to adjust their spending limits. * * @param {string} [redirectUrl] - Optional: Make use of the redirectUrl parameter to have the user redirected back to your app following their limit change. * * @returns {string} redirectionUrl - The URL to redirect the user to. * */ getChangeSpendLimitsUrl(redirectUrl?: string): string; /** * * Generates a new authentication keypair (private and public key). * This is the first step to create a new HandCash account. * * @returns {Object} keyPair - The key pair. * @returns {string} keyPair.privateKey - The private key in hex format. * @returns {string} keyPair.publicKey - The public key in hex format. * * */ generateAuthenticationKeyPair: () => KeyPair; /** * Sends a verification code to the email provided by the user. * * @param {string} email - The email address of the user. * @param {Object} [customEmailParameters] - Optional: Custom parameters to be added to the email. * * @returns {string} requestId - The request id. */ requestEmailCode(email: string, customEmailParameters?: object): Promise<string>; /** * * Verifies the email code that was sent to the user's email. * * @param {string} requestId - The request id that you get from the requestEmailCode method. * @param {string} verificationCode - The verification code that was sent to the user's email. * @param {string} accessPublicKey - The access public key of the user. * */ verifyEmailCode(requestId: string, verificationCode: string, accessPublicKey: string): Promise<void>; /** * Creates a new account for the verified email along with some authentication public key. * @deprecated Use createAccount instead * * @param {string} accessPublicKey - The access public key of the user. * @param {string} email - The email address of the user. * * @returns {Object} UserPublicProfile - The user's public profile. * */ createNewAccount(accessPublicKey: string, email: string): Promise<UserPublicProfile>; /** * Creates a new account for the verified email along with some authentication public key. * * @param {Object} params - The parameters for creating a new account * @param {string} params.accessPublicKey - The access public key of the user. * @param {string} params.email - The email address of the user. * @param {string} [params.alias] - Optional: The alias of the user for the new account. Example: satoshi.33 * * @returns {Object} UserPublicProfile - The user's public profile. * */ createAccount(params: { accessPublicKey: string; email: string; alias?: string; }): Promise<UserPublicProfile>; /** * Initializes the account as usually using the authentication private key. * * @param {string} authToken - The authentication private key. * * @returns {Object} HandCashCloundAccount - The full HandCash cloud account of the user. * */ getAccountFromAuthToken(authToken: string): HandCashCloudAccount; /** * Gets the event type from the incoming webhook request. * * @param request - The incoming web request object. * @returns {WebhookPayload} - The event type. * @throws {Error} - Throws an error if the validation fails or the event type is unknown. */ getWebhookEvent: (signature: string, body: any) => WebhookPayload; } export {};