@invisi-labs/sdk 1.1.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.
@@ -0,0 +1,351 @@
1
+ // src/integrations/ethers.ts
2
+ import {
3
+ Contract,
4
+ zeroPadValue,
5
+ TypedDataEncoder,
6
+ verifyTypedData,
7
+ getAddress as ethersAddress,
8
+ getBytes,
9
+ keccak256,
10
+ isError
11
+ } from "ethers";
12
+ import {
13
+ invisiProtocolAbi,
14
+ invisiAddressRegistryAbi,
15
+ invisiFactoryAbi
16
+ } from "@invisi-labs/protocol/contracts";
17
+ import { ReceivingAddress } from "@invisi-labs/core/address";
18
+ var getAddress = (value) => ethersAddress(value);
19
+ var erc1271Abi = [
20
+ "function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)"
21
+ ];
22
+ function fundingTypes(data) {
23
+ const types = Object.fromEntries(
24
+ Object.entries(data.types).map(([name, fields]) => [name, [...fields]])
25
+ );
26
+ check(
27
+ TypedDataEncoder.from(types).primaryType === data.primaryType,
28
+ "funding typed-data primary type mismatch"
29
+ );
30
+ return types;
31
+ }
32
+ function check(value, message) {
33
+ if (!value) {
34
+ throw new Error(message);
35
+ }
36
+ }
37
+ async function chain(client, expected) {
38
+ check((await client.getNetwork()).chainId === expected, "EVM client chain mismatch");
39
+ }
40
+ function number(value) {
41
+ check(typeof value === "bigint" && value >= 0n, "invalid chain integer");
42
+ return value;
43
+ }
44
+ function boolean(value) {
45
+ check(typeof value === "boolean", "invalid chain boolean");
46
+ return value;
47
+ }
48
+ function word(value) {
49
+ check(typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value), "invalid chain word");
50
+ return value.toLowerCase();
51
+ }
52
+ function ownerWord(value) {
53
+ const identity = ReceivingAddress.fromIdentity(value).walletIdentity;
54
+ return zeroPadValue(identity, 32);
55
+ }
56
+ var EthersChainReader = class {
57
+ constructor(client) {
58
+ this.client = client;
59
+ }
60
+ async getChainId() {
61
+ return (await this.client.getNetwork()).chainId;
62
+ }
63
+ async getProtocolVersion(address) {
64
+ return BigInt(
65
+ await new Contract(getAddress(address), invisiProtocolAbi, this.client).getFunction(
66
+ "VERSION"
67
+ )()
68
+ );
69
+ }
70
+ async getCode(address) {
71
+ return await this.client.getCode(getAddress(address));
72
+ }
73
+ async getFactoryInstanceAddress(factory, salt) {
74
+ return getAddress(
75
+ await new Contract(factory, invisiFactoryAbi, this.client).getFunction(
76
+ "getInstanceAddress"
77
+ )(salt)
78
+ );
79
+ }
80
+ async isFactoryInstance(factory, instance) {
81
+ return boolean(
82
+ await new Contract(factory, invisiFactoryAbi, this.client).getFunction("isInstance")(
83
+ instance
84
+ )
85
+ );
86
+ }
87
+ async getInstanceFactory(instance) {
88
+ return getAddress(
89
+ await new Contract(instance, invisiProtocolAbi, this.client).getFunction("factory")()
90
+ );
91
+ }
92
+ async getLatestBlockNumber() {
93
+ return BigInt(await this.client.getBlockNumber());
94
+ }
95
+ async getBlock(blockNumber) {
96
+ const block = await this.client.getBlock(blockNumber);
97
+ check(
98
+ block && BigInt(block.number) === blockNumber && block.hash && block.parentHash,
99
+ "invalid canonical block"
100
+ );
101
+ return {
102
+ number: BigInt(block.number),
103
+ hash: word(block.hash),
104
+ parentHash: word(block.parentHash),
105
+ timestamp: number(BigInt(block.timestamp))
106
+ };
107
+ }
108
+ async read(context, address, abi, functionName, args, block) {
109
+ await chain(this.client, context.chainId);
110
+ if (block) {
111
+ check(
112
+ (await this.getBlock(block.number)).hash === block.hash,
113
+ "canonical read block mismatch"
114
+ );
115
+ }
116
+ return new Contract(getAddress(address), abi, this.client).getFunction(functionName)(
117
+ ...args,
118
+ ...block ? [{ blockTag: block.number }] : []
119
+ );
120
+ }
121
+ async getFundingNonce(context, payer, block) {
122
+ return number(
123
+ await this.read(
124
+ context,
125
+ context.protocolAddress,
126
+ invisiProtocolAbi,
127
+ "nonces",
128
+ [getAddress(payer)],
129
+ block
130
+ )
131
+ );
132
+ }
133
+ async getRegistryNonce(context, walletIdentity, block) {
134
+ return number(
135
+ await this.read(
136
+ context,
137
+ context.registryAddress,
138
+ invisiAddressRegistryAbi,
139
+ "nonceOf",
140
+ [ownerWord(walletIdentity)],
141
+ block
142
+ )
143
+ );
144
+ }
145
+ async isKnownRoot(context, treeId, root, block) {
146
+ return boolean(
147
+ await this.read(
148
+ context,
149
+ context.protocolAddress,
150
+ invisiProtocolAbi,
151
+ "rootHistory",
152
+ [number(treeId), word(root)],
153
+ block
154
+ )
155
+ );
156
+ }
157
+ async isSpent(context, nullifiers, block) {
158
+ const copied = nullifiers.map(word);
159
+ const result = [];
160
+ for (let offset = 0; offset < copied.length; offset += 32) {
161
+ result.push(
162
+ ...await Promise.all(
163
+ copied.slice(offset, offset + 32).map(
164
+ (nf) => this.read(
165
+ context,
166
+ context.protocolAddress,
167
+ invisiProtocolAbi,
168
+ "isNullifierSpent",
169
+ [nf],
170
+ block
171
+ ).then(boolean)
172
+ )
173
+ )
174
+ );
175
+ }
176
+ return result;
177
+ }
178
+ async getTransaction(hash) {
179
+ try {
180
+ const tx = await this.client.getTransaction(word(hash));
181
+ if (!tx?.to) {
182
+ return null;
183
+ }
184
+ return {
185
+ transactionHash: word(tx.hash),
186
+ to: getAddress(tx.to),
187
+ from: getAddress(tx.from),
188
+ nonce: number(BigInt(tx.nonce)),
189
+ data: tx.data,
190
+ value: number(tx.value)
191
+ };
192
+ } catch (error) {
193
+ if (error instanceof Error && error.name === "TransactionNotFoundError") {
194
+ return null;
195
+ }
196
+ throw error;
197
+ }
198
+ }
199
+ async getReceipt(hash) {
200
+ try {
201
+ const receipt = await this.client.getTransactionReceipt(word(hash));
202
+ if (!receipt) return null;
203
+ const block = await this.getBlock(BigInt(receipt.blockNumber));
204
+ check(block.hash === receipt.blockHash, "receipt block is no longer canonical");
205
+ return {
206
+ block,
207
+ transactionHash: word(receipt.hash),
208
+ status: receipt.status === 1 ? "success" : "reverted",
209
+ logs: receipt.logs.map((log) => {
210
+ check(
211
+ !log.removed && log.transactionHash === receipt.hash && log.index !== null,
212
+ "invalid receipt log"
213
+ );
214
+ return {
215
+ address: getAddress(log.address),
216
+ data: log.data,
217
+ topics: [...log.topics],
218
+ transactionHash: word(log.transactionHash),
219
+ logIndex: log.index
220
+ };
221
+ })
222
+ };
223
+ } catch (error) {
224
+ if (error instanceof Error && error.name === "TransactionReceiptNotFoundError") {
225
+ return null;
226
+ }
227
+ throw error;
228
+ }
229
+ }
230
+ };
231
+ var EthersAddressResolver = class {
232
+ constructor(client, context, expectedRuntimeCodeHash) {
233
+ this.client = client;
234
+ this.expectedRuntimeCodeHash = expectedRuntimeCodeHash;
235
+ this.#context = Object.freeze({
236
+ ...context,
237
+ registryAddress: getAddress(context.registryAddress)
238
+ });
239
+ check(BigInt(context.registryAddress) !== 0n, "invalid registry address");
240
+ }
241
+ #context;
242
+ lookup = async (walletIdentity) => {
243
+ await chain(this.client, this.#context.chainId);
244
+ if (this.expectedRuntimeCodeHash) {
245
+ const code = await this.client.getCode(this.#context.registryAddress);
246
+ check(
247
+ code !== "0x" && keccak256(code) === this.expectedRuntimeCodeHash,
248
+ "registry runtime profile mismatch"
249
+ );
250
+ }
251
+ const block = await this.client.getBlock("latest");
252
+ check(block && block.hash, "invalid registry block");
253
+ const contract = new Contract(
254
+ this.#context.registryAddress,
255
+ invisiAddressRegistryAbi,
256
+ this.client
257
+ );
258
+ const registered = await contract.getFunction("isRegistered")(ownerWord(walletIdentity), {
259
+ blockTag: block.number
260
+ });
261
+ if (!registered) return null;
262
+ const [keys] = await contract.getFunction("receivingKeysOf")(ownerWord(walletIdentity), {
263
+ blockTag: block.number
264
+ });
265
+ check(
266
+ (await this.client.getBlock(block.number))?.hash === block.hash,
267
+ "canonical registry read changed"
268
+ );
269
+ return ReceivingAddress.from({
270
+ walletIdentity,
271
+ viewingPublicKey: getBytes(keys.viewingPublicKey),
272
+ clueKey: getBytes(keys.clueKey)
273
+ }).getReceivingKeys();
274
+ };
275
+ };
276
+ var EthersFundingSigner = class _EthersFundingSigner {
277
+ constructor(signer, chainId, address) {
278
+ this.signer = signer;
279
+ this.chainId = chainId;
280
+ this.address = getAddress(address);
281
+ }
282
+ address;
283
+ static async create(signer, chainId) {
284
+ return new _EthersFundingSigner(signer, chainId, getAddress(await signer.getAddress()));
285
+ }
286
+ async signTypedData(data) {
287
+ const copied = structuredClone(data);
288
+ check(
289
+ BigInt(copied.domain.chainId) === this.chainId,
290
+ "funding typed-data chain mismatch"
291
+ );
292
+ check(
293
+ getAddress(await this.signer.getAddress()) === this.address,
294
+ "funding signer address mismatch"
295
+ );
296
+ if (this.signer.provider) await chain(this.signer.provider, this.chainId);
297
+ return await this.signer.signTypedData(
298
+ copied.domain,
299
+ fundingTypes(copied),
300
+ copied.message
301
+ );
302
+ }
303
+ };
304
+ var EthersFundingVerifier = class {
305
+ constructor(client, chainId) {
306
+ this.client = client;
307
+ this.chainId = chainId;
308
+ }
309
+ async verifyTypedData(data) {
310
+ const copied = structuredClone(data);
311
+ check(
312
+ BigInt(copied.domain.chainId) === this.chainId,
313
+ "funding typed-data chain mismatch"
314
+ );
315
+ await chain(this.client, this.chainId);
316
+ const address = getAddress(copied.address);
317
+ if (await this.client.getCode(address) === "0x") {
318
+ try {
319
+ return getAddress(
320
+ verifyTypedData(
321
+ copied.domain,
322
+ fundingTypes(copied),
323
+ copied.message,
324
+ copied.signature
325
+ )
326
+ ) === address;
327
+ } catch {
328
+ return false;
329
+ }
330
+ }
331
+ try {
332
+ return await new Contract(address, erc1271Abi, this.client).getFunction(
333
+ "isValidSignature"
334
+ )(
335
+ TypedDataEncoder.hash(copied.domain, fundingTypes(copied), copied.message),
336
+ copied.signature
337
+ ) === "0x1626ba7e";
338
+ } catch (error) {
339
+ if (isError(error, "CALL_EXCEPTION")) return false;
340
+ throw error;
341
+ }
342
+ }
343
+ };
344
+
345
+ export {
346
+ EthersChainReader,
347
+ EthersAddressResolver,
348
+ EthersFundingSigner,
349
+ EthersFundingVerifier
350
+ };
351
+ //# sourceMappingURL=chunk-NAEEEZMH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/integrations/ethers.ts"],"sourcesContent":["import {\n Contract,\n zeroPadValue,\n Interface,\n TypedDataEncoder,\n verifyTypedData,\n getAddress as ethersAddress,\n getBytes,\n keccak256,\n isError,\n type Provider,\n type Signer,\n} from \"ethers\";\nimport type { Address, Hex } from \"@invisi-labs/protocol/contracts\";\nconst getAddress = (value: string): Address => ethersAddress(value) as Address;\nimport {\n invisiProtocolAbi,\n invisiAddressRegistryAbi,\n invisiFactoryAbi,\n} from \"@invisi-labs/protocol/contracts\";\nimport { ReceivingAddress, type ReceivingKeyLookup } from \"@invisi-labs/core/address\";\nimport type {\n ChainReader,\n FactoryReader,\n RegistryReader,\n RegistryContext,\n TransactionContext,\n DeploymentContext,\n CanonicalBlock,\n CanonicalReceipt,\n} from \"@invisi-labs/protocol\";\nimport type { FundingSigner, FundingTypedData, FundingAuthorizationVerifier } from \"../session\";\n\nconst erc1271Abi = [\n \"function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)\",\n];\nfunction fundingTypes(data: FundingTypedData) {\n const types = Object.fromEntries(\n Object.entries(data.types).map(([name, fields]) => [name, [...fields]])\n );\n check(\n TypedDataEncoder.from(types).primaryType === data.primaryType,\n \"funding typed-data primary type mismatch\"\n );\n return types;\n}\n\nfunction check(value: unknown, message: string): asserts value {\n if (!value) {\n throw new Error(message);\n }\n}\n\nasync function chain(client: Provider, expected: bigint): Promise<void> {\n check((await client.getNetwork()).chainId === expected, \"EVM client chain mismatch\");\n}\n\nfunction number(value: unknown): bigint {\n check(typeof value === \"bigint\" && value >= 0n, \"invalid chain integer\");\n return value;\n}\n\nfunction boolean(value: unknown): boolean {\n check(typeof value === \"boolean\", \"invalid chain boolean\");\n return value;\n}\n\nfunction word(value: unknown): Hex {\n check(typeof value === \"string\" && /^0x[0-9a-fA-F]{64}$/.test(value), \"invalid chain word\");\n return value.toLowerCase() as Hex;\n}\n\nfunction ownerWord(value: Hex): Hex {\n // Public owners use canonical EVM addresses; registry slots remain bytes32.\n const identity = ReceivingAddress.fromIdentity(value).walletIdentity;\n return zeroPadValue(identity, 32) as Hex;\n}\n\n/** Reads exact block numbers; higher layers additionally enforce post-read snapshot barriers. */\nexport class EthersChainReader implements ChainReader, RegistryReader, FactoryReader {\n constructor(readonly client: Provider) {}\n\n async getChainId() {\n return (await this.client.getNetwork()).chainId;\n }\n\n async getProtocolVersion(address: Address): Promise<bigint> {\n return BigInt(\n await new Contract(getAddress(address), invisiProtocolAbi, this.client).getFunction(\n \"VERSION\"\n )()\n );\n }\n\n async getCode(address: Address): Promise<Hex> {\n return (await this.client.getCode(getAddress(address))) as Hex;\n }\n\n async getFactoryInstanceAddress(factory: Address, salt: Hex): Promise<Address> {\n return getAddress(\n await new Contract(factory, invisiFactoryAbi, this.client).getFunction(\n \"getInstanceAddress\"\n )(salt)\n );\n }\n async isFactoryInstance(factory: Address, instance: Address): Promise<boolean> {\n return boolean(\n await new Contract(factory, invisiFactoryAbi, this.client).getFunction(\"isInstance\")(\n instance\n )\n );\n }\n async getInstanceFactory(instance: Address): Promise<Address> {\n return getAddress(\n await new Contract(instance, invisiProtocolAbi, this.client).getFunction(\"factory\")()\n );\n }\n async getLatestBlockNumber() {\n return BigInt(await this.client.getBlockNumber());\n }\n\n async getBlock(blockNumber: bigint): Promise<CanonicalBlock> {\n const block = await this.client.getBlock(blockNumber);\n check(\n block && BigInt(block.number) === blockNumber && block.hash && block.parentHash,\n \"invalid canonical block\"\n );\n return {\n number: BigInt(block.number),\n hash: word(block.hash),\n parentHash: word(block.parentHash),\n timestamp: number(BigInt(block.timestamp)),\n };\n }\n\n private async read(\n context: { chainId: bigint },\n address: Address,\n abi: ConstructorParameters<typeof Interface>[0],\n functionName: string,\n args: readonly unknown[],\n block?: CanonicalBlock\n ): Promise<unknown> {\n await chain(this.client, context.chainId);\n if (block) {\n check(\n (await this.getBlock(block.number)).hash === block.hash,\n \"canonical read block mismatch\"\n );\n }\n return new Contract(getAddress(address), abi, this.client).getFunction(functionName)(\n ...args,\n ...(block ? [{ blockTag: block.number }] : [])\n );\n }\n\n async getFundingNonce(context: DeploymentContext, payer: Address, block: CanonicalBlock) {\n return number(\n await this.read(\n context,\n context.protocolAddress,\n invisiProtocolAbi,\n \"nonces\",\n [getAddress(payer)],\n block\n )\n );\n }\n\n async getRegistryNonce(context: RegistryContext, walletIdentity: Hex, block: CanonicalBlock) {\n return number(\n await this.read(\n context,\n context.registryAddress,\n invisiAddressRegistryAbi,\n \"nonceOf\",\n [ownerWord(walletIdentity)],\n block\n )\n );\n }\n\n async isKnownRoot(\n context: DeploymentContext,\n treeId: bigint,\n root: Hex,\n block: CanonicalBlock\n ) {\n return boolean(\n await this.read(\n context,\n context.protocolAddress,\n invisiProtocolAbi,\n \"rootHistory\",\n [number(treeId), word(root)],\n block\n )\n );\n }\n\n async isSpent(context: DeploymentContext, nullifiers: readonly Hex[], block: CanonicalBlock) {\n const copied = nullifiers.map(word);\n const result: boolean[] = [];\n for (let offset = 0; offset < copied.length; offset += 32) {\n result.push(\n ...(await Promise.all(\n copied\n .slice(offset, offset + 32)\n .map((nf) =>\n this.read(\n context,\n context.protocolAddress,\n invisiProtocolAbi,\n \"isNullifierSpent\",\n [nf],\n block\n ).then(boolean)\n )\n ))\n );\n }\n return result;\n }\n\n async getTransaction(hash: Hex) {\n try {\n const tx = await this.client.getTransaction(word(hash));\n if (!tx?.to) {\n return null;\n }\n return {\n transactionHash: word(tx.hash),\n to: getAddress(tx.to),\n from: getAddress(tx.from),\n nonce: number(BigInt(tx.nonce)),\n data: tx.data as Hex,\n value: number(tx.value),\n };\n } catch (error) {\n if (error instanceof Error && error.name === \"TransactionNotFoundError\") {\n return null;\n }\n throw error;\n }\n }\n\n async getReceipt(hash: Hex): Promise<CanonicalReceipt | null> {\n try {\n const receipt = await this.client.getTransactionReceipt(word(hash));\n if (!receipt) return null;\n const block = await this.getBlock(BigInt(receipt.blockNumber));\n check(block.hash === receipt.blockHash, \"receipt block is no longer canonical\");\n return {\n block,\n transactionHash: word(receipt.hash),\n status: receipt.status === 1 ? \"success\" : \"reverted\",\n logs: receipt.logs.map((log) => {\n check(\n !log.removed && log.transactionHash === receipt.hash && log.index !== null,\n \"invalid receipt log\"\n );\n return {\n address: getAddress(log.address),\n data: log.data as Hex,\n topics: [...log.topics] as Hex[],\n transactionHash: word(log.transactionHash),\n logIndex: log.index,\n };\n }),\n };\n } catch (error) {\n if (error instanceof Error && error.name === \"TransactionReceiptNotFoundError\") {\n return null;\n }\n throw error;\n }\n }\n}\n\n/** Resolves only the explicitly selected registry. Validates canonical public key encodings. */\nexport class EthersAddressResolver {\n readonly #context: Readonly<RegistryContext>;\n\n constructor(\n readonly client: Provider,\n context: RegistryContext,\n readonly expectedRuntimeCodeHash?: Hex\n ) {\n this.#context = Object.freeze({\n ...context,\n registryAddress: getAddress(context.registryAddress),\n });\n check(BigInt(context.registryAddress) !== 0n, \"invalid registry address\");\n }\n\n readonly lookup: ReceivingKeyLookup = async (walletIdentity) => {\n await chain(this.client, this.#context.chainId);\n if (this.expectedRuntimeCodeHash) {\n const code = await this.client.getCode(this.#context.registryAddress);\n check(\n code !== \"0x\" && keccak256(code) === this.expectedRuntimeCodeHash,\n \"registry runtime profile mismatch\"\n );\n }\n const block = await this.client.getBlock(\"latest\");\n check(block && block.hash, \"invalid registry block\");\n const contract = new Contract(\n this.#context.registryAddress,\n invisiAddressRegistryAbi,\n this.client\n );\n const registered = await contract.getFunction(\"isRegistered\")(ownerWord(walletIdentity), {\n blockTag: block.number,\n });\n if (!registered) return null;\n const [keys] = await contract.getFunction(\"receivingKeysOf\")(ownerWord(walletIdentity), {\n blockTag: block.number,\n });\n check(\n (await this.client.getBlock(block.number))?.hash === block.hash,\n \"canonical registry read changed\"\n );\n return ReceivingAddress.from({\n walletIdentity,\n viewingPublicKey: getBytes(keys.viewingPublicKey),\n clueKey: getBytes(keys.clueKey),\n }).getReceivingKeys();\n };\n}\n\nexport class EthersFundingSigner implements FundingSigner {\n readonly address: Address;\n constructor(\n readonly signer: Signer,\n readonly chainId: bigint,\n address: Address\n ) {\n this.address = getAddress(address);\n }\n static async create(signer: Signer, chainId: bigint): Promise<EthersFundingSigner> {\n return new EthersFundingSigner(signer, chainId, getAddress(await signer.getAddress()));\n }\n async signTypedData(data: FundingTypedData): Promise<Hex> {\n const copied = structuredClone(data);\n check(\n BigInt(copied.domain.chainId as bigint) === this.chainId,\n \"funding typed-data chain mismatch\"\n );\n check(\n getAddress(await this.signer.getAddress()) === this.address,\n \"funding signer address mismatch\"\n );\n if (this.signer.provider) await chain(this.signer.provider, this.chainId);\n return (await this.signer.signTypedData(\n copied.domain,\n fundingTypes(copied),\n copied.message\n )) as Hex;\n }\n}\n\nexport class EthersFundingVerifier implements FundingAuthorizationVerifier {\n constructor(\n readonly client: Provider,\n readonly chainId: bigint\n ) {}\n async verifyTypedData(\n data: FundingTypedData & { address: Address; signature: Hex }\n ): Promise<boolean> {\n const copied = structuredClone(data);\n check(\n BigInt(copied.domain.chainId as bigint) === this.chainId,\n \"funding typed-data chain mismatch\"\n );\n await chain(this.client, this.chainId);\n const address = getAddress(copied.address);\n if ((await this.client.getCode(address)) === \"0x\") {\n try {\n return (\n getAddress(\n verifyTypedData(\n copied.domain,\n fundingTypes(copied),\n copied.message,\n copied.signature\n )\n ) === address\n );\n } catch {\n return false;\n }\n }\n try {\n return (\n (await new Contract(address, erc1271Abi, this.client).getFunction(\n \"isValidSignature\"\n )(\n TypedDataEncoder.hash(copied.domain, fundingTypes(copied), copied.message),\n copied.signature\n )) === \"0x1626ba7e\"\n );\n } catch (error) {\n if (isError(error, \"CALL_EXCEPTION\")) return false;\n throw error;\n }\n }\n}\n"],"mappings":";AAAA;AAAA,EACI;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,OAGG;AAGP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAC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