@haskou/value-objects 1.2.0 → 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.
Files changed (75) hide show
  1. package/README.md +29 -2
  2. package/dist/errors/InvalidKeyError.d.ts +5 -0
  3. package/dist/errors/InvalidKeyError.d.ts.map +1 -0
  4. package/dist/errors/InvalidKeyError.js +11 -0
  5. package/dist/errors/InvalidKeyError.js.map +1 -0
  6. package/dist/errors/InvalidSignatureError.d.ts +5 -0
  7. package/dist/errors/InvalidSignatureError.d.ts.map +1 -0
  8. package/dist/errors/InvalidSignatureError.js +11 -0
  9. package/dist/errors/InvalidSignatureError.js.map +1 -0
  10. package/dist/errors/index.d.ts +3 -0
  11. package/dist/errors/index.d.ts.map +1 -1
  12. package/dist/errors/index.js +3 -0
  13. package/dist/errors/index.js.map +1 -1
  14. package/dist/value-objects/crypto/CryptoPayload.d.ts +4 -0
  15. package/dist/value-objects/crypto/CryptoPayload.d.ts.map +1 -0
  16. package/dist/value-objects/crypto/CryptoPayload.js +3 -0
  17. package/dist/value-objects/crypto/CryptoPayload.js.map +1 -0
  18. package/dist/value-objects/crypto/EncryptedKeyPair.d.ts +21 -0
  19. package/dist/value-objects/crypto/EncryptedKeyPair.d.ts.map +1 -0
  20. package/dist/value-objects/crypto/EncryptedKeyPair.js +35 -0
  21. package/dist/value-objects/crypto/EncryptedKeyPair.js.map +1 -0
  22. package/dist/value-objects/crypto/EncryptedPayload.d.ts +4 -0
  23. package/dist/value-objects/crypto/EncryptedPayload.d.ts.map +1 -0
  24. package/dist/value-objects/crypto/EncryptedPayload.js +8 -0
  25. package/dist/value-objects/crypto/EncryptedPayload.js.map +1 -0
  26. package/dist/value-objects/crypto/EncryptedPrivateKey.d.ts +14 -0
  27. package/dist/value-objects/crypto/EncryptedPrivateKey.d.ts.map +1 -0
  28. package/dist/value-objects/crypto/EncryptedPrivateKey.js +55 -0
  29. package/dist/value-objects/crypto/EncryptedPrivateKey.js.map +1 -0
  30. package/dist/value-objects/crypto/Key.d.ts +4 -0
  31. package/dist/value-objects/crypto/Key.d.ts.map +1 -0
  32. package/dist/value-objects/crypto/Key.js +8 -0
  33. package/dist/value-objects/crypto/Key.js.map +1 -0
  34. package/dist/value-objects/crypto/KeyPair.d.ts +22 -0
  35. package/dist/value-objects/crypto/KeyPair.d.ts.map +1 -0
  36. package/dist/value-objects/crypto/KeyPair.js +45 -0
  37. package/dist/value-objects/crypto/KeyPair.js.map +1 -0
  38. package/dist/value-objects/crypto/PrivateKey.d.ts +13 -0
  39. package/dist/value-objects/crypto/PrivateKey.d.ts.map +1 -0
  40. package/dist/value-objects/crypto/PrivateKey.js +36 -0
  41. package/dist/value-objects/crypto/PrivateKey.js.map +1 -0
  42. package/dist/value-objects/crypto/PublicKey.d.ts +13 -0
  43. package/dist/value-objects/crypto/PublicKey.d.ts.map +1 -0
  44. package/dist/value-objects/crypto/PublicKey.js +36 -0
  45. package/dist/value-objects/crypto/PublicKey.js.map +1 -0
  46. package/dist/value-objects/crypto/Signature.d.ts +10 -0
  47. package/dist/value-objects/crypto/Signature.d.ts.map +1 -0
  48. package/dist/value-objects/crypto/Signature.js +27 -0
  49. package/dist/value-objects/crypto/Signature.js.map +1 -0
  50. package/dist/value-objects/crypto/index.d.ts +9 -0
  51. package/dist/value-objects/crypto/index.d.ts.map +1 -0
  52. package/dist/value-objects/crypto/index.js +12 -0
  53. package/dist/value-objects/crypto/index.js.map +1 -0
  54. package/dist/value-objects/hashes/MD5Hash.d.ts +2 -1
  55. package/dist/value-objects/hashes/MD5Hash.d.ts.map +1 -1
  56. package/dist/value-objects/hashes/MD5Hash.js.map +1 -1
  57. package/dist/value-objects/hashes/SHA256Hash.d.ts +2 -1
  58. package/dist/value-objects/hashes/SHA256Hash.d.ts.map +1 -1
  59. package/dist/value-objects/hashes/SHA256Hash.js.map +1 -1
  60. package/dist/value-objects/hashes/SHA512Hash.d.ts +2 -1
  61. package/dist/value-objects/hashes/SHA512Hash.d.ts.map +1 -1
  62. package/dist/value-objects/hashes/SHA512Hash.js.map +1 -1
  63. package/dist/value-objects/index.d.ts +2 -0
  64. package/dist/value-objects/index.d.ts.map +1 -1
  65. package/dist/value-objects/index.js +2 -0
  66. package/dist/value-objects/index.js.map +1 -1
  67. package/dist/value-objects/media/Media.d.ts +8 -0
  68. package/dist/value-objects/media/Media.d.ts.map +1 -0
  69. package/dist/value-objects/media/Media.js +24 -0
  70. package/dist/value-objects/media/Media.js.map +1 -0
  71. package/dist/value-objects/media/index.d.ts +2 -0
  72. package/dist/value-objects/media/index.d.ts.map +1 -0
  73. package/dist/value-objects/media/index.js +5 -0
  74. package/dist/value-objects/media/index.js.map +1 -0
  75. package/package.json +1 -1
package/README.md CHANGED
@@ -83,12 +83,23 @@ your application.
83
83
  - **`Longitude`** - Longitude (-180 to 180)
84
84
  - **`Coordinates`** - Coordinate pairs
85
85
 
