@airgap/stellar 0.13.41-beta.0 → 0.13.41-beta.11
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 +6 -6
- package/v1/data/StellarAddress.d.ts +1 -2
- package/v1/data/StellarAddress.js +6 -9
- package/v1/data/StellarAddress.js.map +1 -1
- package/v1/index.d.ts +4 -3
- package/v1/index.js +3 -1
- package/v1/index.js.map +1 -1
- package/v1/module/StellarAssets.d.ts +3 -0
- package/v1/module/StellarAssets.js +47 -0
- package/v1/module/StellarAssets.js.map +1 -0
- package/v1/module/StellarModule.d.ts +5 -8
- package/v1/module/StellarModule.js +27 -10
- package/v1/module/StellarModule.js.map +1 -1
- package/v1/protocol/StellarProtocol.d.ts +27 -4
- package/v1/protocol/StellarProtocol.js +595 -150
- package/v1/protocol/StellarProtocol.js.map +1 -1
- package/v1/protocol/stellarAssets/StellarAsset.d.ts +18 -0
- package/v1/protocol/stellarAssets/StellarAsset.js +497 -0
- package/v1/protocol/stellarAssets/StellarAsset.js.map +1 -0
- package/v1/serializer/v3/serializer-companion.js +18 -8
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +0 -1
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/protocol.d.ts +35 -0
- package/v1/types/protocol.js +19 -0
- package/v1/types/protocol.js.map +1 -1
- package/v1/protocol/StellarCryptoClient.d.ts +0 -8
- package/v1/protocol/StellarCryptoClient.js +0 -104
- package/v1/protocol/StellarCryptoClient.js.map +0 -1
|
@@ -57,47 +57,11 @@ var errors_1 = require("@airgap/coinlib-core/errors");
|
|
|
57
57
|
var module_kit_1 = require("@airgap/module-kit");
|
|
58
58
|
var stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
59
59
|
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
60
|
+
var protocol_1 = require("../types/protocol");
|
|
60
61
|
var StellarAddress_1 = require("../data/StellarAddress");
|
|
61
62
|
var StellarProtocolImpl = /** @class */ (function () {
|
|
62
63
|
function StellarProtocolImpl(options) {
|
|
63
64
|
if (options === void 0) { options = {}; }
|
|
64
|
-
// public async signMessageWithKeyPair(message: string, keyPair: KeyPair): Promise<Signature> {
|
|
65
|
-
// const secretValue = keyPair.secretKey.value
|
|
66
|
-
// const privateKeyHex =
|
|
67
|
-
// keyPair.secretKey.format === 'hex' ? secretValue : Buffer.from(StrKey.decodeEd25519SecretSeed(secretValue)).toString('hex')
|
|
68
|
-
// const stellarFormat = StrKey.isValidEd25519SecretSeed(secretValue)
|
|
69
|
-
// if (!stellarFormat && !isHex(secretValue)) {
|
|
70
|
-
// throw new ConditionViolationError(Domain.STELLAR, 'Invalid private key format.')
|
|
71
|
-
// }
|
|
72
|
-
// const signatureHex = await this.cryptoClient.signMessage(message, { privateKey: privateKeyHex })
|
|
73
|
-
// return newSignature(signatureHex, 'hex')
|
|
74
|
-
// }
|
|
75
|
-
// public async decryptAsymmetricWithKeyPair(payload: string, keyPair: KeyPair | ExtendedKeyPair): Promise<string> {
|
|
76
|
-
// if (keyPair.secretKey.format !== 'hex') {
|
|
77
|
-
// throw new ConditionViolationError(Domain.STELLAR, 'Secret key is of an unexpected format.')
|
|
78
|
-
// }
|
|
79
|
-
// if (keyPair.publicKey.type !== 'pub') {
|
|
80
|
-
// throw new ConditionViolationError(Domain.STELLAR, 'Public key must be of type "pub"')
|
|
81
|
-
// }
|
|
82
|
-
// const hexPublicKey = convertPublicKey(keyPair.publicKey, 'hex')
|
|
83
|
-
// return this.cryptoClient.decryptAsymmetric(payload, { publicKey: hexPublicKey.value, privateKey: keyPair.secretKey.value })
|
|
84
|
-
// }
|
|
85
|
-
// public async encryptAsymmetricWithPublicKey(payload: string, publicKey: PublicKey): Promise<string> {
|
|
86
|
-
// const hexPublicKey: PublicKey = convertPublicKey(publicKey, 'hex')
|
|
87
|
-
// return this.cryptoClient.encryptAsymmetric(payload, hexPublicKey.value)
|
|
88
|
-
// }
|
|
89
|
-
// encryptAESWithSecretKey(payload: string, secretKey: SecretKey): Promise<string> {
|
|
90
|
-
// if (secretKey.format !== 'hex') {
|
|
91
|
-
// throw new ConditionViolationError(Domain.STELLAR, 'Secret key is of an unexpected format.')
|
|
92
|
-
// }
|
|
93
|
-
// return this.cryptoClient.encryptAES(payload, secretKey.value)
|
|
94
|
-
// }
|
|
95
|
-
// public async decryptAESWithSecretKey(payload: string, secretKey: SecretKey): Promise<string> {
|
|
96
|
-
// if (secretKey.format !== 'hex') {
|
|
97
|
-
// throw new ConditionViolationError(Domain.STELLAR, 'Secret key is of an unexpected format.')
|
|
98
|
-
// }
|
|
99
|
-
// return this.cryptoClient.decryptAES(payload, secretKey.value)
|
|
100
|
-
// }
|
|
101
65
|
this.units = {
|
|
102
66
|
XLM: {
|
|
103
67
|
symbol: { value: 'XLM', market: 'xlm' },
|
|
@@ -105,17 +69,27 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
105
69
|
}
|
|
106
70
|
};
|
|
107
71
|
this.feeDefaults = {
|
|
108
|
-
low: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, '
|
|
109
|
-
medium: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, '
|
|
110
|
-
high: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, '
|
|
72
|
+
low: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, 'blockchain'),
|
|
73
|
+
medium: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, 'blockchain'),
|
|
74
|
+
high: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, 'blockchain')
|
|
111
75
|
};
|
|
112
76
|
this.metadata = {
|
|
113
|
-
identifier: coinlib_core_1.MainProtocolSymbols.
|
|
77
|
+
identifier: coinlib_core_1.MainProtocolSymbols.STELLAR,
|
|
114
78
|
name: 'Stellar',
|
|
115
79
|
units: this.units,
|
|
116
80
|
mainUnit: 'XLM',
|
|
117
81
|
fee: {
|
|
118
|
-
defaults: this.feeDefaults
|
|
82
|
+
defaults: this.feeDefaults,
|
|
83
|
+
mainUnit: 'XLM',
|
|
84
|
+
units: {
|
|
85
|
+
XLM: {
|
|
86
|
+
symbol: {
|
|
87
|
+
value: 'XLM',
|
|
88
|
+
market: 'xlm'
|
|
89
|
+
},
|
|
90
|
+
decimals: 7
|
|
91
|
+
}
|
|
92
|
+
}
|
|
119
93
|
},
|
|
120
94
|
account: {
|
|
121
95
|
standardDerivationPath: "m/44h/148h/0h",
|
|
@@ -131,16 +105,205 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
131
105
|
}
|
|
132
106
|
}
|
|
133
107
|
};
|
|
134
|
-
// public async verifyMessageWithPublicKey(message: string, signature: Signature, publicKey: PublicKey): Promise<boolean> {
|
|
135
|
-
// return this.cryptoClient.verifyMessage(message, signature.value, publicKey.value)
|
|
136
|
-
// }
|
|
137
|
-
// Offline methods
|
|
138
108
|
this.cryptoConfiguration = {
|
|
139
109
|
algorithm: 'ed25519'
|
|
140
110
|
};
|
|
141
111
|
this.options = createStellarProtocolOptions(options.network);
|
|
142
|
-
|
|
112
|
+
this.server = new stellar_sdk_1.Horizon.Server(this.options.network.rpcUrl);
|
|
143
113
|
}
|
|
114
|
+
StellarProtocolImpl.prototype.getMultisigStatus = function (publicKey) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var address, account, error_1;
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
120
|
+
case 1:
|
|
121
|
+
address = _a.sent();
|
|
122
|
+
_a.label = 2;
|
|
123
|
+
case 2:
|
|
124
|
+
_a.trys.push([2, 4, , 5]);
|
|
125
|
+
return [4 /*yield*/, this.server.loadAccount(address)];
|
|
126
|
+
case 3:
|
|
127
|
+
account = _a.sent();
|
|
128
|
+
return [2 /*return*/, account.signers.length > 1];
|
|
129
|
+
case 4:
|
|
130
|
+
error_1 = _a.sent();
|
|
131
|
+
return [2 /*return*/, false];
|
|
132
|
+
case 5: return [2 /*return*/];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
StellarProtocolImpl.prototype.getSigners = function (publicKey) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
+
var address, account, error_2;
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
switch (_a.label) {
|
|
142
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
143
|
+
case 1:
|
|
144
|
+
address = _a.sent();
|
|
145
|
+
_a.label = 2;
|
|
146
|
+
case 2:
|
|
147
|
+
_a.trys.push([2, 4, , 5]);
|
|
148
|
+
return [4 /*yield*/, this.server.loadAccount(address)];
|
|
149
|
+
case 3:
|
|
150
|
+
account = _a.sent();
|
|
151
|
+
return [2 /*return*/, account.signers];
|
|
152
|
+
case 4:
|
|
153
|
+
error_2 = _a.sent();
|
|
154
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_2);
|
|
155
|
+
case 5: return [2 /*return*/];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
StellarProtocolImpl.prototype.getThresholds = function (publicKey) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
var address, account, error_3;
|
|
163
|
+
return __generator(this, function (_a) {
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
166
|
+
case 1:
|
|
167
|
+
address = _a.sent();
|
|
168
|
+
_a.label = 2;
|
|
169
|
+
case 2:
|
|
170
|
+
_a.trys.push([2, 4, , 5]);
|
|
171
|
+
return [4 /*yield*/, this.server.loadAccount(address)];
|
|
172
|
+
case 3:
|
|
173
|
+
account = _a.sent();
|
|
174
|
+
return [2 /*return*/, account.thresholds];
|
|
175
|
+
case 4:
|
|
176
|
+
error_3 = _a.sent();
|
|
177
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_3);
|
|
178
|
+
case 5: return [2 /*return*/];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
StellarProtocolImpl.prototype.getThresholdReachedStatus = function (transaction) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
var tx, sourceAccountId, account, signers, thresholds, requiredThreshold, totalWeight, _i, _a, sig, _b, signers_1, signer, keypair, hint, threshold, error_4;
|
|
186
|
+
return __generator(this, function (_c) {
|
|
187
|
+
switch (_c.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
_c.trys.push([0, 2, , 3]);
|
|
190
|
+
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
191
|
+
sourceAccountId = tx.source;
|
|
192
|
+
return [4 /*yield*/, this.server.loadAccount(sourceAccountId)];
|
|
193
|
+
case 1:
|
|
194
|
+
account = _c.sent();
|
|
195
|
+
signers = account.signers;
|
|
196
|
+
thresholds = account.thresholds;
|
|
197
|
+
requiredThreshold = tx.operations.some(function (op) { return ['setOptions', 'accountMerge'].includes(op.type); })
|
|
198
|
+
? thresholds.high_threshold
|
|
199
|
+
: tx.operations.some(function (op) {
|
|
200
|
+
return [
|
|
201
|
+
'createAccount',
|
|
202
|
+
'payment',
|
|
203
|
+
'pathPaymentStrictReceive',
|
|
204
|
+
'pathPaymentStrictSend',
|
|
205
|
+
'manageSellOffer',
|
|
206
|
+
'manageBuyOffer',
|
|
207
|
+
'createPassiveSellOffer',
|
|
208
|
+
'changeTrust',
|
|
209
|
+
'manageData',
|
|
210
|
+
'createClaimableBalance',
|
|
211
|
+
'beginSponsoringFutureReserves',
|
|
212
|
+
'endSponsoringFutureReserves',
|
|
213
|
+
'revokeSponsorship',
|
|
214
|
+
'clawback',
|
|
215
|
+
'clawbackClaimableBalance',
|
|
216
|
+
'liquidityPoolDeposit',
|
|
217
|
+
'liquidityPoolWithdraw',
|
|
218
|
+
'invokeHostFunction',
|
|
219
|
+
'extendFootprintTtl',
|
|
220
|
+
'restoreFootprint'
|
|
221
|
+
].includes(op.type);
|
|
222
|
+
})
|
|
223
|
+
? thresholds.med_threshold
|
|
224
|
+
: thresholds.low_threshold;
|
|
225
|
+
totalWeight = 0;
|
|
226
|
+
for (_i = 0, _a = tx.signatures; _i < _a.length; _i++) {
|
|
227
|
+
sig = _a[_i];
|
|
228
|
+
for (_b = 0, signers_1 = signers; _b < signers_1.length; _b++) {
|
|
229
|
+
signer = signers_1[_b];
|
|
230
|
+
keypair = stellar_sdk_1.Keypair.fromPublicKey(signer.key);
|
|
231
|
+
hint = keypair.signatureHint();
|
|
232
|
+
if (hint.equals(sig.hint())) {
|
|
233
|
+
totalWeight += signer.weight;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
threshold = {
|
|
238
|
+
thresholdRequired: requiredThreshold,
|
|
239
|
+
currentThreshold: totalWeight
|
|
240
|
+
};
|
|
241
|
+
return [2 /*return*/, threshold];
|
|
242
|
+
case 2:
|
|
243
|
+
error_4 = _c.sent();
|
|
244
|
+
return [2 /*return*/, {
|
|
245
|
+
thresholdRequired: 0,
|
|
246
|
+
currentThreshold: 0
|
|
247
|
+
}];
|
|
248
|
+
case 3: return [2 /*return*/];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
StellarProtocolImpl.prototype.adjustSigner = function (masterPublicky, signerPublicKey, weight, lowThreshold, medThreshold, highThreshold) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
+
var masterAddress, signerAddress, account, signers, txBuilder, masterWeight;
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
switch (_a.label) {
|
|
258
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(masterPublicky)];
|
|
259
|
+
case 1:
|
|
260
|
+
masterAddress = _a.sent();
|
|
261
|
+
return [4 /*yield*/, this.getAddressFromPublicKey(signerPublicKey)];
|
|
262
|
+
case 2:
|
|
263
|
+
signerAddress = _a.sent();
|
|
264
|
+
return [4 /*yield*/, this.server.loadAccount(masterAddress)];
|
|
265
|
+
case 3:
|
|
266
|
+
account = _a.sent();
|
|
267
|
+
signers = account.signers;
|
|
268
|
+
txBuilder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
269
|
+
fee: stellar_sdk_1.BASE_FEE,
|
|
270
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
271
|
+
});
|
|
272
|
+
if (signers.length === 1) {
|
|
273
|
+
masterWeight = weight;
|
|
274
|
+
txBuilder
|
|
275
|
+
.addOperation(stellar_sdk_1.Operation.setOptions({
|
|
276
|
+
masterWeight: masterWeight,
|
|
277
|
+
lowThreshold: lowThreshold,
|
|
278
|
+
medThreshold: medThreshold,
|
|
279
|
+
highThreshold: highThreshold,
|
|
280
|
+
signer: {
|
|
281
|
+
ed25519PublicKey: signerAddress,
|
|
282
|
+
weight: weight
|
|
283
|
+
}
|
|
284
|
+
}))
|
|
285
|
+
.setTimeout(600);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
txBuilder
|
|
289
|
+
.addOperation(stellar_sdk_1.Operation.setOptions({
|
|
290
|
+
lowThreshold: lowThreshold,
|
|
291
|
+
medThreshold: medThreshold,
|
|
292
|
+
highThreshold: highThreshold,
|
|
293
|
+
signer: {
|
|
294
|
+
ed25519PublicKey: signerAddress,
|
|
295
|
+
weight: weight
|
|
296
|
+
}
|
|
297
|
+
}))
|
|
298
|
+
.setTimeout(600);
|
|
299
|
+
}
|
|
300
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
301
|
+
transaction: txBuilder.build().toXDR()
|
|
302
|
+
})];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
};
|
|
144
307
|
StellarProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
|
|
145
308
|
return __awaiter(this, void 0, void 0, function () {
|
|
146
309
|
var address;
|
|
@@ -157,7 +320,7 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
157
320
|
StellarProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
|
|
158
321
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
159
322
|
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
-
var endpoint, url, response, data, paymentTransactions, transactions,
|
|
323
|
+
var endpoint, url, response, data, paymentTransactions, transactions, error_5;
|
|
161
324
|
var _this = this;
|
|
162
325
|
return __generator(this, function (_l) {
|
|
163
326
|
switch (_l.label) {
|
|
@@ -171,41 +334,43 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
171
334
|
data = response.data;
|
|
172
335
|
paymentTransactions = (_c = (_b = data._embedded) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : [];
|
|
173
336
|
transactions = paymentTransactions
|
|
174
|
-
.filter(function (tx) {
|
|
337
|
+
.filter(function (tx) {
|
|
338
|
+
return (tx.type === protocol_1.StellarTransactionType.PAYMENT && tx.asset_type === protocol_1.StellarAssetType.NATIVE) || tx.type === 'create_account';
|
|
339
|
+
})
|
|
175
340
|
.map(function (tx) {
|
|
176
341
|
var txData = tx.transaction;
|
|
342
|
+
var isPayment = tx.type === protocol_1.StellarTransactionType.PAYMENT;
|
|
343
|
+
var txAmount = isPayment ? tx.amount : tx.starting_balance;
|
|
344
|
+
var amount = new bignumber_1.default(txAmount).multipliedBy(1e7).toString();
|
|
345
|
+
var from = isPayment ? tx.from : tx.funder;
|
|
346
|
+
var to = isPayment ? tx.to : tx.account;
|
|
347
|
+
var isInbound = to.toLowerCase() === address.toLowerCase();
|
|
177
348
|
return {
|
|
178
|
-
from: [
|
|
179
|
-
to: [
|
|
180
|
-
isInbound:
|
|
181
|
-
amount: (0, module_kit_1.newAmount)(
|
|
182
|
-
fee: (0, module_kit_1.newAmount)(
|
|
349
|
+
from: [from],
|
|
350
|
+
to: [to],
|
|
351
|
+
isInbound: isInbound,
|
|
352
|
+
amount: (0, module_kit_1.newAmount)(amount, 'blockchain'),
|
|
353
|
+
fee: (0, module_kit_1.newAmount)(txData.fee_charged, 'blockchain'),
|
|
183
354
|
network: _this.options.network,
|
|
184
|
-
timestamp: new Date(tx.created_at).getTime(),
|
|
355
|
+
timestamp: Math.floor(new Date(tx.created_at).getTime() / 1000),
|
|
185
356
|
status: {
|
|
186
357
|
type: tx.transaction_successful ? 'applied' : 'failed',
|
|
187
358
|
hash: tx.transaction_hash,
|
|
188
359
|
block: txData.ledger.toString()
|
|
189
360
|
},
|
|
190
|
-
arbitraryData: txData.
|
|
191
|
-
? txData.memo
|
|
192
|
-
: txData.memo_type === 'hash'
|
|
193
|
-
? "Hash: ".concat(txData.memo)
|
|
194
|
-
: txData.memo_type === 'id'
|
|
195
|
-
? "ID: ".concat(txData.memo)
|
|
196
|
-
: undefined
|
|
361
|
+
arbitraryData: txData.memo
|
|
197
362
|
};
|
|
198
363
|
});
|
|
199
364
|
return [2 /*return*/, {
|
|
200
365
|
transactions: transactions,
|
|
201
366
|
cursor: {
|
|
202
367
|
hasNext: ((_e = (_d = data._links) === null || _d === void 0 ? void 0 : _d.next) === null || _e === void 0 ? void 0 : _e.href) !== undefined,
|
|
203
|
-
next: (_j = (_h = (_g = (_f = data._links) === null || _f === void 0 ? void 0 : _f.next) === null || _g === void 0 ? void 0 : _g.href) === null || _h === void 0 ? void 0 : _h.replace(this.options.network.rpcUrl, '')) !== null && _j !== void 0 ? _j :
|
|
368
|
+
next: (_j = (_h = (_g = (_f = data._links) === null || _f === void 0 ? void 0 : _f.next) === null || _g === void 0 ? void 0 : _g.href) === null || _h === void 0 ? void 0 : _h.replace(this.options.network.rpcUrl, '')) !== null && _j !== void 0 ? _j : undefined
|
|
204
369
|
}
|
|
205
370
|
}];
|
|
206
371
|
case 2:
|
|
207
|
-
|
|
208
|
-
if (((_k =
|
|
372
|
+
error_5 = _l.sent();
|
|
373
|
+
if (((_k = error_5.response) === null || _k === void 0 ? void 0 : _k.status) === 404) {
|
|
209
374
|
return [2 /*return*/, {
|
|
210
375
|
transactions: [],
|
|
211
376
|
cursor: {
|
|
@@ -214,7 +379,7 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
214
379
|
}
|
|
215
380
|
}];
|
|
216
381
|
}
|
|
217
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR,
|
|
382
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_5);
|
|
218
383
|
case 3: return [2 /*return*/];
|
|
219
384
|
}
|
|
220
385
|
});
|
|
@@ -222,7 +387,7 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
222
387
|
};
|
|
223
388
|
StellarProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
|
|
224
389
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
var balance, balanceBn, fee, amountWithoutFees,
|
|
390
|
+
var balance, balanceBn, fee, amountWithoutFees, error_6;
|
|
226
391
|
return __generator(this, function (_a) {
|
|
227
392
|
switch (_a.label) {
|
|
228
393
|
case 0:
|
|
@@ -236,16 +401,16 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
236
401
|
fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value);
|
|
237
402
|
}
|
|
238
403
|
else {
|
|
239
|
-
fee = new bignumber_1.default(
|
|
404
|
+
fee = new bignumber_1.default(stellar_sdk_1.BASE_FEE).multipliedBy(to.length).dividedBy(1e7);
|
|
240
405
|
}
|
|
241
406
|
if (fee.gte(balanceBn)) {
|
|
242
|
-
|
|
407
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(0, 'blockchain')];
|
|
243
408
|
}
|
|
244
409
|
amountWithoutFees = balanceBn.minus(fee);
|
|
245
|
-
return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees
|
|
410
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees, 'blockchain')];
|
|
246
411
|
case 2:
|
|
247
|
-
|
|
248
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR,
|
|
412
|
+
error_6 = _a.sent();
|
|
413
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_6);
|
|
249
414
|
case 3: return [2 /*return*/];
|
|
250
415
|
}
|
|
251
416
|
});
|
|
@@ -277,7 +442,6 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
277
442
|
return __generator(this, function (_a) {
|
|
278
443
|
switch (transaction.type) {
|
|
279
444
|
case 'signed':
|
|
280
|
-
return [2 /*return*/, this.getDetailsFromEncodedTransaction(transaction.transaction, _publicKey)];
|
|
281
445
|
case 'unsigned':
|
|
282
446
|
return [2 /*return*/, this.getDetailsFromEncodedTransaction(transaction.transaction, _publicKey)];
|
|
283
447
|
default:
|
|
@@ -288,32 +452,272 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
288
452
|
});
|
|
289
453
|
});
|
|
290
454
|
};
|
|
455
|
+
StellarProtocolImpl.prototype.getDetailsFromEncodedGenericTransaction = function (transaction) {
|
|
456
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
457
|
+
return __generator(this, function (_a) {
|
|
458
|
+
return [2 /*return*/, stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.PUBLIC)];
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
};
|
|
291
462
|
StellarProtocolImpl.prototype.getDetailsFromEncodedTransaction = function (transaction, publicKey) {
|
|
292
|
-
var _a, _b, _c, _d
|
|
463
|
+
var _a, _b, _c, _d;
|
|
293
464
|
return __awaiter(this, void 0, void 0, function () {
|
|
294
|
-
var transactions, tx, op, isInbound,
|
|
295
|
-
return __generator(this, function (
|
|
465
|
+
var transactions, tx, _i, _e, txDetails, amount, op, to, fee, isInbound, type, uiAlerts, displayFromTo, asetType, asetType, cont, contractAddress, sendAssetIsNative, sendAssetIsNative, signer, descriptionParts, memo;
|
|
466
|
+
return __generator(this, function (_f) {
|
|
296
467
|
transactions = [];
|
|
297
|
-
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
468
|
+
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
469
|
+
for (_i = 0, _e = tx.operations; _i < _e.length; _i++) {
|
|
470
|
+
txDetails = _e[_i];
|
|
471
|
+
amount = void 0;
|
|
472
|
+
op = void 0;
|
|
473
|
+
to = void 0;
|
|
474
|
+
fee = void 0;
|
|
475
|
+
isInbound = void 0;
|
|
476
|
+
type = void 0;
|
|
477
|
+
uiAlerts = [];
|
|
478
|
+
displayFromTo = true;
|
|
479
|
+
if (txDetails.type === protocol_1.StellarTransactionType.PAYMENT) {
|
|
480
|
+
op = txDetails;
|
|
481
|
+
if (op.asset.code === protocol_1.StellarAssetType.XLM) {
|
|
482
|
+
amount = new bignumber_1.default(op.amount).multipliedBy(1e7).toString();
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
uiAlerts.push({
|
|
486
|
+
type: 'warning',
|
|
487
|
+
title: { value: protocol_1.StellarTransactionType.PAYMENT, type: 'plain' },
|
|
488
|
+
description: {
|
|
489
|
+
value: "".concat(op.amount, " ").concat(op.asset.code, " will be deducted from the source wallet"),
|
|
490
|
+
type: 'plain'
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
amount = new bignumber_1.default(0).multipliedBy(1e7).toString();
|
|
494
|
+
}
|
|
495
|
+
fee = tx.fee;
|
|
496
|
+
to = [op.destination];
|
|
497
|
+
type = protocol_1.StellarTransactionType.PAYMENT;
|
|
498
|
+
isInbound = to[0].toLowerCase() === publicKey.value.toLowerCase();
|
|
499
|
+
}
|
|
500
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.CREATE_ACCOUNT) {
|
|
501
|
+
op = txDetails;
|
|
502
|
+
amount = new bignumber_1.default(op.startingBalance).multipliedBy(1e7).toString();
|
|
503
|
+
to = [op.destination];
|
|
504
|
+
fee = tx.fee;
|
|
505
|
+
isInbound = to[0].toLowerCase() === publicKey.value.toLowerCase();
|
|
506
|
+
type = protocol_1.StellarTransactionType.CREATE_ACCOUNT;
|
|
507
|
+
}
|
|
508
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.CHANGE_TRUST) {
|
|
509
|
+
op = txDetails;
|
|
510
|
+
amount = new bignumber_1.default(0).toString();
|
|
511
|
+
if (op.line instanceof stellar_sdk_1.Asset) {
|
|
512
|
+
asetType = op.line;
|
|
513
|
+
to = [asetType.getIssuer()];
|
|
514
|
+
}
|
|
515
|
+
else if (op.line instanceof stellar_sdk_1.LiquidityPoolAsset) {
|
|
516
|
+
asetType = op.line;
|
|
517
|
+
to = [(_a = asetType.assetA.getIssuer()) !== null && _a !== void 0 ? _a : protocol_1.StellarAssetType.NATIVE, (_b = asetType.assetB.getIssuer()) !== null && _b !== void 0 ? _b : protocol_1.StellarAssetType.NATIVE];
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
to = [tx.source];
|
|
521
|
+
}
|
|
522
|
+
fee = new bignumber_1.default(tx.fee).dividedBy(tx.operations.length).toString();
|
|
523
|
+
isInbound = false;
|
|
524
|
+
type = protocol_1.StellarTransactionType.CHANGE_TRUST;
|
|
525
|
+
}
|
|
526
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION) {
|
|
527
|
+
isInbound = false;
|
|
528
|
+
op = txDetails;
|
|
529
|
+
fee = tx.fee;
|
|
530
|
+
cont = op.func.value();
|
|
531
|
+
amount = new bignumber_1.default(0).toString();
|
|
532
|
+
try {
|
|
533
|
+
Buffer.from(cont.contractAddress().value(), 'hex');
|
|
534
|
+
contractAddress = stellar_sdk_1.StrKey.encodeContract(Buffer.from(cont.contractAddress().value(), 'hex'));
|
|
535
|
+
to = [contractAddress];
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
to = [tx.source];
|
|
539
|
+
}
|
|
540
|
+
type = protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION;
|
|
541
|
+
displayFromTo = false;
|
|
542
|
+
uiAlerts.push({
|
|
543
|
+
type: 'warning',
|
|
544
|
+
title: { value: protocol_1.StellarTransactionType.INOKE_HOST_FUNCTION, type: 'plain' },
|
|
545
|
+
description: {
|
|
546
|
+
value: "Transaction ".concat(txDetails.type, " type was not decoded. Please understand what you are signing before proceeding."),
|
|
547
|
+
type: 'plain'
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.PATH_PAYMENT_RECIEVE) {
|
|
552
|
+
op = txDetails;
|
|
553
|
+
fee = tx.fee;
|
|
554
|
+
sendAssetIsNative = op.sendAsset.isNative();
|
|
555
|
+
amount = new bignumber_1.default(sendAssetIsNative ? op.sendMax : 0).multipliedBy(1e7).toString();
|
|
556
|
+
to = [txDetails.destination];
|
|
557
|
+
isInbound = false;
|
|
558
|
+
type = protocol_1.StellarTransactionType.PATH_PAYMENT_RECIEVE;
|
|
559
|
+
if (!sendAssetIsNative) {
|
|
560
|
+
uiAlerts.push({
|
|
561
|
+
type: 'warning',
|
|
562
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
563
|
+
description: {
|
|
564
|
+
value: "Maximum of ".concat(op.sendMax, " ").concat(op.sendAsset, " will be deducted from the source wallet"),
|
|
565
|
+
type: 'plain'
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
uiAlerts.push({
|
|
571
|
+
type: 'info',
|
|
572
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
573
|
+
description: {
|
|
574
|
+
value: "".concat(op.destAmount, " ").concat(op.destAsset, " will added to your wallet"),
|
|
575
|
+
type: 'plain'
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.PATH_PAYMENT_SEND) {
|
|
581
|
+
op = txDetails;
|
|
582
|
+
fee = tx.fee;
|
|
583
|
+
sendAssetIsNative = op.sendAsset.isNative();
|
|
584
|
+
amount = new bignumber_1.default(sendAssetIsNative ? op.sendAmount : 0).multipliedBy(1e7).toString();
|
|
585
|
+
to = [txDetails.destination];
|
|
586
|
+
isInbound = false;
|
|
587
|
+
type = protocol_1.StellarTransactionType.PATH_PAYMENT_SEND;
|
|
588
|
+
if (!sendAssetIsNative) {
|
|
589
|
+
uiAlerts.push({
|
|
590
|
+
type: 'warning',
|
|
591
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
592
|
+
description: {
|
|
593
|
+
value: "".concat(op.sendAmount, " ").concat(op.sendAsset, " will be deducted from the source wallet"),
|
|
594
|
+
type: 'plain'
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
uiAlerts.push({
|
|
600
|
+
type: 'info',
|
|
601
|
+
title: { value: protocol_1.StellarTransactionType.PATH_PAYMENT_SEND, type: 'plain' },
|
|
602
|
+
description: {
|
|
603
|
+
value: "Minimum of ".concat(op.destMin, " ").concat(op.destAsset, " will added to your wallet"),
|
|
604
|
+
type: 'plain'
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT) {
|
|
610
|
+
amount = new bignumber_1.default(0).toString();
|
|
611
|
+
op = txDetails;
|
|
612
|
+
fee = tx.fee;
|
|
613
|
+
to = [op.liquidityPoolId];
|
|
614
|
+
uiAlerts.push({
|
|
615
|
+
type: 'warning',
|
|
616
|
+
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT, type: 'plain' },
|
|
617
|
+
description: {
|
|
618
|
+
value: "Transaction is not fully decoded",
|
|
619
|
+
type: 'plain'
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
uiAlerts.push({
|
|
623
|
+
type: 'warning',
|
|
624
|
+
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT, type: 'plain' },
|
|
625
|
+
description: {
|
|
626
|
+
value: "".concat(op.maxAmountA, " & ").concat(op.maxAmountB, " of two different assets will be deducted from the source wallet"),
|
|
627
|
+
type: 'plain'
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
type = protocol_1.StellarTransactionType.LIQUIDITY_POOL_DEPOSIT;
|
|
631
|
+
}
|
|
632
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.LIQUIDITY_POOL_WITHDRAW) {
|
|
633
|
+
amount = new bignumber_1.default(0).toString();
|
|
634
|
+
op = txDetails;
|
|
635
|
+
fee = tx.fee;
|
|
636
|
+
to = [op.liquidityPoolId];
|
|
637
|
+
uiAlerts.push({
|
|
638
|
+
type: 'info',
|
|
639
|
+
title: { value: protocol_1.StellarTransactionType.LIQUIDITY_POOL_WITHDRAW, type: 'plain' },
|
|
640
|
+
description: {
|
|
641
|
+
value: "".concat(op.minAmountA, " & ").concat(op.minAmountB, " of two different assets will be added to your wallet"),
|
|
642
|
+
type: 'plain'
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
type = protocol_1.StellarTransactionType.LIQUIDITY_POOL_WITHDRAW;
|
|
646
|
+
}
|
|
647
|
+
else if (txDetails.type === protocol_1.StellarTransactionType.SET_OPTIONS) {
|
|
648
|
+
op = txDetails;
|
|
649
|
+
fee = tx.fee;
|
|
650
|
+
signer = op.signer;
|
|
651
|
+
if ('ed25519PublicKey' in signer && signer.ed25519PublicKey) {
|
|
652
|
+
to = [signer.ed25519PublicKey];
|
|
653
|
+
}
|
|
654
|
+
else if ('ed25519SignedPayload' in signer && signer.ed25519SignedPayload) {
|
|
655
|
+
to = [signer.ed25519SignedPayload];
|
|
656
|
+
}
|
|
657
|
+
else if ('preAuthTx' in signer && signer.preAuthTx) {
|
|
658
|
+
to = [signer.preAuthTx.toString('hex')];
|
|
659
|
+
}
|
|
660
|
+
else if ('sha256Hash' in signer && signer.sha256Hash) {
|
|
661
|
+
to = [signer.sha256Hash.toString('hex')];
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
to = [tx.source];
|
|
665
|
+
}
|
|
666
|
+
descriptionParts = [
|
|
667
|
+
to[0] && "Signer: ".concat(to[0]),
|
|
668
|
+
op.masterWeight !== undefined && "MasterWeight: ".concat(op.masterWeight),
|
|
669
|
+
op.lowThreshold !== undefined && "LowThreshold: ".concat(op.lowThreshold),
|
|
670
|
+
op.medThreshold !== undefined && "MedThreshold: ".concat(op.medThreshold),
|
|
671
|
+
op.highThreshold !== undefined && "HighThreshold: ".concat(op.highThreshold)
|
|
672
|
+
]
|
|
673
|
+
.filter(Boolean)
|
|
674
|
+
.join('\n');
|
|
675
|
+
uiAlerts.push({
|
|
676
|
+
type: 'info',
|
|
677
|
+
title: { value: protocol_1.StellarTransactionType.SET_OPTIONS, type: 'plain' },
|
|
678
|
+
description: {
|
|
679
|
+
value: "You are setting the following parameters:\n".concat(descriptionParts),
|
|
680
|
+
type: 'plain'
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
amount = new bignumber_1.default(0).toString();
|
|
684
|
+
type = protocol_1.StellarTransactionType.SET_OPTIONS;
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
to = [tx.source];
|
|
688
|
+
fee = tx.fee;
|
|
689
|
+
amount = new bignumber_1.default(0).toString();
|
|
690
|
+
isInbound = false;
|
|
691
|
+
type = txDetails.type;
|
|
692
|
+
uiAlerts.push({
|
|
693
|
+
type: 'warning',
|
|
694
|
+
title: { value: txDetails.type, type: 'plain' },
|
|
695
|
+
description: {
|
|
696
|
+
value: "Transaction ".concat(txDetails.type, " type was not decoded. Please understand what you are signing before proceeding."),
|
|
697
|
+
type: 'plain'
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
displayFromTo = false;
|
|
701
|
+
}
|
|
702
|
+
memo = tx.memo.type === 'text' || tx.memo.type === 'id'
|
|
703
|
+
? (_c = tx.memo.value) === null || _c === void 0 ? void 0 : _c.toString()
|
|
704
|
+
: tx.memo.type === 'hash' || tx.memo.type === 'return'
|
|
705
|
+
? (_d = tx.memo.value) === null || _d === void 0 ? void 0 : _d.toString('hex')
|
|
307
706
|
: undefined;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
707
|
+
transactions.push({
|
|
708
|
+
from: [tx.source],
|
|
709
|
+
to: to,
|
|
710
|
+
isInbound: isInbound,
|
|
711
|
+
amount: (0, module_kit_1.newAmount)(amount, 'blockchain'),
|
|
712
|
+
fee: (0, module_kit_1.newAmount)(fee, 'blockchain'),
|
|
713
|
+
network: this.options.network,
|
|
714
|
+
arbitraryData: memo,
|
|
715
|
+
type: type,
|
|
716
|
+
uiAlerts: uiAlerts,
|
|
717
|
+
json: JSON.stringify(tx),
|
|
718
|
+
displayFromTo: displayFromTo
|
|
719
|
+
});
|
|
720
|
+
}
|
|
317
721
|
return [2 /*return*/, transactions];
|
|
318
722
|
});
|
|
319
723
|
});
|
|
@@ -337,11 +741,10 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
337
741
|
};
|
|
338
742
|
StellarProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
|
|
339
743
|
return __awaiter(this, void 0, void 0, function () {
|
|
340
|
-
var tx
|
|
744
|
+
var tx;
|
|
341
745
|
return __generator(this, function (_a) {
|
|
342
|
-
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction.transaction, stellar_sdk_1.Networks.
|
|
343
|
-
|
|
344
|
-
tx.sign(keyPair);
|
|
746
|
+
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction.transaction, stellar_sdk_1.Networks.PUBLIC);
|
|
747
|
+
tx.sign(stellar_sdk_1.Keypair.fromSecret(stellar_sdk_1.StrKey.encodeEd25519SecretSeed(Buffer.from(secretKey.value, 'hex'))));
|
|
345
748
|
return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({
|
|
346
749
|
transaction: tx.toXDR()
|
|
347
750
|
})];
|
|
@@ -369,91 +772,92 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
369
772
|
});
|
|
370
773
|
};
|
|
371
774
|
StellarProtocolImpl.prototype.getBalanceOfAddress = function (address) {
|
|
372
|
-
var _a;
|
|
373
775
|
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
-
var data, balance,
|
|
375
|
-
return __generator(this, function (
|
|
376
|
-
switch (
|
|
776
|
+
var data, balance, btnBalance, error_7;
|
|
777
|
+
return __generator(this, function (_a) {
|
|
778
|
+
switch (_a.label) {
|
|
377
779
|
case 0:
|
|
378
|
-
|
|
780
|
+
_a.trys.push([0, 2, , 3]);
|
|
379
781
|
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/accounts/").concat(address))];
|
|
380
782
|
case 1:
|
|
381
|
-
data = (
|
|
382
|
-
balance = data.balances.find(function (b) { return b.asset_type ===
|
|
783
|
+
data = (_a.sent()).data;
|
|
784
|
+
balance = data.balances.find(function (b) { return b.asset_type === protocol_1.StellarAssetType.NATIVE; });
|
|
785
|
+
btnBalance = new bignumber_1.default(balance.balance).multipliedBy(1e7).toString();
|
|
383
786
|
return [2 /*return*/, {
|
|
384
|
-
total: (0, module_kit_1.newAmount)(
|
|
787
|
+
total: (0, module_kit_1.newAmount)(btnBalance, 'blockchain')
|
|
385
788
|
}];
|
|
386
789
|
case 2:
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return [2 /*return*/, { total: (0, module_kit_1.newAmount)('0', 'blockchain') }];
|
|
390
|
-
}
|
|
391
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_3);
|
|
790
|
+
error_7 = _a.sent();
|
|
791
|
+
return [2 /*return*/, { total: (0, module_kit_1.newAmount)('0', 'blockchain') }];
|
|
392
792
|
case 3: return [2 /*return*/];
|
|
393
793
|
}
|
|
394
794
|
});
|
|
395
795
|
});
|
|
396
796
|
};
|
|
397
797
|
StellarProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
|
|
398
|
-
var _a;
|
|
798
|
+
var _a, _b;
|
|
399
799
|
return __awaiter(this, void 0, void 0, function () {
|
|
400
|
-
var
|
|
401
|
-
return __generator(this, function (
|
|
402
|
-
switch (
|
|
403
|
-
case 0:
|
|
404
|
-
server = new stellar_sdk_1.Horizon.Server(this.options.network.rpcUrl);
|
|
405
|
-
return [4 /*yield*/, server.loadAccount(publicKey.value)];
|
|
800
|
+
var address, account, fee, txBuilder, _i, details_1, detail, destinationExists, e_1, amount, memo, tx;
|
|
801
|
+
return __generator(this, function (_c) {
|
|
802
|
+
switch (_c.label) {
|
|
803
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
406
804
|
case 1:
|
|
407
|
-
|
|
805
|
+
address = _c.sent();
|
|
806
|
+
return [4 /*yield*/, this.server.loadAccount(address)];
|
|
807
|
+
case 2:
|
|
808
|
+
account = _c.sent();
|
|
809
|
+
fee = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined ? (_a = configuration === null || configuration === void 0 ? void 0 : configuration.fee) === null || _a === void 0 ? void 0 : _a.value : stellar_sdk_1.BASE_FEE;
|
|
408
810
|
txBuilder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
409
|
-
fee:
|
|
410
|
-
networkPassphrase: stellar_sdk_1.Networks.
|
|
811
|
+
fee: fee,
|
|
812
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
411
813
|
});
|
|
412
814
|
_i = 0, details_1 = details;
|
|
413
|
-
|
|
414
|
-
case
|
|
415
|
-
if (!(_i < details_1.length)) return [3 /*break*/,
|
|
815
|
+
_c.label = 3;
|
|
816
|
+
case 3:
|
|
817
|
+
if (!(_i < details_1.length)) return [3 /*break*/, 9];
|
|
416
818
|
detail = details_1[_i];
|
|
417
819
|
destinationExists = true;
|
|
418
|
-
|
|
419
|
-
case 3:
|
|
420
|
-
_b.trys.push([3, 5, , 6]);
|
|
421
|
-
return [4 /*yield*/, server.loadAccount(detail.to)];
|
|
820
|
+
_c.label = 4;
|
|
422
821
|
case 4:
|
|
423
|
-
|
|
424
|
-
return [
|
|
822
|
+
_c.trys.push([4, 6, , 7]);
|
|
823
|
+
return [4 /*yield*/, this.server.loadAccount(detail.to)];
|
|
425
824
|
case 5:
|
|
426
|
-
|
|
427
|
-
|
|
825
|
+
_c.sent();
|
|
826
|
+
return [3 /*break*/, 7];
|
|
827
|
+
case 6:
|
|
828
|
+
e_1 = _c.sent();
|
|
829
|
+
if (((_b = e_1.response) === null || _b === void 0 ? void 0 : _b.status) === 404) {
|
|
428
830
|
destinationExists = false;
|
|
429
831
|
}
|
|
430
832
|
else {
|
|
431
833
|
throw e_1;
|
|
432
834
|
}
|
|
433
|
-
return [3 /*break*/,
|
|
434
|
-
case
|
|
835
|
+
return [3 /*break*/, 7];
|
|
836
|
+
case 7:
|
|
837
|
+
amount = new bignumber_1.default(detail.amount.value).dividedBy(1e7).toString();
|
|
435
838
|
if (destinationExists) {
|
|
436
839
|
txBuilder.addOperation(stellar_sdk_1.Operation.payment({
|
|
437
840
|
destination: detail.to,
|
|
438
841
|
asset: stellar_sdk_1.Asset.native(),
|
|
439
|
-
amount:
|
|
842
|
+
amount: amount
|
|
440
843
|
}));
|
|
441
844
|
}
|
|
442
845
|
else {
|
|
443
846
|
txBuilder.addOperation(stellar_sdk_1.Operation.createAccount({
|
|
444
847
|
destination: detail.to,
|
|
445
|
-
startingBalance:
|
|
848
|
+
startingBalance: amount
|
|
446
849
|
}));
|
|
447
850
|
}
|
|
448
|
-
|
|
449
|
-
case 7:
|
|
450
|
-
_i++;
|
|
451
|
-
return [3 /*break*/, 2];
|
|
851
|
+
_c.label = 8;
|
|
452
852
|
case 8:
|
|
853
|
+
_i++;
|
|
854
|
+
return [3 /*break*/, 3];
|
|
855
|
+
case 9:
|
|
453
856
|
if (configuration === null || configuration === void 0 ? void 0 : configuration.arbitraryData) {
|
|
454
|
-
|
|
857
|
+
memo = configuration === null || configuration === void 0 ? void 0 : configuration.arbitraryData;
|
|
858
|
+
txBuilder.addMemo(stellar_sdk_1.Memo.id(memo));
|
|
455
859
|
}
|
|
456
|
-
tx = txBuilder.setTimeout(
|
|
860
|
+
tx = txBuilder.setTimeout(600).build();
|
|
457
861
|
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
458
862
|
transaction: tx.toXDR()
|
|
459
863
|
})];
|
|
@@ -481,6 +885,52 @@ var StellarProtocolImpl = /** @class */ (function () {
|
|
|
481
885
|
});
|
|
482
886
|
});
|
|
483
887
|
};
|
|
888
|
+
StellarProtocolImpl.prototype.getWalletConnectChain = function () {
|
|
889
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
890
|
+
var chain;
|
|
891
|
+
return __generator(this, function (_a) {
|
|
892
|
+
chain = this.options.network.type === 'mainnet' ? 'pubnet' : 'testnet';
|
|
893
|
+
return [2 /*return*/, "stellar:".concat(chain)];
|
|
894
|
+
});
|
|
895
|
+
});
|
|
896
|
+
};
|
|
897
|
+
StellarProtocolImpl.prototype.prepareWalletConnectTransactionWithPublicKey = function (publicKey, request) {
|
|
898
|
+
var _a, _b;
|
|
899
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
900
|
+
var sourceAddress, sourceAccount, destination, value, amount, fee, txBuilder, tx;
|
|
901
|
+
return __generator(this, function (_c) {
|
|
902
|
+
switch (_c.label) {
|
|
903
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
904
|
+
case 1:
|
|
905
|
+
sourceAddress = _c.sent();
|
|
906
|
+
return [4 /*yield*/, this.server.loadAccount(sourceAddress)];
|
|
907
|
+
case 2:
|
|
908
|
+
sourceAccount = _c.sent();
|
|
909
|
+
destination = (_a = request.to) !== null && _a !== void 0 ? _a : '';
|
|
910
|
+
value = (_b = request.value) !== null && _b !== void 0 ? _b : '0';
|
|
911
|
+
amount = new bignumber_1.default(value).dividedBy(1e7).toString() // convert from stroops to XLM
|
|
912
|
+
;
|
|
913
|
+
fee = stellar_sdk_1.BASE_FEE;
|
|
914
|
+
txBuilder = new stellar_sdk_1.TransactionBuilder(sourceAccount, {
|
|
915
|
+
fee: fee,
|
|
916
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
917
|
+
});
|
|
918
|
+
txBuilder.addOperation(stellar_sdk_1.Operation.payment({
|
|
919
|
+
destination: destination,
|
|
920
|
+
asset: stellar_sdk_1.Asset.native(),
|
|
921
|
+
amount: amount
|
|
922
|
+
}));
|
|
923
|
+
if (request.data) {
|
|
924
|
+
txBuilder.addMemo(stellar_sdk_1.Memo.id(request.data.toString()));
|
|
925
|
+
}
|
|
926
|
+
tx = txBuilder.setTimeout(600).build();
|
|
927
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
928
|
+
transaction: tx.toXDR()
|
|
929
|
+
})];
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
};
|
|
484
934
|
return StellarProtocolImpl;
|
|
485
935
|
}());
|
|
486
936
|
exports.StellarProtocolImpl = StellarProtocolImpl;
|
|
@@ -492,8 +942,8 @@ exports.createStellarProtocol = createStellarProtocol;
|
|
|
492
942
|
exports.STELLAR_MAINNET_PROTOCOL_NETWORK = {
|
|
493
943
|
name: 'Mainnet',
|
|
494
944
|
type: 'mainnet',
|
|
495
|
-
rpcUrl: 'https://horizon
|
|
496
|
-
blockExplorerUrl: 'https://stellar.expert/explorer/
|
|
945
|
+
rpcUrl: 'https://horizon.stellar.org',
|
|
946
|
+
blockExplorerUrl: 'https://stellar.expert/explorer/public'
|
|
497
947
|
};
|
|
498
948
|
var DEFAULT_STELLAR_PROTOCOL_NETWORK = exports.STELLAR_MAINNET_PROTOCOL_NETWORK;
|
|
499
949
|
function createStellarProtocolOptions(network) {
|
|
@@ -503,9 +953,4 @@ function createStellarProtocolOptions(network) {
|
|
|
503
953
|
};
|
|
504
954
|
}
|
|
505
955
|
exports.createStellarProtocolOptions = createStellarProtocolOptions;
|
|
506
|
-
// function flattenArray(
|
|
507
|
-
// transactions: AirGapTransaction<StellarUnits>[][]
|
|
508
|
-
// ): AirGapTransaction<StellarUnits>[] | PromiseLike<AirGapTransaction<StellarUnits>[]> {
|
|
509
|
-
// throw new Error('Function not implemented.')
|
|
510
|
-
// }
|
|
511
956
|
//# sourceMappingURL=StellarProtocol.js.map
|