@smartledger/bsv 6.2.2 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +27 -27
- package/bsv-ltp.min.js +27 -27
- package/bsv-mnemonic.min.js +8 -8
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +27 -27
- package/bsv.d.ts +9 -7
- package/bsv.min.js +27 -27
- package/docs/MIGRATION_7.md +123 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/index.mjs +116 -0
- package/lib/crypto/ecdsa.js +15 -14
- package/lib/gdaf/attestation-verifier.js +2 -7
- package/lib/gdaf/did-resolver.js +1 -3
- package/lib/ltp/obligation.js +1 -2
- package/lib/ltp/proof.js +1 -3
- package/lib/ltp/right.js +2 -3
- package/lib/mnemonic/mnemonic.js +32 -2
- package/package.json +16 -2
- package/test/build/esm_wrapper.js +66 -0
- package/test/build/exports_resolution.js +58 -0
- package/test/crypto/ecdsa.js +29 -4
- package/test/mnemonic/mnemonic.js +32 -0
- package/test/security/fail_closed_contracts.js +13 -9
- package/version.js +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Migrating to `@smartledger/bsv` 7.0
|
|
2
|
+
|
|
3
|
+
7.0 is a **breaking** major. It is small and mechanical to adopt: two changes,
|
|
4
|
+
both aimed at making the library structurally harder to misuse. This document is
|
|
5
|
+
the complete list of what changed and how to update.
|
|
6
|
+
|
|
7
|
+
> Status: **7.0.0** — released.
|
|
8
|
+
> to npm. APIs below are final in intent; report friction before the stable cut.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. `ECDSA.prototype.verify()` now returns a boolean
|
|
13
|
+
|
|
14
|
+
**Why.** Pre-7.0, the low-level instance method `ECDSA.prototype.verify()`
|
|
15
|
+
returned the ECDSA *instance* (to allow `.sign().verify()` chaining), with the
|
|
16
|
+
real pass/fail result stashed on `.verified`. Because an object is always truthy,
|
|
17
|
+
`if (ecdsa.verify()) { /* trusted */ }` **silently accepted forged signatures** —
|
|
18
|
+
the single most dangerous foot-gun in the library. This class of bug was found
|
|
19
|
+
and fixed at every internal call site during the 6.0 security hardening; 7.0
|
|
20
|
+
removes the trap itself so external code can't reintroduce it.
|
|
21
|
+
|
|
22
|
+
**What changed.** `verify()` now returns a strict `boolean`. The result is still
|
|
23
|
+
mirrored on `this.verified` as a side effect, so the property-read form keeps
|
|
24
|
+
working — only the *chained* `.verify().verified` idiom is gone.
|
|
25
|
+
|
|
26
|
+
### Before → After
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// ❌ pre-7.0 — the classic trap (always truthy, accepts forgeries)
|
|
30
|
+
if (ecdsa.verify()) { accept() }
|
|
31
|
+
|
|
32
|
+
// ✅ pre-7.0 workarounds (still valid in 7.0)
|
|
33
|
+
if (ecdsa.verify().verified) { accept() } // chained read — REMOVED in 7.0
|
|
34
|
+
if (ecdsa.verifyBool()) { accept() } // still works
|
|
35
|
+
ecdsa.verify(); if (ecdsa.verified) { ... } // still works
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
// ✅ 7.0 — verify() is the boolean
|
|
40
|
+
if (ecdsa.verify()) { accept() } // now correct and safe
|
|
41
|
+
const ok = ecdsa.verify() // ok is `true` / `false`
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Migration
|
|
45
|
+
|
|
46
|
+
| If your code does… | Change it to… |
|
|
47
|
+
| ----------------------------- | ------------------------- |
|
|
48
|
+
| `ecdsa.verify().verified` | `ecdsa.verify()` |
|
|
49
|
+
| `if (ecdsa.verify())` (buggy) | *nothing* — now correct |
|
|
50
|
+
| `ecdsa.verifyBool()` | *nothing* — retained alias |
|
|
51
|
+
| `x.sign().verify().sig` etc. | split the chain: `x.sign().verify(); use x.sig` |
|
|
52
|
+
|
|
53
|
+
The **static** `ECDSA.verify(hash, sig, pubkey)` and the high-level
|
|
54
|
+
`Message.prototype.verify()` already returned booleans and are **unchanged**.
|
|
55
|
+
`verifyBool()` remains as an explicit alias.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 2. `package.json` now declares an `exports` map
|
|
60
|
+
|
|
61
|
+
**Why.** A canonical entry point with a `types` / `import` / `require`
|
|
62
|
+
conditional map, so the package is unambiguous to modern bundlers and
|
|
63
|
+
type-checkers and ready for a real dual ESM build.
|
|
64
|
+
|
|
65
|
+
**What changed.** The following import surfaces are explicitly supported:
|
|
66
|
+
|
|
67
|
+
| Specifier | Resolves to |
|
|
68
|
+
| ------------------------------------------- | ------------------ |
|
|
69
|
+
| `@smartledger/bsv` | `index.js` (CJS + `import` default) |
|
|
70
|
+
| `@smartledger/bsv/package.json` | `package.json` |
|
|
71
|
+
| `@smartledger/bsv/version` | `version.js` |
|
|
72
|
+
| `@smartledger/bsv/bsv.min.js` (any bundle) | that bundle file |
|
|
73
|
+
| `@smartledger/bsv/lib/foo` or `/lib/foo.js` | `lib/foo.js` |
|
|
74
|
+
|
|
75
|
+
The package ships a real ESM entry (`index.mjs`, behind the `import` condition),
|
|
76
|
+
so both default **and named** imports work natively:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
import bsv from '@smartledger/bsv' // default
|
|
80
|
+
import { PrivateKey, Transaction, crypto } from '@smartledger/bsv' // named
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`index.mjs` is generated from the CJS build's runtime surface (108 named
|
|
84
|
+
exports) and gated against drift; `require('@smartledger/bsv')` continues to
|
|
85
|
+
return the same object. Deprecated accessors (e.g. `SmartUTXO`) are reachable
|
|
86
|
+
via the default export but are intentionally not named exports, so importing the
|
|
87
|
+
package emits no deprecation warnings.
|
|
88
|
+
|
|
89
|
+
### Breaking edge case
|
|
90
|
+
|
|
91
|
+
Because `exports` switches Node to strict subpath resolution, **directory-style
|
|
92
|
+
deep imports without an explicit file** are no longer resolved:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
require('@smartledger/bsv/lib/smart_contract') // ❌ 7.0 — no auto /index.js
|
|
96
|
+
require('@smartledger/bsv/lib/smart_contract/index') // ✅ point at the file
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The **documented public API has always been the main entry** — prefer it:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
const { SmartContract } = require('@smartledger/bsv') // ✅ recommended
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
CDN usage (`unpkg` / `jsdelivr`) is unaffected — CDNs serve files by path and do
|
|
106
|
+
not apply `exports` resolution.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Not changing in 7.0
|
|
111
|
+
|
|
112
|
+
- Wire formats, script/covenant semantics, transaction building, address/key
|
|
113
|
+
formats — all unchanged.
|
|
114
|
+
- The 16 browser bundles and their globals.
|
|
115
|
+
- `engines.node >= 20.19` (already required since 6.0.2).
|
|
116
|
+
|
|
117
|
+
## Still on the roadmap (not in this alpha)
|
|
118
|
+
|
|
119
|
+
- A full **ESM source migration** (native `import`/`export` throughout `lib/`,
|
|
120
|
+
enabling real tree-shaking). The current `index.mjs` is a thin, drift-gated
|
|
121
|
+
wrapper that already gives working named/default ESM imports over the CJS core.
|
|
122
|
+
- Removal of the residual `verified` side-effect property once downstreams have
|
|
123
|
+
migrated.
|
|
@@ -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@
|
|
58
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
64
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
70
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
85
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@
|
|
86
|
-
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@
|
|
87
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@
|
|
88
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@
|
|
89
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@
|
|
90
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@
|
|
91
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@
|
|
92
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@
|
|
93
|
-
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@
|
|
94
|
-
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@
|
|
95
|
-
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@
|
|
84
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.1/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.0.1/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.1/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.0.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.0.1/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.1/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.1/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.1/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.0.1/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.0.1/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
104
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
110
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
111
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
109
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
117
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
118
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
116
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
137
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
135
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
149
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
725
|
+
<script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.0.1/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@
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
75
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
76
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
74
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
86
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
87
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
85
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
102
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
103
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
101
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
118
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@
|
|
119
|
-
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@
|
|
120
|
-
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@
|
|
121
|
-
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@
|
|
122
|
-
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@
|
|
123
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@
|
|
124
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@
|
|
125
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@
|
|
126
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@
|
|
127
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@
|
|
128
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@
|
|
117
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.1/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.0.1/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.0.1/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.0.1/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.0.1/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.0.1/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.1/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.1/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.1/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.0.1/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
18
18
|
|
|
19
19
|
<!-- Everything included (937KB) -->
|
|
20
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
20
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
131
131
|
|
|
132
132
|
<!-- Smart contracts (937KB) -->
|
|
133
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
133
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-smartcontract.min.js"></script>
|
|
134
134
|
|
|
135
135
|
<!-- Legal tokens (1.16MB) -->
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-ltp.min.js"></script>
|
|
137
137
|
|
|
138
138
|
<!-- Digital identity (1.16MB) -->
|
|
139
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
139
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-gdaf.min.js"></script>
|
|
140
140
|
|
|
141
141
|
<!-- Everything (937KB) -->
|
|
142
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
142
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/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@
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.min.js"></script>
|
|
163
163
|
|
|
164
164
|
<!-- Add smart contracts when ready -->
|
|
165
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
165
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-smartcontract.min.js"></script>
|
|
166
166
|
|
|
167
167
|
<!-- Add advanced features as needed -->
|
|
168
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
169
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
168
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv-gdaf.min.js"></script>
|
|
170
170
|
|
|
171
171
|
<!-- Everything in one file -->
|
|
172
|
-
<script src="https://unpkg.com/@smartledger/bsv@
|
|
172
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.0.1/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
package/index.mjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// GENERATED by scripts/gen-esm-wrapper.js on `npm version` — do not edit.
|
|
2
|
+
// Real ESM entry: default + named exports over the CJS build (index.js).
|
|
3
|
+
import bsv from './index.js'
|
|
4
|
+
|
|
5
|
+
export default bsv
|
|
6
|
+
|
|
7
|
+
export const {
|
|
8
|
+
Address,
|
|
9
|
+
Anchor,
|
|
10
|
+
Block,
|
|
11
|
+
BlockHeader,
|
|
12
|
+
BrowserUTXOManager,
|
|
13
|
+
CustomScriptHelper,
|
|
14
|
+
DIDWeb,
|
|
15
|
+
ECIES,
|
|
16
|
+
EllipticFixed,
|
|
17
|
+
GDAF,
|
|
18
|
+
HDPrivateKey,
|
|
19
|
+
HDPublicKey,
|
|
20
|
+
Input,
|
|
21
|
+
LTP,
|
|
22
|
+
MerkleBlock,
|
|
23
|
+
Message,
|
|
24
|
+
Mnemonic,
|
|
25
|
+
Networks,
|
|
26
|
+
Opcode,
|
|
27
|
+
Ordinals,
|
|
28
|
+
Output,
|
|
29
|
+
PrivateKey,
|
|
30
|
+
PublicKey,
|
|
31
|
+
SPV,
|
|
32
|
+
Script,
|
|
33
|
+
Shamir,
|
|
34
|
+
Signature,
|
|
35
|
+
SmartContract,
|
|
36
|
+
SmartLedger,
|
|
37
|
+
SmartMiner,
|
|
38
|
+
SmartVerify,
|
|
39
|
+
StatusList,
|
|
40
|
+
Transaction,
|
|
41
|
+
UnspentOutput,
|
|
42
|
+
VcJwt,
|
|
43
|
+
addCustomClaimSchema,
|
|
44
|
+
baseVersion,
|
|
45
|
+
canonicalizeClaim,
|
|
46
|
+
createAgeCredential,
|
|
47
|
+
createClaimTemplate,
|
|
48
|
+
createCredentialTemplate,
|
|
49
|
+
createDID,
|
|
50
|
+
createEmailCredential,
|
|
51
|
+
createKYCCredential,
|
|
52
|
+
createLegalRegistry,
|
|
53
|
+
createLegalValidityProof,
|
|
54
|
+
createPresentation,
|
|
55
|
+
createRightToken,
|
|
56
|
+
createSelectiveDisclosure,
|
|
57
|
+
crypto,
|
|
58
|
+
deps,
|
|
59
|
+
encoding,
|
|
60
|
+
errors,
|
|
61
|
+
formatRevocation,
|
|
62
|
+
generateAgeProof,
|
|
63
|
+
generateSelectiveProof,
|
|
64
|
+
getClaimSchema,
|
|
65
|
+
getClaimSchemaNames,
|
|
66
|
+
getClaimSchemas,
|
|
67
|
+
getCredentialSchemas,
|
|
68
|
+
getObligationPriority,
|
|
69
|
+
getObligationStatus,
|
|
70
|
+
getObligationTypes,
|
|
71
|
+
getRightTypes,
|
|
72
|
+
hardenedBy,
|
|
73
|
+
hashClaim,
|
|
74
|
+
isHardened,
|
|
75
|
+
prepareAuditLogQuery,
|
|
76
|
+
prepareBatchCommitment,
|
|
77
|
+
prepareBulkClaimValidation,
|
|
78
|
+
prepareClaimAttestation,
|
|
79
|
+
prepareClaimDispute,
|
|
80
|
+
prepareClaimTemplate,
|
|
81
|
+
prepareClaimValidation,
|
|
82
|
+
prepareLegalValidityProof,
|
|
83
|
+
prepareObligationBreachAssessment,
|
|
84
|
+
prepareObligationFulfillment,
|
|
85
|
+
prepareObligationMonitoringReport,
|
|
86
|
+
prepareObligationToken,
|
|
87
|
+
prepareObligationVerification,
|
|
88
|
+
prepareRegistry,
|
|
89
|
+
prepareRightToken,
|
|
90
|
+
prepareRightTokenTransfer,
|
|
91
|
+
prepareRightTokenVerification,
|
|
92
|
+
prepareRightTypeValidation,
|
|
93
|
+
prepareSelectiveDisclosure,
|
|
94
|
+
prepareSelectiveDisclosureVerification,
|
|
95
|
+
prepareSignatureProof,
|
|
96
|
+
prepareSignatureVerification,
|
|
97
|
+
prepareStatisticsQuery,
|
|
98
|
+
prepareTokenApproval,
|
|
99
|
+
prepareTokenCommitment,
|
|
100
|
+
prepareTokenRegistration,
|
|
101
|
+
prepareTokenRevocation,
|
|
102
|
+
prepareTokenSearch,
|
|
103
|
+
prepareTokenStatusQuery,
|
|
104
|
+
prepareZeroKnowledgeProof,
|
|
105
|
+
resolveDID,
|
|
106
|
+
securityFeatures,
|
|
107
|
+
util,
|
|
108
|
+
validateCredential,
|
|
109
|
+
validateLegalClaim,
|
|
110
|
+
verifyAgeProof,
|
|
111
|
+
verifyCredential,
|
|
112
|
+
verifyLegalToken,
|
|
113
|
+
verifyTokenAnchor,
|
|
114
|
+
version,
|
|
115
|
+
versionGuard
|
|
116
|
+
} = bsv
|
package/lib/crypto/ecdsa.js
CHANGED
|
@@ -287,26 +287,27 @@ ECDSA.prototype.toString = function () {
|
|
|
287
287
|
return JSON.stringify(obj)
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
//
|
|
290
|
+
// verify() returns a BOOLEAN: true only when the signature is valid.
|
|
291
|
+
//
|
|
292
|
+
// BREAKING (7.0): pre-7.0 this returned the ECDSA *instance* (truthy for
|
|
293
|
+
// chaining, with the real result on `.verified`), which silently accepted
|
|
294
|
+
// forged signatures whenever a caller wrote `if (ecdsa.verify())`. It now
|
|
295
|
+
// returns the boolean directly. `this.verified` is still set as a side effect,
|
|
296
|
+
// so `ecdsa.verify(); if (ecdsa.verified)` keeps working; only the chained
|
|
297
|
+
// `.verify().verified` idiom is gone — read the return value instead.
|
|
294
298
|
ECDSA.prototype.verify = function () {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
} else {
|
|
298
|
-
this.verified = false
|
|
299
|
-
}
|
|
300
|
-
return this
|
|
299
|
+
this.verified = !this.sigError()
|
|
300
|
+
return this.verified
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
|
-
* Boolean verification
|
|
305
|
-
*
|
|
304
|
+
* Boolean verification. Retained as an explicit alias of verify() for callers
|
|
305
|
+
* written against pre-7.0 code that needed the safe form; both now return a
|
|
306
|
+
* strict boolean.
|
|
306
307
|
* @returns {Boolean}
|
|
307
308
|
*/
|
|
308
309
|
ECDSA.prototype.verifyBool = function () {
|
|
309
|
-
return this.verify()
|
|
310
|
+
return this.verify() === true
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
ECDSA.sign = function (hashbuf, privkey, endian) {
|
|
@@ -339,7 +340,7 @@ ECDSA.verify = function (hashbuf, sig, pubkey, endian) {
|
|
|
339
340
|
endian: endian,
|
|
340
341
|
sig: sig,
|
|
341
342
|
pubkey: pubkey
|
|
342
|
-
}).verify()
|
|
343
|
+
}).verify()
|
|
343
344
|
}
|
|
344
345
|
|
|
345
346
|
module.exports = ECDSA
|
|
@@ -318,10 +318,7 @@ AttestationVerifier._verifySignature = async function(credential) {
|
|
|
318
318
|
ecdsa.pubkey = publicKey
|
|
319
319
|
ecdsa.sig = signature
|
|
320
320
|
|
|
321
|
-
|
|
322
|
-
// truthy), not a boolean. Read the `.verified` flag, otherwise every
|
|
323
|
-
// structurally-valid proof passes regardless of the actual signature.
|
|
324
|
-
var valid = ecdsa.verify().verified
|
|
321
|
+
var valid = ecdsa.verify()
|
|
325
322
|
|
|
326
323
|
if (valid) {
|
|
327
324
|
return {
|
|
@@ -384,9 +381,7 @@ AttestationVerifier._verifyPresentationSignature = async function(presentation)
|
|
|
384
381
|
ecdsa.pubkey = publicKey
|
|
385
382
|
ecdsa.sig = signature
|
|
386
383
|
|
|
387
|
-
|
|
388
|
-
// `.verified` (see _verifySignature).
|
|
389
|
-
var valid = ecdsa.verify().verified
|
|
384
|
+
var valid = ecdsa.verify()
|
|
390
385
|
|
|
391
386
|
return {
|
|
392
387
|
valid: valid,
|
package/lib/gdaf/did-resolver.js
CHANGED
|
@@ -278,9 +278,7 @@ DIDResolver.verifyOwnership = function(did, signature, message) {
|
|
|
278
278
|
ecdsa.pubkey = publicKey
|
|
279
279
|
ecdsa.sig = sig
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
// result lives on .verified. Returning the instance would accept ANY signature.
|
|
283
|
-
return ecdsa.verify().verified === true
|
|
281
|
+
return ecdsa.verify() === true
|
|
284
282
|
} catch (e) {
|
|
285
283
|
return false
|
|
286
284
|
}
|
package/lib/ltp/obligation.js
CHANGED
|
@@ -871,8 +871,7 @@ var ObligationToken = {
|
|
|
871
871
|
ecdsa.hashbuf = expectedHash
|
|
872
872
|
ecdsa.sig = signature
|
|
873
873
|
ecdsa.pubkey = pubKey
|
|
874
|
-
|
|
875
|
-
if (ecdsa.verify().verified !== true) {
|
|
874
|
+
if (ecdsa.verify() !== true) {
|
|
876
875
|
errors.push('Signature verification failed')
|
|
877
876
|
}
|
|
878
877
|
} catch (error) {
|
package/lib/ltp/proof.js
CHANGED
|
@@ -131,9 +131,7 @@ var LTPProof = {
|
|
|
131
131
|
ecdsa.sig = signature
|
|
132
132
|
ecdsa.pubkey = bsv.PublicKey.fromString(publicKey)
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
// the real result on .verified — read the boolean, never the instance.
|
|
136
|
-
var isValid = ecdsa.verify().verified === true
|
|
134
|
+
var isValid = ecdsa.verify() === true
|
|
137
135
|
|
|
138
136
|
return {
|
|
139
137
|
success: true,
|
package/lib/ltp/right.js
CHANGED
|
@@ -672,7 +672,7 @@ var RightToken = {
|
|
|
672
672
|
ecdsa.sig = signature
|
|
673
673
|
ecdsa.pubkey = pubKey
|
|
674
674
|
|
|
675
|
-
if (!ecdsa.verify()
|
|
675
|
+
if (!ecdsa.verify()) {
|
|
676
676
|
errors.push('Signature verification failed')
|
|
677
677
|
}
|
|
678
678
|
|
|
@@ -852,8 +852,7 @@ var RightToken = {
|
|
|
852
852
|
ecdsa.hashbuf = expectedHash
|
|
853
853
|
ecdsa.sig = signature
|
|
854
854
|
ecdsa.pubkey = pubKey
|
|
855
|
-
|
|
856
|
-
if (ecdsa.verify().verified !== true) {
|
|
855
|
+
if (ecdsa.verify() !== true) {
|
|
857
856
|
errors.push('Signature verification failed')
|
|
858
857
|
}
|
|
859
858
|
} catch (error) {
|