Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/lit 3017 auth unification migrate actual tests #440

Conversation

Ansonhkg
Copy link
Collaborator

@Ansonhkg Ansonhkg commented Apr 24, 2024

Description

This PR merges several other PRs #439 #438 #436, so we can run the tests as they rely on the new features introduced in those branches.

Please check this directory for all the tests

Changes

  • Introduced a helper function for composing an access control resource string. Previously, we only required dataToHash, but it turns out that the string of the hashed access control string must be prepended before it. See 72bcd8d.
  • Better types on Node response fe71ddf
  • Unfortunately node-fetch is needed when running against local tests for some reasons. The package is added a dev dependency so won't affect production. It's only being used in this test. 757d588

Also want to note that we should write scenario in the test/JsDocs for more complex operations, see example

/**
* ## Scenario:
* Delegating capacity credits NFT to Bob (delegatee) for him to execute JS code to sign with his PKP
* - Given: The capacity credits NFT is minted by the dApp owner
* - When: The dApp owner creates a capacity delegation authSig
* - And: The dApp owner delegates the capacity credits NFT to Bob
* - Then: The delegated (Bob's) wallet can execute JS code to sign with his PKP using the capacity from the capacity credits NFT
*
*
* ## Test Commands:
* - ❌ Not supported in Cayenne, but session sigs would still work
* - ✅ NETWORK=manzano yarn test:local --filter=testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs
* - ✅ NETWORK=localchain yarn test:local --filter=testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs
*/

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

 NETWORK=localchain DEBUG=true yarn test:local         
image

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Ansonhkg Ansonhkg self-assigned this Apr 24, 2024
@Ansonhkg Ansonhkg marked this pull request as ready for review April 24, 2024 15:34
@Ansonhkg Ansonhkg changed the base branch from master to feature/lit-2958-auth-unification-ts-tests April 24, 2024 15:38
@Ansonhkg Ansonhkg requested a review from spacesailor24 April 24, 2024 15:40
@DashKash54
Copy link
Collaborator

This PR merges several other PRs #439 #438 #436, so we can run the tests as they rely on the new features introduced in those branches.

Is it juts a merged PR? So what's to review here? @Ansonhkg

@Ansonhkg
Copy link
Collaborator Author

Ansonhkg commented Apr 25, 2024

This PR merges several other PRs #439 #438 #436, so we can run the tests as they rely on the new features introduced in those branches.

Is it juts a merged PR? So what's to review here? @Ansonhkg

The tests & the helper function

Copy link
Collaborator

@glitch003 glitch003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crazy - so many tests! thx for your work here @Ansonhkg

Copy link
Collaborator

@DashKash54 DashKash54 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these tests have been tested against the Auth Uni node PR by spinning up the local nodes? Have they also been tested on Manzano?
Can we add some tests for that fail due to the PKP SessionSigs not having enough resource permissions?
So to summarize this PR tests all the functionality with eoaSessionSigs, pkpSessionSigs & litActionSessionSigs?

local-tests/test.ts Outdated Show resolved Hide resolved
ability: LitAbility.LitActionExecution,
},
],
capabilityAuthSigs: [capacityDelegationAuthSig],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way of knowing whether the Capacity credit was used? It's enforced on Manzano & Habanero but I think you're these tests against local nodes where capacity credits aren't required?

Copy link
Collaborator

@DashKash54 DashKash54 May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're testing it against only the local nodes since Manzano won't have these changes? But local nodes don't enforce capacity credits so we aren't really testing this? @Ansonhkg


const regex = /urn:recap:[\w+\/=]+/g;

