Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIVE-13681 chore: move stacks to its own module #8163

Merged
merged 53 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7200149
chore: move to own module
Wozacosta Oct 22, 2024
07bfc78
move to src
Wozacosta Oct 22, 2024
58131cc
config files for stacks module
Wozacosta Oct 22, 2024
4bc684c
separate bridge test into dataset & test, fix package.json requires
Wozacosta Oct 23, 2024
1476fd3
config files
Wozacosta Oct 23, 2024
eb52987
devicetransactionconfig
Wozacosta Oct 23, 2024
a48fe7b
bot specs + some imports fix
Wozacosta Oct 23, 2024
958f50d
move c32check dep
Wozacosta Oct 23, 2024
2686fb3
bot-deviceAction + pnpmlock
Wozacosta Oct 23, 2024
dcc78c4
some more import fixes + utils inlined
Wozacosta Oct 23, 2024
807507e
some more import fixes
Wozacosta Oct 23, 2024
bb5798c
some missing packages
Wozacosta Oct 23, 2024
06c9aac
critical coin-stacks in llc
Wozacosta Oct 23, 2024
fccb796
resolver
Wozacosta Oct 23, 2024
a45172b
bridge + signer
Wozacosta Oct 23, 2024
9fb09e0
signOperation
Wozacosta Oct 23, 2024
2c572de
signMessage
Wozacosta Oct 23, 2024
76e0c45
cli
Wozacosta Oct 23, 2024
9d8cf5c
errors & types passthrough
Wozacosta Oct 23, 2024
41ce898
fix types import
Wozacosta Oct 23, 2024
6dec96e
add stacks to sync-families-dispatch
Wozacosta Oct 23, 2024
74d123a
jest.config and tsconfig
Wozacosta Oct 23, 2024
b209038
fix typos
Wozacosta Oct 23, 2024
ea2229b
fix imports + types defined in package.json
Wozacosta Oct 23, 2024
1e6cb90
tsconfig es2021 + cli fix
Wozacosta Oct 23, 2024
d080f0d
major fixes following boilerplate
Wozacosta Oct 23, 2024
7bf491c
fix errors import
Wozacosta Oct 23, 2024
1f6c336
fix errors import frontend
Wozacosta Oct 23, 2024
99c218f
lint
Wozacosta Oct 23, 2024
51a7263
lint #2
Wozacosta Oct 23, 2024
fe32c60
unimported
Wozacosta Oct 23, 2024
9b672ed
remove coin-stacks lld
Wozacosta Oct 23, 2024
d977fc0
revert to original array access to stacksnetwork
Wozacosta Oct 24, 2024
c750fd7
cleanup signer.ts
Wozacosta Oct 24, 2024
8b4b58d
add note about shared code utils
Wozacosta Oct 25, 2024
7902020
revert coin-xrp newline in package.json
Wozacosta Oct 25, 2024
cab4737
changeset
Wozacosta Oct 25, 2024
2366495
follow boilerplate structure
Wozacosta Oct 25, 2024
6979c64
fix api import
Wozacosta Oct 25, 2024
a483a45
lint
Wozacosta Oct 25, 2024
a2d7653
missing sign message
Wozacosta Oct 28, 2024
b796383
rebase + regenerate pnpm-lock
Wozacosta Oct 29, 2024
33acad5
test updated pnpm-lock #2
Wozacosta Oct 29, 2024
90a87e9
map hw-signmessage to file
Wozacosta Oct 29, 2024
6254eaf
sort imports
Wozacosta Oct 29, 2024
7501480
network index
Wozacosta Oct 29, 2024
79681f6
remove /
Wozacosta Oct 29, 2024
4d8eda7
remove types-cryptoassets import
Wozacosta Oct 29, 2024
134c11b
use dep types-cryptoassets
Wozacosta Oct 30, 2024
5592780
lint
Wozacosta Oct 30, 2024
e881937
unused
Wozacosta Oct 30, 2024
4a3b1f6
rebase 13-11
Wozacosta Nov 13, 2024
b3721ca
fix: ledger live common unimportedrc updated
qperrot Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/ten-pigs-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ledgerhq/coin-stacks": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

