mirror of
				https://github.com/Xahau/xahau.js.git
				synced 2025-11-04 04:55:48 +00:00 
			
		
		
		
	- Removes need for bundlers to polyfill the `Buffer` class. `UInt8Array` are used instead which are native to the browser and node. - Reduces bundle size 7.1kb gzipped and eliminates 4 runtime dependencies: `base-x`, `base64-js`, `buffer`, and `ieee754`. BREAKING CHANGE: All methods that previously took a `Buffer` now accept a `UInt8Array`. --------- Co-authored-by: Jackson Mills <jmills@ripple.com>
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import {
 | 
						|
  bytesToHex,
 | 
						|
  hexToBytes,
 | 
						|
  hexToString,
 | 
						|
  randomBytes,
 | 
						|
  stringToHex,
 | 
						|
} from '../utils'
 | 
						|
 | 
						|
describe('utils', function () {
 | 
						|
  it('randomBytes', () => {
 | 
						|
    expect(randomBytes(16).byteLength).toEqual(16)
 | 
						|
  })
 | 
						|
 | 
						|
  it('hexToBytes - empty', () => {
 | 
						|
    expect(hexToBytes('')).toEqual(new Uint8Array([]))
 | 
						|
  })
 | 
						|
 | 
						|
  it('hexToBytes - zero', () => {
 | 
						|
    expect(hexToBytes('000000')).toEqual(new Uint8Array([0, 0, 0]))
 | 
						|
  })
 | 
						|
 | 
						|
  it('hexToBytes - DEADBEEF', () => {
 | 
						|
    expect(hexToBytes('DEADBEEF')).toEqual(new Uint8Array([222, 173, 190, 239]))
 | 
						|
  })
 | 
						|
 | 
						|
  it('bytesToHex - DEADBEEF', () => {
 | 
						|
    expect(bytesToHex([222, 173, 190, 239])).toEqual('DEADBEEF')
 | 
						|
  })
 | 
						|
 | 
						|
  it('bytesToHex - 010203', () => {
 | 
						|
    expect(bytesToHex([1, 2, 3])).toEqual('010203')
 | 
						|
  })
 | 
						|
 | 
						|
  it('bytesToHex - DEADBEEF (Uint8Array)', () => {
 | 
						|
    expect(bytesToHex(new Uint8Array([222, 173, 190, 239]))).toEqual('DEADBEEF')
 | 
						|
  })
 | 
						|
 | 
						|
  it('hexToString - deadbeef+infinity symbol (HEX ASCII)', () => {
 | 
						|
    expect(hexToString('646561646265656658D', 'ascii')).toEqual('deadbeefX')
 | 
						|
  })
 | 
						|
 | 
						|
  it('hexToString - deadbeef+infinity symbol (HEX)', () => {
 | 
						|
    expect(hexToString('6465616462656566D68D')).toEqual('deadbeef֍')
 | 
						|
  })
 | 
						|
 | 
						|
  it('stringToHex - deadbeef+infinity symbol (utf8)', () => {
 | 
						|
    expect(stringToHex('deadbeef֍')).toEqual('6465616462656566D68D')
 | 
						|
  })
 | 
						|
})
 |