@pagopa/io-react-native-jwt 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.addPadding = addPadding;
6
7
  exports.decodeBase64 = decodeBase64;
7
8
  exports.encodeBase64 = encodeBase64;
8
9
  exports.removePadding = removePadding;
@@ -29,7 +30,7 @@ function encodeBase64(value) {
29
30
  }
30
31
  }
31
32
  function decodeBase64(value) {
32
- let decoded = (0, _abab.atob)(value);
33
+ let decoded = (0, _abab.atob)(addPadding(value));
33
34
  if (decoded) {
34
35
  return decoded;
35
36
  } else {
@@ -40,4 +41,15 @@ function removePadding(encoded) {
40
41
  // eslint-disable-next-line no-div-regex
41
42
  return encoded.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
42
43
  }
44
+ function addPadding(encoded) {
45
+ encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
46
+ var pad = encoded.length % 4;
47
+ if (pad) {
48
+ if (pad === 1) {
49
+ throw new _errors.JOSEError('InvalidLengthError: Input base64url string is the wrong length to determine padding');
50
+ }
51
+ encoded += new Array(5 - pad).join('=');
52
+ }
53
+ return encoded;
54
+ }
43
55
  //# sourceMappingURL=base64.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_abab","require","_errors","encodeBase64","value","encoded","btoa","removePadding","JOSEError","decodeBase64","decoded","atob","replace"],"sourceRoot":"../../../src","sources":["utils/base64.ts"],"mappings":";;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAACC,KAAa,EAAU;EAClD,IAAIC,OAAO,GAAG,IAAAC,UAAI,EAACF,KAAK,CAAC;EACzB,IAAIC,OAAO,EAAE;IACX,OAAOE,aAAa,CAACF,OAAO,CAAC;EAC/B,CAAC,MAAM;IACL,MAAM,IAAIG,iBAAS,CAAC,mCAAmC,CAAC;EAC1D;AACF;AAEO,SAASC,YAAYA,CAACL,KAAa,EAAU;EAClD,IAAIM,OAAO,GAAG,IAAAC,UAAI,EAACP,KAAK,CAAC;EACzB,IAAIM,OAAO,EAAE;IACX,OAAOA,OAAO;EAChB,CAAC,MAAM;IACL,MAAM,IAAIF,iBAAS,CAAC,gCAAgC,CAAC;EACvD;AACF;AAEO,SAASD,aAAaA,CAACF,OAAe,EAAU;EACrD;EACA,OAAOA,OAAO,CAACO,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAC1E"}
1
+ {"version":3,"names":["_abab","require","_errors","encodeBase64","value","encoded","btoa","removePadding","JOSEError","decodeBase64","decoded","atob","addPadding","replace","pad","length","Array","join"],"sourceRoot":"../../../src","sources":["utils/base64.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAACC,KAAa,EAAU;EAClD,IAAIC,OAAO,GAAG,IAAAC,UAAI,EAACF,KAAK,CAAC;EACzB,IAAIC,OAAO,EAAE;IACX,OAAOE,aAAa,CAACF,OAAO,CAAC;EAC/B,CAAC,MAAM;IACL,MAAM,IAAIG,iBAAS,CAAC,mCAAmC,CAAC;EAC1D;AACF;AAEO,SAASC,YAAYA,CAACL,KAAa,EAAU;EAClD,IAAIM,OAAO,GAAG,IAAAC,UAAI,EAACC,UAAU,CAACR,KAAK,CAAC,CAAC;EACrC,IAAIM,OAAO,EAAE;IACX,OAAOA,OAAO;EAChB,CAAC,MAAM;IACL,MAAM,IAAIF,iBAAS,CAAC,gCAAgC,CAAC;EACvD;AACF;AAEO,SAASD,aAAaA,CAACF,OAAe,EAAU;EACrD;EACA,OAAOA,OAAO,CAACQ,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAC1E;AAEO,SAASD,UAAUA,CAACP,OAAe,EAAU;EAClDA,OAAO,GAAGA,OAAO,CAACQ,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;EACvD,IAAIC,GAAG,GAAGT,OAAO,CAACU,MAAM,GAAG,CAAC;EAC5B,IAAID,GAAG,EAAE;IACP,IAAIA,GAAG,KAAK,CAAC,EAAE;MACb,MAAM,IAAIN,iBAAS,CACjB,qFACF,CAAC;IACH;IACAH,OAAO,IAAI,IAAIW,KAAK,CAAC,CAAC,GAAGF,GAAG,CAAC,CAACG,IAAI,CAAC,GAAG,CAAC;EACzC;EACA,OAAOZ,OAAO;AAChB"}
@@ -22,7 +22,7 @@ export function encodeBase64(value) {
22
22
  }
23
23
  }
24
24
  export function decodeBase64(value) {
25
- let decoded = atob(value);
25
+ let decoded = atob(addPadding(value));
26
26
  if (decoded) {
27
27
  return decoded;
28
28
  } else {
@@ -33,4 +33,15 @@ export function removePadding(encoded) {
33
33
  // eslint-disable-next-line no-div-regex
34
34
  return encoded.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
35
35
  }
36
+ export function addPadding(encoded) {
37
+ encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
38
+ var pad = encoded.length % 4;
39
+ if (pad) {
40
+ if (pad === 1) {
41
+ throw new JOSEError('InvalidLengthError: Input base64url string is the wrong length to determine padding');
42
+ }
43
+ encoded += new Array(5 - pad).join('=');
44
+ }
45
+ return encoded;
46
+ }
36
47
  //# sourceMappingURL=base64.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["btoa","atob","JOSEError","encodeBase64","value","encoded","removePadding","decodeBase64","decoded","replace"],"sourceRoot":"../../../src","sources":["utils/base64.ts"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,QAAQ,MAAM;AACjC,SAASC,SAAS,QAAQ,UAAU;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAACC,KAAa,EAAU;EAClD,IAAIC,OAAO,GAAGL,IAAI,CAACI,KAAK,CAAC;EACzB,IAAIC,OAAO,EAAE;IACX,OAAOC,aAAa,CAACD,OAAO,CAAC;EAC/B,CAAC,MAAM;IACL,MAAM,IAAIH,SAAS,CAAC,mCAAmC,CAAC;EAC1D;AACF;AAEA,OAAO,SAASK,YAAYA,CAACH,KAAa,EAAU;EAClD,IAAII,OAAO,GAAGP,IAAI,CAACG,KAAK,CAAC;EACzB,IAAII,OAAO,EAAE;IACX,OAAOA,OAAO;EAChB,CAAC,MAAM;IACL,MAAM,IAAIN,SAAS,CAAC,gCAAgC,CAAC;EACvD;AACF;AAEA,OAAO,SAASI,aAAaA,CAACD,OAAe,EAAU;EACrD;EACA,OAAOA,OAAO,CAACI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAC1E"}
1
+ {"version":3,"names":["btoa","atob","JOSEError","encodeBase64","value","encoded","removePadding","decodeBase64","decoded","addPadding","replace","pad","length","Array","join"],"sourceRoot":"../../../src","sources":["utils/base64.ts"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,QAAQ,MAAM;AACjC,SAASC,SAAS,QAAQ,UAAU;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAACC,KAAa,EAAU;EAClD,IAAIC,OAAO,GAAGL,IAAI,CAACI,KAAK,CAAC;EACzB,IAAIC,OAAO,EAAE;IACX,OAAOC,aAAa,CAACD,OAAO,CAAC;EAC/B,CAAC,MAAM;IACL,MAAM,IAAIH,SAAS,CAAC,mCAAmC,CAAC;EAC1D;AACF;AAEA,OAAO,SAASK,YAAYA,CAACH,KAAa,EAAU;EAClD,IAAII,OAAO,GAAGP,IAAI,CAACQ,UAAU,CAACL,KAAK,CAAC,CAAC;EACrC,IAAII,OAAO,EAAE;IACX,OAAOA,OAAO;EAChB,CAAC,MAAM;IACL,MAAM,IAAIN,SAAS,CAAC,gCAAgC,CAAC;EACvD;AACF;AAEA,OAAO,SAASI,aAAaA,CAACD,OAAe,EAAU;EACrD;EACA,OAAOA,OAAO,CAACK,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAC1E;AAEA,OAAO,SAASD,UAAUA,CAACJ,OAAe,EAAU;EAClDA,OAAO,GAAGA,OAAO,CAACK,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;EACvD,IAAIC,GAAG,GAAGN,OAAO,CAACO,MAAM,GAAG,CAAC;EAC5B,IAAID,GAAG,EAAE;IACP,IAAIA,GAAG,KAAK,CAAC,EAAE;MACb,MAAM,IAAIT,SAAS,CACjB,qFACF,CAAC;IACH;IACAG,OAAO,IAAI,IAAIQ,KAAK,CAAC,CAAC,GAAGF,GAAG,CAAC,CAACG,IAAI,CAAC,GAAG,CAAC;EACzC;EACA,OAAOT,OAAO;AAChB"}
@@ -1,4 +1,5 @@
1
1
  export declare function encodeBase64(value: string): string;
2
2
  export declare function decodeBase64(value: string): string;
3
3
  export declare function removePadding(encoded: string): string;
4
+ export declare function addPadding(encoded: string): string;
4
5
  //# sourceMappingURL=base64.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../src/utils/base64.ts"],"names":[],"mappings":"AAeA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGrD"}
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../src/utils/base64.ts"],"names":[],"mappings":"AAeA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAYlD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-jwt",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Native support for JWT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -23,7 +23,7 @@ export function encodeBase64(value: string): string {
23
23
  }
24
24
 
25
25
  export function decodeBase64(value: string): string {
26
- let decoded = atob(value);
26
+ let decoded = atob(addPadding(value));
27
27
  if (decoded) {
28
28
  return decoded;
29
29
  } else {
@@ -35,3 +35,17 @@ export function removePadding(encoded: string): string {
35
35
  // eslint-disable-next-line no-div-regex
36
36
  return encoded.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
37
37
  }
38
+
39
+ export function addPadding(encoded: string): string {
40
+ encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
41
+ var pad = encoded.length % 4;
42
+ if (pad) {
43
+ if (pad === 1) {
44
+ throw new JOSEError(
45
+ 'InvalidLengthError: Input base64url string is the wrong length to determine padding'
46
+ );
47
+ }
48
+ encoded += new Array(5 - pad).join('=');
49
+ }
50
+ return encoded;
51
+ }