LIT-Protocol / Issues-and-Reports

For bug reports, feature requests, and implementation questions related to Lit Protocol and use of the Lit SDK.
0 stars 0 forks source link

[Dbrains] <Bug decrypting on Sepolia, encrypting/decrypting with baseSepolia > #9

Closed brunolune closed 6 months ago

brunolune commented 6 months ago

Is there an existing issue for this?

SDK version

"@lit-protocol/lit-node-client": "^3.0.5", "@lit-protocol/lit-node-client-nodejs": "^3.0.5", "@lit-protocol/types": "^3.0.5",

Lit Network

cayenne

Description of the bug/issue

Hi! I am developing an app using ceramic network and lit protocol for encrypting data. I actually was able to do encrypt/decrypt messages using mumbai. However, I needed to change of blockchain due to mumbai deprecation.

I tried base sepolia but cannot even encrypt data and got error message:

" index.esm.mjs:2114 Uncaught (in promise) errConstructorFunc {message: 'Unsupported chain selected. Please select one of:…evmosCosmosTestnet,cheqdMainnet,cheqdTestnet,juno', errorCode: 'UnsupportedChainException', errorKind: 'Validation', status: undefined, details: undefined} details : undefined errorCode : "UnsupportedChainException" errorKind : "Validation" message : "Unsupported chain selected. Please select one of: ethereum,polygon,fantom,xdai,bsc,arbitrum,avalanche,fuji,harmony,mumbai,goerli,cronos,optimism,celo,aurora,eluvio,alfajores,xdc,evmos,evmosTestnet,bscTestnet,baseGoerli,moonbeam,moonriver,moonbaseAlpha,filecoin,hyperspace,sepolia,scrollAlphaTestnet,zksync,zksyncTestnet,lineaGoerli,chronicleTestnet,chiado,zkEvm,mantleTestnet,mantle,klaytn,publicGoodsNetwork,optimismGoerli,waevEclipseTestnet,waevEclipseDevnet,solana,solanaDevnet,solanaTestnet,cosmos,kyve,evmosCosmos,evmosCosmosTestnet,cheqdMainnet,cheqdTestnet,juno" status : undefined [[Prototype]] : Object "

Looks like baseSepolia is not yet supported by lit? Although it is listed on https://developer.litprotocol.com/v3/resources/supported-chains.

I also tried Sepolia blockchain: encrypting worked but got issue decrypting, although Sepolia is in the above list of supported blockchain, I got the following error when decrypting data with Sepolia :

