@exodus/solana-lib 2.2.0 → 2.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 +3 -2
- package/src/fee-data/index.js +2 -0
- package/src/index.js +1 -0
- package/src/msg/index.js +2 -0
- package/src/msg/sign-message-deprecated.js +20 -0
- package/src/msg/sign-message.js +19 -0
- package/src/{tx/sign-message.js → msg/validation.js} +16 -17
- package/src/tx/common.js +4 -0
- package/src/tx/index.js +2 -1
- package/src/tx/prepare-for-signing.js +12 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@exodus/currency": "^2.3.2",
|
|
24
24
|
"@exodus/key-utils": "^3.1.0",
|
|
25
25
|
"@exodus/models": "^10.1.0",
|
|
26
|
+
"@exodus/solana-web3.js": "^1.63.1-exodus.3",
|
|
26
27
|
"@project-serum/serum": "0.13.64",
|
|
27
28
|
"bn.js": "^4.11.0",
|
|
28
29
|
"borsh": "^0.7.0",
|
|
@@ -39,5 +40,5 @@
|
|
|
39
40
|
"@solana/web3.js": "^1.90.0",
|
|
40
41
|
"bip39": "^2.6.0"
|
|
41
42
|
},
|
|
42
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "02a052ff417b0c4d0379edf866b6a984ca6a4830"
|
|
43
44
|
}
|
package/src/fee-data/index.js
CHANGED
package/src/index.js
CHANGED
package/src/msg/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import nacl from 'tweetnacl'
|
|
3
|
+
import bs58 from 'bs58'
|
|
4
|
+
|
|
5
|
+
import { isTransactionMessage } from './validation'
|
|
6
|
+
import { getKeyPairFromPrivateKey } from '../keypair'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated please use messageSigner
|
|
10
|
+
*/
|
|
11
|
+
export function signMessage({ message, privateKey }) {
|
|
12
|
+
const { secretKey } = getKeyPairFromPrivateKey(privateKey)
|
|
13
|
+
const messageBuffer = bs58.decode(message)
|
|
14
|
+
assert(
|
|
15
|
+
!isTransactionMessage(messageBuffer),
|
|
16
|
+
'attempted to sign transaction using message signing'
|
|
17
|
+
)
|
|
18
|
+
const signature = nacl.sign.detached(messageBuffer, secretKey)
|
|
19
|
+
return bs58.encode(signature)
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert'
|
|
2
|
+
import * as nacl from 'tweetnacl'
|
|
3
|
+
|
|
4
|
+
import { isTransactionMessage } from './validation'
|
|
5
|
+
|
|
6
|
+
export const signMessageNew = async ({ privateKey, message }) => {
|
|
7
|
+
const { rawMessage } = message
|
|
8
|
+
assert(Buffer.isBuffer(rawMessage), `rawMessage must be buffer`)
|
|
9
|
+
assert(
|
|
10
|
+
!isTransactionMessage(rawMessage),
|
|
11
|
+
`malicious message signing request, was a transaction message`
|
|
12
|
+
)
|
|
13
|
+
assert(
|
|
14
|
+
Buffer.isBuffer(privateKey) || privateKey instanceof Uint8Array,
|
|
15
|
+
`privateKey is not a Buffer or Uint8Array`
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
return Buffer.from(nacl.sign.detached(rawMessage, privateKey))
|
|
19
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import nacl from 'tweetnacl'
|
|
3
|
-
import bs58 from 'bs58'
|
|
4
|
-
|
|
5
|
-
import { Message } from '../vendor/message'
|
|
6
|
-
import { getKeyPairFromPrivateKey } from '../keypair'
|
|
1
|
+
import { Message } from '@exodus/solana-web3.js'
|
|
7
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Checks if its contains a legacy message.
|
|
5
|
+
* @param {Uint8Array} data
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
8
8
|
function isLegacyMessage(data) {
|
|
9
9
|
try {
|
|
10
10
|
const message = Message.from(data)
|
|
@@ -15,6 +15,11 @@ function isLegacyMessage(data) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Checks if its contains a versioned message.
|
|
20
|
+
* @param {Uint8Array} data
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
18
23
|
function isVersionedMessage(data) {
|
|
19
24
|
if (data.length > 1) {
|
|
20
25
|
// We deploy a heuristic to detect transaction messages.
|
|
@@ -27,18 +32,12 @@ function isVersionedMessage(data) {
|
|
|
27
32
|
return false
|
|
28
33
|
}
|
|
29
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Check whether a message contains a transaction message.
|
|
37
|
+
* @param {Uint8Array} data
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
30
40
|
export function isTransactionMessage(data) {
|
|
31
41
|
const messageBuffer = Buffer.from(data)
|
|
32
42
|
return isLegacyMessage(messageBuffer) || isVersionedMessage(messageBuffer)
|
|
33
43
|
}
|
|
34
|
-
|
|
35
|
-
export default function signMessage({ message, privateKey }) {
|
|
36
|
-
const { secretKey } = getKeyPairFromPrivateKey(privateKey)
|
|
37
|
-
const messageBuffer = bs58.decode(message)
|
|
38
|
-
assert(
|
|
39
|
-
!isTransactionMessage(messageBuffer),
|
|
40
|
-
'attempted to sign transaction using message signing'
|
|
41
|
-
)
|
|
42
|
-
const signature = nacl.sign.detached(messageBuffer, secretKey)
|
|
43
|
-
return bs58.encode(signature)
|
|
44
|
-
}
|
package/src/tx/common.js
CHANGED
|
@@ -8,6 +8,10 @@ export function isLegacyTransaction(tx) {
|
|
|
8
8
|
return !isVersionedTransaction(tx)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export function transactionToBase58(tx) {
|
|
12
|
+
return base58.encode(tx.serialize())
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
export function getTxId(tx) {
|
|
12
16
|
const signature = getFirstSignature(tx)
|
|
13
17
|
if (signature === null) {
|
package/src/tx/index.js
CHANGED
|
@@ -6,4 +6,5 @@ export * from './simulate-and-sign-tx'
|
|
|
6
6
|
export * from './decode-tx-instructions'
|
|
7
7
|
export * from './build-raw-transaction'
|
|
8
8
|
export * from './sign-hardware'
|
|
9
|
-
export
|
|
9
|
+
export * from './prepare-for-signing'
|
|
10
|
+
export { transactionToBase58 } from './common'
|
|
@@ -5,17 +5,11 @@ import { ComputeBudgetProgram, PublicKey } from '../vendor'
|
|
|
5
5
|
import Transaction from '../transaction'
|
|
6
6
|
import { createMetaplexTransferTransaction } from '../helpers/metaplex-transfer'
|
|
7
7
|
|
|
8
|
-
const addPriorityFeeToTransaction = ({ transaction,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
|
|
15
|
-
microLamports: ratio || 100,
|
|
16
|
-
}) // 1 microLamport = 0.000001 lamports
|
|
17
|
-
transaction.add(priorityFeeInstruction)
|
|
18
|
-
}
|
|
8
|
+
const addPriorityFeeToTransaction = ({ transaction, priorityFee }) => {
|
|
9
|
+
const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
|
|
10
|
+
microLamports: priorityFee,
|
|
11
|
+
}) // 1 microLamport = 0.000001 lamports
|
|
12
|
+
transaction.add(priorityFeeInstruction)
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
/**
|
|
@@ -24,14 +18,7 @@ const addPriorityFeeToTransaction = ({ transaction, feeAmount = 0, fixedFee = 0
|
|
|
24
18
|
* @returns a Solana Web3.js Transaction object
|
|
25
19
|
*/
|
|
26
20
|
export function prepareForSigning(unsignedTx) {
|
|
27
|
-
const {
|
|
28
|
-
amount: unitAmount,
|
|
29
|
-
fee: feeAmount,
|
|
30
|
-
fixedFee,
|
|
31
|
-
from,
|
|
32
|
-
method,
|
|
33
|
-
transaction,
|
|
34
|
-
} = unsignedTx.txData
|
|
21
|
+
const { amount: unitAmount, fee: feeAmount, from, method, transaction } = unsignedTx.txData
|
|
35
22
|
|
|
36
23
|
if (!transaction) {
|
|
37
24
|
// Create a transaction in web3.js format
|
|
@@ -49,7 +36,12 @@ export function prepareForSigning(unsignedTx) {
|
|
|
49
36
|
|
|
50
37
|
const transaction = createTx({ txData, method })
|
|
51
38
|
|
|
52
|
-
|
|
39
|
+
if (txData.priorityFee) {
|
|
40
|
+
addPriorityFeeToTransaction({
|
|
41
|
+
transaction,
|
|
42
|
+
priorityFee: txData.priorityFee,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
53
45
|
|
|
54
46
|
if (!transaction.feePayer) {
|
|
55
47
|
transaction.feePayer = new PublicKey(from)
|