File tree 2 files changed +21
-5
lines changed
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' ;
2
2
import { setupEtnaExample } from './utils/etna-helper' ;
3
3
import { testGenesisData } from '../../../src/fixtures/transactions' ;
4
4
import { getEnvVars } from '../../utils/getEnvVars' ;
5
+ import { addSigToAllCreds } from './utils/addSignatureToAllCred' ;
5
6
6
7
/**
7
8
* Create a new chain on the P-Chain.
@@ -38,10 +39,7 @@ const createChainTxExample = async () => {
38
39
context ,
39
40
) ;
40
41
41
- await addTxSignatures ( {
42
- unsignedTx : tx ,
43
- privateKeys : [ utils . hexToBuffer ( PRIVATE_KEY ) ] ,
44
- } ) ;
42
+ await addSigToAllCreds ( tx , utils . hexToBuffer ( PRIVATE_KEY ) ) ;
45
43
46
44
return pvmApi . issueSignedTx ( tx . getSignedTx ( ) ) ;
47
45
} ;
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