@cofhe/sdk 0.7.1 → 0.8.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 +35 -0
- package/acps/acp.ts +10 -1
- package/acps/index.ts +11 -0
- package/acps/onchain-utils.ts +188 -49
- package/acps/registry.ts +73 -0
- package/acps/test/onchainAccessStatus.test.ts +116 -0
- package/acps/types.ts +16 -0
- package/chains/chains/arbitrum.ts +14 -0
- package/chains/chains/ethereum.ts +14 -0
- package/chains/index.ts +5 -1
- package/chains/test/chains.test.ts +24 -3
- package/core/acps.ts +51 -143
- package/core/client.ts +13 -8
- package/core/clientTypes.ts +29 -4
- package/core/config.ts +25 -1
- package/core/consts.ts +14 -2
- package/core/decrypt/verifyDecryptResult.ts +4 -3
- package/core/encrypt/encryptInputsBuilder.ts +6 -0
- package/core/encrypt/zkPackProveVerify.ts +7 -1
- package/core/error.ts +1 -0
- package/core/fetchKeys.ts +2 -2
- package/core/index.ts +9 -1
- package/core/keyStore.ts +23 -10
- package/core/taskManager.ts +48 -0
- package/core/test/acps.test.ts +91 -1
- package/core/test/client.test.ts +41 -0
- package/core/test/config.test.ts +16 -0
- package/core/test/decrypt.test.ts +11 -4
- package/core/test/encryptInputsBuilder.test.ts +1 -1
- package/core/test/fetchKeys.test.ts +23 -2
- package/core/test/keyStore.test.ts +18 -6
- package/core/test/taskManager.test.ts +57 -0
- package/core/types.ts +8 -0
- package/dist/acps.cjs +314 -35
- package/dist/acps.d.cts +251 -4
- package/dist/acps.d.ts +251 -4
- package/dist/acps.js +2 -2
- package/dist/chains.cjs +26 -0
- package/dist/chains.d.cts +45 -1
- package/dist/chains.d.ts +45 -1
- package/dist/chains.js +1 -1
- package/dist/{chunk-43USWPEH.js → chunk-GGI7Y6AW.js} +59 -264
- package/dist/chunk-KSOV5B4B.js +50 -0
- package/dist/{chunk-ESMZCFJY.js → chunk-NMKMCAI3.js} +4 -2
- package/dist/{chunk-Q7CBWGQX.js → chunk-UJYOBHYA.js} +374 -37
- package/dist/{chunk-N6IDQRRU.js → chunk-UKQAJK4N.js} +25 -1
- package/dist/{clientTypes-BN3nbzYM.d.ts → clientTypes-5YPPR16m.d.ts} +77 -14
- package/dist/{clientTypes-CYZjFznO.d.cts → clientTypes-D3aIXmUp.d.cts} +77 -14
- package/dist/core.cjs +271 -136
- package/dist/core.d.cts +29 -8
- package/dist/core.d.ts +29 -8
- package/dist/core.js +4 -4
- package/dist/node.cjs +266 -136
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +5 -5
- package/dist/{acp-Wi6isVQI.d.cts → onchain-utils-CUAK8glx.d.cts} +31 -1
- package/dist/{acp-Wi6isVQI.d.ts → onchain-utils-CUAK8glx.d.ts} +31 -1
- package/dist/web.cjs +360 -150
- package/dist/web.d.cts +49 -3
- package/dist/web.d.ts +49 -3
- package/dist/web.js +51 -20
- package/dist/zkProve.worker.cjs +69 -15
- package/dist/zkProve.worker.js +23 -17
- package/node/storage.ts +2 -2
- package/node/test/inherited.test.ts +5 -1
- package/node/test/storage-memory-fallback.test.ts +47 -0
- package/package.json +5 -3
- package/web/index.ts +100 -26
- package/web/test/countingZkProveWorker.ts +31 -0
- package/web/test/inherited.web.test.ts +5 -1
- package/web/test/mainThreadPool.web.test.ts +174 -0
- package/web/test/threadPoolBenchHelper.ts +140 -0
- package/web/test/threadPoolOff.web.test.ts +17 -0
- package/web/test/threadPoolOn.web.test.ts +80 -0
- package/web/test/workerInitRace.web.test.ts +79 -0
- package/web/tfheThreadPool.ts +140 -0
- package/web/workerManager.ts +4 -2
- package/web/zkProve.worker.ts +42 -17
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isAddress, getAddress, zeroAddress, isHex, keccak256, toHex,
|
|
1
|
+
import { TASK_MANAGER_ID, COFHE_ADDRESS_BOOK_ADDRESS } from './chunk-NMKMCAI3.js';
|
|
2
|
+
import { isAddress, getAddress, zeroAddress, isHex, parseAbi, keccak256, toHex, encodeAbiParameters, decodeErrorResult } from 'viem';
|
|
3
3
|
import nacl from 'tweetnacl';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { createStore } from 'zustand/vanilla';
|
|
@@ -389,11 +389,202 @@ var SignatureUtils = {
|
|
|
389
389
|
throw new Error(`Unknown acp type: ${acpType}`);
|
|
390
390
|
}
|
|
391
391
|
};
|
|
392
|
+
|
|
393
|
+
// core/error.ts
|
|
394
|
+
var CofheErrorCode = /* @__PURE__ */ ((CofheErrorCode2) => {
|
|
395
|
+
CofheErrorCode2["InternalError"] = "INTERNAL_ERROR";
|
|
396
|
+
CofheErrorCode2["UnknownEnvironment"] = "UNKNOWN_ENVIRONMENT";
|
|
397
|
+
CofheErrorCode2["InitTfheFailed"] = "INIT_TFHE_FAILED";
|
|
398
|
+
CofheErrorCode2["InitViemFailed"] = "INIT_VIEM_FAILED";
|
|
399
|
+
CofheErrorCode2["InitEthersFailed"] = "INIT_ETHERS_FAILED";
|
|
400
|
+
CofheErrorCode2["NotConnected"] = "NOT_CONNECTED";
|
|
401
|
+
CofheErrorCode2["MissingPublicClient"] = "MISSING_PUBLIC_CLIENT";
|
|
402
|
+
CofheErrorCode2["MissingWalletClient"] = "MISSING_WALLET_CLIENT";
|
|
403
|
+
CofheErrorCode2["MissingProviderParam"] = "MISSING_PROVIDER_PARAM";
|
|
404
|
+
CofheErrorCode2["EmptySecurityZonesParam"] = "EMPTY_SECURITY_ZONES_PARAM";
|
|
405
|
+
CofheErrorCode2["InvalidACPData"] = "INVALID_ACP_DATA";
|
|
406
|
+
CofheErrorCode2["InvalidACPDomain"] = "INVALID_ACP_DOMAIN";
|
|
407
|
+
CofheErrorCode2["ACPNotFound"] = "ACP_NOT_FOUND";
|
|
408
|
+
CofheErrorCode2["CannotRemoveLastACP"] = "CANNOT_REMOVE_LAST_ACP";
|
|
409
|
+
CofheErrorCode2["AccountUninitialized"] = "ACCOUNT_UNINITIALIZED";
|
|
410
|
+
CofheErrorCode2["ChainIdUninitialized"] = "CHAIN_ID_UNINITIALIZED";
|
|
411
|
+
CofheErrorCode2["ConsumingContractUninitialized"] = "CONSUMING_CONTRACT_UNINITIALIZED";
|
|
412
|
+
CofheErrorCode2["SealOutputFailed"] = "SEAL_OUTPUT_FAILED";
|
|
413
|
+
CofheErrorCode2["SealOutputReturnedNull"] = "SEAL_OUTPUT_RETURNED_NULL";
|
|
414
|
+
CofheErrorCode2["InvalidUtype"] = "INVALID_UTYPE";
|
|
415
|
+
CofheErrorCode2["DecryptFailed"] = "DECRYPT_FAILED";
|
|
416
|
+
CofheErrorCode2["DecryptReturnedNull"] = "DECRYPT_RETURNED_NULL";
|
|
417
|
+
CofheErrorCode2["ZkMocksInsertCtHashesFailed"] = "ZK_MOCKS_INSERT_CT_HASHES_FAILED";
|
|
418
|
+
CofheErrorCode2["ZkMocksCalcCtHashesFailed"] = "ZK_MOCKS_CALC_CT_HASHES_FAILED";
|
|
419
|
+
CofheErrorCode2["ZkMocksVerifySignFailed"] = "ZK_MOCKS_VERIFY_SIGN_FAILED";
|
|
420
|
+
CofheErrorCode2["ZkMocksCreateProofSignatureFailed"] = "ZK_MOCKS_CREATE_PROOF_SIGNATURE_FAILED";
|
|
421
|
+
CofheErrorCode2["ZkVerifyFailed"] = "ZK_VERIFY_FAILED";
|
|
422
|
+
CofheErrorCode2["ZkPackFailed"] = "ZK_PACK_FAILED";
|
|
423
|
+
CofheErrorCode2["ZkProveFailed"] = "ZK_PROVE_FAILED";
|
|
424
|
+
CofheErrorCode2["EncryptRemainingInItems"] = "ENCRYPT_REMAINING_IN_ITEMS";
|
|
425
|
+
CofheErrorCode2["ZkUninitialized"] = "ZK_UNINITIALIZED";
|
|
426
|
+
CofheErrorCode2["ZkVerifierUrlUninitialized"] = "ZK_VERIFIER_URL_UNINITIALIZED";
|
|
427
|
+
CofheErrorCode2["ThresholdNetworkUrlUninitialized"] = "THRESHOLD_NETWORK_URL_UNINITIALIZED";
|
|
428
|
+
CofheErrorCode2["MissingConfig"] = "MISSING_CONFIG";
|
|
429
|
+
CofheErrorCode2["UnsupportedChain"] = "UNSUPPORTED_CHAIN";
|
|
430
|
+
CofheErrorCode2["MissingZkBuilderAndCrsGenerator"] = "MISSING_ZK_BUILDER_AND_CRS_GENERATOR";
|
|
431
|
+
CofheErrorCode2["MissingTfhePublicKeyDeserializer"] = "MISSING_TFHE_PUBLIC_KEY_DESERIALIZER";
|
|
432
|
+
CofheErrorCode2["MissingCompactPkeCrsDeserializer"] = "MISSING_COMPACT_PKE_CRS_DESERIALIZER";
|
|
433
|
+
CofheErrorCode2["MissingFheKey"] = "MISSING_FHE_KEY";
|
|
434
|
+
CofheErrorCode2["MissingCrs"] = "MISSING_CRS";
|
|
435
|
+
CofheErrorCode2["FetchKeysFailed"] = "FETCH_KEYS_FAILED";
|
|
436
|
+
CofheErrorCode2["PublicWalletGetChainIdFailed"] = "PUBLIC_WALLET_GET_CHAIN_ID_FAILED";
|
|
437
|
+
CofheErrorCode2["PublicWalletGetAddressesFailed"] = "PUBLIC_WALLET_GET_ADDRESSES_FAILED";
|
|
438
|
+
CofheErrorCode2["RehydrateKeysStoreFailed"] = "REHYDRATE_KEYS_STORE_FAILED";
|
|
439
|
+
CofheErrorCode2["TaskManagerUnresolved"] = "TASK_MANAGER_UNRESOLVED";
|
|
440
|
+
CofheErrorCode2["BadRequest"] = "BAD_REQUEST";
|
|
441
|
+
CofheErrorCode2["UnknownChain"] = "UNKNOWN_CHAIN";
|
|
442
|
+
CofheErrorCode2["ACPMalformed"] = "ACP_MALFORMED";
|
|
443
|
+
CofheErrorCode2["ACPDenied"] = "ACP_DENIED";
|
|
444
|
+
CofheErrorCode2["ACPExpired"] = "ACP_EXPIRED";
|
|
445
|
+
CofheErrorCode2["ACPInvalid"] = "ACP_INVALID";
|
|
446
|
+
CofheErrorCode2["ACPRevoked"] = "ACP_REVOKED";
|
|
447
|
+
CofheErrorCode2["NotPubliclyAllowed"] = "NOT_PUBLICLY_ALLOWED";
|
|
448
|
+
CofheErrorCode2["CtNotFound"] = "CT_NOT_FOUND";
|
|
449
|
+
CofheErrorCode2["UnsupportedSecurityZone"] = "UNSUPPORTED_SECURITY_ZONE";
|
|
450
|
+
CofheErrorCode2["UnsupportedType"] = "UNSUPPORTED_TYPE";
|
|
451
|
+
CofheErrorCode2["SigningFailed"] = "SIGNING_FAILED";
|
|
452
|
+
CofheErrorCode2["CtSourceError"] = "CT_SOURCE_ERROR";
|
|
453
|
+
CofheErrorCode2["ACPVerifierError"] = "ACP_VERIFIER_ERROR";
|
|
454
|
+
CofheErrorCode2["CtSourceTimeout"] = "CT_SOURCE_TIMEOUT";
|
|
455
|
+
CofheErrorCode2["ACPVerifierTimeout"] = "ACP_VERIFIER_TIMEOUT";
|
|
456
|
+
CofheErrorCode2["ACPRequired"] = "ACP_REQUIRED";
|
|
457
|
+
CofheErrorCode2["SealFailed"] = "SEAL_FAILED";
|
|
458
|
+
return CofheErrorCode2;
|
|
459
|
+
})(CofheErrorCode || {});
|
|
460
|
+
var CofheError = class _CofheError extends Error {
|
|
461
|
+
code;
|
|
462
|
+
cause;
|
|
463
|
+
hint;
|
|
464
|
+
context;
|
|
465
|
+
apiErrorCode;
|
|
466
|
+
constructor({ code, message, cause, hint, context, apiErrorCode }) {
|
|
467
|
+
const fullMessage = cause ? `${message} | Caused by: ${cause.message}` : message;
|
|
468
|
+
super(fullMessage);
|
|
469
|
+
this.name = "CofheError";
|
|
470
|
+
this.code = code;
|
|
471
|
+
this.cause = cause;
|
|
472
|
+
this.hint = hint;
|
|
473
|
+
this.context = context;
|
|
474
|
+
this.apiErrorCode = apiErrorCode;
|
|
475
|
+
if (Error.captureStackTrace) {
|
|
476
|
+
Error.captureStackTrace(this, _CofheError);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Creates a CofheError from an unknown error
|
|
481
|
+
* If the error is a CofheError, it is returned unchanged, else a new CofheError is created
|
|
482
|
+
* If a wrapperError is provided, it is used to create the new CofheError, else a default is used
|
|
483
|
+
*/
|
|
484
|
+
static fromError(error, wrapperError) {
|
|
485
|
+
if (isCofheError(error))
|
|
486
|
+
return error;
|
|
487
|
+
const cause = error instanceof Error ? error : new Error(`${error}`);
|
|
488
|
+
return new _CofheError({
|
|
489
|
+
code: wrapperError?.code ?? "INTERNAL_ERROR" /* InternalError */,
|
|
490
|
+
message: wrapperError?.message ?? "An internal error occurred",
|
|
491
|
+
hint: wrapperError?.hint,
|
|
492
|
+
context: wrapperError?.context,
|
|
493
|
+
apiErrorCode: wrapperError?.apiErrorCode,
|
|
494
|
+
cause
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Serializes the error to JSON string with proper handling of Error objects
|
|
499
|
+
*/
|
|
500
|
+
serialize() {
|
|
501
|
+
return bigintSafeJsonStringify({
|
|
502
|
+
name: this.name,
|
|
503
|
+
code: this.code,
|
|
504
|
+
message: this.message,
|
|
505
|
+
hint: this.hint,
|
|
506
|
+
context: this.context,
|
|
507
|
+
apiErrorCode: this.apiErrorCode,
|
|
508
|
+
cause: this.cause ? {
|
|
509
|
+
name: this.cause.name,
|
|
510
|
+
message: this.cause.message,
|
|
511
|
+
stack: this.cause.stack
|
|
512
|
+
} : void 0,
|
|
513
|
+
stack: this.stack
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Returns a human-readable string representation of the error
|
|
518
|
+
*/
|
|
519
|
+
toString() {
|
|
520
|
+
const codeSuffix = this.apiErrorCode ? ` (api: ${this.apiErrorCode})` : "";
|
|
521
|
+
const parts = [`${this.name} [${this.code}]${codeSuffix}: ${this.message}`];
|
|
522
|
+
if (this.hint) {
|
|
523
|
+
parts.push(`Hint: ${this.hint}`);
|
|
524
|
+
}
|
|
525
|
+
if (this.context && Object.keys(this.context).length > 0) {
|
|
526
|
+
parts.push(`Context: ${bigintSafeJsonStringify(this.context)}`);
|
|
527
|
+
}
|
|
528
|
+
if (this.stack) {
|
|
529
|
+
parts.push(`
|
|
530
|
+
Stack trace:`);
|
|
531
|
+
parts.push(this.stack);
|
|
532
|
+
}
|
|
533
|
+
if (this.cause) {
|
|
534
|
+
parts.push(`
|
|
535
|
+
Caused by: ${this.cause.name}: ${this.cause.message}`);
|
|
536
|
+
if (this.cause.stack) {
|
|
537
|
+
parts.push(this.cause.stack);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return parts.join("\n");
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
var bigintSafeJsonStringify = (value) => {
|
|
544
|
+
return JSON.stringify(value, (key, value2) => {
|
|
545
|
+
if (typeof value2 === "bigint") {
|
|
546
|
+
return `${value2}n`;
|
|
547
|
+
}
|
|
548
|
+
return value2;
|
|
549
|
+
});
|
|
550
|
+
};
|
|
551
|
+
var isCofheError = (error) => error instanceof CofheError;
|
|
552
|
+
|
|
553
|
+
// core/taskManager.ts
|
|
554
|
+
var ADDRESS_BOOK_ABI = parseAbi([
|
|
555
|
+
"function getTm(uint256 id) view returns (address)",
|
|
556
|
+
"error TaskManagerNotSet(uint256 id)"
|
|
557
|
+
]);
|
|
558
|
+
var taskManagerAddressCache = /* @__PURE__ */ new Map();
|
|
559
|
+
var getTaskManagerAddress = async (publicClient, chainId) => {
|
|
560
|
+
const id = chainId ?? publicClient.chain?.id ?? await publicClient.getChainId();
|
|
561
|
+
const cached = taskManagerAddressCache.get(id);
|
|
562
|
+
if (cached != null)
|
|
563
|
+
return cached;
|
|
564
|
+
const pending = publicClient.readContract({
|
|
565
|
+
address: COFHE_ADDRESS_BOOK_ADDRESS,
|
|
566
|
+
abi: ADDRESS_BOOK_ABI,
|
|
567
|
+
functionName: "getTm",
|
|
568
|
+
args: [TASK_MANAGER_ID]
|
|
569
|
+
}).catch((error) => {
|
|
570
|
+
taskManagerAddressCache.delete(id);
|
|
571
|
+
throw CofheError.fromError(error, {
|
|
572
|
+
code: "TASK_MANAGER_UNRESOLVED" /* TaskManagerUnresolved */,
|
|
573
|
+
message: `Failed to resolve the Task Manager from the CoFHEAddressBook on chain ${id}`,
|
|
574
|
+
hint: "Ensure CoFHE is deployed on this chain. On a local hardhat / anvil chain, deploy the CoFHE mocks first.",
|
|
575
|
+
context: { chainId: id, addressBook: COFHE_ADDRESS_BOOK_ADDRESS, taskManagerId: TASK_MANAGER_ID }
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
taskManagerAddressCache.set(id, pending);
|
|
579
|
+
return pending;
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// acps/onchain-utils.ts
|
|
392
583
|
var getAclAddress = async (publicClient) => {
|
|
393
584
|
const ACL_IFACE = "function acl() view returns (address)";
|
|
394
585
|
const aclAbi = parseAbi([ACL_IFACE]);
|
|
395
586
|
return await publicClient.readContract({
|
|
396
|
-
address:
|
|
587
|
+
address: await getTaskManagerAddress(publicClient),
|
|
397
588
|
abi: aclAbi,
|
|
398
589
|
functionName: "acl"
|
|
399
590
|
});
|
|
@@ -420,6 +611,34 @@ var getAclEIP712Domain = async (publicClient) => {
|
|
|
420
611
|
verifyingContract
|
|
421
612
|
};
|
|
422
613
|
};
|
|
614
|
+
var toACPTuple = (acp) => ({
|
|
615
|
+
issuer: acp.issuer,
|
|
616
|
+
expiration: BigInt(acp.expiration),
|
|
617
|
+
recipient: acp.recipient,
|
|
618
|
+
revokerData: BigInt(acp.revokerData),
|
|
619
|
+
revokerContract: acp.revokerContract,
|
|
620
|
+
scope: acp.scope,
|
|
621
|
+
contracts: acp.contracts,
|
|
622
|
+
handles: acp.handles,
|
|
623
|
+
sealingKey: acp.sealingKey,
|
|
624
|
+
issuerSignature: acp.issuerSignature,
|
|
625
|
+
recipientSignature: acp.recipientSignature
|
|
626
|
+
});
|
|
627
|
+
function revertErrorName(err, abi) {
|
|
628
|
+
const walk = err?.walk;
|
|
629
|
+
if (typeof walk === "function") {
|
|
630
|
+
const revertError = walk.call(err, (e) => e?.name === "ContractFunctionRevertedError");
|
|
631
|
+
if (revertError)
|
|
632
|
+
return revertError.data?.errorName ?? "";
|
|
633
|
+
}
|
|
634
|
+
const customErrorName = extractCustomErrorFromDetails(err, abi);
|
|
635
|
+
if (customErrorName)
|
|
636
|
+
return customErrorName;
|
|
637
|
+
const hhDetailsData = extractReturnData(err);
|
|
638
|
+
if (hhDetailsData != null)
|
|
639
|
+
return decodeErrorResult({ abi, data: hhDetailsData }).errorName;
|
|
640
|
+
return void 0;
|
|
641
|
+
}
|
|
423
642
|
var checkACPValidityOnChain = async (acp, publicClient) => {
|
|
424
643
|
const aclAddress = await getAclAddress(publicClient);
|
|
425
644
|
try {
|
|
@@ -427,43 +646,54 @@ var checkACPValidityOnChain = async (acp, publicClient) => {
|
|
|
427
646
|
address: aclAddress,
|
|
428
647
|
abi: checkACPValidityAbi,
|
|
429
648
|
functionName: "checkPermissionValidity",
|
|
430
|
-
args: [
|
|
431
|
-
{
|
|
432
|
-
issuer: acp.issuer,
|
|
433
|
-
expiration: BigInt(acp.expiration),
|
|
434
|
-
recipient: acp.recipient,
|
|
435
|
-
revokerData: BigInt(acp.revokerData),
|
|
436
|
-
revokerContract: acp.revokerContract,
|
|
437
|
-
scope: acp.scope,
|
|
438
|
-
contracts: acp.contracts,
|
|
439
|
-
handles: acp.handles,
|
|
440
|
-
sealingKey: acp.sealingKey,
|
|
441
|
-
issuerSignature: acp.issuerSignature,
|
|
442
|
-
recipientSignature: acp.recipientSignature
|
|
443
|
-
}
|
|
444
|
-
]
|
|
649
|
+
args: [toACPTuple(acp)]
|
|
445
650
|
});
|
|
446
651
|
return true;
|
|
447
652
|
} catch (err) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
653
|
+
const errorName = revertErrorName(err, checkACPValidityAbi);
|
|
654
|
+
if (errorName !== void 0)
|
|
655
|
+
throw new Error(errorName);
|
|
656
|
+
throw err;
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
var PERMISSION_ERROR_STATUS = {
|
|
660
|
+
PermissionInvalid_Expired: "expired",
|
|
661
|
+
PermissionInvalid_Disabled: "revoked",
|
|
662
|
+
PermissionInvalid_IssuerSignature: "invalid-issuer-signature",
|
|
663
|
+
PermissionInvalid_RecipientSignature: "invalid-recipient-signature"
|
|
664
|
+
};
|
|
665
|
+
var getACPAccessStatusOnChain = async (acp, publicClient, handle) => {
|
|
666
|
+
const aclAddress = await getAclAddress(publicClient);
|
|
667
|
+
try {
|
|
668
|
+
if (handle === void 0) {
|
|
669
|
+
await publicClient.simulateContract({
|
|
670
|
+
address: aclAddress,
|
|
671
|
+
abi: acpAccessAbi,
|
|
672
|
+
functionName: "checkPermissionValidity",
|
|
673
|
+
args: [toACPTuple(acp)]
|
|
464
674
|
});
|
|
465
|
-
|
|
675
|
+
return "valid";
|
|
466
676
|
}
|
|
677
|
+
const ctHash = BigInt(handle);
|
|
678
|
+
const allowed = await publicClient.readContract({
|
|
679
|
+
address: aclAddress,
|
|
680
|
+
abi: acpAccessAbi,
|
|
681
|
+
functionName: "isAllowedWithPermission",
|
|
682
|
+
args: [toACPTuple(acp), ctHash]
|
|
683
|
+
});
|
|
684
|
+
if (allowed)
|
|
685
|
+
return "allowed";
|
|
686
|
+
const issuerAllowed = await publicClient.readContract({
|
|
687
|
+
address: aclAddress,
|
|
688
|
+
abi: acpAccessAbi,
|
|
689
|
+
functionName: "isAllowed",
|
|
690
|
+
args: [ctHash, acp.issuer]
|
|
691
|
+
});
|
|
692
|
+
return issuerAllowed ? "out-of-scope" : "issuer-not-allowed";
|
|
693
|
+
} catch (err) {
|
|
694
|
+
const status = PERMISSION_ERROR_STATUS[revertErrorName(err, acpAccessAbi) ?? ""];
|
|
695
|
+
if (status)
|
|
696
|
+
return status;
|
|
467
697
|
throw err;
|
|
468
698
|
}
|
|
469
699
|
};
|
|
@@ -485,7 +715,8 @@ function extractCustomErrorFromDetails(err, abi) {
|
|
|
485
715
|
function extractReturnData(err) {
|
|
486
716
|
const anyErr = err;
|
|
487
717
|
const s = anyErr?.details ?? anyErr?.cause?.details ?? anyErr?.shortMessage ?? anyErr?.message ?? String(err);
|
|
488
|
-
|
|
718
|
+
const match = s.match(/return data:\s*(0x[a-fA-F0-9]+)/) ?? s.match(/custom error (0x[a-fA-F0-9]{8,})/);
|
|
719
|
+
return match?.[1];
|
|
489
720
|
}
|
|
490
721
|
var checkACPValidityAbi = [
|
|
491
722
|
{
|
|
@@ -585,6 +816,58 @@ var checkACPValidityAbi = [
|
|
|
585
816
|
inputs: []
|
|
586
817
|
}
|
|
587
818
|
];
|
|
819
|
+
var acpAccessAbi = [
|
|
820
|
+
...checkACPValidityAbi,
|
|
821
|
+
{
|
|
822
|
+
type: "function",
|
|
823
|
+
name: "isAllowedWithPermission",
|
|
824
|
+
inputs: [checkACPValidityAbi[0].inputs[0], { name: "handle", type: "uint256", internalType: "uint256" }],
|
|
825
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
826
|
+
stateMutability: "view"
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
type: "function",
|
|
830
|
+
name: "isAllowed",
|
|
831
|
+
inputs: [
|
|
832
|
+
{ name: "handle", type: "uint256", internalType: "uint256" },
|
|
833
|
+
{ name: "account", type: "address", internalType: "address" }
|
|
834
|
+
],
|
|
835
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
836
|
+
stateMutability: "view"
|
|
837
|
+
}
|
|
838
|
+
];
|
|
839
|
+
var ACL_SERVED_ADDRESSES_ABI = parseAbi([
|
|
840
|
+
"function acl() view returns (address)",
|
|
841
|
+
"function defaultRevokerContract() view returns (address)",
|
|
842
|
+
"function shareRegistry() view returns (address)"
|
|
843
|
+
]);
|
|
844
|
+
var aclServedAddressesCache = /* @__PURE__ */ new Map();
|
|
845
|
+
var clearAclServedAddresses = () => aclServedAddressesCache.clear();
|
|
846
|
+
var getAclServedAddresses = async (publicClient, chainId) => {
|
|
847
|
+
const cached = aclServedAddressesCache.get(chainId);
|
|
848
|
+
if (cached != null)
|
|
849
|
+
return cached;
|
|
850
|
+
let aclAddress;
|
|
851
|
+
try {
|
|
852
|
+
aclAddress = await publicClient.readContract({
|
|
853
|
+
address: await getTaskManagerAddress(publicClient, chainId),
|
|
854
|
+
abi: ACL_SERVED_ADDRESSES_ABI,
|
|
855
|
+
functionName: "acl"
|
|
856
|
+
});
|
|
857
|
+
} catch {
|
|
858
|
+
return {};
|
|
859
|
+
}
|
|
860
|
+
const [defaultRevoker, shareRegistry] = await Promise.all([
|
|
861
|
+
publicClient.readContract({ address: aclAddress, abi: ACL_SERVED_ADDRESSES_ABI, functionName: "defaultRevokerContract" }).catch(() => void 0),
|
|
862
|
+
publicClient.readContract({ address: aclAddress, abi: ACL_SERVED_ADDRESSES_ABI, functionName: "shareRegistry" }).catch(() => void 0)
|
|
863
|
+
]);
|
|
864
|
+
const resolved = {
|
|
865
|
+
defaultRevoker: defaultRevoker != null && defaultRevoker !== zeroAddress ? defaultRevoker : void 0,
|
|
866
|
+
shareRegistry: shareRegistry != null && shareRegistry !== zeroAddress ? shareRegistry : void 0
|
|
867
|
+
};
|
|
868
|
+
aclServedAddressesCache.set(chainId, resolved);
|
|
869
|
+
return resolved;
|
|
870
|
+
};
|
|
588
871
|
|
|
589
872
|
// acps/acp.ts
|
|
590
873
|
var ACPUtils = {
|
|
@@ -898,8 +1181,62 @@ var ACPUtils = {
|
|
|
898
1181
|
checkValidityOnChain: async (acp, publicClient) => {
|
|
899
1182
|
const publicAcp = ACPUtils.getPublic(acp);
|
|
900
1183
|
return checkACPValidityOnChain(publicAcp, publicClient);
|
|
1184
|
+
},
|
|
1185
|
+
/**
|
|
1186
|
+
* The acp on-chain status as a value instead of a revert: 'valid' or why not, and given a
|
|
1187
|
+
* handle, whether the acp may read it (see `ACPAccessStatus`).
|
|
1188
|
+
*/
|
|
1189
|
+
checkAccessOnChain: async (acp, publicClient, handle) => {
|
|
1190
|
+
return getACPAccessStatusOnChain(ACPUtils.getPublic(acp), publicClient, handle);
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
var ACP_REVOKER_ABI = parseAbi([
|
|
1194
|
+
"function revokeSingle(uint256 id)",
|
|
1195
|
+
"function revokeAllExisting()",
|
|
1196
|
+
"function disabled(address issuer, uint256 id) view returns (bool)"
|
|
1197
|
+
]);
|
|
1198
|
+
var ACP_SHARE_REGISTRY_ABI = parseAbi([
|
|
1199
|
+
"struct ACP { address issuer; uint64 expiration; address recipient; uint256 revokerData; address revokerContract; uint8 scope; address[] contracts; bytes32[] handles; bytes32 sealingKey; bytes issuerSignature; bytes recipientSignature; }",
|
|
1200
|
+
"function share(ACP calldata acp) external returns (bytes32)",
|
|
1201
|
+
"function removeShare(bytes32 shareId) external",
|
|
1202
|
+
"function sharesFor(address recipient) external view returns (ACP[] memory)",
|
|
1203
|
+
"function getShare(bytes32 shareId) external view returns (ACP memory)",
|
|
1204
|
+
"function isShareValid(bytes32 shareId) external view returns (bool)"
|
|
1205
|
+
]);
|
|
1206
|
+
var ACP_SHARE_TUPLE_ABI = [
|
|
1207
|
+
{
|
|
1208
|
+
type: "tuple",
|
|
1209
|
+
components: [
|
|
1210
|
+
{ name: "issuer", type: "address" },
|
|
1211
|
+
{ name: "expiration", type: "uint64" },
|
|
1212
|
+
{ name: "recipient", type: "address" },
|
|
1213
|
+
{ name: "revokerData", type: "uint256" },
|
|
1214
|
+
{ name: "revokerContract", type: "address" },
|
|
1215
|
+
{ name: "scope", type: "uint8" },
|
|
1216
|
+
{ name: "contracts", type: "address[]" },
|
|
1217
|
+
{ name: "handles", type: "bytes32[]" },
|
|
1218
|
+
{ name: "sealingKey", type: "bytes32" },
|
|
1219
|
+
{ name: "issuerSignature", type: "bytes" },
|
|
1220
|
+
{ name: "recipientSignature", type: "bytes" }
|
|
1221
|
+
]
|
|
901
1222
|
}
|
|
1223
|
+
];
|
|
1224
|
+
var ZERO_BYTES32 = `0x${"0".repeat(64)}`;
|
|
1225
|
+
var toChainShare = (acp) => {
|
|
1226
|
+
const pub = ACPUtils.getPublic(acp, true);
|
|
1227
|
+
return {
|
|
1228
|
+
...pub,
|
|
1229
|
+
expiration: BigInt(pub.expiration),
|
|
1230
|
+
revokerData: BigInt(pub.revokerData),
|
|
1231
|
+
sealingKey: ZERO_BYTES32,
|
|
1232
|
+
recipientSignature: "0x"
|
|
1233
|
+
};
|
|
1234
|
+
};
|
|
1235
|
+
var computeShareId = (acp) => {
|
|
1236
|
+
const p = toChainShare(acp);
|
|
1237
|
+
return keccak256(encodeAbiParameters(ACP_SHARE_TUPLE_ABI, [p]));
|
|
902
1238
|
};
|
|
1239
|
+
var shareIdOfChainShare = (share) => keccak256(encodeAbiParameters(ACP_SHARE_TUPLE_ABI, [share]));
|
|
903
1240
|
var ACP_STORE_DEFAULTS = {
|
|
904
1241
|
acps: {},
|
|
905
1242
|
activeACPHash: {}
|
|
@@ -1026,4 +1363,4 @@ var acpStore = {
|
|
|
1026
1363
|
resetStore
|
|
1027
1364
|
};
|
|
1028
1365
|
|
|
1029
|
-
export { ACPScope, ACPUtils, ACP_STORE_DEFAULTS, GenerateSealingKey, ImportACPOptionsValidator, ImportACPValidator, SelfACPOptionsValidator, SelfACPValidator, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, ValidationUtils, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, contractsSchema, getACP, getACPs, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, handlesSchema, removeACP, removeActiveACPHash, resetStore, seal, setACP, setActiveACPHash, unsealWithPrivateKey, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions };
|
|
1366
|
+
export { ACPScope, ACPUtils, ACP_REVOKER_ABI, ACP_SHARE_REGISTRY_ABI, ACP_SHARE_TUPLE_ABI, ACP_STORE_DEFAULTS, CofheError, CofheErrorCode, GenerateSealingKey, ImportACPOptionsValidator, ImportACPValidator, SelfACPOptionsValidator, SelfACPValidator, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, ValidationUtils, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearAclServedAddresses, clearStaleStore, computeShareId, contractsSchema, getACP, getACPs, getAclAddress, getAclServedAddresses, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, getTaskManagerAddress, handlesSchema, isCofheError, removeACP, removeActiveACPHash, resetStore, seal, setACP, setActiveACPHash, shareIdOfChainShare, toChainShare, unsealWithPrivateKey, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions };
|
|
@@ -59,6 +59,28 @@ var baseSepolia = defineChain({
|
|
|
59
59
|
environment: "TESTNET"
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
// chains/chains/ethereum.ts
|
|
63
|
+
var ethereum = defineChain({
|
|
64
|
+
id: 1,
|
|
65
|
+
name: "Ethereum",
|
|
66
|
+
network: "ethereum",
|
|
67
|
+
coFheUrl: "https://cofhe.mainnet.fhenix.zone",
|
|
68
|
+
verifierUrl: "https://cofhe-vrf.mainnet.fhenix.zone",
|
|
69
|
+
thresholdNetworkUrl: "https://cofhe-tn.mainnet.fhenix.zone",
|
|
70
|
+
environment: "MAINNET"
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// chains/chains/arbitrum.ts
|
|
74
|
+
var arbitrum = defineChain({
|
|
75
|
+
id: 42161,
|
|
76
|
+
name: "Arbitrum One",
|
|
77
|
+
network: "arbitrum",
|
|
78
|
+
coFheUrl: "https://cofhe.mainnet.fhenix.zone",
|
|
79
|
+
verifierUrl: "https://cofhe-vrf.mainnet.fhenix.zone",
|
|
80
|
+
thresholdNetworkUrl: "https://cofhe-tn.mainnet.fhenix.zone",
|
|
81
|
+
environment: "MAINNET"
|
|
82
|
+
});
|
|
83
|
+
|
|
62
84
|
// chains/chains/hardhat.ts
|
|
63
85
|
var hardhat = defineChain({
|
|
64
86
|
id: 31337,
|
|
@@ -98,6 +120,8 @@ var chains = {
|
|
|
98
120
|
sepolia,
|
|
99
121
|
arbSepolia,
|
|
100
122
|
baseSepolia,
|
|
123
|
+
ethereum,
|
|
124
|
+
arbitrum,
|
|
101
125
|
hardhat,
|
|
102
126
|
localcofhe,
|
|
103
127
|
stagingCofhe
|
|
@@ -111,4 +135,4 @@ var getChainByName = (name) => {
|
|
|
111
135
|
);
|
|
112
136
|
};
|
|
113
137
|
|
|
114
|
-
export { arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe };
|
|
138
|
+
export { arbSepolia, arbitrum, baseSepolia, chains, ethereum, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe };
|