@exodus/solana-lib 1.2.13 → 1.2.14

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.
Files changed (60) hide show
  1. package/lib/constants.js +19 -0
  2. package/lib/encode.js +67 -0
  3. package/lib/fee-data/index.js +15 -0
  4. package/lib/fee-data/solana.js +14 -0
  5. package/lib/helpers/spl-token.js +122 -0
  6. package/lib/helpers/tokenTransfer.js +78 -0
  7. package/lib/index.js +88 -0
  8. package/lib/keypair.js +38 -0
  9. package/lib/tokens.js +21 -0
  10. package/lib/transaction.js +338 -0
  11. package/lib/tx/create-and-sign-tx.js +15 -0
  12. package/{src → lib}/tx/create-unsigned-tx.js +18 -11
  13. package/lib/tx/index.js +53 -0
  14. package/lib/tx/parse-unsigned-tx.js +55 -0
  15. package/lib/tx/sign-unsigned-tx.js +90 -0
  16. package/lib/vendor/account.js +48 -0
  17. package/lib/vendor/index.js +113 -0
  18. package/lib/vendor/instruction.js +48 -0
  19. package/lib/vendor/message.js +167 -0
  20. package/lib/vendor/nonce-account.js +56 -0
  21. package/lib/vendor/publickey.js +211 -0
  22. package/lib/vendor/stake-program.js +476 -0
  23. package/lib/vendor/system-program.js +640 -0
  24. package/lib/vendor/sysvar.js +19 -0
  25. package/lib/vendor/transaction.js +594 -0
  26. package/lib/vendor/utils/blockhash.js +1 -0
  27. package/lib/vendor/utils/fee-calculator.js +25 -0
  28. package/lib/vendor/utils/layout.js +97 -0
  29. package/lib/vendor/utils/shortvec-encoding.js +41 -0
  30. package/lib/vendor/utils/to-buffer.js +18 -0
  31. package/package.json +4 -5
  32. package/src/constants.js +0 -12
  33. package/src/encode.js +0 -57
  34. package/src/fee-data/index.js +0 -1
  35. package/src/fee-data/solana.js +0 -9
  36. package/src/helpers/spl-token.js +0 -108
  37. package/src/helpers/tokenTransfer.js +0 -72
  38. package/src/index.js +0 -9
  39. package/src/keypair.js +0 -32
  40. package/src/tokens.js +0 -19
  41. package/src/transaction.js +0 -292
  42. package/src/tx/create-and-sign-tx.js +0 -8
  43. package/src/tx/index.js +0 -4
  44. package/src/tx/parse-unsigned-tx.js +0 -41
  45. package/src/tx/sign-unsigned-tx.js +0 -78
  46. package/src/vendor/account.js +0 -38
  47. package/src/vendor/index.js +0 -9
  48. package/src/vendor/instruction.js +0 -46
  49. package/src/vendor/message.js +0 -216
  50. package/src/vendor/nonce-account.js +0 -46
  51. package/src/vendor/publickey.js +0 -212
  52. package/src/vendor/stake-program.js +0 -527
  53. package/src/vendor/system-program.js +0 -782
  54. package/src/vendor/sysvar.js +0 -16
  55. package/src/vendor/transaction.js +0 -594
  56. package/src/vendor/utils/blockhash.js +0 -6
  57. package/src/vendor/utils/fee-calculator.js +0 -17
  58. package/src/vendor/utils/layout.js +0 -80
  59. package/src/vendor/utils/shortvec-encoding.js +0 -30
  60. package/src/vendor/utils/to-buffer.js +0 -9
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _assert = _interopRequireDefault(require("assert"));
9
+
10
+ var _bs = _interopRequireDefault(require("bs58"));
11
+
12
+ var _lodash = require("lodash");
13
+
14
+ var _keypair = require("./keypair");
15
+
16
+ var _encode = require("./encode");
17
+
18
+ var _tokenTransfer = require("./helpers/tokenTransfer");
19
+
20
+ var _vendor = require("./vendor");
21
+
22
+ var _constants = require("./constants");
23
+
24
+ var _tokens = _interopRequireDefault(require("./tokens"));
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ class Tx {
29
+ constructor({
30
+ from,
31
+ to,
32
+ amount,
33
+ recentBlockhash,
34
+ // fee, // (Fee per Signature: 5000 lamports)
35
+ // Tokens related:
36
+ tokenName,
37
+ destinationAddressType,
38
+ isAssociatedTokenAccountActive,
39
+ // true when recipient balance !== 0
40
+ fromTokenAddresses // sender token addresses
41
+
42
+ } = {}) {
43
+ (0, _assert.default)(from, 'from is required');
44
+ (0, _assert.default)(to, 'to is required');
45
+ (0, _assert.default)(amount, 'amount is required');
46
+ (0, _assert.default)(typeof amount === 'number', 'amount must be a number');
47
+ (0, _assert.default)(recentBlockhash, 'recentBlockhash is required');
48
+
49
+ if (tokenName) {
50
+ (0, _assert.default)(typeof destinationAddressType !== 'undefined', 'destinationAddressType is required when sending tokens');
51
+ (0, _assert.default)(typeof isAssociatedTokenAccountActive !== 'undefined', 'isAssociatedTokenAccountActive is required when sending tokens'); // needed to create the recipient account
52
+
53
+ (0, _assert.default)(Array.isArray(fromTokenAddresses), 'fromTokenAddresses Array is required');
54
+ }
55
+
56
+ const token = _tokens.default.find(({
57
+ tokenName: name
58
+ }) => name === tokenName);
59
+
60
+ this.txObj = {
61
+ from,
62
+ to,
63
+ amount,
64
+ recentBlockhash,
65
+ token,
66
+ destinationAddressType,
67
+ isAssociatedTokenAccountActive,
68
+ fromTokenAddresses
69
+ };
70
+
71
+ if (token) {
72
+ // TOKEN transfer tx
73
+ this.buildTokenTransaction(this.txObj);
74
+ } else {
75
+ // SOL tx
76
+ this.buildSOLtransaction(this.txObj);
77
+ }
78
+ }
79
+
80
+ buildSOLtransaction({
81
+ from,
82
+ to,
83
+ amount,
84
+ recentBlockhash
85
+ }) {
86
+ const txInstruction = _vendor.SystemProgram.transfer({
87
+ fromPubkey: new _vendor.PublicKey(from),
88
+ toPubkey: new _vendor.PublicKey(to),
89
+ lamports: amount
90
+ });
91
+
92
+ this.transaction = new _vendor.Transaction({
93
+ instructions: [txInstruction],
94
+ recentBlockhash
95
+ });
96
+ }
97
+
98
+ buildTokenTransaction({
99
+ from,
100
+ to,
101
+ amount,
102
+ recentBlockhash,
103
+ token,
104
+ destinationAddressType,
105
+ isAssociatedTokenAccountActive,
106
+ fromTokenAddresses
107
+ }) {
108
+ this.transaction = new _vendor.Transaction({
109
+ recentBlockhash
110
+ });
111
+ const isUnknown = destinationAddressType === null;
112
+ const isSOLaddress = destinationAddressType === 'solana'; // crete account instruction
113
+
114
+ if (isUnknown) throw new Error('Destination SOL balance cannot be zero (address not active)'); // cannot initialize without knowing the owner
115
+
116
+ if (isSOLaddress && !isAssociatedTokenAccountActive) this.transaction.add((0, _tokenTransfer.createAssociatedTokenAccount)(from, token.mintAddress, to));
117
+ let amountLeft = amount;
118
+ let amountToSend;
119
+
120
+ for (let {
121
+ ticker,
122
+ tokenAccountAddress,
123
+ balance
124
+ } of fromTokenAddresses) {
125
+ // need to add more of this instruction until we reach the desired balance (amount) to send
126
+ (0, _assert.default)(ticker === token.tokenSymbol, `Got unexpected ticker ${ticker}`);
127
+ if (amountLeft === 0) break;
128
+ balance = Number(balance);
129
+
130
+ if (balance >= amountLeft) {
131
+ amountToSend = amountLeft;
132
+ amountLeft = 0;
133
+ } else {
134
+ amountToSend = balance; // not enough balance
135
+
136
+ amountLeft -= amountToSend;
137
+ }
138
+
139
+ const dest = isSOLaddress ? (0, _encode.findAssociatedTokenAddress)(to, token.mintAddress) : to; // add transfer token instruction
140
+
141
+ this.transaction.add((0, _tokenTransfer.createTokenTransferInstruction)(from, tokenAccountAddress, dest, amountToSend));
142
+ }
143
+
144
+ (0, _assert.default)(amountLeft === 0, `Not enough balance to send ${amount} ${token.tokenSymbol}`);
145
+ }
146
+
147
+ static createStakeAccountTransaction({
148
+ address,
149
+ amount,
150
+ seed = _constants.SEED,
151
+ pool,
152
+ recentBlockhash
153
+ }) {
154
+ const fromPubkey = new _vendor.PublicKey(address);
155
+ const stakeAddress = (0, _encode.createStakeAddress)(address, seed);
156
+ const stakePublicKey = new _vendor.PublicKey(stakeAddress);
157
+ const poolKey = new _vendor.PublicKey(pool);
158
+ const authorized = new _vendor.Authorized(fromPubkey, fromPubkey); // staker, withdrawer
159
+
160
+ const lockup = new _vendor.Lockup(0, 0, fromPubkey); // no lockup
161
+ // create account instruction
162
+
163
+ const programTx = _vendor.StakeProgram.createAccountWithSeed({
164
+ fromPubkey,
165
+ stakePubkey: stakePublicKey,
166
+ basePubkey: fromPubkey,
167
+ seed,
168
+ authorized,
169
+ lockup,
170
+ lamports: amount // number
171
+
172
+ }); // delegate funds instruction
173
+
174
+
175
+ const delegateTx = _vendor.StakeProgram.delegate({
176
+ stakePubkey: stakePublicKey,
177
+ authorizedPubkey: fromPubkey,
178
+ votePubkey: poolKey // pool vote key
179
+
180
+ });
181
+
182
+ const transaction = new _vendor.Transaction({
183
+ recentBlockhash
184
+ }).add(programTx).add(delegateTx);
185
+ return transaction;
186
+ }
187
+
188
+ static undelegate({
189
+ address,
190
+ stakeAddresses,
191
+ recentBlockhash
192
+ }) {
193
+ // undelegate all stake addresses
194
+ (0, _assert.default)(Array.isArray(stakeAddresses), 'stakeAddresses Array is required');
195
+ const fromPubkey = new _vendor.PublicKey(address);
196
+ const transaction = new _vendor.Transaction({
197
+ recentBlockhash
198
+ });
199
+ stakeAddresses.forEach(stakeAddress => {
200
+ const stakePublicKey = new _vendor.PublicKey(stakeAddress);
201
+
202
+ const programTx = _vendor.StakeProgram.deactivate({
203
+ stakePubkey: stakePublicKey,
204
+ authorizedPubkey: fromPubkey
205
+ });
206
+
207
+ transaction.add(programTx);
208
+ });
209
+ return transaction;
210
+ }
211
+
212
+ static withdraw({
213
+ address,
214
+ stakeAddresses,
215
+ amount,
216
+ recentBlockhash
217
+ }) {
218
+ const fromPubkey = new _vendor.PublicKey(address);
219
+ const stakeAddress = Array.isArray(stakeAddresses) ? stakeAddresses[0] : stakeAddresses;
220
+ const stakePublicKey = new _vendor.PublicKey(stakeAddress);
221
+
222
+ const transaction = _vendor.StakeProgram.withdraw({
223
+ stakePubkey: stakePublicKey,
224
+ authorizedPubkey: fromPubkey,
225
+ toPubkey: fromPubkey,
226
+ lamports: amount
227
+ });
228
+
229
+ transaction.recentBlockhash = recentBlockhash;
230
+ return transaction;
231
+ }
232
+
233
+ static sign(tx, privateKey) {
234
+ if (!privateKey) throw new Error('Please provide a secretKey');
235
+ const {
236
+ secretKey
237
+ } = (0, _keypair.getKeyPairFromPrivateKey)(privateKey);
238
+ const signers = [new _vendor.Account(secretKey)];
239
+ let transaction = tx;
240
+ if (tx instanceof Tx) transaction = tx.transaction;
241
+ transaction.sign(...signers);
242
+
243
+ if (!transaction.signature) {
244
+ throw new Error('!signature'); // should never happen
245
+ }
246
+ }
247
+
248
+ serialize() {
249
+ const wireTransaction = this.transaction.serialize();
250
+ return wireTransaction.toString('base64');
251
+ }
252
+
253
+ static serialize(tx) {
254
+ let transaction = tx;
255
+ if (tx instanceof Tx) transaction = tx.transaction;
256
+ return transaction.serialize().toString('base64');
257
+ }
258
+
259
+ static decodeStakingTx(serialized) {
260
+ // as base64
261
+ const wireTransaction = Buffer.from(serialized, 'base64');
262
+
263
+ const tx = _vendor.Transaction.from(wireTransaction); // Transaction instance
264
+
265
+
266
+ const txId = _bs.default.encode(tx.signature);
267
+
268
+ const stakingInstructions = tx.instructions.filter(ix => ix.programId.toString() === _constants.STAKE_PROGRAM_ID.toString());
269
+ const isStakingTx = !!stakingInstructions.length;
270
+ if (!isStakingTx) return null; // normal transfer tx
271
+
272
+ const info = {
273
+ txId,
274
+ owner: tx.feePayer.toString() // SOL sender
275
+
276
+ };
277
+ const txDetails = stakingInstructions.reduce((info, ix) => {
278
+ const type = _vendor.StakeInstruction.decodeInstructionType(ix);
279
+
280
+ switch (type) {
281
+ case 'Delegate':
282
+ info.type = 'Delegate';
283
+ info.stakeAddress = (0, _lodash.get)(ix, 'keys[0].pubkey', '').toString();
284
+ info.validator = (0, _lodash.get)(ix, 'keys[1].pubkey', '').toString(); // pool
285
+
286
+ return info;
287
+
288
+ case 'Deactivate':
289
+ // undelegate
290
+ info.type = 'Deactivate';
291
+ info.stakeAddress = (0, _lodash.get)(ix, 'keys[0].pubkey', '').toString(); // TODO: could have multiple addresses undelegating
292
+
293
+ return info;
294
+
295
+ case 'Withdraw':
296
+ info.type = 'Withdraw';
297
+ info.stakeAddress = (0, _lodash.get)(ix, 'keys[0].pubkey', '').toString();
298
+
299
+ const {
300
+ lamports,
301
+ toPubkey
302
+ } = _vendor.StakeInstruction.decodeWithdraw(ix);
303
+
304
+ info.to = toPubkey.toString();
305
+ info.lamports = lamports.toString();
306
+ return info;
307
+
308
+ default:
309
+ // skip unknown instruction type
310
+ return info;
311
+ }
312
+ }, info);
313
+ return txDetails;
314
+ }
315
+
316
+ getTxId() {
317
+ if (!this.transaction.signature) {
318
+ throw new Error('Cannot get txId, tx is not signed');
319
+ }
320
+
321
+ return _bs.default.encode(this.transaction.signature);
322
+ }
323
+
324
+ static getTxId(tx) {
325
+ let transaction = tx;
326
+ if (tx instanceof Tx) transaction = tx.transaction;
327
+
328
+ if (!transaction.signature) {
329
+ throw new Error('Cannot get txId, tx is not signed');
330
+ }
331
+
332
+ return _bs.default.encode(transaction.signature);
333
+ }
334
+
335
+ }
336
+
337
+ var _default = Tx;
338
+ exports.default = _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createAndSignTx = createAndSignTx;
7
+
8
+ var _createUnsignedTx = require("./create-unsigned-tx");
9
+
10
+ var _signUnsignedTx = require("./sign-unsigned-tx");
11
+
12
+ function createAndSignTx(input, privateKey) {
13
+ const unsignedTx = (0, _createUnsignedTx.createUnsignedTx)(input);
14
+ return (0, _signUnsignedTx.signUnsignedTx)(unsignedTx, privateKey);
15
+ }
@@ -1,6 +1,11 @@
1
- import type { UnsignedTransaction, ParsedTransaction } from '@exodus/models/lib/types'
1
+ "use strict";
2
2
 
