@hapi.one/solana-client
Version:
Client library for Solana smart contract for #HAPI
564 lines (548 loc) • 21.9 kB
TypeScript
/// <reference types="node" />
import { PublicKey, Connection, Commitment, ConnectionConfig, Keypair, Transaction, Struct } from '@solana/web3.js';
import BN from 'bn.js';
import { Schema } from 'borsh';
declare class u8 extends BN {
static size: number;
constructor(...args: ConstructorParameters<typeof BN>);
/**
* Convert to Buffer representation
*/
toBuffer(): Buffer;
/**
* Construct a Numberu8 from Buffer representation
*/
static fromBuffer(buffer: Buffer): BN;
}
declare class u32 extends BN {
static size: number;
constructor(...args: ConstructorParameters<typeof BN>);
/**
* Convert to Buffer representation
*/
toBuffer(): Buffer;
/**
* Construct a Numberu32 from Buffer representation
*/
static fromBuffer(buffer: Buffer): BN;
}
declare class u64 extends BN {
static size: number;
constructor(...args: ConstructorParameters<typeof BN>);
/**
* Convert to Buffer representation
*/
toBuffer(): Buffer;
/**
* Construct a Numberu64 from Buffer representation
*/
static fromBuffer(buffer: Buffer): BN;
}
declare enum HapiInstruction {
CreateCommunity = 0,
UpdateCommunity = 1,
CreateNetwork = 2,
UpdateNetwork = 3,
CreateReporter = 4,
UpdateReporter = 5,
CreateCase = 6,
UpdateCase = 7,
CreateAddress = 8,
UpdateAddress = 9
}
declare enum HapiAccountType {
Uninitialized = 0,
Community = 1,
Network = 2,
Reporter = 3,
Case = 4,
Address = 5
}
declare enum ReporterType {
Inactive = 0,
Tracer = 1,
Full = 2,
Authority = 3
}
declare enum Category {
Safe = 0,
WalletService = 1,
MerchantService = 2,
MiningPool = 4,
LowRiskExchange = 8,
MediumRiskExchange = 16,
DeFi = 32,
OTCBroker = 64,
ATM = 128,
Gambling = 256,
IllicitOrganization = 512,
Mixer = 1024,
DarknetService = 2048,
Scam = 4096,
Ransomware = 8192,
Theft = 16384,
Counterfeit = 32768,
TerroristFinancing = 65536,
Sanctions = 131072,
ChildAbuse = 262144
}
declare const Categories: Category[];
declare enum CaseStatus {
Open = 0,
Closed = 1
}
declare class AddressState {
account_type: HapiAccountType;
risk: number;
case_id: u64;
category: number;
constructor(object: Partial<AddressState>);
static schema: Map<typeof AddressState, {
kind: string;
fields: string[][];
}>;
static size: number;
}
declare class Address {
accountType: HapiAccountType;
risk: number;
caseId: u64;
category: Category;
constructor(data?: Partial<Address>);
static getAddress(programId: PublicKey, networkAddress: PublicKey, address: PublicKey): Promise<[PublicKey, number]>;
static fromState(state: AddressState): Address;
static deserialize(buffer: Buffer): Address;
static retrieve(programId: PublicKey, connection: Connection, communityName: string, networkName: string, address: PublicKey): Promise<{
data: Address;
account: PublicKey;
}>;
serialize(): Uint8Array;
toState(): AddressState;
}
declare class CaseState {
account_type: number;
reporter_key: Uint8Array;
categories: number;
status: number;
name: string;
constructor(object: Partial<CaseState>);
static schema: Map<typeof CaseState, {
kind: string;
fields: (string | number[])[][];
}>;
static size: number;
}
declare class Case {
accountType: HapiAccountType;
reporterKey: PublicKey;
categories: Category[];
status: CaseStatus;
name: string;
constructor(data?: Partial<Case>);
static getAddress(programId: PublicKey, communityAddress: PublicKey, caseId: u64): Promise<[PublicKey, number]>;
static fromState(state: CaseState): Case;
static deserialize(buffer: Buffer): Case;
static retrieve(programId: PublicKey, connection: Connection, communityName: string, caseId: u64): Promise<{
data: Case;
account: PublicKey;
}>;
serialize(): Uint8Array;
toState(): CaseState;
}
declare class CommunityState {
account_type: number;
authority: Uint8Array;
name: string;
next_case_id: BN;
constructor(object: Partial<CommunityState>);
static schema: Map<typeof CommunityState, {
kind: string;
fields: (string | number[])[][];
}>;
static size: number;
}
declare class Community {
accountType: HapiAccountType;
authority: PublicKey;
nextCaseId: u64;
name: string;
static size: number;
constructor(data?: Partial<Community>);
static getAddress(programId: PublicKey, communityName: string): Promise<[PublicKey, number]>;
static getAddressSeeds(communityName: string): Uint8Array[];
static fromState(state: CommunityState): Community;
static deserialize(buffer: Buffer): Community;
static retrieve(programId: PublicKey, connection: Connection, communityName: string): Promise<{
data: Community;
account: PublicKey;
}>;
serialize(): Uint8Array;
toState(): CommunityState;
}
declare class NetworkState {
account_type: number;
name: string;
constructor(object: Partial<NetworkState>);
static schema: Schema;
static size: number;
}
declare class Network {
accountType: HapiAccountType;
name: string;
static size: number;
constructor(object?: Partial<Network>);
static getAddress(programId: PublicKey, communityAddress: PublicKey, networkName: string): Promise<[PublicKey, number]>;
static fromState(state: NetworkState): Network;
static deserialize(buffer: Buffer): Network;
static retrieve(programId: PublicKey, connection: Connection, communityName: string, networkName: string): Promise<{
data: Network;
account: PublicKey;
}>;
serialize(): Uint8Array;
toState(): NetworkState;
}
declare class ReporterState {
account_type: number;
reporter_type: number;
name: string;
constructor(object: Partial<ReporterState>);
static schema: Map<typeof ReporterState, {
kind: string;
fields: string[][];
}>;
static size: number;
}
declare class Reporter {
accountType: HapiAccountType;
reporterType: ReporterType;
name: string;
static size: number;
constructor(data?: Partial<Reporter>);
static getAddress(programId: PublicKey, communityAddress: PublicKey, reporterPubkey: PublicKey): Promise<[PublicKey, number]>;
static fromState(state: ReporterState): Reporter;
static deserialize(buffer: Buffer): Reporter;
static retrieve(programId: PublicKey, connection: Connection, communityName: string, reporterPubkey: PublicKey): Promise<{
data: Reporter;
account: PublicKey;
}>;
serialize(): Uint8Array;
toState(): ReporterState;
}
declare const HAPI_PROGRAM_ID: PublicKey;
interface HapiClientConfig {
endpoint: string | Connection;
commitment?: Commitment | ConnectionConfig;
communityName?: string;
programId?: string;
}
interface HapiViewResponse<T> {
account: PublicKey;
data: T;
}
interface HapiActionResponse<T> {
txHash: string;
account: PublicKey;
data: T;
}
interface HapiActionResponseWithMeta<T, U> {
txHash: string;
account: PublicKey;
data: T;
meta: U;
}
interface HapiClientAuthorityConfig extends HapiClientConfig {
payer: Keypair | PublicKey;
}
interface HapiClientReporterConfig extends HapiClientConfig {
payer: Keypair | PublicKey;
}
/** HAPI client to read entity data from Solana */
declare class ReaderClient {
readonly connection: Connection;
protected communityName?: string;
protected programId: PublicKey;
constructor(config: HapiClientConfig);
protected ensureCommunityName(communityName?: string): string;
/**
* Sets community name for context
* @param communityName Community name
* @returns Self
*/
switchCommunity(communityName: string): ReaderClient;
/**
* Fetch community info from blockchain
* @param communityName (Optional) The name of the community to fetch (defaults to context)
* @returns Community info
**/
getCommunity(communityName?: string): Promise<HapiViewResponse<Community>>;
/**
* Fetch network info from blockchain
* @param networkName The name of the network to fetch
* @param communityName (Optional) The name of the community to fetch network from (defaults to context)
* @returns Network info
**/
getNetwork(networkName: string, communityName?: string): Promise<HapiViewResponse<Network>>;
/**
* Fetch reporter info from blockchain
* @param reporterPubkey Public key of the reporter to fetch
* @param communityName (Optional) The name of the community to fetch reporter from (defaults to context)
* @returns Reporter info
**/
getReporter(reporterPubkey: string, communityName?: string): Promise<HapiViewResponse<Reporter>>;
/**
* Fetch case info from blockchain
* @param caseId ID of the case to fetch
* @param communityName (Optional) The name of the community to fetch case from (defaults to context)
* @returns Case info
**/
getCase(caseId: u64, communityName?: string): Promise<HapiViewResponse<Case>>;
/**
* Fetch address info from blockchain
* @param address The address to fetch info for (string for Solana addresses, Buffer for others)
* @param networkName The name of the network to which address belongs to
* @param communityName (Optional) The name of the community to fetch case from (defaults to context)
* @returns Address info
**/
getAddress(address: string | Buffer, networkName: string, communityName?: string): Promise<HapiViewResponse<Address>>;
}
/** HAPI client to operate reporter program functions on Solana */
declare class ReporterClient extends ReaderClient {
payer: Keypair | PublicKey;
get payerPublicKey(): PublicKey;
get payerKeypair(): Keypair | undefined;
constructor(config: HapiClientReporterConfig);
/**
* Create a case creation transaction that can be signed elsewhere
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param caseName The name of the case to create
* @param categories An array of categories to assign to the case
* @returns Transaction to sign
**/
createCaseTransaction(caseName: string, status: CaseStatus, categories: Category[], communityName?: string): Promise<{
transaction: Transaction;
caseId: u64;
}>;
/**
* Create and sign a case creation transaction
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param caseName The name of the case to create
* @param categories An array of categories to assign to the case
* @returns Transaction hash, account address and entity data
**/
createCase(caseName: string, status: CaseStatus, caseCategories: Category[], communityName?: string): Promise<HapiActionResponseWithMeta<Case, {
caseId: u64;
}>>;
/**
* Create a case updating transaction that can be signed elsewhere
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param caseId The ID of the case to update
* @param categories An array of categories to assign to the case
* @returns Transaction to sign
**/
updateCaseTransaction(caseId: u64, status: CaseStatus, categories: Category[], communityName?: string): Promise<{
transaction: Transaction;
}>;
/**
* Create and sign a case updating transaction
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param caseID The ID of the case to update
* @param categories An array of categories to assign to the case
* @returns Transaction hash, account address and entity data
**/
updateCase(caseId: u64, status: CaseStatus, caseCategories: Category[], communityName?: string): Promise<HapiActionResponse<Case>>;
/**
* Create an address creation transaction that can be signed elsewhere
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param networkName The name of the network of the address
* @param address Public key of the address
* @param caseId The ID of the case to assign to the address
* @param category Category to assign to the address
* @param risk Risk score to assign to the address (0 to 10)
* @returns Transaction to sign
**/
createAddressTransaction(networkName: string, address: PublicKey, caseId: u64, category: Category, risk: number, communityName?: string): Promise<{
transaction: Transaction;
}>;
/**
* Create and sign a address creation transaction
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param networkName The name of the network of the address
* @param address Public key of the address
* @param caseId The ID of the case to assign to the address
* @param category Category to assign to the address
* @param risk Risk score to assign to the address (0 to 10)
* @returns Transaction hash, account address and entity data
**/
createAddress(networkName: string, address: PublicKey, caseId: u64, category: Category, risk: number, communityName?: string): Promise<HapiActionResponse<Address>>;
/**
* Create an address updating transaction that can be signed elsewhere
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param networkName The name of the network of the address
* @param address Public key of the address
* @param caseId The ID of the case to assign to the address
* @param category Category to assign to the address
* @param risk Risk score to assign to the address (0 to 10)
* @returns Transaction to sign
**/
updateAddressTransaction(networkName: string, address: PublicKey, caseId: u64, category: Category, risk: number, communityName?: string): Promise<{
transaction: Transaction;
}>;
/**
* Create and sign a address updating transaction
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @param networkName The name of the network of the address
* @param address Public key of the address
* @param caseId The ID of the case to assign to the address
* @param category Category to assign to the address
* @param risk Risk score to assign to the address (0 to 10)
* @returns Transaction hash, account address and entity data
**/
updateAddress(networkName: string, address: PublicKey, caseId: u64, category: Category, risk: number, communityName?: string): Promise<HapiActionResponse<Address>>;
}
/** HAPI client to operate authority program functions on Solana */
declare class AuthorityClient extends ReaderClient {
payer: Keypair | PublicKey;
get payerPublicKey(): PublicKey;
get payerKeypair(): Keypair | undefined;
constructor(config: HapiClientAuthorityConfig);
/**
* Create a community creation transaction that can be signed elsewhere
* @param payer Public key of the payer account
* @param communityName The name of the community to create
* @returns Transaction to sign
**/
createCommunityTransaction(communityName?: string): Promise<{
transaction: Transaction;
}>;
/**
* Create and sign a community creation transaction
* @param payer Payer's key pair to sign the transaction
* @param communityName The name of the community to create
* @param authority (Optional) Public key of an authority of the community (defaults to payer public key)
* @returns Transaction hash, account address and entity data
**/
createCommunity(communityName?: string): Promise<HapiActionResponse<Community>>;
/**
* Create a network creation transaction that can be signed elsewhere
* @param payer Public key of the payer account (must be the community authority)
* @param communityName The name of the community that the network should belong to
* @param networkName The name of the network to create
* @returns Transaction to sign
**/
createNetworkTransaction(networkName: string, communityName?: string): Promise<{
transaction: Transaction;
}>;
/**
* Create and sign a network creation transaction
* @param payer Payer's key pair to sign the transaction
* @param communityName The name of the community that the network should belong to
* @param networkName The name of the network to create
* @returns Transaction hash, account address and entity data
**/
createNetwork(networkName: string, communityName?: string): Promise<HapiActionResponse<Network>>;
/**
* Create a reporter creation transaction that can be signed elsewhere
* @param payer Public key of the payer account (must be the community authority)
* @param communityName The name of the community that the network should belong to
* @param reporterPubkey Public key of the reporter
* @param reporterType Type of the reporter
* @param reporterName The name of the reporter to create
* @returns Transaction to sign
**/
createReporterTransaction(reporterPubkey: PublicKey, reporterType: ReporterType, reporterName: string, communityName?: string): Promise<{
transaction: Transaction;
}>;
/**
* Create and sign a reporter creation transaction
* @param payer Payer's key pair to sign the transaction
* @param communityName The name of the community that the network should belong to
* @param reporterPubkey Public key of the reporter
* @param reporterType Type of the reporter
* @param reporterName The name of the reporter to create
* @returns Transaction hash, account address and entity data
**/
createReporter(reporterPubkey: PublicKey, reporterType: ReporterType, reporterName: string, communityName?: string): Promise<HapiActionResponse<Reporter>>;
/**
* Create a reporter updating transaction that can be signed elsewhere
* @param payer Public key of the payer account (must be the community authority)
* @param communityName The name of the community that the network should belong to
* @param reporterPubkey Public key of the reporter
* @param reporterType New type of the reporter
* @param reporterName New name of the reporter
* @returns Transaction to sign
**/
updateReporterTransaction(reporterPubkey: PublicKey, reporterType: ReporterType, reporterName: string, communityName?: string): Promise<{
transaction: Transaction;
}>;
/**
* Create and sign a reporter updating transaction
* @param payer Public key of the payer account (must be the community authority)
* @param communityName The name of the community that the network should belong to
* @param reporterPubkey Public key of the reporter
* @param reporterType New type of the reporter
* @param reporterName New name of the reporter
* @returns Transaction hash, account address and updated entity data
**/
updateReporter(reporterPubkey: PublicKey, reporterType: ReporterType, reporterName: string, communityName?: string): Promise<HapiActionResponse<Reporter>>;
}
declare function getHapiInstructionName(instruction: HapiInstruction): string;
declare function getHapiAccountTypeName(accountType: HapiAccountType): string;
declare function getReporterTypeName(reporterType: ReporterType): string;
declare function getCategoryName(category: Category): string;
declare function getCaseStatusName(caseStatus: CaseStatus): string;
declare class CreateCommunityIx extends Struct {
protected tag: HapiInstruction;
name: string;
}
declare class UpdateCommunityIx extends Struct {
protected tag: HapiInstruction;
name: string;
}
declare class CreateNetworkIx extends Struct {
protected tag: HapiInstruction;
name: string;
}
declare class CreateReporterIx extends Struct {
protected tag: HapiInstruction;
reporterType: ReporterType;
name: string;
}
declare class UpdateReporterIx extends Struct {
protected tag: HapiInstruction;
reporterType: ReporterType;
name: string;
}
declare class CreateCaseIx extends Struct {
protected tag: HapiInstruction;
caseId: u64;
categories: u32;
status: number;
name: string;
}
declare class UpdateCaseIx extends Struct {
protected tag: HapiInstruction;
status: number;
categories: u32;
}
declare class CreateAddressIx extends Struct {
protected tag: HapiInstruction;
address: Uint8Array;
risk: number;
caseId: u64;
category: u8;
}
declare class UpdateAddressIx extends Struct {
protected tag: HapiInstruction;
risk: number;
caseId: u64;
category: u8;
}
export { Address, AddressState, AuthorityClient, Case, CaseStatus, Categories, Category, Community, CreateAddressIx, CreateCaseIx, CreateCommunityIx, CreateNetworkIx, CreateReporterIx, HAPI_PROGRAM_ID, HapiAccountType, HapiActionResponse, HapiActionResponseWithMeta, HapiClientAuthorityConfig, HapiClientConfig, HapiClientReporterConfig, HapiInstruction, HapiViewResponse, Network, ReaderClient, Reporter, ReporterClient, ReporterType, UpdateAddressIx, UpdateCaseIx, UpdateCommunityIx, UpdateReporterIx, getCaseStatusName, getCategoryName, getHapiAccountTypeName, getHapiInstructionName, getReporterTypeName, u32, u64, u8 };