@1sat/wallet-toolbox 0.0.22 → 0.0.23

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.
@@ -15,6 +15,7 @@ export declare const ORDLOCK_PREFIX = "2097dfd76851bf465e8f715593b217714858bbe95
15
15
  export declare const ORDLOCK_SUFFIX = "615179547a75537a537a537a0079537a75527a527a7575615579008763567901c161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169587951797e58797eaa577961007982775179517958947f7551790128947f77517a75517a75618777777777777777777767557951876351795779a9876957795779ac777777777777777767006868";
16
16
  export declare const LOCK_PREFIX = "20d37f4de0d1c735b4d51a5572df0f3d9104d1d9e99db8694fdd1b1a92e1f0dce1757601687f76a9";
17
17
  export declare const LOCK_SUFFIX = "88ac7e7601207f75a9011488";
18
+ export declare const ONESAT_PROTOCOL: [0 | 1 | 2, string];
18
19
  export declare const MESSAGE_SIGNING_PROTOCOL: [0 | 1 | 2, string];
19
20
  export declare const MAX_INSCRIPTION_BYTES = 100000;
20
21
  export declare const MIN_UNLOCK_SATS = 1500;
@@ -21,7 +21,8 @@ export const ORDLOCK_SUFFIX = "615179547a75537a537a537a0079537a75527a527a7575615
21
21
  // Lock template constants
22
22
  export const LOCK_PREFIX = "20d37f4de0d1c735b4d51a5572df0f3d9104d1d9e99db8694fdd1b1a92e1f0dce1757601687f76a9";
23
23
  export const LOCK_SUFFIX = "88ac7e7601207f75a9011488";
24
- // Message signing protocol
24
+ // Protocol IDs
25
+ export const ONESAT_PROTOCOL = [1, "1sat"];
25
26
  export const MESSAGE_SIGNING_PROTOCOL = [1, "message signing"];
26
27
  // Constants
27
28
  export const MAX_INSCRIPTION_BYTES = 100_000;
@@ -5,11 +5,7 @@
5
5
  */
6
6
  import { P2PKH, PublicKey, Script, Utils } from "@bsv/sdk";
7
7
  import { Inscription } from "@bopen-io/templates";
8
- import { MAX_INSCRIPTION_BYTES, ORDINALS_BASKET } from "../constants";
9
- // ============================================================================
10
- // Constants
11
- // ============================================================================
12
- const ORDINAL_PROTOCOL = [1, "ordinal"];
8
+ import { MAX_INSCRIPTION_BYTES, ORDINALS_BASKET, ONESAT_PROTOCOL } from "../constants";
13
9
  // ============================================================================
14
10
  // Internal helpers
15
11
  // ============================================================================
@@ -58,7 +54,7 @@ export const inscribe = {
58
54
  }
59
55
  const keyID = Date.now().toString();
