diff --git a/src/sdk/ACL.json b/src/sdk/ACL.json new file mode 100644 index 0000000..5853bbe --- /dev/null +++ b/src/sdk/ACL.json @@ -0,0 +1,381 @@ +{ + "_format": "hh-sol-artifact-1", + "contractName": "ACL", + "sourceName": "fhevm/lib/ACL.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "_coprocessorAddress", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256[]", + "name": "handlesList", + "type": "uint256[]" + } + ], + "name": "AllowedForDecryption", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "contractAddress", + "type": "address" + } + ], + "name": "NewDelegation", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "contractAddress", + "type": "address" + } + ], + "name": "RevokedDelegation", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "handle", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "allow", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "handlesList", + "type": "uint256[]" + } + ], + "name": "allowForDecryption", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "handle", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "allowTransient", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "allowedForDecryption", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "internalType": "uint256", + "name": "handle", + "type": "uint256" + }, + { + "internalType": "address", + "name": "contractAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "allowedOnBehalf", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "handle", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "allowedTransient", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "cleanTransientStorage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "internalType": "address", + "name": "contractAddress", + "type": "address" + } + ], + "name": "delegateAccountForContract", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "internalType": "address", + "name": "contractAddress", + "type": "address" + } + ], + "name": "delegates", + "outputs": [ + { + "internalType": "bool", + "name": "isDelegate", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "fhEVMcoprocessorAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVersion", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "handle", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "isAllowed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "handle", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "persistAllowed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "handle", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "persistedAllowedPairs", + "outputs": [ + { + "internalType": "bool", + "name": "isAllowed", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "internalType": "address", + "name": "contractAddress", + "type": "address" + } + ], + "name": "removeDelegationForContract", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x60a060405234801561000f575f80fd5b50604051610e03380380610e0383398101604081905261002e9161003f565b6001600160a01b031660805261006c565b5f6020828403121561004f575f80fd5b81516001600160a01b0381168114610065575f80fd5b9392505050565b608051610d7861008b5f395f818161011701526105380152610d785ff3fe608060405234801561000f575f80fd5b50600436106100f0575f3560e01c80637a9a598e11610093578063b198d65711610063578063b198d65714610248578063c151dcf31461025b578063ccd9a7cd1461027d578063f623fab414610290575f80fd5b80637a9a598e146101dc5780638d9c9c92146101ef578063985d44ab14610202578063b0f4173714610215575f80fd5b806337e6b44f116100ce57806337e6b44f1461015b578063557e1004146101a35780635faa299a146101b657806365d0509c146101c9575f80fd5b80630d8e6e2c146100f457806331d87e7d1461011257806335334c2314610151575b5f80fd5b6100fc6102bd565b6040516101099190610a8a565b60405180910390f35b6101397f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610109565b61015961031e565b005b610193610169366004610ad7565b5f9182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6040519015158152602001610109565b6101596101b1366004610b15565b610348565b6101936101c4366004610ad7565b610420565b6101596101d7366004610ad7565b61045e565b6101936101ea366004610ad7565b6104da565b6101596101fd366004610ad7565b61052d565b610159610210366004610bce565b610606565b610193610223366004610bf6565b600260209081525f938452604080852082529284528284209052825290205460ff1681565b610159610256366004610bce565b6106ec565b610193610269366004610c36565b5f6020819052908152604090205460ff1681565b61019361028b366004610c4d565b610854565b61019361029e366004610ad7565b600160209081525f928352604080842090915290825290205460ff1681565b6060604051806040016040528060038152602001621050d360ea1b8152506102e45f6108e9565b6102ee60016108e9565b6102f75f6108e9565b60405160200161030a9493929190610c97565b604051602081830303815290604052905090565b5f5c5f805d600190810190805b8281101561034357805c5f825d5f815d50810161032b565b505050565b80515f5b818110156103e4575f83828151811061036757610367610d14565b6020026020010151905061037b8133610420565b6103c35760405162461bcd60e51b81526020600482015260146024820152731cd95b99195c881a5cdb89dd08185b1b1bddd95960621b60448201526064015b60405180910390fd5b5f908152602081905260409020805460ff191660019081179091550161034c565b507f2fd616621b8415a2efb27b224024340ac767797553ce6fdf4c1adefd160504c6826040516104149190610d28565b60405180910390a15050565b5f61042b83836104da565b8061045757505f8381526001602090815260408083206001600160a01b038616845290915290205460ff165b9392505050565b6104688233610420565b6104ab5760405162461bcd60e51b81526020600482015260146024820152731cd95b99195c881a5cdb89dd08185b1b1bddd95960621b60448201526064016103ba565b5f9182526001602081815260408085206001600160a01b0390941685529290529120805460ff19169091179055565b5f805f848460405160200161050b92919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60408051808303601f1901815291905280516020909101205c95945050505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105aa576105678233610420565b6105aa5760405162461bcd60e51b81526020600482015260146024820152731cd95b99195c881a5cdb89dd08185b1b1bddd95960621b60448201526064016103ba565b5f82826040516020016105d992919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b6040516020818303038152906040528051906020012090506001815d60015f5c0181815d805f5d50505050565b335f9081526002602090815260408083206001600160a01b038681168552908352818420908516845290915290205460ff166106845760405162461bcd60e51b815260206004820152601160248201527f6e6f742064656c6567617465642079657400000000000000000000000000000060448201526064016103ba565b335f8181526002602090815260408083206001600160a01b038781168086529184528285209087168086529352818420805460ff1916905590519193909290917f718a1622aecd6d64aeaebe3b2110f9e2a337cc379e87b327fd1c50a683808ff69190a45050565b336001600160a01b0382160361076a5760405162461bcd60e51b815260206004820152603360248201527f636f6e7472616374416464726573732073686f756c642062652064696666657260448201527f656e742066726f6d206d73672e73656e6465720000000000000000000000000060648201526084016103ba565b335f9081526002602090815260408083206001600160a01b038681168552908352818420908516845290915290205460ff16156107e95760405162461bcd60e51b815260206004820152601160248201527f616c72656164792064656c65676174656400000000000000000000000000000060448201526064016103ba565b335f8181526002602090815260408083206001600160a01b038781168086529184528285209087168086529352818420805460ff1916600117905590519193909290917ff03b7c0d4879b0bcbbf440794871f139c96fd13a145a8172b33b9cab5fa2830a9190a45050565b5f8381526001602090815260408083206001600160a01b038516845290915281205460ff1680156108a657505f8481526001602090815260408083206001600160a01b038716845290915290205460ff165b80156108e057506001600160a01b038083165f908152600260209081526040808320898516845282528083209387168352929052205460ff165b95945050505050565b60605f6108f583610986565b60010190505f8167ffffffffffffffff81111561091457610914610b01565b6040519080825280601f01601f19166020018201604052801561093e576020820181803683370190505b5090508181016020015b5f19017f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a850494508461094857509392505050565b5f807a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083106109ce577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef810000000083106109fa576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310610a1857662386f26fc10000830492506010015b6305f5e1008310610a30576305f5e100830492506008015b6127108310610a4457612710830492506004015b60648310610a56576064830492506002015b600a8310610a62576001015b92915050565b5f5b83811015610a82578181015183820152602001610a6a565b50505f910152565b602081525f8251806020840152610aa8816040850160208701610a68565b601f01601f19169190910160400192915050565b80356001600160a01b0381168114610ad2575f80fd5b919050565b5f8060408385031215610ae8575f80fd5b82359150610af860208401610abc565b90509250929050565b634e487b7160e01b5f52604160045260245ffd5b5f6020808385031215610b26575f80fd5b823567ffffffffffffffff80821115610b3d575f80fd5b818501915085601f830112610b50575f80fd5b813581811115610b6257610b62610b01565b8060051b604051601f19603f83011681018181108582111715610b8757610b87610b01565b604052918252848201925083810185019188831115610ba4575f80fd5b938501935b82851015610bc257843584529385019392850192610ba9565b98975050505050505050565b5f8060408385031215610bdf575f80fd5b610be883610abc565b9150610af860208401610abc565b5f805f60608486031215610c08575f80fd5b610c1184610abc565b9250610c1f60208501610abc565b9150610c2d60408501610abc565b90509250925092565b5f60208284031215610c46575f80fd5b5035919050565b5f805f8060808587031215610c60575f80fd5b610c6985610abc565b935060208501359250610c7e60408601610abc565b9150610c8c60608601610abc565b905092959194509250565b5f8551610ca8818460208a01610a68565b61103b60f11b9083019081528551610cc7816002840160208a01610a68565b808201915050601760f91b8060028301528551610ceb816003850160208a01610a68565b60039201918201528351610d06816004840160208801610a68565b016004019695505050505050565b634e487b7160e01b5f52603260045260245ffd5b602080825282518282018190525f9190848201906040850190845b81811015610d5f57835183529284019291840191600101610d43565b5090969550505050505056fea164736f6c6343000818000a", + "deployedBytecode": "0x608060405234801561000f575f80fd5b50600436106100f0575f3560e01c80637a9a598e11610093578063b198d65711610063578063b198d65714610248578063c151dcf31461025b578063ccd9a7cd1461027d578063f623fab414610290575f80fd5b80637a9a598e146101dc5780638d9c9c92146101ef578063985d44ab14610202578063b0f4173714610215575f80fd5b806337e6b44f116100ce57806337e6b44f1461015b578063557e1004146101a35780635faa299a146101b657806365d0509c146101c9575f80fd5b80630d8e6e2c146100f457806331d87e7d1461011257806335334c2314610151575b5f80fd5b6100fc6102bd565b6040516101099190610a8a565b60405180910390f35b6101397f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610109565b61015961031e565b005b610193610169366004610ad7565b5f9182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6040519015158152602001610109565b6101596101b1366004610b15565b610348565b6101936101c4366004610ad7565b610420565b6101596101d7366004610ad7565b61045e565b6101936101ea366004610ad7565b6104da565b6101596101fd366004610ad7565b61052d565b610159610210366004610bce565b610606565b610193610223366004610bf6565b600260209081525f938452604080852082529284528284209052825290205460ff1681565b610159610256366004610bce565b6106ec565b610193610269366004610c36565b5f6020819052908152604090205460ff1681565b61019361028b366004610c4d565b610854565b61019361029e366004610ad7565b600160209081525f928352604080842090915290825290205460ff1681565b6060604051806040016040528060038152602001621050d360ea1b8152506102e45f6108e9565b6102ee60016108e9565b6102f75f6108e9565b60405160200161030a9493929190610c97565b604051602081830303815290604052905090565b5f5c5f805d600190810190805b8281101561034357805c5f825d5f815d50810161032b565b505050565b80515f5b818110156103e4575f83828151811061036757610367610d14565b6020026020010151905061037b8133610420565b6103c35760405162461bcd60e51b81526020600482015260146024820152731cd95b99195c881a5cdb89dd08185b1b1bddd95960621b60448201526064015b60405180910390fd5b5f908152602081905260409020805460ff191660019081179091550161034c565b507f2fd616621b8415a2efb27b224024340ac767797553ce6fdf4c1adefd160504c6826040516104149190610d28565b60405180910390a15050565b5f61042b83836104da565b8061045757505f8381526001602090815260408083206001600160a01b038616845290915290205460ff165b9392505050565b6104688233610420565b6104ab5760405162461bcd60e51b81526020600482015260146024820152731cd95b99195c881a5cdb89dd08185b1b1bddd95960621b60448201526064016103ba565b5f9182526001602081815260408085206001600160a01b0390941685529290529120805460ff19169091179055565b5f805f848460405160200161050b92919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60408051808303601f1901815291905280516020909101205c95945050505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105aa576105678233610420565b6105aa5760405162461bcd60e51b81526020600482015260146024820152731cd95b99195c881a5cdb89dd08185b1b1bddd95960621b60448201526064016103ba565b5f82826040516020016105d992919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b6040516020818303038152906040528051906020012090506001815d60015f5c0181815d805f5d50505050565b335f9081526002602090815260408083206001600160a01b038681168552908352818420908516845290915290205460ff166106845760405162461bcd60e51b815260206004820152601160248201527f6e6f742064656c6567617465642079657400000000000000000000000000000060448201526064016103ba565b335f8181526002602090815260408083206001600160a01b038781168086529184528285209087168086529352818420805460ff1916905590519193909290917f718a1622aecd6d64aeaebe3b2110f9e2a337cc379e87b327fd1c50a683808ff69190a45050565b336001600160a01b0382160361076a5760405162461bcd60e51b815260206004820152603360248201527f636f6e7472616374416464726573732073686f756c642062652064696666657260448201527f656e742066726f6d206d73672e73656e6465720000000000000000000000000060648201526084016103ba565b335f9081526002602090815260408083206001600160a01b038681168552908352818420908516845290915290205460ff16156107e95760405162461bcd60e51b815260206004820152601160248201527f616c72656164792064656c65676174656400000000000000000000000000000060448201526064016103ba565b335f8181526002602090815260408083206001600160a01b038781168086529184528285209087168086529352818420805460ff1916600117905590519193909290917ff03b7c0d4879b0bcbbf440794871f139c96fd13a145a8172b33b9cab5fa2830a9190a45050565b5f8381526001602090815260408083206001600160a01b038516845290915281205460ff1680156108a657505f8481526001602090815260408083206001600160a01b038716845290915290205460ff165b80156108e057506001600160a01b038083165f908152600260209081526040808320898516845282528083209387168352929052205460ff165b95945050505050565b60605f6108f583610986565b60010190505f8167ffffffffffffffff81111561091457610914610b01565b6040519080825280601f01601f19166020018201604052801561093e576020820181803683370190505b5090508181016020015b5f19017f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a850494508461094857509392505050565b5f807a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083106109ce577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef810000000083106109fa576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310610a1857662386f26fc10000830492506010015b6305f5e1008310610a30576305f5e100830492506008015b6127108310610a4457612710830492506004015b60648310610a56576064830492506002015b600a8310610a62576001015b92915050565b5f5b83811015610a82578181015183820152602001610a6a565b50505f910152565b602081525f8251806020840152610aa8816040850160208701610a68565b601f01601f19169190910160400192915050565b80356001600160a01b0381168114610ad2575f80fd5b919050565b5f8060408385031215610ae8575f80fd5b82359150610af860208401610abc565b90509250929050565b634e487b7160e01b5f52604160045260245ffd5b5f6020808385031215610b26575f80fd5b823567ffffffffffffffff80821115610b3d575f80fd5b818501915085601f830112610b50575f80fd5b813581811115610b6257610b62610b01565b8060051b604051601f19603f83011681018181108582111715610b8757610b87610b01565b604052918252848201925083810185019188831115610ba4575f80fd5b938501935b82851015610bc257843584529385019392850192610ba9565b98975050505050505050565b5f8060408385031215610bdf575f80fd5b610be883610abc565b9150610af860208401610abc565b5f805f60608486031215610c08575f80fd5b610c1184610abc565b9250610c1f60208501610abc565b9150610c2d60408501610abc565b90509250925092565b5f60208284031215610c46575f80fd5b5035919050565b5f805f8060808587031215610c60575f80fd5b610c6985610abc565b935060208501359250610c7e60408601610abc565b9150610c8c60608601610abc565b905092959194509250565b5f8551610ca8818460208a01610a68565b61103b60f11b9083019081528551610cc7816002840160208a01610a68565b808201915050601760f91b8060028301528551610ceb816003850160208a01610a68565b60039201918201528351610d06816004840160208801610a68565b016004019695505050505050565b634e487b7160e01b5f52603260045260245ffd5b602080825282518282018190525f9190848201906040850190845b81811015610d5f57835183529284019291840191600101610d43565b5090969550505050505056fea164736f6c6343000818000a", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/src/sdk/index.ts b/src/sdk/index.ts index a33b89a..ccd4807 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -1,5 +1,4 @@ import { TfheCompactPublicKey } from 'node-tfhe'; -import type { Eip1193Provider } from 'ethers'; import { URL } from 'url'; import { fromHexString } from '../utils'; import { ZKInput } from './encrypt'; @@ -7,8 +6,6 @@ import { getPublicKeyFromNetwork, getPublicKeyFromCoprocessor, getChainIdFromNetwork, - getChainIdFromEip1193, - getPublicKeyFromEip1193, } from './network'; import { createEncryptedInput } from './encrypt'; import { generateKeypair, createEIP712, EIP712 } from './keypair'; @@ -25,9 +22,9 @@ type FhevmInstanceConfig = { chainId?: number; publicKey?: string; gatewayUrl?: string; - network?: Eip1193Provider; networkUrl?: string; coprocessorUrl?: string; + aclAddress?: string; }; export type FhevmInstance = { @@ -55,7 +52,8 @@ export type FhevmInstance = { export const createInstance = async ( config: FhevmInstanceConfig, ): Promise => { - let { publicKey, networkUrl, network, gatewayUrl, coprocessorUrl } = config; + let { publicKey, networkUrl, gatewayUrl, coprocessorUrl, aclAddress } = + config; if (gatewayUrl) { gatewayUrl = new URL(gatewayUrl).href; @@ -76,8 +74,6 @@ export const createInstance = async ( throw new Error('chainId must be a number.'); } else if (networkUrl) { chainId = await getChainIdFromNetwork(networkUrl); - } else if (network) { - chainId = await getChainIdFromEip1193(network); } else { throw new Error( "You didn't provide the chainId nor the network url to get it.", @@ -89,8 +85,10 @@ export const createInstance = async ( publicKey = data.publicKey; } else if (networkUrl && !publicKey) { publicKey = await getPublicKeyFromNetwork(networkUrl); - } else if (network && !publicKey) { - publicKey = await getPublicKeyFromEip1193(network); + } + + if (networkUrl && !chainId) { + chainId = await getChainIdFromNetwork(networkUrl); } if (publicKey && typeof publicKey !== 'string') @@ -114,7 +112,7 @@ export const createInstance = async ( ), generateKeypair, createEIP712: createEIP712(chainId), - reencrypt: reencryptRequest(gatewayUrl), + reencrypt: reencryptRequest(gatewayUrl, networkUrl, aclAddress), getPublicKey: () => publicKey || null, }; }; diff --git a/src/sdk/reencrypt.ts b/src/sdk/reencrypt.ts index 919a7e5..5c2266a 100644 --- a/src/sdk/reencrypt.ts +++ b/src/sdk/reencrypt.ts @@ -10,9 +10,12 @@ import { process_reencryption_resp_from_json, u8vec_to_cryptobox_sk, } from '../kms/node/kms_lib.js'; +import { ethers } from 'ethers'; + +import aclArtifact from './ACL.json'; export const reencryptRequest = - (gatewayUrl?: string) => + (gatewayUrl?: string, networkUrl?: string, aclAddress?: string) => async ( handle: bigint, privateKey: string, @@ -22,6 +25,20 @@ export const reencryptRequest = userAddress: string, ) => { if (!gatewayUrl) throw new Error('You must provide a reencryption URL.'); + if (!aclAddress) throw new Error('You must provide the ACL address.'); + const provider = new ethers.JsonRpcProvider(networkUrl); + const acl = new ethers.Contract(contractAddress, aclArtifact.abi, provider); + const userAllowed = await acl.persistAllowed(handle, userAddress); + const contractAllowed = await acl.persistAllowed(handle, contractAddress); + const isAllowed = userAllowed && contractAllowed; + if (!isAllowed) { + throw new Error('User is not authorized to reencrypt this handle!'); + } + if (userAddress === contractAddress) { + throw new Error( + 'userAddress should not be equal to contractAddress when requesting reencryption!', + ); + } const payload = { signature: signature.replace(/^(0x)/, ''),