@did-btcr2/method 0.54.1 → 0.55.0
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/.tsbuildinfo +1 -1
- package/dist/browser.js +3 -3
- package/dist/browser.mjs +3 -3
- package/dist/cjs/index.js +165 -164
- package/dist/esm/utils/appendix.js +3 -2
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/types/utils/appendix.d.ts +1 -1
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/utils/appendix.ts +3 -2
package/dist/cjs/index.js
CHANGED
|
@@ -694,15 +694,16 @@ var BeaconFactory = class {
|
|
|
694
694
|
|
|
695
695
|
// src/core/beacon/signal-discovery.ts
|
|
696
696
|
var import_bitcoin3 = require("@did-btcr2/bitcoin");
|
|
697
|
-
var
|
|
697
|
+
var import_common9 = require("@did-btcr2/common");
|
|
698
698
|
|
|
699
699
|
// src/core/beacon/utils.ts
|
|
700
700
|
var import_bitcoin2 = require("@did-btcr2/bitcoin");
|
|
701
|
-
var
|
|
701
|
+
var import_common8 = require("@did-btcr2/common");
|
|
702
702
|
var import_btc_signer2 = require("@scure/btc-signer");
|
|
703
703
|
|
|
704
704
|
// src/utils/appendix.ts
|
|
705
705
|
var import_dids = require("@web5/dids");
|
|
706
|
+
var import_common6 = require("@did-btcr2/common");
|
|
706
707
|
var Appendix = class _Appendix {
|
|
707
708
|
/**
|
|
708
709
|
* Extracts a DID fragment from a given input
|
|
@@ -744,10 +745,10 @@ var Appendix = class _Appendix {
|
|
|
744
745
|
* Extracts the verification methods from a given DID Document.
|
|
745
746
|
* @param didDocument The DID Document to extract the verification methods from
|
|
746
747
|
* @returns An array of DidVerificationMethod objects
|
|
747
|
-
* @throws
|
|
748
|
+
* @throws {DidDocumentError} if the didDocument is not provided
|
|
748
749
|
*/
|
|
749
750
|
static getVerificationMethods(didDocument) {
|
|
750
|
-
if (!didDocument) throw new
|
|
751
|
+
if (!didDocument) throw new import_common6.DidDocumentError(`Required parameter missing: 'didDocument'`);
|
|
751
752
|
const verificationMethods = [];
|
|
752
753
|
verificationMethods.push(...didDocument.verificationMethod?.filter(_Appendix.isDidVerificationMethod) ?? []);
|
|
753
754
|
Object.keys(import_dids.DidVerificationRelationship).forEach((relationship) => {
|
|
@@ -851,7 +852,7 @@ var Appendix = class _Appendix {
|
|
|
851
852
|
};
|
|
852
853
|
|
|
853
854
|
// src/core/identifier.ts
|
|
854
|
-
var
|
|
855
|
+
var import_common7 = require("@did-btcr2/common");
|
|
855
856
|
var import_keypair = require("@did-btcr2/keypair");
|
|
856
857
|
var import_base = require("@scure/base");
|
|
857
858
|
var Identifier = class _Identifier {
|
|
@@ -871,33 +872,33 @@ var Identifier = class _Identifier {
|
|
|
871
872
|
*/
|
|
872
873
|
static encode(genesisBytes, options) {
|
|
873
874
|
const { idType, version = 1, network = "bitcoin" } = options;
|
|
874
|
-
if (!(idType in
|
|
875
|
-
throw new
|
|
875
|
+
if (!(idType in import_common7.IdentifierTypes)) {
|
|
876
|
+
throw new import_common7.IdentifierError('Expected "idType" to be "KEY" or "EXTERNAL"', import_common7.INVALID_DID, { idType });
|
|
876
877
|
}
|
|
877
878
|
if (version !== 1) {
|
|
878
|
-
throw new
|
|
879
|
+
throw new import_common7.IdentifierError('Expected "version" to be 1', import_common7.INVALID_DID, { version });
|
|
879
880
|
}
|
|
880
881
|
if (typeof network !== "string") {
|
|
881
|
-
throw new
|
|
882
|
+
throw new import_common7.IdentifierError('Expected "network" to be a known network name', import_common7.INVALID_DID, { network });
|
|
882
883
|
}
|
|
883
|
-
const networkValue =
|
|
884
|
+
const networkValue = import_common7.BitcoinNetworkNames[network];
|
|
884
885
|
if (networkValue === void 0) {
|
|
885
|
-
throw new
|
|
886
|
+
throw new import_common7.IdentifierError('Invalid "network" name', import_common7.INVALID_DID, { network });
|
|
886
887
|
}
|
|
887
888
|
if (idType === "KEY") {
|
|
888
889
|
try {
|
|
889
890
|
new import_keypair.CompressedSecp256k1PublicKey(genesisBytes);
|
|
890
891
|
} catch {
|
|
891
|
-
throw new
|
|
892
|
+
throw new import_common7.IdentifierError(
|
|
892
893
|
'Expected "genesisBytes" to be a valid compressed secp256k1 public key',
|
|
893
|
-
|
|
894
|
+
import_common7.INVALID_DID,
|
|
894
895
|
{ genesisBytes }
|
|
895
896
|
);
|
|
896
897
|
}
|
|
897
898
|
} else if (genesisBytes.length !== 32) {
|
|
898
|
-
throw new
|
|
899
|
+
throw new import_common7.IdentifierError(
|
|
899
900
|
'Expected "genesisBytes" to be a 32-byte hash for EXTERNAL identifiers',
|
|
900
|
-
|
|
901
|
+
import_common7.INVALID_DID,
|
|
901
902
|
{ genesisBytes }
|
|
902
903
|
);
|
|
903
904
|
}
|
|
@@ -917,50 +918,50 @@ var Identifier = class _Identifier {
|
|
|
917
918
|
static decode(identifier) {
|
|
918
919
|
const components = identifier.split(":");
|
|
919
920
|
if (components.length !== 3) {
|
|
920
|
-
throw new
|
|
921
|
+
throw new import_common7.IdentifierError(`Invalid did: ${identifier}`, import_common7.INVALID_DID, { identifier });
|
|
921
922
|
}
|
|
922
923
|
const [scheme, method, encoded] = components;
|
|
923
924
|
if (scheme !== "did") {
|
|
924
|
-
throw new
|
|
925
|
+
throw new import_common7.IdentifierError(`Invalid did: ${identifier}`, import_common7.INVALID_DID, { identifier });
|
|
925
926
|
}
|
|
926
927
|
if (method !== "btcr2") {
|
|
927
|
-
throw new
|
|
928
|
+
throw new import_common7.IdentifierError(`Invalid did method: ${method}`, import_common7.METHOD_NOT_SUPPORTED, { identifier });
|
|
928
929
|
}
|
|
929
930
|
if (!encoded) {
|
|
930
|
-
throw new
|
|
931
|
+
throw new import_common7.IdentifierError(`Invalid method-specific id: ${identifier}`, import_common7.INVALID_DID, { identifier });
|
|
931
932
|
}
|
|
932
933
|
const { prefix: hrp, bytes: dataBytes } = import_base.bech32m.decodeToBytes(encoded);
|
|
933
934
|
if (!["x", "k"].includes(hrp)) {
|
|
934
|
-
throw new
|
|
935
|
+
throw new import_common7.IdentifierError(`Invalid hrp: ${hrp}`, import_common7.INVALID_DID, { identifier });
|
|
935
936
|
}
|
|
936
937
|
if (!dataBytes || dataBytes.length < 1) {
|
|
937
|
-
throw new
|
|
938
|
+
throw new import_common7.IdentifierError(`Failed to decode id: ${encoded}`, import_common7.INVALID_DID, { identifier });
|
|
938
939
|
}
|
|
939
940
|
const idType = hrp === "k" ? "KEY" : "EXTERNAL";
|
|
940
941
|
const btcr2Version = dataBytes[0] >>> 4;
|
|
941
942
|
if (btcr2Version !== 0) {
|
|
942
|
-
throw new
|
|
943
|
+
throw new import_common7.IdentifierError(`Invalid btcr2_version (expected 0): ${btcr2Version}`, import_common7.INVALID_DID, { identifier });
|
|
943
944
|
}
|
|
944
945
|
const version = 1;
|
|
945
946
|
const networkValue = dataBytes[0] & 15;
|
|
946
|
-
const networkName =
|
|
947
|
+
const networkName = import_common7.BitcoinNetworkNames[networkValue];
|
|
947
948
|
let network;
|
|
948
949
|
if (typeof networkName === "string") {
|
|
949
950
|
network = networkName;
|
|
950
951
|
} else if (networkValue >= 12 && networkValue <= 14) {
|
|
951
952
|
network = networkValue - 11;
|
|
952
953
|
} else {
|
|
953
|
-
throw new
|
|
954
|
+
throw new import_common7.IdentifierError(`Invalid network: ${networkValue}`, import_common7.INVALID_DID, { identifier });
|
|
954
955
|
}
|
|
955
956
|
const genesisBytes = dataBytes.slice(1);
|
|
956
957
|
if (idType === "KEY") {
|
|
957
958
|
try {
|
|
958
959
|
new import_keypair.CompressedSecp256k1PublicKey(genesisBytes);
|
|
959
960
|
} catch {
|
|
960
|
-
throw new
|
|
961
|
+
throw new import_common7.IdentifierError(`Invalid genesisBytes: ${genesisBytes}`, import_common7.INVALID_DID, { identifier });
|
|
961
962
|
}
|
|
962
963
|
} else if (genesisBytes.length !== 32) {
|
|
963
|
-
throw new
|
|
964
|
+
throw new import_common7.IdentifierError(`Invalid genesisBytes: ${genesisBytes}`, import_common7.INVALID_DID, { identifier });
|
|
964
965
|
}
|
|
965
966
|
return { idType, hrp, version, network, genesisBytes };
|
|
966
967
|
}
|
|
@@ -989,9 +990,9 @@ var Identifier = class _Identifier {
|
|
|
989
990
|
static getPublicKey(did) {
|
|
990
991
|
const { idType, genesisBytes } = _Identifier.decode(did);
|
|
991
992
|
if (idType !== "KEY") {
|
|
992
|
-
throw new
|
|
993
|
+
throw new import_common7.IdentifierError(
|
|
993
994
|
`Cannot extract public key from EXTERNAL DID: ${did}. EXTERNAL DIDs encode a document hash, not a public key.`,
|
|
994
|
-
|
|
995
|
+
import_common7.INVALID_DID,
|
|
995
996
|
{ did, idType }
|
|
996
997
|
);
|
|
997
998
|
}
|
|
@@ -1022,7 +1023,7 @@ var BeaconUtils = class {
|
|
|
1022
1023
|
*/
|
|
1023
1024
|
static parseBitcoinAddress(uri) {
|
|
1024
1025
|
if (!uri.startsWith("bitcoin:")) {
|
|
1025
|
-
throw new
|
|
1026
|
+
throw new import_common8.MethodError("Invalid Bitcoin URI format", "BEACON_SERVICE_ERROR", { uri });
|
|
1026
1027
|
}
|
|
1027
1028
|
return uri.replace("bitcoin:", "").split("?")[0];
|
|
1028
1029
|
}
|
|
@@ -1103,7 +1104,7 @@ var BeaconUtils = class {
|
|
|
1103
1104
|
const p2wpkhAddr = (0, import_btc_signer2.p2wpkh)(publicKey, network).address;
|
|
1104
1105
|
const p2trAddr = (0, import_btc_signer2.p2tr)(publicKey.slice(1, 33), void 0, network).address;
|
|
1105
1106
|
if (!p2pkhAddr || !p2wpkhAddr || !p2trAddr) {
|
|
1106
|
-
throw new
|
|
1107
|
+
throw new import_common8.DidMethodError("Failed to generate bitcoin addresses");
|
|
1107
1108
|
}
|
|
1108
1109
|
return [
|
|
1109
1110
|
{
|
|
@@ -1228,7 +1229,7 @@ var BeaconSignalDiscovery = class {
|
|
|
1228
1229
|
}
|
|
1229
1230
|
const rpc = bitcoin.rpc;
|
|
1230
1231
|
if (!rpc) {
|
|
1231
|
-
throw new
|
|
1232
|
+
throw new import_common9.ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin);
|
|
1232
1233
|
}
|
|
1233
1234
|
const targetHeight = await rpc.getBlockCount();
|
|
1234
1235
|
const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
|
|
@@ -1295,27 +1296,27 @@ var BeaconSignalDiscovery = class {
|
|
|
1295
1296
|
};
|
|
1296
1297
|
|
|
1297
1298
|
// src/core/did-sender-resolver.ts
|
|
1298
|
-
var
|
|
1299
|
+
var import_common14 = require("@did-btcr2/common");
|
|
1299
1300
|
var import_cryptosuite3 = require("@did-btcr2/cryptosuite");
|
|
1300
1301
|
var import_keypair4 = require("@did-btcr2/keypair");
|
|
1301
1302
|
|
|
1302
1303
|
// src/core/resolver.ts
|
|
1303
1304
|
var import_bitcoin5 = require("@did-btcr2/bitcoin");
|
|
1304
|
-
var
|
|
1305
|
+
var import_common13 = require("@did-btcr2/common");
|
|
1305
1306
|
var import_cryptosuite2 = require("@did-btcr2/cryptosuite");
|
|
1306
1307
|
var import_keypair3 = require("@did-btcr2/keypair");
|
|
1307
1308
|
|
|
1308
1309
|
// src/did-btcr2.ts
|
|
1309
|
-
var
|
|
1310
|
+
var import_common12 = require("@did-btcr2/common");
|
|
1310
1311
|
var import_dids2 = require("@web5/dids");
|
|
1311
1312
|
|
|
1312
1313
|
// src/core/updater.ts
|
|
1313
|
-
var
|
|
1314
|
+
var import_common11 = require("@did-btcr2/common");
|
|
1314
1315
|
var import_cryptosuite = require("@did-btcr2/cryptosuite");
|
|
1315
1316
|
|
|
1316
1317
|
// src/utils/did-document.ts
|
|
1317
1318
|
var import_bitcoin4 = require("@did-btcr2/bitcoin");
|
|
1318
|
-
var
|
|
1319
|
+
var import_common10 = require("@did-btcr2/common");
|
|
1319
1320
|
var import_keypair2 = require("@did-btcr2/keypair");
|
|
1320
1321
|
var import_utils4 = require("@web5/dids/utils");
|
|
1321
1322
|
var import_btc_signer3 = require("@scure/btc-signer");
|
|
@@ -1343,16 +1344,16 @@ var DidVerificationMethod = class {
|
|
|
1343
1344
|
secretKeyMultibase;
|
|
1344
1345
|
constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }) {
|
|
1345
1346
|
if (type !== MULTIKEY_VERIFICATION_METHOD_TYPE) {
|
|
1346
|
-
throw new
|
|
1347
|
+
throw new import_common10.DidDocumentError(
|
|
1347
1348
|
`Invalid verification method: type must be "${MULTIKEY_VERIFICATION_METHOD_TYPE}"`,
|
|
1348
|
-
|
|
1349
|
+
import_common10.INVALID_DID_DOCUMENT,
|
|
1349
1350
|
{ id, type }
|
|
1350
1351
|
);
|
|
1351
1352
|
}
|
|
1352
1353
|
if (typeof publicKeyMultibase !== "string" || !publicKeyMultibase.startsWith(MULTIKEY_PUBLIC_KEY_MULTIBASE_PREFIX)) {
|
|
1353
|
-
throw new
|
|
1354
|
+
throw new import_common10.DidDocumentError(
|
|
1354
1355
|
`Invalid verification method: publicKeyMultibase must start with "${MULTIKEY_PUBLIC_KEY_MULTIBASE_PREFIX}"`,
|
|
1355
|
-
|
|
1356
|
+
import_common10.INVALID_DID_DOCUMENT,
|
|
1356
1357
|
{ id, publicKeyMultibase }
|
|
1357
1358
|
);
|
|
1358
1359
|
}
|
|
@@ -1382,20 +1383,20 @@ var DidDocument = class _DidDocument {
|
|
|
1382
1383
|
deactivated;
|
|
1383
1384
|
constructor(document) {
|
|
1384
1385
|
if (!document.id) {
|
|
1385
|
-
throw new
|
|
1386
|
+
throw new import_common10.DidDocumentError("DID Document must have an id", import_common10.INVALID_DID_DOCUMENT, document);
|
|
1386
1387
|
}
|
|
1387
|
-
const idType = document.id.includes("k1") ?
|
|
1388
|
+
const idType = document.id.includes("k1") ? import_common10.IdentifierTypes.KEY : import_common10.IdentifierTypes.EXTERNAL;
|
|
1388
1389
|
const isGenesis = document.id === ID_PLACEHOLDER_VALUE;
|
|
1389
1390
|
const { id, verificationMethod: vm, service } = document;
|
|
1390
1391
|
if (!isGenesis) {
|
|
1391
1392
|
if (!_DidDocument.isValidId(id)) {
|
|
1392
|
-
throw new
|
|
1393
|
+
throw new import_common10.DidDocumentError(`Invalid id: ${id}`, import_common10.INVALID_DID_DOCUMENT, document);
|
|
1393
1394
|
}
|
|
1394
1395
|
if (!_DidDocument.isValidVerificationMethods(vm)) {
|
|
1395
|
-
throw new
|
|
1396
|
+
throw new import_common10.DidDocumentError("Invalid verificationMethod: " + vm, import_common10.INVALID_DID_DOCUMENT, document);
|
|
1396
1397
|
}
|
|
1397
1398
|
if (!_DidDocument.isValidServices(service)) {
|
|
1398
|
-
throw new
|
|
1399
|
+
throw new import_common10.DidDocumentError("Invalid service: " + service, import_common10.INVALID_DID_DOCUMENT, document);
|
|
1399
1400
|
}
|
|
1400
1401
|
}
|
|
1401
1402
|
this.id = document.id;
|
|
@@ -1405,7 +1406,7 @@ var DidDocument = class _DidDocument {
|
|
|
1405
1406
|
"https://www.w3.org/ns/did/v1.1",
|
|
1406
1407
|
"https://btcr2.dev/context/v1"
|
|
1407
1408
|
];
|
|
1408
|
-
if (idType ===
|
|
1409
|
+
if (idType === import_common10.IdentifierTypes.KEY) {
|
|
1409
1410
|
const keyRef = `${this.id}#initialKey`;
|
|
1410
1411
|
this.authentication = document.authentication || [keyRef];
|
|
1411
1412
|
this.assertionMethod = document.assertionMethod || [keyRef];
|
|
@@ -1491,19 +1492,19 @@ var DidDocument = class _DidDocument {
|
|
|
1491
1492
|
*/
|
|
1492
1493
|
static isValid(didDocument) {
|
|
1493
1494
|
if (!this.isValidContext(didDocument?.["@context"])) {
|
|
1494
|
-
throw new
|
|
1495
|
+
throw new import_common10.DidDocumentError('Invalid "@context"', import_common10.INVALID_DID_DOCUMENT, didDocument);
|
|
1495
1496
|
}
|
|
1496
1497
|
if (!this.isValidId(didDocument?.id)) {
|
|
1497
|
-
throw new
|
|
1498
|
+
throw new import_common10.DidDocumentError('Invalid "id"', import_common10.INVALID_DID_DOCUMENT, didDocument);
|
|
1498
1499
|
}
|
|
1499
1500
|
if (!this.isValidVerificationMethods(didDocument?.verificationMethod)) {
|
|
1500
|
-
throw new
|
|
1501
|
+
throw new import_common10.DidDocumentError('Invalid "verificationMethod"', import_common10.INVALID_DID_DOCUMENT, didDocument);
|
|
1501
1502
|
}
|
|
1502
1503
|
if (!this.isValidServices(didDocument?.service)) {
|
|
1503
|
-
throw new
|
|
1504
|
+
throw new import_common10.DidDocumentError('Invalid "service"', import_common10.INVALID_DID_DOCUMENT, didDocument);
|
|
1504
1505
|
}
|
|
1505
1506
|
if (!this.isValidVerificationRelationships(didDocument)) {
|
|
1506
|
-
throw new
|
|
1507
|
+
throw new import_common10.DidDocumentError("Invalid verification relationships", import_common10.INVALID_DID_DOCUMENT, didDocument);
|
|
1507
1508
|
}
|
|
1508
1509
|
return true;
|
|
1509
1510
|
}
|
|
@@ -1591,16 +1592,16 @@ var DidDocument = class _DidDocument {
|
|
|
1591
1592
|
*/
|
|
1592
1593
|
validateGenesis() {
|
|
1593
1594
|
if (this.id !== ID_PLACEHOLDER_VALUE) {
|
|
1594
|
-
throw new
|
|
1595
|
+
throw new import_common10.DidDocumentError("Invalid GenesisDocument ID", import_common10.INVALID_DID_DOCUMENT, this);
|
|
1595
1596
|
}
|
|
1596
1597
|
if (!this.verificationMethod.every((vm) => vm.id.includes(ID_PLACEHOLDER_VALUE) && vm.controller === ID_PLACEHOLDER_VALUE)) {
|
|
1597
|
-
throw new
|
|
1598
|
+
throw new import_common10.DidDocumentError("Invalid GenesisDocument verificationMethod", import_common10.INVALID_DID_DOCUMENT, this);
|
|
1598
1599
|
}
|
|
1599
1600
|
if (!this.service.every((svc) => svc.id.includes(ID_PLACEHOLDER_VALUE))) {
|
|
1600
|
-
throw new
|
|
1601
|
+
throw new import_common10.DidDocumentError("Invalid GenesisDocument service", import_common10.INVALID_DID_DOCUMENT, this);
|
|
1601
1602
|
}
|
|
1602
1603
|
if (!_DidDocument.isValidVerificationRelationships(this)) {
|
|
1603
|
-
throw new
|
|
1604
|
+
throw new import_common10.DidDocumentError("Invalid GenesisDocument assertionMethod", import_common10.INVALID_DID_DOCUMENT, this);
|
|
1604
1605
|
}
|
|
1605
1606
|
return true;
|
|
1606
1607
|
}
|
|
@@ -1610,7 +1611,7 @@ var DidDocument = class _DidDocument {
|
|
|
1610
1611
|
*/
|
|
1611
1612
|
toIntermediate() {
|
|
1612
1613
|
if (this.id.includes("k1")) {
|
|
1613
|
-
throw new
|
|
1614
|
+
throw new import_common10.DidDocumentError("Cannot convert a key identifier to an intermediate document", import_common10.INVALID_DID_DOCUMENT, this);
|
|
1614
1615
|
}
|
|
1615
1616
|
return new GenesisDocument(this);
|
|
1616
1617
|
}
|
|
@@ -1635,7 +1636,7 @@ var GenesisDocument = class _GenesisDocument extends DidDocument {
|
|
|
1635
1636
|
* @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
|
|
1636
1637
|
*/
|
|
1637
1638
|
static fromDidDocument(didDocument) {
|
|
1638
|
-
const intermediateDocument =
|
|
1639
|
+
const intermediateDocument = import_common10.JSONUtils.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE);
|
|
1639
1640
|
return new _GenesisDocument(intermediateDocument);
|
|
1640
1641
|
}
|
|
1641
1642
|
/**
|
|
@@ -1692,7 +1693,7 @@ var GenesisDocument = class _GenesisDocument extends DidDocument {
|
|
|
1692
1693
|
* @returns {Bytes} The genesis bytes.
|
|
1693
1694
|
*/
|
|
1694
1695
|
static toGenesisBytes(genesisDocument) {
|
|
1695
|
-
return (0,
|
|
1696
|
+
return (0, import_common10.hash)((0, import_common10.canonicalize)(genesisDocument));
|
|
1696
1697
|
}
|
|
1697
1698
|
};
|
|
1698
1699
|
|
|
@@ -1737,26 +1738,26 @@ var Updater = class _Updater {
|
|
|
1737
1738
|
patch: patches,
|
|
1738
1739
|
targetHash: "",
|
|
1739
1740
|
targetVersionId: sourceVersionId + 1,
|
|
1740
|
-
sourceHash: (0,
|
|
1741
|
+
sourceHash: (0, import_common11.canonicalHash)(sourceDocument)
|
|
1741
1742
|
};
|
|
1742
|
-
const targetDocument =
|
|
1743
|
+
const targetDocument = import_common11.JSONPatch.apply(sourceDocument, patches);
|
|
1743
1744
|
if (targetDocument.id !== sourceDocument.id) {
|
|
1744
|
-
throw new
|
|
1745
|
+
throw new import_common11.UpdateError(
|
|
1745
1746
|
`Patches must not change the DID document id (source "${sourceDocument.id}" to target "${targetDocument.id}").`,
|
|
1746
|
-
|
|
1747
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1747
1748
|
{ sourceId: sourceDocument.id, targetId: targetDocument.id }
|
|
1748
1749
|
);
|
|
1749
1750
|
}
|
|
1750
1751
|
try {
|
|
1751
1752
|
DidDocument.isValid(targetDocument);
|
|
1752
1753
|
} catch (error) {
|
|
1753
|
-
throw new
|
|
1754
|
+
throw new import_common11.UpdateError(
|
|
1754
1755
|
"Error validating targetDocument: " + (error instanceof Error ? error.message : String(error)),
|
|
1755
|
-
|
|
1756
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1756
1757
|
targetDocument
|
|
1757
1758
|
);
|
|
1758
1759
|
}
|
|
1759
|
-
unsignedUpdate.targetHash = (0,
|
|
1760
|
+
unsignedUpdate.targetHash = (0, import_common11.canonicalHash)(targetDocument);
|
|
1760
1761
|
return unsignedUpdate;
|
|
1761
1762
|
}
|
|
1762
1763
|
/**
|
|
@@ -1770,18 +1771,18 @@ var Updater = class _Updater {
|
|
|
1770
1771
|
*/
|
|
1771
1772
|
static sign(did, unsignedUpdate, verificationMethod, signer) {
|
|
1772
1773
|
if (!did.startsWith("did:btcr2:")) {
|
|
1773
|
-
throw new
|
|
1774
|
+
throw new import_common11.UpdateError(
|
|
1774
1775
|
`Expected a did:btcr2 identifier for the root capability; got "${did}".`,
|
|
1775
|
-
|
|
1776
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1776
1777
|
{ did }
|
|
1777
1778
|
);
|
|
1778
1779
|
}
|
|
1779
1780
|
const controller = verificationMethod.controller;
|
|
1780
1781
|
const hashIdx = verificationMethod.id.indexOf("#");
|
|
1781
1782
|
if (hashIdx < 0) {
|
|
1782
|
-
throw new
|
|
1783
|
+
throw new import_common11.UpdateError(
|
|
1783
1784
|
`Verification method id must contain a fragment (e.g. "${verificationMethod.id}#initialKey"); got "${verificationMethod.id}".`,
|
|
1784
|
-
|
|
1785
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1785
1786
|
{ verificationMethodId: verificationMethod.id }
|
|
1786
1787
|
);
|
|
1787
1788
|
}
|
|
@@ -1789,9 +1790,9 @@ var Updater = class _Updater {
|
|
|
1789
1790
|
const multikey = import_cryptosuite.SchnorrMultikey.fromSigner(id, controller, signer);
|
|
1790
1791
|
const signerKey = multikey.publicKey.multibase.encoded;
|
|
1791
1792
|
if (verificationMethod.publicKeyMultibase && signerKey !== verificationMethod.publicKeyMultibase) {
|
|
1792
|
-
throw new
|
|
1793
|
+
throw new import_common11.UpdateError(
|
|
1793
1794
|
`Signing key does not match verification method "${verificationMethod.id}": the signer's public key differs from the method's published publicKeyMultibase.`,
|
|
1794
|
-
|
|
1795
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1795
1796
|
{
|
|
1796
1797
|
verificationMethodId: verificationMethod.id,
|
|
1797
1798
|
expected: verificationMethod.publicKeyMultibase,
|
|
@@ -1908,16 +1909,16 @@ var Updater = class _Updater {
|
|
|
1908
1909
|
switch (need.kind) {
|
|
1909
1910
|
case "NeedSigningKey": {
|
|
1910
1911
|
if (this.#state.phase !== "Sign") {
|
|
1911
|
-
throw new
|
|
1912
|
+
throw new import_common11.UpdateError(
|
|
1912
1913
|
`Cannot provide NeedSigningKey: updater phase is ${this.#state.phase}, expected Sign.`,
|
|
1913
|
-
|
|
1914
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1914
1915
|
{ phase: this.#state.phase }
|
|
1915
1916
|
);
|
|
1916
1917
|
}
|
|
1917
1918
|
if (!data) {
|
|
1918
|
-
throw new
|
|
1919
|
+
throw new import_common11.UpdateError(
|
|
1919
1920
|
"NeedSigningKey requires a Signer.",
|
|
1920
|
-
|
|
1921
|
+
import_common11.INVALID_DID_UPDATE
|
|
1921
1922
|
);
|
|
1922
1923
|
}
|
|
1923
1924
|
const unsignedUpdate = this.#state.unsignedUpdate;
|
|
@@ -1932,18 +1933,18 @@ var Updater = class _Updater {
|
|
|
1932
1933
|
}
|
|
1933
1934
|
case "NeedFunding": {
|
|
1934
1935
|
if (this.#state.phase !== "Fund") {
|
|
1935
|
-
throw new
|
|
1936
|
+
throw new import_common11.UpdateError(
|
|
1936
1937
|
`Cannot provide NeedFunding: updater phase is ${this.#state.phase}, expected Fund.`,
|
|
1937
|
-
|
|
1938
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1938
1939
|
{ phase: this.#state.phase }
|
|
1939
1940
|
);
|
|
1940
1941
|
}
|
|
1941
1942
|
if (data !== void 0) {
|
|
1942
1943
|
const proof = data;
|
|
1943
1944
|
if (typeof proof.utxoCount !== "number" || !Number.isFinite(proof.utxoCount) || proof.utxoCount < 1) {
|
|
1944
|
-
throw new
|
|
1945
|
+
throw new import_common11.UpdateError(
|
|
1945
1946
|
`NeedFunding proof must have utxoCount >= 1; got ${String(proof.utxoCount)}.`,
|
|
1946
|
-
|
|
1947
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1947
1948
|
{ utxoCount: proof.utxoCount }
|
|
1948
1949
|
);
|
|
1949
1950
|
}
|
|
@@ -1957,9 +1958,9 @@ var Updater = class _Updater {
|
|
|
1957
1958
|
}
|
|
1958
1959
|
case "NeedBroadcast": {
|
|
1959
1960
|
if (this.#state.phase !== "Broadcast") {
|
|
1960
|
-
throw new
|
|
1961
|
+
throw new import_common11.UpdateError(
|
|
1961
1962
|
`Cannot provide NeedBroadcast: updater phase is ${this.#state.phase}, expected Broadcast.`,
|
|
1962
|
-
|
|
1963
|
+
import_common11.INVALID_DID_UPDATE,
|
|
1963
1964
|
{ phase: this.#state.phase }
|
|
1964
1965
|
);
|
|
1965
1966
|
}
|
|
@@ -1995,9 +1996,9 @@ var DidBtcr2 = class {
|
|
|
1995
1996
|
static create(genesisBytes, options) {
|
|
1996
1997
|
const { idType, version = 1, network = "bitcoin" } = options || {};
|
|
1997
1998
|
if (!idType) {
|
|
1998
|
-
throw new
|
|
1999
|
+
throw new import_common12.MethodError(
|
|
1999
2000
|
"idType is required for creating a did:btcr2 identifier",
|
|
2000
|
-
|
|
2001
|
+
import_common12.INVALID_DID_DOCUMENT,
|
|
2001
2002
|
options
|
|
2002
2003
|
);
|
|
2003
2004
|
}
|
|
@@ -2027,7 +2028,7 @@ var DidBtcr2 = class {
|
|
|
2027
2028
|
static resolve(did, resolutionOptions = {}) {
|
|
2028
2029
|
const didComponents = Identifier.decode(did);
|
|
2029
2030
|
const sidecarData = Resolver.sidecarData(resolutionOptions.sidecar);
|
|
2030
|
-
const currentDocument = didComponents.hrp ===
|
|
2031
|
+
const currentDocument = didComponents.hrp === import_common12.IdentifierHrp.k ? Resolver.deterministic(didComponents) : null;
|
|
2031
2032
|
return new Resolver(didComponents, sidecarData, currentDocument, {
|
|
2032
2033
|
versionId: resolutionOptions.versionId,
|
|
2033
2034
|
versionTime: resolutionOptions.versionTime,
|
|
@@ -2066,39 +2067,39 @@ var DidBtcr2 = class {
|
|
|
2066
2067
|
beaconId
|
|
2067
2068
|
}) {
|
|
2068
2069
|
if (!sourceDocument.capabilityInvocation?.some((vr) => vr === verificationMethodId)) {
|
|
2069
|
-
throw new
|
|
2070
|
+
throw new import_common12.UpdateError(
|
|
2070
2071
|
"Invalid verificationMethodId: not authorized for capabilityInvocation",
|
|
2071
|
-
|
|
2072
|
+
import_common12.INVALID_DID_DOCUMENT,
|
|
2072
2073
|
sourceDocument
|
|
2073
2074
|
);
|
|
2074
2075
|
}
|
|
2075
2076
|
const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
|
|
2076
2077
|
if (!verificationMethod) {
|
|
2077
|
-
throw new
|
|
2078
|
+
throw new import_common12.UpdateError(
|
|
2078
2079
|
"Invalid verificationMethod: not found in source document",
|
|
2079
|
-
|
|
2080
|
+
import_common12.INVALID_DID_DOCUMENT,
|
|
2080
2081
|
{ sourceDocument, verificationMethodId }
|
|
2081
2082
|
);
|
|
2082
2083
|
}
|
|
2083
2084
|
if (verificationMethod.type !== MULTIKEY_VERIFICATION_METHOD_TYPE) {
|
|
2084
|
-
throw new
|
|
2085
|
+
throw new import_common12.UpdateError(
|
|
2085
2086
|
`Invalid verificationMethod: verificationMethod.type must be "${MULTIKEY_VERIFICATION_METHOD_TYPE}"`,
|
|
2086
|
-
|
|
2087
|
+
import_common12.INVALID_DID_DOCUMENT,
|
|
2087
2088
|
verificationMethod
|
|
2088
2089
|
);
|
|
2089
2090
|
}
|
|
2090
2091
|
if (!verificationMethod.publicKeyMultibase?.startsWith(MULTIKEY_PUBLIC_KEY_MULTIBASE_PREFIX)) {
|
|
2091
|
-
throw new
|
|
2092
|
+
throw new import_common12.UpdateError(
|
|
2092
2093
|
`Invalid verificationMethodId: publicKeyMultibase prefix must start with "${MULTIKEY_PUBLIC_KEY_MULTIBASE_PREFIX}"`,
|
|
2093
|
-
|
|
2094
|
+
import_common12.INVALID_DID_DOCUMENT,
|
|
2094
2095
|
verificationMethod
|
|
2095
2096
|
);
|
|
2096
2097
|
}
|
|
2097
2098
|
const beaconService = sourceDocument.service.filter((service) => service.id === beaconId).filter((service) => !!service).shift();
|
|
2098
2099
|
if (!beaconService) {
|
|
2099
|
-
throw new
|
|
2100
|
+
throw new import_common12.UpdateError(
|
|
2100
2101
|
"No beacon service found for provided beaconId",
|
|
2101
|
-
|
|
2102
|
+
import_common12.INVALID_DID_UPDATE,
|
|
2102
2103
|
{ sourceDocument, beaconId }
|
|
2103
2104
|
);
|
|
2104
2105
|
}
|
|
@@ -2124,7 +2125,7 @@ var DidBtcr2 = class {
|
|
|
2124
2125
|
methodId ??= "#initialKey";
|
|
2125
2126
|
const parsedDid = import_dids2.Did.parse(didDocument.id);
|
|
2126
2127
|
if (parsedDid && parsedDid.method !== this.methodName) {
|
|
2127
|
-
throw new
|
|
2128
|
+
throw new import_common12.MethodError(`Method not supported: ${parsedDid.method}`, import_common12.METHOD_NOT_SUPPORTED, { identifier: didDocument.id });
|
|
2128
2129
|
}
|
|
2129
2130
|
const verificationMethod = didDocument.verificationMethod?.find(
|
|
2130
2131
|
(vm) => Appendix.extractDidFragment(vm.id) === (Appendix.extractDidFragment(methodId) ?? Appendix.extractDidFragment(didDocument.assertionMethod?.[0]))
|
|
@@ -2244,14 +2245,14 @@ var Resolver = class _Resolver {
|
|
|
2244
2245
|
* @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
|
|
2245
2246
|
*/
|
|
2246
2247
|
static external(didComponents, genesisDocument) {
|
|
2247
|
-
const genesisDocumentHash = (0,
|
|
2248
|
+
const genesisDocumentHash = (0, import_common13.canonicalHashBytes)(genesisDocument);
|
|
2248
2249
|
if (!(0, import_utils6.equalBytes)(didComponents.genesisBytes, genesisDocumentHash)) {
|
|
2249
|
-
throw new
|
|
2250
|
+
throw new import_common13.ResolveError(
|
|
2250
2251
|
`Initial document mismatch: genesisBytes !== genesisDocumentHash`,
|
|
2251
|
-
|
|
2252
|
+
import_common13.INVALID_DID_DOCUMENT,
|
|
2252
2253
|
{
|
|
2253
|
-
genesisBytes: (0,
|
|
2254
|
-
genesisDocumentHash: (0,
|
|
2254
|
+
genesisBytes: (0, import_common13.encode)(didComponents.genesisBytes, "hex"),
|
|
2255
|
+
genesisDocumentHash: (0, import_common13.encode)(genesisDocumentHash, "hex")
|
|
2255
2256
|
}
|
|
2256
2257
|
);
|
|
2257
2258
|
}
|
|
@@ -2270,17 +2271,17 @@ var Resolver = class _Resolver {
|
|
|
2270
2271
|
const updateMap = /* @__PURE__ */ new Map();
|
|
2271
2272
|
if (sidecar.updates?.length)
|
|
2272
2273
|
for (const update of sidecar.updates) {
|
|
2273
|
-
updateMap.set((0,
|
|
2274
|
+
updateMap.set((0, import_common13.canonicalHash)(update, { encoding: "hex" }), update);
|
|
2274
2275
|
}
|
|
2275
2276
|
const casMap = /* @__PURE__ */ new Map();
|
|
2276
2277
|
if (sidecar.casUpdates?.length)
|
|
2277
2278
|
for (const update of sidecar.casUpdates) {
|
|
2278
|
-
casMap.set((0,
|
|
2279
|
+
casMap.set((0, import_common13.canonicalHash)(update, { encoding: "hex" }), update);
|
|
2279
2280
|
}
|
|
2280
2281
|
const smtMap = /* @__PURE__ */ new Map();
|
|
2281
2282
|
if (sidecar.smtProofs?.length)
|
|
2282
2283
|
for (const proof of sidecar.smtProofs) {
|
|
2283
|
-
smtMap.set((0,
|
|
2284
|
+
smtMap.set((0, import_common13.encode)((0, import_common13.decode)(proof.id, "base64urlnopad"), "hex"), proof);
|
|
2284
2285
|
}
|
|
2285
2286
|
return { updateMap, casMap, smtMap };
|
|
2286
2287
|
}
|
|
@@ -2311,38 +2312,38 @@ var Resolver = class _Resolver {
|
|
|
2311
2312
|
}
|
|
2312
2313
|
};
|
|
2313
2314
|
for (const [update, block] of updates) {
|
|
2314
|
-
const currentDocumentHash = (0,
|
|
2315
|
-
const blocktime =
|
|
2316
|
-
response.metadata.updated =
|
|
2315
|
+
const currentDocumentHash = (0, import_common13.canonicalHashBytes)(response.didDocument);
|
|
2316
|
+
const blocktime = import_common13.DateUtils.blocktimeToTimestamp(block.time);
|
|
2317
|
+
response.metadata.updated = import_common13.DateUtils.toISOStringNonFractional(blocktime);
|
|
2317
2318
|
response.metadata.confirmations = block.confirmations;
|
|
2318
2319
|
if (update.targetVersionId <= currentVersionId) {
|
|
2319
2320
|
this.confirmDuplicate(update, updateHashHistory);
|
|
2320
2321
|
continue;
|
|
2321
2322
|
}
|
|
2322
2323
|
if (versionTime) {
|
|
2323
|
-
if (blocktime >
|
|
2324
|
+
if (blocktime > import_common13.DateUtils.dateStringToTimestamp(versionTime)) {
|
|
2324
2325
|
return response;
|
|
2325
2326
|
}
|
|
2326
2327
|
}
|
|
2327
2328
|
if (update.targetVersionId === currentVersionId + 1) {
|
|
2328
|
-
const sourceHashBytes = (0,
|
|
2329
|
+
const sourceHashBytes = (0, import_common13.decode)(update.sourceHash, "base64urlnopad");
|
|
2329
2330
|
if (!(0, import_utils6.equalBytes)(sourceHashBytes, currentDocumentHash)) {
|
|
2330
|
-
throw new
|
|
2331
|
+
throw new import_common13.ResolveError(
|
|
2331
2332
|
`Hash mismatch: update.sourceHash !== currentDocumentHash`,
|
|
2332
|
-
|
|
2333
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2333
2334
|
{
|
|
2334
2335
|
sourceHash: update.sourceHash,
|
|
2335
|
-
currentDocumentHash: (0,
|
|
2336
|
+
currentDocumentHash: (0, import_common13.encode)(currentDocumentHash, "hex")
|
|
2336
2337
|
}
|
|
2337
2338
|
);
|
|
2338
2339
|
}
|
|
2339
2340
|
response.didDocument = this.applyUpdate(response.didDocument, update);
|
|
2340
|
-
const unsignedUpdate =
|
|
2341
|
-
updateHashHistory.push((0,
|
|
2341
|
+
const unsignedUpdate = import_common13.JSONUtils.deleteKeys(update, ["proof"]);
|
|
2342
|
+
updateHashHistory.push((0, import_common13.canonicalHashBytes)(unsignedUpdate));
|
|
2342
2343
|
} else {
|
|
2343
|
-
throw new
|
|
2344
|
+
throw new import_common13.ResolveError(
|
|
2344
2345
|
`Version Id Mismatch: targetVersionId cannot be > currentVersionId + 1`,
|
|
2345
|
-
|
|
2346
|
+
import_common13.LATE_PUBLISHING_ERROR,
|
|
2346
2347
|
{
|
|
2347
2348
|
targetVersionId: update.targetVersionId,
|
|
2348
2349
|
currentVersionId: currentVersionId + 1
|
|
@@ -2371,19 +2372,19 @@ var Resolver = class _Resolver {
|
|
|
2371
2372
|
*/
|
|
2372
2373
|
static confirmDuplicate(update, updateHashHistory) {
|
|
2373
2374
|
if (!Number.isInteger(update.targetVersionId) || update.targetVersionId < 2) {
|
|
2374
|
-
throw new
|
|
2375
|
+
throw new import_common13.ResolveError(
|
|
2375
2376
|
`Invalid duplicate: targetVersionId must be an integer >= 2`,
|
|
2376
|
-
|
|
2377
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2377
2378
|
{ targetVersionId: update.targetVersionId }
|
|
2378
2379
|
);
|
|
2379
2380
|
}
|
|
2380
2381
|
const { proof: _, ...unsignedUpdate } = update;
|
|
2381
|
-
const unsignedUpdateHash = (0,
|
|
2382
|
+
const unsignedUpdateHash = (0, import_common13.canonicalHashBytes)(unsignedUpdate);
|
|
2382
2383
|
const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
|
|
2383
2384
|
if (historicalUpdateHash === void 0) {
|
|
2384
|
-
throw new
|
|
2385
|
+
throw new import_common13.ResolveError(
|
|
2385
2386
|
`Invalid duplicate: no applied update in history for targetVersionId`,
|
|
2386
|
-
|
|
2387
|
+
import_common13.LATE_PUBLISHING_ERROR,
|
|
2387
2388
|
{
|
|
2388
2389
|
targetVersionId: update.targetVersionId,
|
|
2389
2390
|
historyLength: updateHashHistory.length
|
|
@@ -2391,12 +2392,12 @@ var Resolver = class _Resolver {
|
|
|
2391
2392
|
);
|
|
2392
2393
|
}
|
|
2393
2394
|
if (!(0, import_utils6.equalBytes)(historicalUpdateHash, unsignedUpdateHash)) {
|
|
2394
|
-
throw new
|
|
2395
|
+
throw new import_common13.ResolveError(
|
|
2395
2396
|
`Invalid duplicate: unsigned update hash does not match historical hash`,
|
|
2396
|
-
|
|
2397
|
+
import_common13.LATE_PUBLISHING_ERROR,
|
|
2397
2398
|
{
|
|
2398
|
-
unsignedUpdateHash: (0,
|
|
2399
|
-
historicalHash: (0,
|
|
2399
|
+
unsignedUpdateHash: (0, import_common13.encode)(unsignedUpdateHash, "hex"),
|
|
2400
|
+
historicalHash: (0, import_common13.encode)(historicalUpdateHash, "hex")
|
|
2400
2401
|
}
|
|
2401
2402
|
);
|
|
2402
2403
|
}
|
|
@@ -2411,42 +2412,42 @@ var Resolver = class _Resolver {
|
|
|
2411
2412
|
static applyUpdate(currentDocument, update) {
|
|
2412
2413
|
const capabilityId = update.proof?.capability;
|
|
2413
2414
|
if (!capabilityId) {
|
|
2414
|
-
throw new
|
|
2415
|
+
throw new import_common13.ResolveError("No root capability found in update", import_common13.INVALID_DID_UPDATE, update);
|
|
2415
2416
|
}
|
|
2416
2417
|
const rootCapability = Appendix.dereferenceZcapId(capabilityId);
|
|
2417
2418
|
const { invocationTarget, controller: rootController } = rootCapability;
|
|
2418
2419
|
if (![invocationTarget, rootController].every((id) => id === currentDocument.id)) {
|
|
2419
|
-
throw new
|
|
2420
|
+
throw new import_common13.ResolveError(
|
|
2420
2421
|
"Invalid root capability",
|
|
2421
|
-
|
|
2422
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2422
2423
|
{ rootCapability, currentDocument }
|
|
2423
2424
|
);
|
|
2424
2425
|
}
|
|
2425
2426
|
const verificationMethodId = update.proof?.verificationMethod;
|
|
2426
2427
|
if (!verificationMethodId) {
|
|
2427
|
-
throw new
|
|
2428
|
+
throw new import_common13.ResolveError("No verificationMethod found in update", import_common13.INVALID_DID_UPDATE, update);
|
|
2428
2429
|
}
|
|
2429
2430
|
const vm = DidBtcr2.getSigningMethod(currentDocument, verificationMethodId);
|
|
2430
2431
|
const multikey = import_cryptosuite2.SchnorrMultikey.fromVerificationMethod(vm);
|
|
2431
2432
|
const cryptosuite = new import_cryptosuite2.BIP340Cryptosuite(multikey);
|
|
2432
|
-
const canonicalUpdate = (0,
|
|
2433
|
+
const canonicalUpdate = (0, import_common13.canonicalize)(update);
|
|
2433
2434
|
const diProof = new import_cryptosuite2.BIP340DataIntegrityProof(cryptosuite);
|
|
2434
2435
|
const verificationResult = diProof.verifyProof(canonicalUpdate, "capabilityInvocation");
|
|
2435
2436
|
if (!verificationResult.verified) {
|
|
2436
|
-
throw new
|
|
2437
|
+
throw new import_common13.ResolveError(
|
|
2437
2438
|
"Invalid update: proof not verified",
|
|
2438
|
-
|
|
2439
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2439
2440
|
verificationResult
|
|
2440
2441
|
);
|
|
2441
2442
|
}
|
|
2442
|
-
const updatedDocument =
|
|
2443
|
+
const updatedDocument = import_common13.JSONPatch.apply(currentDocument, update.patch);
|
|
2443
2444
|
DidDocument.validate(updatedDocument);
|
|
2444
|
-
const currentDocumentHash = (0,
|
|
2445
|
-
const updateTargetHash = (0,
|
|
2445
|
+
const currentDocumentHash = (0, import_common13.canonicalHashBytes)(updatedDocument);
|
|
2446
|
+
const updateTargetHash = (0, import_common13.decode)(update.targetHash);
|
|
2446
2447
|
if (!(0, import_utils6.equalBytes)(updateTargetHash, currentDocumentHash)) {
|
|
2447
|
-
throw new
|
|
2448
|
+
throw new import_common13.ResolveError(
|
|
2448
2449
|
`Invalid update: update.targetHash !== currentDocumentHash`,
|
|
2449
|
-
|
|
2450
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2450
2451
|
{ updateTargetHash, currentDocumentHash }
|
|
2451
2452
|
);
|
|
2452
2453
|
}
|
|
@@ -2474,7 +2475,7 @@ var Resolver = class _Resolver {
|
|
|
2474
2475
|
this.#phase = "BeaconDiscovery" /* BeaconDiscovery */;
|
|
2475
2476
|
continue;
|
|
2476
2477
|
}
|
|
2477
|
-
const genesisHash = (0,
|
|
2478
|
+
const genesisHash = (0, import_common13.encode)(this.#didComponents.genesisBytes, "hex");
|
|
2478
2479
|
return {
|
|
2479
2480
|
status: "action-required",
|
|
2480
2481
|
needs: [{ kind: "NeedGenesisDocument", genesisHash }]
|
|
@@ -2543,9 +2544,9 @@ var Resolver = class _Resolver {
|
|
|
2543
2544
|
});
|
|
2544
2545
|
if (hasNewServices) {
|
|
2545
2546
|
if (++this.#discoveryRounds > this.#maxDiscoveryRounds) {
|
|
2546
|
-
throw new
|
|
2547
|
+
throw new import_common13.ResolveError(
|
|
2547
2548
|
`Exceeded the configured maximum of ${this.#maxDiscoveryRounds} beacon-discovery rounds. Raise or remove ResolutionOptions.maxDiscoveryRounds to resolve this DID.`,
|
|
2548
|
-
|
|
2549
|
+
import_common13.INTERNAL_ERROR,
|
|
2549
2550
|
{ maxDiscoveryRounds: this.#maxDiscoveryRounds, discoveryRounds: this.#discoveryRounds }
|
|
2550
2551
|
);
|
|
2551
2552
|
}
|
|
@@ -2576,9 +2577,9 @@ var Resolver = class _Resolver {
|
|
|
2576
2577
|
switch (need.kind) {
|
|
2577
2578
|
case "NeedGenesisDocument": {
|
|
2578
2579
|
if (!isRecord(data)) {
|
|
2579
|
-
throw new
|
|
2580
|
+
throw new import_common13.ResolveError(
|
|
2580
2581
|
"Provided data for NeedGenesisDocument must be a document object.",
|
|
2581
|
-
|
|
2582
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2582
2583
|
{ kind: need.kind }
|
|
2583
2584
|
);
|
|
2584
2585
|
}
|
|
@@ -2587,9 +2588,9 @@ var Resolver = class _Resolver {
|
|
|
2587
2588
|
}
|
|
2588
2589
|
case "NeedBeaconSignals": {
|
|
2589
2590
|
if (!(data instanceof Map)) {
|
|
2590
|
-
throw new
|
|
2591
|
+
throw new import_common13.ResolveError(
|
|
2591
2592
|
"Provided data for NeedBeaconSignals must be a Map of beacon services to signals.",
|
|
2592
|
-
|
|
2593
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2593
2594
|
{ kind: need.kind }
|
|
2594
2595
|
);
|
|
2595
2596
|
}
|
|
@@ -2600,17 +2601,17 @@ var Resolver = class _Resolver {
|
|
|
2600
2601
|
}
|
|
2601
2602
|
case "NeedCASAnnouncement": {
|
|
2602
2603
|
if (!isCASAnnouncement(data)) {
|
|
2603
|
-
throw new
|
|
2604
|
+
throw new import_common13.ResolveError(
|
|
2604
2605
|
"Provided data for NeedCASAnnouncement is not a CAS announcement.",
|
|
2605
|
-
|
|
2606
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2606
2607
|
{ kind: need.kind }
|
|
2607
2608
|
);
|
|
2608
2609
|
}
|
|
2609
|
-
const announcementHash = (0,
|
|
2610
|
+
const announcementHash = (0, import_common13.canonicalHash)(data, { encoding: "hex" });
|
|
2610
2611
|
if (announcementHash !== need.announcementHash) {
|
|
2611
|
-
throw new
|
|
2612
|
+
throw new import_common13.ResolveError(
|
|
2612
2613
|
`CAS announcement hash mismatch: expected ${need.announcementHash}, got ${announcementHash}.`,
|
|
2613
|
-
|
|
2614
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2614
2615
|
{ expected: need.announcementHash, actual: announcementHash }
|
|
2615
2616
|
);
|
|
2616
2617
|
}
|
|
@@ -2619,17 +2620,17 @@ var Resolver = class _Resolver {
|
|
|
2619
2620
|
}
|
|
2620
2621
|
case "NeedSignedUpdate": {
|
|
2621
2622
|
if (!isSignedBTCR2Update(data)) {
|
|
2622
|
-
throw new
|
|
2623
|
+
throw new import_common13.ResolveError(
|
|
2623
2624
|
"Provided data for NeedSignedUpdate is not a signed BTCR2 update.",
|
|
2624
|
-
|
|
2625
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2625
2626
|
{ kind: need.kind }
|
|
2626
2627
|
);
|
|
2627
2628
|
}
|
|
2628
|
-
const updateHash = (0,
|
|
2629
|
+
const updateHash = (0, import_common13.canonicalHash)(data, { encoding: "hex" });
|
|
2629
2630
|
if (updateHash !== need.updateHash) {
|
|
2630
|
-
throw new
|
|
2631
|
+
throw new import_common13.ResolveError(
|
|
2631
2632
|
`Signed update hash mismatch: expected ${need.updateHash}, got ${updateHash}.`,
|
|
2632
|
-
|
|
2633
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2633
2634
|
{ expected: need.updateHash, actual: updateHash }
|
|
2634
2635
|
);
|
|
2635
2636
|
}
|
|
@@ -2638,17 +2639,17 @@ var Resolver = class _Resolver {
|
|
|
2638
2639
|
}
|
|
2639
2640
|
case "NeedSMTProof": {
|
|
2640
2641
|
if (!isSMTProof(data)) {
|
|
2641
|
-
throw new
|
|
2642
|
+
throw new import_common13.ResolveError(
|
|
2642
2643
|
"Provided data for NeedSMTProof is not an SMT proof.",
|
|
2643
|
-
|
|
2644
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2644
2645
|
{ kind: need.kind }
|
|
2645
2646
|
);
|
|
2646
2647
|
}
|
|
2647
|
-
const proofIdHex = (0,
|
|
2648
|
+
const proofIdHex = (0, import_common13.encode)((0, import_common13.decode)(data.id, "base64urlnopad"), "hex");
|
|
2648
2649
|
if (proofIdHex !== need.smtRootHash) {
|
|
2649
|
-
throw new
|
|
2650
|
+
throw new import_common13.ResolveError(
|
|
2650
2651
|
`SMT proof root hash mismatch: expected ${need.smtRootHash}, got ${proofIdHex}`,
|
|
2651
|
-
|
|
2652
|
+
import_common13.INVALID_DID_UPDATE,
|
|
2652
2653
|
{ expected: need.smtRootHash, actual: proofIdHex }
|
|
2653
2654
|
);
|
|
2654
2655
|
}
|
|
@@ -2663,17 +2664,17 @@ var Resolver = class _Resolver {
|
|
|
2663
2664
|
function getAggregationCommunicationKey(document) {
|
|
2664
2665
|
const invocation = document.capabilityInvocation?.[0];
|
|
2665
2666
|
if (invocation === void 0) {
|
|
2666
|
-
throw new
|
|
2667
|
+
throw new import_common14.DidDocumentError(
|
|
2667
2668
|
"Cannot derive aggregation communication key: capabilityInvocation is absent",
|
|
2668
|
-
|
|
2669
|
+
import_common14.INVALID_DID_DOCUMENT,
|
|
2669
2670
|
{ id: document.id }
|
|
2670
2671
|
);
|
|
2671
2672
|
}
|
|
2672
2673
|
const vm = typeof invocation === "string" ? document.verificationMethod?.find((method) => method.id === invocation) : invocation;
|
|
2673
2674
|
if (!vm) {
|
|
2674
|
-
throw new
|
|
2675
|
+
throw new import_common14.DidDocumentError(
|
|
2675
2676
|
`Cannot derive aggregation communication key: capabilityInvocation[0] "${invocation}" does not resolve to a verification method`,
|
|
2676
|
-
|
|
2677
|
+
import_common14.INVALID_DID_DOCUMENT,
|
|
2677
2678
|
{ id: document.id, invocation }
|
|
2678
2679
|
);
|
|
2679
2680
|
}
|
|
@@ -2695,12 +2696,12 @@ function resolveBtcr2SenderPk(did, opts) {
|
|
|
2695
2696
|
}
|
|
2696
2697
|
|
|
2697
2698
|
// src/utils/did-document-builder.ts
|
|
2698
|
-
var
|
|
2699
|
+
var import_common15 = require("@did-btcr2/common");
|
|
2699
2700
|
var DidDocumentBuilder = class {
|
|
2700
2701
|
document = {};
|
|
2701
2702
|
constructor(initialDocument) {
|
|
2702
2703
|
if (!initialDocument.id) {
|
|
2703
|
-
throw new
|
|
2704
|
+
throw new import_common15.DidDocumentError('Missing required "id" property', import_common15.INVALID_DID_DOCUMENT, initialDocument);
|
|
2704
2705
|
}
|
|
2705
2706
|
this.document.id = initialDocument.id;
|
|
2706
2707
|
this.document.verificationMethod = initialDocument.verificationMethod ?? [];
|