Skip to content

Commit

Permalink
chore: add util
Browse files Browse the repository at this point in the history
  • Loading branch information
ruijialin-avalabs committed Nov 14, 2024
1 parent 01c8574 commit cba36c9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/p-chain/etna/utils/addSignatureToAllCred.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { secp256k1, type UnsignedTx } from '../../../../src';

export const addSigToAllCreds = async (
unsignedTx: UnsignedTx,
privateKey: Uint8Array,
) => {
const unsignedBytes = unsignedTx.toBytes();
const publicKey = secp256k1.getPublicKey(privateKey);

if (!unsignedTx.hasPubkey(publicKey)) {
return;
}
const signature = await secp256k1.sign(unsignedBytes, privateKey);

for (let i = 0; i < unsignedTx.getCredentials().length; i++) {
unsignedTx.addSignatureAt(signature, i, 0);
}
};

0 comments on commit cba36c9

Please sign in to comment.