44
55*/
66
7- import { assert } from 'chai'
7+ import { assert , expect } from 'chai'
88import { randomInt , randomBytes } from 'crypto'
99
1010import { Account } from '../../src/Account'
@@ -13,6 +13,7 @@ import {
1313 isAddress ,
1414 isPublicKey ,
1515 isPublicKeyChecksum ,
16+ hexToByteArray ,
1617 prefix0x ,
1718 remove0xPrefix ,
1819 toAddress ,
@@ -22,6 +23,12 @@ import {
2223} from '../../src/Utils'
2324
2425const PUBLIC_ADDRESS = '0x5288fec4153b702430771dfac8aed0b21cafca4344dae0d47b97f0bf532b3306'
26+ const PUBLIC_ADDRESS_BYTES = [
27+ 0x52 , 0x88 , 0xFE , 0xC4 , 0x15 , 0x3B , 0x70 , 0x24 ,
28+ 0x30 , 0x77 , 0x1D , 0xFA , 0xC8 , 0xAE , 0xD0 , 0xB2 ,
29+ 0x1C , 0xAF , 0xCA , 0x43 , 0x44 , 0xDA , 0xE0 , 0xD4 ,
30+ 0x7B , 0x97 , 0xF0 , 0xBF , 0x53 , 0x2B , 0x33 , 0x06
31+ ]
2532const PUBLIC_ADDRESS_CHECHKSUM = '0x5288Fec4153b702430771DFAC8AeD0B21CAFca4344daE0d47B97F0bf532b3306'
2633
2734
@@ -128,6 +135,18 @@ describe('Utils module', () => {
128135 } )
129136 } )
130137
138+ describe ( 'hexToBytes' , ( ) => {
139+ it ( 'should convert a hex string to Uint8Array' , ( ) => {
140+ expect ( ( ) => hexToByteArray ( PUBLIC_ADDRESS ) ) . to . throw ( TypeError , / c o n t a i n s n o n h e x c h a r a c t e r s / )
141+
142+ let result = hexToByteArray ( remove0xPrefix ( PUBLIC_ADDRESS ) )
143+ assert . equal ( Uint8Array . from ( PUBLIC_ADDRESS_BYTES ) . toString ( ) , result . toString ( ) )
144+
145+ result = hexToByteArray ( remove0xPrefix ( PUBLIC_ADDRESS_CHECHKSUM ) )
146+ assert . equal ( Uint8Array . from ( PUBLIC_ADDRESS_BYTES ) . toString ( ) , result . toString ( ) )
147+
148+ } )
149+ } )
131150 describe ( 'Convert Uint8Array to and from WordArray for crypto-js' , ( ) => {
132151 it ( 'should convert to word array' , ( ) => {
133152 const testLength = 64
0 commit comments