XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

ValidationError(instance.escrowCreation.condition does not match pattern "^[A-F0-9]{0,256}$") #953

Closed surferwat closed 5 years ago

surferwat commented 5 years ago

Hi!

After I send a conditional escrowCreation transaction to the XRP Test Net Faucet via the RippleAPI, I get the following error message: [ValidationError(instance.escrowCreation.condition does not match pattern "^[A-F0-9]{0,256}$")]

It looks like the pattern only accepts upper case letters, but the condition generated using five-bells-conditions includes lower case ones. Should the condition only include upper case letters? Or should the pattern be changed to allow for lower case letters? Thank you.

Additional details:

I am using the Crypto-Conditions library, five-bells-condition to calculate a condition as shown in the code block below which is based off of the example provided here: https://developers.ripple.com/send-a-conditionally-held-escrow.html

// Generate crypto conditions
const fulfillment_bytes = crypto.randomBytes(32);
const myFulfillment = new cc.PreimageSha256();
myFulfillment.setPreimage(fulfillment_bytes);

// (Random hexadecimal, 78 chars in length)
const condition = myFulfillment.getConditionBinary().toString('hex');

The string condition generated and used in defining the escrow is as follows: a025802086f3a3d870e4060905f5cfffc2c6c256e62ce610971bb634bd25f83408b54a60810120

intelliot commented 5 years ago

@surferwat The condition should only include upper case letters, although it's actually just a hexadecimal representation of the data. You should convert the string to uppercase with .toUpperCase():

const condition = myFulfillment.getConditionBinary().toString('hex').toUpperCase();

// keep secret until you want to finish executing the held payment:
const fulfillment = myFulfillment.serializeBinary().toString('hex').toUpperCase();

(Aside from prepareEscrowCreation's validation, ripple-lib's sign method relies on ripple-binary-codec, which does not recognize lowercase letters for the hex representation.)

surferwat commented 5 years ago

Got it. Thank you.