@did-btcr2/method 0.22.0 → 0.23.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 (105) hide show
  1. package/dist/browser.js +274 -1239
  2. package/dist/browser.mjs +274 -1239
  3. package/dist/cjs/core/beacon/aggregation/cohort/index.js +13 -2
  4. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
  5. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +7 -2
  6. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
  7. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
  8. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
  9. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
  10. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  11. package/dist/cjs/core/beacon/aggregation/session/index.js +15 -3
  12. package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
  13. package/dist/cjs/core/beacon/cas-beacon.js +1 -1
  14. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
  15. package/dist/cjs/core/beacon/signal-discovery.js +6 -6
  16. package/dist/cjs/core/beacon/signal-discovery.js.map +1 -1
  17. package/dist/cjs/core/beacon/singleton.js +13 -12
  18. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  19. package/dist/cjs/core/beacon/smt-beacon.js +1 -1
  20. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
  21. package/dist/cjs/core/identifier.js +11 -13
  22. package/dist/cjs/core/identifier.js.map +1 -1
  23. package/dist/cjs/core/resolve.js +14 -15
  24. package/dist/cjs/core/resolve.js.map +1 -1
  25. package/dist/cjs/core/update.js +2 -2
  26. package/dist/cjs/core/update.js.map +1 -1
  27. package/dist/cjs/did-btcr2.js +11 -14
  28. package/dist/cjs/did-btcr2.js.map +1 -1
  29. package/dist/cjs/utils/did-document.js +13 -2
  30. package/dist/cjs/utils/did-document.js.map +1 -1
  31. package/dist/esm/core/beacon/aggregation/cohort/index.js +13 -2
  32. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
  33. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +7 -2
  34. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
  35. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
  36. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
  37. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
  38. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  39. package/dist/esm/core/beacon/aggregation/session/index.js +15 -3
  40. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
  41. package/dist/esm/core/beacon/cas-beacon.js +1 -1
  42. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  43. package/dist/esm/core/beacon/signal-discovery.js +6 -6
  44. package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
  45. package/dist/esm/core/beacon/singleton.js +13 -12
  46. package/dist/esm/core/beacon/singleton.js.map +1 -1
  47. package/dist/esm/core/beacon/smt-beacon.js +1 -1
  48. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  49. package/dist/esm/core/identifier.js +11 -13
  50. package/dist/esm/core/identifier.js.map +1 -1
  51. package/dist/esm/core/resolve.js +14 -15
  52. package/dist/esm/core/resolve.js.map +1 -1
  53. package/dist/esm/core/update.js +2 -2
  54. package/dist/esm/core/update.js.map +1 -1
  55. package/dist/esm/did-btcr2.js +11 -14
  56. package/dist/esm/did-btcr2.js.map +1 -1
  57. package/dist/esm/utils/did-document.js +13 -2
  58. package/dist/esm/utils/did-document.js.map +1 -1
  59. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
  60. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -1
  61. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +1 -1
  62. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
  63. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
  64. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  65. package/dist/types/core/beacon/aggregation/session/index.d.ts +1 -1
  66. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
  67. package/dist/types/core/beacon/beacon.d.ts +3 -3
  68. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  69. package/dist/types/core/beacon/cas-beacon.d.ts +3 -3
  70. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  71. package/dist/types/core/beacon/signal-discovery.d.ts +5 -5
  72. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
  73. package/dist/types/core/beacon/singleton.d.ts +3 -3
  74. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  75. package/dist/types/core/beacon/smt-beacon.d.ts +3 -3
  76. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  77. package/dist/types/core/identifier.d.ts +17 -21
  78. package/dist/types/core/identifier.d.ts.map +1 -1
  79. package/dist/types/core/interfaces.d.ts +2 -2
  80. package/dist/types/core/interfaces.d.ts.map +1 -1
  81. package/dist/types/core/resolve.d.ts +3 -3
  82. package/dist/types/core/resolve.d.ts.map +1 -1
  83. package/dist/types/core/update.d.ts +2 -2
  84. package/dist/types/core/update.d.ts.map +1 -1
  85. package/dist/types/did-btcr2.d.ts +4 -4
  86. package/dist/types/did-btcr2.d.ts.map +1 -1
  87. package/dist/types/utils/did-document.d.ts +3 -1
  88. package/dist/types/utils/did-document.d.ts.map +1 -1
  89. package/package.json +5 -6
  90. package/src/core/beacon/aggregation/cohort/index.ts +13 -2
  91. package/src/core/beacon/aggregation/cohort/messages/base.ts +7 -2
  92. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +5 -12
  93. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +5 -8
  94. package/src/core/beacon/aggregation/session/index.ts +15 -3
  95. package/src/core/beacon/beacon.ts +3 -3
  96. package/src/core/beacon/cas-beacon.ts +3 -3
  97. package/src/core/beacon/signal-discovery.ts +9 -9
  98. package/src/core/beacon/singleton.ts +15 -15
  99. package/src/core/beacon/smt-beacon.ts +3 -3
  100. package/src/core/identifier.ts +31 -28
  101. package/src/core/interfaces.ts +2 -2
  102. package/src/core/resolve.ts +17 -18
  103. package/src/core/update.ts +4 -4
  104. package/src/did-btcr2.ts +21 -19
  105. package/src/utils/did-document.ts +14 -2
