smartledger-bsv 3.2.1 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +289 -55
  3. package/architecture_demo.js +247 -0
  4. package/bsv-covenant.min.js +10 -0
  5. package/bsv-gdaf.min.js +37 -0
  6. package/bsv-ltp.min.js +37 -0
  7. package/bsv-script-helper.min.js +10 -0
  8. package/bsv-security.min.js +31 -0
  9. package/bsv-shamir.min.js +12 -0
  10. package/bsv-smartcontract.min.js +37 -0
  11. package/bsv.bundle.js +9 -9
  12. package/bsv.min.js +3 -3
  13. package/build/bsv-covenant.min.js +10 -0
  14. package/build/bsv-script-helper.min.js +10 -0
  15. package/build/bsv-security.min.js +31 -0
  16. package/build/bsv-smartcontract.min.js +39 -0
  17. package/build/bsv.bundle.js +39 -0
  18. package/build/bsv.min.js +39 -0
  19. package/build/webpack.bundle.config.js +22 -0
  20. package/build/webpack.config.js +18 -0
  21. package/build/webpack.covenant.config.js +27 -0
  22. package/build/webpack.gdaf.config.js +54 -0
  23. package/build/webpack.ltp.config.js +17 -0
  24. package/build/webpack.script-helper.config.js +27 -0
  25. package/build/webpack.security.config.js +23 -0
  26. package/build/webpack.smartcontract.config.js +25 -0
  27. package/build/webpack.subproject.config.js +6 -0
  28. package/bundle-entry.js +341 -0
  29. package/complete_ltp_demo.js +511 -0
  30. package/covenant-entry.js +44 -0
  31. package/docs/pushtx-key-insights.md +106 -0
  32. package/gdaf-entry.js +54 -0
  33. package/index.js +272 -5
  34. package/lib/crypto/shamir.js +360 -0
  35. package/lib/gdaf/attestation-signer.js +461 -0
  36. package/lib/gdaf/attestation-verifier.js +600 -0
  37. package/lib/gdaf/did-resolver.js +382 -0
  38. package/lib/gdaf/index.js +471 -0
  39. package/lib/gdaf/schema-validator.js +682 -0
  40. package/lib/gdaf/smartledger-anchor.js +486 -0
  41. package/lib/gdaf/zk-prover.js +507 -0
  42. package/lib/ltp/anchor.js +438 -0
  43. package/lib/ltp/claim.js +1026 -0
  44. package/lib/ltp/index.js +470 -0
  45. package/lib/ltp/obligation.js +945 -0
  46. package/lib/ltp/proof.js +828 -0
  47. package/lib/ltp/registry.js +702 -0
  48. package/lib/ltp/right.js +765 -0
  49. package/lib/smart_contract/API_REFERENCE.md +1 -1
  50. package/lib/smart_contract/EXAMPLES.md +2 -2
  51. package/lib/smart_contract/QUICK_START.md +2 -2
  52. package/lib/smart_contract/README.md +1 -1
  53. package/lib/smart_contract/index.js +4 -0
  54. package/ltp-entry.js +92 -0
  55. package/package.json +91 -20
  56. package/script-helper-entry.js +49 -0
  57. package/security-entry.js +70 -0
  58. package/shamir-entry.js +173 -0
  59. package/shamir_demo.js +121 -0
  60. package/simple_demo.js +204 -0
  61. package/smartcontract-entry.js +133 -0
  62. package/test_shamir.js +221 -0
  63. package/test_standalone_shamir.html +83 -0
  64. package/tests/bundle-completeness-test.html +131 -0
  65. package/tests/bundle-demo.html +476 -0
  66. package/tests/smartcontract-test.html +239 -0
  67. package/tests/standalone-modules-test.html +260 -0
  68. package/tests/test.html +612 -0
  69. package/tests/unpkg-demo.html +194 -0
  70. package/docs/nchain.md +0 -958
