diff --git a/content/_code-samples/secure-signing/py/sign-payment.py b/content/_code-samples/secure-signing/py/sign-payment.py new file mode 100644 index 0000000000..32fb55bbf8 --- /dev/null +++ b/content/_code-samples/secure-signing/py/sign-payment.py @@ -0,0 +1,34 @@ +from xrpl.core import keypairs + +# Define network client +from xrpl.clients import JsonRpcClient +JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" +client = JsonRpcClient(JSON_RPC_URL) + +# Define signer address +from xrpl.wallet import Wallet +test_wallet_1 = Wallet(seed="shrPSF6vV3v3yoND9J3NeKks6M3xd") +print(test_wallet_1.classic_address) # "raaFKKmgf6CRZttTVABeTcsqzRQ51bNR6Q" + +# Prepate the tranaaction +from xrpl.ledger import get_latest_validated_ledger_sequence +current_validated_ledger = get_latest_validated_ledger_sequence(client) +min_ledger = current_validated_ledger + 1 +max_ledger = min_ledger + 20 + +from xrpl.models.transactions import Payment +# not working in testing +# from xrpl.utils import xrp_to_drops +my_payment = Payment( + account=test_wallet_1.classic_address, + amount="2200000", + destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", + sequence=test_wallet_1.next_sequence_num, +) +print("Payment object:", my_payment) +print(f"Can be validated in ledger range: {min_ledger} - {max_ledger}") + +# Sign transaction ------------------------------------------------------------- +import xrpl.transaction +signed = xrpl.transaction.safe_sign_transaction(my_payment, test_wallet_1) +print("Signed transaction blob:", signed) diff --git a/content/tutorials/get-started/set-up-secure-signing.md b/content/tutorials/get-started/set-up-secure-signing.md index 2ac9a52545..e723b31527 100644 --- a/content/tutorials/get-started/set-up-secure-signing.md +++ b/content/tutorials/get-started/set-up-secure-signing.md @@ -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. -### 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: + + + +*JavaScript* ```js {% include '_code-samples/secure-signing/js/signPayment.js' %} ``` +*Python* + +```py +{% include '_code-samples/secure-signing/py/sign-payment.py' %} +``` + + + + 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][] - [submit method][] - [RippleAPI Reference](rippleapi-reference.html) + - [xrpl-py Reference](https://xrpl-py.readthedocs.io/en/latest/index.html)