-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.d.ts
More file actions
176 lines (155 loc) · 5.1 KB
/
Copy pathindex.d.ts
File metadata and controls
176 lines (155 loc) · 5.1 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { Transform, Readable, Writable } from 'stream';
export class ToString extends Transform {
constructor(options?: any, schema?: any);
}
export class Sealer extends Transform {
constructor(options?: {
keyPair: any;
hashProvider?: SealedHashProvider;
[key: string]: any;
});
}
export class Unsealer extends Transform {
constructor(options?: {
keyPair: any;
context?: any;
progressHandler?: (...args: any[]) => void;
hashProvider?: SealedHashProvider;
[key: string]: any;
});
}
export class SealedFileStream extends Readable {
constructor(filePath: string, options?: any);
}
/** PipelineContext / PipelineContextInFile 配置 */
export interface PipelineContextOptions {
/**
* 落盘频率:每提交多少个 item 调用一次 saveContext。
* 默认 32。流结束(_final)仍会强制落盘。
*/
saveFrequency?: number;
/**
* 强一致性保证:为 true 时 save 落盘会 fsync。
* 默认 false(省略 fsync,提升吞吐)。
*/
strongConsistency?: boolean;
[key: string]: any;
}
export class PipelineContext {
context: Record<string, any>;
options: PipelineContextOptions;
constructor(options?: PipelineContextOptions);
update(key: string, value: any): void;
saveContext(): Promise<void> | void;
loadContext(): Promise<void> | void;
}
export class PipelineContextInFile extends PipelineContext {
constructor(filePath: string, options?: PipelineContextOptions);
saveContext(): Promise<void>;
loadContext(): Promise<void>;
}
export class RecoverableReadStream extends Readable {
constructor(filePath: string, context: PipelineContext, options?: any);
}
export class RecoverableWriteStream extends Writable {
constructor(filePath: string, context: PipelineContext, options?: any);
}
// Sealed file utilities
export function isSealedFile(filePath: string): boolean;
export function sealedFileVersion(filePath: string): number;
export function dataHashOfSealedFile(filePath: string): Buffer | null;
export function signedDataHash(keyPair: any, dataHash: Buffer): Buffer;
export function forwardSkey(keyPair: any, dianPKey: any, enclaveHash?: Buffer): { encrypted_skey: Buffer; forward_sig: Buffer };
/**
* 可注入的 keccak 实现。
* Node 默认会优先用 optionalDependency `keccak` 原生 addon(约 350MB/s),
* 不可用时回退 @noble/hashes 纯 JS(约 20~40MB/s);也可用本接口强制指定。
*/
export interface SealedHashProvider {
keccak256(data: Uint8Array): Uint8Array;
}
/** Node 侧当前生效的 keccak 实现;浏览器入口不导出此函数 */
export function getKeccakImplementation(): 'native' | 'js';
export function calculateSealedHash(
filePath: string,
options?: { hashProvider?: SealedHashProvider }
): string;
/** 可 JSON 持久化的扫描断点;与 fileSize + itemCount 绑定,换文件即失效 */
export interface SealedHashCheckpoint {
version: number;
fileSize: number;
itemCount: number;
itemIndex: number;
offset: number;
/** 已扫过部分的滚动哈希(十六进制) */
hash: string;
}
export interface SealedHashProgress {
bytesRead: number;
totalBytes: number;
itemIndex: number;
itemCount: number;
/** 0 ~ 1 */
progress: number;
}
export interface CalculateSealedHashAsyncOptions {
onProgress?: (progress: SealedHashProgress) => void;
onCheckpoint?: (checkpoint: SealedHashCheckpoint) => void;
signal?: AbortSignal;
checkpoint?: SealedHashCheckpoint | null;
hashProvider?: SealedHashProvider;
/** 单次读盘窗口,默认 4MiB */
chunkSize?: number;
/** 每扫过多少字节让出一次事件循环,默认 1MiB */
yieldEveryBytes?: number;
}
/**
* 异步计算密封文件哈希:分片让出事件循环,不会冻结 UI 线程。
* 取消时抛 MetaEncryptorError('ERR_SEALED_HASH_ABORTED'),`detail.checkpoint` 可用于续算。
*/
export function calculateSealedHashAsync(
filePath: string,
options?: CalculateSealedHashAsyncOptions
): Promise<string>;
// DataProvider (constructor-style API)
export class DataProviderClass {
header: any;
block_meta_info: any[];
sealed_data: any[];
data_lines: any[];
counter: number;
key_pair: any;
constructor(keyPair: any, options?: { hashProvider?: SealedHashProvider });
write_batch(batch: any, public_key: string, writable_stream?: any): void;
sealData(input: any, writable_stream?: any, is_end?: boolean): any;
setHeaderAndMeta(): { headerInfo: Buffer; blockInfo: Buffer; meta: any };
static headerAndBlockBufferFromBuffer(buf: Buffer): { header: Buffer; block: Buffer } | null;
}
export const DataProvider: typeof DataProviderClass;
export const checkSealedData: any;
export const unsealData: any;
export const YPCNtObject: any;
export const YPCCrypto: any;
export { Sealer as defaultSealer };
export default {
ToString,
Sealer,
Unsealer,
SealedFileStream,
PipelineContext,
PipelineContextInFile,
RecoverableReadStream,
RecoverableWriteStream,
isSealedFile,
sealedFileVersion,
dataHashOfSealedFile,
signedDataHash,
forwardSkey,
calculateSealedHash,
calculateSealedHashAsync,
DataProvider,
checkSealedData,
unsealData,
YPCNtObject,
YPCCrypto
};