mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 07:35:52 +00:00
run prettier on all packages
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
/* eslint-disable func-style */
|
||||
|
||||
import { coreTypes } from "./types";
|
||||
import { BinaryParser } from "./serdes/binary-parser";
|
||||
import { AccountID } from "./types/account-id";
|
||||
import { HashPrefix } from "./hash-prefixes";
|
||||
import { BinarySerializer, BytesList } from "./serdes/binary-serializer";
|
||||
import { sha512Half, transactionID } from "./hashes";
|
||||
import { FieldInstance } from "./enums";
|
||||
import { STObject } from "./types/st-object";
|
||||
import { JsonObject } from "./types/serialized-type";
|
||||
import { Buffer } from "buffer/";
|
||||
import * as bigInt from "big-integer";
|
||||
import { coreTypes } from './types'
|
||||
import { BinaryParser } from './serdes/binary-parser'
|
||||
import { AccountID } from './types/account-id'
|
||||
import { HashPrefix } from './hash-prefixes'
|
||||
import { BinarySerializer, BytesList } from './serdes/binary-serializer'
|
||||
import { sha512Half, transactionID } from './hashes'
|
||||
import { FieldInstance } from './enums'
|
||||
import { STObject } from './types/st-object'
|
||||
import { JsonObject } from './types/serialized-type'
|
||||
import { Buffer } from 'buffer/'
|
||||
import * as bigInt from 'big-integer'
|
||||
|
||||
/**
|
||||
* Construct a BinaryParser
|
||||
@@ -18,7 +18,7 @@ import * as bigInt from "big-integer";
|
||||
* @param bytes hex-string to construct BinaryParser from
|
||||
* @returns A BinaryParser
|
||||
*/
|
||||
const makeParser = (bytes: string): BinaryParser => new BinaryParser(bytes);
|
||||
const makeParser = (bytes: string): BinaryParser => new BinaryParser(bytes)
|
||||
|
||||
/**
|
||||
* Parse BinaryParser into JSON
|
||||
@@ -27,7 +27,7 @@ const makeParser = (bytes: string): BinaryParser => new BinaryParser(bytes);
|
||||
* @returns JSON for the bytes in the BinaryParser
|
||||
*/
|
||||
const readJSON = (parser: BinaryParser): JsonObject =>
|
||||
(parser.readType(coreTypes.STObject) as STObject).toJSON();
|
||||
(parser.readType(coreTypes.STObject) as STObject).toJSON()
|
||||
|
||||
/**
|
||||
* Parse a hex-string into its JSON interpretation
|
||||
@@ -35,7 +35,7 @@ const readJSON = (parser: BinaryParser): JsonObject =>
|
||||
* @param bytes hex-string to parse into JSON
|
||||
* @returns JSON
|
||||
*/
|
||||
const binaryToJSON = (bytes: string): JsonObject => readJSON(makeParser(bytes));
|
||||
const binaryToJSON = (bytes: string): JsonObject => readJSON(makeParser(bytes))
|
||||
|
||||
/**
|
||||
* Interface for passing parameters to SerializeObject
|
||||
@@ -43,9 +43,9 @@ const binaryToJSON = (bytes: string): JsonObject => readJSON(makeParser(bytes));
|
||||
* @field set signingFieldOnly to true if you want to serialize only signing fields
|
||||
*/
|
||||
interface OptionObject {
|
||||
prefix?: Buffer;
|
||||
suffix?: Buffer;
|
||||
signingFieldsOnly?: boolean;
|
||||
prefix?: Buffer
|
||||
suffix?: Buffer
|
||||
signingFieldsOnly?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,23 +56,23 @@ interface OptionObject {
|
||||
* @returns A Buffer containing the serialized object
|
||||
*/
|
||||
function serializeObject(object: JsonObject, opts: OptionObject = {}): Buffer {
|
||||
const { prefix, suffix, signingFieldsOnly = false } = opts;
|
||||
const bytesList = new BytesList();
|
||||
const { prefix, suffix, signingFieldsOnly = false } = opts
|
||||
const bytesList = new BytesList()
|
||||
|
||||
if (prefix) {
|
||||
bytesList.put(prefix);
|
||||
bytesList.put(prefix)
|
||||
}
|
||||
|
||||
const filter = signingFieldsOnly
|
||||
? (f: FieldInstance): boolean => f.isSigningField
|
||||
: undefined;
|
||||
coreTypes.STObject.from(object, filter).toBytesSink(bytesList);
|
||||
: undefined
|
||||
coreTypes.STObject.from(object, filter).toBytesSink(bytesList)
|
||||
|
||||
if (suffix) {
|
||||
bytesList.put(suffix);
|
||||
bytesList.put(suffix)
|
||||
}
|
||||
|
||||
return bytesList.toBytes();
|
||||
return bytesList.toBytes()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,17 +84,17 @@ function serializeObject(object: JsonObject, opts: OptionObject = {}): Buffer {
|
||||
*/
|
||||
function signingData(
|
||||
transaction: JsonObject,
|
||||
prefix: Buffer = HashPrefix.transactionSig
|
||||
prefix: Buffer = HashPrefix.transactionSig,
|
||||
): Buffer {
|
||||
return serializeObject(transaction, { prefix, signingFieldsOnly: true });
|
||||
return serializeObject(transaction, { prefix, signingFieldsOnly: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface describing fields required for a Claim
|
||||
*/
|
||||
interface ClaimObject extends JsonObject {
|
||||
channel: string;
|
||||
amount: string | number;
|
||||
channel: string
|
||||
amount: string | number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,17 +104,17 @@ interface ClaimObject extends JsonObject {
|
||||
* @returns the serialized object with appropriate prefix
|
||||
*/
|
||||
function signingClaimData(claim: ClaimObject): Buffer {
|
||||
const num = bigInt(String(claim.amount));
|
||||
const prefix = HashPrefix.paymentChannelClaim;
|
||||
const channel = coreTypes.Hash256.from(claim.channel).toBytes();
|
||||
const amount = coreTypes.UInt64.from(num).toBytes();
|
||||
const num = bigInt(String(claim.amount))
|
||||
const prefix = HashPrefix.paymentChannelClaim
|
||||
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
|
||||
const amount = coreTypes.UInt64.from(num).toBytes()
|
||||
|
||||
const bytesList = new BytesList();
|
||||
const bytesList = new BytesList()
|
||||
|
||||
bytesList.put(prefix);
|
||||
bytesList.put(channel);
|
||||
bytesList.put(amount);
|
||||
return bytesList.toBytes();
|
||||
bytesList.put(prefix)
|
||||
bytesList.put(channel)
|
||||
bytesList.put(amount)
|
||||
return bytesList.toBytes()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,15 +126,15 @@ function signingClaimData(claim: ClaimObject): Buffer {
|
||||
*/
|
||||
function multiSigningData(
|
||||
transaction: JsonObject,
|
||||
signingAccount: string | AccountID
|
||||
signingAccount: string | AccountID,
|
||||
): Buffer {
|
||||
const prefix = HashPrefix.transactionMultiSig;
|
||||
const suffix = coreTypes.AccountID.from(signingAccount).toBytes();
|
||||
const prefix = HashPrefix.transactionMultiSig
|
||||
const suffix = coreTypes.AccountID.from(signingAccount).toBytes()
|
||||
return serializeObject(transaction, {
|
||||
prefix,
|
||||
suffix,
|
||||
signingFieldsOnly: true,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -151,4 +151,4 @@ export {
|
||||
binaryToJSON,
|
||||
sha512Half,
|
||||
transactionID,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user