@did-btcr2/method 0.23.0 → 0.25.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/README.md +96 -50
- package/dist/browser.js +36332 -37280
- package/dist/browser.mjs +36331 -37279
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/coordinator.js +40 -44
- package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/participant.js +35 -38
- package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js +3 -4
- package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/cjs/core/beacon/beacon.js.map +1 -1
- package/dist/cjs/core/beacon/cas-beacon.js +119 -7
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/factory.js +1 -1
- package/dist/cjs/core/beacon/factory.js.map +1 -1
- package/dist/cjs/core/beacon/{singleton.js → singleton-beacon.js} +19 -27
- package/dist/cjs/core/beacon/singleton-beacon.js.map +1 -0
- package/dist/cjs/core/beacon/smt-beacon.js +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
- package/dist/cjs/core/identifier.js +1 -1
- package/dist/cjs/core/identifier.js.map +1 -1
- package/dist/{esm/core/resolve.js → cjs/core/resolver.js} +244 -92
- package/dist/cjs/core/resolver.js.map +1 -0
- package/dist/cjs/core/update.js +7 -7
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +34 -94
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/did-document.js +9 -19
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/coordinator.js +40 -44
- package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/participant.js +35 -38
- package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +3 -4
- package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/esm/core/beacon/beacon.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +119 -7
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/factory.js +1 -1
- package/dist/esm/core/beacon/factory.js.map +1 -1
- package/dist/esm/core/beacon/{singleton.js → singleton-beacon.js} +19 -27
- package/dist/esm/core/beacon/singleton-beacon.js.map +1 -0
- package/dist/esm/core/beacon/smt-beacon.js +1 -1
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/identifier.js +1 -1
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/{cjs/core/resolve.js → esm/core/resolver.js} +244 -92
- package/dist/esm/core/resolver.js.map +1 -0
- package/dist/esm/core/update.js +7 -7
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +34 -94
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/did-document.js +9 -19
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +2 -2
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +4 -3
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +5 -3
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/error.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/communication/service.d.ts +3 -2
- package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/coordinator.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/participant.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +1 -0
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/session/status.d.ts +1 -0
- package/dist/types/core/beacon/beacon.d.ts +10 -4
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +27 -7
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +1 -0
- package/dist/types/core/beacon/factory.d.ts +1 -0
- package/dist/types/core/beacon/interfaces.d.ts +1 -0
- package/dist/types/core/beacon/signal-discovery.d.ts +1 -0
- package/dist/types/core/beacon/{singleton.d.ts → singleton-beacon.d.ts} +7 -5
- package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/smt-beacon.d.ts +5 -3
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/utils.d.ts +1 -0
- package/dist/types/core/identifier.d.ts +1 -0
- package/dist/types/core/interfaces.d.ts +6 -15
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolver.d.ts +167 -0
- package/dist/types/core/resolver.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +1 -0
- package/dist/types/core/update.d.ts +4 -3
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +17 -16
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +1 -0
- package/dist/types/utils/did-document-builder.d.ts +1 -0
- package/dist/types/utils/did-document.d.ts +2 -6
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +1 -1
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +4 -3
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +4 -3
- package/src/core/beacon/aggregation/communication/service.ts +2 -2
- package/src/core/beacon/aggregation/coordinator.ts +40 -44
- package/src/core/beacon/aggregation/participant.ts +38 -40
- package/src/core/beacon/aggregation/session/index.ts +3 -4
- package/src/core/beacon/beacon.ts +9 -5
- package/src/core/beacon/cas-beacon.ts +156 -10
- package/src/core/beacon/factory.ts +1 -1
- package/src/core/beacon/{singleton.ts → singleton-beacon.ts} +20 -36
- package/src/core/beacon/smt-beacon.ts +4 -3
- package/src/core/identifier.ts +1 -1
- package/src/core/interfaces.ts +5 -16
- package/src/core/resolver.ts +706 -0
- package/src/core/update.ts +9 -9
- package/src/did-btcr2.ts +37 -130
- package/src/index.ts +2 -3
- package/src/utils/did-document.ts +10 -18
- package/dist/cjs/core/beacon/singleton.js.map +0 -1
- package/dist/cjs/core/resolve.js.map +0 -1
- package/dist/cjs/utils/general.js +0 -195
- package/dist/cjs/utils/general.js.map +0 -1
- package/dist/esm/core/beacon/singleton.js.map +0 -1
- package/dist/esm/core/resolve.js.map +0 -1
- package/dist/esm/utils/general.js +0 -195
- package/dist/esm/utils/general.js.map +0 -1
- package/dist/types/core/beacon/singleton.d.ts.map +0 -1
- package/dist/types/core/resolve.d.ts +0 -92
- package/dist/types/core/resolve.d.ts.map +0 -1
- package/dist/types/utils/general.d.ts +0 -85
- package/dist/types/utils/general.d.ts.map +0 -1
- package/src/core/resolve.ts +0 -474
- package/src/utils/general.ts +0 -204
|
@@ -1,25 +1,81 @@
|
|
|
1
1
|
import { getNetwork } from '@did-btcr2/bitcoin';
|
|
2
|
-
import {
|
|
2
|
+
import { canonicalHash, canonicalize, DateUtils, encode as encodeHash, decode as decodeHash, INVALID_DID_DOCUMENT, INVALID_DID_UPDATE, JSONPatch, JSONUtils, LATE_PUBLISHING_ERROR, ResolveError } from '@did-btcr2/common';
|
|
3
3
|
import { BIP340Cryptosuite, BIP340DataIntegrityProof, SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
4
4
|
import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
5
|
-
import { bytesToHex } from '@noble/hashes/utils';
|
|
6
5
|
import { DidBtcr2 } from '../did-btcr2.js';
|
|
7
6
|
import { Appendix } from '../utils/appendix.js';
|
|
8
7
|
import { DidDocument, ID_PLACEHOLDER_VALUE } from '../utils/did-document.js';
|
|
9
8
|
import { BeaconFactory } from './beacon/factory.js';
|
|
10
|
-
import { BeaconSignalDiscovery } from './beacon/signal-discovery.js';
|
|
11
9
|
import { BeaconUtils } from './beacon/utils.js';
|
|
12
10
|
import { Identifier } from './identifier.js';
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Resolving a did:btcr2 identifier iteratively builds a DID document by applying BTCR2 Updates
|
|
16
|
-
* to an Initial DID Document that have been committed to the Bitcoin blockchain by Authorized
|
|
17
|
-
* Beacon Signals. The Initial DID Document is either deterministically created from the DID or
|
|
18
|
-
* provided by Sidecar Data.
|
|
19
|
-
* @class Resolve
|
|
20
|
-
* @type {Resolve}
|
|
12
|
+
* Different possible Resolver states representing phases in the resolution process.
|
|
21
13
|
*/
|
|
22
|
-
|
|
14
|
+
var ResolverPhase;
|
|
15
|
+
(function (ResolverPhase) {
|
|
16
|
+
ResolverPhase["GenesisDocument"] = "GenesisDocument";
|
|
17
|
+
ResolverPhase["BeaconDiscovery"] = "BeaconDiscovery";
|
|
18
|
+
ResolverPhase["BeaconProcess"] = "BeaconProcess";
|
|
19
|
+
ResolverPhase["ApplyUpdates"] = "ApplyUpdates";
|
|
20
|
+
ResolverPhase["Complete"] = "Complete";
|
|
21
|
+
})(ResolverPhase || (ResolverPhase = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Sans-I/O state machine for did:btcr2 resolution.
|
|
24
|
+
*
|
|
25
|
+
* Created by {@link DidBtcr2.resolve} (the factory). The caller drives resolution
|
|
26
|
+
* by repeatedly calling {@link resolve} and {@link provide}:
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const resolver = DidBtcr2.resolve(did, { sidecar });
|
|
30
|
+
* let state = resolver.resolve();
|
|
31
|
+
*
|
|
32
|
+
* while (state.status === 'action-required') {
|
|
33
|
+
* for (const need of state.needs) { ... fetch & provide ... }
|
|
34
|
+
* state = resolver.resolve();
|
|
35
|
+
* }
|
|
36
|
+
* const { didDocument, metadata } = state.result;
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* The Resolver performs **zero I/O**. All external data (Bitcoin signals, CAS
|
|
40
|
+
* data, genesis documents) flows through the advance/provide protocol.
|
|
41
|
+
*
|
|
42
|
+
* @class Resolver
|
|
43
|
+
*/
|
|
44
|
+
export class Resolver {
|
|
45
|
+
// --- Immutable inputs ---
|
|
46
|
+
#didComponents;
|
|
47
|
+
#versionId;
|
|
48
|
+
#versionTime;
|
|
49
|
+
/**
|
|
50
|
+
* The specific phase the Resolver is current in.
|
|
51
|
+
*/
|
|
52
|
+
#phase;
|
|
53
|
+
#sidecarData;
|
|
54
|
+
#currentDocument;
|
|
55
|
+
#providedGenesisDocument = null;
|
|
56
|
+
#beaconServicesSignals = new Map();
|
|
57
|
+
#processedServices = new Set();
|
|
58
|
+
#requestCache = new Set();
|
|
59
|
+
#unsortedUpdates = [];
|
|
60
|
+
#resolvedResponse = null;
|
|
61
|
+
/**
|
|
62
|
+
* @internal — Use {@link DidBtcr2.resolve} to create instances.
|
|
63
|
+
*/
|
|
64
|
+
constructor(didComponents, sidecarData, currentDocument, options) {
|
|
65
|
+
this.#didComponents = didComponents;
|
|
66
|
+
this.#sidecarData = sidecarData;
|
|
67
|
+
this.#currentDocument = currentDocument;
|
|
68
|
+
this.#versionId = options?.versionId;
|
|
69
|
+
this.#versionTime = options?.versionTime;
|
|
70
|
+
// If a genesis document was provided (from sidecar), pre-seed it for validation
|
|
71
|
+
if (options?.genesisDocument) {
|
|
72
|
+
this.#providedGenesisDocument = options.genesisDocument;
|
|
73
|
+
}
|
|
74
|
+
// If current document was established by the factory, skip GenesisDocument phase
|
|
75
|
+
this.#phase = currentDocument
|
|
76
|
+
? ResolverPhase.BeaconDiscovery
|
|
77
|
+
: ResolverPhase.GenesisDocument;
|
|
78
|
+
}
|
|
23
79
|
/**
|
|
24
80
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-secp256k1-public-key | 7.2.d.1 if genesis bytes is a secp256k1 Public Key}.
|
|
25
81
|
* @param {DidComponents} didComponents The decoded components of the did.
|
|
@@ -27,11 +83,11 @@ export class Resolve {
|
|
|
27
83
|
*/
|
|
28
84
|
static deterministic(didComponents) {
|
|
29
85
|
// Deconstruct the bytes from the given components
|
|
30
|
-
const
|
|
86
|
+
const genesisBytes = didComponents.genesisBytes;
|
|
31
87
|
// Encode the did from the didComponents
|
|
32
88
|
const did = Identifier.encode(genesisBytes, didComponents);
|
|
33
89
|
// Construct a new CompressedSecp256k1PublicKey and deconstruct the publicKey and publicKeyMultibase
|
|
34
|
-
const { multibase
|
|
90
|
+
const { multibase } = new CompressedSecp256k1PublicKey(genesisBytes);
|
|
35
91
|
// Generate the service field for the DID Document
|
|
36
92
|
const service = BeaconUtils.generateBeaconServices({
|
|
37
93
|
id: did,
|
|
@@ -45,7 +101,7 @@ export class Resolve {
|
|
|
45
101
|
id: `${did}#initialKey`,
|
|
46
102
|
type: 'Multikey',
|
|
47
103
|
controller: did,
|
|
48
|
-
publicKeyMultibase:
|
|
104
|
+
publicKeyMultibase: multibase.encoded
|
|
49
105
|
}],
|
|
50
106
|
service
|
|
51
107
|
});
|
|
@@ -53,20 +109,21 @@ export class Resolve {
|
|
|
53
109
|
/**
|
|
54
110
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-sha-256-hash | 7.2.d.2 if genesis_bytes is a SHA-256 Hash}.
|
|
55
111
|
* @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
|
|
56
|
-
* @param {
|
|
57
|
-
* @returns {
|
|
112
|
+
* @param {object} genesisDocument The genesis document for resolving the DID Document.
|
|
113
|
+
* @returns {DidDocument} The resolved DID Document object
|
|
58
114
|
* @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
|
|
59
115
|
*/
|
|
60
|
-
static
|
|
116
|
+
static external(didComponents, genesisDocument) {
|
|
117
|
+
// Encode the genesis bytes from the did components
|
|
118
|
+
const genesisBytes = encodeHash(didComponents.genesisBytes);
|
|
61
119
|
// Canonicalize and sha256 hash the currentDocument
|
|
62
|
-
const
|
|
63
|
-
const { genesisBytes } = didComponents;
|
|
120
|
+
const genesisDocumentBytes = canonicalHash(genesisDocument);
|
|
64
121
|
// If the genesisBytes do not match the hashBytes, throw an error
|
|
65
|
-
if (
|
|
66
|
-
throw new ResolveError(`Initial document mismatch: genesisBytes
|
|
122
|
+
if (genesisBytes !== genesisDocumentBytes) {
|
|
123
|
+
throw new ResolveError(`Initial document mismatch: genesisBytes !== genesisDocumentBytes`, INVALID_DID_DOCUMENT, { genesisBytes, genesisDocumentBytes });
|
|
67
124
|
}
|
|
68
125
|
// Encode the did from the didComponents
|
|
69
|
-
const did = Identifier.encode(genesisBytes, didComponents);
|
|
126
|
+
const did = Identifier.encode(decodeHash(genesisBytes), didComponents);
|
|
70
127
|
// Replace the placeholder did with the did throughout the currentDocument.
|
|
71
128
|
const currentDocument = JSON.parse(JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did));
|
|
72
129
|
// Return a W3C conformant DID Document
|
|
@@ -75,20 +132,20 @@ export class Resolve {
|
|
|
75
132
|
/**
|
|
76
133
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-sidecar-data | Process Sidecar Data}
|
|
77
134
|
* @param {Sidecar} sidecar The sidecar data to process.
|
|
78
|
-
* @returns {
|
|
135
|
+
* @returns {SidecarData} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
79
136
|
*/
|
|
80
137
|
static sidecarData(sidecar = {}) {
|
|
81
138
|
// BTCR2 Signed Updates map
|
|
82
139
|
const updateMap = new Map();
|
|
83
140
|
if (sidecar.updates?.length)
|
|
84
141
|
for (const update of sidecar.updates) {
|
|
85
|
-
updateMap.set(
|
|
142
|
+
updateMap.set(canonicalHash(update), update);
|
|
86
143
|
}
|
|
87
144
|
// CAS Announcements map
|
|
88
145
|
const casMap = new Map();
|
|
89
146
|
if (sidecar.casUpdates?.length)
|
|
90
147
|
for (const update of sidecar.casUpdates) {
|
|
91
|
-
casMap.set(
|
|
148
|
+
casMap.set(canonicalHash(update), update);
|
|
92
149
|
}
|
|
93
150
|
// SMT Proofs map
|
|
94
151
|
const smtMap = new Map();
|
|
@@ -98,68 +155,15 @@ export class Resolve {
|
|
|
98
155
|
}
|
|
99
156
|
return { updateMap, casMap, smtMap };
|
|
100
157
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#establish-current-document | 7.2.d Establish current_document}.
|
|
103
|
-
* Resolution begins by creating an Initial Did Document called current_document (Current DID Document).
|
|
104
|
-
* The current_document is iteratively patched with BTCR2 Signed Updates announced by Authorized Beacon Signals.
|
|
105
|
-
* @param {DidComponents} didComponents The decoded components of the did.
|
|
106
|
-
* @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
|
|
107
|
-
* @returns {Promise<DidDocument>} The resolved DID Document object.
|
|
108
|
-
* @throws {ResolveError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
|
|
109
|
-
*/
|
|
110
|
-
static async currentDocument(didComponents, genesisDocument) {
|
|
111
|
-
// Deconstruct the hrp from the components
|
|
112
|
-
const { hrp, genesisBytes } = didComponents;
|
|
113
|
-
// If hrp `x`, perform external resolution
|
|
114
|
-
if (hrp === IdentifierHrp.x) {
|
|
115
|
-
if (!genesisDocument)
|
|
116
|
-
throw new ResolveError('External resolution requires genesisDocument', MISSING_UPDATE_DATA, { didComponents });
|
|
117
|
-
return await this.external(didComponents, genesisDocument);
|
|
118
|
-
}
|
|
119
|
-
// Check for hrp `k`
|
|
120
|
-
if (hrp === IdentifierHrp.k) {
|
|
121
|
-
// Validate genesis bytes as a compressed secp256k1 public key
|
|
122
|
-
if (!CompressedSecp256k1PublicKey.isValid(genesisBytes)) {
|
|
123
|
-
throw new ResolveError('Deterministic resolution requires valid secp256k1 public key', INVALID_DID, { genesisBytes });
|
|
124
|
-
}
|
|
125
|
-
// Perform deterministic resolution
|
|
126
|
-
return this.deterministic(didComponents);
|
|
127
|
-
}
|
|
128
|
-
// Else, throw an error for unsupported hrp
|
|
129
|
-
throw new ResolveError(`Unsupported DID hrp ${hrp}`, INVALID_DID, { hrp });
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Finds uses the beacon services in the currentDocument to scan for onchain Beacon Signals (transactions) containing
|
|
133
|
-
* Signal Bytes (last output in OP_RETURN transaction).
|
|
134
|
-
* @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
|
|
135
|
-
* @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
136
|
-
* @param {BitcoinConnection} bitcoin The bitcoin network connection used to fetch beacon signals
|
|
137
|
-
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
|
|
138
|
-
*/
|
|
139
|
-
static async beaconSignals(beaconServices, sidecarData, bitcoin) {
|
|
140
|
-
// Discover Beacon Signals via indexer server (esplora/electrs) or full node
|
|
141
|
-
const beaconServicesSignals = bitcoin.rest
|
|
142
|
-
? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin)
|
|
143
|
-
: await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin);
|
|
144
|
-
// Process each beacon's signals in parallel
|
|
145
|
-
const promises = await Promise.all(Array.from(beaconServicesSignals.entries()).map(async ([service, signals]) => {
|
|
146
|
-
// Skip beacons with no signals
|
|
147
|
-
if (!signals.length)
|
|
148
|
-
return [];
|
|
149
|
-
// Establish a typed beacon and process its signals
|
|
150
|
-
return BeaconFactory.establish(service).processSignals(signals, sidecarData);
|
|
151
|
-
}));
|
|
152
|
-
return promises.flat();
|
|
153
|
-
}
|
|
154
158
|
/**
|
|
155
159
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-updates | 7.2.f Process updates Array}.
|
|
156
160
|
* @param {DidDocument} currentDocument The current DID Document to apply the updates to.
|
|
157
161
|
* @param {Array<[SignedBTCR2Update, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
|
|
158
162
|
* @param {string} [versionTime] The optional version time to limit updates to.
|
|
159
163
|
* @param {string} [versionId] The optional version id to limit updates to.
|
|
160
|
-
* @returns {
|
|
164
|
+
* @returns {DidResolutionResponse} The updated DID Document, number of confirmations, and version id.
|
|
161
165
|
*/
|
|
162
|
-
static
|
|
166
|
+
static updates(currentDocument, unsortedUpdates, versionTime, versionId) {
|
|
163
167
|
// Start the version number being processed at 1
|
|
164
168
|
let currentVersionId = 1;
|
|
165
169
|
// Initialize an empty array to hold the update hashes
|
|
@@ -179,9 +183,10 @@ export class Resolve {
|
|
|
179
183
|
// Iterate over each (update block) pair
|
|
180
184
|
for (const [update, block] of updates) {
|
|
181
185
|
// Get the hash of the current document
|
|
182
|
-
const currentDocumentHash =
|
|
186
|
+
const currentDocumentHash = canonicalHash(response.didDocument);
|
|
183
187
|
// Safely convert block.time to timestamp
|
|
184
188
|
const blocktime = DateUtils.blocktimeToTimestamp(block.time);
|
|
189
|
+
// TODO: How to detect if block is unconfirmed and exit gracefully or return without it
|
|
185
190
|
// Set the updated field to the blocktime of the current update
|
|
186
191
|
response.metadata.updated = DateUtils.toISOStringNonFractional(blocktime);
|
|
187
192
|
// Set confirmations to the block confirmations
|
|
@@ -207,11 +212,11 @@ export class Resolve {
|
|
|
207
212
|
throw new ResolveError(`Hash mismatch: update.sourceHash !== currentDocumentHash`, INVALID_DID_UPDATE, { sourceHash: update.sourceHash, currentDocumentHash });
|
|
208
213
|
}
|
|
209
214
|
// Apply the update to the currentDocument and set it in the response
|
|
210
|
-
response.didDocument =
|
|
215
|
+
response.didDocument = this.applyUpdate(response.didDocument, update);
|
|
211
216
|
// Create unsigned_update by removing the proof property from update.
|
|
212
217
|
const unsignedUpdate = JSONUtils.deleteKeys(update, ['proof']);
|
|
213
218
|
// Push the canonicalized unsigned update hash to the updateHashHistory
|
|
214
|
-
updateHashHistory.push(
|
|
219
|
+
updateHashHistory.push(canonicalHash(unsignedUpdate));
|
|
215
220
|
}
|
|
216
221
|
// If update.targetVersionId > currentVersionId + 1, throw LATE_PUBLISHING error
|
|
217
222
|
else if (update.targetVersionId > currentVersionId + 1) {
|
|
@@ -225,13 +230,14 @@ export class Resolve {
|
|
|
225
230
|
// Set response.versionId to be the new currentVersionId
|
|
226
231
|
response.metadata.versionId = `${currentVersionId}`;
|
|
227
232
|
// If resolutionOptions.versionId is defined and <= currentVersionId, return currentDocument
|
|
228
|
-
|
|
233
|
+
const versionIdNumber = Number(versionId);
|
|
234
|
+
if (!isNaN(versionIdNumber) && versionIdNumber <= currentVersionId) {
|
|
229
235
|
return response;
|
|
230
236
|
}
|
|
231
237
|
// Check if the current document is deactivated before further processing
|
|
232
|
-
if (
|
|
238
|
+
if (response.didDocument.deactivated) {
|
|
233
239
|
// Set the response deactivated flag to true
|
|
234
|
-
response.metadata.deactivated =
|
|
240
|
+
response.metadata.deactivated = response.didDocument.deactivated;
|
|
235
241
|
// If deactivated, stop processing further updates and return the response
|
|
236
242
|
return response;
|
|
237
243
|
}
|
|
@@ -239,17 +245,19 @@ export class Resolve {
|
|
|
239
245
|
// Return response data
|
|
240
246
|
return response;
|
|
241
247
|
}
|
|
248
|
+
// ─── Private static: update internals ──────────────────────────────
|
|
242
249
|
/**
|
|
243
250
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
|
|
244
251
|
* This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
|
|
245
252
|
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
|
|
253
|
+
* @param {string[]} updateHashHistory The accumulated hash history for comparison.
|
|
246
254
|
* @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
|
|
247
255
|
*/
|
|
248
256
|
static confirmDuplicate(update, updateHashHistory) {
|
|
249
257
|
// Create unsigned_update by removing the proof property from update.
|
|
250
258
|
const { proof: _, ...unsignedUpdate } = update;
|
|
251
259
|
// Hash unsignedUpdate with JSON Document Hashing algorithm
|
|
252
|
-
const unsignedUpdateHash =
|
|
260
|
+
const unsignedUpdateHash = canonicalHash(unsignedUpdate);
|
|
253
261
|
// Let historicalUpdateHash equal updateHashHistory[updateHashIndex].
|
|
254
262
|
const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
|
|
255
263
|
// Check if the updateHash matches the historical hash
|
|
@@ -261,10 +269,10 @@ export class Resolve {
|
|
|
261
269
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}.
|
|
262
270
|
* @param {DidDocument} currentDocument The current DID Document to apply the update to.
|
|
263
271
|
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
|
|
264
|
-
* @returns {
|
|
272
|
+
* @returns {DidDocument} The updated DID Document after applying the update.
|
|
265
273
|
* @throws {ResolveError} If the update is invalid or cannot be applied.
|
|
266
274
|
*/
|
|
267
|
-
static
|
|
275
|
+
static applyUpdate(currentDocument, update) {
|
|
268
276
|
// Get the capability id from the to update proof.
|
|
269
277
|
const capabilityId = update.proof?.capability;
|
|
270
278
|
// Since this field is optional, check that it exists
|
|
@@ -295,7 +303,7 @@ export class Resolve {
|
|
|
295
303
|
// Construct a new BIP340Cryptosuite with the SchnorrMultikey.
|
|
296
304
|
const cryptosuite = new BIP340Cryptosuite(multikey);
|
|
297
305
|
// Canonicalize the update
|
|
298
|
-
const canonicalUpdate =
|
|
306
|
+
const canonicalUpdate = canonicalize(update);
|
|
299
307
|
// Construct a DataIntegrityProof with the cryptosuite
|
|
300
308
|
const diProof = new BIP340DataIntegrityProof(cryptosuite);
|
|
301
309
|
// Call the verifyProof method
|
|
@@ -309,7 +317,7 @@ export class Resolve {
|
|
|
309
317
|
// Verify that updatedDocument is conformant to DID Core v1.1.
|
|
310
318
|
DidDocument.validate(updatedDocument);
|
|
311
319
|
// Canonicalize and hash the updatedDocument to get the currentDocumentHash.
|
|
312
|
-
const currentDocumentHash =
|
|
320
|
+
const currentDocumentHash = canonicalHash(updatedDocument);
|
|
313
321
|
// Prepare the update targetHash for comparison with currentDocumentHash.
|
|
314
322
|
const updateTargetHash = update.targetHash;
|
|
315
323
|
// Make sure the update.targetHash equals currentDocumentHash.
|
|
@@ -320,5 +328,149 @@ export class Resolve {
|
|
|
320
328
|
// Return final updatedDocument.
|
|
321
329
|
return updatedDocument;
|
|
322
330
|
}
|
|
331
|
+
// ─── Instance: state machine ───────────────────────────────────────
|
|
332
|
+
/**
|
|
333
|
+
* Advance the state machine. Returns either:
|
|
334
|
+
* - `{ status: 'action-required', needs }` — caller must provide data via {@link provide}
|
|
335
|
+
* - `{ status: 'resolved', result }` — resolution complete
|
|
336
|
+
*
|
|
337
|
+
* Analogous to Rust's `Resolver::resolve()`.
|
|
338
|
+
*/
|
|
339
|
+
resolve() {
|
|
340
|
+
// Internal loop — keeps advancing through phases until data is needed or done
|
|
341
|
+
while (true) {
|
|
342
|
+
switch (this.#phase) {
|
|
343
|
+
// Phase: GenesisDocument
|
|
344
|
+
// Only entered for EXTERNAL (x HRP) identifiers when genesis doc was not in sidecar.
|
|
345
|
+
case ResolverPhase.GenesisDocument: {
|
|
346
|
+
if (this.#providedGenesisDocument) {
|
|
347
|
+
// Genesis doc was provided — establish the current document
|
|
348
|
+
this.#currentDocument = Resolver.external(this.#didComponents, this.#providedGenesisDocument);
|
|
349
|
+
this.#providedGenesisDocument = null;
|
|
350
|
+
this.#phase = ResolverPhase.BeaconDiscovery;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
// Need genesis document from caller
|
|
354
|
+
const genesisHash = encodeHash(this.#didComponents.genesisBytes);
|
|
355
|
+
return {
|
|
356
|
+
status: 'action-required',
|
|
357
|
+
needs: [{ kind: 'NeedGenesisDocument', genesisHash }]
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
// Phase: BeaconDiscovery
|
|
361
|
+
// Extract beacon services, emit NeedBeaconSignals for addresses not yet queried.
|
|
362
|
+
case ResolverPhase.BeaconDiscovery: {
|
|
363
|
+
const beaconServices = BeaconUtils.getBeaconServices(this.#currentDocument);
|
|
364
|
+
// Filter to services whose addresses haven't been requested yet
|
|
365
|
+
const newServices = beaconServices.filter(service => {
|
|
366
|
+
const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
|
|
367
|
+
return !this.#requestCache.has(address);
|
|
368
|
+
});
|
|
369
|
+
if (newServices.length > 0) {
|
|
370
|
+
// Mark addresses as requested so we don't re-request on subsequent rounds
|
|
371
|
+
for (const service of newServices) {
|
|
372
|
+
const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
|
|
373
|
+
this.#requestCache.add(address);
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
status: 'action-required',
|
|
377
|
+
needs: [{ kind: 'NeedBeaconSignals', beaconServices: newServices }]
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
// No new beacon services to query — move to processing
|
|
381
|
+
this.#phase = ResolverPhase.BeaconProcess;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
// Phase: BeaconProcess
|
|
385
|
+
// Process each beacon's signals. Collect updates and data needs.
|
|
386
|
+
case ResolverPhase.BeaconProcess: {
|
|
387
|
+
const allNeeds = [];
|
|
388
|
+
for (const [service, signals] of this.#beaconServicesSignals) {
|
|
389
|
+
// Skip already-processed services and services with no signals
|
|
390
|
+
if (this.#processedServices.has(service.id) || !signals.length)
|
|
391
|
+
continue;
|
|
392
|
+
// Establish a typed beacon and process its signals
|
|
393
|
+
const beacon = BeaconFactory.establish(service);
|
|
394
|
+
const result = beacon.processSignals(signals, this.#sidecarData);
|
|
395
|
+
if (result.needs.length > 0) {
|
|
396
|
+
// This service has unmet data needs — collect them
|
|
397
|
+
allNeeds.push(...result.needs);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// All signals for this service resolved — collect updates, mark processed
|
|
401
|
+
this.#unsortedUpdates.push(...result.updates);
|
|
402
|
+
this.#processedServices.add(service.id);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (allNeeds.length > 0) {
|
|
406
|
+
return { status: 'action-required', needs: allNeeds };
|
|
407
|
+
}
|
|
408
|
+
this.#phase = ResolverPhase.ApplyUpdates;
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
// Phase: ApplyUpdates
|
|
412
|
+
// Apply collected updates, then check for new beacon services (multi-round).
|
|
413
|
+
case ResolverPhase.ApplyUpdates: {
|
|
414
|
+
if (this.#unsortedUpdates.length > 0) {
|
|
415
|
+
// Apply all collected updates to the current document
|
|
416
|
+
this.#resolvedResponse = Resolver.updates(this.#currentDocument, this.#unsortedUpdates, this.#versionTime, this.#versionId);
|
|
417
|
+
this.#currentDocument = this.#resolvedResponse.didDocument;
|
|
418
|
+
this.#unsortedUpdates = [];
|
|
419
|
+
// Check for new beacon services added by updates (multi-round discovery)
|
|
420
|
+
const beaconServices = BeaconUtils.getBeaconServices(this.#currentDocument);
|
|
421
|
+
const hasNewServices = beaconServices.some(service => {
|
|
422
|
+
const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
|
|
423
|
+
return !this.#requestCache.has(address);
|
|
424
|
+
});
|
|
425
|
+
if (hasNewServices) {
|
|
426
|
+
// Loop back to discover signals for new beacon services
|
|
427
|
+
this.#phase = ResolverPhase.BeaconDiscovery;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
this.#phase = ResolverPhase.Complete;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
// Phase: Complete
|
|
435
|
+
case ResolverPhase.Complete: {
|
|
436
|
+
return {
|
|
437
|
+
status: 'resolved',
|
|
438
|
+
result: this.#resolvedResponse ?? {
|
|
439
|
+
didDocument: this.#currentDocument,
|
|
440
|
+
metadata: {
|
|
441
|
+
versionId: this.#versionId ?? '1',
|
|
442
|
+
deactivated: this.#currentDocument.deactivated || false
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
provide(need, data) {
|
|
451
|
+
switch (need.kind) {
|
|
452
|
+
case 'NeedGenesisDocument': {
|
|
453
|
+
this.#providedGenesisDocument = data;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
case 'NeedBeaconSignals': {
|
|
457
|
+
const signals = data;
|
|
458
|
+
for (const [service, serviceSignals] of signals) {
|
|
459
|
+
this.#beaconServicesSignals.set(service, serviceSignals);
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
case 'NeedCASAnnouncement': {
|
|
464
|
+
const announcement = data;
|
|
465
|
+
this.#sidecarData.casMap.set(canonicalHash(announcement), announcement);
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
case 'NeedSignedUpdate': {
|
|
469
|
+
const update = data;
|
|
470
|
+
this.#sidecarData.updateMap.set(canonicalHash(update), update);
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
323
475
|
}
|
|
324
|
-
//# sourceMappingURL=
|
|
476
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../src/core/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAA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AM,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,OAAO,EAAE,CAAC;oBAC/C,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;gBAC3D,CAAC;gBACD,MAAM;YACR,CAAC;YAED,KAAK,qBAAqB,CAAC,CAAC,CAAC;gBAC3B,MAAM,YAAY,GAAG,IAAuB,CAAC;gBAC7C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC;gBACxE,MAAM;YACR,CAAC;YAED,KAAK,kBAAkB,CAAC,CAAC,CAAC;gBACxB,MAAM,MAAM,GAAG,IAAyB,CAAC;gBACzC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;gBAC/D,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/cjs/core/update.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { canonicalHash, INVALID_DID_UPDATE, JSONPatch, UpdateError } from '@did-btcr2/common';
|
|
2
2
|
import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
3
3
|
import { DidDocument } from '../utils/did-document.js';
|
|
4
4
|
import { BeaconFactory } from './beacon/factory.js';
|
|
@@ -22,10 +22,10 @@ export class Update {
|
|
|
22
22
|
* @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
|
|
23
23
|
* @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
24
24
|
* @param {number} sourceVersionId The version ID of the source document.
|
|
25
|
-
* @returns {
|
|
25
|
+
* @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
|
|
26
26
|
* @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
|
|
27
27
|
*/
|
|
28
|
-
static
|
|
28
|
+
static construct(sourceDocument, patches, sourceVersionId) {
|
|
29
29
|
// Initialize an unsigned update conformant to btcr2 spec.
|
|
30
30
|
const unsignedUpdate = {
|
|
31
31
|
'@context': [
|
|
@@ -37,7 +37,7 @@ export class Update {
|
|
|
37
37
|
patch: patches,
|
|
38
38
|
targetHash: '',
|
|
39
39
|
targetVersionId: sourceVersionId + 1,
|
|
40
|
-
sourceHash:
|
|
40
|
+
sourceHash: canonicalHash(sourceDocument),
|
|
41
41
|
};
|
|
42
42
|
// Apply all JSON patches to sourceDocument.
|
|
43
43
|
const targetDocument = JSONPatch.apply(sourceDocument, patches);
|
|
@@ -49,8 +49,8 @@ export class Update {
|
|
|
49
49
|
// If validation fails, throw an UpdateError with INVALID_DID_UPDATE.
|
|
50
50
|
throw new UpdateError('Error validating targetDocument: ' + (error instanceof Error ? error.message : String(error)), INVALID_DID_UPDATE, targetDocument);
|
|
51
51
|
}
|
|
52
|
-
// Set the targetHash by canonicalizing the targetDocument and encoding it in
|
|
53
|
-
unsignedUpdate.targetHash =
|
|
52
|
+
// Set the targetHash by canonicalizing the targetDocument and encoding it in base64url.
|
|
53
|
+
unsignedUpdate.targetHash = canonicalHash(targetDocument);
|
|
54
54
|
// Return unsignedUpdate.
|
|
55
55
|
return unsignedUpdate;
|
|
56
56
|
}
|
|
@@ -64,7 +64,7 @@ export class Update {
|
|
|
64
64
|
* @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
|
|
65
65
|
* @throws {UpdateError} if the privateKeyBytes are invalid
|
|
66
66
|
*/
|
|
67
|
-
static
|
|
67
|
+
static sign(did, unsignedUpdate, verificationMethod, secretKey) {
|
|
68
68
|
// Parse the controller from the verificationMethod
|
|
69
69
|
const controller = verificationMethod.controller;
|
|
70
70
|
// Parse the fragment from the vmId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/core/update.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3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