Skip to main content

Class: PrivyClient

The Privy client performs operations against the Privy API.

import {PrivyClient} from '@privy-io/privy-node';

Hierarchyโ€‹

  • PrivyConfig

    โ†ณ PrivyClient

Constructorsโ€‹

constructorโ€‹

โ€ข new PrivyClient(apiKey, apiSecret, options?)

Creates a new Privy client.

Parametersโ€‹

NameTypeDescription
apiKeystringPrivy API key.
apiSecretstringPrivy API secret.
optionsObjectInitialization options.
options.apiURL?stringThe URL of the Privy API. Defaults to https://api.privy.io/v0.
options.customSigningFn?SigningFnOverrides auth token signing and disables automatic signing key generation. Custom auth public keys can be registered with Privy via the console.
options.kmsURL?stringThe URL of the Privy KMS. Defaults to https://kms.privy.io/v0.
options.timeout?numberTime in milliseconds after which to timeout requests to the API and KMS. Defaults to 10000 (10 seconds).

Overridesโ€‹

PrivyConfig.constructor

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:61

Methodsโ€‹

addRequestersToRoleโ€‹

โ–ธ addRequestersToRole(roleId, requesterIds): Promise<string[]>

Assign the given role to a list of requesters.

Parametersโ€‹

NameTypeDescription
roleIdstringThe id of the role.
requesterIdsstring[]A list of requester ids to assign the role.

Returnsโ€‹

Promise<string[]>

Inherited fromโ€‹

PrivyConfig.addRequestersToRole

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:582


createAccessGroupโ€‹

โ–ธ createAccessGroup(attributes): Promise<AccessGroup>

Create an access group.

Parametersโ€‹

NameType
attributesCreateAccessGroupRequest

Returnsโ€‹

Promise<AccessGroup>

Inherited fromโ€‹

PrivyConfig.createAccessGroup

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:450


createAccessTokenโ€‹

โ–ธ createAccessToken(requesterId): Promise<string>

Generate a Privy access token for the given data requester.

Parametersโ€‹

NameTypeDescription
requesterIdstringData requester user ID.

Returnsโ€‹

Promise<string>

Inherited fromโ€‹

PrivyConfig.createAccessToken

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:282


createFieldโ€‹

โ–ธ createField(attributes): Promise<Field>

Create a field.

Parametersโ€‹

NameType
attributesCreateFieldRequest

Returnsโ€‹

Promise<Field>

Inherited fromโ€‹

PrivyConfig.createField

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:306


createRoleโ€‹

โ–ธ createRole(attributes): Promise<Role>

Create a role.

Parametersโ€‹

NameType
attributesCreateRoleRequest

Returnsโ€‹

Promise<Role>

Inherited fromโ€‹

PrivyConfig.createRole

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:376


decryptAndVerifyโ€‹

โ–ธ decryptAndVerify(field, ciphertext, integrityHash): Promise<Uint8Array>

Parametersโ€‹

NameType
fieldEncryptedUserDataResponseValue
ciphertextUint8Array
integrityHashstring

Returnsโ€‹

Promise<Uint8Array>

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:575


decryptBatchKeysโ€‹

โ–ธ decryptBatchKeys(request): Promise<(null | Uint8Array)[][]>

Calls the KMS to decrypt the given data keys.

Parametersโ€‹

NameTypeDescription
requestDataKeyBatchRequestThe DataKeyBatchRequest to send to the KMS.

Returnsโ€‹

Promise<(null | Uint8Array)[][]>

2-D Array of decrypted batch keys ordered by the same ordering of user, field as the request, mapping to the decrypted key if it exists or null otherwise.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:636


decryptKeysโ€‹

โ–ธ decryptKeys(request): Promise<Uint8Array[]>

Parametersโ€‹

NameType
requestDataKeyUserRequest

Returnsโ€‹

Promise<Uint8Array[]>

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:621


delโ€‹

โ–ธ del(userId, fields): Promise<void>

Delete a field of data for a given user.

await client.del("0x123", "email");

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user.
fieldsstringThe field to delete.

Returnsโ€‹

Promise<void>

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:230

โ–ธ del(userId, fields): Promise<void>

Delete multiple fields of data for a given user.

await client.del("0x123", ["email", "name"]);

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user.
fieldsstring[]The list of fields to delete.

Returnsโ€‹

Promise<void>

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:241


deleteAccessGroupโ€‹

