-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update interfaces to support new keys/backward compatible
- Loading branch information
1 parent
585c57d
commit 39520d8
Showing
15 changed files
with
227 additions
and
124 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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { RSAPrivateKey, RSAPublicKey } from './rsa'; | ||
export { EllipticCurvePrivateKey, EllipticCurvePublicKey } from './ec'; | ||
export { SECP256k1PrivateKey, SECP256k1PublicKey } from './secp256k1'; | ||
export { KeyType, PrivateKey, PublicKey } from './interface'; | ||
export { RSAPrivateKey, RSAPublicKey } from "./rsa"; | ||
export { EllipticCurvePrivateKey, EllipticCurvePublicKey } from "./ec"; | ||
export { SECP256k1PrivateKey, SECP256k1PublicKey } from "./secp256k1"; | ||
export { KeyType, PrivateKey, PublicKey } from "./interface"; | ||
export { fromJWK, fromIdentifier } from "./utils"; |
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
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,32 @@ | ||
import { EllipticCurvePrivateKey } from "./ec"; | ||
import { KeyType, PrivateKey, PublicKey, KeyTypeBytesReverse } from "./interface"; | ||
import { RSAPrivateKey, RSAPublicKey } from "./rsa"; | ||
import { SECP256k1PrivateKey, SECP256k1PublicKey } from "./secp256k1" | ||
|
||
export const fromJWK = async (keyData: JsonWebKey): Promise<PrivateKey> => { | ||
const format = "jwk"; | ||
switch(keyData.kty) { | ||
case "EC": | ||
return SECP256k1PrivateKey.deserialize({format, keyData}); | ||
case "OKP": | ||
return EllipticCurvePrivateKey.deserialize({format, keyData, type: KeyType.ED_25519}); | ||
case "RSA": | ||
return RSAPrivateKey.deserialize({format, keyData, type: KeyType.RSA_65537}); | ||
default: | ||
throw new Error(`Unsupported kty ${keyData.kty}`); | ||
} | ||
} | ||
|
||
export const fromIdentifier = async ({identifier}: {identifier: Uint8Array}): Promise<PublicKey> => { | ||
if (identifier.byteLength % 2 == 0) { | ||
return RSAPublicKey.deserialize({format: "raw", keyData: identifier, type: KeyType.RSA_65537}); | ||
} | ||
const keyTypeByte = identifier[0]; | ||
switch (KeyTypeBytesReverse.get(keyTypeByte)) { | ||
case "ec_secp256k1": | ||
return SECP256k1PublicKey.fromIdentifier({identifier}) | ||
default: | ||
throw new Error(`Unknown KeyType byte prefix ${keyTypeByte}`); | ||
} | ||
|
||
}; |
Oops, something went wrong.