@zama-fhe/sdk 1.0.0-alpha.10
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 +28 -0
- package/README.md +801 -0
- package/dist/chunk-5QJTGZHY.js +101 -0
- package/dist/chunk-5QJTGZHY.js.map +1 -0
- package/dist/chunk-6JRD26PS.js +114 -0
- package/dist/chunk-6JRD26PS.js.map +1 -0
- package/dist/chunk-PHE3BSIB.js +5143 -0
- package/dist/chunk-PHE3BSIB.js.map +1 -0
- package/dist/chunk-UF47M3QR.js +32 -0
- package/dist/chunk-UF47M3QR.js.map +1 -0
- package/dist/chunk-WYWAO3QE.js +182 -0
- package/dist/chunk-WYWAO3QE.js.map +1 -0
- package/dist/cleartext/index.d.ts +45 -0
- package/dist/cleartext/index.js +522 -0
- package/dist/cleartext/index.js.map +1 -0
- package/dist/ethers/index.d.ts +86 -0
- package/dist/ethers/index.js +148 -0
- package/dist/ethers/index.js.map +1 -0
- package/dist/index.d.ts +33405 -0
- package/dist/index.js +3563 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.d.ts +195 -0
- package/dist/node/index.js +337 -0
- package/dist/node/index.js.map +1 -0
- package/dist/relayer-sdk-Dh9aQmBm.d.ts +39 -0
- package/dist/relayer-sdk.node-worker.d.ts +2 -0
- package/dist/relayer-sdk.node-worker.js +348 -0
- package/dist/relayer-sdk.node-worker.js.map +1 -0
- package/dist/relayer-sdk.types-CgHZ6qZn.d.ts +327 -0
- package/dist/relayer-sdk.worker.js +511 -0
- package/dist/relayer-sdk.worker.js.map +1 -0
- package/dist/relayer-utils-phBmWrNB.d.ts +10 -0
- package/dist/token.types-CUTkehsp.d.ts +299 -0
- package/dist/transfer-batcher-CNtrNMz6.d.ts +197 -0
- package/dist/viem/index.d.ts +58 -0
- package/dist/viem/index.js +143 -0
- package/dist/viem/index.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Eip1193Provider, Signer, Provider } from 'ethers';
|
|
2
|
+
import { E as EIP712TypedData, H as Hex } from '../relayer-sdk.types-CgHZ6qZn.js';
|
|
3
|
+
import { G as GenericSigner, C as ContractCallConfig, T as TransactionReceipt, S as SignerLifecycleCallbacks } from '../token.types-CUTkehsp.js';
|
|
4
|
+
export { R as RawLog } from '../token.types-CUTkehsp.js';
|
|
5
|
+
import { Address } from '@zama-fhe/relayer-sdk/bundle';
|
|
6
|
+
import { B as BatchTransferData } from '../transfer-batcher-CNtrNMz6.js';
|
|
7
|
+
|
|
8
|
+
interface ProviderConnectInfo {
|
|
9
|
+
chainId: string;
|
|
10
|
+
}
|
|
11
|
+
interface ProviderMessage {
|
|
12
|
+
type: string;
|
|
13
|
+
data: unknown;
|
|
14
|
+
}
|
|
15
|
+
declare class ProviderRpcError extends Error {
|
|
16
|
+
code: number;
|
|
17
|
+
details: string;
|
|
18
|
+
constructor(code: number, message: string);
|
|
19
|
+
}
|
|
20
|
+
interface EIP1193EventMap {
|
|
21
|
+
accountsChanged(accounts: Address[]): void;
|
|
22
|
+
chainChanged(chainId: string): void;
|
|
23
|
+
connect(connectInfo: ProviderConnectInfo): void;
|
|
24
|
+
disconnect(error: ProviderRpcError): void;
|
|
25
|
+
message(message: ProviderMessage): void;
|
|
26
|
+
}
|
|
27
|
+
interface EIP1193Events {
|
|
28
|
+
on<event extends keyof EIP1193EventMap>(event: event, listener: EIP1193EventMap[event]): void;
|
|
29
|
+
removeListener<event extends keyof EIP1193EventMap>(event: event, listener: EIP1193EventMap[event]): void;
|
|
30
|
+
}
|
|
31
|
+
interface EIP1193Provider extends Eip1193Provider, EIP1193Events {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for {@link EthersSigner}.
|
|
36
|
+
*
|
|
37
|
+
* Two variants:
|
|
38
|
+
*
|
|
39
|
+
* - **Browser** — `{ ethereum }`: pass the raw EIP-1193 provider (e.g. `window.ethereum`).
|
|
40
|
+
* A `BrowserProvider` is created internally and `subscribe()` works automatically.
|
|
41
|
+
*
|
|
42
|
+
* - **Node / direct signer** — `{ signer }`: pass an ethers `Signer` (e.g. `Wallet`).
|
|
43
|
+
* `subscribe()` is not available since there is no EIP-1193 provider.
|
|
44
|
+
*/
|
|
45
|
+
type EthersSignerConfig = {
|
|
46
|
+
ethereum: EIP1193Provider;
|
|
47
|
+
} | {
|
|
48
|
+
signer: Signer;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* GenericSigner backed by ethers.
|
|
52
|
+
*
|
|
53
|
+
* Accepts either a raw EIP-1193 provider (`{ ethereum }`) which creates a
|
|
54
|
+
* `BrowserProvider` internally, or a `Signer` directly (`{ signer }`)
|
|
55
|
+
* for Node.js scripts.
|
|
56
|
+
*
|
|
57
|
+
* @param config - {@link EthersSignerConfig}
|
|
58
|
+
*/
|
|
59
|
+
declare class EthersSigner implements GenericSigner {
|
|
60
|
+
private signerPromise;
|
|
61
|
+
private readonly provider?;
|
|
62
|
+
constructor(config: EthersSignerConfig);
|
|
63
|
+
getChainId(): Promise<number>;
|
|
64
|
+
getAddress(): Promise<Address>;
|
|
65
|
+
signTypedData(typedData: EIP712TypedData): Promise<Hex>;
|
|
66
|
+
writeContract<C extends ContractCallConfig>(config: C): Promise<Hex>;
|
|
67
|
+
readContract<T, C extends ContractCallConfig>(config: C): Promise<T>;
|
|
68
|
+
waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt>;
|
|
69
|
+
subscribe(callbacks: SignerLifecycleCallbacks): () => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare function readConfidentialBalanceOfContract(provider: Provider | Signer, tokenAddress: Address, userAddress: Address): Promise<any>;
|
|
73
|
+
declare function readWrapperForTokenContract(provider: Provider | Signer, coordinator: Address, tokenAddress: Address): Promise<any>;
|
|
74
|
+
declare function readUnderlyingTokenContract(provider: Provider | Signer, wrapperAddress: Address): Promise<any>;
|
|
75
|
+
declare function readWrapperExistsContract(provider: Provider | Signer, coordinator: Address, tokenAddress: Address): Promise<any>;
|
|
76
|
+
declare function readSupportsInterfaceContract(provider: Provider | Signer, tokenAddress: Address, interfaceId: Address): Promise<any>;
|
|
77
|
+
declare function writeConfidentialTransferContract(signer: Signer, tokenAddress: Address, to: Address, handle: Uint8Array, inputProof: Uint8Array): Promise<`0x${string}`>;
|
|
78
|
+
declare function writeConfidentialBatchTransferContract(signer: Signer, batcherAddress: Address, tokenAddress: Address, fromAddress: Address, batchTransferData: BatchTransferData[], fees: bigint): Promise<`0x${string}`>;
|
|
79
|
+
declare function writeUnwrapContract(signer: Signer, encryptedErc20: Address, from: Address, to: Address, encryptedAmount: Uint8Array, inputProof: Uint8Array): Promise<`0x${string}`>;
|
|
80
|
+
declare function writeUnwrapFromBalanceContract(signer: Signer, encryptedErc20: Address, from: Address, to: Address, encryptedBalance: Address): Promise<`0x${string}`>;
|
|
81
|
+
declare function writeFinalizeUnwrapContract(signer: Signer, wrapper: Address, burntAmount: Address, burntAmountCleartext: bigint, decryptionProof: Address): Promise<`0x${string}`>;
|
|
82
|
+
declare function writeSetOperatorContract(signer: Signer, tokenAddress: Address, spender: Address, timestamp?: number): Promise<`0x${string}`>;
|
|
83
|
+
declare function writeWrapContract(signer: Signer, wrapperAddress: Address, to: Address, amount: bigint): Promise<`0x${string}`>;
|
|
84
|
+
declare function writeWrapETHContract(signer: Signer, wrapperAddress: Address, to: Address, amount: bigint, value: bigint): Promise<`0x${string}`>;
|
|
85
|
+
|
|
86
|
+
export { BatchTransferData, ContractCallConfig, type EIP1193EventMap, type EIP1193Events, type EIP1193Provider, EIP712TypedData, EthersSigner, type EthersSignerConfig, GenericSigner, Hex, type ProviderConnectInfo, type ProviderMessage, ProviderRpcError, SignerLifecycleCallbacks, TransactionReceipt, readConfidentialBalanceOfContract, readSupportsInterfaceContract, readUnderlyingTokenContract, readWrapperExistsContract, readWrapperForTokenContract, writeConfidentialBatchTransferContract, writeConfidentialTransferContract, writeFinalizeUnwrapContract, writeSetOperatorContract, writeUnwrapContract, writeUnwrapFromBalanceContract, writeWrapContract, writeWrapETHContract };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { eip1193Subscribe } from '../chunk-UF47M3QR.js';
|
|
2
|
+
import { confidentialBalanceOfContract, getWrapperContract, underlyingContract, wrapperExistsContract, supportsInterfaceContract, confidentialTransferContract, confidentialBatchTransferContract, unwrapContract, unwrapFromBalanceContract, finalizeUnwrapContract, setOperatorContract, wrapContract, wrapETHContract } from '../chunk-PHE3BSIB.js';
|
|
3
|
+
import { BrowserProvider, ethers } from 'ethers';
|
|
4
|
+
|
|
5
|
+
function toHex(s) {
|
|
6
|
+
if (!s.startsWith("0x")) throw new TypeError(`Expected hex string, got: ${s}`);
|
|
7
|
+
return s;
|
|
8
|
+
}
|
|
9
|
+
var EthersSigner = class {
|
|
10
|
+
signerPromise;
|
|
11
|
+
provider;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
if ("ethereum" in config) {
|
|
14
|
+
this.signerPromise = new BrowserProvider(config.ethereum).getSigner();
|
|
15
|
+
this.provider = config.ethereum;
|
|
16
|
+
} else {
|
|
17
|
+
this.signerPromise = Promise.resolve(config.signer);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async getChainId() {
|
|
21
|
+
const signer = await this.signerPromise;
|
|
22
|
+
const provider = signer.provider;
|
|
23
|
+
if (!provider) throw new TypeError("Signer has no provider");
|
|
24
|
+
const network = await provider.getNetwork();
|
|
25
|
+
return Number(network.chainId);
|
|
26
|
+
}
|
|
27
|
+
async getAddress() {
|
|
28
|
+
const signer = await this.signerPromise;
|
|
29
|
+
return toHex(await signer.getAddress());
|
|
30
|
+
}
|
|
31
|
+
async signTypedData(typedData) {
|
|
32
|
+
const signer = await this.signerPromise;
|
|
33
|
+
const { domain, types, message } = typedData;
|
|
34
|
+
const { EIP712Domain: _, ...sigTypes } = types;
|
|
35
|
+
const sig = await signer.signTypedData(domain, sigTypes, message);
|
|
36
|
+
return toHex(sig);
|
|
37
|
+
}
|
|
38
|
+
async writeContract(config) {
|
|
39
|
+
const signer = await this.signerPromise;
|
|
40
|
+
const contract = new ethers.Contract(config.address, config.abi, signer);
|
|
41
|
+
const overrides = {};
|
|
42
|
+
if (config.value !== void 0) overrides.value = config.value;
|
|
43
|
+
const tx = await contract[config.functionName](...config.args, overrides);
|
|
44
|
+
return toHex(tx.hash);
|
|
45
|
+
}
|
|
46
|
+
async readContract(config) {
|
|
47
|
+
const signer = await this.signerPromise;
|
|
48
|
+
const contract = new ethers.Contract(config.address, config.abi, signer);
|
|
49
|
+
return contract[config.functionName](...config.args);
|
|
50
|
+
}
|
|
51
|
+
async waitForTransactionReceipt(hash) {
|
|
52
|
+
const signer = await this.signerPromise;
|
|
53
|
+
const provider = signer.provider;
|
|
54
|
+
if (!provider) throw new TypeError("Signer has no provider");
|
|
55
|
+
const receipt = await provider.waitForTransaction(hash);
|
|
56
|
+
if (!receipt) throw new Error("Transaction receipt not found");
|
|
57
|
+
return {
|
|
58
|
+
logs: receipt.logs.map((log) => ({
|
|
59
|
+
topics: log.topics.filter((t) => t !== null),
|
|
60
|
+
data: log.data
|
|
61
|
+
}))
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
subscribe(callbacks) {
|
|
65
|
+
return eip1193Subscribe(this.provider, () => this.getAddress(), callbacks);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/ethers/ethers.types.ts
|
|
70
|
+
var ProviderRpcError = class extends Error {
|
|
71
|
+
code;
|
|
72
|
+
details;
|
|
73
|
+
constructor(code, message) {
|
|
74
|
+
super(message);
|
|
75
|
+
this.code = code;
|
|
76
|
+
this.details = message;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
async function ethersRead(provider, config) {
|
|
80
|
+
const contract = new ethers.Contract(config.address, config.abi, provider);
|
|
81
|
+
return contract[config.functionName](...config.args);
|
|
82
|
+
}
|
|
83
|
+
function toHex2(s) {
|
|
84
|
+
if (!s.startsWith("0x")) throw new TypeError(`Expected hex string, got: ${s}`);
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
87
|
+
async function ethersWrite(signer, config) {
|
|
88
|
+
const contract = new ethers.Contract(config.address, config.abi, signer);
|
|
89
|
+
const tx = await contract[config.functionName](...config.args, {
|
|
90
|
+
value: config.value
|
|
91
|
+
});
|
|
92
|
+
return toHex2(tx.hash);
|
|
93
|
+
}
|
|
94
|
+
function readConfidentialBalanceOfContract(provider, tokenAddress, userAddress) {
|
|
95
|
+
return ethersRead(provider, confidentialBalanceOfContract(tokenAddress, userAddress));
|
|
96
|
+
}
|
|
97
|
+
function readWrapperForTokenContract(provider, coordinator, tokenAddress) {
|
|
98
|
+
return ethersRead(provider, getWrapperContract(coordinator, tokenAddress));
|
|
99
|
+
}
|
|
100
|
+
function readUnderlyingTokenContract(provider, wrapperAddress) {
|
|
101
|
+
return ethersRead(provider, underlyingContract(wrapperAddress));
|
|
102
|
+
}
|
|
103
|
+
function readWrapperExistsContract(provider, coordinator, tokenAddress) {
|
|
104
|
+
return ethersRead(provider, wrapperExistsContract(coordinator, tokenAddress));
|
|
105
|
+
}
|
|
106
|
+
function readSupportsInterfaceContract(provider, tokenAddress, interfaceId) {
|
|
107
|
+
return ethersRead(provider, supportsInterfaceContract(tokenAddress, interfaceId));
|
|
108
|
+
}
|
|
109
|
+
function writeConfidentialTransferContract(signer, tokenAddress, to, handle, inputProof) {
|
|
110
|
+
return ethersWrite(signer, confidentialTransferContract(tokenAddress, to, handle, inputProof));
|
|
111
|
+
}
|
|
112
|
+
function writeConfidentialBatchTransferContract(signer, batcherAddress, tokenAddress, fromAddress, batchTransferData, fees) {
|
|
113
|
+
return ethersWrite(
|
|
114
|
+
signer,
|
|
115
|
+
confidentialBatchTransferContract(
|
|
116
|
+
batcherAddress,
|
|
117
|
+
tokenAddress,
|
|
118
|
+
fromAddress,
|
|
119
|
+
batchTransferData,
|
|
120
|
+
fees
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
function writeUnwrapContract(signer, encryptedErc20, from, to, encryptedAmount, inputProof) {
|
|
125
|
+
return ethersWrite(signer, unwrapContract(encryptedErc20, from, to, encryptedAmount, inputProof));
|
|
126
|
+
}
|
|
127
|
+
function writeUnwrapFromBalanceContract(signer, encryptedErc20, from, to, encryptedBalance) {
|
|
128
|
+
return ethersWrite(signer, unwrapFromBalanceContract(encryptedErc20, from, to, encryptedBalance));
|
|
129
|
+
}
|
|
130
|
+
function writeFinalizeUnwrapContract(signer, wrapper, burntAmount, burntAmountCleartext, decryptionProof) {
|
|
131
|
+
return ethersWrite(
|
|
132
|
+
signer,
|
|
133
|
+
finalizeUnwrapContract(wrapper, burntAmount, burntAmountCleartext, decryptionProof)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
function writeSetOperatorContract(signer, tokenAddress, spender, timestamp) {
|
|
137
|
+
return ethersWrite(signer, setOperatorContract(tokenAddress, spender, timestamp));
|
|
138
|
+
}
|
|
139
|
+
function writeWrapContract(signer, wrapperAddress, to, amount) {
|
|
140
|
+
return ethersWrite(signer, wrapContract(wrapperAddress, to, amount));
|
|
141
|
+
}
|
|
142
|
+
function writeWrapETHContract(signer, wrapperAddress, to, amount, value) {
|
|
143
|
+
return ethersWrite(signer, wrapETHContract(wrapperAddress, to, amount, value));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { EthersSigner, ProviderRpcError, readConfidentialBalanceOfContract, readSupportsInterfaceContract, readUnderlyingTokenContract, readWrapperExistsContract, readWrapperForTokenContract, writeConfidentialBatchTransferContract, writeConfidentialTransferContract, writeFinalizeUnwrapContract, writeSetOperatorContract, writeUnwrapContract, writeUnwrapFromBalanceContract, writeWrapContract, writeWrapETHContract };
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
148
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ethers/ethers-signer.ts","../../src/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,CAAA;AACrE;AAEO,SAAS,oBAAA,CACd,MAAA,EACA,cAAA,EACA,EAAA,EACA,QACA,KAAA,EACA;AACA,EAAA,OAAO,YAAY,MAAA,EAAQ,eAAA,CAAgB,gBAAgB,EAAA,EAAI,MAAA,EAAQ,KAAK,CAAC,CAAA;AAC/E","file":"index.js","sourcesContent":["import { ethers, BrowserProvider, type Signer } from \"ethers\";\nimport type { Address, EIP712TypedData } from \"../relayer/relayer-sdk.types\";\nimport type {\n ContractCallConfig,\n GenericSigner,\n Hex,\n SignerLifecycleCallbacks,\n TransactionReceipt,\n} from \"../token/token.types\";\nimport { eip1193Subscribe } from \"../token/eip1193-subscribe\";\nimport { EIP1193Provider } from \"./ethers.types\";\n\n/** Validate and narrow a string to the `Hex` branded type. */\nfunction toHex(s: string): Hex {\n if (!s.startsWith(\"0x\")) throw new TypeError(`Expected hex string, got: ${s}`);\n return s as Hex;\n}\n\n/**\n * Configuration for {@link EthersSigner}.\n *\n * Two variants:\n *\n * - **Browser** — `{ ethereum }`: pass the raw EIP-1193 provider (e.g. `window.ethereum`).\n * A `BrowserProvider` is created internally and `subscribe()` works automatically.\n *\n * - **Node / direct signer** — `{ signer }`: pass an ethers `Signer` (e.g. `Wallet`).\n * `subscribe()` is not available since there is no EIP-1193 provider.\n */\nexport type EthersSignerConfig = { ethereum: EIP1193Provider } | { signer: Signer };\n\n/**\n * GenericSigner backed by ethers.\n *\n * Accepts either a raw EIP-1193 provider (`{ ethereum }`) which creates a\n * `BrowserProvider` internally, or a `Signer` directly (`{ signer }`)\n * for Node.js scripts.\n *\n * @param config - {@link EthersSignerConfig}\n */\nexport class EthersSigner implements GenericSigner {\n private signerPromise: Promise<Signer>;\n private readonly provider?: EIP1193Provider;\n\n constructor(config: EthersSignerConfig) {\n if (\"ethereum\" in config) {\n this.signerPromise = new BrowserProvider(config.ethereum).getSigner();\n this.provider = config.ethereum;\n } else {\n this.signerPromise = Promise.resolve(config.signer);\n }\n }\n\n async getChainId(): Promise<number> {\n const signer = await this.signerPromise;\n const provider = signer.provider;\n if (!provider) throw new TypeError(\"Signer has no provider\");\n const network = await provider.getNetwork();\n return Number(network.chainId);\n }\n\n async getAddress(): Promise<Address> {\n const signer = await this.signerPromise;\n return toHex(await signer.getAddress()) as Address;\n }\n\n async signTypedData(typedData: EIP712TypedData): Promise<Hex> {\n const signer = await this.signerPromise;\n const { domain, types, message } = typedData;\n const { EIP712Domain: _, ...sigTypes } = types;\n const sig = await signer.signTypedData(domain, sigTypes, message);\n return toHex(sig);\n }\n\n async writeContract<C extends ContractCallConfig>(config: C): Promise<Hex> {\n const signer = await this.signerPromise;\n const contract = new ethers.Contract(config.address, config.abi as ethers.InterfaceAbi, signer);\n const overrides: Record<string, unknown> = {};\n if (config.value !== undefined) overrides.value = config.value;\n const tx = await contract[config.functionName]!(...config.args, overrides);\n return toHex(tx.hash);\n }\n\n async readContract<T, C extends ContractCallConfig>(config: C): Promise<T> {\n const signer = await this.signerPromise;\n const contract = new ethers.Contract(config.address, config.abi as ethers.InterfaceAbi, signer);\n return contract[config.functionName]!(...config.args) as Promise<T>;\n }\n\n async waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt> {\n const signer = await this.signerPromise;\n const provider = signer.provider;\n if (!provider) throw new TypeError(\"Signer has no provider\");\n const receipt = await provider.waitForTransaction(hash);\n if (!receipt) throw new Error(\"Transaction receipt not found\");\n return {\n logs: receipt.logs.map((log) => ({\n topics: log.topics.filter((t): t is string => t !== null),\n data: log.data,\n })),\n };\n }\n\n subscribe(callbacks: SignerLifecycleCallbacks): () => void {\n return eip1193Subscribe(this.provider, () => this.getAddress(), callbacks);\n }\n}\n","import { Eip1193Provider } from \"ethers\";\nimport { Address } from \"../relayer/relayer-sdk.types\";\n\nexport interface ProviderConnectInfo {\n chainId: string;\n}\n\nexport interface ProviderMessage {\n type: string;\n data: unknown;\n}\n\nexport class ProviderRpcError extends Error {\n code: number;\n details: string;\n\n constructor(code: number, message: string) {\n super(message);\n this.code = code;\n this.details = message;\n }\n}\n\nexport interface EIP1193EventMap {\n accountsChanged(accounts: Address[]): void;\n chainChanged(chainId: string): void;\n connect(connectInfo: ProviderConnectInfo): void;\n disconnect(error: ProviderRpcError): void;\n message(message: ProviderMessage): void;\n}\n\nexport interface EIP1193Events {\n on<event extends keyof EIP1193EventMap>(event: event, listener: EIP1193EventMap[event]): void;\n removeListener<event extends keyof EIP1193EventMap>(\n event: event,\n listener: EIP1193EventMap[event],\n ): void;\n}\n\nexport interface EIP1193Provider extends Eip1193Provider, EIP1193Events {}\n","import { ethers, type Provider, type Signer } from \"ethers\";\nimport type { Address, Hex } 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\ninterface ContractConfig {\n address: string;\n abi: readonly unknown[];\n functionName: string;\n args: readonly unknown[];\n value?: bigint;\n}\n\nasync function ethersRead(provider: Provider | Signer, config: ContractConfig) {\n const contract = new ethers.Contract(config.address, config.abi as ethers.InterfaceAbi, provider);\n return contract[config.functionName]!(...config.args);\n}\n\n/** Validate and narrow a string to the `Hex` branded type. */\nfunction toHex(s: string): Hex {\n if (!s.startsWith(\"0x\")) throw new TypeError(`Expected hex string, got: ${s}`);\n return s as Hex;\n}\n\nasync function ethersWrite(signer: Signer, config: ContractConfig): Promise<Hex> {\n const contract = new ethers.Contract(config.address, config.abi as ethers.InterfaceAbi, signer);\n const tx = await contract[config.functionName]!(...config.args, {\n value: config.value,\n });\n return toHex(tx.hash);\n}\n\n// ── Read helpers ────────────────────────────────────────────\n\nexport function readConfidentialBalanceOfContract(\n provider: Provider | Signer,\n tokenAddress: Address,\n userAddress: Address,\n) {\n return ethersRead(provider, confidentialBalanceOfContract(tokenAddress, userAddress));\n}\n\nexport function readWrapperForTokenContract(\n provider: Provider | Signer,\n coordinator: Address,\n tokenAddress: Address,\n) {\n return ethersRead(provider, getWrapperContract(coordinator, tokenAddress));\n}\n\nexport function readUnderlyingTokenContract(provider: Provider | Signer, wrapperAddress: Address) {\n return ethersRead(provider, underlyingContract(wrapperAddress));\n}\n\nexport function readWrapperExistsContract(\n provider: Provider | Signer,\n coordinator: Address,\n tokenAddress: Address,\n) {\n return ethersRead(provider, wrapperExistsContract(coordinator, tokenAddress));\n}\n\nexport function readSupportsInterfaceContract(\n provider: Provider | Signer,\n tokenAddress: Address,\n interfaceId: Address,\n) {\n return ethersRead(provider, supportsInterfaceContract(tokenAddress, interfaceId));\n}\n\n// ── Write helpers ───────────────────────────────────────────\n\nexport function writeConfidentialTransferContract(\n signer: Signer,\n tokenAddress: Address,\n to: Address,\n handle: Uint8Array,\n inputProof: Uint8Array,\n) {\n return ethersWrite(signer, confidentialTransferContract(tokenAddress, to, handle, inputProof));\n}\n\nexport function writeConfidentialBatchTransferContract(\n signer: Signer,\n batcherAddress: Address,\n tokenAddress: Address,\n fromAddress: Address,\n batchTransferData: BatchTransferData[],\n fees: bigint,\n) {\n return ethersWrite(\n signer,\n confidentialBatchTransferContract(\n batcherAddress,\n tokenAddress,\n fromAddress,\n batchTransferData,\n fees,\n ),\n );\n}\n\nexport function writeUnwrapContract(\n signer: Signer,\n encryptedErc20: Address,\n from: Address,\n to: Address,\n encryptedAmount: Uint8Array,\n inputProof: Uint8Array,\n) {\n return ethersWrite(signer, unwrapContract(encryptedErc20, from, to, encryptedAmount, inputProof));\n}\n\nexport function writeUnwrapFromBalanceContract(\n signer: Signer,\n encryptedErc20: Address,\n from: Address,\n to: Address,\n encryptedBalance: Address,\n) {\n return ethersWrite(signer, unwrapFromBalanceContract(encryptedErc20, from, to, encryptedBalance));\n}\n\nexport function writeFinalizeUnwrapContract(\n signer: Signer,\n wrapper: Address,\n burntAmount: Address,\n burntAmountCleartext: bigint,\n decryptionProof: Address,\n) {\n return ethersWrite(\n signer,\n finalizeUnwrapContract(wrapper, burntAmount, burntAmountCleartext, decryptionProof),\n );\n}\n\nexport function writeSetOperatorContract(\n signer: Signer,\n tokenAddress: Address,\n spender: Address,\n timestamp?: number,\n) {\n return ethersWrite(signer, setOperatorContract(tokenAddress, spender, timestamp));\n}\n\nexport function writeWrapContract(\n signer: Signer,\n wrapperAddress: Address,\n to: Address,\n amount: bigint,\n) {\n return ethersWrite(signer, wrapContract(wrapperAddress, to, amount));\n}\n\nexport function writeWrapETHContract(\n signer: Signer,\n wrapperAddress: Address,\n to: Address,\n amount: bigint,\n value: bigint,\n) {\n return ethersWrite(signer, wrapETHContract(wrapperAddress, to, amount, value));\n}\n"]}
|