@digitaldefiance/node-ecies-lib 1.1.22 → 1.1.24

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 (212) hide show
  1. package/README.md +8 -0
  2. package/package.json +6 -5
  3. package/src/constants.d.ts +32 -0
  4. package/src/constants.d.ts.map +1 -0
  5. package/src/constants.js +137 -0
  6. package/src/constants.js.map +1 -0
  7. package/src/enumerations/index.d.ts +2 -0
  8. package/src/enumerations/index.d.ts.map +1 -0
  9. package/src/enumerations/index.js +5 -0
  10. package/src/enumerations/index.js.map +1 -0
  11. package/src/enumerations/pbkdf2-profile.d.ts +9 -0
  12. package/src/enumerations/pbkdf2-profile.d.ts.map +1 -0
  13. package/src/enumerations/pbkdf2-profile.js +13 -0
  14. package/src/enumerations/pbkdf2-profile.js.map +1 -0
  15. package/src/i18n/ecies-i18n-factory.d.ts +54 -0
  16. package/src/i18n/ecies-i18n-factory.d.ts.map +1 -0
  17. package/src/i18n/ecies-i18n-factory.js +333 -0
  18. package/src/i18n/ecies-i18n-factory.js.map +1 -0
  19. package/src/i18n/{index.ts → index.d.ts} +1 -0
  20. package/src/i18n/index.d.ts.map +1 -0
  21. package/src/i18n/index.js +5 -0
  22. package/src/i18n/index.js.map +1 -0
  23. package/src/{index.ts → index.d.ts} +1 -0
  24. package/src/index.d.ts.map +1 -0
  25. package/src/index.js +11 -0
  26. package/src/index.js.map +1 -0
  27. package/src/interfaces/authenticated-cipher.d.ts +10 -0
  28. package/src/interfaces/authenticated-cipher.d.ts.map +1 -0
  29. package/src/interfaces/authenticated-cipher.js +3 -0
  30. package/src/interfaces/authenticated-cipher.js.map +1 -0
  31. package/src/interfaces/authenticated-decipher.d.ts +9 -0
  32. package/src/interfaces/authenticated-decipher.d.ts.map +1 -0
  33. package/src/interfaces/authenticated-decipher.js +3 -0
  34. package/src/interfaces/authenticated-decipher.js.map +1 -0
  35. package/src/interfaces/checksum-config.d.ts +5 -0
  36. package/src/interfaces/checksum-config.d.ts.map +1 -0
  37. package/src/interfaces/checksum-config.js +3 -0
  38. package/src/interfaces/checksum-config.js.map +1 -0
  39. package/src/interfaces/checksum-consts.d.ts +11 -0
  40. package/src/interfaces/checksum-consts.d.ts.map +1 -0
  41. package/src/interfaces/checksum-consts.js +3 -0
  42. package/src/interfaces/checksum-consts.js.map +1 -0
  43. package/src/interfaces/constants.d.ts +43 -0
  44. package/src/interfaces/constants.d.ts.map +1 -0
  45. package/src/interfaces/constants.js +3 -0
  46. package/src/interfaces/constants.js.map +1 -0
  47. package/src/interfaces/ecies-consts.d.ts +88 -0
  48. package/src/interfaces/ecies-consts.d.ts.map +1 -0
  49. package/src/interfaces/ecies-consts.js +3 -0
  50. package/src/interfaces/ecies-consts.js.map +1 -0
  51. package/src/interfaces/encryption-consts.d.ts +11 -0
  52. package/src/interfaces/encryption-consts.d.ts.map +1 -0
  53. package/src/interfaces/encryption-consts.js +3 -0
  54. package/src/interfaces/encryption-consts.js.map +1 -0
  55. package/src/interfaces/{index.ts → index.d.ts} +1 -0
  56. package/src/interfaces/index.d.ts.map +1 -0
  57. package/src/interfaces/index.js +21 -0
  58. package/src/interfaces/index.js.map +1 -0
  59. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +6 -0
  60. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -0
  61. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js +3 -0
  62. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +1 -0
  63. package/src/interfaces/keyring-consts.d.ts +6 -0
  64. package/src/interfaces/keyring-consts.d.ts.map +1 -0
  65. package/src/interfaces/keyring-consts.js +3 -0
  66. package/src/interfaces/keyring-consts.js.map +1 -0
  67. package/src/interfaces/member-operational.d.ts +36 -0
  68. package/src/interfaces/member-operational.d.ts.map +1 -0
  69. package/src/interfaces/member-operational.js +3 -0
  70. package/src/interfaces/member-operational.js.map +1 -0
  71. package/src/interfaces/{member-with-mnemonic.ts → member-with-mnemonic.d.ts} +3 -3
  72. package/src/interfaces/member-with-mnemonic.d.ts.map +1 -0
  73. package/src/interfaces/member-with-mnemonic.js +3 -0
  74. package/src/interfaces/member-with-mnemonic.js.map +1 -0
  75. package/src/interfaces/{multi-encrypted-message.ts → multi-encrypted-message.d.ts} +5 -5
  76. package/src/interfaces/multi-encrypted-message.d.ts.map +1 -0
  77. package/src/interfaces/multi-encrypted-message.js +3 -0
  78. package/src/interfaces/multi-encrypted-message.js.map +1 -0
  79. package/src/interfaces/multi-encrypted-parsed-header.d.ts +24 -0
  80. package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -0
  81. package/src/interfaces/multi-encrypted-parsed-header.js +3 -0
  82. package/src/interfaces/multi-encrypted-parsed-header.js.map +1 -0
  83. package/src/interfaces/{pbkdf-profiles.ts → pbkdf-profiles.d.ts} +2 -2
  84. package/src/interfaces/pbkdf-profiles.d.ts.map +1 -0
  85. package/src/interfaces/pbkdf-profiles.js +3 -0
  86. package/src/interfaces/pbkdf-profiles.js.map +1 -0
  87. package/src/interfaces/pbkdf2-result.d.ts +6 -0
  88. package/src/interfaces/pbkdf2-result.d.ts.map +1 -0
  89. package/src/interfaces/pbkdf2-result.js +3 -0
  90. package/src/interfaces/pbkdf2-result.js.map +1 -0
  91. package/src/interfaces/signing-key-private-key-info.d.ts +11 -0
  92. package/src/interfaces/signing-key-private-key-info.d.ts.map +1 -0
  93. package/src/interfaces/signing-key-private-key-info.js +3 -0
  94. package/src/interfaces/signing-key-private-key-info.js.map +1 -0
  95. package/src/interfaces/{simple-keypair-buffer.ts → simple-keypair-buffer.d.ts} +3 -3
  96. package/src/interfaces/simple-keypair-buffer.d.ts.map +1 -0
  97. package/src/interfaces/simple-keypair-buffer.js +3 -0
  98. package/src/interfaces/simple-keypair-buffer.js.map +1 -0
  99. package/src/interfaces/{simple-keypair.ts → simple-keypair.d.ts} +3 -3
  100. package/src/interfaces/simple-keypair.d.ts.map +1 -0
  101. package/src/interfaces/simple-keypair.js +3 -0
  102. package/src/interfaces/simple-keypair.js.map +1 -0
  103. package/src/interfaces/simple-public-key-only-buffer.d.ts +4 -0
  104. package/src/interfaces/simple-public-key-only-buffer.d.ts.map +1 -0
  105. package/src/interfaces/simple-public-key-only-buffer.js +3 -0
  106. package/src/interfaces/simple-public-key-only-buffer.js.map +1 -0
  107. package/src/interfaces/simple-public-key-only.d.ts +4 -0
  108. package/src/interfaces/simple-public-key-only.d.ts.map +1 -0
  109. package/src/interfaces/simple-public-key-only.js +3 -0
  110. package/src/interfaces/simple-public-key-only.js.map +1 -0
  111. package/src/interfaces/single-encrypted-parsed-header.d.ts +35 -0
  112. package/src/interfaces/single-encrypted-parsed-header.d.ts.map +1 -0
  113. package/src/interfaces/single-encrypted-parsed-header.js +3 -0
  114. package/src/interfaces/single-encrypted-parsed-header.js.map +1 -0
  115. package/src/interfaces/{wallet-seed.ts → wallet-seed.d.ts} +3 -3
  116. package/src/interfaces/wallet-seed.d.ts.map +1 -0
  117. package/src/interfaces/wallet-seed.js +3 -0
  118. package/src/interfaces/wallet-seed.js.map +1 -0
  119. package/src/interfaces/wrapped-key-consts.d.ts +7 -0
  120. package/src/interfaces/wrapped-key-consts.d.ts.map +1 -0
  121. package/src/interfaces/wrapped-key-consts.js +3 -0
  122. package/src/interfaces/wrapped-key-consts.js.map +1 -0
  123. package/src/member.d.ts +74 -0
  124. package/src/member.d.ts.map +1 -0
  125. package/src/member.js +273 -0
  126. package/src/member.js.map +1 -0
  127. package/src/services/aes-gcm.d.ts +66 -0
  128. package/src/services/aes-gcm.d.ts.map +1 -0
  129. package/src/services/aes-gcm.js +115 -0
  130. package/src/services/aes-gcm.js.map +1 -0
  131. package/src/services/ecies/crypto-core.d.ts +83 -0
  132. package/src/services/ecies/crypto-core.d.ts.map +1 -0
  133. package/src/services/ecies/crypto-core.js +166 -0
  134. package/src/services/ecies/crypto-core.js.map +1 -0
  135. package/src/services/ecies/file.d.ts +30 -0
  136. package/src/services/ecies/file.d.ts.map +1 -0
  137. package/src/services/ecies/file.js +112 -0
  138. package/src/services/ecies/file.js.map +1 -0
  139. package/src/services/ecies/{index.ts → index.d.ts} +1 -0
  140. package/src/services/ecies/index.d.ts.map +1 -0
  141. package/src/services/ecies/index.js +11 -0
  142. package/src/services/ecies/index.js.map +1 -0
  143. package/src/services/ecies/multi-recipient.d.ts +82 -0
  144. package/src/services/ecies/multi-recipient.d.ts.map +1 -0
  145. package/src/services/ecies/multi-recipient.js +360 -0
  146. package/src/services/ecies/multi-recipient.js.map +1 -0
  147. package/src/services/ecies/service.d.ts +70 -0
  148. package/src/services/ecies/service.d.ts.map +1 -0
  149. package/src/services/ecies/service.js +167 -0
  150. package/src/services/ecies/service.js.map +1 -0
  151. package/src/services/ecies/signature.d.ts +38 -0
  152. package/src/services/ecies/signature.d.ts.map +1 -0
  153. package/src/services/ecies/signature.js +69 -0
  154. package/src/services/ecies/signature.js.map +1 -0
  155. package/src/services/ecies/single-recipient.d.ts +85 -0
  156. package/src/services/ecies/single-recipient.d.ts.map +1 -0
  157. package/src/services/ecies/single-recipient.js +399 -0
  158. package/src/services/ecies/single-recipient.js.map +1 -0
  159. package/src/services/ecies/utilities.d.ts +22 -0
  160. package/src/services/ecies/utilities.d.ts.map +1 -0
  161. package/src/services/ecies/utilities.js +75 -0
  162. package/src/services/ecies/utilities.js.map +1 -0
  163. package/src/services/index.d.ts +4 -0
  164. package/src/services/index.d.ts.map +1 -0
  165. package/src/services/index.js +7 -0
  166. package/src/services/index.js.map +1 -0
  167. package/src/services/pbkdf2.d.ts +106 -0
  168. package/src/services/pbkdf2.d.ts.map +1 -0
  169. package/src/services/pbkdf2.js +195 -0
  170. package/src/services/pbkdf2.js.map +1 -0
  171. package/src/{types.ts → types.d.ts} +9 -26
  172. package/src/types.d.ts.map +1 -0
  173. package/src/types.js +3 -0
  174. package/src/types.js.map +1 -0
  175. package/src/utils.d.ts +11 -0
  176. package/src/utils.d.ts.map +1 -0
  177. package/src/utils.js +82 -0
  178. package/src/utils.js.map +1 -0
  179. package/LICENSE +0 -21
  180. package/src/constants.ts +0 -182
  181. package/src/enumerations/index.ts +0 -1
  182. package/src/enumerations/pbkdf2-profile.ts +0 -8
  183. package/src/i18n/ecies-i18n-factory.ts +0 -435
  184. package/src/interfaces/authenticated-cipher.ts +0 -9
  185. package/src/interfaces/authenticated-decipher.ts +0 -8
  186. package/src/interfaces/checksum-config.ts +0 -4
  187. package/src/interfaces/checksum-consts.ts +0 -13
  188. package/src/interfaces/constants.ts +0 -43
  189. package/src/interfaces/ecies-consts.ts +0 -99
  190. package/src/interfaces/encryption-consts.ts +0 -10
  191. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.ts +0 -7
  192. package/src/interfaces/keyring-consts.ts +0 -5
  193. package/src/interfaces/member-operational.ts +0 -52
  194. package/src/interfaces/multi-encrypted-parsed-header.ts +0 -24
  195. package/src/interfaces/pbkdf2-result.ts +0 -5
  196. package/src/interfaces/signing-key-private-key-info.ts +0 -12
  197. package/src/interfaces/simple-public-key-only-buffer.ts +0 -3
  198. package/src/interfaces/simple-public-key-only.ts +0 -3
  199. package/src/interfaces/single-encrypted-parsed-header.ts +0 -35
  200. package/src/interfaces/wrapped-key-consts.ts +0 -6
  201. package/src/member.ts +0 -463
  202. package/src/services/aes-gcm.ts +0 -160
  203. package/src/services/ecies/crypto-core.ts +0 -213
  204. package/src/services/ecies/file.ts +0 -174
  205. package/src/services/ecies/multi-recipient.ts +0 -583
  206. package/src/services/ecies/service.ts +0 -351
  207. package/src/services/ecies/signature.ts +0 -91
  208. package/src/services/ecies/single-recipient.ts +0 -676
  209. package/src/services/ecies/utilities.ts +0 -111
  210. package/src/services/index.ts +0 -3
  211. package/src/services/pbkdf2.ts +0 -307
  212. package/src/utils.ts +0 -104
