@smartledger/bsv 9.1.0 → 9.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.
@@ -20,5 +20,5 @@ var bsvSmartContract=(()=>{var Yn=Object.create;var mr=Object.defineProperty;var
20
20
  [${s+1}/${n.length}] Step (${c})`);try{if(typeof i.step=="function")i.step();else{console.log("\u26A0\uFE0F Step-by-step execution not supported in this BSV version"),console.log("\u{1F4A1} Consider using runFullEvaluation instead");break}console.log(`\u{1F9E9} Executed: ${c}`),Yt(i.stack,i.altstack)}catch(d){console.log(`\u26A0\uFE0F Error executing ${c}: ${d.message}`);break}}o&&o.close(),console.log(`
21
21
  ===========================================`),console.log("\u2705 Final Stack State:"),Yt(i.stack||[],i.altstack||[]),console.log("===========================================")}function Zi(e,t,r){console.log("==========================================="),console.log("\u{1F50D} SCRIPT INTERPRETER DEBUGGER (FULL RUN)"),console.log(`===========================================
22
22
  `);let i=new at,n=new Hs(1e5),o=i.verify(e,t,r,0,at.SCRIPT_ENABLE_SIGHASH_FORKID,n);console.log("\u{1F510} Locking Script:",t.toASM()),console.log("\u{1F513} Unlocking Script:",e.toASM()),console.log("-------------------------------------------"),console.log("\u2705 Result:",o?"TRUE (Success)":"\u274C FALSE (Failure)"),console.log("Final Stack:",i.stack.map(s=>s.toString("hex"))),console.log("AltStack:",i.altstack.map(s=>s.toString("hex"))),console.log("===========================================")}async function Ji(){if(typeof m.default>"u"||!m.default.argv){console.log("\u2699\uFE0F CLI mode not available in browser environment");return}let e=m.default.argv.slice(2),t=P=>{let O=e.indexOf(P);return O!==-1&&e[O+1]?e[O+1]:null},r=t("--unlocking"),i=t("--locking"),n=t("--combined"),o=e.includes("--step"),s=e.includes("--truth"),a,c,d;if(n)d=ot(n);else{a=ot(r),c=ot(i);let P=u.Buffer.concat([a.toBuffer(),c.toBuffer()]);d=he.fromBuffer(P)}let g=new Fs,y=new Cs({prevTxId:"0".repeat(64),outputIndex:0,script:he.empty(),satoshis:1e5,output:new Wi({satoshis:1e5,script:he.empty()})});g.addInput(y),g.addOutput(new Wi({satoshis:1e5,script:he.empty()})),o?await Qi(d,g,!0):s?Zi(a||he.empty(),c||he.empty(),g):console.log("\u2699\uFE0F No mode specified. Use --step or --truth")}Xt.exports={parseScript:ot,printStack:Yt,stepThroughScript:Qi,runFullEvaluation:Zi,main:Ji};typeof C<"u"&&C.main===Xt&&Ji()});var pe=x((su,un)=>{"use strict";f();var rn=A(),nn=ge(),jt=G(),Wt=q(),Ls=He(),on=Ke(),sn=_e(),ct=D(),Rs=fe(),tn=Ee(),Qt=tn.SIGHASH_ALL|tn.SIGHASH_FORKID;function an(){return nn.mainnetFlags()}function Bs(e,t,r){r=r||{};var i=new nn,n=i.verify(e,t,r.tx||new Wt,r.inputIndex||0,r.flags||an(),new ct(r.satoshis||0));return{ok:n,err:i.errstr||""}}function cn(e,t,r,i,n){return sn.sighashPreimage(e,n||Qt,t,r,new ct(i))}function Ns(e,t,r,i,n){return Rs.sha256sha256(cn(e,t,r,i,n))}function Us(e,t,r,i,n,o){o=o||Qt;var s=sn.sign(e,t,o,r,i,new ct(n));return u.Buffer.concat([s.toDER(),u.Buffer.from([o])])}function qs(e,t,r){r=r||{};var i=new Wt().addOutput(new on({script:e,satoshis:t})),n=new Wt;return n.addInput(new Ls({prevTxId:i.hash,outputIndex:0,script:rn.empty()}),e,t),r.outputs&&r.outputs.forEach(function(o){n.addOutput(o)}),{funding:i,spend:n}}function Ds(e,t){var r=e.toAddress?e.toAddress():e;return new on({script:rn.buildPublicKeyHashOut(r),satoshis:t})}function Ms(e){return e===0?jt.OP_0:e===-1?jt.OP_1NEGATE:e>=1&&e<=16?jt["OP_"+e]:new ct(e).toScriptNumBuffer()}un.exports={SIGHASH:Qt,flags:an,verify:Bs,rawPreimage:cn,sighashDigest:Ns,signInput:Us,fundAndSpend:qs,p2pkhOutput:Ds,scriptNum:Ms}});var ln=x((cu,pn)=>{"use strict";f();var Gs=fe(),Vs=pe(),qe=A(),Ue=G(),hn=Vs.signInput;function zs(e){var t=Gs.sha256(e),r=new qe().add(Ue.OP_SHA256).add(t).add(Ue.OP_EQUAL);return{lock:r,meta:{name:"hash-lock",digest:t.toString("hex")},unlock:function(i,n,o){return new qe().add(o||e)}}}function Ks(e){var t=e.toPublicKey(),r=qe.buildPublicKeyHashOut(t.toAddress());return{lock:r,meta:{name:"p2pkh",address:t.toAddress().toString()},unlock:function(i,n){return new qe().add(hn(i,e,0,r,n)).add(t.toBuffer())}}}function $s(e,t){var r=t.map(function(n){return n.toPublicKey()}),i=new qe().add(Ue["OP_"+e]);return r.forEach(function(n){i.add(n.toBuffer())}),i.add(Ue["OP_"+r.length]).add(Ue.OP_CHECKMULTISIG),{lock:i,meta:{name:e+"-of-"+r.length+"-multisig"},unlock:function(n,o,s){s=s||t.slice(0,e);var a=new qe().add(Ue.OP_0);return s.forEach(function(c){a.add(hn(n,c,0,i,o))}),a}}}pn.exports={hashLock:zs,p2pkh:Ks,multisig:$s}});var Xe=x((hu,xn)=>{"use strict";f();var dn=A(),_=G(),ee=Ee(),ut=D(),fn=fe(),Jt=pe(),er=Jt.SIGHASH,ht=Jt.scriptNum,De=u.Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),tr=new ut("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",16),Ys=u.Buffer.concat([u.Buffer.from([2]),De]),gn=u.Buffer.from(De).reverse(),mn=u.Buffer.concat([u.Buffer.from(tr.toBuffer()).reverse(),u.Buffer.from([0])]),Xs=u.Buffer.concat([u.Buffer.from([48,68,2,32]),De,u.Buffer.from([2,32])]);function Zt(e,t){var r;for(r=0;r<t-1;r++)e.add(_.OP_1).add(_.OP_SPLIT);for(r=0;r<t-1;r++)e.add(_.OP_SWAP).add(_.OP_CAT);return e}var js=ee.SIGHASH_ALL|ee.SIGHASH_FORKID,Ws=ee.SIGHASH_SINGLE|ee.SIGHASH_FORKID,Qs=ee.SIGHASH_SINGLE|ee.SIGHASH_ANYONECANPAY|ee.SIGHASH_FORKID,Zs=ee.SIGHASH_ALL|ee.SIGHASH_ANYONECANPAY|ee.SIGHASH_FORKID;function rr(e,t){var r=t&&t.sighashType||er;return e.add(_.OP_HASH256),Zt(e,32),e.add(gn).add(_.OP_ADD),e.add(mn).add(_.OP_MOD),e.add(ht(32)).add(_.OP_NUM2BIN),Zt(e,32),e.add(De).add(_.OP_DUP),e.add(_.OP_2).add(_.OP_SWAP).add(_.OP_CAT),e.add(_.OP_TOALTSTACK),e.add(u.Buffer.from([48,68,2,32])).add(_.OP_SWAP).add(_.OP_CAT),e.add(u.Buffer.from([2,32])).add(_.OP_CAT),e.add(_.OP_SWAP).add(_.OP_CAT),e.add(u.Buffer.from([r])).add(_.OP_CAT),e.add(_.OP_FROMALTSTACK).add(_.OP_CHECKSIG),e}function Js(){return rr(new dn)}function yn(e){return e.add(ht(40)).add(_.OP_RIGHT).add(ht(32)).add(_.OP_LEFT),e}function ea(e){return Sn(e,er)}function Sn(e,t){var r=u.Buffer.from([t&255,0,0,0]);return e.add(_.OP_DUP).add(ht(4)).add(_.OP_RIGHT).add(r).add(_.OP_EQUALVERIFY),e}function ta(e){var t=u.Buffer.concat(e.map(function(r){return r.toBufferWriter().toBuffer()}));return fn.sha256sha256(t)}function ra(e){var t=new dn().add(_.OP_DUP);return rr(t),t.add(_.OP_VERIFY),yn(t),t.add(u.Buffer.from(e)).add(_.OP_EQUAL),t}var ia=new ut("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex");function vn(e){var t=fn.sha256sha256(e);if(t[0]<1||t[0]>127)return null;var r=new ut(t).add(new ut(De)).mod(tr);if(r.gt(ia))return null;var i=r.toBuffer("be",32);return i[0]>=1?i:null}function na(e,t,r,i,n){typeof n=="number"&&(n={maxTries:n}),n=n||{};var o=n.maxTries||5e3,s=n.start||0,a=n.field||"nLockTime",c=n.sighashType||er;if(a!=="nLockTime"&&a!=="sequence")throw new Error("grind field must be 'nLockTime' or 'sequence'");for(var d=e.inputs[t],g=0;g<o;g++){var y=s+g;a==="nLockTime"?e.nLockTime=y:d.sequenceNumber=4294967294-y;var P=Jt.rawPreimage(e,t,r,i,c);if(vn(P))return{preimage:P,tries:g+1,field:a,nonce:y}}throw new Error("OP_PUSH_TX grind failed after "+o+" tries")}xn.exports={Gx:De,N:tr,PUBKEY:Ys,gxLe:gn,N_LE:mn,DER_PREFIX:Xs,reverseBytes:Zt,pushTxCore:rr,authenticator:Js,extractHashOutputs:yn,assertSighashAll:ea,assertSighashType:Sn,SIGHASH_ALL_FORKID:js,SIGHASH_SINGLE_FORKID:Ws,SIGHASH_SINGLE_ANYONECANPAY_FORKID:Qs,SIGHASH_ALL_ANYONECANPAY_FORKID:Zs,hashOutputs:ta,valueCovenant:ra,sFromPreimage:vn,grind:na}});var nr=x((lu,On)=>{"use strict";f();var ir=Xe(),oa=pe(),sa=A(),T=G(),Me=oa.scriptNum;function aa(e){var t=new sa;return t.add(T.OP_DUP),ir.pushTxCore(t),t.add(T.OP_VERIFY),ir.assertSighashAll(t),t.add(T.OP_DUP),t.add(Me(104)).add(T.OP_SPLIT).add(T.OP_NIP),t.add(T.OP_SIZE).add(Me(52)).add(T.OP_SUB).add(T.OP_SPLIT).add(T.OP_DROP),t.add(T.OP_OVER),t.add(Me(52)).add(T.OP_RIGHT).add(Me(8)).add(T.OP_LEFT),t.add(T.OP_BIN2NUM).add(Me(e)).add(T.OP_SUB),t.add(Me(8)).add(T.OP_NUM2BIN),t.add(T.OP_SWAP).add(T.OP_CAT),t.add(T.OP_HASH256),t.add(T.OP_SWAP),ir.extractHashOutputs(t),t.add(T.OP_EQUAL),t}On.exports={pelsCovenant:aa}});var _n=x((fu,Pn)=>{f();Pn.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PublicKey});var ar=x((mu,wn)=>{"use strict";f();var ca=ze(),ua=_n(),ha=A(),En=fe(),sr=pe(),E=G(),Ge=sr.scriptNum;function pt(e){return e instanceof ca?e.toPublicKey().toBuffer():e instanceof ua?e.toBuffer():e}function pa(){return{name:"single-key",commit:function(e){return En.sha256ripemd160(pt(e))},emit:function(e){return e.add(E.OP_OVER).add(E.OP_HASH160).add(E.OP_EQUALVERIFY),e.add(E.OP_CHECKSIGVERIFY),e},unlockArgs:function(e,t,r,i,n){var o=sr.signInput(e,n,t,r,i);return[o,n.toPublicKey().toBuffer()]}}}function or(e,t){var r=t.length;if(e<1||e>r||r<1||r>16)throw new Error("multisig requires 1 <= m <= n <= 16");var i=new ha().add(E["OP_"+e]);return t.forEach(function(n){i.add(u.Buffer.from(n))}),i.add(E["OP_"+r]).add(E.OP_CHECKMULTISIG),i.toBuffer()}function la(e,t){if(typeof t!="number"||!Number.isInteger(t))throw new Error("multisig(m, nKeys): nKeys is the NUMBER of keys, not the keys themselves"+(Array.isArray(t)?" \u2014 pass "+t.length+" instead of the array":""));if(typeof e!="number"||!Number.isInteger(e))throw new Error("multisig(m, nKeys): m must be an integer");if(e<1||e>t||t<1||t>16)throw new Error("multisig requires 1 <= m <= n <= 16");return{name:e+"-of-"+t+"-multisig",m:e,n:t,commit:function(r){if(r.length!==t)throw new Error("expected "+t+" public keys");return En.sha256ripemd160(or(e,r.map(pt)))},emit:function(r){r.add(E.OP_OVER).add(E.OP_HASH160).add(E.OP_EQUALVERIFY),r.add(Ge(1)).add(E.OP_SPLIT).add(E.OP_NIP),r.add(E.OP_SIZE).add(Ge(2)).add(E.OP_SUB).add(E.OP_SPLIT).add(E.OP_DROP);for(var i=0;i<this.n;i++)r.add(Ge(34)).add(E.OP_SPLIT),r.add(E.OP_SWAP).add(Ge(1)).add(E.OP_SPLIT).add(E.OP_NIP),r.add(E.OP_TOALTSTACK);for(r.add(E.OP_DROP),r.add(Ge(this.m)),i=0;i<this.n;i++)r.add(E.OP_FROMALTSTACK);return r.add(Ge(this.n)),r.add(E.OP_CHECKMULTISIGVERIFY),r},unlockArgs:function(r,i,n,o,s){var a=s.keys;if(a.length!==t)throw new Error("expected "+t+" public keys in signer.keys");var c=or(e,a.map(pt)),d=a.map(pt).map(function(P){return P.toString("hex")}),g=s.signWith.map(function(P){var O=d.indexOf(P.toPublicKey().toBuffer().toString("hex"));if(O<0)throw new Error("signWith key is not in the committed key set");return{idx:O,priv:P}}).sort(function(P,O){return O.idx-P.idx}).slice(0,e);if(g.length<e)throw new Error("need at least "+e+" signing keys");var y=g.map(function(P){return sr.signInput(r,P.priv,i,n,o)});return[E.OP_0].concat(y).concat([c])}}}function da(e){if(!e||typeof e.emit!="function"||typeof e.unlockArgs!="function"||typeof e.commit!="function")throw new Error("predicate authorizer needs { commit, emit, unlockArgs } functions");return{name:e.name||"predicate",commit:e.commit,emit:e.emit,unlockArgs:e.unlockArgs}}wn.exports={singleKey:pa,multisig:la,predicate:da,redeemScript:or}});var ur=x((Su,Cn)=>{"use strict";f();var fa=D(),je=Xe(),cr=pe(),We=ar(),lt=A(),v=G(),te=cr.scriptNum;function Tn(e,t){var r=u.Buffer.isBuffer(e)?e:t.commit(e);if(r.length!==20)throw new Error("owner commitment must be 20 bytes (HASH160)");return r}function In(e,t){return t.length?e.add(u.Buffer.from(t)):e.add(v.OP_0)}function An(e,t){return e.add(v.OP_DUP),je.pushTxCore(e),e.add(v.OP_VERIFY),je.assertSighashAll(e),e.add(v.OP_DUP).add(te(52)).add(v.OP_RIGHT).add(te(8)).add(v.OP_LEFT).add(v.OP_TOALTSTACK),e.add(v.OP_DUP),je.extractHashOutputs(e),e.add(v.OP_TOALTSTACK),e.add(te(104)).add(v.OP_SPLIT).add(v.OP_NIP).add(v.OP_SIZE).add(te(52)).add(v.OP_SUB).add(v.OP_SPLIT).add(v.OP_DROP),e.add(v.OP_DUP).add(te(4)).add(te(20)).add(v.OP_SUBSTR),e.add(v.OP_SWAP).add(v.OP_TOALTSTACK),t.emit(e),e.add(v.OP_FROMALTSTACK),e}function bn(e){return e.add(te(4)).add(v.OP_SPLIT).add(te(20)).add(v.OP_SPLIT).add(v.OP_NIP),e.add(v.OP_TOALTSTACK),e.add(v.OP_SWAP).add(v.OP_CAT),e.add(v.OP_FROMALTSTACK).add(v.OP_CAT),e}function kn(e){var t=e.toBuffer().length;if(t<=252||t>65535)throw new Error("token script length must use a 3-byte varint (253..65535); got "+t);return e}function ga(e,t,r){r=r||We.singleKey();var i=new lt;return i.add(Tn(t,r)),i.add(v.OP_DROP),An(i,r),bn(i),i.add(v.OP_FROMALTSTACK),i.add(v.OP_SWAP),i.add(v.OP_FROMALTSTACK),i.add(v.OP_BIN2NUM).add(te(e)).add(v.OP_SUB).add(te(8)).add(v.OP_NUM2BIN),i.add(v.OP_SWAP).add(v.OP_CAT),i.add(v.OP_HASH256),i.add(v.OP_EQUAL),kn(i)}function Hn(e,t){t=t||We.singleKey();var r=new lt;return r.add(Tn(e,t)),r.add(v.OP_DROP),An(r,t),bn(r),r.add(v.OP_CAT),r.add(v.OP_SWAP).add(v.OP_CAT),r.add(v.OP_CAT),r.add(v.OP_FROMALTSTACK),r.add(v.OP_FROMALTSTACK).add(v.OP_DROP),r.add(v.OP_SWAP).add(v.OP_HASH256).add(v.OP_EQUAL),kn(r)}function ma(e){return We.singleKey().commit(e)}function ya(e,t,r,i,n,o){o=o||{};var s=o.auth||We.singleKey(),a=o.inputIndex||0;if(t.length!==20)throw new Error("newOwnerHash must be 20 bytes (HASH160)");if(i<=1&&!o.allowLowValue)throw new Error("unlockTransfer: single-output token sets output = input - fee, which burns a "+i+"-sat UTXO (e.g. a 1-sat ordinal). Use Token.transferOrdinal / ownershipTokenMulti to preserve the satoshi.");je.grind(r,a,n,i,o.grind);var c=cr.rawPreimage(r,a,n,i),d=s.unlockArgs(r,a,n,i,e),g=new lt().add(u.Buffer.from(t));return d.forEach(function(y){g.add(y)}),g.add(u.Buffer.from(c)),g}function Fn(e,t,r,i,n,o,s){s=s||{};var a=s.auth||We.singleKey(),c=s.inputIndex||0;if(t.length!==20)throw new Error("newOwnerHash must be 20 bytes (HASH160)");if(!o||o.tokenValue==null||o.tokenValue.length!==8)throw new Error("layout.tokenValue must be the 8-byte LE value of the token output");je.grind(r,c,n,i,s.grind);var d=cr.rawPreimage(r,c,n,i),g=a.unlockArgs(r,c,n,i,e),y=new lt;return In(y,o.before||u.Buffer.alloc(0)),In(y,o.after||u.Buffer.alloc(0)),y.add(u.Buffer.from(o.tokenValue)),y.add(u.Buffer.from(t)),g.forEach(function(P){y.add(P)}),y.add(u.Buffer.from(d)),y}function Sa(e,t){return Hn(e,t)}function va(e,t,r,i,n,o){o=o||{},i==null&&(i=1);var s=o.tokenIndex||0,a=r.outputs||[],c=a[s];if(!c)throw new Error("transferOrdinal: spend has no output at tokenIndex "+s);if(c.satoshis!==i)throw new Error("transferOrdinal: token output value ("+c.satoshis+" sat) must equal the ordinal value ("+i+" sat) to avoid burning the inscription");function d(O){return O.toBufferWriter().toBuffer()}var g=u.Buffer.concat(a.slice(0,s).map(d)),y=u.Buffer.concat(a.slice(s+1).map(d)),P=new fa(i).toBuffer({endian:"little",size:8});return Fn(e,t,r,i,n,{before:g,after:y,tokenValue:P},o)}Cn.exports={ownershipToken:ga,ownershipTokenMulti:Hn,ordinalLock:Sa,ownerId:ma,unlockTransfer:ya,unlockTransferMulti:Fn,transferOrdinal:va}});var gr=x((xu,Ln)=>{"use strict";f();var dt=Xe(),xa=nr(),Oa=ur(),dr=pe(),pr=A(),$=G(),lr=q(),hr=dr.scriptNum;function Pa(e,t){return e instanceof lr.Output?e:e instanceof pr?new lr.Output({script:e,satoshis:t}):dr.p2pkhOutput(e,t)}function _a(e,t,r,i,n,o){o=o||5e4;for(var s=0;s<o;s++){e.nLockTime=n+s;var a=dr.rawPreimage(e,t,r,i);if(dt.sFromPreimage(a))return a}throw new Error("covenant grind failed after "+o+" tries")}function le(){if(!(this instanceof le))return new le;this._outputs=[],this._minLockTime=null}le.prototype.payTo=function(e,t){return this._outputs.push(Pa(e,t)),this};le.prototype.lockUntil=function(e){return this._minLockTime=e,this};le.prototype.outputs=function(){return this._outputs.map(function(e){return new lr.Output(e.toObject())})};le.prototype.describe=function(){var e=[];return this._outputs.forEach(function(t,r){e.push("output["+r+"] = "+t.satoshis+" sat to "+t.script.toASM().slice(0,24)+"...")}),this._minLockTime!==null&&e.push("nLockTime >= "+this._minLockTime),"spend allowed iff: "+e.join(" AND ")};le.prototype.compile=function(){if(this._outputs.length===0&&this._minLockTime===null)throw new Error("empty policy: add at least one constraint (payTo / lockUntil)");var e=this,t=new pr().add($.OP_DUP);if(dt.pushTxCore(t),t.add($.OP_VERIFY),this._outputs.length){var r=dt.hashOutputs(this._outputs);t.add($.OP_DUP),dt.extractHashOutputs(t),t.add(u.Buffer.from(r)).add($.OP_EQUALVERIFY)}return this._minLockTime!==null&&(t.add($.OP_DUP),t.add(hr(8)).add($.OP_RIGHT).add(hr(4)).add($.OP_LEFT),t.add($.OP_BIN2NUM).add(hr(this._minLockTime)).add($.OP_GREATERTHANOREQUAL).add($.OP_VERIFY)),t.add($.OP_DROP).add($.OP_1),{lock:t,outputs:e.outputs(),describe:function(){return e.describe()},unlock:function(i,n,o){o=o||0;var s=e._minLockTime===null?0:e._minLockTime;return e._minLockTime!==null&&(i.inputs[o].sequenceNumber=4294967294),new pr().add(_a(i,o,t,n,s))}}};function fr(){return new le}fr.perpetual=function(e){return xa.pelsCovenant(e)};fr.token=function(e,t){return Oa.ownershipToken(e,t)};Ln.exports={policy:fr,Policy:le}});var qn=x((Pu,Un)=>{"use strict";f();var Ea=ge(),wa=D(),Ia=q(),Ta=G(),Aa=pe();function Bn(e){if(e===0)return"OP_0";if(e>=1&&e<=75)return"PUSH("+e+")";if(e===76)return"OP_PUSHDATA1";if(e===77)return"OP_PUSHDATA2";if(e===78)return"OP_PUSHDATA4";try{return Ta.fromNumber(e).toString()}catch{return"0x"+e.toString(16)}}function Rn(e,t){t=t||16;var r=u.Buffer.from(e).toString("hex");return r.length<=t*2?r||"0":r.slice(0,t*2)+"...("+e.length+"B)"}function ba(e,t,r){r=r||{};var i=new Ea,n=[];i.stepListener=function(s,a,c){n.push({phase:i.script===t?"lock":"unlock",op:Bn(s.opcode&&typeof s.opcode.toNumber=="function"?s.opcode.toNumber():s.opcode.num),stack:a.map(function(d){return Rn(d)}),altstack:c.map(function(d){return Rn(d)})})};var o=i.verify(e,t,r.tx||new Ia,r.inputIndex||0,typeof r.flags=="number"?r.flags:Aa.flags(),new wa(r.satoshis||0));return{ok:o,err:i.errstr||"",steps:n}}function Nn(e){var t=[],r=null;return e.steps.forEach(function(i,n){i.phase!==r&&(t.push("-- "+i.phase+" script --"),r=i.phase);var o=i.stack.length?i.stack.join(" | "):"(empty)",s=i.altstack.length?" alt:["+i.altstack.join(" | ")+"]":"";t.push(String(n).padStart(3)+" "+i.op.padEnd(16)+" -> ["+o+"]"+s)}),t.push((e.ok?"VALID":"INVALID")+(e.err?" ("+e.err+")":"")),t.join(`
23
- `)}function ka(e){return console.log(Nn(e)),e}Un.exports={trace:ba,format:Nn,print:ka,opLabel:Bn}});var Mn=x((Eu,Dn)=>{"use strict";f();Dn.exports="9.1.0"});var zn=x((Iu,Vn)=>{"use strict";f();var Ha=fe(),Gn=q(),Fa=It(),Ca=A(),p={Covenant:oi(),Preimage:J(),SIGHASH:pi(),Builder:Si(),UTXOGenerator:Ri(),ScriptTester:Di(),CovenantBuilder:Gt().CovenantBuilder,CovenantTemplates:Gt().CovenantTemplates,OpcodeMap:qt(),ScriptUtils:Yi(),StackExaminer:ji(),ScriptInterpreter:en(),CovenantHelpers:pe(),Locks:ln(),PushTx:Xe(),PELS:nr(),Token:ur(),Authorizers:ar(),DSL:gr(),Policy:gr().Policy,Debugger:qn()};p.policy=p.DSL.policy;p.trace=function(e,t,r){return p.Debugger.trace(e,t,r)};p.verifyScript=function(e,t,r){return p.CovenantHelpers.verify(e,t,r)};p.perpetualCovenant=function(e){return p.PELS.pelsCovenant(e)};p.ownershipToken=function(e,t,r){return p.Token.ownershipToken(e,t,r)};p.valueCovenant=function(e){return p.PushTx.valueCovenant(e)};p.ordinalLock=function(e,t){return p.Token.ordinalLock(e,t)};p.transferOrdinal=function(e,t,r,i,n,o){return p.Token.transferOrdinal(e,t,r,i,n,o)};p.createCovenant=function(e,t){return new p.Covenant(e,t)};p.extractPreimage=function(e,t){return new p.Preimage(e,t)};p.analyzeSIGHASH=function(e){return new p.SIGHASH(e)};p.buildCovenant=function(e,t){return new p.Builder(e,t)};p.createUTXOGenerator=function(e){return new p.UTXOGenerator(e)};p.createTestEnvironment=function(e){return p.UTXOGenerator.createTestEnvironment(e)};p.testScript=function(e,t,r){return p.ScriptTester.test(e,t,r)};p.testCovenant=function(e,t,r){return p.ScriptTester.testCovenant(e,t,r)};p.testFieldExtraction=function(e,t,r){return p.ScriptTester.testFieldExtraction(e,t,r)};p.debugScript=function(e,t){var r=new p.ScriptTester(t);return r.debug(e)};p.explainZeroHashes=function(){return p.SIGHASH.explainZeroMystery()};p.getAllSIGHASHTypes=function(){return p.SIGHASH.getAllTypes()};p.demonstrateAllSIGHASH=function(){return p.SIGHASH.generateAllDemonstrations()};p.createCovenantBuilder=function(){return new p.CovenantBuilder};p.createValueLockCovenant=function(e){return p.CovenantTemplates.valueLock(e)};p.createHashLockCovenant=function(e){return p.CovenantTemplates.hashLock(e)};p.createComplexValidationCovenant=function(e){return p.CovenantTemplates.complexValidation(e)};p.getOpcodeMap=function(){return p.OpcodeMap.opcodeMap};p.simulateScript=function(e,t){return p.OpcodeMap.utils.simulate(e,t)};p.createASMFromJS=function(e){return p.OpcodeMap.utils.createASM(e)};p.scriptToASM=function(e){return p.ScriptUtils.scriptToASM(e)};p.asmToScript=function(e){return p.ScriptUtils.asmToScript(e)};p.asmToHex=function(e){return p.ScriptUtils.asmToHex(e)};p.hexToASM=function(e){return p.ScriptUtils.hexToASM(e)};p.scriptToHex=function(e){return p.ScriptUtils.scriptToHex(e)};p.validateASM=function(e){return p.ScriptUtils.validateASM(e)};p.validateScript=function(e){return p.ScriptUtils.validateScript(e)};p.estimateScriptSize=function(e){return p.ScriptUtils.estimateScriptSize(e)};p.optimizeScript=function(e){return p.ScriptUtils.optimizeScript(e)};p.compareScripts=function(e,t){return p.ScriptUtils.compareScripts(e,t)};p.explainScript=function(e){return p.ScriptUtils.explainScript(e)};p.scriptMetrics=function(e){return p.ScriptUtils.scriptMetrics(e)};p.analyzeComplexity=function(e){return p.ScriptUtils.analyzeComplexity(e)};p.findOptimizations=function(e){return p.ScriptUtils.findOptimizations(e)};p.covenantToEnglish=function(e){return p.ScriptUtils.covenantToEnglish(e)};p.batchTestScripts=function(e,t){return p.ScriptUtils.batchTestScripts(e,t)};p.examineStack=function(e,t){return p.StackExaminer.runScript(e,t)};p.debugScriptExecution=function(e,t,r){return r=r||{},r.stepMode?p.ScriptInterpreter.stepThroughScript(p.ScriptInterpreter.parseScript(e+" "+t),new Gn,!0):p.ScriptInterpreter.runFullEvaluation(p.ScriptInterpreter.parseScript(e),p.ScriptInterpreter.parseScript(t),new Gn)};p.parseScript=function(e){return p.ScriptInterpreter.parseScript(e)};p.printStack=function(e,t){return p.ScriptInterpreter.printStack(e,t)};p.createQuickCovenant=function(e,t){let r=p.createCovenantBuilder();switch(e){case"value_lock":return r.comment(`Value lock: minimum ${t.value} satoshis`).extractField("value").push(t.value).greaterThanOrEqual().verify().build();case"hash_lock":return r.comment(`Hash lock: requires preimage of ${t.hash}`).push("secret_placeholder").sha256().push(t.hash).equalVerify().build();case"time_lock":return r.comment(`Time lock: requires nLockTime > ${t.timestamp}`).extractField("nLockTime").push(t.timestamp).greaterThan().verify().build();case"multi_condition":let i=r.comment("Multi-condition covenant");return t.conditions.forEach(n=>{switch(n.type){case"value":i=i.extractField("value").push(n.value).greaterThanOrEqual().verify();break;case"hash":i=i.push("secret_placeholder").sha256().push(n.hash).equalVerify();break;case"time":i=i.extractField("nLockTime").push(n.timestamp).greaterThan().verify();break}}),i.build();default:throw new Error(`Unknown covenant type: ${e}`)}};p.completeCovenantFlow=function(e,t,r){var i=new p.Covenant(e);return i.completeFlow(t,r)};p.getEducationalResources=function(){return{zeroHashMystery:p.SIGHASH.explainZeroMystery(),sighashTypes:p.SIGHASH.getAllTypes(),exampleDemonstrations:p.SIGHASH.generateAllDemonstrations()}};p.utils={};p.utils.reconstructP2pkhScript=function(e){return Ca.buildPublicKeyHashOut(e).toHex()};p.utils.createCovenantAddress=function(e){var t=Ha.sha256ripemd160(e.toBuffer());return Fa.fromScriptHash(t)};p.utils.decodeCompactSize=function(e,t){return p.Preimage.decodeCompactSize(e,t)};p.version=Mn();p.description="Smart Contract Framework for Bitcoin SV";p.features={BIP143_PREIMAGE:!0,COMPACT_SIZE_VARINT:!0,BIDIRECTIONAL_EXTRACTION:!0,SIGHASH_DETECTION:!0,ZERO_HASH_WARNINGS:!0,MULTI_FIELD_VALIDATION:!0,REAL_UTXO_GENERATION:!0,SCRIPT_TESTING:!0,LOCAL_VERIFICATION:!0,JAVASCRIPT_TO_SCRIPT:!0,OPCODE_MAPPING:!0,COVENANT_BUILDER:!0,SCRIPT_ANALYSIS:!0,SCRIPT_OPTIMIZATION:!0,SCRIPT_CONVERSION:!0,BATCH_TESTING:!0,QUICK_COVENANTS:!0,SCRIPT_EXPLANATIONS:!0,STACK_EXAMINATION:!0,SCRIPT_DEBUGGING:!0,STEP_BY_STEP_EXECUTION:!0,INTERACTIVE_DEBUGGING:!0};p.interpretScript=p.debugScriptExecution;p.getScriptMetrics=p.scriptMetrics;Vn.exports=p});var La=x((Au,Kn)=>{f();Kn.exports=zn()});return La();})();
23
+ `)}function ka(e){return console.log(Nn(e)),e}Un.exports={trace:ba,format:Nn,print:ka,opLabel:Bn}});var Mn=x((Eu,Dn)=>{"use strict";f();Dn.exports="9.2.0"});var zn=x((Iu,Vn)=>{"use strict";f();var Ha=fe(),Gn=q(),Fa=It(),Ca=A(),p={Covenant:oi(),Preimage:J(),SIGHASH:pi(),Builder:Si(),UTXOGenerator:Ri(),ScriptTester:Di(),CovenantBuilder:Gt().CovenantBuilder,CovenantTemplates:Gt().CovenantTemplates,OpcodeMap:qt(),ScriptUtils:Yi(),StackExaminer:ji(),ScriptInterpreter:en(),CovenantHelpers:pe(),Locks:ln(),PushTx:Xe(),PELS:nr(),Token:ur(),Authorizers:ar(),DSL:gr(),Policy:gr().Policy,Debugger:qn()};p.policy=p.DSL.policy;p.trace=function(e,t,r){return p.Debugger.trace(e,t,r)};p.verifyScript=function(e,t,r){return p.CovenantHelpers.verify(e,t,r)};p.perpetualCovenant=function(e){return p.PELS.pelsCovenant(e)};p.ownershipToken=function(e,t,r){return p.Token.ownershipToken(e,t,r)};p.valueCovenant=function(e){return p.PushTx.valueCovenant(e)};p.ordinalLock=function(e,t){return p.Token.ordinalLock(e,t)};p.transferOrdinal=function(e,t,r,i,n,o){return p.Token.transferOrdinal(e,t,r,i,n,o)};p.createCovenant=function(e,t){return new p.Covenant(e,t)};p.extractPreimage=function(e,t){return new p.Preimage(e,t)};p.analyzeSIGHASH=function(e){return new p.SIGHASH(e)};p.buildCovenant=function(e,t){return new p.Builder(e,t)};p.createUTXOGenerator=function(e){return new p.UTXOGenerator(e)};p.createTestEnvironment=function(e){return p.UTXOGenerator.createTestEnvironment(e)};p.testScript=function(e,t,r){return p.ScriptTester.test(e,t,r)};p.testCovenant=function(e,t,r){return p.ScriptTester.testCovenant(e,t,r)};p.testFieldExtraction=function(e,t,r){return p.ScriptTester.testFieldExtraction(e,t,r)};p.debugScript=function(e,t){var r=new p.ScriptTester(t);return r.debug(e)};p.explainZeroHashes=function(){return p.SIGHASH.explainZeroMystery()};p.getAllSIGHASHTypes=function(){return p.SIGHASH.getAllTypes()};p.demonstrateAllSIGHASH=function(){return p.SIGHASH.generateAllDemonstrations()};p.createCovenantBuilder=function(){return new p.CovenantBuilder};p.createValueLockCovenant=function(e){return p.CovenantTemplates.valueLock(e)};p.createHashLockCovenant=function(e){return p.CovenantTemplates.hashLock(e)};p.createComplexValidationCovenant=function(e){return p.CovenantTemplates.complexValidation(e)};p.getOpcodeMap=function(){return p.OpcodeMap.opcodeMap};p.simulateScript=function(e,t){return p.OpcodeMap.utils.simulate(e,t)};p.createASMFromJS=function(e){return p.OpcodeMap.utils.createASM(e)};p.scriptToASM=function(e){return p.ScriptUtils.scriptToASM(e)};p.asmToScript=function(e){return p.ScriptUtils.asmToScript(e)};p.asmToHex=function(e){return p.ScriptUtils.asmToHex(e)};p.hexToASM=function(e){return p.ScriptUtils.hexToASM(e)};p.scriptToHex=function(e){return p.ScriptUtils.scriptToHex(e)};p.validateASM=function(e){return p.ScriptUtils.validateASM(e)};p.validateScript=function(e){return p.ScriptUtils.validateScript(e)};p.estimateScriptSize=function(e){return p.ScriptUtils.estimateScriptSize(e)};p.optimizeScript=function(e){return p.ScriptUtils.optimizeScript(e)};p.compareScripts=function(e,t){return p.ScriptUtils.compareScripts(e,t)};p.explainScript=function(e){return p.ScriptUtils.explainScript(e)};p.scriptMetrics=function(e){return p.ScriptUtils.scriptMetrics(e)};p.analyzeComplexity=function(e){return p.ScriptUtils.analyzeComplexity(e)};p.findOptimizations=function(e){return p.ScriptUtils.findOptimizations(e)};p.covenantToEnglish=function(e){return p.ScriptUtils.covenantToEnglish(e)};p.batchTestScripts=function(e,t){return p.ScriptUtils.batchTestScripts(e,t)};p.examineStack=function(e,t){return p.StackExaminer.runScript(e,t)};p.debugScriptExecution=function(e,t,r){return r=r||{},r.stepMode?p.ScriptInterpreter.stepThroughScript(p.ScriptInterpreter.parseScript(e+" "+t),new Gn,!0):p.ScriptInterpreter.runFullEvaluation(p.ScriptInterpreter.parseScript(e),p.ScriptInterpreter.parseScript(t),new Gn)};p.parseScript=function(e){return p.ScriptInterpreter.parseScript(e)};p.printStack=function(e,t){return p.ScriptInterpreter.printStack(e,t)};p.createQuickCovenant=function(e,t){let r=p.createCovenantBuilder();switch(e){case"value_lock":return r.comment(`Value lock: minimum ${t.value} satoshis`).extractField("value").push(t.value).greaterThanOrEqual().verify().build();case"hash_lock":return r.comment(`Hash lock: requires preimage of ${t.hash}`).push("secret_placeholder").sha256().push(t.hash).equalVerify().build();case"time_lock":return r.comment(`Time lock: requires nLockTime > ${t.timestamp}`).extractField("nLockTime").push(t.timestamp).greaterThan().verify().build();case"multi_condition":let i=r.comment("Multi-condition covenant");return t.conditions.forEach(n=>{switch(n.type){case"value":i=i.extractField("value").push(n.value).greaterThanOrEqual().verify();break;case"hash":i=i.push("secret_placeholder").sha256().push(n.hash).equalVerify();break;case"time":i=i.extractField("nLockTime").push(n.timestamp).greaterThan().verify();break}}),i.build();default:throw new Error(`Unknown covenant type: ${e}`)}};p.completeCovenantFlow=function(e,t,r){var i=new p.Covenant(e);return i.completeFlow(t,r)};p.getEducationalResources=function(){return{zeroHashMystery:p.SIGHASH.explainZeroMystery(),sighashTypes:p.SIGHASH.getAllTypes(),exampleDemonstrations:p.SIGHASH.generateAllDemonstrations()}};p.utils={};p.utils.reconstructP2pkhScript=function(e){return Ca.buildPublicKeyHashOut(e).toHex()};p.utils.createCovenantAddress=function(e){var t=Ha.sha256ripemd160(e.toBuffer());return Fa.fromScriptHash(t)};p.utils.decodeCompactSize=function(e,t){return p.Preimage.decodeCompactSize(e,t)};p.version=Mn();p.description="Smart Contract Framework for Bitcoin SV";p.features={BIP143_PREIMAGE:!0,COMPACT_SIZE_VARINT:!0,BIDIRECTIONAL_EXTRACTION:!0,SIGHASH_DETECTION:!0,ZERO_HASH_WARNINGS:!0,MULTI_FIELD_VALIDATION:!0,REAL_UTXO_GENERATION:!0,SCRIPT_TESTING:!0,LOCAL_VERIFICATION:!0,JAVASCRIPT_TO_SCRIPT:!0,OPCODE_MAPPING:!0,COVENANT_BUILDER:!0,SCRIPT_ANALYSIS:!0,SCRIPT_OPTIMIZATION:!0,SCRIPT_CONVERSION:!0,BATCH_TESTING:!0,QUICK_COVENANTS:!0,SCRIPT_EXPLANATIONS:!0,STACK_EXAMINATION:!0,SCRIPT_DEBUGGING:!0,STEP_BY_STEP_EXECUTION:!0,INTERACTIVE_DEBUGGING:!0};p.interpretScript=p.debugScriptExecution;p.getScriptMetrics=p.scriptMetrics;Vn.exports=p});var La=x((Au,Kn)=>{f();Kn.exports=zn()});return La();})();
24
24
  if(typeof module!=="undefined"&&module.exports){module.exports=bsvSmartContract}else if(typeof define==="function"&&define.amd){define([],function(){return bsvSmartContract})}