@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
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { CofheError } from './chunk-J23FYAI2.js';
|
|
2
|
+
import 'viem';
|
|
3
|
+
|
|
4
|
+
// core/types.ts
|
|
5
|
+
var FheTypes = /* @__PURE__ */ ((FheTypes2) => {
|
|
6
|
+
FheTypes2[FheTypes2["Bool"] = 0] = "Bool";
|
|
7
|
+
FheTypes2[FheTypes2["Uint4"] = 1] = "Uint4";
|
|
8
|
+
FheTypes2[FheTypes2["Uint8"] = 2] = "Uint8";
|
|
9
|
+
FheTypes2[FheTypes2["Uint16"] = 3] = "Uint16";
|
|
10
|
+
FheTypes2[FheTypes2["Uint32"] = 4] = "Uint32";
|
|
11
|
+
FheTypes2[FheTypes2["Uint64"] = 5] = "Uint64";
|
|
12
|
+
FheTypes2[FheTypes2["Uint128"] = 6] = "Uint128";
|
|
13
|
+
FheTypes2[FheTypes2["Uint160"] = 7] = "Uint160";
|
|
14
|
+
FheTypes2[FheTypes2["Uint256"] = 8] = "Uint256";
|
|
15
|
+
FheTypes2[FheTypes2["Uint512"] = 9] = "Uint512";
|
|
16
|
+
FheTypes2[FheTypes2["Uint1024"] = 10] = "Uint1024";
|
|
17
|
+
FheTypes2[FheTypes2["Uint2048"] = 11] = "Uint2048";
|
|
18
|
+
FheTypes2[FheTypes2["Uint2"] = 12] = "Uint2";
|
|
19
|
+
FheTypes2[FheTypes2["Uint6"] = 13] = "Uint6";
|
|
20
|
+
FheTypes2[FheTypes2["Uint10"] = 14] = "Uint10";
|
|
21
|
+
FheTypes2[FheTypes2["Uint12"] = 15] = "Uint12";
|
|
22
|
+
FheTypes2[FheTypes2["Uint14"] = 16] = "Uint14";
|
|
23
|
+
FheTypes2[FheTypes2["Int2"] = 17] = "Int2";
|
|
24
|
+
FheTypes2[FheTypes2["Int4"] = 18] = "Int4";
|
|
25
|
+
FheTypes2[FheTypes2["Int6"] = 19] = "Int6";
|
|
26
|
+
FheTypes2[FheTypes2["Int8"] = 20] = "Int8";
|
|
27
|
+
FheTypes2[FheTypes2["Int10"] = 21] = "Int10";
|
|
28
|
+
FheTypes2[FheTypes2["Int12"] = 22] = "Int12";
|
|
29
|
+
FheTypes2[FheTypes2["Int14"] = 23] = "Int14";
|
|
30
|
+
FheTypes2[FheTypes2["Int16"] = 24] = "Int16";
|
|
31
|
+
FheTypes2[FheTypes2["Int32"] = 25] = "Int32";
|
|
32
|
+
FheTypes2[FheTypes2["Int64"] = 26] = "Int64";
|
|
33
|
+
FheTypes2[FheTypes2["Int128"] = 27] = "Int128";
|
|
34
|
+
FheTypes2[FheTypes2["Int160"] = 28] = "Int160";
|
|
35
|
+
FheTypes2[FheTypes2["Int256"] = 29] = "Int256";
|
|
36
|
+
return FheTypes2;
|
|
37
|
+
})(FheTypes || {});
|
|
38
|
+
var FheUintUTypes = [
|
|
39
|
+
2 /* Uint8 */,
|
|
40
|
+
3 /* Uint16 */,
|
|
41
|
+
4 /* Uint32 */,
|
|
42
|
+
5 /* Uint64 */,
|
|
43
|
+
6 /* Uint128 */
|
|
44
|
+
// [U256-DISABLED]
|
|
45
|
+
// FheTypes.Uint256,
|
|
46
|
+
];
|
|
47
|
+
var FheAllUTypes = [
|
|
48
|
+
0 /* Bool */,
|
|
49
|
+
2 /* Uint8 */,
|
|
50
|
+
3 /* Uint16 */,
|
|
51
|
+
4 /* Uint32 */,
|
|
52
|
+
5 /* Uint64 */,
|
|
53
|
+
6 /* Uint128 */,
|
|
54
|
+
// [U256-DISABLED]
|
|
55
|
+
// FheTypes.Uint256,
|
|
56
|
+
7 /* Uint160 */
|
|
57
|
+
];
|
|
58
|
+
var EncryptableFactoriesImpl = {
|
|
59
|
+
bool: (data, securityZone = 0) => ({ data, securityZone, utype: 0 /* Bool */ }),
|
|
60
|
+
address: (data, securityZone = 0) => ({ data, securityZone, utype: 7 /* Uint160 */ }),
|
|
61
|
+
uint8: (data, securityZone = 0) => ({ data, securityZone, utype: 2 /* Uint8 */ }),
|
|
62
|
+
uint16: (data, securityZone = 0) => ({ data, securityZone, utype: 3 /* Uint16 */ }),
|
|
63
|
+
uint32: (data, securityZone = 0) => ({ data, securityZone, utype: 4 /* Uint32 */ }),
|
|
64
|
+
uint64: (data, securityZone = 0) => ({ data, securityZone, utype: 5 /* Uint64 */ }),
|
|
65
|
+
uint128: (data, securityZone = 0) => ({ data, securityZone, utype: 6 /* Uint128 */ })
|
|
66
|
+
// [U256-DISABLED]
|
|
67
|
+
// uint256: (data: EncryptableUint256['data'], securityZone = 0) =>
|
|
68
|
+
// ({ data, securityZone, utype: FheTypes.Uint256 }) as EncryptableUint256,
|
|
69
|
+
};
|
|
70
|
+
function createEncryptableByLiteral(type, data, securityZone = 0) {
|
|
71
|
+
switch (type) {
|
|
72
|
+
case "bool": {
|
|
73
|
+
if (typeof data !== "boolean")
|
|
74
|
+
throw new Error("Bool encryptable data must be boolean");
|
|
75
|
+
return EncryptableFactoriesImpl.bool(data, securityZone);
|
|
76
|
+
}
|
|
77
|
+
case "address":
|
|
78
|
+
case "uint8":
|
|
79
|
+
case "uint16":
|
|
80
|
+
case "uint32":
|
|
81
|
+
case "uint64":
|
|
82
|
+
case "uint128": {
|
|
83
|
+
if (typeof data === "boolean")
|
|
84
|
+
throw new Error("Uint encryptable data must be string or bigint");
|
|
85
|
+
return EncryptableFactoriesImpl[type](data, securityZone);
|
|
86
|
+
}
|
|
87
|
+
default: {
|
|
88
|
+
const _exhaustive = type;
|
|
89
|
+
throw new Error(`Unsupported encryptable type: ${_exhaustive}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var Encryptable = {
|
|
94
|
+
...EncryptableFactoriesImpl,
|
|
95
|
+
create: createEncryptableByLiteral
|
|
96
|
+
};
|
|
97
|
+
function isEncryptableItem(value) {
|
|
98
|
+
return (
|
|
99
|
+
// Is object and exists
|
|
100
|
+
typeof value === "object" && value !== null && // Has securityZone
|
|
101
|
+
"securityZone" in value && typeof value.securityZone === "number" && // Has utype
|
|
102
|
+
"utype" in value && FheAllUTypes.includes(value.utype) && // Has data
|
|
103
|
+
"data" in value && ["string", "number", "bigint", "boolean"].includes(typeof value.data)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
var EncryptStep = /* @__PURE__ */ ((EncryptStep2) => {
|
|
107
|
+
EncryptStep2["InitTfhe"] = "initTfhe";
|
|
108
|
+
EncryptStep2["FetchKeys"] = "fetchKeys";
|
|
109
|
+
EncryptStep2["Pack"] = "pack";
|
|
110
|
+
EncryptStep2["Prove"] = "prove";
|
|
111
|
+
EncryptStep2["Verify"] = "verify";
|
|
112
|
+
return EncryptStep2;
|
|
113
|
+
})(EncryptStep || {});
|
|
114
|
+
function isLastEncryptionStep(step) {
|
|
115
|
+
return step === "verify" /* Verify */;
|
|
116
|
+
}
|
|
117
|
+
var toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
118
|
+
var HEX_BODY_REGEX = /^[0-9a-fA-F]*$/;
|
|
119
|
+
var fromHexString = (hexString) => {
|
|
120
|
+
const body = hexString.replace(/^0x/, "");
|
|
121
|
+
if (!HEX_BODY_REGEX.test(body)) {
|
|
122
|
+
throw new Error("Invalid hex string: contains non-hexadecimal characters");
|
|
123
|
+
}
|
|
124
|
+
const padded = body.length % 2 === 1 ? `0${body}` : body;
|
|
125
|
+
const arr = padded.match(/.{1,2}/g);
|
|
126
|
+
if (!arr)
|
|
127
|
+
return new Uint8Array();
|
|
128
|
+
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
129
|
+
};
|
|
130
|
+
var toBigIntOrThrow = (value) => {
|
|
131
|
+
if (typeof value === "bigint") {
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return BigInt(value);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw new Error("Invalid input: Unable to convert to bigint");
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var validateBigIntInRange = (value, max, min = 0n) => {
|
|
141
|
+
if (typeof value !== "bigint") {
|
|
142
|
+
throw new Error("Value must be of type bigint");
|
|
143
|
+
}
|
|
144
|
+
if (value > max || value < min) {
|
|
145
|
+
throw new Error(`Value out of range: ${max} - ${min}, try a different uint type`);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var hexToBytes = (hex) => fromHexString(hex);
|
|
149
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
150
|
+
async function getPublicClientChainID(publicClient) {
|
|
151
|
+
let chainId = null;
|
|
152
|
+
try {
|
|
153
|
+
chainId = publicClient.chain?.id ?? await publicClient.getChainId();
|
|
154
|
+
} catch (e) {
|
|
155
|
+
throw new CofheError({
|
|
156
|
+
code: "PUBLIC_WALLET_GET_CHAIN_ID_FAILED" /* PublicWalletGetChainIdFailed */,
|
|
157
|
+
message: "getting chain ID from public client failed",
|
|
158
|
+
cause: e instanceof Error ? e : void 0
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (chainId === null) {
|
|
162
|
+
throw new CofheError({
|
|
163
|
+
code: "PUBLIC_WALLET_GET_CHAIN_ID_FAILED" /* PublicWalletGetChainIdFailed */,
|
|
164
|
+
message: "chain ID from public client is null"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return chainId;
|
|
168
|
+
}
|
|
169
|
+
async function getWalletClientAccount(walletClient) {
|
|
170
|
+
let address;
|
|
171
|
+
try {
|
|
172
|
+
address = walletClient.account?.address;
|
|
173
|
+
if (!address) {
|
|
174
|
+
address = (await walletClient.getAddresses())?.[0];
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
throw new CofheError({
|
|
178
|
+
code: "PUBLIC_WALLET_GET_ADDRESSES_FAILED" /* PublicWalletGetAddressesFailed */,
|
|
179
|
+
message: "getting address from wallet client failed",
|
|
180
|
+
cause: e instanceof Error ? e : void 0
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (!address) {
|
|
184
|
+
throw new CofheError({
|
|
185
|
+
code: "PUBLIC_WALLET_GET_ADDRESSES_FAILED" /* PublicWalletGetAddressesFailed */,
|
|
186
|
+
message: "address from wallet client is null"
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return address;
|
|
190
|
+
}
|
|
191
|
+
function fheTypeToString(utype) {
|
|
192
|
+
switch (utype) {
|
|
193
|
+
case 0 /* Bool */:
|
|
194
|
+
return "bool";
|
|
195
|
+
case 1 /* Uint4 */:
|
|
196
|
+
return "uint4";
|
|
197
|
+
case 2 /* Uint8 */:
|
|
198
|
+
return "uint8";
|
|
199
|
+
case 3 /* Uint16 */:
|
|
200
|
+
return "uint16";
|
|
201
|
+
case 4 /* Uint32 */:
|
|
202
|
+
return "uint32";
|
|
203
|
+
case 5 /* Uint64 */:
|
|
204
|
+
return "uint64";
|
|
205
|
+
case 6 /* Uint128 */:
|
|
206
|
+
return "uint128";
|
|
207
|
+
case 7 /* Uint160 */:
|
|
208
|
+
return "uint160";
|
|
209
|
+
case 8 /* Uint256 */:
|
|
210
|
+
return "uint256";
|
|
211
|
+
case 9 /* Uint512 */:
|
|
212
|
+
return "uint512";
|
|
213
|
+
case 10 /* Uint1024 */:
|
|
214
|
+
return "uint1024";
|
|
215
|
+
case 11 /* Uint2048 */:
|
|
216
|
+
return "uint2048";
|
|
217
|
+
case 12 /* Uint2 */:
|
|
218
|
+
return "uint2";
|
|
219
|
+
case 13 /* Uint6 */:
|
|
220
|
+
return "uint6";
|
|
221
|
+
case 14 /* Uint10 */:
|
|
222
|
+
return "uint10";
|
|
223
|
+
default:
|
|
224
|
+
throw new Error(`Unknown FheType: ${utype}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, fheTypeToString, fromHexString, getPublicClientChainID, getWalletClientAccount, hexToBytes, isEncryptableItem, isLastEncryptionStep, sleep, toBigIntOrThrow, toHexString, validateBigIntInRange };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Hex } from 'viem';
|
|
2
2
|
import { C as CofheChain } from './types-C07FK-cL.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as ACP,
|
|
4
|
+
import { A as ACP, k as EIP712Domain, C as CreateSelfACPOptions, J as SelfACP, g as CreateSharingACPOptions, K as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, P as ACPHashFields, f as SerializedACP, O as ACPAccessStatus, S as ShareLabel, j as IncomingShare, p as AclServedAddresses, L as LabelledShare, w as ShareLabelVerifyMode, x as ShareLabelCheck, l as ACPUtils } from './onchain-utils-CgOslubH.cjs';
|
|
5
5
|
import { StoreApi } from 'zustand/vanilla';
|
|
6
6
|
|
|
7
7
|
type TfheInitializer = () => Promise<boolean>;
|
|
@@ -280,6 +280,13 @@ type CofheConfig = {
|
|
|
280
280
|
* names a registry.
|
|
281
281
|
*/
|
|
282
282
|
sharingRegistry?: Record<number, `0x${string}`>;
|
|
283
|
+
/**
|
|
284
|
+
* The name of this app, e.g. 'explorer.fhenix.io'. Set, every share the client creates
|
|
285
|
+
* carries the app's key (`shareAppKey(app)`, kept in the share metadata), and
|
|
286
|
+
* `getIncomingShares` lists only the shares posted for this app. Unset, shares carry no
|
|
287
|
+
* key and every importable share is listed.
|
|
288
|
+
*/
|
|
289
|
+
app?: string;
|
|
283
290
|
};
|
|
284
291
|
/** Mocks configs */
|
|
285
292
|
mocks: {
|
|
@@ -341,6 +348,7 @@ declare const CofheConfigSchema: z.ZodObject<{
|
|
|
341
348
|
defaultRevoker: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
|
|
342
349
|
defaultContractScopes: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`[]>, Record<number, `0x${string}`[]>>>;
|
|
343
350
|
sharingRegistry: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
|
|
351
|
+
app: z.ZodOptional<z.ZodString>;
|
|
344
352
|
}, z.core.$strip>>>;
|
|
345
353
|
mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
346
354
|
decryptDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -1015,6 +1023,25 @@ type ImportActivationOptions = {
|
|
|
1015
1023
|
*/
|
|
1016
1024
|
activate?: boolean;
|
|
1017
1025
|
};
|
|
1026
|
+
/** Options for importing a shared acp: activation, and the recipient's own name for it. */
|
|
1027
|
+
type ImportSharedOptions = ImportActivationOptions & {
|
|
1028
|
+
/**
|
|
1029
|
+
* The name of the imported acp. Defaults to "Shared by 0x1234…abcd" (its issuer); the issuer's
|
|
1030
|
+
* own name for the share is not exported and is ignored if present.
|
|
1031
|
+
*/
|
|
1032
|
+
name?: string;
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* What `shareOnChain` posts with a share: the labels of its handles (one per handle, in order;
|
|
1036
|
+
* encoded with `encodeShareMetadata`), or an already encoded metadata blob. Written once, with the
|
|
1037
|
+
* share. Omitted, the labels the acp was created with are posted (`createSharing({ labels })`),
|
|
1038
|
+
* or none. `appKey` goes with given labels; a client configured with `acp: { app }` fills it in.
|
|
1039
|
+
*/
|
|
1040
|
+
type ShareOnChainOptions = {
|
|
1041
|
+
labels?: readonly ShareLabel[];
|
|
1042
|
+
metadata?: Hex;
|
|
1043
|
+
appKey?: Hex;
|
|
1044
|
+
};
|
|
1018
1045
|
declare const acps: {
|
|
1019
1046
|
getSnapshot: () => {
|
|
1020
1047
|
acps: {
|
|
@@ -1025,6 +1052,7 @@ declare const acps: {
|
|
|
1025
1052
|
name: string;
|
|
1026
1053
|
type: "self" | "sharing" | "recipient";
|
|
1027
1054
|
sealingPrivateKey: Hex;
|
|
1055
|
+
metadata?: Hex | undefined;
|
|
1028
1056
|
_signedDomain?: EIP712Domain | undefined;
|
|
1029
1057
|
issuer: Hex;
|
|
1030
1058
|
expiration: number;
|
|
@@ -1056,6 +1084,7 @@ declare const acps: {
|
|
|
1056
1084
|
name: string;
|
|
1057
1085
|
type: "self" | "sharing" | "recipient";
|
|
1058
1086
|
sealingPrivateKey: Hex;
|
|
1087
|
+
metadata?: Hex | undefined;
|
|
1059
1088
|
_signedDomain?: EIP712Domain | undefined;
|
|
1060
1089
|
issuer: Hex;
|
|
1061
1090
|
expiration: number;
|
|
@@ -1086,6 +1115,7 @@ declare const acps: {
|
|
|
1086
1115
|
name: string;
|
|
1087
1116
|
type: "self" | "sharing" | "recipient";
|
|
1088
1117
|
sealingPrivateKey: Hex;
|
|
1118
|
+
metadata?: Hex | undefined;
|
|
1089
1119
|
_signedDomain?: EIP712Domain | undefined;
|
|
1090
1120
|
issuer: Hex;
|
|
1091
1121
|
expiration: number;
|
|
@@ -1110,7 +1140,7 @@ declare const acps: {
|
|
|
1110
1140
|
}) => void) => () => void;
|
|
1111
1141
|
createSelf: (options: CreateSelfACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfACP>;
|
|
1112
1142
|
createSharing: (options: CreateSharingACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingACP>;
|
|
1113
|
-
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate }?:
|
|
1143
|
+
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate, name }?: ImportSharedOptions) => Promise<RecipientACP>;
|
|
1114
1144
|
getOrCreateSelfACP: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfACPOptions) => Promise<ACP>;
|
|
1115
1145
|
getOrCreateSharingACP: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingACPOptions, chainId?: number, account?: string) => Promise<ACP>;
|
|
1116
1146
|
getHash: (acp: ACPHashFields) => string;
|
|
@@ -1120,6 +1150,7 @@ declare const acps: {
|
|
|
1120
1150
|
name: string;
|
|
1121
1151
|
type: "self" | "sharing" | "recipient";
|
|
1122
1152
|
sealingPrivateKey: Hex;
|
|
1153
|
+
metadata?: Hex | undefined;
|
|
1123
1154
|
_signedDomain?: EIP712Domain | undefined;
|
|
1124
1155
|
issuer: Hex;
|
|
1125
1156
|
expiration: number;
|
|
@@ -1138,6 +1169,7 @@ declare const acps: {
|
|
|
1138
1169
|
name: string;
|
|
1139
1170
|
type: "self" | "sharing" | "recipient";
|
|
1140
1171
|
sealingPrivateKey: Hex;
|
|
1172
|
+
metadata?: Hex | undefined;
|
|
1141
1173
|
_signedDomain?: EIP712Domain | undefined;
|
|
1142
1174
|
issuer: Hex;
|
|
1143
1175
|
expiration: number;
|
|
@@ -1162,24 +1194,17 @@ declare const acps: {
|
|
|
1162
1194
|
revokeAllACPs: (walletClient: WalletClient, publicClient: PublicClient, revokerContract?: Hex) => Promise<Hex>;
|
|
1163
1195
|
isACPRevoked: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
|
|
1164
1196
|
checkAccess: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
|
|
1165
|
-
shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex) => Promise<{
|
|
1197
|
+
shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex, options?: ShareOnChainOptions) => Promise<{
|
|
1166
1198
|
txHash: Hex;
|
|
1167
1199
|
shareId: Hex;
|
|
1168
1200
|
}>;
|
|
1169
|
-
getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex
|
|
1170
|
-
|
|
1201
|
+
getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex, { appKey }?: {
|
|
1202
|
+
appKey?: Hex;
|
|
1203
|
+
}) => Promise<IncomingShare[]>;
|
|
1204
|
+
getShareFromChain: (publicClient: PublicClient, registry: Hex, shareId: Hex) => Promise<IncomingShare | null>;
|
|
1205
|
+
importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportSharedOptions) => Promise<RecipientACP>;
|
|
1171
1206
|
removeShareOnChain: (shareId: Hex, walletClient: WalletClient, registry: Hex) => Promise<Hex>;
|
|
1172
1207
|
computeShareId: (acp: ACP) => Hex;
|
|
1173
|
-
applyACPDefaults: <T extends {
|
|
1174
|
-
revokerData?: number;
|
|
1175
|
-
revokerContract?: string;
|
|
1176
|
-
scope?: number;
|
|
1177
|
-
contracts?: string[];
|
|
1178
|
-
handles?: (bigint | number | string)[];
|
|
1179
|
-
}>(options: T, acpConfig: {
|
|
1180
|
-
defaultRevoker?: Record<number, Hex>;
|
|
1181
|
-
defaultContractScopes?: Record<number, Hex[]>;
|
|
1182
|
-
} | undefined, chainId: number) => T;
|
|
1183
1208
|
applyACPDefaultsFromChain: <T extends {
|
|
1184
1209
|
revokerData?: number;
|
|
1185
1210
|
revokerContract?: string;
|
|
@@ -1238,9 +1263,10 @@ type CofheClientACPsClients = {
|
|
|
1238
1263
|
};
|
|
1239
1264
|
/**
|
|
1240
1265
|
* Options for `importShared`. `activate: false` stores the imported acp without making it the active
|
|
1241
|
-
* one (default `true`).
|
|
1266
|
+
* one (default `true`). `name` names it (default "Shared by 0x1234…abcd"). Clients default to the
|
|
1267
|
+
* connected ones; pass both to override.
|
|
1242
1268
|
*/
|
|
1243
|
-
type CofheClientImportSharedOptions =
|
|
1269
|
+
type CofheClientImportSharedOptions = ImportSharedOptions & (CofheClientACPsClients | {
|
|
1244
1270
|
publicClient?: undefined;
|
|
1245
1271
|
walletClient?: undefined;
|
|
1246
1272
|
});
|
|
@@ -1269,15 +1295,29 @@ type CofheClientACPs = {
|
|
|
1269
1295
|
* 'sharing', no recipient signature yet) the handle-less check covers expiry and revocation only.
|
|
1270
1296
|
*/
|
|
1271
1297
|
checkAccess: (acp: ACP, handle?: bigint | `0x${string}`) => Promise<ACPAccessStatus>;
|
|
1272
|
-
/**
|
|
1273
|
-
|
|
1298
|
+
/**
|
|
1299
|
+
* Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`),
|
|
1300
|
+
* optionally with the labels of its handles (`options.labels`, one per handle) or an encoded blob.
|
|
1301
|
+
*/
|
|
1302
|
+
shareOnChain: (acp: ACP, options?: ShareOnChainOptions) => Promise<{
|
|
1274
1303
|
txHash: `0x${string}`;
|
|
1275
1304
|
shareId: `0x${string}`;
|
|
1276
1305
|
}>;
|
|
1277
|
-
/** Importable shares addressed to the connected account (unexpired, not revoked). */
|
|
1306
|
+
/** Importable shares addressed to the connected account (unexpired, not revoked), with their metadata. */
|
|
1278
1307
|
getIncomingShares: () => Promise<IncomingShare[]>;
|
|
1308
|
+
/** One share by id, as posted; null when unknown or removed. */
|
|
1309
|
+
getShareFromChain: (shareId: `0x${string}`) => Promise<IncomingShare | null>;
|
|
1310
|
+
/**
|
|
1311
|
+
* Check a share's labels against the chain, index for index with its handles, as far as
|
|
1312
|
+
* `verify` says (default 'all'). Takes a share read from the registry or an acp imported from
|
|
1313
|
+
* exported JSON (or the issuer's sharing acp). Null for a share without metadata. Throws on a
|
|
1314
|
+
* malformed blob.
|
|
1315
|
+
*/
|
|
1316
|
+
verifyShareLabels: (share: LabelledShare, options?: {
|
|
1317
|
+
verify?: ShareLabelVerifyMode;
|
|
1318
|
+
}) => Promise<ShareLabelCheck[] | null>;
|
|
1279
1319
|
/** Import a share read from the registry: sign as recipient, store and (unless `activate: false`) activate. */
|
|
1280
|
-
importFromChain: (share: IncomingShare, options?:
|
|
1320
|
+
importFromChain: (share: IncomingShare, options?: ImportSharedOptions) => Promise<RecipientACP>;
|
|
1281
1321
|
/** Recipient-side: remove a share from the registry (after import, or to decline). */
|
|
1282
1322
|
dismissShare: (shareId: `0x${string}`) => Promise<`0x${string}`>;
|
|
1283
1323
|
/** Issuer-side: retract a pending share from the registry. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Hex } from 'viem';
|
|
2
2
|
import { C as CofheChain } from './types-C07FK-cL.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as ACP,
|
|
4
|
+
import { A as ACP, k as EIP712Domain, C as CreateSelfACPOptions, J as SelfACP, g as CreateSharingACPOptions, K as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, P as ACPHashFields, f as SerializedACP, O as ACPAccessStatus, S as ShareLabel, j as IncomingShare, p as AclServedAddresses, L as LabelledShare, w as ShareLabelVerifyMode, x as ShareLabelCheck, l as ACPUtils } from './onchain-utils-CgOslubH.js';
|
|
5
5
|
import { StoreApi } from 'zustand/vanilla';
|
|
6
6
|
|
|
7
7
|
type TfheInitializer = () => Promise<boolean>;
|
|
@@ -280,6 +280,13 @@ type CofheConfig = {
|
|
|
280
280
|
* names a registry.
|
|
281
281
|
*/
|
|
282
282
|
sharingRegistry?: Record<number, `0x${string}`>;
|
|
283
|
+
/**
|
|
284
|
+
* The name of this app, e.g. 'explorer.fhenix.io'. Set, every share the client creates
|
|
285
|
+
* carries the app's key (`shareAppKey(app)`, kept in the share metadata), and
|
|
286
|
+
* `getIncomingShares` lists only the shares posted for this app. Unset, shares carry no
|
|
287
|
+
* key and every importable share is listed.
|
|
288
|
+
*/
|
|
289
|
+
app?: string;
|
|
283
290
|
};
|
|
284
291
|
/** Mocks configs */
|
|
285
292
|
mocks: {
|
|
@@ -341,6 +348,7 @@ declare const CofheConfigSchema: z.ZodObject<{
|
|
|
341
348
|
defaultRevoker: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
|
|
342
349
|
defaultContractScopes: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`[]>, Record<number, `0x${string}`[]>>>;
|
|
343
350
|
sharingRegistry: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
|
|
351
|
+
app: z.ZodOptional<z.ZodString>;
|
|
344
352
|
}, z.core.$strip>>>;
|
|
345
353
|
mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
346
354
|
decryptDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -1015,6 +1023,25 @@ type ImportActivationOptions = {
|
|
|
1015
1023
|
*/
|
|
1016
1024
|
activate?: boolean;
|
|
1017
1025
|
};
|
|
1026
|
+
/** Options for importing a shared acp: activation, and the recipient's own name for it. */
|
|
1027
|
+
type ImportSharedOptions = ImportActivationOptions & {
|
|
1028
|
+
/**
|
|
1029
|
+
* The name of the imported acp. Defaults to "Shared by 0x1234…abcd" (its issuer); the issuer's
|
|
1030
|
+
* own name for the share is not exported and is ignored if present.
|
|
1031
|
+
*/
|
|
1032
|
+
name?: string;
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* What `shareOnChain` posts with a share: the labels of its handles (one per handle, in order;
|
|
1036
|
+
* encoded with `encodeShareMetadata`), or an already encoded metadata blob. Written once, with the
|
|
1037
|
+
* share. Omitted, the labels the acp was created with are posted (`createSharing({ labels })`),
|
|
1038
|
+
* or none. `appKey` goes with given labels; a client configured with `acp: { app }` fills it in.
|
|
1039
|
+
*/
|
|
1040
|
+
type ShareOnChainOptions = {
|
|
1041
|
+
labels?: readonly ShareLabel[];
|
|
1042
|
+
metadata?: Hex;
|
|
1043
|
+
appKey?: Hex;
|
|
1044
|
+
};
|
|
1018
1045
|
declare const acps: {
|
|
1019
1046
|
getSnapshot: () => {
|
|
1020
1047
|
acps: {
|
|
@@ -1025,6 +1052,7 @@ declare const acps: {
|
|
|
1025
1052
|
name: string;
|
|
1026
1053
|
type: "self" | "sharing" | "recipient";
|
|
1027
1054
|
sealingPrivateKey: Hex;
|
|
1055
|
+
metadata?: Hex | undefined;
|
|
1028
1056
|
_signedDomain?: EIP712Domain | undefined;
|
|
1029
1057
|
issuer: Hex;
|
|
1030
1058
|
expiration: number;
|
|
@@ -1056,6 +1084,7 @@ declare const acps: {
|
|
|
1056
1084
|
name: string;
|
|
1057
1085
|
type: "self" | "sharing" | "recipient";
|
|
1058
1086
|
sealingPrivateKey: Hex;
|
|
1087
|
+
metadata?: Hex | undefined;
|
|
1059
1088
|
_signedDomain?: EIP712Domain | undefined;
|
|
1060
1089
|
issuer: Hex;
|
|
1061
1090
|
expiration: number;
|
|
@@ -1086,6 +1115,7 @@ declare const acps: {
|
|
|
1086
1115
|
name: string;
|
|
1087
1116
|
type: "self" | "sharing" | "recipient";
|
|
1088
1117
|
sealingPrivateKey: Hex;
|
|
1118
|
+
metadata?: Hex | undefined;
|
|
1089
1119
|
_signedDomain?: EIP712Domain | undefined;
|
|
1090
1120
|
issuer: Hex;
|
|
1091
1121
|
expiration: number;
|
|
@@ -1110,7 +1140,7 @@ declare const acps: {
|
|
|
1110
1140
|
}) => void) => () => void;
|
|
1111
1141
|
createSelf: (options: CreateSelfACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfACP>;
|
|
1112
1142
|
createSharing: (options: CreateSharingACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingACP>;
|
|
1113
|
-
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate }?:
|
|
1143
|
+
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate, name }?: ImportSharedOptions) => Promise<RecipientACP>;
|
|
1114
1144
|
getOrCreateSelfACP: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfACPOptions) => Promise<ACP>;
|
|
1115
1145
|
getOrCreateSharingACP: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingACPOptions, chainId?: number, account?: string) => Promise<ACP>;
|
|
1116
1146
|
getHash: (acp: ACPHashFields) => string;
|
|
@@ -1120,6 +1150,7 @@ declare const acps: {
|
|
|
1120
1150
|
name: string;
|
|
1121
1151
|
type: "self" | "sharing" | "recipient";
|
|
1122
1152
|
sealingPrivateKey: Hex;
|
|
1153
|
+
metadata?: Hex | undefined;
|
|
1123
1154
|
_signedDomain?: EIP712Domain | undefined;
|
|
1124
1155
|
issuer: Hex;
|
|
1125
1156
|
expiration: number;
|
|
@@ -1138,6 +1169,7 @@ declare const acps: {
|
|
|
1138
1169
|
name: string;
|
|
1139
1170
|
type: "self" | "sharing" | "recipient";
|
|
1140
1171
|
sealingPrivateKey: Hex;
|
|
1172
|
+
metadata?: Hex | undefined;
|
|
1141
1173
|
_signedDomain?: EIP712Domain | undefined;
|
|
1142
1174
|
issuer: Hex;
|
|
1143
1175
|
expiration: number;
|
|
@@ -1162,24 +1194,17 @@ declare const acps: {
|
|
|
1162
1194
|
revokeAllACPs: (walletClient: WalletClient, publicClient: PublicClient, revokerContract?: Hex) => Promise<Hex>;
|
|
1163
1195
|
isACPRevoked: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
|
|
1164
1196
|
checkAccess: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
|
|
1165
|
-
shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex) => Promise<{
|
|
1197
|
+
shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex, options?: ShareOnChainOptions) => Promise<{
|
|
1166
1198
|
txHash: Hex;
|
|
1167
1199
|
shareId: Hex;
|
|
1168
1200
|
}>;
|
|
1169
|
-
getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex
|
|
1170
|
-
|
|
1201
|
+
getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex, { appKey }?: {
|
|
1202
|
+
appKey?: Hex;
|
|
1203
|
+
}) => Promise<IncomingShare[]>;
|
|
1204
|
+
getShareFromChain: (publicClient: PublicClient, registry: Hex, shareId: Hex) => Promise<IncomingShare | null>;
|
|
1205
|
+
importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportSharedOptions) => Promise<RecipientACP>;
|
|
1171
1206
|
removeShareOnChain: (shareId: Hex, walletClient: WalletClient, registry: Hex) => Promise<Hex>;
|
|
1172
1207
|
computeShareId: (acp: ACP) => Hex;
|
|
1173
|
-
applyACPDefaults: <T extends {
|
|
1174
|
-
revokerData?: number;
|
|
1175
|
-
revokerContract?: string;
|
|
1176
|
-
scope?: number;
|
|
1177
|
-
contracts?: string[];
|
|
1178
|
-
handles?: (bigint | number | string)[];
|
|
1179
|
-
}>(options: T, acpConfig: {
|
|
1180
|
-
defaultRevoker?: Record<number, Hex>;
|
|
1181
|
-
defaultContractScopes?: Record<number, Hex[]>;
|
|
1182
|
-
} | undefined, chainId: number) => T;
|
|
1183
1208
|
applyACPDefaultsFromChain: <T extends {
|
|
1184
1209
|
revokerData?: number;
|
|
1185
1210
|
revokerContract?: string;
|
|
@@ -1238,9 +1263,10 @@ type CofheClientACPsClients = {
|
|
|
1238
1263
|
};
|
|
1239
1264
|
/**
|
|
1240
1265
|
* Options for `importShared`. `activate: false` stores the imported acp without making it the active
|
|
1241
|
-
* one (default `true`).
|
|
1266
|
+
* one (default `true`). `name` names it (default "Shared by 0x1234…abcd"). Clients default to the
|
|
1267
|
+
* connected ones; pass both to override.
|
|
1242
1268
|
*/
|
|
1243
|
-
type CofheClientImportSharedOptions =
|
|
1269
|
+
type CofheClientImportSharedOptions = ImportSharedOptions & (CofheClientACPsClients | {
|
|
1244
1270
|
publicClient?: undefined;
|
|
1245
1271
|
walletClient?: undefined;
|
|
1246
1272
|
});
|
|
@@ -1269,15 +1295,29 @@ type CofheClientACPs = {
|
|
|
1269
1295
|
* 'sharing', no recipient signature yet) the handle-less check covers expiry and revocation only.
|
|
1270
1296
|
*/
|
|
1271
1297
|
checkAccess: (acp: ACP, handle?: bigint | `0x${string}`) => Promise<ACPAccessStatus>;
|
|
1272
|
-
/**
|
|
1273
|
-
|
|
1298
|
+
/**
|
|
1299
|
+
* Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`),
|
|
1300
|
+
* optionally with the labels of its handles (`options.labels`, one per handle) or an encoded blob.
|
|
1301
|
+
*/
|
|
1302
|
+
shareOnChain: (acp: ACP, options?: ShareOnChainOptions) => Promise<{
|
|
1274
1303
|
txHash: `0x${string}`;
|
|
1275
1304
|
shareId: `0x${string}`;
|
|
1276
1305
|
}>;
|
|
1277
|
-
/** Importable shares addressed to the connected account (unexpired, not revoked). */
|
|
1306
|
+
/** Importable shares addressed to the connected account (unexpired, not revoked), with their metadata. */
|
|
1278
1307
|
getIncomingShares: () => Promise<IncomingShare[]>;
|
|
1308
|
+
/** One share by id, as posted; null when unknown or removed. */
|
|
1309
|
+
getShareFromChain: (shareId: `0x${string}`) => Promise<IncomingShare | null>;
|
|
1310
|
+
/**
|
|
1311
|
+
* Check a share's labels against the chain, index for index with its handles, as far as
|
|
1312
|
+
* `verify` says (default 'all'). Takes a share read from the registry or an acp imported from
|
|
1313
|
+
* exported JSON (or the issuer's sharing acp). Null for a share without metadata. Throws on a
|
|
1314
|
+
* malformed blob.
|
|
1315
|
+
*/
|
|
1316
|
+
verifyShareLabels: (share: LabelledShare, options?: {
|
|
1317
|
+
verify?: ShareLabelVerifyMode;
|
|
1318
|
+
}) => Promise<ShareLabelCheck[] | null>;
|
|
1279
1319
|
/** Import a share read from the registry: sign as recipient, store and (unless `activate: false`) activate. */
|
|
1280
|
-
importFromChain: (share: IncomingShare, options?:
|
|
1320
|
+
importFromChain: (share: IncomingShare, options?: ImportSharedOptions) => Promise<RecipientACP>;
|
|
1281
1321
|
/** Recipient-side: remove a share from the registry (after import, or to decline). */
|
|
1282
1322
|
dismissShare: (shareId: `0x${string}`) => Promise<`0x${string}`>;
|
|
1283
1323
|
/** Issuer-side: retract a pending share from the registry. */
|