Initial change from Babel/JS to TypeScript (#70)

* will compile as typescript

* migrated test suite to use JestJS

* Migrated to Jest testing framework and typescript source files

* updated deps

* updated prepublish

* resolved 1 failing test

* changed decimal .0 on four tests, it appears that these were the only four tests expecting integer values to have '.0'

* added linter

* added package-lock

* removed tslint in favor of eslint

* changed yarn to npm

* updated version 2.6->3.0

* removing package lock

* updated node version in nvmrc and jest version in package

* removed nvmrc

* removed some unused functions

* replaced data driven with file from master

* commitint yarn.lock

* removing babel as a dependency in favor of typescript compiling to es5

* removing babel deps

* resolved testing issues by migrating helper function

* added partial linting functionality for test suite

* updated imports for decodeLedgerData

* updated test

* updated yarn.lock

* removed a console.log

* added eslint-jest-plugin to package

* reverting to old linting, will add linting in next PR

* removed comments in shamap

* re-adding .nvmrc

* npm -> yarn

* added . to .eslintrc

* added .eslintrc

* removing linting for this PR

* Changed linting to print a message so that linting doesnt fail in CI

* changing back

* added newline so diff wont show

* removed eslint deps, since linting will be dealt with in a later PR

* changed function calls to describe(...)
This commit is contained in:
Nathan Nichols
2020-06-24 09:00:28 -07:00
parent 16b1b91a76
commit a930b9413c
91 changed files with 5058 additions and 5142 deletions

View File

@@ -0,0 +1,69 @@
/* eslint-disable func-style */
import { BN } from 'bn.js';
import { coreTypes } from './types';
const { HashPrefix } = require('./hash-prefixes');
const {BinaryParser} = require('./serdes/binary-parser');
const {BinarySerializer, BytesList} = require('./serdes/binary-serializer');
const {bytesToHex, slice, parseBytes} = require('./utils/bytes-utils');
const {sha512Half, transactionID} = require('./hashes');
const makeParser = bytes => new BinaryParser(bytes);
const readJSON = parser => parser.readType(coreTypes.STObject).toJSON();
const binaryToJSON = bytes => readJSON(makeParser(bytes));
function serializeObject(object, opts = <any>{}) {
const {prefix, suffix, signingFieldsOnly = false} = opts;
const bytesList = new BytesList();
if (prefix) {
bytesList.put(prefix);
}
const filter = signingFieldsOnly ? f => f.isSigningField : undefined;
coreTypes.STObject.from(object).toBytesSink(bytesList, filter);
if (suffix) {
bytesList.put(suffix);
}
return bytesList.toBytes();
}
function signingData(tx, prefix = HashPrefix.transactionSig) {
return serializeObject(tx, {prefix, signingFieldsOnly: true});
}
function signingClaimData(claim) {
const prefix = HashPrefix.paymentChannelClaim
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
const amount = new coreTypes.UInt64(new BN(claim.amount)).toBytes();
const bytesList = new BytesList();
bytesList.put(prefix)
bytesList.put(channel)
bytesList.put(amount)
return bytesList.toBytes()
}
function multiSigningData(tx, signingAccount) {
const prefix = HashPrefix.transactionMultiSig;
const suffix = coreTypes.AccountID.from(signingAccount).toBytes();
return serializeObject(tx, {prefix, suffix, signingFieldsOnly: true});
}
export {
BinaryParser,
BinarySerializer,
BytesList,
makeParser,
serializeObject,
readJSON,
bytesToHex,
parseBytes,
multiSigningData,
signingData,
signingClaimData,
binaryToJSON,
sha512Half,
transactionID,
slice
};