@@ -340,22 +340,40 @@ const extractTransactionVersion = (version: number): number => {
340340 return parseInt ( version . toString ( 16 ) . substr ( 2 , 2 ) , 16 ) ;
341341} ;
342342
343+ /**
344+ * Extract recipient value from encoded hexadecimal notation.
345+ *
346+ * If bit 0 of byte 0 is not set (e.g. 0x90), then it is a regular address.
347+ * Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
348+ *
349+ * @param recipient {string} Encoded hexadecimal recipient notation
350+ * @return {Address | NamespaceId }
351+ */
343352const extractRecipient = ( recipient : string ) : Address | NamespaceId => {
344- // If bit 0 of byte 0 is not set (like in 0x90), then it is a regular address.
345- // Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
346- const fstByteBit0 = recipient . substr ( 1 , 1 ) ;
353+ // If bit 0 of byte 0 is not set (like in 0x90), then it is a regular address.
354+ // Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
355+ const bit0 = convert . hexToUint8 ( recipient . substr ( 1 , 2 ) ) [ 0 ] ;
347356
348- if ( parseInt ( fstByteBit0 , 2 ) === 1 ) {
349- // namespaceId encoded hexadecimal notation provided
350- // only 8 bytes are relevant to resolve the NamespaceId
351- const relevantPart = recipient . substr ( 2 , 16 ) ;
352- return NamespaceId . createFromEncoded ( relevantPart ) ;
353- }
357+ if ( ( bit0 & 16 ) === 16 ) {
358+ // namespaceId encoded hexadecimal notation provided
359+ // only 8 bytes are relevant to resolve the NamespaceId
360+ const relevantPart = recipient . substr ( 2 , 16 ) ;
361+ return NamespaceId . createFromEncoded ( relevantPart ) ;
362+ }
354363
355- // read address from encoded hexadecimal notation
356- return Address . createFromEncoded ( recipient ) ;
364+ // read address from encoded hexadecimal notation
365+ return Address . createFromEncoded ( recipient ) ;
357366} ;
358367
368+ /**
369+ * Extract mosaics from encoded UInt64 notation.
370+ *
371+ * If most significant bit of byte 0 is set, then it is a namespaceId.
372+ * If most significant bit of byte 0 is not set, then it is a mosaicId.
373+ *
374+ * @param mosaics {Array | undefined} The DTO array of mosaics (with UInt64 Id notation)
375+ * @return {Mosaic[] }
376+ */
359377const extractMosaics = ( mosaics : any ) : Mosaic [ ] => {
360378
361379 if ( mosaics === undefined ) {
0 commit comments