Skip to content

Commit

Permalink
feat(xlm): add combine function
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Prohaszka <[email protected]>
  • Loading branch information
sprohaszka-ledger committed Jul 17, 2024
1 parent 095e290 commit 159c82e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
20 changes: 10 additions & 10 deletions libs/coin-modules/coin-stellar/src/api/index.integ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ describe("Stellar Api", () => {
});
});

// describe("lastBlock", () => {
// it("returns last block info", async () => {
// // When
// const result = await module.lastBlock();
describe("lastBlock", () => {
it("returns last block info", async () => {
// When
const result = await module.lastBlock();

// // Then
// expect(result.hash).toBeDefined();
// expect(result.height).toBeDefined();
// expect(result.time).toBeInstanceOf(Date);
// });
// });
// Then
expect(result.hash).toBeDefined();
expect(result.height).toBeDefined();
expect(result.time).toBeInstanceOf(Date);
});
});

describe("getBalance", () => {
it("returns a list regarding address parameter", async () => {
Expand Down
14 changes: 9 additions & 5 deletions libs/coin-modules/coin-stellar/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ import type { Api } from "@ledgerhq/coin-framework/api/index";
import coinConfig, { type StellarConfig } from "../config";
import {
broadcast,
// combine,
combine,
craftTransaction,
// estimateFees,
getBalance,
listOperations,
lastBlock,
// rawEncode,
} from "../logic";

export function createApi(config: StellarConfig): Api {
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));

return {
broadcast,
combine: () => {
throw new Error("Method not supported");
},
combine: compose,
craftTransaction: craft,
estimateFees: () => Promise.reject(new Error("Method not supported")),
getBalance,
Expand Down Expand Up @@ -66,3 +63,10 @@ async function craft(
);
return tx.xdr;
}

function compose(tx: string, signature: string, pubkey?: string): string {
if (!pubkey) {
throw new Error("Missing pubkey");
}
return combine(tx, signature, pubkey);
}
14 changes: 12 additions & 2 deletions libs/coin-modules/coin-stellar/src/logic/combine.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import { Transaction as StellarSdkTransaction } from "@stellar/stellar-sdk";

// export function combine(transaction: string, signature: string, publicKey?: string): string {
// }
// https://developers.stellar.org/docs/learn/encyclopedia/network-configuration/network-passphrases
// Mainnet
const NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015";
// Testnet
// const NETWORK_PASSPHRASE = "Test SDF Network ; September 2015";

export function combine(transaction: string, signature: string, publicKey: string): string {
const unsignedTx = new StellarSdkTransaction(transaction, NETWORK_PASSPHRASE);
unsignedTx.addSignature(publicKey, signature);
return unsignedTx.toXDR();
}
2 changes: 1 addition & 1 deletion libs/coin-modules/coin-stellar/src/logic/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { broadcast } from "./broadcast";
// export { combine } from "./combine";
export { combine } from "./combine";
export { craftTransaction } from "./craftTransaction";
// export { estimateFees } from "./estimateFees";
export { getBalance } from "./getBalance";
Expand Down

0 comments on commit 159c82e

Please sign in to comment.