Skip to content

Commit

Permalink
AE-2356: Fetch signing tool version
Browse files Browse the repository at this point in the history
The version is now fetched from /version endpoint instead of being hard coded to '1.1'.
  • Loading branch information
outamaa committed Dec 4, 2024
1 parent 8d09c51 commit 5d562ec
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions etp-front/src/pages/energiatodistus/signing/signature-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,37 @@ const mpolluxUrl = 'https://localhost:53952';
const mpolluxVersionUrl = `${mpolluxUrl}/version`;
const mpolluxSignUrl = `${mpolluxUrl}/sign`;

const signatureOptions = {
version: '1.1',
const signatureOptions = version => ({
version: version,
selector: {
keyusages: ['nonrepudiation'],
keyalgorithms: ['rsa']
},
contentType: 'data',
hashAlgorithm: 'SHA256',
signatureType: 'signature'
};
});

// Example of mPollux response can be found in etp-core/docker/mpollux/api/version
export const versionInfo = fetch => Fetch.getJson(fetch, mpolluxVersionUrl);

const getSignatureOptions = fetch =>
R.map(R.compose(signatureOptions, R.prop('version')), versionInfo(fetch));

export const isValidSignatureResponse = R.compose(
R.equals('ok'),
R.prop('status')
);

export const getSignature = R.curry((fetch, content) =>
R.compose(
R.map(R.pick(['signature', 'chain'])),
Future.filter(isValidSignatureResponse, 'error'),
Fetch.responseAsJson,
Future.encaseP(Fetch.fetchWithMethod(fetch, 'post', mpolluxSignUrl)),
R.assoc('content', R.__, signatureOptions),
R.prop('digest')
)(content)
R.chain(
R.compose(
R.map(R.pick(['signature', 'chain'])),
Future.filter(isValidSignatureResponse, 'error'),
Fetch.responseAsJson,
Future.encaseP(Fetch.fetchWithMethod(fetch, 'post', mpolluxSignUrl)),
R.assoc('content', R.prop('digest', content))
),
getSignatureOptions(fetch)
)
);

0 comments on commit 5d562ec

Please sign in to comment.