@@ -20,14 +20,15 @@ import type {
20
20
AccessList , AccessListish , Authorization , AuthorizationLike
21
21
} from "./index.js" ;
22
22
23
-
24
23
const BN_0 = BigInt ( 0 ) ;
25
24
const BN_2 = BigInt ( 2 ) ;
26
25
const BN_27 = BigInt ( 27 )
27
26
const BN_28 = BigInt ( 28 )
28
27
const BN_35 = BigInt ( 35 ) ;
29
28
const BN_MAX_UINT = BigInt ( "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ) ;
30
29
30
+ const inspect = Symbol . for ( "nodejs.util.inspect.custom" ) ;
31
+
31
32
const BLOB_SIZE = 4096 * 32 ;
32
33
33
34
// 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
318
319
formatNumber ( a . nonce , "nonce" ) ,
319
320
formatNumber ( a . signature . yParity , "yParity" ) ,
320
321
toBeArray ( a . signature . r ) ,
321
- toBeArray ( a . signature . s )
322
+ toBeArray ( a . signature . _s )
322
323
] ;
323
324
} ) ;
324
325
}
@@ -434,7 +435,7 @@ function _serializeLegacy(tx: Transaction, sig: null | Signature): string {
434
435
// Add the signature
435
436
fields . push ( toBeArray ( v ) ) ;
436
437
fields . push ( toBeArray ( sig . r ) ) ;
437
- fields . push ( toBeArray ( sig . s ) ) ;
438
+ fields . push ( toBeArray ( sig . _s ) ) ;
438
439
439
440
return encodeRlp ( fields ) ;
440
441
}
@@ -895,6 +896,20 @@ export class Transaction implements TransactionLike<string> {
895
896
this . #sig = ( value == null ) ? null : Signature . from ( value ) ;
896
897
}
897
898
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
+
898
913
/**
899
914
* The access list.
900
915
*
@@ -1104,15 +1119,15 @@ export class Transaction implements TransactionLike<string> {
1104
1119
*/
1105
1120
get from ( ) : null | string {
1106
1121
if ( this . signature == null ) { return null ; }
1107
- return recoverAddress ( this . unsignedHash , this . signature ) ;
1122
+ return recoverAddress ( this . unsignedHash , this . signature . getCanonical ( ) ) ;
1108
1123
}
1109
1124
1110
1125
/**
1111
1126
* The public key of the sender, if signed. Otherwise, ``null``.
1112
1127
*/
1113
1128
get fromPublicKey ( ) : null | string {
1114
1129
if ( this . signature == null ) { return null ; }
1115
- return SigningKey . recoverPublicKey ( this . unsignedHash , this . signature ) ;
1130
+ return SigningKey . recoverPublicKey ( this . unsignedHash , this . signature . getCanonical ( ) ) ;
1116
1131
}
1117
1132
1118
1133
/**
@@ -1315,6 +1330,53 @@ export class Transaction implements TransactionLike<string> {
1315
1330
} ;
1316
1331
}
1317
1332
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
+
1318
1380
/**
1319
1381
* Create a **Transaction** from a serialized transaction or a
1320
1382
* Transaction-like object.
0 commit comments