โ–ธ deleteAccessGroup(accessGroupId): Promise<void>

Delete an access group Default access groups cannot be deleted.

Parametersโ€‹

NameTypeDescription
accessGroupIdstringThe id of the access group.

Returnsโ€‹

Promise<void>

Inherited fromโ€‹

PrivyConfig.deleteAccessGroup

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:502


deleteFieldโ€‹

โ–ธ deleteField(fieldId): Promise<void>

Delete a field.

Parametersโ€‹

NameTypeDescription
fieldIdstringUnique alphanumeric identifier for the field.

Returnsโ€‹

Promise<void>

Inherited fromโ€‹

PrivyConfig.deleteField

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:348


deleteRoleโ€‹

โ–ธ deleteRole(roleId): Promise<void>

Delete a role. Default roles cannot be deleted.

Parametersโ€‹

NameTypeDescription
roleIdstringUnique alphanumeric identifier for the role.

Returnsโ€‹

Promise<void>

Inherited fromโ€‹

PrivyConfig.deleteRole

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:420


โ–ธ delink(userId, alias): Promise<void>

Delinks a particular user id alias from any other user id's it's linked to. If it is not linked to any other user id, an error is thrown.

Parametersโ€‹

NameTypeDescription
userIdstringA user id that the alias is initially linked to.
aliasstringThe user id to be delinked from the bundle.

Returnsโ€‹

Promise<void>

AliasBundle if everything succeeds. Otherwise an error is thrown.

Inherited fromโ€‹

PrivyConfig.delink

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:242


fetchAliasesโ€‹

โ–ธ fetchAliases(userId): Promise<AliasBundle>

Reads and decrypts the aliases a given user id is linked to.

Parametersโ€‹

NameTypeDescription
userIdstringAny user id within the alias bundle.

Returnsโ€‹

Promise<AliasBundle>

AliasBundle if everything succeeds. Otherwise an error is thrown.

Inherited fromโ€‹

PrivyConfig.fetchAliases

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:264


getโ€‹

โ–ธ get(userId, fields): Promise<null | FieldInstance>

Get a single field of user data from the Privy API.

const email = await client.get("0x123", "email");

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user this data belongs to.
fieldsstringString field name.

Returnsโ€‹

Promise<null | FieldInstance>

A FieldInstance if the field exists, or null otherwise.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:120

โ–ธ get(userId, fields): Promise<(null | FieldInstance)[]>

Get multiple fields of user data from the Privy API.

const [firstName, lastName] = await client.get("0x123", ["first-name", "last-name"]);

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user this data belongs to.
fieldsstring[]Array of string field names.

Returnsโ€‹

Promise<(null | FieldInstance)[]>

Array of results in the same order as the input. Each result is a FieldInstance if the field exists or null otherwise.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:132


getAccessGroupโ€‹

โ–ธ getAccessGroup(accessGroupId): Promise<AccessGroup>

Retrieve an access group.

Parametersโ€‹

NameTypeDescription
accessGroupIdstringThe id of the access group.

Returnsโ€‹

Promise<AccessGroup>

Inherited fromโ€‹

PrivyConfig.getAccessGroup

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:463


getBatchโ€‹

โ–ธ getBatch(fields, options?): Promise<BatchFieldInstances>

Get a batch of admin-accessible user data from the Privy API, indexed by user ID.

Parametersโ€‹

NameTypeDescription
fieldsstring | string[]-
optionsBatchOptionsOptional object containing batch request configuration.

Returnsโ€‹

Promise<BatchFieldInstances>

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:156


getByIntegrityHashโ€‹

โ–ธ getByIntegrityHash(integrityHash): Promise<null | FieldInstance>

Lookup a field instance by its integrity hash. This method can be used to verify data in addition to fetching it from Privy. For example, this method will:

  1. Lookup data by integrity hash
  2. Return the field instance if it exists
  3. Re-compute the integrity hash client side. If it is NOT the same as the integrityHash argument, this method will throw an error.
const ssn = await client.put("0x123", "ssn", "123-45-6789");
const ssnIntegrityHash = ssn.integrity_hash;

// later on...
const ssn = await client.getByIntegrityHash(ssnIntegrityHash);

Parametersโ€‹

NameTypeDescription
integrityHashstringHash used for content addressing.

Returnsโ€‹

Promise<null | FieldInstance>

The corresponding FieldInstance if it exists, or null otherwise.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:403


getFieldโ€‹

