Skip to main content

Class: IdentityClient

Implements

Constructors

new IdentityClient()

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.compilot.ai as the ComPilot 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 = ...

props.type: "getCredentials" = ...

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;isAuthorized: true;payload: string;signature: EIP155Signature; } | {errorMessage: any;isAuthorized: false; }>

Used to retrieve a signature from the ComPilot 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: the block number after which the request is considered expired.
  • signature: 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;isAuthorized: true;payload: string;signature: EIP155Signature; } | {errorMessage: any;isAuthorized: false; }>

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
);

getTxAuthSignatureTezos()

getTxAuthSignatureTezos(input: Omit\<{args: string;blockExpiration: number;chainID: TezosChainId;contractAddress: TezosContractAddress;functionName: TezosEntrypointName;nonce: number;userAddress: TezosImplicitAddress; }, "userAddress">): Promise\<{blockExpiration: number;isAuthorized: true;signature: EdSignature; } | {errorMessage: any;isAuthorized: false; }>

Used to retrieve a signature from the ComPilot API to authorize a contract call gated with the Tezos smart contract gating.

It returns a signatureResponse object that has three properties:

  • isAuthorized: boolean. True if this customer is authorized.
  • blockExpiration: the block number after which the request is considered expired.
  • signature: 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.

getTxAuthSignatureTezos has one argument, a tezosTxAuthInput object with the following properties.

PropertyDescription
contractAddressThe address of the gated smart contract
functionNameThe name of the function in the gated smart contract
argsA string containing the input for the function as bytes
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: string;blockExpiration: number;chainID: TezosChainId;contractAddress: TezosContractAddress;functionName: TezosEntrypointName;nonce: number;userAddress: TezosImplicitAddress; }, "userAddress">

Returns

Promise\<{blockExpiration: number;isAuthorized: true;signature: EdSignature; } | {errorMessage: any;isAuthorized: false; }>


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

For some examples, see init examples.

Parameters

authenticationInputs: IdentityAuthenticationInputs

Returns

Promise\<void>


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;
};
)

Implementation of

IIdentityClient.onCloseScreen


onScenarioExecution()

onScenarioExecution(onScenarioExecutionCallback: (data: {data: SdkVerificationResponseSchema;type: "RuleEngineScenarioExecution"; } | {data: {address: null | string;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;workflowSessionId: string; }[];type: "OffChainScenarioExecution"; } | {data: any;type: "OnChainScenarioExecution"; }) => void): void

Callback function. Called when a scenario is executed by the ComPilot 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.

This must be emitted before you use init.

Parameters

onSdkReadyCallback

Returns

void

Example

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

onSendTransaction()

onSendTransaction(sendTransactionCallback: (data: {accountAddress: BlockchainAddress;data: String0x;to: BlockchainAddress;value: string; }) => Promise\<undefined | `0x${string}`>): void

Callback function. Used to sign transactions on the on-chain ZKP allowlist system.

The ZKPs and associated transaction data is prepared in the identity app by making a call to the API to get the ZKPrequests and creating the ZKP using the PolygonID Wallet.

Then, the transaction is signed and sent using this callback. to be registered by client to send transaction.

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.

This needs to be registered by the integrator. It requires a function that will provide a signature from the connected wallet.

Parameters

signMessageCallback

Returns

void

Example

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

Implementation of

IIdentityClient.onSignMessage


onVerification()

onVerification(onVerification: (isVerified: boolean) => void): void

Callback function. Called when any type of verification happens (ZKP or ComPilot Rules Engine).

Parameters

onVerification

Returns

void

Example

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

polygonIdRequest()

polygonIdRequest(data: {authRequest: AuthorizationRequestMessage;type: "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 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 ZeroKnowledgeProofRequest: generates a zk-request for the given inputs
ArgumentRequiredDescription
typeYesRequest type; can be auth, zkp, or credentialOffer
zkpRequestNoSet to zkpRequest when type is zkp
note

The examples follow the Iden3comm standard.

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 have any arguments.

tip

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

When flow is completed, a response is sent to the webhooks.

After the flow is completed, you should tell the customer of your decision and proceed with the transaction if appropriate.

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 have any arguments.

tip

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

When flow is completed, a response is sent to the webhooks.

After the flow is completed, you should tell the customer of your decision and proceed with the transaction if appropriate.

See line 32 and line 73 in IdentityFlow.tsx for examples.

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>;