Skip to content

Commit

Permalink
fix: sign button no longer relies for accouunt update
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranroneill committed Jul 10, 2024
1 parent 45328cc commit 81521b6
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 151 deletions.
56 changes: 56 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { sign } = require('tweetnacl');

Check failure on line 1 in index.js

View workflow job for this annotation

GitHub Actions / Lint

Require statement not part of import statement
const { encode } = require('@stablelib/hex');

Check failure on line 2 in index.js

View workflow job for this annotation

GitHub Actions / Lint

Require statement not part of import statement
const {
generateAccount,
mnemonicFromSeed,
secretKeyToMnemonic,
} = require('algosdk');

Check failure on line 7 in index.js

View workflow job for this annotation

GitHub Actions / Lint

Require statement not part of import statement

const account = generateAccount();
const seed = account.sk.slice(0, sign.seedLength);
const mnemonicFromPrivateKey = secretKeyToMnemonic(account.sk);
const _mnemonicFromSeed = mnemonicFromSeed(seed);

console.log('address:', account.addr);
console.log('privateKey byte length:', account.sk.byteLength);
console.log('seed:', encode(seed));
console.log('seed byte length:', seed.byteLength);
console.log('mnemonicFromPrivateKey:', mnemonicFromPrivateKey);
console.log('mnemonicFromSeed:', _mnemonicFromSeed);

const privateKey = account.sk.slice(0, sign.seedLength);
const publicKey = account.sk.slice(sign.seedLength, account.sk.length);

console.log('privateKey:', encode(privateKey));
console.log('publicKey:', encode(publicKey));
console.log(
'sign.keyPair.fromSecretKey()#publicKey:',
encode(sign.keyPair.fromSecretKey(account.sk).publicKey)
);

const generatePrivateKey = () =>

Check warning on line 31 in index.js

View workflow job for this annotation

GitHub Actions / Lint

'generatePrivateKey' is assigned a value but never used
encode(sign.keyPair().secretKey.slice(0, sign.seedLength), true);

console.log(sign.keyPair().secretKey);

