@cofhe/sdk 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/acps/acp.ts +25 -6
- package/acps/index.ts +20 -15
- package/acps/onchain-utils.ts +15 -10
- package/acps/registry.ts +166 -8
- package/acps/sealing.ts +31 -5
- package/acps/share-metadata/appKey.ts +8 -0
- package/acps/share-metadata/decode.ts +120 -0
- package/acps/share-metadata/describe.ts +198 -0
- package/acps/share-metadata/encode.ts +147 -0
- package/acps/share-metadata/erc7984.ts +26 -0
- package/acps/share-metadata/index.ts +9 -0
- package/acps/share-metadata/layout.ts +69 -0
- package/acps/share-metadata/presets.ts +116 -0
- package/acps/share-metadata/schema.ts +47 -0
- package/acps/share-metadata/test/codec.test.ts +140 -0
- package/acps/share-metadata/test/describe.test.ts +112 -0
- package/acps/share-metadata/test/fixtures.ts +157 -0
- package/acps/share-metadata/test/live.test.ts +56 -0
- package/acps/share-metadata/test/presets.test.ts +119 -0
- package/acps/share-metadata/test/verify.test.ts +144 -0
- package/acps/share-metadata/verify.ts +155 -0
- package/acps/store.ts +48 -18
- package/acps/test/aclServedAddresses.test.ts +65 -0
- package/acps/test/acp.test.ts +102 -7
- package/acps/test/localstorage.test.ts +28 -1
- package/acps/test/registry.test.ts +144 -0
- package/acps/test/sealing.test.ts +74 -0
- package/acps/test/store.test.ts +71 -0
- package/acps/test/utils.test.ts +63 -0
- package/acps/test/validation.test.ts +0 -4
- package/acps/types.ts +43 -6
- package/acps/utils.ts +15 -2
- package/acps/validation.ts +3 -1
- package/core/acps.ts +123 -74
- package/core/client.ts +33 -7
- package/core/clientTypes.ts +25 -7
- package/core/config.ts +8 -0
- package/core/decrypt/apiError.ts +4 -1
- package/core/decrypt/verifyDecryptResult.ts +4 -1
- package/core/encrypt/cofheMocksZkVerifySign.ts +19 -2
- package/core/test/acpDefaults.test.ts +108 -19
- package/core/test/acpStoreAccountCase.test.ts +80 -0
- package/core/test/acps.test.ts +38 -3
- package/core/test/apiError.test.ts +8 -0
- package/core/test/appKeyConfig.test.ts +94 -0
- package/core/test/config.test.ts +8 -0
- package/core/test/decryptBuilders.test.ts +110 -2
- package/core/test/incomingShares.test.ts +84 -0
- package/core/test/mocksEncryptRange.test.ts +90 -0
- package/core/test/utils.test.ts +128 -0
- package/core/test/verifyDecryptResult.test.ts +51 -0
- package/core/utils.ts +16 -9
- package/dist/acps.cjs +796 -132
- package/dist/acps.d.cts +367 -35
- package/dist/acps.d.ts +367 -35
- package/dist/acps.js +2 -2
- package/dist/{chunk-UJYOBHYA.js → chunk-3L2IVPMI.js} +688 -203
- package/dist/chunk-J23FYAI2.js +174 -0
- package/dist/{chunk-GGI7Y6AW.js → chunk-O2ITEUEU.js} +110 -269
- package/dist/chunk-WJGTPW7K.js +228 -0
- package/dist/{clientTypes-D3aIXmUp.d.cts → clientTypes-IO6b5Um8.d.cts} +61 -21
- package/dist/{clientTypes-5YPPR16m.d.ts → clientTypes-b1pOxOUE.d.ts} +61 -21
- package/dist/core.cjs +3115 -2584
- package/dist/core.d.cts +6 -3
- package/dist/core.d.ts +6 -3
- package/dist/core.js +4 -3
- package/dist/node.cjs +3001 -2470
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +18 -17
- package/dist/{onchain-utils-CUAK8glx.d.cts → onchain-utils-CgOslubH.d.cts} +139 -15
- package/dist/{onchain-utils-CUAK8glx.d.ts → onchain-utils-CgOslubH.d.ts} +139 -15
- package/dist/web.cjs +3011 -2487
- package/dist/web.d.cts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +4 -10
- package/dist/zkProve.worker.cjs +14 -7
- package/dist/zkProve.worker.js +2 -8
- package/node/index.ts +1 -10
- package/node/storage.ts +18 -7
- package/node/test/storage-permissions.test.ts +40 -0
- package/package.json +4 -4
- package/web/index.ts +1 -10
- package/web/test/threadPoolBenchHelper.ts +1 -7
- package/web/zkProve.worker.ts +1 -10
- package/dist/chunk-NMKMCAI3.js +0 -14
package/dist/web.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-IO6b5Um8.cjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './onchain-utils-
|
|
5
|
+
import './onchain-utils-CgOslubH.cjs';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
declare function createSsrStorage(): IStorage;
|
package/dist/web.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-b1pOxOUE.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './onchain-utils-
|
|
5
|
+
import './onchain-utils-CgOslubH.js';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
declare function createSsrStorage(): IStorage;
|
package/dist/web.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createCofheConfigBase, createCofheClientBase
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase } from './chunk-O2ITEUEU.js';
|
|
2
2
|
import './chunk-UKQAJK4N.js';
|
|
3
|
-
import './chunk-
|
|
3
|
+
import './chunk-3L2IVPMI.js';
|
|
4
4
|
import { initTfheThreadPool } from './chunk-KSOV5B4B.js';
|
|
5
|
-
import {
|
|
5
|
+
import { fheTypeToString, fromHexString } from './chunk-WJGTPW7K.js';
|
|
6
|
+
import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-J23FYAI2.js';
|
|
6
7
|
import { constructClient } from 'iframe-shared-storage';
|
|
7
8
|
|
|
8
9
|
// web/const.ts
|
|
@@ -233,13 +234,6 @@ function requireTfhe() {
|
|
|
233
234
|
}
|
|
234
235
|
return tfheModule;
|
|
235
236
|
}
|
|
236
|
-
var fromHexString = (hexString) => {
|
|
237
|
-
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
238
|
-
const arr = cleanString.replace(/^0x/, "").match(/.{1,2}/g);
|
|
239
|
-
if (!arr)
|
|
240
|
-
return new Uint8Array();
|
|
241
|
-
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
242
|
-
};
|
|
243
237
|
var _deserializeTfhePublicKey = (buff) => {
|
|
244
238
|
return requireTfhe().TfheCompactPublicKey.safe_deserialize(
|
|
245
239
|
fromHexString(buff),
|
package/dist/zkProve.worker.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
require('viem');
|
|
4
|
+
|
|
3
5
|
// core/consts.ts
|
|
4
6
|
var TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT = BigInt(1 << 30);
|
|
5
7
|
|
|
@@ -51,6 +53,18 @@ async function initTfheThreadPool(mod, setting = "auto") {
|
|
|
51
53
|
};
|
|
52
54
|
}
|
|
53
55
|
}
|
|
56
|
+
var HEX_BODY_REGEX = /^[0-9a-fA-F]*$/;
|
|
57
|
+
var fromHexString = (hexString) => {
|
|
58
|
+
const body = hexString.replace(/^0x/, "");
|
|
59
|
+
if (!HEX_BODY_REGEX.test(body)) {
|
|
60
|
+
throw new Error("Invalid hex string: contains non-hexadecimal characters");
|
|
61
|
+
}
|
|
62
|
+
const padded = body.length % 2 === 1 ? `0${body}` : body;
|
|
63
|
+
const arr = padded.match(/.{1,2}/g);
|
|
64
|
+
if (!arr)
|
|
65
|
+
return new Uint8Array();
|
|
66
|
+
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
67
|
+
};
|
|
54
68
|
|
|
55
69
|
// web/zkProve.worker.ts
|
|
56
70
|
var tfheModule = null;
|
|
@@ -74,13 +88,6 @@ function initTfhe(tfheThreads = "auto") {
|
|
|
74
88
|
})();
|
|
75
89
|
return initPromise;
|
|
76
90
|
}
|
|
77
|
-
function fromHexString(hexString) {
|
|
78
|
-
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
79
|
-
const arr = cleanString.replace(/^0x/, "").match(/.{1,2}/g);
|
|
80
|
-
if (!arr)
|
|
81
|
-
return new Uint8Array();
|
|
82
|
-
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
83
|
-
}
|
|
84
91
|
if (typeof self !== "undefined") {
|
|
85
92
|
self.onmessage = async (event) => {
|
|
86
93
|
const { id, type, fheKeyHex, crsHex, items, metadata, tfheThreads } = event.data;
|
package/dist/zkProve.worker.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { initTfheThreadPool } from './chunk-KSOV5B4B.js';
|
|
2
|
-
import {
|
|
2
|
+
import { fromHexString } from './chunk-WJGTPW7K.js';
|
|
3
|
+
import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-J23FYAI2.js';
|
|
3
4
|
|
|
4
5
|
// web/zkProve.worker.ts
|
|
5
6
|
var tfheModule = null;
|
|
@@ -23,13 +24,6 @@ function initTfhe(tfheThreads = "auto") {
|
|
|
23
24
|
})();
|
|
24
25
|
return initPromise;
|
|
25
26
|
}
|
|
26
|
-
function fromHexString(hexString) {
|
|
27
|
-
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
28
|
-
const arr = cleanString.replace(/^0x/, "").match(/.{1,2}/g);
|
|
29
|
-
if (!arr)
|
|
30
|
-
return new Uint8Array();
|
|
31
|
-
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
32
|
-
}
|
|
33
27
|
if (typeof self !== "undefined") {
|
|
34
28
|
self.onmessage = async (event) => {
|
|
35
29
|
const { id, type, fheKeyHex, crsHex, items, metadata, tfheThreads } = event.data;
|
package/node/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type FheKeyDeserializer,
|
|
11
11
|
TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT,
|
|
12
12
|
} from '@/core';
|
|
13
|
+
import { fromHexString } from '../core/utils.js';
|
|
13
14
|
|
|
14
15
|
// Import node-specific storage (internal use only)
|
|
15
16
|
import { createNodeStorage } from './storage.js';
|
|
@@ -30,16 +31,6 @@ async function initTfhe(): Promise<boolean> {
|
|
|
30
31
|
return true;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
/**
|
|
34
|
-
* Utility to convert the hex string key to a Uint8Array for use with tfhe
|
|
35
|
-
*/
|
|
36
|
-
const fromHexString = (hexString: string): Uint8Array => {
|
|
37
|
-
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
38
|
-
const arr = cleanString.replace(/^0x/, '').match(/.{1,2}/g);
|
|
39
|
-
if (!arr) return new Uint8Array();
|
|
40
|
-
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
41
|
-
};
|
|
42
|
-
|
|
43
34
|
const _deserializeTfhePublicKey = (buff: string): TfheCompactPublicKey => {
|
|
44
35
|
return TfheCompactPublicKey.safe_deserialize(fromHexString(buff), TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT);
|
|
45
36
|
};
|
package/node/storage.ts
CHANGED
|
@@ -8,6 +8,17 @@ import { join } from 'path';
|
|
|
8
8
|
// Memory storage fallback
|
|
9
9
|
const memoryStorage: Record<string, unknown> = {};
|
|
10
10
|
|
|
11
|
+
const getStorageDir = () => join(process.env.HOME || process.env.USERPROFILE || '.', '.cofhesdk');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Keep the directory and files private to the current user. `mode` only applies
|
|
15
|
+
* on creation, so chmod also tightens directories/files created by earlier SDK versions.
|
|
16
|
+
*/
|
|
17
|
+
const ensureStorageDir = async (storageDir: string) => {
|
|
18
|
+
await fs.mkdir(storageDir, { recursive: true, mode: 0o700 });
|
|
19
|
+
await fs.chmod(storageDir, 0o700).catch(() => {});
|
|
20
|
+
};
|
|
21
|
+
|
|
11
22
|
/**
|
|
12
23
|
* Creates a node storage implementation using the filesystem
|
|
13
24
|
* @returns IStorage implementation for Node.js environments
|
|
@@ -16,8 +27,8 @@ export const createNodeStorage = (): IStorage => {
|
|
|
16
27
|
return {
|
|
17
28
|
getItem: async (name: string) => {
|
|
18
29
|
try {
|
|
19
|
-
const storageDir =
|
|
20
|
-
await
|
|
30
|
+
const storageDir = getStorageDir();
|
|
31
|
+
await ensureStorageDir(storageDir);
|
|
21
32
|
const filePath = join(storageDir, `${name}.json`);
|
|
22
33
|
const data = await fs.readFile(filePath, 'utf8').catch(() => null);
|
|
23
34
|
return data ? JSON.parse(data) : null;
|
|
@@ -28,10 +39,11 @@ export const createNodeStorage = (): IStorage => {
|
|
|
28
39
|
},
|
|
29
40
|
setItem: async (name: string, value: any) => {
|
|
30
41
|
try {
|
|
31
|
-
const storageDir =
|
|
32
|
-
await
|
|
42
|
+
const storageDir = getStorageDir();
|
|
43
|
+
await ensureStorageDir(storageDir);
|
|
33
44
|
const filePath = join(storageDir, `${name}.json`);
|
|
34
|
-
await fs.writeFile(filePath, JSON.stringify(value));
|
|
45
|
+
await fs.writeFile(filePath, JSON.stringify(value), { mode: 0o600 });
|
|
46
|
+
await fs.chmod(filePath, 0o600).catch(() => {});
|
|
35
47
|
} catch (e) {
|
|
36
48
|
console.warn('Node.js filesystem modules not available, falling back to memory storage' + e);
|
|
37
49
|
memoryStorage[name] = value;
|
|
@@ -39,8 +51,7 @@ export const createNodeStorage = (): IStorage => {
|
|
|
39
51
|
},
|
|
40
52
|
removeItem: async (name: string) => {
|
|
41
53
|
try {
|
|
42
|
-
const
|
|
43
|
-
const filePath = join(storageDir, `${name}.json`);
|
|
54
|
+
const filePath = join(getStorageDir(), `${name}.json`);
|
|
44
55
|
await fs.unlink(filePath).catch(() => {});
|
|
45
56
|
} catch (e) {
|
|
46
57
|
console.warn('Node.js filesystem modules not available, falling back to memory storage' + e);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { createNodeStorage } from '../storage.js';
|
|
6
|
+
|
|
7
|
+
const withTempHome = async (fn: (home: string) => Promise<void>) => {
|
|
8
|
+
const home = await fs.mkdtemp(path.join(os.tmpdir(), 'cofhe-home-'));
|
|
9
|
+
const oldHome = process.env.HOME;
|
|
10
|
+
process.env.HOME = home;
|
|
11
|
+
try {
|
|
12
|
+
await fn(home);
|
|
13
|
+
} finally {
|
|
14
|
+
if (oldHome === undefined) delete process.env.HOME;
|
|
15
|
+
else process.env.HOME = oldHome;
|
|
16
|
+
await fs.rm(home, { recursive: true, force: true });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('node storage permissions', () => {
|
|
21
|
+
it.skipIf(process.platform === 'win32')('does not make stored data readable by other users', () =>
|
|
22
|
+
withTempHome(async (home) => {
|
|
23
|
+
await createNodeStorage().setItem('t', { value: 1 });
|
|
24
|
+
const st = await fs.stat(path.join(home, '.cofhesdk', 't.json'));
|
|
25
|
+
expect(st.mode & 0o077).toBe(0);
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
it.skipIf(process.platform === 'win32')('tightens permissions of a file created with loose permissions', () =>
|
|
30
|
+
withTempHome(async (home) => {
|
|
31
|
+
const dir = path.join(home, '.cofhesdk');
|
|
32
|
+
await fs.mkdir(dir, { mode: 0o755 });
|
|
33
|
+
const file = path.join(dir, 't.json');
|
|
34
|
+
await fs.writeFile(file, '{}', { mode: 0o644 });
|
|
35
|
+
await createNodeStorage().setItem('t', { value: 1 });
|
|
36
|
+
expect((await fs.stat(file)).mode & 0o077).toBe(0);
|
|
37
|
+
expect((await fs.stat(dir)).mode & 0o077).toBe(0);
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cofhe/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SDK for Fhenix COFHE coprocessor interaction",
|
|
6
6
|
"main": "./dist/core.cjs",
|
|
@@ -101,9 +101,9 @@
|
|
|
101
101
|
"tsup": "8.0.2",
|
|
102
102
|
"typescript": "5.5.4",
|
|
103
103
|
"vitest": "3.2.4",
|
|
104
|
-
"@cofhe/
|
|
104
|
+
"@cofhe/eslint-config": "0.2.1",
|
|
105
105
|
"@cofhe/tsconfig": "0.1.2",
|
|
106
|
-
"@cofhe/
|
|
106
|
+
"@cofhe/test-setup": "0.0.0"
|
|
107
107
|
},
|
|
108
108
|
"publishConfig": {
|
|
109
109
|
"access": "public",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"check:types": "tsc --noEmit",
|
|
117
117
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
118
118
|
"test": "vitest run",
|
|
119
|
-
"test:live": "vitest run core/test/decrypt.test.ts node/test/inherited.test.ts web/test/inherited.web.test.ts",
|
|
119
|
+
"test:live": "vitest run core/test/decrypt.test.ts acps/share-metadata/test/live.test.ts node/test/inherited.test.ts web/test/inherited.web.test.ts",
|
|
120
120
|
"test:threadpool": "vitest run web/test/threadPoolOff.web.test.ts web/test/threadPoolOn.web.test.ts web/test/mainThreadPool.web.test.ts web/test/workerInitRace.web.test.ts --no-file-parallelism",
|
|
121
121
|
"test:watch": "vitest",
|
|
122
122
|
"test:coverage": "vitest run --coverage"
|
package/web/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
fheTypeToString,
|
|
15
15
|
TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT,
|
|
16
16
|
} from '@/core';
|
|
17
|
+
import { fromHexString } from '../core/utils.js';
|
|
17
18
|
|
|
18
19
|
// Import web-specific storage (internal use only)
|
|
19
20
|
import { createSsrStorage, createWebStorage } from './storage.js';
|
|
@@ -116,16 +117,6 @@ function requireTfhe(): typeof import('tfhe') {
|
|
|
116
117
|
return tfheModule;
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
/**
|
|
120
|
-
* Utility to convert the hex string key to a Uint8Array for use with tfhe
|
|
121
|
-
*/
|
|
122
|
-
const fromHexString = (hexString: string): Uint8Array => {
|
|
123
|
-
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
124
|
-
const arr = cleanString.replace(/^0x/, '').match(/.{1,2}/g);
|
|
125
|
-
if (!arr) return new Uint8Array();
|
|
126
|
-
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
127
|
-
};
|
|
128
|
-
|
|
129
120
|
const _deserializeTfhePublicKey = (buff: string): TfheCompactPublicKey => {
|
|
130
121
|
return requireTfhe().TfheCompactPublicKey.safe_deserialize(
|
|
131
122
|
fromHexString(buff),
|
|
@@ -10,6 +10,7 @@ import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from '../../core/consts';
|
|
|
10
10
|
import { STAGING_TESTS } from '../../core/test/stagingRedirect';
|
|
11
11
|
import { arbSepolia as cofheArbSepolia, stagingCofhe } from '@/chains';
|
|
12
12
|
import { initTfheThreadPool, type TfheThreadPoolResult } from '../tfheThreadPool.js';
|
|
13
|
+
import { fromHexString } from '../../core/utils.js';
|
|
13
14
|
|
|
14
15
|
// Same backend as the rest of the web suite: Arbitrum Sepolia, or staging when
|
|
15
16
|
// TEST_STAGING_ENABLED=true.
|
|
@@ -30,13 +31,6 @@ declare const __THREADPOOL_TESTS__: boolean | undefined;
|
|
|
30
31
|
*/
|
|
31
32
|
export const THREADPOOL_TESTS = typeof __THREADPOOL_TESTS__ !== 'undefined' ? __THREADPOOL_TESTS__ : false;
|
|
32
33
|
|
|
33
|
-
function fromHexString(hexString: string): Uint8Array {
|
|
34
|
-
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
35
|
-
const arr = cleanString.replace(/^0x/, '').match(/.{1,2}/g);
|
|
36
|
-
if (!arr) return new Uint8Array();
|
|
37
|
-
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
34
|
/** Fetch the network's real FHE public key + CRS. Proving itself is fully local. */
|
|
41
35
|
export async function fetchNetworkKeys(securityZone = 0): Promise<{ fheKey: string; crs: string }> {
|
|
42
36
|
const post = async (path: string) => {
|
package/web/zkProve.worker.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from '../core/consts';
|
|
|
10
10
|
import type { ZkProveWorkerRequest, ZkProveWorkerResponse } from '../core/encrypt/zkPackProveVerify.js';
|
|
11
11
|
import { initTfheThreadPool, type TfheThreadPoolResult } from './tfheThreadPool.js';
|
|
12
12
|
import type { TfheThreadsSetting } from '../core/types.js';
|
|
13
|
+
import { fromHexString } from '../core/utils.js';
|
|
13
14
|
|
|
14
15
|
// TFHE module (will be initialized on first use)
|
|
15
16
|
let tfheModule: any = null;
|
|
@@ -57,16 +58,6 @@ function initTfhe(tfheThreads: TfheThreadsSetting = 'auto'): Promise<void> {
|
|
|
57
58
|
return initPromise;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
/**
|
|
61
|
-
* Convert hex string to Uint8Array
|
|
62
|
-
*/
|
|
63
|
-
function fromHexString(hexString: string): Uint8Array {
|
|
64
|
-
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
65
|
-
const arr = cleanString.replace(/^0x/, '').match(/.{1,2}/g);
|
|
66
|
-
if (!arr) return new Uint8Array();
|
|
67
|
-
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
61
|
// Guard the top-level `self` references so this file is safe to evaluate in
|
|
71
62
|
// non-worker contexts (e.g. when bundlers like webpack pull the worker chunk
|
|
72
63
|
// into the server bundle for SSR). The body is dead code anywhere `self` is
|
package/dist/chunk-NMKMCAI3.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// core/consts.ts
|
|
2
|
-
var COFHE_ADDRESS_BOOK_ADDRESS = "0xC0F4e00E531a2B086492Ae3DCC1515038307196b";
|
|
3
|
-
var TASK_MANAGER_ID = 1n;
|
|
4
|
-
var MOCKS_TASK_MANAGER_ADDRESS = "0x0000000000000000000000000000000000005000";
|
|
5
|
-
var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000005001";
|
|
6
|
-
var MOCKS_THRESHOLD_NETWORK_ADDRESS = "0x0000000000000000000000000000000000005002";
|
|
7
|
-
var MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY = "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
|
|
8
|
-
var MOCKS_ZK_VERIFIER_SIGNER_ADDRESS = "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
|
|
9
|
-
var MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
10
|
-
var TFHE_RS_ZK_MAX_BITS = 2048;
|
|
11
|
-
var TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT = BigInt(1 << 30);
|
|
12
|
-
var TFHE_RS_KEY_VERSION = 2;
|
|
13
|
-
|
|
14
|
-
export { COFHE_ADDRESS_BOOK_ADDRESS, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_TASK_MANAGER_ADDRESS, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ID, TFHE_RS_KEY_VERSION, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS };
|