@did-btcr2/method 0.24.1 → 0.25.2

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 (101) hide show
  1. package/dist/browser.js +1541 -26561
  2. package/dist/browser.mjs +1541 -26561
  3. package/dist/cjs/core/beacon/aggregation/cohort/index.js +2 -1
  4. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
  5. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +3 -2
  6. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  7. package/dist/cjs/core/beacon/aggregation/coordinator.js +2 -1
  8. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
  9. package/dist/cjs/core/beacon/aggregation/participant.js +3 -2
  10. package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
  11. package/dist/cjs/core/beacon/beacon.js.map +1 -1
  12. package/dist/cjs/core/beacon/cas-beacon.js +120 -7
  13. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
  14. package/dist/cjs/core/beacon/factory.js +1 -1
  15. package/dist/cjs/core/beacon/factory.js.map +1 -1
  16. package/dist/cjs/core/beacon/signal-discovery.js +1 -1
  17. package/dist/cjs/core/beacon/signal-discovery.js.map +1 -1
  18. package/dist/cjs/core/beacon/{singleton.js → singleton-beacon.js} +20 -27
  19. package/dist/cjs/core/beacon/singleton-beacon.js.map +1 -0
  20. package/dist/cjs/core/beacon/smt-beacon.js +1 -1
  21. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
  22. package/dist/{esm/core/resolve.js → cjs/core/resolver.js} +241 -93
  23. package/dist/cjs/core/resolver.js.map +1 -0
  24. package/dist/cjs/core/update.js +5 -5
  25. package/dist/cjs/core/update.js.map +1 -1
  26. package/dist/cjs/did-btcr2.js +39 -96
  27. package/dist/cjs/did-btcr2.js.map +1 -1
  28. package/dist/cjs/index.js +2 -2
  29. package/dist/cjs/index.js.map +1 -1
  30. package/dist/esm/core/beacon/aggregation/cohort/index.js +2 -1
  31. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
  32. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +3 -2
  33. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  34. package/dist/esm/core/beacon/aggregation/coordinator.js +2 -1
  35. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  36. package/dist/esm/core/beacon/aggregation/participant.js +3 -2
  37. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  38. package/dist/esm/core/beacon/beacon.js.map +1 -1
  39. package/dist/esm/core/beacon/cas-beacon.js +120 -7
  40. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  41. package/dist/esm/core/beacon/factory.js +1 -1
  42. package/dist/esm/core/beacon/factory.js.map +1 -1
  43. package/dist/esm/core/beacon/signal-discovery.js +1 -1
  44. package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
  45. package/dist/esm/core/beacon/{singleton.js → singleton-beacon.js} +20 -27
  46. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -0
  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/{cjs/core/resolve.js → esm/core/resolver.js} +241 -93
  50. package/dist/esm/core/resolver.js.map +1 -0
  51. package/dist/esm/core/update.js +5 -5
  52. package/dist/esm/core/update.js.map +1 -1
  53. package/dist/esm/did-btcr2.js +39 -96
  54. package/dist/esm/did-btcr2.js.map +1 -1
  55. package/dist/esm/index.js +2 -2
  56. package/dist/esm/index.js.map +1 -1
  57. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -1
  58. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  59. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  60. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  61. package/dist/types/core/beacon/beacon.d.ts +9 -4
  62. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  63. package/dist/types/core/beacon/cas-beacon.d.ts +26 -7
  64. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  65. package/dist/types/core/beacon/{singleton.d.ts → singleton-beacon.d.ts} +7 -5
  66. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -0
  67. package/dist/types/core/beacon/smt-beacon.d.ts +4 -3
  68. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  69. package/dist/types/core/interfaces.d.ts +5 -15
  70. package/dist/types/core/interfaces.d.ts.map +1 -1
  71. package/dist/types/core/resolver.d.ts +167 -0
  72. package/dist/types/core/resolver.d.ts.map +1 -0
  73. package/dist/types/core/update.d.ts +3 -3
  74. package/dist/types/core/update.d.ts.map +1 -1
  75. package/dist/types/did-btcr2.d.ts +16 -16
  76. package/dist/types/did-btcr2.d.ts.map +1 -1
  77. package/dist/types/index.d.ts +2 -2
  78. package/dist/types/index.d.ts.map +1 -1
  79. package/package.json +5 -6
  80. package/src/core/beacon/aggregation/cohort/index.ts +2 -1
  81. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +3 -2
  82. package/src/core/beacon/aggregation/coordinator.ts +2 -1
  83. package/src/core/beacon/aggregation/participant.ts +3 -2
  84. package/src/core/beacon/beacon.ts +9 -5
  85. package/src/core/beacon/cas-beacon.ts +157 -10
  86. package/src/core/beacon/factory.ts +1 -1
  87. package/src/core/beacon/signal-discovery.ts +1 -1
  88. package/src/core/beacon/{singleton.ts → singleton-beacon.ts} +21 -36
  89. package/src/core/beacon/smt-beacon.ts +4 -3
  90. package/src/core/interfaces.ts +5 -16
  91. package/src/core/{resolve.ts → resolver.ts} +355 -130
  92. package/src/core/update.ts +7 -7
  93. package/src/did-btcr2.ts +42 -132
  94. package/src/index.ts +2 -2
  95. package/dist/cjs/core/beacon/singleton.js.map +0 -1
  96. package/dist/cjs/core/resolve.js.map +0 -1
  97. package/dist/esm/core/beacon/singleton.js.map +0 -1
  98. package/dist/esm/core/resolve.js.map +0 -1
  99. package/dist/types/core/beacon/singleton.d.ts.map +0 -1
  100. package/dist/types/core/resolve.d.ts +0 -93
  101. package/dist/types/core/resolve.d.ts.map +0 -1
