@abraca/nuxt 2.41.0 → 2.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "2.41.0",
7
+ "version": "2.42.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -0,0 +1,30 @@
1
+ type __VLS_Props = {
2
+ open?: boolean;
3
+ /** Inline error string from the consumer's submit handler. */
4
+ error?: string | null;
5
+ /** Loading flag while consumer handles submit. */
6
+ loading?: boolean;
7
+ /** Title text. */
8
+ title?: string;
9
+ /** Subtitle text. */
10
+ subtitle?: string;
11
+ };
12
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
13
+ submit: (payload: {
14
+ privateKey: string;
15
+ ephemeral: boolean;
16
+ }) => any;
17
+ "update:open": (open: boolean) => any;
18
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
19
+ onSubmit?: ((payload: {
20
+ privateKey: string;
21
+ ephemeral: boolean;
22
+ }) => any) | undefined;
23
+ "onUpdate:open"?: ((open: boolean) => any) | undefined;
24
+ }>, {
25
+ subtitle: string;
26
+ title: string;
27
+ loading: boolean;
28
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
29
+ declare const _default: typeof __VLS_export;
30
+ export default _default;
@@ -0,0 +1,111 @@
1
+ <script setup>
2
+ import { ref, computed, watch } from "vue";
3
+ const props = defineProps({
4
+ open: { type: Boolean, required: false },
5
+ error: { type: [String, null], required: false },
6
+ loading: { type: Boolean, required: false, default: false },
7
+ title: { type: String, required: false, default: "Sign in with a private key" },
8
+ subtitle: { type: String, required: false, default: "Paste a 32-byte Ed25519 private key (base64url) to sign in as the matching identity." }
9
+ });
10
+ const emit = defineEmits(["update:open", "submit"]);
11
+ const open = computed({
12
+ get: () => !!props.open,
13
+ set: (v) => emit("update:open", v)
14
+ });
15
+ const privateKey = ref("");
16
+ const ephemeral = ref(false);
17
+ watch(() => props.open, (v) => {
18
+ if (!v) return;
19
+ privateKey.value = "";
20
+ ephemeral.value = false;
21
+ });
22
+ const SEED_RE = /^[\w-]{43}=?$/;
23
+ const trimmed = computed(() => privateKey.value.trim());
24
+ const looksValid = computed(() => SEED_RE.test(trimmed.value));
25
+ const showError = computed(() => trimmed.value.length > 0 && !looksValid.value);
26
+ const canSubmit = computed(() => looksValid.value && !props.loading);
27
+ function submit() {
28
+ if (!canSubmit.value) return;
29
+ emit("submit", { privateKey: trimmed.value, ephemeral: ephemeral.value });
30
+ }
31
+ </script>
32
+
33
+ <template>
34
+ <UModal
35
+ v-model:open="open"
36
+ :title="title"
37
+ :ui="{ content: 'sm:max-w-lg' }"
38
+ >
39
+ <template #body>
40
+ <div class="flex flex-col gap-5">
41
+ <p class="text-sm text-(--ui-text-muted) text-center">
42
+ {{ subtitle }}
43
+ </p>
44
+
45
+ <UAlert
46
+ v-if="error"
47
+ color="error"
48
+ variant="soft"
49
+ icon="i-lucide-triangle-alert"
50
+ :description="error"
51
+ />
52
+
53
+ <UAlert
54
+ v-else-if="showError"
55
+ color="warning"
56
+ variant="soft"
57
+ icon="i-lucide-triangle-alert"
58
+ description="That doesn't look like a 32-byte base64url private key."
59
+ />
60
+
61
+ <div class="flex flex-col gap-1">
62
+ <label class="text-xs font-medium text-(--ui-text-muted)">PRIVATE KEY</label>
63
+ <UInput
64
+ v-model="privateKey"
65
+ type="password"
66
+ size="md"
67
+ autofocus
68
+ autocapitalize="off"
69
+ autocomplete="off"
70
+ spellcheck="false"
71
+ placeholder="base64url 32-byte seed"
72
+ icon="i-lucide-key-round"
73
+ class="font-mono"
74
+ :ui="{ base: 'rounded-sm' }"
75
+ @keydown.enter="submit"
76
+ />
77
+ </div>
78
+
79
+ <label class="flex items-center gap-2 cursor-pointer text-sm px-1">
80
+ <USwitch
81
+ v-model="ephemeral"
82
+ size="sm"
83
+ />
84
+ <span>Don't store on this device (ephemeral session)</span>
85
+ </label>
86
+ </div>
87
+ </template>
88
+
89
+ <template #footer>
90
+ <div class="flex items-center justify-end gap-2 w-full">
91
+ <UButton
92
+ variant="ghost"
93
+ color="neutral"
94
+ size="sm"
95
+ label="Cancel"
96
+ @click="open = false"
97
+ />
98
+ <UButton
99
+ variant="solid"
100
+ color="primary"
101
+ size="sm"
102
+ icon="i-lucide-log-in"
103
+ label="Sign in"
104
+ :loading="loading"
105
+ :disabled="!canSubmit"
106
+ @click="submit"
107
+ />
108
+ </div>
109
+ </template>
110
+ </UModal>
111
+ </template>
@@ -0,0 +1,30 @@
1
+ type __VLS_Props = {
2
+ open?: boolean;
3
+ /** Inline error string from the consumer's submit handler. */
4
+ error?: string | null;
5
+ /** Loading flag while consumer handles submit. */
6
+ loading?: boolean;
7
+ /** Title text. */
8
+ title?: string;
9
+ /** Subtitle text. */
10
+ subtitle?: string;
11
+ };
12
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
13
+ submit: (payload: {
14
+ privateKey: string;
15
+ ephemeral: boolean;
16
+ }) => any;
17
+ "update:open": (open: boolean) => any;
18
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
19
+ onSubmit?: ((payload: {
20
+ privateKey: string;
21
+ ephemeral: boolean;
22
+ }) => any) | undefined;
23
+ "onUpdate:open"?: ((open: boolean) => any) | undefined;
24
+ }>, {
25
+ subtitle: string;
26
+ title: string;
27
+ loading: boolean;
28
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
29
+ declare const _default: typeof __VLS_export;
30
+ export default _default;
@@ -15,6 +15,7 @@ export declare function useAbracadabraAuth(): {
15
15
  loginWithPassword: any;
16
16
  registerWithPassword: any;
17
17
  loginWithMnemonic: any;
18
+ loginWithKeypair: any;
18
19
  logout: any;
19
20
  logoutServer: any;
20
21
  logoutAll: any;
@@ -18,6 +18,7 @@ export function useAbracadabraAuth() {
18
18
  loginWithPassword: abra.loginWithPassword,
19
19
  registerWithPassword: abra.registerWithPassword,
20
20
  loginWithMnemonic: abra.loginWithMnemonic,
21
+ loginWithKeypair: abra.loginWithKeypair,
21
22
  logout: abra.logout,
22
23
  logoutServer: abra.logoutServer,
23
24
  logoutAll: abra.logoutAll,
@@ -884,6 +884,66 @@ export default defineNuxtPlugin({
884
884
  await _initPromise;
885
885
  }
886
886
  }
887
+ async function loginWithKeypair(opts) {
888
+ const raw = (opts.privateKey ?? "").trim();
889
+ if (!raw) throw new Error("Private key is required");
890
+ let seed;
891
+ try {
892
+ seed = fromBase64Url(raw);
893
+ } catch {
894
+ throw new Error("Private key must be base64url-encoded");
895
+ }
896
+ if (seed.length !== 32) {
897
+ seed.fill(0);
898
+ throw new Error("Private key must decode to a 32-byte Ed25519 seed");
899
+ }
900
+ const [edModule, { sha512 }] = await Promise.all([
901
+ import("@noble/ed25519"),
902
+ import("@noble/hashes/sha2.js")
903
+ ]);
904
+ const ed = edModule.default ?? edModule;
905
+ if (ed.hashes) {
906
+ ed.hashes.sha512 = sha512;
907
+ ed.hashes.sha512Async = (m) => Promise.resolve(sha512(m));
908
+ }
909
+ const pubKey = toBase64Url(ed.getPublicKey(seed));
910
+ if (opts.ephemeral) {
911
+ _wipeEphemeralSeed();
912
+ _ephemeralSeed = seed;
913
+ localStorage.removeItem("abracadabra_privkey");
914
+ if (typeof window !== "undefined") {
915
+ window.addEventListener("beforeunload", _wipeEphemeralSeed);
916
+ }
917
+ publicKeyB64.value = pubKey;
918
+ identityState.value = "claimed";
919
+ addLog("Ephemeral keypair session", "auth");
920
+ } else {
921
+ _wipeEphemeralSeed();
922
+ try {
923
+ const { softKeystoreAvailable, importSoftKeyFromSeed } = await import("./utils/softKeystore.js");
924
+ if (softKeystoreAvailable()) {
925
+ await importSoftKeyFromSeed(seed);
926
+ } else {
927
+ localStorage.setItem("abracadabra_privkey", toBase64Url(seed));
928
+ }
929
+ } finally {
930
+ seed.fill(0);
931
+ }
932
+ localStorage.setItem(CLAIMED_FLAG_KEY, "1");
933
+ localStorage.setItem(PUBKEY_KEY, pubKey);
934
+ localStorage.removeItem(REQUIRE_PASSKEY_KEY);
935
+ publicKeyB64.value = pubKey;
936
+ identityState.value = "claimed";
937
+ addLog("Authenticated via keypair", "auth");
938
+ }
939
+ const serverUrl = currentServerUrl.value;
940
+ if (client.value || serverUrl) {
941
+ _teardown();
942
+ _initPromise = null;
943
+ _initPromise = init(serverUrl);
944
+ await _initPromise;
945
+ }
946
+ }
887
947
  async function confirmPasswordReset(opts) {
888
948
  if (!client.value) throw new Error("Not connected");
889
949
  await client.value.confirmPasswordReset(opts);
@@ -1521,6 +1581,7 @@ export default defineNuxtPlugin({
1521
1581
  loginWithPassword,
1522
1582
  registerWithPassword,
1523
1583
  loginWithMnemonic,
1584
+ loginWithKeypair,
1524
1585
  logout,
1525
1586
  reconnect,
1526
1587
  logoutServer,
@@ -68,6 +68,8 @@ export default defineNuxtPlugin({
68
68
  loginWithHardware: noopAsync,
69
69
  loginWithPassword: noopAsync,
70
70
  registerWithPassword: noopAsync,
71
+ loginWithMnemonic: noopAsync,
72
+ loginWithKeypair: noopAsync,
71
73
  logout: noopAsync,
72
74
  logoutServer: noopAsync,
73
75
  logoutAll: noopAsync,
@@ -506,6 +506,25 @@ export interface AbracadabraState {
506
506
  displayName?: string;
507
507
  inviteCode?: string;
508
508
  }) => Promise<void>;
509
+ /**
510
+ * Log in with a BIP-39 recovery phrase. Derives the Ed25519 seed, persists it
511
+ * (unless `ephemeral`), marks the identity 'claimed', and re-inits so the WS
512
+ * re-authenticates via challenge-response.
513
+ */
514
+ loginWithMnemonic: (opts: {
515
+ mnemonic: string;
516
+ passphrase?: string;
517
+ ephemeral?: boolean;
518
+ }) => Promise<void>;
519
+ /**
520
+ * Log in with a raw Ed25519 private key (32-byte base64url seed — the
521
+ * `NUXT_ABRACADABRA_SERVICE_PRIVATE_KEY` shape). Same persistence + re-init
522
+ * path as `loginWithMnemonic`; `ephemeral` keeps the seed in memory only.
523
+ */
524
+ loginWithKeypair: (opts: {
525
+ privateKey: string;
526
+ ephemeral?: boolean;
527
+ }) => Promise<void>;
509
528
  logout: () => Promise<void>;
510
529
  /** Revoke the current JWT server-side, then clear local identity. */
511
530
  logoutServer: () => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/nuxt",
3
- "version": "2.41.0",
3
+ "version": "2.42.0",
4
4
  "description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
5
5
  "repository": "abracadabra/abracadabra-nuxt",
6
6
  "license": "MIT",