@okcontract/sdk
Version:
One-stop-shop permissionless SDK for building any blockchain frontend
69 lines (68 loc) • 2.53 kB
TypeScript
import type { AnyCell, SheetProxy, ValueCell } from "@okcontract/cells";
import type { Address, Network } from "@okcontract/multichain";
import type { OKConnector } from "./wallet";
export declare const LOADING: "wait";
export declare const SUCCESS: "success";
export declare const WARNING: "warning";
export type UploadStatus = typeof LOADING | typeof SUCCESS | typeof WARNING | undefined;
export interface LighthouseUploadMeta {
Name: string;
Hash: string;
Size: string;
}
export type LighthouseUpload = {
data: ValueCell<ArrayBuffer | string | null>;
meta: ValueCell<LighthouseUploadMeta>;
status: ValueCell<UploadStatus>;
url: ValueCell<string>;
};
export type LighthouseEnv = Map<string, LighthouseUpload>;
export declare class Lighthouse {
private proxy;
/** api token */
private token;
/** the wallet client used to sign message */
private _conn;
/** if we its lighthouse authenticated */
readonly isAuth: ValueCell<boolean>;
/** the lighthouse environment (key is path - value is lighthouse upload data)*/
private _env;
constructor(proxy: SheetProxy, conn: AnyCell<OKConnector<Network>>);
private set;
private unset;
get(path: string): LighthouseUpload;
/**
* Authenticates a user using their wallet ID.
* On successful verification, it stores the access token.
*
* @param {Address} walletID - The user's wallet ID for authentication.
* @returns {Promise<boolean>} - True if authenticated, false otherwise.
*/
authenticate(walletID: Address<Network>): Promise<boolean>;
/**
* Uploads and pin a document via Lighthouse.storage to IPFS.
* Also update lighthouse data cells (data and meta)
* @param data
* @returns {Promise<LighthouseUploadMeta>} - True if upload succeed else false
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
* @todo add @types/mime-types for mime
*/
upload(path: string, data: string | ArrayBuffer, mime?: string): Promise<{
success: boolean;
meta?: LighthouseUploadMeta;
error?: Error;
}>;
/**
* Add a new Lighthouse reference in environment
* @param path - The path at which the data will be added
* @param url - The new url
*/
addNew(path: string, url: string): void;
/**
* Unset all Lighthouse cell and remove lighthouse data
* from the env for a given path
* @param path
*/
remove(path: string): void;
}