@@ -233,6 +233,23 @@ describe('ALGO:', function () {
233233 explain . outputs [ 0 ] . amount . should . equal ( amount . toString ( ) ) ;
234234 explain . outputs [ 0 ] . address . should . equal ( destination ) ;
235235 } ) ;
236+
237+ it ( 'should surface the rekey target when explaining a transfer transaction that rekeys the account' , async function ( ) {
238+ const sender = AlgoResources . accounts . account1 . address ;
239+ const destination = AlgoResources . accounts . account2 . address ;
240+ const rekeyAddress = AlgoResources . accounts . account3 . address ;
241+ const txBuilder = buildBaseTransferTransaction ( { sender, destination, amount : 10000 } ) ;
242+ txBuilder . reKeyTo ( { address : rekeyAddress } ) ;
243+ const unsignedTransaction = await txBuilder . build ( ) ;
244+ const unsignedHex = Buffer . from ( unsignedTransaction . toBroadcastFormat ( ) ) . toString ( 'hex' ) ;
245+ const explain = await basecoin . explainTransaction ( {
246+ txHex : unsignedHex ,
247+ feeInfo : { fee : '1000' } ,
248+ } ) ;
249+ explain . reKeyTo . should . equal ( rekeyAddress ) ;
250+ explain . displayOrder . should . containEql ( 'reKeyTo' ) ;
251+ explain . outputs [ 0 ] . address . should . equal ( destination ) ;
252+ } ) ;
236253 } ) ;
237254
238255 describe ( 'Asset Transfer Builder: ' , ( ) => {
@@ -349,6 +366,23 @@ describe('ALGO:', function () {
349366 explain . outputs [ 0 ] . address . should . equal ( destination ) ;
350367 explain . tokenId . should . equal ( 1 ) ;
351368 } ) ;
369+
370+ it ( 'should surface the rekey target when explaining an asset transfer transaction that rekeys the account' , async function ( ) {
371+ const sender = AlgoResources . accounts . account1 . address ;
372+ const destination = AlgoResources . accounts . account2 . address ;
373+ const rekeyAddress = AlgoResources . accounts . account3 . address ;
374+ const txBuilder = buildBaseAssetTransferTransaction ( { sender, destination, amount : 10000 , tokenId : 1 } ) ;
375+ txBuilder . reKeyTo ( { address : rekeyAddress } ) ;
376+ const unsignedTransaction = await txBuilder . build ( ) ;
377+ const unsignedHex = Buffer . from ( unsignedTransaction . toBroadcastFormat ( ) ) . toString ( 'hex' ) ;
378+ const explain = await basecoin . explainTransaction ( {
379+ txHex : unsignedHex ,
380+ feeInfo : { fee : '1000' } ,
381+ } ) ;
382+ explain . reKeyTo . should . equal ( rekeyAddress ) ;
383+ explain . displayOrder . should . containEql ( 'reKeyTo' ) ;
384+ explain . outputs [ 0 ] . address . should . equal ( destination ) ;
385+ } ) ;
352386 } ) ;
353387
354388 describe ( 'Wallet Init Builder: ' , ( ) => {
@@ -648,6 +682,62 @@ describe('ALGO:', function () {
648682 } ) ;
649683 signed . txHex . should . equal ( AlgoResources . rawTx . transfer . multisig ) ;
650684 } ) ;
685+
686+ it ( 'should refuse to sign a transaction that rekeys the account' , async function ( ) {
687+ const factory = new TransactionBuilderFactory ( coins . get ( 'algo' ) ) ;
688+ const txBuilder = factory
689+ . getTransferBuilder ( )
690+ . sender ( { address : AlgoResources . accounts . account1 . address } )
691+ . to ( { address : AlgoResources . accounts . account2 . address } )
692+ . amount ( 10000 )
693+ . isFlatFee ( true )
694+ . fee ( { fee : '1000' } )
695+ . firstRound ( 1 )
696+ . lastRound ( 100 )
697+ . testnet ( ) ;
698+ txBuilder . reKeyTo ( { address : AlgoResources . accounts . account3 . address } ) ;
699+ const unsignedTx = await txBuilder . build ( ) ;
700+ const unsignedHex = Buffer . from ( unsignedTx . toBroadcastFormat ( ) ) . toString ( 'hex' ) ;
701+
702+ await basecoin
703+ . signTransaction ( {
704+ txPrebuild : {
705+ txHex : unsignedHex ,
706+ keys : [ AlgoResources . accounts . account1 . pubKey . toString ( 'hex' ) ] ,
707+ addressVersion : 1 ,
708+ } ,
709+ prv : AlgoResources . accounts . account1 . prvKey ,
710+ } )
711+ . should . be . rejectedWith ( / r e f u s i n g t o s i g n u n l e s s t h e r e k e y i s c o n f i r m e d i n t e n t i o n a l / ) ;
712+ } ) ;
713+
714+ it ( 'should sign a transaction that rekeys the account when the rekey is explicitly allowed' , async function ( ) {
715+ const factory = new TransactionBuilderFactory ( coins . get ( 'algo' ) ) ;
716+ const txBuilder = factory
717+ . getTransferBuilder ( )
718+ . sender ( { address : AlgoResources . accounts . account1 . address } )
719+ . to ( { address : AlgoResources . accounts . account2 . address } )
720+ . amount ( 10000 )
721+ . isFlatFee ( true )
722+ . fee ( { fee : '1000' } )
723+ . firstRound ( 1 )
724+ . lastRound ( 100 )
725+ . testnet ( ) ;
726+ txBuilder . reKeyTo ( { address : AlgoResources . accounts . account3 . address } ) ;
727+ const unsignedTx = await txBuilder . build ( ) ;
728+ const unsignedHex = Buffer . from ( unsignedTx . toBroadcastFormat ( ) ) . toString ( 'hex' ) ;
729+
730+ const signed = await basecoin . signTransaction ( {
731+ txPrebuild : {
732+ txHex : unsignedHex ,
733+ keys : [ AlgoResources . accounts . account1 . pubKey . toString ( 'hex' ) ] ,
734+ addressVersion : 1 ,
735+ } ,
736+ prv : AlgoResources . accounts . account1 . prvKey ,
737+ allowReKeyTo : true ,
738+ } ) ;
739+ assert . strictEqual ( typeof signed . txHex , 'string' ) ;
740+ } ) ;
651741 } ) ;
652742
653743 describe ( 'Sign message' , ( ) => {
0 commit comments