@1sat/sweep-ui 0.0.6 → 0.0.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.
@@ -1,5 +1,5 @@
1
1
  import type { LegacyKeys } from "../types";
2
- import type { WalletInterface } from "@bsv/sdk";
2
+ import { type WalletInterface } from "@bsv/sdk";
3
3
  export interface SweepAppProps {
4
4
  legacyKeys?: LegacyKeys;
5
5
  wallet?: WalletInterface | null;
@@ -1 +1 @@
1
- {"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,QAAQ,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,aAAa,2CAiQrG"}
1
+ {"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAI5D,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,QAAQ,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,aAAa,2CA4QrG"}
package/dist/index.js CHANGED
@@ -1800,8 +1800,20 @@ import {
1800
1800
  sweepOrdinals,
1801
1801
  sweepBsv21
1802
1802
  } from "@1sat/actions";
1803
+ function getOwner(output) {
1804
+ return output.events?.find((e) => e.startsWith("own:"))?.slice(4);
1805
+ }
1806
+ function buildKeys(outputs, keyMap) {
1807
+ return outputs.map((output) => {
1808
+ const owner = getOwner(output);
1809
+ const key = owner ? keyMap.get(owner) : undefined;
1810
+ if (!key)
1811
+ throw new Error(`No key for output ${output.outpoint} (owner: ${owner})`);
1812
+ return key;
1813
+ });
1814
+ }
1803
1815
  async function executeSweep(params) {
1804
- const { wallet, wif, funding, ordinals, bsv21Tokens, amount, onProgress } = params;
1816
+ const { wallet, keys, funding, ordinals, bsv21Tokens, amount, onProgress } = params;
1805
1817
  const ctx = createContext2(wallet, { services: getServices(), chain: "main" });
1806
1818
  const result = {
1807
1819
  ordinalTxids: [],
@@ -1812,7 +1824,7 @@ async function executeSweep(params) {
1812
1824
  onProgress(`Sweeping ${funding.length} BSV UTXOs...`);
1813
1825
  try {
1814
1826
  const inputs = await prepareSweepInputs(ctx, funding);
1815
- const bsvResult = await sweepBsv.execute(ctx, { inputs, wif, amount });
1827
+ const bsvResult = await sweepBsv.execute(ctx, { inputs, keys: buildKeys(funding, keys), amount });
1816
1828
  if (bsvResult.error)
1817
1829
  result.errors.push(`BSV: ${bsvResult.error}`);
1818
1830
  else if (bsvResult.txid)
@@ -1825,7 +1837,7 @@ async function executeSweep(params) {
1825
1837
  onProgress(`Sweeping ${ordinals.length} ordinals...`);
1826
1838
  try {
1827
1839
  const inputs = await prepareSweepInputs(ctx, ordinals);
1828
- const ordResult = await sweepOrdinals.execute(ctx, { inputs, wif });
1840
+ const ordResult = await sweepOrdinals.execute(ctx, { inputs, keys: buildKeys(ordinals, keys) });
1829
1841
  if (ordResult.error)
1830
1842
  result.errors.push(`Ordinals: ${ordResult.error}`);
1831
1843
  else if (ordResult.txid)
@@ -1853,7 +1865,7 @@ async function executeSweep(params) {
1853
1865
  tokenId,
1854
1866
  amount: "0"
1855
1867
  })),
1856
- wif
1868
+ keys: buildKeys(tokens, keys)
1857
1869
  });
1858
1870
  if (tokenResult.error)
1859
1871
  result.errors.push(`BSV-21 (${tokenId.slice(0, 8)}): ${tokenResult.error}`);
@@ -2052,6 +2064,7 @@ async function legacyBurnOrdinals(params) {
2052
2064
  }
2053
2065
 
2054
2066
  // src/components/SweepApp.tsx
2067
+ import { PrivateKey as PrivateKey3 } from "@bsv/sdk";
2055
2068
  import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
2056
2069
  function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }) {
2057
2070
  const [walletConnected, setWalletConnected] = useState5(!!externalWallet);
@@ -2072,6 +2085,17 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }
2072
2085
  const resolveWallet = useCallback2(() => {
2073
2086
  return externalWallet ?? getWallet();
2074
2087
  }, [externalWallet]);
2088
+ const keyMap = useMemo(() => {
2089
+ if (!legacyKeys)
2090
+ return new Map;
2091
+ const map = new Map;
2092
+ map.set(deriveAddress(legacyKeys.payPk), PrivateKey3.fromWif(legacyKeys.payPk));
2093
+ map.set(deriveAddress(legacyKeys.ordPk), PrivateKey3.fromWif(legacyKeys.ordPk));
2094
+ if (legacyKeys.identityPk) {
2095
+ map.set(deriveAddress(legacyKeys.identityPk), PrivateKey3.fromWif(legacyKeys.identityPk));
2096
+ }
2097
+ return map;
2098
+ }, [legacyKeys]);
2075
2099
  const addTx = useCallback2((label, txid, error) => {
2076
2100
  setTxHistory((prev) => [...prev, { label, txid, timestamp: new Date, error }]);
2077
2101
  }, []);
@@ -2202,7 +2226,7 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }
2202
2226
  if (!wallet || !legacyKeys || !assets)
