@did-btcr2/api 0.3.1 → 0.4.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.
- package/dist/.tsbuildinfo +1 -0
- package/dist/browser.js +125526 -120388
- package/dist/browser.mjs +125579 -120441
- package/dist/cjs/index.js +2239 -14
- package/dist/esm/api.js +1 -1
- package/dist/esm/bitcoin.js.map +1 -1
- package/dist/esm/cas.js +7 -8
- package/dist/esm/cas.js.map +1 -1
- package/dist/esm/crypto.js.map +1 -1
- package/dist/esm/did.js.map +1 -1
- package/dist/esm/kms.js.map +1 -1
- package/dist/esm/method.js +5 -5
- package/dist/esm/method.js.map +1 -1
- package/dist/types/api.d.ts +3 -3
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/bitcoin.d.ts +2 -1
- package/dist/types/bitcoin.d.ts.map +1 -1
- package/dist/types/cas.d.ts +5 -4
- package/dist/types/cas.d.ts.map +1 -1
- package/dist/types/crypto.d.ts +4 -3
- package/dist/types/crypto.d.ts.map +1 -1
- package/dist/types/did.d.ts +1 -2
- package/dist/types/did.d.ts.map +1 -1
- package/dist/types/kms.d.ts +3 -2
- package/dist/types/kms.d.ts.map +1 -1
- package/dist/types/method.d.ts +5 -5
- package/dist/types/method.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/api.ts +3 -3
- package/src/bitcoin.ts +3 -2
- package/src/cas.ts +8 -8
- package/src/crypto.ts +10 -8
- package/src/did.ts +2 -2
- package/src/kms.ts +4 -3
- package/src/method.ts +9 -9
- package/dist/cjs/api.js +0 -240
- package/dist/cjs/api.js.map +0 -1
- package/dist/cjs/bitcoin.js +0 -110
- package/dist/cjs/bitcoin.js.map +0 -1
- package/dist/cjs/cas.js +0 -90
- package/dist/cjs/cas.js.map +0 -1
- package/dist/cjs/crypto.js +0 -425
- package/dist/cjs/crypto.js.map +0 -1
- package/dist/cjs/did.js +0 -70
- package/dist/cjs/did.js.map +0 -1
- package/dist/cjs/helpers.js +0 -28
- package/dist/cjs/helpers.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/kms.js +0 -73
- package/dist/cjs/kms.js.map +0 -1
- package/dist/cjs/method.js +0 -262
- package/dist/cjs/method.js.map +0 -1
- package/dist/cjs/types.js +0 -2
- package/dist/cjs/types.js.map +0 -1
package/src/method.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
1
|
+
import type { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
2
|
import type { DocumentBytes, HexString, KeyBytes, PatchOperation } from '@did-btcr2/common';
|
|
3
|
-
import { IdentifierTypes, NotImplementedError } from '@did-btcr2/common';
|
|
4
|
-
import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
3
|
+
import { decode as decodeHash, IdentifierTypes, NotImplementedError } from '@did-btcr2/common';
|
|
4
|
+
import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
5
5
|
import type { Btcr2DidDocument, CASAnnouncement, DidCreateOptions, NeedCASAnnouncement, NeedGenesisDocument, NeedSignedUpdate, ResolutionOptions } from '@did-btcr2/method';
|
|
6
6
|
import { BeaconSignalDiscovery, DidBtcr2 } from '@did-btcr2/method';
|
|
7
7
|
import type { DidResolutionResult, DidVerificationMethod } from '@web5/dids';
|
|
8
|
-
import { BitcoinApi } from './bitcoin.js';
|
|
9
|
-
import { CasApi } from './cas.js';
|
|
8
|
+
import type { BitcoinApi } from './bitcoin.js';
|
|
9
|
+
import type { CasApi } from './cas.js';
|
|
10
10
|
import { assertBytes, assertCompressedPubkey, assertString, NOOP_LOGGER } from './helpers.js';
|
|
11
11
|
import type { Logger } from './types.js';
|
|
12
12
|
|
|
@@ -53,7 +53,7 @@ export class DidMethodApi {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Resolve a DID by driving the sans-I/O
|
|
56
|
+
* Resolve a DID by driving the sans-I/O `Resolver` state machine (from @did-btcr2/method).
|
|
57
57
|
* If a Bitcoin connection is configured on the API, it is used automatically
|
|
58
58
|
* to fetch beacon signals. Sidecar data flows through `options.sidecar`.
|
|
59
59
|
* @param did The DID to resolve.
|
|
@@ -96,7 +96,7 @@ export class DidMethodApi {
|
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
98
|
this.#log.debug('Fetching genesis document from CAS: %s', need.genesisHash);
|
|
99
|
-
const doc = await this.#cas.retrieve(need.genesisHash);
|
|
99
|
+
const doc = await this.#cas.retrieve(decodeHash(need.genesisHash, 'hex'));
|
|
100
100
|
if(!doc) {
|
|
101
101
|
throw new Error(
|
|
102
102
|
`Genesis document not found in CAS (hash: ${need.genesisHash}).`
|
|
@@ -114,7 +114,7 @@ export class DidMethodApi {
|
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
116
|
this.#log.debug('Fetching CAS announcement from CAS: %s', need.announcementHash);
|
|
117
|
-
const announcement = await this.#cas.retrieve(need.announcementHash);
|
|
117
|
+
const announcement = await this.#cas.retrieve(decodeHash(need.announcementHash, 'hex'));
|
|
118
118
|
if(!announcement) {
|
|
119
119
|
throw new Error(
|
|
120
120
|
`CAS announcement not found in CAS (hash: ${need.announcementHash}).`
|
|
@@ -132,7 +132,7 @@ export class DidMethodApi {
|
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
this.#log.debug('Fetching signed update from CAS: %s', need.updateHash);
|
|
135
|
-
const update = await this.#cas.retrieve(need.updateHash);
|
|
135
|
+
const update = await this.#cas.retrieve(decodeHash(need.updateHash, 'hex'));
|
|
136
136
|
if(!update) {
|
|
137
137
|
throw new Error(
|
|
138
138
|
`Signed update not found in CAS (hash: ${need.updateHash}).`
|
package/dist/cjs/api.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
2
|
-
import { BitcoinApi } from './bitcoin.js';
|
|
3
|
-
import { CasApi } from './cas.js';
|
|
4
|
-
import { CryptoApi } from './crypto.js';
|
|
5
|
-
import { DidApi } from './did.js';
|
|
6
|
-
import { assertString, NOOP_LOGGER } from './helpers.js';
|
|
7
|
-
import { KeyManagerApi } from './kms.js';
|
|
8
|
-
import { DidMethodApi } from './method.js';
|
|
9
|
-
/**
|
|
10
|
-
* Main DidBtcr2Api facade — the primary entry point for the SDK.
|
|
11
|
-
*
|
|
12
|
-
* Exposes sub-facades for Bitcoin, DID Method, KeyPair, Crypto, and
|
|
13
|
-
* KeyManager operations. Created via the {@link createApi} factory.
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export class DidBtcr2Api {
|
|
17
|
-
/** Cryptographic operations (keypair, multikey, cryptosuite, proof). */
|
|
18
|
-
crypto;
|
|
19
|
-
/** DID identifier operations (encode, decode, generate, parse). */
|
|
20
|
-
did;
|
|
21
|
-
/** Key management operations. */
|
|
22
|
-
kms;
|
|
23
|
-
#btcConfig;
|
|
24
|
-
#btc;
|
|
25
|
-
#casConfig;
|
|
26
|
-
#cas;
|
|
27
|
-
#btcr2;
|
|
28
|
-
#log;
|
|
29
|
-
#disposed = false;
|
|
30
|
-
constructor(config) {
|
|
31
|
-
this.#btcConfig = config?.btc;
|
|
32
|
-
this.#casConfig = config?.cas;
|
|
33
|
-
this.#log = config?.logger ?? NOOP_LOGGER;
|
|
34
|
-
this.kms = new KeyManagerApi(config?.kms);
|
|
35
|
-
this.did = new DidApi();
|
|
36
|
-
this.crypto = new CryptoApi();
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Bitcoin API sub-facade (lazily initialized).
|
|
40
|
-
* Only available when `btc` config was provided to the constructor.
|
|
41
|
-
* @throws {Error} If the instance has been disposed or no Bitcoin config was provided.
|
|
42
|
-
*/
|
|
43
|
-
get btc() {
|
|
44
|
-
this.#assertNotDisposed();
|
|
45
|
-
if (!this.#btc) {
|
|
46
|
-
if (!this.#btcConfig) {
|
|
47
|
-
throw new Error('Bitcoin not configured. Pass a btc config to createApi(), e.g.: '
|
|
48
|
-
+ 'createApi({ btc: { network: \'regtest\' } })');
|
|
49
|
-
}
|
|
50
|
-
this.#btc = new BitcoinApi(this.#btcConfig);
|
|
51
|
-
}
|
|
52
|
-
return this.#btc;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* CAS API sub-facade (lazily initialized).
|
|
56
|
-
* Only available when `cas` config was provided to the constructor.
|
|
57
|
-
* @throws {Error} If the instance has been disposed or no CAS config was provided.
|
|
58
|
-
*/
|
|
59
|
-
get cas() {
|
|
60
|
-
this.#assertNotDisposed();
|
|
61
|
-
if (!this.#cas) {
|
|
62
|
-
if (!this.#casConfig) {
|
|
63
|
-
throw new Error('CAS not configured. Pass a cas config to createApi(), e.g.: '
|
|
64
|
-
+ 'createApi({ cas: { helia: await createHelia() } })');
|
|
65
|
-
}
|
|
66
|
-
this.#cas = new CasApi(this.#casConfig);
|
|
67
|
-
}
|
|
68
|
-
return this.#cas;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* DID Method API sub-facade (lazily initialized with bitcoin + CAS wiring).
|
|
72
|
-
* @throws {Error} If the instance has been disposed.
|
|
73
|
-
*/
|
|
74
|
-
get btcr2() {
|
|
75
|
-
this.#assertNotDisposed();
|
|
76
|
-
if (!this.#btcr2) {
|
|
77
|
-
this.#btcr2 = new DidMethodApi(this.#btcConfig ? this.btc : undefined, this.#casConfig ? this.cas : undefined, this.#log);
|
|
78
|
-
}
|
|
79
|
-
return this.#btcr2;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Whether this API instance has been disposed.
|
|
83
|
-
*/
|
|
84
|
-
get disposed() {
|
|
85
|
-
return this.#disposed;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Create a DID using either deterministic (KEY) or external (EXTERNAL) mode.
|
|
89
|
-
* @param type The creation mode.
|
|
90
|
-
* @param genesisBytes Public key bytes (deterministic) or document bytes (external).
|
|
91
|
-
* @param options Creation options (idType is set for you).
|
|
92
|
-
* @returns The created DID identifier string.
|
|
93
|
-
*/
|
|
94
|
-
createDid(type, genesisBytes, options) {
|
|
95
|
-
this.#assertNotDisposed();
|
|
96
|
-
return type === 'deterministic'
|
|
97
|
-
? this.btcr2.createDeterministic(genesisBytes, options)
|
|
98
|
-
: this.btcr2.createExternal(genesisBytes, options);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Generate a new DID, create the keypair, and import it into the KMS.
|
|
102
|
-
* @param options Optional settings.
|
|
103
|
-
* @param options.setActive Whether to set the imported key as active in the KMS (default `true`).
|
|
104
|
-
* @param options.network Network for the generated DID (default `'regtest'`).
|
|
105
|
-
* @returns The generated DID string and KMS key identifier.
|
|
106
|
-
*/
|
|
107
|
-
generateDid(options) {
|
|
108
|
-
this.#assertNotDisposed();
|
|
109
|
-
const { keyPair, did } = this.did.generate(options?.network);
|
|
110
|
-
const kp = SchnorrKeyPair.fromJSON(keyPair);
|
|
111
|
-
const keyId = this.kms.import(kp, { setActive: options?.setActive ?? true });
|
|
112
|
-
return { did, keyId };
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Resolve a DID, automatically injecting the configured Bitcoin connection.
|
|
116
|
-
* @param did The DID to resolve.
|
|
117
|
-
* @param options Optional resolution options.
|
|
118
|
-
* @returns The resolution result.
|
|
119
|
-
*/
|
|
120
|
-
async resolveDid(did, options) {
|
|
121
|
-
this.#assertNotDisposed();
|
|
122
|
-
return await this.btcr2.resolve(did, options);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Resolve a DID and return a discriminated result instead of throwing.
|
|
126
|
-
* Useful when resolution failure is an expected outcome (e.g. checking
|
|
127
|
-
* whether a DID exists before creating it).
|
|
128
|
-
* @param did The DID to resolve.
|
|
129
|
-
* @param options Optional resolution options.
|
|
130
|
-
* @returns A {@link ResolutionResult} with `ok: true` on success or
|
|
131
|
-
* `ok: false` with error details on failure.
|
|
132
|
-
*/
|
|
133
|
-
async tryResolveDid(did, options) {
|
|
134
|
-
this.#assertNotDisposed();
|
|
135
|
-
assertString(did, 'did');
|
|
136
|
-
try {
|
|
137
|
-
const raw = await this.btcr2.resolve(did, options);
|
|
138
|
-
if (raw.didDocument) {
|
|
139
|
-
return {
|
|
140
|
-
ok: true,
|
|
141
|
-
document: raw.didDocument,
|
|
142
|
-
metadata: raw.didDocumentMetadata,
|
|
143
|
-
raw,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
ok: false,
|
|
148
|
-
error: raw.didResolutionMetadata?.error ?? 'unknown',
|
|
149
|
-
errorMessage: raw.didResolutionMetadata?.errorMessage,
|
|
150
|
-
raw,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
catch (err) {
|
|
154
|
-
return {
|
|
155
|
-
ok: false,
|
|
156
|
-
error: 'internalError',
|
|
157
|
-
errorMessage: err.message,
|
|
158
|
-
raw: {
|
|
159
|
-
didDocument: null,
|
|
160
|
-
didDocumentMetadata: {},
|
|
161
|
-
didResolutionMetadata: { error: 'internalError', errorMessage: err.message },
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Update a DID document: resolve the current state, apply patches, sign, and announce.
|
|
168
|
-
* Automatically injects the configured Bitcoin connection.
|
|
169
|
-
*
|
|
170
|
-
* If `sourceDocument` and `sourceVersionId` are both provided, resolution
|
|
171
|
-
* is skipped. Otherwise the DID is resolved first to obtain them.
|
|
172
|
-
* @param params The update parameters.
|
|
173
|
-
* @returns The signed update.
|
|
174
|
-
*/
|
|
175
|
-
async updateDid({ did, patches, verificationMethodId, beaconId, sourceDocument, sourceVersionId, }) {
|
|
176
|
-
this.#assertNotDisposed();
|
|
177
|
-
assertString(did, 'did');
|
|
178
|
-
let doc = sourceDocument;
|
|
179
|
-
let versionId = sourceVersionId;
|
|
180
|
-
if (!doc || versionId === undefined) {
|
|
181
|
-
const resolution = await this.resolveDid(did);
|
|
182
|
-
if (!resolution.didDocument) {
|
|
183
|
-
const meta = resolution.didResolutionMetadata;
|
|
184
|
-
const detail = meta?.error ? `: ${meta.error}` : '.';
|
|
185
|
-
const extra = meta?.errorMessage ? ` ${meta.errorMessage}` : '';
|
|
186
|
-
throw new Error(`Failed to resolve DID ${did} for update${detail}${extra}`, { cause: meta });
|
|
187
|
-
}
|
|
188
|
-
doc = doc ?? resolution.didDocument;
|
|
189
|
-
if (versionId === undefined) {
|
|
190
|
-
const rawVersionId = resolution.didDocumentMetadata?.versionId;
|
|
191
|
-
if (rawVersionId === undefined || rawVersionId === null) {
|
|
192
|
-
throw new Error(`Resolution of DID ${did} succeeded but returned no versionId in metadata. `
|
|
193
|
-
+ 'Provide sourceVersionId explicitly.');
|
|
194
|
-
}
|
|
195
|
-
const parsed = Number(rawVersionId);
|
|
196
|
-
if (!Number.isFinite(parsed)) {
|
|
197
|
-
throw new Error(`Resolution of DID ${did} returned a non-numeric versionId: ${String(rawVersionId)}.`);
|
|
198
|
-
}
|
|
199
|
-
versionId = parsed;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return await this.btcr2.update({
|
|
203
|
-
sourceDocument: doc,
|
|
204
|
-
patches,
|
|
205
|
-
sourceVersionId: versionId,
|
|
206
|
-
verificationMethodId,
|
|
207
|
-
beaconId,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Release internal references. After disposal, accessing `btc`, `btcr2`,
|
|
212
|
-
* or calling top-level methods will throw.
|
|
213
|
-
*
|
|
214
|
-
* Note: the underlying {@link BitcoinConnection} does not hold persistent
|
|
215
|
-
* connections, so this is primarily a guard against accidental reuse.
|
|
216
|
-
*/
|
|
217
|
-
dispose() {
|
|
218
|
-
this.#btc = undefined;
|
|
219
|
-
this.#cas = undefined;
|
|
220
|
-
this.#btcr2 = undefined;
|
|
221
|
-
this.#btcConfig = undefined;
|
|
222
|
-
this.#casConfig = undefined;
|
|
223
|
-
this.#disposed = true;
|
|
224
|
-
}
|
|
225
|
-
#assertNotDisposed() {
|
|
226
|
-
if (this.#disposed) {
|
|
227
|
-
throw new Error('This DidBtcr2Api instance has been disposed and can no longer be used.');
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Create a new {@link DidBtcr2Api} instance with the given configuration.
|
|
233
|
-
* @param config Optional configuration for the API.
|
|
234
|
-
* @returns The created DidBtcr2Api instance.
|
|
235
|
-
* @public
|
|
236
|
-
*/
|
|
237
|
-
export function createApi(config) {
|
|
238
|
-
return new DidBtcr2Api(config);
|
|
239
|
-
}
|
|
240
|
-
//# sourceMappingURL=api.js.map
|
package/dist/cjs/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAkB,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACtB,wEAAwE;IAC/D,MAAM,CAAY;IAC3B,mEAAmE;IAC1D,GAAG,CAAS;IACrB,iCAAiC;IACxB,GAAG,CAAgB;IAE5B,UAAU,CAAoB;IAC9B,IAAI,CAAc;IAClB,UAAU,CAAa;IACvB,IAAI,CAAU;IACd,MAAM,CAAgB;IACtB,IAAI,CAAS;IACb,SAAS,GAAG,KAAK,CAAC;IAElB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AAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC7B,MAAM,IAAI,KAAK,CACb,qBAAqB,GAAG,sCAAsC,MAAM,CAAC,YAAY,CAAC,GAAG,CACtF,CAAC;gBACJ,CAAC;gBACD,SAAS,GAAG,MAAM,CAAC;YACrB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAC7B,cAAc,EAAM,GAAG;YACvB,OAAO;YACP,eAAe,EAAK,SAAS;YAC7B,oBAAoB;YACpB,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,kBAAkB;QAChB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,MAAkB;IAC1C,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/cjs/bitcoin.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
|
-
import { assertString } from './helpers.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 class BitcoinApi {
|
|
13
|
-
/** The underlying BitcoinConnection used for all operations. */
|
|
14
|
-
connection;
|
|
15
|
-
/** REST client for the active network. */
|
|
16
|
-
get rest() {
|
|
17
|
-
return this.connection.rest;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* RPC client for the active network, or `undefined` if not configured.
|
|
21
|
-
* Use {@link requireRpc} when RPC is expected to be available.
|
|
22
|
-
*/
|
|
23
|
-
get rpc() {
|
|
24
|
-
return this.connection.rpc;
|
|
25
|
-
}
|
|
26
|
-
/** Whether an RPC client is available for this network. */
|
|
27
|
-
get hasRpc() {
|
|
28
|
-
return this.connection.rpc !== undefined;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* RPC client for the active network.
|
|
32
|
-
* @throws {Error} If RPC was not configured for this network.
|
|
33
|
-
*/
|
|
34
|
-
requireRpc() {
|
|
35
|
-
const client = this.connection.rpc;
|
|
36
|
-
if (!client) {
|
|
37
|
-
throw new Error('RPC client not configured. Pass an rpc config when creating the BitcoinApi, e.g.: '
|
|
38
|
-
+ '{ network: \'regtest\', rpc: { host: \'http://localhost:18443\', username: \'u\', password: \'p\' } }');
|
|
39
|
-
}
|
|
40
|
-
return client;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Create a BitcoinApi for a specific network with optional endpoint overrides.
|
|
44
|
-
* Uses BitcoinConnection.forNetwork() — no env vars consulted.
|
|
45
|
-
* @param cfg The network and optional REST/RPC overrides.
|
|
46
|
-
*/
|
|
47
|
-
constructor(cfg) {
|
|
48
|
-
let executor = cfg.executor;
|
|
49
|
-
// Wrap the default fetch with a timeout if configured and no custom
|
|
50
|
-
// executor was provided.
|
|
51
|
-
if (!executor && cfg.timeoutMs !== undefined) {
|
|
52
|
-
const ms = cfg.timeoutMs;
|
|
53
|
-
executor = (req) => fetch(req.url, {
|
|
54
|
-
method: req.method,
|
|
55
|
-
headers: req.headers,
|
|
56
|
-
body: req.body,
|
|
57
|
-
signal: AbortSignal.timeout(ms),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
this.connection = BitcoinConnection.forNetwork(cfg.network, {
|
|
61
|
-
rest: cfg.rest,
|
|
62
|
-
rpc: cfg.rpc,
|
|
63
|
-
executor,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Fetch a transaction by txid via REST.
|
|
68
|
-
* @param txid The transaction ID (64-character hex string).
|
|
69
|
-
* @returns The fetched transaction.
|
|
70
|
-
*/
|
|
71
|
-
async getTransaction(txid) {
|
|
72
|
-
assertString(txid, 'txid');
|
|
73
|
-
return await this.rest.transaction.get(txid);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Broadcast a raw tx (hex) via REST.
|
|
77
|
-
* @param rawTxHex The raw transaction hex string.
|
|
78
|
-
*/
|
|
79
|
-
async send(rawTxHex) {
|
|
80
|
-
assertString(rawTxHex, 'rawTxHex');
|
|
81
|
-
return await this.rest.transaction.send(rawTxHex);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get UTXOs for an address via REST.
|
|
85
|
-
* @param address The Bitcoin address.
|
|
86
|
-
*/
|
|
87
|
-
async getUtxos(address) {
|
|
88
|
-
assertString(address, 'address');
|
|
89
|
-
return await this.rest.address.getUtxos(address);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Get a block by hash or height via REST.
|
|
93
|
-
* @param params Block identifier — at least one of `hash` or `height` is required.
|
|
94
|
-
*/
|
|
95
|
-
async getBlock(params) {
|
|
96
|
-
if (!params.hash && params.height === undefined) {
|
|
97
|
-
throw new Error('getBlock requires at least one of hash or height.');
|
|
98
|
-
}
|
|
99
|
-
return await this.rest.block.get({ blockhash: params.hash, height: params.height });
|
|
100
|
-
}
|
|
101
|
-
/** Convert BTC to satoshis (integer-safe string-split arithmetic). */
|
|
102
|
-
static btcToSats(btc) {
|
|
103
|
-
return BitcoinConnection.btcToSats(btc);
|
|
104
|
-
}
|
|
105
|
-
/** Convert satoshis to BTC (integer-safe string-split arithmetic). */
|
|
106
|
-
static satsToBtc(sats) {
|
|
107
|
-
return BitcoinConnection.satsToBtc(sats);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=bitcoin.js.map
|
package/dist/cjs/bitcoin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin.js","sourceRoot":"","sources":["../../src/bitcoin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAIlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAU;IACrB,gEAAgE;IACvD,UAAU,CAAoB;IAEvC,0CAA0C;IAC1C,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;IAC7B,CAAC;IAED,2DAA2D;IAC3D,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,KAAK,SAAS,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,oFAAoF;kBAClF,uGAAuG,CAC1G,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,YAAY,GAAqB;QAC/B,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;QAC5B,oEAAoE;QACpE,yBAAyB;QACzB,IAAI,CAAC,QA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,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACtF,CAAC;IAED,sEAAsE;IACtE,MAAM,CAAC,SAAS,CAAC,GAAW;QAC1B,OAAO,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAED,sEAAsE;IACtE,MAAM,CAAC,SAAS,CAAC,IAAY;QAC3B,OAAO,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
package/dist/cjs/cas.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { canonicalize, decode as decodeHash } from '@did-btcr2/common';
|
|
2
|
-
import { CID } from 'multiformats/cid';
|
|
3
|
-
import * as raw from 'multiformats/codecs/raw';
|
|
4
|
-
import { create as createDigest } from 'multiformats/hashes/digest';
|
|
5
|
-
import { sha256 } from 'multiformats/hashes/sha2';
|
|
6
|
-
import { assertString } from './helpers.js';
|
|
7
|
-
/**
|
|
8
|
-
* Default {@link CasExecutor} backed by IPFS via Helia.
|
|
9
|
-
*
|
|
10
|
-
* Stores/retrieves data as raw blocks (`0x55` codec) with SHA-256 hashing.
|
|
11
|
-
* The CID is deterministically derived from the content hash, so lookups
|
|
12
|
-
* by base64url SHA-256 hash translate directly to CID lookups.
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export class IpfsCasExecutor {
|
|
16
|
-
#helia;
|
|
17
|
-
constructor(helia) {
|
|
18
|
-
this.#helia = helia;
|
|
19
|
-
}
|
|
20
|
-
async retrieve(hash) {
|
|
21
|
-
const hashBytes = decodeHash(hash, 'base64url');
|
|
22
|
-
const cid = CID.create(1, raw.code, createDigest(sha256.code, hashBytes));
|
|
23
|
-
try {
|
|
24
|
-
return await this.#helia.blockstore.get(cid);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async publish(data) {
|
|
31
|
-
const digest = await sha256.digest(data);
|
|
32
|
-
const cid = CID.createV1(raw.code, digest);
|
|
33
|
-
await this.#helia.blockstore.put(cid, data);
|
|
34
|
-
// Return base64url-encoded hash (no padding)
|
|
35
|
-
return btoa(String.fromCharCode(...digest.bytes.slice(2)))
|
|
36
|
-
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Content-Addressed Storage API sub-facade.
|
|
41
|
-
*
|
|
42
|
-
* Provides `publish` and `retrieve` for JSON objects using their
|
|
43
|
-
* JCS-canonicalized SHA-256 hash as the content address.
|
|
44
|
-
*
|
|
45
|
-
* By default uses IPFS (via Helia). Inject a custom {@link CasExecutor}
|
|
46
|
-
* to use a different CAS backend.
|
|
47
|
-
*
|
|
48
|
-
* Lazily initialized by {@link DidBtcr2Api} to avoid startup overhead
|
|
49
|
-
* when CAS features are not used.
|
|
50
|
-
* @public
|
|
51
|
-
*/
|
|
52
|
-
export class CasApi {
|
|
53
|
-
#executor;
|
|
54
|
-
constructor(config) {
|
|
55
|
-
if (config.executor) {
|
|
56
|
-
this.#executor = config.executor;
|
|
57
|
-
}
|
|
58
|
-
else if (config.helia) {
|
|
59
|
-
this.#executor = new IpfsCasExecutor(config.helia);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw new Error('CAS configuration requires either an executor or a Helia instance. '
|
|
63
|
-
+ 'Example: createApi({ cas: { helia: await createHelia() } })');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Retrieve a JSON object from the CAS by its base64url SHA-256 hash.
|
|
68
|
-
* @param hash Base64url-encoded SHA-256 hash of the JCS-canonicalized object.
|
|
69
|
-
* @returns The parsed JSON object, or `null` if not found.
|
|
70
|
-
*/
|
|
71
|
-
async retrieve(hash) {
|
|
72
|
-
assertString(hash, 'hash');
|
|
73
|
-
const bytes = await this.#executor.retrieve(hash);
|
|
74
|
-
if (!bytes)
|
|
75
|
-
return null;
|
|
76
|
-
return JSON.parse(new TextDecoder().decode(bytes));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Publish a JSON object to the CAS.
|
|
80
|
-
* The object is JCS-canonicalized before storage; the returned hash
|
|
81
|
-
* matches what {@link canonicalHash} would produce.
|
|
82
|
-
* @param object The JSON object to publish.
|
|
83
|
-
* @returns The base64url-encoded SHA-256 hash (content address).
|
|
84
|
-
*/
|
|
85
|
-
async publish(object) {
|
|
86
|
-
const bytes = new TextEncoder().encode(canonicalize(object));
|
|
87
|
-
return await this.#executor.publish(bytes);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=cas.js.map
|
package/dist/cjs/cas.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cas.js","sourceRoot":"","sources":["../../src/cas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAgB5C;;;;;;;GAOG;AACH,MAAM,OAAO,eAAe;IACjB,MAAM,CAAQ;IAEvB,YAAY,KAAY;QACtB,IAAI,CAAC,MAA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