Skip to content

Commit f4a16f6

Browse files
committed
Add Tutorials for Confidential Transfers
1 parent e1b969c commit f4a16f6

7 files changed

Lines changed: 721 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Confidential Transfers Code Samples
2+
3+
This directory contains code samples demonstrating how to make confidential transfers on the XRP Ledger.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Confidential Transfers Examples (Python)
2+
3+
This directory contains Python examples demonstrating how to issue Multi-Purpose Tokens (MPTs) with confidential transfer capabilities on the XRP Ledger using XLS-96.
4+
5+
## Setup
6+
7+
Install dependencies before running any examples:
8+
9+
```bash
10+
python -m venv .venv
11+
source .venv/bin/activate
12+
pip install -r requirements.txt
13+
```
14+
15+
> **Note**: xrpl-py uses the [mpt-crypto](https://github.com/XRPLF/mpt-crypto) C extension for ElGamal encryption and zero-knowledge proofs. It should be automatically compiled when installing `xrpl-py` with confidential transfer support.
16+
17+
## Issue MPT with Confidential Transfers
18+
19+
```sh
20+
python issue-mpt-confidential.py
21+
```
22+
23+
The script demonstrates the complete flow of creating an MPT with confidential transfer capabilities. It should output:
24+
25+
```sh
26+
=== Generating Accounts ===
27+
Issuer: rD3WNSDgCvjR2BV99iJwuNbWaHw79FnbAe
28+
Issuer Second Account: r37aF5y8LmnevoSazEPBxcuK9q16BxygR5
29+
Auditor: rJ8PzfXouMh9p7pu2qeYQQqNogLZw3E3ZZ
30+
31+
=== Generating ElGamal Keypairs ===
32+
Issuer ElGamal Public Key: 0235DF4B6A3B01BFD8981BB00D7BF93C45B304756E6C0B1BB90DC2C2814C9A5079
33+
Issuer Second Account ElGamal Public Key: 0229FB94F953F527D256156F628BEBF0CC0CF142210B332A7E3EAAF0239E9CA6A3
34+
Auditor ElGamal Public Key: 03DCF9E4AE3425877A8E31FECB7E0D4039E8D6C0A6DC763F8A1FE89A5B5A8C8551
35+
36+
=== Creating MPT Issuance... ===
37+
Submitting MPTokenIssuanceCreate transaction...
38+
MPT issuance created successfully!
39+
MPT Issuance ID: 0035245E850CD28DE38957CCD3AA04AB7AEE25B2F218D0BE
40+
41+
=== Registering ElGamal Keys On-Ledger... ===
42+
Submitting MPTokenIssuanceSet transaction...
43+
{
44+
"account": "rD3WNSDgCvjR2BV99iJwuNbWaHw79FnbAe",
45+
"transaction_type": "MPTokenIssuanceSet",
46+
"signing_pub_key": "",
47+
"mptoken_issuance_id": "0035245E850CD28DE38957CCD3AA04AB7AEE25B2F218D0BE",
48+
"issuer_elgamal_public_key": "0235DF4B6A3B01BFD8981BB00D7BF93C45B304756E6C0B1BB90DC2C2814C9A5079",
49+
"auditor_elgamal_public_key": "03DCF9E4AE3425877A8E31FECB7E0D4039E8D6C0A6DC763F8A1FE89A5B5A8C8551"
50+
}
51+
ElGamal keys registered successfully!
52+
53+
=== Sending public tokens to issuer second account... ===
54+
Submitting MPTokenAuthorize transaction...
55+
Issuer second account authorized CTST MPT successfully!
56+
57+
Submitting Payment transaction...
58+
Payment successful!
59+
Issuer Sent 1000 CTST tokens to r37aF5y8LmnevoSazEPBxcuK9q16BxygR5
60+
61+
=== Converting Public Balance to Confidential... ===
62+
Generating zero-knowledge proof...
63+
Encrypting amount for holder...
64+
Encrypting amount for issuer...
65+
Encrypting amount for auditor...
66+
67+
Submitting ConfidentialMPTConvert transaction...
68+
{
69+
"account": "r37aF5y8LmnevoSazEPBxcuK9q16BxygR5",
70+
"transaction_type": "ConfidentialMPTConvert",
71+
"signing_pub_key": "",
72+
"mptoken_issuance_id": "0035245E850CD28DE38957CCD3AA04AB7AEE25B2F218D0BE",
73+
"mpt_amount": 1000,
74+
"holder_encrypted_amount": "02AA26FCE527014BA9A148721074E4E2D6760399C6C3512ADD51FE14526CF259C9021C9CF39776966B2D095011296BB4D52414B8123463A619E9F7347FD11D6F72F0",
75+
"issuer_encrypted_amount": "02AA26FCE527014BA9A148721074E4E2D6760399C6C3512ADD51FE14526CF259C903E1FFED64B7F41543AF73B5F9B2B16FDD3BA8D9B477FD0993DAE84FEFCFA94032",
76+
"blinding_factor": "3E9185BC123763C3F0FA564422768C6BC42B9D1B6B0D722EA81F46347DB6CAC7",
77+
"holder_elgamal_public_key": "0229FB94F953F527D256156F628BEBF0CC0CF142210B332A7E3EAAF0239E9CA6A3",
78+
"auditor_encrypted_amount": "02AA26FCE527014BA9A148721074E4E2D6760399C6C3512ADD51FE14526CF259C9029901F33957FD0DEC77DCF25E96E7EDDDC24AA7AE533398CA119297421B97343D",
79+
"zk_proof": "02DD6A920AA90AA91500D04757D2E51F788F2F751FCABF3698E969606741D206F66C36C37DE4BAAF6EEF423F0C7D08AFE8DB382314C041755B999AB1223435E6AF"
80+
}
81+
Conversion successful!
82+
Converted 1000 CTST tokens to confidential balance.
83+
84+
=== Merging Inbox into Spending Balance... ===
85+
Submitting ConfidentialMPTMergeInbox transaction...
86+
{
87+
"account": "r37aF5y8LmnevoSazEPBxcuK9q16BxygR5",
88+
"transaction_type": "ConfidentialMPTMergeInbox",
89+
"signing_pub_key": "",
90+
"mptoken_issuance_id": "0035245E850CD28DE38957CCD3AA04AB7AEE25B2F218D0BE"
91+
}
92+
Merge successful!
93+
94+
=== Verifying Confidential Balances ===
95+
Querying issuer second account's MPToken object...
96+
97+
Issuer second account MPToken object:
98+
{
99+
"Account": "r37aF5y8LmnevoSazEPBxcuK9q16BxygR5",
100+
"AuditorEncryptedBalance": "02AA26FCE527014BA9A148721074E4E2D6760399C6C3512ADD51FE14526CF259C9029901F33957FD0DEC77DCF25E96E7EDDDC24AA7AE533398CA119297421B97343D",
101+
"ConfidentialBalanceInbox": "03CE04EA1FC44C65E9DE022DCD08B9DDDFA881922909C2A080E7171CF8574D9A2003F481D7BBAB214E638BE548588B71F7E280EE64C8EFD0424D80FCF5640DBB1A68",
102+
"ConfidentialBalanceSpending": "02595D92B73CD0A7DDB5D81B5BAF668C5367DDAF499AD8D0EF556D3526AA2FE5A90247149548FF9B26862AB9D980D2ED0AFE5E2B6F940623B1EA97C2868F2E05CAF4",
103+
"ConfidentialBalanceVersion": 1,
104+
"Flags": 0,
105+
"HolderElGamalPublicKey": "0229FB94F953F527D256156F628BEBF0CC0CF142210B332A7E3EAAF0239E9CA6A3",
106+
"IssuerEncryptedBalance": "02AA26FCE527014BA9A148721074E4E2D6760399C6C3512ADD51FE14526CF259C903E1FFED64B7F41543AF73B5F9B2B16FDD3BA8D9B477FD0993DAE84FEFCFA94032",
107+
"LedgerEntryType": "MPToken",
108+
"MPTokenIssuanceID": "0035245E850CD28DE38957CCD3AA04AB7AEE25B2F218D0BE",
109+
"OwnerNode": "0",
110+
"PreviousTxnID": "1826376084C31D89B90946306E0D70D0557C6B404DBE4356675269F6660B5432",
111+
"PreviousTxnLgrSeq": 3482748,
112+
"index": "5398F35AA4EA52AA0AC10C3A5A067C85FF70F8131921BE8678C9673D6EC5F1F9"
113+
}
114+
115+
=== Saving Keys for Development ===
116+
Keys and issuance data saved to confidential-setup.json
117+
```

0 commit comments

Comments
 (0)