@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.
Files changed (113) hide show
  1. package/dist/CoreBuffer.d.ts +0 -1
  2. package/dist/CoreBuffer.js +1 -4
  3. package/dist/CoreBuffer.js.map +1 -1
  4. package/dist/CryptoDerivation.js +2 -2
  5. package/dist/CryptoDerivation.js.map +1 -1
  6. package/dist/CryptoPrivateKey.d.ts +14 -17
  7. package/dist/CryptoPrivateKey.js +24 -39
  8. package/dist/CryptoPrivateKey.js.map +1 -1
  9. package/dist/CryptoPublicKey.d.ts +13 -16
  10. package/dist/CryptoPublicKey.js +22 -37
  11. package/dist/CryptoPublicKey.js.map +1 -1
  12. package/dist/CryptoSerializable.d.ts +5 -0
  13. package/dist/CryptoSerializable.js +15 -0
  14. package/dist/CryptoSerializable.js.map +1 -0
  15. package/dist/CryptoValidation.d.ts +4 -6
  16. package/dist/CryptoValidation.js +16 -29
  17. package/dist/CryptoValidation.js.map +1 -1
  18. package/dist/SodiumWrapper.js +5 -1
  19. package/dist/SodiumWrapper.js.map +1 -1
  20. package/dist/buildInformation.js +5 -5
  21. package/dist/encryption/CryptoCipher.d.ts +10 -11
  22. package/dist/encryption/CryptoCipher.js +62 -59
  23. package/dist/encryption/CryptoCipher.js.map +1 -1
  24. package/dist/encryption/CryptoEncryption.js +10 -12
  25. package/dist/encryption/CryptoEncryption.js.map +1 -1
  26. package/dist/encryption/CryptoSecretKey.d.ts +8 -9
  27. package/dist/encryption/CryptoSecretKey.js +36 -32
  28. package/dist/encryption/CryptoSecretKey.js.map +1 -1
  29. package/dist/exchange/CryptoExchange.d.ts +0 -2
  30. package/dist/exchange/CryptoExchange.js +5 -22
  31. package/dist/exchange/CryptoExchange.js.map +1 -1
  32. package/dist/exchange/CryptoExchangeKeypair.d.ts +10 -11
  33. package/dist/exchange/CryptoExchangeKeypair.js +33 -30
  34. package/dist/exchange/CryptoExchangeKeypair.js.map +1 -1
  35. package/dist/exchange/CryptoExchangePrivateKey.d.ts +8 -10
  36. package/dist/exchange/CryptoExchangePrivateKey.js +50 -31
  37. package/dist/exchange/CryptoExchangePrivateKey.js.map +1 -1
  38. package/dist/exchange/CryptoExchangePublicKey.d.ts +6 -7
  39. package/dist/exchange/CryptoExchangePublicKey.js +31 -32
  40. package/dist/exchange/CryptoExchangePublicKey.js.map +1 -1
  41. package/dist/exchange/CryptoExchangeSecrets.d.ts +10 -11
  42. package/dist/exchange/CryptoExchangeSecrets.js +33 -35
  43. package/dist/exchange/CryptoExchangeSecrets.js.map +1 -1
  44. package/dist/exchange/CryptoExchangeValidation.d.ts +7 -10
  45. package/dist/exchange/CryptoExchangeValidation.js +9 -36
  46. package/dist/exchange/CryptoExchangeValidation.js.map +1 -1
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +6 -1
  49. package/dist/index.js.map +1 -1
  50. package/dist/relationship/CryptoRelationshipPublicRequest.d.ts +8 -9
  51. package/dist/relationship/CryptoRelationshipPublicRequest.js +23 -42
  52. package/dist/relationship/CryptoRelationshipPublicRequest.js.map +1 -1
  53. package/dist/relationship/CryptoRelationshipPublicResponse.d.ts +8 -9
  54. package/dist/relationship/CryptoRelationshipPublicResponse.js +24 -38
  55. package/dist/relationship/CryptoRelationshipPublicResponse.js.map +1 -1
  56. package/dist/relationship/CryptoRelationshipRequestSecrets.d.ts +6 -7
  57. package/dist/relationship/CryptoRelationshipRequestSecrets.js +7 -10
  58. package/dist/relationship/CryptoRelationshipRequestSecrets.js.map +1 -1
  59. package/dist/relationship/CryptoRelationshipSecrets.d.ts +6 -7
  60. package/dist/relationship/CryptoRelationshipSecrets.js +8 -11
  61. package/dist/relationship/CryptoRelationshipSecrets.js.map +1 -1
  62. package/dist/signature/CryptoSignature.d.ts +12 -13
  63. package/dist/signature/CryptoSignature.js +39 -35
  64. package/dist/signature/CryptoSignature.js.map +1 -1
  65. package/dist/signature/CryptoSignatureAlgorithm.d.ts +5 -0
  66. package/dist/signature/CryptoSignatureAlgorithm.js +3 -0
  67. package/dist/signature/CryptoSignatureAlgorithm.js.map +1 -0
  68. package/dist/signature/CryptoSignatureKeypair.d.ts +10 -11
  69. package/dist/signature/CryptoSignatureKeypair.js +36 -38
  70. package/dist/signature/CryptoSignatureKeypair.js.map +1 -1
  71. package/dist/signature/CryptoSignaturePrivateKey.d.ts +10 -13
  72. package/dist/signature/CryptoSignaturePrivateKey.js +28 -37
  73. package/dist/signature/CryptoSignaturePrivateKey.js.map +1 -1
  74. package/dist/signature/CryptoSignaturePublicKey.d.ts +9 -12
  75. package/dist/signature/CryptoSignaturePublicKey.js +22 -44
  76. package/dist/signature/CryptoSignaturePublicKey.js.map +1 -1
  77. package/dist/signature/CryptoSignatureValidation.d.ts +10 -12
  78. package/dist/signature/CryptoSignatureValidation.js +13 -35
  79. package/dist/signature/CryptoSignatureValidation.js.map +1 -1
  80. package/dist/signature/CryptoSignatures.d.ts +1 -5
  81. package/dist/signature/CryptoSignatures.js +5 -5
  82. package/dist/signature/CryptoSignatures.js.map +1 -1
  83. package/dist/state/CryptoPrivateState.d.ts +12 -20
  84. package/dist/state/CryptoPrivateState.js +73 -77
  85. package/dist/state/CryptoPrivateState.js.map +1 -1
  86. package/dist/state/CryptoPrivateStateReceive.d.ts +4 -6
  87. package/dist/state/CryptoPrivateStateReceive.js +27 -39
  88. package/dist/state/CryptoPrivateStateReceive.js.map +1 -1
  89. package/dist/state/CryptoPrivateStateTransmit.d.ts +3 -4
  90. package/dist/state/CryptoPrivateStateTransmit.js +14 -40
  91. package/dist/state/CryptoPrivateStateTransmit.js.map +1 -1
  92. package/dist/state/CryptoPublicState.d.ts +11 -16
  93. package/dist/state/CryptoPublicState.js +44 -53
  94. package/dist/state/CryptoPublicState.js.map +1 -1
  95. package/dist/stream/CryptoStream.js +5 -2
  96. package/dist/stream/CryptoStream.js.map +1 -1
  97. package/dist/stream/CryptoStreamAddress.d.ts +7 -10
  98. package/dist/stream/CryptoStreamAddress.js +13 -29
  99. package/dist/stream/CryptoStreamAddress.js.map +1 -1
  100. package/dist/stream/CryptoStreamHeader.d.ts +9 -12
  101. package/dist/stream/CryptoStreamHeader.js +15 -18
  102. package/dist/stream/CryptoStreamHeader.js.map +1 -1
  103. package/dist/stream/CryptoStreamState.d.ts +6 -10
  104. package/dist/stream/CryptoStreamState.js +15 -33
  105. package/dist/stream/CryptoStreamState.js.map +1 -1
  106. package/lib-web/nmshd.crypto.js +795 -1023
  107. package/lib-web/nmshd.crypto.js.map +1 -1
  108. package/lib-web/nmshd.crypto.min.js +1 -1
  109. package/lib-web/nmshd.crypto.min.js.map +1 -1
  110. package/package.json +18 -18
  111. package/dist/CryptoSerializableAsync.d.ts +0 -5
  112. package/dist/CryptoSerializableAsync.js +0 -24
  113. package/dist/CryptoSerializableAsync.js.map +0 -1
