import type { AccessControlConditions, AccsDefaultParams, JsonAuthSig } from '@lit-protocol/constants'; import * as Lit from '@lit-protocol/lit-node-client'; import type { Connection } from '@tableland/sdk'; import type { IGunUserInstance } from 'gun/types/sea'; import { MeemAPI } from '../generated/api.generated'; import { Id } from './id'; export interface IPartialAccessControlCondition extends Partial { returnValueTest?: { key?: string; comparator: string; value: string; }; } export declare type EmitterEvents = { [path: string]: (items: { [id: string]: any; }) => void; }; export declare type GunOptions = Partial<{ /** Undocumented but mentioned. Write data to a JSON. */ file: string; /** Undocumented but mentioned. Create a websocket server */ web: any; /** Undocumented but mentioned. Amazon S3 */ s3: { key: string; secret: string; bucket: string; region?: string; fakes3?: any; }; /** The URLs are properties, and the value is an empty object. */ peers: string[]; /** Default: true, creates and persists local (nodejs) data using Radisk. */ radisk: boolean; /** Default: true, persists local (browser) data to localStorage. */ localStorage: boolean; /** Uuid allows you to override the default 24 random alphanumeric soul generator with your own function. */ uuid(): string; /** * Allows you to pass options to a 3rd party module. Their project README will likely list the exposed options * @see https://github.com/amark/gun/wiki/Modules */ [key: string]: any; }>; export declare class Storage { private id; private jwt?; /** Mapping of chainId:Tableland instance */ private tablelands; /** The LIT protocol client */ private lit?; private gun?; private emitter; private apiUrl?; constructor(options: { id: Id; jwt?: string; isGunEnabled: boolean; gunOptions?: GunOptions; apiUrl?: string; }); /** Sets the JWT used in api calls */ setJwt(jwt?: string): void; getGunInstance(): IGunUserInstance | undefined; /** Get an instance of the Tableland SDK */ getTablelandInstance(options: { chainId: number; }): Promise; /** Get a LIT protocol client */ getLitInstance(options?: { alertWhenUnauthorized?: boolean; debug?: boolean; }): Promise; /** Generate an RSA public/private keypair */ generateKeyPair(): Promise<{ publicKey: JsonWebKey; privateKey: JsonWebKey; }>; generateAESKey(): Promise; /** Encrypt data using a public key */ encrypt(options: { data: Record; key: JsonWebKey; algorithm?: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm; /** The algorithm params to pass to crypto.subtle.decrypt(...). Default AES-CTR length 128 */ algorithmParams?: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams; }): Promise; /** Encrypt data using LIT protocol */ encryptWithLit(options: { /** The chainId to encrypt on */ chainId: number; /** The data to encrypt */ data: Record; /** * The token(s) that may be held in order to decrypt the string * * For advanced customization options see: https://developer.litprotocol.com/SDK/Explanation/encryption */ accessControlConditions: IPartialAccessControlCondition[]; }): Promise<{ accessControlConditions: AccessControlConditions; encryptedSymmetricKey: string; encryptedStr: Blob; }>; /** Fetches a file from IPFS and decrypts it using LIT */ fetchFromIPFSAndDecrypt(options: { /** The chainId to decrypt on */ chainId: number; /** The IPFS URI to decrypt */ ipfsURI: string; /** The access control conditions */ accessControlConditions: AccessControlConditions; /** The lit encrypted symmetric key obtained from the saveEncryptionKey method */ encryptedSymmetricKey: string; /** Fetch using a custom IPFS gateway. Defaults to the Meem IPFS gateway */ ipfsGateway?: string; }): Promise<{ decryptedString: string | undefined; data: Record; }>; /** Decrypt data using a private key */ decrypt(options: { /** The string to decrypt */ strToDecrypt: string; privateKey: JsonWebKey; /** The algorithm used to generate the privateKey. Default AES-CTR */ algorithm?: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm; /** The algorithm params to pass to crypto.subtle.decrypt(...). Default AES-CTR length 128 */ algorithmParams?: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams; }): Promise<{ decryptedString: any; data: Record; }>; /** Decrypt data using LIT protocol */ decryptWithLit(options: { /** The chainId to decrypt on */ chainId: number; /** The string to decrypt */ strToDecrypt: Blob | string; /** The access control conditions */ accessControlConditions: AccessControlConditions; /** The lit encrypted symmetric key obtained from the saveEncryptionKey method */ encryptedSymmetricKey: string; }): Promise<{ decryptedString: string | undefined; data: Record; }>; /** Decrypt an item stored in GunDB using a private key */ decryptItem(options: { item: Record; privateKey: JsonWebKey; }): Promise>; /** Decrypt an item stored in GunDB using LIT */ decryptItemWithLit(options: { item: Record; chainId: number; }): Promise>; /** Subscribe to data changes on a path */ on(options: { /** The path to listen for */ path: string; /** The callback invoked when data changes */ cb: (data: any) => void; /** The chain id */ chainId?: number; /** Will decrypt the data using the JSON web key. If omitted, will decrypt using LIT */ privateKey?: JsonWebKey; }): Promise; /** Unsubscribe to events */ off(path: string, cb: (data: any) => void): Promise; /** Encrypt the "data" field and then write to GunDB */ encryptAndWrite(options: { /** The path to write the data */ path: string; /** The values to be written to the db in the form of columnName:value */ writeColumns?: { [columnName: string]: any; }; /** The values to be encrypted and written to the db "data" column in the form of columnName:value */ data: { [columnName: string]: any; }; /** * The key that will be used to encrypt the data */ key: JsonWebKey; }): Promise<{ id: string; hash: string; item: import("gun/types").IGunChain, any, string>, any, `#${string}`> | undefined; }>; /** Encrypt the "data" field and then write to GunDB */ encryptWithLitAndWrite(options: { /** The chain */ chainId: number; /** The path to write the data */ path: string; /** The values to be written to the db in the form of columnName:value */ writeColumns?: { [columnName: string]: any; }; /** The values to be encrypted and written to the db "data" column in the form of columnName:value */ data: { [columnName: string]: any; }; /** * The token(s) that may be held in order to decrypt the string * * For advanced customization options see: https://developer.litprotocol.com/SDK/Explanation/encryption */ accessControlConditions: IPartialAccessControlCondition[]; }): Promise<{ id: string; hash: string; }>; /** Encrypt the "data" field and then write to tableland */ encryptAndWriteToTableland(options: { /** The chain */ chainId: number; /** The Tableland table name */ tableName: string; /** The values to be written to the db in the form of columnName:value */ writeColumns?: { [columnName: string]: any; }; /** The values to be encrypted and written to the db "data" column in the form of columnName:value */ data: { [columnName: string]: any; }; /** * The token(s) that may be held in order to decrypt the string * * For advanced customization options see: https://developer.litprotocol.com/SDK/Explanation/encryption */ accessControlConditions: IPartialAccessControlCondition[]; }): Promise; /** Insert data in a Tableland table */ write(options: { /** The chain */ chainId: number; /** The Tableland table name */ tableName: string; /** The values to be written to the db in the form of columnName:value */ writeColumns: { [columnName: string]: any; }; }): Promise; /** Count records in a Tableland table */ count(options: { /** The chain */ chainId: number; /** The Tableland table name */ tableName: string; /** * Add a WHERE clause. Only exact matches are supported * * Example: { id: 1 } * * */ where?: Record; }): Promise; /** Fetch data from a Tableland table */ read(options: { /** The chain */ chainId: number; /** The Tableland table name */ tableName: string; /** Column names to fetch. Default all columns */ columns?: string[]; /** Limit the number of items returned. Default 100 */ limit?: number; /** The column name to order by. Default "createdAt" */ orderBy?: string; /** The sort direction. Default DESC */ order?: 'ASC' | 'DESC'; /** * Add a WHERE clause. Only exact matches are supported * * Example: { id: 1 } * * */ where?: Record; /** * If set will attempt to decrypt the rows "data" column using LIT protocol and * filter out any rows that fail decryption */ authSig?: JsonAuthSig; }): Promise<{ [columnName: string]: any; }[]>; /** Save data or JSON to IPFS */ saveToIPFS(options: { data?: string; json?: Record; }): Promise; /** Converts a Blob to a base64 string */ blobToBase64(blob: Blob): Promise; /** Converts a base64 URI into a Blob */ base64URIToBlob(dataURI: string): Blob; /** * Converts nested arrays in an object to objects * * GunDB doesn't allow arrays so this is a necessary step before saving data */ sanitizeGunData(obj: any): Record; /** * Converts objects back to regular after using sanitizeForGun * * GunDB doesn't allow arrays so this is a necessary step before saving data */ desanitizeGunData(obj: any): any; private convertArraysToObjects; private importGunExtensions; }