@@ -3,12 +3,12 @@ import {
33 BaseKey ,
44 BaseTransactionBuilder ,
55 BuildTransactionError ,
6- FeeOptions ,
76 PublicKey as BasePublicKey ,
87 Signature ,
98 TransactionType ,
109} from '@bitgo/sdk-core' ;
1110import BigNumber from 'bignumber.js' ;
11+ import { KeyPair } from './keyPair' ;
1212import { Transaction } from './transaction/transaction' ;
1313import utils from './utils' ;
1414
@@ -42,21 +42,6 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
4242 this . _signatures . push ( { publicKey, signature } ) ;
4343 }
4444
45- /**
46- * Sets the sender of this transaction.
47- * This account will be responsible for paying transaction fees.
48- *
49- * @param {string } senderAddress the account that is sending this transaction
50- * @returns {TransactionBuilder } This transaction builder
51- */
52- sender ( senderAddress : string ) : this {
53- throw new Error ( 'Method not implemented.' ) ;
54- }
55-
56- fee ( feeOptions : FeeOptions ) : this {
57- throw new Error ( 'Method not implemented.' ) ;
58- }
59-
6045 /** @inheritdoc */
6146 protected fromImplementation ( rawTransaction : string ) : Transaction {
6247 throw new Error ( 'Method not implemented.' ) ;
@@ -77,17 +62,37 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
7762
7863 /** @inheritdoc */
7964 validateKey ( key : BaseKey ) : void {
80- throw new Error ( 'Method not implemented.' ) ;
65+ let keyPair : KeyPair ;
66+ try {
67+ keyPair = new KeyPair ( { prv : key . key } ) ;
68+ } catch {
69+ throw new BuildTransactionError ( 'Invalid key' ) ;
70+ }
71+ if ( ! keyPair . getKeys ( ) . prv ) {
72+ throw new BuildTransactionError ( 'Invalid key' ) ;
73+ }
8174 }
8275
8376 /** @inheritdoc */
84- validateRawTransaction ( rawTransaction : string ) : void {
85- throw new Error ( 'Method not implemented.' ) ;
77+ async validateRawTransaction ( rawTransaction : string ) : Promise < void > {
78+ if ( ! rawTransaction || ! this . _transaction . transaction ) {
79+ throw new BuildTransactionError ( 'invalid raw transaction' ) ;
80+ }
81+ const localHash = await utils . computeHashFromPreparedTransaction ( rawTransaction ) ;
82+ if ( localHash !== this . _transaction . transaction . preparedTransactionHash ) {
83+ throw new BuildTransactionError ( 'invalid raw transaction, hash not matching' ) ;
84+ }
8685 }
8786
8887 /** @inheritdoc */
89- validateTransaction ( transaction ?: Transaction ) : void {
90- throw new Error ( 'Method not implemented.' ) ;
88+ async validateTransaction ( transaction ?: Transaction ) : Promise < void > {
89+ if ( ! transaction ?. transaction ?. preparedTransaction ) {
90+ return ;
91+ }
92+ const localHash = await utils . computeHashFromPreparedTransaction ( transaction . transaction . preparedTransaction ) ;
93+ if ( localHash !== transaction . transaction . preparedTransactionHash ) {
94+ throw new BuildTransactionError ( 'invalid transaction' ) ;
95+ }
9196 }
9297
9398 /** @inheritdoc */
0 commit comments