File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -445,6 +445,10 @@ export default class Point extends BasePoint {
445445 * const encodedPointHex = aPoint.encode(true, 'hex');
446446 */
447447 encode ( compact : boolean = true , enc ?: 'hex' ) : number [ ] | string {
448+ if ( this . inf === true ) {
449+ if ( enc === 'hex' ) return '00'
450+ return [ 0x00 ]
451+ }
448452 const len = this . curve . p . byteLength ( )
449453 const x = this . getX ( ) . toArray ( 'be' , len )
450454 let res : number [ ]
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111 toBase58Check ,
1212 verifyNotNull
1313} from '../../primitives/utils'
14+ import Point from '../../primitives/Point'
1415
1516describe ( 'utils' , ( ) => {
1617 it ( 'should convert to array' , ( ) => {
@@ -359,3 +360,19 @@ describe('toUTF8 strict UTF-8 decoding (TOB-21)', () => {
359360
360361} )
361362
363+ describe ( 'Point.encode infinity handling' , ( ) => {
364+ it ( 'encodes infinity as 00 (array)' , ( ) => {
365+ const p = new Point ( null , null )
366+ expect ( p . encode ( ) ) . toEqual ( [ 0x00 ] )
367+ } )
368+
369+ it ( 'encodes infinity as 00 (hex)' , ( ) => {
370+ const p = new Point ( null , null )
371+ expect ( p . encode ( true , 'hex' ) ) . toBe ( '00' )
372+ } )
373+
374+ it ( 'does not throw for infinity' , ( ) => {
375+ const p = new Point ( null , null )
376+ expect ( ( ) => p . encode ( ) ) . not . toThrow ( )
377+ } )
378+ } )
You can’t perform that action at this time.
0 commit comments