-
Notifications
You must be signed in to change notification settings - Fork 8
feat: initial gnap and http signatures implementation #10
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
Changes from all commits
50cc13d
64ee7e0
2130dd8
e9e8dcf
baa2e9f
9b725c3
61ba6c9
6a2ccd3
8719193
adc8124
777b019
0a20138
94cd07f
d327d72
188cc0d
90c9d37
00885a3
250d03b
25b523c
3056025
a2aed05
f56b513
2ca863f
a813747
de3c090
a43785c
cb07c23
f040f2a
75f7708
7b21489
782ec63
aa4493c
293b0d8
973bc42
9303f8e
29f52bd
3f468f5
28ad4f0
81429ee
c339b91
27b7106
bbfbe66
a8ab4ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| name: Test Python open payments sdk | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - '**' | ||
| pull_request: | ||
| branches: | ||
| - '**' | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ${{ matrix.os }} | ||
|
|
||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest] | ||
| python-version: ["3.10","3.11","3.12","3.13"] | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Setup Poetry on Windows | ||
| if: runner.os == 'Windows' | ||
| run: | | ||
| (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py - | ||
| echo "$env:APPDATA\Python\Scripts" >> $env:GITHUB_PATH | ||
|
|
||
| - name: Verify Poetry and create env on Windows | ||
| if: runner.os == 'Windows' | ||
| run: | | ||
| poetry --version | ||
| poetry config virtualenvs.create false | ||
|
|
||
|
|
||
| - name: Setup Poetry on Ubuntu | ||
| if: runner.os != 'Windows' | ||
| run: | | ||
| curl -sSL https://install.python-poetry.org | python3 - | ||
| echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
| poetry config virtualenvs.create false | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| poetry install --no-interaction --no-root | ||
| poetry install --only dev | ||
|
|
||
| - name: Run Unit Tests | ||
| run: | | ||
| poetry run pytest tests/unit/ | ||
|
|
||
| audit: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Install dependencies | ||
| run: | | ||
| python3 -m pip install . # assumes dependencies declared in pyproject.toml | ||
| python3 -m pip install pip-audit | ||
| - name: Run pip-audit | ||
| run: pip-audit . |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,3 +170,4 @@ poetry.toml | |
| pyrightconfig.json | ||
|
|
||
| # End of https://www.toptal.com/developers/gitignore/api/python | ||
| privkey.pem | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,130 @@ An Open Payments server runs two sub-systems, a resource server which exposes AP | |
|
|
||
| ## Local development | ||
|
|
||
| ### Dependencies | ||
|
|
||
| - Python >= 3.11 | ||
|
|
||
| To install python visit [Python Download](https://www.python.org/downloads/) | ||
|
|
||
| - Poetry | ||
| To install poetry visit [Poetry Documentation](https://python-poetry.org/docs/). | ||
|
|
||
| ### Installation | ||
|
|
||
| 1. Activate your virtual emvironment. No need to create one, Poetry creates one. | ||
| Read [managing environments in Poetry](https://python-poetry.org/docs/managing-environments/). | ||
|
|
||
| 2. Install the dependencies in the poetry.lock | ||
|
|
||
| ``` | ||
| > poetry install | ||
| ``` | ||
|
elijah0kello marked this conversation as resolved.
|
||
|
|
||
| ## Usage | ||
|
|
||
| To use this SDK, you will first need to install it in your project. Currently, you will need to build from source but once it is hosted on PyPi you will be able to install it with `pip`. | ||
|
|
||
| ```bash | ||
| python3 -m pip install open-payments-python-sdk #currently not setup | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are running |
||
| ``` | ||
|
|
||
| ## Installing from source | ||
|
|
||
| Clone the repository | ||
|
|
||
| ```bash | ||
| git clone https://github.com/interledger/open-payments-python-sdk.git | ||
| cd open-payments-python-sdk | ||
| ``` | ||
|
|
||
| Build the package | ||
|
|
||
| ```bash | ||
| poetry build | ||
| ``` | ||
|
|
||
| After running this command, the wheel package will be written to the `dist/` folder in the repo you just cloned | ||
|
|
||
| Install it in your project | ||
|
|
||
| ```bash | ||
| pip install </path/to/>open-payments-python-sdk/dist/open_payments_sdk-0.1.0-py3-none-any.whl | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have a poetry based setup, there is no need to point to a pinned version of the wheel file. |
||
| ``` | ||
|
|
||
| # Initialising the Client | ||
|
|
||
| To create a client you can do so by importing the `OpenPaymentsClient` defined in the [`client`](./src/client/client.py) module and instantiating it. | ||
|
|
||
| ```python | ||
| from open_payments_sdk.client.client import OpenPaymentsClient | ||
|
|
||
| with open("privkey.pem","r",encoding="utf_8") as privkey: | ||
| private_key = privkey.read() | ||
|
|
||
| op_client = OpenPaymentsClient(keyid="27b4f8d2-746c-4522-b3f0-874ca15bfe65",private_key=private_key) | ||
| ``` | ||
|
|
||
| The client is to be created after you have created a key pair and have obtained the `kid` and `private_key` | ||
|
|
||
| Some helper functions have been created to ease key pair creation. A class called `KeyManager` has been created and it provides functions to create a key pair and load a private key from UTF-8 string. It also returns an object that has information to be registered at the AS when registering the public key. | ||
|
|
||
| ```python | ||
| import json | ||
| from open_payments_sdk.gnap_utils.keys import KeyManager | ||
|
|
||
| key_manager = KeyManager() | ||
| key_pair = key_manager.generate_key_pair() # generate key pair | ||
|
|
||
| with open("privkey.pem", "w",encoding="utf_8") as pem_file: # save private key to file | ||
| pem_file.write(key_pair.private_key_pem) | ||
|
|
||
|
|
||
| with open("jwks.json","w", encoding="utf_8") as jwks_file: # save jwks.json file | ||
| jwks_file.write(json.dumps(key_pair.jwks.keys[0].__dict__)) | ||
|
|
||
|
|
||
| with open("privkey.pem", "r", encoding="utf_8") as privkey: # load private key from file system | ||
| private_key = privkey.read() | ||
|
|
||
| private_key = key_manager.load_ed25519_private_key_from_pem( | ||
| private_key | ||
| ) # load private key fron file utf_8 string | ||
|
|
||
| public_key = private_key.public_key() # derive public key from private key | ||
| ``` | ||
|
|
||
| ## Wallets | ||
|
|
||
| You can use the created client to interact with the resource server. In this case we will use it to interact with a wallet address to get the wallet address details and jwks.json | ||
|
|
||
| ```python | ||
| #get wallet address | ||
| wallet_address_details = op_client.wallet.get_wallet_address("https://ilp.interledger-test.dev/elijahokellosalary") | ||
|
|
||
| # Response | ||
| {'id': AnyUrl('https://ilp.interledger-test.dev/elijahokellosalary'), 'publicName': 'elijahokellosalary', 'assetCode': AssetCode(root='USD'), 'assetScale': AssetScale(root=2), 'authServer': AnyUrl('https://auth.interledger-test.dev/'), 'resourceServer': AnyUrl('https://ilp.interledger-test.dev/')} | ||
|
|
||
| ``` | ||
|
|
||
| Get Wallet jwks | ||
|
|
||
| ```python | ||
| #get wallet jwks | ||
| wallet_jwks = op_client.wallet.get_keys("https://ilp.interledger-test.dev/elijahokellosalary") | ||
|
|
||
| # Response | ||
| {'keys': []} | ||
|
|
||
| ``` | ||
|
|
||
| ## Grants | ||
|
|
||
| You can use the created client to request a grant from the authorization server. In this case we will use it to request a grant for an incoming payment resource. Check the [fixtures](./tests/conftest.py) file to see the request body. | ||
|
|
||
| ```python | ||
| wallet = op_client.wallet.get_wallet_address("https://ilp.interledger-test.dev/5c327379") | ||
| grant_response = op_client.grants.post_grant_request(grant_request=grant_req_dto,auth_server_endpoint=str(wallet.authServer)) | ||
|
|
||
| # Response | ||
| {'access_token': {'access': [{'actions': ['create', 'read'], 'identifier': 'https://ilp.interledger-test.dev/5c327379', 'type': 'incoming-payment'}], 'value': '2E6F040D518B6F1A0883', 'manage': 'https://auth.interledger-test.dev/token/dad85db0-804d-4778-bf78-33eb5f81d86e', 'expires_in': 600}, 'continue': {'access_token': {'value': '3A088F83D39BDCDEC995'}, 'uri': 'https://auth.interledger-test.dev/continue/d2bb7a46-8cd9-4dde-83e2-821353b50579'}} | ||
|
|
||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.