@nmshd/crypto 1.0.9 → 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 +7 -10
- package/dist/CryptoPrivateKey.js +18 -33
- package/dist/CryptoPrivateKey.js.map +1 -1
- package/dist/CryptoPublicKey.d.ts +6 -9
- package/dist/CryptoPublicKey.js +16 -31
- package/dist/CryptoPublicKey.js.map +1 -1
- package/dist/CryptoSerializable.js.map +1 -1
- package/dist/CryptoValidation.d.ts +4 -6
- package/dist/CryptoValidation.js +16 -29
- package/dist/CryptoValidation.js.map +1 -1
- package/dist/buildInformation.js +4 -4
- package/dist/encryption/CryptoCipher.d.ts +5 -6
- package/dist/encryption/CryptoCipher.js +59 -56
- 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 +3 -4
- package/dist/encryption/CryptoSecretKey.js +34 -30
- package/dist/encryption/CryptoSecretKey.js.map +1 -1
- package/dist/exchange/CryptoExchange.d.ts +0 -2
- package/dist/exchange/CryptoExchange.js +3 -20
- package/dist/exchange/CryptoExchange.js.map +1 -1
- package/dist/exchange/CryptoExchangeKeypair.d.ts +3 -4
- package/dist/exchange/CryptoExchangeKeypair.js +29 -22
- package/dist/exchange/CryptoExchangeKeypair.js.map +1 -1
- package/dist/exchange/CryptoExchangePrivateKey.d.ts +3 -5
- package/dist/exchange/CryptoExchangePrivateKey.js +50 -31
- package/dist/exchange/CryptoExchangePrivateKey.js.map +1 -1
- package/dist/exchange/CryptoExchangePublicKey.d.ts +3 -4
- package/dist/exchange/CryptoExchangePublicKey.js +28 -29
- package/dist/exchange/CryptoExchangePublicKey.js.map +1 -1
- package/dist/exchange/CryptoExchangeSecrets.d.ts +4 -5
- package/dist/exchange/CryptoExchangeSecrets.js +32 -34
- 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 +1 -0
- package/dist/index.js.map +1 -1
- package/dist/relationship/CryptoRelationshipPublicRequest.d.ts +1 -2
- package/dist/relationship/CryptoRelationshipPublicRequest.js +19 -34
- package/dist/relationship/CryptoRelationshipPublicRequest.js.map +1 -1
- package/dist/relationship/CryptoRelationshipPublicResponse.d.ts +1 -2
- package/dist/relationship/CryptoRelationshipPublicResponse.js +20 -30
- package/dist/relationship/CryptoRelationshipPublicResponse.js.map +1 -1
- package/dist/relationship/CryptoRelationshipRequestSecrets.d.ts +0 -1
- package/dist/relationship/CryptoRelationshipRequestSecrets.js +1 -4
- package/dist/relationship/CryptoRelationshipRequestSecrets.js.map +1 -1
- package/dist/relationship/CryptoRelationshipSecrets.d.ts +0 -1
- package/dist/relationship/CryptoRelationshipSecrets.js +1 -4
- package/dist/relationship/CryptoRelationshipSecrets.js.map +1 -1
- package/dist/signature/CryptoSignature.d.ts +5 -6
- package/dist/signature/CryptoSignature.js +36 -32
- 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 +3 -4
- package/dist/signature/CryptoSignatureKeypair.js +32 -30
- package/dist/signature/CryptoSignatureKeypair.js.map +1 -1
- package/dist/signature/CryptoSignaturePrivateKey.d.ts +5 -8
- package/dist/signature/CryptoSignaturePrivateKey.js +24 -35
- package/dist/signature/CryptoSignaturePrivateKey.js.map +1 -1
- package/dist/signature/CryptoSignaturePublicKey.d.ts +4 -7
- package/dist/signature/CryptoSignaturePublicKey.js +19 -41
- 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 +4 -4
- package/dist/signature/CryptoSignatures.js.map +1 -1
- package/dist/state/CryptoPrivateState.d.ts +7 -15
- package/dist/state/CryptoPrivateState.js +72 -76
- package/dist/state/CryptoPrivateState.js.map +1 -1
- package/dist/state/CryptoPrivateStateReceive.d.ts +2 -4
- package/dist/state/CryptoPrivateStateReceive.js +27 -39
- package/dist/state/CryptoPrivateStateReceive.js.map +1 -1
- package/dist/state/CryptoPrivateStateTransmit.d.ts +1 -2
- package/dist/state/CryptoPrivateStateTransmit.js +14 -40
- package/dist/state/CryptoPrivateStateTransmit.js.map +1 -1
- package/dist/state/CryptoPublicState.d.ts +5 -10
- package/dist/state/CryptoPublicState.js +42 -51
- 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 +3 -6
- package/dist/stream/CryptoStreamAddress.js +13 -29
- package/dist/stream/CryptoStreamAddress.js.map +1 -1
- package/dist/stream/CryptoStreamHeader.d.ts +5 -8
- package/dist/stream/CryptoStreamHeader.js +15 -18
- package/dist/stream/CryptoStreamHeader.js.map +1 -1
- package/dist/stream/CryptoStreamState.d.ts +3 -7
- package/dist/stream/CryptoStreamState.js +14 -32
- package/dist/stream/CryptoStreamState.js.map +1 -1
- package/lib-web/nmshd.crypto.js +701 -914
- 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 +3 -3
|
@@ -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");
|
|
17
|
+
const CryptoStateType_1 = require("./CryptoStateType");
|
|
10
18
|
class CryptoPrivateState extends ts_serval_1.Serializable {
|
|
11
|
-
constructor(nonce, counter, secretKey, algorithm, stateType, id) {
|
|
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
|
-
}
|
|
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.Serializable {
|
|
|
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 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 new CryptoPrivateState(nonceBuffer, value.cnt, secretKeyBuffer, value.alg, value.typ, value.id);
|
|
104
|
-
}
|
|
105
|
-
static deserialize(value) {
|
|
106
|
-
const obj = JSON.parse(value);
|
|
107
|
-
return 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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ptoCipher } 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):
|
|
9
|
+
static fromPublicState(publicState: CryptoPublicState, secretKey: CoreBuffer, counter?: number): CryptoPrivateStateReceive;
|
|
10
|
+
protected static preFrom(value: any): any;
|
|
12
11
|
static from(obj: CryptoPrivateState | ICryptoPrivateState): CryptoPrivateStateReceive;
|
|
13
12
|
static fromJSON(value: ICryptoPrivateStateSerialized): CryptoPrivateStateReceive;
|
|
14
|
-
static deserialize(value: string): CryptoPrivateStateReceive;
|
|
15
13
|
}
|
|
@@ -5,14 +5,10 @@ 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
8
|
var CryptoPrivateStateReceive_1;
|
|
12
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
10
|
exports.CryptoPrivateStateReceive = void 0;
|
|
14
11
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
15
|
-
const CoreBuffer_1 = require("../CoreBuffer");
|
|
16
12
|
const CryptoError_1 = require("../CryptoError");
|
|
17
13
|
const CryptoErrorCode_1 = require("../CryptoErrorCode");
|
|
18
14
|
const CryptoValidation_1 = require("../CryptoValidation");
|
|
@@ -20,9 +16,6 @@ const CryptoEncryption_1 = require("../encryption/CryptoEncryption");
|
|
|
20
16
|
const CryptoPrivateState_1 = require("./CryptoPrivateState");
|
|
21
17
|
const CryptoStateType_1 = require("./CryptoStateType");
|
|
22
18
|
let CryptoPrivateStateReceive = CryptoPrivateStateReceive_1 = class CryptoPrivateStateReceive extends CryptoPrivateState_1.CryptoPrivateState {
|
|
23
|
-
constructor(nonce, counter, secretKey, algorithm, id) {
|
|
24
|
-
super(nonce, counter, secretKey, algorithm, CryptoStateType_1.CryptoStateType.Receive, id);
|
|
25
|
-
}
|
|
26
19
|
toJSON() {
|
|
27
20
|
const obj = super.toJSON();
|
|
28
21
|
obj["@type"] = "CryptoPrivateStateReceive";
|
|
@@ -47,47 +40,42 @@ let CryptoPrivateStateReceive = CryptoPrivateStateReceive_1 = class CryptoPrivat
|
|
|
47
40
|
return plaintext;
|
|
48
41
|
}
|
|
49
42
|
static fromNonce(nonce, secretKey, counter = 0) {
|
|
50
|
-
return
|
|
43
|
+
return CryptoPrivateStateReceive_1.from({
|
|
44
|
+
nonce: nonce.clone(),
|
|
45
|
+
counter,
|
|
46
|
+
secretKey,
|
|
47
|
+
algorithm: 3 /* XCHACHA20_POLY1305 */,
|
|
48
|
+
stateType: CryptoStateType_1.CryptoStateType.Receive
|
|
49
|
+
});
|
|
51
50
|
}
|
|
52
51
|
static fromPublicState(publicState, secretKey, counter = 0) {
|
|
53
|
-
return
|
|
52
|
+
return CryptoPrivateStateReceive_1.from({
|
|
53
|
+
nonce: publicState.nonce.clone(),
|
|
54
|
+
counter,
|
|
55
|
+
secretKey,
|
|
56
|
+
algorithm: publicState.algorithm,
|
|
57
|
+
id: publicState.id,
|
|
58
|
+
stateType: CryptoStateType_1.CryptoStateType.Receive
|
|
59
|
+
});
|
|
54
60
|
}
|
|
55
|
-
static
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!obj.nonce) {
|
|
62
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongNonce, "No nonce set.");
|
|
63
|
-
}
|
|
64
|
-
if (typeof obj.counter === "undefined") {
|
|
65
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongCounter, "No counter.");
|
|
61
|
+
static preFrom(value) {
|
|
62
|
+
value = super.preFrom(value);
|
|
63
|
+
CryptoValidation_1.CryptoValidation.checkBufferAsStringOrBuffer(value.nonce, 0, 24, "nonce");
|
|
64
|
+
CryptoValidation_1.CryptoValidation.checkSecretKeyForAlgorithm(value.secretKey, value.algorithm);
|
|
65
|
+
if (value.stateType) {
|
|
66
|
+
CryptoValidation_1.CryptoValidation.checkStateType(value.stateType);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongType, "The given object has a wrong state type.");
|
|
69
|
-
}
|
|
70
|
-
return new CryptoPrivateStateReceive_1(CoreBuffer_1.CoreBuffer.from(obj.nonce), obj.counter, CoreBuffer_1.CoreBuffer.from(obj.secretKey), obj.algorithm, obj.id);
|
|
68
|
+
return value;
|
|
71
69
|
}
|
|
72
|
-
static
|
|
73
|
-
|
|
74
|
-
CryptoValidation_1.CryptoValidation.checkCounter(value.cnt);
|
|
75
|
-
CryptoValidation_1.CryptoValidation.checkSerializedBuffer(value.nnc, 0, 24, "nnc");
|
|
76
|
-
CryptoValidation_1.CryptoValidation.checkSerializedSecretKeyForAlgorithm(value.key, value.alg);
|
|
77
|
-
if (value.typ) {
|
|
78
|
-
CryptoValidation_1.CryptoValidation.checkStateType(value.typ);
|
|
79
|
-
}
|
|
80
|
-
const nonceBuffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.nnc);
|
|
81
|
-
const secretKeyBuffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.key);
|
|
82
|
-
return new CryptoPrivateStateReceive_1(nonceBuffer, value.cnt, secretKeyBuffer, value.alg, value.id);
|
|
70
|
+
static from(obj) {
|
|
71
|
+
return this.fromAny(obj);
|
|
83
72
|
}
|
|
84
|
-
static
|
|
85
|
-
return this.
|
|
73
|
+
static fromJSON(value) {
|
|
74
|
+
return this.fromAny(value);
|
|
86
75
|
}
|
|
87
76
|
};
|
|
88
77
|
CryptoPrivateStateReceive = CryptoPrivateStateReceive_1 = __decorate([
|
|
89
|
-
(0, ts_serval_1.type)("CryptoPrivateStateReceive")
|
|
90
|
-
__metadata("design:paramtypes", [CoreBuffer_1.CoreBuffer, Number, CoreBuffer_1.CoreBuffer, Number, String])
|
|
78
|
+
(0, ts_serval_1.type)("CryptoPrivateStateReceive")
|
|
91
79
|
], CryptoPrivateStateReceive);
|
|
92
80
|
exports.CryptoPrivateStateReceive = CryptoPrivateStateReceive;
|
|
93
81
|
//# sourceMappingURL=CryptoPrivateStateReceive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoPrivateStateReceive.js","sourceRoot":"","sources":["../../src/state/CryptoPrivateStateReceive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CryptoPrivateStateReceive.js","sourceRoot":"","sources":["../../src/state/CryptoPrivateStateReceive.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,kDAA0C;AAE1C,gDAA6C;AAC7C,wDAAqD;AACrD,0DAAuD;AAEvD,qEAA6F;AAC7F,6DAA8G;AAE9G,uDAAoD;AAGpD,IAAa,yBAAyB,iCAAtC,MAAa,yBAA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,11 @@ import { CryptoCipher } from "../encryption/CryptoCipher";
|
|
|
3
3
|
import { CryptoEncryptionAlgorithm } from "../encryption/CryptoEncryption";
|
|
4
4
|
import { CryptoPrivateState, ICryptoPrivateState, ICryptoPrivateStateSerialized } from "./CryptoPrivateState";
|
|
5
5
|
export declare class CryptoPrivateStateTransmit extends CryptoPrivateState {
|
|
6
|
-
constructor(nonce: CoreBuffer, counter: number, secretKey: CoreBuffer, algorithm?: CryptoEncryptionAlgorithm, id?: string);
|
|
7
6
|
toJSON(): ICryptoPrivateStateSerialized;
|
|
8
7
|
encrypt(plaintext: CoreBuffer): Promise<CryptoCipher>;
|
|
9
8
|
decrypt(cipher: CryptoCipher): Promise<CoreBuffer>;
|
|
10
9
|
static generate(secretKey?: CoreBuffer, id?: string, algorithm?: CryptoEncryptionAlgorithm): CryptoPrivateStateTransmit;
|
|
11
10
|
static from(obj: CryptoPrivateState | ICryptoPrivateState): CryptoPrivateStateTransmit;
|
|
11
|
+
protected static preFrom(value: any): any;
|
|
12
12
|
static fromJSON(value: ICryptoPrivateStateSerialized): CryptoPrivateStateTransmit;
|
|
13
|
-
static deserialize(value: string): CryptoPrivateStateTransmit;
|
|
14
13
|
}
|
|
@@ -5,24 +5,16 @@ 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 CryptoPrivateStateTransmit_1;
|
|
12
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
9
|
exports.CryptoPrivateStateTransmit = void 0;
|
|
14
10
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
15
|
-
const CoreBuffer_1 = require("../CoreBuffer");
|
|
16
11
|
const CryptoError_1 = require("../CryptoError");
|
|
17
12
|
const CryptoErrorCode_1 = require("../CryptoErrorCode");
|
|
18
13
|
const CryptoValidation_1 = require("../CryptoValidation");
|
|
19
14
|
const CryptoEncryption_1 = require("../encryption/CryptoEncryption");
|
|
20
15
|
const CryptoPrivateState_1 = require("./CryptoPrivateState");
|
|
21
16
|
const CryptoStateType_1 = require("./CryptoStateType");
|
|
22
|
-
let CryptoPrivateStateTransmit =
|
|
23
|
-
constructor(nonce, counter, secretKey, algorithm = 3 /* XCHACHA20_POLY1305 */, id) {
|
|
24
|
-
super(nonce, counter, secretKey, algorithm, CryptoStateType_1.CryptoStateType.Transmit, id);
|
|
25
|
-
}
|
|
17
|
+
let CryptoPrivateStateTransmit = class CryptoPrivateStateTransmit extends CryptoPrivateState_1.CryptoPrivateState {
|
|
26
18
|
toJSON() {
|
|
27
19
|
const obj = super.toJSON();
|
|
28
20
|
obj["@type"] = "CryptoPrivateStateTransmit";
|
|
@@ -48,44 +40,26 @@ let CryptoPrivateStateTransmit = CryptoPrivateStateTransmit_1 = class CryptoPriv
|
|
|
48
40
|
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongCounter);
|
|
49
41
|
const nonce = CryptoEncryption_1.CryptoEncryption.createNonce(algorithm);
|
|
50
42
|
const counter = 0;
|
|
51
|
-
return
|
|
43
|
+
return this.from({ nonce, counter, secretKey, algorithm, id, stateType: CryptoStateType_1.CryptoStateType.Transmit });
|
|
52
44
|
}
|
|
53
45
|
static from(obj) {
|
|
54
|
-
|
|
55
|
-
if (!obj.secretKey) {
|
|
56
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongSecretKey, "No secretKey property set.");
|
|
57
|
-
}
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
59
|
-
if (!obj.nonce) {
|
|
60
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongNonce, "No nonce nor counter property set.");
|
|
61
|
-
}
|
|
62
|
-
if (typeof obj.counter === "undefined") {
|
|
63
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongCounter, "Wrong counter.");
|
|
64
|
-
}
|
|
65
|
-
if (obj.stateType !== CryptoStateType_1.CryptoStateType.Transmit) {
|
|
66
|
-
throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.StateWrongType, "The given object has a wrong state type.");
|
|
67
|
-
}
|
|
68
|
-
return new CryptoPrivateStateTransmit_1(CoreBuffer_1.CoreBuffer.from(obj.nonce), obj.counter, CoreBuffer_1.CoreBuffer.from(obj.secretKey), obj.algorithm, obj.id);
|
|
46
|
+
return this.fromAny(obj);
|
|
69
47
|
}
|
|
70
|
-
static
|
|
71
|
-
|
|
72
|
-
CryptoValidation_1.CryptoValidation.
|
|
73
|
-
CryptoValidation_1.CryptoValidation.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
CryptoValidation_1.CryptoValidation.checkStateType(value.typ);
|
|
48
|
+
static preFrom(value) {
|
|
49
|
+
value = super.preFrom(value);
|
|
50
|
+
CryptoValidation_1.CryptoValidation.checkBufferAsStringOrBuffer(value.nonce, 0, 24, "nonce");
|
|
51
|
+
CryptoValidation_1.CryptoValidation.checkSecretKeyForAlgorithm(value.secretKey, value.algorithm);
|
|
52
|
+
if (value.stateType) {
|
|
53
|
+
CryptoValidation_1.CryptoValidation.checkStateType(value.stateType);
|
|
77
54
|
}
|
|
78
|
-
|
|
79
|
-
const secretKeyBuffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.key);
|
|
80
|
-
return new CryptoPrivateStateTransmit_1(nonceBuffer, value.cnt, secretKeyBuffer, value.alg, value.id);
|
|
55
|
+
return value;
|
|
81
56
|
}
|
|
82
|
-
static
|
|
83
|
-
return this.
|
|
57
|
+
static fromJSON(value) {
|
|
58
|
+
return this.fromAny(value);
|
|
84
59
|
}
|
|
85
60
|
};
|
|
86
|
-
CryptoPrivateStateTransmit =
|
|
87
|
-
(0, ts_serval_1.type)("CryptoPrivateStateTransmit")
|
|
88
|
-
__metadata("design:paramtypes", [CoreBuffer_1.CoreBuffer, Number, CoreBuffer_1.CoreBuffer, Number, String])
|
|
61
|
+
CryptoPrivateStateTransmit = __decorate([
|
|
62
|
+
(0, ts_serval_1.type)("CryptoPrivateStateTransmit")
|
|
89
63
|
], CryptoPrivateStateTransmit);
|
|
90
64
|
exports.CryptoPrivateStateTransmit = CryptoPrivateStateTransmit;
|
|
91
65
|
//# sourceMappingURL=CryptoPrivateStateTransmit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoPrivateStateTransmit.js","sourceRoot":"","sources":["../../src/state/CryptoPrivateStateTransmit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CryptoPrivateStateTransmit.js","sourceRoot":"","sources":["../../src/state/CryptoPrivateStateTransmit.ts"],"names":[],"mappings":";;;;;;;;;AAAA,kDAA0C;AAE1C,gDAA6C;AAC7C,wDAAqD;AACrD,0DAAuD;AAEvD,qEAA6F;AAC7F,6DAA8G;AAC9G,uDAAoD;AAGpD,IAAa,0BAA0B,GAAvC,MAAa,0BAA2B,SAAQ,uCAAkB;IAC9C,MAAM;QAClB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC3B,GAAG,CAAC,OAAO,CAAC,GAAG,4BAA4B,CAAC;QAC5C,OAAO,GAAG,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,SAAqB;QACtC,MAAM,MAAM,GAAG,MAAM,mCAAgB,CAAC,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9G,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO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AAO,CAAC,KAAK,CAAC,CAAC;QAE7B,mCAAgB,CAAC,2BAA2B,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAC1E,mCAAgB,CAAC,0BAA0B,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;QAE9E,IAAI,KAAK,CAAC,SAAS,EAAE;YACjB,mCAAgB,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;SACpD;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAU,QAAQ,CAAC,KAAoC;QAChE,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACJ,CAAA;AA3DY,0BAA0B;IADtC,IAAA,gBAAI,EAAC,4BAA4B,CAAC;GACtB,0BAA0B,CA2DtC;AA3DY,gEAA0B"}
|
|
@@ -15,19 +15,14 @@ export interface ICryptoPublicState extends ISerializable {
|
|
|
15
15
|
stateType: CryptoStateType;
|
|
16
16
|
}
|
|
17
17
|
export declare class CryptoPublicState extends Serializable implements ICryptoPublicState, IClearable {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private readonly _algorithm;
|
|
23
|
-
get algorithm(): CryptoEncryptionAlgorithm;
|
|
24
|
-
private readonly _stateType;
|
|
25
|
-
get stateType(): CryptoStateType;
|
|
26
|
-
constructor(nonce: CoreBuffer, algorithm: CryptoEncryptionAlgorithm, stateType: CryptoStateType, id?: string);
|
|
18
|
+
id?: string;
|
|
19
|
+
nonce: CoreBuffer;
|
|
20
|
+
algorithm: CryptoEncryptionAlgorithm;
|
|
21
|
+
stateType: CryptoStateType;
|
|
27
22
|
clear(): void;
|
|
28
23
|
toJSON(verbose?: boolean): ICryptoPublicStateSerialized;
|
|
24
|
+
protected static preFrom(value: any): any;
|
|
29
25
|
static from(value: CryptoPublicState | ICryptoPublicState): CryptoPublicState;
|
|
30
26
|
static fromJSON(value: ICryptoPublicStateSerialized): CryptoPublicState;
|
|
31
27
|
static fromBase64(value: string): CryptoPublicState;
|
|
32
|
-
static deserialize(value: string): CryptoPublicState;
|
|
33
28
|
}
|
|
@@ -8,80 +8,71 @@ 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 CryptoPublicState_1;
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
exports.CryptoPublicState = void 0;
|
|
14
13
|
const ts_serval_1 = require("@js-soft/ts-serval");
|
|
15
14
|
const CoreBuffer_1 = require("../CoreBuffer");
|
|
16
15
|
const CryptoValidation_1 = require("../CryptoValidation");
|
|
17
16
|
const CryptoStateType_1 = require("./CryptoStateType");
|
|
18
|
-
let CryptoPublicState =
|
|
19
|
-
constructor(nonce, algorithm, stateType, id) {
|
|
20
|
-
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(algorithm);
|
|
21
|
-
CryptoValidation_1.CryptoValidation.checkNonceForAlgorithm(nonce, algorithm);
|
|
22
|
-
CryptoValidation_1.CryptoValidation.checkStateType(stateType);
|
|
23
|
-
super();
|
|
24
|
-
this._nonce = nonce;
|
|
25
|
-
this._algorithm = algorithm;
|
|
26
|
-
this._id = id;
|
|
27
|
-
this._stateType = stateType;
|
|
28
|
-
}
|
|
29
|
-
get id() {
|
|
30
|
-
return this._id;
|
|
31
|
-
}
|
|
32
|
-
get nonce() {
|
|
33
|
-
return this._nonce;
|
|
34
|
-
}
|
|
35
|
-
get algorithm() {
|
|
36
|
-
return this._algorithm;
|
|
37
|
-
}
|
|
38
|
-
get stateType() {
|
|
39
|
-
return this._stateType;
|
|
40
|
-
}
|
|
17
|
+
let CryptoPublicState = class CryptoPublicState extends ts_serval_1.Serializable {
|
|
41
18
|
clear() {
|
|
42
19
|
this.nonce.clear();
|
|
43
20
|
}
|
|
44
21
|
toJSON(verbose = true) {
|
|
45
|
-
|
|
22
|
+
return {
|
|
23
|
+
"@type": verbose ? "CryptoPublicState" : undefined,
|
|
46
24
|
nnc: this.nonce.toBase64URL(),
|
|
47
25
|
alg: this.algorithm,
|
|
48
|
-
typ: this.stateType
|
|
26
|
+
typ: this.stateType,
|
|
27
|
+
id: this.id
|
|
49
28
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
}
|
|
30
|
+
static preFrom(value) {
|
|
31
|
+
if (value.nnc) {
|
|
32
|
+
value = {
|
|
33
|
+
nonce: value.nnc,
|
|
34
|
+
algorithm: value.alg,
|
|
35
|
+
stateType: value.typ,
|
|
36
|
+
id: value.id
|
|
37
|
+
};
|
|
55
38
|
}
|
|
56
|
-
|
|
39
|
+
CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(value.algorithm);
|
|
40
|
+
CryptoValidation_1.CryptoValidation.checkStateType(value.stateType);
|
|
41
|
+
CryptoValidation_1.CryptoValidation.checkNonce(value.nonce, value.algorithm);
|
|
42
|
+
return value;
|
|
57
43
|
}
|
|
58
44
|
static from(value) {
|
|
59
|
-
return
|
|
45
|
+
return this.fromAny(value);
|
|
60
46
|
}
|
|
61
47
|
static fromJSON(value) {
|
|
62
|
-
|
|
63
|
-
error = CryptoValidation_1.CryptoValidation.checkEncryptionAlgorithm(value.alg);
|
|
64
|
-
if (error)
|
|
65
|
-
throw error;
|
|
66
|
-
error = CryptoValidation_1.CryptoValidation.checkStateType(value.typ);
|
|
67
|
-
if (error)
|
|
68
|
-
throw error;
|
|
69
|
-
error = CryptoValidation_1.CryptoValidation.checkNonceAsString(value.nnc, value.alg);
|
|
70
|
-
if (error)
|
|
71
|
-
throw error;
|
|
72
|
-
const buffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.nnc);
|
|
73
|
-
return new CryptoPublicState_1(buffer, value.alg, value.typ, value.id);
|
|
48
|
+
return this.fromAny(value);
|
|
74
49
|
}
|
|
75
50
|
static fromBase64(value) {
|
|
76
51
|
return this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
|
|
77
52
|
}
|
|
78
|
-
static deserialize(value) {
|
|
79
|
-
return this.fromJSON(JSON.parse(value));
|
|
80
|
-
}
|
|
81
53
|
};
|
|
82
|
-
|
|
83
|
-
(0, ts_serval_1.
|
|
84
|
-
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, ts_serval_1.validate)({ nullable: true }),
|
|
56
|
+
(0, ts_serval_1.serialize)(),
|
|
57
|
+
__metadata("design:type", String)
|
|
58
|
+
], CryptoPublicState.prototype, "id", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, ts_serval_1.validate)(),
|
|
61
|
+
(0, ts_serval_1.serialize)(),
|
|
62
|
+
__metadata("design:type", CoreBuffer_1.CoreBuffer)
|
|
63
|
+
], CryptoPublicState.prototype, "nonce", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, ts_serval_1.validate)(),
|
|
66
|
+
(0, ts_serval_1.serialize)(),
|
|
67
|
+
__metadata("design:type", Number)
|
|
68
|
+
], CryptoPublicState.prototype, "algorithm", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, ts_serval_1.validate)(),
|
|
71
|
+
(0, ts_serval_1.serialize)(),
|
|
72
|
+
__metadata("design:type", Number)
|
|
73
|
+
], CryptoPublicState.prototype, "stateType", void 0);
|
|
74
|
+
CryptoPublicState = __decorate([
|
|
75
|
+
(0, ts_serval_1.type)("CryptoPublicState")
|
|
85
76
|
], CryptoPublicState);
|
|
86
77
|
exports.CryptoPublicState = CryptoPublicState;
|
|
87
78
|
//# sourceMappingURL=CryptoPublicState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoPublicState.js","sourceRoot":"","sources":["../../src/state/CryptoPublicState.ts"],"names":[],"mappings":"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