mirror of
https://github.com/Blah-IM/Weblah.git
synced 2025-08-21 03:22:40 +00:00
feat: [wip] identity menu & creation
This commit is contained in:
parent
0989ed4fa8
commit
3a76e2f9f8
14 changed files with 282 additions and 3 deletions
|
@ -16,6 +16,9 @@ export class BlahKeyPair {
|
|||
get id() {
|
||||
return this.publicIdentity.id;
|
||||
}
|
||||
get name() {
|
||||
return this.publicIdentity.name;
|
||||
}
|
||||
|
||||
private constructor(publicIdentity: BlahPublicIdentity, privateKey: CryptoKey) {
|
||||
this.publicIdentity = publicIdentity;
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
import canonicalize from 'canonicalize';
|
||||
import type { BlahSignedPayload } from './signedPayload';
|
||||
import { bufToHex, hexToBuf } from './utils';
|
||||
import { adjectives, animals, uniqueNamesGenerator } from 'unique-names-generator';
|
||||
|
||||
export function generateName(id: string) {
|
||||
return uniqueNamesGenerator({
|
||||
seed: id,
|
||||
style: 'capital',
|
||||
separator: ' ',
|
||||
dictionaries: [adjectives, animals]
|
||||
});
|
||||
}
|
||||
|
||||
export class BlahPublicIdentity {
|
||||
private publicKey: CryptoKey;
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
private constructor(publicKey: CryptoKey, id: string) {
|
||||
this.publicKey = publicKey;
|
||||
this.id = id;
|
||||
this.name = generateName(id);
|
||||
}
|
||||
|
||||
static async fromPublicKey(publicKey: CryptoKey): Promise<BlahPublicIdentity> {
|
||||
|
|
9
src/lib/components/DropdownMenu.ts
Normal file
9
src/lib/components/DropdownMenu.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { DropdownMenu } from 'bits-ui';
|
||||
|
||||
import Content from './DropdownMenu/Content.svelte';
|
||||
import Trigger from './DropdownMenu/Trigger.svelte';
|
||||
import Item from './DropdownMenu/Item.svelte';
|
||||
|
||||
const { Root, RadioGroup, RadioItem, Separator } = DropdownMenu;
|
||||
|
||||
export { Root, Trigger, Content, Item, RadioGroup, RadioItem, Separator };
|
13
src/lib/components/DropdownMenu/Content.svelte
Normal file
13
src/lib/components/DropdownMenu/Content.svelte
Normal file
|
@ -0,0 +1,13 @@
|
|||
<script lang="ts">
|
||||
import { DropdownMenu, type DropdownMenuContentProps } from 'bits-ui';
|
||||
|
||||
interface $$Props extends DropdownMenuContentProps {}
|
||||
</script>
|
||||
|
||||
<DropdownMenu.Content
|
||||
class="bg-sb-overlay min-w-32 rounded-lg border border-ss-secondary p-1 shadow-xl"
|
||||
sideOffset={4}
|
||||
{...$$restProps}
|
||||
>
|
||||
<slot />
|
||||
</DropdownMenu.Content>
|
13
src/lib/components/DropdownMenu/Item.svelte
Normal file
13
src/lib/components/DropdownMenu/Item.svelte
Normal file
|
@ -0,0 +1,13 @@
|
|||
<script lang="ts">
|
||||
import { DropdownMenu, type DropdownMenuItemProps } from 'bits-ui';
|
||||
|
||||
type $$Props = DropdownMenuItemProps;
|
||||
</script>
|
||||
|
||||
<DropdownMenu.Item
|
||||
class="cursor-default rounded px-1.5 py-0.5 text-sf-primary transition-colors duration-200 hover:bg-accent-50 dark:hover:bg-white/5"
|
||||
on:click
|
||||
{...$$restProps}
|
||||
>
|
||||
<slot />
|
||||
</DropdownMenu.Item>
|
8
src/lib/components/DropdownMenu/Trigger.svelte
Normal file
8
src/lib/components/DropdownMenu/Trigger.svelte
Normal file
|
@ -0,0 +1,8 @@
|
|||
<script lang="ts">
|
||||
import { DropdownMenu, type DropdownMenuTriggerProps } from 'bits-ui';
|
||||
type $$Props = DropdownMenuTriggerProps;
|
||||
</script>
|
||||
|
||||
<DropdownMenu.Trigger class="cursor-default" {...$$restProps}>
|
||||
<slot />
|
||||
</DropdownMenu.Trigger>
|
|
@ -2,3 +2,4 @@ import type { EncodedBlahKeyPair } from './blah/crypto';
|
|||
import { localStore } from './localstore';
|
||||
|
||||
export const keyStore = localStore<EncodedBlahKeyPair[]>('weblah-keypairs', []);
|
||||
export const currentKeyIndex = localStore<number>('weblah-current-key-index', 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue