@nmshd/transport 2.0.0-beta.5 → 2.0.0-beta.6
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/core/CoreCrypto.d.ts +1 -0
- package/dist/core/CoreCrypto.js +14 -12
- package/dist/core/CoreCrypto.js.map +1 -1
- package/dist/core/CoreUtil.js +1 -2
- package/dist/core/CoreUtil.js.map +1 -1
- package/dist/core/Reference.js +2 -2
- package/dist/core/Reference.js.map +1 -1
- package/dist/core/Transport.js +4 -1
- package/dist/core/Transport.js.map +1 -1
- package/dist/core/TransportController.d.ts +1 -1
- package/dist/core/TransportController.js +2 -3
- package/dist/core/TransportController.js.map +1 -1
- package/dist/core/TransportErrors.d.ts +5 -73
- package/dist/core/TransportErrors.js +10 -153
- package/dist/core/TransportErrors.js.map +1 -1
- package/dist/core/TransportLoggerFactory.js +1 -2
- package/dist/core/TransportLoggerFactory.js.map +1 -1
- package/dist/core/types/CoreAddress.d.ts +1 -1
- package/dist/core/types/CoreAddress.js.map +1 -1
- package/dist/core/types/CoreDate.js +3 -4
- package/dist/core/types/CoreDate.js.map +1 -1
- package/dist/core/types/CoreId.d.ts +1 -1
- package/dist/core/types/CoreId.js +1 -2
- package/dist/core/types/CoreId.js.map +1 -1
- package/dist/modules/accounts/AccountController.d.ts +2 -0
- package/dist/modules/accounts/AccountController.js +30 -8
- package/dist/modules/accounts/AccountController.js.map +1 -1
- package/dist/modules/accounts/IdentityController.d.ts +1 -1
- package/dist/modules/accounts/IdentityController.js +24 -4
- package/dist/modules/accounts/IdentityController.js.map +1 -1
- package/dist/modules/accounts/IdentityUtil.d.ts +1 -1
- package/dist/modules/accounts/IdentityUtil.js +3 -4
- package/dist/modules/accounts/IdentityUtil.js.map +1 -1
- package/dist/modules/challenges/ChallengeController.js +26 -3
- package/dist/modules/challenges/ChallengeController.js.map +1 -1
- package/dist/modules/devices/DeviceController.d.ts +1 -1
- package/dist/modules/devices/DeviceController.js +41 -12
- package/dist/modules/devices/DeviceController.js.map +1 -1
- package/dist/modules/devices/DeviceSecretController.js +43 -13
- package/dist/modules/devices/DeviceSecretController.js.map +1 -1
- package/dist/modules/files/FileController.js +42 -8
- package/dist/modules/files/FileController.js.map +1 -1
- package/dist/modules/messages/MessageController.js +66 -12
- package/dist/modules/messages/MessageController.js.map +1 -1
- package/dist/modules/relationshipTemplates/RelationshipTemplateController.js +31 -3
- package/dist/modules/relationshipTemplates/RelationshipTemplateController.js.map +1 -1
- package/dist/modules/relationships/RelationshipSecretController.js +88 -17
- package/dist/modules/relationships/RelationshipSecretController.js.map +1 -1
- package/dist/modules/relationships/RelationshipsController.d.ts +3 -3
- package/dist/modules/relationships/RelationshipsController.js +112 -59
- package/dist/modules/relationships/RelationshipsController.js.map +1 -1
- package/dist/modules/secrets/SecretController.js +18 -4
- package/dist/modules/secrets/SecretController.js.map +1 -1
- package/dist/modules/sync/DatawalletModificationsProcessor.d.ts +1 -0
- package/dist/modules/sync/DatawalletModificationsProcessor.js +20 -3
- package/dist/modules/sync/DatawalletModificationsProcessor.js.map +1 -1
- package/dist/modules/sync/SyncController.d.ts +1 -0
- package/dist/modules/sync/SyncController.js +53 -24
- package/dist/modules/sync/SyncController.js.map +1 -1
- package/dist/modules/tokens/TokenController.js +31 -3
- package/dist/modules/tokens/TokenController.js.map +1 -1
- package/dist/util/PasswordGenerator.js +1 -2
- package/dist/util/PasswordGenerator.js.map +1 -1
- package/dist/util/Random.js +7 -8
- package/dist/util/Random.js.map +1 -1
- package/lib-web/nmshd.transport.js +734 -407
- 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 +6 -6
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.IdentityController = void 0;
|
|
13
|
+
const ts_utils_1 = require("@js-soft/ts-utils");
|
|
4
14
|
const crypto_1 = require("@nmshd/crypto");
|
|
5
15
|
const core_1 = require("../../core");
|
|
6
16
|
const DeviceSecretController_1 = require("../devices/DeviceSecretController");
|
|
17
|
+
const Identity_1 = require("./data/Identity");
|
|
7
18
|
class IdentityController extends core_1.TransportController {
|
|
8
19
|
constructor(parent) {
|
|
9
20
|
super(core_1.ControllerName.Identity, parent);
|
|
@@ -22,9 +33,6 @@ class IdentityController extends core_1.TransportController {
|
|
|
22
33
|
}
|
|
23
34
|
async init(identity) {
|
|
24
35
|
await super.init();
|
|
25
|
-
if (!identity) {
|
|
26
|
-
throw core_1.TransportErrors.identity.identityNotSet().logWith(this._log);
|
|
27
|
-
}
|
|
28
36
|
this._identity = identity;
|
|
29
37
|
return this;
|
|
30
38
|
}
|
|
@@ -37,7 +45,7 @@ class IdentityController extends core_1.TransportController {
|
|
|
37
45
|
async sign(content) {
|
|
38
46
|
const privateKeyContainer = await this.parent.activeDevice.secrets.loadSecret(DeviceSecretController_1.DeviceSecretType.IdentitySignature);
|
|
39
47
|
if (!privateKeyContainer || !(privateKeyContainer.secret instanceof crypto_1.CryptoSignaturePrivateKey)) {
|
|
40
|
-
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.IdentitySignature)
|
|
48
|
+
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.IdentitySignature);
|
|
41
49
|
}
|
|
42
50
|
const privateKey = privateKeyContainer.secret;
|
|
43
51
|
const signature = await core_1.CoreCrypto.sign(content, privateKey);
|
|
@@ -49,5 +57,17 @@ class IdentityController extends core_1.TransportController {
|
|
|
49
57
|
return valid;
|
|
50
58
|
}
|
|
51
59
|
}
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, ts_utils_1.log)(),
|
|
62
|
+
__metadata("design:type", Function),
|
|
63
|
+
__metadata("design:paramtypes", [Identity_1.Identity]),
|
|
64
|
+
__metadata("design:returntype", Promise)
|
|
65
|
+
], IdentityController.prototype, "init", null);
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, ts_utils_1.log)(),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", [crypto_1.CoreBuffer]),
|
|
70
|
+
__metadata("design:returntype", Promise)
|
|
71
|
+
], IdentityController.prototype, "sign", null);
|
|
52
72
|
exports.IdentityController = IdentityController;
|
|
53
73
|
//# sourceMappingURL=IdentityController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityController.js","sourceRoot":"","sources":["../../../src/modules/accounts/IdentityController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IdentityController.js","sourceRoot":"","sources":["../../../src/modules/accounts/IdentityController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAuC;AACvC,0CAAgH;AAChH,qCAA0G;AAE1G,8EAAoE;AACpE,8CAAiD;AAEjD,MAAa,kBAAmB,SAAQ,0BAAmB;IAkBvD,YAAmB,MAAyB;QACxC,KAAK,CAAC,qBAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC;IAnBD,IAAW,OAAO;QACd,OAAO,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CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,OAAmB,EAAE,SAA0B;QAC/D,MAAM,KAAK,GAAG,MAAM,iBAAU,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QACzE,OAAO,KAAK,CAAA;IAChB,CAAC;CACJ;AAlCyB;IADrB,IAAA,cAAG,GAAE;;qCAC+B,mBAAQ;;8CAK5C;AAWY;IADZ,IAAA,cAAG,GAAE;;qCACqB,mBAAU;;8CAYpC;AAnDL,gDAyDC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ICryptoSignaturePublicKey } from "@nmshd/crypto";
|
|
2
2
|
import { CoreAddress } from "../../core";
|
|
3
3
|
export declare class IdentityUtil {
|
|
4
|
-
static createAddress(publicKey: ICryptoSignaturePublicKey, realm
|
|
4
|
+
static createAddress(publicKey: ICryptoSignaturePublicKey, realm: string): Promise<CoreAddress>;
|
|
5
5
|
static checkAddress(address: CoreAddress, publicKey?: ICryptoSignaturePublicKey, realm?: string): Promise<boolean>;
|
|
6
6
|
}
|
|
@@ -4,10 +4,9 @@ exports.IdentityUtil = void 0;
|
|
|
4
4
|
const crypto_1 = require("@nmshd/crypto");
|
|
5
5
|
const core_1 = require("../../core");
|
|
6
6
|
class IdentityUtil {
|
|
7
|
-
static async createAddress(publicKey, realm
|
|
8
|
-
if (realm
|
|
9
|
-
throw core_1.TransportErrors.
|
|
10
|
-
}
|
|
7
|
+
static async createAddress(publicKey, realm) {
|
|
8
|
+
if (realm.length !== 3)
|
|
9
|
+
throw core_1.TransportErrors.general.realmLength();
|
|
11
10
|
const sha512buffer = await crypto_1.CryptoHash.hash(publicKey.publicKey, 2 /* CryptoHashAlgorithm.SHA512 */);
|
|
12
11
|
const hash = await crypto_1.CryptoHash.hash(sha512buffer, 1 /* CryptoHashAlgorithm.SHA256 */);
|
|
13
12
|
const hashedPublicKey = new crypto_1.CoreBuffer(hash.buffer.slice(0, 20));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityUtil.js","sourceRoot":"","sources":["../../../src/modules/accounts/IdentityUtil.ts"],"names":[],"mappings":";;;AAAA,0CAAsG;AACtG,qCAAyD;AAEzD,MAAa,YAAY;IACd,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,SAAoC,EAAE,
|
|
1
|
+
{"version":3,"file":"IdentityUtil.js","sourceRoot":"","sources":["../../../src/modules/accounts/IdentityUtil.ts"],"names":[],"mappings":";;;AAAA,0CAAsG;AACtG,qCAAyD;AAEzD,MAAa,YAAY;IACd,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,SAAoC,EAAE,KAAa;QACjF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,sBAAe,CAAC,OAAO,CAAC,WAAW,EAAE,CAAA;QAEnE,MAAM,YAAY,GAAG,MAAM,mBAAU,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,qCAA6B,CAAA;QAC3F,MAAM,IAAI,GAAG,MAAM,mBAAU,CAAC,IAAI,CAAC,YAAY,qCAA6B,CAAA;QAC5E,MAAM,eAAe,GAAG,IAAI,mBAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QAEhE,MAAM,cAAc,GAAG,mBAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QACjD,cAAc,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;QAEtC,MAAM,gBAAgB,GAAG,MAAM,mBAAU,CAAC,IAAI,CAAC,cAAc,qCAA6B,CAAA;QAC1F,MAAM,YAAY,GAAG,MAAM,mBAAU,CAAC,IAAI,CAAC,gBAAgB,qCAA6B,CAAA;QACxF,MAAM,QAAQ,GAAG,IAAI,mBAAU,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAEhE,MAAM,aAAa,GAAG,eAAe,CAAA;QAC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AoB,GAAG,IAAI,mBAAU,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAChF,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,mBAAU,CAAC,aAAa,CAAC,CAAC,EAAE;YAC7D,OAAO,KAAK,CAAA;SACf;QAED,IAAI,SAAS,EAAE;YACX,MAAM,YAAY,GAAG,MAAM,mBAAU,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,qCAA6B,CAAA;YAC3F,IAAI,YAAY,GAAG,MAAM,mBAAU,CAAC,IAAI,CAAC,YAAY,qCAA6B,CAAA;YAClF,YAAY,GAAG,IAAI,mBAAU,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;YAC/D,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,mBAAU,CAAC,WAAW,CAAC,CAAC,EAAE;gBACnD,4CAA4C;gBAC5C,OAAO,KAAK,CAAA;aACf;SACJ;QACD,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AA7DD,oCA6DC"}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.ChallengeController = void 0;
|
|
13
|
+
const ts_utils_1 = require("@js-soft/ts-utils");
|
|
4
14
|
const crypto_1 = require("@nmshd/crypto");
|
|
5
15
|
const core_1 = require("../../core");
|
|
6
16
|
const TransportController_1 = require("../../core/TransportController");
|
|
@@ -33,7 +43,7 @@ class ChallengeController extends TransportController_1.TransportController {
|
|
|
33
43
|
isValid = await this.parent.relationships.verifyIdentity(relationship, challengeBuffer, signedChallenge.signature);
|
|
34
44
|
break;
|
|
35
45
|
case Challenge_1.ChallengeType.Device:
|
|
36
|
-
throw core_1.TransportErrors.general.
|
|
46
|
+
throw core_1.TransportErrors.general.notSupported();
|
|
37
47
|
case Challenge_1.ChallengeType.Relationship:
|
|
38
48
|
isValid = await this.parent.relationships.verify(relationship, challengeBuffer, signedChallenge.signature);
|
|
39
49
|
break;
|
|
@@ -77,7 +87,7 @@ class ChallengeController extends TransportController_1.TransportController {
|
|
|
77
87
|
}
|
|
78
88
|
async createChallenge(type = Challenge_1.ChallengeType.Identity, relationship) {
|
|
79
89
|
if (type === Challenge_1.ChallengeType.Relationship && !relationship) {
|
|
80
|
-
throw core_1.TransportErrors.challenges.
|
|
90
|
+
throw core_1.TransportErrors.challenges.challengeTypeRequiresRelationship();
|
|
81
91
|
}
|
|
82
92
|
const backboneResponse = (await this.authClient.createChallenge()).value;
|
|
83
93
|
const challenge = Challenge_1.Challenge.from({
|
|
@@ -101,7 +111,7 @@ class ChallengeController extends TransportController_1.TransportController {
|
|
|
101
111
|
break;
|
|
102
112
|
case Challenge_1.ChallengeType.Relationship:
|
|
103
113
|
if (!relationship) {
|
|
104
|
-
throw core_1.TransportErrors.challenges.
|
|
114
|
+
throw core_1.TransportErrors.challenges.challengeTypeRequiresRelationship();
|
|
105
115
|
}
|
|
106
116
|
signature = await this.parent.relationships.sign(relationship, challengeBuffer);
|
|
107
117
|
break;
|
|
@@ -113,5 +123,18 @@ class ChallengeController extends TransportController_1.TransportController {
|
|
|
113
123
|
return signedChallenge;
|
|
114
124
|
}
|
|
115
125
|
}
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, ts_utils_1.log)(),
|
|
128
|
+
__metadata("design:type", Function),
|
|
129
|
+
__metadata("design:paramtypes", [Challenge_1.Challenge,
|
|
130
|
+
ChallengeSigned_1.ChallengeSigned]),
|
|
131
|
+
__metadata("design:returntype", Promise)
|
|
132
|
+
], ChallengeController.prototype, "validateChallengeLocally", null);
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, ts_utils_1.log)(),
|
|
135
|
+
__metadata("design:type", Function),
|
|
136
|
+
__metadata("design:paramtypes", [String, Relationship_1.Relationship]),
|
|
137
|
+
__metadata("design:returntype", Promise)
|
|
138
|
+
], ChallengeController.prototype, "createChallenge", null);
|
|
116
139
|
exports.ChallengeController = ChallengeController;
|
|
117
140
|
//# sourceMappingURL=ChallengeController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChallengeController.js","sourceRoot":"","sources":["../../../src/modules/challenges/ChallengeController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChallengeController.js","sourceRoot":"","sources":["../../../src/modules/challenges/ChallengeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAuC;AACvC,0CAAkE;AAClE,qCAAuF;AACvF,wEAAoF;AAEpF,sEAAkE;AAClE,wEAAoE;AACpE,gEAA4D;AAC5D,gDAA2D;AAC3D,4DAAwD;AAExD,MAAa,mBAAoB,SAAQ,yCAAmB;IAIxD,YAAmB,MAAyB;QACxC,KAAK,CAAC,oCAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC3C,CAAC;IAEe,KAAK,CAAC,IAAI;QACtB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QAElB,IAAI,CAAC,MAAM,GAAG,IAAI,iCAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;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,CAAC,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC;gBAC/C,CAAC,CAAC,SAAS;YACf,IAAI,EAAE,IAAI;SACb,CAAC,CAAA;QAEF,MAAM,mBAAmB,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QACtD,MAAM,eAAe,GAAG,mBAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAA;QAChE,IAAI,SAAS,CAAA;QACb,QAAQ,IAAI,EAAE;YACV,KAAK,yBAAa,CAAC,QAAQ;gBACvB,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;gBAC5D,MAAK;YACT,KAAK,yBAAa,CAAC,MAAM;gBACrB,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;gBAChE,MAAK;YACT,KAAK,yBAAa,CAAC,YAAY;gBAC3B,IAAI,CAAC,YAAY,EAAE;oBACf,MAAM,sBAAe,CAAC,UAAU,CAAC,iCAAiC,EAAE,CAAA;iBACvE;gBACD,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,eAAe,CAAC,CAAA;gBAC/E,MAAK;SACZ;QAED,MAAM,eAAe,GAAG,iCAAe,CAAC,IAAI,CAAC;YACzC,SAAS,EAAE,mBAAmB;YAC9B,SAAS,EAAE,SAAS;SACvB,CAAC,CAAA;QACF,OAAO,eAAe,CAAA;IAC1B,CAAC;CACJ;AAxHiB;IADb,IAAA,cAAG,GAAE;;qCAES,qBAAS;QACH,iCAAe;;mEAgCnC;AA2CY;IADZ,IAAA,cAAG,GAAE;;6CAGa,2BAAY;;0DAwC9B;AAxIL,kDAyIC"}
|
|
@@ -18,7 +18,7 @@ export declare class DeviceController extends TransportController {
|
|
|
18
18
|
get device(): Device;
|
|
19
19
|
get deviceOrUndefined(): Device | undefined;
|
|
20
20
|
constructor(parent: AccountController);
|
|
21
|
-
init(baseKey
|
|
21
|
+
init(baseKey: CryptoSecretKey, device: Device): Promise<DeviceController>;
|
|
22
22
|
changePassword(newPassword: string): Promise<void>;
|
|
23
23
|
update(update: {
|
|
24
24
|
name?: string;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DeviceController = void 0;
|
|
13
|
+
const ts_utils_1 = require("@js-soft/ts-utils");
|
|
4
14
|
const crypto_1 = require("@nmshd/crypto");
|
|
5
15
|
const core_1 = require("../../core");
|
|
6
16
|
const DeviceSecretController_1 = require("./DeviceSecretController");
|
|
17
|
+
const Device_1 = require("./local/Device");
|
|
7
18
|
const DeviceSecretCredentials_1 = require("./local/DeviceSecretCredentials");
|
|
8
19
|
class DeviceController extends core_1.TransportController {
|
|
9
20
|
constructor(parent) {
|
|
@@ -38,7 +49,7 @@ class DeviceController extends core_1.TransportController {
|
|
|
38
49
|
}
|
|
39
50
|
get device() {
|
|
40
51
|
if (!this._device)
|
|
41
|
-
throw
|
|
52
|
+
throw new Error("The Device controller is not initialized.");
|
|
42
53
|
return this._device;
|
|
43
54
|
}
|
|
44
55
|
get deviceOrUndefined() {
|
|
@@ -46,12 +57,6 @@ class DeviceController extends core_1.TransportController {
|
|
|
46
57
|
}
|
|
47
58
|
async init(baseKey, device) {
|
|
48
59
|
await super.init();
|
|
49
|
-
if (!device) {
|
|
50
|
-
throw core_1.TransportErrors.device.deviceNotSet().logWith(this._log);
|
|
51
|
-
}
|
|
52
|
-
if (!baseKey) {
|
|
53
|
-
throw core_1.TransportErrors.secrets.secretNotFound("BaseKey").logWith(this._log);
|
|
54
|
-
}
|
|
55
60
|
this._device = device;
|
|
56
61
|
this._secrets = await new DeviceSecretController_1.DeviceSecretController(this.parent, baseKey).init();
|
|
57
62
|
return this;
|
|
@@ -90,7 +95,7 @@ class DeviceController extends core_1.TransportController {
|
|
|
90
95
|
async sign(content) {
|
|
91
96
|
const privateKeyContainer = await this.secrets.loadSecret(DeviceSecretController_1.DeviceSecretType.DeviceSignature);
|
|
92
97
|
if (!privateKeyContainer || !(privateKeyContainer.secret instanceof crypto_1.CryptoSignaturePrivateKey)) {
|
|
93
|
-
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceSignature)
|
|
98
|
+
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceSignature);
|
|
94
99
|
}
|
|
95
100
|
const privateKey = privateKeyContainer.secret;
|
|
96
101
|
const signature = await core_1.CoreCrypto.sign(content, privateKey);
|
|
@@ -99,21 +104,21 @@ class DeviceController extends core_1.TransportController {
|
|
|
99
104
|
}
|
|
100
105
|
async verify(content, signature) {
|
|
101
106
|
if (!this.publicKey) {
|
|
102
|
-
throw
|
|
107
|
+
throw new Error("The device has no public key to verify a signature. This can happen if the device is not onboarded yet.");
|
|
103
108
|
}
|
|
104
109
|
return await core_1.CoreCrypto.verify(content, signature, this.publicKey);
|
|
105
110
|
}
|
|
106
111
|
async getCredentials() {
|
|
107
112
|
const credentialContainer = await this.secrets.loadSecret(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
|
|
108
113
|
if (!credentialContainer) {
|
|
109
|
-
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceCredentials)
|
|
114
|
+
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
|
|
110
115
|
}
|
|
111
116
|
if (!(credentialContainer.secret instanceof DeviceSecretCredentials_1.DeviceSecretCredentials)) {
|
|
112
|
-
throw core_1.TransportErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials)
|
|
117
|
+
throw core_1.TransportErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
|
|
113
118
|
}
|
|
114
119
|
const credentials = credentialContainer.secret;
|
|
115
120
|
if (!credentials.username || !credentials.password) {
|
|
116
|
-
throw core_1.TransportErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials)
|
|
121
|
+
throw core_1.TransportErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
|
|
117
122
|
}
|
|
118
123
|
return {
|
|
119
124
|
username: credentials.username,
|
|
@@ -121,5 +126,29 @@ class DeviceController extends core_1.TransportController {
|
|
|
121
126
|
};
|
|
122
127
|
}
|
|
123
128
|
}
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, ts_utils_1.log)(),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", [crypto_1.CryptoSecretKey, Device_1.Device]),
|
|
133
|
+
__metadata("design:returntype", Promise)
|
|
134
|
+
], DeviceController.prototype, "init", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, ts_utils_1.log)(),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", [crypto_1.CoreBuffer]),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], DeviceController.prototype, "sign", null);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, ts_utils_1.log)(),
|
|
143
|
+
__metadata("design:type", Function),
|
|
144
|
+
__metadata("design:paramtypes", [crypto_1.CoreBuffer, crypto_1.CryptoSignature]),
|
|
145
|
+
__metadata("design:returntype", Promise)
|
|
146
|
+
], DeviceController.prototype, "verify", null);
|
|
147
|
+
__decorate([
|
|
148
|
+
(0, ts_utils_1.log)(),
|
|
149
|
+
__metadata("design:type", Function),
|
|
150
|
+
__metadata("design:paramtypes", []),
|
|
151
|
+
__metadata("design:returntype", Promise)
|
|
152
|
+
], DeviceController.prototype, "getCredentials", null);
|
|
124
153
|
exports.DeviceController = DeviceController;
|
|
125
154
|
//# sourceMappingURL=DeviceController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceController.js","sourceRoot":"","sources":["../../../src/modules/devices/DeviceController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeviceController.js","sourceRoot":"","sources":["../../../src/modules/devices/DeviceController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAuC;AACvC,0CAMsB;AACtB,qCAQmB;AAEnB,qEAAmF;AACnF,2CAAmD;AACnD,6EAAyE;AAEzE,MAAa,gBAAiB,SAAQ,0BAAmB;IA+CrD,YAAmB,MAAyB;QACxC,KAAK,CAAC,qBAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,CAAC;IAhDD,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAA;IACxB,CAAC;IAGD,IAAW,EAAE;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA;IACzB,CAAC;IAED,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAA;IAChC,CAAC;IAED,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAA;IAClC,CAAC;IAED,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,MAAM,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,EAAE,WAAW,CAAC,QAAQ;YAC9B,QAAQ,EAAE,WAAW,CAAC,QAAQ;SACjC,CAAA;IACL,CAAC;CACJ;AAzFyB;IADrB,IAAA,cAAG,GAAE;;qCAC8B,wBAAe,EAAU,eAAM;;4CAOlE;AAqCY;IADZ,IAAA,cAAG,GAAE;;qCACqB,mBAAU;;4CAUpC;AAGY;IADZ,IAAA,cAAG,GAAE;;qCACuB,mBAAU,EAAa,wBAAe;;8CAQlE;AAGY;IADZ,IAAA,cAAG,GAAE;;;;sDAqBL;AA5IL,4CA6IC"}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DeviceSecretController = exports.DeviceSecretType = void 0;
|
|
4
13
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
14
|
+
const ts_utils_1 = require("@js-soft/ts-utils");
|
|
5
15
|
const crypto_1 = require("@nmshd/crypto");
|
|
6
16
|
const core_1 = require("../../core");
|
|
7
17
|
const TransportController_1 = require("../../core/TransportController");
|
|
8
18
|
const TransportIds_1 = require("../../core/TransportIds");
|
|
9
19
|
const SecretContainerCipher_1 = require("../secrets/data/SecretContainerCipher");
|
|
10
20
|
const SecretContainerPlain_1 = require("../secrets/data/SecretContainerPlain");
|
|
21
|
+
const DatawalletModification_1 = require("../sync/local/DatawalletModification");
|
|
22
|
+
const Device_1 = require("./local/Device");
|
|
11
23
|
const DeviceSharedSecret_1 = require("./transmission/DeviceSharedSecret");
|
|
12
24
|
var DeviceSecretType;
|
|
13
25
|
(function (DeviceSecretType) {
|
|
@@ -86,17 +98,17 @@ class DeviceSecretController extends TransportController_1.TransportController {
|
|
|
86
98
|
async createDeviceSharedSecret(device, deviceIndex, includeIdentityPrivateKey = false) {
|
|
87
99
|
const synchronizationKey = await this.loadSecret(DeviceSecretType.IdentitySynchronizationMaster);
|
|
88
100
|
if (!synchronizationKey || !(synchronizationKey.secret instanceof crypto_1.CryptoSecretKey)) {
|
|
89
|
-
throw core_1.TransportErrors.secrets.secretNotFound("SynchronizationKey")
|
|
101
|
+
throw core_1.TransportErrors.secrets.secretNotFound("SynchronizationKey");
|
|
90
102
|
}
|
|
91
103
|
const baseKey = await this.loadSecret(DeviceSecretType.SharedSecretBaseKey);
|
|
92
104
|
if (!baseKey || !(baseKey.secret instanceof crypto_1.CryptoSecretKey)) {
|
|
93
|
-
throw core_1.TransportErrors.secrets.secretNotFound("baseKey")
|
|
105
|
+
throw core_1.TransportErrors.secrets.secretNotFound("baseKey");
|
|
94
106
|
}
|
|
95
107
|
let identityPrivateKey;
|
|
96
108
|
if (includeIdentityPrivateKey) {
|
|
97
109
|
identityPrivateKey = await this.loadSecret(DeviceSecretType.IdentitySignature);
|
|
98
110
|
if (!identityPrivateKey || !(identityPrivateKey.secret instanceof crypto_1.CryptoSignaturePrivateKey)) {
|
|
99
|
-
throw core_1.TransportErrors.secrets.secretNotFound("IdentityKey")
|
|
111
|
+
throw core_1.TransportErrors.secrets.secretNotFound("IdentityKey");
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
114
|
const deviceSharedSecret = DeviceSharedSecret_1.DeviceSharedSecret.from({
|
|
@@ -123,9 +135,7 @@ class DeviceSecretController extends TransportController_1.TransportController {
|
|
|
123
135
|
const serializedEvent = crypto_1.CoreBuffer.fromUtf8(JSON.stringify(event.payload));
|
|
124
136
|
const privSync = await this.loadSecret(DeviceSecretType.IdentitySynchronizationMaster);
|
|
125
137
|
if (!privSync || !(privSync.secret instanceof crypto_1.CryptoSecretKey)) {
|
|
126
|
-
throw core_1.TransportErrors.secrets
|
|
127
|
-
.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster)
|
|
128
|
-
.logWith(this._log);
|
|
138
|
+
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster);
|
|
129
139
|
}
|
|
130
140
|
const encryptionKey = await core_1.CoreCrypto.deriveKeyFromBase(privSync.secret, index, "DataSync");
|
|
131
141
|
const cipher = await core_1.CoreCrypto.encrypt(serializedEvent, encryptionKey);
|
|
@@ -139,9 +149,7 @@ class DeviceSecretController extends TransportController_1.TransportController {
|
|
|
139
149
|
const payloadCipher = crypto_1.CryptoCipher.fromBase64(payloadCipherBase64);
|
|
140
150
|
const privSync = await this.loadSecret(DeviceSecretType.IdentitySynchronizationMaster);
|
|
141
151
|
if (!privSync || !(privSync.secret instanceof crypto_1.CryptoSecretKey)) {
|
|
142
|
-
throw core_1.TransportErrors.secrets
|
|
143
|
-
.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster)
|
|
144
|
-
.logWith(this._log);
|
|
152
|
+
throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster);
|
|
145
153
|
}
|
|
146
154
|
const decryptionKey = await core_1.CoreCrypto.deriveKeyFromBase(privSync.secret, index, "DataSync");
|
|
147
155
|
const plaintext = await core_1.CoreCrypto.decrypt(payloadCipher, decryptionKey);
|
|
@@ -151,13 +159,35 @@ class DeviceSecretController extends TransportController_1.TransportController {
|
|
|
151
159
|
}
|
|
152
160
|
getBaseKey() {
|
|
153
161
|
if (!this.baseKey) {
|
|
154
|
-
throw core_1.TransportErrors.general
|
|
155
|
-
.recordNotFound(crypto_1.CryptoSecretKey, DeviceSecretType.SharedSecretBaseKey)
|
|
156
|
-
.logWith(this._log);
|
|
162
|
+
throw core_1.TransportErrors.general.recordNotFound(crypto_1.CryptoSecretKey, DeviceSecretType.SharedSecretBaseKey);
|
|
157
163
|
}
|
|
158
164
|
return this.baseKey;
|
|
159
165
|
}
|
|
160
166
|
}
|
|
161
|
-
exports.DeviceSecretController = DeviceSecretController;
|
|
162
167
|
DeviceSecretController.secretContext = "DEVICE01";
|
|
168
|
+
__decorate([
|
|
169
|
+
(0, ts_utils_1.log)(),
|
|
170
|
+
__metadata("design:type", Function),
|
|
171
|
+
__metadata("design:paramtypes", [Device_1.Device, Number, Object]),
|
|
172
|
+
__metadata("design:returntype", Promise)
|
|
173
|
+
], DeviceSecretController.prototype, "createDeviceSharedSecret", null);
|
|
174
|
+
__decorate([
|
|
175
|
+
(0, ts_utils_1.log)(),
|
|
176
|
+
__metadata("design:type", Function),
|
|
177
|
+
__metadata("design:paramtypes", [DatawalletModification_1.DatawalletModification, Number]),
|
|
178
|
+
__metadata("design:returntype", Promise)
|
|
179
|
+
], DeviceSecretController.prototype, "encryptDatawalletModificationPayload", null);
|
|
180
|
+
__decorate([
|
|
181
|
+
(0, ts_utils_1.log)(),
|
|
182
|
+
__metadata("design:type", Function),
|
|
183
|
+
__metadata("design:paramtypes", [Object, Number]),
|
|
184
|
+
__metadata("design:returntype", Promise)
|
|
185
|
+
], DeviceSecretController.prototype, "decryptDatawalletModificationPayload", null);
|
|
186
|
+
__decorate([
|
|
187
|
+
(0, ts_utils_1.log)(),
|
|
188
|
+
__metadata("design:type", Function),
|
|
189
|
+
__metadata("design:paramtypes", []),
|
|
190
|
+
__metadata("design:returntype", crypto_1.CryptoSecretKey)
|
|
191
|
+
], DeviceSecretController.prototype, "getBaseKey", null);
|
|
192
|
+
exports.DeviceSecretController = DeviceSecretController;
|
|
163
193
|
//# sourceMappingURL=DeviceSecretController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceSecretController.js","sourceRoot":"","sources":["../../../src/modules/devices/DeviceSecretController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeviceSecretController.js","sourceRoot":"","sources":["../../../src/modules/devices/DeviceSecretController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,kDAAiD;AACjD,gDAAuC;AACvC,0CAUsB;AACtB,qCAAkE;AAClE,wEAAoF;AACpF,0DAAsD;AAEtD,iFAAqG;AACrG,+EAA2E;AAC3E,iFAA6E;AAC7E,2CAAuC;AAEvC,0EAAsE;AAEtE,IAAY,gBAOX;AAPD,WAAY,gBAAgB;IACxB,qFAAiE,CAAA;IACjE,4DAAwC,CAAA;IACxC,0DAAsC,CAAA;IACtC,0DAAsC,CAAA;IACtC,wDAAoC,CAAA;IACpC,4DAAwC,CAAA;AAC5C,CAAC,EAPW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAO3B;AAED;;;;GAIG;AACH,MAAa,sBAAuB,SAAQ,yCAAmB;IAO3D,YAAmB,MAAyB,EAAE,OAAwB;QAClE,KAAK,CAAC,oCAAc,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;IAEe,KAAK,CAAC,IAAI;QACtB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QAElB,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;QAEpD,OAAO,IAAI,CAAA;IACf,CAAC;IAEM,KAAK,CAAC,WAAW,CACpB,MAMqB,EACrB,IAAY;QAEZ,MAAM,WAAW,GAAW,MAAM,CAAC,SAAS,EAAE,CAAA;QAC9C,MAAM,WAAW,GAAe,mBAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;QAEhE,MAAM,aAAa,GAAoB,MAAM,iBAAU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 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.FileController = void 0;
|
|
13
|
+
const ts_utils_1 = require("@js-soft/ts-utils");
|
|
4
14
|
const crypto_1 = require("@nmshd/crypto");
|
|
5
15
|
const core_1 = require("../../core");
|
|
6
16
|
const DbCollectionName_1 = require("../../core/DbCollectionName");
|
|
@@ -55,7 +65,7 @@ class FileController extends TransportController_1.TransportController {
|
|
|
55
65
|
async updateCacheOfExistingFileInDb(id, response) {
|
|
56
66
|
const fileDoc = await this.files.read(id);
|
|
57
67
|
if (!fileDoc) {
|
|
58
|
-
throw core_1.TransportErrors.general.recordNotFound(File_1.File, id)
|
|
68
|
+
throw core_1.TransportErrors.general.recordNotFound(File_1.File, id);
|
|
59
69
|
}
|
|
60
70
|
const file = File_1.File.from(fileDoc);
|
|
61
71
|
await this.updateCacheOfFile(file, response);
|
|
@@ -77,7 +87,7 @@ class FileController extends TransportController_1.TransportController {
|
|
|
77
87
|
const plaintextMetadataBuffer = await core_1.CoreCrypto.decrypt(cipher, secretKey);
|
|
78
88
|
const plaintextMetadata = FileMetadata_1.FileMetadata.deserialize(plaintextMetadataBuffer.toUtf8());
|
|
79
89
|
if (!(plaintextMetadata instanceof FileMetadata_1.FileMetadata)) {
|
|
80
|
-
throw core_1.TransportErrors.files.invalidMetadata(response.id)
|
|
90
|
+
throw core_1.TransportErrors.files.invalidMetadata(response.id);
|
|
81
91
|
}
|
|
82
92
|
// TODO: JSSNMSHDD-2486 (check signature)
|
|
83
93
|
const cachedFile = CachedFile_1.CachedFile.fromBackbone(response, plaintextMetadata);
|
|
@@ -110,7 +120,7 @@ class FileController extends TransportController_1.TransportController {
|
|
|
110
120
|
const id = idOrFile instanceof core_1.CoreId ? idOrFile.toString() : idOrFile.id.toString();
|
|
111
121
|
const fileDoc = await this.files.read(id);
|
|
112
122
|
if (!fileDoc) {
|
|
113
|
-
throw core_1.TransportErrors.general.recordNotFound(File_1.File, id.toString())
|
|
123
|
+
throw core_1.TransportErrors.general.recordNotFound(File_1.File, id.toString());
|
|
114
124
|
}
|
|
115
125
|
const file = File_1.File.from(fileDoc);
|
|
116
126
|
file.setMetadata(metadata);
|
|
@@ -185,33 +195,57 @@ class FileController extends TransportController_1.TransportController {
|
|
|
185
195
|
async downloadFileContent(idOrFile) {
|
|
186
196
|
const file = idOrFile instanceof File_1.File ? idOrFile : await this.getFile(idOrFile);
|
|
187
197
|
if (!file) {
|
|
188
|
-
throw core_1.TransportErrors.general.recordNotFound(File_1.File, idOrFile.toString())
|
|
198
|
+
throw core_1.TransportErrors.general.recordNotFound(File_1.File, idOrFile.toString());
|
|
189
199
|
}
|
|
190
200
|
if (!file.cache) {
|
|
191
|
-
throw core_1.TransportErrors.general.cacheEmpty(File_1.File, file.id.toString())
|
|
201
|
+
throw core_1.TransportErrors.general.cacheEmpty(File_1.File, file.id.toString());
|
|
192
202
|
}
|
|
193
203
|
const downloadResponse = (await this.client.downloadFile(file.id.toString())).value;
|
|
194
204
|
const buffer = crypto_1.CoreBuffer.fromObject(downloadResponse);
|
|
195
205
|
const hash = await crypto_1.CryptoHash.hash(buffer, 2 /* CryptoHashAlgorithm.SHA512 */);
|
|
196
206
|
const hashb64 = hash.toBase64URL();
|
|
197
207
|
if (hashb64 !== file.cache.cipherHash.hash) {
|
|
198
|
-
throw core_1.TransportErrors.files.cipherMismatch()
|
|
208
|
+
throw core_1.TransportErrors.files.cipherMismatch();
|
|
199
209
|
}
|
|
200
210
|
/*
|
|
201
211
|
// TODO: JSSNMSHDD-2486 (verify owner signature)
|
|
202
212
|
const valid = await Crypto.verify(parcel.cipher.cipher, parcel.ownerSignature, owner.signing)
|
|
203
213
|
if (!valid) {
|
|
204
|
-
throw CoreErrors.General.SignatureNotValid("file")
|
|
214
|
+
throw CoreErrors.General.SignatureNotValid("file")
|
|
205
215
|
}
|
|
206
216
|
*/
|
|
207
217
|
const cipher = crypto_1.CryptoCipher.fromBase64(buffer.toBase64URL());
|
|
208
218
|
const decrypt = await core_1.CoreCrypto.decrypt(cipher, file.cache.cipherKey);
|
|
209
219
|
const plaintextHashesMatch = await file.cache.plaintextHash.verify(decrypt, 2 /* CryptoHashAlgorithm.SHA512 */);
|
|
210
220
|
if (!plaintextHashesMatch) {
|
|
211
|
-
throw core_1.TransportErrors.files.plaintextHashMismatch()
|
|
221
|
+
throw core_1.TransportErrors.files.plaintextHashMismatch();
|
|
212
222
|
}
|
|
213
223
|
return decrypt;
|
|
214
224
|
}
|
|
215
225
|
}
|
|
226
|
+
__decorate([
|
|
227
|
+
(0, ts_utils_1.log)(),
|
|
228
|
+
__metadata("design:type", Function),
|
|
229
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
230
|
+
__metadata("design:returntype", Promise)
|
|
231
|
+
], FileController.prototype, "updateCacheOfExistingFileInDb", null);
|
|
232
|
+
__decorate([
|
|
233
|
+
(0, ts_utils_1.log)(),
|
|
234
|
+
__metadata("design:type", Function),
|
|
235
|
+
__metadata("design:paramtypes", [Object, crypto_1.CryptoSecretKey]),
|
|
236
|
+
__metadata("design:returntype", Promise)
|
|
237
|
+
], FileController.prototype, "decryptFile", null);
|
|
238
|
+
__decorate([
|
|
239
|
+
(0, ts_utils_1.log)(),
|
|
240
|
+
__metadata("design:type", Function),
|
|
241
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
242
|
+
__metadata("design:returntype", Promise)
|
|
243
|
+
], FileController.prototype, "setFileMetadata", null);
|
|
244
|
+
__decorate([
|
|
245
|
+
(0, ts_utils_1.log)(),
|
|
246
|
+
__metadata("design:type", Function),
|
|
247
|
+
__metadata("design:paramtypes", [Object]),
|
|
248
|
+
__metadata("design:returntype", Promise)
|
|
249
|
+
], FileController.prototype, "downloadFileContent", null);
|
|
216
250
|
exports.FileController = FileController;
|
|
217
251
|
//# sourceMappingURL=FileController.js.map
|