Skip to content

Commit

Permalink
feat: get rid of Nonce and Balance from spawn arguments and princ…
Browse files Browse the repository at this point in the history
…ipal computation
  • Loading branch information
brusherru committed Nov 28, 2024
1 parent 3a51192 commit c594017
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 105 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@noble/ed25519": "^2.1.0",
"@scure/bip39": "^1.2.2",
"@spacemesh/ed25519-bip32": "^0.2.1",
"@spacemesh/sm-codec": "^0.9.0-athena.1",
"@spacemesh/sm-codec": "^0.9.0-athena.2",
"@tabler/icons-react": "^3.1.0",
"@tanstack/react-virtual": "^3.3.0",
"@uidotdev/usehooks": "^2.4.1",
Expand Down
7 changes: 6 additions & 1 deletion src/api/requests/tx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Athena, SpawnTransaction, SpendTransaction, StdMethods } from '@spacemesh/sm-codec';
import {
Athena,
SpawnTransaction,
SpendTransaction,
StdMethods,
} from '@spacemesh/sm-codec';

import { Bech32Address } from '../../types/common';
import { Transaction } from '../../types/tx';
Expand Down
51 changes: 0 additions & 51 deletions src/components/sendTx/AthenaWalletSpawn.tsx

This file was deleted.

