@nmshd/crypto 1.0.8 → 2.0.1
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 +28 -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 +795 -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 +18 -18
- package/dist/CryptoSerializableAsync.d.ts +0 -5
- package/dist/CryptoSerializableAsync.js +0 -24
- package/dist/CryptoSerializableAsync.js.map +0 -1
|
@@ -5,71 +5,49 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
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
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
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
|
-
};
|
|
11
|
-
var CryptoSignaturePublicKey_1;
|
|
12
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
9
|
exports.CryptoSignaturePublicKey = void 0;
|
|
14
10
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
15
11
|
const CoreBuffer_1 = require("../CoreBuffer");
|
|
16
12
|
const CryptoPublicKey_1 = require("../CryptoPublicKey");
|
|
17
13
|
const CryptoSignatureValidation_1 = require("./CryptoSignatureValidation");
|
|
18
|
-
let CryptoSignaturePublicKey =
|
|
19
|
-
constructor(algorithm, publicKey) {
|
|
20
|
-
CryptoSignatureValidation_1.CryptoSignatureValidation.checkSignatureAlgorithm(algorithm);
|
|
21
|
-
CryptoSignatureValidation_1.CryptoSignatureValidation.checkSignaturePublicKeyAsBuffer(publicKey, algorithm);
|
|
22
|
-
super(algorithm, publicKey);
|
|
23
|
-
this.algorithm = algorithm;
|
|
24
|
-
this.publicKey = publicKey;
|
|
25
|
-
}
|
|
14
|
+
let CryptoSignaturePublicKey = class CryptoSignaturePublicKey extends CryptoPublicKey_1.CryptoPublicKey {
|
|
26
15
|
toJSON(verbose = true) {
|
|
27
|
-
|
|
16
|
+
return {
|
|
28
17
|
pub: this.publicKey.toBase64URL(),
|
|
29
|
-
alg: this.algorithm
|
|
18
|
+
alg: this.algorithm,
|
|
19
|
+
"@type": verbose ? "CryptoSignaturePublicKey" : undefined
|
|
30
20
|
};
|
|
31
|
-
if (verbose) {
|
|
32
|
-
obj["@type"] = "CryptoSignaturePublicKey";
|
|
33
|
-
}
|
|
34
|
-
return obj;
|
|
35
21
|
}
|
|
36
22
|
clear() {
|
|
37
23
|
this.publicKey.clear();
|
|
38
24
|
}
|
|
39
|
-
serialize(verbose = true) {
|
|
40
|
-
return JSON.stringify(this.toJSON(verbose));
|
|
41
|
-
}
|
|
42
25
|
toBase64(verbose = true) {
|
|
43
26
|
return CoreBuffer_1.CoreBuffer.utf8_base64(this.serialize(verbose));
|
|
44
27
|
}
|
|
45
28
|
static from(value) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
static
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
algorithm: value.alg,
|
|
59
|
-
publicKey: buffer
|
|
60
|
-
});
|
|
29
|
+
return this.fromAny(value);
|
|
30
|
+
}
|
|
31
|
+
static preFrom(value) {
|
|
32
|
+
if (value.pub) {
|
|
33
|
+
value = {
|
|
34
|
+
algorithm: value.alg,
|
|
35
|
+
publicKey: value.pub
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
CryptoSignatureValidation_1.CryptoSignatureValidation.checkSignatureAlgorithm(value.algorithm);
|
|
39
|
+
CryptoSignatureValidation_1.CryptoSignatureValidation.checkSignaturePublicKey(value.publicKey, value.algorithm, "publicKey");
|
|
40
|
+
return value;
|
|
61
41
|
}
|
|
62
|
-
static
|
|
63
|
-
return
|
|
42
|
+
static fromJSON(value) {
|
|
43
|
+
return this.fromAny(value);
|
|
64
44
|
}
|
|
65
|
-
static
|
|
66
|
-
|
|
67
|
-
return await this.fromJSON(obj);
|
|
45
|
+
static fromBase64(value) {
|
|
46
|
+
return this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
|
|
68
47
|
}
|
|
69
48
|
};
|
|
70
|
-
CryptoSignaturePublicKey =
|
|
71
|
-
(0, ts_serval_1.type)("CryptoSignaturePublicKey")
|
|
72
|
-
__metadata("design:paramtypes", [Number, CoreBuffer_1.CoreBuffer])
|
|
49
|
+
CryptoSignaturePublicKey = __decorate([
|
|
50
|
+
(0, ts_serval_1.type)("CryptoSignaturePublicKey")
|
|
73
51
|
], CryptoSignaturePublicKey);
|
|
74
52
|
exports.CryptoSignaturePublicKey = CryptoSignaturePublicKey;
|
|
75
53
|
//# sourceMappingURL=CryptoSignaturePublicKey.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoSignaturePublicKey.js","sourceRoot":"","sources":["../../src/signature/CryptoSignaturePublicKey.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CryptoSignaturePublicKey.js","sourceRoot":"","sources":["../../src/signature/CryptoSignaturePublicKey.ts"],"names":[],"mappings":";;;;;;;;;AAAA,kDAAsE;AACtE,8CAAoE;AACpE,wDAAqD;AAErD,2EAAwE;AAaxE,IAAa,wBAAwB,GAArC,MAAa,wBAAyB,SAAQ,iCAAe;IAGzC,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,0BAA0B,CAAC,CAAC,CAAC,SAAS;SAC5D,CAAC;IACN,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAEe,QAAQ,CAAC,OAAO,GAAG,IAAI;QACnC,OAAO,uBAAU,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAEM,MAAM,CAAU,IAAI,CAAC,KAA2D;QACnF,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAU,OAAO,CAAC,KAAU;QACrC,IAAI,KAAK,CAAC,GAAG,EAAE;YACX,KAAK,GAAG;gBACJ,SAAS,EAAE,KAAK,CAAC,GAAG;gBACpB,SAAS,EAAE,KAAK,CAAC,GAAG;aACvB,CAAC;SACL;QAED,qDAAyB,CAAC,uBAAuB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAEnE,qDAAyB,CAAC,uBAAuB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAEjG,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAA0C;QAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAU,UAAU,CAAC,KAAa;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AA7CY,wBAAwB;IADpC,IAAA,gBAAI,EAAC,0BAA0B,CAAC;GACpB,wBAAwB,CA6CpC;AA7CY,4DAAwB"}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { CoreBuffer } from "../CoreBuffer";
|
|
2
2
|
import { CryptoError } from "../CryptoError";
|
|
3
3
|
import { CryptoValidation } from "../CryptoValidation";
|
|
4
|
-
import {
|
|
5
|
-
import { CryptoSignaturePublicKey } from "./CryptoSignaturePublicKey";
|
|
6
|
-
import { CryptoSignatureAlgorithm } from "./CryptoSignatures";
|
|
4
|
+
import { CryptoSignatureAlgorithm } from "./CryptoSignatureAlgorithm";
|
|
7
5
|
export declare class CryptoSignatureValidation extends CryptoValidation {
|
|
8
|
-
static readonly PRIVATE_KEY_MIN_BYTES
|
|
9
|
-
static readonly PRIVATE_KEY_MAX_BYTES
|
|
10
|
-
static readonly PUBLIC_KEY_MIN_BYTES
|
|
11
|
-
static readonly PUBLIC_KEY_MAX_BYTES
|
|
12
|
-
static readonly SIGNATURE_MIN_BYTES
|
|
13
|
-
static readonly SIGNATURE_MAX_BYTES
|
|
6
|
+
static readonly PRIVATE_KEY_MIN_BYTES = 20;
|
|
7
|
+
static readonly PRIVATE_KEY_MAX_BYTES = 80;
|
|
8
|
+
static readonly PUBLIC_KEY_MIN_BYTES = 20;
|
|
9
|
+
static readonly PUBLIC_KEY_MAX_BYTES = 80;
|
|
10
|
+
static readonly SIGNATURE_MIN_BYTES = 20;
|
|
11
|
+
static readonly SIGNATURE_MAX_BYTES = 100;
|
|
14
12
|
static checkSignatureAlgorithm(algorithm: number, throwError?: boolean): CryptoError | undefined;
|
|
15
13
|
static checkSignaturePrivateKeyAsString(key: string, propertyName?: string, throwError?: boolean): CryptoError | undefined;
|
|
16
14
|
static checkSignaturePrivateKeyAsBuffer(buffer: CoreBuffer, propertyName?: string, throwError?: boolean): CryptoError | undefined;
|
|
17
|
-
static checkSignaturePrivateKey(privateKey:
|
|
15
|
+
static checkSignaturePrivateKey(privateKey: string | CoreBuffer, propertyName?: string, throwError?: boolean): CryptoError | undefined;
|
|
18
16
|
static checkSignaturePublicKeyAsString(key: string, algorithm: CryptoSignatureAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
|
|
19
17
|
static checkSignaturePublicKeyAsBuffer(buffer: CoreBuffer, algorithm: CryptoSignatureAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
|
|
20
|
-
static checkSignaturePublicKey(publicKey:
|
|
18
|
+
static checkSignaturePublicKey(publicKey: string | CoreBuffer, algorithm: CryptoSignatureAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
|
|
21
19
|
static checkSignatureAsString(signature: string, throwError?: boolean): CryptoError | undefined;
|
|
22
20
|
static checkSignatureAsBuffer(signature: CoreBuffer, throwError?: boolean): CryptoError | undefined;
|
|
21
|
+
static checkSignature(signature: string | CoreBuffer, throwError?: boolean): CryptoError | undefined;
|
|
23
22
|
static checkSignaturePublicKeyId(keyId: string, throwError?: boolean): CryptoError | undefined;
|
|
24
23
|
static checkSignatureKeyId(keyId: string, throwError?: boolean): CryptoError | undefined;
|
|
25
24
|
static checkSignatureId(id: string, throwError?: boolean): CryptoError | undefined;
|
|
26
|
-
static checkSignatureKeypair(privateKey: CryptoSignaturePrivateKey, publicKey: CryptoSignaturePublicKey, throwError?: boolean): CryptoError | undefined;
|
|
27
25
|
}
|
|
@@ -4,8 +4,6 @@ exports.CryptoSignatureValidation = void 0;
|
|
|
4
4
|
const CryptoError_1 = require("../CryptoError");
|
|
5
5
|
const CryptoErrorCode_1 = require("../CryptoErrorCode");
|
|
6
6
|
const CryptoValidation_1 = require("../CryptoValidation");
|
|
7
|
-
const CryptoSignaturePrivateKey_1 = require("./CryptoSignaturePrivateKey");
|
|
8
|
-
const CryptoSignaturePublicKey_1 = require("./CryptoSignaturePublicKey");
|
|
9
7
|
class CryptoSignatureValidation extends CryptoValidation_1.CryptoValidation {
|
|
10
8
|
static checkSignatureAlgorithm(algorithm, throwError = true) {
|
|
11
9
|
let error;
|
|
@@ -28,14 +26,11 @@ class CryptoSignatureValidation extends CryptoValidation_1.CryptoValidation {
|
|
|
28
26
|
static checkSignaturePrivateKeyAsBuffer(buffer, propertyName = "privateKey", throwError = true) {
|
|
29
27
|
return super.checkBuffer(buffer, this.PRIVATE_KEY_MIN_BYTES, this.PRIVATE_KEY_MAX_BYTES, propertyName, throwError);
|
|
30
28
|
}
|
|
31
|
-
static checkSignaturePrivateKey(privateKey, throwError = true) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
error = new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.SignatureWrongPrivateKey, "PrivateKey must be of type CryptoSignaturePrivateKey.");
|
|
29
|
+
static checkSignaturePrivateKey(privateKey, propertyName = "privateKey", throwError = true) {
|
|
30
|
+
if (typeof privateKey === "string") {
|
|
31
|
+
return this.checkSignaturePrivateKeyAsString(privateKey, propertyName, throwError);
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
throw error;
|
|
38
|
-
return error;
|
|
33
|
+
return this.checkSignaturePrivateKeyAsBuffer(privateKey, propertyName, throwError);
|
|
39
34
|
}
|
|
40
35
|
static checkSignaturePublicKeyAsString(key, algorithm, propertyName = "publicKey", throwError = true) {
|
|
41
36
|
return super.checkSerializedBuffer(key, this.PUBLIC_KEY_MIN_BYTES, this.PUBLIC_KEY_MAX_BYTES, propertyName, throwError);
|
|
@@ -43,14 +38,11 @@ class CryptoSignatureValidation extends CryptoValidation_1.CryptoValidation {
|
|
|
43
38
|
static checkSignaturePublicKeyAsBuffer(buffer, algorithm, propertyName = "publicKey", throwError = true) {
|
|
44
39
|
return super.checkBuffer(buffer, this.PUBLIC_KEY_MIN_BYTES, this.PUBLIC_KEY_MAX_BYTES, propertyName, throwError);
|
|
45
40
|
}
|
|
46
|
-
static checkSignaturePublicKey(publicKey, throwError = true) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
error = new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.SignatureWrongPublicKey, "Public key must be of type CryptoSignaturePublicKey.");
|
|
41
|
+
static checkSignaturePublicKey(publicKey, algorithm, propertyName = "publicKey", throwError = true) {
|
|
42
|
+
if (typeof publicKey === "string") {
|
|
43
|
+
return this.checkSignaturePublicKeyAsString(publicKey, algorithm, propertyName, throwError);
|
|
50
44
|
}
|
|
51
|
-
|
|
52
|
-
throw error;
|
|
53
|
-
return error;
|
|
45
|
+
return this.checkSignaturePublicKeyAsBuffer(publicKey, algorithm, propertyName, throwError);
|
|
54
46
|
}
|
|
55
47
|
static checkSignatureAsString(signature, throwError = true) {
|
|
56
48
|
return this.checkSerializedBuffer(signature, this.SIGNATURE_MIN_BYTES, this.SIGNATURE_MAX_BYTES, "signature", throwError);
|
|
@@ -58,6 +50,11 @@ class CryptoSignatureValidation extends CryptoValidation_1.CryptoValidation {
|
|
|
58
50
|
static checkSignatureAsBuffer(signature, throwError = true) {
|
|
59
51
|
return this.checkBuffer(signature, this.SIGNATURE_MIN_BYTES, this.SIGNATURE_MAX_BYTES, "signature", throwError);
|
|
60
52
|
}
|
|
53
|
+
static checkSignature(signature, throwError = true) {
|
|
54
|
+
if (typeof signature === "string")
|
|
55
|
+
return this.checkSignatureAsString(signature, throwError);
|
|
56
|
+
return this.checkSignatureAsBuffer(signature, throwError);
|
|
57
|
+
}
|
|
61
58
|
static checkSignaturePublicKeyId(keyId, throwError = true) {
|
|
62
59
|
return this.checkId(keyId, 0, 30, throwError);
|
|
63
60
|
}
|
|
@@ -91,25 +88,6 @@ class CryptoSignatureValidation extends CryptoValidation_1.CryptoValidation {
|
|
|
91
88
|
throw error;
|
|
92
89
|
return error;
|
|
93
90
|
}
|
|
94
|
-
static checkSignatureKeypair(privateKey, publicKey, throwError = true) {
|
|
95
|
-
let error;
|
|
96
|
-
error = this.checkSignaturePublicKey(publicKey, throwError);
|
|
97
|
-
if (error && throwError)
|
|
98
|
-
throw error;
|
|
99
|
-
else if (error)
|
|
100
|
-
return error;
|
|
101
|
-
error = this.checkSignaturePrivateKey(privateKey, throwError);
|
|
102
|
-
if (error && throwError)
|
|
103
|
-
throw error;
|
|
104
|
-
else if (error)
|
|
105
|
-
return error;
|
|
106
|
-
if (privateKey.algorithm !== publicKey.algorithm) {
|
|
107
|
-
error = new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.SignatureWrongAlgorithm, "Algorithms of private and public key do not match.");
|
|
108
|
-
}
|
|
109
|
-
if (error && throwError)
|
|
110
|
-
throw error;
|
|
111
|
-
return error;
|
|
112
|
-
}
|
|
113
91
|
}
|
|
114
92
|
exports.CryptoSignatureValidation = CryptoSignatureValidation;
|
|
115
93
|
CryptoSignatureValidation.PRIVATE_KEY_MIN_BYTES = 20;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoSignatureValidation.js","sourceRoot":"","sources":["../../src/signature/CryptoSignatureValidation.ts"],"names":[],"mappings":";;;AACA,gDAA6C;AAC7C,wDAAqD;AACrD,0DAAuD;
|
|
1
|
+
{"version":3,"file":"CryptoSignatureValidation.js","sourceRoot":"","sources":["../../src/signature/CryptoSignatureValidation.ts"],"names":[],"mappings":";;;AACA,gDAA6C;AAC7C,wDAAqD;AACrD,0DAAuD;AAGvD,MAAa,yBAA0B,SAAQ,mCAAgB;IAQpD,MAAM,CAAC,uBAAuB,CAAC,SAAiB,EAAE,UAAU,GAAG,IAAI;QACtE,IAAI,KAA8B,CAAC;QACnC,QAAQ,SAAS,EAAE;YACf,2BAA4C;YAC5C,wBAAyC;YACzC;gBACI,MAAM;YACV;gBACI,KAAK,GAAG,IAAI,yBAAW,CACnB,iCAAe,CAAC,uBAAuB,EACvC,8CAA8C,CACjD,CAAC;gBACF,MAAM;SACb;QACD,IAAI,UAAU,IAAI,KAAK;YAAE,MAAM,KAAK,CAAC;QACrC,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,gCAAgC,CAC1C,GAAW,EACX,YAAY,GAAG,YAAY,EAC3B,UAAU,GAAG,IAAI;QAEjB,OAAO,KAAK,CAAC,qBAAqB,CAC9B,GAAG,EACH,IAAI,CAAC,qBAAqB,EAC1B,IAAI,CAAC,qBAAqB,EAC1B,YAAY,EACZ,UAAU,CACb,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,gCAAgC,CAC1C,MAAkB,EAClB,YAAY,GAAG,YAAY,EAC3B,UAAU,GAAG,IAAI;QAEjB,OAAO,KAAK,CAAC,WAAW,CACpB,MAAM,EACN,IAAI,CAAC,qBAAqB,EAC1B,IAAI,CAAC,qBAAqB,EAC1B,YAAY,EAC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,IAAI,UAAU;YAAE,MAAM,KAAK,CAAC;QACrC,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,gBAAgB,CAAC,EAAU,EAAE,UAAU,GAAG,IAAI;QACxD,IAAI,KAAK,CAAC;QACV,IAAI,OAAO,EAAE,KAAK,WAAW,EAAE;YAC3B,OAAO;SACV;QACD,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;YACxB,KAAK,GAAG,IAAI,yBAAW,CAAC,iCAAe,CAAC,OAAO,EAAE,sCAAsC,CAAC,CAAC;SAC5F;QACD,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE;YAC1B,KAAK,GAAG,IAAI,yBAAW,CAAC,iCAAe,CAAC,OAAO,EAAE,+CAA+C,CAAC,CAAC;SACrG;QACD,IAAI,KAAK,IAAI,UAAU;YAAE,MAAM,KAAK,CAAC;QACrC,OAAO,KAAK,CAAC;IACjB,CAAC;;AAjKL,8DAkKC;AAjK0B,+CAAqB,GAAG,EAAE,CAAC;AAC3B,+CAAqB,GAAG,EAAE,CAAC;AAC3B,8CAAoB,GAAG,EAAE,CAAC;AAC1B,8CAAoB,GAAG,EAAE,CAAC;AAC1B,6CAAmB,GAAG,EAAE,CAAC;AACzB,6CAAmB,GAAG,GAAG,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { CoreBuffer } from "../CoreBuffer";
|
|
2
2
|
import { CryptoHashAlgorithm } from "../hash/CryptoHash";
|
|
3
3
|
import { CryptoSignature } from "./CryptoSignature";
|
|
4
|
+
import { CryptoSignatureAlgorithm } from "./CryptoSignatureAlgorithm";
|
|
4
5
|
import { CryptoSignatureKeypair } from "./CryptoSignatureKeypair";
|
|
5
6
|
import { CryptoSignaturePrivateKey } from "./CryptoSignaturePrivateKey";
|
|
6
7
|
import { CryptoSignaturePublicKey } from "./CryptoSignaturePublicKey";
|
|
7
|
-
export declare const enum CryptoSignatureAlgorithm {
|
|
8
|
-
ECDSA_P256 = 1,
|
|
9
|
-
ECDSA_P521 = 2,
|
|
10
|
-
ECDSA_ED25519 = 3
|
|
11
|
-
}
|
|
12
8
|
export declare class CryptoSignatures {
|
|
13
9
|
static privateKeyToPublicKey(privateKey: CryptoSignaturePrivateKey): Promise<CryptoSignaturePublicKey>;
|
|
14
10
|
/**
|
|
@@ -16,7 +16,7 @@ class CryptoSignatures {
|
|
|
16
16
|
case 3 /* ECDSA_ED25519 */:
|
|
17
17
|
try {
|
|
18
18
|
const publicKey = (await SodiumWrapper_1.SodiumWrapper.ready()).crypto_sign_ed25519_sk_to_pk(privateKey.privateKey.buffer);
|
|
19
|
-
return
|
|
19
|
+
return CryptoSignaturePublicKey_1.CryptoSignaturePublicKey.from({
|
|
20
20
|
algorithm: privateKey.algorithm,
|
|
21
21
|
publicKey: CoreBuffer_1.CoreBuffer.from(publicKey)
|
|
22
22
|
});
|
|
@@ -47,9 +47,9 @@ class CryptoSignatures {
|
|
|
47
47
|
default:
|
|
48
48
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.NotYetImplemented);
|
|
49
49
|
}
|
|
50
|
-
const privateKey =
|
|
51
|
-
const publicKey =
|
|
52
|
-
const keypair =
|
|
50
|
+
const privateKey = CryptoSignaturePrivateKey_1.CryptoSignaturePrivateKey.from({ algorithm, privateKey: CoreBuffer_1.CoreBuffer.from(pair.privateKey) });
|
|
51
|
+
const publicKey = CryptoSignaturePublicKey_1.CryptoSignaturePublicKey.from({ algorithm, publicKey: CoreBuffer_1.CoreBuffer.from(pair.publicKey) });
|
|
52
|
+
const keypair = CryptoSignatureKeypair_1.CryptoSignatureKeypair.from({ publicKey, privateKey });
|
|
53
53
|
return keypair;
|
|
54
54
|
}
|
|
55
55
|
static async sign(content, privateKey, algorithm = 2 /* SHA512 */, keyId, id) {
|
|
@@ -59,7 +59,7 @@ class CryptoSignatures {
|
|
|
59
59
|
try {
|
|
60
60
|
const signatureArray = (await SodiumWrapper_1.SodiumWrapper.ready()).crypto_sign_detached(content.buffer, privateKeyBuffer);
|
|
61
61
|
const signatureBuffer = new CoreBuffer_1.CoreBuffer(signatureArray);
|
|
62
|
-
const signature =
|
|
62
|
+
const signature = CryptoSignature_1.CryptoSignature.from({ signature: signatureBuffer, algorithm, keyId, id });
|
|
63
63
|
return signature;
|
|
64
64
|
}
|
|
65
65
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoSignatures.js","sourceRoot":"","sources":["../../src/signature/CryptoSignatures.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAC3C,gDAA6C;AAC7C,wDAAqD;AAErD,oDAAiD;AACjD,uDAAoD;
|
|
1
|
+
{"version":3,"file":"CryptoSignatures.js","sourceRoot":"","sources":["../../src/signature/CryptoSignatures.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAC3C,gDAA6C;AAC7C,wDAAqD;AAErD,oDAAiD;AACjD,uDAAoD;AAEpD,qEAAkE;AAClE,2EAAwE;AACxE,yEAAsE;AACtE,2EAAwE;AAExE,MAAa,gBAAgB;IAClB,MAAM,CAAC,KAAK,CAAC,qBAAqB,CACrC,UAAqC;QAErC,QAAQ,UAAU,CAAC,SAAS,EAAE;YAC1B;gBACI,IAAI;oBACA,MAAM,SAAS,GAAG,CAAC,MAAM,6BAAa,CAAC,KAAK,EAAE,CAAC,CAAC,4BAA4B,CACxE,UAAU,CAAC,UAAU,CAAC,MAAM,CAC/B,CAAC;oBACF,OAAO,mDAAwB,CAAC,IAAI,CAAC;wBACjC,SAAS,EAAE,UAAU,CAAC,SAAS;wBAC/B,SAAS,EAAE,uBAAU,CAAC,IAAI,CAAC,SAAS,CAAC;qBACxC,CAAC,CAAC;iBACN;gBAAC,OAAO,CAAC,EAAE;oBACR,MAAM,IAAI,yBAAW,CAAC,iCAAe,CAAC,sBAAsB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;iBACzE;YACL;gBACI,MAAM,IAAI,yBAAW,CAAC,iCA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K,EAAE,CAAC,CAAC,2BAA2B,CACnE,SAAS,CAAC,SAAS,CAAC,MAAM,EAC1B,OAAO,CAAC,MAAM,EACd,eAAe,CAClB,CAAC;YAEF,OAAO,KAAK,CAAC;SAChB;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,KAAK,GAAG,IAAI,yBAAW,CAAC,iCAAe,CAAC,eAAe,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YACvE,MAAM,KAAK,CAAC;SACf;IACL,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,SAAgD;QAC/E,IAAI,MAAkB,CAAC;QACvB,IAAI,SAAS,YAAY,mDAAwB,EAAE;YAC/C,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC;SAChC;aAAM,IAAI,SAAS,YAAY,uBAAU,EAAE;YACxC,MAAM,GAAG,SAAS,CAAC;SACtB;aAAM;YACH,MAAM,IAAI,yBAAW,CACjB,iCAAe,CAAC,uBAAuB,EACvC,8EAA8E,CACjF,CAAC;SACL;QACD,qDAAyB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE9C,OAAO,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;CACJ;AAnID,4CAmIC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ISerializable, ISerialized, Serializable } from "@js-soft/ts-serval";
|
|
2
2
|
import { CoreBuffer, IClearable, ICoreBuffer } from "../CoreBuffer";
|
|
3
3
|
import { CryptoEncryptionAlgorithm } from "../encryption/CryptoEncryption";
|
|
4
4
|
import { CryptoPublicState } from "./CryptoPublicState";
|
|
@@ -11,7 +11,7 @@ export interface ICryptoPrivateStateSerialized extends ISerialized {
|
|
|
11
11
|
id?: string;
|
|
12
12
|
typ: number;
|
|
13
13
|
}
|
|
14
|
-
export interface ICryptoPrivateState extends
|
|
14
|
+
export interface ICryptoPrivateState extends ISerializable {
|
|
15
15
|
secretKey: ICoreBuffer;
|
|
16
16
|
nonce: ICoreBuffer;
|
|
17
17
|
counter: number;
|
|
@@ -19,27 +19,19 @@ export interface ICryptoPrivateState extends ISerializableAsync {
|
|
|
19
19
|
id?: string;
|
|
20
20
|
stateType: CryptoStateType;
|
|
21
21
|
}
|
|
22
|
-
export declare class CryptoPrivateState extends
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
private readonly _secretKey;
|
|
30
|
-
get secretKey(): CoreBuffer;
|
|
31
|
-
private readonly _algorithm;
|
|
32
|
-
get algorithm(): CryptoEncryptionAlgorithm;
|
|
33
|
-
private readonly _stateType;
|
|
34
|
-
get stateType(): CryptoStateType;
|
|
35
|
-
constructor(nonce: CoreBuffer, counter: number, secretKey: CoreBuffer, algorithm: CryptoEncryptionAlgorithm, stateType: CryptoStateType, id?: string);
|
|
22
|
+
export declare class CryptoPrivateState extends Serializable implements ICryptoPrivateState, IClearable {
|
|
23
|
+
id?: string;
|
|
24
|
+
nonce: CoreBuffer;
|
|
25
|
+
counter: number;
|
|
26
|
+
secretKey: CoreBuffer;
|
|
27
|
+
algorithm: CryptoEncryptionAlgorithm;
|
|
28
|
+
stateType: CryptoStateType;
|
|
36
29
|
protected setCounter(value: number): void;
|
|
37
30
|
clear(): void;
|
|
38
31
|
toString(): string;
|
|
39
|
-
serialize(): string;
|
|
40
32
|
toPublicState(): CryptoPublicState;
|
|
41
33
|
toJSON(verbose?: boolean): ICryptoPrivateStateSerialized;
|
|
42
|
-
static
|
|
43
|
-
static
|
|
44
|
-
static
|
|
34
|
+
protected static preFrom(value: any): any;
|
|
35
|
+
static from(obj: CryptoPrivateState | ICryptoPrivateState): CryptoPrivateState;
|
|
36
|
+
static fromJSON(value: ICryptoPrivateStateSerialized): CryptoPrivateState;
|
|
45
37
|
}
|
|
@@ -1,50 +1,23 @@
|
|
|
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.CryptoPrivateState = void 0;
|
|
4
13
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
5
14
|
const CoreBuffer_1 = require("../CoreBuffer");
|
|
6
|
-
const CryptoError_1 = require("../CryptoError");
|
|
7
|
-
const CryptoErrorCode_1 = require("../CryptoErrorCode");
|
|
8
15
|
const CryptoValidation_1 = require("../CryptoValidation");
|
|
9
16
|
const CryptoPublicState_1 = require("./CryptoPublicState");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(algorithm);
|
|
13
|
-
CryptoValidation_1.CryptoValidation.checkCounter(counter);
|
|
14
|
-
CryptoValidation_1.CryptoValidation.checkNonceForAlgorithm(nonce, algorithm);
|
|
15
|
-
CryptoValidation_1.CryptoValidation.checkSecretKeyForAlgorithm(secretKey, algorithm);
|
|
16
|
-
CryptoValidation_1.CryptoValidation.checkStateType(stateType);
|
|
17
|
-
if (id) {
|
|
18
|
-
CryptoValidation_1.CryptoValidation.checkId(id);
|
|
19
|
-
}
|
|
20
|
-
super();
|
|
21
|
-
this._nonce = nonce;
|
|
22
|
-
this._counter = counter ? counter : 0;
|
|
23
|
-
this._secretKey = secretKey;
|
|
24
|
-
this._algorithm = algorithm;
|
|
25
|
-
this._stateType = stateType;
|
|
26
|
-
this._id = id;
|
|
27
|
-
}
|
|
28
|
-
get id() {
|
|
29
|
-
return this._id;
|
|
30
|
-
}
|
|
31
|
-
get nonce() {
|
|
32
|
-
return this._nonce;
|
|
33
|
-
}
|
|
34
|
-
get counter() {
|
|
35
|
-
return this._counter;
|
|
36
|
-
}
|
|
37
|
-
get secretKey() {
|
|
38
|
-
return this._secretKey;
|
|
39
|
-
}
|
|
40
|
-
get algorithm() {
|
|
41
|
-
return this._algorithm;
|
|
42
|
-
}
|
|
43
|
-
get stateType() {
|
|
44
|
-
return this._stateType;
|
|
45
|
-
}
|
|
17
|
+
const CryptoStateType_1 = require("./CryptoStateType");
|
|
18
|
+
class CryptoPrivateState extends ts_serval_1.Serializable {
|
|
46
19
|
setCounter(value) {
|
|
47
|
-
this.
|
|
20
|
+
this.counter = value;
|
|
48
21
|
}
|
|
49
22
|
clear() {
|
|
50
23
|
this.secretKey.clear();
|
|
@@ -53,59 +26,82 @@ class CryptoPrivateState extends ts_serval_1.SerializableAsync {
|
|
|
53
26
|
toString() {
|
|
54
27
|
return this.serialize();
|
|
55
28
|
}
|
|
56
|
-
serialize() {
|
|
57
|
-
const obj = this.toJSON();
|
|
58
|
-
return JSON.stringify(obj);
|
|
59
|
-
}
|
|
60
29
|
toPublicState() {
|
|
61
|
-
return
|
|
30
|
+
return CryptoPublicState_1.CryptoPublicState.from({
|
|
31
|
+
nonce: this.nonce.clone(),
|
|
32
|
+
algorithm: this.algorithm,
|
|
33
|
+
stateType: this.stateType,
|
|
34
|
+
id: this.id
|
|
35
|
+
});
|
|
62
36
|
}
|
|
63
37
|
toJSON(verbose = true) {
|
|
64
|
-
|
|
38
|
+
return {
|
|
65
39
|
nnc: this.nonce.toBase64URL(),
|
|
66
40
|
cnt: this.counter,
|
|
67
41
|
key: this.secretKey.toBase64URL(),
|
|
68
42
|
alg: this.algorithm,
|
|
69
|
-
typ: this.stateType
|
|
43
|
+
typ: this.stateType,
|
|
44
|
+
id: this.id,
|
|
45
|
+
"@type": verbose ? "CryptoPrivateState" : undefined
|
|
70
46
|
};
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
}
|
|
48
|
+
static preFrom(value) {
|
|
49
|
+
if (value.nnc) {
|
|
50
|
+
value = {
|
|
51
|
+
nonce: value.nnc,
|
|
52
|
+
counter: value.cnt,
|
|
53
|
+
secretKey: value.key,
|
|
54
|
+
algorithm: value.alg,
|
|
55
|
+
stateType: value.typ,
|
|
56
|
+
id: value.id
|
|
57
|
+
};
|
|
73
58
|
}
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(value.algorithm);
|
|
60
|
+
CryptoValidation_1.CryptoValidation.checkCounter(value.counter);
|
|
61
|
+
CryptoValidation_1.CryptoValidation.checkNonce(value.nonce, value.algorithm);
|
|
62
|
+
CryptoValidation_1.CryptoValidation.checkSecretKeyForAlgorithm(value.secretKey, value.algorithm);
|
|
63
|
+
CryptoValidation_1.CryptoValidation.checkStateType(value.stateType);
|
|
64
|
+
if (value.id) {
|
|
65
|
+
CryptoValidation_1.CryptoValidation.checkId(value.id);
|
|
76
66
|
}
|
|
77
|
-
return
|
|
67
|
+
return value;
|
|
78
68
|
}
|
|
79
69
|
static from(obj) {
|
|
80
|
-
|
|
81
|
-
if (!obj.secretKey) {
|
|
82
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongSecretKey, "No secretKey property set.");
|
|
83
|
-
}
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
85
|
-
if (!obj.nonce) {
|
|
86
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongNonce, "No nonce nor counter property set.");
|
|
87
|
-
}
|
|
88
|
-
if (typeof obj.counter === "undefined") {
|
|
89
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongCounter, "Wrong counter.");
|
|
90
|
-
}
|
|
91
|
-
return Promise.resolve(new CryptoPrivateState(CoreBuffer_1.CoreBuffer.from(obj.nonce), obj.counter, CoreBuffer_1.CoreBuffer.from(obj.secretKey), obj.algorithm, obj.stateType, obj.id));
|
|
70
|
+
return this.fromAny(obj);
|
|
92
71
|
}
|
|
93
72
|
static fromJSON(value) {
|
|
94
|
-
|
|
95
|
-
CryptoValidation_1.CryptoValidation.checkCounter(value.cnt);
|
|
96
|
-
CryptoValidation_1.CryptoValidation.checkSerializedBuffer(value.nnc, 0, 24, "nonce");
|
|
97
|
-
CryptoValidation_1.CryptoValidation.checkSerializedSecretKeyForAlgorithm(value.key, value.alg);
|
|
98
|
-
if (value.typ) {
|
|
99
|
-
CryptoValidation_1.CryptoValidation.checkStateType(value.typ);
|
|
100
|
-
}
|
|
101
|
-
const nonceBuffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.nnc);
|
|
102
|
-
const secretKeyBuffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.key);
|
|
103
|
-
return Promise.resolve(new CryptoPrivateState(nonceBuffer, value.cnt, secretKeyBuffer, value.alg, value.typ, value.id));
|
|
104
|
-
}
|
|
105
|
-
static async deserialize(value) {
|
|
106
|
-
const obj = JSON.parse(value);
|
|
107
|
-
return await this.from(obj);
|
|
73
|
+
return this.fromAny(value);
|
|
108
74
|
}
|
|
109
75
|
}
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, ts_serval_1.validate)({ nullable: true }),
|
|
78
|
+
(0, ts_serval_1.serialize)(),
|
|
79
|
+
__metadata("design:type", String)
|
|
80
|
+
], CryptoPrivateState.prototype, "id", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
(0, ts_serval_1.validate)(),
|
|
83
|
+
(0, ts_serval_1.serialize)(),
|
|
84
|
+
__metadata("design:type", CoreBuffer_1.CoreBuffer)
|
|
85
|
+
], CryptoPrivateState.prototype, "nonce", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, ts_serval_1.validate)(),
|
|
88
|
+
(0, ts_serval_1.serialize)(),
|
|
89
|
+
__metadata("design:type", Number)
|
|
90
|
+
], CryptoPrivateState.prototype, "counter", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, ts_serval_1.validate)(),
|
|
93
|
+
(0, ts_serval_1.serialize)(),
|
|
94
|
+
__metadata("design:type", CoreBuffer_1.CoreBuffer)
|
|
95
|
+
], CryptoPrivateState.prototype, "secretKey", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, ts_serval_1.validate)(),
|
|
98
|
+
(0, ts_serval_1.serialize)(),
|
|
99
|
+
__metadata("design:type", Number)
|
|
100
|
+
], CryptoPrivateState.prototype, "algorithm", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, ts_serval_1.validate)(),
|
|
103
|
+
(0, ts_serval_1.serialize)(),
|
|
104
|
+
__metadata("design:type", Number)
|
|
105
|
+
], CryptoPrivateState.prototype, "stateType", void 0);
|
|
110
106
|
exports.CryptoPrivateState = CryptoPrivateState;
|
|
111
107
|
//# sourceMappingURL=CryptoPrivateState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoPrivateState.js","sourceRoot":"","sources":["../../src/state/CryptoPrivateState.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CryptoPrivateState.js","sourceRoot":"","sources":["../../src/state/CryptoPrivateState.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAmG;AACnG,8CAAoE;AACpE,0DAAuD;AAEvD,2DAAwD;AACxD,uDAAoD;AAoBpD,MAAa,kBAAmB,SAAQ,wBAAY;IAyBtC,UAAU,CAAC,KAAa;QAC9B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACzB,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAEe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,CAAC,CAAC;QAC1D,mCAAgB,CAAC,0BAA0B,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;QAC9E,mCAAgB,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjD,IAAI,KAAK,CAAC,EAAE,EAAE;YACV,mCAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;SACtC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAC,GAA6C;QAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAAoC;QACvD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACJ;AAxFG;IAFC,IAAA,oBAAQ,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,IAAA,qBAAS,GAAE;;8CACO;AAInB;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACE,uBAAU;iDAAC;AAIzB;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;;mDACW;AAIvB;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACM,uBAAU;qDAAC;AAI7B;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;;qDACgC;AAI5C;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;;qDACsB;AAvBtC,gDA2FC"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { CoreBuffer } from "../CoreBuffer";
|
|
2
2
|
import { CryptoCipher } from "../encryption/CryptoCipher";
|
|
3
|
-
import { CryptoEncryptionAlgorithm } from "../encryption/CryptoEncryption";
|
|
4
3
|
import { CryptoPrivateState, ICryptoPrivateState, ICryptoPrivateStateSerialized } from "./CryptoPrivateState";
|
|
5
4
|
import { CryptoPublicState } from "./CryptoPublicState";
|
|
6
5
|
export declare class CryptoPrivateStateReceive extends CryptoPrivateState {
|
|
7
|
-
constructor(nonce: CoreBuffer, counter: number, secretKey: CoreBuffer, algorithm: CryptoEncryptionAlgorithm, id?: string);
|
|
8
6
|
toJSON(): ICryptoPrivateStateSerialized;
|
|
9
7
|
decrypt(cipher: CryptoCipher, omitCounterCheck?: boolean): Promise<CoreBuffer>;
|
|
10
8
|
static fromNonce(nonce: CoreBuffer, secretKey: CoreBuffer, counter?: number): CryptoPrivateStateReceive;
|
|
11
|
-
static fromPublicState(publicState: CryptoPublicState, secretKey: CoreBuffer, counter?: number):
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
9
|
+
static fromPublicState(publicState: CryptoPublicState, secretKey: CoreBuffer, counter?: number): CryptoPrivateStateReceive;
|
|
10
|
+
protected static preFrom(value: any): any;
|
|
11
|
+
static from(obj: CryptoPrivateState | ICryptoPrivateState): CryptoPrivateStateReceive;
|
|
12
|
+
static fromJSON(value: ICryptoPrivateStateSerialized): CryptoPrivateStateReceive;
|
|
15
13
|
}
|