(user: User)
| 10 | // secretKey: Buffer.from(keypair.secretKey).toString('base64'), string |
| 11 | }; |
| 12 | } |
| 13 | |
| 14 | // reconstrucitng keypair from secret key as 1:1 mapping is maintained between secret key and keypair |
| 15 | export function createKeypairFromSecretKey(secretKey: Uint8Array) { |
| 16 | const keypair = Keypair.fromSecretKey(secretKey); |
| 17 | return { |
| 18 | publicKey: keypair.publicKey, |
| 19 | secretKey: keypair.secretKey |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | // creating a function to sign a transaction |
| 25 | |
| 26 | export function signTransaction(transaction: Transaction, secretKey: Uint8Array) { |
| 27 | // we need to reconstruct the keypair from the secret key to sign the transaction only public key won't work |
| 28 | const keypair = Keypair.fromSecretKey(secretKey); |
| 29 | transaction.sign(keypair); |
| 30 | return transaction; |
| 31 | } |
| 32 |
no test coverage detected