[Lit-JS-SDK v3.0.5] getting provider via lit connect modal misc.js:155 [Lit-JS-SDK v3.0.5] got provider Proxy(f) {_events: {…}, _eventsCount: 4, _maxListeners: 100, _log: d, _state: {…}, …} misc.js:155 [Lit-JS-SDK v3.0.5] @deprecated soon to be removed. - trying to enable provider. this will trigger the metamask popup. misc.js:155 [Lit-JS-SDK v3.0.5] listing accounts misc.js:155 [Lit-JS-SDK v3.0.5] accounts ['0x8a1fb49cB17ab6D1BF2CaC34E1F06451C8205605'] misc.js:155 [Lit-JS-SDK v3.0.5] got web3 and account: 0x8a1fb49cb17ab6d1bf2cac34e1f06451c8205605 misc.js:155 [Lit-JS-SDK v3.0.5] currentChainIdOrError: {type: 'SUCCESS', result: 11155111} misc.js:155 [Lit-JS-SDK v3.0.5] selectedChainId: 11155111 misc.js:155 [Lit-JS-SDK v3.0.5] selectedChainIdHex: 0xaa36a7 misc.js:155 [Lit-JS-SDK v3.0.5] authSigOrError: {type: 'SUCCESS', result: '{"sig":"0x6dce6e5b23b1a4c6639130ceb761a647df2e7c3e…ss":"0xe60930dd528485ba57f4a17b02209877c2a9bfac"}'} misc.js:155 [Lit-JS-SDK v3.0.5] chainId from web3 {type: 'SUCCESS', result: 11155111} misc.js:155 [Lit-JS-SDK v3.0.5] checkAndSignAuthMessage with chainId [object Object] and chain set to sepolia and selectedChain is {contractAddress: null, chainId: 11155111, name: 'Sepolia Testnet', symbol: 'ETH', decimals: 18, …} misc.js:155 [Lit-JS-SDK v3.0.5] checking if sig is in local storage misc.js:155 [Lit-JS-SDK v3.0.5] 6. authSig: {sig: '0x6dce6e5b23b1a4c6639130ceb761a647df2e7c3e26b9ce0a…c16dd54655859afa3b28618f2e3dfe49e6b8fee6d533ef01c', derivedVia: 'web3.eth.personal.sign', signedMessage: 'localhost:3000 wants you to sign in with your Ethe…05.081Z\nExpiration Time: 2024-04-16T21:33:05.056Z', address: '0xe60930dd528485ba57f4a17b02209877c2a9bfac'} misc.js:155 [Lit-JS-SDK v3.0.5] signing auth message because account is not the same as the address in the auth sig misc.js:155 [Lit-JS-SDK v3.0.5] pausing... misc.js:155 [Lit-JS-SDK v3.0.5] signing with 0x8a1fb49cB17ab6D1BF2CaC34E1F06451C8205605 misc.js:155 [Lit-JS-SDK v3.0.5] Signing with personal_sign misc.js:155 [Lit-JS-SDK v3.0.5] Signature: 0xa50d552559971c79d41c7a52b5c4f6ca25ea441029f2893e0f2f62041e350b1444a800505980d837e33345d831a96ec0759591e601123ef32c44b810da7c99511c misc.js:155 [Lit-JS-SDK v3.0.5] recovered address: 0x8a1fb49cb17ab6d1bf2cac34e1f06451c8205605 misc.js:155 [Lit-JS-SDK v3.0.5] generated and saved lit-comms-keypair misc.js:155 [Lit-JS-SDK v3.0.5] 7. authSig: {sig: '0xa50d552559971c79d41c7a52b5c4f6ca25ea441029f2893e…33345d831a96ec0759591e601123ef32c44b810da7c99511c', derivedVia: 'web3.eth.personal.sign', signedMessage: 'localhost:3000 wants you to sign in with your Ethe…20.185Z\nExpiration Time: 2024-04-17T13:05:20.159Z', address: '0x8a1fb49cb17ab6d1bf2cac34e1f06451c8205605'} lit.ts:70 [Lit-JS-SDK v3.0.5] checkIfAuthSigRequiresChainParam lit.ts:70 [Lit-JS-SDK v3.0.5] checkIfAuthSigRequiresChainParam lit.ts:70 [Lit-JS-SDK v3.0.5] Hashing access control conditions: [{"contractAddress":"0x8ac38927a379804823728f17633f27c1945a0695","chain":"sepolia","standardContractType":"","method":"balanceOf","parameters":[":userAddress"],"returnValueTest":{"comparator":">","value":"0"}}] misc.js:155 [Lit-JS-SDK v3.0.5] formattedAccessControlConditions [{"contractAddress":"0x8ac38927a379804823728f17633f27c1945a0695","chain":"sepolia","standardContractType":"","method":"balanceOf","parameters":[":userAddress"],"returnValueTest":{"comparator":">","value":"0"}}] misc.js:155 [Lit-JS-SDK v3.0.5] identityParam lit-accesscontrolcondition://222f3c4f55a7128bf88ce9223366afcf6e0804f2201f65c98563c865216d03a1/e0a4e7d4dddd90f3c9ba5c2a1a6c955538dd93cd80d3692756b631bc5d84734c misc.js:155 [Lit-JS-SDK v3.0.5] getSigningShareForDecryption misc.js:155 [Lit-JS-SDK v3.0.5] sendCommandToNode with url https://cayenne.litgateway.com:7371/web/encryption/sign and data {accessControlConditions: Array(1), evmContractConditions: undefined, solRpcConditions: undefined, unifiedAccessControlConditions: undefined, dataToEncryptHash: 'e0a4e7d4dddd90f3c9ba5c2a1a6c955538dd93cd80d3692756b631bc5d84734c', …}accessControlConditions: [{…}]authSig: {sig: '0xa50d552559971c79d41c7a52b5c4f6ca25ea441029f2893e…33345d831a96ec0759591e601123ef32c44b810da7c99511c', derivedVia: 'web3.eth.personal.sign', signedMessage: 'localhost:3000 wants you to sign in with your Ethe…20.185Z\nExpiration Time: 2024-04-17T13:05:20.159Z', address: '0x8a1fb49cb17ab6d1bf2cac34e1f06451c8205605'}chain: "ethereum"dataToEncryptHash: "e0a4e7d4dddd90f3c9ba5c2a1a6c955538dd93cd80d3692756b631bc5d84734c"evmContractConditions: undefinedsolRpcConditions: undefinedunifiedAccessControlConditions: undefined[[Prototype]]: Object misc.js:155 [Lit-JS-SDK v3.0.5] getSigningShareForDecryption misc.js:155 [Lit-JS-SDK v3.0.5] sendCommandToNode with url https://cayenne.litgateway.com:7370/web/encryption/sign and data {accessControlConditions: Array(1), evmContractConditions: undefined, solRpcConditions: undefined, unifiedAccessControlConditions: undefined, dataToEncryptHash: 'e0a4e7d4dddd90f3c9ba5c2a1a6c955538dd93cd80d3692756b631bc5d84734c', …} misc.js:155 [Lit-JS-SDK v3.0.5] getSigningShareForDecryption misc.js:155 [Lit-JS-SDK v3.0.5] sendCommandToNode with url https://cayenne.litgateway.com:7372/web/encryption/sign and data {accessControlConditions: Array(1), evmContractConditions: undefined, solRpcConditions: undefined, unifiedAccessControlConditions: undefined, dataToEncryptHash: 'e0a4e7d4dddd90f3c9ba5c2a1a6c955538dd93cd80d3692756b631bc5d84734c', …}accessControlConditions: [{…}]authSig: {sig: '0xa50d552559971c79d41c7a52b5c4f6ca25ea441029f2893e…33345d831a96ec0759591e601123ef32c44b810da7c99511c', derivedVia: 'web3.eth.personal.sign', signedMessage: 'localhost:3000 wants you to sign in with your Ethe…20.185Z\nExpiration Time: 2024-04-17T13:05:20.159Z', address: '0x8a1fb49cb17ab6d1bf2cac34e1f06451c8205605'}chain: "ethereum"dataToEncryptHash: "e0a4e7d4dddd90f3c9ba5c2a1a6c955538dd93cd80d3692756b631bc5d84734c"evmContractConditions: undefinedsolRpcConditions: undefinedunifiedAccessControlConditions: undefined[[Prototype]]: Object lit.ts:70

   POST https://cayenne.litgateway.com:7371/web/encryption/sign 401 (Unauthorized)

LitCore.sendCommandToNode @ lit-core.js:180 LitNodeClientNodeJs.getSigningShareForDecryption @ lit-node-client-nodejs.js:418 eval @ lit-node-client-nodejs.js:1203 LitCore.getNodePromises @ lit-core.js:206 LitNodeClientNodeJs.decrypt @ lit-node-client-nodejs.js:1200 await in LitNodeClientNodeJs.decrypt (async) decryptToString @ encryption.js:207 decryptWithLit @ lit.ts:70 await in decryptWithLit (async) handleDecrypt @ messagesDAOBox.tsx:21 onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show 20 more frames Show less lit.ts:70 Something went wrong, internal id for request: lit_80276a6930a97. Please provide this identifier with any support requests. Error is The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions - The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions window.console.error @ app-index.js:35 console.error @ hydration-error-info.js:41 eval @ lit-core.js:191 Promise.catch (async) LitCore.sendCommandToNode @ lit-core.js:190 LitNodeClientNodeJs.getSigningShareForDecryption @ lit-node-client-nodejs.js:418 eval @ lit-node-client-nodejs.js:1203 LitCore.getNodePromises @ lit-core.js:206 LitNodeClientNodeJs.decrypt @ lit-node-client-nodejs.js:1200 await in LitNodeClientNodeJs.decrypt (async) decryptToString @ encryption.js:207 decryptWithLit @ lit.ts:70 await in decryptWithLit (async) handleDecrypt @ messagesDAOBox.tsx:21 onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show 23 more frames Show less lit.ts:70

   POST https://cayenne.litgateway.com:7370/web/encryption/sign 401 (Unauthorized)

