Skip to content

Add type conversions to the trac-crypto-api #30

@leonardotc

Description

@leonardotc

What to do

  • Move createMessage from msb to the trac-crypto-api
  • Move bigIntToDecimalString and bufferToBigInt from msb to the trac-crypto-api
  • Move more stuff that makes sense especially if its associated with TNK conversion.
  • Change both peer and msb to pull those from the api instead of their own source (and remove the code accordingly).

Benefit

We dont need to commit (support) to those functions on an application level, we eliminate duplication and we can change msb independently from peer which eliminates a coupling layer (making sure that change that on msb wont break peer, especially if a someone uses an expression on package.json like some people do.

Reasoning

Peer, the contract and MSB are using some basic functionality from msb. In this case, it doesnt make sense for MSB itself to export since its free-of-context logic. I would imagine the best place would be the trac-crypto-api.

import { createMessage } from "trac-msb/src/utils/buffer.js";
import { bufferToBigInt, bigIntToDecimalString } from "trac-msb/src/utils/amountSerialization.js";

The bufferToBigInt may be a bit overstretching. We use it to display info on msb. Msb should be able to display info about itself through proper delegation so I would keep that out. That is further suplemented by the fact that a balance representation in binary IS, pretty much, a specific concern of msb (but might still be worth doing). The others probably make a little bit more sense since pretty print of bigints can be associated with wallet-like daps and create message could be seen as an auxiliary function for serializing, hashing and signing (which is a very standard crypto process).

The dump of the imports (for ilustrative purposes).

import { bufferToBigInt, bigIntToDecimalString } from "trac-msb/src/utils/amountSerialization.js";
import PartialTransaction from "trac-msb/src/core/network/protocols/shared/validators/PartialTransaction.js";
import { normalizeTransactionOperation } from "trac-msb/src/utils/normalizers.js";
import { safeDecodeApplyOperation } from "trac-msb/src/utils/protobuf/operationHelpers.js";
import { MainSettlementBus } from "trac-msb/src/index.js";
import { createConfig as createMsbConfig, ENV as MSB_ENV } from "trac-msb/src/config/env.js";
import { createMessage } from "trac-msb/src/utils/buffer.js";
import { bigIntToDecimalString, decimalStringToBigInt } from "trac-msb/src/utils/amountSerialization.js";
import { createMessage } from "trac-msb/src/utils/buffer.js";
import { safeDecodeApplyOperation } from "trac-msb/src/utils/protobuf/operationHelpers.js";
import { MainSettlementBus } from "trac-msb/src/index.js";
import { createConfig as createMsbConfig, ENV as MSB_ENV } from "trac-msb/src/config/env.js";
import { bufferToBigInt, bigIntToDecimalString } from "trac-msb/src/utils/amountSerialization.js";

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions