@odatano/core 2.0.0-rc.5 → 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 +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +347 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +496 -11
- package/@cds-models/CardanoIndexerService/index.js +64 -0
- package/@cds-models/CardanoODataService/index.d.ts +414 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +32 -19
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +58 -44
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +7 -22
- package/@cds-models/index.d.ts +101 -1
- package/@cds-models/index.js +16 -1
- package/@cds-models/odatano/cardano/index.d.ts +437 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +207 -167
- package/db/schema.cds +2402 -1705
- package/db/types.cds +446 -295
- package/package.json +41 -16
- package/scripts/migrate-schema.mjs +334 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -135
- package/srv/blockchain/backends/blockfrost-backend.js +66 -172
- package/srv/blockchain/backends/cardano-backend.d.ts +94 -186
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +103 -168
- package/srv/blockchain/backends/koios-backend.js +428 -360
- package/srv/blockchain/backends/odatano-backend.d.ts +54 -0
- package/srv/blockchain/backends/odatano-backend.js +169 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +123 -190
- package/srv/blockchain/backends/ogmios-backend.js +637 -315
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +61 -241
- package/srv/blockchain/cardano-client.js +253 -293
- package/srv/blockchain/cardano-indexer.d.ts +282 -281
- package/srv/blockchain/cardano-indexer.js +1551 -484
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +153 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +43 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +153 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/certificate-backfill.js +162 -0
- package/srv/blockchain/crawler/crawler.d.ts +104 -81
- package/srv/blockchain/crawler/crawler.js +532 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +28 -0
- package/srv/blockchain/crawler/credential-backfill.js +124 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- 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/sync-state.d.ts +27 -47
- package/srv/blockchain/crawler/sync-state.js +113 -63
- package/srv/blockchain/crawler/transaction-backfill.d.ts +44 -0
- package/srv/blockchain/crawler/transaction-backfill.js +278 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +419 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +17 -126
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +70 -83
- package/srv/blockchain/signing/submission-finalizer.d.ts +23 -45
- package/srv/blockchain/signing/submission-finalizer.js +219 -86
- package/srv/blockchain/stored-chain.d.ts +20 -0
- package/srv/blockchain/stored-chain.js +237 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +652 -416
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +5 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +5 -20
- package/srv/blockchain/wallet-worker/build-request.js +47 -30
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -46
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +25 -45
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/job-store.d.ts +30 -148
- package/srv/blockchain/wallet-worker/job-store.js +101 -201
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +8 -80
- package/srv/blockchain/wallet-worker/wallet-worker.js +107 -155
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +4 -9
- package/srv/cardano-backend-service.cds +78 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +242 -0
- package/srv/cardano-indexer-service.cds +387 -73
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +532 -16
- package/srv/cardano-service.cds +424 -269
- package/srv/cardano-service.js +289 -201
- package/srv/cardano-sign-service.cds +201 -180
- package/srv/cardano-sign-service.js +71 -201
- package/srv/cardano-tx-service.cds +451 -370
- package/srv/cardano-tx-service.js +271 -289
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +118 -125
- package/srv/cardano-worker-service.js +52 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +113 -0
- package/srv/config.js +409 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +84 -404
- 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 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -236
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +18 -182
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +3 -10
- package/srv/utils/collections.js +3 -10
- package/srv/utils/const.d.ts +23 -74
- package/srv/utils/const.js +32 -79
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +6 -21
- package/srv/utils/db-indexes.d.ts +27 -0
- package/srv/utils/db-indexes.js +120 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +38 -0
- package/srv/utils/error-codes.d.ts +22 -75
- package/srv/utils/error-codes.js +23 -72
- package/srv/utils/errors.d.ts +46 -187
- package/srv/utils/errors.js +114 -230
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +102 -223
- package/srv/utils/mappers.js +387 -316
- package/srv/utils/network-context.js +2 -13
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +10 -105
- package/srv/utils/tx-build-helper.js +81 -144
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +261 -191
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +50 -149
|
@@ -1,21 +1,7 @@
|
|
|
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
|
-
*/
|
|
1
|
+
/** Concurrent requests for the same key share one backend call and its result. */
|
|
8
2
|
export declare class RequestCoalescer<T> {
|
|
9
3
|
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
|
-
*/
|
|
4
|
+
/** Returns the in-flight promise for this key, or starts the fetcher. */
|
|
19
5
|
get(key: string, fetcher: () => Promise<T>): Promise<T>;
|
|
20
6
|
/** Number of currently in-flight requests */
|
|
21
7
|
get size(): number;
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RequestCoalescer = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* RequestCoalescer — Deduplicates concurrent requests for the same resource key.
|
|
6
|
-
*
|
|
7
|
-
* When multiple callers request the same key simultaneously (e.g., same txHash
|
|
8
|
-
* during parallel address indexing), only one backend call is made. All callers
|
|
9
|
-
* receive the same Promise/result.
|
|
10
|
-
*/
|
|
4
|
+
/** Concurrent requests for the same key share one backend call and its result. */
|
|
11
5
|
class RequestCoalescer {
|
|
12
6
|
pending = new Map();
|
|
13
|
-
/**
|
|
14
|
-
* Get a value by key, deduplicating concurrent requests.
|
|
15
|
-
* If a request for this key is already in-flight, returns the existing Promise.
|
|
16
|
-
* Otherwise, calls the fetcher and caches the Promise until it resolves.
|
|
17
|
-
*
|
|
18
|
-
* @param key Unique identifier (e.g., txHash, bech32 address)
|
|
19
|
-
* @param fetcher Function that performs the actual fetch
|
|
20
|
-
* @returns The fetched value
|
|
21
|
-
*/
|
|
7
|
+
/** Returns the in-flight promise for this key, or starts the fetcher. */
|
|
22
8
|
async get(key, fetcher) {
|
|
23
9
|
const existing = this.pending.get(key);
|
|
24
10
|
if (existing)
|
|
@@ -1,8 +1,3 @@
|
|
|
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
1
|
export interface CoseVerifyInput {
|
|
7
2
|
address: string;
|
|
8
3
|
coseSignature: string;
|
|
@@ -14,21 +9,12 @@ export interface CoseVerifyResult {
|
|
|
14
9
|
valid: boolean;
|
|
15
10
|
/** failure detail when !valid; empty string when valid */
|
|
16
11
|
reason: string;
|
|
17
|
-
/**
|
|
12
|
+
/** The signed message as text. Empty when the payload is not UTF-8, or hashed and not matched. */
|
|
18
13
|
signedPayload: string;
|
|
14
|
+
/** hex; the payload bytes as signed (the blake2b-224 of the message when the wallet hashed it) */
|
|
15
|
+
signedPayloadHex: string;
|
|
19
16
|
/** hex blake2b-224 of the signer public key (empty until the key is parsed) */
|
|
20
17
|
signerVkh: string;
|
|
21
18
|
}
|
|
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
19
|
export declare function verifyDataSignature(input: CoseVerifyInput): CoseVerifyResult;
|
|
34
20
|
//# sourceMappingURL=cose-verifier.d.ts.map
|
|
@@ -8,24 +8,45 @@ const cds_1 = __importDefault(require("@sap/cds"));
|
|
|
8
8
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
9
9
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
10
10
|
const crypto_1 = require("@harmoniclabs/crypto");
|
|
11
|
-
const
|
|
11
|
+
const bech32_1 = require("bech32");
|
|
12
|
+
const node_util_1 = require("node:util");
|
|
13
|
+
const const_1 = require("../../utils/const");
|
|
12
14
|
const logger = cds_1.default.log('CoseVerifier');
|
|
13
15
|
/** CBOR tag 18 = COSE_Sign1 (RFC 8152). signData may or may not wrap in it. */
|
|
14
16
|
const COSE_SIGN1_TAG = 18;
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
+
// The one algorithm CIP-30 signData allows: EdDSA with an Ed25519 key.
|
|
18
|
+
const ALG_EDDSA = -8;
|
|
19
|
+
const KTY_OKP = 1;
|
|
20
|
+
const CRV_ED25519 = 6;
|
|
17
21
|
const ED25519_PUBKEY_LEN = 32;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const ED25519_SIGNATURE_LEN = 64;
|
|
23
|
+
const BLAKE2B_224_LEN = 28;
|
|
24
|
+
/** Entries of a COSE map by label. Throws on a repeated label, which COSE forbids. */
|
|
25
|
+
function readLabels(obj, what) {
|
|
26
|
+
if (!(obj instanceof cbor_1.CborMap))
|
|
27
|
+
throw new Error(`${what} must be a CBOR map`);
|
|
28
|
+
const labels = new Map();
|
|
29
|
+
for (const { k, v } of obj.map) {
|
|
30
|
+
const label = k instanceof cbor_1.CborUInt || k instanceof cbor_1.CborNegInt ? Number(k.num) : k instanceof cbor_1.CborText ? k.text : undefined;
|
|
31
|
+
if (label === undefined)
|
|
32
|
+
throw new Error(`${what} has a label that is neither an integer nor a text`);
|
|
33
|
+
if (labels.has(label))
|
|
34
|
+
throw new Error(`${what} repeats the label ${label}`);
|
|
35
|
+
labels.set(label, v);
|
|
36
|
+
}
|
|
37
|
+
return labels;
|
|
38
|
+
}
|
|
39
|
+
function intValue(obj) {
|
|
40
|
+
return obj instanceof cbor_1.CborUInt || obj instanceof cbor_1.CborNegInt ? Number(obj.num) : undefined;
|
|
28
41
|
}
|
|
42
|
+
function optionalBytes(obj, what) {
|
|
43
|
+
if (obj === undefined)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (!(obj instanceof cbor_1.CborBytes))
|
|
46
|
+
throw new Error(`${what} must be a byte string`);
|
|
47
|
+
return obj.bytes;
|
|
48
|
+
}
|
|
49
|
+
const sameBytes = (a, b) => Buffer.from(a).equals(Buffer.from(b));
|
|
29
50
|
function parseCoseSign1(hex) {
|
|
30
51
|
let obj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(hex));
|
|
31
52
|
// CIP-30 signData may emit the COSE_Sign1 wrapped in tag 18 or bare.
|
|
@@ -34,33 +55,59 @@ function parseCoseSign1(hex) {
|
|
|
34
55
|
if (!(obj instanceof cbor_1.CborArray) || obj.array.length !== 4) {
|
|
35
56
|
throw new Error('COSE_Sign1 must be a 4-element array [protected, unprotected, payload, signature]');
|
|
36
57
|
}
|
|
37
|
-
const [prot, , payload, signature] = obj.array;
|
|
58
|
+
const [prot, unprot, payload, signature] = obj.array;
|
|
38
59
|
if (!(prot instanceof cbor_1.CborBytes))
|
|
39
60
|
throw new Error('COSE_Sign1 protected header must be a byte string');
|
|
40
61
|
if (!(payload instanceof cbor_1.CborBytes))
|
|
41
62
|
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(
|
|
44
|
-
|
|
63
|
+
if (!(signature instanceof cbor_1.CborBytes) || signature.bytes.length !== ED25519_SIGNATURE_LEN) {
|
|
64
|
+
throw new Error(`COSE_Sign1 signature must be a byte string of ${ED25519_SIGNATURE_LEN} bytes`);
|
|
65
|
+
}
|
|
66
|
+
if (prot.bytes.length === 0)
|
|
67
|
+
throw new Error('COSE_Sign1 protected header is empty; alg and address are required');
|
|
68
|
+
const signed = readLabels(cbor_1.Cbor.parse(prot.bytes), 'COSE_Sign1 protected header');
|
|
69
|
+
const unsigned = readLabels(unprot, 'COSE_Sign1 unprotected header');
|
|
70
|
+
for (const label of unsigned.keys()) {
|
|
71
|
+
if (signed.has(label))
|
|
72
|
+
throw new Error(`COSE_Sign1 carries the header ${label} twice`);
|
|
73
|
+
}
|
|
74
|
+
if (intValue(signed.get(1)) !== ALG_EDDSA)
|
|
75
|
+
throw new Error('COSE_Sign1 protected header alg (1) must be EdDSA (-8)');
|
|
76
|
+
const address = optionalBytes(signed.get('address'), 'COSE_Sign1 address header');
|
|
77
|
+
if (!address)
|
|
78
|
+
throw new Error('COSE_Sign1 protected header carries no address');
|
|
79
|
+
const hashed = unsigned.get('hashed') ?? signed.get('hashed');
|
|
80
|
+
if (hashed !== undefined && !(hashed instanceof cbor_1.CborSimple && typeof hashed.simple === 'boolean')) {
|
|
81
|
+
throw new Error('COSE_Sign1 header hashed must be a boolean');
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
protectedBytes: prot.bytes,
|
|
85
|
+
payload: payload.bytes,
|
|
86
|
+
signature: signature.bytes,
|
|
87
|
+
address,
|
|
88
|
+
kid: optionalBytes(signed.get(4), 'COSE_Sign1 kid (4)'),
|
|
89
|
+
hashed: hashed instanceof cbor_1.CborSimple && hashed.simple === true,
|
|
90
|
+
};
|
|
45
91
|
}
|
|
46
|
-
/**
|
|
92
|
+
/** The Ed25519 public key of a COSE_Key, after its key type, algorithm and curve are checked. */
|
|
47
93
|
function parseCoseKey(hex) {
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
throw new Error('COSE_Key must be
|
|
51
|
-
|
|
94
|
+
const key = readLabels(cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(hex)), 'COSE_Key');
|
|
95
|
+
if (intValue(key.get(1)) !== KTY_OKP)
|
|
96
|
+
throw new Error('COSE_Key kty (1) must be OKP (1)');
|
|
97
|
+
if (intValue(key.get(3)) !== ALG_EDDSA)
|
|
98
|
+
throw new Error('COSE_Key alg (3) must be EdDSA (-8)');
|
|
99
|
+
if (intValue(key.get(-1)) !== CRV_ED25519)
|
|
100
|
+
throw new Error('COSE_Key crv (-1) must be Ed25519 (6)');
|
|
101
|
+
const x = key.get(-2);
|
|
52
102
|
if (!(x instanceof cbor_1.CborBytes))
|
|
53
103
|
throw new Error('COSE_Key is missing the Ed25519 public key (label -2)');
|
|
54
104
|
if (x.bytes.length !== ED25519_PUBKEY_LEN) {
|
|
55
105
|
throw new Error(`COSE_Key public key must be ${ED25519_PUBKEY_LEN} bytes, got ${x.bytes.length}`);
|
|
56
106
|
}
|
|
57
|
-
return x.bytes;
|
|
107
|
+
return { publicKey: x.bytes, kid: optionalBytes(key.get(2), 'COSE_Key kid (2)') };
|
|
58
108
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* [ "Signature1" (tstr), protected (bstr, exact bytes), external_aad (h''), payload (bstr) ]
|
|
62
|
-
* external_aad is empty for CIP-8 / CIP-30 signData.
|
|
63
|
-
*/
|
|
109
|
+
// The signed COSE Sig_structure: ["Signature1", protected, external_aad, payload].
|
|
110
|
+
// external_aad is empty for CIP-8 and CIP-30 signData.
|
|
64
111
|
function buildSigStructure(protectedBytes, payload) {
|
|
65
112
|
const sigStruct = new cbor_1.CborArray([
|
|
66
113
|
new cbor_1.CborText('Signature1'),
|
|
@@ -70,59 +117,88 @@ function buildSigStructure(protectedBytes, payload) {
|
|
|
70
117
|
]);
|
|
71
118
|
return cbor_1.Cbor.encode(sigStruct);
|
|
72
119
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
// The credential whose key signs for an address (CIP-30): the payment credential of a base, pointer
|
|
121
|
+
// or enterprise address, the stake credential of a reward address. Null for anything else.
|
|
122
|
+
function signingCredential(address) {
|
|
123
|
+
let bytes;
|
|
124
|
+
try {
|
|
125
|
+
bytes = Buffer.from(bech32_1.bech32.fromWords(bech32_1.bech32.decode(address, const_1.BECH32_MAX_LENGTH).words));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
if (bytes.length < 1 + BLAKE2B_224_LEN)
|
|
131
|
+
return null;
|
|
132
|
+
const type = bytes[0] >> 4;
|
|
133
|
+
const hash = bytes.subarray(1, 1 + BLAKE2B_224_LEN).toString('hex');
|
|
134
|
+
if (type <= 7)
|
|
135
|
+
return { bytes, hash, isScript: (type & 1) === 1 };
|
|
136
|
+
if (type === 14 || type === 15)
|
|
137
|
+
return { bytes, hash, isScript: type === 15 };
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
/** The bytes as text when they are valid UTF-8, else an empty string. */
|
|
141
|
+
function utf8OrEmpty(bytes) {
|
|
142
|
+
try {
|
|
143
|
+
return new node_util_1.TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Checks one CIP-30 signData result: structure, address, signer key, payload, then the signature.
|
|
150
|
+
// Stateless: a caller using it for login must issue the message itself, with a nonce and an expiry.
|
|
151
|
+
// Never throws; a failure returns `valid: false` with the reason.
|
|
84
152
|
function verifyDataSignature(input) {
|
|
85
|
-
const result = { valid: false, reason: '', signedPayload: '', signerVkh: '' };
|
|
153
|
+
const result = { valid: false, reason: '', signedPayload: '', signedPayloadHex: '', signerVkh: '' };
|
|
154
|
+
const fail = (reason) => {
|
|
155
|
+
result.reason = reason;
|
|
156
|
+
return result;
|
|
157
|
+
};
|
|
86
158
|
try {
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
result.
|
|
90
|
-
result.signerVkh = (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
|
|
159
|
+
const sign1 = parseCoseSign1(input.coseSignature);
|
|
160
|
+
const key = parseCoseKey(input.coseKey);
|
|
161
|
+
result.signedPayloadHex = (0, uint8array_utils_1.toHex)(sign1.payload);
|
|
162
|
+
result.signerVkh = (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(key.publicKey));
|
|
163
|
+
if (!sign1.hashed)
|
|
164
|
+
result.signedPayload = utf8OrEmpty(sign1.payload);
|
|
165
|
+
if (sign1.kid && key.kid && !sameBytes(sign1.kid, key.kid))
|
|
166
|
+
return fail('COSE_Sign1 kid and COSE_Key kid differ');
|
|
167
|
+
const signer = signingCredential(input.address);
|
|
168
|
+
if (!signer)
|
|
169
|
+
return fail('Address could not be decoded (a bech32 payment or reward address is required)');
|
|
170
|
+
if (!sameBytes(sign1.address, signer.bytes))
|
|
171
|
+
return fail('The address in the signed header is not the given address');
|
|
172
|
+
if (signer.isScript)
|
|
173
|
+
return fail('Address credential is a script hash; a key-hash address is required');
|
|
174
|
+
if (signer.hash !== result.signerVkh) {
|
|
175
|
+
return fail(`Signer key hash ${result.signerVkh} does not match the address credential ${signer.hash}`);
|
|
96
176
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
177
|
+
// The message is compared byte for byte; a hashed payload by its blake2b-224.
|
|
178
|
+
const expected = input.expectedPayload ?? undefined;
|
|
179
|
+
if (sign1.hashed) {
|
|
180
|
+
if (sign1.payload.length !== BLAKE2B_224_LEN)
|
|
181
|
+
return fail(`A hashed payload must be ${BLAKE2B_224_LEN} bytes (blake2b-224)`);
|
|
182
|
+
if (expected === undefined)
|
|
183
|
+
return fail('The wallet signed the hash of the message; pass expectedPayload to compare it');
|
|
184
|
+
if (!sameBytes((0, crypto_1.blake2b_224)(Buffer.from(expected, 'utf8')), sign1.payload))
|
|
185
|
+
return fail('Signed payload does not match the expected payload');
|
|
186
|
+
result.signedPayload = expected;
|
|
100
187
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
return result;
|
|
188
|
+
else if (expected !== undefined && !sameBytes(Buffer.from(expected, 'utf8'), sign1.payload)) {
|
|
189
|
+
return fail('Signed payload does not match the expected payload');
|
|
104
190
|
}
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
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;
|
|
191
|
+
const sigStructure = buildSigStructure(sign1.protectedBytes, sign1.payload);
|
|
192
|
+
if (!(0, crypto_1.verifyEd25519Signature_sync)(sign1.signature, sigStructure, key.publicKey)) {
|
|
193
|
+
return fail('Ed25519 signature does not verify against the signed message');
|
|
117
194
|
}
|
|
118
195
|
result.valid = true;
|
|
119
196
|
logger.debug({ signerVkh: result.signerVkh }, 'COSE_Sign1 data signature verified');
|
|
120
197
|
return result;
|
|
121
198
|
}
|
|
122
199
|
catch (err) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return result;
|
|
200
|
+
logger.warn(`Data signature not verified: ${err instanceof Error ? err.message : String(err)}`);
|
|
201
|
+
return fail(`Failed to verify data signature: ${err instanceof Error ? err.message : String(err)}`);
|
|
126
202
|
}
|
|
127
203
|
}
|
|
128
204
|
//# sourceMappingURL=cose-verifier.js.map
|
|
@@ -1,145 +1,45 @@
|
|
|
1
1
|
import { SignatureVerifier } from './signature-verifier';
|
|
2
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
|
-
*/
|
|
3
|
+
/** External signing workflow. No private keys are ever handled here. */
|
|
17
4
|
export declare class ExternalSignerModule {
|
|
18
5
|
private verifier;
|
|
19
6
|
private signingTtlMs;
|
|
20
7
|
constructor(options?: {
|
|
21
8
|
signingTtlMs?: number;
|
|
22
9
|
});
|
|
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
|
-
*/
|
|
10
|
+
/** Create the unsigned-tx export payload that starts a signing request (workflow entry point). */
|
|
37
11
|
createSigningRequest(buildId: string, unsignedTxCbor: string, txBodyHash: string, network: string, message: string, options?: {
|
|
38
12
|
requiredSigners?: string[];
|
|
39
13
|
signerTypeHint?: ExternalSignerType;
|
|
40
14
|
}): UnsignedTxExportPayload;
|
|
41
|
-
/**
|
|
42
|
-
* Generate signing instructions for different signer types
|
|
43
|
-
*/
|
|
15
|
+
/** Signing instructions for the different signer types (CIP-30 request + cardano-cli recipe). */
|
|
44
16
|
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
|
-
*/
|
|
17
|
+
/** Verify a signed tx against the build's body hash; enforces the signing TTL when `expiresAt` is given. */
|
|
56
18
|
verifySignedTransaction(signedTxCbor: string, expectedTxBodyHash: string, options?: Omit<VerificationOptions, 'expectedTxBodyHash'> & {
|
|
57
19
|
expiresAt?: string;
|
|
58
20
|
}): 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
|
-
*/
|
|
21
|
+
/** Like verifySignedTransaction, but throws TransactionValidationError on failure. */
|
|
67
22
|
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
|
-
*/
|
|
23
|
+
/** Initial (pending) workflow state for a signing request. */
|
|
77
24
|
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
|
-
*/
|
|
25
|
+
/** Workflow state → signed. */
|
|
85
26
|
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
|
-
*/
|
|
27
|
+
/** Workflow state → verified, or → failed when the verification result is invalid. */
|
|
93
28
|
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
|
-
*/
|
|
29
|
+
/** Workflow state → submitted. */
|
|
101
30
|
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
|
-
*/
|
|
31
|
+
/** Workflow state → failed. */
|
|
109
32
|
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
|
-
*/
|
|
33
|
+
/** True when the ISO-8601 `expiresAt` lies in the past. */
|
|
116
34
|
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
|
-
*/
|
|
35
|
+
/** Pre-submission check: signature + body-hash integrity against the build; throws TransactionValidationError. */
|
|
130
36
|
validateForSubmission(payload: SignedTxPayload, originalBuildTxBodyHash: string): SignatureVerificationResult;
|
|
131
|
-
/**
|
|
132
|
-
* Get the signature verifier instance
|
|
133
|
-
*/
|
|
37
|
+
/** The underlying signature verifier. */
|
|
134
38
|
getVerifier(): SignatureVerifier;
|
|
135
39
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Get the singleton ExternalSignerModule instance
|
|
138
|
-
*/
|
|
40
|
+
/** Singleton ExternalSignerModule. */
|
|
139
41
|
export declare function getExternalSignerModule(): ExternalSignerModule;
|
|
140
|
-
/**
|
|
141
|
-
* Create a new ExternalSignerModule instance with custom options
|
|
142
|
-
*/
|
|
42
|
+
/** New ExternalSignerModule with custom options (not the singleton). */
|
|
143
43
|
export declare function createExternalSignerModule(options?: {
|
|
144
44
|
signingTtlMs?: number;
|
|
145
45
|
}): ExternalSignerModule;
|