@@ -8,22 +8,16 @@ 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 CryptoExchangeKeypair_1;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.CryptoExchangeKeypair = void 0;
14
13
  const ts_serval_1 = require("@js-soft/ts-serval");
15
14
  const CoreBuffer_1 = require("../CoreBuffer");
16
- const CryptoSerializableAsync_1 = require("../CryptoSerializableAsync");
15
+ const CryptoError_1 = require("../CryptoError");
16
+ const CryptoErrorCode_1 = require("../CryptoErrorCode");
17
+ const CryptoSerializable_1 = require("../CryptoSerializable");
17
18
  const CryptoExchangePrivateKey_1 = require("./CryptoExchangePrivateKey");
18
19
  const CryptoExchangePublicKey_1 = require("./CryptoExchangePublicKey");
19
- const CryptoExchangeValidation_1 = require("./CryptoExchangeValidation");
20
- let CryptoExchangeKeypair = CryptoExchangeKeypair_1 = class CryptoExchangeKeypair extends CryptoSerializableAsync_1.CryptoSerializableAsync {
21
- constructor(publicKey, privateKey) {
22
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangeKeypair(privateKey, publicKey);
23
- super();
24
- this.publicKey = publicKey;
25
- this.privateKey = privateKey;
26
- }
20
+ let CryptoExchangeKeypair = class CryptoExchangeKeypair extends CryptoSerializable_1.CryptoSerializable {
27
21
  toJSON(verbose = true) {
28
22
  const obj = {
29
23
  pub: this.publicKey.toJSON(false),
@@ -38,31 +32,40 @@ let CryptoExchangeKeypair = CryptoExchangeKeypair_1 = class CryptoExchangeKeypai
38
32
  this.publicKey.clear();
39
33
  this.privateKey.clear();
40
34
  }
41
- static async from(value) {
42
- const [privateKey, publicKey] = await Promise.all([
43
- CryptoExchangePrivateKey_1.CryptoExchangePrivateKey.from(value.privateKey),
44
- CryptoExchangePublicKey_1.CryptoExchangePublicKey.from(value.publicKey)
45
- ]);
46
- return new CryptoExchangeKeypair_1(publicKey, privateKey);
35
+ static preFrom(value) {
36
+ if (value.pub) {
37
+ value = {
38
+ publicKey: value.pub,
39
+ privateKey: value.prv
40
+ };
41
+ }
42
+ if (value.privateKey.algorithm !== value.publicKey.algorithm) {
43
+ throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.ExchangeWrongAlgorithm, "Algorithms of private and public key do not match.");
44
+ }
45
+ return value;
47
46
  }
48
- static async fromJSON(value) {
49
- const [privateKey, publicKey] = await Promise.all([
50
- CryptoExchangePrivateKey_1.CryptoExchangePrivateKey.fromJSON(value.prv),
51
- CryptoExchangePublicKey_1.CryptoExchangePublicKey.fromJSON(value.pub)
52
- ]);
53
- return new CryptoExchangeKeypair_1(publicKey, privateKey);
47
+ static from(value) {
48
+ return this.fromAny(value);
54
49
  }
55
- static async fromBase64(value) {
56
- return await this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
50
+ static fromJSON(value) {
51
+ return this.fromAny(value);
57
52
  }
58
- static async deserialize(value) {
59
- const obj = JSON.parse(value);
60
- return await this.fromJSON(obj);
53
+ static fromBase64(value) {
54
+ return this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
61
55
  }
62
56
  };
63
- CryptoExchangeKeypair = CryptoExchangeKeypair_1 = __decorate([
64
- (0, ts_serval_1.type)("CryptoExchangeKeypair"),
65
- __metadata("design:paramtypes", [CryptoExchangePublicKey_1.CryptoExchangePublicKey, CryptoExchangePrivateKey_1.CryptoExchangePrivateKey])
57
+ __decorate([
58
+ (0, ts_serval_1.validate)(),
59
+ (0, ts_serval_1.serialize)(),
60
+ __metadata("design:type", CryptoExchangePublicKey_1.CryptoExchangePublicKey)
61
+ ], CryptoExchangeKeypair.prototype, "publicKey", void 0);
62
+ __decorate([
63
+ (0, ts_serval_1.validate)(),
64
+ (0, ts_serval_1.serialize)(),
65
+ __metadata("design:type", CryptoExchangePrivateKey_1.CryptoExchangePrivateKey)
66
+ ], CryptoExchangeKeypair.prototype, "privateKey", void 0);
67
+ CryptoExchangeKeypair = __decorate([
68
+ (0, ts_serval_1.type)("CryptoExchangeKeypair")
66
69
  ], CryptoExchangeKeypair);
67
70
  exports.CryptoExchangeKeypair = CryptoExchangeKeypair;
68
71
  //# sourceMappingURL=CryptoExchangeKeypair.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoExchangeKeypair.js","sourceRoot":"","sources":["../../src/exchange/CryptoExchangeKeypair.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kDAA2E;AAC3E,8CAAuD;AACvD,wEAAqE;AACrE,yEAIoC;AACpC,uEAImC;AACnC,yEAAsE;AAatE,IAAa,qBAAqB,6BAAlC,MAAa,qBAAsB,SAAQ,iDAAuB;IAI9D,YAAmB,SAAkC,EAAE,UAAoC;QACvF,mDAAwB,CAAC,oBAAoB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAErE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,OAAO,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QAED,IAAI,KAAK,CAAC,UAAU,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE;YAC1D,MAAM,IAAI,yBAAW,CACjB,iCAAe,CAAC,sBAAsB,EACtC,oDAAoD,CACvD,CAAC;SACL;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAC,KAAqD;QACpE,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAAuC;QAC1D,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;AApDG;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACM,iDAAuB;wDAAC;AAI1C;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACO,mDAAwB;yDAAC;AAPnC,qBAAqB;IADjC,IAAA,gBAAI,EAAC,uBAAuB,CAAC;GACjB,qBAAqB,CAuDjC;AAvDY,sDAAqB"}
@@ -1,4 +1,4 @@
1
- import { ISerializableAsync, ISerialized } from "@js-soft/ts-serval";
1
+ import { ISerializable, ISerialized } from "@js-soft/ts-serval";
2
2
  import { CoreBuffer, IClearable, ICoreBuffer } from "../CoreBuffer";
3
3
  import { CryptoPrivateKey } from "../CryptoPrivateKey";
4
4
  import { CryptoExchangeAlgorithm } from "./CryptoExchange";
@@ -7,21 +7,19 @@ export interface ICryptoExchangePrivateKeySerialized extends ISerialized {
7
7
  alg: number;
8
8
  prv: string;
9
9
  }
10
- export interface ICryptoExchangePrivateKey extends ISerializableAsync {
10
+ export interface ICryptoExchangePrivateKey extends ISerializable {
11
11
  algorithm: CryptoExchangeAlgorithm;
12
12
  privateKey: ICoreBuffer;
13
13
  }
14
14
  export declare class CryptoExchangePrivateKey extends CryptoPrivateKey implements ICryptoExchangePrivateKey, IClearable {
15
- readonly algorithm: CryptoExchangeAlgorithm;
16
- readonly privateKey: CoreBuffer;
17
- constructor(algorithm: CryptoExchangeAlgorithm, privateKey: CoreBuffer);
15
+ algorithm: CryptoExchangeAlgorithm;
16
+ privateKey: CoreBuffer;
18
17
  toJSON(verbose?: boolean): ICryptoExchangePrivateKeySerialized;
19
18
  clear(): void;
20
- serialize(verbose?: boolean): string;
21
19
  toBase64(verbose?: boolean): string;
22
20
  toPublicKey(): Promise<CryptoExchangePublicKey>;
23
- static from(value: CryptoExchangePrivateKey | ICryptoExchangePrivateKey): Promise<CryptoExchangePrivateKey>;
24
- static fromJSON(value: ICryptoExchangePrivateKeySerialized): Promise<CryptoExchangePrivateKey>;
25
- static fromBase64(value: string): Promise<CryptoExchangePrivateKey>;
26
- static deserialize(value: string): Promise<CryptoExchangePrivateKey>;
21
+ static from(value: CryptoExchangePrivateKey | ICryptoExchangePrivateKey): CryptoExchangePrivateKey;
22
+ protected static preFrom(value: any): any;
23
+ static fromJSON(value: ICryptoExchangePrivateKeySerialized): CryptoExchangePrivateKey;
24
+ static fromBase64(value: string): CryptoExchangePrivateKey;
27
25
  }
@@ -8,63 +8,82 @@ 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 CryptoExchangePrivateKey_1;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.CryptoExchangePrivateKey = void 0;
14
13
  const ts_serval_1 = require("@js-soft/ts-serval");
15
14
  const CoreBuffer_1 = require("../CoreBuffer");
15
+ const CryptoError_1 = require("../CryptoError");
16
+ const CryptoErrorCode_1 = require("../CryptoErrorCode");
16
17
  const CryptoPrivateKey_1 = require("../CryptoPrivateKey");
17
- const CryptoExchange_1 = require("./CryptoExchange");
18
+ const SodiumWrapper_1 = require("../SodiumWrapper");
19
+ const CryptoExchangePublicKey_1 = require("./CryptoExchangePublicKey");
18
20
  const CryptoExchangeValidation_1 = require("./CryptoExchangeValidation");
19
- let CryptoExchangePrivateKey = CryptoExchangePrivateKey_1 = class CryptoExchangePrivateKey extends CryptoPrivateKey_1.CryptoPrivateKey {
20
- constructor(algorithm, privateKey) {
21
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangeAlgorithm(algorithm);
22
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangePrivateKeyAsBuffer(privateKey, algorithm);
23
- super(algorithm, privateKey);
24
- this.algorithm = algorithm;
25
- this.privateKey = privateKey;
26
- }
21
+ let CryptoExchangePrivateKey = class CryptoExchangePrivateKey extends CryptoPrivateKey_1.CryptoPrivateKey {
27
22
  toJSON(verbose = true) {
28
- const obj = {
23
+ return {
29
24
  prv: this.privateKey.toBase64URL(),
30
- alg: this.algorithm
25
+ alg: this.algorithm,
26
+ "@type": verbose ? "CryptoExchangePrivateKey" : undefined
31
27
  };
32
- if (verbose) {
33
- obj["@type"] = "CryptoExchangePrivateKey";
34
- }
35
- return obj;
36
28
  }
37
29
  clear() {
38
30
  this.privateKey.clear();
39
31
  }
40
- serialize(verbose = true) {
41
- return JSON.stringify(this.toJSON(verbose));
42
- }
43
32
  toBase64(verbose = true) {
44
33
  return CoreBuffer_1.CoreBuffer.utf8_base64(this.serialize(verbose));
45
34
  }
46
35
  async toPublicKey() {
47
- return await CryptoExchange_1.CryptoExchange.privateKeyToPublicKey(this);
36
+ let publicKey;
37
+ switch (this.algorithm) {
38
+ case 3 /* ECDH_X25519 */:
39
+ try {
40
+ publicKey = (await SodiumWrapper_1.SodiumWrapper.ready()).crypto_scalarmult_base(this.privateKey.buffer);
41
+ }
42
+ catch (e) {
43
+ throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.ExchangeKeyGeneration, `${e}`);
44
+ }
45
+ break;
46
+ default:
47
+ throw new CryptoError_1.CryptoError(CryptoErrorCode_1.CryptoErrorCode.NotYetImplemented);
48
+ }
49
+ return CryptoExchangePublicKey_1.CryptoExchangePublicKey.from({
50
+ algorithm: this.algorithm,
51
+ publicKey: CoreBuffer_1.CoreBuffer.from(publicKey)
52
+ });
48
53
  }
49
54
  static from(value) {
50
- return Promise.resolve(new CryptoExchangePrivateKey_1(value.algorithm, CoreBuffer_1.CoreBuffer.from(value.privateKey)));
55
+ return this.fromAny(value);
56
+ }
57
+ static preFrom(value) {
58
+ if (value.alg) {
59
+ value = {
60
+ algorithm: value.alg,
61
+ privateKey: CoreBuffer_1.CoreBuffer.fromBase64URL(value.prv)
62
+ };
63
+ }
64
+ CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangeAlgorithm(value.algorithm);
65
+ CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangePrivateKey(value.privateKey, value.algorithm, "privateKey");
66
+ return value;
51
67
  }
52
68
  static fromJSON(value) {
53
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangeAlgorithm(value.alg);
54
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangePrivateKeyAsNumber(value.prv, value.alg, "privateKey");
55
- const buffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.prv);
56
- return Promise.resolve(new CryptoExchangePrivateKey_1(value.alg, buffer));
69
+ return this.fromAny(value);
57
70
  }
58
71
  static fromBase64(value) {
59
72
  return this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
60
73
  }
61
- static async deserialize(value) {
62
- return await this.fromJSON(JSON.parse(value));
63
- }
64
74
  };
65
- CryptoExchangePrivateKey = CryptoExchangePrivateKey_1 = __decorate([
66
- (0, ts_serval_1.type)("CryptoExchangePrivateKey"),
67
- __metadata("design:paramtypes", [Number, CoreBuffer_1.CoreBuffer])
75
+ __decorate([
76
+ (0, ts_serval_1.validate)(),
77
+ (0, ts_serval_1.serialize)(),
78
+ __metadata("design:type", Number)
79
+ ], CryptoExchangePrivateKey.prototype, "algorithm", void 0);
80
+ __decorate([
81
+ (0, ts_serval_1.validate)(),
82
+ (0, ts_serval_1.serialize)(),
83
+ __metadata("design:type", CoreBuffer_1.CoreBuffer)
84
+ ], CryptoExchangePrivateKey.prototype, "privateKey", void 0);
85
+ CryptoExchangePrivateKey = __decorate([
86
+ (0, ts_serval_1.type)("CryptoExchangePrivateKey")
68
87
  ], CryptoExchangePrivateKey);
69
88
  exports.CryptoExchangePrivateKey = CryptoExchangePrivateKey;
70
89
  //# sourceMappingURL=CryptoExchangePrivateKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoExchangePrivateKey.js","sourceRoot":"","sources":["../../src/exchange/CryptoExchangePrivateKey.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kDAA2E;AAC3E,8CAAoE;AACpE,0DAAuD;AACvD,qDAA2E;AAE3E,yEAAsE;AAatE,IAAa,wBAAwB,gCAArC,MAAa,wBAAyB,SAAQ,mCAAgB;IAI1D,YAAmB,SAAkC,EAAE,UAAsB;QACzE,mDAAwB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAC3D,mDAAwB,CAAC,+BAA+B,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAEhF,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAE7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,OAAO,GAAG,IAAI;QACxB,MAAM,GAAG,GAAwC;YAC7C,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE;YAClC,GAAG,EAAE,IAAI,CAAC,SAAS;SACtB,CAAC;QACF,IAAI,OAAO,EAAE;YACT,GAAG,CAAC,OAAO,CAAC,GAAG,0BAA0B,CAAC;SAC7C;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAE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U;4DAAC;AAP9B,wBAAwB;IADpC,IAAA,gBAAI,EAAC,0BAA0B,CAAC;GACpB,wBAAwB,CAsEpC;AAtEY,4DAAwB"}
@@ -11,13 +11,12 @@ export interface ICryptoExchangePublicKey {
11
11
  publicKey: CoreBuffer;
12
12
  }
13
13
  export declare class CryptoExchangePublicKey extends CryptoPublicKey implements ICryptoExchangePublicKey, IClearable {
14
- readonly algorithm: CryptoExchangeAlgorithm;
15
- readonly publicKey: CoreBuffer;
16
- constructor(algorithm: CryptoExchangeAlgorithm, publicKey: CoreBuffer);
14
+ algorithm: CryptoExchangeAlgorithm;
15
+ publicKey: CoreBuffer;
17
16
  toJSON(verbose?: boolean): ICryptoExchangePublicKeySerialized;
18
17
  clear(): void;
19
- static from(value: CryptoExchangePublicKey | ICryptoExchangePublicKey): Promise<CryptoExchangePublicKey>;
20
- static fromJSON(value: ICryptoExchangePublicKeySerialized): Promise<CryptoExchangePublicKey>;
21
- static fromBase64(value: string): Promise<CryptoExchangePublicKey>;
22
- static deserialize(value: string): Promise<CryptoExchangePublicKey>;
18
+ protected static preFrom(value: any): any;
19
+ static from(value: CryptoExchangePublicKey | ICryptoExchangePublicKey): CryptoExchangePublicKey;
20
+ static fromJSON(value: ICryptoExchangePublicKeySerialized): CryptoExchangePublicKey;
21
+ static fromBase64(value: string): CryptoExchangePublicKey;
23
22
  }
@@ -8,57 +8,56 @@ 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 CryptoExchangePublicKey_1;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.CryptoExchangePublicKey = void 0;
14
13
  const ts_serval_1 = require("@js-soft/ts-serval");
15
14
  const CoreBuffer_1 = require("../CoreBuffer");
16
15
  const CryptoPublicKey_1 = require("../CryptoPublicKey");
17
16
  const CryptoExchangeValidation_1 = require("./CryptoExchangeValidation");
18
- let CryptoExchangePublicKey = CryptoExchangePublicKey_1 = class CryptoExchangePublicKey extends CryptoPublicKey_1.CryptoPublicKey {
19
- constructor(algorithm, publicKey) {
20
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangeAlgorithm(algorithm);
21
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangePublicKeyAsBuffer(publicKey, algorithm);
22
- super(algorithm, publicKey);
23
- this.algorithm = algorithm;
24
- this.publicKey = publicKey;
25
- }
17
+ let CryptoExchangePublicKey = class CryptoExchangePublicKey extends CryptoPublicKey_1.CryptoPublicKey {
26
18
  toJSON(verbose = true) {
27
- const obj = {
19
+ return {
20
+ "@type": verbose ? "CryptoExchangePublicKey" : undefined,
28
21
  pub: this.publicKey.toBase64URL(),
29
22
  alg: this.algorithm
30
23
  };
31
- if (verbose) {
32
- obj["@type"] = "CryptoExchangePublicKey";
33
- }
34
- return obj;
35
24
  }
36
25
  clear() {
37
26
  this.publicKey.clear();
38
27
  }
39
- static from(value) {
40
- return Promise.resolve(new CryptoExchangePublicKey_1(value.algorithm, value.publicKey));
28
+ static preFrom(value) {
29
+ if (value.alg) {
30
+ value = {
31
+ algorithm: value.alg,
32
+ publicKey: value.pub
33
+ };
34
+ }
35
+ CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangeAlgorithm(value.algorithm);
36
+ CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangePublicKey(value.publicKey, value.algorithm);
37
+ return value;
41
38
  }
42
- static async fromJSON(value) {
43
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangeAlgorithm(value.alg);
44
- CryptoExchangeValidation_1.CryptoExchangeValidation.checkExchangePrivateKeyAsNumber(value.pub, value.alg, "publicKey");
45
- const buffer = CoreBuffer_1.CoreBuffer.fromBase64URL(value.pub);
46
- return await this.from({
47
- algorithm: value.alg,
48
- publicKey: buffer
49
- });
39
+ static from(value) {
40
+ return this.fromAny(value);
50
41
  }
51
- static async fromBase64(value) {
52
- return await this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
42
+ static fromJSON(value) {
43
+ return this.fromAny(value);
53
44
  }
54
- static async deserialize(value) {
55
- const obj = JSON.parse(value);
56
- return await this.fromJSON(obj);
45
+ static fromBase64(value) {
46
+ return this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value));
57
47
  }
58
48
  };
59
- CryptoExchangePublicKey = CryptoExchangePublicKey_1 = __decorate([
60
- (0, ts_serval_1.type)("CryptoExchangePublicKey"),
61
- __metadata("design:paramtypes", [Number, CoreBuffer_1.CoreBuffer])
49
+ __decorate([
50
+ (0, ts_serval_1.validate)(),
51
+ (0, ts_serval_1.serialize)(),
52
+ __metadata("design:type", Number)
53
+ ], CryptoExchangePublicKey.prototype, "algorithm", void 0);
54
+ __decorate([
55
+ (0, ts_serval_1.validate)(),
56
+ (0, ts_serval_1.serialize)(),
57
+ __metadata("design:type", CoreBuffer_1.CoreBuffer)
58
+ ], CryptoExchangePublicKey.prototype, "publicKey", void 0);
59
+ CryptoExchangePublicKey = __decorate([
60
+ (0, ts_serval_1.type)("CryptoExchangePublicKey")
62
61
  ], CryptoExchangePublicKey);
63
62
  exports.CryptoExchangePublicKey = CryptoExchangePublicKey;
64
63
  //# sourceMappingURL=CryptoExchangePublicKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoExchangePublicKey.js","sourceRoot":"","sources":["../../src/exchange/CryptoExchangePublicKey.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kDAAuD;AACvD,8CAAuD;AACvD,wDAAqD;AAErD,yEAAsE;AAatE,IAAa,uBAAuB,+BAApC,MAAa,uBAAwB,SAAQ,iCAAe;IAIxD,YAAmB,SAAkC,EAAE,SAAqB;QACxE,mDAAwB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAC3D,mDAAwB,CAAC,8BAA8B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9E,KAAK,CAAC,SAAS,EAAE,SA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jF,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAAyC;QAC5D,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;AA3CG;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;;0DACuC;AAInD;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACe,uBAAU;0DAAC;AAP7B,uBAAuB;IADnC,IAAA,gBAAI,EAAC,yBAAyB,CAAC;GACnB,uBAAuB,CA8CnC;AA9CY,0DAAuB"}
@@ -1,28 +1,27 @@
1
- import { ISerializableAsync, ISerialized } from "@js-soft/ts-serval";
1
+ import { ISerializable, ISerialized } from "@js-soft/ts-serval";
2
2
  import { CoreBuffer, IClearable, ICoreBuffer } from "../CoreBuffer";
3
- import { CryptoSerializableAsync } from "../CryptoSerializableAsync";
3
+ import { CryptoSerializable } from "../CryptoSerializable";
4
4
  import { CryptoEncryptionAlgorithm } from "../encryption/CryptoEncryption";
5
5
  export interface ICryptoExchangeSecretsSerialized extends ISerialized {
6
6
  alg: CryptoEncryptionAlgorithm;
7
7
  rx: string;
8
8
  tx: string;
9
9
  }
10
- export interface ICryptoExchangeSecrets extends ISerializableAsync {
10
+ export interface ICryptoExchangeSecrets extends ISerializable {
11
11
  algorithm: CryptoEncryptionAlgorithm;
12
12
  receivingKey: ICoreBuffer;
13
13
  transmissionKey: ICoreBuffer;
14
14
  }
15
- export declare class CryptoExchangeSecrets extends CryptoSerializableAsync implements ICryptoExchangeSecrets, IClearable {
16
- readonly algorithm: CryptoEncryptionAlgorithm;
17
- readonly receivingKey: CoreBuffer;
18
- readonly transmissionKey: CoreBuffer;
19
- constructor(receivingKey: CoreBuffer, transmissionKey: CoreBuffer, algorithm: CryptoEncryptionAlgorithm);
15
+ export declare class CryptoExchangeSecrets extends CryptoSerializable implements ICryptoExchangeSecrets, IClearable {
16
+ algorithm: CryptoEncryptionAlgorithm;
17
+ receivingKey: CoreBuffer;
18
+ transmissionKey: CoreBuffer;
20
19
  toJSON(verbose?: boolean): ICryptoExchangeSecretsSerialized;
21
20
  clear(): void;
22
21
  serialize(verbose?: boolean): string;
23
22
  toBase64(verbose?: boolean): string;
24
- static from(value: CryptoExchangeSecrets | ICryptoExchangeSecrets): Promise<CryptoExchangeSecrets>;
25
- static fromJSON(value: ICryptoExchangeSecretsSerialized): Promise<CryptoExchangeSecrets>;
23
+ static from(value: CryptoExchangeSecrets | ICryptoExchangeSecrets): CryptoExchangeSecrets;
24
+ static preFrom(value: any): any;
25
+ static fromJSON(value: ICryptoExchangeSecretsSerialized): CryptoExchangeSecrets;
26
26
  static fromBase64(value: string): Promise<CryptoExchangeSecrets>;
27
- static deserialize(value: string): Promise<CryptoExchangeSecrets>;
28
27
  }
@@ -8,29 +8,19 @@ 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 CryptoExchangeSecrets_1;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.CryptoExchangeSecrets = void 0;
14
13
  const ts_serval_1 = require("@js-soft/ts-serval");
15
14
  const CoreBuffer_1 = require("../CoreBuffer");
16
- const CryptoSerializableAsync_1 = require("../CryptoSerializableAsync");
17
- let CryptoExchangeSecrets = CryptoExchangeSecrets_1 = class CryptoExchangeSecrets extends CryptoSerializableAsync_1.CryptoSerializableAsync {
18
- constructor(receivingKey, transmissionKey, algorithm) {
19
- super();
20
- this.receivingKey = receivingKey;
21
- this.transmissionKey = transmissionKey;
22
- this.algorithm = algorithm;
23
- }
15
+ const CryptoSerializable_1 = require("../CryptoSerializable");
16
+ let CryptoExchangeSecrets = class CryptoExchangeSecrets extends CryptoSerializable_1.CryptoSerializable {
24
17
  toJSON(verbose = true) {
25
- const obj = {
18
+ return {
26
19
  rx: this.receivingKey.toBase64URL(),
27
20
  tx: this.transmissionKey.toBase64URL(),
28
- alg: this.algorithm
21
+ alg: this.algorithm,
22
+ "@type": verbose ? "CryptoExchangeSecrets" : undefined
29
23
  };
30
- if (verbose) {
31
- obj["@type"] = "CryptoExchangeSecrets";
32
- }
33
- return obj;
34
24
  }
35
25
  clear() {
36
26
  this.receivingKey.clear();
@@ -43,34 +33,42 @@ let CryptoExchangeSecrets = CryptoExchangeSecrets_1 = class CryptoExchangeSecret
43
33
  return CoreBuffer_1.CoreBuffer.utf8_base64(this.serialize(verbose));
44
34
  }
45
35
  static from(value) {
46
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
47
- if (!value.algorithm || !value.receivingKey || !value.transmissionKey) {
48
- throw new Error("No algorithm, receivingKey or transmissionKey property set.");
36
+ return this.fromAny(value);
37
+ }
38
+ static preFrom(value) {
39
+ if (value.rx) {
40
+ value = {
41
+ algorithm: value.alg,
42
+ receivingKey: value.rx,
43
+ transmissionKey: value.tx
44
+ };
49
45
  }
50
- const receivingKey = CoreBuffer_1.CoreBuffer.from(value.receivingKey);
51
- const transmissionKey = CoreBuffer_1.CoreBuffer.from(value.transmissionKey);
52
- return Promise.resolve(new CryptoExchangeSecrets_1(receivingKey, transmissionKey, value.algorithm));
46
+ return value;
53
47
  }
54
48
  static fromJSON(value) {
55
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
56
- if (!value.alg || !value.rx || !value.tx) {
57
- throw new Error("No algorithm, receivingKey or transmissionKey property set.");
58
- }
59
- const receivingKey = CoreBuffer_1.CoreBuffer.fromBase64URL(value.rx);
60
- const transmissionKey = CoreBuffer_1.CoreBuffer.fromBase64URL(value.tx);
61
- return Promise.resolve(new CryptoExchangeSecrets_1(receivingKey, transmissionKey, value.alg));
49
+ return this.fromAny(value);
62
50
  }
63
51
  static fromBase64(value) {
64
52
  return Promise.resolve(this.deserialize(CoreBuffer_1.CoreBuffer.base64_utf8(value)));
65
53
  }
66
- static async deserialize(value) {
67
- const obj = JSON.parse(value);
68
- return await this.fromJSON(obj);
69
- }
70
54
  };
71
- CryptoExchangeSecrets = CryptoExchangeSecrets_1 = __decorate([
72
- (0, ts_serval_1.type)("CryptoExchangeSecrets"),
73
- __metadata("design:paramtypes", [CoreBuffer_1.CoreBuffer, CoreBuffer_1.CoreBuffer, Number])
55
+ __decorate([
56
+ (0, ts_serval_1.validate)(),
57
+ (0, ts_serval_1.serialize)(),
58
+ __metadata("design:type", Number)
59
+ ], CryptoExchangeSecrets.prototype, "algorithm", void 0);
60
+ __decorate([
61
+ (0, ts_serval_1.validate)(),
62
+ (0, ts_serval_1.serialize)(),
63
+ __metadata("design:type", CoreBuffer_1.CoreBuffer)
64
+ ], CryptoExchangeSecrets.prototype, "receivingKey", void 0);
65
+ __decorate([
66
+ (0, ts_serval_1.validate)(),
67
+ (0, ts_serval_1.serialize)(),
68
+ __metadata("design:type", CoreBuffer_1.CoreBuffer)
69
+ ], CryptoExchangeSecrets.prototype, "transmissionKey", void 0);
70
+ CryptoExchangeSecrets = __decorate([
71
+ (0, ts_serval_1.type)("CryptoExchangeSecrets")
74
72
  ], CryptoExchangeSecrets);
75
73
  exports.CryptoExchangeSecrets = CryptoExchangeSecrets;
76
74
  //# sourceMappingURL=CryptoExchangeSecrets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoExchangeSecrets.js","sourceRoot":"","sources":["../../src/exchange/CryptoExchangeSecrets.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kDAA2E;AAC3E,8CAAoE;AACpE,wEAAqE;AAgBrE,IAAa,qBAAqB,6BAAlC,MAAa,qBAAsB,SAAQ,iDAAuB;IAK9D,YAAmB,YAAwB,EAAE,eAA2B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AAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,KAAa;QAClC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,uBAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;CACJ,CAAA;AAtDG;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;;wDACgC;AAI5C;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACS,uBAAU;2DAAC;AAIhC;IAFC,IAAA,oBAAQ,GAAE;IACV,IAAA,qBAAS,GAAE;8BACY,uBAAU;8DAAC;AAX1B,qBAAqB;IADjC,IAAA,gBAAI,EAAC,uBAAuB,CAAC;GACjB,qBAAqB,CAyDjC;AAzDY,sDAAqB"}
@@ -2,19 +2,16 @@ import { CoreBuffer } from "../CoreBuffer";
2
2
  import { CryptoError } from "../CryptoError";
3
3
  import { CryptoValidation } from "../CryptoValidation";
4
4
  import { CryptoExchangeAlgorithm } from "./CryptoExchange";
5
- import { CryptoExchangePrivateKey } from "./CryptoExchangePrivateKey";
6
- import { CryptoExchangePublicKey } from "./CryptoExchangePublicKey";
7
5
  export declare class CryptoExchangeValidation extends CryptoValidation {
8
- static readonly PRIVATE_KEY_MIN_BYTES: number;
9
- static readonly PRIVATE_KEY_MAX_BYTES: number;
10
- static readonly PUBLIC_KEY_MIN_BYTES: number;
11
- static readonly PUBLIC_KEY_MAX_BYTES: number;
6
+ static readonly PRIVATE_KEY_MIN_BYTES = 20;
7
+ static readonly PRIVATE_KEY_MAX_BYTES = 40;
8
+ static readonly PUBLIC_KEY_MIN_BYTES = 20;
9
+ static readonly PUBLIC_KEY_MAX_BYTES = 40;
12
10
  static checkExchangeAlgorithm(algorithm: number, throwError?: boolean): CryptoError | undefined;
13
- static checkExchangePrivateKeyAsNumber(privateKey: string, algorithm: CryptoExchangeAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
11
+ static checkExchangePrivateKeyAsString(privateKey: string, algorithm: CryptoExchangeAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
14
12
  static checkExchangePrivateKeyAsBuffer(privateKey: CoreBuffer, algorithm: CryptoExchangeAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
15
- static checkExchangePrivateKey(privateKey: CryptoExchangePrivateKey, throwError?: boolean): CryptoError | undefined;
13
+ static checkExchangePrivateKey(privateKey: string | CoreBuffer, algorithm: CryptoExchangeAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
16
14
  static checkExchangePublicKeyAsString(publicKey: string, algorithm: CryptoExchangeAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
17
15
  static checkExchangePublicKeyAsBuffer(publicKey: CoreBuffer, algorithm: CryptoExchangeAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
18
- static checkExchangePublicKey(publicKey: CryptoExchangePublicKey, throwError?: boolean): CryptoError | undefined;
19
- static checkExchangeKeypair(privateKey: CryptoExchangePrivateKey, publicKey: CryptoExchangePublicKey, throwError?: boolean): CryptoError | undefined;
16
+ static checkExchangePublicKey(publicKey: string | CoreBuffer, algorithm: CryptoExchangeAlgorithm, propertyName?: string, throwError?: boolean): CryptoError | undefined;
20
17
  }