@bcts/xid 1.0.0-alpha.12 → 1.0.0-alpha.13
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/dist/index.cjs +108 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -34
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +49 -34
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +109 -93
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +105 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -10
- package/src/index.ts +3 -0
- package/src/key.ts +91 -60
- package/src/xid-document.ts +64 -70
package/dist/index.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope,
|
|
1
|
+
var bctsXid = (function(exports, _bcts_components, _bcts_known_values, _bcts_envelope, _bcts_provenance_mark, _bcts_dcbor) {
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
//#region src/error.ts
|
|
@@ -574,14 +574,14 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
574
574
|
* Represents a key in an XID document.
|
|
575
575
|
*/
|
|
576
576
|
var Key = class Key {
|
|
577
|
-
|
|
578
|
-
|
|
577
|
+
_publicKeys;
|
|
578
|
+
_privateKeyData;
|
|
579
579
|
_nickname;
|
|
580
580
|
_endpoints;
|
|
581
581
|
_permissions;
|
|
582
|
-
constructor(
|
|
583
|
-
this.
|
|
584
|
-
this.
|
|
582
|
+
constructor(publicKeys, privateKeyData, nickname = "", endpoints = /* @__PURE__ */ new Set(), permissions = Permissions.new()) {
|
|
583
|
+
this._publicKeys = publicKeys;
|
|
584
|
+
this._privateKeyData = privateKeyData;
|
|
585
585
|
this._nickname = nickname;
|
|
586
586
|
this._endpoints = endpoints;
|
|
587
587
|
this._permissions = permissions;
|
|
@@ -589,64 +589,78 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
589
589
|
/**
|
|
590
590
|
* Create a new Key with only public keys.
|
|
591
591
|
*/
|
|
592
|
-
static new(
|
|
593
|
-
return new Key(
|
|
592
|
+
static new(publicKeys) {
|
|
593
|
+
return new Key(publicKeys);
|
|
594
594
|
}
|
|
595
595
|
/**
|
|
596
596
|
* Create a new Key with public keys and allow-all permissions.
|
|
597
597
|
*/
|
|
598
|
-
static newAllowAll(
|
|
599
|
-
return new Key(
|
|
598
|
+
static newAllowAll(publicKeys) {
|
|
599
|
+
return new Key(publicKeys, void 0, "", /* @__PURE__ */ new Set(), Permissions.newAllowAll());
|
|
600
600
|
}
|
|
601
601
|
/**
|
|
602
|
-
* Create a new Key with private
|
|
602
|
+
* Create a new Key with private keys.
|
|
603
603
|
*/
|
|
604
|
-
static
|
|
604
|
+
static newWithPrivateKeys(privateKeys, publicKeys) {
|
|
605
605
|
const salt = _bcts_components.Salt.random(32);
|
|
606
|
-
return new Key(
|
|
606
|
+
return new Key(publicKeys, {
|
|
607
607
|
data: {
|
|
608
608
|
type: "decrypted",
|
|
609
|
-
|
|
609
|
+
privateKeys
|
|
610
610
|
},
|
|
611
611
|
salt
|
|
612
612
|
}, "", /* @__PURE__ */ new Set(), Permissions.newAllowAll());
|
|
613
613
|
}
|
|
614
614
|
/**
|
|
615
|
-
*
|
|
615
|
+
* Create a new Key with private key base (derives keys from it).
|
|
616
|
+
*/
|
|
617
|
+
static newWithPrivateKeyBase(privateKeyBase) {
|
|
618
|
+
const privateKeys = privateKeyBase.ed25519PrivateKeys();
|
|
619
|
+
const publicKeys = privateKeyBase.ed25519PublicKeys();
|
|
620
|
+
return Key.newWithPrivateKeys(privateKeys, publicKeys);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Get the public keys.
|
|
616
624
|
*/
|
|
617
|
-
|
|
618
|
-
return this.
|
|
625
|
+
publicKeys() {
|
|
626
|
+
return this._publicKeys;
|
|
619
627
|
}
|
|
620
628
|
/**
|
|
621
|
-
* Get the private
|
|
629
|
+
* Get the private keys, if available and decrypted.
|
|
622
630
|
*/
|
|
623
|
-
|
|
624
|
-
if (this.
|
|
625
|
-
if (this.
|
|
631
|
+
privateKeys() {
|
|
632
|
+
if (this._privateKeyData === void 0) return void 0;
|
|
633
|
+
if (this._privateKeyData.data.type === "decrypted") return this._privateKeyData.data.privateKeys;
|
|
626
634
|
}
|
|
627
635
|
/**
|
|
628
636
|
* Check if this key has decrypted private keys.
|
|
629
637
|
*/
|
|
630
638
|
hasPrivateKeys() {
|
|
631
|
-
return this.
|
|
639
|
+
return this._privateKeyData?.data.type === "decrypted";
|
|
632
640
|
}
|
|
633
641
|
/**
|
|
634
642
|
* Check if this key has encrypted private keys.
|
|
635
643
|
*/
|
|
636
644
|
hasEncryptedPrivateKeys() {
|
|
637
|
-
return this.
|
|
645
|
+
return this._privateKeyData?.data.type === "encrypted";
|
|
638
646
|
}
|
|
639
647
|
/**
|
|
640
648
|
* Get the salt used for private key decorrelation.
|
|
641
649
|
*/
|
|
642
650
|
privateKeySalt() {
|
|
643
|
-
return this.
|
|
651
|
+
return this._privateKeyData?.salt;
|
|
644
652
|
}
|
|
645
653
|
/**
|
|
646
|
-
* Get the reference for this key (based on public
|
|
654
|
+
* Get the reference for this key (based on public keys tagged CBOR).
|
|
647
655
|
*/
|
|
648
656
|
reference() {
|
|
649
|
-
return
|
|
657
|
+
return this._publicKeys.reference();
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Verify a signature against a message.
|
|
661
|
+
*/
|
|
662
|
+
verify(signature, message) {
|
|
663
|
+
return this._publicKeys.verify(signature, message);
|
|
650
664
|
}
|
|
651
665
|
/**
|
|
652
666
|
* Get the endpoints set.
|
|
@@ -688,26 +702,26 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
688
702
|
* Convert to envelope with specified options.
|
|
689
703
|
*/
|
|
690
704
|
intoEnvelopeOpt(privateKeyOptions = XIDPrivateKeyOptions.Omit) {
|
|
691
|
-
let envelope = _bcts_envelope.Envelope.new(this.
|
|
692
|
-
if (this.
|
|
693
|
-
const { data, salt } = this.
|
|
705
|
+
let envelope = _bcts_envelope.Envelope.new(this._publicKeys.taggedCborData());
|
|
706
|
+
if (this._privateKeyData !== void 0) {
|
|
707
|
+
const { data, salt } = this._privateKeyData;
|
|
694
708
|
if (data.type === "encrypted") {
|
|
695
709
|
envelope = envelope.addAssertion(kv$3(_bcts_known_values.PRIVATE_KEY), data.envelope);
|
|
696
710
|
envelope = envelope.addAssertion(kv$3(_bcts_known_values.SALT), salt.toData());
|
|
697
711
|
} else if (data.type === "decrypted") switch (typeof privateKeyOptions === "object" ? privateKeyOptions.type : privateKeyOptions) {
|
|
698
712
|
case XIDPrivateKeyOptions.Include:
|
|
699
|
-
envelope = envelope.addAssertion(kv$3(_bcts_known_values.PRIVATE_KEY), data.
|
|
713
|
+
envelope = envelope.addAssertion(kv$3(_bcts_known_values.PRIVATE_KEY), data.privateKeys.taggedCborData());
|
|
700
714
|
envelope = envelope.addAssertion(kv$3(_bcts_known_values.SALT), salt.toData());
|
|
701
715
|
break;
|
|
702
716
|
case XIDPrivateKeyOptions.Elide: {
|
|
703
|
-
const elidedAssertion = _bcts_envelope.Envelope.newAssertion(kv$3(_bcts_known_values.PRIVATE_KEY), data.
|
|
717
|
+
const elidedAssertion = _bcts_envelope.Envelope.newAssertion(kv$3(_bcts_known_values.PRIVATE_KEY), data.privateKeys.taggedCborData()).elide();
|
|
704
718
|
envelope = envelope.addAssertionEnvelope(elidedAssertion);
|
|
705
719
|
envelope = envelope.addAssertion(kv$3(_bcts_known_values.SALT), salt.toData());
|
|
706
720
|
break;
|
|
707
721
|
}
|
|
708
722
|
case XIDPrivateKeyOptions.Encrypt:
|
|
709
723
|
if (typeof privateKeyOptions === "object") {
|
|
710
|
-
const encrypted = _bcts_envelope.Envelope.new(data.
|
|
724
|
+
const encrypted = _bcts_envelope.Envelope.new(data.privateKeys.taggedCborData()).encryptSubject(privateKeyOptions.password);
|
|
711
725
|
envelope = envelope.addAssertion(kv$3(_bcts_known_values.PRIVATE_KEY), encrypted);
|
|
712
726
|
envelope = envelope.addAssertion(kv$3(_bcts_known_values.SALT), salt.toData());
|
|
713
727
|
}
|
|
@@ -729,10 +743,10 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
729
743
|
*/
|
|
730
744
|
static tryFromEnvelope(envelope, password) {
|
|
731
745
|
const env = envelope;
|
|
732
|
-
const
|
|
733
|
-
if (
|
|
734
|
-
const
|
|
735
|
-
let
|
|
746
|
+
const publicKeysData = (env.case().type === "node" ? env.subject() : env).asByteString();
|
|
747
|
+
if (publicKeysData === void 0) throw XIDError.component(/* @__PURE__ */ new Error("Could not extract public keys from envelope"));
|
|
748
|
+
const publicKeys = _bcts_components.PublicKeys.fromTaggedCborData(publicKeysData);
|
|
749
|
+
let privateKeyData;
|
|
736
750
|
let salt = _bcts_components.Salt.random(32);
|
|
737
751
|
const saltAssertions = env.assertionsWithPredicate(_bcts_known_values.SALT);
|
|
738
752
|
if (saltAssertions.length > 0) {
|
|
@@ -749,15 +763,15 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
749
763
|
const privateKeyObject = assertionCase.assertion.object();
|
|
750
764
|
if (privateKeyObject.case().type === "encrypted") if (password !== void 0) try {
|
|
751
765
|
const decryptedData = privateKeyObject.decryptSubject(password).asByteString();
|
|
752
|
-
if (decryptedData !== void 0)
|
|
766
|
+
if (decryptedData !== void 0) privateKeyData = {
|
|
753
767
|
data: {
|
|
754
768
|
type: "decrypted",
|
|
755
|
-
|
|
769
|
+
privateKeys: _bcts_components.PrivateKeys.fromTaggedCborData(decryptedData)
|
|
756
770
|
},
|
|
757
771
|
salt
|
|
758
772
|
};
|
|
759
773
|
} catch {
|
|
760
|
-
|
|
774
|
+
privateKeyData = {
|
|
761
775
|
data: {
|
|
762
776
|
type: "encrypted",
|
|
763
777
|
envelope: privateKeyObject
|
|
@@ -765,7 +779,7 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
765
779
|
salt
|
|
766
780
|
};
|
|
767
781
|
}
|
|
768
|
-
else
|
|
782
|
+
else privateKeyData = {
|
|
769
783
|
data: {
|
|
770
784
|
type: "encrypted",
|
|
771
785
|
envelope: privateKeyObject
|
|
@@ -773,11 +787,11 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
773
787
|
salt
|
|
774
788
|
};
|
|
775
789
|
else {
|
|
776
|
-
const
|
|
777
|
-
if (
|
|
790
|
+
const privateKeysBytes = privateKeyObject.asByteString();
|
|
791
|
+
if (privateKeysBytes !== void 0) privateKeyData = {
|
|
778
792
|
data: {
|
|
779
793
|
type: "decrypted",
|
|
780
|
-
|
|
794
|
+
privateKeys: _bcts_components.PrivateKeys.fromTaggedCborData(privateKeysBytes)
|
|
781
795
|
},
|
|
782
796
|
salt
|
|
783
797
|
};
|
|
@@ -796,27 +810,27 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
796
810
|
if (text !== void 0) endpoints.add(text);
|
|
797
811
|
}
|
|
798
812
|
const permissions = Permissions.tryFromEnvelope(envelope);
|
|
799
|
-
return new Key(
|
|
813
|
+
return new Key(publicKeys, privateKeyData, nickname, endpoints, permissions);
|
|
800
814
|
}
|
|
801
815
|
/**
|
|
802
816
|
* Check equality with another Key.
|
|
803
817
|
*/
|
|
804
818
|
equals(other) {
|
|
805
|
-
return this.
|
|
819
|
+
return this._publicKeys.equals(other._publicKeys);
|
|
806
820
|
}
|
|
807
821
|
/**
|
|
808
822
|
* Get a hash key for use in Sets/Maps.
|
|
809
823
|
*/
|
|
810
824
|
hashKey() {
|
|
811
|
-
return this.
|
|
825
|
+
return this._publicKeys.reference().toHex();
|
|
812
826
|
}
|
|
813
827
|
/**
|
|
814
828
|
* Clone this Key.
|
|
815
829
|
*/
|
|
816
830
|
clone() {
|
|
817
|
-
return new Key(this.
|
|
818
|
-
data: this.
|
|
819
|
-
salt: this.
|
|
831
|
+
return new Key(this._publicKeys, this._privateKeyData !== void 0 ? {
|
|
832
|
+
data: this._privateKeyData.data,
|
|
833
|
+
salt: this._privateKeyData.salt
|
|
820
834
|
} : void 0, this._nickname, new Set(this._endpoints), this._permissions.clone());
|
|
821
835
|
}
|
|
822
836
|
};
|
|
@@ -963,11 +977,11 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
963
977
|
intoEnvelope() {
|
|
964
978
|
let envelope = _bcts_envelope.Envelope.new(this._uri);
|
|
965
979
|
for (const keyRef of this._keyReferences) {
|
|
966
|
-
const refBytes = hexToBytes
|
|
980
|
+
const refBytes = hexToBytes(keyRef);
|
|
967
981
|
envelope = envelope.addAssertion(kv$2(_bcts_known_values.KEY), refBytes);
|
|
968
982
|
}
|
|
969
983
|
for (const delegateRef of this._delegateReferences) {
|
|
970
|
-
const refBytes = hexToBytes
|
|
984
|
+
const refBytes = hexToBytes(delegateRef);
|
|
971
985
|
envelope = envelope.addAssertion(kv$2(_bcts_known_values.DELEGATE), refBytes);
|
|
972
986
|
}
|
|
973
987
|
if (this._capability !== "") envelope = envelope.addAssertion(kv$2(_bcts_known_values.CAPABILITY), this._capability);
|
|
@@ -1048,7 +1062,7 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1048
1062
|
return clone;
|
|
1049
1063
|
}
|
|
1050
1064
|
};
|
|
1051
|
-
function hexToBytes
|
|
1065
|
+
function hexToBytes(hex) {
|
|
1052
1066
|
const bytes = new Uint8Array(hex.length / 2);
|
|
1053
1067
|
for (let i = 0; i < hex.length; i += 2) bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
1054
1068
|
return bytes;
|
|
@@ -1459,18 +1473,19 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1459
1473
|
static new(keyOptions = { type: "default" }, markOptions = { type: "none" }) {
|
|
1460
1474
|
const inceptionKey = XIDDocument.inceptionKeyForOptions(keyOptions);
|
|
1461
1475
|
const provenance = XIDDocument.genesisMarkWithOptions(markOptions);
|
|
1462
|
-
const doc = new XIDDocument(_bcts_components.XID.from(
|
|
1476
|
+
const doc = new XIDDocument(_bcts_components.XID.from(inceptionKey.publicKeys().reference().getDigest().toData()), /* @__PURE__ */ new Set(), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), provenance);
|
|
1463
1477
|
doc.addKey(inceptionKey);
|
|
1464
1478
|
return doc;
|
|
1465
1479
|
}
|
|
1466
1480
|
static inceptionKeyForOptions(options) {
|
|
1467
1481
|
switch (options.type) {
|
|
1468
1482
|
case "default": {
|
|
1469
|
-
const privateKeyBase =
|
|
1483
|
+
const privateKeyBase = _bcts_components.PrivateKeyBase.new();
|
|
1470
1484
|
return Key.newWithPrivateKeyBase(privateKeyBase);
|
|
1471
1485
|
}
|
|
1472
|
-
case "
|
|
1486
|
+
case "publicKeys": return Key.newAllowAll(options.publicKeys);
|
|
1473
1487
|
case "privateKeyBase": return Key.newWithPrivateKeyBase(options.privateKeyBase);
|
|
1488
|
+
case "privateKeys": return Key.newWithPrivateKeys(options.privateKeys, options.publicKeys);
|
|
1474
1489
|
}
|
|
1475
1490
|
}
|
|
1476
1491
|
static genesisMarkWithOptions(options) {
|
|
@@ -1537,10 +1552,10 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1537
1552
|
this._keys.set(hashKey, key);
|
|
1538
1553
|
}
|
|
1539
1554
|
/**
|
|
1540
|
-
* Find a key by its public
|
|
1555
|
+
* Find a key by its public keys.
|
|
1541
1556
|
*/
|
|
1542
|
-
|
|
1543
|
-
const hashKey =
|
|
1557
|
+
findKeyByPublicKeys(publicKeys) {
|
|
1558
|
+
const hashKey = publicKeys.reference().toHex();
|
|
1544
1559
|
return this._keys.get(hashKey);
|
|
1545
1560
|
}
|
|
1546
1561
|
/**
|
|
@@ -1552,8 +1567,8 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1552
1567
|
/**
|
|
1553
1568
|
* Take and remove a key.
|
|
1554
1569
|
*/
|
|
1555
|
-
takeKey(
|
|
1556
|
-
const hashKey =
|
|
1570
|
+
takeKey(publicKeys) {
|
|
1571
|
+
const hashKey = publicKeys.reference().toHex();
|
|
1557
1572
|
const key = this._keys.get(hashKey);
|
|
1558
1573
|
if (key !== void 0) this._keys.delete(hashKey);
|
|
1559
1574
|
return key;
|
|
@@ -1561,28 +1576,28 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1561
1576
|
/**
|
|
1562
1577
|
* Remove a key.
|
|
1563
1578
|
*/
|
|
1564
|
-
removeKey(
|
|
1565
|
-
if (this.servicesReferenceKey(
|
|
1566
|
-
const hashKey =
|
|
1579
|
+
removeKey(publicKeys) {
|
|
1580
|
+
if (this.servicesReferenceKey(publicKeys)) throw XIDError.stillReferenced("key");
|
|
1581
|
+
const hashKey = publicKeys.reference().toHex();
|
|
1567
1582
|
if (!this._keys.delete(hashKey)) throw XIDError.notFound("key");
|
|
1568
1583
|
}
|
|
1569
1584
|
/**
|
|
1570
|
-
* Check if the given public
|
|
1585
|
+
* Check if the given public keys is the inception signing key.
|
|
1571
1586
|
*/
|
|
1572
|
-
isInceptionKey(
|
|
1573
|
-
return bytesEqual(
|
|
1587
|
+
isInceptionKey(publicKeys) {
|
|
1588
|
+
return bytesEqual(publicKeys.reference().getDigest().toData(), this._xid.toData());
|
|
1574
1589
|
}
|
|
1575
1590
|
/**
|
|
1576
1591
|
* Get the inception key, if it exists in the document.
|
|
1577
1592
|
*/
|
|
1578
1593
|
inceptionKey() {
|
|
1579
|
-
for (const key of this._keys.values()) if (this.isInceptionKey(key.
|
|
1594
|
+
for (const key of this._keys.values()) if (this.isInceptionKey(key.publicKeys())) return key;
|
|
1580
1595
|
}
|
|
1581
1596
|
/**
|
|
1582
|
-
* Get the inception private
|
|
1597
|
+
* Get the inception private keys, if available.
|
|
1583
1598
|
*/
|
|
1584
|
-
|
|
1585
|
-
return this.inceptionKey()?.
|
|
1599
|
+
inceptionPrivateKeys() {
|
|
1600
|
+
return this.inceptionKey()?.privateKeys();
|
|
1586
1601
|
}
|
|
1587
1602
|
/**
|
|
1588
1603
|
* Remove the inception key from the document.
|
|
@@ -1687,13 +1702,11 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1687
1702
|
checkServiceConsistency(service) {
|
|
1688
1703
|
if (service.keyReferences().size === 0 && service.delegateReferences().size === 0) throw XIDError.noReferences(service.uri());
|
|
1689
1704
|
for (const keyRef of service.keyReferences()) {
|
|
1690
|
-
const
|
|
1691
|
-
const ref = _bcts_components.Reference.hash(refBytes);
|
|
1705
|
+
const ref = _bcts_components.Reference.fromHex(keyRef);
|
|
1692
1706
|
if (this.findKeyByReference(ref) === void 0) throw XIDError.unknownKeyReference(keyRef, service.uri());
|
|
1693
1707
|
}
|
|
1694
1708
|
for (const delegateRef of service.delegateReferences()) {
|
|
1695
|
-
const
|
|
1696
|
-
const ref = _bcts_components.Reference.hash(refBytes);
|
|
1709
|
+
const ref = _bcts_components.Reference.fromHex(delegateRef);
|
|
1697
1710
|
if (this.findDelegateByReference(ref) === void 0) throw XIDError.unknownDelegateReference(delegateRef, service.uri());
|
|
1698
1711
|
}
|
|
1699
1712
|
if (service.permissions().allow.size === 0) throw XIDError.noPermissions(service.uri());
|
|
@@ -1701,8 +1714,8 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1701
1714
|
/**
|
|
1702
1715
|
* Check if any service references the given key.
|
|
1703
1716
|
*/
|
|
1704
|
-
servicesReferenceKey(
|
|
1705
|
-
const keyRef =
|
|
1717
|
+
servicesReferenceKey(publicKeys) {
|
|
1718
|
+
const keyRef = publicKeys.reference().toHex();
|
|
1706
1719
|
for (const service of this._services.values()) if (service.keyReferences().has(keyRef)) return true;
|
|
1707
1720
|
return false;
|
|
1708
1721
|
}
|
|
@@ -1781,13 +1794,18 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1781
1794
|
case "inception": {
|
|
1782
1795
|
const inceptionKey = this.inceptionKey();
|
|
1783
1796
|
if (inceptionKey === void 0) throw XIDError.missingInceptionKey();
|
|
1784
|
-
const
|
|
1785
|
-
if (
|
|
1786
|
-
envelope = envelope.
|
|
1797
|
+
const privateKeys = inceptionKey.privateKeys();
|
|
1798
|
+
if (privateKeys === void 0) throw XIDError.missingInceptionKey();
|
|
1799
|
+
envelope = envelope.sign(privateKeys);
|
|
1787
1800
|
break;
|
|
1788
1801
|
}
|
|
1789
|
-
case "privateKeyBase":
|
|
1790
|
-
|
|
1802
|
+
case "privateKeyBase": {
|
|
1803
|
+
const privateKeys = signingOptions.privateKeyBase.ed25519PrivateKeys();
|
|
1804
|
+
envelope = envelope.sign(privateKeys);
|
|
1805
|
+
break;
|
|
1806
|
+
}
|
|
1807
|
+
case "privateKeys":
|
|
1808
|
+
envelope = envelope.sign(signingOptions.privateKeys);
|
|
1791
1809
|
break;
|
|
1792
1810
|
case "none":
|
|
1793
1811
|
default: break;
|
|
@@ -1814,8 +1832,8 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1814
1832
|
const doc = XIDDocument.fromEnvelopeInner(unwrapped, password);
|
|
1815
1833
|
const inceptionKey = doc.inceptionKey();
|
|
1816
1834
|
if (inceptionKey === void 0) throw XIDError.missingInceptionKey();
|
|
1817
|
-
if (!envelopeExt.hasSignatureFrom(inceptionKey.
|
|
1818
|
-
if (!doc.isInceptionKey(inceptionKey.
|
|
1835
|
+
if (!envelopeExt.hasSignatureFrom(inceptionKey.publicKeys())) throw XIDError.signatureVerificationFailed();
|
|
1836
|
+
if (!doc.isInceptionKey(inceptionKey.publicKeys())) throw XIDError.invalidXid();
|
|
1819
1837
|
return doc;
|
|
1820
1838
|
}
|
|
1821
1839
|
}
|
|
@@ -1869,7 +1887,7 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1869
1887
|
* Create a signed envelope.
|
|
1870
1888
|
*/
|
|
1871
1889
|
toSignedEnvelope(signingKey) {
|
|
1872
|
-
return this.toEnvelope(XIDPrivateKeyOptions.Omit, XIDGeneratorOptions.Omit, { type: "none" }).
|
|
1890
|
+
return this.toEnvelope(XIDPrivateKeyOptions.Omit, XIDGeneratorOptions.Omit, { type: "none" }).sign(signingKey);
|
|
1873
1891
|
}
|
|
1874
1892
|
/**
|
|
1875
1893
|
* Get the reference for this document.
|
|
@@ -1897,19 +1915,11 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1897
1915
|
}
|
|
1898
1916
|
};
|
|
1899
1917
|
registerXIDDocumentClass(XIDDocument);
|
|
1900
|
-
function hexToBytes(hex) {
|
|
1901
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
1902
|
-
for (let i = 0; i < hex.length; i += 2) bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
1903
|
-
return bytes;
|
|
1904
|
-
}
|
|
1905
1918
|
function bytesEqual(a, b) {
|
|
1906
1919
|
if (a.length !== b.length) return false;
|
|
1907
1920
|
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
1908
1921
|
return true;
|
|
1909
1922
|
}
|
|
1910
|
-
function hashPublicKey(publicKeyBase) {
|
|
1911
|
-
return _bcts_components.Reference.hash(publicKeyBase.data()).getDigest().toData();
|
|
1912
|
-
}
|
|
1913
1923
|
|
|
1914
1924
|
//#endregion
|
|
1915
1925
|
//#region src/index.ts
|
|
@@ -1926,6 +1936,12 @@ exports.Provenance = Provenance;
|
|
|
1926
1936
|
exports.Service = Service;
|
|
1927
1937
|
exports.Shared = Shared;
|
|
1928
1938
|
exports.VERSION = VERSION;
|
|
1939
|
+
Object.defineProperty(exports, 'XID', {
|
|
1940
|
+
enumerable: true,
|
|
1941
|
+
get: function () {
|
|
1942
|
+
return _bcts_components.XID;
|
|
1943
|
+
}
|
|
1944
|
+
});
|
|
1929
1945
|
exports.XIDDocument = XIDDocument;
|
|
1930
1946
|
exports.XIDError = XIDError;
|
|
1931
1947
|
exports.XIDErrorCode = XIDErrorCode;
|
|
@@ -1938,5 +1954,5 @@ exports.privilegeToEnvelope = privilegeToEnvelope;
|
|
|
1938
1954
|
exports.privilegeToKnownValue = privilegeToKnownValue;
|
|
1939
1955
|
exports.registerXIDDocumentClass = registerXIDDocumentClass;
|
|
1940
1956
|
return exports;
|
|
1941
|
-
})({}, bctsKnownValues, bctsEnvelope,
|
|
1957
|
+
})({}, bctsComponents, bctsKnownValues, bctsEnvelope, bctsProvenanceMark, bctsDcbor);
|
|
1942
1958
|
//# sourceMappingURL=index.iife.js.map
|