request-wallet-sign 0.1.1 → 0.2.0

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.
Files changed (2) hide show
  1. package/bin/index.js +32 -5
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -600,6 +600,7 @@ function txDataText() {
600
600
  out.valueEth = formatEther(REQUEST.value) + ' ' + (meta.symbol || 'ETH');
601
601
  if (REQUEST.data) out.data = REQUEST.data;
602
602
  if (REQUEST.gas) out.gas = REQUEST.gas;
603
+ if (REQUEST.authorizationList) out.authorizationList = REQUEST.authorizationList;
603
604
  } else if (REQUEST._type === 'signTypedData') {
604
605
  out.typedData = REQUEST.typedData;
605
606
  } else {
@@ -681,14 +682,19 @@ async function switchChain(account) {
681
682
  }
682
683
 
683
684
  async function buildTx(account) {
685
+ // An EIP-7702 authorizationList (e.g. relaying someone else's signed
686
+ // authorization) makes this a type-4 transaction; otherwise plain EIP-1559.
687
+ const authList = Array.isArray(REQUEST.authorizationList) && REQUEST.authorizationList.length
688
+ ? REQUEST.authorizationList : null;
684
689
  const tx = {
685
- type: '0x2',
690
+ type: authList ? '0x4' : '0x2',
686
691
  from: account,
687
692
  chainId: hex(REQUEST.chainId),
688
693
  value: REQUEST.value || '0x0',
689
694
  };
690
695
  if (REQUEST.to) tx.to = REQUEST.to;
691
696
  if (REQUEST.data) tx.data = REQUEST.data;
697
+ if (authList) tx.authorizationList = authList;
692
698
 
693
699
  // Gas limit
694
700
  if (REQUEST.gas) {
@@ -913,6 +919,19 @@ async function renderWhatThisDoes() {
913
919
 
914
920
  const { to, data, value } = REQUEST;
915
921
 
922
+ // EIP-7702: this tx also installs account delegation(s) — the highest-impact
923
+ // part, so surface each delegate target up front (Details shows the full tx).
924
+ if (Array.isArray(REQUEST.authorizationList) && REQUEST.authorizationList.length) {
925
+ const fields = REQUEST.authorizationList.map((a, i) => ({
926
+ label: 'Delegate #' + (i + 1),
927
+ value: (a && a.address) ? a.address : '(unknown target)',
928
+ danger: true,
929
+ }));
930
+ if (to) fields.push({ label: 'Then calls', value: to });
931
+ showWhat('Authorize account delegation (EIP-7702)', fields);
932
+ return;
933
+ }
934
+
916
935
  // Contract deployment
917
936
  if (!to && data && data.length > 2) {
918
937
  const bytes = Math.floor((data.length - 2) / 2);
@@ -1132,10 +1151,18 @@ export async function run(argv) {
1132
1151
  }
1133
1152
 
1134
1153
  // ── Entry point ───────────────────────────────────────────────────────────────
1135
- // Only execute when run directly (not when imported by tests).
1136
-
1137
- const isMain = process.argv[1] &&
1138
- new URL(import.meta.url).pathname === process.argv[1];
1154
+ // Only execute when run directly (not when imported by tests). Resolve symlinks
1155
+ // on both sides: when launched via an installed bin (npx / global install),
1156
+ // process.argv[1] is a symlink in node_modules/.bin whose realpath is this file,
1157
+ // while import.meta.url is already the resolved path — comparing them raw fails.
1158
+ import { realpathSync } from 'node:fs';
1159
+ import { fileURLToPath } from 'node:url';
1160
+
1161
+ let isMain = false;
1162
+ try {
1163
+ isMain = !!process.argv[1] &&
1164
+ realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
1165
+ } catch { isMain = false; }
1139
1166
 
1140
1167
  if (isMain) {
1141
1168
  run(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "request-wallet-sign",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Let AI agents surface wallet signing requests to users via a local browser page",
5
5
  "type": "module",
6
6
  "engines": {