@ledgerhq/coin-module-framework 8.0.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/lib/api/impl.d.ts +74 -0
- package/lib/api/impl.d.ts.map +1 -0
- package/lib/api/impl.js +60 -0
- package/lib/api/impl.js.map +1 -0
- package/lib/api/index.d.ts +4 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +4 -0
- package/lib/api/index.js.map +1 -1
- package/lib/api/notSupported.d.ts +14 -0
- package/lib/api/notSupported.d.ts.map +1 -1
- package/lib/api/notSupported.js +31 -2
- package/lib/api/notSupported.js.map +1 -1
- package/lib/api/notSupportedApi.d.ts +37 -0
- package/lib/api/notSupportedApi.d.ts.map +1 -0
- package/lib/api/notSupportedApi.js +68 -0
- package/lib/api/notSupportedApi.js.map +1 -0
- package/lib/api/types.d.ts +4 -0
- package/lib/api/types.d.ts.map +1 -1
- package/lib/api/withDefaults.d.ts +31 -0
- package/lib/api/withDefaults.d.ts.map +1 -0
- package/lib/api/withDefaults.js +57 -0
- package/lib/api/withDefaults.js.map +1 -0
- package/lib/api/wrappers/index.d.ts +17 -0
- package/lib/api/wrappers/index.d.ts.map +1 -0
- package/lib/api/wrappers/index.js +35 -0
- package/lib/api/wrappers/index.js.map +1 -0
- package/lib/api/wrappers/instrumenter.d.ts +27 -0
- package/lib/api/wrappers/instrumenter.d.ts.map +1 -0
- package/lib/api/wrappers/instrumenter.js +46 -0
- package/lib/api/wrappers/instrumenter.js.map +1 -0
- package/lib/api/wrappers/withLogging.d.ts +11 -0
- package/lib/api/wrappers/withLogging.d.ts.map +1 -0
- package/lib/api/wrappers/withLogging.js +40 -0
- package/lib/api/wrappers/withLogging.js.map +1 -0
- package/lib/api/wrappers/withTracing.d.ts +18 -0
- package/lib/api/wrappers/withTracing.d.ts.map +1 -0
- package/lib/api/wrappers/withTracing.js +40 -0
- package/lib/api/wrappers/withTracing.js.map +1 -0
- package/lib/test-utils/capabilities.d.ts +44 -0
- package/lib/test-utils/capabilities.d.ts.map +1 -0
- package/lib/test-utils/capabilities.js +44 -0
- package/lib/test-utils/capabilities.js.map +1 -0
- package/lib/test-utils/helpers.d.ts +1 -1
- package/lib/test-utils/helpers.d.ts.map +1 -1
- package/lib/test-utils/helpers.js +15 -0
- package/lib/test-utils/helpers.js.map +1 -1
- package/lib-es/api/impl.d.ts +74 -0
- package/lib-es/api/impl.d.ts.map +1 -0
- package/lib-es/api/impl.js +57 -0
- package/lib-es/api/impl.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -0
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +4 -0
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/notSupported.d.ts +14 -0
- package/lib-es/api/notSupported.d.ts.map +1 -1
- package/lib-es/api/notSupported.js +30 -2
- package/lib-es/api/notSupported.js.map +1 -1
- package/lib-es/api/notSupportedApi.d.ts +37 -0
- package/lib-es/api/notSupportedApi.d.ts.map +1 -0
- package/lib-es/api/notSupportedApi.js +65 -0
- package/lib-es/api/notSupportedApi.js.map +1 -0
- package/lib-es/api/types.d.ts +4 -0
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/api/withDefaults.d.ts +31 -0
- package/lib-es/api/withDefaults.d.ts.map +1 -0
- package/lib-es/api/withDefaults.js +54 -0
- package/lib-es/api/withDefaults.js.map +1 -0
- package/lib-es/api/wrappers/index.d.ts +17 -0
- package/lib-es/api/wrappers/index.d.ts.map +1 -0
- package/lib-es/api/wrappers/index.js +19 -0
- package/lib-es/api/wrappers/index.js.map +1 -0
- package/lib-es/api/wrappers/instrumenter.d.ts +27 -0
- package/lib-es/api/wrappers/instrumenter.d.ts.map +1 -0
- package/lib-es/api/wrappers/instrumenter.js +43 -0
- package/lib-es/api/wrappers/instrumenter.js.map +1 -0
- package/lib-es/api/wrappers/withLogging.d.ts +11 -0
- package/lib-es/api/wrappers/withLogging.d.ts.map +1 -0
- package/lib-es/api/wrappers/withLogging.js +37 -0
- package/lib-es/api/wrappers/withLogging.js.map +1 -0
- package/lib-es/api/wrappers/withTracing.d.ts +18 -0
- package/lib-es/api/wrappers/withTracing.d.ts.map +1 -0
- package/lib-es/api/wrappers/withTracing.js +37 -0
- package/lib-es/api/wrappers/withTracing.js.map +1 -0
- package/lib-es/test-utils/capabilities.d.ts +44 -0
- package/lib-es/test-utils/capabilities.d.ts.map +1 -0
- package/lib-es/test-utils/capabilities.js +41 -0
- package/lib-es/test-utils/capabilities.js.map +1 -0
- package/lib-es/test-utils/helpers.d.ts +1 -1
- package/lib-es/test-utils/helpers.d.ts.map +1 -1
- package/lib-es/test-utils/helpers.js +1 -0
- package/lib-es/test-utils/helpers.js.map +1 -1
- package/package.json +1 -1
- package/src/api/impl.test.ts +83 -0
- package/src/api/impl.ts +112 -0
- package/src/api/index.ts +4 -0
- package/src/api/notSupported.ts +32 -2
- package/src/api/notSupportedApi.test.ts +67 -0
- package/src/api/notSupportedApi.ts +74 -0
- package/src/api/types.ts +4 -0
- package/src/api/withDefaults.test.ts +190 -0
- package/src/api/withDefaults.ts +87 -0
- package/src/api/wrappers/index.ts +20 -0
- package/src/api/wrappers/instrumenter.test.ts +123 -0
- package/src/api/wrappers/instrumenter.ts +58 -0
- package/src/api/wrappers/withLogging.test.ts +137 -0
- package/src/api/wrappers/withLogging.ts +47 -0
- package/src/api/wrappers/withTracing.test.ts +125 -0
- package/src/api/wrappers/withTracing.ts +56 -0
- package/src/test-utils/capabilities.test.ts +108 -0
- package/src/test-utils/capabilities.ts +93 -0
- package/src/test-utils/helpers.ts +2 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.withDefaults = withDefaults;
|
|
6
|
+
const impl_1 = require("./impl");
|
|
7
|
+
const notSupported_1 = require("./notSupported");
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes an authored capability method to "present" or "absent".
|
|
10
|
+
*
|
|
11
|
+
* A `notSupported()` stub counts as absent: it is a placeholder, not an implementation,
|
|
12
|
+
* so the framework's own default takes over. Behavior is unchanged either way (both throw
|
|
13
|
+
* the same `"<name> is not supported"`), but `supports()` then reports the truth.
|
|
14
|
+
*/
|
|
15
|
+
function implemented(value) {
|
|
16
|
+
return value === undefined || (0, notSupported_1.isNotSupportedStub)(value) ? undefined : value;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Widens a {@link CoinModuleImpl} authoring value to the full {@link CoinModuleApi}
|
|
20
|
+
* consumer contract by backfilling the capability methods the author omitted, and attaches
|
|
21
|
+
* a `supports()` introspection helper.
|
|
22
|
+
*
|
|
23
|
+
* Default per omitted method:
|
|
24
|
+
* - `getAccountInfo` → a `{ type: 'none' }` sentinel (ADR-045): having no extra account
|
|
25
|
+
* metadata is an answer, so callers get one instead of an exception.
|
|
26
|
+
* - every other capability → `notSupported(name)`, which throws `"<name> is not supported"`.
|
|
27
|
+
*
|
|
28
|
+
* Properties the authoring object carries beyond the API surface are preserved.
|
|
29
|
+
*
|
|
30
|
+
* A capability method is considered implemented only when the author supplied a real
|
|
31
|
+
* function — a `notSupported()` stub is treated as if the method had been omitted.
|
|
32
|
+
*/
|
|
33
|
+
function withDefaults(impl) {
|
|
34
|
+
const implementedMethods = new Set(impl_1.optionalApiKeys.filter((k) => implemented(impl[k]) !== undefined));
|
|
35
|
+
// Spread first so anything the module exposes beyond the API surface survives, then
|
|
36
|
+
// override every capability method with either the real implementation or the default.
|
|
37
|
+
return {
|
|
38
|
+
...impl,
|
|
39
|
+
getBlock: implemented(impl.getBlock) ?? (0, notSupported_1.notSupported)('getBlock'),
|
|
40
|
+
getBlockInfo: implemented(impl.getBlockInfo) ?? (0, notSupported_1.notSupported)('getBlockInfo'),
|
|
41
|
+
getStakes: implemented(impl.getStakes) ?? (0, notSupported_1.notSupported)('getStakes'),
|
|
42
|
+
getRewards: implemented(impl.getRewards) ?? (0, notSupported_1.notSupported)('getRewards'),
|
|
43
|
+
getValidators: implemented(impl.getValidators) ?? (0, notSupported_1.notSupported)('getValidators'),
|
|
44
|
+
call: implemented(impl.call) ?? (0, notSupported_1.notSupported)('call'),
|
|
45
|
+
craftRawTransaction: implemented(impl.craftRawTransaction) ?? (0, notSupported_1.notSupported)('craftRawTransaction'),
|
|
46
|
+
register: implemented(impl.register) ?? (0, notSupported_1.notSupported)('register'),
|
|
47
|
+
getNextSequence: implemented(impl.getNextSequence) ?? (0, notSupported_1.notSupported)('getNextSequence'),
|
|
48
|
+
validateIntent: implemented(impl.validateIntent) ?? (0, notSupported_1.notSupported)('validateIntent'),
|
|
49
|
+
validateAddress: implemented(impl.validateAddress) ?? (0, notSupported_1.notSupported)('validateAddress'),
|
|
50
|
+
// ADR-045: an absent getAccountInfo means the chain has no extra account metadata to
|
|
51
|
+
// report, which is an answer rather than a missing capability — hence a sentinel instead
|
|
52
|
+
// of a throwing stub. Callers read `type` and branch on it.
|
|
53
|
+
getAccountInfo: implemented(impl.getAccountInfo) ?? (() => Promise.resolve({ type: 'none' })),
|
|
54
|
+
supports: (method) => implementedMethods.has(method),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=withDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withDefaults.js","sourceRoot":"","sources":["../../src/api/withDefaults.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAmDtC,oCAkCC;AAhFD,iCAAwC;AACxC,iDAAiE;AAmBjE;;;;;;GAMG;AACH,SAAS,WAAW,CAAI,KAAoB;IAC1C,OAAO,KAAK,KAAK,SAAS,IAAI,IAAA,iCAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAA;AAC7E,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,YAAY,CAM1B,IAA8D;IAE9D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAChC,sBAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAClE,CAAA;IAED,oFAAoF;IACpF,uFAAuF;IACvF,OAAO;QACL,GAAG,IAAI;QACP,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAA,2BAAY,EAAC,UAAU,CAAC;QAChE,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,IAAA,2BAAY,EAAC,cAAc,CAAC;QAC5E,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,IAAA,2BAAY,EAAC,WAAW,CAAC;QACnE,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAA,2BAAY,EAAC,YAAY,CAAC;QACtE,aAAa,EAAE,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,IAAA,2BAAY,EAAC,eAAe,CAAC;QAC/E,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAA,2BAAY,EAAC,MAAM,CAAC;QACpD,mBAAmB,EACjB,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,IAAA,2BAAY,EAAC,qBAAqB,CAAC;QAC9E,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAA,2BAAY,EAAC,UAAU,CAAC;QAChE,eAAe,EAAE,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,IAAA,2BAAY,EAAC,iBAAiB,CAAC;QACrF,cAAc,EAAE,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,IAAA,2BAAY,EAAC,gBAAgB,CAAC;QAClF,eAAe,EAAE,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,IAAA,2BAAY,EAAC,iBAAiB,CAAC;QACrF,qFAAqF;QACrF,yFAAyF;QACzF,4DAA4D;QAC5D,cAAc,EAAE,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7F,QAAQ,EAAE,CAAC,MAAsB,EAAW,EAAE,CAAC,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC;KAC9E,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable cross-cutting wrappers over a {@link CoinModuleApi}.
|
|
3
|
+
*
|
|
4
|
+
* Each takes a full API and returns one with identical generics, so they compose in any
|
|
5
|
+
* order and none of them belongs to the core contract: a consumer that wants no
|
|
6
|
+
* instrumentation never reaches this folder.
|
|
7
|
+
*
|
|
8
|
+
* That signature is the line between this folder and the core. `withDefaults` shares the
|
|
9
|
+
* `with*` name but stays in the core because it *changes* the type — it widens an authoring
|
|
10
|
+
* `CoinModuleImpl` into the `CoinModuleApi` consumers require, which is the adapter the
|
|
11
|
+
* authoring type exists for and not an optional concern. Anything that preserves the
|
|
12
|
+
* contract it receives belongs here; anything that produces it belongs in the core.
|
|
13
|
+
*/
|
|
14
|
+
export * from './instrumenter';
|
|
15
|
+
export * from './withLogging';
|
|
16
|
+
export * from './withTracing';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/wrappers/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
/**
|
|
20
|
+
* Composable cross-cutting wrappers over a {@link CoinModuleApi}.
|
|
21
|
+
*
|
|
22
|
+
* Each takes a full API and returns one with identical generics, so they compose in any
|
|
23
|
+
* order and none of them belongs to the core contract: a consumer that wants no
|
|
24
|
+
* instrumentation never reaches this folder.
|
|
25
|
+
*
|
|
26
|
+
* That signature is the line between this folder and the core. `withDefaults` shares the
|
|
27
|
+
* `with*` name but stays in the core because it *changes* the type — it widens an authoring
|
|
28
|
+
* `CoinModuleImpl` into the `CoinModuleApi` consumers require, which is the adapter the
|
|
29
|
+
* authoring type exists for and not an optional concern. Anything that preserves the
|
|
30
|
+
* contract it receives belongs here; anything that produces it belongs in the core.
|
|
31
|
+
*/
|
|
32
|
+
__exportStar(require("./instrumenter"), exports);
|
|
33
|
+
__exportStar(require("./withLogging"), exports);
|
|
34
|
+
__exportStar(require("./withTracing"), exports);
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/wrappers/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;;;;;;;;;;;;AAEtC;;;;;;;;;;;;GAYG;AAEH,iDAA8B;AAC9B,gDAA6B;AAC7B,gDAA6B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CurrencyConfig } from '../../config';
|
|
2
|
+
import type { CoinModuleApi, Memo, TxData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a copy of a {@link CoinModuleApi} whose contract methods route through the
|
|
5
|
+
* provided `instrument` function. Everything else the object carries — non-API members
|
|
6
|
+
* such as the legacy bridge surface, or `supports` — is copied over untouched.
|
|
7
|
+
*
|
|
8
|
+
* Exported so other wrappers (withLogging, withTracing, withMetrics, …) can reuse the
|
|
9
|
+
* same interception mechanism without duplicating the boilerplate.
|
|
10
|
+
*
|
|
11
|
+
* The wrapped set is {@link apiMethodKeys}, the contract's own method list, rather than
|
|
12
|
+
* "every property that happens to be a function": what gets instrumented is then readable
|
|
13
|
+
* from the source, and a method added to the contract cannot be silently skipped — the
|
|
14
|
+
* exhaustiveness guard next to that list fails to compile first.
|
|
15
|
+
*
|
|
16
|
+
* Each method is wrapped and bound once, eagerly, so repeated reads are referentially
|
|
17
|
+
* stable (`api.getBalance === api.getBalance`) — a consumer using a method as a dependency
|
|
18
|
+
* key, a React effect or a memo cache, would otherwise see a new function every time — and
|
|
19
|
+
* no allocation happens on the call path.
|
|
20
|
+
*
|
|
21
|
+
* Expects a plain object, which is what a `createApi()` result and a `withDefaults` result
|
|
22
|
+
* both are. Methods living on a prototype rather than on the object itself are copied by
|
|
23
|
+
* value here, so a class instance that reassigns its own methods after wrapping would not
|
|
24
|
+
* see the change.
|
|
25
|
+
*/
|
|
26
|
+
export declare function instrumentApi<C extends CurrencyConfig, M extends Memo, T extends TxData, Extra extends object = Record<never, never>>(api: CoinModuleApi<C, M, T> & Extra, instrument: (name: string, fn: (...args: unknown[]) => unknown, args: unknown[]) => unknown): CoinModuleApi<C, M, T> & Extra;
|
|
27
|
+
//# sourceMappingURL=instrumenter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumenter.d.ts","sourceRoot":"","sources":["../../../src/api/wrappers/instrumenter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAO3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,IAAI,EACd,CAAC,SAAS,MAAM,EAChB,KAAK,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE3C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,EACnC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAC1F,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAehC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.instrumentApi = instrumentApi;
|
|
6
|
+
const impl_1 = require("../impl");
|
|
7
|
+
/** Narrows a copied member to a callable without asserting its type. */
|
|
8
|
+
const isMethod = (value) => typeof value === 'function';
|
|
9
|
+
/**
|
|
10
|
+
* Returns a copy of a {@link CoinModuleApi} whose contract methods route through the
|
|
11
|
+
* provided `instrument` function. Everything else the object carries — non-API members
|
|
12
|
+
* such as the legacy bridge surface, or `supports` — is copied over untouched.
|
|
13
|
+
*
|
|
14
|
+
* Exported so other wrappers (withLogging, withTracing, withMetrics, …) can reuse the
|
|
15
|
+
* same interception mechanism without duplicating the boilerplate.
|
|
16
|
+
*
|
|
17
|
+
* The wrapped set is {@link apiMethodKeys}, the contract's own method list, rather than
|
|
18
|
+
* "every property that happens to be a function": what gets instrumented is then readable
|
|
19
|
+
* from the source, and a method added to the contract cannot be silently skipped — the
|
|
20
|
+
* exhaustiveness guard next to that list fails to compile first.
|
|
21
|
+
*
|
|
22
|
+
* Each method is wrapped and bound once, eagerly, so repeated reads are referentially
|
|
23
|
+
* stable (`api.getBalance === api.getBalance`) — a consumer using a method as a dependency
|
|
24
|
+
* key, a React effect or a memo cache, would otherwise see a new function every time — and
|
|
25
|
+
* no allocation happens on the call path.
|
|
26
|
+
*
|
|
27
|
+
* Expects a plain object, which is what a `createApi()` result and a `withDefaults` result
|
|
28
|
+
* both are. Methods living on a prototype rather than on the object itself are copied by
|
|
29
|
+
* value here, so a class instance that reassigns its own methods after wrapping would not
|
|
30
|
+
* see the change.
|
|
31
|
+
*/
|
|
32
|
+
function instrumentApi(api, instrument) {
|
|
33
|
+
const instrumented = { ...api };
|
|
34
|
+
for (const name of impl_1.apiMethodKeys) {
|
|
35
|
+
const method = instrumented[name];
|
|
36
|
+
// A contract method the object does not carry: `listFeeOptions`, which withDefaults
|
|
37
|
+
// leaves absent, or any method on a value that never went through withDefaults.
|
|
38
|
+
if (!isMethod(method))
|
|
39
|
+
continue;
|
|
40
|
+
const bound = method.bind(api);
|
|
41
|
+
instrumented[name] = (...args) => instrument(name, bound, args);
|
|
42
|
+
}
|
|
43
|
+
// oxlint-disable-next-line consistent-type-assertions -- every contract method was replaced by a wrapper of the same arity and the rest was copied verbatim, so the shape is unchanged; TS cannot follow that through an index-signature write
|
|
44
|
+
return instrumented;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=instrumenter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../../src/api/wrappers/instrumenter.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAiCtC,sCAuBC;AApDD,kCAAuC;AAEvC,wEAAwE;AACxE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA4C,EAAE,CAC5E,OAAO,KAAK,KAAK,UAAU,CAAA;AAE7B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,aAAa,CAM3B,GAAmC,EACnC,UAA2F;IAE3F,MAAM,YAAY,GAA4B,EAAE,GAAG,GAAG,EAAE,CAAA;IAExD,KAAK,MAAM,IAAI,IAAI,oBAAa,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;QACjC,oFAAoF;QACpF,gFAAgF;QAChF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,SAAQ;QAE/B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC9B,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAe,EAAW,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;IACrF,CAAC;IAED,+OAA+O;IAC/O,OAAO,YAA8C,CAAA;AACvD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CurrencyConfig } from '../../config';
|
|
2
|
+
import type { CoinModuleApi, Memo, MemoNotSupported, TxData, TxDataNotSupported } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a {@link CoinModuleApi} to emit log entries via the per-call {@link Context}'s
|
|
5
|
+
* logger before and after each method invocation, including on error.
|
|
6
|
+
*
|
|
7
|
+
* The Context is forwarded unchanged to the underlying method.
|
|
8
|
+
* Handles both synchronous methods (e.g. `combine`) and async methods uniformly.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withLogging<C extends CurrencyConfig, M extends Memo = MemoNotSupported, T extends TxData = TxDataNotSupported, Extra extends object = Record<never, never>>(api: CoinModuleApi<C, M, T> & Extra): CoinModuleApi<C, M, T> & Extra;
|
|
11
|
+
//# sourceMappingURL=withLogging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withLogging.d.ts","sourceRoot":"","sources":["../../../src/api/wrappers/withLogging.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGjG;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,IAAI,GAAG,gBAAgB,EACjC,CAAC,SAAS,MAAM,GAAG,kBAAkB,EACrC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC3C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CA2BrE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.withLogging = withLogging;
|
|
6
|
+
const instrumenter_1 = require("./instrumenter");
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a {@link CoinModuleApi} to emit log entries via the per-call {@link Context}'s
|
|
9
|
+
* logger before and after each method invocation, including on error.
|
|
10
|
+
*
|
|
11
|
+
* The Context is forwarded unchanged to the underlying method.
|
|
12
|
+
* Handles both synchronous methods (e.g. `combine`) and async methods uniformly.
|
|
13
|
+
*/
|
|
14
|
+
function withLogging(api) {
|
|
15
|
+
return (0, instrumenter_1.instrumentApi)(api, (name, fn, args) => {
|
|
16
|
+
// oxlint-disable-next-line consistent-type-assertions -- args[0] is always Context<C> per CoinModuleApi contract; unknown cast needed to access logger
|
|
17
|
+
const logger = args[0]?.logger;
|
|
18
|
+
logger?.(`[coin-module] ${name}: call`);
|
|
19
|
+
let result;
|
|
20
|
+
try {
|
|
21
|
+
result = fn(...args);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger?.(`[coin-module] ${name}: error`, e);
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
if (result instanceof Promise) {
|
|
28
|
+
return result.then((v) => {
|
|
29
|
+
logger?.(`[coin-module] ${name}: ok`);
|
|
30
|
+
return v;
|
|
31
|
+
}, (e) => {
|
|
32
|
+
logger?.(`[coin-module] ${name}: error`, e);
|
|
33
|
+
throw e;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
logger?.(`[coin-module] ${name}: ok`);
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=withLogging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withLogging.js","sourceRoot":"","sources":["../../../src/api/wrappers/withLogging.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAatC,kCAgCC;AAzCD,iDAA8C;AAE9C;;;;;;GAMG;AACH,SAAgB,WAAW,CAKzB,GAAmC;IACnC,OAAO,IAAA,4BAAa,EAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;QAC3C,uJAAuJ;QACvJ,MAAM,MAAM,GAAI,IAAI,CAAC,CAAC,CAA4B,EAAE,MAAM,CAAA;QAC1D,MAAM,EAAE,CAAC,iBAAiB,IAAI,QAAQ,CAAC,CAAA;QACvC,IAAI,MAAe,CAAA;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;QACtB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,EAAE,CAAC,iBAAiB,IAAI,SAAS,EAAE,CAAC,CAAC,CAAA;YAC3C,MAAM,CAAC,CAAA;QACT,CAAC;QACD,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC,IAAI,CAChB,CAAC,CAAC,EAAE,EAAE;gBACJ,MAAM,EAAE,CAAC,iBAAiB,IAAI,MAAM,CAAC,CAAA;gBACrC,OAAO,CAAC,CAAA;YACV,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;gBACJ,MAAM,EAAE,CAAC,iBAAiB,IAAI,SAAS,EAAE,CAAC,CAAC,CAAA;gBAC3C,MAAM,CAAC,CAAA;YACT,CAAC,CACF,CAAA;QACH,CAAC;QACD,MAAM,EAAE,CAAC,iBAAiB,IAAI,MAAM,CAAC,CAAA;QACrC,OAAO,MAAM,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CurrencyConfig } from '../../config';
|
|
2
|
+
import type { CoinModuleApi, Memo, MemoNotSupported, TxData, TxDataNotSupported } from '../types';
|
|
3
|
+
export interface Span {
|
|
4
|
+
end(): void;
|
|
5
|
+
setError(error: unknown): void;
|
|
6
|
+
}
|
|
7
|
+
export interface Tracer {
|
|
8
|
+
startSpan(name: string): Span;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a {@link CoinModuleApi} to open a tracing span around each method invocation.
|
|
12
|
+
*
|
|
13
|
+
* The span is ended on success, or after `setError` on throw.
|
|
14
|
+
* The Context is forwarded unchanged to the underlying method.
|
|
15
|
+
* Handles both synchronous methods (e.g. `combine`) and async methods uniformly.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withTracing<C extends CurrencyConfig, M extends Memo = MemoNotSupported, T extends TxData = TxDataNotSupported, Extra extends object = Record<never, never>>(api: CoinModuleApi<C, M, T> & Extra, tracer: Tracer): CoinModuleApi<C, M, T> & Extra;
|
|
18
|
+
//# sourceMappingURL=withTracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withTracing.d.ts","sourceRoot":"","sources":["../../../src/api/wrappers/withTracing.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGjG,MAAM,WAAW,IAAI;IACnB,GAAG,IAAI,IAAI,CAAA;IACX,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;CAC/B;AAED,MAAM,WAAW,MAAM;IACrB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,IAAI,GAAG,gBAAgB,EACjC,CAAC,SAAS,MAAM,GAAG,kBAAkB,EACrC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC3C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CA2BrF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.withTracing = withTracing;
|
|
6
|
+
const instrumenter_1 = require("./instrumenter");
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a {@link CoinModuleApi} to open a tracing span around each method invocation.
|
|
9
|
+
*
|
|
10
|
+
* The span is ended on success, or after `setError` on throw.
|
|
11
|
+
* The Context is forwarded unchanged to the underlying method.
|
|
12
|
+
* Handles both synchronous methods (e.g. `combine`) and async methods uniformly.
|
|
13
|
+
*/
|
|
14
|
+
function withTracing(api, tracer) {
|
|
15
|
+
return (0, instrumenter_1.instrumentApi)(api, (name, fn, args) => {
|
|
16
|
+
const span = tracer.startSpan(name);
|
|
17
|
+
let result;
|
|
18
|
+
try {
|
|
19
|
+
result = fn(...args);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
span.setError(e);
|
|
23
|
+
span.end();
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
if (result instanceof Promise) {
|
|
27
|
+
return result.then((v) => {
|
|
28
|
+
span.end();
|
|
29
|
+
return v;
|
|
30
|
+
}, (e) => {
|
|
31
|
+
span.setError(e);
|
|
32
|
+
span.end();
|
|
33
|
+
throw e;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
span.end();
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=withTracing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withTracing.js","sourceRoot":"","sources":["../../../src/api/wrappers/withTracing.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAsBtC,kCAgCC;AAlDD,iDAA8C;AAW9C;;;;;;GAMG;AACH,SAAgB,WAAW,CAKzB,GAAmC,EAAE,MAAc;IACnD,OAAO,IAAA,4BAAa,EAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;QAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QACnC,IAAI,MAAe,CAAA;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;QACtB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;YAChB,IAAI,CAAC,GAAG,EAAE,CAAA;YACV,MAAM,CAAC,CAAA;QACT,CAAC;QACD,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC,IAAI,CAChB,CAAC,CAAC,EAAE,EAAE;gBACJ,IAAI,CAAC,GAAG,EAAE,CAAA;gBACV,OAAO,CAAC,CAAA;YACV,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;gBACJ,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;gBAChB,IAAI,CAAC,GAAG,EAAE,CAAA;gBACV,MAAM,CAAC,CAAA;YACT,CAAC,CACF,CAAA;QACH,CAAC;QACD,IAAI,CAAC,GAAG,EAAE,CAAA;QACV,OAAO,MAAM,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CoinModuleImpl, OptionalApiKey } from '../api/impl';
|
|
2
|
+
import type { Memo, TxData } from '../api/types';
|
|
3
|
+
import type { Context, CurrencyConfig } from '../config';
|
|
4
|
+
/**
|
|
5
|
+
* What a module reports about the capabilities it does not implement, as a consumer sees it
|
|
6
|
+
* through `withDefaults`. Meant to be asserted whole:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* await expect(capabilityReport(createApi(), context)).resolves.toEqual({
|
|
10
|
+
* unsupported: ['call', 'craftRawTransaction', 'getRewards', 'getValidators', 'register'],
|
|
11
|
+
* inconsistent: [],
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* One expectation then covers what a module's api test used to spell out method by method:
|
|
16
|
+
* that each capability is absent, that reaching it raises `"<name> is not supported"`, and
|
|
17
|
+
* that `supports()` agrees. `toEqual` makes it exhaustive — a capability dropped or newly
|
|
18
|
+
* implemented changes the list, so the test notices instead of silently still passing.
|
|
19
|
+
*
|
|
20
|
+
* It reads a module written either way: a `CoinModuleImpl` that omits its capabilities, or a
|
|
21
|
+
* value built by spreading `notSupportedApi()`. Both are "not implemented" as far as
|
|
22
|
+
* `supports()` is concerned, which is what this observes.
|
|
23
|
+
*/
|
|
24
|
+
export type CapabilityReport = {
|
|
25
|
+
/** Capabilities the module does not implement, sorted, each verified to raise its error. */
|
|
26
|
+
unsupported: OptionalApiKey[];
|
|
27
|
+
/**
|
|
28
|
+
* Capabilities `supports()` calls absent but which did not raise `"<name> is not
|
|
29
|
+
* supported"` when reached — a missing backfill, or an error naming another method.
|
|
30
|
+
* Expected to be empty.
|
|
31
|
+
*/
|
|
32
|
+
inconsistent: OptionalApiKey[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Builds a {@link CapabilityReport} for a coin module.
|
|
36
|
+
*
|
|
37
|
+
* Only the capabilities `supports()` reports absent are actually invoked — a real
|
|
38
|
+
* implementation is never called, so this never reaches the network.
|
|
39
|
+
*
|
|
40
|
+
* `getAccountInfo` is excluded: per ADR-045 its default is the `{ type: 'none' }` sentinel
|
|
41
|
+
* rather than an error, so it is not a capability in the sense the rest of this list is.
|
|
42
|
+
*/
|
|
43
|
+
export declare function capabilityReport<ConfigType extends CurrencyConfig, MemoType extends Memo, TxDataType extends TxData>(impl: CoinModuleImpl<ConfigType, MemoType, TxDataType>, context: Context<ConfigType>): Promise<CapabilityReport>;
|
|
44
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/test-utils/capabilities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAQxD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,4FAA4F;IAC5F,WAAW,EAAE,cAAc,EAAE,CAAA;IAC7B;;;;OAIG;IACH,YAAY,EAAE,cAAc,EAAE,CAAA;CAC/B,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,SAAS,cAAc,EACjC,QAAQ,SAAS,IAAI,EACrB,UAAU,SAAS,MAAM,EAEzB,IAAI,EAAE,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EACtD,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAgC3B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.capabilityReport = capabilityReport;
|
|
6
|
+
const impl_1 = require("../api/impl");
|
|
7
|
+
const withDefaults_1 = require("../api/withDefaults");
|
|
8
|
+
/** Narrows a member reached by name to a callable without asserting its type. */
|
|
9
|
+
const isMethod = (value) => typeof value === 'function';
|
|
10
|
+
/**
|
|
11
|
+
* Builds a {@link CapabilityReport} for a coin module.
|
|
12
|
+
*
|
|
13
|
+
* Only the capabilities `supports()` reports absent are actually invoked — a real
|
|
14
|
+
* implementation is never called, so this never reaches the network.
|
|
15
|
+
*
|
|
16
|
+
* `getAccountInfo` is excluded: per ADR-045 its default is the `{ type: 'none' }` sentinel
|
|
17
|
+
* rather than an error, so it is not a capability in the sense the rest of this list is.
|
|
18
|
+
*/
|
|
19
|
+
async function capabilityReport(impl, context) {
|
|
20
|
+
const resolved = (0, withDefaults_1.withDefaults)(impl);
|
|
21
|
+
const asRecord = resolved;
|
|
22
|
+
const unsupported = [];
|
|
23
|
+
const inconsistent = [];
|
|
24
|
+
for (const name of impl_1.optionalApiKeys) {
|
|
25
|
+
if (name === 'getAccountInfo' || resolved.supports(name))
|
|
26
|
+
continue;
|
|
27
|
+
const method = asRecord[name];
|
|
28
|
+
if (!isMethod(method)) {
|
|
29
|
+
inconsistent.push(name);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
// The framework default throws synchronously, but a module may still carry a stub written
|
|
33
|
+
// as an async function, which rejects instead. Both count as raising the error.
|
|
34
|
+
const raised = await Promise.resolve()
|
|
35
|
+
.then(() => method(context))
|
|
36
|
+
.then(() => undefined, (error) => (error instanceof Error ? error.message : String(error)));
|
|
37
|
+
if (raised === `${name} is not supported`)
|
|
38
|
+
unsupported.push(name);
|
|
39
|
+
else
|
|
40
|
+
inconsistent.push(name);
|
|
41
|
+
}
|
|
42
|
+
return { unsupported: unsupported.sort(), inconsistent: inconsistent.sort() };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/test-utils/capabilities.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAoDtC,4CAuCC;AAtFD,sCAA6C;AAC7C,sDAAkD;AAElD,iFAAiF;AACjF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA4C,EAAE,CAC5E,OAAO,KAAK,KAAK,UAAU,CAAA;AAiC7B;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB,CAKpC,IAAsD,EACtD,OAA4B;IAE5B,MAAM,QAAQ,GAEV,IAAA,2BAAY,EAAC,IAAI,CAAC,CAAA;IACtB,MAAM,QAAQ,GAA4B,QAAQ,CAAA;IAElD,MAAM,WAAW,GAAqB,EAAE,CAAA;IACxC,MAAM,YAAY,GAAqB,EAAE,CAAA;IAEzC,KAAK,MAAM,IAAI,IAAI,sBAAe,EAAE,CAAC;QACnC,IAAI,IAAI,KAAK,gBAAgB,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,SAAQ;QAElE,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACvB,SAAQ;QACV,CAAC;QAED,0FAA0F;QAC1F,gFAAgF;QAChF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE;aACnC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aAC3B,IAAI,CACH,GAAG,EAAE,CAAC,SAAS,EACf,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC7E,CAAA;QAEH,IAAI,MAAM,KAAK,GAAG,IAAI,mBAAmB;YAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;;YAC5D,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE,EAAE,CAAA;AAC/E,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AssetInfo, Memo, MemoNotSupported, SendTransactionIntent, StakingOperation, StakingTransactionIntent, TxData, TxDataNotSupported } from '../api/index';
|
|
2
|
+
export * from './capabilities';
|
|
2
3
|
type SendPartialBase = {
|
|
3
4
|
type: string;
|
|
4
5
|
} & Partial<Omit<SendTransactionIntent<MemoNotSupported, TxDataNotSupported>, 'intentType' | 'type'>>;
|
|
@@ -17,5 +18,4 @@ export declare function createStakingTransactionIntentMockData<MemoType extends
|
|
|
17
18
|
export declare function createAssetInfoMockData(partial: {
|
|
18
19
|
type: string;
|
|
19
20
|
} & Partial<Omit<AssetInfo, 'type'>>): AssetInfo;
|
|
20
|
-
export {};
|
|
21
21
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/test-utils/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,MAAM,EACN,kBAAkB,EACnB,MAAM,cAAc,CAAA;AAErB,KAAK,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAC/C,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,CACzF,CAAA;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,EAE9C,OAAO,EAAE,eAAe,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAE,GAChE,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAe9C,KAAK,kBAAkB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,OAAO,CAC1E,IAAI,CACF,wBAAwB,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,EAC9D,YAAY,GAAG,MAAM,GAAG,MAAM,CAC/B,CACF,CAAA;AAED,wBAAgB,sCAAsC,CACpD,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,EAE9C,OAAO,EAAE,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAE,GACnE,wBAAwB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAiBjD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,GAC3D,SAAS,CAGX"}
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/test-utils/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,MAAM,EACN,kBAAkB,EACnB,MAAM,cAAc,CAAA;AAErB,cAAc,gBAAgB,CAAA;AAE9B,KAAK,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAC/C,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,CACzF,CAAA;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,EAE9C,OAAO,EAAE,eAAe,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAE,GAChE,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAe9C,KAAK,kBAAkB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,OAAO,CAC1E,IAAI,CACF,wBAAwB,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,EAC9D,YAAY,GAAG,MAAM,GAAG,MAAM,CAC/B,CACF,CAAA;AAED,wBAAgB,sCAAsC,CACpD,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,EAE9C,OAAO,EAAE,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAE,GACnE,wBAAwB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAiBjD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,GAC3D,SAAS,CAGX"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
4
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
19
|
exports.createSendTransactionIntentMockData = createSendTransactionIntentMockData;
|
|
6
20
|
exports.createStakingTransactionIntentMockData = createStakingTransactionIntentMockData;
|
|
7
21
|
exports.createAssetInfoMockData = createAssetInfoMockData;
|
|
22
|
+
__exportStar(require("./capabilities"), exports);
|
|
8
23
|
function createSendTransactionIntentMockData(partial) {
|
|
9
24
|
const base = {
|
|
10
25
|
intentType: 'transaction',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/test-utils/helpers.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/test-utils/helpers.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;;;;;;;;;;;;AAyBtC,kFAYC;AAeD,wFAcC;AAED,0DAKC;AA5DD,iDAA8B;AAY9B,SAAgB,mCAAmC,CACjD,OAAwB;IAExB,MAAM,IAAI,GAAgE;QACxE,UAAU,EAAE,aAAa;QACzB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,gBAAgB;QAC1C,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,mBAAmB;QACnD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;QAC5B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3C,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AACzC,CAAC;AAeD,SAAgB,sCAAsC,CACpD,OAA2B;IAE3B,MAAM,IAAI,GAAmE;QAC3E,UAAU,EAAE,SAAS;QACrB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,gBAAgB;QAC1C,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,mBAAmB;QACnD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;QAC5B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1C,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,mBAAmB;KACtD,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AACzC,CAAC;AAED,SAAgB,uBAAuB,CACrC,OAA4D;IAE5D,MAAM,KAAK,GAAc,EAAE,GAAG,OAAO,EAAE,CAAA;IACvC,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CurrencyConfig } from '../config';
|
|
2
|
+
import type { CoinModuleApi, Memo, MemoNotSupported, TxData, TxDataNotSupported } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Methods a CoinModuleImpl author may omit when the chain does not support them.
|
|
5
|
+
* The framework's `withDefaults` fills the gaps before the consumer receives the
|
|
6
|
+
* object as a full {@link CoinModuleApi}.
|
|
7
|
+
*
|
|
8
|
+
* Block — getBlock, getBlockInfo (many chains throw "not supported")
|
|
9
|
+
* Staking — getStakes, getRewards, (à la carte; a module may ship getStakes
|
|
10
|
+
* getValidators without getValidators)
|
|
11
|
+
* SmartContract— call (optional escape-hatch)
|
|
12
|
+
* RawCrafting — craftRawTransaction (not all chains accept externally-built txs)
|
|
13
|
+
* Enrollment — register (optional indexer backend)
|
|
14
|
+
* Sequence — getNextSequence (some chains have no sequence/nonce concept)
|
|
15
|
+
* Validation — validateIntent, (some chains cannot fully validate intents
|
|
16
|
+
* validateAddress or addresses without a network round-trip)
|
|
17
|
+
* AccountInfo — getAccountInfo (chain-specific account metadata; absent means
|
|
18
|
+
* "nothing to report", not "unsupported")
|
|
19
|
+
*/
|
|
20
|
+
export declare const optionalApiKeys: readonly ["getBlock", "getBlockInfo", "getStakes", "getRewards", "getValidators", "call", "craftRawTransaction", "register", "getNextSequence", "validateIntent", "validateAddress", "getAccountInfo"];
|
|
21
|
+
/**
|
|
22
|
+
* A method name that a {@link CoinModuleImpl} author may omit.
|
|
23
|
+
*
|
|
24
|
+
* Derived from {@link optionalApiKeys} so the type and the runtime list used by
|
|
25
|
+
* `withDefaults` cannot drift apart.
|
|
26
|
+
*/
|
|
27
|
+
export type OptionalApiKey = (typeof optionalApiKeys)[number];
|
|
28
|
+
/**
|
|
29
|
+
* Methods every {@link CoinModuleImpl} author must implement: the minimum a chain has to
|
|
30
|
+
* expose for the module to be usable at all. Complement of {@link optionalApiKeys}.
|
|
31
|
+
*/
|
|
32
|
+
export declare const requiredApiKeys: readonly ["lastBlock", "getBalance", "listOperations", "craftTransaction", "estimateFees", "combine", "broadcast", "craftTransactionData"];
|
|
33
|
+
/** A method name a {@link CoinModuleImpl} author must implement. */
|
|
34
|
+
export type RequiredApiKey = (typeof requiredApiKeys)[number];
|
|
35
|
+
/**
|
|
36
|
+
* Every method the {@link CoinModuleApi} contract declares.
|
|
37
|
+
*
|
|
38
|
+
* Wrappers iterate this list to instrument an API without reflecting over the object at
|
|
39
|
+
* runtime, so what they touch is fixed and readable rather than "whatever is a function".
|
|
40
|
+
* `listFeeOptions` is neither required nor omittable — the contract itself declares it
|
|
41
|
+
* optional and `withDefaults` does not backfill it — hence its place here and nowhere else.
|
|
42
|
+
*/
|
|
43
|
+
export declare const apiMethodKeys: readonly ["lastBlock", "getBalance", "listOperations", "craftTransaction", "estimateFees", "combine", "broadcast", "craftTransactionData", "getBlock", "getBlockInfo", "getStakes", "getRewards", "getValidators", "call", "craftRawTransaction", "register", "getNextSequence", "validateIntent", "validateAddress", "getAccountInfo", "listFeeOptions"];
|
|
44
|
+
/** A method name declared by the {@link CoinModuleApi} contract. */
|
|
45
|
+
export type ApiMethodKey = (typeof apiMethodKeys)[number];
|
|
46
|
+
/**
|
|
47
|
+
* Compile-time guard: {@link apiMethodKeys} must name every method of the contract.
|
|
48
|
+
*
|
|
49
|
+
* Add a method to {@link CoinModuleApi} without listing it and `Unlisted` stops being
|
|
50
|
+
* `never`, which this alias rejects — so a wrapper can never silently skip a new method.
|
|
51
|
+
*/
|
|
52
|
+
type AssertNever<T extends never> = T;
|
|
53
|
+
export type ApiMethodKeysAreExhaustive = AssertNever<Exclude<keyof CoinModuleApi<CurrencyConfig>, ApiMethodKey>>;
|
|
54
|
+
/**
|
|
55
|
+
* Authoring type for a coin-module implementation.
|
|
56
|
+
*
|
|
57
|
+
* Declare your module's `createApi` return type as `CoinModuleImpl<…>` instead of
|
|
58
|
+
* `CoinModuleApi<…>`. Any method in the optional set (see source) may be omitted;
|
|
59
|
+
* the framework's `withDefaults` wrapper will supply the "not supported" stub before
|
|
60
|
+
* handing the object to consumers.
|
|
61
|
+
*
|
|
62
|
+
* The consumer/full contract ({@link CoinModuleApi}) is structurally unchanged —
|
|
63
|
+
* it remains the required type at every call site.
|
|
64
|
+
*
|
|
65
|
+
* Generic parameters are identical to {@link CoinModuleApi}:
|
|
66
|
+
* - `ConfigType` — the coin-specific config shape
|
|
67
|
+
* - `MemoType` — memo variant (defaults to {@link MemoNotSupported})
|
|
68
|
+
* - `TxDataType` — transaction data variant (defaults to {@link TxDataNotSupported})
|
|
69
|
+
*
|
|
70
|
+
* @see CoinModuleApi — the full consumer/runtime contract (unchanged)
|
|
71
|
+
*/
|
|
72
|
+
export type CoinModuleImpl<ConfigType extends CurrencyConfig, MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported> = Omit<CoinModuleApi<ConfigType, MemoType, TxDataType>, OptionalApiKey> & Partial<Pick<CoinModuleApi<ConfigType, MemoType, TxDataType>, OptionalApiKey>>;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impl.d.ts","sourceRoot":"","sources":["../../src/api/impl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEhG;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe,wMAalB,CAAA;AAEV;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7D;;;GAGG;AACH,eAAO,MAAM,eAAe,4IASlB,CAAA;AAEV,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,2VAAsE,CAAA;AAEhG,oEAAoE;AACpE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzD;;;;;GAKG;AACH,KAAK,WAAW,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,CAAA;AACrC,MAAM,MAAM,0BAA0B,GAAG,WAAW,CAClD,OAAO,CAAC,MAAM,aAAa,CAAC,cAAc,CAAC,EAAE,YAAY,CAAC,CAC3D,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,cAAc,CACxB,UAAU,SAAS,cAAc,EACjC,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,IAC5C,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,cAAc,CAAC,GACvE,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,cAAc,CAAC,CAAC,CAAA"}
|