@tatumio/bch 2.0.1-alpha.203

Sign up to get free protection for your applications and to get access to all the features.
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@tatumio/bch",
3
+ "version": "v2.0.1-alpha.203",
4
+ "license": "MIT",
5
+ "main": "./src/index.js",
6
+ "typings": "./src/index.d.ts",
7
+ "dependencies": {
8
+ "@tatumio/shared-testing": "v2.0.1-alpha.202",
9
+ "@tatumio/shared-blockchain-btc-based": "v2.0.1-alpha.202",
10
+ "@tatumio/shared-core": "v2.0.1-alpha.202",
11
+ "axios": "^0.24.0",
12
+ "@tatumio/api-client": "v2.0.1-alpha.202",
13
+ "cross-blob": "^3.0.0",
14
+ "form-data": "^4.0.0",
15
+ "@tatumio/shared-blockchain-abstract": "v2.0.1-alpha.202",
16
+ "@tatumio/shared-abstract-sdk": "v2.0.1-alpha.202",
17
+ "bignumber.js": "^9.0.2",
18
+ "bip32": "^2.0.5",
19
+ "bip39": "^3.0.2",
20
+ "bitcoinjs-lib": "^5.2.0",
21
+ "hdkey": "^2.0.1",
22
+ "bitcore-lib": "^8.25.25",
23
+ "coininfo": "^5.1.0",
24
+ "@tatumio/bitcoincashjs2-lib": "^4.1.2",
25
+ "cashaddrjs": "^0.4.4"
26
+ },
27
+ "peerDependencies": {}
28
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/bch.sdk';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./lib/bch.sdk"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/blockchain/bch/src/index.ts"],"names":[],"mappings":";;;AAAA,6DAA6B"}
@@ -0,0 +1,119 @@
1
+ import { BlockchainBitcoinCashService } from '@tatumio/api-client';
2
+ import { SDKArguments } from '@tatumio/shared-abstract-sdk';
3
+ export declare const TatumBchSDK: (args: SDKArguments) => {
4
+ wallet: import("../../../../../dist/packages/shared/blockchain/abstract/src").SdkWithWalletFunctions;
5
+ transaction: import("@tatumio/shared-blockchain-btc-based").BtcBasedTx<import("@tatumio/api-client").BchTransaction | import("@tatumio/api-client").BchTransactionKMS>;
6
+ blockchain: {
7
+ info: typeof BlockchainBitcoinCashService.bchGetBlockChainInfo;
8
+ broadcast: typeof BlockchainBitcoinCashService.bchBroadcast;
9
+ getBlockHash: typeof BlockchainBitcoinCashService.bchGetBlockHash;
10
+ getBlock: typeof BlockchainBitcoinCashService.bchGetBlock;
11
+ getTxForAccount: typeof BlockchainBitcoinCashService.bchGetTxByAddress;
12
+ getTransaction: typeof BlockchainBitcoinCashService.bchGetRawTransaction;
13
+ send: typeof BlockchainBitcoinCashService.bchTransferBlockchain;
14
+ };
15
+ kms: {
16
+ sign(tx: import("@tatumio/shared-core").ChainTransactionKMS, privateKeys: string[]): Promise<string>;
17
+ getAllPending(signatures?: string): import("@tatumio/api-client").CancelablePromise<import("@tatumio/api-client").PendingTransaction>;
18
+ get: typeof import("@tatumio/api-client").SecurityKeyManagementSystemService.getPendingTransactionToSign;
19
+ complete: typeof import("@tatumio/api-client").SecurityKeyManagementSystemService.completePendingSignature;
20
+ delete: typeof import("@tatumio/api-client").SecurityKeyManagementSystemService.deletePendingTransactionToSign;
21
+ };
22
+ offchain: {
23
+ depositAddress: {
24
+ checkExists: (address: string, index?: number) => Promise<import("@tatumio/api-client").Account>;
25
+ create: typeof import("@tatumio/api-client").OffChainAccountService.generateDepositAddress;
26
+ createMultiple: typeof import("@tatumio/api-client").OffChainAccountService.generateDepositAddressesBatch;
27
+ assign: typeof import("@tatumio/api-client").OffChainAccountService.assignAddress;
28
+ remove: typeof import("@tatumio/api-client").OffChainAccountService.removeAddress;
29
+ getByAccount: typeof import("@tatumio/api-client").OffChainAccountService.getAllDepositAddresses;
30
+ };
31
+ withdrawal: {
32
+ getAll: (status?: "InProgress" | "Done" | "Cancelled", pageSize?: number, offset?: number) => Promise<import("@tatumio/api-client").WithdrawalObject[]>;
33
+ };
34
+ storeTokenAddress: typeof import("@tatumio/api-client").OffChainBlockchainService.storeTokenAddress;
35
+ };
36
+ getExchangeRate(basePair?: import("@tatumio/shared-core").Fiat): import("@tatumio/api-client").CancelablePromise<import("@tatumio/api-client").ExchangeRate>;
37
+ storage: {
38
+ upload: typeof import("@tatumio/api-client").StorageIpfsService.storeIpfs;
39
+ get: typeof import("@tatumio/api-client").StorageIpfsService.getIpfsData;
40
+ };
41
+ subscriptions: typeof import("@tatumio/api-client").LedgerSubscriptionService;
42
+ ledger: {
43
+ customer: {
44
+ get: typeof import("@tatumio/api-client").LedgerCustomerService.getCustomerByExternalOrInternalId;
45
+ getAll: typeof import("@tatumio/api-client").LedgerCustomerService.findAllCustomers;
46
+ update: typeof import("@tatumio/api-client").LedgerCustomerService.updateCustomer;
47
+ activate: typeof import("@tatumio/api-client").LedgerCustomerService.activateCustomer;
48
+ deactivate: typeof import("@tatumio/api-client").LedgerCustomerService.deactivateCustomer;
49
+ enable: typeof import("@tatumio/api-client").LedgerCustomerService.enableCustomer;
50
+ disable: typeof import("@tatumio/api-client").LedgerCustomerService.disableCustomer;
51
+ };
52
+ orderBook: {
53
+ getHistorical: typeof import("@tatumio/api-client").LedgerOrderBookService.getHistoricalTradesBody;
54
+ getActiveBuyTrades: typeof import("@tatumio/api-client").LedgerOrderBookService.getBuyTradesBody;
55
+ getActiveSellTrades: typeof import("@tatumio/api-client").LedgerOrderBookService.getBuyTradesBody;
56
+ newTrade: typeof import("@tatumio/api-client").LedgerOrderBookService.storeTrade;
57
+ get: typeof import("@tatumio/api-client").LedgerOrderBookService.getTradeById;
58
+ cancel: typeof import("@tatumio/api-client").LedgerOrderBookService.deleteTrade;
59
+ cancelByAccount: typeof import("@tatumio/api-client").LedgerOrderBookService.deleteAccountTrades;
60
+ };
61
+ transaction: {
62
+ send: typeof import("@tatumio/api-client").LedgerTransactionService.sendTransaction;
63
+ sendMultiple: typeof import("@tatumio/api-client").LedgerTransactionService.sendTransactionBatch;
64
+ getAll: typeof import("@tatumio/api-client").LedgerTransactionService.getTransactions;
65
+ getAllByAccount: typeof import("@tatumio/api-client").LedgerTransactionService.getTransactionsByAccountId;
66
+ getAllByCustomer: typeof import("@tatumio/api-client").LedgerTransactionService.getTransactionsByCustomerId;
67
+ getAllByReference: typeof import("@tatumio/api-client").LedgerTransactionService.getTransactionsByReference;
68
+ countByAccount: (filter: import("@tatumio/api-client").TransactionFilter) => any;
69
+ countByCustomer: (filter: import("@tatumio/api-client").TransactionFilterCustomer) => any;
70
+ };
71
+ virtualCurrency: {
72
+ create: typeof import("@tatumio/api-client").LedgerVirtualCurrencyService.createCurrency;
73
+ mint: typeof import("@tatumio/api-client").LedgerVirtualCurrencyService.mintCurrency;
74
+ revoke: typeof import("@tatumio/api-client").LedgerVirtualCurrencyService.revokeCurrency;
75
+ getByName: typeof import("@tatumio/api-client").LedgerVirtualCurrencyService.getCurrency;
76
+ update: typeof import("@tatumio/api-client").LedgerVirtualCurrencyService.updateCurrency;
77
+ };
78
+ blockAmount: {
79
+ block: typeof import("@tatumio/api-client").LedgerAccountService.blockAmount;
80
+ unblock: typeof import("@tatumio/api-client").LedgerAccountService.deleteBlockAmount;
81
+ unblockWithTransaction: typeof import("@tatumio/api-client").LedgerAccountService.unblockAmountWithTransaction;
82
+ };
83
+ account: {
84
+ get: typeof import("@tatumio/api-client").LedgerAccountService.getAccountByAccountId;
85
+ getAll: typeof import("@tatumio/api-client").LedgerAccountService.getAllAccounts;
86
+ getByCustomerId: typeof import("@tatumio/api-client").LedgerAccountService.getAccountsByCustomerId;
87
+ getBalance: typeof import("@tatumio/api-client").LedgerAccountService.getAccountBalance;
88
+ create: typeof import("@tatumio/api-client").LedgerAccountService.createAccount;
89
+ createMultiple: typeof import("@tatumio/api-client").LedgerAccountService.createAccountBatch;
90
+ update: typeof import("@tatumio/api-client").LedgerAccountService.updateAccountByAccountId;
91
+ getBlockedAmountsByAccountId: typeof import("@tatumio/api-client").LedgerAccountService.getBlockAmountById;
92
+ activate: typeof import("@tatumio/api-client").LedgerAccountService.activateAccount;
93
+ deactivate: typeof import("@tatumio/api-client").LedgerAccountService.deactivateAccount;
94
+ freeze: typeof import("@tatumio/api-client").LedgerAccountService.freezeAccount;
95
+ unfreeze: typeof import("@tatumio/api-client").LedgerAccountService.unfreezeAccount;
96
+ generate: (account: import("@tatumio/api-client").CreateAccount, generateNewWalletFn: any, generateNewWallet?: boolean, testnet?: boolean, webhookUrl?: string) => Promise<any>;
97
+ };
98
+ };
99
+ security: {
100
+ checkMaliciousAddress: typeof import("@tatumio/api-client").SecurityAddressService.checkMalicousAddress;
101
+ };
102
+ tatum: {
103
+ getCredits: typeof import("@tatumio/api-client").TatumServiceService.getCredits;
104
+ getVersion: typeof import("@tatumio/api-client").TatumServiceService.getVersion;
105
+ freezeApiKey: typeof import("@tatumio/api-client").TatumServiceService.freezeApiKey;
106
+ unfreezeApiKey: typeof import("@tatumio/api-client").TatumServiceService.unfreezeApiKey;
107
+ };
108
+ nft: {
109
+ mintNFT: typeof import("@tatumio/api-client").BlockchainNftService.nftMintErc721;
110
+ getNFTTransaction: typeof import("@tatumio/api-client").BlockchainNftService.nftGetTransactErc721;
111
+ getNFTTransactionsByToken: typeof import("@tatumio/api-client").BlockchainNftService.nftGetTransactionByToken;
112
+ getNFTTransactionsByAddress: typeof import("@tatumio/api-client").BlockchainNftService.nftGetTransactionByAddress;
113
+ getNFTsByAddress: typeof import("@tatumio/api-client").BlockchainNftService.nftGetBalanceErc721;
114
+ getNFTProvenanceData: typeof import("@tatumio/api-client").BlockchainNftService.nftGetProvenanceDataErc721;
115
+ getNFTMetadataURI: typeof import("@tatumio/api-client").BlockchainNftService.nftGetMetadataErc721;
116
+ getNFTRoyalty: typeof import("@tatumio/api-client").BlockchainNftService.nftGetRoyaltyErc721;
117
+ prepareAddNFTMinterAbstraction: typeof import("@tatumio/api-client").BlockchainNftService.nftGetRoyaltyErc721;
118
+ };
119
+ };
@@ -0,0 +1,8 @@
1
+ import { SdkError, SdkErrorCode } from '@tatumio/shared-abstract-sdk';
2
+ export declare const BCH_ERRORS_MAPPING: {
3
+ 'Transaction has absurd fees': SdkErrorCode;
4
+ };
5
+ export declare type BchSdkErrorCode = SdkErrorCode.BTC_FEE_TOO_SMALL | SdkErrorCode.BTC_UTXO_NOT_FOUND | SdkErrorCode.BTC_NOT_ENOUGH_BALANCE;
6
+ export declare class BchSdkError extends SdkError {
7
+ constructor(error: Error | BchSdkErrorCode);
8
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BchSdkError = exports.BCH_ERRORS_MAPPING = void 0;
4
+ const shared_abstract_sdk_1 = require("@tatumio/shared-abstract-sdk");
5
+ exports.BCH_ERRORS_MAPPING = {
6
+ 'Transaction has absurd fees': shared_abstract_sdk_1.SdkErrorCode.BTC_FEE_IS_TOO_LARGE,
7
+ };
8
+ class BchSdkError extends shared_abstract_sdk_1.SdkError {
9
+ constructor(error) {
10
+ if (typeof error === 'string') {
11
+ super({
12
+ code: error,
13
+ });
14
+ }
15
+ else {
16
+ super({
17
+ originalError: error,
18
+ errorSubstringMapping: exports.BCH_ERRORS_MAPPING,
19
+ });
20
+ }
21
+ }
22
+ }
23
+ exports.BchSdkError = BchSdkError;
24
+ //# sourceMappingURL=bch.sdk.errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bch.sdk.errors.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/bch/src/lib/bch.sdk.errors.ts"],"names":[],"mappings":";;;AAAA,sEAAqE;AAExD,QAAA,kBAAkB,GAAG;IAChC,6BAA6B,EAAE,kCAAY,CAAC,oBAAoB;CACjE,CAAA;AAOD,MAAa,WAAY,SAAQ,8BAAQ;IACvC,YAAY,KAA8B;QACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,KAAK,CAAC;gBACJ,IAAI,EAAE,KAAK;aACZ,CAAC,CAAA;SACH;aAAM;YACL,KAAK,CAAC;gBACJ,aAAa,EAAE,KAAK;gBACpB,qBAAqB,EAAE,0BAAkB;aAC1C,CAAC,CAAA;SACH;IACH,CAAC;CACF;AAbD,kCAaC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TatumBchSDK = void 0;
4
+ const shared_core_1 = require("@tatumio/shared-core");
5
+ const shared_blockchain_btc_based_1 = require("@tatumio/shared-blockchain-btc-based");
6
+ const api_client_1 = require("@tatumio/api-client");
7
+ const bch_sdk_tx_1 = require("./bch.sdk.tx");
8
+ const bch_sdk_wallet_1 = require("./bch.sdk.wallet");
9
+ const blockchain = shared_core_1.Blockchain.BCH;
10
+ const TatumBchSDK = (args) => {
11
+ return Object.assign(Object.assign({}, (0, shared_blockchain_btc_based_1.btcBasedSdk)(Object.assign(Object.assign({}, args), { blockchain }))), { wallet: (0, bch_sdk_wallet_1.bchWallet)(Object.assign(Object.assign({}, args), { blockchain })), transaction: (0, bch_sdk_tx_1.bchTransactions)(), blockchain: {
12
+ info: api_client_1.BlockchainBitcoinCashService.bchGetBlockChainInfo,
13
+ broadcast: api_client_1.BlockchainBitcoinCashService.bchBroadcast,
14
+ getBlockHash: api_client_1.BlockchainBitcoinCashService.bchGetBlockHash,
15
+ getBlock: api_client_1.BlockchainBitcoinCashService.bchGetBlock,
16
+ getTxForAccount: api_client_1.BlockchainBitcoinCashService.bchGetTxByAddress,
17
+ getTransaction: api_client_1.BlockchainBitcoinCashService.bchGetRawTransaction,
18
+ send: api_client_1.BlockchainBitcoinCashService.bchTransferBlockchain,
19
+ } });
20
+ };
21
+ exports.TatumBchSDK = TatumBchSDK;
22
+ //# sourceMappingURL=bch.sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bch.sdk.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/bch/src/lib/bch.sdk.ts"],"names":[],"mappings":";;;AAAA,sDAAiD;AACjD,sFAAkE;AAClE,oDAAkE;AAElE,6CAA8C;AAC9C,qDAA4C;AAE5C,MAAM,UAAU,GAAG,wBAAU,CAAC,GAAG,CAAA;AAE1B,MAAM,WAAW,GAAG,CAAC,IAAkB,EAAE,EAAE;IAChD,uCACK,IAAA,yCAAW,kCAAM,IAAI,KAAE,UAAU,IAAG,KACvC,MAAM,EAAE,IAAA,0BAAS,kCAAM,IAAI,KAAE,UAAU,IAAG,EAC1C,WAAW,EAAE,IAAA,4BAAe,GAAE,EAC9B,UAAU,EAAE;YACV,IAAI,EAAE,yCAA4B,CAAC,oBAAoB;YACvD,SAAS,EAAE,yCAA4B,CAAC,YAAY;YACpD,YAAY,EAAE,yCAA4B,CAAC,eAAe;YAC1D,QAAQ,EAAE,yCAA4B,CAAC,WAAW;YAClD,eAAe,EAAE,yCAA4B,CAAC,iBAAiB;YAC/D,cAAc,EAAE,yCAA4B,CAAC,oBAAoB;YACjE,IAAI,EAAE,yCAA4B,CAAC,qBAAqB;SACzD,IACF;AACH,CAAC,CAAA;AAfY,QAAA,WAAW,eAevB"}
@@ -0,0 +1,5 @@
1
+ import { BchTransaction, BchTransactionKMS } from '@tatumio/api-client';
2
+ import { BtcBasedTx } from '@tatumio/shared-blockchain-btc-based';
3
+ declare type BchTransactionBody = BchTransaction | BchTransactionKMS;
4
+ export declare const bchTransactions: () => BtcBasedTx<BchTransactionBody>;
5
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bchTransactions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const api_client_1 = require("@tatumio/api-client");
6
+ const bch_address_1 = require("./utils/bch.address");
7
+ const bch_sdk_errors_1 = require("./bch.sdk.errors");
8
+ const shared_abstract_sdk_1 = require("@tatumio/shared-abstract-sdk");
9
+ const coininfo_1 = (0, tslib_1.__importDefault)(require("coininfo"));
10
+ const bitcoincashjs2_lib_1 = require("@tatumio/bitcoincashjs2-lib");
11
+ const bignumber_js_1 = (0, tslib_1.__importDefault)(require("bignumber.js"));
12
+ const sendTransaction = (body, args) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
13
+ return api_client_1.ApiServices.blockchain.bcash.bchBroadcast({
14
+ txData: yield prepareSignedTransaction(body, args),
15
+ });
16
+ });
17
+ // @TODO add support - by address
18
+ const prepareSignedTransaction = (body, args) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
19
+ try {
20
+ const network = args.testnet
21
+ ? coininfo_1.default.bitcoincash.test.toBitcoinJS()
22
+ : coininfo_1.default.bitcoincash.main.toBitcoinJS();
23
+ const transactionBuilder = new bitcoincashjs2_lib_1.TransactionBuilder(network);
24
+ const privateKeysToSign = [];
25
+ const amountToSign = [];
26
+ const txs = yield getTransactions(body.fromUTXO.map((u) => u.txHash));
27
+ for (const [i, item] of body.fromUTXO.entries()) {
28
+ transactionBuilder.addInput(item.txHash, item.index, 0xffffffff, null);
29
+ if ('signatureId' in item)
30
+ privateKeysToSign.push(item.signatureId);
31
+ else if ('privateKey' in item)
32
+ privateKeysToSign.push(item.privateKey);
33
+ const vout = txs[i].vout[item.index];
34
+ if (!vout)
35
+ throw new bch_sdk_errors_1.BchSdkError(shared_abstract_sdk_1.SdkErrorCode.BTC_UTXO_NOT_FOUND);
36
+ amountToSign.push(shared_abstract_sdk_1.amountUtils.toSatoshis(vout.value));
37
+ const fromUTXO = body.fromUTXO;
38
+ if (fromUTXO && 'signatureId' in fromUTXO[0] && fromUTXO[0].signatureId) {
39
+ return JSON.stringify({ txData: JSON.stringify(txs[i]), privateKeysToSign });
40
+ }
41
+ }
42
+ body.to.forEach((item) => {
43
+ transactionBuilder.addOutput(bch_address_1.bcashAddressHelper.getAddress(item.address), shared_abstract_sdk_1.amountUtils.toSatoshis(item.value));
44
+ });
45
+ verifyAmounts(amountToSign, body);
46
+ for (let i = 0; i < privateKeysToSign.length; i++) {
47
+ const ecPair = bitcoincashjs2_lib_1.ECPair.fromWIF(privateKeysToSign[i], network);
48
+ transactionBuilder.sign(i, ecPair, undefined, 0x01, amountToSign[i], undefined, bitcoincashjs2_lib_1.ECSignature.SCHNORR);
49
+ }
50
+ return transactionBuilder.build().toHex();
51
+ }
52
+ catch (e) {
53
+ throw new bch_sdk_errors_1.BchSdkError(e);
54
+ }
55
+ });
56
+ function verifyAmounts(amountToSign, body) {
57
+ const outputsSum = body.to
58
+ .map((to) => shared_abstract_sdk_1.amountUtils.toSatoshis(to.value))
59
+ .reduce((e, acc) => e.plus(acc), new bignumber_js_1.default(0));
60
+ const inputsSum = amountToSign
61
+ .map((i) => new bignumber_js_1.default(i))
62
+ .reduce((v, acc) => v.plus(acc), new bignumber_js_1.default(0));
63
+ if (outputsSum.eq(inputsSum)) {
64
+ throw new bch_sdk_errors_1.BchSdkError(shared_abstract_sdk_1.SdkErrorCode.BTC_FEE_TOO_SMALL);
65
+ }
66
+ if (outputsSum.gt(inputsSum)) {
67
+ throw new bch_sdk_errors_1.BchSdkError(shared_abstract_sdk_1.SdkErrorCode.BTC_NOT_ENOUGH_BALANCE);
68
+ }
69
+ }
70
+ const getTransactions = (txHash) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
71
+ const result = [];
72
+ for (const tx of txHash) {
73
+ result.push(api_client_1.ApiServices.blockchain.bcash.bchGetRawTransaction(tx));
74
+ }
75
+ return Promise.all(result);
76
+ });
77
+ const bchTransactions = () => ({
78
+ sendTransaction,
79
+ prepareSignedTransaction,
80
+ });
81
+ exports.bchTransactions = bchTransactions;
82
+ //# sourceMappingURL=bch.sdk.tx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bch.sdk.tx.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/bch/src/lib/bch.sdk.tx.ts"],"names":[],"mappings":";;;;AAAA,oDAM4B;AAC5B,qDAAwD;AACxD,qDAA8C;AAC9C,sEAAwE;AAExE,qEAA+B;AAC/B,oEAAqF;AAEr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C,EAAE,CAAC,CAAC,CAAA;KACnE;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC5B,CAAC,CAAA,CAAA;AAEM,MAAM,eAAe,GAAG,GAAmC,EAAE,CAAC,CAAC;IACpE,eAAe;IACf,wBAAwB;CACzB,CAAC,CAAA;AAHW,QAAA,eAAe,mBAG1B"}
@@ -0,0 +1,5 @@
1
+ import { BtcBasedBlockchain } from '@tatumio/shared-core';
2
+ import { SdkWithWalletFunctions } from '@tatumio/shared-blockchain-abstract';
3
+ export declare const bchWallet: (args: {
4
+ blockchain: BtcBasedBlockchain;
5
+ }) => SdkWithWalletFunctions;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bchWallet = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const shared_core_1 = require("@tatumio/shared-core");
6
+ const bitcoincashjs2_lib_1 = (0, tslib_1.__importDefault)(require("@tatumio/bitcoincashjs2-lib"));
7
+ const cashaddrjs_1 = (0, tslib_1.__importDefault)(require("cashaddrjs"));
8
+ const shared_blockchain_btc_based_1 = require("@tatumio/shared-blockchain-btc-based");
9
+ const bch_address_1 = require("./utils/bch.address");
10
+ const bitcoinjs_lib_1 = require("bitcoinjs-lib");
11
+ const bchWallet = (args) => {
12
+ const btcBased = (0, shared_blockchain_btc_based_1.btcBasedWallet)(args);
13
+ return Object.assign(Object.assign({}, btcBased), { generateAddressFromXPub: (xpub, i, options) => {
14
+ const network = shared_core_1.blockchainUtils.getNetworkConfig(args.blockchain, options);
15
+ const hdNode = bitcoincashjs2_lib_1.default.HDNode.fromBase58(xpub, network);
16
+ const legacy = hdNode.derivePath(String(i)).getAddress();
17
+ const decoded = bch_address_1.bcashAddressHelper.decode(legacy);
18
+ return cashaddrjs_1.default.encode(decoded.prefix, decoded.type, decoded.hash);
19
+ }, generateAddressFromPrivateKey: (privateKey, options) => {
20
+ const network = shared_core_1.blockchainUtils.getNetworkConfig(args.blockchain, options);
21
+ const keyPair = bitcoinjs_lib_1.ECPair.fromWIF(privateKey, network);
22
+ const legacy = bitcoinjs_lib_1.payments.p2pkh({ pubkey: keyPair.publicKey, network }).address;
23
+ const decoded = bch_address_1.bcashAddressHelper.decode(legacy);
24
+ return cashaddrjs_1.default.encode(decoded.prefix, decoded.type, decoded.hash);
25
+ } });
26
+ };
27
+ exports.bchWallet = bchWallet;
28
+ //# sourceMappingURL=bch.sdk.wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bch.sdk.wallet.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/bch/src/lib/bch.sdk.wallet.ts"],"names":[],"mappings":";;;;AAAA,sDAA0E;AAE1E,kGAA+C;AAC/C,yEAAiC;AACjC,sFAAqE;AACrE,qDAAwD;AAExD,iDAAgD;AAEzC,MAAM,SAAS,GAAG,CAAC,IAAwC,EAA0B,EAAE;IAC5F,MAAM,QAAQ,GAAG,IAAA,4CAAc,EAAC,IAAI,CAAC,CAAA;IAErC,uCACK,QAAQ,KACX,uBAAuB,EAAE,CAAC,IAAY,EAAE,CAAS,EAAE,OAA8B,EAAU,EAAE;YAC3F,MAAM,OAAO,GAAG,6BAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;YAC1E,MAAM,MAAM,GAAG,4BAAK,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;YACrD,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAA;YAExD,MAAM,OAAO,GAAG,gCAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAEjD,OAAO,oBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QACpE,CAAC,EACD,6BAA6B,EAAE,CAAC,UAAkB,EAAE,OAA8B,EAAU,EAAE;YAC5F,MAAM,OAAO,GAAG,6BAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;YAC1E,MAAM,OAAO,GAAG,sBAAM,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;YACnD,MAAM,MAAM,GAAG,wBAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAA;YAC7E,MAAM,OAAO,GAAG,gCAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAEjD,OAAO,oBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QACpE,CAAC,IACF;AACH,CAAC,CAAA;AAvBY,QAAA,SAAS,aAuBrB"}
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ interface Hash {
3
+ hash: Buffer;
4
+ }
5
+ interface Decoded extends Hash {
6
+ prefix: string;
7
+ type: string;
8
+ format: string;
9
+ }
10
+ export declare const bcashAddressHelper: {
11
+ getAddress: (address: string) => any;
12
+ toLegacyAddress: (address: string) => any;
13
+ decode: (address: string) => Decoded;
14
+ };
15
+ export {};
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bcashAddressHelper = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // @ts-ignore
6
+ const coininfo_1 = (0, tslib_1.__importDefault)(require("coininfo"));
7
+ // @ts-ignore
8
+ const bitcoincashjs2_lib_1 = (0, tslib_1.__importDefault)(require("@tatumio/bitcoincashjs2-lib"));
9
+ const bitcoinjs_lib_1 = require("bitcoinjs-lib");
10
+ exports.bcashAddressHelper = {
11
+ getAddress: (address) => {
12
+ try {
13
+ return exports.bcashAddressHelper.toLegacyAddress(address);
14
+ }
15
+ catch (e) {
16
+ return address;
17
+ }
18
+ },
19
+ toLegacyAddress: (address) => {
20
+ const { prefix, type, hash } = exports.bcashAddressHelper.decode(address);
21
+ let bitcoincash = coininfo_1.default.bitcoincash.main;
22
+ switch (prefix) {
23
+ case 'bitcoincash':
24
+ bitcoincash = coininfo_1.default.bitcoincash.main;
25
+ break;
26
+ case 'bchtest':
27
+ bitcoincash = coininfo_1.default.bitcoincash.test;
28
+ break;
29
+ }
30
+ let version = bitcoincash.versions.public;
31
+ switch (type) {
32
+ case 'P2PKH':
33
+ version = bitcoincash.versions.public;
34
+ break;
35
+ case 'P2SH':
36
+ version = bitcoincash.versions.scripthash;
37
+ break;
38
+ }
39
+ const hashBuf = Buffer.from(hash);
40
+ return bitcoincashjs2_lib_1.default.address.toBase58Check(hashBuf, version);
41
+ },
42
+ decode: (address) => {
43
+ const { version, hash } = bitcoincashjs2_lib_1.default.address.fromBase58Check(address);
44
+ let decoded = {
45
+ prefix: '',
46
+ type: '',
47
+ hash,
48
+ format: '',
49
+ };
50
+ switch (version) {
51
+ case bitcoinjs_lib_1.networks.bitcoin.pubKeyHash:
52
+ decoded = {
53
+ prefix: 'bitcoincash',
54
+ type: 'P2PKH',
55
+ hash,
56
+ format: 'legacy',
57
+ };
58
+ break;
59
+ case bitcoinjs_lib_1.networks.bitcoin.scriptHash:
60
+ decoded = {
61
+ prefix: 'bitcoincash',
62
+ type: 'P2SH',
63
+ hash,
64
+ format: 'legacy',
65
+ };
66
+ break;
67
+ case bitcoinjs_lib_1.networks.testnet.pubKeyHash:
68
+ decoded = {
69
+ prefix: 'bchtest',
70
+ type: 'P2PKH',
71
+ hash,
72
+ format: 'legacy',
73
+ };
74
+ break;
75
+ case bitcoinjs_lib_1.networks.testnet.scriptHash:
76
+ decoded = {
77
+ prefix: 'bchtest',
78
+ type: 'P2SH',
79
+ hash,
80
+ format: 'legacy',
81
+ };
82
+ break;
83
+ }
84
+ return decoded;
85
+ },
86
+ };
87
+ //# sourceMappingURL=bch.address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bch.address.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/bch/src/lib/utils/bch.address.ts"],"names":[],"mappings":";;;;AAAA,aAAa;AACb,qEAA+B;AAC/B,aAAa;AACb,kGAA+C;AAC/C,iDAAwC;AAgB3B,QAAA,kBAAkB,GAAG;IAChC,UAAU,EAAE,CAAC,OAAe,EAAE,EAAE;QAC9B,IAAI;YACF,OAAO,0BAAkB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;SACnD;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,OAAO,CAAA;SACf;IACH,CAAC;IACD,eAAe,EAAE,CAAC,OAAe,EAAE,EAAE;QACnC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAY,0BAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC1E,IAAI,WAAW,GAAG,kBAAQ,CAAC,WAAW,CAAC,IAAI,CAAA;QAC3C,QAAQ,MAAM,EAAE;YACd,KAAK,aAAa;gBAChB,WAAW,GAAG,kBAAQ,CAAC,WAAW,CAAC,IAAI,CAAA;gBACvC,MAAK;YACP,KAAK,SAAS;gBACZ,WAAW,GAAG,kBAAQ,CAAC,WAAW,CAAC,IAAI,CAAA;gBACvC,MAAK;SACR;QAED,IAAI,OAAO,GAAW,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAA;QACjD,QAAQ,IAAI,EAAE;YACZ,KAAK,OAAO;gBACV,OAAO,GAAG,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAA;gBACrC,MAAK;YACP,KAAK,MAAM;gBACT,OAAO,GAAG,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAA;gBACzC,MAAK;SACR;QAED,MAAM,OAAO,GAAW,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEzC,OAAO,4BAAK,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACtD,C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