@ledgerhq/coin-kaspa 2.2.2 → 2.2.3-nightly.20260923074751
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +5 -9
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +3 -2
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +6 -10
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +1 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/package.json +6 -7
- package/src/bridge/estimateMaxSpendable.test.ts +141 -0
- package/src/bridge/estimateMaxSpendable.ts +6 -11
- package/src/bridge/getTransactionStatus.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ledgerhq/coin-framework
|
|
2
2
|
|
|
3
|
+
## 2.2.3-nightly.20260923074751
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#22343](https://github.com/LedgerHQ/ledger-live/pull/22343) [`387619d`](https://github.com/LedgerHQ/ledger-live/commit/387619d7be17b3d7cd86031430769c6bb6638a68) Thanks [@gre-ledger](https://github.com/gre-ledger)! - Drop the `documentation` doc-gen CLI: remove the `doc` script and `documentation` devDependency, and the related `micromark` patch in `.pnpmfile.cjs`
|
|
8
|
+
|
|
9
|
+
- [#22073](https://github.com/LedgerHQ/ledger-live/pull/22073) [`bf2987f`](https://github.com/LedgerHQ/ledger-live/commit/bf2987f5dfdb90062c453b02f0512d89c0c55693) Thanks [@pawell24](https://github.com/pawell24)! - Cap estimateMaxSpendable to the 88-UTXO-per-tx limit, fixing UtxoLimitReachedError on accounts with more than 88 UTXOs (LIVE-32902)
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`387619d`](https://github.com/LedgerHQ/ledger-live/commit/387619d7be17b3d7cd86031430769c6bb6638a68), [`a62ad28`](https://github.com/LedgerHQ/ledger-live/commit/a62ad28e4900a887567fb61fb8f197af4fa5a23b), [`5d2f40f`](https://github.com/LedgerHQ/ledger-live/commit/5d2f40f470f859960e43a2a08755a962796f6beb), [`d59d123`](https://github.com/LedgerHQ/ledger-live/commit/d59d123a2ba037b44507b1f5424e31f05309ec26), [`40251b4`](https://github.com/LedgerHQ/ledger-live/commit/40251b41a62b2381c5c79410073a5f0b3c1fe629), [`e2134f5`](https://github.com/LedgerHQ/ledger-live/commit/e2134f5cffe4669ff5896e2b52904fe22218461b)]:
|
|
12
|
+
- @ledgerhq/ledger-wallet-framework@3.5.0-nightly.20260923074751
|
|
13
|
+
- @ledgerhq/types-live@6.125.0-nightly.20260923074751
|
|
14
|
+
- @ledgerhq/live-env@4.0.1-nightly.20260923074751
|
|
15
|
+
|
|
3
16
|
## 2.2.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAC9C,WAAW,EACX,YAAY,CACb,CAAC,sBAAsB,CAQvB,CAAC"}
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.estimateMaxSpendable = void 0;
|
|
4
4
|
const index_1 = require("@ledgerhq/ledger-wallet-framework/account/index");
|
|
5
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
6
5
|
const logic_1 = require("../logic");
|
|
6
|
+
const getTransactionStatus_1 = require("./getTransactionStatus");
|
|
7
7
|
const estimateMaxSpendable = async ({ account, parentAccount, transaction }) => {
|
|
8
8
|
const mainAccount = (0, index_1.getMainAccount)(account, parentAccount);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const maxSpendable = mainAccount.spendableBalance
|
|
14
|
-
.minus(506 * feeRate.toNumber())
|
|
15
|
-
.minus(1118 * mainAccount.activeAddressCount * feeRate.toNumber());
|
|
16
|
-
return maxSpendable.lt(0) ? (0, bignumber_js_1.BigNumber)(0) : maxSpendable;
|
|
9
|
+
const { utxos } = await (0, getTransactionStatus_1.getCachedUtxos)(mainAccount).catch(() => ({ utxos: [] }));
|
|
10
|
+
const isEcdsaRecipient = transaction?.recipient ? transaction.recipient.length > 67 : true;
|
|
11
|
+
const feeRate = (0, logic_1.getFeeRate)(transaction).toNumber() || 1;
|
|
12
|
+
return (0, logic_1.calcMaxSpendableAmount)(utxos, isEcdsaRecipient, feeRate);
|
|
17
13
|
};
|
|
18
14
|
exports.estimateMaxSpendable = estimateMaxSpendable;
|
|
19
15
|
//# sourceMappingURL=estimateMaxSpendable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":";;;AAAA,2EAAiF;AAEjF
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":";;;AAAA,2EAAiF;AAEjF,oCAA8D;AAE9D,iEAAwD;AAEjD,MAAM,oBAAoB,GAGL,KAAK,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,EAAE;IAC5E,MAAM,WAAW,GAAG,IAAA,sBAAc,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAE3D,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAA,qCAAc,EAAC,WAAW,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACjF,MAAM,gBAAgB,GAAG,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3F,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAExD,OAAO,IAAA,8BAAsB,EAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,CAAC;AAXW,QAAA,oBAAoB,GAApB,oBAAoB,CAW/B"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { KaspaAccount, Transaction, TransactionStatus } from "../types";
|
|
2
|
+
export declare const getCachedUtxos: import("@ledgerhq/live-network/cache").CacheRes<[account: KaspaAccount], {
|
|
3
|
+
utxos: import("../types").KaspaUtxo[];
|
|
4
|
+
accountAddresses: import("../types").AccountAddresses;
|
|
5
|
+
}>;
|
|
2
6
|
declare const getTransactionStatus: (account: KaspaAccount, transaction: Transaction) => Promise<TransactionStatus>;
|
|
3
7
|
export default getTransactionStatus;
|
|
4
8
|
//# sourceMappingURL=getTransactionStatus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGxE,eAAO,MAAM,cAAc;;;EAW1B,CAAC;AAEF,QAAA,MAAM,oBAAoB,YACf,YAAY,eACR,WAAW,KACvB,OAAO,CAAC,iBAAiB,CAkF3B,CAAC;eAEa,oBAAoB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCachedUtxos = void 0;
|
|
3
4
|
const errors_1 = require("@ledgerhq/ledger-wallet-framework/errors");
|
|
4
5
|
const errors_2 = require("../errors");
|
|
5
6
|
const cache_1 = require("@ledgerhq/live-network/cache");
|
|
@@ -7,7 +8,7 @@ const bignumber_js_1 = require("bignumber.js");
|
|
|
7
8
|
const logic_1 = require("../logic");
|
|
8
9
|
const constants_1 = require("../logic/constants");
|
|
9
10
|
const errors_3 = require("../types/errors");
|
|
10
|
-
|
|
11
|
+
exports.getCachedUtxos = (0, cache_1.makeLRUCache)(async (account) => {
|
|
11
12
|
const { compressedPublicKey, chainCode } = (0, logic_1.parseExtendedPublicKey)(Buffer.from(account.xpub, "hex"));
|
|
12
13
|
return await (0, logic_1.scanUtxos)(compressedPublicKey, chainCode);
|
|
13
14
|
}, (account) => {
|
|
@@ -40,7 +41,7 @@ const getTransactionStatus = async (account, transaction) => {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
if ((transaction.amount.gte(20000000) || transaction.useAllAmount) && !!transaction.recipient) {
|
|
43
|
-
const { utxos } = await getCachedUtxos(account);
|
|
44
|
+
const { utxos } = await (0, exports.getCachedUtxos)(account);
|
|
44
45
|
const maxSpendableAmount = (0, logic_1.calcMaxSpendableAmount)(utxos, transaction.recipient.length > 67, (0, logic_1.getFeeRate)(transaction).toNumber() || 1);
|
|
45
46
|
if (transaction.useAllAmount) {
|
|
46
47
|
transaction.amount = maxSpendableAmount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":";;;AAAA,qEAQkD;AAClD,sCAAsC;AACtC,wDAAqE;AACrE,+CAAyC;AACzC,oCAOkB;AAClB,kDAAsD;AAEtD,4CAAkF;AAErE,QAAA,cAAc,GAAG,IAAA,oBAAY,EACxC,KAAK,EAAE,OAAqB,EAAE,EAAE;IAC9B,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,IAAA,8BAAsB,EAC/D,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CACjC,CAAC;IACF,OAAO,MAAM,IAAA,iBAAS,EAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC,EACD,CAAC,OAAqB,EAAE,EAAE;IACxB,OAAO,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC;AACzB,CAAC,EACD,IAAA,eAAO,EAAC,CAAC,CAAC,CACX,CAAC;AAEF,MAAM,oBAAoB,GAAG,KAAK,EAChC,OAAqB,EACrB,WAAwB,EACI,EAAE;IAC9B,MAAM,MAAM,GAA0B,EAAE,CAAC;IACzC,MAAM,QAAQ,GAA0B,EAAE,CAAC;IAE3C,IAAI,WAAW,GAAc,IAAA,wBAAS,EAAC,CAAC,CAAC,CAAC;IAE1C,IAAI,CAAC,WA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,SAAS,CAAC,MAAM,GAAG,EAAE,EACjC,WAAW,CAAC,MAAM,EAClB,IAAA,kBAAU,EAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CACxC,CAAC;YACF,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC;YAEzB,IAAI,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChD,QAAQ,CAAC,UAAU,GAAG,IAAI,mBAAU,EAAE,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,QAAQ;QACR,aAAa,EAAE,WAAW;QAC1B,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;KACjD,CAAC;AACJ,CAAC,CAAC;kBAEa,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAC9C,WAAW,EACX,YAAY,CACb,CAAC,sBAAsB,CAQvB,CAAC"}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { getMainAccount } from "@ledgerhq/ledger-wallet-framework/account/index";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { calcMaxSpendableAmount, getFeeRate } from "../logic";
|
|
3
|
+
import { getCachedUtxos } from "./getTransactionStatus";
|
|
4
4
|
export const estimateMaxSpendable = async ({ account, parentAccount, transaction }) => {
|
|
5
5
|
const mainAccount = getMainAccount(account, parentAccount);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const maxSpendable = mainAccount.spendableBalance
|
|
11
|
-
.minus(506 * feeRate.toNumber())
|
|
12
|
-
.minus(1118 * mainAccount.activeAddressCount * feeRate.toNumber());
|
|
13
|
-
return maxSpendable.lt(0) ? BigNumber(0) : maxSpendable;
|
|
6
|
+
const { utxos } = await getCachedUtxos(mainAccount).catch(() => ({ utxos: [] }));
|
|
7
|
+
const isEcdsaRecipient = transaction?.recipient ? transaction.recipient.length > 67 : true;
|
|
8
|
+
const feeRate = getFeeRate(transaction).toNumber() || 1;
|
|
9
|
+
return calcMaxSpendableAmount(utxos, isEcdsaRecipient, feeRate);
|
|
14
10
|
};
|
|
15
11
|
//# sourceMappingURL=estimateMaxSpendable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AAEjF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AAEjF,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,CAAC,MAAM,oBAAoB,GAGL,KAAK,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,EAAE;IAC5E,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAE3D,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACjF,MAAM,gBAAgB,GAAG,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3F,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAExD,OAAO,sBAAsB,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,CAAC"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { KaspaAccount, Transaction, TransactionStatus } from "../types";
|
|
2
|
+
export declare const getCachedUtxos: import("@ledgerhq/live-network/cache").CacheRes<[account: KaspaAccount], {
|
|
3
|
+
utxos: import("..").KaspaUtxo[];
|
|
4
|
+
accountAddresses: import("..").AccountAddresses;
|
|
5
|
+
}>;
|
|
2
6
|
declare const getTransactionStatus: (account: KaspaAccount, transaction: Transaction) => Promise<TransactionStatus>;
|
|
3
7
|
export default getTransactionStatus;
|
|
4
8
|
//# sourceMappingURL=getTransactionStatus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGxE,eAAO,MAAM,cAAc;;;EAW1B,CAAC;AAEF,QAAA,MAAM,oBAAoB,YACf,YAAY,eACR,WAAW,KACvB,OAAO,CAAC,iBAAiB,CAkF3B,CAAC;eAEa,oBAAoB"}
|
|
@@ -5,7 +5,7 @@ import { BigNumber } from "bignumber.js";
|
|
|
5
5
|
import { calcMaxSpendableAmount, getFeeRate, isValidKaspaAddress, parseExtendedPublicKey, scanUtxos, selectUtxos, } from "../logic";
|
|
6
6
|
import { MAX_UTXOS_PER_TX } from "../logic/constants";
|
|
7
7
|
import { ReducedAmountUtxoWarning, UtxoLimitReachedError } from "../types/errors";
|
|
8
|
-
const getCachedUtxos = makeLRUCache(async (account) => {
|
|
8
|
+
export const getCachedUtxos = makeLRUCache(async (account) => {
|
|
9
9
|
const { compressedPublicKey, chainCode } = parseExtendedPublicKey(Buffer.from(account.xpub, "hex"));
|
|
10
10
|
return await scanUtxos(compressedPublicKey, chainCode);
|
|
11
11
|
}, (account) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,mBAAmB,EACnB,sBAAsB,EACtB,SAAS,EACT,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAElF,MAAM,cAAc,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,mBAAmB,EACnB,sBAAsB,EACtB,SAAS,EACT,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAElF,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CACxC,KAAK,EAAE,OAAqB,EAAE,EAAE;IAC9B,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,sBAAsB,CAC/D,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CACjC,CAAC;IACF,OAAO,MAAM,SAAS,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC,EACD,CAAC,OAAqB,EAAE,EAAE;IACxB,OAAO,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC;AACzB,CAAC,EACD,OAAO,CAAC,CAAC,CAAC,CACX,CAAC;AAEF,MAAM,oBAAoB,GAAG,KAAK,EAChC,OAAqB,EACrB,WAAwB,EACI,EAAE;IAC9B,MAAM,MAAM,GAA0B,EAAE,CAAC;IACzC,MAAM,QAAQ,GAA0B,EAAE,CAAC;IAE3C,IAAI,WAAW,GAAc,S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CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,EACjC,WAAW,CAAC,MAAM,EAClB,UAAU,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CACxC,CAAC;YACF,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC;YAEzB,IAAI,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChD,QAAQ,CAAC,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,QAAQ;QACR,aAAa,EAAE,WAAW;QAC1B,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;KACjD,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-kaspa",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3-nightly.20260923074751",
|
|
4
4
|
"description": "Ledger Kaspa Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -107,9 +107,9 @@
|
|
|
107
107
|
"lru-cache": "^7.14.1",
|
|
108
108
|
"prando": "^6.0.1",
|
|
109
109
|
"rxjs": "7.8.2",
|
|
110
|
-
"@ledgerhq/ledger-wallet-framework": "^3.
|
|
111
|
-
"@ledgerhq/
|
|
112
|
-
"@ledgerhq/live
|
|
110
|
+
"@ledgerhq/ledger-wallet-framework": "^3.5.0-nightly.20260923074751",
|
|
111
|
+
"@ledgerhq/live-env": "^4.0.1-nightly.20260923074751",
|
|
112
|
+
"@ledgerhq/types-live": "^6.125.0-nightly.20260923074751"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"@swc/core": "1.15.11",
|
|
@@ -126,9 +126,9 @@
|
|
|
126
126
|
"oxfmt": "0.67.0",
|
|
127
127
|
"oxlint": "1.82.0",
|
|
128
128
|
"timemachine": "^0.3.2",
|
|
129
|
+
"@ledgerhq/disable-network-setup": "^0.3.0",
|
|
129
130
|
"@ledgerhq/test-quarantine": "0.0.0",
|
|
130
|
-
"@ledgerhq/wallet-framework-test-setup": "^0.1.
|
|
131
|
-
"@ledgerhq/disable-network-setup": "^0.3.0"
|
|
131
|
+
"@ledgerhq/wallet-framework-test-setup": "^0.1.11-nightly.20260923074751"
|
|
132
132
|
},
|
|
133
133
|
"scripts": {
|
|
134
134
|
"clean": "rimraf lib lib-es",
|
|
@@ -137,7 +137,6 @@
|
|
|
137
137
|
"prewatch": "pnpm build",
|
|
138
138
|
"watch": "tsc --watch --project tsconfig.build.json",
|
|
139
139
|
"watch:es": "tsc --watch --project tsconfig.build.json -m esnext --moduleResolution bundler --outDir lib-es",
|
|
140
|
-
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
141
140
|
"lint": "oxlint src",
|
|
142
141
|
"lint:fix": "oxfmt src && oxlint src --fix --quiet",
|
|
143
142
|
"test": "jest",
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
jest.mock("@ledgerhq/ledger-wallet-framework/account/index");
|
|
2
|
+
jest.mock("./getTransactionStatus");
|
|
3
|
+
|
|
4
|
+
import type { DeepPartial, DeepPartialReturn } from "@ledgerhq/coin-module-framework/test/utils";
|
|
5
|
+
import { getMainAccount } from "@ledgerhq/ledger-wallet-framework/account/index";
|
|
6
|
+
import { BigNumber } from "bignumber.js";
|
|
7
|
+
import { KaspaAccount, KaspaUtxo, Transaction } from "../types";
|
|
8
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
9
|
+
import { getCachedUtxos } from "./getTransactionStatus";
|
|
10
|
+
|
|
11
|
+
const mockedGetMainAccount = jest.mocked(getMainAccount);
|
|
12
|
+
const mockedGetCachedUtxos = jest.mocked<DeepPartialReturn<typeof getCachedUtxos>>(getCachedUtxos);
|
|
13
|
+
|
|
14
|
+
const SCHNORR_RECIPIENT = "kaspa:qrp78nf43jaz3zk0j4dxga4ncdzk95xhun95hp6scyh6g6z7kwugy02wfw6ee";
|
|
15
|
+
const ECDSA_RECIPIENT = "kaspa:qyp8y7hlk9uj5l9vqsyz78x90yt84cujdytg93s8q8malhpdq6c4hpg9dyesk65";
|
|
16
|
+
|
|
17
|
+
const generateUtxoSet = (
|
|
18
|
+
count: number,
|
|
19
|
+
amount: BigNumber,
|
|
20
|
+
startBlockDaaScore: string,
|
|
21
|
+
): KaspaUtxo[] =>
|
|
22
|
+
Array.from(
|
|
23
|
+
{ length: count },
|
|
24
|
+
(_, i) =>
|
|
25
|
+
({
|
|
26
|
+
address: SCHNORR_RECIPIENT,
|
|
27
|
+
outpoint: { transactionId: i.toString(16).padStart(64, "0"), index: i },
|
|
28
|
+
utxoEntry: {
|
|
29
|
+
amount,
|
|
30
|
+
scriptPublicKey: { version: 0, scriptPublicKey: "" },
|
|
31
|
+
blockDaaScore: (Number(startBlockDaaScore) + i).toString(),
|
|
32
|
+
isCoinbase: true,
|
|
33
|
+
},
|
|
34
|
+
accountType: 0,
|
|
35
|
+
accountIndex: 0,
|
|
36
|
+
}) as KaspaUtxo,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const mockAccount: DeepPartial<KaspaAccount> = {
|
|
40
|
+
id: "mock_kaspa_account",
|
|
41
|
+
xpub: "mock_xpub",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const baseTransaction: DeepPartial<Transaction> = {
|
|
45
|
+
family: "kaspa",
|
|
46
|
+
recipient: SCHNORR_RECIPIENT,
|
|
47
|
+
feesStrategy: "custom",
|
|
48
|
+
customFeeRate: new BigNumber(1),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
describe("estimateMaxSpendable", () => {
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
mockedGetMainAccount.mockReturnValue(mockAccount as KaspaAccount);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("computes max spendable from the account's UTXOs when there are fewer than the 88-UTXO-per-tx limit", async () => {
|
|
58
|
+
const utxos = generateUtxoSet(5, new BigNumber(1_0000_0000), "12345");
|
|
59
|
+
mockedGetCachedUtxos.mockResolvedValue({ utxos });
|
|
60
|
+
|
|
61
|
+
const result = await estimateMaxSpendable({
|
|
62
|
+
account: mockAccount as KaspaAccount,
|
|
63
|
+
parentAccount: undefined,
|
|
64
|
+
transaction: baseTransaction as Transaction,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(result.toNumber()).toBe(5_0000_0000 - 5 * 1118 - 506);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("caps spendable amount to the 88-UTXO-per-tx limit when the account has more UTXOs than that", async () => {
|
|
71
|
+
const utxos = generateUtxoSet(100, new BigNumber(1_0000_0000), "12345");
|
|
72
|
+
mockedGetCachedUtxos.mockResolvedValue({ utxos });
|
|
73
|
+
|
|
74
|
+
const result = await estimateMaxSpendable({
|
|
75
|
+
account: mockAccount as KaspaAccount,
|
|
76
|
+
parentAccount: undefined,
|
|
77
|
+
transaction: baseTransaction as Transaction,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const cappedExpected = 88 * 1_0000_0000 - 88 * 1118 - 506;
|
|
81
|
+
const oldBuggyFormula = 100 * 1_0000_0000 - 506 - 1118;
|
|
82
|
+
|
|
83
|
+
expect(result.toNumber()).toBe(cappedExpected);
|
|
84
|
+
expect(result.toNumber()).toBeLessThan(oldBuggyFormula);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("deducts the extra ECDSA-recipient mass penalty", async () => {
|
|
88
|
+
const utxos = generateUtxoSet(5, new BigNumber(1_0000_0000), "12345");
|
|
89
|
+
mockedGetCachedUtxos.mockResolvedValue({ utxos });
|
|
90
|
+
|
|
91
|
+
const result = await estimateMaxSpendable({
|
|
92
|
+
account: mockAccount as KaspaAccount,
|
|
93
|
+
parentAccount: undefined,
|
|
94
|
+
transaction: { ...baseTransaction, recipient: ECDSA_RECIPIENT } as Transaction,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expect(result.toNumber()).toBe(5_0000_0000 - 5 * 1118 - 506 - 11);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("treats a missing transaction as the worst case (ECDSA) and does not throw", async () => {
|
|
101
|
+
const utxos = generateUtxoSet(5, new BigNumber(1_0000_0000), "12345");
|
|
102
|
+
mockedGetCachedUtxos.mockResolvedValue({ utxos });
|
|
103
|
+
|
|
104
|
+
const result = await estimateMaxSpendable({
|
|
105
|
+
account: mockAccount as KaspaAccount,
|
|
106
|
+
parentAccount: undefined,
|
|
107
|
+
transaction: undefined,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(result.toNumber()).toBe(5_0000_0000 - 5 * 1118 - 506 - 11);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("resolves to zero instead of rejecting when fetching UTXOs fails", async () => {
|
|
114
|
+
mockedGetCachedUtxos.mockRejectedValue(new Error("indexer unavailable"));
|
|
115
|
+
|
|
116
|
+
const result = await estimateMaxSpendable({
|
|
117
|
+
account: mockAccount as KaspaAccount,
|
|
118
|
+
parentAccount: undefined,
|
|
119
|
+
transaction: baseTransaction as Transaction,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(result.toNumber()).toBe(0);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("resolves the main account via getMainAccount before fetching UTXOs", async () => {
|
|
126
|
+
const parentAccount: DeepPartial<KaspaAccount> = {
|
|
127
|
+
id: "parent_kaspa_account",
|
|
128
|
+
xpub: "parent_xpub",
|
|
129
|
+
};
|
|
130
|
+
mockedGetMainAccount.mockReturnValue(parentAccount as KaspaAccount);
|
|
131
|
+
mockedGetCachedUtxos.mockResolvedValue({ utxos: [] });
|
|
132
|
+
|
|
133
|
+
await estimateMaxSpendable({
|
|
134
|
+
account: mockAccount as KaspaAccount,
|
|
135
|
+
parentAccount: undefined,
|
|
136
|
+
transaction: baseTransaction as Transaction,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
expect(mockedGetCachedUtxos).toHaveBeenCalledWith(parentAccount);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getMainAccount } from "@ledgerhq/ledger-wallet-framework/account/index";
|
|
2
2
|
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
-
import {
|
|
4
|
-
import { getFeeRate } from "../logic";
|
|
3
|
+
import { calcMaxSpendableAmount, getFeeRate } from "../logic";
|
|
5
4
|
import { KaspaAccount, Transaction } from "../types";
|
|
5
|
+
import { getCachedUtxos } from "./getTransactionStatus";
|
|
6
6
|
|
|
7
7
|
export const estimateMaxSpendable: AccountBridge<
|
|
8
8
|
Transaction,
|
|
@@ -10,14 +10,9 @@ export const estimateMaxSpendable: AccountBridge<
|
|
|
10
10
|
>["estimateMaxSpendable"] = async ({ account, parentAccount, transaction }) => {
|
|
11
11
|
const mainAccount = getMainAccount(account, parentAccount);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const feeRate: BigNumber = getFeeRate(transaction);
|
|
13
|
+
const { utxos } = await getCachedUtxos(mainAccount).catch(() => ({ utxos: [] }));
|
|
14
|
+
const isEcdsaRecipient = transaction?.recipient ? transaction.recipient.length > 67 : true;
|
|
15
|
+
const feeRate = getFeeRate(transaction).toNumber() || 1;
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
.minus(506 * feeRate.toNumber())
|
|
20
|
-
.minus(1118 * mainAccount.activeAddressCount * feeRate.toNumber());
|
|
21
|
-
|
|
22
|
-
return maxSpendable.lt(0) ? BigNumber(0) : maxSpendable;
|
|
17
|
+
return calcMaxSpendableAmount(utxos, isEcdsaRecipient, feeRate);
|
|
23
18
|
};
|
|
@@ -22,7 +22,7 @@ import { MAX_UTXOS_PER_TX } from "../logic/constants";
|
|
|
22
22
|
import { KaspaAccount, Transaction, TransactionStatus } from "../types";
|
|
23
23
|
import { ReducedAmountUtxoWarning, UtxoLimitReachedError } from "../types/errors";
|
|
24
24
|
|
|
25
|
-
const getCachedUtxos = makeLRUCache(
|
|
25
|
+
export const getCachedUtxos = makeLRUCache(
|
|
26
26
|
async (account: KaspaAccount) => {
|
|
27
27
|
const { compressedPublicKey, chainCode } = parseExtendedPublicKey(
|
|
28
28
|
Buffer.from(account.xpub, "hex"),
|