@invisi-labs/sdk 1.1.7 → 1.2.1

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.
Files changed (118) hide show
  1. package/README.md +5 -0
  2. package/dist/broadcaster-3KTB4JO2.cjs +21 -0
  3. package/dist/broadcaster-3KTB4JO2.cjs.map +1 -0
  4. package/dist/broadcaster-7ZKKSTZQ.js +21 -0
  5. package/dist/broadcaster-preparation-PJ263WBL.cjs +15 -0
  6. package/dist/broadcaster-preparation-PJ263WBL.cjs.map +1 -0
  7. package/dist/broadcaster-preparation-ZQAPZAUG.js +15 -0
  8. package/dist/broadcaster-preparation-ZQAPZAUG.js.map +1 -0
  9. package/dist/{chunk-LOU7AP2B.cjs → chunk-2URICDPW.cjs} +72 -33
  10. package/dist/chunk-2URICDPW.cjs.map +1 -0
  11. package/dist/chunk-3D24ABYR.js +86 -0
  12. package/dist/chunk-3D24ABYR.js.map +1 -0
  13. package/dist/chunk-3KTQQZOW.cjs +71 -0
  14. package/dist/chunk-3KTQQZOW.cjs.map +1 -0
  15. package/dist/chunk-4SDP53YQ.cjs +765 -0
  16. package/dist/chunk-4SDP53YQ.cjs.map +1 -0
  17. package/dist/{chunk-XHKQ2BO2.js → chunk-4VI6LYGH.js} +25 -2
  18. package/dist/chunk-4VI6LYGH.js.map +1 -0
  19. package/dist/chunk-BBSRP4MH.cjs +287 -0
  20. package/dist/chunk-BBSRP4MH.cjs.map +1 -0
  21. package/dist/chunk-DGMVGFKM.js +41 -0
  22. package/dist/chunk-DGMVGFKM.js.map +1 -0
  23. package/dist/chunk-DHQEB6JR.cjs +1616 -0
  24. package/dist/chunk-DHQEB6JR.cjs.map +1 -0
  25. package/dist/chunk-FKF67XE6.js +1616 -0
  26. package/dist/chunk-FKF67XE6.js.map +1 -0
  27. package/dist/chunk-GUD3LAUO.js +765 -0
  28. package/dist/chunk-GUD3LAUO.js.map +1 -0
  29. package/dist/chunk-HCB7RQ3S.cjs +79 -0
  30. package/dist/chunk-HCB7RQ3S.cjs.map +1 -0
  31. package/dist/{chunk-GTPUYPQL.js → chunk-HKGJXQVN.js} +69 -30
  32. package/dist/chunk-HKGJXQVN.js.map +1 -0
  33. package/dist/chunk-HLH5JZD4.js +287 -0
  34. package/dist/chunk-HLH5JZD4.js.map +1 -0
  35. package/dist/chunk-J6TZZVAM.cjs +230 -0
  36. package/dist/chunk-J6TZZVAM.cjs.map +1 -0
  37. package/dist/{chunk-7F7ZZW3L.cjs → chunk-LOR6PYH5.cjs} +25 -2
  38. package/dist/chunk-LOR6PYH5.cjs.map +1 -0
  39. package/dist/chunk-MA2QZEF5.cjs +399 -0
  40. package/dist/chunk-MA2QZEF5.cjs.map +1 -0
  41. package/dist/chunk-MI4IP4ZD.cjs +86 -0
  42. package/dist/chunk-MI4IP4ZD.cjs.map +1 -0
  43. package/dist/chunk-OCZLJKIA.cjs +41 -0
  44. package/dist/chunk-OCZLJKIA.cjs.map +1 -0
  45. package/dist/chunk-R5YAOJKB.js +71 -0
  46. package/dist/chunk-R5YAOJKB.js.map +1 -0
  47. package/dist/chunk-RY4M2CIQ.js +399 -0
  48. package/dist/chunk-RY4M2CIQ.js.map +1 -0
  49. package/dist/chunk-THMD5QO2.js +79 -0
  50. package/dist/chunk-THMD5QO2.js.map +1 -0
  51. package/dist/chunk-ZD2652WH.js +230 -0
  52. package/dist/chunk-ZD2652WH.js.map +1 -0
  53. package/dist/credit.cjs +1 -0
  54. package/dist/credit.cjs.map +1 -0
  55. package/dist/credit.d.cts +12 -0
  56. package/dist/credit.d.ts +12 -0
  57. package/dist/credit.js +1 -0
  58. package/dist/credit.js.map +1 -0
  59. package/dist/ethers.cjs +2 -2
  60. package/dist/ethers.cjs.map +1 -1
  61. package/dist/ethers.d.cts +15 -4
  62. package/dist/ethers.d.ts +15 -4
  63. package/dist/ethers.js +1 -1
  64. package/dist/index-CLhGwLxZ.d.cts +42 -0
  65. package/dist/index-Crp-ZFiM.d.ts +42 -0
  66. package/dist/index.cjs +69 -38
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.cts +21 -14
  69. package/dist/index.d.ts +21 -14
  70. package/dist/index.js +64 -33
  71. package/dist/index.js.map +1 -1
  72. package/dist/note.cjs +11 -0
  73. package/dist/note.cjs.map +1 -0
  74. package/dist/note.d.cts +29 -0
  75. package/dist/note.d.ts +29 -0
  76. package/dist/note.js +11 -0
  77. package/dist/note.js.map +1 -0
  78. package/dist/{broadcaster-preparation-DMxxZ_1Q.d.cts → operation-bridge-CoECSxfi.d.cts} +130 -245
  79. package/dist/{broadcaster-preparation-DMxxZ_1Q.d.ts → operation-bridge-CoECSxfi.d.ts} +130 -245
  80. package/dist/preparation-HUBTVCZE.js +404 -0
  81. package/dist/preparation-HUBTVCZE.js.map +1 -0
  82. package/dist/preparation-QD3ZSYV5.cjs +404 -0
  83. package/dist/preparation-QD3ZSYV5.cjs.map +1 -0
  84. package/dist/provenance-preparation-43DN2WK7.cjs +16 -0
  85. package/dist/provenance-preparation-43DN2WK7.cjs.map +1 -0
  86. package/dist/provenance-preparation-HEZE4L5H.js +16 -0
  87. package/dist/provenance-preparation-HEZE4L5H.js.map +1 -0
  88. package/dist/provenance.cjs +59 -0
  89. package/dist/provenance.cjs.map +1 -0
  90. package/dist/provenance.d.cts +34 -0
  91. package/dist/provenance.d.ts +34 -0
  92. package/dist/provenance.js +59 -0
  93. package/dist/provenance.js.map +1 -0
  94. package/dist/{receipt-logs-m0-bhaxW.d.ts → receipt-logs-DQRJK0l8.d.cts} +84 -78
  95. package/dist/{receipt-logs-CvC951p7.d.cts → receipt-logs-fMR6Bwql.d.ts} +84 -78
  96. package/dist/session-support.cjs +28 -7
  97. package/dist/session-support.cjs.map +1 -1
  98. package/dist/session-support.d.cts +71 -39
  99. package/dist/session-support.d.ts +71 -39
  100. package/dist/session-support.js +58 -37
  101. package/dist/session-support.js.map +1 -1
  102. package/package.json +22 -6
  103. package/dist/broadcaster-preparation-RMWQFYNL.js +0 -11
  104. package/dist/broadcaster-preparation-UGOTO4SX.cjs +0 -11
  105. package/dist/broadcaster-preparation-UGOTO4SX.cjs.map +0 -1
  106. package/dist/chunk-7F7ZZW3L.cjs.map +0 -1
  107. package/dist/chunk-EHP5TBC6.js +0 -3565
  108. package/dist/chunk-EHP5TBC6.js.map +0 -1
  109. package/dist/chunk-GTPUYPQL.js.map +0 -1
  110. package/dist/chunk-ITTGBIG2.js +0 -1877
  111. package/dist/chunk-ITTGBIG2.js.map +0 -1
  112. package/dist/chunk-J2JH6HIG.cjs +0 -1877
  113. package/dist/chunk-J2JH6HIG.cjs.map +0 -1
  114. package/dist/chunk-LOU7AP2B.cjs.map +0 -1
  115. package/dist/chunk-RHNIHI4P.cjs +0 -3565
  116. package/dist/chunk-RHNIHI4P.cjs.map +0 -1
  117. package/dist/chunk-XHKQ2BO2.js.map +0 -1
  118. /package/dist/{broadcaster-preparation-RMWQFYNL.js.map → broadcaster-7ZKKSTZQ.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/wx/Workspace/invisi-lab/invisi-sdk-ts/packages/sdk/dist/chunk-LOR6PYH5.cjs","../src/integrations/ethers.ts"],"names":[],"mappings":"AAAA;ACAA,0DAA0D;AAW1D;AACI;AACA;AACA;AAAA,4DACG;AACP;AACI;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,gCAGG;AAMP,IAAM,WAAA,EAAa,CAAC,KAAA,EAAA,GAA2B,gCAAA,KAAmB,CAAA;AAElE,IAAM,WAAA,EAAa;AAAA,EACf;AACJ,CAAA;AACA,SAAS,YAAA,CAAa,IAAA,EAAwB;AAC1C,EAAA,MAAM,MAAA,EAAQ,MAAA,CAAO,WAAA;AAAA,IACjB,MAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,KAAK,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,EAAA,GAAM,CAAC,IAAA,EAAM,CAAC,GAAG,MAAM,CAAC,CAAC;AA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,IAAA,CAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,EAAA,IAAO,IAAA,EAAM;AAC/C,MAAA,IAAI;AACA,QAAA,OACI,UAAA;AAAA,UACI,qCAAA;AAAA,YACI,MAAA,CAAO,MAAA;AAAA,YACP,YAAA,CAAa,MAAM,CAAA;AAAA,YACnB,MAAA,CAAO,OAAA;AAAA,YACP,MAAA,CAAO;AAAA,UACX;AAAA,QACJ,EAAA,IAAM,OAAA;AAAA,MAEd,EAAA,UAAQ;AACJ,QAAA,OAAO,KAAA;AAAA,MACX;AAAA,IACJ;AACA,IAAA,IAAI;AACA,MAAA,OACK,MAAM,IAAI,qBAAA,CAAS,OAAA,EAAS,UAAA,EAAY,IAAA,CAAK,MAAM,CAAA,CAAE,WAAA;AAAA,QAClD;AAAA,MACJ,CAAA;AAAA,QACI,wBAAA,CAAiB,IAAA,CAAK,MAAA,CAAO,MAAA,EAAQ,YAAA,CAAa,MAAM,CAAA,EAAG,MAAA,CAAO,OAAO,CAAA;AAAA,QACzE,MAAA,CAAO;AAAA,MACX,EAAA,IAAO,YAAA;AAAA,IAEf,EAAA,MAAA,CAAS,KAAA,EAAO;AACZ,MAAA,GAAA,CAAI,6BAAA,KAAQ,EAAO,gBAAgB,CAAA,EAAG,OAAO,KAAA;AAC7C,MAAA,MAAM,KAAA;AAAA,IACV;AAAA,EACJ;AACJ,CAAA;ADvFA;AACA;AACE;AACA;AACA;AACA;AACF,+MAAC","file":"/Users/wx/Workspace/invisi-lab/invisi-sdk-ts/packages/sdk/dist/chunk-LOR6PYH5.cjs","sourcesContent":[null,"import { ReceivingAddress, type ReceivingKeyLookup } from \"@invisi-labs/primitives/address\";\nimport type {\n CanonicalBlock,\n CanonicalReceipt,\n ChainReader,\n DeploymentContext,\n FactoryReader,\n RegistryContext,\n} from \"@invisi-labs/protocol\";\nimport type { RegistryReader } from \"@invisi-labs/rpc\";\nimport type { Address, Hex } from \"@invisi-labs/protocol/contracts\";\nimport {\n invisiAddressRegistryAbi,\n invisiFactoryAbi,\n invisiProtocolAbi,\n} from \"@invisi-labs/protocol/contracts\";\nimport {\n Contract,\n getAddress as ethersAddress,\n getBytes,\n Interface,\n isError,\n keccak256,\n TypedDataEncoder,\n verifyTypedData,\n zeroPadValue,\n type Provider,\n type Signer,\n} from \"ethers\";\nimport type {\n FundingAuthorizationVerifier,\n FundingSigner,\n FundingTypedData,\n} from \"../transactions/operation-types\";\nconst getAddress = (value: string): Address => ethersAddress(value) as Address;\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).ownerAddress;\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 isValidRegistrationSignature(\n owner: Address,\n digest: Hex,\n signature: Hex\n ): Promise<boolean> {\n try {\n const result = await this.client.call({\n to: getAddress(owner),\n data: new Interface(erc1271Abi).encodeFunctionData(\"isValidSignature\", [\n digest,\n signature,\n ]),\n });\n // SignatureChecker compares the complete first return word, including padding.\n return (\n result.length >= 66 &&\n result.slice(0, 66).toLowerCase() === \"0x1626ba7e\" + \"00\".repeat(28)\n );\n } catch (error) {\n if (isError(error, \"CALL_EXCEPTION\")) return false;\n throw error;\n }\n }\n\n async getProtocolAddressRegistry(address: Address): Promise<Address> {\n return getAddress(\n await new Contract(getAddress(address), invisiProtocolAbi, this.client).getFunction(\n \"addressRegistry\"\n )()\n );\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 getCreditAllocation(\n context: import(\"@invisi-labs/protocol\").DeploymentContext,\n owner: Address,\n token: Address,\n block: CanonicalBlock\n ): Promise<{ shard: bigint; slot: number }> {\n const result = (await this.read(\n context,\n context.protocolAddress,\n invisiProtocolAbi,\n \"creditAllocation\",\n [owner, token],\n block\n )) as readonly bigint[];\n return { shard: BigInt(result[0]!), slot: Number(result[1]!) };\n }\n async getCreditRevocationBitmap(\n context: import(\"@invisi-labs/protocol\").DeploymentContext,\n owner: Address,\n token: Address,\n shard: bigint,\n wordIndex: number,\n block: CanonicalBlock\n ): Promise<bigint> {\n return BigInt(\n (await this.read(\n context,\n context.protocolAddress,\n invisiProtocolAbi,\n \"creditRevocationBitmap\",\n [owner, token, shard, wordIndex],\n block\n )) as bigint\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, ownerAddress: Hex, block: CanonicalBlock) {\n return number(\n await this.read(\n context,\n context.registryAddress,\n invisiAddressRegistryAbi,\n \"nonceOf\",\n [ownerWord(ownerAddress)],\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 (ownerAddress) => {\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(ownerAddress), {\n blockTag: block.number,\n });\n if (!registered) return null;\n const [keys] = await contract.getFunction(\"receivingKeysOf\")(ownerWord(ownerAddress), {\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 ownerAddress,\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"]}
