@@ -139,6 +139,66 @@ class TokenHolder {
139139 return executeRuleCallPrefix ;
140140 }
141141
142+ /**
143+ * It is used to get call prefix of executeRedeem method in TokenHolder contract.
144+ *
145+ * @returns {string } Encoded signature of executeRedeem method.
146+ */
147+ getTokenHolderExecuteRedemptionCallPrefix ( ) {
148+ const executeRedeemHash = this . auxiliaryWeb3 . utils . soliditySha3 (
149+ 'executeRedemption(address,bytes,uint256,bytes32,bytes32,uint8)'
150+ ) ;
151+ const executeRedeemCallPrefix = executeRedeemHash . substring ( 0 , 10 ) ;
152+ return executeRedeemCallPrefix ;
153+ }
154+
155+ /**
156+ * Executable data for co-gateway redeem.
157+ *
158+ * @param amount Redeem amount that will be transferred from redeemer account.
159+ * @param beneficiary The address in the origin chain where the value tokens will be released.
160+ * @param gasPrice Gas price that redeemer is ready to pay to get the redeem process done.
161+ * @param gasLimit Gas limit that redeemer is ready to pay.
162+ * @param nonce Nonce of the redeemer address.
163+ * @param hashLock Hash Lock provided by the facilitator.
164+ * @returns {* }
165+ */
166+ getCoGatewayRedeemExecutableData ( amount , beneficiary , gasPrice , gasLimit , nonce , hashLock ) {
167+ return this . auxiliaryWeb3 . eth . abi . encodeFunctionCall (
168+ {
169+ name : 'redeem' ,
170+ type : 'function' ,
171+ inputs : [
172+ {
173+ type : 'uint256' ,
174+ name : 'amount'
175+ } ,
176+ {
177+ type : 'address' ,
178+ name : 'beneficiary'
179+ } ,
180+ {
181+ type : 'uint256' ,
182+ name : 'gasPrice'
183+ } ,
184+ {
185+ type : 'uint256' ,
186+ name : 'gasLimit'
187+ } ,
188+ {
189+ type : 'uint256' ,
190+ name : 'nonce'
191+ } ,
192+ {
193+ type : 'bytes32' ,
194+ name : 'hashlock'
195+ }
196+ ]
197+ } ,
198+ [ amount , beneficiary , gasPrice , gasLimit , nonce , hashLock ]
199+ ) ;
200+ }
201+
142202 /**
143203 * It is used to execute executable data signed by a session key.
144204 *
@@ -193,6 +253,60 @@ class TokenHolder {
193253 return Promise . resolve ( this . contract . methods . executeRule ( to , data , nonce , r , s , v ) ) ;
194254 }
195255
256+ /**
257+ * It is used to execute redeem data signed by a session key.
258+ *
259+ * @param {string } to The target contract address the transaction will be executed upon.
260+ * @param {string } data The payload of a function to be executed in the target contract.
261+ * @param {string } nonce The nonce of an session key that was used to sign the transaction.
262+ * @param {string } r `r` part of the signature.
263+ * @param {string } s `s` part of the signature.
264+ * @param {string } v `v` part of the signature.
265+ * @param {Object } txOptions Tx options.
266+ *
267+ * @returns {Promise<Object> } Promise that resolves to transaction receipt.
268+ */
269+ async executeRedemption ( to , data , nonce , r , s , v , txOptions ) {
270+ if ( ! txOptions ) {
271+ const err = new TypeError ( 'Invalid transaction options.' ) ;
272+ return Promise . reject ( err ) ;
273+ }
274+ if ( ! Web3 . utils . isAddress ( txOptions . from ) ) {
275+ const err = new TypeError ( `Invalid from address: ${ txOptions . from } .` ) ;
276+ return Promise . reject ( err ) ;
277+ }
278+ const txObject = await this . executeRedemptionRawTx ( to , data , nonce , r , s , v ) ;
279+ return Utils . sendTransaction ( txObject , txOptions ) ;
280+ }
281+
282+ /**
283+ * Private method which is used to execute redeem data signed by a session key.
284+ *
285+ * @param {string } to The target contract address the transaction will be executed upon.
286+ * @param {string } data The payload of a function to be executed in the target contract.
287+ * @param {string } nonce The nonce of an session key that was used to sign the transaction.
288+ * @param {string } r `r` part of the signature signed by sessionKey.
289+ * @param {string } s `s` part of the signature signed by sessionKey.
290+ * @param {string } v `v` part of the signature signed by sessionKey.
291+ *
292+ * @returns {Promise<Object> } Promise that resolves to raw transaction object.
293+ */
294+ executeRedemptionRawTx ( to , data , nonce , r , s , v ) {
295+ if ( ! Web3 . utils . isAddress ( to ) ) {
296+ const err = new TypeError ( `Invalid to address: ${ to } .` ) ;
297+ return Promise . reject ( err ) ;
298+ }
299+ if ( ! data ) {
300+ const err = new TypeError ( `Invalid data: ${ data } .` ) ;
301+ return Promise . reject ( err ) ;
302+ }
303+ if ( ! nonce ) {
304+ const err = new TypeError ( `Invalid nonce: ${ nonce } .` ) ;
305+ return Promise . reject ( err ) ;
306+ }
307+ return Promise . resolve ( this . contract . methods . executeRedemption ( to , data , nonce , r , s , v ) ) ;
308+ }
309+
196310 /**
197311 * It returns the session key data object.
198312 *
0 commit comments