@buildersgarden/siwa 0.0.13 → 0.0.15

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.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * circle.ts
3
+ *
4
+ * Circle developer-controlled wallet signer implementation.
5
+ */
6
+ import type { CircleDeveloperControlledWalletsClient } from "@circle-fin/developer-controlled-wallets";
7
+ import type { Address } from "viem";
8
+ import type { Signer } from "./types.js";
9
+ /**
10
+ * Configuration for the Circle SIWA signer.
11
+ */
12
+ export interface CircleSiwaSignerConfig {
13
+ /** Circle API key */
14
+ apiKey: string;
15
+ /** Circle entity secret */
16
+ entitySecret: string;
17
+ /** Circle wallet ID */
18
+ walletId: string;
19
+ /** Wallet address (optional - will be fetched from Circle if not provided) */
20
+ walletAddress?: Address;
21
+ }
22
+ /**
23
+ * Configuration using an existing Circle client.
24
+ */
25
+ export interface CircleSiwaSignerClientConfig {
26
+ /** Existing Circle client instance */
27
+ client: CircleDeveloperControlledWalletsClient;
28
+ /** Circle wallet ID */
29
+ walletId: string;
30
+ /** Wallet address (optional - will be fetched from Circle if not provided) */
31
+ walletAddress?: Address;
32
+ }
33
+ /**
34
+ * Creates a SIWA Signer that wraps Circle's developer-controlled wallet SDK.
35
+ *
36
+ * This signer implements the core Signer interface for SIWA message signing.
37
+ * It supports both standard message signing (EIP-191) and raw hex signing
38
+ * for ERC-8128 HTTP message signatures.
39
+ *
40
+ * The wallet address can be provided explicitly or fetched automatically
41
+ * from Circle using the wallet ID.
42
+ *
43
+ * @param config - Circle wallet configuration
44
+ * @returns A Promise that resolves to a Signer compatible with SIWA's signSIWAMessage function
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * import { signSIWAMessage, generateNonce } from '@buildersgarden/siwa/siwa';
49
+ * import { createCircleSiwaSigner } from '@buildersgarden/siwa/signer';
50
+ *
51
+ * // Address is fetched automatically from Circle
52
+ * const signer = await createCircleSiwaSigner({
53
+ * apiKey: process.env.CIRCLE_API_KEY!,
54
+ * entitySecret: process.env.CIRCLE_ENTITY_SECRET!,
55
+ * walletId: 'your-wallet-id',
56
+ * });
57
+ *
58
+ * const { message, signature, address } = await signSIWAMessage({
59
+ * domain: 'example.com',
60
+ * uri: 'https://example.com/login',
61
+ * agentId: 123,
62
+ * agentRegistry: 'eip155:84532:0x...',
63
+ * chainId: 84532,
64
+ * nonce: generateNonce(),
65
+ * issuedAt: new Date().toISOString(),
66
+ * }, signer);
67
+ * ```
68
+ */
69
+ export declare function createCircleSiwaSigner(config: CircleSiwaSignerConfig): Promise<Signer>;
70
+ /**
71
+ * Creates a SIWA Signer from an existing Circle client instance.
72
+ *
73
+ * Use this when you already have a Circle client initialized and want
74
+ * to reuse it for SIWA signing.
75
+ *
76
+ * @param config - Configuration with existing Circle client
77
+ * @returns A Promise that resolves to a Signer compatible with SIWA's signSIWAMessage function
78
+ */
79
+ export declare function createCircleSiwaSignerFromClient(config: CircleSiwaSignerClientConfig): Promise<Signer>;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * circle.ts
3
+ *
4
+ * Circle developer-controlled wallet signer implementation.
5
+ */
6
+ import { initiateDeveloperControlledWalletsClient } from "@circle-fin/developer-controlled-wallets";
7
+ /**
8
+ * Fetches wallet address from Circle API using the wallet ID.
9
+ */
10
+ async function fetchWalletAddress(client, walletId) {
11
+ const response = await client.getWallet({ id: walletId });
12
+ const address = response.data?.wallet?.address;
13
+ if (!address) {
14
+ throw new Error(`Failed to fetch wallet address for wallet ID: ${walletId}`);
15
+ }
16
+ return address;
17
+ }
18
+ /**
19
+ * Creates a SIWA Signer that wraps Circle's developer-controlled wallet SDK.
20
+ *
21
+ * This signer implements the core Signer interface for SIWA message signing.
22
+ * It supports both standard message signing (EIP-191) and raw hex signing
23
+ * for ERC-8128 HTTP message signatures.
24
+ *
25
+ * The wallet address can be provided explicitly or fetched automatically
26
+ * from Circle using the wallet ID.
27
+ *
28
+ * @param config - Circle wallet configuration
29
+ * @returns A Promise that resolves to a Signer compatible with SIWA's signSIWAMessage function
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { signSIWAMessage, generateNonce } from '@buildersgarden/siwa/siwa';
34
+ * import { createCircleSiwaSigner } from '@buildersgarden/siwa/signer';
35
+ *
36
+ * // Address is fetched automatically from Circle
37
+ * const signer = await createCircleSiwaSigner({
38
+ * apiKey: process.env.CIRCLE_API_KEY!,
39
+ * entitySecret: process.env.CIRCLE_ENTITY_SECRET!,
40
+ * walletId: 'your-wallet-id',
41
+ * });
42
+ *
43
+ * const { message, signature, address } = await signSIWAMessage({
44
+ * domain: 'example.com',
45
+ * uri: 'https://example.com/login',
46
+ * agentId: 123,
47
+ * agentRegistry: 'eip155:84532:0x...',
48
+ * chainId: 84532,
49
+ * nonce: generateNonce(),
50
+ * issuedAt: new Date().toISOString(),
51
+ * }, signer);
52
+ * ```
53
+ */
54
+ export async function createCircleSiwaSigner(config) {
55
+ const client = initiateDeveloperControlledWalletsClient({
56
+ apiKey: config.apiKey,
57
+ entitySecret: config.entitySecret,
58
+ });
59
+ return createCircleSiwaSignerFromClient({
60
+ client,
61
+ walletId: config.walletId,
62
+ ...(config.walletAddress && { walletAddress: config.walletAddress }),
63
+ });
64
+ }
65
+ /**
66
+ * Creates a SIWA Signer from an existing Circle client instance.
67
+ *
68
+ * Use this when you already have a Circle client initialized and want
69
+ * to reuse it for SIWA signing.
70
+ *
71
+ * @param config - Configuration with existing Circle client
72
+ * @returns A Promise that resolves to a Signer compatible with SIWA's signSIWAMessage function
73
+ */
74
+ export async function createCircleSiwaSignerFromClient(config) {
75
+ const { client, walletId } = config;
76
+ // Fetch wallet address from Circle if not provided
77
+ const walletAddress = config.walletAddress ?? (await fetchWalletAddress(client, walletId));
78
+ return {
79
+ /**
80
+ * Returns the wallet address.
81
+ */
82
+ async getAddress() {
83
+ return walletAddress;
84
+ },
85
+ /**
86
+ * Signs a message using EIP-191 personal_sign.
87
+ * Used for standard SIWA message signing.
88
+ */
89
+ async signMessage(message) {
90
+ const response = await client.signMessage({
91
+ walletId,
92
+ message,
93
+ encodedByHex: false,
94
+ });
95
+ const signature = response.data?.signature;
96
+ if (!signature) {
97
+ throw new Error("Circle signMessage failed: no signature returned");
98
+ }
99
+ return signature;
100
+ },
101
+ /**
102
+ * Signs raw hex bytes.
103
+ * Used by ERC-8128 for HTTP message signatures.
104
+ */
105
+ async signRawMessage(rawHex) {
106
+ // Strip 0x prefix if present for Circle API
107
+ const hexMessage = rawHex.startsWith("0x") ? rawHex.slice(2) : rawHex;
108
+ const response = await client.signMessage({
109
+ walletId,
110
+ message: hexMessage,
111
+ encodedByHex: true,
112
+ });
113
+ const signature = response.data?.signature;
114
+ if (!signature) {
115
+ throw new Error("Circle signRawMessage failed: no signature returned");
116
+ }
117
+ return signature;
118
+ },
119
+ };
120
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * signer/index.ts
3
+ *
4
+ * Wallet-agnostic signing abstraction for SIWA.
5
+ *
6
+ * This module provides a `Signer` interface that abstracts signing operations,
7
+ * allowing developers to use any wallet provider without changing the SDK.
8
+ *
9
+ * Available signer implementations:
10
+ * - createKeyringProxySigner(config) — Keyring proxy server (HMAC-authenticated)
11
+ * - createLocalAccountSigner(account) — viem LocalAccount (privateKeyToAccount)
12
+ * - createWalletClientSigner(client) — viem WalletClient (Privy, MetaMask, etc.)
13
+ * - createCircleSiwaSigner(config) — Circle developer-controlled wallet
14
+ * - createCircleSiwaSignerFromClient(config) — Circle with existing client
15
+ * - createPrivySiwaSigner(config) — Privy server wallet
16
+ *
17
+ * Usage:
18
+ * import { signSIWAMessage, createLocalAccountSigner } from '@buildersgarden/siwa';
19
+ * import { privateKeyToAccount } from 'viem/accounts';
20
+ *
21
+ * const account = privateKeyToAccount('0x...');
22
+ * const signer = createLocalAccountSigner(account);
23
+ * const { message, signature } = await signSIWAMessage(fields, signer);
24
+ */
25
+ export type { Signer, SignerType, TransactionSigner, TransactionRequest, KeyringProxyConfig, } from './types.js';
26
+ export { createKeyringProxySigner } from './keyring-proxy.js';
27
+ export { createLocalAccountSigner } from './local-account.js';
28
+ export { createWalletClientSigner } from './wallet-client.js';
29
+ export { createCircleSiwaSigner, createCircleSiwaSignerFromClient, type CircleSiwaSignerConfig, type CircleSiwaSignerClientConfig, } from './circle.js';
30
+ export { createPrivySiwaSigner, type PrivySiwaSignerConfig, } from './privy.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * signer/index.ts
3
+ *
4
+ * Wallet-agnostic signing abstraction for SIWA.
5
+ *
6
+ * This module provides a `Signer` interface that abstracts signing operations,
7
+ * allowing developers to use any wallet provider without changing the SDK.
8
+ *
9
+ * Available signer implementations:
10
+ * - createKeyringProxySigner(config) — Keyring proxy server (HMAC-authenticated)
11
+ * - createLocalAccountSigner(account) — viem LocalAccount (privateKeyToAccount)
12
+ * - createWalletClientSigner(client) — viem WalletClient (Privy, MetaMask, etc.)
13
+ * - createCircleSiwaSigner(config) — Circle developer-controlled wallet
14
+ * - createCircleSiwaSignerFromClient(config) — Circle with existing client
15
+ * - createPrivySiwaSigner(config) — Privy server wallet
16
+ *
17
+ * Usage:
18
+ * import { signSIWAMessage, createLocalAccountSigner } from '@buildersgarden/siwa';
19
+ * import { privateKeyToAccount } from 'viem/accounts';
20
+ *
21
+ * const account = privateKeyToAccount('0x...');
22
+ * const signer = createLocalAccountSigner(account);
23
+ * const { message, signature } = await signSIWAMessage(fields, signer);
24
+ */
25
+ // Signer implementations
26
+ export { createKeyringProxySigner } from './keyring-proxy.js';
27
+ export { createLocalAccountSigner } from './local-account.js';
28
+ export { createWalletClientSigner } from './wallet-client.js';
29
+ export { createCircleSiwaSigner, createCircleSiwaSignerFromClient, } from './circle.js';
30
+ export { createPrivySiwaSigner, } from './privy.js';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * keyring-proxy.ts
3
+ *
4
+ * Keyring proxy signer implementation.
5
+ * Delegates signing to a secure keyring proxy server via HMAC-authenticated HTTP requests.
6
+ */
7
+ import type { KeyringProxyConfig, TransactionSigner } from './types.js';
8
+ /**
9
+ * Create a signer backed by the keyring proxy server.
10
+ *
11
+ * The private key is stored securely in the proxy server and never
12
+ * enters the calling process. All signing operations are performed
13
+ * via HMAC-authenticated HTTP requests.
14
+ *
15
+ * @param config - Proxy URL and secret (or use env vars)
16
+ * @returns A TransactionSigner that delegates to the keyring proxy
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const signer = createKeyringProxySigner({
21
+ * proxyUrl: 'http://localhost:3100',
22
+ * proxySecret: 'my-secret',
23
+ * });
24
+ * const { message, signature } = await signSIWAMessage(fields, signer);
25
+ * ```
26
+ */
27
+ export declare function createKeyringProxySigner(config?: KeyringProxyConfig): TransactionSigner;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * keyring-proxy.ts
3
+ *
4
+ * Keyring proxy signer implementation.
5
+ * Delegates signing to a secure keyring proxy server via HMAC-authenticated HTTP requests.
6
+ */
7
+ import { computeHmac } from '../proxy-auth.js';
8
+ /**
9
+ * Internal helper for HMAC-authenticated proxy requests.
10
+ */
11
+ async function proxyRequest(config, endpoint, body = {}) {
12
+ const url = config.proxyUrl || process.env.KEYRING_PROXY_URL;
13
+ const secret = config.proxySecret || process.env.KEYRING_PROXY_SECRET;
14
+ if (!url) {
15
+ throw new Error('Keyring proxy requires KEYRING_PROXY_URL or config.proxyUrl');
16
+ }
17
+ if (!secret) {
18
+ throw new Error('Keyring proxy requires KEYRING_PROXY_SECRET or config.proxySecret');
19
+ }
20
+ const bodyStr = JSON.stringify(body, (_key, value) => typeof value === 'bigint' ? '0x' + value.toString(16) : value);
21
+ const hmacHeaders = computeHmac(secret, 'POST', endpoint, bodyStr);
22
+ const res = await fetch(`${url}${endpoint}`, {
23
+ method: 'POST',
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ ...hmacHeaders,
27
+ },
28
+ body: bodyStr,
29
+ });
30
+ if (!res.ok) {
31
+ const text = await res.text();
32
+ throw new Error(`Proxy ${endpoint} failed (${res.status}): ${text}`);
33
+ }
34
+ return res.json();
35
+ }
36
+ /**
37
+ * Create a signer backed by the keyring proxy server.
38
+ *
39
+ * The private key is stored securely in the proxy server and never
40
+ * enters the calling process. All signing operations are performed
41
+ * via HMAC-authenticated HTTP requests.
42
+ *
43
+ * @param config - Proxy URL and secret (or use env vars)
44
+ * @returns A TransactionSigner that delegates to the keyring proxy
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const signer = createKeyringProxySigner({
49
+ * proxyUrl: 'http://localhost:3100',
50
+ * proxySecret: 'my-secret',
51
+ * });
52
+ * const { message, signature } = await signSIWAMessage(fields, signer);
53
+ * ```
54
+ */
55
+ export function createKeyringProxySigner(config = {}) {
56
+ return {
57
+ async getAddress() {
58
+ const data = await proxyRequest(config, '/get-address');
59
+ return data.address;
60
+ },
61
+ async signMessage(message) {
62
+ const data = await proxyRequest(config, '/sign-message', { message });
63
+ return data.signature;
64
+ },
65
+ async signRawMessage(rawHex) {
66
+ const data = await proxyRequest(config, '/sign-message', {
67
+ message: rawHex,
68
+ raw: true,
69
+ });
70
+ return data.signature;
71
+ },
72
+ async signTransaction(tx) {
73
+ const data = await proxyRequest(config, '/sign-transaction', { tx });
74
+ return data.signedTx;
75
+ },
76
+ };
77
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * local-account.ts
3
+ *
4
+ * Local account signer implementation using viem LocalAccount.
5
+ */
6
+ import type { LocalAccount } from 'viem/accounts';
7
+ import type { TransactionSigner } from './types.js';
8
+ /**
9
+ * Create a signer from a viem LocalAccount.
10
+ *
11
+ * Use this when you have direct access to a private key via
12
+ * viem's `privateKeyToAccount()` or similar.
13
+ *
14
+ * @param account - A viem LocalAccount (from privateKeyToAccount, mnemonicToAccount, etc.)
15
+ * @returns A TransactionSigner that signs using the local account
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { privateKeyToAccount } from 'viem/accounts';
20
+ *
21
+ * const account = privateKeyToAccount('0x...');
22
+ * const signer = createLocalAccountSigner(account);
23
+ * const { message, signature } = await signSIWAMessage(fields, signer);
24
+ * ```
25
+ */
26
+ export declare function createLocalAccountSigner(account: LocalAccount): TransactionSigner;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * local-account.ts
3
+ *
4
+ * Local account signer implementation using viem LocalAccount.
5
+ */
6
+ /**
7
+ * Create a signer from a viem LocalAccount.
8
+ *
9
+ * Use this when you have direct access to a private key via
10
+ * viem's `privateKeyToAccount()` or similar.
11
+ *
12
+ * @param account - A viem LocalAccount (from privateKeyToAccount, mnemonicToAccount, etc.)
13
+ * @returns A TransactionSigner that signs using the local account
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { privateKeyToAccount } from 'viem/accounts';
18
+ *
19
+ * const account = privateKeyToAccount('0x...');
20
+ * const signer = createLocalAccountSigner(account);
21
+ * const { message, signature } = await signSIWAMessage(fields, signer);
22
+ * ```
23
+ */
24
+ export function createLocalAccountSigner(account) {
25
+ return {
26
+ async getAddress() {
27
+ return account.address;
28
+ },
29
+ async signMessage(message) {
30
+ return account.signMessage({ message });
31
+ },
32
+ async signRawMessage(rawHex) {
33
+ return account.signMessage({ message: { raw: rawHex } });
34
+ },
35
+ async signTransaction(tx) {
36
+ return account.signTransaction(tx);
37
+ },
38
+ };
39
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * privy.ts
3
+ *
4
+ * Privy server wallet signer implementation.
5
+ */
6
+ import type { PrivyClient } from "@privy-io/node";
7
+ import type { Address } from "viem";
8
+ import type { Signer } from "./types.js";
9
+ /**
10
+ * Configuration for the Privy SIWA signer.
11
+ */
12
+ export interface PrivySiwaSignerConfig {
13
+ /** Privy client instance */
14
+ client: PrivyClient;
15
+ /** Privy wallet ID */
16
+ walletId: string;
17
+ /** Wallet address */
18
+ walletAddress: Address;
19
+ }
20
+ /**
21
+ * Creates a SIWA Signer that wraps Privy's server wallet SDK.
22
+ *
23
+ * This signer implements the core Signer interface for SIWA message signing.
24
+ * It supports both standard message signing (EIP-191) and raw hex signing
25
+ * for ERC-8128 HTTP message signatures.
26
+ *
27
+ * @param config - Privy wallet configuration
28
+ * @returns A Signer compatible with SIWA's signSIWAMessage function
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { PrivyClient } from '@privy-io/node';
33
+ * import { signSIWAMessage, generateNonce } from '@buildersgarden/siwa/siwa';
34
+ * import { createPrivySiwaSigner } from '@buildersgarden/siwa/signer';
35
+ *
36
+ * const privy = new PrivyClient({
37
+ * appId: process.env.PRIVY_APP_ID!,
38
+ * appSecret: process.env.PRIVY_APP_SECRET!,
39
+ * });
40
+ *
41
+ * const signer = createPrivySiwaSigner({
42
+ * client: privy,
43
+ * walletId: 'your-wallet-id',
44
+ * walletAddress: '0x...',
45
+ * });
46
+ *
47
+ * const { message, signature, address } = await signSIWAMessage({
48
+ * domain: 'example.com',
49
+ * uri: 'https://example.com/login',
50
+ * agentId: 123,
51
+ * agentRegistry: 'eip155:84532:0x...',
52
+ * chainId: 84532,
53
+ * nonce: generateNonce(),
54
+ * issuedAt: new Date().toISOString(),
55
+ * }, signer);
56
+ * ```
57
+ */
58
+ export declare function createPrivySiwaSigner(config: PrivySiwaSignerConfig): Signer;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * privy.ts
3
+ *
4
+ * Privy server wallet signer implementation.
5
+ */
6
+ /**
7
+ * Creates a SIWA Signer that wraps Privy's server wallet SDK.
8
+ *
9
+ * This signer implements the core Signer interface for SIWA message signing.
10
+ * It supports both standard message signing (EIP-191) and raw hex signing
11
+ * for ERC-8128 HTTP message signatures.
12
+ *
13
+ * @param config - Privy wallet configuration
14
+ * @returns A Signer compatible with SIWA's signSIWAMessage function
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { PrivyClient } from '@privy-io/node';
19
+ * import { signSIWAMessage, generateNonce } from '@buildersgarden/siwa/siwa';
20
+ * import { createPrivySiwaSigner } from '@buildersgarden/siwa/signer';
21
+ *
22
+ * const privy = new PrivyClient({
23
+ * appId: process.env.PRIVY_APP_ID!,
24
+ * appSecret: process.env.PRIVY_APP_SECRET!,
25
+ * });
26
+ *
27
+ * const signer = createPrivySiwaSigner({
28
+ * client: privy,
29
+ * walletId: 'your-wallet-id',
30
+ * walletAddress: '0x...',
31
+ * });
32
+ *
33
+ * const { message, signature, address } = await signSIWAMessage({
34
+ * domain: 'example.com',
35
+ * uri: 'https://example.com/login',
36
+ * agentId: 123,
37
+ * agentRegistry: 'eip155:84532:0x...',
38
+ * chainId: 84532,
39
+ * nonce: generateNonce(),
40
+ * issuedAt: new Date().toISOString(),
41
+ * }, signer);
42
+ * ```
43
+ */
44
+ export function createPrivySiwaSigner(config) {
45
+ const { client, walletId, walletAddress } = config;
46
+ return {
47
+ /**
48
+ * Returns the wallet address.
49
+ */
50
+ async getAddress() {
51
+ return walletAddress;
52
+ },
53
+ /**
54
+ * Signs a message using EIP-191 personal_sign.
55
+ * Used for standard SIWA message signing.
56
+ */
57
+ async signMessage(message) {
58
+ const result = await client.wallets().ethereum().signMessage(walletId, {
59
+ message,
60
+ });
61
+ return result.signature;
62
+ },
63
+ /**
64
+ * Signs raw hex bytes.
65
+ * Used by ERC-8128 for HTTP message signatures.
66
+ */
67
+ async signRawMessage(rawHex) {
68
+ const result = await client.wallets().ethereum().signMessage(walletId, {
69
+ message: rawHex,
70
+ });
71
+ return result.signature;
72
+ },
73
+ };
74
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * types.ts
3
+ *
4
+ * Core signer types and interfaces for SIWA.
5
+ */
6
+ import type { Address, Hex } from 'viem';
7
+ /**
8
+ * Signer type detected during SIWA sign-in.
9
+ *
10
+ * - `'eoa'` — Externally Owned Account (ECDSA key pair)
11
+ * - `'sca'` — Smart Contract Account (ERC-1271, e.g. Safe, TBA, Kernel)
12
+ */
13
+ export type SignerType = 'eoa' | 'sca';
14
+ /**
15
+ * Core signer interface for message signing.
16
+ *
17
+ * Implement this interface to add support for new wallet providers.
18
+ */
19
+ export interface Signer {
20
+ /** Get the signer's address */
21
+ getAddress(): Promise<Address>;
22
+ /** Sign a message (EIP-191 personal_sign) */
23
+ signMessage(message: string): Promise<Hex>;
24
+ /**
25
+ * Sign raw bytes (optional).
26
+ * Used by ERC-8128 for HTTP message signatures.
27
+ * If not implemented, signMessage will be used as fallback.
28
+ */
29
+ signRawMessage?(rawHex: Hex): Promise<Hex>;
30
+ }
31
+ /**
32
+ * Extended signer with transaction signing capabilities.
33
+ *
34
+ * Required for onchain operations like agent registration.
35
+ */
36
+ export interface TransactionSigner extends Signer {
37
+ /** Sign a transaction and return the serialized signed transaction */
38
+ signTransaction(tx: TransactionRequest): Promise<Hex>;
39
+ }
40
+ /** Transaction request compatible with viem */
41
+ export interface TransactionRequest {
42
+ to?: Address;
43
+ data?: Hex;
44
+ value?: bigint;
45
+ nonce?: number;
46
+ chainId?: number;
47
+ gas?: bigint;
48
+ maxFeePerGas?: bigint;
49
+ maxPriorityFeePerGas?: bigint;
50
+ gasPrice?: bigint;
51
+ type?: number | string;
52
+ accessList?: any[];
53
+ }
54
+ /** Configuration for the keyring proxy signer */
55
+ export interface KeyringProxyConfig {
56
+ /** URL of the keyring proxy server (or KEYRING_PROXY_URL env var) */
57
+ proxyUrl?: string;
58
+ /** HMAC shared secret (or KEYRING_PROXY_SECRET env var) */
59
+ proxySecret?: string;
60
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * types.ts
3
+ *
4
+ * Core signer types and interfaces for SIWA.
5
+ */
6
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * wallet-client.ts
3
+ *
4
+ * WalletClient signer implementation for browser wallets and embedded wallets.
5
+ */
6
+ import type { Address, WalletClient } from 'viem';
7
+ import type { Signer } from './types.js';
8
+ /**
9
+ * Create a signer from a viem WalletClient.
10
+ *
11
+ * Use this for browser wallets (MetaMask, etc.), embedded wallets (Privy),
12
+ * WalletConnect, or any wallet that provides an EIP-1193 provider.
13
+ *
14
+ * @param client - A viem WalletClient
15
+ * @param account - Optional specific account address to use
16
+ * @returns A Signer that delegates to the WalletClient
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // With Privy embedded wallet
21
+ * const provider = await privyWallet.getEthereumProvider();
22
+ * const walletClient = createWalletClient({
23
+ * chain: baseSepolia,
24
+ * transport: custom(provider),
25
+ * });
26
+ * const signer = createWalletClientSigner(walletClient);
27
+ *
28
+ * // With browser wallet (MetaMask)
29
+ * const walletClient = createWalletClient({
30
+ * chain: mainnet,
31
+ * transport: custom(window.ethereum),
32
+ * });
33
+ * const signer = createWalletClientSigner(walletClient);
34
+ * ```
35
+ */
36
+ export declare function createWalletClientSigner(client: WalletClient, account?: Address): Signer;