UNPKG

@investorid/identity-sdk

Version:
159 lines (158 loc) 6.7 kB
import { Contract, Signer } from 'ethers'; import { Provider } from 'ethers/providers'; import { ParamType } from 'ethers/utils'; import { ClaimData, ClaimScheme, ClaimType } from '../claims/Claim.interface'; import { Key, KeyPurpose, KeyType } from './Key.interface'; import { ClaimHolder } from './ClaimHolder.interface'; export default class Identity implements ClaimHolder { keyHolderInstance?: Contract; claimHolderInstance?: Contract; address?: string; provider?: Provider | Signer; /** * Instantiate a new Identity with the provided address or ENS string that will be resolved. * @param addressOrENS Must be a valid Ethereum address, checksumed, all lower-case or all uppercase. * @param [provider] If provided, the identity will use this provider for all blockchain operation (unless override) instead of the SDK default provider. */ static at(addressOrENS: string, provider?: Provider): Promise<Identity>; /** * Deploy a new Identity, and return the Identity object. * The signer will pay for the deployment, and will be added in the MANAGEMENT keys. * If not given, the Signer will use the default provider from the SDK if it is defined and is a Signer. * Note that the identity will be returned with the provided Signer, thus management operation can be chained. * @param [signer] */ static deployNew(signer?: Signer): Promise<Identity>; /** * Instantiate an Identity. * @param address A valid Ethereum address (not an ENS, use `Identity#at(ens)`.). * @param provider Override the default provider of SDK, and use for all operation of this Identity. */ constructor(address: string, provider?: Provider | Signer); /** * Add a claim to an Identity. * The signature must have been signed with a keypair having the public key in the CLAIM keys of Identity. * @param claimType * @param scheme * @param issuer * @param signature * @param data * @param uri * @param [signer] */ addClaim(claimType: ClaimType, scheme: ClaimScheme, issuer: string, signature: string, data: string, uri: string, signer?: Signer): Promise<any>; /** * Add a Key to an Identity. * The Signer must have a MANAGEMENT key in the Identity. * @param key Must be a valid byte32 hex string (pass the keccak256 hash of the key string). * @param purpose Must be an integer. It is recommended to use the standard KeyPurpose enum. * @param type Must be a an integer. It is recommended to use the standard KeyType enum. * @param [signer] Blockchain signer. */ addKey(key: string, purpose: KeyPurpose, type: KeyType, signer?: Signer): Promise<any>; /** * Get ClaimData details for an Identity. * @param claimId * @param [provider] */ getClaim(claimId: string, provider?: Provider | Signer): Promise<ClaimData>; /** * Get claims details for an Identity. * @deprecated * @param claimId * @param [provider] */ getClaims(claimId: string, provider?: Provider | Signer): Promise<ClaimData[]>; /** * Get Claims details by type for an Identity. * @param claimType * @param [provider] */ getClaimsByType(claimType: ClaimType | number, provider?: Provider | Signer): Promise<ClaimData[]>; /** * Get ClaimData IDs by type for an Identity. * @param claimType * @param [provider] */ getClaimIdsByType(claimType: ClaimType | number, provider?: Provider | Signer): Promise<string[]>; /** * Get the details of a key in an Identity. * @param key * @param [provider] */ getKey(key: string, provider?: Provider | Signer): Promise<Key>; /** * Get the purpose of a key in an identity. * @param key * @param [provider] */ getKeyPurpose(key: string, provider?: Provider | Signer): Promise<KeyPurpose>; /** * Get the details of the keys contained in an Identity by purpose. * @param purpose * @param [provider] */ getKeysByPurpose(purpose: KeyPurpose, provider?: Provider | Signer): Promise<Key[]>; /** * Instantiate the Identity ClaimHolder Contract with the Identity's address. * @param [providerOrSigner] */ instantiateClaimHolder(providerOrSigner?: Provider | Signer): Promise<Contract>; /** * Instantiate the Identity KeyHolder Contract with the Identity's address. * @param [providerOrSigner] */ instantiateKeyHolder(providerOrSigner?: Provider | Signer): Promise<Contract>; /** * Instantiate an Identity with the given abi using the object's address. * @param abi * @param [providerOrSigner] */ instantiate(abi: (string | ParamType)[], providerOrSigner?: Provider | Signer): Promise<Contract>; /** * Instantiate an Identity with the given abi at a given address. * @param address * @param abi * @param [providerOrSigner] */ instantiateAtAddress(address: string, abi: (string | ParamType)[], providerOrSigner?: Provider | Signer): Promise<Contract>; /** * Check if a key has at least the given purpose. * @param key * @param purpose * @param [provider] */ keyHasPurpose(key: string, purpose: KeyPurpose, provider?: Provider | Signer): Promise<boolean>; /** * Remove a claim, provided the signer has the right to do so. * @param claimId * @param [signer] */ removeClaim(claimId: string, signer?: Signer): Promise<void>; /** * Remove a Key from an Identity. * The Signer must have a MANAGEMENT key in the Identity. * @param key Key must be a valid byte32 hex string. * @param [signer] Override the identity or default SDK signer. */ removeKey(key: string, signer?: Signer): Promise<any>; /** * Use another provider or signer to interact with the Identity. * This will reset all contract instances of the identity that will need to be instantiated once again with the new provider. * @param providerOrSigner */ useProvider(providerOrSigner: Provider | Signer): void; /** * Verify if the message was signed with a key that is authorized to perform action for this Identity. * @param message * @param signature * @param providerOrSigner */ validateSignature(message: string, signature: string, providerOrSigner?: Provider | Signer): Promise<boolean>; /** * Verify a specific claim given with full data or by ID. * @param claim Claim object or ID. * @param [provider] */ verifyClaim(claim: any | string, provider?: Provider | Signer): Promise<any>; }