@smartledger/bsv 7.0.2 → 7.1.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.
@@ -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.0.2/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.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@7.0.2/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.2/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.2/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.2/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.1.0/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.1.0/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.1.0/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.1.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.1.0/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.1.0/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.1.0/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.1.0/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.1.0/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.1.0/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.0.2/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.2/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.2/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.0.2/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.2/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.1.0/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.1.0/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.1.0/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.1.0/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.1.0/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.1.0/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.1.0/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.1.0/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.1.0/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.1.0/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.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.0.2/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@7.1.0/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -18,6 +18,21 @@ var ECDSA = function ECDSA (obj) {
18
18
  }
19
19
  }
20
20
 
21
+ // A nonce may be consumed by at most one signature: signing two messages under
22
+ // one k reveals the private key. Assigning k marks it fresh; _findSignature
23
+ // marks it stale once used, and derives a new RFC 6979 nonce when it is stale.
24
+ Object.defineProperty(ECDSA.prototype, 'k', {
25
+ get: function () {
26
+ return this._k
27
+ },
28
+ set: function (k) {
29
+ this._k = k
30
+ this._kFresh = true
31
+ },
32
+ enumerable: true,
33
+ configurable: true
34
+ })
35
+
21
36
  ECDSA.prototype.set = function (obj) {
22
37
  this.hashbuf = obj.hashbuf || this.hashbuf
23
38
  this.endian = obj.endian || this.endian // the endianness of hashbuf
@@ -39,7 +54,11 @@ ECDSA.prototype.set = function (obj) {
39
54
  this.sig = this.sig
40
55
  }
41
56
 
42
- this.k = obj.k || this.k
57
+ // Must not be `this.k = obj.k || this.k`: that re-runs the setter and would
58
+ // re-mark an already-spent nonce as fresh.
59
+ if (obj.k) {
60
+ this.k = obj.k
61
+ }
43
62
  this.verified = obj.verified || this.verified
44
63
  return this
45
64
  }
