@@ -212,3 +212,66 @@ describe('Point codec', () => {
212212 makeShortTest ( shortPointOddY )
213213 )
214214} )
215+
216+ describe ( 'JacobianPoint – Infinity handling and equality (TOB-18)' , ( ) => {
217+ function J ( x : any , y : any , z : any ) {
218+ return new JPoint ( x , y , z )
219+ }
220+
221+ it ( 'Multiple infinity representations are canonicalized and equal' , ( ) => {
222+ const inf1 = J ( null , null , null )
223+ const inf2 = J ( '0' , '0' , '0' )
224+ const inf3 = J ( new BigNumber ( 0 ) , new BigNumber ( 0 ) , new BigNumber ( 0 ) )
225+
226+ expect ( inf1 . isInfinity ( ) ) . toBe ( true )
227+ expect ( inf2 . isInfinity ( ) ) . toBe ( true )
228+ expect ( inf3 . isInfinity ( ) ) . toBe ( true )
229+
230+ expect ( inf1 . eq ( inf2 ) ) . toBe ( true )
231+ expect ( inf2 . eq ( inf3 ) ) . toBe ( true )
232+ expect ( inf1 . eq ( inf3 ) ) . toBe ( true )
233+ } )
234+
235+ it ( 'Infinity must not equal a finite point' , ( ) => {
236+ const inf = J ( null , null , null )
237+
238+ const good = J (
239+ new BigNumber ( 'e7789226' , 16 ) ,
240+ new BigNumber ( '4b76b191' , 16 ) ,
241+ new BigNumber ( 'cbf8d990' , 16 )
242+ )
243+
244+ expect ( inf . eq ( good ) ) . toBe ( false )
245+ expect ( good . eq ( inf ) ) . toBe ( false )
246+ } )
247+
248+ it ( 'Infinity equals infinity (canonicalized)' , ( ) => {
249+ const inf1 = J ( null , null , null )
250+ const inf2 = J ( '0' , '0' , '0' )
251+
252+ expect ( inf1 . eq ( inf2 ) ) . toBe ( true )
253+ expect ( inf2 . eq ( inf1 ) ) . toBe ( true )
254+ } )
255+
256+ it ( 'Infinity is detected when z is zero in RED form' , ( ) => {
257+ const redZero = new BigNumber ( 0 ) . toRed ( new Curve ( ) . red )
258+ const p = J ( '1' , '2' , redZero )
259+
260+ expect ( p . isInfinity ( ) ) . toBe ( true )
261+
262+ const clean = J ( null , null , null )
263+ expect ( p . eq ( clean ) ) . toBe ( true )
264+ expect ( clean . eq ( p ) ) . toBe ( true )
265+ } )
266+
267+ it ( 'eq() must handle mixed canonical and non-canonical infinity cases' , ( ) => {
268+ const canonical = J ( null , null , null )
269+ const messy = J ( '1' , '1' , new BigNumber ( 0 ) )
270+
271+ expect ( messy . isInfinity ( ) ) . toBe ( true )
272+ expect ( canonical . eq ( messy ) ) . toBe ( true )
273+ expect ( messy . eq ( canonical ) ) . toBe ( true )
274+ } )
275+ } )
276+
277+
0 commit comments