@@ -15,6 +15,7 @@ import {
1515 Ed25519PublicKey ,
1616 Ed25519Signature ,
1717 generateUserTransactionHash ,
18+ Hex ,
1819 RawTransaction ,
1920 SignedTransaction ,
2021 SimpleTransaction ,
@@ -26,6 +27,7 @@ import utils from '../utils';
2627export abstract class Transaction extends BaseTransaction {
2728 protected _rawTransaction : RawTransaction ;
2829 protected _signature : Signature ;
30+ public txRecipient : TransactionRecipient ; //TODO: check and fix - layering, and usage.
2931
3032 static DEFAULT_PUBLIC_KEY = Buffer . alloc ( 32 ) ;
3133 static DEFAULT_SIGNATURE = Buffer . alloc ( 64 ) ;
@@ -86,7 +88,7 @@ export abstract class Transaction extends BaseTransaction {
8688 let publicKeyBuffer = Transaction . DEFAULT_PUBLIC_KEY ;
8789 let signatureBuffer = Transaction . DEFAULT_SIGNATURE ;
8890 if ( this . _signature && this . _signature . publicKey && this . _signature . signature ) {
89- publicKeyBuffer = Buffer . from ( this . _signature . publicKey . pub , 'hex' ) ;
91+ publicKeyBuffer = Buffer . from ( Hex . fromHexString ( this . _signature . publicKey . pub ) . toUint8Array ( ) ) ;
9092 signatureBuffer = this . _signature . signature ;
9193 }
9294 const publicKey = new Ed25519PublicKey ( publicKeyBuffer ) ;
@@ -103,7 +105,6 @@ export abstract class Transaction extends BaseTransaction {
103105 if ( ! Transaction . DEFAULT_PUBLIC_KEY . equals ( publicKeyBuffer ) && ! Transaction . DEFAULT_SIGNATURE . equals ( signature ) ) {
104106 this . _signatures . push ( signature . toString ( 'hex' ) ) ;
105107 this . _signature = { publicKey, signature } ;
106- this . serialize ( ) ;
107108 }
108109 }
109110
@@ -119,18 +120,18 @@ export abstract class Transaction extends BaseTransaction {
119120 }
120121
121122 loadInputsAndOutputs ( ) : void {
122- const txRecipient = this . recipient ;
123+ this . txRecipient = this . recipient ;
123124 this . _inputs = [
124125 {
125126 address : this . sender ,
126- value : txRecipient . amount as string ,
127+ value : this . txRecipient . amount as string ,
127128 coin : this . _coinConfig . name ,
128129 } ,
129130 ] ;
130131 this . _outputs = [
131132 {
132- address : txRecipient . address ,
133- value : txRecipient . amount as string ,
133+ address : this . txRecipient . address ,
134+ value : this . txRecipient . amount as string ,
134135 coin : this . _coinConfig . name ,
135136 } ,
136137 ] ;
@@ -144,9 +145,8 @@ export abstract class Transaction extends BaseTransaction {
144145 this . loadInputsAndOutputs ( ) ;
145146
146147 const authenticator = signedTxn . authenticator as TransactionAuthenticatorEd25519 ;
147- const publicKey = Buffer . from ( authenticator . public_key . toUint8Array ( ) ) ;
148148 const signature = Buffer . from ( authenticator . signature . toUint8Array ( ) ) ;
149- this . addSignature ( { pub : publicKey . toString ( ) } , signature ) ;
149+ this . addSignature ( { pub : authenticator . public_key . toString ( ) } , signature ) ;
150150 } catch ( e ) {
151151 console . error ( 'invalid raw transaction' , e ) ;
152152 throw new Error ( 'invalid raw transaction' ) ;
@@ -155,6 +155,7 @@ export abstract class Transaction extends BaseTransaction {
155155
156156 /** @inheritDoc */
157157 explainTransaction ( ) : TransactionExplanation {
158+ //TODO: explain transaction to take input as params then take build txn and return the explanation
158159 const displayOrder = [ 'id' , 'outputs' , 'outputAmount' , 'changeOutputs' , 'changeAmount' , 'fee' , 'withdrawAmount' ] ;
159160
160161 const outputs : TransactionRecipient [ ] = [ this . recipient ] ;
0 commit comments