@tatumio/egld 2.0.1-alpha.248
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 +22 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +5 -0
- package/src/constants.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/egld.sdk.d.ts +113 -0
- package/src/lib/egld.sdk.js +31 -0
- package/src/lib/egld.sdk.js.map +1 -0
- package/src/lib/egld.utils.d.ts +22 -0
- package/src/lib/egld.utils.js +139 -0
- package/src/lib/egld.utils.js.map +1 -0
- package/src/lib/services/egld.kms.d.ts +10 -0
- package/src/lib/services/egld.kms.js +16 -0
- package/src/lib/services/egld.kms.js.map +1 -0
- package/src/lib/services/egld.offchain.d.ts +34 -0
- package/src/lib/services/egld.offchain.js +62 -0
- package/src/lib/services/egld.offchain.js.map +1 -0
- package/src/lib/services/egld.record.d.ts +17 -0
- package/src/lib/services/egld.record.js +22 -0
- package/src/lib/services/egld.record.js.map +1 -0
- package/src/lib/services/egld.tx.d.ts +100 -0
- package/src/lib/services/egld.tx.js +250 -0
- package/src/lib/services/egld.tx.js.map +1 -0
- package/src/lib/services/egld.wallet.d.ts +31 -0
- package/src/lib/services/egld.wallet.js +66 -0
- package/src/lib/services/egld.wallet.js.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tatumio/egld",
|
|
3
|
+
"version": "2.0.1-alpha.248",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"typings": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@tatumio/api-client": "2.0.1-alpha.248",
|
|
9
|
+
"axios": "^0.26.0",
|
|
10
|
+
"form-data": "^4.0.0",
|
|
11
|
+
"@tatumio/shared-testing-common": "2.0.1-alpha.248",
|
|
12
|
+
"@tatumio/shared-core": "2.0.1-alpha.248",
|
|
13
|
+
"@tatumio/shared-abstract-sdk": "2.0.1-alpha.248",
|
|
14
|
+
"bignumber.js": "^9.0.2",
|
|
15
|
+
"@tatumio/shared-blockchain-abstract": "2.0.1-alpha.248",
|
|
16
|
+
"ed25519-hd-key": "^1.2.0",
|
|
17
|
+
"web3-core": "^1.7.0",
|
|
18
|
+
"@elrondnetwork/erdjs": "^9.2.4",
|
|
19
|
+
"bip39": "^3.0.2"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ESDT_SYSTEM_SMART_CONTRACT_ADDRESS = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u";
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ESDT_SYSTEM_SMART_CONTRACT_ADDRESS = void 0;
|
|
4
|
+
exports.ESDT_SYSTEM_SMART_CONTRACT_ADDRESS = 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u';
|
|
5
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/blockchain/egld/src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,kCAAkC,GAC7C,gEAAgE,CAAA"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/egld.sdk';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/blockchain/egld/src/index.ts"],"names":[],"mappings":";;;AAAA,8DAA8B"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { SDKArguments } from '@tatumio/shared-abstract-sdk';
|
|
2
|
+
import { BlockchainElrondNetworkEgldService } from '@tatumio/api-client';
|
|
3
|
+
export declare const TatumEgldSDK: (args: SDKArguments) => {
|
|
4
|
+
record: {
|
|
5
|
+
getLog(id: string): import("@tatumio/api-client").CancelablePromise<{
|
|
6
|
+
data: string;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
wallet: {
|
|
10
|
+
generateBlockchainWallet: (mnem: string) => Promise<import("@tatumio/api-client").Wallet>;
|
|
11
|
+
generateWallet: (mnemonic?: string) => import("@tatumio/api-client").CancelablePromise<{
|
|
12
|
+
mnemonic?: string;
|
|
13
|
+
}>;
|
|
14
|
+
generatePrivateKeyFromMnemonic: (testnet: boolean, mnemonic: string, i: number) => Promise<string>;
|
|
15
|
+
generateAddress: (testnet: boolean, mnemonic: string, i: number) => Promise<string>;
|
|
16
|
+
};
|
|
17
|
+
transaction: {
|
|
18
|
+
prepare: {
|
|
19
|
+
deploy: (body: import("./egld.utils").TransferEgld) => Promise<string>;
|
|
20
|
+
signedTransaction: (body: import("./egld.utils").TransferEgld) => Promise<string>;
|
|
21
|
+
smartContractMethodInvocation: (body: import("./egld.utils").TransferEgld) => Promise<string>;
|
|
22
|
+
transferNft: (body: import("./egld.utils").TransferEgld) => Promise<string>;
|
|
23
|
+
deployNft: (body: import("./egld.utils").TransferEgld) => Promise<string>;
|
|
24
|
+
};
|
|
25
|
+
send: {
|
|
26
|
+
deploy: (body: import("./egld.utils").TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
27
|
+
signedTransaction: (body: import("./egld.utils").TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
28
|
+
smartContractMethodInvocation: (body: import("./egld.utils").TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
29
|
+
transferNft: (body: import("./egld.utils").TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
30
|
+
deployNft: (body: import("./egld.utils").TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
offchain: {
|
|
34
|
+
send: (body: import("@tatumio/api-client").TransferEth | import("@tatumio/api-client").TransferEthMnemonic | import("@tatumio/api-client").TransferEthKMS) => Promise<void | import("@tatumio/api-client").OffchainTransactionResult | import("@tatumio/api-client").OffchainTransactionSignatureResult | {
|
|
35
|
+
id?: string;
|
|
36
|
+
}>;
|
|
37
|
+
depositAddress: {
|
|
38
|
+
checkExists: (address: string, index?: number) => Promise<any>;
|
|
39
|
+
create: any;
|
|
40
|
+
createMultiple: any;
|
|
41
|
+
assign: any;
|
|
42
|
+
remove: any;
|
|
43
|
+
getByAccount: any;
|
|
44
|
+
};
|
|
45
|
+
withdrawal: {
|
|
46
|
+
getAll: (status?: "InProgress" | "Done" | "Cancelled", pageSize?: number, offset?: number) => Promise<any[]>;
|
|
47
|
+
broadcast: any;
|
|
48
|
+
create: any;
|
|
49
|
+
complete: any;
|
|
50
|
+
};
|
|
51
|
+
storeTokenAddress: any;
|
|
52
|
+
};
|
|
53
|
+
kms: {
|
|
54
|
+
sign(tx: import("@tatumio/shared-core").ChainTransactionKMS, fromPrivateKey: string): Promise<string>;
|
|
55
|
+
getAllPending(signatures?: string): import("@tatumio/api-client").CancelablePromise<import("@tatumio/api-client").PendingTransaction[]>;
|
|
56
|
+
get: typeof import("@tatumio/api-client").SecurityKeyManagementSystemService.getPendingTransactionToSign;
|
|
57
|
+
complete: typeof import("@tatumio/api-client").SecurityKeyManagementSystemService.completePendingSignature;
|
|
58
|
+
delete: typeof import("@tatumio/api-client").SecurityKeyManagementSystemService.deletePendingTransactionToSign;
|
|
59
|
+
};
|
|
60
|
+
blockchain: {
|
|
61
|
+
broadcast: typeof BlockchainElrondNetworkEgldService.egldBroadcast;
|
|
62
|
+
getBlock: typeof BlockchainElrondNetworkEgldService.egldGetBlock;
|
|
63
|
+
getCurrentBlock: typeof BlockchainElrondNetworkEgldService.eGldGetCurrentBlock;
|
|
64
|
+
generateWallet: typeof BlockchainElrondNetworkEgldService.egldGenerateWallet;
|
|
65
|
+
generateAddress: typeof BlockchainElrondNetworkEgldService.egldGenerateAddress;
|
|
66
|
+
generatePrivateKeyOfAddress: typeof BlockchainElrondNetworkEgldService.egldGenerateAddressPrivateKey;
|
|
67
|
+
getBalance: typeof BlockchainElrondNetworkEgldService.egldGetBalance;
|
|
68
|
+
getTransaction: typeof BlockchainElrondNetworkEgldService.egldGetTransaction;
|
|
69
|
+
getTransactionsSentFromAddress: typeof BlockchainElrondNetworkEgldService.egldGetTransactionAddress;
|
|
70
|
+
getCountOfTransactionSentFromAddress: typeof BlockchainElrondNetworkEgldService.egldGetTransactionCount;
|
|
71
|
+
};
|
|
72
|
+
node: {
|
|
73
|
+
post: typeof BlockchainElrondNetworkEgldService.egldNodePost;
|
|
74
|
+
get: typeof BlockchainElrondNetworkEgldService.egldNodeGet;
|
|
75
|
+
};
|
|
76
|
+
getExchangeRate(basePair?: import("@tatumio/api-client").Fiat): import("@tatumio/api-client").CancelablePromise<import("@tatumio/api-client").ExchangeRate>;
|
|
77
|
+
storage: {
|
|
78
|
+
upload: typeof import("@tatumio/api-client").StorageIpfsService.storeIpfs;
|
|
79
|
+
get: typeof import("@tatumio/api-client").StorageIpfsService.getIpfsData;
|
|
80
|
+
};
|
|
81
|
+
subscriptions: typeof import("@tatumio/api-client").LedgerSubscriptionService;
|
|
82
|
+
security: {
|
|
83
|
+
checkMaliciousAddress: typeof import("@tatumio/api-client").SecurityAddressService.checkMalicousAddress;
|
|
84
|
+
};
|
|
85
|
+
tatum: {
|
|
86
|
+
getCredits: typeof import("@tatumio/api-client").TatumServiceService.getCredits;
|
|
87
|
+
getVersion: typeof import("@tatumio/api-client").TatumServiceService.getVersion;
|
|
88
|
+
freezeApiKey: typeof import("@tatumio/api-client").TatumServiceService.freezeApiKey;
|
|
89
|
+
unfreezeApiKey: typeof import("@tatumio/api-client").TatumServiceService.unfreezeApiKey;
|
|
90
|
+
};
|
|
91
|
+
nft: {
|
|
92
|
+
deployNFTSmartContract: typeof import("@tatumio/api-client").BlockchainNftService.nftDeployErc721;
|
|
93
|
+
addNFTMinter: typeof import("@tatumio/api-client").BlockchainNftService.nftAddMinter;
|
|
94
|
+
mintNFT: typeof import("@tatumio/api-client").BlockchainNftService.nftMintErc721;
|
|
95
|
+
mintMultipleNFTs: typeof import("@tatumio/api-client").BlockchainNftService.nftMintMultipleErc721;
|
|
96
|
+
burnNFT: typeof import("@tatumio/api-client").BlockchainNftService.nftBurnErc721;
|
|
97
|
+
transferNFT: typeof import("@tatumio/api-client").BlockchainNftService.nftTransferErc721;
|
|
98
|
+
updateNFTRoyalty: typeof import("@tatumio/api-client").BlockchainNftService.nftUpdateCashbackErc721;
|
|
99
|
+
getNFTTransaction: typeof import("@tatumio/api-client").BlockchainNftService.nftGetTransactErc721;
|
|
100
|
+
getNFTTransactionsByToken: typeof import("@tatumio/api-client").BlockchainNftService.nftGetTransactionByToken;
|
|
101
|
+
getNFTTransactionsByAddress: typeof import("@tatumio/api-client").BlockchainNftService.nftGetTransactionByAddress;
|
|
102
|
+
getNFTsByAddress: typeof import("@tatumio/api-client").BlockchainNftService.nftGetTokensByAddressErc721;
|
|
103
|
+
getNFTProvenanceData: typeof import("@tatumio/api-client").BlockchainNftService.nftGetProvenanceDataErc721;
|
|
104
|
+
getNFTMetadataURI: typeof import("@tatumio/api-client").BlockchainNftService.nftGetMetadataErc721;
|
|
105
|
+
getNFTRoyalty: typeof import("@tatumio/api-client").BlockchainNftService.nftGetRoyaltyErc721;
|
|
106
|
+
getNFTAccountBalance: typeof import("@tatumio/api-client").BlockchainNftService.nftGetBalanceErc721;
|
|
107
|
+
getNFTImage: (chain: "ETH" | "BSC" | "MATIC" | "CELO" | "FLOW" | "TRON" | "ONE" | "KLAY" | "SOL" | "KCS", contractAddress: string, tokenId: string, account?: string) => Promise<{
|
|
108
|
+
originalUrl: string;
|
|
109
|
+
publicUrl: string;
|
|
110
|
+
}>;
|
|
111
|
+
prepareAddNftMinterAbstraction: (body: import("@tatumio/api-client").AddNftMinter | import("@tatumio/api-client").AddNftMinterKMS) => string[];
|
|
112
|
+
};
|
|
113
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TatumEgldSDK = void 0;
|
|
4
|
+
const shared_core_1 = require("@tatumio/shared-core");
|
|
5
|
+
const shared_blockchain_abstract_1 = require("@tatumio/shared-blockchain-abstract");
|
|
6
|
+
const api_client_1 = require("@tatumio/api-client");
|
|
7
|
+
const egld_record_1 = require("./services/egld.record");
|
|
8
|
+
const egld_wallet_1 = require("./services/egld.wallet");
|
|
9
|
+
const egld_tx_1 = require("./services/egld.tx");
|
|
10
|
+
const egld_offchain_1 = require("./services/egld.offchain");
|
|
11
|
+
const egld_kms_1 = require("./services/egld.kms");
|
|
12
|
+
const blockchain = shared_core_1.Blockchain.EGLD;
|
|
13
|
+
const TatumEgldSDK = (args) => {
|
|
14
|
+
return Object.assign(Object.assign({}, (0, shared_blockchain_abstract_1.abstractBlockchainSdk)(Object.assign(Object.assign({}, args), { blockchain }))), { record: (0, egld_record_1.egldRecord)(), wallet: (0, egld_wallet_1.egldWallet)(), transaction: (0, egld_tx_1.egldTransactionService)(), offchain: (0, egld_offchain_1.egldOffchainService)({ blockchain }), kms: (0, egld_kms_1.egldKmsService)({ blockchain }), blockchain: {
|
|
15
|
+
broadcast: api_client_1.BlockchainElrondNetworkEgldService.egldBroadcast,
|
|
16
|
+
getBlock: api_client_1.BlockchainElrondNetworkEgldService.egldGetBlock,
|
|
17
|
+
getCurrentBlock: api_client_1.BlockchainElrondNetworkEgldService.eGldGetCurrentBlock,
|
|
18
|
+
generateWallet: api_client_1.BlockchainElrondNetworkEgldService.egldGenerateWallet,
|
|
19
|
+
generateAddress: api_client_1.BlockchainElrondNetworkEgldService.egldGenerateAddress,
|
|
20
|
+
generatePrivateKeyOfAddress: api_client_1.BlockchainElrondNetworkEgldService.egldGenerateAddressPrivateKey,
|
|
21
|
+
getBalance: api_client_1.BlockchainElrondNetworkEgldService.egldGetBalance,
|
|
22
|
+
getTransaction: api_client_1.BlockchainElrondNetworkEgldService.egldGetTransaction,
|
|
23
|
+
getTransactionsSentFromAddress: api_client_1.BlockchainElrondNetworkEgldService.egldGetTransactionAddress,
|
|
24
|
+
getCountOfTransactionSentFromAddress: api_client_1.BlockchainElrondNetworkEgldService.egldGetTransactionCount,
|
|
25
|
+
}, node: {
|
|
26
|
+
post: api_client_1.BlockchainElrondNetworkEgldService.egldNodePost,
|
|
27
|
+
get: api_client_1.BlockchainElrondNetworkEgldService.egldNodeGet,
|
|
28
|
+
} });
|
|
29
|
+
};
|
|
30
|
+
exports.TatumEgldSDK = TatumEgldSDK;
|
|
31
|
+
//# sourceMappingURL=egld.sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egld.sdk.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/egld/src/lib/egld.sdk.ts"],"names":[],"mappings":";;;AAAA,sDAAiD;AAEjD,oFAA2E;AAC3E,oDAAwE;AACxE,wDAAmD;AACnD,wDAAmD;AACnD,gDAA2D;AAC3D,4DAA8D;AAC9D,kDAAoD;AAEpD,MAAM,UAAU,GAAG,wBAAU,CAAC,IAAI,CAAA;AAE3B,MAAM,YAAY,GAAG,CAAC,IAAkB,EAAE,EAAE;IACjD,uCACK,IAAA,kDAAqB,kCAAM,IAAI,KAAE,UAAU,IAAG,KACjD,MAAM,EAAE,IAAA,wBAAU,GAAE,EACpB,MAAM,EAAE,IAAA,wBAAU,GAAE,EACpB,WAAW,EAAE,IAAA,gCAAsB,GAAE,EACrC,QAAQ,EAAE,IAAA,mCAAmB,EAAC,EAAE,UAAU,EAAE,CAAC,EAC7C,GAAG,EAAE,IAAA,yBAAc,EAAC,EAAE,UAAU,EAAE,CAAC,EACnC,UAAU,EAAE;YACV,SAAS,EAAE,+CAAkC,CAAC,aAAa;YAC3D,QAAQ,EAAE,+CAAkC,CAAC,YAAY;YACzD,eAAe,EAAE,+CAAkC,CAAC,mBAAmB;YACvE,cAAc,EAAE,+CAAkC,CAAC,kBAAkB;YACrE,eAAe,EAAE,+CAAkC,CAAC,mBAAmB;YACvE,2BAA2B,EAAE,+CAAkC,CAAC,6BAA6B;YAC7F,UAAU,EAAE,+CAAkC,CAAC,cAAc;YAC7D,cAAc,EAAE,+CAAkC,CAAC,kBAAkB;YACrE,8BAA8B,EAAE,+CAAkC,CAAC,yBAAyB;YAC5F,oCAAoC,EAAE,+CAAkC,CAAC,uBAAuB;SACjG,EACD,IAAI,EAAE;YACJ,IAAI,EAAE,+CAAkC,CAAC,YAAY;YACrD,GAAG,EAAE,+CAAkC,CAAC,WAAW;SACpD,IACF;AACH,CAAC,CAAA;AAzBY,QAAA,YAAY,gBAyBxB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EgldTx, TransferEgldBlockchain } from '@tatumio/api-client';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { TransactionConfig } from 'web3-core';
|
|
4
|
+
import { Transaction } from '@elrondnetwork/erdjs';
|
|
5
|
+
import { FromPrivateKeyOrSignatureId } from '@tatumio/shared-blockchain-abstract';
|
|
6
|
+
import { EsdtData } from './services/egld.tx';
|
|
7
|
+
export declare type TransferEgld = FromPrivateKeyOrSignatureId<TransferEgldBlockchain> & {
|
|
8
|
+
service?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const generateAddressFromPrivatekey: (privKey: string) => string;
|
|
11
|
+
export declare const signTransaction: (tx: Transaction, fromPrivateKey: string) => Promise<string>;
|
|
12
|
+
export declare const egldUtils: {
|
|
13
|
+
encodeNumber: (n: number | BigNumber) => string;
|
|
14
|
+
prepareProperties: (props: any) => string;
|
|
15
|
+
getClient: (provider?: string) => string;
|
|
16
|
+
getConfig: () => Promise<any>;
|
|
17
|
+
getGasPrice: () => Promise<number>;
|
|
18
|
+
getGasLimit: (tx: EgldTx) => Promise<number>;
|
|
19
|
+
isEsdtData: (input: object) => input is EsdtData;
|
|
20
|
+
parseTransferEgldBlockchainData: (body: Pick<TransferEgld, 'data'>) => EsdtData;
|
|
21
|
+
};
|
|
22
|
+
export declare const prepareSignedTransactionAbstraction: (transaction: TransactionConfig, signatureId?: string | undefined, fromPrivateKey?: string | undefined) => Promise<string>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareSignedTransactionAbstraction = exports.egldUtils = exports.signTransaction = exports.generateAddressFromPrivatekey = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_client_1 = require("@tatumio/api-client");
|
|
6
|
+
const axios_1 = (0, tslib_1.__importDefault)(require("axios"));
|
|
7
|
+
const bech32 = (0, tslib_1.__importStar)(require("bech32"));
|
|
8
|
+
const bignumber_js_1 = (0, tslib_1.__importDefault)(require("bignumber.js"));
|
|
9
|
+
const ed25519_hd_key_1 = require("ed25519-hd-key");
|
|
10
|
+
const erdjs_1 = require("@elrondnetwork/erdjs");
|
|
11
|
+
const ELROND_V3_ENDPOINT = () => `${process.env['TATUM_API_URL'] || api_client_1.TATUM_API_CONSTANTS.URL}/v3/egld/node`;
|
|
12
|
+
const generateAddressFromPrivatekey = (privKey) => {
|
|
13
|
+
const publicKey = (0, ed25519_hd_key_1.getPublicKey)(Buffer.from(privKey, 'hex'), false).toString('hex');
|
|
14
|
+
const words = bech32.toWords(Buffer.from(publicKey.slice(-64), 'hex'));
|
|
15
|
+
const address = bech32.encode('erd', words);
|
|
16
|
+
return address;
|
|
17
|
+
};
|
|
18
|
+
exports.generateAddressFromPrivatekey = generateAddressFromPrivatekey;
|
|
19
|
+
const signTransaction = (tx, fromPrivateKey) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
20
|
+
const fromAddrSigner = new erdjs_1.UserSigner(erdjs_1.UserSecretKey.fromString(fromPrivateKey));
|
|
21
|
+
yield fromAddrSigner.sign(tx);
|
|
22
|
+
return JSON.stringify(tx.toSendable());
|
|
23
|
+
});
|
|
24
|
+
exports.signTransaction = signTransaction;
|
|
25
|
+
exports.egldUtils = {
|
|
26
|
+
encodeNumber: (n) => {
|
|
27
|
+
const bn = new bignumber_js_1.default(n);
|
|
28
|
+
if (bn.isNaN()) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
const result = bn.toString(16).toLowerCase();
|
|
32
|
+
return `${(result.length % 2 ? '0' : '') + result}`;
|
|
33
|
+
},
|
|
34
|
+
prepareProperties: (props) => {
|
|
35
|
+
if (!props) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
const keys = Object.keys(props);
|
|
39
|
+
const asHexTrue = Buffer.from('true').toString('hex');
|
|
40
|
+
const asHexFalse = Buffer.from('false').toString('hex');
|
|
41
|
+
let result = '';
|
|
42
|
+
for (const k of keys) {
|
|
43
|
+
result += `@${Buffer.from(k).toString('hex')}@${props[k] ? asHexTrue : asHexFalse}`;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
getClient: (provider) => {
|
|
48
|
+
const client = provider || ELROND_V3_ENDPOINT();
|
|
49
|
+
return client;
|
|
50
|
+
},
|
|
51
|
+
getConfig: () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
52
|
+
const gasStationUrl = yield exports.egldUtils.getClient();
|
|
53
|
+
try {
|
|
54
|
+
const response = yield axios_1.default.get(`${gasStationUrl}/d341d8f5-5f6a-43ca-a57c-c67839d1a1cb/network/config`);
|
|
55
|
+
return response === null || response === void 0 ? void 0 : response.data;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error(e);
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}),
|
|
62
|
+
getGasPrice: () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const { data } = yield exports.egldUtils.getConfig();
|
|
65
|
+
const price = (_a = data === null || data === void 0 ? void 0 : data.config) === null || _a === void 0 ? void 0 : _a.erd_min_gas_price;
|
|
66
|
+
if (price) {
|
|
67
|
+
return price;
|
|
68
|
+
}
|
|
69
|
+
throw Error(((_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.returnMessage) || 'egld.gasPrice.error');
|
|
70
|
+
}),
|
|
71
|
+
getGasLimit: (tx) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
72
|
+
var _c, _d;
|
|
73
|
+
const gasStationUrl = yield exports.egldUtils.getClient();
|
|
74
|
+
const { data } = yield axios_1.default.post(`${gasStationUrl}/d341d8f5-5f6a-43ca-a57c-c67839d1a1cb/transaction/cost`, tx);
|
|
75
|
+
const gas = (_c = data === null || data === void 0 ? void 0 : data.data) === null || _c === void 0 ? void 0 : _c.txGasUnits;
|
|
76
|
+
if (gas) {
|
|
77
|
+
return gas;
|
|
78
|
+
}
|
|
79
|
+
throw Error(((_d = data === null || data === void 0 ? void 0 : data.data) === null || _d === void 0 ? void 0 : _d.returnMessage) || 'egld.gasLimit.error');
|
|
80
|
+
}),
|
|
81
|
+
isEsdtData: (input) => {
|
|
82
|
+
return input && 'name' in input && 'symbol' in input && 'supply' in input && 'digits' in input;
|
|
83
|
+
},
|
|
84
|
+
parseTransferEgldBlockchainData: (body) => {
|
|
85
|
+
let parsed;
|
|
86
|
+
try {
|
|
87
|
+
parsed = (body === null || body === void 0 ? void 0 : body.data) && JSON.parse(body.data);
|
|
88
|
+
}
|
|
89
|
+
catch (_a) {
|
|
90
|
+
throw new Error('Unable to parse Egld data input');
|
|
91
|
+
}
|
|
92
|
+
if (!exports.egldUtils.isEsdtData(parsed)) {
|
|
93
|
+
throw new Error('Unable to parse Egld data input');
|
|
94
|
+
}
|
|
95
|
+
return parsed;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
const prepareSignedTransactionAbstraction = (transaction, signatureId, fromPrivateKey) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
99
|
+
const sender = transaction.from || (yield (0, exports.generateAddressFromPrivatekey)(fromPrivateKey));
|
|
100
|
+
const { data } = yield exports.egldUtils.getConfig();
|
|
101
|
+
const config = data === null || data === void 0 ? void 0 : data.config;
|
|
102
|
+
const gasPrice = (transaction.gasPrice ? transaction.gasPrice : config === null || config === void 0 ? void 0 : config.erd_min_gas_price) || 1000000000;
|
|
103
|
+
const nonce = yield api_client_1.ApiServices.blockchain.elgo.egldGetTransactionCount(sender);
|
|
104
|
+
const egldTx = {
|
|
105
|
+
nonce,
|
|
106
|
+
value: new bignumber_js_1.default(transaction.value).isLessThan(0)
|
|
107
|
+
? '0'
|
|
108
|
+
: new bignumber_js_1.default(transaction.value).multipliedBy(1e18).toString(),
|
|
109
|
+
receiver: transaction.to,
|
|
110
|
+
sender,
|
|
111
|
+
gasPrice,
|
|
112
|
+
gasLimit: 0,
|
|
113
|
+
data: transaction.data ? Buffer.from(transaction.data).toString('base64') : undefined,
|
|
114
|
+
};
|
|
115
|
+
const gasLimit = transaction.gas || (yield exports.egldUtils.getGasLimit(egldTx));
|
|
116
|
+
egldTx.gasLimit = new bignumber_js_1.default(gasLimit).toNumber();
|
|
117
|
+
if (signatureId) {
|
|
118
|
+
return JSON.stringify({
|
|
119
|
+
from: sender,
|
|
120
|
+
to: transaction.to,
|
|
121
|
+
value: transaction.value,
|
|
122
|
+
data: transaction.data,
|
|
123
|
+
gasPrice,
|
|
124
|
+
gasLimit,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const erdjsTransaction = new erdjs_1.Transaction({
|
|
128
|
+
nonce: egldTx.nonce ? new erdjs_1.Nonce(egldTx.nonce) : undefined,
|
|
129
|
+
value: egldTx.value ? erdjs_1.Balance.fromString(egldTx.value) : undefined,
|
|
130
|
+
receiver: new erdjs_1.Address(egldTx.receiver),
|
|
131
|
+
sender: new erdjs_1.Address(egldTx.sender),
|
|
132
|
+
gasPrice: egldTx.gasPrice ? new erdjs_1.GasPrice(egldTx.gasPrice) : undefined,
|
|
133
|
+
gasLimit: new erdjs_1.GasLimit(egldTx.gasLimit),
|
|
134
|
+
data: transaction.data ? new erdjs_1.TransactionPayload(transaction.data) : undefined,
|
|
135
|
+
});
|
|
136
|
+
return yield (0, exports.signTransaction)(erdjsTransaction, fromPrivateKey);
|
|
137
|
+
});
|
|
138
|
+
exports.prepareSignedTransactionAbstraction = prepareSignedTransactionAbstraction;
|
|
139
|
+
//# sourceMappingURL=egld.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egld.utils.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/egld/src/lib/egld.utils.ts"],"names":[],"mappings":";;;;AAAA,oDAAsG;AACtG,+DAAyB;AACzB,4DAAgC;AAChC,6EAAoC;AACpC,mDAA6C;AAE7C,gDAU6B;AAI7B,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,gCAAmB,CAAC,GAAG,eAAe,CAAA;AAMnG,MAAM,6BAA6B,GAAG,CAAC,OAAe,EAAE,EAAE;IAC/D,MAAM,SAAS,GAAG,IAAA,6BAAY,EAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAClF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;IACtE,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;I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S, fromPrivateKey: string): Promise<string>;
|
|
6
|
+
getAllPending(signatures?: string): import("../../../../../../dist/packages/api-client/src").CancelablePromise<import("../../../../../../dist/packages/api-client/src").PendingTransaction[]>;
|
|
7
|
+
get: typeof import("../../../../../../dist/packages/api-client/src").SecurityKeyManagementSystemService.getPendingTransactionToSign;
|
|
8
|
+
complete: typeof import("../../../../../../dist/packages/api-client/src").SecurityKeyManagementSystemService.completePendingSignature;
|
|
9
|
+
delete: typeof import("../../../../../../dist/packages/api-client/src").SecurityKeyManagementSystemService.deletePendingTransactionToSign;
|
|
10
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.egldKmsService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const shared_blockchain_abstract_1 = require("@tatumio/shared-blockchain-abstract");
|
|
6
|
+
const egld_utils_1 = require("../egld.utils");
|
|
7
|
+
const egldKmsService = (args) => {
|
|
8
|
+
return Object.assign(Object.assign({}, (0, shared_blockchain_abstract_1.abstractBlockchainKms)(args)), { sign(tx, fromPrivateKey) {
|
|
9
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
10
|
+
const transaction = JSON.parse(tx.serializedTransaction);
|
|
11
|
+
return yield (0, egld_utils_1.prepareSignedTransactionAbstraction)(transaction, undefined, fromPrivateKey);
|
|
12
|
+
});
|
|
13
|
+
} });
|
|
14
|
+
};
|
|
15
|
+
exports.egldKmsService = egldKmsService;
|
|
16
|
+
//# sourceMappingURL=egld.kms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egld.kms.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/egld/src/lib/services/egld.kms.ts"],"names":[],"mappings":";;;;AACA,oFAA2E;AAC3E,8CAAmE;AAE5D,MAAM,cAAc,GAAG,CAAC,IAAgC,EAAE,EAAE;IACjE,uCACK,IAAA,kDAAqB,EAAC,IAAI,CAAC,KACxB,IAAI,CAAC,EAAuB,EAAE,cAAsB;;gBACxD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAA;gBAExD,OAAO,MAAM,IAAA,gDAAmC,EAAC,WAAW,EAAE,SAAS,EAAE,cAAc,CAAC,CAAA;YAC1F,CAAC;SAAA,IACF;AACH,CAAC,CAAA;AATY,QAAA,cAAc,kBAS1B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OffchainTransactionResult, OffchainTransactionSignatureResult, TransferEth, TransferEthKMS, TransferEthMnemonic } from '@tatumio/api-client';
|
|
2
|
+
import { Blockchain } from '@tatumio/shared-core';
|
|
3
|
+
export declare const egldOffchainService: (args: {
|
|
4
|
+
blockchain: Blockchain;
|
|
5
|
+
}) => {
|
|
6
|
+
/**
|
|
7
|
+
* Send EGLD transaction from Tatum Ledger account to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
8
|
+
* This operation is irreversible.
|
|
9
|
+
* @param body content of the transaction to broadcast
|
|
10
|
+
* @returns transaction id of the transaction in the blockchain or id of the withdrawal, if it was not cancelled automatically
|
|
11
|
+
*/
|
|
12
|
+
send: (body: EgldOffchain) => Promise<SendOffchainResponse>;
|
|
13
|
+
depositAddress: {
|
|
14
|
+
checkExists: (address: string, index?: number) => Promise<any>;
|
|
15
|
+
create: any;
|
|
16
|
+
createMultiple: any;
|
|
17
|
+
assign: any;
|
|
18
|
+
remove: any;
|
|
19
|
+
getByAccount: any;
|
|
20
|
+
};
|
|
21
|
+
withdrawal: {
|
|
22
|
+
getAll: (status?: "InProgress" | "Done" | "Cancelled", pageSize?: number, offset?: number) => Promise<any[]>;
|
|
23
|
+
broadcast: any;
|
|
24
|
+
create: any;
|
|
25
|
+
complete: any;
|
|
26
|
+
};
|
|
27
|
+
storeTokenAddress: any;
|
|
28
|
+
};
|
|
29
|
+
declare type EgldOffchain = TransferEth | TransferEthMnemonic | TransferEthKMS;
|
|
30
|
+
declare type SendOffchainResponse = OffchainTransactionResult | OffchainTransactionSignatureResult | {
|
|
31
|
+
id?: string;
|
|
32
|
+
} | void;
|
|
33
|
+
export declare const send: (body: EgldOffchain) => Promise<SendOffchainResponse>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.send = exports.egldOffchainService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_client_1 = require("@tatumio/api-client");
|
|
6
|
+
const shared_blockchain_abstract_1 = require("@tatumio/shared-blockchain-abstract");
|
|
7
|
+
const bignumber_js_1 = (0, tslib_1.__importDefault)(require("bignumber.js"));
|
|
8
|
+
const egld_tx_1 = require("./egld.tx");
|
|
9
|
+
const egldOffchainService = (args) => {
|
|
10
|
+
return Object.assign(Object.assign({}, (0, shared_blockchain_abstract_1.abstractBlockchainOffchain)(args)), {
|
|
11
|
+
/**
|
|
12
|
+
* Send EGLD transaction from Tatum Ledger account to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
13
|
+
* This operation is irreversible.
|
|
14
|
+
* @param body content of the transaction to broadcast
|
|
15
|
+
* @returns transaction id of the transaction in the blockchain or id of the withdrawal, if it was not cancelled automatically
|
|
16
|
+
*/
|
|
17
|
+
send: exports.send });
|
|
18
|
+
};
|
|
19
|
+
exports.egldOffchainService = egldOffchainService;
|
|
20
|
+
const send = (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
21
|
+
if ('signatureId' in body) {
|
|
22
|
+
return yield api_client_1.ApiServices.offChain.blockchain.egldTransfer(body);
|
|
23
|
+
}
|
|
24
|
+
const { gasLimit, gasPrice } = body, withdrawal = (0, tslib_1.__rest)(body, ["gasLimit", "gasPrice"]);
|
|
25
|
+
let fromPriv;
|
|
26
|
+
if ('mnemonic' in body) {
|
|
27
|
+
fromPriv = (yield api_client_1.ApiServices.blockchain.elgo.egldGenerateAddressPrivateKey({
|
|
28
|
+
mnemonic: body.mnemonic,
|
|
29
|
+
index: body.index,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
fromPriv = body.privateKey;
|
|
34
|
+
const fee = {
|
|
35
|
+
gasLimit: `${gasLimit || '50000'}`,
|
|
36
|
+
gasPrice: `${gasPrice || '1000000000'}`,
|
|
37
|
+
};
|
|
38
|
+
const txData = yield (0, egld_tx_1.prepareSignedTransaction)({
|
|
39
|
+
amount: body.amount,
|
|
40
|
+
fromPrivateKey: fromPriv,
|
|
41
|
+
fee,
|
|
42
|
+
to: body.address,
|
|
43
|
+
});
|
|
44
|
+
const { id } = yield api_client_1.ApiServices.offChain.withdrawal.storeWithdrawal(Object.assign(Object.assign({}, withdrawal), { fee: new bignumber_js_1.default(fee.gasLimit).multipliedBy(fee.gasPrice).toString() }));
|
|
45
|
+
try {
|
|
46
|
+
return Object.assign(Object.assign({}, (yield api_client_1.ApiServices.offChain.withdrawal.broadcastBlockchainTransaction({
|
|
47
|
+
txData,
|
|
48
|
+
withdrawalId: id,
|
|
49
|
+
currency: api_client_1.Currency.EGLD,
|
|
50
|
+
}))), { id });
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
try {
|
|
54
|
+
return yield api_client_1.ApiServices.offChain.withdrawal.cancelInProgressWithdrawal(id);
|
|
55
|
+
}
|
|
56
|
+
catch (e1) {
|
|
57
|
+
return { id };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
exports.send = send;
|
|
62
|
+
//# sourceMappingURL=egld.offchain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egld.offchain.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/egld/src/lib/services/egld.offchain.ts"],"names":[],"mappings":";;;;AAAA,oDAQ4B;AAC5B,oFAAgF;AAEhF,6EAAoC;AACpC,uCAAoD;AAE7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,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,IACtE,CAAA;IAEF,IAAI;QACF,uCACK,CAAC,MAAM,wBAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,8BAA8B,CAAC;YACvE,MAAM;YACN,YAAY,EAAE,EAAE;YAChB,QAAQ,EAAE,qBAAQ,CAAC,IAAI;SACxB,CAAC,CAAC,KACH,EAAE,IACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,IAAI;YACF,OAAO,MAAM,wBAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,EAAG,CAAC,CAAA;SAC7E;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,EAAE,EAAE,CAAA;SACd;KACF;AACH,CAAC,CAAA,CAAA;AAhDY,QAAA,IAAI,QAgDhB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CancelablePromise } from '@tatumio/api-client';
|
|
2
|
+
export declare const egldRecord: () => {
|
|
3
|
+
/**
|
|
4
|
+
* Get log record
|
|
5
|
+
* <h4>1 credit per API call.</h4><br/><p>Gets log data from blockchain.</p>
|
|
6
|
+
* @param chain The blockchain to get the log record from
|
|
7
|
+
* @param id ID of the log record / transaction on the blockchain
|
|
8
|
+
* @returns any OK
|
|
9
|
+
* @throws ApiError
|
|
10
|
+
*/
|
|
11
|
+
getLog(id: string): CancelablePromise<{
|
|
12
|
+
/**
|
|
13
|
+
* Data stored in the record.
|
|
14
|
+
*/
|
|
15
|
+
data: string;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.egldRecord = void 0;
|
|
4
|
+
const api_client_1 = require("@tatumio/api-client");
|
|
5
|
+
const shared_core_1 = require("@tatumio/shared-core");
|
|
6
|
+
const egldRecord = () => {
|
|
7
|
+
return {
|
|
8
|
+
/**
|
|
9
|
+
* Get log record
|
|
10
|
+
* <h4>1 credit per API call.</h4><br/><p>Gets log data from blockchain.</p>
|
|
11
|
+
* @param chain The blockchain to get the log record from
|
|
12
|
+
* @param id ID of the log record / transaction on the blockchain
|
|
13
|
+
* @returns any OK
|
|
14
|
+
* @throws ApiError
|
|
15
|
+
*/
|
|
16
|
+
getLog(id) {
|
|
17
|
+
return api_client_1.BlockchainRecordService.getLog(shared_core_1.Blockchain.EGLD, id);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.egldRecord = egldRecord;
|
|
22
|
+
//# sourceMappingURL=egld.record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egld.record.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/egld/src/lib/services/egld.record.ts"],"names":[],"mappings":";;;AAAA,oDAAgF;AAChF,sDAAiD;AAE1C,MAAM,UAAU,GAAG,GAAG,EAAE;IAC7B,OAAO;QACL;;;;;;;WAOG;QACH,MAAM,CAAC,EAAU;YAMf,OAAO,oCAAuB,CAAC,MAAM,CAAC,wBAAU,CAAC,IAAW,EAAE,EAAE,CAAC,CAAA;QACnE,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAnBY,QAAA,UAAU,cAmBtB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { TransferEgld } from '../egld.utils';
|
|
2
|
+
export interface EsdtData extends EsdtToken {
|
|
3
|
+
name: string;
|
|
4
|
+
symbol: string;
|
|
5
|
+
supply: number;
|
|
6
|
+
digits: number;
|
|
7
|
+
properties?: EsdtProperties;
|
|
8
|
+
}
|
|
9
|
+
interface EsdtProperties {
|
|
10
|
+
properties?: {
|
|
11
|
+
canFreeze?: boolean;
|
|
12
|
+
canWipe?: boolean;
|
|
13
|
+
canPause?: boolean;
|
|
14
|
+
canMint?: boolean;
|
|
15
|
+
canBurn?: boolean;
|
|
16
|
+
canChangeOwner?: boolean;
|
|
17
|
+
canUpgrade?: boolean;
|
|
18
|
+
canAddSpecialRoles?: boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface EsdtToken {
|
|
22
|
+
service: string;
|
|
23
|
+
tokenId: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const prepareSignedTransaction: (body: TransferEgld) => Promise<string>;
|
|
26
|
+
export declare const prepareTransferEsdtSignedTransaction: (body: TransferEgld) => Promise<string>;
|
|
27
|
+
export declare const prepareTransferNft: (body: TransferEgld) => Promise<string>;
|
|
28
|
+
export declare const prepareDeployNftOrSft: (body: TransferEgld) => Promise<string>;
|
|
29
|
+
export declare const egldTransactionService: () => {
|
|
30
|
+
prepare: {
|
|
31
|
+
/**
|
|
32
|
+
* Sign ESDT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
33
|
+
* @param body content of the transaction to broadcast
|
|
34
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
35
|
+
*/
|
|
36
|
+
deploy: (body: TransferEgld) => Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Sign EGLD transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
39
|
+
* @param body content of the transaction to broadcast
|
|
40
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
41
|
+
*/
|
|
42
|
+
signedTransaction: (body: TransferEgld) => Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Sign ESDT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
45
|
+
* @param body content of the transaction to broadcast
|
|
46
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
47
|
+
*/
|
|
48
|
+
smartContractMethodInvocation: (body: TransferEgld) => Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Sign ESDT transfer NFT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
51
|
+
* @param body content of the transaction to broadcast
|
|
52
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
53
|
+
*/
|
|
54
|
+
transferNft: (body: TransferEgld) => Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Sign ESDT deploy NFT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
57
|
+
* @param body content of the transaction to broadcast
|
|
58
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
59
|
+
*/
|
|
60
|
+
deployNft: (body: TransferEgld) => Promise<string>;
|
|
61
|
+
};
|
|
62
|
+
send: {
|
|
63
|
+
/**
|
|
64
|
+
* Send EGLD deploy ESDT transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
65
|
+
* This operation is irreversible.
|
|
66
|
+
* @param body content of the transaction to broadcast
|
|
67
|
+
* @returns transaction id of the transaction in the blockchain
|
|
68
|
+
*/
|
|
69
|
+
deploy: (body: TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
70
|
+
/**
|
|
71
|
+
* Send EGLD or supported ERC20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
72
|
+
* This operation is irreversible.
|
|
73
|
+
* @param body content of the transaction to broadcast
|
|
74
|
+
* @returns transaction id of the transaction in the blockchain
|
|
75
|
+
*/
|
|
76
|
+
signedTransaction: (body: TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
77
|
+
/**
|
|
78
|
+
* Send EGLD invoke smart contract transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
79
|
+
* This operation is irreversible.
|
|
80
|
+
* @param body content of the transaction to broadcast
|
|
81
|
+
* @returns transaction id of the transaction in the blockchain
|
|
82
|
+
*/
|
|
83
|
+
smartContractMethodInvocation: (body: TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
84
|
+
/**
|
|
85
|
+
* Send EGLD ERC721 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
86
|
+
* This operation is irreversible.
|
|
87
|
+
* @param body content of the transaction to broadcast
|
|
88
|
+
* @returns transaction id of the transaction in the blockchain
|
|
89
|
+
*/
|
|
90
|
+
transferNft: (body: TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
91
|
+
/**
|
|
92
|
+
* Send EGLD NFT deploy to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
93
|
+
* This operation is irreversible.
|
|
94
|
+
* @param body content of the transaction to broadcast
|
|
95
|
+
* @returns transaction id of the transaction in the blockchain
|
|
96
|
+
*/
|
|
97
|
+
deployNft: (body: TransferEgld) => Promise<import("@tatumio/api-client").TransactionHashKMS>;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.egldTransactionService = exports.prepareDeployNftOrSft = exports.prepareTransferNft = exports.prepareTransferEsdtSignedTransaction = exports.prepareSignedTransaction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_client_1 = require("@tatumio/api-client");
|
|
6
|
+
const bignumber_js_1 = (0, tslib_1.__importDefault)(require("bignumber.js"));
|
|
7
|
+
const egld_utils_1 = require("../egld.utils");
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
9
|
+
const prepareEsdtIssuanceData = (data) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
10
|
+
const tokenName = Buffer.from(data.name).toString('hex');
|
|
11
|
+
const tokenTicker = Buffer.from(data.symbol).toString('hex');
|
|
12
|
+
const initialSupply = egld_utils_1.egldUtils.encodeNumber(data.supply);
|
|
13
|
+
const decimals = egld_utils_1.egldUtils.encodeNumber(data.digits);
|
|
14
|
+
const properties = egld_utils_1.egldUtils.prepareProperties(data.properties || {
|
|
15
|
+
canAddSpecialRoles: true,
|
|
16
|
+
canChangeOwner: true,
|
|
17
|
+
canUpgrade: true,
|
|
18
|
+
canMint: true,
|
|
19
|
+
canBurn: true,
|
|
20
|
+
});
|
|
21
|
+
return `${data.service}@${tokenName}@${tokenTicker}@${initialSupply}@${decimals}` + properties;
|
|
22
|
+
});
|
|
23
|
+
const prepareDeploy = (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
24
|
+
const { amount, fee, fromPrivateKey, signatureId, from, data } = body;
|
|
25
|
+
const value = amount ? new bignumber_js_1.default(amount).toNumber() : 0.05;
|
|
26
|
+
const sender = from || (fromPrivateKey && (0, egld_utils_1.generateAddressFromPrivatekey)(fromPrivateKey));
|
|
27
|
+
const parsedData = data && JSON.parse(data);
|
|
28
|
+
const preparedData = parsedData
|
|
29
|
+
? yield prepareEsdtIssuanceData(Object.assign(Object.assign({}, parsedData), { service: parsedData.service || 'issue' }))
|
|
30
|
+
: '{ service: issue }';
|
|
31
|
+
const tx = {
|
|
32
|
+
from: sender,
|
|
33
|
+
to: constants_1.ESDT_SYSTEM_SMART_CONTRACT_ADDRESS,
|
|
34
|
+
value,
|
|
35
|
+
gasPrice: fee === null || fee === void 0 ? void 0 : fee.gasPrice,
|
|
36
|
+
gas: fee === null || fee === void 0 ? void 0 : fee.gasLimit,
|
|
37
|
+
data: preparedData,
|
|
38
|
+
};
|
|
39
|
+
return yield (0, egld_utils_1.prepareSignedTransactionAbstraction)(tx, signatureId, fromPrivateKey);
|
|
40
|
+
});
|
|
41
|
+
const prepareEsdtTransferData = (data) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
42
|
+
const tokenId = Buffer.from(data.tokenId).toString('hex');
|
|
43
|
+
const value = egld_utils_1.egldUtils.encodeNumber(data.value);
|
|
44
|
+
let args = '';
|
|
45
|
+
if (data.methodName) {
|
|
46
|
+
args += '@' + Buffer.from(data.methodName).toString('hex');
|
|
47
|
+
for (const k of data.arguments || []) {
|
|
48
|
+
if (new bignumber_js_1.default(k).isNaN()) {
|
|
49
|
+
args += `@${Buffer.from(k).toString('hex')}`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
args += `@${egld_utils_1.egldUtils.encodeNumber(new bignumber_js_1.default(k))}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return `${data.service}@${tokenId}@${value}` + args;
|
|
57
|
+
});
|
|
58
|
+
const prepareSignedTransaction = (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
59
|
+
const { fromPrivateKey, signatureId, from, to, amount, fee, data } = body;
|
|
60
|
+
const tx = {
|
|
61
|
+
from: from || 0,
|
|
62
|
+
to: to,
|
|
63
|
+
value: amount,
|
|
64
|
+
gasPrice: fee === null || fee === void 0 ? void 0 : fee.gasPrice,
|
|
65
|
+
gas: fee === null || fee === void 0 ? void 0 : fee.gasLimit,
|
|
66
|
+
data,
|
|
67
|
+
};
|
|
68
|
+
return yield (0, egld_utils_1.prepareSignedTransactionAbstraction)(tx, signatureId, fromPrivateKey);
|
|
69
|
+
});
|
|
70
|
+
exports.prepareSignedTransaction = prepareSignedTransaction;
|
|
71
|
+
const prepareTransferEsdtSignedTransaction = (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
72
|
+
const { fromPrivateKey, signatureId, from, to, fee, data } = body;
|
|
73
|
+
const sender = from || (yield (0, egld_utils_1.generateAddressFromPrivatekey)(fromPrivateKey));
|
|
74
|
+
const parsedData = data && JSON.parse(data);
|
|
75
|
+
const preparedData = parsedData
|
|
76
|
+
? yield prepareEsdtTransferData(Object.assign(Object.assign({}, parsedData), { service: parsedData.service || 'ESDTTransfer' }))
|
|
77
|
+
: `{ service: ESDTTransfer }`;
|
|
78
|
+
const tx = {
|
|
79
|
+
from: sender,
|
|
80
|
+
to,
|
|
81
|
+
gasPrice: fee === null || fee === void 0 ? void 0 : fee.gasPrice,
|
|
82
|
+
gas: fee === null || fee === void 0 ? void 0 : fee.gasLimit,
|
|
83
|
+
data: preparedData,
|
|
84
|
+
};
|
|
85
|
+
return yield (0, egld_utils_1.prepareSignedTransactionAbstraction)(tx, signatureId, fromPrivateKey);
|
|
86
|
+
});
|
|
87
|
+
exports.prepareTransferEsdtSignedTransaction = prepareTransferEsdtSignedTransaction;
|
|
88
|
+
const prepareTransferNft = (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
89
|
+
const { fromPrivateKey, signatureId, from, amount, fee, data } = body;
|
|
90
|
+
const value = amount ? new bignumber_js_1.default(amount).toNumber() : 0;
|
|
91
|
+
const sender = from || (yield (0, egld_utils_1.generateAddressFromPrivatekey)(fromPrivateKey));
|
|
92
|
+
const parsedData = data && JSON.parse(data);
|
|
93
|
+
const preparedData = parsedData
|
|
94
|
+
? yield prepareTransferNftData(Object.assign(Object.assign({}, parsedData), { service: parsedData.service || 'ESDTNFTTransfer' }))
|
|
95
|
+
: '{ service: "ESDTNFTTransfer" }';
|
|
96
|
+
const tx = {
|
|
97
|
+
from: sender,
|
|
98
|
+
to: sender,
|
|
99
|
+
value,
|
|
100
|
+
gasPrice: fee === null || fee === void 0 ? void 0 : fee.gasPrice,
|
|
101
|
+
gas: fee === null || fee === void 0 ? void 0 : fee.gasLimit,
|
|
102
|
+
data: preparedData,
|
|
103
|
+
};
|
|
104
|
+
return yield (0, egld_utils_1.prepareSignedTransactionAbstraction)(tx, signatureId, fromPrivateKey);
|
|
105
|
+
});
|
|
106
|
+
exports.prepareTransferNft = prepareTransferNft;
|
|
107
|
+
const prepareTransferNftData = (data) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
108
|
+
const tokenId = Buffer.from(data.tokenId).toString('hex');
|
|
109
|
+
const nonce = egld_utils_1.egldUtils.encodeNumber(data.nonce);
|
|
110
|
+
const quantity = egld_utils_1.egldUtils.encodeNumber(data.quantity);
|
|
111
|
+
const to = Buffer.from(data.to).toString('hex');
|
|
112
|
+
let args = '';
|
|
113
|
+
if (data.methodName) {
|
|
114
|
+
args += '@' + Buffer.from(data.methodName).toString('hex');
|
|
115
|
+
for (const k of data.arguments || []) {
|
|
116
|
+
if (new bignumber_js_1.default(k).isNaN()) {
|
|
117
|
+
args += `@${Buffer.from(k).toString('hex')}`;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
args += `@${egld_utils_1.egldUtils.encodeNumber(new bignumber_js_1.default(k))}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return `${data.service}@${tokenId}@${nonce}@${quantity}@${to}` + args;
|
|
125
|
+
});
|
|
126
|
+
const prepareDeployNftOrSft = (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
127
|
+
const { fromPrivateKey, signatureId, from, amount, fee, data } = body;
|
|
128
|
+
const value = amount ? new bignumber_js_1.default(amount).toNumber() : 0.05;
|
|
129
|
+
const sender = from || (yield (0, egld_utils_1.generateAddressFromPrivatekey)(fromPrivateKey));
|
|
130
|
+
const parsedData = data && JSON.parse(data);
|
|
131
|
+
const preparedData = parsedData
|
|
132
|
+
? yield prepareIssuanceNftOrSftData(Object.assign(Object.assign({}, parsedData), { service: parsedData.service || 'issueNonFungible' }))
|
|
133
|
+
: '{ service: "issueNonFungible" }';
|
|
134
|
+
const tx = {
|
|
135
|
+
from: sender,
|
|
136
|
+
to: constants_1.ESDT_SYSTEM_SMART_CONTRACT_ADDRESS,
|
|
137
|
+
value,
|
|
138
|
+
gasPrice: fee === null || fee === void 0 ? void 0 : fee.gasPrice,
|
|
139
|
+
gas: fee === null || fee === void 0 ? void 0 : fee.gasLimit,
|
|
140
|
+
data: preparedData,
|
|
141
|
+
};
|
|
142
|
+
return yield (0, egld_utils_1.prepareSignedTransactionAbstraction)(tx, signatureId, fromPrivateKey);
|
|
143
|
+
});
|
|
144
|
+
exports.prepareDeployNftOrSft = prepareDeployNftOrSft;
|
|
145
|
+
const prepareIssuanceNftOrSftData = (data) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
146
|
+
const tokenName = Buffer.from(data.name).toString('hex');
|
|
147
|
+
const tokenTicker = Buffer.from(data.symbol).toString('hex');
|
|
148
|
+
const properties = egld_utils_1.egldUtils.prepareProperties(data.properties);
|
|
149
|
+
return `${data.service}@${tokenName}@${tokenTicker}` + properties;
|
|
150
|
+
});
|
|
151
|
+
const egldTransactionService = () => {
|
|
152
|
+
return {
|
|
153
|
+
prepare: {
|
|
154
|
+
/**
|
|
155
|
+
* Sign ESDT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
156
|
+
* @param body content of the transaction to broadcast
|
|
157
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
158
|
+
*/
|
|
159
|
+
deploy: (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareDeploy(body); }),
|
|
160
|
+
/**
|
|
161
|
+
* Sign EGLD transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
162
|
+
* @param body content of the transaction to broadcast
|
|
163
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
164
|
+
*/
|
|
165
|
+
signedTransaction: (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return (0, exports.prepareSignedTransaction)(body); }),
|
|
166
|
+
/**
|
|
167
|
+
* Sign ESDT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
168
|
+
* @param body content of the transaction to broadcast
|
|
169
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
170
|
+
*/
|
|
171
|
+
smartContractMethodInvocation: (body) => (0, exports.prepareTransferEsdtSignedTransaction)(body),
|
|
172
|
+
/**
|
|
173
|
+
* Sign ESDT transfer NFT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
174
|
+
* @param body content of the transaction to broadcast
|
|
175
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
176
|
+
*/
|
|
177
|
+
transferNft: (body) => (0, exports.prepareTransferNft)(body),
|
|
178
|
+
/**
|
|
179
|
+
* Sign ESDT deploy NFT transaction with private keys locally. Nothing is broadcast to the blockchain.
|
|
180
|
+
* @param body content of the transaction to broadcast
|
|
181
|
+
* @returns transaction data to be broadcast to blockchain.
|
|
182
|
+
*/
|
|
183
|
+
deployNft: (body) => (0, exports.prepareDeployNftOrSft)(body),
|
|
184
|
+
},
|
|
185
|
+
send: {
|
|
186
|
+
/**
|
|
187
|
+
* Send EGLD deploy ESDT transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
188
|
+
* This operation is irreversible.
|
|
189
|
+
* @param body content of the transaction to broadcast
|
|
190
|
+
* @returns transaction id of the transaction in the blockchain
|
|
191
|
+
*/
|
|
192
|
+
deploy: (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
193
|
+
return yield api_client_1.BlockchainElrondNetworkEgldService.egldBroadcast({
|
|
194
|
+
txData: yield prepareDeploy(body),
|
|
195
|
+
signatureId: body.signatureId,
|
|
196
|
+
});
|
|
197
|
+
}),
|
|
198
|
+
/**
|
|
199
|
+
* Send EGLD or supported ERC20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
200
|
+
* This operation is irreversible.
|
|
201
|
+
* @param body content of the transaction to broadcast
|
|
202
|
+
* @returns transaction id of the transaction in the blockchain
|
|
203
|
+
*/
|
|
204
|
+
signedTransaction: (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
205
|
+
return yield api_client_1.BlockchainElrondNetworkEgldService.egldBroadcast({
|
|
206
|
+
txData: yield (0, exports.prepareSignedTransaction)(body),
|
|
207
|
+
signatureId: body.signatureId,
|
|
208
|
+
});
|
|
209
|
+
}),
|
|
210
|
+
/**
|
|
211
|
+
* Send EGLD invoke smart contract transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
212
|
+
* This operation is irreversible.
|
|
213
|
+
* @param body content of the transaction to broadcast
|
|
214
|
+
* @returns transaction id of the transaction in the blockchain
|
|
215
|
+
*/
|
|
216
|
+
smartContractMethodInvocation: (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
217
|
+
return yield api_client_1.BlockchainElrondNetworkEgldService.egldBroadcast({
|
|
218
|
+
txData: yield (0, exports.prepareTransferEsdtSignedTransaction)(body),
|
|
219
|
+
signatureId: body.signatureId,
|
|
220
|
+
});
|
|
221
|
+
}),
|
|
222
|
+
/**
|
|
223
|
+
* Send EGLD ERC721 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
224
|
+
* This operation is irreversible.
|
|
225
|
+
* @param body content of the transaction to broadcast
|
|
226
|
+
* @returns transaction id of the transaction in the blockchain
|
|
227
|
+
*/
|
|
228
|
+
transferNft: (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
229
|
+
return yield api_client_1.BlockchainElrondNetworkEgldService.egldBroadcast({
|
|
230
|
+
txData: yield (0, exports.prepareTransferNft)(body),
|
|
231
|
+
signatureId: body.signatureId,
|
|
232
|
+
});
|
|
233
|
+
}),
|
|
234
|
+
/**
|
|
235
|
+
* Send EGLD NFT deploy to the blockchain. This method broadcasts signed transaction to the blockchain.
|
|
236
|
+
* This operation is irreversible.
|
|
237
|
+
* @param body content of the transaction to broadcast
|
|
238
|
+
* @returns transaction id of the transaction in the blockchain
|
|
239
|
+
*/
|
|
240
|
+
deployNft: (body) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
241
|
+
return yield api_client_1.BlockchainElrondNetworkEgldService.egldBroadcast({
|
|
242
|
+
txData: yield (0, exports.prepareDeployNftOrSft)(body),
|
|
243
|
+
signatureId: body.signatureId,
|
|
244
|
+
});
|
|
245
|
+
}),
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
exports.egldTransactionService = egldTransactionService;
|
|
250
|
+
//# sourceMappingURL=egld.tx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egld.tx.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/egld/src/lib/services/egld.tx.ts"],"names":[],"mappings":";;;;AAAA,oDAAwE;AACxE,6EAAoC;AACpC,8CAKsB;AAEtB,+CAAoE;AA4DpE,MAAM,uBAAuB,GAAG,CAAO,IAAe,EAAmB,EAAE;IACzE,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,C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B,CAAC,CAAA;cAAA;YACJ;;;;;eAKG;YACH,6BAA6B,EAAE,CAAO,IAAkB,EAAE,EAAE;gBAC1D,OAAA,MAAM,+CAAkC,CAAC,aAAa,CAAC;oBACrD,MAAM,EAAE,MAAM,IAAA,4CAAoC,EAAC,IAAI,CAAC;oBACxD,WAAW,EAAE,IAAI,CAAC,WAAW;iBAC9B,CAAC,CAAA;cAAA;YAEJ;;;;;eAKG;YACH,WAAW,EAAE,CAAO,IAAkB,EAAE,EAAE;gBACxC,OAAA,MAAM,+CAAkC,CAAC,aAAa,CAAC;oBACrD,MAAM,EAAE,MAAM,IAAA,0BAAkB,EAAC,IAAI,CAAC;oBACtC,WAAW,EAAE,IAAI,CAAC,WAAW;iBAC9B,CAAC,CAAA;cAAA;YACJ;;;;;eAKG;YACH,SAAS,EAAE,CAAO,IAAkB,EAAE,EAAE;gBACtC,OAAA,MAAM,+CAAkC,CAAC,aAAa,CAAC;oBACrD,MAAM,EAAE,MAAM,IAAA,6BAAqB,EAAC,IAAI,CAAC;oBACzC,WAAW,EAAE,IAAI,CAAC,WAAW;iBAC9B,CAAC,CAAA;cAAA;SACL;KACF,CAAA;AACH,CAAC,CAAA;AA7FY,QAAA,sBAAsB,0BA6FlC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Wallet } from '@tatumio/api-client';
|
|
2
|
+
export declare const egldWallet: () => {
|
|
3
|
+
/**
|
|
4
|
+
* Generate EGLD wallet
|
|
5
|
+
* @param mnem mnemonic seed to use
|
|
6
|
+
* @returns wallet
|
|
7
|
+
*/
|
|
8
|
+
generateBlockchainWallet: (mnem: string) => Promise<Wallet>;
|
|
9
|
+
/**
|
|
10
|
+
* Generate wallet
|
|
11
|
+
* @param mnemonic optional mnemonic seed to use. If not present, new one will be generated
|
|
12
|
+
* @returns wallet or a combination of address and private key
|
|
13
|
+
*/
|
|
14
|
+
generateWallet: (mnemonic?: string) => import("@tatumio/api-client").CancelablePromise<{
|
|
15
|
+
mnemonic?: string;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Generate private key from mnemonic seed
|
|
19
|
+
* @param testnet testnet or mainnet version of address
|
|
20
|
+
* @param mnemonic mnemonic to generate private key from
|
|
21
|
+
* @param i derivation index of private key to generate.
|
|
22
|
+
* @returns blockchain private key to the address
|
|
23
|
+
*/
|
|
24
|
+
generatePrivateKeyFromMnemonic: (testnet: boolean, mnemonic: string, i: number) => Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Generate address from private key
|
|
27
|
+
* @param privateKey private key to use
|
|
28
|
+
* @returns blockchain private key to the address
|
|
29
|
+
*/
|
|
30
|
+
generateAddress: (testnet: boolean, mnemonic: string, i: number) => Promise<string>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.egldWallet = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bech32 = (0, tslib_1.__importStar)(require("bech32"));
|
|
6
|
+
const bip39_1 = require("bip39");
|
|
7
|
+
const ed25519_hd_key_1 = require("ed25519-hd-key");
|
|
8
|
+
const api_client_1 = require("@tatumio/api-client");
|
|
9
|
+
const shared_core_1 = require("@tatumio/shared-core");
|
|
10
|
+
const generatePrivateKey = (testnet, mnemonic, i) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
11
|
+
const path = (testnet ? shared_core_1.COMMON_TESTNET_DERIVATION_PATH + "'" : shared_core_1.DERIVATION_PATH.EGLD) + `/${i}'`;
|
|
12
|
+
const seed = yield (0, bip39_1.mnemonicToSeed)(mnemonic);
|
|
13
|
+
const { key } = (0, ed25519_hd_key_1.derivePath)(path, seed.toString('hex'));
|
|
14
|
+
return key.toString('hex');
|
|
15
|
+
});
|
|
16
|
+
const convertPrivateKey = (privKey) => {
|
|
17
|
+
const publicKey = (0, ed25519_hd_key_1.getPublicKey)(Buffer.from(privKey, 'hex'), false).toString('hex');
|
|
18
|
+
const words = bech32.toWords(Buffer.from(publicKey.slice(-64), 'hex'));
|
|
19
|
+
const address = bech32.encode('erd', words);
|
|
20
|
+
return address;
|
|
21
|
+
};
|
|
22
|
+
const egldWallet = () => {
|
|
23
|
+
return {
|
|
24
|
+
/**
|
|
25
|
+
* Generate EGLD wallet
|
|
26
|
+
* @param mnem mnemonic seed to use
|
|
27
|
+
* @returns wallet
|
|
28
|
+
*/
|
|
29
|
+
generateBlockchainWallet: (mnem) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
30
|
+
return {
|
|
31
|
+
mnemonic: mnem,
|
|
32
|
+
xpub: '',
|
|
33
|
+
};
|
|
34
|
+
}),
|
|
35
|
+
/**
|
|
36
|
+
* Generate wallet
|
|
37
|
+
* @param mnemonic optional mnemonic seed to use. If not present, new one will be generated
|
|
38
|
+
* @returns wallet or a combination of address and private key
|
|
39
|
+
*/
|
|
40
|
+
generateWallet: (mnemonic) => {
|
|
41
|
+
mnemonic || (mnemonic = (0, bip39_1.generateMnemonic)(256));
|
|
42
|
+
return api_client_1.ApiServices.blockchain.elgo.egldGenerateWallet(mnemonic);
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Generate private key from mnemonic seed
|
|
46
|
+
* @param testnet testnet or mainnet version of address
|
|
47
|
+
* @param mnemonic mnemonic to generate private key from
|
|
48
|
+
* @param i derivation index of private key to generate.
|
|
49
|
+
* @returns blockchain private key to the address
|
|
50
|
+
*/
|
|
51
|
+
generatePrivateKeyFromMnemonic: (testnet, mnemonic, i) => {
|
|
52
|
+
return generatePrivateKey(testnet, mnemonic, i);
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Generate address from private key
|
|
56
|
+
* @param privateKey private key to use
|
|
57
|
+
* @returns blockchain private key to the address
|
|
58
|
+
*/
|
|
59
|
+
generateAddress: (testnet, mnemonic, i) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
60
|
+
const privateKey = yield generatePrivateKey(testnet, mnemonic, i);
|
|
61
|
+
return convertPrivateKey(privateKey);
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.egldWallet = egldWallet;
|
|
66
|
+
//# sourceMappingURL=egld.wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egld.wallet.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/egld/src/lib/services/egld.wallet.ts"],"names":[],"mappings":";;;;AAAA,4DAAgC;AAChC,iCAAwD;AACxD,mDAAyD;AACzD,oDAAyD;AACzD,sDAAsF;AAEtF,MAAM,kBAAkB,GAAG,CAAO,OAAgB,EAAE,QAAgB,EAAE,CAAS,EAAmB,EAAE;IAClG,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,4CAA8B,GAAG,GAAG,CAAC,CAAC,CAAC,6BAAe,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAA;IAC/F,MAAM,IAAI,GAAG,MAAM,IAAA,sBAAc,EAAC,QAAQ,CAAC,CAAA;IAC3C,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,2BAAU,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;IACtD,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA,CAAA;AAED,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,EAAE;IAC5C,MAAM,SAAS,GAAG,IAAA,6BAAY,EAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAClF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;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