@exodus/solana-lib 1.2.8 → 1.2.9-build2
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/lib/constants.js +19 -0
- package/lib/encode.js +67 -0
- package/lib/fee-data/index.js +15 -0
- package/lib/fee-data/solana.js +14 -0
- package/lib/helpers/spl-token.js +122 -0
- package/lib/helpers/tokenTransfer.js +78 -0
- package/lib/index.js +88 -0
- package/lib/keypair.js +38 -0
- package/lib/tokens.js +21 -0
- package/lib/transaction.js +338 -0
- package/lib/tx/create-and-sign-tx.js +15 -0
- package/{src → lib}/tx/create-unsigned-tx.js +20 -11
- package/lib/tx/index.js +53 -0
- package/lib/tx/parse-unsigned-tx.js +55 -0
- package/lib/tx/sign-unsigned-tx.js +90 -0
- package/lib/vendor/account.js +48 -0
- package/lib/vendor/index.js +113 -0
- package/lib/vendor/instruction.js +48 -0
- package/lib/vendor/message.js +167 -0
- package/lib/vendor/nonce-account.js +56 -0
- package/lib/vendor/publickey.js +211 -0
- package/lib/vendor/stake-program.js +476 -0
- package/lib/vendor/system-program.js +640 -0
- package/lib/vendor/sysvar.js +19 -0
- package/lib/vendor/transaction.js +594 -0
- package/lib/vendor/utils/blockhash.js +1 -0
- package/lib/vendor/utils/fee-calculator.js +25 -0
- package/lib/vendor/utils/layout.js +97 -0
- package/lib/vendor/utils/shortvec-encoding.js +41 -0
- package/lib/vendor/utils/to-buffer.js +18 -0
- package/package.json +4 -5
- package/src/constants.js +0 -12
- package/src/encode.js +0 -57
- package/src/fee-data/index.js +0 -1
- package/src/fee-data/solana.js +0 -9
- package/src/helpers/spl-token.js +0 -108
- package/src/helpers/tokenTransfer.js +0 -72
- package/src/index.js +0 -8
- package/src/keypair.js +0 -32
- package/src/tokens.js +0 -19
- package/src/transaction.js +0 -240
- package/src/tx/create-and-sign-tx.js +0 -8
- package/src/tx/index.js +0 -4
- package/src/tx/parse-unsigned-tx.js +0 -39
- package/src/tx/sign-unsigned-tx.js +0 -78
- package/src/vendor/account.js +0 -38
- package/src/vendor/index.js +0 -9
- package/src/vendor/instruction.js +0 -46
- package/src/vendor/message.js +0 -216
- package/src/vendor/nonce-account.js +0 -46
- package/src/vendor/publickey.js +0 -212
- package/src/vendor/stake-program.js +0 -527
- package/src/vendor/system-program.js +0 -782
- package/src/vendor/sysvar.js +0 -16
- package/src/vendor/transaction.js +0 -594
- package/src/vendor/utils/blockhash.js +0 -6
- package/src/vendor/utils/fee-calculator.js +0 -17
- package/src/vendor/utils/layout.js +0 -80
- package/src/vendor/utils/shortvec-encoding.js +0 -30
- package/src/vendor/utils/to-buffer.js +0 -9
package/lib/constants.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SEED = exports.TOKEN_PROGRAM_ID = exports.STAKE_PROGRAM_ID = exports.SYSTEM_PROGRAM_ID = exports.SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = void 0;
|
|
7
|
+
|
|
8
|
+
var _vendor = require("./vendor");
|
|
9
|
+
|
|
10
|
+
const SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = new _vendor.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
11
|
+
exports.SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID;
|
|
12
|
+
const SYSTEM_PROGRAM_ID = _vendor.SystemProgram.programId;
|
|
13
|
+
exports.SYSTEM_PROGRAM_ID = SYSTEM_PROGRAM_ID;
|
|
14
|
+
const STAKE_PROGRAM_ID = _vendor.StakeProgram.programId;
|
|
15
|
+
exports.STAKE_PROGRAM_ID = STAKE_PROGRAM_ID;
|
|
16
|
+
const TOKEN_PROGRAM_ID = new _vendor.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
|
|
17
|
+
exports.TOKEN_PROGRAM_ID = TOKEN_PROGRAM_ID;
|
|
18
|
+
const SEED = 'stake:0';
|
|
19
|
+
exports.SEED = SEED;
|
package/lib/encode.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
7
|
+
exports.getAddressFromPrivateKey = getAddressFromPrivateKey;
|
|
8
|
+
exports.isValidAddress = isValidAddress;
|
|
9
|
+
exports.findAssociatedTokenAddress = findAssociatedTokenAddress;
|
|
10
|
+
exports.createStakeAddress = createStakeAddress;
|
|
11
|
+
|
|
12
|
+
var _vendor = require("./vendor");
|
|
13
|
+
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
|
|
16
|
+
var _keypair = require("./keypair");
|
|
17
|
+
|
|
18
|
+
var _bs = _interopRequireDefault(require("bs58"));
|
|
19
|
+
|
|
20
|
+
var _bn2 = _interopRequireDefault(require("bn.js"));
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
function getAddressFromPublicKey(publicKey) {
|
|
25
|
+
return _bs.default.encode(Buffer.from(publicKey, 'hex'));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getAddressFromPrivateKey(privateKey) {
|
|
29
|
+
return getAddressFromPublicKey((0, _keypair.getPublicKey)(privateKey));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isValidAddress(address) {
|
|
33
|
+
try {
|
|
34
|
+
// assume base 58 encoding by default
|
|
35
|
+
const decoded = _bs.default.decode(address);
|
|
36
|
+
|
|
37
|
+
if (decoded.length !== 32) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const _bn = new _bn2.default(decoded);
|
|
42
|
+
|
|
43
|
+
if (_bn.byteLength() > 32) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return true;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
} // doc: https://spl.solana.com/associated-token-account (HACK: refactored to sync)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
|
|
55
|
+
walletAddress = new _vendor.PublicKey(walletAddress);
|
|
56
|
+
tokenMintAddress = new _vendor.PublicKey(tokenMintAddress);
|
|
57
|
+
return _vendor.PublicKey.findProgramAddress([walletAddress.toBuffer(), _constants.TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()], _constants.SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID)[0].toBase58(); // returns encoded PublicKey
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function createStakeAddress(walletAddress, seed = _constants.SEED) {
|
|
61
|
+
const fromPubkey = new _vendor.PublicKey(walletAddress);
|
|
62
|
+
|
|
63
|
+
const newAccountPubkey = _vendor.PublicKey.createWithSeed( // HACK: refactored to sync
|
|
64
|
+
fromPubkey, seed, _vendor.StakeProgram.programId);
|
|
65
|
+
|
|
66
|
+
return newAccountPubkey.toBase58();
|
|
67
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "solana", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _solana.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _solana = _interopRequireDefault(require("./solana"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _assetLib = require("@exodus/asset-lib");
|
|
9
|
+
|
|
10
|
+
var _default = new _assetLib.FeeData({
|
|
11
|
+
fee: '0.000005 SOL'
|
|
12
|
+
}, 'fee', 'solana');
|
|
13
|
+
|
|
14
|
+
exports.default = _default;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Token = exports.U64 = void 0;
|
|
7
|
+
|
|
8
|
+
var _assert = _interopRequireDefault(require("assert"));
|
|
9
|
+
|
|
10
|
+
var _bn = _interopRequireDefault(require("bn.js"));
|
|
11
|
+
|
|
12
|
+
var BufferLayout = _interopRequireWildcard(require("@exodus/buffer-layout"));
|
|
13
|
+
|
|
14
|
+
var _vendor = require("../vendor");
|
|
15
|
+
|
|
16
|
+
var Layout = _interopRequireWildcard(require("../vendor/utils/layout"));
|
|
17
|
+
|
|
18
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
// Extracted from https://github.com/ExodusMovement/solana-spl-token/blob/master/src/index.js#L263
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 64-bit value
|
|
28
|
+
*/
|
|
29
|
+
class U64 extends _bn.default {
|
|
30
|
+
/**
|
|
31
|
+
* Convert to Buffer representation
|
|
32
|
+
*/
|
|
33
|
+
toBuffer() {
|
|
34
|
+
const a = super.toArray().reverse();
|
|
35
|
+
const b = Buffer.from(a);
|
|
36
|
+
|
|
37
|
+
if (b.length === 8) {
|
|
38
|
+
return b;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
(0, _assert.default)(b.length < 8, 'u64 too large');
|
|
42
|
+
const zeroPad = Buffer.alloc(8);
|
|
43
|
+
b.copy(zeroPad);
|
|
44
|
+
return zeroPad;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Construct a u64 from Buffer representation
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
static fromBuffer(buffer) {
|
|
52
|
+
(0, _assert.default)(buffer.length === 8, `Invalid buffer length: ${buffer.length}`);
|
|
53
|
+
return new U64([...buffer].reverse().map(i => `00${i.toString(16)}`.slice(-2)).join(''), 16);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.U64 = U64;
|
|
59
|
+
const u64 = U64; // alias
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* An ERC20-like Token
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
class Token {
|
|
66
|
+
/**
|
|
67
|
+
* Construct a Transfer instruction
|
|
68
|
+
*
|
|
69
|
+
* @param programId SPL Token program account
|
|
70
|
+
* @param source Source account
|
|
71
|
+
* @param destination Destination account
|
|
72
|
+
* @param owner Owner of the source account
|
|
73
|
+
* @param multiSigners Signing accounts if `authority` is a multiSig
|
|
74
|
+
* @param amount Number of tokens to transfer
|
|
75
|
+
*/
|
|
76
|
+
static createTransferInstruction(programId, source, destination, owner, multiSigners, amount) {
|
|
77
|
+
const dataLayout = BufferLayout.struct([BufferLayout.u8('instruction'), Layout.uint64('amount')]);
|
|
78
|
+
const data = Buffer.alloc(dataLayout.span);
|
|
79
|
+
dataLayout.encode({
|
|
80
|
+
instruction: 3,
|
|
81
|
+
// Transfer instruction
|
|
82
|
+
amount: new U64(amount).toBuffer()
|
|
83
|
+
}, data);
|
|
84
|
+
let keys = [{
|
|
85
|
+
pubkey: source,
|
|
86
|
+
isSigner: false,
|
|
87
|
+
isWritable: true
|
|
88
|
+
}, {
|
|
89
|
+
pubkey: destination,
|
|
90
|
+
isSigner: false,
|
|
91
|
+
isWritable: true
|
|
92
|
+
}];
|
|
93
|
+
|
|
94
|
+
if (multiSigners.length === 0) {
|
|
95
|
+
keys.push({
|
|
96
|
+
pubkey: owner,
|
|
97
|
+
isSigner: true,
|
|
98
|
+
isWritable: false
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
keys.push({
|
|
102
|
+
pubkey: owner,
|
|
103
|
+
isSigner: false,
|
|
104
|
+
isWritable: false
|
|
105
|
+
});
|
|
106
|
+
multiSigners.forEach(signer => keys.push({
|
|
107
|
+
pubkey: signer.publicKey,
|
|
108
|
+
isSigner: true,
|
|
109
|
+
isWritable: false
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return new _vendor.TransactionInstruction({
|
|
114
|
+
keys,
|
|
115
|
+
programId: programId,
|
|
116
|
+
data
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
exports.Token = Token;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTokenTransferInstruction = exports.createAssociatedTokenAccount = void 0;
|
|
7
|
+
|
|
8
|
+
var _splToken = require("./spl-token");
|
|
9
|
+
|
|
10
|
+
var _vendor = require("../vendor");
|
|
11
|
+
|
|
12
|
+
var _constants = require("../constants");
|
|
13
|
+
|
|
14
|
+
var _encode = require("../encode");
|
|
15
|
+
|
|
16
|
+
const createAssociatedTokenAccount = (senderAddress, tokenMintAddress, ownerAddress) => // destination SOL address
|
|
17
|
+
{
|
|
18
|
+
const associatedTokenAccountPublicKey = new _vendor.PublicKey((0, _encode.findAssociatedTokenAddress)(ownerAddress, tokenMintAddress));
|
|
19
|
+
const feePayerPublicKey = new _vendor.PublicKey(senderAddress);
|
|
20
|
+
const ownerPublicKey = new _vendor.PublicKey(ownerAddress);
|
|
21
|
+
const tokenMintPublicKey = new _vendor.PublicKey(tokenMintAddress);
|
|
22
|
+
const ix = createIx(feePayerPublicKey, // feePayer
|
|
23
|
+
associatedTokenAccountPublicKey, ownerPublicKey, tokenMintPublicKey);
|
|
24
|
+
return ix; // returns the instruction
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.createAssociatedTokenAccount = createAssociatedTokenAccount;
|
|
28
|
+
|
|
29
|
+
function createIx(funderPubkey, associatedTokenAccountPublicKey, ownerPublicKey, tokenMintPublicKey) {
|
|
30
|
+
return new _vendor.TransactionInstruction({
|
|
31
|
+
programId: _constants.SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
|
|
32
|
+
data: Buffer.from([]),
|
|
33
|
+
keys: [{
|
|
34
|
+
pubkey: funderPubkey,
|
|
35
|
+
isSigner: true,
|
|
36
|
+
isWritable: true
|
|
37
|
+
}, {
|
|
38
|
+
pubkey: associatedTokenAccountPublicKey,
|
|
39
|
+
isSigner: false,
|
|
40
|
+
isWritable: true
|
|
41
|
+
}, {
|
|
42
|
+
pubkey: ownerPublicKey,
|
|
43
|
+
isSigner: false,
|
|
44
|
+
isWritable: false
|
|
45
|
+
}, {
|
|
46
|
+
pubkey: tokenMintPublicKey,
|
|
47
|
+
isSigner: false,
|
|
48
|
+
isWritable: false
|
|
49
|
+
}, {
|
|
50
|
+
pubkey: _vendor.SystemProgram.programId,
|
|
51
|
+
isSigner: false,
|
|
52
|
+
isWritable: false
|
|
53
|
+
}, {
|
|
54
|
+
pubkey: _constants.TOKEN_PROGRAM_ID,
|
|
55
|
+
isSigner: false,
|
|
56
|
+
isWritable: false
|
|
57
|
+
}, {
|
|
58
|
+
pubkey: _vendor.SYSVAR_RENT_PUBKEY,
|
|
59
|
+
isSigner: false,
|
|
60
|
+
isWritable: false
|
|
61
|
+
}]
|
|
62
|
+
});
|
|
63
|
+
} // https://github.com/paul-schaaf/spl-token-ui/blob/main/src/solana/token/editing.ts#L211
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
const createTokenTransferInstruction = (owner, fromTokenAddress, to, amount) => {
|
|
67
|
+
const sourcePubkey = new _vendor.PublicKey(fromTokenAddress); // the token ADDRESS needed!
|
|
68
|
+
|
|
69
|
+
const destinationPubkey = new _vendor.PublicKey(to);
|
|
70
|
+
console.log(`destination token address: ${destinationPubkey.toBase58()}`);
|
|
71
|
+
const ownerAccountOrWalletPublicKey = new _vendor.PublicKey(owner); // the only native SOL address
|
|
72
|
+
|
|
73
|
+
const transferIx = _splToken.Token.createTransferInstruction(_constants.TOKEN_PROGRAM_ID, sourcePubkey, destinationPubkey, ownerAccountOrWalletPublicKey, [], amount);
|
|
74
|
+
|
|
75
|
+
return transferIx;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.createTokenTransferInstruction = createTokenTransferInstruction;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
StakeInstruction: true,
|
|
8
|
+
tokens: true,
|
|
9
|
+
Transaction: true
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "StakeInstruction", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return _vendor.StakeInstruction;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "tokens", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return _tokens.default;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "Transaction", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return _transaction.default;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
var _constants = require("./constants");
|
|
31
|
+
|
|
32
|
+
Object.keys(_constants).forEach(function (key) {
|
|
33
|
+
if (key === "default" || key === "__esModule") return;
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
35
|
+
Object.defineProperty(exports, key, {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () {
|
|
38
|
+
return _constants[key];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
var _encode = require("./encode");
|
|
44
|
+
|
|
45
|
+
Object.keys(_encode).forEach(function (key) {
|
|
46
|
+
if (key === "default" || key === "__esModule") return;
|
|
47
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
48
|
+
Object.defineProperty(exports, key, {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _encode[key];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
var _keypair = require("./keypair");
|
|
57
|
+
|
|
58
|
+
Object.keys(_keypair).forEach(function (key) {
|
|
59
|
+
if (key === "default" || key === "__esModule") return;
|
|
60
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
61
|
+
Object.defineProperty(exports, key, {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _keypair[key];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
var _tx = require("./tx");
|
|
70
|
+
|
|
71
|
+
Object.keys(_tx).forEach(function (key) {
|
|
72
|
+
if (key === "default" || key === "__esModule") return;
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
74
|
+
Object.defineProperty(exports, key, {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function () {
|
|
77
|
+
return _tx[key];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
var _vendor = require("./vendor");
|
|
83
|
+
|
|
84
|
+
var _tokens = _interopRequireDefault(require("./tokens"));
|
|
85
|
+
|
|
86
|
+
var _transaction = _interopRequireDefault(require("./transaction"));
|
|
87
|
+
|
|
88
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/keypair.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getKeyPairFromPrivateKey = getKeyPairFromPrivateKey;
|
|
7
|
+
exports.getPublicKey = getPublicKey;
|
|
8
|
+
exports.sign = sign;
|
|
9
|
+
exports.verifySignature = verifySignature;
|
|
10
|
+
|
|
11
|
+
var _tweetnacl = _interopRequireDefault(require("tweetnacl"));
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
function getKeyPairFromPrivateKey(privateKey) {
|
|
16
|
+
const {
|
|
17
|
+
publicKey,
|
|
18
|
+
secretKey
|
|
19
|
+
} = _tweetnacl.default.sign.keyPair.fromSeed(Buffer.from(privateKey, 'hex').slice(0, 32));
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
secretKey: Buffer.from(secretKey, 'hex'),
|
|
23
|
+
// secretKey
|
|
24
|
+
publicKey: Buffer.from(publicKey, 'hex')
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getPublicKey(privateKey) {
|
|
29
|
+
return getKeyPairFromPrivateKey(privateKey).publicKey;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sign(data, privateKey) {
|
|
33
|
+
return Buffer.from(_tweetnacl.default.sign.detached(data, getKeyPairFromPrivateKey(Buffer.from(privateKey, 'hex')).secretKey), 'hex');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function verifySignature(data, signature, publicKey) {
|
|
37
|
+
return _tweetnacl.default.sign.detached.verify(data, signature, Buffer.from(publicKey, 'hex'));
|
|
38
|
+
}
|
package/lib/tokens.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
// adapted from https://github.com/project-serum/spl-token-wallet/blob/master/src/utils/tokens/names.js
|
|
8
|
+
const TOKENS = [{
|
|
9
|
+
mintAddress: 'SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt',
|
|
10
|
+
tokenName: 'serum',
|
|
11
|
+
tokenProperName: 'Serum',
|
|
12
|
+
tokenSymbol: 'SRM'
|
|
13
|
+
}, {
|
|
14
|
+
mintAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
15
|
+
tokenName: 'usdcoin_solana',
|
|
16
|
+
tokenProperName: 'USD Coin Solana',
|
|
17
|
+
tokenSymbol: 'USDCSOL'
|
|
18
|
+
} // ....
|
|
19
|
+
];
|
|
20
|
+
var _default = TOKENS;
|
|
21
|
+
exports.default = _default;
|