kin-sdk-v2


Namekin-sdk-v2 JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/kinecosystem/kin-python
SummaryKin SDK for Python
upload_time2021-01-13 19:35:12
maintainer
docs_urlNone
authorKik Engineering
requires_python>=3.6
licenseMIT
keywords kin agora stellar blockchain cryptocurrency
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Kin Python SDK

The Kin Python SDK enables developers use Kin inside their backend servers. It contains support for blockchain actions 
such as creating accounts and sending payments, as well a webhook handler class to assist with implementing Agora webhooks. 

## Requirements
Python 3.6 or higher

## Installation
```
pip install kin-sdk-v2
```

## Overview
The SDK contains two main components: the `Client` and the `WebhookHandler`. The `Client` is used for blockchain
actions, such as creating accounts sending payments, while the `WebhookHandler` is meant for developers who wish to make
use of Agora Webhooks. It is recommended that developers read the [website documentation](https://docs.kin.org) prior to using this SDK.



## Client
The main component of this library is the `Client` class, which facilitates access to the Kin blockchain. 

### Initialization
At a minimum, the client needs to be instantiated with an `Environment`.

```python
from agora.client import Client, Environment 

client = Client(Environment.TEST)
```

Apps with [registered](https://docs.kin.org/app-registration) app indexes should initialize the client with their index:
```python
from agora.client import Client, Environment

client = Client(Environment.TEST, app_index=1)
```

Additional options include:
- `whitelist_key`: The private key of an account that will be used to co-sign all transactions. Should only be set for Kin 3.
- `grpc_channel`: A specific `grpc.Channel` to use. Cannot be set if `endpoint` is set.
- `endpoint`: A specific endpoint to use in the client. Cannot be set if `grpc_channel` is set.
- `retry_config`: A custom `agora.client.RetryConfig` to configure how the client retries requests.
- `kin_version`: The version of Kin to use. Defaults to 3.
- `default_commitment`: (Kin 4 only) The commitment requirement to use by default for Kin 4 Agora requests. See the [website documentation](https://docs.kin.org/solana#commitment) for more information.

### Usage
#### Create an Account
The `create_account` method creates an account with the provided private key.

To create a new account, first generate a new private key:
```python
from agora.keys import PrivateKey

private_key = PrivateKey.random()
```

Next, submit it using `create_account`:
```python
client.create_account(private_key)
```

In addition to the mandatory `private_key` parameter, `create_account` has the following optional parameters:
- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details. 
- `subsidizer`: (Kin 4 only) The private key of an account to use as the funder of the transaction instead of the subsidizer configured on Agora.

#### Get a Transaction
The `get_transaction` method gets transaction data by transaction id.
```python
# tx_id is either a 32-byte Stellar transaction hash or a 64-byte Solana transaction signature 
tx_id = b'<txid>'
transaction_data = client.get_transaction(tx_id)
```

In addition to the mandatory `tx_id` parameter, `get_transaction` has the following optional parameters:
- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details. 

#### Get an Account Balance
The `get_balance` method gets the balance of the provided account, in [quarks](https://docs.kin.org/terms-and-concepts#quark).
```python
from agora.keys import PrivateKey
from agora.client import Client, Environment

client = Client(Environment.TEST, app_index=1)
public_key = PrivateKey.random().public_key
balance = client.get_balance(public_key)
``` 

In addition to the mandatory `public_key` parameter, `get_balance` has the following optional parameters:
- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details. 

#### Submit a Payment
The `submit_payment` method submits the provided payment to Agora.
```python
from agora.client import Client, Environment
from agora.model import Payment, TransactionType, PrivateKey, PublicKey
from agora.utils import kin_to_quarks

client = Client(Environment.TEST, app_index=1)
sender = PrivateKey.from_string('SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
dest = PublicKey.from_string('GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
payment = Payment(sender, dest, TransactionType.EARN, kin_to_quarks("1"))

tx_hash = client.submit_payment(payment)
```

A `Payment` has the following required properties:
- `sender`: The private key of the account from which the payment will be sent.
- `destination`: The public key of the account to which the payment will be sent.
- `tx_type`: The transaction type of the payment.
- `quarks`: The amount of the payment, in [quarks](https://docs.kin.org/terms-and-concepts#quark).

Additionally, it has some optional properties:
- `channel`: (Kin 2 and Kin 3 only) The private key of a [channel](https://docs.kin.org/how-it-works#channels) account to use as the source of the transaction. If unset, `sender` will be used as the transaction source.
- `invoice`: An [Invoice](https://docs.kin.org/how-it-works#invoices) to associate with this payment. Cannot be set if `memo` is set.
- `memo` A text memo to include in the transaction. Cannot be set if `invoice` is set.
- `subsidizer`: (Kin 4 only) The private key of an account to use as the funder of the transaction instead of the subsidizer configured on Agora.

`submit_payment` also has the following optional properties:
- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details.
- `sender_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment sender.
- `dest_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment destination.

#### Submit an Earn Batch
The `submit_earn_batch` method submits a batch of earns to Agora from a single account. It batches the earns into fewer 
transactions where possible and submits as many transactions as necessary to submit all the earns.
```python
from agora.client import Client, Environment
from agora.model import Earn, PrivateKey, PublicKey
from agora.utils import kin_to_quarks

client = Client(Environment.TEST, app_index=1)
sender = PrivateKey.from_string('SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
dest1 = PublicKey.from_string('GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1')
dest2 = PublicKey.from_string('GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2')

# Send two earns of 1 Kin each
earns = [
    Earn(dest1, kin_to_quarks("1")),
    Earn(dest2, 100000),  # also equivalent to 1 Kin
    ...
]

batch_earn_result = client.submit_earn_batch(sender, earns)
```

A single `Earn` has the following properties:
- `destination`: The public key of the account to which the earn will be sent.
- `quarks`: The amount of the earn, in [quarks](https://docs.kin.org/terms-and-concepts#quark).
- `invoice`: (optional) An [Invoice](https://docs.kin.org/how-it-works#invoices) to associate with this earn.

The `submit_earn_batch` method has the following parameters:
- `sender`:  The private key of the account from which the earns will be sent.
- `earns`: The list of earns to send.
- `channel`: (optional, Kin 2 and Kin 3 only) The private key of a [channel](https://docs.kin.org/how-it-works#channels) account to use as the transaction source. If not set, `sender` will be used as the source.
- `memo`: (optional) A text memo to include in the transaction. Cannot be used if the earns have invoices associated with them.
- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details.
- `sender_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment sender.
- `dest_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment destination.

### Examples
A few examples for creating an account and different ways of submitting payments and batched earns can be found in `examples/client`.

## Webhook Handler
The `WebhookHandler` class is designed to assist developers with implementing the [Agora webhooks](https://docs.kin.org/how-it-works#webhooks). 

Only apps that have been assigned an [app index](https://docs.kin.org/app-registration) can make use of Agora webhooks.   

### Initialization
The `WebhookHandler` must be instantiated with the app's configured [webhook secret](https://docs.kin.org/agora/webhook#authentication).
```python
from agora.client import Environment
from agora.webhook.handler import WebhookHandler

webhook_handler = WebhookHandler(Environment.TEST, 'mysecret')
```  

### Usage
Currently, `WebhookHandler` contains support for the following webhooks:
- [Events](https://docs.kin.org/how-it-works#events), with `handle_events`
- [Sign Transaction](https://docs.kin.org/how-it-works#sign-transaction), with `handle_sign_transaction`

#### Events Webhook
To use the `WebhookHandler` with the Events webhook, developers should define a function that accepts a list of events and processes them in some way:
```python
from typing import List

from agora.webhook.events import Event


def process_events(events: List[Event]) -> None:
    # some processing logic
    return
``` 

This function can be used with `WebhookHandler.handle_events` inside your events endpoint logic as follows:
```python
from typing import List

from agora.client import Environment
from agora.webhook import WebhookHandler, AGORA_HMAC_HEADER
from agora.webhook.events import Event

webhook_handler = WebhookHandler(Environment.TEST, 'mysecret')


def process_events(events: List[Event]) -> None:
    # some processing logic
    return


# This will vary depending on which framework is used.
def events_endpoint_func(request):
    status_code, request_body = webhook_handler.handle_events(
        process_events,
        request.headers.get(AGORA_HMAC_HEADER),
        request.body,
    )

    # respond using provided status_code and request_body  
```

`WebhookHandler.handle_events` takes in the following mandatory parameters:
- `f`: A function that accepts a list of Events. Any return value will be ignored.
- `signature`: The base64-encoded signature included as the `X-Agora-HMAC-SHA256` header in the HTTP request (see the [Agora Webhook Reference](https://docs.kin.org/agora/webhook) for more details).
- `req_body`: The string request body.

#### Sign Transaction Webhook 
The sign transaction webhook is used to sign Kin 3 transactions with a whitelisted Kin 3 account to remove fees. On Kin 4, the webhook can be used to simply approve or reject transactions submitted by mobile clients. 

To use the `WebhookHandler` with the Sign Transaction webhook, developers should define a function that accepts a sign transaction request and response object and verifies the request in some way and modifies the response object as needed:
```python
from agora.webhook.sign_transaction import SignTransactionRequest, SignTransactionResponse

def verify_request(req: SignTransactionRequest, resp: SignTransactionResponse) -> None:
    # verify the transaction inside `req`, and modify `resp` as needed.
    return
```

This function can be used with `WebhookHandler.sign_transaction` inside your sign transaction endpoint logic as follows:
```python
from agora.client import Environment
from agora.webhook import WebhookHandler, AGORA_HMAC_HEADER
from agora.webhook.sign_transaction import SignTransactionRequest, SignTransactionResponse

webhook_handler = WebhookHandler(Environment.TEST, 'mysecret')

def verify_request(req: SignTransactionRequest, resp: SignTransactionResponse) -> None:
    # verify the transaction inside `req`, and modify `resp` as needed (e.g. by calling `sign`).
    return

# This will vary depending on which framework is used.
def sign_tx_endpoint_func(request):
    status_code, request_body = webhook_handler.handle_sign_transaction(
        verify_request,
        request.headers.get(AGORA_HMAC_HEADER),
        request.body,
    )

    # respond using provided status_code and request_body  
```

`WebhookHandler.handle_sign_transaction` takes in the following mandatory parameters:
- `f`: A function that takes in a SignTransactionRequest and a SignTransactionResponse. Any return value will be ignored.
- `signature`: The base64-encoded signature included as the `X-Agora-HMAC-SHA256` header in the HTTP request (see the [Agora Webhook Reference](https://docs.kin.org/agora/webhook) for more details).
- `req_body`: The string request body.

### Example Code
A simple example Flask server implementing both the Events and Sign Transaction webhooks can be found in `examples/webhook/app.py`. To run it, first install all required dependencies (it is recommended that you use a virtual environment):
```
make deps
make deps-dev
```

Next, run it as follows from the root directory (it will run on port 8080):
```
export WEBHOOK_SECRET=yoursecrethere
export WEBHOOK_SEED=SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

python -m examples.webhook.app
``` 

## API Reference

The API reference can be found [here](https://docs.kin.org/python/api).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kinecosystem/kin-python",
    "name": "kin-sdk-v2",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "kin,agora,stellar,blockchain,cryptocurrency",
    "author": "Kik Engineering",
    "author_email": "engineering@kik.com",
    "download_url": "https://files.pythonhosted.org/packages/5e/09/760581c5ebdbb7b920d895dd8d2a95eec913bc43d935c1c596d18260d445/kin-sdk-v2-0.6.1.tar.gz",
    "platform": "",
    "description": "# Kin Python SDK\n\nThe Kin Python SDK enables developers use Kin inside their backend servers. It contains support for blockchain actions \nsuch as creating accounts and sending payments, as well a webhook handler class to assist with implementing Agora webhooks. \n\n## Requirements\nPython 3.6 or higher\n\n## Installation\n```\npip install kin-sdk-v2\n```\n\n## Overview\nThe SDK contains two main components: the `Client` and the `WebhookHandler`. The `Client` is used for blockchain\nactions, such as creating accounts sending payments, while the `WebhookHandler` is meant for developers who wish to make\nuse of Agora Webhooks. It is recommended that developers read the [website documentation](https://docs.kin.org) prior to using this SDK.\n\n\n\n## Client\nThe main component of this library is the `Client` class, which facilitates access to the Kin blockchain. \n\n### Initialization\nAt a minimum, the client needs to be instantiated with an `Environment`.\n\n```python\nfrom agora.client import Client, Environment \n\nclient = Client(Environment.TEST)\n```\n\nApps with [registered](https://docs.kin.org/app-registration) app indexes should initialize the client with their index:\n```python\nfrom agora.client import Client, Environment\n\nclient = Client(Environment.TEST, app_index=1)\n```\n\nAdditional options include:\n- `whitelist_key`: The private key of an account that will be used to co-sign all transactions. Should only be set for Kin 3.\n- `grpc_channel`: A specific `grpc.Channel` to use. Cannot be set if `endpoint` is set.\n- `endpoint`: A specific endpoint to use in the client. Cannot be set if `grpc_channel` is set.\n- `retry_config`: A custom `agora.client.RetryConfig` to configure how the client retries requests.\n- `kin_version`: The version of Kin to use. Defaults to 3.\n- `default_commitment`: (Kin 4 only) The commitment requirement to use by default for Kin 4 Agora requests. See the [website documentation](https://docs.kin.org/solana#commitment) for more information.\n\n### Usage\n#### Create an Account\nThe `create_account` method creates an account with the provided private key.\n\nTo create a new account, first generate a new private key:\n```python\nfrom agora.keys import PrivateKey\n\nprivate_key = PrivateKey.random()\n```\n\nNext, submit it using `create_account`:\n```python\nclient.create_account(private_key)\n```\n\nIn addition to the mandatory `private_key` parameter, `create_account` has the following optional parameters:\n- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details. \n- `subsidizer`: (Kin 4 only) The private key of an account to use as the funder of the transaction instead of the subsidizer configured on Agora.\n\n#### Get a Transaction\nThe `get_transaction` method gets transaction data by transaction id.\n```python\n# tx_id is either a 32-byte Stellar transaction hash or a 64-byte Solana transaction signature \ntx_id = b'<txid>'\ntransaction_data = client.get_transaction(tx_id)\n```\n\nIn addition to the mandatory `tx_id` parameter, `get_transaction` has the following optional parameters:\n- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details. \n\n#### Get an Account Balance\nThe `get_balance` method gets the balance of the provided account, in [quarks](https://docs.kin.org/terms-and-concepts#quark).\n```python\nfrom agora.keys import PrivateKey\nfrom agora.client import Client, Environment\n\nclient = Client(Environment.TEST, app_index=1)\npublic_key = PrivateKey.random().public_key\nbalance = client.get_balance(public_key)\n``` \n\nIn addition to the mandatory `public_key` parameter, `get_balance` has the following optional parameters:\n- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details. \n\n#### Submit a Payment\nThe `submit_payment` method submits the provided payment to Agora.\n```python\nfrom agora.client import Client, Environment\nfrom agora.model import Payment, TransactionType, PrivateKey, PublicKey\nfrom agora.utils import kin_to_quarks\n\nclient = Client(Environment.TEST, app_index=1)\nsender = PrivateKey.from_string('SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')\ndest = PublicKey.from_string('GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')\npayment = Payment(sender, dest, TransactionType.EARN, kin_to_quarks(\"1\"))\n\ntx_hash = client.submit_payment(payment)\n```\n\nA `Payment` has the following required properties:\n- `sender`: The private key of the account from which the payment will be sent.\n- `destination`: The public key of the account to which the payment will be sent.\n- `tx_type`: The transaction type of the payment.\n- `quarks`: The amount of the payment, in [quarks](https://docs.kin.org/terms-and-concepts#quark).\n\nAdditionally, it has some optional properties:\n- `channel`: (Kin 2 and Kin 3 only) The private key of a [channel](https://docs.kin.org/how-it-works#channels) account to use as the source of the transaction. If unset, `sender` will be used as the transaction source.\n- `invoice`: An [Invoice](https://docs.kin.org/how-it-works#invoices) to associate with this payment. Cannot be set if `memo` is set.\n- `memo` A text memo to include in the transaction. Cannot be set if `invoice` is set.\n- `subsidizer`: (Kin 4 only) The private key of an account to use as the funder of the transaction instead of the subsidizer configured on Agora.\n\n`submit_payment` also has the following optional properties:\n- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details.\n- `sender_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment sender.\n- `dest_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment destination.\n\n#### Submit an Earn Batch\nThe `submit_earn_batch` method submits a batch of earns to Agora from a single account. It batches the earns into fewer \ntransactions where possible and submits as many transactions as necessary to submit all the earns.\n```python\nfrom agora.client import Client, Environment\nfrom agora.model import Earn, PrivateKey, PublicKey\nfrom agora.utils import kin_to_quarks\n\nclient = Client(Environment.TEST, app_index=1)\nsender = PrivateKey.from_string('SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')\ndest1 = PublicKey.from_string('GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1')\ndest2 = PublicKey.from_string('GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2')\n\n# Send two earns of 1 Kin each\nearns = [\n    Earn(dest1, kin_to_quarks(\"1\")),\n    Earn(dest2, 100000),  # also equivalent to 1 Kin\n    ...\n]\n\nbatch_earn_result = client.submit_earn_batch(sender, earns)\n```\n\nA single `Earn` has the following properties:\n- `destination`: The public key of the account to which the earn will be sent.\n- `quarks`: The amount of the earn, in [quarks](https://docs.kin.org/terms-and-concepts#quark).\n- `invoice`: (optional) An [Invoice](https://docs.kin.org/how-it-works#invoices) to associate with this earn.\n\nThe `submit_earn_batch` method has the following parameters:\n- `sender`:  The private key of the account from which the earns will be sent.\n- `earns`: The list of earns to send.\n- `channel`: (optional, Kin 2 and Kin 3 only) The private key of a [channel](https://docs.kin.org/how-it-works#channels) account to use as the transaction source. If not set, `sender` will be used as the source.\n- `memo`: (optional) A text memo to include in the transaction. Cannot be used if the earns have invoices associated with them.\n- `commitment`: (Kin 4 only) Indicates to Solana which bank state to query. See the [website documentation](https://docs.kin.org/solana#commitment) for more details.\n- `sender_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment sender.\n- `dest_resolution`: (Kin 4 only) Indicates which type of account resolution to use for the payment destination.\n\n### Examples\nA few examples for creating an account and different ways of submitting payments and batched earns can be found in `examples/client`.\n\n## Webhook Handler\nThe `WebhookHandler` class is designed to assist developers with implementing the [Agora webhooks](https://docs.kin.org/how-it-works#webhooks). \n\nOnly apps that have been assigned an [app index](https://docs.kin.org/app-registration) can make use of Agora webhooks.   \n\n### Initialization\nThe `WebhookHandler` must be instantiated with the app's configured [webhook secret](https://docs.kin.org/agora/webhook#authentication).\n```python\nfrom agora.client import Environment\nfrom agora.webhook.handler import WebhookHandler\n\nwebhook_handler = WebhookHandler(Environment.TEST, 'mysecret')\n```  \n\n### Usage\nCurrently, `WebhookHandler` contains support for the following webhooks:\n- [Events](https://docs.kin.org/how-it-works#events), with `handle_events`\n- [Sign Transaction](https://docs.kin.org/how-it-works#sign-transaction), with `handle_sign_transaction`\n\n#### Events Webhook\nTo use the `WebhookHandler` with the Events webhook, developers should define a function that accepts a list of events and processes them in some way:\n```python\nfrom typing import List\n\nfrom agora.webhook.events import Event\n\n\ndef process_events(events: List[Event]) -> None:\n    # some processing logic\n    return\n``` \n\nThis function can be used with `WebhookHandler.handle_events` inside your events endpoint logic as follows:\n```python\nfrom typing import List\n\nfrom agora.client import Environment\nfrom agora.webhook import WebhookHandler, AGORA_HMAC_HEADER\nfrom agora.webhook.events import Event\n\nwebhook_handler = WebhookHandler(Environment.TEST, 'mysecret')\n\n\ndef process_events(events: List[Event]) -> None:\n    # some processing logic\n    return\n\n\n# This will vary depending on which framework is used.\ndef events_endpoint_func(request):\n    status_code, request_body = webhook_handler.handle_events(\n        process_events,\n        request.headers.get(AGORA_HMAC_HEADER),\n        request.body,\n    )\n\n    # respond using provided status_code and request_body  \n```\n\n`WebhookHandler.handle_events` takes in the following mandatory parameters:\n- `f`: A function that accepts a list of Events. Any return value will be ignored.\n- `signature`: The base64-encoded signature included as the `X-Agora-HMAC-SHA256` header in the HTTP request (see the [Agora Webhook Reference](https://docs.kin.org/agora/webhook) for more details).\n- `req_body`: The string request body.\n\n#### Sign Transaction Webhook \nThe sign transaction webhook is used to sign Kin 3 transactions with a whitelisted Kin 3 account to remove fees. On Kin 4, the webhook can be used to simply approve or reject transactions submitted by mobile clients. \n\nTo use the `WebhookHandler` with the Sign Transaction webhook, developers should define a function that accepts a sign transaction request and response object and verifies the request in some way and modifies the response object as needed:\n```python\nfrom agora.webhook.sign_transaction import SignTransactionRequest, SignTransactionResponse\n\ndef verify_request(req: SignTransactionRequest, resp: SignTransactionResponse) -> None:\n    # verify the transaction inside `req`, and modify `resp` as needed.\n    return\n```\n\nThis function can be used with `WebhookHandler.sign_transaction` inside your sign transaction endpoint logic as follows:\n```python\nfrom agora.client import Environment\nfrom agora.webhook import WebhookHandler, AGORA_HMAC_HEADER\nfrom agora.webhook.sign_transaction import SignTransactionRequest, SignTransactionResponse\n\nwebhook_handler = WebhookHandler(Environment.TEST, 'mysecret')\n\ndef verify_request(req: SignTransactionRequest, resp: SignTransactionResponse) -> None:\n    # verify the transaction inside `req`, and modify `resp` as needed (e.g. by calling `sign`).\n    return\n\n# This will vary depending on which framework is used.\ndef sign_tx_endpoint_func(request):\n    status_code, request_body = webhook_handler.handle_sign_transaction(\n        verify_request,\n        request.headers.get(AGORA_HMAC_HEADER),\n        request.body,\n    )\n\n    # respond using provided status_code and request_body  \n```\n\n`WebhookHandler.handle_sign_transaction` takes in the following mandatory parameters:\n- `f`: A function that takes in a SignTransactionRequest and a SignTransactionResponse. Any return value will be ignored.\n- `signature`: The base64-encoded signature included as the `X-Agora-HMAC-SHA256` header in the HTTP request (see the [Agora Webhook Reference](https://docs.kin.org/agora/webhook) for more details).\n- `req_body`: The string request body.\n\n### Example Code\nA simple example Flask server implementing both the Events and Sign Transaction webhooks can be found in `examples/webhook/app.py`. To run it, first install all required dependencies (it is recommended that you use a virtual environment):\n```\nmake deps\nmake deps-dev\n```\n\nNext, run it as follows from the root directory (it will run on port 8080):\n```\nexport WEBHOOK_SECRET=yoursecrethere\nexport WEBHOOK_SEED=SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n\npython -m examples.webhook.app\n``` \n\n## API Reference\n\nThe API reference can be found [here](https://docs.kin.org/python/api).\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Kin SDK for Python",
    "version": "0.6.1",
    "split_keywords": [
        "kin",
        "agora",
        "stellar",
        "blockchain",
        "cryptocurrency"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "cde0b84611ccd73bd67c5d60f03ee8aa",
                "sha256": "066c1ebe29e4938bae41847f68c5aaefcd262ea3684d85930af57e56fb1e64e8"
            },
            "downloads": -1,
            "filename": "kin_sdk_v2-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cde0b84611ccd73bd67c5d60f03ee8aa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 56689,
            "upload_time": "2021-01-13T19:35:11",
            "upload_time_iso_8601": "2021-01-13T19:35:11.492224Z",
            "url": "https://files.pythonhosted.org/packages/16/d3/d8698fbfbdd1be84f96f34913b8d6867819fdad8932f396de8a0e5fe9652/kin_sdk_v2-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "57d3ed4ae74ab19db8c69e3101c77f62",
                "sha256": "64a80a1825dd4197b3fd7959d595644f67ae68ab42254496093c16b9f756fe2c"
            },
            "downloads": -1,
            "filename": "kin-sdk-v2-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "57d3ed4ae74ab19db8c69e3101c77f62",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 46914,
            "upload_time": "2021-01-13T19:35:12",
            "upload_time_iso_8601": "2021-01-13T19:35:12.755606Z",
            "url": "https://files.pythonhosted.org/packages/5e/09/760581c5ebdbb7b920d895dd8d2a95eec913bc43d935c1c596d18260d445/kin-sdk-v2-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-01-13 19:35:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "kinecosystem",
    "error": "Could not fetch GitHub repository",
    "lcname": "kin-sdk-v2"
}
        
Elapsed time: 0.18951s