Skip to main content

sapphire.py

Installation

pip3 install --user -r requirements.txt
pip3 install --user -r requirements.dev.txt
make

Changelog

https://github.com/oasisprotocol/sapphire-paratime/tree/main/clients/py/CHANGELOG.md

Usage

from web3 import Web3, AsyncWeb3
from web3.middleware import SignAndSendRawMiddlewareBuilder
from eth_account import Account
from eth_account.signers.local import LocalAccount

from sapphirepy import sapphire

w3 = Web3(Web3.HTTPProvider(sapphire.NETWORKS['sapphire-localnet']))
async_w3 = AsyncWeb3(
    AsyncWeb3.AsyncHTTPProvider(
        sapphire.NETWORKS['sapphire-localnet']
    )
)

# Optional: Setup your Web3 provider with a signing account.
# This account is used for signing transactions.
account: LocalAccount = (
    Account.from_key(  # pylint: disable=no-value-for-parameter
        private_key="<your_private_key_here>"
    )
)
w3.middleware_onion.add(SignAndSendRawMiddlewareBuilder.build(account))

# Finally, wrap the provider to add Sapphire end-to-end encryption.
# Note: Account parameter in the wrap() function is used for signing view
# calls and can be different from the account used for singing transactions.
w3 = sapphire.wrap(w3, account) # Can provide custom "account" parameter
w3.eth.default_account = account.address # Alternatively you can set "from" tx param each time for signed view calls
# Wrapper middleware also works with AsyncWeb3
async_w3 = sapphire.wrap(async_w3, account)

# Account parameter is optional, to encrypt view calls without signing 
# we can omit the account parameter
w3 = sapphire.wrap(w3)
async_w3 = sapphire.wrap(async_w3)

# Optionally, query Oasis Web3 Gateway for the gas price.
from web3.gas_strategies.rpc import rpc_gas_price_strategy
w3.eth.set_gas_price_strategy(rpc_gas_price_strategy)

The Sapphire middleware for Web3.py ensures all transactions, gas estimates and view calls are end-to-end encrypted between your application and the smart contract.

License

The Deoxys-ii library and its test vectors are derived directly from the original go library.

The remainder of the Oasis Sapphire python bindings is licensed under Apache 2.0 license.

Metadata

Release files for oasis-sapphire-py 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for oasis-sapphire-py 0.4.2
File Interpreter ABI Platform Actions
oasis_sapphire_py-0.4.2-py3-none-any.whl Python 3 none any Details for oasis_sapphire_py-0.4.2-py3-none-any.whl

Release files / oasis_sapphire_py-0.4.2-py3-none-any.whl

Download URL oasis_sapphire_py-0.4.2-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3c957df9958fd6e8e7cf700228d4255bf1f32800974e11770f4ba41b2be65ab
BLAKE2b-256 checksum
How to use checksums
12be6b2771f716c3d94d249262e85418e9175864d925537c1f0f55af3170ccef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for oasis-sapphire-py 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page