Skip to content

Commit 06c8738

Browse files
Merge pull request #913 from ava-labs/addSigToAllCred
chore: add sig to all credentials
2 parents ef80a85 + cba36c9 commit 06c8738

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

examples/p-chain/etna/createChain.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { addTxSignatures, pvm, utils } from '../../../src';
1+
import { pvm, utils } from '../../../src';
22
import { setupEtnaExample } from './utils/etna-helper';
33
import { testGenesisData } from '../../../src/fixtures/transactions';
44
import { getEnvVars } from '../../utils/getEnvVars';
5+
import { addSigToAllCreds } from './utils/addSignatureToAllCred';
56

67
/**
78
* Create a new chain on the P-Chain.
@@ -38,10 +39,7 @@ const createChainTxExample = async () => {
3839
context,
3940
);
4041

41-
await addTxSignatures({
42-
unsignedTx: tx,
43-
privateKeys: [utils.hexToBuffer(PRIVATE_KEY)],
44-
});
42+
await addSigToAllCreds(tx, utils.hexToBuffer(PRIVATE_KEY));
4543

4644
return pvmApi.issueSignedTx(tx.getSignedTx());
4745
};
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)