package/src/did-btcr2.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
1
+ import { BitcoinConnection } from '@did-btcr2/bitcoin';
2
2
  import {
3
3
  DocumentBytes,
4
4
  HexString,
@@ -8,6 +8,7 @@ import {
8
8
  KeyBytes,
9
9
  METHOD_NOT_SUPPORTED,
10
10
  MethodError,
11
+ MISSING_RESOLUTION_OPTIONS,
11
12
  MISSING_UPDATE_DATA,
12
13
  PatchOperation,
13
14
  ResolveError,
@@ -37,7 +38,7 @@ export type Btcr2Identifier = string;
37
38
 
38
39
  export interface DidCreateOptions {
39
40
  /** Type of identifier to create (key or external) */
40
- idType: 'KEY' | 'EXTERNAL';
41
+ idType: string;
41
42
  /** DID BTCR2 Version Number */
42
43
  version?: number;
43
44
  /** Bitcoin Network */
@@ -83,10 +84,7 @@ export class DidBtcr2 implements DidMethod {
83
84
  * const did = DidBtcr2.create(genesisBytes, { idType: 'KEY', network: 'regtest' });
84
85
  * ```
85
86
  */
86
- static create(
87
- genesisBytes: KeyBytes | DocumentBytes,
88
- options?: DidCreateOptions
89
- ): Btcr2Identifier {
87
+ static create(genesisBytes: KeyBytes | DocumentBytes, options?: DidCreateOptions): Btcr2Identifier {
90
88
  // Deconstruct the idType, version and network from the options, setting defaults if not given
91
89
  const { idType, version = 1, network = 'bitcoin' } = options || {};
92
90
 
@@ -98,7 +96,7 @@ export class DidBtcr2 implements DidMethod {
98
96
  }
99
97
 
100
98
  // Call identifier encoding algorithm
101
- return Identifier.encode({ idType, genesisBytes, version, network });
99
+ return Identifier.encode(genesisBytes, { idType, version, network });
102
100
  }
103
101
 
104
102
  /**
@@ -172,12 +170,11 @@ export class DidBtcr2 implements DidMethod {
172
170
 
173
171
  // Check if bitcoin driver provided
174
172
  if(!resolutionOptions?.drivers?.bitcoin) {
175
- // If not, initialize default drivers
176
- resolutionOptions.drivers = resolutionOptions.drivers || {};
177
- // Set bitcoin driver to default BitcoinNetworkConnection
178
- resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection();
179
- // Set the network based on the decoded identifier
180
- resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
173
+ throw new ResolveError(
174
+ 'Bitcoin connection required for resolve. Pass a configured driver via '
175
+ + 'resolutionOptions.drivers.bitcoin or use DidBtcr2Api which injects it automatically.',
176
+ MISSING_RESOLUTION_OPTIONS, resolutionOptions
177
+ );
181
178
  }
182
179
 
183
180
  // Get the bitcoin driver from the resolution options
@@ -217,9 +214,8 @@ export class DidBtcr2 implements DidMethod {
217
214
  // Return didResolutionResult;
218
215
  return didResolutionResult;
219
216
  } catch (error: any) {
220
- console.error(error);
221
217
  // Rethrow any unexpected errors that are not a `ResolveError`.
222
- if (!(error instanceof ResolveError)) throw new Error(error);
218
+ if (!(error instanceof ResolveError)) throw new Error(error.message ?? error, { cause: error });
223
219
 
224
220
  // Return a DID Resolution Result with the appropriate error code.
225
221
  return {
@@ -247,7 +243,7 @@ export class DidBtcr2 implements DidMethod {
247
243
  * @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
248
244
  * @param {string} params.beaconId The beacon ID associated with the update.
249
245
  * @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
250
- * @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
246
+ * @param {BitcoinConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
251
247
  * @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
252
248
  * @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
253
249
  * header is not `zQ3s`
@@ -267,7 +263,7 @@ export class DidBtcr2 implements DidMethod {
267
263
  verificationMethodId: string;
268
264
  beaconId: string;
269
265
  signingMaterial?: KeyBytes | HexString;
270
- bitcoin?: BitcoinNetworkConnection;
266
+ bitcoin?: BitcoinConnection;
271
267
  }): Promise<SignedBTCR2Update> {
272
268
  // TODO: provide KMS as alternative
273
269
  // If no signingMaterial provided, throw an UpdateError with INVALID_DID_UPDATE.
@@ -337,8 +333,14 @@ export class DidBtcr2 implements DidMethod {
337
333
  INVALID_DID_UPDATE, {sourceDocument, beaconId}
338
334
  );
339
335
  }
340
- // If no bitcoin network connection provided, initialize default
341
- bitcoin ??= new BitcoinNetworkConnection();
336
+ // Require an explicit bitcoin connection no silent env-var fallback
337
+ if (!bitcoin) {
338
+ throw new UpdateError(
339
+ 'Bitcoin connection required for update. Pass a configured `bitcoin` parameter '
340
+ + 'or use DidBtcr2Api which injects it automatically.',
341
+ INVALID_DID_UPDATE, { beaconId }
342
+ );
343
+ }
342
344
 
343
345
  // Announce the signed update to the blockchain using the specified beacon(s)
344
346
  await Update.announce(beaconService, signed, secretKey, bitcoin);
@@ -99,6 +99,7 @@ export interface Btcr2DidDocument extends W3CDidDocument {
99
99
  capabilityInvocation?: Array<string | DidVerificationMethod>;
100
100
  capabilityDelegation?: Array<string | DidVerificationMethod>;
101
101
  service: Array<BeaconService>;
102
+ deactivated?: boolean;
102
103
  }
103
104
 
104
105
  /**
@@ -114,6 +115,7 @@ export interface Btcr2DidDocument extends W3CDidDocument {
114
115
  * @property {Array<string | DidVerificationMethod>} [capabilityInvocation] - The capability invocation methods of the DID Document.
115
116
  * @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
116
117
  * @property {Array<BeaconService>} service - The services of the DID Document.
118
+ * @property {boolean} [deactivated] - Indicates if the DID Document is deactivated.
117
119
  */
118
120
  export class DidDocument implements Btcr2DidDocument {
119
121
  id: string;
@@ -199,8 +201,18 @@ export class DidDocument implements Btcr2DidDocument {
199
201
  * Convert the DidDocument to a JSON object.
200
202
  * @returns {DidDocument} The JSON representation of the DidDocument.
201
203
  */
202
- public json(): object {
203
- return Object.fromEntries(Object.entries(this)) as DidDocument;
204
+ public toJSON(): DidDocumentLike {
205
+ return {
206
+ id : this.id,
207
+ '@context' : this['@context'],
208
+ verificationMethod : this.verificationMethod,
209
+ authentication : this.authentication,
210
+ assertionMethod : this.assertionMethod,
211
+ capabilityInvocation : this.capabilityInvocation,
212
+ capabilityDelegation : this.capabilityDelegation,
213
+ service : this.service,
214
+ deactivated : this.deactivated
215
+ };
204
216
  }
205
217
 
206
218
  /**