@inco/lightning-js 0.0.0-bootstrap.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/LICENSE +201 -0
- package/README.md +587 -0
- package/dist/cjs/advancedacl/index.d.ts +2 -0
- package/dist/cjs/advancedacl/index.js +19 -0
- package/dist/cjs/advancedacl/session-key.d.ts +95 -0
- package/dist/cjs/advancedacl/session-key.js +376 -0
- package/dist/cjs/advancedacl/types.d.ts +16 -0
- package/dist/cjs/advancedacl/types.js +3 -0
- package/dist/cjs/attestedcompute/attested-compute.d.ts +65 -0
- package/dist/cjs/attestedcompute/attested-compute.js +80 -0
- package/dist/cjs/attestedcompute/types.d.ts +35 -0
- package/dist/cjs/attestedcompute/types.js +46 -0
- package/dist/cjs/attesteddecrypt/attested-decrypt.d.ts +61 -0
- package/dist/cjs/attesteddecrypt/attested-decrypt.js +118 -0
- package/dist/cjs/attesteddecrypt/index.d.ts +1 -0
- package/dist/cjs/attesteddecrypt/index.js +18 -0
- package/dist/cjs/attesteddecrypt/types.d.ts +27 -0
- package/dist/cjs/attesteddecrypt/types.js +16 -0
- package/dist/cjs/attestedreveal/attested-reveal.d.ts +21 -0
- package/dist/cjs/attestedreveal/attested-reveal.js +31 -0
- package/dist/cjs/attestedreveal/index.d.ts +2 -0
- package/dist/cjs/attestedreveal/index.js +21 -0
- package/dist/cjs/attestedreveal/types.d.ts +4 -0
- package/dist/cjs/attestedreveal/types.js +13 -0
- package/dist/cjs/binary.d.ts +104 -0
- package/dist/cjs/binary.js +171 -0
- package/dist/cjs/chain.d.ts +50 -0
- package/dist/cjs/chain.js +62 -0
- package/dist/cjs/eip712/eip712.d.ts +18 -0
- package/dist/cjs/eip712/eip712.js +51 -0
- package/dist/cjs/eip712/index.d.ts +1 -0
- package/dist/cjs/eip712/index.js +8 -0
- package/dist/cjs/elistattesteddecrypt/elist-attested-decrypt.d.ts +51 -0
- package/dist/cjs/elistattesteddecrypt/elist-attested-decrypt.js +94 -0
- package/dist/cjs/elistattesteddecrypt/index.d.ts +2 -0
- package/dist/cjs/elistattesteddecrypt/index.js +22 -0
- package/dist/cjs/elistattesteddecrypt/types.d.ts +31 -0
- package/dist/cjs/elistattesteddecrypt/types.js +16 -0
- package/dist/cjs/encryption/encryption.d.ts +235 -0
- package/dist/cjs/encryption/encryption.js +226 -0
- package/dist/cjs/encryption/index.d.ts +1 -0
- package/dist/cjs/encryption/index.js +19 -0
- package/dist/cjs/generated/abis/add-two.d.ts +117 -0
- package/dist/cjs/generated/abis/add-two.js +80 -0
- package/dist/cjs/generated/abis/lightning.d.ts +3362 -0
- package/dist/cjs/generated/abis/lightning.js +2445 -0
- package/dist/cjs/generated/abis/test-elist.d.ts +276 -0
- package/dist/cjs/generated/abis/test-elist.js +168 -0
- package/dist/cjs/generated/abis/verifier.d.ts +1353 -0
- package/dist/cjs/generated/abis/verifier.js +954 -0
- package/dist/cjs/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +1494 -0
- package/dist/cjs/generated/es/inco/covalidator/compute/v1/server_pb.js +395 -0
- package/dist/cjs/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +247 -0
- package/dist/cjs/generated/es/inco/covalidator/compute/v1/types_pb.js +80 -0
- package/dist/cjs/generated/es/inco/helioswrapper/v1/helioswrapper_pb.d.ts +77 -0
- package/dist/cjs/generated/es/inco/helioswrapper/v1/helioswrapper_pb.js +28 -0
- package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +685 -0
- package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.js +100 -0
- package/dist/cjs/generated/es/inco/kms/lite/v1/types_pb.d.ts +289 -0
- package/dist/cjs/generated/es/inco/kms/lite/v1/types_pb.js +136 -0
- package/dist/cjs/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +371 -0
- package/dist/cjs/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.js +88 -0
- package/dist/cjs/generated/lightning.d.ts +830 -0
- package/dist/cjs/generated/lightning.js +872 -0
- package/dist/cjs/generated/local-node.d.ts +50 -0
- package/dist/cjs/generated/local-node.js +107 -0
- package/dist/cjs/handle.d.ts +123 -0
- package/dist/cjs/handle.js +221 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/kms/client.d.ts +12 -0
- package/dist/cjs/kms/client.js +47 -0
- package/dist/cjs/kms/quorumClient.d.ts +65 -0
- package/dist/cjs/kms/quorumClient.js +463 -0
- package/dist/cjs/kms/quorumConsistency.d.ts +82 -0
- package/dist/cjs/kms/quorumConsistency.js +269 -0
- package/dist/cjs/kms/signatureVerification.d.ts +35 -0
- package/dist/cjs/kms/signatureVerification.js +88 -0
- package/dist/cjs/kms/thresholdPromises.d.ts +8 -0
- package/dist/cjs/kms/thresholdPromises.js +62 -0
- package/dist/cjs/lite/attested-compute.d.ts +6 -0
- package/dist/cjs/lite/attested-compute.js +8 -0
- package/dist/cjs/lite/attested-decrypt.d.ts +4 -0
- package/dist/cjs/lite/attested-decrypt.js +6 -0
- package/dist/cjs/lite/deployments.d.ts +24 -0
- package/dist/cjs/lite/deployments.js +21 -0
- package/dist/cjs/lite/hadu.d.ts +4 -0
- package/dist/cjs/lite/hadu.js +28 -0
- package/dist/cjs/lite/index.d.ts +13 -0
- package/dist/cjs/lite/index.js +31 -0
- package/dist/cjs/lite/lightning.d.ts +459 -0
- package/dist/cjs/lite/lightning.js +696 -0
- package/dist/cjs/lite/types.d.ts +47 -0
- package/dist/cjs/lite/types.js +3 -0
- package/dist/cjs/lite/xwing.d.ts +154 -0
- package/dist/cjs/lite/xwing.js +326 -0
- package/dist/cjs/local/index.d.ts +1 -0
- package/dist/cjs/local/index.js +18 -0
- package/dist/cjs/local/local-node.d.ts +37 -0
- package/dist/cjs/local/local-node.js +80 -0
- package/dist/cjs/reencryption/eip712.d.ts +56 -0
- package/dist/cjs/reencryption/eip712.js +90 -0
- package/dist/cjs/reencryption/index.d.ts +2 -0
- package/dist/cjs/reencryption/index.js +19 -0
- package/dist/cjs/reencryption/types.d.ts +48 -0
- package/dist/cjs/reencryption/types.js +3 -0
- package/dist/cjs/retry.d.ts +30 -0
- package/dist/cjs/retry.js +87 -0
- package/dist/cjs/schema.d.ts +4 -0
- package/dist/cjs/schema.js +19 -0
- package/dist/cjs/test/mocks.d.ts +20 -0
- package/dist/cjs/test/mocks.js +72 -0
- package/dist/cjs/viem.d.ts +1141 -0
- package/dist/cjs/viem.js +36 -0
- package/dist/esm/advancedacl/index.d.ts +2 -0
- package/dist/esm/advancedacl/index.js +3 -0
- package/dist/esm/advancedacl/session-key.d.ts +95 -0
- package/dist/esm/advancedacl/session-key.js +367 -0
- package/dist/esm/advancedacl/types.d.ts +16 -0
- package/dist/esm/advancedacl/types.js +2 -0
- package/dist/esm/attestedcompute/attested-compute.d.ts +65 -0
- package/dist/esm/attestedcompute/attested-compute.js +76 -0
- package/dist/esm/attestedcompute/types.d.ts +35 -0
- package/dist/esm/attestedcompute/types.js +42 -0
- package/dist/esm/attesteddecrypt/attested-decrypt.d.ts +61 -0
- package/dist/esm/attesteddecrypt/attested-decrypt.js +112 -0
- package/dist/esm/attesteddecrypt/index.d.ts +1 -0
- package/dist/esm/attesteddecrypt/index.js +2 -0
- package/dist/esm/attesteddecrypt/types.d.ts +27 -0
- package/dist/esm/attesteddecrypt/types.js +12 -0
- package/dist/esm/attestedreveal/attested-reveal.d.ts +21 -0
- package/dist/esm/attestedreveal/attested-reveal.js +28 -0
- package/dist/esm/attestedreveal/index.d.ts +2 -0
- package/dist/esm/attestedreveal/index.js +3 -0
- package/dist/esm/attestedreveal/types.d.ts +4 -0
- package/dist/esm/attestedreveal/types.js +9 -0
- package/dist/esm/binary.d.ts +104 -0
- package/dist/esm/binary.js +155 -0
- package/dist/esm/chain.d.ts +50 -0
- package/dist/esm/chain.js +58 -0
- package/dist/esm/eip712/eip712.d.ts +18 -0
- package/dist/esm/eip712/eip712.js +46 -0
- package/dist/esm/eip712/index.d.ts +1 -0
- package/dist/esm/eip712/index.js +2 -0
- package/dist/esm/elistattesteddecrypt/elist-attested-decrypt.d.ts +51 -0
- package/dist/esm/elistattesteddecrypt/elist-attested-decrypt.js +89 -0
- package/dist/esm/elistattesteddecrypt/index.d.ts +2 -0
- package/dist/esm/elistattesteddecrypt/index.js +3 -0
- package/dist/esm/elistattesteddecrypt/types.d.ts +31 -0
- package/dist/esm/elistattesteddecrypt/types.js +12 -0
- package/dist/esm/encryption/encryption.d.ts +235 -0
- package/dist/esm/encryption/encryption.js +214 -0
- package/dist/esm/encryption/index.d.ts +1 -0
- package/dist/esm/encryption/index.js +2 -0
- package/dist/esm/generated/abis/add-two.d.ts +117 -0
- package/dist/esm/generated/abis/add-two.js +77 -0
- package/dist/esm/generated/abis/lightning.d.ts +3362 -0
- package/dist/esm/generated/abis/lightning.js +2442 -0
- package/dist/esm/generated/abis/test-elist.d.ts +276 -0
- package/dist/esm/generated/abis/test-elist.js +165 -0
- package/dist/esm/generated/abis/verifier.d.ts +1353 -0
- package/dist/esm/generated/abis/verifier.js +951 -0
- package/dist/esm/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +1494 -0
- package/dist/esm/generated/es/inco/covalidator/compute/v1/server_pb.js +392 -0
- package/dist/esm/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +247 -0
- package/dist/esm/generated/es/inco/covalidator/compute/v1/types_pb.js +77 -0
- package/dist/esm/generated/es/inco/helioswrapper/v1/helioswrapper_pb.d.ts +77 -0
- package/dist/esm/generated/es/inco/helioswrapper/v1/helioswrapper_pb.js +25 -0
- package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +685 -0
- package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.js +97 -0
- package/dist/esm/generated/es/inco/kms/lite/v1/types_pb.d.ts +289 -0
- package/dist/esm/generated/es/inco/kms/lite/v1/types_pb.js +133 -0
- package/dist/esm/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +371 -0
- package/dist/esm/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.js +85 -0
- package/dist/esm/generated/lightning.d.ts +830 -0
- package/dist/esm/generated/lightning.js +869 -0
- package/dist/esm/generated/local-node.d.ts +50 -0
- package/dist/esm/generated/local-node.js +104 -0
- package/dist/esm/handle.d.ts +123 -0
- package/dist/esm/handle.js +212 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/kms/client.d.ts +12 -0
- package/dist/esm/kms/client.js +40 -0
- package/dist/esm/kms/quorumClient.d.ts +65 -0
- package/dist/esm/kms/quorumClient.js +459 -0
- package/dist/esm/kms/quorumConsistency.d.ts +82 -0
- package/dist/esm/kms/quorumConsistency.js +260 -0
- package/dist/esm/kms/signatureVerification.d.ts +35 -0
- package/dist/esm/kms/signatureVerification.js +84 -0
- package/dist/esm/kms/thresholdPromises.d.ts +8 -0
- package/dist/esm/kms/thresholdPromises.js +59 -0
- package/dist/esm/lite/attested-compute.d.ts +6 -0
- package/dist/esm/lite/attested-compute.js +4 -0
- package/dist/esm/lite/attested-decrypt.d.ts +4 -0
- package/dist/esm/lite/attested-decrypt.js +3 -0
- package/dist/esm/lite/deployments.d.ts +24 -0
- package/dist/esm/lite/deployments.js +17 -0
- package/dist/esm/lite/hadu.d.ts +4 -0
- package/dist/esm/lite/hadu.js +24 -0
- package/dist/esm/lite/index.d.ts +13 -0
- package/dist/esm/lite/index.js +10 -0
- package/dist/esm/lite/lightning.d.ts +459 -0
- package/dist/esm/lite/lightning.js +692 -0
- package/dist/esm/lite/types.d.ts +47 -0
- package/dist/esm/lite/types.js +2 -0
- package/dist/esm/lite/xwing.d.ts +154 -0
- package/dist/esm/lite/xwing.js +311 -0
- package/dist/esm/local/index.d.ts +1 -0
- package/dist/esm/local/index.js +2 -0
- package/dist/esm/local/local-node.d.ts +37 -0
- package/dist/esm/local/local-node.js +76 -0
- package/dist/esm/reencryption/eip712.d.ts +56 -0
- package/dist/esm/reencryption/eip712.js +87 -0
- package/dist/esm/reencryption/index.d.ts +2 -0
- package/dist/esm/reencryption/index.js +3 -0
- package/dist/esm/reencryption/types.d.ts +48 -0
- package/dist/esm/reencryption/types.js +2 -0
- package/dist/esm/retry.d.ts +30 -0
- package/dist/esm/retry.js +82 -0
- package/dist/esm/schema.d.ts +4 -0
- package/dist/esm/schema.js +15 -0
- package/dist/esm/test/mocks.d.ts +20 -0
- package/dist/esm/test/mocks.js +64 -0
- package/dist/esm/viem.d.ts +1141 -0
- package/dist/esm/viem.js +32 -0
- package/dist/types/advancedacl/index.d.ts +2 -0
- package/dist/types/advancedacl/session-key.d.ts +95 -0
- package/dist/types/advancedacl/types.d.ts +16 -0
- package/dist/types/attestedcompute/attested-compute.d.ts +65 -0
- package/dist/types/attestedcompute/types.d.ts +35 -0
- package/dist/types/attesteddecrypt/attested-decrypt.d.ts +61 -0
- package/dist/types/attesteddecrypt/index.d.ts +1 -0
- package/dist/types/attesteddecrypt/types.d.ts +27 -0
- package/dist/types/attestedreveal/attested-reveal.d.ts +21 -0
- package/dist/types/attestedreveal/index.d.ts +2 -0
- package/dist/types/attestedreveal/types.d.ts +4 -0
- package/dist/types/binary.d.ts +104 -0
- package/dist/types/chain.d.ts +50 -0
- package/dist/types/eip712/eip712.d.ts +18 -0
- package/dist/types/eip712/index.d.ts +1 -0
- package/dist/types/elistattesteddecrypt/elist-attested-decrypt.d.ts +51 -0
- package/dist/types/elistattesteddecrypt/index.d.ts +2 -0
- package/dist/types/elistattesteddecrypt/types.d.ts +31 -0
- package/dist/types/encryption/encryption.d.ts +235 -0
- package/dist/types/encryption/index.d.ts +1 -0
- package/dist/types/generated/abis/add-two.d.ts +117 -0
- package/dist/types/generated/abis/lightning.d.ts +3362 -0
- package/dist/types/generated/abis/test-elist.d.ts +276 -0
- package/dist/types/generated/abis/verifier.d.ts +1353 -0
- package/dist/types/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +1494 -0
- package/dist/types/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +247 -0
- package/dist/types/generated/es/inco/helioswrapper/v1/helioswrapper_pb.d.ts +77 -0
- package/dist/types/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +685 -0
- package/dist/types/generated/es/inco/kms/lite/v1/types_pb.d.ts +289 -0
- package/dist/types/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +371 -0
- package/dist/types/generated/lightning.d.ts +830 -0
- package/dist/types/generated/local-node.d.ts +50 -0
- package/dist/types/handle.d.ts +123 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/kms/client.d.ts +12 -0
- package/dist/types/kms/quorumClient.d.ts +65 -0
- package/dist/types/kms/quorumConsistency.d.ts +82 -0
- package/dist/types/kms/signatureVerification.d.ts +35 -0
- package/dist/types/kms/thresholdPromises.d.ts +8 -0
- package/dist/types/lite/attested-compute.d.ts +6 -0
- package/dist/types/lite/attested-decrypt.d.ts +4 -0
- package/dist/types/lite/deployments.d.ts +24 -0
- package/dist/types/lite/hadu.d.ts +4 -0
- package/dist/types/lite/index.d.ts +13 -0
- package/dist/types/lite/lightning.d.ts +459 -0
- package/dist/types/lite/types.d.ts +47 -0
- package/dist/types/lite/xwing.d.ts +154 -0
- package/dist/types/local/index.d.ts +1 -0
- package/dist/types/local/local-node.d.ts +37 -0
- package/dist/types/reencryption/eip712.d.ts +56 -0
- package/dist/types/reencryption/index.d.ts +2 -0
- package/dist/types/reencryption/types.d.ts +48 -0
- package/dist/types/retry.d.ts +30 -0
- package/dist/types/schema.d.ts +4 -0
- package/dist/types/test/mocks.d.ts +20 -0
- package/dist/types/viem.d.ts +1141 -0
- package/package.json +129 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { create } from '@bufbuild/protobuf';
|
|
2
|
+
import { bytesToHex, hexToBytes } from 'viem';
|
|
3
|
+
import { decryptEncryptedAttestations, validateHandle, } from '../attesteddecrypt/attested-decrypt.js';
|
|
4
|
+
import { bigintToBytes32 } from '../binary.js';
|
|
5
|
+
import { fetchEip712DomainVersion } from '../eip712/eip712.js';
|
|
6
|
+
import { AttestedComputeRequestSchema, } from '../generated/es/inco/kms/lite/v1/kms_service_pb.js';
|
|
7
|
+
import { reencryptPublicKeysMatch } from '../lite/xwing.js';
|
|
8
|
+
import { createEIP712Payload } from '../reencryption/eip712.js';
|
|
9
|
+
import { AttestedComputeError } from './types.js';
|
|
10
|
+
export const ATTESTED_COMPUTE_DOMAIN_NAME = 'IncoAttestedCompute';
|
|
11
|
+
export async function attestedCompute({ executorAddress, lhsHandle, op, rhsPlaintext, backoffConfig, walletClient, kmsQuorumClient, chainId, reencryptPubKey, reencryptKeypair, }) {
|
|
12
|
+
try {
|
|
13
|
+
validateHandle(lhsHandle);
|
|
14
|
+
if (reencryptPubKey &&
|
|
15
|
+
reencryptKeypair &&
|
|
16
|
+
!reencryptPublicKeysMatch(reencryptPubKey, reencryptKeypair)) {
|
|
17
|
+
throw new AttestedComputeError('reencryptPubKey does not match reencryptKeypair public key');
|
|
18
|
+
}
|
|
19
|
+
const rhsPlaintextBig = typeof rhsPlaintext === 'boolean'
|
|
20
|
+
? rhsPlaintext
|
|
21
|
+
? 1n
|
|
22
|
+
: 0n
|
|
23
|
+
: BigInt(rhsPlaintext);
|
|
24
|
+
const eip712DomainVersion = await fetchEip712DomainVersion(executorAddress, walletClient);
|
|
25
|
+
// Create the EIP712 payload for the handles to decrypt
|
|
26
|
+
const eip712Payload = createEIP712Payload({
|
|
27
|
+
chainId: BigInt(chainId),
|
|
28
|
+
primaryType: 'AttestedComputeRequest',
|
|
29
|
+
primaryTypeFields: [
|
|
30
|
+
{ name: 'op', type: 'uint8' },
|
|
31
|
+
{ name: 'lhsHandle', type: 'bytes32' },
|
|
32
|
+
{ name: 'rhsPlaintext', type: 'bytes32' },
|
|
33
|
+
{ name: 'publicKey', type: 'bytes' },
|
|
34
|
+
],
|
|
35
|
+
message: {
|
|
36
|
+
op: op,
|
|
37
|
+
lhsHandle: lhsHandle,
|
|
38
|
+
rhsPlaintext: bigintToBytes32(rhsPlaintextBig),
|
|
39
|
+
publicKey: bytesToHex(reencryptPubKey ? reencryptPubKey : new Uint8Array()),
|
|
40
|
+
},
|
|
41
|
+
domainName: ATTESTED_COMPUTE_DOMAIN_NAME,
|
|
42
|
+
domainVersion: eip712DomainVersion,
|
|
43
|
+
});
|
|
44
|
+
// Sign the EIP712 message
|
|
45
|
+
const eip712Signature = await walletClient.signTypedData(eip712Payload);
|
|
46
|
+
const attestedComputeRequest = create(AttestedComputeRequestSchema, {
|
|
47
|
+
userAddress: walletClient.account.address,
|
|
48
|
+
reencryptPubKey: reencryptPubKey ? reencryptPubKey : new Uint8Array(),
|
|
49
|
+
op: op,
|
|
50
|
+
lhsHandle: lhsHandle,
|
|
51
|
+
rhsPlaintext: rhsPlaintextBig.toString(16),
|
|
52
|
+
eip712Signature: hexToBytes(eip712Signature),
|
|
53
|
+
aclProof: {
|
|
54
|
+
proof: {
|
|
55
|
+
case: 'incoLiteBasicAclProof',
|
|
56
|
+
value: {},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
// Envelope signatures are verified against the on-chain authorized signer set
|
|
61
|
+
let decryptionAttestation = await kmsQuorumClient.attestedCompute(attestedComputeRequest, executorAddress, walletClient, backoffConfig, reencryptKeypair);
|
|
62
|
+
// Decrypt encrypted attestations and verify inner DecryptionAttestation signatures
|
|
63
|
+
if (reencryptPubKey && reencryptKeypair) {
|
|
64
|
+
const [decryptedAttestation] = await decryptEncryptedAttestations([decryptionAttestation], reencryptKeypair);
|
|
65
|
+
return decryptedAttestation;
|
|
66
|
+
}
|
|
67
|
+
return decryptionAttestation;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof AttestedComputeError) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
throw new AttestedComputeError('Failed to perform attested compute', error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=data:application/json;base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UNuRixJQUFJLGVBQWUsSUFBSSxnQkFBZ0IsRUFBRSxDQUFDO1lBQ3hDLE1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyxHQUFHLE1BQU0sNEJBQTRCLENBQy9ELENBQUMscUJBQXFCLENBQUMsRUFDdkIsZ0JBQWdCLENBQ2pCLENBQUM7WUFDRixPQUFPLG9CQUFrRSxDQUFDO1FBQzVFLENBQUM7UUFFRCxPQUFPLHFCQUVnRCxDQUFDO0lBQzFELENBQUM7SUFBQyxPQUFPLEtBQUssRUFBRSxDQUFDO1FBQ2YsSUFBSSxLQUFLLFlBQVksb0JBQW9CLEVBQUUsQ0FBQztZQUMxQyxNQUFNLEtBQUssQ0FBQztRQUNkLENBQUM7UUFDRCxNQUFNLElBQUksb0JBQW9CLENBQUMsb0NBQW9DLEVBQUUsS0FBSyxDQUFDLENBQUM7SUFDOUUsQ0FBQztBQUNILENBQUMifQ==
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { DecryptionAttestation } from '../attesteddecrypt/types.js';
|
|
2
|
+
import { HexString } from '../binary.js';
|
|
3
|
+
import { EncryptionScheme, SupportedTeeType } from '../encryption/encryption.js';
|
|
4
|
+
import { SupportedScalarBinaryOp } from '../generated/es/inco/kms/lite/v1/types_pb.js';
|
|
5
|
+
import type { BackoffConfig } from '../retry.js';
|
|
6
|
+
/**
|
|
7
|
+
* Supported attested compute operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare const AttestedComputeSupportedOps: {
|
|
10
|
+
readonly Eq: SupportedScalarBinaryOp.TEE_EQ;
|
|
11
|
+
readonly Ne: SupportedScalarBinaryOp.TEE_NE;
|
|
12
|
+
readonly Ge: SupportedScalarBinaryOp.TEE_GE;
|
|
13
|
+
readonly Gt: SupportedScalarBinaryOp.TEE_GT;
|
|
14
|
+
readonly Le: SupportedScalarBinaryOp.TEE_LE;
|
|
15
|
+
readonly Lt: SupportedScalarBinaryOp.TEE_LT;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* This type represents all the supported operations for attested compute.
|
|
19
|
+
*/
|
|
20
|
+
export type AttestedComputeOP = (typeof AttestedComputeSupportedOps)[keyof typeof AttestedComputeSupportedOps];
|
|
21
|
+
/**
|
|
22
|
+
* Custom error class for attested compute operations.
|
|
23
|
+
*/
|
|
24
|
+
export declare class AttestedComputeError extends Error {
|
|
25
|
+
readonly cause?: unknown | undefined;
|
|
26
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
27
|
+
}
|
|
28
|
+
export type AttestedCompute<S extends EncryptionScheme> = <T extends SupportedTeeType>(args: AttestedComputeFnArgs<S, T>) => Promise<DecryptionAttestation<S, T>>;
|
|
29
|
+
export type AttestedComputeFnArgs<S extends EncryptionScheme, T extends SupportedTeeType> = {
|
|
30
|
+
/** The handle to compute on */
|
|
31
|
+
lhsHandle: HexString;
|
|
32
|
+
op: AttestedComputeOP;
|
|
33
|
+
rhsPlaintext: bigint | boolean;
|
|
34
|
+
backoffConfig?: Partial<BackoffConfig>;
|
|
35
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SupportedScalarBinaryOp } from '../generated/es/inco/kms/lite/v1/types_pb.js';
|
|
2
|
+
/**
|
|
3
|
+
* Supported attested compute operations.
|
|
4
|
+
*/
|
|
5
|
+
export const AttestedComputeSupportedOps = {
|
|
6
|
+
/*
|
|
7
|
+
Add: SupportedScalarBinaryOp.TEE_ADD,
|
|
8
|
+
Sub: SupportedScalarBinaryOp.TEE_SUB,
|
|
9
|
+
Mul: SupportedScalarBinaryOp.TEE_MUL,
|
|
10
|
+
Div: SupportedScalarBinaryOp.TEE_DIV,
|
|
11
|
+
Rem: SupportedScalarBinaryOp.TEE_REM,
|
|
12
|
+
BitAnd: SupportedScalarBinaryOp.TEE_BIT_AND,
|
|
13
|
+
BitOr: SupportedScalarBinaryOp.TEE_BIT_OR,
|
|
14
|
+
BitXor: SupportedScalarBinaryOp.TEE_BIT_XOR,
|
|
15
|
+
Shl: SupportedScalarBinaryOp.TEE_SHL,
|
|
16
|
+
Shr: SupportedScalarBinaryOp.TEE_SHR,
|
|
17
|
+
Rotl: SupportedScalarBinaryOp.TEE_ROTL,
|
|
18
|
+
Rotr: SupportedScalarBinaryOp.TEE_ROTR,
|
|
19
|
+
*/
|
|
20
|
+
Eq: SupportedScalarBinaryOp.TEE_EQ,
|
|
21
|
+
Ne: SupportedScalarBinaryOp.TEE_NE,
|
|
22
|
+
Ge: SupportedScalarBinaryOp.TEE_GE,
|
|
23
|
+
Gt: SupportedScalarBinaryOp.TEE_GT,
|
|
24
|
+
Le: SupportedScalarBinaryOp.TEE_LE,
|
|
25
|
+
Lt: SupportedScalarBinaryOp.TEE_LT,
|
|
26
|
+
/*
|
|
27
|
+
Min: SupportedScalarBinaryOp.TEE_MIN,
|
|
28
|
+
Max: SupportedScalarBinaryOp.TEE_MAX,
|
|
29
|
+
*/
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Custom error class for attested compute operations.
|
|
33
|
+
*/
|
|
34
|
+
export class AttestedComputeError extends Error {
|
|
35
|
+
cause;
|
|
36
|
+
constructor(message, cause) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.cause = cause;
|
|
39
|
+
this.name = 'AttestedComputeError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRjb21wdXRlL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sRUFBRSx1QkFBdUIsRUFBRSxNQUFNLDhDQUE4QyxDQUFDO0FBR3ZGOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sMkJBQTJCLEdBQUc7SUFDekM7Ozs7Ozs7Ozs7Ozs7TUFhRTtJQUNGLEVBQUUsRUFBRSx1QkFBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSx1QkFBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSx1QkFBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSx1QkFBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSx1QkFBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSx1QkFBdUIsQ0FBQyxNQUFNO0lBQ2xDOzs7TUFHRTtDQUNNLENBQUM7QUFRWDs7R0FFRztBQUNILE1BQU0sT0FBTyxvQkFBcUIsU0FBUSxLQUFLO0lBRzNCO0lBRmxCLFlBQ0UsT0FBZSxFQUNDLEtBQWU7UUFFL0IsS0FBSyxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBRkMsVUFBSyxHQUFMLEtBQUssQ0FBVTtRQUcvQixJQUFJLENBQUMsSUFBSSxHQUFHLHNCQUFzQixDQUFDO0lBQ3JDLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Account, Chain, Transport, WalletClient } from 'viem';
|
|
2
|
+
import { type HexString } from '../binary.js';
|
|
3
|
+
import { type SupportedChainId } from '../chain.js';
|
|
4
|
+
import { EncryptionScheme, type SupportedTeeType } from '../encryption/encryption.js';
|
|
5
|
+
import { type HandleWithProof } from '../generated/es/inco/kms/lite/v1/types_pb.js';
|
|
6
|
+
import { validateHandle } from '../handle.js';
|
|
7
|
+
import { KmsQuorumClient } from '../kms/quorumClient.js';
|
|
8
|
+
import type { XwingKeypair } from '../lite/xwing.js';
|
|
9
|
+
import type { BackoffConfig } from '../retry.js';
|
|
10
|
+
import { type DecryptionAttestation, type EncryptedDecryptionAttestation } from './types.js';
|
|
11
|
+
export { validateHandle };
|
|
12
|
+
export declare const ATTESTED_DECRYPT_DOMAIN_NAME = "IncoAttestedDecrypt";
|
|
13
|
+
/**
|
|
14
|
+
* Arguments for creating an attested decrypt request.
|
|
15
|
+
*/
|
|
16
|
+
export interface IncoLiteAttestedDecryptorArgs {
|
|
17
|
+
/** The wallet used to interact with the blockchain and sign the decrypt request */
|
|
18
|
+
walletClient: WalletClient<Transport, Chain, Account>;
|
|
19
|
+
/** The KMS quorum client instance */
|
|
20
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
21
|
+
/** The chain ID to use */
|
|
22
|
+
chainId: SupportedChainId;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Decrypt multiple handles in a single attested request.
|
|
26
|
+
* Returns an array of attestations aligned with the response ordering.
|
|
27
|
+
*
|
|
28
|
+
* @param args - The arguments for creating the attested decrypt function
|
|
29
|
+
* @returns A function that can decrypt handles and return an attestation
|
|
30
|
+
* @throws {AttestedDecryptError} If the creation fails
|
|
31
|
+
*/
|
|
32
|
+
export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, reencryptKeypair, kmsQuorumClient, executorAddress, }: {
|
|
33
|
+
handles: HexString[];
|
|
34
|
+
backoffConfig?: Partial<BackoffConfig> | undefined;
|
|
35
|
+
walletClient: WalletClient<Transport, Chain, Account>;
|
|
36
|
+
chainId: SupportedChainId;
|
|
37
|
+
reencryptPubKey: Uint8Array;
|
|
38
|
+
reencryptKeypair: XwingKeypair;
|
|
39
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
40
|
+
executorAddress: HexString;
|
|
41
|
+
}): Promise<Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
|
|
42
|
+
/**
|
|
43
|
+
* Decrypt multiple handles in a single attested request.
|
|
44
|
+
* Returns an array of attestations aligned with the response ordering.
|
|
45
|
+
*
|
|
46
|
+
* @param args - The arguments for creating the attested decrypt function
|
|
47
|
+
* @returns A function that can decrypt handles and return an attestation
|
|
48
|
+
* @throws {AttestedDecryptError} If the creation fails
|
|
49
|
+
*/
|
|
50
|
+
export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, kmsQuorumClient, executorAddress, }: {
|
|
51
|
+
handles: HexString[];
|
|
52
|
+
backoffConfig?: Partial<BackoffConfig> | undefined;
|
|
53
|
+
walletClient: WalletClient<Transport, Chain, Account>;
|
|
54
|
+
chainId: SupportedChainId;
|
|
55
|
+
reencryptPubKey: Uint8Array;
|
|
56
|
+
reencryptKeypair?: never;
|
|
57
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
58
|
+
executorAddress: HexString;
|
|
59
|
+
}): Promise<Array<EncryptedDecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
|
|
60
|
+
export declare function buildHandlesWithProofs(handles: HexString[]): Array<HandleWithProof>;
|
|
61
|
+
export declare function decryptEncryptedAttestations(attestations: Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType> | EncryptedDecryptionAttestation<EncryptionScheme, SupportedTeeType>>, reencryptKeypair: XwingKeypair): Promise<Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { create } from '@bufbuild/protobuf';
|
|
2
|
+
import { hexToBytes } from 'viem';
|
|
3
|
+
import { bytesToBigInt } from '../binary.js';
|
|
4
|
+
import { buildEip712Payload, signEip712 } from '../eip712/eip712.js';
|
|
5
|
+
import { bigintToPlaintext, encryptionSchemes, } from '../encryption/encryption.js';
|
|
6
|
+
import { AttestedDecryptRequestSchema, } from '../generated/es/inco/kms/lite/v1/kms_service_pb.js';
|
|
7
|
+
import { HandleWithProofSchema, } from '../generated/es/inco/kms/lite/v1/types_pb.js';
|
|
8
|
+
import { getHandleType, validateHandle } from '../handle.js';
|
|
9
|
+
import { decrypt, reencryptPublicKeysMatch } from '../lite/xwing.js';
|
|
10
|
+
import { AttestedDecryptError, } from './types.js';
|
|
11
|
+
export { validateHandle };
|
|
12
|
+
export const ATTESTED_DECRYPT_DOMAIN_NAME = 'IncoAttestedDecrypt';
|
|
13
|
+
/**
|
|
14
|
+
* Decrypt multiple handles in a single attested request.
|
|
15
|
+
* Returns an array of attestations aligned with the response ordering.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The arguments for creating the attested decrypt function
|
|
18
|
+
* @returns A function that can decrypt handles and return an attestation
|
|
19
|
+
* @throws {AttestedDecryptError} If the creation fails
|
|
20
|
+
*/
|
|
21
|
+
export async function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, reencryptKeypair, kmsQuorumClient, executorAddress, }) {
|
|
22
|
+
try {
|
|
23
|
+
handles.forEach(validateHandle);
|
|
24
|
+
if (!reencryptPubKey) {
|
|
25
|
+
throw new AttestedDecryptError('Reencrypt public key is required');
|
|
26
|
+
}
|
|
27
|
+
if (reencryptKeypair &&
|
|
28
|
+
!reencryptPublicKeysMatch(reencryptPubKey, reencryptKeypair)) {
|
|
29
|
+
throw new AttestedDecryptError('reencryptPubKey does not match reencryptKeypair public key');
|
|
30
|
+
}
|
|
31
|
+
const eip712Payload = await buildEip712Payload({
|
|
32
|
+
executorAddress,
|
|
33
|
+
ethClient: walletClient,
|
|
34
|
+
chainId,
|
|
35
|
+
handles,
|
|
36
|
+
reencryptPubKey,
|
|
37
|
+
});
|
|
38
|
+
const eip712SignatureHex = await signEip712(walletClient, eip712Payload);
|
|
39
|
+
const handlesWithProofs = buildHandlesWithProofs(handles);
|
|
40
|
+
const attestedDecryptRequest = buildAttestedDecryptRequest({
|
|
41
|
+
userAddress: walletClient.account.address,
|
|
42
|
+
handlesWithProofs,
|
|
43
|
+
eip712Signature: hexToBytes(eip712SignatureHex),
|
|
44
|
+
reencryptPubKey,
|
|
45
|
+
});
|
|
46
|
+
// Call quorum client which returns aggregated attestations directly
|
|
47
|
+
// The quorum client handles retry logic internally for each KMS client
|
|
48
|
+
// Envelope signatures are verified against the on-chain authorized signer set
|
|
49
|
+
const response = await kmsQuorumClient.attestedDecrypt(attestedDecryptRequest, executorAddress, walletClient, backoffConfig, reencryptKeypair);
|
|
50
|
+
// If reencryptPubKey is provided with a keypair, decrypt the encrypted attestations
|
|
51
|
+
// and verify the inner DecryptionAttestation signatures
|
|
52
|
+
if (reencryptPubKey !== undefined && reencryptKeypair) {
|
|
53
|
+
return decryptEncryptedAttestations(response, reencryptKeypair);
|
|
54
|
+
}
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof AttestedDecryptError) {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
throw new AttestedDecryptError('Failed to decrypt handles', error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function buildHandlesWithProofs(handles) {
|
|
65
|
+
return handles.map((handle) => {
|
|
66
|
+
return create(HandleWithProofSchema, {
|
|
67
|
+
handle: handle,
|
|
68
|
+
aclProof: {
|
|
69
|
+
proof: {
|
|
70
|
+
case: 'incoLiteBasicAclProof',
|
|
71
|
+
value: {},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function buildAttestedDecryptRequest(params) {
|
|
78
|
+
return create(AttestedDecryptRequestSchema, {
|
|
79
|
+
userAddress: params.userAddress,
|
|
80
|
+
handlesWithProofs: params.handlesWithProofs,
|
|
81
|
+
eip712Signature: params.eip712Signature,
|
|
82
|
+
reencryptPubKey: params.reencryptPubKey ?? new Uint8Array(),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export async function decryptEncryptedAttestations(attestations, reencryptKeypair) {
|
|
86
|
+
return Promise.all(attestations.map(async (att) => {
|
|
87
|
+
// If already a plaintext attestation, return as-is
|
|
88
|
+
if ('plaintext' in att && att.plaintext !== undefined) {
|
|
89
|
+
return att;
|
|
90
|
+
}
|
|
91
|
+
// Otherwise, decrypt the encrypted attestation
|
|
92
|
+
if ('encryptedPlaintext' in att && att.encryptedPlaintext !== undefined) {
|
|
93
|
+
const encryptedAtt = att;
|
|
94
|
+
const ct = hexToBytes(encryptedAtt.encryptedPlaintext.ciphertext.value);
|
|
95
|
+
const plaintextBytes = await decrypt(reencryptKeypair, ct);
|
|
96
|
+
const bigIntValue = bytesToBigInt(plaintextBytes);
|
|
97
|
+
const handleType = getHandleType(encryptedAtt.handle);
|
|
98
|
+
// Decrypt the encrypted signatures (which are signatures for the original plaintext)
|
|
99
|
+
// The covalidatorSignatures are for the reencryption struct, not the plaintext
|
|
100
|
+
const decryptedSignatures = await Promise.all(encryptedAtt.encryptedSignatures.map(async (encryptedSig) => {
|
|
101
|
+
return await decrypt(reencryptKeypair, encryptedSig);
|
|
102
|
+
}));
|
|
103
|
+
return {
|
|
104
|
+
handle: encryptedAtt.handle,
|
|
105
|
+
plaintext: bigintToPlaintext(encryptionSchemes.xwing, handleType, bigIntValue),
|
|
106
|
+
covalidatorSignatures: decryptedSignatures,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
throw new AttestedDecryptError('Attestation is neither plaintext nor encrypted');
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0ZWQtZGVjcnlwdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hdHRlc3RlZGRlY3J5cHQvYXR0ZXN0ZWQtZGVjcnlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFFNUMsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUNsQyxPQUFPLEVBQUUsYUFBYSxFQUFrQixNQUFNLGNBQWMsQ0FBQztBQUU3RCxPQUFPLEVBQUUsa0JBQWtCLEVBQUUsVUFBVSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDckUsT0FBTyxFQUNMLGlCQUFpQixFQUVqQixpQkFBaUIsR0FFbEIsTUFBTSw2QkFBNkIsQ0FBQztBQUNyQ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DSixDQUFDLENBQUMsQ0FDSCxDQUFDO0FBQ0osQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HexString } from '../binary.js';
|
|
2
|
+
import type { EncryptionScheme, EncryptResultOf, PlaintextOf, SupportedTeeType } from '../encryption/encryption.js';
|
|
3
|
+
import type { BackoffConfig } from '../retry.js';
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class for attested decrypt operations.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AttestedDecryptError extends Error {
|
|
8
|
+
readonly cause?: unknown | undefined;
|
|
9
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
10
|
+
}
|
|
11
|
+
export type DecryptionAttestation<S extends EncryptionScheme, T extends SupportedTeeType> = {
|
|
12
|
+
handle: HexString;
|
|
13
|
+
plaintext: PlaintextOf<S, T>;
|
|
14
|
+
covalidatorSignatures: Uint8Array[];
|
|
15
|
+
};
|
|
16
|
+
export type EncryptedDecryptionAttestation<S extends EncryptionScheme, T extends SupportedTeeType> = {
|
|
17
|
+
handle: HexString;
|
|
18
|
+
encryptedPlaintext: EncryptResultOf<S, T>;
|
|
19
|
+
encryptedSignatures: Uint8Array[];
|
|
20
|
+
covalidatorSignatures: Uint8Array[];
|
|
21
|
+
};
|
|
22
|
+
export type AttestedDecryptor<S extends EncryptionScheme> = <T extends SupportedTeeType>(args: AttestedDecryptFnArgs<S, T>) => Promise<DecryptionAttestation<S, T>>;
|
|
23
|
+
export type AttestedDecryptFnArgs<S extends EncryptionScheme, T extends SupportedTeeType> = {
|
|
24
|
+
/** The handle to decrypt */
|
|
25
|
+
handle: HexString;
|
|
26
|
+
backoffConfig?: Partial<BackoffConfig>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class for attested decrypt operations.
|
|
3
|
+
*/
|
|
4
|
+
export class AttestedDecryptError extends Error {
|
|
5
|
+
cause;
|
|
6
|
+
constructor(message, cause) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.cause = cause;
|
|
9
|
+
this.name = 'AttestedDecryptError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRkZWNyeXB0L3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNBOztHQUVHO0FBQ0gsTUFBTSxPQUFPLG9CQUFxQixTQUFRLEtBQUs7SUFHM0I7SUFGbEIsWUFDRSxPQUFlLEVBQ0MsS0FBZTtRQUUvQixLQUFLLENBQUMsT0FBTyxDQUFDLENBQUM7UUFGQyxVQUFLLEdBQUwsS0FBSyxDQUFVO1FBRy9CLElBQUksQ0FBQyxJQUFJLEdBQUcsc0JBQXNCLENBQUM7SUFDckMsQ0FBQztDQUNGIn0=
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Chain, PublicClient, Transport } from 'viem';
|
|
2
|
+
import type { DecryptionAttestation } from '../attesteddecrypt/types.js';
|
|
3
|
+
import type { HexString } from '../binary.js';
|
|
4
|
+
import type { EncryptionScheme, SupportedTeeType } from '../encryption/encryption.js';
|
|
5
|
+
import type { KmsQuorumClient } from '../kms/quorumClient.js';
|
|
6
|
+
import type { BackoffConfig } from '../retry.js';
|
|
7
|
+
/**
|
|
8
|
+
* Reveal multiple handles in a single attested request without wallet authentication.
|
|
9
|
+
* Returns an array of plaintext attestations aligned with the response ordering.
|
|
10
|
+
*
|
|
11
|
+
* @param args - The arguments for the attested reveal request
|
|
12
|
+
* @returns An array of decryption attestations
|
|
13
|
+
* @throws {AttestedRevealError} If the reveal fails
|
|
14
|
+
*/
|
|
15
|
+
export declare function attestedReveal({ handles, kmsQuorumClient, executorAddress, publicClient, backoffConfig, }: {
|
|
16
|
+
handles: HexString[];
|
|
17
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
18
|
+
executorAddress: HexString;
|
|
19
|
+
publicClient: PublicClient<Transport, Chain>;
|
|
20
|
+
backoffConfig?: Partial<BackoffConfig> | undefined;
|
|
21
|
+
}): Promise<Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { create } from '@bufbuild/protobuf';
|
|
2
|
+
import { AttestedRevealRequestSchema } from '../generated/es/inco/kms/lite/v1/kms_service_pb.js';
|
|
3
|
+
import { validateHandle } from '../handle.js';
|
|
4
|
+
import { AttestedRevealError } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Reveal multiple handles in a single attested request without wallet authentication.
|
|
7
|
+
* Returns an array of plaintext attestations aligned with the response ordering.
|
|
8
|
+
*
|
|
9
|
+
* @param args - The arguments for the attested reveal request
|
|
10
|
+
* @returns An array of decryption attestations
|
|
11
|
+
* @throws {AttestedRevealError} If the reveal fails
|
|
12
|
+
*/
|
|
13
|
+
export async function attestedReveal({ handles, kmsQuorumClient, executorAddress, publicClient, backoffConfig, }) {
|
|
14
|
+
try {
|
|
15
|
+
handles.forEach(validateHandle);
|
|
16
|
+
const attestedRevealRequest = create(AttestedRevealRequestSchema, {
|
|
17
|
+
handles,
|
|
18
|
+
});
|
|
19
|
+
return (await kmsQuorumClient.attestedReveal(attestedRevealRequest, executorAddress, publicClient, backoffConfig));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error instanceof AttestedRevealError) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
throw new AttestedRevealError('Failed to reveal handles', error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0ZWQtcmV2ZWFsLmpzIiwic291cmNlUm9vdCI6IiIsInNvd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
export { attestedReveal } from './attested-reveal.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRyZXZlYWwvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3RELGNBQWMsWUFBWSxDQUFDIn0=
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class AttestedRevealError extends Error {
|
|
2
|
+
cause;
|
|
3
|
+
constructor(message, cause) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.cause = cause;
|
|
6
|
+
this.name = 'AttestedRevealError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRyZXZlYWwvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxPQUFPLG1CQUFvQixTQUFRLEtBQUs7SUFHMUI7SUFGbEIsWUFDRSxPQUFlLEVBQ0MsS0FBZTtRQUUvQixLQUFLLENBQUMsT0FBTyxDQUFDLENBQUM7UUFGQyxVQUFLLEdBQUwsS0FBSyxDQUFVO1FBRy9CLElBQUksQ0FBQyxJQUFJLEdBQUcscUJBQXFCLENBQUM7SUFDcEMsQ0FBQztDQUNGIn0=
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { Hex } from 'viem';
|
|
3
|
+
/** Schema for a `0x`-prefixed hex string. */
|
|
4
|
+
export declare const HexString: Schema.TemplateLiteral<`0x${string}`>;
|
|
5
|
+
/** A `0x`-prefixed hex-encoded string (e.g. `"0xdeadbeef"`). */
|
|
6
|
+
export type HexString = typeof HexString.Type;
|
|
7
|
+
/** A value that can represent raw bytes — either a hex string or a `Uint8Array`. */
|
|
8
|
+
export type BytesIsh = string | Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a `Uint8Array` to a `bigint`. Returns `0n` for empty arrays.
|
|
11
|
+
* @param byteArray - The byte array to convert.
|
|
12
|
+
* @returns The unsigned big-endian integer representation of the bytes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function bytesToBigInt(byteArray: Uint8Array): bigint;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a `Buffer` to a `bigint`.
|
|
17
|
+
* @param buffer - The buffer to convert.
|
|
18
|
+
* @returns The unsigned big-endian integer representation of the buffer.
|
|
19
|
+
*/
|
|
20
|
+
export declare function bufferToBigInt(buffer: Buffer): bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a `bigint` to a 32-byte `Buffer`, zero-padded on the left.
|
|
23
|
+
* @param value - The bigint to convert.
|
|
24
|
+
* @returns A 32-byte big-endian buffer.
|
|
25
|
+
* @throws If the bigint is negative or too large to fit in 32 bytes.
|
|
26
|
+
*/
|
|
27
|
+
export declare function bigintToBytes(value: bigint): Buffer;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a `bigint` to a {@link Bytes32} hex string, left-padded to 32 bytes.
|
|
30
|
+
* @param value - The bigint to convert.
|
|
31
|
+
* @returns A `Bytes32` hex string.
|
|
32
|
+
* @throws If the bigint is negative or too large to fit in 32 bytes.
|
|
33
|
+
*/
|
|
34
|
+
export declare function bigintToBytes32(value: bigint): Bytes32;
|
|
35
|
+
/**
|
|
36
|
+
* Left-pads a byte array with zeros to the specified length.
|
|
37
|
+
* @param bs - The byte array to pad.
|
|
38
|
+
* @param n - The desired total length in bytes.
|
|
39
|
+
* @returns A new `Buffer` of length `n` with `bs` right-aligned.
|
|
40
|
+
* @throws If `bs` is longer than `n` (would require truncation).
|
|
41
|
+
*/
|
|
42
|
+
export declare function padLeft(bs: Uint8Array, n: number): Buffer;
|
|
43
|
+
/**
|
|
44
|
+
* Parses a {@link BytesIsh} value as a 32-byte value and converts it to a `bigint`.
|
|
45
|
+
* @param bs - A hex string or `Uint8Array` representing exactly 32 bytes.
|
|
46
|
+
* @returns The `bigint` representation of the 32-byte value.
|
|
47
|
+
* @throws If the input is not exactly 32 bytes.
|
|
48
|
+
*/
|
|
49
|
+
export declare function bytes32ToBigint(bs: BytesIsh): bigint;
|
|
50
|
+
/**
|
|
51
|
+
* Decodes a hex string into a `Buffer`. Handles both `0x`-prefixed and bare hex strings.
|
|
52
|
+
* @param hexString - The hex string to decode.
|
|
53
|
+
* @returns A `Buffer` containing the decoded bytes.
|
|
54
|
+
*/
|
|
55
|
+
export declare function bytesFromHexString(hexString: string): Buffer;
|
|
56
|
+
/**
|
|
57
|
+
* Asserts that a string is a valid `0x`-prefixed hex string and narrows its type to `Hex`.
|
|
58
|
+
* @param value - The string to validate.
|
|
59
|
+
* @returns The input typed as `Hex`.
|
|
60
|
+
* @throws If `value` is not a valid hex string.
|
|
61
|
+
*/
|
|
62
|
+
export declare function mustBeHex(value: string): Hex;
|
|
63
|
+
/**
|
|
64
|
+
* Normalises a string to a `0x`-prefixed `Hex` value, adding the prefix if missing.
|
|
65
|
+
* @param value - A hex string, with or without a `0x` prefix.
|
|
66
|
+
* @returns The `0x`-prefixed `Hex` string.
|
|
67
|
+
* @throws If the resulting string is not valid hex.
|
|
68
|
+
*/
|
|
69
|
+
export declare function normaliseToHex(value: string): Hex;
|
|
70
|
+
/**
|
|
71
|
+
* Encodes a `Uint8Array` as a `0x`-prefixed hex string.
|
|
72
|
+
* @param bs - The byte array to encode.
|
|
73
|
+
* @returns A `Hex` string representation of the bytes.
|
|
74
|
+
*/
|
|
75
|
+
export declare function bytesToHex(bs: Uint8Array): Hex;
|
|
76
|
+
/** Schema for a 32-byte (66-character with `0x` prefix) hex string, branded as `Bytes32`. Accepts both hex strings and `Uint8Array` inputs. */
|
|
77
|
+
export declare const Bytes32: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
|
|
78
|
+
/**
|
|
79
|
+
* Parses and validates a {@link BytesIsh} value as a {@link Bytes32}.
|
|
80
|
+
* @param x - A hex string or `Uint8Array` to parse.
|
|
81
|
+
* @returns A validated `Bytes32` value.
|
|
82
|
+
* @throws If the input is not exactly 32 bytes.
|
|
83
|
+
*/
|
|
84
|
+
export declare function asBytes32(x: BytesIsh): Bytes32;
|
|
85
|
+
/** A branded 32-byte hex string type (`0x` + 64 hex characters). */
|
|
86
|
+
export type Bytes32 = typeof Bytes32.Type;
|
|
87
|
+
/** A branded 20-byte Ethereum address type (`0x` + 40 hex characters). */
|
|
88
|
+
export type Address = typeof Address.Type;
|
|
89
|
+
/** Schema for a 20-byte `0x`-prefixed Ethereum address, branded as `Address`. */
|
|
90
|
+
export declare const Address: Schema.brand<Schema.filter<Schema.TemplateLiteral<`0x${string}`>>, "Address">;
|
|
91
|
+
/**
|
|
92
|
+
* Parses and validates a string as an Ethereum {@link Address} (20-byte, `0x`-prefixed).
|
|
93
|
+
* @param address - The string to parse.
|
|
94
|
+
* @returns A validated `Address` value.
|
|
95
|
+
* @throws If the input is not a valid 20-byte hex address.
|
|
96
|
+
*/
|
|
97
|
+
export declare function parseAddress(address: string): Address;
|
|
98
|
+
/**
|
|
99
|
+
* Parses and validates a string as a {@link HexString} (`0x`-prefixed).
|
|
100
|
+
* @param hex - The string to parse.
|
|
101
|
+
* @returns A validated `HexString` value.
|
|
102
|
+
* @throws If the input is not a valid `0x`-prefixed hex string.
|
|
103
|
+
*/
|
|
104
|
+
export declare function parseHex(hex: string): HexString;
|