mirror of
https://github.com/tompro/sattle.git
synced 2026-08-27 07:15:59 +00:00
sattle: Quasar PWA scaffold with lnurlcash-kit protocol core
M1: Quasar 2 / Vue 3 / TS / Pinia / i18n / PWA app shell in the lnurl-wallet palette (#002222/#004444/#55ffcc, Noto Sans). Protocol layer is the external lnurlcash-kit library (git dependency on the fork until upstream merges the prepare fix / publishes to npm); keys.ts + receive.ts vendored from lnurl-wallet with the derivation domain renamed to 'sattle'. Nix dev shell, ci workflow (typecheck, vitest, pwa build).
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
@@ -0,0 +1,15 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 356 360">
|
||||
<path
|
||||
d="M43.4 303.4c0 3.8-2.3 6.3-7.1 6.3h-15v-22h14.4c4.3 0 6.2 2.2 6.2 5.2 0 2.6-1.5 4.4-3.4 5 2.8.4 4.9 2.5 4.9 5.5zm-8-13H24.1v6.9H35c2.1 0 4-1.3 4-3.8 0-2.2-1.3-3.1-3.7-3.1zm5.1 12.6c0-2.3-1.8-3.7-4-3.7H24.2v7.7h11.7c3.4 0 4.6-1.8 4.6-4zm36.3 4v2.7H56v-22h20.6v2.7H58.9v6.8h14.6v2.3H58.9v7.5h17.9zm23-5.8v8.5H97v-8.5l-11-13.4h3.4l8.9 11 8.8-11h3.4l-10.8 13.4zm19.1-1.8V298c0-7.9 5.2-10.7 12.7-10.7 7.5 0 13 2.8 13 10.7v1.4c0 7.9-5.5 10.8-13 10.8s-12.7-3-12.7-10.8zm22.7 0V298c0-5.7-3.9-8-10-8-6 0-9.8 2.3-9.8 8v1.4c0 5.8 3.8 8.1 9.8 8.1 6 0 10-2.3 10-8.1zm37.2-11.6v21.9h-2.9l-15.8-17.9v17.9h-2.8v-22h3l15.6 18v-18h2.9zm37.9 10.2v1.3c0 7.8-5.2 10.4-12.4 10.4H193v-22h11.2c7.2 0 12.4 2.8 12.4 10.3zm-3 0c0-5.3-3.3-7.6-9.4-7.6h-8.4V307h8.4c6 0 9.5-2 9.5-7.7V298zm50.8-7.6h-9.7v19.3h-3v-19.3h-9.7v-2.6h22.4v2.6zm34.4-2.6v21.9h-3v-10.1h-16.8v10h-2.8v-21.8h2.8v9.2H296v-9.2h2.9zm34.9 19.2v2.7h-20.7v-22h20.6v2.7H316v6.8h14.5v2.3H316v7.5h17.8zM24 340.2v7.3h13.9v2.4h-14v9.6H21v-22h20v2.7H24zm41.5 11.4h-9.8v7.9H53v-22h13.3c5.1 0 8 1.9 8 6.8 0 3.7-2 6.3-5.6 7l6 8.2h-3.3l-5.8-8zm-9.8-2.6H66c3.1 0 5.3-1.5 5.3-4.7 0-3.3-2.2-4.1-5.3-4.1H55.7v8.8zm47.9 6.2H89l-2 4.3h-3.2l10.7-22.2H98l10.7 22.2h-3.2l-2-4.3zm-1-2.3l-6.3-13-6 13h12.2zm46.3-15.3v21.9H146v-17.2L135.7 358h-2.1l-10.2-15.6v17h-2.8v-21.8h3l11 16.9 11.3-17h3zm35 19.3v2.6h-20.7v-22h20.6v2.7H166v6.8h14.5v2.3H166v7.6h17.8zm47-19.3l-8.3 22h-3l-7.1-18.6-7 18.6h-3l-8.2-22h3.3L204 356l6.8-18.5h3.4L221 356l6.6-18.5h3.3zm10 11.6v-1.4c0-7.8 5.2-10.7 12.7-10.7 7.6 0 13 2.9 13 10.7v1.4c0 7.9-5.4 10.8-13 10.8-7.5 0-12.7-3-12.7-10.8zm22.8 0v-1.4c0-5.7-4-8-10-8s-9.9 2.3-9.9 8v1.4c0 5.8 3.8 8.2 9.8 8.2 6.1 0 10-2.4 10-8.2zm28.3 2.4h-9.8v7.9h-2.8v-22h13.2c5.2 0 8 1.9 8 6.8 0 3.7-2 6.3-5.6 7l6 8.2h-3.3l-5.8-8zm-9.8-2.6h10.2c3 0 5.2-1.5 5.2-4.7 0-3.3-2.1-4.1-5.2-4.1h-10.2v8.8zm40.3-1.5l-6.8 5.6v6.4h-2.9v-22h2.9v12.3l15.2-12.2h3.7l-9.9 8.1 10.3 13.8h-3.6l-8.9-12z" />
|
||||
<path fill="#050A14"
|
||||
d="M188.4 71.7a10.4 10.4 0 01-20.8 0 10.4 10.4 0 1120.8 0zM224.2 45c-2.2-3.9-5-7.5-8.2-10.7l-12 7c-3.7-3.2-8-5.7-12.6-7.3a49.4 49.4 0 00-9.7 13.9 59 59 0 0140.1 14l7.6-4.4a57 57 0 00-5.2-12.5zM178 125.1c4.5 0 9-.6 13.4-1.7v-14a40 40 0 0012.5-7.2 47.7 47.7 0 00-7.1-15.3 59 59 0 01-32.2 27.7v8.7c4.4 1.2 8.9 1.8 13.4 1.8zM131.8 45c-2.3 4-4 8.1-5.2 12.5l12 7a40 40 0 000 14.4c5.7 1.5 11.3 2 16.9 1.5a59 59 0 01-8-41.7l-7.5-4.3c-3.2 3.2-6 6.7-8.2 10.6z" />
|
||||
<path fill="#00B4FF"
|
||||
d="M224.2 98.4c2.3-3.9 4-8 5.2-12.4l-12-7a40 40 0 000-14.5c-5.7-1.5-11.3-2-16.9-1.5a59 59 0 018 41.7l7.5 4.4c3.2-3.2 6-6.8 8.2-10.7zm-92.4 0c2.2 4 5 7.5 8.2 10.7l12-7a40 40 0 0012.6 7.3c4-4.1 7.3-8.8 9.7-13.8a59 59 0 01-40-14l-7.7 4.4c1.2 4.3 3 8.5 5.2 12.4zm46.2-80c-4.5 0-9 .5-13.4 1.7V34a40 40 0 00-12.5 7.2c1.5 5.7 4 10.8 7.1 15.4a59 59 0 0132.2-27.7V20a53.3 53.3 0 00-13.4-1.8z" />
|
||||
<path fill="#00B4FF"
|
||||
d="M178 9.2a62.6 62.6 0 11-.1 125.2A62.6 62.6 0 01178 9.2m0-9.2a71.7 71.7 0 100 143.5A71.7 71.7 0 00178 0z" />
|
||||
<path fill="#050A14"
|
||||
d="M96.6 212v4.3c-9.2-.8-15.4-5.8-15.4-17.8V180h4.6v18.4c0 8.6 4 12.6 10.8 13.5zm16-31.9v18.4c0 8.9-4.3 12.8-10.9 13.5v4.4c9.2-.7 15.5-5.6 15.5-18v-18.3h-4.7zM62.2 199v-2.2c0-12.7-8.8-17.4-21-17.4-12.1 0-20.7 4.7-20.7 17.4v2.2c0 12.8 8.6 17.6 20.7 17.6 1.5 0 3-.1 4.4-.3l11.8 6.2 2-3.3-8.2-4-6.4-3.1a32 32 0 01-3.6.2c-9.8 0-16-3.9-16-13.3v-2.2c0-9.3 6.2-13.1 16-13.1 9.9 0 16.3 3.8 16.3 13.1v2.2c0 5.3-2.1 8.7-5.6 10.8l4.8 2.4c3.4-2.8 5.5-7 5.5-13.2zM168 215.6h5.1L156 179.7h-4.8l17 36zM143 205l7.4-15.7-2.4-5-15.1 31.4h5.1l3.3-7h18.3l-1.8-3.7H143zm133.7 10.7h5.2l-17.3-35.9h-4.8l17 36zm-25-10.7l7.4-15.7-2.4-5-15.1 31.4h5.1l3.3-7h18.3l-1.7-3.7h-14.8zm73.8-2.5c6-1.2 9-5.4 9-11.4 0-8-4.5-10.9-12.9-10.9h-21.4v35.5h4.6v-31.3h16.5c5 0 8.5 1.4 8.5 6.7 0 5.2-3.5 7.7-8.5 7.7h-11.4v4.1h10.7l9.3 12.8h5.5l-9.9-13.2zm-117.4 9.9c-9.7 0-14.7-2.5-18.6-6.3l-2.2 3.8c5.1 5 11 6.7 21 6.7 1.6 0 3.1-.1 4.6-.3l-1.9-4h-3zm18.4-7c0-6.4-4.7-8.6-13.8-9.4l-10.1-1c-6.7-.7-9.3-2.2-9.3-5.6 0-2.5 1.4-4 4.6-5l-1.8-3.8c-4.7 1.4-7.5 4.2-7.5 8.9 0 5.2 3.4 8.7 13 9.6l11.3 1.2c6.4.6 8.9 2 8.9 5.4 0 2.7-2.1 4.7-6 5.8l1.8 3.9c5.3-1.6 8.9-4.7 8.9-10zm-20.3-21.9c7.9 0 13.3 1.8 18.1 5.7l1.8-3.9a30 30 0 00-19.6-5.9c-2 0-4 .1-5.7.3l1.9 4 3.5-.2z" />
|
||||
<path fill="#00B4FF"
|
||||
d="M.5 251.9c29.6-.5 59.2-.8 88.8-1l88.7-.3 88.7.3 44.4.4 44.4.6-44.4.6-44.4.4-88.7.3-88.7-.3a7981 7981 0 01-88.8-1z" />
|
||||
<path fill="none" d="M-565.2 324H-252v15.8h-313.2z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.4 KiB |
@@ -0,0 +1,33 @@
|
||||
import { defineBoot } from '#q-app';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
|
||||
import messages from '@/i18n';
|
||||
|
||||
export type MessageLanguages = keyof typeof messages;
|
||||
// Type-define 'en-US' as the master schema for the resource
|
||||
export type MessageSchema = (typeof messages)['en-US'];
|
||||
|
||||
// See https://vue-i18n.intlify.dev/guide/advanced/typescript.html#global-resource-schema-type-definition
|
||||
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
||||
declare module 'vue-i18n' {
|
||||
// define the locale messages schema
|
||||
export interface DefineLocaleMessage extends MessageSchema {}
|
||||
|
||||
// define the datetime format schema
|
||||
export interface DefineDateTimeFormat {}
|
||||
|
||||
// define the number format schema
|
||||
export interface DefineNumberFormat {}
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/no-empty-object-type */
|
||||
|
||||
export default defineBoot(({ app }) => {
|
||||
const i18n = createI18n<{ message: MessageSchema }, MessageLanguages>({
|
||||
locale: 'en-US',
|
||||
legacy: false,
|
||||
messages,
|
||||
});
|
||||
|
||||
// Set i18n instance on app
|
||||
app.use(i18n);
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
// app global css - sattle's visual identity is inherited from lnurl-wallet
|
||||
// (see src/lnurlcash/ provenance): dark teal surfaces, mint-green accents
|
||||
|
||||
@import '@fontsource/noto-sans/400.css';
|
||||
@import '@fontsource/noto-sans/700.css';
|
||||
|
||||
body {
|
||||
font-family: 'Noto Sans', sans-serif;
|
||||
background: linear-gradient(160deg, #001616 0%, #002222 55%, #001a1a 100%);
|
||||
background-attachment: fixed;
|
||||
color: #55ffcc;
|
||||
}
|
||||
|
||||
// glassy dark-teal card surface, lnurl-wallet style
|
||||
.sattle-card {
|
||||
background: rgba(0, 68, 68, 0.6);
|
||||
border-radius: 8px;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Quasar Sass (& SCSS) Variables
|
||||
// --------------------------------------------------
|
||||
// sattle's visual identity is inherited from lnurl-wallet (dark teal +
|
||||
// mint green). Exact values from lnurl-wallet's src/styles/style.scss:
|
||||
// bg #002222, accent base #004444, primary #55ffcc,
|
||||
// warning #ff8800, negative #ff4444, spent #ff6666,
|
||||
// signed badge #66cc66, device badge #6699cc
|
||||
|
||||
$primary: #55ffcc;
|
||||
$secondary: #004444;
|
||||
$accent: #004444;
|
||||
|
||||
$dark: #002222;
|
||||
$dark-page: #001616;
|
||||
|
||||
$positive: #66cc66;
|
||||
$negative: #ff4444;
|
||||
$info: #6699cc;
|
||||
$warning: #ff8800;
|
||||
|
||||
// extra lnurl-wallet palette tokens, for use in app.scss / components
|
||||
$spent: #ff6666;
|
||||
$bg-glow: #001a1a;
|
||||
@@ -0,0 +1,7 @@
|
||||
// This is just an example,
|
||||
// so you can safely delete all default props below
|
||||
|
||||
export default {
|
||||
failed: 'Action failed',
|
||||
success: 'Action was successful',
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import enUS from './en-US';
|
||||
|
||||
export default {
|
||||
'en-US': enUS,
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<q-layout view="hHh lpR fFf">
|
||||
<q-header class="bg-transparent">
|
||||
<q-toolbar>
|
||||
<q-toolbar-title class="text-weight-bold">sattle</q-toolbar-title>
|
||||
<q-btn
|
||||
flat
|
||||
dense
|
||||
round
|
||||
icon="settings"
|
||||
aria-label="Settings"
|
||||
@click="$router.push('/settings')"
|
||||
/>
|
||||
</q-toolbar>
|
||||
</q-header>
|
||||
|
||||
<q-page-container>
|
||||
<router-view />
|
||||
</q-page-container>
|
||||
</q-layout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts"></script>
|
||||
@@ -0,0 +1,288 @@
|
||||
import {
|
||||
mnemonicToSeedSync,
|
||||
generateMnemonic,
|
||||
validateMnemonic
|
||||
} from '@scure/bip39'
|
||||
import {wordlist} from '@scure/bip39/wordlists/english.js'
|
||||
import {HDKey, HARDENED_OFFSET} from '@scure/bip32'
|
||||
import {hmac} from '@noble/hashes/hmac.js'
|
||||
import {sha256} from '@noble/hashes/sha2.js'
|
||||
import {secp256k1} from '@noble/curves/secp256k1.js'
|
||||
import {bytesToHex, hexToBytes, utf8ToBytes} from '@noble/hashes/utils.js'
|
||||
|
||||
// The wallet's identity is derived against this fixed domain rather than
|
||||
// window.location.hostname, so the same seed phrase always yields the same
|
||||
// linking key (and thus decrypts the same bearer tokens) no matter where
|
||||
// this static build happens to be hosted - github.io, a mirror, file://.
|
||||
export const WALLET_DOMAIN = 'sattle'
|
||||
|
||||
export const generateSeedPhrase = (): string => generateMnemonic(wordlist, 128)
|
||||
|
||||
export const isValidSeedPhrase = (phrase: string): boolean =>
|
||||
validateMnemonic(phrase.trim().toLowerCase(), wordlist)
|
||||
|
||||
const readUint32BE = (bytes: Uint8Array, offset: number): number =>
|
||||
((bytes[offset] << 24) |
|
||||
(bytes[offset + 1] << 16) |
|
||||
(bytes[offset + 2] << 8) |
|
||||
bytes[offset + 3]) >>>
|
||||
0
|
||||
|
||||
// LUD-05: BIP32-based linking-key derivation, same scheme as lnurl_server -
|
||||
// a seed restored there or here produces the same identity for a given domain
|
||||
export const deriveLud05LinkingKey = (
|
||||
seedPhrase: string,
|
||||
domain: string
|
||||
): Uint8Array => {
|
||||
const seed = mnemonicToSeedSync(seedPhrase.trim().toLowerCase())
|
||||
const master = HDKey.fromMasterSeed(seed)
|
||||
|
||||
const hashingKeyNode = master.derive("m/138'/0")
|
||||
if (!hashingKeyNode.privateKey)
|
||||
throw new Error('Could not derive hashing key')
|
||||
const suffix = lud05PathSuffix(hashingKeyNode.privateKey, domain)
|
||||
|
||||
// path suffix longs are raw BIP32 child indices: whether each level ends up
|
||||
// hardened depends solely on its own magnitude (>= 2^31), never forced
|
||||
let node = master.deriveChild(138 + HARDENED_OFFSET)
|
||||
for (const index of suffix) {
|
||||
node = node.deriveChild(index)
|
||||
}
|
||||
if (!node.privateKey) throw new Error('Could not derive linking key')
|
||||
return node.privateKey
|
||||
}
|
||||
|
||||
// the HMAC half of the derivation, split out so the LUD-05 test vector
|
||||
// (which starts from a fixed hashingPrivKey, not a seed phrase) can pin it
|
||||
// directly - see keys.test.ts
|
||||
export const lud05PathSuffix = (
|
||||
hashingKey: Uint8Array,
|
||||
domain: string
|
||||
): number[] => {
|
||||
const material = hmac(sha256, hashingKey, utf8ToBytes(domain))
|
||||
return [0, 4, 8, 12].map(i => readUint32BE(material, i))
|
||||
}
|
||||
|
||||
export const deriveWalletLinkingKey = (seedPhrase: string): Uint8Array =>
|
||||
deriveLud05LinkingKey(seedPhrase, WALLET_DOMAIN)
|
||||
|
||||
export const linkingPubKeyHex = (linkingPrivKey: Uint8Array): string =>
|
||||
bytesToHex(secp256k1.getPublicKey(linkingPrivKey, true))
|
||||
|
||||
// Encrypted-at-rest localStorage secret, same shape as lnurl_server's: the
|
||||
// stored value is either plaintext or, if the holder opted in with a
|
||||
// password, AES-GCM ciphertext keyed by a PBKDF2 stretch of that password -
|
||||
// GCM's auth tag doubles as the "wrong password" check on decrypt.
|
||||
const PBKDF2_ITERATIONS = 210_000
|
||||
|
||||
export type StoredSecret =
|
||||
| {enc: false; value: string}
|
||||
| {enc: true; salt: string; iv: string; ciphertext: string}
|
||||
|
||||
// strict shape check on a StoredSecret - a plaintext form must be exactly a
|
||||
// 32-byte hex key, an encrypted form must carry hex salt/iv/ciphertext of
|
||||
// the sizes encryptSecretParts produces. Guards the backup-restore path
|
||||
// (storage.ts's applyBackup), where a crafted file would otherwise get an
|
||||
// arbitrary "linking key" installed verbatim.
|
||||
export const isValidStoredSecret = (
|
||||
stored: unknown
|
||||
): stored is StoredSecret => {
|
||||
if (typeof stored !== 'object' || stored === null) return false
|
||||
const s = stored as Record<string, unknown>
|
||||
if (s.enc === false) {
|
||||
return typeof s.value === 'string' && /^[0-9a-f]{64}$/i.test(s.value)
|
||||
}
|
||||
if (s.enc === true) {
|
||||
return (
|
||||
typeof s.salt === 'string' &&
|
||||
/^[0-9a-f]{32}$/i.test(s.salt) &&
|
||||
typeof s.iv === 'string' &&
|
||||
/^[0-9a-f]{24}$/i.test(s.iv) &&
|
||||
typeof s.ciphertext === 'string' &&
|
||||
s.ciphertext.length > 0 &&
|
||||
s.ciphertext.length % 2 === 0 &&
|
||||
/^[0-9a-f]+$/i.test(s.ciphertext)
|
||||
)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const readSecret = (storageKey: string): StoredSecret | null => {
|
||||
const raw = localStorage.getItem(storageKey)
|
||||
if (!raw) return null
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(raw)
|
||||
return isValidStoredSecret(parsed) ? parsed : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const deriveAesKeyFromPassword = (
|
||||
password: string,
|
||||
salt: Uint8Array
|
||||
): Promise<CryptoKey> =>
|
||||
crypto.subtle
|
||||
.importKey('raw', utf8ToBytes(password), 'PBKDF2', false, ['deriveKey'])
|
||||
.then(baseKey =>
|
||||
crypto.subtle.deriveKey(
|
||||
// the copy pins the TS type to Uint8Array<ArrayBuffer> - hexToBytes
|
||||
// returns Uint8Array<ArrayBufferLike>, which BufferSource rejects
|
||||
{
|
||||
name: 'PBKDF2',
|
||||
salt: new Uint8Array(salt),
|
||||
iterations: PBKDF2_ITERATIONS,
|
||||
hash: 'SHA-256'
|
||||
},
|
||||
baseKey,
|
||||
{name: 'AES-GCM', length: 256},
|
||||
false,
|
||||
['encrypt', 'decrypt']
|
||||
)
|
||||
)
|
||||
|
||||
export type EncryptedSecretParts = {
|
||||
salt: string
|
||||
iv: string
|
||||
ciphertext: string
|
||||
}
|
||||
|
||||
export const encryptSecretParts = async (
|
||||
value: string,
|
||||
password: string
|
||||
): Promise<EncryptedSecretParts> => {
|
||||
const salt = crypto.getRandomValues(new Uint8Array(16))
|
||||
const iv = crypto.getRandomValues(new Uint8Array(12))
|
||||
const aesKey = await deriveAesKeyFromPassword(password, salt)
|
||||
const ciphertext = new Uint8Array(
|
||||
await crypto.subtle.encrypt(
|
||||
{name: 'AES-GCM', iv},
|
||||
aesKey,
|
||||
utf8ToBytes(value)
|
||||
)
|
||||
)
|
||||
return {
|
||||
salt: bytesToHex(salt),
|
||||
iv: bytesToHex(iv),
|
||||
ciphertext: bytesToHex(ciphertext)
|
||||
}
|
||||
}
|
||||
|
||||
// rejects (WebCrypto's own auth-tag check) if the password is wrong
|
||||
export const decryptSecretParts = async (
|
||||
parts: EncryptedSecretParts,
|
||||
password: string
|
||||
): Promise<string> => {
|
||||
const salt = hexToBytes(parts.salt)
|
||||
const iv = hexToBytes(parts.iv)
|
||||
const aesKey = await deriveAesKeyFromPassword(password, salt)
|
||||
const plaintext = await crypto.subtle.decrypt(
|
||||
{name: 'AES-GCM', iv},
|
||||
aesKey,
|
||||
hexToBytes(parts.ciphertext)
|
||||
)
|
||||
return new TextDecoder().decode(plaintext)
|
||||
}
|
||||
|
||||
// The linking key is the only secret this wallet persists - the seed phrase
|
||||
// it was derived from is shown once at setup and never stored. Everything
|
||||
// else at rest (the bearer tokens) is encrypted with a key derived from it,
|
||||
// so protecting this one record with a password protects the whole wallet.
|
||||
const LINKING_KEY_STORAGE_KEY = 'sattle_linking_key'
|
||||
|
||||
export const savedKeyExists = (): boolean =>
|
||||
readSecret(LINKING_KEY_STORAGE_KEY) !== null
|
||||
|
||||
export const savedKeyIsEncrypted = (): boolean =>
|
||||
readSecret(LINKING_KEY_STORAGE_KEY)?.enc === true
|
||||
|
||||
export const getSavedLinkingKeyStored = (): StoredSecret | null =>
|
||||
readSecret(LINKING_KEY_STORAGE_KEY)
|
||||
|
||||
export const getPlainLinkingKey = (): Uint8Array | null => {
|
||||
const stored = readSecret(LINKING_KEY_STORAGE_KEY)
|
||||
if (stored === null || stored.enc === true) return null
|
||||
return hexToBytes(stored.value)
|
||||
}
|
||||
|
||||
export const saveLinkingKey = async (
|
||||
linkingPrivKey: Uint8Array,
|
||||
password?: string
|
||||
): Promise<void> => {
|
||||
const hex = bytesToHex(linkingPrivKey)
|
||||
if (!password) {
|
||||
localStorage.setItem(
|
||||
LINKING_KEY_STORAGE_KEY,
|
||||
JSON.stringify({enc: false, value: hex})
|
||||
)
|
||||
return
|
||||
}
|
||||
const parts = await encryptSecretParts(hex, password)
|
||||
localStorage.setItem(
|
||||
LINKING_KEY_STORAGE_KEY,
|
||||
JSON.stringify({enc: true, ...parts})
|
||||
)
|
||||
}
|
||||
|
||||
export const restoreLinkingKeyStored = (stored: StoredSecret): void => {
|
||||
localStorage.setItem(LINKING_KEY_STORAGE_KEY, JSON.stringify(stored))
|
||||
}
|
||||
|
||||
export const decryptSavedLinkingKey = async (
|
||||
password: string
|
||||
): Promise<Uint8Array> => {
|
||||
const stored = readSecret(LINKING_KEY_STORAGE_KEY)
|
||||
if (!stored || !stored.enc) throw new Error('No encrypted linking key saved.')
|
||||
return hexToBytes(await decryptSecretParts(stored, password))
|
||||
}
|
||||
|
||||
export const clearSavedLinkingKey = (): void => {
|
||||
localStorage.removeItem(LINKING_KEY_STORAGE_KEY)
|
||||
}
|
||||
|
||||
// The bearer-encryption key is derived (not random): sha256 over the linking
|
||||
// key plus a fixed context string. Deterministic derivation is what makes
|
||||
// backup/restore work with nothing but the seed phrase - restore the seed on
|
||||
// a fresh device and every previously exported ciphertext decrypts again.
|
||||
const BEARER_KEY_CONTEXT = 'lnurlcash-bearer-encryption-v1'
|
||||
|
||||
export const deriveBearerAesKey = (
|
||||
linkingPrivKey: Uint8Array
|
||||
): Promise<CryptoKey> => {
|
||||
const material = sha256(
|
||||
new Uint8Array([...linkingPrivKey, ...utf8ToBytes(BEARER_KEY_CONTEXT)])
|
||||
)
|
||||
return crypto.subtle.importKey('raw', material, 'AES-GCM', false, [
|
||||
'encrypt',
|
||||
'decrypt'
|
||||
])
|
||||
}
|
||||
|
||||
export type EncryptedRecordParts = {iv: string; ciphertext: string}
|
||||
|
||||
export const encryptRecord = async (
|
||||
aesKey: CryptoKey,
|
||||
value: object
|
||||
): Promise<EncryptedRecordParts> => {
|
||||
const iv = crypto.getRandomValues(new Uint8Array(12))
|
||||
const ciphertext = new Uint8Array(
|
||||
await crypto.subtle.encrypt(
|
||||
{name: 'AES-GCM', iv},
|
||||
aesKey,
|
||||
utf8ToBytes(JSON.stringify(value))
|
||||
)
|
||||
)
|
||||
return {iv: bytesToHex(iv), ciphertext: bytesToHex(ciphertext)}
|
||||
}
|
||||
|
||||
export const decryptRecord = async <T>(
|
||||
aesKey: CryptoKey,
|
||||
parts: EncryptedRecordParts
|
||||
): Promise<T> => {
|
||||
const plaintext = await crypto.subtle.decrypt(
|
||||
{name: 'AES-GCM', iv: hexToBytes(parts.iv)},
|
||||
aesKey,
|
||||
hexToBytes(parts.ciphertext)
|
||||
)
|
||||
return JSON.parse(new TextDecoder().decode(plaintext)) as T
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import {
|
||||
resolveNoteInput,
|
||||
noteK1,
|
||||
noteDeclaredAmount,
|
||||
serverOf,
|
||||
fetchNoteInfo,
|
||||
rotateNote,
|
||||
withNewK1,
|
||||
NoteSpentError,
|
||||
NoteUnknownError
|
||||
} from 'lnurlcash-kit'
|
||||
import type {Bearer, NewBearer} from './types'
|
||||
|
||||
// shared by Scan and Paste: resolve whatever came in to a note URL, ask the
|
||||
// issuing service what it is worth (an informational GET - per spec this
|
||||
// always puts k1 on the wire, so receive.ts's caller should rotate right
|
||||
// after, see secureReceivedNote). Returns the note even when the info fetch
|
||||
// fails - a bearer is better stored unverified than dropped.
|
||||
export const receiveNote = async (
|
||||
input: string,
|
||||
existing: Bearer[]
|
||||
): Promise<NewBearer> => {
|
||||
const url = resolveNoteInput(input)
|
||||
if (!url) {
|
||||
throw new Error('Not an LNURLcash bearer note (needs a k1).')
|
||||
}
|
||||
const k1 = noteK1(url)
|
||||
if (
|
||||
existing.some(
|
||||
b => noteK1(b.url) === k1 && serverOf(b.url) === serverOf(url)
|
||||
)
|
||||
) {
|
||||
throw new Error('This note is already in your wallet.')
|
||||
}
|
||||
try {
|
||||
const info = await fetchNoteInfo(url)
|
||||
return {
|
||||
url,
|
||||
callback: info.callback,
|
||||
amount: info.maxWithdrawable,
|
||||
verified: true,
|
||||
mintPubkey: info.mintPubkey
|
||||
}
|
||||
} catch (err) {
|
||||
// the service positively told us this k1 is dead - that's worth more
|
||||
// than the sender's own claim, so don't paper over it with an
|
||||
// unverified fallback the way an unreachable/unknown-shaped error
|
||||
// below does. The caller (ReceiveDialog.tsx) surfaces this and never stores
|
||||
// the note.
|
||||
if (err instanceof NoteSpentError || err instanceof NoteUnknownError) {
|
||||
throw err
|
||||
}
|
||||
// service unreachable (or some other non-definitive failure) - fall
|
||||
// back to the sender's own (unverified) declared amount so the note
|
||||
// isn't shown as worth nothing
|
||||
return {
|
||||
url,
|
||||
callback: '',
|
||||
amount: noteDeclaredAmount(url) ?? 0,
|
||||
verified: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// After receiving a note, rotate it: the previous holder (and anything that
|
||||
// logged the URL in transit, since the informational GET above already put
|
||||
// k1 on the wire) still knows the old secret - a rotate burns it and mints
|
||||
// a fresh one only this wallet knows. Returns the updated note URL. Throws
|
||||
// when the service refuses (e.g. a plain LUD-03 withdraw link that doesn't
|
||||
// speak lnurlcash) - the caller should warn, not fail the receive.
|
||||
export const secureReceivedNote = async (note: {
|
||||
url: string
|
||||
callback: string
|
||||
amount: number
|
||||
}): Promise<string> => {
|
||||
const k1 = noteK1(note.url)
|
||||
if (!k1 || !note.callback) {
|
||||
throw new Error('Note has no callback to rotate against yet.')
|
||||
}
|
||||
const result = await rotateNote(note.callback, k1)
|
||||
return withNewK1(note.url, result.k1, note.amount, result.signature)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Shared note types for the protocol core. In lnurl-wallet these lived in
|
||||
// storage.ts (Bearer) and WalletContext.tsx (NewBearer); here they are
|
||||
// extracted framework-free so receive.ts doesn't pull in app state modules.
|
||||
|
||||
// One bearer note held by this wallet - the decrypted, in-memory shape.
|
||||
// `url` is the note's withdraw LNURL with the secret as its k1 param (so it
|
||||
// IS the asset); the displayable bech32/lnurlw:// forms are re-encoded from
|
||||
// it on demand.
|
||||
export type Bearer = {
|
||||
id: string
|
||||
url: string
|
||||
callback: string // the mutating callback from the withdrawRequest JSON, '' until first verified
|
||||
amount: number // msat, last known (maxWithdrawable) - refreshed on demand
|
||||
verified: boolean // false while the issuing service hasn't confirmed the note yet
|
||||
// the issuing service's signing pubkey, cached once seen (withdrawRequest/
|
||||
// payRequest's optional mintPubkey) - lets a note's ?sig= be checked
|
||||
// offline against it without a network round trip
|
||||
mintPubkey?: string
|
||||
// a local-only lock, not a server-verified state: true once this wallet
|
||||
// has melted/handed over the note, or the holder marked it manually. It
|
||||
// just disables further mutating actions here so this copy can't be
|
||||
// reused by accident - it says nothing about whether the service has
|
||||
// actually burned it yet
|
||||
spent?: boolean
|
||||
// manual display order within its mint group - absent means "never
|
||||
// manually placed", which sorts by -createdAt instead, i.e. newest first
|
||||
sortIndex?: number
|
||||
// a free-text note the holder can attach for their own reference (e.g.
|
||||
// "rent", "gift for Alex") - purely local, never sent anywhere, no
|
||||
// protocol meaning at all
|
||||
label?: string
|
||||
// present if this note's secret lives on a paired LNURLvault device,
|
||||
// never in this browser's storage - the device's own note id. When set,
|
||||
// `url` never carries a real k1 (see lnurlcash.ts's withoutK1) - it's a
|
||||
// blank mirror, kept only so this bearer displays like any other
|
||||
// (amount/host/label/state)
|
||||
deviceId?: string
|
||||
createdAt: number
|
||||
updatedAt: number
|
||||
}
|
||||
|
||||
export type NewBearer = {
|
||||
url: string
|
||||
callback: string
|
||||
amount: number
|
||||
verified: boolean
|
||||
mintPubkey?: string
|
||||
deviceId?: string
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<template>
|
||||
<div class="fullscreen bg-blue text-white text-center q-pa-md flex flex-center">
|
||||
<div>
|
||||
<div style="font-size: 30vh">404</div>
|
||||
|
||||
<div class="text-h2" style="opacity: 0.4">Oops. Nothing here...</div>
|
||||
|
||||
<q-btn
|
||||
class="q-mt-xl"
|
||||
color="white"
|
||||
text-color="blue"
|
||||
unelevated
|
||||
to="/"
|
||||
label="Go Home"
|
||||
no-caps
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<q-page class="column items-center q-pa-md">
|
||||
<!-- balance hero: placeholder until M2 wires the note store -->
|
||||
<q-card class="sattle-card balance-card full-width q-mt-xl q-pa-lg text-center">
|
||||
<div class="text-h2 text-weight-bold text-primary">0</div>
|
||||
<div class="text-subtitle1 text-grey-5">sats</div>
|
||||
</q-card>
|
||||
|
||||
<div class="col" />
|
||||
|
||||
<!-- primary actions: visual only, protocol flows land in M2 -->
|
||||
<div class="row full-width justify-center items-center q-gutter-md q-mb-xl">
|
||||
<q-btn
|
||||
unelevated
|
||||
color="secondary"
|
||||
text-color="primary"
|
||||
icon="call_received"
|
||||
label="Receive"
|
||||
class="action-btn"
|
||||
@click="showReceive = true"
|
||||
/>
|
||||
<q-btn
|
||||
fab
|
||||
color="primary"
|
||||
text-color="dark"
|
||||
icon="qr_code_scanner"
|
||||
aria-label="Scan"
|
||||
class="scan-btn"
|
||||
@click="showScan = true"
|
||||
/>
|
||||
<q-btn
|
||||
unelevated
|
||||
color="secondary"
|
||||
text-color="primary"
|
||||
icon="call_made"
|
||||
label="Send"
|
||||
class="action-btn"
|
||||
@click="showSend = true"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<q-dialog v-model="showReceive">
|
||||
<q-card class="sattle-card q-pa-lg">
|
||||
<div class="text-h6">Receive</div>
|
||||
<div class="text-grey-5 q-mt-sm">Coming in milestone M2.</div>
|
||||
<q-card-actions align="right">
|
||||
<q-btn v-close-popup flat label="Close" color="primary" />
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<q-dialog v-model="showSend">
|
||||
<q-card class="sattle-card q-pa-lg">
|
||||
<div class="text-h6">Send</div>
|
||||
<div class="text-grey-5 q-mt-sm">Coming in milestone M2.</div>
|
||||
<q-card-actions align="right">
|
||||
<q-btn v-close-popup flat label="Close" color="primary" />
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<q-dialog v-model="showScan">
|
||||
<q-card class="sattle-card q-pa-lg">
|
||||
<div class="text-h6">Scan</div>
|
||||
<div class="text-grey-5 q-mt-sm">Coming in milestone M2.</div>
|
||||
<q-card-actions align="right">
|
||||
<q-btn v-close-popup flat label="Close" color="primary" />
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
|
||||
const showReceive = ref(false);
|
||||
const showSend = ref(false);
|
||||
const showScan = ref(false);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.balance-card {
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
min-width: 120px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.scan-btn {
|
||||
margin: 0 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<q-page class="q-pa-md">
|
||||
<div class="text-h5 text-weight-bold q-mb-md">Settings</div>
|
||||
|
||||
<!-- group shells only - entries are placeholders until their milestone
|
||||
lands (see project plan: M2 flows, M3 mints, M4 backup/security,
|
||||
M5 NWC) -->
|
||||
<q-list
|
||||
v-for="group in groups"
|
||||
:key="group.label"
|
||||
class="sattle-card q-mb-md"
|
||||
bordered
|
||||
separator
|
||||
>
|
||||
<q-item-label header class="text-primary text-weight-bold">
|
||||
{{ group.label }}
|
||||
</q-item-label>
|
||||
<q-item v-for="item in group.items" :key="item" disable>
|
||||
<q-item-section>{{ item }}</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const groups: { label: string; items: string[] }[] = [
|
||||
{ label: 'Wallet', items: ['Backup', 'Security'] },
|
||||
{ label: 'Connections', items: ['Nostr Wallet Connect', 'Nostr'] },
|
||||
{ label: 'Mints', items: ['Manage mints', 'Move funds'] },
|
||||
{ label: 'Preferences', items: ['Appearance', 'Language', 'Fiat unit'] },
|
||||
{
|
||||
label: 'Advanced',
|
||||
items: ['Notes', 'Offline mode', 'Activity log', 'Export / import', 'Developer'],
|
||||
},
|
||||
{ label: 'About', items: ['Docs', 'Protocol'] },
|
||||
];
|
||||
</script>
|
||||
@@ -0,0 +1,34 @@
|
||||
<template>
|
||||
<q-page class="column items-center justify-center q-pa-md">
|
||||
<div class="text-h3 text-weight-bold text-primary">sattle</div>
|
||||
<div class="text-subtitle1 text-grey-5 q-mt-sm q-mb-xl text-center">
|
||||
A wallet for lnurlcash bearer notes.
|
||||
</div>
|
||||
|
||||
<!-- onboarding placeholder: create/restore flows land in M4 -->
|
||||
<q-btn
|
||||
unelevated
|
||||
color="secondary"
|
||||
text-color="primary"
|
||||
label="Create wallet"
|
||||
class="full-width q-mb-sm onboarding-btn"
|
||||
disable
|
||||
/>
|
||||
<q-btn
|
||||
outline
|
||||
color="primary"
|
||||
label="Restore wallet"
|
||||
class="full-width onboarding-btn"
|
||||
disable
|
||||
/>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.onboarding-btn {
|
||||
max-width: 320px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,38 @@
|
||||
import { defineRouter } from '#q-app';
|
||||
import {
|
||||
createMemoryHistory,
|
||||
createRouter,
|
||||
createWebHashHistory,
|
||||
createWebHistory,
|
||||
} from 'vue-router';
|
||||
|
||||
import routes from './routes';
|
||||
|
||||
/*
|
||||
* If not building with SSR mode, you can
|
||||
* directly export the Router instantiation;
|
||||
*
|
||||
* The function below can be async too; either use
|
||||
* async/await or return a Promise which resolves
|
||||
* with the Router instance.
|
||||
*/
|
||||
|
||||
export default defineRouter((/* { store, ssrContext } */) => {
|
||||
const createHistory = import.meta.env.QUASAR_SERVER
|
||||
? createMemoryHistory
|
||||
: import.meta.env.QUASAR_VUE_ROUTER_MODE === 'history'
|
||||
? createWebHistory
|
||||
: createWebHashHistory;
|
||||
|
||||
const Router = createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
routes,
|
||||
|
||||
// Leave this as is and make changes in quasar.conf.js instead!
|
||||
// quasar.conf.js -> build -> vueRouterMode
|
||||
// quasar.conf.js -> build -> publicPath
|
||||
history: createHistory(import.meta.env.QUASAR_VUE_ROUTER_BASE),
|
||||
});
|
||||
|
||||
return Router;
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layouts/MainLayout.vue'),
|
||||
children: [
|
||||
{ path: '', component: () => import('@/pages/IndexPage.vue') },
|
||||
{ path: 'settings', component: () => import('@/pages/SettingsPage.vue') },
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/welcome',
|
||||
component: () => import('@/pages/WelcomePage.vue'),
|
||||
},
|
||||
|
||||
// Always leave this as last one,
|
||||
// but you can also remove it
|
||||
{
|
||||
path: '/:catchAll(.*)*',
|
||||
component: () => import('@/pages/ErrorNotFound.vue'),
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
@@ -0,0 +1,32 @@
|
||||
import { defineStore } from '#q-app';
|
||||
import { createPinia } from 'pinia';
|
||||
|
||||
/*
|
||||
* When adding new properties to stores, you should also
|
||||
* extend the `PiniaCustomProperties` interface.
|
||||
* @see https://pinia.vuejs.org/core-concepts/plugins.html#typing-new-store-properties
|
||||
*/
|
||||
declare module 'pinia' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
export interface PiniaCustomProperties {
|
||||
// add your custom properties here, if any
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If not building with SSR mode, you can
|
||||
* directly export the Store instantiation;
|
||||
*
|
||||
* The function below can be async too; either use
|
||||
* async/await or return a Promise which resolves
|
||||
* with the Store instance.
|
||||
*/
|
||||
|
||||
export default defineStore((/* { ssrContext } */) => {
|
||||
const pinia = createPinia();
|
||||
|
||||
// You can add Pinia plugins here
|
||||
// pinia.use(SomePiniaPlugin)
|
||||
|
||||
return pinia;
|
||||
});
|
||||
Reference in New Issue
Block a user