@@ -88,12 +88,12 @@ describe("cbor", () => {
8888 {
8989 name : "negative float" ,
9090 data : - 3015135.135135135 ,
91- cbor : allocByteArray ( [ 0b111_11011 , + 193 , + 71 , + 0 , + 239 , + 145 , + 76 , + 27 , + 173 ] ) ,
91+ cbor : allocByteArray ( [ 0b111_11011 , 193 , 71 , 0 , 239 , 145 , 76 , 27 , 173 ] ) ,
9292 } ,
9393 {
9494 name : "positive float" ,
9595 data : 3015135.135135135 ,
96- cbor : allocByteArray ( [ 0b111_11011 , + 65 , + 71 , + 0 , + 239 , + 145 , + 76 , + 27 , + 173 ] ) ,
96+ cbor : allocByteArray ( [ 0b111_11011 , 65 , 71 , 0 , 239 , 145 , 76 , 27 , 173 ] ) ,
9797 } ,
9898 {
9999 name : "various numbers" ,
@@ -214,6 +214,18 @@ describe("cbor", () => {
214214 65 , 109 , 110 , 101 , 115 , 116 , 101 , 100 , 32 , 105 , 116 , 101 , 109 , 32 , 66 ,
215215 ] ) ,
216216 } ,
217+ {
218+ name : "object containing big numbers" ,
219+ data : {
220+ map : {
221+ items : [ BigInt ( 1e80 ) ] ,
222+ } ,
223+ } ,
224+ cbor : allocByteArray ( [
225+ 161 , 99 , 109 , 97 , 112 , 161 , 101 , 105 , 116 , 101 , 109 , 115 , 129 , 194 , 88 , 34 , 3 , 95 , 157 , 234 , 62 , 31 , 107 , 224 ,
226+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
227+ ] ) ,
228+ } ,
217229 ] ;
218230
219231 const toBytes = ( hex : string ) => {
@@ -226,6 +238,48 @@ describe("cbor", () => {
226238 } ;
227239
228240 describe ( "locally curated scenarios" , ( ) => {
241+ it ( "should round-trip bigInteger to major 6 with tag 2" , ( ) => {
242+ const bigInt = BigInt ( "1267650600228229401496703205376" ) ;
243+ const serialized = cbor . serialize ( bigInt ) ;
244+
245+ const major = serialized [ 0 ] >> 5 ;
246+ expect ( major ) . toEqual ( 0b110 ) ; // 6
247+
248+ const tag = serialized [ 0 ] & 0b11111 ;
249+ expect ( tag ) . toEqual ( 0b010 ) ; // 2
250+
251+ const byteStringCount = serialized [ 1 ] ;
252+ expect ( byteStringCount ) . toEqual ( 0b010_01101 ) ; // major 2, 13 bytes
253+
254+ const byteString = serialized . slice ( 2 ) ;
255+ expect ( byteString ) . toEqual ( allocByteArray ( [ 0b000_10000 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ) ;
256+
257+ const deserialized = cbor . deserialize ( serialized ) ;
258+ expect ( deserialized ) . toEqual ( bigInt ) ;
259+ } ) ;
260+
261+ it ( "should round-trip negative bigInteger to major 6 with tag 3" , ( ) => {
262+ const bigInt = BigInt ( "-1267650600228229401496703205377" ) ;
263+ const serialized = cbor . serialize ( bigInt ) ;
264+
265+ const major = serialized [ 0 ] >> 5 ;
266+ expect ( major ) . toEqual ( 0b110 ) ; // 6
267+
268+ const tag = serialized [ 0 ] & 0b11111 ;
269+ expect ( tag ) . toEqual ( 0b011 ) ; // 3
270+
271+ const byteStringCount = serialized [ 1 ] ;
272+ expect ( byteStringCount ) . toEqual ( 0b010_01101 ) ; // major 2, 13 bytes
273+
274+ const byteString = serialized . slice ( 2 ) ;
275+ expect ( byteString ) . toEqual ( allocByteArray ( [ 0b000_10000 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ) ;
276+
277+ const deserialized = cbor . deserialize ( serialized ) ;
278+ expect ( deserialized ) . toEqual ( bigInt ) ;
279+ } ) ;
280+
281+ it ( "should round-trip NumericValue to major 6 with tag 4" , ( ) => { } ) ;
282+
229283 it ( "should throw an error if serializing a tag with missing properties" , ( ) => {
230284 expect ( ( ) =>
231285 cbor . serialize ( {
0 commit comments