@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 +38 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +194 -62
- package/dist/browser.mjs +194 -62
- package/dist/cjs/index.js +201 -68
- package/dist/esm/core/aggregation/runner/participant-runner.js +4 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -1
- package/dist/esm/core/updater.js +269 -0
- package/dist/esm/core/updater.js.map +1 -0
- package/dist/esm/did-btcr2.js +30 -42
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types/core/aggregation/runner/participant-runner.d.ts +4 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -1
- package/dist/types/core/updater.d.ts +178 -0
- package/dist/types/core/updater.d.ts.map +1 -0
- package/dist/types/did-btcr2.d.ts +23 -23
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/core/aggregation/runner/participant-runner.ts +4 -0
- package/src/core/updater.ts +415 -0
- package/src/did-btcr2.ts +36 -66
- package/src/index.ts +2 -1
- package/dist/esm/core/update.js +0 -112
- package/dist/esm/core/update.js.map +0 -1
- package/dist/types/core/update.d.ts +0 -52
- package/dist/types/core/update.d.ts.map +0 -1
- package/src/core/update.ts +0 -158
package/dist/browser.mjs
CHANGED
|
@@ -138549,9 +138549,8 @@ init_shim();
|
|
|
138549
138549
|
// src/did-btcr2.ts
|
|
138550
138550
|
init_shim();
|
|
138551
138551
|
var ecc = __toESM(require_dist2(), 1);
|
|
138552
|
-
init_utils();
|
|
138553
138552
|
|
|
138554
|
-
// src/core/
|
|
138553
|
+
// src/core/updater.ts
|
|
138555
138554
|
init_shim();
|
|
138556
138555
|
|
|
138557
138556
|
// src/utils/did-document.ts
|
|
@@ -138917,17 +138916,37 @@ var GenesisDocument = class _GenesisDocument extends DidDocument {
|
|
|
138917
138916
|
}
|
|
138918
138917
|
};
|
|
138919
138918
|
|
|
138920
|
-
// src/core/
|
|
138921
|
-
var
|
|
138919
|
+
// src/core/updater.ts
|
|
138920
|
+
var Updater = class _Updater {
|
|
138921
|
+
#phase = "Construct" /* Construct */;
|
|
138922
|
+
#sourceDocument;
|
|
138923
|
+
#patches;
|
|
138924
|
+
#sourceVersionId;
|
|
138925
|
+
#verificationMethod;
|
|
138926
|
+
#beaconService;
|
|
138927
|
+
#unsignedUpdate = null;
|
|
138928
|
+
#signedUpdate = null;
|
|
138929
|
+
/**
|
|
138930
|
+
* @internal — Use {@link DidBtcr2.update} to create instances.
|
|
138931
|
+
*/
|
|
138932
|
+
constructor(params) {
|
|
138933
|
+
this.#sourceDocument = params.sourceDocument;
|
|
138934
|
+
this.#patches = params.patches;
|
|
138935
|
+
this.#sourceVersionId = params.sourceVersionId;
|
|
138936
|
+
this.#verificationMethod = params.verificationMethod;
|
|
138937
|
+
this.#beaconService = params.beaconService;
|
|
138938
|
+
}
|
|
138939
|
+
// ─── Public static utility methods ─────────────────────────────────────────
|
|
138940
|
+
// Used by generate-vector.ts and other scripts that need direct access to
|
|
138941
|
+
// individual update steps outside the state machine flow.
|
|
138922
138942
|
/**
|
|
138923
138943
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
|
|
138924
|
-
* This process constructs a BTCR2 Unsigned Update conformant to the spec template.
|
|
138925
138944
|
*
|
|
138926
138945
|
* @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
|
|
138927
|
-
* @param {PatchOperation[]} patches The
|
|
138946
|
+
* @param {PatchOperation[]} patches The JSON Patch operations to apply.
|
|
138928
138947
|
* @param {number} sourceVersionId The version ID of the source document.
|
|
138929
138948
|
* @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
|
|
138930
|
-
* @throws {UpdateError}
|
|
138949
|
+
* @throws {UpdateError} If the target document fails DID Core validation.
|
|
138931
138950
|
*/
|
|
138932
138951
|
static construct(sourceDocument, patches, sourceVersionId) {
|
|
138933
138952
|
const unsignedUpdate = {
|
|
@@ -138957,13 +138976,12 @@ var Update = class {
|
|
|
138957
138976
|
}
|
|
138958
138977
|
/**
|
|
138959
138978
|
* Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
|
|
138960
|
-
* This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
|
|
138961
138979
|
*
|
|
138962
|
-
* @param {string} did The did-btcr2 identifier to derive the root capability from
|
|
138963
|
-
* @param {UnsignedBTCR2Update} unsignedUpdate The
|
|
138964
|
-
* @param {DidVerificationMethod} verificationMethod The
|
|
138965
|
-
* @
|
|
138966
|
-
* @
|
|
138980
|
+
* @param {string} did The did-btcr2 identifier to derive the root capability from.
|
|
138981
|
+
* @param {UnsignedBTCR2Update} unsignedUpdate The unsigned update to sign.
|
|
138982
|
+
* @param {DidVerificationMethod} verificationMethod The verification method for signing.
|
|
138983
|
+
* @param {KeyBytes} secretKey The secret key bytes.
|
|
138984
|
+
* @returns {SignedBTCR2Update} The signed update with a Data Integrity proof.
|
|
138967
138985
|
*/
|
|
138968
138986
|
static sign(did, unsignedUpdate, verificationMethod, secretKey) {
|
|
138969
138987
|
const controller = verificationMethod.controller;
|
|
@@ -138988,17 +139006,141 @@ var Update = class {
|
|
|
138988
139006
|
}
|
|
138989
139007
|
/**
|
|
138990
139008
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
|
|
138991
|
-
*
|
|
138992
|
-
*
|
|
138993
|
-
* @param {
|
|
138994
|
-
* @param {
|
|
138995
|
-
* @
|
|
138996
|
-
* @
|
|
139009
|
+
* Announces a signed update to the Bitcoin blockchain via the specified beacon.
|
|
139010
|
+
*
|
|
139011
|
+
* @param {BeaconService} beaconService The beacon service to broadcast through.
|
|
139012
|
+
* @param {SignedBTCR2Update} update The signed update to announce.
|
|
139013
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
139014
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
139015
|
+
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
138997
139016
|
*/
|
|
138998
139017
|
static async announce(beaconService, update, secretKey, bitcoin3) {
|
|
138999
139018
|
const beacon = BeaconFactory.establish(beaconService);
|
|
139000
|
-
|
|
139001
|
-
|
|
139019
|
+
return beacon.broadcastSignal(update, secretKey, bitcoin3);
|
|
139020
|
+
}
|
|
139021
|
+
// ─── Private instance wrappers ─────────────────────────────────────────────
|
|
139022
|
+
// Delegate to the public statics with bound instance fields for cleaner
|
|
139023
|
+
// advance/provide code.
|
|
139024
|
+
#construct() {
|
|
139025
|
+
return _Updater.construct(this.#sourceDocument, this.#patches, this.#sourceVersionId);
|
|
139026
|
+
}
|
|
139027
|
+
#sign(secretKey) {
|
|
139028
|
+
return _Updater.sign(this.#sourceDocument.id, this.#unsignedUpdate, this.#verificationMethod, secretKey);
|
|
139029
|
+
}
|
|
139030
|
+
// ─── State machine ─────────────────────────────────────────────────────────
|
|
139031
|
+
/**
|
|
139032
|
+
* Advance the state machine. Returns either:
|
|
139033
|
+
* - `{ status: 'action-required', needs }` — caller must provide data via {@link provide}
|
|
139034
|
+
* - `{ status: 'complete', result }` — update is signed and broadcast
|
|
139035
|
+
*/
|
|
139036
|
+
advance() {
|
|
139037
|
+
while (true) {
|
|
139038
|
+
switch (this.#phase) {
|
|
139039
|
+
// Phase: Construct
|
|
139040
|
+
// Build the unsigned update from source doc + patches. Pure, synchronous.
|
|
139041
|
+
case "Construct" /* Construct */: {
|
|
139042
|
+
this.#unsignedUpdate = this.#construct();
|
|
139043
|
+
this.#phase = "Sign" /* Sign */;
|
|
139044
|
+
continue;
|
|
139045
|
+
}
|
|
139046
|
+
// Phase: Sign
|
|
139047
|
+
// Emit NeedSigningKey — the caller supplies the secret key (or a KMS signature).
|
|
139048
|
+
case "Sign" /* Sign */: {
|
|
139049
|
+
return {
|
|
139050
|
+
status: "action-required",
|
|
139051
|
+
needs: [{
|
|
139052
|
+
kind: "NeedSigningKey",
|
|
139053
|
+
verificationMethodId: this.#verificationMethod.id,
|
|
139054
|
+
unsignedUpdate: this.#unsignedUpdate
|
|
139055
|
+
}]
|
|
139056
|
+
};
|
|
139057
|
+
}
|
|
139058
|
+
// Phase: Fund
|
|
139059
|
+
// Emit NeedFunding with the beacon address. The caller checks UTXOs,
|
|
139060
|
+
// funds the address if needed, and provides to continue.
|
|
139061
|
+
case "Fund" /* Fund */: {
|
|
139062
|
+
const beaconAddress = this.#beaconService.serviceEndpoint.replace("bitcoin:", "");
|
|
139063
|
+
return {
|
|
139064
|
+
status: "action-required",
|
|
139065
|
+
needs: [{
|
|
139066
|
+
kind: "NeedFunding",
|
|
139067
|
+
beaconAddress,
|
|
139068
|
+
beaconService: this.#beaconService
|
|
139069
|
+
}]
|
|
139070
|
+
};
|
|
139071
|
+
}
|
|
139072
|
+
// Phase: Broadcast
|
|
139073
|
+
// Emit NeedBroadcast with the signed update + beacon service. The caller performs
|
|
139074
|
+
// the actual on-chain announcement (or hands off to the aggregation protocol).
|
|
139075
|
+
case "Broadcast" /* Broadcast */: {
|
|
139076
|
+
return {
|
|
139077
|
+
status: "action-required",
|
|
139078
|
+
needs: [{
|
|
139079
|
+
kind: "NeedBroadcast",
|
|
139080
|
+
beaconService: this.#beaconService,
|
|
139081
|
+
signedUpdate: this.#signedUpdate
|
|
139082
|
+
}]
|
|
139083
|
+
};
|
|
139084
|
+
}
|
|
139085
|
+
// Phase: Complete
|
|
139086
|
+
case "Complete" /* Complete */: {
|
|
139087
|
+
return {
|
|
139088
|
+
status: "complete",
|
|
139089
|
+
result: { signedUpdate: this.#signedUpdate }
|
|
139090
|
+
};
|
|
139091
|
+
}
|
|
139092
|
+
}
|
|
139093
|
+
}
|
|
139094
|
+
}
|
|
139095
|
+
provide(need, data) {
|
|
139096
|
+
switch (need.kind) {
|
|
139097
|
+
case "NeedSigningKey": {
|
|
139098
|
+
if (this.#phase !== "Sign" /* Sign */) {
|
|
139099
|
+
throw new UpdateError(
|
|
139100
|
+
`Cannot provide NeedSigningKey: updater phase is ${this.#phase}, expected Sign.`,
|
|
139101
|
+
INVALID_DID_UPDATE,
|
|
139102
|
+
{ phase: this.#phase }
|
|
139103
|
+
);
|
|
139104
|
+
}
|
|
139105
|
+
if (!data) {
|
|
139106
|
+
throw new UpdateError(
|
|
139107
|
+
"NeedSigningKey requires secret key bytes.",
|
|
139108
|
+
INVALID_DID_UPDATE
|
|
139109
|
+
);
|
|
139110
|
+
}
|
|
139111
|
+
if (!this.#unsignedUpdate) {
|
|
139112
|
+
throw new UpdateError(
|
|
139113
|
+
"Internal error: unsigned update missing in Sign phase.",
|
|
139114
|
+
INVALID_DID_UPDATE
|
|
139115
|
+
);
|
|
139116
|
+
}
|
|
139117
|
+
this.#signedUpdate = this.#sign(data);
|
|
139118
|
+
this.#phase = "Fund" /* Fund */;
|
|
139119
|
+
break;
|
|
139120
|
+
}
|
|
139121
|
+
case "NeedFunding": {
|
|
139122
|
+
if (this.#phase !== "Fund" /* Fund */) {
|
|
139123
|
+
throw new UpdateError(
|
|
139124
|
+
`Cannot provide NeedFunding: updater phase is ${this.#phase}, expected Fund.`,
|
|
139125
|
+
INVALID_DID_UPDATE,
|
|
139126
|
+
{ phase: this.#phase }
|
|
139127
|
+
);
|
|
139128
|
+
}
|
|
139129
|
+
this.#phase = "Broadcast" /* Broadcast */;
|
|
139130
|
+
break;
|
|
139131
|
+
}
|
|
139132
|
+
case "NeedBroadcast": {
|
|
139133
|
+
if (this.#phase !== "Broadcast" /* Broadcast */) {
|
|
139134
|
+
throw new UpdateError(
|
|
139135
|
+
`Cannot provide NeedBroadcast: updater phase is ${this.#phase}, expected Broadcast.`,
|
|
139136
|
+
INVALID_DID_UPDATE,
|
|
139137
|
+
{ phase: this.#phase }
|
|
139138
|
+
);
|
|
139139
|
+
}
|
|
139140
|
+
this.#phase = "Complete" /* Complete */;
|
|
139141
|
+
break;
|
|
139142
|
+
}
|
|
139143
|
+
}
|
|
139002
139144
|
}
|
|
139003
139145
|
};
|
|
139004
139146
|
|
|
@@ -139068,42 +139210,35 @@ var DidBtcr2 = class {
|
|
|
139068
139210
|
});
|
|
139069
139211
|
}
|
|
139070
139212
|
/**
|
|
139071
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#
|
|
139072
|
-
*
|
|
139073
|
-
*
|
|
139074
|
-
*
|
|
139075
|
-
*
|
|
139076
|
-
*
|
|
139077
|
-
*
|
|
139078
|
-
*
|
|
139213
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 7.3 Update}.
|
|
139214
|
+
*
|
|
139215
|
+
* Factory method that validates the update parameters and returns a sans-I/O
|
|
139216
|
+
* {@link Updater} state machine. The caller drives the updater through its
|
|
139217
|
+
* phases (Construct → Sign → Broadcast → Complete) by calling `advance()` and
|
|
139218
|
+
* `provide()`. The method package performs **zero I/O** — signing key retrieval
|
|
139219
|
+
* (or KMS delegation) and the on-chain broadcast are the caller's responsibility.
|
|
139220
|
+
*
|
|
139221
|
+
* For a fully-wired version with Bitcoin broadcast and key handling, see
|
|
139222
|
+
* `DidMethodApi.update()` in `@did-btcr2/api`.
|
|
139223
|
+
*
|
|
139224
|
+
* @param params Update construction parameters.
|
|
139079
139225
|
* @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
|
|
139080
|
-
* @param {PatchOperation[]} params.patches The
|
|
139081
|
-
* @param {
|
|
139082
|
-
* @param {string} params.verificationMethodId The
|
|
139083
|
-
* @param {string} params.beaconId The beacon ID
|
|
139084
|
-
* @
|
|
139085
|
-
* @
|
|
139086
|
-
*
|
|
139087
|
-
*
|
|
139088
|
-
* header is not `zQ3s`
|
|
139226
|
+
* @param {PatchOperation[]} params.patches The JSON Patch operations to apply.
|
|
139227
|
+
* @param {number} params.sourceVersionId The version ID before applying the update.
|
|
139228
|
+
* @param {string} params.verificationMethodId The verification method ID to sign with.
|
|
139229
|
+
* @param {string} params.beaconId The beacon service ID to broadcast through.
|
|
139230
|
+
* @returns {Updater} A sans-I/O state machine for driving the update.
|
|
139231
|
+
* @throws {UpdateError} If the verification method is not authorized, not found,
|
|
139232
|
+
* not of type `Multikey`, or does not have a `zQ3s` publicKeyMultibase prefix.
|
|
139233
|
+
* Also throws if the beacon service is not found.
|
|
139089
139234
|
*/
|
|
139090
|
-
static
|
|
139235
|
+
static update({
|
|
139091
139236
|
sourceDocument,
|
|
139092
139237
|
patches,
|
|
139093
139238
|
sourceVersionId,
|
|
139094
139239
|
verificationMethodId,
|
|
139095
|
-
beaconId
|
|
139096
|
-
signingMaterial,
|
|
139097
|
-
bitcoin: bitcoin3
|
|
139240
|
+
beaconId
|
|
139098
139241
|
}) {
|
|
139099
|
-
if (!signingMaterial) {
|
|
139100
|
-
throw new UpdateError(
|
|
139101
|
-
"Missing signing material for update",
|
|
139102
|
-
INVALID_DID_UPDATE,
|
|
139103
|
-
{ signingMaterial }
|
|
139104
|
-
);
|
|
139105
|
-
}
|
|
139106
|
-
const secretKey = typeof signingMaterial === "string" ? hexToBytes(signingMaterial) : signingMaterial;
|
|
139107
139242
|
if (!sourceDocument.capabilityInvocation?.some((vr) => vr === verificationMethodId)) {
|
|
139108
139243
|
throw new UpdateError(
|
|
139109
139244
|
"Invalid verificationMethodId: not authorized for capabilityInvocation",
|
|
@@ -139133,8 +139268,6 @@ var DidBtcr2 = class {
|
|
|
139133
139268
|
verificationMethod
|
|
139134
139269
|
);
|
|
139135
139270
|
}
|
|
139136
|
-
const update = Update.construct(sourceDocument, patches, sourceVersionId);
|
|
139137
|
-
const signed = Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
|
|
139138
139271
|
const beaconService = sourceDocument.service.filter((service) => service.id === beaconId).filter((service) => !!service).shift();
|
|
139139
139272
|
if (!beaconService) {
|
|
139140
139273
|
throw new UpdateError(
|
|
@@ -139143,15 +139276,13 @@ var DidBtcr2 = class {
|
|
|
139143
139276
|
{ sourceDocument, beaconId }
|
|
139144
139277
|
);
|
|
139145
139278
|
}
|
|
139146
|
-
|
|
139147
|
-
|
|
139148
|
-
|
|
139149
|
-
|
|
139150
|
-
|
|
139151
|
-
|
|
139152
|
-
}
|
|
139153
|
-
await Update.announce(beaconService, signed, secretKey, bitcoin3);
|
|
139154
|
-
return signed;
|
|
139279
|
+
return new Updater({
|
|
139280
|
+
sourceDocument,
|
|
139281
|
+
patches,
|
|
139282
|
+
sourceVersionId,
|
|
139283
|
+
verificationMethod,
|
|
139284
|
+
beaconService
|
|
139285
|
+
});
|
|
139155
139286
|
}
|
|
139156
139287
|
/**
|
|
139157
139288
|
* Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
|
|
@@ -139698,11 +139829,12 @@ export {
|
|
|
139698
139829
|
SigningSessionPhase,
|
|
139699
139830
|
SingletonBeacon,
|
|
139700
139831
|
SingletonBeaconError,
|
|
139832
|
+
StaticFeeEstimator,
|
|
139701
139833
|
TransportAdapterError,
|
|
139702
139834
|
TransportError,
|
|
139703
139835
|
TransportFactory,
|
|
139704
139836
|
TypedEventEmitter,
|
|
139705
|
-
|
|
139837
|
+
Updater,
|
|
139706
139838
|
VALIDATION_ACK,
|
|
139707
139839
|
createAggregatedNonceMessage,
|
|
139708
139840
|
createAuthorizationRequestMessage,
|