@odatano/core 1.8.0 → 1.9.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/@cds-models/CardanoODataService/index.d.ts +66 -42
- package/@cds-models/CardanoODataService/index.d.ts.map +1 -1
- package/@cds-models/CardanoODataService/index.js.map +1 -1
- package/@cds-models/CardanoODataService/index.ts +11 -7
- package/@cds-models/CardanoSignService/index.d.ts +49 -0
- package/@cds-models/CardanoSignService/index.d.ts.map +1 -1
- package/@cds-models/CardanoSignService/index.js.map +1 -1
- package/@cds-models/CardanoSignService/index.ts +41 -0
- package/@cds-models/odatano/cardano/index.d.ts +70 -46
- package/@cds-models/odatano/cardano/index.d.ts.map +1 -1
- package/@cds-models/odatano/cardano/index.js +2 -2
- package/@cds-models/odatano/cardano/index.js.map +1 -1
- package/@cds-models/odatano/cardano/index.ts +13 -13
- package/db/schema.cds +18 -18
- package/db/types.cds +3 -3
- package/package.json +16 -2
- package/src/index.d.ts +29 -0
- package/src/index.js +1 -0
- package/src/plugin.d.ts +2 -0
- package/src/plugin.js +6 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +155 -0
- package/srv/blockchain/backends/blockfrost-backend.js +19 -8
- package/srv/blockchain/backends/cardano-backend.d.ts +182 -0
- package/srv/blockchain/backends/koios-backend.d.ts +171 -0
- package/srv/blockchain/backends/koios-backend.js +69 -27
- package/srv/blockchain/backends/ogmios-backend.d.ts +188 -0
- package/srv/blockchain/backends/ogmios-backend.js +175 -108
- package/srv/blockchain/cardano-client.d.ts +279 -0
- package/srv/blockchain/cardano-client.js +134 -33
- package/srv/blockchain/cardano-indexer.d.ts +330 -0
- package/srv/blockchain/cardano-indexer.js +51 -8
- package/srv/blockchain/cardano-tx-builder.d.ts +113 -0
- package/srv/blockchain/cardano-tx-builder.js +61 -54
- package/srv/blockchain/circuit-breaker.d.ts +37 -0
- package/srv/blockchain/circuit-breaker.js +11 -2
- package/srv/blockchain/request-coalescer.d.ts +23 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +34 -0
- package/srv/blockchain/signing/cose-verifier.js +128 -0
- package/srv/blockchain/signing/external-signer.d.ts +146 -0
- package/srv/blockchain/signing/external-signer.js +23 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +74 -0
- package/srv/blockchain/signing/hsm-signer.js +20 -5
- package/srv/blockchain/signing/signature-verifier.d.ts +56 -0
- package/srv/blockchain/signing/signature-verifier.js +11 -2
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +236 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +626 -187
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +47 -0
- package/srv/cardano-service.cds +23 -3
- package/srv/cardano-service.d.ts +2 -0
- package/srv/cardano-service.js +25 -5
- package/srv/cardano-sign-service.cds +25 -0
- package/srv/cardano-sign-service.d.ts +2 -0
- package/srv/cardano-sign-service.js +243 -131
- package/srv/cardano-tx-service.d.ts +12 -0
- package/srv/cardano-tx-service.js +152 -110
- package/srv/cbor/index.d.ts +2 -0
- package/srv/cbor/parse.d.ts +64 -0
- package/srv/server.d.ts +90 -0
- package/srv/server.js +34 -9
- package/srv/utils/backend-request-handler.d.ts +20 -0
- package/srv/utils/const.d.ts +183 -0
- package/srv/utils/const.js +13 -6
- package/srv/utils/error-codes.d.ts +79 -0
- package/srv/utils/errors.d.ts +259 -0
- package/srv/utils/errors.js +22 -7
- package/srv/utils/mappers.d.ts +260 -0
- package/srv/utils/mappers.js +52 -17
- package/srv/utils/network-context.d.ts +6 -0
- package/srv/utils/network-context.js +27 -0
- package/srv/utils/plutus-placeholders.d.ts +35 -0
- package/srv/utils/plutus-placeholders.js +5 -15
- package/srv/utils/signing-helper.d.ts +23 -0
- package/srv/utils/signing-helper.js +5 -2
- package/srv/utils/tx-build-helper.d.ts +76 -0
- package/srv/utils/tx-build-helper.js +10 -37
- package/srv/utils/types.d.ts +653 -0
- package/srv/utils/validators.d.ts +145 -0
- package/srv/utils/validators.js +41 -19
- package/@cds-models/CardanoWatcherAdminService/index.js +0 -109
- package/@cds-models/CardanoWatcherAdminService/index.js.map +0 -1
- package/@cds-models/CardanoWatcherAdminService/index.ts +0 -263
- package/@cds-models/cds/outbox/index.js.map +0 -1
- package/@cds-models/cds/xt/MTXServices/index.js +0 -8
- package/@cds-models/cds/xt/MTXServices/index.js.map +0 -1
- package/@cds-models/cds/xt/MTXServices/index.ts +0 -4
- package/@cds-models/odatano/reeve/index.js +0 -77
- package/@cds-models/odatano/reeve/index.js.map +0 -1
- package/@cds-models/odatano/reeve/index.ts +0 -57
- package/@cds-models/odatano/transactions/index.js +0 -55
- package/@cds-models/odatano/transactions/index.js.map +0 -1
- package/@cds-models/odatano/transactions/index.ts +0 -18
- package/@cds-models/odatano/watch/index.js +0 -114
- package/@cds-models/odatano/watch/index.js.map +0 -1
- package/@cds-models/odatano/watch/index.ts +0 -110
- package/config/preview/cardano-node/alonzo-genesis.json +0 -196
- package/config/preview/cardano-node/byron-genesis.json +0 -117
- package/config/preview/cardano-node/config.json +0 -117
- package/config/preview/cardano-node/conway-genesis.json +0 -297
- package/config/preview/cardano-node/peer-snapshot.json +0 -890
- package/config/preview/cardano-node/shelley-genesis.json +0 -68
- package/config/preview/cardano-node/topology.json +0 -24
- package/output/sora/iter0_base.json +0 -32
- package/output/sora/iter0_base.mp4 +0 -0
- package/output/sora/logo_ref_1280x720.png +0 -0
- package/output/sora/odatano_full_logo_sky_ref_1280x720.png +0 -0
- package/output/sora/odatano_full_logo_transparent.png +0 -0
- package/output/sora/odatano_full_logo_transparent_dark.png +0 -0
- package/output/sora/odatano_full_logo_v4_8s.json +0 -32
- package/output/sora/odatano_full_logo_v4_8s.mp4 +0 -0
- package/output/sora/odatano_full_logo_v5_create.json +0 -15
- package/output/sora/odatano_full_logo_v5_fixes.json +0 -15
- package/output/sora/odatano_full_logo_v5_fixes.mp4 +0 -0
- package/output/sora/odatano_logo_v1.json +0 -32
- package/output/sora/odatano_logo_v1.mp4 +0 -0
- package/output/sora/odatano_o_only_clean.png +0 -0
- package/output/sora/odatano_o_sky_ref_1280x720.png +0 -0
- package/output/sora/odatano_o_sky_v2_8s.json +0 -32
- package/output/sora/odatano_o_sky_v2_8s.mp4 +0 -0
- package/output/sora/odatano_o_sky_v3_create.json +0 -15
- package/output/sora/odatano_o_sky_v3_splash_text.json +0 -15
- package/output/sora/odatano_o_sky_v3_splash_text.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo_clean.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo_final.mp4 +0 -0
- package/output/sora/odatano_v6_endframe.jpg +0 -0
- package/output/sora/odatano_v6_endframe_clean.jpg +0 -0
- package/output/sora/odatano_v6_endframe_final.jpg +0 -0
- package/output/sora/odatano_v7_1_earlylogo_fadeoldtext.mp4 +0 -0
- package/output/sora/odatano_v7_1_end.jpg +0 -0
- package/output/sora/odatano_v7_1_transition.jpg +0 -0
- package/output/sora/odatano_v7_2_original2d_keep_sky.mp4 +0 -0
- package/output/sora/odatano_v7_endframe_nobg.jpg +0 -0
- package/output/sora/odatano_v7_endframe_nobg_cleanend.jpg +0 -0
- package/output/sora/odatano_v7_spin_splash_logo_nobg.mp4 +0 -0
- package/output/sora/odatano_v7_spin_splash_logo_nobg_cleanend.mp4 +0 -0
- package/prod.mtaext +0 -17
- package/prod.mtaext.example +0 -27
- package/review.md +0 -42
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/plugin.d.ts.map +0 -1
- package/src/plugin.js.map +0 -1
- package/srv/blockchain/backends/blockfrost-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/blockfrost-backend.js.map +0 -1
- package/srv/blockchain/backends/cardano-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/cardano-backend.js.map +0 -1
- package/srv/blockchain/backends/koios-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/koios-backend.js.map +0 -1
- package/srv/blockchain/backends/ogmios-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/ogmios-backend.js.map +0 -1
- package/srv/blockchain/cardano-client.d.ts.map +0 -1
- package/srv/blockchain/cardano-client.js.map +0 -1
- package/srv/blockchain/cardano-indexer.d.ts.map +0 -1
- package/srv/blockchain/cardano-indexer.js.map +0 -1
- package/srv/blockchain/cardano-tx-builder.d.ts.map +0 -1
- package/srv/blockchain/cardano-tx-builder.js.map +0 -1
- package/srv/blockchain/circuit-breaker.d.ts.map +0 -1
- package/srv/blockchain/circuit-breaker.js.map +0 -1
- package/srv/blockchain/request-coalescer.d.ts.map +0 -1
- package/srv/blockchain/request-coalescer.js.map +0 -1
- package/srv/blockchain/signing/external-signer.d.ts.map +0 -1
- package/srv/blockchain/signing/external-signer.js.map +0 -1
- package/srv/blockchain/signing/hsm-signer.d.ts.map +0 -1
- package/srv/blockchain/signing/hsm-signer.js.map +0 -1
- package/srv/blockchain/signing/signature-verifier.d.ts.map +0 -1
- package/srv/blockchain/signing/signature-verifier.js.map +0 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/buildooor-tx.js.map +0 -1
- package/srv/blockchain/transaction-building/cardano-tx.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/cardano-tx.js.map +0 -1
- package/srv/cardano-service.d.ts.map +0 -1
- package/srv/cardano-service.js.map +0 -1
- package/srv/cardano-sign-service.d.ts.map +0 -1
- package/srv/cardano-sign-service.js.map +0 -1
- package/srv/cardano-tx-service.d.ts.map +0 -1
- package/srv/cardano-tx-service.js.map +0 -1
- package/srv/cbor/index.d.ts.map +0 -1
- package/srv/cbor/index.js.map +0 -1
- package/srv/cbor/parse.d.ts.map +0 -1
- package/srv/cbor/parse.js.map +0 -1
- package/srv/server.d.ts.map +0 -1
- package/srv/server.js.map +0 -1
- package/srv/utils/backend-request-handler.d.ts.map +0 -1
- package/srv/utils/backend-request-handler.js.map +0 -1
- package/srv/utils/const.d.ts.map +0 -1
- package/srv/utils/const.js.map +0 -1
- package/srv/utils/error-codes.d.ts.map +0 -1
- package/srv/utils/error-codes.js.map +0 -1
- package/srv/utils/errors.d.ts.map +0 -1
- package/srv/utils/errors.js.map +0 -1
- package/srv/utils/mappers.d.ts.map +0 -1
- package/srv/utils/mappers.js.map +0 -1
- package/srv/utils/plutus-placeholders.d.ts.map +0 -1
- package/srv/utils/plutus-placeholders.js.map +0 -1
- package/srv/utils/signing-helper.d.ts.map +0 -1
- package/srv/utils/signing-helper.js.map +0 -1
- package/srv/utils/tx-build-helper.d.ts.map +0 -1
- package/srv/utils/tx-build-helper.js.map +0 -1
- package/srv/utils/types.d.ts.map +0 -1
- package/srv/utils/types.js.map +0 -1
- package/srv/utils/validators.d.ts.map +0 -1
- package/srv/utils/validators.js.map +0 -1
|
@@ -208,12 +208,17 @@ class CardanoTransactionBuilder {
|
|
|
208
208
|
if (!scriptOutput) {
|
|
209
209
|
throw new errors_1.TransactionValidationError(`Script UTxO output ${scriptRef.txHash}#${scriptRef.outputIndex} not found in transaction`);
|
|
210
210
|
}
|
|
211
|
+
// spending an already-consumed script UTxO is the most common replay mistake —
|
|
212
|
+
// catch it here with a clear 400 instead of a node-side rejection at submit
|
|
213
|
+
await this._assertUnspent(scriptRef, scriptOutput.address, 'scriptUtxo', new Map());
|
|
211
214
|
allUtxos.push({
|
|
212
215
|
txHash: scriptRef.txHash,
|
|
213
216
|
outputIndex: scriptRef.outputIndex,
|
|
214
217
|
address: scriptOutput.address,
|
|
215
218
|
amount: scriptOutput.amount,
|
|
216
219
|
inlineDatum: scriptOutput.inlineDatum,
|
|
220
|
+
datumHash: scriptOutput.dataHash ?? undefined,
|
|
221
|
+
scriptRef: scriptOutput.referenceScriptHash ?? undefined,
|
|
217
222
|
});
|
|
218
223
|
}
|
|
219
224
|
// Resolve forced inputs (may overlap with sender UTxOs or the script UTxO — dedup below).
|
|
@@ -242,68 +247,65 @@ class CardanoTransactionBuilder {
|
|
|
242
247
|
return txBuildResult;
|
|
243
248
|
}
|
|
244
249
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
250
|
+
* Verify that a transaction output resolved via getTransaction is still unspent,
|
|
251
|
+
* by checking the live UTxO set of its address. getTransaction only proves the
|
|
252
|
+
* output EXISTED — a spent output would otherwise surface as a cryptic node-side
|
|
253
|
+
* rejection at submit instead of a clear 400 here.
|
|
249
254
|
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
* @returns resolved UTxOs, in the same order as deduped refs
|
|
255
|
+
* Lookup failures are logged and tolerated (the check is best-effort; refusing to
|
|
256
|
+
* build on a flaky backend would be a new failure mode).
|
|
253
257
|
*/
|
|
254
|
-
async
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const key = `${r.txHash}#${r.outputIndex}`;
|
|
261
|
-
if (seen.has(key))
|
|
262
|
-
return false;
|
|
263
|
-
seen.add(key);
|
|
264
|
-
return true;
|
|
265
|
-
});
|
|
266
|
-
const resolved = [];
|
|
267
|
-
for (const ref of dedupedRefs) {
|
|
268
|
-
// 1) Cheap path: already in sender UTxOs
|
|
269
|
-
const local = senderUtxos.find(u => u.txHash === ref.txHash && u.outputIndex === ref.outputIndex);
|
|
270
|
-
if (local) {
|
|
271
|
-
resolved.push(local);
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
// 2) Fallback: fetch the producing transaction and look up the output.
|
|
275
|
-
// If the output does not exist OR the UTxO has already been spent, treat as missing.
|
|
276
|
-
let tx;
|
|
277
|
-
try {
|
|
278
|
-
tx = await this.client.getTransaction(ref.txHash);
|
|
258
|
+
async _assertUnspent(ref, address, kind, liveUtxoCache) {
|
|
259
|
+
let live;
|
|
260
|
+
try {
|
|
261
|
+
const cached = liveUtxoCache.get(address);
|
|
262
|
+
if (cached) {
|
|
263
|
+
live = cached;
|
|
279
264
|
}
|
|
280
|
-
|
|
281
|
-
|
|
265
|
+
else {
|
|
266
|
+
live = await this.client.getAddressUtxos(address);
|
|
267
|
+
liveUtxoCache.set(address, live);
|
|
282
268
|
}
|
|
283
|
-
const output = tx?.outputs?.find(o => o.outputIndex === ref.outputIndex);
|
|
284
|
-
if (!output) {
|
|
285
|
-
throw new errors_1.TransactionValidationError(`forceInput ${ref.txHash}#${ref.outputIndex} not found on-chain`);
|
|
286
|
-
}
|
|
287
|
-
resolved.push({
|
|
288
|
-
txHash: ref.txHash,
|
|
289
|
-
outputIndex: ref.outputIndex,
|
|
290
|
-
address: output.address,
|
|
291
|
-
amount: output.amount,
|
|
292
|
-
inlineDatum: output.inlineDatum,
|
|
293
|
-
datumHash: output.dataHash ?? undefined,
|
|
294
|
-
scriptRef: output.referenceScriptHash ?? undefined,
|
|
295
|
-
});
|
|
296
269
|
}
|
|
297
|
-
|
|
270
|
+
catch (err) {
|
|
271
|
+
logger.warn(`Could not verify ${kind} ${ref.txHash}#${ref.outputIndex} is unspent: ${err instanceof Error ? err.message : String(err)}`);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const isLive = live.some(u => u.txHash === ref.txHash && u.outputIndex === ref.outputIndex);
|
|
275
|
+
if (!isLive) {
|
|
276
|
+
throw new errors_1.TransactionValidationError(`${kind} ${ref.txHash}#${ref.outputIndex} is already spent`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Resolve forced-input refs (consumed) to full UTxO records.
|
|
281
|
+
* Thin wrapper over _resolveInputRefs — see it for behaviour.
|
|
282
|
+
*/
|
|
283
|
+
_resolveForceInputs(refs, senderUtxos) {
|
|
284
|
+
return this._resolveInputRefs(refs, senderUtxos, 'forceInput');
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Resolve CIP-31 reference input refs (read-only, NOT merged into the
|
|
288
|
+
* coin-selection set) to full UTxO records.
|
|
289
|
+
*/
|
|
290
|
+
_resolveReferenceInputs(refs, knownUtxos) {
|
|
291
|
+
return this._resolveInputRefs(refs, knownUtxos, 'referenceInput');
|
|
298
292
|
}
|
|
299
293
|
/**
|
|
300
|
-
* Resolve
|
|
301
|
-
*
|
|
302
|
-
*
|
|
294
|
+
* Resolve a list of {txHash, outputIndex} refs to full UTxO records.
|
|
295
|
+
* Prefers matching against already-known UTxOs to avoid extra backend calls;
|
|
296
|
+
* otherwise fetches the producing transaction and verifies the output is
|
|
297
|
+
* unspent. Throws TransactionValidationError (labelled by `kind`) if any ref
|
|
298
|
+
* cannot be resolved (missing or spent). Deduplicates refs before lookup.
|
|
299
|
+
*
|
|
300
|
+
* @param refs input refs from the request
|
|
301
|
+
* @param knownUtxos UTxOs already fetched (cheap-match pool)
|
|
302
|
+
* @param kind label used in error messages / the spent-check
|
|
303
|
+
* @returns resolved UTxOs, in the same order as the deduped refs
|
|
303
304
|
*/
|
|
304
|
-
async
|
|
305
|
+
async _resolveInputRefs(refs, knownUtxos, kind) {
|
|
305
306
|
if (!refs || refs.length === 0)
|
|
306
307
|
return [];
|
|
308
|
+
// Dedup by "txHash#index" key
|
|
307
309
|
const seen = new Set();
|
|
308
310
|
const dedupedRefs = refs.filter(r => {
|
|
309
311
|
const key = `${r.txHash}#${r.outputIndex}`;
|
|
@@ -312,24 +314,29 @@ class CardanoTransactionBuilder {
|
|
|
312
314
|
seen.add(key);
|
|
313
315
|
return true;
|
|
314
316
|
});
|
|
317
|
+
const liveUtxoCache = new Map();
|
|
315
318
|
const resolved = [];
|
|
316
319
|
for (const ref of dedupedRefs) {
|
|
320
|
+
// 1) Cheap path: already known
|
|
317
321
|
const local = knownUtxos.find(u => u.txHash === ref.txHash && u.outputIndex === ref.outputIndex);
|
|
318
322
|
if (local) {
|
|
319
323
|
resolved.push(local);
|
|
320
324
|
continue;
|
|
321
325
|
}
|
|
326
|
+
// 2) Fallback: fetch the producing transaction and look up the output.
|
|
322
327
|
let tx;
|
|
323
328
|
try {
|
|
324
329
|
tx = await this.client.getTransaction(ref.txHash);
|
|
325
330
|
}
|
|
326
331
|
catch (err) {
|
|
327
|
-
throw new errors_1.TransactionValidationError(
|
|
332
|
+
throw new errors_1.TransactionValidationError(`${kind} ${ref.txHash}#${ref.outputIndex} not found on-chain`, err);
|
|
328
333
|
}
|
|
329
334
|
const output = tx?.outputs?.find(o => o.outputIndex === ref.outputIndex);
|
|
330
335
|
if (!output) {
|
|
331
|
-
throw new errors_1.TransactionValidationError(
|
|
336
|
+
throw new errors_1.TransactionValidationError(`${kind} ${ref.txHash}#${ref.outputIndex} not found on-chain`);
|
|
332
337
|
}
|
|
338
|
+
// getTransaction proves existence, not spendability
|
|
339
|
+
await this._assertUnspent(ref, output.address, kind, liveUtxoCache);
|
|
333
340
|
resolved.push({
|
|
334
341
|
txHash: ref.txHash,
|
|
335
342
|
outputIndex: ref.outputIndex,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type CircuitState = 'closed' | 'open' | 'half-open';
|
|
2
|
+
export interface CircuitBreakerConfig {
|
|
3
|
+
/** Number of failures before opening the circuit (default: 5) */
|
|
4
|
+
failureThreshold: number;
|
|
5
|
+
/** Number of successes in half-open before closing (default: 2) */
|
|
6
|
+
successThreshold: number;
|
|
7
|
+
/** Time in ms before transitioning from open to half-open (default: 30000) */
|
|
8
|
+
resetTimeoutMs: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Circuit Breaker for backend failover.
|
|
12
|
+
* Tracks per-backend failure counts and prevents hammering unhealthy backends.
|
|
13
|
+
*
|
|
14
|
+
* States:
|
|
15
|
+
* closed → normal operation, requests pass through
|
|
16
|
+
* open → backend is unhealthy, requests are skipped
|
|
17
|
+
* half-open → probe period, limited requests allowed to test recovery
|
|
18
|
+
*/
|
|
19
|
+
export declare class CircuitBreakerManager {
|
|
20
|
+
private circuits;
|
|
21
|
+
private config;
|
|
22
|
+
constructor(config?: Partial<CircuitBreakerConfig>);
|
|
23
|
+
/**
|
|
24
|
+
* Check if a backend should be attempted.
|
|
25
|
+
* Transitions open → half-open if reset timeout has elapsed.
|
|
26
|
+
*/
|
|
27
|
+
shouldAttempt(backendName: string): boolean;
|
|
28
|
+
/** Record a successful call to a backend. */
|
|
29
|
+
recordSuccess(backendName: string): void;
|
|
30
|
+
/** Record a failed call to a backend. */
|
|
31
|
+
recordFailure(backendName: string): void;
|
|
32
|
+
/** Get the current state of a backend's circuit. */
|
|
33
|
+
getState(backendName: string): CircuitState;
|
|
34
|
+
/** Reset all circuit states (for testing). */
|
|
35
|
+
reset(): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -41,12 +41,18 @@ class CircuitBreakerManager {
|
|
|
41
41
|
if (elapsed >= this.config.resetTimeoutMs) {
|
|
42
42
|
entry.state = 'half-open';
|
|
43
43
|
entry.successes = 0;
|
|
44
|
+
entry.halfOpenProbes = 1; // this caller takes the first probe slot
|
|
44
45
|
logger.debug(`Circuit half-open for ${backendName} after ${elapsed}ms`);
|
|
45
46
|
return true;
|
|
46
47
|
}
|
|
47
48
|
return false;
|
|
48
49
|
}
|
|
49
|
-
// half-open:
|
|
50
|
+
// half-open: cap in-flight probes at successThreshold — previously a burst
|
|
51
|
+
// of concurrent requests all probed a barely-recovering backend at once
|
|
52
|
+
if (entry.halfOpenProbes >= this.config.successThreshold) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
entry.halfOpenProbes++;
|
|
50
56
|
return true;
|
|
51
57
|
}
|
|
52
58
|
/** Record a successful call to a backend. */
|
|
@@ -55,11 +61,13 @@ class CircuitBreakerManager {
|
|
|
55
61
|
if (!entry)
|
|
56
62
|
return;
|
|
57
63
|
if (entry.state === 'half-open') {
|
|
64
|
+
entry.halfOpenProbes = Math.max(0, entry.halfOpenProbes - 1); // release probe slot
|
|
58
65
|
entry.successes++;
|
|
59
66
|
if (entry.successes >= this.config.successThreshold) {
|
|
60
67
|
entry.state = 'closed';
|
|
61
68
|
entry.failures = 0;
|
|
62
69
|
entry.successes = 0;
|
|
70
|
+
entry.halfOpenProbes = 0;
|
|
63
71
|
logger.info(`Circuit closed for ${backendName} (recovered)`);
|
|
64
72
|
}
|
|
65
73
|
}
|
|
@@ -72,7 +80,7 @@ class CircuitBreakerManager {
|
|
|
72
80
|
recordFailure(backendName) {
|
|
73
81
|
let entry = this.circuits.get(backendName);
|
|
74
82
|
if (!entry) {
|
|
75
|
-
entry = { state: 'closed', failures: 0, successes: 0, lastFailureTime: 0 };
|
|
83
|
+
entry = { state: 'closed', failures: 0, successes: 0, lastFailureTime: 0, halfOpenProbes: 0 };
|
|
76
84
|
this.circuits.set(backendName, entry);
|
|
77
85
|
}
|
|
78
86
|
entry.failures++;
|
|
@@ -81,6 +89,7 @@ class CircuitBreakerManager {
|
|
|
81
89
|
// Any failure in half-open reopens the circuit
|
|
82
90
|
entry.state = 'open';
|
|
83
91
|
entry.successes = 0;
|
|
92
|
+
entry.halfOpenProbes = 0;
|
|
84
93
|
logger.warn(`Circuit re-opened for ${backendName} (failed during probe)`);
|
|
85
94
|
}
|
|
86
95
|
else if (entry.state === 'closed' && entry.failures >= this.config.failureThreshold) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestCoalescer — Deduplicates concurrent requests for the same resource key.
|
|
3
|
+
*
|
|
4
|
+
* When multiple callers request the same key simultaneously (e.g., same txHash
|
|
5
|
+
* during parallel address indexing), only one backend call is made. All callers
|
|
6
|
+
* receive the same Promise/result.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RequestCoalescer<T> {
|
|
9
|
+
private pending;
|
|
10
|
+
/**
|
|
11
|
+
* Get a value by key, deduplicating concurrent requests.
|
|
12
|
+
* If a request for this key is already in-flight, returns the existing Promise.
|
|
13
|
+
* Otherwise, calls the fetcher and caches the Promise until it resolves.
|
|
14
|
+
*
|
|
15
|
+
* @param key Unique identifier (e.g., txHash, bech32 address)
|
|
16
|
+
* @param fetcher Function that performs the actual fetch
|
|
17
|
+
* @returns The fetched value
|
|
18
|
+
*/
|
|
19
|
+
get(key: string, fetcher: () => Promise<T>): Promise<T>;
|
|
20
|
+
/** Number of currently in-flight requests */
|
|
21
|
+
get size(): number;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=request-coalescer.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input to {@link verifyDataSignature}. Mirrors the CIP-30 `signData` result:
|
|
3
|
+
* `coseSignature` is the hex `signature` field (COSE_Sign1), `coseKey` is the
|
|
4
|
+
* hex `key` field (COSE_Key).
|
|
5
|
+
*/
|
|
6
|
+
export interface CoseVerifyInput {
|
|
7
|
+
address: string;
|
|
8
|
+
coseSignature: string;
|
|
9
|
+
coseKey: string;
|
|
10
|
+
expectedPayload?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Result of a COSE_Sign1 verification. Shape mirrors the CDS action return. */
|
|
13
|
+
export interface CoseVerifyResult {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
/** failure detail when !valid; empty string when valid */
|
|
16
|
+
reason: string;
|
|
17
|
+
/** UTF-8 of the signed payload, echoed back for the caller to inspect */
|
|
18
|
+
signedPayload: string;
|
|
19
|
+
/** hex blake2b-224 of the signer public key (empty until the key is parsed) */
|
|
20
|
+
signerVkh: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Verify a CIP-30 `signData` (COSE_Sign1) message signature against a bech32
|
|
24
|
+
* address. Stateless crypto only & no nonce/replay/session handling.
|
|
25
|
+
* Never throws: all failures are returned as `{ valid: false, reason }`.
|
|
26
|
+
*
|
|
27
|
+
* Checks, in order:
|
|
28
|
+
* 1. COSE_Sign1 + COSE_Key parse
|
|
29
|
+
* 2. signer key hash (blake2b-224) == the address payment credential (key, not script)
|
|
30
|
+
* 3. (optional) signed payload == expectedPayload
|
|
31
|
+
* 4. Ed25519 signature over the COSE Sig_structure
|
|
32
|
+
*/
|
|
33
|
+
export declare function verifyDataSignature(input: CoseVerifyInput): CoseVerifyResult;
|
|
34
|
+
//# sourceMappingURL=cose-verifier.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.verifyDataSignature = verifyDataSignature;
|
|
7
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
8
|
+
const cbor_1 = require("@harmoniclabs/cbor");
|
|
9
|
+
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
10
|
+
const crypto_1 = require("@harmoniclabs/crypto");
|
|
11
|
+
const validators_1 = require("../../utils/validators");
|
|
12
|
+
const logger = cds_1.default.log('CoseVerifier');
|
|
13
|
+
/** CBOR tag 18 = COSE_Sign1 (RFC 8152). signData may or may not wrap in it. */
|
|
14
|
+
const COSE_SIGN1_TAG = 18;
|
|
15
|
+
/** COSE_Key label for the OKP public key x-coordinate (the raw Ed25519 key). */
|
|
16
|
+
const COSE_KEY_LABEL_X = -2;
|
|
17
|
+
const ED25519_PUBKEY_LEN = 32;
|
|
18
|
+
/** Find a COSE map entry by its integer label (handles +ve and -ve labels). */
|
|
19
|
+
function findIntLabel(map, label) {
|
|
20
|
+
const entry = map.map.find(e => {
|
|
21
|
+
if (e.k instanceof cbor_1.CborUInt)
|
|
22
|
+
return Number(e.k.num) === label;
|
|
23
|
+
if (e.k instanceof cbor_1.CborNegInt)
|
|
24
|
+
return Number(e.k.num) === label;
|
|
25
|
+
return false;
|
|
26
|
+
});
|
|
27
|
+
return entry?.v;
|
|
28
|
+
}
|
|
29
|
+
function parseCoseSign1(hex) {
|
|
30
|
+
let obj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(hex));
|
|
31
|
+
// CIP-30 signData may emit the COSE_Sign1 wrapped in tag 18 or bare.
|
|
32
|
+
if (obj instanceof cbor_1.CborTag && Number(obj.tag) === COSE_SIGN1_TAG)
|
|
33
|
+
obj = obj.data;
|
|
34
|
+
if (!(obj instanceof cbor_1.CborArray) || obj.array.length !== 4) {
|
|
35
|
+
throw new Error('COSE_Sign1 must be a 4-element array [protected, unprotected, payload, signature]');
|
|
36
|
+
}
|
|
37
|
+
const [prot, , payload, signature] = obj.array;
|
|
38
|
+
if (!(prot instanceof cbor_1.CborBytes))
|
|
39
|
+
throw new Error('COSE_Sign1 protected header must be a byte string');
|
|
40
|
+
if (!(payload instanceof cbor_1.CborBytes))
|
|
41
|
+
throw new Error('COSE_Sign1 payload must be a byte string (detached payloads are not supported)');
|
|
42
|
+
if (!(signature instanceof cbor_1.CborBytes))
|
|
43
|
+
throw new Error('COSE_Sign1 signature must be a byte string');
|
|
44
|
+
return { protectedBytes: prot.bytes, payload: payload.bytes, signature: signature.bytes };
|
|
45
|
+
}
|
|
46
|
+
/** Extract the raw 32-byte Ed25519 public key from a COSE_Key (label -2). */
|
|
47
|
+
function parseCoseKey(hex) {
|
|
48
|
+
const obj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(hex));
|
|
49
|
+
if (!(obj instanceof cbor_1.CborMap))
|
|
50
|
+
throw new Error('COSE_Key must be a CBOR map');
|
|
51
|
+
const x = findIntLabel(obj, COSE_KEY_LABEL_X);
|
|
52
|
+
if (!(x instanceof cbor_1.CborBytes))
|
|
53
|
+
throw new Error('COSE_Key is missing the Ed25519 public key (label -2)');
|
|
54
|
+
if (x.bytes.length !== ED25519_PUBKEY_LEN) {
|
|
55
|
+
throw new Error(`COSE_Key public key must be ${ED25519_PUBKEY_LEN} bytes, got ${x.bytes.length}`);
|
|
56
|
+
}
|
|
57
|
+
return x.bytes;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build the COSE Sig_structure that was actually signed and CBOR-encode it:
|
|
61
|
+
* [ "Signature1" (tstr), protected (bstr, exact bytes), external_aad (h''), payload (bstr) ]
|
|
62
|
+
* external_aad is empty for CIP-8 / CIP-30 signData.
|
|
63
|
+
*/
|
|
64
|
+
function buildSigStructure(protectedBytes, payload) {
|
|
65
|
+
const sigStruct = new cbor_1.CborArray([
|
|
66
|
+
new cbor_1.CborText('Signature1'),
|
|
67
|
+
new cbor_1.CborBytes(protectedBytes),
|
|
68
|
+
new cbor_1.CborBytes(new Uint8Array(0)),
|
|
69
|
+
new cbor_1.CborBytes(payload),
|
|
70
|
+
]);
|
|
71
|
+
return cbor_1.Cbor.encode(sigStruct);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Verify a CIP-30 `signData` (COSE_Sign1) message signature against a bech32
|
|
75
|
+
* address. Stateless crypto only & no nonce/replay/session handling.
|
|
76
|
+
* Never throws: all failures are returned as `{ valid: false, reason }`.
|
|
77
|
+
*
|
|
78
|
+
* Checks, in order:
|
|
79
|
+
* 1. COSE_Sign1 + COSE_Key parse
|
|
80
|
+
* 2. signer key hash (blake2b-224) == the address payment credential (key, not script)
|
|
81
|
+
* 3. (optional) signed payload == expectedPayload
|
|
82
|
+
* 4. Ed25519 signature over the COSE Sig_structure
|
|
83
|
+
*/
|
|
84
|
+
function verifyDataSignature(input) {
|
|
85
|
+
const result = { valid: false, reason: '', signedPayload: '', signerVkh: '' };
|
|
86
|
+
try {
|
|
87
|
+
const { protectedBytes, payload, signature } = parseCoseSign1(input.coseSignature);
|
|
88
|
+
const pubKey = parseCoseKey(input.coseKey);
|
|
89
|
+
result.signedPayload = Buffer.from(payload).toString('utf8');
|
|
90
|
+
result.signerVkh = (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(pubKey));
|
|
91
|
+
// 2. signer key hash must equal the address payment credential (key hash, not script)
|
|
92
|
+
const cred = (0, validators_1.extractPaymentCredential)(input.address);
|
|
93
|
+
if (!cred) {
|
|
94
|
+
result.reason = 'Address could not be decoded or has no payment credential (base/enterprise key-hash address required)';
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
if (cred.isScript) {
|
|
98
|
+
result.reason = 'Address payment credential is a script hash; a key-hash address is required';
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
if (cred.hash.toLowerCase() !== result.signerVkh.toLowerCase()) {
|
|
102
|
+
result.reason = `Signer key hash ${result.signerVkh} does not match address payment credential ${cred.hash}`;
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
// 3. optional anti-replay payload check
|
|
106
|
+
if (input.expectedPayload !== undefined && input.expectedPayload !== null) {
|
|
107
|
+
if (result.signedPayload !== input.expectedPayload) {
|
|
108
|
+
result.reason = 'Signed payload does not match the expected payload';
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// 4. Ed25519 signature over the rebuilt Sig_structure
|
|
113
|
+
const sigStructure = buildSigStructure(protectedBytes, payload);
|
|
114
|
+
if (!(0, crypto_1.verifyEd25519Signature_sync)(signature, sigStructure, pubKey)) {
|
|
115
|
+
result.reason = 'Ed25519 signature does not verify against the signed message';
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
result.valid = true;
|
|
119
|
+
logger.debug({ signerVkh: result.signerVkh }, 'COSE_Sign1 data signature verified');
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
result.reason = `Failed to verify data signature: ${err instanceof Error ? err.message : String(err)}`;
|
|
124
|
+
logger.warn(result.reason);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=cose-verifier.js.map
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { SignatureVerifier } from './signature-verifier';
|
|
2
|
+
import { ExternalSignerType, UnsignedTxExportPayload, SignedTxPayload, SigningWorkflowState, SignatureVerificationResult, VerificationOptions } from '../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* ExternalSignerModule - Manages the external signing workflow
|
|
5
|
+
*
|
|
6
|
+
* This module orchestrates the complete flow:
|
|
7
|
+
* 1. Create signing request from build result
|
|
8
|
+
* 2. Export unsigned transaction for external signing
|
|
9
|
+
* 3. Receive and verify signed transaction
|
|
10
|
+
* 4. Prepare for submission
|
|
11
|
+
*
|
|
12
|
+
* Key security principles:
|
|
13
|
+
* - NO private keys are ever handled by this service
|
|
14
|
+
* - Signature verification ensures transaction integrity
|
|
15
|
+
* - Complete audit trail of the signing workflow
|
|
16
|
+
*/
|
|
17
|
+
export declare class ExternalSignerModule {
|
|
18
|
+
private verifier;
|
|
19
|
+
private signingTtlMs;
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
signingTtlMs?: number;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Create an unsigned transaction export payload for external signing
|
|
25
|
+
*
|
|
26
|
+
* This is the entry point for the external signing workflow.
|
|
27
|
+
* Call this after building a transaction to get a standardized
|
|
28
|
+
* payload that external signers can use.
|
|
29
|
+
*
|
|
30
|
+
* @param buildId - The build ID from TransactionBuilds
|
|
31
|
+
* @param unsignedTxCbor - The unsigned transaction CBOR
|
|
32
|
+
* @param txBodyHash - The transaction body hash
|
|
33
|
+
* @param network - The Cardano network
|
|
34
|
+
* @param options - Additional options
|
|
35
|
+
* @returns Unsigned transaction export payload
|
|
36
|
+
*/
|
|
37
|
+
createSigningRequest(buildId: string, unsignedTxCbor: string, txBodyHash: string, network: string, message: string, options?: {
|
|
38
|
+
requiredSigners?: string[];
|
|
39
|
+
signerTypeHint?: ExternalSignerType;
|
|
40
|
+
}): UnsignedTxExportPayload;
|
|
41
|
+
/**
|
|
42
|
+
* Generate signing instructions for different signer types
|
|
43
|
+
*/
|
|
44
|
+
private generateSigningInstructions;
|
|
45
|
+
/**
|
|
46
|
+
* Verify a signed transaction
|
|
47
|
+
*
|
|
48
|
+
* Call this after receiving a signed transaction from an external signer.
|
|
49
|
+
* This verifies the signature integrity before submission.
|
|
50
|
+
*
|
|
51
|
+
* @param signedTxCbor - The signed transaction CBOR
|
|
52
|
+
* @param expectedTxBodyHash - The expected transaction body hash (from the build)
|
|
53
|
+
* @param options - Additional verification options
|
|
54
|
+
* @returns Verification result
|
|
55
|
+
*/
|
|
56
|
+
verifySignedTransaction(signedTxCbor: string, expectedTxBodyHash: string, options?: Omit<VerificationOptions, 'expectedTxBodyHash'> & {
|
|
57
|
+
expiresAt?: string;
|
|
58
|
+
}): SignatureVerificationResult;
|
|
59
|
+
/**
|
|
60
|
+
* Verify signed transaction and throw on failure
|
|
61
|
+
*
|
|
62
|
+
* @param signedTxCbor - The signed transaction CBOR
|
|
63
|
+
* @param expectedTxBodyHash - The expected transaction body hash
|
|
64
|
+
* @param options - Additional verification options
|
|
65
|
+
* @throws {TransactionValidationError} if verification fails
|
|
66
|
+
*/
|
|
67
|
+
verifyOrThrow(signedTxCbor: string, expectedTxBodyHash: string, options?: Omit<VerificationOptions, 'expectedTxBodyHash'>): SignatureVerificationResult;
|
|
68
|
+
/**
|
|
69
|
+
* Create a complete signing workflow state
|
|
70
|
+
*
|
|
71
|
+
* This creates a trackable workflow state that can be stored
|
|
72
|
+
* and updated throughout the signing process.
|
|
73
|
+
*
|
|
74
|
+
* @param signingRequest - The unsigned transaction export payload
|
|
75
|
+
* @returns Initial workflow state
|
|
76
|
+
*/
|
|
77
|
+
createWorkflowState(signingRequest: UnsignedTxExportPayload): SigningWorkflowState;
|
|
78
|
+
/**
|
|
79
|
+
* Update workflow state after signing
|
|
80
|
+
*
|
|
81
|
+
* @param state - Current workflow state
|
|
82
|
+
* @param signedTxCbor - The signed transaction CBOR
|
|
83
|
+
* @returns Updated workflow state
|
|
84
|
+
*/
|
|
85
|
+
markAsSigned(state: SigningWorkflowState, signedTxCbor: string): SigningWorkflowState;
|
|
86
|
+
/**
|
|
87
|
+
* Update workflow state after verification
|
|
88
|
+
*
|
|
89
|
+
* @param state - Current workflow state
|
|
90
|
+
* @param verificationResult - The verification result
|
|
91
|
+
* @returns Updated workflow state
|
|
92
|
+
*/
|
|
93
|
+
markAsVerified(state: SigningWorkflowState, verificationResult: SignatureVerificationResult): SigningWorkflowState;
|
|
94
|
+
/**
|
|
95
|
+
* Update workflow state after submission
|
|
96
|
+
*
|
|
97
|
+
* @param state - Current workflow state
|
|
98
|
+
* @param txHash - The submitted transaction hash
|
|
99
|
+
* @returns Updated workflow state
|
|
100
|
+
*/
|
|
101
|
+
markAsSubmitted(state: SigningWorkflowState, txHash: string): SigningWorkflowState;
|
|
102
|
+
/**
|
|
103
|
+
* Update workflow state on failure
|
|
104
|
+
*
|
|
105
|
+
* @param state - Current workflow state
|
|
106
|
+
* @param errorMessage - The error message
|
|
107
|
+
* @returns Updated workflow state
|
|
108
|
+
*/
|
|
109
|
+
markAsFailed(state: SigningWorkflowState, errorMessage: string): SigningWorkflowState;
|
|
110
|
+
/**
|
|
111
|
+
* Check if a signing request has expired
|
|
112
|
+
*
|
|
113
|
+
* @param expiresAt - The expiration timestamp (ISO 8601)
|
|
114
|
+
* @returns true if expired
|
|
115
|
+
*/
|
|
116
|
+
isExpired(expiresAt: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Validate a signed transaction payload before submission
|
|
119
|
+
*
|
|
120
|
+
* This performs all pre-submission checks:
|
|
121
|
+
* 1. Verify the signature
|
|
122
|
+
* 2. Check transaction hasn't been tampered with
|
|
123
|
+
* 3. Ensure the build ID matches
|
|
124
|
+
*
|
|
125
|
+
* @param payload - The signed transaction payload
|
|
126
|
+
* @param originalBuildTxBodyHash - The original transaction body hash from the build
|
|
127
|
+
* @returns Validation result with verification details
|
|
128
|
+
* @throws {TransactionValidationError} if validation fails
|
|
129
|
+
*/
|
|
130
|
+
validateForSubmission(payload: SignedTxPayload, originalBuildTxBodyHash: string): SignatureVerificationResult;
|
|
131
|
+
/**
|
|
132
|
+
* Get the signature verifier instance
|
|
133
|
+
*/
|
|
134
|
+
getVerifier(): SignatureVerifier;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get the singleton ExternalSignerModule instance
|
|
138
|
+
*/
|
|
139
|
+
export declare function getExternalSignerModule(): ExternalSignerModule;
|
|
140
|
+
/**
|
|
141
|
+
* Create a new ExternalSignerModule instance with custom options
|
|
142
|
+
*/
|
|
143
|
+
export declare function createExternalSignerModule(options?: {
|
|
144
|
+
signingTtlMs?: number;
|
|
145
|
+
}): ExternalSignerModule;
|
|
146
|
+
//# sourceMappingURL=external-signer.d.ts.map
|
|
@@ -15,6 +15,28 @@ const logger = cds_1.default.log('ExternalSigner');
|
|
|
15
15
|
* Default TTL for signing requests (30 minutes)
|
|
16
16
|
*/
|
|
17
17
|
const DEFAULT_SIGNING_TTL_MS = 30 * 60 * 1000;
|
|
18
|
+
/** Network flag for cardano-cli (mainnet vs testnet-magic). */
|
|
19
|
+
const CLI_NETWORK_FLAG = {
|
|
20
|
+
mainnet: '--mainnet',
|
|
21
|
+
preprod: '--testnet-magic 1',
|
|
22
|
+
preview: '--testnet-magic 2',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Build a copy-pasteable cardano-cli signing recipe for the unsigned tx.
|
|
26
|
+
* Templated (the caller supplies their own signing key file); the network flag
|
|
27
|
+
* and the unsigned CBOR are filled in. Previously this was always NULL despite
|
|
28
|
+
* the schema exposing a `cardanoCliCommand` field.
|
|
29
|
+
*/
|
|
30
|
+
function buildCardanoCliCommand(network, unsignedTxCbor) {
|
|
31
|
+
const netFlag = CLI_NETWORK_FLAG[network] ?? '--testnet-magic <MAGIC>';
|
|
32
|
+
return [
|
|
33
|
+
'# 1) Save the unsigned transaction to a file:',
|
|
34
|
+
`echo '{"type":"Unwitnessed Tx ConwayEra","description":"","cborHex":"${unsignedTxCbor}"}' > tx.unsigned`,
|
|
35
|
+
'# 2) Sign it with your payment key:',
|
|
36
|
+
`cardano-cli conway transaction sign --tx-file tx.unsigned --signing-key-file payment.skey ${netFlag} --out-file tx.signed`,
|
|
37
|
+
'# 3) Submit the cborHex from tx.signed via SubmitSignedTransaction / SubmitVerifiedTransaction',
|
|
38
|
+
].join('\n');
|
|
39
|
+
}
|
|
18
40
|
/**
|
|
19
41
|
* ExternalSignerModule - Manages the external signing workflow
|
|
20
42
|
*
|
|
@@ -87,6 +109,7 @@ class ExternalSignerModule {
|
|
|
87
109
|
txCbor: unsignedTxCbor,
|
|
88
110
|
partialSign: false,
|
|
89
111
|
},
|
|
112
|
+
cardanoCliCommand: buildCardanoCliCommand(network, unsignedTxCbor),
|
|
90
113
|
};
|
|
91
114
|
}
|
|
92
115
|
/**
|