support: move stacks to its own coin module
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@ledgerhq/coin-evm": "workspace:^",
"@ledgerhq/coin-filecoin": "workspace:^",
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/coin-stacks": "workspace:^",
"@ledgerhq/devices": "workspace:*",
"@ledgerhq/domain-service": "workspace:^",
"@ledgerhq/errors": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import invariant from "invariant";
import React from "react";
import { StyleSheet } from "react-native";
import type { Transaction } from "@ledgerhq/live-common/generated/types";
import { ExtraDeviceTransactionField } from "@ledgerhq/live-common/families/stacks/deviceTransactionConfig";
import { DeviceTransactionField } from "@ledgerhq/live-common/transaction/index";
import { ExtraDeviceTransactionField } from "@ledgerhq/coin-stacks/deviceTransactionConfig";
import LText from "~/components/LText";
import { DataRow } from "~/components/ValidateOnDeviceDataRow";

Expand Down
20 changes: 20 additions & 0 deletions libs/coin-modules/coin-stacks/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
env: {
browser: true,
es6: true,
},
overrides: [
{
files: ["src/**/*.test.{ts,tsx}"],
env: {
"jest/globals": true,
},
plugins: ["jest"],
},
],
rules: {
"no-console": ["error", { allow: ["warn", "error"] }],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "warn",
},
};
31 changes: 31 additions & 0 deletions libs/coin-modules/coin-stacks/.unimportedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"entry": [
"src/api/index.ts",
"src/bridge/index.ts",
"src/bridge/deviceTransactionConfig.ts",
"src/datasets/dataset-1.ts",
"src/signer/index.ts",
"src/test/index.ts",
"src/index.ts"
],
"ignorePatterns": [
"**/node_modules/**",
"**/*.fixture.ts",
"**/*.mock.ts",
"**/*.test.{js,jsx,ts,tsx}"
],
"ignoreUnresolved": [
"jest-get-type",
"jest-matcher-utils",
"jest-message-util"
],
"ignoreUnimported": [
"src/network/index.ts",
"src/signer/signMessage.ts"
],
"ignoreUnused": [
"@ledgerhq/types-cryptoassets",
"ripple-address-codec",
"ripple-binary-codec"
]
}
8 changes: 8 additions & 0 deletions libs/coin-modules/coin-stacks/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
collectCoverageFrom: ["src/**/*.ts"],
coverageDirectory: "coverage",
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["lib/", "lib-es/", ".integration.test.ts"]
};
136 changes: 136 additions & 0 deletions libs/coin-modules/coin-stacks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"name": "@ledgerhq/coin-stacks",
"version": "0.1.0",
"description": "Ledger Stacks Coin integration",
"keywords": [
"Ledger",
"LedgerWallet",
"stacks",
"stx",
"Bitcoin layer2",
"Hardware Wallet"
],
"repository": {
"type": "git",
"url": "https://github.com/LedgerHQ/ledger-live.git"
},
"bugs": {
"url": "https://github.com/LedgerHQ/ledger-live/issues"
},
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-stacks",
"publishConfig": {
"access": "public"
},
"typesVersions": {
"*": {
"lib/*": [
"lib/*"
],
"lib-es/*": [
"lib-es/*"
],
"deviceTransactionConfig": [
"lib/bridge/deviceTransactionConfig"
],
"specs": [
"lib/test/bot-specs"
],
"transaction": [
"lib/bridge/transaction"
],
"*": [
"lib/*"
]
}
},
"exports": {
"./lib/*": "./lib/*.js",
"./lib-es/*": "./lib-es/*.js",
"./api": {
"require": "./lib/api/index.js",
"default": "./lib-es/api/index.js"
},
"./deviceTransactionConfig": {
"require": "./lib/bridge/deviceTransactionConfig.js",
"default": "./lib-es/bridge/deviceTransactionConfig.js"
},
"./signer": {
"require": "./lib/signer/index.js",
"default": "./lib-es/signer/index.js"
},
"./hw-signMessage": {
"require": "./lib/signer/signMessage.js",
"default": "./lib-es/signer/signMessage.js"
},
"./specs": {
"require": "./lib/test/bot-specs.js",
"default": "./lib-es/test/bot-specs.js"
},
"./transaction": {
"require": "./lib/bridge/transaction.js",
"default": "./lib-es/bridge/transaction.js"
},
"./types": {
"require": "./lib/types/index.js",
"default": "./lib-es/types/index.js"
},
"./*": {
"require": "./lib/*.js",
"default": "./lib-es/*.js"
},
".": {
"require": "./lib/index.js",
"default": "./lib-es/index.js"
},
"./package.json": "./package.json"
},
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/cryptoassets": "workspace:^",
"@ledgerhq/devices": "workspace:*",
"@ledgerhq/errors": "workspace:^",
"@ledgerhq/live-env": "workspace:^",
"@ledgerhq/live-network": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"@ledgerhq/types-cryptoassets": "workspace:^",
"@ledgerhq/types-live": "workspace:^",
"axios": "1.7.7",
"bignumber.js": "^9.1.2",
"c32check": "1.1.3",
"invariant": "^2.2.4",
"lodash": "^4.17.21",
"ripple-address-codec": "^5.0.0",
qperrot marked this conversation as resolved.
Show resolved Hide resolved
"ripple-binary-codec": "^1.3.0",
qperrot marked this conversation as resolved.
Show resolved Hide resolved
"rxjs": "^7.8.1",
"@stacks/network": "6.10.0",
"@stacks/transactions": "6.11.0",
"@zondax/ledger-stacks": "^1.0.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only related to nano app right ? shouldn't be in coin-module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in signer.ts for the interface StacksSigner I am moving it in devDependencies

},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
qperrot marked this conversation as resolved.
Show resolved Hide resolved
"@types/invariant": "^2.2.37",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.14.191",
"dotenv": "^16.4.5",
"expect": "^27.4.6",
"jest": "^29.7.0",
"ripple-keypairs": "^2.0.0",
"ts-jest": "^29.1.1",
"typescript": "^5.4.5"
},
"scripts": {
"clean": "rimraf lib lib-es",
"build": "tsc && tsc -m ES6 --outDir lib-es",
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-stacks.json",
"prewatch": "pnpm build",
"watch": "tsc --watch",
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
"lint:fix": "pnpm lint --fix",
"test": "jest",
"test-integ": "DOTENV_CONFIG_PATH=.env.integ.test jest --config=jest.integ.config.js",
"typecheck": "tsc --noEmit",
"unimported": "unimported"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import invariant from "invariant";
import { AccountBridge } from "@ledgerhq/types-live";
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
import { StacksOperation, Transaction } from "./types";
import { getTxToBroadcast } from "./bridge/utils/misc";
import { broadcastTx } from "./bridge/utils/api";
import { AccountBridge } from "@ledgerhq/types-live";
import invariant from "invariant";
import { broadcastTx } from "../network/api";
import { StacksOperation, Transaction } from "../types";
import { getTxToBroadcast } from "./utils/misc";

export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
signedOperation: { operation, signature, rawData },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BigNumber from "bignumber.js";
import { Account, OperationType } from "@ledgerhq/types-live";
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
import { StacksOperation, Transaction } from "./types";
import { getAddress } from "./bridge/utils/misc";
import { Account, OperationType } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";
import { StacksOperation, Transaction } from "../types";
import { getAddress } from "./utils/misc";

export const buildOptimisticOperation = (
account: Account,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AccountBridge } from "@ledgerhq/types-live";
import { Transaction } from "./types";
import BigNumber from "bignumber.js";
import { AnchorMode } from "@stacks/transactions";
import BigNumber from "bignumber.js";
import { Transaction } from "../types";

export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => ({
family: "stacks",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber } from "bignumber.js";
import type { CommonDeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
import type { Account, AccountLike } from "@ledgerhq/types-live";
import type { DeviceTransactionField } from "../../transaction";
import type { Transaction, TransactionStatus } from "./types";
import { BigNumber } from "bignumber.js";
import type { Transaction, TransactionStatus } from "../types";

export type ExtraDeviceTransactionField =
| {
Expand All @@ -15,6 +15,8 @@ export type ExtraDeviceTransactionField =
value: BigNumber;
};

export type DeviceTransactionField = CommonDeviceTransactionField | ExtraDeviceTransactionField;

function getDeviceTransactionConfig(input: {
account: AccountLike;
parentAccount: Account | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets/abandonseed";
import { AccountBridge } from "@ledgerhq/types-live";
import { StacksMainnet } from "@stacks/network";
import {
UnsignedTokenTransferOptions,
estimateTransaction,
makeUnsignedSTXTokenTransfer,
} from "@stacks/transactions";
import invariant from "invariant";
import BigNumber from "bignumber.js";
import { StacksMainnet } from "@stacks/network";
import { AccountBridge } from "@ledgerhq/types-live";
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets/abandonseed";
import invariant from "invariant";
import { StacksNetwork } from "../network/api.types";
import { Transaction } from "../types";
import { createTransaction } from "./createTransaction";
import { StacksNetwork } from "./bridge/utils/api.types";
import { Transaction } from "./types";

export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
NotEnoughBalance,
RecipientRequired,
} from "@ledgerhq/errors";
import BigNumber from "bignumber.js";
import { AccountBridge } from "@ledgerhq/types-live";
import { Transaction, TransactionStatus } from "./types";
import { validateAddress } from "./bridge/utils/addresses";
import { getAddress } from "./bridge/utils/misc";
import { StacksMemoTooLong } from "./errors";
import BigNumber from "bignumber.js";
import { StacksMemoTooLong } from "../errors";
import { Transaction, TransactionStatus } from "../types";
import { validateAddress } from "./utils/addresses";
import { getAddress } from "./utils/misc";

export const getTransactionStatus: AccountBridge<Transaction>["getTransactionStatus"] = async (
account,
Expand Down
64 changes: 64 additions & 0 deletions libs/coin-modules/coin-stacks/src/bridge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
makeAccountBridgeReceive,
makeScanAccounts,
makeSync,
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
import resolver from "../signer/index";
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
import { SignerContext } from "@ledgerhq/coin-framework/signer";
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
import type { Transaction, TransactionStatus, StacksSigner } from "../types";
import { getTransactionStatus } from "./getTransactionStatus";
import { estimateMaxSpendable } from "./estimateMaxSpendable";
import { prepareTransaction } from "./prepareTransaction";
import { createTransaction } from "./createTransaction";
import { getAccountShape } from "./synchronization";
import { buildSignOperation } from "./signOperation";
import { broadcast } from "./broadcast";

function buildCurrencyBridge(signerContext: SignerContext<StacksSigner>): CurrencyBridge {
const getAddress = resolver(signerContext);

const scanAccounts = makeScanAccounts({
getAccountShape,
getAddressFn: getAddressWrapper(getAddress),
});

return {
preload: () => Promise.resolve({}),
hydrate: () => {},
scanAccounts,
};
}

const sync = makeSync({ getAccountShape });

function buildAccountBridge(
signerContext: SignerContext<StacksSigner>,
): AccountBridge<Transaction, Account, TransactionStatus> {
const getAddress = resolver(signerContext);
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));

const signOperation = buildSignOperation(signerContext);

return {
estimateMaxSpendable,
createTransaction,
updateTransaction: defaultUpdateTransaction,
getTransactionStatus,
prepareTransaction,
sync,
receive,
signOperation,
broadcast,
};
}

export function createBridges(signerContext: SignerContext<StacksSigner>) {
return {
currencyBridge: buildCurrencyBridge(signerContext),
accountBridge: buildAccountBridge(signerContext),
};
}
export { prepareTransaction, estimateMaxSpendable };
qperrot marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading