@did-btcr2/method 0.27.0 → 0.29.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.
Files changed (114) hide show
  1. package/README.md +38 -9
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +20181 -31588
  4. package/dist/browser.mjs +20110 -31517
  5. package/dist/cjs/index.js +1355 -422
  6. package/dist/esm/core/aggregation/beacon-strategy.js +62 -0
  7. package/dist/esm/core/aggregation/beacon-strategy.js.map +1 -0
  8. package/dist/esm/core/aggregation/cohort.js +31 -8
  9. package/dist/esm/core/aggregation/cohort.js.map +1 -1
  10. package/dist/esm/core/aggregation/logger.js +15 -0
  11. package/dist/esm/core/aggregation/logger.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/base.js +12 -1
  13. package/dist/esm/core/aggregation/messages/base.js.map +1 -1
  14. package/dist/esm/core/aggregation/messages/bodies.js +90 -0
  15. package/dist/esm/core/aggregation/messages/bodies.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/factories.js.map +1 -1
  17. package/dist/esm/core/aggregation/messages/index.js +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js.map +1 -1
  19. package/dist/esm/core/aggregation/participant.js +39 -46
  20. package/dist/esm/core/aggregation/participant.js.map +1 -1
  21. package/dist/esm/core/aggregation/runner/participant-runner.js +34 -4
  22. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -1
  23. package/dist/esm/core/aggregation/runner/service-runner.js +198 -19
  24. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -1
  25. package/dist/esm/core/aggregation/service.js +143 -15
  26. package/dist/esm/core/aggregation/service.js.map +1 -1
  27. package/dist/esm/core/aggregation/signing-session.js +44 -5
  28. package/dist/esm/core/aggregation/signing-session.js.map +1 -1
  29. package/dist/esm/core/aggregation/transport/didcomm.js +9 -0
  30. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -1
  31. package/dist/esm/core/aggregation/transport/nostr.js +245 -16
  32. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -1
  33. package/dist/esm/core/beacon/beacon.js +147 -61
  34. package/dist/esm/core/beacon/beacon.js.map +1 -1
  35. package/dist/esm/core/beacon/utils.js +14 -9
  36. package/dist/esm/core/beacon/utils.js.map +1 -1
  37. package/dist/esm/core/updater.js +269 -0
  38. package/dist/esm/core/updater.js.map +1 -0
  39. package/dist/esm/did-btcr2.js +30 -46
  40. package/dist/esm/did-btcr2.js.map +1 -1
  41. package/dist/esm/index.js +4 -1
  42. package/dist/esm/index.js.map +1 -1
  43. package/dist/esm/utils/did-document.js +2 -2
  44. package/dist/esm/utils/did-document.js.map +1 -1
  45. package/dist/types/core/aggregation/beacon-strategy.d.ts +52 -0
  46. package/dist/types/core/aggregation/beacon-strategy.d.ts.map +1 -0
  47. package/dist/types/core/aggregation/cohort.d.ts +20 -3
  48. package/dist/types/core/aggregation/cohort.d.ts.map +1 -1
  49. package/dist/types/core/aggregation/logger.d.ts +22 -0
  50. package/dist/types/core/aggregation/logger.d.ts.map +1 -0
  51. package/dist/types/core/aggregation/messages/base.d.ts +13 -1
  52. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -1
  53. package/dist/types/core/aggregation/messages/bodies.d.ts +130 -0
  54. package/dist/types/core/aggregation/messages/bodies.d.ts.map +1 -0
  55. package/dist/types/core/aggregation/messages/factories.d.ts +1 -0
  56. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -1
  57. package/dist/types/core/aggregation/messages/index.d.ts +1 -0
  58. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -1
  59. package/dist/types/core/aggregation/participant.d.ts +2 -0
  60. package/dist/types/core/aggregation/participant.d.ts.map +1 -1
  61. package/dist/types/core/aggregation/runner/events.d.ts +32 -6
  62. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -1
  63. package/dist/types/core/aggregation/runner/participant-runner.d.ts +8 -2
  64. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -1
  65. package/dist/types/core/aggregation/runner/service-runner.d.ts +33 -3
  66. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -1
  67. package/dist/types/core/aggregation/service.d.ts +33 -2
  68. package/dist/types/core/aggregation/service.d.ts.map +1 -1
  69. package/dist/types/core/aggregation/signing-session.d.ts +5 -1
  70. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -1
  71. package/dist/types/core/aggregation/transport/didcomm.d.ts +3 -0
  72. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -1
  73. package/dist/types/core/aggregation/transport/nostr.d.ts +99 -1
  74. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -1
  75. package/dist/types/core/aggregation/transport/transport.d.ts +25 -0
  76. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -1
  77. package/dist/types/core/beacon/beacon.d.ts +85 -18
  78. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  79. package/dist/types/core/beacon/utils.d.ts +2 -2
  80. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  81. package/dist/types/core/updater.d.ts +178 -0
  82. package/dist/types/core/updater.d.ts.map +1 -0
  83. package/dist/types/did-btcr2.d.ts +23 -23
  84. package/dist/types/did-btcr2.d.ts.map +1 -1
  85. package/dist/types/index.d.ts +4 -1
  86. package/dist/types/index.d.ts.map +1 -1
  87. package/package.json +4 -6
  88. package/src/core/aggregation/beacon-strategy.ts +123 -0
  89. package/src/core/aggregation/cohort.ts +34 -8
  90. package/src/core/aggregation/logger.ts +33 -0
  91. package/src/core/aggregation/messages/base.ts +20 -5
  92. package/src/core/aggregation/messages/bodies.ts +223 -0
  93. package/src/core/aggregation/messages/factories.ts +1 -0
  94. package/src/core/aggregation/messages/index.ts +1 -0
  95. package/src/core/aggregation/participant.ts +40 -46
  96. package/src/core/aggregation/runner/events.ts +27 -3
  97. package/src/core/aggregation/runner/participant-runner.ts +42 -4
  98. package/src/core/aggregation/runner/service-runner.ts +227 -19
  99. package/src/core/aggregation/service.ts +189 -20
  100. package/src/core/aggregation/signing-session.ts +65 -7
  101. package/src/core/aggregation/transport/didcomm.ts +17 -0
  102. package/src/core/aggregation/transport/nostr.ts +266 -23
  103. package/src/core/aggregation/transport/transport.ts +33 -0
  104. package/src/core/beacon/beacon.ts +217 -76
  105. package/src/core/beacon/utils.ts +16 -11
  106. package/src/core/updater.ts +415 -0
  107. package/src/did-btcr2.ts +36 -71
  108. package/src/index.ts +4 -1
  109. package/src/utils/did-document.ts +2 -2
  110. package/dist/esm/core/update.js +0 -112
  111. package/dist/esm/core/update.js.map +0 -1
  112. package/dist/types/core/update.d.ts +0 -52
  113. package/dist/types/core/update.d.ts.map +0 -1
  114. package/src/core/update.ts +0 -158
