Skip to content

Commit ea0bc8a

Browse files
committed
revise code
1 parent f1b0dea commit ea0bc8a

File tree

10 files changed

+102
-111
lines changed

10 files changed

+102
-111
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ let r = forwardSkey(keyPair, dianPKey, enclaveHash);
245245
}
246246
```
247247
248-
##### 可恢复流
248+
##### 可恢复流(仅适用于Node环境)
249249
250250
meta-encryptor 提供了支持断点续传的可恢复流功能,主要包含以下组件:
251251

batch.yarn.test.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

index.d.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { Transform, Readable, Writable } from 'stream';
2+
3+
export class ToString extends Transform {
4+
constructor(options?: any, schema?: any);
5+
}
6+
7+
export class Sealer extends Transform {
8+
constructor(options?: any);
9+
}
10+
11+
export class Unsealer extends Transform {
12+
constructor(options?: any);
13+
}
14+
15+
export class SealedFileStream extends Readable {
16+
constructor(filePath: string, options?: any);
17+
}
18+
19+
export class PipelineContext {
20+
context: Record<string, any>;
21+
options: any;
22+
constructor(options?: any);
23+
update(key: string, value: any): void;
24+
saveContext(): Promise<void> | void;
25+
loadContext(): Promise<void> | void;
26+
}
27+
28+
export class PipelineContextInFile extends PipelineContext {
29+
constructor(filePath: string, options?: any);
30+
saveContext(): Promise<void>;
31+
loadContext(): Promise<void>;
32+
}
33+
34+
export class RecoverableReadStream extends Readable {
35+
constructor(filePath: string, context: PipelineContext, options?: any);
36+
}
37+
38+
export class RecoverableWriteStream extends Writable {
39+
constructor(filePath: string, context: PipelineContext, options?: any);
40+
}
41+
42+
// Sealed file utilities
43+
export function isSealedFile(filePath: string): boolean;
44+
export function sealedFileVersion(filePath: string): number;
45+
export function dataHashOfSealedFile(filePath: string): Buffer | null;
46+
export function signedDataHash(keyPair: any, dataHash: Buffer): Buffer;
47+
export function forwardSkey(keyPair: any, dianPKey: any, enclaveHash?: Buffer): { encrypted_skey: Buffer; forward_sig: Buffer };
48+
export function calculateSealedHash(filePath: string): string;
49+
50+
// DataProvider (constructor-style API)
51+
export class DataProviderClass {
52+
header: any;
53+
block_meta_info: any[];
54+
sealed_data: any[];
55+
data_lines: any[];
56+
counter: number;
57+
key_pair: any;
58+
constructor(keyPair: any);
59+
write_batch(batch: any, public_key: string, writable_stream?: any): void;
60+
sealData(input: any, writable_stream?: any, is_end?: boolean): any;
61+
setHeaderAndMeta(): { headerInfo: Buffer; blockInfo: Buffer; meta: any };
62+
static headerAndBlockBufferFromBuffer(buf: Buffer): { header: Buffer; block: Buffer } | null;
63+
}
64+
65+
export const DataProvider: typeof DataProviderClass;
66+
export const checkSealedData: any;
67+
export const unsealData: any;
68+
69+
export const YPCNtObject: any;
70+
export const YPCCrypto: any;
71+
72+
export { Sealer as defaultSealer };
73+
74+
export default {
75+
ToString,
76+
Sealer,
77+
Unsealer,
78+
SealedFileStream,
79+
PipelineContext,
80+
PipelineContextInFile,
81+
RecoverableReadStream,
82+
RecoverableWriteStream,
83+
isSealedFile,
84+
sealedFileVersion,
85+
dataHashOfSealedFile,
86+
signedDataHash,
87+
forwardSkey,
88+
calculateSealedHash,
89+
DataProvider,
90+
checkSealedData,
91+
unsealData,
92+
YPCNtObject,
93+
YPCCrypto
94+
};

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Data Seal/Unseal for Fidelius",
55
"main": "build/commonjs/index.node.cjs",
66
"module": "build/es/index.node.js",
7-
"types": "src/index.d.ts",
7+
"types": "index.d.ts",
88
"exports": {
99
".": {
1010
"browser": {
@@ -20,10 +20,9 @@
2020
"type": "module",
2121
"files": [
2222
"build",
23-
"src/index.d.ts",
24-
"src/browser",
25-
"src/header_util.js",
26-
"src/limits.js"
23+
"README.md",
24+
"README.en.md",
25+
"LICENSE"
2726
],
2827
"scripts": {
2928
"build": "rollup-cli-build --no-uglify",

src/browser/UnsealerBrowser.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// 使用浏览器兼容版本的 header_util,避免 bytebuffer 依赖问题
1+
22
import { ntpackage2batch, fromNtInput } from './header_util.browser.js';
33
import { HeaderSize, MagicNum, CurrentBlockFileVersion } from '../limits.js';
44
import { BrowserCrypto } from './ypccrypto.browser.js';
55

6-
// SSR兼容:将 MagicNum 转换为 Uint8Array(避免 Buffer 依赖)
76
const MAGIC_NUM_BYTES = (() => {
87
if (MagicNum instanceof Uint8Array) {
98
return MagicNum;
@@ -63,7 +62,6 @@ export class UnsealerBrowser {
6362
throw new Error('Unsupported version: '+version_number);
6463
}
6564
const magic = headerBytes.slice(0,8);
66-
// SSR兼容:使用纯 Uint8Array 比较,避免 Buffer 依赖
6765
if(magic.length !== MAGIC_NUM_BYTES.length){
6866
throw new Error('Magic number mismatch');
6967
}

src/browser/downloadUnsealed.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// 命令式 API:下载并解密加密文件
2-
// 使用方式:
3-
// import { downloadUnsealed } from '@yeez-tech/meta-encryptor/src/browser/downloadUnsealed.js'
4-
// downloadUnsealed({ url: '...', privateKey: '...', filename: '...' })
51

62
import { unsealStream } from './UnsealerBrowser.js'
73
import { prepareSealedResponse } from './SealedHttpTailHeaderTransform.js'

src/browser/vite.config.example.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ function copyServiceWorker() {
2626
copyServiceWorker()
2727

2828
export default defineConfig({
29-
// 你的其他配置...
3029
})
3130

src/index.d.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"esModuleInterop": true,
44
"resolveJsonModule": true,
55
"noEmit": false,
6+
"allowJs": true,
67
"rootDir": "./src",
78
"outDir": "./dist",
89
"emitDeclarationOnly": true,
910
"declaration": true,
1011
"declarationDir": "./dist/types"
1112
},
1213
"include": [
13-
"src/*",
14-
"test/UnsealerWithTus.js"
14+
"src/**/*"
1515
],
1616
"exclude": [
1717
"node_modules"

webpack.config.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)