@buildonspark/spark-sdk 0.1.38 → 0.1.40
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 +12 -0
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +1 -1
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libspark_frost.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/armeabi-v7a/libspark_frost.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/armeabi-v7a/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86/libspark_frost.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86_64/libspark_frost.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86_64/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/arm64-v8a/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/arm64-v8a/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/armeabi-v7a/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/armeabi-v7a/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/arm64-v8a/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/arm64-v8a/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/armeabi-v7a/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/armeabi-v7a/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86/libuniffi_spark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86_64/libspark_frost.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86_64/libuniffi_spark_frost.so +0 -0
- package/dist/{RequestLightningSendInput-B4JdzclX.d.ts → RequestLightningSendInput-CJtcHOnu.d.ts} +1 -1
- package/dist/{RequestLightningSendInput-39_zGri6.d.cts → RequestLightningSendInput-DfmfqzZo.d.cts} +1 -1
- package/dist/address/index.d.cts +1 -1
- package/dist/address/index.d.ts +1 -1
- package/dist/address/index.js +2 -2
- package/dist/{chunk-W3EC5XSA.js → chunk-5MNQB2T4.js} +2 -2
- package/dist/chunk-ED3ZAFDI.js +784 -0
- package/dist/{chunk-VJTDG4BQ.js → chunk-HK6LPV6Z.js} +10 -1
- package/dist/{chunk-7WRK6WNJ.js → chunk-LHT4QTFK.js} +556 -41
- package/dist/{chunk-RAPBVYJY.js → chunk-RFCXPGDM.js} +26 -4
- package/dist/{chunk-DI7QXUQJ.js → chunk-W2VXS35Y.js} +4 -4
- package/dist/graphql/objects/index.d.cts +5 -4
- package/dist/graphql/objects/index.d.ts +5 -4
- package/dist/{index-CxAi2L8y.d.ts → index-BDEYgYxP.d.ts} +42 -4
- package/dist/{index-Dm17Ggfe.d.cts → index-CLdtdMU4.d.cts} +42 -4
- package/dist/index.cjs +1069 -40
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +33 -17
- package/dist/index.node.cjs +1069 -40
- package/dist/index.node.d.cts +6 -6
- package/dist/index.node.d.ts +6 -6
- package/dist/index.node.js +33 -17
- package/dist/native/index.cjs +1069 -40
- package/dist/native/index.d.cts +108 -5
- package/dist/native/index.d.ts +108 -5
- package/dist/native/index.js +1065 -40
- package/dist/{network-GFGEHkS4.d.cts → network-B10hBoHp.d.cts} +8 -1
- package/dist/{network-DobHpaV6.d.ts → network-CCgyIsGl.d.ts} +8 -1
- package/dist/services/config.cjs +29 -12
- package/dist/services/config.d.cts +4 -4
- package/dist/services/config.d.ts +4 -4
- package/dist/services/config.js +5 -5
- package/dist/services/connection.d.cts +4 -4
- package/dist/services/connection.d.ts +4 -4
- package/dist/services/connection.js +2 -2
- package/dist/services/index.cjs +30 -13
- package/dist/services/index.d.cts +4 -4
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +8 -8
- package/dist/services/lrc-connection.d.cts +4 -4
- package/dist/services/lrc-connection.d.ts +4 -4
- package/dist/services/lrc-connection.js +1 -1
- package/dist/services/token-transactions.cjs +1 -1
- package/dist/services/token-transactions.d.cts +4 -4
- package/dist/services/token-transactions.d.ts +4 -4
- package/dist/services/token-transactions.js +3 -3
- package/dist/services/wallet-config.d.cts +4 -4
- package/dist/services/wallet-config.d.ts +4 -4
- package/dist/signer/signer.cjs +23 -6
- package/dist/signer/signer.d.cts +3 -2
- package/dist/signer/signer.d.ts +3 -2
- package/dist/signer/signer.js +1 -1
- package/dist/{signer-DFGw9RRp.d.ts → signer-C5h1DpjF.d.ts} +4 -1
- package/dist/{signer-C1t40Wus.d.cts → signer-CYwn7h9U.d.cts} +4 -1
- package/dist/types/index.d.cts +4 -3
- package/dist/types/index.d.ts +4 -3
- package/dist/utils/index.cjs +891 -2
- package/dist/utils/index.d.cts +62 -6
- package/dist/utils/index.d.ts +62 -6
- package/dist/utils/index.js +23 -7
- package/package.json +1 -1
- package/src/services/deposit.ts +23 -5
- package/src/services/token-transactions.ts +1 -1
- package/src/services/transfer.ts +218 -11
- package/src/services/tree-creation.ts +29 -14
- package/src/signer/signer.ts +47 -5
- package/src/spark-wallet/spark-wallet.ts +430 -4
- package/src/tests/integration/swap.test.ts +225 -0
- package/src/tests/integration/tree-creation.test.ts +5 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/mempool.ts +26 -1
- package/src/utils/network.ts +15 -0
- package/src/utils/transaction.ts +22 -2
- package/src/utils/unilateral-exit.ts +729 -0
- package/dist/chunk-E5SL7XTO.js +0 -301
- package/dist/{chunk-LIP2K6KR.js → chunk-2CDJZQN4.js} +3 -3
- package/dist/{chunk-RGWBSZIO.js → chunk-I4JI6TYN.js} +4 -4
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as btc from '@scure/btc-signer';
|
|
2
2
|
import { Transaction } from '@scure/btc-signer';
|
|
3
3
|
import { TransactionOutput, TransactionInput } from '@scure/btc-signer/psbt';
|
|
4
|
-
import { N as Network } from '../network-
|
|
5
|
-
export { L as LRC_WALLET_NETWORK, c as LRC_WALLET_NETWORK_TYPE, b as NetworkToProto, a as NetworkType, g as getNetwork, d as getNetworkFromAddress } from '../network-
|
|
6
|
-
import { i as SigningNonce, h as SigningCommitment } from '../signer-
|
|
7
|
-
export { V as VerifiableSecretShare, d as bigIntToPrivateKey, c as computerLagrangeCoefficients, e as evaluatePolynomial, f as fieldDiv, a as generatePolynomialForSecretSharing, g as getRandomBigInt, m as modInverse, r as recoverSecret, s as splitSecret, b as splitSecretWithProofs, v as validateShare } from '../signer-
|
|
8
|
-
import { j as OutputWithPreviousTransactionData, l as TransferPackage } from '../spark-DXYE9gMM.cjs';
|
|
4
|
+
import { N as Network } from '../network-B10hBoHp.cjs';
|
|
5
|
+
export { L as LRC_WALLET_NETWORK, c as LRC_WALLET_NETWORK_TYPE, b as NetworkToProto, a as NetworkType, g as getNetwork, d as getNetworkFromAddress, e as getNetworkFromString } from '../network-B10hBoHp.cjs';
|
|
6
|
+
import { i as SigningNonce, h as SigningCommitment } from '../signer-CYwn7h9U.cjs';
|
|
7
|
+
export { V as VerifiableSecretShare, d as bigIntToPrivateKey, c as computerLagrangeCoefficients, e as evaluatePolynomial, f as fieldDiv, a as generatePolynomialForSecretSharing, g as getRandomBigInt, m as modInverse, r as recoverSecret, s as splitSecret, b as splitSecretWithProofs, v as validateShare } from '../signer-CYwn7h9U.cjs';
|
|
8
|
+
import { j as OutputWithPreviousTransactionData, l as TransferPackage, g as SparkServiceClient } from '../spark-DXYE9gMM.cjs';
|
|
9
9
|
import '@buildonspark/lrc20-sdk';
|
|
10
10
|
import 'bitcoinjs-lib';
|
|
11
11
|
import '../BitcoinNetwork-TnABML0T.cjs';
|
|
@@ -41,6 +41,7 @@ declare function sumOfPrivateKeys(keys: Uint8Array[]): Uint8Array<ArrayBufferLik
|
|
|
41
41
|
declare function lastKeyWithTarget(target: Uint8Array, keys: Uint8Array[]): Uint8Array<ArrayBufferLike>;
|
|
42
42
|
|
|
43
43
|
declare function getLatestDepositTxId(address: string): Promise<string | null>;
|
|
44
|
+
declare function isTxBroadcast(txid: string, baseUrl: string, network?: any): Promise<boolean>;
|
|
44
45
|
|
|
45
46
|
declare function proofOfPossessionMessageHashForDepositAddress(userPubkey: Uint8Array, operatorPubkey: Uint8Array, depositAddress: string): Uint8Array;
|
|
46
47
|
|
|
@@ -65,6 +66,12 @@ declare function filterTokenBalanceForTokenPublicKey(tokenBalances: Map<string,
|
|
|
65
66
|
|
|
66
67
|
declare function getTransferPackageSigningPayload(transferID: string, transferPackage: TransferPackage): Uint8Array;
|
|
67
68
|
|
|
69
|
+
declare const DEFAULT_FEE_SATS: number;
|
|
70
|
+
/**
|
|
71
|
+
* Subtracts the default fee from the amount if it's greater than the fee.
|
|
72
|
+
* Returns the original amount if it's less than or equal to the fee.
|
|
73
|
+
*/
|
|
74
|
+
declare function maybeApplyFee(amount: bigint): bigint;
|
|
68
75
|
declare function createRefundTx(sequence: number, nodeOutPoint: TransactionInput, amountSats: bigint, receivingPubkey: Uint8Array, network: Network): Transaction;
|
|
69
76
|
declare function getCurrentTimelock(currSequence?: number): number;
|
|
70
77
|
declare function getTransactionSequence(currSequence?: number): number;
|
|
@@ -74,4 +81,53 @@ declare function getNextTransactionSequence(currSequence?: number, forRefresh?:
|
|
|
74
81
|
};
|
|
75
82
|
declare function getEphemeralAnchorOutput(): TransactionOutput;
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
interface LeafInfo {
|
|
85
|
+
leafId: string;
|
|
86
|
+
nodeTx: string;
|
|
87
|
+
refundTx: string;
|
|
88
|
+
}
|
|
89
|
+
interface Utxo {
|
|
90
|
+
txid: string;
|
|
91
|
+
vout: number;
|
|
92
|
+
value: bigint;
|
|
93
|
+
script: string;
|
|
94
|
+
publicKey: string;
|
|
95
|
+
}
|
|
96
|
+
interface FeeRate {
|
|
97
|
+
satPerVbyte: number;
|
|
98
|
+
}
|
|
99
|
+
interface FeeBumpTxPackage {
|
|
100
|
+
tx: string;
|
|
101
|
+
feeBumpPsbt?: string;
|
|
102
|
+
}
|
|
103
|
+
interface FeeBumpTxChain {
|
|
104
|
+
leafId: string;
|
|
105
|
+
txPackages: FeeBumpTxPackage[];
|
|
106
|
+
}
|
|
107
|
+
interface TxChain {
|
|
108
|
+
leafId: string;
|
|
109
|
+
transactions: string[];
|
|
110
|
+
}
|
|
111
|
+
interface BroadcastConfig {
|
|
112
|
+
bitcoinCoreRpcUrl?: string;
|
|
113
|
+
rpcUsername?: string;
|
|
114
|
+
rpcPassword?: string;
|
|
115
|
+
autoBroadcast?: boolean;
|
|
116
|
+
network?: "MAINNET" | "REGTEST" | "TESTNET" | "SIGNET" | "LOCAL";
|
|
117
|
+
}
|
|
118
|
+
interface BroadcastResult {
|
|
119
|
+
success: boolean;
|
|
120
|
+
txids?: string[];
|
|
121
|
+
error?: string;
|
|
122
|
+
broadcastedPackages?: number;
|
|
123
|
+
}
|
|
124
|
+
declare function isEphemeralAnchorOutput(script?: Uint8Array, amount?: bigint): boolean;
|
|
125
|
+
declare function constructUnilateralExitTxs(nodeHexStrings: string[], sparkClient?: SparkServiceClient, network?: any): Promise<TxChain[]>;
|
|
126
|
+
declare function constructUnilateralExitFeeBumpPackages(nodeHexStrings: string[], utxos: Utxo[], feeRate: FeeRate, electrsUrl: string, sparkClient?: SparkServiceClient, network?: any): Promise<FeeBumpTxChain[]>;
|
|
127
|
+
declare function constructFeeBumpTx(txHex: string, utxos: Utxo[], feeRate: FeeRate, previousFeeBumpTx?: string): {
|
|
128
|
+
feeBumpPsbt: string;
|
|
129
|
+
usedUtxos: Utxo[];
|
|
130
|
+
correctedParentTx?: string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export { type BroadcastConfig, type BroadcastResult, DEFAULT_FEE_SATS, type FeeBumpTxChain, type FeeBumpTxPackage, type FeeRate, type LeafInfo, Network, type TxChain, type Utxo, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, calculateAvailableTokenAmount, checkIfSelectedOutputsAreAvailable, collectResponses, computeTaprootKeyNoScript, constructFeeBumpTx, constructUnilateralExitFeeBumpPackages, constructUnilateralExitTxs, createRefundTx, createSigningCommitment, createSigningNonce, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, filterTokenBalanceForTokenPublicKey, generateAdaptorFromSignature, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getTransactionSequence, getTransferPackageSigningPayload, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, isEphemeralAnchorOutput, isTxBroadcast, lastKeyWithTarget, maybeApplyFee, proofOfPossessionMessageHashForDepositAddress, subtractPrivateKeys, subtractPublicKeys, sumOfPrivateKeys, validateOutboundAdaptorSignature };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as btc from '@scure/btc-signer';
|
|
2
2
|
import { Transaction } from '@scure/btc-signer';
|
|
3
3
|
import { TransactionOutput, TransactionInput } from '@scure/btc-signer/psbt';
|
|
4
|
-
import { N as Network } from '../network-
|
|
5
|
-
export { L as LRC_WALLET_NETWORK, c as LRC_WALLET_NETWORK_TYPE, b as NetworkToProto, a as NetworkType, g as getNetwork, d as getNetworkFromAddress } from '../network-
|
|
6
|
-
import { i as SigningNonce, h as SigningCommitment } from '../signer-
|
|
7
|
-
export { V as VerifiableSecretShare, d as bigIntToPrivateKey, c as computerLagrangeCoefficients, e as evaluatePolynomial, f as fieldDiv, a as generatePolynomialForSecretSharing, g as getRandomBigInt, m as modInverse, r as recoverSecret, s as splitSecret, b as splitSecretWithProofs, v as validateShare } from '../signer-
|
|
8
|
-
import { j as OutputWithPreviousTransactionData, l as TransferPackage } from '../spark-DXYE9gMM.js';
|
|
4
|
+
import { N as Network } from '../network-CCgyIsGl.js';
|
|
5
|
+
export { L as LRC_WALLET_NETWORK, c as LRC_WALLET_NETWORK_TYPE, b as NetworkToProto, a as NetworkType, g as getNetwork, d as getNetworkFromAddress, e as getNetworkFromString } from '../network-CCgyIsGl.js';
|
|
6
|
+
import { i as SigningNonce, h as SigningCommitment } from '../signer-C5h1DpjF.js';
|
|
7
|
+
export { V as VerifiableSecretShare, d as bigIntToPrivateKey, c as computerLagrangeCoefficients, e as evaluatePolynomial, f as fieldDiv, a as generatePolynomialForSecretSharing, g as getRandomBigInt, m as modInverse, r as recoverSecret, s as splitSecret, b as splitSecretWithProofs, v as validateShare } from '../signer-C5h1DpjF.js';
|
|
8
|
+
import { j as OutputWithPreviousTransactionData, l as TransferPackage, g as SparkServiceClient } from '../spark-DXYE9gMM.js';
|
|
9
9
|
import '@buildonspark/lrc20-sdk';
|
|
10
10
|
import 'bitcoinjs-lib';
|
|
11
11
|
import '../BitcoinNetwork-TnABML0T.js';
|
|
@@ -41,6 +41,7 @@ declare function sumOfPrivateKeys(keys: Uint8Array[]): Uint8Array<ArrayBufferLik
|
|
|
41
41
|
declare function lastKeyWithTarget(target: Uint8Array, keys: Uint8Array[]): Uint8Array<ArrayBufferLike>;
|
|
42
42
|
|
|
43
43
|
declare function getLatestDepositTxId(address: string): Promise<string | null>;
|
|
44
|
+
declare function isTxBroadcast(txid: string, baseUrl: string, network?: any): Promise<boolean>;
|
|
44
45
|
|
|
45
46
|
declare function proofOfPossessionMessageHashForDepositAddress(userPubkey: Uint8Array, operatorPubkey: Uint8Array, depositAddress: string): Uint8Array;
|
|
46
47
|
|
|
@@ -65,6 +66,12 @@ declare function filterTokenBalanceForTokenPublicKey(tokenBalances: Map<string,
|
|
|
65
66
|
|
|
66
67
|
declare function getTransferPackageSigningPayload(transferID: string, transferPackage: TransferPackage): Uint8Array;
|
|
67
68
|
|
|
69
|
+
declare const DEFAULT_FEE_SATS: number;
|
|
70
|
+
/**
|
|
71
|
+
* Subtracts the default fee from the amount if it's greater than the fee.
|
|
72
|
+
* Returns the original amount if it's less than or equal to the fee.
|
|
73
|
+
*/
|
|
74
|
+
declare function maybeApplyFee(amount: bigint): bigint;
|
|
68
75
|
declare function createRefundTx(sequence: number, nodeOutPoint: TransactionInput, amountSats: bigint, receivingPubkey: Uint8Array, network: Network): Transaction;
|
|
69
76
|
declare function getCurrentTimelock(currSequence?: number): number;
|
|
70
77
|
declare function getTransactionSequence(currSequence?: number): number;
|
|
@@ -74,4 +81,53 @@ declare function getNextTransactionSequence(currSequence?: number, forRefresh?:
|
|
|
74
81
|
};
|
|
75
82
|
declare function getEphemeralAnchorOutput(): TransactionOutput;
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
interface LeafInfo {
|
|
85
|
+
leafId: string;
|
|
86
|
+
nodeTx: string;
|
|
87
|
+
refundTx: string;
|
|
88
|
+
}
|
|
89
|
+
interface Utxo {
|
|
90
|
+
txid: string;
|
|
91
|
+
vout: number;
|
|
92
|
+
value: bigint;
|
|
93
|
+
script: string;
|
|
94
|
+
publicKey: string;
|
|
95
|
+
}
|
|
96
|
+
interface FeeRate {
|
|
97
|
+
satPerVbyte: number;
|
|
98
|
+
}
|
|
99
|
+
interface FeeBumpTxPackage {
|
|
100
|
+
tx: string;
|
|
101
|
+
feeBumpPsbt?: string;
|
|
102
|
+
}
|
|
103
|
+
interface FeeBumpTxChain {
|
|
104
|
+
leafId: string;
|
|
105
|
+
txPackages: FeeBumpTxPackage[];
|
|
106
|
+
}
|
|
107
|
+
interface TxChain {
|
|
108
|
+
leafId: string;
|
|
109
|
+
transactions: string[];
|
|
110
|
+
}
|
|
111
|
+
interface BroadcastConfig {
|
|
112
|
+
bitcoinCoreRpcUrl?: string;
|
|
113
|
+
rpcUsername?: string;
|
|
114
|
+
rpcPassword?: string;
|
|
115
|
+
autoBroadcast?: boolean;
|
|
116
|
+
network?: "MAINNET" | "REGTEST" | "TESTNET" | "SIGNET" | "LOCAL";
|
|
117
|
+
}
|
|
118
|
+
interface BroadcastResult {
|
|
119
|
+
success: boolean;
|
|
120
|
+
txids?: string[];
|
|
121
|
+
error?: string;
|
|
122
|
+
broadcastedPackages?: number;
|
|
123
|
+
}
|
|
124
|
+
declare function isEphemeralAnchorOutput(script?: Uint8Array, amount?: bigint): boolean;
|
|
125
|
+
declare function constructUnilateralExitTxs(nodeHexStrings: string[], sparkClient?: SparkServiceClient, network?: any): Promise<TxChain[]>;
|
|
126
|
+
declare function constructUnilateralExitFeeBumpPackages(nodeHexStrings: string[], utxos: Utxo[], feeRate: FeeRate, electrsUrl: string, sparkClient?: SparkServiceClient, network?: any): Promise<FeeBumpTxChain[]>;
|
|
127
|
+
declare function constructFeeBumpTx(txHex: string, utxos: Utxo[], feeRate: FeeRate, previousFeeBumpTx?: string): {
|
|
128
|
+
feeBumpPsbt: string;
|
|
129
|
+
usedUtxos: Utxo[];
|
|
130
|
+
correctedParentTx?: string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export { type BroadcastConfig, type BroadcastResult, DEFAULT_FEE_SATS, type FeeBumpTxChain, type FeeBumpTxPackage, type FeeRate, type LeafInfo, Network, type TxChain, type Utxo, addPrivateKeys, addPublicKeys, applyAdaptorToSignature, applyAdditiveTweakToPublicKey, calculateAvailableTokenAmount, checkIfSelectedOutputsAreAvailable, collectResponses, computeTaprootKeyNoScript, constructFeeBumpTx, constructUnilateralExitFeeBumpPackages, constructUnilateralExitTxs, createRefundTx, createSigningCommitment, createSigningNonce, decodeBytesToSigningCommitment, decodeBytesToSigningNonce, encodeSigningCommitmentToBytes, encodeSigningNonceToBytes, filterTokenBalanceForTokenPublicKey, generateAdaptorFromSignature, generateSignatureFromExistingAdaptor, getCurrentTimelock, getEphemeralAnchorOutput, getLatestDepositTxId, getNextTransactionSequence, getP2TRAddressFromPkScript, getP2TRAddressFromPublicKey, getP2TRScriptFromPublicKey, getP2WPKHAddressFromPublicKey, getRandomSigningNonce, getSigHashFromTx, getSigningCommitmentFromNonce, getTransactionSequence, getTransferPackageSigningPayload, getTxFromRawTxBytes, getTxFromRawTxHex, getTxId, getTxIdNoReverse, isEphemeralAnchorOutput, isTxBroadcast, lastKeyWithTarget, maybeApplyFee, proofOfPossessionMessageHashForDepositAddress, subtractPrivateKeys, subtractPublicKeys, sumOfPrivateKeys, validateOutboundAdaptorSignature };
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_FEE_SATS,
|
|
2
3
|
computeTaprootKeyNoScript,
|
|
4
|
+
constructFeeBumpTx,
|
|
5
|
+
constructUnilateralExitFeeBumpPackages,
|
|
6
|
+
constructUnilateralExitTxs,
|
|
3
7
|
createRefundTx,
|
|
4
8
|
getCurrentTimelock,
|
|
5
9
|
getEphemeralAnchorOutput,
|
|
@@ -16,26 +20,29 @@ import {
|
|
|
16
20
|
getTxFromRawTxHex,
|
|
17
21
|
getTxId,
|
|
18
22
|
getTxIdNoReverse,
|
|
23
|
+
isEphemeralAnchorOutput,
|
|
24
|
+
isTxBroadcast,
|
|
25
|
+
maybeApplyFee,
|
|
19
26
|
proofOfPossessionMessageHashForDepositAddress
|
|
20
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-ED3ZAFDI.js";
|
|
28
|
+
import "../chunk-A74XSEW3.js";
|
|
29
|
+
import "../chunk-S7KD6DDL.js";
|
|
21
30
|
import {
|
|
22
31
|
calculateAvailableTokenAmount,
|
|
23
32
|
checkIfSelectedOutputsAreAvailable,
|
|
24
33
|
collectResponses,
|
|
25
34
|
filterTokenBalanceForTokenPublicKey
|
|
26
35
|
} from "../chunk-57XLH3ZR.js";
|
|
27
|
-
import "../chunk-A74XSEW3.js";
|
|
28
|
-
import "../chunk-S7KD6DDL.js";
|
|
29
36
|
import {
|
|
30
37
|
LRC_WALLET_NETWORK,
|
|
31
38
|
LRC_WALLET_NETWORK_TYPE,
|
|
32
39
|
Network,
|
|
33
40
|
NetworkToProto,
|
|
34
41
|
getNetwork,
|
|
35
|
-
getNetworkFromAddress
|
|
36
|
-
|
|
42
|
+
getNetworkFromAddress,
|
|
43
|
+
getNetworkFromString
|
|
44
|
+
} from "../chunk-HK6LPV6Z.js";
|
|
37
45
|
import "../chunk-ZUVYYR5T.js";
|
|
38
|
-
import "../chunk-HMLOC6TE.js";
|
|
39
46
|
import {
|
|
40
47
|
addPrivateKeys,
|
|
41
48
|
addPublicKeys,
|
|
@@ -70,11 +77,13 @@ import {
|
|
|
70
77
|
splitSecretWithProofs,
|
|
71
78
|
validateShare
|
|
72
79
|
} from "../chunk-MGPRLH6Q.js";
|
|
80
|
+
import "../chunk-HMLOC6TE.js";
|
|
73
81
|
import "../chunk-VTUGIIWI.js";
|
|
74
|
-
import "../chunk-C5LTJBI7.js";
|
|
75
82
|
import "../chunk-TWF35O6M.js";
|
|
83
|
+
import "../chunk-C5LTJBI7.js";
|
|
76
84
|
import "../chunk-MVRQ5US7.js";
|
|
77
85
|
export {
|
|
86
|
+
DEFAULT_FEE_SATS,
|
|
78
87
|
LRC_WALLET_NETWORK,
|
|
79
88
|
LRC_WALLET_NETWORK_TYPE,
|
|
80
89
|
Network,
|
|
@@ -89,6 +98,9 @@ export {
|
|
|
89
98
|
collectResponses,
|
|
90
99
|
computeTaprootKeyNoScript,
|
|
91
100
|
computerLagrangeCoefficients,
|
|
101
|
+
constructFeeBumpTx,
|
|
102
|
+
constructUnilateralExitFeeBumpPackages,
|
|
103
|
+
constructUnilateralExitTxs,
|
|
92
104
|
createRefundTx,
|
|
93
105
|
createSigningCommitment,
|
|
94
106
|
createSigningNonce,
|
|
@@ -107,6 +119,7 @@ export {
|
|
|
107
119
|
getLatestDepositTxId,
|
|
108
120
|
getNetwork,
|
|
109
121
|
getNetworkFromAddress,
|
|
122
|
+
getNetworkFromString,
|
|
110
123
|
getNextTransactionSequence,
|
|
111
124
|
getP2TRAddressFromPkScript,
|
|
112
125
|
getP2TRAddressFromPublicKey,
|
|
@@ -122,7 +135,10 @@ export {
|
|
|
122
135
|
getTxFromRawTxHex,
|
|
123
136
|
getTxId,
|
|
124
137
|
getTxIdNoReverse,
|
|
138
|
+
isEphemeralAnchorOutput,
|
|
139
|
+
isTxBroadcast,
|
|
125
140
|
lastKeyWithTarget,
|
|
141
|
+
maybeApplyFee,
|
|
126
142
|
modInverse,
|
|
127
143
|
proofOfPossessionMessageHashForDepositAddress,
|
|
128
144
|
recoverSecret,
|
package/package.json
CHANGED
package/src/services/deposit.ts
CHANGED
|
@@ -20,6 +20,10 @@ import {
|
|
|
20
20
|
import { subtractPublicKeys } from "../utils/keys.js";
|
|
21
21
|
import { getNetwork } from "../utils/network.js";
|
|
22
22
|
import { proofOfPossessionMessageHashForDepositAddress } from "../utils/proof.js";
|
|
23
|
+
import {
|
|
24
|
+
DEFAULT_FEE_SATS,
|
|
25
|
+
getEphemeralAnchorOutput,
|
|
26
|
+
} from "../utils/transaction.js";
|
|
23
27
|
import { WalletConfigService } from "./config.js";
|
|
24
28
|
import { ConnectionManager } from "./connection.js";
|
|
25
29
|
|
|
@@ -184,7 +188,7 @@ export class DepositService {
|
|
|
184
188
|
vout,
|
|
185
189
|
}: CreateTreeRootParams) {
|
|
186
190
|
// Create a root tx
|
|
187
|
-
const rootTx = new Transaction();
|
|
191
|
+
const rootTx = new Transaction({ version: 3 });
|
|
188
192
|
const output = depositTx.getOutput(vout);
|
|
189
193
|
if (!output) {
|
|
190
194
|
throw new ValidationError("Invalid deposit transaction output", {
|
|
@@ -203,6 +207,13 @@ export class DepositService {
|
|
|
203
207
|
});
|
|
204
208
|
}
|
|
205
209
|
|
|
210
|
+
// Calculate fee and adjust output amount
|
|
211
|
+
let outputAmount = amount;
|
|
212
|
+
/*if (outputAmount > DEFAULT_FEE_SATS) {
|
|
213
|
+
outputAmount = outputAmount - BigInt(DEFAULT_FEE_SATS);
|
|
214
|
+
}*/
|
|
215
|
+
|
|
216
|
+
// Create new output with fee-adjusted amount
|
|
206
217
|
rootTx.addInput({
|
|
207
218
|
txid: getTxId(depositTx),
|
|
208
219
|
index: vout,
|
|
@@ -210,16 +221,21 @@ export class DepositService {
|
|
|
210
221
|
|
|
211
222
|
rootTx.addOutput({
|
|
212
223
|
script,
|
|
213
|
-
amount,
|
|
224
|
+
amount: outputAmount,
|
|
214
225
|
});
|
|
215
226
|
|
|
227
|
+
rootTx.addOutput(getEphemeralAnchorOutput());
|
|
228
|
+
|
|
216
229
|
const rootNonceCommitment =
|
|
217
230
|
await this.config.signer.getRandomSigningCommitment();
|
|
218
231
|
const rootTxSighash = getSigHashFromTx(rootTx, 0, output);
|
|
219
232
|
|
|
220
233
|
// Create a refund tx
|
|
221
|
-
const refundTx = new Transaction();
|
|
234
|
+
const refundTx = new Transaction({ version: 3 });
|
|
222
235
|
const sequence = (1 << 30) | INITIAL_TIME_LOCK;
|
|
236
|
+
/* if (outputAmount > DEFAULT_FEE_SATS) {
|
|
237
|
+
outputAmount = outputAmount - BigInt(DEFAULT_FEE_SATS);
|
|
238
|
+
}*/
|
|
223
239
|
refundTx.addInput({
|
|
224
240
|
txid: getTxId(rootTx),
|
|
225
241
|
index: 0,
|
|
@@ -237,12 +253,14 @@ export class DepositService {
|
|
|
237
253
|
|
|
238
254
|
refundTx.addOutput({
|
|
239
255
|
script: refundPkScript,
|
|
240
|
-
amount:
|
|
256
|
+
amount: outputAmount,
|
|
241
257
|
});
|
|
242
258
|
|
|
259
|
+
refundTx.addOutput(getEphemeralAnchorOutput());
|
|
260
|
+
|
|
243
261
|
const refundNonceCommitment =
|
|
244
262
|
await this.config.signer.getRandomSigningCommitment();
|
|
245
|
-
const refundTxSighash = getSigHashFromTx(refundTx, 0,
|
|
263
|
+
const refundTxSighash = getSigHashFromTx(refundTx, 0, rootTx.getOutput(0));
|
|
246
264
|
|
|
247
265
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
248
266
|
this.config.getCoordinatorAddress(),
|
|
@@ -40,7 +40,7 @@ import { SigningOperator } from "./wallet-config.js";
|
|
|
40
40
|
import { hexToBytes } from "@noble/hashes/utils";
|
|
41
41
|
import { decodeSparkAddress } from "../address/index.js";
|
|
42
42
|
|
|
43
|
-
const MAX_TOKEN_OUTPUTS =
|
|
43
|
+
const MAX_TOKEN_OUTPUTS = 500;
|
|
44
44
|
|
|
45
45
|
export class TokenTransactionService {
|
|
46
46
|
protected readonly config: WalletConfigService;
|
package/src/services/transfer.ts
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
getEphemeralAnchorOutput,
|
|
50
50
|
getNextTransactionSequence,
|
|
51
51
|
getTransactionSequence,
|
|
52
|
+
maybeApplyFee,
|
|
52
53
|
} from "../utils/transaction.js";
|
|
53
54
|
import { getTransferPackageSigningPayload } from "../utils/transfer_package.js";
|
|
54
55
|
import { WalletConfigService } from "./config.js";
|
|
@@ -156,6 +157,42 @@ export class BaseTransferService {
|
|
|
156
157
|
return updatedTransfer;
|
|
157
158
|
}
|
|
158
159
|
|
|
160
|
+
async deliverTransferPackage(
|
|
161
|
+
transfer: Transfer,
|
|
162
|
+
leaves: LeafKeyTweak[],
|
|
163
|
+
refundSignatureMap: Map<string, Uint8Array>,
|
|
164
|
+
): Promise<Transfer> {
|
|
165
|
+
const keyTweakInputMap = await this.prepareSendTransferKeyTweaks(
|
|
166
|
+
transfer.id,
|
|
167
|
+
transfer.receiverIdentityPublicKey,
|
|
168
|
+
leaves,
|
|
169
|
+
refundSignatureMap,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const transferPackage = await this.prepareTransferPackage(
|
|
173
|
+
transfer.id,
|
|
174
|
+
keyTweakInputMap,
|
|
175
|
+
leaves,
|
|
176
|
+
transfer.receiverIdentityPublicKey,
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const sparkClient = await this.connectionManager.createSparkClient(
|
|
180
|
+
this.config.getCoordinatorAddress(),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const response = await sparkClient.finalize_transfer_with_transfer_package({
|
|
184
|
+
transferId: transfer.id,
|
|
185
|
+
ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
186
|
+
transferPackage,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (!response.transfer) {
|
|
190
|
+
throw new ValidationError("No transfer response from operator");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return response.transfer;
|
|
194
|
+
}
|
|
195
|
+
|
|
159
196
|
async sendTransferWithKeyTweaks(
|
|
160
197
|
leaves: LeafKeyTweak[],
|
|
161
198
|
receiverIdentityPubkey: Uint8Array,
|
|
@@ -1179,10 +1216,27 @@ export class TransferService extends BaseTransferService {
|
|
|
1179
1216
|
throw Error("Could not fetch tx input");
|
|
1180
1217
|
}
|
|
1181
1218
|
|
|
1182
|
-
const newTx = new Transaction({ allowUnknownOutputs: true });
|
|
1183
|
-
|
|
1184
|
-
|
|
1219
|
+
const newTx = new Transaction({ version: 3, allowUnknownOutputs: true });
|
|
1220
|
+
|
|
1221
|
+
// Apply fee to the main output
|
|
1222
|
+
const originalOutput = nodeTx.getOutput(0);
|
|
1223
|
+
if (!originalOutput) {
|
|
1224
|
+
throw Error("Could not get original output");
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
newTx.addOutput({
|
|
1228
|
+
script: originalOutput.script!,
|
|
1229
|
+
amount: originalOutput.amount!,
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
// Copy any additional outputs (like ephemeral anchors) without fee reduction
|
|
1233
|
+
for (let j = 1; j < nodeTx.outputsLength; j++) {
|
|
1234
|
+
const additionalOutput = nodeTx.getOutput(j);
|
|
1235
|
+
if (additionalOutput) {
|
|
1236
|
+
newTx.addOutput(additionalOutput);
|
|
1237
|
+
}
|
|
1185
1238
|
}
|
|
1239
|
+
|
|
1186
1240
|
if (i === 0) {
|
|
1187
1241
|
const currSequence = input.sequence;
|
|
1188
1242
|
|
|
@@ -1212,10 +1266,28 @@ export class TransferService extends BaseTransferService {
|
|
|
1212
1266
|
throw Error("leaf does not have refund tx");
|
|
1213
1267
|
}
|
|
1214
1268
|
const refundTx = getTxFromRawTxBytes(leaf?.refundTx);
|
|
1215
|
-
const newRefundTx = new Transaction({
|
|
1269
|
+
const newRefundTx = new Transaction({
|
|
1270
|
+
version: 3,
|
|
1271
|
+
allowUnknownOutputs: true,
|
|
1272
|
+
});
|
|
1273
|
+
|
|
1274
|
+
// Apply fee to the refund output
|
|
1275
|
+
const originalRefundOutput = refundTx.getOutput(0);
|
|
1276
|
+
if (!originalRefundOutput) {
|
|
1277
|
+
throw Error("Could not get original refund output");
|
|
1278
|
+
}
|
|
1216
1279
|
|
|
1217
|
-
|
|
1218
|
-
|
|
1280
|
+
newRefundTx.addOutput({
|
|
1281
|
+
script: originalRefundOutput.script!,
|
|
1282
|
+
amount: originalRefundOutput.amount!,
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
// Copy any additional outputs (like ephemeral anchors) without fee reduction
|
|
1286
|
+
for (let j = 1; j < refundTx.outputsLength; j++) {
|
|
1287
|
+
const additionalOutput = refundTx.getOutput(j);
|
|
1288
|
+
if (additionalOutput) {
|
|
1289
|
+
newRefundTx.addOutput(additionalOutput);
|
|
1290
|
+
}
|
|
1219
1291
|
}
|
|
1220
1292
|
|
|
1221
1293
|
const refundTxInput = refundTx.getInput(0);
|
|
@@ -1347,10 +1419,12 @@ export class TransferService extends BaseTransferService {
|
|
|
1347
1419
|
refundTxSignature: refundSignature,
|
|
1348
1420
|
});
|
|
1349
1421
|
|
|
1350
|
-
|
|
1422
|
+
const result = await sparkClient.finalize_node_signatures({
|
|
1351
1423
|
intent: SignatureIntent.REFRESH,
|
|
1352
1424
|
nodeSignatures,
|
|
1353
1425
|
});
|
|
1426
|
+
|
|
1427
|
+
return result;
|
|
1354
1428
|
}
|
|
1355
1429
|
|
|
1356
1430
|
async extendTimelock(node: TreeNode, signingPubKey: Uint8Array) {
|
|
@@ -1365,9 +1439,24 @@ export class TransferService extends BaseTransferService {
|
|
|
1365
1439
|
|
|
1366
1440
|
const { nextSequence: newNodeSequence } =
|
|
1367
1441
|
getNextTransactionSequence(refundSequence);
|
|
1368
|
-
const newNodeTx = new Transaction({
|
|
1442
|
+
const newNodeTx = new Transaction({
|
|
1443
|
+
version: 3,
|
|
1444
|
+
allowUnknownOutputs: true,
|
|
1445
|
+
});
|
|
1369
1446
|
newNodeTx.addInput({ ...newNodeOutPoint, sequence: newNodeSequence });
|
|
1370
|
-
|
|
1447
|
+
|
|
1448
|
+
// Apply fee to the new node transaction output
|
|
1449
|
+
const originalOutput = nodeTx.getOutput(0);
|
|
1450
|
+
if (!originalOutput) {
|
|
1451
|
+
throw Error("Could not get original node output");
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// const feeReducedAmount = maybeApplyFee(originalOutput.amount!);
|
|
1455
|
+
newNodeTx.addOutput({
|
|
1456
|
+
script: originalOutput.script!,
|
|
1457
|
+
amount: originalOutput.amount!, // feeReducedAmount,
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1371
1460
|
newNodeTx.addOutput(getEphemeralAnchorOutput());
|
|
1372
1461
|
|
|
1373
1462
|
const newRefundOutPoint: TransactionInput = {
|
|
@@ -1380,16 +1469,22 @@ export class TransferService extends BaseTransferService {
|
|
|
1380
1469
|
throw new Error("Amount not found in extendTimelock");
|
|
1381
1470
|
}
|
|
1382
1471
|
|
|
1472
|
+
// Apply fee to the refund transaction as well
|
|
1473
|
+
// const feeReducedRefundAmount = maybeApplyFee(amountSats);
|
|
1383
1474
|
const newRefundTx = createRefundTx(
|
|
1384
1475
|
initialSequence(),
|
|
1385
1476
|
newRefundOutPoint,
|
|
1386
|
-
amountSats,
|
|
1477
|
+
amountSats, // feeReducedRefundAmount,
|
|
1387
1478
|
signingPubKey,
|
|
1388
1479
|
this.config.getNetwork(),
|
|
1389
1480
|
);
|
|
1390
1481
|
|
|
1391
1482
|
const nodeSighash = getSigHashFromTx(newNodeTx, 0, nodeTx.getOutput(0));
|
|
1392
|
-
const refundSighash = getSigHashFromTx(
|
|
1483
|
+
const refundSighash = getSigHashFromTx(
|
|
1484
|
+
newRefundTx,
|
|
1485
|
+
0,
|
|
1486
|
+
newNodeTx.getOutput(0),
|
|
1487
|
+
);
|
|
1393
1488
|
|
|
1394
1489
|
const newNodeSigningJob = {
|
|
1395
1490
|
signingPublicKey: signingPubKey,
|
|
@@ -1483,4 +1578,116 @@ export class TransferService extends BaseTransferService {
|
|
|
1483
1578
|
],
|
|
1484
1579
|
});
|
|
1485
1580
|
}
|
|
1581
|
+
|
|
1582
|
+
async refreshTimelockRefundTx(node: TreeNode, signingPubKey: Uint8Array) {
|
|
1583
|
+
const nodeTx = getTxFromRawTxBytes(node.nodeTx);
|
|
1584
|
+
const refundTx = getTxFromRawTxBytes(node.refundTx);
|
|
1585
|
+
|
|
1586
|
+
const currSequence = refundTx.getInput(0).sequence || 0;
|
|
1587
|
+
const { nextSequence } = getNextTransactionSequence(currSequence);
|
|
1588
|
+
|
|
1589
|
+
const newRefundTx = new Transaction({
|
|
1590
|
+
version: 3,
|
|
1591
|
+
allowUnknownOutputs: true,
|
|
1592
|
+
});
|
|
1593
|
+
|
|
1594
|
+
// Apply fee to the refund output
|
|
1595
|
+
const originalRefundOutput = refundTx.getOutput(0);
|
|
1596
|
+
if (!originalRefundOutput) {
|
|
1597
|
+
throw Error("Could not get original refund output");
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
newRefundTx.addOutput({
|
|
1601
|
+
script: originalRefundOutput.script!,
|
|
1602
|
+
amount: originalRefundOutput.amount!,
|
|
1603
|
+
});
|
|
1604
|
+
|
|
1605
|
+
// Copy any additional outputs (like ephemeral anchors) without fee reduction
|
|
1606
|
+
for (let j = 1; j < refundTx.outputsLength; j++) {
|
|
1607
|
+
const additionalOutput = refundTx.getOutput(j);
|
|
1608
|
+
if (additionalOutput) {
|
|
1609
|
+
newRefundTx.addOutput(additionalOutput);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
const refundTxInput = refundTx.getInput(0);
|
|
1614
|
+
if (!refundTxInput) {
|
|
1615
|
+
throw Error("refund tx doesn't have input");
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
newRefundTx.addInput({
|
|
1619
|
+
...refundTxInput,
|
|
1620
|
+
sequence: nextSequence,
|
|
1621
|
+
});
|
|
1622
|
+
|
|
1623
|
+
const refundSigningJob = {
|
|
1624
|
+
signingPublicKey: signingPubKey,
|
|
1625
|
+
rawTx: newRefundTx.toBytes(),
|
|
1626
|
+
signingNonceCommitment:
|
|
1627
|
+
await this.config.signer.getRandomSigningCommitment(),
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
const sparkClient = await this.connectionManager.createSparkClient(
|
|
1631
|
+
this.config.getCoordinatorAddress(),
|
|
1632
|
+
);
|
|
1633
|
+
|
|
1634
|
+
const response = await sparkClient.refresh_timelock({
|
|
1635
|
+
leafId: node.id,
|
|
1636
|
+
ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
1637
|
+
signingJobs: [refundSigningJob],
|
|
1638
|
+
});
|
|
1639
|
+
|
|
1640
|
+
if (response.signingResults.length !== 1) {
|
|
1641
|
+
throw Error(
|
|
1642
|
+
`Expected 1 signing result, got ${response.signingResults.length}`,
|
|
1643
|
+
);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
const signingResult = response.signingResults[0];
|
|
1647
|
+
if (!signingResult || !refundSigningJob.signingNonceCommitment) {
|
|
1648
|
+
throw Error("Signing result or nonce commitment does not exist");
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
const rawTx = getTxFromRawTxBytes(refundSigningJob.rawTx);
|
|
1652
|
+
const txOut = nodeTx.getOutput(0);
|
|
1653
|
+
|
|
1654
|
+
const rawTxSighash = getSigHashFromTx(rawTx, 0, txOut);
|
|
1655
|
+
|
|
1656
|
+
const userSignature = await this.config.signer.signFrost({
|
|
1657
|
+
message: rawTxSighash,
|
|
1658
|
+
privateAsPubKey: signingPubKey,
|
|
1659
|
+
publicKey: signingPubKey,
|
|
1660
|
+
verifyingKey: signingResult.verifyingKey,
|
|
1661
|
+
selfCommitment: refundSigningJob.signingNonceCommitment,
|
|
1662
|
+
statechainCommitments:
|
|
1663
|
+
signingResult.signingResult?.signingNonceCommitments,
|
|
1664
|
+
adaptorPubKey: new Uint8Array(),
|
|
1665
|
+
});
|
|
1666
|
+
|
|
1667
|
+
const signature = await this.config.signer.aggregateFrost({
|
|
1668
|
+
message: rawTxSighash,
|
|
1669
|
+
statechainSignatures: signingResult.signingResult?.signatureShares,
|
|
1670
|
+
statechainPublicKeys: signingResult.signingResult?.publicKeys,
|
|
1671
|
+
verifyingKey: signingResult.verifyingKey,
|
|
1672
|
+
statechainCommitments:
|
|
1673
|
+
signingResult.signingResult?.signingNonceCommitments,
|
|
1674
|
+
selfCommitment: refundSigningJob.signingNonceCommitment,
|
|
1675
|
+
publicKey: signingPubKey,
|
|
1676
|
+
selfSignature: userSignature,
|
|
1677
|
+
adaptorPubKey: new Uint8Array(),
|
|
1678
|
+
});
|
|
1679
|
+
|
|
1680
|
+
const result = await sparkClient.finalize_node_signatures({
|
|
1681
|
+
intent: SignatureIntent.REFRESH,
|
|
1682
|
+
nodeSignatures: [
|
|
1683
|
+
{
|
|
1684
|
+
nodeId: node.id,
|
|
1685
|
+
nodeTxSignature: new Uint8Array(),
|
|
1686
|
+
refundTxSignature: signature,
|
|
1687
|
+
},
|
|
1688
|
+
],
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
return result;
|
|
1692
|
+
}
|
|
1486
1693
|
}
|