@did-btcr2/api 0.2.2 → 0.3.1
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/browser.js +56457 -104900
- package/dist/browser.mjs +56442 -104885
- package/dist/cjs/api.js +31 -934
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/bitcoin.js +110 -0
- package/dist/cjs/bitcoin.js.map +1 -0
- package/dist/cjs/cas.js +90 -0
- package/dist/cjs/cas.js.map +1 -0
- package/dist/cjs/crypto.js +425 -0
- package/dist/cjs/crypto.js.map +1 -0
- package/dist/cjs/did.js +70 -0
- package/dist/cjs/did.js.map +1 -0
- package/dist/cjs/helpers.js +28 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/kms.js +73 -0
- package/dist/cjs/kms.js.map +1 -0
- package/dist/cjs/method.js +262 -0
- package/dist/cjs/method.js.map +1 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/api.js +31 -934
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/bitcoin.js +110 -0
- package/dist/esm/bitcoin.js.map +1 -0
- package/dist/esm/cas.js +90 -0
- package/dist/esm/cas.js.map +1 -0
- package/dist/esm/crypto.js +425 -0
- package/dist/esm/crypto.js.map +1 -0
- package/dist/esm/did.js +70 -0
- package/dist/esm/did.js.map +1 -0
- package/dist/esm/helpers.js +28 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/kms.js +73 -0
- package/dist/esm/kms.js.map +1 -0
- package/dist/esm/method.js +262 -0
- package/dist/esm/method.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/api.d.ts +19 -693
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/bitcoin.d.ts +64 -0
- package/dist/types/bitcoin.d.ts.map +1 -0
- package/dist/types/cas.d.ts +70 -0
- package/dist/types/cas.d.ts.map +1 -0
- package/dist/types/crypto.d.ts +310 -0
- package/dist/types/crypto.d.ts.map +1 -0
- package/dist/types/did.d.ts +51 -0
- package/dist/types/did.d.ts.map +1 -0
- package/dist/types/helpers.d.ts +10 -0
- package/dist/types/helpers.d.ts.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/kms.d.ts +49 -0
- package/dist/types/kms.d.ts.map +1 -0
- package/dist/types/method.d.ts +117 -0
- package/dist/types/method.d.ts.map +1 -0
- package/dist/types/types.d.ts +128 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/api.ts +40 -1317
- package/src/bitcoin.ts +129 -0
- package/src/cas.ts +121 -0
- package/src/crypto.ts +525 -0
- package/src/did.ts +75 -0
- package/src/helpers.ts +35 -0
- package/src/index.ts +37 -1
- package/src/kms.ts +95 -0
- package/src/method.ts +331 -0
- package/src/types.ts +122 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { BIP340Cryptosuite, BIP340DataIntegrityProof, SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
2
|
+
import { CompressedSecp256k1PublicKey, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
|
|
3
|
+
/**
|
|
4
|
+
* Schnorr keypair operations.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class KeyPairApi {
|
|
8
|
+
/**
|
|
9
|
+
* Generate a new Schnorr keypair.
|
|
10
|
+
* @returns The generated Schnorr keypair.
|
|
11
|
+
*/
|
|
12
|
+
generate() {
|
|
13
|
+
return SchnorrKeyPair.generate();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a Schnorr keypair from secret key bytes or hex string.
|
|
17
|
+
* @param data The secret key bytes or hex string.
|
|
18
|
+
* @returns The created Schnorr keypair.
|
|
19
|
+
*/
|
|
20
|
+
fromSecret(data) {
|
|
21
|
+
return SchnorrKeyPair.fromSecret(data);
|
|
22
|
+
}
|
|
23
|
+
/** Create a secret key from entropy (bytes or bigint). */
|
|
24
|
+
secretKeyFrom(ent) {
|
|
25
|
+
return new Secp256k1SecretKey(ent);
|
|
26
|
+
}
|
|
27
|
+
/** Create a compressed public key from bytes. */
|
|
28
|
+
publicKeyFrom(byt) {
|
|
29
|
+
return new CompressedSecp256k1PublicKey(byt);
|
|
30
|
+
}
|
|
31
|
+
/** Deserialize a keypair from a JSON object. */
|
|
32
|
+
fromJSON(obj) {
|
|
33
|
+
return SchnorrKeyPair.fromJSON(obj);
|
|
34
|
+
}
|
|
35
|
+
/** Serialize a keypair to a JSON object. */
|
|
36
|
+
toJSON(kp) {
|
|
37
|
+
return kp.exportJSON();
|
|
38
|
+
}
|
|
39
|
+
/** Compare two keypairs for equality. */
|
|
40
|
+
equals(kp1, kp2) {
|
|
41
|
+
return SchnorrKeyPair.equals(kp1, kp2);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Schnorr cryptosuite operations.
|
|
46
|
+
*
|
|
47
|
+
* Optionally stateful: call {@link use} to set a current cryptosuite, then
|
|
48
|
+
* call {@link createProof}, {@link verifyProof}, or {@link toDataIntegrityProof}
|
|
49
|
+
* without passing an explicit instance. Pass an explicit instance to any
|
|
50
|
+
* method to override the current one for that call.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export class CryptosuiteApi {
|
|
54
|
+
#current;
|
|
55
|
+
/** The currently active cryptosuite, or `undefined` if none is set. */
|
|
56
|
+
get current() {
|
|
57
|
+
return this.#current;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set the current cryptosuite for subsequent operations.
|
|
61
|
+
* @param cs The cryptosuite to activate.
|
|
62
|
+
* @returns `this` for chaining.
|
|
63
|
+
*/
|
|
64
|
+
use(cs) {
|
|
65
|
+
this.#current = cs;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/** Clear the current cryptosuite. */
|
|
69
|
+
clear() {
|
|
70
|
+
this.#current = undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a new Schnorr cryptosuite from a multikey.
|
|
74
|
+
* @param multikey The Schnorr multikey to use.
|
|
75
|
+
* @returns The created Schnorr cryptosuite.
|
|
76
|
+
*/
|
|
77
|
+
create(multikey) {
|
|
78
|
+
return new BIP340Cryptosuite(multikey);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Convenience: resolve a key from the KMS and create a cryptosuite in one step.
|
|
82
|
+
* @param id The multikey ID (e.g. '#initialKey').
|
|
83
|
+
* @param controller The DID that controls this key.
|
|
84
|
+
* @param keyId The KMS key identifier to resolve.
|
|
85
|
+
* @param kms The KeyManagerApi instance holding the key.
|
|
86
|
+
* @returns The created Schnorr cryptosuite.
|
|
87
|
+
*/
|
|
88
|
+
createFromKms(id, controller, keyId, kms) {
|
|
89
|
+
const pubBytes = kms.getPublicKey(keyId);
|
|
90
|
+
const mk = SchnorrMultikey.fromPublicKey({ id, controller, publicKeyBytes: pubBytes });
|
|
91
|
+
return new BIP340Cryptosuite(mk);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Convert a cryptosuite to a Data Integrity Proof instance.
|
|
95
|
+
* Uses the current cryptosuite when `cryptosuite` is omitted.
|
|
96
|
+
* @param cryptosuite Optional explicit cryptosuite to convert.
|
|
97
|
+
* @returns The Data Integrity Proof instance.
|
|
98
|
+
*/
|
|
99
|
+
toDataIntegrityProof(cryptosuite) {
|
|
100
|
+
const cs = cryptosuite ?? this.#requireCurrent();
|
|
101
|
+
return cs.toDataIntegrityProof();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a proof for a document.
|
|
105
|
+
* Uses the current cryptosuite when `cryptosuite` is omitted.
|
|
106
|
+
* @param document The document to create the proof for.
|
|
107
|
+
* @param config Configuration for the proof creation.
|
|
108
|
+
* @param cryptosuite Optional explicit cryptosuite; defaults to current.
|
|
109
|
+
* @returns The created proof.
|
|
110
|
+
*/
|
|
111
|
+
createProof(document, config, cryptosuite) {
|
|
112
|
+
const cs = cryptosuite ?? this.#requireCurrent();
|
|
113
|
+
return cs.createProof(document, config);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Verify a proof for a document.
|
|
117
|
+
* Uses the current cryptosuite when `cryptosuite` is omitted.
|
|
118
|
+
* @param document The document to verify the proof for.
|
|
119
|
+
* @param cryptosuite Optional explicit cryptosuite; defaults to current.
|
|
120
|
+
* @returns The full verification result.
|
|
121
|
+
*/
|
|
122
|
+
verifyProof(document, cryptosuite) {
|
|
123
|
+
const cs = cryptosuite ?? this.#requireCurrent();
|
|
124
|
+
return cs.verifyProof(document);
|
|
125
|
+
}
|
|
126
|
+
#requireCurrent() {
|
|
127
|
+
if (!this.#current) {
|
|
128
|
+
throw new Error('No current cryptosuite set. Call cryptosuite.use(cs) first, or pass an explicit instance.');
|
|
129
|
+
}
|
|
130
|
+
return this.#current;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Data Integrity Proof operations.
|
|
135
|
+
*
|
|
136
|
+
* Optionally stateful: call {@link use} to set a current proof instance, then
|
|
137
|
+
* call {@link addProof} or {@link verifyProof} without passing an explicit
|
|
138
|
+
* instance. Pass an explicit instance to override for that call.
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export class DataIntegrityProofApi {
|
|
142
|
+
#current;
|
|
143
|
+
/** The currently active proof instance, or `undefined` if none is set. */
|
|
144
|
+
get current() {
|
|
145
|
+
return this.#current;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Set the current proof instance for subsequent operations.
|
|
149
|
+
* @param p The proof instance to activate.
|
|
150
|
+
* @returns `this` for chaining.
|
|
151
|
+
*/
|
|
152
|
+
use(p) {
|
|
153
|
+
this.#current = p;
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/** Clear the current proof instance. */
|
|
157
|
+
clear() {
|
|
158
|
+
this.#current = undefined;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a BIP340DataIntegrityProof instance with the given cryptosuite.
|
|
162
|
+
* @param cryptosuite The cryptosuite to use for proof operations.
|
|
163
|
+
* @returns The created BIP340DataIntegrityProof instance.
|
|
164
|
+
*/
|
|
165
|
+
create(cryptosuite) {
|
|
166
|
+
return new BIP340DataIntegrityProof(cryptosuite);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Add a proof to a document.
|
|
170
|
+
* Uses the current proof instance when `proof` is omitted.
|
|
171
|
+
* @param document The document to add the proof to.
|
|
172
|
+
* @param config Configuration for adding the proof.
|
|
173
|
+
* @param proof Optional explicit proof instance; defaults to current.
|
|
174
|
+
* @returns A document with a proof added.
|
|
175
|
+
*/
|
|
176
|
+
addProof(document, config, proof) {
|
|
177
|
+
const p = proof ?? this.#requireCurrent();
|
|
178
|
+
return p.addProof(document, config);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Convenience: create a cryptosuite, proof instance, and sign a document
|
|
182
|
+
* in one call. Requires a multikey with signing capability.
|
|
183
|
+
* @param multikey The Schnorr multikey (must include secret key).
|
|
184
|
+
* @param document The unsigned document to sign.
|
|
185
|
+
* @param config The Data Integrity proof configuration.
|
|
186
|
+
* @returns The signed document with proof attached.
|
|
187
|
+
*/
|
|
188
|
+
signDocument(multikey, document, config) {
|
|
189
|
+
const cs = new BIP340Cryptosuite(multikey);
|
|
190
|
+
const proofInst = new BIP340DataIntegrityProof(cs);
|
|
191
|
+
return proofInst.addProof(document, config);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Verify a proof using a BIP340DataIntegrityProof instance.
|
|
195
|
+
* Uses the current proof instance when `proof` is omitted.
|
|
196
|
+
* @param document The document to verify the proof for.
|
|
197
|
+
* @param expectedPurpose The expected proof purpose.
|
|
198
|
+
* @param mediaType The media type of the document.
|
|
199
|
+
* @param expectedDomain The expected domain for the proof.
|
|
200
|
+
* @param expectedChallenge The expected challenge for the proof.
|
|
201
|
+
* @param proof Optional explicit proof instance; defaults to current.
|
|
202
|
+
* @returns The result of verifying the proof.
|
|
203
|
+
*/
|
|
204
|
+
verifyProof(document, expectedPurpose, mediaType, expectedDomain, expectedChallenge, proof) {
|
|
205
|
+
const p = proof ?? this.#requireCurrent();
|
|
206
|
+
return p.verifyProof(document, expectedPurpose, mediaType, expectedDomain, expectedChallenge);
|
|
207
|
+
}
|
|
208
|
+
#requireCurrent() {
|
|
209
|
+
if (!this.#current) {
|
|
210
|
+
throw new Error('No current proof instance set. Call proof.use(p) first, or pass an explicit instance.');
|
|
211
|
+
}
|
|
212
|
+
return this.#current;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Schnorr multikey operations.
|
|
217
|
+
*
|
|
218
|
+
* Optionally stateful: call {@link use} to set a current multikey, then
|
|
219
|
+
* call {@link sign}, {@link verify}, or {@link toVerificationMethod} without
|
|
220
|
+
* passing an explicit instance. Pass an explicit instance to any method to
|
|
221
|
+
* override the current one for that call.
|
|
222
|
+
* @public
|
|
223
|
+
*/
|
|
224
|
+
export class MultikeyApi {
|
|
225
|
+
#current;
|
|
226
|
+
/** The currently active multikey, or `undefined` if none is set. */
|
|
227
|
+
get current() {
|
|
228
|
+
return this.#current;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Set the current multikey for subsequent operations.
|
|
232
|
+
* @param mk The multikey to activate.
|
|
233
|
+
* @returns `this` for chaining.
|
|
234
|
+
*/
|
|
235
|
+
use(mk) {
|
|
236
|
+
this.#current = mk;
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
/** Clear the current multikey. */
|
|
240
|
+
clear() {
|
|
241
|
+
this.#current = undefined;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a new Schnorr multikey from a keypair.
|
|
245
|
+
* @param id The multikey ID.
|
|
246
|
+
* @param controller The multikey controller.
|
|
247
|
+
* @param keyPair The Schnorr keypair to use.
|
|
248
|
+
* @returns The created Schnorr multikey.
|
|
249
|
+
*/
|
|
250
|
+
create(id, controller, keyPair) {
|
|
251
|
+
return new SchnorrMultikey({ id, controller, keyPair });
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Create a Schnorr multikey from raw secret key bytes.
|
|
255
|
+
* @param id The multikey ID.
|
|
256
|
+
* @param controller The multikey controller.
|
|
257
|
+
* @param secretKeyBytes The secret key bytes.
|
|
258
|
+
* @returns The created Schnorr multikey.
|
|
259
|
+
*/
|
|
260
|
+
fromSecretKey(id, controller, secretKeyBytes) {
|
|
261
|
+
return SchnorrMultikey.fromSecretKey(id, controller, secretKeyBytes);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Create a verification-only multikey from public key bytes.
|
|
265
|
+
* @param params The id, controller, and publicKeyBytes.
|
|
266
|
+
* @returns The created Multikey.
|
|
267
|
+
*/
|
|
268
|
+
fromPublicKey(params) {
|
|
269
|
+
return SchnorrMultikey.fromPublicKey(params);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Convenience: resolve a key from the KMS and create a multikey in one step.
|
|
273
|
+
* @param id The multikey ID.
|
|
274
|
+
* @param controller The multikey controller DID.
|
|
275
|
+
* @param keyId The KMS key identifier to resolve.
|
|
276
|
+
* @param kms The KeyManagerApi instance holding the key.
|
|
277
|
+
* @returns The created Multikey (verification-only; public key from KMS).
|
|
278
|
+
*/
|
|
279
|
+
fromKms(id, controller, keyId, kms) {
|
|
280
|
+
const pubBytes = kms.getPublicKey(keyId);
|
|
281
|
+
return SchnorrMultikey.fromPublicKey({ id, controller, publicKeyBytes: pubBytes });
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Reconstruct a multikey from a DID document's verification method.
|
|
285
|
+
* @param verificationMethod The verification method to convert.
|
|
286
|
+
* @returns The reconstructed multikey.
|
|
287
|
+
*/
|
|
288
|
+
fromVerificationMethod(verificationMethod) {
|
|
289
|
+
return SchnorrMultikey.fromVerificationMethod(verificationMethod);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Produce a DID Verification Method JSON from a multikey.
|
|
293
|
+
* Uses the current multikey when `mk` is omitted.
|
|
294
|
+
* @param mk Optional explicit multikey; defaults to current.
|
|
295
|
+
*/
|
|
296
|
+
toVerificationMethod(mk) {
|
|
297
|
+
const m = mk ?? this.#requireCurrent();
|
|
298
|
+
return m.toVerificationMethod();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Sign bytes via the multikey (requires secret).
|
|
302
|
+
* Uses the current multikey when `mk` is omitted.
|
|
303
|
+
* @param data The data to sign.
|
|
304
|
+
* @param mk Optional explicit multikey; defaults to current.
|
|
305
|
+
*/
|
|
306
|
+
sign(data, mk) {
|
|
307
|
+
const m = mk ?? this.#requireCurrent();
|
|
308
|
+
return m.sign(data);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Verify signature via multikey.
|
|
312
|
+
* Uses the current multikey when `mk` is omitted.
|
|
313
|
+
* @param data The data that was signed.
|
|
314
|
+
* @param signature The signature to verify.
|
|
315
|
+
* @param mk Optional explicit multikey; defaults to current.
|
|
316
|
+
*/
|
|
317
|
+
verify(data, signature, mk) {
|
|
318
|
+
const m = mk ?? this.#requireCurrent();
|
|
319
|
+
return m.verify(signature, data);
|
|
320
|
+
}
|
|
321
|
+
#requireCurrent() {
|
|
322
|
+
if (!this.#current) {
|
|
323
|
+
throw new Error('No current multikey set. Call multikey.use(mk) first, or pass an explicit instance.');
|
|
324
|
+
}
|
|
325
|
+
return this.#current;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Aggregated cryptographic operations sub-facade.
|
|
330
|
+
*
|
|
331
|
+
* Provides direct access to the four sub-facades ({@link keypair},
|
|
332
|
+
* {@link multikey}, {@link cryptosuite}, {@link proof}) plus top-level
|
|
333
|
+
* convenience methods that orchestrate the full signing/verification
|
|
334
|
+
* pipeline using their stateful defaults.
|
|
335
|
+
*
|
|
336
|
+
* @example Stateful pipeline
|
|
337
|
+
* ```ts
|
|
338
|
+
* const api = createApi();
|
|
339
|
+
* const kp = api.crypto.keypair.generate();
|
|
340
|
+
* const mk = api.crypto.multikey.create('#key-1', 'did:btcr2:test', kp);
|
|
341
|
+
*
|
|
342
|
+
* // Set the active multikey — flows through to cryptosuite and proof
|
|
343
|
+
* api.crypto.activate(mk);
|
|
344
|
+
*
|
|
345
|
+
* // Now sign without threading instances
|
|
346
|
+
* const signed = api.crypto.signDocument(unsignedDoc, proofConfig);
|
|
347
|
+
* ```
|
|
348
|
+
* @public
|
|
349
|
+
*/
|
|
350
|
+
export class CryptoApi {
|
|
351
|
+
/** Schnorr keypair operations. */
|
|
352
|
+
keypair = new KeyPairApi();
|
|
353
|
+
/** Schnorr Multikey operations (optionally stateful). */
|
|
354
|
+
multikey = new MultikeyApi();
|
|
355
|
+
/** Schnorr Cryptosuite operations (optionally stateful). */
|
|
356
|
+
cryptosuite = new CryptosuiteApi();
|
|
357
|
+
/** Data Integrity Proof operations (optionally stateful). */
|
|
358
|
+
proof = new DataIntegrityProofApi();
|
|
359
|
+
/**
|
|
360
|
+
* Activate a multikey and propagate through the full pipeline.
|
|
361
|
+
* Sets the current multikey, creates a cryptosuite from it, and creates
|
|
362
|
+
* a proof instance from the cryptosuite — all three sub-facades become
|
|
363
|
+
* ready for stateful operations.
|
|
364
|
+
* @param mk The multikey to activate (must include a secret key for signing).
|
|
365
|
+
* @returns `this` for chaining.
|
|
366
|
+
*/
|
|
367
|
+
activate(mk) {
|
|
368
|
+
this.multikey.use(mk);
|
|
369
|
+
const cs = this.cryptosuite.create(mk);
|
|
370
|
+
this.cryptosuite.use(cs);
|
|
371
|
+
const p = this.proof.create(cs);
|
|
372
|
+
this.proof.use(p);
|
|
373
|
+
return this;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Clear stateful defaults from all sub-facades.
|
|
377
|
+
*/
|
|
378
|
+
deactivate() {
|
|
379
|
+
this.multikey.clear();
|
|
380
|
+
this.cryptosuite.clear();
|
|
381
|
+
this.proof.clear();
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Sign data using the current multikey.
|
|
385
|
+
* Shorthand for `crypto.multikey.sign(data)`.
|
|
386
|
+
* @param data The data to sign.
|
|
387
|
+
* @returns The signature bytes.
|
|
388
|
+
*/
|
|
389
|
+
sign(data) {
|
|
390
|
+
return this.multikey.sign(data);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Verify a signature using the current multikey.
|
|
394
|
+
* Shorthand for `crypto.multikey.verify(data, signature)`.
|
|
395
|
+
* @param data The data that was signed.
|
|
396
|
+
* @param signature The signature to verify.
|
|
397
|
+
* @returns `true` if the signature is valid.
|
|
398
|
+
*/
|
|
399
|
+
verify(data, signature) {
|
|
400
|
+
return this.multikey.verify(data, signature);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Sign a BTCR2 update document using the current proof instance.
|
|
404
|
+
* Shorthand for `crypto.proof.addProof(document, config)`.
|
|
405
|
+
*
|
|
406
|
+
* Requires {@link activate} to have been called first, or the three
|
|
407
|
+
* sub-facades to have been configured individually.
|
|
408
|
+
* @param document The unsigned BTCR2 update document.
|
|
409
|
+
* @param config The Data Integrity proof configuration.
|
|
410
|
+
* @returns The signed document with proof attached.
|
|
411
|
+
*/
|
|
412
|
+
signDocument(document, config) {
|
|
413
|
+
return this.proof.addProof(document, config);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Verify a signed BTCR2 update document using the current cryptosuite.
|
|
417
|
+
* Shorthand for `crypto.cryptosuite.verifyProof(document)`.
|
|
418
|
+
* @param document The signed document to verify.
|
|
419
|
+
* @returns The full verification result.
|
|
420
|
+
*/
|
|
421
|
+
verifyDocument(document) {
|
|
422
|
+
return this.cryptosuite.verifyProof(document);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EAMxB,eAAe,EAIhB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAKtG;;;GAGG;AACH,MAAM,OAAO,UAAU;IACrB;;;OAGG;IACH,QAAQ;QACN,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,IAA0B;QACnC,OAAO,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,0DAA0D;IAC1D,aAAa,CAAC,GAAY;QACxB,OAAO,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,iDAAiD;IACjD,aAAa,CAAC,GAAU;QACtB,OAAO,IAAI,4BAA4B,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED,gDAAgD;IAChD,QAAQ,CAAC,GAAyB;QAChC,OAAO,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IAED,4CAA4C;IAC5C,MAAM,CAAC,EAAkB;QACvB,OAAO,EAAE,CAAC,UAAU,EAAE,CAAC;IACzB,CAAC;IAED,yCAAyC;IACzC,MAAM,CAAC,GAAmB,EAAE,GAAmB;QAC7C,OAAO,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzC,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAc;IACzB,QAAQ,CAAqB;IAE7B,uEAAuE;IACvE,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ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
|
|
1
|
+
import { IdentifierTypes } from '@did-btcr2/common';
|
|
2
|
+
import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
|
+
import { Identifier } from '@did-btcr2/method';
|
|
4
|
+
import { Did } from '@web5/dids';
|
|
5
|
+
import { assertBytes, assertString } from './helpers.js';
|
|
6
|
+
/**
|
|
7
|
+
* DID identifier operations sub-facade (encode, decode, generate, parse).
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export class DidApi {
|
|
11
|
+
/**
|
|
12
|
+
* Encode a DID from genesis bytes and options.
|
|
13
|
+
* @param genesisBytes The genesis document bytes.
|
|
14
|
+
* @param options The creation options.
|
|
15
|
+
* @returns The encoded DID string.
|
|
16
|
+
*/
|
|
17
|
+
encode(genesisBytes, options) {
|
|
18
|
+
assertBytes(genesisBytes, 'genesisBytes');
|
|
19
|
+
return Identifier.encode(genesisBytes, options);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Decode a DID into its components.
|
|
23
|
+
* @param did The DID string to decode.
|
|
24
|
+
* @returns The decoded identifier components.
|
|
25
|
+
*/
|
|
26
|
+
decode(did) {
|
|
27
|
+
assertString(did, 'did');
|
|
28
|
+
return Identifier.decode(did);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate a new DID along with its keypair.
|
|
32
|
+
*
|
|
33
|
+
* When no `network` is given, defaults to `'regtest'` (upstream default).
|
|
34
|
+
* Pass an explicit network to generate DIDs for other networks.
|
|
35
|
+
*
|
|
36
|
+
* @param network Optional network to generate the DID for.
|
|
37
|
+
* @returns The generated keypair and DID string.
|
|
38
|
+
*/
|
|
39
|
+
generate(network) {
|
|
40
|
+
if (!network)
|
|
41
|
+
return Identifier.generate();
|
|
42
|
+
const kp = SchnorrKeyPair.generate();
|
|
43
|
+
const did = Identifier.encode(kp.publicKey.compressed, {
|
|
44
|
+
idType: IdentifierTypes.KEY,
|
|
45
|
+
network,
|
|
46
|
+
});
|
|
47
|
+
return { keyPair: kp.exportJSON(), did };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a DID string is valid.
|
|
51
|
+
* @param did The DID string to validate.
|
|
52
|
+
* @returns `true` if valid, `false` otherwise.
|
|
53
|
+
*/
|
|
54
|
+
isValid(did) {
|
|
55
|
+
if (typeof did !== 'string' || did.length === 0)
|
|
56
|
+
return false;
|
|
57
|
+
return Identifier.isValid(did);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse a DID string into a Did instance.
|
|
61
|
+
* @param did The DID string to parse.
|
|
62
|
+
* @returns The parsed Did instance, or `null` if parsing failed.
|
|
63
|
+
*/
|
|
64
|
+
parse(did) {
|
|
65
|
+
if (typeof did !== 'string' || did.length === 0)
|
|
66
|
+
return null;
|
|
67
|
+
return Did.parse(did);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=did.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did.js","sourceRoot":"","sources":["../../src/did.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAwB,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEzD;;;GAGG;AACH,MAAM,OAAO,MAAM;IACjB;;;;;OAKG;IACH,MAAM,CAAC,YAA2B,EAAE,OAAyB;QAC3D,WAAW,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QAC1C,OAAO,UAAU,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAW;QAChB,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAqB;QAC5B,IAAI,CAAC,OAAO;YAAE,OAAO,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC3C,MAAM,EAAE,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE;YACrD,MAAM,EAAG,eAAe,CAAC,GAAG;YAC5B,OAAO;SACR,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,GAAW;QACjB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC9D,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAW;QACf,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7D,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const noopFn = () => { };
|
|
2
|
+
/** @internal */
|
|
3
|
+
export const NOOP_LOGGER = {
|
|
4
|
+
debug: noopFn,
|
|
5
|
+
info: noopFn,
|
|
6
|
+
warn: noopFn,
|
|
7
|
+
error: noopFn,
|
|
8
|
+
};
|
|
9
|
+
/** @internal */
|
|
10
|
+
export function assertString(value, name) {
|
|
11
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
12
|
+
throw new Error(`${name} must be a non-empty string.`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** @internal */
|
|
16
|
+
export function assertBytes(value, name) {
|
|
17
|
+
if (!(value instanceof Uint8Array) || value.length === 0) {
|
|
18
|
+
throw new Error(`${name} must be a non-empty Uint8Array.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** @internal */
|
|
22
|
+
export function assertCompressedPubkey(value, name) {
|
|
23
|
+
assertBytes(value, name);
|
|
24
|
+
if (value.length !== 33) {
|
|
25
|
+
throw new Error(`${name} must be a 33-byte compressed public key, got ${value.length} bytes.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAExB,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAW;IACjC,KAAK,EAAG,MAAM;IACd,IAAI,EAAI,MAAM;IACd,IAAI,EAAI,MAAM;IACd,KAAK,EAAG,MAAM;CACf,CAAC;AAEF,gBAAgB;AAChB,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,IAAY;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,8BAA8B,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,IAAY;IACtD,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,kCAAkC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,KAAc,EAAE,IAAY;IACjE,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzB,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,iDAAiD,KAAK,CAAC,MAAM,SAAS,CAC9E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
// Upstream re-exports
|
|
2
|
+
export { DidDocument, DidDocumentBuilder, Identifier } from '@did-btcr2/method';
|
|
3
|
+
export { IdentifierTypes } from '@did-btcr2/common';
|
|
4
|
+
// Local modules
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export * from './helpers.js';
|
|
7
|
+
export * from './bitcoin.js';
|
|
8
|
+
export * from './cas.js';
|
|
9
|
+
export * from './kms.js';
|
|
10
|
+
export * from './crypto.js';
|
|
11
|
+
export * from './did.js';
|
|
12
|
+
export * from './method.js';
|
|
1
13
|
export * from './api.js';
|
|
2
14
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAyBpD,gBAAgB;AAChB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
package/dist/esm/kms.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Kms, } from '@did-btcr2/kms';
|
|
2
|
+
import { assertBytes } from './helpers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Key management operations sub-facade.
|
|
5
|
+
*
|
|
6
|
+
* Wraps a {@link KeyManager} interface. By default uses the built-in
|
|
7
|
+
* {@link Kms} implementation; a custom implementation can be injected
|
|
8
|
+
* via {@link ApiConfig}.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export class KeyManagerApi {
|
|
12
|
+
/** The backing KeyManager instance. */
|
|
13
|
+
kms;
|
|
14
|
+
/** Create a new KeyManagerApi, optionally backed by a custom KeyManager. */
|
|
15
|
+
constructor(kms) {
|
|
16
|
+
this.kms = kms ?? new Kms();
|
|
17
|
+
}
|
|
18
|
+
/** Generate a new key directly in the KMS. */
|
|
19
|
+
generateKey(options) {
|
|
20
|
+
return this.kms.generateKey(options);
|
|
21
|
+
}
|
|
22
|
+
/** Set the active key by its identifier. */
|
|
23
|
+
setActive(id) {
|
|
24
|
+
this.kms.setActiveKey(id);
|
|
25
|
+
}
|
|
26
|
+
/** Get the public key bytes for a key identifier. */
|
|
27
|
+
getPublicKey(id) {
|
|
28
|
+
return this.kms.getPublicKey(id);
|
|
29
|
+
}
|
|
30
|
+
/** Import a Schnorr keypair into the KMS. */
|
|
31
|
+
import(kp, options) {
|
|
32
|
+
return this.kms.importKey(kp, options);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Export a Schnorr keypair from the KMS.
|
|
36
|
+
* Only supported when the backing KMS is the built-in {@link Kms} class.
|
|
37
|
+
* @throws {Error} If the backing KMS does not support key export.
|
|
38
|
+
*/
|
|
39
|
+
export(id) {
|
|
40
|
+
if (!(this.kms instanceof Kms)) {
|
|
41
|
+
throw new Error('Key export is not supported by the current KeyManager implementation. '
|
|
42
|
+
+ 'Export is only available with the built-in Kms class.');
|
|
43
|
+
}
|
|
44
|
+
return this.kms.exportKey(id);
|
|
45
|
+
}
|
|
46
|
+
/** List all managed key identifiers. */
|
|
47
|
+
listKeys() {
|
|
48
|
+
return this.kms.listKeys();
|
|
49
|
+
}
|
|
50
|
+
/** Remove a key from the KMS. */
|
|
51
|
+
removeKey(id, options = {}) {
|
|
52
|
+
return this.kms.removeKey(id, options);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sign data via the KMS.
|
|
56
|
+
* @param data The data to sign (must be non-empty).
|
|
57
|
+
* @param id Optional key identifier; uses the active key if omitted.
|
|
58
|
+
* @param options Signing options (scheme defaults to 'schnorr').
|
|
59
|
+
*/
|
|
60
|
+
sign(data, id, options) {
|
|
61
|
+
assertBytes(data, 'data');
|
|
62
|
+
return this.kms.sign(data, id, options);
|
|
63
|
+
}
|
|
64
|
+
/** Verify a signature via the KMS. */
|
|
65
|
+
verify(signature, data, id, options) {
|
|
66
|
+
return this.kms.verify(signature, data, id, options);
|
|
67
|
+
}
|
|
68
|
+
/** Compute a SHA-256 digest. */
|
|
69
|
+
digest(data) {
|
|
70
|
+
return this.kms.digest(data);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=kms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kms.js","sourceRoot":"","sources":["../../src/kms.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,GAAG,GAEJ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IACxB,uCAAuC;IAC9B,GAAG,CAAa;IAEzB,4EAA4E;IAC5E,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED,8CAA8C;IAC9C,WAAW,CAAC,OAA4B;QACtC,OAAO,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