11#!/usr/bin/env ts-node
22import 'dotenv/config' ;
3- import axios from 'axios' ;
43import { ethers } from 'ethers' ;
54import { createDecipheriv , createECDH , hkdfSync } from 'crypto' ;
65import { config as loadEnv } from 'dotenv' ;
6+ import { readFileSync } from 'fs' ;
77import { resolve } from 'path' ;
88
99// Load dedicated env file for decryption, next to this script
1010loadEnv ( { path : resolve ( __dirname , '.env.decrypt' ) } ) ;
1111
12- const KEYS_URL =
13- process . env . KEYS_URL || 'https://api.ignitemarket.xyz/proxy-api-keys' ;
1412const ENV_KEY = 'PRIVATE_KEY' ;
13+ const INPUT_FILE = 'ignite-api-keys.json' ;
1514
1615const ECDH_SALT = Buffer . from ( 'key-publish-ecdh-salt-v1' ) ;
1716const ECDH_INFO_PREFIX = Buffer . from ( 'key-publish-api-key:v1:' ) ;
1817const AES_NONCE_SIZE = 12 ;
1918const AUTH_TAG_SIZE = 16 ;
2019
2120interface 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