@coinbase/cdp-sdk
Version:
SDK for interacting with the Coinbase Developer Platform Wallet API
180 lines • 6.23 kB
JavaScript
import { z } from "zod";
/**
* Enum for Action types
*/
export const ActionEnum = z.enum(["reject", "accept"]);
/**
* Enum for SolAddressOperator values
*/
export const SolAddressOperatorEnum = z.enum(["in", "not in"]);
/**
* Enum for SolValueOperator values
*/
export const SolValueOperatorEnum = z.enum([">", ">=", "<", "<=", "=="]);
/**
* Enum for SplAddressOperator values
*/
export const SplAddressOperatorEnum = z.enum(["in", "not in"]);
/**
* Enum for SplValueOperator values
*/
export const SplValueOperatorEnum = z.enum([">", ">=", "<", "<=", "=="]);
/**
* Enum for MintAddressOperator values
*/
export const MintAddressOperatorEnum = z.enum(["in", "not in"]);
/**
* Schema for Solana address criterions
*/
export const SolAddressCriterionSchema = z.object({
/** The type of criterion, must be "solAddress" for Solana address-based rules. */
type: z.literal("solAddress"),
/**
* Array of Solana addresses to compare against.
* Each address must be a valid Base58-encoded Solana address (32-44 characters).
*/
addresses: z.array(z.string().regex(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/)),
/**
* The operator to use for evaluating transaction addresses.
* "in" checks if an address is in the provided list.
* "not in" checks if an address is not in the provided list.
*/
operator: SolAddressOperatorEnum,
});
/**
* Schema for SOL value criterions
*/
export const SolValueCriterionSchema = z.object({
/** The type of criterion, must be "solValue" for SOL value-based rules. */
type: z.literal("solValue"),
/**
* The SOL value amount in lamports to compare against, as a string.
* Must contain only digits.
*/
solValue: z.string().regex(/^[0-9]+$/),
/** The comparison operator to use for evaluating transaction SOL values against the threshold. */
operator: SolValueOperatorEnum,
});
/**
* Schema for SPL address criterions
*/
export const SplAddressCriterionSchema = z.object({
/** The type of criterion, must be "splAddress" for SPL address-based rules. */
type: z.literal("splAddress"),
/**
* Array of Solana addresses to compare against for SPL token transfer recipients.
* Each address must be a valid Base58-encoded Solana address (32-44 characters).
*/
addresses: z.array(z.string().regex(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/)),
/**
* The operator to use for evaluating SPL token transfer recipient addresses.
* "in" checks if an address is in the provided list.
* "not in" checks if an address is not in the provided list.
*/
operator: SplAddressOperatorEnum,
});
/**
* Schema for SPL value criterions
*/
export const SplValueCriterionSchema = z.object({
/** The type of criterion, must be "splValue" for SPL token value-based rules. */
type: z.literal("splValue"),
/**
* The SPL token value amount to compare against, as a string.
* Must contain only digits.
*/
splValue: z.string().regex(/^[0-9]+$/),
/** The comparison operator to use for evaluating SPL token values against the threshold. */
operator: SplValueOperatorEnum,
});
/**
* Schema for mint address criterions
*/
export const MintAddressCriterionSchema = z.object({
/** The type of criterion, must be "mintAddress" for token mint address-based rules. */
type: z.literal("mintAddress"),
/**
* Array of Solana addresses to compare against for token mint addresses.
* Each address must be a valid Base58-encoded Solana address (32-44 characters).
*/
addresses: z.array(z.string().regex(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/)),
/**
* The operator to use for evaluating token mint addresses.
* "in" checks if an address is in the provided list.
* "not in" checks if an address is not in the provided list.
*/
operator: MintAddressOperatorEnum,
});
/**
* Schema for criteria used in SignSolTransaction operations
*/
export const SignSolTransactionCriteriaSchema = z
.array(z.discriminatedUnion("type", [
SolAddressCriterionSchema,
SolValueCriterionSchema,
SplAddressCriterionSchema,
SplValueCriterionSchema,
MintAddressCriterionSchema,
]))
.max(10)
.min(1);
/**
* Schema for criteria used in SendSolTransaction operations
*/
export const SendSolTransactionCriteriaSchema = z
.array(z.discriminatedUnion("type", [
SolAddressCriterionSchema,
SolValueCriterionSchema,
SplAddressCriterionSchema,
SplValueCriterionSchema,
MintAddressCriterionSchema,
]))
.max(10)
.min(1);
/**
* Enum for Solana Operation types
*/
export const SolOperationEnum = z.enum(["signSolTransaction", "sendSolTransaction"]);
/**
* Type representing a 'signSolTransaction' policy rule that can accept or reject specific operations
* based on a set of criteria.
*/
export const SignSolTransactionRuleSchema = z.object({
/**
* Determines whether matching the rule will cause a request to be rejected or accepted.
* "accept" will allow the transaction, "reject" will block it.
*/
action: ActionEnum,
/**
* The operation to which this rule applies.
* Must be "signSolTransaction".
*/
operation: z.literal("signSolTransaction"),
/**
* The set of criteria that must be matched for this rule to apply.
* Must be compatible with the specified operation type.
*/
criteria: SignSolTransactionCriteriaSchema,
});
/**
* Type representing a 'sendSolTransaction' policy rule that can accept or reject specific operations
* based on a set of criteria.
*/
export const SendSolTransactionRuleSchema = z.object({
/**
* Determines whether matching the rule will cause a request to be rejected or accepted.
* "accept" will allow the transaction, "reject" will block it.
*/
action: ActionEnum,
/**
* The operation to which this rule applies.
* Must be "sendSolTransaction".
*/
operation: z.literal("sendSolTransaction"),
/**
* The set of criteria that must be matched for this rule to apply.
* Must be compatible with the specified operation type.
*/
criteria: SendSolTransactionCriteriaSchema,
});
//# sourceMappingURL=solanaSchema.js.map