@did-btcr2/api 0.2.1 → 0.3.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 (74) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.js +149910 -127351
  3. package/dist/browser.mjs +149186 -126627
  4. package/dist/cjs/api.js +210 -150
  5. package/dist/cjs/api.js.map +1 -1
  6. package/dist/cjs/bitcoin.js +110 -0
  7. package/dist/cjs/bitcoin.js.map +1 -0
  8. package/dist/cjs/cas.js +90 -0
  9. package/dist/cjs/cas.js.map +1 -0
  10. package/dist/cjs/crypto.js +425 -0
  11. package/dist/cjs/crypto.js.map +1 -0
  12. package/dist/cjs/did.js +70 -0
  13. package/dist/cjs/did.js.map +1 -0
  14. package/dist/cjs/helpers.js +28 -0
  15. package/dist/cjs/helpers.js.map +1 -0
  16. package/dist/cjs/index.js +12 -0
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/kms.js +73 -0
  19. package/dist/cjs/kms.js.map +1 -0
  20. package/dist/cjs/method.js +262 -0
  21. package/dist/cjs/method.js.map +1 -0
  22. package/dist/cjs/types.js +2 -0
  23. package/dist/cjs/types.js.map +1 -0
  24. package/dist/esm/api.js +210 -150
  25. package/dist/esm/api.js.map +1 -1
  26. package/dist/esm/bitcoin.js +110 -0
  27. package/dist/esm/bitcoin.js.map +1 -0
  28. package/dist/esm/cas.js +90 -0
  29. package/dist/esm/cas.js.map +1 -0
  30. package/dist/esm/crypto.js +425 -0
  31. package/dist/esm/crypto.js.map +1 -0
  32. package/dist/esm/did.js +70 -0
  33. package/dist/esm/did.js.map +1 -0
  34. package/dist/esm/helpers.js +28 -0
  35. package/dist/esm/helpers.js.map +1 -0
  36. package/dist/esm/index.js +12 -0
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/kms.js +73 -0
  39. package/dist/esm/kms.js.map +1 -0
  40. package/dist/esm/method.js +262 -0
  41. package/dist/esm/method.js.map +1 -0
  42. package/dist/esm/types.js +2 -0
  43. package/dist/esm/types.js.map +1 -0
  44. package/dist/types/api.d.ts +107 -97
  45. package/dist/types/api.d.ts.map +1 -1
  46. package/dist/types/bitcoin.d.ts +64 -0
  47. package/dist/types/bitcoin.d.ts.map +1 -0
  48. package/dist/types/cas.d.ts +70 -0
  49. package/dist/types/cas.d.ts.map +1 -0
  50. package/dist/types/crypto.d.ts +310 -0
  51. package/dist/types/crypto.d.ts.map +1 -0
  52. package/dist/types/did.d.ts +51 -0
  53. package/dist/types/did.d.ts.map +1 -0
  54. package/dist/types/helpers.d.ts +10 -0
  55. package/dist/types/helpers.d.ts.map +1 -0
  56. package/dist/types/index.d.ts +15 -0
  57. package/dist/types/index.d.ts.map +1 -1
  58. package/dist/types/kms.d.ts +49 -0
  59. package/dist/types/kms.d.ts.map +1 -0
  60. package/dist/types/method.d.ts +117 -0
  61. package/dist/types/method.d.ts.map +1 -0
  62. package/dist/types/types.d.ts +128 -0
  63. package/dist/types/types.d.ts.map +1 -0
  64. package/package.json +7 -6
  65. package/src/api.ts +246 -262
  66. package/src/bitcoin.ts +129 -0
  67. package/src/cas.ts +121 -0
  68. package/src/crypto.ts +525 -0
  69. package/src/did.ts +75 -0
  70. package/src/helpers.ts +35 -0
  71. package/src/index.ts +37 -1
  72. package/src/kms.ts +95 -0
  73. package/src/method.ts +331 -0
  74. package/src/types.ts +122 -0
