-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clerk-sdk-node): Properly import key from jwk
- Loading branch information
1 parent
88b4897
commit e982fd0
Showing
2 changed files
with
26 additions
and
10 deletions.
There are no files selected for viewing
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
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,21 @@ | ||
export const decodeBase64 = (base64: string) => | ||
Buffer.from(base64, 'base64').toString('binary'); | ||
|
||
// toSPKIDer converts a PEM encoded Public Key to DER encoded | ||
export function toSPKIDer(pem: string): ArrayBuffer { | ||
const pemHeader = "-----BEGIN PUBLIC KEY-----"; | ||
const pemFooter = "-----END PUBLIC KEY-----"; | ||
const pemContents = pem.substring(pemHeader.length, pem.length - pemFooter.length); | ||
const binaryDerString = decodeBase64(pemContents) | ||
return str2ab(binaryDerString); | ||
} | ||
|
||
// https://stackoverflow.com/a/11058858 | ||
function str2ab(input: string): ArrayBuffer { | ||
const buf = new ArrayBuffer(input.length); | ||
const bufView = new Uint8Array(buf); | ||
for (let i = 0, strLen = input.length; i < strLen; i++) { | ||
bufView[i] = input.charCodeAt(i); | ||
} | ||
return buf; | ||
} |