browser-evm-signer 0.1.11 → 0.1.13

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.
@@ -97,5 +97,10 @@ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyf
97
97
  export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
98
98
  export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
99
99
  export declare let import_meta_ponyfill: ImportMetaPonyfill;
100
+ declare global {
101
+ interface Error {
102
+ cause?: unknown;
103
+ }
104
+ }
100
105
  export {};
101
106
  //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,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AE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC;AACxB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ /** Discriminating codes the browser UI may attach to a rejection so consumers can react
2
+ * programmatically (e.g. clear caches) without string-matching error messages. */
3
+ export declare const SignerErrorCode: {
4
+ /** The connected wallet account is different from the address the caller required. */
5
+ readonly WrongWalletAddress: "WRONG_WALLET_ADDRESS";
6
+ };
7
+ export type SignerErrorCode = typeof SignerErrorCode[keyof typeof SignerErrorCode];
8
+ /** Thrown by `WalletSigner` when the user rejected because the connected wallet did not match
9
+ * the address the caller expected. Callers commonly invalidate any cached address on this. */
10
+ export declare class WrongWalletAddressError extends Error {
11
+ readonly name = "WrongWalletAddressError";
12
+ readonly code: "WRONG_WALLET_ADDRESS";
13
+ }
14
+ /** Walk an error's `cause` chain looking for a `WrongWalletAddressError`. Higher-level libraries
15
+ * (e.g. viem) frequently wrap signer errors, so consumers should not rely on bare `instanceof`. */
16
+ export declare function findWrongWalletAddressError(err: unknown): WrongWalletAddressError | undefined;
17
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;mFACmF;AACnF,eAAO,MAAM,eAAe;IAC1B,sFAAsF;;CAE9E,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAEnF;+FAC+F;AAC/F,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAkB,IAAI,6BAA6B;IACnD,QAAQ,CAAC,IAAI,yBAAsC;CACpD;AAED;oGACoG;AACpG,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,CAK7F"}
package/esm/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ /** Discriminating codes the browser UI may attach to a rejection so consumers can react
2
+ * programmatically (e.g. clear caches) without string-matching error messages. */
3
+ export const SignerErrorCode = {
4
+ /** The connected wallet account is different from the address the caller required. */
5
+ WrongWalletAddress: "WRONG_WALLET_ADDRESS",
6
+ };
7
+ /** Thrown by `WalletSigner` when the user rejected because the connected wallet did not match
8
+ * the address the caller expected. Callers commonly invalidate any cached address on this. */
9
+ export class WrongWalletAddressError extends Error {
10
+ constructor() {
11
+ super(...arguments);
12
+ Object.defineProperty(this, "name", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: "WrongWalletAddressError"
17
+ });
18
+ Object.defineProperty(this, "code", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: SignerErrorCode.WrongWalletAddress
23
+ });
24
+ }
25
+ }
26
+ /** Walk an error's `cause` chain looking for a `WrongWalletAddressError`. Higher-level libraries
27
+ * (e.g. viem) frequently wrap signer errors, so consumers should not rely on bare `instanceof`. */
28
+ export function findWrongWalletAddressError(err) {
29
+ for (let e = err; e instanceof Error; e = e.cause) {
30
+ if (e instanceof WrongWalletAddressError)
31
+ return e;
32
+ }
33
+ return undefined;
34
+ }
@@ -52,7 +52,7 @@ function handleApiRequest(pathname, method, body, store) {
52
52
  }
53
53
  const result = data.success
54
54
  ? { success: true, result: data.result || "" }
55
- : { success: false, error: data.error || "Unknown error" };
55
+ : { success: false, error: data.error || "Unknown error", code: data.code };
56
56
  const completed = store.complete(id, result);
