@odatano/core 2.0.0-rc.49 → 2.0.0-rc.50
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/CardanoAgentService/index.d.ts +6 -12
- package/@cds-models/CardanoIndexerService/index.d.ts +200 -2
- package/@cds-models/CardanoIndexerService/index.js +24 -0
- package/@cds-models/CardanoODataService/index.d.ts +49 -6
- package/@cds-models/CardanoODataService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +3 -3
- package/@cds-models/CardanoWorkerService/index.d.ts +4 -3
- package/@cds-models/index.d.ts +9 -1
- package/@cds-models/index.js +2 -1
- package/@cds-models/odatano/cardano/index.d.ts +59 -5
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/README.md +29 -17
- package/db/schema.cds +117 -24
- package/db/types.cds +8 -0
- package/package.json +17 -15
- package/scripts/migrate-schema.mjs +334 -0
- package/src/index.d.ts +7 -5
- package/src/index.js +12 -10
- package/src/plugin.js +6 -7
- package/srv/blockchain/backends/blockfrost-backend.js +9 -1
- package/srv/blockchain/backends/cardano-backend.d.ts +15 -0
- package/srv/blockchain/backends/cardano-backend.js +5 -0
- package/srv/blockchain/backends/koios-backend.js +16 -10
- package/srv/blockchain/backends/ogmios-backend.d.ts +9 -3
- package/srv/blockchain/backends/ogmios-backend.js +60 -18
- package/srv/blockchain/cardano-client.d.ts +5 -4
- package/srv/blockchain/cardano-client.js +46 -13
- package/srv/blockchain/cardano-indexer.d.ts +116 -9
- package/srv/blockchain/cardano-indexer.js +436 -189
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +153 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +23 -1
- package/srv/blockchain/crawler/asset-registry-backfill.js +91 -1
- package/srv/blockchain/crawler/certificate-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/certificate-backfill.js +10 -3
- package/srv/blockchain/crawler/crawler.d.ts +15 -0
- package/srv/blockchain/crawler/crawler.js +68 -3
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +171 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
- package/srv/blockchain/crawler/transaction-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/transaction-backfill.js +12 -8
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -1
- package/srv/blockchain/signing/cose-verifier.js +144 -56
- package/srv/blockchain/signing/hsm-signer.js +2 -1
- package/srv/blockchain/signing/submission-finalizer.d.ts +15 -4
- package/srv/blockchain/signing/submission-finalizer.js +201 -69
- package/srv/blockchain/stored-chain.js +1 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +1 -3
- package/srv/blockchain/transaction-building/buildooor-tx.js +34 -54
- package/srv/blockchain/transaction-presence.d.ts +5 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.js +1 -1
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -1
- package/srv/blockchain/wallet-worker/build-request.js +25 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +1 -1
- package/srv/blockchain/wallet-worker/job-store.d.ts +17 -7
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +2 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +2 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +42 -32
- package/srv/cardano-agent-service.cds +11 -12
- package/srv/cardano-agent-service.js +2 -0
- package/srv/cardano-backend-service.cds +34 -1
- package/srv/cardano-backend-service.js +20 -17
- package/srv/cardano-indexer-service.cds +153 -12
- package/srv/cardano-indexer-service.js +175 -29
- package/srv/cardano-service.cds +67 -3
- package/srv/cardano-service.js +132 -67
- package/srv/cardano-sign-service.cds +30 -20
- package/srv/cardano-sign-service.js +13 -10
- package/srv/cardano-tx-service.cds +15 -1
- package/srv/cardano-tx-service.js +4 -1
- package/srv/cardano-worker-service.cds +16 -7
- package/srv/cardano-worker-service.js +31 -22
- package/srv/cbor/parse.js +11 -34
- package/srv/config.d.ts +113 -0
- package/srv/config.js +409 -0
- package/srv/server.d.ts +9 -14
- package/srv/server.js +32 -316
- package/srv/utils/agent-access.d.ts +9 -0
- package/srv/utils/agent-access.js +67 -0
- package/srv/utils/agent-grants-config.d.ts +0 -17
- package/srv/utils/agent-grants-config.js +6 -81
- package/srv/utils/agent-grants.d.ts +6 -19
- package/srv/utils/agent-grants.js +69 -130
- package/srv/utils/const.d.ts +4 -0
- package/srv/utils/const.js +5 -1
- package/srv/utils/db-indexes.js +11 -3
- package/srv/utils/error-codes.d.ts +4 -0
- package/srv/utils/error-codes.js +4 -0
- package/srv/utils/errors.d.ts +6 -0
- package/srv/utils/errors.js +23 -1
- package/srv/utils/liveness.js +2 -5
- package/srv/utils/mappers.d.ts +5 -7
- package/srv/utils/mappers.js +22 -9
- package/srv/utils/pg-order-nulls.js +4 -3
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/tx-request-parsers.d.ts +1 -1
- package/srv/utils/tx-request-parsers.js +3 -3
- package/srv/utils/tx-utils.d.ts +3 -0
- package/srv/utils/tx-utils.js +17 -3
- package/srv/utils/types.d.ts +16 -3
- package/scripts/migrate-txseq.mjs +0 -138
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -13
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +0 -71
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -15
- package/srv/blockchain/transaction-building/caller-datums.js +0 -133
- package/srv/cbor/redeemer-tag-patch.d.ts +0 -3
- package/srv/cbor/redeemer-tag-patch.js +0 -61
- package/srv/utils/legacy-service-paths.d.ts +0 -11
- package/srv/utils/legacy-service-paths.js +0 -58
package/srv/cardano-service.js
CHANGED
|
@@ -11,6 +11,11 @@ const backend_request_handler_1 = require("./utils/backend-request-handler");
|
|
|
11
11
|
const cbor_1 = require("./cbor");
|
|
12
12
|
const paging_1 = require("./utils/paging");
|
|
13
13
|
const CardanoODataService_1 = require("#cds-models/CardanoODataService");
|
|
14
|
+
const mappers_1 = require("./utils/mappers");
|
|
15
|
+
const tx_utils_1 = require("./utils/tx-utils");
|
|
16
|
+
const result_numbers_1 = require("./utils/result-numbers");
|
|
17
|
+
/** Pause between two reads of a waiting GetLatestTransactionsByAddress call. */
|
|
18
|
+
const ADDRESS_WAIT_POLL_MS = 5000;
|
|
14
19
|
/** Newest temporal slice per key; child tables keep one row per validFrom. */
|
|
15
20
|
function latestSlices(rows, keyOf) {
|
|
16
21
|
const seen = new Map();
|
|
@@ -24,11 +29,35 @@ function latestSlices(rows, keyOf) {
|
|
|
24
29
|
}
|
|
25
30
|
const { SELECT } = cds_1.default.ql;
|
|
26
31
|
const logger = cds_1.default.log(`CardanoService`);
|
|
32
|
+
/** Pairs a provider read with the write of its result; the result type follows from the read. */
|
|
33
|
+
function indexPair(fetch, store) {
|
|
34
|
+
return { fetch, store };
|
|
35
|
+
}
|
|
36
|
+
// Fills misses without holding the request transaction while the provider answers: every missing
|
|
37
|
+
// key is read from the provider first, then all are stored. A row stored in the meantime is kept.
|
|
38
|
+
// Returns the row found or stored per key.
|
|
39
|
+
async function indexMissing(db, keys, exists, index) {
|
|
40
|
+
const rows = await (0, tx_utils_1.readOutside)(db, async (d) => {
|
|
41
|
+
const found = [];
|
|
42
|
+
for (const key of keys)
|
|
43
|
+
found.push(await exists(d, key));
|
|
44
|
+
return found;
|
|
45
|
+
});
|
|
46
|
+
const fetched = new Map();
|
|
47
|
+
for (const [i, key] of keys.entries()) {
|
|
48
|
+
if (!rows[i])
|
|
49
|
+
fetched.set(i, await index.fetch(db, key));
|
|
50
|
+
}
|
|
51
|
+
for (const [i, value] of fetched) {
|
|
52
|
+
rows[i] = (await exists(db, keys[i])) || await index.store(db, value);
|
|
53
|
+
}
|
|
54
|
+
return rows;
|
|
55
|
+
}
|
|
27
56
|
/** Upper bound of the temporal window; must outlast the slowest index-on-miss of one request. */
|
|
28
57
|
const TEMPORAL_WINDOW_SLACK_MS = 60 * 60 * 1000;
|
|
29
58
|
// CAP's temporal window is fixed at transaction start, so a slice written by index-on-miss would be
|
|
30
59
|
// invisible to the re-read. This widens the upper bound unless the client set `sap-valid-*`.
|
|
31
|
-
// Must run before the
|
|
60
|
+
// Must run before the request transaction's first statement.
|
|
32
61
|
function widenTemporalWindow(req) {
|
|
33
62
|
const q = req.http?.req?.query;
|
|
34
63
|
if (q && (q['sap-valid-at'] || q['sap-valid-from'] || q['sap-valid-to']))
|
|
@@ -46,7 +75,7 @@ function widenTemporalWindow(req) {
|
|
|
46
75
|
}
|
|
47
76
|
}
|
|
48
77
|
/** READ handler that indexes a missing key first, then runs the client's own query (keeps `$expand`, `$select`). */
|
|
49
|
-
function indexOnMissRead(entity, reqKeyField, validate,
|
|
78
|
+
function indexOnMissRead(entity, reqKeyField, validate, index, options) {
|
|
50
79
|
const dbKey = options?.entityKeyField || reqKeyField;
|
|
51
80
|
const errMsg = options?.errorMessage || `Invalid ${reqKeyField} format`;
|
|
52
81
|
return async (req) => {
|
|
@@ -56,20 +85,18 @@ function indexOnMissRead(entity, reqKeyField, validate, indexFn, options) {
|
|
|
56
85
|
(0, errors_1.rejectInvalid)(req, dbKey, errMsg, reqKeyField);
|
|
57
86
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
58
87
|
if (key !== undefined && key !== null) {
|
|
59
|
-
widenTemporalWindow(req);
|
|
88
|
+
widenTemporalWindow(req);
|
|
60
89
|
// The temporal aspect hides expired rows, so a miss here triggers a re-index.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// The client's query is the only authority on the result: never fall back to
|
|
65
|
-
// `existing`, or an excluding $filter / second key would yield a sibling row instead of 404.
|
|
90
|
+
await indexMissing(db, [key], (d, k) => d.run(SELECT.one.from(entity).where({ [dbKey]: k })), index);
|
|
91
|
+
// The client's query is the only authority on the result: never answer with the row
|
|
92
|
+
// found here, or an excluding $filter / second key would yield a sibling row instead of 404.
|
|
66
93
|
}
|
|
67
94
|
return db.run(req.query);
|
|
68
95
|
});
|
|
69
96
|
};
|
|
70
97
|
}
|
|
71
98
|
/** Factory: action handler with required-key validation and index-on-miss. */
|
|
72
|
-
function indexOnMissAction(actionName, entity, reqKeyField, validate,
|
|
99
|
+
function indexOnMissAction(actionName, entity, reqKeyField, validate, index, options) {
|
|
73
100
|
const dbKey = options?.entityKeyField || reqKeyField;
|
|
74
101
|
const errMsg = options?.errorMessage || `Invalid ${reqKeyField} format`;
|
|
75
102
|
return async (req) => {
|
|
@@ -79,11 +106,10 @@ function indexOnMissAction(actionName, entity, reqKeyField, validate, indexFn, o
|
|
|
79
106
|
if (!validate(key))
|
|
80
107
|
(0, errors_1.rejectInvalid)(req, actionName, errMsg, reqKeyField);
|
|
81
108
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
109
|
+
widenTemporalWindow(req);
|
|
82
110
|
// The temporal aspect hides expired rows, so a miss here triggers a re-index.
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
return await indexFn(db, key);
|
|
86
|
-
return existing;
|
|
111
|
+
const [row] = await indexMissing(db, [key], (d, k) => d.run(SELECT.one.from(entity).where({ [dbKey]: k })), index);
|
|
112
|
+
return row;
|
|
87
113
|
});
|
|
88
114
|
};
|
|
89
115
|
}
|
|
@@ -142,7 +168,7 @@ function addressesInReadQuery(req) {
|
|
|
142
168
|
return Array.from(found);
|
|
143
169
|
}
|
|
144
170
|
/** READ handler for a child set of Addresses: indexes the named address on a miss, then runs the query. */
|
|
145
|
-
function addressChildRead(isIndexed,
|
|
171
|
+
function addressChildRead(isIndexed, index) {
|
|
146
172
|
return async (req) => {
|
|
147
173
|
const addresses = addressesInReadQuery(req);
|
|
148
174
|
if (addresses.length > MAX_ADDRESSES_PER_READ) {
|
|
@@ -154,11 +180,8 @@ function addressChildRead(isIndexed, indexFn) {
|
|
|
154
180
|
}
|
|
155
181
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
156
182
|
if (addresses.length) {
|
|
157
|
-
widenTemporalWindow(req);
|
|
158
|
-
|
|
159
|
-
if (!(await isIndexed(db, address)))
|
|
160
|
-
await indexFn(db, address);
|
|
161
|
-
}
|
|
183
|
+
widenTemporalWindow(req);
|
|
184
|
+
await indexMissing(db, addresses, isIndexed, index);
|
|
162
185
|
}
|
|
163
186
|
return db.run(req.query);
|
|
164
187
|
});
|
|
@@ -169,6 +192,7 @@ function addressChildRead(isIndexed, indexFn) {
|
|
|
169
192
|
// ---------------------------------------------------------------------------
|
|
170
193
|
/** CardanoODataService handlers: blockchain read queries with index-on-miss. */
|
|
171
194
|
module.exports = (srv) => {
|
|
195
|
+
(0, result_numbers_1.answerNumbersAsText)(srv);
|
|
172
196
|
logger.debug('Module loaded - registering handlers');
|
|
173
197
|
// For plural-shaped names (NetworkInformation, TransactionMetadata, AssetHistory) cds-typer
|
|
174
198
|
// exports the singular class under the plain name and the entity-set class with a trailing
|
|
@@ -187,14 +211,24 @@ module.exports = (srv) => {
|
|
|
187
211
|
}
|
|
188
212
|
}
|
|
189
213
|
const indexer = () => (0, server_1.getCardanoIndexer)();
|
|
214
|
+
// The read and the store half of each index-on-miss; the indexer is resolved per request.
|
|
215
|
+
const blockIndex = indexPair((db, hash) => indexer().fetchBlock(db, hash), (db, fetched) => indexer().storeBlock(db, fetched));
|
|
216
|
+
const epochIndex = indexPair((_db, epoch) => indexer().fetchEpoch(epoch), (db, fetched) => indexer().storeEpoch(db, fetched));
|
|
217
|
+
const poolIndex = indexPair((db, poolId) => indexer().fetchPool(db, poolId), (db, fetched) => indexer().storePool(db, fetched));
|
|
218
|
+
const accountIndex = indexPair((db, stakeAddress) => indexer().fetchAccount(db, stakeAddress), (db, fetched) => indexer().storeAccount(db, fetched));
|
|
219
|
+
const drepIndex = indexPair((_db, drepId) => indexer().fetchDrep(drepId), (db, fetched) => indexer().storeDrep(db, fetched));
|
|
220
|
+
const assetIndex = indexPair((db, unit) => indexer().resolveAssetInfo(db, unit), (db, fetched) => indexer().storeAsset(db, fetched));
|
|
221
|
+
const addressIndex = indexPair((db, address) => indexer().fetchAddress(db, address), (db, fetched) => indexer().storeAddress(db, fetched));
|
|
222
|
+
const transactionIndex = indexPair((db, hash) => indexer().fetchTransaction(db, hash), (db, fetched) => indexer().storeTransaction(db, fetched));
|
|
223
|
+
const metadataIndex = indexPair((db, hash) => indexer().fetchTransactionMetadata(db, hash), (db, fetched) => indexer().storeTransactionMetadata(db, fetched));
|
|
224
|
+
const networkIndex = indexPair((db, _key) => indexer().fetchNetworkInformation(db), (db, fetched) => indexer().storeNetworkInformation(db, fetched));
|
|
225
|
+
const protocolParametersIndex = indexPair((db, _key) => indexer().fetchProtocolParameters(db), (db, fetched) => indexer().storeProtocolParameters(db, fetched));
|
|
190
226
|
// ---------------------------------------------------------------------------
|
|
191
227
|
// Network Information (singleton - no key field)
|
|
192
228
|
// ---------------------------------------------------------------------------
|
|
193
229
|
async function fetchNetworkInformation(db) {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
return await indexer().indexNetworkInformation(db);
|
|
197
|
-
return existing;
|
|
230
|
+
const [row] = await indexMissing(db, [null], (d) => d.run(SELECT.one.from(NetworkInformation)), networkIndex);
|
|
231
|
+
return row;
|
|
198
232
|
}
|
|
199
233
|
srv.on('READ', NetworkInformation, async (req) => {
|
|
200
234
|
return (0, backend_request_handler_1.handleRequest)(req, fetchNetworkInformation);
|
|
@@ -205,39 +239,39 @@ module.exports = (srv) => {
|
|
|
205
239
|
// ---------------------------------------------------------------------------
|
|
206
240
|
// Blocks
|
|
207
241
|
// ---------------------------------------------------------------------------
|
|
208
|
-
srv.on('READ', Blocks, indexOnMissRead(Blocks, 'hash', validators_1.isBlockHash,
|
|
209
|
-
srv.on('GetBlockByHash', indexOnMissAction('GetBlockByHash', Blocks, 'hash', validators_1.isBlockHash,
|
|
242
|
+
srv.on('READ', Blocks, indexOnMissRead(Blocks, 'hash', validators_1.isBlockHash, blockIndex));
|
|
243
|
+
srv.on('GetBlockByHash', indexOnMissAction('GetBlockByHash', Blocks, 'hash', validators_1.isBlockHash, blockIndex));
|
|
210
244
|
srv.on('GetLatestBlock', async (req) => {
|
|
211
245
|
return (0, backend_request_handler_1.handleRequest)(req, (db) => indexer().indexLatestBlock(db));
|
|
212
246
|
});
|
|
213
247
|
// ---------------------------------------------------------------------------
|
|
214
248
|
// Epochs
|
|
215
249
|
// ---------------------------------------------------------------------------
|
|
216
|
-
srv.on('READ', Epochs, indexOnMissRead(Epochs, 'epoch', validators_1.isEpochNumber,
|
|
217
|
-
srv.on('GetEpochByNumber', indexOnMissAction('GetEpochByNumber', Epochs, 'epochNumber', validators_1.isEpochNumber,
|
|
250
|
+
srv.on('READ', Epochs, indexOnMissRead(Epochs, 'epoch', validators_1.isEpochNumber, epochIndex, { errorMessage: 'epochNumber has invalid format' }));
|
|
251
|
+
srv.on('GetEpochByNumber', indexOnMissAction('GetEpochByNumber', Epochs, 'epochNumber', validators_1.isEpochNumber, epochIndex, { entityKeyField: 'epoch', errorMessage: 'epochNumber has invalid format' }));
|
|
218
252
|
srv.on('GetLatestEpoch', async (req) => {
|
|
219
253
|
return (0, backend_request_handler_1.handleRequest)(req, (db) => indexer().indexLatestEpoch(db));
|
|
220
254
|
});
|
|
221
255
|
// ---------------------------------------------------------------------------
|
|
222
256
|
// Pools
|
|
223
257
|
// ---------------------------------------------------------------------------
|
|
224
|
-
srv.on('READ', Pools, indexOnMissRead(Pools, 'poolId', validators_1.isValidPoolId,
|
|
225
|
-
srv.on('GetPoolById', indexOnMissAction('GetPoolById', Pools, 'poolId', validators_1.isValidPoolId,
|
|
258
|
+
srv.on('READ', Pools, indexOnMissRead(Pools, 'poolId', validators_1.isValidPoolId, poolIndex));
|
|
259
|
+
srv.on('GetPoolById', indexOnMissAction('GetPoolById', Pools, 'poolId', validators_1.isValidPoolId, poolIndex));
|
|
226
260
|
// ---------------------------------------------------------------------------
|
|
227
261
|
// Accounts
|
|
228
262
|
// ---------------------------------------------------------------------------
|
|
229
|
-
srv.on('READ', Accounts, indexOnMissRead(Accounts, 'stakeAddress', validators_1.isValidBech32StakeAddress,
|
|
230
|
-
srv.on('GetAccountByStakeAddress', indexOnMissAction('GetAccountByStakeAddress', Accounts, 'stakeAddress', validators_1.isValidBech32StakeAddress,
|
|
263
|
+
srv.on('READ', Accounts, indexOnMissRead(Accounts, 'stakeAddress', validators_1.isValidBech32StakeAddress, accountIndex));
|
|
264
|
+
srv.on('GetAccountByStakeAddress', indexOnMissAction('GetAccountByStakeAddress', Accounts, 'stakeAddress', validators_1.isValidBech32StakeAddress, accountIndex));
|
|
231
265
|
// ---------------------------------------------------------------------------
|
|
232
266
|
// Dreps
|
|
233
267
|
// ---------------------------------------------------------------------------
|
|
234
|
-
srv.on('READ', Dreps, indexOnMissRead(Dreps, 'drepId', validators_1.isValidDrepId,
|
|
235
|
-
srv.on('GetDrepById', indexOnMissAction('GetDrepById', Dreps, 'drepId', validators_1.isValidDrepId,
|
|
268
|
+
srv.on('READ', Dreps, indexOnMissRead(Dreps, 'drepId', validators_1.isValidDrepId, drepIndex));
|
|
269
|
+
srv.on('GetDrepById', indexOnMissAction('GetDrepById', Dreps, 'drepId', validators_1.isValidDrepId, drepIndex));
|
|
236
270
|
// ---------------------------------------------------------------------------
|
|
237
271
|
// Assets
|
|
238
272
|
// ---------------------------------------------------------------------------
|
|
239
|
-
srv.on('READ', Assets, indexOnMissRead(Assets, 'unit', validators_1.isAssetUnit,
|
|
240
|
-
srv.on('GetAssetInfo', indexOnMissAction('GetAssetInfo', Assets, 'unit', validators_1.isAssetUnit,
|
|
273
|
+
srv.on('READ', Assets, indexOnMissRead(Assets, 'unit', validators_1.isAssetUnit, assetIndex, { errorMessage: 'Invalid asset unit format' }));
|
|
274
|
+
srv.on('GetAssetInfo', indexOnMissAction('GetAssetInfo', Assets, 'unit', validators_1.isAssetUnit, assetIndex, { errorMessage: 'Invalid asset unit format' }));
|
|
241
275
|
// Asset history: READ serves stored rows only; GetAssetHistory fetches and stores them.
|
|
242
276
|
srv.on('READ', AssetHistory, async (req) => {
|
|
243
277
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => db.run(req.query));
|
|
@@ -259,8 +293,8 @@ module.exports = (srv) => {
|
|
|
259
293
|
// ---------------------------------------------------------------------------
|
|
260
294
|
// Addresses
|
|
261
295
|
// ---------------------------------------------------------------------------
|
|
262
|
-
srv.on('READ', Addresses, indexOnMissRead(Addresses, 'address', validators_1.isValidBech32Address,
|
|
263
|
-
srv.on('GetAddressByBech32', indexOnMissAction('GetAddressByBech32', Addresses, 'address', validators_1.isValidBech32Address,
|
|
296
|
+
srv.on('READ', Addresses, indexOnMissRead(Addresses, 'address', validators_1.isValidBech32Address, addressIndex, { errorMessage: 'Invalid bech32 address format' }));
|
|
297
|
+
srv.on('GetAddressByBech32', indexOnMissAction('GetAddressByBech32', Addresses, 'address', validators_1.isValidBech32Address, addressIndex, { errorMessage: 'Invalid bech32 address format' }));
|
|
264
298
|
// GetAssetsByAddress: indexes the parent address if needed, then queries child assets.
|
|
265
299
|
srv.on(CardanoODataService_1.GetAssetsByAddress, async (req) => {
|
|
266
300
|
const { address } = req.data;
|
|
@@ -270,29 +304,30 @@ module.exports = (srv) => {
|
|
|
270
304
|
(0, errors_1.rejectInvalid)(req, 'GetAssetsByAddress', 'Invalid bech32 address format', 'address');
|
|
271
305
|
const page = (0, paging_1.pageOf)(req.data, 1000);
|
|
272
306
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
273
|
-
widenTemporalWindow(req);
|
|
274
|
-
|
|
275
|
-
if (!existing)
|
|
276
|
-
await indexer().indexAddress(db, address);
|
|
307
|
+
widenTemporalWindow(req);
|
|
308
|
+
await indexMissing(db, [address], addressIndexed, addressIndex);
|
|
277
309
|
const assets = await db.run(SELECT.from(AddressAssets).where({ address_address: address }));
|
|
278
310
|
return (0, paging_1.pageRows)((0, paging_1.byKey)(latestSlices(assets, (asset) => asset.unit ?? ''), (a) => a.unit ?? ''), page);
|
|
279
311
|
});
|
|
280
312
|
});
|
|
281
313
|
// Prefer the full address index; when no configured backend supports getAddress
|
|
282
314
|
// (AllBackendsFailedError with zero collected errors, e.g. Ogmios only), fall back to a
|
|
283
|
-
// UTxO-only index.
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
catch (err) {
|
|
289
|
-
if (err instanceof errors_1.AllBackendsFailedError && err.errors.length === 0) {
|
|
290
|
-
await indexer().indexAddressUtxos(db, address);
|
|
315
|
+
// UTxO-only index.
|
|
316
|
+
const addressOrUtxosIndex = {
|
|
317
|
+
fetch: async (db, address) => {
|
|
318
|
+
try {
|
|
319
|
+
return await indexer().fetchAddress(db, address);
|
|
291
320
|
}
|
|
292
|
-
|
|
321
|
+
catch (err) {
|
|
322
|
+
if (err instanceof errors_1.AllBackendsFailedError && err.errors.length === 0) {
|
|
323
|
+
return { address, utxos: await indexer().fetchAddressUtxos(address) };
|
|
324
|
+
}
|
|
293
325
|
throw err;
|
|
294
326
|
}
|
|
295
|
-
}
|
|
327
|
+
},
|
|
328
|
+
store: (db, fetched) => 'utxos' in fetched
|
|
329
|
+
? indexer().storeAddressUtxos(db, fetched.address, fetched.utxos)
|
|
330
|
+
: indexer().storeAddress(db, fetched),
|
|
296
331
|
};
|
|
297
332
|
// An address is indexed when its Addresses row is valid. The UTxO-only fallback writes no
|
|
298
333
|
// Addresses row, so for UTxOs a valid AddressUTxOs row counts as well.
|
|
@@ -308,17 +343,16 @@ module.exports = (srv) => {
|
|
|
308
343
|
(0, errors_1.rejectInvalid)(req, 'GetUTxOsByAddress', 'Invalid bech32 address format', 'address');
|
|
309
344
|
const page = (0, paging_1.pageOf)(req.data, 1000);
|
|
310
345
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
311
|
-
widenTemporalWindow(req);
|
|
312
|
-
|
|
313
|
-
await indexAddressOrUtxos(db, address);
|
|
346
|
+
widenTemporalWindow(req);
|
|
347
|
+
await indexMissing(db, [address], addressUtxosIndexed, addressOrUtxosIndex);
|
|
314
348
|
const utxos = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
|
|
315
349
|
return (0, paging_1.pageRows)((0, paging_1.byOutRef)(latestSlices(utxos, (utxo) => `${utxo.hash}#${utxo.index}`)), page);
|
|
316
350
|
});
|
|
317
351
|
});
|
|
318
352
|
// Collection reads of the address child sets fill like the parent: an address named in the
|
|
319
353
|
// navigation or the $filter is indexed on a miss, then the client's own query runs.
|
|
320
|
-
srv.on('READ', AddressUTxOs, addressChildRead(addressUtxosIndexed,
|
|
321
|
-
srv.on('READ', AddressAssets, addressChildRead(addressIndexed,
|
|
354
|
+
srv.on('READ', AddressUTxOs, addressChildRead(addressUtxosIndexed, addressOrUtxosIndex));
|
|
355
|
+
srv.on('READ', AddressAssets, addressChildRead(addressIndexed, addressIndex));
|
|
322
356
|
// GetUTxOsByCredential: always-fresh credential-keyed UTxO query (dApp state reads need current
|
|
323
357
|
// data). Crawled UTxO set + node first, else Koios; ProviderUnavailableError without either.
|
|
324
358
|
srv.on(CardanoODataService_1.GetUTxOsByCredential, async (req) => {
|
|
@@ -334,8 +368,8 @@ module.exports = (srv) => {
|
|
|
334
368
|
// ---------------------------------------------------------------------------
|
|
335
369
|
// Transactions
|
|
336
370
|
// ---------------------------------------------------------------------------
|
|
337
|
-
srv.on('READ', Transactions, indexOnMissRead(Transactions, 'hash', validators_1.isTxHash,
|
|
338
|
-
srv.on('GetTransactionByHash', indexOnMissAction('GetTransactionByHash', Transactions, 'hash', validators_1.isTxHash,
|
|
371
|
+
srv.on('READ', Transactions, indexOnMissRead(Transactions, 'hash', validators_1.isTxHash, transactionIndex, { errorMessage: 'Invalid transaction hash format' }));
|
|
372
|
+
srv.on('GetTransactionByHash', indexOnMissAction('GetTransactionByHash', Transactions, 'hash', validators_1.isTxHash, transactionIndex, { errorMessage: 'Invalid transaction hash format' }));
|
|
339
373
|
srv.on(CardanoODataService_1.GetTransactionConfirmations, async (req) => {
|
|
340
374
|
const { txHash } = req.data;
|
|
341
375
|
if (!txHash)
|
|
@@ -347,7 +381,7 @@ module.exports = (srv) => {
|
|
|
347
381
|
// ---------------------------------------------------------------------------
|
|
348
382
|
// Transaction Metadata
|
|
349
383
|
// ---------------------------------------------------------------------------
|
|
350
|
-
srv.on('READ', TransactionMetadata, indexOnMissRead(TransactionMetadata, 'tx_hash', validators_1.isTxHash,
|
|
384
|
+
srv.on('READ', TransactionMetadata, indexOnMissRead(TransactionMetadata, 'tx_hash', validators_1.isTxHash, metadataIndex, { errorMessage: 'Invalid transaction hash format' }));
|
|
351
385
|
// GetMetadataByTxHash: returns all metadata rows of a transaction.
|
|
352
386
|
srv.on(CardanoODataService_1.GetMetadataByTxHash, async (req) => {
|
|
353
387
|
const { txHash } = req.data;
|
|
@@ -357,20 +391,32 @@ module.exports = (srv) => {
|
|
|
357
391
|
(0, errors_1.rejectInvalid)(req, 'GetMetadataByTxHash', 'Invalid transaction hash format', 'txHash');
|
|
358
392
|
const page = (0, paging_1.pageOf)(req.data, 1000);
|
|
359
393
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
360
|
-
const
|
|
361
|
-
|
|
394
|
+
const stored = async (d, hash) => {
|
|
395
|
+
const existing = await d.run(SELECT.from(TransactionMetadata).where({ tx_hash: hash }));
|
|
396
|
+
return existing?.length ? existing : null;
|
|
397
|
+
};
|
|
398
|
+
const [rows] = await indexMissing(db, [txHash], stored, metadataIndex);
|
|
362
399
|
return (0, paging_1.pageRows)((0, paging_1.byKey)(rows, (m) => String(m.label ?? '').padStart(20, '0')), page);
|
|
363
400
|
});
|
|
364
401
|
});
|
|
402
|
+
// GetMetadataByLabel: stored metadata of one label along the chain. Reads the database only.
|
|
403
|
+
srv.on(CardanoODataService_1.GetMetadataByLabel, async (req) => {
|
|
404
|
+
const { label, fromSlot } = req.data;
|
|
405
|
+
if (label == null || String(label).trim() === '')
|
|
406
|
+
(0, errors_1.rejectMissing)(req, 'GetMetadataByLabel', 'label');
|
|
407
|
+
const id = (0, mappers_1.metadataIdFor)(String(label).trim());
|
|
408
|
+
if (id === null)
|
|
409
|
+
(0, errors_1.rejectInvalid)(req, 'GetMetadataByLabel', 'label must be an unsigned 64-bit integer', 'label');
|
|
410
|
+
const { limit, skip } = (0, paging_1.pageOf)(req.data, 100);
|
|
411
|
+
return (0, backend_request_handler_1.handleRequest)(req, (db) => db.run(SELECT.from(TransactionMetadata).where({ id, txSeq: { '>=': (0, mappers_1.txSeqOf)(Number(fromSlot ?? 0), 0) } }).orderBy('txSeq').limit(limit, skip)));
|
|
412
|
+
});
|
|
365
413
|
// ---------------------------------------------------------------------------
|
|
366
414
|
// Protocol Parameters (singleton)
|
|
367
415
|
// ---------------------------------------------------------------------------
|
|
368
416
|
srv.on('READ', LedgerProtocolParameters, async (req) => {
|
|
369
417
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
return indexer().indexProtocolParameters(db);
|
|
373
|
-
return existing;
|
|
418
|
+
const [row] = await indexMissing(db, [null], (d) => d.run(SELECT.one.from(LedgerProtocolParameters)), protocolParametersIndex);
|
|
419
|
+
return row;
|
|
374
420
|
});
|
|
375
421
|
});
|
|
376
422
|
srv.on('GetLedgerProtocolParameters', async (req) => {
|
|
@@ -400,15 +446,34 @@ module.exports = (srv) => {
|
|
|
400
446
|
// ---------------------------------------------------------------------------
|
|
401
447
|
// Address Transactions
|
|
402
448
|
// ---------------------------------------------------------------------------
|
|
449
|
+
// GetLatestTransactionsByAddress: the newest transactions of an address. With sinceTime only
|
|
450
|
+
// newer ones; with waitMs the call re-reads until one appears or the time is up.
|
|
403
451
|
srv.on(CardanoODataService_1.GetLatestTransactionsByAddress, async (req) => {
|
|
404
|
-
const { address } = req.data;
|
|
452
|
+
const { address, sinceTime, waitMs } = req.data;
|
|
405
453
|
if (!address)
|
|
406
454
|
(0, errors_1.rejectMissing)(req, 'GetLatestTransactionsByAddress', 'address');
|
|
407
455
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
408
456
|
(0, errors_1.rejectInvalid)(req, 'GetLatestTransactionsByAddress', 'Invalid bech32 address format', 'address');
|
|
457
|
+
if (waitMs && sinceTime == null)
|
|
458
|
+
(0, errors_1.rejectInvalid)(req, 'GetLatestTransactionsByAddress', 'waitMs needs sinceTime', 'waitMs');
|
|
409
459
|
const page = (0, paging_1.latestWindowPage)(req, 'GetLatestTransactionsByAddress', 10);
|
|
460
|
+
const window = page.skip + page.limit;
|
|
461
|
+
const since = sinceTime == null ? null : Number(sinceTime);
|
|
462
|
+
const newer = (rows) => since == null ? rows : rows.filter((r) => Number(r.blockTime ?? 0) > since);
|
|
463
|
+
const deadline = Date.now() + Number(waitMs ?? 0);
|
|
410
464
|
// Every call lists the newest hashes; stored rows are reused, only new ones are fetched.
|
|
411
|
-
return (0, backend_request_handler_1.handleRequest)(req, async (db) =>
|
|
465
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
466
|
+
if (!waitMs)
|
|
467
|
+
return (0, paging_1.pageRows)(newer(await indexer().indexAddressTransactions(db, address, window)), page);
|
|
468
|
+
// each read in its own transaction: a waiting request holds no database connection
|
|
469
|
+
for (;;) {
|
|
470
|
+
const rows = newer(await (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx((tx) => indexer().indexAddressTransactions(tx, address, window))));
|
|
471
|
+
const timeUp = Date.now() + ADDRESS_WAIT_POLL_MS > deadline || req.http?.res.destroyed === true;
|
|
472
|
+
if (rows.length || timeUp)
|
|
473
|
+
return (0, paging_1.pageRows)(rows, page);
|
|
474
|
+
await new Promise((resolve) => setTimeout(resolve, ADDRESS_WAIT_POLL_MS));
|
|
475
|
+
}
|
|
476
|
+
});
|
|
412
477
|
});
|
|
413
478
|
logger.debug('All handlers registered');
|
|
414
479
|
};
|
|
@@ -13,37 +13,38 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
13
13
|
@readonly
|
|
14
14
|
@title : 'Signature Verifications'
|
|
15
15
|
@description: 'Projection for Signature Verifications - stores verification results'
|
|
16
|
-
@requires : '
|
|
16
|
+
@requires : 'Sign'
|
|
17
17
|
entity SignatureVerifications as projection on db.SignatureVerifications;
|
|
18
18
|
|
|
19
19
|
@readonly
|
|
20
20
|
@title : 'Address Signing Requests'
|
|
21
21
|
@description: 'Signing requests of an address, ordered by request id'
|
|
22
|
-
@requires : '
|
|
22
|
+
@requires : 'Sign'
|
|
23
23
|
entity AddressSigningRequests as projection on db.AddressSigningRequests;
|
|
24
24
|
|
|
25
25
|
@readonly
|
|
26
26
|
@title : 'Transaction Builds'
|
|
27
27
|
@description: 'Projection for Transaction Builds - needed by CreateSigningRequest to look up build details'
|
|
28
|
-
@requires : '
|
|
28
|
+
@requires : 'Sign'
|
|
29
29
|
entity TransactionBuilds as projection on db.TransactionBuilds;
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
@readonly
|
|
33
33
|
@title : 'Transaction Submissions'
|
|
34
34
|
@description: 'Projection for Transaction Submissions - stores submission results'
|
|
35
|
-
@requires : '
|
|
35
|
+
@requires : 'Sign'
|
|
36
36
|
entity TransactionSubmissions as projection on db.TransactionSubmissions;
|
|
37
37
|
|
|
38
38
|
@readonly
|
|
39
39
|
@title : 'Signing Requests'
|
|
40
40
|
@description: 'Projection for Signing Requests - tracks signing workflow'
|
|
41
|
-
@requires : '
|
|
41
|
+
@requires : 'Sign'
|
|
42
42
|
entity SigningRequests as projection on db.SigningRequests;
|
|
43
43
|
|
|
44
44
|
@title : 'Verify Signature'
|
|
45
45
|
@description: 'Verify the signature of a signed transaction. Stores the verification result for audit trail.'
|
|
46
|
-
@requires : '
|
|
46
|
+
@requires : 'Sign'
|
|
47
|
+
@odatano.agent: 'grant'
|
|
47
48
|
action VerifySignature(
|
|
48
49
|
@title: 'Signing Request ID'
|
|
49
50
|
@description: 'The unique identifier of the signing request'
|
|
@@ -63,7 +64,8 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
63
64
|
|
|
64
65
|
@title : 'Submit Verified Transaction'
|
|
65
66
|
@description: 'Verify and submit a signed transaction in one step. Updates the signing request status and creates submission record.'
|
|
66
|
-
@requires : '
|
|
67
|
+
@requires : 'Sign'
|
|
68
|
+
@odatano.agent: 'grant'
|
|
67
69
|
action SubmitVerifiedTransaction(
|
|
68
70
|
@title: 'Signing Request ID'
|
|
69
71
|
@description: 'The unique identifier of the signing request'
|
|
@@ -93,19 +95,21 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
93
95
|
// so the caller is not yet authenticated. It writes nothing and touches no key, so it leaks nothing.
|
|
94
96
|
@requires : 'any'
|
|
95
97
|
@title : 'Verify Data Signature (CIP-30 signData)'
|
|
96
|
-
@description: 'Verify a COSE_Sign1 message signature against a bech32 address. Confirms
|
|
98
|
+
@description: 'Verify a COSE_Sign1 message signature against a bech32 address. Confirms EdDSA over an Ed25519 key, that the signed header names the given address, that the signer key hashes to its credential (payment credential, or stake credential of a reward address), the Ed25519 signature, and (optionally) that the signed payload matches an expected value.'
|
|
99
|
+
@odatano.agent: 'read'
|
|
97
100
|
action VerifyDataSignature(
|
|
98
|
-
@description: 'Bech32 address the wallet
|
|
101
|
+
@description: 'Bech32 payment or reward address the wallet signed with'
|
|
99
102
|
address : Bech32,
|
|
100
103
|
@description: 'Hex-encoded COSE_Sign1 CBOR (the `signature` field from CIP-30 signData)'
|
|
101
|
-
coseSignature : String,
|
|
104
|
+
coseSignature : String(65536),
|
|
102
105
|
@description: 'Hex-encoded COSE_Key CBOR (the `key` field from CIP-30 signData)'
|
|
103
|
-
coseKey : String,
|
|
104
|
-
@description: 'Optional expected UTF-8 payload; when set, the signed payload must equal it (anti-replay). When omitted, the decoded payload is returned for the caller to check.'
|
|
105
|
-
expectedPayload: String)
|
|
106
|
+
coseKey : String(512),
|
|
107
|
+
@description: 'Optional expected UTF-8 payload; when set, the signed payload must equal it byte for byte (anti-replay). Required when the wallet signed the hash of the message. When omitted, the decoded payload is returned for the caller to check.'
|
|
108
|
+
expectedPayload: String(16384)) returns {
|
|
106
109
|
@description: 'Whether the signature is valid and all checks passed' valid : Boolean;
|
|
107
110
|
@description: 'Failure detail when not valid' reason : String;
|
|
108
|
-
@description: '
|
|
111
|
+
@description: 'The signed message as text; empty when the payload is not UTF-8' signedPayload : String;
|
|
112
|
+
@description: 'The payload bytes as signed, hex; the blake2b-224 of the message when the wallet hashed it' signedPayloadHex : String;
|
|
109
113
|
@description: 'Hex blake2b-224 of the signer public key' signerVkh : String;
|
|
110
114
|
};
|
|
111
115
|
|
|
@@ -115,7 +119,8 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
115
119
|
|
|
116
120
|
@title : 'Create Signing Request'
|
|
117
121
|
@description: 'Create a signing request for external signing. Returns transaction details, signing instructions, and CLI commands. The request is persisted for audit trail.'
|
|
118
|
-
@requires : '
|
|
122
|
+
@requires : 'Sign'
|
|
123
|
+
@odatano.agent: 'grant'
|
|
119
124
|
action CreateSigningRequest(
|
|
120
125
|
@title: 'Build ID'
|
|
121
126
|
@description: 'The unique identifier of the transaction build'
|
|
@@ -126,7 +131,8 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
126
131
|
|
|
127
132
|
@title : 'Get Signing Request'
|
|
128
133
|
@description: 'Retrieve an existing signing request by ID'
|
|
129
|
-
@requires : '
|
|
134
|
+
@requires : 'Sign'
|
|
135
|
+
@odatano.agent: 'read'
|
|
130
136
|
action GetSigningRequest(
|
|
131
137
|
@title: 'Signing Request ID'
|
|
132
138
|
@description: 'The unique identifier of the signing request'
|
|
@@ -134,7 +140,8 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
134
140
|
|
|
135
141
|
@title : 'Address Signing Requests'
|
|
136
142
|
@description: 'Projection for retrieving signing requests by address'
|
|
137
|
-
@requires : '
|
|
143
|
+
@requires : 'Sign'
|
|
144
|
+
@odatano.agent: 'read'
|
|
138
145
|
action GetSigningRequestsByAddress(
|
|
139
146
|
@title: 'Bech32 Address'
|
|
140
147
|
@description: 'The Bech32 encoded address to retrieve signing requests for'
|
|
@@ -154,7 +161,8 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
154
161
|
|
|
155
162
|
@title : 'Sign with HSM'
|
|
156
163
|
@description: 'Sign a transaction using the configured Hardware Security Module. Creates a signing request, signs with the HSM, and verifies the signature. Returns the signing request with status verified.'
|
|
157
|
-
@requires : '
|
|
164
|
+
@requires : 'Sign'
|
|
165
|
+
@odatano.agent: 'operator'
|
|
158
166
|
action SignWithHsm(
|
|
159
167
|
@title: 'Build ID'
|
|
160
168
|
@description: 'The unique identifier of the transaction build to sign'
|
|
@@ -165,7 +173,8 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
165
173
|
|
|
166
174
|
@title : 'Sign and Submit with HSM'
|
|
167
175
|
@description: 'Sign a transaction using the HSM and submit it to the blockchain in one atomic operation. Returns the transaction submission details.'
|
|
168
|
-
@requires : '
|
|
176
|
+
@requires : 'Sign'
|
|
177
|
+
@odatano.agent: 'operator'
|
|
169
178
|
action SignAndSubmitWithHsm(
|
|
170
179
|
@title: 'Build ID'
|
|
171
180
|
@description: 'The unique identifier of the transaction build to sign and submit'
|
|
@@ -179,7 +188,8 @@ service CardanoSignService @(impl: './cardano-sign-service') {
|
|
|
179
188
|
|
|
180
189
|
@title : 'Get HSM Status'
|
|
181
190
|
@description: 'Check the current status of the HSM connection and key availability.'
|
|
182
|
-
@requires : '
|
|
191
|
+
@requires : 'Sign'
|
|
192
|
+
@odatano.agent: 'read'
|
|
183
193
|
action GetHsmStatus() returns {
|
|
184
194
|
@title: 'Connected' @description: 'Whether the HSM session is active' connected : Boolean;
|
|
185
195
|
@title: 'Key ID' @description: 'The PKCS#11 key identifier in use' keyId : String;
|
|
@@ -16,6 +16,7 @@ const cose_verifier_1 = require("./blockchain/signing/cose-verifier");
|
|
|
16
16
|
const signing_helper_1 = require("./utils/signing-helper");
|
|
17
17
|
const tx_utils_1 = require("./utils/tx-utils");
|
|
18
18
|
const paging_1 = require("./utils/paging");
|
|
19
|
+
const result_numbers_1 = require("./utils/result-numbers");
|
|
19
20
|
const submission_finalizer_1 = require("./blockchain/signing/submission-finalizer");
|
|
20
21
|
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
21
22
|
const logger = cds_1.default.log('CardanoSignService');
|
|
@@ -75,6 +76,7 @@ function enforceHsmRole(req, actionName) {
|
|
|
75
76
|
}
|
|
76
77
|
/** CardanoSignService handlers: external and HSM signing, verification, submission. */
|
|
77
78
|
module.exports = (srv) => {
|
|
79
|
+
(0, result_numbers_1.answerNumbersAsText)(srv);
|
|
78
80
|
logger.info('Module loaded - registering handlers');
|
|
79
81
|
const { SigningRequests, AddressSigningRequests, TransactionBuilds, } = require('#cds-models/CardanoSignService');
|
|
80
82
|
// before-READ: bulk-expire pending requests past their TTL, at most once per minute.
|
|
@@ -221,13 +223,10 @@ module.exports = (srv) => {
|
|
|
221
223
|
// Throws on failure; bound to the keys that must witness this tx.
|
|
222
224
|
const requiredSigners = await resolveRequiredSigners(db, signingRequest, TransactionBuilds);
|
|
223
225
|
const verificationResult = (0, external_signer_1.getExternalSignerModule)().verifyOrThrow(fullSignedTxCbor, signingRequest.txBodyHash, { requiredSigners });
|
|
224
|
-
// Atomic claim.
|
|
225
|
-
// interrupted submission can be
|
|
226
|
+
// Atomic claim. The signed CBOR, the signer and the claim time go with it, so an
|
|
227
|
+
// interrupted or unresolved submission can be resolved later.
|
|
226
228
|
const claimed = await db.run(UPDATE.entity(SigningRequests)
|
|
227
|
-
.set({
|
|
228
|
-
status: 'submitting',
|
|
229
|
-
...(deferSubmit ? { signedTxCbor: fullSignedTxCbor, signerType, signerInfo } : {}),
|
|
230
|
-
})
|
|
229
|
+
.set({ status: 'submitting', signedTxCbor: fullSignedTxCbor, signerType, signerInfo, signedAt: now })
|
|
231
230
|
.where({
|
|
232
231
|
id: signingRequestId,
|
|
233
232
|
status: { in: ['pending', 'verified'] },
|
|
@@ -280,8 +279,9 @@ module.exports = (srv) => {
|
|
|
280
279
|
const { address, coseSignature, coseKey, expectedPayload } = req.data;
|
|
281
280
|
if (!address)
|
|
282
281
|
(0, errors_1.rejectMissing)(req, 'VerifyDataSignature', 'address');
|
|
283
|
-
if (!(0, validators_1.isValidBech32Address)(address))
|
|
282
|
+
if (!(0, validators_1.isValidBech32Address)(address) && !(0, validators_1.isValidBech32StakeAddress)(address)) {
|
|
284
283
|
(0, errors_1.rejectInvalid)(req, 'VerifyDataSignature', 'Invalid bech32 address format', 'address');
|
|
284
|
+
}
|
|
285
285
|
if (!coseSignature)
|
|
286
286
|
(0, errors_1.rejectMissing)(req, 'VerifyDataSignature', 'coseSignature');
|
|
287
287
|
if (!coseKey)
|
|
@@ -395,12 +395,15 @@ module.exports = (srv) => {
|
|
|
395
395
|
logger.error({ signingRequestId: signingRequestRecord.id, hsmKey: hsmKeyIdentifier }, 'HSM signature verification failed, aborting submission');
|
|
396
396
|
(0, errors_1.rejectInvalid)(req, 'SignAndSubmitWithHsm', 'HSM signature verification failed', 'signedTxCbor');
|
|
397
397
|
}
|
|
398
|
-
// Claim as 'submitting'
|
|
399
|
-
//
|
|
398
|
+
// Claim as 'submitting' with the signed CBOR, the signer and the claim time, so an
|
|
399
|
+
// interrupted or unresolved submission can be resolved later.
|
|
400
400
|
await db.run(UPDATE.entity(SigningRequests).set({
|
|
401
401
|
status: 'submitting',
|
|
402
402
|
hsmKeyId: hsmKeyIdentifier,
|
|
403
|
-
|
|
403
|
+
signedTxCbor,
|
|
404
|
+
signerType: 'hsm',
|
|
405
|
+
signerInfo: `HSM key: ${hsmKeyIdentifier}`,
|
|
406
|
+
signedAt: new Date().toISOString(),
|
|
404
407
|
}).where({ id: signingRequestRecord.id }));
|
|
405
408
|
return { signingRequestId: signingRequestRecord.id, signedTxCbor, txHash: build.txBodyHash, verificationResult, hsmKeyIdentifier };
|
|
406
409
|
};
|