@zama-fhe/sdk 3.7.0-beta.8 → 3.7.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.
- package/dist/cjs/base-signer.cjs +1 -1
- package/dist/cjs/base-signer.cjs.map +1 -1
- package/dist/cjs/chains/index.cjs +1 -1
- package/dist/cjs/chains.cjs +1 -1
- package/dist/cjs/chains.cjs.map +1 -1
- package/dist/cjs/erc165.cjs +1 -1
- package/dist/cjs/erc165.cjs.map +1 -1
- package/dist/cjs/fhevm-relayer.cjs +1 -1
- package/dist/cjs/fhevm-relayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/telemetry.cjs +1 -1
- package/dist/cjs/telemetry.cjs.map +1 -1
- package/dist/cjs/token.cjs +1 -1
- package/dist/cjs/token.cjs.map +1 -1
- package/dist/cjs/vaults/index.cjs +1 -1
- package/dist/cjs/web/index.cjs +1 -1
- package/dist/cjs/wrapped-token.cjs +1 -1
- package/dist/esm/{base-signer-46j6PRq-.d.ts → base-signer-BxIDBDTF.d.ts} +2 -2
- package/dist/esm/base-signer-ClrhHzbm.js +2 -0
- package/dist/esm/base-signer-ClrhHzbm.js.map +1 -0
- package/dist/esm/chains/index.d.ts +2 -2
- package/dist/esm/chains/index.js +1 -1
- package/dist/esm/{chains-iPpnjXql.js → chains-BwlDI944.js} +2 -2
- package/dist/esm/chains-BwlDI944.js.map +1 -0
- package/dist/esm/cleartext/index.d.ts +2 -2
- package/dist/esm/cleartext/index.js +1 -1
- package/dist/esm/{cleartext-DInZ0vz-.d.ts → cleartext-BnTAN4-g.d.ts} +2 -2
- package/dist/esm/{cleartext-C0ba9z6Z.js → cleartext-DBZq4E1O.js} +2 -2
- package/dist/esm/{cleartext-C0ba9z6Z.js.map → cleartext-DBZq4E1O.js.map} +1 -1
- package/dist/esm/erc165-BAd2z3ay.js +2 -0
- package/dist/esm/erc165-BAd2z3ay.js.map +1 -0
- package/dist/esm/ethers/index.d.ts +4 -4
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/fhevm-relayer-BEQ31nmT.js +8 -0
- package/dist/esm/{fhevm-relayer-BWhXU1WB.js.map → fhevm-relayer-BEQ31nmT.js.map} +1 -1
- package/dist/esm/{index-DHMs4ZRb.d.ts → index-BlY7CCPB.d.ts} +7 -7
- package/dist/esm/{decryption-q0ODuDDS.d.ts → index-CD2sMpst.d.ts} +3 -7
- package/dist/esm/{index-Cdbp_93f.d.ts → index-D1Wtji3m.d.ts} +4 -26
- package/dist/esm/{index-C1clixw5.d.ts → index-fsWBYM8S.d.ts} +4 -4
- package/dist/esm/index.d.ts +9 -10
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node/index.d.ts +5 -5
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/node/index.js.map +1 -1
- package/dist/esm/query/index.d.ts +5 -6
- package/dist/esm/query/index.js +1 -1
- package/dist/esm/telemetry-CBSzrmab.js +2 -0
- package/dist/esm/{telemetry-DvJV3oBk.js.map → telemetry-CBSzrmab.js.map} +1 -1
- package/dist/esm/token-CTvEGQmH.js +2 -0
- package/dist/esm/token-CTvEGQmH.js.map +1 -0
- package/dist/esm/{types-Bz42Emet.d.ts → types-C2ccCjoA.d.ts} +3 -3
- package/dist/esm/{types-BIgPY1yI.d.ts → types-CHepK8MK.d.ts} +2 -2
- package/dist/esm/{types-I9lJwH20.d.ts → types-Dc1fpXWt.d.ts} +3 -3
- package/dist/esm/vaults/index.d.ts +2 -3
- package/dist/esm/vaults/index.js +1 -1
- package/dist/esm/viem/index.d.ts +4 -4
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/web/index.d.ts +17 -2
- package/dist/esm/web/index.js +1 -1
- package/dist/esm/wrapped-token-IDUEFpZx.js +2 -0
- package/dist/esm/{wrapped-token-3usJd0oi.js.map → wrapped-token-IDUEFpZx.js.map} +1 -1
- package/package.json +1 -15
- package/dist/cjs/fatal-batch.cjs +0 -2
- package/dist/cjs/fatal-batch.cjs.map +0 -1
- package/dist/cjs/internal/index.cjs +0 -2
- package/dist/cjs/internal/index.cjs.map +0 -1
- package/dist/cjs/signing.cjs +0 -2
- package/dist/cjs/signing.cjs.map +0 -1
- package/dist/esm/base-signer-CNHZZnr2.js +0 -2
- package/dist/esm/base-signer-CNHZZnr2.js.map +0 -1
- package/dist/esm/chains-iPpnjXql.js.map +0 -1
- package/dist/esm/encrypt-worker-client-CKTlhAGI.d.ts +0 -19
- package/dist/esm/erc165-B8gx2luK.js +0 -2
- package/dist/esm/erc165-B8gx2luK.js.map +0 -1
- package/dist/esm/fatal-batch-BiiS7KdS.js +0 -2
- package/dist/esm/fatal-batch-BiiS7KdS.js.map +0 -1
- package/dist/esm/fhevm-relayer-BWhXU1WB.js +0 -8
- package/dist/esm/index-B09m_e9L.d.ts +0 -1
- package/dist/esm/internal/index.d.ts +0 -26
- package/dist/esm/internal/index.js +0 -2
- package/dist/esm/internal/index.js.map +0 -1
- package/dist/esm/signing-C6nbPCyd.js +0 -2
- package/dist/esm/signing-C6nbPCyd.js.map +0 -1
- package/dist/esm/telemetry-DvJV3oBk.js +0 -2
- package/dist/esm/token-g6sinwTx.js +0 -2
- package/dist/esm/token-g6sinwTx.js.map +0 -1
- package/dist/esm/wrapped-token-3usJd0oi.js +0 -2
package/dist/esm/viem/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as e,B as t,D as n,E as r,F as i,H as a,O as o,T as s,h as c,s as l,v as u,x as d}from"../erc165-
|
|
1
|
+
import{A as e,B as t,D as n,E as r,F as i,H as a,O as o,T as s,h as c,s as l,v as u,x as d}from"../erc165-BAd2z3ay.js";import{i as f,t as p}from"../base-signer-ClrhHzbm.js";import{a as m,i as h,n as g,o as _,r as v,s as y,t as b}from"../wrappers-registry-Cm3JJeqx.js";import{t as x}from"../eip1193-subscribe-CNxVHW6y.js";import{encodeFunctionData as S,getAddress as C,serializeTransaction as w}from"viem";var T=class{#e;constructor(e){this.#e=e.publicClient}async getChainId(){return this.#e.getChainId()}async readContract(e){return this.#e.readContract(e)}async waitForTransactionReceipt(e){return this.#e.waitForTransactionReceipt({hash:e})}async getBlockTimestamp(){return(await this.#e.getBlock()).timestamp}async prepareTransaction(e){let{from:t,calldata:n}=e,r=S({abi:n.abi,functionName:n.functionName,args:n.args}),i=this.#e.getChainId(),o=e.nonce===void 0?this.#e.getTransactionCount({address:t,blockTag:`pending`}):Promise.resolve(e.nonce),s=e.gasLimit===void 0?n.gas??this.#e.estimateGas({account:t,to:n.address,data:r,value:n.value??0n}).catch(e=>{throw new a(`ViemProvider.prepareTransaction: gas estimation reverted for ${n.functionName} on ${n.address}`,{cause:e})}):Promise.resolve(e.gasLimit),c=e.fees??this.#e.estimateFeesPerGas(),[l,u,d,f]=await Promise.all([i,o,s,c]);return w({type:`eip1559`,chainId:l,nonce:u,to:n.address,data:r,value:n.value??0n,gas:d,maxFeePerGas:f.maxFeePerGas,maxPriorityFeePerGas:f.maxPriorityFeePerGas})}};function E(e){let t=(e.primaryType?e.types[e.primaryType]:void 0)??[],n={...e.message};for(let{name:e,type:r}of t)/^uint\d*$/.test(r)&&(n[e]=BigInt(n[e]));return n}function D(e){if(!(!e.account||!e.chain))return{address:C(e.account.address),chainId:e.chain.id}}var O=class extends p{#e;#t;#n;constructor(e){super(D(e.walletClient)),this.#e=e.walletClient,this.#t=e.ethereum,this.#n=this.#i()}#r(e){if(!this.#e.account)throw new t(e);return{walletClient:this.#e,account:this.#e.account}}async signTypedData(e){let{walletClient:t,account:n}=this.#r(`signTypedData`),{EIP712Domain:r,...i}=e.types;return t.signTypedData({account:n,primaryType:e.primaryType,types:i,domain:e.domain,message:E(e)})}async writeContract(e){let{walletClient:t,account:n}=this.#r(`writeContract`);return t.writeContract({chain:t.chain,account:n,...e})}#i(){return this.#t?x({provider:this.#t,getInitialWalletAccount:()=>D(this.#e),onWalletAccountChange:({next:e})=>{this.walletAccount.setSnapshot(e)}}):()=>{}}onDispose(){this.#n()}};function k(e){return f(new O({walletClient:e.walletClient,ethereum:e.ethereum}),new T({publicClient:e.publicClient}),e)}function A(e){if(!e.account)throw TypeError(`WalletClient has no account`);return e.account}function j(e,t,n){return e.readContract(c(t,n))}function M(e,t){return e.readContract(r(t))}function N(e,t,n){return e.readContract(l(t,n))}function P(e,t,n,r,i){return e.writeContract({chain:e.chain,account:A(e),...u(t,n,r,i)})}function F(e,t,r,i,a,o){return e.writeContract({chain:e.chain,account:A(e),...n(t,r,i,a,o)})}function I(e,t,n,r,i){return e.writeContract({chain:e.chain,account:A(e),...o(t,n,r,i)})}function L(e,t,n,r,i){return e.writeContract({chain:e.chain,account:A(e),...d(t,n,r,i)})}function R(e,t,n,r){return e.writeContract({chain:e.chain,account:A(e),...s(t,n,r)})}function z(t,n,r,i){return t.writeContract({chain:t.chain,account:A(t),...e(n,r,i)})}function B(e,t){return e.readContract(h(t))}function V(e,t){return e.readContract(m(t))}function H(e,t,n,r){return e.readContract(_(t,n,r))}function U(e,t,n){return e.readContract(v(t,n))}function W(e,t,n){return e.readContract(b(t,n))}function G(e,t,n){return e.readContract(g(t,n))}function K(e,t,n){return e.readContract(y(t,n))}export{p as BaseSigner,T as ViemProvider,O as ViemSigner,i as ZamaSDKEvents,k as createConfig,j as readConfidentialBalanceOfContract,W as readConfidentialTokenAddressContract,K as readIsConfidentialTokenValidContract,N as readSupportsInterfaceContract,G as readTokenAddressContract,U as readTokenPairContract,B as readTokenPairsContract,V as readTokenPairsLengthContract,H as readTokenPairsSliceContract,M as readUnderlyingTokenContract,P as writeConfidentialTransferContract,L as writeFinalizeUnwrapContract,R as writeSetOperatorContract,F as writeUnwrapContract,I as writeUnwrapFromBalanceContract,z as writeWrapContract};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/web/index.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import { dn as FhevmRelayerOptions, fn as FhevmRuntimeConfig, n as RelayerConfig, pn as RelayerOptions, r as WebRelayerConfig, un as FhevmClientOptions } from "../types-
|
|
2
|
-
import {
|
|
1
|
+
import { dn as FhevmRelayerOptions, fn as FhevmRuntimeConfig, n as RelayerConfig, pn as RelayerOptions, r as WebRelayerConfig, un as FhevmClientOptions } from "../types-CHepK8MK.js";
|
|
2
|
+
import { EIP1193Provider } from "viem";
|
|
3
|
+
import "@fhevm/sdk/chains";
|
|
4
|
+
//#region src/worker/encrypt-worker-client.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Watchdog deadlines, in milliseconds, for worker lifecycle steps: each is a
|
|
7
|
+
* ceiling on "the worker never answered", not on legitimate slow work. Encrypt
|
|
8
|
+
* operations themselves are not watched: nothing bounds local WASM compute, so
|
|
9
|
+
* a proof may run for as long as it needs.
|
|
10
|
+
*/
|
|
11
|
+
type EncryptWorkerTimeouts = {
|
|
12
|
+
/** Worker startup + module-graph load; a bundler that mishandled the worker URL fails here. */
|
|
13
|
+
readonly spawn: number;
|
|
14
|
+
/** Client init inside the worker realm: chain reads and WASM compilation. */
|
|
15
|
+
readonly init: number;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
3
18
|
//#region src/config/web.d.ts
|
|
4
19
|
/** {@link RelayerOptions} plus the web-only encryption offload switches. */
|
|
5
20
|
interface WebRelayerOptions extends RelayerOptions {
|
package/dist/esm/web/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{n as e,t}from"../fhevm-relayer-BEQ31nmT.js";import{t as n}from"../validation-ClSvPh6P.js";import{z as r}from"zod/mini";const i=e=>r._default(r.number().check(r.positive()),e),a=r.custom(e=>typeof e==`function`),o=r.object({offloadEncrypt:r._default(r.union([r.literal(`auto`),r.boolean()]),`auto`),offloadTimeouts:r.optional(r.object({spawn:i(e.spawn),init:i(e.init)})),offloadWorker:r.optional(r.union([r.string().check(r.minLength(1)),r.instanceof(URL),a]))});function s(e){let{offloadEncrypt:r,offloadTimeouts:i,offloadWorker:a,...s}=e??{},c=n(o,{offloadEncrypt:r,offloadTimeouts:i,offloadWorker:a});return{type:`web`,createRelayer:(e,n,r)=>new t({chain:e,options:s,telemetry:r&&{state:r,runtime:`web`},offloadEncrypt:c.offloadEncrypt,offloadTimeouts:c.offloadTimeouts,offloadWorker:c.offloadWorker,logger:n})}}export{s as web};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{S as e,i as t,r as n}from"./relayer-C3jVhqSK.js";import{A as r,D as i,E as a,F as o,H as s,L as c,M as l,O as u,P as d,c as f,j as p,k as ee,l as m,o as te,u as h,x as ne}from"./erc165-BAd2z3ay.js";import{r as g,t as _}from"./encryption-6AVd-82z.js";import{a as v,f as y,h as b,l as re,o as x,p as ie,t as ae}from"./token-CTvEGQmH.js";import{r as S,t as oe}from"./primitives-Cym-3HKa.js";import{getAddress as C,keccak256 as w,toBytes as T,zeroAddress as se}from"viem";import{z as E}from"zod/mini";function D(e){if(!(e instanceof Error))return null;let t=e.cause;if(typeof t!=`object`||!t||!(`data`in t))return null;let{data:n}=t;return typeof n!=`object`||!n||!(`errorName`in n)?null:typeof n.errorName==`string`?n.errorName:null}var O=class extends n{unwrapTxHash;unwrapRequestId;constructor(e,n,r){super(t.UnshieldAlreadyFinalized,e,r),this.name=`UnshieldAlreadyFinalizedError`,this.unwrapTxHash=n.unwrapTxHash,this.unwrapRequestId=n.unwrapRequestId}};const k=`InvalidUnwrapRequest`,A=w(T(`${k}(bytes32)`)).slice(0,10);function j(e){for(let t=e;t instanceof Error;t=t.cause)if(D(t)===k||t.message.includes(k)||t.message.includes(A))return!0;return!1}const M=[{type:`function`,name:`allowance`,inputs:[{name:`owner`,type:`address`,internalType:`address`},{name:`spender`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`approve`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`balanceOf`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`supportsInterface`,inputs:[{name:`interfaceId`,type:`bytes4`,internalType:`bytes4`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`totalSupply`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`transfer`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFrom`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`event`,name:`Approval`,inputs:[{name:`owner`,type:`address`,indexed:!0,internalType:`address`},{name:`spender`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`Transfer`,inputs:[{name:`from`,type:`address`,indexed:!0,internalType:`address`},{name:`to`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1}];function N(e,t,n,r=`0x`){return{address:e,abi:M,functionName:`transferAndCall`,args:[t,n,r]}}function P(e){return e.startsWith(`0x`)?e:`0x${e}`}function F(e){return w(T(e))}function I(e){return C(P(e.slice(-40)))}function L(e){return e}function R(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function z(e,t){return C(P(R(e,t).slice(-40)))}function B(e,t){return BigInt(`0x`+R(e,t))}function V(e,t){return P(R(e,t))}const H={ConfidentialTransfer:F(`ConfidentialTransfer(address,address,bytes32)`),Wrap:F(`Wrap(address,uint256,bytes32)`),UnwrapRequested:F(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:F(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function U(e){return e.topics[0]!==H.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:I(e.topics[1]),to:I(e.topics[2]),encryptedAmount:L(e.topics[3])}}function W(e){return e.topics[0]!==H.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:I(e.topics[1]),roundedAmount:B(e.data,0),encryptedWrappedAmount:V(e.data,1)}}function G(e){return e.topics[0]!==H.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:I(e.topics[1]),unwrapRequestId:L(e.topics[2]),encryptedAmount:V(e.data,0)}}function K(e){return e.topics[0]!==H.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:I(e.topics[1]),unwrapRequestId:L(e.topics[2]),encryptedAmount:V(e.data,0),cleartextAmount:B(e.data,1)}}function q(e){return U(e)??W(e)??G(e)??K(e)}function ce(e){let t=[];for(let n of e){let e=q(n);e&&t.push(e)}return t}function J(e){for(let t of e){let e=G(t);if(e)return e}return null}function le(e){for(let t of e){let e=W(t);if(e)return e}return null}const ue=[H.ConfidentialTransfer,H.Wrap,H.UnwrapRequested,H.UnwrapFinalized],Y={DelegatedForUserDecryption:F(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:F(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function X(e){return e.topics[0]!==Y.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:I(e.topics[1]),delegate:I(e.topics[2]),contractAddress:z(e.data,0),delegationCounter:B(e.data,1),oldExpirationDate:B(e.data,2),newExpirationDate:B(e.data,3)}}function Z(e){return e.topics[0]!==Y.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:I(e.topics[1]),delegate:I(e.topics[2]),contractAddress:z(e.data,0),delegationCounter:B(e.data,1),oldExpirationDate:B(e.data,2)}}function Q(e){return X(e)??Z(e)}function de(e){let t=[];for(let n of e){let e=Q(n);e&&t.push(e)}return t}function fe(e){for(let t of e){let e=X(t);if(e)return e}return null}function pe(e){for(let t of e){let e=Z(t);if(e)return e}return null}const me=[Y.DelegatedForUserDecryption,Y.RevokedDelegationForUserDecryption];function $(e){return`zama:pending-unshield:${oe(e)}`}const he=E.union([E.pipe(S,E.transform(e=>({unwrapTxHash:e}))),E.pipe(E.object({version:E.literal(1),unwrapTxHash:S,unwrapRequestId:E.optional(S)}),E.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function ge(e,t,n,r){if(r===void 0){await e.set($(t),n);return}await e.set($(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function _e(e,t){let n=$(t),r=await e.get(n);if(r==null)return null;let i=he.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function ve(e,t){await e.delete($(t))}var ye=class extends ae{#e;#t=null;#n=null;#r(e){try{return d(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(t){throw new c(e,{cause:t})}}async underlying(){return this.#f()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#f();this.#n=await this.sdk.provider.readContract(te(e))}catch{this.#n=!1}return this.#n}async allowance(e){let t=await this.#f();return this.sdk.provider.readContract(f(t,C(e),this.address))}async shield(t,r){let i=await v(`shield`,this.sdk.signer,this.sdk.provider),a=await this.isPayable(),o=await this.#f(),s=C(i.address),c;try{c=await this.sdk.provider.readContract(h(o,s))}catch(t){throw t instanceof n?t:new y(`Could not read ERC-20 balance for shield validation (token: ${o})`,{cause:e(t)})}if(c<t)throw new b(`Insufficient ERC-20 balance: requested ${t}, available ${c} (token: ${o})`,{requested:t,available:c,token:o});return a?this.#i(t,o,s,r):this.#a(t,s,r)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?C(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:N(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(t,i){this.#r(`wrap`);let a=await v(`wrap`,this.sdk.signer,this.sdk.provider),o=await this.#f(),s=C(a.address),c;try{c=await this.sdk.provider.readContract(h(o,s))}catch(t){throw t instanceof n?t:new y(`Could not read ERC-20 balance for wrap validation (token: ${o})`,{cause:e(t)})}if(c<t)throw new b(`Insufficient ERC-20 balance: requested ${t}, available ${c} (token: ${o})`,{requested:t,available:c,token:o});let l;try{l=await this.sdk.provider.readContract(f(o,s,this.address))}catch(t){throw t instanceof n?t:new y(`Could not read ERC-20 allowance for wrap validation (token: ${o})`,{cause:e(t)})}if(l<t)throw new ie(`Insufficient allowance for wrap: requested ${t}, approved ${l}. Call approveUnderlying() first (token: ${o}).`,{requested:t,available:l,token:o});let u=i?.to?C(i.to):s;return this.submitTransaction({operation:`wrap`,config:r(this.address,u,t),onSubmitted:i?.onWrapSubmitted})}async#a(e,t,n){this.#r(`shield`);let i=n?.approvalStrategy??`exact`;i!==`skip`&&await this.#m(e,i===`max`,n);let a=n?.to?C(n.to):t;return this.submitTransaction({operation:`shield:approveAndWrap`,config:r(this.address,a,e),onSubmitted:n?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let t=await v(`approveUnderlying`,this.sdk.signer,this.sdk.provider),n=await this.#f(),r=C(t.address),i=e??2n**256n-1n;return i>0n&&await this.sdk.provider.readContract(f(n,r,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:m(n,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:m(n,this.address,i)})}async unshield(e,t){let{skipBalanceCheck:n=!1,onUnwrapSubmitted:r,onFinalizing:i,onFinalizeSubmitted:a}=t??{};n||await this.assertConfidentialBalance(e,`unshield`);let o={onFinalizing:i,onFinalizeSubmitted:a},s=crypto.randomUUID(),c=await this.#o(e,`unshield`);return p(`unshield: onUnwrapSubmitted`,()=>r?.(c.txHash),this.sdk.logger),this.#p(c.unwrapRequestId,c.txHash,s,o,`unshield`)}async unshieldAll(e){let t=crypto.randomUUID(),n=await this.unwrapAll();return p(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(n.txHash),this.sdk.logger),this.#p(n.unwrapRequestId,n.txHash,t,e,`unshield-all`)}async resumeUnshield(e,t){let r;try{r=await this.sdk.provider.waitForTransactionReceipt(e)}catch(e){throw e instanceof n?e:new s(`Failed to get unwrap receipt`,{cause:e})}let i=this.#c(r.logs);if(await this.#l(i))throw await this.#d(`resumeUnshield`),new O(`Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.`,{unwrapTxHash:e,unwrapRequestId:i});return this.#p(i,e,crypto.randomUUID(),t,`resume-unshield`)}async getPendingUnshield(){let e=await _e(this.sdk.storage,this.address);return e?await this.#u(e)?(await this.#d(`getPendingUnshield`),null):e.unwrapTxHash:null}async unwrap(e){return this.#o(e,`unwrap`)}async#o(e,t){this.#r(`unwrap`);let n=C((await v(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:r,inputProof:a}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:n},{operation:t}),[o]=r;if(!o)throw new g(`Encryption returned no encrypted values`);let s=await this.submitTransaction({operation:`unwrap`,config:i(this.address,n,n,o,a)});return{...s,unwrapRequestId:this.#c(s.receipt.logs)}}async unwrapAll(){this.#r(`unwrapAll`);let e=C((await v(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),t=await this.readConfidentialBalanceOf(e);if(re(t))throw new _(`Cannot unshield: balance is zero`);let n=await this.submitTransaction({operation:`unwrapAll`,config:u(this.address,e,e,t)});return{...n,unwrapRequestId:this.#c(n.receipt.logs)}}async finalizeUnwrap(e){return this.#s(e,`finalize-unwrap`)}async#s(e,t){this.#r(`finalizeUnwrap`),await x(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let n=await this.sdk.decryption.decryptPublicValues([e],{operation:t}),r=n.clearValues[e];return l(r,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:ne(this.address,e,r,n.decryptionProof)})}#c(e){let t=J(e.filter(e=>e.address===void 0||C(e.address)===this.address));if(!t)throw new s(`No UnwrapRequested event from this wrapper found in the unwrap receipt`);return t.unwrapRequestId}async#l(e){try{return await this.sdk.provider.readContract(ee(this.address,e))===se}catch{return!1}}async#u(e){let t=e.unwrapRequestId;if(t===void 0)try{let n=await this.sdk.provider.waitForTransactionReceipt(e.unwrapTxHash);t=this.#c(n.logs)}catch{return!1}return this.#l(t)}async#d(e){await p(`${e}: clearPendingUnshield`,()=>ve(this.sdk.storage,this.address),this.sdk.logger)}async#f(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(a(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#p(e,t,n,r,i){this.emit({type:o.UnshieldPhase1Submitted,txHash:t,operationId:n}),await p(`unshield: savePendingUnshield`,()=>ge(this.sdk.storage,this.address,t,e),this.sdk.logger),this.emit({type:o.UnshieldPhase2Started,operationId:n}),p(`unshield: onFinalizing`,()=>r?.onFinalizing?.(),this.sdk.logger);let a;try{a=await this.#s(e,i)}catch(n){throw j(n)?(await this.#d(`unshield`),new O(`The unwrap request was finalized concurrently — the funds were already delivered.`,{unwrapTxHash:t,unwrapRequestId:e},{cause:n})):n}return this.emit({type:o.UnshieldPhase2Submitted,txHash:a.txHash,operationId:n}),p(`unshield: onFinalizeSubmitted`,()=>r?.onFinalizeSubmitted?.(a.txHash),this.sdk.logger),await this.#d(`unshield`),a}async#m(e,t,n){this.#r(`approveUnderlying`);let r=await this.#f(),i=C((await v(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),a=await this.sdk.provider.readContract(f(r,i,this.address));if(a>=e)return;a>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:m(r,this.address,0n)});let o=t?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:m(r,this.address,o),onSubmitted:n?.onApprovalSubmitted})}};export{N as C,V as S,D as T,pe as _,H as a,F as b,U as c,ce as d,Z as f,fe as g,W as h,ue as i,X as l,G as m,me as n,Q as o,K as p,Y as r,de as s,ye as t,q as u,J as v,O as w,I as x,le as y};
|
|
2
|
+
//# sourceMappingURL=wrapped-token-IDUEFpZx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapped-token-3usJd0oi.js","names":["#getUnderlying","#isPayable","#shieldViaTransferAndCall","#shieldViaApproveAndWrap","#requireSigner","#ensureAllowance","#unwrap","#finalizeUnshield","#extractUnwrapRequestId","#isUnwrapRequestConsumed","#clearStoredPendingUnshield","#isPendingUnshieldConsumed","#finalizeUnwrap","#underlying","#underlyingPromise"],"sources":["../../src/errors/revert.ts","../../src/errors/unshield.ts","../../src/abi/erc1363.abi.ts","../../src/contracts/erc1363.ts","../../src/utils/hex.ts","../../src/events/log-decoding.ts","../../src/events/onchain-events.ts","../../src/token/pending-unshield.ts","../../src/token/wrapped-token.ts"],"sourcesContent":["/**\n * Extract the decoded custom error name from a viem ContractFunctionRevertedError,\n * or `null` when the error carries no structured revert data.\n * @internal\n */\nexport function extractRevertErrorName(error: unknown): string | null {\n if (!(error instanceof Error)) {\n return null;\n }\n const cause = error.cause;\n if (typeof cause !== \"object\" || cause === null || !(\"data\" in cause)) {\n return null;\n }\n const { data } = cause;\n if (typeof data !== \"object\" || data === null || !(\"errorName\" in data)) {\n return null;\n }\n return typeof data.errorName === \"string\" ? data.errorName : null;\n}\n","import { keccak256, toBytes, type Hex } from \"viem\";\nimport type { EncryptedValue } from \"../relayer/types\";\nimport { ZamaError, ZamaErrorCode } from \"./base\";\nimport { extractRevertErrorName } from \"./revert\";\n\n/** Structured details identifying the consumed unwrap request. */\nexport interface UnshieldAlreadyFinalizedDetails {\n /** Transaction hash of the original unwrap request. */\n readonly unwrapTxHash: Hex;\n /** Request identifier from the `UnwrapRequested` event. */\n readonly unwrapRequestId: EncryptedValue;\n}\n\n/**\n * The unwrap request was already finalized on-chain: the underlying ERC-20\n * tokens were delivered and there is nothing left to resume. The SDK clears\n * the persisted pending-unshield pointer before throwing, so treat this as a\n * success signal: refresh balances and dismiss any \"resume unshield\" prompt.\n */\nexport class UnshieldAlreadyFinalizedError extends ZamaError {\n /** Transaction hash of the original unwrap request. */\n readonly unwrapTxHash: Hex;\n /** Request identifier from the `UnwrapRequested` event. */\n readonly unwrapRequestId: EncryptedValue;\n\n constructor(message: string, details: UnshieldAlreadyFinalizedDetails, options?: ErrorOptions) {\n super(ZamaErrorCode.UnshieldAlreadyFinalized, message, options);\n this.name = \"UnshieldAlreadyFinalizedError\";\n this.unwrapTxHash = details.unwrapTxHash;\n this.unwrapRequestId = details.unwrapRequestId;\n }\n}\n\nconst INVALID_UNWRAP_REQUEST = \"InvalidUnwrapRequest\";\nconst INVALID_UNWRAP_REQUEST_SELECTOR = keccak256(\n toBytes(`${INVALID_UNWRAP_REQUEST}(bytes32)`),\n).slice(0, 10);\n\n/**\n * True if `error` (or anything on its `cause` chain) is the wrapper's\n * `InvalidUnwrapRequest` custom revert. Prefers viem's structured\n * `cause.data.errorName`, falling back to message matching on the error name\n * and the raw 4-byte selector for non-viem providers.\n * @internal\n */\nexport function isInvalidUnwrapRequestRevert(error: unknown): boolean {\n for (let current = error; current instanceof Error; current = current.cause) {\n if (extractRevertErrorName(current) === INVALID_UNWRAP_REQUEST) {\n return true;\n }\n if (\n current.message.includes(INVALID_UNWRAP_REQUEST) ||\n current.message.includes(INVALID_UNWRAP_REQUEST_SELECTOR)\n ) {\n return true;\n }\n }\n return false;\n}\n","// DO NOT EDIT: generated by `pnpm abi:build` from\n// contracts/out/IERC1363.sol/IERC1363.json.\n// Regenerate after `pnpm contracts:build`; `pnpm abi:check` enforces this in CI.\nexport const erc1363Abi = [\n {\n type: \"function\",\n name: \"allowance\",\n inputs: [\n { name: \"owner\", type: \"address\", internalType: \"address\" },\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n ],\n outputs: [{ name: \"\", type: \"uint256\", internalType: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"approve\",\n inputs: [\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"approveAndCall\",\n inputs: [\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"approveAndCall\",\n inputs: [\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"data\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"balanceOf\",\n inputs: [{ name: \"account\", type: \"address\", internalType: \"address\" }],\n outputs: [{ name: \"\", type: \"uint256\", internalType: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"supportsInterface\",\n inputs: [{ name: \"interfaceId\", type: \"bytes4\", internalType: \"bytes4\" }],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"totalSupply\",\n inputs: [],\n outputs: [{ name: \"\", type: \"uint256\", internalType: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"transfer\",\n inputs: [\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferAndCall\",\n inputs: [\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferAndCall\",\n inputs: [\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"data\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferFrom\",\n inputs: [\n { name: \"from\", type: \"address\", internalType: \"address\" },\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferFromAndCall\",\n inputs: [\n { name: \"from\", type: \"address\", internalType: \"address\" },\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"data\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferFromAndCall\",\n inputs: [\n { name: \"from\", type: \"address\", internalType: \"address\" },\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"event\",\n name: \"Approval\",\n inputs: [\n { name: \"owner\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"spender\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"value\", type: \"uint256\", indexed: false, internalType: \"uint256\" },\n ],\n anonymous: false,\n },\n {\n type: \"event\",\n name: \"Transfer\",\n inputs: [\n { name: \"from\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"to\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"value\", type: \"uint256\", indexed: false, internalType: \"uint256\" },\n ],\n anonymous: false,\n },\n] as const;\n","import type { Address, Hex } from \"viem\";\nimport { erc1363Abi } from \"../abi/erc1363.abi\";\n\n/**\n * Returns the contract config for an ERC-1363 `transferAndCall`.\n *\n * @param tokenAddress - The ERC-20 token to transfer from (the underlying, not the wrapper).\n * @param to - The recipient of the ERC-20 transfer. In `Token.shield`, this is\n * the wrapper contract whose `onTransferReceived` callback mints\n * confidential tokens to the address encoded in `data`.\n * @param amount - The amount to transfer.\n * @param data - Raw 20-byte recipient address for shield-to-other (decoded by\n * the wrapper as `address(bytes20(data))`). Empty `0x` for self-shield —\n * the wrapper falls back to `from`.\n */\nexport function transferAndCallContract(\n tokenAddress: Address,\n to: Address,\n amount: bigint,\n data: Hex = \"0x\",\n) {\n return {\n address: tokenAddress,\n abi: erc1363Abi,\n functionName: \"transferAndCall\",\n args: [to, amount, data],\n } as const;\n}\n","import type { Hex } from \"viem\";\nimport { assertCondition } from \"./assertions\";\n\n/** Normalize a un-prefixed hex payload to a 0x-prefixed `Hex` value. */\nexport function prefixHex(value: string): Hex {\n return (value.startsWith(\"0x\") ? value : `0x${value}`) as Hex;\n}\n\n/** Convert a public `Hex` value back an unprefixed format. */\nexport function unprefixHex(value: Hex): string {\n assertCondition(value.startsWith(\"0x\"), `Expected 0x-prefixed hex, got: ${value}`);\n return value.slice(2);\n}\n","/**\n * Primitives for decoding raw EVM logs without an ABI decoder.\n *\n * @internal\n */\n\nimport { getAddress, keccak256, toBytes, type Address, type Hex } from \"viem\";\nimport type { EncryptedValue } from \"../relayer/types\";\nimport { prefixHex } from \"../utils\";\n\n/** Hashes the canonical signature — `Joined(uint256,address,bytes32)`, not the declaration with parameter names. */\nexport function eventTopic(signature: string): Hex {\n return keccak256(toBytes(signature));\n}\n\nexport function topicToAddress(topic: Hex): Address {\n return getAddress(prefixHex(topic.slice(-40)));\n}\n\nexport function topicToBytes32(topic: Hex): EncryptedValue {\n // EVM topics are already 32-byte 0x-prefixed hex — cast directly\n return topic as EncryptedValue;\n}\n\nexport function wordAt(data: Hex, index: number): string {\n // data starts with \"0x\", each word is 64 hex chars (32 bytes)\n const start = 2 + index * 64;\n const word = data.slice(start, start + 64);\n return word.length === 64 ? word : word.padEnd(64, \"0\");\n}\n\nexport function wordToAddress(data: Hex, index: number): Address {\n return getAddress(prefixHex(wordAt(data, index).slice(-40)));\n}\n\nexport function wordToBigInt(data: Hex, index: number): bigint {\n return BigInt(\"0x\" + wordAt(data, index));\n}\n\nexport function wordToBytes32(data: Hex, index: number): EncryptedValue {\n // wordAt returns exactly 64 hex chars — prefix and cast directly\n return prefixHex(wordAt(data, index)) as EncryptedValue;\n}\n","/**\n * Framework-agnostic event decoders for confidential token contracts.\n * Works with raw log data from any provider.\n */\n\nimport type { EncryptedValue } from \"../relayer/types\";\nimport type { Address } from \"viem\";\nimport type { RawLog } from \"../types/transaction\";\nimport {\n eventTopic,\n topicToAddress,\n topicToBytes32,\n wordToAddress,\n wordToBigInt,\n wordToBytes32,\n} from \"./log-decoding\";\nexport type { RawLog } from \"../types/transaction\";\n\n// ---------------------------------------------------------------------------\n// Event topic0 constants (keccak256 of canonical signature)\n// ---------------------------------------------------------------------------\n\n/**\n * Event topic0 constants (keccak256 of the canonical Solidity signature).\n * Pass to `getLogs({ topics: [Object.values(Topics)] })` to fetch all events.\n */\nexport const Topics = {\n /** `ConfidentialTransfer(address indexed from, address indexed to, bytes32 indexed amount)` */\n ConfidentialTransfer: eventTopic(\"ConfidentialTransfer(address,address,bytes32)\"),\n /** `Wrap(address indexed to, uint256 roundedAmount, euint64 encryptedWrappedAmount)` */\n Wrap: eventTopic(\"Wrap(address,uint256,bytes32)\"),\n /** `UnwrapRequested(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 amount)` */\n UnwrapRequested: eventTopic(\"UnwrapRequested(address,bytes32,bytes32)\"),\n /** `UnwrapFinalized(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 encryptedAmount, uint64 cleartextAmount)` */\n UnwrapFinalized: eventTopic(\"UnwrapFinalized(address,bytes32,bytes32,uint64)\"),\n} as const;\n\n// ---------------------------------------------------------------------------\n// Typed event interfaces\n// ---------------------------------------------------------------------------\n\n/** Decoded `ConfidentialTransfer` event — an encrypted token transfer. */\nexport interface ConfidentialTransferEvent {\n /** Event name discriminant. */\n readonly eventName: \"ConfidentialTransfer\";\n /** Sender address. */\n readonly from: Address;\n /** Receiver address. */\n readonly to: Address;\n /** FHE encrypted value for the transferred amount. */\n readonly encryptedAmount: EncryptedValue;\n}\n\n/**\n * Decoded `Wrap` event — an ERC-20 shield (wrap) operation. Emitted alongside a\n * `ConfidentialTransfer(from=zeroAddress, ...)`; `encryptedWrappedAmount` is the same FHE\n * handle that lands in `ConfidentialTransfer.encryptedAmount`.\n */\nexport interface WrapEvent {\n /** Event name discriminant. */\n readonly eventName: \"Wrap\";\n /** Receiver of the minted confidential tokens. */\n readonly to: Address;\n /** Cleartext underlying ERC-20 tokens deposited, rounded down to a multiple of the rate. */\n readonly roundedAmount: bigint;\n /** FHE encrypted value for the wrapped (minted) amount. */\n readonly encryptedWrappedAmount: EncryptedValue;\n}\n\n/** Decoded `UnwrapRequested` event — an unshield request submitted. */\nexport interface UnwrapRequestedEvent {\n /** Event name discriminant. */\n readonly eventName: \"UnwrapRequested\";\n /** Address that will receive the unwrapped ERC-20 tokens. */\n readonly receiver: Address;\n /** FHE encrypted value for the requested unshield amount. */\n readonly encryptedAmount: EncryptedValue;\n /** Request identifier from the `UnwrapRequested` event topic. */\n readonly unwrapRequestId: EncryptedValue;\n}\n\n/** Decoded `UnwrapFinalized` event — an unshield completed on-chain. */\nexport interface UnwrapFinalizedEvent {\n /** Event name discriminant. */\n readonly eventName: \"UnwrapFinalized\";\n /** Address receiving the unwrapped ERC-20 tokens. */\n readonly receiver: Address;\n /** FHE encrypted value of the burnt confidential balance. */\n readonly encryptedAmount: EncryptedValue;\n /** Cleartext amount of underlying ERC-20 tokens returned. */\n readonly cleartextAmount: bigint;\n /** Request identifier from the `UnwrapFinalized` event topic. */\n readonly unwrapRequestId: EncryptedValue;\n}\n\n/** Union of all decoded confidential token event types. */\nexport type OnChainEvent =\n | ConfidentialTransferEvent\n | WrapEvent\n | UnwrapRequestedEvent\n | UnwrapFinalizedEvent;\n\n// ---------------------------------------------------------------------------\n// Individual decoders\n// ---------------------------------------------------------------------------\n\n/**\n * ConfidentialTransfer(address indexed from, address indexed to, bytes32 indexed amount)\n * All 3 params indexed → topics[1..3], no data.\n */\nexport function decodeConfidentialTransfer(log: RawLog): ConfidentialTransferEvent | null {\n if (log.topics[0] !== Topics.ConfidentialTransfer) {\n return null;\n }\n if (log.topics.length < 4) {\n return null;\n }\n\n return {\n eventName: \"ConfidentialTransfer\",\n from: topicToAddress(log.topics[1]!),\n to: topicToAddress(log.topics[2]!),\n encryptedAmount: topicToBytes32(log.topics[3]!),\n };\n}\n\n/**\n * Wrap(address indexed to, uint256 roundedAmount, euint64 encryptedWrappedAmount)\n * Indexed: to (topics[1])\n * Data: roundedAmount (uint256), encryptedWrappedAmount (bytes32)\n */\nexport function decodeWrap(log: RawLog): WrapEvent | null {\n if (log.topics[0] !== Topics.Wrap) {\n return null;\n }\n if (log.topics.length < 2) {\n return null;\n }\n\n return {\n eventName: \"Wrap\",\n to: topicToAddress(log.topics[1]!),\n roundedAmount: wordToBigInt(log.data, 0),\n encryptedWrappedAmount: wordToBytes32(log.data, 1),\n };\n}\n\n/**\n * UnwrapRequested(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 amount)\n */\nexport function decodeUnwrapRequested(log: RawLog): UnwrapRequestedEvent | null {\n if (log.topics[0] !== Topics.UnwrapRequested) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"UnwrapRequested\",\n receiver: topicToAddress(log.topics[1]!),\n unwrapRequestId: topicToBytes32(log.topics[2]!),\n encryptedAmount: wordToBytes32(log.data, 0),\n };\n}\n\n/**\n * UnwrapFinalized(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 encryptedAmount, uint64 cleartextAmount)\n */\nexport function decodeUnwrapFinalized(log: RawLog): UnwrapFinalizedEvent | null {\n if (log.topics[0] !== Topics.UnwrapFinalized) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"UnwrapFinalized\",\n receiver: topicToAddress(log.topics[1]!),\n unwrapRequestId: topicToBytes32(log.topics[2]!),\n encryptedAmount: wordToBytes32(log.data, 0),\n cleartextAmount: wordToBigInt(log.data, 1),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Convenience helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Try all decoders on a single log and return the first match, or `null`.\n *\n * @example\n * ```ts\n * const event = decodeOnChainEvent(log);\n * if (event?.eventName === \"ConfidentialTransfer\") {\n * console.log(event.from, event.to);\n * }\n * ```\n */\nexport function decodeOnChainEvent(log: RawLog): OnChainEvent | null {\n return (\n decodeConfidentialTransfer(log) ??\n decodeWrap(log) ??\n decodeUnwrapRequested(log) ??\n decodeUnwrapFinalized(log)\n );\n}\n\n/**\n * Batch-decode an array of logs, skipping unrecognized entries.\n *\n * @example\n * ```ts\n * const events = decodeOnChainEvents(receipt.logs);\n * ```\n */\nexport function decodeOnChainEvents(logs: readonly RawLog[]): OnChainEvent[] {\n const events: OnChainEvent[] = [];\n for (const log of logs) {\n const event = decodeOnChainEvent(log);\n if (event) {\n events.push(event);\n }\n }\n return events;\n}\n\n/**\n * Find the first {@link UnwrapRequestedEvent} in a logs array.\n *\n * @example\n * ```ts\n * const event = findUnwrapRequested(receipt.logs);\n * if (event) console.log(event.receiver, event.encryptedAmount);\n * ```\n */\nexport function findUnwrapRequested(logs: readonly RawLog[]): UnwrapRequestedEvent | null {\n for (const log of logs) {\n const event = decodeUnwrapRequested(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * Find the first {@link WrapEvent} in a logs array.\n *\n * @example\n * ```ts\n * const event = findWrap(receipt.logs);\n * if (event) console.log(event.to, event.roundedAmount);\n * ```\n */\nexport function findWrap(logs: readonly RawLog[]): WrapEvent | null {\n for (const log of logs) {\n const event = decodeWrap(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * All confidential token event topic0 hashes.\n * Pass to `getLogs({ topics: [TOKEN_TOPICS] })` to fetch\n * all confidential token events in a single RPC call.\n */\nexport const TOKEN_TOPICS = [\n Topics.ConfidentialTransfer,\n Topics.Wrap,\n Topics.UnwrapRequested,\n Topics.UnwrapFinalized,\n] as const;\n\n// ---------------------------------------------------------------------------\n// ACL delegation event topic0 constants\n// ---------------------------------------------------------------------------\n\n/**\n * ACL delegation event topic0 constants (keccak256 of the canonical Solidity signature).\n * These are ACL events, NOT token events — they are emitted by the ACL contract.\n */\nexport const AclTopics = {\n /** `DelegatedForUserDecryption(address indexed delegator, address indexed delegate, address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate, uint64 newExpirationDate)` */\n DelegatedForUserDecryption: eventTopic(\n \"DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)\",\n ),\n /** `RevokedDelegationForUserDecryption(address indexed delegator, address indexed delegate, address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate)` */\n RevokedDelegationForUserDecryption: eventTopic(\n \"RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)\",\n ),\n} as const;\n\n// ---------------------------------------------------------------------------\n// ACL delegation event interfaces\n// ---------------------------------------------------------------------------\n\n/** Decoded `DelegatedForUserDecryption` event — a delegation was created or renewed. */\nexport interface DelegatedForUserDecryptionEvent {\n /** Event name discriminant. */\n readonly eventName: \"DelegatedForUserDecryption\";\n /** Address of the delegator (the account granting access). */\n readonly delegator: Address;\n /** Address of the delegate (the account receiving access). */\n readonly delegate: Address;\n /** Contract address the delegation applies to. */\n readonly contractAddress: Address;\n /** Monotonic delegation counter. */\n readonly delegationCounter: bigint;\n /** Previous expiration timestamp (0 if first delegation). */\n readonly oldExpirationDate: bigint;\n /** New expiration timestamp. */\n readonly newExpirationDate: bigint;\n}\n\n/** Decoded `RevokedDelegationForUserDecryption` event — a delegation was revoked. */\nexport interface RevokedDelegationForUserDecryptionEvent {\n /** Event name discriminant. */\n readonly eventName: \"RevokedDelegationForUserDecryption\";\n /** Address of the delegator. */\n readonly delegator: Address;\n /** Address of the delegate. */\n readonly delegate: Address;\n /** Contract address the revocation applies to. */\n readonly contractAddress: Address;\n /** Monotonic delegation counter. */\n readonly delegationCounter: bigint;\n /** Expiration date that was active before revocation. */\n readonly oldExpirationDate: bigint;\n}\n\n/** Union of all decoded ACL delegation event types. */\nexport type AclEvent = DelegatedForUserDecryptionEvent | RevokedDelegationForUserDecryptionEvent;\n\n// ---------------------------------------------------------------------------\n// ACL delegation event decoders\n// ---------------------------------------------------------------------------\n\n/**\n * DelegatedForUserDecryption(address indexed delegator, address indexed delegate,\n * address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate, uint64 newExpirationDate)\n * Indexed: delegator (topics[1]), delegate (topics[2])\n * Data: contractAddress, delegationCounter, oldExpirationDate, newExpirationDate\n */\nexport function decodeDelegatedForUserDecryption(\n log: RawLog,\n): DelegatedForUserDecryptionEvent | null {\n if (log.topics[0] !== AclTopics.DelegatedForUserDecryption) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"DelegatedForUserDecryption\",\n delegator: topicToAddress(log.topics[1]!),\n delegate: topicToAddress(log.topics[2]!),\n contractAddress: wordToAddress(log.data, 0),\n delegationCounter: wordToBigInt(log.data, 1),\n oldExpirationDate: wordToBigInt(log.data, 2),\n newExpirationDate: wordToBigInt(log.data, 3),\n };\n}\n\n/**\n * RevokedDelegationForUserDecryption(address indexed delegator, address indexed delegate,\n * address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate)\n * Indexed: delegator (topics[1]), delegate (topics[2])\n * Data: contractAddress, delegationCounter, oldExpirationDate\n */\nexport function decodeRevokedDelegationForUserDecryption(\n log: RawLog,\n): RevokedDelegationForUserDecryptionEvent | null {\n if (log.topics[0] !== AclTopics.RevokedDelegationForUserDecryption) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"RevokedDelegationForUserDecryption\",\n delegator: topicToAddress(log.topics[1]!),\n delegate: topicToAddress(log.topics[2]!),\n contractAddress: wordToAddress(log.data, 0),\n delegationCounter: wordToBigInt(log.data, 1),\n oldExpirationDate: wordToBigInt(log.data, 2),\n };\n}\n\n/**\n * Try all ACL delegation decoders on a single log and return the first match, or `null`.\n */\nexport function decodeAclEvent(log: RawLog): AclEvent | null {\n return decodeDelegatedForUserDecryption(log) ?? decodeRevokedDelegationForUserDecryption(log);\n}\n\n/**\n * Batch-decode an array of logs for ACL delegation events, skipping unrecognized entries.\n */\nexport function decodeAclEvents(logs: readonly RawLog[]): AclEvent[] {\n const events: AclEvent[] = [];\n for (const log of logs) {\n const event = decodeAclEvent(log);\n if (event) {\n events.push(event);\n }\n }\n return events;\n}\n\n/**\n * Find the first {@link DelegatedForUserDecryptionEvent} in a logs array.\n */\nexport function findDelegatedForUserDecryption(\n logs: readonly RawLog[],\n): DelegatedForUserDecryptionEvent | null {\n for (const log of logs) {\n const event = decodeDelegatedForUserDecryption(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * Find the first {@link RevokedDelegationForUserDecryptionEvent} in a logs array.\n */\nexport function findRevokedDelegationForUserDecryption(\n logs: readonly RawLog[],\n): RevokedDelegationForUserDecryptionEvent | null {\n for (const log of logs) {\n const event = decodeRevokedDelegationForUserDecryption(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * Both ACL delegation event topic0 hashes.\n * Pass to `getLogs({ topics: [ACL_TOPICS] })` to fetch\n * all delegation events in a single RPC call.\n */\nexport const ACL_TOPICS = [\n AclTopics.DelegatedForUserDecryption,\n AclTopics.RevokedDelegationForUserDecryption,\n] as const;\n","import type { Address, Hex } from \"viem\";\nimport { z } from \"zod/mini\";\nimport { checksum, hex } from \"../schemas/primitives\";\nimport type { GenericStorage } from \"../types\";\nimport type { EncryptedValue } from \"../relayer/types\";\n\nconst STORAGE_PREFIX = \"zama:pending-unshield:\";\nconst CURRENT_VERSION = 1;\n\n/**\n * Persisted state for an in-progress unshield request.\n * Used to resume an interrupted unshield after page reload.\n *\n * @internal\n */\nexport interface PendingUnshieldRequest {\n /** Transaction hash of the original unwrap call. */\n readonly unwrapTxHash: Hex;\n /**\n * Request identifier from the `UnwrapRequested` event.\n * Always populated for entries persisted by this SDK version; pass it as\n * `unwrapRequestId` to `finalizeUnwrap`. Absent only when re-loading a\n * pending unshield serialized by an older SDK version that did not\n * record this field — in that case pass the `encryptedAmount` from the\n * `UnwrapRequested` event to `finalizeUnwrap` instead.\n */\n readonly unwrapRequestId?: EncryptedValue;\n}\n\ninterface StoredPendingUnshieldRequest extends PendingUnshieldRequest {\n readonly version: typeof CURRENT_VERSION;\n}\n\nfunction storageKey(wrapperAddress: Address): string {\n return `${STORAGE_PREFIX}${checksum(wrapperAddress)}`;\n}\n\nconst PendingUnshieldRequestSchema = z.union([\n z.pipe(\n hex,\n z.transform((unwrapTxHash: Hex) => ({ unwrapTxHash })),\n ),\n z.pipe(\n z.object({\n version: z.literal(CURRENT_VERSION),\n unwrapTxHash: hex,\n unwrapRequestId: z.optional(hex),\n }),\n z.transform(\n ({\n unwrapTxHash,\n unwrapRequestId,\n }: {\n version: typeof CURRENT_VERSION;\n unwrapTxHash: Hex;\n unwrapRequestId?: Hex;\n }) => ({ unwrapTxHash, unwrapRequestId }),\n ),\n ),\n]);\n\n/**\n * Persist the unwrap tx hash so an interrupted unshield can be resumed later\n * (e.g. after a page reload).\n *\n * @internal\n */\nexport async function savePendingUnshield(\n storage: GenericStorage,\n wrapperAddress: Address,\n unwrapTxHash: Hex,\n unwrapRequestId?: EncryptedValue,\n): Promise<void> {\n if (unwrapRequestId === undefined) {\n await storage.set(storageKey(wrapperAddress), unwrapTxHash);\n return;\n }\n\n await storage.set(storageKey(wrapperAddress), {\n version: CURRENT_VERSION,\n unwrapTxHash,\n unwrapRequestId,\n } satisfies StoredPendingUnshieldRequest);\n}\n\n/**\n * Load a previously saved unwrap tx hash, or `null` if none exists.\n *\n * @internal\n */\nexport async function loadPendingUnshield(\n storage: GenericStorage,\n wrapperAddress: Address,\n): Promise<Hex | null> {\n const request = await loadPendingUnshieldRequest(storage, wrapperAddress);\n return request?.unwrapTxHash ?? null;\n}\n\n/**\n * Load a previously saved unwrap request, including `unwrapRequestId` when available.\n *\n * `resumeUnshield()` only needs `unwrapTxHash`: it reloads the transaction receipt and\n * rediscovers the right finalize input from the emitted `UnwrapRequested` event.\n * Use `unwrapRequestId` directly only for custom flows that call `finalizeUnwrap()`\n * without reloading the original unwrap receipt.\n *\n * @internal\n */\nexport async function loadPendingUnshieldRequest(\n storage: GenericStorage,\n wrapperAddress: Address,\n): Promise<PendingUnshieldRequest | null> {\n const key = storageKey(wrapperAddress);\n const value = await storage.get<Hex | StoredPendingUnshieldRequest>(key);\n if (value === null || value === undefined) {\n return null;\n }\n const parsed = PendingUnshieldRequestSchema.safeParse(value);\n if (!parsed.success) {\n await storage.delete(key);\n return null;\n }\n return parsed.data as PendingUnshieldRequest;\n}\n\n/**\n * Clear the saved unwrap tx hash after a successful finalization.\n *\n * @internal\n */\nexport async function clearPendingUnshield(\n storage: GenericStorage,\n wrapperAddress: Address,\n): Promise<void> {\n await storage.delete(storageKey(wrapperAddress));\n}\n","import { getAddress, zeroAddress, type Address, type Hex } from \"viem\";\nimport {\n allowanceContract,\n approveContract,\n balanceOfContract,\n finalizeUnwrapContract,\n isPayableTokenContract,\n transferAndCallContract,\n underlyingContract,\n unwrapContract,\n unwrapFromBalanceContract,\n unwrapRequesterContract,\n wrapContract,\n} from \"../contracts\";\nimport {\n DecryptionFailedError,\n ERC20ReadFailedError,\n EncryptionFailedError,\n InsufficientAllowanceError,\n InsufficientERC20BalanceError,\n SignerNotConfiguredError,\n TransactionRevertedError,\n UnshieldAlreadyFinalizedError,\n ZamaError,\n} from \"../errors\";\nimport { isInvalidUnwrapRequestRevert } from \"../errors/unshield\";\nimport { findUnwrapRequested } from \"../events/onchain-events\";\nimport { ZamaSDKEvents } from \"../events/sdk-events\";\nimport type { EncryptedValue } from \"../relayer/types\";\nimport type {\n GenericSigner,\n ShieldCallbacks,\n ShieldOptions,\n TransactionResult,\n UnshieldCallbacks,\n UnshieldOptions,\n UnwrapResult,\n WrapOptions,\n} from \"../types\";\nimport type { RawLog } from \"../types/transaction\";\nimport { toError } from \"../utils\";\nimport { requireAlignedWalletAccount, requireChainAlignment } from \"../utils/alignment\";\nimport { assertBigint, assertNonNullable } from \"../utils/assertions\";\nimport { isEncryptedValueZero } from \"../utils/handles\";\nimport type { TelemetryOperation } from \"../telemetry\";\nimport { swallow } from \"../utils/swallow\";\nimport {\n clearPendingUnshield,\n loadPendingUnshieldRequest,\n savePendingUnshield,\n type PendingUnshieldRequest,\n} from \"./pending-unshield\";\nimport { Token } from \"./token\";\n\n/**\n * Confidential ERC-20 wrapper (ERC-7984 ERC20Wrapper).\n *\n * Extends {@link Token} with wrapper-specific operations:\n * - `shield` / `unshield` — convert between the underlying ERC-20 and confidential balance\n * - `unwrap` / `unwrapAll` / `finalizeUnwrap` — low-level two-phase primitives\n * - `underlying` / `allowance` — wrapper reads\n *\n * `WrappedToken.address` is the wrapper contract address itself — the wrapper\n * IS the confidential token.\n */\nexport class WrappedToken extends Token {\n #underlying: Address | undefined;\n #underlyingPromise: Promise<Address> | null = null;\n #isPayable: boolean | null = null;\n\n /** Resolve `sdk.signer` or throw {@link SignerNotConfiguredError} tagged with `operation`. */\n #requireSigner(operation: string): GenericSigner {\n try {\n assertNonNullable(this.sdk.signer, \"WrappedToken.sdk.signer\");\n return this.sdk.signer;\n } catch (cause) {\n throw new SignerNotConfiguredError(operation, { cause });\n }\n }\n\n // WRAPPER READS\n\n /**\n * Read the underlying ERC-20 token address from the wrapper contract.\n *\n * @returns The underlying ERC-20 token address.\n */\n async underlying(): Promise<Address> {\n return this.#getUnderlying();\n }\n\n /**\n * Check whether the underlying ERC-20 supports ERC-1363 (payable token).\n * Result is cached per WrappedToken instance (negative results included):\n * once we know an underlying does not support ERC-1363, subsequent shields\n * go straight to the `approve` + `wrap` path without re-probing.\n */\n async isPayable(): Promise<boolean> {\n if (this.#isPayable !== null) {\n return this.#isPayable;\n }\n try {\n const underlying = await this.#getUnderlying();\n this.#isPayable = await this.sdk.provider.readContract(isPayableTokenContract(underlying));\n } catch {\n this.#isPayable = false;\n }\n return this.#isPayable;\n }\n\n /**\n * Read the ERC-20 allowance granted by `owner` to this wrapper for the\n * underlying token.\n *\n * @param owner - The owner address whose allowance to read.\n * @returns The current allowance as a bigint.\n */\n async allowance(owner: Address): Promise<bigint> {\n const underlying = await this.#getUnderlying();\n return this.sdk.provider.readContract(\n allowanceContract(underlying, getAddress(owner), this.address),\n );\n }\n\n // SHIELD (ERC-20 → confidential)\n\n /**\n * Shield public ERC-20 tokens into confidential tokens.\n *\n * The execution path is decided automatically by ERC-165 introspection on\n * the underlying ERC-20:\n * - **`transferAndCall`** (single tx): when the underlying supports\n * ERC-1363, no approval is required — the wrapper's `onTransferReceived`\n * callback mints confidential tokens directly. `approvalStrategy` is\n * **ignored** on this path. See {@link ShieldPath}.\n * - **`approveAndWrap`** (two-tx fallback): otherwise, an `approve` is\n * followed by a `wrap`. Approval is controlled by `approvalStrategy`\n * (`\"exact\"` by default, `\"max\"` for unlimited, `\"skip\"` to opt out).\n *\n * The ERC-20 balance is validated before submitting (public read, no\n * signing required) so the call works for all wallet types, including\n * smart wallets.\n *\n * @param amount - The plaintext amount to shield.\n * @param options - Optional: `approvalStrategy`, `to`, callbacks.\n * @returns The transaction hash and mined receipt.\n * @throws if signer and provider are on different chains. {@link ChainMismatchError}\n * @throws if the ERC-20 balance is less than `amount`. {@link InsufficientERC20BalanceError}\n * @throws if the ERC-20 approval or shield transaction reverts. {@link TransactionRevertedError}\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.shield(1000n);\n * ```\n */\n async shield(amount: bigint, options?: ShieldOptions): Promise<TransactionResult> {\n const account = await requireAlignedWalletAccount(\"shield\", this.sdk.signer, this.sdk.provider);\n\n const isPayableToken = await this.isPayable();\n const underlying = await this.#getUnderlying();\n const userAddress = getAddress(account.address);\n\n // ERC-20 balance check always runs (public read, no signing needed, works for all wallet types)\n let erc20Balance: bigint;\n try {\n erc20Balance = await this.sdk.provider.readContract(\n balanceOfContract(underlying, userAddress),\n );\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new ERC20ReadFailedError(\n `Could not read ERC-20 balance for shield validation (token: ${underlying})`,\n { cause: toError(error) },\n );\n }\n if (erc20Balance < amount) {\n throw new InsufficientERC20BalanceError(\n `Insufficient ERC-20 balance: requested ${amount}, available ${erc20Balance} (token: ${underlying})`,\n { requested: amount, available: erc20Balance, token: underlying },\n );\n }\n\n if (isPayableToken) {\n return this.#shieldViaTransferAndCall(amount, underlying, userAddress, options);\n }\n return this.#shieldViaApproveAndWrap(amount, userAddress, options);\n }\n\n async #shieldViaTransferAndCall(\n amount: bigint,\n underlying: Address,\n userAddress: Address,\n options?: ShieldOptions,\n ): Promise<TransactionResult> {\n this.#requireSigner(\"shield\");\n const recipient = options?.to ? getAddress(options.to) : userAddress;\n // ERC7984ERC20Wrapper.onTransferReceived decodes the recipient via\n // `address(bytes20(data))` — i.e. the first 20 bytes of `data`. We pass\n // the raw 20-byte address (not ABI-encoded), and the empty payload `0x`\n // for self-shield so the wrapper falls back to `from`.\n const data: Hex = recipient === userAddress ? \"0x\" : recipient;\n\n return this.submitTransaction({\n operation: \"shield:transferAndCall\",\n config: transferAndCallContract(underlying, this.address, amount, data),\n onSubmitted: options?.onShieldSubmitted,\n });\n }\n\n /**\n * Wrap already-approved underlying ERC-20 into confidential tokens.\n *\n * Escape hatch for splitting shield across two signatures: call\n * {@link approveUnderlying} first, then `wrap`. Most callers should use\n * {@link shield}, which routes and orchestrates approval automatically.\n *\n * Validates the ERC-20 balance and the allowance granted to this wrapper\n * (public reads, no signing) and fails early with a clear error.\n *\n * @param amount - The plaintext amount to wrap.\n * @param options - Optional `to` recipient and `onWrapSubmitted` callback.\n * @returns The transaction hash and mined receipt.\n * @throws if reading the ERC-20 balance or allowance fails. {@link ERC20ReadFailedError}\n * @throws if the ERC-20 balance is less than `amount`. {@link InsufficientERC20BalanceError}\n * @throws if the allowance granted to the wrapper is less than `amount`. {@link InsufficientAllowanceError}\n *\n * @example\n * ```ts\n * await wrappedToken.approveUnderlying(1000n);\n * await wrappedToken.wrap(1000n);\n * ```\n */\n async wrap(amount: bigint, options?: WrapOptions): Promise<TransactionResult> {\n this.#requireSigner(\"wrap\");\n const account = await requireAlignedWalletAccount(\"wrap\", this.sdk.signer, this.sdk.provider);\n const underlying = await this.#getUnderlying();\n const userAddress = getAddress(account.address);\n\n let erc20Balance: bigint;\n try {\n erc20Balance = await this.sdk.provider.readContract(\n balanceOfContract(underlying, userAddress),\n );\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new ERC20ReadFailedError(\n `Could not read ERC-20 balance for wrap validation (token: ${underlying})`,\n { cause: toError(error) },\n );\n }\n if (erc20Balance < amount) {\n throw new InsufficientERC20BalanceError(\n `Insufficient ERC-20 balance: requested ${amount}, available ${erc20Balance} (token: ${underlying})`,\n { requested: amount, available: erc20Balance, token: underlying },\n );\n }\n\n let allowance: bigint;\n try {\n allowance = await this.sdk.provider.readContract(\n allowanceContract(underlying, userAddress, this.address),\n );\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new ERC20ReadFailedError(\n `Could not read ERC-20 allowance for wrap validation (token: ${underlying})`,\n { cause: toError(error) },\n );\n }\n if (allowance < amount) {\n throw new InsufficientAllowanceError(\n `Insufficient allowance for wrap: requested ${amount}, approved ${allowance}. Call approveUnderlying() first (token: ${underlying}).`,\n { requested: amount, available: allowance, token: underlying },\n );\n }\n\n const recipient = options?.to ? getAddress(options.to) : userAddress;\n return this.submitTransaction({\n operation: \"wrap\",\n config: wrapContract(this.address, recipient, amount),\n onSubmitted: options?.onWrapSubmitted,\n });\n }\n\n async #shieldViaApproveAndWrap(\n amount: bigint,\n userAddress: Address,\n options?: ShieldOptions,\n ): Promise<TransactionResult> {\n this.#requireSigner(\"shield\");\n const strategy = options?.approvalStrategy ?? \"exact\";\n if (strategy !== \"skip\") {\n await this.#ensureAllowance(amount, strategy === \"max\", options);\n }\n const recipient = options?.to ? getAddress(options.to) : userAddress;\n return this.submitTransaction({\n operation: \"shield:approveAndWrap\",\n config: wrapContract(this.address, recipient, amount),\n onSubmitted: options?.onShieldSubmitted,\n });\n }\n\n /**\n * Approve this wrapper contract to spend the underlying ERC-20.\n * Defaults to max uint256. Resets to zero first if there's an existing\n * non-zero allowance (required by tokens like USDT).\n *\n * @param amount - Optional approval amount. Defaults to max uint256.\n * @returns The transaction hash and mined receipt.\n *\n * @example\n * ```ts\n * await wrappedToken.approveUnderlying(); // max approval\n * await wrappedToken.approveUnderlying(1000n); // exact amount\n * ```\n */\n async approveUnderlying(amount?: bigint): Promise<TransactionResult> {\n this.#requireSigner(\"approveUnderlying\");\n const account = await requireAlignedWalletAccount(\n \"approveUnderlying\",\n this.sdk.signer,\n this.sdk.provider,\n );\n const underlying = await this.#getUnderlying();\n const userAddress = getAddress(account.address);\n\n const approvalAmount = amount ?? 2n ** 256n - 1n;\n\n if (approvalAmount > 0n) {\n const currentAllowance = await this.sdk.provider.readContract(\n allowanceContract(underlying, userAddress, this.address),\n );\n\n if (currentAllowance > 0n) {\n await this.submitTransaction({\n operation: \"approveUnderlying:reset\",\n config: approveContract(underlying, this.address, 0n),\n });\n }\n }\n\n return this.submitTransaction({\n operation: \"approveUnderlying\",\n config: approveContract(underlying, this.address, approvalAmount),\n });\n }\n\n // UNSHIELD (confidential → ERC-20)\n\n /**\n * Unshield a specific amount and finalize in one call.\n * Orchestrates: unshield → wait for receipt → parse event → finalize.\n *\n * By default, the SDK validates the confidential balance before submitting.\n * Set `skipBalanceCheck: true` to bypass this validation (e.g. for smart wallets).\n *\n * @param amount - The plaintext amount to unshield.\n * @param options - Optional: `skipBalanceCheck` (default `false`), callbacks.\n * @returns The finalize transaction hash and mined receipt.\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.unshield(500n);\n * ```\n */\n async unshield(amount: bigint, options?: UnshieldOptions): Promise<TransactionResult> {\n const {\n skipBalanceCheck = false,\n onUnwrapSubmitted,\n onFinalizing,\n onFinalizeSubmitted,\n } = options ?? {};\n\n if (!skipBalanceCheck) {\n await this.assertConfidentialBalance(amount, \"unshield\");\n }\n\n const callbacks: UnshieldCallbacks = { onFinalizing, onFinalizeSubmitted };\n const operationId = crypto.randomUUID();\n const unwrapResult = await this.#unwrap(amount, \"unshield\");\n void swallow(\n \"unshield: onUnwrapSubmitted\",\n () => onUnwrapSubmitted?.(unwrapResult.txHash),\n this.sdk.logger,\n );\n // Reuse the id the unwrap already decoded — no second receipt fetch or decode.\n return this.#finalizeUnshield(\n unwrapResult.unwrapRequestId,\n unwrapResult.txHash,\n operationId,\n callbacks,\n \"unshield\",\n );\n }\n\n /**\n * Unshield the entire balance and finalize in one call.\n * Orchestrates: unshieldAll → wait for receipt → parse event → finalize.\n *\n * @param callbacks - Optional progress callbacks for each phase.\n * @returns The finalize transaction hash and mined receipt.\n * @throws if the balance is zero. {@link DecryptionFailedError}\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.unshieldAll();\n * ```\n */\n async unshieldAll(callbacks?: UnshieldCallbacks): Promise<TransactionResult> {\n const operationId = crypto.randomUUID();\n const unwrapResult = await this.unwrapAll();\n void swallow(\n \"unshieldAll: onUnwrapSubmitted\",\n () => callbacks?.onUnwrapSubmitted?.(unwrapResult.txHash),\n this.sdk.logger,\n );\n // Reuse the id `unwrapAll()` already decoded — no second receipt fetch or decode.\n return this.#finalizeUnshield(\n unwrapResult.unwrapRequestId,\n unwrapResult.txHash,\n operationId,\n callbacks,\n \"unshield-all\",\n );\n }\n\n /**\n * Resume an in-progress unshield from an existing unwrap tx hash.\n * Useful when the user already submitted the unwrap but the finalize step\n * was interrupted (e.g. page reload, network error).\n *\n * @param unwrapTxHash - The transaction hash of the previously submitted unwrap.\n * @param callbacks - Optional progress callbacks.\n * @returns The finalize transaction hash and mined receipt.\n * @throws if the unwrap request was already finalized on-chain; the persisted\n * pending-unshield state is cleared first. {@link UnshieldAlreadyFinalizedError}\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.resumeUnshield(previousUnwrapTxHash);\n * ```\n */\n async resumeUnshield(\n unwrapTxHash: Hex,\n callbacks?: UnshieldCallbacks,\n ): Promise<TransactionResult> {\n // The only entry point that starts from a bare hash, so it's the only one\n // that has to fetch the receipt and decode the id from chain.\n let receipt;\n try {\n receipt = await this.sdk.provider.waitForTransactionReceipt(unwrapTxHash);\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new TransactionRevertedError(\"Failed to get unwrap receipt\", { cause: error });\n }\n const unwrapRequestId = this.#extractUnwrapRequestId(receipt.logs);\n if (await this.#isUnwrapRequestConsumed(unwrapRequestId)) {\n await this.#clearStoredPendingUnshield(\"resumeUnshield\");\n throw new UnshieldAlreadyFinalizedError(\n \"Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.\",\n { unwrapTxHash, unwrapRequestId },\n );\n }\n return this.#finalizeUnshield(\n unwrapRequestId,\n unwrapTxHash,\n crypto.randomUUID(),\n callbacks,\n \"resume-unshield\",\n );\n }\n\n /**\n * Return the unwrap tx hash of an unshield that was interrupted between its\n * two phases, or `null` if none is pending for this wrapper.\n *\n * The SDK persists this automatically when {@link unshield}/{@link unshieldAll}\n * submit phase 1, and clears it once phase 2 finalizes. Use the returned hash\n * to surface a \"resume\" affordance, then pass it to {@link resumeUnshield}.\n * Resuming is intentionally caller-driven — auto-resuming on load would fire a\n * wallet transaction unprompted.\n *\n * The pointer is verified on-chain before it is reported: if the unwrap\n * request was already finalized (e.g. the tab closed before the SDK could\n * clear storage), the stale pointer is cleared and `null` is returned. When\n * the verification read fails, the pointer is returned unverified: a\n * network error never deletes recovery state.\n *\n * @returns The pending unwrap tx hash, or `null`.\n *\n * @example\n * ```ts\n * const unwrapTxHash = await wrappedToken.getPendingUnshield();\n * if (unwrapTxHash) await wrappedToken.resumeUnshield(unwrapTxHash);\n * ```\n */\n async getPendingUnshield(): Promise<Hex | null> {\n const pending = await loadPendingUnshieldRequest(this.sdk.storage, this.address);\n if (!pending) {\n return null;\n }\n if (await this.#isPendingUnshieldConsumed(pending)) {\n await this.#clearStoredPendingUnshield(\"getPendingUnshield\");\n return null;\n }\n return pending.unwrapTxHash;\n }\n\n // UNSHIELD LOW-LEVEL PRIMITIVES\n\n /**\n * Request an unwrap for a specific amount. Encrypts the amount first.\n * Pass the result's `unwrapRequestId` to {@link finalizeUnwrap} once the\n * request is processed on-chain.\n *\n * @param amount - The plaintext amount to unwrap (encrypted automatically).\n * @returns The tx hash, mined receipt, and the `unwrapRequestId` for `finalizeUnwrap`.\n *\n * @example\n * ```ts\n * const result = await wrappedToken.unwrap(500n);\n * await wrappedToken.finalizeUnwrap(result.unwrapRequestId);\n * ```\n */\n async unwrap(amount: bigint): Promise<UnwrapResult> {\n return this.#unwrap(amount, \"unwrap\");\n }\n\n async #unwrap(amount: bigint, telemetryOperation: TelemetryOperation): Promise<UnwrapResult> {\n this.#requireSigner(\"unwrap\");\n const account = await requireAlignedWalletAccount(\"unwrap\", this.sdk.signer, this.sdk.provider);\n const userAddress = getAddress(account.address);\n\n const { encryptedValues, inputProof } = await this.sdk.encrypt(\n { values: [{ value: amount, type: \"euint64\" }], contractAddress: this.address, userAddress },\n { operation: telemetryOperation },\n );\n\n const [encryptedAmount] = encryptedValues;\n if (!encryptedAmount) {\n throw new EncryptionFailedError(\"Encryption returned no encrypted values\");\n }\n\n const result = await this.submitTransaction({\n operation: \"unwrap\",\n config: unwrapContract(this.address, userAddress, userAddress, encryptedAmount, inputProof),\n });\n\n return { ...result, unwrapRequestId: this.#extractUnwrapRequestId(result.receipt.logs) };\n }\n\n /**\n * Request an unwrap for the entire confidential balance.\n * Uses the on-chain encrypted balance directly (no encryption needed).\n * Throws if the balance is zero.\n *\n * @returns The tx hash, mined receipt, and the `unwrapRequestId` for `finalizeUnwrap`.\n * @throws if the balance is zero. {@link DecryptionFailedError}\n *\n * @example\n * ```ts\n * const result = await wrappedToken.unwrapAll();\n * await wrappedToken.finalizeUnwrap(result.unwrapRequestId);\n * ```\n */\n async unwrapAll(): Promise<UnwrapResult> {\n this.#requireSigner(\"unwrapAll\");\n const account = await requireAlignedWalletAccount(\n \"unwrapAll\",\n this.sdk.signer,\n this.sdk.provider,\n );\n const userAddress = getAddress(account.address);\n const encryptedValue = await this.readConfidentialBalanceOf(userAddress);\n\n if (isEncryptedValueZero(encryptedValue)) {\n throw new DecryptionFailedError(\"Cannot unshield: balance is zero\");\n }\n\n const result = await this.submitTransaction({\n operation: \"unwrapAll\",\n config: unwrapFromBalanceContract(this.address, userAddress, userAddress, encryptedValue),\n });\n\n return { ...result, unwrapRequestId: this.#extractUnwrapRequestId(result.receipt.logs) };\n }\n\n /**\n * Complete an unwrap by fetching the public decryption proof and finalizing.\n * Call this once the unwrap request has been processed on-chain.\n *\n * @param unwrapRequestId - The `unwrapRequestId` from an {@link UnwrapResult}\n * (`result.unwrapRequestId`) returned by {@link unwrap} / {@link unwrapAll},\n * or one decoded from an `UnwrapRequested` event (e.g. when finalizing\n * across sessions).\n * @returns The transaction hash and mined receipt.\n *\n * @example\n * ```ts\n * const { unwrapRequestId } = await wrappedToken.unwrap(500n);\n * await wrappedToken.finalizeUnwrap(unwrapRequestId);\n * ```\n */\n async finalizeUnwrap(unwrapRequestId: EncryptedValue): Promise<TransactionResult> {\n return this.#finalizeUnwrap(unwrapRequestId, \"finalize-unwrap\");\n }\n\n async #finalizeUnwrap(\n unwrapRequestId: EncryptedValue,\n telemetryOperation: TelemetryOperation,\n ): Promise<TransactionResult> {\n this.#requireSigner(\"finalizeUnwrap\");\n await requireChainAlignment(\"finalizeUnwrap\", this.sdk.signer, this.sdk.provider);\n const result = await this.sdk.decryption.decryptPublicValues([unwrapRequestId], {\n operation: telemetryOperation,\n });\n const clearValue = result.clearValues[unwrapRequestId];\n assertBigint(clearValue, \"finalizeUnwrap: clearValue\");\n return this.submitTransaction({\n operation: \"finalizeUnwrap\",\n config: finalizeUnwrapContract(\n this.address,\n unwrapRequestId,\n clearValue,\n result.decryptionProof,\n ),\n });\n }\n\n // PRIVATE HELPERS\n\n /**\n * Decode the `unwrapRequestId` from an unwrap/unshield receipt's logs.\n * Only logs emitted by this wrapper count: a caller-supplied tx hash from a\n * different wrapper must fail here, not decode a foreign request id. Logs\n * without an emitter address (older custom adapters) are kept.\n * Throws when no matching `UnwrapRequested` event is found.\n */\n #extractUnwrapRequestId(logs: readonly RawLog[]): EncryptedValue {\n const ownLogs = logs.filter(\n (log) => log.address === undefined || getAddress(log.address) === this.address,\n );\n const event = findUnwrapRequested(ownLogs);\n if (!event) {\n throw new TransactionRevertedError(\n \"No UnwrapRequested event from this wrapper found in the unwrap receipt\",\n );\n }\n return event.unwrapRequestId;\n }\n\n /**\n * True only when the unwrap request is definitely gone. `unwrapRequester`\n * returns the zero address once finalize deletes the request, and the id\n * always comes from the unwrap tx's own `UnwrapRequested` event, so zero can\n * only mean \"already finalized\". A failed read returns `false`: the check\n * fails open, so a network error never heals recovery state.\n */\n async #isUnwrapRequestConsumed(unwrapRequestId: EncryptedValue): Promise<boolean> {\n try {\n const requester = await this.sdk.provider.readContract(\n unwrapRequesterContract(this.address, unwrapRequestId),\n );\n return requester === zeroAddress;\n } catch {\n return false;\n }\n }\n\n /**\n * Consumed-request check for a persisted pointer; legacy hash-only entries\n * re-derive the request id from the unwrap receipt.\n */\n async #isPendingUnshieldConsumed(pending: PendingUnshieldRequest): Promise<boolean> {\n let unwrapRequestId = pending.unwrapRequestId;\n if (unwrapRequestId === undefined) {\n try {\n const receipt = await this.sdk.provider.waitForTransactionReceipt(pending.unwrapTxHash);\n unwrapRequestId = this.#extractUnwrapRequestId(receipt.logs);\n } catch {\n return false;\n }\n }\n return this.#isUnwrapRequestConsumed(unwrapRequestId);\n }\n\n async #clearStoredPendingUnshield(operation: string): Promise<void> {\n await swallow(\n `${operation}: clearPendingUnshield`,\n () => clearPendingUnshield(this.sdk.storage, this.address),\n this.sdk.logger,\n );\n }\n\n async #getUnderlying(): Promise<Address> {\n if (this.#underlying !== undefined) {\n return this.#underlying;\n }\n if (!this.#underlyingPromise) {\n this.#underlyingPromise = this.sdk.provider\n .readContract(underlyingContract(this.address))\n .then((v) => {\n this.#underlying = v;\n this.#underlyingPromise = null;\n return v;\n })\n .catch((error) => {\n this.#underlyingPromise = null;\n throw error;\n });\n }\n return this.#underlyingPromise;\n }\n\n /**\n * Phase 2 of unshield, shared by {@link unshield}/{@link unshieldAll} (which\n * pass the id `unwrap`/`unwrapAll` already decoded) and {@link resumeUnshield}\n * (which decoded it from a fetched receipt). Persists the unwrap hash for\n * recovery, finalizes, then clears the persisted state.\n */\n async #finalizeUnshield(\n unwrapRequestId: EncryptedValue,\n unwrapTxHash: Hex,\n operationId: string,\n callbacks: UnshieldCallbacks | undefined,\n telemetryOperation: TelemetryOperation,\n ): Promise<TransactionResult> {\n this.emit({ type: ZamaSDKEvents.UnshieldPhase1Submitted, txHash: unwrapTxHash, operationId });\n await swallow(\n \"unshield: savePendingUnshield\",\n () => savePendingUnshield(this.sdk.storage, this.address, unwrapTxHash, unwrapRequestId),\n this.sdk.logger,\n );\n this.emit({ type: ZamaSDKEvents.UnshieldPhase2Started, operationId });\n void swallow(\"unshield: onFinalizing\", () => callbacks?.onFinalizing?.(), this.sdk.logger);\n let finalizeResult: TransactionResult;\n try {\n finalizeResult = await this.#finalizeUnwrap(unwrapRequestId, telemetryOperation);\n } catch (error) {\n // The id comes from this wrapper's own UnwrapRequested event and the only\n // transition to \"gone\" is a successful finalize, so this revert means a\n // concurrent finalize won the race (second tab, double click, third\n // party). The funds arrived; heal.\n if (!isInvalidUnwrapRequestRevert(error)) {\n throw error;\n }\n await this.#clearStoredPendingUnshield(\"unshield\");\n throw new UnshieldAlreadyFinalizedError(\n \"The unwrap request was finalized concurrently — the funds were already delivered.\",\n { unwrapTxHash, unwrapRequestId },\n { cause: error },\n );\n }\n this.emit({\n type: ZamaSDKEvents.UnshieldPhase2Submitted,\n txHash: finalizeResult.txHash,\n operationId,\n });\n void swallow(\n \"unshield: onFinalizeSubmitted\",\n () => callbacks?.onFinalizeSubmitted?.(finalizeResult.txHash),\n this.sdk.logger,\n );\n // Phase 2 landed: the persisted recovery state is no longer needed.\n await this.#clearStoredPendingUnshield(\"unshield\");\n return finalizeResult;\n }\n\n async #ensureAllowance(\n amount: bigint,\n maxApproval: boolean,\n callbacks?: ShieldCallbacks,\n ): Promise<void> {\n this.#requireSigner(\"approveUnderlying\");\n const underlying = await this.#getUnderlying();\n const account = await requireAlignedWalletAccount(\n \"approveUnderlying\",\n this.sdk.signer,\n this.sdk.provider,\n );\n const userAddress = getAddress(account.address);\n const allowance = await this.sdk.provider.readContract(\n allowanceContract(underlying, userAddress, this.address),\n );\n\n if (allowance >= amount) {\n return;\n }\n\n // Reset to zero first when there's an existing non-zero allowance.\n // Required by non-standard tokens like USDT, and also mitigates the\n // ERC-20 approve race condition for all tokens.\n if (allowance > 0n) {\n await this.submitTransaction({\n operation: \"approveUnderlying:reset\",\n config: approveContract(underlying, this.address, 0n),\n });\n }\n\n const approvalAmount = maxApproval ? 2n ** 256n - 1n : amount;\n\n await this.submitTransaction({\n operation: \"approveUnderlying\",\n config: approveContract(underlying, this.address, approvalAmount),\n onSubmitted: callbacks?.onApprovalSubmitted,\n });\n }\n}\n"],"mappings":"ofAKA,SAAgB,EAAuB,EAA+B,CACpE,GAAI,EAAE,aAAiB,OACrB,OAAO,KAET,IAAM,EAAQ,EAAM,MACpB,GAAI,OAAO,GAAU,WAAY,GAAkB,EAAE,SAAU,GAC7D,OAAO,KAET,GAAM,CAAE,QAAS,EAIjB,OAHI,OAAO,GAAS,WAAY,GAAiB,EAAE,cAAe,GACzD,KAEF,OA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vC,EAAc,GAAW,MALT,EACpB,oBACA,KAAK,IAAI,OACT,KAAK,IAAI,QACX,EAAA,CACuC,OAAO,EACxC,EAAY,MAAM,KAAK,IAAI,SAAS,aACxC,EAAkB,EAAY,EAAa,KAAK,OAAO,CACzD,EAEA,GAAI,GAAa,EACf,OAME,EAAY,IACd,MAAM,KAAK,kBAAkB,CAC3B,UAAW,0BACX,OAAQ,EAAgB,EAAY,KAAK,QAAS,EAAE,CACtD,CAAC,EAGH,IAAM,EAAiB,EAAc,IAAM,KAAO,GAAK,EAEvD,MAAM,KAAK,kBAAkB,CAC3B,UAAW,oBACX,OAAQ,EAAgB,EAAY,KAAK,QAAS,CAAc,EAChE,YAAa,GAAW,mBAC1B,CAAC,CACH,CACF"}
|
|
1
|
+
{"version":3,"file":"wrapped-token-IDUEFpZx.js","names":["#getUnderlying","#isPayable","#shieldViaTransferAndCall","#shieldViaApproveAndWrap","#requireSigner","#ensureAllowance","#unwrap","#finalizeUnshield","#extractUnwrapRequestId","#isUnwrapRequestConsumed","#clearStoredPendingUnshield","#isPendingUnshieldConsumed","#finalizeUnwrap","#underlying","#underlyingPromise"],"sources":["../../src/errors/revert.ts","../../src/errors/unshield.ts","../../src/abi/erc1363.abi.ts","../../src/contracts/erc1363.ts","../../src/utils/hex.ts","../../src/events/log-decoding.ts","../../src/events/onchain-events.ts","../../src/token/pending-unshield.ts","../../src/token/wrapped-token.ts"],"sourcesContent":["/**\n * Extract the decoded custom error name from a viem ContractFunctionRevertedError,\n * or `null` when the error carries no structured revert data.\n * @internal\n */\nexport function extractRevertErrorName(error: unknown): string | null {\n if (!(error instanceof Error)) {\n return null;\n }\n const cause = error.cause;\n if (typeof cause !== \"object\" || cause === null || !(\"data\" in cause)) {\n return null;\n }\n const { data } = cause;\n if (typeof data !== \"object\" || data === null || !(\"errorName\" in data)) {\n return null;\n }\n return typeof data.errorName === \"string\" ? data.errorName : null;\n}\n","import { keccak256, toBytes, type Hex } from \"viem\";\nimport type { EncryptedValue } from \"../relayer/types\";\nimport { ZamaError, ZamaErrorCode } from \"./base\";\nimport { extractRevertErrorName } from \"./revert\";\n\n/** Structured details identifying the consumed unwrap request. */\nexport interface UnshieldAlreadyFinalizedDetails {\n /** Transaction hash of the original unwrap request. */\n readonly unwrapTxHash: Hex;\n /** Request identifier from the `UnwrapRequested` event. */\n readonly unwrapRequestId: EncryptedValue;\n}\n\n/**\n * The unwrap request was already finalized on-chain: the underlying ERC-20\n * tokens were delivered and there is nothing left to resume. The SDK clears\n * the persisted pending-unshield pointer before throwing, so treat this as a\n * success signal: refresh balances and dismiss any \"resume unshield\" prompt.\n */\nexport class UnshieldAlreadyFinalizedError extends ZamaError {\n /** Transaction hash of the original unwrap request. */\n readonly unwrapTxHash: Hex;\n /** Request identifier from the `UnwrapRequested` event. */\n readonly unwrapRequestId: EncryptedValue;\n\n constructor(message: string, details: UnshieldAlreadyFinalizedDetails, options?: ErrorOptions) {\n super(ZamaErrorCode.UnshieldAlreadyFinalized, message, options);\n this.name = \"UnshieldAlreadyFinalizedError\";\n this.unwrapTxHash = details.unwrapTxHash;\n this.unwrapRequestId = details.unwrapRequestId;\n }\n}\n\nconst INVALID_UNWRAP_REQUEST = \"InvalidUnwrapRequest\";\nconst INVALID_UNWRAP_REQUEST_SELECTOR = keccak256(\n toBytes(`${INVALID_UNWRAP_REQUEST}(bytes32)`),\n).slice(0, 10);\n\n/**\n * True if `error` (or anything on its `cause` chain) is the wrapper's\n * `InvalidUnwrapRequest` custom revert. Prefers viem's structured\n * `cause.data.errorName`, falling back to message matching on the error name\n * and the raw 4-byte selector for non-viem providers.\n * @internal\n */\nexport function isInvalidUnwrapRequestRevert(error: unknown): boolean {\n for (let current = error; current instanceof Error; current = current.cause) {\n if (extractRevertErrorName(current) === INVALID_UNWRAP_REQUEST) {\n return true;\n }\n if (\n current.message.includes(INVALID_UNWRAP_REQUEST) ||\n current.message.includes(INVALID_UNWRAP_REQUEST_SELECTOR)\n ) {\n return true;\n }\n }\n return false;\n}\n","// DO NOT EDIT: generated by `pnpm abi:build` from\n// contracts/out/IERC1363.sol/IERC1363.json.\n// Regenerate after `pnpm contracts:build`; `pnpm abi:check` enforces this in CI.\nexport const erc1363Abi = [\n {\n type: \"function\",\n name: \"allowance\",\n inputs: [\n { name: \"owner\", type: \"address\", internalType: \"address\" },\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n ],\n outputs: [{ name: \"\", type: \"uint256\", internalType: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"approve\",\n inputs: [\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"approveAndCall\",\n inputs: [\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"approveAndCall\",\n inputs: [\n { name: \"spender\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"data\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"balanceOf\",\n inputs: [{ name: \"account\", type: \"address\", internalType: \"address\" }],\n outputs: [{ name: \"\", type: \"uint256\", internalType: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"supportsInterface\",\n inputs: [{ name: \"interfaceId\", type: \"bytes4\", internalType: \"bytes4\" }],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"totalSupply\",\n inputs: [],\n outputs: [{ name: \"\", type: \"uint256\", internalType: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"transfer\",\n inputs: [\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferAndCall\",\n inputs: [\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferAndCall\",\n inputs: [\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"data\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferFrom\",\n inputs: [\n { name: \"from\", type: \"address\", internalType: \"address\" },\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferFromAndCall\",\n inputs: [\n { name: \"from\", type: \"address\", internalType: \"address\" },\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"data\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"transferFromAndCall\",\n inputs: [\n { name: \"from\", type: \"address\", internalType: \"address\" },\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\", internalType: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"event\",\n name: \"Approval\",\n inputs: [\n { name: \"owner\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"spender\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"value\", type: \"uint256\", indexed: false, internalType: \"uint256\" },\n ],\n anonymous: false,\n },\n {\n type: \"event\",\n name: \"Transfer\",\n inputs: [\n { name: \"from\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"to\", type: \"address\", indexed: true, internalType: \"address\" },\n { name: \"value\", type: \"uint256\", indexed: false, internalType: \"uint256\" },\n ],\n anonymous: false,\n },\n] as const;\n","import type { Address, Hex } from \"viem\";\nimport { erc1363Abi } from \"../abi/erc1363.abi\";\n\n/**\n * Returns the contract config for an ERC-1363 `transferAndCall`.\n *\n * @param tokenAddress - The ERC-20 token to transfer from (the underlying, not the wrapper).\n * @param to - The recipient of the ERC-20 transfer. In `Token.shield`, this is\n * the wrapper contract whose `onTransferReceived` callback mints\n * confidential tokens to the address encoded in `data`.\n * @param amount - The amount to transfer.\n * @param data - Raw 20-byte recipient address for shield-to-other (decoded by\n * the wrapper as `address(bytes20(data))`). Empty `0x` for self-shield —\n * the wrapper falls back to `from`.\n */\nexport function transferAndCallContract(\n tokenAddress: Address,\n to: Address,\n amount: bigint,\n data: Hex = \"0x\",\n) {\n return {\n address: tokenAddress,\n abi: erc1363Abi,\n functionName: \"transferAndCall\",\n args: [to, amount, data],\n } as const;\n}\n","import type { Hex } from \"viem\";\nimport { assertCondition } from \"./assertions\";\n\n/** Normalize a un-prefixed hex payload to a 0x-prefixed `Hex` value. */\nexport function prefixHex(value: string): Hex {\n return (value.startsWith(\"0x\") ? value : `0x${value}`) as Hex;\n}\n\n/** Convert a public `Hex` value back an unprefixed format. */\nexport function unprefixHex(value: Hex): string {\n assertCondition(value.startsWith(\"0x\"), `Expected 0x-prefixed hex, got: ${value}`);\n return value.slice(2);\n}\n","/**\n * Primitives for decoding raw EVM logs without an ABI decoder.\n *\n * @internal\n */\n\nimport { getAddress, keccak256, toBytes, type Address, type Hex } from \"viem\";\nimport type { EncryptedValue } from \"../relayer/types\";\nimport { prefixHex } from \"../utils\";\n\n/** Hashes the canonical signature — `Joined(uint256,address,bytes32)`, not the declaration with parameter names. */\nexport function eventTopic(signature: string): Hex {\n return keccak256(toBytes(signature));\n}\n\nexport function topicToAddress(topic: Hex): Address {\n return getAddress(prefixHex(topic.slice(-40)));\n}\n\nexport function topicToBytes32(topic: Hex): EncryptedValue {\n // EVM topics are already 32-byte 0x-prefixed hex — cast directly\n return topic as EncryptedValue;\n}\n\nexport function wordAt(data: Hex, index: number): string {\n // data starts with \"0x\", each word is 64 hex chars (32 bytes)\n const start = 2 + index * 64;\n const word = data.slice(start, start + 64);\n return word.length === 64 ? word : word.padEnd(64, \"0\");\n}\n\nexport function wordToAddress(data: Hex, index: number): Address {\n return getAddress(prefixHex(wordAt(data, index).slice(-40)));\n}\n\nexport function wordToBigInt(data: Hex, index: number): bigint {\n return BigInt(\"0x\" + wordAt(data, index));\n}\n\nexport function wordToBytes32(data: Hex, index: number): EncryptedValue {\n // wordAt returns exactly 64 hex chars — prefix and cast directly\n return prefixHex(wordAt(data, index)) as EncryptedValue;\n}\n","/**\n * Framework-agnostic event decoders for confidential token contracts.\n * Works with raw log data from any provider.\n */\n\nimport type { EncryptedValue } from \"../relayer/types\";\nimport type { Address } from \"viem\";\nimport type { RawLog } from \"../types/transaction\";\nimport {\n eventTopic,\n topicToAddress,\n topicToBytes32,\n wordToAddress,\n wordToBigInt,\n wordToBytes32,\n} from \"./log-decoding\";\nexport type { RawLog } from \"../types/transaction\";\n\n// ---------------------------------------------------------------------------\n// Event topic0 constants (keccak256 of canonical signature)\n// ---------------------------------------------------------------------------\n\n/**\n * Event topic0 constants (keccak256 of the canonical Solidity signature).\n * Pass to `getLogs({ topics: [Object.values(Topics)] })` to fetch all events.\n */\nexport const Topics = {\n /** `ConfidentialTransfer(address indexed from, address indexed to, bytes32 indexed amount)` */\n ConfidentialTransfer: eventTopic(\"ConfidentialTransfer(address,address,bytes32)\"),\n /** `Wrap(address indexed to, uint256 roundedAmount, euint64 encryptedWrappedAmount)` */\n Wrap: eventTopic(\"Wrap(address,uint256,bytes32)\"),\n /** `UnwrapRequested(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 amount)` */\n UnwrapRequested: eventTopic(\"UnwrapRequested(address,bytes32,bytes32)\"),\n /** `UnwrapFinalized(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 encryptedAmount, uint64 cleartextAmount)` */\n UnwrapFinalized: eventTopic(\"UnwrapFinalized(address,bytes32,bytes32,uint64)\"),\n} as const;\n\n// ---------------------------------------------------------------------------\n// Typed event interfaces\n// ---------------------------------------------------------------------------\n\n/** Decoded `ConfidentialTransfer` event — an encrypted token transfer. */\nexport interface ConfidentialTransferEvent {\n /** Event name discriminant. */\n readonly eventName: \"ConfidentialTransfer\";\n /** Sender address. */\n readonly from: Address;\n /** Receiver address. */\n readonly to: Address;\n /** FHE encrypted value for the transferred amount. */\n readonly encryptedAmount: EncryptedValue;\n}\n\n/**\n * Decoded `Wrap` event — an ERC-20 shield (wrap) operation. Emitted alongside a\n * `ConfidentialTransfer(from=zeroAddress, ...)`; `encryptedWrappedAmount` is the same FHE\n * handle that lands in `ConfidentialTransfer.encryptedAmount`.\n */\nexport interface WrapEvent {\n /** Event name discriminant. */\n readonly eventName: \"Wrap\";\n /** Receiver of the minted confidential tokens. */\n readonly to: Address;\n /** Cleartext underlying ERC-20 tokens deposited, rounded down to a multiple of the rate. */\n readonly roundedAmount: bigint;\n /** FHE encrypted value for the wrapped (minted) amount. */\n readonly encryptedWrappedAmount: EncryptedValue;\n}\n\n/** Decoded `UnwrapRequested` event — an unshield request submitted. */\nexport interface UnwrapRequestedEvent {\n /** Event name discriminant. */\n readonly eventName: \"UnwrapRequested\";\n /** Address that will receive the unwrapped ERC-20 tokens. */\n readonly receiver: Address;\n /** FHE encrypted value for the requested unshield amount. */\n readonly encryptedAmount: EncryptedValue;\n /** Request identifier from the `UnwrapRequested` event topic. */\n readonly unwrapRequestId: EncryptedValue;\n}\n\n/** Decoded `UnwrapFinalized` event — an unshield completed on-chain. */\nexport interface UnwrapFinalizedEvent {\n /** Event name discriminant. */\n readonly eventName: \"UnwrapFinalized\";\n /** Address receiving the unwrapped ERC-20 tokens. */\n readonly receiver: Address;\n /** FHE encrypted value of the burnt confidential balance. */\n readonly encryptedAmount: EncryptedValue;\n /** Cleartext amount of underlying ERC-20 tokens returned. */\n readonly cleartextAmount: bigint;\n /** Request identifier from the `UnwrapFinalized` event topic. */\n readonly unwrapRequestId: EncryptedValue;\n}\n\n/** Union of all decoded confidential token event types. */\nexport type OnChainEvent =\n | ConfidentialTransferEvent\n | WrapEvent\n | UnwrapRequestedEvent\n | UnwrapFinalizedEvent;\n\n// ---------------------------------------------------------------------------\n// Individual decoders\n// ---------------------------------------------------------------------------\n\n/**\n * ConfidentialTransfer(address indexed from, address indexed to, bytes32 indexed amount)\n * All 3 params indexed → topics[1..3], no data.\n */\nexport function decodeConfidentialTransfer(log: RawLog): ConfidentialTransferEvent | null {\n if (log.topics[0] !== Topics.ConfidentialTransfer) {\n return null;\n }\n if (log.topics.length < 4) {\n return null;\n }\n\n return {\n eventName: \"ConfidentialTransfer\",\n from: topicToAddress(log.topics[1]!),\n to: topicToAddress(log.topics[2]!),\n encryptedAmount: topicToBytes32(log.topics[3]!),\n };\n}\n\n/**\n * Wrap(address indexed to, uint256 roundedAmount, euint64 encryptedWrappedAmount)\n * Indexed: to (topics[1])\n * Data: roundedAmount (uint256), encryptedWrappedAmount (bytes32)\n */\nexport function decodeWrap(log: RawLog): WrapEvent | null {\n if (log.topics[0] !== Topics.Wrap) {\n return null;\n }\n if (log.topics.length < 2) {\n return null;\n }\n\n return {\n eventName: \"Wrap\",\n to: topicToAddress(log.topics[1]!),\n roundedAmount: wordToBigInt(log.data, 0),\n encryptedWrappedAmount: wordToBytes32(log.data, 1),\n };\n}\n\n/**\n * UnwrapRequested(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 amount)\n */\nexport function decodeUnwrapRequested(log: RawLog): UnwrapRequestedEvent | null {\n if (log.topics[0] !== Topics.UnwrapRequested) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"UnwrapRequested\",\n receiver: topicToAddress(log.topics[1]!),\n unwrapRequestId: topicToBytes32(log.topics[2]!),\n encryptedAmount: wordToBytes32(log.data, 0),\n };\n}\n\n/**\n * UnwrapFinalized(address indexed receiver, bytes32 indexed unwrapRequestId, bytes32 encryptedAmount, uint64 cleartextAmount)\n */\nexport function decodeUnwrapFinalized(log: RawLog): UnwrapFinalizedEvent | null {\n if (log.topics[0] !== Topics.UnwrapFinalized) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"UnwrapFinalized\",\n receiver: topicToAddress(log.topics[1]!),\n unwrapRequestId: topicToBytes32(log.topics[2]!),\n encryptedAmount: wordToBytes32(log.data, 0),\n cleartextAmount: wordToBigInt(log.data, 1),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Convenience helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Try all decoders on a single log and return the first match, or `null`.\n *\n * @example\n * ```ts\n * const event = decodeOnChainEvent(log);\n * if (event?.eventName === \"ConfidentialTransfer\") {\n * console.log(event.from, event.to);\n * }\n * ```\n */\nexport function decodeOnChainEvent(log: RawLog): OnChainEvent | null {\n return (\n decodeConfidentialTransfer(log) ??\n decodeWrap(log) ??\n decodeUnwrapRequested(log) ??\n decodeUnwrapFinalized(log)\n );\n}\n\n/**\n * Batch-decode an array of logs, skipping unrecognized entries.\n *\n * @example\n * ```ts\n * const events = decodeOnChainEvents(receipt.logs);\n * ```\n */\nexport function decodeOnChainEvents(logs: readonly RawLog[]): OnChainEvent[] {\n const events: OnChainEvent[] = [];\n for (const log of logs) {\n const event = decodeOnChainEvent(log);\n if (event) {\n events.push(event);\n }\n }\n return events;\n}\n\n/**\n * Find the first {@link UnwrapRequestedEvent} in a logs array.\n *\n * @example\n * ```ts\n * const event = findUnwrapRequested(receipt.logs);\n * if (event) console.log(event.receiver, event.encryptedAmount);\n * ```\n */\nexport function findUnwrapRequested(logs: readonly RawLog[]): UnwrapRequestedEvent | null {\n for (const log of logs) {\n const event = decodeUnwrapRequested(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * Find the first {@link WrapEvent} in a logs array.\n *\n * @example\n * ```ts\n * const event = findWrap(receipt.logs);\n * if (event) console.log(event.to, event.roundedAmount);\n * ```\n */\nexport function findWrap(logs: readonly RawLog[]): WrapEvent | null {\n for (const log of logs) {\n const event = decodeWrap(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * All confidential token event topic0 hashes.\n * Pass to `getLogs({ topics: [TOKEN_TOPICS] })` to fetch\n * all confidential token events in a single RPC call.\n */\nexport const TOKEN_TOPICS = [\n Topics.ConfidentialTransfer,\n Topics.Wrap,\n Topics.UnwrapRequested,\n Topics.UnwrapFinalized,\n] as const;\n\n// ---------------------------------------------------------------------------\n// ACL delegation event topic0 constants\n// ---------------------------------------------------------------------------\n\n/**\n * ACL delegation event topic0 constants (keccak256 of the canonical Solidity signature).\n * These are ACL events, NOT token events — they are emitted by the ACL contract.\n */\nexport const AclTopics = {\n /** `DelegatedForUserDecryption(address indexed delegator, address indexed delegate, address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate, uint64 newExpirationDate)` */\n DelegatedForUserDecryption: eventTopic(\n \"DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)\",\n ),\n /** `RevokedDelegationForUserDecryption(address indexed delegator, address indexed delegate, address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate)` */\n RevokedDelegationForUserDecryption: eventTopic(\n \"RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)\",\n ),\n} as const;\n\n// ---------------------------------------------------------------------------\n// ACL delegation event interfaces\n// ---------------------------------------------------------------------------\n\n/** Decoded `DelegatedForUserDecryption` event — a delegation was created or renewed. */\nexport interface DelegatedForUserDecryptionEvent {\n /** Event name discriminant. */\n readonly eventName: \"DelegatedForUserDecryption\";\n /** Address of the delegator (the account granting access). */\n readonly delegator: Address;\n /** Address of the delegate (the account receiving access). */\n readonly delegate: Address;\n /** Contract address the delegation applies to. */\n readonly contractAddress: Address;\n /** Monotonic delegation counter. */\n readonly delegationCounter: bigint;\n /** Previous expiration timestamp (0 if first delegation). */\n readonly oldExpirationDate: bigint;\n /** New expiration timestamp. */\n readonly newExpirationDate: bigint;\n}\n\n/** Decoded `RevokedDelegationForUserDecryption` event — a delegation was revoked. */\nexport interface RevokedDelegationForUserDecryptionEvent {\n /** Event name discriminant. */\n readonly eventName: \"RevokedDelegationForUserDecryption\";\n /** Address of the delegator. */\n readonly delegator: Address;\n /** Address of the delegate. */\n readonly delegate: Address;\n /** Contract address the revocation applies to. */\n readonly contractAddress: Address;\n /** Monotonic delegation counter. */\n readonly delegationCounter: bigint;\n /** Expiration date that was active before revocation. */\n readonly oldExpirationDate: bigint;\n}\n\n/** Union of all decoded ACL delegation event types. */\nexport type AclEvent = DelegatedForUserDecryptionEvent | RevokedDelegationForUserDecryptionEvent;\n\n// ---------------------------------------------------------------------------\n// ACL delegation event decoders\n// ---------------------------------------------------------------------------\n\n/**\n * DelegatedForUserDecryption(address indexed delegator, address indexed delegate,\n * address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate, uint64 newExpirationDate)\n * Indexed: delegator (topics[1]), delegate (topics[2])\n * Data: contractAddress, delegationCounter, oldExpirationDate, newExpirationDate\n */\nexport function decodeDelegatedForUserDecryption(\n log: RawLog,\n): DelegatedForUserDecryptionEvent | null {\n if (log.topics[0] !== AclTopics.DelegatedForUserDecryption) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"DelegatedForUserDecryption\",\n delegator: topicToAddress(log.topics[1]!),\n delegate: topicToAddress(log.topics[2]!),\n contractAddress: wordToAddress(log.data, 0),\n delegationCounter: wordToBigInt(log.data, 1),\n oldExpirationDate: wordToBigInt(log.data, 2),\n newExpirationDate: wordToBigInt(log.data, 3),\n };\n}\n\n/**\n * RevokedDelegationForUserDecryption(address indexed delegator, address indexed delegate,\n * address contractAddress, uint64 delegationCounter, uint64 oldExpirationDate)\n * Indexed: delegator (topics[1]), delegate (topics[2])\n * Data: contractAddress, delegationCounter, oldExpirationDate\n */\nexport function decodeRevokedDelegationForUserDecryption(\n log: RawLog,\n): RevokedDelegationForUserDecryptionEvent | null {\n if (log.topics[0] !== AclTopics.RevokedDelegationForUserDecryption) {\n return null;\n }\n if (log.topics.length < 3) {\n return null;\n }\n\n return {\n eventName: \"RevokedDelegationForUserDecryption\",\n delegator: topicToAddress(log.topics[1]!),\n delegate: topicToAddress(log.topics[2]!),\n contractAddress: wordToAddress(log.data, 0),\n delegationCounter: wordToBigInt(log.data, 1),\n oldExpirationDate: wordToBigInt(log.data, 2),\n };\n}\n\n/**\n * Try all ACL delegation decoders on a single log and return the first match, or `null`.\n */\nexport function decodeAclEvent(log: RawLog): AclEvent | null {\n return decodeDelegatedForUserDecryption(log) ?? decodeRevokedDelegationForUserDecryption(log);\n}\n\n/**\n * Batch-decode an array of logs for ACL delegation events, skipping unrecognized entries.\n */\nexport function decodeAclEvents(logs: readonly RawLog[]): AclEvent[] {\n const events: AclEvent[] = [];\n for (const log of logs) {\n const event = decodeAclEvent(log);\n if (event) {\n events.push(event);\n }\n }\n return events;\n}\n\n/**\n * Find the first {@link DelegatedForUserDecryptionEvent} in a logs array.\n */\nexport function findDelegatedForUserDecryption(\n logs: readonly RawLog[],\n): DelegatedForUserDecryptionEvent | null {\n for (const log of logs) {\n const event = decodeDelegatedForUserDecryption(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * Find the first {@link RevokedDelegationForUserDecryptionEvent} in a logs array.\n */\nexport function findRevokedDelegationForUserDecryption(\n logs: readonly RawLog[],\n): RevokedDelegationForUserDecryptionEvent | null {\n for (const log of logs) {\n const event = decodeRevokedDelegationForUserDecryption(log);\n if (event) {\n return event;\n }\n }\n return null;\n}\n\n/**\n * Both ACL delegation event topic0 hashes.\n * Pass to `getLogs({ topics: [ACL_TOPICS] })` to fetch\n * all delegation events in a single RPC call.\n */\nexport const ACL_TOPICS = [\n AclTopics.DelegatedForUserDecryption,\n AclTopics.RevokedDelegationForUserDecryption,\n] as const;\n","import type { Address, Hex } from \"viem\";\nimport { z } from \"zod/mini\";\nimport { checksum, hex } from \"../schemas/primitives\";\nimport type { GenericStorage } from \"../types\";\nimport type { EncryptedValue } from \"../relayer/types\";\n\nconst STORAGE_PREFIX = \"zama:pending-unshield:\";\nconst CURRENT_VERSION = 1;\n\n/**\n * Persisted state for an in-progress unshield request.\n * Used to resume an interrupted unshield after page reload.\n *\n * @internal\n */\nexport interface PendingUnshieldRequest {\n /** Transaction hash of the original unwrap call. */\n readonly unwrapTxHash: Hex;\n /**\n * Request identifier from the `UnwrapRequested` event.\n * Always populated for entries persisted by this SDK version; pass it as\n * `unwrapRequestId` to `finalizeUnwrap`. Absent only when re-loading a\n * pending unshield serialized by an older SDK version that did not\n * record this field — in that case pass the `encryptedAmount` from the\n * `UnwrapRequested` event to `finalizeUnwrap` instead.\n */\n readonly unwrapRequestId?: EncryptedValue;\n}\n\ninterface StoredPendingUnshieldRequest extends PendingUnshieldRequest {\n readonly version: typeof CURRENT_VERSION;\n}\n\nfunction storageKey(wrapperAddress: Address): string {\n return `${STORAGE_PREFIX}${checksum(wrapperAddress)}`;\n}\n\nconst PendingUnshieldRequestSchema = z.union([\n z.pipe(\n hex,\n z.transform((unwrapTxHash: Hex) => ({ unwrapTxHash })),\n ),\n z.pipe(\n z.object({\n version: z.literal(CURRENT_VERSION),\n unwrapTxHash: hex,\n unwrapRequestId: z.optional(hex),\n }),\n z.transform(\n ({\n unwrapTxHash,\n unwrapRequestId,\n }: {\n version: typeof CURRENT_VERSION;\n unwrapTxHash: Hex;\n unwrapRequestId?: Hex;\n }) => ({ unwrapTxHash, unwrapRequestId }),\n ),\n ),\n]);\n\n/**\n * Persist the unwrap tx hash so an interrupted unshield can be resumed later\n * (e.g. after a page reload).\n *\n * @internal\n */\nexport async function savePendingUnshield(\n storage: GenericStorage,\n wrapperAddress: Address,\n unwrapTxHash: Hex,\n unwrapRequestId?: EncryptedValue,\n): Promise<void> {\n if (unwrapRequestId === undefined) {\n await storage.set(storageKey(wrapperAddress), unwrapTxHash);\n return;\n }\n\n await storage.set(storageKey(wrapperAddress), {\n version: CURRENT_VERSION,\n unwrapTxHash,\n unwrapRequestId,\n } satisfies StoredPendingUnshieldRequest);\n}\n\n/**\n * Load a previously saved unwrap tx hash, or `null` if none exists.\n *\n * @internal\n */\nexport async function loadPendingUnshield(\n storage: GenericStorage,\n wrapperAddress: Address,\n): Promise<Hex | null> {\n const request = await loadPendingUnshieldRequest(storage, wrapperAddress);\n return request?.unwrapTxHash ?? null;\n}\n\n/**\n * Load a previously saved unwrap request, including `unwrapRequestId` when available.\n *\n * `resumeUnshield()` only needs `unwrapTxHash`: it reloads the transaction receipt and\n * rediscovers the right finalize input from the emitted `UnwrapRequested` event.\n * Use `unwrapRequestId` directly only for custom flows that call `finalizeUnwrap()`\n * without reloading the original unwrap receipt.\n *\n * @internal\n */\nexport async function loadPendingUnshieldRequest(\n storage: GenericStorage,\n wrapperAddress: Address,\n): Promise<PendingUnshieldRequest | null> {\n const key = storageKey(wrapperAddress);\n const value = await storage.get<Hex | StoredPendingUnshieldRequest>(key);\n if (value === null || value === undefined) {\n return null;\n }\n const parsed = PendingUnshieldRequestSchema.safeParse(value);\n if (!parsed.success) {\n await storage.delete(key);\n return null;\n }\n return parsed.data as PendingUnshieldRequest;\n}\n\n/**\n * Clear the saved unwrap tx hash after a successful finalization.\n *\n * @internal\n */\nexport async function clearPendingUnshield(\n storage: GenericStorage,\n wrapperAddress: Address,\n): Promise<void> {\n await storage.delete(storageKey(wrapperAddress));\n}\n","import { getAddress, zeroAddress, type Address, type Hex } from \"viem\";\nimport {\n allowanceContract,\n approveContract,\n balanceOfContract,\n finalizeUnwrapContract,\n isPayableTokenContract,\n transferAndCallContract,\n underlyingContract,\n unwrapContract,\n unwrapFromBalanceContract,\n unwrapRequesterContract,\n wrapContract,\n} from \"../contracts\";\nimport {\n DecryptionFailedError,\n ERC20ReadFailedError,\n EncryptionFailedError,\n InsufficientAllowanceError,\n InsufficientERC20BalanceError,\n SignerNotConfiguredError,\n TransactionRevertedError,\n UnshieldAlreadyFinalizedError,\n ZamaError,\n} from \"../errors\";\nimport { isInvalidUnwrapRequestRevert } from \"../errors/unshield\";\nimport { findUnwrapRequested } from \"../events/onchain-events\";\nimport { ZamaSDKEvents } from \"../events/sdk-events\";\nimport type { EncryptedValue } from \"../relayer/types\";\nimport type {\n GenericSigner,\n ShieldCallbacks,\n ShieldOptions,\n TransactionResult,\n UnshieldCallbacks,\n UnshieldOptions,\n UnwrapResult,\n WrapOptions,\n} from \"../types\";\nimport type { RawLog } from \"../types/transaction\";\nimport { toError } from \"../utils\";\nimport { requireAlignedWalletAccount, requireChainAlignment } from \"../utils/alignment\";\nimport { assertBigint, assertNonNullable } from \"../utils/assertions\";\nimport { isEncryptedValueZero } from \"../utils/handles\";\nimport type { TelemetryOperation } from \"../telemetry\";\nimport { swallow } from \"../utils/swallow\";\nimport {\n clearPendingUnshield,\n loadPendingUnshieldRequest,\n savePendingUnshield,\n type PendingUnshieldRequest,\n} from \"./pending-unshield\";\nimport { Token } from \"./token\";\n\n/**\n * Confidential ERC-20 wrapper (ERC-7984 ERC20Wrapper).\n *\n * Extends {@link Token} with wrapper-specific operations:\n * - `shield` / `unshield` — convert between the underlying ERC-20 and confidential balance\n * - `unwrap` / `unwrapAll` / `finalizeUnwrap` — low-level two-phase primitives\n * - `underlying` / `allowance` — wrapper reads\n *\n * `WrappedToken.address` is the wrapper contract address itself — the wrapper\n * IS the confidential token.\n */\nexport class WrappedToken extends Token {\n #underlying: Address | undefined;\n #underlyingPromise: Promise<Address> | null = null;\n #isPayable: boolean | null = null;\n\n /** Resolve `sdk.signer` or throw {@link SignerNotConfiguredError} tagged with `operation`. */\n #requireSigner(operation: string): GenericSigner {\n try {\n assertNonNullable(this.sdk.signer, \"WrappedToken.sdk.signer\");\n return this.sdk.signer;\n } catch (cause) {\n throw new SignerNotConfiguredError(operation, { cause });\n }\n }\n\n // WRAPPER READS\n\n /**\n * Read the underlying ERC-20 token address from the wrapper contract.\n *\n * @returns The underlying ERC-20 token address.\n */\n async underlying(): Promise<Address> {\n return this.#getUnderlying();\n }\n\n /**\n * Check whether the underlying ERC-20 supports ERC-1363 (payable token).\n * Result is cached per WrappedToken instance (negative results included):\n * once we know an underlying does not support ERC-1363, subsequent shields\n * go straight to the `approve` + `wrap` path without re-probing.\n */\n async isPayable(): Promise<boolean> {\n if (this.#isPayable !== null) {\n return this.#isPayable;\n }\n try {\n const underlying = await this.#getUnderlying();\n this.#isPayable = await this.sdk.provider.readContract(isPayableTokenContract(underlying));\n } catch {\n this.#isPayable = false;\n }\n return this.#isPayable;\n }\n\n /**\n * Read the ERC-20 allowance granted by `owner` to this wrapper for the\n * underlying token.\n *\n * @param owner - The owner address whose allowance to read.\n * @returns The current allowance as a bigint.\n */\n async allowance(owner: Address): Promise<bigint> {\n const underlying = await this.#getUnderlying();\n return this.sdk.provider.readContract(\n allowanceContract(underlying, getAddress(owner), this.address),\n );\n }\n\n // SHIELD (ERC-20 → confidential)\n\n /**\n * Shield public ERC-20 tokens into confidential tokens.\n *\n * The execution path is decided automatically by ERC-165 introspection on\n * the underlying ERC-20:\n * - **`transferAndCall`** (single tx): when the underlying supports\n * ERC-1363, no approval is required — the wrapper's `onTransferReceived`\n * callback mints confidential tokens directly. `approvalStrategy` is\n * **ignored** on this path. See {@link ShieldPath}.\n * - **`approveAndWrap`** (two-tx fallback): otherwise, an `approve` is\n * followed by a `wrap`. Approval is controlled by `approvalStrategy`\n * (`\"exact\"` by default, `\"max\"` for unlimited, `\"skip\"` to opt out).\n *\n * The ERC-20 balance is validated before submitting (public read, no\n * signing required) so the call works for all wallet types, including\n * smart wallets.\n *\n * @param amount - The plaintext amount to shield.\n * @param options - Optional: `approvalStrategy`, `to`, callbacks.\n * @returns The transaction hash and mined receipt.\n * @throws if signer and provider are on different chains. {@link ChainMismatchError}\n * @throws if the ERC-20 balance is less than `amount`. {@link InsufficientERC20BalanceError}\n * @throws if the ERC-20 approval or shield transaction reverts. {@link TransactionRevertedError}\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.shield(1000n);\n * ```\n */\n async shield(amount: bigint, options?: ShieldOptions): Promise<TransactionResult> {\n const account = await requireAlignedWalletAccount(\"shield\", this.sdk.signer, this.sdk.provider);\n\n const isPayableToken = await this.isPayable();\n const underlying = await this.#getUnderlying();\n const userAddress = getAddress(account.address);\n\n // ERC-20 balance check always runs (public read, no signing needed, works for all wallet types)\n let erc20Balance: bigint;\n try {\n erc20Balance = await this.sdk.provider.readContract(\n balanceOfContract(underlying, userAddress),\n );\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new ERC20ReadFailedError(\n `Could not read ERC-20 balance for shield validation (token: ${underlying})`,\n { cause: toError(error) },\n );\n }\n if (erc20Balance < amount) {\n throw new InsufficientERC20BalanceError(\n `Insufficient ERC-20 balance: requested ${amount}, available ${erc20Balance} (token: ${underlying})`,\n { requested: amount, available: erc20Balance, token: underlying },\n );\n }\n\n if (isPayableToken) {\n return this.#shieldViaTransferAndCall(amount, underlying, userAddress, options);\n }\n return this.#shieldViaApproveAndWrap(amount, userAddress, options);\n }\n\n async #shieldViaTransferAndCall(\n amount: bigint,\n underlying: Address,\n userAddress: Address,\n options?: ShieldOptions,\n ): Promise<TransactionResult> {\n this.#requireSigner(\"shield\");\n const recipient = options?.to ? getAddress(options.to) : userAddress;\n // ERC7984ERC20Wrapper.onTransferReceived decodes the recipient via\n // `address(bytes20(data))` — i.e. the first 20 bytes of `data`. We pass\n // the raw 20-byte address (not ABI-encoded), and the empty payload `0x`\n // for self-shield so the wrapper falls back to `from`.\n const data: Hex = recipient === userAddress ? \"0x\" : recipient;\n\n return this.submitTransaction({\n operation: \"shield:transferAndCall\",\n config: transferAndCallContract(underlying, this.address, amount, data),\n onSubmitted: options?.onShieldSubmitted,\n });\n }\n\n /**\n * Wrap already-approved underlying ERC-20 into confidential tokens.\n *\n * Escape hatch for splitting shield across two signatures: call\n * {@link approveUnderlying} first, then `wrap`. Most callers should use\n * {@link shield}, which routes and orchestrates approval automatically.\n *\n * Validates the ERC-20 balance and the allowance granted to this wrapper\n * (public reads, no signing) and fails early with a clear error.\n *\n * @param amount - The plaintext amount to wrap.\n * @param options - Optional `to` recipient and `onWrapSubmitted` callback.\n * @returns The transaction hash and mined receipt.\n * @throws if reading the ERC-20 balance or allowance fails. {@link ERC20ReadFailedError}\n * @throws if the ERC-20 balance is less than `amount`. {@link InsufficientERC20BalanceError}\n * @throws if the allowance granted to the wrapper is less than `amount`. {@link InsufficientAllowanceError}\n *\n * @example\n * ```ts\n * await wrappedToken.approveUnderlying(1000n);\n * await wrappedToken.wrap(1000n);\n * ```\n */\n async wrap(amount: bigint, options?: WrapOptions): Promise<TransactionResult> {\n this.#requireSigner(\"wrap\");\n const account = await requireAlignedWalletAccount(\"wrap\", this.sdk.signer, this.sdk.provider);\n const underlying = await this.#getUnderlying();\n const userAddress = getAddress(account.address);\n\n let erc20Balance: bigint;\n try {\n erc20Balance = await this.sdk.provider.readContract(\n balanceOfContract(underlying, userAddress),\n );\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new ERC20ReadFailedError(\n `Could not read ERC-20 balance for wrap validation (token: ${underlying})`,\n { cause: toError(error) },\n );\n }\n if (erc20Balance < amount) {\n throw new InsufficientERC20BalanceError(\n `Insufficient ERC-20 balance: requested ${amount}, available ${erc20Balance} (token: ${underlying})`,\n { requested: amount, available: erc20Balance, token: underlying },\n );\n }\n\n let allowance: bigint;\n try {\n allowance = await this.sdk.provider.readContract(\n allowanceContract(underlying, userAddress, this.address),\n );\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new ERC20ReadFailedError(\n `Could not read ERC-20 allowance for wrap validation (token: ${underlying})`,\n { cause: toError(error) },\n );\n }\n if (allowance < amount) {\n throw new InsufficientAllowanceError(\n `Insufficient allowance for wrap: requested ${amount}, approved ${allowance}. Call approveUnderlying() first (token: ${underlying}).`,\n { requested: amount, available: allowance, token: underlying },\n );\n }\n\n const recipient = options?.to ? getAddress(options.to) : userAddress;\n return this.submitTransaction({\n operation: \"wrap\",\n config: wrapContract(this.address, recipient, amount),\n onSubmitted: options?.onWrapSubmitted,\n });\n }\n\n async #shieldViaApproveAndWrap(\n amount: bigint,\n userAddress: Address,\n options?: ShieldOptions,\n ): Promise<TransactionResult> {\n this.#requireSigner(\"shield\");\n const strategy = options?.approvalStrategy ?? \"exact\";\n if (strategy !== \"skip\") {\n await this.#ensureAllowance(amount, strategy === \"max\", options);\n }\n const recipient = options?.to ? getAddress(options.to) : userAddress;\n return this.submitTransaction({\n operation: \"shield:approveAndWrap\",\n config: wrapContract(this.address, recipient, amount),\n onSubmitted: options?.onShieldSubmitted,\n });\n }\n\n /**\n * Approve this wrapper contract to spend the underlying ERC-20.\n * Defaults to max uint256. Resets to zero first if there's an existing\n * non-zero allowance (required by tokens like USDT).\n *\n * @param amount - Optional approval amount. Defaults to max uint256.\n * @returns The transaction hash and mined receipt.\n *\n * @example\n * ```ts\n * await wrappedToken.approveUnderlying(); // max approval\n * await wrappedToken.approveUnderlying(1000n); // exact amount\n * ```\n */\n async approveUnderlying(amount?: bigint): Promise<TransactionResult> {\n this.#requireSigner(\"approveUnderlying\");\n const account = await requireAlignedWalletAccount(\n \"approveUnderlying\",\n this.sdk.signer,\n this.sdk.provider,\n );\n const underlying = await this.#getUnderlying();\n const userAddress = getAddress(account.address);\n\n const approvalAmount = amount ?? 2n ** 256n - 1n;\n\n if (approvalAmount > 0n) {\n const currentAllowance = await this.sdk.provider.readContract(\n allowanceContract(underlying, userAddress, this.address),\n );\n\n if (currentAllowance > 0n) {\n await this.submitTransaction({\n operation: \"approveUnderlying:reset\",\n config: approveContract(underlying, this.address, 0n),\n });\n }\n }\n\n return this.submitTransaction({\n operation: \"approveUnderlying\",\n config: approveContract(underlying, this.address, approvalAmount),\n });\n }\n\n // UNSHIELD (confidential → ERC-20)\n\n /**\n * Unshield a specific amount and finalize in one call.\n * Orchestrates: unshield → wait for receipt → parse event → finalize.\n *\n * By default, the SDK validates the confidential balance before submitting.\n * Set `skipBalanceCheck: true` to bypass this validation (e.g. for smart wallets).\n *\n * @param amount - The plaintext amount to unshield.\n * @param options - Optional: `skipBalanceCheck` (default `false`), callbacks.\n * @returns The finalize transaction hash and mined receipt.\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.unshield(500n);\n * ```\n */\n async unshield(amount: bigint, options?: UnshieldOptions): Promise<TransactionResult> {\n const {\n skipBalanceCheck = false,\n onUnwrapSubmitted,\n onFinalizing,\n onFinalizeSubmitted,\n } = options ?? {};\n\n if (!skipBalanceCheck) {\n await this.assertConfidentialBalance(amount, \"unshield\");\n }\n\n const callbacks: UnshieldCallbacks = { onFinalizing, onFinalizeSubmitted };\n const operationId = crypto.randomUUID();\n const unwrapResult = await this.#unwrap(amount, \"unshield\");\n void swallow(\n \"unshield: onUnwrapSubmitted\",\n () => onUnwrapSubmitted?.(unwrapResult.txHash),\n this.sdk.logger,\n );\n // Reuse the id the unwrap already decoded — no second receipt fetch or decode.\n return this.#finalizeUnshield(\n unwrapResult.unwrapRequestId,\n unwrapResult.txHash,\n operationId,\n callbacks,\n \"unshield\",\n );\n }\n\n /**\n * Unshield the entire balance and finalize in one call.\n * Orchestrates: unshieldAll → wait for receipt → parse event → finalize.\n *\n * @param callbacks - Optional progress callbacks for each phase.\n * @returns The finalize transaction hash and mined receipt.\n * @throws if the balance is zero. {@link DecryptionFailedError}\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.unshieldAll();\n * ```\n */\n async unshieldAll(callbacks?: UnshieldCallbacks): Promise<TransactionResult> {\n const operationId = crypto.randomUUID();\n const unwrapResult = await this.unwrapAll();\n void swallow(\n \"unshieldAll: onUnwrapSubmitted\",\n () => callbacks?.onUnwrapSubmitted?.(unwrapResult.txHash),\n this.sdk.logger,\n );\n // Reuse the id `unwrapAll()` already decoded — no second receipt fetch or decode.\n return this.#finalizeUnshield(\n unwrapResult.unwrapRequestId,\n unwrapResult.txHash,\n operationId,\n callbacks,\n \"unshield-all\",\n );\n }\n\n /**\n * Resume an in-progress unshield from an existing unwrap tx hash.\n * Useful when the user already submitted the unwrap but the finalize step\n * was interrupted (e.g. page reload, network error).\n *\n * @param unwrapTxHash - The transaction hash of the previously submitted unwrap.\n * @param callbacks - Optional progress callbacks.\n * @returns The finalize transaction hash and mined receipt.\n * @throws if the unwrap request was already finalized on-chain; the persisted\n * pending-unshield state is cleared first. {@link UnshieldAlreadyFinalizedError}\n *\n * @example\n * ```ts\n * const txHash = await wrappedToken.resumeUnshield(previousUnwrapTxHash);\n * ```\n */\n async resumeUnshield(\n unwrapTxHash: Hex,\n callbacks?: UnshieldCallbacks,\n ): Promise<TransactionResult> {\n // The only entry point that starts from a bare hash, so it's the only one\n // that has to fetch the receipt and decode the id from chain.\n let receipt;\n try {\n receipt = await this.sdk.provider.waitForTransactionReceipt(unwrapTxHash);\n } catch (error) {\n if (error instanceof ZamaError) {\n throw error;\n }\n throw new TransactionRevertedError(\"Failed to get unwrap receipt\", { cause: error });\n }\n const unwrapRequestId = this.#extractUnwrapRequestId(receipt.logs);\n if (await this.#isUnwrapRequestConsumed(unwrapRequestId)) {\n await this.#clearStoredPendingUnshield(\"resumeUnshield\");\n throw new UnshieldAlreadyFinalizedError(\n \"Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.\",\n { unwrapTxHash, unwrapRequestId },\n );\n }\n return this.#finalizeUnshield(\n unwrapRequestId,\n unwrapTxHash,\n crypto.randomUUID(),\n callbacks,\n \"resume-unshield\",\n );\n }\n\n /**\n * Return the unwrap tx hash of an unshield that was interrupted between its\n * two phases, or `null` if none is pending for this wrapper.\n *\n * The SDK persists this automatically when {@link unshield}/{@link unshieldAll}\n * submit phase 1, and clears it once phase 2 finalizes. Use the returned hash\n * to surface a \"resume\" affordance, then pass it to {@link resumeUnshield}.\n * Resuming is intentionally caller-driven — auto-resuming on load would fire a\n * wallet transaction unprompted.\n *\n * The pointer is verified on-chain before it is reported: if the unwrap\n * request was already finalized (e.g. the tab closed before the SDK could\n * clear storage), the stale pointer is cleared and `null` is returned. When\n * the verification read fails, the pointer is returned unverified: a\n * network error never deletes recovery state.\n *\n * @returns The pending unwrap tx hash, or `null`.\n *\n * @example\n * ```ts\n * const unwrapTxHash = await wrappedToken.getPendingUnshield();\n * if (unwrapTxHash) await wrappedToken.resumeUnshield(unwrapTxHash);\n * ```\n */\n async getPendingUnshield(): Promise<Hex | null> {\n const pending = await loadPendingUnshieldRequest(this.sdk.storage, this.address);\n if (!pending) {\n return null;\n }\n if (await this.#isPendingUnshieldConsumed(pending)) {\n await this.#clearStoredPendingUnshield(\"getPendingUnshield\");\n return null;\n }\n return pending.unwrapTxHash;\n }\n\n // UNSHIELD LOW-LEVEL PRIMITIVES\n\n /**\n * Request an unwrap for a specific amount. Encrypts the amount first.\n * Pass the result's `unwrapRequestId` to {@link finalizeUnwrap} once the\n * request is processed on-chain.\n *\n * @param amount - The plaintext amount to unwrap (encrypted automatically).\n * @returns The tx hash, mined receipt, and the `unwrapRequestId` for `finalizeUnwrap`.\n *\n * @example\n * ```ts\n * const result = await wrappedToken.unwrap(500n);\n * await wrappedToken.finalizeUnwrap(result.unwrapRequestId);\n * ```\n */\n async unwrap(amount: bigint): Promise<UnwrapResult> {\n return this.#unwrap(amount, \"unwrap\");\n }\n\n async #unwrap(amount: bigint, telemetryOperation: TelemetryOperation): Promise<UnwrapResult> {\n this.#requireSigner(\"unwrap\");\n const account = await requireAlignedWalletAccount(\"unwrap\", this.sdk.signer, this.sdk.provider);\n const userAddress = getAddress(account.address);\n\n const { encryptedValues, inputProof } = await this.sdk.encrypt(\n { values: [{ value: amount, type: \"euint64\" }], contractAddress: this.address, userAddress },\n { operation: telemetryOperation },\n );\n\n const [encryptedAmount] = encryptedValues;\n if (!encryptedAmount) {\n throw new EncryptionFailedError(\"Encryption returned no encrypted values\");\n }\n\n const result = await this.submitTransaction({\n operation: \"unwrap\",\n config: unwrapContract(this.address, userAddress, userAddress, encryptedAmount, inputProof),\n });\n\n return { ...result, unwrapRequestId: this.#extractUnwrapRequestId(result.receipt.logs) };\n }\n\n /**\n * Request an unwrap for the entire confidential balance.\n * Uses the on-chain encrypted balance directly (no encryption needed).\n * Throws if the balance is zero.\n *\n * @returns The tx hash, mined receipt, and the `unwrapRequestId` for `finalizeUnwrap`.\n * @throws if the balance is zero. {@link DecryptionFailedError}\n *\n * @example\n * ```ts\n * const result = await wrappedToken.unwrapAll();\n * await wrappedToken.finalizeUnwrap(result.unwrapRequestId);\n * ```\n */\n async unwrapAll(): Promise<UnwrapResult> {\n this.#requireSigner(\"unwrapAll\");\n const account = await requireAlignedWalletAccount(\n \"unwrapAll\",\n this.sdk.signer,\n this.sdk.provider,\n );\n const userAddress = getAddress(account.address);\n const encryptedValue = await this.readConfidentialBalanceOf(userAddress);\n\n if (isEncryptedValueZero(encryptedValue)) {\n throw new DecryptionFailedError(\"Cannot unshield: balance is zero\");\n }\n\n const result = await this.submitTransaction({\n operation: \"unwrapAll\",\n config: unwrapFromBalanceContract(this.address, userAddress, userAddress, encryptedValue),\n });\n\n return { ...result, unwrapRequestId: this.#extractUnwrapRequestId(result.receipt.logs) };\n }\n\n /**\n * Complete an unwrap by fetching the public decryption proof and finalizing.\n * Call this once the unwrap request has been processed on-chain.\n *\n * @param unwrapRequestId - The `unwrapRequestId` from an {@link UnwrapResult}\n * (`result.unwrapRequestId`) returned by {@link unwrap} / {@link unwrapAll},\n * or one decoded from an `UnwrapRequested` event (e.g. when finalizing\n * across sessions).\n * @returns The transaction hash and mined receipt.\n *\n * @example\n * ```ts\n * const { unwrapRequestId } = await wrappedToken.unwrap(500n);\n * await wrappedToken.finalizeUnwrap(unwrapRequestId);\n * ```\n */\n async finalizeUnwrap(unwrapRequestId: EncryptedValue): Promise<TransactionResult> {\n return this.#finalizeUnwrap(unwrapRequestId, \"finalize-unwrap\");\n }\n\n async #finalizeUnwrap(\n unwrapRequestId: EncryptedValue,\n telemetryOperation: TelemetryOperation,\n ): Promise<TransactionResult> {\n this.#requireSigner(\"finalizeUnwrap\");\n await requireChainAlignment(\"finalizeUnwrap\", this.sdk.signer, this.sdk.provider);\n const result = await this.sdk.decryption.decryptPublicValues([unwrapRequestId], {\n operation: telemetryOperation,\n });\n const clearValue = result.clearValues[unwrapRequestId];\n assertBigint(clearValue, \"finalizeUnwrap: clearValue\");\n return this.submitTransaction({\n operation: \"finalizeUnwrap\",\n config: finalizeUnwrapContract(\n this.address,\n unwrapRequestId,\n clearValue,\n result.decryptionProof,\n ),\n });\n }\n\n // PRIVATE HELPERS\n\n /**\n * Decode the `unwrapRequestId` from an unwrap/unshield receipt's logs.\n * Only logs emitted by this wrapper count: a caller-supplied tx hash from a\n * different wrapper must fail here, not decode a foreign request id. Logs\n * without an emitter address (older custom adapters) are kept.\n * Throws when no matching `UnwrapRequested` event is found.\n */\n #extractUnwrapRequestId(logs: readonly RawLog[]): EncryptedValue {\n const ownLogs = logs.filter(\n (log) => log.address === undefined || getAddress(log.address) === this.address,\n );\n const event = findUnwrapRequested(ownLogs);\n if (!event) {\n throw new TransactionRevertedError(\n \"No UnwrapRequested event from this wrapper found in the unwrap receipt\",\n );\n }\n return event.unwrapRequestId;\n }\n\n /**\n * True only when the unwrap request is definitely gone. `unwrapRequester`\n * returns the zero address once finalize deletes the request, and the id\n * always comes from the unwrap tx's own `UnwrapRequested` event, so zero can\n * only mean \"already finalized\". A failed read returns `false`: the check\n * fails open, so a network error never heals recovery state.\n */\n async #isUnwrapRequestConsumed(unwrapRequestId: EncryptedValue): Promise<boolean> {\n try {\n const requester = await this.sdk.provider.readContract(\n unwrapRequesterContract(this.address, unwrapRequestId),\n );\n return requester === zeroAddress;\n } catch {\n return false;\n }\n }\n\n /**\n * Consumed-request check for a persisted pointer; legacy hash-only entries\n * re-derive the request id from the unwrap receipt.\n */\n async #isPendingUnshieldConsumed(pending: PendingUnshieldRequest): Promise<boolean> {\n let unwrapRequestId = pending.unwrapRequestId;\n if (unwrapRequestId === undefined) {\n try {\n const receipt = await this.sdk.provider.waitForTransactionReceipt(pending.unwrapTxHash);\n unwrapRequestId = this.#extractUnwrapRequestId(receipt.logs);\n } catch {\n return false;\n }\n }\n return this.#isUnwrapRequestConsumed(unwrapRequestId);\n }\n\n async #clearStoredPendingUnshield(operation: string): Promise<void> {\n await swallow(\n `${operation}: clearPendingUnshield`,\n () => clearPendingUnshield(this.sdk.storage, this.address),\n this.sdk.logger,\n );\n }\n\n async #getUnderlying(): Promise<Address> {\n if (this.#underlying !== undefined) {\n return this.#underlying;\n }\n if (!this.#underlyingPromise) {\n this.#underlyingPromise = this.sdk.provider\n .readContract(underlyingContract(this.address))\n .then((v) => {\n this.#underlying = v;\n this.#underlyingPromise = null;\n return v;\n })\n .catch((error) => {\n this.#underlyingPromise = null;\n throw error;\n });\n }\n return this.#underlyingPromise;\n }\n\n /**\n * Phase 2 of unshield, shared by {@link unshield}/{@link unshieldAll} (which\n * pass the id `unwrap`/`unwrapAll` already decoded) and {@link resumeUnshield}\n * (which decoded it from a fetched receipt). Persists the unwrap hash for\n * recovery, finalizes, then clears the persisted state.\n */\n async #finalizeUnshield(\n unwrapRequestId: EncryptedValue,\n unwrapTxHash: Hex,\n operationId: string,\n callbacks: UnshieldCallbacks | undefined,\n telemetryOperation: TelemetryOperation,\n ): Promise<TransactionResult> {\n this.emit({ type: ZamaSDKEvents.UnshieldPhase1Submitted, txHash: unwrapTxHash, operationId });\n await swallow(\n \"unshield: savePendingUnshield\",\n () => savePendingUnshield(this.sdk.storage, this.address, unwrapTxHash, unwrapRequestId),\n this.sdk.logger,\n );\n this.emit({ type: ZamaSDKEvents.UnshieldPhase2Started, operationId });\n void swallow(\"unshield: onFinalizing\", () => callbacks?.onFinalizing?.(), this.sdk.logger);\n let finalizeResult: TransactionResult;\n try {\n finalizeResult = await this.#finalizeUnwrap(unwrapRequestId, telemetryOperation);\n } catch (error) {\n // The id comes from this wrapper's own UnwrapRequested event and the only\n // transition to \"gone\" is a successful finalize, so this revert means a\n // concurrent finalize won the race (second tab, double click, third\n // party). The funds arrived; heal.\n if (!isInvalidUnwrapRequestRevert(error)) {\n throw error;\n }\n await this.#clearStoredPendingUnshield(\"unshield\");\n throw new UnshieldAlreadyFinalizedError(\n \"The unwrap request was finalized concurrently — the funds were already delivered.\",\n { unwrapTxHash, unwrapRequestId },\n { cause: error },\n );\n }\n this.emit({\n type: ZamaSDKEvents.UnshieldPhase2Submitted,\n txHash: finalizeResult.txHash,\n operationId,\n });\n void swallow(\n \"unshield: onFinalizeSubmitted\",\n () => callbacks?.onFinalizeSubmitted?.(finalizeResult.txHash),\n this.sdk.logger,\n );\n // Phase 2 landed: the persisted recovery state is no longer needed.\n await this.#clearStoredPendingUnshield(\"unshield\");\n return finalizeResult;\n }\n\n async #ensureAllowance(\n amount: bigint,\n maxApproval: boolean,\n callbacks?: ShieldCallbacks,\n ): Promise<void> {\n this.#requireSigner(\"approveUnderlying\");\n const underlying = await this.#getUnderlying();\n const account = await requireAlignedWalletAccount(\n \"approveUnderlying\",\n this.sdk.signer,\n this.sdk.provider,\n );\n const userAddress = getAddress(account.address);\n const allowance = await this.sdk.provider.readContract(\n allowanceContract(underlying, userAddress, this.address),\n );\n\n if (allowance >= amount) {\n return;\n }\n\n // Reset to zero first when there's an existing non-zero allowance.\n // Required by non-standard tokens like USDT, and also mitigates the\n // ERC-20 approve race condition for all tokens.\n if (allowance > 0n) {\n await this.submitTransaction({\n operation: \"approveUnderlying:reset\",\n config: approveContract(underlying, this.address, 0n),\n });\n }\n\n const approvalAmount = maxApproval ? 2n ** 256n - 1n : amount;\n\n await this.submitTransaction({\n operation: \"approveUnderlying\",\n config: approveContract(underlying, this.address, approvalAmount),\n onSubmitted: callbacks?.onApprovalSubmitted,\n });\n }\n}\n"],"mappings":"wfAKA,SAAgB,EAAuB,EAA+B,CACpE,GAAI,EAAE,aAAiB,OACrB,OAAO,KAET,IAAM,EAAQ,EAAM,MACpB,GAAI,OAAO,GAAU,WAAY,GAAkB,EAAE,SAAU,GAC7D,OAAO,KAET,GAAM,CAAE,QAAS,EAIjB,OAHI,OAAO,GAAS,WAAY,GAAiB,EAAE,cAAe,GACzD,KAEF,OAAO,EAAK,WAAc,SAAW,EAAK,UAAY,IAC/D,CCCA,IAAa,EAAb,cAAmD,CAAU,CAE3D,aAEA,gBAEA,YAAY,EAAiB,EAA0C,EAAwB,CAC7F,MAAM,EAAc,yBAA0B,EAAS,CAAO,EAC9D,KAAK,KAAO,gCACZ,KAAK,aAAe,EAAQ,aAC5B,KAAK,gBAAkB,EAAQ,eACjC,CACF,EAEA,MAAM,EAAyB,uBACzB,EAAkC,EACtC,EAAQ,GAAG,EAAuB,UAAU,CAC9C,CAAC,CAAC,MAAM,EAAG,EAAE,EASb,SAAgB,EAA6B,EAAyB,CACpE,IAAK,IAAI,EAAU,EAAO,aAAmB,MAAO,EAAU,EAAQ,MAIpE,GAHI,EAAuB,CAAO,IAAM,GAItC,EAAQ,QAAQ,SAAS,CAAsB,GAC/C,EAAQ,QAAQ,SAAS,CAA+B,EAExD,MAAO,GAGX,MAAO,EACT,CCvDA,MAAa,EAAa,CACxB,CACE,KAAM,WACN,KAAM,YACN,OAAQ,CACN,CAAE,KAAM,QAAS,KAAM,UAAW,aAAc,SAAU,EAC1D,CAAE,KAAM,UAAW,KAAM,UAAW,aAAc,SAAU,CAC9D,EACA,QAAS,CAAC,CAAE,KAAM,GAAI,KAAM,UAAW,aAAc,SAAU,CAAC,EAChE,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,UAC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F,GAA4B,UAAU,EAC3C,IAAI,EACR,oFACA,CAAE,eAAc,iBAAgB,EAChC,CAAE,MAAO,CAAM,CACjB,GAPQ,CAQV,CAaA,OAZA,KAAK,KAAK,CACR,KAAM,EAAc,wBACpB,OAAQ,EAAe,OACvB,aACF,CAAC,EACD,EACE,oCACM,GAAW,sBAAsB,EAAe,MAAM,EAC5D,KAAK,IAAI,MACX,EAEA,MAAM,KAAKA,GAA4B,UAAU,EAC1C,CACT,CAEA,KAAML,GACJ,EACA,EACA,EACe,CACf,KAAKD,GAAe,mBAAmB,EACvC,IAAM,EAAa,MAAM,KAAKJ,GAAe,EAMvC,EAAc,GAAW,MALT,EACpB,oBACA,KAAK,IAAI,OACT,KAAK,IAAI,QACX,EAAA,CACuC,OAAO,EACxC,EAAY,MAAM,KAAK,IAAI,SAAS,aACxC,EAAkB,EAAY,EAAa,KAAK,OAAO,CACzD,EAEA,GAAI,GAAa,EACf,OAME,EAAY,IACd,MAAM,KAAK,kBAAkB,CAC3B,UAAW,0BACX,OAAQ,EAAgB,EAAY,KAAK,QAAS,EAAE,CACtD,CAAC,EAGH,IAAM,EAAiB,EAAc,IAAM,KAAO,GAAK,EAEvD,MAAM,KAAK,kBAAkB,CAC3B,UAAW,oBACX,OAAQ,EAAgB,EAAY,KAAK,QAAS,CAAc,EAChE,YAAa,GAAW,mBAC1B,CAAC,CACH,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zama-fhe/sdk",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"description": "TypeScript SDK for Zama fhEVM confidential smart contracts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"blockchain",
|
|
@@ -62,9 +62,6 @@
|
|
|
62
62
|
],
|
|
63
63
|
"vaults": [
|
|
64
64
|
"./dist/esm/vaults/index.d.ts"
|
|
65
|
-
],
|
|
66
|
-
"internal": [
|
|
67
|
-
"./dist/esm/internal/index.d.ts"
|
|
68
65
|
]
|
|
69
66
|
}
|
|
70
67
|
},
|
|
@@ -171,17 +168,6 @@
|
|
|
171
168
|
"./encrypt.worker.js": "./dist/esm/encrypt.worker.js",
|
|
172
169
|
"./package.json": {
|
|
173
170
|
"default": "./package.json"
|
|
174
|
-
},
|
|
175
|
-
"./internal": {
|
|
176
|
-
"import": {
|
|
177
|
-
"types": "./dist/esm/internal/index.d.ts",
|
|
178
|
-
"default": "./dist/esm/internal/index.js"
|
|
179
|
-
},
|
|
180
|
-
"require": {
|
|
181
|
-
"types": "./dist/esm/internal/index.d.ts",
|
|
182
|
-
"default": "./dist/cjs/internal/index.cjs"
|
|
183
|
-
},
|
|
184
|
-
"default": "./dist/esm/internal/index.js"
|
|
185
171
|
}
|
|
186
172
|
},
|
|
187
173
|
"publishConfig": {
|
package/dist/cjs/fatal-batch.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./relayer.cjs"),t=require("./signing.cjs");var n=class extends e.r{retryAfter;constructor(t,n){let{retryAfter:r,...i}=n??{};super(e.i.RpcRateLimited,t,i),this.name=`RpcRateLimitError`,this.retryAfter=r}};const r={[e.i.SigningRejected]:t.n,[e.i.SigningFailed]:t.t,[e.i.Configuration]:e.t,[e.i.RpcRateLimited]:n,[e.i.KeyWrappingFailed]:t.a,[e.i.RevokedKmsContext]:t.l};function i(e){return Object.values(r).some(t=>e instanceof t)}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
|
|
2
|
-
//# sourceMappingURL=fatal-batch.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fatal-batch.cjs","names":["ZamaError","ZamaErrorCode","ZamaErrorCode","SigningRejectedError","SigningFailedError","ConfigurationError","KeyWrappingError","RevokedKmsContextError"],"sources":["../../src/errors/rpc.ts","../../src/errors/fatal-batch.ts"],"sourcesContent":["import { ZamaError, ZamaErrorCode } from \"./base\";\n\n/**\n * The consumer's RPC provider rate-limited an on-chain read the SDK performs\n * during decryption (e.g. the ACL check) — HTTP 429 or JSON-RPC `-32005`. An\n * RPC-endpoint problem, **not** a decryption/entitlement failure, and safe to\n * **retry**. Kept distinct from the relayer's own back-pressure\n * ({@link RelayerRequestFailedError}).\n *\n * Backoff for chain RPC is owned by the consumer's transport: viem/ethers\n * already honor the `Retry-After` header and retry internally before this error\n * surfaces, so it is configured on the transport you pass via `chain.network`\n * (not re-implemented here).\n *\n * @example\n * ```ts\n * try {\n * await sdk.decryption.decryptValues([{ encryptedValue, contractAddress }]);\n * } catch (e) {\n * if (e instanceof RpcRateLimitError) {\n * // back off and retry; consider a higher-throughput RPC endpoint\n * }\n * }\n * ```\n */\nexport class RpcRateLimitError extends ZamaError {\n /**\n * Suggested delay before retrying, in **seconds**, when a numeric `retryAfter`\n * is present on the error. Usually `undefined` for chain RPC: the `Retry-After`\n * header is consumed by the consumer's viem/ethers transport (which owns the\n * backoff), not surfaced here — see the class doc.\n */\n readonly retryAfter: number | undefined;\n\n constructor(message: string, options?: ErrorOptions & { retryAfter?: number }) {\n const { retryAfter, ...errorOptions } = options ?? {};\n super(ZamaErrorCode.RpcRateLimited, message, errorOptions);\n this.name = \"RpcRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n","import { ZamaErrorCode, type ZamaError } from \"./base\";\nimport { KeyWrappingError, RevokedKmsContextError } from \"./credential\";\nimport { ConfigurationError } from \"./relayer\";\nimport { RpcRateLimitError } from \"./rpc\";\nimport { SigningRejectedError, SigningFailedError } from \"./signing\";\n\nexport const fatalBatchErrors = {\n [ZamaErrorCode.SigningRejected]: SigningRejectedError,\n [ZamaErrorCode.SigningFailed]: SigningFailedError,\n [ZamaErrorCode.Configuration]: ConfigurationError,\n [ZamaErrorCode.RpcRateLimited]: RpcRateLimitError,\n [ZamaErrorCode.KeyWrappingFailed]: KeyWrappingError,\n [ZamaErrorCode.RevokedKmsContext]: RevokedKmsContextError,\n} satisfies Partial<Record<ZamaErrorCode, new (message: string) => ZamaError>>;\n\n/** Systemic failures abort a batch because retrying each item would repeat the same failure. */\nexport function isFatalBatchError(error: unknown): boolean {\n return Object.values(fatalBatchErrors).some((Constructor) => error instanceof Constructor);\n}\n"],"mappings":"4DAyBA,IAAa,EAAb,cAAuCA,EAAAA,CAAU,CAO/C,WAEA,YAAY,EAAiB,EAAkD,CAC7E,GAAM,CAAE,aAAY,GAAG,GAAiB,GAAW,CAAC,EACpD,MAAMC,EAAAA,EAAc,eAAgB,EAAS,CAAY,EACzD,KAAK,KAAO,oBACZ,KAAK,WAAa,CACpB,CACF,EClCA,MAAa,EAAmB,EAC7BC,EAAAA,EAAc,iBAAkBC,EAAAA,GAChCD,EAAAA,EAAc,eAAgBE,EAAAA,GAC9BF,EAAAA,EAAc,eAAgBG,EAAAA,GAC9BH,EAAAA,EAAc,gBAAiB,GAC/BA,EAAAA,EAAc,mBAAoBI,EAAAA,GAClCJ,EAAAA,EAAc,mBAAoBK,EAAAA,CACrC,EAGA,SAAgB,EAAkB,EAAyB,CACzD,OAAO,OAAO,OAAO,CAAgB,CAAC,CAAC,KAAM,GAAgB,aAAiB,CAAW,CAC3F"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../fhevm-relayer.cjs"),t=require("../relayer.cjs"),n=require("../fatal-batch.cjs").t;function r(e,r,i){let a=n[e],o=a?new a(r):new t.r(e,r,e===t.i.RelayerRequestFailed?{retryable:i.retryable}:void 0);return o.retryable&&t.y(i.retryAfter)?Object.assign(o,{retryAfter:i.retryAfter}):o}function i(e,t){return e.onWalletAccountChange(t)}exports.reviveZamaError=r,exports.subscribeWalletAccountChanges=i,exports.toFhevmAuth=e.n;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["fatalBatchErrors","ZamaError","ZamaErrorCode","isValidRetryAfterSeconds"],"sources":["../../../src/errors/revive.ts","../../../src/internal/wallet-events.ts"],"sourcesContent":["import { isValidRetryAfterSeconds } from \"../utils/error\";\nimport { ZamaError, ZamaErrorCode } from \"./base\";\nimport { fatalBatchErrors } from \"./fatal-batch\";\n\nconst callbackErrors: Partial<Record<ZamaErrorCode, new (message: string) => ZamaError>> =\n fatalBatchErrors;\n\n/** Restores callback failures whose class identity controls batch termination. */\nexport function reviveZamaError(\n code: ZamaErrorCode,\n message: string,\n options: { retryable: boolean; retryAfter?: number },\n): ZamaError {\n const Constructor = callbackErrors[code];\n const error = Constructor\n ? new Constructor(message)\n : new ZamaError(\n code,\n message,\n code === ZamaErrorCode.RelayerRequestFailed ? { retryable: options.retryable } : undefined,\n );\n if (error.retryable && isValidRetryAfterSeconds(options.retryAfter)) {\n return Object.assign(error, { retryAfter: options.retryAfter });\n }\n return error;\n}\n","import type { WalletAccountListener } from \"../types/signer\";\nimport type { ZamaSDK } from \"../zama-sdk\";\n\n/** Subscribe after the SDK's wallet cleanup, through the internal integration entry point. */\nexport function subscribeWalletAccountChanges(\n sdk: ZamaSDK,\n listener: WalletAccountListener,\n): () => void {\n return sdk.onWalletAccountChange(listener);\n}\n"],"mappings":"uIAIM,8BACJA,CAAAA,CAAAA,EAGF,SAAgB,EACd,EACA,EACA,EACW,CACX,IAAM,EAAc,EAAe,GAC7B,EAAQ,EACV,IAAI,EAAY,CAAO,EACvB,IAAIC,EAAAA,EACF,EACA,EACA,IAASC,EAAAA,EAAc,qBAAuB,CAAE,UAAW,EAAQ,SAAU,EAAI,IAAA,EACnF,EAIJ,OAHI,EAAM,WAAaC,EAAAA,EAAyB,EAAQ,UAAU,EACzD,OAAO,OAAO,EAAO,CAAE,WAAY,EAAQ,UAAW,CAAC,EAEzD,CACT,CCrBA,SAAgB,EACd,EACA,EACY,CACZ,OAAO,EAAI,sBAAsB,CAAQ,CAC3C"}
|
package/dist/cjs/signing.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./relayer.cjs");var t=class extends e.r{constructor(t,n){super(e.i.TransportKeyPairExpired,t,n),this.name=`TransportKeyPairExpiredError`}},n=class extends e.r{constructor(t,n){super(e.i.InvalidTransportKeyPair,t,n),this.name=`InvalidTransportKeyPairError`}},r=class extends e.r{constructor(t,n){super(e.i.RevokedKmsContext,t,n),this.name=`RevokedKmsContextError`}},i=class extends e.r{constructor(t,n){super(e.i.NoCiphertext,t,n),this.name=`NoCiphertextError`}},a=class extends e.r{constructor(t,n){super(e.i.KeyWrappingFailed,t,n),this.name=`KeyWrappingError`}},o=class extends e.r{constructor(t,n){super(e.i.TransportKeyPairChanged,t,n),this.name=`TransportKeyPairChangedError`}},s=class extends e.r{preparedChainId;activeChainId;constructor({preparedChainId:t,activeChainId:n},r){super(e.i.PreparedPermitChainMismatch,`registerPermit: prepared.chainId (${t}) does not match the active chain (${n}). Register the permit while the SDK is configured for the chain it was prepared for.`,r),this.name=`PreparedPermitChainMismatchError`,this.preparedChainId=t,this.activeChainId=n}},c=class extends e.r{constructor(t,n){super(e.i.PreparedPermitExpired,t,n),this.name=`PreparedPermitExpiredError`}},l=class extends e.r{operation;rpcCode;walletErrorName;constructor(t,n){let{operation:r,rpcCode:i,walletErrorName:a,...o}=n??{};super(e.i.SigningRejected,t,o),this.name=`SigningRejectedError`,this.operation=r,this.rpcCode=i,this.walletErrorName=a}},u=class extends e.r{operation;rpcCode;walletErrorName;constructor(t,n){let{operation:r,rpcCode:i,walletErrorName:a,...o}=n??{};super(e.i.SigningFailed,t,o),this.name=`SigningFailedError`,this.operation=r,this.rpcCode=i,this.walletErrorName=a}};function d(t,r){if(t instanceof e.r)return t;let{operation:i}=r,a=typeof t==`object`&&!!t&&`code`in t&&t.code===4001,o=t instanceof Error?t.message:String(t),s=o.toLowerCase(),c=s.includes(`user rejected`)||s.includes(`user denied`),d=`${i}: ${o}`;return a||c?new l(d,{cause:t,operation:i,rpcCode:e.l(t),walletErrorName:e.u(t)}):e.p(o)?new n(d,{cause:t}):new u(d,{cause:t,operation:i,rpcCode:e.l(t),walletErrorName:e.u(t)})}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return o}});
|
|
2
|
-
//# sourceMappingURL=signing.cjs.map
|
package/dist/cjs/signing.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signing.cjs","names":["ZamaError","ZamaErrorCode","ZamaError","ZamaErrorCode","extractRpcErrorCode","extractWalletErrorName","isInvalidTransportKeyPairMessage"],"sources":["../../src/errors/credential.ts","../../src/errors/signing.ts"],"sourcesContent":["import { ZamaError, ZamaErrorCode } from \"./base\";\n\n/** Transport key pair has expired and needs regeneration. */\nexport class TransportKeyPairExpiredError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.TransportKeyPairExpired, message, options);\n this.name = \"TransportKeyPairExpiredError\";\n }\n}\n\n/** Relayer rejected the transport key pair (stale, expired, or malformed). */\nexport class InvalidTransportKeyPairError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.InvalidTransportKeyPair, message, options);\n this.name = \"InvalidTransportKeyPairError\";\n }\n}\n\n/**\n * The permit's KMS context has been revoked on-chain, so the permit (and every\n * other permit signed under that context) is permanently unusable. The SDK\n * already tried to self-heal before surfacing this. Check `cause` to tell why\n * it failed: a `SigningFailedError` means the configured signer could not\n * produce a new permit, waiting will not help, establish a new permit with a\n * working signer. Any other cause means the retry hit the same revoked\n * context, typically because the upstream validity check caches a stale\n * \"valid\" verdict for up to 15 minutes; wait out that window and retry.\n */\nexport class RevokedKmsContextError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.RevokedKmsContext, message, options);\n this.name = \"RevokedKmsContextError\";\n }\n}\n\n/** No FHE ciphertext exists for this account (never shielded). */\nexport class NoCiphertextError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.NoCiphertext, message, options);\n this.name = \"NoCiphertextError\";\n }\n}\n\n/**\n * Wrapping or unwrapping the transport private key with `transportKeyPairDerivationSecret` failed:\n * a scoped entry that fails to unwrap may belong to a peer using a different secret, so it fails\n * loudly instead of silently regenerating and clobbering that peer's entry, or the underlying\n * WebCrypto operation itself failed (e.g. `crypto.subtle` unavailable in this environment).\n */\nexport class KeyWrappingError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.KeyWrappingFailed, message, options);\n this.name = \"KeyWrappingError\";\n }\n}\n\n/**\n * The transport key pair changed between `preparePermit` and `registerPermit`\n * (expired, evicted, or rotated in between). The prepared EIP-712 payload was\n * signed against the old key pair's public key — registering it under a\n * different one would persist a permit bound to the wrong key. Call\n * `preparePermit` again to rebind the signature request to the current key pair.\n */\nexport class TransportKeyPairChangedError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.TransportKeyPairChanged, message, options);\n this.name = \"TransportKeyPairChangedError\";\n }\n}\n\n/**\n * A prepared permit's `chainId` doesn't match the chain `registerPermit` is\n * running against. The EIP-712 payload's domain is bound to the chain it was\n * prepared for; registering it under a different chain would persist a permit\n * whose signed payload disagrees with its storage scope.\n */\nexport class PreparedPermitChainMismatchError extends ZamaError {\n /** Chain ID the permit was prepared for. */\n readonly preparedChainId: number;\n /** Chain ID `registerPermit` is currently running against. */\n readonly activeChainId: number;\n\n constructor(\n { preparedChainId, activeChainId }: { preparedChainId: number; activeChainId: number },\n options?: ErrorOptions,\n ) {\n super(\n ZamaErrorCode.PreparedPermitChainMismatch,\n `registerPermit: prepared.chainId (${preparedChainId}) does not match the active chain ` +\n `(${activeChainId}). Register the permit while the SDK is configured for the chain it was prepared for.`,\n options,\n );\n this.name = \"PreparedPermitChainMismatchError\";\n this.preparedChainId = preparedChainId;\n this.activeChainId = activeChainId;\n }\n}\n\n/** A prepared permit's validity window elapsed before its signature was registered. */\nexport class PreparedPermitExpiredError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.PreparedPermitExpired, message, options);\n this.name = \"PreparedPermitExpiredError\";\n }\n}\n","import {\n extractRpcErrorCode,\n extractWalletErrorName,\n isInvalidTransportKeyPairMessage,\n} from \"../utils/error\";\nimport { ZamaError, ZamaErrorCode } from \"./base\";\nimport { InvalidTransportKeyPairError } from \"./credential\";\n\n/**\n * Diagnostic metadata attached to a signing-failure error, on top of the\n * inherited `cause`. All optional and best-effort: `operation` comes from the\n * caller, `rpcCode`/`walletErrorName` are extracted from the wallet's raw\n * error by {@link wrapSigningError}.\n */\nexport interface SigningErrorMetadata {\n /** Name of the SDK operation that was signing when the wallet/provider failed (e.g. \"grantPermit\"). */\n operation?: string;\n /** JSON-RPC / EIP-1193 numeric error code found in the failure's cause chain, if any. */\n rpcCode?: number;\n /** `name` of the error class the wallet/provider library threw (e.g. viem's `InvalidParamsRpcError`). */\n walletErrorName?: string;\n}\n\n/** User rejected the wallet signature prompt. */\nexport class SigningRejectedError extends ZamaError {\n /** Name of the SDK operation that was signing when the user rejected. */\n readonly operation: string | undefined;\n /** JSON-RPC / EIP-1193 numeric error code found in the failure's cause chain, if any. */\n readonly rpcCode: number | undefined;\n /** `name` of the error class the wallet/provider library threw. */\n readonly walletErrorName: string | undefined;\n\n constructor(message: string, options?: ErrorOptions & SigningErrorMetadata) {\n const { operation, rpcCode, walletErrorName, ...errorOptions } = options ?? {};\n super(ZamaErrorCode.SigningRejected, message, errorOptions);\n this.name = \"SigningRejectedError\";\n this.operation = operation;\n this.rpcCode = rpcCode;\n this.walletErrorName = walletErrorName;\n }\n}\n\n/** Wallet signature failed for a reason other than rejection. */\nexport class SigningFailedError extends ZamaError {\n /** Name of the SDK operation that was signing when the wallet/provider failed. */\n readonly operation: string | undefined;\n /** JSON-RPC / EIP-1193 numeric error code found in the failure's cause chain, if any. */\n readonly rpcCode: number | undefined;\n /** `name` of the error class the wallet/provider library threw. */\n readonly walletErrorName: string | undefined;\n\n constructor(message: string, options?: ErrorOptions & SigningErrorMetadata) {\n const { operation, rpcCode, walletErrorName, ...errorOptions } = options ?? {};\n super(ZamaErrorCode.SigningFailed, message, errorOptions);\n this.name = \"SigningFailedError\";\n this.operation = operation;\n this.rpcCode = rpcCode;\n this.walletErrorName = walletErrorName;\n }\n}\n\n/**\n * Classify a caught signing error into {@link SigningRejectedError},\n * {@link SigningFailedError}, or {@link InvalidTransportKeyPairError} and\n * return it rather than throw (mirroring {@link wrapDecryptError}/\n * {@link wrapEncryptError}), so a caller can emit an observability event\n * carrying the classified error before throwing it themselves. Enriches the\n * result with `rpcCode`/`walletErrorName` extracted from `error`'s cause\n * chain, and passes an already-typed `ZamaError` through unchanged.\n */\nexport function wrapSigningError(error: unknown, context: { operation: string }): ZamaError {\n if (error instanceof ZamaError) {\n return error;\n }\n const { operation } = context;\n const hasCode4001 =\n typeof error === \"object\" && error !== null && \"code\" in error && error.code === 4001;\n const originalMsg = error instanceof Error ? error.message : String(error);\n const lowerMsg = originalMsg.toLowerCase();\n const hasRejectionMessage =\n lowerMsg.includes(\"user rejected\") || lowerMsg.includes(\"user denied\");\n const fullMessage = `${operation}: ${originalMsg}`;\n if (hasCode4001 || hasRejectionMessage) {\n return new SigningRejectedError(fullMessage, {\n cause: error,\n operation,\n rpcCode: extractRpcErrorCode(error),\n walletErrorName: extractWalletErrorName(error),\n });\n }\n // A stale transport key pair the relayer can't re-derive (post-rotation) is\n // not a signing failure per se — surface it as the typed, self-heal signal so\n // the caller can evict the vault entry and regenerate.\n if (isInvalidTransportKeyPairMessage(originalMsg)) {\n return new InvalidTransportKeyPairError(fullMessage, { cause: error });\n }\n return new SigningFailedError(fullMessage, {\n cause: error,\n operation,\n rpcCode: extractRpcErrorCode(error),\n walletErrorName: extractWalletErrorName(error),\n });\n}\n"],"mappings":"iCAGA,IAAa,EAAb,cAAkDA,EAAAA,CAAU,CAC1D,YAAY,EAAiB,EAAwB,CACnD,MAAMC,EAAAA,EAAc,wBAAyB,EAAS,CAAO,EAC7D,KAAK,KAAO,8BACd,CACF,EAGa,EAAb,cAAkDD,EAAAA,CAAU,CAC1D,YAAY,EAAiB,EAAwB,CACnD,MAAMC,EAAAA,EAAc,wBAAyB,EAAS,CAAO,EAC7D,KAAK,KAAO,8BACd,CACF,EAYa,EAAb,cAA4CD,EAAAA,CAAU,CACpD,YAAY,EAAiB,EAAwB,CACnD,MAAMC,EAAAA,EAAc,kBAAmB,EAAS,CAAO,EACvD,KAAK,KAAO,wBACd,CACF,EAGa,EAAb,cAAuCD,EAAAA,CAAU,CAC/C,YAAY,EAAiB,EAAwB,CACnD,MAAMC,EAAAA,EAAc,aAAc,EAAS,CAAO,EAClD,KAAK,KAAO,mBACd,CACF,EAQa,EAAb,cAAsCD,EAAAA,CAAU,CAC9C,YAAY,EAAiB,EAAwB,CACnD,MAAMC,EAAAA,EAAc,kBAAmB,EAAS,CAAO,EACvD,KAAK,KAAO,kBACd,CACF,EASa,EAAb,cAAkDD,EAAAA,CAAU,CAC1D,YAAY,EAAiB,EAAwB,CACnD,MAAMC,EAAAA,EAAc,wBAAyB,EAAS,CAAO,EAC7D,KAAK,KAAO,8BACd,CACF,EAQa,EAAb,cAAsDD,EAAAA,CAAU,CAE9D,gBAEA,cAEA,YACE,CAAE,kBAAiB,iBACnB,EACA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