@@ -0,0 +1,247 @@
1
+ /**
2
+ * SmartLedger-BSV Legal Token Protocol (LTP) - Primitives-Only Architecture Demo
3
+ *
4
+ * This demonstrates the key architectural difference:
5
+ * BEFORE: Library did blockchain publishing and storage
6
+ * AFTER: Library provides preparation primitives, external systems handle publishing
7
+ */
8
+
9
+ const bsv = require('./index.js')
10
+
11
+ console.log('🚀 SmartLedger-BSV LTP: Primitives-Only Architecture')
12
+ console.log('==================================================\n')
13
+
14
+ console.log('🔄 ARCHITECTURAL TRANSFORMATION DEMO')
15
+ console.log('------------------------------------\n')
16
+
17
+ // Demo keys and identities
18
+ const issuerPrivateKey = new bsv.PrivateKey()
19
+ const ownerDID = `did:bsv:${new bsv.PrivateKey().publicKey.toString()}`
20
+ const obligorDID = `did:bsv:${new bsv.PrivateKey().publicKey.toString()}`
21
+
22
+ console.log('📋 Participants:')
23
+ console.log(` Issuer DID: ${issuerPrivateKey.publicKey.toString()}`)
24
+ console.log(` Owner DID: ${ownerDID}`)
25
+ console.log(` Obligor DID: ${obligorDID}\n`)
26
+
27
+ /**
28
+ * DEMONSTRATE CLAIM VALIDATION PRIMITIVES
29
+ */
30
+ console.log('1️⃣ CLAIM VALIDATION - Primitives Only')
31
+ console.log('=====================================')
32
+
33
+ const propertyClaimData = {
34
+ type: 'PropertyTitle',
35
+ property: {
36
+ address: '123 Blockchain Street',
37
+ parcel_id: 'BLK-2024-001',
38
+ property_type: 'residential'
39
+ },
40
+ owner: ownerDID
41
+ }
42
+
43
+ // Get available schemas (unchanged utility)
44
+ const availableSchemas = bsv.getClaimSchemaNames()
45
+ console.log('📚 Available claim schemas:', availableSchemas.join(', '))
46
+
47
+ // Create claim template (utility function)
48
+ const claimTemplate = bsv.createClaimTemplate('PropertyTitle')
49
+ console.log('📋 Claim template structure:')
50
+ console.log(' Required fields:', Object.keys(claimTemplate.properties).slice(0, 3).join(', '), '...')
51
+
52
+ console.log('\n🔧 PRIMITIVES-ONLY APPROACH:')
53
+ console.log(' ✅ Library validates claim structure')
54
+ console.log(' ✅ Library provides canonicalization')
55
+ console.log(' ✅ Library generates claim hash')
56
+ console.log(' ❌ Library does NOT store claims')
57
+ console.log(' ❌ Library does NOT publish to blockchain')
58
+
59
+ // Demonstrate claim processing primitives
60
+ const claimHash = bsv.hashClaim(propertyClaimData)
61
+ const canonicalClaim = bsv.canonicalizeClaim(propertyClaimData)
62
+
63
+ console.log('📊 Claim processing results:')
64
+ console.log(` Claim Hash: ${claimHash}`)
65
+ console.log(` Canonical Form: ${canonicalClaim.length} bytes`)
66
+ console.log('')
67
+
68
+ /**
69
+ * DEMONSTRATE RIGHT TOKEN PRIMITIVES
70
+ */
71
+ console.log('2️⃣ RIGHT TOKEN - Preparation Primitives')
72
+ console.log('=======================================')
73
+
74
+ console.log('🔧 PRIMITIVES-ONLY APPROACH:')
75
+
76
+ // Get available right types
77
+ const rightTypes = bsv.getRightTypes()
78
+ console.log('⚖️ Available right types:', Object.keys(rightTypes).slice(0, 4).join(', '), '...')
79
+
80
+ // Prepare right token (doesn't create, just prepares structure)
81
+ try {
82
+ const rightTokenPrep = bsv.prepareRightToken(
83
+ 'PROPERTY_OWNERSHIP',
84
+ `did:bsv:${issuerPrivateKey.publicKey.toString()}`,
85
+ ownerDID,
86
+ propertyClaimData,
87
+ issuerPrivateKey,
88
+ {
89
+ jurisdiction: 'demo_jurisdiction',
90
+ validUntil: '2034-01-15'
91
+ }
92
+ )
93
+
94
+ console.log('🏠 Right token prepared:')
95
+ console.log(` Token ID: ${rightTokenPrep.tokenId}`)
96
+ console.log(` Right Type: ${rightTokenPrep.rightType}`)
97
+ console.log(` Valid Until: ${rightTokenPrep.validUntil}`)
98
+ console.log(` Jurisdiction: ${rightTokenPrep.jurisdiction}`)
99
+
100
+ // Prepare verification data
101
+ const verificationPrep = bsv.prepareRightTokenVerification(rightTokenPrep.token)
102
+ console.log(` Verification Ready: ${verificationPrep.isValid ? 'YES' : 'NO'}`)
103
+
104
+ console.log('\n ✅ Library prepares token structure')
105
+ console.log(' ✅ Library validates token format')
106
+ console.log(' ✅ Library signs token data')
107
+ console.log(' ❌ Library does NOT publish to blockchain')
108
+ console.log(' ❌ Library does NOT store in registry')
109
+
110
+ } catch (error) {
111
+ console.log('⚠️ Right token preparation demo skipped (module loading)')
112
+ console.log(' Expected: Token preparation without blockchain publishing')
113
+ }
114
+
115
+ console.log('')
116
+
117
+ /**
118
+ * DEMONSTRATE OBLIGATION PRIMITIVES
119
+ */
120
+ console.log('3️⃣ OBLIGATION TOKEN - Management Primitives')
121
+ console.log('===========================================')
122
+
123
+ console.log('🔧 PRIMITIVES-ONLY APPROACH:')
124
+
125
+ // Get obligation types and statuses
126
+ try {
127
+ const obligationTypes = bsv.getObligationTypes()
128
+ const obligationStatuses = bsv.getObligationStatus()
129
+
130
+ console.log('📊 Obligation framework:')
131
+ console.log(` Types available: ${Object.keys(obligationTypes).length}`)
132
+ console.log(` Status options: ${Object.keys(obligationStatuses).length}`)
133
+ console.log(` Priority levels: ${Object.keys(bsv.getObligationPriority()).length}`)
134
+
135
+ console.log('\n ✅ Library prepares obligation tokens')
136
+ console.log(' ✅ Library validates fulfillment data')
137
+ console.log(' ✅ Library tracks obligation status')
138
+ console.log(' ❌ Library does NOT execute payments')
139
+ console.log(' ❌ Library does NOT enforce obligations')
140
+
141
+ } catch (error) {
142
+ console.log('⚠️ Obligation demo skipped (module loading)')
143
+ console.log(' Expected: Obligation management without execution')
144
+ }
145
+
146
+ console.log('')
147
+
148
+ /**
149
+ * DEMONSTRATE REGISTRY PRIMITIVES
150
+ */
151
+ console.log('4️⃣ REGISTRY MANAGEMENT - Preparation Primitives')
152
+ console.log('===============================================')
153
+
154
+ console.log('🔧 PRIMITIVES-ONLY APPROACH:')
155
+ console.log(' ✅ Library prepares registry data structures')
156
+ console.log(' ✅ Library formats token registration data')
157
+ console.log(' ✅ Library validates registry queries')
158
+ console.log(' ❌ Library does NOT store registry data')
159
+ console.log(' ❌ Library does NOT manage database connections')
160
+
161
+ // Simulate registry preparation
162
+ console.log('📝 Registry operations prepared:')
163
+ console.log(' • Token registration data formatted')
164
+ console.log(' • Search query structure validated')
165
+ console.log(' • Audit log format prepared')
166
+ console.log(' • Statistics query template ready')
167
+ console.log('')
168
+
169
+ /**
170
+ * DEMONSTRATE BLOCKCHAIN ANCHORING PRIMITIVES
171
+ */
172
+ console.log('5️⃣ BLOCKCHAIN ANCHORING - Commitment Primitives')
173
+ console.log('===============================================')
174
+
175
+ console.log('🔧 PRIMITIVES-ONLY APPROACH:')
176
+ console.log(' ✅ Library prepares commitment hashes')
177
+ console.log(' ✅ Library creates merkle tree structures')
178
+ console.log(' ✅ Library validates anchor proofs')
179
+ console.log(' ❌ Library does NOT publish transactions')
180
+ console.log(' ❌ Library does NOT manage wallet keys')
181
+
182
+ // Simulate anchor preparation
183
+ console.log('⛓️ Blockchain operations prepared:')
184
+ console.log(' • Token commitment hash: ready for transaction')
185
+ console.log(' • Batch merkle root: ready for efficient anchoring')
186
+ console.log(' • Verification proof: ready for anchor validation')
187
+ console.log(' • Revocation format: ready for token cancellation')
188
+ console.log('')
189
+
190
+ /**
191
+ * SUMMARY OF ARCHITECTURAL BENEFITS
192
+ */
193
+ console.log('🎯 PRIMITIVES-ONLY ARCHITECTURE BENEFITS')
194
+ console.log('========================================')
195
+ console.log('')
196
+ console.log('🏗️ SEPARATION OF CONCERNS:')
197
+ console.log(' 📚 SmartLedger-BSV: Foundation library with crypto primitives')
198
+ console.log(' 🔧 External Apps: Handle UI, storage, and blockchain publishing')
199
+ console.log(' ⚖️ Legal Framework: Validated structure and compliance tools')
200
+ console.log('')
201
+ console.log('💪 DEVELOPER BENEFITS:')
202
+ console.log(' • Maximum flexibility in implementation choices')
203
+ console.log(' • No vendor lock-in to specific platforms or blockchains')
204
+ console.log(' • Clean separation between crypto/legal logic and app logic')
205
+ console.log(' • Easy integration with existing systems and workflows')
206
+ console.log('')
207
+ console.log('⚡ LIBRARY ADVANTAGES:')
208
+ console.log(' • Focused on what it does best: cryptography and validation')
209
+ console.log(' • Smaller footprint and fewer dependencies')
210
+ console.log(' • More predictable behavior and easier testing')
211
+ console.log(' • Clear API boundaries and responsibilities')
212
+ console.log('')
213
+ console.log('🔗 INTEGRATION PATTERN:')
214
+ console.log(' 1. Use SmartLedger-BSV to prepare and validate legal tokens')
215
+ console.log(' 2. Use external systems for blockchain publishing')
216
+ console.log(' 3. Use external systems for storage and registries')
217
+ console.log(' 4. Use external systems for user interfaces and workflows')
218
+ console.log('')
219
+ console.log('🚀 RESULT: Complete foundation for any Legal Token Protocol')
220
+ console.log(' application while maintaining architectural flexibility!')
221
+
222
+ /**
223
+ * SHOW EXAMPLE EXTERNAL SYSTEM INTEGRATION
224
+ */
225
+ console.log('')
226
+ console.log('📋 EXAMPLE: How External Systems Would Use These Primitives')
227
+ console.log('=========================================================')
228
+ console.log('')
229
+ console.log('// External Application Code Example:')
230
+ console.log('const bsv = require("smartledger-bsv")')
231
+ console.log('const MyBlockchainAPI = require("my-blockchain-service")')
232
+ console.log('const MyStorage = require("my-database-service")')
233
+ console.log('')
234
+ console.log('// 1. Use SmartLedger-BSV to prepare legal token')
235
+ console.log('const tokenPrep = bsv.prepareRightToken(...)')
236
+ console.log('')
237
+ console.log('// 2. Use external service to publish to blockchain')
238
+ console.log('const txResult = await MyBlockchainAPI.publish(tokenPrep.commitment)')
239
+ console.log('')
240
+ console.log('// 3. Use external service to store token data')
241
+ console.log('const storeResult = await MyStorage.save(tokenPrep.token)')
242
+ console.log('')
243
+ console.log('// 4. Use SmartLedger-BSV to verify results')
244
+ console.log('const verification = bsv.verifyTokenAnchor(token, txResult.txid)')
245
+ console.log('')
246
+ console.log('This pattern gives developers complete control while ensuring')
247
+ console.log('cryptographic and legal correctness through SmartLedger-BSV!')
@@ -0,0 +1,10 @@
1
+ var bsvCovenant=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";if("undefined"==typeof bsv)throw new Error("CovenantInterface requires BSV library. Load bsv.min.js first.");const n=r(1);"undefined"!=typeof window&&(window.bsvCovenant={CovenantInterface:n,version:bsv.version||"unknown"},"undefined"!=typeof bsv&&(bsv.CovenantInterface=n),console.log("CovenantInterface standalone module loaded")),t.exports={CovenantInterface:n,version:bsv.version||"unknown"}},function(t,e,r){(function(e){const n=r(7);class o{constructor(t,e){this.tx=t,this.covenant=e,this.preimages=new Map}getPreimage(t,e,r){const n=`${t}-${e.toHex()}-${r}`;if(!this.preimages.has(n)){const o=this.covenant.getPreimage(this.tx,t,e,r);this.preimages.set(n,o)}return this.preimages.get(n)}signInput(t,e,r,o){const i=this.covenant.createSignature(this.tx,e,t,r,o),a=(new n.Script).add(i).add(e.publicKey.toBuffer());return this.tx.inputs[t].setScript(a),this}getTransaction(){return this.tx}verify(){try{return this.tx.verify()}catch(t){return console.error("Transaction validation error:",t.message),!1}}}class i{constructor(t){this.hex=t,this.buffer=e.from(t,"hex"),this.parseFields()}parseFields(){let t=0;this.nVersion=this.buffer.subarray(t,t+4),this.nVersionValue=this.buffer.readUInt32LE(t),t+=4,this.hashPrevouts=this.buffer.subarray(t,t+32),t+=32,this.hashSequence=this.buffer.subarray(t,t+32),t+=32,this.outpoint=this.buffer.subarray(t,t+36),this.prevTxId=this.buffer.subarray(t,t+32),t+=32,this.outputIndex=this.buffer.subarray(t,t+4),this.outputIndexValue=this.buffer.readUInt32LE(t),t+=4;const e=this.readVarInt(t);t+=this.getVarIntLength(e),this.scriptCode=this.buffer.subarray(t,t+e),t+=e,this.amount=this.buffer.subarray(t,t+8),this.amountValue=this.buffer.readBigUInt64LE(t),t+=8,this.nSequence=this.buffer.subarray(t,t+4),this.nSequenceValue=this.buffer.readUInt32LE(t),t+=4,this.hashOutputs=this.buffer.subarray(t,t+32),t+=32,this.nLockTime=this.buffer.subarray(t,t+4),this.nLockTimeValue=this.buffer.readUInt32LE(t),t+=4,this.sighashType=this.buffer.subarray(t,t+4),this.sighashTypeValue=this.buffer.readUInt32LE(t),t+=4,this.isValid=t===this.buffer.length&&this.buffer.length>=108}readVarInt(t){const e=this.buffer.readUInt8(t);return e<253?e:253===e?this.buffer.readUInt16LE(t+1):254===e?this.buffer.readUInt32LE(t+1):255===e?this.buffer.readBigUInt64LE(t+1):void 0}getVarIntLength(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}}class a{constructor(t,e){this.isValid=t,this.message=e}toString(){return`${this.isValid?"VALID":"INVALID"}: ${this.message}`}}t.exports={CovenantInterface:class{constructor(){this.bsv=n}createCovenantTransaction(t){const e=new n.Transaction;return t.inputs&&t.inputs.forEach(t=>e.from(t)),t.outputs&&t.outputs.forEach(t=>{t.script?e.addOutput(new n.Transaction.Output({script:t.script,satoshis:t.satoshis})):e.to(t.address,t.satoshis)}),t.feePerKb&&e.feePerKb(t.feePerKb),new o(e,this)}createSignature(t,r,o,i,a,f=null){f=f||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const s=n.Transaction.sighash.sign(t,r,f,o,i,new n.crypto.BN(a));return e.concat([s.toDER(),e.from([f])])}getPreimage(t,e,r,o,a=null){a=a||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const f=n.Transaction.sighash.sighash(t,a,e,r,new n.crypto.BN(o));return new i(f)}createStateMachine(t,r,o){const i=new n.Script;i.add(e.from([r])),i.add(n.Opcode.OP_EQUAL),i.add(n.Opcode.OP_VERIFY);for(let o=0;o<t.length-1;o++)o===r&&t[o].nextStates.forEach(t=>{i.add(e.from([t])),i.add(n.Opcode.OP_EQUAL),i.add(n.Opcode.OP_IF),i.add(n.Opcode.OP_ENDIF)});return i.add(n.Opcode.OP_DUP),i.add(n.Opcode.OP_HASH160),i.add(o.toAddress().hashBuffer),i.add(n.Opcode.OP_EQUALVERIFY),i.add(n.Opcode.OP_CHECKSIG),i}createEscrow(t,r,o,i=null){const a=new n.Script;return i&&(a.add(n.Opcode.OP_IF),a.add(e.from(i.toString(16).padStart(8,"0"),"hex").reverse()),a.add(n.Opcode.OP_CHECKLOCKTIMEVERIFY),a.add(n.Opcode.OP_DROP),a.add(t.toBuffer()),a.add(n.Opcode.OP_CHECKSIG),a.add(n.Opcode.OP_ELSE)),a.add(n.Opcode.OP_2),a.add(t.toBuffer()),a.add(r.toBuffer()),a.add(o.toBuffer()),a.add(n.Opcode.OP_3),a.add(n.Opcode.OP_CHECKMULTISIG),i&&a.add(n.Opcode.OP_ENDIF),a}createTokenTransfer(t,r,o=null){const i=new n.Script;return r>0&&(i.add(n.Opcode.OP_DUP),i.add(e.from(r.toString(16),"hex")),i.add(n.Opcode.OP_GREATERTHANOREQUAL),i.add(n.Opcode.OP_VERIFY)),o&&i.add(o.toBuffer()),i.add(n.Opcode.OP_DUP),i.add(n.Opcode.OP_HASH160),i.add(t.toAddress().hashBuffer),i.add(n.Opcode.OP_EQUALVERIFY),i.add(n.Opcode.OP_CHECKSIG),i}validateCovenant(t,e,r,o){try{const i=new n.Script.Interpreter,f=n.Script.Interpreter.SCRIPT_VERIFY_P2SH|n.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|n.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID|n.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES|n.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES,s=i.verify(r,o,t,e,f);return new a(s,i.errstr||"Success")}catch(t){return new a(!1,t.message)}}createAdvancedCovenant(t,e={}){const r={pushtx:this.createPushtxCovenant,perpetual:this.createPerpetualCovenant,pels:this.createPerpetualCovenant,introspection:this.createIntrospectionCovenant},n=r[t];if(!n)throw new Error(`Unknown advanced covenant type: ${t}. Available types: ${Object.keys(r).join(", ")}`);return n.call(this,e)}createPushtxCovenant(t={}){const{publicKey:r="0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",enforceOutputs:o=!0,sighashType:i=65}=t,a=new n.Script;a.add(n.Opcode.OP_2DUP).add(n.Opcode.OP_HASH256).add(n.Opcode.OP_SWAP),a.add(e.from("ffffffff","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),a.add(e.from("00000000","hex")).add(e.from("41000000","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_CAT),a.add(n.Opcode.OP_HASH256);a.add(e.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex")).add(n.Opcode.OP_ADD);return a.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_MOD),this._addDERConversion(a),a.add(e.from([i])).add(n.Opcode.OP_CAT).add(e.from(r,"hex")),a.add(n.Opcode.OP_CHECKSIGVERIFY),o&&this._addOutputValidation(a,t),a}createPerpetualCovenant(t={}){const{publicKeyHash:r,feeDeduction:o=512,enforceScript:i=!0,enforceValue:a=!0}=t;if(!r)throw new Error("publicKeyHash required for perpetual covenant");const f=new n.Script;return f.add(n.Opcode.OP_2DUP).add(n.Opcode.OP_BIN2NUM),o>0&&f.add(e.from(o.toString(16).padStart(4,"0"),"hex")).add(n.Opcode.OP_SUB),f.add(e.from([8])).add(n.Opcode.OP_NUM2BIN).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),f.add(n.Opcode.OP_HASH256),this._addPreimageConstruction(f,t),this._addPushtxSignature(f,t),f.add(n.Opcode.OP_SWAP).add(e.from([104])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP).add(n.Opcode.OP_SWAP).add(e.from([8])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),(a||i)&&f.add(n.Opcode.OP_EQUALVERIFY),f.add(n.Opcode.OP_DUP).add(n.Opcode.OP_HASH160).add(e.from(r,"hex")).add(n.Opcode.OP_EQUALVERIFY).add(n.Opcode.OP_CHECKSIG),f}createIntrospectionCovenant(t={}){const{validateInputs:r=!1,validateOutputs:o=!0,validateSequence:i=!1,validateLocktime:a=!1}=t,f=new n.Script;return this._addPushtxSignature(f,t),r&&f.add(n.Opcode.OP_DUP).add(e.from([4,36])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_DROP),o&&f.add(n.Opcode.OP_DUP).add(e.from([100])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP).add(e.from([32])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_DROP),f}_addDERConversion(t){t.add(n.Opcode.OP_DUP).add(e.from("7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0","hex")).add(n.Opcode.OP_GREATERTHAN).add(n.Opcode.OP_IF);t.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_SUB),t.add(n.Opcode.OP_ENDIF),t.add(n.Opcode.OP_SIZE).add(n.Opcode.OP_DUP).add(e.from([36])).add(n.Opcode.OP_ADD).add(e.from([48])).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),t.add(e.from("022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179802","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT)}_addOutputValidation(t,r){const{enforceValue:o,enforceScript:i,enforceCount:a}=r;o&&t.add(n.Opcode.OP_DUP).add(e.from([8])).add(n.Opcode.OP_SPLIT),i&&t.add(n.Opcode.OP_DUP).add(n.Opcode.OP_SIZE).add(e.from([9])).add(n.Opcode.OP_SUB).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP)}_addPreimageConstruction(t,r){const{version:o=1,locktime:i=0,sighashType:a=65,sequence:f=4294967295}=r;t.add(e.from(f.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT).add(e.from(i.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT).add(e.from(a.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT)}_addPushtxSignature(t,r){const{publicKey:o="0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",sighashType:i=65}=r;t.add(n.Opcode.OP_HASH256);t.add(e.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex")).add(n.Opcode.OP_ADD);t.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_MOD),this._addDERConversion(t),t.add(e.from([i])).add(n.Opcode.OP_CAT).add(e.from(o,"hex")).add(n.Opcode.OP_CHECKSIGVERIFY)}},CovenantTransaction:o,CovenantPreimage:i,CovenantValidation:a}}).call(this,r(2).Buffer)},function(t,e,r){"use strict";(function(t){
2
+ /*!
3
+ * The buffer module from node.js, for the browser.
4
+ *
5
+ * @author Feross Aboukhadijeh <http://feross.org>
6
+ * @license MIT
7
+ */
8
+ var n=r(4),o=r(5),i=r(6);function a(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(t,e){if(a()<e)throw new RangeError("Invalid typed array length");return s.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=s.prototype:(null===t&&(t=new s(e)),t.length=e),t}function s(t,e,r){if(!(s.TYPED_ARRAY_SUPPORT||this instanceof s))return new s(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return h(this,t)}return u(this,t,e,r)}function u(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);s.TYPED_ARRAY_SUPPORT?(t=e).__proto__=s.prototype:t=c(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!s.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|l(e,r),o=(t=f(t,n)).write(e,r);o!==n&&(t=t.slice(0,o));return t}(t,e,r):function(t,e){if(s.isBuffer(e)){var r=0|p(e.length);return 0===(t=f(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?f(t,0):c(t,e);if("Buffer"===e.type&&i(e.data))return c(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function d(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e){if(d(e),t=f(t,e<0?0:0|p(e)),!s.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function c(t,e){var r=e.length<0?0:0|p(e.length);t=f(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function p(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function l(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return V(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return F(t).length;default:if(n)return V(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,e,r);case"utf8":case"utf-8":return m(this,e,r);case"ascii":return I(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function O(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:P(t,e,r,n,o);if("number"==typeof e)return e&=255,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):P(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function P(t,e,r,n,o){var i,a=1,f=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,f/=2,s/=2,r/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(o){var d=-1;for(i=r;i<f;i++)if(u(t,i)===u(e,-1===d?0:i-d)){if(-1===d&&(d=i),i-d+1===s)return d*a}else-1!==d&&(i-=i-d),d=-1}else for(r+s>f&&(r=f-s),i=r;i>=0;i--){for(var h=!0,c=0;c<s;c++)if(u(t,i+c)!==u(e,c)){h=!1;break}if(h)return i}return-1}function _(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var a=0;a<n;++a){var f=parseInt(e.substr(2*a,2),16);if(isNaN(f))return a;t[r+a]=f}return a}function b(t,e,r,n){return k(V(e,t.length-r),t,r,n)}function w(t,e,r,n){return k(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function v(t,e,r,n){return w(t,e,r,n)}function E(t,e,r,n){return k(F(e),t,r,n)}function A(t,e,r,n){return k(function(t,e){for(var r,n,o,i=[],a=0;a<t.length&&!((e-=2)<0);++a)r=t.charCodeAt(a),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function S(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function m(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,a,f,s,u=t[o],d=null,h=u>239?4:u>223?3:u>191?2:1;if(o+h<=r)switch(h){case 1:u<128&&(d=u);break;case 2:128==(192&(i=t[o+1]))&&(s=(31&u)<<6|63&i)>127&&(d=s);break;case 3:i=t[o+1],a=t[o+2],128==(192&i)&&128==(192&a)&&(s=(15&u)<<12|(63&i)<<6|63&a)>2047&&(s<55296||s>57343)&&(d=s);break;case 4:i=t[o+1],a=t[o+2],f=t[o+3],128==(192&i)&&128==(192&a)&&128==(192&f)&&(s=(15&u)<<18|(63&i)<<12|(63&a)<<6|63&f)>65535&&s<1114112&&(d=s)}null===d?(d=65533,h=1):d>65535&&(d-=65536,n.push(d>>>10&1023|55296),d=56320|1023&d),n.push(d),o+=h}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return r}(n)}e.Buffer=s,e.SlowBuffer=function(t){+t!=t&&(t=0);return s.alloc(+t)},e.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=a(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,r){return u(null,t,e,r)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,r){return function(t,e,r,n){return d(e),e<=0?f(t,e):void 0!==r?"string"==typeof n?f(t,e).fill(r,n):f(t,e).fill(r):f(t,e)}(null,t,e,r)},s.allocUnsafe=function(t){return h(null,t)},s.allocUnsafeSlow=function(t){return h(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!i(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=s.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var a=t[r];if(!s.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,o),o+=a.length}return n},s.byteLength=l,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)O(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)O(this,e,e+3),O(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)O(this,e,e+7),O(this,e+1,e+6),O(this,e+2,e+5),O(this,e+3,e+4);return this},s.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?m(this,0,t):g.apply(this,arguments)},s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},s.prototype.compare=function(t,e,r,n,o){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),f=Math.min(i,a),u=this.slice(n,o),d=t.slice(e,r),h=0;h<f;++h)if(u[h]!==d[h]){i=u[h],a=d[h];break}return i<a?-1:a<i?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return y(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return y(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return b(this,t,e,r);case"ascii":return w(this,t,e,r);case"latin1":case"binary":return v(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function T(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function R(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=N(t[i]);return o}function C(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function U(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,o,i){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function L(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o<i;++o)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function x(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o<i;++o)t[r+o]=e>>>8*(n?o:3-o)&255}function D(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Y(t,e,r,n,i){return i||D(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function M(t,e,r,n,i){return i||D(t,0,r,8),o.write(t,e,r,n,52,8),r+8}s.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),s.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=s.prototype;else{var o=e-t;r=new s(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},s.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},s.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},s.prototype.readUInt8=function(t,e){return e||U(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||U(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||U(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=e,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},s.prototype.readInt8=function(t,e){return e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){e||U(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||U(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||U(t,4,this.length),o.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||U(t,4,this.length),o.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||U(t,8,this.length),o.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||U(t,8,this.length),o.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):x(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=0,a=1,f=0;for(this[e]=255&t;++i<r&&(a*=256);)t<0&&0===f&&0!==this[e+i-1]&&(f=1),this[e+i]=(t/a>>0)-f&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=r-1,a=1,f=0;for(this[e+i]=255&t;--i>=0&&(a*=256);)t<0&&0===f&&0!==this[e+i+1]&&(f=1),this[e+i]=(t/a>>0)-f&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):x(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return Y(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return Y(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o,i=n-r;if(this===t&&r<e&&e<n)for(o=i-1;o>=0;--o)t[o+e]=this[o+r];else if(i<1e3||!s.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var a=s.isBuffer(t)?t:V(new s(t,n).toString()),f=a.length;for(i=0;i<r-e;++i)this[i+e]=a[i%f]}return this};var H=/[^+\/0-9A-Za-z-_]/g;function N(t){return t<16?"0"+t.toString(16):t.toString(16)}function V(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],a=0;a<n;++a){if((r=t.charCodeAt(a))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function F(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(H,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function k(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}}).call(this,r(3))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=u(t),a=n[0],f=n[1],s=new i(function(t,e,r){return 3*(e+r)/4-r}(0,a,f)),d=0,h=f>0?a-4:a;for(r=0;r<h;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],s[d++]=e>>16&255,s[d++]=e>>8&255,s[d++]=255&e;2===f&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,s[d++]=255&e);1===f&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,s[d++]=e>>8&255,s[d++]=255&e);return s},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],a=0,f=r-o;a<f;a+=16383)i.push(d(t,a,a+16383>f?f:a+16383));1===o?(e=t[r-1],i.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f=0,s=a.length;f<s;++f)n[f]=a[f],o[a.charCodeAt(f)]=f;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function d(t,e,r){for(var o,i,a=[],f=e;f<r;f+=3)o=(t[f]<<16&16711680)+(t[f+1]<<8&65280)+(255&t[f+2]),a.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return a.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){
9
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
10
+ e.read=function(t,e,r,n,o){var i,a,f=8*o-n-1,s=(1<<f)-1,u=s>>1,d=-7,h=r?o-1:0,c=r?-1:1,p=t[e+h];for(h+=c,i=p&(1<<-d)-1,p>>=-d,d+=f;d>0;i=256*i+t[e+h],h+=c,d-=8);for(a=i&(1<<-d)-1,i>>=-d,d+=n;d>0;a=256*a+t[e+h],h+=c,d-=8);if(0===i)i=1-u;else{if(i===s)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),i-=u}return(p?-1:1)*a*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var a,f,s,u=8*i-o-1,d=(1<<u)-1,h=d>>1,c=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,l=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(f=isNaN(e)?1:0,a=d):(a=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-a))<1&&(a--,s*=2),(e+=a+h>=1?c/s:c*Math.pow(2,1-h))*s>=2&&(a++,s/=2),a+h>=d?(f=0,a=d):a+h>=1?(f=(e*s-1)*Math.pow(2,o),a+=h):(f=e*Math.pow(2,h-1)*Math.pow(2,o),a=0));o>=8;t[r+p]=255&f,p+=l,f/=256,o-=8);for(a=a<<o|f,u+=o;u>0;t[r+p]=255&a,p+=l,a/=256,u-=8);t[r+p-l]|=128*g}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e){t.exports=bsv}]);