86
- ### Hashes
86
+ ### 🔐 Cryptography
87
+ - **`KeyPair`** - Ed25519 key pair generation, signing, and verification
88
+ - **`PrivateKey`** - Ed25519 private key (PEM format) with signing
89
+ - **`PublicKey`** - Ed25519 public key (PEM format) with signature verification
90
+ - **`Signature`** - Base64-encoded ed25519 digital signature
91
+ - **`EncryptedPrivateKey`** - AES-256-GCM encrypted private key (password-based)
92
+ - **`EncryptedKeyPair`** - Key pair with encrypted private key
93
+
94
+ ### 📎 Media
95
+ - **`Media`** - Binary/string content with Buffer, size, and Base64 helpers
96
+
97
+ ### #️ Hashes
87
98
  - **`MD5Hash`** - MD5 hashes with helpers
88
99
  - **`SHA256Hash`** - SHA‑256 hashes with helpers
89
100
  - **`SHA512Hash`** - SHA‑512 hashes with helpers
90
101
 
91
- ### �📝 Other
102
+ ### 📝 Other
92
103
  - **`Enum`** - Base class for typed enumerations
93
104
 
94
105
  ## 💡 Basic Examples
@@ -130,6 +141,22 @@ const md5 = MD5Hash.from('hello'); // 5d41402abc4b2a76b9719d911017c592
130
141
  const sha256 = SHA256Hash.from('hello'); // 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
131
142
  const sha512 = SHA512Hash.from('hello'); // 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
132
143
  console.log(md5.toBase64());