LitCore.sendCommandToNode @ lit-core.js:180 LitNodeClientNodeJs.getSigningShareForDecryption @ lit-node-client-nodejs.js:418 eval @ lit-node-client-nodejs.js:1203 LitCore.getNodePromises @ lit-core.js:206 LitNodeClientNodeJs.decrypt @ lit-node-client-nodejs.js:1200 await in LitNodeClientNodeJs.decrypt (async) decryptToString @ encryption.js:207 decryptWithLit @ lit.ts:70 await in decryptWithLit (async) handleDecrypt @ messagesDAOBox.tsx:21 onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show 20 more frames Show less lit.ts:70 Something went wrong, internal id for request: lit_80276a6930a97. Please provide this identifier with any support requests. Error is The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions - The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions window.console.error @ app-index.js:35 console.error @ hydration-error-info.js:41 eval @ lit-core.js:191 Promise.catch (async) LitCore.sendCommandToNode @ lit-core.js:190 LitNodeClientNodeJs.getSigningShareForDecryption @ lit-node-client-nodejs.js:418 eval @ lit-node-client-nodejs.js:1203 LitCore.getNodePromises @ lit-core.js:206 LitNodeClientNodeJs.decrypt @ lit-node-client-nodejs.js:1200 await in LitNodeClientNodeJs.decrypt (async) decryptToString @ encryption.js:207 decryptWithLit @ lit.ts:70 await in decryptWithLit (async) handleDecrypt @ messagesDAOBox.tsx:21 onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show 23 more frames Show less lit.ts:70

POST https://cayenne.litgateway.com:7372/web/encryption/sign 401 (Unauthorized) LitCore.sendCommandToNode @ lit-core.js:180 LitNodeClientNodeJs.getSigningShareForDecryption @ lit-node-client-nodejs.js:418 eval @ lit-node-client-nodejs.js:1203 LitCore.getNodePromises @ lit-core.js:206 LitNodeClientNodeJs.decrypt @ lit-node-client-nodejs.js:1200 await in LitNodeClientNodeJs.decrypt (async) decryptToString @ encryption.js:207 decryptWithLit @ lit.ts:70 await in decryptWithLit (async) handleDecrypt @ messagesDAOBox.tsx:21 onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show 20 more frames Show less lit.ts:70 Something went wrong, internal id for request: lit_80276a6930a97. Please provide this identifier with any support requests. Error is The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions - The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions window.console.error @ app-index.js:35 console.error @ hydration-error-info.js:41 eval @ lit-core.js:191 Promise.catch (async) LitCore.sendCommandToNode @ lit-core.js:190 LitNodeClientNodeJs.getSigningShareForDecryption @ lit-node-client-nodejs.js:418 eval @ lit-node-client-nodejs.js:1203 LitCore.getNodePromises @ lit-core.js:206 LitNodeClientNodeJs.decrypt @ lit-node-client-nodejs.js:1200 await in LitNodeClientNodeJs.decrypt (async) decryptToString @ encryption.js:207 decryptWithLit @ lit.ts:70 await in decryptWithLit (async) handleDecrypt @ messagesDAOBox.tsx:21 onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show 23 more frames Show less misc.js:155 [Lit-JS-SDK v3.0.5] most common error: {"errorKind":"Validation","errorCode":"NodeAccessControlConditionsReturnedNotAuthorized","status":401,"message":"The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions","correlationId":"lit_80276a6930a97","details":["The access control condition check returned that you are not permitted to access this content. Are you sure you meet the conditions? Check the auth_sig and the other conditions"]} messagesDAOBox.tsx:31 Uncaught (in promise) errConstructorFunc {message: 'The access control condition check returned that y…ons? Check the auth_sig and the other conditions', errorCode: 'NodeAccessControlConditionsReturnedNotAuthorized', errorKind: 'Validation', status: 401, details: Array(1)} handleDecrypt @ messagesDAOBox.tsx:31 await in handleDecrypt (async) onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show 14 more frames Show less

Severity of the bug

I wanna use lit-protocol to encrypt data related to different projects stored on ceramic network . I can work on something else while figuring out the bug...

Steps To Reproduce

I am using nextjs14 for the app.

I share lit client in a context provider:

