To obtain a correct interface signature, we need to follow these 5 steps:
Construct the body parameter object correctly according to the requirements.
Concatenate the parameters of the complete body parameter object, sorted alphabetically, using '&' as a separator. For example: channel=chainge&extra=1_6495000&orderType....
Prefix the string generated in step 2 with EvmAddress=...&{result of step 2}, for example: EvmAddress=0x42a6685ef29886Cbcb595Aa903f00dea0d1787d8&channel=chainge&extra=1_6495000&orderType....
Apply keccak256 hashing to the result of step 3.
Sign the result of step 4 with the wallet.
get Signature examples:
constsortParams= (params, evmAddress) => {let keys =Object.keys(params)if(!keys.length) returnundefined keys =keys.sort();constkeyValList= []for (constkeyof keys) {constval= params[key];if(val) {keyValList.push(`${key}=${val}`) } }constdata=keyValList.join('&')constraw=`EvmAddress=${evmAddress}&${data}`return raw}// step 1constbodyParams= { channel:"chainge", extra:`1_6495000`, orderType:'1', slippage:'0', sourceCerts: sourceCerts, // 7b2266726f6d416d6f756e74223a223130303030303030222c2266726f6d496e646578223a2235222c2266726f6d436861696e223a2246534e222c2266726f6d41646472223a22307834326136363835656632393838364362636235393541613930336630306465613064313738376438222c226365727448617368223a22307834313930646334363237636234653937323932623662373138643731386433633361663933663134343737333436656663313831666635343966363966373934222c2266726f6d5075626c69634b6579223a22222c227369676e6174757265223a22313233343536227d
toChain:'ETH', toIndex:'5', toAddr:'0x42a6685ef29886Cbcb595Aa903f00dea0d1787d8', execStrategy:"", timeout:"0", triggerPrice:"0",}// step 2 & setp3let raw =sortParams(bodyParams,'0x42a6685ef29886Cbcb595Aa903f00dea0d1787d8') asstring;console.log(raw) // EvmAddress=0x42a6685ef29886Cbcb595Aa903f00dea0d1787d8&channel=chainge&extra=1_6495000&orderType=1&slippage=0&sourceCerts=7b2266726f6d416d6f756e74223a223130303030303030222c2266726f6d496e646578223a2235222c2266726f6d436861696e223a2246534e222c2266726f6d41646472223a22307834326136363835656632393838364362636235393541613930336630306465613064313738376438222c226365727448617368223a22307834313930646334363237636234653937323932623662373138643731386433633361663933663134343737333436656663313831666635343966363966373934222c2266726f6d5075626c69634b6579223a22222c227369676e6174757265223a22313233343536227d&timeout=0&toAddr=0x42a6685ef29886Cbcb595Aa903f00dea0d1787d8&toChain=ETH&toIndex=5&triggerPrice=0
// step4raw =keccak256(toHex(raw));console.log(raw) // 0x24129902c42ed3eb40c93dddfe80bf12cc44853ecbda70427dff75c0ce6d189b// step5 Calling wallet message signing// Calculates an Ethereum-specific signature in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).
// Note: The signature should not include the prefix '0x'.let signature =wallet.signMessage(raw)