@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { hardhat as hardhat$1 } from './chunk-UKQAJK4N.js';
|
|
2
|
-
import { acpStore,
|
|
3
|
-
import {
|
|
2
|
+
import { acpStore, clearAclServedAddresses, getAclServedAddresses, computeShareId, ACPUtils, getTaskManagerAddress, verifyShareLabels, decodeShareMetadata, shareAppKey, ACP_SHARE_REGISTRY_ABI, readShare, readSharesFor, toChainShare, ACP_REVOKER_ABI, decodeShareAppKey, encodeShareMetadata } from './chunk-3L2IVPMI.js';
|
|
3
|
+
import { sleep, getPublicClientChainID, getWalletClientAccount, validateBigIntInRange, toBigIntOrThrow, hexToBytes, toHexString, FheUintUTypes } from './chunk-WJGTPW7K.js';
|
|
4
|
+
import { TFHE_RS_KEY_VERSION, CofheError, TFHE_RS_ZK_MAX_BITS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from './chunk-J23FYAI2.js';
|
|
4
5
|
import { createStore } from 'zustand/vanilla';
|
|
5
6
|
import { parseAbi, isAddressEqual, zeroAddress, recoverAddress, encodePacked, keccak256, createWalletClient, http, getAddress, parseSignature, serializeSignature } from 'viem';
|
|
6
7
|
import { hardhat } from 'viem/chains';
|
|
@@ -9,224 +10,6 @@ import { z } from 'zod';
|
|
|
9
10
|
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
10
11
|
import { produce } from 'immer';
|
|
11
12
|
|
|
12
|
-
// core/types.ts
|
|
13
|
-
var FheTypes = /* @__PURE__ */ ((FheTypes2) => {
|
|
14
|
-
FheTypes2[FheTypes2["Bool"] = 0] = "Bool";
|
|
15
|
-
FheTypes2[FheTypes2["Uint4"] = 1] = "Uint4";
|
|
16
|
-
FheTypes2[FheTypes2["Uint8"] = 2] = "Uint8";
|
|
17
|
-
FheTypes2[FheTypes2["Uint16"] = 3] = "Uint16";
|
|
18
|
-
FheTypes2[FheTypes2["Uint32"] = 4] = "Uint32";
|
|
19
|
-
FheTypes2[FheTypes2["Uint64"] = 5] = "Uint64";
|
|
20
|
-
FheTypes2[FheTypes2["Uint128"] = 6] = "Uint128";
|
|
21
|
-
FheTypes2[FheTypes2["Uint160"] = 7] = "Uint160";
|
|
22
|
-
FheTypes2[FheTypes2["Uint256"] = 8] = "Uint256";
|
|
23
|
-
FheTypes2[FheTypes2["Uint512"] = 9] = "Uint512";
|
|
24
|
-
FheTypes2[FheTypes2["Uint1024"] = 10] = "Uint1024";
|
|
25
|
-
FheTypes2[FheTypes2["Uint2048"] = 11] = "Uint2048";
|
|
26
|
-
FheTypes2[FheTypes2["Uint2"] = 12] = "Uint2";
|
|
27
|
-
FheTypes2[FheTypes2["Uint6"] = 13] = "Uint6";
|
|
28
|
-
FheTypes2[FheTypes2["Uint10"] = 14] = "Uint10";
|
|
29
|
-
FheTypes2[FheTypes2["Uint12"] = 15] = "Uint12";
|
|
30
|
-
FheTypes2[FheTypes2["Uint14"] = 16] = "Uint14";
|
|
31
|
-
FheTypes2[FheTypes2["Int2"] = 17] = "Int2";
|
|
32
|
-
FheTypes2[FheTypes2["Int4"] = 18] = "Int4";
|
|
33
|
-
FheTypes2[FheTypes2["Int6"] = 19] = "Int6";
|
|
34
|
-
FheTypes2[FheTypes2["Int8"] = 20] = "Int8";
|
|
35
|
-
FheTypes2[FheTypes2["Int10"] = 21] = "Int10";
|
|
36
|
-
FheTypes2[FheTypes2["Int12"] = 22] = "Int12";
|
|
37
|
-
FheTypes2[FheTypes2["Int14"] = 23] = "Int14";
|
|
38
|
-
FheTypes2[FheTypes2["Int16"] = 24] = "Int16";
|
|
39
|
-
FheTypes2[FheTypes2["Int32"] = 25] = "Int32";
|
|
40
|
-
FheTypes2[FheTypes2["Int64"] = 26] = "Int64";
|
|
41
|
-
FheTypes2[FheTypes2["Int128"] = 27] = "Int128";
|
|
42
|
-
FheTypes2[FheTypes2["Int160"] = 28] = "Int160";
|
|
43
|
-
FheTypes2[FheTypes2["Int256"] = 29] = "Int256";
|
|
44
|
-
return FheTypes2;
|
|
45
|
-
})(FheTypes || {});
|
|
46
|
-
var FheUintUTypes = [
|
|
47
|
-
2 /* Uint8 */,
|
|
48
|
-
3 /* Uint16 */,
|
|
49
|
-
4 /* Uint32 */,
|
|
50
|
-
5 /* Uint64 */,
|
|
51
|
-
6 /* Uint128 */
|
|
52
|
-
// [U256-DISABLED]
|
|
53
|
-
// FheTypes.Uint256,
|
|
54
|
-
];
|
|
55
|
-
var FheAllUTypes = [
|
|
56
|
-
0 /* Bool */,
|
|
57
|
-
2 /* Uint8 */,
|
|
58
|
-
3 /* Uint16 */,
|
|
59
|
-
4 /* Uint32 */,
|
|
60
|
-
5 /* Uint64 */,
|
|
61
|
-
6 /* Uint128 */,
|
|
62
|
-
// [U256-DISABLED]
|
|
63
|
-
// FheTypes.Uint256,
|
|
64
|
-
7 /* Uint160 */
|
|
65
|
-
];
|
|
66
|
-
var EncryptableFactoriesImpl = {
|
|
67
|
-
bool: (data, securityZone = 0) => ({ data, securityZone, utype: 0 /* Bool */ }),
|
|
68
|
-
address: (data, securityZone = 0) => ({ data, securityZone, utype: 7 /* Uint160 */ }),
|
|
69
|
-
uint8: (data, securityZone = 0) => ({ data, securityZone, utype: 2 /* Uint8 */ }),
|
|
70
|
-
uint16: (data, securityZone = 0) => ({ data, securityZone, utype: 3 /* Uint16 */ }),
|
|
71
|
-
uint32: (data, securityZone = 0) => ({ data, securityZone, utype: 4 /* Uint32 */ }),
|
|
72
|
-
uint64: (data, securityZone = 0) => ({ data, securityZone, utype: 5 /* Uint64 */ }),
|
|
73
|
-
uint128: (data, securityZone = 0) => ({ data, securityZone, utype: 6 /* Uint128 */ })
|
|
74
|
-
// [U256-DISABLED]
|
|
75
|
-
// uint256: (data: EncryptableUint256['data'], securityZone = 0) =>
|
|
76
|
-
// ({ data, securityZone, utype: FheTypes.Uint256 }) as EncryptableUint256,
|
|
77
|
-
};
|
|
78
|
-
function createEncryptableByLiteral(type, data, securityZone = 0) {
|
|
79
|
-
switch (type) {
|
|
80
|
-
case "bool": {
|
|
81
|
-
if (typeof data !== "boolean")
|
|
82
|
-
throw new Error("Bool encryptable data must be boolean");
|
|
83
|
-
return EncryptableFactoriesImpl.bool(data, securityZone);
|
|
84
|
-
}
|
|
85
|
-
case "address":
|
|
86
|
-
case "uint8":
|
|
87
|
-
case "uint16":
|
|
88
|
-
case "uint32":
|
|
89
|
-
case "uint64":
|
|
90
|
-
case "uint128": {
|
|
91
|
-
if (typeof data === "boolean")
|
|
92
|
-
throw new Error("Uint encryptable data must be string or bigint");
|
|
93
|
-
return EncryptableFactoriesImpl[type](data, securityZone);
|
|
94
|
-
}
|
|
95
|
-
default: {
|
|
96
|
-
const _exhaustive = type;
|
|
97
|
-
throw new Error(`Unsupported encryptable type: ${_exhaustive}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
var Encryptable = {
|
|
102
|
-
...EncryptableFactoriesImpl,
|
|
103
|
-
create: createEncryptableByLiteral
|
|
104
|
-
};
|
|
105
|
-
function isEncryptableItem(value) {
|
|
106
|
-
return (
|
|
107
|
-
// Is object and exists
|
|
108
|
-
typeof value === "object" && value !== null && // Has securityZone
|
|
109
|
-
"securityZone" in value && typeof value.securityZone === "number" && // Has utype
|
|
110
|
-
"utype" in value && FheAllUTypes.includes(value.utype) && // Has data
|
|
111
|
-
"data" in value && ["string", "number", "bigint", "boolean"].includes(typeof value.data)
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
var EncryptStep = /* @__PURE__ */ ((EncryptStep2) => {
|
|
115
|
-
EncryptStep2["InitTfhe"] = "initTfhe";
|
|
116
|
-
EncryptStep2["FetchKeys"] = "fetchKeys";
|
|
117
|
-
EncryptStep2["Pack"] = "pack";
|
|
118
|
-
EncryptStep2["Prove"] = "prove";
|
|
119
|
-
EncryptStep2["Verify"] = "verify";
|
|
120
|
-
return EncryptStep2;
|
|
121
|
-
})(EncryptStep || {});
|
|
122
|
-
function isLastEncryptionStep(step) {
|
|
123
|
-
return step === "verify" /* Verify */;
|
|
124
|
-
}
|
|
125
|
-
var toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
126
|
-
var toBigIntOrThrow = (value) => {
|
|
127
|
-
if (typeof value === "bigint") {
|
|
128
|
-
return value;
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
return BigInt(value);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
throw new Error("Invalid input: Unable to convert to bigint");
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
var validateBigIntInRange = (value, max, min = 0n) => {
|
|
137
|
-
if (typeof value !== "bigint") {
|
|
138
|
-
throw new Error("Value must be of type bigint");
|
|
139
|
-
}
|
|
140
|
-
if (value > max || value < min) {
|
|
141
|
-
throw new Error(`Value out of range: ${max} - ${min}, try a different uint type`);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
var hexToBytes = (hex) => {
|
|
145
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
146
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
147
|
-
bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
|
|
148
|
-
}
|
|
149
|
-
return bytes;
|
|
150
|
-
};
|
|
151
|
-
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
152
|
-
async function getPublicClientChainID(publicClient) {
|
|
153
|
-
let chainId = null;
|
|
154
|
-
try {
|
|
155
|
-
chainId = publicClient.chain?.id ?? await publicClient.getChainId();
|
|
156
|
-
} catch (e) {
|
|
157
|
-
throw new CofheError({
|
|
158
|
-
code: "PUBLIC_WALLET_GET_CHAIN_ID_FAILED" /* PublicWalletGetChainIdFailed */,
|
|
159
|
-
message: "getting chain ID from public client failed",
|
|
160
|
-
cause: e instanceof Error ? e : void 0
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (chainId === null) {
|
|
164
|
-
throw new CofheError({
|
|
165
|
-
code: "PUBLIC_WALLET_GET_CHAIN_ID_FAILED" /* PublicWalletGetChainIdFailed */,
|
|
166
|
-
message: "chain ID from public client is null"
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
return chainId;
|
|
170
|
-
}
|
|
171
|
-
async function getWalletClientAccount(walletClient) {
|
|
172
|
-
let address;
|
|
173
|
-
try {
|
|
174
|
-
address = walletClient.account?.address;
|
|
175
|
-
if (!address) {
|
|
176
|
-
address = (await walletClient.getAddresses())?.[0];
|
|
177
|
-
}
|
|
178
|
-
} catch (e) {
|
|
179
|
-
throw new CofheError({
|
|
180
|
-
code: "PUBLIC_WALLET_GET_ADDRESSES_FAILED" /* PublicWalletGetAddressesFailed */,
|
|
181
|
-
message: "getting address from wallet client failed",
|
|
182
|
-
cause: e instanceof Error ? e : void 0
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
if (!address) {
|
|
186
|
-
throw new CofheError({
|
|
187
|
-
code: "PUBLIC_WALLET_GET_ADDRESSES_FAILED" /* PublicWalletGetAddressesFailed */,
|
|
188
|
-
message: "address from wallet client is null"
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return address;
|
|
192
|
-
}
|
|
193
|
-
function fheTypeToString(utype) {
|
|
194
|
-
switch (utype) {
|
|
195
|
-
case 0 /* Bool */:
|
|
196
|
-
return "bool";
|
|
197
|
-
case 1 /* Uint4 */:
|
|
198
|
-
return "uint4";
|
|
199
|
-
case 2 /* Uint8 */:
|
|
200
|
-
return "uint8";
|
|
201
|
-
case 3 /* Uint16 */:
|
|
202
|
-
return "uint16";
|
|
203
|
-
case 4 /* Uint32 */:
|
|
204
|
-
return "uint32";
|
|
205
|
-
case 5 /* Uint64 */:
|
|
206
|
-
return "uint64";
|
|
207
|
-
case 6 /* Uint128 */:
|
|
208
|
-
return "uint128";
|
|
209
|
-
case 7 /* Uint160 */:
|
|
210
|
-
return "uint160";
|
|
211
|
-
case 8 /* Uint256 */:
|
|
212
|
-
return "uint256";
|
|
213
|
-
case 9 /* Uint512 */:
|
|
214
|
-
return "uint512";
|
|
215
|
-
case 10 /* Uint1024 */:
|
|
216
|
-
return "uint1024";
|
|
217
|
-
case 11 /* Uint2048 */:
|
|
218
|
-
return "uint2048";
|
|
219
|
-
case 12 /* Uint2 */:
|
|
220
|
-
return "uint2";
|
|
221
|
-
case 13 /* Uint6 */:
|
|
222
|
-
return "uint6";
|
|
223
|
-
case 14 /* Uint10 */:
|
|
224
|
-
return "uint10";
|
|
225
|
-
default:
|
|
226
|
-
throw new Error(`Unknown FheType: ${utype}`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
13
|
// core/encrypt/zkPackProveVerify.ts
|
|
231
14
|
var MAX_UINT8 = 255n;
|
|
232
15
|
var MAX_UINT16 = 65535n;
|
|
@@ -515,26 +298,32 @@ async function cofheMocksCheckEncryptableBits(items) {
|
|
|
515
298
|
break;
|
|
516
299
|
}
|
|
517
300
|
case 2 /* Uint8 */: {
|
|
301
|
+
validateBigIntInRange(toBigIntOrThrow(item.data), MAX_UINT8);
|
|
518
302
|
totalBits += 8;
|
|
519
303
|
break;
|
|
520
304
|
}
|
|
521
305
|
case 3 /* Uint16 */: {
|
|
306
|
+
validateBigIntInRange(toBigIntOrThrow(item.data), MAX_UINT16);
|
|
522
307
|
totalBits += 16;
|
|
523
308
|
break;
|
|
524
309
|
}
|
|
525
310
|
case 4 /* Uint32 */: {
|
|
311
|
+
validateBigIntInRange(toBigIntOrThrow(item.data), MAX_UINT32);
|
|
526
312
|
totalBits += 32;
|
|
527
313
|
break;
|
|
528
314
|
}
|
|
529
315
|
case 5 /* Uint64 */: {
|
|
316
|
+
validateBigIntInRange(toBigIntOrThrow(item.data), MAX_UINT64);
|
|
530
317
|
totalBits += 64;
|
|
531
318
|
break;
|
|
532
319
|
}
|
|
533
320
|
case 6 /* Uint128 */: {
|
|
321
|
+
validateBigIntInRange(toBigIntOrThrow(item.data), MAX_UINT128);
|
|
534
322
|
totalBits += 128;
|
|
535
323
|
break;
|
|
536
324
|
}
|
|
537
325
|
case 7 /* Uint160 */: {
|
|
326
|
+
validateBigIntInRange(toBigIntOrThrow(item.data), MAX_UINT160);
|
|
538
327
|
totalBits += 160;
|
|
539
328
|
break;
|
|
540
329
|
}
|
|
@@ -709,7 +498,8 @@ var CofheConfigSchema = z.object({
|
|
|
709
498
|
acp: z.object({
|
|
710
499
|
defaultRevoker: z.custom().optional(),
|
|
711
500
|
defaultContractScopes: z.custom().optional(),
|
|
712
|
-
sharingRegistry: z.custom().optional()
|
|
501
|
+
sharingRegistry: z.custom().optional(),
|
|
502
|
+
app: z.string().min(1).optional()
|
|
713
503
|
}).optional().default({}),
|
|
714
504
|
/** Mocks configs */
|
|
715
505
|
mocks: z.object({
|
|
@@ -1538,8 +1328,14 @@ var createSelf = async (options, publicClient, walletClient) => {
|
|
|
1538
1328
|
var createSharing = async (options, publicClient, walletClient) => {
|
|
1539
1329
|
return createACPWithSign(options, publicClient, walletClient, ACPUtils.createSharingAndSign, false);
|
|
1540
1330
|
};
|
|
1541
|
-
var importShared = async (options, publicClient, walletClient, { activate = true } = {}) => {
|
|
1542
|
-
return createACPWithSign(
|
|
1331
|
+
var importShared = async (options, publicClient, walletClient, { activate = true, name } = {}) => {
|
|
1332
|
+
return createACPWithSign(
|
|
1333
|
+
options,
|
|
1334
|
+
publicClient,
|
|
1335
|
+
walletClient,
|
|
1336
|
+
(o, pc, wc) => ACPUtils.importSharedAndSign(o, pc, wc, { name }),
|
|
1337
|
+
activate
|
|
1338
|
+
);
|
|
1543
1339
|
};
|
|
1544
1340
|
var getHash = (acp) => {
|
|
1545
1341
|
return ACPUtils.getHash(acp);
|
|
@@ -1586,13 +1382,15 @@ var getOrCreateSharingACP = async (publicClient, walletClient, options, chainId,
|
|
|
1586
1382
|
}
|
|
1587
1383
|
return createSharing(options, publicClient, walletClient);
|
|
1588
1384
|
};
|
|
1589
|
-
var
|
|
1385
|
+
var applyACPDefaultsFromChain = async (options, acpConfig, publicClient, chainId) => {
|
|
1590
1386
|
const result = { ...options };
|
|
1591
|
-
const
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1387
|
+
const hasRevokerOptions = options.revokerData != null || options.revokerContract != null;
|
|
1388
|
+
if (!hasRevokerOptions) {
|
|
1389
|
+
const defaultRevoker = acpConfig?.defaultRevoker?.[chainId] ?? (await getAclServedAddresses(publicClient, chainId)).defaultRevoker;
|
|
1390
|
+
if (defaultRevoker != null) {
|
|
1391
|
+
result.revokerContract = defaultRevoker;
|
|
1392
|
+
result.revokerData = await getBlockRevokerData(publicClient);
|
|
1393
|
+
}
|
|
1596
1394
|
}
|
|
1597
1395
|
const defaultContracts = acpConfig?.defaultContractScopes?.[chainId];
|
|
1598
1396
|
const hasScopeOptions = options.scope != null || options.contracts != null || options.handles != null;
|
|
@@ -1601,13 +1399,15 @@ var applyACPDefaults = (options, acpConfig, chainId) => {
|
|
|
1601
1399
|
}
|
|
1602
1400
|
return result;
|
|
1603
1401
|
};
|
|
1604
|
-
var
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1402
|
+
var getBlockRevokerData = async (publicClient) => {
|
|
1403
|
+
const block = await publicClient.getBlock();
|
|
1404
|
+
const revokerData = Number(block.timestamp);
|
|
1405
|
+
if (!Number.isSafeInteger(revokerData)) {
|
|
1406
|
+
throw new Error(
|
|
1407
|
+
`ACP revokerData cannot represent the chain block timestamp ${block.timestamp.toString()} as a safe integer`
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
return revokerData;
|
|
1611
1411
|
};
|
|
1612
1412
|
var revokeACP = async (acp, walletClient) => {
|
|
1613
1413
|
if (acp.revokerContract === zeroAddress || acp.revokerData === 0) {
|
|
@@ -1666,7 +1466,17 @@ var isACPRevoked = async (acp, publicClient) => {
|
|
|
1666
1466
|
args: [acp.issuer, BigInt(acp.revokerData)]
|
|
1667
1467
|
});
|
|
1668
1468
|
};
|
|
1669
|
-
var
|
|
1469
|
+
var metadataOf = (acp, { labels, metadata, appKey }) => {
|
|
1470
|
+
if (labels != null && metadata != null)
|
|
1471
|
+
throw new Error("Pass either labels or metadata, not both");
|
|
1472
|
+
if (labels == null)
|
|
1473
|
+
return metadata ?? acp.metadata ?? "0x";
|
|
1474
|
+
if (labels.length !== acp.handles.length) {
|
|
1475
|
+
throw new Error(`Cannot label a share of ${acp.handles.length} handles with ${labels.length} labels`);
|
|
1476
|
+
}
|
|
1477
|
+
return encodeShareMetadata(labels, { issuer: acp.issuer, appKey });
|
|
1478
|
+
};
|
|
1479
|
+
var shareOnChain = async (acp, walletClient, registry, options = {}) => {
|
|
1670
1480
|
if (acp.type !== "sharing") {
|
|
1671
1481
|
throw new Error(`Cannot share a '${acp.type}' ACP on-chain \u2014 only 'sharing' ACPs are shareable.`);
|
|
1672
1482
|
}
|
|
@@ -1678,38 +1488,48 @@ var shareOnChain = async (acp, walletClient, registry) => {
|
|
|
1678
1488
|
if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
1679
1489
|
throw new Error("Only the ACP issuer can share it on-chain");
|
|
1680
1490
|
}
|
|
1491
|
+
const metadata = metadataOf(acp, options);
|
|
1681
1492
|
const txHash = await walletClient.writeContract({
|
|
1682
1493
|
address: registry,
|
|
1683
1494
|
abi: ACP_SHARE_REGISTRY_ABI,
|
|
1684
1495
|
functionName: "share",
|
|
1685
|
-
args: [toChainShare(acp)],
|
|
1496
|
+
args: [toChainShare(acp), metadata],
|
|
1686
1497
|
account: walletClient.account,
|
|
1687
1498
|
chain: walletClient.chain ?? null
|
|
1688
1499
|
});
|
|
1689
1500
|
return { txHash, shareId: computeShareId(acp) };
|
|
1690
1501
|
};
|
|
1691
|
-
var
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1502
|
+
var toIncomingShare = ({ shareId, share: s, metadata }) => ({
|
|
1503
|
+
shareId,
|
|
1504
|
+
issuer: s.issuer,
|
|
1505
|
+
expiration: Number(s.expiration),
|
|
1506
|
+
recipient: s.recipient,
|
|
1507
|
+
revokerData: Number(s.revokerData),
|
|
1508
|
+
revokerContract: s.revokerContract,
|
|
1509
|
+
scope: Number(s.scope),
|
|
1510
|
+
contracts: [...s.contracts],
|
|
1511
|
+
handles: [...s.handles],
|
|
1512
|
+
issuerSignature: s.issuerSignature,
|
|
1513
|
+
metadata,
|
|
1514
|
+
...appKeyOf(metadata, s.handles) && { appKey: appKeyOf(metadata, s.handles) }
|
|
1515
|
+
});
|
|
1516
|
+
var appKeyOf = (metadata, handles) => {
|
|
1517
|
+
try {
|
|
1518
|
+
return decodeShareAppKey(metadata, handles);
|
|
1519
|
+
} catch {
|
|
1520
|
+
return void 0;
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
var getIncomingShares = async (publicClient, registry, recipient, { appKey } = {}) => {
|
|
1524
|
+
const shares = (await readSharesFor(publicClient, registry, recipient)).posted.map(toIncomingShare);
|
|
1525
|
+
return appKey == null ? shares : shares.filter((share) => share.appKey === appKey);
|
|
1526
|
+
};
|
|
1527
|
+
var getShareFromChain = async (publicClient, registry, shareId) => {
|
|
1528
|
+
const posted = await readShare(publicClient, registry, shareId);
|
|
1529
|
+
return posted && toIncomingShare(posted);
|
|
1710
1530
|
};
|
|
1711
1531
|
var importFromChain = async (share, publicClient, walletClient, importOptions = {}) => {
|
|
1712
|
-
const { shareId: _shareId, ...options } = share;
|
|
1532
|
+
const { shareId: _shareId, appKey: _appKey, ...options } = share;
|
|
1713
1533
|
return importShared({ ...options, type: "sharing" }, publicClient, walletClient, importOptions);
|
|
1714
1534
|
};
|
|
1715
1535
|
var removeShareOnChain = async (shareId, walletClient, registry) => {
|
|
@@ -1751,10 +1571,10 @@ var acps = {
|
|
|
1751
1571
|
checkAccess,
|
|
1752
1572
|
shareOnChain,
|
|
1753
1573
|
getIncomingShares,
|
|
1574
|
+
getShareFromChain,
|
|
1754
1575
|
importFromChain,
|
|
1755
1576
|
removeShareOnChain,
|
|
1756
1577
|
computeShareId,
|
|
1757
|
-
applyACPDefaults,
|
|
1758
1578
|
applyACPDefaultsFromChain,
|
|
1759
1579
|
getAclServedAddresses,
|
|
1760
1580
|
clearAclServedAddresses
|
|
@@ -2061,7 +1881,7 @@ var BACKEND_ERROR_CODE_TO_COFHE_ERROR_CODE = {
|
|
|
2061
1881
|
seal_failed: "SEAL_FAILED" /* SealFailed */
|
|
2062
1882
|
};
|
|
2063
1883
|
function isBackendApiErrorCode(value) {
|
|
2064
|
-
return value
|
|
1884
|
+
return Object.prototype.hasOwnProperty.call(BACKEND_ERROR_CODE_TO_COFHE_ERROR_CODE, value);
|
|
2065
1885
|
}
|
|
2066
1886
|
async function parseApiErrorResponseBody(response) {
|
|
2067
1887
|
let errorMessage = `HTTP ${response.status}`;
|
|
@@ -3474,7 +3294,7 @@ async function verifyDecryptResult(handle, cleartext, signature, publicClient) {
|
|
|
3474
3294
|
args: []
|
|
3475
3295
|
});
|
|
3476
3296
|
if (isAddressEqual(expectedSigner, zeroAddress))
|
|
3477
|
-
return
|
|
3297
|
+
return false;
|
|
3478
3298
|
const ctHash = BigInt(handle);
|
|
3479
3299
|
const messageHash = buildDecryptResultHash(ctHash, cleartext, chainId);
|
|
3480
3300
|
try {
|
|
@@ -3502,6 +3322,7 @@ function createCofheClientBase(opts) {
|
|
|
3502
3322
|
const updateConnectState = (partial) => {
|
|
3503
3323
|
connectStore.setState((state) => ({ ...state, ...partial }));
|
|
3504
3324
|
};
|
|
3325
|
+
const withAppKey = () => opts.config.acp?.app == null ? {} : { appKey: shareAppKey(opts.config.acp.app) };
|
|
3505
3326
|
const _resolveSharingRegistry = async (publicClient, chainId) => {
|
|
3506
3327
|
const configured = opts.config.acp?.sharingRegistry?.[chainId];
|
|
3507
3328
|
if (configured != null)
|
|
@@ -3660,16 +3481,16 @@ function createCofheClientBase(opts) {
|
|
|
3660
3481
|
const { publicClient, walletClient } = clients ?? connectStore.getState();
|
|
3661
3482
|
const chainId = await publicClient.getChainId();
|
|
3662
3483
|
return acps.createSharing(
|
|
3663
|
-
await acps.applyACPDefaultsFromChain(options, opts.config.acp, publicClient, chainId),
|
|
3484
|
+
await acps.applyACPDefaultsFromChain({ ...withAppKey(), ...options }, opts.config.acp, publicClient, chainId),
|
|
3664
3485
|
publicClient,
|
|
3665
3486
|
walletClient
|
|
3666
3487
|
);
|
|
3667
3488
|
},
|
|
3668
3489
|
importShared: async (options, importOptions = {}) => {
|
|
3669
3490
|
_requireConnected();
|
|
3670
|
-
const { activate, ...clients } = importOptions;
|
|
3491
|
+
const { activate, name, ...clients } = importOptions;
|
|
3671
3492
|
const { publicClient, walletClient } = clients.publicClient ? clients : connectStore.getState();
|
|
3672
|
-
return acps.importShared(options, publicClient, walletClient, { activate });
|
|
3493
|
+
return acps.importShared(options, publicClient, walletClient, { activate, name });
|
|
3673
3494
|
},
|
|
3674
3495
|
// Get or create methods (require connection)
|
|
3675
3496
|
getOrCreateSelfACP: async (chainId, account, options) => {
|
|
@@ -3691,7 +3512,7 @@ function createCofheClientBase(opts) {
|
|
|
3691
3512
|
return acps.getOrCreateSharingACP(
|
|
3692
3513
|
publicClient,
|
|
3693
3514
|
walletClient,
|
|
3694
|
-
await acps.applyACPDefaultsFromChain(options, opts.config.acp, publicClient, _chainId),
|
|
3515
|
+
await acps.applyACPDefaultsFromChain({ ...withAppKey(), ...options }, opts.config.acp, publicClient, _chainId),
|
|
3695
3516
|
_chainId,
|
|
3696
3517
|
_account
|
|
3697
3518
|
);
|
|
@@ -3718,12 +3539,12 @@ function createCofheClientBase(opts) {
|
|
|
3718
3539
|
return acps.checkAccess(acp, publicClient, handle);
|
|
3719
3540
|
},
|
|
3720
3541
|
// On-chain sharing (require connection + config.acp.sharingRegistry)
|
|
3721
|
-
shareOnChain: async (acp) => {
|
|
3542
|
+
shareOnChain: async (acp, options) => {
|
|
3722
3543
|
_requireConnected();
|
|
3723
3544
|
const { publicClient, walletClient } = connectStore.getState();
|
|
3724
3545
|
const chainId = await publicClient.getChainId();
|
|
3725
3546
|
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
3726
|
-
return acps.shareOnChain(acp, walletClient, sharingRegistry);
|
|
3547
|
+
return acps.shareOnChain(acp, walletClient, sharingRegistry, { ...withAppKey(), ...options });
|
|
3727
3548
|
},
|
|
3728
3549
|
getIncomingShares: async () => {
|
|
3729
3550
|
_requireConnected();
|
|
@@ -3731,7 +3552,27 @@ function createCofheClientBase(opts) {
|
|
|
3731
3552
|
const chainId = await publicClient.getChainId();
|
|
3732
3553
|
const account = walletClient.account.address;
|
|
3733
3554
|
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
3734
|
-
return acps.getIncomingShares(publicClient, sharingRegistry, account);
|
|
3555
|
+
return acps.getIncomingShares(publicClient, sharingRegistry, account, withAppKey());
|
|
3556
|
+
},
|
|
3557
|
+
getShareFromChain: async (shareId) => {
|
|
3558
|
+
_requireConnected();
|
|
3559
|
+
const { publicClient } = connectStore.getState();
|
|
3560
|
+
const chainId = await publicClient.getChainId();
|
|
3561
|
+
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
3562
|
+
return acps.getShareFromChain(publicClient, sharingRegistry, shareId);
|
|
3563
|
+
},
|
|
3564
|
+
verifyShareLabels: async (share, options) => {
|
|
3565
|
+
_requireConnected();
|
|
3566
|
+
const { publicClient } = connectStore.getState();
|
|
3567
|
+
if (share.metadata == null || share.metadata === "0x")
|
|
3568
|
+
return null;
|
|
3569
|
+
return verifyShareLabels({
|
|
3570
|
+
labels: decodeShareMetadata(share.metadata, share.handles),
|
|
3571
|
+
handles: share.handles,
|
|
3572
|
+
issuer: share.issuer,
|
|
3573
|
+
publicClient,
|
|
3574
|
+
verify: options?.verify
|
|
3575
|
+
});
|
|
3735
3576
|
},
|
|
3736
3577
|
importFromChain: async (share, options) => {
|
|
3737
3578
|
_requireConnected();
|
|
@@ -3824,4 +3665,4 @@ function createCofheClientBase(opts) {
|
|
|
3824
3665
|
};
|
|
3825
3666
|
}
|
|
3826
3667
|
|
|
3827
|
-
export { DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder,
|
|
3668
|
+
export { DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, InitialConnectStore, assertNoRenamedConfigKeys, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, getCofheConfigItem, getCofheDebugInterceptors, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker };
|