Skip to content

Commit

Permalink
feat: follow latest Athena tx format changes for Wallet account
Browse files Browse the repository at this point in the history
  • Loading branch information
brusherru committed Jan 16, 2025
1 parent e6bf640 commit 8fc33f9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 24 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.2",
"@spacemesh/sm-codec": "^0.9.0-athena.3",
"@tabler/icons-react": "^3.1.0",
"@tanstack/react-virtual": "^3.3.0",
"@uidotdev/usehooks": "^2.4.1",
Expand Down
10 changes: 0 additions & 10 deletions src/components/CreateAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,6 @@ function CreateAccountModal({
value={unusedKey?.publicKey}
hasCreateOption
/>
<FormInput
label="Nonce"
inputProps={{ type: 'number' }}
register={register('Nonce', {
required: 'Please specify nonce',
valueAsNumber: true,
})}
errors={errors}
isSubmitted={isSubmitted}
/>
</>
);
default:
Expand Down
3 changes: 0 additions & 3 deletions src/components/createAccountSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const MainAccountSchemas = z.discriminatedUnion('templateAddress', [
const AthenaWalletSchema = z.object({
displayName: DisplayNameSchema,
templateAddress: z.literal(`A${Athena.Wallet.TEMPLATE_PUBKEY_HEX}`),
Nonce: z.number().int().min(0),
PublicKey: PublicKeySchema,
});

Expand Down Expand Up @@ -99,8 +98,6 @@ export const extractSpawnArgs = (data: FormValues): AnySpawnArguments => {
args = AthenaWalletSchema.safeParse(data);
if (args.success) {
return {
Nonce: args.data.Nonce,
Balance: 0,
PublicKey: args.data.PublicKey,
};
}
Expand Down
14 changes: 9 additions & 5 deletions src/components/sendTx/SendTxModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Athena,
Codecs,
DrainArguments,
hash,
MultiSigSpawnArguments as MultiSigSpawnArgumentsTx,
MultiSigTemplate,
SingleSigSpawnArguments as SingleSigSpawnArgumentsTx,
Expand Down Expand Up @@ -368,6 +369,7 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
].methods[Athena.Wallet.METHODS_HEX.SPAWN].enc({
Version: 1n,
Principal: pinripalBytes,
TemplateAddress: Athena.Wallet.TEMPLATE_PUBKEY,
Nonce: BigInt(data.nonce),
GasPrice: BigInt(data.gasPrice),
Payload: Arguments,
Expand Down Expand Up @@ -508,6 +510,7 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
].methods[Athena.Wallet.METHODS_HEX.SPEND].enc({
Version: 1n,
Principal: pinripalBytes,
TemplateAddress: undefined,
Nonce: BigInt(data.nonce),
GasPrice: BigInt(data.gasPrice),
Payload: Arguments,
Expand Down Expand Up @@ -677,6 +680,11 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
throw new Error('Cannot sign transaction: Open the wallet first');
}
const keyToUse = wallet.keychain.find((k) => k.publicKey === signWith);
// TODO: Remove that Athena kludge
const dataToSign = currerntAccount.isAthena
? hash(txData.encoded)
: prepareTxForSign(genesisID, txData.encoded);

if (isForeignKey(keyToUse) && keyToUse.origin === KeyOrigin.Ledger) {
if (!(await checkDeviceConnection()) || !connectedDevice) {
return null;
Expand All @@ -688,10 +696,6 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
modalWrongDevice.onOpen();
return null;
}
// TODO: Remove that Athena kludge
const dataToSign = currerntAccount.isAthena
? txData.encoded
: prepareTxForSign(genesisID, txData.encoded);

return connectedDevice.actions
.signTx(keyToUse.path, dataToSign)
Expand All @@ -704,7 +708,7 @@ function SendTxModal({ isOpen, onClose }: SendTxModalProps): JSX.Element {
return withPassword(
(password) =>
signTx(
txData.encoded,
dataToSign,
signWith,
password,
currerntAccount.isAthena || false
Expand Down
2 changes: 1 addition & 1 deletion src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +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(fromHexString(args.PublicKey));
const principal = tpl.principal({ PubKey: fromHexString(args.PublicKey) });
return generateAddress(principal, hrp);
}

Expand Down
8 changes: 4 additions & 4 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.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==
"@spacemesh/sm-codec@^0.9.0-athena.3":
version "0.9.0-athena.3"
resolved "https://registry.yarnpkg.com/@spacemesh/sm-codec/-/sm-codec-0.9.0-athena.3.tgz#00bab28cbd1b24914ecb39b8fa44ae5b1cd3c313"
integrity sha512-68jrlZCiHvApXLP3IDAUE36Q4nPDeA8m11LfmLshrwhhhAM4cwmwySYWBAe8V1RZUunisYRi0e2K9NYdlmlpkw==
dependencies:
"@noble/hashes" "^1.4.0"
scale-ts "^1.6.0"
Expand Down

0 comments on commit 8fc33f9

Please sign in to comment.