@smartledger/bsv 6.0.0 → 6.0.2

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.
@@ -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@6.0.0/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.0.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@6.0.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.0.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.0.0/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.0.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.0.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.0.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.0.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@6.0.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@6.0.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@6.0.0/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.0.2/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@6.0.2/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.0.2/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.0.2/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.0.2/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.0.2/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.0.2/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.0.2/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@6.0.2/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@6.0.2/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.0.0/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@6.0.0/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@6.0.0/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@6.0.0/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@6.0.0/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.0.0/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.0.0/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.0.0/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.0.0/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.0.0/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.0.0/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.0.2/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@6.0.2/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@6.0.2/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@6.0.2/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@6.0.2/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.0.2/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.0.2/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.0.2/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.0.2/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.0.2/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/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@6.0.0/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@6.0.0/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@6.0.2/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -24,13 +24,15 @@ var MAX_DEC = 18
24
24
  /** A non-negative integer string (no sign, no decimal point). */
25
25
  function isIntString (v) { return typeof v === 'string' && /^\d+$/.test(v) }
26
26
 
27
- /** Normalize an amount-like field to a non-negative integer string. */
27
+ /** Normalize an amount-like field to a CANONICAL non-negative integer string (no leading zeros). */
28
28
  function normInt (v, name) {
29
29
  if (typeof v === 'number') {
30
30
  if (!Number.isInteger(v) || v < 0) throw new Error(name + ' must be a non-negative integer')
31
31
  return String(v)
32
32
  }
33
- if (isIntString(v)) return v
33
+ // Strip leading zeros ("007" -> "7", "000" -> "0") so the emitted payload is canonical
34
+ // and not rejected by indexers that expect canonical decimal integers.
35
+ if (isIntString(v)) return v.replace(/^0+(?=\d)/, '')
34
36
  throw new Error(name + ' must be a non-negative integer (string or number)')
35
37
  }
36
38
 
@@ -45,7 +45,6 @@ var inscription = require('./inscription')
45
45
  var Script = bsv.Script
46
46
  var Opcode = bsv.Opcode
47
47
  var BufferReader = bsv.encoding.BufferReader
48
- var BN = bsv.crypto.BN
49
48
 
50
49
  // OrdLock commits to the FULL output set (so payments can be pinned) but leaves the
51
50
  // input set open for the buyer's funding — SIGHASH_ALL|ANYONECANPAY|FORKID (0xc1).
