@multiplechain/bitcoin 0.1.18 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +7 -1
  2. package/dist/assets/Coin.d.ts +38 -0
  3. package/dist/assets/index.d.ts +1 -0
  4. package/dist/browser/Wallet.d.ts +81 -0
  5. package/dist/browser/adapters/Leather.d.ts +16 -0
  6. package/dist/browser/adapters/UniSat.d.ts +19 -0
  7. package/dist/browser/adapters/Xverse.d.ts +6 -0
  8. package/dist/browser/adapters/icons.d.ts +6 -0
  9. package/dist/browser/adapters/index.d.ts +3 -0
  10. package/dist/browser/index.d.ts +11 -0
  11. package/dist/index.cjs +83 -0
  12. package/dist/index.cjs.map +7 -0
  13. package/dist/index.d.ts +6 -0
  14. package/dist/index.es.js +43583 -0
  15. package/dist/index.es.js.map +1 -0
  16. package/dist/index.umd.js +133 -0
  17. package/dist/index.umd.js.map +1 -0
  18. package/dist/models/CoinTransaction.d.ts +24 -0
  19. package/dist/models/Transaction.d.ts +106 -0
  20. package/dist/models/index.d.ts +2 -0
  21. package/dist/services/Provider.d.ts +80 -0
  22. package/dist/services/TransactionListener.d.ts +120 -0
  23. package/dist/services/TransactionSigner.d.ts +50 -0
  24. package/dist/services/index.d.ts +2 -0
  25. package/dist/utils.d.ts +3 -0
  26. package/package.json +85 -50
  27. package/LICENSE +0 -21
  28. package/dist/bitcoin-provider.js +0 -2
  29. package/dist/bitcoin-provider.js.LICENSE.txt +0 -30
  30. package/src/adapters/leather.js +0 -75
  31. package/src/adapters/trustwallet.js +0 -32
  32. package/src/adapters/unisat.js +0 -42
  33. package/src/adapters/xverse.js +0 -86
  34. package/src/entity/coin.js +0 -74
  35. package/src/entity/token.js +0 -5
  36. package/src/entity/transaction.js +0 -183
  37. package/src/get-adapter.js +0 -14
  38. package/src/provider.js +0 -221
  39. package/src/utils.js +0 -26
  40. package/src/wallet.js +0 -180
