Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
arobsn committed Jul 2, 2024
1 parent f830979 commit 83043b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 66 deletions.
10 changes: 2 additions & 8 deletions src/erg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import {
attestInput,
signTx
} from "./interactions";
import type { AttestedTransaction, SignTransactionResponse } from "./types/internal";
import { uniq, Network } from "@fleet-sdk/common";
import type {
AttestedTransaction,
SignTransactionResponse
} from "./types/internal";

export { DeviceError, RETURN_CODE, Network };
export * from "./types/public";
Expand Down Expand Up @@ -144,10 +141,7 @@ export class ErgoLedgerApp {
* @param path Bip44 path.
* @returns a Promise with true if the user accepts or throws an exception if it get rejected.
*/
public async showAddress(
path: string,
network = Network.Mainnet
): Promise<boolean> {
public async showAddress(path: string, network = Network.Mainnet): Promise<boolean> {
this._debug("showAddress", path);
return showAddress(this._device, network, path, this.authToken);
}
Expand Down
5 changes: 1 addition & 4 deletions src/interactions/deriveAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ function sendDeriveAddress(
throw new Error(`Invalid change path: ${change}`);
}

const data = Buffer.concat([
Buffer.alloc(1, network),
serialize.path(pathArray)
]);
const data = Buffer.concat([Buffer.alloc(1, network), serialize.path(pathArray)]);

return device.send(
COMMAND.DERIVE_ADDRESS,
Expand Down
65 changes: 11 additions & 54 deletions src/interactions/signTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ export async function signTx(
await sendDistinctTokensIds(device, sessionId, tx.distinctTokenIds);
await sendInputs(device, sessionId, tx.inputs);
await sendDataInputs(device, sessionId, tx.dataInputs);
await sendOutputs(
device,
sessionId,
tx.outputs,
tx.changeMap,
tx.distinctTokenIds
);
await sendOutputs(device, sessionId, tx.outputs, tx.changeMap, tx.distinctTokenIds);
const proof = await sendConfirmAndSign(device, sessionId);

return new Uint8Array(proof);
Expand Down Expand Up @@ -112,19 +106,10 @@ async function sendDistinctTokensIds(
}
}

async function sendInputs(
device: Device,
sessionId: number,
inputs: AttestedBox[]
) {
async function sendInputs(device: Device, sessionId: number, inputs: AttestedBox[]) {
for (const input of inputs) {
for (const frame of input.frames) {
await device.send(
COMMAND.SIGN_TX,
P1.ADD_INPUT_BOX_FRAME,
sessionId,
frame.bytes
);
await device.send(COMMAND.SIGN_TX, P1.ADD_INPUT_BOX_FRAME, sessionId, frame.bytes);
}

if (input.extension !== undefined && input.extension.length > 0) {
Expand All @@ -146,17 +131,9 @@ async function sendBoxContextExtension(
);
}

async function sendDataInputs(
device: Device,
sessionId: number,
boxIds: string[]
) {
async function sendDataInputs(device: Device, sessionId: number, boxIds: string[]) {
const MAX_PACKET_SIZE = 7;
const packets = serialize.arrayAsMappedChunks(
boxIds,
MAX_PACKET_SIZE,
serialize.hex
);
const packets = serialize.arrayAsMappedChunks(boxIds, MAX_PACKET_SIZE, serialize.hex);

for (const p of packets) {
await device.send(COMMAND.SIGN_TX, P1.ADD_DATA_INPUTS, sessionId, p);
Expand All @@ -170,9 +147,7 @@ async function sendOutputs(
changeMap: ChangeMap,
distinctTokenIds: Uint8Array[]
) {
const distinctTokenIdsStr = distinctTokenIds.map((t) =>
Buffer.from(t).toString("hex")
);
const distinctTokenIdsStr = distinctTokenIds.map((t) => Buffer.from(t).toString("hex"));

for (const box of boxes) {
await device.send(
Expand All @@ -191,21 +166,14 @@ async function sendOutputs(
const tree = deserialize.hex(box.ergoTree);
if (tree === MINER_FEE_TREE) {
await addOutputBoxMinersFeeTree(device, sessionId);
} else if (
ErgoAddress.fromErgoTree(tree).toString() === changeMap.address
) {
} else if (ErgoAddress.fromErgoTree(tree).toString() === changeMap.address) {
await addOutputBoxChangeTree(device, sessionId, changeMap.path);
} else {
await addOutputBoxErgoTree(device, sessionId, box.ergoTree);
}

if (box.tokens && box.tokens.length > 0) {
await addOutputBoxTokens(
device,
sessionId,
box.tokens,
distinctTokenIdsStr
);
await addOutputBoxTokens(device, sessionId, box.tokens, distinctTokenIdsStr);
}

if (box.registers.length > 0) {
Expand All @@ -214,11 +182,7 @@ async function sendOutputs(
}
}

async function addOutputBoxErgoTree(
device: Device,
sessionId: number,
ergoTree: Buffer
) {
async function addOutputBoxErgoTree(device: Device, sessionId: number, ergoTree: Buffer) {
await device.sendData(
COMMAND.SIGN_TX,
P1.ADD_OUTPUT_BOX_ERGO_TREE_CHUNK,
Expand All @@ -236,11 +200,7 @@ async function addOutputBoxMinersFeeTree(device: Device, sessionId: number) {
);
}

async function addOutputBoxChangeTree(
device: Device,
sessionId: number,
path: string
) {
async function addOutputBoxChangeTree(device: Device, sessionId: number, path: string) {
await device.send(
COMMAND.SIGN_TX,
P1.ADD_OUTPUT_BOX_CHANGE_TREE,
Expand Down Expand Up @@ -281,10 +241,7 @@ async function addOutputBoxRegisters(
);
}

async function sendConfirmAndSign(
device: Device,
sessionId: number
): Promise<Buffer> {
async function sendConfirmAndSign(device: Device, sessionId: number): Promise<Buffer> {
const response = await device.send(
COMMAND.SIGN_TX,
P1.CONFIRM_AND_SIGN,
Expand Down

0 comments on commit 83043b3

Please sign in to comment.