144
+
145
+ // Crypto
146
+ const keyPair = KeyPair.generate(); // Ed25519 key pair
147
+ const signature = keyPair.sign('hello world'); // Sign a message
148
+ keyPair.isValidSignature('hello world', signature); // true
149
+
150
+ // Encrypted key pairs
151
+ const encrypted = await keyPair.encryptKeyPair('my-password');
152
+ const sig = encrypted.sign('message', 'my-password');
153
+ encrypted.isValidSignature('message', sig); // true
154
+
155
+ // Media
156
+ const media = new Media('hello world');
157
+ console.log(media.getSize()); // 11
158
+ console.log(media.getBase64()); // 'aGVsbG8gd29ybGQ='
159
+ console.log(media.getBuffer()); // <Buffer 68 65 6c 6c 6f ...>
133
160
  ```
134
161
 
135
162
  ## 📚 Technical Documentation
@@ -0,0 +1,5 @@
1
+ import { DomainError } from './DomainError';
2
+ export declare class InvalidKeyError extends DomainError {
3
+ constructor(keySize: number, possibleKeySizes: number[]);
4
+ }
5
+ //# sourceMappingURL=InvalidKeyError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvalidKeyError.d.ts","sourceRoot":"","sources":["../../src/errors/InvalidKeyError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,eAAgB,SAAQ,WAAW;gBAClC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE;CAOxD"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidKeyError = void 0;
4
+ const DomainError_1 = require("./DomainError");
5
+ class InvalidKeyError extends DomainError_1.DomainError {
6
+ constructor(keySize, possibleKeySizes) {
7
+ super(`Invalid key size: ${keySize}. Supported key sizes are ${possibleKeySizes.join(', ')}`);
8
+ }
9
+ }
10
+ exports.InvalidKeyError = InvalidKeyError;
11
+ //# sourceMappingURL=InvalidKeyError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvalidKeyError.js","sourceRoot":"","sources":["../../src/errors/InvalidKeyError.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAE5C,MAAa,eAAgB,SAAQ,yBAAW;IAC9C,YAAY,OAAe,EAAE,gBAA0B;QACrD,KAAK,CACH,qBAAqB,OAAO,6BAA6B,gBAAgB,CAAC,IAAI,CAC5E,IAAI,CACL,EAAE,CACJ,CAAC;IACJ,CAAC;CACF;AARD,0CAQC"}
@@ -0,0 +1,5 @@
1
+ import { DomainError } from './DomainError';
2
+ export declare class InvalidSignatureError extends DomainError {
3
+ constructor(length: number);
4
+ }
5
+ //# sourceMappingURL=InvalidSignatureError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvalidSignatureError.d.ts","sourceRoot":"","sources":["../../src/errors/InvalidSignatureError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,MAAM,EAAE,MAAM;CAG3B"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidSignatureError = void 0;
4
+ const DomainError_1 = require("./DomainError");
5
+ class InvalidSignatureError extends DomainError_1.DomainError {
6
+ constructor(length) {
7
+ super(`Signature must be a ${length}-character string`);
8
+ }
9
+ }
10
+ exports.InvalidSignatureError = InvalidSignatureError;
11
+ //# sourceMappingURL=InvalidSignatureError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvalidSignatureError.js","sourceRoot":"","sources":["../../src/errors/InvalidSignatureError.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAE5C,MAAa,qBAAsB,SAAQ,yBAAW;IACpD,YAAY,MAAc;QACxB,KAAK,CAAC,uBAAuB,MAAM,mBAAmB,CAAC,CAAC;IAC1D,CAAC;CACF;AAJD,sDAIC"}
@@ -16,6 +16,9 @@ export * from './InvalidNumberError';
16
16
  export * from './InvalidPositiveNumberError';
17
17
  export * from './InvalidStringLengthError';
18
18
  export * from './InvalidTimestampIntervalError';
19
+ export * from './InvalidKeyError';
20
+ export * from './InvalidLengthError';
21
+ export * from './InvalidSignatureError';
19
22
  export * from './NullObjectError';
20
23
  export * from './ValueNotInEnumError';
21
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
@@ -19,6 +19,9 @@ tslib_1.__exportStar(require("./InvalidNumberError"), exports);
19
19
  tslib_1.__exportStar(require("./InvalidPositiveNumberError"), exports);
20
20
  tslib_1.__exportStar(require("./InvalidStringLengthError"), exports);
21
21
  tslib_1.__exportStar(require("./InvalidTimestampIntervalError"), exports);
22
+ tslib_1.__exportStar(require("./InvalidKeyError"), exports);
23
+ tslib_1.__exportStar(require("./InvalidLengthError"), exports);
24
+ tslib_1.__exportStar(require("./InvalidSignatureError"), exports);
22
25
  tslib_1.__exportStar(require("./NullObjectError"), exports);
23
26
  tslib_1.__exportStar(require("./ValueNotInEnumError"), exports);
24
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,wDAA8B;AAC9B,8DAAoC;AACpC,4DAAkC;AAClC,kEAAwC;AACxC,6DAAmC;AACnC,8DAAoC;AACpC,+DAAqC;AACrC,6DAAmC;AACnC,gEAAsC;AACtC,iEAAuC;AACvC,kEAAwC;AACxC,8DAAoC;AACpC,gEAAsC;AACtC,+DAAqC;AACrC,uEAA6C;AAC7C,qEAA2C;AAC3C,0EAAgD;AAChD,4DAAkC;AAClC,gEAAsC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,wDAA8B;AAC9B,8DAAoC;AACpC,4DAAkC;AAClC,kEAAwC;AACxC,6DAAmC;AACnC,8DAAoC;AACpC,+DAAqC;AACrC,6DAAmC;AACnC,gEAAsC;AACtC,iEAAuC;AACvC,kEAAwC;AACxC,8DAAoC;AACpC,gEAAsC;AACtC,+DAAqC;AACrC,uEAA6C;AAC7C,qEAA2C;AAC3C,0EAAgD;AAChD,4DAAkC;AAClC,+DAAqC;AACrC,kEAAwC;AACxC,4DAAkC;AAClC,gEAAsC"}
@@ -0,0 +1,4 @@
1
+ import { Media } from '../media';
2
+ import { StringValueObject } from '../StringValueObject';
3
+ export type CryptoPayload = string | StringValueObject | Buffer | Media;
4
+ //# sourceMappingURL=CryptoPayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CryptoPayload.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/CryptoPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,iBAAiB,GAAG,MAAM,GAAG,KAAK,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=CryptoPayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CryptoPayload.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/CryptoPayload.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import { PrimitiveOf } from '../../interfaces';
2
+ import { StringValueObject } from '../StringValueObject';
3
+ import { CryptoPayload } from './CryptoPayload';
4
+ import { EncryptedPrivateKey } from './EncryptedPrivateKey';
5
+ import { PrivateKey } from './PrivateKey';
6
+ import { PublicKey } from './PublicKey';
7
+ import { Signature } from './Signature';
8
+ export declare class EncryptedKeyPair {
9
+ private readonly publicKey;
10
+ private readonly encryptedPrivateKey;
11
+ static encryptKeyPair(publicKey: PublicKey, privateKey: PrivateKey, password: string | StringValueObject): Promise<EncryptedKeyPair>;
12
+ static fromPrimitives(primitives: PrimitiveOf<EncryptedKeyPair>): EncryptedKeyPair;
13
+ constructor(publicKey: PublicKey, encryptedPrivateKey: EncryptedPrivateKey);
14
+ isValidSignature(payload: CryptoPayload, signature: Signature): boolean;
15
+ sign(payload: CryptoPayload, password: string | StringValueObject): Promise<Signature>;
16
+ toPrimitives(): {
17
+ encryptedPrivateKey: string;
18
+ publicKey: string;
19
+ };
20
+ }
21
+ //# sourceMappingURL=EncryptedKeyPair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedKeyPair.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/EncryptedKeyPair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,gBAAgB;IAwBzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;WAxBlB,cAAc,CAChC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GACnC,OAAO,CAAC,gBAAgB,CAAC;WASd,cAAc,CAC1B,UAAU,EAAE,WAAW,CAAC,gBAAgB,CAAC,GACxC,gBAAgB;gBAQA,SAAS,EAAE,SAAS,EACpB,mBAAmB,EAAE,mBAAmB;IAGpD,gBAAgB,CACrB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,SAAS,GACnB,OAAO;IAIG,IAAI,CACf,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GACnC,OAAO,CAAC,SAAS,CAAC;IAMd,YAAY;;;;CAMpB"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptedKeyPair = void 0;
4
+ const EncryptedPrivateKey_1 = require("./EncryptedPrivateKey");
5
+ const PublicKey_1 = require("./PublicKey");
6
+ class EncryptedKeyPair {
7
+ publicKey;
8
+ encryptedPrivateKey;
9
+ static async encryptKeyPair(publicKey, privateKey, password) {
10
+ const encryptedPrivateKey = await EncryptedPrivateKey_1.EncryptedPrivateKey.create(privateKey, password);
11
+ return new EncryptedKeyPair(publicKey, encryptedPrivateKey);
12
+ }
13
+ static fromPrimitives(primitives) {
14
+ return new EncryptedKeyPair(new PublicKey_1.PublicKey(primitives.publicKey), new EncryptedPrivateKey_1.EncryptedPrivateKey(primitives.encryptedPrivateKey));
15
+ }
16
+ constructor(publicKey, encryptedPrivateKey) {
17
+ this.publicKey = publicKey;
18
+ this.encryptedPrivateKey = encryptedPrivateKey;
19
+ }
20
+ isValidSignature(payload, signature) {
21
+ return this.publicKey.isValidSignature(payload, signature);
22
+ }
23
+ async sign(payload, password) {
24
+ const privateKey = await this.encryptedPrivateKey.decrypt(password);
25
+ return privateKey.sign(payload);
26
+ }
27
+ toPrimitives() {
28
+ return {
29
+ encryptedPrivateKey: this.encryptedPrivateKey.valueOf(),
30
+ publicKey: this.publicKey.valueOf(),
31
+ };
32
+ }
33
+ }
34
+ exports.EncryptedKeyPair = EncryptedKeyPair;
35
+ //# sourceMappingURL=EncryptedKeyPair.js.map
@@ -0,0 +1 @@
1
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"}
@@ -0,0 +1,4 @@
1
+ import { ValueObject } from '../ValueObject';
2
+ export declare class EncryptedPayload extends ValueObject<string> {
3
+ }
4
+ //# sourceMappingURL=EncryptedPayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedPayload.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/EncryptedPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,gBAAiB,SAAQ,WAAW,CAAC,MAAM,CAAC;CAAG"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptedPayload = void 0;
4
+ const ValueObject_1 = require("../ValueObject");
5
+ class EncryptedPayload extends ValueObject_1.ValueObject {
6
+ }
7
+ exports.EncryptedPayload = EncryptedPayload;
8
+ //# sourceMappingURL=EncryptedPayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedPayload.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/EncryptedPayload.ts"],"names":[],"mappings":";;;AAAA,gDAA6C;AAE7C,MAAa,gBAAiB,SAAQ,yBAAmB;CAAG;AAA5D,4CAA4D"}
@@ -0,0 +1,14 @@
1
+ import { StringValueObject } from '../StringValueObject';
2
+ import { ValueObject } from '../ValueObject';
3
+ import { PrivateKey } from './PrivateKey';
4
+ export declare class EncryptedPrivateKey extends ValueObject<string> {
5
+ private static readonly ITERATIONS;
6
+ private static readonly SALT_ENTROPY;
7
+ private static readonly IV_ENTROPY;
8
+ private static readonly LENGTH;
9
+ private static readonly ALGORITHM;
10
+ static create(privateKey: PrivateKey, password: string | StringValueObject): Promise<EncryptedPrivateKey>;
11
+ constructor(encryptedPrivateKey: string | StringValueObject);
12
+ decrypt(password: string | StringValueObject): Promise<PrivateKey>;
13
+ }
14
+ //# sourceMappingURL=EncryptedPrivateKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedPrivateKey.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/EncryptedPrivateKey.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,qBAAa,mBAAoB,SAAQ,WAAW,CAAC,MAAM,CAAC;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAU;IAC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAM;IAC1C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAM;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAM;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAY;WAEzB,MAAM,CACxB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GACnC,OAAO,CAAC,mBAAmB,CAAC;gBA2BnB,mBAAmB,EAAE,MAAM,GAAG,iBAAiB;IAI9C,OAAO,CAClB,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GACnC,OAAO,CAAC,UAAU,CAAC;CA0BvB"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptedPrivateKey = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto = tslib_1.__importStar(require("node:crypto"));
6
+ const node_util_1 = require("node:util");
7
+ const ValueObject_1 = require("../ValueObject");
8
+ const PrivateKey_1 = require("./PrivateKey");
9
+ const pbkdf2 = (0, node_util_1.promisify)(crypto.pbkdf2);
10
+ const randomBytes = (0, node_util_1.promisify)(crypto.randomBytes);
11
+ class EncryptedPrivateKey extends ValueObject_1.ValueObject {
12
+ static ITERATIONS = 100000;
13
+ static SALT_ENTROPY = 16;
14
+ static IV_ENTROPY = 12;
15
+ static LENGTH = 32;
16
+ static ALGORITHM = 'sha256';
17
+ static async create(privateKey, password) {
18
+ const salt = await randomBytes(EncryptedPrivateKey.SALT_ENTROPY);
19
+ const key = await pbkdf2(password.valueOf(), salt, EncryptedPrivateKey.ITERATIONS, EncryptedPrivateKey.LENGTH, EncryptedPrivateKey.ALGORITHM);
20
+ const iv = await randomBytes(EncryptedPrivateKey.IV_ENTROPY);
21
+ const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
22
+ const encrypted = Buffer.concat([
23
+ cipher.update(privateKey.valueOf()),
24
+ cipher.final(),
25
+ ]);
26
+ const tag = cipher.getAuthTag();
27
+ const encryptedPrivateKey = [
28
+ encrypted.toString('base64'),
29
+ iv.toString('base64'),
30
+ salt.toString('base64'),
31
+ tag.toString('base64'),
32
+ ].join('.');
33
+ return new EncryptedPrivateKey(encryptedPrivateKey);
34
+ }
35
+ constructor(encryptedPrivateKey) {
36
+ super(encryptedPrivateKey?.valueOf());
37
+ }
38
+ async decrypt(password) {
39
+ const [cipherTextB64, ivB64, saltB64, tagB64] = this.valueOf().split('.');
40
+ const cipherText = Buffer.from(cipherTextB64, 'base64');
41
+ const iv = Buffer.from(ivB64, 'base64');
42
+ const salt = Buffer.from(saltB64, 'base64');
43
+ const tag = Buffer.from(tagB64, 'base64');
44
+ const key = await pbkdf2(password.valueOf(), salt, EncryptedPrivateKey.ITERATIONS, EncryptedPrivateKey.LENGTH, EncryptedPrivateKey.ALGORITHM);
45
+ const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
46
+ decipher.setAuthTag(tag);
47
+ const decrypted = Buffer.concat([
48
+ decipher.update(cipherText),
49
+ decipher.final(),
50
+ ]);
51
+ return new PrivateKey_1.PrivateKey(decrypted.toString());
52
+ }
53
+ }
54
+ exports.EncryptedPrivateKey = EncryptedPrivateKey;
55
+ //# sourceMappingURL=EncryptedPrivateKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Encry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AAG,MAAM,CAAC,MAAM,CAAC;YAC9B,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;YAC3B,QAAQ,CAAC,KAAK,EAAE;SACjB,CAAC,CAAC;QAEH,OAAO,IAAI,uBAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9C,CAAC;;AApEH,kDAqEC"}
@@ -0,0 +1,4 @@
1
+ import { ValueObject } from '../ValueObject';
2
+ export declare abstract class Key extends ValueObject<string> {
3
+ }
4
+ //# sourceMappingURL=Key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Key.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/Key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,8BAAsB,GAAI,SAAQ,WAAW,CAAC,MAAM,CAAC;CAAG"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Key = void 0;
4
+ const ValueObject_1 = require("../ValueObject");
5
+ class Key extends ValueObject_1.ValueObject {
6
+ }
7
+ exports.Key = Key;
8
+ //# sourceMappingURL=Key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Key.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/Key.ts"],"names":[],"mappings":";;;AAAA,gDAA6C;AAE7C,MAAsB,GAAI,SAAQ,yBAAmB;CAAG;AAAxD,kBAAwD"}
@@ -0,0 +1,22 @@
1
+ import { PrimitiveOf } from '../../interfaces';
2
+ import { StringValueObject } from '../StringValueObject';
3
+ import { CryptoPayload } from './CryptoPayload';
4
+ import { EncryptedKeyPair } from './EncryptedKeyPair';
5
+ import { PrivateKey } from './PrivateKey';
6
+ import { PublicKey } from './PublicKey';
7
+ import { Signature } from './Signature';
8
+ export declare class KeyPair {
9
+ private readonly publicKey;
10
+ private readonly privateKey;
11
+ static generate(): Promise<KeyPair>;
12
+ static fromPrimitives(primitives: PrimitiveOf<KeyPair>): KeyPair;
13
+ constructor(publicKey: PublicKey, privateKey: PrivateKey);
14
+ encryptKeyPair(password: string | StringValueObject): Promise<EncryptedKeyPair>;
15
+ isValidSignature(payload: CryptoPayload, signature: Signature): boolean;
16
+ sign(payload: CryptoPayload): Signature;
17
+ toPrimitives(): {
18
+ privateKey: string;
19
+ publicKey: string;
20
+ };
21
+ }
22
+ //# sourceMappingURL=KeyPair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyPair.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/KeyPair.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC,qBAAa,OAAO;IAkBhB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU;WAlBT,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;WASlC,cAAc,CAAC,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO;gBAQpD,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU;IAG5B,cAAc,CACzB,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GACnC,OAAO,CAAC,gBAAgB,CAAC;IAQrB,gBAAgB,CACrB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,SAAS,GACnB,OAAO;IAIH,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS;IAIvC,YAAY;;;;CAMpB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyPair = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto = tslib_1.__importStar(require("node:crypto"));
6
+ const node_util_1 = require("node:util");
7
+ const EncryptedKeyPair_1 = require("./EncryptedKeyPair");
8
+ const PrivateKey_1 = require("./PrivateKey");
9
+ const PublicKey_1 = require("./PublicKey");
10
+ const generateKeyPair = (0, node_util_1.promisify)(crypto.generateKeyPair);
11
+ class KeyPair {
12
+ publicKey;
13
+ privateKey;
14
+ static async generate() {
15
+ const { privateKey, publicKey } = await generateKeyPair('ed25519', {
16
+ privateKeyEncoding: { format: 'pem', type: 'pkcs8' },
17
+ publicKeyEncoding: { format: 'pem', type: 'spki' },
18
+ });
19
+ return new KeyPair(new PublicKey_1.PublicKey(publicKey), new PrivateKey_1.PrivateKey(privateKey));
20
+ }
21
+ static fromPrimitives(primitives) {
22
+ return new KeyPair(new PublicKey_1.PublicKey(primitives.publicKey), new PrivateKey_1.PrivateKey(primitives.privateKey));
23
+ }
24
+ constructor(publicKey, privateKey) {
25
+ this.publicKey = publicKey;
26
+ this.privateKey = privateKey;
27
+ }
28
+ async encryptKeyPair(password) {
29
+ return await EncryptedKeyPair_1.EncryptedKeyPair.encryptKeyPair(this.publicKey, this.privateKey, password.valueOf());
30
+ }
31
+ isValidSignature(payload, signature) {
32
+ return this.publicKey.isValidSignature(payload, signature);
33
+ }
34
+ sign(payload) {
35
+ return this.privateKey.sign(payload);
36
+ }
37
+ toPrimitives() {
38
+ return {
39
+ privateKey: this.privateKey.valueOf(),
40
+ publicKey: this.publicKey.valueOf(),
41
+ };
42
+ }
43
+ }
44
+ exports.KeyPair = KeyPair;
45
+ //# sourceMappingURL=KeyPair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyPair.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/KeyPair.ts"],"names":[],"mappings":";;;;AAAA,4DAAsC;AACtC,yCAA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AAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAEM,YAAY;QACjB,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACrC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;SACpC,CAAC;IACJ,CAAC;CACF;AAjDD,0BAiDC"}
@@ -0,0 +1,13 @@
1
+ import { StringValueObject } from '../StringValueObject';
2
+ import { CryptoPayload } from './CryptoPayload';
3
+ import { Key } from './Key';
4
+ import { Signature } from './Signature';
5
+ export declare class PrivateKey extends Key {
6
+ private static readonly LENGTH;
7
+ private static readonly PATTERN;
8
+ static fromPEM(pem: string | StringValueObject): PrivateKey;
9
+ constructor(value: string | StringValueObject);
10
+ private ensureIsValidPrivateKey;
11
+ sign(payload: CryptoPayload): Signature;
12
+ }
13
+ //# sourceMappingURL=PrivateKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrivateKey.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/PrivateKey.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,UAAW,SAAQ,GAAG;IACjC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAO;IACrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CACiD;WAElE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,UAAU;gBAItD,KAAK,EAAE,MAAM,GAAG,iBAAiB;IAU7C,OAAO,CAAC,uBAAuB;IAQxB,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS;CAM/C"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrivateKey = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto = tslib_1.__importStar(require("node:crypto"));
6
+ const InvalidFormatError_1 = require("../../errors/InvalidFormatError");
7
+ const InvalidLengthError_1 = require("../../errors/InvalidLengthError");
8
+ const patterns_1 = require("../../patterns");
9
+ const NullObject_1 = require("../NullObject");
10
+ const Key_1 = require("./Key");
11
+ const Signature_1 = require("./Signature");
12
+ class PrivateKey extends Key_1.Key {
13
+ static LENGTH = 119;
14
+ static PATTERN = /^-----BEGIN PRIVATE KEY-----\n[A-Za-z0-9+/=]+\n-----END PRIVATE KEY-----\n$/;
15
+ static fromPEM(pem) {
16
+ return new PrivateKey(pem.valueOf());
17
+ }
18
+ constructor(value) {
19
+ super(value?.valueOf());
20
+ if (NullObject_1.NullObject.isNullObject(this)) {
21
+ return this;
22
+ }
23
+ this.ensureIsValidPrivateKey(this.value);
24
+ }
25
+ ensureIsValidPrivateKey(value) {
26
+ (0, patterns_1.assert)(value.length === PrivateKey.LENGTH, new InvalidLengthError_1.InvalidLengthError(value, PrivateKey.LENGTH));
27
+ (0, patterns_1.assert)(PrivateKey.PATTERN.test(value), new InvalidFormatError_1.InvalidFormatError(value));
28
+ }
29
+ sign(payload) {
30
+ const messageBuffer = Buffer.from(payload.valueOf());
31
+ const signatureBuffer = crypto.sign(null, messageBuffer, this.valueOf());
32
+ return Signature_1.Signature.fromBuffer(signatureBuffer);
33
+ }
34
+ }
35
+ exports.PrivateKey = PrivateKey;
36
+ //# sourceMappingURL=PrivateKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrivateKey.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/PrivateKey.ts"],"names":[],"mappings":";;;;AAAA,4DAAsC;AAEtC,wEAAqE;AACrE,wEAAqE;AACrE,6CAAwC;AACxC,8CAA2C;AAG3C,+BAA4B;AAC5B,2CAAwC;AAExC,MAAa,UAAW,SAAQ,SAAG;IACzB,MAAM,CAAU,MAAM,GAAG,GAAG,CAAC;IAC7B,MAAM,CAAU,OAAO,GAC7B,6EAA6E,CAAC;IAEzE,MAAM,CAAC,OAAO,CAAC,GAA+B;QACnD,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,YAAY,KAAiC;QAC3C,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QAExB,IAAI,uBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAEO,uBAAuB,CAAC,KAAa;QAC3C,IAAA,iBAAM,EACJ,KAAK,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAClC,IAAI,uCAAkB,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CACjD,CAAC;QACF,IAAA,iBAAM,EAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,uCAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;IAEM,IAAI,CAAC,OAAsB;QAChC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACrD,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAEzE,OAAO,qBAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;;AAhCH,gCAiCC"}
@@ -0,0 +1,13 @@
1
+ import { StringValueObject } from '../StringValueObject';
2
+ import { CryptoPayload } from './CryptoPayload';
3
+ import { Key } from './Key';
4
+ import { Signature } from './Signature';
5
+ export declare class PublicKey extends Key {
6
+ private static readonly LENGTH;
7
+ private static readonly PATTERN;
8
+ static fromPEM(pem: string | StringValueObject): PublicKey;
9
+ constructor(value: string | StringValueObject);
10
+ private ensureIsValidPublicKey;
11
+ isValidSignature(payload: CryptoPayload, signature: Signature): boolean;
12
+ }
13
+ //# sourceMappingURL=PublicKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PublicKey.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/PublicKey.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,SAAU,SAAQ,GAAG;IAChC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAO;IACrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAC+C;WAEhE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;gBAIrD,KAAK,EAAE,MAAM,GAAG,iBAAiB;IAU7C,OAAO,CAAC,sBAAsB;IAQvB,gBAAgB,CACrB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,SAAS,GACnB,OAAO;CAYX"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PublicKey = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto = tslib_1.__importStar(require("node:crypto"));
6
+ const InvalidFormatError_1 = require("../../errors/InvalidFormatError");
7
+ const InvalidLengthError_1 = require("../../errors/InvalidLengthError");
8
+ const patterns_1 = require("../../patterns");
9
+ const NullObject_1 = require("../NullObject");
10
+ const Key_1 = require("./Key");
11
+ class PublicKey extends Key_1.Key {
12
+ static LENGTH = 113;
13
+ static PATTERN = /^-----BEGIN PUBLIC KEY-----\n[A-Za-z0-9+/=]+\n-----END PUBLIC KEY-----\n$/;
14
+ static fromPEM(pem) {
15
+ return new PublicKey(pem.valueOf());
16
+ }
17
+ constructor(value) {
18
+ super(value?.valueOf());
19
+ if (NullObject_1.NullObject.isNullObject(this)) {
20
+ return this;
21
+ }
22
+ this.ensureIsValidPublicKey(this.value);
23
+ }
24
+ ensureIsValidPublicKey(value) {
25
+ (0, patterns_1.assert)(value.length === PublicKey.LENGTH, new InvalidLengthError_1.InvalidLengthError(value, PublicKey.LENGTH));
26
+ (0, patterns_1.assert)(PublicKey.PATTERN.test(value), new InvalidFormatError_1.InvalidFormatError(value));
27
+ }
28
+ isValidSignature(payload, signature) {
29
+ const messageBuffer = Buffer.from(payload.valueOf());
30
+ const signatureBuffer = Buffer.from(signature.valueOf(), 'base64');
31
+ const valid = crypto.verify(null, messageBuffer, this.valueOf(), signatureBuffer);
32
+ return valid;
33
+ }
34
+ }
35
+ exports.PublicKey = PublicKey;
36
+ //# sourceMappingURL=PublicKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PublicKey.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/PublicKey.ts"],"names":[],"mappings":";;;;AAAA,4DAAsC;AAEtC,wEAAqE;AACrE,wEAAqE;AACrE,6CAAwC;AACxC,8CAA2C;AAG3C,+BAA4B;AAG5B,MAAa,SAAU,SAAQ,SAAG;IACxB,MAAM,CAAU,MAAM,GAAG,GAAG,CAAC;IAC7B,MAAM,CAAU,OAAO,GAC7B,2EAA2E,CAAC;IAEvE,MAAM,CAAC,OAAO,CAAC,GAA+B;QACnD,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,YAAY,KAAiC;QAC3C,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QAExB,IAAI,uBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAEO,sBAAsB,CAAC,KAAa;QAC1C,IAAA,iBAAM,EACJ,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EACjC,IAAI,uCAAkB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAChD,CAAC;QACF,IAAA,iBAAM,EAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,uCAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,CAAC;IAEM,gBAAgB,CACrB,OAAsB,EACtB,SAAoB;QAEpB,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACrD,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;QACnE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,IAAI,EACJ,aAAa,EACb,IAAI,CAAC,OAAO,EAAE,EACd,eAAe,CAChB,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC;;AAzCH,8BA0CC"}
@@ -0,0 +1,10 @@
1
+ import { StringValueObject } from '../StringValueObject';
2
+ import { ValueObject } from '../ValueObject';
3
+ export declare class Signature extends ValueObject<string> {
4
+ private static readonly LENGTH;
5
+ private static readonly PATTERN;
6
+ static fromBuffer(buffer: Buffer): Signature;
7
+ constructor(value: string | StringValueObject);
8
+ private hasValidFormat;
9
+ }
10
+ //# sourceMappingURL=Signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signature.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/Signature.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,qBAAa,SAAU,SAAQ,WAAW,CAAC,MAAM,CAAC;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAM;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAA2B;WAE5C,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;gBAIvC,KAAK,EAAE,MAAM,GAAG,iBAAiB;IAU7C,OAAO,CAAC,cAAc;CAGvB"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Signature = void 0;
4
+ const InvalidSignatureError_1 = require("../../errors/InvalidSignatureError");
5
+ const patterns_1 = require("../../patterns");
6
+ const NullObject_1 = require("../NullObject");
7
+ const ValueObject_1 = require("../ValueObject");
8
+ // TODO: Test
9
+ class Signature extends ValueObject_1.ValueObject {
10
+ static LENGTH = 88;
11
+ static PATTERN = /^[A-Za-z0-9+/]{86}==$/;
12
+ static fromBuffer(buffer) {
13
+ return new Signature(buffer.toString('base64'));
14
+ }
15
+ constructor(value) {
16
+ super(value?.valueOf());
17
+ if (NullObject_1.NullObject.isNullObject(this)) {
18
+ return this;
19
+ }
20
+ (0, patterns_1.assert)(this.hasValidFormat(), new InvalidSignatureError_1.InvalidSignatureError(Signature.LENGTH));
21
+ }
22
+ hasValidFormat() {
23
+ return Signature.PATTERN.test(this.value);
24
+ }
25
+ }
26
+ exports.Signature = Signature;
27
+ //# sourceMappingURL=Signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signature.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/Signature.ts"],"names":[],"mappings":";;;AAAA,8EAA2E;AAC3E,6CAAwC;AACxC,8CAA2C;AAE3C,gDAA6C;AAE7C,aAAa;AACb,MAAa,SAAU,SAAQ,yBAAmB;IACxC,MAAM,CAAU,MAAM,GAAG,EAAE,CAAC;IAC5B,MAAM,CAAU,OAAO,GAAG,uBAAuB,CAAC;IAEnD,MAAM,CAAC,UAAU,CAAC,MAAc;QACrC,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,YAAY,KAAiC;QAC3C,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QAExB,IAAI,uBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAA,iBAAM,EAAC,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,6CAAqB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7E,CAAC;IAEO,cAAc;QACpB,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;;AApBH,8BAqBC"}
@@ -0,0 +1,9 @@
1
+ export * from './EncryptedKeyPair';
2
+ export * from './EncryptedPayload';
3
+ export * from './EncryptedPrivateKey';
4
+ export * from './Key';
5
+ export * from './KeyPair';
6
+ export * from './PrivateKey';
7
+ export * from './PublicKey';
8
+ export * from './Signature';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/value-objects/crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./EncryptedKeyPair"), exports);
5
+ tslib_1.__exportStar(require("./EncryptedPayload"), exports);
6
+ tslib_1.__exportStar(require("./EncryptedPrivateKey"), exports);
7
+ tslib_1.__exportStar(require("./Key"), exports);
8
+ tslib_1.__exportStar(require("./KeyPair"), exports);
9
+ tslib_1.__exportStar(require("./PrivateKey"), exports);
10
+ tslib_1.__exportStar(require("./PublicKey"), exports);
11
+ tslib_1.__exportStar(require("./Signature"), exports);
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/value-objects/crypto/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC;AACnC,gEAAsC;AACtC,gDAAsB;AACtB,oDAA0B;AAC1B,uDAA6B;AAC7B,sDAA4B;AAC5B,sDAA4B"}
@@ -1,8 +1,9 @@
1
+ import { Media } from '../media/Media';
1
2
  import { StringValueObject } from '../StringValueObject';
2
3
  import { Hash } from './Hash';
3
4
  export declare class MD5Hash extends Hash {
4
5
  static isValid(hash: string | StringValueObject): boolean;
5
- static from(buffer: Buffer | string | StringValueObject): MD5Hash;
6
+ static from(buffer: string | StringValueObject | Media | Buffer): MD5Hash;
6
7
  constructor(source: string | StringValueObject);
7
8
  }
8
9
  //# sourceMappingURL=MD5Hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MD5Hash.d.ts","sourceRoot":"","sources":["../../../src/value-objects/hashes/MD5Hash.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,qBAAa,OAAQ,SAAQ,IAAI;WACjB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO;WAIlD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,GAAG,OAAO;gBAM5D,MAAM,EAAE,MAAM,GAAG,iBAAiB;CAY/C"}
1
+ {"version":3,"file":"MD5Hash.d.ts","sourceRoot":"","sources":["../../../src/value-objects/hashes/MD5Hash.ts"],"names":[],"mapp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AE,MAAM,CAAC,OAAO,EAAE,CAAC,CAC9C,CAAC;IACJ,CAAC;CACF;AAvBD,0BAuBC"}
1
+ {"version":3,"file":"MD5Hash.js","sourceRoot":"","sources":["../../../src/value-objects/hashes/MD5Hash.ts"],"names":[],"mappings":";;;;AAAA,sEAAiC;AAEjC,oEAAiE;AACjE,6CAAwC;AAExC,8CAA2C;AAE3C,iCAA8B;AAE9B,MAAa,OAAQ,SAAQ,WAAI;IACxB,MAAM,CAAC,OAAO,CAAC,IAAgC;QACpD,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;IAEM,MAAM,CAAC,IAAI,CAChB,MAAmD;QAEnD,OAAO,IAAI,OAAO,CAChB,qBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAChE,CAAC;IACJ,CAAC;IAED,YAAY,MAAkC;QAC5C,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAEzB,IAAI,uBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAA,iBAAM,EACJ,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAC/B,IAAI,mCAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAC9C,CAAC;IACJ,CAAC;CACF;AAzBD,0BAyBC"}
@@ -1,8 +1,9 @@
1
+ import { Media } from '../media/Media';
1
2
  import { StringValueObject } from '../StringValueObject';
2
3
  import { ValueObject } from '../ValueObject';
3
4
  export declare class SHA256Hash extends ValueObject<string> {
4
5
  static isValid(hash: string | StringValueObject): boolean;
5
- static from(buffer: Buffer | string | StringValueObject): SHA256Hash;
6
+ static from(buffer: string | StringValueObject | Media | Buffer): SHA256Hash;
6
7
  constructor(source: string | StringValueObject);
7
8
  toBase64(): StringValueObject;
8
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SHA256Hash.d.ts","sourceRoot":"","sources":["../../../src/value-objects/hashes/SHA256Hash.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,UAAW,SAAQ,WAAW,CAAC,MAAM,CAAC;WACnC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO;WAIlD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,GAAG,UAAU;gBAM/D,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAavC,QAAQ,IAAI,iBAAiB;CAKrC"}
1
+ {"version":3,"file":"SHA256Hash.d.ts","sourceRoot":"","sources":["../../../src/value-objects/hashes/SHA256Hash.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,UAAW,SAAQ,WAAW,CAAC,MAAM,CAAC;WACnC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO;WAIlD,IAAI,CAChB,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAClD,UAAU;gBAMD,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAavC,QAAQ,IAAI,iBAAiB;CAKrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SHA256Hash.js","sourceRoot":"","sources":["../../../src/value-objects/hashes/SHA256Hash.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,oEAAiE;AACjE,6CAAwC;AACxC,8CAA2C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OAAO,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACnD,CAAC;IAEM,MAAM,CAAC,IAAI,CAChB,MAAmD;QAEnD,OAAO,IAAI,UAAU,CACnB,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAC5D,CAAC;IACJ,CAAC;IAED,YAAY,MAAkC;QAC5C,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAEzB,IAAI,uBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAA,iBAAM,EACJ,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAClC,IAAI,mCAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CACjD,CAAC;IACJ,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,qCAAiB,CAC1B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACtD,CAAC;IACJ,CAAC;CACF;AA/BD,gCA+BC"}
@@ -1,8 +1,9 @@
1
+ import { Media } from '../media/Media';
1
2
  import { StringValueObject } from '../StringValueObject';
2
3
  import { ValueObject } from '../ValueObject';
3
4
  export declare class SHA512Hash extends ValueObject<string> {
4
5
  static isValid(hash: string | StringValueObject): boolean;
5
- static from(buffer: Buffer | string | StringValueObject): SHA512Hash;
6
+ static from(buffer: string | StringValueObject | Media | Buffer): SHA512Hash;
6
7
  constructor(source: string | StringValueObject);
7
8
  toBase64(): StringValueObject;
8
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SHA512Hash.d.ts","sourceRoot":"","sources":["../../../src/value-objects/hashes/SHA512Hash.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,UAAW,SAAQ,WAAW,CAAC,MAAM,CAAC;WACnC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO;WAIlD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,GAAG,UAAU;gBAM/D,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAavC,QAAQ,IAAI,iBAAiB;CAKrC"}
1
+ {"version":3,"file":"SHA512Hash.d.ts","sourceRoot":"","sources":["../../../src/value-objects/hashes/SHA512Hash.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,UAAW,SAAQ,WAAW,CAAC,MAAM,CAAC;WACnC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO;WAIlD,IAAI,CAChB,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAClD,UAAU;gBAMD,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAavC,QAAQ,IAAI,iBAAiB;CAKrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SHA512Hash.js","sourceRoot":"","sources":["../../../src/value-objects/hashes/SHA512Hash.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,oEAAiE;AACjE,6CAAwC;AACxC,8CAA2C;AAC3C,4DAAyD;AACzD,gDAA6C;AAE7C,MAAa,UAAW,SAAQ,yBAAmB;IAC1C,MAAM,CAAC,OAAO,CAAC,IAAgC;QACpD,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC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AC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAC5D,CAAC;IACJ,CAAC;IAED,YAAY,MAAkC;QAC5C,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAEzB,IAAI,uBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAA,iBAAM,EACJ,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAClC,IAAI,mCAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CACjD,CAAC;IACJ,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,qCAAiB,CAC1B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACtD,CAAC;IACJ,CAAC;CACF;AA/BD,gCA+BC"}
@@ -1,6 +1,8 @@
1
1
  export * from './coordinates';
2
+ export * from './crypto';
2
3
  export * from './hashes';
3
4
  export * from './ids';
5
+ export * from './media';
4
6
  export * from './time';
5
7
  export * from './Color';
6
8
  export * from './Email';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/value-objects/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/value-objects/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./coordinates"), exports);
5
+ tslib_1.__exportStar(require("./crypto"), exports);
5
6
  tslib_1.__exportStar(require("./hashes"), exports);
6
7
  tslib_1.__exportStar(require("./ids"), exports);
8
+ tslib_1.__exportStar(require("./media"), exports);
7
9
  tslib_1.__exportStar(require("./time"), exports);
8
10
  tslib_1.__exportStar(require("./Color"), exports);
9
11
  tslib_1.__exportStar(require("./Email"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/value-objects/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,mDAAyB;AACzB,gDAAsB;AACtB,iDAAuB;AACvB,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB;AACvB,oDAA0B;AAC1B,8DAAoC;AACpC,2DAAiC;AACjC,8DAAoC;AACpC,uDAA6B;AAC7B,wDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/value-objects/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,mDAAyB;AACzB,mDAAyB;AACzB,gDAAsB;AACtB,kDAAwB;AACxB,iDAAuB;AACvB,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB;AACvB,oDAA0B;AAC1B,8DAAoC;AACpC,2DAAiC;AACjC,8DAAoC;AACpC,uDAA6B;AAC7B,wDAA8B"}
@@ -0,0 +1,8 @@
1
+ import { ValueObject } from '../ValueObject';
2
+ export declare class Media extends ValueObject<string> {
3
+ constructor(value: string | Buffer);
4
+ getBuffer(): Buffer;
5
+ getSize(): number;
6
+ getBase64(): string;
7
+ }
8
+ //# sourceMappingURL=Media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Media.d.ts","sourceRoot":"","sources":["../../../src/value-objects/media/Media.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,KAAM,SAAQ,WAAW,CAAC,MAAM,CAAC;gBAChC,KAAK,EAAE,MAAM,GAAG,MAAM;IAQ3B,SAAS,IAAI,MAAM;IAInB,OAAO,IAAI,MAAM;IAIjB,SAAS,IAAI,MAAM;CAG3B"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Media = void 0;
4
+ const NullObject_1 = require("../NullObject");
5
+ const ValueObject_1 = require("../ValueObject");
6
+ class Media extends ValueObject_1.ValueObject {
7
+ constructor(value) {
8
+ super(value?.toString());
9
+ if (NullObject_1.NullObject.isNullObject(this)) {
10
+ return this;
11
+ }
12
+ }
13
+ getBuffer() {
14
+ return Buffer.from(this.value);
15
+ }
16
+ getSize() {
17
+ return this.getBuffer().length;
18
+ }
19
+ getBase64() {
20
+ return this.getBuffer().toString('base64');
21
+ }
22
+ }
23
+ exports.Media = Media;
24
+ //# sourceMappingURL=Media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Media.js","sourceRoot":"","sources":["../../../src/value-objects/media/Media.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAC3C,gDAA6C;AAE7C,MAAa,KAAM,SAAQ,yBAAmB;IAC5C,YAAY,KAAsB;QAChC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEzB,IAAI,uBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAEM,SAAS;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC;IACjC,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACF;AApBD,sBAoBC"}
@@ -0,0 +1,2 @@
1
+ export * from './Media';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/value-objects/media/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./Media"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/value-objects/media/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haskou/value-objects",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [