@@ -43,7 +43,7 @@ class IlpV4 extends IlpBase {
4343 * @returns {IlpResponse } - object containing the fulfilment, condition and ilp packet (v4)
4444 */
4545 getResponseIlp ( transactionObject ) {
46- const fulfilment = this . calculateFulfil ( transactionObject ) ;
46+ const fulfilment = this . #calculateFulfilFromTransactionObject ( transactionObject ) ;
4747 const condition = super . calculateConditionFromFulfil ( fulfilment ) ;
4848 const ilpPacket = this . calculateIlpPacket ( transactionObject , condition ) ;
4949
@@ -57,6 +57,17 @@ class IlpV4 extends IlpBase {
5757 return result ;
5858 }
5959
60+ /**
61+ * Calculates a fulfilment given a base64 encoded ilp packet
62+ *
63+ * @returns {string } - string containing base64 encoded fulfilment
64+ */
65+ calculateFulfil ( base64EncodedPacket ) {
66+ const transactionObject = this . getTransactionObject ( base64EncodedPacket ) ;
67+ const { fulfilment } = this . getResponseIlp ( transactionObject ) ;
68+ return fulfilment ;
69+ }
70+
6071 /**
6172 * @typedef {Object } IlpInputV4
6273 * @prop {String } amount - Transfer amount.
@@ -110,18 +121,6 @@ class IlpV4 extends IlpBase {
110121 return ILP_ADDRESS ;
111122 }
112123
113- /**
114- * Calculates a fulfilment given a transaction object and a secret
115- *
116- * @returns {string } - string containing base64 encoded fulfilment
117- */
118- calculateFulfil ( transactionObject ) {
119- const base64EncodedTransaction = Buffer . from ( safeStringify ( transactionObject ) ) . toString ( 'base64' ) ;
120- const encodedSecret = Buffer . from ( this . secret ) . toString ( 'base64' ) ;
121-
122- return super . _createHmac ( base64EncodedTransaction , encodedSecret ) ;
123- }
124-
125124 calculateIlpPacket ( transactionObject , condition ) {
126125 const packetInput = this . makeQuotePacketInput ( transactionObject , condition ) ;
127126 const packet = ilpPacket . serializeIlpPrepare ( packetInput ) ;
@@ -138,6 +137,18 @@ class IlpV4 extends IlpBase {
138137 const binaryPacket = Buffer . from ( inputIlpPacket , 'base64' ) ;
139138 return ilpPacket . deserializeIlpPrepare ( binaryPacket ) ;
140139 }
140+
141+ /**
142+ * Calculates a fulfilment given a transaction object and a secret
143+ *
144+ * @returns {string } - string containing base64 encoded fulfilment
145+ */
146+ #calculateFulfilFromTransactionObject( transactionObject ) {
147+ const base64EncodedTransaction = Buffer . from ( safeStringify ( transactionObject ) ) . toString ( 'base64' ) ;
148+ const encodedSecret = Buffer . from ( this . secret ) . toString ( 'base64' ) ;
149+
150+ return super . _createHmac ( base64EncodedTransaction , encodedSecret ) ;
151+ }
141152}
142153
143154module . exports = IlpV4 ;
0 commit comments