asym box : Fix condition on T

This commit is contained in:
2024-05-14 15:24:17 +02:00
parent 435976e837
commit 25a8275c91
+3 -3
View File
@@ -6,7 +6,7 @@ export type PrivKey = CryptoKey
const algorithm: RsaOaepParams = {name: "RSA-OAEP"}
export class PrivateBox<T extends ArrayBufferView> {
export class PrivateBox<T> {
readonly cipher: Uint8Array;
readonly _phantom!: T;
@@ -29,7 +29,7 @@ export class PrivateBox<T extends ArrayBufferView> {
return [keys.privateKey, keys.publicKey]
}
public static async encrypt<T extends ArrayBufferView>(key: PubKey, data: T): Promise<Result<PrivateBox<T>>> {
public static async encrypt<T>(key: PubKey, data: Uint8Array): Promise<Result<PrivateBox<T>>> {
try {
const cipher = await window.crypto.subtle.encrypt(algorithm, key, data)
return Result.ok(new PrivateBox(new Uint8Array(cipher)))
@@ -49,7 +49,7 @@ export class PrivateBox<T extends ArrayBufferView> {
public toString() : string {
return misc.a2b64(new Uint8Array(this.cipher))
}
public static fromString<T extends ArrayBufferView>(data: string) : Result<PrivateBox<T>> {
public static fromString<T>(data: string) : Result<PrivateBox<T>> {
const res = misc.b642a(data)
if (res.error()) return Result.error([])
return Result.ok(new PrivateBox(res.unwrap()))