-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(epic): construct private key from escaped JS string
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
extensions/epic/lib/api/auth/constructPrivateKey/constructPrivateKey.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { constructPrivateKey } from './constructPrivateKey' | ||
|
||
const ESCAPED_PRIVATE_KEY = `-----BEGIN PRIVATE KEY-----\naaaaaaa\nbbbbb\nT62++bneShPHC6MB4Juo8OzZyn3XbNmyXxlnYgfnuy3PxF+lDg74IhApeW54u29t\ncccc\no0sppFxaEI36IFnyOOvmrFfJAO13nrMRuDLZeN9bHyZ4I+qQ2YRJmdN9fltQFZMQ\na/2n1dv00nX1Pd+mayOAV0fF20obDoI4gqZRaikG/gnNn7+ufIvxNdClft6INLhb\nddddd\nPEpsOnUyvQKBgD0ao0KxPiNSoTlV0OT8+SW+Wr8UxqCg/3JdT1+CxpER489PR1my\ngggg\nE9kfri8cvi1B+xxJu8paMitvwTYF6HU72bR5N2Yk4LXcMiHVln4gUji9cKkbQBvo\n-----END PRIVATE KEY-----` | ||
|
||
const EXPECTED_PRIVATE_KEY = `-----BEGIN PRIVATE KEY----- | ||
aaaaaaa | ||
bbbbb | ||
T62++bneShPHC6MB4Juo8OzZyn3XbNmyXxlnYgfnuy3PxF+lDg74IhApeW54u29t | ||
cccc | ||
o0sppFxaEI36IFnyOOvmrFfJAO13nrMRuDLZeN9bHyZ4I+qQ2YRJmdN9fltQFZMQ | ||
a/2n1dv00nX1Pd+mayOAV0fF20obDoI4gqZRaikG/gnNn7+ufIvxNdClft6INLhb | ||
ddddd | ||
PEpsOnUyvQKBgD0ao0KxPiNSoTlV0OT8+SW+Wr8UxqCg/3JdT1+CxpER489PR1my | ||
gggg | ||
E9kfri8cvi1B+xxJu8paMitvwTYF6HU72bR5N2Yk4LXcMiHVln4gUji9cKkbQBvo | ||
-----END PRIVATE KEY-----` | ||
|
||
describe('constructPrivateKey', () => { | ||
it('should format a private key', () => { | ||
const formattedKey = constructPrivateKey(ESCAPED_PRIVATE_KEY) | ||
expect(formattedKey).toBe(EXPECTED_PRIVATE_KEY) | ||
}) | ||
|
||
it('should leave the key as is if it is already formatted', () => { | ||
const formattedKey = constructPrivateKey(EXPECTED_PRIVATE_KEY) | ||
expect(formattedKey).toBe(EXPECTED_PRIVATE_KEY) | ||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
extensions/epic/lib/api/auth/constructPrivateKey/constructPrivateKey.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Transforms a single-line private key with explicit \n into a properly formatted private key. | ||
* @param inputKey - The single-line private key string. | ||
* @returns The correctly formatted private key string. | ||
*/ | ||
export const constructPrivateKey = (privateKey: string): string => { | ||
// Replace explicit \n with actual newlines | ||
const formattedKey = privateKey.replace(/\\n/g, '\n') | ||
|
||
return formattedKey | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { constructPrivateKey } from './constructPrivateKey' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters