@certen.io/sdk 0.9.0 → 0.10.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 +73 -0
- package/README.md +81 -0
- package/dist/agent.d.ts +8 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +12 -0
- package/dist/agent.js.map +1 -1
- package/dist/browser.d.ts +34 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +43 -0
- package/dist/browser.js.map +1 -0
- package/dist/bytes.d.ts +14 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +47 -0
- package/dist/bytes.js.map +1 -0
- package/dist/chains.d.ts +198 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +261 -0
- package/dist/chains.js.map +1 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +38 -6
- package/dist/client.js.map +1 -1
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +3 -0
- package/dist/defaults.js.map +1 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +36 -23
- package/dist/doctor.js.map +1 -1
- package/dist/error-codes.d.ts.map +1 -1
- package/dist/error-codes.js +17 -0
- package/dist/error-codes.js.map +1 -1
- package/dist/errors.d.ts +76 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +108 -0
- package/dist/errors.js.map +1 -1
- package/dist/execution-proof.d.ts.map +1 -1
- package/dist/execution-proof.js +2 -1
- package/dist/execution-proof.js.map +1 -1
- package/dist/funding.d.ts +43 -6
- package/dist/funding.d.ts.map +1 -1
- package/dist/funding.js +69 -29
- package/dist/funding.js.map +1 -1
- package/dist/header-fields.d.ts +68 -0
- package/dist/header-fields.d.ts.map +1 -0
- package/dist/header-fields.js +147 -0
- package/dist/header-fields.js.map +1 -0
- package/dist/index.d.ts +9 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -26
- package/dist/index.js.map +1 -1
- package/dist/intent-states.d.ts +75 -0
- package/dist/intent-states.d.ts.map +1 -0
- package/dist/intent-states.js +66 -0
- package/dist/intent-states.js.map +1 -0
- package/dist/internal.d.ts +18 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +44 -0
- package/dist/internal.js.map +1 -1
- package/dist/origin.d.ts +19 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +80 -0
- package/dist/origin.js.map +1 -0
- package/dist/random.d.ts +27 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +30 -0
- package/dist/random.js.map +1 -0
- package/dist/reason-codes.d.ts +15 -0
- package/dist/reason-codes.d.ts.map +1 -0
- package/dist/reason-codes.js +30 -0
- package/dist/reason-codes.js.map +1 -0
- package/dist/resources/admin.d.ts +5 -2
- package/dist/resources/admin.d.ts.map +1 -1
- package/dist/resources/admin.js +8 -3
- package/dist/resources/admin.js.map +1 -1
- package/dist/resources/billing.d.ts.map +1 -1
- package/dist/resources/billing.js +5 -4
- package/dist/resources/billing.js.map +1 -1
- package/dist/resources/chains.d.ts +10 -0
- package/dist/resources/chains.d.ts.map +1 -1
- package/dist/resources/chains.js +15 -1
- package/dist/resources/chains.js.map +1 -1
- package/dist/resources/device.d.ts.map +1 -1
- package/dist/resources/device.js +2 -1
- package/dist/resources/device.js.map +1 -1
- package/dist/resources/execute.d.ts +49 -4
- package/dist/resources/execute.d.ts.map +1 -1
- package/dist/resources/execute.js +108 -29
- package/dist/resources/execute.js.map +1 -1
- package/dist/resources/governance.js +3 -3
- package/dist/resources/governance.js.map +1 -1
- package/dist/resources/identity.js +5 -5
- package/dist/resources/identity.js.map +1 -1
- package/dist/resources/oauth-clients.d.ts.map +1 -1
- package/dist/resources/oauth-clients.js +3 -2
- package/dist/resources/oauth-clients.js.map +1 -1
- package/dist/resources/proof.d.ts +10 -2
- package/dist/resources/proof.d.ts.map +1 -1
- package/dist/resources/proof.js +33 -11
- package/dist/resources/proof.js.map +1 -1
- package/dist/resources/registration-tokens.d.ts.map +1 -1
- package/dist/resources/registration-tokens.js +2 -1
- package/dist/resources/registration-tokens.js.map +1 -1
- package/dist/resources/sign.js +2 -2
- package/dist/resources/sign.js.map +1 -1
- package/dist/resources/transaction.d.ts.map +1 -1
- package/dist/resources/transaction.js +7 -3
- package/dist/resources/transaction.js.map +1 -1
- package/dist/resources/transparency.d.ts.map +1 -1
- package/dist/resources/transparency.js +3 -2
- package/dist/resources/transparency.js.map +1 -1
- package/dist/resources/webhooks.d.ts +5 -3
- package/dist/resources/webhooks.d.ts.map +1 -1
- package/dist/resources/webhooks.js +12 -8
- package/dist/resources/webhooks.js.map +1 -1
- package/dist/sha256.d.ts +10 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/sha256.js +71 -0
- package/dist/sha256.js.map +1 -0
- package/dist/share-target.d.ts +10 -0
- package/dist/share-target.d.ts.map +1 -0
- package/dist/share-target.js +25 -0
- package/dist/share-target.js.map +1 -0
- package/dist/shared-proof.d.ts +1 -5
- package/dist/shared-proof.d.ts.map +1 -1
- package/dist/shared-proof.js +6 -20
- package/dist/shared-proof.js.map +1 -1
- package/dist/signing-check.d.ts +66 -0
- package/dist/signing-check.d.ts.map +1 -0
- package/dist/signing-check.js +171 -0
- package/dist/signing-check.js.map +1 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/verify-receipt.d.ts.map +1 -1
- package/dist/verify-receipt.js +68 -28
- package/dist/verify-receipt.js.map +1 -1
- package/dist/verify.d.ts +82 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +180 -0
- package/dist/verify.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +25 -7
package/dist/chains.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chain catalogue: the one place this SDK, the CLI and the MCP server learn what a chain IS.
|
|
3
|
+
*
|
|
4
|
+
* Before this file the same facts lived in five tables — the CLI's supported list, its alias map,
|
|
5
|
+
* its numeric-id map, its block-time table and its faucet table, plus two copies of a numeric-id
|
|
6
|
+
* map in the SDK — and they had already drifted (the SDK knew five chains, the CLI three). Every
|
|
7
|
+
* native-balance check also assumed the gas token was called `ETH`, which on a chain whose gas is
|
|
8
|
+
* not ETH made the funding guards pass without looking. Each of those is now derived from here.
|
|
9
|
+
*
|
|
10
|
+
* **What this table is, and what it is not.**
|
|
11
|
+
*
|
|
12
|
+
* - It is static on purpose. Normalizing a numeric `chain_id`, naming the gas token, estimating a
|
|
13
|
+
* wait and validating a flag must all work offline and on a first run.
|
|
14
|
+
* - It does NOT decide what is enabled on its own. A chain is offered only when it is enabled in
|
|
15
|
+
* configuration AND the gateway serves it (`GET /v1/chains`): see {@link resolveEnabledChains}.
|
|
16
|
+
* The catalogue's `enabledByDefault` is only the configuration default.
|
|
17
|
+
* - A `retired` entry is kept for reading: an older gateway may still return its numeric id in a
|
|
18
|
+
* portfolio, and dropping it would make that row unrecognisable. A retired chain is never
|
|
19
|
+
* offered and cannot be enabled.
|
|
20
|
+
*/
|
|
21
|
+
export type ChainSupport = 'live' | 'opt-in' | 'retired';
|
|
22
|
+
export interface ChainCatalogueEntry {
|
|
23
|
+
/** Registry slug, as `GET /v1/chains` names it. */
|
|
24
|
+
readonly slug: string;
|
|
25
|
+
/** Numeric EVM chain id (EIP-155). */
|
|
26
|
+
readonly chainId: number;
|
|
27
|
+
readonly displayName: string;
|
|
28
|
+
readonly environment: 'testnet';
|
|
29
|
+
/** The native gas token's symbol as the gateway's portfolio reports it, e.g. `ETH`, `TEL`. */
|
|
30
|
+
readonly nativeSymbol: string;
|
|
31
|
+
readonly nativeDecimals: number;
|
|
32
|
+
/**
|
|
33
|
+
* Typical seconds per block, for turning a confirmation count into an estimate a person can plan
|
|
34
|
+
* around. Never a promise; see `blocksOnlyWithTraffic`.
|
|
35
|
+
*/
|
|
36
|
+
readonly blockSeconds: number;
|
|
37
|
+
/**
|
|
38
|
+
* The chain produces a block only when there is a transaction to put in it. A confirmation count
|
|
39
|
+
* on such a chain is not a measure of time at all when it is idle, so every estimate built on
|
|
40
|
+
* `blockSeconds` is a lower bound and must be presented as one.
|
|
41
|
+
*/
|
|
42
|
+
readonly blocksOnlyWithTraffic: boolean;
|
|
43
|
+
/** Where to get testnet gas. Absent rather than guessed. */
|
|
44
|
+
readonly faucet?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Names people type for this chain that are NOT its slug. They SUGGEST and never substitute: a
|
|
47
|
+
* mainnet name mapped silently to a testnet would be the client deciding where money goes.
|
|
48
|
+
*/
|
|
49
|
+
readonly aliases: readonly string[];
|
|
50
|
+
readonly support: ChainSupport;
|
|
51
|
+
/** Enabled when configuration says nothing. True only for `live` chains. */
|
|
52
|
+
readonly enabledByDefault: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Every chain this SDK knows. Order is the order chains are listed to a person.
|
|
56
|
+
*
|
|
57
|
+
* Facts verified 2026-10-05 against chainid.network and, for Telcoin Adiri, against the chain's
|
|
58
|
+
* own RPC (`eth_chainId` = 0x7e1). Adiri's block cadence was measured over its last 6000 blocks:
|
|
59
|
+
* blocks appear only when there is a transaction, and active blocks cluster 7–16 s apart.
|
|
60
|
+
*/
|
|
61
|
+
export declare const CHAIN_CATALOGUE: readonly ChainCatalogueEntry[];
|
|
62
|
+
/** The catalogue entry for a slug or a numeric chain id (either spelling), or undefined. */
|
|
63
|
+
export declare function chainInfo(value: string | number | null | undefined): ChainCatalogueEntry | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Resolve whatever the gateway called a chain into its slug.
|
|
66
|
+
*
|
|
67
|
+
* A numeric id the catalogue knows becomes its slug. Anything else is returned unchanged (trimmed):
|
|
68
|
+
* a value we cannot map is still the best label we have for it, and inventing one would be worse.
|
|
69
|
+
*/
|
|
70
|
+
export declare function chainSlug(value: string | number | null | undefined): string;
|
|
71
|
+
/** The native gas token's symbol, or undefined when the catalogue does not know the chain. */
|
|
72
|
+
export declare function nativeSymbolFor(chain: string | number | null | undefined): string | undefined;
|
|
73
|
+
export declare function faucetForChain(chain: string | number | null | undefined): string | undefined;
|
|
74
|
+
/** Slugs the catalogue enables when configuration says nothing: the live chains, in order. */
|
|
75
|
+
export declare function defaultEnabledChains(): string[];
|
|
76
|
+
/** Slugs that configuration may enable: everything not retired. */
|
|
77
|
+
export declare function enablableChains(): string[];
|
|
78
|
+
/** Thrown when configuration names a chain that cannot be enabled. */
|
|
79
|
+
export declare class ChainConfigurationError extends Error {
|
|
80
|
+
readonly chain: string;
|
|
81
|
+
constructor(chain: string, message: string);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parse an enabled-chains setting (e.g. `CERTEN_ENABLED_CHAINS`): a comma-separated list of slugs
|
|
85
|
+
* or numeric ids that REPLACES the default set.
|
|
86
|
+
*
|
|
87
|
+
* Unset or blank means the default set. Every name must be a catalogue chain that is not retired;
|
|
88
|
+
* anything else is refused by name — an enable switch that quietly ignored a typo would leave a
|
|
89
|
+
* person believing a chain was on.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseEnabledChains(setting: string | undefined | null): string[];
|
|
92
|
+
/** The part of a `GET /v1/chains` entry this module reads. */
|
|
93
|
+
export interface ServedChain {
|
|
94
|
+
id: string;
|
|
95
|
+
chainId?: number | null;
|
|
96
|
+
/**
|
|
97
|
+
* The gateway's enable switch for this chain. A gateway that follows the contract lists EVERY catalogue chain with an explicit
|
|
98
|
+
* boolean, so `false` means "exists, switched off" (`chain_not_enabled`) and a chain that is not listed at all means "the gateway
|
|
99
|
+
* does not know it" (`unknown_chain`). An entry with no `enabled` field comes from a gateway that listed only the chains it
|
|
100
|
+
* served, and is treated as enabled.
|
|
101
|
+
*/
|
|
102
|
+
enabled?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/** Does the gateway serve this entry? Listed, and not explicitly disabled. */
|
|
105
|
+
export declare function gatewayServes(entry: ServedChain): boolean;
|
|
106
|
+
export type ChainAvailability = {
|
|
107
|
+
state: 'enabled';
|
|
108
|
+
chain: ChainCatalogueEntry;
|
|
109
|
+
} | {
|
|
110
|
+
state: 'unknown';
|
|
111
|
+
chain: string;
|
|
112
|
+
} | {
|
|
113
|
+
state: 'retired';
|
|
114
|
+
chain: ChainCatalogueEntry;
|
|
115
|
+
} | {
|
|
116
|
+
state: 'not-configured';
|
|
117
|
+
chain: ChainCatalogueEntry;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The gateway's list does not contain this chain. To the gateway it is an unknown chain (`unknown_chain`). This is NOT "disabled":
|
|
121
|
+
* omission and an explicit `enabled: false` are different facts and a caller acts differently on each.
|
|
122
|
+
*/
|
|
123
|
+
| {
|
|
124
|
+
state: 'unlisted';
|
|
125
|
+
chain: ChainCatalogueEntry;
|
|
126
|
+
code: 'unknown_chain';
|
|
127
|
+
}
|
|
128
|
+
/** The gateway lists this chain with `enabled: false`: it exists and is switched off (`chain_not_enabled`). */
|
|
129
|
+
| {
|
|
130
|
+
state: 'disabled';
|
|
131
|
+
chain: ChainCatalogueEntry;
|
|
132
|
+
code: 'chain_not_enabled';
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Is `chain` available to use, given the configured set and (when known) what the gateway serves?
|
|
136
|
+
*
|
|
137
|
+
* `served` undefined means "the gateway has not been asked": the configured set alone decides,
|
|
138
|
+
* which is what an offline client can know. Passing the gateway's list narrows it — the client
|
|
139
|
+
* never offers a chain the gateway does not serve.
|
|
140
|
+
*/
|
|
141
|
+
export declare function chainAvailability(chain: string | number, configured: readonly string[], served?: readonly ServedChain[]): ChainAvailability;
|
|
142
|
+
/**
|
|
143
|
+
* The chains to offer: configured ∩ served, in catalogue order.
|
|
144
|
+
*
|
|
145
|
+
* `served` undefined means the gateway was not consulted, and the configured set is returned.
|
|
146
|
+
*/
|
|
147
|
+
export declare function resolveEnabledChains(configured?: readonly string[], served?: readonly ServedChain[]): ChainCatalogueEntry[];
|
|
148
|
+
/** One balance row as the portfolio and identity endpoints report it. */
|
|
149
|
+
export interface BalanceRow {
|
|
150
|
+
token?: string;
|
|
151
|
+
balance: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* What the reported balances say about the gas on one chain account.
|
|
155
|
+
*
|
|
156
|
+
* - `funded` / `empty`: the native row was found and read.
|
|
157
|
+
* - `no-balances`: nothing was reported for the account (not yet deployed, or not yet indexed).
|
|
158
|
+
* - `unknown-native`: the catalogue does not know this chain's gas token, so no row can be
|
|
159
|
+
* identified as the gas — refused by name rather than guessed.
|
|
160
|
+
* - `native-not-reported`: rows were reported, but none is the chain's gas token (e.g. an `ETH`
|
|
161
|
+
* row on a chain whose gas is `TEL`). Treating any of them as gas would be reading the wrong
|
|
162
|
+
* number.
|
|
163
|
+
* - `unreadable`: the native row's balance is not a number (the gateway reports `unavailable` when
|
|
164
|
+
* its balance lookup failed).
|
|
165
|
+
*/
|
|
166
|
+
export type NativeBalanceReading = {
|
|
167
|
+
state: 'funded';
|
|
168
|
+
symbol: string;
|
|
169
|
+
balance: string;
|
|
170
|
+
} | {
|
|
171
|
+
state: 'empty';
|
|
172
|
+
symbol: string;
|
|
173
|
+
balance: string;
|
|
174
|
+
} | {
|
|
175
|
+
state: 'no-balances';
|
|
176
|
+
} | {
|
|
177
|
+
state: 'unknown-native';
|
|
178
|
+
chain: string;
|
|
179
|
+
} | {
|
|
180
|
+
state: 'native-not-reported';
|
|
181
|
+
chain: string;
|
|
182
|
+
symbol: string;
|
|
183
|
+
reported: string[];
|
|
184
|
+
} | {
|
|
185
|
+
state: 'unreadable';
|
|
186
|
+
symbol: string;
|
|
187
|
+
balance: string;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Find and read the native (gas) balance among an account's reported balance rows.
|
|
191
|
+
*
|
|
192
|
+
* A row is the native one when its token is the catalogue's symbol for the chain, or is reported
|
|
193
|
+
* without a token / as `native` (how the gateway marks a native row it did not name).
|
|
194
|
+
*/
|
|
195
|
+
export declare function readNativeBalance(chain: string | number, balances: readonly BalanceRow[] | undefined | null): NativeBalanceReading;
|
|
196
|
+
/** A sentence naming why the gas on `chain` could not be read, for an unverifiable reading. */
|
|
197
|
+
export declare function describeUnverifiable(chain: string, reading: NativeBalanceReading): string | undefined;
|
|
198
|
+
//# sourceMappingURL=chains.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzD,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,qBAAqB,EAAE,OAAO,CAAC;IACxC,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,4EAA4E;IAC5E,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,mBAAmB,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gB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,KAAK,EAAE,qBAAqB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GACnF;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,EAAE,SAAS,UAAU,EAAE,GAAG,SAAS,GAAG,IAAI,GACjD,oBAAoB,CAkBtB;AAED,+FAA+F;AAC/F,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS,CAYrG"}
|
package/dist/chains.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chain catalogue: the one place this SDK, the CLI and the MCP server learn what a chain IS.
|
|
3
|
+
*
|
|
4
|
+
* Before this file the same facts lived in five tables — the CLI's supported list, its alias map,
|
|
5
|
+
* its numeric-id map, its block-time table and its faucet table, plus two copies of a numeric-id
|
|
6
|
+
* map in the SDK — and they had already drifted (the SDK knew five chains, the CLI three). Every
|
|
7
|
+
* native-balance check also assumed the gas token was called `ETH`, which on a chain whose gas is
|
|
8
|
+
* not ETH made the funding guards pass without looking. Each of those is now derived from here.
|
|
9
|
+
*
|
|
10
|
+
* **What this table is, and what it is not.**
|
|
11
|
+
*
|
|
12
|
+
* - It is static on purpose. Normalizing a numeric `chain_id`, naming the gas token, estimating a
|
|
13
|
+
* wait and validating a flag must all work offline and on a first run.
|
|
14
|
+
* - It does NOT decide what is enabled on its own. A chain is offered only when it is enabled in
|
|
15
|
+
* configuration AND the gateway serves it (`GET /v1/chains`): see {@link resolveEnabledChains}.
|
|
16
|
+
* The catalogue's `enabledByDefault` is only the configuration default.
|
|
17
|
+
* - A `retired` entry is kept for reading: an older gateway may still return its numeric id in a
|
|
18
|
+
* portfolio, and dropping it would make that row unrecognisable. A retired chain is never
|
|
19
|
+
* offered and cannot be enabled.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Every chain this SDK knows. Order is the order chains are listed to a person.
|
|
23
|
+
*
|
|
24
|
+
* Facts verified 2026-10-05 against chainid.network and, for Telcoin Adiri, against the chain's
|
|
25
|
+
* own RPC (`eth_chainId` = 0x7e1). Adiri's block cadence was measured over its last 6000 blocks:
|
|
26
|
+
* blocks appear only when there is a transaction, and active blocks cluster 7–16 s apart.
|
|
27
|
+
*/
|
|
28
|
+
export const CHAIN_CATALOGUE = Object.freeze([
|
|
29
|
+
{
|
|
30
|
+
slug: 'ethereum-sepolia',
|
|
31
|
+
chainId: 11155111,
|
|
32
|
+
displayName: 'Ethereum Sepolia',
|
|
33
|
+
environment: 'testnet',
|
|
34
|
+
nativeSymbol: 'ETH',
|
|
35
|
+
nativeDecimals: 18,
|
|
36
|
+
blockSeconds: 12,
|
|
37
|
+
blocksOnlyWithTraffic: false,
|
|
38
|
+
faucet: 'https://sepoliafaucet.com',
|
|
39
|
+
aliases: ['eth', 'ethereum', 'sepolia', 'eth-sepolia', 'mainnet'],
|
|
40
|
+
support: 'live',
|
|
41
|
+
enabledByDefault: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
slug: 'base-sepolia',
|
|
45
|
+
chainId: 84532,
|
|
46
|
+
displayName: 'Base Sepolia',
|
|
47
|
+
environment: 'testnet',
|
|
48
|
+
nativeSymbol: 'ETH',
|
|
49
|
+
nativeDecimals: 18,
|
|
50
|
+
blockSeconds: 2,
|
|
51
|
+
blocksOnlyWithTraffic: false,
|
|
52
|
+
faucet: 'https://www.alchemy.com/faucets/base-sepolia',
|
|
53
|
+
aliases: ['base', 'basesepolia'],
|
|
54
|
+
support: 'live',
|
|
55
|
+
enabledByDefault: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
slug: 'arbitrum-sepolia',
|
|
59
|
+
chainId: 421614,
|
|
60
|
+
displayName: 'Arbitrum Sepolia',
|
|
61
|
+
environment: 'testnet',
|
|
62
|
+
nativeSymbol: 'ETH',
|
|
63
|
+
nativeDecimals: 18,
|
|
64
|
+
blockSeconds: 0.25,
|
|
65
|
+
blocksOnlyWithTraffic: false,
|
|
66
|
+
faucet: 'https://www.alchemy.com/faucets/arbitrum-sepolia',
|
|
67
|
+
aliases: ['arb', 'arbitrum', 'arb-sepolia', 'arbsepolia'],
|
|
68
|
+
support: 'live',
|
|
69
|
+
enabledByDefault: true,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
// Telcoin Network's testnet. Gas is TEL, not ETH. Off until configuration enables it AND the
|
|
73
|
+
// gateway serves it.
|
|
74
|
+
slug: 'telcoin-adiri',
|
|
75
|
+
chainId: 2017,
|
|
76
|
+
displayName: 'Telcoin Adiri (testnet)',
|
|
77
|
+
environment: 'testnet',
|
|
78
|
+
nativeSymbol: 'TEL',
|
|
79
|
+
nativeDecimals: 18,
|
|
80
|
+
blockSeconds: 7,
|
|
81
|
+
blocksOnlyWithTraffic: true,
|
|
82
|
+
faucet: 'https://www.telcoin.network/faucet',
|
|
83
|
+
aliases: ['adiri', 'telcoin', 'tel', 'telcoin-testnet', 'telcoin-network'],
|
|
84
|
+
support: 'opt-in',
|
|
85
|
+
enabledByDefault: false,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
slug: 'optimism-sepolia',
|
|
89
|
+
chainId: 11155420,
|
|
90
|
+
displayName: 'OP Sepolia',
|
|
91
|
+
environment: 'testnet',
|
|
92
|
+
nativeSymbol: 'ETH',
|
|
93
|
+
nativeDecimals: 18,
|
|
94
|
+
blockSeconds: 2,
|
|
95
|
+
blocksOnlyWithTraffic: false,
|
|
96
|
+
aliases: [],
|
|
97
|
+
support: 'retired',
|
|
98
|
+
enabledByDefault: false,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
slug: 'polygon-amoy',
|
|
102
|
+
chainId: 80002,
|
|
103
|
+
displayName: 'Polygon Amoy',
|
|
104
|
+
environment: 'testnet',
|
|
105
|
+
nativeSymbol: 'POL',
|
|
106
|
+
nativeDecimals: 18,
|
|
107
|
+
blockSeconds: 2,
|
|
108
|
+
blocksOnlyWithTraffic: false,
|
|
109
|
+
aliases: [],
|
|
110
|
+
support: 'retired',
|
|
111
|
+
enabledByDefault: false,
|
|
112
|
+
},
|
|
113
|
+
].map((entry) => Object.freeze({ ...entry, aliases: Object.freeze([...entry.aliases]) })));
|
|
114
|
+
const BY_SLUG = new Map(CHAIN_CATALOGUE.map((c) => [c.slug, c]));
|
|
115
|
+
const BY_NUMERIC = new Map(CHAIN_CATALOGUE.map((c) => [String(c.chainId), c]));
|
|
116
|
+
/** The catalogue entry for a slug or a numeric chain id (either spelling), or undefined. */
|
|
117
|
+
export function chainInfo(value) {
|
|
118
|
+
if (value === null || value === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
const raw = String(value).trim();
|
|
121
|
+
return BY_SLUG.get(raw) ?? BY_NUMERIC.get(raw);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolve whatever the gateway called a chain into its slug.
|
|
125
|
+
*
|
|
126
|
+
* A numeric id the catalogue knows becomes its slug. Anything else is returned unchanged (trimmed):
|
|
127
|
+
* a value we cannot map is still the best label we have for it, and inventing one would be worse.
|
|
128
|
+
*/
|
|
129
|
+
export function chainSlug(value) {
|
|
130
|
+
if (value === null || value === undefined)
|
|
131
|
+
return '';
|
|
132
|
+
const raw = String(value).trim();
|
|
133
|
+
return chainInfo(raw)?.slug ?? raw;
|
|
134
|
+
}
|
|
135
|
+
/** The native gas token's symbol, or undefined when the catalogue does not know the chain. */
|
|
136
|
+
export function nativeSymbolFor(chain) {
|
|
137
|
+
return chainInfo(chain)?.nativeSymbol;
|
|
138
|
+
}
|
|
139
|
+
export function faucetForChain(chain) {
|
|
140
|
+
return chainInfo(chain)?.faucet;
|
|
141
|
+
}
|
|
142
|
+
/** Slugs the catalogue enables when configuration says nothing: the live chains, in order. */
|
|
143
|
+
export function defaultEnabledChains() {
|
|
144
|
+
return CHAIN_CATALOGUE.filter((c) => c.enabledByDefault).map((c) => c.slug);
|
|
145
|
+
}
|
|
146
|
+
/** Slugs that configuration may enable: everything not retired. */
|
|
147
|
+
export function enablableChains() {
|
|
148
|
+
return CHAIN_CATALOGUE.filter((c) => c.support !== 'retired').map((c) => c.slug);
|
|
149
|
+
}
|
|
150
|
+
/** Thrown when configuration names a chain that cannot be enabled. */
|
|
151
|
+
export class ChainConfigurationError extends Error {
|
|
152
|
+
chain;
|
|
153
|
+
constructor(chain, message) {
|
|
154
|
+
super(message);
|
|
155
|
+
this.name = 'ChainConfigurationError';
|
|
156
|
+
this.chain = chain;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Parse an enabled-chains setting (e.g. `CERTEN_ENABLED_CHAINS`): a comma-separated list of slugs
|
|
161
|
+
* or numeric ids that REPLACES the default set.
|
|
162
|
+
*
|
|
163
|
+
* Unset or blank means the default set. Every name must be a catalogue chain that is not retired;
|
|
164
|
+
* anything else is refused by name — an enable switch that quietly ignored a typo would leave a
|
|
165
|
+
* person believing a chain was on.
|
|
166
|
+
*/
|
|
167
|
+
export function parseEnabledChains(setting) {
|
|
168
|
+
if (setting === undefined || setting === null || setting.trim() === '')
|
|
169
|
+
return defaultEnabledChains();
|
|
170
|
+
const out = [];
|
|
171
|
+
for (const part of setting.split(',').map((p) => p.trim()).filter((p) => p.length > 0)) {
|
|
172
|
+
const info = chainInfo(part);
|
|
173
|
+
if (!info) {
|
|
174
|
+
throw new ChainConfigurationError(part, `"${part}" is not a chain this client knows, so it cannot be enabled. Known: ${enablableChains().join(', ')}.`);
|
|
175
|
+
}
|
|
176
|
+
if (info.support === 'retired') {
|
|
177
|
+
throw new ChainConfigurationError(info.slug, `"${info.slug}" is retired and cannot be enabled. Enablable: ${enablableChains().join(', ')}.`);
|
|
178
|
+
}
|
|
179
|
+
if (!out.includes(info.slug))
|
|
180
|
+
out.push(info.slug);
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
/** Does the gateway serve this entry? Listed, and not explicitly disabled. */
|
|
185
|
+
export function gatewayServes(entry) {
|
|
186
|
+
return entry.enabled !== false;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Is `chain` available to use, given the configured set and (when known) what the gateway serves?
|
|
190
|
+
*
|
|
191
|
+
* `served` undefined means "the gateway has not been asked": the configured set alone decides,
|
|
192
|
+
* which is what an offline client can know. Passing the gateway's list narrows it — the client
|
|
193
|
+
* never offers a chain the gateway does not serve.
|
|
194
|
+
*/
|
|
195
|
+
export function chainAvailability(chain, configured, served) {
|
|
196
|
+
const info = chainInfo(chain);
|
|
197
|
+
if (!info)
|
|
198
|
+
return { state: 'unknown', chain: String(chain).trim() };
|
|
199
|
+
if (info.support === 'retired')
|
|
200
|
+
return { state: 'retired', chain: info };
|
|
201
|
+
if (!configured.includes(info.slug))
|
|
202
|
+
return { state: 'not-configured', chain: info };
|
|
203
|
+
if (served !== undefined) {
|
|
204
|
+
const entry = served.find((s) => chainSlug(s.id) === info.slug || (s.chainId !== null && s.chainId === info.chainId));
|
|
205
|
+
if (!entry)
|
|
206
|
+
return { state: 'unlisted', chain: info, code: 'unknown_chain' };
|
|
207
|
+
if (!gatewayServes(entry))
|
|
208
|
+
return { state: 'disabled', chain: info, code: 'chain_not_enabled' };
|
|
209
|
+
}
|
|
210
|
+
return { state: 'enabled', chain: info };
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The chains to offer: configured ∩ served, in catalogue order.
|
|
214
|
+
*
|
|
215
|
+
* `served` undefined means the gateway was not consulted, and the configured set is returned.
|
|
216
|
+
*/
|
|
217
|
+
export function resolveEnabledChains(configured = defaultEnabledChains(), served) {
|
|
218
|
+
return CHAIN_CATALOGUE.filter((c) => chainAvailability(c.slug, configured, served).state === 'enabled');
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Find and read the native (gas) balance among an account's reported balance rows.
|
|
222
|
+
*
|
|
223
|
+
* A row is the native one when its token is the catalogue's symbol for the chain, or is reported
|
|
224
|
+
* without a token / as `native` (how the gateway marks a native row it did not name).
|
|
225
|
+
*/
|
|
226
|
+
export function readNativeBalance(chain, balances) {
|
|
227
|
+
const symbol = nativeSymbolFor(chain);
|
|
228
|
+
if (symbol === undefined)
|
|
229
|
+
return { state: 'unknown-native', chain: chainSlug(chain) };
|
|
230
|
+
const rows = balances ?? [];
|
|
231
|
+
if (rows.length === 0)
|
|
232
|
+
return { state: 'no-balances' };
|
|
233
|
+
const native = rows.find((b) => !b.token || b.token === 'native' || b.token.toUpperCase() === symbol.toUpperCase());
|
|
234
|
+
if (!native) {
|
|
235
|
+
return {
|
|
236
|
+
state: 'native-not-reported',
|
|
237
|
+
chain: chainSlug(chain),
|
|
238
|
+
symbol,
|
|
239
|
+
reported: rows.map((b) => b.token ?? ''),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const n = Number(native.balance);
|
|
243
|
+
if (native.balance === '' || !Number.isFinite(n))
|
|
244
|
+
return { state: 'unreadable', symbol, balance: native.balance };
|
|
245
|
+
return n > 0 ? { state: 'funded', symbol, balance: native.balance } : { state: 'empty', symbol, balance: native.balance };
|
|
246
|
+
}
|
|
247
|
+
/** A sentence naming why the gas on `chain` could not be read, for an unverifiable reading. */
|
|
248
|
+
export function describeUnverifiable(chain, reading) {
|
|
249
|
+
switch (reading.state) {
|
|
250
|
+
case 'unknown-native':
|
|
251
|
+
return `this client does not know the native gas token of "${reading.chain}", so it cannot tell which balance pays for execution`;
|
|
252
|
+
case 'native-not-reported':
|
|
253
|
+
return `the gateway reported ${reading.reported.map((t) => t || '(unnamed)').join(', ')} on ${chain}, `
|
|
254
|
+
+ `but its gas token is ${reading.symbol}`;
|
|
255
|
+
case 'unreadable':
|
|
256
|
+
return `the gateway could not read the ${reading.symbol} balance on ${chain} (it reported "${reading.balance}")`;
|
|
257
|
+
default:
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=chains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAqCH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAmC,MAAM,CAAC,MAAM,CAAC;IAC3E;QACE,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,QAAQ;QACjB,WAAW,EAAE,kBAAkB;QAC/B,WAAW,EAAE,SAAS;QACtB,YAAY,EAAE,KAAK;QACnB,cAAc,EAAE,EAAE;QAClB,YAAY,EAAE,EAAE;QAChB,qBAAqB,EAAE,KAAK;QAC5B,MAAM,EAAE,2BAA2B;QACnC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC;QACjE,OAAO,EAAE,MAAM;QACf,gBAAgB,EAAE,IAAI;KACvB;IACD;QACE,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,cAAc;QAC3B,WAAW,EAAE,SAAS;QACtB,YAAY,EAAE,KAAK;QACnB,cAAc,EAAE,EAAE;QAClB,YAAY,EAAE,CAAC;QACf,qBAAqB,EAAE,KAAK;QAC5B,MAAM,EAAE,8CAA8C;QACtD,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC;QAChC,OAAO,EAAE,MAAM;QACf,gBAAgB,EAAE,IAAI;KACvB;IACD;QACE,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,MAAM;QACf,WAAW,EAAE,kBAAkB;QAC/B,WAAW,EAAE,SAAS;QACt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K,gBAAgB;YACnB,OAAO,sDAAsD,OAAO,CAAC,KAAK,uDAAuD,CAAC;QACpI,KAAK,qBAAqB;YACxB,OAAO,wBAAwB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI;kBACnG,wBAAwB,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/C,KAAK,YAAY;YACf,OAAO,kCAAkC,OAAO,CAAC,MAAM,eAAe,KAAK,kBAAkB,OAAO,CAAC,OAAO,IAAI,CAAC;QACnH;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_BASE_URL } from './defaults.js';
|
|
1
2
|
import { IdentityResource } from './resources/identity.js';
|
|
2
3
|
import { TransactionResource } from './resources/transaction.js';
|
|
3
4
|
import { GovernanceResource } from './resources/governance.js';
|
|
@@ -29,7 +30,7 @@ import type { CertenClientOptions, MeResponse } from './types.js';
|
|
|
29
30
|
* retargeted (staging, a self-hosted gateway, a future `api.certen.io` once it fronts the gateway) without
|
|
30
31
|
* a code change or an SDK release.
|
|
31
32
|
*/
|
|
32
|
-
export
|
|
33
|
+
export { DEFAULT_BASE_URL };
|
|
33
34
|
export declare class CertenClient {
|
|
34
35
|
private http;
|
|
35
36
|
private rateLimit;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAIjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,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C,CAAC;KAC7C;CA4PF;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAC/B,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,EACxG,QAAQ,SAAM,GACb,qBAAqB,CAAC,CAAC,CAAC,CAwB1B;AAED,wBAAuB,iBAAiB,CAAC,CAAC,EACxC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EACrF,QAAQ,SAAM,GACb,qBAAqB,CAAC;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,CAU9E"}
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { randomHex } from './random.js';
|
|
3
|
+
import { DEFAULT_BASE_URL } from './defaults.js';
|
|
4
|
+
import { SDK_VERSION } from './version.js';
|
|
5
|
+
import { CertenError, CertenForeignOriginError } from './errors.js';
|
|
6
|
+
import { assertOwnOrigin, redirectStaysOnOrigin } from './origin.js';
|
|
4
7
|
import { IdentityResource } from './resources/identity.js';
|
|
5
8
|
import { TransactionResource } from './resources/transaction.js';
|
|
6
9
|
import { GovernanceResource } from './resources/governance.js';
|
|
@@ -32,7 +35,7 @@ import { runDoctor } from './doctor.js';
|
|
|
32
35
|
* retargeted (staging, a self-hosted gateway, a future `api.certen.io` once it fronts the gateway) without
|
|
33
36
|
* a code change or an SDK release.
|
|
34
37
|
*/
|
|
35
|
-
export
|
|
38
|
+
export { DEFAULT_BASE_URL };
|
|
36
39
|
/** Read an env var without assuming `process` exists — this SDK also runs in browsers, where touching a
|
|
37
40
|
* bare `process` is a ReferenceError rather than `undefined`. */
|
|
38
41
|
function envBaseUrl() {
|
|
@@ -43,6 +46,10 @@ function envBaseUrl() {
|
|
|
43
46
|
return undefined;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
49
|
+
/** Node, as opposed to a browser or a worker. Reads nothing that throws when `process` is absent. */
|
|
50
|
+
function isNode() {
|
|
51
|
+
return typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions?.node;
|
|
52
|
+
}
|
|
46
53
|
const DEFAULT_MAX_RETRIES = 3;
|
|
47
54
|
const DEFAULT_BASE_BACKOFF_MS = 250;
|
|
48
55
|
const DEFAULT_MAX_BACKOFF_MS = 8_000;
|
|
@@ -214,16 +221,29 @@ export class CertenClient {
|
|
|
214
221
|
clientSecret: options.clientSecret,
|
|
215
222
|
scope: options.scope,
|
|
216
223
|
};
|
|
224
|
+
const baseURL = options.baseUrl ?? envBaseUrl() ?? DEFAULT_BASE_URL;
|
|
217
225
|
this.http = axios.create({
|
|
218
|
-
baseURL
|
|
226
|
+
baseURL,
|
|
219
227
|
headers: {
|
|
220
228
|
// The credential header is set per-request by the interceptor below, because a minted token
|
|
221
229
|
// changes over the client's life and a header baked in here never would.
|
|
222
230
|
'Content-Type': 'application/json',
|
|
223
|
-
|
|
231
|
+
// A browser forbids scripts setting User-Agent (the request would be refused or the header silently dropped), so only a Node
|
|
232
|
+
// process names itself. It names the SDK's own version, not whatever package happens to be running it.
|
|
233
|
+
...(isNode() ? { 'User-Agent': `certen-sdk-node/${SDK_VERSION}` } : {}),
|
|
224
234
|
},
|
|
225
235
|
timeout: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
226
236
|
validateStatus: (status) => status >= 200 && status < 300,
|
|
237
|
+
// The key travels on every request, so a redirect off the gateway's own origin must not carry it. Refused by name, not
|
|
238
|
+
// followed without the key: a gateway that redirects elsewhere is misconfigured or compromised, and either way the caller
|
|
239
|
+
// should hear it. (An http -> https upgrade of the same host is allowed.) Node's http adapter only; browsers follow redirects
|
|
240
|
+
// themselves.
|
|
241
|
+
beforeRedirect: (redirect) => {
|
|
242
|
+
const to = String(redirect.href ?? `${String(redirect.protocol)}//${String(redirect.host ?? redirect.hostname)}${String(redirect.path ?? '')}`);
|
|
243
|
+
if (!redirectStaysOnOrigin(baseURL, to)) {
|
|
244
|
+
throw new CertenForeignOriginError(`certen: the gateway redirected to ${JSON.stringify(to)}, which is not its own origin. The redirect was not followed and no credential was sent there.`, to, baseURL, 'redirect');
|
|
245
|
+
}
|
|
246
|
+
},
|
|
227
247
|
});
|
|
228
248
|
const autoIdem = options.autoIdempotencyKey !== false;
|
|
229
249
|
const skipPatterns = options.skipIdempotencyFor ?? [];
|
|
@@ -241,6 +261,8 @@ export class CertenClient {
|
|
|
241
261
|
};
|
|
242
262
|
// Auto-stamp Idempotency-Key on every POST that didn't already supply one.
|
|
243
263
|
this.http.interceptors.request.use(async (req) => {
|
|
264
|
+
// First, before the credential is attached or anything is sent: the key goes only to this client's own origin.
|
|
265
|
+
assertOwnOrigin(req.url, req.baseURL ?? baseURL, 'request');
|
|
244
266
|
const reqPath = req.url ?? '';
|
|
245
267
|
// Attach the credential here, not at construction: a minted token is refreshed over this
|
|
246
268
|
// client's life, and a header fixed in the axios defaults could never change.
|
|
@@ -293,6 +315,16 @@ export class CertenClient {
|
|
|
293
315
|
}
|
|
294
316
|
return response;
|
|
295
317
|
}, async (error) => {
|
|
318
|
+
// An error this client raised itself (the origin guard, a failed token mint) is already typed. It is not a transport
|
|
319
|
+
// failure, and wrapping it as NETWORK_ERROR would make it retryable.
|
|
320
|
+
if (error instanceof CertenError)
|
|
321
|
+
throw error;
|
|
322
|
+
// follow-redirects wraps what a beforeRedirect hook throws, one or two levels down.
|
|
323
|
+
for (let cause = error.cause, depth = 0; cause && depth < 5; depth++) {
|
|
324
|
+
if (cause instanceof CertenForeignOriginError)
|
|
325
|
+
throw cause;
|
|
326
|
+
cause = cause.cause;
|
|
327
|
+
}
|
|
296
328
|
const cfg = error.config;
|
|
297
329
|
const status = error.response?.status ?? 0;
|
|
298
330
|
// A non-JSON error body (an edge 502, an HTML error page) leaves `data` as a string, so
|
|
@@ -400,7 +432,7 @@ function sleep(ms) {
|
|
|
400
432
|
}
|
|
401
433
|
function generateIdempotencyKey() {
|
|
402
434
|
// Stable across retries within a process; unique across calls.
|
|
403
|
-
return `sdk_${Date.now().toString(36)}_${
|
|
435
|
+
return `sdk_${Date.now().toString(36)}_${randomHex(8)}`;
|
|
404
436
|
}
|
|
405
437
|
/**
|
|
406
438
|
* Async iterator helper for paginated list endpoints.
|