const secretKey1 = new Uint8Array([
177, 128, 122, 222, 69, 20, 122, 56, 201, 121, 18, 112, 29, 225, 199, 16, 71,
212, 51, 244, 21, 102, 83, 245, 66, 165, 211, 55, 141, 79, 22, 204, 134, 189,
241, 74, 92, 222, 22, 218, 196, 197, 159, 174, 51, 203, 88, 234, 2, 76, 13, 0,
160, 180, 83, 193, 104, 39, 106, 9, 9, 209, 138, 81,
]);
const secretKey2 = new Uint8Array([
210, 190, 72, 201, 18, 160, 41, 151, 90, 41, 177, 247, 108, 197, 164, 64, 241,
187, 185, 93, 54, 145, 222, 245, 80, 99, 177, 236, 35, 18, 96, 70, 97, 7, 92,
174, 48, 168, 36, 207, 98, 82, 9, 209, 157, 7, 237, 213, 146, 251, 210, 140,
171, 245, 101, 201, 52, 211, 113, 77, 100, 37, 1, 103,
]);
const challenge = new Uint8Array([
178, 70, 214, 9, 123, 64, 164, 247, 117, 99, 228, 178, 196, 30, 33, 180, 249,
242, 116, 64, 204, 165, 83, 177, 51, 62, 98, 34, 164, 207, 220, 116,
]);
console.log('challenge:', encode(challenge));
console.log('secret key 1:', encode(secretKey1));
console.log('signature 1:', encode(sign.detached(challenge, secretKey1)));
console.log('secret key 2:', encode(secretKey2));
console.log('signature 2:', encode(sign.detached(challenge, secretKey2)));
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const PaymentTransactionContent: FC<ITransactionBodyProps> = ({
<VStack
alignItems="flex-start"
justifyContent="flex-start"
spacing={DEFAULT_GAP / 2}
spacing={DEFAULT_GAP / 3}
w="full"
>
{condensed ? (
Expand Down Expand Up @@ -223,7 +223,7 @@ const PaymentTransactionContent: FC<ITransactionBodyProps> = ({
isOpen={condensed.expanded}
onChange={condensed.onChange}
>
<VStack spacing={2} w="full">
<VStack spacing={DEFAULT_GAP / 3} w="full">
{renderExtraInformation()}
</VStack>
</MoreInformationAccordion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,23 @@ import {
useSelectAccounts,
useSelectLogger,
useSelectNetworks,
useSelectSessions,
} from '@extension/selectors';

// theme
import { theme } from '@extension/theme';

// types
import type { IAppThunkDispatch, IModalProps } from '@extension/types';
import type {
IAccountWithExtendedProps,
IAppThunkDispatch,
IModalProps,
} from '@extension/types';

// utils
import decodeUnsignedTransaction from '@extension/utils/decodeUnsignedTransaction';
import groupTransactions from '@extension/utils/groupTransactions';
import authorizedAccountsForEvent from './utils/authorizedAccountsForEvent';
import signTransactions from './utils/signTransactions';

const SignTransactionsModal: FC<IModalProps> = ({ onClose }) => {
Expand All @@ -76,9 +82,9 @@ const SignTransactionsModal: FC<IModalProps> = ({ onClose }) => {
const accounts = useSelectAccounts();
const logger = useSelectLogger();
const networks = useSelectNetworks();
const sessions = useSelectSessions();
// hooks
const { authorizedAccounts, event, setAuthorizedAccounts } =
useSignTransactionsModal();
const { event } = useSignTransactionsModal();
const {
error: passwordError,
onChange: onPasswordChange,
Expand All @@ -92,6 +98,7 @@ const SignTransactionsModal: FC<IModalProps> = ({ onClose }) => {
const [moreDetailsTransactions, setMoreDetailsTransactions] = useState<
Transaction[] | null
>(null);
const [signing, setSigning] = useState<boolean>(false);
// handlers
const handleCancelClick = async () => {
if (event) {
Expand All @@ -114,7 +121,6 @@ const SignTransactionsModal: FC<IModalProps> = ({ onClose }) => {
};
const handleClose = () => {
resetPassword();
setAuthorizedAccounts(null);

onClose && onClose();
};
Expand All @@ -127,18 +133,23 @@ const SignTransactionsModal: FC<IModalProps> = ({ onClose }) => {
};
const handlePreviousClick = () => setMoreDetailsTransactions(null);
const handleSignClick = async () => {
let authorizedAccounts: IAccountWithExtendedProps[];
let stxns: (string | null)[];

if (
validatePassword() ||
!event ||
!event.payload.message.params ||
!authorizedAccounts
) {
if (validatePassword() || !event || !event.payload.message.params) {
return;
}

setSigning(true);

try {
authorizedAccounts = await authorizedAccountsForEvent({
accounts,
event,
logger,
networks,
sessions,
});
stxns = await signTransactions({
accounts: authorizedAccounts,
arc0001Transactions: event.payload.message.params.txns,
Expand Down Expand Up @@ -193,6 +204,8 @@ const SignTransactionsModal: FC<IModalProps> = ({ onClose }) => {
break;
}
}

setSigning(false);
};
const renderContent = () => {
let decodedTransactions: Transaction[];
Expand Down Expand Up @@ -325,6 +338,7 @@ const SignTransactionsModal: FC<IModalProps> = ({ onClose }) => {

{/*sign button*/}
<Button
isLoading={signing}
onClick={handleSignClick}
size="lg"
variant="solid"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ISignTransactionsParams } from '@agoralabs-sh/avm-web-provider';

// types
import type { IClientRequestEvent } from '@extension/types';

interface IState {
event: IClientRequestEvent<ISignTransactionsParams> | null;
}

export default IState;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type { default as IUseSignTransactionsModalState } from './IUseSignTransactionsModalState';
export type { default as IState } from './IState';
Loading

0 comments on commit 81521b6

Please sign in to comment.