@pagopa/io-react-native-wallet 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,20 @@ const createCryptoContextFor = keytag => {
|
|
45
45
|
};
|
46
46
|
};
|
47
47
|
|
48
|
+
// Wraps finally for async expressions
|
49
|
+
exports.createCryptoContextFor = createCryptoContextFor;
|
50
|
+
const asyncFinally = (fn, onFinally) => async function () {
|
51
|
+
try {
|
52
|
+
return await fn(...arguments);
|
53
|
+
// ^^^^^ return await is usually to be avoided,
|
54
|
+
// in this case is needed for the finally{} statement to be executed correctly
|
55
|
+
} catch (error) {
|
56
|
+
throw error;
|
57
|
+
} finally {
|
58
|
+
await onFinally();
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
48
62
|
/**
|
49
63
|
* Executes the input function injecting an ephemeral crypto context.
|
50
64
|
* An ephemeral crypto context is a context which is bound to a key
|
@@ -53,19 +67,12 @@ const createCryptoContextFor = keytag => {
|
|
53
67
|
* @param fn The procedure to be executed
|
54
68
|
* @returns The returned value of the input procedure.
|
55
69
|
*/
|
56
|
-
exports.createCryptoContextFor = createCryptoContextFor;
|
57
70
|
const useEphemeralKey = async fn => {
|
58
71
|
// Use an ephemeral key to be destroyed after use
|
59
72
|
const keytag = `ephemeral-${_reactNativeUuid.default.v4()}`;
|
60
73
|
await (0, _ioReactNativeCrypto.generate)(keytag);
|
61
74
|
const ephemeralContext = createCryptoContextFor(keytag);
|
62
|
-
|
63
|
-
return fn(ephemeralContext);
|
64
|
-
} catch (error) {
|
65
|
-
throw error;
|
66
|
-
} finally {
|
67
|
-
await (0, _ioReactNativeCrypto.deleteKey)(keytag);
|
68
|
-
}
|
75
|
+
return asyncFinally(fn, () => (0, _ioReactNativeCrypto.deleteKey)(keytag))(ephemeralContext);
|
69
76
|
};
|
70
77
|
exports.useEphemeralKey = useEphemeralKey;
|
71
78
|
//# sourceMappingURL=crypto.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_ioReactNativeCrypto","require","_reactNativeUuid","_interopRequireDefault","_ioReactNativeJwt","_jwk","obj","__esModule","default","createCryptoContextFor","keytag","getPublicKey","then","fixBase64EncodingOnKey","jwk","kid","thumbprint","getSignature","value","sign","exports","
|
1
|
+
{"version":3,"names":["_ioReactNativeCrypto","require","_reactNativeUuid","_interopRequireDefault","_ioReactNativeJwt","_jwk","obj","__esModule","default","createCryptoContextFor","keytag","getPublicKey","then","fixBase64EncodingOnKey","jwk","kid","thumbprint","getSignature","value","sign","exports","asyncFinally","fn","onFinally","arguments","error","useEphemeralKey","uuid","v4","generate","ephemeralContext","deleteKey"],"sourceRoot":"../../../src","sources":["utils/crypto.ts"],"mappings":";;;;;;AAAA,IAAAA,oBAAA,GAAAC,OAAA;AAMA,IAAAC,gBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AAA+C,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,sBAAsB,GAAIC,MAAc,IAAoB;EACvE,OAAO;IACL;AACJ;AACA;AACA;AACA;IACI,MAAMC,YAAYA,CAAA,EAAG;MACnB,OAAO,IAAAA,iCAAY,EAACD,MAAM,CAAC,CACxBE,IAAI,CAACC,2BAAsB,CAAC,CAC5BD,IAAI,CAAC,MAAOE,GAAG,KAAM;QACpB,GAAGA,GAAG;QACN;QACA;QACA;QACA;QACAC,GAAG,EAAE,MAAM,IAAAC,4BAAU,EAACF,GAAG;MAC3B,CAAC,CAAC,CAAC;IACP,CAAC;IACD;AACJ;AACA;AACA;AACA;AACA;IACI,MAAMG,YAAYA,CAACC,KAAa,EAAE;MAChC,OAAO,IAAAC,yBAAI,EAACD,KAAK,EAAER,MAAM,CAAC;IAC5B;EACF,CAAC;AACH,CAAC;;AAED;AAAAU,OAAA,CAAAX,sBAAA,GAAAA,sBAAA;AACA,MAAMY,YAAY,GAChBA,CACEC,EAA8B,EAC9BC,SAAqC,KAEvC,kBAAkC;EAChC,IAAI;IACF,OAAO,MAAMD,EAAE,CAAC,GAAAE,SAAO,CAAC;IACxB;IACA;EACF,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,MAAMA,KAAK;EACb,CAAC,SAAS;IACR,MAAMF,SAAS,CAAC,CAAC;EACnB;AACF,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,eAAe,GAAG,MAC7BJ,EAAmD,IACpC;EACf;EACA,MAAMZ,MAAM,GAAI,aAAYiB,wBAAI,CAACC,EAAE,CAAC,CAAE,EAAC;EACvC,MAAM,IAAAC,6BAAQ,EAACnB,MAAM,CAAC;EACtB,MAAMoB,gBAAgB,GAAGrB,sBAAsB,CAACC,MAAM,CAAC;EACvD,OAAOW,YAAY,CAACC,EAAE,EAAE,MAAM,IAAAS,8BAAS,EAACrB,MAAM,CAAC,CAAC,CAACoB,gBAAgB,CAAC;AACpE,CAAC;AAACV,OAAA,CAAAM,eAAA,GAAAA,eAAA"}
|
@@ -39,6 +39,19 @@ export const createCryptoContextFor = keytag => {
|
|
39
39
|
};
|
40
40
|
};
|
41
41
|
|
42
|
+
// Wraps finally for async expressions
|
43
|
+
const asyncFinally = (fn, onFinally) => async function () {
|
44
|
+
try {
|
45
|
+
return await fn(...arguments);
|
46
|
+
// ^^^^^ return await is usually to be avoided,
|
47
|
+
// in this case is needed for the finally{} statement to be executed correctly
|
48
|
+
} catch (error) {
|
49
|
+
throw error;
|
50
|
+
} finally {
|
51
|
+
await onFinally();
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
42
55
|
/**
|
43
56
|
* Executes the input function injecting an ephemeral crypto context.
|
44
57
|
* An ephemeral crypto context is a context which is bound to a key
|
@@ -52,12 +65,6 @@ export const useEphemeralKey = async fn => {
|
|
52
65
|
const keytag = `ephemeral-${uuid.v4()}`;
|
53
66
|
await generate(keytag);
|
54
67
|
const ephemeralContext = createCryptoContextFor(keytag);
|
55
|
-
|
56
|
-
return fn(ephemeralContext);
|
57
|
-
} catch (error) {
|
58
|
-
throw error;
|
59
|
-
} finally {
|
60
|
-
await deleteKey(keytag);
|
61
|
-
}
|
68
|
+
return asyncFinally(fn, () => deleteKey(keytag))(ephemeralContext);
|
62
69
|
};
|
63
70
|
//# sourceMappingURL=crypto.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["getPublicKey","sign","generate","deleteKey","uuid","thumbprint","fixBase64EncodingOnKey","createCryptoContextFor","keytag","then","jwk","kid","getSignature","value","
|
1
|
+
{"version":3,"names":["getPublicKey","sign","generate","deleteKey","uuid","thumbprint","fixBase64EncodingOnKey","createCryptoContextFor","keytag","then","jwk","kid","getSignature","value","asyncFinally","fn","onFinally","arguments","error","useEphemeralKey","v4","ephemeralContext"],"sourceRoot":"../../../src","sources":["utils/crypto.ts"],"mappings":"AAAA,SACEA,YAAY,EACZC,IAAI,EACJC,QAAQ,EACRC,SAAS,QACJ,gCAAgC;AACvC,OAAOC,IAAI,MAAM,mBAAmB;AACpC,SAASC,UAAU,QAA4B,6BAA6B;AAC5E,SAASC,sBAAsB,QAAQ,OAAO;;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAIC,MAAc,IAAoB;EACvE,OAAO;IACL;AACJ;AACA;AACA;AACA;IACI,MAAMR,YAAYA,CAAA,EAAG;MACnB,OAAOA,YAAY,CAACQ,MAAM,CAAC,CACxBC,IAAI,CAACH,sBAAsB,CAAC,CAC5BG,IAAI,CAAC,MAAOC,GAAG,KAAM;QACpB,GAAGA,GAAG;QACN;QACA;QACA;QACA;QACAC,GAAG,EAAE,MAAMN,UAAU,CAACK,GAAG;MAC3B,CAAC,CAAC,CAAC;IACP,CAAC;IACD;AACJ;AACA;AACA;AACA;AACA;IACI,MAAME,YAAYA,CAACC,KAAa,EAAE;MAChC,OAAOZ,IAAI,CAACY,KAAK,EAAEL,MAAM,CAAC;IAC5B;EACF,CAAC;AACH,CAAC;;AAED;AACA,MAAMM,YAAY,GAChBA,CACEC,EAA8B,EAC9BC,SAAqC,KAEvC,kBAAkC;EAChC,IAAI;IACF,OAAO,MAAMD,EAAE,CAAC,GAAAE,SAAO,CAAC;IACxB;IACA;EACF,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,MAAMA,KAAK;EACb,CAAC,SAAS;IACR,MAAMF,SAAS,CAAC,CAAC;EACnB;AACF,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,eAAe,GAAG,MAC7BJ,EAAmD,IACpC;EACf;EACA,MAAMP,MAAM,GAAI,aAAYJ,IAAI,CAACgB,EAAE,CAAC,CAAE,EAAC;EACvC,MAAMlB,QAAQ,CAACM,MAAM,CAAC;EACtB,MAAMa,gBAAgB,GAAGd,sBAAsB,CAACC,MAAM,CAAC;EACvD,OAAOM,YAAY,CAACC,EAAE,EAAE,MAAMZ,SAAS,CAACK,MAAM,CAAC,CAAC,CAACa,gBAAgB,CAAC;AACpE,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":"AAOA,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG7E;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,WAAY,MAAM,KAAG,aA6BvD,CAAC;
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":"AAOA,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG7E;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,WAAY,MAAM,KAAG,aA6BvD,CAAC;AAoBF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,6BACH,aAAa,8BAOrC,CAAC"}
|
package/package.json
CHANGED
package/src/utils/crypto.ts
CHANGED
@@ -46,6 +46,24 @@ export const createCryptoContextFor = (keytag: string): CryptoContext => {
|
|
46
46
|
};
|
47
47
|
};
|
48
48
|
|
49
|
+
// Wraps finally for async expressions
|
50
|
+
const asyncFinally =
|
51
|
+
<A extends Array<unknown>, R>(
|
52
|
+
fn: (...args: A) => Promise<R>,
|
53
|
+
onFinally: () => void | Promise<void>
|
54
|
+
) =>
|
55
|
+
async (...args: A): Promise<R> => {
|
56
|
+
try {
|
57
|
+
return await fn(...args);
|
58
|
+
// ^^^^^ return await is usually to be avoided,
|
59
|
+
// in this case is needed for the finally{} statement to be executed correctly
|
60
|
+
} catch (error) {
|
61
|
+
throw error;
|
62
|
+
} finally {
|
63
|
+
await onFinally();
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
49
67
|
/**
|
50
68
|
* Executes the input function injecting an ephemeral crypto context.
|
51
69
|
* An ephemeral crypto context is a context which is bound to a key
|
@@ -61,11 +79,5 @@ export const useEphemeralKey = async <R>(
|
|
61
79
|
const keytag = `ephemeral-${uuid.v4()}`;
|
62
80
|
await generate(keytag);
|
63
81
|
const ephemeralContext = createCryptoContextFor(keytag);
|
64
|
-
|
65
|
-
return fn(ephemeralContext);
|
66
|
-
} catch (error) {
|
67
|
-
throw error;
|
68
|
-
} finally {
|
69
|
-
await deleteKey(keytag);
|
70
|
-
}
|
82
|
+
return asyncFinally(fn, () => deleteKey(keytag))(ephemeralContext);
|
71
83
|
};
|