File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ export class Utils implements BaseUtils {
4343
4444 /** @inheritdoc */
4545 isValidPublicKey ( key : string ) : boolean {
46+ key = this . stripHexPrefix ( key ) ;
4647 return isValidEd25519PublicKey ( key ) ;
4748 }
4849
@@ -102,6 +103,15 @@ export class Utils implements BaseUtils {
102103 castToNumber ( value : bigint ) : number {
103104 return new BigNumber ( value . toString ( ) ) . toNumber ( ) ;
104105 }
106+
107+ /**
108+ * Strip hex prefix
109+ * @param str
110+ * @returns hex string without 0x prefix
111+ */
112+ stripHexPrefix ( str : string ) : string {
113+ return str . replace ( / ^ 0 x / i, '' ) ;
114+ }
105115}
106116
107117const utils = new Utils ( ) ;
Original file line number Diff line number Diff line change @@ -64,6 +64,13 @@ describe('APT:', function () {
6464 tapt . getBaseFactor ( ) . should . equal ( 1e8 ) ;
6565 } ) ;
6666
67+ it ( 'is valid pub' , function ( ) {
68+ // with 0x prefix
69+ basecoin . isValidPub ( '0x9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07' ) . should . equal ( true ) ;
70+ // without 0x prefix
71+ basecoin . isValidPub ( '9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07' ) . should . equal ( true ) ;
72+ } ) ;
73+
6774 describe ( 'Verify transaction: ' , ( ) => {
6875 it ( 'should succeed to verify transaction' , async function ( ) {
6976 const txPrebuild = newTxPrebuild ( ) ;
Original file line number Diff line number Diff line change @@ -36,4 +36,16 @@ describe('Aptos util library', function () {
3636 should . throws ( ( ) => utils . deserializeSignedTransaction ( testData . INVALID_TRANSFER ) ) ;
3737 } ) ;
3838 } ) ;
39+
40+ it ( 'strip hex prefix' , function ( ) {
41+ const s = utils . stripHexPrefix ( '0x9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07' ) ;
42+ should . equal ( s , '9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07' ) ;
43+ } ) ;
44+
45+ it ( 'is valid public key' , function ( ) {
46+ // with 0x prefix
47+ should . equal ( true , utils . isValidPublicKey ( '0x9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07' ) ) ;
48+ // without 0x prefix
49+ should . equal ( true , utils . isValidPublicKey ( '9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07' ) ) ;
50+ } ) ;
3951} ) ;
You can’t perform that action at this time.
0 commit comments