@@ -20,14 +20,15 @@ import type {
2020 AccessList , AccessListish , Authorization , AuthorizationLike
2121} from "./index.js" ;
2222
23-
2423const BN_0 = BigInt ( 0 ) ;
2524const BN_2 = BigInt ( 2 ) ;
2625const BN_27 = BigInt ( 27 )
2726const BN_28 = BigInt ( 28 )
2827const BN_35 = BigInt ( 35 ) ;
2928const BN_MAX_UINT = BigInt ( "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ) ;
3029
30+ const inspect = Symbol . for ( "nodejs.util.inspect.custom" ) ;
31+
3132const BLOB_SIZE = 4096 * 32 ;
3233
3334// The BLS Modulo; each field within a BLOb must be less than this
@@ -318,7 +319,7 @@ function formatAuthorizationList(value: Array<Authorization>): Array<Array<strin
318319 formatNumber ( a . nonce , "nonce" ) ,
319320 formatNumber ( a . signature . yParity , "yParity" ) ,
320321 toBeArray ( a . signature . r ) ,
321- toBeArray ( a . signature . s )
322+ toBeArray ( a . signature . _s )
322323 ] ;
323324 } ) ;
324325}
@@ -434,7 +435,7 @@ function _serializeLegacy(tx: Transaction, sig: null | Signature): string {
434435 // Add the signature
435436 fields . push ( toBeArray ( v ) ) ;
436437 fields . push ( toBeArray ( sig . r ) ) ;
437- fields . push ( toBeArray ( sig . s ) ) ;
438+ fields . push ( toBeArray ( sig . _s ) ) ;
438439
439440 return encodeRlp ( fields ) ;
440441}
@@ -895,6 +896,20 @@ export class Transaction implements TransactionLike<string> {
895896 this . #sig = ( value == null ) ? null : Signature . from ( value ) ;
896897 }
897898
899+ isValid ( ) : boolean {
900+ const sig = this . signature ;
901+ if ( sig && ! sig . isValid ( ) ) { return false ; }
902+
903+ const auths = this . authorizationList ;
904+ if ( auths ) {
905+ for ( const auth of auths ) {
906+ if ( ! auth . signature . isValid ( ) ) { return false ; }
907+ }
908+ }
909+
910+ return true ;
911+ }
912+
898913 /**
899914 * The access list.
900915 *
@@ -1104,15 +1119,15 @@ export class Transaction implements TransactionLike<string> {
11041119 */
11051120 get from ( ) : null | string {
11061121 if ( this . signature == null ) { return null ; }
1107- return recoverAddress ( this . unsignedHash , this . signature ) ;
1122+ return recoverAddress ( this . unsignedHash , this . signature . getCanonical ( ) ) ;
11081123 }
11091124
11101125 /**
11111126 * The public key of the sender, if signed. Otherwise, ``null``.
11121127 */
11131128 get fromPublicKey ( ) : null | string {
11141129 if ( this . signature == null ) { return null ; }
1115- return SigningKey . recoverPublicKey ( this . unsignedHash , this . signature ) ;
1130+ return SigningKey . recoverPublicKey ( this . unsignedHash , this . signature . getCanonical ( ) ) ;
11161131 }
11171132
11181133 /**
@@ -1315,6 +1330,53 @@ export class Transaction implements TransactionLike<string> {
13151330 } ;
13161331 }
13171332
1333+ [ inspect ] ( ) : string {
1334+ return this . toString ( ) ;
1335+ }
1336+
1337+ toString ( ) : string {
1338+ const output : Array < string > = [ ] ;
1339+ const add = ( key : string ) => {
1340+ let value = ( < any > this ) [ key ] ;
1341+ if ( typeof ( value ) === "string" ) { value = JSON . stringify ( value ) ; }
1342+ output . push ( `${ key } : ${ value } ` ) ;
1343+ } ;
1344+
1345+ if ( this . type ) { add ( "type" ) ; }
1346+ add ( "to" ) ;
1347+ add ( "data" ) ;
1348+ add ( "nonce" ) ;
1349+ add ( "gasLimit" ) ;
1350+ add ( "value" ) ;
1351+ if ( this . chainId != null ) { add ( "chainId" ) ; }
1352+ if ( this . signature ) {
1353+ add ( "from" ) ;
1354+ output . push ( `signature: ${ this . signature . toString ( ) } ` ) ;
1355+ }
1356+
1357+ // @TODO : accessList
1358+
1359+ // @TODO : blobs (might make output huge; maybe just include a flag?)
1360+
1361+ const auths = this . authorizationList ;
1362+ if ( auths ) {
1363+ const outputAuths : Array < string > = [ ] ;
1364+ for ( const auth of auths ) {
1365+ const o : Array < string > = [ ] ;
1366+ o . push ( `address: ${ JSON . stringify ( auth . address ) } ` ) ;
1367+ if ( auth . nonce != null ) { o . push ( `nonce: ${ auth . nonce } ` ) ; }
1368+ if ( auth . chainId != null ) { o . push ( `chainId: ${ auth . chainId } ` ) ; }
1369+ if ( auth . signature ) {
1370+ o . push ( `signature: ${ auth . signature . toString ( ) } ` ) ;
1371+ }
1372+ outputAuths . push ( `Authorization { ${ o . join ( ", " ) } }` ) ;
1373+ }
1374+ output . push ( `authorizations: [ ${ outputAuths . join ( ", " ) } ]` ) ;
1375+ }
1376+
1377+ return `Transaction { ${ output . join ( ", " ) } }` ;
1378+ }
1379+
13181380 /**
13191381 * Create a **Transaction** from a serialized transaction or a
13201382 * Transaction-like object.
0 commit comments