@investorid/identity-sdk
Version:
Interact with BlockChain Identities.
125 lines (124 loc) • 5.63 kB
TypeScript
import { AccessGrant, AccessGrantType, AccessToken, ClaimData, ClaimObject, ClaimStatus, ClaimType } from './Claim.interface';
import { SignerModuleInterface } from '../core/SignerModule';
import { HexString } from '../core/utils/Utils';
export declare class Claim implements ClaimObject {
address?: string;
data?: string;
hash?: string;
id?: string;
issuanceDate?: Date;
emissionDate?: Date;
issuer?: string;
privateData?: object;
publicData?: object;
scheme?: number;
signature?: string;
status?: ClaimStatus;
type?: number;
uri?: string;
/**
* Standardize a Claim Issuer provider response for a claim.
* Even if the standard is to return camelCase properties, some may return snake_case.
* @param data
*/
private static standardizeProviderResponse;
/**
* Generate the hash of a claim using the provided data.
* @param type
* @param emissionDate
* @param publicData
* @param privateData
*/
static generateHash(type: ClaimType, emissionDate: Date, publicData: object, privateData: object): string;
static generateBlockchainHash(address: string, topic: number, data: string): string;
/**
* Instantiate a new claim from an URI.
* @param uri
*/
static createFromURI(uri: string): Promise<ClaimObject>;
/**
* Generate the blockchain hash of a claim and signs it with the provided signer or the default signer of the SDK.
* @param type
* @param address
* @param data
* @param [signer]
* @returns Claim signature.
*/
static sign(type: ClaimType, address: string, data: HexString, signer?: SignerModuleInterface): Promise<string>;
/**
* Verify the signature of a claim.
* The standard signature of a claim is the keccak256 hash of (identityAddress, type, data) prefixed and signed.
* The data argument is exactly the content of the data claim field stored in blockchain (caution to hex padding).
* Data is expected to be an hexString.
* Using the IdentitySDK, call `IdentitySDK.utils.toHex('data')`.
* Using web3utils, call `web3utils.asciiToHex('data)`.
* Using ethersjs, call `Ethers.utils.hexlify(Ethers.utils.toUtf8Bytes('data'))`
* @param signingKey
* @param type
* @param address Address of identity contract.
* @param data
* @param signature
*/
static verifySignature(signingKey: string, type: ClaimType, address: string, data: string, signature: string): Promise<boolean>;
/**
* Create a new Claim Object from a ClaimData (got from BlockChain Identity Contract).
* Use #.createFromURI() to fetch from an URI.
* @param claim
*/
constructor(claim?: ClaimData);
/**
* Complete an AccessGrant challenge to validate a PERSISTENT grant or obtain an access token with an IMMEDIATE grant.
* @param accessGrant
* @param [signer] Signer to sign the challenge if signature is not provided in accessGrant.
*/
completeAccessChallenge(accessGrant: AccessGrant, signer?: SignerModuleInterface): Promise<AccessGrant | AccessToken>;
/**
* Retrieve public data of the claim.
* Will fetch a GET on the Claim URI, with ?private_data=true&access_token=<...>.
* Use the .requestAccessToken() method to get an Access Token, and .requestAccess() to request access to the claim data.
* @param accessToken
*/
getPrivateData(accessToken: string): Promise<object>;
/**
* Retrieve public data of the claim.
* Will fetch a GET on the Claim URI.
*/
getPublicData(): Promise<object>;
/**
* Generate the hash of the claim data if it was populated with private data.
* If all data are not provided as arguments, data fromm the Claim object will be used.
* Note that to verify a claim complete data, you will obviously need to have access to its private data.
* Use the .populate() method to fetch all the public and private data if available.
* @param type
* @param emissionDate
* @param publicData
* @param privateData
*/
generateHash(type?: ClaimType, emissionDate?: Date, publicData?: object, privateData?: object): string;
/**
* Request access to a Claim private data.
* If the signer already possess a persistent Access Grant, this should return the existing access grant to request access token with.
* To require a PERSISTENT access grant, the signer is required. It must expose the getPublicKey() function.
* @param accessType
* @param signer Required if access grant type is PERSISTENT.
*/
requestAccess(accessType?: AccessGrantType, signer?: SignerModuleInterface): Promise<AccessGrant>;
/**
* Use a confirmed AccessGrant to obtain an AccessToken.
* @param accessGrant
* @param signer
*/
requestAccessToken(accessGrant: AccessGrant, signer: SignerModuleInterface): Promise<AccessToken>;
/**
* Populate Claim Object with public and eventually private data.
* Getting the private data requires an accessToken.
* @param accessToken
*/
populate(accessToken?: string): Promise<void>;
/**
* Sign the claim.
* It will update the signature property of the claim. The signature can only be generated for a claim that as a type, an address and data.
* @param signer Signer module to use. If null, use default signer of SDK.
*/
sign(signer?: SignerModuleInterface): Promise<string>;
}