@nmshd/crypto 1.0.7 → 2.0.0
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/CoreBuffer.d.ts +0 -1
- package/dist/CoreBuffer.js +1 -4
- package/dist/CoreBuffer.js.map +1 -1
- package/dist/CryptoDerivation.js +2 -2
- package/dist/CryptoDerivation.js.map +1 -1
- package/dist/CryptoPrivateKey.d.ts +14 -17
- package/dist/CryptoPrivateKey.js +24 -39
- package/dist/CryptoPrivateKey.js.map +1 -1
- package/dist/CryptoPublicKey.d.ts +13 -16
- package/dist/CryptoPublicKey.js +22 -37
- package/dist/CryptoPublicKey.js.map +1 -1
- package/dist/CryptoSerializable.d.ts +5 -0
- package/dist/CryptoSerializable.js +15 -0
- package/dist/CryptoSerializable.js.map +1 -0
- package/dist/CryptoValidation.d.ts +4 -6
- package/dist/CryptoValidation.js +16 -29
- package/dist/CryptoValidation.js.map +1 -1
- package/dist/SodiumWrapper.js +5 -1
- package/dist/SodiumWrapper.js.map +1 -1
- package/dist/buildInformation.js +5 -5
- package/dist/encryption/CryptoCipher.d.ts +10 -11
- package/dist/encryption/CryptoCipher.js +62 -59
- package/dist/encryption/CryptoCipher.js.map +1 -1
- package/dist/encryption/CryptoEncryption.js +10 -12
- package/dist/encryption/CryptoEncryption.js.map +1 -1
- package/dist/encryption/CryptoSecretKey.d.ts +8 -9
- package/dist/encryption/CryptoSecretKey.js +36 -32
- package/dist/encryption/CryptoSecretKey.js.map +1 -1
- package/dist/exchange/CryptoExchange.d.ts +0 -2
- package/dist/exchange/CryptoExchange.js +5 -22
- package/dist/exchange/CryptoExchange.js.map +1 -1
- package/dist/exchange/CryptoExchangeKeypair.d.ts +10 -11
- package/dist/exchange/CryptoExchangeKeypair.js +33 -30
- package/dist/exchange/CryptoExchangeKeypair.js.map +1 -1
- package/dist/exchange/CryptoExchangePrivateKey.d.ts +8 -10
- package/dist/exchange/CryptoExchangePrivateKey.js +50 -31
- package/dist/exchange/CryptoExchangePrivateKey.js.map +1 -1
- package/dist/exchange/CryptoExchangePublicKey.d.ts +6 -7
- package/dist/exchange/CryptoExchangePublicKey.js +31 -32
- package/dist/exchange/CryptoExchangePublicKey.js.map +1 -1
- package/dist/exchange/CryptoExchangeSecrets.d.ts +10 -11
- package/dist/exchange/CryptoExchangeSecrets.js +33 -35
- package/dist/exchange/CryptoExchangeSecrets.js.map +1 -1
- package/dist/exchange/CryptoExchangeValidation.d.ts +7 -10
- package/dist/exchange/CryptoExchangeValidation.js +9 -36
- package/dist/exchange/CryptoExchangeValidation.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/relationship/CryptoRelationshipPublicRequest.d.ts +8 -9
- package/dist/relationship/CryptoRelationshipPublicRequest.js +23 -42
- package/dist/relationship/CryptoRelationshipPublicRequest.js.map +1 -1
- package/dist/relationship/CryptoRelationshipPublicResponse.d.ts +8 -9
- package/dist/relationship/CryptoRelationshipPublicResponse.js +24 -38
- package/dist/relationship/CryptoRelationshipPublicResponse.js.map +1 -1
- package/dist/relationship/CryptoRelationshipRequestSecrets.d.ts +6 -7
- package/dist/relationship/CryptoRelationshipRequestSecrets.js +7 -10
- package/dist/relationship/CryptoRelationshipRequestSecrets.js.map +1 -1
- package/dist/relationship/CryptoRelationshipSecrets.d.ts +6 -7
- package/dist/relationship/CryptoRelationshipSecrets.js +8 -11
- package/dist/relationship/CryptoRelationshipSecrets.js.map +1 -1
- package/dist/signature/CryptoSignature.d.ts +12 -13
- package/dist/signature/CryptoSignature.js +39 -35
- package/dist/signature/CryptoSignature.js.map +1 -1
- package/dist/signature/CryptoSignatureAlgorithm.d.ts +5 -0
- package/dist/signature/CryptoSignatureAlgorithm.js +3 -0
- package/dist/signature/CryptoSignatureAlgorithm.js.map +1 -0
- package/dist/signature/CryptoSignatureKeypair.d.ts +10 -11
- package/dist/signature/CryptoSignatureKeypair.js +36 -38
- package/dist/signature/CryptoSignatureKeypair.js.map +1 -1
- package/dist/signature/CryptoSignaturePrivateKey.d.ts +10 -13
- package/dist/signature/CryptoSignaturePrivateKey.js +26 -37
- package/dist/signature/CryptoSignaturePrivateKey.js.map +1 -1
- package/dist/signature/CryptoSignaturePublicKey.d.ts +9 -12
- package/dist/signature/CryptoSignaturePublicKey.js +22 -44
- package/dist/signature/CryptoSignaturePublicKey.js.map +1 -1
- package/dist/signature/CryptoSignatureValidation.d.ts +10 -12
- package/dist/signature/CryptoSignatureValidation.js +13 -35
- package/dist/signature/CryptoSignatureValidation.js.map +1 -1
- package/dist/signature/CryptoSignatures.d.ts +1 -5
- package/dist/signature/CryptoSignatures.js +5 -5
- package/dist/signature/CryptoSignatures.js.map +1 -1
- package/dist/state/CryptoPrivateState.d.ts +12 -20
- package/dist/state/CryptoPrivateState.js +73 -77
- package/dist/state/CryptoPrivateState.js.map +1 -1
- package/dist/state/CryptoPrivateStateReceive.d.ts +4 -6
- package/dist/state/CryptoPrivateStateReceive.js +27 -39
- package/dist/state/CryptoPrivateStateReceive.js.map +1 -1
- package/dist/state/CryptoPrivateStateTransmit.d.ts +3 -4
- package/dist/state/CryptoPrivateStateTransmit.js +14 -40
- package/dist/state/CryptoPrivateStateTransmit.js.map +1 -1
- package/dist/state/CryptoPublicState.d.ts +11 -16
- package/dist/state/CryptoPublicState.js +44 -53
- package/dist/state/CryptoPublicState.js.map +1 -1
- package/dist/stream/CryptoStream.js +5 -2
- package/dist/stream/CryptoStream.js.map +1 -1
- package/dist/stream/CryptoStreamAddress.d.ts +7 -10
- package/dist/stream/CryptoStreamAddress.js +13 -29
- package/dist/stream/CryptoStreamAddress.js.map +1 -1
- package/dist/stream/CryptoStreamHeader.d.ts +9 -12
- package/dist/stream/CryptoStreamHeader.js +15 -18
- package/dist/stream/CryptoStreamHeader.js.map +1 -1
- package/dist/stream/CryptoStreamState.d.ts +6 -10
- package/dist/stream/CryptoStreamState.js +15 -33
- package/dist/stream/CryptoStreamState.js.map +1 -1
- package/lib-web/nmshd.crypto.js +793 -1023
- package/lib-web/nmshd.crypto.js.map +1 -1
- package/lib-web/nmshd.crypto.min.js +1 -1
- package/lib-web/nmshd.crypto.min.js.map +1 -1
- package/package.json +19 -19
- package/dist/CryptoSerializableAsync.d.ts +0 -5
- package/dist/CryptoSerializableAsync.js +0 -24
- package/dist/CryptoSerializableAsync.js.map +0 -1
package/dist/buildInformation.js
CHANGED
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildInformation = void 0;
|
|
4
4
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
5
5
|
exports.buildInformation = {
|
|
6
|
-
version: "
|
|
7
|
-
build: "
|
|
8
|
-
date: "2022-
|
|
9
|
-
commit: "
|
|
10
|
-
dependencies: {"libsodium-wrappers-sumo":"0.7.
|
|
6
|
+
version: "2.0.0",
|
|
7
|
+
build: "12",
|
|
8
|
+
date: "2022-04-12T11:17:12+00:00",
|
|
9
|
+
commit: "25fed42ba3e27d868f9584bf3c990f983b8ea70b",
|
|
10
|
+
dependencies: {"libsodium-wrappers-sumo":"0.7.10","uuid":"8.3.2"},
|
|
11
11
|
libraries: {
|
|
12
12
|
serval: ts_serval_1.buildInformation
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ISerializable, ISerialized } from "@js-soft/ts-serval";
|
|
2
2
|
import { CoreBuffer, IClearable, ICoreBuffer } from "../CoreBuffer";
|
|
3
|
-
import {
|
|
3
|
+
import { CryptoSerializable } from "../CryptoSerializable";
|
|
4
4
|
import { CryptoEncryptionAlgorithm } from "./CryptoEncryption";
|
|
5
5
|
export interface ICryptoCipherSerialized extends ISerialized {
|
|
6
6
|
alg: number;
|
|
@@ -14,18 +14,17 @@ export interface ICryptoCipher extends ISerializable {
|
|
|
14
14
|
counter?: number;
|
|
15
15
|
nonce?: ICoreBuffer;
|
|
16
16
|
}
|
|
17
|
-
export declare class CryptoCipher extends
|
|
17
|
+
export declare class CryptoCipher extends CryptoSerializable implements ICryptoCipher, IClearable {
|
|
18
18
|
static MIN_CIPHER_BYTES: number;
|
|
19
19
|
static MAX_CIPHER_BYTES: number;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
constructor(cipher: CoreBuffer, algorithm: CryptoEncryptionAlgorithm, nonce?: CoreBuffer, counter?: number);
|
|
20
|
+
algorithm: CryptoEncryptionAlgorithm;
|
|
21
|
+
cipher: CoreBuffer;
|
|
22
|
+
counter?: number;
|
|
23
|
+
nonce?: CoreBuffer;
|
|
25
24
|
toJSON(verbose?: boolean): ICryptoCipherSerialized;
|
|
26
25
|
clear(): void;
|
|
27
|
-
static from(value: CryptoCipher | ICryptoCipher):
|
|
28
|
-
static
|
|
29
|
-
static
|
|
30
|
-
static
|
|
26
|
+
static from(value: CryptoCipher | ICryptoCipher): CryptoCipher;
|
|
27
|
+
protected static preFrom(value: any): any;
|
|
28
|
+
static fromJSON(value: ICryptoCipherSerialized): CryptoCipher;
|
|
29
|
+
static fromBase64(value: string): CryptoCipher;
|
|
31
30
|
}
|
|
@@ -15,84 +15,87 @@ const ts_serval_1 = require("@js-soft/ts-serval");
|
|
|
15
15
|
const CoreBuffer_1 = require("../CoreBuffer");
|
|
16
16
|
const CryptoError_1 = require("../CryptoError");
|
|
17
17
|
const CryptoErrorCode_1 = require("../CryptoErrorCode");
|
|
18
|
-
const
|
|
18
|
+
const CryptoSerializable_1 = require("../CryptoSerializable");
|
|
19
19
|
const CryptoValidation_1 = require("../CryptoValidation");
|
|
20
|
-
let CryptoCipher = CryptoCipher_1 = class CryptoCipher extends
|
|
21
|
-
constructor(cipher, algorithm, nonce, counter) {
|
|
22
|
-
if (!nonce && typeof counter === "undefined") {
|
|
23
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.EncryptionNoNonceNorCounter, "No nonce nor counter property set.");
|
|
24
|
-
}
|
|
25
|
-
if (nonce && typeof counter !== "undefined") {
|
|
26
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.EncryptionNonceAndCounter, "Nonce and counter properties are set.");
|
|
27
|
-
}
|
|
28
|
-
CryptoValidation_1.CryptoValidation.checkBuffer(cipher, CryptoCipher_1.MIN_CIPHER_BYTES, CryptoCipher_1.MAX_CIPHER_BYTES, "cipher");
|
|
29
|
-
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(algorithm);
|
|
30
|
-
if (typeof counter !== "undefined") {
|
|
31
|
-
CryptoValidation_1.CryptoValidation.checkCounter(counter);
|
|
32
|
-
}
|
|
33
|
-
if (typeof nonce !== "undefined") {
|
|
34
|
-
CryptoValidation_1.CryptoValidation.checkNonceForAlgorithm(nonce, algorithm);
|
|
35
|
-
}
|
|
36
|
-
super();
|
|
37
|
-
this.cipher = cipher;
|
|
38
|
-
this.nonce = nonce;
|
|
39
|
-
this.counter = counter;
|
|
40
|
-
this.algorithm = algorithm;
|
|
41
|
-
}
|
|
20
|
+
let CryptoCipher = CryptoCipher_1 = class CryptoCipher extends CryptoSerializable_1.CryptoSerializable {
|
|
42
21
|
toJSON(verbose = true) {
|
|
43
|
-
|
|
22
|
+
return {
|
|
44
23
|
cph: this.cipher.toBase64URL(),
|
|
45
|
-
alg: this.algorithm
|
|
24
|
+
alg: this.algorithm,
|
|
25
|
+
nnc: this.nonce ? this.nonce.toBase64URL() : undefined,
|
|
26
|
+
cnt: this.counter,
|
|
27
|
+
"@type": verbose ? "CryptoCipher" : undefined
|
|
46
28
|
};
|
|
47
|
-
if (this.nonce) {
|
|
48
|
-
obj.nnc = this.nonce.toBase64URL();
|
|
49
|
-
}
|
|
50
|
-
if (typeof this.counter !== "undefined") {
|
|
51
|
-
obj.cnt = this.counter;
|
|
52
|
-
}
|
|
53
|
-
if (verbose) {
|
|
54
|
-
obj["@type"] = "CryptoCipher";
|
|
55
|
-
}
|
|
56
|
-
return obj;
|
|
57
29
|
}
|
|
58
30
|
clear() {
|
|
31
|
+
var _a;
|
|
59
32
|
this.cipher.clear();
|
|
60
|
-
|
|
61
|
-
this.nonce.clear();
|
|
33
|
+
(_a = this.nonce) === null || _a === void 0 ? void 0 : _a.clear();
|
|
62
34
|
}
|
|
63
35
|
static from(value) {
|
|
64
|
-
return
|
|
36
|
+
return this.fromAny(value);
|
|
65
37
|
}
|
|
66
|
-
static
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
38
|
+
static preFrom(value) {
|
|
39
|
+
if (value.cph) {
|
|
40
|
+
value = {
|
|
41
|
+
cipher: value.cph,
|
|
42
|
+
algorithm: value.alg,
|
|
43
|
+
nonce: value.nnc,
|
|
44
|
+
counter: value.cnt
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (!value.nonce && typeof value.counter === "undefined") {
|
|
48
|
+
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.EncryptionNoNonceNorCounter, "No nonce nor counter property set.");
|
|
49
|
+
}
|
|
50
|
+
if (value.nonce && typeof value.counter !== "undefined") {
|
|
51
|
+
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.EncryptionNonceAndCounter, "Nonce and counter properties are set.");
|
|
74
52
|
}
|
|
75
|
-
if (typeof value.
|
|
76
|
-
CryptoValidation_1.CryptoValidation.
|
|
77
|
-
counter = value.cnt;
|
|
53
|
+
if (typeof value.cipher === "string") {
|
|
54
|
+
CryptoValidation_1.CryptoValidation.checkSerializedBuffer(value.cipher, this.MIN_CIPHER_BYTES, this.MAX_CIPHER_BYTES, "cipher");
|
|
78
55
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
56
|
+
else {
|
|
57
|
+
CryptoValidation_1.CryptoValidation.checkBuffer(value.cipher, CryptoCipher_1.MIN_CIPHER_BYTES, CryptoCipher_1.MAX_CIPHER_BYTES, "cipher");
|
|
58
|
+
}
|
|
59
|
+
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(value.algorithm);
|
|
60
|
+
if (value.counter) {
|
|
61
|
+
CryptoValidation_1.CryptoValidation.checkCounter(value.counter);
|
|
62
|
+
}
|
|
63
|
+
if (value.nonce) {
|
|
64
|
+
CryptoValidation_1.CryptoValidation.checkNonce(value.nonce, value.algorithm);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
82
67
|
}
|
|
83
|
-
static
|
|
84
|
-
return
|
|
68
|
+
static fromJSON(value) {
|
|
69
|
+
return this.fromAny(value);
|
|
85
70
|
}
|
|
86
|
-
static
|
|
87
|
-
|
|
88
|
-
return await this.fromJSON(obj);
|
|
71
|
+
static fromBase64(value) {
|
|
72
|
+
return this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
|
|
89
73
|
}
|
|
90
74
|
};
|
|
91
75
|
CryptoCipher.MIN_CIPHER_BYTES = 2;
|
|
92
76
|
CryptoCipher.MAX_CIPHER_BYTES = 100 * 1024 * 1024;
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, ts_serval_1.validate)(),
|
|
79
|
+
(0, ts_serval_1.serialize)(),
|
|
80
|
+
__metadata("design:type", Number)
|
|
81
|
+
], CryptoCipher.prototype, "algorithm", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, ts_serval_1.validate)(),
|
|
84
|
+
(0, ts_serval_1.serialize)(),
|
|
85
|
+
__metadata("design:type", CoreBuffer_1.CoreBuffer)
|
|
86
|
+
], CryptoCipher.prototype, "cipher", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, ts_serval_1.validate)({ nullable: true }),
|
|
89
|
+
(0, ts_serval_1.serialize)(),
|
|
90
|
+
__metadata("design:type", Number)
|
|
91
|
+
], CryptoCipher.prototype, "counter", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
(0, ts_serval_1.validate)({ nullable: true }),
|
|
94
|
+
(0, ts_serval_1.serialize)(),
|
|
95
|
+
__metadata("design:type", CoreBuffer_1.CoreBuffer)
|
|
96
|
+
], CryptoCipher.prototype, "nonce", void 0);
|
|
93
97
|
CryptoCipher = CryptoCipher_1 = __decorate([
|
|
94
|
-
(0, ts_serval_1.type)("CryptoCipher")
|
|
95
|
-
__metadata("design:paramtypes", [CoreBuffer_1.CoreBuffer, Number, CoreBuffer_1.CoreBuffer, Number])
|
|
98
|
+
(0, ts_serval_1.type)("CryptoCipher")
|
|
96
99
|
], CryptoCipher);
|
|
97
100
|
exports.CryptoCipher = CryptoCipher;
|
|
98
101
|
//# sourceMappingURL=CryptoCipher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoCipher.js","sourceRoot":"","sources":["../../src/encryption/CryptoCipher.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"CryptoCipher.js","sourceRoot":"","sources":["../../src/encryption/CryptoCipher.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kDAA2F;AAC3F,8CAAoE;AACpE,gDAA6C;AAC7C,wDAAqD;AACrD,8DAA2D;AAC3D,0DAAuD;AAkBvD,IAAa,YAAY,oBAAzB,MAAa,YAAa,SAAQ,uCAAkB;IAoBhC,MAAM,CAAC,OAAO,GAAG,IAAI;QACjC,OAAO;YACH,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;YAC9B,GAAG,EAAE,IAAI,CAAC,SAAS;YACnB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;YACtD,GAAG,EAAE,IAAI,CAAC,OAAO;YACjB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;SAChD,CAAC;IACN,CAAC;IAEM,KAAK;;QACR,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,MAAA,IAAI,CAAC,KAAK,0CAAE,KAAK,EAAE,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AK,EAAE;YACb,mCAAgB,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;SAC7D;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAA8B;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,KAAa;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AA1FiB,6BAAgB,GAAG,CAAE,CAAA;AACrB,6BAAgB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAK,CAAA;AAInD;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;;+CACgC;AAI5C;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACG,uBAAU;4CAAC;AAI1B;IAFC,IAAA,oBAAQ,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,IAAA,qBAAS,GAAE;;6CACY;AAIxB;IAFC,IAAA,oBAAQ,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,IAAA,qBAAS,GAAE;8BACG,uBAAU;2CAAC;AAlBjB,YAAY;IADxB,IAAA,gBAAI,EAAC,cAAc,CAAC;GACR,YAAY,CA2FxB;AA3FY,oCAAY"}
|
|
@@ -24,8 +24,7 @@ class CryptoEncryption {
|
|
|
24
24
|
default:
|
|
25
25
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.NotYetImplemented);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
return secretKey;
|
|
27
|
+
return CryptoSecretKey_1.CryptoSecretKey.from({ secretKey: buffer, algorithm });
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Encrypts a given plaintext [[CoreBuffer]] object with the given secretKey. If a nonce is set,
|
|
@@ -38,11 +37,9 @@ class CryptoEncryption {
|
|
|
38
37
|
* @param algorithm
|
|
39
38
|
*/
|
|
40
39
|
static async encrypt(plaintext, secretKey, nonce, algorithm = 3 /* XCHACHA20_POLY1305 */) {
|
|
41
|
-
CryptoValidation_1.CryptoValidation.checkPlaintext(plaintext);
|
|
42
40
|
let correctAlgorithm;
|
|
43
41
|
let secretKeyBuffer;
|
|
44
42
|
if (secretKey instanceof CryptoSecretKey_1.CryptoSecretKey) {
|
|
45
|
-
CryptoValidation_1.CryptoValidation.checkSecretKey(secretKey);
|
|
46
43
|
correctAlgorithm = secretKey.algorithm;
|
|
47
44
|
secretKeyBuffer = secretKey.secretKey.buffer;
|
|
48
45
|
}
|
|
@@ -64,26 +61,29 @@ class CryptoEncryption {
|
|
|
64
61
|
else {
|
|
65
62
|
publicnonce = sodium.randombytes_buf(24);
|
|
66
63
|
}
|
|
67
|
-
let
|
|
64
|
+
let cipher;
|
|
68
65
|
switch (correctAlgorithm) {
|
|
69
66
|
case 3 /* XCHACHA20_POLY1305 */:
|
|
70
67
|
try {
|
|
71
|
-
|
|
72
|
-
cipherbuffer = new CoreBuffer_1.CoreBuffer(cipher);
|
|
73
|
-
return new CryptoCipher_1.CryptoCipher(cipherbuffer, correctAlgorithm, new CoreBuffer_1.CoreBuffer(publicnonce));
|
|
68
|
+
cipher = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(plaintext.buffer, "", new Uint8Array(), publicnonce, secretKeyBuffer);
|
|
74
69
|
}
|
|
75
70
|
catch (e) {
|
|
76
71
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.EncryptionEncrypt, `${e}`);
|
|
77
72
|
}
|
|
73
|
+
break;
|
|
78
74
|
default:
|
|
79
75
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.NotYetImplemented);
|
|
80
76
|
}
|
|
77
|
+
return CryptoCipher_1.CryptoCipher.from({
|
|
78
|
+
cipher: CoreBuffer_1.CoreBuffer.from(cipher),
|
|
79
|
+
algorithm: correctAlgorithm,
|
|
80
|
+
nonce: CoreBuffer_1.CoreBuffer.from(publicnonce)
|
|
81
|
+
});
|
|
81
82
|
}
|
|
82
83
|
static async encryptWithCounter(plaintext, secretKey, nonce, counter, algorithm = 3 /* XCHACHA20_POLY1305 */) {
|
|
83
84
|
let correctAlgorithm;
|
|
84
85
|
let secretKeyBuffer;
|
|
85
86
|
if (secretKey instanceof CryptoSecretKey_1.CryptoSecretKey) {
|
|
86
|
-
CryptoValidation_1.CryptoValidation.checkSecretKey(secretKey);
|
|
87
87
|
correctAlgorithm = secretKey.algorithm;
|
|
88
88
|
secretKeyBuffer = secretKey.secretKey.buffer;
|
|
89
89
|
}
|
|
@@ -104,7 +104,7 @@ class CryptoEncryption {
|
|
|
104
104
|
try {
|
|
105
105
|
const cipher = (await SodiumWrapper_1.SodiumWrapper.ready()).crypto_aead_xchacha20poly1305_ietf_encrypt(plaintext.buffer, "", new Uint8Array(), publicnonce.buffer, secretKeyBuffer);
|
|
106
106
|
cipherbuffer = new CoreBuffer_1.CoreBuffer(cipher);
|
|
107
|
-
return
|
|
107
|
+
return CryptoCipher_1.CryptoCipher.from({ cipher: cipherbuffer, algorithm, counter });
|
|
108
108
|
}
|
|
109
109
|
catch (e) {
|
|
110
110
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.EncryptionEncrypt, `${e}`);
|
|
@@ -114,11 +114,9 @@ class CryptoEncryption {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
static async decrypt(cipher, secretKey, nonce, algorithm = 3 /* XCHACHA20_POLY1305 */) {
|
|
117
|
-
CryptoValidation_1.CryptoValidation.checkCipher(cipher);
|
|
118
117
|
let correctAlgorithm;
|
|
119
118
|
let secretKeyBuffer;
|
|
120
119
|
if (secretKey instanceof CryptoSecretKey_1.CryptoSecretKey) {
|
|
121
|
-
CryptoValidation_1.CryptoValidation.checkSecretKey(secretKey);
|
|
122
120
|
correctAlgorithm = secretKey.algorithm;
|
|
123
121
|
secretKeyBuffer = secretKey.secretKey.buffer;
|
|
124
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoEncryption.js","sourceRoot":"","sources":["../../src/encryption/CryptoEncryption.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAC3C,gDAA6C;AAC7C,wDAAqD;AACrD,0DAAuD;AACvD,oDAAiD;AACjD,iDAA8C;AAC9C,uDAAoD;AAwBpD,MAAsB,gBAAgB;IAC3B,MAAM,CAAC,KAAK,CAAC,WAAW,CAC3B,sCAAmF;QAEnF,mCAAgB,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAErD,IAAI,MAAkB,CAAC;QACvB,QAAQ,SAAS,EAAE;YACf;gBACI,IAAI;oBACA,MAAM,GAAG,IAAI,uBAAU,CAAC,CAAC,MAAM,6BAAa,CAAC,KAAK,EAAE,CAAC,CAAC,yCAAyC,EAAE,CAAC,CAAC;iBACtG;gBAAC,OAAO,CAAC,EAAE;oBACR,MAAM,IAAI,yBAAW,CAAC,iCAAe,CAAC,uBAAuB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;iBAC1E;gBAED,MAAM;YACV;gBACI,MAAM,IAAI,yBAAW,CAAC,iCAAe,CAAC,iBAAiB,CAAC,CAAC;SAChE;QAED,
|
|
1
|
+
{"version":3,"file":"CryptoEncryption.js","sourceRoot":"","sources":["../../src/encryption/CryptoEncryption.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAC3C,gDAA6C;AAC7C,wDAAqD;AACrD,0DAAuD;AACvD,oDAAiD;AACjD,iDAA8C;AAC9C,uDAAoD;AAwBpD,MAAsB,gBAAgB;IAC3B,MAAM,CAAC,KAAK,CAAC,WAAW,CAC3B,sCAAmF;QAEnF,mCAAgB,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAErD,IAAI,MAAkB,CAAC;QACvB,Q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K,MAAM,CAAC,WAAW,CAAC,KAA8B,EAAE,OAAe;QACtE,IAAI,MAAM,CAAC;QACX,IAAI,KAAK,YAAY,UAAU,EAAE;YAC7B,MAAM,GAAG,IAAI,uBAAU,CAAC,KAAK,CAAC,CAAC;SAClC;aAAM,IAAI,KAAK,YAAY,uBAAU,EAAE;YACpC,MAAM,GAAG,KAAK,CAAC;SAClB;aAAM;YACH,MAAM,IAAI,yBAAW,CAAC,iCAAe,CAAC,oBAAoB,CAAC,CAAC;SAC/D;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE1C,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAhRD,4CAgRC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ISerializable, ISerialized } from "@js-soft/ts-serval";
|
|
2
2
|
import { CoreBuffer, IClearable, ICoreBuffer } from "../CoreBuffer";
|
|
3
|
-
import {
|
|
3
|
+
import { CryptoSerializable } from "../CryptoSerializable";
|
|
4
4
|
import { CryptoEncryptionAlgorithm } from "./CryptoEncryption";
|
|
5
5
|
export interface ICryptoSecretKeySerialized extends ISerialized {
|
|
6
6
|
alg: number;
|
|
@@ -10,14 +10,13 @@ export interface ICryptoSecretKey extends ISerializable {
|
|
|
10
10
|
algorithm: CryptoEncryptionAlgorithm;
|
|
11
11
|
secretKey: ICoreBuffer;
|
|
12
12
|
}
|
|
13
|
-
export declare class CryptoSecretKey extends
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor(secretKey: CoreBuffer, algorithm?: CryptoEncryptionAlgorithm);
|
|
13
|
+
export declare class CryptoSecretKey extends CryptoSerializable implements ICryptoSecretKey, IClearable {
|
|
14
|
+
algorithm: CryptoEncryptionAlgorithm;
|
|
15
|
+
secretKey: CoreBuffer;
|
|
17
16
|
toJSON(verbose?: boolean): ICryptoSecretKeySerialized;
|
|
18
17
|
clear(): void;
|
|
19
|
-
static from(value: CryptoSecretKey | ICryptoSecretKey):
|
|
20
|
-
static
|
|
21
|
-
static
|
|
22
|
-
static
|
|
18
|
+
static from(value: CryptoSecretKey | ICryptoSecretKey): CryptoSecretKey;
|
|
19
|
+
protected static preFrom(value: any): any;
|
|
20
|
+
static fromJSON(value: ICryptoSecretKeySerialized): CryptoSecretKey;
|
|
21
|
+
static fromBase64(value: string): CryptoSecretKey;
|
|
23
22
|
}
|
|
@@ -8,57 +8,61 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var CryptoSecretKey_1;
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
exports.CryptoSecretKey = void 0;
|
|
14
13
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
15
14
|
const CoreBuffer_1 = require("../CoreBuffer");
|
|
16
|
-
const
|
|
15
|
+
const CryptoSerializable_1 = require("../CryptoSerializable");
|
|
17
16
|
const CryptoValidation_1 = require("../CryptoValidation");
|
|
18
|
-
let CryptoSecretKey =
|
|
19
|
-
constructor(secretKey, algorithm = 3 /* XCHACHA20_POLY1305 */) {
|
|
20
|
-
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(algorithm);
|
|
21
|
-
CryptoValidation_1.CryptoValidation.checkSecretKeyForAlgorithm(secretKey, algorithm);
|
|
22
|
-
super();
|
|
23
|
-
this.algorithm = algorithm;
|
|
24
|
-
this.secretKey = secretKey;
|
|
25
|
-
}
|
|
17
|
+
let CryptoSecretKey = class CryptoSecretKey extends CryptoSerializable_1.CryptoSerializable {
|
|
26
18
|
toJSON(verbose = true) {
|
|
27
|
-
|
|
19
|
+
return {
|
|
28
20
|
key: this.secretKey.toBase64URL(),
|
|
29
|
-
alg: this.algorithm
|
|
21
|
+
alg: this.algorithm,
|
|
22
|
+
"@type": verbose ? "CryptoSecretKey" : undefined
|
|
30
23
|
};
|
|
31
|
-
if (verbose) {
|
|
32
|
-
obj["@type"] = "CryptoSecretKey";
|
|
33
|
-
}
|
|
34
|
-
return obj;
|
|
35
24
|
}
|
|
36
25
|
clear() {
|
|
37
26
|
this.secretKey.clear();
|
|
38
27
|
}
|
|
39
28
|
static from(value) {
|
|
40
|
-
return
|
|
29
|
+
return this.fromAny(value);
|
|
41
30
|
}
|
|
42
|
-
static
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
static preFrom(value) {
|
|
32
|
+
if (value.alg) {
|
|
33
|
+
value = {
|
|
34
|
+
algorithm: value.alg,
|
|
35
|
+
secretKey: value.key
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(value.algorithm);
|
|
39
|
+
if (typeof value.secretKey === "string") {
|
|
40
|
+
CryptoValidation_1.CryptoValidation.checkSerializedSecretKeyForAlgorithm(value.secretKey, value.algorithm);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
CryptoValidation_1.CryptoValidation.checkSecretKeyForAlgorithm(value.secretKey, value.algorithm);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
static fromJSON(value) {
|
|
48
|
+
return this.fromAny(value);
|
|
50
49
|
}
|
|
51
50
|
static fromBase64(value) {
|
|
52
51
|
return this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
|
|
53
52
|
}
|
|
54
|
-
static async deserialize(value) {
|
|
55
|
-
const obj = JSON.parse(value);
|
|
56
|
-
return await this.fromJSON(obj);
|
|
57
|
-
}
|
|
58
53
|
};
|
|
59
|
-
|
|
60
|
-
(0, ts_serval_1.
|
|
61
|
-
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, ts_serval_1.validate)(),
|
|
56
|
+
(0, ts_serval_1.serialize)(),
|
|
57
|
+
__metadata("design:type", Number)
|
|
58
|
+
], CryptoSecretKey.prototype, "algorithm", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, ts_serval_1.validate)(),
|
|
61
|
+
(0, ts_serval_1.serialize)(),
|
|
62
|
+
__metadata("design:type", CoreBuffer_1.CoreBuffer)
|
|
63
|
+
], CryptoSecretKey.prototype, "secretKey", void 0);
|
|
64
|
+
CryptoSecretKey = __decorate([
|
|
65
|
+
(0, ts_serval_1.type)("CryptoSecretKey")
|
|
62
66
|
], CryptoSecretKey);
|
|
63
67
|
exports.CryptoSecretKey = CryptoSecretKey;
|
|
64
68
|
//# sourceMappingURL=CryptoSecretKey.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoSecretKey.js","sourceRoot":"","sources":["../../src/encryption/CryptoSecretKey.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CryptoSecretKey.js","sourceRoot":"","sources":["../../src/encryption/CryptoSecretKey.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA2F;AAC3F,8CAAoE;AACpE,8DAA2D;AAC3D,0DAAuD;AAcvD,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,uCAAkB;IAQnC,MAAM,CAAC,OAAO,GAAG,IAAI;QACjC,OAAO;YACH,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACjC,GAAG,EAAE,IAAI,CAAC,SAAS;YACnB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS;SACnD,CAAC;IACN,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,IAAI,CAAC,KAAyC;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAES,MAAM,CAAU,OAAO,CAAC,KAAU;QACxC,IAAI,KAAK,CAAC,GAAG,EAAE;YACX,KAAK,GAAG;gBACJ,SAAS,EAAE,KAAK,CAAC,GAAG;gBACpB,SAAS,EAAE,KAAK,CAAC,GAAG;aACvB,CAAC;SACL;QAED,mCAAgB,CAAC,wBAAwB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAE3D,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,EAAE;YACrC,mCAAgB,CAAC,oCAAoC,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;SAC3F;aAAM;YACH,mCAAgB,CAAC,0BAA0B,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;SACjF;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAAiC;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,KAAa;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AA/CG;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;;kDACgC;AAG5C;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACM,uBAAU;kDAAC;AANpB,eAAe;IAD3B,IAAA,gBAAI,EAAC,iBAAiB,CAAC;GACX,eAAe,CAkD3B;AAlDY,0CAAe"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CryptoEncryptionAlgorithm } from "../encryption/CryptoEncryption";
|
|
2
2
|
import { CryptoExchangeKeypair } from "./CryptoExchangeKeypair";
|
|
3
|
-
import { CryptoExchangePrivateKey } from "./CryptoExchangePrivateKey";
|
|
4
3
|
import { CryptoExchangePublicKey } from "./CryptoExchangePublicKey";
|
|
5
4
|
import { CryptoExchangeSecrets } from "./CryptoExchangeSecrets";
|
|
6
5
|
export declare const enum CryptoExchangeAlgorithm {
|
|
@@ -9,7 +8,6 @@ export declare const enum CryptoExchangeAlgorithm {
|
|
|
9
8
|
ECDH_X25519 = 3
|
|
10
9
|
}
|
|
11
10
|
export declare class CryptoExchange {
|
|
12
|
-
static privateKeyToPublicKey(privateKey: CryptoExchangePrivateKey): Promise<CryptoExchangePublicKey>;
|
|
13
11
|
/**
|
|
14
12
|
* Generates a keypair for the specified key exchange algorithm
|
|
15
13
|
*
|
|
@@ -10,23 +10,6 @@ const CryptoExchangePrivateKey_1 = require("./CryptoExchangePrivateKey");
|
|
|
10
10
|
const CryptoExchangePublicKey_1 = require("./CryptoExchangePublicKey");
|
|
11
11
|
const CryptoExchangeSecrets_1 = require("./CryptoExchangeSecrets");
|
|
12
12
|
class CryptoExchange {
|
|
13
|
-
static async privateKeyToPublicKey(privateKey) {
|
|
14
|
-
switch (privateKey.algorithm) {
|
|
15
|
-
case 3 /* ECDH_X25519 */:
|
|
16
|
-
try {
|
|
17
|
-
const publicKey = (await SodiumWrapper_1.SodiumWrapper.ready()).crypto_scalarmult_base(privateKey.privateKey.buffer);
|
|
18
|
-
return await CryptoExchangePublicKey_1.CryptoExchangePublicKey.from({
|
|
19
|
-
algorithm: privateKey.algorithm,
|
|
20
|
-
publicKey: CoreBuffer_1.CoreBuffer.from(publicKey)
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.ExchangeKeyGeneration, `${e}`);
|
|
25
|
-
}
|
|
26
|
-
default:
|
|
27
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.NotYetImplemented);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
13
|
/**
|
|
31
14
|
* Generates a keypair for the specified key exchange algorithm
|
|
32
15
|
*
|
|
@@ -51,9 +34,9 @@ class CryptoExchange {
|
|
|
51
34
|
default:
|
|
52
35
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.NotYetImplemented);
|
|
53
36
|
}
|
|
54
|
-
const privateKey =
|
|
55
|
-
const publicKey =
|
|
56
|
-
const keypair =
|
|
37
|
+
const privateKey = CryptoExchangePrivateKey_1.CryptoExchangePrivateKey.from({ algorithm, privateKey: CoreBuffer_1.CoreBuffer.from(privateKeyBuffer) });
|
|
38
|
+
const publicKey = CryptoExchangePublicKey_1.CryptoExchangePublicKey.from({ algorithm, publicKey: CoreBuffer_1.CoreBuffer.from(publicKeyBuffer) });
|
|
39
|
+
const keypair = CryptoExchangeKeypair_1.CryptoExchangeKeypair.from({ publicKey, privateKey });
|
|
57
40
|
return keypair;
|
|
58
41
|
}
|
|
59
42
|
/**
|
|
@@ -80,7 +63,7 @@ class CryptoExchange {
|
|
|
80
63
|
catch (e) {
|
|
81
64
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.ExchangeKeyDerivation, `${e}`);
|
|
82
65
|
}
|
|
83
|
-
const secrets =
|
|
66
|
+
const secrets = CryptoExchangeSecrets_1.CryptoExchangeSecrets.from({
|
|
84
67
|
receivingKey: CoreBuffer_1.CoreBuffer.from(sharedKey.sharedRx),
|
|
85
68
|
transmissionKey: CoreBuffer_1.CoreBuffer.from(sharedKey.sharedTx),
|
|
86
69
|
algorithm: algorithm
|
|
@@ -111,7 +94,7 @@ class CryptoExchange {
|
|
|
111
94
|
catch (e) {
|
|
112
95
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.ExchangeKeyDerivation, `${e}`);
|
|
113
96
|
}
|
|
114
|
-
const secrets =
|
|
97
|
+
const secrets = CryptoExchangeSecrets_1.CryptoExchangeSecrets.from({
|
|
115
98
|
receivingKey: CoreBuffer_1.CoreBuffer.from(sharedKey.sharedRx),
|
|
116
99
|
transmissionKey: CoreBuffer_1.CoreBuffer.from(sharedKey.sharedTx),
|
|
117
100
|
algorithm: algorithm
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoExchange.js","sourceRoot":"","sources":["../../src/exchange/CryptoExchange.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAC3C,gDAA6C;AAC7C,wDAAqD;AAErD,oDAAiD;AACjD,mEAAgE;AAChE,yEAAsE;AACtE,uEAAoE;AACpE,mEAAgE;AAWhE,MAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"CryptoExchange.js","sourceRoot":"","sources":["../../src/exchange/CryptoExchange.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAC3C,gDAA6C;AAC7C,wDAAqD;AAErD,oDAAiD;AACjD,mEAAgE;AAChE,yEAAsE;AACtE,uEAAoE;AACpE,mEAAgE;AAWhE,MAAa,cAAc;IACvB;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,eAAe,CAC/B,+BAAwE;QAExE,IAAI,gBAAgB,CAAC;QACrB,IAAI,eAAe,CAAC;QAEpB,QAAQ,SAAmB,EAAE;YACzB;gBACI,IAAI,IAAI,CAAC;gBACT,IAAI;oBACA,IAAI,GAAG,CAAC,MAAM,6BAAa,CAAC,KAAK,EAAE,CAAC,CAAC,iBAAiB,EAAE,CAAC;iBAC5D;gBAAC,OAAO,CAAM,EAAE;oBACb,MAAM,IAAI,yBAAW,CAAC,iCAAe,CAAC,qBAAqB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;iBACxE;gBACD,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC;gBACnC,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC;gBACjC,MAAM;YACV;gBACI,MAAM,IAAI,yBAAW,CAAC,iCAAe,CAAC,iBAAiB,CAAC,CAAC;SAChE;QAED,MAAM,UAAU,GAAG,mDAAwB,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,uBAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;QAC/G,MAAM,SAAS,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,gBAAgB,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAC3C,gBAAgB,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,EAC7C,kBAAkB,CAAC,SAAS,CAAC,MAAM,CACtC,CAAC;SACL;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,yBAAW,CAAC,iCAAe,CAAC,qBAAqB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;SACxE;QAED,MAAM,OAAO,GAAG,6CAAqB,CAAC,IAAI,CAAC;YACvC,YAAY,EAAE,uBAAU,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACjD,eAAe,EAAE,uBAAU,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YACpD,SAAS,EAAE,SAAS;SACvB,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAlHD,wCAkHC"}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ISerializable, ISerialized } from "@js-soft/ts-serval";
|
|
2
2
|
import { IClearable } from "../CoreBuffer";
|
|
3
|
-
import {
|
|
3
|
+
import { CryptoSerializable } from "../CryptoSerializable";
|
|
4
4
|
import { CryptoExchangePrivateKey, ICryptoExchangePrivateKey, ICryptoExchangePrivateKeySerialized } from "./CryptoExchangePrivateKey";
|
|
5
5
|
import { CryptoExchangePublicKey, ICryptoExchangePublicKey, ICryptoExchangePublicKeySerialized } from "./CryptoExchangePublicKey";
|
|
6
6
|
export interface ICryptoExchangeKeypairSerialized extends ISerialized {
|
|
7
7
|
pub: ICryptoExchangePublicKeySerialized;
|
|
8
8
|
prv: ICryptoExchangePrivateKeySerialized;
|
|
9
9
|
}
|
|
10
|
-
export interface ICryptoExchangeKeypair extends
|
|
10
|
+
export interface ICryptoExchangeKeypair extends ISerializable {
|
|
11
11
|
publicKey: ICryptoExchangePublicKey;
|
|
12
12
|
privateKey: ICryptoExchangePrivateKey;
|
|
13
13
|
}
|
|
14
|
-
export declare class CryptoExchangeKeypair extends
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
constructor(publicKey: CryptoExchangePublicKey, privateKey: CryptoExchangePrivateKey);
|
|
14
|
+
export declare class CryptoExchangeKeypair extends CryptoSerializable implements ICryptoExchangeKeypair, IClearable {
|
|
15
|
+
publicKey: CryptoExchangePublicKey;
|
|
16
|
+
privateKey: CryptoExchangePrivateKey;
|
|
18
17
|
toJSON(verbose?: boolean): ICryptoExchangeKeypairSerialized;
|
|
19
18
|
clear(): void;
|
|
20
|
-
static
|
|
21
|
-
static
|
|
22
|
-
static
|
|
23
|
-
static
|
|
19
|
+
protected static preFrom(value: any): any;
|
|
20
|
+
static from(value: CryptoExchangeKeypair | ICryptoExchangeKeypair): CryptoExchangeKeypair;
|
|
21
|
+
static fromJSON(value: ICryptoExchangeKeypairSerialized): CryptoExchangeKeypair;
|
|
22
|
+
static fromBase64(value: string): CryptoExchangeKeypair;
|
|
24
23
|
}
|