@@ -20,10 +20,12 @@ import { RawAddress } from '../../core/format/RawAddress';
2020import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils' ;
2121import { Address } from '../account/Address' ;
2222import { MosaicId } from '../mosaic/MosaicId' ;
23+ import { NamespaceId } from '../namespace/NamespaceId' ;
2324import { UInt64 } from '../UInt64' ;
2425import { ReceiptType } from './ReceiptType' ;
2526import { ReceiptVersion } from './ReceiptVersion' ;
2627import { ResolutionEntry } from './ResolutionEntry' ;
28+ import { ResolutionType } from './ResolutionType' ;
2729
2830/**
2931 * When a transaction includes an alias, a so called resolution statement reflects the resolved value for that block:
@@ -34,19 +36,24 @@ export class ResolutionStatement {
3436
3537 /**
3638 * Receipt - resolution statement object
39+ * @param resolutionType - The resolution type
3740 * @param height - The block height
3841 * @param unresolved - An unresolved address or unresolved mosaicId.
3942 * @param resolutionEntries - The array of resolution entries.
4043 */
4144 constructor (
45+ /**
46+ * Resolution type
47+ */
48+ public readonly resolutionType : ResolutionType ,
4249 /**
4350 * The block height.
4451 */
4552 public readonly height : UInt64 ,
4653 /**
4754 * An unresolved address or unresolved mosaicId.
4855 */
49- public readonly unresolved : Address | MosaicId ,
56+ public readonly unresolved : Address | MosaicId | NamespaceId ,
5057 /**
5158 * The array of resolution entries.
5259 */
@@ -58,10 +65,9 @@ export class ResolutionStatement {
5865 * @return {string } receipt hash in hex
5966 */
6067 public generateHash ( ) : string {
61- const type = this . unresolved instanceof Address ? ReceiptType . Address_Alias_Resolution
62- : ReceiptType . Mosaic_Alias_Resolution ;
63- const unresolvedBytes = this . unresolved instanceof Address ? RawAddress . stringToAddress ( this . unresolved . plain ( ) )
64- : Convert . hexToUint8 ( this . unresolved . toHex ( ) ) ;
68+ const type = this . resolutionType === ResolutionType . Address ? ReceiptType . Address_Alias_Resolution
69+ : ReceiptType . Mosaic_Alias_Resolution ;
70+ const unresolvedBytes = this . getUnresolvedBytes ( this . resolutionType ) ;
6571 const hasher = sha3_256 . create ( ) ;
6672 hasher . update ( GeneratorUtils . uintToBuffer ( ReceiptVersion . RESOLUTION_STATEMENT , 2 ) ) ;
6773 hasher . update ( GeneratorUtils . uintToBuffer ( type , 2 ) ) ;
@@ -76,4 +82,27 @@ export class ResolutionStatement {
7682 hasher . update ( entryBytes ) ;
7783 return hasher . hex ( ) . toUpperCase ( ) ;
7884 }
85+
86+ /**
87+ * @internal
88+ * Generate buffer for unresulved
89+ * @param - The resolution Type
90+ * @return {Uint8Array }
91+ */
92+ private getUnresolvedBytes ( resolutionType : ResolutionType ) : Uint8Array {
93+ if ( resolutionType === ResolutionType . Address ) {
94+ const recipientString =
95+ this . unresolved instanceof NamespaceId ? ( this . unresolved as NamespaceId ) . toHex ( )
96+ : ( this . unresolved as Address ) . plain ( ) ;
97+ if ( / ^ [ 0 - 9 a - f A - F ] { 16 } $ / . test ( recipientString ) ) {
98+ // received hexadecimal notation of namespaceId (alias)
99+ return RawAddress . aliasToRecipient ( Convert . hexToUint8 ( recipientString ) ) ;
100+ } else {
101+ // received recipient address
102+ return RawAddress . stringToAddress ( recipientString ) ;
103+ }
104+ }
105+
106+ return GeneratorUtils . uint64ToBuffer ( UInt64 . fromHex ( ( this . unresolved as MosaicId | NamespaceId ) . toHex ( ) ) . toDTO ( ) ) ;
107+ }
79108}
0 commit comments