@@ -0,0 +1,262 @@
1
+ import { IdentifierTypes, NotImplementedError } from '@did-btcr2/common';
2
+ import { BeaconSignalDiscovery, DidBtcr2 } from '@did-btcr2/method';
3
+ import { assertBytes, assertCompressedPubkey, assertString, NOOP_LOGGER } from './helpers.js';
4
+ /**
5
+ * DID method operations sub-facade: create, resolve, update, deactivate.
6
+ *
7
+ * Lazily initialized by {@link DidBtcr2Api} because it depends on
8
+ * {@link BitcoinApi} which requires network configuration.
9
+ * @public
10
+ */
11
+ export class DidMethodApi {
12
+ #btc;
13
+ #cas;
14
+ #log;
15
+ constructor(btc, cas, logger) {
16
+ this.#btc = btc;
17
+ this.#cas = cas;
18
+ this.#log = logger ?? NOOP_LOGGER;
19
+ }
20
+ /**
21
+ * Create a deterministic (k1) DID from a public key.
22
+ * Sets idType to KEY automatically.
23
+ * @param genesisBytes The compressed public key bytes (33 bytes).
24
+ * @param options Creation options (idType is set for you).
25
+ * @returns The created DID identifier string.
26
+ */
27
+ createDeterministic(genesisBytes, options = {}) {
28
+ assertCompressedPubkey(genesisBytes, 'genesisBytes');
29
+ return DidBtcr2.create(genesisBytes, { ...options, idType: IdentifierTypes.KEY });
30
+ }
31
+ /**
32
+ * Create a non-deterministic (x1) DID from external genesis document bytes.
33
+ * Sets idType to EXTERNAL automatically.
34
+ * @param genesisBytes The genesis document bytes.
35
+ * @param options Creation options (idType is set for you).
36
+ * @returns The created DID identifier string.
37
+ */
38
+ createExternal(genesisBytes, options = {}) {
39
+ assertBytes(genesisBytes, 'genesisBytes');
40
+ return DidBtcr2.create(genesisBytes, { ...options, idType: IdentifierTypes.EXTERNAL });
41
+ }
42
+ /**
43
+ * Resolve a DID by driving the sans-I/O {@link Resolver} state machine.
44
+ * If a Bitcoin connection is configured on the API, it is used automatically
45
+ * to fetch beacon signals. Sidecar data flows through `options.sidecar`.
46
+ * @param did The DID to resolve.
47
+ * @param options Resolution options.
48
+ * @returns The resolution result.
49
+ */
50
+ async resolve(did, options) {
51
+ assertString(did, 'did');
52
+ this.#log.debug('Resolving DID', did);
53
+ try {
54
+ const resolver = DidBtcr2.resolve(did, options);
55
+ let state = resolver.resolve();
56
+ while (state.status === 'action-required') {
57
+ for (const need of state.needs) {
58
+ switch (need.kind) {
59
+ case 'NeedBeaconSignals': {
60
+ if (!this.#btc) {
61
+ throw new Error('Bitcoin connection required to fetch beacon signals. '
62
+ + 'Configure a BitcoinApi on the DidBtcr2Api instance.');
63
+ }
64
+ this.#log.debug('Fetching beacon signals for %d service(s)', need.beaconServices.length);
65
+ const signals = await BeaconSignalDiscovery.indexer([...need.beaconServices], this.#btc.connection);
66
+ resolver.provide(need, signals);
67
+ break;
68
+ }
69
+ case 'NeedGenesisDocument': {
70
+ if (!this.#cas) {
71
+ throw new Error(`Genesis document required but not in sidecar (hash: ${need.genesisHash}), `
72
+ + 'and no CAS driver configured. Either provide the genesis document via '
73
+ + 'options.sidecar.genesisDocument or configure a CAS driver.');
74
+ }
75
+ this.#log.debug('Fetching genesis document from CAS: %s', need.genesisHash);
76
+ const doc = await this.#cas.retrieve(need.genesisHash);
77
+ if (!doc) {
78
+ throw new Error(`Genesis document not found in CAS (hash: ${need.genesisHash}).`);
79
+ }
80
+ resolver.provide(need, doc);
81
+ break;
82
+ }
83
+ case 'NeedCASAnnouncement': {
84
+ if (!this.#cas) {
85
+ throw new Error(`CAS announcement required but not in sidecar (hash: ${need.announcementHash}), `
86
+ + 'and no CAS driver configured. Either provide it via '
87
+ + 'options.sidecar.casUpdates or configure a CAS driver.');
88
+ }
89
+ this.#log.debug('Fetching CAS announcement from CAS: %s', need.announcementHash);
90
+ const announcement = await this.#cas.retrieve(need.announcementHash);
91
+ if (!announcement) {
92
+ throw new Error(`CAS announcement not found in CAS (hash: ${need.announcementHash}).`);
93
+ }
94
+ resolver.provide(need, announcement);
95
+ break;
96
+ }
97
+ case 'NeedSignedUpdate': {
98
+ if (!this.#cas) {
99
+ throw new Error(`Signed update required but not in sidecar (hash: ${need.updateHash}), `
100
+ + 'and no CAS driver configured. Either provide it via '
101
+ + 'options.sidecar.updates or configure a CAS driver.');
102
+ }
103
+ this.#log.debug('Fetching signed update from CAS: %s', need.updateHash);
104
+ const update = await this.#cas.retrieve(need.updateHash);
105
+ if (!update) {
106
+ throw new Error(`Signed update not found in CAS (hash: ${need.updateHash}).`);
107
+ }
108
+ resolver.provide(need, update);
109
+ break;
110
+ }
111
+ }
112
+ }
113
+ state = resolver.resolve();
114
+ }
115
+ this.#log.debug('DID resolved successfully', did, state.result.metadata);
116
+ return {
117
+ didResolutionMetadata: {},
118
+ didDocument: state.result.didDocument,
119
+ didDocumentMetadata: state.result.metadata,
120
+ };
121
+ }
122
+ catch (err) {
123
+ this.#log.error('DID resolution failed', did, err);
124
+ throw new Error(`Failed to resolve DID: ${did}`, { cause: err });
125
+ }
126
+ }
127
+ /**
128
+ * Update an existing DID document. If a Bitcoin connection is configured on
129
+ * the API, it is injected automatically.
130
+ * @param params The update parameters.
131
+ * @returns The signed update.
132
+ */
133
+ async update({ sourceDocument, patches, sourceVersionId, verificationMethodId, beaconId, signingMaterial, bitcoin, }) {
134
+ const btcConnection = bitcoin ?? this.#btc?.connection ?? undefined;
135
+ return await DidBtcr2.update({
136
+ sourceDocument,
137
+ patches,
138
+ sourceVersionId,
139
+ verificationMethodId,
140
+ beaconId,
141
+ signingMaterial,
142
+ bitcoin: btcConnection,
143
+ });
144
+ }
145
+ /**
146
+ * Get the signing method from a DID document by method ID.
147
+ * @param didDocument The DID document.
148
+ * @param methodId The method ID (if omitted, the first signing method is returned).
149
+ * @returns The found signing method.
150
+ */
151
+ getSigningMethod(didDocument, methodId) {
152
+ return DidBtcr2.getSigningMethod(didDocument, methodId);
153
+ }
154
+ /**
155
+ * Create a fluent builder for a DID update operation.
156
+ * @param sourceDocument The current DID document to update.
157
+ * @returns An {@link UpdateBuilder} for chaining update parameters.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * const signed = await api.btcr2
162
+ * .buildUpdate(currentDoc)
163
+ * .patch({ op: 'add', path: '/service/1', value: newService })
164
+ * .version(2)
165
+ * .signer('#initialKey')
166
+ * .beacon('#beacon-0')
167
+ * .execute();
168
+ * ```
169
+ */
170
+ buildUpdate(sourceDocument) {
171
+ return new UpdateBuilder(this, sourceDocument);
172
+ }
173
+ /** Deactivate a DID (not yet implemented in the core method). */
174
+ async deactivate() {
175
+ throw new NotImplementedError('DidMethodApi.deactivate is not implemented yet.', {
176
+ type: 'DID_API_METHOD_NOT_IMPLEMENTED',
177
+ name: 'NOT_IMPLEMENTED_ERROR'
178
+ });
179
+ }
180
+ }
181
+ /**
182
+ * Fluent builder for DID update operations. Reduces the cognitive load of
183
+ * the 7-parameter `update()` call by letting callers chain named steps.
184
+ *
185
+ * Created via {@link DidMethodApi.buildUpdate}.
186
+ * @public
187
+ */
188
+ export class UpdateBuilder {
189
+ #methodApi;
190
+ #sourceDocument;
191
+ #patches = [];
192
+ #sourceVersionId;
193
+ #verificationMethodId;
194
+ #beaconId;
195
+ #signingMaterial;
196
+ #bitcoin;
197
+ /** @internal */
198
+ constructor(methodApi, sourceDocument) {
199
+ this.#methodApi = methodApi;
200
+ this.#sourceDocument = sourceDocument;
201
+ }
202
+ /** Add a single JSON Patch operation. Can be called multiple times. */
203
+ patch(op) {
204
+ this.#patches.push(op);
205
+ return this;
206
+ }
207
+ /** Set all patches at once (replaces any previously added). */
208
+ patches(ops) {
209
+ this.#patches = [...ops];
210
+ return this;
211
+ }
212
+ /** Set the source version ID. */
213
+ version(id) {
214
+ this.#sourceVersionId = id;
215
+ return this;
216
+ }
217
+ /** Set the verification method ID used for signing. */
218
+ signer(methodId) {
219
+ this.#verificationMethodId = methodId;
220
+ return this;
221
+ }
222
+ /** Set the beacon ID for the update announcement. */
223
+ beacon(beaconId) {
224
+ this.#beaconId = beaconId;
225
+ return this;
226
+ }
227
+ /** Set the signing material (secret key bytes or hex). */
228
+ signingMaterial(material) {
229
+ this.#signingMaterial = material;
230
+ return this;
231
+ }
232
+ /** Override the Bitcoin connection for this update. */
233
+ withBitcoin(connection) {
234
+ this.#bitcoin = connection;
235
+ return this;
236
+ }
237
+ /**
238
+ * Execute the update.
239
+ * @throws {Error} If required fields (version, signer, beacon) are missing.
240
+ */
241
+ async execute() {
242
+ if (this.#sourceVersionId === undefined) {
243
+ throw new Error('UpdateBuilder: sourceVersionId is required. Call .version(id) before .execute().');
244
+ }
245
+ if (!this.#verificationMethodId) {
246
+ throw new Error('UpdateBuilder: verificationMethodId is required. Call .signer(id) before .execute().');
247
+ }
248
+ if (!this.#beaconId) {
249
+ throw new Error('UpdateBuilder: beaconId is required. Call .beacon(id) before .execute().');
250
+ }
251
+ return this.#methodApi.update({
252
+ sourceDocument: this.#sourceDocument,
253
+ patches: this.#patches,
254
+ sourceVersionId: this.#sourceVersionId,
255
+ verificationMethodId: this.#verificationMethodId,
256
+ beaconId: this.#beaconId,
257
+ signingMaterial: this.#signingMaterial,
258
+ bitcoin: this.#bitcoin,
259
+ });
260
+ }
261
+ }
262
+ //# sourceMappingURL=method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.js","sourceRoot":"","sources":["../../src/method.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGzE,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIpE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG9F;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IACvB,IAAI,CAAc;IAClB,IAAI,CAAU;IACd,IAAI,CAAS;IAEb,YAAY,GAAgB,EAAE,GAAY,EAAE,MAAe;QACzD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,MAAM,IAAI,WAAW,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACH,mBAAmB,CAAC,YAAsB,EAAE,UAA4C,EAAE;QACxF,sBAAsB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QACrD,OAAO,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;OAMG;IACH,cAAc,CAAC,YAA2B,EAAE,UAA4C,EAAE;QACxF,WAAW,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC,MAAM,CA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ACjD,QAAQ,EAAe,IAAI,CAAC,SAAS;YACrC,eAAe,EAAQ,IAAI,CAAC,gBAAgB;YAC5C,OAAO,EAAgB,IAAI,CAAC,QAAQ;SACrC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -1,113 +1,123 @@
1
- import { BitcoinCoreRpcClient, BitcoinNetworkConnection, BitcoinRestClient, BlockV3, RawTransactionV2, RestClientConfigParams, RpcClientConfig } from '@did-btcr2/bitcoin';
2
- import type { Bytes, CryptosuiteName, DocumentBytes, Entropy, HashBytes, Hex, HexString, JSONObject, KeyBytes, PatchOperation, ProofBytes, SchnorrKeyPairObject, SignatureBytes } from '@did-btcr2/common';
3
- import { IdentifierTypes } from '@did-btcr2/common';
4
- import type { MultikeyObject, SignedBTCR2Update } from '@did-btcr2/cryptosuite';
5
- import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
6
- import { SchnorrKeyPair } from '@did-btcr2/keypair';
7
- import type { Btcr2DidDocument, DidCreateOptions, ResolutionOptions, SidecarData } from '@did-btcr2/method';
8
- import { DidDocument, DidDocumentBuilder, Identifier } from '@did-btcr2/method';
9
- import type { DidResolutionResult, DidService, DidVerificationMethod } from '@web5/dids';
10
- export { DidDocument, DidDocumentBuilder, Identifier, IdentifierTypes };
11
- export type { BlockV3, Bytes, CryptosuiteName, DidResolutionResult, DidService, DidVerificationMethod, DocumentBytes, HashBytes, Hex, JSONObject, KeyBytes, MultikeyObject, PatchOperation, ProofBytes, RawTransactionV2, RestClientConfigParams, RpcClientConfig, SchnorrKeyPairObject, SignatureBytes };
12
- export type NetworkName = 'mainnet' | 'testnet4' | 'signet' | 'regtest';
13
- export type BitcoinApiConfig = {
14
- /** Shortcut to compute base URLs and params via @did-btcr2/bitcoin getNetwork */
15
- network?: NetworkName;
16
- /** Override REST client settings */
17
- rest?: RestClientConfigParams;
18
- /** Override RPC client settings */
19
- rpc?: RpcClientConfig;
20
- /** Default number of confirmations to consider "final" */
21
- defaultConfirmations?: number;
22
- };
23
- export type ApiConfig = {
24
- bitcoin?: BitcoinApiConfig;
25
- };
26
- export declare class KeyPairApi {
27
- /** Generate a new Schnorr keypair (secp256k1). */
28
- static generate(): SchnorrKeyPair;
29
- /** Import from secret key bytes or bigint. */
30
- static fromSecret(ent: Entropy): SchnorrKeyPair;
31
- }
32
- export declare class MultikeyApi {
1
+ import type { NetworkName } from '@did-btcr2/bitcoin';
2
+ import type { DocumentBytes, KeyBytes, PatchOperation } from '@did-btcr2/common';
3
+ import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
4
+ import { KeyIdentifier } from '@did-btcr2/kms';
5
+ import type { Btcr2DidDocument, DidCreateOptions, ResolutionOptions } from '@did-btcr2/method';
6
+ import type { DidResolutionResult } from '@web5/dids';
7
+ import { BitcoinApi } from './bitcoin.js';
8
+ import { CasApi } from './cas.js';
9
+ import { CryptoApi } from './crypto.js';
10
+ import { DidApi } from './did.js';
11
+ import { KeyManagerApi } from './kms.js';
12
+ import { DidMethodApi } from './method.js';
13
+ import type { ApiConfig, ResolutionResult } from './types.js';
14
+ /**
15
+ * Main DidBtcr2Api facade — the primary entry point for the SDK.
16
+ *
17
+ * Exposes sub-facades for Bitcoin, DID Method, KeyPair, Crypto, and
18
+ * KeyManager operations. Created via the {@link createApi} factory.
19
+ * @public
20
+ */
21
+ export declare class DidBtcr2Api {
22
+ #private;
23
+ /** Cryptographic operations (keypair, multikey, cryptosuite, proof). */
24
+ readonly crypto: CryptoApi;
25
+ /** DID identifier operations (encode, decode, generate, parse). */
26
+ readonly did: DidApi;
27
+ /** Key management operations. */
28
+ readonly kms: KeyManagerApi;
29
+ constructor(config?: ApiConfig);
33
30
  /**
34
- * Create a Schnorr Multikey wrapper (includes verificationMethod, sign/verify).
35
- * If secret is present, the multikey can sign.
31
+ * Bitcoin API sub-facade (lazily initialized).
32
+ * Only available when `btc` config was provided to the constructor.
33
+ * @throws {Error} If the instance has been disposed or no Bitcoin config was provided.
36
34
  */
37
- static create(params: {
38
- id: string;
39
- controller: string;
40
- keys: SchnorrKeyPair;
41
- }): SchnorrMultikey;
42
- /** Produce a DID Verification Method JSON from a multikey. */
43
- static toVerificationMethod(mk: SchnorrMultikey): DidVerificationMethod;
44
- /** Sign bytes via the multikey (requires secret). */
45
- static sign(mk: SchnorrMultikey, data: Bytes): Promise<SignatureBytes>;
46
- /** Verify signature via multikey. */
47
- static verify(mk: SchnorrMultikey, data: Bytes, signature: SignatureBytes): Promise<boolean>;
48
- }
49
- export declare class CryptoApi {
50
- static keyPairApi: KeyPairApi;
51
- static multikeyApi: MultikeyApi;
52
- }
53
- export declare class BitcoinApi {
54
- readonly rest: BitcoinRestClient;
55
- readonly rpc: BitcoinCoreRpcClient;
56
- readonly defaultConfirmations: number;
57
- constructor(cfg?: BitcoinApiConfig);
58
- /** Fetch a transaction by txid via REST. */
59
- getTransaction(txid: string): Promise<import("@did-btcr2/bitcoin").RawTransactionRest>;
60
- /** Broadcast a raw tx (hex) via REST. */
61
- send(rawTxHex: string): Promise<string>;
62
- /** Get UTXOs for an address via REST. */
63
- getUtxos(address: string): Promise<import("@did-btcr2/bitcoin").AddressUtxo[]>;
64
- /** Get a block by hash or height via REST. */
65
- getBlock(params: {
66
- hash?: string;
67
- height?: number;
68
- }): Promise<import("@did-btcr2/bitcoin").BlockResponse | undefined>;
69
- }
70
- export declare class DidApi {
35
+ get btc(): BitcoinApi;
36
+ /**
37
+ * CAS API sub-facade (lazily initialized).
38
+ * Only available when `cas` config was provided to the constructor.
39
+ * @throws {Error} If the instance has been disposed or no CAS config was provided.
40
+ */
41
+ get cas(): CasApi;
42
+ /**
43
+ * DID Method API sub-facade (lazily initialized with bitcoin + CAS wiring).
44
+ * @throws {Error} If the instance has been disposed.
45
+ */
46
+ get btcr2(): DidMethodApi;
71
47
  /**
72
- * Create a deterministic DID from a public key (bytes).
48
+ * Whether this API instance has been disposed.
73
49
  */
74
- createDeterministic({ genesisBytes, options }: {
75
- genesisBytes: KeyBytes;
76
- options: DidCreateOptions;
77
- }): Promise<string>;
50
+ get disposed(): boolean;
78
51
  /**
79
- * Create from an intermediate DID document (external genesis).
52
+ * Create a DID using either deterministic (KEY) or external (EXTERNAL) mode.
53
+ * @param type The creation mode.
54
+ * @param genesisBytes Public key bytes (deterministic) or document bytes (external).
55
+ * @param options Creation options (idType is set for you).
56
+ * @returns The created DID identifier string.
80
57
  */
81
- createExternal({ genesisBytes, options }: {
82
- genesisBytes: DocumentBytes;
83
- options: DidCreateOptions;
84
- }): Promise<string>;
58
+ createDid(type: 'deterministic' | 'external', genesisBytes: KeyBytes | DocumentBytes, options?: Omit<DidCreateOptions, 'idType'>): string;
85
59
  /**
86
- * Resolve DID document from DID (did:btcr2:...).
60
+ * Generate a new DID, create the keypair, and import it into the KMS.
61
+ * @param options Optional settings.
62
+ * @param options.setActive Whether to set the imported key as active in the KMS (default `true`).
63
+ * @param options.network Network for the generated DID (default `'regtest'`).
64
+ * @returns The generated DID string and KMS key identifier.
87
65
  */
88
- resolve(did: string, options: ResolutionOptions): Promise<DidResolutionResult>;
66
+ generateDid(options?: {
67
+ setActive?: boolean;
68
+ network?: NetworkName;
69
+ }): {
70
+ did: string;
71
+ keyId: KeyIdentifier;
72
+ };
89
73
  /**
90
- * Update a DID Document using a JSON Patch, signed as capabilityInvocation.
91
- * You provide the prior DID Document (to pick VM), a JSON Patch, and a signer multikey.
92
- * This delegates to MethodUpdate (which follows the cryptosuite rules internally).
74
+ * Resolve a DID, automatically injecting the configured Bitcoin connection.
75
+ * @param did The DID to resolve.
76
+ * @param options Optional resolution options.
77
+ * @returns The resolution result.
93
78
  */
94
- update({ sourceDocument, patches, sourceVersionId, verificationMethodId, beaconId, signingMaterial, bitcoin, }: {
95
- sourceDocument: Btcr2DidDocument;
79
+ resolveDid(did: string, options?: ResolutionOptions): Promise<DidResolutionResult>;
80
+ /**
81
+ * Resolve a DID and return a discriminated result instead of throwing.
82
+ * Useful when resolution failure is an expected outcome (e.g. checking
83
+ * whether a DID exists before creating it).
84
+ * @param did The DID to resolve.
85
+ * @param options Optional resolution options.
86
+ * @returns A {@link ResolutionResult} with `ok: true` on success or
87
+ * `ok: false` with error details on failure.
88
+ */
89
+ tryResolveDid(did: string, options?: ResolutionOptions): Promise<ResolutionResult>;
90
+ /**
91
+ * Update a DID document: resolve the current state, apply patches, sign, and announce.
92
+ * Automatically injects the configured Bitcoin connection.
93
+ *
94
+ * If `sourceDocument` and `sourceVersionId` are both provided, resolution
95
+ * is skipped. Otherwise the DID is resolved first to obtain them.
96
+ * @param params The update parameters.
97
+ * @returns The signed update.
98
+ */
99
+ updateDid({ did, patches, verificationMethodId, beaconId, sourceDocument, sourceVersionId, }: {
100
+ did: string;
96
101
  patches: PatchOperation[];
97
- sourceVersionId: number;
98
102
  verificationMethodId: string;
99
103
  beaconId: string;
100
- signingMaterial?: KeyBytes | HexString;
101
- bitcoin?: BitcoinNetworkConnection;
104
+ sourceDocument?: Btcr2DidDocument;
105
+ sourceVersionId?: number;
102
106
  }): Promise<SignedBTCR2Update>;
103
- /** Deactivate convenience: applies the standard `deactivated: true` patch. */
104
- deactivate(): Promise<SidecarData>;
105
- }
106
- export declare class DidBtcr2Api {
107
- readonly bitcoin: BitcoinApi;
108
- readonly did: DidApi;
109
- readonly keys: KeyPairApi;
110
- readonly crypto: CryptoApi;
111
- constructor(config?: ApiConfig);
107
+ /**
108
+ * Release internal references. After disposal, accessing `btc`, `btcr2`,
109
+ * or calling top-level methods will throw.
110
+ *
111
+ * Note: the underlying {@link BitcoinConnection} does not hold persistent
112
+ * connections, so this is primarily a guard against accidental reuse.
113
+ */
114
+ dispose(): void;
112
115
  }
116
+ /**
117
+ * Create a new {@link DidBtcr2Api} instance with the given configuration.
118
+ * @param config Optional configuration for the API.
119
+ * @returns The created DidBtcr2Api instance.
120
+ * @public
121
+ */
113
122
  export declare function createApi(config?: ApiConfig): DidBtcr2Api;
123
+ //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,EACjB,OAAO,EACP,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,KAAK,EACL,eAAe,EACf,aAAa,EACb,OAAO,EACP,SAAS,EACT,GAAG,EACH,SAAS,EACT,UAAU,EACV,QAAQ,EACR,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAwE,eAAe,EAAuB,MAAM,mBAAmB,CAAC;AAC/I,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAsB,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5G,OAAO,EAAY,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEzF,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;AACxE,YAAY,EACV,OAAO,EACP,KAAK,EACL,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,GAAG,EACH,UAAU,EACV,QAAQ,EACR,cAAc,EACd,cAAc,EACd,UAAU,EACV,gBAAgB,EA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AAc,EAAE,CAAC;QAC1B,oBAAoB,EAAE,MAAM,CAAC;QAC7B,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,CAAC,EAAE,gBAAgB,CAAC;QAClC,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA+C9B;;;;;;OAMG;IACH,OAAO,IAAI,IAAI;CAchB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,WAAW,CAEzD"}
@@ -0,0 +1,64 @@
1
+ import { BitcoinConnection, BitcoinCoreRpcClient, BitcoinRestClient, type RawTransactionRest } from '@did-btcr2/bitcoin';
2
+ import type { BitcoinApiConfig } from './types.js';
3
+ /**
4
+ * Bitcoin network operations sub-facade.
5
+ * Always backed by a {@link BitcoinConnection} so it can be passed to
6
+ * resolve/update without extra configuration.
7
+ *
8
+ * Lazily initialized by {@link DidBtcr2Api} to avoid connection overhead
9
+ * when Bitcoin features are not used.
10
+ * @public
11
+ */
12
+ export declare class BitcoinApi {
13
+ /** The underlying BitcoinConnection used for all operations. */
14
+ readonly connection: BitcoinConnection;
15
+ /** REST client for the active network. */
16
+ get rest(): BitcoinRestClient;
17
+ /**
18
+ * RPC client for the active network, or `undefined` if not configured.
19
+ * Use {@link requireRpc} when RPC is expected to be available.
20
+ */
21
+ get rpc(): BitcoinCoreRpcClient | undefined;
22
+ /** Whether an RPC client is available for this network. */
23
+ get hasRpc(): boolean;
24
+ /**
25
+ * RPC client for the active network.
26
+ * @throws {Error} If RPC was not configured for this network.
27
+ */
28
+ requireRpc(): BitcoinCoreRpcClient;
29
+ /**
30
+ * Create a BitcoinApi for a specific network with optional endpoint overrides.
31
+ * Uses BitcoinConnection.forNetwork() — no env vars consulted.
32
+ * @param cfg The network and optional REST/RPC overrides.
33
+ */
34
+ constructor(cfg: BitcoinApiConfig);
35
+ /**
36
+ * Fetch a transaction by txid via REST.
37
+ * @param txid The transaction ID (64-character hex string).
38
+ * @returns The fetched transaction.
39
+ */
40
+ getTransaction(txid: string): Promise<RawTransactionRest>;
41
+ /**
42
+ * Broadcast a raw tx (hex) via REST.
43
+ * @param rawTxHex The raw transaction hex string.
44
+ */
45
+ send(rawTxHex: string): Promise<string>;
46
+ /**
47
+ * Get UTXOs for an address via REST.
48
+ * @param address The Bitcoin address.
49
+ */
50
+ getUtxos(address: string): Promise<import("@did-btcr2/bitcoin").AddressUtxo[]>;
51
+ /**
52
+ * Get a block by hash or height via REST.
53
+ * @param params Block identifier — at least one of `hash` or `height` is required.
54
+ */
55
+ getBlock(params: {
56
+ hash?: string;
57
+ height?: number;
58
+ }): Promise<import("@did-btcr2/bitcoin").EsploraBlock | undefined>;
59
+ /** Convert BTC to satoshis (integer-safe string-split arithmetic). */
60
+ static btcToSats(btc: number): number;
61
+ /** Convert satoshis to BTC (integer-safe string-split arithmetic). */
62
+ static satsToBtc(sats: number): number;
63
+ }
64
+ //# sourceMappingURL=bitcoin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitcoin.d.ts","sourceRoot":"","sources":["../../src/bitcoin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;GAQG;AACH,qBAAa,UAAU;IACrB,gEAAgE;IAChE,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAC;IAEvC,0CAA0C;IAC1C,IAAI,IAAI,IAAI,iBAAiB,CAE5B;IAED;;;OAGG;IACH,IAAI,GAAG,IAAI,oBAAoB,GAAG,SAAS,CAE1C;IAED,2DAA2D;IAC3D,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED;;;OAGG;IACH,UAAU,IAAI,oBAAoB;IAWlC;;;;OAIG;gBACS,GAAG,EAAE,gBAAgB;IAoBjC;;;;OAIG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAK/D;;;OAGG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM;IAK3B;;;OAGG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM;IAK9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAOzD,sEAAsE;IACtE,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIrC,sEAAsE;IACtE,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAGvC"}