b017 0.0.0-b1 → 0.2.0

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +568 -39
  2. package/LICENSE.txt +56 -56
  3. package/README.md +310 -206
  4. package/dist/index.d.ts +15 -7
  5. package/dist/index.js +14 -5
  6. package/dist/lib/boltLib.d.ts +29 -3
  7. package/dist/lib/boltLib.js +60 -12
  8. package/dist/lib/genesis.d.ts +20 -0
  9. package/dist/lib/genesis.js +45 -0
  10. package/dist/lib/multi/multiBoltLib.d.ts +22 -2
  11. package/dist/lib/multi/multiBoltLib.js +114 -129
  12. package/dist/lib/scanner/beef.d.ts +11 -0
  13. package/dist/lib/scanner/beef.js +63 -0
  14. package/dist/lib/scanner/fingerprints.d.ts +12 -2
  15. package/dist/lib/scanner/fingerprints.js +45 -12
  16. package/dist/lib/scanner/verifyEvents.d.ts +84 -6
  17. package/dist/lib/scanner/verifyEvents.js +520 -45
  18. package/dist/lib/single/singleAncestor.d.ts +27 -3
  19. package/dist/lib/single/singleAncestor.js +49 -18
  20. package/dist/lib/single/singleSpend.d.ts +12 -3
  21. package/dist/lib/single/singleSpend.js +48 -16
  22. package/dist/tokens/BOLT.d.ts +6 -5
  23. package/dist/tokens/GenesisMultiBOLT.d.ts +29 -0
  24. package/dist/tokens/GenesisMultiBOLT.js +48 -0
  25. package/dist/tokens/MultiBOLT.d.ts +17 -12
  26. package/dist/tokens/MultiBOLT.js +82 -74
  27. package/dist/tokens/templates/AuthBolt.sx.template.d.ts +35 -0
  28. package/dist/tokens/templates/AuthBolt.sx.template.js +82 -0
  29. package/dist/tokens/templates/FixedMulti.sx.template.d.ts +13 -0
  30. package/dist/tokens/templates/FixedMulti.sx.template.js +23 -0
  31. package/dist/tokens/templates/MinSimple.sx.template.d.ts +10 -1
  32. package/dist/tokens/templates/MinSimple.sx.template.js +15 -1
  33. package/dist/tokens/templates/OpenMulti.sx.template.d.ts +13 -0
  34. package/dist/tokens/templates/OpenMulti.sx.template.js +23 -0
  35. package/dist/tokens/templates/SerialBolt.sx.template.d.ts +23 -0
  36. package/dist/tokens/templates/SerialBolt.sx.template.js +61 -0
  37. package/dist/tokens/templates/SimpleMulti.sx.template.d.ts +12 -6
  38. package/dist/tokens/templates/SimpleMulti.sx.template.js +33 -25
  39. package/dist/tokens/templates/pay2Proof.d.ts +2 -1
  40. package/dist/tokens/templates/pay2Proof.js +1 -1
  41. package/package.json +64 -58
  42. package/dist/tokens/templates/MinSimpleBalance.sx.template.d.ts +0 -24
  43. package/dist/tokens/templates/MinSimpleBalance.sx.template.js +0 -59
  44. package/dist/tokens/templates/MinSimpleDiscount.sx.template.d.ts +0 -23
  45. package/dist/tokens/templates/MinSimpleDiscount.sx.template.js +0 -58
@@ -1,7 +1,7 @@
1
1
  import { Transaction, P2PKH, Hash, Utils } from "@bsv/sdk";
2
2
  import SimpleMultiTemplate from "./templates/SimpleMulti.sx.template.js";
3
3
  import Pay2ProofTemplate from "./templates/pay2Proof.js";
4
- import { verifyTx, buildOutpoint } from "../lib/boltLib.js";
4
+ import { verifyTx, buildOutpoint, p2pkhUnlock, toSigner, recipientPubKey, recipientSigner } from "../lib/boltLib.js";
5
5
  import { BOLT } from "./BOLT.js";
6
6
  // SimpleMultiBolt: optimised fungible token (16-byte balance, mandatory change + funding).
7
7
  // The runtime lock/unlock/melt assembler is in templates/SimpleMulti.sx.template.ts.
