IdentityClient

Class: IdentityClient

Implements

  • IIdentityClient

Constructors

new IdentityClient(config?: IdentityClientConfig): IdentityClient

  • Constructs a new IdentityClient object.

Parameters

  • config?: IdentityClientConfig
    • Optional configuration object for the IdentityClient. See IdentityClientConfig for further details. If env is not defined, prod is used as default, using https://identity.nexera.id as Nexera KYC app.

Returns

  • IdentityClient

Properties

polygonIdDID?

  • optional: polygonIdDID: string

Methods

close()

close(): void
  • Closes the Identity SDK.

Returns

  • void

Example

IDENTITY_CLIENT.close();

getStoredCredentials()

getStoredCredentials(props: {data: undefined;type: "getCredentials"; }): Promise<{id: string;issuanceDate: string;journeyId: string;type: string[]; }[]>
  • Returns the stored credentials of the connected wallet.
ArgumentRequiredDescription
typeYesAlways set to getCredentials
dataYesAlways set to undefined

Parameters

  • props
    • props.data?: undefined= undefined
    • props.type: "getCredentials"= undefined

Returns

  • Promise<{id: string;issuanceDate: string;journeyId: string;type: string[]; }[]>

Example

const credentials = await IDENTITY_CLIENT.getStoredCredentials(
  { type: "getCredentials", data: undefined }, // data will be able to add filters later
);

getTxAuthSignature()

getTxAuthSignature(input: Omit<{args: unknown[];blockExpiration: number;chainId: EvmChainId;contractAbi: Record<string, unknown>[];contractAddress: AddressSchema;functionName: string;nonce: number;userAddress: AddressSchema; }, "userAddress">): Promise<{blockExpiration: number;errorMessage: any;isAuthorized: boolean;payload: string;signature: `0x${string}`;signatureData: string; }>
  • Used to retrieve a signature from the Nexera API to authorize a contract call gated with the TxAuthDataSignature smart contract gating.

It returns a signatureResponse object that has three properties:

  • isAuthorized: boolean: True if this customer is authorized.
  • blockExpiration: number: The block number after which the request is considered expired.
  • signature: string: The signature.

By default, blockExpiration is 50 greater than the latest block, giving the signature a validity of 50 blocks. If you want to change this (for security or convenience, for example) you can set an explicit value for blockExpiration, as shown in the example below.

getTxAuthSignature has one argument, a txAuthInput object with the following properties:

PropertyDescription
contractAbiThe ABI for the gated smart contract
contractAddressThe address of the gated smart contract
functionNameThe name of the function in the gated smart contract
argsAn array containing the input for the function
chainIdThe ID of the chain that the tx will be posted on
blockExpirationBlock number after which the request is considered expired; optional

Parameters

  • input: Omit<{args: unknown[];blockExpiration: number;chainId: EvmChainId;contractAbi: Record<string, unknown>[];contractAddress: AddressSchema;functionName: string;nonce: number;userAddress: AddressSchema; }, "userAddress">

Returns

  • Promise<{blockExpiration: number;errorMessage: any;isAuthorized: boolean;payload: string;signature: 0x${string};signatureData: string; }>

Example

// optional blockExpiration
const blockExpiration =
  Number((await txAuthWalletClient.getBlock({ blockTag: "latest" })).number) +
  100;

// get chain ID from client
const chainId = await client.getChainId();

// Tx Auth Input
// with our example Gated NFT Minter
const txAuthInput = {
  contractAbi: ExampleGatedNFTMinterABI,
  contractAddress: ExampleGatedNFTMinterAddress,
  functionName: "mintNFTGated",
  args: [recipientAddress],
  blockExpiration,
  chainId,
};

// Get signature Response
const signatureResponse: GetTxAuthDataSignatureResponse =
  await IDENTITY_CLIENT.getTxAuthSignature(txAuthInput);

init()

init(authenticationInputs: IdentityAuthenticationInputs): Promise<void>
  • The init method receives the authorization inputs. It must be called before any flow starts.

There are several callbacks that can be used to integrate with the SDK lifecycle. They are onSignMessage, onSendTransaction, onSdkReady, onVerification, and onScenarioExecution.

Ideally, these should all be registered before calling init.

ArgumentDescriptionRequired
accessTokenThe access token from your back end serverYes
signatureSignatureYes
signingMessageSigning message, used to store the KYC data in the customer's browserYes

Parameters

  • authenticationInputs: IdentityAuthenticationInputs

Returns

  • Promise<void>

Example

await IDENTITY_CLIENT.init({
  accessToken: "your_access_token",
  signature: "your_signature",
  signingMessage: "your_signing_message",
});

onCloseScreen()

onCloseScreen(onCloseScreenCallback: () => Promise<string>): void
  • Callback function. Called when the identity modal is closed.

Parameters

  • onCloseScreenCallback

Returns

  • void

Example

public onCloseScreen = (
  onCloseScreenCallback: () => Promise<string>) => {
    this.callbacks.closeScreenCallback = onCloseScreenCallback;
  };
)

onScenarioExecution()

onScenarioExecution(onScenarioExecutionCallback: (data: {data: SdkVerificationResponseSchema;type: "RuleEngineScenarioExecution"; } | {data: {address: BlockchainAddress;executionId: UuidString;projectId: string;query: QueryConfigSimplified;requestMessage: AuthorizationRequestMessage;responseMessage: null | {body: {did_doc: any;message: string;scope: {circuitId: string;id: number;proof: ProofData;pub_signals: ...[];vp: any; }[]; };from: string;id: string;thid: string;to: string;typ: ZKPMessage | PlainMessage | SignedMessage;type: string; };scenarioId: string;scenarioName: string;sessionId: UuidString;status: "pending" | "authorised" | "unauthorised";verificationError: null | string; }[];type: "OffChainScenarioExecution"; } | {data: any;type: "OnChainScenarioExecution"; }) => void): void
  • Callback function. Called when a scenario is executed by the NexeraID Rules Engine.