57
57
  if (!completed) {
58
58
  return new Response(JSON.stringify({ error: "Failed to complete request" }), {
package/esm/mod.d.ts CHANGED
@@ -2,6 +2,7 @@ import "./_dnt.polyfills.js";
2
2
  export { type BalanceResult, type ConnectResult, type SendTransactionParams, type SignMessageParams, type SignResult, type SignTypedDataParams, type TransactionResult, WalletSigner, type WalletSignerOptions, } from "./wallet-signer.js";
3
3
  export { CHAINS, getChainConfig, getDefaultChainId, getPort, getRpcUrl } from "./config.js";
4
4
  export type { ChainConfig, TypedDataDomain, TypedDataField } from "./types.js";
5
+ export { findWrongWalletAddressError, SignerErrorCode, WrongWalletAddressError } from "./errors.js";
5
6
  export { walletSignerTransport, type WalletSignerTransportOptions } from "./transport.js";
6
7
  export { connectWalletViem, type ConnectWalletViemOptions, type ViemBrowserAccount } from "./viem-account.js";
7
8
  export { PendingStore, pendingStore } from "./pending-store.js";
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,YAAY,EACZ,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE/E,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE9G,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,YAAY,EACZ,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE/E,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEpG,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE9G,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
package/esm/mod.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import "./_dnt.polyfills.js";
2
2
  export { WalletSigner, } from "./wallet-signer.js";
3
3
  export { CHAINS, getChainConfig, getDefaultChainId, getPort, getRpcUrl } from "./config.js";
4
+ export { findWrongWalletAddressError, SignerErrorCode, WrongWalletAddressError } from "./errors.js";
4
5
  export { walletSignerTransport } from "./transport.js";
5
6
  export { connectWalletViem } from "./viem-account.js";
6
7
  export { PendingStore, pendingStore } from "./pending-store.js";
@@ -21,6 +21,7 @@ export declare class PendingStore {
21
21
  */
22
22
  createSendTransactionRequest(params: {
23
23
  to: string;
24
+ from?: string;
24
25
  value?: string;
25
26
  data?: string;
26
27
  chainId?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"pending-store.d.ts","sourceRoot":"","sources":["../src/pending-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EACd,aAAa,EAGb,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAUpB;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,QAAQ,CAAkC;IAElD;;OAEG;IACH,oBAAoB,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;KAAE;IAWtH;;OAEG;IACH,4BAA4B,CAAC,MAAM,EAAE;QACnC,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;KAAE;IAUnD;;OAEG;I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QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;KAAE;IAUnD;;OAEG;IACH,OAAO,CAAC,MAAM;IAwBd;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI3C;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO;IAmBpD;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO;IAmB5C;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB;;OAEG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAED,2DAA2D;AAC3D,eAAO,MAAM,YAAY,EAAE,YAAiC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,OAAO,KAAK,EAAyB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG9E,qDAAqD;AACrD,MAAM,WAAW,4BAA4B;IAC3C,0GAA0G;IAC1G,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,sFAAsF;AACtF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,CAyDjB"}
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,OAAO,KAAK,EAAyB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG9E,qDAAqD;AACrD,MAAM,WAAW,4BAA4B;IAC3C,0GAA0G;IAC1G,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,sFAAsF;AACtF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,CA0DjB"}
package/esm/transport.js CHANGED
@@ -6,14 +6,16 @@ export function walletSignerTransport(signer, options) {
6
6
  async request({ method, params }) {
7
7
  switch (method) {
8
8
  case "personal_sign": {
9
- const [messageHex] = params;
9
+ const [messageHex, address] = params;
10
10
  const message = hexToString(messageHex);
11
- const { signature } = await signer.signMessage({ message });
11
+ const { signature } = await signer.signMessage({ message, address });
12
12
  return signature;
13
13
  }
14
14
  case "eth_sendTransaction": {
15
15
  const [tx] = params;
16
16
  const sendParams = { to: tx.to };
17
+ if (tx.from)
18
+ sendParams.from = tx.from;
17
19
  if (tx.data)
18
20
  sendParams.data = tx.data;
19
21
  if (tx.value)
@@ -31,9 +33,9 @@ export function walletSignerTransport(signer, options) {
31
33
  return txHash;
32
34
  }
33
35
  case "eth_signTypedData_v4": {
34
- const [, typedDataJson] = params;
36
+ const [address, typedDataJson] = params;
35
37
  const { domain, types, primaryType, message } = JSON.parse(typedDataJson);
36
- const { signature } = await signer.signTypedData({ domain, types, primaryType, message });
38
+ const { signature } = await signer.signTypedData({ domain, types, primaryType, message, address });
37
39
  return signature;
38
40
  }
39
41
  case "eth_chainId":
package/esm/types.d.ts CHANGED
@@ -24,6 +24,8 @@ export interface ConnectRequest extends BaseRequest {
24
24
  export interface SendTransactionRequest extends BaseRequest {
25
25
  type: "send_transaction";
26
26
  to: string;
27
+ /** Expected `from` address. When set, the browser UI refuses to sign unless the connected wallet matches. */
28
+ from?: string;
27
29
  value?: string;
28
30
  data?: string;
29
31
  gasLimit?: string;
@@ -64,6 +66,8 @@ export interface SuccessResult {
64
66
  export interface ErrorResult {
65
67
  success: false;
66
68
  error: string;
69
+ /** Discriminating code so consumers can react programmatically. See `SignerErrorCode`. */
70
+ code?: string;
67
71
  }
68
72
  export type RequestResult = SuccessResult | ErrorResult;
69
73
  export interface PendingEntry<T extends PendingRequest = PendingRequest> {
@@ -78,5 +82,7 @@ export interface CompleteApiRequest {
78
82
  success: boolean;
79
83
  result?: string;
80
84
  error?: string;
85
+ /** Discriminating code paired with `error`. See `SignerErrorCode`. */
86
+ code?: string;
81
87
  }
82
88
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAGD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,kBAAkB,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAE9F,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IACzD,IAAI,EAAE,kBAAkB,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,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ED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,SAAS,EAAE,eAAe,CAAA;CAAE,CAAC,CA8BtE"}
1
+ {"version":3,"file":"viem-account.d.ts","sourceRoot":"","sources":["../src/viem-account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAO,MAAM,MAAM,CAAC;AAExE,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAyB,KAAK,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAE1F,oHAAoH;AACpH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC;IACzC,aAAa,EAAE,YAAY,CAAC,eAAe,CAAC,CAAC;IAC7C,eAAe,EAAE,KAAK,CAAC;CACxB;AAED,iDAAiD;AACjD,MAAM,WAAW,wBAAyB,SAAQ,4BAA4B;IAC5E,oFAAoF;IACpF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,SAAS,EAAE,eAAe,CAAA;CAAE,CAAC,CAiCtE"}
@@ -16,13 +16,16 @@ export async function connectWalletViem(signer, options) {
16
16
  else {
17
17
  msg = typeof message.raw === "string" ? message.raw : new TextDecoder().decode(message.raw);
18
18
  }
19
- const { signature } = await signer.signMessage({ message: msg });
19
+ const { signature } = await signer.signMessage({ message: msg, address });
20
20
  return signature;
21
21
  };
22
22
  // viem's CustomSource["signTypedData"] uses heavily generic conditional types (TypedDataDefinition)
23
23
  // that TypeScript can't prove assignable to any concrete type inside the generic callback.
24
24
  const signTypedData = async (params) => {
25
- const { signature } = await signer.signTypedData(params);
25
+ const { signature } = await signer.signTypedData({
26
+ ...params,
27
+ address,
28
+ });
26
29
  return signature;
27
30
  };
28
31
  const account = {
@@ -10,6 +10,8 @@ export interface WalletSignerOptions {
10
10
  /** Parameters for {@linkcode WalletSigner.sendTransaction}. */
11
11
  export interface SendTransactionParams {
12
12
  to: string;
13
+ /** Expected `from` address. When set, the browser UI refuses to sign unless the connected wallet matches. */
14
+ from?: string;
13
15
  value?: string;
14
16
  data?: string;
15
17
  chainId?: number;
@@ -66,6 +68,8 @@ export declare class WalletSigner {
66
68
  constructor(options?: WalletSignerOptions);
67
69
  /** The PendingStore owned by this signer */
68
70
  get pendingStore(): PendingStore;
71
+ /** Unwrap a pending-store result, mapping discriminating error codes to typed exceptions. */
72
+ private _unwrap;
69
73
  /** The configured default chain ID */
70
74
  get defaultChainId(): number;
71
75
  /** The HTTP server port, or null if not yet started */
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-signer.d.ts","sourceRoot":"","sources":["../src/wallet-signer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAElE,2DAA2D;AAC3D,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yGAAyG;IACzG,WAAW,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CACjE;AAED,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf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,CAAC,IAAI,CAAC;CAShC"}
@@ -3,6 +3,7 @@ import { PendingStore } from "./pending-store.js";
3
3
  import { createHttpServer } from "./http-server.js";
4
4
  import { buildConnectUrl, buildSignUrl, openBrowser } from "./browser.js";
5
5
  import { CHAINS, getDefaultChainId, getPort, getRpcUrl } from "./config.js";
6
+ import { SignerErrorCode, WrongWalletAddressError } from "./errors.js";
6
7
  /**
7
8
  * Programmatic interface to the wallet signer.
8
9
  * Each instance owns its own PendingStore and HTTP server.
@@ -57,6 +58,14 @@ export class WalletSigner {
57
58
  get pendingStore() {
58
59
  return this._pendingStore;
59
60
  }
61
+ /** Unwrap a pending-store result, mapping discriminating error codes to typed exceptions. */
62
+ _unwrap(result) {
63
+ if (result.success)
64
+ return result.result;
65
+ if (result.code === SignerErrorCode.WrongWalletAddress)
66
+ throw new WrongWalletAddressError(result.error);
67
+ throw new Error(result.error);
68
+ }
60
69
  /** The configured default chain ID */
61
70
  get defaultChainId() {
62
71
  return this._defaultChainId;
@@ -86,10 +95,7 @@ export class WalletSigner {
86
95
  const { id, promise } = this._pendingStore.createConnectRequest({ chainId, address: options?.address });
87
96
  const approvalUrl = buildConnectUrl(port, id);
88
97
  await this._openBrowser(approvalUrl);
89
- const result = await promise;
90
- if (!result.success)
91
- throw new Error(result.error);
92
- return { address: result.result, approvalUrl };
98
+ return { address: this._unwrap(await promise), approvalUrl };
93
99
  }
94
100
  /**
95
101
  * Send a transaction via the connected browser wallet.
@@ -103,10 +109,7 @@ export class WalletSigner {
103
109
  });
104
110
  const approvalUrl = buildSignUrl(port, id);
105
111
  await this._openBrowser(approvalUrl);
106
- const result = await promise;
107
- if (!result.success)
108
- throw new Error(result.error);
109
- return { txHash: result.result, approvalUrl };
112
+ return { txHash: this._unwrap(await promise), approvalUrl };
110
113
  }
111
114
  /**
112
115
  * Sign a message using personal_sign.
@@ -120,10 +123,7 @@ export class WalletSigner {
120
123
  });
121
124
  const approvalUrl = buildSignUrl(port, id);
122
125
  await this._openBrowser(approvalUrl);
123
- const result = await promise;
124
- if (!result.success)
125
- throw new Error(result.error);
126
- return { signature: result.result, approvalUrl };
126
+ return { signature: this._unwrap(await promise), approvalUrl };
127
127
  }
128
128
  /**
129
129
  * Sign EIP-712 typed data.
@@ -137,10 +137,7 @@ export class WalletSigner {
137
137
  });
138
138
  const approvalUrl = buildSignUrl(port, id);
139
139
  await this._openBrowser(approvalUrl);
140
- const result = await promise;
141
- if (!result.success)
142
- throw new Error(result.error);
143
- return { signature: result.result, approvalUrl };
140
+ return { signature: this._unwrap(await promise), approvalUrl };
144
141
  }
145
142
  /**
146
143
  * Get the native token balance of an address.
@@ -1 +1 @@
1
- {"version":3,"file":"web-ui.gen.d.ts","sourceRoot":"","sources":["../src/web-ui.gen.ts"],"names":[],"mappings":"AAGA,iEAAiE;AACjE,wBAAgB,YAAY,IAAI,MAAM,CA+qCrC"}
1
+ {"version":3,"file":"web-ui.gen.d.ts","sourceRoot":"","sources":["../src/web-ui.gen.ts"],"names":[],"mappings":"AAGA,iEAAiE;AACjE,wBAAgB,YAAY,IAAI,MAAM,CAqxCrC"}
package/esm/web-ui.gen.js CHANGED
@@ -453,6 +453,10 @@ export function getIndexHtml() {
453
453
  </div>
454
454
  <h1>Send Transaction</h1>
455
455
 
456
+ <div id="tx-required" class="required-address hidden">
457
+ Required: <span id="tx-required-text" class="address"></span>
458
+ </div>
459
+
456
460
  <!-- success -->
457
461
  <div id="tx-success" class="success-box hidden">
458
462
  <p>Transaction Sent!</p>
@@ -460,6 +464,19 @@ export function getIndexHtml() {
460
464
  <p class="small">This window will close automatically...</p>
461
465
  </div>
462
466
 
467
+ <!-- wrong address -->
468
+ <div id="tx-wrong" class="hidden">
469
+ <div class="error-box">
470
+ <p>Wrong Address</p>
471
+ <p class="small">Expected: <span id="tx-wrong-expected" class="address"></span></p>
472
+ <p class="small">Connected: <span id="tx-wrong-got" class="address"></span></p>
473
+ <p class="small">Switch to the correct account in your wallet to continue.</p>
474
+ </div>
475
+ <div class="buttons">
476
+ <button class="btn-secondary" onclick="app.rejectTx()">Reject</button>
477
+ </div>
478
+ </div>
479
+
463
480
  <!-- error -->
464
481
  <div id="tx-err" class="error-box hidden">
465
482
  <p>Transaction Failed</p>
@@ -519,6 +536,10 @@ export function getIndexHtml() {
519
536
  </div>
520
537
  <h1 id="msg-heading">Sign Message</h1>
521
538
 
539
+ <div id="msg-required" class="required-address hidden">
540
+ Required: <span id="msg-required-text" class="address"></span>
541
+ </div>
542
+
522
543
  <!-- success -->
523
544
  <div id="msg-success" class="success-box hidden">
524
545
  <p>Signed Successfully!</p>
@@ -526,6 +547,19 @@ export function getIndexHtml() {
526
547
  <p class="small">This window will close automatically...</p>
527
548
  </div>
528
549
 
550
+ <!-- wrong address -->
551
+ <div id="msg-wrong" class="hidden">
552
+ <div class="error-box">
553
+ <p>Wrong Address</p>
554
+ <p class="small">Expected: <span id="msg-wrong-expected" class="address"></span></p>
555
+ <p class="small">Connected: <span id="msg-wrong-got" class="address"></span></p>
556
+ <p class="small">Switch to the correct account in your wallet to continue.</p>
557
+ </div>
558
+ <div class="buttons">
559
+ <button class="btn-secondary" onclick="app.rejectSign()">Reject</button>
560
+ </div>
561
+ </div>
562
+
529
563
  <!-- error -->
530
564
  <div id="msg-err" class="error-box hidden">
531
565
  <p>Signing Failed</p>
@@ -789,14 +823,17 @@ export function getIndexHtml() {
789
823
  }
790
824
  }
791
825
 
792
- async function completeError(id, error) {
826
+ async function completeError(id, error, code) {
793
827
  await fetch("/api/complete/" + id, {
794
828
  method: "POST",
795
829
  headers: { "Content-Type": "application/json" },
796
- body: JSON.stringify({ success: false, error: error }),
830
+ body: JSON.stringify({ success: false, error: error, code: code }),
797
831
  }).catch(function () {});
798
832
  }
799
833
 
834
+ // Keep in sync with \`SignerErrorCode\` in src/errors.ts.
835
+ var ERROR_CODE_WRONG_WALLET_ADDRESS = "WRONG_WALLET_ADDRESS";
836
+
800
837
  // --- App State ---
801
838
  var request = null;
802
839
  var viewStatus = "idle";
@@ -861,14 +898,26 @@ export function getIndexHtml() {
861
898
 
862
899
  function renderTx() {
863
900
  hide($("tx-success"));
901
+ hide($("tx-wrong"));
864
902
  hide($("tx-err"));
865
903
  hide($("tx-details"));
866
904
  hide($("tx-no-wallet"));
867
905
  hide($("tx-footer"));
868
906
 
907
+ // Required address (shown unless success or wrong_address)
908
+ if (request.from && viewStatus !== "success" && viewStatus !== "wrong_address") {
909
+ $("tx-required-text").textContent = request.from;
910
+ show($("tx-required"));
911
+ } else hide($("tx-required"));
912
+
869
913
  if (viewStatus === "success") {
870
914
  $("tx-hash").textContent = txHash;
871
915
  show($("tx-success"));
916
+ } else if (viewStatus === "wrong_address") {
917
+ $("tx-wrong-expected").textContent = request.from;
918
+ $("tx-wrong-got").textContent = connectedAddress;
919
+ show($("tx-wrong"));
920
+ return;
872
921
  } else if (viewStatus === "error") {
873
922
  $("tx-err-msg").textContent = viewError;
874
923
  show($("tx-err"));
@@ -914,15 +963,27 @@ export function getIndexHtml() {
914
963
  $("msg-heading").textContent = isTypedData ? "Sign Typed Data" : "Sign Message";
915
964
 
916
965
  hide($("msg-success"));
966
+ hide($("msg-wrong"));
917
967
  hide($("msg-err"));
918
968
  hide($("msg-content"));
919
969
  hide($("msg-chain"));
920
970
  hide($("msg-no-wallet"));
921
971
  hide($("msg-footer"));
922
972
 
973
+ // Required address (shown unless success or wrong_address)
974
+ if (request.address && viewStatus !== "success" && viewStatus !== "wrong_address") {
975
+ $("msg-required-text").textContent = request.address;
976
+ show($("msg-required"));
977
+ } else hide($("msg-required"));
978
+
923
979
  if (viewStatus === "success") {
924
980
  $("msg-sig").textContent = signature;
925
981
  show($("msg-success"));
982
+ } else if (viewStatus === "wrong_address") {
983
+ $("msg-wrong-expected").textContent = request.address;
984
+ $("msg-wrong-got").textContent = connectedAddress;
985
+ show($("msg-wrong"));
986
+ return;
926
987
  } else if (viewStatus === "error") {
927
988
  $("msg-err-msg").textContent = viewError;
928
989
  show($("msg-err"));
@@ -999,12 +1060,36 @@ export function getIndexHtml() {
999
1060
  }
1000
1061
  }
1001
1062
 
1063
+ function expectedAddress() {
1064
+ return request.type === "send_transaction" ? request.from : request.address;
1065
+ }
1066
+
1067
+ function wrongAddressMessage() {
1068
+ return "Wrong wallet address: expected " + expectedAddress() + ", got " + connectedAddress;
1069
+ }
1070
+
1071
+ async function rejectWith(defaultReason) {
1072
+ if (viewStatus === "wrong_address") {
1073
+ await completeError(request.id, wrongAddressMessage(), ERROR_CODE_WRONG_WALLET_ADDRESS);
1074
+ } else {
1075
+ await completeError(request.id, defaultReason);
1076
+ }
1077
+ }
1078
+
1002
1079
  function startListeningForAccountChange() {
1003
1080
  cleanupAccountsListener();
1081
+ var expected = expectedAddress();
1082
+ if (!expected) return;
1004
1083
  unsubAccountsChanged = onAccountsChanged(async function (accounts) {
1005
- if (!request.address || accounts.length === 0) return;
1084
+ if (accounts.length === 0) return;
1006
1085
  var newAddr = accounts[0];
1007
- if (addressMatch(newAddr, request.address)) {
1086
+ connectedAddress = newAddr;
1087
+ if (!addressMatch(newAddr, expected)) {
1088
+ render();
1089
+ return;
1090
+ }
1091
+ cleanupAccountsListener();
1092
+ if (request.type === "connect") {
1008
1093
  try {
1009
1094
  await finishConnect(newAddr);
1010
1095
  } catch (err) {
@@ -1013,9 +1098,10 @@ export function getIndexHtml() {
1013
1098
  render();
1014
1099
  completeError(request.id, viewError);
1015
1100
  }
1101
+ } else if (request.type === "send_transaction") {
1102
+ await app.handleSignTx();
1016
1103
  } else {
1017
- connectedAddress = newAddr;
1018
- render();
1104
+ await app.handleSignMsg();
1019
1105
  }
1020
1106
  });
1021
1107
  }
@@ -1046,7 +1132,7 @@ export function getIndexHtml() {
1046
1132
 
1047
1133
  cancelConnect: async function () {
1048
1134
  cleanupAccountsListener();
1049
- await completeError(request.id, "User cancelled");
1135
+ await rejectWith("User cancelled");
1050
1136
  window.close();
1051
1137
  },
1052
1138
 
@@ -1059,6 +1145,13 @@ export function getIndexHtml() {
1059
1145
  if (accounts.length > 0) connectedAddress = accounts[0];
1060
1146
  else connectedAddress = (await requestAccounts())[0];
1061
1147
 
1148
+ if (request.from && !addressMatch(connectedAddress, request.from)) {
1149
+ viewStatus = "wrong_address";
1150
+ render();
1151
+ startListeningForAccountChange();
1152
+ return;
1153
+ }
1154
+
1062
1155
  if (request.chainId) {
1063
1156
  var currentChainId = await getChainId();
1064
1157
  if (currentChainId !== request.chainId) await switchChain(request.chainId);
@@ -1067,7 +1160,7 @@ export function getIndexHtml() {
1067
1160
  viewStatus = "signing";
1068
1161
  render();
1069
1162
 
1070
- var txParams = { from: connectedAddress, to: request.to };
1163
+ var txParams = { from: request.from || connectedAddress, to: request.to };
1071
1164
  if (request.value) txParams.value = "0x" + BigInt(request.value).toString(16);
1072
1165
  if (request.data) txParams.data = request.data;
1073
1166
  if (request.gasLimit) txParams.gas = "0x" + BigInt(request.gasLimit).toString(16);
@@ -1094,7 +1187,8 @@ export function getIndexHtml() {
1094
1187
  },
1095
1188
 
1096
1189
  rejectTx: async function () {
1097
- await completeError(request.id, "User rejected transaction");
1190
+ cleanupAccountsListener();
1191
+ await rejectWith("User rejected transaction");
1098
1192
  window.close();
1099
1193
  },
1100
1194
 
@@ -1109,6 +1203,13 @@ export function getIndexHtml() {
1109
1203
  else address = (await requestAccounts())[0];
1110
1204
  connectedAddress = address;
1111
1205
 
1206
+ if (request.address && !addressMatch(address, request.address)) {
1207
+ viewStatus = "wrong_address";
1208
+ render();
1209
+ startListeningForAccountChange();
1210
+ return;
1211
+ }
1212
+
1112
1213
  if (request.chainId) {
1113
1214
  var currentChainId = await getChainId();
1114
1215
  if (currentChainId !== request.chainId) await switchChain(request.chainId);
@@ -1153,7 +1254,8 @@ export function getIndexHtml() {
1153
1254
  },
1154
1255
 
1155
1256
  rejectSign: async function () {
1156
- await completeError(request.id, "User rejected signing");
1257
+ cleanupAccountsListener();
1258
+ await rejectWith("User rejected signing");
1157
1259
  window.close();
1158
1260
  },
1159
1261
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-evm-signer",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Route EVM transactions to browser wallets for signing — standalone library, no MCP dependency",
5
5
  "keywords": [
6
6
  "wallet",
@@ -41,6 +41,6 @@
41
41
  },
42
42
  "_generatedBy": "dnt@dev",
43
43
  "peerDependencies": {
44
- "viem": "2.47.2"
44
+ "viem": "^2.48.4"
45
45
  }
46
46
  }