@did-btcr2/method 0.27.0 → 0.28.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 CHANGED
@@ -16,7 +16,8 @@ pnpm add @did-btcr2/method
16
16
  |---|---|
17
17
  | Create a DID (offline, deterministic or external) | `DidBtcr2.create()` |
18
18
  | Resolve a DID (sans-I/O state machine) | `DidBtcr2.resolve()` |
19
- | Construct, sign, and announce updates | `Update.construct()`, `Update.sign()`, `Update.announce()` |
19
+ | Update a DID (sans-I/O state machine) | `DidBtcr2.update()` `Updater` |
20
+ | Update utilities (construct, sign, announce) | `Updater.construct()`, `Updater.sign()`, `Updater.announce()` |
20
21
  | Beacon types (Singleton, CAS, SMT) | `SingletonBeacon`, `CASBeacon`, `SMTBeacon` |
21
22
  | Fee estimation (pluggable) | `FeeEstimator`, `StaticFeeEstimator` |
22
23
  | Multi-party aggregation (MuSig2) | `AggregationServiceRunner`, `AggregationParticipantRunner` |
@@ -63,18 +64,46 @@ const { didDocument, metadata } = state.result;
63
64
 
64
65
  See [`src/core/resolver.ts`](./src/core/resolver.ts) for the full `DataNeed` union and phase transitions.
65
66
 
66
- ### Construct and Sign an Update
67
+ ### Update a DID
68
+
69
+ `DidBtcr2.update()` returns a sans-I/O state machine — the counterpart to the Resolver. The caller drives the update by fulfilling typed data needs (signing key, funding confirmation, broadcast).
67
70
 
68
71
  ```typescript
69
- import { Update, Resolver } from '@did-btcr2/method';
72
+ import { DidBtcr2, Updater } from '@did-btcr2/method';
73
+
74
+ const updater = DidBtcr2.update({
75
+ sourceDocument,
76
+ patches : [{ op: 'add', path: '/service/-', value: newService }],
77
+ sourceVersionId : 1,
78
+ verificationMethodId : '#initialKey',
79
+ beaconId : '#beacon-0',
80
+ });
81
+
82
+ let state = updater.advance();
83
+ while (state.status === 'action-required') {
84
+ for (const need of state.needs) {
85
+ switch (need.kind) {
86
+ case 'NeedSigningKey':
87
+ updater.provide(need, secretKeyBytes);
88
+ break;
89
+ case 'NeedFunding':
90
+ // Check UTXOs at need.beaconAddress, fund if needed
91
+ updater.provide(need);
92
+ break;
93
+ case 'NeedBroadcast':
94
+ await Updater.announce(need.beaconService, need.signedUpdate, secretKey, bitcoin);
95
+ updater.provide(need);
96
+ break;
97
+ }
98
+ }
99
+ state = updater.advance();
100
+ }
70
101
 
71
- const doc = Resolver.deterministic({ genesisBytes: keys.publicKey.compressed, /* ... */ });
72
- const unsigned = await Update.construct(doc, [
73
- { op: 'add', path: '/service/-', value: { /* new service */ } },
74
- ], 1);
75
- const signed = Update.sign(did, unsigned, doc.verificationMethod![0], keys.raw.secret!);
102
+ const { signedUpdate } = state.result;
76
103
  ```
77
104
 
105
+ See [`src/core/updater.ts`](./src/core/updater.ts) for the full `UpdaterDataNeed` union and phase transitions.
106
+
78
107
  ### Update Aggregation (Multi-Party MuSig2)
79
108
 
80
109
  Aggregation lets multiple DID controllers coordinate a single Bitcoin transaction that announces all of their updates at once, signed n-of-n with MuSig2. The high-level `Runner` API hides the message routing and decision plumbing:
@@ -125,4 +154,4 @@ Tests run from compiled JS, so run `pnpm build:tests` before `pnpm test` after a
125
154
  - **[`docs/beacon-system-overview.md`](./docs/beacon-system-overview.md)** — Beacon architecture, Singleton / CAS / SMT behavior, signal discovery
126
155
  - **[`docs/aggregation.md`](./docs/aggregation.md)** — Multi-party aggregation protocol, Runner and state machine APIs, e2e examples
127
156
  - **[`docs/test-vectors.md`](./docs/test-vectors.md)** — CLI tool for generating did:btcr2 test vectors via a stepped workflow
128
- - **Source reference** — See JSDoc comments on public classes; the most important entry points are `DidBtcr2` (facade), `Resolver` (read path), `Update` (write path), and the aggregation runners.
157
+ - **Source reference** — See JSDoc comments on public classes; the most important entry points are `DidBtcr2` (facade), `Resolver` (read path), `Updater` (write path), and the aggregation runners.