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

auth-helpers package with SessionCapabilityObject #88

Merged

Conversation

hwrdtm
Copy link
Contributor

@hwrdtm hwrdtm commented Apr 26, 2023

What

Closes LIT-247

Apologies for the big PR! If you want I can break it down into smaller chunks.

This PR:

  • Introduces a new auth-helpers package that contains an abstraction over various session capability object implementations - today, we will roll out with using a SIWE ReCap based implementation that implements ISessionCapabilityObject.
  • Introduce ILitResource which is an abstraction over any LIT-related logical resource, and LitAbility which is a specific action upon a LIT resource. For a user to make a request, they will couple them together as a LitResourceAbilityRequest - we check for compatibility on the SDK and Rust node side, so that you can't logically do a decryption ability over a Rate Limit Increase NFT resource.
  • Made lit-node-client-nodejs use stronger types and fix usages of session sigs here and there.
    • Store walletSig (auth sigs)
  • Integrate getSessionSigs to use auth-helpers session capability object generation / verification.
  • Allow passing optional statement to AuthCallbackParams

Examples:

Creating an ACC LIT resource and then requesting to perform the signing operation over it, by generating session sigs with the SDK, which the SDK will generate a session capability object with wildcard abilities for this specific ACC resource (*/*):

    const litResource = new LitAccessControlConditionResource(hashedResourceId);

    let sessionSigs = savedParams.litNodeClient.getSessionSigs({
      chain: 'ethereum',
      resourceAbilityRequests: [
        {
          resource: litResource,
          ability: LitAbility.AccessControlConditionSigning,
        },
      ],
    });

TODO

  • Test against Rust node validation logic (locally)
  • Use siwe-recap at 0.0.2-alpha.0
  • Update to use more descriptive resource prefixes

Testing

Manually tested from OAuth PKP repo, works as intended.

E2E:

  • yarn tools --dev --apps
  • yarn tools --test --e2e html

Packages:

  • npx nx run lit-node-client-nodejs:test
  • npx nx run auth-helpers:test

@hwrdtm hwrdtm self-assigned this Apr 26, 2023
@vercel
Copy link

vercel bot commented Apr 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
html-test-app-lit-js-sdk-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 6:43pm

Copy link
Contributor Author

@hwrdtm hwrdtm left a comment

Choose a reason for hiding this comment

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

Apologies for the big PR! If anyone wants I can break it down further.

/**
* These are the user-facing abilities that can be granted to a session.
*/
export enum LitAbility {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New concept that I'm introducing to SDK users.

LitAction = 'lit-la',
}

export interface ISessionCapabilityObject {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Abstraction over any concrete session capability object implementation.

addAllCapabilitiesForResource(litResource: ILitResource): void;
}

export interface ILitResource {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

abstraction over any LIT-related logical resource.

}

get statement(): string {
return sanitizeSiweMessage(this.#inner.statement);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed until spruceid/recap-ts#11 is done.

@@ -0,0 +1,32 @@
import { SiweMessage } from 'siwe';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file contains entry points to getting session capability objects, that are all currently implemented by Recap.

* @example If you want to request the ability to decrypt an access control condition, then you would pass
* [{ resource: new LitAccessControlConditionResource('someResource), ability: LitAbility.AccessControlConditionDecryption }]
*/
resourceAbilityRequests: LitResourceAbilityRequest[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

breaking change, but, as discussed we will proceed like so with heads up to users and that's it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to introduce LitResource and LitAbility to better separate those two concepts, rather than have everything be encoded into a single string and parsing in a way that is (IMO) less legible.

tsconfig.json Outdated Show resolved Hide resolved
packages/auth-helpers/src/lib/models.ts Show resolved Hide resolved
packages/auth-helpers/src/lib/models.ts Show resolved Hide resolved
}

static extract(siwe: SiweMessage): RecapSessionCapabilityObject {
const recap = Recap.extract_and_verify(siwe);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can verification fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea it can

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

@Ansonhkg Ansonhkg left a comment

Choose a reason for hiding this comment

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

lgtm! can we also update this repo readme with simple instructions on why and how to use it, example code etc.? also a changelog for the breaking change

Copy link
Collaborator

@Ansonhkg Ansonhkg left a comment

Choose a reason for hiding this comment

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

love it btw!

@hwrdtm
Copy link
Contributor Author

hwrdtm commented May 12, 2023

lgtm! can we also update this repo readme with simple instructions on why and how to use it, example code etc.? also a changelog for the breaking change

I can do changelog but I plan to update our website docs soon anyways, so I'll just do it there. I don't think the root README.md is the best place for it.

@hwrdtm
Copy link
Contributor Author

hwrdtm commented May 13, 2023

@Ansonhkg node side changes have been merged per https://github.com/LIT-Protocol/lit-assets/pull/149 and this PR is ready to go. Let's merge and publish this. Docs will come shortly after.

@hwrdtm hwrdtm force-pushed the feature/lit-247-sdk-make-sessionsigs-compliant-with-siwe branch from 458ef0f to e2f1137 Compare May 16, 2023 18:43
@Ansonhkg Ansonhkg merged commit 253c432 into master May 17, 2023
2 checks passed
@Ansonhkg
Copy link
Collaborator

@hwrdtm Published to latest 2.1.166

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.

None yet

4 participants