diff --git a/src/utils/bignumber.ts b/src/utils/bignumber.ts index 7abc0fdf2b..a1a5c75a1c 100644 --- a/src/utils/bignumber.ts +++ b/src/utils/bignumber.ts @@ -1,18 +1,10 @@ /** * Big Number Helpers * @module @aeternity/aepp-sdk/es/utils/bignumber - * @example import { parseBigNumber, isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber' + * @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber' */ import BigNumber from 'bignumber.js' -/** - * Convert number to string - * @param {String|Number|BigNumber} number number to convert - * @return {String} - */ -export const parseBigNumber = (number: string | number | BigNumber): string => - new BigNumber(number.toString()).toString(10) - /** * Check if value is BigNumber, Number or number string representation * @param {String|Number|BigNumber} number number to convert diff --git a/src/utils/crypto.js b/src/utils/crypto.js index a73908a844..84687ef380 100644 --- a/src/utils/crypto.js +++ b/src/utils/crypto.js @@ -26,7 +26,7 @@ import nacl from 'tweetnacl' import aesjs from 'aes-js' import shajs from 'sha.js' -import { str2buf, toBytes } from './bytes' +import { str2buf } from './bytes' import { decode } from '../tx/builder/helpers' import { hash } from './crypto-ts' import { InvalidChecksumError, MessageLimitError } from './errors' @@ -63,16 +63,6 @@ export function isAddressValid (address, prefix = 'ak') { } } -/** - * Parse decimal address and return base58Check encoded address with prefix 'ak' - * @rtype (input: String) => address: String - * @param {String} decimalAddress - Address - * @return {String} address - */ -export function addressFromDecimal (decimalAddress) { - return aeEncodeKey(toBytes(decimalAddress, true)) -} - /** * Calculate SHA256 hash of `input` * @rtype (input: String) => hash: String @@ -284,19 +274,6 @@ export function verifyMessage (str, signature, publicKey) { return verify(messageToHash(str), signature, publicKey) } -/** - * æternity readable public keys are the base58-encoded public key, prepended - * with 'ak_' - * @rtype (binaryKey: Buffer) => String - * @param {Buffer} binaryKey - Key to encode - * @return {String} Encoded key - */ -export function aeEncodeKey (binaryKey) { - const publicKeyBuffer = Buffer.from(binaryKey, 'hex') - const pubKeyAddress = encodeBase58Check(publicKeyBuffer) - return `ak_${pubKeyAddress}` -} - /** * Check key pair for validity * diff --git a/test/unit/amount-formatter.ts b/test/unit/amount-formatter.ts index 9da97e428f..3c1df28296 100644 --- a/test/unit/amount-formatter.ts +++ b/test/unit/amount-formatter.ts @@ -20,21 +20,20 @@ import { expect } from 'chai' import BigNumber from 'bignumber.js' import '..' import { AE_AMOUNT_FORMATS, formatAmount, toAe, toAettos } from '../../src/utils/amount-formatter' -import { parseBigNumber } from '../../src/utils/bignumber' import { InvalidDenominationError, IllegalArgumentError } from '../../src/utils/errors' describe('Amount Formatter', function () { - it('to aettos', async () => { + it('to aettos', () => { [ - [1, AE_AMOUNT_FORMATS.AE, 1e18], - [10, AE_AMOUNT_FORMATS.AE, 10e18], - [100, AE_AMOUNT_FORMATS.AE, 100e18], - [10012312, AE_AMOUNT_FORMATS.AE, 10012312e18], - [1, AE_AMOUNT_FORMATS.AETTOS, 1] - ].forEach( - ([v, d, e]) => expect(parseBigNumber(e)).to.be.equal(toAettos(v, { denomination: d.toString() })) - ) + [1, AE_AMOUNT_FORMATS.AE, '1000000000000000000'], + [11, AE_AMOUNT_FORMATS.AE, '11000000000000000000'], + [111, AE_AMOUNT_FORMATS.AE, '111000000000000000000'], + [10012312, AE_AMOUNT_FORMATS.AE, '10012312000000000000000000'], + [1, AE_AMOUNT_FORMATS.AETTOS, '1'] + ].forEach(([v, denomination, e]: [number, string, string]) => + expect(toAettos(v, { denomination })).to.be.equal(e)) }) + it('to Ae', () => { [ [1, AE_AMOUNT_FORMATS.AETTOS, new BigNumber(1).div(1e18)], @@ -42,10 +41,10 @@ describe('Amount Formatter', function () { [100, AE_AMOUNT_FORMATS.AETTOS, new BigNumber(100).div(1e18)], [10012312, AE_AMOUNT_FORMATS.AETTOS, new BigNumber(10012312).div(1e18)], [1, AE_AMOUNT_FORMATS.AE, 1] - ].forEach( - ([v, d, e]) => expect(parseBigNumber(e)).to.be.equal(toAe(v, { denomination: d.toString() })) - ) + ].forEach(([v, denomination, e]: [number, string, BigNumber]) => + expect(toAe(v, { denomination })).to.be.equal(e.toString(10))) }) + it('format', () => { [ [1, AE_AMOUNT_FORMATS.AE, AE_AMOUNT_FORMATS.AETTOS, new BigNumber(1e18)], @@ -67,17 +66,18 @@ describe('Amount Formatter', function () { [1, AE_AMOUNT_FORMATS.NANO_AE, AE_AMOUNT_FORMATS.AETTOS, new BigNumber(1000000000)], [1, AE_AMOUNT_FORMATS.FEMTO_AE, AE_AMOUNT_FORMATS.AETTOS, new BigNumber(1000)], [1, AE_AMOUNT_FORMATS.NANO_AE, AE_AMOUNT_FORMATS.FEMTO_AE, new BigNumber(1000000)] - ].forEach( - ([v, dF, dT, e]) => expect(parseBigNumber(e)).to.be.equal(formatAmount(v, { denomination: dF.toString(), targetDenomination: dT.toString() })) - ) + ].forEach(([v, denomination, targetDenomination, e]: [number, string, string, BigNumber]) => + expect(formatAmount(v, { denomination, targetDenomination })).to.be.equal(e.toString(10))) }) + it('Invalid value', () => { [ - [true, [AE_AMOUNT_FORMATS.AE, AE_AMOUNT_FORMATS.AE], 'Value true is not type of number', IllegalArgumentError], - [1, [AE_AMOUNT_FORMATS.AE, 'ASD'], 'Invalid target denomination: ASD', InvalidDenominationError], - [1, ['ASD', AE_AMOUNT_FORMATS.AE], 'Invalid denomination: ASD', InvalidDenominationError] - ].forEach(([v, [dF, dT], error]: any[]) => { - expect(() => formatAmount(v, { denomination: dF, targetDenomination: dT })).to.throw(error) + [true, AE_AMOUNT_FORMATS.AE, AE_AMOUNT_FORMATS.AE, IllegalArgumentError, 'Value true is not type of number'], + [1, AE_AMOUNT_FORMATS.AE, 'ASD', InvalidDenominationError, 'Invalid target denomination: ASD'], + [1, 'ASD', AE_AMOUNT_FORMATS.AE, InvalidDenominationError, 'Invalid denomination: ASD'] + ].forEach(([v, dF, dT, error, msg]: any[]) => { + expect(() => formatAmount(v, { denomination: dF, targetDenomination: dT })) + .to.throw(error, msg) }) }) }) diff --git a/test/unit/tx.js b/test/unit/tx.js index 26cc9b8341..aa5e3462c8 100644 --- a/test/unit/tx.js +++ b/test/unit/tx.js @@ -33,7 +33,6 @@ import { } from '../../src/tx/builder/helpers' import BigNumber from 'bignumber.js' import { toBytes } from '../../src/utils/bytes' -import { parseBigNumber } from '../../src/utils/bignumber' import { buildTx, unpackTx } from '../../src/tx/builder' import { NAME_BID_RANGES } from '../../src/tx/builder/schema' import { @@ -49,10 +48,6 @@ describe('Tx', function () { return hash.should.be.equal(await commitmentHash('foobar.chain', _salt)) }) - it('Parse big number', async () => { - parseBigNumber('123123123123').should.be.a('string') - }) - it('test from big number to bytes', async () => { // TODO investigate about float numbers serialization const data = [