@economicagents/keystore 0.1.0 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAwD5E,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAC;IAAC,UAAU,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE,CAAC;AAErF,wBAAsB,gBAAgB,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CA6B1F;AAED,wBAAgB,oBAAoB,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,YAAY,CAqC/E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA+E5E,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAC;IAAC,UAAU,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE,CAAC;AAErF,wBAAsB,gBAAgB,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CA6B1F;AAED,wBAAgB,oBAAoB,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,YAAY,CAkC/E"}
package/dist/index.js CHANGED
@@ -10,6 +10,29 @@ import { privateKeyToAccount } from "viem/accounts";
10
10
  const DEFAULT_KEYSTORE_DIR = join(homedir(), ".foundry", "keystores");
11
11
  const PRIVATE_KEY_WARNING = "Warning: PRIVATE_KEY in .env is insecure. Prefer: cast wallet import aep --interactive, then set AEP_KEYSTORE_ACCOUNT=aep";
12
12
  let privateKeyWarningEmitted = false;
13
+ function readPasswordFromFile(filePath) {
14
+ const normalized = filePath.trim();
15
+ if (!normalized || normalized.includes("\0") || normalized.split(/[/\\]/).includes("..")) {
16
+ throw new Error("Invalid keystore password file path");
17
+ }
18
+ const raw = readFileSync(normalized, "utf-8");
19
+ const line = raw.replace(/\r?\n$/, "").trim();
20
+ if (!line) {
21
+ throw new Error("Keystore password file is empty");
22
+ }
23
+ return line;
24
+ }
25
+ /** Password from AEP_KEYSTORE_PASSWORD_FILE, then FOUNDRY_PASSWORD / AEP_KEYSTORE_PASSWORD / ETH_KEYSTORE_PASSWORD */
26
+ function keystorePasswordFromEnv() {
27
+ const pwdFile = process.env.AEP_KEYSTORE_PASSWORD_FILE?.trim();
28
+ if (pwdFile) {
29
+ return readPasswordFromFile(pwdFile);
30
+ }
31
+ const pw = process.env.FOUNDRY_PASSWORD ??
32
+ process.env.AEP_KEYSTORE_PASSWORD ??
33
+ process.env.ETH_KEYSTORE_PASSWORD;
34
+ return pw?.trim() ? pw : undefined;
35
+ }
13
36
  function resolveKeystorePath(accountName) {
14
37
  const explicitPath = process.env.AEP_KEYSTORE_PATH;
15
38
  if (explicitPath && existsSync(explicitPath)) {
@@ -37,9 +60,7 @@ function resolveKeystorePath(accountName) {
37
60
  return null;
38
61
  }
39
62
  async function getPassword() {
40
- const pw = process.env.FOUNDRY_PASSWORD ??
41
- process.env.AEP_KEYSTORE_PASSWORD ??
42
- process.env.ETH_KEYSTORE_PASSWORD;
63
+ const pw = keystorePasswordFromEnv();
43
64
  if (pw)
44
65
  return pw;
45
66
  if (process.stdin.isTTY) {
@@ -52,7 +73,7 @@ async function getPassword() {
52
73
  });
53
74
  });
54
75
  }
55
- throw new Error("Keystore password required. Set FOUNDRY_PASSWORD or AEP_KEYSTORE_PASSWORD, or run interactively.");
76
+ throw new Error("Keystore password required. Set AEP_KEYSTORE_PASSWORD_FILE, FOUNDRY_PASSWORD, or AEP_KEYSTORE_PASSWORD, or run interactively.");
56
77
  }
57
78
  export async function getSignerAccount(accountNameOverride) {
58
79
  const accountName = accountNameOverride ??
@@ -86,11 +107,9 @@ export function getSignerAccountSync(accountNameOverride) {
86
107
  const keystorePath = resolveKeystorePath(accountName);
87
108
  if (keystorePath) {
88
109
  const json = readFileSync(keystorePath, "utf-8");
89
- const password = process.env.FOUNDRY_PASSWORD ??
90
- process.env.AEP_KEYSTORE_PASSWORD ??
91
- process.env.ETH_KEYSTORE_PASSWORD;
110
+ const password = keystorePasswordFromEnv();
92
111
  if (!password) {
93
- throw new Error("Keystore password required. Set FOUNDRY_PASSWORD or AEP_KEYSTORE_PASSWORD for non-interactive use.");
112
+ throw new Error("Keystore password required. Set AEP_KEYSTORE_PASSWORD_FILE, FOUNDRY_PASSWORD, or AEP_KEYSTORE_PASSWORD for non-interactive use.");
94
113
  }
95
114
  const wallet = Wallet.fromEncryptedJsonSync(json, password);
96
115
  const pk = (wallet.privateKey.startsWith("0x") ? wallet.privateKey : `0x${wallet.privateKey}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economicagents/keystore",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Foundry keystore signer resolver for AEP",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "ethers": "^6.13.0",
32
- "viem": "^2.21.0"
32
+ "viem": "^2.47.5"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^22.0.0",