@@ -2,7 +2,7 @@ import { MethodError } from '@did-btcr2/common';
2
2
  import { Beacon } from './beacon.js';
3
3
  import { CASBeacon } from './cas-beacon.js';
4
4
  import { BeaconService } from './interfaces.js';
5
- import { SingletonBeacon } from './singleton.js';
5
+ import { SingletonBeacon } from './singleton-beacon.js';
6
6
  import { SMTBeacon } from './smt-beacon.js';
7
7
 
8
8
  /**
@@ -38,7 +38,7 @@ export class BeaconSignalDiscovery {
38
38
  beaconServiceSignals.set(beaconService, []);
39
39
  // Get the transactions for the beacon address via REST
40
40
  const beaconSignals = await bitcoin.rest.address.getTxs(
41
- beaconService.serviceEndpoint as string
41
+ BeaconUtils.parseBitcoinAddress(beaconService.serviceEndpoint as string)
42
42
  );
43
43
 
44
44
  // If no signals are found, continue
@@ -1,9 +1,10 @@
1
1
  import { AddressUtxo, BitcoinConnection } from '@did-btcr2/bitcoin';
2
- import { canonicalHash, canonicalize, hash, INVALID_SIDECAR_DATA, KeyBytes, MISSING_UPDATE_DATA } from '@did-btcr2/common';
2
+ import { canonicalize, decode, encode, hash, KeyBytes } from '@did-btcr2/common';
3
3
  import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
4
4
  import { SchnorrKeyPair } from '@did-btcr2/keypair';
5
- import { base64urlnopad } from '@scure/base';
5
+ import { hexToBytes } from '@noble/hashes/utils';
6
6
  import { opcodes, Psbt, script } from 'bitcoinjs-lib';
7
+ import type { BeaconProcessResult, DataNeed } from '../resolver.js';
7
8
  import { SidecarData } from '../types.js';
8
9
  import { Beacon } from './beacon.js';
9
10
  import { SingletonBeaconError } from './error.js';
@@ -27,54 +28,38 @@ export class SingletonBeacon extends Beacon {
27
28
 
28
29
  /**
29
30
  * Processes an array of Beacon Signals associated with a Singleton Beacon Service.
30
- * @returns {Promise<SignedBTCR2Update | undefined>} The DID Update payload announced by the Beacon Signal.
31
- * @throws {SingletonBeaconError} if the signalTx is invalid or the signalSidecarData is invalid.
31
+ * @param {Array<BeaconSignal>} signals The beacon signals discovered on-chain.
32
+ * @param {SidecarData} sidecar The processed sidecar data.
33
+ * @returns {BeaconProcessResult} Successfully resolved updates and any data needs.
32
34
  */
33
- async processSignals(
35
+ processSignals(
34
36
  signals: Array<BeaconSignal>,
35
37
  sidecar: SidecarData
36
- ): Promise<Array<[SignedBTCR2Update, BlockMetadata]>> {
37
- // Initialize an empty array to hold the BTCR2 signed updates
38
+ ): BeaconProcessResult {
38
39
  const updates = new Array<[SignedBTCR2Update, BlockMetadata]>();
40
+ const needs = new Array<DataNeed>();
39
41
 
40
- // Loop through each signal in signals
41
42
  for(const signal of signals) {
42
- // Grab the beacon signal bytes hash from the signal
43
- const updateHash = signal.signalBytes;
43
+ // Decode signal bytes from hex and re-encode to base64url for sidecar lookup
44
+ const updateHash = encode(decode(signal.signalBytes, 'hex'));
44
45
 
45
- // Use the updateHash as the sidecar data lookup key to retrieve the btcr2 update
46
+ // Look up the signed update in sidecar updateMap
46
47
  const signedUpdate = sidecar.updateMap.get(updateHash);
47
48
 
48
- // If no btcr2 update is found in sidecar data maps, throw missingUpdateData error.
49
49
  if(!signedUpdate) {
50
- throw new SingletonBeaconError(
51
- `BTCR2 Signed Update not found for update hash ${updateHash}.`,
52
- MISSING_UPDATE_DATA, signal
53
- );
50
+ // Data not available — emit a need instead of throwing
51
+ needs.push({
52
+ kind : 'NeedSignedUpdate',
53
+ updateHash,
54
+ beaconServiceId : this.service.id
55
+ });
56
+ continue;
54
57
  }
55
58
 
56
- // TODO: Review for simplification how we are encoding and comparing
57
- // Canonicalize, hash and encode to base64url the signed update object found in sidecar or CAS
58
- const encodedUpdate = canonicalHash(signedUpdate, { encoding: 'base64url' });
59
-
60
- // Encode the signal bytes hex string to base64url
61
- const signalBytes = base64urlnopad.encode(Buffer.from(updateHash, 'hex'));
62
-
63
- // Check for mismatch between found sidecar/cas update hash and onchain beacon signal hash
64
- if (encodedUpdate !== signalBytes) {
65
- // If mismatch, throw invalidSidecarData error.
66
- throw new SingletonBeaconError(
67
- `Hash mismatch: sidecar update ${encodedUpdate} !== signal bytes ${signalBytes}.`,
68
- INVALID_SIDECAR_DATA, { encodedUpdate, signalBytes }
69
- );
70
- }
71
-
72
- // Push signedUpdate to updates array
73
59
  updates.push([signedUpdate, signal.blockMetadata]);
74
60
  }
75
61
 
76
- // Return the array of signed updates
77
- return updates;
62
+ return { updates, needs };
78
63
  }
79
64
  /**
80
65
  * Broadcasts a SingletonBeacon signal to the Bitcoin network.
@@ -128,7 +113,7 @@ export class SingletonBeacon extends Beacon {
128
113
  .addInput({
129
114
  hash : utxo.txid,
130
115
  index : utxo.vout,
131
- nonWitnessUtxo : Buffer.from(prevTx, 'hex')
116
+ nonWitnessUtxo : hexToBytes(prevTx)
132
117
  })
133
118
  // Add a change output minus a fee of 500 sats
134
119
  // TODO: calculate fee based on transaction vsize and current fee rates
@@ -1,10 +1,11 @@
1
1
  import { BitcoinConnection } from '@did-btcr2/bitcoin';
2
2
  import { KeyBytes } from '@did-btcr2/common';
3
3
  import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
4
+ import type { BeaconProcessResult } from '../resolver.js';
4
5
  import { SidecarData } from '../types.js';
5
6
  import { Beacon } from './beacon.js';
6
7
  import { SMTBeaconError } from './error.js';
7
- import { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
8
+ import { BeaconService, BeaconSignal } from './interfaces.js';
8
9
 
9
10
  /**
10
11
  * Implements {@link https://dcdpr.github.io/did-btcr2/terminology.html#smt-beacon | SMTBeacon}.
@@ -25,13 +26,13 @@ export class SMTBeacon extends Beacon {
25
26
  * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
26
27
  * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
27
28
  * @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
28
- * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
29
+ * @returns {BeaconProcessResult} The processed signals.
29
30
  * @throws {SMTBeaconError} if processing fails.
30
31
  */
31
32
  processSignals(
32
33
  signals: Array<BeaconSignal>,
33
34
  sidecar: SidecarData
34
- ): Promise<Array<[SignedBTCR2Update, BlockMetadata]>> {
35
+ ): BeaconProcessResult {
35
36
  throw new SMTBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signals, sidecar});
36
37
  }
37
38
 
@@ -1,4 +1,3 @@
1
- import { BitcoinConnection } from '@did-btcr2/bitcoin';
2
1
  import { DidResolutionOptions } from '@web5/dids';
3
2
  import { Sidecar } from './types.js';
4
3
 
@@ -12,8 +11,12 @@ export interface RootCapability {
12
11
  /**
13
12
  * See {@link https://dcdpr.github.io/did-btcr2/data-structures.html#resolution-options-example-panel-show | Resolution Options}
14
13
  * for data structure details.
14
+ *
15
+ * Resolution is now fully sans-I/O via the {@link Resolver} state machine.
16
+ * External data (Bitcoin signals, CAS data) is provided through the
17
+ * `resolver.resolve()` / `resolver.provide()` protocol.
15
18
  */
16
- export interface ResolutionOptionsCore extends DidResolutionOptions {
19
+ export interface ResolutionOptions extends DidResolutionOptions {
17
20
  /**
18
21
  * Optional ASCII string representation of the specific version of a DID document
19
22
  * to be resolved.
@@ -34,20 +37,6 @@ export interface ResolutionOptionsCore extends DidResolutionOptions {
34
37
  sidecar?: Sidecar;
35
38
  }
36
39
 
37
- /**
38
- * Full set of resolution options for the did:btcr2 method. See {@link ResolutionOptionsCore}
39
- * for the resolution options defined by the specification.
40
- * @extends ResolutionOptionsCore
41
- */
42
- export interface ResolutionOptions extends ResolutionOptionsCore {
43
- /**
44
- * Drivers for interacting with external systems, such as the Bitcoin network.
45
- */
46
- drivers?: {
47
- bitcoin?: BitcoinConnection;
48
- };
49
- }
50
-
51
40
  /**
52
41
  * {@link https://dcdpr.github.io/did-btcr2/terminology.html#smt-proof | SMT Proof}
53
42
  * a set of SHA-256 hashes for nodes in a Sparse Merkle Tree that together form