Skip to content

Commit cba36c9

Browse files
chore: add util
1 parent 01c8574 commit cba36c9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { secp256k1, type UnsignedTx } from '../../../../src';
2+
3+
export const addSigToAllCreds = async (
4+
unsignedTx: UnsignedTx,
5+
privateKey: Uint8Array,
6+
) => {
7+
const unsignedBytes = unsignedTx.toBytes();
8+
const publicKey = secp256k1.getPublicKey(privateKey);
9+
10+
if (!unsignedTx.hasPubkey(publicKey)) {
11+
return;
12+
}
13+
const signature = await secp256k1.sign(unsignedBytes, privateKey);
14+
15+
for (let i = 0; i < unsignedTx.getCredentials().length; i++) {
16+
unsignedTx.addSignatureAt(signature, i, 0);
17+
}
18+
};

0 commit comments

Comments
 (0)