60
56
  const { publicKey } = await ctx.wallet.getPublicKey({
61
- protocolID: ORDINAL_PROTOCOL,
57
+ protocolID: ONESAT_PROTOCOL,
62
58
  keyID,
63
59
  counterparty: "self",
64
60
  forSelf: true,
@@ -75,7 +71,7 @@ export const inscribe = {
75
71
  basket: ORDINALS_BASKET,
76
72
  tags: [`type:${input.contentType}`],
77
73
  customInstructions: JSON.stringify({
78
- protocolID: ORDINAL_PROTOCOL,
74
+ protocolID: ONESAT_PROTOCOL,
79
75
  keyID,
80
76
  }),
81
77
  },
@@ -6,18 +6,13 @@
6
6
  */
7
7
  import { BigNumber, Hash, LockingScript, OP, P2PKH, PublicKey, Script, Transaction, TransactionSignature, UnlockingScript, Utils, } from "@bsv/sdk";
8
8
  import { OrdLock } from "@bopen-io/templates";
9
- import { ORDINALS_BASKET, ORDLOCK_PREFIX, ORDLOCK_SUFFIX } from "../constants";
10
- // ============================================================================
11
- // Constants
12
- // ============================================================================
13
- const ORDINAL_PROTOCOL = [1, "ordinal"];
14
- const ORDINAL_LISTING_PROTOCOL = [1, "ordinal listing"];
9
+ import { ORDINALS_BASKET, ORDLOCK_PREFIX, ORDLOCK_SUFFIX, ONESAT_PROTOCOL } from "../constants";
15
10
  // ============================================================================
16
11
  // Internal helpers
17
12
  // ============================================================================
18
13
  async function deriveCancelAddressInternal(ctx, outpoint) {
19
14
  const result = await ctx.wallet.getPublicKey({
20
- protocolID: ORDINAL_LISTING_PROTOCOL,
15
+ protocolID: ONESAT_PROTOCOL,
21
16
  keyID: outpoint,
22
17
  forSelf: true,
23
18
  });
@@ -97,7 +92,7 @@ export async function buildTransferOrdinal(ctx, request) {
97
92
  let recipientAddress;
98
93
  if (counterparty) {
99
94
  const { publicKey } = await ctx.wallet.getPublicKey({
100
- protocolID: ORDINAL_PROTOCOL,
95
+ protocolID: ONESAT_PROTOCOL,
101
96
  keyID: outpoint,
102
97
  counterparty,
103
98
  forSelf: false,
@@ -169,7 +164,7 @@ export async function buildListOrdinal(ctx, request) {
169
164
  basket: ORDINALS_BASKET,
170
165
  tags,
171
166
  customInstructions: JSON.stringify({
172
- protocolID: ORDINAL_LISTING_PROTOCOL,
167
+ protocolID: ONESAT_PROTOCOL,
173
168
  keyID: outpoint,
174
169
  }),
175
170
  },
@@ -248,7 +243,10 @@ export const transferOrdinal = {
248
243
  if ("error" in params) {
249
244
  return params;
250
245
  }
251
- const result = await ctx.wallet.createAction(params);
246
+ const result = await ctx.wallet.createAction({
247
+ ...params,
248
+ options: { randomizeOutputs: false },
249
+ });
252
250
  if (!result.txid) {
253
251
  return { error: "no-txid-returned" };
254
252
  }
@@ -283,7 +281,10 @@ export const listOrdinal = {
283
281
  if ("error" in params) {
284
282
  return params;
285
283
  }
286
- const result = await ctx.wallet.createAction(params);
284
+ const result = await ctx.wallet.createAction({
285
+ ...params,
286
+ options: { randomizeOutputs: false },
287
+ });
287
288
  if (!result.txid) {
288
289
  return { error: "no-txid-returned" };
289
290
  }
@@ -355,7 +356,7 @@ export const cancelListing = {
355
356
  customInstructions: JSON.stringify({ protocolID, keyID }),
356
357
  },
357
358
  ],
358
- options: { signAndProcess: false },
359
+ options: { signAndProcess: false, randomizeOutputs: false },
359
360
  });
360
361
  if ("error" in createResult && createResult.error) {
361
362
  return { error: String(createResult.error) };
@@ -473,7 +474,7 @@ export const purchaseOrdinal = {
473
474
  return { error: "not-an-ordlock-listing" };
474
475
  }
475
476
  const { publicKey } = await ctx.wallet.getPublicKey({
476
- protocolID: ORDINAL_PROTOCOL,
477
+ protocolID: ONESAT_PROTOCOL,
477
478
  keyID: outpoint,
478
479
  counterparty: "self",
479
480
  forSelf: true,
@@ -488,7 +489,7 @@ export const purchaseOrdinal = {
488
489
  basket: ORDINALS_BASKET,
489
490
  tags: [`type:${contentType}`, `origin:${origin}`],
490
491
  customInstructions: JSON.stringify({
491
- protocolID: ORDINAL_PROTOCOL,
492
+ protocolID: ONESAT_PROTOCOL,
492
493
  keyID: outpoint,
493
494
  }),
494
495
  });
@@ -523,7 +524,7 @@ export const purchaseOrdinal = {
523
524
  },
524
525
  ],
525
526
  outputs,
526
- options: { signAndProcess: false },
527
+ options: { signAndProcess: false, randomizeOutputs: false },
527
528
  });
528
529
  if ("error" in createResult && createResult.error) {
529
530
  return { error: String(createResult.error) };
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * Functions for sweeping assets from external wallets into a BRC-100 wallet.
5
5
  */
6
- import { P2PKH, PrivateKey, Transaction, } from "@bsv/sdk";
6
+ import { P2PKH, PrivateKey, PublicKey, Transaction, } from "@bsv/sdk";
7
+ import { ONESAT_PROTOCOL } from "../constants";
7
8
  export * from "./types";
8
9
  /**
9
10
  * Prepare sweep inputs from IndexedOutput objects by fetching locking scripts.
@@ -288,9 +289,9 @@ export const sweepOrdinals = {
288
289
  // Build outputs - one per ordinal, each 1 sat to derived address
289
290
  const outputs = [];
290
291
  for (const input of inputs) {
291
- // Derive a unique public key for this ordinal
292
+ // Derive a unique public key for this ordinal using the input outpoint as keyID
292
293
  const pubKeyResult = await ctx.wallet.getPublicKey({
293
- protocolID: [1, "ordinal"],
294
+ protocolID: ONESAT_PROTOCOL,
294
295
  keyID: input.outpoint,
295
296
  forSelf: true,
296
297
  });
@@ -298,24 +299,35 @@ export const sweepOrdinals = {
298
299
  return { error: `Failed to derive key for ${input.outpoint}` };
299
300
  }
300
301
  // Create P2PKH locking script from derived public key
301
- const derivedAddress = pubKeyResult.publicKey;
302
+ const derivedAddress = PublicKey.fromString(pubKeyResult.publicKey).toAddress();
302
303
  const lockingScript = new P2PKH().lock(derivedAddress);
304
+ // Build tags following ordinals API pattern
305
+ const tags = [];
306
+ if (input.contentType)
307
+ tags.push(`type:${input.contentType}`);
308
+ if (input.origin)
309
+ tags.push(`origin:${input.origin}`);
303
310
  outputs.push({
304
311
  lockingScript: lockingScript.toHex(),
305
312
  satoshis: 1,
306
313
  outputDescription: `Ordinal ${input.origin ?? input.outpoint}`,
307
314
  basket: "1sat",
308
- tags: ["insc", "origin"],
315
+ tags,
316
+ customInstructions: JSON.stringify({
317
+ protocolID: ONESAT_PROTOCOL,
318
+ keyID: input.outpoint,
319
+ }),
309
320
  });
310
321
  }
311
322
  const beefData = firstBeef.toBinary();
312
323
  // Create action to get signable transaction
324
+ // CRITICAL: randomizeOutputs must be false to preserve ordinal satoshi positions
313
325
  const createResult = await ctx.wallet.createAction({
314
326
  description: `Sweep ${inputs.length} ordinal${inputs.length !== 1 ? "s" : ""}`,
315
327
  inputBEEF: beefData,
316
328
  inputs: inputDescriptors,
317
329
  outputs,
318
- options: { signAndProcess: false },
330
+ options: { signAndProcess: false, randomizeOutputs: false },
319
331
  });
320
332
  if ("error" in createResult && createResult.error) {
321
333
  return { error: String(createResult.error) };
@@ -325,7 +337,6 @@ export const sweepOrdinals = {
325
337
  }
326
338
  // Sign each input with our external key
327
339
  const tx = Transaction.fromBEEF(createResult.signableTransaction.tx);
328
- console.log(`[sweepOrdinals] Transaction has ${tx.inputs.length} inputs, ${tx.outputs.length} outputs`);
329
340
  // Build a set of outpoints we control
330
341
  const ourOutpoints = new Set(inputs.map((input) => {
331
342
  const [txid, vout] = input.outpoint.split("_");
@@ -289,7 +289,7 @@ export const sendBsv21 = {
289
289
  inputDescription: "Token input",
290
290
  })),
291
291
  outputs,
292
- options: { signAndProcess: false },
292
+ options: { signAndProcess: false, randomizeOutputs: false },
293
293
  });
294
294
  if ("error" in createResult && createResult.error) {
295
295
  return { error: String(createResult.error) };
@@ -421,7 +421,7 @@ export const purchaseBsv21 = {
421
421
  },
422
422
  ],
423
423
  outputs,
424
- options: { signAndProcess: false },
424
+ options: { signAndProcess: false, randomizeOutputs: false },
425
425
  });
426
426
  if ("error" in createResult && createResult.error) {
427
427
  return { error: String(createResult.error) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/wallet-toolbox",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "BSV wallet library extending @bsv/wallet-toolbox with 1Sat Ordinals protocol support",
5
5
  "author": "1Sat Team",
6
6
  "license": "MIT",