@requestnetwork/transaction-manager 0.26.1-next.1351 → 0.26.1-next.710

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  `@requestnetwork/transaction-manager` is a typescript library part of the [Request Network protocol](https://github.com/RequestNetwork/requestNetwork).
4
4
  It is the default implementation of the Transaction layer. It creates transactions to be sent to Data Access.
5
- When privacy is implemented, this package will handle the encryption
5
+ When privacy is implemented, this package will handle the encryption.
6
6
 
7
7
  ## Installation
8
8
 
@@ -17,7 +17,7 @@ npm install @requestnetwork/transaction-manager
17
17
  In order to decrypt encrypted transactions, you must provide a decryption provider.
18
18
  You can see the specification of decryption provider [here](./specs/decryption-provider.md).
19
19
 
20
- An example of implementation of a decryption provider is available in the package: [epk-decryption](../../epk-decryption)
20
+ An example of implementation of a decryption provider is available in the package: [epk-decryption](../epk-decryption/)
21
21
 
22
22
  ```javascript
23
23
  import EthereumPrivateKeyDecryptionProvider from '@requestnetwork/epk-decryption';
@@ -50,7 +50,7 @@ const transactionManager = new TransactionManager(dataAccess);
50
50
 
51
51
  const data = '{ what: "ever", it: "is,", this: "must", work: true }';
52
52
  const channelId = 'myRequest';
53
- const channelTopics = ['stakeholder1','stakeholder2'];
53
+ const channelTopics = ['stakeholder1', 'stakeholder2'];
54
54
 
55
55
  const { result } = await transactionManager.persistTransaction(data, channelId, channelTopics);
56
56
  ```
@@ -103,7 +103,9 @@ const transactionManager = new TransactionManager(dataAccess, decryptionProvider
103
103
 
104
104
  const channelId = 'myRequest';
105
105
 
106
- const { result: {transactions} } = await transactionManager.getTransactionsByChannelId(channelId);
106
+ const {
107
+ result: { transactions },
108
+ } = await transactionManager.getTransactionsByChannelId(channelId);
107
109
  ```
108
110
 
109
111
  ### Get Transactions from topic
@@ -20,11 +20,11 @@ export default class ChannelParser {
20
20
  /**
21
21
  * Get channel type and channel key from a list of transactions (if applicable)
22
22
  *
23
- * @param channelId the channelId of the channel
23
+ * @param _channelId the channelId of the channel
24
24
  * @param transactions the transactions of the channel to decrypt and clean
25
25
  * @returns Promise resolving the channel type and the channel key (if applicable)
26
26
  */
27
- getChannelTypeAndChannelKey(channelId: string, transactions: TransactionTypes.ITimestampedTransaction[]): Promise<{
27
+ getChannelTypeAndChannelKey(_channelId: string, transactions: TransactionTypes.ITimestampedTransaction[]): Promise<{
28
28
  channelType: TransactionTypes.ChannelType;
29
29
  channelKey: EncryptionTypes.IDecryptionParameters | undefined;
30
30
  encryptionMethod: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"channel-parser.d.ts","sourceRoot":"","sources":["../src/channel-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAInG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,iBAAiB,CAAqB;gBAE3B,kBAAkB,CAAC,EAAE,uBAAuB,CAAC,mBAAmB;IAGnF;;;;;;OAMG;IACU,sBAAsB,CACjC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,gBAAgB,CAAC,uBAAuB,EAAE,GACvD,OAAO,CAAC;QACT,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;QACrC,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAC;QACrE,mBAAmB,EAAE,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;KACzE,CAAC;IAiHF;;;;;;OAMG;IACU,2BAA2B,CACtC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,gBAAgB,CAAC,uBAAuB,EAAE,GACvD,OAAO,CAAC;QACT,WAAW,EAAE,gBAAgB,CAAC,WAAW,CAAC;QAC1C,UAAU,EAAE,eAAe,CAAC,qBAAqB,GAAG,SAAS,CAAC;QAC9D,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;KACtC,CAAC;CAwEH"}
1
+ {"version":3,"file":"channel-parser.d.ts","sourceRoot":"","sources":["../src/channel-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAInG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,iBAAiB,CAAqB;gBAE3B,kBAAkB,CAAC,EAAE,uBAAuB,CAAC,mBAAmB;IAGnF;;;;;;OAMG;IACU,sBAAsB,CACjC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,gBAAgB,CAAC,uBAAuB,EAAE,GACvD,OAAO,CAAC;QACT,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;QACrC,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAC;QACrE,mBAAmB,EAAE,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;KACzE,CAAC;IA8GF;;;;;;OAMG;IACU,2BAA2B,CAEtC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,gBAAgB,CAAC,uBAAuB,EAAE,GACvD,OAAO,CAAC;QACT,WAAW,EAAE,gBAAgB,CAAC,WAAW,CAAC;QAC1C,UAAU,EAAE,eAAe,CAAC,qBAAqB,GAAG,SAAS,CAAC;QAC9D,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;KACtC,CAAC;CA8EH"}
@@ -1,14 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
12
4
  const types_1 = require("@requestnetwork/types");
13
5
  const transactions_parser_1 = require("./transactions-parser");
14
6
  /**
@@ -26,17 +18,18 @@ class ChannelParser {
26
18
  * @returns Promise resolving the kept transactions and the ignored ones with the reason
27
19
  */
28
20
  decryptAndCleanChannel(channelId, transactions) {
29
- return __awaiter(this, void 0, void 0, function* () {
21
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
22
  let channelType = types_1.TransactionTypes.ChannelType.UNKNOWN;
31
- let channelKey;
32
23
  let encryptionMethod;
24
+ // Search for channel key
25
+ const { channelKey } = yield this.getChannelTypeAndChannelKey(channelId, transactions);
33
26
  // use of .reduce instead of .map to keep a sequential execution
34
- const validAndIgnoredTransactions = yield transactions.reduce((accumulatorPromise, timestampedTransaction) => __awaiter(this, void 0, void 0, function* () {
27
+ const validAndIgnoredTransactions = yield transactions.reduce((accumulatorPromise, timestampedTransaction) => tslib_1.__awaiter(this, void 0, void 0, function* () {
35
28
  const result = yield accumulatorPromise;
36
29
  let parsedData;
37
30
  try {
38
31
  // Parse the transaction from data-access to get a transaction object and the channel key if encrypted
39
- parsedData = yield this.transactionParser.parsePersistedTransaction(timestampedTransaction.transaction, channelType, channelKey);
32
+ parsedData = yield this.transactionParser.parsePersistedTransaction(timestampedTransaction.transaction, channelType, channelKey, encryptionMethod);
40
33
  }
41
34
  catch (error) {
42
35
  return result.concat([
@@ -78,12 +71,10 @@ class ChannelParser {
78
71
  ]);
79
72
  }
80
73
  // from the first valid transaction, we can deduce the type of the channel
81
- channelType = !!parsedData.channelKey
74
+ channelType = parsedData.channelKey
82
75
  ? types_1.TransactionTypes.ChannelType.ENCRYPTED
83
76
  : types_1.TransactionTypes.ChannelType.CLEAR;
84
77
  encryptionMethod = parsedData.encryptionMethod;
85
- // we keep the channelKey for this channel
86
- channelKey = parsedData.channelKey;
87
78
  }
88
79
  const data = yield transaction.getData();
89
80
  // add the decrypted transaction as valid
@@ -111,25 +102,33 @@ class ChannelParser {
111
102
  /**
112
103
  * Get channel type and channel key from a list of transactions (if applicable)
113
104
  *
114
- * @param channelId the channelId of the channel
105
+ * @param _channelId the channelId of the channel
115
106
  * @param transactions the transactions of the channel to decrypt and clean
116
107
  * @returns Promise resolving the channel type and the channel key (if applicable)
117
108
  */
118
- getChannelTypeAndChannelKey(channelId, transactions) {
119
- return __awaiter(this, void 0, void 0, function* () {
109
+ getChannelTypeAndChannelKey(
110
+ // TODO: Consider removing channelId argument
111
+ _channelId, transactions) {
112
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
120
113
  // use of .reduce instead of .map to keep a sequential execution
121
- const channelTypeAndKey = yield transactions.reduce((accumulatorPromise, timestampedTransaction) => __awaiter(this, void 0, void 0, function* () {
114
+ const channelTypeAndKey = yield transactions.reduce((accumulatorPromise, timestampedTransaction) => tslib_1.__awaiter(this, void 0, void 0, function* () {
122
115
  const result = yield accumulatorPromise;
123
- // if we know the channel type, we skip the remaining transactions
124
- if (result.channelType !== types_1.TransactionTypes.ChannelType.UNKNOWN) {
116
+ // Skip remaining transactions if channel is CLEAR or after channelKey is found
117
+ if (result.channelType === types_1.TransactionTypes.ChannelType.CLEAR || result.channelKey) {
125
118
  return result;
126
119
  }
127
120
  let parsedData;
128
121
  try {
129
122
  // Parse the transaction from data-access to get a transaction object and the channel key if encrypted
130
- parsedData = yield this.transactionParser.parsePersistedTransaction(timestampedTransaction.transaction, types_1.TransactionTypes.ChannelType.UNKNOWN);
123
+ parsedData = yield this.transactionParser.parsePersistedTransaction(timestampedTransaction.transaction, result.channelType, result.channelKey, result.encryptionMethod);
131
124
  }
132
125
  catch (error) {
126
+ // If the transaction is encrypted but the channel key is not found, save channelType and encryptionMethod
127
+ if (error.message.startsWith('Impossible to decrypt the channel key from this transaction') &&
128
+ result.channelType === types_1.TransactionTypes.ChannelType.UNKNOWN) {
129
+ result.channelType = types_1.TransactionTypes.ChannelType.ENCRYPTED;
130
+ result.encryptionMethod = timestampedTransaction.transaction.encryptionMethod;
131
+ }
133
132
  // Error during the parsing, we just ignore this transaction
134
133
  return result;
135
134
  }
@@ -140,14 +139,8 @@ class ChannelParser {
140
139
  // Error in the transaction, we just ignore it
141
140
  return result;
142
141
  }
143
- // check if the data hash matches the channel id
144
- const hash = yield transaction.getHash();
145
- if (hash !== channelId) {
146
- // we just ignored it
147
- return result;
148
- }
149
142
  // We can deduce the type of the channel
150
- result.channelType = !!parsedData.channelKey
143
+ result.channelType = parsedData.channelKey
151
144
  ? types_1.TransactionTypes.ChannelType.ENCRYPTED
152
145
  : types_1.TransactionTypes.ChannelType.CLEAR;
153
146
  // we keep the channelKey for this channel
@@ -1 +1 @@
1
- {"version":3,"file":"channel-parser.js","sourceRoot":"","sources":["../src/channel-parser.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iDAAmG;AAEnG,+DAAuD;AAEvD;;GAEG;AACH,MAAqB,aAAa;IAGhC,YAAmB,kBAAgE;QACjF,IAAI,CAAC,iBAAiB,GAAG,IAAI,6BAAkB,CAAC,kBAAkB,CAAC,CAAC;IACtE,CAAC;IACD;;;;;;OAMG;IACU,sBAAsB,CACjC,SAAiB,EACjB,YAAwD;;YAMxD,IAAI,WAAW,GAAiC,wBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC;YACrF,IAAI,UAA6D,CAAC;YAClE,IAAI,gBAAoC,CAAC;YAOzC,gEAAgE;YAChE,MAAM,2BAA2B,GAAmC,MAAM,YAAY,CAAC,MAAM,CAC3F,CACE,kBAA2D,EAC3D,sBAAgE,EAChE,EAAE;gBACF,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC;gBAExC,IAAI,UAAU,CAAC;gBACf,IAAI;oBACF,sGAAsG;oBACtG,UAAU,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,yBAAyB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W,CAAC,QAAQ,EAAE,CAAC;gBAC3C,IAAI,KAAK,KAAK,EAAE,EAAE;oBAChB,8CAA8C;oBAC9C,OAAO,MAAM,CAAC;iBACf;gBAED,wCAAwC;gBACxC,MAAM,CAAC,WAAW,GAAG,UAAU,CAAC,UAAU;oBACxC,CAAC,CAAC,wBAAgB,CAAC,WAAW,CAAC,SAAS;oBACxC,CAAC,CAAC,wBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC;gBAEvC,0CAA0C;gBAC1C,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;gBAE1C,iDAAiD;gBACjD,MAAM,CAAC,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,CAAC;gBAEtD,OAAO,MAAM,CAAC;YAChB,CAAC,CAAA,EACD,OAAO,CAAC,OAAO,CAAC;gBACd,UAAU,EAAE,SAAS;gBACrB,WAAW,EAAE,wBAAgB,CAAC,WAAW,CAAC,OAAO;gBACjD,gBAAgB,EAAE,SAAS;aAC5B,CAAC,CACH,CAAC;YAEF,OAAO,iBAAiB,CAAC;QAC3B,CAAC;KAAA;CACF;AA/ND,gCA+NC"}
@@ -1,15 +1,7 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const multi_format_1 = require("@requestnetwork/multi-format");
3
+ const tslib_1 = require("tslib");
4
+ const MultiFormat = require("@requestnetwork/multi-format");
13
5
  const utils_1 = require("@requestnetwork/utils");
14
6
  /**
15
7
  * Class representing a clear transaction
@@ -24,7 +16,7 @@ class ClearTransaction {
24
16
  * @returns a promise resolving the transaction data
25
17
  */
26
18
  getData() {
27
- return __awaiter(this, void 0, void 0, function* () {
19
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
20
  return this.data;
29
21
  });
30
22
  }
@@ -34,8 +26,8 @@ class ClearTransaction {
34
26
  * @returns a promise resolving the transaction data hash
35
27
  */
36
28
  getHash() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- return multi_format_1.default.serialize(utils_1.default.crypto.normalizeKeccak256Hash(JSON.parse(this.data)));
29
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
+ return MultiFormat.serialize((0, utils_1.normalizeKeccak256Hash)(JSON.parse(this.data)));
39
31
  });
40
32
  }
41
33
  /**
@@ -44,7 +36,7 @@ class ClearTransaction {
44
36
  * @returns a promise resolving a string of the error if any, otherwise an empty string
45
37
  */
46
38
  getError() {
47
- return __awaiter(this, void 0, void 0, function* () {
39
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
48
40
  try {
49
41
  JSON.parse(this.data);
50
42
  return '';
@@ -1 +1 @@
1
- {"version":3,"file":"clear-transaction.js","sourceRoot":"","sources":["../src/clear-transaction.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAuD;AAEvD,iDAA0C;AAE1C;;GAEG;AACH,MAAqB,gBAAgB;IAGnC,YAAY,IAAuC;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACU,OAAO;;YAClB,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;KAAA;IAED;;;;OAIG;IACU,OAAO;;YAClB,OAAO,sBAAW,CAAC,SAAS,CAAC,eAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3F,CAAC;KAAA;IAED;;;;OAIG;IACU,QAAQ;;YACnB,IAAI;gBACF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtB,OAAO,EAAE,CAAC;aACX;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,0CAA0C,CAAC;aACnD;QACH,CAAC;KAAA;CACF;AAtCD,mCAsCC"}
1
+ {"version":3,"file":"clear-transaction.js","sourceRoot":"","sources":["../src/clear-transaction.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAE5D,iDAA+D;AAE/D;;GAEG;AACH,MAAqB,gBAAgB;IAGnC,YAAY,IAAuC;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACU,OAAO;;YAClB,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;KAAA;IAED;;;;OAIG;IACU,OAAO;;YAClB,OAAO,WAAW,CAAC,SAAS,CAAC,IAAA,8BAAsB,EAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC9E,CAAC;KAAA;IAED;;;;OAIG;IACU,QAAQ;;YACnB,IAAI;gBACF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtB,OAAO,EAAE,CAAC;aACX;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,0CAA0C,CAAC;aACnD;QACH,CAAC;KAAA;CACF;AAtCD,mCAsCC"}
@@ -1 +1 @@
1
- {"version":3,"file":"encrypted-transaction.d.ts","sourceRoot":"","sources":["../src/encrypted-transaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG1E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,gBAAgB,CAAC,YAAY;IAChF,4DAA4D;IAC5D,OAAO,CAAC,IAAI,CAAyC;IAErD,mFAAmF;IACnF,OAAO,CAAC,kBAAkB,CAAc;IAExC,qBAAqB;IACrB,OAAO,CAAC,aAAa,CAAoC;IAEzD,gDAAgD;IAChD,OAAO,CAAC,UAAU,CAAwC;IAE1D;;;;OAIG;gBAED,aAAa,EAAE,gBAAgB,CAAC,gBAAgB,EAChD,UAAU,EAAE,eAAe,CAAC,qBAAqB;IAMnD;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC;IAYlE;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAavC;;;;OAIG;IACU,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;CAczC"}
1
+ {"version":3,"file":"encrypted-transaction.d.ts","sourceRoot":"","sources":["../src/encrypted-transaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG1E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,gBAAgB,CAAC,YAAY;IAChF,4DAA4D;IAC5D,OAAO,CAAC,IAAI,CAAyC;IAErD,mFAAmF;IACnF,OAAO,CAAC,kBAAkB,CAAM;IAEhC,qBAAqB;IACrB,OAAO,CAAC,aAAa,CAAoC;IAEzD,gDAAgD;IAChD,OAAO,CAAC,UAAU,CAAwC;IAE1D;;;;OAIG;gBAED,aAAa,EAAE,gBAAgB,CAAC,gBAAgB,EAChD,UAAU,EAAE,eAAe,CAAC,qBAAqB;IAMnD;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC;IAYlE;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAavC;;;;OAIG;IACU,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;CAczC"}
@@ -1,15 +1,7 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const multi_format_1 = require("@requestnetwork/multi-format");
3
+ const tslib_1 = require("tslib");
4
+ const MultiFormat = require("@requestnetwork/multi-format");
13
5
  const utils_1 = require("@requestnetwork/utils");
14
6
  /**
15
7
  * Class representing an encrypted transaction
@@ -34,11 +26,11 @@ class EncryptedTransaction {
34
26
  * @returns a promise resolving the transaction data
35
27
  */
36
28
  getData() {
37
- return __awaiter(this, void 0, void 0, function* () {
29
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
30
  if (this.data === '') {
39
31
  try {
40
- const encryptedData = multi_format_1.default.deserialize(this.persistedData);
41
- this.data = yield utils_1.default.encryption.decrypt(encryptedData, this.channelKey);
32
+ const encryptedData = MultiFormat.deserialize(this.persistedData);
33
+ this.data = yield (0, utils_1.decrypt)(encryptedData, this.channelKey);
42
34
  }
43
35
  catch (_a) {
44
36
  throw new Error('Impossible to decrypt the transaction');
@@ -53,12 +45,12 @@ class EncryptedTransaction {
53
45
  * @returns a promise resolving the transaction data hash
54
46
  */
55
47
  getHash() {
56
- return __awaiter(this, void 0, void 0, function* () {
48
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
57
49
  if (this.dataHashSerialized === '') {
58
50
  const data = yield this.getData();
59
51
  try {
60
- const dataHash = yield utils_1.default.crypto.normalizeKeccak256Hash(JSON.parse(data));
61
- this.dataHashSerialized = multi_format_1.default.serialize(dataHash);
52
+ const dataHash = (0, utils_1.normalizeKeccak256Hash)(JSON.parse(data));
53
+ this.dataHashSerialized = MultiFormat.serialize(dataHash);
62
54
  }
63
55
  catch (e) {
64
56
  throw new Error('Impossible to JSON parse the decrypted transaction data');
@@ -73,7 +65,7 @@ class EncryptedTransaction {
73
65
  * @returns a promise resolving a string of the error if any, otherwise an empty string
74
66
  */
75
67
  getError() {
76
- return __awaiter(this, void 0, void 0, function* () {
68
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
77
69
  let data = '';
78
70
  try {
79
71
  data = yield this.getData();
@@ -1 +1 @@
1
- {"version":3,"file":"encrypted-transaction.js","sourceRoot":"","sources":["../src/encrypted-transaction.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAuD;AAEvD,iDAA0C;AAE1C;;GAEG;AACH,MAAqB,oBAAoB;IAavC;;;;OAIG;IACH,YACE,aAAgD,EAChD,UAAiD;QAnBnD,4DAA4D;QACpD,SAAI,GAAsC,EAAE,CAAC;QAErD,mFAAmF;QAC3E,uBAAkB,GAAW,EAAE,CAAC;QAiBtC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACU,OAAO;;YAClB,IAAI,IAAI,CAAC,IAAI,KAAK,EAAE,EAAE;gBACpB,IAAI;oBACF,MAAM,aAAa,GAAG,sBAAW,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;oBAClE,IAAI,CAAC,IAAI,GAAG,MAAM,eAAK,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;iBAC5E;gBAAC,WAAM;oBACN,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;iBAC1D;aACF;YACD,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;KAAA;IAED;;;;OAIG;IACU,OAAO;;YAClB,IAAI,IAAI,CAAC,kBAAkB,KAAK,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClC,IAAI;oBACF,MAAM,QAAQ,GAA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AM,CAAC,OAAO,OAAO,kBAAmB,YAAW,gBAAgB,CAAC,mBAAmB;IACrF,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,aAAa,CAAgB;gBAGnC,UAAU,EAAE,eAAe,CAAC,WAAW,EACvC,kBAAkB,CAAC,EAAE,uBAAuB,CAAC,mBAAmB;IAMlE;;;;;;;;;OASG;IACU,kBAAkB,CAC7B,eAAe,EAAE,gBAAgB,CAAC,gBAAgB,EAClD,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,MAAM,EAAO,EACrB,gBAAgB,GAAE,eAAe,CAAC,qBAAqB,EAAO,GAC7D,OAAO,CAAC,gBAAgB,CAAC,yBAAyB,CAAC;IA8FtD;;;;;;;;OAQG;IACU,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,mBAAmB,CAAC,EAAE,gBAAgB,CAAC,oBAAoB,GAC1D,OAAO,CAAC,gBAAgB,CAAC,sBAAsB,CAAC;IA4BnD;;;;;;OAMG;IACU,kBAAkB,CAC7B,KAAK,EAAE,MAAM,EACb,cAAc,CAAC,EAAE,gBAAgB,CAAC,oBAAoB,GACrD,OAAO,CAAC,gBAAgB,CAAC,gCAAgC,CAAC;IAM7D;;;;;;OAMG;IACU,2BAA2B,CACtC,MAAM,EAAE,MAAM,EAAE,EAChB,cAAc,CAAC,EAAE,gBAAgB,CAAC,oBAAoB,GACrD,OAAO,CAAC,gBAAgB,CAAC,gCAAgC,CAAC;IAM7D;;;;;OAKG;YACW,qBAAqB;CA6BpC"}
@@ -1,15 +1,7 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const multi_format_1 = require("@requestnetwork/multi-format");
3
+ const tslib_1 = require("tslib");
4
+ const MultiFormat = require("@requestnetwork/multi-format");
13
5
  const types_1 = require("@requestnetwork/types");
14
6
  const utils_1 = require("@requestnetwork/utils");
15
7
  const events_1 = require("events");
@@ -34,11 +26,11 @@ class TransactionManager {
34
26
  * @returns object containing the meta-data of the persist
35
27
  */
36
28
  persistTransaction(transactionData, channelId, topics = [], encryptionParams = []) {
37
- return __awaiter(this, void 0, void 0, function* () {
29
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
30
  let transaction = {};
39
31
  let channelEncryptionMethod;
40
32
  // compute hash to add it to the topics
41
- const hash = multi_format_1.default.serialize(utils_1.default.crypto.normalizeKeccak256Hash(JSON.parse(transactionData)));
33
+ const hash = MultiFormat.serialize((0, utils_1.normalizeKeccak256Hash)(JSON.parse(transactionData)));
42
34
  // Need to create a new channel (only the first transaction can have the hash equals to the channel id)
43
35
  if (channelId === hash) {
44
36
  if (encryptionParams.length === 0) {
@@ -54,7 +46,7 @@ class TransactionManager {
54
46
  }
55
47
  else {
56
48
  const resultGetTx = yield this.dataAccess.getTransactionsByChannelId(channelId);
57
- const { channelKey, channelType, encryptionMethod, } = yield this.channelParser.getChannelTypeAndChannelKey(channelId, resultGetTx.result.transactions);
49
+ const { channelKey, channelType, encryptionMethod } = yield this.channelParser.getChannelTypeAndChannelKey(channelId, resultGetTx.result.transactions);
58
50
  if (channelType === types_1.TransactionTypes.ChannelType.UNKNOWN) {
59
51
  throw new Error(`Impossible to retrieve the channel: ${channelId}`);
60
52
  }
@@ -63,14 +55,10 @@ class TransactionManager {
63
55
  transaction = yield transactions_factory_1.default.createClearTransaction(transactionData);
64
56
  }
65
57
  if (channelType === types_1.TransactionTypes.ChannelType.ENCRYPTED) {
66
- // we cannot add new stakeholders to an existing channel
67
- if (encryptionParams.length !== 0) {
68
- throw new Error('Impossible to add new stakeholder to an existing channel');
69
- }
70
58
  if (!channelKey) {
71
59
  throw new Error(`Impossible to decrypt the channel key of: ${channelId}`);
72
60
  }
73
- transaction = yield transactions_factory_1.default.createEncryptedTransaction(transactionData, channelKey);
61
+ transaction = yield transactions_factory_1.default.createEncryptedTransaction(transactionData, channelKey, encryptionParams);
74
62
  channelEncryptionMethod = encryptionMethod;
75
63
  }
76
64
  }
@@ -82,6 +70,8 @@ class TransactionManager {
82
70
  meta: {
83
71
  dataAccessMeta: persistResult.meta,
84
72
  encryptionMethod: channelEncryptionMethod,
73
+ transactionData: transaction,
74
+ topics: topics.concat([hash]),
85
75
  },
86
76
  result: {},
87
77
  });
@@ -98,7 +88,7 @@ class TransactionManager {
98
88
  // propagate the confirmation
99
89
  result.emit('confirmed', resultAfterConfirmation);
100
90
  })
101
- .on('error', error => {
91
+ .on('error', (error) => {
102
92
  result.emit('error', error);
103
93
  });
104
94
  return result;
@@ -114,10 +104,10 @@ class TransactionManager {
114
104
  * @returns list of transactions of the channel
115
105
  */
116
106
  getTransactionsByChannelId(channelId, timestampBoundaries) {
117
- return __awaiter(this, void 0, void 0, function* () {
107
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
118
108
  const resultGetTx = yield this.dataAccess.getTransactionsByChannelId(channelId, timestampBoundaries);
119
109
  // Decrypts and cleans the channel from the data-access layers
120
- const { transactions, ignoredTransactions, encryptionMethod, } = yield this.channelParser.decryptAndCleanChannel(channelId, resultGetTx.result.transactions);
110
+ const { transactions, ignoredTransactions, encryptionMethod } = yield this.channelParser.decryptAndCleanChannel(channelId, resultGetTx.result.transactions);
121
111
  const meta = {
122
112
  dataAccessMeta: resultGetTx.meta,
123
113
  encryptionMethod,
@@ -142,7 +132,7 @@ class TransactionManager {
142
132
  * @returns list of channels indexed by topic
143
133
  */
144
134
  getChannelsByTopic(topic, updatedBetween) {
145
- return __awaiter(this, void 0, void 0, function* () {
135
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
146
136
  const resultGetTx = yield this.dataAccess.getChannelsByTopic(topic, updatedBetween);
147
137
  return this.parseMultipleChannels(resultGetTx);
148
138
  });
@@ -155,7 +145,7 @@ class TransactionManager {
155
145
  * @returns list of channels indexed by topics
156
146
  */
157
147
  getChannelsByMultipleTopics(topics, updatedBetween) {
158
- return __awaiter(this, void 0, void 0, function* () {
148
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
159
149
  const resultGetTx = yield this.dataAccess.getChannelsByMultipleTopics(topics, updatedBetween);
160
150
  return this.parseMultipleChannels(resultGetTx);
161
151
  });
@@ -167,9 +157,9 @@ class TransactionManager {
167
157
  * @returns decrypted and cleaned channels in the right format
168
158
  */
169
159
  parseMultipleChannels(resultGetTx) {
170
- return __awaiter(this, void 0, void 0, function* () {
160
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
171
161
  // Get the channels from the data-access layers to decrypt and clean them one by one
172
- const result = yield Object.keys(resultGetTx.result.transactions).reduce((accumulatorPromise, channelId) => __awaiter(this, void 0, void 0, function* () {
162
+ const result = yield Object.keys(resultGetTx.result.transactions).reduce((accumulatorPromise, channelId) => tslib_1.__awaiter(this, void 0, void 0, function* () {
173
163
  const cleaned = yield this.channelParser.decryptAndCleanChannel(channelId, resultGetTx.result.transactions[channelId]);
174
164
  // await for the accumulator promise at the end to parallelize the calls to decryptAndCleanChannel()
175
165
  const accumulator = yield accumulatorPromise;
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-manager.js","sourceRoot":"","sources":["../src/transaction-manager.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAuD;AACvD,iDAK+B;AAC/B,iDAA0C;AAE1C,mCAAsC;AAEtC,qDAA6C;AAC7C,iEAAyD;AAEzD;;GAEG;AACH,MAAqB,kBAAkB;IAIrC,YACE,UAAuC,EACvC,kBAAgE;QAEhE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CA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,UAAU,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;YAE9F,OAAO,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QACjD,CAAC;KAAA;IAED;;;;;OAKG;IACW,qBAAqB,CACjC,WAAsD;;YAEtD,oFAAoF;YACpF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CACtE,CAAO,kBAAkB,EAAE,SAAS,EAAE,EAAE;gBACtC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,sBAAsB,CAC7D,SAAS,EACT,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAC3C,CAAC;gBAEF,oGAAoG;gBACpG,MAAM,WAAW,GAAQ,MAAM,kBAAkB,CAAC;gBAElD,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;gBAC3D,WAAW,CAAC,mBAAmB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC;gBACzE,OAAO,WAAW,CAAC;YACrB,CAAC,CAAA,EACD,OAAO,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAAE,EAAE,CAAC,CAC/D,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE;oBACJ,cAAc,EAAE,WAAW,CAAC,IAAI;oBAChC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;iBAChD;gBACD,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE;aAC9C,CAAC;QACJ,CAAC;KAAA;CACF;AApOD,qCAoOC"}
@@ -23,8 +23,10 @@ export default class TransactionsFactory {
23
23
  *
24
24
  * @param data The data to create the transaction with
25
25
  * @param channelKey Channel key use to encrypt the transaction
26
+ * @param encryptionParams Array of additional encryption parameters to encrypt the key with
27
+
26
28
  * @returns the encrypted transaction
27
29
  */
28
- static createEncryptedTransaction(data: TransactionTypes.ITransactionData, channelKey: EncryptionTypes.IEncryptionParameters): Promise<TransactionTypes.IPersistedTransaction>;
30
+ static createEncryptedTransaction(data: TransactionTypes.ITransactionData, channelKey: EncryptionTypes.IEncryptionParameters, encryptionParams?: EncryptionTypes.IEncryptionParameters[]): Promise<TransactionTypes.IPersistedTransaction>;
29
31
  }
30
32
  //# sourceMappingURL=transactions-factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactions-factory.d.ts","sourceRoot":"","sources":["../src/transactions-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG1E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC;;;;;OAKG;WACiB,sBAAsB,CACxC,IAAI,EAAE,gBAAgB,CAAC,gBAAgB,GACtC,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC;IAUlD;;;;;;OAMG;WACiB,sCAAsC,CACxD,IAAI,EAAE,gBAAgB,CAAC,gBAAgB,EACvC,gBAAgB,EAAE,eAAe,CAAC,qBAAqB,EAAE,GACxD,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC;IAyElD;;;;;;OAMG;WACiB,0BAA0B,CAC5C,IAAI,EAAE,gBAAgB,CAAC,gBAAgB,EACvC,UAAU,EAAE,eAAe,CAAC,qBAAqB,GAChD,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC;CAsBnD"}
1
+ {"version":3,"file":"transactions-factory.d.ts","sourceRoot":"","sources":["../src/transactions-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAO1E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC;;;;;OAKG;WACiB,sBAAsB,CACxC,IAAI,EAAE,gBAAgB,CAAC,gBAAgB,GACtC,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC;IAUlD;;;;;;OAMG;WACiB,sCAAsC,CACxD,IAAI,EAAE,gBAAgB,CAAC,gBAAgB,EACvC,gBAAgB,EAAE,eAAe,CAAC,qBAAqB,EAAE,GACxD,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC;IAuElD;;;;;;;;OAQG;WACiB,0BAA0B,CAC5C,IAAI,EAAE,gBAAgB,CAAC,gBAAgB,EACvC,UAAU,EAAE,eAAe,CAAC,qBAAqB,EACjD,gBAAgB,GAAE,eAAe,CAAC,qBAAqB,EAAO,GAC7D,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC;CAyEnD"}
@@ -1,15 +1,7 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const multi_format_1 = require("@requestnetwork/multi-format");
3
+ const tslib_1 = require("tslib");
4
+ const MultiFormat = require("@requestnetwork/multi-format");
13
5
  const types_1 = require("@requestnetwork/types");
14
6
  const utils_1 = require("@requestnetwork/utils");
15
7
  /**
@@ -23,7 +15,7 @@ class TransactionsFactory {
23
15
  * @returns the transaction
24
16
  */
25
17
  static createClearTransaction(data) {
26
- return __awaiter(this, void 0, void 0, function* () {
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
19
  try {
28
20
  JSON.parse(data);
29
21
  }
@@ -41,13 +33,13 @@ class TransactionsFactory {
41
33
  * @returns the encrypted transaction
42
34
  */
43
35
  static createEncryptedTransactionInNewChannel(data, encryptionParams) {
44
- return __awaiter(this, void 0, void 0, function* () {
36
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
45
37
  // format encryption method property
46
38
  const encryptionMethod = `${types_1.EncryptionTypes.METHOD.ECIES}-${types_1.EncryptionTypes.METHOD.AES256_GCM}`;
47
39
  // Generate a key for the AES encryption
48
- const symmetricKey = yield utils_1.default.crypto.generate32BufferKey();
40
+ const symmetricKey = yield (0, utils_1.generate32BufferKey)();
49
41
  // Encrypt the data with the key and the AES256-GCM algorithm
50
- const encryptedData = yield utils_1.default.encryption.encrypt(data, {
42
+ const encryptedData = yield (0, utils_1.encrypt)(data, {
51
43
  key: symmetricKey,
52
44
  method: types_1.EncryptionTypes.METHOD.AES256_GCM,
53
45
  });
@@ -62,20 +54,20 @@ class TransactionsFactory {
62
54
  throw new Error(`encryptionParams method must be all: ${types_1.EncryptionTypes.METHOD.ECIES}`);
63
55
  }
64
56
  // Compute key encryption and identity hash for every encryption parameters given
65
- const encryptedKeyAndIdentityHashesPromises = encryptionParams.map((encryptionParam) => __awaiter(this, void 0, void 0, function* () {
66
- const encryptedKey = yield utils_1.default.encryption.encrypt(symmetricKey, encryptionParam);
67
- const identityEncryption = utils_1.default.encryption.getIdentityFromEncryptionParams(encryptionParam);
68
- const multiFormattedIdentity = multi_format_1.default.serialize(identityEncryption);
57
+ const encryptedKeyAndIdentityHashesPromises = encryptionParams.map((encryptionParam) => tslib_1.__awaiter(this, void 0, void 0, function* () {
58
+ const encryptedKey = yield (0, utils_1.encrypt)(symmetricKey, encryptionParam);
59
+ const identityEncryption = (0, utils_1.getIdentityFromEncryptionParams)(encryptionParam);
60
+ const multiFormattedIdentity = MultiFormat.serialize(identityEncryption);
69
61
  return { encryptedKey, multiFormattedIdentity };
70
62
  }));
71
63
  const encryptedKeyAndIdentityHashes = yield Promise.all(encryptedKeyAndIdentityHashesPromises);
72
64
  // Create the encrypted keys object - Encrypted keys indexed by identity multi-format
73
65
  const keys = encryptedKeyAndIdentityHashes.reduce((allKeys, keyAndHash) => {
74
- const encryptedKeySerialized = multi_format_1.default.serialize(keyAndHash.encryptedKey);
66
+ const encryptedKeySerialized = MultiFormat.serialize(keyAndHash.encryptedKey);
75
67
  allKeys[keyAndHash.multiFormattedIdentity] = encryptedKeySerialized;
76
68
  return allKeys;
77
69
  }, {});
78
- const encryptedDataSerialized = multi_format_1.default.serialize(encryptedData);
70
+ const encryptedDataSerialized = MultiFormat.serialize(encryptedData);
79
71
  return { encryptedData: encryptedDataSerialized, keys, encryptionMethod };
80
72
  });
81
73
  }
@@ -84,24 +76,50 @@ class TransactionsFactory {
84
76
  *
85
77
  * @param data The data to create the transaction with
86
78
  * @param channelKey Channel key use to encrypt the transaction
79
+ * @param encryptionParams Array of additional encryption parameters to encrypt the key with
80
+
87
81
  * @returns the encrypted transaction
88
82
  */
89
- static createEncryptedTransaction(data, channelKey) {
90
- return __awaiter(this, void 0, void 0, function* () {
83
+ static createEncryptedTransaction(data, channelKey, encryptionParams = []) {
84
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
91
85
  // check if the encryption method is the good one
92
86
  if (channelKey.method !== types_1.EncryptionTypes.METHOD.AES256_GCM) {
93
87
  throw new Error(`encryption method not supported for the channel key: ${channelKey.method}`);
94
88
  }
95
89
  // Encrypt the data with the key and the AES256-GCM algorithm
96
- const encryptedData = yield utils_1.default.encryption.encrypt(data, channelKey);
90
+ const encryptedData = yield (0, utils_1.encrypt)(data, channelKey);
97
91
  try {
98
92
  JSON.parse(data);
99
93
  }
100
94
  catch (error) {
101
95
  throw new Error('Data not parsable');
102
96
  }
103
- const encryptedDataSerialized = multi_format_1.default.serialize(encryptedData);
104
- return { encryptedData: encryptedDataSerialized };
97
+ const encryptedDataSerialized = MultiFormat.serialize(encryptedData);
98
+ if (encryptionParams.length === 0) {
99
+ return { encryptedData: encryptedDataSerialized };
100
+ }
101
+ else {
102
+ // FIXME: Refactor, duplicated from createEncryptedTransactionInNewChannel
103
+ // Check that all the encryption parameters given are ECIES (the only encryption method supported for now)
104
+ if (!encryptionParams.every((encryptionParam) => encryptionParam.method === types_1.EncryptionTypes.METHOD.ECIES)) {
105
+ throw new Error(`encryptionParams method must be all: ${types_1.EncryptionTypes.METHOD.ECIES}`);
106
+ }
107
+ // Compute key encryption and identity hash for every encryption parameters given
108
+ const encryptedKeyAndIdentityHashesPromises = encryptionParams.map((encryptionParam) => tslib_1.__awaiter(this, void 0, void 0, function* () {
109
+ const encryptedKey = yield (0, utils_1.encrypt)(channelKey.key, encryptionParam);
110
+ const identityEncryption = (0, utils_1.getIdentityFromEncryptionParams)(encryptionParam);
111
+ const multiFormattedIdentity = MultiFormat.serialize(identityEncryption);
112
+ return { encryptedKey, multiFormattedIdentity };
113
+ }));
114
+ const encryptedKeyAndIdentityHashes = yield Promise.all(encryptedKeyAndIdentityHashesPromises);
115
+ // Create the encrypted keys object - Encrypted keys indexed by identity multi-format
116
+ const keys = encryptedKeyAndIdentityHashes.reduce((allKeys, keyAndHash) => {
117
+ const encryptedKeySerialized = MultiFormat.serialize(keyAndHash.encryptedKey);
118
+ allKeys[keyAndHash.multiFormattedIdentity] = encryptedKeySerialized;
119
+ return allKeys;
120
+ }, {});
121
+ return { encryptedData: encryptedDataSerialized, keys };
122
+ }
105
123
  });
106
124
  }
107
125
  }