mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
Merge pull request #1011 from ripple/secure-signing-py
Add python example for secure signing
This commit is contained in:
22
content/_code-samples/secure-signing/py/sign-payment.py
Normal file
22
content/_code-samples/secure-signing/py/sign-payment.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Define signer address
|
||||||
|
import os
|
||||||
|
my_secret = os.getenv("MY_SECRET")
|
||||||
|
from xrpl.wallet import Wallet
|
||||||
|
wallet = Wallet(seed="MY_SECRET")
|
||||||
|
print(wallet.classic_address) # "raaFKKmgf6CRZttTVABeTcsqzRQ51bNR6Q"
|
||||||
|
|
||||||
|
from xrpl.models.transactions import Payment
|
||||||
|
from xrpl.utils import xrp_to_drops
|
||||||
|
my_payment = Payment(
|
||||||
|
account=test_wallet_1.classic_address,
|
||||||
|
amount=xrp_to_drops(22),
|
||||||
|
fee="10",
|
||||||
|
destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||||
|
sequence=16126889,
|
||||||
|
)
|
||||||
|
print("Payment object:", my_payment)
|
||||||
|
|
||||||
|
# Sign transaction -------------------------------------------------------------
|
||||||
|
import xrpl.transaction
|
||||||
|
signed = xrpl.transaction.safe_sign_transaction(my_payment, test_wallet_1)
|
||||||
|
print("Signed transaction blob:", signed)
|
||||||
@@ -74,14 +74,27 @@ If you use a client library not published by Ripple, make sure it uses proper, s
|
|||||||
|
|
||||||
For best security, be sure to keep your client library updated to the latest stable version.
|
For best security, be sure to keep your client library updated to the latest stable version.
|
||||||
|
|
||||||
### Example Local Signing with RippleAPI
|
### Local Signing Example
|
||||||
|
|
||||||
The following code sample shows how to sign transaction instructions locally with RippleAPI for JavaScript:
|
The following code sample shows how to sign transaction instructions locally with [`ripple-lib`](https://github.com/ripple/ripple-lib) for JavaScript and [`xrpl-py`](https://github.com/XRPLF/xrpl-py) for Python:
|
||||||
|
|
||||||
|
<!-- MULTICODE_BLOCK_START -->
|
||||||
|
|
||||||
|
*JavaScript*
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{% include '_code-samples/secure-signing/js/signPayment.js' %}
|
{% include '_code-samples/secure-signing/js/signPayment.js' %}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
*Python*
|
||||||
|
|
||||||
|
```py
|
||||||
|
{% include '_code-samples/secure-signing/py/sign-payment.py' %}
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- MULTICODE_BLOCK_END -->
|
||||||
|
|
||||||
|
|
||||||
For greater security, you can load your secret keys from a management tool such as [Vault](https://www.vaultproject.io/).
|
For greater security, you can load your secret keys from a management tool such as [Vault](https://www.vaultproject.io/).
|
||||||
|
|
||||||
|
|
||||||
@@ -117,6 +130,7 @@ To use this configuration, follow the steps for [running `rippled` on a private
|
|||||||
- [sign method][]
|
- [sign method][]
|
||||||
- [submit method][]
|
- [submit method][]
|
||||||
- [RippleAPI Reference](rippleapi-reference.html)
|
- [RippleAPI Reference](rippleapi-reference.html)
|
||||||
|
- [xrpl-py Reference](https://xrpl-py.readthedocs.io/en/latest/index.html)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user