โ–ธ getField(fieldId): Promise<Field>

Retrieve a field.

Parametersโ€‹

NameTypeDescription
fieldIdstringUnique alphanumeric identifier for the field.

Returnsโ€‹

Promise<Field>

Inherited fromโ€‹

PrivyConfig.getField

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:319


getFileโ€‹

โ–ธ getFile(userId, field): Promise<null | FieldInstance>

Download a file stored under a field.

const avatar = await client.getFile("0x123", "avatar");
download(avatar);

function download(field: FieldInstance) {
const data = window.URL.createObjectURL(field.blob());

// Lookup extension by mime type (included on blob)
const ext = getExtensionFromMIMEType(blob.type);
const filename = `${field.integrity_hash}.${ext}`;

// Create a link pointing to the ObjectURL containing the blob.
const link = document.createElement("a");
link.style = "display: none;";
link.href = data;
link.download = filename;
link.click();

// Cleanup
window.URL.revokeObjectURL(data);
link.remove();
}

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user this file belongs to.
fieldstringThe field the file is stored under.

Returnsโ€‹

Promise<null | FieldInstance>

A FieldInstance if the file exists, or null otherwise.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:283


getRequesterRolesโ€‹

โ–ธ getRequesterRoles(requesterId): Promise<string[]>

Get all the roles assigned to the requester.

Parametersโ€‹

NameTypeDescription
requesterIdstringThe id of the requester.

Returnsโ€‹

Promise<string[]>

Inherited fromโ€‹

PrivyConfig.getRequesterRoles

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:551


getRoleโ€‹

โ–ธ getRole(roleId): Promise<Role>

Retrieve a role.

Parametersโ€‹

NameTypeDescription
roleIdstringUnique alphanumeric identifier for the role.

Returnsโ€‹

Promise<Role>

Inherited fromโ€‹

PrivyConfig.getRole

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:389


getRoleRequestersโ€‹

โ–ธ getRoleRequesters(roleId): Promise<string[]>

Get all the requesters assigned to the given role id.

Parametersโ€‹

NameTypeDescription
roleIdstringThe id of the role.

Returnsโ€‹

Promise<string[]>

Inherited fromโ€‹

PrivyConfig.getRoleRequesters

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:566


getUserPermissionsโ€‹

โ–ธ getUserPermissions(userId, fieldIds?): Promise<UserPermission[]>

Get the permissions required for accessing a given user's data.

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user to fetch permissions for.
fieldIds?string[]Optional list of field ids to scope the request to.

Returnsโ€‹

Promise<UserPermission[]>

Inherited fromโ€‹

PrivyConfig.getUserPermissions

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:516


getWrapperKeysโ€‹

โ–ธ getWrapperKeys(userId, fields, algorithm): Promise<{ algorithm: string ; id: Uint8Array ; publicKey: Uint8Array }[]>

Parametersโ€‹

NameType
userIdstring
fieldsstring[]
algorithmstring

Returnsโ€‹

Promise<{ algorithm: string ; id: Uint8Array ; publicKey: Uint8Array }[]>

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:601


โ–ธ link(userId, alias): Promise<AliasBundle>

Links a new user id alias to an pre-existing user id.

Parametersโ€‹

NameTypeDescription
userIdstringA user id for which data already exists.
aliasstringA new user id to be linked to the pre-existing user id. No data should previously exist for this new user id.

Returnsโ€‹

Promise<AliasBundle>

AliasBundle containing the id's of all users that are linked together.

Inherited fromโ€‹

PrivyConfig.link

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:205


listAccessGroupsโ€‹

โ–ธ listAccessGroups(): Promise<AccessGroup[]>

List all access groups. Retrieves all the defined access groups for this account.

Returnsโ€‹

Promise<AccessGroup[]>

Inherited fromโ€‹

PrivyConfig.listAccessGroups

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:433


listFieldsโ€‹

โ–ธ listFields(): Promise<Field[]>

List all fields.

Returnsโ€‹

Promise<Field[]>

Inherited fromโ€‹

PrivyConfig.listFields

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:290


listRolesโ€‹

โ–ธ listRoles(): Promise<Role[]>

List all roles. Retrieves all the defined roles for this account.

Returnsโ€‹

Promise<Role[]>

Inherited fromโ€‹

PrivyConfig.listRoles

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:361


putโ€‹

โ–ธ put(userId, field, value): Promise<FieldInstance>

Updates data for a single field for a given user.

