@airgap/stellar 0.13.41-beta.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/LICENSE.md +7 -0
- package/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +65 -0
- package/readme.md +121 -0
- package/v1/block-explorer/StellarBlockExplorer.d.ts +9 -0
- package/v1/block-explorer/StellarBlockExplorer.js +72 -0
- package/v1/block-explorer/StellarBlockExplorer.js.map +1 -0
- package/v1/data/StellarAddress.d.ts +9 -0
- package/v1/data/StellarAddress.js +30 -0
- package/v1/data/StellarAddress.js.map +1 -0
- package/v1/index.d.ts +13 -0
- package/v1/index.js +11 -0
- package/v1/index.js.map +1 -0
- package/v1/module/StellarModule.d.ts +17 -0
- package/v1/module/StellarModule.js +107 -0
- package/v1/module/StellarModule.js.map +1 -0
- package/v1/module.d.ts +3 -0
- package/v1/module.js +24 -0
- package/v1/module.js.map +1 -0
- package/v1/protocol/StellarCryptoClient.d.ts +8 -0
- package/v1/protocol/StellarCryptoClient.js +104 -0
- package/v1/protocol/StellarCryptoClient.js.map +1 -0
- package/v1/protocol/StellarProtocol.d.ts +42 -0
- package/v1/protocol/StellarProtocol.js +511 -0
- package/v1/protocol/StellarProtocol.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +42 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-stellar.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-stellar.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-stellar.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-stellar.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-stellar.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-stellar.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-stellar.json +29 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-stellar.json +19 -0
- package/v1/serializer/v3/serializer-companion.d.ts +14 -0
- package/v1/serializer/v3/serializer-companion.js +158 -0
- package/v1/serializer/v3/serializer-companion.js.map +1 -0
- package/v1/serializer/v3/validators/transaction-validator.d.ts +7 -0
- package/v1/serializer/v3/validators/transaction-validator.js +89 -0
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
- package/v1/serializer/v3/validators/validators.d.ts +6 -0
- package/v1/serializer/v3/validators/validators.js +92 -0
- package/v1/serializer/v3/validators/validators.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/protocol.d.ts +7 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/transaction.d.ts +10 -0
- package/v1/types/transaction.js +6 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/convert.d.ts +3 -0
- package/v1/utils/convert.js +32 -0
- package/v1/utils/convert.js.map +1 -0
- package/v1/utils/key.d.ts +3 -0
- package/v1/utils/key.js +37 -0
- package/v1/utils/key.js.map +1 -0
- package/v1/utils/signature.d.ts +2 -0
- package/v1/utils/signature.js +22 -0
- package/v1/utils/signature.js.map +1 -0
- package/v1/utils/transaction.d.ts +3 -0
- package/v1/utils/transaction.js +22 -0
- package/v1/utils/transaction.js.map +1 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.StellarCryptoClient = void 0;
|
|
55
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
56
|
+
var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
57
|
+
var Ed25519CryptoClient_1 = require("@airgap/coinlib-core/protocols/Ed25519CryptoClient");
|
|
58
|
+
var stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
59
|
+
var MESSAGE_PREFIX = 'Stellar Signed Message:\n';
|
|
60
|
+
var MAX_MESSAGE_LENGTH = 0xfd;
|
|
61
|
+
var prepareSignedMessage = function (message) {
|
|
62
|
+
var prefix = Buffer.from(MESSAGE_PREFIX, 'utf8');
|
|
63
|
+
var content = Buffer.from(message, 'utf8');
|
|
64
|
+
if (content.length >= MAX_MESSAGE_LENGTH) {
|
|
65
|
+
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.STELLAR, 'Message exceeds maximum length');
|
|
66
|
+
}
|
|
67
|
+
return Buffer.concat([Buffer.from([prefix.length]), prefix, Buffer.from([content.length]), content]);
|
|
68
|
+
};
|
|
69
|
+
var StellarCryptoClient = /** @class */ (function (_super) {
|
|
70
|
+
__extends(StellarCryptoClient, _super);
|
|
71
|
+
function StellarCryptoClient() {
|
|
72
|
+
return _super.call(this) || this;
|
|
73
|
+
}
|
|
74
|
+
StellarCryptoClient.prototype.signMessage = function (message, keypair) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var preparedMessage, kp, signature;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
preparedMessage = prepareSignedMessage(message);
|
|
79
|
+
if (!stellar_sdk_1.StrKey.isValidEd25519SecretSeed(keypair.privateKey)) {
|
|
80
|
+
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.STELLAR, 'Invalid Stellar secret key format');
|
|
81
|
+
}
|
|
82
|
+
kp = stellar_sdk_1.Keypair.fromSecret(keypair.privateKey);
|
|
83
|
+
signature = kp.sign(preparedMessage);
|
|
84
|
+
return [2 /*return*/, Buffer.from(signature).toString('hex')];
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
StellarCryptoClient.prototype.verifyMessage = function (message, signature, publicKey) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var preparedMessage, kp;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
preparedMessage = prepareSignedMessage(message);
|
|
93
|
+
if (!stellar_sdk_1.StrKey.isValidEd25519PublicKey(publicKey)) {
|
|
94
|
+
return [2 /*return*/, false];
|
|
95
|
+
}
|
|
96
|
+
kp = stellar_sdk_1.Keypair.fromPublicKey(publicKey);
|
|
97
|
+
return [2 /*return*/, kp.verify(preparedMessage, Buffer.from(signature, 'hex'))];
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
return StellarCryptoClient;
|
|
102
|
+
}(Ed25519CryptoClient_1.Ed25519CryptoClient));
|
|
103
|
+
exports.StellarCryptoClient = StellarCryptoClient;
|
|
104
|
+
//# sourceMappingURL=StellarCryptoClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StellarCryptoClient.js","sourceRoot":"","sources":["../../../src/v1/protocol/StellarCryptoClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA+D;AAC/D,2EAAkE;AAClE,0FAAwF;AACxF,oDAAsD;AAEtD,IAAM,cAAc,GAAG,2BAA2B,CAAA;AAClD,IAAM,kBAAkB,GAAG,IAAI,CAAA;AAE/B,IAAM,oBAAoB,GAAG,UAAC,OAAe;IAC3C,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;IAClD,IAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAE5C,IAAI,OAAO,CAAC,MAAM,IAAI,kBAAkB,EAAE;QACxC,MAAM,IAAI,0BAAiB,CAAC,sBAAM,CAAC,OAAO,EAAE,gCAAgC,CAAC,CAAA;KAC9E;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAA;AACtG,CAAC,CAAA;AAED;IAAyC,uCAAmB;IAC1D;eACE,iBAAO;IACT,CAAC;IAEY,yCAAW,GAAxB,UAAyB,OAAe,EAAE,OAA+B;;;;gBACjE,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAA;gBAErD,IAAI,CAAC,oBAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;oBACxD,MAAM,IAAI,0BAAiB,CAAC,sBAAM,CAAC,OAAO,EAAE,mCAAmC,CAAC,CAAA;iBACjF;gBAEK,EAAE,GAAG,qBAAO,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;gBAC3C,SAAS,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;gBAE1C,sBAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAA;;;KAC9C;IAEY,2CAAa,GAA1B,UAA2B,OAAe,EAAE,SAAiB,EAAE,SAAiB;;;;gBACxE,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAA;gBAErD,IAAI,CAAC,oBAAM,CAAC,uBAAuB,CAAC,SAAS,CAAC,EAAE;oBAC9C,sBAAO,KAAK,EAAA;iBACb;gBAEK,EAAE,GAAG,qBAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;gBAC3C,sBAAO,EAAE,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,EAAA;;;KACjE;IACH,0BAAC;AAAD,CAAC,AA5BD,CAAyC,yCAAmB,GA4B3D;AA5BY,kDAAmB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Address, AirGapProtocol, AirGapTransaction, Balance, CryptoDerivative, FeeDefaults, KeyPair, ProtocolMetadata, PublicKey, RecursivePartial, SecretKey, TransactionFullConfiguration, TransactionDetails, AirGapTransactionsWithCursor, Amount, TransactionSimpleConfiguration } from '@airgap/module-kit';
|
|
2
|
+
import { StellarCryptoConfiguration } from '../types/crypto';
|
|
3
|
+
import { StellarProtocolNetwork, StellarProtocolOptions, StellarUnits } from '../types/protocol';
|
|
4
|
+
import { StellarSignedTransaction, StellarTransactionCursor, StellarUnsignedTransaction } from '../types/transaction';
|
|
5
|
+
export interface StellarProtocol extends AirGapProtocol<{
|
|
6
|
+
AddressResult: Address;
|
|
7
|
+
ProtocolNetwork: StellarProtocolNetwork;
|
|
8
|
+
CryptoConfiguration: StellarCryptoConfiguration;
|
|
9
|
+
SignedTransaction: StellarSignedTransaction;
|
|
10
|
+
TransactionCursor: StellarTransactionCursor;
|
|
11
|
+
Units: StellarUnits;
|
|
12
|
+
FeeEstimation: FeeDefaults<StellarUnits>;
|
|
13
|
+
UnsignedTransaction: StellarUnsignedTransaction;
|
|
14
|
+
}, 'FetchDataForAddress'> {
|
|
15
|
+
}
|
|
16
|
+
export declare class StellarProtocolImpl implements StellarProtocol {
|
|
17
|
+
private readonly options;
|
|
18
|
+
constructor(options?: RecursivePartial<StellarProtocolOptions>);
|
|
19
|
+
getTransactionsForPublicKey(publicKey: PublicKey, limit: number, cursor?: StellarTransactionCursor | undefined): Promise<AirGapTransactionsWithCursor<StellarTransactionCursor, StellarUnits>>;
|
|
20
|
+
getTransactionsForAddress(address: Address, limit: number, cursor?: StellarTransactionCursor | undefined): Promise<AirGapTransactionsWithCursor<StellarTransactionCursor, StellarUnits>>;
|
|
21
|
+
getTransactionMaxAmountWithPublicKey(publicKey: PublicKey, to: Address[], configuration?: TransactionFullConfiguration<StellarUnits>): Promise<Amount<StellarUnits>>;
|
|
22
|
+
getTransactionFeeWithPublicKey(publicKey: PublicKey, details: TransactionDetails<StellarUnits>[], configuration?: TransactionSimpleConfiguration): Promise<FeeDefaults<StellarUnits>>;
|
|
23
|
+
private readonly units;
|
|
24
|
+
private readonly feeDefaults;
|
|
25
|
+
private readonly metadata;
|
|
26
|
+
getMetadata(): Promise<ProtocolMetadata<StellarUnits>>;
|
|
27
|
+
getAddressFromPublicKey(publicKey: PublicKey): Promise<string>;
|
|
28
|
+
getDetailsFromTransaction(transaction: StellarSignedTransaction | StellarUnsignedTransaction, _publicKey: PublicKey): Promise<AirGapTransaction<StellarUnits>[]>;
|
|
29
|
+
private getDetailsFromEncodedTransaction;
|
|
30
|
+
private readonly cryptoConfiguration;
|
|
31
|
+
getCryptoConfiguration(): Promise<StellarCryptoConfiguration>;
|
|
32
|
+
getKeyPairFromDerivative(derivative: CryptoDerivative): Promise<KeyPair>;
|
|
33
|
+
signTransactionWithSecretKey(transaction: StellarUnsignedTransaction, secretKey: SecretKey): Promise<StellarSignedTransaction>;
|
|
34
|
+
getNetwork(): Promise<StellarProtocolNetwork>;
|
|
35
|
+
getBalanceOfPublicKey(publicKey: PublicKey): Promise<Balance<StellarUnits>>;
|
|
36
|
+
getBalanceOfAddress(address: string): Promise<Balance<StellarUnits>>;
|
|
37
|
+
prepareTransactionWithPublicKey(publicKey: PublicKey, details: TransactionDetails<StellarUnits>[], configuration?: TransactionFullConfiguration<StellarUnits>): Promise<StellarUnsignedTransaction>;
|
|
38
|
+
broadcastTransaction(transaction: StellarSignedTransaction): Promise<string>;
|
|
39
|
+
}
|
|
40
|
+
export declare function createStellarProtocol(options?: RecursivePartial<StellarProtocolOptions>): StellarProtocol;
|
|
41
|
+
export declare const STELLAR_MAINNET_PROTOCOL_NETWORK: StellarProtocolNetwork;
|
|
42
|
+
export declare function createStellarProtocolOptions(network?: Partial<StellarProtocolNetwork>): StellarProtocolOptions;
|
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.createStellarProtocolOptions = exports.STELLAR_MAINNET_PROTOCOL_NETWORK = exports.createStellarProtocol = exports.StellarProtocolImpl = void 0;
|
|
54
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
55
|
+
var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
56
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
57
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
58
|
+
var stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
59
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
60
|
+
var StellarAddress_1 = require("../data/StellarAddress");
|
|
61
|
+
var StellarProtocolImpl = /** @class */ (function () {
|
|
62
|
+
function StellarProtocolImpl(options) {
|
|
63
|
+
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
|
+
this.units = {
|
|
102
|
+
XLM: {
|
|
103
|
+
symbol: { value: 'XLM', market: 'xlm' },
|
|
104
|
+
decimals: 7
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
this.feeDefaults = {
|
|
108
|
+
low: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, 'XLM').blockchain(this.units),
|
|
109
|
+
medium: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, 'XLM').blockchain(this.units),
|
|
110
|
+
high: (0, module_kit_1.newAmount)(stellar_sdk_1.BASE_FEE, 'XLM').blockchain(this.units)
|
|
111
|
+
};
|
|
112
|
+
this.metadata = {
|
|
113
|
+
identifier: coinlib_core_1.MainProtocolSymbols.XLM,
|
|
114
|
+
name: 'Stellar',
|
|
115
|
+
units: this.units,
|
|
116
|
+
mainUnit: 'XLM',
|
|
117
|
+
fee: {
|
|
118
|
+
defaults: this.feeDefaults
|
|
119
|
+
},
|
|
120
|
+
account: {
|
|
121
|
+
standardDerivationPath: "m/44h/148h/0h",
|
|
122
|
+
address: {
|
|
123
|
+
isCaseSensitive: false,
|
|
124
|
+
placeholder: 'GABC...',
|
|
125
|
+
regex: '^G[0-9A-Z]{55}$'
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
transaction: {
|
|
129
|
+
arbitraryData: {
|
|
130
|
+
inner: { name: 'memo' }
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
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
|
+
this.cryptoConfiguration = {
|
|
139
|
+
algorithm: 'ed25519'
|
|
140
|
+
};
|
|
141
|
+
this.options = createStellarProtocolOptions(options.network);
|
|
142
|
+
// this.cryptoClient = new StellarCryptoClient()
|
|
143
|
+
}
|
|
144
|
+
StellarProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var address;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
switch (_a.label) {
|
|
149
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
150
|
+
case 1:
|
|
151
|
+
address = _a.sent();
|
|
152
|
+
return [2 /*return*/, this.getTransactionsForAddress(address, limit, cursor)];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
StellarProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
|
|
158
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
var endpoint, url, response, data, paymentTransactions, transactions, error_1;
|
|
161
|
+
var _this = this;
|
|
162
|
+
return __generator(this, function (_l) {
|
|
163
|
+
switch (_l.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
_l.trys.push([0, 2, , 3]);
|
|
166
|
+
endpoint = (_a = cursor === null || cursor === void 0 ? void 0 : cursor.next) !== null && _a !== void 0 ? _a : "/accounts/".concat(address, "/payments?limit=").concat(limit, "&order=desc&join=transactions");
|
|
167
|
+
url = "".concat(this.options.network.rpcUrl).concat(endpoint);
|
|
168
|
+
return [4 /*yield*/, index_1.default.get(url)];
|
|
169
|
+
case 1:
|
|
170
|
+
response = _l.sent();
|
|
171
|
+
data = response.data;
|
|
172
|
+
paymentTransactions = (_c = (_b = data._embedded) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : [];
|
|
173
|
+
transactions = paymentTransactions
|
|
174
|
+
.filter(function (tx) { return tx.type === 'payment'; })
|
|
175
|
+
.map(function (tx) {
|
|
176
|
+
var txData = tx.transaction;
|
|
177
|
+
return {
|
|
178
|
+
from: [tx.from],
|
|
179
|
+
to: [tx.to],
|
|
180
|
+
isInbound: tx.to.toLowerCase() === address.toLowerCase(),
|
|
181
|
+
amount: (0, module_kit_1.newAmount)(tx.amount, 'blockchain'),
|
|
182
|
+
fee: (0, module_kit_1.newAmount)((parseInt(txData.fee_charged) / 10000000).toFixed(7), 'blockchain'),
|
|
183
|
+
network: _this.options.network,
|
|
184
|
+
timestamp: new Date(tx.created_at).getTime(),
|
|
185
|
+
status: {
|
|
186
|
+
type: tx.transaction_successful ? 'applied' : 'failed',
|
|
187
|
+
hash: tx.transaction_hash,
|
|
188
|
+
block: txData.ledger.toString()
|
|
189
|
+
},
|
|
190
|
+
arbitraryData: txData.memo_type === 'text'
|
|
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
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
return [2 /*return*/, {
|
|
200
|
+
transactions: transactions,
|
|
201
|
+
cursor: {
|
|
202
|
+
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 : ''
|
|
204
|
+
}
|
|
205
|
+
}];
|
|
206
|
+
case 2:
|
|
207
|
+
error_1 = _l.sent();
|
|
208
|
+
if (((_k = error_1.response) === null || _k === void 0 ? void 0 : _k.status) === 404) {
|
|
209
|
+
return [2 /*return*/, {
|
|
210
|
+
transactions: [],
|
|
211
|
+
cursor: {
|
|
212
|
+
hasNext: false,
|
|
213
|
+
next: ''
|
|
214
|
+
}
|
|
215
|
+
}];
|
|
216
|
+
}
|
|
217
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_1);
|
|
218
|
+
case 3: return [2 /*return*/];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
StellarProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
+
var balance, balanceBn, fee, amountWithoutFees, error_2;
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
switch (_a.label) {
|
|
228
|
+
case 0:
|
|
229
|
+
_a.trys.push([0, 2, , 3]);
|
|
230
|
+
return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
231
|
+
case 1:
|
|
232
|
+
balance = _a.sent();
|
|
233
|
+
balanceBn = new bignumber_1.default(balance.total.value || '0');
|
|
234
|
+
fee = void 0;
|
|
235
|
+
if ((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined) {
|
|
236
|
+
fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
fee = new bignumber_1.default(to.length * Number(stellar_sdk_1.BASE_FEE)).dividedBy(10000000);
|
|
240
|
+
}
|
|
241
|
+
if (fee.gte(balanceBn)) {
|
|
242
|
+
fee = new bignumber_1.default(0);
|
|
243
|
+
}
|
|
244
|
+
amountWithoutFees = balanceBn.minus(fee);
|
|
245
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees.toFixed(), 'blockchain')];
|
|
246
|
+
case 2:
|
|
247
|
+
error_2 = _a.sent();
|
|
248
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.STELLAR, error_2);
|
|
249
|
+
case 3: return [2 /*return*/];
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
StellarProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details, configuration) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
return [2 /*return*/, this.feeDefaults];
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
StellarProtocolImpl.prototype.getMetadata = function () {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
return [2 /*return*/, this.metadata];
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
StellarProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
return [2 /*return*/, StellarAddress_1.StellarAddress.from(publicKey).asString()];
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
StellarProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, _publicKey) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
return __generator(this, function (_a) {
|
|
278
|
+
switch (transaction.type) {
|
|
279
|
+
case 'signed':
|
|
280
|
+
return [2 /*return*/, this.getDetailsFromEncodedTransaction(transaction.transaction, _publicKey)];
|
|
281
|
+
case 'unsigned':
|
|
282
|
+
return [2 /*return*/, this.getDetailsFromEncodedTransaction(transaction.transaction, _publicKey)];
|
|
283
|
+
default:
|
|
284
|
+
(0, coinlib_core_1.assertNever)(transaction);
|
|
285
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.STELLAR, 'Unsupported transaction type.');
|
|
286
|
+
}
|
|
287
|
+
return [2 /*return*/];
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
StellarProtocolImpl.prototype.getDetailsFromEncodedTransaction = function (transaction, publicKey) {
|
|
292
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
293
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
294
|
+
var transactions, tx, op, isInbound, feeXLM, memoText;
|
|
295
|
+
return __generator(this, function (_h) {
|
|
296
|
+
transactions = [];
|
|
297
|
+
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction, stellar_sdk_1.Networks.TESTNET);
|
|
298
|
+
op = tx.operations[0];
|
|
299
|
+
isInbound = ((_a = op.source) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === publicKey.value.toLowerCase();
|
|
300
|
+
feeXLM = (parseInt(tx.fee) / 1e7).toFixed(7);
|
|
301
|
+
memoText = ((_b = tx.memo) === null || _b === void 0 ? void 0 : _b.type) === 'text'
|
|
302
|
+
? (_c = tx.memo.value) === null || _c === void 0 ? void 0 : _c.toString()
|
|
303
|
+
: ((_d = tx.memo) === null || _d === void 0 ? void 0 : _d.type) === 'hash'
|
|
304
|
+
? "Hash: ".concat((_e = tx.memo.value) === null || _e === void 0 ? void 0 : _e.toString('hex'))
|
|
305
|
+
: ((_f = tx.memo) === null || _f === void 0 ? void 0 : _f.type) === 'id'
|
|
306
|
+
? "ID: ".concat((_g = tx.memo.value) === null || _g === void 0 ? void 0 : _g.toString())
|
|
307
|
+
: undefined;
|
|
308
|
+
transactions.push({
|
|
309
|
+
from: [tx.source],
|
|
310
|
+
to: [op.source || ''],
|
|
311
|
+
isInbound: isInbound,
|
|
312
|
+
amount: (0, module_kit_1.newAmount)(op.amount, 'blockchain'),
|
|
313
|
+
fee: (0, module_kit_1.newAmount)(feeXLM, 'blockchain'),
|
|
314
|
+
network: this.options.network,
|
|
315
|
+
arbitraryData: memoText
|
|
316
|
+
});
|
|
317
|
+
return [2 /*return*/, transactions];
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
StellarProtocolImpl.prototype.getCryptoConfiguration = function () {
|
|
322
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
323
|
+
return __generator(this, function (_a) {
|
|
324
|
+
return [2 /*return*/, this.cryptoConfiguration];
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
StellarProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
330
|
+
return __generator(this, function (_a) {
|
|
331
|
+
return [2 /*return*/, {
|
|
332
|
+
secretKey: (0, module_kit_1.newSecretKey)(derivative.secretKey, 'hex'),
|
|
333
|
+
publicKey: (0, module_kit_1.newPublicKey)(derivative.publicKey, 'hex')
|
|
334
|
+
}];
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
StellarProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
|
|
339
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
340
|
+
var tx, keyPair;
|
|
341
|
+
return __generator(this, function (_a) {
|
|
342
|
+
tx = stellar_sdk_1.TransactionBuilder.fromXDR(transaction.transaction, stellar_sdk_1.Networks.TESTNET);
|
|
343
|
+
keyPair = stellar_sdk_1.Keypair.fromSecret(secretKey.value);
|
|
344
|
+
tx.sign(keyPair);
|
|
345
|
+
return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({
|
|
346
|
+
transaction: tx.toXDR()
|
|
347
|
+
})];
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
};
|
|
351
|
+
StellarProtocolImpl.prototype.getNetwork = function () {
|
|
352
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
353
|
+
return __generator(this, function (_a) {
|
|
354
|
+
return [2 /*return*/, this.options.network];
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
StellarProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
360
|
+
var address;
|
|
361
|
+
return __generator(this, function (_a) {
|
|
362
|
+
switch (_a.label) {
|
|
363
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
364
|
+
case 1:
|
|
365
|
+
address = _a.sent();
|
|
366
|
+
return [2 /*return*/, this.getBalanceOfAddress(address)];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
StellarProtocolImpl.prototype.getBalanceOfAddress = function (address) {
|
|
372
|
+
var _a;
|
|
373
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
+
var data, balance, error_3;
|
|
375
|
+
return __generator(this, function (_b) {
|
|
376
|
+
switch (_b.label) {
|
|
377
|
+
case 0:
|
|
378
|
+
_b.trys.push([0, 2, , 3]);
|
|
379
|
+
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/accounts/").concat(address))];
|
|
380
|
+
case 1:
|
|
381
|
+
data = (_b.sent()).data;
|
|
382
|
+
balance = data.balances.find(function (b) { return b.asset_type === 'native'; });
|
|
383
|
+
return [2 /*return*/, {
|
|
384
|
+
total: (0, module_kit_1.newAmount)(balance.balance, 'blockchain')
|
|
385
|
+
}];
|
|
386
|
+
case 2:
|
|
387
|
+
error_3 = _b.sent();
|
|
388
|
+
if (((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
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);
|
|
392
|
+
case 3: return [2 /*return*/];
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
};
|
|
397
|
+
StellarProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
|
|
398
|
+
var _a;
|
|
399
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
400
|
+
var server, account, txBuilder, _i, details_1, detail, destinationExists, e_1, tx;
|
|
401
|
+
return __generator(this, function (_b) {
|
|
402
|
+
switch (_b.label) {
|
|
403
|
+
case 0:
|
|
404
|
+
server = new stellar_sdk_1.Horizon.Server(this.options.network.rpcUrl);
|
|
405
|
+
return [4 /*yield*/, server.loadAccount(publicKey.value)];
|
|
406
|
+
case 1:
|
|
407
|
+
account = _b.sent();
|
|
408
|
+
txBuilder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
409
|
+
fee: stellar_sdk_1.BASE_FEE,
|
|
410
|
+
networkPassphrase: stellar_sdk_1.Networks.TESTNET
|
|
411
|
+
});
|
|
412
|
+
_i = 0, details_1 = details;
|
|
413
|
+
_b.label = 2;
|
|
414
|
+
case 2:
|
|
415
|
+
if (!(_i < details_1.length)) return [3 /*break*/, 8];
|
|
416
|
+
detail = details_1[_i];
|
|
417
|
+
destinationExists = true;
|
|
418
|
+
_b.label = 3;
|
|
419
|
+
case 3:
|
|
420
|
+
_b.trys.push([3, 5, , 6]);
|
|
421
|
+
return [4 /*yield*/, server.loadAccount(detail.to)];
|
|
422
|
+
case 4:
|
|
423
|
+
_b.sent();
|
|
424
|
+
return [3 /*break*/, 6];
|
|
425
|
+
case 5:
|
|
426
|
+
e_1 = _b.sent();
|
|
427
|
+
if (((_a = e_1.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
428
|
+
destinationExists = false;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
throw e_1;
|
|
432
|
+
}
|
|
433
|
+
return [3 /*break*/, 6];
|
|
434
|
+
case 6:
|
|
435
|
+
if (destinationExists) {
|
|
436
|
+
txBuilder.addOperation(stellar_sdk_1.Operation.payment({
|
|
437
|
+
destination: detail.to,
|
|
438
|
+
asset: stellar_sdk_1.Asset.native(),
|
|
439
|
+
amount: (0, module_kit_1.newAmount)(detail.amount).blockchain(this.units).value
|
|
440
|
+
}));
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
txBuilder.addOperation(stellar_sdk_1.Operation.createAccount({
|
|
444
|
+
destination: detail.to,
|
|
445
|
+
startingBalance: (0, module_kit_1.newAmount)(detail.amount).blockchain(this.units).value
|
|
446
|
+
}));
|
|
447
|
+
}
|
|
448
|
+
_b.label = 7;
|
|
449
|
+
case 7:
|
|
450
|
+
_i++;
|
|
451
|
+
return [3 /*break*/, 2];
|
|
452
|
+
case 8:
|
|
453
|
+
if (configuration === null || configuration === void 0 ? void 0 : configuration.arbitraryData) {
|
|
454
|
+
txBuilder.addMemo(stellar_sdk_1.Memo.text(configuration.arbitraryData));
|
|
455
|
+
}
|
|
456
|
+
tx = txBuilder.setTimeout(30).build();
|
|
457
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
458
|
+
transaction: tx.toXDR()
|
|
459
|
+
})];
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
};
|
|
464
|
+
StellarProtocolImpl.prototype.broadcastTransaction = function (transaction) {
|
|
465
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
466
|
+
var params, data;
|
|
467
|
+
return __generator(this, function (_a) {
|
|
468
|
+
switch (_a.label) {
|
|
469
|
+
case 0:
|
|
470
|
+
params = new URLSearchParams();
|
|
471
|
+
params.append('tx', transaction.transaction);
|
|
472
|
+
return [4 /*yield*/, index_1.default.post("".concat(this.options.network.rpcUrl, "/transactions"), params.toString(), {
|
|
473
|
+
headers: {
|
|
474
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
475
|
+
}
|
|
476
|
+
})];
|
|
477
|
+
case 1:
|
|
478
|
+
data = (_a.sent()).data;
|
|
479
|
+
return [2 /*return*/, data.hash];
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
return StellarProtocolImpl;
|
|
485
|
+
}());
|
|
486
|
+
exports.StellarProtocolImpl = StellarProtocolImpl;
|
|
487
|
+
function createStellarProtocol(options) {
|
|
488
|
+
if (options === void 0) { options = {}; }
|
|
489
|
+
return new StellarProtocolImpl(options);
|
|
490
|
+
}
|
|
491
|
+
exports.createStellarProtocol = createStellarProtocol;
|
|
492
|
+
exports.STELLAR_MAINNET_PROTOCOL_NETWORK = {
|
|
493
|
+
name: 'Mainnet',
|
|
494
|
+
type: 'mainnet',
|
|
495
|
+
rpcUrl: 'https://horizon-testnet.stellar.org',
|
|
496
|
+
blockExplorerUrl: 'https://stellar.expert/explorer/testnet'
|
|
497
|
+
};
|
|
498
|
+
var DEFAULT_STELLAR_PROTOCOL_NETWORK = exports.STELLAR_MAINNET_PROTOCOL_NETWORK;
|
|
499
|
+
function createStellarProtocolOptions(network) {
|
|
500
|
+
if (network === void 0) { network = {}; }
|
|
501
|
+
return {
|
|
502
|
+
network: __assign(__assign({}, DEFAULT_STELLAR_PROTOCOL_NETWORK), network)
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
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
|
+
//# sourceMappingURL=StellarProtocol.js.map
|