console.log("Starting Lit Client..."); const litClient = new LitJsSdk.LitNodeClient({ //litNetwork: "cayenne", url: window.location.origin, }); litClient.connect(); setLit(litClient);

[...]

<CeramicContext.Provider value={{ ceramic, composeClient, isAuth, setAuth, accountId, setAccountId, didsession, setDidsession, lit, }}

{children} </CeramicContext.Provider> );

Then I consume the context in a component for encrypting a message:

const processForm: SubmitHandler = async (data) => { //setMessage(data.message); if (lit && data.message && data.message.length > 0) { const tokenDetails = await tokenVotingClient.methods.getToken( selectedProject.aragonDaoTokenVotingPluginAddress ); const tokenAddress = tokenDetails?.address ?? ""; console.log("tokenAddress in messageDAOModal:", tokenAddress); // TODO here must give conditions to be a member of the selectedProject DAO const accessControlConditions = [ { contractAddress: tokenAddress, standardContractType: "", chain, method: "balanceOf", parameters: [":userAddress"], returnValueTest: { comparator: ">", value: "0", }, }, ]; / const accessControlConditions = [ { contractAddress: "", standardContractType: "", chain, method: "", parameters: [":userAddress"], returnValueTest: { comparator: "=", value: account.address as string, }, }, ]; /

  const { ciphertext, dataToEncryptHash } = await encryptWithLit(
    lit,
    data.message,
    accessControlConditions,
    chain
  );

  console.log(ciphertext);

  const stringified = JSON.stringify(accessControlConditions);
  const b64 = new TextEncoder().encode(stringified);
  const encoded = await encodeb64(b64);

  const message: any = await composeClient.executeQuery<{
    createMessages: {
      document: MessageDAO;
    };
  }>(`
    mutation {
      createMessagesDAOs(input: {
        content: {
          body: """${dataToEncryptHash}"""
          to: "${selectedProject.aragonDaoSubENS}"
          created: "${new Date().toISOString()}"
          ciphertext: "${ciphertext}"
          chain: "${chain}"
          accessControlConditions: "${encoded}"
          accessControlConditionType: "accessControlConditions"
          profileId: "${profile.id}"
        }
      })
      {
        document {
          body
          to
          created
          ciphertext
          chain
          accessControlConditions
          profileId
        }
      }
    }
  `);

  console.log(message);
  setOpen(false);
}

};

And I use the lit client in another component to decrypt the message:

const handleDecrypt = async (event: any, message: MessageDAO) => { const encryptedMessage = message.body; const ciphertext = message.ciphertext; const accessControl = decodeb64(message.accessControlConditions); const decoded = new TextDecoder().decode(accessControl); if (lit) { const decodedMessage = await decryptWithLit( lit, ciphertext, encryptedMessage, JSON.parse(decoded), message.chain ); event.target.parentElement.children[1].innerText = decodedMessage; event.target.innerText = "Decoded!"; } };

Link to code

No response

Anything else?

No response

Aaryan-R-S commented 6 months ago

Hey @brunolune!
I just checked that I'm able to encrypt and decrypt content on sepolia and baseSepolia with these access control conditions:

        const client = new LitJsSdk.LitNodeClient({
            litNetwork: "cayenne", 
            debug: true,
        });

        const chain = "sepolia"; // baseSepolia

        const accessControlConditions = [
            {
              contractAddress: "",
              standardContractType: "",
              chain,
              method: "eth_getBalance",
              parameters: [":userAddress", "latest"],

              returnValueTest: {
                comparator: ">=",
                value: "000000000000", // 0.000001 ETH
              },
            },
        ];

Can you try upgrading SDK to latest version 4.2.1? Also try debugging at your end.
If issue still persists, can you share your code via GitHub?

You can refer this code for the reference - https://github.com/Aaryan-R-S/LIT-Protocol-demo-reactjs/blob/master/src/components/EncryptAuthSig.jsx

brunolune commented 6 months ago

Hello!

Thanks for the reply. I upgraded to version 4.2.1. However, I still got the error when I used an accessControlCondition based on my ERC20 token, not the ETH balance of the user. It works if I use your conditions:

const accessControlConditions = [ { contractAddress: "", standardContractType: "", chain, method: "eth_getBalance", parameters: [":userAddress", "latest"],

          returnValueTest: {
            comparator: ">=",
            value: "000000000000", // 0.000001 ETH
          },
        },
    ];

But It doesn't work if I use mine:

const accessControlConditions = [ { contractAddress: tokenAddress, standardContractType: "", chain, method: "balanceOf", parameters: [":userAddress"], returnValueTest: { comparator: ">", value: "0", }, }, ];

The tokenAddress for instance is 0x8ac38927a379804823728f17633f27c1945a0695 on sepolia.

I got the following error using this last condition:

