@cofhe/sdk 1.0.0 → 1.1.0-alpha.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/core/acps.ts +64 -23
- package/core/client.ts +32 -1
- package/core/clientTypes.ts +22 -1
- package/core/test/acpsPrepare.test.ts +77 -0
- package/dist/acps.d.cts +4 -358
- package/dist/acps.d.ts +4 -358
- package/dist/{chunk-O2ITEUEU.js → chunk-2EO4JSR7.js} +63 -21
- package/dist/{clientTypes-b1pOxOUE.d.ts → clientTypes-CnslFzxB.d.ts} +38 -2
- package/dist/{clientTypes-IO6b5Um8.d.cts → clientTypes-RXwLVWou.d.cts} +38 -2
- package/dist/core.cjs +62 -20
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +1 -1
- package/dist/node.cjs +62 -20
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -1
- package/dist/{onchain-utils-CgOslubH.d.ts → onchain-utils-Ns56cBm0.d.cts} +356 -2
- package/dist/{onchain-utils-CgOslubH.d.cts → onchain-utils-Ns56cBm0.d.ts} +356 -2
- package/dist/web.cjs +62 -20
- package/dist/web.d.cts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +1 -1
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { WalletClient, PublicClient, Hex } from 'viem';
|
|
1
|
+
import { WalletClient, PublicClient, Hex, ContractFunctionParameters } from 'viem';
|
|
2
2
|
import { C as CofheChain } from './types-C07FK-cL.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as ACP, k as EIP712Domain, C as CreateSelfACPOptions,
|
|
4
|
+
import { A as ACP, k as EIP712Domain, C as CreateSelfACPOptions, $ as SelfACP, g as CreateSharingACPOptions, a0 as SharingACP, I as ImportSharedACPOptions, a1 as RecipientACP, a5 as ACPHashFields, f as SerializedACP, t as ACP_REVOKER_ABI, a4 as ACPAccessStatus, S as ShareLabel, v as ACP_SHARE_REGISTRY_ABI, j as IncomingShare, p as AclServedAddresses, L as LabelledShare, Q as ShareLabelVerifyMode, R as ShareLabelCheck, l as ACPUtils } from './onchain-utils-Ns56cBm0.cjs';
|
|
5
5
|
import { StoreApi } from 'zustand/vanilla';
|
|
6
6
|
|
|
7
7
|
type TfheInitializer = () => Promise<boolean>;
|
|
@@ -1031,6 +1031,21 @@ type ImportSharedOptions = ImportActivationOptions & {
|
|
|
1031
1031
|
*/
|
|
1032
1032
|
name?: string;
|
|
1033
1033
|
};
|
|
1034
|
+
/**
|
|
1035
|
+
* Revoke a single acp on-chain via its revoker contract.
|
|
1036
|
+
* Only the acp's issuer can revoke it (enforced by the revoker: revocations
|
|
1037
|
+
* are keyed by msg.sender). The acp stays in local storage — on-chain
|
|
1038
|
+
* validation will reject it from the next block onwards.
|
|
1039
|
+
*
|
|
1040
|
+
* @returns the revocation transaction hash
|
|
1041
|
+
*/
|
|
1042
|
+
/**
|
|
1043
|
+
* A registry or revoker write built but not sent: what a simulation or `writeContract` takes,
|
|
1044
|
+
* minus the sender. For a caller that sends through its own path (simulate first, record the
|
|
1045
|
+
* transaction) instead of the plain `writeContract` the senders below do.
|
|
1046
|
+
*/
|
|
1047
|
+
type ShareRegistryWrite<functionName extends 'share' | 'removeShare'> = ContractFunctionParameters<typeof ACP_SHARE_REGISTRY_ABI, 'nonpayable', functionName>;
|
|
1048
|
+
type RevokerWrite = ContractFunctionParameters<typeof ACP_REVOKER_ABI, 'nonpayable', 'revokeSingle'>;
|
|
1034
1049
|
/**
|
|
1035
1050
|
* What `shareOnChain` posts with a share: the labels of its handles (one per handle, in order;
|
|
1036
1051
|
* encoded with `encodeShareMetadata`), or an already encoded metadata blob. Written once, with the
|
|
@@ -1191,6 +1206,7 @@ declare const acps: {
|
|
|
1191
1206
|
selectActiveACP: (chainId: number, account: string, hash: string) => void;
|
|
1192
1207
|
removeActiveACP: (chainId: number, account: string) => Promise<void>;
|
|
1193
1208
|
revokeACP: (acp: ACP, walletClient: WalletClient) => Promise<Hex>;
|
|
1209
|
+
prepareRevokeACP: (acp: ACP) => RevokerWrite;
|
|
1194
1210
|
revokeAllACPs: (walletClient: WalletClient, publicClient: PublicClient, revokerContract?: Hex) => Promise<Hex>;
|
|
1195
1211
|
isACPRevoked: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
|
|
1196
1212
|
checkAccess: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
|
|
@@ -1198,12 +1214,17 @@ declare const acps: {
|
|
|
1198
1214
|
txHash: Hex;
|
|
1199
1215
|
shareId: Hex;
|
|
1200
1216
|
}>;
|
|
1217
|
+
prepareShareOnChain: (acp: ACP, registry: Hex, options?: ShareOnChainOptions) => {
|
|
1218
|
+
write: ShareRegistryWrite<"share">;
|
|
1219
|
+
shareId: Hex;
|
|
1220
|
+
};
|
|
1201
1221
|
getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex, { appKey }?: {
|
|
1202
1222
|
appKey?: Hex;
|
|
1203
1223
|
}) => Promise<IncomingShare[]>;
|
|
1204
1224
|
getShareFromChain: (publicClient: PublicClient, registry: Hex, shareId: Hex) => Promise<IncomingShare | null>;
|
|
1205
1225
|
importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportSharedOptions) => Promise<RecipientACP>;
|
|
1206
1226
|
removeShareOnChain: (shareId: Hex, walletClient: WalletClient, registry: Hex) => Promise<Hex>;
|
|
1227
|
+
prepareRemoveShare: (shareId: Hex, registry: Hex) => ShareRegistryWrite<"removeShare">;
|
|
1207
1228
|
computeShareId: (acp: ACP) => Hex;
|
|
1208
1229
|
applyACPDefaultsFromChain: <T extends {
|
|
1209
1230
|
revokerData?: number;
|
|
@@ -1286,6 +1307,11 @@ type CofheClientACPs = {
|
|
|
1286
1307
|
removeACP: (hash: string, chainId?: number, account?: string) => void;
|
|
1287
1308
|
removeActiveACP: (chainId?: number, account?: string) => void;
|
|
1288
1309
|
revokeACP: (acp: ACP) => Promise<`0x${string}`>;
|
|
1310
|
+
/**
|
|
1311
|
+
* The revoker write `revokeACP` sends, built but not sent — for an app that sends through its own
|
|
1312
|
+
* path (a simulation first, a transaction store). Issuer only; throws for an acp without a revoker.
|
|
1313
|
+
*/
|
|
1314
|
+
prepareRevokeACP: (acp: ACP) => RevokerWrite;
|
|
1289
1315
|
revokeAllACPs: (revokerContract?: `0x${string}`) => Promise<`0x${string}`>;
|
|
1290
1316
|
isACPRevoked: (acp: ACP) => Promise<boolean>;
|
|
1291
1317
|
/**
|
|
@@ -1303,6 +1329,16 @@ type CofheClientACPs = {
|
|
|
1303
1329
|
txHash: `0x${string}`;
|
|
1304
1330
|
shareId: `0x${string}`;
|
|
1305
1331
|
}>;
|
|
1332
|
+
/**
|
|
1333
|
+
* The registry write `shareOnChain` sends and the share id it gets, built but not sent — for an
|
|
1334
|
+
* app that sends through its own path (a simulation first, a transaction store). Issuer only.
|
|
1335
|
+
*/
|
|
1336
|
+
prepareShareOnChain: (acp: ACP, options?: ShareOnChainOptions) => Promise<{
|
|
1337
|
+
write: ShareRegistryWrite<'share'>;
|
|
1338
|
+
shareId: `0x${string}`;
|
|
1339
|
+
}>;
|
|
1340
|
+
/** The registry write `dismissShare` / `cancelShare` sends, built but not sent. */
|
|
1341
|
+
prepareRemoveShare: (shareId: `0x${string}`) => Promise<ShareRegistryWrite<'removeShare'>>;
|
|
1306
1342
|
/** Importable shares addressed to the connected account (unexpired, not revoked), with their metadata. */
|
|
1307
1343
|
getIncomingShares: () => Promise<IncomingShare[]>;
|
|
1308
1344
|
/** One share by id, as posted; null when unknown or removed. */
|
package/dist/core.cjs
CHANGED
|
@@ -3464,23 +3464,25 @@ var getBlockRevokerData = async (publicClient) => {
|
|
|
3464
3464
|
}
|
|
3465
3465
|
return revokerData;
|
|
3466
3466
|
};
|
|
3467
|
-
var
|
|
3467
|
+
var prepareRevokeACP = (acp) => {
|
|
3468
3468
|
if (acp.revokerContract === viem.zeroAddress || acp.revokerData === 0) {
|
|
3469
3469
|
throw new Error("ACP is not revocable: it has no revoker (revokerContract/revokerData unset)");
|
|
3470
3470
|
}
|
|
3471
|
+
return {
|
|
3472
|
+
address: acp.revokerContract,
|
|
3473
|
+
abi: ACP_REVOKER_ABI,
|
|
3474
|
+
functionName: "revokeSingle",
|
|
3475
|
+
args: [BigInt(acp.revokerData)]
|
|
3476
|
+
};
|
|
3477
|
+
};
|
|
3478
|
+
var revokeACP = async (acp, walletClient) => {
|
|
3479
|
+
const write = prepareRevokeACP(acp);
|
|
3471
3480
|
if (walletClient.account == null)
|
|
3472
3481
|
throw new Error("Missing walletClient account");
|
|
3473
3482
|
if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
3474
3483
|
throw new Error("Only the acp issuer can revoke it");
|
|
3475
3484
|
}
|
|
3476
|
-
return walletClient.writeContract({
|
|
3477
|
-
address: acp.revokerContract,
|
|
3478
|
-
abi: ACP_REVOKER_ABI,
|
|
3479
|
-
functionName: "revokeSingle",
|
|
3480
|
-
args: [BigInt(acp.revokerData)],
|
|
3481
|
-
account: walletClient.account,
|
|
3482
|
-
chain: walletClient.chain
|
|
3483
|
-
});
|
|
3485
|
+
return walletClient.writeContract({ ...write, account: walletClient.account, chain: walletClient.chain });
|
|
3484
3486
|
};
|
|
3485
3487
|
var revokeAllACPs = async (walletClient, publicClient, revokerContract) => {
|
|
3486
3488
|
if (walletClient.account == null)
|
|
@@ -3531,28 +3533,36 @@ var metadataOf = (acp, { labels, metadata, appKey }) => {
|
|
|
3531
3533
|
}
|
|
3532
3534
|
return encodeShareMetadata(labels, { issuer: acp.issuer, appKey });
|
|
3533
3535
|
};
|
|
3534
|
-
var
|
|
3536
|
+
var prepareShareOnChain = (acp, registry, options = {}) => {
|
|
3535
3537
|
if (acp.type !== "sharing") {
|
|
3536
3538
|
throw new Error(`Cannot share a '${acp.type}' ACP on-chain \u2014 only 'sharing' ACPs are shareable.`);
|
|
3537
3539
|
}
|
|
3538
3540
|
if (acp.issuerSignature === "0x") {
|
|
3539
3541
|
throw new Error("Cannot share an unsigned sharing ACP \u2014 sign it first.");
|
|
3540
3542
|
}
|
|
3543
|
+
return {
|
|
3544
|
+
write: {
|
|
3545
|
+
address: registry,
|
|
3546
|
+
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3547
|
+
functionName: "share",
|
|
3548
|
+
args: [toChainShare(acp), metadataOf(acp, options)]
|
|
3549
|
+
},
|
|
3550
|
+
shareId: computeShareId(acp)
|
|
3551
|
+
};
|
|
3552
|
+
};
|
|
3553
|
+
var shareOnChain = async (acp, walletClient, registry, options = {}) => {
|
|
3554
|
+
const { write, shareId } = prepareShareOnChain(acp, registry, options);
|
|
3541
3555
|
if (walletClient.account == null)
|
|
3542
3556
|
throw new Error("Missing walletClient account");
|
|
3543
3557
|
if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
3544
3558
|
throw new Error("Only the ACP issuer can share it on-chain");
|
|
3545
3559
|
}
|
|
3546
|
-
const metadata = metadataOf(acp, options);
|
|
3547
3560
|
const txHash = await walletClient.writeContract({
|
|
3548
|
-
|
|
3549
|
-
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3550
|
-
functionName: "share",
|
|
3551
|
-
args: [toChainShare(acp), metadata],
|
|
3561
|
+
...write,
|
|
3552
3562
|
account: walletClient.account,
|
|
3553
3563
|
chain: walletClient.chain ?? null
|
|
3554
3564
|
});
|
|
3555
|
-
return { txHash, shareId
|
|
3565
|
+
return { txHash, shareId };
|
|
3556
3566
|
};
|
|
3557
3567
|
var toIncomingShare = ({ shareId, share: s, metadata }) => ({
|
|
3558
3568
|
shareId,
|
|
@@ -3587,14 +3597,17 @@ var importFromChain = async (share, publicClient, walletClient, importOptions =
|
|
|
3587
3597
|
const { shareId: _shareId, appKey: _appKey, ...options } = share;
|
|
3588
3598
|
return importShared({ ...options, type: "sharing" }, publicClient, walletClient, importOptions);
|
|
3589
3599
|
};
|
|
3600
|
+
var prepareRemoveShare = (shareId, registry) => ({
|
|
3601
|
+
address: registry,
|
|
3602
|
+
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3603
|
+
functionName: "removeShare",
|
|
3604
|
+
args: [shareId]
|
|
3605
|
+
});
|
|
3590
3606
|
var removeShareOnChain = async (shareId, walletClient, registry) => {
|
|
3591
3607
|
if (walletClient.account == null)
|
|
3592
3608
|
throw new Error("Missing walletClient account");
|
|
3593
3609
|
return walletClient.writeContract({
|
|
3594
|
-
|
|
3595
|
-
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3596
|
-
functionName: "removeShare",
|
|
3597
|
-
args: [shareId],
|
|
3610
|
+
...prepareRemoveShare(shareId, registry),
|
|
3598
3611
|
account: walletClient.account,
|
|
3599
3612
|
chain: walletClient.chain ?? null
|
|
3600
3613
|
});
|
|
@@ -3621,14 +3634,17 @@ var acps = {
|
|
|
3621
3634
|
selectActiveACP,
|
|
3622
3635
|
removeActiveACP,
|
|
3623
3636
|
revokeACP,
|
|
3637
|
+
prepareRevokeACP,
|
|
3624
3638
|
revokeAllACPs,
|
|
3625
3639
|
isACPRevoked,
|
|
3626
3640
|
checkAccess,
|
|
3627
3641
|
shareOnChain,
|
|
3642
|
+
prepareShareOnChain,
|
|
3628
3643
|
getIncomingShares,
|
|
3629
3644
|
getShareFromChain,
|
|
3630
3645
|
importFromChain,
|
|
3631
3646
|
removeShareOnChain,
|
|
3647
|
+
prepareRemoveShare,
|
|
3632
3648
|
computeShareId,
|
|
3633
3649
|
applyACPDefaultsFromChain,
|
|
3634
3650
|
getAclServedAddresses,
|
|
@@ -5411,6 +5427,12 @@ function createCofheClientBase(opts) {
|
|
|
5411
5427
|
});
|
|
5412
5428
|
}
|
|
5413
5429
|
};
|
|
5430
|
+
const _requireIssuer = (acp, what) => {
|
|
5431
|
+
const sender = connectStore.getState().walletClient?.account?.address;
|
|
5432
|
+
if (sender == null || sender.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
5433
|
+
throw new Error(`Only the acp issuer can ${what}`);
|
|
5434
|
+
}
|
|
5435
|
+
};
|
|
5414
5436
|
async function connect(publicClient, walletClient) {
|
|
5415
5437
|
const state = connectStore.getState();
|
|
5416
5438
|
if (state.connected && state.publicClient === publicClient && state.walletClient === walletClient)
|
|
@@ -5578,6 +5600,11 @@ function createCofheClientBase(opts) {
|
|
|
5578
5600
|
const { walletClient } = connectStore.getState();
|
|
5579
5601
|
return acps.revokeACP(acp, walletClient);
|
|
5580
5602
|
},
|
|
5603
|
+
prepareRevokeACP: (acp) => {
|
|
5604
|
+
_requireConnected();
|
|
5605
|
+
_requireIssuer(acp, "revoke it");
|
|
5606
|
+
return acps.prepareRevokeACP(acp);
|
|
5607
|
+
},
|
|
5581
5608
|
revokeAllACPs: async (revokerContract) => {
|
|
5582
5609
|
_requireConnected();
|
|
5583
5610
|
const { publicClient, walletClient } = connectStore.getState();
|
|
@@ -5601,6 +5628,21 @@ function createCofheClientBase(opts) {
|
|
|
5601
5628
|
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5602
5629
|
return acps.shareOnChain(acp, walletClient, sharingRegistry, { ...withAppKey(), ...options });
|
|
5603
5630
|
},
|
|
5631
|
+
prepareShareOnChain: async (acp, options) => {
|
|
5632
|
+
_requireConnected();
|
|
5633
|
+
_requireIssuer(acp, "share it on-chain");
|
|
5634
|
+
const { publicClient } = connectStore.getState();
|
|
5635
|
+
const chainId = await publicClient.getChainId();
|
|
5636
|
+
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5637
|
+
return acps.prepareShareOnChain(acp, sharingRegistry, { ...withAppKey(), ...options });
|
|
5638
|
+
},
|
|
5639
|
+
prepareRemoveShare: async (shareId) => {
|
|
5640
|
+
_requireConnected();
|
|
5641
|
+
const { publicClient } = connectStore.getState();
|
|
5642
|
+
const chainId = await publicClient.getChainId();
|
|
5643
|
+
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5644
|
+
return acps.prepareRemoveShare(shareId, sharingRegistry);
|
|
5645
|
+
},
|
|
5604
5646
|
getIncomingShares: async () => {
|
|
5605
5647
|
_requireConnected();
|
|
5606
5648
|
const { publicClient, walletClient } = connectStore.getState();
|
package/dist/core.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-
|
|
2
|
-
export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-
|
|
1
|
+
import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-RXwLVWou.cjs';
|
|
2
|
+
export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-RXwLVWou.cjs';
|
|
3
3
|
import { PublicClient, Address, Hex } from 'viem';
|
|
4
4
|
import './types-C07FK-cL.cjs';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import './onchain-utils-
|
|
6
|
+
import './onchain-utils-Ns56cBm0.cjs';
|
|
7
7
|
import 'zustand/vanilla';
|
|
8
8
|
|
|
9
9
|
declare const InitialConnectStore: CofheClientConnectionState;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-
|
|
2
|
-
export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-
|
|
1
|
+
import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-CnslFzxB.js';
|
|
2
|
+
export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-CnslFzxB.js';
|
|
3
3
|
import { PublicClient, Address, Hex } from 'viem';
|
|
4
4
|
import './types-C07FK-cL.js';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import './onchain-utils-
|
|
6
|
+
import './onchain-utils-Ns56cBm0.js';
|
|
7
7
|
import 'zustand/vanilla';
|
|
8
8
|
|
|
9
9
|
declare const InitialConnectStore: CofheClientConnectionState;
|
package/dist/core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { InitialConnectStore as CONNECT_STORE_DEFAULTS, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, assertNoRenamedConfigKeys, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, getCofheConfigItem, getCofheDebugInterceptors, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker } from './chunk-
|
|
1
|
+
export { InitialConnectStore as CONNECT_STORE_DEFAULTS, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, assertNoRenamedConfigKeys, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, getCofheConfigItem, getCofheDebugInterceptors, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker } from './chunk-2EO4JSR7.js';
|
|
2
2
|
import './chunk-UKQAJK4N.js';
|
|
3
3
|
export { getTaskManagerAddress } from './chunk-3L2IVPMI.js';
|
|
4
4
|
export { EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, fheTypeToString, isEncryptableItem, isLastEncryptionStep } from './chunk-WJGTPW7K.js';
|
package/dist/node.cjs
CHANGED
|
@@ -3257,23 +3257,25 @@ var getBlockRevokerData = async (publicClient) => {
|
|
|
3257
3257
|
}
|
|
3258
3258
|
return revokerData;
|
|
3259
3259
|
};
|
|
3260
|
-
var
|
|
3260
|
+
var prepareRevokeACP = (acp) => {
|
|
3261
3261
|
if (acp.revokerContract === viem.zeroAddress || acp.revokerData === 0) {
|
|
3262
3262
|
throw new Error("ACP is not revocable: it has no revoker (revokerContract/revokerData unset)");
|
|
3263
3263
|
}
|
|
3264
|
+
return {
|
|
3265
|
+
address: acp.revokerContract,
|
|
3266
|
+
abi: ACP_REVOKER_ABI,
|
|
3267
|
+
functionName: "revokeSingle",
|
|
3268
|
+
args: [BigInt(acp.revokerData)]
|
|
3269
|
+
};
|
|
3270
|
+
};
|
|
3271
|
+
var revokeACP = async (acp, walletClient) => {
|
|
3272
|
+
const write = prepareRevokeACP(acp);
|
|
3264
3273
|
if (walletClient.account == null)
|
|
3265
3274
|
throw new Error("Missing walletClient account");
|
|
3266
3275
|
if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
3267
3276
|
throw new Error("Only the acp issuer can revoke it");
|
|
3268
3277
|
}
|
|
3269
|
-
return walletClient.writeContract({
|
|
3270
|
-
address: acp.revokerContract,
|
|
3271
|
-
abi: ACP_REVOKER_ABI,
|
|
3272
|
-
functionName: "revokeSingle",
|
|
3273
|
-
args: [BigInt(acp.revokerData)],
|
|
3274
|
-
account: walletClient.account,
|
|
3275
|
-
chain: walletClient.chain
|
|
3276
|
-
});
|
|
3278
|
+
return walletClient.writeContract({ ...write, account: walletClient.account, chain: walletClient.chain });
|
|
3277
3279
|
};
|
|
3278
3280
|
var revokeAllACPs = async (walletClient, publicClient, revokerContract) => {
|
|
3279
3281
|
if (walletClient.account == null)
|
|
@@ -3324,28 +3326,36 @@ var metadataOf = (acp, { labels, metadata, appKey }) => {
|
|
|
3324
3326
|
}
|
|
3325
3327
|
return encodeShareMetadata(labels, { issuer: acp.issuer, appKey });
|
|
3326
3328
|
};
|
|
3327
|
-
var
|
|
3329
|
+
var prepareShareOnChain = (acp, registry, options = {}) => {
|
|
3328
3330
|
if (acp.type !== "sharing") {
|
|
3329
3331
|
throw new Error(`Cannot share a '${acp.type}' ACP on-chain \u2014 only 'sharing' ACPs are shareable.`);
|
|
3330
3332
|
}
|
|
3331
3333
|
if (acp.issuerSignature === "0x") {
|
|
3332
3334
|
throw new Error("Cannot share an unsigned sharing ACP \u2014 sign it first.");
|
|
3333
3335
|
}
|
|
3336
|
+
return {
|
|
3337
|
+
write: {
|
|
3338
|
+
address: registry,
|
|
3339
|
+
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3340
|
+
functionName: "share",
|
|
3341
|
+
args: [toChainShare(acp), metadataOf(acp, options)]
|
|
3342
|
+
},
|
|
3343
|
+
shareId: computeShareId(acp)
|
|
3344
|
+
};
|
|
3345
|
+
};
|
|
3346
|
+
var shareOnChain = async (acp, walletClient, registry, options = {}) => {
|
|
3347
|
+
const { write, shareId } = prepareShareOnChain(acp, registry, options);
|
|
3334
3348
|
if (walletClient.account == null)
|
|
3335
3349
|
throw new Error("Missing walletClient account");
|
|
3336
3350
|
if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
3337
3351
|
throw new Error("Only the ACP issuer can share it on-chain");
|
|
3338
3352
|
}
|
|
3339
|
-
const metadata = metadataOf(acp, options);
|
|
3340
3353
|
const txHash = await walletClient.writeContract({
|
|
3341
|
-
|
|
3342
|
-
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3343
|
-
functionName: "share",
|
|
3344
|
-
args: [toChainShare(acp), metadata],
|
|
3354
|
+
...write,
|
|
3345
3355
|
account: walletClient.account,
|
|
3346
3356
|
chain: walletClient.chain ?? null
|
|
3347
3357
|
});
|
|
3348
|
-
return { txHash, shareId
|
|
3358
|
+
return { txHash, shareId };
|
|
3349
3359
|
};
|
|
3350
3360
|
var toIncomingShare = ({ shareId, share: s, metadata }) => ({
|
|
3351
3361
|
shareId,
|
|
@@ -3380,14 +3390,17 @@ var importFromChain = async (share, publicClient, walletClient, importOptions =
|
|
|
3380
3390
|
const { shareId: _shareId, appKey: _appKey, ...options } = share;
|
|
3381
3391
|
return importShared({ ...options, type: "sharing" }, publicClient, walletClient, importOptions);
|
|
3382
3392
|
};
|
|
3393
|
+
var prepareRemoveShare = (shareId, registry) => ({
|
|
3394
|
+
address: registry,
|
|
3395
|
+
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3396
|
+
functionName: "removeShare",
|
|
3397
|
+
args: [shareId]
|
|
3398
|
+
});
|
|
3383
3399
|
var removeShareOnChain = async (shareId, walletClient, registry) => {
|
|
3384
3400
|
if (walletClient.account == null)
|
|
3385
3401
|
throw new Error("Missing walletClient account");
|
|
3386
3402
|
return walletClient.writeContract({
|
|
3387
|
-
|
|
3388
|
-
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3389
|
-
functionName: "removeShare",
|
|
3390
|
-
args: [shareId],
|
|
3403
|
+
...prepareRemoveShare(shareId, registry),
|
|
3391
3404
|
account: walletClient.account,
|
|
3392
3405
|
chain: walletClient.chain ?? null
|
|
3393
3406
|
});
|
|
@@ -3414,14 +3427,17 @@ var acps = {
|
|
|
3414
3427
|
selectActiveACP,
|
|
3415
3428
|
removeActiveACP,
|
|
3416
3429
|
revokeACP,
|
|
3430
|
+
prepareRevokeACP,
|
|
3417
3431
|
revokeAllACPs,
|
|
3418
3432
|
isACPRevoked,
|
|
3419
3433
|
checkAccess,
|
|
3420
3434
|
shareOnChain,
|
|
3435
|
+
prepareShareOnChain,
|
|
3421
3436
|
getIncomingShares,
|
|
3422
3437
|
getShareFromChain,
|
|
3423
3438
|
importFromChain,
|
|
3424
3439
|
removeShareOnChain,
|
|
3440
|
+
prepareRemoveShare,
|
|
3425
3441
|
computeShareId,
|
|
3426
3442
|
applyACPDefaultsFromChain,
|
|
3427
3443
|
getAclServedAddresses,
|
|
@@ -5197,6 +5213,12 @@ function createCofheClientBase(opts) {
|
|
|
5197
5213
|
});
|
|
5198
5214
|
}
|
|
5199
5215
|
};
|
|
5216
|
+
const _requireIssuer = (acp, what) => {
|
|
5217
|
+
const sender = connectStore.getState().walletClient?.account?.address;
|
|
5218
|
+
if (sender == null || sender.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
5219
|
+
throw new Error(`Only the acp issuer can ${what}`);
|
|
5220
|
+
}
|
|
5221
|
+
};
|
|
5200
5222
|
async function connect(publicClient, walletClient) {
|
|
5201
5223
|
const state = connectStore.getState();
|
|
5202
5224
|
if (state.connected && state.publicClient === publicClient && state.walletClient === walletClient)
|
|
@@ -5364,6 +5386,11 @@ function createCofheClientBase(opts) {
|
|
|
5364
5386
|
const { walletClient } = connectStore.getState();
|
|
5365
5387
|
return acps.revokeACP(acp, walletClient);
|
|
5366
5388
|
},
|
|
5389
|
+
prepareRevokeACP: (acp) => {
|
|
5390
|
+
_requireConnected();
|
|
5391
|
+
_requireIssuer(acp, "revoke it");
|
|
5392
|
+
return acps.prepareRevokeACP(acp);
|
|
5393
|
+
},
|
|
5367
5394
|
revokeAllACPs: async (revokerContract) => {
|
|
5368
5395
|
_requireConnected();
|
|
5369
5396
|
const { publicClient, walletClient } = connectStore.getState();
|
|
@@ -5387,6 +5414,21 @@ function createCofheClientBase(opts) {
|
|
|
5387
5414
|
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5388
5415
|
return acps.shareOnChain(acp, walletClient, sharingRegistry, { ...withAppKey(), ...options });
|
|
5389
5416
|
},
|
|
5417
|
+
prepareShareOnChain: async (acp, options) => {
|
|
5418
|
+
_requireConnected();
|
|
5419
|
+
_requireIssuer(acp, "share it on-chain");
|
|
5420
|
+
const { publicClient } = connectStore.getState();
|
|
5421
|
+
const chainId = await publicClient.getChainId();
|
|
5422
|
+
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5423
|
+
return acps.prepareShareOnChain(acp, sharingRegistry, { ...withAppKey(), ...options });
|
|
5424
|
+
},
|
|
5425
|
+
prepareRemoveShare: async (shareId) => {
|
|
5426
|
+
_requireConnected();
|
|
5427
|
+
const { publicClient } = connectStore.getState();
|
|
5428
|
+
const chainId = await publicClient.getChainId();
|
|
5429
|
+
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5430
|
+
return acps.prepareRemoveShare(shareId, sharingRegistry);
|
|
5431
|
+
},
|
|
5390
5432
|
getIncomingShares: async () => {
|
|
5391
5433
|
_requireConnected();
|
|
5392
5434
|
const { publicClient, walletClient } = connectStore.getState();
|
package/dist/node.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-
|
|
1
|
+
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-RXwLVWou.cjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './onchain-utils-
|
|
5
|
+
import './onchain-utils-Ns56cBm0.cjs';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/node.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-
|
|
1
|
+
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-CnslFzxB.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './onchain-utils-
|
|
5
|
+
import './onchain-utils-Ns56cBm0.js';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCofheConfigBase, createCofheClientBase } from './chunk-
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase } from './chunk-2EO4JSR7.js';
|
|
2
2
|
import './chunk-UKQAJK4N.js';
|
|
3
3
|
import './chunk-3L2IVPMI.js';
|
|
4
4
|
import { fromHexString } from './chunk-WJGTPW7K.js';
|