Reputation: 508
Looking for a lightweight way to manually sign an OfferCreate
... it would be clumsy to start some JavaScript engine in order to get it done.
Upvotes: 1
Views: 182
Reputation: 508
Hmm ... even though it hasn't been maintained for 4 years it looks like it still works.
Clone ripple-lib-java
and do mvn install in ripple-bouncycastle
& ripple-core
Then copy the built JARs into <YourProject>/libs
Add local dependencies in Gradle Kotlin DSL:
repositories {
flatDir {
dirs("libs")
}
}
dependencies {
implementation(":ripple-bouncycastle-0.0.1-SNAPSHOT")
implementation(":ripple-core-0.0.1-SNAPSHOT")
runtime("org.json:json:20190722") // No newskool kotlinx-serialization here :(
}
Create & sign OfferCreate:
val offerCreate = OfferCreate()
offerCreate.account(AccountID.fromString("r3jpWpUysF4SAkUNbG4WhDZ5mAJ7rGUDx6"))
offerCreate.expiration(UInt32(get2MinExpiration()))
offerCreate.fee(Amount(BigDecimal("0.00001")))
offerCreate.flags(UInt32(0))
offerCreate.sequence(UInt32(1))
val amountXRP = BigDecimal(200)
val amountBTC = convert(amountXRP, RIPPLE_XRP, BITCOIN)
offerCreate.takerGets(Amount(amountXRP))
offerCreate.takerPays(Amount(amountBTC, Currency.fromString(BITCOIN), AccountID.fromString(BITCOIN_TRUSTED_ISSUER)))
val signedTransaction = offerCreate.sign("[***Secret***]")
println(offerCreate.toJSON())
println(signedTransaction.tx_blob)
A bit annoying that you can't do a toJSON()
on a SignedTransaction
. It can
t be a security thing, since sign()
only adds public key fields: https://xrpl.org/transaction-common-fields.html#signers-field
Upvotes: 1