const email = await client.put("0x123", "email", "foo@example.com");

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user this data belongs to.
fieldstringString field name.
valuestringValue to save.

Returnsโ€‹

Promise<FieldInstance>

FieldInstance of the updated field.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:183

โ–ธ put(userId, fields): Promise<FieldInstance[]>

Updates data for multiple fields for a given user.

const [firstName, lastName] = await client.put("0x123", [
{field: "first-name", value: "Jane"},
{field: "last-name", value: "Doe"},
]);

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user this data belongs to.
fieldsUpdateFieldInstanceRequest[]Array of objects with field and value keys.

Returnsโ€‹

Promise<FieldInstance[]>

Array of FieldInstances of the updated fields, in the same order as the input.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:198


putFileโ€‹

โ–ธ putFile(userId, field, plaintext, contentType): Promise<FieldInstance>

Upload a file for a given field.

const onUpdateAvatar = async (avatar: File) => {
try {
await client.putFile("0x123", "avatar", avatar);
} catch (error) {
console.log(error);
}
};

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user this file belongs to.
fieldstringThe field to store the file in.
plaintextBuffer-
contentTypestring-

Returnsโ€‹

Promise<FieldInstance>

FieldInstance for the uploaded file.

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:333


removeRequesterFromRoleโ€‹

โ–ธ removeRequesterFromRole(roleId, requesterId): Promise<void>

Remove the requester from the given role.

Parametersโ€‹

NameTypeDescription
roleIdstringThe id of the role.
requesterIdstringThe requester to remove from the role.

Returnsโ€‹

Promise<void>

Inherited fromโ€‹

PrivyConfig.removeRequesterFromRole

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:599


sendEmailโ€‹

โ–ธ sendEmail(userId, subject, htmlContent, fields?): Promise<void>

Sends an email to a given user ID with the subject and HTML specified.

Optionally, if you would like to incorporate user data into the email, you may do so using the Handlebars templating format. Embed the field IDs corresponding to desired values into the HTML content and update the fields param to include those fields.

For example, if you include fields=["username"], you can then use this in your htmlContent like so: htmlContent="Hello {{username}}, ..."

precondition In order for sendEmail to work, a valid destination email must already be stored for the input user userId in a field with the field ID email.

Parametersโ€‹

NameTypeDescription
userIdstringUser ID
subjectstringSubject of the email
htmlContentstringHTML content to send. If any handlebars content is included, it will be replaced using the fields provided before sending.
fields?string | string[]Single field ID or an array of field IDs to dynamically include in the email using Handlebars. Files, such as images, are not yet supported.

Returnsโ€‹

Promise<void>

Defined inโ€‹

privy-js/packages/privy-node/src/client.ts:760


updateAccessGroupโ€‹

โ–ธ updateAccessGroup(accessGroupId, attributes): Promise<AccessGroup>

Update an access group. Default access groups cannot be updated.

Parametersโ€‹

NameTypeDescription
accessGroupIdstringThe id of the access group.
attributesUpdateAccessGroupRequest

Returnsโ€‹

Promise<AccessGroup>

Inherited fromโ€‹

PrivyConfig.updateAccessGroup

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:482


updateFieldโ€‹

โ–ธ updateField(fieldId, attributes): Promise<Field>

Update a field.

Parametersโ€‹

NameType
fieldIdstring
attributesUpdateFieldRequest

Returnsโ€‹

Promise<Field>

Inherited fromโ€‹

PrivyConfig.updateField

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:335


updateRoleโ€‹

โ–ธ updateRole(roleId, attributes): Promise<Role>

Update a role. Default roles cannot be updated.

Parametersโ€‹

NameTypeDescription
roleIdstringUnique alphanumeric identifier for the role.
attributesUpdateRoleRequest

Returnsโ€‹

Promise<Role>

Inherited fromโ€‹

PrivyConfig.updateRole

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:406


updateUserPermissionsโ€‹

โ–ธ updateUserPermissions(userId, permissions): Promise<UserPermission[]>

Update the permissions required for accessing a given user's data.

Parametersโ€‹

NameTypeDescription
userIdstringThe id of the user to fetch permissions for.
permissionsUserPermission[]A list of permissions objects.

Returnsโ€‹

Promise<UserPermission[]>

Inherited fromโ€‹

PrivyConfig.updateUserPermissions

Defined inโ€‹

privy-js/packages/privy-node/src/config.ts:532