Skip to content

Commit de620cc

Browse files
committed
add key import from file
1 parent fe72708 commit de620cc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

test/resources/test_keyfile.dat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
U2FsdGVkX1+zZPlLL1zR8ac9kCp+lHWGsjpUwBINwhpnTJWlu4TctG/Zha/8Mx0ZXjMbb73KZN+N/pBawfTmmw==
2+

test/unit/KeyPair.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const PRIVATE_TEST_KEY_PASSWORD = 'secret'
3333
const SIGN_HASH_TEXT = '5bb1ce718241bfec110552b86bb7cccf0d95b8a5f462fbf6dff7c48543622ba5'
3434
const SIGN_TEXT = '0x7eceffab47295be3891ea745838a99102bfaf525ec43632366c7ec3f54db4822b5d581573aecde94c420554f963baebbf412e4304ad8636886ddfa7b1049f70e'
3535

36+
const TEST_KEY_FILE = 'test/resources/test_keyfile.dat'
37+
3638
describe('KeyPair class tests', () => {
3739
describe('Key pair from PEM to new format', async () => {
3840
it('should import and export a new encrypted format', async () => {
@@ -74,7 +76,7 @@ describe('KeyPair class tests', () => {
7476
})
7577
})
7678

77-
describe('Export keys', () => {
79+
describe('Import and Export keys', () => {
7880
it('should export/import key pair key too text', async () => {
7981
const keyPair = await KeyPair.create()
8082
const text = keyPair.exportToString(PRIVATE_TEST_KEY_PASSWORD)
@@ -94,6 +96,13 @@ describe('KeyPair class tests', () => {
9496
assert.equal(keyPairSaved.publicKeyAPI, keyPair.publicKeyAPI)
9597
fs.unlinkSync(filename)
9698
})
99+
it('should import key from test key file', async () => {
100+
const keyPair = await KeyPair.importFromString(PRIVATE_ENCRYPTED_KEY, PRIVATE_TEST_KEY_PASSWORD)
101+
assert(keyPair)
102+
103+
const keyPairSaved = await KeyPair.importFromFile(TEST_KEY_FILE, PRIVATE_TEST_KEY_PASSWORD)
104+
assert.equal(keyPairSaved.publicKeyAPI, keyPair.publicKeyAPI)
105+
})
97106
})
98107
describe('Sign text', () => {
99108
it('should sign a standard hash text to produce a confirmed signed result', async () => {

0 commit comments

Comments
 (0)