diff --git a/.gitignore b/.gitignore index 192a6b1..f23495e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ yarn-error.log* .env.test.local .env.production.local .env +.env.backup # turbo .turbo diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index f2a3aed..38c0ac6 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/.yarn/versions/c1145127.yml b/.yarn/versions/c1145127.yml new file mode 100644 index 0000000..86f2b5e --- /dev/null +++ b/.yarn/versions/c1145127.yml @@ -0,0 +1,3 @@ +undecided: + - lit-privacy + - ts diff --git a/packages/lit-actions/lit-actions/proofOfMembership.js b/packages/lit-actions/lit-actions/proofOfMembership.js index b5c69b2..4b64298 100644 --- a/packages/lit-actions/lit-actions/proofOfMembership.js +++ b/packages/lit-actions/lit-actions/proofOfMembership.js @@ -19,21 +19,29 @@ export default `const generateProofOfIdentity = async () => { contractAddress: tokenAddress, standardContractType: tokenType, chain, - method: 'balanceOf', - parameters: [ - address - ], + method: "balanceOf", + parameters: [address], returnValueTest: { - comparator: '>', - value: '0' - } - } - ] + comparator: ">", + value: "0", + }, + }, + ]; // check lit conditions - const result = await LitActions.checkConditions({conditions, authSig, chain}); + const result = await LitActions.checkConditions({ + conditions, + authSig, + chain, + }); // return if balance is 0 - if(!result) { + if (!result) { console.log("Zero Balance. No Membership found."); + LitActions.setResponse({ + response: JSON.stringify({ + success: false, + data: { balance: 0 }, + }), + }); return; } // user has balance > 0 @@ -42,9 +50,11 @@ export default `const generateProofOfIdentity = async () => { 32 ); - const toSign = ethers.utils.keccak256(ethers.utils.hexlify( - ethers.utils.concat([identityProof, parsedBlockNumber, publicSignal]) - )); + const toSign = ethers.utils.keccak256( + ethers.utils.hexlify( + ethers.utils.concat([identityProof, parsedBlockNumber, publicSignal]) + ) + ); const sigShare = await LitActions.ethPersonalSignMessageEcdsa({ message: toSign, @@ -54,4 +64,4 @@ export default `const generateProofOfIdentity = async () => { }; generateProofOfIdentity(); -`; +` diff --git a/packages/lit-actions/test/proofOfMembership.test.js b/packages/lit-actions/test/proofOfMembership.test.js index b362495..e981ce5 100644 --- a/packages/lit-actions/test/proofOfMembership.test.js +++ b/packages/lit-actions/test/proofOfMembership.test.js @@ -71,6 +71,10 @@ describe("generateProofOfMembership", () => { MembershipFingerprint, PKP_Membership ); + console.log(proofOfMembershipOutput) + if(!proofOfMembershipOutput.response?.success && proofOfMembershipOutput.response?.data?.balance === 0){ + throw Error("No balance found."); + } if (proofOfMembershipOutput.signatures?.sig1 === undefined) { console.log("No signature was done because no membership found"); } diff --git a/packages/lit-privacy-sdk/package.json b/packages/lit-privacy-sdk/package.json index d98daff..947d34c 100644 --- a/packages/lit-privacy-sdk/package.json +++ b/packages/lit-privacy-sdk/package.json @@ -1,6 +1,6 @@ { "name": "lit-privacy-sdk", - "version": "1.0.2", + "version": "1.0.4", "description": "", "main": "./dist/index.js", "typings": "./dist/index.d.ts", diff --git a/packages/lit-privacy-sdk/src/LitPrivacy/LitPrivacy.ts b/packages/lit-privacy-sdk/src/LitPrivacy/LitPrivacy.ts index eae0b44..680c25b 100644 --- a/packages/lit-privacy-sdk/src/LitPrivacy/LitPrivacy.ts +++ b/packages/lit-privacy-sdk/src/LitPrivacy/LitPrivacy.ts @@ -137,13 +137,20 @@ export default class LitPrivacy extends LitPrivacyConstants { LitPrivacy.MEMBERSHIP_PROOF_SIGNER_PKP.PUBLIC_KEY, LitPrivacy.LIT_ACTIONS_CID.PROOF_OF_MEMBERSHIP ); + // check if no membership found + if ( + // @ts-ignore + !proofOfMembershipOutput.response?.success && // @ts-ignore + proofOfMembershipOutput.response?.data?.balance === 0 + ) { + console.log("No signature was done because no membership found"); + throw Error("No signature was done because no membership found."); + } // the returned output will have signature under `sig1` property // check if the user has correct membership or not by ensuring signature is generated if (proofOfMembershipOutput.signatures?.sig1 === undefined) { - console.log("No signature was done because no membership found"); - throw Error( - "Failed generating Proof of Membership. Either the wallet doesn't contain the token or check the parameters" - ); + console.log("Check parameters passed to LitAction"); + throw Error("Check parameters passed to LitAction."); } // this is the final membership proof generated from Lit Action @@ -218,13 +225,18 @@ export default class LitPrivacy extends LitPrivacyConstants { data: transactionData.data as string, }; - // Without a specific API key, the relay request will fail! - // Go to https://relay.gelato.network to get a testnet API key with 1Balance. - // Send a relay request using Gelato Relay! - const relayResponse = await relay.sponsoredCall(request, gelatoApiKey); - - console.log(relayResponse); - return relayResponse.taskId; + try { + // Without a specific API key, the relay request will fail! + // Go to https://relay.gelato.network to get a testnet API key with 1Balance. + // Send a relay request using Gelato Relay! + const relayResponse = await relay.sponsoredCall(request, gelatoApiKey); + console.log(relayResponse); + return relayResponse.taskId; + } catch (e) { + console.error("Realy call failed."); + console.error(e); + return -1; + } } async executeLitAction(fingerprint: any, PKP: string, litActionCid: string) { diff --git a/packages/lit-privacy-sdk/src/config/constants.ts b/packages/lit-privacy-sdk/src/config/constants.ts index bfd4914..f602533 100644 --- a/packages/lit-privacy-sdk/src/config/constants.ts +++ b/packages/lit-privacy-sdk/src/config/constants.ts @@ -1,5 +1,5 @@ export const PROOF_OF_IDENTITY_ACTION_CID: string= "QmTVqamJEKyprAG8DFuEuCnVQGitnWeQWu3ctRjYEVVAuS"; -export const PROOF_OF_MEMBERSHIP_ACTION_CID: string= "QmNVsvPnyHUKU8qSFRbxKuSCN1P3wRPBuYpgEFngNXuuHs"; +export const PROOF_OF_MEMBERSHIP_ACTION_CID: string= "Qmc4g16oXLPoYEAVi3t3UsCzTiH5JrEqsrW7hLYjvfwbBh"; export const IDENTITY_PROOF_SIGNER_PKP_PUBLIC_KEY: string= "0x04d45f2109cf7a1cfcd7519a87d0f405d1f5d55398ed9d80896944ca932581eff4a98a4d8059ebba3cc6d9f996744a33ba990144021b32355dc7c4ddb8a7d58eeb"; export const IDENTITY_PROOF_SIGNER_PKP_ADDRESS: string= "0x5846D64aA8de4eb9a0245D00f1963Db4FEE1e31F"; export const MEMBERSHIP_PROOF_SIGNER_PKP_PUBLIC_KEY: string= "0x04275b2c585bf9761bbba3997535116100b627a05dd86c434cbe4ab1ddc5917c33857b33cce39dccf30782b66892b07886547ebd6ef3888b82d47a7501ad11556b";