xumm4j v0.3.2 #19
Replies: 3 comments 3 replies
-
https://github.com/francisrosario/xumm4j - v0.2.0 is now available. package com.fl.xumm4j;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fl.xrpl4j.model.jackson.ObjectMapperFactory;
import com.fl.xrpl4j.model.transactions.Address;
import com.fl.xrpl4j.model.transactions.Payment;
import com.fl.xrpl4j.model.transactions.XrpCurrencyAmount;
import com.fl.xumm4j.dao.CuratedAssetsDAO;
import com.fl.xumm4j.sdk.XummClient;
import com.fl.xumm4j.sdk.builder.CredentialsBuilder;
import com.fl.xumm4j.sdk.builder.PayloadBuilder;
import com.fl.xumm4j.sdk.Deserialize;
import java.math.BigDecimal;
public class testMain {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper objectMapper = ObjectMapperFactory.create();
// Don't worry about this key being exposed...
// I generated it for testing, demonstration purposes. keys not being used in production env.
CredentialsBuilder myAccess = new CredentialsBuilder.builder()
.apiKey("7208fca5-4ac3-4638-b006-897dfcc0ab29")
.secretKey("6dab854e-b317-47f7-8453-490b8bd171ad")
.build();
XummClient xummClient = new XummClient(myAccess);
//Use modified version of xrpl4j model, It won't throw an error if Account and sequence are missing.
//Modified version package name starts with com.fl.xrpl4j.*
Payment payment = Payment.builder()
//.account()
//.sequence()
.fee(XrpCurrencyAmount.ofDrops(12))
.destination(Address.of("ra5nK24KXen9AHvsdFTKHSANinZseWnPcX"))
.amount(XrpCurrencyAmount.ofXrp(BigDecimal.valueOf(8787)))
.build();
String JSON = null;
try {
JSON = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(payment);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
PayloadBuilder payload = new PayloadBuilder.builder()
.txjson(JSON)
.instruction("This is a payment transaction")
.build();
System.out.println("Generated Payload: \n" + payload.getGeneratedPayload());
String Payload = payload.getGeneratedPayload();
System.out.println(Payload+"\n");
//Post payload
System.out.println(xummClient.postPayload(Payload));
System.out.println(xummClient.getRates("USD"));
System.out.println(xummClient.doPing());
System.out.println(xummClient.getCuratedAssets());
//Storage
System.out.println(xummClient.setStorage(JSON));
System.out.println(xummClient.getStorage());
System.out.println(xummClient.deleteStorage());
//KYC
System.out.println(xummClient.getKycStatus("rDWLGshgAxSX2G4TEv3gA6QhtLgiXrWQXB"));
//Get Transaction
System.out.println(xummClient.getTransaction("DA66B07C9FE0876A3447DE4C57D565FC9C5324485912D10B48C0507F191A4021"));
String jsonResponse = xummClient.getCuratedAssets();
DeserializeIT deserialize = new DeserializeIT();
//Other DAO are available under com.fl.xumm4j.dao.*
CuratedAssetsDAO result = deserialize.CuratedAssets(jsonResponse);
result.forEachCurrencies(System.out::println);
result.forEachDetails(System.out::println);
result.forEachIssuer(System.out::println);
}
} |
Beta Was this translation helpful? Give feedback.
-
Awesome job @francisrosario! Thank you so much for doing this! Let me loop in @nixer89 here, to see if is willing to do a quick code scan (test) as he's definitely more knowledgeable in Java than I a (no pressure @nixer89)! After that I'm definitely more than willing to refer to this SDK as a community contributed SDK for Java 👍 Thanks again! I'll be in touch ;) |
Beta Was this translation helpful? Give feedback.
-
thanks for tagging @WietseWind! I might give it a try in the upcoming week(s) and test the xumm4j sdk :) and awesome job already, @francisrosario! |
Beta Was this translation helpful? Give feedback.
-
This discussion is dedicated to xumm4j. I will post all progress made in xumm4j here. At the same, I'll add here some projects that utilize xumm4j. I started to build this SDK because I'm having a hard time refactoring code from one project to another that utilizes XUMM API. This SDK is very important since it will be heavily used in my NFT Marketplace and other XRPL related projects like Standalone NFT Wallet Creator...
Github:
https://github.com/francisrosario/xumm4j
Project(s) that uses xumm4j:
https://github.com/francisrosario/NFTWalletCreator_xApp-JavaEE/
XUMM SDK (Java)
Interact with the XUMM API from Java environments.
Please note! The xumm4j SDK (XUMM API in general) is for BACKEND USE only. Please DO NOT use your API credentials in a FRONTEND environment.
Installation
Use this XUMM SDK in your project by adding the following to your
pom.xml
:Optional dependecy if you want to use modified version of xrpl4j model:
How to use the xumm4j SDK
Import required class.
Now continue by creating an instance of CredentialsBuilder, XummClient, and Deserialize:
Credentials
The XummClient will look in your CredentialsBuilder Object, and It's highly recommended not to hard-code the API Key and Secret Key, You may use https://docs.oracle.com/javase/tutorial/essential/environment/env.html Environment Variables to hide your API Key and Secret Key.
Create your app and get your XUMM API credentials at the XUMM Developer Console:
More information about the XUMM API, payloads, the API workflow, sending Push notifications, etc. please check the XUMM API Docs:
Methods & params (+ samples)
For more information about the XUMM API, payloads, the API workflow, sending Push notifications, etc., please check the XUMM API Docs:
xummclient.*
for the helper methods; Along with methods to get/update payloads for users to sign.deserialize.*
for JSON deserialization.Please note all snippets below assume you created an instance of the XummClient into the
xummclient
object name and DeserializeIT into thedeserialize
object name, as the How to use the xumm4j section outlines.XummClient methods
Payloads
Payloads are the primary reason for the XUMM API (thus, this SDK) to exist. The XUMM API Docs explain 'Payloads' like this:
A payload can contain an XRPL transaction template. Some properties may be omitted, as they will be added by the XUMM app when a user signs a transaction. A simple payload may look like this:
As you can see, the payload looks like a regular XRPL transaction, wrapped in a
txjson
object, omitting the mandatoryAccount
,Fee
andSequence
properties. They will be added containing the correct values when an app user signs the payload.Optionally (besides
txjson
) a payload can contain these properties (XUMM API Postpayload):options
to define payload options like a return URL, expiration, etc.custom_meta
to add metadata, user insruction, your own unique ID, ...user_token
to push the payload to a user (after obtaining a user specific token)Instead of providing a
txjson
transaction, a transaction formatted as HEX blob (string) can be provided in atxblob
property.xummclient.getPayload
To get payload details, status and if resolved & signed: results (transaction, transaction hash, etc.) you can
.getPayload(UUID)
a payload.You can
.getPayload(UUID)
a payload by:xummclient.postPayload + PayloadBuilder + xrpl4j JSON Builder
Creating payload by using
PayloadBuilder
class and xrpl4j JSON Builder.Import the following class:
The following code constructs an Payment object, which represents an Payment Transaction:
These objects can be serialized to and deserialized from the rippled JSON representations using the provided Jackson
ObjectMapper
, which can be instantiated using ObjectMapperFactory.Using the Payment object we just created, we can use the supplied ObjectMapper to serialize to JSON:
We now can now generate the payload object by using
PayloadBuilder
class:You can also generate payload by using all of the attributes available:
By using xrpl4j JSON Builder + xumm4j PayloadBuilder we now have a payload object ready to be submmited using
.postPayload(JSON)
method.Once
.postPayload(JSON)
method is executed you'll get a response similar below:More information regarding payload For more information about payloads. Take a look at the Developer Docs for more information about payloads.
The
next.always
URL is the URL to send the end-user to, scan a QR code or automatically open the XUMM app (if on mobile). If auser_token
has been provided as part of the payload data provided topostPayload()
, you can see if the payload has been pushed to the end user. A button "didn't receive a push notification" could then take the user to thenext.no_push_msg_received
URL.Alternatively, user routing/instruction flows can be custom-built using the QR information provided in the
refs
object. There's more information about the payload workflow and a paylaod lifecycle in the Developer Docs.xummclient.deletePayload
To cancel a payload, provide a payload UUID (string), By performing a
xummclient.getPayload();
first) or a<CreatedPayload>
(by using the response of axummclient.postPayload();
call). By canceling an existing payload, the payload will be marked as expired and can no longer be opened by users.Please note: if a user already opened the payload in XUMM APP, the payload cannot be canceled: the user may still be resolving the payload in the XUMM App and should have a chance to complete that process.
xummclient.doPing
The
ping
method allows you to verify API access (valid credentials) and returns some info on your XUMM APP:Returns
<String>
:xummclient.getCuratedAssets
The
.getCuratedAssets()
method allows you to get the list of trusted issuers and IOU. This is the same list used topopulate the "Add Asset" button at the XUMM home screen.
Returns
<String>
:xummclient.getKycStatus
The
.getKycStatus(user_token)
return the KYC status of a user based on a user_token, issued after the user signed a Sign Request (from your app) before (see Payloads - Intro).If a user token specified is invalid, revoked, expired, etc., the method will always
return
NONE
, just like when a user didn't go through KYC. This is because you cannot see distinct a non-KYC'd user from an invalid token.Alternatively, KYC status can be retrieved for an XPRL account address: the address selected in XUMM when KYC was initiated.
... or using an account address:
Returns
<String>
:Notes on KYC information
true
, but an account can no longer be trusted. Eg. when account keys are compromised and a 3rd party now controls the account. While unlikely, depending on the level of trust required for your application you may want to mitigate against these kinds of fraud.xummclient.getTransaction
The
.getTransaction(txid)
method allows you to get the transaction outcome (mainnet)live from the XRP ledger, as fetched for you by the XUMM backend.
Returns
<String>
:App Storage
App Storage allows you to store a JSON object at the XUMM API platform, containing a max of 60KB of data.
Your XUMM APP storage is stored at the XUMM API backend, meaning it persists until you overwrite or delete it.
This data is private and accessible only with your API credentials. This private JSON data can be used to store credentials/config/bootstrap info / ... for your headless application (e.g., POS device).
Beta Was this translation helpful? Give feedback.
All reactions