@certen.io/sdk 0.4.0 → 0.7.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 +874 -185
- package/README.md +133 -119
- package/dist/client.d.ts +99 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +269 -20
- package/dist/client.js.map +1 -1
- package/dist/doctor.d.ts +53 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +451 -0
- package/dist/doctor.js.map +1 -0
- package/dist/error-codes.d.ts +14 -0
- package/dist/error-codes.d.ts.map +1 -0
- package/dist/error-codes.js +55 -0
- package/dist/error-codes.js.map +1 -0
- package/dist/errors.d.ts +91 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +130 -1
- package/dist/errors.js.map +1 -1
- package/dist/funding.d.ts +43 -0
- package/dist/funding.d.ts.map +1 -0
- package/dist/funding.js +116 -0
- package/dist/funding.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +56 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +68 -0
- package/dist/oauth.js.map +1 -0
- package/dist/registration.d.ts +33 -0
- package/dist/registration.d.ts.map +1 -0
- package/dist/registration.js +49 -0
- package/dist/registration.js.map +1 -0
- package/dist/resources/admin.d.ts +52 -1
- package/dist/resources/admin.d.ts.map +1 -1
- package/dist/resources/admin.js +55 -0
- package/dist/resources/admin.js.map +1 -1
- package/dist/resources/billing.d.ts +242 -0
- package/dist/resources/billing.d.ts.map +1 -0
- package/dist/resources/billing.js +376 -0
- package/dist/resources/billing.js.map +1 -0
- package/dist/resources/chains.d.ts +38 -0
- package/dist/resources/chains.d.ts.map +1 -0
- package/dist/resources/chains.js +46 -0
- package/dist/resources/chains.js.map +1 -0
- package/dist/resources/device.d.ts +43 -0
- package/dist/resources/device.d.ts.map +1 -0
- package/dist/resources/device.js +49 -0
- package/dist/resources/device.js.map +1 -0
- package/dist/resources/execute.d.ts +39 -1
- package/dist/resources/execute.d.ts.map +1 -1
- package/dist/resources/execute.js +41 -1
- package/dist/resources/execute.js.map +1 -1
- package/dist/resources/health.d.ts +34 -0
- package/dist/resources/health.d.ts.map +1 -0
- package/dist/resources/health.js +43 -0
- package/dist/resources/health.js.map +1 -0
- package/dist/resources/identity.d.ts +83 -2
- package/dist/resources/identity.d.ts.map +1 -1
- package/dist/resources/identity.js +154 -2
- package/dist/resources/identity.js.map +1 -1
- package/dist/resources/oauth-clients.d.ts +71 -0
- package/dist/resources/oauth-clients.d.ts.map +1 -0
- package/dist/resources/oauth-clients.js +75 -0
- package/dist/resources/oauth-clients.js.map +1 -0
- package/dist/resources/pending.d.ts +13 -1
- package/dist/resources/pending.d.ts.map +1 -1
- package/dist/resources/pending.js +15 -0
- package/dist/resources/pending.js.map +1 -1
- package/dist/resources/proof.d.ts +75 -0
- package/dist/resources/proof.d.ts.map +1 -0
- package/dist/resources/proof.js +103 -0
- package/dist/resources/proof.js.map +1 -0
- package/dist/resources/registration-tokens.d.ts +51 -0
- package/dist/resources/registration-tokens.d.ts.map +1 -0
- package/dist/resources/registration-tokens.js +54 -0
- package/dist/resources/registration-tokens.js.map +1 -0
- package/dist/resources/transaction.d.ts +20 -0
- package/dist/resources/transaction.d.ts.map +1 -1
- package/dist/resources/transaction.js +28 -0
- package/dist/resources/transaction.js.map +1 -1
- package/dist/resources/transparency.d.ts +68 -0
- package/dist/resources/transparency.d.ts.map +1 -0
- package/dist/resources/transparency.js +83 -0
- package/dist/resources/transparency.js.map +1 -0
- package/dist/resources/webhooks.d.ts +97 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +112 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/self-signup.d.ts +66 -0
- package/dist/self-signup.d.ts.map +1 -0
- package/dist/self-signup.js +76 -0
- package/dist/self-signup.js.map +1 -0
- package/dist/shared-proof.d.ts +34 -0
- package/dist/shared-proof.d.ts.map +1 -0
- package/dist/shared-proof.js +78 -0
- package/dist/shared-proof.js.map +1 -0
- package/dist/types.d.ts +901 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/verify-receipt.d.ts +32 -0
- package/dist/verify-receipt.d.ts.map +1 -0
- package/dist/verify-receipt.js +176 -0
- package/dist/verify-receipt.js.map +1 -0
- package/package.json +6 -5
package/dist/errors.d.ts
CHANGED
|
@@ -8,11 +8,33 @@ export declare class CertenError extends Error {
|
|
|
8
8
|
readonly code: string;
|
|
9
9
|
readonly requestId?: string;
|
|
10
10
|
readonly details?: unknown;
|
|
11
|
+
/**
|
|
12
|
+
* The gateway's parsed response body, when it sent one.
|
|
13
|
+
*
|
|
14
|
+
* Kept because some refusals carry the FIX and not just the diagnosis: a 402
|
|
15
|
+
* arrives with a live payment target, and discarding the body left the caller
|
|
16
|
+
* holding a message string. Undefined when the body was not JSON (an edge 502,
|
|
17
|
+
* an HTML error page) and when there was no response at all.
|
|
18
|
+
*/
|
|
19
|
+
readonly body?: unknown;
|
|
11
20
|
constructor(message: string, status: number, code: string, opts?: {
|
|
12
21
|
requestId?: string;
|
|
13
22
|
details?: unknown;
|
|
23
|
+
body?: unknown;
|
|
14
24
|
});
|
|
15
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* True when repeating this identical request can eventually succeed on its own.
|
|
27
|
+
*
|
|
28
|
+
* Status alone gets two cases wrong, and both are decided by the CODE:
|
|
29
|
+
*
|
|
30
|
+
* - `IDEMPOTENCY_KEY_IN_FLIGHT` is a 409, which status-wise reads as "do not retry" — but the
|
|
31
|
+
* whole point of that code is that an identical request is already running, and retrying the
|
|
32
|
+
* SAME key is precisely the correct response. Treating it as terminal fails a request that
|
|
33
|
+
* would have succeeded a moment later.
|
|
34
|
+
* - `PLAN_QUOTA_EXCEEDED` is a 429, which reads as "back off and retry" — but it is a quota for
|
|
35
|
+
* the billing period, not a per-second rate. No amount of backing off clears it, so retrying
|
|
36
|
+
* only burns the attempts a genuinely transient failure would need.
|
|
37
|
+
*/
|
|
16
38
|
get isRetryable(): boolean;
|
|
17
39
|
/** True for client-side input mistakes. Never auto-retry these. */
|
|
18
40
|
get isClientError(): boolean;
|
|
@@ -20,6 +42,7 @@ export declare class CertenError extends Error {
|
|
|
20
42
|
static fromAxios(message: string, status: number, code: string, opts?: {
|
|
21
43
|
requestId?: string;
|
|
22
44
|
details?: unknown;
|
|
45
|
+
body?: unknown;
|
|
23
46
|
}): CertenError;
|
|
24
47
|
}
|
|
25
48
|
export declare class CertenAuthError extends CertenError {
|
|
@@ -32,4 +55,71 @@ export declare class CertenBadRequestError extends CertenError {
|
|
|
32
55
|
}
|
|
33
56
|
export declare class CertenServerError extends CertenError {
|
|
34
57
|
}
|
|
58
|
+
/** A live way to settle a 402, minted by the gateway with the refusal. */
|
|
59
|
+
export interface PaymentResolution {
|
|
60
|
+
/** Reference the deposit is matched by. */
|
|
61
|
+
payment_intent: string;
|
|
62
|
+
chain: string;
|
|
63
|
+
to_address: string;
|
|
64
|
+
/** Send EXACTLY this. Attribution matches the amount, so a different one will not credit. */
|
|
65
|
+
amount_usd: string;
|
|
66
|
+
expires_at: string;
|
|
67
|
+
/** True when an already-open payment covered the shortfall and was reused. */
|
|
68
|
+
reused_existing: boolean;
|
|
69
|
+
portal_url: string;
|
|
70
|
+
cli_command: string;
|
|
71
|
+
note: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The account cannot pay for this work. HTTP 402.
|
|
75
|
+
*
|
|
76
|
+
* Distinct from `CertenBadRequestError` because nothing is wrong with the request
|
|
77
|
+
* — it is priced, valid, and would succeed once funded. A host product needs that
|
|
78
|
+
* distinction to decide between showing a top-up prompt and showing a validation
|
|
79
|
+
* error.
|
|
80
|
+
*
|
|
81
|
+
* Two codes arrive here and they need different remedies:
|
|
82
|
+
*
|
|
83
|
+
* PAYMENT_REQUIRED the balance does not cover this request. Add funds.
|
|
84
|
+
* COMMITMENT_EXCEEDED the balance would cover this request alone, but pending
|
|
85
|
+
* intents have already claimed it. Add funds OR wait for
|
|
86
|
+
* those to settle or expire — see `pendingIntents`.
|
|
87
|
+
*
|
|
88
|
+
* Never retried automatically, and never should be: the outcome cannot change
|
|
89
|
+
* until money moves, so a retry loop is just load.
|
|
90
|
+
*
|
|
91
|
+
* `resolution` is null when the gateway could not mint a target (no chain
|
|
92
|
+
* configured for deposits, for instance). The refusal is still valid; there is
|
|
93
|
+
* simply no one-step fix to offer, so fall back to `portalUrl` on your own UI.
|
|
94
|
+
*/
|
|
95
|
+
export declare class CertenPaymentRequiredError extends CertenError {
|
|
96
|
+
private get payload();
|
|
97
|
+
private nested;
|
|
98
|
+
private str;
|
|
99
|
+
/** True when pending commitments, not the raw balance, caused the refusal. */
|
|
100
|
+
get isCommitmentExceeded(): boolean;
|
|
101
|
+
/** How much more is needed, as a fixed-6dp decimal string. */
|
|
102
|
+
get shortfallUsd(): string | undefined;
|
|
103
|
+
get spendableUsd(): string | undefined;
|
|
104
|
+
/** Non-terminal intents that have already claimed balance. Commitment case only. */
|
|
105
|
+
get pendingIntents(): number | undefined;
|
|
106
|
+
/** Re-send the request with this to reuse the price you were quoted. */
|
|
107
|
+
get quoteId(): string | undefined;
|
|
108
|
+
/** After this, the quoted price is gone and the work must be re-quoted. */
|
|
109
|
+
get quoteExpiresAt(): string | undefined;
|
|
110
|
+
/** The payment target, or null when the gateway could not offer one. */
|
|
111
|
+
get resolution(): PaymentResolution | null;
|
|
112
|
+
/** Deep link for your own UI to send the customer to. */
|
|
113
|
+
get portalUrl(): string | undefined;
|
|
114
|
+
/** The exact command that settles this from a terminal. */
|
|
115
|
+
get cliCommand(): string | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* One line fit to show a person, whichever code arrived.
|
|
118
|
+
*
|
|
119
|
+
* Provided so every host product does not re-derive the same sentence, and get
|
|
120
|
+
* the commitment case wrong by telling the customer to add funds when waiting
|
|
121
|
+
* would also work.
|
|
122
|
+
*/
|
|
123
|
+
get summary(): string;
|
|
124
|
+
}
|
|
35
125
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClC;;;;;;;OAOG;IACH,SAAgB,IAAI,CAAC,EAAE,OAAO,CAAC;gBAG7B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAO;IAWtE;;;;;;;;;;;;OAYG;IACH,IAAI,WAAW,IAAI,OAAO,CASzB;IAED,mEAAmE;IACnE,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,gEAAgE;IAChE,MAAM,CAAC,SAAS,CACd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EA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IAAI,iBAAiB,GAAG,IAAI,CAKzC;IAED,yDAAyD;IACzD,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,2DAA2D;IAC3D,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAEnC;IAED;;;;;;OAMG;IACH,IAAI,OAAO,IAAI,MAAM,CAUpB;CACF"}
|
package/dist/errors.js
CHANGED
|
@@ -8,6 +8,15 @@ export class CertenError extends Error {
|
|
|
8
8
|
code;
|
|
9
9
|
requestId;
|
|
10
10
|
details;
|
|
11
|
+
/**
|
|
12
|
+
* The gateway's parsed response body, when it sent one.
|
|
13
|
+
*
|
|
14
|
+
* Kept because some refusals carry the FIX and not just the diagnosis: a 402
|
|
15
|
+
* arrives with a live payment target, and discarding the body left the caller
|
|
16
|
+
* holding a message string. Undefined when the body was not JSON (an edge 502,
|
|
17
|
+
* an HTML error page) and when there was no response at all.
|
|
18
|
+
*/
|
|
19
|
+
body;
|
|
11
20
|
constructor(message, status, code, opts = {}) {
|
|
12
21
|
super(message);
|
|
13
22
|
this.name = 'CertenError';
|
|
@@ -15,11 +24,29 @@ export class CertenError extends Error {
|
|
|
15
24
|
this.code = code;
|
|
16
25
|
this.requestId = opts.requestId;
|
|
17
26
|
this.details = opts.details;
|
|
27
|
+
this.body = opts.body;
|
|
18
28
|
}
|
|
19
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* True when repeating this identical request can eventually succeed on its own.
|
|
31
|
+
*
|
|
32
|
+
* Status alone gets two cases wrong, and both are decided by the CODE:
|
|
33
|
+
*
|
|
34
|
+
* - `IDEMPOTENCY_KEY_IN_FLIGHT` is a 409, which status-wise reads as "do not retry" — but the
|
|
35
|
+
* whole point of that code is that an identical request is already running, and retrying the
|
|
36
|
+
* SAME key is precisely the correct response. Treating it as terminal fails a request that
|
|
37
|
+
* would have succeeded a moment later.
|
|
38
|
+
* - `PLAN_QUOTA_EXCEEDED` is a 429, which reads as "back off and retry" — but it is a quota for
|
|
39
|
+
* the billing period, not a per-second rate. No amount of backing off clears it, so retrying
|
|
40
|
+
* only burns the attempts a genuinely transient failure would need.
|
|
41
|
+
*/
|
|
20
42
|
get isRetryable() {
|
|
21
43
|
if (this.code === 'NETWORK_ERROR')
|
|
22
44
|
return true;
|
|
45
|
+
// Code beats status, in both directions.
|
|
46
|
+
if (this.code === 'IDEMPOTENCY_KEY_IN_FLIGHT')
|
|
47
|
+
return true;
|
|
48
|
+
if (this.code === 'PLAN_QUOTA_EXCEEDED')
|
|
49
|
+
return false;
|
|
23
50
|
if (this.status >= 500 && this.status < 600)
|
|
24
51
|
return true;
|
|
25
52
|
if (this.status === 429)
|
|
@@ -38,6 +65,11 @@ export class CertenError extends Error {
|
|
|
38
65
|
return new CertenAuthError(message, status, code, opts);
|
|
39
66
|
if (status === 429)
|
|
40
67
|
return new CertenRateLimitError(message, status, code, opts);
|
|
68
|
+
// Before the generic 4xx branch: a payment problem is not a malformed request,
|
|
69
|
+
// and a host product needs to tell those apart to know whether to show a
|
|
70
|
+
// "top up" prompt or a validation message.
|
|
71
|
+
if (status === 402)
|
|
72
|
+
return new CertenPaymentRequiredError(message, status, code, opts);
|
|
41
73
|
if (status >= 500)
|
|
42
74
|
return new CertenServerError(message, status, code, opts);
|
|
43
75
|
if (status >= 400)
|
|
@@ -58,4 +90,101 @@ export class CertenBadRequestError extends CertenError {
|
|
|
58
90
|
}
|
|
59
91
|
export class CertenServerError extends CertenError {
|
|
60
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The account cannot pay for this work. HTTP 402.
|
|
95
|
+
*
|
|
96
|
+
* Distinct from `CertenBadRequestError` because nothing is wrong with the request
|
|
97
|
+
* — it is priced, valid, and would succeed once funded. A host product needs that
|
|
98
|
+
* distinction to decide between showing a top-up prompt and showing a validation
|
|
99
|
+
* error.
|
|
100
|
+
*
|
|
101
|
+
* Two codes arrive here and they need different remedies:
|
|
102
|
+
*
|
|
103
|
+
* PAYMENT_REQUIRED the balance does not cover this request. Add funds.
|
|
104
|
+
* COMMITMENT_EXCEEDED the balance would cover this request alone, but pending
|
|
105
|
+
* intents have already claimed it. Add funds OR wait for
|
|
106
|
+
* those to settle or expire — see `pendingIntents`.
|
|
107
|
+
*
|
|
108
|
+
* Never retried automatically, and never should be: the outcome cannot change
|
|
109
|
+
* until money moves, so a retry loop is just load.
|
|
110
|
+
*
|
|
111
|
+
* `resolution` is null when the gateway could not mint a target (no chain
|
|
112
|
+
* configured for deposits, for instance). The refusal is still valid; there is
|
|
113
|
+
* simply no one-step fix to offer, so fall back to `portalUrl` on your own UI.
|
|
114
|
+
*/
|
|
115
|
+
export class CertenPaymentRequiredError extends CertenError {
|
|
116
|
+
get payload() {
|
|
117
|
+
return (typeof this.body === 'object' && this.body !== null)
|
|
118
|
+
? this.body
|
|
119
|
+
: {};
|
|
120
|
+
}
|
|
121
|
+
nested(key) {
|
|
122
|
+
const v = this.payload[key];
|
|
123
|
+
return (typeof v === 'object' && v !== null) ? v : {};
|
|
124
|
+
}
|
|
125
|
+
str(obj, key) {
|
|
126
|
+
const v = obj[key];
|
|
127
|
+
return typeof v === 'string' ? v : undefined;
|
|
128
|
+
}
|
|
129
|
+
/** True when pending commitments, not the raw balance, caused the refusal. */
|
|
130
|
+
get isCommitmentExceeded() {
|
|
131
|
+
return this.code === 'COMMITMENT_EXCEEDED';
|
|
132
|
+
}
|
|
133
|
+
/** How much more is needed, as a fixed-6dp decimal string. */
|
|
134
|
+
get shortfallUsd() {
|
|
135
|
+
return this.str(this.nested('balance'), 'shortfall_usd')
|
|
136
|
+
?? this.str(this.nested('commitments'), 'shortfall_usd');
|
|
137
|
+
}
|
|
138
|
+
get spendableUsd() {
|
|
139
|
+
return this.str(this.nested('balance'), 'spendable_usd');
|
|
140
|
+
}
|
|
141
|
+
/** Non-terminal intents that have already claimed balance. Commitment case only. */
|
|
142
|
+
get pendingIntents() {
|
|
143
|
+
const v = this.nested('commitments').pending_intents;
|
|
144
|
+
return typeof v === 'number' ? v : undefined;
|
|
145
|
+
}
|
|
146
|
+
/** Re-send the request with this to reuse the price you were quoted. */
|
|
147
|
+
get quoteId() {
|
|
148
|
+
return this.str(this.nested('quote'), 'id');
|
|
149
|
+
}
|
|
150
|
+
/** After this, the quoted price is gone and the work must be re-quoted. */
|
|
151
|
+
get quoteExpiresAt() {
|
|
152
|
+
return this.str(this.nested('quote'), 'expires_at')
|
|
153
|
+
?? this.str(this.payload, 'quote_expires_at');
|
|
154
|
+
}
|
|
155
|
+
/** The payment target, or null when the gateway could not offer one. */
|
|
156
|
+
get resolution() {
|
|
157
|
+
const r = this.payload.resolve;
|
|
158
|
+
if (typeof r !== 'object' || r === null)
|
|
159
|
+
return null;
|
|
160
|
+
const o = r;
|
|
161
|
+
return typeof o.payment_intent === 'string' ? r : null;
|
|
162
|
+
}
|
|
163
|
+
/** Deep link for your own UI to send the customer to. */
|
|
164
|
+
get portalUrl() {
|
|
165
|
+
return this.resolution?.portal_url;
|
|
166
|
+
}
|
|
167
|
+
/** The exact command that settles this from a terminal. */
|
|
168
|
+
get cliCommand() {
|
|
169
|
+
return this.resolution?.cli_command;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* One line fit to show a person, whichever code arrived.
|
|
173
|
+
*
|
|
174
|
+
* Provided so every host product does not re-derive the same sentence, and get
|
|
175
|
+
* the commitment case wrong by telling the customer to add funds when waiting
|
|
176
|
+
* would also work.
|
|
177
|
+
*/
|
|
178
|
+
get summary() {
|
|
179
|
+
const short = this.shortfallUsd;
|
|
180
|
+
if (this.isCommitmentExceeded) {
|
|
181
|
+
const n = this.pendingIntents;
|
|
182
|
+
return `Pending work has already claimed this balance${n ? ` (${n} intent${n === 1 ? '' : 's'})` : ''}`
|
|
183
|
+
+ `${short ? `, leaving ${short} USD short` : ''}. Add funds, or wait for it to settle.`;
|
|
184
|
+
}
|
|
185
|
+
return short
|
|
186
|
+
? `Not enough funds: ${short} USD short of this request.`
|
|
187
|
+
: 'Not enough funds for this request.';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
61
190
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,SAAS,CAAU;IACnB,OAAO,CAAW;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,SAAS,CAAU;IACnB,OAAO,CAAW;IAClC;;;;;;;OAOG;IACa,IAAI,CAAW;IAE/B,YACE,OAAe,EACf,MAAc,EACd,IAAY,EACZ,OAAkE,EAAE;QAEpE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe;YAAE,OAAO,IAAI,CAAC;QAC/C,yCAAyC;QACzC,IAAI,IAAI,CAAC,IAAI,KAAK,2BAA2B;YAAE,OAAO,IAAI,CAAC;QAC3D,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB;YAAE,OAAO,KAAK,CAAC;QACtD,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,GA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X,OAAO,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;IACrC,CAAC;IAED,2DAA2D;IAC3D,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACH,IAAI,OAAO;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAChC,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC;YAC9B,OAAO,gDAAgD,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;kBACnG,GAAG,KAAK,CAAC,CAAC,CAAC,aAAa,KAAK,YAAY,CAAC,CAAC,CAAC,EAAE,wCAAwC,CAAC;QAC7F,CAAC;QACD,OAAO,KAAK;YACV,CAAC,CAAC,qBAAqB,KAAK,6BAA6B;YACzD,CAAC,CAAC,oCAAoC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { CertenError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* The unfunded abstract account guard.
|
|
5
|
+
*
|
|
6
|
+
* This is the most expensive silent failure the platform can produce, and it is invisible at every
|
|
7
|
+
* point where someone might notice it. A fresh identity gets a deterministic abstract account on
|
|
8
|
+
* each linked chain, with a zero balance. An intent that moves value from it is accepted, signed
|
|
9
|
+
* and submitted — every call returns success — and then parks at `anchoring` forever, because the
|
|
10
|
+
* execution leg cannot run on chain. No response says so. The intent simply never reaches a
|
|
11
|
+
* terminal state, and the failure is usually blamed on the gateway.
|
|
12
|
+
*
|
|
13
|
+
* So the SDK refuses before submitting, and says why.
|
|
14
|
+
*
|
|
15
|
+
* **The check is one-directional by design.** It refuses ONLY on a positively observed zero
|
|
16
|
+
* balance. If the balance cannot be read — the chain is absent from the portfolio, the account is
|
|
17
|
+
* not deployed, the lookup fails — the intent proceeds. A guard that blocked on missing data would
|
|
18
|
+
* break legitimate work every time the portfolio view lagged, which is a worse failure than the one
|
|
19
|
+
* it prevents. It is a courtesy, not a gate the product depends on.
|
|
20
|
+
*/
|
|
21
|
+
/** Thrown instead of submitting an intent that could never execute. */
|
|
22
|
+
export declare class CertenUnfundedAccountError extends CertenError {
|
|
23
|
+
readonly address: string;
|
|
24
|
+
readonly chain: string;
|
|
25
|
+
constructor(address: string, chain: string);
|
|
26
|
+
/** Never. Funding is a human act; retrying changes nothing. */
|
|
27
|
+
get isRetryable(): boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare function normalizeChainId(value: string | number | null | undefined): string;
|
|
30
|
+
/** Does this amount move value? A zero or absent amount needs no funded account. */
|
|
31
|
+
export declare function movesValue(amount: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Refuse a value-moving intent from an abstract account positively known to be empty.
|
|
34
|
+
*
|
|
35
|
+
* Reads the portfolio directly rather than taking a client, so this stays usable from inside
|
|
36
|
+
* `ExecuteResource`, which holds only an axios instance.
|
|
37
|
+
*/
|
|
38
|
+
export declare function assertFundedForValue(http: AxiosInstance, params: {
|
|
39
|
+
identityId: string;
|
|
40
|
+
chain: string | undefined;
|
|
41
|
+
amount: unknown;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
//# sourceMappingURL=funding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funding.d.ts","sourceRoot":"","sources":["../src/funding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AAEH,uEAAuE;AACvE,qBAAa,0BAA2B,SAAQ,WAAW;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAe1C,+DAA+D;IAC/D,IAAI,WAAW,IAAI,OAAO,CAEzB;CACF;AAuBD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIlF;AAED,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAOnD;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACzE,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
package/dist/funding.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CertenError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* The unfunded abstract account guard.
|
|
4
|
+
*
|
|
5
|
+
* This is the most expensive silent failure the platform can produce, and it is invisible at every
|
|
6
|
+
* point where someone might notice it. A fresh identity gets a deterministic abstract account on
|
|
7
|
+
* each linked chain, with a zero balance. An intent that moves value from it is accepted, signed
|
|
8
|
+
* and submitted — every call returns success — and then parks at `anchoring` forever, because the
|
|
9
|
+
* execution leg cannot run on chain. No response says so. The intent simply never reaches a
|
|
10
|
+
* terminal state, and the failure is usually blamed on the gateway.
|
|
11
|
+
*
|
|
12
|
+
* So the SDK refuses before submitting, and says why.
|
|
13
|
+
*
|
|
14
|
+
* **The check is one-directional by design.** It refuses ONLY on a positively observed zero
|
|
15
|
+
* balance. If the balance cannot be read — the chain is absent from the portfolio, the account is
|
|
16
|
+
* not deployed, the lookup fails — the intent proceeds. A guard that blocked on missing data would
|
|
17
|
+
* break legitimate work every time the portfolio view lagged, which is a worse failure than the one
|
|
18
|
+
* it prevents. It is a courtesy, not a gate the product depends on.
|
|
19
|
+
*/
|
|
20
|
+
/** Thrown instead of submitting an intent that could never execute. */
|
|
21
|
+
export class CertenUnfundedAccountError extends CertenError {
|
|
22
|
+
address;
|
|
23
|
+
chain;
|
|
24
|
+
constructor(address, chain) {
|
|
25
|
+
super(`The abstract account ${address} on ${chain} holds no gas. This intent would be accepted, `
|
|
26
|
+
+ 'signed and submitted, and would then park at "anchoring" forever, because the execution leg '
|
|
27
|
+
+ 'cannot run on chain. Fund it first, or pass skipFundingCheck: true to submit anyway.',
|
|
28
|
+
// 0 is the SDK's "this never reached the gateway" status, which is exactly true here: the
|
|
29
|
+
// guard runs before the request, and nothing was submitted.
|
|
30
|
+
0, 'ABSTRACT_ACCOUNT_UNFUNDED');
|
|
31
|
+
this.name = 'CertenUnfundedAccountError';
|
|
32
|
+
this.address = address;
|
|
33
|
+
this.chain = chain;
|
|
34
|
+
}
|
|
35
|
+
/** Never. Funding is a human act; retrying changes nothing. */
|
|
36
|
+
get isRetryable() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Numeric EVM chain id → registry slug.
|
|
42
|
+
*
|
|
43
|
+
* `GET /v1/portfolio` used to return `chain_id` as a slug on some chain accounts and as a numeric
|
|
44
|
+
* EVM id on others, in the same response, because the gateway stored whatever the caller sent.
|
|
45
|
+
* Comparing raw strings matched the slug entries and silently skipped the numeric ones — so this
|
|
46
|
+
* guard did nothing on exactly the accounts it was written to protect.
|
|
47
|
+
*
|
|
48
|
+
* The gateway now canonicalizes on write and has backfilled the old rows, so a current gateway
|
|
49
|
+
* returns slugs only. This stays anyway, and not out of superstition: the SDK is versioned
|
|
50
|
+
* independently and is routinely pointed at a gateway older than itself. A guard that silently
|
|
51
|
+
* stops guarding against an older peer is worse than no guard, because nothing signals the gap.
|
|
52
|
+
*/
|
|
53
|
+
const NUMERIC_CHAIN_IDS = {
|
|
54
|
+
11155111: 'ethereum-sepolia',
|
|
55
|
+
84532: 'base-sepolia',
|
|
56
|
+
421614: 'arbitrum-sepolia',
|
|
57
|
+
11155420: 'optimism-sepolia',
|
|
58
|
+
80002: 'polygon-amoy',
|
|
59
|
+
};
|
|
60
|
+
export function normalizeChainId(value) {
|
|
61
|
+
if (value === null || value === undefined)
|
|
62
|
+
return '';
|
|
63
|
+
const raw = String(value).trim();
|
|
64
|
+
return NUMERIC_CHAIN_IDS[raw] ?? raw;
|
|
65
|
+
}
|
|
66
|
+
/** Does this amount move value? A zero or absent amount needs no funded account. */
|
|
67
|
+
export function movesValue(amount) {
|
|
68
|
+
if (amount === undefined || amount === null || amount === '')
|
|
69
|
+
return false;
|
|
70
|
+
const n = Number(String(amount));
|
|
71
|
+
// A non-numeric amount is not evidence of zero. Assume it moves value and let the gateway judge
|
|
72
|
+
// the shape — the opposite default would skip the guard on exactly the malformed input that most
|
|
73
|
+
// warrants a second look.
|
|
74
|
+
return Number.isFinite(n) ? n > 0 : true;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Refuse a value-moving intent from an abstract account positively known to be empty.
|
|
78
|
+
*
|
|
79
|
+
* Reads the portfolio directly rather than taking a client, so this stays usable from inside
|
|
80
|
+
* `ExecuteResource`, which holds only an axios instance.
|
|
81
|
+
*/
|
|
82
|
+
export async function assertFundedForValue(http, params) {
|
|
83
|
+
if (!params.chain || !movesValue(params.amount))
|
|
84
|
+
return;
|
|
85
|
+
let address;
|
|
86
|
+
let balance;
|
|
87
|
+
try {
|
|
88
|
+
const { data } = await http.get('/v1/portfolio', { params: { identity: params.identityId } });
|
|
89
|
+
const want = normalizeChainId(params.chain);
|
|
90
|
+
const identities = data.identities ?? [];
|
|
91
|
+
for (const identity of identities) {
|
|
92
|
+
for (const chain of identity.chains ?? []) {
|
|
93
|
+
if (normalizeChainId(chain.chain_id) !== want)
|
|
94
|
+
continue;
|
|
95
|
+
// The NATIVE balance is what pays for execution. A token balance on the same account does
|
|
96
|
+
// not make the execution leg runnable.
|
|
97
|
+
const native = (chain.balances ?? [])
|
|
98
|
+
.find((b) => !b.token || b.token === 'ETH' || b.token === 'native');
|
|
99
|
+
if (!native)
|
|
100
|
+
return;
|
|
101
|
+
address = chain.address;
|
|
102
|
+
balance = native.balance;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// An unavailable portfolio must never block a transaction.
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (address === undefined || balance === undefined)
|
|
111
|
+
return;
|
|
112
|
+
if (Number(balance) > 0)
|
|
113
|
+
return;
|
|
114
|
+
throw new CertenUnfundedAccountError(address, normalizeChainId(params.chain));
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=funding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funding.js","sourceRoot":"","sources":["../src/funding.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AAEH,uEAAuE;AACvE,MAAM,OAAO,0BAA2B,SAAQ,WAAW;IAChD,OAAO,CAAS;IAChB,KAAK,CAAS;IAEvB,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CACH,wBAAwB,OAAO,OAAO,KAAK,gDAAgD;cACzF,8FAA8F;cAC9F,sFAAsF;QACxF,0FAA0F;QAC1F,4DAA4D;QAC5D,CAAC,EACD,2BAA2B,CAC5B,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,+DAA+D;IAC/D,IAAI,WAAW;QACb,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,iBAAiB,GAA2B;IAChD,QAAQ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MAAM,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,UAAU,GAAI,IAElB,CAAC,UAAU,IAAI,EAAE,CAAC;QAEpB,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;YAClC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;gBAC1C,IAAI,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI;oBAAE,SAAS;gBACxD,0FAA0F;gBAC1F,uCAAuC;gBACvC,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;qBAClC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;gBACtE,IAAI,CAAC,MAAM;oBAAE,OAAO;gBACpB,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;gBACxB,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,2DAA2D;QAC3D,OAAO;IACT,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO;IAC3D,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO;IAEhC,MAAM,IAAI,0BAA0B,CAAC,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAChF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export { CertenClient, paginate, paginateWithTotal, DEFAULT_BASE_URL } from './client.js';
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export type { SignFn, ProofGatedCallParams, TransferParams, OpenedIntent } from './resources/execute.js';
|
|
4
|
-
export { CertenError, CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError, } from './errors.js';
|
|
4
|
+
export { CertenError, CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError, CertenPaymentRequiredError, } from './errors.js';
|
|
5
|
+
export type { PaymentResolution } from './errors.js';
|
|
6
|
+
export { runDoctor, CREDENTIALLED_CHECKS } from './doctor.js';
|
|
7
|
+
export { fetchSharedProof, parseShareTarget } from './shared-proof.js';
|
|
8
|
+
export { fetchOAuthToken, refreshOAuthToken, revokeOAuthToken } from './oauth.js';
|
|
9
|
+
export { parseMnemonicTarget } from './resources/identity.js';
|
|
10
|
+
export { redeemRegistrationToken } from './registration.js';
|
|
11
|
+
export { selfSignup, requestSignupChallenge, completeSignup } from './self-signup.js';
|
|
12
|
+
export { CertenUnfundedAccountError, movesValue, normalizeChainId } from './funding.js';
|
|
13
|
+
export type { DoctorReport, DoctorCheck, CheckStatus } from './doctor.js';
|
|
5
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,EACL,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,EACL,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGvE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGlF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,0BAA0B,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACxF,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
export { CertenClient, paginate, paginateWithTotal, DEFAULT_BASE_URL } from './client.js';
|
|
2
2
|
export * from './types.js';
|
|
3
|
-
export { CertenError, CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError, } from './errors.js';
|
|
3
|
+
export { CertenError, CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError, CertenPaymentRequiredError, } from './errors.js';
|
|
4
|
+
export { runDoctor, CREDENTIALLED_CHECKS } from './doctor.js';
|
|
5
|
+
// Standalone on purpose: redeeming a share link needs no API key and therefore no client. See
|
|
6
|
+
// shared-proof.ts.
|
|
7
|
+
export { fetchSharedProof, parseShareTarget } from './shared-proof.js';
|
|
8
|
+
// Standalone for the same reason: these carry their credential in the body and need no API key,
|
|
9
|
+
// so a caller using OAuth is not made to hold one. See oauth.ts.
|
|
10
|
+
export { fetchOAuthToken, refreshOAuthToken, revokeOAuthToken } from './oauth.js';
|
|
11
|
+
// Exported so a caller can split `mnemonic_retrieval.url` the same way the SDK does, rather than
|
|
12
|
+
// writing their own regex against a string whose parts they cannot afford to get wrong.
|
|
13
|
+
export { parseMnemonicTarget } from './resources/identity.js';
|
|
14
|
+
// Standalone for the same reason as the OAuth helpers: the caller has no credential yet, and
|
|
15
|
+
// obtaining its first one is the entire purpose. See registration.ts.
|
|
16
|
+
export { redeemRegistrationToken } from './registration.js';
|
|
17
|
+
// Keypair-proof self-service signup — no browser, no email, nobody at CERTEN. Standalone for the
|
|
18
|
+
// same reason: the caller holds nothing yet. See self-signup.ts.
|
|
19
|
+
export { selfSignup, requestSignupChallenge, completeSignup } from './self-signup.js';
|
|
20
|
+
export { CertenUnfundedAccountError, movesValue, normalizeChainId } from './funding.js';
|
|
4
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc,YAAY,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc,YAAY,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC9D,8FAA8F;AAC9F,mBAAmB;AACnB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,gGAAgG;AAChG,iEAAiE;AACjE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAClF,iGAAiG;AACjG,wFAAwF;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,6FAA6F;AAC7F,sEAAsE;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,iGAAiG;AACjG,iEAAiE;AACjE,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,0BAA0B,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/oauth.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { OAuthTokens } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The OAuth2 token lifecycle: obtain, refresh, revoke.
|
|
4
|
+
*
|
|
5
|
+
* None of it was reachable from this SDK — not the token endpoint, not revocation. A machine using
|
|
6
|
+
* client credentials could get a token only by hand-rolling HTTP, and could not give it back at
|
|
7
|
+
* all. That asymmetry is the dangerous half: a leaked token had no revocation path an integration
|
|
8
|
+
* could call, so the response to a suspected compromise was to open a browser.
|
|
9
|
+
*
|
|
10
|
+
* **Standalone functions, deliberately — not methods on `CertenClient`.** Both endpoints take their
|
|
11
|
+
* credential in the BODY and require no API key, which is the whole point: a service using OAuth
|
|
12
|
+
* has a client id and secret, not an API key, so routing these through a constructor that demands
|
|
13
|
+
* `apiKey` would ask for the one credential such a caller does not hold. Same reasoning as
|
|
14
|
+
* `fetchSharedProof`.
|
|
15
|
+
*/
|
|
16
|
+
interface Endpoint {
|
|
17
|
+
/** Defaults to the SDK's configured gateway. */
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Exchange client credentials for an access token.
|
|
23
|
+
*
|
|
24
|
+
* Returns an access token good for an hour and a refresh token good for thirty days.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fetchOAuthToken(params: {
|
|
27
|
+
clientId: string;
|
|
28
|
+
clientSecret: string;
|
|
29
|
+
scope?: string;
|
|
30
|
+
}, options?: Endpoint): Promise<OAuthTokens>;
|
|
31
|
+
/**
|
|
32
|
+
* Trade a refresh token for a fresh pair.
|
|
33
|
+
*
|
|
34
|
+
* **The old refresh token is spent the moment this succeeds.** Replaying one that has already been
|
|
35
|
+
* used revokes its entire descendant chain — that is deliberate theft detection, not a bug: if a
|
|
36
|
+
* stolen token is replayed, both the thief's and the victim's tokens die and the compromise
|
|
37
|
+
* surfaces. So store the new pair before doing anything else, and never retry this call blindly
|
|
38
|
+
* with the same token.
|
|
39
|
+
*/
|
|
40
|
+
export declare function refreshOAuthToken(refreshToken: string, options?: Endpoint): Promise<OAuthTokens>;
|
|
41
|
+
/**
|
|
42
|
+
* Revoke a token (RFC 7009).
|
|
43
|
+
*
|
|
44
|
+
* Accepts an access token or a refresh token; revoking a REFRESH token kills its whole descendant
|
|
45
|
+
* chain, which is what you want when responding to a leak.
|
|
46
|
+
*
|
|
47
|
+
* Always resolves when the request is understood, even for a token that never existed — the
|
|
48
|
+
* endpoint deliberately does not reveal whether it did, because an endpoint that distinguished them
|
|
49
|
+
* would be an oracle for guessing tokens. So a successful call means "this token is not valid now",
|
|
50
|
+
* not "this token was valid and now is not".
|
|
51
|
+
*/
|
|
52
|
+
export declare function revokeOAuthToken(token: string, options?: Endpoint & {
|
|
53
|
+
tokenTypeHint?: 'access_token' | 'refresh_token';
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AAEH,UAAU,QAAQ;IAChB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA0BD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAClE,OAAO,GAAE,QAAa,GACrB,OAAO,CAAC,WAAW,CAAC,CAOtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,QAAa,GACrB,OAAO,CAAC,WAAW,CAAC,CAKtB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,QAAQ,GAAG;IAAE,aAAa,CAAC,EAAE,cAAc,GAAG,eAAe,CAAA;CAAO,GAC5E,OAAO,CAAC,IAAI,CAAC,CAKf"}
|