diff --git a/examples/p-chain/etna/createChain.ts b/examples/p-chain/etna/createChain.ts index 86520e589..a0164888d 100644 --- a/examples/p-chain/etna/createChain.ts +++ b/examples/p-chain/etna/createChain.ts @@ -1,7 +1,8 @@ -import { addTxSignatures, pvm, utils } from '../../../src'; +import { pvm, utils } from '../../../src'; import { setupEtnaExample } from './utils/etna-helper'; import { testGenesisData } from '../../../src/fixtures/transactions'; import { getEnvVars } from '../../utils/getEnvVars'; +import { addSigToAllCreds } from './utils/addSignatureToAllCred'; /** * Create a new chain on the P-Chain. @@ -38,10 +39,7 @@ const createChainTxExample = async () => { context, ); - await addTxSignatures({ - unsignedTx: tx, - privateKeys: [utils.hexToBuffer(PRIVATE_KEY)], - }); + await addSigToAllCreds(tx, utils.hexToBuffer(PRIVATE_KEY)); return pvmApi.issueSignedTx(tx.getSignedTx()); }; diff --git a/examples/p-chain/etna/utils/addSignatureToAllCred.ts b/examples/p-chain/etna/utils/addSignatureToAllCred.ts new file mode 100644 index 000000000..d1ed72763 --- /dev/null +++ b/examples/p-chain/etna/utils/addSignatureToAllCred.ts @@ -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); + } +};