Parameters

  • onScenarioExecutionCallback

Returns

  • void

Example

IDENTITY_CLIENT.onScenarioExecution((data) => {});

onSdkReady()

onSdkReady(onSdkReadyCallback: (data: {did: string; }) => void): void
  • Callback function. Called when the SDK is ready. onSdkReady means that the Polygon ID wallet is ready and the blockchain client and SDK are set up.

Parameters

  • onSdkReadyCallback

Returns

  • void

Example

IDENTITY_CLIENT.onSdkReady((data) => {
  setDID(data.did);
});

onSendTransaction()

onSendTransaction(sendTransactionCallback: (data: {accountAddress: AddressSchema;data: PrivateKey;to: AddressSchema;value: string; }) => Promise<undefined | `0x${string}`>): void
  • Callback function. Used to sign transactions on the on-chain ZKP allowlist system.

Parameters

  • sendTransactionCallback

(data: TransactionData) => Promise<txHash: string>

Returns

  • void

Example

import { useWalletClient } from "wagmi";

IDENTITY_CLIENT.onSendTransaction(async (data: TransactionData) => {
  return walletClient.sendTransaction({
    account: data.accountAddress,
    to: data.to,
    data: data.data,
    value: data.value ? parseEther(data.value) : parseEther("0"),
  });
});

onSignMessage()

onSignMessage(signMessageCallback: (data: {message: string; }) => Promise<string>): void
  • Callback function. Called when a message needs to be signed.

Parameters

  • signMessageCallback

Returns

  • void

Example

IDENTITY_CLIENT.onSignMessage(async (data: { message: string }) => {
  return await signMessageAsync({ message: data.message });
});

onVerification()

onVerification(onVerification: (isVerified: boolean) => void): void
  • Callback function. Called when any type of verification happens (ZKP or NexeraID Rules Engine).

Parameters

  • onVerification

Returns

  • void

Example

IDENTITY_CLIENT.onVerification((isVerified) => {
  setVerified(isVerified);
});

polygonIdRequest()

polygonIdRequest(data: {authRequest: AuthorizationRequestMessage;type

```javascript
: "auth"; } | {credentialOfferRequest: QrCodeLinkWithSchemaType;type: "credentialOffer"; } | {type: "zkp";zkpRequest: ZeroKnowledgeProofRequest; }): Promise<unknown>
  • Starts a PolygonId protocol flow.

Supports:

  • auth: Handles AuthorizationRequestMessage, generates a zk-request for the given inputs, and automatically calls the verify endpoint with zk-proof generated with the wallet.
  • credentialOffer: Handles CredentialOffer object in string format, adds a credential to the Polygon wallet (sent from a third party).
  • credentialRequest: Generates a zk-request for the given inputs.
ArgumentRequiredDescription
typeYesRequest type; can be auth, zkp, or credentialOffer
zkpRequestNoSet to zkpRequest when type is zkp

Parameters

  • data: {authRequest: AuthorizationRequestMessage;type: "auth"; } | {credentialOfferRequest: QrCodeLinkWithSchemaType;type: "credentialOffer"; } | {type: "zkp";zkpRequest: ZeroKnowledgeProofRequest; }

Returns

  • Promise<unknown>

Examples

// generates a zero-knowledge request for the given inputs and automatically
// calls the verify endpoint with the zero-knowledge proof generated by the wallet.

import type { AuthorizationRequestMessage } from "@unblokttechnology/nexera-id-schemas";
const authRequest: AuthorizationRequestMessage = {...}
await IDENTITY_CLIENT.polygonIdRequest(
  { type: "auth", authRequest}
);

// Generates a zero-knowledge request for the given inputs.

import type { ZeroKnowledgeProofRequest } from "@unblokttechnology/nexera-id-schemas";
const zkpRequest: ZeroKnowledgeProofRequest = {...}
await IDENTITY_CLIENT.polygonIdRequest(
  { type: "zkp", zkpRequest: zkpRequest }
);

// Handles a CredentialOffer object in string format. It adds a credential, sent from a third party, to the Polygon ID wallet.

const authRequest: string = "{...}";
await IDENTITY_CLIENT.polygonIdRequest({
  type: "credentialOffer",
  credentialOfferRequest,
});

startKYB()

startKYB(): void
  • Starts a KYB flow.

After onSdkReady is emitted, you can start the KYB flow using the startKYB method. It does not require any arguments.

Returns

  • void

Examples

// This code should be in a hook.
IDENTITY_CLIENT.onSdkReady((data) => {
  setDID(data.did);
});

// This code should be in the return statement of a react component.
<Button
  id="example-kyc-verify-link-button"
  onClick={() => {
    IDENTITY_CLIENT.startKYB();
  }}
  disabled={!did}
>
Verify
</Button>;

startVerification()

startVerification(): void
  • Starts a verification flow.

After onSdkReady is emitted, you can start the verification flow using the startVerification method. It does not require any arguments.

📘

onSdkReady means that the Polygon ID wallet is ready and the blockchain client and SDK are set up.

Returns

  • void

Examples

// This code should be in a hook.
IDENTITY_CLIENT.onSdkReady((data) => {
  setDID(data.did);
});

// This code should be in the return statement of a react component.
<Button
  id="example-kyc-verify-link-button"
  onClick={() => {
    IDENTITY_CLIENT.startVerification();
    close();
  }}
  disabled={!did}
>
Verify
</Button>;