Skip to content

Commit

Permalink
Merge pull request #294 from near/sign-transactions-fixes
Browse files Browse the repository at this point in the history
fix: `signTransactions` Improvements
  • Loading branch information
lewis-sqa authored May 20, 2022
2 parents 6e3f10c + 05ebfda commit c76fc49
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
7 changes: 1 addition & 6 deletions packages/ledger/src/lib/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,7 @@ const Ledger: WalletBehaviourFactory<HardwareWallet> = async ({
await connectLedgerDevice();

const signedTransactions = await signTransactions(
transformTransactions([
{
receiverId,
actions,
},
]),
transformTransactions([{ signerId, receiverId, actions }]),
signer,
options.network
);
Expand Down
7 changes: 1 addition & 6 deletions packages/math-wallet/src/lib/math-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ const MathWallet: WalletBehaviourFactory<InjectedWallet> = async ({
}

const signedTransactions = await signTransactions(
transformTransactions([
{
receiverId,
actions,
},
]),
transformTransactions([{ signerId, receiverId, actions }]),
_state.wallet.signer,
options.network
);
Expand Down
14 changes: 8 additions & 6 deletions packages/wallet-utils/src/lib/sign-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ export const signTransactions = async (
const signedTransactions: Array<nearTransactions.SignedTransaction> = [];

for (let i = 0; i < transactions.length; i++) {
const publicKey = (
await signer.getPublicKey(transactions[i].signerId, network.nodeUrl)
).toString();
const publicKey = await signer.getPublicKey(
transactions[i].signerId,
network.networkId
);

const [block, accessKey] = await Promise.all([
provider.block({ finality: "final" }),
provider.query<AccessKeyView>({
request_type: "view_access_key",
finality: "final",
account_id: transactions[i].signerId,
public_key: publicKey,
public_key: publicKey.toString(),
}),
]);

Expand All @@ -40,7 +41,7 @@ export const signTransactions = async (

const transaction = nearTransactions.createTransaction(
transactions[i].signerId,
utils.PublicKey.from(publicKey),
utils.PublicKey.from(publicKey.toString()),
transactions[i].receiverId,
accessKey.nonce + i + 1,
actions,
Expand All @@ -50,7 +51,8 @@ export const signTransactions = async (
const response = await nearTransactions.signTransaction(
transaction,
signer,
transactions[i].signerId
transactions[i].signerId,
network.networkId
);

signedTransactions.push(response[1]);
Expand Down

0 comments on commit c76fc49

Please sign in to comment.