-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
155 lines (135 loc) · 5.41 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
declare module 'ethstorage-sdk' {
import { ethers } from 'ethers';
import { NodeFile } from 'ethstorage-sdk/file';
// Constants
export const BLOB_DATA_SIZE: number;
export const OP_BLOB_DATA_SIZE: number;
export const BLOB_SIZE: number;
export const MAX_BLOB_COUNT: number;
export const PaddingPer31Bytes: number;
export const RawData: number;
export const BLOB_COUNT_LIMIT: number;
export const UPLOAD_TYPE_CALLDATA: number;
export const UPLOAD_TYPE_BLOB: number;
export const MAX_CHUNKS: number;
export const ETHSTORAGE_MAPPING: {
[chainId: number]: string;
};
export const EthStorageAbi: string[];
export const FlatDirectoryAbi: string[];
export const FlatDirectoryBytecode: string;
// Types
export type BufferLike = Buffer | Uint8Array;
export type FileLike = File | NodeFile;
export type ContentLike = BufferLike | FileLike;
export type AsyncFunction<T> = (...args: any[]) => Promise<T>;
// Interfaces
export interface SDKConfig {
rpc: string;
ethStorageRpc?: string;
privateKey: string;
address?: string;
}
export interface EstimateGasRequest {
key: string,
content: ContentLike,
type: number,
gasIncPct?: number,
chunkHashes?: Uint8Array[],
}
export interface UploadRequest extends EstimateGasRequest {
callback: Partial<UploadCallback>,
}
export interface CostEstimate {
storageCost: bigint;
gasCost: bigint;
}
export interface UploadCallback {
onProgress: (currentChunk: number, totalChunks: number, isChange: boolean) => void;
onFail: (error: Error) => void;
onFinish: (totalUploadChunks: number, totalUploadSize: number, totalStorageCost: bigint) => void;
}
export interface DownloadCallback {
onProgress: (currentChunk: number, totalChunks: number, chunkData: Buffer) => void;
onFail: (error: Error) => void;
onFinish: () => void;
}
// Classes
export class EthStorage {
static create(config: SDKConfig): Promise<EthStorage>;
constructor(config: SDKConfig);
init(rpc: string, address?: string): Promise<void>;
estimateCost(key: string, data: Buffer | Uint8Array): Promise<CostEstimate>;
write(key: string, data: Buffer | Uint8Array): Promise<boolean>;
read(key: string): Promise<Uint8Array>;
writeBlobs(keys: string[], dataBlobs: Buffer[] | Uint8Array[]): Promise<boolean>;
}
export class FlatDirectory {
static create(config: SDKConfig): Promise<FlatDirectory>;
isSupportBlob(): boolean;
deploy(): Promise<string | null>;
setDefault(filename: string): Promise<boolean>;
remove(key: string): Promise<boolean>;
download(key: string, cb: Partial<DownloadCallback>): void;
fetchHashes(keys: string[]):Promise<any>;
estimateCost(request: EstimateGasRequest): Promise<CostEstimate>;
upload(request: UploadRequest): Promise<void>;
}
// Utils
export namespace utils {
export class BlobUploader {
static create(rpc: string, pk: string): Promise<BlobUploader>;
constructor(rpc: string, pk: string);
init(): Promise<void>;
getNonce(): Promise<number>;
getBlobGasPrice(): Promise<bigint>;
getGasPrice(): Promise<ethers.FeeData>;
estimateGas(params: any): Promise<bigint | null>;
sendTx(tx: ethers.TransactionRequest, blobs?: Uint8Array[], commitments?: Uint8Array[]): Promise<ethers.TransactionResponse>;
sendTxLock(tx: ethers.TransactionRequest, blobs?: Uint8Array[], commitments?: Uint8Array[]): Promise<ethers.TransactionResponse>;
getCommitment(blob: Uint8Array): Uint8Array;
getBlobHash(blob: Uint8Array): string;
}
export function encodeOpBlobs(data: Uint8Array): Uint8Array[];
export function encodeOpBlob(blob: Uint8Array): Uint8Array;
export function stringToHex(s: string): string;
export function getChainId(rpc: string): Promise<number>;
export function getContentChunk(content: ContentLike, start: number, end: number): Uint8Array;
export function isBuffer(content: BufferLike): boolean;
export function isFile(content: FileLike): boolean;
export function isNodejs(): boolean;
export function commitmentsToVersionedHashes(commitment: Uint8Array): string;
export function getHash(commitment: Uint8Array): string;
export function retry<T>(fn: AsyncFunction<T>, retries: number, isThrow?: boolean, ...args: any[]): Promise<T>;
}
// Default export
const ethstorage: {
BLOB_DATA_SIZE: number;
BLOB_SIZE: number;
ETHSTORAGE_MAPPING: typeof ETHSTORAGE_MAPPING;
EthStorage: typeof EthStorage;
EthStorageAbi: string[];
FlatDirectory: typeof FlatDirectory;
FlatDirectoryAbi: string[];
FlatDirectoryBytecode: string;
MAX_BLOB_COUNT: number;
PaddingPer31Bytes: number;
RawData: number;
utils: typeof utils;
};
export default ethstorage;
}
declare module 'ethstorage-sdk/file' {
// Classes
export class NodeFile {
constructor(filePath: string, start?: number, end?: number, type?: string);
slice(start: number, end: number): NodeFile;
arrayBuffer(): Promise<Buffer>;
text(): Promise<string>;
// stream(): ReadStream;
}
const nodefile: {
NodeFile: typeof NodeFile;
};
export default nodefile;
}