@did-btcr2/method 0.19.0 → 0.22.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 (120) hide show
  1. package/README.md +223 -1
  2. package/dist/browser.js +3496 -4202
  3. package/dist/browser.mjs +3496 -4202
  4. package/dist/cjs/core/beacon/beacon.js +25 -0
  5. package/dist/cjs/core/beacon/beacon.js.map +1 -0
  6. package/dist/cjs/core/beacon/cas-beacon.js +20 -36
  7. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
  8. package/dist/cjs/core/beacon/error.js +4 -4
  9. package/dist/cjs/core/beacon/error.js.map +1 -1
  10. package/dist/cjs/core/beacon/factory.js +5 -7
  11. package/dist/cjs/core/beacon/factory.js.map +1 -1
  12. package/dist/cjs/core/beacon/interfaces.js +1 -31
  13. package/dist/cjs/core/beacon/interfaces.js.map +1 -1
  14. package/dist/cjs/core/beacon/signal-discovery.js +183 -0
  15. package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
  16. package/dist/cjs/core/beacon/singleton.js +56 -86
  17. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  18. package/dist/cjs/core/beacon/smt-beacon.js +22 -39
  19. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
  20. package/dist/cjs/core/beacon/utils.js +4 -9
  21. package/dist/cjs/core/beacon/utils.js.map +1 -1
  22. package/dist/cjs/core/resolve.js +121 -307
  23. package/dist/cjs/core/resolve.js.map +1 -1
  24. package/dist/cjs/core/update.js +62 -154
  25. package/dist/cjs/core/update.js.map +1 -1
  26. package/dist/cjs/did-btcr2.js +100 -91
  27. package/dist/cjs/did-btcr2.js.map +1 -1
  28. package/dist/cjs/index.js +3 -1
  29. package/dist/cjs/index.js.map +1 -1
  30. package/dist/cjs/utils/appendix.js +6 -15
  31. package/dist/cjs/utils/appendix.js.map +1 -1
  32. package/dist/cjs/utils/did-document-builder.js +5 -6
  33. package/dist/cjs/utils/did-document-builder.js.map +1 -1
  34. package/dist/cjs/utils/did-document.js +42 -38
  35. package/dist/cjs/utils/did-document.js.map +1 -1
  36. package/dist/esm/core/beacon/beacon.js +25 -0
  37. package/dist/esm/core/beacon/beacon.js.map +1 -0
  38. package/dist/esm/core/beacon/cas-beacon.js +20 -36
  39. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  40. package/dist/esm/core/beacon/error.js +4 -4
  41. package/dist/esm/core/beacon/error.js.map +1 -1
  42. package/dist/esm/core/beacon/factory.js +5 -7
  43. package/dist/esm/core/beacon/factory.js.map +1 -1
  44. package/dist/esm/core/beacon/interfaces.js +1 -31
  45. package/dist/esm/core/beacon/interfaces.js.map +1 -1
  46. package/dist/esm/core/beacon/signal-discovery.js +183 -0
  47. package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
  48. package/dist/esm/core/beacon/singleton.js +56 -86
  49. package/dist/esm/core/beacon/singleton.js.map +1 -1
  50. package/dist/esm/core/beacon/smt-beacon.js +22 -39
  51. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  52. package/dist/esm/core/beacon/utils.js +4 -9
  53. package/dist/esm/core/beacon/utils.js.map +1 -1
  54. package/dist/esm/core/resolve.js +121 -307
  55. package/dist/esm/core/resolve.js.map +1 -1
  56. package/dist/esm/core/update.js +62 -154
  57. package/dist/esm/core/update.js.map +1 -1
  58. package/dist/esm/did-btcr2.js +100 -91
  59. package/dist/esm/did-btcr2.js.map +1 -1
  60. package/dist/esm/index.js +3 -1
  61. package/dist/esm/index.js.map +1 -1
  62. package/dist/esm/utils/appendix.js +6 -15
  63. package/dist/esm/utils/appendix.js.map +1 -1
  64. package/dist/esm/utils/did-document-builder.js +5 -6
  65. package/dist/esm/utils/did-document-builder.js.map +1 -1
  66. package/dist/esm/utils/did-document.js +42 -38
  67. package/dist/esm/utils/did-document.js.map +1 -1
  68. package/dist/types/core/beacon/beacon.d.ts +44 -0
  69. package/dist/types/core/beacon/beacon.d.ts.map +1 -0
  70. package/dist/types/core/beacon/cas-beacon.d.ts +19 -30
  71. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  72. package/dist/types/core/beacon/error.d.ts +2 -2
  73. package/dist/types/core/beacon/error.d.ts.map +1 -1
  74. package/dist/types/core/beacon/factory.d.ts +4 -6
  75. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  76. package/dist/types/core/beacon/interfaces.d.ts +7 -46
  77. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  78. package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
  79. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
  80. package/dist/types/core/beacon/singleton.d.ts +17 -30
  81. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  82. package/dist/types/core/beacon/smt-beacon.d.ts +21 -33
  83. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  84. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  85. package/dist/types/core/interfaces.d.ts +1 -8
  86. package/dist/types/core/interfaces.d.ts.map +1 -1
  87. package/dist/types/core/resolve.d.ts +34 -47
  88. package/dist/types/core/resolve.d.ts.map +1 -1
  89. package/dist/types/core/types.d.ts +21 -8
  90. package/dist/types/core/types.d.ts.map +1 -1
  91. package/dist/types/core/update.d.ts +30 -73
  92. package/dist/types/core/update.d.ts.map +1 -1
  93. package/dist/types/did-btcr2.d.ts +44 -47
  94. package/dist/types/did-btcr2.d.ts.map +1 -1
  95. package/dist/types/index.d.ts +3 -1
  96. package/dist/types/index.d.ts.map +1 -1
  97. package/dist/types/utils/appendix.d.ts.map +1 -1
  98. package/dist/types/utils/did-document-builder.d.ts +5 -1
  99. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  100. package/dist/types/utils/did-document.d.ts +26 -21
  101. package/dist/types/utils/did-document.d.ts.map +1 -1
  102. package/package.json +8 -7
  103. package/src/core/beacon/beacon.ts +58 -0
  104. package/src/core/beacon/cas-beacon.ts +30 -44
  105. package/src/core/beacon/error.ts +5 -6
  106. package/src/core/beacon/factory.ts +7 -9
  107. package/src/core/beacon/interfaces.ts +7 -64
  108. package/src/core/beacon/signal-discovery.ts +237 -0
  109. package/src/core/beacon/singleton.ts +78 -100
  110. package/src/core/beacon/smt-beacon.ts +32 -49
  111. package/src/core/beacon/utils.ts +16 -13
  112. package/src/core/interfaces.ts +1 -9
  113. package/src/core/resolve.ts +163 -395
  114. package/src/core/types.ts +25 -8
  115. package/src/core/update.ts +91 -236
  116. package/src/did-btcr2.ts +154 -116
  117. package/src/index.ts +8 -1
  118. package/src/utils/appendix.ts +8 -22
  119. package/src/utils/did-document-builder.ts +5 -7
  120. package/src/utils/did-document.ts +80 -73
