@ledgerhq/coin-module-framework 8.1.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 +98 -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/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/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/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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
1
|
# @ledgerhq/coin-module-framework
|
|
2
2
|
|
|
3
|
+
## 8.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#826](https://github.com/LedgerHQ/coin-modules/pull/826) [`2ec4aa4`](https://github.com/LedgerHQ/coin-modules/commit/2ec4aa48b23168e3fb846928435c1f5110b8153e) Thanks [@cted-ledger](https://github.com/cted-ledger)! - Add `CoinModuleImpl` authoring type — modules may now declare only the methods they implement; optional capabilities (`getBlock`, `getBlockInfo`, `getStakes`, `getRewards`, `getValidators`, `call`, `craftRawTransaction`, `register`, `getNextSequence`, `validateIntent`, `validateAddress`, `getAccountInfo`) may be omitted. The consumer contract `CoinModuleApi` is unchanged.
|
|
8
|
+
|
|
9
|
+
The method sets are published as lists with their types derived from them — `optionalApiKeys` / `OptionalApiKey`, `requiredApiKeys` / `RequiredApiKey`, and `apiMethodKeys` / `ApiMethodKey` for the contract as a whole — so the types and any runtime iteration over them share one source. A compile-time guard holds `apiMethodKeys` to the contract: a method added to `CoinModuleApi` without being listed fails to compile, so nothing that iterates the list can silently skip it.
|
|
10
|
+
|
|
11
|
+
- [#826](https://github.com/LedgerHQ/coin-modules/pull/826) [`2ec4aa4`](https://github.com/LedgerHQ/coin-modules/commit/2ec4aa48b23168e3fb846928435c1f5110b8153e) Thanks [@cted-ledger](https://github.com/cted-ledger)! - Add `withDefaults()` framework adapter: widens a `CoinModuleImpl` authoring value to the
|
|
12
|
+
full `CoinModuleApi` consumer contract by backfilling every omitted capability method with
|
|
13
|
+
a default, and exposes a `supports(method)` introspection helper.
|
|
14
|
+
|
|
15
|
+
The default depends on the method: `getAccountInfo` is backfilled with a `{ type: 'none' }`
|
|
16
|
+
sentinel, because a chain having no extra account metadata is an answer rather than a missing
|
|
17
|
+
capability (ADR-045); every other capability is backfilled with `notSupported(name)`, which
|
|
18
|
+
throws `"<name> is not supported"`. Since the sentinel is always supplied, the returned type
|
|
19
|
+
narrows `getAccountInfo` to required — callers reach it without a non-null assertion and read its
|
|
20
|
+
`type` to tell a real answer from the sentinel.
|
|
21
|
+
|
|
22
|
+
Members the authoring object carries beyond the API surface are preserved, in the returned
|
|
23
|
+
**type** as well as at runtime. Consumers that hand out an intersection — Ledger Live's resolve
|
|
24
|
+
point returns `CoinModuleApi & BridgeApi` — therefore keep the non-API half without a cast.
|
|
25
|
+
|
|
26
|
+
`notSupported()` now tags the stub it builds, and the new `isNotSupportedStub()` predicate
|
|
27
|
+
exposes that check. `withDefaults` treats a tagged stub as an omitted method, so
|
|
28
|
+
`supports()` reports a capability as available only when a real implementation was
|
|
29
|
+
supplied — a module that still fills the slot with `notSupported()` is reported as
|
|
30
|
+
unsupported. Behavior is unchanged in both cases (the same "not supported" error is
|
|
31
|
+
thrown). Only stubs built by `notSupported()` are detectable; an inline hand-rolled
|
|
32
|
+
`throw` cannot be told apart from an implementation.
|
|
33
|
+
|
|
34
|
+
- [#826](https://github.com/LedgerHQ/coin-modules/pull/826) [`2ec4aa4`](https://github.com/LedgerHQ/coin-modules/commit/2ec4aa48b23168e3fb846928435c1f5110b8153e) Thanks [@cted-ledger](https://github.com/cted-ledger)! - Add `capabilityReport()` to `@ledgerhq/coin-module-framework/test-utils`: a module's
|
|
35
|
+
unimplemented capabilities, as a consumer sees them through `withDefaults`, returned as data
|
|
36
|
+
for a single expectation.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
await expect(capabilityReport(createApi(), context)).resolves.toEqual({
|
|
40
|
+
unsupported: [
|
|
41
|
+
"call",
|
|
42
|
+
"craftRawTransaction",
|
|
43
|
+
"getRewards",
|
|
44
|
+
"getValidators",
|
|
45
|
+
"register",
|
|
46
|
+
],
|
|
47
|
+
inconsistent: [],
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
That one expectation covers what a module's api test used to spell out method by method: each
|
|
52
|
+
capability is absent, reaching it raises `"<name> is not supported"`, and `supports()` agrees.
|
|
53
|
+
`toEqual` makes it exhaustive — implementing a capability, or dropping one, changes the list, so
|
|
54
|
+
the test notices instead of silently still passing.
|
|
55
|
+
|
|
56
|
+
It reads a module authored either way: a `CoinModuleImpl` that omits its capabilities, or a
|
|
57
|
+
value built by spreading `notSupportedApi()`. Both are "not implemented" as far as `supports()`
|
|
58
|
+
is concerned, which is what this observes.
|
|
59
|
+
|
|
60
|
+
Only the capabilities `supports()` reports absent are ever invoked, so a real implementation is
|
|
61
|
+
never called and the report never reaches the network. `getAccountInfo` is excluded: per ADR-045
|
|
62
|
+
its default is the `{ type: "none" }` sentinel rather than an error. `inconsistent` is a canary —
|
|
63
|
+
it fills only if a capability reported absent does not raise its error, so it is expected empty.
|
|
64
|
+
|
|
65
|
+
The helper carries no assertion library: it returns data and the caller asserts.
|
|
66
|
+
|
|
67
|
+
- [#826](https://github.com/LedgerHQ/coin-modules/pull/826) [`2ec4aa4`](https://github.com/LedgerHQ/coin-modules/commit/2ec4aa48b23168e3fb846928435c1f5110b8153e) Thanks [@cted-ledger](https://github.com/cted-ledger)! - Add `withLogging()` and `withTracing()` composable wrappers: each takes a `CoinModuleApi`
|
|
68
|
+
and returns a `CoinModuleApi` with identical generics, applying cross-cutting instrumentation
|
|
69
|
+
(logging via `context.logger`, or tracing via a caller-supplied `Tracer`) at the consumer
|
|
70
|
+
layer. Composition `withLogging(withTracing(api, t))` is supported. Also exports
|
|
71
|
+
`instrumentApi` for building additional wrappers.
|
|
72
|
+
|
|
73
|
+
They live in their own `api/wrappers/` folder, separate from the core framework, and are
|
|
74
|
+
re-exported from `api/index` — a consumer that wants no instrumentation never reaches them.
|
|
75
|
+
|
|
76
|
+
`instrumentApi` wraps the contract's own method list (`apiMethodKeys`) eagerly, without a
|
|
77
|
+
Proxy or reflection: what gets instrumented is readable from the source, each method is
|
|
78
|
+
wrapped and bound once so nothing is allocated on the call path, and reading the same method
|
|
79
|
+
twice yields the same reference — a method stays usable as a dependency key.
|
|
80
|
+
|
|
81
|
+
Both wrappers preserve members the wrapped object carries beyond the API surface, in the
|
|
82
|
+
returned **type** as well as at runtime, so wrapping a `CoinModuleApi & BridgeApi` keeps the
|
|
83
|
+
non-API half reachable without a cast. Those extra members are copied over uninstrumented:
|
|
84
|
+
the wrapper reaches only what the contract declares.
|
|
85
|
+
|
|
86
|
+
- [#826](https://github.com/LedgerHQ/coin-modules/pull/826) [`2ec4aa4`](https://github.com/LedgerHQ/coin-modules/commit/2ec4aa48b23168e3fb846928435c1f5110b8153e) Thanks [@cted-ledger](https://github.com/cted-ledger)! - Add `notSupportedApi()`: a full `CoinModuleApi` whose every capability is a tagged
|
|
87
|
+
"not supported" stub. A module can spread it and override what its chain supports, so it
|
|
88
|
+
satisfies the complete contract directly instead of declaring a `CoinModuleImpl` and being
|
|
89
|
+
widened by `withDefaults`.
|
|
90
|
+
|
|
91
|
+
The two authoring styles interoperate rather than compete. Because the stubs are tagged,
|
|
92
|
+
a value built this way still reports the truth through `withDefaults`'s `supports()` — a
|
|
93
|
+
spread stub counts as an omitted method, not as an implementation — so a module may be
|
|
94
|
+
authored either way and reports the same capabilities to a consumer.
|
|
95
|
+
|
|
96
|
+
It is also what a module can use when it does not implement everything the authoring type
|
|
97
|
+
requires: a read-only module, or a chain with no crafting path. `getAccountInfo` resolves
|
|
98
|
+
the ADR-045 `{ type: 'none' }` sentinel rather than throwing, and `listFeeOptions` is left
|
|
99
|
+
absent, both matching `withDefaults`.
|
|
100
|
+
|
|
3
101
|
## 8.1.0
|
|
4
102
|
|
|
5
103
|
### Minor Changes
|
|
@@ -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"}
|
package/lib/api/impl.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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.apiMethodKeys = exports.requiredApiKeys = exports.optionalApiKeys = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* Methods a CoinModuleImpl author may omit when the chain does not support them.
|
|
8
|
+
* The framework's `withDefaults` fills the gaps before the consumer receives the
|
|
9
|
+
* object as a full {@link CoinModuleApi}.
|
|
10
|
+
*
|
|
11
|
+
* Block — getBlock, getBlockInfo (many chains throw "not supported")
|
|
12
|
+
* Staking — getStakes, getRewards, (à la carte; a module may ship getStakes
|
|
13
|
+
* getValidators without getValidators)
|
|
14
|
+
* SmartContract— call (optional escape-hatch)
|
|
15
|
+
* RawCrafting — craftRawTransaction (not all chains accept externally-built txs)
|
|
16
|
+
* Enrollment — register (optional indexer backend)
|
|
17
|
+
* Sequence — getNextSequence (some chains have no sequence/nonce concept)
|
|
18
|
+
* Validation — validateIntent, (some chains cannot fully validate intents
|
|
19
|
+
* validateAddress or addresses without a network round-trip)
|
|
20
|
+
* AccountInfo — getAccountInfo (chain-specific account metadata; absent means
|
|
21
|
+
* "nothing to report", not "unsupported")
|
|
22
|
+
*/
|
|
23
|
+
exports.optionalApiKeys = [
|
|
24
|
+
'getBlock',
|
|
25
|
+
'getBlockInfo',
|
|
26
|
+
'getStakes',
|
|
27
|
+
'getRewards',
|
|
28
|
+
'getValidators',
|
|
29
|
+
'call',
|
|
30
|
+
'craftRawTransaction',
|
|
31
|
+
'register',
|
|
32
|
+
'getNextSequence',
|
|
33
|
+
'validateIntent',
|
|
34
|
+
'validateAddress',
|
|
35
|
+
'getAccountInfo',
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Methods every {@link CoinModuleImpl} author must implement: the minimum a chain has to
|
|
39
|
+
* expose for the module to be usable at all. Complement of {@link optionalApiKeys}.
|
|
40
|
+
*/
|
|
41
|
+
exports.requiredApiKeys = [
|
|
42
|
+
'lastBlock',
|
|
43
|
+
'getBalance',
|
|
44
|
+
'listOperations',
|
|
45
|
+
'craftTransaction',
|
|
46
|
+
'estimateFees',
|
|
47
|
+
'combine',
|
|
48
|
+
'broadcast',
|
|
49
|
+
'craftTransactionData',
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Every method the {@link CoinModuleApi} contract declares.
|
|
53
|
+
*
|
|
54
|
+
* Wrappers iterate this list to instrument an API without reflecting over the object at
|
|
55
|
+
* runtime, so what they touch is fixed and readable rather than "whatever is a function".
|
|
56
|
+
* `listFeeOptions` is neither required nor omittable — the contract itself declares it
|
|
57
|
+
* optional and `withDefaults` does not backfill it — hence its place here and nowhere else.
|
|
58
|
+
*/
|
|
59
|
+
exports.apiMethodKeys = [...exports.requiredApiKeys, ...exports.optionalApiKeys, 'listFeeOptions'];
|
|
60
|
+
//# sourceMappingURL=impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impl.js","sourceRoot":"","sources":["../../src/api/impl.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;AAKtC;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,cAAc;IACd,WAAW;IACX,YAAY;IACZ,eAAe;IACf,MAAM;IACN,qBAAqB;IACrB,UAAU;IACV,iBAAiB;IACjB,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;CACR,CAAA;AAUV;;;GAGG;AACU,QAAA,eAAe,GAAG;IAC7B,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,kBAAkB;IAClB,cAAc;IACd,SAAS;IACT,WAAW;IACX,sBAAsB;CACd,CAAA;AAKV;;;;;;;GAOG;AACU,QAAA,aAAa,GAAG,CAAC,GAAG,uBAAe,EAAE,GAAG,uBAAe,EAAE,gBAAgB,CAAU,CAAA"}
|
package/lib/api/index.d.ts
CHANGED
|
@@ -4,5 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export * from './errors';
|
|
6
6
|
export * from './notSupported';
|
|
7
|
+
export * from './notSupportedApi';
|
|
7
8
|
export * from './types';
|
|
9
|
+
export * from './impl';
|
|
10
|
+
export * from './withDefaults';
|
|
11
|
+
export * from './wrappers/index';
|
|
8
12
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAEH,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAEH,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
|
package/lib/api/index.js
CHANGED
|
@@ -22,5 +22,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
*/
|
|
23
23
|
__exportStar(require("./errors"), exports);
|
|
24
24
|
__exportStar(require("./notSupported"), exports);
|
|
25
|
+
__exportStar(require("./notSupportedApi"), exports);
|
|
25
26
|
__exportStar(require("./types"), exports);
|
|
27
|
+
__exportStar(require("./impl"), exports);
|
|
28
|
+
__exportStar(require("./withDefaults"), exports);
|
|
29
|
+
__exportStar(require("./wrappers/index"), exports);
|
|
26
30
|
//# sourceMappingURL=index.js.map
|
package/lib/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;;;;;;;;;;;;AAEtC;;;GAGG;AAEH,2CAAwB;AACxB,iDAA8B;AAC9B,0CAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;;;;;;;;;;;;AAEtC;;;GAGG;AAEH,2CAAwB;AACxB,iDAA8B;AAC9B,oDAAiC;AACjC,0CAAuB;AACvB,yCAAsB;AACtB,iDAA8B;AAC9B,mDAAgC"}
|
|
@@ -2,8 +2,22 @@
|
|
|
2
2
|
* Build a {@link CoinModuleApi} method stub that always throws a standardized
|
|
3
3
|
* "not supported" error. Use it for optional API methods a module does not implement.
|
|
4
4
|
*
|
|
5
|
+
* The returned function is tagged so the framework can tell it apart from a real
|
|
6
|
+
* implementation — see {@link isNotSupportedStub}.
|
|
7
|
+
*
|
|
5
8
|
* @param name the API method name, used in the error message
|
|
6
9
|
* @returns a function that throws `"<name> is not supported"` when invoked
|
|
7
10
|
*/
|
|
8
11
|
export declare const notSupported: (name: string) => () => never;
|
|
12
|
+
/**
|
|
13
|
+
* Tells whether a value is a stub produced by {@link notSupported}, i.e. a placeholder
|
|
14
|
+
* rather than a real implementation.
|
|
15
|
+
*
|
|
16
|
+
* **Limitation** — only stubs built by {@link notSupported} are detectable. A module that
|
|
17
|
+
* hand-rolls `() => { throw new Error('x is not supported') }` inline is indistinguishable
|
|
18
|
+
* from a real implementation, because whether a function throws cannot be known without
|
|
19
|
+
* calling it. Modules should therefore either omit an unsupported method entirely (the
|
|
20
|
+
* migrated shape) or build its stub with {@link notSupported}.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isNotSupportedStub(value: unknown): boolean;
|
|
9
23
|
//# sourceMappingURL=notSupported.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notSupported.d.ts","sourceRoot":"","sources":["../../src/api/notSupported.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"notSupported.d.ts","sourceRoot":"","sources":["../../src/api/notSupported.ts"],"names":[],"mappings":"AAYA;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,WACtB,KAKlB,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE1D"}
|
package/lib/api/notSupported.js
CHANGED
|
@@ -3,15 +3,44 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.notSupported = void 0;
|
|
6
|
+
exports.isNotSupportedStub = isNotSupportedStub;
|
|
7
|
+
/**
|
|
8
|
+
* Marks a function as a framework-built "not supported" stub.
|
|
9
|
+
*
|
|
10
|
+
* `Symbol.for` (the global registry) is used deliberately: in a monorepo the framework
|
|
11
|
+
* may be present as more than one physical module instance, and a locally-scoped symbol
|
|
12
|
+
* would not match across them.
|
|
13
|
+
*/
|
|
14
|
+
const NOT_SUPPORTED_STUB = Symbol.for('@ledgerhq/coin-module-framework:notSupportedStub');
|
|
6
15
|
/**
|
|
7
16
|
* Build a {@link CoinModuleApi} method stub that always throws a standardized
|
|
8
17
|
* "not supported" error. Use it for optional API methods a module does not implement.
|
|
9
18
|
*
|
|
19
|
+
* The returned function is tagged so the framework can tell it apart from a real
|
|
20
|
+
* implementation — see {@link isNotSupportedStub}.
|
|
21
|
+
*
|
|
10
22
|
* @param name the API method name, used in the error message
|
|
11
23
|
* @returns a function that throws `"<name> is not supported"` when invoked
|
|
12
24
|
*/
|
|
13
|
-
const notSupported = (name) =>
|
|
14
|
-
|
|
25
|
+
const notSupported = (name) => {
|
|
26
|
+
const stub = () => {
|
|
27
|
+
throw new Error(`${name} is not supported`);
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(stub, NOT_SUPPORTED_STUB, { value: true, enumerable: false });
|
|
30
|
+
return stub;
|
|
15
31
|
};
|
|
16
32
|
exports.notSupported = notSupported;
|
|
33
|
+
/**
|
|
34
|
+
* Tells whether a value is a stub produced by {@link notSupported}, i.e. a placeholder
|
|
35
|
+
* rather than a real implementation.
|
|
36
|
+
*
|
|
37
|
+
* **Limitation** — only stubs built by {@link notSupported} are detectable. A module that
|
|
38
|
+
* hand-rolls `() => { throw new Error('x is not supported') }` inline is indistinguishable
|
|
39
|
+
* from a real implementation, because whether a function throws cannot be known without
|
|
40
|
+
* calling it. Modules should therefore either omit an unsupported method entirely (the
|
|
41
|
+
* migrated shape) or build its stub with {@link notSupported}.
|
|
42
|
+
*/
|
|
43
|
+
function isNotSupportedStub(value) {
|
|
44
|
+
return typeof value === 'function' && NOT_SUPPORTED_STUB in value;
|
|
45
|
+
}
|
|
17
46
|
//# sourceMappingURL=notSupported.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notSupported.js","sourceRoot":"","sources":["../../src/api/notSupported.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;
|
|
1
|
+
{"version":3,"file":"notSupported.js","sourceRoot":"","sources":["../../src/api/notSupported.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;AAuCtC,gDAEC;AAvCD;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAA;AAEzF;;;;;;;;;GASG;AACI,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE;IAC3C,MAAM,IAAI,GAAG,GAAU,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAA;IAC7C,CAAC,CAAA;IACD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;IACnF,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AANY,QAAA,YAAY,gBAMxB;AAED;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,OAAO,KAAK,KAAK,UAAU,IAAI,kBAAkB,IAAI,KAAK,CAAA;AACnE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CurrencyConfig } from '../config';
|
|
2
|
+
import type { CoinModuleApi, Memo, MemoNotSupported, TxData, TxDataNotSupported } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A full {@link CoinModuleApi} whose every capability is a "not supported" stub.
|
|
5
|
+
*
|
|
6
|
+
* Spread it and override what the chain does support, for a module that would rather
|
|
7
|
+
* satisfy the complete contract directly than declare a `CoinModuleImpl` and be widened by
|
|
8
|
+
* `withDefaults`:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* export function createApi() {
|
|
12
|
+
* return {
|
|
13
|
+
* ...notSupportedApi<MyConfig>(),
|
|
14
|
+
* lastBlock, getBalance, listOperations,
|
|
15
|
+
* } satisfies CoinModuleApi<MyConfig>
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* The two styles interoperate rather than compete, because the stubs are tagged: a value
|
|
20
|
+
* built this way still tells the truth through `withDefaults`'s `supports()`, which treats a
|
|
21
|
+
* tagged stub as an omitted method rather than as an implementation. So a module may be
|
|
22
|
+
* authored either way, wrapped either way, and reports the same capabilities.
|
|
23
|
+
*
|
|
24
|
+
* It is also what a module can use when it does not implement everything the authoring type
|
|
25
|
+
* requires — a read-only module, or a chain with no crafting path. The contract is satisfied
|
|
26
|
+
* statically, and what the chain does not do stays visible at the definition site.
|
|
27
|
+
*
|
|
28
|
+
* `getAccountInfo` is the one method that does not throw: per ADR-045 a chain carrying no
|
|
29
|
+
* extra account metadata is an answer, not a missing capability, so it resolves the
|
|
30
|
+
* `{ type: 'none' }` sentinel — the same default `withDefaults` supplies. `listFeeOptions` is
|
|
31
|
+
* left absent, likewise matching `withDefaults`.
|
|
32
|
+
*
|
|
33
|
+
* The return type is the contract itself, so a method added to `CoinModuleApi` makes this
|
|
34
|
+
* fail to compile until it is covered here.
|
|
35
|
+
*/
|
|
36
|
+
export declare function notSupportedApi<ConfigType extends CurrencyConfig, MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported>(): CoinModuleApi<ConfigType, MemoType, TxDataType>;
|
|
37
|
+
//# sourceMappingURL=notSupportedApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notSupportedApi.d.ts","sourceRoot":"","sources":["../../src/api/notSupportedApi.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;AAGhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAC7B,UAAU,SAAS,cAAc,EACjC,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,KAC3C,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CA6BnD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.notSupportedApi = notSupportedApi;
|
|
6
|
+
const notSupported_1 = require("./notSupported");
|
|
7
|
+
/**
|
|
8
|
+
* A full {@link CoinModuleApi} whose every capability is a "not supported" stub.
|
|
9
|
+
*
|
|
10
|
+
* Spread it and override what the chain does support, for a module that would rather
|
|
11
|
+
* satisfy the complete contract directly than declare a `CoinModuleImpl` and be widened by
|
|
12
|
+
* `withDefaults`:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* export function createApi() {
|
|
16
|
+
* return {
|
|
17
|
+
* ...notSupportedApi<MyConfig>(),
|
|
18
|
+
* lastBlock, getBalance, listOperations,
|
|
19
|
+
* } satisfies CoinModuleApi<MyConfig>
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The two styles interoperate rather than compete, because the stubs are tagged: a value
|
|
24
|
+
* built this way still tells the truth through `withDefaults`'s `supports()`, which treats a
|
|
25
|
+
* tagged stub as an omitted method rather than as an implementation. So a module may be
|
|
26
|
+
* authored either way, wrapped either way, and reports the same capabilities.
|
|
27
|
+
*
|
|
28
|
+
* It is also what a module can use when it does not implement everything the authoring type
|
|
29
|
+
* requires — a read-only module, or a chain with no crafting path. The contract is satisfied
|
|
30
|
+
* statically, and what the chain does not do stays visible at the definition site.
|
|
31
|
+
*
|
|
32
|
+
* `getAccountInfo` is the one method that does not throw: per ADR-045 a chain carrying no
|
|
33
|
+
* extra account metadata is an answer, not a missing capability, so it resolves the
|
|
34
|
+
* `{ type: 'none' }` sentinel — the same default `withDefaults` supplies. `listFeeOptions` is
|
|
35
|
+
* left absent, likewise matching `withDefaults`.
|
|
36
|
+
*
|
|
37
|
+
* The return type is the contract itself, so a method added to `CoinModuleApi` makes this
|
|
38
|
+
* fail to compile until it is covered here.
|
|
39
|
+
*/
|
|
40
|
+
function notSupportedApi() {
|
|
41
|
+
return {
|
|
42
|
+
// Required by the authoring type — a module spreading this one must override them to
|
|
43
|
+
// be functional at all; they are stubbed here so the contract is satisfied statically.
|
|
44
|
+
lastBlock: (0, notSupported_1.notSupported)('lastBlock'),
|
|
45
|
+
getBalance: (0, notSupported_1.notSupported)('getBalance'),
|
|
46
|
+
listOperations: (0, notSupported_1.notSupported)('listOperations'),
|
|
47
|
+
craftTransaction: (0, notSupported_1.notSupported)('craftTransaction'),
|
|
48
|
+
estimateFees: (0, notSupported_1.notSupported)('estimateFees'),
|
|
49
|
+
combine: (0, notSupported_1.notSupported)('combine'),
|
|
50
|
+
broadcast: (0, notSupported_1.notSupported)('broadcast'),
|
|
51
|
+
craftTransactionData: (0, notSupported_1.notSupported)('craftTransactionData'),
|
|
52
|
+
// Optional capabilities.
|
|
53
|
+
getBlock: (0, notSupported_1.notSupported)('getBlock'),
|
|
54
|
+
getBlockInfo: (0, notSupported_1.notSupported)('getBlockInfo'),
|
|
55
|
+
getStakes: (0, notSupported_1.notSupported)('getStakes'),
|
|
56
|
+
getRewards: (0, notSupported_1.notSupported)('getRewards'),
|
|
57
|
+
getValidators: (0, notSupported_1.notSupported)('getValidators'),
|
|
58
|
+
call: (0, notSupported_1.notSupported)('call'),
|
|
59
|
+
craftRawTransaction: (0, notSupported_1.notSupported)('craftRawTransaction'),
|
|
60
|
+
register: (0, notSupported_1.notSupported)('register'),
|
|
61
|
+
getNextSequence: (0, notSupported_1.notSupported)('getNextSequence'),
|
|
62
|
+
validateIntent: (0, notSupported_1.notSupported)('validateIntent'),
|
|
63
|
+
validateAddress: (0, notSupported_1.notSupported)('validateAddress'),
|
|
64
|
+
// Not a capability: absent metadata is an answer (ADR-045).
|
|
65
|
+
getAccountInfo: () => Promise.resolve({ type: 'none' }),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=notSupportedApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notSupportedApi.js","sourceRoot":"","sources":["../../src/api/notSupportedApi.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAuCtC,0CAiCC;AApED,iDAA6C;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,SAAgB,eAAe;IAK7B,OAAO;QACL,qFAAqF;QACrF,uFAAuF;QACvF,SAAS,EAAE,IAAA,2BAAY,EAAC,WAAW,CAAC;QACpC,UAAU,EAAE,IAAA,2BAAY,EAAC,YAAY,CAAC;QACtC,cAAc,EAAE,IAAA,2BAAY,EAAC,gBAAgB,CAAC;QAC9C,gBAAgB,EAAE,IAAA,2BAAY,EAAC,kBAAkB,CAAC;QAClD,YAAY,EAAE,IAAA,2BAAY,EAAC,cAAc,CAAC;QAC1C,OAAO,EAAE,IAAA,2BAAY,EAAC,SAAS,CAAC;QAChC,SAAS,EAAE,IAAA,2BAAY,EAAC,WAAW,CAAC;QACpC,oBAAoB,EAAE,IAAA,2BAAY,EAAC,sBAAsB,CAAC;QAE1D,yBAAyB;QACzB,QAAQ,EAAE,IAAA,2BAAY,EAAC,UAAU,CAAC;QAClC,YAAY,EAAE,IAAA,2BAAY,EAAC,cAAc,CAAC;QAC1C,SAAS,EAAE,IAAA,2BAAY,EAAC,WAAW,CAAC;QACpC,UAAU,EAAE,IAAA,2BAAY,EAAC,YAAY,CAAC;QACtC,aAAa,EAAE,IAAA,2BAAY,EAAC,eAAe,CAAC;QAC5C,IAAI,EAAE,IAAA,2BAAY,EAAC,MAAM,CAAC;QAC1B,mBAAmB,EAAE,IAAA,2BAAY,EAAC,qBAAqB,CAAC;QACxD,QAAQ,EAAE,IAAA,2BAAY,EAAC,UAAU,CAAC;QAClC,eAAe,EAAE,IAAA,2BAAY,EAAC,iBAAiB,CAAC;QAChD,cAAc,EAAE,IAAA,2BAAY,EAAC,gBAAgB,CAAC;QAC9C,eAAe,EAAE,IAAA,2BAAY,EAAC,iBAAiB,CAAC;QAEhD,4DAA4D;QAC5D,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KACxD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CurrencyConfig } from '../config';
|
|
2
|
+
import type { CoinModuleImpl, OptionalApiKey } from './impl';
|
|
3
|
+
import type { CoinModuleApi, Memo, MemoNotSupported, TxData, TxDataNotSupported } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* What {@link withDefaults} returns: the full consumer contract, plus `supports()`.
|
|
6
|
+
*
|
|
7
|
+
* `getAccountInfo` is narrowed to required. It is the one managed capability that
|
|
8
|
+
* {@link CoinModuleApi} itself declares optional, and `withDefaults` always supplies it — so
|
|
9
|
+
* callers can invoke it without a non-null assertion, and read `type` to tell a real answer from
|
|
10
|
+
* the `{ type: 'none' }` sentinel.
|
|
11
|
+
*/
|
|
12
|
+
export type WithDefaultsResult<ConfigType extends CurrencyConfig, MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported> = CoinModuleApi<ConfigType, MemoType, TxDataType> & Required<Pick<CoinModuleApi<ConfigType, MemoType, TxDataType>, 'getAccountInfo'>> & {
|
|
13
|
+
supports: (method: OptionalApiKey) => boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Widens a {@link CoinModuleImpl} authoring value to the full {@link CoinModuleApi}
|
|
17
|
+
* consumer contract by backfilling the capability methods the author omitted, and attaches
|
|
18
|
+
* a `supports()` introspection helper.
|
|
19
|
+
*
|
|
20
|
+
* Default per omitted method:
|
|
21
|
+
* - `getAccountInfo` → a `{ type: 'none' }` sentinel (ADR-045): having no extra account
|
|
22
|
+
* metadata is an answer, so callers get one instead of an exception.
|
|
23
|
+
* - every other capability → `notSupported(name)`, which throws `"<name> is not supported"`.
|
|
24
|
+
*
|
|
25
|
+
* Properties the authoring object carries beyond the API surface are preserved.
|
|
26
|
+
*
|
|
27
|
+
* A capability method is considered implemented only when the author supplied a real
|
|
28
|
+
* function — a `notSupported()` stub is treated as if the method had been omitted.
|
|
29
|
+
*/
|
|
30
|
+
export declare function withDefaults<ConfigType extends CurrencyConfig, MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported, Extra extends object = Record<never, never>>(impl: CoinModuleImpl<ConfigType, MemoType, TxDataType> & Extra): WithDefaultsResult<ConfigType, MemoType, TxDataType> & Extra;
|
|
31
|
+
//# sourceMappingURL=withDefaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withDefaults.d.ts","sourceRoot":"","sources":["../../src/api/withDefaults.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIhG;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,CAC5B,UAAU,SAAS,cAAc,EACjC,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,IAC5C,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,GACjD,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAC,GAAG;IAClF,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAA;CAC9C,CAAA;AAaH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,UAAU,SAAS,cAAc,EACjC,QAAQ,SAAS,IAAI,GAAG,gBAAgB,EACxC,UAAU,SAAS,MAAM,GAAG,kBAAkB,EAC9C,KAAK,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE3C,IAAI,EAAE,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,GAAG,KAAK,GAC7D,kBAAkB,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,GAAG,KAAK,CA2B9D"}
|
|
@@ -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"}
|