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

feat: HTTP to UCAN bridge #325

Merged
merged 45 commits into from Mar 5, 2024
Merged

feat: HTTP to UCAN bridge #325

merged 45 commits into from Mar 5, 2024

Commits on Feb 9, 2024

  1. feat: first draft of UCAN bridge

    To support users in languages that do not have existing UCAN invocation implementations, we are going to launch a bridge that allows them to make simple HTTP requests with JSON bodies that we transform into proper UCAN invocations.
    
    So far this PR has:
    
    1) an untested (but type-checking!) implementation of such a bridge
    2) a markdown description of the bridge protocol, intended to be the first draft of an eventual specification
    
    Notable design choices:
    
    1) I chose to include JUST the base64pad-encoded "secret" in the Authorization header to avoid running afoul of maximum header size restrictions that exist in [some HTTP environments](https://stackoverflow.com/questions/686217/maximum-on-http-header-values).
    2) The `proof` field of the JSON body is a base64pad encoded "delegation archive" (created with `ucanto`'s `Delegation.archive` function)
    
    TODO
    - [ ] factor core bridge logic out to a separate library
    - [ ] factor HTTP input wrangling out to a separate function
    - [ ] rename `UPLOAD_API_DID` and `ACCESS_SERVICE_URL` environment variables to `W3UP_SERVICE_DID` and `W3UP_SERVICE_URL`
    - [ ] add tests
    - [ ] expand and formalize bridge specification, move it to the specs repo (?)
    travis committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    5ebd1ea View commit details
    Browse the repository at this point in the history
  2. fix: return JSON properly

    travis committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    b53de7c View commit details
    Browse the repository at this point in the history

Commits on Feb 12, 2024

  1. feat: update spec

    update spec to use https:// github.com/ucan-wg/ucan-http-bearer-token?tab=readme-ov-file#ucan-as-bearer-token-specification-v030 and move the secret to a new `X-Auth-Secret` header
    
    update implementation per this spec - currently typechecks cleanly but throws an error when I actually try to invoke:
    
    ```
    TypeError: proof.export is not a function or its return value is not iterable
        at delegate (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/core/src/delegation.js:466:33)
        at IssuedInvocation.buildIPLDView (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/core/src/invocation.js:101:12)
        at writeInvocations (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/core/src/message.js:114:35)
        at MessageBuilder.buildIPLDView (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/core/src/message.js:79:52)
        at Object.build (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/core/src/message.js:30:49)
        at execute (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/client/src/connection.js:48:31)
        at Connection.execute (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/client/src/connection.js:35:12)
        at IssuedInvocation.execute (/Users/travis/dev/pl/w3infra/node_modules/@ucanto/core/src/invocation.js:115:39)
        at handlerFn (/Users/travis/dev/pl/w3infra/upload-api/functions/bridge.js:124:38)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    ```
    
    I think this is because the `@ipld/dag-ucan` `Ucan.View` is not a full `Delegation`
    travis committed Feb 12, 2024
    Configuration menu
    Copy the full SHA
    4185a6d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    bbfcb35 View commit details
    Browse the repository at this point in the history

Commits on Feb 16, 2024

  1. feat: update to latest designs

    worked with @gobengo and @Gozala to refine the design on this bridge - this is roughly the latest thinking, missing just a few things from PR reviews
    travis committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    02440e0 View commit details
    Browse the repository at this point in the history

Commits on Feb 21, 2024

  1. feat: a bunch of additions from PRs and other discussions

    1) add content negotiation and support CBOR
    2) better parsing abstractions
    3) validate tasks before casting
    
    one slightly weird thing I'm doing is converting the string I get from the AWS lambda to a ReadableStream and then reading it back again - seems silly in this implementation, but is necessary because I plan to pull out the abstraction and support other deployment environments like Cloudflare workers or Node's `fetch` API.
    travis committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    babea35 View commit details
    Browse the repository at this point in the history

Commits on Feb 22, 2024

  1. fix: support two more content types

    also error on unsupported content type
    travis committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    0a0f7d3 View commit details
    Browse the repository at this point in the history

Commits on Feb 23, 2024

  1. feat: update to latest request and response format

    need to update spec
    travis committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    fa74f9c View commit details
    Browse the repository at this point in the history

