@exodus/solana-lib 1.6.8 → 1.6.10
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/sign-message.js +35 -1
- package/src/vendor/transaction.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-lib",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.10",
|
|
4
4
|
"description": "Exodus internal Solana low-level library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"lodash": "^4.17.11",
|
|
28
28
|
"tweetnacl": "^1.0.3"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "1210a44d1b6a8fc0375589f7e2439aa3fd0f6b01"
|
|
31
31
|
}
|
package/src/tx/sign-message.js
CHANGED
|
@@ -1,11 +1,45 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
1
2
|
import nacl from 'tweetnacl'
|
|
2
3
|
import bs58 from 'bs58'
|
|
3
4
|
|
|
5
|
+
import { Message } from '../vendor/message'
|
|
4
6
|
import { getKeyPairFromPrivateKey } from '../keypair'
|
|
5
7
|
|
|
8
|
+
function isLegacyMessage(data) {
|
|
9
|
+
try {
|
|
10
|
+
const message = Message.from(data)
|
|
11
|
+
message.serialize() // Invalid messages will throw on serialization.
|
|
12
|
+
return true
|
|
13
|
+
} catch (err) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isVersionedMessage(data) {
|
|
19
|
+
if (data.length > 1) {
|
|
20
|
+
// We deploy a heuristic to detect transaction messages.
|
|
21
|
+
// The first bytes of a transaction message contains its version number
|
|
22
|
+
// so we ban all bytes starting at 0x80 and ending at 0xFE
|
|
23
|
+
// 0xFF is allowed because that is used for offchain messages
|
|
24
|
+
return data[0] >= 0x80 && data[0] !== 0xff
|
|
25
|
+
} else {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isTransactionMessage(data) {
|
|
31
|
+
const messageBuffer = Buffer.from(data)
|
|
32
|
+
return isLegacyMessage(messageBuffer) || isVersionedMessage(messageBuffer)
|
|
33
|
+
}
|
|
34
|
+
|
|
6
35
|
export default function signMessage({ message, privateKey }) {
|
|
7
36
|
const { secretKey } = getKeyPairFromPrivateKey(privateKey)
|
|
8
|
-
const
|
|
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)
|
|
9
43
|
const bs58Signature = bs58.encode(signature)
|
|
10
44
|
return bs58Signature
|
|
11
45
|
}
|
|
@@ -76,7 +76,7 @@ export class TransactionInstruction {
|
|
|
76
76
|
*/
|
|
77
77
|
data = Buffer.alloc(0)
|
|
78
78
|
|
|
79
|
-
constructor(opts
|
|
79
|
+
constructor(opts) {
|
|
80
80
|
opts && Object.assign(this, opts)
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -156,7 +156,7 @@ export class Transaction {
|
|
|
156
156
|
/**
|
|
157
157
|
* Construct an empty Transaction
|
|
158
158
|
*/
|
|
159
|
-
constructor(opts
|
|
159
|
+
constructor(opts) {
|
|
160
160
|
opts && Object.assign(this, opts)
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
@@ -478,7 +478,7 @@ export class Transaction {
|
|
|
478
478
|
/**
|
|
479
479
|
* Serialize the Transaction in the wire format.
|
|
480
480
|
*/
|
|
481
|
-
serialize(config
|
|
481
|
+
serialize(config) {
|
|
482
482
|
const { requireAllSignatures, verifySignatures } = Object.assign(
|
|
483
483
|
{ requireAllSignatures: true, verifySignatures: true },
|
|
484
484
|
config
|