const recaps = bobsSingleSessionSig.signedMessage.match(regex) || [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will EOA sessionSigs always contain Lit Action/PKP Sign resources?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, if you don't provide them. It's just a helper function within the test environment so won't be used in the sdk

Copy link
Collaborator

@DashKash54 DashKash54 May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I didn't get it. In the actual SDK does the EOA sessionSig by default have these resources? I think it's enforced by the nodes? @Ansonhkg

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, in the actual SDK we don't have set resources by default.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it different from testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs?
What do you mean by unspecified capacity token? In case of it being specified where exactly is it specified?

Copy link
Collaborator Author

@Ansonhkg Ansonhkg Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unspecified capacity token - meaning you are having the capacityTokenId field omitted in the SDK, which also mean that you are having the nft_id omitted from the node side, which means that there's no nft_id to scope into, aka. the function does not limit the scope of the query to specific NFT IDs, meaning it assumes that all NFTs owned by the user (as determined by their address) are eligible.

Copy link
Collaborator

@DashKash54 DashKash54 May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure that we're on the same page, can you please explain what capacityTokenId & nft_id are used for. An example would help @Ansonhkg

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capacityTokenId is the sdk param, and nft_id is the node param


const appOwnersCapacityDelegationAuthSig = (
await devEnv.litNodeClient.createCapacityDelegationAuthSig({
dAppOwnerWallet: alice.wallet,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have multiple ways to create a delegationAuthSig? Wouldn't this confuse the users? Why is providing dAppOwnerWallet when you can simply create the authSig with the wallet itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not have multiple ways to create it, those you saw are helper functions within the test.

re: dAppOwnerWallet you can simply create the authSig yourself

yes, you technically can, but this function has an explicit behaviour that matches user's intention when they call it, whereas "simply create the authSig yourself" is implicit, you can use it if you know what you're doing.

Copy link
Collaborator

@DashKash54 DashKash54 May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is only for testing? The SDK only provides a one way to do so? @Ansonhkg

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the SDK now provides 3 ways using the as outlined in this PR #436
a generic one with implicit behaviour, and 2 with explicit behaviours

Copy link
Collaborator

@DashKash54 DashKash54 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few more imp comments

Comment on lines 32 to 33
Lit.Actions.claimKey({keyId: "foo"});
Lit.Actions.claimKey({keyId: "bar"});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a step required before claiming a PKP? Someone has to make it claimable right or can anyone claim any PKP? @joshLong145

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DashKash54 the keyId is postfixed with the ipfs id so it makes the claim unique to the Lit Action. So you are only claim in context to the lit action as the app id

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I thought the app had to do something before for making the PKP claimable. Turns out your just need to provide the keyId? @joshLong145

packages/auth-helpers/src/lib/resources.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ansonhkg Can you please double check all you interfaces against the node counter parts eg: https://github.com/LIT-Protocol/lit-assets/blob/aff82c4381139476aeaa6faa814069b184d38d39/rust/lit-node/src/models/mod.rs#L177
Note, some params are still accepted in the nodes for backwards compatible reasons but they don't need to be present in the SDK as we're not making the SDK backwards compatible with the older node versions
For instance, we don't allow passing an AuthSig for signSessionKey: https://github.com/LIT-Protocol/lit-assets/blob/aff82c4381139476aeaa6faa814069b184d38d39/rust/lit-node/src/endpoints/versions/v1.rs#L59
There are bunch of other restrictions for the v1 endpoint in the above node file. We should make the SDK interfaces compatible with those restriction as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ansonhkg this comment is remaining

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea has been addressed in one of the comments below, will double check again here #435

packages/types/src/lib/interfaces.ts Outdated Show resolved Hide resolved
packages/types/src/lib/interfaces.ts Outdated Show resolved Hide resolved
packages/types/src/lib/interfaces.ts Outdated Show resolved Hide resolved
packages/types/src/lib/interfaces.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@DashKash54 DashKash54 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some more comments

statement,
} = params;
// Useful log for debugging
if (!params.delegateeAddresses || params.delegateeAddresses.length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making passing delegateeAddresses mandatory & when provided empty array that means anyone can use it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think @Ansonhkg?

Copy link
Collaborator Author

@Ansonhkg Ansonhkg May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing an empty array means no one can use it though, I think we should not allow an empty array instead. btw the log message has been updated in another PR that's merged to the staging. Noting it here #435

@Ansonhkg Ansonhkg requested a review from DashKash54 April 30, 2024 15:38
Comment on lines 248 to 249
* FIXME: We should create a separate interface for JsExecutionRequestBody
* a body that the SDK accepts, and another one the node actually accepts.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we have a single interface?

statement: authCallbackParams.statement,
sessionKey: params.sessionSigsParams.sessionKey,
authSpecificData = {
authSig: JSON.parse(params.authMethod.accessToken),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SignSessionKey no longer accepts AuthSig

@DashKash54
Copy link
Collaborator

DashKash54 commented May 1, 2024

Responded to your comments & left a couple new comments. After these are addresses this is good to merge 😄 @Ansonhkg

Copy link
Collaborator

@DashKash54 DashKash54 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the PRs though there are still some unresolved comments which aren't addressed. Please address those and resolve. Great job @Ansonhkg 🚀

@Ansonhkg Ansonhkg merged commit abd27c2 into feature/lit-2958-auth-unification-ts-tests May 1, 2024
2 checks passed
@Ansonhkg Ansonhkg deleted the feature/lit-3017-auth-unification-migrate-actual-tests branch May 1, 2024 16:11
@joshLong145 joshLong145 mentioned this pull request May 13, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants