@provablehq/sdk
Version:
A Software Development Kit (SDK) for Zero-Knowledge Transactions
152 lines (151 loc) • 5.97 kB
TypeScript
import { EncryptedRecord } from "./models/record-provider/encryptedRecord";
import { OwnedFilter } from "./models/record-scanner/ownedFilter";
import { OwnedRecord } from "./models/record-provider/ownedRecord";
import { RecordProvider } from "./record-provider";
import { Field, ViewKey } from "./wasm";
import { RecordsFilter } from "./models/record-scanner/recordsFilter";
import { RegistrationResponse } from "./models/record-scanner/registrationResponse";
import { StatusResponse } from "./models/record-scanner/statusResponse";
type RecordScannerOptions = {
url: string;
apiKey?: string | {
header: string;
value: string;
};
};
/**
* RecordScanner is a RecordProvider implementation that uses the record scanner service to find records.
*
* @example
* const account = new Account({ privateKey: 'APrivateKey1...' });
*
* const recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org" });
* recordScanner.setAccount(account);
* recordScanner.setApiKey("your-api-key");
* const uuid = await recordScanner.register(0);
*
* const filter = {
* uuid,
* filter: {
* program: "credits.aleo",
* records: ["credits"],
* },
* responseFilter: {
* commitment: true,
* owner: true,
* tag: true,
* tag?: boolean;
* sender: true,
* spent: true,
* record_ciphertext: true,
* block_height: true;
* block_timestamp: true;
* output_index: true;
* record_name: true;
* function_name: true;
* program_name: true;
* transition_id: true;
* transaction_id: true;
* transaction_index: true;
* transition_index: true;
* },
* unspent: true,
* };
*
* const records = await recordScanner.findRecords(filter);
*/
declare class RecordScanner implements RecordProvider {
readonly url: string;
private apiKey?;
private uuid?;
constructor(options: RecordScannerOptions);
/**
* Set the API key to use for the record scanner.
*
* @param {string} apiKey The API key to use for the record scanner.
*/
setApiKey(apiKey: string | {
header: string;
value: string;
}): Promise<void>;
/**
* Set the UUID to use for the record scanner.
*
* @param {Field} uuid The UUID to use for the record scanner.
*/
setUuid(uuidOrViewKey: Field | ViewKey): Promise<void>;
/**
* Register the account with the record scanner service.
*
* @param {number} startBlock The block height to start scanning from.
* @returns {Promise<RegistrationResponse>} The response from the record scanner service.
*/
register(viewKey: ViewKey, startBlock: number): Promise<RegistrationResponse>;
/**
* Get encrypted records from the record scanner service.
*
* @param {RecordsFilter} recordsFilter The filter to use to find the records and filter the response.
* @returns {Promise<EncryptedRecord[]>} The encrypted records.
*/
encryptedRecords(recordsFilter: RecordsFilter): Promise<EncryptedRecord[]>;
/**
* Check if a list of serial numbers exist in the record scanner service.
*
* @param {string[]} serialNumbers The serial numbers to check.
* @returns {Promise<Record<string, boolean>>} Map of Aleo Record serial numbers and whether they appeared in any inputs on chain. If boolean corresponding to the Serial Number has a true value, that Record is considered spent by the Aleo Network.
*/
checkSerialNumbers(serialNumbers: string[]): Promise<Record<string, boolean>>;
/**
* Check if a list of tags exist in the record scanner service.
*
* @param {string[]} tags The tags to check.
* @returns {Promise<Record<string, boolean>>} Map of Aleo Record tags and whether they appeared in any inputs on chain. If boolean corresponding to the tag has a true value, that Record is considered spent by the Aleo Network.
*/
checkTags(tags: string[]): Promise<Record<string, boolean>>;
/**
* Check the status of a record scanner indexing job.
*
* @param {string} jobId The job id to check.
* @returns {Promise<StatusResponse>} The status of the job.
*/
checkStatus(): Promise<StatusResponse>;
/**
* Find a record in the record scanner service.
*
* @param {OwnedFilter} searchParameters The filter to use to find the record.
* @returns {Promise<OwnedRecord>} The record.
*/
findRecord(searchParameters: OwnedFilter): Promise<OwnedRecord>;
/**
* Find records in the record scanner service.
*
* @param {OwnedFilter} filter The filter to use to find the records.
* @returns {Promise<OwnedRecord[]>} The records.
*/
findRecords(filter: OwnedFilter): Promise<OwnedRecord[]>;
/**
* Find a credits record in the record scanner service.
*
* @param {number} microcredits The amount of microcredits to find.
* @param {OwnedFilter} searchParameters The filter to use to find the record.
* @returns {Promise<OwnedRecord>} The record.
*/
findCreditsRecord(microcredits: number, searchParameters: OwnedFilter): Promise<OwnedRecord>;
/**
* Find credits records using a record scanning service.
*
* @param {number[]} microcreditAmounts The amounts of microcredits to find.
* @param {OwnedFilter} searchParameters The filter to use to find the records.
* @returns {Promise<OwnedRecord[]>} The records
*/
findCreditsRecords(microcreditAmounts: number[], searchParameters: OwnedFilter): Promise<OwnedRecord[]>;
/**
* Wrapper function to make a request to the record scanner service and handle any errors.
*
* @param {Request} req The request to make.
* @returns {Promise<Response>} The response.
*/
private request;
computeUUID(vk: ViewKey): Field;
}
export { RecordScanner };