@smartledger/bsv 7.8.1 → 7.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +117 -6
  2. package/README.md +38 -38
  3. package/bsv-covenant.min.js +1 -1
  4. package/bsv-ecies.min.js +1 -1
  5. package/bsv-gdaf.min.js +54 -54
  6. package/bsv-ltp.min.js +58 -85
  7. package/bsv-message.min.js +2 -2
  8. package/bsv-mnemonic.min.js +12 -14
  9. package/bsv-script-helper.min.js +1 -1
  10. package/bsv-shamir.min.js +14 -16
  11. package/bsv-smartcontract.min.js +23 -25
  12. package/bsv.bundle.js +54 -54
  13. package/bsv.min.js +54 -54
  14. package/build/esbuild.js +84 -4
  15. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  16. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  17. package/docs/getting-started/INSTALLATION.md +23 -23
  18. package/docs/getting-started/QUICK_START.md +7 -7
  19. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  20. package/index.js +9 -1
  21. package/lib/covenant/helpers.js +146 -0
  22. package/lib/covenant/index.js +21 -0
  23. package/lib/covenant/pushtx.js +243 -0
  24. package/lib/covenant-interface.js +408 -397
  25. package/lib/custom-script-helper.js +44 -38
  26. package/lib/ecies/bitcore-ecies.js +3 -4
  27. package/lib/ecies/electrum-ecies.js +4 -6
  28. package/lib/ecies/errors.js +1 -1
  29. package/lib/gdaf/attestation-signer.js +7 -7
  30. package/lib/gdaf/attestation-verifier.js +5 -6
  31. package/lib/gdaf/did-resolver.js +10 -9
  32. package/lib/gdaf/smartledger-anchor.js +13 -12
  33. package/lib/gdaf/zk-prover.js +8 -8
  34. package/lib/ltp/anchor.js +2 -3
  35. package/lib/ltp/claim.js +2 -3
  36. package/lib/ltp/index.js +2 -3
  37. package/lib/ltp/obligation.js +9 -9
  38. package/lib/ltp/proof.js +7 -7
  39. package/lib/ltp/registry.js +4 -5
  40. package/lib/ltp/right.js +11 -11
  41. package/lib/message/index.js +5 -4
  42. package/lib/message/message.js +11 -11
  43. package/lib/mnemonic/errors.js +1 -1
  44. package/lib/mnemonic/index.js +5 -4
  45. package/lib/mnemonic/mnemonic.js +22 -10
  46. package/lib/ordinals/bsv20.js +4 -4
  47. package/lib/ordinals/inscription.js +8 -12
  48. package/lib/ordinals/ordlock.js +26 -21
  49. package/lib/script/interpreter.js +96 -31
  50. package/lib/smart_contract/authorizers.js +8 -6
  51. package/lib/smart_contract/builder.js +32 -26
  52. package/lib/smart_contract/covenant.js +32 -25
  53. package/lib/smart_contract/covenant_helpers.js +8 -128
  54. package/lib/smart_contract/debugger.js +9 -6
  55. package/lib/smart_contract/dsl.js +5 -6
  56. package/lib/smart_contract/index.js +11 -8
  57. package/lib/smart_contract/locks.js +3 -4
  58. package/lib/smart_contract/opcode_list.js +2 -3
  59. package/lib/smart_contract/pels.js +4 -5
  60. package/lib/smart_contract/preimage.js +11 -7
  61. package/lib/smart_contract/pushtx.js +8 -263
  62. package/lib/smart_contract/script_interpreter.js +112 -105
  63. package/lib/smart_contract/script_tester.js +24 -18
  64. package/lib/smart_contract/script_utils.js +15 -14
  65. package/lib/smart_contract/sighash.js +23 -15
  66. package/lib/smart_contract/stack_examiner.js +70 -63
  67. package/lib/smart_contract/token.js +6 -6
  68. package/lib/smart_contract/utxo_generator.js +21 -15
  69. package/lib/smartutxo.js +27 -21
  70. package/lib/spv/headerchain.js +3 -3
  71. package/lib/spv/merkleproof.js +3 -3
  72. package/package.json +4 -2
  73. package/test/script/chronicle.js +53 -10
  74. package/test/script/interpreter.js +9 -6
  75. package/test/script/string_ops.js +26 -10
  76. package/version.js +1 -1
