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

implement PEX #52

Open
mistermoe opened this issue Mar 22, 2024 · 1 comment
Open

implement PEX #52

mistermoe opened this issue Mar 22, 2024 · 1 comment
Labels

Comments

@mistermoe
Copy link
Member

mistermoe commented Mar 22, 2024

other web5 sdks implementations end up being 6-7 nested loops for selectCredentials I think we can reduce this to worst case 2 nested loops (necessarily 2 because field.paths in an array):

two approaches come to mind:

Approach 1

type FieldToken struct {
  Token  string
  Paths  []string
}
  1. initialize a slice []FieldToken fieldTokens
  2. Initialize an empty json schema
  3. Iterate through constraints.fields. For each field:
  4. Generate a token (random string)
  5. for each path in field.paths:
    1. initialize a FieldToken fieldToken with token and path
    2. append fieldToken to fieldTokens
  6. if the field has a filter, add the filter as a property to the json schema. Use token as the property name

We’re now done constructing VC Selector. Time to build selection candidates:

  1. Initialize a map[string]any selectionCandidate
  2. Initialize a map[string]bool tokensFound
  3. Initialize a map[string]bool tokens
  4. Iterate through fieldTokens:
  5. check if field.token is in tokens. if it is not, add it.
  6. check if field.token is in tokensFound. If it not:
    1. search for field.path within decoded vcJwt. If the path is found:
      1. Add the value to selectionCandidate with field.token as the key
      2. Add field.token to tokensFound
  7. check if len(tokens) == len(tokensFound). if it is not, the vcJwt does not fulfill the constraints. bail
  8. validate the selectionCandidate against the json schema. if it is not valid, the vcJwt does not fulfill the constraints.

Approach 2

type FieldToken struct {
  Token string
  Paths []string
}
  1. initialize a map[string]FieldToken fieldTokens
  2. Initialize an empty json schema
  3. Iterate through constraints.fields. For each field:
  4. Generate a token (random string)
  5. add an entry: (token, field.paths) to fieldTokens
  6. if the field has a filter, add the filter as a property to the json schema. Use token as the property name

We’re now done constructing VC selector. Time to build selection candidates:

  1. Initialize a map[string]any selectionCandidate
  2. Iterate through fieldTokens, for each fieldToken:
  3. initialize value any
  4. Iterate through fieldToken.paths, for each path:
    1. search for path within decoded vcJwt. if it is found,
      1. set value to the value at that path
      2. break
  5. if value is empty, the vcJwt does not satisfy the constraints. bail (greedy bail)
  6. set selectionCandidate[fieldToken.Token] to value
  7. validate the selectionCandidate against the json schema. if it is not valid, the vcJwt does not fulfill the constraints.
@mistermoe mistermoe added the next label Apr 17, 2024
@mistermoe
Copy link
Member Author

also here's a cheeky way to use PD

{
  "constraints": {
    "fields": [{
      "paths": [".*"],
      "filter": /* the entire json schema for the VC */
    }]
  }
}

single field whose only path is equivalent to the entire object. then just use json schema 100% to validate whether the vcjwt satisfies the json schema provided 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant