-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: removed redundant code * feat: added partially signing with for base64 * test: test * refactor: sign
- Loading branch information
1 parent
18a8eec
commit b9491e4
Showing
5 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"gill": minor | ||
--- | ||
|
||
added transactionToBase64WithSigners to sign and base64 encode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
import { pipe } from "@solana/functional"; | ||
import { CompilableTransactionMessage } from "@solana/transaction-messages"; | ||
import { partiallySignTransactionMessageWithSigners } from "@solana/signers"; | ||
import type { CompilableTransactionMessage } from "@solana/transaction-messages"; | ||
|
||
import { | ||
Transaction, | ||
type Transaction, | ||
compileTransaction, | ||
Base64EncodedWireTransaction, | ||
type Base64EncodedWireTransaction, | ||
getBase64EncodedWireTransaction, | ||
} from "@solana/transactions"; | ||
|
||
/** | ||
* Compile a Transaction to a base64 string | ||
* Compile a transaction to a base64 string | ||
* | ||
* Note: This will NOT attempt to sign the transaction, | ||
* so it will be missing `signatures` from any of the attached Signers | ||
* | ||
* Use {@link transactionToBase64WithSignatures} sign and base64 encode | ||
*/ | ||
export function transactionToBase64( | ||
tx: CompilableTransactionMessage | Transaction, | ||
): Base64EncodedWireTransaction { | ||
if ("messageBytes" in tx) { | ||
return pipe(tx, getBase64EncodedWireTransaction); | ||
} else { | ||
return pipe(tx, compileTransaction, getBase64EncodedWireTransaction); | ||
} | ||
if ("messageBytes" in tx) return pipe(tx, getBase64EncodedWireTransaction); | ||
else return pipe(tx, compileTransaction, getBase64EncodedWireTransaction); | ||
} | ||
|
||
/** | ||
* Compile a transaction to a base64 string and sign it with all attached Signers | ||
* | ||
* See also {@link partiallySignTransactionMessageWithSigners} | ||
*/ | ||
export async function transactionToBase64WithSigners( | ||
tx: CompilableTransactionMessage | Transaction, | ||
): Promise<Base64EncodedWireTransaction> { | ||
if ("messageBytes" in tx) return transactionToBase64(tx); | ||
else return transactionToBase64(await partiallySignTransactionMessageWithSigners(tx)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters