@atomiqlabs/lp-lib 15.0.3 → 15.0.4
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.
|
@@ -12,6 +12,7 @@ const FromBtcAmountAssertions_1 = require("../assertions/FromBtcAmountAssertions
|
|
|
12
12
|
const crypto_1 = require("crypto");
|
|
13
13
|
const btc_signer_1 = require("@scure/btc-signer");
|
|
14
14
|
const SpvVaults_1 = require("./SpvVaults");
|
|
15
|
+
const BitcoinUtils_1 = require("../../utils/BitcoinUtils");
|
|
15
16
|
const TX_MAX_VSIZE = 16 * 1024;
|
|
16
17
|
class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
17
18
|
constructor(storageDirectory, vaultStorage, path, chainsData, swapPricing, bitcoin, bitcoinRpc, spvVaultSigner, config) {
|
|
@@ -342,7 +343,7 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
|
342
343
|
//Check correct psbt
|
|
343
344
|
for (let i = 1; i < transaction.inputsLength; i++) { //Skip first vault input
|
|
344
345
|
const txIn = transaction.getInput(i);
|
|
345
|
-
if ((0,
|
|
346
|
+
if ((0, BitcoinUtils_1.isLegacyInput)(txIn))
|
|
346
347
|
throw {
|
|
347
348
|
code: 20514,
|
|
348
349
|
msg: "Legacy (pre-segwit) inputs in tx are not allowed!"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLegacyInput = void 0;
|
|
4
|
+
const utxo_1 = require("@scure/btc-signer/utxo");
|
|
5
|
+
const btc_signer_1 = require("@scure/btc-signer");
|
|
6
|
+
function parsePushOpcode(script) {
|
|
7
|
+
if (script[0] === 0x00) {
|
|
8
|
+
return Uint8Array.from([]);
|
|
9
|
+
}
|
|
10
|
+
if (script[0] <= 0x4b) {
|
|
11
|
+
return script.slice(1, 1 + script[0]);
|
|
12
|
+
}
|
|
13
|
+
if (script[0] === 0x4c) {
|
|
14
|
+
return script.slice(2, 2 + script[1]);
|
|
15
|
+
}
|
|
16
|
+
if (script[0] === 0x4d) {
|
|
17
|
+
const length = Buffer.from(script.slice(1, 3)).readUInt16LE();
|
|
18
|
+
return script.slice(3, 3 + length);
|
|
19
|
+
}
|
|
20
|
+
if (script[0] === 0x4e) {
|
|
21
|
+
const length = Buffer.from(script.slice(1, 5)).readUInt32LE();
|
|
22
|
+
return script.slice(5, 5 + length);
|
|
23
|
+
}
|
|
24
|
+
if (script[0] === 0x4f) {
|
|
25
|
+
return Uint8Array.from([0x81]);
|
|
26
|
+
}
|
|
27
|
+
if (script[0] >= 0x51 && script[0] <= 0x60) {
|
|
28
|
+
return Uint8Array.from([script[0] - 0x50]);
|
|
29
|
+
}
|
|
30
|
+
throw new Error("No push opcode detected");
|
|
31
|
+
}
|
|
32
|
+
function isLegacyInput(input) {
|
|
33
|
+
const prevOut = (0, utxo_1.getPrevOut)(input);
|
|
34
|
+
const first = btc_signer_1.OutScript.decode(prevOut.script);
|
|
35
|
+
if (first.type === "tr" || first.type === "wsh" || first.type === "wpkh")
|
|
36
|
+
return false;
|
|
37
|
+
if (first.type === "sh") {
|
|
38
|
+
const redeemScript = input.redeemScript ?? parsePushOpcode(input.finalScriptSig);
|
|
39
|
+
const second = btc_signer_1.OutScript.decode(redeemScript);
|
|
40
|
+
if (second.type === "wsh" || second.type === "wpkh")
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
exports.isLegacyInput = isLegacyInput;
|
package/package.json
CHANGED
|
@@ -29,6 +29,7 @@ import {FromBtcAmountAssertions} from "../assertions/FromBtcAmountAssertions";
|
|
|
29
29
|
import {randomBytes} from "crypto";
|
|
30
30
|
import {getInputType, OutScript, Transaction} from "@scure/btc-signer";
|
|
31
31
|
import {SpvVaults, VAULT_DUST_AMOUNT} from "./SpvVaults";
|
|
32
|
+
import {isLegacyInput} from "../../utils/BitcoinUtils";
|
|
32
33
|
|
|
33
34
|
export type SpvVaultSwapHandlerConfig = SwapBaseConfig & {
|
|
34
35
|
vaultsCheckInterval: number,
|
|
@@ -471,7 +472,7 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
|
|
|
471
472
|
//Check correct psbt
|
|
472
473
|
for(let i=1;i<transaction.inputsLength;i++) { //Skip first vault input
|
|
473
474
|
const txIn = transaction.getInput(i);
|
|
474
|
-
if(
|
|
475
|
+
if(isLegacyInput(txIn)) throw {
|
|
475
476
|
code: 20514,
|
|
476
477
|
msg: "Legacy (pre-segwit) inputs in tx are not allowed!"
|
|
477
478
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {TransactionInput} from "@scure/btc-signer/psbt";
|
|
2
|
+
import {getPrevOut} from "@scure/btc-signer/utxo";
|
|
3
|
+
import {OutScript} from "@scure/btc-signer";
|
|
4
|
+
|
|
5
|
+
function parsePushOpcode(script: Uint8Array): Uint8Array {
|
|
6
|
+
if(script[0]===0x00) {
|
|
7
|
+
return Uint8Array.from([]);
|
|
8
|
+
}
|
|
9
|
+
if(script[0]<=0x4b) {
|
|
10
|
+
return script.slice(1, 1+script[0]);
|
|
11
|
+
}
|
|
12
|
+
if(script[0]===0x4c) {
|
|
13
|
+
return script.slice(2, 2+script[1]);
|
|
14
|
+
}
|
|
15
|
+
if(script[0]===0x4d) {
|
|
16
|
+
const length = Buffer.from(script.slice(1, 3)).readUInt16LE();
|
|
17
|
+
return script.slice(3, 3+length);
|
|
18
|
+
}
|
|
19
|
+
if(script[0]===0x4e) {
|
|
20
|
+
const length = Buffer.from(script.slice(1, 5)).readUInt32LE();
|
|
21
|
+
return script.slice(5, 5+length);
|
|
22
|
+
}
|
|
23
|
+
if(script[0]===0x4f) {
|
|
24
|
+
return Uint8Array.from([0x81]);
|
|
25
|
+
}
|
|
26
|
+
if(script[0]>=0x51 && script[0]<=0x60) {
|
|
27
|
+
return Uint8Array.from([script[0] - 0x50]);
|
|
28
|
+
}
|
|
29
|
+
throw new Error("No push opcode detected");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isLegacyInput(input: TransactionInput): boolean {
|
|
33
|
+
const prevOut = getPrevOut(input);
|
|
34
|
+
const first = OutScript.decode(prevOut.script);
|
|
35
|
+
if(first.type==="tr" || first.type==="wsh" || first.type==="wpkh") return false;
|
|
36
|
+
if(first.type==="sh") {
|
|
37
|
+
const redeemScript = input.redeemScript ?? parsePushOpcode(input.finalScriptSig);
|
|
38
|
+
const second = OutScript.decode(redeemScript);
|
|
39
|
+
if(second.type==="wsh" || second.type==="wpkh") return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|