3
- export function createUnsignedTx({
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createUnsignedTx = createUnsignedTx;
7
+
8
+ function createUnsignedTx({
4
9
  asset,
5
10
  from,
6
11
  to,
@@ -10,14 +15,16 @@ export function createUnsignedTx({
10
15
  // Tokens related:
11
16
  tokenName,
12
17
  destinationAddressType,
13
- isAssociatedTokenAccountActive, // true when recipient balance !== 0
14
- fromTokenAddresses, // sender token addresses
18
+ isAssociatedTokenAccountActive,
19
+ // true when recipient balance !== 0
20
+ fromTokenAddresses,
21
+ // sender token addresses
15
22
  // Staking related:
16
23
  method,
17
24
  stakeAddresses,
18
25
  seed,
19
- pool,
20
- }: ParsedTransaction): UnsignedTransaction {
26
+ pool
27
+ }) {
21
28
  return {
22
29
  txData: {
23
30
  from,
@@ -34,10 +41,10 @@ export function createUnsignedTx({
34
41
  method,
35
42
  stakeAddresses,
36
43
  seed,
37
- pool,
44
+ pool
38
45
  },
39
46
  txMeta: {
40
- assetName: asset.name,
41
- },
42
- }
43
- }
47
+ assetName: asset.name
48
+ }
49
+ };
50
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _signUnsignedTx = require("./sign-unsigned-tx");
8
+
9
+ Object.keys(_signUnsignedTx).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ Object.defineProperty(exports, key, {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _signUnsignedTx[key];
15
+ }
16
+ });
17
+ });
18
+
19
+ var _parseUnsignedTx = require("./parse-unsigned-tx");
20
+
21
+ Object.keys(_parseUnsignedTx).forEach(function (key) {
22
+ if (key === "default" || key === "__esModule") return;
23
+ Object.defineProperty(exports, key, {
24
+ enumerable: true,
25
+ get: function () {
26
+ return _parseUnsignedTx[key];
27
+ }
28
+ });
29
+ });
30
+
31
+ var _createUnsignedTx = require("./create-unsigned-tx");
32
+
33
+ Object.keys(_createUnsignedTx).forEach(function (key) {
34
+ if (key === "default" || key === "__esModule") return;
35
+ Object.defineProperty(exports, key, {
36
+ enumerable: true,
37
+ get: function () {
38
+ return _createUnsignedTx[key];
39
+ }
40
+ });
41
+ });
42
+
43
+ var _createAndSignTx = require("./create-and-sign-tx");
44
+
45
+ Object.keys(_createAndSignTx).forEach(function (key) {
46
+ if (key === "default" || key === "__esModule") return;
47
+ Object.defineProperty(exports, key, {
48
+ enumerable: true,
49
+ get: function () {
50
+ return _createAndSignTx[key];
51
+ }
52
+ });
53
+ });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseUnsignedTx = parseUnsignedTx;
7
+
8
+ var _assets = _interopRequireDefault(require("@exodus/assets"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
13
+
14
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
+
16
+ function parseUnsignedTx(unsignedTx) {
17
+ const asset = _assets.default.solana;
18
+
19
+ const _unsignedTx$txData = unsignedTx.txData,
20
+ {
21
+ from,
22
+ to,
23
+ recentBlockhash,
24
+ tokenName,
25
+ destinationAddressType,
26
+ isAssociatedTokenAccountActive,
27
+ fromTokenAddresses,
28
+ method,
29
+ stakeAddresses,
30
+ seed,
31
+ pool
32
+ } = _unsignedTx$txData,
33
+ txData = _objectWithoutProperties(_unsignedTx$txData, ["from", "to", "recentBlockhash", "tokenName", "destinationAddressType", "isAssociatedTokenAccountActive", "fromTokenAddresses", "method", "stakeAddresses", "seed", "pool"]);
34
+
35
+ const amount = asset.currency.baseUnit(txData.amount);
36
+ const fee = asset.currency.baseUnit(txData.fee);
37
+ return {
38
+ asset,
39
+ from: [from],
40
+ to,
41
+ amount,
42
+ fee,
43
+ recentBlockhash,
44
+ // token related
45
+ tokenName,
46
+ destinationAddressType,
47
+ isAssociatedTokenAccountActive,
48
+ fromTokenAddresses,
49
+ // staking related
50
+ method,
51
+ stakeAddresses,
52
+ seed,
53
+ pool
54
+ };
55
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.signUnsignedTx = signUnsignedTx;
7
+
8
+ var _assets = _interopRequireDefault(require("@exodus/assets"));
9
+
10
+ var _ = require("../");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function signUnsignedTx(unsignedTx, privateKey) {
15
+ const {
16
+ from,
17
+ to,
18
+ amount: unitAmount,
19
+ recentBlockhash,
20
+ // tokens related
21
+ tokenName,
22
+ destinationAddressType,
23
+ isAssociatedTokenAccountActive,
24
+ fromTokenAddresses,
25
+ // staking related
26
+ stakeAddresses,
27
+ method,
28
+ seed,
29
+ pool
30
+ } = unsignedTx.txData;
31
+ const asset = _assets.default.solana;
32
+ const address = from;
33
+ const amount = unitAmount ? asset.currency.baseUnit(unitAmount).toNumber() : unitAmount;
34
+ let tx;
35
+
36
+ switch (method) {
37
+ case 'delegate':
38
+ tx = _.Transaction.createStakeAccountTransaction({
39
+ address,
40
+ amount,
41
+ recentBlockhash,
42
+ seed,
43
+ pool
44
+ });
45
+ break;
46
+
47
+ case 'undelegate':
48
+ tx = _.Transaction.undelegate({
49
+ address,
50
+ stakeAddresses,
51
+ recentBlockhash
52
+ });
53
+ break;
54
+
55
+ case 'withdraw':
56
+ tx = _.Transaction.withdraw({
57
+ address,
58
+ stakeAddresses,
59
+ amount,
60
+ recentBlockhash
61
+ });
62
+ break;
63
+
64
+ default:
65
+ // SOL and Token tx
66
+ tx = new _.Transaction({
67
+ from,
68
+ to,
69
+ amount,
70
+ recentBlockhash,
71
+ tokenName,
72
+ destinationAddressType,
73
+ isAssociatedTokenAccountActive,
74
+ fromTokenAddresses
75
+ });
76
+ break;
77
+ } // sign plain tx
78
+
79
+
80
+ _.Transaction.sign(tx, privateKey);
81
+
82
+ const rawTx = _.Transaction.serialize(tx);
83
+
84
+ const txId = _.Transaction.getTxId(tx);
85
+
86
+ return {
87
+ txId,
88
+ rawTx
89
+ };
90
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Account = void 0;
7
+
8
+ var _publickey = require("./publickey");
9
+
10
+ var _keypair = require("../keypair");
11
+
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+
14
+ class Account {
15
+ /**
16
+ * Create a new Account object
17
+ *
18
+ * @param secretKey Secret key for the account
19
+ */
20
+ constructor(secretKey) {
21
+ _defineProperty(this, "_keypair", void 0);
22
+
23
+ if (secretKey) {
24
+ this._keypair = (0, _keypair.getKeyPairFromPrivateKey)(Buffer.from(secretKey, 'hex'));
25
+ } else {
26
+ throw new Error('Please provide a secretKey');
27
+ }
28
+ }
29
+ /**
30
+ * The public key for this account
31
+ */
32
+
33
+
34
+ get publicKey() {
35
+ return new _publickey.PublicKey(this._keypair.publicKey);
36
+ }
37
+ /**
38
+ * The **unencrypted** secret key for this account
39
+ */
40
+
41
+
42
+ get secretKey() {
43
+ return this._keypair.secretKey;
44
+ }
45
+
46
+ }
47
+
48
+ exports.Account = Account;