@@ -57,6 +56,14 @@ function pushData (s, buf) { return (buf && buf.length) ? s.add(Buffer.from(buf)
57
56
  /** Serialize a Transaction.Output to its on-wire bytes (8-byte value || varint || script). */
58
57
  function serializeOutput (out) { return out.toBufferWriter().toBuffer() }
59
58
 
59
+ /** Assert a value is a non-negative integer satoshi amount; return it. */
60
+ function assertSats (v, label) {
61
+ if (typeof v !== 'number' || !isFinite(v) || v < 0 || Math.floor(v) !== v) {
62
+ throw new Error(label + ' must be a non-negative integer number of satoshis (got ' + v + ')')
63
+ }
64
+ return v
65
+ }
66
+
60
67
  /** Coerce a Script, Buffer, or hex string to a Script. */
61
68
  function coerceScript (v) {
62
69
  if (v instanceof Script) return v
@@ -81,9 +88,13 @@ function resolvePubKeyHash (owner) {
81
88
  return toAddress(owner).hashBuffer
82
89
  }
83
90
 
84
- /** Build the seller's payment Output (P2PKH) from an address/pubkey/key and a price in sats. */
91
+ /**
92
+ * Build the seller's payment Output (P2PKH) from an address/pubkey/key and a price in sats.
93
+ * A pre-built Transaction.Output is NOT accepted here — use it directly (or pass it as a
94
+ * `payOutputs`/`payTo` spec) — so that `price` is never silently ignored.
95
+ */
85
96
  function payOutputFor (payTo, price) {
86
- if (payTo instanceof bsv.Transaction.Output) return payTo
97
+ assertSats(price, 'payment price')
87
98
  return new bsv.Transaction.Output({
88
99
  script: Script.buildPublicKeyHashOut(toAddress(payTo)), satoshis: price
89
100
  })
@@ -112,7 +123,10 @@ function resolvePayOutputs (params) {
112
123
  }
113
124
  if (params.payOutput != null) return [outputFromSpec(params.payOutput)]
114
125
  if (params.price != null) {
115
- var arr = [payOutputFor(params.payTo != null ? params.payTo : params.seller, params.price)]
126
+ var payTo = params.payTo != null ? params.payTo : params.seller
127
+ // A pre-built Output as payTo is used verbatim (its own value); otherwise build P2PKH(price).
128
+ var first = (payTo instanceof bsv.Transaction.Output) ? payTo : payOutputFor(payTo, params.price)
129
+ var arr = [first]
116
130
  if (params.royalties) params.royalties.forEach(function (r) { arr.push(outputFromSpec(r)) })
117
131
  return arr
118
132
  }
@@ -193,6 +207,9 @@ function splitPayBlob (blob) {
193
207
  * is not a recognizable OrdLock (so it doubles as a detector).
194
208
  *
195
209
  * @param {Script|Buffer|string} script
210
+ * @param {object} [opts] { network } network for the returned address strings
211
+ * ('livenet' | 'testnet' | a bsv.Networks.Network); defaults to livenet. The
212
+ * pubKeyHash / output scripts are network-agnostic and always exact.
196
213
  * @returns {null|{
197
214
  * seller: { pubKeyHash: Buffer, address: string },
198
215
  * payOutputs: Array<{ satoshis: number, script: Script, address: string|null }>,
@@ -201,7 +218,8 @@ function splitPayBlob (blob) {
201
218
  * inscription: null|{ contentType: string, content: Buffer, contentText: string }
202
219
  * }}
203
220
  */
204
- function parseOrdLock (script) {
221
+ function parseOrdLock (script, opts) {
222
+ var network = opts && opts.network
205
223
  try {
206
224
  var s = coerceScript(script)
207
225
  var chunks = s.chunks
@@ -239,7 +257,7 @@ function parseOrdLock (script) {
239
257
 
240
258
  var payOutputs = splitPayBlob(payBlob).map(function (o) {
241
259
  var addr = null
242
- try { if (o.script.isPublicKeyHashOut()) addr = o.script.toAddress().toString() } catch (e) {}
260
+ try { if (o.script.isPublicKeyHashOut()) addr = o.script.toAddress(network).toString() } catch (e) {}
243
261
  return { satoshis: o.satoshis, script: o.script, address: addr }
244
262
  })
245
263
  var totalPrice = payOutputs.reduce(function (a, o) { return a + o.satoshis }, 0)
@@ -251,7 +269,7 @@ function parseOrdLock (script) {
251
269
  }
252
270
 
253
271
  return {
254
- seller: { pubKeyHash: sellerPKH, address: bsv.Address.fromPublicKeyHash(sellerPKH).toString() },
272
+ seller: { pubKeyHash: sellerPKH, address: bsv.Address.fromPublicKeyHash(sellerPKH, network).toString() },
255
273
  payOutputs: payOutputs,
256
274
  payBlob: payBlob,
257
275
  totalPrice: totalPrice,
@@ -263,7 +281,7 @@ function parseOrdLock (script) {
263
281
  }
264
282
 
265
283
  /** True if `script` is a recognizable OrdLock listing. */
266
- function isOrdLock (script) { return parseOrdLock(script) !== null }
284
+ function isOrdLock (script, opts) { return parseOrdLock(script, opts) !== null }
267
285
 
268
286
  /**
269
287
  * Build the 1-sat Transaction.Output that lists an ordinal for sale under an OrdLock.
@@ -312,7 +330,8 @@ function purchase (params) {
312
330
  var satoshis = params.satoshis != null ? params.satoshis : 1
313
331
  var outs = spend.outputs || []
314
332
 
315
- var parsed = parseOrdLock(lockingScript)
333
+ // Reuse a caller-supplied parse of the SAME lockingScript when given (avoids re-parsing).
334
+ var parsed = params.parsed || parseOrdLock(lockingScript)
316
335
  var payoutCount = params.payoutCount != null ? params.payoutCount
317
336
  : (parsed ? parsed.payOutputs.length : 1)
318
337
  if (payoutIndex + payoutCount > outs.length) {
@@ -389,6 +408,9 @@ function addSpendInput (tx, outpoint, script, satoshis) {
389
408
 
390
409
  /** Sign input `idx` as P2PKH with `coin.privateKey` over the finalized tx (ALL|FORKID). */
391
410
  function signP2PKHInput (tx, idx, coin) {
411
+ // The satoshi amount is part of the BIP-143 preimage — a missing/NaN value silently
412
+ // produces a signature over the wrong amount that fails on-chain, so require it explicitly.
413
+ assertSats(coin.satoshis, 'input ' + idx + ' satoshis')
392
414
  var sc = coerceScript(coin.script)
393
415
  var sig = H.signInput(tx, coin.privateKey, idx, sc, coin.satoshis, P.SIGHASH_ALL_FORKID)
394
416
  var us = new Script()
@@ -419,12 +441,12 @@ function buildListingTx (params) {
419
441
  if (!ordinal || !ordinal.script || !ordinal.privateKey) {
420
442
  throw new Error('buildListingTx requires ordinal { script, privateKey, txid, outputIndex }')
421
443
  }
422
- var ordSats = ordinal.satoshis != null ? ordinal.satoshis : 1
444
+ var ordSats = assertSats(ordinal.satoshis != null ? ordinal.satoshis : 1, 'ordinal satoshis')
423
445
  var lock = buildOrdLock(params)
424
446
 
425
447
  var funding = params.funding || []
426
448
  var fee = params.fee != null ? params.fee : 500
427
- var fundingTotal = funding.reduce(function (a, f) { return a + f.satoshis }, 0)
449
+ var fundingTotal = funding.reduce(function (a, f) { return a + assertSats(f.satoshis, 'funding satoshis') }, 0)
428
450
  var change = fundingTotal - fee
429
451
  if (change < 0) {
430
452
  throw new Error('buildListingTx: insufficient funding — need ' + fee + ' sat fee, funded ' + fundingTotal)
@@ -439,7 +461,9 @@ function buildListingTx (params) {
439
461
  tx.addOutput(payOutputFor(params.changeAddress || ordinal.privateKey.toAddress(), change))
440
462
  }
441
463
 
442
- signP2PKHInput(tx, 0, ordinal)
464
+ // Sign the ordinal input with the RESOLVED value (ordSats), not the raw (maybe-omitted)
465
+ // ordinal.satoshis — else the signature commits to the wrong amount and fails on-chain.
466
+ signP2PKHInput(tx, 0, { script: ordinal.script, privateKey: ordinal.privateKey, satoshis: ordSats })
443
467
  funding.forEach(function (f, i) { signP2PKHInput(tx, 1 + i, f) })
444
468
 
445
469
  return { tx: tx, listingScript: lock, listingOutpoint: { txid: tx.hash, outputIndex: 0 } }
@@ -477,7 +501,7 @@ function buildPurchaseTx (params) {
477
501
  var lockingScript = coerceScript(listing.script)
478
502
  var parsed = parseOrdLock(lockingScript)
479
503
  if (!parsed) throw new Error('buildPurchaseTx: listing.script is not a parseable OrdLock')
480
- var ordSats = listing.satoshis != null ? listing.satoshis : 1
504
+ var ordSats = assertSats(listing.satoshis != null ? listing.satoshis : 1, 'listing satoshis')
481
505
 
482
506
  var payOuts = params.payOutputs
483
507
  ? params.payOutputs.map(outputFromSpec)
@@ -487,7 +511,7 @@ function buildPurchaseTx (params) {
487
511
  var paidTotal = payOuts.reduce(function (a, o) { return a + o.satoshis }, 0)
488
512
 
489
513
  var fee = params.fee != null ? params.fee : 500
490
- var fundingTotal = params.funding.reduce(function (a, f) { return a + f.satoshis }, 0)
514
+ var fundingTotal = params.funding.reduce(function (a, f) { return a + assertSats(f.satoshis, 'funding satoshis') }, 0)
491
515
  var change = fundingTotal - paidTotal - fee
492
516
  if (change < 0) {
493
517
  throw new Error('buildPurchaseTx: insufficient funding — need ' + (paidTotal + fee) +
@@ -508,6 +532,7 @@ function buildPurchaseTx (params) {
508
532
  purchase({
509
533
  spend: tx,
510
534
  lockingScript: lockingScript,
535
+ parsed: parsed, // reuse the parse above — don't re-parse inside purchase()
511
536
  satoshis: ordSats,
512
537
  inputIndex: 0,
513
538
  payoutIndex: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "description": "🚀 Complete Bitcoin SV development framework with legally-recognizable DID:web + W3C VC-JWT toolkit, Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), StatusList2021 revocation, and 16 flexible loading options. Standards-based credentials with ES256/ES256K support, on-chain BSV anchoring, and comprehensive Bitcoin SV API. Perfect for legal tokens, verifiable credentials, DeFi, smart contracts, and secure Bitcoin applications.",
5
5
  "author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
6
6
  "homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
@@ -9,6 +9,9 @@
9
9
  },
10
10
  "main": "index.js",
11
11
  "types": "bsv.d.ts",
12
+ "engines": {
13
+ "node": ">=20.19.0"
14
+ },
12
15
  "bin": {
13
16
  "smartledger-bsv": "./bin/cli.js"
14
17
  },
@@ -66,6 +66,16 @@ describe('Ordinals BSV-20 fungible tokens', function () {
66
66
  p.amt.should.equal('42')
67
67
  })
68
68
 
69
+ // Code-review finding #4: leading-zero integer strings are canonicalized (indexers expect
70
+ // canonical decimals), while preserving arbitrary precision.
71
+ it('canonicalizes leading-zero amount strings', function () {
72
+ B.parseBsv20(B.buildMint({ address: address, tick: 'ORDI', amt: '007' })).amt.should.equal('7')
73
+ B.parseBsv20(B.buildDeploy({ address: address, tick: 'ORDI', max: '000100' })).max.should.equal('100')
74
+ // canonicalization does not corrupt a huge value
75
+ var huge = '90000000000000000000000000'
76
+ B.parseBsv20(B.buildMint({ address: address, tick: 'ORDI', amt: '0' + huge })).amt.should.equal(huge)
77
+ })
78
+
69
79
  it('builds a 1-sat token output', function () {
70
80
  var out = B.createMintOutput({ address: address, tick: 'ORDI', amt: '1' })
71
81
  out.satoshis.should.equal(1)
@@ -480,3 +480,73 @@ describe('Ordinals OrdLock — full lifecycle (list -> buy / cancel)', function
480
480
  }).should.throw(/insufficient funding/)
481
481
  })
482
482
  })
483
+
484
+ describe('Ordinals OrdLock — code-review regressions', function () {
485
+ this.timeout(20000)
486
+ var I = bsv.Script.Interpreter
487
+ var saved
488
+ before(function () {
489
+ saved = { el: I.MAX_SCRIPT_ELEMENT_SIZE, num: I.MAXIMUM_ELEMENT_SIZE, ops: I.MAX_OPS_PER_SCRIPT }
490
+ SC.enableGenesis()
491
+ })
492
+ after(function () {
493
+ I.MAX_SCRIPT_ELEMENT_SIZE = saved.el
494
+ I.MAXIMUM_ELEMENT_SIZE = saved.num
495
+ I.MAX_OPS_PER_SCRIPT = saved.ops
496
+ })
497
+
498
+ var owner = PrivateKey.fromRandom()
499
+ var fundKey = PrivateKey.fromRandom()
500
+ var ownerScript = bsv.Script.buildPublicKeyHashOut(owner.toAddress())
501
+ var fundScript = bsv.Script.buildPublicKeyHashOut(fundKey.toAddress())
502
+
503
+ // Finding #1: buildListingTx must sign the ordinal input with the resolved value even
504
+ // when the caller omits ordinal.satoshis (documented to default to 1).
505
+ it('buildListingTx signs a valid ordinal input when ordinal.satoshis is omitted', function () {
506
+ var out = Ord.buildListingTx({
507
+ ordinal: { txid: '0e'.repeat(32), outputIndex: 0, script: ownerScript, privateKey: owner }, // no satoshis
508
+ seller: owner.toAddress(),
509
+ price: PRICE,
510
+ funding: [{ txid: 'f0'.repeat(32), outputIndex: 0, script: fundScript, satoshis: 20000, privateKey: fundKey }],
511
+ fee: 500
512
+ })
513
+ verify(out.tx.inputs[0].script, ownerScript, { tx: out.tx, satoshis: 1, inputIndex: 0 }).ok.should.equal(true)
514
+ })
515
+
516
+ // Finding #2: parsed addresses honor a network option instead of always being livenet.
517
+ it('parseOrdLock formats addresses for the requested network', function () {
518
+ var lock = Ord.buildOrdLock({ seller: owner.toAddress(), price: PRICE })
519
+ var live = Ord.parseOrdLock(lock).seller.address
520
+ var test = Ord.parseOrdLock(lock, { network: 'testnet' }).seller.address
521
+ live.should.not.equal(test)
522
+ bsv.Address.fromString(test).network.name.should.equal('testnet')
523
+ bsv.Address.fromString(live).network.name.should.equal('livenet')
524
+ })
525
+
526
+ // Finding #3: a funding coin missing satoshis fails fast (was a silent wrong-amount signature).
527
+ it('buildPurchaseTx throws when a funding coin has no satoshis', function () {
528
+ var lock = Ord.buildOrdLock({ seller: owner.toAddress(), price: PRICE })
529
+ ;(function () {
530
+ Ord.buildPurchaseTx({
531
+ listing: { txid: 'a1'.repeat(32), outputIndex: 0, script: lock, satoshis: 1 },
532
+ ordinalDestination: fundKey.toAddress(),
533
+ funding: [{ txid: 'b1'.repeat(32), outputIndex: 0, script: fundScript, privateKey: fundKey }], // no satoshis
534
+ fee: 500
535
+ })
536
+ }).should.throw(/satoshis/)
537
+ })
538
+
539
+ // Finding #5: payOutputFor never silently ignores price when handed a full Output.
540
+ it('payOutputFor rejects a Transaction.Output (price would be ignored)', function () {
541
+ var o = new bsv.Transaction.Output({ script: ownerScript, satoshis: 5 })
542
+ ;(function () { Ord.payOutputFor(o, PRICE) }).should.throw()
543
+ })
544
+
545
+ it('buildOrdLock still accepts a pre-built Output as payTo (uses its own value)', function () {
546
+ var lock = Ord.buildOrdLock({
547
+ seller: owner.toAddress(), price: 1,
548
+ payTo: new bsv.Transaction.Output({ script: ownerScript, satoshis: 777 })
549
+ })
550
+ Ord.parseOrdLock(lock).totalPrice.should.equal(777)
551
+ })
552
+ })