【问题标题】:Since ripple-lib-java is unmaintained, how do you manually sign a transaction?由于ripple-lib-java 未维护,您如何手动签署交易?
【发布时间】:2019-12-23 14:54:40
【问题描述】:

正在寻找一种轻量级的方法来手动签署OfferCreate ...启动一些 JavaScript 引擎来完成它会很笨拙。

【问题讨论】:

    标签: kotlin cryptocurrency rippled


    【解决方案1】:

    嗯……虽然它已经 4 年没有维护了,但它看起来仍然可以工作。

    克隆 ripple-lib-java 并在 ripple-bouncycastleripple-core 中执行 mvn 安装

    然后将构建好的JAR复制到<YourProject>/libs

    在 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 :(
    }
    

    创建并签署 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)
    

    你不能在SignedTransaction 上执行toJSON() 有点烦人。它可以 不是安全问题,因为sign() 只添加公钥字段:https://xrpl.org/transaction-common-fields.html#signers-field

    【讨论】:

    • 呃……我什么时候才能学会阅读代码……signedTransaction.txn.toJSON()
    猜你喜欢
    • 2020-06-25
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多