@zama-fhe/sdk 1.0.0-alpha.2

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.
@@ -0,0 +1,196 @@
1
+ import { Address } from '@zama-fhe/relayer-sdk/bundle';
2
+
3
+ /** Batch transfer data for confidentialBatchTransfer. */
4
+ interface BatchTransferData {
5
+ to: Address;
6
+ encryptedAmount: Address;
7
+ inputProof: Address;
8
+ retryFor: bigint;
9
+ }
10
+ /**
11
+ * Returns the contract config for a confidential batch transfer.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const txHash = await signer.writeContract(
16
+ * confidentialBatchTransferContract(batcherAddress, tokenAddress, fromAddress, data, fees),
17
+ * );
18
+ * ```
19
+ */
20
+ declare function confidentialBatchTransferContract(batcherAddress: Address, tokenAddress: Address, fromAddress: Address, batchTransferData: BatchTransferData[], fees: bigint): {
21
+ readonly address: `0x${string}`;
22
+ readonly abi: readonly [{
23
+ readonly inputs: readonly [{
24
+ readonly internalType: "contract AdminProvider";
25
+ readonly name: "adminProvider_";
26
+ readonly type: "address";
27
+ }];
28
+ readonly stateMutability: "nonpayable";
29
+ readonly type: "constructor";
30
+ }, {
31
+ readonly inputs: readonly [{
32
+ readonly internalType: "address";
33
+ readonly name: "holder";
34
+ readonly type: "address";
35
+ }, {
36
+ readonly internalType: "address";
37
+ readonly name: "spender";
38
+ readonly type: "address";
39
+ }];
40
+ readonly name: "ERC7984UnauthorizedSpender";
41
+ readonly type: "error";
42
+ }, {
43
+ readonly inputs: readonly [];
44
+ readonly name: "EmptyTransferArray";
45
+ readonly type: "error";
46
+ }, {
47
+ readonly inputs: readonly [];
48
+ readonly name: "FeeTransferFailed";
49
+ readonly type: "error";
50
+ }, {
51
+ readonly inputs: readonly [];
52
+ readonly name: "InsufficientFee";
53
+ readonly type: "error";
54
+ }, {
55
+ readonly inputs: readonly [];
56
+ readonly name: "OnlyOriginalSenderCanRetry";
57
+ readonly type: "error";
58
+ }, {
59
+ readonly inputs: readonly [];
60
+ readonly name: "ZamaProtocolUnsupported";
61
+ readonly type: "error";
62
+ }, {
63
+ readonly anonymous: false;
64
+ readonly inputs: readonly [{
65
+ readonly indexed: true;
66
+ readonly internalType: "address";
67
+ readonly name: "cToken";
68
+ readonly type: "address";
69
+ }, {
70
+ readonly indexed: true;
71
+ readonly internalType: "address";
72
+ readonly name: "sender";
73
+ readonly type: "address";
74
+ }, {
75
+ readonly indexed: false;
76
+ readonly internalType: "uint256";
77
+ readonly name: "startTxId";
78
+ readonly type: "uint256";
79
+ }, {
80
+ readonly indexed: false;
81
+ readonly internalType: "uint256";
82
+ readonly name: "endTxId";
83
+ readonly type: "uint256";
84
+ }, {
85
+ readonly indexed: false;
86
+ readonly internalType: "uint256";
87
+ readonly name: "fee";
88
+ readonly type: "uint256";
89
+ }];
90
+ readonly name: "BatchTransfer";
91
+ readonly type: "event";
92
+ }, {
93
+ readonly anonymous: false;
94
+ readonly inputs: readonly [{
95
+ readonly indexed: true;
96
+ readonly internalType: "address";
97
+ readonly name: "cToken";
98
+ readonly type: "address";
99
+ }, {
100
+ readonly indexed: true;
101
+ readonly internalType: "address";
102
+ readonly name: "sender";
103
+ readonly type: "address";
104
+ }, {
105
+ readonly indexed: false;
106
+ readonly internalType: "uint256";
107
+ readonly name: "originalTxId";
108
+ readonly type: "uint256";
109
+ }, {
110
+ readonly indexed: false;
111
+ readonly internalType: "uint256";
112
+ readonly name: "retryTxId";
113
+ readonly type: "uint256";
114
+ }];
115
+ readonly name: "RetryTransfer";
116
+ readonly type: "event";
117
+ }, {
118
+ readonly inputs: readonly [];
119
+ readonly name: "adminProvider";
120
+ readonly outputs: readonly [{
121
+ readonly internalType: "contract AdminProvider";
122
+ readonly name: "";
123
+ readonly type: "address";
124
+ }];
125
+ readonly stateMutability: "view";
126
+ readonly type: "function";
127
+ }, {
128
+ readonly inputs: readonly [{
129
+ readonly internalType: "contract RegulatedERC7984Upgradeable";
130
+ readonly name: "cToken";
131
+ readonly type: "address";
132
+ }, {
133
+ readonly internalType: "address";
134
+ readonly name: "from";
135
+ readonly type: "address";
136
+ }, {
137
+ readonly components: readonly [{
138
+ readonly internalType: "address";
139
+ readonly name: "to";
140
+ readonly type: "address";
141
+ }, {
142
+ readonly internalType: "externalEuint64";
143
+ readonly name: "encryptedAmount";
144
+ readonly type: "bytes32";
145
+ }, {
146
+ readonly internalType: "bytes";
147
+ readonly name: "inputProof";
148
+ readonly type: "bytes";
149
+ }, {
150
+ readonly internalType: "uint256";
151
+ readonly name: "retryFor";
152
+ readonly type: "uint256";
153
+ }];
154
+ readonly internalType: "struct ERC7984TransferBatcher.ConfidentialTransferInput[]";
155
+ readonly name: "transfers";
156
+ readonly type: "tuple[]";
157
+ }];
158
+ readonly name: "confidentialBatchTransfer";
159
+ readonly outputs: readonly [];
160
+ readonly stateMutability: "payable";
161
+ readonly type: "function";
162
+ }, {
163
+ readonly inputs: readonly [];
164
+ readonly name: "confidentialProtocolId";
165
+ readonly outputs: readonly [{
166
+ readonly internalType: "uint256";
167
+ readonly name: "";
168
+ readonly type: "uint256";
169
+ }];
170
+ readonly stateMutability: "view";
171
+ readonly type: "function";
172
+ }, {
173
+ readonly inputs: readonly [{
174
+ readonly internalType: "address";
175
+ readonly name: "cToken";
176
+ readonly type: "address";
177
+ }, {
178
+ readonly internalType: "uint256";
179
+ readonly name: "txId";
180
+ readonly type: "uint256";
181
+ }];
182
+ readonly name: "txIdToSender";
183
+ readonly outputs: readonly [{
184
+ readonly internalType: "address";
185
+ readonly name: "sender";
186
+ readonly type: "address";
187
+ }];
188
+ readonly stateMutability: "view";
189
+ readonly type: "function";
190
+ }];
191
+ readonly functionName: "confidentialBatchTransfer";
192
+ readonly args: readonly [`0x${string}`, `0x${string}`, BatchTransferData[]];
193
+ readonly value: bigint;
194
+ };
195
+
196
+ export { type BatchTransferData as B, confidentialBatchTransferContract as c };
@@ -0,0 +1,42 @@
1
+ import { G as GenericSigner, E as EIP712TypedData, H as Hex, C as ContractCallConfig, T as TransactionReceipt } from '../token.types-D1ELXBX9.js';
2
+ import { WalletClient, PublicClient } from 'viem';
3
+ import { Address } from '@zama-fhe/relayer-sdk/bundle';
4
+ import { B as BatchTransferData } from '../transfer-batcher-BdbgGcJG.js';
5
+
6
+ /** Configuration for {@link ViemSigner}. */
7
+ interface ViemSignerConfig {
8
+ walletClient: WalletClient;
9
+ publicClient: PublicClient;
10
+ }
11
+ /**
12
+ * GenericSigner backed by viem.
13
+ *
14
+ * @param config - {@link ViemSignerConfig} with walletClient and publicClient
15
+ */
16
+ declare class ViemSigner implements GenericSigner {
17
+ private readonly walletClient;
18
+ private readonly publicClient;
19
+ constructor(config: ViemSignerConfig);
20
+ getChainId(): Promise<number>;
21
+ getAddress(): Promise<Address>;
22
+ signTypedData(typedData: EIP712TypedData): Promise<Hex>;
23
+ writeContract<C extends ContractCallConfig = ContractCallConfig>(config: C): Promise<Hex>;
24
+ readContract<T, C extends ContractCallConfig = ContractCallConfig>(config: C): Promise<T>;
25
+ waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt>;
26
+ }
27
+
28
+ declare function readConfidentialBalanceOfContract(client: PublicClient, tokenAddress: Address, userAddress: Address): Promise<`0x${string}`>;
29
+ declare function readWrapperForTokenContract(client: PublicClient, coordinator: Address, tokenAddress: Address): Promise<`0x${string}`>;
30
+ declare function readUnderlyingTokenContract(client: PublicClient, wrapperAddress: Address): Promise<`0x${string}`>;
31
+ declare function readWrapperExistsContract(client: PublicClient, coordinator: Address, tokenAddress: Address): Promise<boolean>;
32
+ declare function readSupportsInterfaceContract(client: PublicClient, tokenAddress: Address, interfaceId: Address): Promise<boolean>;
33
+ declare function writeConfidentialTransferContract(client: WalletClient, tokenAddress: Address, to: Address, handle: Uint8Array, inputProof: Uint8Array): Promise<`0x${string}`>;
34
+ declare function writeConfidentialBatchTransferContract(client: WalletClient, batcherAddress: Address, tokenAddress: Address, fromAddress: Address, batchTransferData: BatchTransferData[], fees: bigint): Promise<`0x${string}`>;
35
+ declare function writeUnwrapContract(client: WalletClient, encryptedErc20: Address, from: Address, to: Address, encryptedAmount: Uint8Array, inputProof: Uint8Array): Promise<`0x${string}`>;
36
+ declare function writeUnwrapFromBalanceContract(client: WalletClient, encryptedErc20: Address, from: Address, to: Address, encryptedBalance: Address): Promise<`0x${string}`>;
37
+ declare function writeFinalizeUnwrapContract(client: WalletClient, wrapper: Address, burntAmount: Address, burntAmountCleartext: bigint, decryptionProof: Address): Promise<`0x${string}`>;
38
+ declare function writeSetOperatorContract(client: WalletClient, tokenAddress: Address, spender: Address, timestamp?: number): Promise<`0x${string}`>;
39
+ declare function writeWrapContract(client: WalletClient, wrapperAddress: Address, to: Address, amount: bigint): Promise<`0x${string}`>;
40
+ declare function writeWrapETHContract(client: WalletClient, wrapperAddress: Address, to: Address, amount: bigint, value: bigint): Promise<`0x${string}`>;
41
+
42
+ export { ViemSigner, type ViemSignerConfig, readConfidentialBalanceOfContract, readSupportsInterfaceContract, readUnderlyingTokenContract, readWrapperExistsContract, readWrapperForTokenContract, writeConfidentialBatchTransferContract, writeConfidentialTransferContract, writeFinalizeUnwrapContract, writeSetOperatorContract, writeUnwrapContract, writeUnwrapFromBalanceContract, writeWrapContract, writeWrapETHContract };
@@ -0,0 +1,138 @@
1
+ import { confidentialBalanceOfContract, getWrapperContract, underlyingContract, wrapperExistsContract, supportsInterfaceContract, confidentialTransferContract, confidentialBatchTransferContract, unwrapContract, unwrapFromBalanceContract, finalizeUnwrapContract, setOperatorContract, wrapContract, wrapETHContract } from '../chunk-2FIUGJJY.js';
2
+ import '../chunk-CTX3H4CB.js';
3
+
4
+ // src/viem/viem-signer.ts
5
+ var ViemSigner = class {
6
+ walletClient;
7
+ publicClient;
8
+ constructor(config) {
9
+ this.walletClient = config.walletClient;
10
+ this.publicClient = config.publicClient;
11
+ }
12
+ async getChainId() {
13
+ return this.publicClient.getChainId();
14
+ }
15
+ async getAddress() {
16
+ const account = this.walletClient.account;
17
+ if (!account) {
18
+ throw new TypeError("Invalid address");
19
+ }
20
+ return account.address;
21
+ }
22
+ async signTypedData(typedData) {
23
+ const account = this.walletClient.account;
24
+ if (!account) throw new TypeError("WalletClient has no account");
25
+ const { EIP712Domain: _, ...sigTypes } = typedData.types;
26
+ return this.walletClient.signTypedData({
27
+ account,
28
+ primaryType: Object.keys(sigTypes)[0],
29
+ types: sigTypes,
30
+ domain: typedData.domain,
31
+ message: typedData.message
32
+ });
33
+ }
34
+ async writeContract(config) {
35
+ const account = this.walletClient.account;
36
+ if (!account) throw new TypeError("WalletClient has no account");
37
+ return this.walletClient.writeContract({
38
+ chain: this.walletClient.chain,
39
+ account,
40
+ ...config
41
+ });
42
+ }
43
+ async readContract(config) {
44
+ return this.publicClient.readContract(config);
45
+ }
46
+ async waitForTransactionReceipt(hash) {
47
+ return this.publicClient.waitForTransactionReceipt({ hash });
48
+ }
49
+ };
50
+
51
+ // src/viem/contracts.ts
52
+ function requireAccount(client) {
53
+ if (!client.account) {
54
+ throw new TypeError("WalletClient has no account");
55
+ }
56
+ return client.account;
57
+ }
58
+ function readConfidentialBalanceOfContract(client, tokenAddress, userAddress) {
59
+ return client.readContract(confidentialBalanceOfContract(tokenAddress, userAddress));
60
+ }
61
+ function readWrapperForTokenContract(client, coordinator, tokenAddress) {
62
+ return client.readContract(getWrapperContract(coordinator, tokenAddress));
63
+ }
64
+ function readUnderlyingTokenContract(client, wrapperAddress) {
65
+ return client.readContract(underlyingContract(wrapperAddress));
66
+ }
67
+ function readWrapperExistsContract(client, coordinator, tokenAddress) {
68
+ return client.readContract(wrapperExistsContract(coordinator, tokenAddress));
69
+ }
70
+ function readSupportsInterfaceContract(client, tokenAddress, interfaceId) {
71
+ return client.readContract(supportsInterfaceContract(tokenAddress, interfaceId));
72
+ }
73
+ function writeConfidentialTransferContract(client, tokenAddress, to, handle, inputProof) {
74
+ return client.writeContract({
75
+ chain: client.chain,
76
+ account: requireAccount(client),
77
+ ...confidentialTransferContract(tokenAddress, to, handle, inputProof)
78
+ });
79
+ }
80
+ function writeConfidentialBatchTransferContract(client, batcherAddress, tokenAddress, fromAddress, batchTransferData, fees) {
81
+ return client.writeContract({
82
+ chain: client.chain,
83
+ account: requireAccount(client),
84
+ ...confidentialBatchTransferContract(
85
+ batcherAddress,
86
+ tokenAddress,
87
+ fromAddress,
88
+ batchTransferData,
89
+ fees
90
+ )
91
+ });
92
+ }
93
+ function writeUnwrapContract(client, encryptedErc20, from, to, encryptedAmount, inputProof) {
94
+ return client.writeContract({
95
+ chain: client.chain,
96
+ account: requireAccount(client),
97
+ ...unwrapContract(encryptedErc20, from, to, encryptedAmount, inputProof)
98
+ });
99
+ }
100
+ function writeUnwrapFromBalanceContract(client, encryptedErc20, from, to, encryptedBalance) {
101
+ return client.writeContract({
102
+ chain: client.chain,
103
+ account: requireAccount(client),
104
+ ...unwrapFromBalanceContract(encryptedErc20, from, to, encryptedBalance)
105
+ });
106
+ }
107
+ function writeFinalizeUnwrapContract(client, wrapper, burntAmount, burntAmountCleartext, decryptionProof) {
108
+ return client.writeContract({
109
+ chain: client.chain,
110
+ account: requireAccount(client),
111
+ ...finalizeUnwrapContract(wrapper, burntAmount, burntAmountCleartext, decryptionProof)
112
+ });
113
+ }
114
+ function writeSetOperatorContract(client, tokenAddress, spender, timestamp) {
115
+ return client.writeContract({
116
+ chain: client.chain,
117
+ account: requireAccount(client),
118
+ ...setOperatorContract(tokenAddress, spender, timestamp)
119
+ });
120
+ }
121
+ function writeWrapContract(client, wrapperAddress, to, amount) {
122
+ return client.writeContract({
123
+ chain: client.chain,
124
+ account: requireAccount(client),
125
+ ...wrapContract(wrapperAddress, to, amount)
126
+ });
127
+ }
128
+ function writeWrapETHContract(client, wrapperAddress, to, amount, value) {
129
+ return client.writeContract({
130
+ chain: client.chain,
131
+ account: requireAccount(client),
132
+ ...wrapETHContract(wrapperAddress, to, amount, value)
133
+ });
134
+ }
135
+
136
+ export { ViemSigner, readConfidentialBalanceOfContract, readSupportsInterfaceContract, readUnderlyingTokenContract, readWrapperExistsContract, readWrapperForTokenContract, writeConfidentialBatchTransferContract, writeConfidentialTransferContract, writeFinalizeUnwrapContract, writeSetOperatorContract, writeUnwrapContract, writeUnwrapFromBalanceContract, writeWrapContract, writeWrapETHContract };
137
+ //# sourceMappingURL=index.js.map
138
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/viem/viem-signer.ts","../../src/viem/contracts.ts"],"names":[],"mappings":";;;;AAqBO,IAAM,aAAN,MAA0C;AAAA,EAC9B,YAAA;AAAA,EACA,YAAA;AAAA,EAEjB,YAAY,MAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,eAAe,MAAA,CAAO,YAAA;AAC3B,IAAA,IAAA,CAAK,eAAe,MAAA,CAAO,YAAA;AAAA,EAC7B;AAAA,EAEA,MAAM,UAAA,GAA8B;AAClC,IAAA,OAAO,IAAA,CAAK,aAAa,UAAA,EAAW;AAAA,EACtC;AAAA,EAEA,MAAM,UAAA,GAA+B;AACnC,IAAA,MAAM,OAAA,GAAU,KAAK,YAAA,CAAa,OAAA;AAClC,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,UAAU,iBAAiB,CAAA;AAAA,IACvC;AACA,IAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,EACjB;AAAA,EAEA,MAAM,cAAc,SAAA,EAA0C;AAC5D,IAAA,MAAM,OAAA,GAAU,KAAK,YAAA,CAAa,OAAA;AAClC,IAAA,IAAI,CAAC,OAAA,EAAS,MAAM,IAAI,UAAU,6BAA6B,CAAA;AAC/D,IAAA,MAAM,EAAE,YAAA,EAAc,CAAA,EAAG,GAAG,QAAA,KAAa,SAAA,CAAU,KAAA;AACnD,IAAA,OAAO,IAAA,CAAK,aAAa,aAAA,CAAc;AAAA,MACrC,OAAA;AAAA,MACA,WAAA,EAAa,MAAA,CAAO,IAAA,CAAK,QAAQ,EAAE,CAAC,CAAA;AAAA,MACpC,KAAA,EAAO,QAAA;AAAA,MACP,Q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KAAA;AAAA,IACd,OAAA,EAAS,eAAe,MAAM,CAAA;AAAA,IAC9B,GAAG,eAAA,CAAgB,cAAA,EAAgB,EAAA,EAAI,QAAQ,KAAK;AAAA,GACrD,CAAA;AACH","file":"index.js","sourcesContent":["import type {\n GenericSigner,\n ContractCallConfig,\n TransactionReceipt,\n Hex,\n} from \"../token/token.types\";\nimport type { PublicClient, WalletClient } from \"viem\";\nimport type { Address, EIP712TypedData } from \"../relayer/relayer-sdk.types\";\nimport { writeContract } from \"viem/actions\";\n\n/** Configuration for {@link ViemSigner}. */\nexport interface ViemSignerConfig {\n walletClient: WalletClient;\n publicClient: PublicClient;\n}\n\n/**\n * GenericSigner backed by viem.\n *\n * @param config - {@link ViemSignerConfig} with walletClient and publicClient\n */\nexport class ViemSigner implements GenericSigner {\n private readonly walletClient: WalletClient;\n private readonly publicClient: PublicClient;\n\n constructor(config: ViemSignerConfig) {\n this.walletClient = config.walletClient;\n this.publicClient = config.publicClient;\n }\n\n async getChainId(): Promise<number> {\n return this.publicClient.getChainId();\n }\n\n async getAddress(): Promise<Address> {\n const account = this.walletClient.account;\n if (!account) {\n throw new TypeError(\"Invalid address\");\n }\n return account.address;\n }\n\n async signTypedData(typedData: EIP712TypedData): Promise<Hex> {\n const account = this.walletClient.account;\n if (!account) throw new TypeError(\"WalletClient has no account\");\n const { EIP712Domain: _, ...sigTypes } = typedData.types;\n return this.walletClient.signTypedData({\n account,\n primaryType: Object.keys(sigTypes)[0]!,\n types: sigTypes,\n domain: typedData.domain,\n message: typedData.message,\n });\n }\n\n async writeContract<C extends ContractCallConfig = ContractCallConfig>(config: C): Promise<Hex> {\n const account = this.walletClient.account;\n if (!account) throw new TypeError(\"WalletClient has no account\");\n return this.walletClient.writeContract({\n chain: this.walletClient.chain,\n account,\n ...config,\n } as Parameters<typeof writeContract>[1]);\n }\n\n async readContract<T, C extends ContractCallConfig = ContractCallConfig>(config: C): Promise<T> {\n return this.publicClient.readContract(config) as Promise<T>;\n }\n\n async waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt> {\n return this.publicClient.waitForTransactionReceipt({ hash });\n }\n}\n","import type { PublicClient, WalletClient } from \"viem\";\nimport type { Address } from \"../relayer/relayer-sdk.types\";\nimport type { BatchTransferData } from \"../contracts\";\nimport {\n confidentialBalanceOfContract,\n confidentialBatchTransferContract,\n confidentialTransferContract,\n finalizeUnwrapContract,\n getWrapperContract,\n setOperatorContract,\n supportsInterfaceContract,\n underlyingContract,\n unwrapContract,\n unwrapFromBalanceContract,\n wrapContract,\n wrapETHContract,\n wrapperExistsContract,\n} from \"../contracts\";\n\n// ── Helpers ────────────────────────────────────────────────\n\nfunction requireAccount(client: WalletClient) {\n if (!client.account) {\n throw new TypeError(\"WalletClient has no account\");\n }\n return client.account;\n}\n\n// ── Read helpers ────────────────────────────────────────────\n\nexport function readConfidentialBalanceOfContract(\n client: PublicClient,\n tokenAddress: Address,\n userAddress: Address,\n) {\n return client.readContract(confidentialBalanceOfContract(tokenAddress, userAddress));\n}\n\nexport function readWrapperForTokenContract(\n client: PublicClient,\n coordinator: Address,\n tokenAddress: Address,\n) {\n return client.readContract(getWrapperContract(coordinator, tokenAddress));\n}\n\nexport function readUnderlyingTokenContract(client: PublicClient, wrapperAddress: Address) {\n return client.readContract(underlyingContract(wrapperAddress));\n}\n\nexport function readWrapperExistsContract(\n client: PublicClient,\n coordinator: Address,\n tokenAddress: Address,\n) {\n return client.readContract(wrapperExistsContract(coordinator, tokenAddress));\n}\n\nexport function readSupportsInterfaceContract(\n client: PublicClient,\n tokenAddress: Address,\n interfaceId: Address,\n) {\n return client.readContract(supportsInterfaceContract(tokenAddress, interfaceId));\n}\n\n// ── Write helpers ───────────────────────────────────────────\n\nexport function writeConfidentialTransferContract(\n client: WalletClient,\n tokenAddress: Address,\n to: Address,\n handle: Uint8Array,\n inputProof: Uint8Array,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...confidentialTransferContract(tokenAddress, to, handle, inputProof),\n });\n}\n\nexport function writeConfidentialBatchTransferContract(\n client: WalletClient,\n batcherAddress: Address,\n tokenAddress: Address,\n fromAddress: Address,\n batchTransferData: BatchTransferData[],\n fees: bigint,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...confidentialBatchTransferContract(\n batcherAddress,\n tokenAddress,\n fromAddress,\n batchTransferData,\n fees,\n ),\n });\n}\n\nexport function writeUnwrapContract(\n client: WalletClient,\n encryptedErc20: Address,\n from: Address,\n to: Address,\n encryptedAmount: Uint8Array,\n inputProof: Uint8Array,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...unwrapContract(encryptedErc20, from, to, encryptedAmount, inputProof),\n });\n}\n\nexport function writeUnwrapFromBalanceContract(\n client: WalletClient,\n encryptedErc20: Address,\n from: Address,\n to: Address,\n encryptedBalance: Address,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...unwrapFromBalanceContract(encryptedErc20, from, to, encryptedBalance),\n });\n}\n\nexport function writeFinalizeUnwrapContract(\n client: WalletClient,\n wrapper: Address,\n burntAmount: Address,\n burntAmountCleartext: bigint,\n decryptionProof: Address,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...finalizeUnwrapContract(wrapper, burntAmount, burntAmountCleartext, decryptionProof),\n });\n}\n\nexport function writeSetOperatorContract(\n client: WalletClient,\n tokenAddress: Address,\n spender: Address,\n timestamp?: number,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...setOperatorContract(tokenAddress, spender, timestamp),\n });\n}\n\nexport function writeWrapContract(\n client: WalletClient,\n wrapperAddress: Address,\n to: Address,\n amount: bigint,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...wrapContract(wrapperAddress, to, amount),\n });\n}\n\nexport function writeWrapETHContract(\n client: WalletClient,\n wrapperAddress: Address,\n to: Address,\n amount: bigint,\n value: bigint,\n) {\n return client.writeContract({\n chain: client.chain,\n account: requireAccount(client),\n ...wrapETHContract(wrapperAddress, to, amount, value),\n });\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@zama-fhe/sdk",
3
+ "version": "1.0.0-alpha.2",
4
+ "description": "TypeScript SDK for Zama confidential ERC-20 tokens (fhEVM)",
5
+ "license": "BSD-3-Clause-Clear",
6
+ "author": "Zama",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/zama-ai/sdk",
10
+ "directory": "packages/sdk"
11
+ },
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ },
20
+ "./viem": {
21
+ "types": "./dist/viem/index.d.ts",
22
+ "import": "./dist/viem/index.js"
23
+ },
24
+ "./ethers": {
25
+ "types": "./dist/ethers/index.d.ts",
26
+ "import": "./dist/ethers/index.js"
27
+ },
28
+ "./node": {
29
+ "types": "./dist/node/index.d.ts",
30
+ "import": "./dist/node/index.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "keywords": [
42
+ "fhe",
43
+ "zama",
44
+ "fhevm",
45
+ "confidential",
46
+ "erc20",
47
+ "privacy",
48
+ "homomorphic-encryption",
49
+ "token",
50
+ "ethereum",
51
+ "blockchain"
52
+ ],
53
+ "homepage": "https://github.com/zama-ai/sdk#readme",
54
+ "bugs": {
55
+ "url": "https://github.com/zama-ai/sdk/issues"
56
+ },
57
+ "scripts": {
58
+ "build": "tsup",
59
+ "lint": "eslint .",
60
+ "typecheck": "tsc --noEmit"
61
+ },
62
+ "devDependencies": {
63
+ "@zama-fhe/relayer-sdk": "0.4.1",
64
+ "tsup": "^8.5.1"
65
+ },
66
+ "peerDependencies": {
67
+ "viem": ">=2",
68
+ "ethers": ">=6",
69
+ "@zama-fhe/relayer-sdk": "~0.4.1"
70
+ },
71
+ "sideEffects": false,
72
+ "peerDependenciesMeta": {
73
+ "viem": {
74
+ "optional": true
75
+ },
76
+ "ethers": {
77
+ "optional": true
78
+ },
79
+ "@zama-fhe/relayer-sdk": {
80
+ "optional": true
81
+ }
82
+ },
83
+ "packageManager": "pnpm@10.30.2",
84
+ "engines": {
85
+ "node": ">=22",
86
+ "pnpm": ">=10"
87
+ }
88
+ }