@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,143 @@
|
|
|
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
|
+
|
|
4
|
+
// src/viem/viem-signer.ts
|
|
5
|
+
var ViemSigner = class {
|
|
6
|
+
walletClient;
|
|
7
|
+
publicClient;
|
|
8
|
+
ethereum;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.walletClient = config.walletClient;
|
|
11
|
+
this.publicClient = config.publicClient;
|
|
12
|
+
this.ethereum = config.ethereum;
|
|
13
|
+
}
|
|
14
|
+
async getChainId() {
|
|
15
|
+
return this.publicClient.getChainId();
|
|
16
|
+
}
|
|
17
|
+
async getAddress() {
|
|
18
|
+
const account = this.walletClient.account;
|
|
19
|
+
if (!account) {
|
|
20
|
+
throw new TypeError("Invalid address");
|
|
21
|
+
}
|
|
22
|
+
return account.address;
|
|
23
|
+
}
|
|
24
|
+
async signTypedData(typedData) {
|
|
25
|
+
const account = this.walletClient.account;
|
|
26
|
+
if (!account) throw new TypeError("WalletClient has no account");
|
|
27
|
+
const { EIP712Domain: _, ...sigTypes } = typedData.types;
|
|
28
|
+
return this.walletClient.signTypedData({
|
|
29
|
+
account,
|
|
30
|
+
primaryType: Object.keys(sigTypes)[0],
|
|
31
|
+
types: sigTypes,
|
|
32
|
+
domain: typedData.domain,
|
|
33
|
+
message: typedData.message
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async writeContract(config) {
|
|
37
|
+
const account = this.walletClient.account;
|
|
38
|
+
if (!account) throw new TypeError("WalletClient has no account");
|
|
39
|
+
return this.walletClient.writeContract({
|
|
40
|
+
chain: this.walletClient.chain,
|
|
41
|
+
account,
|
|
42
|
+
...config
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async readContract(config) {
|
|
46
|
+
return this.publicClient.readContract(config);
|
|
47
|
+
}
|
|
48
|
+
async waitForTransactionReceipt(hash) {
|
|
49
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
50
|
+
}
|
|
51
|
+
subscribe(callbacks) {
|
|
52
|
+
return eip1193Subscribe(this.ethereum, () => this.getAddress(), callbacks);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/viem/contracts.ts
|
|
57
|
+
function requireAccount(client) {
|
|
58
|
+
if (!client.account) {
|
|
59
|
+
throw new TypeError("WalletClient has no account");
|
|
60
|
+
}
|
|
61
|
+
return client.account;
|
|
62
|
+
}
|
|
63
|
+
function readConfidentialBalanceOfContract(client, tokenAddress, userAddress) {
|
|
64
|
+
return client.readContract(confidentialBalanceOfContract(tokenAddress, userAddress));
|
|
65
|
+
}
|
|
66
|
+
function readWrapperForTokenContract(client, coordinator, tokenAddress) {
|
|
67
|
+
return client.readContract(getWrapperContract(coordinator, tokenAddress));
|
|
68
|
+
}
|
|
69
|
+
function readUnderlyingTokenContract(client, wrapperAddress) {
|
|
70
|
+
return client.readContract(underlyingContract(wrapperAddress));
|
|
71
|
+
}
|
|
72
|
+
function readWrapperExistsContract(client, coordinator, tokenAddress) {
|
|
73
|
+
return client.readContract(wrapperExistsContract(coordinator, tokenAddress));
|
|
74
|
+
}
|
|
75
|
+
function readSupportsInterfaceContract(client, tokenAddress, interfaceId) {
|
|
76
|
+
return client.readContract(supportsInterfaceContract(tokenAddress, interfaceId));
|
|
77
|
+
}
|
|
78
|
+
function writeConfidentialTransferContract(client, tokenAddress, to, handle, inputProof) {
|
|
79
|
+
return client.writeContract({
|
|
80
|
+
chain: client.chain,
|
|
81
|
+
account: requireAccount(client),
|
|
82
|
+
...confidentialTransferContract(tokenAddress, to, handle, inputProof)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function writeConfidentialBatchTransferContract(client, batcherAddress, tokenAddress, fromAddress, batchTransferData, fees) {
|
|
86
|
+
return client.writeContract({
|
|
87
|
+
chain: client.chain,
|
|
88
|
+
account: requireAccount(client),
|
|
89
|
+
...confidentialBatchTransferContract(
|
|
90
|
+
batcherAddress,
|
|
91
|
+
tokenAddress,
|
|
92
|
+
fromAddress,
|
|
93
|
+
batchTransferData,
|
|
94
|
+
fees
|
|
95
|
+
)
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function writeUnwrapContract(client, encryptedErc20, from, to, encryptedAmount, inputProof) {
|
|
99
|
+
return client.writeContract({
|
|
100
|
+
chain: client.chain,
|
|
101
|
+
account: requireAccount(client),
|
|
102
|
+
...unwrapContract(encryptedErc20, from, to, encryptedAmount, inputProof)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function writeUnwrapFromBalanceContract(client, encryptedErc20, from, to, encryptedBalance) {
|
|
106
|
+
return client.writeContract({
|
|
107
|
+
chain: client.chain,
|
|
108
|
+
account: requireAccount(client),
|
|
109
|
+
...unwrapFromBalanceContract(encryptedErc20, from, to, encryptedBalance)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function writeFinalizeUnwrapContract(client, wrapper, burntAmount, burntAmountCleartext, decryptionProof) {
|
|
113
|
+
return client.writeContract({
|
|
114
|
+
chain: client.chain,
|
|
115
|
+
account: requireAccount(client),
|
|
116
|
+
...finalizeUnwrapContract(wrapper, burntAmount, burntAmountCleartext, decryptionProof)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function writeSetOperatorContract(client, tokenAddress, spender, timestamp) {
|
|
120
|
+
return client.writeContract({
|
|
121
|
+
chain: client.chain,
|
|
122
|
+
account: requireAccount(client),
|
|
123
|
+
...setOperatorContract(tokenAddress, spender, timestamp)
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function writeWrapContract(client, wrapperAddress, to, amount) {
|
|
127
|
+
return client.writeContract({
|
|
128
|
+
chain: client.chain,
|
|
129
|
+
account: requireAccount(client),
|
|
130
|
+
...wrapContract(wrapperAddress, to, amount)
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function writeWrapETHContract(client, wrapperAddress, to, amount, value) {
|
|
134
|
+
return client.writeContract({
|
|
135
|
+
chain: client.chain,
|
|
136
|
+
account: requireAccount(client),
|
|
137
|
+
...wrapETHContract(wrapperAddress, to, amount, value)
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { ViemSigner, readConfidentialBalanceOfContract, readSupportsInterfaceContract, readUnderlyingTokenContract, readWrapperExistsContract, readWrapperForTokenContract, writeConfidentialBatchTransferContract, writeConfidentialTransferContract, writeFinalizeUnwrapContract, writeSetOperatorContract, writeUnwrapContract, writeUnwrapFromBalanceContract, writeWrapContract, writeWrapETHContract };
|
|
142
|
+
//# sourceMappingURL=index.js.map
|
|
143
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/viem/viem-signer.ts","../../src/viem/contracts.ts"],"names":[],"mappings":";;;;AAmCO,IAAM,aAAN,MAA0C;AAAA,EAC9B,YAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EAEjB,YAAY,MAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,eAAe,MAAA,CAAO,YAAA;AAC3B,IAAA,IAAA,CAAK,eAAe,MAAA,CAAO,YAAA;AAC3B,IAAA,IAAA,CAAK,WAAW,MAAA,CAAO,QAAA;AAAA,EACzB;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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B,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,OAAA,EAAS,eAAe,MAAM,CAAA;AAAA,IAC9B,GAAG,mBAAA,CAAoB,YAAA,EAAc,OAAA,EAAS,SAAS;AAAA,GACxD,CAAA;AACH;AAEO,SAAS,iBAAA,CACd,MAAA,EACA,cAAA,EACA,EAAA,EACA,MAAA,EACA;AACA,EAAA,OAAO,OAAO,aAAA,CAAc;AAAA,IAC1B,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,OAAA,EAAS,eAAe,MAAM,CAAA;AAAA,IAC9B,GAAG,YAAA,CAAa,cAAA,EAAgB,EAAA,EAAI,MAAM;AAAA,GAC3C,CAAA;AACH;AAEO,SAAS,oBAAA,CACd,MAAA,EACA,cAAA,EACA,EAAA,EACA,QACA,KAAA,EACA;AACA,EAAA,OAAO,OAAO,aAAA,CAAc;AAAA,IAC1B,OAAO,MAAA,CAAO,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 { EIP1193Provider, PublicClient, WalletClient } from \"viem\";\nimport { writeContract } from \"viem/actions\";\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\";\n\n/**\n * Configuration for {@link ViemSigner}.\n *\n * The optional `ethereum` field is needed for `subscribe()` (EIP-1193\n * `accountsChanged` / `disconnect` events). It cannot be auto-extracted from\n * `walletClient` because viem's `custom(ethereum)` transport captures the\n * provider in a closure and does **not** expose `on` / `removeListener` on\n * `walletClient.transport`.\n *\n * If you omit `ethereum`, `subscribe()` returns a no-op. For automatic\n * wallet lifecycle handling, consider using `WagmiSigner` instead.\n */\nexport interface ViemSignerConfig {\n walletClient: WalletClient;\n publicClient: PublicClient;\n ethereum?: EIP1193Provider;\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 private readonly ethereum?: EIP1193Provider;\n\n constructor(config: ViemSignerConfig) {\n this.walletClient = config.walletClient;\n this.publicClient = config.publicClient;\n this.ethereum = config.ethereum;\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 subscribe(callbacks: SignerLifecycleCallbacks): () => void {\n return eip1193Subscribe(this.ethereum, () => this.getAddress(), callbacks);\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,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zama-fhe/sdk",
|
|
3
|
+
"version": "1.0.0-alpha.10",
|
|
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
|
+
"./cleartext": {
|
|
21
|
+
"types": "./dist/cleartext/index.d.ts",
|
|
22
|
+
"import": "./dist/cleartext/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./viem": {
|
|
25
|
+
"types": "./dist/viem/index.d.ts",
|
|
26
|
+
"import": "./dist/viem/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./ethers": {
|
|
29
|
+
"types": "./dist/ethers/index.d.ts",
|
|
30
|
+
"import": "./dist/ethers/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./node": {
|
|
33
|
+
"types": "./dist/node/index.d.ts",
|
|
34
|
+
"import": "./dist/node/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"fhe",
|
|
47
|
+
"zama",
|
|
48
|
+
"fhevm",
|
|
49
|
+
"confidential",
|
|
50
|
+
"erc20",
|
|
51
|
+
"privacy",
|
|
52
|
+
"homomorphic-encryption",
|
|
53
|
+
"token",
|
|
54
|
+
"ethereum",
|
|
55
|
+
"blockchain"
|
|
56
|
+
],
|
|
57
|
+
"homepage": "https://github.com/zama-ai/sdk#readme",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/zama-ai/sdk/issues"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsup",
|
|
63
|
+
"lint": "eslint .",
|
|
64
|
+
"typecheck": "tsc --noEmit"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@zama-fhe/relayer-sdk": "0.4.1",
|
|
68
|
+
"tsup": "^8.5.1"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"viem": ">=2",
|
|
72
|
+
"ethers": ">=6",
|
|
73
|
+
"@zama-fhe/relayer-sdk": "~0.4.1"
|
|
74
|
+
},
|
|
75
|
+
"sideEffects": false,
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"viem": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"ethers": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"@zama-fhe/relayer-sdk": {
|
|
84
|
+
"optional": true
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"engines": {
|
|
88
|
+
"node": ">=22"
|
|
89
|
+
}
|
|
90
|
+
}
|