@arkade-os/sdk 0.4.0-next.6 → 0.4.0-next.7
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.
|
@@ -273,21 +273,6 @@ class ReadonlyWallet {
|
|
|
273
273
|
await this.walletRepository.saveVtxos(address, allExtended);
|
|
274
274
|
return allExtended;
|
|
275
275
|
}
|
|
276
|
-
async getVirtualCoins(filter = { withRecoverable: true, withUnrolled: false }) {
|
|
277
|
-
const scripts = [base_1.hex.encode(this.offchainTapscript.pkScript)];
|
|
278
|
-
const response = await this.indexerProvider.getVtxos({ scripts });
|
|
279
|
-
const allVtxos = response.vtxos;
|
|
280
|
-
let vtxos = allVtxos.filter(_1.isSpendable);
|
|
281
|
-
// all recoverable vtxos are spendable by definition
|
|
282
|
-
if (!filter.withRecoverable) {
|
|
283
|
-
vtxos = vtxos.filter((vtxo) => !(0, _1.isRecoverable)(vtxo) && !(0, _1.isExpired)(vtxo));
|
|
284
|
-
}
|
|
285
|
-
if (filter.withUnrolled) {
|
|
286
|
-
const spentVtxos = allVtxos.filter((vtxo) => !(0, _1.isSpendable)(vtxo));
|
|
287
|
-
vtxos.push(...spentVtxos.filter((vtxo) => vtxo.isUnrolled));
|
|
288
|
-
}
|
|
289
|
-
return vtxos;
|
|
290
|
-
}
|
|
291
276
|
async getTransactionHistory() {
|
|
292
277
|
const scripts = await this.getWalletScripts();
|
|
293
278
|
const response = await this.indexerProvider.getVtxos({ scripts });
|
|
@@ -738,6 +723,10 @@ class Wallet extends ReadonlyWallet {
|
|
|
738
723
|
async getDelegatorManager() {
|
|
739
724
|
return this._delegatorManager;
|
|
740
725
|
}
|
|
726
|
+
/**
|
|
727
|
+
* @deprecated Use `send`
|
|
728
|
+
* @param params
|
|
729
|
+
*/
|
|
741
730
|
async sendBitcoin(params) {
|
|
742
731
|
if (params.amount <= 0) {
|
|
743
732
|
throw new Error("Amount must be positive");
|
|
@@ -971,7 +960,7 @@ class Wallet extends ReadonlyWallet {
|
|
|
971
960
|
async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, connectorsGraph) {
|
|
972
961
|
// the signed forfeits transactions to submit
|
|
973
962
|
const signedForfeits = [];
|
|
974
|
-
const vtxos = await this.
|
|
963
|
+
const vtxos = await this.getVtxos();
|
|
975
964
|
let settlementPsbt = btc_signer_1.Transaction.fromPSBT(base_1.base64.decode(event.commitmentTx));
|
|
976
965
|
let hasBoardingUtxos = false;
|
|
977
966
|
let connectorIndex = 0;
|
|
@@ -1290,7 +1279,7 @@ class Wallet extends ReadonlyWallet {
|
|
|
1290
1279
|
const recipients = (0, utils_1.validateRecipients)(args, Number(this.dustAmount));
|
|
1291
1280
|
const address = await this.getAddress();
|
|
1292
1281
|
const outputAddress = address_1.ArkAddress.decode(address);
|
|
1293
|
-
const virtualCoins = await this.
|
|
1282
|
+
const virtualCoins = await this.getVtxos({
|
|
1294
1283
|
withRecoverable: false,
|
|
1295
1284
|
});
|
|
1296
1285
|
// keep track of asset changes
|
|
@@ -1425,16 +1414,12 @@ class Wallet extends ReadonlyWallet {
|
|
|
1425
1414
|
* @returns The ark transaction id and server-signed checkpoint PSBTs (for bookkeeping)
|
|
1426
1415
|
*/
|
|
1427
1416
|
async buildAndSubmitOffchainTx(inputs, outputs) {
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
...input,
|
|
1435
|
-
tapLeafScript,
|
|
1436
|
-
tapTree,
|
|
1437
|
-
})), outputs, this.serverUnrollScript);
|
|
1417
|
+
const offchainTx = (0, arkTransaction_1.buildOffchainTx)(inputs.map((input) => {
|
|
1418
|
+
return {
|
|
1419
|
+
...input,
|
|
1420
|
+
tapLeafScript: input.forfeitTapLeafScript,
|
|
1421
|
+
};
|
|
1422
|
+
}), outputs, this.serverUnrollScript);
|
|
1438
1423
|
const signedVirtualTx = await this.identity.sign(offchainTx.arkTx);
|
|
1439
1424
|
const { arkTxid, signedCheckpointTxs } = await this.arkProvider.submitTx(base_1.base64.encode(signedVirtualTx.toPSBT()), offchainTx.checkpoints.map((c) => base_1.base64.encode(c.toPSBT())));
|
|
1440
1425
|
const finalCheckpoints = await Promise.all(signedCheckpointTxs.map(async (c) => {
|
|
@@ -268,21 +268,6 @@ export class ReadonlyWallet {
|
|
|
268
268
|
await this.walletRepository.saveVtxos(address, allExtended);
|
|
269
269
|
return allExtended;
|
|
270
270
|
}
|
|
271
|
-
async getVirtualCoins(filter = { withRecoverable: true, withUnrolled: false }) {
|
|
272
|
-
const scripts = [hex.encode(this.offchainTapscript.pkScript)];
|
|
273
|
-
const response = await this.indexerProvider.getVtxos({ scripts });
|
|
274
|
-
const allVtxos = response.vtxos;
|
|
275
|
-
let vtxos = allVtxos.filter(isSpendable);
|
|
276
|
-
// all recoverable vtxos are spendable by definition
|
|
277
|
-
if (!filter.withRecoverable) {
|
|
278
|
-
vtxos = vtxos.filter((vtxo) => !isRecoverable(vtxo) && !isExpired(vtxo));
|
|
279
|
-
}
|
|
280
|
-
if (filter.withUnrolled) {
|
|
281
|
-
const spentVtxos = allVtxos.filter((vtxo) => !isSpendable(vtxo));
|
|
282
|
-
vtxos.push(...spentVtxos.filter((vtxo) => vtxo.isUnrolled));
|
|
283
|
-
}
|
|
284
|
-
return vtxos;
|
|
285
|
-
}
|
|
286
271
|
async getTransactionHistory() {
|
|
287
272
|
const scripts = await this.getWalletScripts();
|
|
288
273
|
const response = await this.indexerProvider.getVtxos({ scripts });
|
|
@@ -732,6 +717,10 @@ export class Wallet extends ReadonlyWallet {
|
|
|
732
717
|
async getDelegatorManager() {
|
|
733
718
|
return this._delegatorManager;
|
|
734
719
|
}
|
|
720
|
+
/**
|
|
721
|
+
* @deprecated Use `send`
|
|
722
|
+
* @param params
|
|
723
|
+
*/
|
|
735
724
|
async sendBitcoin(params) {
|
|
736
725
|
if (params.amount <= 0) {
|
|
737
726
|
throw new Error("Amount must be positive");
|
|
@@ -965,7 +954,7 @@ export class Wallet extends ReadonlyWallet {
|
|
|
965
954
|
async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, connectorsGraph) {
|
|
966
955
|
// the signed forfeits transactions to submit
|
|
967
956
|
const signedForfeits = [];
|
|
968
|
-
const vtxos = await this.
|
|
957
|
+
const vtxos = await this.getVtxos();
|
|
969
958
|
let settlementPsbt = Transaction.fromPSBT(base64.decode(event.commitmentTx));
|
|
970
959
|
let hasBoardingUtxos = false;
|
|
971
960
|
let connectorIndex = 0;
|
|
@@ -1284,7 +1273,7 @@ export class Wallet extends ReadonlyWallet {
|
|
|
1284
1273
|
const recipients = validateRecipients(args, Number(this.dustAmount));
|
|
1285
1274
|
const address = await this.getAddress();
|
|
1286
1275
|
const outputAddress = ArkAddress.decode(address);
|
|
1287
|
-
const virtualCoins = await this.
|
|
1276
|
+
const virtualCoins = await this.getVtxos({
|
|
1288
1277
|
withRecoverable: false,
|
|
1289
1278
|
});
|
|
1290
1279
|
// keep track of asset changes
|
|
@@ -1419,16 +1408,12 @@ export class Wallet extends ReadonlyWallet {
|
|
|
1419
1408
|
* @returns The ark transaction id and server-signed checkpoint PSBTs (for bookkeeping)
|
|
1420
1409
|
*/
|
|
1421
1410
|
async buildAndSubmitOffchainTx(inputs, outputs) {
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
...input,
|
|
1429
|
-
tapLeafScript,
|
|
1430
|
-
tapTree,
|
|
1431
|
-
})), outputs, this.serverUnrollScript);
|
|
1411
|
+
const offchainTx = buildOffchainTx(inputs.map((input) => {
|
|
1412
|
+
return {
|
|
1413
|
+
...input,
|
|
1414
|
+
tapLeafScript: input.forfeitTapLeafScript,
|
|
1415
|
+
};
|
|
1416
|
+
}), outputs, this.serverUnrollScript);
|
|
1432
1417
|
const signedVirtualTx = await this.identity.sign(offchainTx.arkTx);
|
|
1433
1418
|
const { arkTxid, signedCheckpointTxs } = await this.arkProvider.submitTx(base64.encode(signedVirtualTx.toPSBT()), offchainTx.checkpoints.map((c) => base64.encode(c.toPSBT())));
|
|
1434
1419
|
const finalCheckpoints = await Promise.all(signedCheckpointTxs.map(async (c) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Packet } from "../extension/asset";
|
|
2
|
-
import { Asset, Recipient, VirtualCoin } from "./index";
|
|
2
|
+
import { Asset, ExtendedVirtualCoin, Recipient, VirtualCoin } from "./index";
|
|
3
3
|
/**
|
|
4
4
|
* Creates an asset packet from asset inputs and receivers.
|
|
5
5
|
* Groups inputs and outputs by asset ID and creates the Packet object
|
|
@@ -13,8 +13,8 @@ export declare function createAssetPacket(assetInputs: Map<number, Asset[]>, rec
|
|
|
13
13
|
* Selects coins that contain a specific asset.
|
|
14
14
|
* Returns coins sorted by amount (smallest first for better coin selection).
|
|
15
15
|
*/
|
|
16
|
-
export declare function selectCoinsWithAsset(coins:
|
|
17
|
-
selected:
|
|
16
|
+
export declare function selectCoinsWithAsset(coins: ExtendedVirtualCoin[], assetId: string, requiredAmount: bigint): {
|
|
17
|
+
selected: ExtendedVirtualCoin[];
|
|
18
18
|
totalAssetAmount: bigint;
|
|
19
19
|
};
|
|
20
20
|
export declare function computeAssetChange(inputAssets: Map<string, bigint>, outputAssets: Map<string, bigint>): Map<string, bigint>;
|
|
@@ -7,7 +7,7 @@ import { OnchainProvider } from "../providers/onchain";
|
|
|
7
7
|
import { ArkProvider, SettlementEvent, SignedIntent } from "../providers/ark";
|
|
8
8
|
import { SignerSession } from "../tree/signingSession";
|
|
9
9
|
import { Identity, ReadonlyIdentity } from "../identity";
|
|
10
|
-
import { ArkTransaction, Recipient, Coin, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IReadonlyWallet, IWallet, ReadonlyWalletConfig, SendBitcoinParams, SettleParams,
|
|
10
|
+
import { ArkTransaction, Recipient, Coin, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IReadonlyWallet, IWallet, ReadonlyWalletConfig, SendBitcoinParams, SettleParams, WalletBalance, WalletConfig, IAssetManager, IReadonlyAssetManager } from ".";
|
|
11
11
|
import { CSVMultisigTapscript } from "../script/tapscript";
|
|
12
12
|
import { Intent } from "../intent";
|
|
13
13
|
import { IndexerProvider } from "../providers/indexer";
|
|
@@ -74,7 +74,6 @@ export declare class ReadonlyWallet implements IReadonlyWallet {
|
|
|
74
74
|
getBoardingAddress(): Promise<string>;
|
|
75
75
|
getBalance(): Promise<WalletBalance>;
|
|
76
76
|
getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]>;
|
|
77
|
-
protected getVirtualCoins(filter?: GetVtxosFilter): Promise<VirtualCoin[]>;
|
|
78
77
|
getTransactionHistory(): Promise<ArkTransaction[]>;
|
|
79
78
|
getBoardingTxs(): Promise<{
|
|
80
79
|
boardingTxs: ArkTransaction[];
|
|
@@ -193,6 +192,10 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
193
192
|
*/
|
|
194
193
|
toReadonly(): Promise<ReadonlyWallet>;
|
|
195
194
|
getDelegatorManager(): Promise<IDelegatorManager | undefined>;
|
|
195
|
+
/**
|
|
196
|
+
* @deprecated Use `send`
|
|
197
|
+
* @param params
|
|
198
|
+
*/
|
|
196
199
|
sendBitcoin(params: SendBitcoinParams): Promise<string>;
|
|
197
200
|
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
198
201
|
private handleSettlementFinalizationEvent;
|
|
@@ -238,7 +241,7 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
238
241
|
* sign it, submit to the ark provider, and finalize.
|
|
239
242
|
* @returns The ark transaction id and server-signed checkpoint PSBTs (for bookkeeping)
|
|
240
243
|
*/
|
|
241
|
-
buildAndSubmitOffchainTx(inputs:
|
|
244
|
+
buildAndSubmitOffchainTx(inputs: ExtendedVirtualCoin[], outputs: TransactionOutput[]): Promise<{
|
|
242
245
|
arkTxid: string;
|
|
243
246
|
signedCheckpointTxs: string[];
|
|
244
247
|
}>;
|
|
@@ -251,8 +254,8 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
251
254
|
* @param targetAmount Target amount to reach in satoshis
|
|
252
255
|
* @returns Selected coins and change amount
|
|
253
256
|
*/
|
|
254
|
-
export declare function selectVirtualCoins(coins:
|
|
255
|
-
inputs:
|
|
257
|
+
export declare function selectVirtualCoins(coins: ExtendedVirtualCoin[], targetAmount: number): {
|
|
258
|
+
inputs: ExtendedVirtualCoin[];
|
|
256
259
|
changeAmount: bigint;
|
|
257
260
|
};
|
|
258
261
|
/**
|