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

Rewrite Generating SessionSigs Guide #295

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

spacesailor24
Copy link
Contributor

@spacesailor24 spacesailor24 commented May 31, 2024

This PR rewrites the existing Generating SessionSigs guide, updating and fixing the code. This is the corresponding PR for the full implementation of the guide

Copy link

netlify bot commented May 31, 2024

Deploy Preview for lit-dev-docs failed.

Name Link
🔨 Latest commit 30c8e83
🔍 Latest deploy log https://app.netlify.com/sites/lit-dev-docs/deploys/665fdd0eee9eac000809f921

@alexvotofuture
Copy link
Contributor

This guide is so much more readable and well-documented, @spacesailor24!

Per the contribution checklist (on the other ticket linked here), please confirm that someone else at the company runs the code and gets the desired result bug-free.

Other than that, if everything @glitch003 mentioned on Slack is addressed, should be good to go.

import { LitAccessControlConditionResource } from "@lit-protocol/auth-helpers";
```

This resource specifies a Lit Access Control Conditions (ACC) the `ability` is being granted for. Specifying `"*"` grants the `ability` to any ACC, regardless of what the conditions are. To grant the `ability` for a specific ACC, you can specify the hashed key value of the ACC in place of `"*"` like so:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshLong145 @Ansonhkg How do I get the hashed key value of the ACC to give to LitAccessControlConditionResource when setting resourceAbilityRequests for a Session Sig?

Copy link
Contributor

Choose a reason for hiding this comment

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

in the LitAccessControlConditionResource class there's a public static method called generateResourceString which Composes a resource string by hashing access control conditions and appending a data hash.

So:

const accsResourceString =
  await LitAccessControlConditionResource.generateResourceString(
    accs,
    encryptRes.dataToEncryptHash
  );

const resourceAbilityRequests = [
{
        resource: new LitAccessControlConditionResource(accsResourceString),
        ability: LitAbility.AccessControlConditionDecryption,
}];

Comment on lines +270 to +271
<!-- TODO Is this correct? -->
- `AccessControlConditionSigning` This grants the ability to sign data using threshold signing by the Lit nodes in the network if the Access Control Conditions is satisfied.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshLong145 I'm not sure if this statement is correct

Copy link
Contributor

Choose a reason for hiding this comment

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

@DashKash54 @hwrdtm can you confirm this?

Choose a reason for hiding this comment

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

I think this was used for jwt features hence signing being referred to but we should get confirmation

# Generating SessionSigs
# Generating Session Signatures

[Session signatures](./intro.md) can be obtained using the [getSessionSigs](https://v5.api-docs.getlit.dev/classes/lit_node_client_src.LitNodeClientNodeJs.html#getSessionSigs) method provided by the Lit SDK. This method will generate a _session keypair_ for you locally, and will use the `authNeededCallback` method you specify to sign the session keypair, authorizing it to use the specified [Lit Resources and Abilities](./resources-and-abilities.md) on the Lit network.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to refer to the V6 doc? also we need to think how do we update them automatically in the future. eg. we can use a url shortener/self-host service that can redirect & track all the ref links, and update them all at once.

eg.
bit.ly/v5-doc -> https://v5-foo.getlit.dev

later when we want to update:
bit.ly/v5-doc -> https://v5-bar.getlit.dev

Suggested change
[Session signatures](./intro.md) can be obtained using the [getSessionSigs](https://v5.api-docs.getlit.dev/classes/lit_node_client_src.LitNodeClientNodeJs.html#getSessionSigs) method provided by the Lit SDK. This method will generate a _session keypair_ for you locally, and will use the `authNeededCallback` method you specify to sign the session keypair, authorizing it to use the specified [Lit Resources and Abilities](./resources-and-abilities.md) on the Lit network.
[Session signatures](./intro.md) can be obtained using the [getSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getSessionSigs) method provided by the Lit SDK. This method will generate a _session keypair_ for you locally, and will use the `authNeededCallback` method you specify to sign the session keypair, authorizing it to use the specified [Lit Resources and Abilities](./resources-and-abilities.md) on the Lit network.

Choose a reason for hiding this comment

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

yea we should do something like this. good idea @Ansonhkg

import { LitAccessControlConditionResource } from "@lit-protocol/auth-helpers";
```

This resource specifies a Lit Access Control Conditions (ACC) the `ability` is being granted for. Specifying `"*"` grants the `ability` to any ACC, regardless of what the conditions are. To grant the `ability` for a specific ACC, you can specify the hashed key value of the ACC in place of `"*"` like so:
Copy link
Contributor

Choose a reason for hiding this comment

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

in the LitAccessControlConditionResource class there's a public static method called generateResourceString which Composes a resource string by hashing access control conditions and appending a data hash.

So:

const accsResourceString =
  await LitAccessControlConditionResource.generateResourceString(
    accs,
    encryptRes.dataToEncryptHash
  );

const resourceAbilityRequests = [
{
        resource: new LitAccessControlConditionResource(accsResourceString),
        ability: LitAbility.AccessControlConditionDecryption,
}];

Comment on lines +270 to +271
<!-- TODO Is this correct? -->
- `AccessControlConditionSigning` This grants the ability to sign data using threshold signing by the Lit nodes in the network if the Access Control Conditions is satisfied.
Copy link
Contributor

Choose a reason for hiding this comment

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

@DashKash54 @hwrdtm can you confirm this?


## Instantiating an Ethers.js Wallet

Next we'll use our `ETHEREUM_PRIVATE_KEY` constant to instantiate an instance of `ethers.Wallet`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Next we'll use our `ETHEREUM_PRIVATE_KEY` constant to instantiate an instance of `ethers.Wallet`:
Next we'll use our `ETHEREUM_PRIVATE_KEY` constant to instantiate an instance of `ethers.Wallet`:
> **Note:** When working with Ethereum, you can use various blockchain clients or libraries (such as ethers.js, viem, etc.) to manage your private key and sign messages. As long as the chosen class or library has a `signMessage` function, it can be used effectively.

Comment on lines +26 to +28
- `"@lit-protocol/auth-helpers": "^6.0.0-beta.3"`
- `"@lit-protocol/constants": "^6.0.0-beta.3"`
- `"@lit-protocol/lit-node-client": "^6.0.0-beta.3"`

Choose a reason for hiding this comment

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

This is now beta.4 perhaps we use a script to update these package versions so we can run it once and update all docs pages to the latest package build.

Comment on lines +223 to +224
This resource specifies what Lit Programmable Key Pair (PKP) the `ability` is being granted for. Specifying `"*"` grants the `ability` for all PKPs. To grant the `ability` for a specific PKP, you can specify the token ID of the PKP in place of `"*"` like so:

Choose a reason for hiding this comment

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

Should we warn that * permissions are basically no permissions? Since we will allow any pkp to use it if configured like this?

@joshLong145
Copy link

@spacesailor24
Can we fix the build errors and merge this?

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