@smartledger/bsv 8.1.0 → 8.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.
- package/CHANGELOG.md +82 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +47 -47
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +48 -48
- package/bsv.min.js +48 -48
- package/docs/AUDIT_SCOPE.md +8 -8
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/lib/gdaf/attestation-signer.js +90 -2
- package/lib/gdaf/attestation-verifier.js +41 -25
- package/lib/gdaf/zk-prover.js +143 -46
- package/package.json +3 -2
- package/test/gdaf/canonicalization.js +106 -0
- package/test/gdaf/zk_prover.js +204 -0
- package/tools/minimal_reproduction.js +119 -0
- package/tools/opcode_map.js +342 -0
- package/tools/server.js +97 -0
- package/tools/simple_real_tx.js +136 -0
- package/tools/sv-sighash-harness.js +123 -0
- package/tools/sv-sighash-report.js +71 -0
- package/tools/sv-tx-harness.js +172 -0
- package/tools/sv-tx-report.js +43 -0
- package/tools/sv-vector-harness.js +304 -0
- package/tools/sv-vector-report.js +88 -0
- package/version.js +1 -1
package/bsv-smartcontract.min.js
CHANGED
|
@@ -20,5 +20,5 @@ var bsvSmartContract=(()=>{var Vn=Object.create;var fr=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}`),Kt(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:"),Kt(i.stack||[],i.altstack||[]),console.log("===========================================")}function $i(e,t,r){console.log("==========================================="),console.log("\u{1F50D} SCRIPT INTERPRETER DEBUGGER (FULL RUN)"),console.log(`===========================================
|
|
22
22
|
`);let i=new at,n=new ws(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 Xi(){if(typeof S.default>"u"||!S.default.argv){console.log("\u2699\uFE0F CLI mode not available in browser environment");return}let e=S.default.argv.slice(2),t=v=>{let x=e.indexOf(v);return x!==-1&&e[x+1]?e[x+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 v=u.Buffer.concat([a.toBuffer(),c.toBuffer()]);d=he.fromBuffer(v)}let g=new Is,m=new Ts({prevTxId:"0".repeat(64),outputIndex:0,script:he.empty(),satoshis:1e5,output:new zi({satoshis:1e5,script:he.empty()})});g.addInput(m),g.addOutput(new zi({satoshis:1e5,script:he.empty()})),o?await Yi(d,g,!0):s?$i(a||he.empty(),c||he.empty(),g):console.log("\u2699\uFE0F No mode specified. Use --step or --truth")}zt.exports={parseScript:ot,printStack:Kt,stepThroughScript:Yi,runFullEvaluation:$i,main:Xi};typeof R<"u"&&R.main===zt&&Xi()});var le=P((Jc,rn)=>{"use strict";f();var Qi=b(),Xt=me(),Yt=V(),$t=D(),As=Fe(),Zi=Ke(),Ji=Ee(),ct=M(),bs=ge(),Wi=we(),jt=Wi.SIGHASH_ALL|Wi.SIGHASH_FORKID;function en(){var e=Xt;return e.SCRIPT_VERIFY_P2SH|e.SCRIPT_VERIFY_STRICTENC|e.SCRIPT_VERIFY_DERSIG|e.SCRIPT_VERIFY_LOW_S|e.SCRIPT_VERIFY_MINIMALDATA|e.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY|e.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY|e.SCRIPT_ENABLE_SIGHASH_FORKID|e.SCRIPT_ENABLE_MAGNETIC_OPCODES|e.SCRIPT_ENABLE_MONOLITH_OPCODES|e.SCRIPT_ENABLE_CHRONICLE}function ks(e){return Xt.useGenesisLimits(e)}function Hs(e,t,r){r=r||{};var i=new Xt,n=i.verify(e,t,r.tx||new $t,r.inputIndex||0,r.flags||en(),new ct(r.satoshis||0));return{ok:n,err:i.errstr||""}}function tn(e,t,r,i,n){return Ji.sighashPreimage(e,n||jt,t,r,new ct(i))}function Fs(e,t,r,i,n){return bs.sha256sha256(tn(e,t,r,i,n))}function Cs(e,t,r,i,n,o){o=o||jt;var s=Ji.sign(e,t,o,r,i,new ct(n));return u.Buffer.concat([s.toDER(),u.Buffer.from([o])])}function Rs(e,t,r){r=r||{};var i=new $t().addOutput(new Zi({script:e,satoshis:t})),n=new $t;return n.addInput(new As({prevTxId:i.hash,outputIndex:0,script:Qi.empty()}),e,t),r.outputs&&r.outputs.forEach(function(o){n.addOutput(o)}),{funding:i,spend:n}}function Ls(e,t){var r=e.toAddress?e.toAddress():e;return new Zi({script:Qi.buildPublicKeyHashOut(r),satoshis:t})}function Bs(e){return e===0?Yt.OP_0:e===-1?Yt.OP_1NEGATE:e>=1&&e<=16?Yt["OP_"+e]:new ct(e).toScriptNumBuffer()}rn.exports={SIGHASH:jt,flags:en,enableGenesis:ks,verify:Hs,rawPreimage:tn,sighashDigest:Fs,signInput:Cs,fundAndSpend:Rs,p2pkhOutput:Ls,scriptNum:Bs}});var cn=P((tu,an)=>{"use strict";f();var nn=ge(),on=le(),W=b(),T=V(),$e=on.signInput,sn=on.scriptNum;function Ns(e){var t=nn.sha256(e),r=new W().add(T.OP_SHA256).add(t).add(T.OP_EQUAL);return{lock:r,meta:{name:"hash-lock",digest:t.toString("hex")},unlock:function(i,n,o){return new W().add(o||e)}}}function Us(e){var t=e.toPublicKey(),r=W.buildPublicKeyHashOut(t.toAddress());return{lock:r,meta:{name:"p2pkh",address:t.toAddress().toString()},unlock:function(i,n){return new W().add($e(i,e,0,r,n)).add(t.toBuffer())}}}function qs(e,t){var r=e.toPublicKey(),i=new W().add(sn(t)).add(T.OP_CHECKLOCKTIMEVERIFY).add(T.OP_DROP).add(r.toBuffer()).add(T.OP_CHECKSIG);return{lock:i,meta:{name:"cltv-timelock",locktime:t},unlock:function(n,o){return new W().add($e(n,e,0,i,o))}}}function Ds(e,t){var r=t.map(function(n){return n.toPublicKey()}),i=new W().add(T["OP_"+e]);return r.forEach(function(n){i.add(n.toBuffer())}),i.add(T["OP_"+r.length]).add(T.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 W().add(T.OP_0);return s.forEach(function(c){a.add($e(n,c,0,i,o))}),a}}}function Ms(e){var t=nn.sha256(e.secret),r=new W().add(T.OP_IF).add(T.OP_SHA256).add(t).add(T.OP_EQUALVERIFY).add(e.receiver.toPublicKey().toBuffer()).add(T.OP_CHECKSIG).add(T.OP_ELSE).add(sn(e.timeout)).add(T.OP_CHECKLOCKTIMEVERIFY).add(T.OP_DROP).add(e.sender.toPublicKey().toBuffer()).add(T.OP_CHECKSIG).add(T.OP_ENDIF);return{lock:r,meta:{name:"htlc",digest:t.toString("hex"),timeout:e.timeout},unlockClaim:function(i,n){return new W().add($e(i,e.receiver,0,r,n)).add(e.secret).add(T.OP_1)},unlockRefund:function(i,n){return new W().add($e(i,e.sender,0,r,n)).add(T.OP_0)}}}an.exports={hashLock:Ns,p2pkh:Us,timeLockCLTV:qs,multisig:Ds,htlc:Ms}});var Xe=P((iu,mn)=>{"use strict";f();var un=b(),_=V(),re=we(),ut=M(),pn=ge(),Qt=le(),Zt=Qt.SIGHASH,pt=Qt.scriptNum,qe=u.Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Jt=new ut("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",16),Gs=u.Buffer.concat([u.Buffer.from([2]),qe]),hn=u.Buffer.from(qe).reverse(),ln=u.Buffer.concat([u.Buffer.from(Jt.toBuffer()).reverse(),u.Buffer.from([0])]),Vs=u.Buffer.concat([u.Buffer.from([48,68,2,32]),qe,u.Buffer.from([2,32])]);function Wt(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 Ks=re.SIGHASH_ALL|re.SIGHASH_FORKID,zs=re.SIGHASH_SINGLE|re.SIGHASH_FORKID,Ys=re.SIGHASH_SINGLE|re.SIGHASH_ANYONECANPAY|re.SIGHASH_FORKID,$s=re.SIGHASH_ALL|re.SIGHASH_ANYONECANPAY|re.SIGHASH_FORKID;function er(e,t){var r=t&&t.sighashType||Zt;return e.add(_.OP_HASH256),Wt(e,32),e.add(hn).add(_.OP_ADD),e.add(ln).add(_.OP_MOD),e.add(pt(32)).add(_.OP_NUM2BIN),Wt(e,32),e.add(qe).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 Xs(){return er(new un)}function dn(e){return e.add(pt(40)).add(_.OP_RIGHT).add(pt(32)).add(_.OP_LEFT),e}function js(e){return fn(e,Zt)}function fn(e,t){var r=u.Buffer.from([t&255,0,0,0]);return e.add(_.OP_DUP).add(pt(4)).add(_.OP_RIGHT).add(r).add(_.OP_EQUALVERIFY),e}function Ws(e){var t=u.Buffer.concat(e.map(function(r){return r.toBufferWriter().toBuffer()}));return pn.sha256sha256(t)}function Qs(e){var t=new un().add(_.OP_DUP);return er(t),t.add(_.OP_VERIFY),dn(t),t.add(u.Buffer.from(e)).add(_.OP_EQUAL),t}var Zs=new ut("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex");function gn(e){var t=pn.sha256sha256(e);if(t[0]<1||t[0]>127)return null;var r=new ut(t).add(new ut(qe)).mod(Jt);if(r.gt(Zs))return null;var i=r.toBuffer("be",32);return i[0]>=1?i:null}function Js(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||Zt;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 m=s+g;a==="nLockTime"?e.nLockTime=m:d.sequenceNumber=4294967294-m;var v=Qt.rawPreimage(e,t,r,i,c);if(gn(v))return{preimage:v,tries:g+1,field:a,nonce:m}}throw new Error("OP_PUSH_TX grind failed after "+o+" tries")}mn.exports={Gx:qe,N:Jt,PUBKEY:Gs,gxLe:hn,N_LE:ln,DER_PREFIX:Vs,reverseBytes:Wt,pushTxCore:er,authenticator:Xs,extractHashOutputs:dn,assertSighashAll:js,assertSighashType:fn,SIGHASH_ALL_FORKID:Ks,SIGHASH_SINGLE_FORKID:zs,SIGHASH_SINGLE_ANYONECANPAY_FORKID:Ys,SIGHASH_ALL_ANYONECANPAY_FORKID:$s,hashOutputs:Ws,valueCovenant:Qs,sFromPreimage:gn,grind:Js}});var rr=P((ou,Sn)=>{"use strict";f();var tr=Xe(),ea=le(),ta=b(),A=V(),De=ea.scriptNum;function ra(e){var t=new ta;return t.add(A.OP_DUP),tr.pushTxCore(t),t.add(A.OP_VERIFY),tr.assertSighashAll(t),t.add(A.OP_DUP),t.add(De(104)).add(A.OP_SPLIT).add(A.OP_NIP),t.add(A.OP_SIZE).add(De(52)).add(A.OP_SUB).add(A.OP_SPLIT).add(A.OP_DROP),t.add(A.OP_OVER),t.add(De(52)).add(A.OP_RIGHT).add(De(8)).add(A.OP_LEFT),t.add(A.OP_BIN2NUM).add(De(e)).add(A.OP_SUB),t.add(De(8)).add(A.OP_NUM2BIN),t.add(A.OP_SWAP).add(A.OP_CAT),t.add(A.OP_HASH256),t.add(A.OP_SWAP),tr.extractHashOutputs(t),t.add(A.OP_EQUAL),t}Sn.exports={pelsCovenant:ra}});var On=P((au,yn)=>{f();yn.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PublicKey});var or=P((uu,xn)=>{"use strict";f();var ia=Ve(),na=On(),oa=b(),Pn=ge(),nr=le(),E=V(),Me=nr.scriptNum;function ht(e){return e instanceof ia?e.toPublicKey().toBuffer():e instanceof na?e.toBuffer():e}function sa(){return{name:"single-key",commit:function(e){return Pn.sha256ripemd160(ht(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=nr.signInput(e,n,t,r,i);return[o,n.toPublicKey().toBuffer()]}}}function ir(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 oa().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 aa(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 Pn.sha256ripemd160(ir(e,r.map(ht)))},emit:function(r){r.add(E.OP_OVER).add(E.OP_HASH160).add(E.OP_EQUALVERIFY),r.add(Me(1)).add(E.OP_SPLIT).add(E.OP_NIP),r.add(E.OP_SIZE).add(Me(2)).add(E.OP_SUB).add(E.OP_SPLIT).add(E.OP_DROP);for(var i=0;i<this.n;i++)r.add(Me(34)).add(E.OP_SPLIT),r.add(E.OP_SWAP).add(Me(1)).add(E.OP_SPLIT).add(E.OP_NIP),r.add(E.OP_TOALTSTACK);for(r.add(E.OP_DROP),r.add(Me(this.m)),i=0;i<this.n;i++)r.add(E.OP_FROMALTSTACK);return r.add(Me(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=ir(e,a.map(ht)),d=a.map(ht).map(function(v){return v.toString("hex")}),g=s.signWith.map(function(v){var x=d.indexOf(v.toPublicKey().toBuffer().toString("hex"));if(x<0)throw new Error("signWith key is not in the committed key set");return{idx:x,priv:v}}).sort(function(v,x){return x.idx-v.idx}).slice(0,e);if(g.length<e)throw new Error("need at least "+e+" signing keys");var m=g.map(function(v){return nr.signInput(r,v.priv,i,n,o)});return[E.OP_0].concat(m).concat([c])}}}function ca(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}}xn.exports={singleKey:sa,multisig:aa,predicate:ca,redeemScript:ir}});var ar=P((hu,bn)=>{"use strict";f();var ua=M(),je=Xe(),sr=le(),We=or(),lt=b(),O=V(),ie=sr.scriptNum;function _n(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 vn(e,t){return t.length?e.add(u.Buffer.from(t)):e.add(O.OP_0)}function En(e,t){return e.add(O.OP_DUP),je.pushTxCore(e),e.add(O.OP_VERIFY),je.assertSighashAll(e),e.add(O.OP_DUP).add(ie(52)).add(O.OP_RIGHT).add(ie(8)).add(O.OP_LEFT).add(O.OP_TOALTSTACK),e.add(O.OP_DUP),je.extractHashOutputs(e),e.add(O.OP_TOALTSTACK),e.add(ie(104)).add(O.OP_SPLIT).add(O.OP_NIP).add(O.OP_SIZE).add(ie(52)).add(O.OP_SUB).add(O.OP_SPLIT).add(O.OP_DROP),e.add(O.OP_DUP).add(ie(4)).add(ie(20)).add(O.OP_SUBSTR),e.add(O.OP_SWAP).add(O.OP_TOALTSTACK),t.emit(e),e.add(O.OP_FROMALTSTACK),e}function wn(e){return e.add(ie(4)).add(O.OP_SPLIT).add(ie(20)).add(O.OP_SPLIT).add(O.OP_NIP),e.add(O.OP_TOALTSTACK),e.add(O.OP_SWAP).add(O.OP_CAT),e.add(O.OP_FROMALTSTACK).add(O.OP_CAT),e}function In(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 pa(e,t,r){r=r||We.singleKey();var i=new lt;return i.add(_n(t,r)),i.add(O.OP_DROP),En(i,r),wn(i),i.add(O.OP_FROMALTSTACK),i.add(O.OP_SWAP),i.add(O.OP_FROMALTSTACK),i.add(O.OP_BIN2NUM).add(ie(e)).add(O.OP_SUB).add(ie(8)).add(O.OP_NUM2BIN),i.add(O.OP_SWAP).add(O.OP_CAT),i.add(O.OP_HASH256),i.add(O.OP_EQUAL),In(i)}function Tn(e,t){t=t||We.singleKey();var r=new lt;return r.add(_n(e,t)),r.add(O.OP_DROP),En(r,t),wn(r),r.add(O.OP_CAT),r.add(O.OP_SWAP).add(O.OP_CAT),r.add(O.OP_CAT),r.add(O.OP_FROMALTSTACK),r.add(O.OP_FROMALTSTACK).add(O.OP_DROP),r.add(O.OP_SWAP).add(O.OP_HASH256).add(O.OP_EQUAL),In(r)}function ha(e){return We.singleKey().commit(e)}function la(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=sr.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(m){g.add(m)}),g.add(u.Buffer.from(c)),g}function An(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=sr.rawPreimage(r,c,n,i),g=a.unlockArgs(r,c,n,i,e),m=new lt;return vn(m,o.before||u.Buffer.alloc(0)),vn(m,o.after||u.Buffer.alloc(0)),m.add(u.Buffer.from(o.tokenValue)),m.add(u.Buffer.from(t)),g.forEach(function(v){m.add(v)}),m.add(u.Buffer.from(d)),m}function da(e,t){return Tn(e,t)}function fa(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(x){return x.toBufferWriter().toBuffer()}var g=u.Buffer.concat(a.slice(0,s).map(d)),m=u.Buffer.concat(a.slice(s+1).map(d)),v=new ua(i).toBuffer({endian:"little",size:8});return An(e,t,r,i,n,{before:g,after:m,tokenValue:v},o)}bn.exports={ownershipToken:pa,ownershipTokenMulti:Tn,ordinalLock:da,ownerId:ha,unlockTransfer:la,unlockTransferMulti:An,transferOrdinal:fa}});var dr=P((du,kn)=>{"use strict";f();var dt=Xe(),ga=rr(),ma=ar(),hr=le(),ur=b(),$=V(),pr=D(),cr=hr.scriptNum;function Sa(e,t){return e instanceof pr.Output?e:e instanceof ur?new pr.Output({script:e,satoshis:t}):hr.p2pkhOutput(e,t)}function ya(e,t,r,i,n,o){o=o||5e4;for(var s=0;s<o;s++){e.nLockTime=n+s;var a=hr.rawPreimage(e,t,r,i);if(dt.sFromPreimage(a))return a}throw new Error("covenant grind failed after "+o+" tries")}function de(){if(!(this instanceof de))return new de;this._outputs=[],this._minLockTime=null}de.prototype.payTo=function(e,t){return this._outputs.push(Sa(e,t)),this};de.prototype.lockUntil=function(e){return this._minLockTime=e,this};de.prototype.outputs=function(){return this._outputs.map(function(e){return new pr.Output(e.toObject())})};de.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 ")};de.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 ur().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(cr(8)).add($.OP_RIGHT).add(cr(4)).add($.OP_LEFT),t.add($.OP_BIN2NUM).add(cr(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 ur().add(ya(i,o,t,n,s))}}};function lr(){return new de}lr.perpetual=function(e){return ga.pelsCovenant(e)};lr.token=function(e,t){return ma.ownershipToken(e,t)};kn.exports={policy:lr,Policy:de}});var Ln=P((gu,Rn)=>{"use strict";f();var Oa=me(),Pa=M(),xa=D(),va=V(),_a=le();function Fn(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 va.fromNumber(e).toString()}catch{return"0x"+e.toString(16)}}function Hn(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 Ea(e,t,r){r=r||{};var i=new Oa,n=[];i.stepListener=function(s,a,c){n.push({phase:i.script===t?"lock":"unlock",op:Fn(s.opcode&&typeof s.opcode.toNumber=="function"?s.opcode.toNumber():s.opcode.num),stack:a.map(function(d){return Hn(d)}),altstack:c.map(function(d){return Hn(d)})})};var o=i.verify(e,t,r.tx||new xa,r.inputIndex||0,typeof r.flags=="number"?r.flags:_a.flags(),new Pa(r.satoshis||0));return{ok:o,err:i.errstr||"",steps:n}}function Cn(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 wa(e){return console.log(Cn(e)),e}Rn.exports={trace:Ea,format:Cn,print:wa,opLabel:Fn}});var Nn=P((Su,Bn)=>{"use strict";f();Bn.exports="8.
|
|
23
|
+
`)}function wa(e){return console.log(Cn(e)),e}Rn.exports={trace:Ea,format:Cn,print:wa,opLabel:Fn}});var Nn=P((Su,Bn)=>{"use strict";f();Bn.exports="8.2.0"});var Dn=P((Ou,qn)=>{"use strict";f();var Ia=ge(),Un=D(),Ta=It(),Aa=b(),h={Covenant:ii(),Preimage:te(),SIGHASH:ui(),Builder:di(),UTXOGenerator:ki(),ScriptTester:Li(),CovenantBuilder:qt().CovenantBuilder,CovenantTemplates:qt().CovenantTemplates,OpcodeMap:Bt(),ScriptUtils:Gi(),StackExaminer:Ki(),ScriptInterpreter:ji(),CovenantHelpers:le(),Locks:cn(),PushTx:Xe(),PELS:rr(),Token:ar(),Authorizers:or(),DSL:dr(),Policy:dr().Policy,Debugger:Ln()};h.policy=h.DSL.policy;h.trace=function(e,t,r){return h.Debugger.trace(e,t,r)};h.enableGenesis=function(e){return h.CovenantHelpers.enableGenesis(e)};h.verifyScript=function(e,t,r){return h.CovenantHelpers.verify(e,t,r)};h.perpetualCovenant=function(e){return h.PELS.pelsCovenant(e)};h.ownershipToken=function(e,t,r){return h.Token.ownershipToken(e,t,r)};h.valueCovenant=function(e){return h.PushTx.valueCovenant(e)};h.ordinalLock=function(e,t){return h.Token.ordinalLock(e,t)};h.transferOrdinal=function(e,t,r,i,n,o){return h.Token.transferOrdinal(e,t,r,i,n,o)};h.createCovenant=function(e,t){return new h.Covenant(e,t)};h.extractPreimage=function(e,t){return new h.Preimage(e,t)};h.analyzeSIGHASH=function(e){return new h.SIGHASH(e)};h.buildCovenant=function(e,t){return new h.Builder(e,t)};h.createUTXOGenerator=function(e){return new h.UTXOGenerator(e)};h.createTestEnvironment=function(e){return h.UTXOGenerator.createTestEnvironment(e)};h.testScript=function(e,t,r){return h.ScriptTester.test(e,t,r)};h.testCovenant=function(e,t,r){return h.ScriptTester.testCovenant(e,t,r)};h.testFieldExtraction=function(e,t,r){return h.ScriptTester.testFieldExtraction(e,t,r)};h.debugScript=function(e,t){var r=new h.ScriptTester(t);return r.debug(e)};h.explainZeroHashes=function(){return h.SIGHASH.explainZeroMystery()};h.getAllSIGHASHTypes=function(){return h.SIGHASH.getAllTypes()};h.demonstrateAllSIGHASH=function(){return h.SIGHASH.generateAllDemonstrations()};h.createCovenantBuilder=function(){return new h.CovenantBuilder};h.createValueLockCovenant=function(e){return h.CovenantTemplates.valueLock(e)};h.createHashLockCovenant=function(e){return h.CovenantTemplates.hashLock(e)};h.createComplexValidationCovenant=function(e){return h.CovenantTemplates.complexValidation(e)};h.getOpcodeMap=function(){return h.OpcodeMap.opcodeMap};h.simulateScript=function(e,t){return h.OpcodeMap.utils.simulate(e,t)};h.createASMFromJS=function(e){return h.OpcodeMap.utils.createASM(e)};h.scriptToASM=function(e){return h.ScriptUtils.scriptToASM(e)};h.asmToScript=function(e){return h.ScriptUtils.asmToScript(e)};h.asmToHex=function(e){return h.ScriptUtils.asmToHex(e)};h.hexToASM=function(e){return h.ScriptUtils.hexToASM(e)};h.scriptToHex=function(e){return h.ScriptUtils.scriptToHex(e)};h.validateASM=function(e){return h.ScriptUtils.validateASM(e)};h.validateScript=function(e){return h.ScriptUtils.validateScript(e)};h.estimateScriptSize=function(e){return h.ScriptUtils.estimateScriptSize(e)};h.optimizeScript=function(e){return h.ScriptUtils.optimizeScript(e)};h.compareScripts=function(e,t){return h.ScriptUtils.compareScripts(e,t)};h.explainScript=function(e){return h.ScriptUtils.explainScript(e)};h.scriptMetrics=function(e){return h.ScriptUtils.scriptMetrics(e)};h.analyzeComplexity=function(e){return h.ScriptUtils.analyzeComplexity(e)};h.findOptimizations=function(e){return h.ScriptUtils.findOptimizations(e)};h.covenantToEnglish=function(e){return h.ScriptUtils.covenantToEnglish(e)};h.batchTestScripts=function(e,t){return h.ScriptUtils.batchTestScripts(e,t)};h.examineStack=function(e,t){return h.StackExaminer.runScript(e,t)};h.debugScriptExecution=function(e,t,r){return r=r||{},r.stepMode?h.ScriptInterpreter.stepThroughScript(h.ScriptInterpreter.parseScript(e+" "+t),new Un,!0):h.ScriptInterpreter.runFullEvaluation(h.ScriptInterpreter.parseScript(e),h.ScriptInterpreter.parseScript(t),new Un)};h.parseScript=function(e){return h.ScriptInterpreter.parseScript(e)};h.printStack=function(e,t){return h.ScriptInterpreter.printStack(e,t)};h.createQuickCovenant=function(e,t){let r=h.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}`)}};h.completeCovenantFlow=function(e,t,r){var i=new h.Covenant(e);return i.completeFlow(t,r)};h.getEducationalResources=function(){return{zeroHashMystery:h.SIGHASH.explainZeroMystery(),sighashTypes:h.SIGHASH.getAllTypes(),exampleDemonstrations:h.SIGHASH.generateAllDemonstrations()}};h.utils={};h.utils.reconstructP2pkhScript=function(e){return Aa.buildPublicKeyHashOut(e).toHex()};h.utils.createCovenantAddress=function(e){var t=Ia.sha256ripemd160(e.toBuffer());return Ta.fromScriptHash(t)};h.utils.decodeCompactSize=function(e,t){return h.Preimage.decodeCompactSize(e,t)};h.version=Nn();h.description="Smart Contract Framework for Bitcoin SV";h.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};h.interpretScript=h.debugScriptExecution;h.getScriptMetrics=h.scriptMetrics;qn.exports=h});var ba=P((xu,Mn)=>{f();Mn.exports=Dn()});return ba();})();
|
|
24
24
|
if(typeof module!=="undefined"&&module.exports){module.exports=bsvSmartContract}else if(typeof define==="function"&&define.amd){define([],function(){return bsvSmartContract})}
|