UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

56 lines (54 loc) • 1.97 kB
import { colors } from "../../utils/theme.mjs"; import { ensureCustodyBalance, submitRegistryWriteCustody } from "./custody-signer.mjs"; import { ensureDelegateKey, submitRegistryWriteDelegated } from "./delegate-signer.mjs"; import { submitRegistryWrite } from "./near-signer.mjs"; import { Context, Layer } from "effect"; //#region src/services/auth/signer.ts /** The strategy dispatch, exported for the train's procedural deps. */ const dispatchSubmit = (input) => input.mode === "custody" ? (async () => { await ensureCustodyBalance(input.custodyWallet); console.log(` Signing via ${colors.cyan(`OutLayer custody wallet ${input.custodyWallet.nearAccountId}`)}`); return submitRegistryWriteCustody({ contract: input.contract, args: input.args, custodyWallet: input.custodyWallet, idempotencyKey: input.idempotencyKey }); })() : input.mode === "wallet" ? (async () => { const record = await ensureDelegateKey({ configDir: input.configDir, account: input.account, contract: input.contract, network: input.network, siteUrl: input.credential.siteUrl }); return submitRegistryWriteDelegated({ account: input.account, contract: input.contract, network: input.network, args: input.args, delegatePrivateKey: record.privateKey, relayEndpoint: `${input.credential.siteUrl}/api/auth/near/relay`, apiKey: input.credential.apiKey }); })() : submitRegistryWrite({ account: input.account, contract: input.contract, method: "__fastdata_kv", args: input.args, network: input.network, privateKey: input.privateKey }, input.strategy); var SignerService = class SignerService extends Context.Service()("everything-dev/auth/signer") { static Live = Layer.succeed(this, SignerService.of({ submitRegistryWrite, submitRegistryWriteDelegated, submitRegistryWriteCustody, ensureDelegateKey, ensureCustodyBalance, submit: dispatchSubmit })); }; //#endregion export { SignerService, dispatchSubmit }; //# sourceMappingURL=signer.mjs.map