@@ -1,112 +0,0 @@
1
- import { canonicalHash, INVALID_DID_UPDATE, JSONPatch, UpdateError } from '@did-btcr2/common';
2
- import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
3
- import { DidDocument } from '../utils/did-document.js';
4
- import { BeaconFactory } from './beacon/factory.js';
5
- /**
6
- * Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
7
- *
8
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
9
- * data format, signed by a verificationMethod that has the authority to make
10
- * the update as specified in the previous DID document. Capability invocations
11
- * for updates MUST be authorized using Data Integrity following the
12
- * bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
13
- *
14
- * @class Update
15
- * @type {Update}
16
- */
17
- export class Update {
18
- /**
19
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
20
- * This process constructs a BTCR2 Unsigned Update conformant to the spec template.
21
- *
22
- * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
23
- * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
24
- * @param {number} sourceVersionId The version ID of the source document.
25
- * @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
26
- * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
27
- */
28
- static construct(sourceDocument, patches, sourceVersionId) {
29
- // Initialize an unsigned update conformant to btcr2 spec.
30
- const unsignedUpdate = {
31
- '@context': [
32
- 'https://w3id.org/security/v2',
33
- 'https://w3id.org/zcap/v1',
34
- 'https://w3id.org/json-ld-patch/v1',
35
- 'https://btcr2.dev/context/v1'
36
- ],
37
- patch: patches,
38
- targetHash: '',
39
- targetVersionId: sourceVersionId + 1,
40
- sourceHash: canonicalHash(sourceDocument),
41
- };
42
- // Apply all JSON patches to sourceDocument.
43
- const targetDocument = JSONPatch.apply(sourceDocument, patches);
44
- try {
45
- // Ensure the targetDocument is conformant to DID Core v1.1.
46
- DidDocument.isValid(targetDocument);
47
- }
48
- catch (error) {
49
- // If validation fails, throw an UpdateError with INVALID_DID_UPDATE.
50
- throw new UpdateError('Error validating targetDocument: ' + (error instanceof Error ? error.message : String(error)), INVALID_DID_UPDATE, targetDocument);
51
- }
52
- // Set the targetHash by canonicalizing the targetDocument and encoding it in base64url.
53
- unsignedUpdate.targetHash = canonicalHash(targetDocument);
54
- // Return unsignedUpdate.
55
- return unsignedUpdate;
56
- }
57
- /**
58
- * Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
59
- * This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
60
- *
61
- * @param {string} did The did-btcr2 identifier to derive the root capability from
62
- * @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
63
- * @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
64
- * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
65
- * @throws {UpdateError} if the privateKeyBytes are invalid
66
- */
67
- static sign(did, unsignedUpdate, verificationMethod, secretKey) {
68
- // Parse the controller from the verificationMethod
69
- const controller = verificationMethod.controller;
70
- // Parse the fragment from the vmId
71
- const id = verificationMethod.id.slice(verificationMethod.id.indexOf('#'));
72
- // Construct a Schnorr Multikey
73
- const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
74
- // Define the Data Integrity proof config
75
- const config = {
76
- '@context': [
77
- 'https://w3id.org/security/v2',
78
- 'https://w3id.org/zcap/v1',
79
- 'https://w3id.org/json-ld-patch/v1',
80
- 'https://btcr2.dev/context/v1'
81
- ],
82
- cryptosuite: 'bip340-jcs-2025',
83
- type: 'DataIntegrityProof',
84
- verificationMethod: verificationMethod.id,
85
- proofPurpose: 'capabilityInvocation',
86
- capability: `urn:zcap:root:${encodeURIComponent(did)}`,
87
- capabilityAction: 'Write',
88
- };
89
- // Go from multikey => cryptosuite => diproof
90
- const diproof = multikey.toCryptosuite().toDataIntegrityProof();
91
- // Use the config to add a proof to the unsigned update
92
- return diproof.addProof(unsignedUpdate, config);
93
- }
94
- /**
95
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
96
- * BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
97
- * @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
98
- * @param {SignedBTCR2Update} update The signed update object to be announced.
99
- * @param {KeyBytes} secretKey The private key used to sign the update for announcement.
100
- * @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
101
- * @throws {UpdateError} if the beaconService type is invalid
102
- */
103
- static async announce(beaconService, update, secretKey, bitcoin) {
104
- // Establish a beacon object
105
- const beacon = BeaconFactory.establish(beaconService);
106
- // Broadcast the update
107
- const result = await beacon.broadcastSignal(update, secretKey, bitcoin);
108
- // Return the sidecarData
109
- return result;
110
- }
111
- }
112
- //# sourceMappingURL=update.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/core/update.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAM3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from '@did-btcr2/common';
2
- import type { SignedBTCR2Update, UnsignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
- import type { Btcr2DidDocument, DidVerificationMethod } from '../utils/did-document.js';
4
- import type { BeaconService } from './beacon/interfaces.js';
5
- import type { BitcoinConnection } from '@did-btcr2/bitcoin';
6
- /**
7
- * Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
8
- *
9
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
10
- * data format, signed by a verificationMethod that has the authority to make
11
- * the update as specified in the previous DID document. Capability invocations
12
- * for updates MUST be authorized using Data Integrity following the
13
- * bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
14
- *
15
- * @class Update
16
- * @type {Update}
17
- */
18
- export declare class Update {
19
- /**
20
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
21
- * This process constructs a BTCR2 Unsigned Update conformant to the spec template.
22
- *
23
- * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
24
- * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
25
- * @param {number} sourceVersionId The version ID of the source document.
26
- * @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
27
- * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
28
- */
29
- static construct(sourceDocument: Btcr2DidDocument, patches: PatchOperation[], sourceVersionId: number): UnsignedBTCR2Update;
30
- /**
31
- * Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
32
- * This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
33
- *
34
- * @param {string} did The did-btcr2 identifier to derive the root capability from
35
- * @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
36
- * @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
37
- * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
38
- * @throws {UpdateError} if the privateKeyBytes are invalid
39
- */
40
- static sign(did: string, unsignedUpdate: UnsignedBTCR2Update, verificationMethod: DidVerificationMethod, secretKey: KeyBytes): SignedBTCR2Update;
41
- /**
42
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
43
- * BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
44
- * @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
45
- * @param {SignedBTCR2Update} update The signed update object to be announced.
46
- * @param {KeyBytes} secretKey The private key used to sign the update for announcement.
47
- * @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
48
- * @throws {UpdateError} if the beaconService type is invalid
49
- */
50
- static announce(beaconService: BeaconService, update: SignedBTCR2Update, secretKey: KeyBytes, bitcoin: BitcoinConnection): Promise<SignedBTCR2Update>;
51
- }
52
- //# sourceMappingURL=update.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/core/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAO3C,OAAO,KAAK,EAEV,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAGxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB;;;;;;;;;OASG;IACH,MAAM,CAAC,SAAS,CACd,cAAc,EAAE,gBAAgB,EAChC,OAAO,EAAE,cAAc,EAAE,EACzB,eAAe,EAAE,MAAM,GACtB,mBAAmB;IAoCtB;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CACT,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,mBAAmB,EACnC,kBAAkB,EAAE,qBAAqB,EACzC,SAAS,EAAE,QAAQ,GAClB,iBAAiB;IAgCpB;;;;;;;;OAQG;WACU,QAAQ,CACnB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,QAAQ,EACnB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC;CAU9B"}
@@ -1,158 +0,0 @@
1
- import type {
2
- KeyBytes,
3
- PatchOperation} from '@did-btcr2/common';
4
- import {
5
- canonicalHash,
6
- INVALID_DID_UPDATE,
7
- JSONPatch,
8
- UpdateError
9
- } from '@did-btcr2/common';
10
- import type {
11
- DataIntegrityConfig,
12
- SignedBTCR2Update,
13
- UnsignedBTCR2Update
14
- } from '@did-btcr2/cryptosuite';
15
- import {
16
- SchnorrMultikey
17
- } from '@did-btcr2/cryptosuite';
18
- import type { Btcr2DidDocument, DidVerificationMethod } from '../utils/did-document.js';
19
- import { DidDocument } from '../utils/did-document.js';
20
- import { BeaconFactory } from './beacon/factory.js';
21
- import type { BeaconService } from './beacon/interfaces.js';
22
- import type { BitcoinConnection } from '@did-btcr2/bitcoin';
23
-
24
- /**
25
- * Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
26
- *
27
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
28
- * data format, signed by a verificationMethod that has the authority to make
29
- * the update as specified in the previous DID document. Capability invocations
30
- * for updates MUST be authorized using Data Integrity following the
31
- * bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
32
- *
33
- * @class Update
34
- * @type {Update}
35
- */
36
- export class Update {
37
- /**
38
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
39
- * This process constructs a BTCR2 Unsigned Update conformant to the spec template.
40
- *
41
- * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
42
- * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
43
- * @param {number} sourceVersionId The version ID of the source document.
44
- * @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
45
- * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
46
- */
47
- static construct(
48
- sourceDocument: Btcr2DidDocument,
49
- patches: PatchOperation[],
50
- sourceVersionId: number,
51
- ): UnsignedBTCR2Update {
52
- // Initialize an unsigned update conformant to btcr2 spec.
53
- const unsignedUpdate: UnsignedBTCR2Update = {
54
- '@context' : [
55
- 'https://w3id.org/security/v2',
56
- 'https://w3id.org/zcap/v1',
57
- 'https://w3id.org/json-ld-patch/v1',
58
- 'https://btcr2.dev/context/v1'
59
- ],
60
- patch : patches,
61
- targetHash : '',
62
- targetVersionId : sourceVersionId + 1,
63
- sourceHash : canonicalHash(sourceDocument),
64
- };
65
-
66
- // Apply all JSON patches to sourceDocument.
67
- const targetDocument = JSONPatch.apply(sourceDocument, patches);
68
-
69
- try {
70
- // Ensure the targetDocument is conformant to DID Core v1.1.
71
- DidDocument.isValid(targetDocument);
72
- } catch (error) {
73
- // If validation fails, throw an UpdateError with INVALID_DID_UPDATE.
74
- throw new UpdateError(
75
- 'Error validating targetDocument: ' + (error instanceof Error ? error.message : String(error)),
76
- INVALID_DID_UPDATE, targetDocument
77
- );
78
- }
79
-
80
- // Set the targetHash by canonicalizing the targetDocument and encoding it in base64url.
81
- unsignedUpdate.targetHash = canonicalHash(targetDocument);
82
-
83
- // Return unsignedUpdate.
84
- return unsignedUpdate;
85
- }
86
-
87
- /**
88
- * Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
89
- * This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
90
- *
91
- * @param {string} did The did-btcr2 identifier to derive the root capability from
92
- * @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
93
- * @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
94
- * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
95
- * @throws {UpdateError} if the privateKeyBytes are invalid
96
- */
97
- static sign(
98
- did: string,
99
- unsignedUpdate: UnsignedBTCR2Update,
100
- verificationMethod: DidVerificationMethod,
101
- secretKey: KeyBytes,
102
- ): SignedBTCR2Update {
103
- // Parse the controller from the verificationMethod
104
- const controller = verificationMethod.controller;
105
- // Parse the fragment from the vmId
106
- const id = verificationMethod.id.slice(verificationMethod.id.indexOf('#'));
107
-
108
- // Construct a Schnorr Multikey
109
- const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
110
-
111
- // Define the Data Integrity proof config
112
- const config: DataIntegrityConfig = {
113
- '@context' : [
114
- 'https://w3id.org/security/v2',
115
- 'https://w3id.org/zcap/v1',
116
- 'https://w3id.org/json-ld-patch/v1',
117
- 'https://btcr2.dev/context/v1'
118
- ],
119
- cryptosuite : 'bip340-jcs-2025',
120
- type : 'DataIntegrityProof',
121
- verificationMethod : verificationMethod.id,
122
- proofPurpose : 'capabilityInvocation',
123
- capability : `urn:zcap:root:${encodeURIComponent(did)}`,
124
- capabilityAction : 'Write',
125
- };
126
-
127
- // Go from multikey => cryptosuite => diproof
128
- const diproof = multikey.toCryptosuite().toDataIntegrityProof();
129
-
130
- // Use the config to add a proof to the unsigned update
131
- return diproof.addProof(unsignedUpdate, config);
132
- }
133
-
134
- /**
135
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
136
- * BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
137
- * @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
138
- * @param {SignedBTCR2Update} update The signed update object to be announced.
139
- * @param {KeyBytes} secretKey The private key used to sign the update for announcement.
140
- * @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
141
- * @throws {UpdateError} if the beaconService type is invalid
142
- */
143
- static async announce(
144
- beaconService: BeaconService,
145
- update: SignedBTCR2Update,
146
- secretKey: KeyBytes,
147
- bitcoin: BitcoinConnection
148
- ): Promise<SignedBTCR2Update> {
149
- // Establish a beacon object
150
- const beacon = BeaconFactory.establish(beaconService);
151
-
152
- // Broadcast the update
153
- const result = await beacon.broadcastSignal(update, secretKey, bitcoin);
154
-
155
- // Return the sidecarData
156
- return result;
157
- }
158
- }