Skip to content

Commit

Permalink
chore: Bump version to 0.3.0 (#1)
Browse files Browse the repository at this point in the history
* feat: Use AccountId32 for account identifier

* style: Reformat

* chore: Rename variables
  • Loading branch information
conr2d authored Jul 26, 2024
1 parent 714ce96 commit 0b75185
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 39 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keyhub",
"version": "0.1.0",
"version": "0.3.0",
"license": "AGPL-3.0-or-later",
"scripts": {
"dev": "vite dev",
Expand All @@ -18,8 +18,9 @@
"@github/webauthn-json": "^2.1.1",
"@material/material-color-utilities": "^0.2.6",
"@noble/curves": "^1.1.0",
"@pinot/api": "^0.1.0",
"@pinot/util": "^0.1.2",
"@pinot/api": "^0.3.1",
"@pinot/util": "^0.3.0",
"@polkadot/util-crypto": "^12.6.2",
"@simplewebauthn/server": "^7.4.0",
"@simplewebauthn/typescript-types": "^7.4.0",
"@smui/button": "^7.0.0-beta.14",
Expand Down Expand Up @@ -49,6 +50,7 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-svelte": "^2.32.4",
"html5-qrcode": "^2.3.8",
"intl-messageformat": "^10.5.14",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"smui-theme": "^7.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/Id.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
{#each keys as key}
<div class="card">
<div class="key-container">
{'did:key:' + key.public_key}
{key.public_key}
</div>
<div class="key-desc">
<div class="key-content-name">
Expand Down
32 changes: 20 additions & 12 deletions src/lib/pages/Wallet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import type { Account } from '$lib/types';
import type { IconName } from '$lib/ui/icon';
import type { ApiPromise, WebAuthnSigner } from '@pinot/api';
import { bnToBn, hexToU8a, u8aConcat, u8aToBase64url } from '@pinot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
import { bnToBn, hexToU8a, u8aConcat } from '@pinot/util';
import { blake2AsU8a, encodeAddress } from '@polkadot/util-crypto';
import Fab from '@smui/fab';
import Textfield from '@smui/textfield';
import { Splide, SplideSlide, SplideTrack } from '@splidejs/svelte-splide';
Expand Down Expand Up @@ -59,25 +59,29 @@
let to = data?.to ?? '';
let amount = data?.amount ?? '';
const BILLION = bnToBn(1000000000);
const TEN_TRILLION = bnToBn('100000000000000');
/**
* onClick handler for confirm button in send page.
*/
async function confirmTransfer() {
let resolved = to;
if (to.startsWith('0x')) {
const address = await api.query.accountAliasRegistry.accountAliases({ EthereumAddress: to });
const address = await api.query.alias.accountIdOf({ EthereumAddress: to });
if (!address || address.toHex() === '0x') {
let u8a = blake2AsU8a(u8aConcat(Uint8Array.from([0x65, 0x76, 0x6d, 0x3a]), hexToU8a(to)));
u8a = u8aConcat(Uint8Array.from([0xa0, 0xe4, 0x02, 0x20]), u8a);
resolved = 'u' + u8aToBase64url(u8a);
resolved = encodeAddress(u8a);
} else {
resolved = 'u' + u8aToBase64url(address.toU8a(true));
resolved = encodeAddress(address);
}
}
await api.tx.balances
.transfer(resolved, bnToBn(amount).mul(BILLION).toString())
.transferKeepAlive(
resolved,
bnToBn((parseFloat(amount) * 10000).toFixed(0))
.mul(TEN_TRILLION)
.toString()
)
.signAndSend(signers[active].address, { signer: signers[active] });
to = '';
amount = '';
Expand Down Expand Up @@ -218,7 +222,7 @@
</div>
<div class="card__content">
<div class="amount">{balances[i] ?? '-'}</div>
<div class="unit">nCDT</div>
<div class="unit">CDT</div>
</div>
</button>
</SplideSlide>
Expand All @@ -245,10 +249,10 @@
bind:value={amount}
label="Amount"
style="margin-top: 12px;"
suffix="nCDT"
input$inputmode="numeric"
suffix="CDT"
input$inputmode="decimal"
type="text"
input$pattern="[0-9]*"
input$pattern="([0-9]*|[0-9]+\.[0-9]*)"
>
<Icon smui="textfield" name="price_change" variant="rounded" slot="leadingIcon" />
</Textfield>
Expand Down Expand Up @@ -283,6 +287,9 @@
<div class="reader-container">
<div id="reader" />
</div>
{#if context === 'read'}
<Button on:click={() => setContext('send')}>input recipient</Button>
{/if}
{#if context === 'remv'}
<div class="button-container">
<Button variant="filled" class="button-error" on:click={() => removeCard()}>
Expand Down Expand Up @@ -363,6 +370,7 @@
color: var(--mdc-theme-on-surface);
width: 54px;
height: 54px;
cursor: default;
}
.network-selector__icon {
Expand Down
17 changes: 7 additions & 10 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { onMount, onDestroy } from 'svelte';
import Layout from './Layout.svelte';
import { goto } from '$app/navigation';
import { Apps, Entry, Id, Settings, Wallet } from '$lib/pages';
import { Entry, Id, Settings, Wallet } from '$lib/pages';
import { path } from '$lib/stores';
import { timestamp } from '$lib/utils';
Expand All @@ -19,7 +19,7 @@
let signers: WebAuthnSigner[] = [];
let unsubs = [];
const BILLION = bnToBn(1000000000);
const TEN_TRILLION = bnToBn('100000000000000');
onMount(async () => {
const cachedKeys = localStorage.getItem('keys');
Expand Down Expand Up @@ -77,10 +77,9 @@
balances.push('-');
unsubs.push(
await api.query.system.account(addressRaw, ({ data: { free } }) => {
balances[i] = bnToBn(free.toHex())
.div(BILLION)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
balances[i] = (
parseInt(bnToBn(free.toHex()).div(TEN_TRILLION).toString()) / 10000
).toLocaleString('en-US', { minimumFractionDigits: 4, maximumFractionDigits: 4 });
})
);
}
Expand Down Expand Up @@ -126,16 +125,14 @@

<Layout>
{#if $path.startsWith('/wallet')}
<Wallet bind:api bind:accounts bind:balances bind:signers {removeAccount} data={data?.wallet} />
<Wallet {api} {accounts} {balances} {signers} {removeAccount} data={data?.wallet} />
{:else if $path.startsWith('/id')}
<Id bind:keys />
<Id {keys} />
{:else}
<div class="content-wrapper">
<div class="content">
{#if $path.startsWith('/entry')}
<Entry />
{:else if $path.startsWith('/apps')}
<Apps />
{:else if $path.startsWith('/settings')}
<Settings />
{/if}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { PageLoad } from './$types';

export async function load({ url }: PageLoad) {
const endpoint = url.searchParams.get('endpoint') ?? 'wss://testnet.noirhq.org';
const endpoint =
url.searchParams.get('endpoint') ?? import.meta.env.VITE_NODE_ENDPOINT ?? 'ws://localhost:9944';
const path = url.searchParams.get('path');
let wallet = {};

Expand Down
5 changes: 0 additions & 5 deletions src/routes/Layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
icon: 'badge',
path: '/id'
},
{
id: 'apps',
icon: 'apps',
path: '/apps'
},
{
id: 'settings',
icon: 'settings',
Expand Down
7 changes: 4 additions & 3 deletions src/routes/api/v1/users/me/keys/+server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { User, Key } from '$server/v1/types/types.server';
import { p256 } from '@noble/curves/p256';
import { blake2AsU8a, encodeAddress } from '@polkadot/util-crypto';
import {
generateRegistrationOptions,
verifyRegistrationResponse,
Expand Down Expand Up @@ -110,8 +111,8 @@ export async function PUT({ request }) {

const publicKey = p256.ProjectivePoint.fromHex(
'04' + x.toString('hex') + y.toString('hex')
).toHex(true);
const universalAddress = `u${Buffer.from(`8024${publicKey}`, 'hex').toString('base64url')}`;
).toRawBytes(true);
const accountId = encodeAddress(blake2AsU8a(publicKey));

let verification: VerifiedRegistrationResponse;
try {
Expand Down Expand Up @@ -143,7 +144,7 @@ export async function PUT({ request }) {
const insertedAlias = get<string>(alias);
const createdKey: Key = {
user_id,
public_key: universalAddress,
public_key: accountId,
alias: insertedAlias,
credential_id: Buffer.from(credentialID).toString('base64url'),
cred: JSON.stringify(authenticator),
Expand Down
8 changes: 5 additions & 3 deletions src/routes/api/v1/webauthn/registration/finish/+server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { User, Key } from '$server/v1/types/types.server';
import { p256 } from '@noble/curves/p256';
import { blake2AsU8a, encodeAddress } from '@polkadot/util-crypto';
import {
verifyRegistrationResponse,
type VerifiedRegistrationResponse
Expand Down Expand Up @@ -35,8 +36,9 @@ export async function POST({ request }) {

const publicKey = p256.ProjectivePoint.fromHex(
'04' + x.toString('hex') + y.toString('hex')
).toHex(true);
const universalAddress = `u${Buffer.from(`8024${publicKey}`, 'hex').toString('base64url')}`;
).toRawBytes(true);
const accountId = encodeAddress(blake2AsU8a(publicKey));

let verification: VerifiedRegistrationResponse;
try {
verification = await verifyRegistrationResponse({
Expand Down Expand Up @@ -69,7 +71,7 @@ export async function POST({ request }) {
};
const createdKey: Key = {
user_id: userId,
public_key: universalAddress,
public_key: accountId,
credential_id: Buffer.from(credentialID).toString('base64url'),
cred: JSON.stringify(authenticator),
is_primary: true,
Expand Down
3 changes: 2 additions & 1 deletion src/routes/api/v1/webauthn/registration/start/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export async function POST({ request }) {
userDisplayName: username,
authenticatorSelection: {
requireResidentKey
}
},
supportedAlgorithmIDs: [-7]
});

user.set(username);
Expand Down

0 comments on commit 0b75185

Please sign in to comment.