@nmshd/transport 1.1.6 → 1.1.10
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/dist/buildInformation.js +5 -5
- package/dist/modules/challenges/ChallengeController.d.ts +5 -2
- package/dist/modules/challenges/ChallengeController.js +21 -27
- package/dist/modules/challenges/ChallengeController.js.map +1 -1
- package/dist/modules/files/FileController.js +3 -20
- package/dist/modules/files/FileController.js.map +1 -1
- package/dist/modules/relationshipTemplates/RelationshipTemplateController.js +3 -20
- package/dist/modules/relationshipTemplates/RelationshipTemplateController.js.map +1 -1
- package/dist/modules/tokens/TokenController.js +17 -23
- package/dist/modules/tokens/TokenController.js.map +1 -1
- package/lib-web/nmshd.transport.js +51 -104
- package/lib-web/nmshd.transport.js.map +1 -1
- package/lib-web/nmshd.transport.min.js +1 -1
- package/lib-web/nmshd.transport.min.js.map +1 -1
- package/package.json +28 -26
|
@@ -15,11 +15,11 @@ exports.buildInformation = void 0;
|
|
|
15
15
|
const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
|
|
16
16
|
const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
|
|
17
17
|
exports.buildInformation = {
|
|
18
|
-
version: "1.1.
|
|
19
|
-
build: "
|
|
20
|
-
date: "2022-
|
|
21
|
-
commit: "
|
|
22
|
-
dependencies: {"@js-soft/docdb-access-abstractions":"1.0.1","@js-soft/logging-abstractions":"1.0.0","@js-soft/simple-logger":"1.0.
|
|
18
|
+
version: "1.1.10",
|
|
19
|
+
build: "22",
|
|
20
|
+
date: "2022-02-21T10:57:30+00:00",
|
|
21
|
+
commit: "c5a9ae56d5ed7ce0dd69a16080babe841ceed26d",
|
|
22
|
+
dependencies: {"@js-soft/docdb-access-abstractions":"1.0.1","@js-soft/logging-abstractions":"1.0.0","@js-soft/simple-logger":"1.0.1","@js-soft/ts-utils":"1.1.1","axios":"^0.26.0","deep-equal":"^2.0.5","fast-json-patch":"^3.1.0","form-data":"^4.0.0","json-stringify-safe":"^5.0.1","lodash":"^4.17.21","luxon":"^2.3.0","qs":"^6.10.3","reflect-metadata":"^0.1.13","ts-simple-nameof":"^1.3.1","uuid":"^8.3.2"},
|
|
23
23
|
libraries: {
|
|
24
24
|
crypto: crypto_1.buildInformation,
|
|
25
25
|
serval: ts_serval_1.buildInformation
|
|
@@ -4103,51 +4103,45 @@ class ChallengeController extends TransportController_1.TransportController {
|
|
|
4103
4103
|
this.authClient = new ChallengeAuthClient_1.ChallengeAuthClient(this.config, this.parent.authenticator);
|
|
4104
4104
|
return this;
|
|
4105
4105
|
}
|
|
4106
|
-
async
|
|
4107
|
-
if (!challenge.createdBy)
|
|
4108
|
-
return;
|
|
4109
|
-
}
|
|
4106
|
+
async validateChallengeLocally(challenge, signedChallenge) {
|
|
4107
|
+
if (!challenge.createdBy)
|
|
4108
|
+
return { isValid: false };
|
|
4110
4109
|
const relationship = await this.parent.relationships.getActiveRelationshipToIdentity(challenge.createdBy);
|
|
4111
4110
|
if (!relationship) {
|
|
4112
4111
|
throw core_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, challenge.createdBy.toString());
|
|
4113
4112
|
}
|
|
4114
4113
|
const challengeBuffer = crypto_1.CoreBuffer.fromUtf8(signedChallenge.challenge);
|
|
4115
|
-
let
|
|
4114
|
+
let isValid = false;
|
|
4116
4115
|
switch (challenge.type) {
|
|
4117
4116
|
case Challenge_1.ChallengeType.Identity:
|
|
4118
|
-
|
|
4117
|
+
isValid = await this.parent.relationships.verifyIdentity(relationship, challengeBuffer, signedChallenge.signature);
|
|
4119
4118
|
break;
|
|
4120
4119
|
case Challenge_1.ChallengeType.Device:
|
|
4121
4120
|
throw core_1.TransportErrors.general.notImplemented().logWith(this._log);
|
|
4122
4121
|
case Challenge_1.ChallengeType.Relationship:
|
|
4123
|
-
|
|
4122
|
+
isValid = await this.parent.relationships.verify(relationship, challengeBuffer, signedChallenge.signature);
|
|
4124
4123
|
break;
|
|
4125
4124
|
}
|
|
4126
|
-
if (!
|
|
4127
|
-
return;
|
|
4128
|
-
}
|
|
4129
|
-
return relationship;
|
|
4125
|
+
if (!isValid)
|
|
4126
|
+
return { isValid: false };
|
|
4127
|
+
return { isValid: true, correspondingRelationship: relationship };
|
|
4130
4128
|
}
|
|
4131
|
-
async
|
|
4129
|
+
async validateChallenge(signedChallenge, requiredType) {
|
|
4132
4130
|
const challenge = await Challenge_1.Challenge.deserialize(signedChallenge.challenge);
|
|
4133
|
-
if (requiredType && challenge.type !== requiredType)
|
|
4134
|
-
return;
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
this.authClient.getChallenge(challenge.id.toString())
|
|
4142
|
-
]);
|
|
4143
|
-
if (!relationship ||
|
|
4144
|
-
(challenge.createdBy && response.value.createdBy !== challenge.createdBy.toString()) ||
|
|
4131
|
+
if (requiredType && challenge.type !== requiredType)
|
|
4132
|
+
return { isValid: false };
|
|
4133
|
+
if (challenge.expiresAt.isExpired())
|
|
4134
|
+
return { isValid: false };
|
|
4135
|
+
const backboneChallengeResponse = await this.authClient.getChallenge(challenge.id.toString());
|
|
4136
|
+
if (backboneChallengeResponse.isError)
|
|
4137
|
+
return { isValid: false };
|
|
4138
|
+
if ((challenge.createdBy && backboneChallengeResponse.value.createdBy !== challenge.createdBy.toString()) ||
|
|
4145
4139
|
// TODO: JSSNMSHDD-2472 (Reenable check once the backbone returns with same timestamp)
|
|
4146
4140
|
// response.expiresAt !== challenge.expiresAt.toString() ||
|
|
4147
|
-
|
|
4148
|
-
return;
|
|
4141
|
+
backboneChallengeResponse.value.id !== challenge.id.toString()) {
|
|
4142
|
+
return { isValid: false };
|
|
4149
4143
|
}
|
|
4150
|
-
return
|
|
4144
|
+
return await this.validateChallengeLocally(challenge, signedChallenge);
|
|
4151
4145
|
}
|
|
4152
4146
|
async createAccountCreationChallenge(identity) {
|
|
4153
4147
|
const backboneResponse = (await this.client.createChallenge()).value;
|
|
@@ -5252,29 +5246,12 @@ class FileController extends TransportController_1.TransportController {
|
|
|
5252
5246
|
if (ids.length < 1) {
|
|
5253
5247
|
return [];
|
|
5254
5248
|
}
|
|
5249
|
+
// TODO: JSSNMSHDD-2820 (check for items that couldn't be fetched e.g. because it is expired)
|
|
5250
|
+
const resultItems = (await this.client.getFiles({ ids })).value;
|
|
5255
5251
|
const promises = [];
|
|
5256
|
-
for (const id of ids) {
|
|
5257
|
-
const result = await this.client.getFile(id);
|
|
5258
|
-
if (result.isError) {
|
|
5259
|
-
if (result.error.code === "error.transport.recordNotFound" ||
|
|
5260
|
-
result.error.code === "error.transport.request.notFound" ||
|
|
5261
|
-
result.error.code === "error.platform.recordNotFound") {
|
|
5262
|
-
this.log.warn(`Record id ${id} could not be found on backbone. It might be expired.`, result.error);
|
|
5263
|
-
continue;
|
|
5264
|
-
}
|
|
5265
|
-
throw result.error;
|
|
5266
|
-
}
|
|
5267
|
-
const resultItem = result.value;
|
|
5268
|
-
promises.push(this.updateCacheOfExistingFileInDb(resultItem.id, resultItem));
|
|
5269
|
-
}
|
|
5270
|
-
/*
|
|
5271
|
-
// TODO: Optimize once backbone handling is clarified
|
|
5272
|
-
const resultItems = (await this.client.getFiles({ ids })).value
|
|
5273
|
-
const promises = []
|
|
5274
5252
|
for await (const resultItem of resultItems) {
|
|
5275
|
-
promises.push(this.updateCacheOfExistingFileInDb(resultItem.id, resultItem))
|
|
5253
|
+
promises.push(this.updateCacheOfExistingFileInDb(resultItem.id, resultItem));
|
|
5276
5254
|
}
|
|
5277
|
-
*/
|
|
5278
5255
|
return await Promise.all(promises);
|
|
5279
5256
|
}
|
|
5280
5257
|
async updateCacheOfExistingFileInDb(id, response) {
|
|
@@ -7160,29 +7137,12 @@ class RelationshipTemplateController extends TransportController_1.TransportCont
|
|
|
7160
7137
|
if (ids.length < 1) {
|
|
7161
7138
|
return [];
|
|
7162
7139
|
}
|
|
7140
|
+
// TODO: JSSNMSHDD-2820 (check for items that couldn't be fetched e.g. because it is expired)
|
|
7141
|
+
const resultItems = (await this.client.getRelationshipTemplates({ ids })).value;
|
|
7163
7142
|
const promises = [];
|
|
7164
|
-
for (const id of ids) {
|
|
7165
|
-
const result = await this.client.getRelationshipTemplate(id);
|
|
7166
|
-
if (result.isError) {
|
|
7167
|
-
if (result.error.code === "error.transport.recordNotFound" ||
|
|
7168
|
-
result.error.code === "error.transport.request.notFound" ||
|
|
7169
|
-
result.error.code === "error.platform.recordNotFound") {
|
|
7170
|
-
this.log.warn(`Record id ${id} could not be found on backbone. It might be expired.`, result.error);
|
|
7171
|
-
continue;
|
|
7172
|
-
}
|
|
7173
|
-
throw result.error;
|
|
7174
|
-
}
|
|
7175
|
-
const resultItem = result.value;
|
|
7176
|
-
promises.push(this.updateCacheOfExistingTemplateInDb(resultItem.id, resultItem));
|
|
7177
|
-
}
|
|
7178
|
-
/*
|
|
7179
|
-
// TODO: Optimize once backbone handling is clarified
|
|
7180
|
-
const resultItems = (await this.client.getRelationshipTemplates({ ids })).value
|
|
7181
|
-
const promises = []
|
|
7182
7143
|
for await (const resultItem of resultItems) {
|
|
7183
|
-
promises.push(this.updateCacheOfExistingTemplateInDb(resultItem.id, resultItem))
|
|
7144
|
+
promises.push(this.updateCacheOfExistingTemplateInDb(resultItem.id, resultItem));
|
|
7184
7145
|
}
|
|
7185
|
-
*/
|
|
7186
7146
|
return await Promise.all(promises);
|
|
7187
7147
|
}
|
|
7188
7148
|
async fetchCaches(ids) {
|
|
@@ -11067,30 +11027,14 @@ class TokenController extends TransportController_1.TransportController {
|
|
|
11067
11027
|
if (ids.length < 1) {
|
|
11068
11028
|
return [];
|
|
11069
11029
|
}
|
|
11030
|
+
// TODO: JSSNMSHDD-2820 (check for items that couldn't be fetched e.g. because it is expired)
|
|
11031
|
+
const resultItems = (await this.client.getTokens({ ids })).value;
|
|
11070
11032
|
const promises = [];
|
|
11071
|
-
for (const id of ids) {
|
|
11072
|
-
const result = await this.client.getToken(id);
|
|
11073
|
-
if (result.isError) {
|
|
11074
|
-
if (result.error.code === "error.transport.recordNotFound" ||
|
|
11075
|
-
result.error.code === "error.transport.request.notFound" ||
|
|
11076
|
-
result.error.code === "error.platform.recordNotFound") {
|
|
11077
|
-
this.log.warn(`Record id ${id} could not be found on backbone. It might be expired.`, result.error);
|
|
11078
|
-
continue;
|
|
11079
|
-
}
|
|
11080
|
-
throw result.error;
|
|
11081
|
-
}
|
|
11082
|
-
const resultItem = result.value;
|
|
11083
|
-
promises.push(this.updateCacheOfExistingTokenInDb(resultItem.id, resultItem));
|
|
11084
|
-
}
|
|
11085
|
-
/*
|
|
11086
|
-
// TODO: Optimize once backbone handling is clarified
|
|
11087
|
-
const resultItems = (await this.client.getTokens({ ids })).value
|
|
11088
|
-
const promises = []
|
|
11089
11033
|
for await (const resultItem of resultItems) {
|
|
11090
|
-
promises.push(this.updateCacheOfExistingTokenInDb(resultItem.id, resultItem))
|
|
11034
|
+
promises.push(this.updateCacheOfExistingTokenInDb(resultItem.id, resultItem));
|
|
11091
11035
|
}
|
|
11092
|
-
|
|
11093
|
-
return await Promise.all(promises);
|
|
11036
|
+
const isToken = (item) => !!item;
|
|
11037
|
+
return (await Promise.all(promises)).filter(isToken);
|
|
11094
11038
|
}
|
|
11095
11039
|
async fetchCaches(ids) {
|
|
11096
11040
|
if (ids.length === 0)
|
|
@@ -11106,7 +11050,8 @@ class TokenController extends TransportController_1.TransportController {
|
|
|
11106
11050
|
async updateCacheOfExistingTokenInDb(id, response) {
|
|
11107
11051
|
const tokenDoc = await this.tokens.read(id);
|
|
11108
11052
|
if (!tokenDoc) {
|
|
11109
|
-
|
|
11053
|
+
core_1.TransportErrors.general.recordNotFound(Token_1.Token, id).logWith(this._log);
|
|
11054
|
+
return;
|
|
11110
11055
|
}
|
|
11111
11056
|
const token = await Token_1.Token.from(tokenDoc);
|
|
11112
11057
|
await this.updateCacheOfToken(token, response);
|
|
@@ -11149,7 +11094,16 @@ class TokenController extends TransportController_1.TransportController {
|
|
|
11149
11094
|
async loadPeerToken(id, secretKey, ephemeral) {
|
|
11150
11095
|
const tokenDoc = await this.tokens.read(id.toString());
|
|
11151
11096
|
if (tokenDoc) {
|
|
11152
|
-
|
|
11097
|
+
let token = await Token_1.Token.from(tokenDoc);
|
|
11098
|
+
if (token.cache) {
|
|
11099
|
+
return token;
|
|
11100
|
+
}
|
|
11101
|
+
token = await this.updateCacheOfExistingTokenInDb(id.toString());
|
|
11102
|
+
if (!token) {
|
|
11103
|
+
// This should not happen, we only update the cache if we found the tokenDoc
|
|
11104
|
+
throw new Error(`Tried to update a token (with ID: '${id.toString()}') that doesn't exist in the local database.`);
|
|
11105
|
+
}
|
|
11106
|
+
return token;
|
|
11153
11107
|
}
|
|
11154
11108
|
const token = await Token_1.Token.from({
|
|
11155
11109
|
id: id,
|
|
@@ -12081,7 +12035,7 @@ class SimpleLogger {
|
|
|
12081
12035
|
if (arg instanceof Error) {
|
|
12082
12036
|
return (_a = arg.stack) !== null && _a !== void 0 ? _a : `${arg.name}: ${arg.message}`;
|
|
12083
12037
|
}
|
|
12084
|
-
return json_stringify_safe_1.default(arg);
|
|
12038
|
+
return (0, json_stringify_safe_1.default)(arg);
|
|
12085
12039
|
})
|
|
12086
12040
|
.join("\n");
|
|
12087
12041
|
return { msg: message };
|
|
@@ -13151,10 +13105,6 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|
|
13151
13105
|
config = configOrUrl || {};
|
|
13152
13106
|
}
|
|
13153
13107
|
|
|
13154
|
-
if (!config.url) {
|
|
13155
|
-
throw new Error('Provided config url is not valid');
|
|
13156
|
-
}
|
|
13157
|
-
|
|
13158
13108
|
config = mergeConfig(this.defaults, config);
|
|
13159
13109
|
|
|
13160
13110
|
// Set config.method
|
|
@@ -13237,9 +13187,6 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|
|
13237
13187
|
};
|
|
13238
13188
|
|
|
13239
13189
|
Axios.prototype.getUri = function getUri(config) {
|
|
13240
|
-
if (!config.url) {
|
|
13241
|
-
throw new Error('Provided config url is not valid');
|
|
13242
|
-
}
|
|
13243
13190
|
config = mergeConfig(this.defaults, config);
|
|
13244
13191
|
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
|
|
13245
13192
|
};
|
|
@@ -13880,7 +13827,7 @@ module.exports = defaults;
|
|
|
13880
13827
|
/***/ ((module) => {
|
|
13881
13828
|
|
|
13882
13829
|
module.exports = {
|
|
13883
|
-
"version": "0.
|
|
13830
|
+
"version": "0.26.0"
|
|
13884
13831
|
};
|
|
13885
13832
|
|
|
13886
13833
|
/***/ }),
|