@exodus/solana-lib 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/tx/prepare-for-signing.js +14 -1
- package/src/tx/sign-unsigned-tx.js +17 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"@solana/web3.js": "^1.90.0",
|
|
41
41
|
"bip39": "^2.6.0"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "b6fa8852ada6a3b2de7d2a8c6f0f74c3c6aac7e7"
|
|
44
44
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isNumberUnit } from '@exodus/currency'
|
|
2
2
|
import BN from 'bn.js'
|
|
3
|
+
import { VersionedTransaction } from '@exodus/solana-web3.js'
|
|
3
4
|
|
|
4
5
|
import { ComputeBudgetProgram, PublicKey } from '../vendor'
|
|
5
6
|
import Transaction from '../transaction'
|
|
@@ -25,7 +26,19 @@ const addComputeBudgetToTransaction = ({ transaction, computeUnits }) => {
|
|
|
25
26
|
* @returns a Solana Web3.js Transaction object
|
|
26
27
|
*/
|
|
27
28
|
export function prepareForSigning(unsignedTx) {
|
|
28
|
-
const {
|
|
29
|
+
const {
|
|
30
|
+
amount: unitAmount,
|
|
31
|
+
fee: feeAmount,
|
|
32
|
+
from,
|
|
33
|
+
method,
|
|
34
|
+
transaction,
|
|
35
|
+
transactionBuffer,
|
|
36
|
+
} = unsignedTx.txData
|
|
37
|
+
|
|
38
|
+
// Recreate a Web3.js Transaction instance if the buffer provided.
|
|
39
|
+
if (transactionBuffer) {
|
|
40
|
+
return VersionedTransaction.deserialize(transactionBuffer)
|
|
41
|
+
}
|
|
29
42
|
|
|
30
43
|
if (!transaction) {
|
|
31
44
|
// Create a transaction in web3.js format
|
|
@@ -38,6 +38,21 @@ export async function signUnsignedTx(unsignedTx, privateKey) {
|
|
|
38
38
|
return extractTransaction({ tx })
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// Some transactions that we construct internally are technically not complete.
|
|
42
|
+
// They don't contain the empty signature slot for the public key.
|
|
43
|
+
export const fillTransactionWithEmptySignatureSlot = ({ transaction, publicKey }) => {
|
|
44
|
+
const foundEmptySignatureSlot = transaction.signatures.find(({ publicKey: _publicKey }) =>
|
|
45
|
+
_publicKey.equals(publicKey)
|
|
46
|
+
)
|
|
47
|
+
if (!foundEmptySignatureSlot) {
|
|
48
|
+
// We could use `setSigners` but maybe this is more robust?
|
|
49
|
+
transaction.signatures.push({
|
|
50
|
+
publicKey,
|
|
51
|
+
signature: null,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
41
56
|
// Signs plain tx.
|
|
42
57
|
const _signTx = async ({ tx, signer }) => {
|
|
43
58
|
const publicKey = new PublicKey(bs58.encode(Buffer.from(await signer.getPublicKey())))
|
|
@@ -46,20 +61,9 @@ const _signTx = async ({ tx, signer }) => {
|
|
|
46
61
|
// VersionedTransaction
|
|
47
62
|
return _signVersionedTransaction({ tx, signer, publicKey })
|
|
48
63
|
}
|
|
49
|
-
// Legacy Transactions
|
|
50
64
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
const foundEmptySignatureSlot = tx.signatures.find(({ publicKey: _publicKey }) =>
|
|
54
|
-
_publicKey.equals(publicKey)
|
|
55
|
-
)
|
|
56
|
-
if (!foundEmptySignatureSlot) {
|
|
57
|
-
// We could use `setSigners` but maybe this is more robust?
|
|
58
|
-
tx.signatures.push({
|
|
59
|
-
publicKey,
|
|
60
|
-
signature: null,
|
|
61
|
-
})
|
|
62
|
-
}
|
|
65
|
+
// Legacy Transactions
|
|
66
|
+
fillTransactionWithEmptySignatureSlot({ transaction: tx, publicKey })
|
|
63
67
|
|
|
64
68
|
return _signLegacyTransaction({ tx, signer, publicKey })
|
|
65
69
|
}
|