lit.ts:70 POST https://cayenne.litgateway.com:7371/web/encryption/sign 401 (Unauthorized) sendRequest @ misc.js:568 LitCore.sendCommandToNode @ lit-core.js:598 LitNodeClientNodeJs.getSigningShareForDecryption @ lit-node-client-nodejs.js:591 eval @ lit-node-client-nodejs.js:1516 LitCore.getNodePromises @ lit-core.js:613 wrapper @ lit-node-client-nodejs.js:1513 executeWithRetry @ misc.js:610 await in executeWithRetry (async)
LitNodeClientNodeJs.decrypt @ lit-node-client-nodejs.js:1530 await in LitNodeClientNodeJs.decrypt (async)
decryptToString @ encryption.js:200 decryptWithLit @ lit.ts:70 await in decryptWithLit (async)
handleDecrypt @ messagesDAOBox.tsx:21 onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show less messagesDAOBox.tsx:31 Uncaught (in promise) errConstructorFunc {message: 'The access control condition check returned that y…ons? Check the auth_sig and the other conditions', errorCode: 'NodeAccessControlConditionsReturnedNotAuthorized', errorKind: 'Validation', status: 401, details: Array(1), …} handleDecrypt @ messagesDAOBox.tsx:31 await in handleDecrypt (async)
onClick @ messagesDAOBox.tsx:143 callCallback @ react-dom.development.js:17629 invokeGuardedCallbackImpl @ react-dom.development.js:17667 invokeGuardedCallback @ react-dom.development.js:17729 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:17741 executeDispatch @ react-dom.development.js:27186 processDispatchQueueItemsInOrder @ react-dom.development.js:27206 processDispatchQueue @ react-dom.development.js:27215 dispatchEventsForPlugins @ react-dom.development.js:27223 eval @ react-dom.development.js:27378 batchedUpdates$1 @ react-dom.development.js:21180 batchedUpdates @ react-dom.development.js:24349 dispatchEventForPluginEventSystem @ react-dom.development.js:27377 dispatchEvent @ react-dom.development.js:25416 dispatchDiscreteEvent @ react-dom.development.js:25392 Show less

Aaryan-R-S commented 6 months ago

I see, you are not setting standardContractType field to ERC20.

Use this ACC and it will work:

        const client = new LitJsSdk.LitNodeClient({
            litNetwork: "cayenne", 
            debug: true,
        });

        const chain = "sepolia";

        const accessControlConditions = [
            {
              contractAddress: "0x8ac38927a379804823728f17633f27c1945a0695",
              standardContractType: "ERC20",
              chain,
              method: "balanceOf",
              parameters: [":userAddress", "latest"],

              returnValueTest: {
                comparator: ">=",
                value: "000000000000", // 0.000001 ETH
              },
            },
        ];
brunolune commented 6 months ago

Okay indeed great, I thought it was optional, thank you!

brunolune commented 6 months ago

Okay indeed, it works with standardContractType: "ERC20", I thought it was optional, thank you! One question: what does "latest" mean in parameters? and also why using multiple zeros in the value field? Another point: I got many types errors after upgrading to 4.2.1 for "@lit-protocol/lit-node-client", "@lit-protocol/lit-node-client-nodejs", "@lit-protocol/types".

zach-is-my-name commented 6 months ago

Would love documentation on the "magic" params also!

Aaryan-R-S commented 6 months ago

Hey @zach-is-my-name where exactly you saw that 'magic' keyword? Can you share link?

Aaryan-R-S commented 6 months ago

Hey @brunolune!

  1. Will get back to you
  2. You can use single zero also
  3. These types errors will be fixed in upcoming releases. Wanna share some of them in form of SS?
zach-is-my-name commented 6 months ago

Hey @zach-is-my-name where exactly you saw that 'magic' keyword? Can you share link?

Hi Aaryan! yes! Sorry I mistook bruno's question about the "latest" param for a question about the ":userAddress" param, which while perhaps not "magical" is apparently "special" lol. https://github.com/LIT-Protocol/Node/blob/a4da3bff9fef4e8b0eea15604c7e26d0e8a45a5b/rust/lit-node/src/access_control/mod.rs#L1190

I think there's a few others besides ':userAddress'. Just discovered it's only documented in the Solana and Cosmos sections, which is why I originally missed it. https://github.com/search?q=repo%3ALIT-Protocol%2Fdocs+%22The+parameter+of%22&type=code

