Skip to content

Commit 1b66ea3

Browse files
committed
feat: Do not allow importing keystore from cli
1 parent df7f4db commit 1b66ea3

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/neuron-wallet/src/models/keys/keystore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { UnsupportedCipher, IncorrectPassword, InvalidKeystore } from 'exception
66
import { ExtendedPrivateKey } from './key'
77

88
const CIPHER = 'aes-128-ctr'
9+
const CKB_CLI_ORIGIN = 'ckb-cli'
910

1011
interface CipherParams {
1112
iv: string
@@ -42,6 +43,9 @@ export default class Keystore {
4243
static fromJson = (json: string) => {
4344
try {
4445
const object = JSON.parse(json)
46+
if (object.origin === CKB_CLI_ORIGIN) {
47+
throw 'Keystore from CKB CLI is not supported'
48+
}
4549
return new Keystore(object.crypto, object.id)
4650
} catch {
4751
throw new InvalidKeystore()

packages/neuron-wallet/tests/models/keys/keystore.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,14 @@ describe('load ckb cli standard keystore', () => {
5959
expect(extendedPrivateKey.chainCode).toEqual('615302e2c93151a55c29121dd02ad554e47908a6df6d7374f357092cec11675b')
6060
})
6161
})
62+
63+
describe('load ckb cli origin keystore', () => {
64+
const keystoreString =
65+
'{"origin":"ckb-cli", "address":"ea22142fa5be326e834681144ca30326f99a6d5a","crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"29304e5bcbb1885ef5cdcb40b5312b58"},"ciphertext":"93054530a8fbe5b11995acda856585d7362ac7d2b1e4f268c633d997be2d6532c4962501d0835bf52a4693ae7a091ac9bac9297793f4116ef7c123edb00dbc85","kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"724327e67ca321ccf15035bb78a0a05c816bebbe218a0840abdc26da8453c1f4"},"mac":"1d0e5660ffbfc1f9ff4da97aefcfc2153c0ec1b411e35ffee26ee92815cc06f9"},"id":"43c1116e-efd5-4c9e-a86a-3ec0ab163122","version":3}'
66+
67+
it('does not load', () => {
68+
expect(
69+
() => Keystore.fromJson(keystoreString)
70+
).toThrowError()
71+
})
72+
})

0 commit comments

Comments
 (0)