@hardkas/tx-builder 0.8.5-alpha → 0.8.9-alpha
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/dist/index.d.ts +9 -1
- package/dist/index.js +9 -7
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,14 @@ declare function estimateTransactionMass(input: {
|
|
|
48
48
|
*/
|
|
49
49
|
declare function estimateFeeFromMass(mass: bigint, feeRateSompiPerMass: bigint): bigint;
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Kaspa dust threshold in sompi.
|
|
53
|
+
* Based on the rusty-kaspa wallet heuristic for standard P2PK outputs:
|
|
54
|
+
* value * 1000 / (STANDARD_OUTPUT_SIZE_PLUS_INPUT_SIZE * 3) < MINIMUM_RELAY_TRANSACTION_FEE
|
|
55
|
+
* For standard outputs this equates to ~546 sompi.
|
|
56
|
+
* We use 600 as a conservative margin, consistent with the localnet.
|
|
57
|
+
*/
|
|
58
|
+
declare const DUST_THRESHOLD_SOMPI = 600n;
|
|
51
59
|
type SemanticVerificationSeverity = "info" | "warning" | "error" | "critical";
|
|
52
60
|
interface SemanticVerificationIssue {
|
|
53
61
|
code: string;
|
|
@@ -147,4 +155,4 @@ declare function createMockUtxo(input: {
|
|
|
147
155
|
readonly index?: number;
|
|
148
156
|
}): Utxo;
|
|
149
157
|
|
|
150
|
-
export { KASPA_MASS_CONSTANTS, type MassBreakdown, type MassEstimateResult, type Outpoint, type SemanticVerificationIssue, type SemanticVerificationResult, type SemanticVerificationSeverity, type SemanticVerifyContext, type Sompi, type TxBuildRequest, type TxOutput, type TxPlan, type Utxo, buildPaymentPlan, createMockUtxo, estimateFeeFromMass, estimateMass, estimateTransactionMass, verifySignedTxSemantics, verifyTxPlanSemantics, verifyTxReceiptSemantics };
|
|
158
|
+
export { DUST_THRESHOLD_SOMPI, KASPA_MASS_CONSTANTS, type MassBreakdown, type MassEstimateResult, type Outpoint, type SemanticVerificationIssue, type SemanticVerificationResult, type SemanticVerificationSeverity, type SemanticVerifyContext, type Sompi, type TxBuildRequest, type TxOutput, type TxPlan, type Utxo, buildPaymentPlan, createMockUtxo, estimateFeeFromMass, estimateMass, estimateTransactionMass, verifySignedTxSemantics, verifyTxPlanSemantics, verifyTxReceiptSemantics };
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,7 @@ function estimateFeeFromMass(mass, feeRateSompiPerMass) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// src/verify.ts
|
|
67
|
+
var DUST_THRESHOLD_SOMPI = 600n;
|
|
67
68
|
function verifyTxPlanSemantics(plan, context = {}) {
|
|
68
69
|
const issues = [];
|
|
69
70
|
const addIssue = (code, severity, message, path) => {
|
|
@@ -145,20 +146,20 @@ function verifyTxPlanSemantics(plan, context = {}) {
|
|
|
145
146
|
`outputs[${i}]`
|
|
146
147
|
);
|
|
147
148
|
}
|
|
148
|
-
if (BigInt(o.amountSompi) <
|
|
149
|
+
if (BigInt(o.amountSompi) < DUST_THRESHOLD_SOMPI) {
|
|
149
150
|
addIssue(
|
|
150
151
|
"DUST_OUTPUT",
|
|
151
|
-
"
|
|
152
|
-
`Output ${i}
|
|
152
|
+
"error",
|
|
153
|
+
`Output ${i} is below dust threshold (${DUST_THRESHOLD_SOMPI} sompi): ${o.amountSompi} sompi`,
|
|
153
154
|
`outputs[${i}]`
|
|
154
155
|
);
|
|
155
156
|
}
|
|
156
157
|
});
|
|
157
|
-
if (plan.change && BigInt(plan.change.amountSompi) <
|
|
158
|
+
if (plan.change && BigInt(plan.change.amountSompi) < DUST_THRESHOLD_SOMPI) {
|
|
158
159
|
addIssue(
|
|
159
160
|
"DUST_CHANGE",
|
|
160
|
-
"
|
|
161
|
-
`Change output
|
|
161
|
+
"error",
|
|
162
|
+
`Change output is below dust threshold (${DUST_THRESHOLD_SOMPI} sompi): ${plan.change.amountSompi} sompi`,
|
|
162
163
|
"change"
|
|
163
164
|
);
|
|
164
165
|
}
|
|
@@ -319,7 +320,7 @@ function buildPaymentPlan(request) {
|
|
|
319
320
|
const estimatedFeeSompi = estimatedMass * request.feeRateSompiPerMass;
|
|
320
321
|
if (selectedAmount >= target + estimatedFeeSompi) {
|
|
321
322
|
const changeAmount = selectedAmount - target - estimatedFeeSompi;
|
|
322
|
-
const hasActualChange = changeAmount
|
|
323
|
+
const hasActualChange = changeAmount >= DUST_THRESHOLD_SOMPI;
|
|
323
324
|
let finalMass = estimatedMass;
|
|
324
325
|
let finalFee = estimatedFeeSompi;
|
|
325
326
|
if (!hasActualChange) {
|
|
@@ -376,6 +377,7 @@ function createMockUtxo(input) {
|
|
|
376
377
|
};
|
|
377
378
|
}
|
|
378
379
|
export {
|
|
380
|
+
DUST_THRESHOLD_SOMPI,
|
|
379
381
|
KASPA_MASS_CONSTANTS,
|
|
380
382
|
buildPaymentPlan,
|
|
381
383
|
createMockUtxo,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/tx-builder",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@hardkas/core": "0.8.
|
|
15
|
+
"@hardkas/core": "0.8.9-alpha"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"tsup": "^8.3.5",
|