Skip to content

Commit

Permalink
Fixed defaulting for signing transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
amirsaran3 committed May 16, 2022
1 parent 3d88778 commit d270d9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
28 changes: 17 additions & 11 deletions packages/ledger/src/lib/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,32 @@ const Ledger: WalletBehaviourFactory<HardwareWallet> = async ({

const signer: Signer = {
createKey: () => {
throw Error("Not implemented");
throw new Error("Not implemented");
},
getPublicKey: async () => {
if (!_state.accounts.length) {
throw new Error(`${metadata.name} not connected`);
getPublicKey: async (accountId) => {
const account = _state.accounts.find((a) => a.accountId === accountId);

if (!account) {
throw new Error("Failed to find public key for account");
}

return utils.PublicKey.from(_state.accounts[0].publicKey);
return utils.PublicKey.from(account.publicKey);
},
signMessage: async (message: Uint8Array) => {
if (!_state.accounts.length) {
throw new Error(`${metadata.name} not connected`);
signMessage: async (message, accountId) => {
const account = _state.accounts.find((a) => a.accountId === accountId);

if (!account) {
throw new Error("Failed to find account for signing");
}

const signature = await _state.client.sign({
data: message,
derivationPath: _state.accounts[0].derivationPath,
derivationPath: account.derivationPath,
});

return {
signature,
publicKey: utils.PublicKey.from(_state.accounts[0].publicKey),
publicKey: utils.PublicKey.from(account.publicKey),
};
},
};
Expand Down Expand Up @@ -182,10 +186,12 @@ const Ledger: WalletBehaviourFactory<HardwareWallet> = async ({
throw new Error("Wallet not connected");
}

const signerId = t.signerId ? t.signerId : _state.accounts[0].accountId;

return {
receiverId: t.receiverId,
actions: t.actions,
signerId: _state.accounts[0].accountId,
signerId,
};
});
};
Expand Down
4 changes: 3 additions & 1 deletion packages/math-wallet/src/lib/math-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ const MathWallet: WalletBehaviourFactory<InjectedWallet> = async ({
}

return transactions.map((t) => {
const signerId = t.signerId ? t.signerId : account.accountId;

return {
receiverId: t.receiverId,
actions: t.actions,
signerId: account.accountId,
signerId,
};
});
};
Expand Down
6 changes: 4 additions & 2 deletions packages/wallet-utils/src/lib/sign-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ export const signTransactions = async (
signer: Signer,
networkId: string
) => {
const publicKey = (await signer.getPublicKey()).toString();

const provider = new providers.JsonRpcProvider({
url: networkId,
});

const signedTransactions: Array<nearTransactions.SignedTransaction> = [];

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

const [block, accessKey] = await Promise.all([
provider.block({ finality: "final" }),
provider.query<AccessKeyView>({
Expand Down

0 comments on commit d270d9c

Please sign in to comment.