@@ -226,7 +245,8 @@ ECDSA.prototype._findSignature = function (d, e) {
226
245
  var badrs = 0
227
246
  var k, Q, r, s
228
247
  do {
229
- if (!this.k || badrs > 0) {
248
+ // A spent nonce (!this._kFresh) must never be reused for a second message.
249
+ if (!this.k || !this._kFresh || badrs > 0) {
230
250
  this.deterministicK(badrs)
231
251
  }
232
252
  badrs++
@@ -236,6 +256,8 @@ ECDSA.prototype._findSignature = function (d, e) {
236
256
  s = k.invm(N).mul(e.add(d.mul(r))).umod(N)
237
257
  } while (r.cmp(BN.Zero) <= 0 || s.cmp(BN.Zero) <= 0)
238
258
 
259
+ this._kFresh = false
260
+
239
261
  s = ECDSA.toLowS(s)
240
262
  return {
241
263
  s: s,
@@ -82,8 +82,26 @@ Signature.fromString = function (str) {
82
82
  return Signature.fromDER(buf)
83
83
  }
84
84
 
85
+ /**
86
+ * A DER INTEGER carrying r or s must be non-empty, positive (high bit clear,
87
+ * since ECDSA r/s are unsigned), and minimally padded — a leading 0x00 is
88
+ * permitted only to clear the high bit of the byte that follows. Anything else
89
+ * is a second encoding of the same number, i.e. a malleable signature.
90
+ */
91
+ function checkCanonicalInt (name, ibuf) {
92
+ $.checkArgument(ibuf.length > 0, new Error('Length of ' + name + ' is zero'))
93
+ $.checkArgument(!(ibuf[0] & 0x80), new Error('Value of ' + name + ' is negative'))
94
+ $.checkArgument(!(ibuf.length > 1 && ibuf[0] === 0x00 && !(ibuf[1] & 0x80)),
95
+ new Error('Value of ' + name + ' is excessively padded'))
96
+ }
97
+
85
98
  /**
86
99
  * In order to mimic the non-strict DER encoding of OpenSSL, set strict = false.
100
+ *
101
+ * Non-strict is required to parse the non-canonical signatures already on chain
102
+ * and is what fromTxFormat uses; consensus-level canonicality is enforced
103
+ * separately by isTxDER under the interpreter's flags. Strict is the default and
104
+ * is what application-level callers (fromDER/fromString) get.
87
105
  */
88
106
  Signature.parseDER = function (buf, strict) {
89
107
  $.checkArgument(Buffer.isBuffer(buf), new Error('DER formatted signature should be a buffer'))
@@ -115,12 +133,17 @@ Signature.parseDER = function (buf, strict) {
115
133
  var slength = buf[2 + 2 + rlength + 1]
116
134
  var sbuf = buf.slice(2 + 2 + rlength + 2, 2 + 2 + rlength + 2 + slength)
117
135
  var s = BN.fromBuffer(sbuf)
118
- var sneg = buf[2 + 2 + rlength + 2 + 2] === 0x00
136
+ var sneg = buf[2 + 2 + rlength + 2] === 0x00
119
137
  $.checkArgument(slength === sbuf.length, new Error('Length of s incorrect'))
120
138
 
121
139
  var sumlength = 2 + 2 + rlength + 2 + slength
122
140
  $.checkArgument(length === sumlength - 2, new Error('Length of signature incorrect'))
123
141
 
142
+ if (strict) {
143
+ checkCanonicalInt('r', rbuf)
144
+ checkCanonicalInt('s', sbuf)
145
+ }
146
+
124
147
  var obj = {
125
148
  header: header,
126
149
  length: length,
@@ -384,24 +407,28 @@ Signature.prototype.isValid = function () {
384
407
  }
385
408
 
386
409
  /**
387
- * Apply SmartLedger security canonicalization - called during crypto operations
410
+ * Assert that this signature is safe to accept: r and s in (0, n) and s
411
+ * canonical (low-S). Throws if not; returns `this` for chaining.
412
+ *
413
+ * This asserts rather than rewrites. Silently replacing a high-S s with n-s
414
+ * cannot protect against malleability — ECDSA accepts s and n-s equally, so the
415
+ * rewritten signature verifies exactly as the original did, and the only effect
416
+ * is to hide from the caller that they were handed a malleated signature. Use
417
+ * toCanonical() to deliberately normalize one.
388
418
  */
389
419
  Signature.prototype.applySecurityPatches = function () {
390
420
  var Point = require('./point')
391
421
  var n = Point.getN()
392
422
  var nh = n.shrn(1) // n/2
393
423
 
394
- // Security validation
395
424
  if (this.r.isZero() || this.s.isZero()) {
396
425
  throw new Error('Invalid signature: zero r or s')
397
426
  }
398
427
  if (this.r.gte(n) || this.s.gte(n)) {
399
428
  throw new Error('Invalid signature: out of range')
400
429
  }
401
-
402
- // Canonicalize s value (anti-malleability)
403
430
  if (this.s.gt(nh)) {
404
- this.s = n.sub(this.s)
431
+ throw new Error('Invalid signature: non-canonical (high) s')
405
432
  }
406
433
 
407
434
  return this
@@ -59,20 +59,19 @@ function smartVerify (msgHash, sig, pubkey) {
59
59
  return false
60
60
  }
61
61
 
62
- // Canonicalize s to lower half (anti-malleability)
63
- let canonicalS = s
62
+ // Reject high-S rather than canonicalizing it: ECDSA accepts s and n-s
63
+ // equally, so verifying a rewritten s would report every malleated signature
64
+ // as valid — the outcome this module exists to prevent.
64
65
  if (s.gt(nh)) {
65
- canonicalS = n.sub(s)
66
+ return false
66
67
  }
67
68
 
68
- // Create canonicalized signature object for ECDSA verify
69
69
  const Signature = require('./signature')
70
70
  const canonicalSig = new Signature({
71
71
  r: r,
72
- s: canonicalS
72
+ s: s
73
73
  })
74
74
 
75
- // Use BSV's ECDSA verify with canonical signature object
76
75
  return ECDSA.verify(msgHash, canonicalSig, pubkey)
77
76
  }
78
77
 
package/lib/ltp/claim.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var bsv = require('../../')
4
4
  var Hash = bsv.crypto.Hash
5
5
  var $ = bsv.util.preconditions
6
+ var Id = require('../util/id')
6
7
 
7
8
  /**
8
9
  * Legal Token Protocol - Claim Preparation Primitives
@@ -691,9 +692,7 @@ var ClaimValidator = {
691
692
  * @private
692
693
  */
693
694
  _generateBatchId: function() {
694
- // Non-security: identifier collision avoidance only
695
- var data = 'batch_' + Date.now() + '_' + Math.random()
696
- return Hash.sha256(Buffer.from(data)).toString('hex').substring(0, 16)
695
+ return Id.randomHex(16)
697
696
  },
698
697
 
699
698
  /**
@@ -6,6 +6,7 @@ var ECDSA = bsv.crypto.ECDSA
6
6
  var Signature = bsv.crypto.Signature
7
7
  var PrivateKey = bsv.PrivateKey
8
8
  var $ = bsv.util.preconditions
9
+ var Id = require('../util/id')
9
10
 
10
11
  /**
11
12
  * Resolve the AUTHORITATIVE signer public key for a token: the issuer's key,
@@ -976,12 +977,7 @@ var ObligationToken = {
976
977
  * @private
977
978
  */
978
979
  _generateUUID: function() {
979
- // Non-security: identifier collision avoidance only (not RFC 4122 v4 random)
980
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
981
- var r = Math.random() * 16 | 0
982
- var v = c === 'x' ? r : (r & 0x3 | 0x8)
983
- return v.toString(16)
984
- })
980
+ return Id.uuid4()
985
981
  }
986
982
  }
987
983
 
@@ -5,6 +5,7 @@ var Hash = bsv.crypto.Hash
5
5
  var Address = bsv.Address
6
6
  var Transaction = bsv.Transaction
7
7
  var $ = bsv.util.preconditions
8
+ var Id = require('../util/id')
8
9
 
9
10
  /**
10
11
  * Legal Token Protocol - Registry Primitives
@@ -552,9 +553,7 @@ var LTPRegistry = {
552
553
  * @private
553
554
  */
554
555
  _generateRegistryId: function() {
555
- // Non-security: identifier collision avoidance only
556
- var data = 'reg_' + Date.now() + '_' + Math.random()
557
- return 'reg_' + Hash.sha256(Buffer.from(data)).toString('hex').substring(0, 16)
556
+ return 'reg_' + Id.randomHex(16)
558
557
  },
559
558
 
560
559
  /**
@@ -686,9 +685,11 @@ var LTPRegistry = {
686
685
  * @private
687
686
  */
688
687
  _generateAuditId: function() {
689
- // Non-security: identifier collision avoidance only
690
- var data = 'audit_' + Date.now() + '_' + Math.random()
691
- return 'audit_' + Hash.sha256(Buffer.from(data)).toString('hex').substring(0, 12)
688
+ // 128 bits. Audit entries are minted per action and retained for years, and
689
+ // a collision silently overwrites a record in a Map-keyed store, so this is
690
+ // sized to close the birthday question outright rather than to match the
691
+ // per-registry ids above (which are minted once each).
692
+ return 'audit_' + Id.randomHex(32)
692
693
  },
693
694
 
694
695
  /**
package/lib/ltp/right.js CHANGED
@@ -7,6 +7,7 @@ var Signature = bsv.crypto.Signature
7
7
  var PrivateKey = bsv.PrivateKey
8
8
  var $ = bsv.util.preconditions
9
9
  var _ = require('../util/_')
10
+ var Id = require('../util/id')
10
11
 
11
12
  /**
12
13
  * Resolve the AUTHORITATIVE signer public key for a token: the issuer's key.
@@ -925,12 +926,7 @@ var RightToken = {
925
926
  * @private
926
927
  */
927
928
  _generateUUID: function() {
928
- // Non-security: identifier collision avoidance only (not RFC 4122 v4 random)
929
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
930
- var r = Math.random() * 16 | 0
931
- var v = c === 'x' ? r : (r & 0x3 | 0x8)
932
- return v.toString(16)
933
- })
929
+ return Id.uuid4()
934
930
  }
935
931
  }
936
932
 
package/lib/util/id.js ADDED
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ var Random = require('../crypto/random')
4
+
5
+ /**
6
+ * RFC 4122 version 4 UUID, drawn from the CSPRNG.
7
+ *
8
+ * The engine's built-in PRNG is not an acceptable source here: V8 implements it
9
+ * with xorshift128+, whose internal state is recoverable from a handful of
10
+ * outputs, so one emitted identifier can expose every later id from the same
11
+ * process.
12
+ *
13
+ * @returns {String} e.g. '1b4e28ba-2fa1-4d9b-b6f7-1e3c9a8d5c02'
14
+ */
15
+ function uuid4 () {
16
+ var bytes = Random.getRandomBuffer(16)
17
+
18
+ bytes[6] = (bytes[6] & 0x0f) | 0x40 // version 4
19
+ bytes[8] = (bytes[8] & 0x3f) | 0x80 // variant 10x
20
+
21
+ var hex = bytes.toString('hex')
22
+ return [
23
+ hex.substring(0, 8),
24
+ hex.substring(8, 12),
25
+ hex.substring(12, 16),
26
+ hex.substring(16, 20),
27
+ hex.substring(20, 32)
28
+ ].join('-')
29
+ }
30
+
31
+ /**
32
+ * Opaque identifier of `length` hex characters, drawn from the CSPRNG.
33
+ * Entropy is 4 bits per character, so callers choose `length` to bound
34
+ * collision probability across the population of ids they expect to mint.
35
+ *
36
+ * @param {Number} length - number of hex characters
37
+ * @returns {String}
38
+ */
39
+ function randomHex (length) {
40
+ return Random.getRandomBuffer(Math.ceil(length / 2))
41
+ .toString('hex')
42
+ .substring(0, length)
43
+ }
44
+
45
+ module.exports = {
46
+ uuid4: uuid4,
47
+ randomHex: randomHex
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "7.0.2",
3
+ "version": "7.1.0",
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",
@@ -16,23 +16,30 @@ var fs = require('fs')
16
16
  var path = require('path')
17
17
  var execFileSync = require('child_process').execFileSync
18
18
  var spawnSync = require('child_process').spawnSync
19
- var gen = require('../../scripts/gen-esm-wrapper')
20
19
 
21
20
  var ROOT = path.resolve(__dirname, '../..')
22
21
  var MJS = path.join(ROOT, 'index.mjs')
23
22
 
23
+ // scripts/ is dev tooling and is not published, so the two checks that
24
+ // regenerate index.mjs can only run from a checkout. The ESM import checks below
25
+ // run everywhere, including against an installed copy. Presence is tested rather
26
+ // than try/catch'd so a broken generator still fails loudly in the repo.
27
+ var GEN = path.join(ROOT, 'scripts', 'gen-esm-wrapper.js')
28
+ var gen = fs.existsSync(GEN) ? require(GEN) : null
29
+ var itFromCheckout = gen ? it : it.skip
30
+
24
31
  function runEsm (body) {
25
32
  return execFileSync(process.execPath, ['--input-type=module', '-e', body],
26
33
  { cwd: ROOT, stdio: 'pipe' })
27
34
  }
28
35
 
29
36
  describe('ESM wrapper (index.mjs)', function () {
30
- it('is in sync with the CJS surface (no drift)', function () {
37
+ itFromCheckout('is in sync with the CJS surface (no drift)', function () {
31
38
  var onDisk = fs.readFileSync(MJS, 'utf8')
32
39
  onDisk.should.equal(gen.generate())
33
40
  })
34
41
 
35
- it('exports every non-accessor top-level member as a named binding', function () {
42
+ itFromCheckout('exports every non-accessor top-level member as a named binding', function () {
36
43
  var bsv = require('../..')
37
44
  var names = gen.exportableNames(bsv)
38
45
  names.length.should.be.above(100)