@@ -0,0 +1,24 @@
1
+ import { TransactionStatusEnum, AssetDirectionEnum, WalletAddress, CoinTransactionInterface, TransferAmount } from '@multiplechain/types';
2
+ import { Transaction } from './Transaction.ts';
3
+
4
+ export declare class CoinTransaction extends Transaction implements CoinTransactionInterface {
5
+ /**
6
+ * @returns {Promise<WalletAddress>} Wallet address of the receiver of transaction
7
+ */
8
+ getReceiver(): Promise<WalletAddress>;
9
+ /**
10
+ * @returns {Promise<WalletAddress>} Wallet address of the sender of transaction
11
+ */
12
+ getSender(): Promise<WalletAddress>;
13
+ /**
14
+ * @returns {Promise<TransferAmount>} Amount of coin that will be transferred
15
+ */
16
+ getAmount(): Promise<TransferAmount>;
17
+ /**
18
+ * @param {AssetDirectionEnum} direction - Direction of the transaction (asset)
19
+ * @param {WalletAddress} address - Wallet address of the receiver or sender of the transaction, dependant on direction
20
+ * @param {TransferAmount} amount Amount of assets that will be transferred
21
+ * @returns {Promise<TransactionStatusEnum>} Status of the transaction
22
+ */
23
+ verifyTransfer(direction: AssetDirectionEnum, address: WalletAddress, amount: TransferAmount): Promise<TransactionStatusEnum>;
24
+ }
@@ -0,0 +1,106 @@
1
+ import { TransactionStatusEnum, TransactionTypeEnum, BlockConfirmationCount, BlockNumber, BlockTimestamp, TransactionFee, TransactionId, TransactionInterface, WalletAddress } from '@multiplechain/types';
2
+ import { Provider } from '../services/Provider.ts';
3
+
4
+ export interface VinObject {
5
+ txid: string;
6
+ vout: number;
7
+ prevout: {
8
+ scriptpubkey: string;
9
+ scriptpubkey_asm: string;
10
+ scriptpubkey_type: string;
11
+ scriptpubkey_address: string;
12
+ value: number;
13
+ };
14
+ scriptsig: string;
15
+ scriptsig_asm: string;
16
+ witness: string[];
17
+ is_coinbase: boolean;
18
+ sequence: number;
19
+ }
20
+ export interface VoutObject {
21
+ scriptpubkey: string;
22
+ scriptpubkey_asm: string;
23
+ scriptpubkey_type: string;
24
+ scriptpubkey_address: string;
25
+ value: number;
26
+ }
27
+ export interface TransactionData {
28
+ txid: string;
29
+ version: number;
30
+ locktime: number;
31
+ vin: VinObject[];
32
+ vout: VoutObject[];
33
+ size: number;
34
+ weight: number;
35
+ fee: number;
36
+ status: {
37
+ confirmed: boolean;
38
+ block_height: number;
39
+ block_hash: string;
40
+ block_time: number;
41
+ };
42
+ }
43
+ export declare class Transaction implements TransactionInterface<TransactionData> {
44
+ /**
45
+ * Each transaction has its own unique ID defined by the user
46
+ */
47
+ id: TransactionId;
48
+ /**
49
+ * Blockchain network provider
50
+ */
51
+ provider: Provider;
52
+ /**
53
+ * Transaction data
54
+ */
55
+ data: TransactionData | null;
56
+ /**
57
+ * @param {TransactionId} id Transaction id
58
+ * @param {Provider} provider Blockchain network provider
59
+ */
60
+ constructor(id: TransactionId, provider?: Provider);
61
+ /**
62
+ * @returns {Promise<TransactionData | null>} Transaction data
63
+ */
64
+ getData(): Promise<TransactionData | null>;
65
+ /**
66
+ * @param {number} ms - Milliseconds to wait for the transaction to be confirmed. Default is 4000ms
67
+ * @returns {Promise<TransactionStatusEnum>} Status of the transaction
68
+ */
69
+ wait(ms?: number): Promise<TransactionStatusEnum>;
70
+ /**
71
+ * @returns {TransactionId} Transaction ID
72
+ */
73
+ getId(): TransactionId;
74
+ /**
75
+ * @returns {Promise<TransactionTypeEnum>} Transaction type
76
+ */
77
+ getType(): Promise<TransactionTypeEnum>;
78
+ /**
79
+ * @returns {string} Transaction URL
80
+ */
81
+ getUrl(): string;
82
+ /**
83
+ * @returns {Promise<WalletAddress>} Wallet address of the sender of transaction
84
+ */
85
+ getSigner(): Promise<WalletAddress>;
86
+ /**
87
+ * @returns {Promise<TransactionFee>} Transaction fee
88
+ */
89
+ getFee(): Promise<TransactionFee>;
90
+ /**
91
+ * @returns {Promise<BlockNumber>} Block number that transaction
92
+ */
93
+ getBlockNumber(): Promise<BlockNumber>;
94
+ /**
95
+ * @returns {Promise<BlockTimestamp>} Block timestamp that transaction
96
+ */
97
+ getBlockTimestamp(): Promise<BlockTimestamp>;
98
+ /**
99
+ * @returns {Promise<BlockConfirmationCount>} Confirmation count of the block
100
+ */
101
+ getBlockConfirmationCount(): Promise<BlockConfirmationCount>;
102
+ /**
103
+ * @returns {Promise<TransactionStatusEnum>} Status of the transaction
104
+ */
105
+ getStatus(): Promise<TransactionStatusEnum>;
106
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Transaction.ts';
2
+ export * from './CoinTransaction.ts';
@@ -0,0 +1,80 @@
1
+ import { ProviderInterface } from '@multiplechain/types';
2
+
3
+ export interface BitcoinNetworkConfigInterface {
4
+ testnet: boolean;
5
+ blockCypherToken?: string;
6
+ }
7
+ export declare class Provider implements ProviderInterface<BitcoinNetworkConfigInterface> {
8
+ /**
9
+ * Network configuration of the provider
10
+ */
11
+ network: BitcoinNetworkConfigInterface;
12
+ /**
13
+ * API URL
14
+ */
15
+ api: string;
16
+ /**
17
+ * Explorer URL
18
+ */
19
+ explorer: string;
20
+ /**
21
+ * Websocket URL
22
+ */
23
+ wsUrl: string;
24
+ /**
25
+ * BlockCypher token
26
+ */
27
+ blockCypherToken?: string;
28
+ /**
29
+ * Default BlockCypher token
30
+ */
31
+ defaultBlockCypherToken: string;
32
+ /**
33
+ * Static instance of the provider
34
+ */
35
+ private static _instance;
36
+ /**
37
+ * @param network - Network configuration of the provider
38
+ */
39
+ constructor(network: BitcoinNetworkConfigInterface);
40
+ /**
41
+ * Get the static instance of the provider
42
+ * @returns {Provider} Provider
43
+ */
44
+ static get instance(): Provider;
45
+ /**
46
+ * Initialize the static instance of the provider
47
+ * @param {BitcoinNetworkConfigInterface} network - Network configuration of the provider
48
+ * @returns {void}
49
+ */
50
+ static initialize(network: BitcoinNetworkConfigInterface): void;
51
+ /**
52
+ * Check RPC connection
53
+ * @param {string} url - RPC URL
54
+ * @returns {Promise<boolean | Error>}
55
+ */
56
+ checkRpcConnection(url?: string): Promise<boolean | Error>;
57
+ /**
58
+ * Check WS connection
59
+ * @param {string} url - Websocket URL
60
+ * @returns {Promise<boolean | Error>}
61
+ */
62
+ checkWsConnection(url?: string): Promise<boolean | Error>;
63
+ /**
64
+ * Update network configuration of the provider
65
+ * @param {BitcoinNetworkConfigInterface} network - Network configuration
66
+ * @returns {void}
67
+ */
68
+ update(network: BitcoinNetworkConfigInterface): void;
69
+ /**
70
+ * Create a new endpoint
71
+ * @param {string} endpoint - Endpoint
72
+ * @returns {string} Endpoint
73
+ */
74
+ createEndpoint(endpoint: string): string;
75
+ /**
76
+ * Get the current network configuration is testnet or not
77
+ * @returns {boolean} Testnet or not
78
+ */
79
+ isTestnet(): boolean;
80
+ }
@@ -0,0 +1,120 @@
1
+ import { CoinTransaction } from '../models/CoinTransaction.ts';
2
+ import { Transaction } from '../models/Transaction.ts';
3
+ import { Provider } from './Provider.ts';
4
+ import { default as WebSocket } from 'ws';
5
+ import { TransactionTypeEnum, DynamicTransactionType, TransactionListenerInterface, DynamicTransactionListenerFilterType, TransactionId } from '@multiplechain/types';
6
+
7
+ interface Values {
8
+ txId: string;
9
+ amount?: number;
10
+ sender?: string;
11
+ receiver?: string;
12
+ }
13
+ type TransactionListenerTriggerType<T extends TransactionTypeEnum> = DynamicTransactionType<T, Transaction, Transaction, CoinTransaction, Transaction, Transaction>;
14
+ type TransactionListenerCallbackType<T extends TransactionTypeEnum, Transaction = TransactionListenerTriggerType<T>> = (transaction: Transaction) => void;
15
+ export declare class TransactionListener<T extends TransactionTypeEnum, DTransaction extends TransactionListenerTriggerType<T>, CallBackType extends TransactionListenerCallbackType<T>> implements TransactionListenerInterface<T, DTransaction, CallBackType> {
16
+ /**
17
+ * Transaction type
18
+ */
19
+ type: T;
20
+ /**
21
+ * Provider
22
+ */
23
+ provider: Provider;
24
+ /**
25
+ * Listener status
26
+ */
27
+ status: boolean;
28
+ /**
29
+ * Transaction listener callback
30
+ */
31
+ callbacks: CallBackType[];
32
+ /**
33
+ * Triggered transactions
34
+ */
35
+ triggeredTransactions: TransactionId[];
36
+ /**
37
+ * Transaction listener filter
38
+ */
39
+ filter?: DynamicTransactionListenerFilterType<T> | Record<string, never>;
40
+ /**
41
+ * WebSocket
42
+ */
43
+ webSocket: WebSocket;
44
+ /**
45
+ * Dynamic stop method
46
+ */
47
+ dynamicStop: () => void;
48
+ /**
49
+ * @param {T} type - Transaction type
50
+ * @param {DynamicTransactionListenerFilterType<T>} filter - Transaction listener filter
51
+ * @param {Provider} provider - Provider
52
+ */
53
+ constructor(type: T, filter?: DynamicTransactionListenerFilterType<T>, provider?: Provider);
54
+ /**
55
+ * Close the listener
56
+ * @returns {void}
57
+ */
58
+ stop(): void;
59
+ /**
60
+ * Start the listener
61
+ * @returns {void}
62
+ */
63
+ start(): void;
64
+ /**
65
+ * Get the listener status
66
+ * @returns {boolean} Listener status
67
+ */
68
+ getStatus(): boolean;
69
+ /**
70
+ * Listen to the transaction events
71
+ * @param {CallBackType} callback - Transaction listener callback
72
+ * @returns {Promise<boolean>}
73
+ */
74
+ on(callback: CallBackType): Promise<boolean>;
75
+ /**
76
+ * Trigger the event when a transaction is detected
77
+ * @param {TransactionListenerTriggerType<T>} transaction - Transaction data
78
+ * @returns {void}
79
+ */
80
+ trigger<T extends TransactionTypeEnum>(transaction: TransactionListenerTriggerType<T>): void;
81
+ isBlockCypherProcess(): boolean;
82
+ /**
83
+ * Create message for the listener
84
+ * @param {string} receiver - Receiver address
85
+ * @returns {string} Message
86
+ */
87
+ createMessage(receiver?: string): string;
88
+ /**
89
+ * Parse the data
90
+ * @param {any} data - Data
91
+ * @returns {Values} Parsed data
92
+ */
93
+ getValues(data: any): Values;
94
+ /**
95
+ * General transaction process
96
+ * @returns {void}
97
+ */
98
+ generalProcess(): void;
99
+ /**
100
+ * Contract transaction process
101
+ * @returns {void}
102
+ */
103
+ contractProcess(): void;
104
+ /**
105
+ * Coin transaction process
106
+ * @returns {void}
107
+ */
108
+ coinProcess(): void;
109
+ /**
110
+ * Token transaction process
111
+ * @returns {void}
112
+ */
113
+ tokenProcess(): void;
114
+ /**
115
+ * NFT transaction process
116
+ * @returns {void}
117
+ */
118
+ nftProcess(): void;
119
+ }
120
+ export {};
@@ -0,0 +1,50 @@
1
+ import { PrivateKey, TransactionId, TransactionSignerInterface } from '@multiplechain/types';
2
+ import { Transaction as BitcoreLibTransactionData } from 'bitcore-lib';
3
+ import { Provider } from '../services/Provider.ts';
4
+
5
+ export interface TransactionData {
6
+ sender: string;
7
+ receiver: string;
8
+ amount: number;
9
+ bitcoreLib: BitcoreLibTransactionData;
10
+ }
11
+ export declare class TransactionSigner implements TransactionSignerInterface<TransactionData, string> {
12
+ /**
13
+ * Transaction data from the blockchain network
14
+ */
15
+ rawData: TransactionData;
16
+ /**
17
+ * Signed transaction data
18
+ */
19
+ signedData?: string;
20
+ /**
21
+ * Blockchain network provider
22
+ */
23
+ provider: Provider;
24
+ /**
25
+ * @param {TransactionData} rawData - Transaction data
26
+ * @param {Provider} provider - Blockchain network provider
27
+ */
28
+ constructor(rawData: TransactionData, provider?: Provider);
29
+ /**
30
+ * Sign the transaction
31
+ * @param {PrivateKey} privateKey - Transaction data
32
+ * @returns {Promise<this>} Signed transaction data
33
+ */
34
+ sign(privateKey: PrivateKey): Promise<this>;
35
+ /**
36
+ * Send the transaction to the blockchain network
37
+ * @returns {Promise<TransactionId>}
38
+ */
39
+ send(): Promise<TransactionId>;
40
+ /**
41
+ * Get the raw transaction data
42
+ * @returns {TransactionData}
43
+ */
44
+ getRawData(): TransactionData;
45
+ /**
46
+ * Get the signed transaction data
47
+ * @returns {string}
48
+ */
49
+ getSignedData(): string;
50
+ }
@@ -0,0 +1,2 @@
1
+ export * from './TransactionSigner.ts';
2
+ export * from './TransactionListener.ts';
@@ -0,0 +1,3 @@
1
+ export * from '@multiplechain/utils';
2
+ export declare const fromSatoshi: (amount: number) => number;
3
+ export declare const toSatoshi: (amount: number) => number;
package/package.json CHANGED
@@ -1,50 +1,85 @@
1
- {
2
- "namespace": "multiplechain",
3
- "name": "@multiplechain/bitcoin",
4
- "version": "0.1.18",
5
- "description": "Bitcoin JS provider",
6
- "scripts": {
7
- "serve": "parcel test.html --no-cache --dist-dir test",
8
- "build": "webpack"
9
- },
10
- "files": [
11
- "src",
12
- "dist"
13
- ],
14
- "main": "src/bitcoin-provider.js",
15
- "types": "index.d.ts",
16
- "typings": "index.d.ts",
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/MultipleChain/bitcoin.git"
20
- },
21
- "keywords": [
22
- "Blockchain",
23
- "Bitcoin",
24
- "Cryptocurrency"
25
- ],
26
- "author": "MultipleChain",
27
- "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/MultipleChain/bitcoin/issues"
30
- },
31
- "homepage": "https://github.com/MultipleChain/bitcoin",
32
- "dependencies": {
33
- "@multiplechain/utils": "^0.1.1",
34
- "bignumber.js": "^9.1.1",
35
- "install": "^0.13.0",
36
- "npm": "^9.7.2",
37
- "sats-connect": "^1.1.1",
38
- "web3-utils": "^1.8.1",
39
- "ws": "^8.13.0"
40
- },
41
- "devDependencies": {
42
- "assert": "^2.0.0",
43
- "buffer": "^5.7.1",
44
- "events": "^3.3.0",
45
- "process": "^0.11.10",
46
- "stream-browserify": "^3.0.0",
47
- "webpack": "^5.76.0",
48
- "webpack-cli": "^5.0.1"
49
- }
50
- }
1
+ {
2
+ "name": "@multiplechain/bitcoin",
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.es.js",
7
+ "unpkg": "dist/index.umd.js",
8
+ "browser": "dist/index.umd.js",
9
+ "jsdelivr": "dist/index.umd.js",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "default": "./dist/index.es.js",
14
+ "types": "./dist/browser/index.d.ts"
15
+ },
16
+ "require": {
17
+ "default": "./dist/index.cjs",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "./node": {
22
+ "default": "./dist/index.cjs",
23
+ "types": "./dist/index.d.ts"
24
+ },
25
+ "./browser": {
26
+ "default": "./dist/index.es.js",
27
+ "types": "./dist/browser/index.d.ts"
28
+ }
29
+ },
30
+ "typesVersions": {
31
+ "*": {
32
+ "node": [
33
+ "./dist/index.d.ts"
34
+ ],
35
+ "browser": [
36
+ "./dist/browser/index.d.ts"
37
+ ]
38
+ }
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md",
43
+ "!tsconfig.tsbuildinfo"
44
+ ],
45
+ "scripts": {
46
+ "dev": "vite",
47
+ "clean": "rm -rf dist",
48
+ "watch": "tsc --watch",
49
+ "build:vite": "vite build",
50
+ "build:node": "tsx esbuild.ts",
51
+ "typecheck": "tsc --noEmit",
52
+ "lint": "eslint . --ext .ts",
53
+ "test": "vitest run --dir tests",
54
+ "test-ui": "vitest watch --ui",
55
+ "prepublishOnly": "pnpm run build",
56
+ "build": "pnpm run build:vite && pnpm run build:node"
57
+ },
58
+ "keywords": [
59
+ "web3",
60
+ "crypto",
61
+ "blockchain",
62
+ "multiple-chain"
63
+ ],
64
+ "author": "MultipleChain",
65
+ "license": "MIT",
66
+ "homepage": "https://github.com/MultipleChain/js/tree/master/packages/networks/network-name",
67
+ "repository": {
68
+ "type": "git",
69
+ "url": "git+https://github.com/MultipleChain/js.git"
70
+ },
71
+ "bugs": {
72
+ "url": "https://github.com/MultipleChain/js/issues"
73
+ },
74
+ "dependencies": {
75
+ "@multiplechain/types": "^0.1.63",
76
+ "@multiplechain/utils": "^0.1.21",
77
+ "axios": "^1.6.8",
78
+ "bitcore-lib": "^10.0.28",
79
+ "sats-connect": "^2.3.1",
80
+ "ws": "^8.17.0"
81
+ },
82
+ "devDependencies": {
83
+ "@types/bitcore-lib": "^0.15.6"
84
+ }
85
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 MultipleChain
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.