summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-05-26 09:25:03 -0300
committerSebastian <sebasjm@gmail.com>2023-05-26 09:26:12 -0300
commite3d046457b53fa1dc5b0cd446ebdeb9b22e2dfe7 (patch)
tree64dd43db499fc0fd536ea4a553c259025af9daf9 /packages
parent562067a28788084832af4a2862d06f99a71476d3 (diff)
downloadwallet-core-e3d046457b53fa1dc5b0cd446ebdeb9b22e2dfe7.tar.gz
wallet-core-e3d046457b53fa1dc5b0cd446ebdeb9b22e2dfe7.tar.bz2
wallet-core-e3d046457b53fa1dc5b0cd446ebdeb9b22e2dfe7.zip
moving into taler-crpto
Diffstat (limited to 'packages')
-rw-r--r--packages/exchange-backoffice-ui/src/account.ts34
-rw-r--r--packages/taler-util/src/taler-crypto.ts2
2 files changed, 18 insertions, 18 deletions
diff --git a/packages/exchange-backoffice-ui/src/account.ts b/packages/exchange-backoffice-ui/src/account.ts
index 019c0bb43..6c3766940 100644
--- a/packages/exchange-backoffice-ui/src/account.ts
+++ b/packages/exchange-backoffice-ui/src/account.ts
@@ -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
@@ -55,27 +63,19 @@ export async function unlockAccount(
* @returns
*/
export async function createNewAccount(password: string) {
- const { privateKey } = await createPair();
+ const { eddsaPriv } = createEddsaKeyPair();
const salt = createSalt();
- const protectedPrivKey = await protectWithPassword(
- privateKey,
+ const key = stringToBytes(password);
+
+ const protectedPrivKey = await encryptWithDerivedKey(
+ getRandomBytesF(24),
+ key,
+ eddsaPriv,
salt,
- password,
);
- // const privRaw = await crypto.subtle
- // .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));
+ const protectedPriv = bytesToString(protectedPrivKey);
return { accountId: protectedPriv, salt };
}
diff --git a/packages/taler-util/src/taler-crypto.ts b/packages/taler-util/src/taler-crypto.ts
index 3cd482bfa..6fc6d14f6 100644
--- a/packages/taler-util/src/taler-crypto.ts
+++ b/packages/taler-util/src/taler-crypto.ts
@@ -1393,7 +1393,7 @@ async function deriveKey(
});
}
-async function encryptWithDerivedKey(
+export async function encryptWithDerivedKey(
nonce: EncryptionNonce,
keySeed: OpaqueData,
plaintext: OpaqueData,