package/build/esbuild.js CHANGED
@@ -44,18 +44,95 @@ function polyfillPlugin (mode) {
44
44
  }
45
45
  }
46
46
 
47
- // Externalise the bsv root (require('../..') / require('../index.js') / etc.) to the global
48
- // `bsv` — the webpack `externals: { … : 'bsv' }` behaviour for feature bundles.
47
+ // Map a lib/ module to the expression that retrieves it from the global `bsv`.
48
+ // Feature bundles resolve shared primitives through this table instead of
49
+ // bundling their own copy.
50
+ //
51
+ // This exists because modules under lib/ used to reach the shared primitives by
52
+ // requiring the package ROOT, and this plugin externalised that single require.
53
+ // Those root requires were removed (they made module load order load-bearing and
54
+ // blocked any move to ESM), so each module now imports what it needs directly —
55
+ // which means the externalisation has to happen per module rather than once.
56
+ //
57
+ // Getting this wrong is not merely a size regression. If a feature bundle embeds
58
+ // its own PrivateKey class, a key constructed by bsv.min.js fails `instanceof`
59
+ // inside that bundle, and index.js's versionGuard reports two library instances.
60
+ const GLOBAL_BSV = '(typeof globalThis!=="undefined"?globalThis:(typeof self!=="undefined"?self:window)).bsv'
61
+ const LIB_GLOBALS = {
62
+ 'address': 'Address',
63
+ 'opcode': 'Opcode',
64
+ 'networks': 'Networks',
65
+ 'privatekey': 'PrivateKey',
66
+ 'publickey': 'PublicKey',
67
+ 'hdprivatekey': 'HDPrivateKey',
68
+ 'hdpublickey': 'HDPublicKey',
69
+ 'script': 'Script',
70
+ 'script/index': 'Script',
71
+ 'script/interpreter': 'Script.Interpreter',
72
+ 'transaction': 'Transaction',
73
+ 'transaction/index': 'Transaction',
74
+ 'transaction/input': 'Transaction.Input',
75
+ 'transaction/output': 'Transaction.Output',
76
+ 'transaction/sighash': 'Transaction.sighash',
77
+ 'transaction/unspentoutput': 'Transaction.UnspentOutput',
78
+ 'crypto/bn': 'crypto.BN',
79
+ 'crypto/ecdsa': 'crypto.ECDSA',
80
+ 'crypto/hash': 'crypto.Hash',
81
+ 'crypto/point': 'crypto.Point',
82
+ 'crypto/random': 'crypto.Random',
83
+ 'crypto/signature': 'crypto.Signature',
84
+ 'encoding/base58': 'encoding.Base58',
85
+ 'encoding/base58check': 'encoding.Base58Check',
86
+ 'encoding/bufferreader': 'encoding.BufferReader',
87
+ 'encoding/bufferwriter': 'encoding.BufferWriter',
88
+ 'encoding/varint': 'encoding.Varint',
89
+ 'errors': 'errors',
90
+ 'errors/index': 'errors',
91
+ 'util/js': 'util.js',
92
+ 'util/preconditions': 'util.preconditions',
93
+ 'block': 'Block',
94
+ 'block/index': 'Block',
95
+ 'block/blockheader': 'BlockHeader',
96
+ 'block/merkleblock': 'MerkleBlock'
97
+ // Deliberately NOT mapped: lib/util/_.js. Its only global alias is the legacy
98
+ // `bsv.deps._`, which is slated for removal in the next major; the bundles
99
+ // should not be the thing keeping it alive. It is ~1.7 KB, has no dependencies
100
+ // and no identity semantics (pure isString/isNumber-style predicates), so a
101
+ // duplicate copy in the message/mnemonic bundles is harmless — unlike a
102
+ // duplicate PrivateKey, which would break instanceof across bundles.
103
+ }
104
+
105
+ const LIB_DIR = path.join(ROOT, 'lib')
106
+
107
+ // Turn an absolute resolved path into its lib-relative key ('crypto/hash').
108
+ function libKey (resolved) {
109
+ if (resolved.indexOf(LIB_DIR + path.sep) !== 0) return null
110
+ return resolved.slice(LIB_DIR.length + 1).replace(/\\/g, '/').replace(/\.js$/, '')
111
+ }
112
+
113
+ // Externalise the bsv root (require('../..') / require('../index.js') / etc.) and the
114
+ // individual lib/ primitives to the global `bsv` — the webpack
115
+ // `externals: { … : 'bsv' }` behaviour for feature bundles.
49
116
  function externalBsvPlugin () {
50
117
  return {
51
118
  name: 'external-bsv',
52
119
  setup (build) {
53
120
  build.onResolve({ filter: /^\.\.?[\\/]/ }, (a) => {
54
121
  const resolved = path.resolve(a.resolveDir, a.path)
55
- if (resolved === BSV_INDEX || resolved === ROOT) return { path: a.path, namespace: 'bsv-global' }
122
+ if (resolved === BSV_INDEX || resolved === ROOT) {
123
+ return { path: a.path, namespace: 'bsv-global' }
124
+ }
125
+ const key = libKey(resolved)
126
+ if (key && LIB_GLOBALS[key]) {
127
+ return { path: LIB_GLOBALS[key], namespace: 'bsv-global-member' }
128
+ }
56
129
  })
57
130
  build.onLoad({ filter: /.*/, namespace: 'bsv-global' }, () => ({
58
- contents: 'module.exports=(typeof globalThis!=="undefined"?globalThis:(typeof self!=="undefined"?self:window)).bsv',
131
+ contents: 'module.exports=' + GLOBAL_BSV,
132
+ loader: 'js'
133
+ }))
134
+ build.onLoad({ filter: /.*/, namespace: 'bsv-global-member' }, (a) => ({
135
+ contents: 'module.exports=' + GLOBAL_BSV + '.' + a.path,
59
136
  loader: 'js'
60
137
  }))
61
138
  }
@@ -105,6 +182,9 @@ function buildOne (cfg, opts) {
105
182
  inject: [path.join(__dirname, 'esbuild/globals.js')],
106
183
  define: { global: 'globalThis' },
107
184
  footer: { js: umdFooter(cfg.global) },
185
+ // Opt-in build graph, used to assert that feature bundles externalise the
186
+ // shared primitives instead of embedding a second copy of them.
187
+ metafile: opts.metafile === true,
108
188
  write: opts.write !== false,
109
189
  outfile: opts.write === false ? undefined : path.join(ROOT, cfg.file),
110
190
  logLevel: opts.logLevel || 'warning'
@@ -55,19 +55,19 @@ Three advanced modules totaling **~2.7MB** of functionality:
55
55
  - **Purpose**: Threshold cryptography for secure secret distribution
56
56
  - **Use Cases**: Backup keys, multi-party security, key recovery
57
57
  - **Features**: Split secrets into N shares, require M to reconstruct
58
- - **CDN**: `unpkg.com/@smartledger/bsv@7.8.1/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.10.0/bsv-shamir.min.js`
59
59
 
60
60
  #### **🌐 Global Digital Attestation Framework - GDAF (1184KB)**
61
61
  - **Purpose**: W3C Verifiable Credentials and decentralized identity
62
62
  - **Use Cases**: Identity verification, attestations, zero-knowledge proofs
63
63
  - **Features**: DID creation, credential issuance, selective disclosure
64
- - **CDN**: `unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js`
65
65
 
66
66
  #### **⚖️ Legal Token Protocol - LTP (1184KB)**
67
67
  - **Purpose**: Legal compliance framework for tokenized assets
68
68
  - **Use Cases**: Property rights, obligations, compliant tokenization
69
69
  - **Features**: Legal primitives, compliance checking, attestation anchoring
70
- - **CDN**: `unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js`
71
71
 
72
72
  ### **2. Incorrect File Sizes in Documentation**
73
73
 
@@ -81,18 +81,18 @@ Three advanced modules totaling **~2.7MB** of functionality:
81
81
 
82
82
  | Module | Size | Use Case | CDN Link |
83
83
  |--------|------|----------|----------|
84
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.8.1/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.8.1/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.8.1/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.8.1/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.8.1/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.8.1/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.10.0/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.10.0/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.10.0/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.10.0/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.10.0/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.10.0/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js` |
96
96
 
97
97
  ## 🎯 **Updated Usage Examples**
98
98
 
@@ -100,22 +100,22 @@ Three advanced modules totaling **~2.7MB** of functionality:
100
100
 
101
101
  #### **1. Basic Development (~963KB)**
102
102
  ```html
103
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-script-helper.min.js"></script>
105
105
  ```
106
106
 
107
107
  #### **2. Smart Contract Development (~2.7MB — each bundle re-embeds core BSV)**
108
108
  ```html
109
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js"></script>
112
112
  ```
113
113
 
114
114
  #### **3. 🆕 Legal & Compliance Development (~3.2MB — each bundle re-embeds core BSV)**
115
115
  ```html
116
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js"></script>
119
119
  <script>
120
120
  // Legal Token Protocol
121
121
  const legalToken = bsv.createLegalToken({
@@ -132,9 +132,9 @@ Three advanced modules totaling **~2.7MB** of functionality:
132
132
 
133
133
  #### **4. 🆕 Security & Cryptography (~1.4MB)**
134
134
  ```html
135
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-shamir.min.js"></script>
138
138
  <script>
139
139
  // Shamir Secret Sharing
140
140
  const shares = bsv.splitSecret('my_secret_key', 5, 3); // 5 shares, 3 needed
@@ -146,7 +146,7 @@ Three advanced modules totaling **~2.7MB** of functionality:
146
146
 
147
147
  #### **5. Everything Bundle (937KB)**
148
148
  ```html
149
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js"></script>
150
150
  <script>
151
151
  // Everything available immediately
152
152
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -722,7 +722,7 @@ interface UTXO {
722
722
  <html>
723
723
  <head>
724
724
  <title>UTXO Manager Demo</title>
725
- <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.8.1/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.10.0/bsv.min.js"></script>
726
726
  </head>
727
727
  <body>
728
728
  <script>
@@ -48,7 +48,7 @@ const tx: Transaction = new Transaction();
48
48
  #### **Core Library Only (937KB)**
49
49
  For basic Bitcoin SV operations:
50
50
  ```html
51
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
52
52
  <script>
53
53
  const privateKey = new bsv.PrivateKey();
54
54
  const address = privateKey.toAddress();
@@ -58,7 +58,7 @@ For basic Bitcoin SV operations:
58
58
  #### **Complete Bundle (937KB)**
59
59
  Everything in one file:
60
60
  ```html
61
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js"></script>
62
62
  <script>
63
63
  // All features available immediately
64
64
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -71,9 +71,9 @@ Everything in one file:
71
71
 
72
72
  #### **Smart Contract Development (~2.7MB total — each bundle is self-contained and re-embeds core BSV)**
73
73
  ```html
74
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js"></script>
77
77
  <script>
78
78
  const covenant = bsv.SmartContract.createCovenantBuilder()
79
79
  .extractField('amount').push(50000).greaterThanOrEqual().build();
@@ -82,9 +82,9 @@ Everything in one file:
82
82
 
83
83
  #### **Legal & Identity Development (~3.2MB total — each bundle is self-contained and re-embeds core BSV)**
84
84
  ```html
85
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js"></script>
88
88
  <script>
89
89
  // Legal Token Protocol
90
90
  const propertyToken = bsv.createPropertyToken({
@@ -98,9 +98,9 @@ Everything in one file:
98
98
 
99
99
  #### **Security & Cryptography (~1.4MB total — each bundle is self-contained and re-embeds core BSV)**
100
100
  ```html
101
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-shamir.min.js"></script>
104
104
  <script>
105
105
  // Threshold Cryptography
106
106
  const shares = bsv.splitSecret('my_secret_key', 5, 3);
@@ -114,18 +114,18 @@ Everything in one file:
114
114
 
115
115
  | Module | Size | Purpose | CDN Link |
116
116
  |--------|------|---------|----------|
117
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.8.1/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.8.1/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.8.1/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.8.1/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.8.1/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.8.1/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.10.0/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.10.0/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.10.0/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.10.0/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.10.0/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.10.0/bsv-message.min.js` |
129
129
 
130
130
  ## ⚙️ **Development Environment Setup**
131
131
 
@@ -14,10 +14,10 @@ npm install @smartledger/bsv
14
14
  ### Browser CDN (Instant)
15
15
  ```html
16
16
  <!-- Core library (937KB) -->
17
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js"></script>
21
21
  ```
22
22
 
23
23
  ## 💰 **Your First Transaction (60 seconds)**
@@ -127,19 +127,19 @@ SmartLedger-BSV offers 12 different loading options - use only what you need:
127
127
 
128
128
  ```html
129
129
  <!-- Core BSV only (937KB) -->
130
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js"></script>
143
143
  ```
144
144
 
145
145
  ## ⚡ **Key Advantages**
@@ -159,17 +159,17 @@ const recovered = bsv.reconstructSecret([shares[0], shares[2], shares[4]]);
159
159
  ### **New Modular Options**
160
160
  ```html
161
161
  <!-- Core compatibility (same size as bsv@1.5.6) -->
162
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
package/index.js CHANGED
@@ -2,7 +2,15 @@
2
2
 
3
3
  var bsv = module.exports
4
4
 
5
- // Initialize dependencies first to avoid circular dependency issues.
5
+ // `bsv.deps` is a legacy compatibility surface, retained as public API.
6
+ //
7
+ // It previously had to be initialized FIRST because modules under lib/ read
8
+ // `bsv.deps._` and friends back off the package root while index.js was still
9
+ // executing — 45 files required the root, so load order was load-bearing.
10
+ // Those cycles were removed: every module under lib/ now requires its
11
+ // dependencies directly, and nothing in lib/ reads bsv.deps any more.
12
+ // The property stays because external consumers may use it; removing it is a
13
+ // breaking change deferred to the next major.
6
14
  //
7
15
  // `bn.js`, `bs58`, and `elliptic` are declared runtime deps in
8
16
  // package.json. In Node they MUST be installed — silently swallowing
@@ -0,0 +1,146 @@
1
+ 'use strict'
2
+ /**
3
+ * SmartContract covenant helpers
4
+ * ==============================
5
+ *
6
+ * Shared utilities for building and verifying custom locking scripts &
7
+ * OP_PUSH_TX covenants: a consensus-flag verify() harness, raw BIP-143 preimage
8
+ * access, signing, and fund/spend scaffolding. Used by ./pushtx, ./pels, ./token
9
+ * and ./locks.
10
+ */
11
+
12
+ var Script = require('../script')
13
+ var Interpreter = require('../script/interpreter')
14
+ var Opcode = require('../opcode')
15
+ var Transaction = require('../transaction')
16
+ var Input = require('../transaction/input')
17
+ var Output = require('../transaction/output')
18
+ var sighash = require('../transaction/sighash')
19
+ var BN = require('../crypto/bn')
20
+ var Hash = require('../crypto/hash')
21
+ var Signature = require('../crypto/signature')
22
+
23
+ // SIGHASH_ALL | SIGHASH_FORKID — the BSV default these covenants are built for.
24
+ var SIGHASH = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID // 0x41
25
+
26
+ // Post-Genesis consensus + STANDARD RELAY flags — what mainnet miners actually
27
+ // enforce. Includes SCRIPT_VERIFY_MINIMALDATA (every push must be minimal) and
28
+ // SCRIPT_VERIFY_LOW_S (canonical signatures). Verifying with these flags locally
29
+ // mirrors mainnet relay/consensus policy, so a covenant that passes here is
30
+ // expected to be accepted on broadcast — catch non-relayable scripts before then.
31
+ function flags () {
32
+ var I = Interpreter
33
+ return I.SCRIPT_VERIFY_P2SH |
34
+ I.SCRIPT_VERIFY_STRICTENC |
35
+ I.SCRIPT_VERIFY_DERSIG |
36
+ I.SCRIPT_VERIFY_LOW_S |
37
+ I.SCRIPT_VERIFY_MINIMALDATA |
38
+ I.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
39
+ I.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY |
40
+ I.SCRIPT_ENABLE_SIGHASH_FORKID |
41
+ I.SCRIPT_ENABLE_MAGNETIC_OPCODES |
42
+ I.SCRIPT_ENABLE_MONOLITH_OPCODES |
43
+ // REQUIRED, not optional. pushTxCore emits OP_RIGHT/OP_LEFT — see
44
+ // extractHashOutputs and assertSighashType — and those bytes (180/181) are
45
+ // upgradable NOPs on the network until Chronicle activates. Without this
46
+ // flag the interpreter treats them as no-ops, exactly as a pre-Chronicle
47
+ // node does, and the covenant does not verify.
48
+ //
49
+ // Stated plainly: OP_PUSH_TX covenants built by this library DEPEND on
50
+ // Chronicle and cannot be spent on a pre-Chronicle chain. That was
51
+ // previously invisible because the interpreter ran the string opcodes
52
+ // unconditionally — more permissively than the network.
53
+ I.SCRIPT_ENABLE_CHRONICLE
54
+ }
55
+
56
+ /**
57
+ * Opt into post-Genesis script limits (needed by OP_PUSH_TX covenants).
58
+ * Thin wrapper over Interpreter.useGenesisLimits (added in 4.1.0).
59
+ */
60
+ function enableGenesis (max) {
61
+ return Interpreter.useGenesisLimits(max)
62
+ }
63
+
64
+ /**
65
+ * Verify an unlocking script against a locking script through the consensus
66
+ * interpreter. @returns {{ok:boolean, err:string}}
67
+ */
68
+ function verify (unlockingScript, lockingScript, opts) {
69
+ opts = opts || {}
70
+ var interp = new Interpreter()
71
+ var ok = interp.verify(
72
+ unlockingScript,
73
+ lockingScript,
74
+ opts.tx || new Transaction(),
75
+ opts.inputIndex || 0,
76
+ opts.flags || flags(),
77
+ new BN(opts.satoshis || 0)
78
+ )
79
+ return { ok: ok, err: interp.errstr || '' }
80
+ }
81
+
82
+ /** Raw BIP-143 preimage (the serialization that is double-SHA256'd), not the digest. */
83
+ function rawPreimage (tx, inputIndex, lockingScript, satoshis, sighashType) {
84
+ return sighash.sighashPreimage(
85
+ tx, sighashType || SIGHASH, inputIndex, lockingScript, new BN(satoshis))
86
+ }
87
+
88
+ /** Sighash digest = HASH256(rawPreimage) — useful for asserting OP_PUSH_TX linkage in JS. */
89
+ function sighashDigest (tx, inputIndex, lockingScript, satoshis, sighashType) {
90
+ return Hash.sha256sha256(rawPreimage(tx, inputIndex, lockingScript, satoshis, sighashType))
91
+ }
92
+
93
+ /** DER+sighash-byte signature over `lockingScript` for `inputIndex`. */
94
+ function signInput (tx, privateKey, inputIndex, lockingScript, satoshis, sighashType) {
95
+ sighashType = sighashType || SIGHASH
96
+ var sig = sighash.sign(tx, privateKey, sighashType, inputIndex, lockingScript, new BN(satoshis))
97
+ return Buffer.concat([sig.toDER(), Buffer.from([sighashType])])
98
+ }
99
+
100
+ /**
101
+ * Build a funding tx paying `satoshis` into `lockingScript`, plus a spending tx
102
+ * consuming it with the supplied outputs. Returns { funding, spend }; the caller
103
+ * sets spend.inputs[0] script.
104
+ */
105
+ function fundAndSpend (lockingScript, satoshis, opts) {
106
+ opts = opts || {}
107
+ var funding = new Transaction().addOutput(
108
+ new Output({ script: lockingScript, satoshis: satoshis }))
109
+ var spend = new Transaction()
110
+ spend.addInput(
111
+ new Input({ prevTxId: funding.hash, outputIndex: 0, script: Script.empty() }),
112
+ lockingScript, satoshis)
113
+ if (opts.outputs) opts.outputs.forEach(function (o) { spend.addOutput(o) })
114
+ return { funding: funding, spend: spend }
115
+ }
116
+
117
+ /** A P2PKH Output object for an address or public key. */
118
+ function p2pkhOutput (addressOrPubKey, satoshis) {
119
+ var addr = addressOrPubKey.toAddress ? addressOrPubKey.toAddress() : addressOrPubKey
120
+ return new Output({ script: Script.buildPublicKeyHashOut(addr), satoshis: satoshis })
121
+ }
122
+
123
+ /** Minimal little-endian script-number Buffer (push as data to put a number on-stack). */
124
+ function scriptNum (n) {
125
+ // Minimal on-stack number: 0..16 and -1 use the dedicated opcodes (OP_0..OP_16,
126
+ // OP_1NEGATE) instead of a data push, so covenant scripts stay MINIMALDATA-clean
127
+ // (mainnet relay policy). Larger values use a minimal scriptNum push. The result
128
+ // is passed to Script.add(), which accepts an opcode number or a Buffer.
129
+ if (n === 0) return Opcode.OP_0
130
+ if (n === -1) return Opcode.OP_1NEGATE
131
+ if (n >= 1 && n <= 16) return Opcode['OP_' + n]
132
+ return new BN(n).toScriptNumBuffer()
133
+ }
134
+
135
+ module.exports = {
136
+ SIGHASH: SIGHASH,
137
+ flags: flags,
138
+ enableGenesis: enableGenesis,
139
+ verify: verify,
140
+ rawPreimage: rawPreimage,
141
+ sighashDigest: sighashDigest,
142
+ signInput: signInput,
143
+ fundAndSpend: fundAndSpend,
144
+ p2pkhOutput: p2pkhOutput,
145
+ scriptNum: scriptNum
146
+ }
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+ /**
3
+ * Covenant primitives — OP_PUSH_TX and the BIP-143 preimage helpers it needs.
4
+ *
5
+ * These live in core rather than under lib/smart_contract because they have two
6
+ * independent consumers: the smart-contract tooling, and lib/ordinals (OrdLock
7
+ * covenants). lib/ordinals previously reached sideways into lib/smart_contract
8
+ * for them, which was the only dependency from core code into the application
9
+ * layer and the one thing blocking a clean split of the two.
10
+ *
11
+ * Nothing here depends on anything above Script / Transaction / crypto.
12
+ *
13
+ * The old paths (lib/smart_contract/pushtx.js and
14
+ * lib/smart_contract/covenant_helpers.js) remain as re-export shims, since deep
15
+ * imports are public API via the package.json exports map.
16
+ */
17
+
18
+ module.exports = {
19
+ PushTx: require('./pushtx'),
20
+ Helpers: require('./helpers')
21
+ }