@cofhe/sdk 0.1.0 → 0.2.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 +62 -0
- package/adapters/ethers5.test.ts +174 -0
- package/adapters/ethers5.ts +36 -0
- package/adapters/ethers6.test.ts +169 -0
- package/adapters/ethers6.ts +36 -0
- package/adapters/hardhat-node.ts +167 -0
- package/adapters/hardhat.hh2.test.ts +159 -0
- package/adapters/hardhat.ts +36 -0
- package/adapters/index.test.ts +20 -0
- package/adapters/index.ts +5 -0
- package/adapters/smartWallet.ts +99 -0
- package/adapters/test-utils.ts +53 -0
- package/adapters/types.ts +6 -0
- package/adapters/wagmi.test.ts +156 -0
- package/adapters/wagmi.ts +17 -0
- package/chains/chains/arbSepolia.ts +14 -0
- package/chains/chains/baseSepolia.ts +14 -0
- package/chains/chains/hardhat.ts +15 -0
- package/chains/chains/localcofhe.ts +14 -0
- package/chains/chains/sepolia.ts +14 -0
- package/chains/chains.test.ts +50 -0
- package/chains/defineChain.ts +18 -0
- package/chains/index.ts +35 -0
- package/chains/types.ts +32 -0
- package/core/baseBuilder.ts +119 -0
- package/core/client.test.ts +315 -0
- package/core/client.ts +292 -0
- package/core/clientTypes.ts +108 -0
- package/core/config.test.ts +235 -0
- package/core/config.ts +220 -0
- package/core/decrypt/MockQueryDecrypterAbi.ts +129 -0
- package/core/decrypt/cofheMocksSealOutput.ts +57 -0
- package/core/decrypt/decryptHandleBuilder.ts +287 -0
- package/core/decrypt/decryptUtils.ts +28 -0
- package/core/decrypt/tnSealOutputV1.ts +59 -0
- package/core/decrypt/tnSealOutputV2.ts +298 -0
- package/core/encrypt/MockZkVerifierAbi.ts +106 -0
- package/core/encrypt/cofheMocksZkVerifySign.ts +284 -0
- package/core/encrypt/encryptInputsBuilder.test.ts +751 -0
- package/core/encrypt/encryptInputsBuilder.ts +560 -0
- package/core/encrypt/encryptUtils.ts +67 -0
- package/core/encrypt/zkPackProveVerify.ts +335 -0
- package/core/error.ts +168 -0
- package/core/fetchKeys.test.ts +195 -0
- package/core/fetchKeys.ts +144 -0
- package/core/index.ts +89 -0
- package/core/keyStore.test.ts +226 -0
- package/core/keyStore.ts +154 -0
- package/core/permits.test.ts +494 -0
- package/core/permits.ts +200 -0
- package/core/types.ts +398 -0
- package/core/utils.ts +130 -0
- package/dist/adapters.cjs +88 -0
- package/dist/adapters.d.cts +14576 -0
- package/dist/adapters.d.ts +14576 -0
- package/dist/adapters.js +83 -0
- package/dist/chains.cjs +114 -0
- package/dist/chains.d.cts +121 -0
- package/dist/chains.d.ts +121 -0
- package/dist/chains.js +1 -0
- package/dist/chunk-UGBVZNRT.js +818 -0
- package/dist/chunk-WEAZ25JO.js +105 -0
- package/dist/chunk-WGCRJCBR.js +2523 -0
- package/dist/clientTypes-5_1nwtUe.d.cts +914 -0
- package/dist/clientTypes-Es7fyi65.d.ts +914 -0
- package/dist/core.cjs +3414 -0
- package/dist/core.d.cts +111 -0
- package/dist/core.d.ts +111 -0
- package/dist/core.js +3 -0
- package/dist/node.cjs +3286 -0
- package/dist/node.d.cts +22 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.js +91 -0
- package/dist/permit-fUSe6KKq.d.cts +349 -0
- package/dist/permit-fUSe6KKq.d.ts +349 -0
- package/dist/permits.cjs +871 -0
- package/dist/permits.d.cts +1045 -0
- package/dist/permits.d.ts +1045 -0
- package/dist/permits.js +1 -0
- package/dist/types-KImPrEIe.d.cts +48 -0
- package/dist/types-KImPrEIe.d.ts +48 -0
- package/dist/web.cjs +3478 -0
- package/dist/web.d.cts +38 -0
- package/dist/web.d.ts +38 -0
- package/dist/web.js +240 -0
- package/dist/zkProve.worker.cjs +93 -0
- package/dist/zkProve.worker.d.cts +2 -0
- package/dist/zkProve.worker.d.ts +2 -0
- package/dist/zkProve.worker.js +91 -0
- package/node/client.test.ts +147 -0
- package/node/config.test.ts +68 -0
- package/node/encryptInputs.test.ts +155 -0
- package/node/index.ts +97 -0
- package/node/storage.ts +51 -0
- package/package.json +27 -15
- package/permits/index.ts +68 -0
- package/permits/localstorage.test.ts +117 -0
- package/permits/permit.test.ts +477 -0
- package/permits/permit.ts +405 -0
- package/permits/sealing.test.ts +84 -0
- package/permits/sealing.ts +131 -0
- package/permits/signature.ts +79 -0
- package/permits/store.test.ts +128 -0
- package/permits/store.ts +166 -0
- package/permits/test-utils.ts +20 -0
- package/permits/types.ts +191 -0
- package/permits/utils.ts +62 -0
- package/permits/validation.test.ts +288 -0
- package/permits/validation.ts +369 -0
- package/web/client.web.test.ts +147 -0
- package/web/config.web.test.ts +69 -0
- package/web/encryptInputs.web.test.ts +172 -0
- package/web/index.ts +161 -0
- package/web/storage.ts +34 -0
- package/web/worker.builder.web.test.ts +148 -0
- package/web/worker.config.web.test.ts +329 -0
- package/web/worker.output.web.test.ts +84 -0
- package/web/workerManager.test.ts +80 -0
- package/web/workerManager.ts +214 -0
- package/web/workerManager.web.test.ts +114 -0
- package/web/zkProve.worker.ts +133 -0
package/dist/node.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-5_1nwtUe.cjs';
|
|
2
|
+
import 'viem';
|
|
3
|
+
import './types-KImPrEIe.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import './permit-fUSe6KKq.cjs';
|
|
6
|
+
import 'zustand/vanilla';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a CoFHE SDK configuration for Node.js with filesystem storage as default
|
|
10
|
+
* @param config - The CoFHE SDK input configuration (fheKeyStorage will default to filesystem if not provided)
|
|
11
|
+
* @returns The CoFHE SDK configuration with Node.js defaults applied
|
|
12
|
+
*/
|
|
13
|
+
declare function createCofhesdkConfig(config: CofhesdkInputConfig): CofhesdkConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a CoFHE SDK client instance for Node.js with node-tfhe automatically configured
|
|
16
|
+
* TFHE will be initialized automatically on first encryption - no manual setup required
|
|
17
|
+
* @param config - The CoFHE SDK configuration (use createCofhesdkConfig to create with Node.js defaults)
|
|
18
|
+
* @returns The CoFHE SDK client instance
|
|
19
|
+
*/
|
|
20
|
+
declare function createCofhesdkClient(config: CofhesdkConfig): CofhesdkClient;
|
|
21
|
+
|
|
22
|
+
export { createCofhesdkClient, createCofhesdkConfig };
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-Es7fyi65.js';
|
|
2
|
+
import 'viem';
|
|
3
|
+
import './types-KImPrEIe.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import './permit-fUSe6KKq.js';
|
|
6
|
+
import 'zustand/vanilla';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a CoFHE SDK configuration for Node.js with filesystem storage as default
|
|
10
|
+
* @param config - The CoFHE SDK input configuration (fheKeyStorage will default to filesystem if not provided)
|
|
11
|
+
* @returns The CoFHE SDK configuration with Node.js defaults applied
|
|
12
|
+
*/
|
|
13
|
+
declare function createCofhesdkConfig(config: CofhesdkInputConfig): CofhesdkConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a CoFHE SDK client instance for Node.js with node-tfhe automatically configured
|
|
16
|
+
* TFHE will be initialized automatically on first encryption - no manual setup required
|
|
17
|
+
* @param config - The CoFHE SDK configuration (use createCofhesdkConfig to create with Node.js defaults)
|
|
18
|
+
* @returns The CoFHE SDK client instance
|
|
19
|
+
*/
|
|
20
|
+
declare function createCofhesdkClient(config: CofhesdkConfig): CofhesdkClient;
|
|
21
|
+
|
|
22
|
+
export { createCofhesdkClient, createCofhesdkConfig };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createCofhesdkConfigBase, createCofhesdkClientBase } from './chunk-WGCRJCBR.js';
|
|
2
|
+
import './chunk-WEAZ25JO.js';
|
|
3
|
+
import './chunk-UGBVZNRT.js';
|
|
4
|
+
import { promises } from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { init_panic_hook, TfheCompactPublicKey, CompactPkeCrs, ProvenCompactCiphertextList } from 'node-tfhe';
|
|
7
|
+
|
|
8
|
+
var memoryStorage = {};
|
|
9
|
+
var createNodeStorage = () => {
|
|
10
|
+
return {
|
|
11
|
+
getItem: async (name) => {
|
|
12
|
+
try {
|
|
13
|
+
const storageDir = join(process.env.HOME || process.env.USERPROFILE || ".", ".cofhesdk");
|
|
14
|
+
await promises.mkdir(storageDir, { recursive: true });
|
|
15
|
+
const filePath = join(storageDir, `${name}.json`);
|
|
16
|
+
const data = await promises.readFile(filePath, "utf8").catch(() => null);
|
|
17
|
+
return data ? JSON.parse(data) : null;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.warn("Node.js filesystem modules not available, falling back to memory storage" + e);
|
|
20
|
+
return memoryStorage[name] || null;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
setItem: async (name, value) => {
|
|
24
|
+
try {
|
|
25
|
+
const storageDir = join(process.env.HOME || process.env.USERPROFILE || ".", ".cofhesdk");
|
|
26
|
+
await promises.mkdir(storageDir, { recursive: true });
|
|
27
|
+
const filePath = join(storageDir, `${name}.json`);
|
|
28
|
+
await promises.writeFile(filePath, JSON.stringify(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.warn("Node.js filesystem modules not available, falling back to memory storage" + e);
|
|
31
|
+
memoryStorage[name] = JSON.stringify(value);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
removeItem: async (name) => {
|
|
35
|
+
try {
|
|
36
|
+
const storageDir = join(process.env.HOME || process.env.USERPROFILE || ".", ".cofhesdk");
|
|
37
|
+
const filePath = join(storageDir, `${name}.json`);
|
|
38
|
+
await promises.unlink(filePath).catch(() => {
|
|
39
|
+
});
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.warn("Node.js filesystem modules not available, falling back to memory storage" + e);
|
|
42
|
+
delete memoryStorage[name];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var tfheInitialized = false;
|
|
48
|
+
async function initTfhe() {
|
|
49
|
+
if (tfheInitialized)
|
|
50
|
+
return false;
|
|
51
|
+
await init_panic_hook();
|
|
52
|
+
tfheInitialized = true;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
var fromHexString = (hexString) => {
|
|
56
|
+
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
57
|
+
const arr = cleanString.replace(/^0x/, "").match(/.{1,2}/g);
|
|
58
|
+
if (!arr)
|
|
59
|
+
return new Uint8Array();
|
|
60
|
+
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
61
|
+
};
|
|
62
|
+
var tfhePublicKeyDeserializer = (buff) => {
|
|
63
|
+
TfheCompactPublicKey.deserialize(fromHexString(buff));
|
|
64
|
+
};
|
|
65
|
+
var compactPkeCrsDeserializer = (buff) => {
|
|
66
|
+
CompactPkeCrs.deserialize(fromHexString(buff));
|
|
67
|
+
};
|
|
68
|
+
var zkBuilderAndCrsGenerator = (fhe, crs) => {
|
|
69
|
+
const fhePublicKey = TfheCompactPublicKey.deserialize(fromHexString(fhe));
|
|
70
|
+
const zkBuilder = ProvenCompactCiphertextList.builder(fhePublicKey);
|
|
71
|
+
const zkCrs = CompactPkeCrs.deserialize(fromHexString(crs));
|
|
72
|
+
return { zkBuilder, zkCrs };
|
|
73
|
+
};
|
|
74
|
+
function createCofhesdkConfig(config) {
|
|
75
|
+
return createCofhesdkConfigBase({
|
|
76
|
+
environment: "node",
|
|
77
|
+
...config,
|
|
78
|
+
fheKeyStorage: config.fheKeyStorage === null ? null : config.fheKeyStorage ?? createNodeStorage()
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function createCofhesdkClient(config) {
|
|
82
|
+
return createCofhesdkClientBase({
|
|
83
|
+
config,
|
|
84
|
+
zkBuilderAndCrsGenerator,
|
|
85
|
+
tfhePublicKeyDeserializer,
|
|
86
|
+
compactPkeCrsDeserializer,
|
|
87
|
+
initTfhe
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { createCofhesdkClient, createCofhesdkConfig };
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import { PublicClient, WalletClient } from 'viem';
|
|
3
|
+
|
|
4
|
+
type EthEncryptedData = {
|
|
5
|
+
data: Uint8Array;
|
|
6
|
+
public_key: Uint8Array;
|
|
7
|
+
nonce: Uint8Array;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A class representing a SealingKey which provides cryptographic sealing (encryption)
|
|
11
|
+
* and unsealing (decryption) capabilities.
|
|
12
|
+
*/
|
|
13
|
+
declare class SealingKey$1 {
|
|
14
|
+
/**
|
|
15
|
+
* The private key used for decryption.
|
|
16
|
+
*/
|
|
17
|
+
privateKey: string;
|
|
18
|
+
/**
|
|
19
|
+
* The public key used for encryption.
|
|
20
|
+
*/
|
|
21
|
+
publicKey: string;
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a SealingKey instance with the given private and public keys.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} privateKey - The private key used for decryption.
|
|
26
|
+
* @param {string} publicKey - The public key used for encryption.
|
|
27
|
+
* @throws Will throw an error if the provided keys lengths do not match
|
|
28
|
+
* the required lengths for private and public keys.
|
|
29
|
+
*/
|
|
30
|
+
constructor(privateKey: string, publicKey: string);
|
|
31
|
+
unseal: (parsedData: EthEncryptedData) => bigint;
|
|
32
|
+
/**
|
|
33
|
+
* Serializes the SealingKey to a JSON object.
|
|
34
|
+
*/
|
|
35
|
+
serialize: () => {
|
|
36
|
+
privateKey: string;
|
|
37
|
+
publicKey: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Deserializes the SealingKey from a JSON object.
|
|
41
|
+
*/
|
|
42
|
+
static deserialize: (privateKey: string, publicKey: string) => SealingKey$1;
|
|
43
|
+
/**
|
|
44
|
+
* Seals (encrypts) the provided message for a receiver with the specified public key.
|
|
45
|
+
*
|
|
46
|
+
* @param {bigint | number} value - The message to be encrypted.
|
|
47
|
+
* @param {string} publicKey - The public key of the intended recipient.
|
|
48
|
+
* @returns string - The encrypted message in hexadecimal format.
|
|
49
|
+
* @static
|
|
50
|
+
* @throws Will throw if the provided publicKey or value do not meet defined preconditions.
|
|
51
|
+
*/
|
|
52
|
+
static seal: (value: bigint | number, publicKey: string) => EthEncryptedData;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Asynchronously generates a new SealingKey.
|
|
56
|
+
* This function uses the 'nacl' library to create a new public/private key pair for sealing purposes.
|
|
57
|
+
* A sealing key is used to encrypt data such that it can only be unsealed (decrypted) by the owner of the corresponding private key.
|
|
58
|
+
* @returns {SealingKey} - A new SealingKey object containing the hexadecimal strings of the public and private keys.
|
|
59
|
+
*/
|
|
60
|
+
declare const GenerateSealingKey: () => SealingKey$1;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* EIP712 related types
|
|
64
|
+
*/
|
|
65
|
+
type EIP712Type = {
|
|
66
|
+
name: string;
|
|
67
|
+
type: string;
|
|
68
|
+
};
|
|
69
|
+
type EIP712Types = Record<string, EIP712Type[]>;
|
|
70
|
+
type EIP712Message = Record<string, string>;
|
|
71
|
+
type EIP712Domain = {
|
|
72
|
+
chainId: number;
|
|
73
|
+
name: string;
|
|
74
|
+
verifyingContract: `0x${string}`;
|
|
75
|
+
version: string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Sealing key type - using the actual SealingKey class
|
|
79
|
+
*/
|
|
80
|
+
type SealingKey = SealingKey$1;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Core Permit interface - immutable design for React compatibility
|
|
84
|
+
*/
|
|
85
|
+
interface Permit {
|
|
86
|
+
/**
|
|
87
|
+
* Name for this permit, for organization and UI usage, not included in signature.
|
|
88
|
+
*/
|
|
89
|
+
name: string;
|
|
90
|
+
/**
|
|
91
|
+
* The type of the Permit (self / sharing)
|
|
92
|
+
* (self) Permit that will be signed and used by the issuer
|
|
93
|
+
* (sharing) Permit that is signed by the issuer, but intended to be shared with recipient
|
|
94
|
+
* (recipient) Permit that has been received, and signed by the recipient
|
|
95
|
+
*/
|
|
96
|
+
type: 'self' | 'sharing' | 'recipient';
|
|
97
|
+
/**
|
|
98
|
+
* (base) User that initially created the permission, target of data fetching
|
|
99
|
+
*/
|
|
100
|
+
issuer: `0x${string}`;
|
|
101
|
+
/**
|
|
102
|
+
* (base) Expiration timestamp
|
|
103
|
+
*/
|
|
104
|
+
expiration: number;
|
|
105
|
+
/**
|
|
106
|
+
* (sharing) The user that this permission will be shared with
|
|
107
|
+
* ** optional, use `address(0)` to disable **
|
|
108
|
+
*/
|
|
109
|
+
recipient: `0x${string}`;
|
|
110
|
+
/**
|
|
111
|
+
* (issuer defined validation) An id used to query a contract to check this permissions validity
|
|
112
|
+
* ** optional, use `0` to disable **
|
|
113
|
+
*/
|
|
114
|
+
validatorId: number;
|
|
115
|
+
/**
|
|
116
|
+
* (issuer defined validation) The contract to query to determine permission validity
|
|
117
|
+
* ** optional, user `address(0)` to disable **
|
|
118
|
+
*/
|
|
119
|
+
validatorContract: `0x${string}`;
|
|
120
|
+
/**
|
|
121
|
+
* (base) The publicKey of a sealingPair used to re-encrypt `issuer`s confidential data
|
|
122
|
+
* (non-sharing) Populated by `issuer`
|
|
123
|
+
* (sharing) Populated by `recipient`
|
|
124
|
+
*/
|
|
125
|
+
sealingPair: SealingKey;
|
|
126
|
+
/**
|
|
127
|
+
* (base) `signTypedData` signature created by `issuer`.
|
|
128
|
+
* (base) Shared- and Self- permissions differ in signature format: (`sealingKey` absent in shared signature)
|
|
129
|
+
* (non-sharing) < issuer, expiration, recipient, validatorId, validatorContract, sealingKey >
|
|
130
|
+
* (sharing) < issuer, expiration, recipient, validatorId, validatorContract >
|
|
131
|
+
*/
|
|
132
|
+
issuerSignature: `0x${string}`;
|
|
133
|
+
/**
|
|
134
|
+
* (sharing) `signTypedData` signature created by `recipient` with format:
|
|
135
|
+
* (sharing) < sealingKey, issuerSignature>
|
|
136
|
+
* ** required for shared permits **
|
|
137
|
+
*/
|
|
138
|
+
recipientSignature: `0x${string}`;
|
|
139
|
+
/**
|
|
140
|
+
* EIP712 domain used to sign this permit.
|
|
141
|
+
* Should not be set manually, included in metadata as part of serialization flows.
|
|
142
|
+
*/
|
|
143
|
+
_signedDomain?: EIP712Domain;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Permit discriminant helpers
|
|
147
|
+
*/
|
|
148
|
+
type PermitType = Permit['type'];
|
|
149
|
+
/**
|
|
150
|
+
* Utility type to narrow a permit to a specific discriminant.
|
|
151
|
+
*
|
|
152
|
+
* Note: this only narrows the `type` field. Runtime/validation constraints
|
|
153
|
+
* (e.g. recipient == zeroAddress for self permits) are enforced elsewhere.
|
|
154
|
+
*/
|
|
155
|
+
type PermitOf<T extends PermitType> = Expand<Omit<Permit, 'type'> & {
|
|
156
|
+
type: T;
|
|
157
|
+
}>;
|
|
158
|
+
type SelfPermit = PermitOf<'self'>;
|
|
159
|
+
type SharingPermit = PermitOf<'sharing'>;
|
|
160
|
+
type RecipientPermit = PermitOf<'recipient'>;
|
|
161
|
+
/**
|
|
162
|
+
* Optional additional metadata of a Permit
|
|
163
|
+
* Can be passed into the constructor, but not necessary
|
|
164
|
+
* Useful for deserialization
|
|
165
|
+
*/
|
|
166
|
+
interface PermitMetadata {
|
|
167
|
+
/**
|
|
168
|
+
* EIP712 domain used to sign this permit.
|
|
169
|
+
* Should not be set manually, included in metadata as part of serialization flows.
|
|
170
|
+
*/
|
|
171
|
+
_signedDomain?: EIP712Domain;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Utility types for permit creation
|
|
175
|
+
*/
|
|
176
|
+
type CreateSelfPermitOptions = {
|
|
177
|
+
type?: 'self';
|
|
178
|
+
issuer: string;
|
|
179
|
+
name?: string;
|
|
180
|
+
expiration?: number;
|
|
181
|
+
validatorId?: number;
|
|
182
|
+
validatorContract?: string;
|
|
183
|
+
};
|
|
184
|
+
type CreateSharingPermitOptions = {
|
|
185
|
+
type?: 'sharing';
|
|
186
|
+
issuer: string;
|
|
187
|
+
recipient: string;
|
|
188
|
+
name?: string;
|
|
189
|
+
expiration?: number;
|
|
190
|
+
validatorId?: number;
|
|
191
|
+
validatorContract?: string;
|
|
192
|
+
};
|
|
193
|
+
type ImportSharedPermitOptions = {
|
|
194
|
+
type?: 'sharing';
|
|
195
|
+
issuer: string;
|
|
196
|
+
recipient: string;
|
|
197
|
+
issuerSignature: string;
|
|
198
|
+
name?: string;
|
|
199
|
+
expiration?: number;
|
|
200
|
+
validatorId?: number;
|
|
201
|
+
validatorContract?: string;
|
|
202
|
+
};
|
|
203
|
+
type SerializedPermit = Omit<Permit, 'sealingPair'> & {
|
|
204
|
+
_signedDomain?: EIP712Domain;
|
|
205
|
+
sealingPair: {
|
|
206
|
+
privateKey: string;
|
|
207
|
+
publicKey: string;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* A type representing the Permission struct that is passed to Permissioned.sol to grant encrypted data access.
|
|
212
|
+
*/
|
|
213
|
+
type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair'> & {
|
|
214
|
+
sealingKey: `0x${string}`;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Validation result type
|
|
218
|
+
*/
|
|
219
|
+
interface ValidationResult {
|
|
220
|
+
valid: boolean;
|
|
221
|
+
error: string | null;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Signature types for EIP712 signing
|
|
225
|
+
*/
|
|
226
|
+
type PermitSignaturePrimaryType = 'PermissionedV2IssuerSelf' | 'PermissionedV2IssuerShared' | 'PermissionedV2Recipient';
|
|
227
|
+
type Expand<T> = T extends infer O ? {
|
|
228
|
+
[K in keyof O]: O[K];
|
|
229
|
+
} : never;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Main Permit utilities - functional approach for React compatibility
|
|
233
|
+
*/
|
|
234
|
+
declare const PermitUtils: {
|
|
235
|
+
/**
|
|
236
|
+
* Create a self permit for personal use
|
|
237
|
+
*/
|
|
238
|
+
createSelf: (options: CreateSelfPermitOptions) => SelfPermit;
|
|
239
|
+
/**
|
|
240
|
+
* Create a sharing permit to be shared with another user
|
|
241
|
+
*/
|
|
242
|
+
createSharing: (options: CreateSharingPermitOptions) => SharingPermit;
|
|
243
|
+
/**
|
|
244
|
+
* Import a shared permit from various input formats
|
|
245
|
+
*/
|
|
246
|
+
importShared: (options: ImportSharedPermitOptions | string) => RecipientPermit;
|
|
247
|
+
/**
|
|
248
|
+
* Sign a permit with the provided wallet client
|
|
249
|
+
*/
|
|
250
|
+
sign: <T extends Permit>(permit: T, publicClient: PublicClient, walletClient: WalletClient) => Promise<T>;
|
|
251
|
+
/**
|
|
252
|
+
* Create and sign a self permit in one operation
|
|
253
|
+
*/
|
|
254
|
+
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
|
|
255
|
+
/**
|
|
256
|
+
* Create and sign a sharing permit in one operation
|
|
257
|
+
*/
|
|
258
|
+
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
|
|
259
|
+
/**
|
|
260
|
+
* Import and sign a shared permit in one operation from various input formats
|
|
261
|
+
*/
|
|
262
|
+
importSharedAndSign: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
|
|
263
|
+
/**
|
|
264
|
+
* Deserialize a permit from serialized data
|
|
265
|
+
*/
|
|
266
|
+
deserialize: (data: SerializedPermit) => Permit;
|
|
267
|
+
/**
|
|
268
|
+
* Serialize a permit for storage
|
|
269
|
+
*/
|
|
270
|
+
serialize: (permit: Permit) => SerializedPermit;
|
|
271
|
+
/**
|
|
272
|
+
* Validate a permit
|
|
273
|
+
*/
|
|
274
|
+
validate: (permit: Permit) => zod.SafeParseReturnType<{
|
|
275
|
+
type: "self" | "sharing" | "recipient";
|
|
276
|
+
issuer: string;
|
|
277
|
+
recipient?: string | undefined;
|
|
278
|
+
name?: string | undefined;
|
|
279
|
+
expiration?: number | undefined;
|
|
280
|
+
validatorId?: number | undefined;
|
|
281
|
+
validatorContract?: string | undefined;
|
|
282
|
+
sealingPair?: {
|
|
283
|
+
privateKey: string;
|
|
284
|
+
publicKey: string;
|
|
285
|
+
} | undefined;
|
|
286
|
+
issuerSignature?: string | undefined;
|
|
287
|
+
recipientSignature?: string | undefined;
|
|
288
|
+
}, {
|
|
289
|
+
recipient: `0x${string}`;
|
|
290
|
+
type: "self" | "sharing" | "recipient";
|
|
291
|
+
name: string;
|
|
292
|
+
issuer: `0x${string}`;
|
|
293
|
+
expiration: number;
|
|
294
|
+
validatorId: number;
|
|
295
|
+
validatorContract: `0x${string}`;
|
|
296
|
+
issuerSignature: string;
|
|
297
|
+
recipientSignature: string;
|
|
298
|
+
sealingPair?: {
|
|
299
|
+
privateKey: string;
|
|
300
|
+
publicKey: string;
|
|
301
|
+
} | undefined;
|
|
302
|
+
}>;
|
|
303
|
+
/**
|
|
304
|
+
* Get the permission object from a permit (for use in contracts)
|
|
305
|
+
*/
|
|
306
|
+
getPermission: (permit: Permit, skipValidation?: boolean) => Permission;
|
|
307
|
+
/**
|
|
308
|
+
* Get a stable hash for the permit (used as key in storage)
|
|
309
|
+
*/
|
|
310
|
+
getHash: (permit: Permit) => string;
|
|
311
|
+
/**
|
|
312
|
+
* Export permit data for sharing (removes sensitive fields)
|
|
313
|
+
*/
|
|
314
|
+
export: (permit: Permit) => string;
|
|
315
|
+
/**
|
|
316
|
+
* Unseal encrypted data using the permit's sealing key
|
|
317
|
+
*/
|
|
318
|
+
unseal: (permit: Permit, ciphertext: EthEncryptedData) => bigint;
|
|
319
|
+
/**
|
|
320
|
+
* Check if permit is expired
|
|
321
|
+
*/
|
|
322
|
+
isExpired: (permit: Permit) => boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Check if permit is signed
|
|
325
|
+
*/
|
|
326
|
+
isSigned: (permit: Permit) => boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Check if permit is valid
|
|
329
|
+
*/
|
|
330
|
+
isValid: (permit: Permit) => ValidationResult;
|
|
331
|
+
/**
|
|
332
|
+
* Update permit name (returns new permit instance)
|
|
333
|
+
*/
|
|
334
|
+
updateName: (permit: Permit, name: string) => Permit;
|
|
335
|
+
/**
|
|
336
|
+
* Fetch EIP712 domain from the blockchain
|
|
337
|
+
*/
|
|
338
|
+
fetchEIP712Domain: (publicClient: PublicClient) => Promise<EIP712Domain>;
|
|
339
|
+
/**
|
|
340
|
+
* Check if permit's signed domain matches the provided domain
|
|
341
|
+
*/
|
|
342
|
+
matchesDomain: (permit: Permit, domain: EIP712Domain) => boolean;
|
|
343
|
+
/**
|
|
344
|
+
* Check if permit's signed domain is valid for the current chain
|
|
345
|
+
*/
|
|
346
|
+
checkSignedDomainValid: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
export { type CreateSelfPermitOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedPermitOptions as I, type Permit as P, type RecipientPermit as R, type SerializedPermit as S, type ValidationResult as V, type PermitSignaturePrimaryType as a, type Permission as b, type EIP712Message as c, type CreateSharingPermitOptions as d, type PermitMetadata as e, type EIP712Domain as f, PermitUtils as g, SealingKey$1 as h, type EthEncryptedData as i, type EIP712Type as j, type PermitType as k, type PermitOf as l, type SelfPermit as m, type SharingPermit as n, type Expand as o };
|