@houlak/plexo-sdk 0.1.46 → 0.1.48
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.
- package/lib/sdk/helpers/signature/signatureHelper.js +2 -9
- package/lib/sdk/helpers/signature/signatureUtils.js +4 -1
- package/lib/sdk/helpers/signature/stringifyWithFloats.d.ts +1 -1
- package/lib/sdk/helpers/signature/stringifyWithFloats.js +2 -4
- package/lib/sdk/models/IssuerData.d.ts +2 -0
- package/lib/utils/case.util.js +0 -2
- package/package.json +1 -1
|
@@ -44,7 +44,6 @@ var config_1 = require("../../../config/config");
|
|
|
44
44
|
var __1 = require("../..");
|
|
45
45
|
var utils_1 = require("../../../utils");
|
|
46
46
|
var signatureUtils_1 = require("./signatureUtils");
|
|
47
|
-
var stringifyWithFloats_1 = require("./stringifyWithFloats");
|
|
48
47
|
var client = axios_1.default.create({
|
|
49
48
|
baseURL: config_1.config.plexoUrl,
|
|
50
49
|
});
|
|
@@ -94,7 +93,7 @@ var getPlexoKey = function (fingerprint) { return __awaiter(void 0, void 0, void
|
|
|
94
93
|
});
|
|
95
94
|
}); };
|
|
96
95
|
var unwrapCallback = function (fingerprint, response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
-
var serverResponse, plexoResponse, err_1, certificate, key, canonizedObject, objectInPascalCase, objectSorted,
|
|
96
|
+
var serverResponse, plexoResponse, err_1, certificate, key, canonizedObject, objectInPascalCase, objectSorted, objectBuffer, verifySignature;
|
|
98
97
|
return __generator(this, function (_a) {
|
|
99
98
|
switch (_a.label) {
|
|
100
99
|
case 0:
|
|
@@ -115,27 +114,21 @@ var unwrapCallback = function (fingerprint, response) { return __awaiter(void 0,
|
|
|
115
114
|
case 3:
|
|
116
115
|
certificate = new crypto_1.X509Certificate(Buffer.from(plexoResponse.Object.Object.Response.Key, 'base64'));
|
|
117
116
|
key = certificate.publicKey.export({ format: 'pem', type: 'pkcs1' });
|
|
118
|
-
logger_lib_1.default.info(response, 'Callback de Plexo');
|
|
119
117
|
canonizedObject = signatureUtils_1.signatureUtils.canonizeJson(response.object, [
|
|
120
118
|
'CreditLimits',
|
|
121
119
|
'creditLimits',
|
|
122
120
|
]);
|
|
123
|
-
logger_lib_1.default.info(canonizedObject, 'Objeto canonizado');
|
|
124
121
|
objectInPascalCase = utils_1.caseUtils.toPascalKeys(canonizedObject);
|
|
125
122
|
objectSorted = signatureUtils_1.signatureUtils.sortObject(objectInPascalCase);
|
|
126
|
-
|
|
127
|
-
logger_lib_1.default.info(objectWithAmounts, 'Objeto a verificar');
|
|
128
|
-
objectBuffer = Buffer.from(JSON.stringify(objectWithAmounts));
|
|
123
|
+
objectBuffer = Buffer.from(JSON.stringify(objectSorted));
|
|
129
124
|
verifySignature = (0, crypto_1.createVerify)('SHA512')
|
|
130
125
|
.update(objectBuffer)
|
|
131
126
|
.verify(key, response.signature, 'base64');
|
|
132
|
-
logger_lib_1.default.info(verifySignature, 'Verify Signature');
|
|
133
127
|
serverResponse = {
|
|
134
128
|
response: response.object.object,
|
|
135
129
|
resultCode: verifySignature ? __1.ResultCodes.Ok : __1.ResultCodes.InvalidSignature,
|
|
136
130
|
errorMessage: verifySignature ? 'Success' : 'Signature do not match',
|
|
137
131
|
};
|
|
138
|
-
logger_lib_1.default.info(serverResponse, 'Server response, end of unwrap');
|
|
139
132
|
return [2 /*return*/, serverResponse];
|
|
140
133
|
}
|
|
141
134
|
});
|
|
@@ -48,6 +48,7 @@ var canonizeJson = function (object, keysToSkip) {
|
|
|
48
48
|
var cleanObject = deleteObjectUndefined(object, keysToSkip);
|
|
49
49
|
return sortObject(cleanObject);
|
|
50
50
|
};
|
|
51
|
+
var nonSortedObjects = ['metadata', 'Metadata'];
|
|
51
52
|
var sortObject = function (object) {
|
|
52
53
|
if (Array.isArray(object)) {
|
|
53
54
|
var newArray_1 = [];
|
|
@@ -58,7 +59,9 @@ var sortObject = function (object) {
|
|
|
58
59
|
var newObject_1 = {};
|
|
59
60
|
Object.keys(object)
|
|
60
61
|
.sort()
|
|
61
|
-
.map(function (key) {
|
|
62
|
+
.map(function (key) {
|
|
63
|
+
return (newObject_1[key] = nonSortedObjects.includes(key) ? object[key] : sortObject(object[key]));
|
|
64
|
+
});
|
|
62
65
|
return newObject_1;
|
|
63
66
|
}
|
|
64
67
|
return object;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const stringifyAmountsWithFloats: (object: any
|
|
1
|
+
export declare const stringifyAmountsWithFloats: (object: any) => string;
|
|
@@ -56,18 +56,16 @@ var stringifyWithFloats = function (config, decimals) {
|
|
|
56
56
|
// By using this, when we have for example Amount: 100, we replace that for Amount: 100.0.
|
|
57
57
|
// If we send just 100, Plexo doesn't like that and we receive a
|
|
58
58
|
// "signature does not match" error message
|
|
59
|
-
var stringifyAmountsWithFloats = function (object
|
|
59
|
+
var stringifyAmountsWithFloats = function (object) {
|
|
60
60
|
return stringifyWithFloats({
|
|
61
61
|
amount: 'float',
|
|
62
62
|
billedAmount: 'float',
|
|
63
63
|
taxedAmount: 'float',
|
|
64
64
|
vatAmount: 'float',
|
|
65
|
-
returnAmount: 'float',
|
|
66
65
|
Amount: 'float',
|
|
67
66
|
BilledAmount: 'float',
|
|
68
67
|
TaxedAmount: 'float',
|
|
69
68
|
VATAmount: 'float',
|
|
70
|
-
|
|
71
|
-
}, amountAfterComma || 1)(object, null, 0);
|
|
69
|
+
}, 1)(object, null, 0);
|
|
72
70
|
};
|
|
73
71
|
exports.stringifyAmountsWithFloats = stringifyAmountsWithFloats;
|
package/lib/utils/case.util.js
CHANGED
|
@@ -5,10 +5,8 @@ var js_convert_case_1 = require("js-convert-case");
|
|
|
5
5
|
var specialWords = [
|
|
6
6
|
{ word: 'UtcUnixTimeExpiration', substitute: 'UTCUnixTimeExpiration' },
|
|
7
7
|
{ word: 'UtcunixTimeExpiration', substitute: 'UTCUnixTimeExpiration' },
|
|
8
|
-
{ word: 'utcunixTimeExpiration', substitute: 'UTCUnixTimeExpiration' },
|
|
9
8
|
{ word: 'VatAmount', substitute: 'VATAmount' },
|
|
10
9
|
{ word: 'InstrumentExpirationUtc', substitute: 'InstrumentExpirationUTC' },
|
|
11
|
-
{ word: 'ExecutionDateUtc', substitute: 'ExecutionDateUTC' },
|
|
12
10
|
];
|
|
13
11
|
var camelCaseSpecialWords = [
|
|
14
12
|
{
|