@@ -0,0 +1,74 @@
1
+ import { EmailString, MemberErrorType, MemberType, SecureBuffer, SecureString } from '@digitaldefiance/ecies-lib';
2
+ import { Wallet } from '@ethereumjs/wallet';
3
+ /**
4
+ * Custom error classes that work with the plugin i18n system
5
+ */
6
+ export declare class NodeMemberError extends Error {
7
+ readonly type: MemberErrorType;
8
+ constructor(message: string, type: MemberErrorType);
9
+ }
10
+ import { ECIESService } from './services/ecies/service';
11
+ import { Types } from 'mongoose';
12
+ import { IMemberOperational } from './interfaces/member-operational';
13
+ import { SignatureBuffer } from './types';
14
+ /**
15
+ * A member of Brightchain.
16
+ * In the Owner Free Filesystem (OFF), members are used to:
17
+ * 1. Sign and verify data
18
+ * 2. Encrypt and decrypt data
19
+ * 3. Participate in voting
20
+ * 4. Establish ownership of data
21
+ */
22
+ export declare class Member implements IMemberOperational<Types.ObjectId> {
23
+ private readonly _eciesService;
24
+ private readonly _id;
25
+ private readonly _type;
26
+ private readonly _name;
27
+ private readonly _email;
28
+ private readonly _publicKey;
29
+ private readonly _creatorId;
30
+ private readonly _dateCreated;
31
+ private readonly _dateUpdated;
32
+ private _privateKey?;
33
+ private _wallet?;
34
+ constructor(eciesService: ECIESService, type: MemberType, name: string, email: EmailString, publicKey: Buffer, privateKey?: SecureBuffer, wallet?: Wallet, id?: Types.ObjectId, dateCreated?: Date, dateUpdated?: Date, creatorId?: Types.ObjectId);
35
+ get id(): Types.ObjectId;
36
+ get type(): MemberType;
37
+ get name(): string;
38
+ get email(): EmailString;
39
+ get publicKey(): Buffer;
40
+ get creatorId(): Types.ObjectId;
41
+ get dateCreated(): Date;
42
+ get dateUpdated(): Date;
43
+ get privateKey(): SecureBuffer | undefined;
44
+ get wallet(): Wallet;
45
+ get hasPrivateKey(): boolean;
46
+ unloadPrivateKey(): void;
47
+ unloadWallet(): void;
48
+ unloadWalletAndPrivateKey(): void;
49
+ loadWallet(mnemonic: SecureString): void;
50
+ /**
51
+ * Loads the private key and optionally the voting private key.
52
+ *
53
+ * @param privateKey The private key to load.
54
+ * @param votingPrivateKey The voting private key to load.
55
+ */
56
+ loadPrivateKey(privateKey: SecureBuffer): void;
57
+ sign(data: Buffer): SignatureBuffer;
58
+ signData(data: Buffer): SignatureBuffer;
59
+ verify(signature: SignatureBuffer, data: Buffer): boolean;
60
+ verifySignature(data: Buffer, signature: Buffer, publicKey: Buffer): boolean;
61
+ private static readonly MAX_ENCRYPTION_SIZE;
62
+ private static readonly VALID_STRING_REGEX;
63
+ encryptData(data: string | Buffer, recipientPublicKey?: Buffer): Buffer;
64
+ decryptData(encryptedData: Buffer): Buffer;
65
+ toJson(): string;
66
+ dispose(): void;
67
+ static fromJson(json: string, eciesService: ECIESService): Member;
68
+ static fromMnemonic(mnemonic: SecureString, eciesService: ECIESService, memberType?: MemberType, name?: string, email?: EmailString): Member;
69
+ static newMember(eciesService: ECIESService, type: MemberType, name: string, email: EmailString, forceMnemonic?: SecureString, createdBy?: Types.ObjectId): {
70
+ member: Member;
71
+ mnemonic: SecureString;
72
+ };
73
+ }
74
+ //# sourceMappingURL=member.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"member.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/member.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EAEX,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAM5C;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aACK,IAAI,EAAE,eAAe;gBAAtD,OAAO,EAAE,MAAM,EAAkB,IAAI,EAAE,eAAe;CAInE;AAED,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;GAOG;AACH,qBAAa,MAAO,YAAW,kBAAkB,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC/D,OAAO,CAAC,QAAQ,CAAC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/src/member.js ADDED
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Member = exports.NodeMemberError = void 0;
4
+ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
5
+ const ecies_i18n_factory_1 = require("./i18n/ecies-i18n-factory");
6
+ /**
7
+ * Custom error classes that work with the plugin i18n system
8
+ */
9
+ class NodeMemberError extends Error {
10
+ type;
11
+ constructor(message, type) {
12
+ super(message);
13
+ this.type = type;
14
+ this.name = 'NodeMemberError';
15
+ }
16
+ }
17
+ exports.NodeMemberError = NodeMemberError;
18
+ // Removed: import { ServiceProvider } from './services/service.provider';
19
+ const mongodb_1 = require("mongodb");
20
+ /**
21
+ * A member of Brightchain.
22
+ * In the Owner Free Filesystem (OFF), members are used to:
23
+ * 1. Sign and verify data
24
+ * 2. Encrypt and decrypt data
25
+ * 3. Participate in voting
26
+ * 4. Establish ownership of data
27
+ */
28
+ class Member {
29
+ _eciesService;
30
+ _id;
31
+ _type;
32
+ _name;
33
+ _email;
34
+ _publicKey;
35
+ _creatorId;
36
+ _dateCreated;
37
+ _dateUpdated;
38
+ _privateKey;
39
+ _wallet;
40
+ constructor(
41
+ // Add injected services as parameters
42
+ eciesService,
43
+ // Original parameters
44
+ type, name, email, publicKey, privateKey, wallet, id, dateCreated, dateUpdated, creatorId) {
45
+ // Assign injected services
46
+ this._eciesService = eciesService;
47
+ // Assign original parameters
48
+ this._type = type;
49
+ this._id = id ?? new mongodb_1.ObjectId();
50
+ this._name = name;
51
+ if (!this._name || this._name.length == 0) {
52
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_MissingMemberName), ecies_lib_1.MemberErrorType.MissingMemberName);
53
+ }
54
+ if (this._name.trim() != this._name) {
55
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_InvalidMemberNameWhitespace), ecies_lib_1.MemberErrorType.InvalidMemberNameWhitespace);
56
+ }
57
+ this._email = email;
58
+ this._publicKey = publicKey;
59
+ this._privateKey = privateKey;
60
+ this._wallet = wallet;
61
+ // don't create a new date object with nearly identical values to the existing one
62
+ let _now = null;
63
+ const now = function () {
64
+ if (!_now) {
65
+ _now = new Date();
66
+ }
67
+ return _now;
68
+ };
69
+ this._dateCreated = dateCreated ?? now();
70
+ this._dateUpdated = dateUpdated ?? now();
71
+ this._creatorId = creatorId ?? this._id;
72
+ }
73
+ // Required getters
74
+ get id() {
75
+ return this._id;
76
+ }
77
+ get type() {
78
+ return this._type;
79
+ }
80
+ get name() {
81
+ return this._name;
82
+ }
83
+ get email() {
84
+ return this._email;
85
+ }
86
+ get publicKey() {
87
+ return this._publicKey;
88
+ }
89
+ get creatorId() {
90
+ return this._creatorId;
91
+ }
92
+ get dateCreated() {
93
+ return this._dateCreated;
94
+ }
95
+ get dateUpdated() {
96
+ return this._dateUpdated;
97
+ }
98
+ // Optional private data getters
99
+ get privateKey() {
100
+ return this._privateKey;
101
+ }
102
+ get wallet() {
103
+ if (!this._wallet) {
104
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_NoWallet), ecies_lib_1.MemberErrorType.NoWallet);
105
+ }
106
+ return this._wallet;
107
+ }
108
+ // State getters
109
+ get hasPrivateKey() {
110
+ return this._privateKey !== undefined;
111
+ }
112
+ unloadPrivateKey() {
113
+ // Do not dispose here; tests expect the same SecureBuffer instance to remain usable
114
+ // when reloaded into another member in the same process.
115
+ this._privateKey = undefined;
116
+ }
117
+ unloadWallet() {
118
+ this._wallet = undefined;
119
+ }
120
+ unloadWalletAndPrivateKey() {
121
+ this.unloadWallet();
122
+ this.unloadPrivateKey();
123
+ }
124
+ loadWallet(mnemonic) {
125
+ if (this._wallet) {
126
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_WalletAlreadyLoaded), ecies_lib_1.MemberErrorType.WalletAlreadyLoaded);
127
+ }
128
+ const { wallet } = this._eciesService.walletAndSeedFromMnemonic(mnemonic);
129
+ const privateKey = wallet.getPrivateKey();
130
+ const publicKey = wallet.getPublicKey();
131
+ const publicKeyWithPrefix = Buffer.concat([
132
+ Buffer.from([ecies_lib_1.ECIES.PUBLIC_KEY_MAGIC]),
133
+ publicKey,
134
+ ]);
135
+ if (publicKeyWithPrefix.toString('hex') !== this._publicKey.toString('hex')) {
136
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_InvalidMnemonic), ecies_lib_1.MemberErrorType.InvalidMnemonic);
137
+ }
138
+ this._wallet = wallet;
139
+ this._privateKey = new ecies_lib_1.SecureBuffer(privateKey);
140
+ }
141
+ /**
142
+ * Loads the private key and optionally the voting private key.
143
+ *
144
+ * @param privateKey The private key to load.
145
+ * @param votingPrivateKey The voting private key to load.
146
+ */
147
+ loadPrivateKey(privateKey) {
148
+ this._privateKey = privateKey;
149
+ }
150
+ sign(data) {
151
+ if (!this._privateKey) {
152
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_MissingPrivateKey), ecies_lib_1.MemberErrorType.MissingPrivateKey);
153
+ }
154
+ return this._eciesService.signMessage(Buffer.from(this._privateKey.value), data);
155
+ }
156
+ signData(data) {
157
+ if (!this._privateKey) {
158
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_MissingPrivateKey), ecies_lib_1.MemberErrorType.MissingPrivateKey);
159
+ }
160
+ return this._eciesService.signMessage(Buffer.from(this._privateKey.value), data);
161
+ }
162
+ verify(signature, data) {
163
+ return this._eciesService.verifyMessage(this._publicKey, data, signature);
164
+ }
165
+ verifySignature(data, signature, publicKey) {
166
+ return this._eciesService.verifyMessage(publicKey, data, signature);
167
+ }
168
+ static MAX_ENCRYPTION_SIZE = 1024 * 1024 * 10; // 10MB limit
169
+ static VALID_STRING_REGEX = /^[\x20-\x7E\n\r\t]*$/; // Printable ASCII + common whitespace
170
+ encryptData(data, recipientPublicKey) {
171
+ // Validate input
172
+ if (!data) {
173
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_MissingEncryptionData), ecies_lib_1.MemberErrorType.MissingEncryptionData);
174
+ }
175
+ // Check size limit
176
+ const dataSize = Buffer.isBuffer(data)
177
+ ? data.length
178
+ : Buffer.byteLength(data);
179
+ if (dataSize > Member.MAX_ENCRYPTION_SIZE) {
180
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_EncryptionDataTooLarge), ecies_lib_1.MemberErrorType.EncryptionDataTooLarge);
181
+ }
182
+ // Create buffer from data
183
+ const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data);
184
+ // Use recipient public key or self public key
185
+ const targetPublicKey = recipientPublicKey || this._publicKey;
186
+ return this._eciesService.encryptSimpleOrSingle(false, targetPublicKey, bufferData);
187
+ }
188
+ decryptData(encryptedData) {
189
+ if (!this._privateKey) {
190
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_MissingPrivateKey), ecies_lib_1.MemberErrorType.MissingPrivateKey);
191
+ }
192
+ // decryptSingleWithHeader now returns the Buffer directly
193
+ return this._eciesService.decryptSimpleOrSingleWithHeader(false, Buffer.from(this._privateKey.value), encryptedData);
194
+ }
195
+ toJson() {
196
+ const storage = {
197
+ id: this._id.toString(),
198
+ type: this._type,
199
+ name: this._name,
200
+ email: this._email.toString(),
201
+ publicKey: this._publicKey.toString('base64'),
202
+ creatorId: this._creatorId.toString(),
203
+ dateCreated: this._dateCreated.toISOString(),
204
+ dateUpdated: this._dateUpdated.toISOString(),
205
+ };
206
+ return JSON.stringify(storage);
207
+ }
208
+ dispose() {
209
+ // Ensure secret material is zeroized when disposing
210
+ try {
211
+ this._privateKey?.dispose();
212
+ }
213
+ finally {
214
+ this.unloadWalletAndPrivateKey();
215
+ }
216
+ }
217
+ static fromJson(json,
218
+ // Add injected services as parameters
219
+ eciesService) {
220
+ const storage = JSON.parse(json);
221
+ const email = new ecies_lib_1.EmailString(storage.email);
222
+ // Pass injected services to constructor
223
+ const dateCreated = new Date(storage.dateCreated);
224
+ return new Member(eciesService, storage.type, storage.name, email, Buffer.from(storage.publicKey, 'base64'), undefined, undefined, new mongodb_1.ObjectId(storage.id), dateCreated, new Date(storage.dateUpdated), new mongodb_1.ObjectId(storage.creatorId));
225
+ }
226
+ static fromMnemonic(mnemonic, eciesService, memberType = ecies_lib_1.MemberType.User, name = 'Test User', email = new ecies_lib_1.EmailString('test@example.com')) {
227
+ const { wallet } = eciesService.walletAndSeedFromMnemonic(mnemonic);
228
+ const privateKey = wallet.getPrivateKey();
229
+ const publicKeyWithPrefix = Buffer.concat([
230
+ Buffer.from([ecies_lib_1.ECIES.PUBLIC_KEY_MAGIC]),
231
+ wallet.getPublicKey(),
232
+ ]);
233
+ return new Member(eciesService, memberType, name, email, publicKeyWithPrefix, new ecies_lib_1.SecureBuffer(privateKey), wallet);
234
+ }
235
+ static newMember(
236
+ // Add injected services as parameters
237
+ eciesService,
238
+ // Original parameters
239
+ type, name, email, forceMnemonic, createdBy) {
240
+ // Validate inputs first
241
+ if (!name || name.length == 0) {
242
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_MissingMemberName), ecies_lib_1.MemberErrorType.MissingMemberName);
243
+ }
244
+ if (name.trim() != name) {
245
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_InvalidMemberNameWhitespace), ecies_lib_1.MemberErrorType.InvalidMemberNameWhitespace);
246
+ }
247
+ if (!email || email.toString().length == 0) {
248
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_MissingEmail), ecies_lib_1.MemberErrorType.MissingEmail);
249
+ }
250
+ if (email.toString().trim() != email.toString()) {
251
+ throw new NodeMemberError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Member_InvalidEmailWhitespace), ecies_lib_1.MemberErrorType.InvalidEmailWhitespace);
252
+ }
253
+ // Use injected services
254
+ const mnemonic = forceMnemonic ?? eciesService.generateNewMnemonic();
255
+ const { wallet } = eciesService.walletAndSeedFromMnemonic(mnemonic);
256
+ // Get private key from wallet
257
+ const privateKey = wallet.getPrivateKey();
258
+ // Get public key with 0x04 prefix
259
+ const publicKeyWithPrefix = Buffer.concat([
260
+ Buffer.from([ecies_lib_1.ECIES.PUBLIC_KEY_MAGIC]),
261
+ wallet.getPublicKey(),
262
+ ]);
263
+ const newId = new mongodb_1.ObjectId();
264
+ const dateCreated = new Date();
265
+ return {
266
+ // Pass injected services to constructor
267
+ member: new Member(eciesService, type, name, email, publicKeyWithPrefix, new ecies_lib_1.SecureBuffer(privateKey), wallet, newId, dateCreated, dateCreated, createdBy ?? newId),
268
+ mnemonic,
269
+ };
270
+ }
271
+ }
272
+ exports.Member = Member;
273
+ //# sourceMappingURL=member.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"member.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/member.ts"],"names":[],"mappings":";;;AAAA,0DAQoC;AAEpC,kEAGmC;AAEnC;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACK;IAA7C,YAAY,OAAe,EAAkB,IAAqB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI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B,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,IAAI,kBAAQ,EAAE,CAAC;QAC7B,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;QAC/B,OAAO;YACL,wCAAwC;YACxC,MAAM,EAAE,IAAI,MAAM,CAChB,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,mBAAmB,EACnB,IAAI,wBAAY,CAAC,UAAU,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,WAAW,EACX,WAAW,EACX,SAAS,IAAI,KAAK,CACnB;YACD,QAAQ;SACT,CAAC;IACJ,CAAC;;AAraH,wBAsaC"}
@@ -0,0 +1,66 @@
1
+ import { IConstants } from '../interfaces/constants';
2
+ export declare class AESGCMService {
3
+ private readonly algorithmName;
4
+ private readonly mode;
5
+ private readonly keyBits;
6
+ private readonly ivSize;
7
+ private readonly keyringAlgorithmConfiguration;
8
+ constructor(constants?: IConstants);
9
+ get ALGORITHM_NAME(): string;
10
+ get MODE(): string;
11
+ get KEY_BITS(): number;
12
+ /**
13
+ * Encrypt data using AES-GCM
14
+ * @param data Data to encrypt
15
+ * @param key Key to use for encryption (must be 16, 24 or 32 bytes for AES)
16
+ * @param authTag Whether to return separate auth tag
17
+ * @returns Encrypted data with IV and optional separate auth tag
18
+ */
19
+ encrypt(data: Buffer, key: Buffer, authTag?: boolean): {
20
+ encrypted: Buffer;
21
+ iv: Buffer;
22
+ tag?: Buffer;
23
+ };
24
+ /**
25
+ * Combine encrypted data and auth tag into a single Buffer
26
+ * @param encryptedData The encrypted data
27
+ * @param authTag The authentication tag
28
+ * @returns The combined Buffer
29
+ */
30
+ combineEncryptedDataAndTag(encryptedData: Buffer, authTag: Buffer): Buffer;
31
+ /**
32
+ * Combine IV and encrypted data (with optional auth tag) into a single Buffer
33
+ * @param iv The initialization vector
34
+ * @param encryptedDataWithTag The encrypted data with auth tag already appended (if applicable)
35
+ * @returns The combined Buffer
36
+ */
37
+ combineIvAndEncryptedData(iv: Buffer, encryptedDataWithTag: Buffer): Buffer;
38
+ /**
39
+ * Combine IV, encrypted data and auth tag into a single Buffer
40
+ * @param iv The initialization vector
41
+ * @param encryptedData The encrypted data
42
+ * @param authTag The authentication tag
43
+ * @returns The combined Buffer
44
+ */
45
+ combineIvTagAndEncryptedData(iv: Buffer, encryptedData: Buffer, authTag: Buffer): Buffer;
46
+ /**
47
+ * Split combined encrypted data back into its components
48
+ * @param combinedData The combined data containing IV, encrypted data, and optionally auth tag
49
+ * @param hasAuthTag Whether the combined data includes an authentication tag
50
+ * @returns Object containing the split components
51
+ */
52
+ splitEncryptedData(combinedData: Buffer, hasAuthTag?: boolean): {
53
+ iv: Buffer;
54
+ encryptedDataWithTag: Buffer;
55
+ };
56
+ /**
57
+ * Decrypt data using AES-GCM
58
+ * @param iv The initialization vector
59
+ * @param encryptedData Data to decrypt (with auth tag appended)
60
+ * @param key Key to use for decryption (must be 16, 24 or 32 bytes for AES)
61
+ * @param authTag Whether the encrypted data includes an authentication tag
62
+ * @returns Decrypted data
63
+ */
64
+ decrypt(iv: Buffer, encryptedData: Buffer, key: Buffer, authTag?: boolean): Buffer;
65
+ }
66
+ //# sourceMappingURL=aes-gcm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/aes-gcm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIrD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAiB;gBAEnD,SAAS,GAAE,UAAsB;IAQ7C,IAAW,cAAc,IAAI,MAAM,CAElC;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED;;;;;;OAMG;IACI,OAAO,CACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,OAAe,GACvB;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE;IAmBlD;;;;;OAKG;IACI,0BAA0B,CAC/B,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,MAAM;IAIT;;;;;OAKG;IACI,yBAAyB,CAC9B,EAAE,EAAE,MAAM,EACV,oBAAoB,EAAE,MAAM,GAC3B,MAAM;IAIT;;;;;;OAMG;IACI,4BAA4B,CACjC,EAAE,EAAE,MAAM,EACV,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,MAAM;IAQT;;;;;OAKG;IACI,kBAAkB,CACvB,YAAY,EAAE,MAAM,EACpB,UAAU,GAAE,OAAc,GACzB;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAA;KAAE;IAkB/C;;;;;;;OAOG;IACI,OAAO,CACZ,EAAE,EAAE,MAAM,EACV,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,OAAe,GACvB,MAAM;CAWV"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AESGCMService = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const i18n_1 = require("../i18n");
6
+ const constants_1 = require("../constants");
7
+ class AESGCMService {
8
+ algorithmName;
9
+ mode;
10
+ keyBits;
11
+ ivSize;
12
+ keyringAlgorithmConfiguration;
13
+ constructor(constants = constants_1.Constants) {
14
+ this.algorithmName = constants.KEYRING.ALGORITHM;
15
+ this.mode = constants.KEYRING.MODE;
16
+ this.keyBits = constants.KEYRING.KEY_BITS;
17
+ this.ivSize = constants.WRAPPED_KEY.IV_SIZE;
18
+ this.keyringAlgorithmConfiguration = constants.KEYRING_ALGORITHM_CONFIGURATION;
19
+ }
20
+ get ALGORITHM_NAME() {
21
+ return this.algorithmName;
22
+ }
23
+ get MODE() {
24
+ return this.mode;
25
+ }
26
+ get KEY_BITS() {
27
+ return this.keyBits;
28
+ }
29
+ /**
30
+ * Encrypt data using AES-GCM
31
+ * @param data Data to encrypt
32
+ * @param key Key to use for encryption (must be 16, 24 or 32 bytes for AES)
33
+ * @param authTag Whether to return separate auth tag
34
+ * @returns Encrypted data with IV and optional separate auth tag
35
+ */
36
+ encrypt(data, key, authTag = false) {
37
+ const iv = (0, crypto_1.randomBytes)(this.ivSize);
38
+ const cipher = (0, crypto_1.createCipheriv)(this.keyringAlgorithmConfiguration, key, iv);
39
+ const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
40
+ const tag = cipher.getAuthTag();
41
+ if (!authTag) {
42
+ const encryptedWithTag = Buffer.concat([encrypted, tag]);
43
+ return { encrypted: encryptedWithTag, iv: iv };
44
+ }
45
+ return {
46
+ encrypted: encrypted,
47
+ iv: iv,
48
+ tag: tag,
49
+ };
50
+ }
51
+ /**
52
+ * Combine encrypted data and auth tag into a single Buffer
53
+ * @param encryptedData The encrypted data
54
+ * @param authTag The authentication tag
55
+ * @returns The combined Buffer
56
+ */
57
+ combineEncryptedDataAndTag(encryptedData, authTag) {
58
+ return Buffer.concat([encryptedData, authTag]);
59
+ }
60
+ /**
61
+ * Combine IV and encrypted data (with optional auth tag) into a single Buffer
62
+ * @param iv The initialization vector
63
+ * @param encryptedDataWithTag The encrypted data with auth tag already appended (if applicable)
64
+ * @returns The combined Buffer
65
+ */
66
+ combineIvAndEncryptedData(iv, encryptedDataWithTag) {
67
+ return Buffer.concat([iv, encryptedDataWithTag]);
68
+ }
69
+ /**
70
+ * Combine IV, encrypted data and auth tag into a single Buffer
71
+ * @param iv The initialization vector
72
+ * @param encryptedData The encrypted data
73
+ * @param authTag The authentication tag
74
+ * @returns The combined Buffer
75
+ */
76
+ combineIvTagAndEncryptedData(iv, encryptedData, authTag) {
77
+ const encryptedWithTag = this.combineEncryptedDataAndTag(encryptedData, authTag);
78
+ return this.combineIvAndEncryptedData(iv, encryptedWithTag);
79
+ }
80
+ /**
81
+ * Split combined encrypted data back into its components
82
+ * @param combinedData The combined data containing IV, encrypted data, and optionally auth tag
83
+ * @param hasAuthTag Whether the combined data includes an authentication tag
84
+ * @returns Object containing the split components
85
+ */
86
+ splitEncryptedData(combinedData, hasAuthTag = true) {
87
+ const ivLength = this.ivSize;
88
+ const minLength = ivLength + (hasAuthTag ? 16 : 0);
89
+ if (combinedData.length < minLength) {
90
+ const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
91
+ throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_CombinedDataTooShort));
92
+ }
93
+ const iv = combinedData.subarray(0, ivLength);
94
+ const encryptedDataWithTag = combinedData.subarray(ivLength);
95
+ return { iv, encryptedDataWithTag };
96
+ }
97
+ /**
98
+ * Decrypt data using AES-GCM
99
+ * @param iv The initialization vector
100
+ * @param encryptedData Data to decrypt (with auth tag appended)
101
+ * @param key Key to use for decryption (must be 16, 24 or 32 bytes for AES)
102
+ * @param authTag Whether the encrypted data includes an authentication tag
103
+ * @returns Decrypted data
104
+ */
105
+ decrypt(iv, encryptedData, key, authTag = false) {
106
+ const decipher = (0, crypto_1.createDecipheriv)(this.keyringAlgorithmConfiguration, key, iv);
107
+ const tagLength = 16;
108
+ const tag = encryptedData.subarray(-tagLength);
109
+ const ciphertext = encryptedData.subarray(0, -tagLength);
110
+ decipher.setAuthTag(tag);
111
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
112
+ }
113
+ }
114
+ exports.AESGCMService = AESGCMService;
115
+ //# sourceMappingURL=aes-gcm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes-gcm.js","sourceR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,EAAE,yBAAkB,CAAC,0BAA0B,CAAC,CAC5F,CAAC;QACJ,CAAC;QAED,MAAM,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC9C,MAAM,oBAAoB,GAAG,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAE7D,OAAO,EAAE,EAAE,EAAE,oBAAoB,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACI,OAAO,CACZ,EAAU,EACV,aAAqB,EACrB,GAAW,EACX,UAAmB,KAAK;QAExB,MAAM,QAAQ,GAAG,IAAA,yBAAgB,EAAC,IAAI,CAAC,6BAA6B,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAE/E,MAAM,SAAS,GAAG,EAAE,CAAC;QACrB,MAAM,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;QAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;QAEzD,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAEzB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AAzJD,sCAyJC"}
@@ -0,0 +1,83 @@
1
+ import { IECIESConfig, IECIESConstants, SecureString } from '@digitaldefiance/ecies-lib';
2
+ import { Wallet } from '@ethereumjs/wallet';
3
+ import { ISimpleKeyPairBuffer } from '../../interfaces/simple-keypair-buffer';
4
+ import { IWalletSeed } from '../../interfaces/wallet-seed';
5
+ /**
6
+ * Core encryption and decryption functions for ECIES
7
+ * Includes coverage for simple and single modes, does not cover multiple mode which is in a separate module
8
+ */
9
+ export declare class EciesCryptoCore {
10
+ protected readonly _config: IECIESConfig;
11
+ protected readonly _consts: IECIESConstants;
12
+ get config(): IECIESConfig;
13
+ get consts(): IECIESConstants;
14
+ constructor(config: IECIESConfig, eciesParams?: IECIESConstants);
15
+ /**
16
+ * Validates and normalizes a public key for ECIES operations
17
+ * @param publicKey The public key to normalize
18
+ * @returns Properly formatted public key
19
+ */
20
+ normalizePublicKey(publicKey: Buffer): Buffer;
21
+ /**
22
+ * Generate a new mnemonic
23
+ * @returns {SecureString} The new mnemonic
24
+ */
25
+ generateNewMnemonic(): SecureString;
26
+ /**
27
+ * Generate a new wallet from a seed
28
+ * @param seed {Buffer} The seed to generate the wallet from
29
+ * @returns {Wallet} The new wallet
30
+ */
31
+ walletFromSeed(seed: Buffer): Wallet;
32
+ /**
33
+ * Generate a new wallet and seed from a mnemonic
34
+ * @param mnemonic {SecureString} The mnemonic to generate the wallet and seed from
35
+ * @returns {IWalletSeed} The new wallet and seed
36
+ */
37
+ walletAndSeedFromMnemonic(mnemonic: SecureString): IWalletSeed;
38
+ /**
39
+ * Generate a new wallet and seed from a mnemonic
40
+ * @param wallet {Wallet} The wallet to generate the key pair from
41
+ * @returns {ISimpleKeyPairBuffer} The new key pair
42
+ */
43
+ walletToSimpleKeyPairBuffer(wallet: Wallet): ISimpleKeyPairBuffer;
44
+ /**
45
+ * Create a simple key pair from a seed
46
+ * @param seed {Buffer} The seed to generate the key pair from
47
+ * @returns {ISimpleKeyPairBuffer} The new key pair
48
+ */
49
+ seedToSimpleKeyPairBuffer(seed: Buffer): ISimpleKeyPairBuffer;
50
+ /**
51
+ * Create a simple key pair from a mnemonic
52
+ * @param mnemonic {SecureString} The mnemonic to generate the key pair from
53
+ * @returns {ISimpleKeyPairBuffer} The new key pair
54
+ */
55
+ mnemonicToSimpleKeyPairBuffer(mnemonic: SecureString): ISimpleKeyPairBuffer;
56
+ /**
57
+ * Generate a random private key
58
+ * @returns {Buffer} The new private key
59
+ */
60
+ generatePrivateKey(): Buffer;
61
+ /**
62
+ * Get public key from private key
63
+ * @param privateKey {Buffer} The private key
64
+ * @returns {Buffer} The public key
65
+ */
66
+ getPublicKey(privateKey: Buffer): Buffer;
67
+ /**
68
+ * Generate ephemeral key pair for ECIES
69
+ * @returns {Promise<ISimpleKeyPairBuffer>} The key pair
70
+ */
71
+ generateEphemeralKeyPair(): Promise<{
72
+ privateKey: Buffer;
73
+ publicKey: Buffer;
74
+ }>;
75
+ /**
76
+ * Compute ECDH shared secret
77
+ * @param privateKey {Buffer} The private key
78
+ * @param publicKey {Buffer} The public key
79
+ * @returns {Buffer} The shared secret
80
+ */
81
+ computeSharedSecret(privateKey: Buffer, publicKey: Buffer): Buffer;
82
+ }
83
+ //# sourceMappingURL=crypto-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-core.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/crypto-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,eAAe,EAEf,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAS,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAInD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D;;;GAGG;AACH,qBAAa,eAAe;IAC1B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAC5C,IAAW,MAAM,IAAI,YAAY,CAEhC;IAED,IAAW,MAAM,IAAI,eAAe,CAEnC;gBAEW,MAAM,EAAE,YAAY,EAAE,WAAW,GAAE,eAAiC;IAKhF;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAiDpD;;;OAGG;IACI,mBAAmB,IAAI,YAAY;IAI1C;;;;OAIG;IACI,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAO3C;;;;OAIG;IACI,yBAAyB,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