From ce62654b85bc7f62b5dceeaafc6bfa3338bdf0ee Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 8 Sep 2023 08:25:49 -0400 Subject: [PATCH] refactor: move to use KeyPairEd25519 and createKeyPair --- src/portal.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/portal.ts b/src/portal.ts index 8e1dcbf..dfbdb8c 100644 --- a/src/portal.ts +++ b/src/portal.ts @@ -1,9 +1,10 @@ -import { KeyPair, Portal } from "#types.js"; +import { Portal } from "#types.js"; import { Client } from "@lumeweb/libportal"; import { deriveChildKey } from "#keys.js"; -import { ed25519 } from "@noble/curves/ed25519"; import { bytesToHex } from "@noble/hashes/utils"; import COMMUNITY_PORTAL_LIST from "@lumeweb/community-portals"; +import { createKeyPair } from "@lumeweb/libs5"; +import type { KeyPairEd25519 } from "@lumeweb/libs5"; let activePortalMasterKey; @@ -46,16 +47,13 @@ export function generatePortalEmail(portal: Portal) { return `${userId}@example.com`; } -export function generatePortalKeyPair(portal: Portal): KeyPair { +export function generatePortalKeyPair(portal: Portal): KeyPairEd25519 { const privateKey = deriveChildKey( activePortalMasterKey, `portal-account:${portal.id}`, ); - return { - privateKey, - publicKey: ed25519.getPublicKey(privateKey), - }; + return createKeyPair(privateKey); } export function getActivePortals(): Client[] { @@ -78,7 +76,7 @@ export function initPortal(portal: Portal): Client { const client = new Client({ email: generatePortalEmail(portal), portalUrl: portal.url, - privateKey: generatePortalKeyPair(portal).privateKey, + privateKey: generatePortalKeyPair(portal).extractBytes(), jwt: jwt as string, });