Skip to content

Commit 25376ee

Browse files
committed
feat: remove automatic key file fetch from decryption script
1 parent 3e7b798 commit 25376ee

2 files changed

Lines changed: 38 additions & 34 deletions

File tree

scripts/web2/README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Ignite API Key Decryption example
1+
# Ignite Proxy API Key Decryption example
22

3-
This is a sample script demonstrating how to decrypt your Ignite proxy API key using your provider's signing policy private key.
3+
This is a sample script demonstrating how to obtain your Ignite proxy API key.
44

55
## Setup
66

@@ -14,25 +14,30 @@ Create a `.env.decrypt` file in `scripts/web2/` with:
1414

1515
```bash
1616
PRIVATE_KEY=0x...
17-
KEYS_URL=https://api.ignitemarket.xyz/proxy-api-keys
1817
```
1918

2019
- `PRIVATE_KEY`: your provider's signing policy private key in hex format.
21-
- `KEYS_URL`: endpoint with published API keys, defaults to: `https://api.ignitemarket.xyz/proxy-api-keys`.
2220

23-
## Usage
21+
## Step 1: Fetch encrypted keys list
2422

25-
From the project root, run:
23+
From `scripts/web2/`, run:
24+
25+
```bash
26+
curl -s "https://api.ignitemarket.xyz/proxy-api-keys" -o ignite-api-keys.json
27+
```
28+
29+
## Step 2: Decrypt your API key
30+
31+
From `scripts/web2/`, run:
2632

2733
```bash
28-
cd scripts/web2
2934
npx ts-node decrypt-ignite-key.ts
3035
```
3136

32-
The script will:
37+
This will:
3338

34-
1. Load `PRIVATE_KEY` (and optionally `KEYS_URL`) from `.env.decrypt`.
35-
2. Derive your signing policy address from `PRIVATE_KEY`.
36-
3. Fetch encrypted API keys from `KEYS_URL`.
37-
4. Find the entry matching your address.
38-
5. Decrypt the API key and print it to stdout.
39+
1. Load `PRIVATE_KEY` from `.env.decrypt`.
40+
2. Read the full keys JSON file (`ignite-api-keys.json`).
41+
3. Filter find entry matching your signing policy address derived from `PRIVATE_KEY`.
42+
4. Decrypt the API key.
43+
5. Print the decrypted API key to stdout.

scripts/web2/decrypt-ignite-key.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
#!/usr/bin/env ts-node
22
import 'dotenv/config';
3-
import axios from 'axios';
43
import { ethers } from 'ethers';
54
import { createDecipheriv, createECDH, hkdfSync } from 'crypto';
65
import { config as loadEnv } from 'dotenv';
6+
import { readFileSync } from 'fs';
77
import { resolve } from 'path';
88

99
// Load dedicated env file for decryption, next to this script
1010
loadEnv({ path: resolve(__dirname, '.env.decrypt') });
1111

12-
const KEYS_URL =
13-
process.env.KEYS_URL || 'https://api.ignitemarket.xyz/proxy-api-keys';
1412
const ENV_KEY = 'PRIVATE_KEY';
13+
const INPUT_FILE = 'ignite-api-keys.json';
1514

1615
const ECDH_SALT = Buffer.from('key-publish-ecdh-salt-v1');
1716
const ECDH_INFO_PREFIX = Buffer.from('key-publish-api-key:v1:');
1817
const AES_NONCE_SIZE = 12;
1918
const AUTH_TAG_SIZE = 16;
2019

2120
interface EncryptedKeyRecord {
22-
signing_address?: string;
23-
identity_address?: string;
21+
signing_policy_address: string;
2422
encrypted_API_key: string;
2523
}
2624

@@ -107,26 +105,27 @@ function decryptIgniteKey(
107105
}
108106
}
109107

110-
async function fetchEncryptedKeys(): Promise<EncryptedKeyRecord[]> {
111-
const resp = await axios.get(KEYS_URL, { timeout: 10_000 });
112-
const data = resp.data;
113-
if (!data || typeof data !== 'object' || !Array.isArray(data.data)) {
114-
throw new Error('API response is not in the expected format.');
108+
function loadAllKeysFromFile(): EncryptedKeyRecord[] {
109+
const filePath = resolve(__dirname, INPUT_FILE);
110+
const raw = readFileSync(filePath, { encoding: 'utf8' });
111+
const parsed = JSON.parse(raw) as any;
112+
113+
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.data)) {
114+
throw new Error(
115+
`Input file ${INPUT_FILE} does not contain a 'data' array.`,
116+
);
115117
}
116-
return data.data as EncryptedKeyRecord[];
118+
119+
return parsed.data as EncryptedKeyRecord[];
117120
}
118121

119-
function findEncryptedKeyForAddress(
122+
function findRecordForAddress(
120123
records: EncryptedKeyRecord[],
121124
myAddress: string,
122125
): string | undefined {
123126
const target = myAddress.toLowerCase();
124127
for (const item of records) {
125-
const addr = (
126-
item.signing_address ||
127-
item.identity_address ||
128-
''
129-
).toString();
128+
const addr = item.signing_policy_address?.toString();
130129
if (addr && addr.toLowerCase() === target) {
131130
return item.encrypted_API_key;
132131
}
@@ -140,15 +139,15 @@ async function main(): Promise<void> {
140139
const wallet = new ethers.Wallet(privateKeyHex);
141140
const myAddress = wallet.address;
142141

143-
console.log(`Derived signing policy address: ${myAddress}`);
142+
console.log(`Decrypting key for signing policy address: ${myAddress}`);
143+
console.log(`Reading keys from file: ${INPUT_FILE}`);
144144

145-
const records = await fetchEncryptedKeys();
146-
const encryptedKey = findEncryptedKeyForAddress(records, myAddress);
145+
const records = loadAllKeysFromFile();
146+
const encryptedKey = findRecordForAddress(records, myAddress);
147147

148148
if (!encryptedKey) {
149149
throw new Error(`No encrypted key found for address ${myAddress}.`);
150150
}
151-
console.log('Found encrypted key. Decrypting...');
152151

153152
const apiKey = decryptIgniteKey(privateKeyHex, myAddress, encryptedKey);
154153

0 commit comments

Comments
 (0)