Commits on Feb 26, 2024

  1. fix: a couple tweaks

    travis committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    73447b7 View commit details
    Browse the repository at this point in the history
  2. fix: lint

    travis committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    f86fb98 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e73ce81 View commit details
    Browse the repository at this point in the history
  4. fix: one more tweak to spec

    travis committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    e45b667 View commit details
    Browse the repository at this point in the history
  5. fix: TODOs, error messages

    travis committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    bc2126c View commit details
    Browse the repository at this point in the history
  6. fix: move spec to specs repo

    travis committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    40536e9 View commit details
    Browse the repository at this point in the history

Commits on Mar 1, 2024

  1. fix: factor env variables out of runtime

    look up required env variables at deploy time
    travis committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    9dbd9d7 View commit details
    Browse the repository at this point in the history
  2. feat: add integration test for bridge

    had to upgrade w3up-client to bring in the coupon functionality
    travis committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    8e783a4 View commit details
    Browse the repository at this point in the history
  3. chore: lint

    travis committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    1acc53e View commit details
    Browse the repository at this point in the history
  4. fix: remove unused parameter

    travis committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    5d40271 View commit details
    Browse the repository at this point in the history
  5. feat: updates from PR review

    1) default to reading the request body as dag-json
    2) use `p` and `s` instead of `data` and `sig`, to match https://github.com/ucan-wg/invocation/blob/c596f04bbaf56c58df76bb578c6dfd53bb88bece/README.md#receipt-response
    3) use `dagJSON.decode`
    travis committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    b4bac79 View commit details
    Browse the repository at this point in the history
  6. fix: integration test

    travis committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    e1f020c View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    aadb19c View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    5c69e18 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    1170dde View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    e9389b4 View commit details
    Browse the repository at this point in the history

Commits on Mar 2, 2024

  1. Configuration menu
    Copy the full SHA
    78fd9a2 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c9c0864 View commit details
    Browse the repository at this point in the history
  3. fix: lint

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    82fd186 View commit details
    Browse the repository at this point in the history
  4. chore: more debugging!

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    1171b8a View commit details
    Browse the repository at this point in the history
  5. chore: more debugging

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    0904d3a View commit details
    Browse the repository at this point in the history
  6. chore: keep debugging

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    6cf3325 View commit details
    Browse the repository at this point in the history
  7. chore: more debugging

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    d8af685 View commit details
    Browse the repository at this point in the history
  8. chore: more debugging!

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    60ba516 View commit details
    Browse the repository at this point in the history
  9. chore: debug

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    9065b95 View commit details
    Browse the repository at this point in the history
  10. chore: debug

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    9a349af View commit details
    Browse the repository at this point in the history
  11. chore: debug

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    c43f4d6 View commit details
    Browse the repository at this point in the history
  12. chore: debugging

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    beeadce View commit details
    Browse the repository at this point in the history
  13. chore: debug

    travis committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    46011cc View commit details
    Browse the repository at this point in the history

Commits on Mar 4, 2024

  1. chore: more loggin

    travis committed Mar 4, 2024
    Configuration menu
    Copy the full SHA
    cb95b05 View commit details
    Browse the repository at this point in the history
  2. fix: fix service URLs

    The bridge was configured to point at staging even when it was running in a PR environment, because we don't customize the `ACCESS_SERVICE_URL` in those environments.
    
    It would be nice to figure out how to set the proper environment variables in different environments, but I suspect the right way to do that might change with the SST upgrade, so for now let's just add a function that encodes the rules we know, since these aren't likely to change soon and would require some code changes anyway.
    travis committed Mar 4, 2024
    Configuration menu
    Copy the full SHA
    71d33eb View commit details
    Browse the repository at this point in the history
  3. fix: no longer need to rewrite auth links!

    hooray!
    travis committed Mar 4, 2024
    Configuration menu
    Copy the full SHA
    14e82d3 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    0fcbf83 View commit details
    Browse the repository at this point in the history
  5. chore: cleanup

    travis committed Mar 4, 2024
    Configuration menu
    Copy the full SHA
    91fa5d0 View commit details
    Browse the repository at this point in the history
  6. fix: lint and types

    travis committed Mar 4, 2024
    Configuration menu
    Copy the full SHA
    3dffb9c View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    c55b512 View commit details
    Browse the repository at this point in the history

Commits on Mar 5, 2024

  1. Configuration menu
    Copy the full SHA
    0f521dc View commit details
    Browse the repository at this point in the history