@tatumio/bnb 2.0.1-alpha.363
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 +20 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/bnb.sdk.d.ts +212 -0
- package/src/lib/bnb.sdk.errors.d.ts +10 -0
- package/src/lib/bnb.sdk.errors.js +30 -0
- package/src/lib/bnb.sdk.errors.js.map +1 -0
- package/src/lib/bnb.sdk.js +26 -0
- package/src/lib/bnb.sdk.js.map +1 -0
- package/src/lib/services/bnb.kms.d.ts +7 -0
- package/src/lib/services/bnb.kms.js +41 -0
- package/src/lib/services/bnb.kms.js.map +1 -0
- package/src/lib/services/bnb.tx.d.ts +52 -0
- package/src/lib/services/bnb.tx.js +139 -0
- package/src/lib/services/bnb.tx.js.map +1 -0
- package/src/lib/services/bnb.virtualAccount.d.ts +41 -0
- package/src/lib/services/bnb.virtualAccount.js +54 -0
- package/src/lib/services/bnb.virtualAccount.js.map +1 -0
- package/src/lib/services/bnb.wallet.d.ts +11 -0
- package/src/lib/services/bnb.wallet.js +25 -0
- package/src/lib/services/bnb.wallet.js.map +1 -0
- package/src/lib/services/bnb.web3.d.ts +5 -0
- package/src/lib/services/bnb.web3.js +23 -0
- package/src/lib/services/bnb.web3.js.map +1 -0
package/package.json
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"name": "@tatumio/bnb",
|
3
|
+
"version": "2.0.1-alpha.363",
|
4
|
+
"license": "MIT",
|
5
|
+
"main": "./src/index.js",
|
6
|
+
"types": "./src/index.d.ts",
|
7
|
+
"dependencies": {
|
8
|
+
"@tatumio/api-client": "2.0.1-alpha.363",
|
9
|
+
"axios": "^0.26.0",
|
10
|
+
"form-data": "^4.0.0",
|
11
|
+
"@tatumio/shared-abstract-sdk": "2.0.1-alpha.363",
|
12
|
+
"@tatumio/shared-testing-common": "2.0.1-alpha.363",
|
13
|
+
"bignumber.js": "^9.0.2",
|
14
|
+
"@tatumio/shared-blockchain-abstract": "2.0.1-alpha.363",
|
15
|
+
"@tatumio/shared-core": "2.0.1-alpha.363",
|
16
|
+
"@binance-chain/javascript-sdk": "^4.1.1",
|
17
|
+
"tslib": "^2.0.0"
|
18
|
+
},
|
19
|
+
"peerDependencies": {}
|
20
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
package/src/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/blockchain/bnb/src/index.ts"],"names":[],"mappings":";;;AAMA,wDAA6B"}
|
@@ -0,0 +1,212 @@
|
|
1
|
+
import { SDKArguments } from '@tatumio/shared-abstract-sdk';
|
2
|
+
import { BnbBeaconChainService } from '@tatumio/api-client';
|
3
|
+
import { BnbApiCallsType } from '../index';
|
4
|
+
export declare const TatumBnbSDK: (args: SDKArguments, apiCalls?: BnbApiCallsType) => {
|
5
|
+
wallet: {
|
6
|
+
generateWallet: (testnet: boolean) => Promise<{
|
7
|
+
address: string;
|
8
|
+
privateKey: string;
|
9
|
+
}>;
|
10
|
+
generatePrivateKey: (len?: number) => string;
|
11
|
+
getAddressFromPrivateKey: (privateKeyHex: string, prefix?: string) => string;
|
12
|
+
getPrivateKeyFromMnemonic: (mnemonic: string, derive?: boolean, index?: number, password?: string) => string;
|
13
|
+
getPublicKeyFromPrivateKey: (privateKeyHex: string) => string;
|
14
|
+
getAddressFromPublicKey: (publicKeyHex: string, prefix?: string) => string;
|
15
|
+
};
|
16
|
+
transaction: {
|
17
|
+
prepareTransaction: (amount: string, address: string, currency: string, key: string, testnet: boolean, memo?: string, signatureId?: string, withdrawalId?: string, from?: string) => Promise<string>;
|
18
|
+
sendTransaction: (body: Omit<import("@tatumio/api-client").TransferBnbBlockchain, "fromPrivateKey"> & Partial<import("@tatumio/api-client").SignatureId & {
|
19
|
+
index: number;
|
20
|
+
}> & Partial<Pick<import("@tatumio/api-client").TransferBnbBlockchain, "fromPrivateKey">> & Partial<{
|
21
|
+
mnemonic: string;
|
22
|
+
}>, options: {
|
23
|
+
testnet: boolean;
|
24
|
+
}) => Promise<import("@tatumio/api-client").TransactionHash>;
|
25
|
+
getMsgData: (amount: string, key: string, address: string, currency: string, testnet: boolean, from?: string) => {
|
26
|
+
fromAddress: string;
|
27
|
+
msg: {
|
28
|
+
inputs: {
|
29
|
+
address: Buffer;
|
30
|
+
coins: {
|
31
|
+
denom: string;
|
32
|
+
amount: number;
|
33
|
+
}[];
|
34
|
+
}[];
|
35
|
+
outputs: {
|
36
|
+
address: Buffer;
|
37
|
+
coins: {
|
38
|
+
denom: string;
|
39
|
+
amount: number;
|
40
|
+
}[];
|
41
|
+
}[];
|
42
|
+
aminoPrefix: import("@binance-chain/javascript-sdk/lib/types").AminoPrefix;
|
43
|
+
};
|
44
|
+
signMsg: {
|
45
|
+
inputs: {
|
46
|
+
address: string;
|
47
|
+
coins: {
|
48
|
+
denom: string;
|
49
|
+
amount: number;
|
50
|
+
}[];
|
51
|
+
}[];
|
52
|
+
outputs: {
|
53
|
+
address: string;
|
54
|
+
coins: {
|
55
|
+
denom: string;
|
56
|
+
amount: number;
|
57
|
+
}[];
|
58
|
+
}[];
|
59
|
+
};
|
60
|
+
};
|
61
|
+
signBnbTx: (testnet: boolean, key: string, fromAddress: string, msg: any, signMsg: any, amount: string, memo?: string, provider?: string) => Promise<string>;
|
62
|
+
};
|
63
|
+
kms: {
|
64
|
+
sign: (tx: import("@tatumio/api-client").PendingTransaction, fromPrivateKey: string, testnet: boolean, provider?: string) => Promise<string>;
|
65
|
+
};
|
66
|
+
virtualAccount: {
|
67
|
+
sendTransactionFromVirtualAccountToBlockchain: (testnet: boolean, body: Omit<import("@tatumio/api-client").TransferBnb, "fromPrivateKey"> & Partial<import("@tatumio/api-client").SignatureId & {
|
68
|
+
index: number;
|
69
|
+
}> & Partial<Pick<import("@tatumio/api-client").TransferBnb, "fromPrivateKey">> & Partial<{
|
70
|
+
mnemonic: string;
|
71
|
+
}>) => Promise<{
|
72
|
+
signatureId: string;
|
73
|
+
txId?: undefined;
|
74
|
+
id?: undefined;
|
75
|
+
completed?: undefined;
|
76
|
+
} | {
|
77
|
+
txId: string;
|
78
|
+
id: string;
|
79
|
+
completed: boolean;
|
80
|
+
signatureId?: undefined;
|
81
|
+
}>;
|
82
|
+
depositAddress: {
|
83
|
+
checkExists: (address: string, index?: number) => Promise<any>;
|
84
|
+
create: any;
|
85
|
+
createMultiple: any;
|
86
|
+
assign: any;
|
87
|
+
remove: any;
|
88
|
+
getByAccount: any;
|
89
|
+
};
|
90
|
+
withdrawal: {
|
91
|
+
getAll: (status?: "InProgress" | "Done" | "Cancelled", pageSize?: number, offset?: number) => Promise<any[]>;
|
92
|
+
broadcast: any;
|
93
|
+
create: any;
|
94
|
+
complete: any;
|
95
|
+
};
|
96
|
+
storeTokenAddress: any;
|
97
|
+
};
|
98
|
+
blockchain: {
|
99
|
+
generateWallet: typeof BnbBeaconChainService.bnbGenerateWallet;
|
100
|
+
getCurrentBlock: typeof BnbBeaconChainService.bnbGetCurrentBlock;
|
101
|
+
getBlock: typeof BnbBeaconChainService.bnbGetBlock;
|
102
|
+
getAccount: typeof BnbBeaconChainService.bnbGetAccount;
|
103
|
+
getTransaction: typeof BnbBeaconChainService.bnbGetTransaction;
|
104
|
+
getTxByAccount: typeof BnbBeaconChainService.bnbGetTxByAccount;
|
105
|
+
blockchainTransfer: typeof BnbBeaconChainService.bnbBlockchainTransfer;
|
106
|
+
broadcast: typeof BnbBeaconChainService.bnbBroadcast;
|
107
|
+
};
|
108
|
+
getExchangeRate(basePair?: import("@tatumio/api-client").Fiat): import("@tatumio/api-client").CancelablePromise<import("@tatumio/api-client").ExchangeRate>;
|
109
|
+
storage: {
|
110
|
+
upload: typeof import("@tatumio/api-client").IpfsService.storeIpfs;
|
111
|
+
get: typeof import("@tatumio/api-client").IpfsService.getIpfsData;
|
112
|
+
};
|
113
|
+
subscriptions: typeof import("@tatumio/api-client").NotificationSubscriptionsService;
|
114
|
+
security: {
|
115
|
+
checkMaliciousAddress: typeof import("@tatumio/api-client").MaliciousAddressService.checkMalicousAddress;
|
116
|
+
};
|
117
|
+
tatum: {
|
118
|
+
getCredits: typeof import("@tatumio/api-client").ServiceUtilsService.getCredits;
|
119
|
+
getVersion: typeof import("@tatumio/api-client").ServiceUtilsService.getVersion;
|
120
|
+
freezeApiKey: typeof import("@tatumio/api-client").ServiceUtilsService.freezeApiKey;
|
121
|
+
unfreezeApiKey: typeof import("@tatumio/api-client").ServiceUtilsService.unfreezeApiKey;
|
122
|
+
};
|
123
|
+
custodialManagedWallet: {
|
124
|
+
transfer: typeof import("@tatumio/api-client").CustodialManagedWalletsService.custodialTransferManagedAddress;
|
125
|
+
getAll: typeof import("@tatumio/api-client").CustodialManagedWalletsService.custodialGetWallets;
|
126
|
+
create: typeof import("@tatumio/api-client").CustodialManagedWalletsService.custodialCreateWallet;
|
127
|
+
delete: typeof import("@tatumio/api-client").CustodialManagedWalletsService.custodialDeleteWallet;
|
128
|
+
get: typeof import("@tatumio/api-client").CustodialManagedWalletsService.custodialGetWallet;
|
129
|
+
};
|
130
|
+
nft: {
|
131
|
+
deployNFTSmartContract: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftDeployErc721;
|
132
|
+
addNFTMinter: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftAddMinter;
|
133
|
+
mintNFT: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftMintErc721;
|
134
|
+
mintMultipleNFTs: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftMintMultipleErc721;
|
135
|
+
burnNFT: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftBurnErc721;
|
136
|
+
transferNFT: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftTransferErc721;
|
137
|
+
updateNFTRoyalty: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftUpdateCashbackErc721;
|
138
|
+
getNFTTransaction: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetTransactErc721;
|
139
|
+
getNFTTransactionsByToken: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetTransactionByToken;
|
140
|
+
getNFTTransactionsByAddress: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetTransactionByAddress;
|
141
|
+
getNFTsByAddress: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetTokensByAddressErc721;
|
142
|
+
getNFTProvenanceData: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetProvenanceDataErc721;
|
143
|
+
getNFTMetadataURI: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetMetadataErc721;
|
144
|
+
getNFTRoyalty: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetRoyaltyErc721;
|
145
|
+
getNFTAccountBalance: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetBalanceErc721;
|
146
|
+
getNFTContractAddress: typeof import("@tatumio/api-client").NftErc721OrCompatibleService.nftGetContractAddress;
|
147
|
+
getNFTImage: (chain: "ETH" | "BSC" | "MATIC" | "CELO" | "FLOW" | "TRON" | "ONE" | "KLAY" | "SOL" | "KCS", contractAddress: string, tokenId: string, account?: string) => Promise<{
|
148
|
+
originalUrl: string;
|
149
|
+
publicUrl: string;
|
150
|
+
}>;
|
151
|
+
prepareAddNftMinterAbstraction: (body: import("@tatumio/api-client").AddNftMinter | import("@tatumio/api-client").AddNftMinterKMS) => string[];
|
152
|
+
};
|
153
|
+
ledger: {
|
154
|
+
customer: {
|
155
|
+
get: typeof import("@tatumio/api-client").CustomerService.getCustomerByExternalOrInternalId;
|
156
|
+
getAll: typeof import("@tatumio/api-client").CustomerService.findAllCustomers;
|
157
|
+
update: typeof import("@tatumio/api-client").CustomerService.updateCustomer;
|
158
|
+
activate: typeof import("@tatumio/api-client").CustomerService.activateCustomer;
|
159
|
+
deactivate: typeof import("@tatumio/api-client").CustomerService.deactivateCustomer;
|
160
|
+
enable: typeof import("@tatumio/api-client").CustomerService.enableCustomer;
|
161
|
+
disable: typeof import("@tatumio/api-client").CustomerService.disableCustomer;
|
162
|
+
};
|
163
|
+
orderBook: {
|
164
|
+
getHistorical: typeof import("@tatumio/api-client").OrderBookService.getHistoricalTradesBody;
|
165
|
+
getActiveBuyTrades: typeof import("@tatumio/api-client").OrderBookService.getBuyTradesBody;
|
166
|
+
getActiveSellTrades: typeof import("@tatumio/api-client").OrderBookService.getSellTradesBody;
|
167
|
+
newTrade: typeof import("@tatumio/api-client").OrderBookService.storeTrade;
|
168
|
+
get: typeof import("@tatumio/api-client").OrderBookService.getTradeById;
|
169
|
+
cancel: typeof import("@tatumio/api-client").OrderBookService.deleteTrade;
|
170
|
+
cancelByAccount: typeof import("@tatumio/api-client").OrderBookService.deleteAccountTrades;
|
171
|
+
};
|
172
|
+
transaction: {
|
173
|
+
send: typeof import("@tatumio/api-client").TransactionService.sendTransaction;
|
174
|
+
sendMultiple: typeof import("@tatumio/api-client").TransactionService.sendTransactionBatch;
|
175
|
+
getAll: typeof import("@tatumio/api-client").TransactionService.getTransactions;
|
176
|
+
getAllByAccount: typeof import("@tatumio/api-client").TransactionService.getTransactionsByAccountId;
|
177
|
+
getAllByCustomer: typeof import("@tatumio/api-client").TransactionService.getTransactionsByCustomerId;
|
178
|
+
getAllByReference: typeof import("@tatumio/api-client").TransactionService.getTransactionsByReference;
|
179
|
+
countByAccount: (filter: import("@tatumio/api-client").TransactionFilter) => import("@tatumio/api-client").CancelablePromise<number | import("@tatumio/api-client").Transaction[]>;
|
180
|
+
countByCustomer: (filter: import("@tatumio/api-client").TransactionFilterCustomer) => import("@tatumio/api-client").CancelablePromise<number | import("@tatumio/api-client").Transaction[]>;
|
181
|
+
};
|
182
|
+
virtualCurrency: {
|
183
|
+
create: typeof import("@tatumio/api-client").VirtualCurrencyService.createCurrency;
|
184
|
+
mint: typeof import("@tatumio/api-client").VirtualCurrencyService.mintCurrency;
|
185
|
+
revoke: typeof import("@tatumio/api-client").VirtualCurrencyService.revokeCurrency;
|
186
|
+
getByName: typeof import("@tatumio/api-client").VirtualCurrencyService.getCurrency;
|
187
|
+
update: typeof import("@tatumio/api-client").VirtualCurrencyService.updateCurrency;
|
188
|
+
};
|
189
|
+
blockAmount: {
|
190
|
+
block: typeof import("@tatumio/api-client").AccountService.blockAmount;
|
191
|
+
unblock: typeof import("@tatumio/api-client").AccountService.deleteBlockAmount;
|
192
|
+
unblockWithTransaction: typeof import("@tatumio/api-client").AccountService.unblockAmountWithTransaction;
|
193
|
+
};
|
194
|
+
account: {
|
195
|
+
get: typeof import("@tatumio/api-client").AccountService.getAccountByAccountId;
|
196
|
+
getAll: typeof import("@tatumio/api-client").AccountService.getAccounts;
|
197
|
+
getByCustomerId: typeof import("@tatumio/api-client").AccountService.getAccountsByCustomerId;
|
198
|
+
getBalance: typeof import("@tatumio/api-client").AccountService.getAccountBalance;
|
199
|
+
create: typeof import("@tatumio/api-client").AccountService.createAccount;
|
200
|
+
createMultiple: typeof import("@tatumio/api-client").AccountService.createAccountBatch;
|
201
|
+
update: typeof import("@tatumio/api-client").AccountService.updateAccountByAccountId;
|
202
|
+
getBlockedAmountsByAccountId: typeof import("@tatumio/api-client").AccountService.getBlockAmountById;
|
203
|
+
activate: typeof import("@tatumio/api-client").AccountService.activateAccount;
|
204
|
+
deactivate: typeof import("@tatumio/api-client").AccountService.deactivateAccount;
|
205
|
+
freeze: typeof import("@tatumio/api-client").AccountService.freezeAccount;
|
206
|
+
unfreeze: typeof import("@tatumio/api-client").AccountService.unfreezeAccount;
|
207
|
+
generate: (account: import("@tatumio/api-client").CreateAccount & {
|
208
|
+
xpub?: string;
|
209
|
+
}, generateNewWalletFn: any, generateNewWallet?: boolean, testnet?: boolean, webhookUrl?: string) => Promise<any>;
|
210
|
+
};
|
211
|
+
};
|
212
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { SdkError, SdkErrorCode } from '@tatumio/shared-abstract-sdk';
|
2
|
+
export declare const BNB_ERRORS_MAPPING: {
|
3
|
+
'chain type is invalid': SdkErrorCode;
|
4
|
+
'TX preparation failure': SdkErrorCode;
|
5
|
+
'insufficient funds on the sender account for performing the transaction': SdkErrorCode;
|
6
|
+
};
|
7
|
+
export declare type BnbSdkErrorCode = SdkErrorCode.KMS_CHAIN_MISMATCH | SdkErrorCode.TX_PREPARATION_FAILED | SdkErrorCode.INSUFFICIENT_FUNDS;
|
8
|
+
export declare class BnbSdkError extends SdkError {
|
9
|
+
constructor(error: Error | BnbSdkErrorCode, errorMessage?: string);
|
10
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BnbSdkError = exports.BNB_ERRORS_MAPPING = void 0;
|
4
|
+
const shared_abstract_sdk_1 = require("@tatumio/shared-abstract-sdk");
|
5
|
+
exports.BNB_ERRORS_MAPPING = {
|
6
|
+
'chain type is invalid': shared_abstract_sdk_1.SdkErrorCode.KMS_CHAIN_MISMATCH,
|
7
|
+
'TX preparation failure': shared_abstract_sdk_1.SdkErrorCode.TX_PREPARATION_FAILED,
|
8
|
+
'insufficient funds on the sender account for performing the transaction': shared_abstract_sdk_1.SdkErrorCode.INSUFFICIENT_FUNDS,
|
9
|
+
};
|
10
|
+
class BnbSdkError extends shared_abstract_sdk_1.SdkError {
|
11
|
+
constructor(error, errorMessage) {
|
12
|
+
if (typeof error === 'string') {
|
13
|
+
super({
|
14
|
+
code: error,
|
15
|
+
originalError: {
|
16
|
+
name: error,
|
17
|
+
message: errorMessage || '',
|
18
|
+
},
|
19
|
+
});
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
super({
|
23
|
+
originalError: error,
|
24
|
+
errorSubstringMapping: exports.BNB_ERRORS_MAPPING,
|
25
|
+
});
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.BnbSdkError = BnbSdkError;
|
30
|
+
//# sourceMappingURL=bnb.sdk.errors.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bnb.sdk.errors.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/bnb/src/lib/bnb.sdk.errors.ts"],"names":[],"mappings":";;;AAAA,sEAAqE;AAExD,QAAA,kBAAkB,GAAG;IAChC,uBAAuB,EAAE,kCAAY,CAAC,kBAAkB;IACxD,wBAAwB,EAAE,kCAAY,CAAC,qBAAqB;IAC5D,yEAAyE,EAAE,kCAAY,CAAC,kBAAkB;CAC3G,CAAA;AAOD,MAAa,WAAY,SAAQ,8BAAQ;IACvC,YAAY,KAA8B,EAAE,YAAqB;QAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,KAAK,CAAC;gBACJ,IAAI,EAAE,KAAK;gBACX,aAAa,EAAE;oBACb,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,YAAY,IAAI,EAAE;iBAC5B;aACF,CAAC,CAAA;SACH;aAAM;YACL,KAAK,CAAC;gBACJ,aAAa,EAAE,KAAK;gBACpB,qBAAqB,EAAE,0BAAkB;aAC1C,CAAC,CAAA;SACH;IACH,CAAC;CACF;AAjBD,kCAiBC"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TatumBnbSDK = void 0;
|
4
|
+
const api_client_1 = require("@tatumio/api-client");
|
5
|
+
const shared_blockchain_abstract_1 = require("@tatumio/shared-blockchain-abstract");
|
6
|
+
const bnb_tx_1 = require("./services/bnb.tx");
|
7
|
+
const bnb_kms_1 = require("./services/bnb.kms");
|
8
|
+
const bnb_wallet_1 = require("./services/bnb.wallet");
|
9
|
+
const shared_core_1 = require("@tatumio/shared-core");
|
10
|
+
const bnb_virtualAccount_1 = require("./services/bnb.virtualAccount");
|
11
|
+
const bnb_web3_1 = require("./services/bnb.web3");
|
12
|
+
const TatumBnbSDK = (args, apiCalls = { getAccountInfo: api_client_1.ApiServices.blockchain.bnb.bnbGetAccount }) => {
|
13
|
+
const web3 = (0, bnb_web3_1.bnbWeb3)(args.provider);
|
14
|
+
return Object.assign(Object.assign({}, (0, shared_blockchain_abstract_1.abstractBlockchainSdk)(Object.assign(Object.assign({}, args), { blockchain: shared_core_1.Blockchain.BNB }))), { wallet: (0, bnb_wallet_1.bnbWallet)(), transaction: (0, bnb_tx_1.bnbTxService)({ web3 }, apiCalls), kms: (0, bnb_kms_1.bnbKmsService)({ web3 }), virtualAccount: (0, bnb_virtualAccount_1.bnbVirtualAccountService)({ web3 }, apiCalls), blockchain: {
|
15
|
+
generateWallet: api_client_1.BnbBeaconChainService.bnbGenerateWallet,
|
16
|
+
getCurrentBlock: api_client_1.BnbBeaconChainService.bnbGetCurrentBlock,
|
17
|
+
getBlock: api_client_1.BnbBeaconChainService.bnbGetBlock,
|
18
|
+
getAccount: api_client_1.BnbBeaconChainService.bnbGetAccount,
|
19
|
+
getTransaction: api_client_1.BnbBeaconChainService.bnbGetTransaction,
|
20
|
+
getTxByAccount: api_client_1.BnbBeaconChainService.bnbGetTxByAccount,
|
21
|
+
blockchainTransfer: api_client_1.BnbBeaconChainService.bnbBlockchainTransfer,
|
22
|
+
broadcast: api_client_1.BnbBeaconChainService.bnbBroadcast,
|
23
|
+
} });
|
24
|
+
};
|
25
|
+
exports.TatumBnbSDK = TatumBnbSDK;
|
26
|
+
//# sourceMappingURL=bnb.sdk.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bnb.sdk.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/bnb/src/lib/bnb.sdk.ts"],"names":[],"mappings":";;;AACA,oDAAwE;AACxE,oFAA2E;AAE3E,8CAAgD;AAChD,gDAAkD;AAClD,sDAAiD;AACjD,sDAAiD;AACjD,sEAAwE;AACxE,kDAAsD;AAE/C,MAAM,WAAW,GAAG,CACzB,IAAkB,EAClB,WAA4B,EAAE,cAAc,EAAE,wBAAW,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,EAAE,EACxF,EAAE;IACF,MAAM,IAAI,GAAY,IAAA,kBAAO,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAE5C,uCACK,IAAA,kDAAqB,kCAAM,IAAI,KAAE,UAAU,EAAE,wBAAU,CAAC,GAAG,IAAG,KACjE,MAAM,EAAE,IAAA,sBAAS,GAAE,EACnB,WAAW,EAAE,IAAA,qBAAY,EAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,EAC7C,GAAG,EAAE,IAAA,uBAAa,EAAC,EAAE,IAAI,EAAE,CAAC,EAC5B,cAAc,EAAE,IAAA,6CAAwB,EAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,EAC5D,UAAU,EAAE;YACV,cAAc,EAAE,kCAAqB,CAAC,iBAAiB;YACvD,eAAe,EAAE,kCAAqB,CAAC,kBAAkB;YACzD,QAAQ,EAAE,kCAAqB,CAAC,WAAW;YAC3C,UAAU,EAAE,kCAAqB,CAAC,aAAa;YAC/C,cAAc,EAAE,kCAAqB,CAAC,iBAAiB;YACvD,cAAc,EAAE,kCAAqB,CAAC,iBAAiB;YACvD,kBAAkB,EAAE,kCAAqB,CAAC,qBAAqB;YAC/D,SAAS,EAAE,kCAAqB,CAAC,YAAY;SAC9C,IACF;AACH,CAAC,CAAA;AAvBY,QAAA,WAAW,eAuBvB"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { PendingTransaction } from '@tatumio/api-client';
|
2
|
+
import { BnbWeb3 } from './bnb.web3';
|
3
|
+
export declare const bnbKmsService: (args: {
|
4
|
+
web3: BnbWeb3;
|
5
|
+
}) => {
|
6
|
+
sign: (tx: PendingTransaction, fromPrivateKey: string, testnet: boolean, provider?: string) => Promise<string>;
|
7
|
+
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.bnbKmsService = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const shared_blockchain_abstract_1 = require("@tatumio/shared-blockchain-abstract");
|
6
|
+
const api_client_1 = require("@tatumio/api-client");
|
7
|
+
const crypto_1 = require("@binance-chain/javascript-sdk/lib/crypto");
|
8
|
+
const shared_abstract_sdk_1 = require("@tatumio/shared-abstract-sdk");
|
9
|
+
const bnb_sdk_errors_1 = require("../bnb.sdk.errors");
|
10
|
+
const bnbKmsService = (args) => {
|
11
|
+
/**
|
12
|
+
* @param tx pending transaction data
|
13
|
+
* @param fromPrivateKey private key to be signed with
|
14
|
+
* @param testnet mainnet or testnet version
|
15
|
+
* @param provider
|
16
|
+
* @returns signed transaction to be sent to the blockchain
|
17
|
+
*/
|
18
|
+
const signBnbKMSTransaction = (tx, fromPrivateKey, testnet, provider) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
19
|
+
if (tx.chain !== api_client_1.Currency.BNB) {
|
20
|
+
throw new bnb_sdk_errors_1.BnbSdkError(shared_abstract_sdk_1.SdkErrorCode.KMS_CHAIN_MISMATCH);
|
21
|
+
}
|
22
|
+
const bnbClient = yield args.web3.getClient(testnet, fromPrivateKey, provider);
|
23
|
+
const fromAddress = (0, crypto_1.getAddressFromPrivateKey)(fromPrivateKey, testnet ? 'tbnb' : 'bnb');
|
24
|
+
const account = yield api_client_1.BnbBeaconChainService.bnbGetAccount(fromAddress);
|
25
|
+
bnbClient.setAccountNumber(account.account_number || 0);
|
26
|
+
const { msg, signMsg, memo } = JSON.parse(tx.serializedTransaction);
|
27
|
+
msg.inputs = msg.inputs.map((i) => {
|
28
|
+
i.address = Buffer.from(i.address.data);
|
29
|
+
return i;
|
30
|
+
});
|
31
|
+
msg.outputs = msg.outputs.map((i) => {
|
32
|
+
i.address = Buffer.from(i.address.data);
|
33
|
+
return i;
|
34
|
+
});
|
35
|
+
const signedTx = yield bnbClient._prepareTransaction(msg, signMsg, fromAddress, account.sequence, memo);
|
36
|
+
return signedTx.serialize();
|
37
|
+
});
|
38
|
+
return Object.assign(Object.assign({}, shared_blockchain_abstract_1.abstractBlockchainKms), { sign: signBnbKMSTransaction });
|
39
|
+
};
|
40
|
+
exports.bnbKmsService = bnbKmsService;
|
41
|
+
//# sourceMappingURL=bnb.kms.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bnb.kms.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/bnb/src/lib/services/bnb.kms.ts"],"names":[],"mappings":";;;;AAAA,oFAA2E;AAC3E,oDAAyF;AACzF,qEAAmF;AACnF,sEAA2D;AAC3D,sDAA+C;AAGxC,MAAM,aAAa,GAAG,CAAC,IAAuB,EAAE,EAAE;IACvD;;;;;;OAMG;IACH,MAAM,qBAAqB,GAAG,CAC5B,EAAsB,EACtB,cAAsB,EACtB,OAAgB,EAChB,QAAiB,EACjB,EAAE;QACF,IAAI,EAAE,CAAC,KAAK,KAAK,qBAAQ,CAAC,GAAG,EAAE;YAC7B,MAAM,IAAI,4BAAW,CAAC,kCAAY,CAAC,kBAAkB,CAAC,CAAA;SACvD;QAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAA;QAC9E,MAAM,WAAW,GAAG,IAAA,iCAAwB,EAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QACtF,MAAM,OAAO,GAAG,MAAM,kCAAqB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;QACtE,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,cAAc,IAAI,CAAC,CAAC,CAAA;QACvD,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAA;QACnE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE;YACrC,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACvC,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;QACF,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE;YACvC,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACvC,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;QACF,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACvG,OAAO,QAAQ,CAAC,SAAS,EAAE,CAAA;IAC7B,CAAC,CAAA,CAAA;IAED,uCACK,kDAAqB,KACxB,IAAI,EAAE,qBAAqB,IAC5B;AACH,CAAC,CAAA;AAvCY,QAAA,aAAa,iBAuCzB"}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { BnbApiCallsType } from '../../index';
|
2
|
+
import { TransferBnbBlockchain } from '@tatumio/api-client';
|
3
|
+
import { AminoPrefix } from '@binance-chain/javascript-sdk/lib/types';
|
4
|
+
import { FromPrivateKeyOrSignatureId } from '@tatumio/shared-blockchain-abstract';
|
5
|
+
import { BnbWeb3 } from './bnb.web3';
|
6
|
+
declare type TransferBnb = FromPrivateKeyOrSignatureId<TransferBnbBlockchain>;
|
7
|
+
export declare const bnbTxService: (args: {
|
8
|
+
web3: BnbWeb3;
|
9
|
+
}, apiCalls: BnbApiCallsType) => {
|
10
|
+
prepareTransaction: (amount: string, address: string, currency: string, key: string, testnet: boolean, memo?: string, signatureId?: string, withdrawalId?: string, from?: string) => Promise<string>;
|
11
|
+
sendTransaction: (body: TransferBnb, options: {
|
12
|
+
testnet: boolean;
|
13
|
+
}) => Promise<import("@tatumio/api-client").TransactionHash>;
|
14
|
+
getMsgData: (amount: string, key: string, address: string, currency: string, testnet: boolean, from?: string) => {
|
15
|
+
fromAddress: string;
|
16
|
+
msg: {
|
17
|
+
inputs: {
|
18
|
+
address: Buffer;
|
19
|
+
coins: {
|
20
|
+
denom: string;
|
21
|
+
amount: number;
|
22
|
+
}[];
|
23
|
+
}[];
|
24
|
+
outputs: {
|
25
|
+
address: Buffer;
|
26
|
+
coins: {
|
27
|
+
denom: string;
|
28
|
+
amount: number;
|
29
|
+
}[];
|
30
|
+
}[];
|
31
|
+
aminoPrefix: AminoPrefix;
|
32
|
+
};
|
33
|
+
signMsg: {
|
34
|
+
inputs: {
|
35
|
+
address: string;
|
36
|
+
coins: {
|
37
|
+
denom: string;
|
38
|
+
amount: number;
|
39
|
+
}[];
|
40
|
+
}[];
|
41
|
+
outputs: {
|
42
|
+
address: string;
|
43
|
+
coins: {
|
44
|
+
denom: string;
|
45
|
+
amount: number;
|
46
|
+
}[];
|
47
|
+
}[];
|
48
|
+
};
|
49
|
+
};
|
50
|
+
signBnbTx: (testnet: boolean, key: string, fromAddress: string, msg: any, signMsg: any, amount: string, memo?: string, provider?: string) => Promise<string>;
|
51
|
+
};
|
52
|
+
export {};
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.bnbTxService = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const api_client_1 = require("@tatumio/api-client");
|
6
|
+
const bignumber_js_1 = require("bignumber.js");
|
7
|
+
const shared_abstract_sdk_1 = require("@tatumio/shared-abstract-sdk");
|
8
|
+
const crypto_1 = require("@binance-chain/javascript-sdk/lib/crypto");
|
9
|
+
const types_1 = require("@binance-chain/javascript-sdk/lib/types");
|
10
|
+
const bnb_sdk_errors_1 = require("../bnb.sdk.errors");
|
11
|
+
const bnbTxService = (args, apiCalls) => {
|
12
|
+
/**
|
13
|
+
* Parses data which will be used in the transaction
|
14
|
+
* @param amount amount to send
|
15
|
+
* @param key private key to sign with
|
16
|
+
* @param address blockchain address where the token should be sent
|
17
|
+
* @param currency transaction currency
|
18
|
+
* @param testnet mainnet or testnet version
|
19
|
+
* @param from address from which to send
|
20
|
+
* @returns transaction data (fromAddress, msg, signMsg) to be prepared for signing
|
21
|
+
*/
|
22
|
+
const getMsgData = (amount, key, address, currency, testnet, from) => {
|
23
|
+
const fromAddress = from || (0, crypto_1.getAddressFromPrivateKey)(key, testnet ? 'tbnb' : 'bnb');
|
24
|
+
const accCode = (0, crypto_1.decodeAddress)(fromAddress);
|
25
|
+
const toAccCode = (0, crypto_1.decodeAddress)(address);
|
26
|
+
const coin = {
|
27
|
+
denom: currency,
|
28
|
+
amount: Math.round(new bignumber_js_1.BigNumber(amount).multipliedBy(new bignumber_js_1.BigNumber(10).pow(8)).toNumber()),
|
29
|
+
};
|
30
|
+
return {
|
31
|
+
fromAddress,
|
32
|
+
msg: {
|
33
|
+
inputs: [
|
34
|
+
{
|
35
|
+
address: accCode,
|
36
|
+
coins: [coin],
|
37
|
+
},
|
38
|
+
],
|
39
|
+
outputs: [
|
40
|
+
{
|
41
|
+
address: toAccCode,
|
42
|
+
coins: [coin],
|
43
|
+
},
|
44
|
+
],
|
45
|
+
aminoPrefix: types_1.AminoPrefix.MsgSend,
|
46
|
+
},
|
47
|
+
signMsg: {
|
48
|
+
inputs: [
|
49
|
+
{
|
50
|
+
address: fromAddress,
|
51
|
+
coins: [coin],
|
52
|
+
},
|
53
|
+
],
|
54
|
+
outputs: [
|
55
|
+
{
|
56
|
+
address,
|
57
|
+
coins: [coin],
|
58
|
+
},
|
59
|
+
],
|
60
|
+
},
|
61
|
+
};
|
62
|
+
};
|
63
|
+
/**
|
64
|
+
* Send BNB transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
|
65
|
+
* @param body content of the transaction to broadcast
|
66
|
+
* @param options mainnet or testnet version
|
67
|
+
* @returns transaction id of the transaction in the blockchain
|
68
|
+
*/
|
69
|
+
const sendTransaction = (body, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
70
|
+
if (body.signatureId) {
|
71
|
+
return api_client_1.ApiServices.blockchain.bnb.bnbBlockchainTransfer(body);
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
return api_client_1.ApiServices.blockchain.bnb.bnbBroadcast({
|
75
|
+
txData: yield prepareTransaction(body.amount, body.to, api_client_1.Currency.BNB, body.fromPrivateKey, options.testnet),
|
76
|
+
});
|
77
|
+
}
|
78
|
+
});
|
79
|
+
/**
|
80
|
+
* Sign BNB transaction with private keys locally. Nothing is broadcast to the blockchain.
|
81
|
+
* @param amount amount to send
|
82
|
+
* @param address blockchain address where the token should be sent
|
83
|
+
* @param currency transaction currency
|
84
|
+
* @param key private key to sign with
|
85
|
+
* @param testnet mainnet or testnet version
|
86
|
+
* @param memo transaction memo
|
87
|
+
* @param signatureId signature id to sign with
|
88
|
+
* @param withdrawalId id of the withdrawal transaction
|
89
|
+
* @param from address from which to send
|
90
|
+
* @returns transaction data to be broadcast to blockchain
|
91
|
+
*/
|
92
|
+
const prepareTransaction = (amount, address, currency, key, testnet, memo, signatureId, withdrawalId, from) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
93
|
+
const { fromAddress, msg, signMsg } = getMsgData(amount, key, address, currency, testnet, from);
|
94
|
+
return signBnbTx(testnet, key, fromAddress, msg, signMsg, amount, memo);
|
95
|
+
});
|
96
|
+
/**
|
97
|
+
*
|
98
|
+
* @param testnet mainnet or testnet version
|
99
|
+
* @param key private key to sign with
|
100
|
+
* @param fromAddress address from which to send
|
101
|
+
* @param msg data from the getMsgData function
|
102
|
+
* @param signMsg data from the getMsgData function
|
103
|
+
* @param amount amount to send
|
104
|
+
* @param memo transaction memo
|
105
|
+
* @param provider
|
106
|
+
* @returns transaction id of the transaction in the blockchain
|
107
|
+
*/
|
108
|
+
const signBnbTx = (testnet, key, fromAddress, msg, signMsg, amount, memo, provider) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
109
|
+
var _a;
|
110
|
+
try {
|
111
|
+
const bnbClient = yield args.web3.getClient(testnet, key, provider);
|
112
|
+
const account = yield apiCalls.getAccountInfo(fromAddress);
|
113
|
+
const balance = (_a = account.balances) === null || _a === void 0 ? void 0 : _a.find((b) => b.symbol && b.symbol.toUpperCase() === 'BNB');
|
114
|
+
const accountBalance = new bignumber_js_1.BigNumber((balance === null || balance === void 0 ? void 0 : balance.free) || 0);
|
115
|
+
const fee = 0.000075;
|
116
|
+
const requiredBalance = new bignumber_js_1.BigNumber(amount).plus(fee);
|
117
|
+
if (accountBalance.isLessThan(requiredBalance)) {
|
118
|
+
throw new bnb_sdk_errors_1.BnbSdkError(shared_abstract_sdk_1.SdkErrorCode.INSUFFICIENT_FUNDS, `Insufficient funds to create transaction from sender account ${account} -> available balance is ${accountBalance.toString()}, required balance is ${requiredBalance.toString()}.`);
|
119
|
+
}
|
120
|
+
bnbClient.setAccountNumber(account.account_number || 0);
|
121
|
+
const signedTx = yield bnbClient._prepareTransaction(msg, signMsg, fromAddress, account.sequence, memo);
|
122
|
+
return signedTx.serialize();
|
123
|
+
}
|
124
|
+
catch (e) {
|
125
|
+
if ((0, shared_abstract_sdk_1.isSdkError)(e)) {
|
126
|
+
throw e;
|
127
|
+
}
|
128
|
+
throw new bnb_sdk_errors_1.BnbSdkError(shared_abstract_sdk_1.SdkErrorCode.TX_PREPARATION_FAILED);
|
129
|
+
}
|
130
|
+
});
|
131
|
+
return {
|
132
|
+
prepareTransaction,
|
133
|
+
sendTransaction,
|
134
|
+
getMsgData,
|
135
|
+
signBnbTx,
|
136
|
+
};
|
137
|
+
};
|
138
|
+
exports.bnbTxService = bnbTxService;
|
139
|
+
//# sourceMappingURL=bnb.tx.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bnb.tx.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/bnb/src/lib/services/bnb.tx.ts"],"names":[],"mappings":";;;;AACA,oDAA4G;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B,eAAe;QACf,UAAU;QACV,SAAS;KACV,CAAA;AACH,CAAC,CAAA;AApKY,QAAA,YAAY,gBAoKxB"}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { FromPrivateKeyOrSignatureId } from '@tatumio/shared-blockchain-abstract';
|
2
|
+
import { TransferBnb } from '@tatumio/api-client';
|
3
|
+
import { BnbApiCallsType } from '@tatumio/bnb';
|
4
|
+
import { BnbWeb3 } from './bnb.web3';
|
5
|
+
declare type TransferBnbPkOrSignature = FromPrivateKeyOrSignatureId<TransferBnb>;
|
6
|
+
export declare const bnbVirtualAccountService: (args: {
|
7
|
+
web3: BnbWeb3;
|
8
|
+
}, apiCalls: BnbApiCallsType) => {
|
9
|
+
sendTransactionFromVirtualAccountToBlockchain: (testnet: boolean, body: TransferBnbPkOrSignature) => Promise<{
|
10
|
+
signatureId: string;
|
11
|
+
txId?: undefined;
|
12
|
+
id?: undefined;
|
13
|
+
completed?: undefined;
|
14
|
+
} | {
|
15
|
+
txId: string;
|
16
|
+
id: string;
|
17
|
+
completed: boolean;
|
18
|
+
signatureId?: undefined;
|
19
|
+
}>;
|
20
|
+
depositAddress: {
|
21
|
+
checkExists: (address: string, index?: number) => Promise<any>;
|
22
|
+
create: any;
|
23
|
+
createMultiple: any; /**
|
24
|
+
* Send BNB transaction from Tatum Ledger account to the blockchain. This method broadcasts signed transaction to the blockchain.
|
25
|
+
* @param body content of the transaction to broadcast
|
26
|
+
* @param testnet chain to work with
|
27
|
+
* @returns transaction id of the transaction in the blockchain or id of the withdrawal
|
28
|
+
*/
|
29
|
+
assign: any;
|
30
|
+
remove: any;
|
31
|
+
getByAccount: any;
|
32
|
+
};
|
33
|
+
withdrawal: {
|
34
|
+
getAll: (status?: "InProgress" | "Done" | "Cancelled", pageSize?: number, offset?: number) => Promise<any[]>;
|
35
|
+
broadcast: any;
|
36
|
+
create: any;
|
37
|
+
complete: any;
|
38
|
+
};
|
39
|
+
storeTokenAddress: any;
|
40
|
+
};
|
41
|
+
export {};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.bnbVirtualAccountService = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const shared_blockchain_abstract_1 = require("@tatumio/shared-blockchain-abstract");
|
6
|
+
const api_client_1 = require("@tatumio/api-client");
|
7
|
+
const bnb_tx_1 = require("./bnb.tx");
|
8
|
+
const shared_core_1 = require("@tatumio/shared-core");
|
9
|
+
const bnbVirtualAccountService = (args, apiCalls) => {
|
10
|
+
const txService = (0, bnb_tx_1.bnbTxService)(args, apiCalls);
|
11
|
+
/**
|
12
|
+
* Send BNB transaction from Tatum Ledger account to the blockchain. This method broadcasts signed transaction to the blockchain.
|
13
|
+
* @param body content of the transaction to broadcast
|
14
|
+
* @param testnet chain to work with
|
15
|
+
* @returns transaction id of the transaction in the blockchain or id of the withdrawal
|
16
|
+
*/
|
17
|
+
const sendTransactionFromVirtualAccountToBlockchain = (testnet, body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
18
|
+
const fee = '0.000075';
|
19
|
+
const { id: withdrawalId } = yield api_client_1.ApiServices.offChain.withdrawal.storeWithdrawal(Object.assign(Object.assign({}, body), { fee }));
|
20
|
+
try {
|
21
|
+
const prepareTx = () => txService.prepareTransaction(body.amount, body.address, api_client_1.Currency.BNB, body.fromPrivateKey, testnet);
|
22
|
+
if (body.signatureId) {
|
23
|
+
return { signatureId: yield prepareTx() };
|
24
|
+
}
|
25
|
+
let txData;
|
26
|
+
try {
|
27
|
+
txData = yield prepareTx();
|
28
|
+
}
|
29
|
+
catch (e) {
|
30
|
+
console.log('Unable to prepare transaction, withdrawal cancelled.');
|
31
|
+
throw e;
|
32
|
+
}
|
33
|
+
try {
|
34
|
+
const response = yield api_client_1.ApiServices.offChain.withdrawal.broadcastBlockchainTransaction({
|
35
|
+
txData,
|
36
|
+
currency: api_client_1.Currency.BNB,
|
37
|
+
withdrawalId,
|
38
|
+
});
|
39
|
+
return { txId: response.txId, id: withdrawalId, completed: !!response.completed };
|
40
|
+
}
|
41
|
+
catch (e) {
|
42
|
+
console.log('Unable to broadcast transaction, withdrawal cancelled.');
|
43
|
+
throw e;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
catch (e) {
|
47
|
+
console.log('Unable to perform offchain <> blockchain transaction.');
|
48
|
+
throw e;
|
49
|
+
}
|
50
|
+
});
|
51
|
+
return Object.assign(Object.assign({}, (0, shared_blockchain_abstract_1.abstractBlockchainVirtualAccount)({ blockchain: shared_core_1.Blockchain.BNB })), { sendTransactionFromVirtualAccountToBlockchain });
|
52
|
+
};
|
53
|
+
exports.bnbVirtualAccountService = bnbVirtualAccountService;
|
54
|
+
//# sourceMappingURL=bnb.virtualAccount.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bnb.virtualAccount.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/bnb/src/lib/services/bnb.virtualAccount.ts"],"names":[],"mappings":";;;;AAAA,oFAG4C;AAC5C,oDAAwE;AACxE,qCAAuC;AAEvC,sDAAiD;AAK1C,MAAM,wBAAwB,GAAG,CAAC,IAAuB,EAAE,QAAyB,EAAE,EAAE;IAC7F,MAAM,SAAS,GAAG,IAAA,qBAAY,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IAE9C;;;;;OAKG;IACH,MAAM,6CAA6C,GAAG,CACpD,OAAgB,EAChB,IAA8B,EAC9B,EAAE;QACF,MAAM,GAAG,GAAG,UAAU,CAAA;QAEtB,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,MAAM,wBAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,eAAe,iCAAM,IAAI,KAAE,GAAG,IAAG,CAAA;QAEpG,IAAI;YACF,MAAM,SAAS,GAAG,GAAG,EAAE,CACrB,SAAS,CAAC,kBAAkB,CAC1B,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,EACZ,qBAAQ,CAAC,GAAG,EACZ,IAAI,CAAC,cAAwB,EAC7B,OAAO,CACR,CAAA;YAEH,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,EAAE,EAAE,CAAA;aAC1C;YAED,IAAI,MAAM,CAAA;YACV,IAAI;gBACF,MAAM,GAAG,MAAM,SAAS,EAAE,CAAA;aAC3B;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAA;gBACnE,MAAM,CAAC,CAAA;aACR;YAED,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,wBAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,8BAA8B,CAAC;oBACpF,MAAM;oBACN,QAAQ,EAAE,qBAAQ,CAAC,GAAG;oBACtB,YAAY;iBACb,CAAC,CAAA;gBACF,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;aAClF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAA;gBACrE,MAAM,CAAC,CAAA;aACR;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAA;YACpE,MAAM,CAAC,CAAA;SACR;IACH,CAAC,CAAA,CAAA;IAED,uCACK,IAAA,6DAAgC,EAAC,EAAE,UAAU,EAAE,wBAAU,CAAC,GAAG,EAAE,CAAC,KACnE,6CAA6C,IAC9C;AACH,CAAC,CAAA;AA5DY,QAAA,wBAAwB,4BA4DpC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare const bnbWallet: () => {
|
2
|
+
generateWallet: (testnet: boolean) => Promise<{
|
3
|
+
address: string;
|
4
|
+
privateKey: string;
|
5
|
+
}>;
|
6
|
+
generatePrivateKey: (len?: number) => string;
|
7
|
+
getAddressFromPrivateKey: (privateKeyHex: string, prefix?: string) => string;
|
8
|
+
getPrivateKeyFromMnemonic: (mnemonic: string, derive?: boolean, index?: number, password?: string) => string;
|
9
|
+
getPublicKeyFromPrivateKey: (privateKeyHex: string) => string;
|
10
|
+
getAddressFromPublicKey: (publicKeyHex: string, prefix?: string) => string;
|
11
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.bnbWallet = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const crypto_1 = require("@binance-chain/javascript-sdk/lib/crypto");
|
6
|
+
const generateBnbWallet = (testnet) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
7
|
+
const privateKey = (0, crypto_1.generatePrivateKey)();
|
8
|
+
const prefix = testnet ? 'tbnb' : 'bnb';
|
9
|
+
return {
|
10
|
+
address: (0, crypto_1.getAddressFromPrivateKey)(privateKey, prefix),
|
11
|
+
privateKey,
|
12
|
+
};
|
13
|
+
});
|
14
|
+
const bnbWallet = () => {
|
15
|
+
return {
|
16
|
+
generateWallet: generateBnbWallet,
|
17
|
+
generatePrivateKey: crypto_1.generatePrivateKey,
|
18
|
+
getAddressFromPrivateKey: crypto_1.getAddressFromPrivateKey,
|
19
|
+
getPrivateKeyFromMnemonic: crypto_1.getPrivateKeyFromMnemonic,
|
20
|
+
getPublicKeyFromPrivateKey: crypto_1.getPublicKeyFromPrivateKey,
|
21
|
+
getAddressFromPublicKey: crypto_1.getAddressFromPublicKey,
|
22
|
+
};
|
23
|
+
};
|
24
|
+
exports.bnbWallet = bnbWallet;
|
25
|
+
//# sourceMappingURL=bnb.wallet.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bnb.wallet.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/bnb/src/lib/services/bnb.wallet.ts"],"names":[],"mappings":";;;;AAAA,qEAMiD;AAEjD,MAAM,iBAAiB,GAAG,CAAO,OAAgB,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAA,2BAAkB,GAAE,CAAA;IACvC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAA;IACvC,OAAO;QACL,OAAO,EAAE,IAAA,iCAAwB,EAAC,UAAU,EAAE,MAAM,CAAC;QACrD,UAAU;KACX,CAAA;AACH,CAAC,CAAA,CAAA;AAEM,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,OAAO;QACL,cAAc,EAAE,iBAAiB;QACjC,kBAAkB,EAAlB,2BAAkB;QAClB,wBAAwB,EAAxB,iCAAwB;QACxB,yBAAyB,EAAzB,kCAAyB;QACzB,0BAA0B,EAA1B,mCAA0B;QAC1B,uBAAuB,EAAvB,gCAAuB;KACxB,CAAA;AACH,CAAC,CAAA;AATY,QAAA,SAAS,aASrB"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.bnbWeb3 = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const api_client_1 = require("@tatumio/api-client");
|
6
|
+
const javascript_sdk_1 = require("@binance-chain/javascript-sdk");
|
7
|
+
const shared_core_1 = require("@tatumio/shared-core");
|
8
|
+
const bnbWeb3 = (clientProvider) => {
|
9
|
+
return {
|
10
|
+
getClient(testnet, privateKey, provider) {
|
11
|
+
var _a;
|
12
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
13
|
+
const bnbClient = new javascript_sdk_1.BncClient((_a = provider !== null && provider !== void 0 ? provider : clientProvider) !== null && _a !== void 0 ? _a : shared_core_1.httpHelper.rpcEndpoint(shared_core_1.Blockchain.BNB, api_client_1.OpenAPI.BASE, api_client_1.TATUM_API_CONSTANTS.API_KEY));
|
14
|
+
bnbClient.chooseNetwork(testnet ? 'testnet' : 'mainnet');
|
15
|
+
yield bnbClient.setPrivateKey(privateKey, true);
|
16
|
+
yield bnbClient.initChain();
|
17
|
+
return bnbClient;
|
18
|
+
});
|
19
|
+
},
|
20
|
+
};
|
21
|
+
};
|
22
|
+
exports.bnbWeb3 = bnbWeb3;
|
23
|
+
//# sourceMappingURL=bnb.web3.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bnb.web3.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/bnb/src/lib/services/bnb.web3.ts"],"names":[],"mappings":";;;;AAAA,oDAAkE;AAClE,kEAAyD;AACzD,sDAA6D;AAMtD,MAAM,OAAO,GAAG,CAAC,cAAuB,EAAW,EAAE;IAC1D,OAAO;QACC,SAAS,CAAC,OAAgB,EAAE,UAAkB,EAAE,QAAiB;;;gBACrE,MAAM,SAAS,GAAG,IAAI,0BAAS,CAC7B,MAAA,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GACN,cAAc,mCACd,wBAAU,CAAC,WAAW,CAAC,wBAAU,CAAC,GAAG,EAAE,oBAAO,CAAC,IAAI,EAAE,gCAAmB,CAAC,OAAO,CAAC,CACpF,CAAA;gBACD,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;gBACxD,MAAM,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;gBAC/C,MAAM,SAAS,CAAC,SAAS,EAAE,CAAA;gBAE3B,OAAO,SAAS,CAAA;;SACjB;KACF,CAAA;AACH,CAAC,CAAA;AAfY,QAAA,OAAO,WAenB"}
|