Skip to content

Commit 005cb8a

Browse files
authored
fix(scripts): adapt to keystore changes (#469)
* fix(scripts): adapt to keystore changes * lint * keep support for old format * remove extra check * error early
1 parent 309e538 commit 005cb8a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

scripts/utils/utils.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,26 @@ export const getSigner = () => {
172172
readFileSync(path.join(homedir(), '.iota', 'iota_config', 'iota.keystore'), 'utf8'),
173173
);
174174

175-
for (const priv of keystore) {
176-
const keypair = decodeIotaPrivateKey(priv);
175+
// Support for old format, can be removed once https://github.com/iotaledger/iota/pull/7704 is in production
176+
if (Array.isArray(keystore)) {
177+
for (const priv of keystore) {
178+
const keypair = decodeIotaPrivateKey(priv);
179+
180+
const pair = Ed25519Keypair.fromSecretKey(keypair.secretKey);
181+
if (pair.getPublicKey().toIotaAddress() === sender) {
182+
return pair;
183+
}
184+
}
185+
throw new Error(`keypair not found for sender: ${sender}`);
186+
}
177187

178-
const pair = Ed25519Keypair.fromSecretKey(keypair.secretKey);
179-
if (pair.getPublicKey().toIotaAddress() === sender) {
180-
return pair;
188+
// New format
189+
for (const entry of keystore.keys) {
190+
if (entry.key.type !== 'key_pair' || entry.address !== sender) {
191+
continue;
181192
}
193+
const keypair = decodeIotaPrivateKey(entry.key.value);
194+
return Ed25519Keypair.fromSecretKey(keypair.secretKey);
182195
}
183196

184197
throw new Error(`keypair not found for sender: ${sender}`);

0 commit comments

Comments
 (0)