sapphirepy package¶
Submodules¶
sapphirepy.deoxysii module¶
This work is derived from: https://github.com/oasisprotocol/deoxysii
Copyright (c) 2019 Oasis Labs Inc. <info@oasislabs.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- class sapphirepy.deoxysii.DeoxysII(key: bytes | bytearray)[source]¶
Bases:
object
- decrypt(nonce: bytes | bytearray, dst: bytearray, ad: bytes | bytearray | None, ciphertext: bytes | bytearray)[source]¶
- derived_k: list[bytearray]¶
- encrypt(nonce: bytes | bytearray, dst: bytearray, ad: bytes | bytearray | None, msg: bytes | bytearray | None)[source]¶
- property implementation¶
- sapphirepy.deoxysii.bc_encrypt(ciphertext: bytearray, derived_k: list[bytearray], tweak: bytearray, plaintext: bytes | bytearray)[source]¶
sapphirepy.envelope module¶
- exception sapphirepy.envelope.CallError[source]¶
Bases:
SapphireError
- exception sapphirepy.envelope.DecryptError[source]¶
Bases:
SapphireError
- exception sapphirepy.envelope.EnvelopeError[source]¶
Bases:
SapphireError
- class sapphirepy.envelope.Failure[source]¶
Bases:
TypedDict
- code: int¶
- message: str | None¶
- module: str¶
- class sapphirepy.envelope.RequestBody[source]¶
Bases:
TypedDict
- data: bytes¶
- epoch: int¶
- nonce: bytes¶
- pk: bytes¶
- class sapphirepy.envelope.ResultOuter[source]¶
Bases:
TypedDict
- ok: AeadEnvelope | None¶
- unknown: AeadEnvelope | None¶
sapphirepy.error module¶
sapphirepy.sapphire module¶
- class sapphirepy.sapphire.CalldataPublicKey[source]¶
Bases:
TypedDict
- checksum: HexStr¶
- epoch: int¶
- key: HexStr¶
- signature: HexStr¶
- class sapphirepy.sapphire.CalldataPublicKeyManager[source]¶
Bases:
object
- add(pk: CalldataPublicKey)[source]¶
- property newest¶
- class sapphirepy.sapphire.ConstructSapphireMiddlewareBuilder(w3: AsyncWeb3 | Web3)[source]¶
Bases:
Web3MiddlewareBuilder
Construct a Sapphire middleware for Web3.py. :param account: Used to encrypt signed queries. :return: A Sapphire middleware function.
- async async_wrap_make_request(make_request: Callable[[RPCEndpoint, Any], Coroutine[Any, Any, RPCResponse]]) Callable[[RPCEndpoint, Any], Coroutine[Any, Any, RPCResponse]] [source]¶
Async version of wrap_make_request that handles the same encryption logic for eth_estimateGas, eth_sendTransaction, and eth_call
- sapphire_account = None¶
- wrap_make_request(make_request: Callable[[RPCEndpoint, Any], RPCResponse]) Callable[[RPCEndpoint, Any], RPCResponse] [source]¶
Synchronous wrapper around async_wrap_make_request. Creates a new event loop to run the async middleware.
Transparently encrypt the calldata for:
eth_estimateGas
eth_sendTransaction
eth_call
The calldata public key, which used to derive a shared secret with an ephemeral key, is retrieved upon the first request. This key is rotated by Sapphire every epoch, and only transactions encrypted with keys from the last 5 epochs are considered valid.
Deployment transactions will not be encrypted, unless the global ENCRYPT_DEPLOYS flag is set. Encrypting deployments will prevent contracts from being verified.
Pre-signed transactions can’t be encrypted if submitted via this instance.
- sapphirepy.sapphire.wrap(w3: Web3 | AsyncWeb3, account: LocalAccount | None = None)[source]¶
Adds the Sapphire transaction encryption middleware to a Web3.py provider.
- Note: the provider must be wrapped after any signing middleware has been
added, otherwise pre-signed transactions will not be encrypted.