File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1- import { addTxSignatures , pvm , utils } from '../../../src' ;
1+ import { pvm , utils } from '../../../src' ;
22import { setupEtnaExample } from './utils/etna-helper' ;
33import { testGenesisData } from '../../../src/fixtures/transactions' ;
44import { 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 number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments