@did-btcr2/method 0.25.3 → 0.26.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 (233) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/browser.js +125307 -122227
  3. package/dist/browser.mjs +125266 -122186
  4. package/dist/cjs/index.js +5043 -43
  5. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
  6. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
  7. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
  8. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
  9. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
  10. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
  11. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
  12. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
  13. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
  14. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
  15. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
  16. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
  17. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +1 -2
  18. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  19. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  20. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  21. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
  22. package/dist/esm/core/beacon/cas-beacon.js +6 -4
  23. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  24. package/dist/esm/core/beacon/signal-discovery.js +1 -1
  25. package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
  26. package/dist/esm/core/beacon/singleton-beacon.js +3 -3
  27. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  28. package/dist/esm/core/beacon/utils.js.map +1 -1
  29. package/dist/esm/core/identifier.js.map +1 -1
  30. package/dist/esm/core/resolver.js +41 -35
  31. package/dist/esm/core/resolver.js.map +1 -1
  32. package/dist/esm/core/update.js.map +1 -1
  33. package/dist/esm/did-btcr2.js +1 -1
  34. package/dist/esm/did-btcr2.js.map +1 -1
  35. package/dist/esm/utils/appendix.js +7 -6
  36. package/dist/esm/utils/appendix.js.map +1 -1
  37. package/dist/esm/utils/did-document-builder.js.map +1 -1
  38. package/dist/esm/utils/did-document.js +2 -2
  39. package/dist/esm/utils/did-document.js.map +1 -1
  40. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +2 -2
  41. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -1
  42. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +10 -10
  43. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +1 -1
  44. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +1 -1
  45. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -1
  46. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +1 -1
  47. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
  48. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +1 -1
  49. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -1
  50. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +1 -1
  51. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -1
  52. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +1 -1
  53. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -1
  54. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +1 -1
  55. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -1
  56. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +1 -1
  57. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -1
  58. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +1 -1
  59. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -1
  60. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +1 -1
  61. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -1
  62. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +1 -1
  63. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -1
  64. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +4 -4
  65. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
  66. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +6 -6
  67. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  68. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +1 -1
  69. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +1 -1
  70. package/dist/types/core/beacon/aggregation/communication/service.d.ts +3 -3
  71. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +1 -1
  72. package/dist/types/core/beacon/aggregation/coordinator.d.ts +3 -3
  73. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  74. package/dist/types/core/beacon/aggregation/participant.d.ts +6 -6
  75. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  76. package/dist/types/core/beacon/aggregation/session/index.d.ts +2 -2
  77. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
  78. package/dist/types/core/beacon/beacon.d.ts +5 -5
  79. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  80. package/dist/types/core/beacon/cas-beacon.d.ts +5 -5
  81. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  82. package/dist/types/core/beacon/factory.d.ts +2 -2
  83. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  84. package/dist/types/core/beacon/interfaces.d.ts +3 -3
  85. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  86. package/dist/types/core/beacon/signal-discovery.d.ts +3 -3
  87. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
  88. package/dist/types/core/beacon/singleton-beacon.d.ts +5 -5
  89. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  90. package/dist/types/core/beacon/smt-beacon.d.ts +5 -5
  91. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  92. package/dist/types/core/beacon/utils.d.ts +4 -4
  93. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  94. package/dist/types/core/identifier.d.ts +2 -2
  95. package/dist/types/core/identifier.d.ts.map +1 -1
  96. package/dist/types/core/interfaces.d.ts +2 -2
  97. package/dist/types/core/interfaces.d.ts.map +1 -1
  98. package/dist/types/core/resolver.d.ts +8 -8
  99. package/dist/types/core/resolver.d.ts.map +1 -1
  100. package/dist/types/core/types.d.ts +6 -5
  101. package/dist/types/core/types.d.ts.map +1 -1
  102. package/dist/types/core/update.d.ts +5 -5
  103. package/dist/types/core/update.d.ts.map +1 -1
  104. package/dist/types/did-btcr2.d.ts +6 -6
  105. package/dist/types/did-btcr2.d.ts.map +1 -1
  106. package/dist/types/utils/appendix.d.ts +7 -7
  107. package/dist/types/utils/appendix.d.ts.map +1 -1
  108. package/dist/types/utils/did-document-builder.d.ts +3 -2
  109. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  110. package/dist/types/utils/did-document.d.ts +3 -3
  111. package/dist/types/utils/did-document.d.ts.map +1 -1
  112. package/package.json +7 -6
  113. package/src/core/beacon/aggregation/cohort/index.ts +3 -2
  114. package/src/core/beacon/aggregation/cohort/messages/index.ts +10 -10
  115. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +2 -1
  116. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +2 -1
  117. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +2 -1
  118. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +2 -1
  119. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +2 -1
  120. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +2 -1
  121. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +2 -1
  122. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +2 -1
  123. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +2 -1
  124. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +2 -1
  125. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +5 -4
  126. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +9 -7
  127. package/src/core/beacon/aggregation/communication/factory.ts +1 -1
  128. package/src/core/beacon/aggregation/communication/service.ts +3 -3
  129. package/src/core/beacon/aggregation/coordinator.ts +12 -8
  130. package/src/core/beacon/aggregation/participant.ts +12 -7
  131. package/src/core/beacon/aggregation/session/index.ts +3 -2
  132. package/src/core/beacon/beacon.ts +5 -5
  133. package/src/core/beacon/cas-beacon.ts +13 -9
  134. package/src/core/beacon/factory.ts +2 -2
  135. package/src/core/beacon/interfaces.ts +3 -3
  136. package/src/core/beacon/signal-discovery.ts +5 -4
  137. package/src/core/beacon/singleton-beacon.ts +8 -7
  138. package/src/core/beacon/smt-beacon.ts +5 -5
  139. package/src/core/beacon/utils.ts +6 -4
  140. package/src/core/identifier.ts +3 -2
  141. package/src/core/interfaces.ts +2 -2
  142. package/src/core/resolver.ts +59 -51
  143. package/src/core/types.ts +6 -5
  144. package/src/core/update.ts +11 -7
  145. package/src/did-btcr2.ts +12 -10
  146. package/src/utils/appendix.ts +14 -16
  147. package/src/utils/did-document-builder.ts +3 -2
  148. package/src/utils/did-document.ts +10 -8
  149. package/dist/cjs/core/beacon/aggregation/cohort/index.js +0 -237
  150. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +0 -1
  151. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +0 -26
  152. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  153. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  154. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  155. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +0 -98
  156. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  157. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  158. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  159. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  160. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  161. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  162. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  163. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  164. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  165. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  166. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  167. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  168. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  169. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  170. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  171. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  172. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  173. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  174. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  175. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  176. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  177. package/dist/cjs/core/beacon/aggregation/cohort/status.js +0 -8
  178. package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +0 -1
  179. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  180. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  181. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
  182. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  183. package/dist/cjs/core/beacon/aggregation/communication/error.js +0 -12
  184. package/dist/cjs/core/beacon/aggregation/communication/error.js.map +0 -1
  185. package/dist/cjs/core/beacon/aggregation/communication/factory.js +0 -21
  186. package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +0 -1
  187. package/dist/cjs/core/beacon/aggregation/communication/service.js +0 -2
  188. package/dist/cjs/core/beacon/aggregation/communication/service.js.map +0 -1
  189. package/dist/cjs/core/beacon/aggregation/coordinator.js +0 -343
  190. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +0 -1
  191. package/dist/cjs/core/beacon/aggregation/participant.js +0 -435
  192. package/dist/cjs/core/beacon/aggregation/participant.js.map +0 -1
  193. package/dist/cjs/core/beacon/aggregation/session/index.js +0 -244
  194. package/dist/cjs/core/beacon/aggregation/session/index.js.map +0 -1
  195. package/dist/cjs/core/beacon/aggregation/session/status.js +0 -11
  196. package/dist/cjs/core/beacon/aggregation/session/status.js.map +0 -1
  197. package/dist/cjs/core/beacon/beacon.js +0 -25
  198. package/dist/cjs/core/beacon/beacon.js.map +0 -1
  199. package/dist/cjs/core/beacon/cas-beacon.js +0 -152
  200. package/dist/cjs/core/beacon/cas-beacon.js.map +0 -1
  201. package/dist/cjs/core/beacon/error.js +0 -37
  202. package/dist/cjs/core/beacon/error.js.map +0 -1
  203. package/dist/cjs/core/beacon/factory.js +0 -29
  204. package/dist/cjs/core/beacon/factory.js.map +0 -1
  205. package/dist/cjs/core/beacon/interfaces.js +0 -2
  206. package/dist/cjs/core/beacon/interfaces.js.map +0 -1
  207. package/dist/cjs/core/beacon/signal-discovery.js +0 -183
  208. package/dist/cjs/core/beacon/signal-discovery.js.map +0 -1
  209. package/dist/cjs/core/beacon/singleton-beacon.js +0 -107
  210. package/dist/cjs/core/beacon/singleton-beacon.js.map +0 -1
  211. package/dist/cjs/core/beacon/smt-beacon.js +0 -39
  212. package/dist/cjs/core/beacon/smt-beacon.js.map +0 -1
  213. package/dist/cjs/core/beacon/utils.js +0 -163
  214. package/dist/cjs/core/beacon/utils.js.map +0 -1
  215. package/dist/cjs/core/identifier.js +0 -248
  216. package/dist/cjs/core/identifier.js.map +0 -1
  217. package/dist/cjs/core/interfaces.js +0 -2
  218. package/dist/cjs/core/interfaces.js.map +0 -1
  219. package/dist/cjs/core/resolver.js +0 -476
  220. package/dist/cjs/core/resolver.js.map +0 -1
  221. package/dist/cjs/core/types.js +0 -2
  222. package/dist/cjs/core/types.js.map +0 -1
  223. package/dist/cjs/core/update.js +0 -112
  224. package/dist/cjs/core/update.js.map +0 -1
  225. package/dist/cjs/did-btcr2.js +0 -193
  226. package/dist/cjs/did-btcr2.js.map +0 -1
  227. package/dist/cjs/index.js.map +0 -1
  228. package/dist/cjs/utils/appendix.js +0 -203
  229. package/dist/cjs/utils/appendix.js.map +0 -1
  230. package/dist/cjs/utils/did-document-builder.js +0 -60
  231. package/dist/cjs/utils/did-document-builder.js.map +0 -1
  232. package/dist/cjs/utils/did-document.js +0 -424
  233. package/dist/cjs/utils/did-document.js.map +0 -1
@@ -1,248 +0,0 @@
1
- import { BitcoinNetworkNames, IdentifierError, IdentifierTypes, INVALID_DID, METHOD_NOT_SUPPORTED } from '@did-btcr2/common';
2
- import { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
3
- import { bech32m } from '@scure/base';
4
- ;
5
- /**
6
- * Implements {@link https://dcdpr.github.io/did-btcr2/#syntax | 3 Syntax}.
7
- * A did:btcr2 DID consists of a did:btcr2 prefix, followed by an id-bech32 value, which is a Bech32m encoding of:
8
- * - the specification version;
9
- * - the Bitcoin network identifier; and
10
- * - either:
11
- * - a key-value representing a secp256k1 public key; or
12
- * - a hash-value representing the hash of an initiating external DID document.
13
- * @class Identifier
14
- * @type {Identifier}
15
- */
16
- export class Identifier {
17
- /**
18
- * Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-encoding | 3.2 did:btcr2 Identifier Encoding}.
19
- *
20
- * A did:btcr2 DID consists of a did:btcr2 prefix, followed by an id-bech32 value, which is a Bech32m encoding of:
21
- * - the specification version;
22
- * - the Bitcoin network identifier; and
23
- * - either:
24
- * - a key-value representing a secp256k1 public key; or
25
- * - a hash-value representing the hash of an initiating external DID document.
26
- *
27
- * @param {KeyBytes | DocumentBytes} genesisBytes The genesis bytes (public key or document bytes).
28
- * @param {DidCreateOptions} options The DID creation options.
29
- * @returns {string} The new did:btcr2 identifier.
30
- */
31
- static encode(genesisBytes, options) {
32
- // Deconstruct the options
33
- const { idType, version = 1, network } = options;
34
- // If idType is not a valid value per above, raise invalidDid error.
35
- if (!(idType in IdentifierTypes)) {
36
- throw new IdentifierError('Expected "idType" to be "KEY" or "EXTERNAL"', INVALID_DID, { idType });
37
- }
38
- // 2. If version is greater than 1, raise invalidDid error.
39
- if (isNaN(version) || version > 1) {
40
- throw new IdentifierError('Expected "version" to be 1', INVALID_DID, { version });
41
- }
42
- // 3. If network is not a valid value (bitcoin|signet|regtest|testnet3|testnet4|number), raise invalidDid error.
43
- if (typeof network === 'string' && !(network in BitcoinNetworkNames)) {
44
- throw new IdentifierError('Invalid "network" name', INVALID_DID, { network });
45
- }
46
- // 4. If network is a number and is outside the range of 1-8, raise invalidDid error.
47
- if (typeof network === 'number' && (network < 0 || network > 8)) {
48
- throw new IdentifierError('Invalid "network" number', INVALID_DID, { network });
49
- }
50
- // 5. If idType is “key” and genesisBytes is not a valid compressed secp256k1 public key, raise invalidDid error.
51
- if (idType === 'KEY') {
52
- try {
53
- new CompressedSecp256k1PublicKey(genesisBytes);
54
- }
55
- catch {
56
- throw new IdentifierError('Expected "genesisBytes" to be a valid compressed secp256k1 public key', INVALID_DID, { genesisBytes });
57
- }
58
- }
59
- // 6. Map idType to hrp from the following:
60
- // 6.1 “key” - “k”
61
- // 6.2 “external” - “x”
62
- const hrp = idType === 'KEY' ? 'k' : 'x';
63
- // 7. Create an empty nibbles numeric array.
64
- const nibbles = [];
65
- // 8. Set fCount equal to (version - 1) / 15, rounded down.
66
- const fCount = Math.floor((version - 1) / 15);
67
- // 9. Append hexadecimal F (decimal 15) to nibbles fCount times.
68
- for (let i = 0; i < fCount; i++) {
69
- nibbles.push(15);
70
- }
71
- // 10. Append (version - 1) mod 15 to nibbles.
72
- nibbles.push((version - 1) % 15);
73
- // 11. If network is a string, append the numeric value from the following map to nibbles:
74
- // "bitcoin" - 0
75
- // "signet" - 1
76
- // "regtest" - 2
77
- // "testnet3" - 3
78
- // "testnet4" - 4
79
- // "mutinynet" - 5
80
- if (typeof network === 'string') {
81
- nibbles.push(BitcoinNetworkNames[network]);
82
- }
83
- else if (typeof network === 'number') {
84
- // 12. If network is a number, append network + 11 to nibbles.
85
- nibbles.push(network + 11);
86
- }
87
- // 13. If the number of entries in nibbles is odd, append 0.
88
- if (nibbles.length % 2 !== 0) {
89
- nibbles.push(0);
90
- }
91
- // 14. Create a dataBytes byte array from nibbles, where index is from 0 to nibbles.length / 2 - 1 and
92
- // encodingBytes[index] = (nibbles[2 * index] << 4) | nibbles[2 * index + 1].
93
- if (fCount !== 0) {
94
- for (const index in Array.from({ length: (nibbles.length / 2) - 1 })) {
95
- throw new IdentifierError('Not implemented', 'NOT_IMPLEMENTED', { index });
96
- }
97
- }
98
- const dataBytes = new Uint8Array([(nibbles[2 * 0] << 4) | nibbles[2 * 0 + 1], ...genesisBytes]);
99
- // 18. Return identifier.
100
- return `did:btcr2:${bech32m.encodeFromBytes(hrp, dataBytes)}`;
101
- }
102
- /**
103
- * Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-decoding | 3.3 did:btcr2 Identifier Decoding}.
104
- * @param {string} identifier The BTCR2 DID to be parsed
105
- * @returns {DidComponents} The parsed identifier components. See {@link DidComponents} for details.
106
- * @throws {DidError} if an error occurs while parsing the identifier
107
- * @throws {DidErrorCode.InvalidDid} if identifier is invalid
108
- * @throws {DidErrorCode.MethodNotSupported} if the method is not supported
109
- */
110
- static decode(identifier) {
111
- // 1. Split identifier into an array of components at the colon : character.
112
- const components = identifier.split(':');
113
- // 2. If the length of the components array is not 3, raise invalidDid error.
114
- if (components.length !== 3) {
115
- throw new IdentifierError(`Invalid did: ${identifier}`, INVALID_DID, { identifier });
116
- }
117
- // Deconstruct the components of the identifier: scheme, method, encoded
118
- const [scheme, method, encoded] = components;
119
- // 3. If components[0] is not “did”, raise invalidDid error.
120
- if (scheme !== 'did') {
121
- throw new IdentifierError(`Invalid did: ${identifier}`, INVALID_DID, { identifier });
122
- }
123
- // 4. If components[1] is not “btcr2”, raise methodNotSupported error.
124
- if (method !== 'btcr2') {
125
- throw new IdentifierError(`Invalid did method: ${method}`, METHOD_NOT_SUPPORTED, { identifier });
126
- }
127
- // 5. Set encodedString to components[2].
128
- if (!encoded) {
129
- throw new IdentifierError(`Invalid method-specific id: ${identifier}`, INVALID_DID, { identifier });
130
- }
131
- // 6. Pass encodedString to the Bech32m Decoding algorithm, retrieving hrp and dataBytes.
132
- const { prefix: hrp, bytes: dataBytes } = bech32m.decodeToBytes(encoded);
133
- // 7. If the Bech32m decoding algorithm fails, raise invalidDid error.
134
- if (!['x', 'k'].includes(hrp)) {
135
- throw new IdentifierError(`Invalid hrp: ${hrp}`, INVALID_DID, { identifier });
136
- }
137
- if (!dataBytes) {
138
- throw new IdentifierError(`Failed to decode id: ${encoded}`, INVALID_DID, { identifier });
139
- }
140
- // 8. Map hrp to idType from the following:
141
- // “k” - “key”
142
- // “x” - “external”
143
- // other - raise invalidDid error
144
- const idType = hrp === 'k' ? 'KEY' : 'EXTERNAL';
145
- // 9. Set version to 1.
146
- let version = 1;
147
- let byteIndex = 0;
148
- // 10. If at any point in the remaining steps there are not enough nibbles to complete the process,
149
- // raise invalidDid error.
150
- let nibblesConsumed = 0;
151
- // 11. Start with the first nibble (the higher nibble of the first byte) of dataBytes.
152
- let currentByte = dataBytes[byteIndex];
153
- let versionNibble = currentByte >>> 4;
154
- // 12. Add the value of the current nibble to version.
155
- while (versionNibble === 0xF) {
156
- // 13. If the value of the nibble is hexadecimal F (decimal 15), advance to the next nibble (the lower nibble of
157
- // the current byte or the higher nibble of the next byte) and return to the previous step.
158
- version += 15;
159
- if (nibblesConsumed % 2 === 0) {
160
- versionNibble = currentByte & 0x0F;
161
- }
162
- else {
163
- currentByte = dataBytes[++byteIndex];
164
- versionNibble = currentByte >>> 4;
165
- }
166
- nibblesConsumed += 1;
167
- // 14. If version is greater than 1, raise invalidDid error.
168
- if (version > 1) {
169
- throw new IdentifierError(`Invalid version: ${version}`, INVALID_DID, { identifier });
170
- }
171
- }
172
- version += versionNibble;
173
- nibblesConsumed += 1;
174
- // 15. Advance to the next nibble and set networkValue to its value.
175
- let networkValue = nibblesConsumed % 2 === 0
176
- ? dataBytes[++byteIndex] >>> 4
177
- : currentByte & 0x0F;
178
- nibblesConsumed += 1;
179
- // 16. Map networkValue to network from the following:
180
- // 0 - "bitcoin"
181
- // 1 - "signet"
182
- // 2 - "regtest"
183
- // 3 - "testnet3"
184
- // 4 - "testnet4"
185
- // 5 - "mutinynet"
186
- // 6-7 - raise invalidDid error
187
- // 8-F - networkValue - 11
188
- let network = BitcoinNetworkNames[networkValue];
189
- if (!network) {
190
- if (networkValue >= 0x8 && networkValue <= 0xF) {
191
- network = networkValue - 11;
192
- }
193
- else {
194
- throw new IdentifierError(`Invalid did: ${identifier}`, INVALID_DID, { identifier });
195
- }
196
- }
197
- // 17. If the number of nibbles consumed is odd:
198
- if (nibblesConsumed % 2 === 1) {
199
- // 17.1 Advance to the next nibble and set fillerNibble to its value.
200
- const fillerNibble = currentByte & 0x0F;
201
- // 17.2 If fillerNibble is not 0, raise invalidDid error.
202
- if (fillerNibble !== 0) {
203
- throw new IdentifierError(`Invalid did: ${identifier}`, INVALID_DID, { identifier });
204
- }
205
- }
206
- // 18. Set genesisBytes to the remaining dataBytes.
207
- const genesisBytes = dataBytes.slice(byteIndex + 1);
208
- // 19. If idType is “key” and genesisBytes is not a valid compressed secp256k1 public key, raise invalidDid error.
209
- if (idType === 'KEY') {
210
- try {
211
- new CompressedSecp256k1PublicKey(genesisBytes);
212
- }
213
- catch {
214
- throw new IdentifierError(`Invalid genesisBytes: ${genesisBytes}`, INVALID_DID, { identifier });
215
- }
216
- }
217
- // 20. Return idType, version, network, and genesisBytes.
218
- return { idType, hrp, version, network, genesisBytes };
219
- }
220
- /**
221
- * Generates a new did:btcr2 identifier based on a newly generated key pair.
222
- * @returns {string} The new did:btcr2 identifier.
223
- */
224
- static generate() {
225
- const keyPair = SchnorrKeyPair.generate();
226
- const did = this.encode(keyPair.publicKey.compressed, {
227
- idType: 'KEY',
228
- version: 1,
229
- network: 'regtest'
230
- });
231
- return { keyPair: keyPair.exportJSON(), did };
232
- }
233
- /**
234
- * Validates a did:btcr2 identifier.
235
- * @param {string} identifier The did:btcr2 identifier to validate.
236
- * @returns {boolean} True if the identifier is valid, false otherwise.
237
- */
238
- static isValid(identifier) {
239
- try {
240
- this.decode(identifier);
241
- return true;
242
- }
243
- catch {
244
- return false;
245
- }
246
- }
247
- }
248
- //# sourceMappingURL=identifier.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identifier.js","sourceRoot":"","sources":["../../../src/core/identifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAwB,eAAe,EAAE,eAAe,EAAE,WAAW,EAAY,oBAAoB,EAAwB,MAAM,mBAAmB,CAAC;AACnL,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAWrC,CAAC;AAgBF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,UAAU;IACrB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,MAAM,CAAC,YAAsC,EAAE,OAAyB;QAC7E,0BAA0B;QAC1B,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAEjD,oEAAoE;QACpE,IAAI,CAAC,CAAC,MAAM,IAAI,eAAe,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,eAAe,CAAC,6CAA6C,EAAE,WAAW,EAAE,EAAC,MAAM,EAAC,CAAC,CAAC;QAClG,CAAC;QAED,2DAA2D;QAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,eAAe,CAAC,4BAA4B,EAAE,WAAW,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC;QAClF,CAAC;QAED,gHAAgH;QAChH,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,mBAAmB,CAAC,EAAE,CAAC;YACrE,MAAM,IAAI,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E,OAAO,EAAE,YAAY,EAAkB,CAAC;IACxE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACb,MAAM,OAAO,GAAI,cAAc,CAAC,QAAQ,EAAE,CAAC;QAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,EAClD;YACE,MAAM,EAAS,KAAK;YACpB,OAAO,EAAQ,CAAC;YAChB,OAAO,EAAQ,SAAS;SACzB,CACF,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,UAAkB;QAC/B,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/core/interfaces.ts"],"names":[],"mappings":""}