Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@utxos/sdk",
"version": "0.0.77",
"version": "0.0.78",
"description": "UTXOS SDK - Web3 infrastructure platform for UTXO blockchains",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand Down Expand Up @@ -41,7 +41,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@buildonspark/spark-sdk": "^0.4.2",
"@buildonspark/spark-sdk": "0.5.0",
"@meshsdk/bitcoin": "1.9.0-beta.89",
"@meshsdk/common": "1.9.0-beta.89",
"@meshsdk/core-cst": "1.9.0-beta.89",
Expand Down
52 changes: 51 additions & 1 deletion src/chains/spark/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import axios, { AxiosInstance } from "axios";
import { openWindow, AddressSummary, OpenWindowResult, ApiError } from "../../";
import {
openWindow,
AddressSummary,
OpenWindowResult,
ApiError,
ExitSpeed,
} from "../../";

export type ValidSparkNetwork = "MAINNET" | "REGTEST";

Expand Down Expand Up @@ -214,6 +220,50 @@ export class Web3SparkWallet {
};
}

public async withdrawToBitcoin({
exitSpeed,
amountSats,
deductFeeFromWithdrawalAmount,
withdrawalAddress,
}: {
exitSpeed: ExitSpeed;
amountSats: number;
deductFeeFromWithdrawalAmount: boolean;
withdrawalAddress: string;
}) {
const res: OpenWindowResult = await openWindow(
{
method: "spark-withdraw-to-bitcoin",
exitSpeed,
withdrawalAddress,
amountSats: String(amountSats),
deductFeeFromWithdrawalAmount:
deductFeeFromWithdrawalAmount === true ? "true" : "false",
projectId: this.projectId,
networkId: String(this.networkId),
},
this.appUrl,
);

if (res.success === false) {
throw new ApiError({
code: 3,
info: "UserDeclined - User declined the transfer.",
});
}

if (res.data.method !== "spark-withdraw-to-bitcoin") {
throw new ApiError({
code: 2,
info: "Recieved the wrong response from wallet popover.",
});
}

return {
withdrawalId: res.data.withdrawalId,
};
}

public async signMessage({ message }: { message: string }) {
const res: OpenWindowResult = await openWindow(
{
Expand Down
2 changes: 2 additions & 0 deletions src/types/spark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,5 @@ declare enum TransferType {
COUNTER_SWAP = 40,
UNRECOGNIZED = -1,
}

export type ExitSpeed = "FAST" | "MEDIUM" | "SLOW";
10 changes: 10 additions & 0 deletions src/types/window/open-window-params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Web3AuthProvider } from "../core";
import { ExitSpeed } from "../spark";

/** in this schema you will see string versions of undefined & boolean, this type is exclusively used for converting into URLSearchParams (where undefined & booleans don't exist) */
export type OpenWindowParams =
Expand Down Expand Up @@ -100,6 +101,15 @@ export type OpenWindowParams =
networkId: string;
txId: string;
}
| {
method: "spark-withdraw-to-bitcoin";
projectId: string;
networkId: string;
exitSpeed: ExitSpeed;
amountSats: string;
deductFeeFromWithdrawalAmount: "true" | "false";
withdrawalAddress: string;
}
/** to be deprecated */
| {
method: "sign-tx";
Expand Down
4 changes: 4 additions & 0 deletions src/types/window/open-window-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export type OpenWindowResult =
method: "spark-claim-static-deposit";
transferId: string;
}
| {
method: "spark-withdraw-to-bitcoin";
withdrawalId: string;
}
/** to be deprecated */
| {
method: "sign-data";
Expand Down