@certen.io/sdk 0.8.2 → 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 +103 -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 +111 -0
- package/dist/execution-proof.d.ts.map +1 -0
- package/dist/execution-proof.js +311 -0
- package/dist/execution-proof.js.map +1 -0
- 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 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -23
- 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 +7 -5
- package/dist/shared-proof.d.ts.map +1 -1
- package/dist/shared-proof.js +36 -17
- 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/funding.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CertenError } from './errors.js';
|
|
2
|
+
import { chainSlug, nativeSymbolFor, readNativeBalance, describeUnverifiable } from './chains.js';
|
|
2
3
|
/**
|
|
3
4
|
* The unfunded abstract account guard.
|
|
4
5
|
*
|
|
@@ -11,11 +12,19 @@ import { CertenError } from './errors.js';
|
|
|
11
12
|
*
|
|
12
13
|
* So the SDK refuses before submitting, and says why.
|
|
13
14
|
*
|
|
14
|
-
* **
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* **What it refuses, and what it lets through.**
|
|
16
|
+
*
|
|
17
|
+
* - A positively observed zero gas balance is refused ({@link CertenUnfundedAccountError}).
|
|
18
|
+
* - A gas balance that cannot be IDENTIFIED is refused by name
|
|
19
|
+
* ({@link CertenFundingUnverifiableError}): the chain's gas token is unknown to the catalogue,
|
|
20
|
+
* the gateway reported balances none of which is that token, or it reported the gas row as
|
|
21
|
+
* unreadable. The first two used to pass silently on any chain whose gas is not called `ETH` —
|
|
22
|
+
* the guard looked for an `ETH` row, found none, and waved the intent through.
|
|
23
|
+
* - The portfolio being unreachable, or the chain not appearing in it at all, lets the intent
|
|
24
|
+
* proceed. A guard that blocked every time the portfolio view lagged would break legitimate work,
|
|
25
|
+
* which is a worse failure than the one it prevents.
|
|
26
|
+
*
|
|
27
|
+
* `skipFundingCheck: true` bypasses all of it, deliberately and visibly.
|
|
19
28
|
*/
|
|
20
29
|
/** Thrown instead of submitting an intent that could never execute. */
|
|
21
30
|
export class CertenUnfundedAccountError extends CertenError {
|
|
@@ -38,7 +47,31 @@ export class CertenUnfundedAccountError extends CertenError {
|
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
/**
|
|
41
|
-
*
|
|
50
|
+
* Thrown instead of submitting a value-moving intent whose gas balance could not be identified.
|
|
51
|
+
*
|
|
52
|
+
* Not the same claim as {@link CertenUnfundedAccountError}: the account may well be funded. What is
|
|
53
|
+
* known is that this client cannot tell, and an unfunded account is a silent, permanent stall.
|
|
54
|
+
*/
|
|
55
|
+
export class CertenFundingUnverifiableError extends CertenError {
|
|
56
|
+
address;
|
|
57
|
+
chain;
|
|
58
|
+
reason;
|
|
59
|
+
constructor(address, chain, reason, why) {
|
|
60
|
+
super(`Cannot verify that the abstract account${address ? ` ${address}` : ''} on ${chain} holds gas: ${why}. `
|
|
61
|
+
+ 'An intent from an unfunded account is accepted, signed and submitted, and then parks at '
|
|
62
|
+
+ '"anchoring" forever. Check the account\'s gas yourself, then pass skipFundingCheck: true to submit.', 0, 'ABSTRACT_ACCOUNT_FUNDING_UNVERIFIABLE');
|
|
63
|
+
this.name = 'CertenFundingUnverifiableError';
|
|
64
|
+
this.address = address;
|
|
65
|
+
this.chain = chain;
|
|
66
|
+
this.reason = reason;
|
|
67
|
+
}
|
|
68
|
+
/** Only an unreadable balance can change on its own; the other two are facts about the chain. */
|
|
69
|
+
get isRetryable() {
|
|
70
|
+
return this.reason === 'unreadable';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Numeric EVM chain id → registry slug, from the chain catalogue (`chains.ts`).
|
|
42
75
|
*
|
|
43
76
|
* `GET /v1/portfolio` used to return `chain_id` as a slug on some chain accounts and as a numeric
|
|
44
77
|
* EVM id on others, in the same response, because the gateway stored whatever the caller sent.
|
|
@@ -50,18 +83,8 @@ export class CertenUnfundedAccountError extends CertenError {
|
|
|
50
83
|
* independently and is routinely pointed at a gateway older than itself. A guard that silently
|
|
51
84
|
* stops guarding against an older peer is worse than no guard, because nothing signals the gap.
|
|
52
85
|
*/
|
|
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
86
|
export function normalizeChainId(value) {
|
|
61
|
-
|
|
62
|
-
return '';
|
|
63
|
-
const raw = String(value).trim();
|
|
64
|
-
return NUMERIC_CHAIN_IDS[raw] ?? raw;
|
|
87
|
+
return chainSlug(value);
|
|
65
88
|
}
|
|
66
89
|
/** Does this amount move value? A zero or absent amount needs no funded account. */
|
|
67
90
|
export function movesValue(amount) {
|
|
@@ -74,7 +97,8 @@ export function movesValue(amount) {
|
|
|
74
97
|
return Number.isFinite(n) ? n > 0 : true;
|
|
75
98
|
}
|
|
76
99
|
/**
|
|
77
|
-
* Refuse a value-moving intent from an abstract account positively known to be empty
|
|
100
|
+
* Refuse a value-moving intent from an abstract account positively known to be empty, or whose gas
|
|
101
|
+
* balance cannot be identified.
|
|
78
102
|
*
|
|
79
103
|
* Reads the portfolio directly rather than taking a client, so this stays usable from inside
|
|
80
104
|
* `ExecuteResource`, which holds only an axios instance.
|
|
@@ -82,24 +106,31 @@ export function movesValue(amount) {
|
|
|
82
106
|
export async function assertFundedForValue(http, params) {
|
|
83
107
|
if (!params.chain || !movesValue(params.amount))
|
|
84
108
|
return;
|
|
109
|
+
const want = normalizeChainId(params.chain);
|
|
110
|
+
// Before any read: on a chain whose gas token is unknown, no balance row can be identified as the
|
|
111
|
+
// gas, so the answer is already known to be unknowable.
|
|
112
|
+
if (nativeSymbolFor(want) === undefined) {
|
|
113
|
+
const reading = { state: 'unknown-native', chain: want };
|
|
114
|
+
throw new CertenFundingUnverifiableError(undefined, want, 'unknown-native', describeUnverifiable(want, reading));
|
|
115
|
+
}
|
|
85
116
|
let address;
|
|
86
|
-
let
|
|
117
|
+
let reading;
|
|
87
118
|
try {
|
|
88
119
|
const { data } = await http.get('/v1/portfolio', { params: { identity: params.identityId } });
|
|
89
|
-
const want = normalizeChainId(params.chain);
|
|
90
120
|
const identities = data.identities ?? [];
|
|
91
121
|
for (const identity of identities) {
|
|
92
122
|
for (const chain of identity.chains ?? []) {
|
|
93
123
|
if (normalizeChainId(chain.chain_id) !== want)
|
|
94
124
|
continue;
|
|
95
125
|
// The NATIVE balance is what pays for execution. A token balance on the same account does
|
|
96
|
-
// not make the execution leg runnable
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
126
|
+
// not make the execution leg runnable — and on a chain whose gas is not ETH, an `ETH` row
|
|
127
|
+
// is not the gas either.
|
|
128
|
+
const r = readNativeBalance(want, chain.balances);
|
|
129
|
+
// Nothing reported for the account yet (not deployed, not indexed): not evidence of zero.
|
|
130
|
+
if (r.state === 'no-balances')
|
|
100
131
|
return;
|
|
101
132
|
address = chain.address;
|
|
102
|
-
|
|
133
|
+
reading = r;
|
|
103
134
|
}
|
|
104
135
|
}
|
|
105
136
|
}
|
|
@@ -107,10 +138,19 @@ export async function assertFundedForValue(http, params) {
|
|
|
107
138
|
// An unavailable portfolio must never block a transaction.
|
|
108
139
|
return;
|
|
109
140
|
}
|
|
110
|
-
if (address === undefined ||
|
|
141
|
+
if (address === undefined || reading === undefined)
|
|
111
142
|
return;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
143
|
+
switch (reading.state) {
|
|
144
|
+
case 'funded':
|
|
145
|
+
return;
|
|
146
|
+
case 'empty':
|
|
147
|
+
throw new CertenUnfundedAccountError(address, want);
|
|
148
|
+
case 'unknown-native':
|
|
149
|
+
case 'native-not-reported':
|
|
150
|
+
case 'unreadable':
|
|
151
|
+
throw new CertenFundingUnverifiableError(address, want, reading.state, describeUnverifiable(want, reading));
|
|
152
|
+
default:
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
115
155
|
}
|
|
116
156
|
//# sourceMappingURL=funding.js.map
|
package/dist/funding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"funding.js","sourceRoot":"","sources":["../src/funding.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"funding.js","sourceRoot":"","sources":["../src/funding.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAA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ction-header fields an intent may carry: extra authorities and a deadline.
|
|
3
|
+
*
|
|
4
|
+
* Both are forwarded to Accumulate as part of the transaction header. They are validated here with
|
|
5
|
+
* the same rules the gateway applies, so a mistake is refused before an Idempotency-Key is spent and
|
|
6
|
+
* before anything is signed — not after a round trip that names a snake_case field the caller never
|
|
7
|
+
* typed.
|
|
8
|
+
*
|
|
9
|
+
* Header authorities are REFUSED by the gateway by default (HTTP 422,
|
|
10
|
+
* `HEADER_AUTHORITY_NOT_EXECUTABLE`): the validators do not yet count a header authority's
|
|
11
|
+
* signature, so an intent carrying one would sit pending, collect every signature, and then never
|
|
12
|
+
* execute. Put a party that must co-sign on the ACCOUNT's authorities instead. The field is exposed
|
|
13
|
+
* so a deployment that has turned the gateway guard off can use it, and so the SDK does not need a
|
|
14
|
+
* release when the validator fix lands.
|
|
15
|
+
*/
|
|
16
|
+
/** The gateway's limit on DISTINCT books, counted after normalisation. More is refused with a 400. */
|
|
17
|
+
export declare const MAX_ADDITIONAL_AUTHORITIES = 8;
|
|
18
|
+
/** The gateway's longest accepted authority URL, checked on the raw entry. */
|
|
19
|
+
export declare const MAX_AUTHORITY_URL_LENGTH = 512;
|
|
20
|
+
/**
|
|
21
|
+
* The gateway's default deadline window: 60 s to 7 days from its clock, in whole seconds
|
|
22
|
+
* (`INTENT_EXPIRY_MIN_S` / `INTENT_EXPIRY_MAX_S`, refused as `EXPIRES_AT_OUT_OF_RANGE`).
|
|
23
|
+
*/
|
|
24
|
+
export declare const GATEWAY_EXPIRY_MIN_S = 60;
|
|
25
|
+
export declare const GATEWAY_EXPIRY_MAX_S: number;
|
|
26
|
+
/**
|
|
27
|
+
* The minimum refused LOCALLY. Higher than the gateway's 60 s on purpose: the deadline is measured
|
|
28
|
+
* when the call is made and checked when the request lands, and a signing prompt, a funding check
|
|
29
|
+
* and the round trip all sit in between. A deadline that passes the local check and fails the remote
|
|
30
|
+
* one costs a request and reads as a gateway fault; 30 s of margin makes that practically impossible.
|
|
31
|
+
*/
|
|
32
|
+
export declare const LOCAL_EXPIRY_MIN_S = 90;
|
|
33
|
+
/**
|
|
34
|
+
* Validate and normalise `additionalAuthorities` exactly as the gateway does: each entry a string of
|
|
35
|
+
* at most 512 characters; trimmed, lowercased and stripped of trailing slashes; then an `acc://` URL
|
|
36
|
+
* with a non-empty host; de-duplicated in caller order; and only THEN at most eight distinct books.
|
|
37
|
+
*
|
|
38
|
+
* Returns `undefined` for an absent or empty list, so the request body carries the field only when
|
|
39
|
+
* it means something. (The gateway additionally refuses the identity's own key book, which needs
|
|
40
|
+
* server-side knowledge and is not mirrored here.)
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeAdditionalAuthorities(value: unknown, where?: string): string[] | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Validate `expiresAt` and render it as RFC 3339.
|
|
45
|
+
*
|
|
46
|
+
* A `Date` becomes its ISO string; a string must be RFC 3339 with a timezone and is passed through
|
|
47
|
+
* trimmed. The deadline, in whole seconds as the gateway counts it, must be between 90 s (local
|
|
48
|
+
* margin over the gateway's 60 s minimum) and 7 days from now.
|
|
49
|
+
*/
|
|
50
|
+
export declare function normalizeExpiresAt(value: unknown, now?: number, where?: string): string | undefined;
|
|
51
|
+
/** Codes of the local header-field refusals above. Status 0: raised before any request. */
|
|
52
|
+
export declare const HEADER_FIELD_ERROR_CODES: readonly string[];
|
|
53
|
+
/**
|
|
54
|
+
* `"90s"`, `"30m"`, `"2h"`, `"7d"` → milliseconds. One positive integer and one unit; anything else
|
|
55
|
+
* throws, because a deadline is not a place to guess what a caller meant.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseDuration(text: string): number;
|
|
58
|
+
/** A deadline `duration` from now, for `expiresAt`: `expiresAt: expiresIn('30m')`. */
|
|
59
|
+
export declare function expiresIn(duration: string | number, now?: number): Date;
|
|
60
|
+
/** Both header fields, validated, as the snake_case body keys the gateway expects. */
|
|
61
|
+
export declare function headerFieldsBody(p: {
|
|
62
|
+
additionalAuthorities?: unknown;
|
|
63
|
+
expiresAt?: unknown;
|
|
64
|
+
}): {
|
|
65
|
+
additional_authorities?: string[];
|
|
66
|
+
expires_at?: string;
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=header-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-fields.d.ts","sourceRoot":"","sources":["../src/header-fields.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,sGAAsG;AACtG,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAC5C,8EAA8E;AAC9E,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,oBAAoB,QAAgB,CAAC;AAClD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAYrC;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAA0B,GAAG,MAAM,EAAE,GAAG,SAAS,CA6BpH;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,GAAE,MAAmB,EAAE,KAAK,SAAc,GAAG,MAAM,GAAG,SAAS,CAyCpH;AAED,2FAA2F;AAC3F,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAErD,CAAC;AAIF;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUlD;AAED,sFAAsF;AACtF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,IAAI,CAMnF;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG;IAC7F,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAKA"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { CertenError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Transaction-header fields an intent may carry: extra authorities and a deadline.
|
|
4
|
+
*
|
|
5
|
+
* Both are forwarded to Accumulate as part of the transaction header. They are validated here with
|
|
6
|
+
* the same rules the gateway applies, so a mistake is refused before an Idempotency-Key is spent and
|
|
7
|
+
* before anything is signed — not after a round trip that names a snake_case field the caller never
|
|
8
|
+
* typed.
|
|
9
|
+
*
|
|
10
|
+
* Header authorities are REFUSED by the gateway by default (HTTP 422,
|
|
11
|
+
* `HEADER_AUTHORITY_NOT_EXECUTABLE`): the validators do not yet count a header authority's
|
|
12
|
+
* signature, so an intent carrying one would sit pending, collect every signature, and then never
|
|
13
|
+
* execute. Put a party that must co-sign on the ACCOUNT's authorities instead. The field is exposed
|
|
14
|
+
* so a deployment that has turned the gateway guard off can use it, and so the SDK does not need a
|
|
15
|
+
* release when the validator fix lands.
|
|
16
|
+
*/
|
|
17
|
+
/** The gateway's limit on DISTINCT books, counted after normalisation. More is refused with a 400. */
|
|
18
|
+
export const MAX_ADDITIONAL_AUTHORITIES = 8;
|
|
19
|
+
/** The gateway's longest accepted authority URL, checked on the raw entry. */
|
|
20
|
+
export const MAX_AUTHORITY_URL_LENGTH = 512;
|
|
21
|
+
/**
|
|
22
|
+
* The gateway's default deadline window: 60 s to 7 days from its clock, in whole seconds
|
|
23
|
+
* (`INTENT_EXPIRY_MIN_S` / `INTENT_EXPIRY_MAX_S`, refused as `EXPIRES_AT_OUT_OF_RANGE`).
|
|
24
|
+
*/
|
|
25
|
+
export const GATEWAY_EXPIRY_MIN_S = 60;
|
|
26
|
+
export const GATEWAY_EXPIRY_MAX_S = 7 * 24 * 3600;
|
|
27
|
+
/**
|
|
28
|
+
* The minimum refused LOCALLY. Higher than the gateway's 60 s on purpose: the deadline is measured
|
|
29
|
+
* when the call is made and checked when the request lands, and a signing prompt, a funding check
|
|
30
|
+
* and the round trip all sit in between. A deadline that passes the local check and fails the remote
|
|
31
|
+
* one costs a request and reads as a gateway fault; 30 s of margin makes that practically impossible.
|
|
32
|
+
*/
|
|
33
|
+
export const LOCAL_EXPIRY_MIN_S = 90;
|
|
34
|
+
/** RFC 3339 date-time with a timezone — the gateway's exact pattern. */
|
|
35
|
+
const RFC3339 = /^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/;
|
|
36
|
+
/** An Accumulate URL with a non-empty host and no whitespace — the gateway's exact pattern. */
|
|
37
|
+
const ACC_URL = /^acc:\/\/[^\s/][^\s]*$/;
|
|
38
|
+
/** The gateway's normalisation: trim, lowercase, strip trailing slashes. */
|
|
39
|
+
function normalizeUrl(u) {
|
|
40
|
+
return u.trim().toLowerCase().replace(/\/+$/, '');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validate and normalise `additionalAuthorities` exactly as the gateway does: each entry a string of
|
|
44
|
+
* at most 512 characters; trimmed, lowercased and stripped of trailing slashes; then an `acc://` URL
|
|
45
|
+
* with a non-empty host; de-duplicated in caller order; and only THEN at most eight distinct books.
|
|
46
|
+
*
|
|
47
|
+
* Returns `undefined` for an absent or empty list, so the request body carries the field only when
|
|
48
|
+
* it means something. (The gateway additionally refuses the identity's own key book, which needs
|
|
49
|
+
* server-side knowledge and is not mirrored here.)
|
|
50
|
+
*/
|
|
51
|
+
export function normalizeAdditionalAuthorities(value, where = 'additionalAuthorities') {
|
|
52
|
+
if (value === undefined || value === null)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (!Array.isArray(value)) {
|
|
55
|
+
throw new CertenError(`${where} must be an array of acc:// key book URLs`, 0, 'INVALID_ADDITIONAL_AUTHORITIES');
|
|
56
|
+
}
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const [i, entry] of value.entries()) {
|
|
59
|
+
if (typeof entry !== 'string' || entry.length > MAX_AUTHORITY_URL_LENGTH) {
|
|
60
|
+
throw new CertenError(`${where}[${i}] must be a string of at most ${MAX_AUTHORITY_URL_LENGTH} characters`, 0, 'INVALID_ADDITIONAL_AUTHORITIES');
|
|
61
|
+
}
|
|
62
|
+
const url = normalizeUrl(entry);
|
|
63
|
+
if (!ACC_URL.test(url)) {
|
|
64
|
+
throw new CertenError(`${where}[${i}] ${JSON.stringify(entry)} is not an Accumulate URL — expected acc://<host>…, e.g. acc://firm.acme/book`, 0, 'INVALID_ADDITIONAL_AUTHORITIES');
|
|
65
|
+
}
|
|
66
|
+
if (!out.includes(url))
|
|
67
|
+
out.push(url);
|
|
68
|
+
}
|
|
69
|
+
if (out.length > MAX_ADDITIONAL_AUTHORITIES) {
|
|
70
|
+
throw new CertenError(`${where} names ${out.length} distinct books; at most ${MAX_ADDITIONAL_AUTHORITIES} are allowed`, 0, 'INVALID_ADDITIONAL_AUTHORITIES');
|
|
71
|
+
}
|
|
72
|
+
return out.length > 0 ? out : undefined;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Validate `expiresAt` and render it as RFC 3339.
|
|
76
|
+
*
|
|
77
|
+
* A `Date` becomes its ISO string; a string must be RFC 3339 with a timezone and is passed through
|
|
78
|
+
* trimmed. The deadline, in whole seconds as the gateway counts it, must be between 90 s (local
|
|
79
|
+
* margin over the gateway's 60 s minimum) and 7 days from now.
|
|
80
|
+
*/
|
|
81
|
+
export function normalizeExpiresAt(value, now = Date.now(), where = 'expiresAt') {
|
|
82
|
+
if (value === undefined || value === null)
|
|
83
|
+
return undefined;
|
|
84
|
+
let iso;
|
|
85
|
+
let at;
|
|
86
|
+
if (value instanceof Date) {
|
|
87
|
+
at = value.getTime();
|
|
88
|
+
if (!Number.isFinite(at))
|
|
89
|
+
throw new CertenError(`${where} is an invalid Date`, 0, 'INVALID_EXPIRES_AT');
|
|
90
|
+
iso = value.toISOString();
|
|
91
|
+
}
|
|
92
|
+
else if (typeof value === 'string') {
|
|
93
|
+
iso = value.trim();
|
|
94
|
+
at = Date.parse(iso);
|
|
95
|
+
if (!RFC3339.test(iso) || !Number.isFinite(at)) {
|
|
96
|
+
throw new CertenError(`${where} "${value}" is not an RFC 3339 date-time with a timezone, e.g. 2026-09-14T12:00:00Z`, 0, 'INVALID_EXPIRES_AT');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new CertenError(`${where} must be a Date or an RFC 3339 string`, 0, 'INVALID_EXPIRES_AT');
|
|
101
|
+
}
|
|
102
|
+
const deltaS = Math.floor(at / 1000) - Math.floor(now / 1000);
|
|
103
|
+
if (deltaS <= 0) {
|
|
104
|
+
throw new CertenError(`${where} ${iso} is in the past — it must be between ${LOCAL_EXPIRY_MIN_S}s and ${GATEWAY_EXPIRY_MAX_S}s (7 days) from now`, 0, 'INVALID_EXPIRES_AT');
|
|
105
|
+
}
|
|
106
|
+
if (deltaS < LOCAL_EXPIRY_MIN_S) {
|
|
107
|
+
throw new CertenError(`${where} is only ${deltaS}s away. The gateway requires at least ${GATEWAY_EXPIRY_MIN_S}s when the request arrives; `
|
|
108
|
+
+ `the SDK asks for ${LOCAL_EXPIRY_MIN_S}s so signing and network time cannot push it under. Use a later deadline.`, 0, 'INVALID_EXPIRES_AT');
|
|
109
|
+
}
|
|
110
|
+
if (deltaS > GATEWAY_EXPIRY_MAX_S) {
|
|
111
|
+
throw new CertenError(`${where} is ${deltaS}s away; the gateway allows at most ${GATEWAY_EXPIRY_MAX_S}s (7 days)`, 0, 'INVALID_EXPIRES_AT');
|
|
112
|
+
}
|
|
113
|
+
return iso;
|
|
114
|
+
}
|
|
115
|
+
/** Codes of the local header-field refusals above. Status 0: raised before any request. */
|
|
116
|
+
export const HEADER_FIELD_ERROR_CODES = [
|
|
117
|
+
'INVALID_ADDITIONAL_AUTHORITIES', 'INVALID_EXPIRES_AT', 'INVALID_DURATION',
|
|
118
|
+
];
|
|
119
|
+
const UNIT_MS = { s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 };
|
|
120
|
+
/**
|
|
121
|
+
* `"90s"`, `"30m"`, `"2h"`, `"7d"` → milliseconds. One positive integer and one unit; anything else
|
|
122
|
+
* throws, because a deadline is not a place to guess what a caller meant.
|
|
123
|
+
*/
|
|
124
|
+
export function parseDuration(text) {
|
|
125
|
+
const m = /^\s*(\d+)\s*([smhd])\s*$/i.exec(String(text ?? ''));
|
|
126
|
+
const n = m ? Number(m[1]) : NaN;
|
|
127
|
+
if (!m || !Number.isSafeInteger(n) || n <= 0) {
|
|
128
|
+
throw new CertenError(`duration "${text}" is not valid — use a positive whole number followed by s, m, h or d, e.g. 30m`, 0, 'INVALID_DURATION');
|
|
129
|
+
}
|
|
130
|
+
return n * UNIT_MS[m[2].toLowerCase()];
|
|
131
|
+
}
|
|
132
|
+
/** A deadline `duration` from now, for `expiresAt`: `expiresAt: expiresIn('30m')`. */
|
|
133
|
+
export function expiresIn(duration, now = Date.now()) {
|
|
134
|
+
const ms = typeof duration === 'number' ? duration : parseDuration(duration);
|
|
135
|
+
if (!Number.isFinite(ms) || ms <= 0) {
|
|
136
|
+
throw new CertenError(`expiresIn needs a positive duration, got ${JSON.stringify(duration)}`, 0, 'INVALID_DURATION');
|
|
137
|
+
}
|
|
138
|
+
return new Date(now + ms);
|
|
139
|
+
}
|
|
140
|
+
/** Both header fields, validated, as the snake_case body keys the gateway expects. */
|
|
141
|
+
export function headerFieldsBody(p) {
|
|
142
|
+
return {
|
|
143
|
+
additional_authorities: normalizeAdditionalAuthorities(p.additionalAuthorities),
|
|
144
|
+
expires_at: normalizeExpiresAt(p.expiresAt),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=header-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-fields.js","sourceRoot":"","sources":["../src/header-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC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IAAI,WAAW,CAAC,4CAA4C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACvH,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;AAC5B,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,gBAAgB,CAAC,CAA2D;IAI1F,OAAO;QACL,sBAAsB,EAAE,8BAA8B,CAAC,CAAC,CAAC,qBAAqB,CAAC;QAC/E,UAAU,EAAE,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export {
|
|
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 { resolveSignTarget } from './sign-target.js';
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's default entry (Node): everything in the browser-safe surface, plus the two parts that need Node.
|
|
3
|
+
* See browser.ts for the portable half and why the split exists.
|
|
4
|
+
*/
|
|
5
|
+
export * from './browser.js';
|
|
6
|
+
export { fetchSharedProof, decodeSharedBundle } from './shared-proof.js';
|
|
14
7
|
export { CertenAgent, ed25519Signer } from './agent.js';
|
|
15
8
|
export type { AgentSigner, CertenAgentState, ProvisionParams } from './agent.js';
|
|
16
|
-
export
|
|
17
|
-
export type {
|
|
9
|
+
export { CertenSigningDataError, checkIntentSigning, checkCosigning, checkGovernanceSigning, inspectSigningData, legsFromIntent, toBaseUnits, SIGNING_DATA_MISMATCH, SIGNING_DATA_ABSENT, SIGNING_VERIFIER_UNAVAILABLE, SIGNING_EXPECTATION_UNAVAILABLE, } from './signing-check.js';
|
|
10
|
+
export type { SigningSummary, ExpectedLeg, ExpectedOperation, Expectation } from './signing-check.js';
|
|
11
|
+
export type { BeforeSign } from './resources/execute.js';
|
|
18
12
|
//# 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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,cAAc,CAAC;AAI7B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAIzE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EACL,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EACnI,qBAAqB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,+BAA+B,GAC1G,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtG,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// shared
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
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';
|
|
21
|
-
// One resolver, shared by the CLI and MCP. Two copies of this would drift — see sign-target.ts.
|
|
22
|
-
export { resolveSignTarget } from './sign-target.js';
|
|
23
|
-
// An autonomous agent's identity and every proof-gated verb it needs, composed once. See agent.ts.
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's default entry (Node): everything in the browser-safe surface, plus the two parts that need Node.
|
|
3
|
+
* See browser.ts for the portable half and why the split exists.
|
|
4
|
+
*/
|
|
5
|
+
export * from './browser.js';
|
|
6
|
+
// Standalone on purpose: redeeming a share link needs no API key and therefore no client. Node-only because a shared bundle may be
|
|
7
|
+
// gzipped (node:zlib). See shared-proof.ts.
|
|
8
|
+
export { fetchSharedProof, decodeSharedBundle } from './shared-proof.js';
|
|
9
|
+
// An autonomous agent's identity and every proof-gated verb it needs, composed once. Node-only: it holds and uses a local ed25519 key
|
|
10
|
+
// through node:crypto. See agent.ts.
|
|
24
11
|
export { CertenAgent, ed25519Signer } from './agent.js';
|
|
12
|
+
export { CertenSigningDataError, checkIntentSigning, checkCosigning, checkGovernanceSigning, inspectSigningData, legsFromIntent, toBaseUnits, SIGNING_DATA_MISMATCH, SIGNING_DATA_ABSENT, SIGNING_VERIFIER_UNAVAILABLE, SIGNING_EXPECTATION_UNAVAILABLE, } from './signing-check.js';
|
|
25
13
|
//# 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
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,cAAc,CAAC;AAE7B,mIAAmI;AACnI,4CAA4C;AAC5C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEzE,sIAAsI;AACtI,qCAAqC;AACrC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGxD,OAAO,EACL,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EACnI,qBAAqB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,+BAA+B,GAC1G,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an intent can be, and what each place means.
|
|
3
|
+
*
|
|
4
|
+
* ONE table, used by `execute.wait()`, the CLI and the MCP server, so they cannot disagree about which statuses end a wait. Before
|
|
5
|
+
* this there were three copies of `['completed', 'delivered', 'proven']`, and none of them knew the two states the execution
|
|
6
|
+
* outcome model added:
|
|
7
|
+
*
|
|
8
|
+
* - `executed`: the action EXECUTED on its chain and its proof bundle is pending. Not a failure, and not terminal: CERTEN produces
|
|
9
|
+
* the bundle automatically and the intent then reads `completed`. The fee is held meanwhile.
|
|
10
|
+
* - `completed_unproven`: the action executed and its proof can NEVER be produced (declared by an operator with the evidence).
|
|
11
|
+
* Terminal. Billed gas only, fee waived. It is never "completed": nothing can be verified for it.
|
|
12
|
+
*
|
|
13
|
+
* `expired` is terminal too, and a failure: the intent will never execute. `wait()` used to poll through it to its timeout.
|
|
14
|
+
*
|
|
15
|
+
* The statuses are the gateway's own (`chk_intent_status`, api-gateway migration 053) and the spec's description of the field.
|
|
16
|
+
* `delivered` and `error` are older spellings this client has always treated as terminal; they stay in the table so a gateway that
|
|
17
|
+
* still sends them is not misread. A status that is not in the table is `unknown` and is never treated as terminal.
|
|
18
|
+
*/
|
|
19
|
+
/** What a status means for a caller waiting on the intent. */
|
|
20
|
+
export type IntentStatusClass =
|
|
21
|
+
/** Opened or in progress; nothing has executed. Keep waiting. */
|
|
22
|
+
'in_flight'
|
|
23
|
+
/** Executed on its chain; the proof bundle is pending. Not terminal, not a failure. Keep waiting for `completed`. */
|
|
24
|
+
| 'executed'
|
|
25
|
+
/** Executed and proven. Terminal. */
|
|
26
|
+
| 'terminal_success'
|
|
27
|
+
/** Executed and its proof can never be produced. Terminal; gas-only billing. */
|
|
28
|
+
| 'terminal_gas_only'
|
|
29
|
+
/** Will never execute. Terminal. */
|
|
30
|
+
| 'terminal_failure'
|
|
31
|
+
/** A status this client does not know. Not terminal: more waiting cannot make it worse, and calling it done could. */
|
|
32
|
+
| 'unknown';
|
|
33
|
+
export declare const INTENT_STATUS_CLASS: {
|
|
34
|
+
readonly created: "in_flight";
|
|
35
|
+
readonly signing_required: "in_flight";
|
|
36
|
+
readonly submitted: "in_flight";
|
|
37
|
+
readonly processing: "in_flight";
|
|
38
|
+
readonly anchoring: "in_flight";
|
|
39
|
+
readonly executed: "executed";
|
|
40
|
+
readonly completed: "terminal_success";
|
|
41
|
+
readonly proven: "terminal_success";
|
|
42
|
+
readonly delivered: "terminal_success";
|
|
43
|
+
readonly completed_unproven: "terminal_gas_only";
|
|
44
|
+
readonly failed: "terminal_failure";
|
|
45
|
+
readonly expired: "terminal_failure";
|
|
46
|
+
readonly error: "terminal_failure";
|
|
47
|
+
};
|
|
48
|
+
export type KnownIntentStatus = keyof typeof INTENT_STATUS_CLASS;
|
|
49
|
+
/** The reason the gateway gives a `completed_unproven` intent: the proof can never be produced. */
|
|
50
|
+
export declare const EXECUTION_PROOF_UNAVAILABLE = "execution_proof_unavailable";
|
|
51
|
+
export declare function classifyIntentStatus(status: unknown): IntentStatusClass;
|
|
52
|
+
/** Does this status end a wait (success, gas-only, or failure)? `executed` and `unknown` do not. */
|
|
53
|
+
export declare function isTerminalIntentStatus(status: unknown): boolean;
|
|
54
|
+
/** What happened to the action itself, which is what a caller usually wants to branch on. */
|
|
55
|
+
export type IntentOutcomeName = 'completed' | 'completed_unproven' | 'executed' | 'failed'
|
|
56
|
+
/** Nothing has executed yet. */
|
|
57
|
+
| 'pending' | 'unknown';
|
|
58
|
+
export interface IntentOutcome {
|
|
59
|
+
/** The gateway's status, verbatim. */
|
|
60
|
+
status: string;
|
|
61
|
+
class: IntentStatusClass;
|
|
62
|
+
terminal: boolean;
|
|
63
|
+
outcome: IntentOutcomeName;
|
|
64
|
+
/**
|
|
65
|
+
* Why, as a stable value. For `completed_unproven` this is always `execution_proof_unavailable`; for a failure it is the gateway's
|
|
66
|
+
* `reason_code`; otherwise null.
|
|
67
|
+
*/
|
|
68
|
+
reason: string | null;
|
|
69
|
+
}
|
|
70
|
+
/** Read the named outcome off a transaction response. Never invents a state: an unrecognised status is `unknown`. */
|
|
71
|
+
export declare function intentOutcome(tx: {
|
|
72
|
+
status?: unknown;
|
|
73
|
+
reason_code?: unknown;
|
|
74
|
+
} | null | undefined): IntentOutcome;
|
|
75
|
+
//# sourceMappingURL=intent-states.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-states.d.ts","sourceRoot":"","sources":["../src/intent-states.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,iBAAiB;AAC3B,iEAAiE;AAC/D,WAAW;AACb,qHAAqH;GACnH,UAAU;AACZ,qCAAqC;GACnC,kBAAkB;AACpB,gFAAgF;GAC9E,mBAAmB;AACrB,oCAAoC;GAClC,kBA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