b017 0.0.0-b1 → 0.1.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.
- package/CHANGELOG.md +274 -1
- package/README.md +118 -23
- package/dist/index.d.ts +15 -7
- package/dist/index.js +14 -5
- package/dist/lib/boltLib.d.ts +29 -3
- package/dist/lib/boltLib.js +60 -12
- package/dist/lib/genesis.d.ts +20 -0
- package/dist/lib/genesis.js +45 -0
- package/dist/lib/multi/multiBoltLib.d.ts +22 -2
- package/dist/lib/multi/multiBoltLib.js +111 -117
- package/dist/lib/scanner/beef.d.ts +11 -0
- package/dist/lib/scanner/beef.js +63 -0
- package/dist/lib/scanner/fingerprints.d.ts +12 -2
- package/dist/lib/scanner/fingerprints.js +44 -11
- package/dist/lib/scanner/verifyEvents.d.ts +84 -6
- package/dist/lib/scanner/verifyEvents.js +519 -44
- package/dist/lib/single/singleAncestor.d.ts +27 -3
- package/dist/lib/single/singleAncestor.js +49 -18
- package/dist/lib/single/singleSpend.d.ts +12 -3
- package/dist/lib/single/singleSpend.js +48 -16
- package/dist/tokens/BOLT.d.ts +6 -5
- package/dist/tokens/GenesisMultiBOLT.d.ts +29 -0
- package/dist/tokens/GenesisMultiBOLT.js +48 -0
- package/dist/tokens/MultiBOLT.d.ts +17 -11
- package/dist/tokens/MultiBOLT.js +79 -68
- package/dist/tokens/templates/AuthBolt.sx.template.d.ts +35 -0
- package/dist/tokens/templates/AuthBolt.sx.template.js +82 -0
- package/dist/tokens/templates/FixedMulti.sx.template.d.ts +13 -0
- package/dist/tokens/templates/FixedMulti.sx.template.js +23 -0
- package/dist/tokens/templates/MinSimple.sx.template.d.ts +10 -1
- package/dist/tokens/templates/MinSimple.sx.template.js +15 -1
- package/dist/tokens/templates/OpenMulti.sx.template.d.ts +13 -0
- package/dist/tokens/templates/OpenMulti.sx.template.js +23 -0
- package/dist/tokens/templates/SerialBolt.sx.template.d.ts +23 -0
- package/dist/tokens/templates/SerialBolt.sx.template.js +61 -0
- package/dist/tokens/templates/SimpleMulti.sx.template.d.ts +11 -5
- package/dist/tokens/templates/SimpleMulti.sx.template.js +30 -21
- package/dist/tokens/templates/pay2Proof.d.ts +2 -1
- package/dist/tokens/templates/pay2Proof.js +1 -1
- package/package.json +8 -3
- package/dist/tokens/templates/MinSimpleBalance.sx.template.d.ts +0 -24
- package/dist/tokens/templates/MinSimpleBalance.sx.template.js +0 -59
- package/dist/tokens/templates/MinSimpleDiscount.sx.template.d.ts +0 -23
- package/dist/tokens/templates/MinSimpleDiscount.sx.template.js +0 -58
package/dist/tokens/MultiBOLT.js
CHANGED
|
@@ -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.
|
|
@@ -13,18 +13,20 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
13
13
|
this.balance = [];
|
|
14
14
|
this.balanceCommit = new Array(16).fill(0x00);
|
|
15
15
|
this.outputIndexN = [0x00];
|
|
16
|
+
/** Lock pushes that lead the SimpleMultiBolt fields (0 here; FixedBOLT / OpenBOLT 2). */
|
|
17
|
+
this.leading = 0;
|
|
16
18
|
this.createTransferInputs = (toPrivKey, _miscData, isCommitTx = true, forceNoChange = false, fundOverride = undefined, forceNoFund = false) => {
|
|
17
19
|
// Determine ancestor proof vout for settles
|
|
18
20
|
const hasAncestor = !isCommitTx && this.prevTxs.length >= 3;
|
|
19
21
|
let proofVout = 1;
|
|
20
22
|
if (hasAncestor) {
|
|
21
23
|
const ancestorTx = this.prevTxs[this.prevTxs.length - 3];
|
|
22
|
-
proofVout = ancestorTx.
|
|
24
|
+
proofVout = this.findProofVout(ancestorTx, this.signer);
|
|
23
25
|
}
|
|
24
26
|
const input = {
|
|
25
27
|
sourceTransaction: this.tx,
|
|
26
28
|
sourceOutputIndex: this.voutIdx,
|
|
27
|
-
unlockingScriptTemplate:
|
|
29
|
+
unlockingScriptTemplate: this.template().unlock(this.signer, recipientPubKey(toPrivKey), this.prevTxs, forceNoChange, forceNoFund, [], // nextBalanceCommit empty for transfer (sim sets none); not 16 zeros
|
|
28
30
|
isCommitTx ? [0x21] : [0x20], // nextTxoType
|
|
29
31
|
[0x00], // inputIndexN
|
|
30
32
|
[], // pubKeyHash2
|
|
@@ -33,8 +35,9 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
33
35
|
};
|
|
34
36
|
const funding = fundOverride || {
|
|
35
37
|
sourceTransaction: this.tx,
|
|
38
|
+
/* v8 ignore next -- a token being spent always has its tx */
|
|
36
39
|
sourceOutputIndex: this.tx?.outputs ? this.tx?.outputs.length - 1 : 0,
|
|
37
|
-
unlockingScriptTemplate:
|
|
40
|
+
unlockingScriptTemplate: p2pkhUnlock(this.signer),
|
|
38
41
|
sequence: 0xffffffff,
|
|
39
42
|
};
|
|
40
43
|
if (hasAncestor) {
|
|
@@ -42,7 +45,7 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
42
45
|
const proof = {
|
|
43
46
|
sourceTransaction: ancestorTx,
|
|
44
47
|
sourceOutputIndex: proofVout,
|
|
45
|
-
unlockingScriptTemplate: new Pay2ProofTemplate().unlock(this.
|
|
48
|
+
unlockingScriptTemplate: new Pay2ProofTemplate().unlock(this.signer),
|
|
46
49
|
sequence: 0xffffffff,
|
|
47
50
|
};
|
|
48
51
|
return forceNoFund ? [input, proof] : [input, proof, funding];
|
|
@@ -50,13 +53,13 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
50
53
|
return forceNoFund ? [input] : [input, funding];
|
|
51
54
|
};
|
|
52
55
|
this.createTransferOutputs = (toPrivKey, isCommitTx = true, forceNoChange = false, customChangeScript) => {
|
|
53
|
-
const toPubKeyHash = Hash.hash160(toPrivKey
|
|
56
|
+
const toPubKeyHash = Hash.hash160(recipientPubKey(toPrivKey));
|
|
54
57
|
const pubKeyHashCommit = isCommitTx
|
|
55
58
|
? toPubKeyHash
|
|
56
59
|
: new Array(20).fill(0x00);
|
|
57
|
-
const tokenLocking =
|
|
60
|
+
const tokenLocking = this.template().lock(isCommitTx
|
|
58
61
|
? this.pubKey
|
|
59
|
-
: toPrivKey
|
|
62
|
+
: recipientPubKey(toPrivKey), this.prevTxs, this.balance, this.balanceCommit, pubKeyHashCommit, new Array(20).fill(0x00), // pubKeyHashCommit2
|
|
60
63
|
new Array(36).fill(0x00), // otherGrandparentOutpoint
|
|
61
64
|
isCommitTx ? [0x21] : [0x20], // txoType
|
|
62
65
|
[0x00], // outputIndexN
|
|
@@ -86,8 +89,13 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
86
89
|
return cleanTx;
|
|
87
90
|
};
|
|
88
91
|
}
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
/** The script template for this token type; FixedBOLT / OpenBOLT override it. */
|
|
93
|
+
template() {
|
|
94
|
+
return new SimpleMultiTemplate();
|
|
95
|
+
}
|
|
96
|
+
async mint(owner, sourceTransaction, mintData = "", balance = [0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) {
|
|
97
|
+
const signer = toSigner(owner);
|
|
98
|
+
const pubKey = signer.publicKey;
|
|
91
99
|
const pubKeyHashStr = Utils.toHex(Hash.hash160(pubKey));
|
|
92
100
|
const version = 2;
|
|
93
101
|
let sourceOutputIndex = -1;
|
|
@@ -106,12 +114,14 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
106
114
|
const input = {
|
|
107
115
|
sourceTransaction,
|
|
108
116
|
sourceOutputIndex,
|
|
109
|
-
unlockingScriptTemplate:
|
|
117
|
+
unlockingScriptTemplate: p2pkhUnlock(signer),
|
|
110
118
|
sequence: 0xffffffff,
|
|
111
119
|
};
|
|
112
120
|
this.pubKeyHash = Hash.hash160(pubKey);
|
|
113
121
|
this.balance = balance;
|
|
114
|
-
|
|
122
|
+
// the issuer's mint bytes (a string is UTF-8); only the genesis family writes them on chain
|
|
123
|
+
this.mintData = typeof mintData === "string" ? Array.from(Buffer.from(mintData, "utf8")) : [...mintData];
|
|
124
|
+
const tokenLocking = this.template().lock(pubKey, this.prevTxs, this.balance, new Array(16).fill(0x00), // balanceCommit = zeros
|
|
115
125
|
new Array(20).fill(0x00), // pubKeyHashCommit
|
|
116
126
|
new Array(20).fill(0x00), // pubKeyHashCommit2
|
|
117
127
|
new Array(36).fill(0x00), // otherGrandparentOutpoint
|
|
@@ -131,16 +141,14 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
131
141
|
]);
|
|
132
142
|
await mintTx.fee(0);
|
|
133
143
|
await mintTx.sign();
|
|
134
|
-
|
|
135
|
-
if (!valid)
|
|
136
|
-
throw new Error("Mint tx not valid");
|
|
144
|
+
verifyTx(mintTx); // throws if the mint is not valid
|
|
137
145
|
this.tx = mintTx;
|
|
138
146
|
this.voutIdx = 0;
|
|
139
147
|
this.prevTxs.push(this.tx);
|
|
140
148
|
this.pubKey = pubKey;
|
|
141
149
|
this.issuerPubKey = pubKey;
|
|
142
150
|
this.genesisOutpoint = buildOutpoint(mintTx, 0);
|
|
143
|
-
this.
|
|
151
|
+
this.signer = signer;
|
|
144
152
|
return this;
|
|
145
153
|
}
|
|
146
154
|
async commit(toPrivKey, commitTxMiscData = "Bolt Protocol Transfer Commit Transaction Miscellaneous Data", forceNoChange = false, fundOverride = undefined, forceNoFund = false, customChangeScript) {
|
|
@@ -176,8 +184,8 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
176
184
|
});
|
|
177
185
|
this.verifyAndLogTransaction(this.tx, 'SETTLE TX', fundOverride?.sourceTransaction);
|
|
178
186
|
this.prevTxs?.push(this.tx);
|
|
179
|
-
this.
|
|
180
|
-
this.pubKey = toPrivKey
|
|
187
|
+
this.signer = recipientSigner(toPrivKey) ?? this.signer;
|
|
188
|
+
this.pubKey = recipientPubKey(toPrivKey);
|
|
181
189
|
this.pubKeyHash = Hash.hash160(this.pubKey);
|
|
182
190
|
return this;
|
|
183
191
|
}
|
|
@@ -212,16 +220,16 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
212
220
|
subtractBalances(a, b) {
|
|
213
221
|
return this.bigIntToBalance(this.balanceToBigInt(a) - this.balanceToBigInt(b));
|
|
214
222
|
}
|
|
215
|
-
// Find proof vout
|
|
223
|
+
// Find the proof vout paying a key's pubKeyHash in an ancestor commit tx. Every commit has exactly
|
|
224
|
+
// one token output at vout 0, so proofs start at vout 1 (a split commit carries two: vout 1 for
|
|
225
|
+
// piece A, vout 2 for piece B) and the last output is change. Falls back to vout 1.
|
|
216
226
|
findProofVout(ancestorTx, key) {
|
|
217
|
-
const pkh = Utils.toHex(Hash.hash160(key
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const proofChunks = ancestorTx.outputs[i].lockingScript.chunks;
|
|
221
|
-
if (proofChunks.length >= 5 && Utils.toHex(proofChunks[4]?.data || []) === pkh)
|
|
227
|
+
const pkh = Utils.toHex(Hash.hash160(recipientPubKey(key)));
|
|
228
|
+
for (let i = 1; i < ancestorTx.outputs.length - 1; i++) {
|
|
229
|
+
if (Utils.toHex(ancestorTx.outputs[i].lockingScript.chunks[4]?.data || []) === pkh)
|
|
222
230
|
return i;
|
|
223
231
|
}
|
|
224
|
-
return
|
|
232
|
+
return 1;
|
|
225
233
|
}
|
|
226
234
|
// 4-byte LE uint32 for vout indices used in outpoint construction
|
|
227
235
|
voutLE(n) {
|
|
@@ -229,25 +237,25 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
229
237
|
new DataView(buf).setUint32(0, n, true);
|
|
230
238
|
return Array.from(new Uint8Array(buf));
|
|
231
239
|
}
|
|
232
|
-
// Get the parent outpoint from a token's locking script (SMB lock chunk 8)
|
|
240
|
+
// Get the parent outpoint from a token's locking script (SMB lock chunk 8, + leading pushes)
|
|
233
241
|
getParentOutpoint() {
|
|
234
|
-
return this.tx.outputs[this.voutIdx].lockingScript.chunks[8].data;
|
|
242
|
+
return this.tx.outputs[this.voutIdx].lockingScript.chunks[8 + this.leading].data;
|
|
235
243
|
}
|
|
236
244
|
// Merge: absorb other token into this one
|
|
237
245
|
async merge(other, toKey, fundingSource) {
|
|
238
|
-
const tpl =
|
|
246
|
+
const tpl = this.template();
|
|
239
247
|
const proofTpl = new Pay2ProofTemplate();
|
|
240
248
|
const version = 2;
|
|
241
|
-
const toPubKeyHash = Hash.hash160(toKey
|
|
249
|
+
const toPubKeyHash = Hash.hash160(recipientPubKey(toKey));
|
|
242
250
|
// Default funding: use the last output of whichever token's tx has a change output we can unlock
|
|
243
251
|
const fundTx = fundingSource?.tx || this.tx;
|
|
244
252
|
const fundVout = fundingSource?.vout ?? (this.tx.outputs.length - 1);
|
|
245
|
-
const fundKey = fundingSource?.key || this.
|
|
253
|
+
const fundKey = fundingSource?.key || this.signer;
|
|
246
254
|
// ── Merge Commit ──
|
|
247
255
|
const thisInput = {
|
|
248
256
|
sourceTransaction: this.tx,
|
|
249
257
|
sourceOutputIndex: this.voutIdx,
|
|
250
|
-
unlockingScriptTemplate: tpl.unlock(this.
|
|
258
|
+
unlockingScriptTemplate: tpl.unlock(this.signer, recipientPubKey(toKey), this.prevTxs, false, false, other.balance, // nextBalanceCommit = other's balance
|
|
251
259
|
[0x25], // merge commit
|
|
252
260
|
[0x00], [], // pubKeyHash2
|
|
253
261
|
[], [], // no proof vout idx for commit
|
|
@@ -258,13 +266,13 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
258
266
|
const otherInput = {
|
|
259
267
|
sourceTransaction: other.tx,
|
|
260
268
|
sourceOutputIndex: other.voutIdx,
|
|
261
|
-
unlockingScriptTemplate: tpl.unlock(other.
|
|
269
|
+
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
270
|
sequence: 0xffffffff,
|
|
263
271
|
};
|
|
264
272
|
const fundInput = {
|
|
265
273
|
sourceTransaction: fundTx,
|
|
266
274
|
sourceOutputIndex: fundVout,
|
|
267
|
-
unlockingScriptTemplate:
|
|
275
|
+
unlockingScriptTemplate: p2pkhUnlock(fundKey),
|
|
268
276
|
sequence: 0xffffffff,
|
|
269
277
|
};
|
|
270
278
|
// Merged token output (commit)
|
|
@@ -280,12 +288,12 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
280
288
|
// Ancestor commits at prevTxs[txIdx - 3] for each lineage
|
|
281
289
|
const thisAncestorCommit = this.prevTxs[this.prevTxs.length - 3];
|
|
282
290
|
const otherAncestorCommit = other.prevTxs[other.prevTxs.length - 3];
|
|
283
|
-
const thisProofVout = this.findProofVout(thisAncestorCommit, this.
|
|
284
|
-
const otherProofVout = this.findProofVout(otherAncestorCommit, other.
|
|
291
|
+
const thisProofVout = this.findProofVout(thisAncestorCommit, this.signer);
|
|
292
|
+
const otherProofVout = this.findProofVout(otherAncestorCommit, other.signer);
|
|
285
293
|
const settleInput = {
|
|
286
294
|
sourceTransaction: commitTx,
|
|
287
295
|
sourceOutputIndex: 0,
|
|
288
|
-
unlockingScriptTemplate: tpl.unlock(this.
|
|
296
|
+
unlockingScriptTemplate: tpl.unlock(this.signer, recipientPubKey(toKey), this.prevTxs, false, false, new Array(16).fill(0x00), [0x24], // merge settle
|
|
289
297
|
[0x00], [], this.voutLE(thisProofVout), // grandparentProofVoutIdx
|
|
290
298
|
this.voutLE(otherProofVout), // interopProofVoutIdx
|
|
291
299
|
[], [], [], otherAncestorCommit),
|
|
@@ -294,34 +302,34 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
294
302
|
const proof0 = {
|
|
295
303
|
sourceTransaction: thisAncestorCommit,
|
|
296
304
|
sourceOutputIndex: thisProofVout,
|
|
297
|
-
unlockingScriptTemplate: proofTpl.unlock(this.
|
|
305
|
+
unlockingScriptTemplate: proofTpl.unlock(this.signer),
|
|
298
306
|
sequence: 0xffffffff,
|
|
299
307
|
};
|
|
300
308
|
const proof1 = {
|
|
301
309
|
sourceTransaction: otherAncestorCommit,
|
|
302
310
|
sourceOutputIndex: otherProofVout,
|
|
303
|
-
unlockingScriptTemplate: proofTpl.unlock(other.
|
|
311
|
+
unlockingScriptTemplate: proofTpl.unlock(other.signer),
|
|
304
312
|
sequence: 0xffffffff,
|
|
305
313
|
};
|
|
306
314
|
const settleFundInput = {
|
|
307
315
|
sourceTransaction: commitTx,
|
|
308
316
|
sourceOutputIndex: commitTx.outputs.length - 1,
|
|
309
|
-
unlockingScriptTemplate:
|
|
317
|
+
unlockingScriptTemplate: p2pkhUnlock(this.signer),
|
|
310
318
|
sequence: 0xffffffff,
|
|
311
319
|
};
|
|
312
320
|
// Merged balance = sum of both tokens' balances (16-byte LE addition)
|
|
313
321
|
const mergedBalance = this.addBalances(this.balance, other.balance);
|
|
314
|
-
const settleTokenOut = tpl.lock(toKey
|
|
322
|
+
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], [0x00], 0);
|
|
315
323
|
// Lock change to the new owner's key so the merged token can fund subsequent operations
|
|
316
|
-
const mergeSettleChangePKH = Hash.hash160(toKey
|
|
324
|
+
const mergeSettleChangePKH = Hash.hash160(recipientPubKey(toKey));
|
|
317
325
|
const settleChangeOut = { change: true, lockingScript: new P2PKH().lock(mergeSettleChangePKH) };
|
|
318
326
|
const settleTx = await this.signAndClean(new Transaction(version, [settleInput, proof0, proof1, settleFundInput], [{ lockingScript: settleTokenOut, satoshis: 1 }, settleChangeOut]));
|
|
319
327
|
this.verifyAndLogTransaction(settleTx, 'MERGE SETTLE TX', undefined, other.prevTxs);
|
|
320
328
|
this.tx = settleTx;
|
|
321
329
|
this.voutIdx = 0;
|
|
322
330
|
this.prevTxs.push(settleTx);
|
|
323
|
-
this.
|
|
324
|
-
this.pubKey = toKey
|
|
331
|
+
this.signer = recipientSigner(toKey) ?? this.signer;
|
|
332
|
+
this.pubKey = recipientPubKey(toKey);
|
|
325
333
|
this.pubKeyHash = Hash.hash160(this.pubKey);
|
|
326
334
|
this.balance = mergedBalance;
|
|
327
335
|
this.balanceCommit = new Array(16).fill(0x00);
|
|
@@ -330,19 +338,19 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
330
338
|
// Split: divide this token into two with specified balances
|
|
331
339
|
// Returns [tokenA, tokenB]
|
|
332
340
|
async split(toKeyA, toKeyB, splitBalanceCommit, fundingSource) {
|
|
333
|
-
const tpl =
|
|
341
|
+
const tpl = this.template();
|
|
334
342
|
const proofTpl = new Pay2ProofTemplate();
|
|
335
343
|
const version = 2;
|
|
336
|
-
const toPubKeyHashA = Hash.hash160(toKeyA
|
|
337
|
-
const toPubKeyHashB = Hash.hash160(toKeyB
|
|
344
|
+
const toPubKeyHashA = Hash.hash160(recipientPubKey(toKeyA));
|
|
345
|
+
const toPubKeyHashB = Hash.hash160(recipientPubKey(toKeyB));
|
|
338
346
|
const fundTx = fundingSource?.tx || this.tx;
|
|
339
347
|
const fundVout = fundingSource?.vout ?? (this.tx.outputs.length - 1);
|
|
340
|
-
const fundKey = fundingSource?.key || this.
|
|
348
|
+
const fundKey = fundingSource?.key || this.signer;
|
|
341
349
|
// ── Split Commit ──
|
|
342
350
|
const tokenInput = {
|
|
343
351
|
sourceTransaction: this.tx,
|
|
344
352
|
sourceOutputIndex: this.voutIdx,
|
|
345
|
-
unlockingScriptTemplate: tpl.unlock(this.
|
|
353
|
+
unlockingScriptTemplate: tpl.unlock(this.signer, recipientPubKey(toKeyA), this.prevTxs, false, false, splitBalanceCommit, // nextBalanceCommit = second split's balance
|
|
346
354
|
[0x23], // split commit
|
|
347
355
|
[0x00], toPubKeyHashB),
|
|
348
356
|
sequence: 0xffffffff,
|
|
@@ -350,7 +358,7 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
350
358
|
const fundInput = {
|
|
351
359
|
sourceTransaction: fundTx,
|
|
352
360
|
sourceOutputIndex: fundVout,
|
|
353
|
-
unlockingScriptTemplate:
|
|
361
|
+
unlockingScriptTemplate: p2pkhUnlock(fundKey),
|
|
354
362
|
sequence: 0xffffffff,
|
|
355
363
|
};
|
|
356
364
|
const tokenOut = tpl.lock(this.pubKey, this.prevTxs, this.balance, splitBalanceCommit, toPubKeyHashA, toPubKeyHashB, new Array(36).fill(0x00), [0x23], [0x00], this.voutIdx);
|
|
@@ -362,11 +370,11 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
362
370
|
this.prevTxs.push(commitTx);
|
|
363
371
|
// ── Split Settle ──
|
|
364
372
|
const ancestorCommit = this.prevTxs[this.prevTxs.length - 3]; // the commit before the split commit
|
|
365
|
-
const ancestorProofVout = ancestorCommit.
|
|
373
|
+
const ancestorProofVout = this.findProofVout(ancestorCommit, this.signer);
|
|
366
374
|
const settleInput = {
|
|
367
375
|
sourceTransaction: commitTx,
|
|
368
376
|
sourceOutputIndex: 0,
|
|
369
|
-
unlockingScriptTemplate: tpl.unlock(this.
|
|
377
|
+
unlockingScriptTemplate: tpl.unlock(this.signer, [], // toPubKey empty -> pubKeyHash1 empty (recipients from commitments)
|
|
370
378
|
this.prevTxs, false, false, [], // nextBalanceCommit empty for split settle
|
|
371
379
|
[0x22], // split settle
|
|
372
380
|
[0x00], [], this.voutLE(ancestorProofVout)),
|
|
@@ -375,21 +383,21 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
375
383
|
const proofInput = {
|
|
376
384
|
sourceTransaction: ancestorCommit,
|
|
377
385
|
sourceOutputIndex: ancestorProofVout,
|
|
378
|
-
unlockingScriptTemplate: proofTpl.unlock(this.
|
|
386
|
+
unlockingScriptTemplate: proofTpl.unlock(this.signer),
|
|
379
387
|
sequence: 0xffffffff,
|
|
380
388
|
};
|
|
381
389
|
const settleFundInput = {
|
|
382
390
|
sourceTransaction: commitTx,
|
|
383
391
|
sourceOutputIndex: commitTx.outputs.length - 1,
|
|
384
|
-
unlockingScriptTemplate:
|
|
392
|
+
unlockingScriptTemplate: p2pkhUnlock(this.signer),
|
|
385
393
|
sequence: 0xffffffff,
|
|
386
394
|
};
|
|
387
395
|
// Two settled token outputs — first gets balance - balanceCommit, second gets balanceCommit
|
|
388
396
|
const mainBalance = this.subtractBalances(this.balance, splitBalanceCommit);
|
|
389
|
-
const settleTokenOut0 = tpl.lock(toKeyA
|
|
390
|
-
const settleTokenOut1 = tpl.lock(toKeyB
|
|
397
|
+
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], [0x00], 0);
|
|
398
|
+
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], [0x01], 0);
|
|
391
399
|
// Lock change to first split recipient so the token can fund subsequent operations
|
|
392
|
-
const splitSettleChangePKH = Hash.hash160(toKeyA
|
|
400
|
+
const splitSettleChangePKH = Hash.hash160(recipientPubKey(toKeyA));
|
|
393
401
|
const settleChangeOut = { change: true, lockingScript: new P2PKH().lock(splitSettleChangePKH) };
|
|
394
402
|
const settleTx = await this.signAndClean(new Transaction(version, [settleInput, proofInput, settleFundInput], [{ lockingScript: settleTokenOut0, satoshis: 1 }, { lockingScript: settleTokenOut1, satoshis: 1 }, settleChangeOut]));
|
|
395
403
|
this.verifyAndLogTransaction(settleTx, 'SPLIT SETTLE TX');
|
|
@@ -397,21 +405,22 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
397
405
|
this.tx = settleTx;
|
|
398
406
|
this.voutIdx = 0;
|
|
399
407
|
this.prevTxs.push(settleTx);
|
|
400
|
-
this.
|
|
401
|
-
this.pubKey = toKeyA
|
|
408
|
+
this.signer = recipientSigner(toKeyA) ?? this.signer;
|
|
409
|
+
this.pubKey = recipientPubKey(toKeyA);
|
|
402
410
|
this.pubKeyHash = Hash.hash160(this.pubKey);
|
|
403
411
|
this.balance = mainBalance;
|
|
404
412
|
// Create second split token
|
|
405
|
-
const tokenB = new
|
|
413
|
+
const tokenB = new this.constructor(); // same token class as this one
|
|
406
414
|
tokenB.tx = settleTx;
|
|
407
415
|
tokenB.voutIdx = 1;
|
|
408
416
|
tokenB.prevTxs = [...this.prevTxs]; // share lineage
|
|
409
|
-
tokenB.
|
|
410
|
-
tokenB.pubKey = toKeyB
|
|
417
|
+
tokenB.signer = recipientSigner(toKeyB);
|
|
418
|
+
tokenB.pubKey = recipientPubKey(toKeyB);
|
|
411
419
|
tokenB.pubKeyHash = Hash.hash160(tokenB.pubKey);
|
|
412
420
|
tokenB.issuerPubKey = this.issuerPubKey;
|
|
413
421
|
tokenB.genesisOutpoint = this.genesisOutpoint;
|
|
414
422
|
tokenB.balance = splitBalanceCommit;
|
|
423
|
+
tokenB.mintData = this.mintData;
|
|
415
424
|
tokenB.skipVerify = this.skipVerify;
|
|
416
425
|
tokenB.verifier = this.verifier;
|
|
417
426
|
return [this, tokenB];
|
|
@@ -420,13 +429,14 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
420
429
|
const input = {
|
|
421
430
|
sourceTransaction: this.tx,
|
|
422
431
|
sourceOutputIndex: this.voutIdx,
|
|
423
|
-
unlockingScriptTemplate:
|
|
432
|
+
unlockingScriptTemplate: this.template().melt(this.signer),
|
|
424
433
|
sequence: 0xffffffff,
|
|
425
434
|
};
|
|
426
435
|
const funding = {
|
|
427
436
|
sourceTransaction: this.tx,
|
|
437
|
+
/* v8 ignore next -- a token being melted always has its tx */
|
|
428
438
|
sourceOutputIndex: this.tx?.outputs ? this.tx?.outputs.length - 1 : 0,
|
|
429
|
-
unlockingScriptTemplate:
|
|
439
|
+
unlockingScriptTemplate: p2pkhUnlock(this.signer),
|
|
430
440
|
sequence: 0xffffffff,
|
|
431
441
|
};
|
|
432
442
|
const version = 2;
|
|
@@ -455,11 +465,12 @@ export class SimpleMultiBOLT extends BOLT {
|
|
|
455
465
|
input.sourceTXID = input.sourceTransaction.id('hex');
|
|
456
466
|
}
|
|
457
467
|
});
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
468
|
+
// verifyTx throws if any input fails (skipOutputCheck: zero-funding txs may have output > input); name the tx
|
|
469
|
+
try {
|
|
470
|
+
verifyTx(tx, true);
|
|
471
|
+
}
|
|
472
|
+
catch (e) {
|
|
473
|
+
throw new Error(`${txType} not valid: ${e.message}`);
|
|
463
474
|
}
|
|
464
475
|
}
|
|
465
476
|
}
|
|
@@ -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
|
+
}
|