Skip to content

Commit

Permalink
Sign auth entries with correct public key in Keypair scenario (#772)
Browse files Browse the repository at this point in the history
Co-authored-by: George <[email protected]>
  • Loading branch information
kalepail and Shaptic authored Sep 12, 2024
1 parent dc0ceaa commit 78b7168
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ import { nativeToScVal } from './scval';
* authorization entry that you can pass along to
* {@link Operation.invokeHostFunction}
*
* @note If using the `SigningCallback` variation, the signer is assumed to be
* the entry's credential address. If you need a different key to sign the
* entry, you will need to use different method (e.g., fork this code).
*
* @see authorizeInvocation
* @example
* import {
Expand Down Expand Up @@ -131,12 +135,14 @@ export async function authorizeEntry(
const payload = hash(preimage.toXDR());

let signature;
let publicKey;
if (typeof signer === 'function') {
signature = Buffer.from(await signer(preimage));
publicKey = Address.fromScAddress(addrAuth.address()).toString();
} else {
signature = Buffer.from(signer.sign(payload));
publicKey = signer.publicKey();
}
const publicKey = Address.fromScAddress(addrAuth.address()).toString();

if (!Keypair.fromPublicKey(publicKey).verify(payload, signature)) {
throw new Error(`signature doesn't match payload`);
Expand Down

0 comments on commit 78b7168

Please sign in to comment.