8 changes: 1 addition & 7 deletions src/components/sendTx/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ const renderTemplateSpecificFields = (form: FormValues) => {
case athenaSuffix(Athena.Wallet.TEMPLATE_PUBKEY_HEX): {
if (form.payload.methodSelector === MethodSelectors.Spawn) {
const args = AthenaWalletSpawnSchema.parse(form.payload);
return (
<>
<PreviewDataRow label="Public key" value={args.PublicKey} />
<PreviewDataRow label="Nonce" value={String(args.Nonce)} />
<PreviewDataRow label="Balance" value={String(args.Balance)} />
</>
);
return <PreviewDataRow label="Public key" value={args.PublicKey} />;
}
if (form.payload.methodSelector === MethodSelectors.Spend) {
const args = SpendSchema.parse(form.payload);
Expand Down
34 changes: 3 additions & 31 deletions src/components/sendTx/SendTxModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import FormInput from '../FormInput';
import FormSelect from '../FormSelect';
import TxFileReader from '../TxFileReader';

import AthenaWalletSpawn from './AthenaWalletSpawn';
import ConfirmationModal, { ConfirmationData } from './ConfirmationModal';
import Drain from './Drain';
import ExportSuccessModal from './ExportSuccessModal';
Expand Down Expand Up @@ -363,8 +362,6 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
const args = AthenaWalletSpawnSchema.parse(data.payload);
const Arguments = {
PubKey: fromHexString(args.PublicKey),
Nonce: BigInt(args.Nonce),
Balance: BigInt(args.Balance),
};
const encoded = Athena.Templates[
'000000000000000000000000000000000000000000000001'
Expand All @@ -380,9 +377,7 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
accountsList.find(
(acc) =>
isAthenaWalletAccount(acc) &&
acc.spawnArguments.PublicKey === args.PublicKey &&
String(acc.spawnArguments.Nonce) === args.Nonce &&
String(acc.spawnArguments.Balance) === args.Balance
acc.spawnArguments.PublicKey === args.PublicKey
)?.displayName || 'external key';

setTxData({
Expand Down Expand Up @@ -1223,8 +1218,9 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
/>
);
}
case athenaSuffix(Athena.Wallet.TEMPLATE_PUBKEY_HEX):
case StdPublicKeys.SingleSig: {
if (!isSingleSigAccount(acc)) {
if (!isSingleSigAccount(acc) && !isAthenaWalletAccount(acc)) {
throw new Error('Invalid account type for SingleSig template');
}
return selectedMethod === StdMethods.Spawn ? (
Expand All @@ -1248,30 +1244,6 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
/>
);
}
case athenaSuffix(Athena.Wallet.TEMPLATE_PUBKEY_HEX): {
if (isAthenaWalletAccount(acc)) {
return selectedMethod === StdMethods.Spawn ? (
<AthenaWalletSpawn
register={register}
unregister={unregister}
setValue={setValue}
spawnArguments={acc.spawnArguments}
/>
) : (
<Spend
register={register}
unregister={unregister}
errors={errors}
isSubmitted={isSubmitted}
accounts={accountsList}
setValue={setValue}
getValues={getValues}
watch={watch}
/>
);
}
throw new Error('Invalid account type for Athena Wallet template');
}
default: {
return <Text color="red">Invalid template address</Text>;
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/sendTx/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Bech32AddressSchema } from '../../api/schemas/address';
import { HexStringSchema } from '../../api/schemas/common';
import { BigIntMin, BigIntStringSchema } from '../../api/schemas/strNumber';
import { Bech32Address } from '../../types/common';
import { athenaSuffix, MethodSelectors } from '../../utils/templates';
import { MethodSelectors } from '../../utils/templates';

// Tx schemas

Expand Down Expand Up @@ -68,8 +68,6 @@ export type VestingSpawnPayload = z.infer<typeof VestingSpawnSchema>;
export const AthenaWalletSpawnSchema = z.object({
methodSelector: z.literal(MethodSelectors.Spawn),
PublicKey: HexStringSchema,
Nonce: BigIntStringSchema.and(BigIntMin(0n)),
Balance: BigIntStringSchema.and(BigIntMin(0n)),
});

export type AthenaWalletSpawnPayload = z.infer<typeof AthenaWalletSpawnSchema>;
Expand Down Expand Up @@ -135,7 +133,7 @@ export type VestingTx = z.infer<typeof VestingSchema>;
export const AthenaWalletSchema = z.object({
templateAddress: z.literal(`A${Athena.Wallet.TEMPLATE_PUBKEY_HEX}`), // TODO
payload: z.discriminatedUnion('methodSelector', [
AthenaWalletSpawnSchema,
SingleSigSpawnSchema,
SpendSchema,
]),
...CommonTxFields,
Expand Down
6 changes: 1 addition & 5 deletions src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ export const computeAddress = <
// TODO: Add support of other addresses
const tpl = Athena.Templates[templateKey as Athena.TemplatePubKeys];
const args = spawnArguments as AthenaSpawnArguments;
const principal = tpl.principal({
Nonce: BigInt(args.Nonce),
Balance: BigInt(args.Balance),
Payload: fromHexString(args.PublicKey),
});
const principal = tpl.principal(fromHexString(args.PublicKey));
return generateAddress(principal, hrp);
}

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2349,10 +2349,10 @@
resolved "https://registry.yarnpkg.com/@spacemesh/ed25519-bip32/-/ed25519-bip32-0.2.1.tgz#f622616060fb477b1fbc5d1292ff21993927a3b2"
integrity sha512-wwB9FHotFBc1IqYLNZRXt9jZIm7K4gWap4EaotEGeoRLvVJNR/J63TXZBEsHhPrMOWTC2yAcxi6GC47bxsYOhA==

"@spacemesh/sm-codec@^0.9.0-athena.1":
version "0.9.0-athena.1"
resolved "https://registry.yarnpkg.com/@spacemesh/sm-codec/-/sm-codec-0.9.0-athena.1.tgz#4ea25a9567a09ce810ecae04274efb1a91a9fced"
integrity sha512-A4bX0WXNCPypyzbZ1L6DvTwcKUb224ogYeRu4m14VvKSXLaeN0lH9ytO7OYAGEj38xSHpT95fwuDhqrrRbdM0g==
"@spacemesh/sm-codec@^0.9.0-athena.2":
version "0.9.0-athena.2"
resolved "https://registry.yarnpkg.com/@spacemesh/sm-codec/-/sm-codec-0.9.0-athena.2.tgz#564c2b7719a1aef5a76d5447ef780e4111a5dcc0"
integrity sha512-Tmn746XJ/sfMpUscvlPQ09qgGM9tVpz1XhMHCg00WWKA3Dir4nkKHN8o/JPkAPHYzBZbdATtURJgk8r+2p8HPw==
dependencies:
"@noble/hashes" "^1.4.0"
scale-ts "^1.6.0"
Expand Down Expand Up @@ -3847,7 +3847,7 @@ create-require@^1.1.0, create-require@^1.1.1:
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

cross-spawn@7.0.5, cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.5.tgz#910aac880ff5243da96b728bc6521a5f6c2f2f82"
integrity sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==
Expand Down

0 comments on commit c594017

Please sign in to comment.