UNPKG

@nktkas/hyperliquid

Version:

Hyperliquid API SDK for all major JS runtimes, written in TypeScript.

159 lines 7.34 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ConvertToMultiSigUserTypes = exports.ConvertToMultiSigUserResponse = exports.ConvertToMultiSigUserRequest = void 0; exports.convertToMultiSigUser = convertToMultiSigUser; const v = __importStar(require("valibot")); // ============================================================ // API Schemas // ============================================================ const _schemas_js_1 = require("../../_schemas.js"); const schemas_js_1 = require("./_base/schemas.js"); /** Signers configuration for {@linkcode ConvertToMultiSigUserRequest}. */ const ConvertToMultiSigUserRequestSigners = /* @__PURE__ */ (() => { return v.pipe(v.union([ v.object({ /** List of authorized user addresses. */ authorizedUsers: v.pipe(v.array(_schemas_js_1.Address), v.description("List of authorized user addresses.")), /** Minimum number of signatures required. */ threshold: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Minimum number of signatures required.")), }), /** Convert a multi-signature account to a single-signature account. */ v.pipe(v.null(), v.description("Convert a multi-signature account to a single-signature account.")), ]), v.description("Signers configuration for `ConvertToMultiSigUserRequest`")); })(); /** * Convert a single-signature account to a multi-signature account or vice versa. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig */ exports.ConvertToMultiSigUserRequest = (() => { return v.pipe(v.object({ /** Action to perform. */ action: v.pipe(v.object({ /** Type of action. */ type: v.pipe(v.literal("convertToMultiSigUser"), v.description("Type of action.")), /** Chain ID in hex format for EIP-712 signing. */ signatureChainId: schemas_js_1.SignatureChainId, /** HyperLiquid network type. */ hyperliquidChain: schemas_js_1.HyperliquidChain, /** * Signers configuration. * * Must be {@linkcode ConvertToMultiSigUserRequestSigners} converted to a string via `JSON.stringify(...)`. */ signers: v.pipe(v.union([ v.pipe(v.string(), v.parseJson(), ConvertToMultiSigUserRequestSigners, v.stringifyJson()), v.pipe(ConvertToMultiSigUserRequestSigners, v.stringifyJson()), ]), v.description("Signers configuration." + "\n\nMust be `ConvertToMultiSigUserRequestSigners` converted to a string via `JSON.stringify(...)`.")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: schemas_js_1.Nonce, }), v.description("Action to perform.")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: schemas_js_1.Nonce, /** ECDSA signature components. */ signature: schemas_js_1.Signature, }), v.description("Convert a single-signature account to a multi-signature account or vice versa.")); })(); /** * Successful response without specific data or error response. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig */ exports.ConvertToMultiSigUserResponse = (() => { return v.pipe(v.union([schemas_js_1.SuccessResponse, schemas_js_1.ErrorResponse]), v.description("Successful response without specific data or error response.")); })(); // ============================================================ // Execution Logic // ============================================================ const execute_js_1 = require("./_base/execute.js"); /** Schema for user-provided action parameters (excludes system fields). */ const ConvertToMultiSigUserParameters = /* @__PURE__ */ (() => { return v.omit(v.object(exports.ConvertToMultiSigUserRequest.entries.action.entries), ["type", "signatureChainId", "hyperliquidChain", "nonce"]); })(); /** EIP-712 types for the {@linkcode convertToMultiSigUser} function. */ exports.ConvertToMultiSigUserTypes = { "HyperliquidTransaction:ConvertToMultiSigUser": [ { name: "hyperliquidChain", type: "string" }, { name: "signers", type: "string" }, { name: "nonce", type: "uint64" }, ], }; /** * Convert a single-signature account to a multi-signature account or vice versa. * * @param config - General configuration for Exchange API requests. * @param params - Parameters specific to the API request. * @param opts - Request execution options. * * @returns Successful response without specific data. * * @throws {ValiError} When the request parameters fail validation (before sending). * @throws {TransportError} When the transport layer throws an error. * @throws {ApiRequestError} When the API returns an unsuccessful response. * * @example * ```ts * import { HttpTransport } from "@nktkas/hyperliquid"; * import { convertToMultiSigUser } from "@nktkas/hyperliquid/api/exchange"; * import { privateKeyToAccount } from "npm:viem/accounts"; * * const wallet = privateKeyToAccount("0x..."); // viem or ethers * const transport = new HttpTransport(); // or `WebSocketTransport` * * // Convert to multi-sig user * await convertToMultiSigUser( * { transport, wallet }, * { * signers: { * authorizedUsers: ["0x...", "0x...", "0x..."], * threshold: 2, * }, * }, * ); * * // Convert to single-sig user * await convertToMultiSigUser( * { transport, wallet }, * { signers: null }, * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig */ function convertToMultiSigUser(config, params, opts) { const action = v.parse(ConvertToMultiSigUserParameters, params); return (0, execute_js_1.executeUserSignedAction)(config, { type: "convertToMultiSigUser", ...action }, exports.ConvertToMultiSigUserTypes, opts); } //# sourceMappingURL=convertToMultiSigUser.js.map