@bcts/xid 1.0.0-alpha.12 → 1.0.0-alpha.14
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 +120 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -34
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +56 -34
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +121 -93
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +117 -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 +85 -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
616
|
*/
|
|
617
|
-
|
|
618
|
-
|
|
617
|
+
static newWithPrivateKeyBase(privateKeyBase) {
|
|
618
|
+
const privateKeys = privateKeyBase.ed25519PrivateKeys();
|
|
619
|
+
const publicKeys = privateKeyBase.ed25519PublicKeys();
|
|
620
|
+
return Key.newWithPrivateKeys(privateKeys, publicKeys);
|
|
619
621
|
}
|
|
620
622
|
/**
|
|
621
|
-
* Get the
|
|
623
|
+
* Get the public keys.
|
|
622
624
|
*/
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
625
|
+
publicKeys() {
|
|
626
|
+
return this._publicKeys;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Get the private keys, if available and decrypted.
|
|
630
|
+
*/
|
|
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,40 @@ 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();
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Get the encryption key (encapsulation public key) for this document.
|
|
1604
|
+
*
|
|
1605
|
+
* Prefers the inception key for encryption. If no inception key is available,
|
|
1606
|
+
* falls back to the first key in the document.
|
|
1607
|
+
*/
|
|
1608
|
+
encryptionKey() {
|
|
1609
|
+
const inceptionKey = this.inceptionKey();
|
|
1610
|
+
if (inceptionKey !== void 0) return inceptionKey.publicKeys().encapsulationPublicKey();
|
|
1611
|
+
const firstKey = this._keys.values().next().value;
|
|
1612
|
+
if (firstKey !== void 0) return firstKey.publicKeys().encapsulationPublicKey();
|
|
1586
1613
|
}
|
|
1587
1614
|
/**
|
|
1588
1615
|
* Remove the inception key from the document.
|
|
@@ -1687,13 +1714,11 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1687
1714
|
checkServiceConsistency(service) {
|
|
1688
1715
|
if (service.keyReferences().size === 0 && service.delegateReferences().size === 0) throw XIDError.noReferences(service.uri());
|
|
1689
1716
|
for (const keyRef of service.keyReferences()) {
|
|
1690
|
-
const
|
|
1691
|
-
const ref = _bcts_components.Reference.hash(refBytes);
|
|
1717
|
+
const ref = _bcts_components.Reference.fromHex(keyRef);
|
|
1692
1718
|
if (this.findKeyByReference(ref) === void 0) throw XIDError.unknownKeyReference(keyRef, service.uri());
|
|
1693
1719
|
}
|
|
1694
1720
|
for (const delegateRef of service.delegateReferences()) {
|
|
1695
|
-
const
|
|
1696
|
-
const ref = _bcts_components.Reference.hash(refBytes);
|
|
1721
|
+
const ref = _bcts_components.Reference.fromHex(delegateRef);
|
|
1697
1722
|
if (this.findDelegateByReference(ref) === void 0) throw XIDError.unknownDelegateReference(delegateRef, service.uri());
|
|
1698
1723
|
}
|
|
1699
1724
|
if (service.permissions().allow.size === 0) throw XIDError.noPermissions(service.uri());
|
|
@@ -1701,8 +1726,8 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1701
1726
|
/**
|
|
1702
1727
|
* Check if any service references the given key.
|
|
1703
1728
|
*/
|
|
1704
|
-
servicesReferenceKey(
|
|
1705
|
-
const keyRef =
|
|
1729
|
+
servicesReferenceKey(publicKeys) {
|
|
1730
|
+
const keyRef = publicKeys.reference().toHex();
|
|
1706
1731
|
for (const service of this._services.values()) if (service.keyReferences().has(keyRef)) return true;
|
|
1707
1732
|
return false;
|
|
1708
1733
|
}
|
|
@@ -1781,13 +1806,18 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1781
1806
|
case "inception": {
|
|
1782
1807
|
const inceptionKey = this.inceptionKey();
|
|
1783
1808
|
if (inceptionKey === void 0) throw XIDError.missingInceptionKey();
|
|
1784
|
-
const
|
|
1785
|
-
if (
|
|
1786
|
-
envelope = envelope.
|
|
1809
|
+
const privateKeys = inceptionKey.privateKeys();
|
|
1810
|
+
if (privateKeys === void 0) throw XIDError.missingInceptionKey();
|
|
1811
|
+
envelope = envelope.sign(privateKeys);
|
|
1812
|
+
break;
|
|
1813
|
+
}
|
|
1814
|
+
case "privateKeyBase": {
|
|
1815
|
+
const privateKeys = signingOptions.privateKeyBase.ed25519PrivateKeys();
|
|
1816
|
+
envelope = envelope.sign(privateKeys);
|
|
1787
1817
|
break;
|
|
1788
1818
|
}
|
|
1789
|
-
case "
|
|
1790
|
-
envelope = envelope.
|
|
1819
|
+
case "privateKeys":
|
|
1820
|
+
envelope = envelope.sign(signingOptions.privateKeys);
|
|
1791
1821
|
break;
|
|
1792
1822
|
case "none":
|
|
1793
1823
|
default: break;
|
|
@@ -1814,8 +1844,8 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1814
1844
|
const doc = XIDDocument.fromEnvelopeInner(unwrapped, password);
|
|
1815
1845
|
const inceptionKey = doc.inceptionKey();
|
|
1816
1846
|
if (inceptionKey === void 0) throw XIDError.missingInceptionKey();
|
|
1817
|
-
if (!envelopeExt.hasSignatureFrom(inceptionKey.
|
|
1818
|
-
if (!doc.isInceptionKey(inceptionKey.
|
|
1847
|
+
if (!envelopeExt.hasSignatureFrom(inceptionKey.publicKeys())) throw XIDError.signatureVerificationFailed();
|
|
1848
|
+
if (!doc.isInceptionKey(inceptionKey.publicKeys())) throw XIDError.invalidXid();
|
|
1819
1849
|
return doc;
|
|
1820
1850
|
}
|
|
1821
1851
|
}
|
|
@@ -1869,7 +1899,7 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1869
1899
|
* Create a signed envelope.
|
|
1870
1900
|
*/
|
|
1871
1901
|
toSignedEnvelope(signingKey) {
|
|
1872
|
-
return this.toEnvelope(XIDPrivateKeyOptions.Omit, XIDGeneratorOptions.Omit, { type: "none" }).
|
|
1902
|
+
return this.toEnvelope(XIDPrivateKeyOptions.Omit, XIDGeneratorOptions.Omit, { type: "none" }).sign(signingKey);
|
|
1873
1903
|
}
|
|
1874
1904
|
/**
|
|
1875
1905
|
* Get the reference for this document.
|
|
@@ -1897,19 +1927,11 @@ var bctsXid = (function(exports, _bcts_known_values, _bcts_envelope, _bcts_compo
|
|
|
1897
1927
|
}
|
|
1898
1928
|
};
|
|
1899
1929
|
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
1930
|
function bytesEqual(a, b) {
|
|
1906
1931
|
if (a.length !== b.length) return false;
|
|
1907
1932
|
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
1908
1933
|
return true;
|
|
1909
1934
|
}
|
|
1910
|
-
function hashPublicKey(publicKeyBase) {
|
|
1911
|
-
return _bcts_components.Reference.hash(publicKeyBase.data()).getDigest().toData();
|
|
1912
|
-
}
|
|
1913
1935
|
|
|
1914
1936
|
//#endregion
|
|
1915
1937
|
//#region src/index.ts
|
|
@@ -1926,6 +1948,12 @@ exports.Provenance = Provenance;
|
|
|
1926
1948
|
exports.Service = Service;
|
|
1927
1949
|
exports.Shared = Shared;
|
|
1928
1950
|
exports.VERSION = VERSION;
|
|
1951
|
+
Object.defineProperty(exports, 'XID', {
|
|
1952
|
+
enumerable: true,
|
|
1953
|
+
get: function () {
|
|
1954
|
+
return _bcts_components.XID;
|
|
1955
|
+
}
|
|
1956
|
+
});
|
|
1929
1957
|
exports.XIDDocument = XIDDocument;
|
|
1930
1958
|
exports.XIDError = XIDError;
|
|
1931
1959
|
exports.XIDErrorCode = XIDErrorCode;
|
|
@@ -1938,5 +1966,5 @@ exports.privilegeToEnvelope = privilegeToEnvelope;
|
|
|
1938
1966
|
exports.privilegeToKnownValue = privilegeToKnownValue;
|
|
1939
1967
|
exports.registerXIDDocumentClass = registerXIDDocumentClass;
|
|
1940
1968
|
return exports;
|
|
1941
|
-
})({}, bctsKnownValues, bctsEnvelope,
|
|
1969
|
+
})({}, bctsComponents, bctsKnownValues, bctsEnvelope, bctsProvenanceMark, bctsDcbor);
|
|
1942
1970
|
//# sourceMappingURL=index.iife.js.map
|