Skip to content

Signer.all

Several signers as one. The sender of a transaction says which of them signs it.

team.ts
import { Config, Effect, Layer } from "effect";
import { Address, Signer } from "@ethect/core";
/** Signs a digest with the key of the treasury, held by a KMS. */
declare const kmsSign: (digest: `0x${string}`) => Effect.Effect<`0x${string}`, Signer.Error>;
export const Team = Layer.unwrap(
Effect.gen(function* () {
const key = yield* Config.Redacted("PRIVATE_KEY");
const treasury = yield* Address.make(yield* Config.String("TREASURY_ADDRESS"));
return Signer.all(
Signer.privateKey(key),
Signer.fromSign({ address: treasury, sign: kmsSign }),
);
}),
);
const program = Effect.gen(function* () {
const [hot, treasury] = yield* Signer.accounts;
// the key signs this one: its account is the first, the sender when none is given
const mine = yield* Signer.signMessage("from the hot key");
const theirs = yield* Signer.signMessage("from the treasury", { from: treasury! });
return { hot, mine, theirs };
}).pipe(Effect.provide(Team));

Everything that takes a sender routes by it: from in Tx.send and in the functions that sign, the account of a Tx.Step, the account of Signer.capabilities.

Any signer fits, not only those that sign here. What the result needs and can fail with is what its signers need and can fail with.

import { Config, Effect, Layer } from "effect";
import { type Eip1193, Signer } from "@ethect/core";
const withWallet = (provider: Eip1193.Provider) =>
Layer.unwrap(
Effect.map(Config.Redacted("PRIVATE_KEY"), (key) =>
Signer.all(Signer.wallet(provider), Signer.privateKey(key)),
),
);
// Layer<Signer.Signer, Signer.Error | ConfigError>

Layer<Signer.Signer, E, R>

A layer that provides one Signer service over all of them. E is what building any of the signers can fail with, and R what any of them needs.

  • Type: ReadonlyArray<Layer<Signer.Signer, any, any>>

The signers, in order. The order decides the first account, and who signs for an account two of them hold.

  • Every account of every signer. Signer.accounts gives them in the order of the signers, each address once.
  • from picks the signer. Each signer is asked in turn for its accounts, and the first that holds the sender signs.
  • An address held twice goes to the first. The others are never asked to sign for it.
  • An account nobody holds is refused with "Unauthorized".
  • A signer that cannot say what it holds is passed over when another holds the sender. A wallet that is not connected does not stop a key from signing. When nobody else holds the sender, the failure is that signer’s own.
  • A handle goes back to the signer of its account. Tx.wait asks the signer that gave it.
  • Each signer keeps its own way with nonces. Signers of the same account on the same transport share one counter.
Error Reason When
Signer.Error "Unauthorized" no signer holds the account asked for
what a signer fails with building it, listing its accounts, or signing with it
  1. Signer.accounts

    1. each signerits accounts, in order
  2. anything with a sender

    1. each signerits accounts in turn, until one holds it
    2. that signerthen its own function, with the same arguments

A local signer answers accounts without asking anyone. A wallet answers from what it knows, or asks eth_accounts.