@@ -1,7 +1,9 @@
1
1
  import { getNetwork } from '@did-btcr2/bitcoin';
2
2
  import {
3
3
  BTCR2_DID_DOCUMENT_CONTEXT,
4
+ Canonicalization,
4
5
  DidDocumentError,
6
+ HashBytes,
5
7
  IdentifierTypes,
6
8
  INVALID_DID_DOCUMENT,
7
9
  JSONObject,
@@ -9,12 +11,12 @@ import {
9
11
  KeyBytes
10
12
  } from '@did-btcr2/common';
11
13
  import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
12
- import { DidService, DidDocument as IIDidDocument, DidVerificationMethod as IIDidVerificationMethod } from '@web5/dids';
14
+ import { DidDocument as W3CDidDocument, DidVerificationMethod as W3CDidVerificationMethod } from '@web5/dids';
15
+ import { payments } from 'bitcoinjs-lib';
13
16
  import { BeaconService } from '../core/beacon/interfaces.js';
14
17
  import { BeaconUtils } from '../core/beacon/utils.js';
15
18
  import { Identifier } from '../core/identifier.js';
16
19
  import { Appendix } from './appendix.js';
17
- import { payments } from 'bitcoinjs-lib';
18
20
 
19
21
  export const ID_PLACEHOLDER_VALUE = 'did:btcr2:_';
20
22
  export const BECH32M_CHARS = '';
@@ -36,7 +38,11 @@ export type VerificationRelationships = {
36
38
  capabilityDelegation?: Array<string | DidVerificationMethod>;
37
39
  }
38
40
 
39
- export interface IDidVerificationMethod extends IIDidVerificationMethod {
41
+ /** Loose type for unvalidated DID / Genesis document-like input objects. */
42
+ export type DidDocumentLike = Partial<Btcr2DidDocument>;
43
+ export type GenesisDocumentLike = Partial<Btcr2DidDocument>;
44
+
45
+ export interface Btcr2VerificationMethod extends W3CDidVerificationMethod {
40
46
  id: string;
41
47
  type: string;
42
48
  controller: string;
@@ -50,14 +56,14 @@ export interface IDidVerificationMethod extends IIDidVerificationMethod {
50
56
  * @type {DidVerificationMethod}
51
57
  *
52
58
  */
53
- export class DidVerificationMethod implements IDidVerificationMethod {
59
+ export class DidVerificationMethod implements Btcr2VerificationMethod {
54
60
  id: string;
55
61
  type: string;
56
62
  controller: string;
57
63
  publicKeyMultibase: string;
58
64
  secretKeyMultibase?: string | undefined;
59
65
 
60
- constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }: IDidVerificationMethod) {
66
+ constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }: Btcr2VerificationMethod) {
61
67
  this.id = id;
62
68
  this.type = type;
63
69
  this.controller = controller;
@@ -72,11 +78,10 @@ export class DidVerificationMethod implements IDidVerificationMethod {
72
78
 
73
79
  /**
74
80
  * BTCR2 DID Document Interface
75
- * @interface IDidDocument
76
- * @type {IDidDocument}
77
- * @extends {IIDidDocument}
81
+ * @interface Btcr2DidDocument
82
+ * @type {Btcr2DidDocument}
83
+ * @extends {W3CDidDocument}
78
84
  * @property {string} id - The identifier of the DID Document.
79
- * @property {Array<string>} [controller] - The controller of the DID Document.
80
85
  * @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
81
86
  * @property {Array<DidVerificationMethod>} verificationMethod - The verification methods of the DID Document.
82
87
  * @property {Array<string | DidVerificationMethod>} [authentication] - The authentication methods of the DID Document.
@@ -85,9 +90,8 @@ export class DidVerificationMethod implements IDidVerificationMethod {
85
90
  * @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
86
91
  * @property {Array<BeaconService>} service - The services of the DID Document.
87
92
  */
88
- export interface IDidDocument extends IIDidDocument {
93
+ export interface Btcr2DidDocument extends W3CDidDocument {
89
94
  id: string;
90
- controller?: Array<string>;
91
95
  '@context'?: Array<string | JSONObject>;
92
96
  verificationMethod: Array<DidVerificationMethod>;
93
97
  authentication?: Array<string | DidVerificationMethod>;
@@ -101,9 +105,8 @@ export interface IDidDocument extends IIDidDocument {
101
105
  * BTCR2 DID Document extends the DidDocument class adding helper methods and properties
102
106
  * @class DidDocument
103
107
  * @type {DidDocument}
104
- * @implements {IDidDocument}
108
+ * @implements {Btcr2DidDocument}
105
109
  * @property {string} id - The identifier of the DID Document.
106
- * @property {Array<string>} [controller] - The controller of the DID Document.
107
110
  * @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
108
111
  * @property {Array<DidVerificationMethod>} verificationMethod - The verification methods of the DID Document.
109
112
  * @property {Array<string | DidVerificationMethod>} [authentication] - The authentication methods of the DID Document.
@@ -112,10 +115,12 @@ export interface IDidDocument extends IIDidDocument {
112
115
  * @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
113
116
  * @property {Array<BeaconService>} service - The services of the DID Document.
114
117
  */
115
- export class DidDocument implements IDidDocument {
118
+ export class DidDocument implements Btcr2DidDocument {
116
119
  id: string;
117
- controller?: Array<string>;
118
- '@context'?: Array<string | JSONObject> = BTCR2_DID_DOCUMENT_CONTEXT;
120
+ '@context'?: Array<string | JSONObject> = [
121
+ 'https://www.w3.org/TR/did-1.1',
122
+ 'https://btcr2.dev/context/v1'
123
+ ];
119
124
  verificationMethod: Array<DidVerificationMethod>;
120
125
  authentication?: Array<string | DidVerificationMethod>;
121
126
  assertionMethod?: Array<string | DidVerificationMethod>;
@@ -124,9 +129,14 @@ export class DidDocument implements IDidDocument {
124
129
  service: Array<BeaconService>;
125
130
  deactivated?: boolean;
126
131
 
127
- constructor(document: IDidDocument) {
132
+ constructor(document: DidDocumentLike) {
133
+ // Ensure document has an id
134
+ if(!document.id) {
135
+ throw new DidDocumentError('DID Document must have an id', INVALID_DID_DOCUMENT, document);
136
+ }
137
+
128
138
  // Set the ID and ID type
129
- const idType = document.id.includes('k')
139
+ const idType = document.id.includes('k1')
130
140
  ? IdentifierTypes.KEY
131
141
  : IdentifierTypes.EXTERNAL;
132
142
 
@@ -134,16 +144,13 @@ export class DidDocument implements IDidDocument {
134
144
  const isGenesis = document.id === ID_PLACEHOLDER_VALUE;
135
145
 
136
146
  // Deconstruct the document parts for validation
137
- const { id, controller, verificationMethod: vm, service } = document;
147
+ const { id, verificationMethod: vm, service } = document;
138
148
 
139
149
  // If not genesis, validate core properties
140
150
  if (!isGenesis) {
141
151
  if (!DidDocument.isValidId(id)) {
142
152
  throw new DidDocumentError(`Invalid id: ${id}`, INVALID_DID_DOCUMENT, document);
143
153
  }
144
- if(!DidDocument.isValidController(controller ?? [id])) {
145
- throw new DidDocumentError(`Invalid controller: ${controller}`, INVALID_DID_DOCUMENT, document);
146
- }
147
154
  if (!DidDocument.isValidVerificationMethods(vm)) {
148
155
  throw new DidDocumentError('Invalid verificationMethod: ' + vm, INVALID_DID_DOCUMENT, document);
149
156
  }
@@ -154,10 +161,12 @@ export class DidDocument implements IDidDocument {
154
161
 
155
162
  // Set core properties
156
163
  this.id = document.id;
157
- this.verificationMethod = document.verificationMethod;
158
- this.service = document.service;
159
- this['@context'] = document['@context'] || BTCR2_DID_DOCUMENT_CONTEXT;
160
- this.controller = document.controller || [this.id];
164
+ this.verificationMethod = document.verificationMethod || [];
165
+ this.service = document.service || [];
166
+ this['@context'] = document['@context'] || [
167
+ 'https://www.w3.org/TR/did-1.1',
168
+ 'https://btcr2.dev/context/v1'
169
+ ];
161
170
 
162
171
  // Relationships logic based on idType
163
172
  if (idType === IdentifierTypes.KEY) {
@@ -177,11 +186,12 @@ export class DidDocument implements IDidDocument {
177
186
 
178
187
  // Sanitize the DID Document
179
188
  DidDocument.sanitize(this);
189
+
180
190
  // If the DID Document is not an intermediateDocument, validate it
181
- if (!isGenesis) {
182
- DidDocument.validate(this);
183
- } else {
191
+ if (isGenesis) {
184
192
  this.validateGenesis();
193
+ } else {
194
+ DidDocument.validate(this);
185
195
  }
186
196
  }
187
197
 
@@ -189,7 +199,7 @@ export class DidDocument implements IDidDocument {
189
199
  * Convert the DidDocument to a JSON object.
190
200
  * @returns {DidDocument} The JSON representation of the DidDocument.
191
201
  */
192
- public json(): DidDocument {
202
+ public json(): object {
193
203
  return Object.fromEntries(Object.entries(this)) as DidDocument;
194
204
  }
195
205
 
@@ -218,7 +228,7 @@ export class DidDocument implements IDidDocument {
218
228
  })
219
229
  ],
220
230
  service
221
- } as IDidDocument;
231
+ } as Btcr2DidDocument;
222
232
  return new DidDocument(document);
223
233
  }
224
234
 
@@ -228,7 +238,7 @@ export class DidDocument implements IDidDocument {
228
238
  * @returns {DidDocument} A new DidDocument.
229
239
  */
230
240
  public static fromExternalIdentifier(data: ExternalData): DidDocument {
231
- return new DidDocument(data as IDidDocument);
241
+ return new DidDocument(data as Btcr2DidDocument);
232
242
  }
233
243
 
234
244
 
@@ -251,7 +261,7 @@ export class DidDocument implements IDidDocument {
251
261
  * @returns {boolean} True if the DID document is valid.
252
262
  * @throws {DidDocumentError} If any validation check fails.
253
263
  */
254
- public static isValid(didDocument: DidDocument): boolean {
264
+ public static isValid(didDocument: DidDocumentLike): boolean {
255
265
  if (!this.isValidContext(didDocument?.['@context'])) {
256
266
  throw new DidDocumentError('Invalid "@context"', INVALID_DID_DOCUMENT, didDocument);
257
267
  }
@@ -276,7 +286,7 @@ export class DidDocument implements IDidDocument {
276
286
  * @param {DidDocument['@context']} context The context to validate.
277
287
  * @returns {boolean} True if the context is valid.
278
288
  */
279
- private static isValidContext(context: DidDocument['@context']): boolean {
289
+ private static isValidContext(context: unknown): boolean {
280
290
  if(!context) return false;
281
291
  if(!Array.isArray(context)) return false;
282
292
  if(!context.every(ctx => typeof ctx === 'string' && BTCR2_DID_DOCUMENT_CONTEXT.includes(ctx))) return false;
@@ -289,7 +299,8 @@ export class DidDocument implements IDidDocument {
289
299
  * @param {string} id The id to validate.
290
300
  * @returns {boolean} True if the id is valid.
291
301
  */
292
- private static isValidId(id: string): boolean {
302
+ private static isValidId(id: unknown): boolean {
303
+ if (typeof id !== 'string') return false;
293
304
  try {
294
305
  Identifier.decode(id);
295
306
  return true;
@@ -316,7 +327,7 @@ export class DidDocument implements IDidDocument {
316
327
  * @param {DidVerificationMethod[]} verificationMethod The verification methods to validate.
317
328
  * @returns {boolean} True if the verification methods are valid.
318
329
  */
319
- private static isValidVerificationMethods(verificationMethod: IIDidVerificationMethod[]): boolean {
330
+ private static isValidVerificationMethods(verificationMethod: unknown): boolean {
320
331
  return Array.isArray(verificationMethod) && verificationMethod.every(Appendix.isDidVerificationMethod);
321
332
  }
322
333
 
@@ -326,7 +337,7 @@ export class DidDocument implements IDidDocument {
326
337
  * @param {DidService[]} service The services to validate.
327
338
  * @returns {boolean} True if the services are valid.
328
339
  */
329
- private static isValidServices(service: DidService[]): boolean {
340
+ private static isValidServices(service: unknown): boolean {
330
341
  return Array.isArray(service) && service.every(BeaconUtils.isBeaconService);
331
342
  }
332
343
 
@@ -336,33 +347,25 @@ export class DidDocument implements IDidDocument {
336
347
  * @param {DidDocument} didDocument The DID Document to validate.
337
348
  * @returns {boolean} True if the verification relationships are valid.
338
349
  */
339
- public static isValidVerificationRelationships(didDocument: DidDocument): boolean {
340
- // Define the available verification relationships
341
- const possibleVerificationRelationships: (keyof DidDocument)[] = [
350
+ public static isValidVerificationRelationships(didDocument: DidDocumentLike): boolean {
351
+ const possibleVerificationRelationships = [
342
352
  'authentication',
343
353
  'assertionMethod',
344
354
  'capabilityInvocation',
345
355
  'capabilityDelegation'
346
- ];
347
-
348
- // Get the DID Document keys
349
- const verificationRelationships = Object.keys(didDocument) as Array<keyof DidDocument>;
350
-
351
- // Filter the DID Document keys to only those that are in the available verification relationships
352
- const availableVerificationRelationships = possibleVerificationRelationships.filter(
353
- key => verificationRelationships.includes(key as keyof DidDocument)
354
- ) as (keyof DidDocument)[];
355
-
356
- // Check if all available verification relationships are valid
357
- return availableVerificationRelationships.every((key) =>
358
- // Check if the key exists in the DID Document
359
- didDocument[key] &&
360
- // Check if the key is an array
361
- Array.isArray(didDocument[key]) &&
362
- // Check that every value in the array is a string or DidVerificationMethod
363
- didDocument[key].every(
364
- entry => typeof entry === 'string' || Appendix.isDidVerificationMethod(entry)
365
- ));
356
+ ] as const;
357
+
358
+ const keys = Object.keys(didDocument);
359
+ const availableKeys = possibleVerificationRelationships.filter(key => keys.includes(key));
360
+
361
+ return availableKeys.every((key) => {
362
+ const value = didDocument[key];
363
+ return value &&
364
+ Array.isArray(value) &&
365
+ value.every(
366
+ (entry) => typeof entry === 'string' || Appendix.isDidVerificationMethod(entry)
367
+ );
368
+ });
366
369
  }
367
370
 
368
371
  /**
@@ -370,7 +373,7 @@ export class DidDocument implements IDidDocument {
370
373
  * @returns {DidDocument} Validated DID Document.
371
374
  * @throws {DidDocumentError} If the DID Document is invalid.
372
375
  */
373
- public static validate(didDocument: DidDocument | GenesisDocument): DidDocument {
376
+ public static validate(didDocument: any): DidDocument {
374
377
  // Validate the DID Document
375
378
  if (didDocument.id === ID_PLACEHOLDER_VALUE) {
376
379
  (didDocument as GenesisDocument).validateGenesis();
@@ -390,10 +393,6 @@ export class DidDocument implements IDidDocument {
390
393
  if(this.id !== ID_PLACEHOLDER_VALUE) {
391
394
  throw new DidDocumentError('Invalid GenesisDocument ID', INVALID_DID_DOCUMENT, this);
392
395
  }
393
- // Validate the controller
394
- if(!this.controller?.every(c => c === ID_PLACEHOLDER_VALUE)) {
395
- throw new DidDocumentError('Invalid GenesisDocument controller', INVALID_DID_DOCUMENT, this);
396
- }
397
396
  // Validate the verificationMethod
398
397
  if(!this.verificationMethod.every(vm => vm.id.includes(ID_PLACEHOLDER_VALUE) && vm.controller === ID_PLACEHOLDER_VALUE)) {
399
398
  throw new DidDocumentError('Invalid GenesisDocument verificationMethod', INVALID_DID_DOCUMENT, this);
@@ -437,8 +436,8 @@ export class Document {
437
436
  * @extends {DidDocument}
438
437
  */
439
438
  export class GenesisDocument extends DidDocument {
440
- constructor(document: object | DidDocument) {
441
- super(document as DidDocument);
439
+ constructor(document: DidDocumentLike) {
440
+ super(document);
442
441
  }
443
442
 
444
443
  /**
@@ -448,7 +447,7 @@ export class GenesisDocument extends DidDocument {
448
447
  */
449
448
  public toDidDocument(did: string): DidDocument {
450
449
  const stringThis = JSON.stringify(this).replaceAll(ID_PLACEHOLDER_VALUE, did);
451
- const parseThis = JSON.parse(stringThis) as IDidDocument;
450
+ const parseThis = JSON.parse(stringThis) as Btcr2DidDocument;
452
451
  return new DidDocument(parseThis);
453
452
  }
454
453
 
@@ -459,7 +458,7 @@ export class GenesisDocument extends DidDocument {
459
458
  * @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
460
459
  */
461
460
  public static fromDidDocument(didDocument: DidDocument): GenesisDocument {
462
- const intermediateDocument = JSONUtils.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE) as IDidDocument;
461
+ const intermediateDocument = JSONUtils.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE) as Btcr2DidDocument;
463
462
  return new GenesisDocument(intermediateDocument);
464
463
  }
465
464
 
@@ -475,8 +474,7 @@ export class GenesisDocument extends DidDocument {
475
474
  relationships: VerificationRelationships,
476
475
  service: Array<BeaconService>
477
476
  ): GenesisDocument {
478
- const id = ID_PLACEHOLDER_VALUE;
479
- return new GenesisDocument({ id, ...relationships, verificationMethod, service, });
477
+ return new GenesisDocument({ id: ID_PLACEHOLDER_VALUE, ...relationships, verificationMethod, service, });
480
478
  }
481
479
 
482
480
  /**
@@ -489,7 +487,7 @@ export class GenesisDocument extends DidDocument {
489
487
  const id = ID_PLACEHOLDER_VALUE;
490
488
  const address = payments.p2pkh({ pubkey: pk.compressed, network: getNetwork(network) })?.address;
491
489
  const services = [{
492
- id : `${id}#key-0`,
490
+ id : `${id}#service-0`,
493
491
  serviceEndpoint : `bitcoin:${address}`,
494
492
  type : 'SingletonBeacon',
495
493
  }];
@@ -518,6 +516,15 @@ export class GenesisDocument extends DidDocument {
518
516
  * @returns {DidDocument} The created DidDocument.
519
517
  */
520
518
  public static fromJSON(object: object | DidDocument): GenesisDocument {
521
- return new GenesisDocument(object as IDidDocument);
519
+ return new GenesisDocument(object as Btcr2DidDocument);
520
+ }
521
+
522
+ /**
523
+ * Convert a GenesisDocument to genesis bytes.
524
+ * @param {GenesisDocument} genesisDocument The GenesisDocument to convert.
525
+ * @returns {Bytes} The genesis bytes.
526
+ */
527
+ static toGenesisBytes(genesisDocument: GenesisDocumentLike): HashBytes {
528
+ return Canonicalization.andHash(genesisDocument);
522
529
  }
523
530
  }