Initialize the User Account

After the user authorizes your application, initialize their account using the authentication token:
import HandcashConnect from '@handcash/handcash-connect';

const handCashConnect = new HandcashConnect({
  appId: 'YOUR_APP_ID',
  appSecret: 'YOUR_APP_SECRET',
});
const account = handCashConnect.getAccountFromAuthToken('<authToken>');

Methods

getCurrentProfile()

Retrieves the full profile of the current user, including both public and private information.
async getCurrentProfile(): Promise<UserProfile>
Returns: A promise that resolves to the user’s full profile. Example:
const profile = await account.profile.getCurrentProfile();
console.log(`Welcome, ${profile.publicProfile.displayName}!`);
Types:
type UserPublicProfile = {
  id: string;
  handle: string;
  paymail: string;
  displayName: string;
  avatarUrl: string;
  createdAt: Date;
};

type UserPrivateProfile = {
  email: string;
};
Response Type:
FieldTypeDescription
publicProfileUserPublicProfilePublic information about the user
privateProfileUserPrivateProfilePrivate information about the user

getPublicProfilesByHandle(handles)

Retrieves the public profiles of HandCash users by their handles.
async getPublicProfilesByHandle(handles: string[]): Promise<UserPublicProfile[]>
  • handles: An array of user handles.
Returns: A promise that resolves to an array of user public profiles. Example:
const handles = ['user1', 'user2'];
const publicProfiles = await account.profile.getPublicProfilesByHandle(handles);
publicProfiles.forEach(profile => console.log(profile.displayName));
Response Type:
FieldTypeDescription
idstringUnique identifier for the user
handlestringUser’s HandCash handle
paymailstringUser’s paymail address
displayNamestringUser’s display name
avatarUrlstringURL of the user’s avatar image
createdAtDateDate when the profile was created

getFriends()

Retrieves a list of the user’s friends and their public profiles. Requires the FRIENDS permission.
async getFriends(): Promise<UserPublicProfile[]>
Returns: A promise that resolves to an array of public profiles of the user’s friends. Example:
const friends = await account.profile.getFriends();
console.log(`You have ${friends.length} friends.`);
Response Type:
FieldTypeDescription
(Same as UserPublicProfile)

getPermissionsInfo()

Retrieves the permissions granted to the app by the user, along with the app ID.
async getPermissionsInfo(): Promise<PermissionInfo>
Returns: A promise that resolves to an object containing the permissions and app ID. Permission Enum:
enum Permission {
  Pay = 'PAY',
  UserPublicProfile = 'USER_PUBLIC_PROFILE',
  UserPrivateProfile = 'USER_PRIVATE_PROFILE',
  Friends = 'FRIENDS',
  Decrypt = 'DECRYPT',
  ReadBalance = 'READ_BALANCE',
}
Example:
const permissionsInfo = await account.profile.getPermissionsInfo();
console.log(`App ID: ${permissionsInfo.appId}`);
console.log('Permissions:', permissionsInfo.items);
Response Type:
FieldTypeDescription
itemsPermission[]Array of Permission enum values
appIdstringUnique identifier for the app

Types

The SDK uses several TypeScript types for representing user profiles, permissions, and other data. Here are some key types:
  • UserProfile: Combines public and private profile information.
  • UserPublicProfile: Contains publicly accessible user information.
  • UserPrivateProfile: Contains private user information.
  • PermissionInfo: Contains permissions and app ID.
For more detailed information on these types, refer to the SDK’s type definitions.