-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c45d329
commit 1cfaa37
Showing
5 changed files
with
78 additions
and
23 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,47 +1,73 @@ | ||
import { | ||
Ed25519Keypair, | ||
X25519Keypair, | ||
Aes256Key, | ||
Keypair, | ||
XSalsa20Poly1305, | ||
Ed25519PublicKey, | ||
X25519PublicKey | ||
X25519PublicKey, | ||
ByteKey, | ||
Secp256k1Keypair, | ||
Secp256k1PublicKey, | ||
PublicKeyEncryptionKey, | ||
PublicSignKey | ||
} from "@peerbit/crypto"; | ||
|
||
export type KeypairFromPublicKey<T> = T extends X25519PublicKey | ||
? X25519PublicKey extends T | ||
? X25519Keypair | ||
: Ed25519Keypair | ||
: Ed25519Keypair; | ||
? X25519Keypair | ||
: T extends Ed25519PublicKey | ||
? Ed25519Keypair | ||
: T extends Secp256k1PublicKey | ||
? Secp256k1Keypair | ||
: T extends PublicSignKey | PublicKeyEncryptionKey | ||
? Keypair | ||
: never; | ||
|
||
export interface Keychain { | ||
// Add a key to the keychain. | ||
// Represents keys internally as X25519 and Aes256. | ||
// Transforms Ed25519 keys to X25519 keys internally? | ||
import( | ||
parameters: ( | ||
| { keypair: Ed25519Keypair | X25519Keypair } | ||
| { key: Aes256Key } | ||
| { keypair: Ed25519Keypair | X25519Keypair | Secp256k1Keypair | Keypair } | ||
| { key: XSalsa20Poly1305 | ByteKey } | ||
) & { id: Uint8Array } | ||
): Promise<void>; | ||
|
||
// This is only really relevant for asymmetric keys? -> No changes | ||
exportByKey< | ||
T extends Ed25519PublicKey | X25519PublicKey, | ||
T extends | ||
| Ed25519PublicKey | ||
| X25519PublicKey | ||
| Secp256k1PublicKey | ||
| PublicSignKey | ||
| PublicKeyEncryptionKey, | ||
Q = KeypairFromPublicKey<T> | ||
>( | ||
publicKey: T | ||
): Promise<Q | undefined>; | ||
|
||
// ID's are the sha256 hashes of the public key (or the symmetric key itself) | ||
// ID's are the sha256base hashes of the public key (or the symmetric key itself) | ||
// Throws if no key can be found of type `type` with id `id`? | ||
// If type is undefined, just return any bytekey. | ||
exportById< | ||
T = "ed25519" | "x25519" | "aes256", | ||
T = | ||
| "ed25519" | ||
| "x25519" | ||
| "secp256k1" | ||
| "xsalsa20poly1305" | ||
| "bytekey" | ||
| "keypair", | ||
Q = T extends "ed25519" | ||
? Ed25519Keypair | ||
: T extends "x25519" | ||
? X25519Keypair | ||
: Aes256Key | ||
: T extends "secp256k1" | ||
? Secp256k1Keypair | ||
: T extends "keypair" | ||
? Keypair | ||
: T extends "xsalsa20poly1305" | ||
? XSalsa20Poly1305 | ||
: ByteKey | ||
>( | ||
id: Uint8Array, | ||
id: string, | ||
type: T | ||
): Promise<Q | undefined>; | ||
} |