@bcts/crypto 1.0.0-alpha.10
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/LICENSE +48 -0
- package/README.md +65 -0
- package/dist/index.cjs +658 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +403 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +403 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.iife.js +652 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.mjs +594 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +80 -0
- package/src/argon.ts +47 -0
- package/src/ecdsa-keys.ts +81 -0
- package/src/ecdsa-signing.ts +65 -0
- package/src/ed25519-signing.ts +72 -0
- package/src/error.ts +49 -0
- package/src/hash.ts +134 -0
- package/src/index.ts +115 -0
- package/src/memzero.ts +37 -0
- package/src/public-key-encryption.ts +68 -0
- package/src/schnorr-signing.ts +90 -0
- package/src/scrypt.ts +50 -0
- package/src/symmetric-encryption.ts +133 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Copyright © 2023 Blockchain Commons, LLC
|
|
2
|
+
Copyright © 2025 Leonardo Amoroso Custodio
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
Subject to the terms and conditions of this license, each copyright holder and
|
|
15
|
+
contributor hereby grants to those receiving rights under this license a
|
|
16
|
+
perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
17
|
+
(except for failure to satisfy the conditions of this license) patent license to
|
|
18
|
+
make, have made, use, offer to sell, sell, import, and otherwise transfer this
|
|
19
|
+
software, where such license applies only to those patent claims, already
|
|
20
|
+
acquired or hereafter acquired, licensable by such copyright holder or
|
|
21
|
+
contributor that are necessarily infringed by:
|
|
22
|
+
|
|
23
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and
|
|
24
|
+
non-copyrightable additions of contributors, in source or binary form)
|
|
25
|
+
alone; or
|
|
26
|
+
|
|
27
|
+
(b) combination of their Contribution(s) with the work of authorship to
|
|
28
|
+
which such Contribution(s) was added by such copyright holder or
|
|
29
|
+
contributor, if, at the time the Contribution is added, such addition causes
|
|
30
|
+
such combination to be necessarily infringed. The patent license shall not
|
|
31
|
+
apply to any other combinations which include the Contribution.
|
|
32
|
+
|
|
33
|
+
Except as expressly stated above, no rights or licenses from any copyright
|
|
34
|
+
holder or contributor is granted under this license, whether expressly, by
|
|
35
|
+
implication, estoppel or otherwise.
|
|
36
|
+
|
|
37
|
+
DISCLAIMER
|
|
38
|
+
|
|
39
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
40
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
41
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
42
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
|
43
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
44
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
45
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
46
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
47
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
48
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Blockchain Commons Crypto Interfaces for TypeScript
|
|
2
|
+
|
|
3
|
+
> Disclaimer: This package is under active development and APIs may change.
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
`@bcts/crypto` exposes a uniform API for the cryptographic primitives used in higher-level [Blockchain Commons](https://blockchaincommons.com) projects such as Gordian Envelope.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Hash Functions**: SHA-256, SHA-512, HMAC, PBKDF2, HKDF, CRC32
|
|
12
|
+
- **Symmetric Encryption**: ChaCha20-Poly1305 AEAD
|
|
13
|
+
- **Public Key Cryptography**:
|
|
14
|
+
- X25519 (key agreement)
|
|
15
|
+
- ECDSA (secp256k1 signing/verification)
|
|
16
|
+
- Schnorr signatures (BIP-340)
|
|
17
|
+
- Ed25519 (signing/verification)
|
|
18
|
+
- **Key Derivation**: Scrypt, Argon2id
|
|
19
|
+
- **Memory Security**: Best-effort memory zeroing utilities
|
|
20
|
+
|
|
21
|
+
## Security Considerations
|
|
22
|
+
|
|
23
|
+
### Memory Zeroing (`memzero`)
|
|
24
|
+
|
|
25
|
+
⚠️ **IMPORTANT SECURITY LIMITATION**
|
|
26
|
+
|
|
27
|
+
The `memzero()` function provides **best-effort** memory clearing in JavaScript/TypeScript, but **cannot guarantee** that sensitive data is fully erased from memory.
|
|
28
|
+
|
|
29
|
+
**Why this limitation exists:**
|
|
30
|
+
|
|
31
|
+
- JavaScript/TypeScript lacks volatile memory writes (unlike the Rust reference implementation which uses `std::ptr::write_volatile()`)
|
|
32
|
+
- JavaScript engines and JIT compilers may optimize away zeroing operations
|
|
33
|
+
- The garbage collector may have made copies of sensitive data
|
|
34
|
+
- Swapped pages or memory dumps may contain copies
|
|
35
|
+
|
|
36
|
+
**What `memzero()` does:**
|
|
37
|
+
|
|
38
|
+
- ✅ Overwrites memory with zeros to reduce exposure time
|
|
39
|
+
- ✅ Makes a verification check to prevent some optimizations
|
|
40
|
+
- ❌ Cannot guarantee complete erasure from physical memory
|
|
41
|
+
|
|
42
|
+
**Best practices for sensitive operations:**
|
|
43
|
+
|
|
44
|
+
1. **Use Web Crypto API when possible**: For truly sensitive cryptographic operations, use `crypto.subtle` with non-extractable keys
|
|
45
|
+
2. **Minimize exposure time**: Call `memzero()` immediately after sensitive operations
|
|
46
|
+
3. **Understand the limitations**: This is defense-in-depth, not a security guarantee
|
|
47
|
+
4. **Consider your threat model**: Evaluate if JavaScript is appropriate for your security requirements
|
|
48
|
+
|
|
49
|
+
**Example:**
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { memzero } from '@bcts/crypto';
|
|
53
|
+
|
|
54
|
+
const sensitiveKey = new Uint8Array(32);
|
|
55
|
+
// ... use the key ...
|
|
56
|
+
|
|
57
|
+
// Clear from memory (best effort)
|
|
58
|
+
memzero(sensitiveKey);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For more details, see the [implementation comments](./src/memzero.ts).
|
|
62
|
+
|
|
63
|
+
## Rust Reference Implementation
|
|
64
|
+
|
|
65
|
+
This TypeScript implementation is based on [bc-crypto-rust](https://github.com/BlockchainCommons/bc-crypto-rust) **v0.14.0** ([commit](https://github.com/BlockchainCommons/bc-crypto-rust/tree/4f2b791320730578b04943c833c4a9e6c232fc4d)).
|