Aaryan-R-S commented 6 months ago

Hey @brunolune!
The parameter "latest" refers to the block identifier the balance for the account is retrieved at.
Oh I see. No issues @zach-is-my-name!

zach-is-my-name commented 6 months ago

I'll submit a PR to docs so that Ethereum users see this as well "The parameter of ":userAddress" will be automatically substituted with the user's wallet address which was verified by checking the message signed by their wallet."

brunolune commented 6 months ago

Lit-protocol types issues found with 4.2.1:

1) Type error encountered in :

let authSig = await checkAndSignAuthMessage({ chain, });

Before only chain was required now nonce is also required? What value to put? from js-sdk/packages/types/src/lib/interfaces.ts :

// The blockhash that the nodes return during the handshake
nonce: string;

What is the blockhash that the nodes return during the handshake?

When encrypting, It seems to work with :

 let authSig = await checkAndSignAuthMessage({
    chain,
    nonce: aStringThatYouWishToEncrypt,
  });

When decrypting it seems to work with:

  let authSig = await checkAndSignAuthMessage({
    chain,
    nonce: dataToEncryptHash,
  });

2) type error on accessControlConditions:

"... Type '{ contractAddress: string; standardContractType: string; chain: string; method: string; parameters: string[]; returnValueTest: { comparator: string; value: string; }; }' is not assignable to type 'AccessControlConditions | LPACC_EVM_BASIC | AccsOperatorParams'. Type '{ contractAddress: string; standardContractType: string; chain: string; method: string; parameters: string[]; returnValueTest: { comparator: string; value: string; }; }' is not assignable to type 'LPACC_EVM_BASIC'. Types of property 'chain' are incompatible. Type 'string' is not assignable to type '"sepolia" | "ethereum" | "polygon" | "fantom" | "xdai" | "bsc" | "arbitrum" | "avalanche" | "fuji" | "harmony" | "mumbai" | "goerli" | "cronos" | "optimism" | "celo" | "aurora" | ... 33 more ... | "verifyTestnet"'.ts(2345)..."

encountered in :

const { ciphertext, dataToEncryptHash } = await encryptWithLit(
    lit,
    data.message,
    //@ts-ignore
    accessControlConditions,
    "sepolia"
      );

even though I used "sepolia" as chain ...:

const accessControlConditions = [
    {
      contractAddress: tokenAddress,
      standardContractType: "ERC20",
      chain: "sepolia",
      method: "balanceOf",
      parameters: [":userAddress", "latest"],
      returnValueTest: {
        comparator: ">",
        value: "0",
      },
    },
      ];

3) Type error with LitNodeClient encountered in:

console.log("Starting Lit Client...");
    const litClient = new LitJsSdk.LitNodeClient({
      //litNetwork: "cayenne",
      url: window.location.origin,
    });
    litClient.connect();
    setLit(litClient);

Error: "Argument of type 'LitNodeClient' is not assignable to parameter of type 'SetStateAction<ILitNodeClient | undefined>'. Type 'LitNodeClient' is not assignable to type 'ILitNodeClient'. Types of property 'handleNodePromises' are incompatible. Type '(nodePromises: Promise[], requestId: string, minNodeCount: number) => Promise<SuccessNodePromises | RejectedNodePromises>' is not assignable to type '(nodePromises: Promise[]) => Promise<RejectedNodePromises | SuccessNodePromises>'. Target signature provides too few arguments. Expected 3 or more, but got 1."

solved with:

const litClient = new LitJsSdk.LitNodeClient({
      //litNetwork: "cayenne",
      url: window.location.origin,
    });
    litClient.connect();
    setLit(litClient as unknown as ILitNodeClient);
Aaryan-R-S commented 6 months ago

Thanks @brunolune! We have addressed this here as mentioned by @MaximusHaximus !

Aaryan-R-S commented 6 months ago

Hey @brunolune! Apologies I missed above two type errors.

For Type Error 1 use:

const nonce = await litNodeClient.getLatestBlockhash();

For Type Error 2: I checked it. I'm not able to reproduce this error. Wanna share your code via GitHub?

For Type Error 3, it has been fixed in this PR

brunolune commented 6 months ago

Thanks version 5.0.0 works for me! It also solved some issues I got with 4.2.1 when deploying my app on Vercel.