moving into taler-crpto
This commit is contained in:
parent
562067a287
commit
e3d046457b
@ -1,4 +1,12 @@
|
|||||||
import { decodeCrock, encodeCrock } from "@gnu-taler/taler-util";
|
import {
|
||||||
|
bytesToString,
|
||||||
|
createEddsaKeyPair,
|
||||||
|
decodeCrock,
|
||||||
|
encodeCrock,
|
||||||
|
encryptWithDerivedKey,
|
||||||
|
getRandomBytesF,
|
||||||
|
stringToBytes,
|
||||||
|
} from "@gnu-taler/taler-util";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new session id from which it will
|
* Create a new session id from which it will
|
||||||
@ -55,27 +63,19 @@ export async function unlockAccount(
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function createNewAccount(password: string) {
|
export async function createNewAccount(password: string) {
|
||||||
const { privateKey } = await createPair();
|
const { eddsaPriv } = createEddsaKeyPair();
|
||||||
const salt = createSalt();
|
const salt = createSalt();
|
||||||
|
|
||||||
const protectedPrivKey = await protectWithPassword(
|
const key = stringToBytes(password);
|
||||||
privateKey,
|
|
||||||
|
const protectedPrivKey = await encryptWithDerivedKey(
|
||||||
|
getRandomBytesF(24),
|
||||||
|
key,
|
||||||
|
eddsaPriv,
|
||||||
salt,
|
salt,
|
||||||
password,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// const privRaw = await crypto.subtle
|
const protectedPriv = bytesToString(protectedPrivKey);
|
||||||
// .exportKey("pkcs8", privateKey)
|
|
||||||
// .catch((e) => {
|
|
||||||
// throw new Error(String(e));
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const pubRaw = await crypto.subtle.exportKey("spki", publicKey).catch((e) => {
|
|
||||||
// throw new Error(String(e));
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const pub = btoa(ab2str(pubRaw));
|
|
||||||
const protectedPriv = btoa(ab2str(protectedPrivKey));
|
|
||||||
|
|
||||||
return { accountId: protectedPriv, salt };
|
return { accountId: protectedPriv, salt };
|
||||||
}
|
}
|
||||||
|
@ -1393,7 +1393,7 @@ async function deriveKey(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function encryptWithDerivedKey(
|
export async function encryptWithDerivedKey(
|
||||||
nonce: EncryptionNonce,
|
nonce: EncryptionNonce,
|
||||||
keySeed: OpaqueData,
|
keySeed: OpaqueData,
|
||||||
plaintext: OpaqueData,
|
plaintext: OpaqueData,
|
||||||
|
Loading…
Reference in New Issue
Block a user