@bitgo/public-types 5.96.2 → 6.0.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/dist/src/schema/mpcv2/signing/eddsaSigningRound.d.ts +61 -0
- package/dist/src/schema/mpcv2/signing/eddsaSigningRound.js +75 -0
- package/dist/src/schema/mpcv2/signing/eddsaSigningRound.js.map +1 -0
- package/dist/src/schema/mpcv2/signing/index.d.ts +1 -0
- package/dist/src/schema/mpcv2/signing/index.js +1 -0
- package/dist/src/schema/mpcv2/signing/index.js.map +1 -1
- package/dist/src/schema/transactionRequest/intents/intent.d.ts +40 -26
- package/dist/src/schema/transactionRequest/intents/solAuthorizeIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solBuildOptions.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solBuildOptions.js +2 -3
- package/dist/src/schema/transactionRequest/intents/solBuildOptions.js.map +1 -1
- package/dist/src/schema/transactionRequest/intents/solClaimIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solCloseAssociatedTokenAccountIntent.d.ts +32 -5
- package/dist/src/schema/transactionRequest/intents/solCloseAssociatedTokenAccountIntent.js +18 -2
- package/dist/src/schema/transactionRequest/intents/solCloseAssociatedTokenAccountIntent.js.map +1 -1
- package/dist/src/schema/transactionRequest/intents/solCreateAssociatedTokenAccountIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solCustomTxIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solDeactivateIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solDelegateIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solGoUnstakeIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solPaymentIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/intents/solStakeIntent.d.ts +4 -4
- package/dist/src/schema/transactionRequest/intents/solUnstakeIntent.d.ts +4 -4
- package/dist/src/schema/transactionRequest/intents/solVersionedCustomTxIntent.d.ts +2 -2
- package/dist/src/schema/transactionRequest/message.d.ts +3 -0
- package/dist/src/schema/transactionRequest/transaction.d.ts +3 -0
- package/dist/src/schema/transactionRequest/transactionRequest.d.ts +92 -52
- package/dist/src/schema/transactionRequest/transactionState.d.ts +3 -0
- package/dist/src/schema/transactionRequest/transactionState.js +3 -0
- package/dist/src/schema/transactionRequest/transactionState.js.map +1 -1
- package/dist/src/schema/webhook/addWalletWebhookRequest.d.ts +2 -2
- package/dist/src/schema/webhook/enterpriseWebhooks.d.ts +3 -0
- package/dist/src/schema/webhook/organizationWebhooks.d.ts +3 -0
- package/dist/src/schema/webhook/webhook.d.ts +3 -0
- package/dist/src/utils/getAssetsFromIntent.js +13 -4
- package/dist/src/utils/getAssetsFromIntent.js.map +1 -1
- package/package.json +1 -1
- package/src/schema/mpcv2/signing/eddsaSigningRound.ts +117 -0
- package/src/schema/mpcv2/signing/index.ts +1 -0
- package/src/schema/transactionRequest/intents/solBuildOptions.ts +20 -3
- package/src/schema/transactionRequest/intents/solCloseAssociatedTokenAccountIntent.ts +94 -5
- package/src/schema/transactionRequest/transactionState.ts +3 -0
- package/src/utils/getAssetsFromIntent.ts +21 -4
|
@@ -1,21 +1,110 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { Address } from "./address";
|
|
2
3
|
import { BaseIntent } from "./baseIntent";
|
|
3
4
|
import { intentTypes } from "./intentType";
|
|
5
|
+
import { RecipientEntry } from "./recipientEntry";
|
|
4
6
|
import { SolBuildOptions } from "./solBuildOptions";
|
|
5
7
|
|
|
8
|
+
/**
|
|
9
|
+
* One close-ATA recipient row: ATA in `address.address`, zero placeholder amount,
|
|
10
|
+
* no token payload. Narrower than {@link RecipientEntry} for compile-time use
|
|
11
|
+
* when you annotate with this type after a successful decode.
|
|
12
|
+
*
|
|
13
|
+
* **Address typing:** {@link Address} is `t.partial` in io-ts, so
|
|
14
|
+
* `t.TypeOf<typeof RecipientEntry>["address"]` still allows a missing inner
|
|
15
|
+
* `address`. The refinement rejects non-strings at **runtime**, but io-ts does
|
|
16
|
+
* not narrow `TypeOf` on refinements—so `decode(...).right` alone will not show
|
|
17
|
+
* `address.address` as required. Use this named type (via
|
|
18
|
+
* {@link SolCloseAssociatedTokenAccountIntent}) for the stricter contract; do
|
|
19
|
+
* not widen back to plain `t.TypeOf<typeof SolCloseAssociatedTokenAccountIntent>`
|
|
20
|
+
* if you need the guarantee on `address.address`.
|
|
21
|
+
*
|
|
22
|
+
* `amount.value` must be the **exact string** `"0"`. The refinement uses string
|
|
23
|
+
* equality (not numeric parsing), so `"0.0"`, `"0.00"`, `"00"`, `"-0"`, `"0x0"`,
|
|
24
|
+
* etc. are rejected. Construct close-ATA placeholders with the literal `"0"`.
|
|
25
|
+
*
|
|
26
|
+
* `amount.symbol` follows {@link RecipientEntry} / `Amount`: any string
|
|
27
|
+
* (including `""`); it is not validated as a ticker and is ignored for asset extraction.
|
|
28
|
+
*/
|
|
29
|
+
export type SolCloseAssociatedTokenAccountRecipient = {
|
|
30
|
+
// Intersection tightens Address.address from string | undefined to required string.
|
|
31
|
+
address: Address & { address: string };
|
|
32
|
+
amount: { value: "0"; symbol: string };
|
|
33
|
+
/**
|
|
34
|
+
* Matches {@link RecipientEntry} / `optionalString` (`string | undefined`).
|
|
35
|
+
* Note: the underlying codec is `t.partial({ data: optionalString })`, so the
|
|
36
|
+
* key may also be absent at runtime; in TS the three states (absent,
|
|
37
|
+
* `undefined`, `string`) collapse to `string | undefined` here.
|
|
38
|
+
*/
|
|
39
|
+
data?: string | undefined;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function isSolCloseAssociatedTokenAccountRecipient(
|
|
43
|
+
recipient: RecipientEntry,
|
|
44
|
+
): recipient is SolCloseAssociatedTokenAccountRecipient {
|
|
45
|
+
if (recipient.amount.value !== "0") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const recipientRecord = recipient as Record<string, unknown>;
|
|
49
|
+
// RecipientEntry’s codec does not declare token fields; io-ts still accepts
|
|
50
|
+
// extra keys, and values widened from richer recipient shapes may carry them.
|
|
51
|
+
if ("tokenName" in recipientRecord || "tokenData" in recipientRecord) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const addressFields = recipient.address as { address?: unknown };
|
|
55
|
+
if (typeof addressFields?.address !== "string") {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Internal io-ts refinement for one close-ATA recipient row (not exported).
|
|
63
|
+
*
|
|
64
|
+
* io-ts does not propagate refinement predicates into `TypeOf`, so
|
|
65
|
+
* `decode(...).right` is still typed as {@link RecipientEntry}. For the narrowed
|
|
66
|
+
* row shape after validation, use {@link SolCloseAssociatedTokenAccountRecipient}
|
|
67
|
+
* (see {@link SolCloseAssociatedTokenAccountIntent}’s exported type, which
|
|
68
|
+
* overrides `recipients` accordingly).
|
|
69
|
+
*/
|
|
70
|
+
const solCloseAssociatedTokenAccountRecipientEntry = t.refinement(
|
|
71
|
+
RecipientEntry,
|
|
72
|
+
isSolCloseAssociatedTokenAccountRecipient,
|
|
73
|
+
"SolCloseAssociatedTokenAccountRecipientEntry",
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const solCloseAssociatedTokenAccountRecipients = t.refinement(
|
|
77
|
+
t.array(solCloseAssociatedTokenAccountRecipientEntry),
|
|
78
|
+
(recipients) => recipients.length > 0,
|
|
79
|
+
"SolCloseAssociatedTokenAccountRecipients",
|
|
80
|
+
);
|
|
81
|
+
|
|
6
82
|
/**
|
|
7
83
|
* @title SOL Close Associated Token Account Intent
|
|
84
|
+
*
|
|
85
|
+
* After `decode`, prefer annotating or threading values as the exported
|
|
86
|
+
* {@link SolCloseAssociatedTokenAccountIntent} **type alias** (below), not raw
|
|
87
|
+
* `t.TypeOf<typeof SolCloseAssociatedTokenAccountIntent>` from io-ts alone, so
|
|
88
|
+
* `recipients` rows keep {@link SolCloseAssociatedTokenAccountRecipient} narrowing
|
|
89
|
+
* (see codec / refinement limitations in that type’s docblock).
|
|
8
90
|
*/
|
|
9
91
|
export const SolCloseAssociatedTokenAccountIntent = t.intersection([
|
|
10
92
|
BaseIntent,
|
|
11
93
|
SolBuildOptions,
|
|
12
94
|
t.type({
|
|
13
95
|
intentType: intentTypes.closeAssociatedTokenAccount,
|
|
14
|
-
|
|
15
|
-
destinationAddress: t.string,
|
|
96
|
+
recipients: solCloseAssociatedTokenAccountRecipients,
|
|
16
97
|
}),
|
|
17
98
|
]);
|
|
18
99
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Intent shape with narrowed `recipients`; use this after `decode` instead of
|
|
102
|
+
* relying only on `t.TypeOf<typeof SolCloseAssociatedTokenAccountIntent>` from
|
|
103
|
+
* the codec so recipient `address.address` and `amount.value` typing match runtime rules.
|
|
104
|
+
*/
|
|
105
|
+
export type SolCloseAssociatedTokenAccountIntent = Omit<
|
|
106
|
+
t.TypeOf<typeof SolCloseAssociatedTokenAccountIntent>,
|
|
107
|
+
"recipients"
|
|
108
|
+
> & {
|
|
109
|
+
recipients: SolCloseAssociatedTokenAccountRecipient[];
|
|
110
|
+
};
|
|
@@ -5,6 +5,17 @@ import {
|
|
|
5
5
|
BaseIntentWithTokenName,
|
|
6
6
|
BaseIntentWithAmount,
|
|
7
7
|
} from "../schema/transactionRequest/intents/baseIntent";
|
|
8
|
+
import { intentTypes } from "../schema/transactionRequest/intents/intentType";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `intentType` values for intents that decode as `BaseIntentWithRecipients`
|
|
12
|
+
* but use `recipients[].amount.symbol` as a non-asset placeholder (do not extract).
|
|
13
|
+
* Extend this set when adding similar intents; a schema-driven marker would be
|
|
14
|
+
* a larger refactor.
|
|
15
|
+
*/
|
|
16
|
+
const INTENT_TYPES_SKIP_RECIPIENT_AMOUNT_SYMBOL_AS_ASSET = new Set<string>([
|
|
17
|
+
intentTypes.closeAssociatedTokenAccount.value,
|
|
18
|
+
]);
|
|
8
19
|
|
|
9
20
|
/**
|
|
10
21
|
* Extracts all asset-related strings from a transaction intent
|
|
@@ -34,10 +45,16 @@ export function getAssetsFromIntent(intent: unknown): string[] {
|
|
|
34
45
|
// Extracts: symbol from amount field
|
|
35
46
|
const recipientsDecoded = BaseIntentWithRecipients.decode(intent);
|
|
36
47
|
if (isRight(recipientsDecoded)) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
const intentType = (intent as Record<string, unknown>)["intentType"];
|
|
49
|
+
const skipRecipientAmountSymbol =
|
|
50
|
+
typeof intentType === "string" &&
|
|
51
|
+
INTENT_TYPES_SKIP_RECIPIENT_AMOUNT_SYMBOL_AS_ASSET.has(intentType);
|
|
52
|
+
if (!skipRecipientAmountSymbol) {
|
|
53
|
+
const data = recipientsDecoded.right;
|
|
54
|
+
for (const recipient of data.recipients) {
|
|
55
|
+
if (recipient.amount?.symbol) {
|
|
56
|
+
assetStrings.add(recipient.amount.symbol);
|
|
57
|
+
}
|
|
41
58
|
}
|
|
42
59
|
}
|
|
43
60
|
}
|