@@ -6,10 +6,12 @@ import { MultiFormatTypes } from '@requestnetwork/types';
6
6
export default {
7
7
formatAes256cbcEncryption,
8
8
formatEciesEncryption,
9
+ formatIdentityEthereumAddress,
9
10
formatKeccak256Hash,
10
11
formatPlainText,
11
12
isAes256cbcEncryption,
12
13
isEciesEncryption,
14
+ isIdentityEthereumAddress,
13
15
isKeccak256Hash,
14
16
isPlainText,
15
17
removePadding,
@@ -19,7 +21,7 @@ export default {
19
21
* Formats a plain text
20
22
*
21
23
* @param data data to format in plain text
22
- * @returns the data with the right prefix ('00' )
24
+ * @returns the data with the right prefix (MultiFormatTypes.prefix.PLAIN_TEXT )
23
25
*/
24
26
function formatPlainText ( data : string ) : string {
25
27
return `${ MultiFormatTypes . prefix . PLAIN_TEXT } ${ data } ` ;
@@ -39,7 +41,7 @@ function isPlainText(formattedData: string): boolean {
39
41
* Transforms a keccak256 to a multi-format keccak256
40
42
*
41
43
* @param hash to format
42
- * @returns format the hash replacing the prefix '0x' by '01'
44
+ * @returns format the hash replacing the prefix '0x' by MultiFormatTypes.prefix.NORMALIZE_KECCAK256_HASH
43
45
*/
44
46
function formatKeccak256Hash ( hash : string ) : string {
45
47
if ( hash . length !== MultiFormatTypes . FORMAT_NORMALIZE_KECCAK256_HASH_LENGTH ) {
@@ -65,7 +67,7 @@ function isKeccak256Hash(formattedData: string): boolean {
65
67
* Transforms an ECIES encrypted data to a multi-format
66
68
*
67
69
* @param encryptedData encrypted data to format
68
- * @returns format the encrypted data adding the prefix '02'
70
+ * @returns format the encrypted data adding the prefix MultiFormatTypes.prefix.ECIES_ENCRYPTED
69
71
*/
70
72
function formatEciesEncryption ( encryptedData : string ) : string {
71
73
return `${ MultiFormatTypes . prefix . ECIES_ENCRYPTED } ${ encryptedData } ` ;
@@ -85,7 +87,7 @@ function isEciesEncryption(formattedData: string): boolean {
85
87
* Transforms an AES256-cbc encrypted data to a multi-format
86
88
*
87
89
* @param encryptedData encrypted data to format
88
- * @returns format the encrypted data adding the prefix '03'
90
+ * @returns format the encrypted data adding the prefix MultiFormatTypes.prefix.AES256_CBC_ENCRYPTED
89
91
*/
90
92
function formatAes256cbcEncryption ( encryptedData : string ) : string {
91
93
return `${ MultiFormatTypes . prefix . AES256_CBC_ENCRYPTED } ${ encryptedData } ` ;
@@ -101,6 +103,29 @@ function isAes256cbcEncryption(formattedData: string): boolean {
101
103
return formattedData . slice ( 0 , 2 ) === MultiFormatTypes . prefix . AES256_CBC_ENCRYPTED ;
102
104
}
103
105
106
+ /**
107
+ * Transforms an ethereum address to a multi-format
108
+ *
109
+ * @param ethereumAddress ethereum address to format
110
+ * @returns format the encrypted data adding the prefix MultiFormatTypes.prefix.IDENTITY_ETHEREUM_ADDRESS
111
+ */
112
+ function formatIdentityEthereumAddress ( ethereumAddress : string ) : string {
113
+ return `${ MultiFormatTypes . prefix . IDENTITY_ETHEREUM_ADDRESS } ${ ethereumAddress . slice ( 2 ) } ` ;
114
+ }
115
+
116
+ /**
117
+ * Checks if a formatted data is an ethereum address identity
118
+ *
119
+ * @param formattedData the formatted data to check
120
+ * @returns true if follow the format, false otherwise
121
+ */
122
+ function isIdentityEthereumAddress ( formattedData : string ) : boolean {
123
+ return (
124
+ formattedData . slice ( 0 , 2 ) === MultiFormatTypes . prefix . IDENTITY_ETHEREUM_ADDRESS &&
125
+ formattedData . length === MultiFormatTypes . FORMAT_IDENTITY_ETHEREUM_ADDRESS_LENGTH
126
+ ) ;
127
+ }
128
+
104
129
/**
105
130
* Removes padding of a multi-format
106
131
*
0 commit comments