@@ -32,7 +32,8 @@ const encoded = [
3232 [ 'base64pad' , 'MRGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchIQ==' ] ,
3333 [ 'base64url' , 'uRGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchIQ' ] ,
3434 [ 'base64urlpad' , 'URGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchIQ==' ] ,
35- [ 'base256emoji' , '🚀💛✋💃✋😻😈🥺🤤🍀🌟💐✋😅✋💦✋🥺🏃😈😴🌟😻😝👏👏' ]
35+ [ 'base256emoji' , '🚀💛✋💃✋😻😈🥺🤤🍀🌟💐✋😅✋💦✋🥺🏃😈😴🌟😻😝👏👏' ] ,
36+ [ 'proquint' , 'pro-hidoj-katoj-kunuh-lanod-kudon-lonoj-fadoj-linoj-lanun-lidom-kojov-kisod-fah' ]
3637 ]
3738 } ,
3839 {
@@ -62,7 +63,8 @@ const encoded = [
6263 [ 'base64pad' , 'MeWVzIG1hbmkgIQ==' ] ,
6364 [ 'base64url' , 'ueWVzIG1hbmkgIQ' ] ,
6465 [ 'base64urlpad' , 'UeWVzIG1hbmkgIQ==' ] ,
65- [ 'base256emoji' , '🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ]
66+ [ 'base256emoji' , '🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ] ,
67+ [ 'proquint' , 'pro-lojoj-lasob-kujod-kunon-fabod' ]
6668 ]
6769 } ,
6870 {
@@ -92,7 +94,8 @@ const encoded = [
9294 [ 'base64pad' , 'MaGVsbG8gd29ybGQ=' ] ,
9395 [ 'base64url' , 'uaGVsbG8gd29ybGQ' ] ,
9496 [ 'base64urlpad' , 'UaGVsbG8gd29ybGQ=' ] ,
95- [ 'base256emoji' , '🚀😴✋🍀🍀😓😅✔😓🥺🍀😳' ]
97+ [ 'base256emoji' , '🚀😴✋🍀🍀😓😅✔😓🥺🍀😳' ] ,
98+ [ 'proquint' , 'pro-kodoj-kudos-kusob-litoz-lanos-kib' ]
9699 ]
97100 } ,
98101 {
@@ -122,7 +125,8 @@ const encoded = [
122125 [ 'base64pad' , 'MAHllcyBtYW5pICE=' ] ,
123126 [ 'base64url' , 'uAHllcyBtYW5pICE' ] ,
124127 [ 'base64urlpad' , 'UAHllcyBtYW5pICE=' ] ,
125- [ 'base256emoji' , '🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ]
128+ [ 'base256emoji' , '🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ] ,
129+ [ 'proquint' , 'pro-badun-kijug-fadot-kajov-kohob-fah' ]
126130 ]
127131 } ,
128132 {
@@ -152,13 +156,30 @@ const encoded = [
152156 [ 'base64pad' , 'MAAB5ZXMgbWFuaSAh' ] ,
153157 [ 'base64url' , 'uAAB5ZXMgbWFuaSAh' ] ,
154158 [ 'base64urlpad' , 'UAAB5ZXMgbWFuaSAh' ] ,
155- [ 'base256emoji' , '🚀🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ]
159+ [ 'base256emoji' , '🚀🚀🚀🏃✋🌈😅🌷🤤😻🌟😅👏' ] ,
160+ [ 'proquint' , 'pro-babab-lojoj-lasob-kujod-kunon-fabod' ]
156161 ]
157162 } ,
163+
164+ // RFC9285 examples
158165 { input : 'AB' , tests : [ [ 'base45' , 'RBB8' ] ] } ,
159166 { input : 'Hello!!' , tests : [ [ 'base45' , 'R%69 VD92EX0' ] ] } ,
160167 { input : 'base-45' , tests : [ [ 'base45' , 'RUJCLQE7W581' ] ] } ,
161- { input : 'ietf!' , tests : [ [ 'base45' , 'RQED8WEX0' ] ] }
168+ { input : 'ietf!' , tests : [ [ 'base45' , 'RQED8WEX0' ] ] } ,
169+
170+ // proquint spec examples, IPv4 addresses
171+ { input : Uint8Array . from ( [ 127 , 0 , 0 , 1 ] ) , tests : [ [ 'proquint' , 'pro-lusab-babad' ] ] } , // 127.0.0.1
172+ { input : Uint8Array . from ( [ 63 , 84 , 220 , 193 ] ) , tests : [ [ 'proquint' , 'pro-gutih-tugad' ] ] } , // 63.84.220.193
173+ { input : Uint8Array . from ( [ 63 , 118 , 7 , 35 ] ) , tests : [ [ 'proquint' , 'pro-gutuk-bisog' ] ] } , // 63.118.7.35
174+ { input : Uint8Array . from ( [ 140 , 98 , 193 , 141 ] ) , tests : [ [ 'proquint' , 'pro-mudof-sakat' ] ] } , // 140.98.193.141
175+ { input : Uint8Array . from ( [ 64 , 255 , 6 , 200 ] ) , tests : [ [ 'proquint' , 'pro-haguz-biram' ] ] } , // 64.255.6.200
176+ { input : Uint8Array . from ( [ 128 , 30 , 52 , 45 ] ) , tests : [ [ 'proquint' , 'pro-mabiv-gibot' ] ] } , // 128.30.52.45
177+ { input : Uint8Array . from ( [ 147 , 67 , 119 , 2 ] ) , tests : [ [ 'proquint' , 'pro-natag-lisaf' ] ] } , // 147.67.119.2
178+ { input : Uint8Array . from ( [ 212 , 58 , 253 , 68 ] ) , tests : [ [ 'proquint' , 'pro-tibup-zujah' ] ] } , // 212.58.253.68
179+ { input : Uint8Array . from ( [ 216 , 35 , 68 , 215 ] ) , tests : [ [ 'proquint' , 'pro-tobog-higil' ] ] } , // 216.35.68.215
180+ { input : Uint8Array . from ( [ 216 , 68 , 232 , 21 ] ) , tests : [ [ 'proquint' , 'pro-todah-vobij' ] ] } , // 216.68.232.21
181+ { input : Uint8Array . from ( [ 198 , 81 , 129 , 136 ] ) , tests : [ [ 'proquint' , 'pro-sinid-makam' ] ] } , // 198.81.129.136
182+ { input : Uint8Array . from ( [ 12 , 110 , 110 , 204 ] ) , tests : [ [ 'proquint' , 'pro-budov-kuras' ] ] } // 12.110.110.204
162183]
163184
164185describe ( 'spec test' , ( ) => {
@@ -169,13 +190,15 @@ describe('spec test', () => {
169190 const base = bases [ name as keyof typeof bases ]
170191
171192 describe ( name , ( ) => {
193+ const byteInput = typeof input === 'string' ? fromString ( input ) : input
194+
172195 it ( `should encode from buffer [${ input } ]` , ( ) => {
173- const out = base . encode ( fromString ( input ) )
196+ const out = base . encode ( byteInput )
174197 assert . deepStrictEqual ( out , output )
175198 } )
176199
177200 it ( `should decode from string [${ input } ]` , ( ) => {
178- assert . deepStrictEqual ( base . decode ( output ) , fromString ( input ) )
201+ assert . deepStrictEqual ( base . decode ( output ) , byteInput )
179202 } )
180203 } )
181204 }
@@ -187,6 +210,10 @@ describe('spec test', () => {
187210 if ( base . name === 'identity' ) {
188211 return this . skip ( )
189212 }
213+ if ( base . name === 'proquint' ) {
214+ assert . throws ( ( ) => base . decode ( 'pro-^!@$%!#$%@#y' ) , `Non-${ base . name } character` )
215+ return
216+ }
190217
191218 assert . throws ( ( ) => base . decode ( base . prefix + '^!@$%!#$%@#y' ) , `Non-${ base . name } character` )
192219 } )
@@ -196,4 +223,15 @@ describe('spec test', () => {
196223 // not enough input chars, should be multiple of 3 or multiple of 3 + 2
197224 assert . throws ( ( ) => bases . base45 . decode ( 'R%69 VD92EX' ) , 'Unexpected end of data' )
198225 } )
226+
227+ it ( 'proquint should fail with invalid input' , ( ) => {
228+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-' ) , 'Unexpected end of data' )
229+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-f' ) , 'Unexpected end of data' )
230+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-fa' ) , 'Unexpected end of data' )
231+ assert . throws ( ( ) => bases . proquint . decode ( 'pro-lojoj-lasob-kujod-kunon-fabo' ) , 'Unexpected end of data' )
232+ assert . throws ( ( ) => bases . proquint . decode ( 'plojoj-lasob-kujod-kunon-fabod' ) , 'Invalid proquint string' )
233+ assert . throws ( ( ) => bases . proquint . decode ( 'prlojoj-lasob-kujod-kunon-fabod' ) , 'Invalid proquint string' )
234+ assert . throws ( ( ) => bases . proquint . decode ( 'prolojoj-lasob-kujod-kunon-fabod' ) , 'Invalid proquint string' )
235+
236+ } )
199237} )
0 commit comments