@@ -0,0 +1,399 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunk4SDP53YQcjs = require('./chunk-4SDP53YQ.cjs');
6
+
7
+
8
+ var _chunkLOR6PYH5cjs = require('./chunk-LOR6PYH5.cjs');
9
+
10
+ // src/credit/state.ts
11
+
12
+
13
+
14
+ var _primitives = require('@invisi-labs/primitives');
15
+ async function creditLeaf(state) {
16
+ return _primitives.computeCreditCommitment.call(void 0, state.note);
17
+ }
18
+ async function assertCreditUpdatePlan(plan) {
19
+ const credit = plan.credit;
20
+ if (!_optionalChain([credit, 'optionalAccess', _ => _.update])) return;
21
+ const input = credit.inputs[0], output = credit.outputs[0], changes = credit.updateChanges;
22
+ if (!input || !output || !changes)
23
+ throw Error("Credit update input, output and adjustment required");
24
+ const derived = await _primitives.deriveCreditUpdate.call(void 0, input.state.note, changes, plan.deadline);
25
+ if (derived.nullifier !== credit.update.nullifier || derived.stateCommitment !== credit.update.creditCommitment || output.commitment !== derived.stateCommitment || await _primitives.computeCreditCommitment.call(void 0, output.state.note) !== derived.stateCommitment)
26
+ throw Error("Credit update adjustment does not match frozen successor");
27
+ }
28
+
29
+ // src/notes/recipient-infrastructure.ts
30
+
31
+
32
+
33
+
34
+ var _rpc = require('@invisi-labs/rpc');
35
+ var recipientInfrastructure = /* @__PURE__ */ Symbol("SDK recipient infrastructure");
36
+ function configureRecipientInfrastructure(options) {
37
+ const { provider, protocolRpc, chainReader } = options;
38
+ const registry = options.protocol.deployment.registry;
39
+ const deployment = options.protocol.deployment;
40
+ const lookup = (source) => async (ownerAddress) => {
41
+ if (!registry) throw new (0, _primitives.MissingCapabilityError)("receiving-key registry deployment");
42
+ if (source === "chain") {
43
+ if (!provider)
44
+ throw new (0, _primitives.MissingCapabilityError)("ethers provider for registry lookup");
45
+ return new (0, _chunkLOR6PYH5cjs.EthersAddressResolver)(
46
+ provider,
47
+ {
48
+ chainId: deployment.chainId,
49
+ registryAddress: registry.address
50
+ },
51
+ registry.runtimeCodeHash
52
+ ).lookup(ownerAddress);
53
+ }
54
+ if (!(protocolRpc instanceof _rpc.ProtocolRpcClient))
55
+ throw new (0, _primitives.MissingCapabilityError)("Protocol RPC recipient discovery");
56
+ const rpc = chainReader ? protocolRpc.withReader(chainReader) : protocolRpc;
57
+ const discovered = await rpc.getDeployment(deployment.chainId);
58
+ if (discovered.protocol.address !== deployment.protocol.address || discovered.protocol.runtimeCodeHash !== deployment.protocol.runtimeCodeHash || discovered.protocol.fromBlock !== deployment.protocol.fromBlock || _optionalChain([discovered, 'access', _2 => _2.registry, 'optionalAccess', _3 => _3.address]) !== registry.address || discovered.registry.runtimeCodeHash !== registry.runtimeCodeHash || discovered.registry.fromBlock !== registry.fromBlock)
59
+ throw new Error("Recipient registry deployment pins mismatch");
60
+ const registration = await rpc.getReceivingAddress(ownerAddress);
61
+ return registration ? _primitives.ReceivingAddress.parse(registration.receivingAddress).getReceivingKeys() : null;
62
+ };
63
+ return { ...options, [recipientInfrastructure]: lookup };
64
+ }
65
+ function recipientLookup(options, source = "protocol-rpc") {
66
+ return async (ownerAddress) => {
67
+ const lookup = options[recipientInfrastructure];
68
+ if (!lookup) throw new (0, _primitives.MissingCapabilityError)("recipient infrastructure");
69
+ return lookup(source)(ownerAddress);
70
+ };
71
+ }
72
+
73
+ // src/discovery/membership.ts
74
+
75
+ async function verifyMembership(reader, context, block, input, proof) {
76
+ if (proof.block.hash !== block.hash || proof.block.number !== block.number || proof.leaf !== input.commitment || proof.treeId !== input.treeId || proof.leafIndex !== input.leafIndex || proof.path.length !== 16 || !Number.isInteger(input.leafIndex) || input.leafIndex < 0 || input.leafIndex >= 65536 || !await reader.isKnownRoot(context, input.treeId, proof.root, block))
77
+ throw new Error("membership context/root mismatch");
78
+ let root = BigInt(input.commitment);
79
+ for (let i = 0; i < 16; i++) {
80
+ const sibling = proof.path[i];
81
+ if (typeof sibling !== "bigint" || sibling < 0n || sibling >= _primitives.FIELD_MODULUS)
82
+ throw new Error("noncanonical membership path");
83
+ root = BigInt(
84
+ await _primitives.poseidonHash.call(void 0, input.leafIndex >> i & 1 ? [sibling, root] : [root, sibling])
85
+ );
86
+ }
87
+ if (root !== BigInt(proof.root))
88
+ throw new Error("membership path does not produce canonical root");
89
+ }
90
+
91
+ // src/transactions/preparation/prepare-common.ts
92
+ var _ethers = require('ethers');
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ var _protocol = require('@invisi-labs/protocol');
101
+
102
+ // src/transactions/preparation/selection.ts
103
+ function selectNotes(notes, target, reserved) {
104
+ if (typeof target !== "bigint" || target < 0n)
105
+ throw new Error("selection target must be a nonnegative amount");
106
+ if (target === 0n) return [];
107
+ const eligible = notes.filter(
108
+ (note) => note.spent === "unspent" && !reserved.has(note.commitment)
109
+ );
110
+ for (const record of eligible)
111
+ if (typeof record.note.amount !== "bigint" || record.note.amount <= 0n || record.note.amount >= 1n << 128n)
112
+ throw new Error("invalid verified note amount");
113
+ eligible.sort(
114
+ (a, b) => a.note.amount > b.note.amount ? -1 : a.note.amount < b.note.amount ? 1 : a.treeId < b.treeId ? -1 : a.treeId > b.treeId ? 1 : a.leafIndex - b.leafIndex || a.commitment.localeCompare(b.commitment)
115
+ );
116
+ const selected = [];
117
+ let total = 0n;
118
+ for (const record of eligible) {
119
+ selected.push(structuredClone(record));
120
+ total += record.note.amount;
121
+ if (total >= target) return selected;
122
+ }
123
+ throw new Error("insufficient verified available funds");
124
+ }
125
+
126
+ // src/transactions/preparation/prepare-common.ts
127
+ function positiveAmount(value, bits = 128) {
128
+ if (typeof value !== "bigint" || value <= 0n || value >= 1n << BigInt(bits)) {
129
+ throw new Error(`amount must be a positive uint${bits}`);
130
+ }
131
+ return value;
132
+ }
133
+ function copyApplicationPayload(value) {
134
+ if (value === void 0) return new Uint8Array();
135
+ if (!(value instanceof Uint8Array)) throw new TypeError("payload must be Uint8Array");
136
+ return Uint8Array.from(value);
137
+ }
138
+ function positiveOutputAmount(payment, outputIndex) {
139
+ try {
140
+ return positiveAmount(payment.amount);
141
+ } catch (cause) {
142
+ throw new (0, _chunk4SDP53YQcjs.InvisiError)(
143
+ "PREPARATION_FAILED",
144
+ cause instanceof Error ? cause.message : "Invalid output amount",
145
+ {
146
+ address: payment.to,
147
+ field: "amount",
148
+ ...outputIndex === void 0 ? {} : { outputIndex },
149
+ cause
150
+ }
151
+ );
152
+ }
153
+ }
154
+ var Preparation = class {
155
+ constructor(runtime) {
156
+ this.runtime = runtime;
157
+ }
158
+ #roots = /* @__PURE__ */ new Map();
159
+ async frame(requested) {
160
+ const { reader, options } = this.runtime;
161
+ await options.protocol.validateDeployment(reader);
162
+ const block = await reader.getBlock(await reader.getLatestBlockNumber());
163
+ const deadline = _nullishCoalesce(requested, () => ( block.timestamp + (_nullishCoalesce(options.transactionTTL, () => ( 300n)))));
164
+ if (typeof deadline !== "bigint" || deadline < block.timestamp || deadline >= 1n << 64n) {
165
+ throw new Error("invalid transaction deadline");
166
+ }
167
+ const state = await this.runtime.readInventory();
168
+ if (state.invalidated) {
169
+ throw new Error("wallet requires canonical resync");
170
+ }
171
+ for (const point of [state.observedThrough]) {
172
+ if (point && (await reader.getBlock(point.number)).hash !== point.hash) {
173
+ throw new Error("canonical wallet checkpoint changed; resync required");
174
+ }
175
+ }
176
+ return {
177
+ context: {
178
+ ...options.protocol.context,
179
+ now: block.timestamp,
180
+ timestamp: block.timestamp
181
+ },
182
+ block,
183
+ deadline
184
+ };
185
+ }
186
+ async assertBlock(frame) {
187
+ if ((await this.runtime.reader.getBlock(frame.block.number)).hash !== frame.block.hash) {
188
+ throw new Error("canonical block changed while preparing");
189
+ }
190
+ }
191
+ async funding(source, frame) {
192
+ if (!source) {
193
+ return { funding: {}, fundingMode: "none" };
194
+ }
195
+ positiveAmount(source.amount);
196
+ const payer = _ethers.getAddress.call(void 0, source.payer);
197
+ const mode = _nullishCoalesce(source.authorization, () => ( "signature"));
198
+ if (BigInt(payer) === 0n) {
199
+ throw new Error("funding payer must be nonzero");
200
+ }
201
+ if (mode !== "signature" && mode !== "caller") {
202
+ throw new Error("invalid funding authorization mode");
203
+ }
204
+ if (mode === "caller" && (source.sigNonce || source.deadline)) {
205
+ throw new Error("caller funding uses zero nonce/deadline");
206
+ }
207
+ const funding = _protocol.normalizeFunding.call(void 0, {
208
+ payer,
209
+ amount: source.amount,
210
+ sigNonce: mode === "caller" ? 0n : await _asyncNullishCoalesce(source.sigNonce, async () => ( await this.runtime.reader.getFundingNonce(
211
+ frame.context,
212
+ payer,
213
+ frame.block
214
+ ))),
215
+ deadline: mode === "caller" ? 0n : _nullishCoalesce(source.deadline, () => ( frame.deadline)),
216
+ ...source.permit ? { permit: structuredClone(source.permit) } : {}
217
+ });
218
+ if (mode === "signature" && funding.deadline < frame.block.timestamp) {
219
+ throw new Error("funding authorization deadline has expired");
220
+ }
221
+ return { funding, fundingMode: mode };
222
+ }
223
+ async change(amount, context) {
224
+ const address = _nullishCoalesce(this.runtime.changeAddress, () => ( this.runtime.options.wallet.getReceivingAddress().toString()));
225
+ try {
226
+ const output = await _chunk4SDP53YQcjs.NoteOutput.create({
227
+ chainId: context.chainId,
228
+ protocolAddress: context.protocolAddress,
229
+ tokenAddress: context.tokenAddress,
230
+ amount,
231
+ recipient: address.startsWith("0i") ? { type: "invisi", address } : { type: "evm", address }
232
+ });
233
+ return await this.output(output, context, true);
234
+ } catch (cause) {
235
+ if (cause instanceof _chunk4SDP53YQcjs.InvisiError)
236
+ throw new (0, _chunk4SDP53YQcjs.InvisiError)(cause.code, cause.message, {
237
+ address,
238
+ field: "changeAddress",
239
+ ...cause.capability ? { capability: cause.capability } : {},
240
+ cause: _nullishCoalesce(cause.cause, () => ( cause))
241
+ });
242
+ throw new (0, _chunk4SDP53YQcjs.InvisiError)(
243
+ "PREPARATION_FAILED",
244
+ cause instanceof Error ? cause.message : "Change output preparation failed",
245
+ { address, field: "changeAddress", cause }
246
+ );
247
+ }
248
+ }
249
+ async output(payment, context, change = false, outputIndex) {
250
+ try {
251
+ positiveOutputAmount(payment, outputIndex);
252
+ const output = await _chunk4SDP53YQcjs.materializeNoteOutput.call(void 0,
253
+ payment,
254
+ context,
255
+ (source) => recipientLookup(this.runtime.options, source)
256
+ );
257
+ return { ...output, change };
258
+ } catch (cause) {
259
+ if (cause instanceof _chunk4SDP53YQcjs.InvisiError) {
260
+ throw new (0, _chunk4SDP53YQcjs.InvisiError)(cause.code, cause.message, {
261
+ address: _nullishCoalesce(cause.address, () => ( payment.to)),
262
+ field: change ? "changeAddress" : _nullishCoalesce(cause.field, () => ( "to")),
263
+ ...outputIndex === void 0 ? {} : { outputIndex },
264
+ ...cause.capability ? { capability: cause.capability } : {},
265
+ cause: _nullishCoalesce(cause.cause, () => ( cause))
266
+ });
267
+ }
268
+ throw new (0, _chunk4SDP53YQcjs.InvisiError)(
269
+ "PREPARATION_FAILED",
270
+ cause instanceof Error ? cause.message : "Output preparation failed",
271
+ {
272
+ address: payment.to,
273
+ field: change ? "changeAddress" : "to",
274
+ ...outputIndex === void 0 ? {} : { outputIndex },
275
+ cause
276
+ }
277
+ );
278
+ }
279
+ }
280
+ async membership(input, frame) {
281
+ const { options, reader } = this.runtime;
282
+ if (!options.protocolRpc)
283
+ throw new (0, _primitives.MissingCapabilityError)("Protocol RPC membership provider");
284
+ const root = this.#roots.get(input.treeId);
285
+ const proof = await options.protocolRpc.getMembership(
286
+ frame.context,
287
+ {
288
+ ...input,
289
+ ...root ? { root } : {}
290
+ },
291
+ frame.block
292
+ );
293
+ if (root && proof.root !== root)
294
+ throw new Error("membership provider changed the pinned source root");
295
+ await verifyMembership(reader, frame.context, frame.block, input, proof);
296
+ this.#roots.set(input.treeId, proof.root);
297
+ return { ...proof, path: [...proof.path] };
298
+ }
299
+ async selectFunds(target, frame, maxInputs = 190) {
300
+ const { scope, options, reader } = this.runtime;
301
+ const state = await this.runtime.readInventory();
302
+ if (state.invalidated) {
303
+ throw new Error("wallet requires canonical resync");
304
+ }
305
+ const need = target > 0n ? target : 0n;
306
+ const nullifier = options.wallet.exportNullifier();
307
+ const reserved = new Set(Object.keys(state.reservations));
308
+ const eligible = Object.values(state.notes).filter(
309
+ (note) => note.note.tokenAddress === BigInt(frame.context.tokenAddress) && note.spent === "unspent" && !reserved.has(note.commitment)
310
+ );
311
+ const byId = new Map(eligible.map((note) => [note.commitment, note]));
312
+ const choices = this.runtime.inputSelection ? [...this.runtime.inputSelection] : this.runtime.explicitInputs ? eligible.map((note) => note.commitment) : need > 0n && options.coinSelector ? await options.coinSelector.select(storedCandidates(eligible), need) : selectNotes(eligible, need, reserved).map((note) => note.commitment);
313
+ if (!Array.isArray(choices) || new Set(choices).size !== choices.length || choices.some((id) => !byId.has(id))) {
314
+ throw new Error("invalid or duplicate coin selection");
315
+ }
316
+ const selected = choices.map((id) => structuredClone(byId.get(id)));
317
+ const amount = selected.reduce((sum, input) => sum + input.note.amount, 0n);
318
+ if (amount < need) {
319
+ throw new Error("coin selection has insufficient verified funds");
320
+ }
321
+ if (selected.length > maxInputs || amount >= 1n << 135n) {
322
+ throw new Error("coin selection exceeds transaction capacity");
323
+ }
324
+ const inputs = [];
325
+ const sources = /* @__PURE__ */ new Map();
326
+ const nullifiers = [];
327
+ for (const input of selected) {
328
+ const note = input.note;
329
+ const c = frame.context;
330
+ if (note.ownerAddress !== scope.ownerAddress || note.chainId !== c.chainId || note.protocolAddress !== BigInt(c.protocolAddress) || note.tokenAddress !== BigInt(c.tokenAddress) || await _primitives.computeNoteCommitment.call(void 0,
331
+ c.chainId,
332
+ BigInt(c.protocolAddress),
333
+ await _primitives.computeNoteIdentity.call(void 0, BigInt(note.ownerAddress), note.nonce),
334
+ note.tokenAddress,
335
+ note.amount
336
+ ) !== input.commitment) {
337
+ throw new Error("selected input preimage/context mismatch");
338
+ }
339
+ const proof = await this.membership(input, frame);
340
+ const path = [...proof.path];
341
+ const root = proof.root;
342
+ if (sources.has(input.treeId) && sources.get(input.treeId) !== root) {
343
+ throw new Error("source roots do not share a canonical snapshot");
344
+ }
345
+ sources.set(input.treeId, root);
346
+ inputs.push({
347
+ note,
348
+ commitment: input.commitment,
349
+ treeId: input.treeId,
350
+ leafIndex: input.leafIndex,
351
+ path
352
+ });
353
+ nullifiers.push(
354
+ await nullifier.compute(
355
+ c.chainId,
356
+ BigInt(c.protocolAddress),
357
+ input.commitment,
358
+ input.note.nonce
359
+ )
360
+ );
361
+ }
362
+ await this.assertUnspent(nullifiers, frame);
363
+ return {
364
+ inputs,
365
+ sources: [...sources].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([treeId, merkleRoot]) => ({ treeId, merkleRoot })),
366
+ nullifiers,
367
+ amount
368
+ };
369
+ }
370
+ async assertUnspent(nullifiers, frame) {
371
+ if (nullifiers.length) {
372
+ const spent = await this.runtime.reader.isSpent(frame.context, nullifiers, frame.block);
373
+ if (spent.length !== nullifiers.length || spent.some((value) => value !== false)) {
374
+ throw new Error("selected input spent or invalid spent-state response");
375
+ }
376
+ }
377
+ }
378
+ };
379
+ function storedCandidates(inputs) {
380
+ const records = inputs.filter(
381
+ (input) => "blockNumber" in input && typeof input.blockNumber === "bigint" && "blockHash" in input && typeof input.blockHash === "string"
382
+ );
383
+ if (records.length !== inputs.length)
384
+ throw new Error("custom coin selection requires stored receipt metadata");
385
+ return structuredClone(records);
386
+ }
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+ exports.creditLeaf = creditLeaf; exports.assertCreditUpdatePlan = assertCreditUpdatePlan; exports.configureRecipientInfrastructure = configureRecipientInfrastructure; exports.recipientLookup = recipientLookup; exports.verifyMembership = verifyMembership; exports.positiveAmount = positiveAmount; exports.copyApplicationPayload = copyApplicationPayload; exports.positiveOutputAmount = positiveOutputAmount; exports.Preparation = Preparation;
399
+ //# sourceMappingURL=chunk-MA2QZEF5.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/wx/Workspace/invisi-lab/invisi-sdk-ts/packages/sdk/dist/chunk-MA2QZEF5.cjs","../src/credit/state.ts","../src/notes/recipient-infrastructure.ts","../src/discovery/membership.ts","../src/transactions/preparation/prepare-common.ts","../src/transactions/preparation/selection.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACPA;AACI;AACA;AAAA,qDAEG;AACP,MAAA,SAAsB,UAAA,CAAW,KAAA,EAA0C;AACvE,EAAA,OAAO,iDAAA,KAAwB,CAAM,IAAI,CAAA;AAC7C;AAGA,MAAA,SAAsB,sBAAA,CAClB,IAAA,EACa;AACb,EAAA,MAAM,OAAA,EAAS,IA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ACkD,IAAA;AAExC,IAAA;AAQW,IAAA;AAGD,MAAA;AACpB,IAAA;AACqD,IAAA;AACA,IAAA;AAClC,IAAA;AACC,MAAA;AACpB,IAAA;AACmD,IAAA;AAC/B,MAAA;AACpB,IAAA;AAC6D,IAAA;AACxB,IAAA;AACV,IAAA;AACG,IAAA;AACP,MAAA;AACH,MAAA;AAGZ,MAAA;AAIM,QAAA;AACsB,QAAA;AAC0B,QAAA;AAC7C,QAAA;AACA,QAAA;AAEX,MAAA;AACkB,QAAA;AACpB,MAAA;AACgD,MAAA;AACrB,MAAA;AACR,MAAA;AACgC,MAAA;AAC/B,QAAA;AACpB,MAAA;AAC8B,MAAA;AAClB,MAAA;AACR,QAAA;AACkB,QAAA;AACJ,QAAA;AACG,QAAA;AACjB,QAAA;AACH,MAAA;AACU,MAAA;AACU,QAAA;AACX,UAAA;AACsB,UAAA;AAClB,UAAA;AACK,UAAA;AACf,QAAA;AACJ,MAAA;AACJ,IAAA;AAC0C,IAAA;AACnC,IAAA;AACH,MAAA;AAEiC,MAAA;AAEjC,MAAA;AACA,MAAA;AACJ,IAAA;AACJ,EAAA;AAEwF,EAAA;AAC7D,IAAA;AAC6B,MAAA;AACA,MAAA;AAC5B,QAAA;AACpB,MAAA;AACJ,IAAA;AACJ,EAAA;AACJ;AAI2E;AAChD,EAAA;AAGF,IAAA;AAGrB,EAAA;AAC8B,EAAA;AACV,IAAA;AACU,EAAA;AAClC;AJmC0D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/wx/Workspace/invisi-lab/invisi-sdk-ts/packages/sdk/dist/chunk-MA2QZEF5.cjs","sourcesContent":[null,"import type { Hex } from \"@invisi-labs/protocol/contracts\";\n\nimport {\n computeCreditCommitment,\n deriveCreditUpdate,\n type CreditDeliveryState,\n} from \"@invisi-labs/primitives\";\nexport async function creditLeaf(state: CreditDeliveryState): Promise<Hex> {\n return computeCreditCommitment(state.note);\n}\n\n/** Rebuild from the original input and delta; cached output balances are never update intent. */\nexport async function assertCreditUpdatePlan(\n plan: import(\"../transactions/operation-types\").OperationPlan\n): Promise<void> {\n const credit = plan.credit;\n if (!credit?.update) return;\n const input = credit.inputs[0],\n output = credit.outputs[0],\n changes = credit.updateChanges;\n if (!input || !output || !changes)\n throw Error(\"Credit update input, output and adjustment required\");\n const derived = await deriveCreditUpdate(input.state.note, changes, plan.deadline);\n if (\n derived.nullifier !== credit.update.nullifier ||\n derived.stateCommitment !== credit.update.creditCommitment ||\n output.commitment !== derived.stateCommitment ||\n (await computeCreditCommitment(output.state.note)) !== derived.stateCommitment\n )\n throw Error(\"Credit update adjustment does not match frozen successor\");\n}\n","import {\n MissingCapabilityError,\n ReceivingAddress,\n type ReceivingKeyLookup,\n} from \"@invisi-labs/primitives\";\nimport { ProtocolRpcClient } from \"@invisi-labs/rpc\";\nimport { EthersAddressResolver } from \"../integrations/ethers\";\nimport type { TransactionInfrastructure } from \"../transactions/operation-types\";\n\nexport type AddressLookup = \"chain\" | \"protocol-rpc\";\nconst recipientInfrastructure = Symbol(\"SDK recipient infrastructure\");\ntype InternalInfrastructure = {\n [recipientInfrastructure]?: (source: AddressLookup) => ReceivingKeyLookup;\n};\n\n/** Capture deployment pins before a Protocol is bound to an operation's token. */\nexport function configureRecipientInfrastructure<T extends TransactionInfrastructure>(\n options: T\n): T {\n const { provider, protocolRpc, chainReader } = options;\n const registry = options.protocol.deployment.registry;\n const deployment = options.protocol.deployment;\n const lookup =\n (source: AddressLookup): ReceivingKeyLookup =>\n async (ownerAddress) => {\n if (!registry) throw new MissingCapabilityError(\"receiving-key registry deployment\");\n if (source === \"chain\") {\n if (!provider)\n throw new MissingCapabilityError(\"ethers provider for registry lookup\");\n return new EthersAddressResolver(\n provider,\n {\n chainId: deployment.chainId,\n registryAddress: registry.address,\n },\n registry.runtimeCodeHash\n ).lookup(ownerAddress);\n }\n if (!(protocolRpc instanceof ProtocolRpcClient))\n throw new MissingCapabilityError(\"Protocol RPC recipient discovery\");\n const rpc = chainReader ? protocolRpc.withReader(chainReader) : protocolRpc;\n const discovered = await rpc.getDeployment(deployment.chainId);\n if (\n discovered.protocol.address !== deployment.protocol.address ||\n discovered.protocol.runtimeCodeHash !== deployment.protocol.runtimeCodeHash ||\n discovered.protocol.fromBlock !== deployment.protocol.fromBlock ||\n discovered.registry?.address !== registry.address ||\n discovered.registry.runtimeCodeHash !== registry.runtimeCodeHash ||\n discovered.registry.fromBlock !== registry.fromBlock\n )\n throw new Error(\"Recipient registry deployment pins mismatch\");\n const registration = await rpc.getReceivingAddress(ownerAddress);\n return registration\n ? ReceivingAddress.parse(registration.receivingAddress).getReceivingKeys()\n : null;\n };\n return { ...options, [recipientInfrastructure]: lookup };\n}\n\n/** Internal lookup plumbing; public APIs never accept resolver functions. */\nexport function recipientLookup(\n options: object,\n source: AddressLookup = \"protocol-rpc\"\n): ReceivingKeyLookup {\n return async (ownerAddress) => {\n const lookup = (options as InternalInfrastructure)[recipientInfrastructure];\n if (!lookup) throw new MissingCapabilityError(\"recipient infrastructure\");\n return lookup(source)(ownerAddress);\n };\n}\n","import type { Hex } from \"@invisi-labs/protocol/contracts\";\n\nimport { FIELD_MODULUS, poseidonHash } from \"@invisi-labs/primitives\";\nimport type {\n CanonicalBlock,\n ChainReader,\n Membership,\n TransactionContext,\n} from \"@invisi-labs/protocol\";\nexport async function verifyMembership(\n reader: ChainReader,\n context: TransactionContext,\n block: CanonicalBlock,\n input: { treeId: bigint; leafIndex: number; commitment: Hex },\n proof: Membership\n): Promise<void> {\n if (\n proof.block.hash !== block.hash ||\n proof.block.number !== block.number ||\n proof.leaf !== input.commitment ||\n proof.treeId !== input.treeId ||\n proof.leafIndex !== input.leafIndex ||\n proof.path.length !== 16 ||\n !Number.isInteger(input.leafIndex) ||\n input.leafIndex < 0 ||\n input.leafIndex >= 65536 ||\n !(await reader.isKnownRoot(context, input.treeId, proof.root, block))\n )\n throw new Error(\"membership context/root mismatch\");\n let root = BigInt(input.commitment);\n for (let i = 0; i < 16; i++) {\n const sibling = proof.path[i]!;\n if (typeof sibling !== \"bigint\" || sibling < 0n || sibling >= FIELD_MODULUS)\n throw new Error(\"noncanonical membership path\");\n root = BigInt(\n await poseidonHash((input.leafIndex >> i) & 1 ? [sibling, root] : [root, sibling])\n );\n }\n if (root !== BigInt(proof.root))\n throw new Error(\"membership path does not produce canonical root\");\n}\n","import type { Hex } from \"@invisi-labs/protocol/contracts\";\nimport { getAddress } from \"ethers\";\nimport { InvisiError } from \"../../errors\";\nimport { NoteOutput, materializeNoteOutput } from \"../../notes/NoteOutput\";\nimport { recipientLookup } from \"../../notes/recipient-infrastructure\";\n\nimport {\n MissingCapabilityError,\n computeNoteCommitment,\n computeNoteIdentity,\n} from \"@invisi-labs/primitives\";\nimport {\n normalizeFunding,\n type CanonicalBlock,\n type FundingInput,\n type Membership,\n type TransactionContext,\n} from \"@invisi-labs/protocol\";\nimport { type NoteMembership } from \"@invisi-labs/prover\";\nimport { verifyMembership } from \"../../discovery/membership\";\nimport type {\n FundingSource,\n OperationPlan,\n PreparationRuntime,\n PreparedOutput,\n} from \"../operation-types\";\nimport type { NoteRecord } from \"../records\";\nimport { selectNotes, type SelectableNote } from \"./selection\";\n\nexport interface PreparationFrame {\n context: TransactionContext;\n block: CanonicalBlock;\n deadline: bigint;\n}\n\nexport function positiveAmount(value: bigint, bits = 128): bigint {\n if (typeof value !== \"bigint\" || value <= 0n || value >= 1n << BigInt(bits)) {\n throw new Error(`amount must be a positive uint${bits}`);\n }\n return value;\n}\n\n/** Reject non-byte JavaScript inputs before copying; empty bytes explicitly clear metadata. */\nexport function copyApplicationPayload(value?: Uint8Array): Uint8Array {\n if (value === undefined) return new Uint8Array();\n if (!(value instanceof Uint8Array)) throw new TypeError(\"payload must be Uint8Array\");\n return Uint8Array.from(value);\n}\n\n/** Preserve the offending payment position even when summing transfer amounts first. */\nexport function positiveOutputAmount(payment: NoteOutput, outputIndex?: number): bigint {\n try {\n return positiveAmount(payment.amount);\n } catch (cause) {\n throw new InvisiError(\n \"PREPARATION_FAILED\",\n cause instanceof Error ? cause.message : \"Invalid output amount\",\n {\n address: payment.to,\n field: \"amount\",\n ...(outputIndex === undefined ? {} : { outputIndex }),\n cause,\n }\n );\n }\n}\n\n/** Shared local preparation checks; private witnesses never enter this object's public records. */\nexport class Preparation<Result> {\n readonly #roots = new Map<bigint, Hex>();\n constructor(readonly runtime: PreparationRuntime<Result>) {}\n\n async frame(requested?: bigint): Promise<PreparationFrame> {\n const { reader, options } = this.runtime;\n await options.protocol.validateDeployment(reader);\n const block = await reader.getBlock(await reader.getLatestBlockNumber());\n const deadline = requested ?? block.timestamp + (options.transactionTTL ?? 300n);\n if (typeof deadline !== \"bigint\" || deadline < block.timestamp || deadline >= 1n << 64n) {\n throw new Error(\"invalid transaction deadline\");\n }\n const state = await this.runtime.readInventory();\n if (state.invalidated) {\n throw new Error(\"wallet requires canonical resync\");\n }\n for (const point of [state.observedThrough]) {\n if (point && (await reader.getBlock(point.number)).hash !== point.hash) {\n throw new Error(\"canonical wallet checkpoint changed; resync required\");\n }\n }\n return {\n context: {\n ...options.protocol.context,\n now: block.timestamp,\n timestamp: block.timestamp,\n },\n block,\n deadline,\n };\n }\n\n async assertBlock(frame: PreparationFrame): Promise<void> {\n if ((await this.runtime.reader.getBlock(frame.block.number)).hash !== frame.block.hash) {\n throw new Error(\"canonical block changed while preparing\");\n }\n }\n\n async funding(\n source: FundingSource | undefined,\n frame: PreparationFrame\n ): Promise<{ funding: FundingInput; fundingMode: OperationPlan[\"fundingMode\"] }> {\n if (!source) {\n return { funding: {}, fundingMode: \"none\" };\n }\n positiveAmount(source.amount);\n const payer = getAddress(source.payer) as Hex;\n const mode = source.authorization ?? \"signature\";\n if (BigInt(payer) === 0n) {\n throw new Error(\"funding payer must be nonzero\");\n }\n if (mode !== \"signature\" && mode !== \"caller\") {\n throw new Error(\"invalid funding authorization mode\");\n }\n if (mode === \"caller\" && (source.sigNonce || source.deadline)) {\n throw new Error(\"caller funding uses zero nonce/deadline\");\n }\n const funding = normalizeFunding({\n payer,\n amount: source.amount,\n sigNonce:\n mode === \"caller\"\n ? 0n\n : (source.sigNonce ??\n (await this.runtime.reader.getFundingNonce(\n frame.context,\n payer,\n frame.block\n ))),\n deadline: mode === \"caller\" ? 0n : (source.deadline ?? frame.deadline),\n ...(source.permit ? { permit: structuredClone(source.permit) } : {}),\n });\n if (mode === \"signature\" && funding.deadline < frame.block.timestamp) {\n throw new Error(\"funding authorization deadline has expired\");\n }\n return { funding, fundingMode: mode };\n }\n\n async change(amount: bigint, context: TransactionContext): Promise<PreparedOutput> {\n const address =\n this.runtime.changeAddress ??\n this.runtime.options.wallet.getReceivingAddress().toString();\n try {\n const output = await NoteOutput.create({\n chainId: context.chainId,\n protocolAddress: context.protocolAddress,\n tokenAddress: context.tokenAddress,\n amount,\n recipient: address.startsWith(\"0i\")\n ? { type: \"invisi\", address }\n : { type: \"evm\", address },\n });\n return await this.output(output, context, true);\n } catch (cause) {\n if (cause instanceof InvisiError)\n throw new InvisiError(cause.code, cause.message, {\n address,\n field: \"changeAddress\",\n ...(cause.capability ? { capability: cause.capability } : {}),\n cause: cause.cause ?? cause,\n });\n throw new InvisiError(\n \"PREPARATION_FAILED\",\n cause instanceof Error ? cause.message : \"Change output preparation failed\",\n { address, field: \"changeAddress\", cause }\n );\n }\n }\n\n async output(\n payment: NoteOutput,\n context: TransactionContext,\n change = false,\n outputIndex?: number\n ): Promise<PreparedOutput> {\n try {\n positiveOutputAmount(payment, outputIndex);\n const output = await materializeNoteOutput(payment, context, (source) =>\n recipientLookup(this.runtime.options, source)\n );\n return { ...output, change };\n } catch (cause) {\n if (cause instanceof InvisiError) {\n throw new InvisiError(cause.code, cause.message, {\n address: cause.address ?? payment.to,\n field: change ? \"changeAddress\" : (cause.field ?? \"to\"),\n ...(outputIndex === undefined ? {} : { outputIndex }),\n ...(cause.capability ? { capability: cause.capability } : {}),\n cause: cause.cause ?? cause,\n });\n }\n throw new InvisiError(\n \"PREPARATION_FAILED\",\n cause instanceof Error ? cause.message : \"Output preparation failed\",\n {\n address: payment.to,\n field: change ? \"changeAddress\" : \"to\",\n ...(outputIndex === undefined ? {} : { outputIndex }),\n cause,\n }\n );\n }\n }\n\n async membership(\n input: { treeId: bigint; leafIndex: number; commitment: Hex },\n frame: PreparationFrame\n ): Promise<Membership> {\n const { options, reader } = this.runtime;\n if (!options.protocolRpc)\n throw new MissingCapabilityError(\"Protocol RPC membership provider\");\n const root = this.#roots.get(input.treeId);\n const proof = await options.protocolRpc.getMembership(\n frame.context,\n {\n ...input,\n ...(root ? { root } : {}),\n },\n frame.block\n );\n if (root && proof.root !== root)\n throw new Error(\"membership provider changed the pinned source root\");\n await verifyMembership(reader, frame.context, frame.block, input, proof);\n this.#roots.set(input.treeId, proof.root);\n return { ...proof, path: [...proof.path] };\n }\n\n async selectFunds(target: bigint, frame: PreparationFrame, maxInputs = 190) {\n const { scope, options, reader } = this.runtime;\n const state = await this.runtime.readInventory();\n if (state.invalidated) {\n throw new Error(\"wallet requires canonical resync\");\n }\n const need = target > 0n ? target : 0n;\n const nullifier = options.wallet.exportNullifier();\n const reserved = new Set(Object.keys(state.reservations));\n const eligible = Object.values(state.notes).filter(\n (note) =>\n note.note.tokenAddress === BigInt(frame.context.tokenAddress) &&\n note.spent === \"unspent\" &&\n !reserved.has(note.commitment)\n );\n const byId = new Map(eligible.map((note) => [note.commitment, note]));\n const choices = this.runtime.inputSelection\n ? [...this.runtime.inputSelection]\n : this.runtime.explicitInputs\n ? eligible.map((note) => note.commitment)\n : need > 0n && options.coinSelector\n ? await options.coinSelector.select(storedCandidates(eligible), need)\n : selectNotes(eligible, need, reserved).map((note) => note.commitment);\n if (\n !Array.isArray(choices) ||\n new Set(choices).size !== choices.length ||\n choices.some((id) => !byId.has(id))\n ) {\n throw new Error(\"invalid or duplicate coin selection\");\n }\n const selected = choices.map((id) => structuredClone(byId.get(id)!));\n const amount = selected.reduce((sum, input) => sum + input.note.amount, 0n);\n if (amount < need) {\n throw new Error(\"coin selection has insufficient verified funds\");\n }\n if (selected.length > maxInputs || amount >= 1n << 135n) {\n throw new Error(\"coin selection exceeds transaction capacity\");\n }\n const inputs: Array<NoteMembership & { commitment: Hex }> = [];\n const sources = new Map<bigint, Hex>();\n const nullifiers: Hex[] = [];\n for (const input of selected) {\n const note = input.note;\n const c = frame.context;\n if (\n note.ownerAddress !== scope.ownerAddress ||\n note.chainId !== c.chainId ||\n note.protocolAddress !== BigInt(c.protocolAddress) ||\n note.tokenAddress !== BigInt(c.tokenAddress) ||\n (await computeNoteCommitment(\n c.chainId,\n BigInt(c.protocolAddress),\n await computeNoteIdentity(BigInt(note.ownerAddress), note.nonce),\n note.tokenAddress,\n note.amount\n )) !== input.commitment\n ) {\n throw new Error(\"selected input preimage/context mismatch\");\n }\n const proof = await this.membership(input, frame);\n const path = [...proof.path];\n const root = proof.root;\n if (sources.has(input.treeId) && sources.get(input.treeId) !== root) {\n throw new Error(\"source roots do not share a canonical snapshot\");\n }\n sources.set(input.treeId, root);\n inputs.push({\n note,\n commitment: input.commitment,\n treeId: input.treeId,\n leafIndex: input.leafIndex,\n path,\n });\n nullifiers.push(\n await nullifier!.compute(\n c.chainId,\n BigInt(c.protocolAddress),\n input.commitment,\n input.note.nonce\n )\n );\n }\n await this.assertUnspent(nullifiers, frame);\n return {\n inputs,\n sources: [...sources]\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n .map(([treeId, merkleRoot]) => ({ treeId, merkleRoot })),\n nullifiers,\n amount,\n };\n }\n\n async assertUnspent(nullifiers: readonly Hex[], frame: PreparationFrame): Promise<void> {\n if (nullifiers.length) {\n const spent = await this.runtime.reader.isSpent(frame.context, nullifiers, frame.block);\n if (spent.length !== nullifiers.length || spent.some((value) => value !== false)) {\n throw new Error(\"selected input spent or invalid spent-state response\");\n }\n }\n }\n}\n\n// Managed custom selectors retain access to receipt metadata. Explicit inputs\n// use their own exact selection and never pass fabricated metadata to a selector.\nfunction storedCandidates(inputs: readonly SelectableNote[]): NoteRecord[] {\n const records = inputs.filter(\n (input): input is NoteRecord =>\n \"blockNumber\" in input &&\n typeof input.blockNumber === \"bigint\" &&\n \"blockHash\" in input &&\n typeof input.blockHash === \"string\"\n );\n if (records.length !== inputs.length)\n throw new Error(\"custom coin selection requires stored receipt metadata\");\n return structuredClone(records);\n}\n","import type { NoteRecord } from \"../records\";\n/** Minimal input count by descending amount, with deterministic tree/position/commitment ties. */\nexport type SelectableNote = Pick<\n NoteRecord,\n \"note\" | \"commitment\" | \"treeId\" | \"leafIndex\" | \"spent\"\n>;\nexport function selectNotes<T extends SelectableNote>(\n notes: readonly T[],\n target: bigint,\n reserved: ReadonlySet<string>\n): T[] {\n if (typeof target !== \"bigint\" || target < 0n)\n throw new Error(\"selection target must be a nonnegative amount\");\n if (target === 0n) return [];\n const eligible = notes.filter(\n (note) => note.spent === \"unspent\" && !reserved.has(note.commitment)\n );\n for (const record of eligible)\n if (\n typeof record.note.amount !== \"bigint\" ||\n record.note.amount <= 0n ||\n record.note.amount >= 1n << 128n\n )\n throw new Error(\"invalid verified note amount\");\n eligible.sort((a, b) =>\n a.note.amount > b.note.amount\n ? -1\n : a.note.amount < b.note.amount\n ? 1\n : a.treeId < b.treeId\n ? -1\n : a.treeId > b.treeId\n ? 1\n : a.leafIndex - b.leafIndex || a.commitment.localeCompare(b.commitment)\n );\n const selected: T[] = [];\n let total = 0n;\n for (const record of eligible) {\n selected.push(structuredClone(record));\n total += record.note.amount;\n if (total >= target) return selected;\n }\n throw new Error(\"insufficient verified available funds\");\n}\n"]}
@@ -0,0 +1,86 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk3KTQQZOWcjs = require('./chunk-3KTQQZOW.cjs');
4
+
5
+ // src/provenance/proof-record.ts
6
+
7
+
8
+
9
+
10
+
11
+
12
+ var _provenance = require('@invisi-labs/protocol/provenance');
13
+ var _protocol = require('@invisi-labs/protocol');
14
+ function keys(value, allowed) {
15
+ if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).some((key) => !allowed.includes(key)))
16
+ throw Error("Unknown Provenance packet field");
17
+ }
18
+ async function validateProvenanceProof(packet, trust) {
19
+ keys(packet, [
20
+ "format",
21
+ "data",
22
+ "context",
23
+ "mainCircuitCapacity",
24
+ "publicInputs",
25
+ "operationDigest",
26
+ "sidecars"
27
+ ]);
28
+ keys(packet.context, ["chainId", "protocolAddress", "tokenAddress"]);
29
+ if (packet.format !== "invisi-provenance-submission-v1" || typeof packet.context.chainId !== "string" || typeof packet.context.protocolAddress !== "string" || typeof packet.context.tokenAddress !== "string" || BigInt(packet.context.chainId) !== BigInt(trust.chainId) || BigInt(packet.context.protocolAddress) !== BigInt(trust.protocolAddress) || !Array.isArray(packet.sidecars) || packet.sidecars.length !== 1)
30
+ throw Error("Provenance packet deployment or shape mismatch");
31
+ const decoded = _chunk3KTQQZOWcjs.decodeBroadcasterIntent.call(void 0, packet.data);
32
+ if (decoded.method !== "transact") throw Error("Provenance requires private transact calldata");
33
+ const context = {
34
+ chainId: BigInt(packet.context.chainId),
35
+ protocolAddress: packet.context.protocolAddress,
36
+ tokenAddress: packet.context.tokenAddress
37
+ };
38
+ const raw = decoded.request.params;
39
+ const params = {
40
+ token: raw.token,
41
+ sources: Array.from(raw.sources, (source) => ({
42
+ treeId: source.treeId,
43
+ merkleRoot: source.merkleRoot
44
+ })),
45
+ nullifiers: [...raw.nullifiers],
46
+ noteCommitments: [...raw.noteCommitments],
47
+ withdrawalAddress: raw.withdrawalAddress,
48
+ withdrawalAmount: raw.withdrawalAmount,
49
+ deadline: raw.deadline,
50
+ feeRecipient: raw.feeRecipient,
51
+ feeAmount: raw.feeAmount
52
+ };
53
+ const deliveries = decoded.request.deliveries.map(
54
+ (d) => d.toObject(true)
55
+ );
56
+ const funding = decoded.request.funding.toObject(true);
57
+ funding.permit.v = Number(funding.permit.v);
58
+ const normalized = _protocol.normalizeTransactRequest.call(void 0, context, params, deliveries, funding);
59
+ const publicInputs = _protocol.transactUserPublicInputs.call(void 0, context, params, deliveries, funding);
60
+ if (!normalized.inputCount || normalized.capacity !== packet.mainCircuitCapacity || JSON.stringify(publicInputs) !== JSON.stringify(packet.publicInputs))
61
+ throw Error("Provenance native statement mismatch");
62
+ const digest = _provenance.operationDigest.call(void 0, {
63
+ ...context,
64
+ mainCircuitCapacity: normalized.capacity,
65
+ publicInputs
66
+ });
67
+ if (packet.operationDigest !== digest) throw Error("Provenance operation digest mismatch");
68
+ const sidecar = packet.sidecars[0];
69
+ const wire = _provenance.proofSidecarToWire.call(void 0, sidecar);
70
+ if (wire.operationIndex !== "0") throw Error("Unsupported Provenance operation index");
71
+ await _provenance.validateProofBundle.call(void 0, wire.proofBundle, trust);
72
+ const pi = wire.proofBundle.publicInputs.map(BigInt);
73
+ if (pi[2] !== BigInt(context.tokenAddress) || pi[6] !== BigInt(normalized.inputCount) || _provenance.word.call(void 0, pi[7] << 128n | pi[8]) !== digest || pi[9] !== await _provenance.inputDigest.call(void 0, normalized.nullifiers))
74
+ throw Error("Provenance proof statement mismatch");
75
+ return {
76
+ ...packet,
77
+ context: { ...packet.context },
78
+ publicInputs: [...publicInputs],
79
+ sidecars: [wire]
80
+ };
81
+ }
82
+
83
+
84
+
85
+ exports.validateProvenanceProof = validateProvenanceProof;
86
+ //# sourceMappingURL=chunk-MI4IP4ZD.cjs.map