2203
2227
  return;
2204
2228
  await runOperation("Sweep BSV", async () => {
2205
- const result = await executeSweep({ wallet, wif: legacyKeys.payPk, funding: getSelectedFunding(), ordinals: [], bsv21Tokens: [], amount: sweepAmount ?? undefined, onProgress: setSweepProgress });
2229
+ const result = await executeSweep({ wallet, keys: keyMap, funding: getSelectedFunding(), ordinals: [], bsv21Tokens: [], amount: sweepAmount ?? undefined, onProgress: setSweepProgress });
2206
2230
  if (result.errors.length > 0)
2207
2231
  throw new Error(result.errors[0]);
2208
2232
  return result.bsvTxid ?? "";
@@ -2224,7 +2248,7 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }
2224
2248
  if (selected.length === 0)
2225
2249
  return;
2226
2250
  await runOperation(`Sweep ${selected.length} ordinal${selected.length !== 1 ? "s" : ""}`, async () => {
2227
- const result = await executeSweep({ wallet, wif: legacyKeys.payPk, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
2251
+ const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
2228
2252
  if (result.errors.length > 0)
2229
2253
  throw new Error(result.errors[0]);
2230
2254
  return result.ordinalTxids[0] ?? "";
@@ -2260,7 +2284,7 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }
2260
2284
  if (selected.length === 0)
2261
2285
  return;
2262
2286
  await runOperation(`Sweep ${selected.length} domain${selected.length !== 1 ? "s" : ""}`, async () => {
2263
- const result = await executeSweep({ wallet, wif: legacyKeys.payPk, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
2287
+ const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
2264
2288
  if (result.errors.length > 0)
2265
2289
  throw new Error(result.errors[0]);
2266
2290
  return result.ordinalTxids[0] ?? "";
@@ -1,5 +1,5 @@
1
1
  import type { IndexedOutput } from "@1sat/types";
2
- import type { WalletInterface } from "@bsv/sdk";
2
+ import { PrivateKey, type WalletInterface } from "@bsv/sdk";
3
3
  export interface SweepResult {
4
4
  bsvTxid?: string;
5
5
  ordinalTxids: string[];
@@ -8,7 +8,7 @@ export interface SweepResult {
8
8
  }
9
9
  export declare function executeSweep(params: {
10
10
  wallet: WalletInterface;
11
- wif: string;
11
+ keys: Map<string, PrivateKey>;
12
12
  funding: IndexedOutput[];
13
13
  ordinals: IndexedOutput[];
14
14
  bsv21Tokens: IndexedOutput[];
@@ -1 +1 @@
1
- {"version":3,"file":"sweeper.d.ts","sourceRoot":"","sources":["../../src/lib/sweeper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGhD,MAAM,WAAW,WAAW;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,eAAe,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,GAAG,OAAO,CAAC,WAAW,CAAC,CAkEvB"}
1
+ {"version":3,"file":"sweeper.d.ts","sourceRoot":"","sources":["../../src/lib/sweeper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAG5D,MAAM,WAAW,WAAW;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB;AAeD,wBAAsB,YAAY,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,GAAG,OAAO,CAAC,WAAW,CAAC,CAkEvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/sweep-ui",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Sweep UI components for migrating legacy BSV assets",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -12,7 +12,7 @@ import { executeSweep } from "../lib/sweeper";
12
12
  import { legacySendBsv, legacySendOrdinals, legacyBurnOrdinals } from "../lib/legacy-send";
13
13
  import { getWallet } from "../lib/wallet";
14
14
  import type { LegacyKeys } from "../types";
15
- import type { WalletInterface } from "@bsv/sdk";
15
+ import { PrivateKey, type WalletInterface } from "@bsv/sdk";
16
16
 
17
17
  type TabId = "ordinals" | "opns" | "bsv21" | "bsv20" | "locks";
18
18
 
@@ -44,6 +44,17 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, swee
44
44
  return externalWallet ?? getWallet();
45
45
  }, [externalWallet]);
46
46
 
47
+ const keyMap = useMemo(() => {
48
+ if (!legacyKeys) return new Map<string, PrivateKey>();
49
+ const map = new Map<string, PrivateKey>();
50
+ map.set(deriveAddress(legacyKeys.payPk), PrivateKey.fromWif(legacyKeys.payPk));
51
+ map.set(deriveAddress(legacyKeys.ordPk), PrivateKey.fromWif(legacyKeys.ordPk));
52
+ if (legacyKeys.identityPk) {
53
+ map.set(deriveAddress(legacyKeys.identityPk), PrivateKey.fromWif(legacyKeys.identityPk));
54
+ }
55
+ return map;
56
+ }, [legacyKeys]);
57
+
47
58
  const addTx = useCallback((label: string, txid: string, error?: string) => {
48
59
  setTxHistory((prev) => [...prev, { label, txid, timestamp: new Date(), error }]);
49
60
  }, []);
@@ -148,7 +159,7 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, swee
148
159
  const wallet = resolveWallet();
149
160
  if (!wallet || !legacyKeys || !assets) return;
150
161
  await runOperation("Sweep BSV", async () => {
151
- const result = await executeSweep({ wallet, wif: legacyKeys.payPk, funding: getSelectedFunding(), ordinals: [], bsv21Tokens: [], amount: sweepAmount ?? undefined, onProgress: setSweepProgress });
162
+ const result = await executeSweep({ wallet, keys: keyMap, funding: getSelectedFunding(), ordinals: [], bsv21Tokens: [], amount: sweepAmount ?? undefined, onProgress: setSweepProgress });
152
163
  if (result.errors.length > 0) throw new Error(result.errors[0]);
153
164
  return result.bsvTxid ?? "";
154
165
  });
@@ -168,7 +179,7 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, swee
168
179
  const selected = assets.ordinals.filter((o) => selectedOrdinals.has(o.outpoint));
169
180
  if (selected.length === 0) return;
170
181
  await runOperation(`Sweep ${selected.length} ordinal${selected.length !== 1 ? "s" : ""}`, async () => {
171
- const result = await executeSweep({ wallet, wif: legacyKeys.payPk, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
182
+ const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
172
183
  if (result.errors.length > 0) throw new Error(result.errors[0]);
173
184
  return result.ordinalTxids[0] ?? "";
174
185
  });
@@ -200,7 +211,7 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, swee
200
211
  const selected = assets.opnsNames.filter((o) => selectedOpns.has(o.outpoint));
201
212
  if (selected.length === 0) return;
202
213
  await runOperation(`Sweep ${selected.length} domain${selected.length !== 1 ? "s" : ""}`, async () => {
203
- const result = await executeSweep({ wallet, wif: legacyKeys.payPk, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
214
+ const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
204
215
  if (result.errors.length > 0) throw new Error(result.errors[0]);
205
216
  return result.ordinalTxids[0] ?? "";
206
217
  });
@@ -6,7 +6,7 @@ import {
6
6
  sweepBsv21,
7
7
  } from "@1sat/actions";
8
8
  import type { IndexedOutput } from "@1sat/types";
9
- import type { WalletInterface } from "@bsv/sdk";
9
+ import { PrivateKey, type WalletInterface } from "@bsv/sdk";
10
10
  import { getServices } from "./services";
11
11
 
12
12
  export interface SweepResult {
@@ -16,16 +16,29 @@ export interface SweepResult {
16
16
  errors: string[];
17
17
  }
18
18
 
19
+ function getOwner(output: IndexedOutput): string | undefined {
20
+ return output.events?.find((e) => e.startsWith("own:"))?.slice(4);
21
+ }
22
+
23
+ function buildKeys(outputs: IndexedOutput[], keyMap: Map<string, PrivateKey>): PrivateKey[] {
24
+ return outputs.map((output) => {
25
+ const owner = getOwner(output);
26
+ const key = owner ? keyMap.get(owner) : undefined;
27
+ if (!key) throw new Error(`No key for output ${output.outpoint} (owner: ${owner})`);
28
+ return key;
29
+ });
30
+ }
31
+
19
32
  export async function executeSweep(params: {
20
33
  wallet: WalletInterface;
21
- wif: string;
34
+ keys: Map<string, PrivateKey>;
22
35
  funding: IndexedOutput[];
23
36
  ordinals: IndexedOutput[];
24
37
  bsv21Tokens: IndexedOutput[];
25
38
  amount?: number;
26
39
  onProgress: (stage: string) => void;
27
40
  }): Promise<SweepResult> {
28
- const { wallet, wif, funding, ordinals, bsv21Tokens, amount, onProgress } = params;
41
+ const { wallet, keys, funding, ordinals, bsv21Tokens, amount, onProgress } = params;
29
42
  const ctx = createContext(wallet, { services: getServices(), chain: "main" });
30
43
 
31
44
  const result: SweepResult = {
@@ -38,7 +51,7 @@ export async function executeSweep(params: {
38
51
  onProgress(`Sweeping ${funding.length} BSV UTXOs...`);
39
52
  try {
40
53
  const inputs = await prepareSweepInputs(ctx, funding);
41
- const bsvResult = await sweepBsv.execute(ctx, { inputs, wif, amount });
54
+ const bsvResult = await sweepBsv.execute(ctx, { inputs, keys: buildKeys(funding, keys), amount });
42
55
  if (bsvResult.error) result.errors.push(`BSV: ${bsvResult.error}`);
43
56
  else if (bsvResult.txid) result.bsvTxid = bsvResult.txid;
44
57
  } catch (e) {
@@ -50,7 +63,7 @@ export async function executeSweep(params: {
50
63
  onProgress(`Sweeping ${ordinals.length} ordinals...`);
51
64
  try {
52
65
  const inputs = await prepareSweepInputs(ctx, ordinals);
53
- const ordResult = await sweepOrdinals.execute(ctx, { inputs, wif });
66
+ const ordResult = await sweepOrdinals.execute(ctx, { inputs, keys: buildKeys(ordinals, keys) });
54
67
  if (ordResult.error) result.errors.push(`Ordinals: ${ordResult.error}`);
55
68
  else if (ordResult.txid) result.ordinalTxids.push(ordResult.txid);
56
69
  } catch (e) {
@@ -78,7 +91,7 @@ export async function executeSweep(params: {
78
91
  tokenId,
79
92
  amount: "0",
80
93
  })),
81
- wif,
94
+ keys: buildKeys(tokens, keys),
82
95
  });
83
96
  if (tokenResult.error) result.errors.push(`BSV-21 (${tokenId.slice(0, 8)}): ${tokenResult.error}`);
84
97
  else if (tokenResult.txid) result.bsv21Txids.push(tokenResult.txid);