UNPKG

@safient/core

Version:

JavaScript SDK to manage safes and interact with Safient protocol.

229 lines (228 loc) 9.05 kB
import { TransactionReceipt, TransactionResponse } from "@ethersproject/providers"; import { Types } from "@safient/contracts"; import { User, UserMeta, Safe, Signer, SafeStore, EventResponse } from "./lib/types"; import { DatabaseType, NetworkType } from "./lib/enums"; import { SafientResponse } from "./lib/services"; export declare class SafientCore { /** @ignore */ private signer; /** @ignore */ private contract; /**@ignore */ private arbitrator; /** @ignore */ private userData; /** @ignore */ private connection; /** @ignore */ private crypto; /** @ignore */ private database; /** @ignore */ private databaseType; /** @ignore */ private Utils; /** @ignore */ private auth; /** @ignore */ private signature; /**@ignore */ private apiKey; /**@ignore */ private apiSecret; /**@ignore */ private threadId; /**@ignore */ private chainId; /**@ignore */ private CERAMIC_URL; /**@ignore */ private ceramicDefintions; /**@ignore */ private guardianFee; /** * Constructor to initilize the Core SDK * @param signer Signer object of the provider for user authentication * @param network The type of network from NetworkType Enum * @param databaseType Type of database to use (Optional) * @param databaseAPIKey Database API key (Optional) * @param databaseAPISecret Database API secret (Optional) * @param threadId ThreadDB ID if its available (Optional) */ constructor(network?: NetworkType, databaseType?: DatabaseType, databaseAPIKey?: any, databaseAPISecret?: any, threadId?: number[]); /** * @param signer Signer object of the provider for user authentication * @returns Connection datatype */ loginUser: (signer: Signer) => Promise<SafientResponse<User>>; /** * This API registers users onto the platform * @param signer Signer object of the provider for user authentication * @param details.name Name of the user (Optional) * @param details.email Email of the user (Optional) * @param guardian If the user is a guardian * @returns User registration ID */ createUser: (signer: Signer, details?: { name: string; email: string; } | undefined, guardian?: boolean) => Promise<SafientResponse<User>>; /** * This API is used to get the login information of the user * @param obj Takes email or did as parameter to get the user information * @returns User or null based on user information present */ getUser: (obj: { email?: string; did?: string; }) => Promise<SafientResponse<User>>; /** * This API is used to get all the user basic information on the platform * @returns Array of users on the platform */ getUsers: () => Promise<SafientResponse<UserMeta[]>>; /** * This API is used to select random guardians from the platform for a safe * @ignore * @param creatorDID DID of the safe creator * @param beneficiaryDID DID of the safe beneficiary * @returns Array of guardian DIDs */ private randomGuardians; /** * This API is used to create a safe either onChain or offChain * @param beneficiary.did DID of the user who inherits/ claims the safe * @param beneficiary.email Email of the user who inherits/ claims the safe * @param safeData Data being stored in the safe * @param onChain The data to be stored onChain or offChain while creating the safe * @param persist Flag to replicate the safe metadata to IPFS * @param claimDetails.type The claim type to recover the safe of type ClaimType * @param claimDetails.period signaling period or dDay timestamp for the claim * @returns ID generated for the Safe */ createSafe: (safeData: SafeStore, beneficiary?: { email?: string | undefined; did?: string | undefined; } | undefined, claimDetails?: { type: number; period: number; } | undefined, safeDetails?: { name?: string | undefined; description?: string | undefined; } | undefined, onChain?: boolean, persist?: boolean) => Promise<SafientResponse<EventResponse>>; /** * This API returns the data of the safe * @param safeId ID of the safe being queried * @returns Encrypted Safe Data */ getSafe: (safeId: string) => Promise<SafientResponse<Safe>>; /** * This API allows for safe claiming for the beneficiary * @param safeId ID of the safe being claimed * @param details.file Evidence submitted with the claim (Application only for Arbitration based claims) * @param details.evidenceName Name of the evidence (Application only for Arbitration based claims) * @param details.description Decscription of the evidence and claim being submitted (Application only for Arbitration based claims) * @returns Dispute Number generated for the claim */ createClaim: (safeId: string, details?: { file: any; evidenceName: string; description: string; } | undefined) => Promise<SafientResponse<EventResponse>>; /** * This API is called by guardians when they have to recover the safe they are part of * @ignore * @param safeId ID of the safe being recovered * @param did DID of the guardian * @returns True of False based on the recovery process */ reconstructSafe: (safeId: string, did: string) => Promise<SafientResponse<boolean>>; /** * This API is for creator of the safe to recover safe data * @param safeId ID of the safe being recovered * @returns Decrypted Safe Data */ recoverSafeByCreator: (safeId: string) => Promise<SafientResponse<any>>; /** * This API updates the stages for a safe * @ignore * @param safeId ID of the safe being updated * @param claimStage The stage of the claim * @param safeStage The stage of the safe * @returns True or False based on update process */ private updateStage; /** * This API decryptes safe data and enables recovery for the Beneficiary of the safe * @param safeId ID of the safe being recovered * @param did DID of the beneficiary * @returns Decrypted Safe Data */ recoverSafeByBeneficiary: (safeId: string, did: string) => Promise<any>; /** * This function is used to get onChain safe data * @param safeId ID of the safe * @returns onChain Safe Data */ getOnChainData: (safeId: string) => Promise<Types.Safe>; /** * This API gets claim data for the safe from onChain * @param claimId onChain claimId * @returns Claim information */ getOnChainClaimData: (claimId: number) => Promise<Types.Claim>; /** * This API get's status of the claim * @param safeId ID of the safe * @param claimId Claim/Dispute ID of the safe * @returns The status of the safe claim */ getClaimStatus: (safeId: string, claimId: number) => Promise<Types.ClaimStatus>; /** * This API syncs onChain and offChain stages of the safe * @ignore * @param safeId ID of the safe. * @returns True or False based on the sync process */ syncStage: (safeId: string) => Promise<SafientResponse<boolean>>; /** * @ignore * Disclaimer: Internal API only. Not production API * Use at your loss * If you reading this code and come across this, be warned not to use this at all * */ giveRuling: (disputeId: number, ruling: number) => Promise<SafientResponse<boolean>>; /** * The API is used to send signal to the safe onChain * @param safeId ID of the safe * @returns Transaction details of the signal */ createSignal: (safeId: string) => Promise<SafientResponse<TransactionReceipt>>; /** * This API is used by guardians to claim the incentivisation * @ignore * @param safeId ID of the safe * @returns True or false based on the incentivisation process */ incentiviseGuardians: (safeId: string) => Promise<SafientResponse<boolean>>; /** * This function returns the total guardian reward balance of a guardian * @param address The address of the guardian * @returns The total guardian reward balance in ETH */ getRewardBalance: (address: string) => Promise<SafientResponse<Number>>; /** * @ignore * This function allows the guardians to claim their rewards * @param funds Total funds need to be claimed in ETH * @returns A transaction response */ claimRewards: (funds: number) => Promise<TransactionResponse>; /** * This function updates the D-Day of a safe * @param safeId ID of the safe * @param dDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe * @returns A transaction response */ updateDDay: (safeId: string, dDay: number) => Promise<TransactionResponse>; }