@@ -12,19 +12,20 @@ export class SimpleMultiBOLT extends BOLT {
12
12
  this.verifier = 'bsv';
13
13
  this.balance = [];
14
14
  this.balanceCommit = new Array(16).fill(0x00);
15
- this.outputIndexN = [0x00];
15
+ /** Lock pushes that lead the SimpleMultiBolt fields (0 here; FixedBOLT / OpenBOLT 2). */
16
+ this.leading = 0;
16
17
  this.createTransferInputs = (toPrivKey, _miscData, isCommitTx = true, forceNoChange = false, fundOverride = undefined, forceNoFund = false) => {
17
18
  // Determine ancestor proof vout for settles
18
19
  const hasAncestor = !isCommitTx && this.prevTxs.length >= 3;
19
20
  let proofVout = 1;
20
21
  if (hasAncestor) {
21
22
  const ancestorTx = this.prevTxs[this.prevTxs.length - 3];
22
- proofVout = ancestorTx.outputs.length >= 5 ? 2 : 1;
23
+ proofVout = this.findProofVout(ancestorTx, this.signer);
23
24
  }
24
25
  const input = {
25
26
  sourceTransaction: this.tx,
26
27
  sourceOutputIndex: this.voutIdx,
27
- unlockingScriptTemplate: new SimpleMultiTemplate().unlock(this.privKey, toPrivKey.toPublicKey().encode(true), this.prevTxs, forceNoChange, forceNoFund, [], // nextBalanceCommit empty for transfer (sim sets none); not 16 zeros
28
+ unlockingScriptTemplate: this.template().unlock(this.signer, recipientPubKey(toPrivKey), this.prevTxs, forceNoChange, forceNoFund, [], // nextBalanceCommit empty for transfer (sim sets none); not 16 zeros
28
29
  isCommitTx ? [0x21] : [0x20], // nextTxoType
29
30
  [0x00], // inputIndexN
30
31
  [], // pubKeyHash2
@@ -33,8 +34,9 @@ export class SimpleMultiBOLT extends BOLT {
33
34
  };
34
35
  const funding = fundOverride || {
35
36
  sourceTransaction: this.tx,
37
+ /* v8 ignore next -- a token being spent always has its tx */
36
38
  sourceOutputIndex: this.tx?.outputs ? this.tx?.outputs.length - 1 : 0,
37
- unlockingScriptTemplate: new P2PKH().unlock(this.privKey),
39
+ unlockingScriptTemplate: p2pkhUnlock(this.signer),
38
40
  sequence: 0xffffffff,
39
41
  };
40
42
  if (hasAncestor) {
@@ -42,7 +44,7 @@ export class SimpleMultiBOLT extends BOLT {
42
44
  const proof = {
43
45
  sourceTransaction: ancestorTx,
44
46
  sourceOutputIndex: proofVout,
45
- unlockingScriptTemplate: new Pay2ProofTemplate().unlock(this.privKey),
47
+ unlockingScriptTemplate: new Pay2ProofTemplate().unlock(this.signer),
46
48
  sequence: 0xffffffff,
47
49
  };
48
50
  return forceNoFund ? [input, proof] : [input, proof, funding];
@@ -50,16 +52,15 @@ export class SimpleMultiBOLT extends BOLT {
50
52
  return forceNoFund ? [input] : [input, funding];
51
53
  };
52
54
  this.createTransferOutputs = (toPrivKey, isCommitTx = true, forceNoChange = false, customChangeScript) => {
53
- const toPubKeyHash = Hash.hash160(toPrivKey.toPublicKey().encode(true));
55
+ const toPubKeyHash = Hash.hash160(recipientPubKey(toPrivKey));
54
56
  const pubKeyHashCommit = isCommitTx
55
57
  ? toPubKeyHash
56
58
  : new Array(20).fill(0x00);
57
- const tokenLocking = new SimpleMultiTemplate().lock(isCommitTx
59
+ const tokenLocking = this.template().lock(isCommitTx
58
60
  ? this.pubKey
59
- : toPrivKey.toPublicKey().encode(true), this.prevTxs, this.balance, this.balanceCommit, pubKeyHashCommit, new Array(20).fill(0x00), // pubKeyHashCommit2
61
+ : recipientPubKey(toPrivKey), this.prevTxs, this.balance, this.balanceCommit, pubKeyHashCommit, new Array(20).fill(0x00), // pubKeyHashCommit2
60
62
  new Array(36).fill(0x00), // otherGrandparentOutpoint
61
63
  isCommitTx ? [0x21] : [0x20], // txoType
62
- [0x00], // outputIndexN
63
64
  isCommitTx ? (this.voutIdx || 0) : 0);
64
65
  const tokenOut = { lockingScript: tokenLocking, satoshis: 1 };
65
66
  const proofOut = {
@@ -86,8 +87,13 @@ export class SimpleMultiBOLT extends BOLT {
86
87
  return cleanTx;
87
88
  };
88
89
  }
89
- async mint(privKey, sourceTransaction, _mintData = "", balance = [0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) {
90
- const pubKey = privKey.toPublicKey().encode(true);
90
+ /** The script template for this token type; FixedBOLT / OpenBOLT override it. */
91
+ template() {
92
+ return new SimpleMultiTemplate();
93
+ }
94
+ async mint(owner, sourceTransaction, mintData = "", balance = [0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) {
95
+ const signer = toSigner(owner);
96
+ const pubKey = signer.publicKey;
91
97
  const pubKeyHashStr = Utils.toHex(Hash.hash160(pubKey));
92
98
  const version = 2;
93
99
  let sourceOutputIndex = -1;
@@ -106,17 +112,18 @@ export class SimpleMultiBOLT extends BOLT {
106
112
  const input = {
107
113
  sourceTransaction,
108
114
  sourceOutputIndex,
109
- unlockingScriptTemplate: new P2PKH().unlock(privKey),
115
+ unlockingScriptTemplate: p2pkhUnlock(signer),
110
116
  sequence: 0xffffffff,
111
117
  };
112
118
  this.pubKeyHash = Hash.hash160(pubKey);
113
119
  this.balance = balance;
114
- const tokenLocking = new SimpleMultiTemplate().lock(pubKey, this.prevTxs, this.balance, new Array(16).fill(0x00), // balanceCommit = zeros
120
+ // the issuer's mint bytes (a string is UTF-8); only the genesis family writes them on chain
121
+ this.mintData = typeof mintData === "string" ? Array.from(Buffer.from(mintData, "utf8")) : [...mintData];
122
+ const tokenLocking = this.template().lock(pubKey, this.prevTxs, this.balance, new Array(16).fill(0x00), // balanceCommit = zeros
115
123
  new Array(20).fill(0x00), // pubKeyHashCommit
116
124
  new Array(20).fill(0x00), // pubKeyHashCommit2
117
125
  new Array(36).fill(0x00), // otherGrandparentOutpoint
118
- [0x20], // txoType = settle (genesis)
119
- [0x00]);
126
+ [0x20]);
120
127
  const tokenOut = {
121
128
  lockingScript: tokenLocking,
122
129
  satoshis: 1,
@@ -131,16 +138,14 @@ export class SimpleMultiBOLT extends BOLT {
131
138
  ]);
132
139
  await mintTx.fee(0);
133
140
  await mintTx.sign();
134
- let { valid } = verifyTx(mintTx);
135
- if (!valid)
136
- throw new Error("Mint tx not valid");
141
+ verifyTx(mintTx); // throws if the mint is not valid
137
142
  this.tx = mintTx;
138
143
  this.voutIdx = 0;
139
144
  this.prevTxs.push(this.tx);
140
145
  this.pubKey = pubKey;
141
146
  this.issuerPubKey = pubKey;
142
147
  this.genesisOutpoint = buildOutpoint(mintTx, 0);
143
- this.privKey = privKey;
148
+ this.signer = signer;
144
149
  return this;
145
150
  }
146
151
  async commit(toPrivKey, commitTxMiscData = "Bolt Protocol Transfer Commit Transaction Miscellaneous Data", forceNoChange = false, fundOverride = undefined, forceNoFund = false, customChangeScript) {
@@ -176,8 +181,8 @@ export class SimpleMultiBOLT extends BOLT {
176
181
  });
177
182
  this.verifyAndLogTransaction(this.tx, 'SETTLE TX', fundOverride?.sourceTransaction);
178
183
  this.prevTxs?.push(this.tx);
179
- this.privKey = toPrivKey;
180
- this.pubKey = toPrivKey.toPublicKey().encode(true);
184
+ this.signer = recipientSigner(toPrivKey) ?? this.signer;
185
+ this.pubKey = recipientPubKey(toPrivKey);
181
186
  this.pubKeyHash = Hash.hash160(this.pubKey);
182
187
  return this;
183
188
  }
@@ -212,16 +217,16 @@ export class SimpleMultiBOLT extends BOLT {
212
217
  subtractBalances(a, b) {
213
218
  return this.bigIntToBalance(this.balanceToBigInt(a) - this.balanceToBigInt(b));
214
219
  }
215
- // Find proof vout that matches a key's pubKeyHash in an ancestor commit tx
220
+ // Find the proof vout paying a key's pubKeyHash in an ancestor commit tx. Every commit has exactly
221
+ // one token output at vout 0, so proofs start at vout 1 (a split commit carries two: vout 1 for
222
+ // piece A, vout 2 for piece B) and the last output is change. Falls back to vout 1.
216
223
  findProofVout(ancestorTx, key) {
217
- const pkh = Utils.toHex(Hash.hash160(key.toPublicKey().encode(true)));
218
- const startIdx = ancestorTx.outputs.length >= 5 ? 2 : 1;
219
- for (let i = startIdx; i < ancestorTx.outputs.length - 1; i++) {
220
- const proofChunks = ancestorTx.outputs[i].lockingScript.chunks;
221
- if (proofChunks.length >= 5 && Utils.toHex(proofChunks[4]?.data || []) === pkh)
224
+ const pkh = Utils.toHex(Hash.hash160(recipientPubKey(key)));
225
+ for (let i = 1; i < ancestorTx.outputs.length - 1; i++) {
226
+ if (Utils.toHex(ancestorTx.outputs[i].lockingScript.chunks[4]?.data || []) === pkh)
222
227
  return i;
223
228
  }
224
- return startIdx;
229
+ return 1;
225
230
  }
226
231
  // 4-byte LE uint32 for vout indices used in outpoint construction
227
232
  voutLE(n) {
@@ -229,25 +234,25 @@ export class SimpleMultiBOLT extends BOLT {
229
234
  new DataView(buf).setUint32(0, n, true);
230
235
  return Array.from(new Uint8Array(buf));
231
236
  }
232
- // Get the parent outpoint from a token's locking script (SMB lock chunk 8)
237
+ // Get the parent outpoint from a token's locking script (SMB lock chunk 7, + leading pushes)
233
238
  getParentOutpoint() {
234
- return this.tx.outputs[this.voutIdx].lockingScript.chunks[8].data;
239
+ return this.tx.outputs[this.voutIdx].lockingScript.chunks[7 + this.leading].data;
235
240
  }
236
241
  // Merge: absorb other token into this one
237
242
  async merge(other, toKey, fundingSource) {
238
- const tpl = new SimpleMultiTemplate();
243
+ const tpl = this.template();
239
244
  const proofTpl = new Pay2ProofTemplate();
240
245
  const version = 2;
241
- const toPubKeyHash = Hash.hash160(toKey.toPublicKey().encode(true));
246
+ const toPubKeyHash = Hash.hash160(recipientPubKey(toKey));
242
247
  // Default funding: use the last output of whichever token's tx has a change output we can unlock
243
248
  const fundTx = fundingSource?.tx || this.tx;
244
249
  const fundVout = fundingSource?.vout ?? (this.tx.outputs.length - 1);
245
- const fundKey = fundingSource?.key || this.privKey;
250
+ const fundKey = fundingSource?.key || this.signer;
246
251
  // ── Merge Commit ──
247
252
  const thisInput = {
248
253
  sourceTransaction: this.tx,
249
254
  sourceOutputIndex: this.voutIdx,
250
- unlockingScriptTemplate: tpl.unlock(this.privKey, toKey.toPublicKey().encode(true), this.prevTxs, false, false, other.balance, // nextBalanceCommit = other's balance
255
+ unlockingScriptTemplate: tpl.unlock(this.signer, recipientPubKey(toKey), this.prevTxs, false, false, other.balance, // nextBalanceCommit = other's balance
251
256
  [0x25], // merge commit
252
257
  [0x00], [], // pubKeyHash2
253
258
  [], [], // no proof vout idx for commit
@@ -258,18 +263,18 @@ export class SimpleMultiBOLT extends BOLT {
258
263
  const otherInput = {
259
264
  sourceTransaction: other.tx,
260
265
  sourceOutputIndex: other.voutIdx,
261
- unlockingScriptTemplate: tpl.unlock(other.privKey, toKey.toPublicKey().encode(true), other.prevTxs, false, false, this.balance, [0x25], [0x01], [], [], [], Hash.hash160(this.pubKey), buildOutpoint(this.tx, this.voutIdx), this.getParentOutpoint()),
266
+ unlockingScriptTemplate: tpl.unlock(other.signer, recipientPubKey(toKey), other.prevTxs, false, false, this.balance, [0x25], [0x01], [], [], [], Hash.hash160(this.pubKey), buildOutpoint(this.tx, this.voutIdx), this.getParentOutpoint()),
262
267
  sequence: 0xffffffff,
263
268
  };
264
269
  const fundInput = {
265
270
  sourceTransaction: fundTx,
266
271
  sourceOutputIndex: fundVout,
267
- unlockingScriptTemplate: new P2PKH().unlock(fundKey),
272
+ unlockingScriptTemplate: p2pkhUnlock(fundKey),
268
273
  sequence: 0xffffffff,
269
274
  };
270
275
  // Merged token output (commit)
271
276
  const tokenOut = tpl.lock(this.pubKey, this.prevTxs, this.balance, other.balance, toPubKeyHash, new Array(20).fill(0x00), other.getParentOutpoint(), // otherGrandparentOutpoint = other token's parentOutpoint
272
- [0x25], [0x00], this.voutIdx);
277
+ [0x25], this.voutIdx);
273
278
  const proofOut = { lockingScript: proofTpl.lock(toPubKeyHash), satoshis: 1, change: false };
274
279
  const changeOut = { change: true, lockingScript: new P2PKH().lock(this.pubKeyHash) };
275
280
  const commitTx = await this.signAndClean(new Transaction(version, [thisInput, otherInput, fundInput], [{ lockingScript: tokenOut, satoshis: 1 }, proofOut, changeOut]));
@@ -280,12 +285,12 @@ export class SimpleMultiBOLT extends BOLT {
280
285
  // Ancestor commits at prevTxs[txIdx - 3] for each lineage
281
286
  const thisAncestorCommit = this.prevTxs[this.prevTxs.length - 3];
282
287
  const otherAncestorCommit = other.prevTxs[other.prevTxs.length - 3];
283
- const thisProofVout = this.findProofVout(thisAncestorCommit, this.privKey);
284
- const otherProofVout = this.findProofVout(otherAncestorCommit, other.privKey);
288
+ const thisProofVout = this.findProofVout(thisAncestorCommit, this.signer);
289
+ const otherProofVout = this.findProofVout(otherAncestorCommit, other.signer);
285
290
  const settleInput = {
286
291
  sourceTransaction: commitTx,
287
292
  sourceOutputIndex: 0,
288
- unlockingScriptTemplate: tpl.unlock(this.privKey, toKey.toPublicKey().encode(true), this.prevTxs, false, false, new Array(16).fill(0x00), [0x24], // merge settle
293
+ unlockingScriptTemplate: tpl.unlock(this.signer, recipientPubKey(toKey), this.prevTxs, false, false, new Array(16).fill(0x00), [0x24], // merge settle
289
294
  [0x00], [], this.voutLE(thisProofVout), // grandparentProofVoutIdx
290
295
  this.voutLE(otherProofVout), // interopProofVoutIdx
291
296
  [], [], [], otherAncestorCommit),
@@ -294,34 +299,34 @@ export class SimpleMultiBOLT extends BOLT {
294
299
  const proof0 = {
295
300
  sourceTransaction: thisAncestorCommit,
296
301
  sourceOutputIndex: thisProofVout,
297
- unlockingScriptTemplate: proofTpl.unlock(this.privKey),
302
+ unlockingScriptTemplate: proofTpl.unlock(this.signer),
298
303
  sequence: 0xffffffff,
299
304
  };
300
305
  const proof1 = {
301
306
  sourceTransaction: otherAncestorCommit,
302
307
  sourceOutputIndex: otherProofVout,
303
- unlockingScriptTemplate: proofTpl.unlock(other.privKey),
308
+ unlockingScriptTemplate: proofTpl.unlock(other.signer),
304
309
  sequence: 0xffffffff,
305
310
  };
306
311
  const settleFundInput = {
307
312
  sourceTransaction: commitTx,
308
313
  sourceOutputIndex: commitTx.outputs.length - 1,
309
- unlockingScriptTemplate: new P2PKH().unlock(this.privKey),
314
+ unlockingScriptTemplate: p2pkhUnlock(this.signer),
310
315
  sequence: 0xffffffff,
311
316
  };
312
317
  // Merged balance = sum of both tokens' balances (16-byte LE addition)
313
318
  const mergedBalance = this.addBalances(this.balance, other.balance);
314
- const settleTokenOut = tpl.lock(toKey.toPublicKey().encode(true), this.prevTxs, mergedBalance, new Array(16).fill(0x00), new Array(20).fill(0x00), new Array(20).fill(0x00), new Array(36).fill(0x00), [0x24], [0x00], 0);
319
+ const settleTokenOut = tpl.lock(recipientPubKey(toKey), this.prevTxs, mergedBalance, new Array(16).fill(0x00), new Array(20).fill(0x00), new Array(20).fill(0x00), new Array(36).fill(0x00), [0x24], 0);
315
320
  // Lock change to the new owner's key so the merged token can fund subsequent operations
316
- const mergeSettleChangePKH = Hash.hash160(toKey.toPublicKey().encode(true));
321
+ const mergeSettleChangePKH = Hash.hash160(recipientPubKey(toKey));
317
322
  const settleChangeOut = { change: true, lockingScript: new P2PKH().lock(mergeSettleChangePKH) };
318
323
  const settleTx = await this.signAndClean(new Transaction(version, [settleInput, proof0, proof1, settleFundInput], [{ lockingScript: settleTokenOut, satoshis: 1 }, settleChangeOut]));
319
324
  this.verifyAndLogTransaction(settleTx, 'MERGE SETTLE TX', undefined, other.prevTxs);
320
325
  this.tx = settleTx;
321
326
  this.voutIdx = 0;
322
327
  this.prevTxs.push(settleTx);
323
- this.privKey = toKey;
324
- this.pubKey = toKey.toPublicKey().encode(true);
328
+ this.signer = recipientSigner(toKey) ?? this.signer;
329
+ this.pubKey = recipientPubKey(toKey);
325
330
  this.pubKeyHash = Hash.hash160(this.pubKey);
326
331
  this.balance = mergedBalance;
327
332
  this.balanceCommit = new Array(16).fill(0x00);
@@ -330,19 +335,19 @@ export class SimpleMultiBOLT extends BOLT {
330
335
  // Split: divide this token into two with specified balances
331
336
  // Returns [tokenA, tokenB]
332
337
  async split(toKeyA, toKeyB, splitBalanceCommit, fundingSource) {
333
- const tpl = new SimpleMultiTemplate();
338
+ const tpl = this.template();
334
339
  const proofTpl = new Pay2ProofTemplate();
335
340
  const version = 2;
336
- const toPubKeyHashA = Hash.hash160(toKeyA.toPublicKey().encode(true));
337
- const toPubKeyHashB = Hash.hash160(toKeyB.toPublicKey().encode(true));
341
+ const toPubKeyHashA = Hash.hash160(recipientPubKey(toKeyA));
342
+ const toPubKeyHashB = Hash.hash160(recipientPubKey(toKeyB));
338
343
  const fundTx = fundingSource?.tx || this.tx;
339
344
  const fundVout = fundingSource?.vout ?? (this.tx.outputs.length - 1);
340
- const fundKey = fundingSource?.key || this.privKey;
345
+ const fundKey = fundingSource?.key || this.signer;
341
346
  // ── Split Commit ──
342
347
  const tokenInput = {
343
348
  sourceTransaction: this.tx,
344
349
  sourceOutputIndex: this.voutIdx,
345
- unlockingScriptTemplate: tpl.unlock(this.privKey, toKeyA.toPublicKey().encode(true), this.prevTxs, false, false, splitBalanceCommit, // nextBalanceCommit = second split's balance
350
+ unlockingScriptTemplate: tpl.unlock(this.signer, recipientPubKey(toKeyA), this.prevTxs, false, false, splitBalanceCommit, // nextBalanceCommit = second split's balance
346
351
  [0x23], // split commit
347
352
  [0x00], toPubKeyHashB),
348
353
  sequence: 0xffffffff,
@@ -350,10 +355,10 @@ export class SimpleMultiBOLT extends BOLT {
350
355
  const fundInput = {
351
356
  sourceTransaction: fundTx,
352
357
  sourceOutputIndex: fundVout,
353
- unlockingScriptTemplate: new P2PKH().unlock(fundKey),
358
+ unlockingScriptTemplate: p2pkhUnlock(fundKey),
354
359
  sequence: 0xffffffff,
355
360
  };
356
- const tokenOut = tpl.lock(this.pubKey, this.prevTxs, this.balance, splitBalanceCommit, toPubKeyHashA, toPubKeyHashB, new Array(36).fill(0x00), [0x23], [0x00], this.voutIdx);
361
+ const tokenOut = tpl.lock(this.pubKey, this.prevTxs, this.balance, splitBalanceCommit, toPubKeyHashA, toPubKeyHashB, new Array(36).fill(0x00), [0x23], this.voutIdx);
357
362
  const proofOut0 = { lockingScript: proofTpl.lock(toPubKeyHashA), satoshis: 1, change: false };
358
363
  const proofOut1 = { lockingScript: proofTpl.lock(toPubKeyHashB), satoshis: 1, change: false };
359
364
  const changeOut = { change: true, lockingScript: new P2PKH().lock(this.pubKeyHash) };
@@ -362,11 +367,11 @@ export class SimpleMultiBOLT extends BOLT {
362
367
  this.prevTxs.push(commitTx);
363
368
  // ── Split Settle ──
364
369
  const ancestorCommit = this.prevTxs[this.prevTxs.length - 3]; // the commit before the split commit
365
- const ancestorProofVout = ancestorCommit.outputs.length >= 5 ? 2 : 1;
370
+ const ancestorProofVout = this.findProofVout(ancestorCommit, this.signer);
366
371
  const settleInput = {
367
372
  sourceTransaction: commitTx,
368
373
  sourceOutputIndex: 0,
369
- unlockingScriptTemplate: tpl.unlock(this.privKey, [], // toPubKey empty -> pubKeyHash1 empty (recipients from commitments)
374
+ unlockingScriptTemplate: tpl.unlock(this.signer, [], // toPubKey empty -> pubKeyHash1 empty (recipients from commitments)
370
375
  this.prevTxs, false, false, [], // nextBalanceCommit empty for split settle
371
376
  [0x22], // split settle
372
377
  [0x00], [], this.voutLE(ancestorProofVout)),
@@ -375,21 +380,21 @@ export class SimpleMultiBOLT extends BOLT {
375
380
  const proofInput = {
376
381
  sourceTransaction: ancestorCommit,
377
382
  sourceOutputIndex: ancestorProofVout,
378
- unlockingScriptTemplate: proofTpl.unlock(this.privKey),
383
+ unlockingScriptTemplate: proofTpl.unlock(this.signer),
379
384
  sequence: 0xffffffff,
380
385
  };
381
386
  const settleFundInput = {
382
387
  sourceTransaction: commitTx,
383
388
  sourceOutputIndex: commitTx.outputs.length - 1,
384
- unlockingScriptTemplate: new P2PKH().unlock(this.privKey),
389
+ unlockingScriptTemplate: p2pkhUnlock(this.signer),
385
390
  sequence: 0xffffffff,
386
391
  };
387
392
  // Two settled token outputs — first gets balance - balanceCommit, second gets balanceCommit
388
393
  const mainBalance = this.subtractBalances(this.balance, splitBalanceCommit);
389
- const settleTokenOut0 = tpl.lock(toKeyA.toPublicKey().encode(true), this.prevTxs, mainBalance, new Array(16).fill(0x00), new Array(20).fill(0x00), new Array(20).fill(0x00), new Array(36).fill(0x00), [0x22], [0x00], 0);
390
- const settleTokenOut1 = tpl.lock(toKeyB.toPublicKey().encode(true), this.prevTxs, splitBalanceCommit, new Array(16).fill(0x00), new Array(20).fill(0x00), new Array(20).fill(0x00), new Array(36).fill(0x00), [0x22], [0x01], 0);
394
+ const settleTokenOut0 = tpl.lock(recipientPubKey(toKeyA), this.prevTxs, mainBalance, new Array(16).fill(0x00), new Array(20).fill(0x00), new Array(20).fill(0x00), new Array(36).fill(0x00), [0x22], 0);
395
+ const settleTokenOut1 = tpl.lock(recipientPubKey(toKeyB), this.prevTxs, splitBalanceCommit, new Array(16).fill(0x00), new Array(20).fill(0x00), new Array(20).fill(0x00), new Array(36).fill(0x00), [0x22], 0);
391
396
  // Lock change to first split recipient so the token can fund subsequent operations
392
- const splitSettleChangePKH = Hash.hash160(toKeyA.toPublicKey().encode(true));
397
+ const splitSettleChangePKH = Hash.hash160(recipientPubKey(toKeyA));
393
398
  const settleChangeOut = { change: true, lockingScript: new P2PKH().lock(splitSettleChangePKH) };
394
399
  const settleTx = await this.signAndClean(new Transaction(version, [settleInput, proofInput, settleFundInput], [{ lockingScript: settleTokenOut0, satoshis: 1 }, { lockingScript: settleTokenOut1, satoshis: 1 }, settleChangeOut]));
395
400
  this.verifyAndLogTransaction(settleTx, 'SPLIT SETTLE TX');
@@ -397,21 +402,22 @@ export class SimpleMultiBOLT extends BOLT {
397
402
  this.tx = settleTx;
398
403
  this.voutIdx = 0;
399
404
  this.prevTxs.push(settleTx);
400
- this.privKey = toKeyA;
401
- this.pubKey = toKeyA.toPublicKey().encode(true);
405
+ this.signer = recipientSigner(toKeyA) ?? this.signer;
406
+ this.pubKey = recipientPubKey(toKeyA);
402
407
  this.pubKeyHash = Hash.hash160(this.pubKey);
403
408
  this.balance = mainBalance;
404
409
  // Create second split token
405
- const tokenB = new SimpleMultiBOLT();
410
+ const tokenB = new this.constructor(); // same token class as this one
406
411
  tokenB.tx = settleTx;
407
412
  tokenB.voutIdx = 1;
408
413
  tokenB.prevTxs = [...this.prevTxs]; // share lineage
409
- tokenB.privKey = toKeyB;
410
- tokenB.pubKey = toKeyB.toPublicKey().encode(true);
414
+ tokenB.signer = recipientSigner(toKeyB);
415
+ tokenB.pubKey = recipientPubKey(toKeyB);
411
416
  tokenB.pubKeyHash = Hash.hash160(tokenB.pubKey);
412
417
  tokenB.issuerPubKey = this.issuerPubKey;
413
418
  tokenB.genesisOutpoint = this.genesisOutpoint;
414
419
  tokenB.balance = splitBalanceCommit;
420
+ tokenB.mintData = this.mintData;
415
421
  tokenB.skipVerify = this.skipVerify;
416
422
  tokenB.verifier = this.verifier;
417
423
  return [this, tokenB];
@@ -420,13 +426,14 @@ export class SimpleMultiBOLT extends BOLT {
420
426
  const input = {
421
427
  sourceTransaction: this.tx,
422
428
  sourceOutputIndex: this.voutIdx,
423
- unlockingScriptTemplate: new SimpleMultiTemplate().melt(this.privKey),
429
+ unlockingScriptTemplate: this.template().melt(this.signer),
424
430
  sequence: 0xffffffff,
425
431
  };
426
432
  const funding = {
427
433
  sourceTransaction: this.tx,
434
+ /* v8 ignore next -- a token being melted always has its tx */
428
435
  sourceOutputIndex: this.tx?.outputs ? this.tx?.outputs.length - 1 : 0,
429
- unlockingScriptTemplate: new P2PKH().unlock(this.privKey),
436
+ unlockingScriptTemplate: p2pkhUnlock(this.signer),
430
437
  sequence: 0xffffffff,
431
438
  };
432
439
  const version = 2;
@@ -455,11 +462,12 @@ export class SimpleMultiBOLT extends BOLT {
455
462
  input.sourceTXID = input.sourceTransaction.id('hex');
456
463
  }
457
464
  });
458
- const { valid, scriptExecutions } = verifyTx(tx, true); // skipOutputCheck: zero-funding txs may have output > input
459
- if (!valid) {
460
- const failedIdx = scriptExecutions.findIndex(e => !e.valid);
461
- console.log(`\n========== SCRIPT FAILURE [bsv] (${txType}) - INPUT ${failedIdx} ==========`);
462
- throw new Error(`${txType} tx not valid [bsv]`);
465
+ // verifyTx throws if any input fails (skipOutputCheck: zero-funding txs may have output > input); name the tx
466
+ try {
467
+ verifyTx(tx, true);
468
+ }
469
+ catch (e) {
470
+ throw new Error(`${txType} not valid: ${e.message}`);
463
471
  }
464
472
  }
465
473
  }
@@ -0,0 +1,35 @@
1
+ import { ScriptTemplate, LockingScript, Script, PrivateKey, Transaction, UnlockingScript } from "@bsv/sdk";
2
+ import type { Signer } from "../../lib/boltLib.js";
3
+ /** authOrMiscData is a DIRECT push (0x00..0x4b), enforced by the lock. */
4
+ export declare const AUTH_DATA_MAX_BYTES = 75;
5
+ export default class AuthBoltTemplate implements ScriptTemplate {
6
+ private readonly UNLOCK_SCRIPT_SUFFIX;
7
+ private readonly LOCK_SCRIPT_SUFFIX;
8
+ /**
9
+ * Build an AuthBolt locking script from its 6 contract args.
10
+ * For a genesis identity mint: pubKeyHash = recipient, issuerPubKey = issuer,
11
+ * pubKeyHashCommitment = zeros[20], txoType = [0x00], parent/grandparent = zeros[36].
12
+ */
13
+ lock(pubKeyHash: number[], issuerPubKey: number[], pubKeyHashCommitment?: number[], txoType?: number[], parentOutpoint?: number[], grandparentOutpoint?: number[]): LockingScript;
14
+ /** The static contract suffix (everything after the 6 data pushes), as a Script. */
15
+ staticSuffix(): Script;
16
+ /**
17
+ * Spend (transfer commit/settle) this bolt, carrying `authOrMiscData`. Requires tx version >= 2.
18
+ * @param beneficiaryPubKeyHash the next owner's 20-byte pkh
19
+ * @param prevTxs prior lineage txs (mint, commit, ...); a back-reaching settle (>= 4 txs) reconstructs its ancestor
20
+ * @param authOrMiscData up to 75 bytes (a direct push) bound by the settle's grandparent rebuild; [] = none (OP_0)
21
+ * @throws if authOrMiscData is longer than 75 bytes (the lock would refuse the tx)
22
+ */
23
+ unlock(privateKey: PrivateKey | Signer, beneficiaryPubKeyHash: number[], prevTxs?: Transaction[], authOrMiscData?: number[], forceNoChange?: boolean, forceNoFund?: boolean): {
24
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
25
+ estimateLength: () => Promise<number>;
26
+ };
27
+ /**
28
+ * MELT (burn) this bolt: an owner spend with a null CTX and no token output. Requires tx version >= 2.
29
+ * A token that is still a genesis mint (or its first commit) can only be melted by the issuer key.
30
+ */
31
+ melt(privateKey: PrivateKey | Signer): {
32
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
33
+ estimateLength: () => Promise<number>;
34
+ };
35
+ }
@@ -0,0 +1,82 @@
1
+ // AuthBolt.sx.template.ts
2
+ // Runtime LOCK assembler for the AuthBolt identity NFT: MinSimpleBolt (zero-funding) plus an owner-supplied
3
+ // `authOrMiscData` (<= 75 B) carried in every spend. LOCK_SCRIPT_SUFFIX / UNLOCK_SCRIPT_SUFFIX are
4
+ // auto-patched from the pre-compiled artifact by scripts/build-min-simple-bolt.mjs (build-time only) -
5
+ // do NOT hand-edit them.
6
+ //
7
+ // Lock layout (6 dynamic data args, then the static contract suffix) - identical to MinSimpleBolt:
8
+ // pubKeyHash[20] · pubKeyHashCommitment[20] · txoType[1] · parentOutpoint[36] ·
9
+ // grandparentOutpoint[36] · issuerPubKey[33] + LOCK_SCRIPT_SUFFIX
10
+ // The two contracts are told apart by the sha256 of the suffix alone (see scanner/fingerprints.ts).
11
+ //
12
+ // Unlock layout (39 args): authOrMiscData, 27 ancestor pieces (incl. Vin1AuthOrMiscData), 11 current-tx args.
13
+ // authOrMiscData is created in a commit and authenticated in the settle (which rebuilds its grandparent
14
+ // commit, whose scriptSig leads with it). The commit's own owner signature does NOT cover it.
15
+ //
16
+ // Receiving off-chain: a minted token sent by SPV does not prove the sender holds the issuer key (anyone can
17
+ // mint an output naming any issuerPubKey). The issuer guard runs when the genesis is first SPENT, so a commit
18
+ // signed by the issuer, funded or not, must accompany it. Where authOrMiscData travels, the signed commit AND
19
+ // settle must be passed together as the package (see README: "Receiving a token off-chain").
20
+ import { LockingScript, Script } from "@bsv/sdk";
21
+ import { singleSpendUnlock } from "../../lib/single/singleSpend.js";
22
+ import { AUTH_BOLT_LAYOUT } from "../../lib/single/singleAncestor.js";
23
+ /** authOrMiscData is a DIRECT push (0x00..0x4b), enforced by the lock. */
24
+ export const AUTH_DATA_MAX_BYTES = 75;
25
+ export default class AuthBoltTemplate {
26
+ constructor() {
27
+ // Static UNLOCK suffix (after the 39 data pushes), patched from the artifact - do NOT hand-edit.
28
+ this.UNLOCK_SCRIPT_SUFFIX = "OP_5 OP_PICK OP_5 OP_ROLL OP_5 OP_ROLL OP_5 OP_PICK OP_5 OP_PICK OP_CAT OP_CAT OP_CAT OP_CAT OP_4 OP_ROLL OP_2 OP_ROLL OP_4 OP_ROLL OP_4 OP_ROLL OP_CAT OP_CAT OP_CAT OP_SWAP OP_IFDUP OP_IF 41 OP_TOALTSTACK OP_HASH256 OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT 00 OP_CAT OP_BIN2NUM OP_1 OP_ADD OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SIZE OP_SWAP OP_CAT 022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179802 OP_SWAP OP_CAT OP_SIZE OP_SWAP OP_CAT 30 OP_SWAP OP_CAT OP_FROMALTSTACK OP_CAT 038ff83d8cf12121491609c4939dc11c4aa35503508fe432dc5a5c1905608b9218 OP_CODESEPARATOR OP_CHECKSIGVERIFY OP_ENDIF";
29
+ this.LOCK_SCRIPT_SUFFIX = "OP_2 OP_PICK OP_BIN2NUM OP_NOT OP_SWAP OP_2SWAP OP_DUP OP_BIN2NUM OP_0NOTEQUAL OP_DUP OP_NOT OP_6 OP_PICK OP_BIN2NUM OP_BOOLAND OP_5 OP_PICK OP_BOOLOR OP_IF OP_3 OP_PICK OP_10 OP_PICK OP_EQUALVERIFY OP_ENDIF 29 OP_PICK OP_SIZE OP_NIP 4c OP_LESSTHAN OP_VERIFY OP_8 OP_PICK OP_IFDUP OP_IF OP_DUP 41 OP_TOALTSTACK OP_HASH256 OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_1 OP_SPLIT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT 00 OP_CAT OP_BIN2NUM OP_1 OP_ADD OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_DUP OP_0NOTEQUAL OP_SPLIT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SWAP OP_CAT OP_SIZE OP_SWAP OP_CAT 022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179802 OP_SWAP OP_CAT OP_SIZE OP_SWAP OP_CAT 30 OP_SWAP OP_CAT OP_FROMALTSTACK OP_CAT 038ff83d8cf12121491609c4939dc11c4aa35503508fe432dc5a5c1905608b9218 OP_CHECKSIGVERIFY OP_4 OP_SPLIT 20 OP_SPLIT 20 OP_SPLIT 24 OP_SPLIT OP_1 OP_SPLIT OP_NIP OP_2 OP_SPLIT OP_SWAP OP_BIN2NUM OP_SPLIT OP_8 OP_SPLIT OP_4 OP_SPLIT 20 OP_SPLIT OP_4 OP_SPLIT OP_1 OP_SPLIT OP_SWAP 41 OP_EQUALVERIFY OP_9 OP_PICK OP_2 OP_GREATERTHANOREQUAL OP_VERIFY OP_5 OP_ROLL 15 OP_SPLIT 15 OP_SPLIT OP_2 OP_SPLIT 25 OP_SPLIT 25 OP_SPLIT 22 OP_SPLIT OP_DUP OP_TOALTSTACK OP_11 OP_PICK OP_DUP OP_BIN2NUM OP_1 OP_EQUALVERIFY 16 OP_PICK OP_NOTIF 1d02b0178876a914 OP_CAT 1c OP_PICK OP_CAT 88ac OP_CAT OP_ENDIF 14 17 OP_PICK OP_NOTIF 19 OP_ELSE 18 OP_ENDIF OP_PICK OP_CAT 14 18 OP_PICK OP_NOTIF 1e OP_PICK OP_ELSE OP_0 14 OP_NUM2BIN OP_ENDIF OP_CAT OP_CAT 17 OP_PICK OP_IF 0100 OP_ELSE 0121 OP_ENDIF OP_CAT 24 OP_15 OP_PICK OP_CAT OP_CAT OP_5 OP_PICK OP_CAT 16 OP_PICK OP_IF 21 1c OP_PICK OP_CAT OP_ELSE OP_3 OP_PICK OP_ENDIF OP_CAT OP_2 OP_PICK OP_CAT fd1105 OP_DUP OP_TOALTSTACK OP_14 OP_PICK OP_SWAP OP_CAT OP_SWAP OP_CAT 17 OP_PICK OP_NOTIF OP_SWAP OP_CAT OP_ELSE OP_NIP OP_ENDIF 1d OP_PICK OP_CAT OP_HASH256 OP_10 OP_PICK OP_EQUALVERIFY OP_12 OP_PICK 16 OP_PICK OP_BIN2NUM 12 OP_PICK OP_BOOLAND OP_IF 39 OP_PICK 37 OP_PICK OP_SIZE OP_NIP OP_0NOTEQUAL OP_1ADD OP_CAT 39 OP_PICK OP_CAT 38 OP_PICK OP_SIZE OP_1 OP_NUM2BIN OP_SWAP OP_CAT OP_0 1b OP_NUM2BIN OP_CAT 38 OP_PICK OP_SIZE OP_1 OP_NUM2BIN OP_SWAP OP_CAT OP_CAT 37 OP_PICK OP_SIZE OP_1 OP_NUM2BIN OP_SWAP OP_CAT OP_CAT 36 OP_PICK 14 OP_SWAP OP_CAT OP_CAT 35 OP_PICK OP_SIZE OP_SWAP OP_CAT OP_CAT 34 OP_PICK 21 OP_SWAP OP_CAT OP_CAT 33 OP_PICK 4c68 OP_SWAP OP_CAT 33 OP_PICK 14 OP_SWAP OP_CAT 33 OP_PICK 14 OP_SWAP OP_CAT OP_CAT 32 OP_PICK 01 OP_SWAP OP_CAT OP_CAT 31 OP_PICK 24 OP_SWAP OP_CAT OP_CAT 30 OP_PICK 24 OP_SWAP OP_CAT OP_CAT OP_6 OP_PICK OP_CAT OP_5 OP_PICK OP_CAT OP_DUP ad68 OP_DUP OP_ROT OP_CAT OP_DROP 03fd1305 OP_SWAP 02 OP_SWAP OP_CAT OP_CAT OP_SWAP fd1105 03 OP_SWAP OP_CAT OP_TOALTSTACK 4d1105 OP_SWAP OP_CAT OP_CAT OP_CAT OP_CAT 2d OP_PICK 34 OP_SWAP OP_CAT OP_CAT OP_FROMALTSTACK OP_CAT 5579557a557a557955797e7e7e7e547a527a547a547a7e7e7e7c73630141 OP_CAT OP_FROMALTSTACK OP_FROMALTSTACK OP_SWAP OP_TOALTSTACK 29 OP_SPLIT OP_NIP 7d01 OP_SPLIT OP_DROP OP_CAT abad68 OP_CAT OP_SIZE OP_2 OP_NUM2BIN fd OP_SWAP OP_CAT OP_SWAP OP_CAT OP_CAT 2b OP_PICK OP_CAT 2a OP_PICK OP_CAT 29 OP_PICK OP_SIZE OP_SWAP OP_CAT OP_CAT 28 OP_PICK OP_CAT 21 OP_PICK OP_SIZE OP_NIP OP_0NOTEQUAL OP_2 OP_ADD OP_CAT OP_13 OP_PICK OP_CAT OP_FROMALTSTACK OP_CAT 27 OP_PICK 14 OP_SWAP OP_CAT OP_CAT 26 OP_PICK 14 OP_SWAP OP_CAT OP_CAT 25 OP_PICK 01 OP_SWAP OP_CAT OP_CAT 24 OP_PICK 24 OP_SWAP OP_CAT OP_CAT 23 OP_PICK 24 OP_SWAP OP_CAT OP_CAT OP_3 OP_PICK OP_CAT OP_2 OP_PICK OP_CAT OP_13 OP_PICK OP_CAT 1d02b0178876a914 OP_CAT 19 OP_PICK OP_CAT 88ac OP_CAT 22 OP_PICK OP_CAT 21 OP_PICK OP_SIZE OP_SWAP OP_CAT OP_CAT 20 OP_PICK OP_CAT OP_HASH256 OP_DUP 14 OP_PICK 20 OP_SPLIT OP_DROP OP_EQUALVERIFY 01000000 OP_CAT OP_CAT OP_ELSE 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK 39 OP_PICK OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_CAT OP_SIZE OP_NIP OP_0 OP_EQUALVERIFY OP_ENDIF 1e OP_PICK OP_CAT OP_HASH256 OP_15 OP_PICK OP_EQUALVERIFY 1a OP_PICK OP_DUP OP_SIZE OP_1SUB OP_SPLIT OP_NIP 41 OP_EQUALVERIFY 1a OP_PICK OP_DUP OP_HASH160 1a OP_ELSE OP_10 OP_PICK OP_DUP OP_SIZE OP_1SUB OP_SPLIT OP_NIP 41 OP_EQUALVERIFY OP_10 OP_PICK OP_DUP OP_HASH160 OP_10 OP_ENDIF OP_PICK OP_EQUALVERIFY OP_CHECKSIG";
30
+ }
31
+ /**
32
+ * Build an AuthBolt locking script from its 6 contract args.
33
+ * For a genesis identity mint: pubKeyHash = recipient, issuerPubKey = issuer,
34
+ * pubKeyHashCommitment = zeros[20], txoType = [0x00], parent/grandparent = zeros[36].
35
+ */
36
+ lock(pubKeyHash, issuerPubKey, pubKeyHashCommitment = new Array(20).fill(0x00), txoType = [0x00], parentOutpoint = new Array(36).fill(0x00), grandparentOutpoint = new Array(36).fill(0x00)) {
37
+ return new LockingScript([
38
+ ...new Script().writeBin(pubKeyHash).chunks,
39
+ ...new Script().writeBin(pubKeyHashCommitment).chunks,
40
+ ...new Script().writeBin(txoType).chunks,
41
+ ...new Script().writeBin(parentOutpoint).chunks,
42
+ ...new Script().writeBin(grandparentOutpoint).chunks,
43
+ ...new Script().writeBin(issuerPubKey).chunks,
44
+ ...Script.fromASM(this.LOCK_SCRIPT_SUFFIX).chunks,
45
+ ]);
46
+ }
47
+ /** The static contract suffix (everything after the 6 data pushes), as a Script. */
48
+ staticSuffix() {
49
+ return Script.fromASM(this.LOCK_SCRIPT_SUFFIX);
50
+ }
51
+ /**
52
+ * Spend (transfer commit/settle) this bolt, carrying `authOrMiscData`. Requires tx version >= 2.
53
+ * @param beneficiaryPubKeyHash the next owner's 20-byte pkh
54
+ * @param prevTxs prior lineage txs (mint, commit, ...); a back-reaching settle (>= 4 txs) reconstructs its ancestor
55
+ * @param authOrMiscData up to 75 bytes (a direct push) bound by the settle's grandparent rebuild; [] = none (OP_0)
56
+ * @throws if authOrMiscData is longer than 75 bytes (the lock would refuse the tx)
57
+ */
58
+ unlock(privateKey, beneficiaryPubKeyHash, prevTxs = [], authOrMiscData = [], forceNoChange = false, forceNoFund = false) {
59
+ if (authOrMiscData.length > AUTH_DATA_MAX_BYTES) {
60
+ throw new Error(`authOrMiscData is ${authOrMiscData.length} bytes; the maximum is ${AUTH_DATA_MAX_BYTES} (a direct push)`);
61
+ }
62
+ return singleSpendUnlock({
63
+ privateKey,
64
+ beneficiaryPubKeyHash,
65
+ unlockScriptSuffixASM: this.UNLOCK_SCRIPT_SUFFIX,
66
+ prevTxs,
67
+ forceNoChange,
68
+ forceNoFund,
69
+ layout: AUTH_BOLT_LAYOUT,
70
+ authOrMiscData,
71
+ });
72
+ }
73
+ /**
74
+ * MELT (burn) this bolt: an owner spend with a null CTX and no token output. Requires tx version >= 2.
75
+ * A token that is still a genesis mint (or its first commit) can only be melted by the issuer key.
76
+ */
77
+ melt(privateKey) {
78
+ return singleSpendUnlock({
79
+ privateKey, beneficiaryPubKeyHash: [], unlockScriptSuffixASM: this.UNLOCK_SCRIPT_SUFFIX, melt: true, layout: AUTH_BOLT_LAYOUT,
80
+ });
81
+ }
82
+ }
@@ -0,0 +1,13 @@
1
+ import { Transaction } from "@bsv/sdk";
2
+ import SimpleMultiTemplate from "./SimpleMulti.sx.template.js";
3
+ import { type MultiLayout } from "../../lib/multi/multiBoltLib.js";
4
+ export default class FixedMultiTemplate extends SimpleMultiTemplate {
5
+ private readonly mintData;
6
+ protected readonly layout: MultiLayout;
7
+ protected readonly LOCK_SCRIPT_SUFFIX: string;
8
+ protected readonly UNLOCK_SCRIPT_SUFFIX: string;
9
+ /** @param mintData the issuer's bytes for the MINT output (0..255); ignored on every later output (OP_0). */
10
+ constructor(mintData?: number[]);
11
+ /** genesisOutpoint (36 B), then mintData. */
12
+ protected leadingPushes(prevTxs: Transaction[], prevVoutIdx: number, txoType: number[]): number[][];
13
+ }