@bcts/components 1.0.0-alpha.16 → 1.0.0-alpha.18
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/README.md +1 -1
- package/dist/index.cjs +100 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1498 -1445
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1498 -1445
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +101 -26
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +100 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Also includes a library of CBOR tags and UR types for use with these types.
|
|
|
10
10
|
|
|
11
11
|
## Rust Reference Implementation
|
|
12
12
|
|
|
13
|
-
This TypeScript implementation is based on [bc-components-rust](https://github.com/BlockchainCommons/bc-components-rust) **v0.
|
|
13
|
+
This TypeScript implementation is based on [bc-components-rust](https://github.com/BlockchainCommons/bc-components-rust) **v0.31.1** ([commit](https://github.com/BlockchainCommons/bc-components-rust/tree/fe31ddd48c1a1b0dfa161e876f7ea5bbadfb5a8f)).
|
|
14
14
|
|
|
15
15
|
### Limitations: SSH Agent Integration
|
|
16
16
|
|
package/dist/index.cjs
CHANGED
|
@@ -2081,6 +2081,12 @@ var ARID = class ARID {
|
|
|
2081
2081
|
const ur = _bcts_uniform_resources.UR.fromURString(urString);
|
|
2082
2082
|
return ARID.fromUR(ur);
|
|
2083
2083
|
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Alias for fromURString for Rust API compatibility.
|
|
2086
|
+
*/
|
|
2087
|
+
static fromUrString(urString) {
|
|
2088
|
+
return ARID.fromURString(urString);
|
|
2089
|
+
}
|
|
2084
2090
|
};
|
|
2085
2091
|
|
|
2086
2092
|
//#endregion
|
|
@@ -2403,6 +2409,28 @@ var XID = class XID {
|
|
|
2403
2409
|
return new XID(data);
|
|
2404
2410
|
}
|
|
2405
2411
|
/**
|
|
2412
|
+
* Create a new XID from the given public key (the "genesis key").
|
|
2413
|
+
*
|
|
2414
|
+
* The XID is the SHA-256 digest of the CBOR encoding of the public key.
|
|
2415
|
+
* This matches Rust's `XID::new(genesis_key: impl AsRef<SigningPublicKey>)`.
|
|
2416
|
+
*/
|
|
2417
|
+
static newFromSigningKey(signingPublicKey) {
|
|
2418
|
+
const keyCborData = signingPublicKey.taggedCborData();
|
|
2419
|
+
const digest = require_digest.Digest.fromImage(keyCborData);
|
|
2420
|
+
return XID.fromData(digest.toData());
|
|
2421
|
+
}
|
|
2422
|
+
/**
|
|
2423
|
+
* Validate the XID against the given public key.
|
|
2424
|
+
*
|
|
2425
|
+
* Returns true if the SHA-256 hash of the key's CBOR encoding matches
|
|
2426
|
+
* the XID data. This matches Rust's `XID::validate(&self, key: &SigningPublicKey)`.
|
|
2427
|
+
*/
|
|
2428
|
+
validate(signingPublicKey) {
|
|
2429
|
+
const keyData = signingPublicKey.taggedCborData();
|
|
2430
|
+
const digest = require_digest.Digest.fromImage(keyData);
|
|
2431
|
+
return this.equals(XID.fromData(digest.toData()));
|
|
2432
|
+
}
|
|
2433
|
+
/**
|
|
2406
2434
|
* Return the data of the XID.
|
|
2407
2435
|
*/
|
|
2408
2436
|
data() {
|
|
@@ -2473,10 +2501,11 @@ var XID = class XID {
|
|
|
2473
2501
|
return true;
|
|
2474
2502
|
}
|
|
2475
2503
|
/**
|
|
2476
|
-
* Get string representation.
|
|
2504
|
+
* Get string representation (short format, matching Rust Display).
|
|
2505
|
+
* Uses first 4 bytes of the XID as hex, e.g., "XID(71274df1)".
|
|
2477
2506
|
*/
|
|
2478
2507
|
toString() {
|
|
2479
|
-
return `XID(${this.
|
|
2508
|
+
return `XID(${this.shortDescription()})`;
|
|
2480
2509
|
}
|
|
2481
2510
|
/**
|
|
2482
2511
|
* Returns the CBOR tags associated with XID.
|
|
@@ -6106,15 +6135,15 @@ var Signature = class Signature {
|
|
|
6106
6135
|
switch (this._type) {
|
|
6107
6136
|
case SignatureScheme.Ed25519: return "Ed25519";
|
|
6108
6137
|
case SignatureScheme.Schnorr: return "Schnorr";
|
|
6109
|
-
case SignatureScheme.Ecdsa: return "
|
|
6138
|
+
case SignatureScheme.Ecdsa: return "Ecdsa";
|
|
6110
6139
|
case SignatureScheme.Sr25519: return "Sr25519";
|
|
6111
6140
|
case SignatureScheme.MLDSA44: return "MLDSA-44";
|
|
6112
6141
|
case SignatureScheme.MLDSA65: return "MLDSA-65";
|
|
6113
6142
|
case SignatureScheme.MLDSA87: return "MLDSA-87";
|
|
6114
|
-
case SignatureScheme.SshEd25519: return "
|
|
6115
|
-
case SignatureScheme.SshDsa: return "
|
|
6116
|
-
case SignatureScheme.SshEcdsaP256: return "
|
|
6117
|
-
case SignatureScheme.SshEcdsaP384: return "
|
|
6143
|
+
case SignatureScheme.SshEd25519: return "SshEd25519";
|
|
6144
|
+
case SignatureScheme.SshDsa: return "SshDsa";
|
|
6145
|
+
case SignatureScheme.SshEcdsaP256: return "SshEcdsaP256";
|
|
6146
|
+
case SignatureScheme.SshEcdsaP384: return "SshEcdsaP384";
|
|
6118
6147
|
default: return this._type;
|
|
6119
6148
|
}
|
|
6120
6149
|
}
|
|
@@ -11447,11 +11476,10 @@ var PrivateKeys = class PrivateKeys {
|
|
|
11447
11476
|
*
|
|
11448
11477
|
* Ported from bc-components-rust/src/private_key_base.rs
|
|
11449
11478
|
*/
|
|
11450
|
-
/**
|
|
11451
|
-
const
|
|
11452
|
-
/** Key derivation
|
|
11453
|
-
const
|
|
11454
|
-
const INFO_AGREEMENT_X25519 = "agreement-x25519";
|
|
11479
|
+
/** Default size of PrivateKeyBase key material in bytes (used for random generation) */
|
|
11480
|
+
const PRIVATE_KEY_BASE_DEFAULT_SIZE = 32;
|
|
11481
|
+
/** Key derivation salt string - must match Rust's bc-crypto derive functions */
|
|
11482
|
+
const SALT_SIGNING = "signing";
|
|
11455
11483
|
/**
|
|
11456
11484
|
* PrivateKeyBase - Root cryptographic material for deterministic key derivation.
|
|
11457
11485
|
*
|
|
@@ -11461,7 +11489,7 @@ const INFO_AGREEMENT_X25519 = "agreement-x25519";
|
|
|
11461
11489
|
var PrivateKeyBase = class PrivateKeyBase {
|
|
11462
11490
|
_data;
|
|
11463
11491
|
constructor(data) {
|
|
11464
|
-
if (data.length
|
|
11492
|
+
if (data.length === 0) throw new Error("PrivateKeyBase must have non-zero length");
|
|
11465
11493
|
this._data = new Uint8Array(data);
|
|
11466
11494
|
}
|
|
11467
11495
|
/**
|
|
@@ -11475,7 +11503,7 @@ var PrivateKeyBase = class PrivateKeyBase {
|
|
|
11475
11503
|
* Create a new random PrivateKeyBase using the provided RNG.
|
|
11476
11504
|
*/
|
|
11477
11505
|
static newUsing(rng) {
|
|
11478
|
-
return new PrivateKeyBase(rng.randomData(
|
|
11506
|
+
return new PrivateKeyBase(rng.randomData(PRIVATE_KEY_BASE_DEFAULT_SIZE));
|
|
11479
11507
|
}
|
|
11480
11508
|
/**
|
|
11481
11509
|
* Create a PrivateKeyBase from raw bytes.
|
|
@@ -11500,21 +11528,20 @@ var PrivateKeyBase = class PrivateKeyBase {
|
|
|
11500
11528
|
/**
|
|
11501
11529
|
* Derive an Ed25519 signing private key.
|
|
11502
11530
|
*
|
|
11503
|
-
* Uses HKDF with
|
|
11531
|
+
* Uses HKDF with salt "signing", matching Rust's derive_signing_private_key().
|
|
11504
11532
|
*/
|
|
11505
11533
|
ed25519SigningPrivateKey() {
|
|
11506
|
-
const derivedKey = this._deriveKey(
|
|
11534
|
+
const derivedKey = this._deriveKey(SALT_SIGNING);
|
|
11507
11535
|
const ed25519Key = Ed25519PrivateKey.from(derivedKey);
|
|
11508
11536
|
return SigningPrivateKey.newEd25519(ed25519Key);
|
|
11509
11537
|
}
|
|
11510
11538
|
/**
|
|
11511
11539
|
* Derive an X25519 agreement private key.
|
|
11512
11540
|
*
|
|
11513
|
-
* Uses HKDF with
|
|
11541
|
+
* Uses HKDF with salt "agreement", matching Rust's derive_agreement_private_key().
|
|
11514
11542
|
*/
|
|
11515
11543
|
x25519PrivateKey() {
|
|
11516
|
-
|
|
11517
|
-
return X25519PrivateKey.fromData(derivedKey);
|
|
11544
|
+
return X25519PrivateKey.deriveFromKeyMaterial(this._data);
|
|
11518
11545
|
}
|
|
11519
11546
|
/**
|
|
11520
11547
|
* Get EncapsulationPrivateKey for decryption.
|
|
@@ -11541,12 +11568,59 @@ var PrivateKeyBase = class PrivateKeyBase {
|
|
|
11541
11568
|
return this.ed25519PrivateKeys().publicKeys();
|
|
11542
11569
|
}
|
|
11543
11570
|
/**
|
|
11571
|
+
* Derive a Schnorr signing private key.
|
|
11572
|
+
*
|
|
11573
|
+
* Uses ECPrivateKey.deriveFromKeyMaterial() matching Rust's
|
|
11574
|
+
* PrivateKeyBase::schnorr_signing_private_key().
|
|
11575
|
+
*/
|
|
11576
|
+
schnorrSigningPrivateKey() {
|
|
11577
|
+
const ecKey = ECPrivateKey.deriveFromKeyMaterial(this._data);
|
|
11578
|
+
return SigningPrivateKey.newSchnorr(ecKey);
|
|
11579
|
+
}
|
|
11580
|
+
/**
|
|
11581
|
+
* Derive a PrivateKeys container with Schnorr signing and X25519 agreement keys.
|
|
11582
|
+
*
|
|
11583
|
+
* Matches Rust's PrivateKeyBase::schnorr_private_keys().
|
|
11584
|
+
*/
|
|
11585
|
+
schnorrPrivateKeys() {
|
|
11586
|
+
return PrivateKeys.withKeys(this.schnorrSigningPrivateKey(), this.encapsulationPrivateKey());
|
|
11587
|
+
}
|
|
11588
|
+
/**
|
|
11589
|
+
* Derive a PublicKeys container from Schnorr derived keys.
|
|
11590
|
+
*/
|
|
11591
|
+
schnorrPublicKeys() {
|
|
11592
|
+
return this.schnorrPrivateKeys().publicKeys();
|
|
11593
|
+
}
|
|
11594
|
+
/**
|
|
11595
|
+
* Derive an ECDSA signing private key.
|
|
11596
|
+
*
|
|
11597
|
+
* Uses ECPrivateKey.deriveFromKeyMaterial() matching Rust's
|
|
11598
|
+
* PrivateKeyBase::ecdsa_signing_private_key().
|
|
11599
|
+
*/
|
|
11600
|
+
ecdsaSigningPrivateKey() {
|
|
11601
|
+
const ecKey = ECPrivateKey.deriveFromKeyMaterial(this._data);
|
|
11602
|
+
return SigningPrivateKey.newEcdsa(ecKey);
|
|
11603
|
+
}
|
|
11604
|
+
/**
|
|
11605
|
+
* Derive a PrivateKeys container with ECDSA signing and X25519 agreement keys.
|
|
11606
|
+
*
|
|
11607
|
+
* Matches Rust's PrivateKeyBase::ecdsa_private_keys().
|
|
11608
|
+
*/
|
|
11609
|
+
ecdsaPrivateKeys() {
|
|
11610
|
+
return PrivateKeys.withKeys(this.ecdsaSigningPrivateKey(), this.encapsulationPrivateKey());
|
|
11611
|
+
}
|
|
11612
|
+
/**
|
|
11613
|
+
* Derive a PublicKeys container from ECDSA derived keys.
|
|
11614
|
+
*/
|
|
11615
|
+
ecdsaPublicKeys() {
|
|
11616
|
+
return this.ecdsaPrivateKeys().publicKeys();
|
|
11617
|
+
}
|
|
11618
|
+
/**
|
|
11544
11619
|
* Internal key derivation using HKDF-SHA256.
|
|
11545
|
-
*
|
|
11620
|
+
* Matches Rust's hkdf_hmac_sha256(key_material, salt, key_len) with empty info.
|
|
11546
11621
|
*/
|
|
11547
|
-
_deriveKey(
|
|
11548
|
-
|
|
11549
|
-
return (0, _bcts_crypto.hkdfHmacSha256)(this._data, salt, 32);
|
|
11622
|
+
_deriveKey(salt) {
|
|
11623
|
+
return (0, _bcts_crypto.hkdfHmacSha256)(this._data, new TextEncoder().encode(salt), 32);
|
|
11550
11624
|
}
|
|
11551
11625
|
/**
|
|
11552
11626
|
* Compare with another PrivateKeyBase.
|
|
@@ -11605,7 +11679,7 @@ var PrivateKeyBase = class PrivateKeyBase {
|
|
|
11605
11679
|
* Static method to decode from tagged CBOR.
|
|
11606
11680
|
*/
|
|
11607
11681
|
static fromTaggedCbor(cborValue) {
|
|
11608
|
-
return new PrivateKeyBase(new Uint8Array(
|
|
11682
|
+
return new PrivateKeyBase(new Uint8Array(PRIVATE_KEY_BASE_DEFAULT_SIZE)).fromTaggedCbor(cborValue);
|
|
11609
11683
|
}
|
|
11610
11684
|
/**
|
|
11611
11685
|
* Static method to decode from tagged CBOR binary data.
|
|
@@ -11619,7 +11693,7 @@ var PrivateKeyBase = class PrivateKeyBase {
|
|
|
11619
11693
|
*/
|
|
11620
11694
|
static fromUntaggedCborData(data) {
|
|
11621
11695
|
const cborValue = (0, _bcts_dcbor.decodeCbor)(data);
|
|
11622
|
-
return new PrivateKeyBase(new Uint8Array(
|
|
11696
|
+
return new PrivateKeyBase(new Uint8Array(PRIVATE_KEY_BASE_DEFAULT_SIZE)).fromUntaggedCbor(cborValue);
|
|
11623
11697
|
}
|
|
11624
11698
|
/**
|
|
11625
11699
|
* Returns the UR representation.
|
|
@@ -11640,7 +11714,7 @@ var PrivateKeyBase = class PrivateKeyBase {
|
|
|
11640
11714
|
*/
|
|
11641
11715
|
static fromUR(ur) {
|
|
11642
11716
|
if (ur.urTypeStr() !== _bcts_tags.PRIVATE_KEY_BASE.name) throw new Error(`Expected UR type ${_bcts_tags.PRIVATE_KEY_BASE.name}, got ${ur.urTypeStr()}`);
|
|
11643
|
-
return new PrivateKeyBase(new Uint8Array(
|
|
11717
|
+
return new PrivateKeyBase(new Uint8Array(PRIVATE_KEY_BASE_DEFAULT_SIZE)).fromUntaggedCbor(ur.cbor());
|
|
11644
11718
|
}
|
|
11645
11719
|
/**
|
|
11646
11720
|
* Creates a PrivateKeyBase from a UR string.
|