edge-currency-plugins 2.6.1 → 3.0.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 (68) hide show
  1. package/README.md +61 -2
  2. package/android/build.gradle +45 -0
  3. package/android/src/main/AndroidManifest.xml +2 -0
  4. package/android/src/main/assets/edge-currency-plugins/669.chunk.js +1 -0
  5. package/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +76 -0
  6. package/android/src/main/java/app/edge/reactnative/currencyplugins/EdgeCurrencyPluginsModule.java +26 -0
  7. package/android/src/main/java/app/edge/reactnative/currencyplugins/EdgeCurrencyPluginsPackage.java +24 -0
  8. package/edge-currency-plugins.d.ts +34 -0
  9. package/edge-currency-plugins.podspec +28 -0
  10. package/ios/EdgeCurrencyPluginsModule.m +4 -0
  11. package/ios/EdgeCurrencyPluginsModule.swift +20 -0
  12. package/ios/edge-currency-plugins.xcodeproj/project.pbxproj +1 -0
  13. package/lib/common/constants.js +1 -2
  14. package/lib/common/plugin/CurrencyPlugin.js +17 -1
  15. package/lib/common/utxobased/db/Models/ProcessorTransaction.js +3 -2
  16. package/lib/common/utxobased/db/Processor.js +5 -0
  17. package/lib/common/utxobased/engine/ServerStates.js +159 -28
  18. package/lib/common/utxobased/engine/UtxoEngine.js +3 -2
  19. package/lib/common/utxobased/engine/UtxoEngineState.js +66 -72
  20. package/lib/common/utxobased/engine/types.js +3 -1
  21. package/lib/common/utxobased/info/badcoin.js +16 -19
  22. package/lib/common/utxobased/info/bitcoin.js +18 -26
  23. package/lib/common/utxobased/info/bitcoincash.js +18 -26
  24. package/lib/common/utxobased/info/bitcoincashtestnet.js +17 -17
  25. package/lib/common/utxobased/info/bitcoingold.js +16 -19
  26. package/lib/common/utxobased/info/bitcoingoldtestnet.js +16 -11
  27. package/lib/common/utxobased/info/bitcoinsv.js +16 -24
  28. package/lib/common/utxobased/info/bitcointestnet.js +17 -25
  29. package/lib/common/utxobased/info/commonInfo.js +20 -11
  30. package/lib/common/utxobased/info/dash.js +18 -21
  31. package/lib/common/utxobased/info/digibyte.js +17 -20
  32. package/lib/common/utxobased/info/dogecoin.js +17 -20
  33. package/lib/common/utxobased/info/eboost.js +16 -19
  34. package/lib/common/utxobased/info/feathercoin.js +16 -24
  35. package/lib/common/utxobased/info/groestlcoin.js +19 -22
  36. package/lib/common/utxobased/info/litecoin.js +18 -26
  37. package/lib/common/utxobased/info/qtum.js +16 -19
  38. package/lib/common/utxobased/info/ravencoin.js +16 -19
  39. package/lib/common/utxobased/info/smartcash.js +16 -19
  40. package/lib/common/utxobased/info/ufo.js +16 -19
  41. package/lib/common/utxobased/info/vertcoin.js +16 -19
  42. package/lib/common/utxobased/info/zcoin.js +22 -24
  43. package/lib/common/utxobased/keymanager/keymanager.js +1 -1
  44. package/lib/common/utxobased/keymanager/types.js +2 -1
  45. package/lib/common/utxobased/network/Blockbook.js +178 -105
  46. package/lib/common/utxobased/network/BlockbookElectrum.js +216 -0
  47. package/lib/common/utxobased/network/Socket.js +130 -66
  48. package/lib/common/utxobased/network/blockbookApi.js +6 -6
  49. package/lib/common/utxobased/network/electrumApi.js +203 -0
  50. package/lib/{types.js → declare-modules.d.js} +2 -0
  51. package/lib/index.js +7 -3
  52. package/lib/react-native.js +26 -0
  53. package/lib/src/common/constants.d.ts +0 -1
  54. package/lib/src/common/utxobased/db/Processor.d.ts +6 -1
  55. package/lib/src/common/utxobased/engine/ServerStates.d.ts +8 -0
  56. package/lib/src/common/utxobased/engine/UtxoEngineState.d.ts +1 -4
  57. package/lib/src/common/utxobased/info/commonInfo.d.ts +4 -2
  58. package/lib/src/common/utxobased/keymanager/types.d.ts +3 -3
  59. package/lib/src/common/utxobased/network/Blockbook.d.ts +20 -7
  60. package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +25 -0
  61. package/lib/src/common/utxobased/network/Socket.d.ts +11 -0
  62. package/lib/src/common/utxobased/network/blockbookApi.d.ts +2 -16
  63. package/lib/src/common/utxobased/network/electrumApi.d.ts +90 -0
  64. package/lib/src/index.d.ts +5 -1
  65. package/lib/src/react-native.d.ts +10 -0
  66. package/lib/test/utils.d.ts +4 -0
  67. package/package.json +24 -11
  68. package/lib/src/types.d.ts +0 -6
@@ -1,2 +1,4 @@
1
- import { EdgeCurrencyInfo } from 'edge-core-js/types';
2
- export declare const memoInfo: Partial<EdgeCurrencyInfo>;
1
+ import { EdgeCurrencyInfo, EdgeMemoOption } from 'edge-core-js/types';
2
+ export declare const utxoCustomFeeTemplate: EdgeCurrencyInfo['customFeeTemplate'];
3
+ export declare const utxoMemoOptions: EdgeMemoOption[];
4
+ export declare const legacyMemoInfo: Partial<EdgeCurrencyInfo>;
@@ -1,13 +1,13 @@
1
1
  import { Cleaner } from 'cleaners';
2
- import { InsufficientFundsError } from 'edge-core-js/types';
2
+ import { EdgeTokenId, InsufficientFundsError } from 'edge-core-js/types';
3
3
  interface InsufficientFundsErrorOptsPlus {
4
- currencyCode?: string;
4
+ tokenId: EdgeTokenId;
5
5
  networkFee?: string;
6
6
  networkFeeShortage?: string;
7
7
  }
8
8
  export declare class InsufficientFundsErrorPlus extends InsufficientFundsError {
9
9
  networkFeeShortage?: string;
10
- constructor(opts?: InsufficientFundsErrorOptsPlus);
10
+ constructor(opts: InsufficientFundsErrorOptsPlus);
11
11
  }
12
12
  export declare const asMaybeInsufficientFundsErrorPlus: Cleaner<InsufficientFundsErrorPlus | undefined>;
13
13
  export {};
@@ -1,31 +1,44 @@
1
1
  import { Cleaner } from 'cleaners';
2
2
  import { EdgeLog, EdgeTransaction } from 'edge-core-js/types';
3
3
  import { EngineEmitter } from '../../plugin/EngineEmitter';
4
- import { AddressResponse, AddresssMessageParams, AddressUtxosResponse, BroadcastTxResponse, InfoResponse, SubscribeAddressResponse, TransactionResponse } from './blockbookApi';
4
+ import { AddressResponse, AddresssMessageParams, AddressUtxosResponse, BlockbookTask, BlockbookTransaction, BroadcastTxResponse, InfoResponse, SubscribeAddressResponse, TransactionResponse } from './blockbookApi';
5
5
  import Deferred from './Deferred';
6
- import { OnQueueSpaceCB } from './Socket';
6
+ import { OnQueueSpaceCB, WsResponse, WsTask } from './Socket';
7
7
  import { SocketEmitter } from './SocketEmitter';
8
8
  export declare type WatchAddressesCB = (response: SubscribeAddressResponse) => void | Promise<void>;
9
9
  export declare type WatchBlocksCB = () => void | Promise<void>;
10
10
  export interface Blockbook {
11
11
  isConnected: boolean;
12
+ broadcastTx: (transaction: EdgeTransaction) => Promise<BroadcastTxResponse>;
12
13
  connect: () => Promise<void>;
13
14
  disconnect: () => Promise<void>;
14
- onQueueSpace: (cb: OnQueueSpaceCB) => void;
15
- fetchInfo: () => Promise<InfoResponse>;
16
15
  fetchAddress: (address: string, params?: AddresssMessageParams) => Promise<AddressResponse>;
17
- watchAddresses: (addresses: string[], deferredAddressSub: Deferred<unknown>) => void;
18
- watchBlocks: (deferredBlockSub: Deferred<unknown>) => void;
19
16
  fetchAddressUtxos: (account: string) => Promise<AddressUtxosResponse>;
17
+ fetchInfo: () => Promise<InfoResponse>;
20
18
  fetchTransaction: (hash: string) => Promise<TransactionResponse>;
21
- broadcastTx: (transaction: EdgeTransaction) => Promise<BroadcastTxResponse>;
19
+ watchAddresses: (addresses: string[], deferredAddressSub: Deferred<unknown>) => void;
20
+ watchBlocks: (deferredBlockSub: Deferred<unknown>) => void;
21
+ onQueueSpace: (cb: OnQueueSpaceCB) => void;
22
+ promisifyWsMessage: <T>(message: BlockbookTask<T>) => Promise<T>;
23
+ addressQueryTask: (address: string, params: {
24
+ asBlockbookAddress?: Cleaner<string> | undefined;
25
+ lastQueriedBlockHeight: number;
26
+ page: number;
27
+ }, deferred: Deferred<AddressResponse>) => WsTask<AddressResponse>;
28
+ transactionQueryTask: (txId: string, deferred: Deferred<BlockbookTransaction>) => WsTask<BlockbookTransaction>;
29
+ transactionSpecialQueryTask: (txId: string, deferred: Deferred<unknown>) => WsTask<unknown>;
30
+ utxoListQueryTask: (address: string, params: {
31
+ asBlockbookAddress?: Cleaner<string> | undefined;
32
+ }, deferred: Deferred<AddressUtxosResponse>) => WsTask<AddressUtxosResponse>;
22
33
  }
23
34
  interface BlockbookConfig {
24
35
  asAddress?: Cleaner<string>;
36
+ asResponse?: Cleaner<WsResponse>;
25
37
  connectionUri: string;
26
38
  engineEmitter: EngineEmitter;
27
39
  log: EdgeLog;
28
40
  onQueueSpaceCB: OnQueueSpaceCB;
41
+ ping?: () => Promise<void>;
29
42
  socketEmitter: SocketEmitter;
30
43
  walletId: string;
31
44
  }
@@ -0,0 +1,25 @@
1
+ import { Cleaner } from 'cleaners';
2
+ import { EdgeLog } from 'edge-core-js/types';
3
+ import { EngineEmitter } from '../../plugin/EngineEmitter';
4
+ import { PluginInfo } from '../../plugin/types';
5
+ import { Blockbook } from './Blockbook';
6
+ import { OnQueueSpaceCB } from './Socket';
7
+ import { SocketEmitter } from './SocketEmitter';
8
+ export interface BlockbookElectrumConfig {
9
+ asAddress?: Cleaner<string>;
10
+ connectionUri: string;
11
+ engineEmitter: EngineEmitter;
12
+ log: EdgeLog;
13
+ onQueueSpaceCB: OnQueueSpaceCB;
14
+ pluginInfo: PluginInfo;
15
+ socketEmitter: SocketEmitter;
16
+ walletId: string;
17
+ }
18
+ export interface ElectrumResponseMessage {
19
+ id: number;
20
+ data: unknown;
21
+ error: {
22
+ message: string;
23
+ } | undefined;
24
+ }
25
+ export declare function makeBlockbookElectrum(config: BlockbookElectrumConfig): Blockbook;
@@ -29,6 +29,7 @@ export interface Socket {
29
29
  }
30
30
  export declare type OnQueueSpaceCB = (uri: string) => Promise<WsTask<unknown> | boolean | undefined>;
31
31
  interface SocketConfig {
32
+ asResponse?: Cleaner<WsResponse>;
32
33
  queueSize?: number;
33
34
  timeout?: number;
34
35
  walletId: string;
@@ -37,5 +38,15 @@ interface SocketConfig {
37
38
  healthCheck: () => Promise<void>;
38
39
  onQueueSpaceCB: OnQueueSpaceCB;
39
40
  }
41
+ export declare type WsResponse = WsResponseMessage[];
42
+ export interface WsResponseMessage {
43
+ id: string;
44
+ data?: unknown;
45
+ error?: {
46
+ message: string;
47
+ } | {
48
+ connected: string;
49
+ };
50
+ }
40
51
  export declare function makeSocket(uri: string, config: SocketConfig): Socket;
41
52
  export {};
@@ -1,5 +1,4 @@
1
1
  import { Cleaner } from 'cleaners';
2
- import { EdgeTransaction } from 'edge-core-js/types';
3
2
  /**
4
3
  * Websocket Task
5
4
  */
@@ -103,7 +102,7 @@ export declare const transactionMessageSpecific: (hash: string) => BlockbookTask
103
102
  /**
104
103
  * Send Transaction
105
104
  */
106
- export declare const broadcastTxMessage: (transaction: EdgeTransaction) => BlockbookTask<BroadcastTxResponse>;
105
+ export declare const broadcastTxMessage: (signedTx: string) => BlockbookTask<BroadcastTxResponse>;
107
106
  export declare type BroadcastTxResponse = ReturnType<typeof asBroadcastTxResponse>;
108
107
  export declare const asBroadcastTxResponse: import("cleaners").ObjectCleaner<{
109
108
  result: string;
@@ -133,20 +132,7 @@ export interface AddressResponse {
133
132
  totalPages: number;
134
133
  itemsOnPage: number;
135
134
  }
136
- export declare const asAddressResponse: (asAddress?: Cleaner<string>) => import("cleaners").ObjectCleaner<{
137
- address: string;
138
- balance: string;
139
- totalReceived: string;
140
- totalSent: string;
141
- txs: number;
142
- unconfirmedBalance: string;
143
- unconfirmedTxs: number;
144
- txids: string[];
145
- transactions: BlockbookTransaction[];
146
- page: number;
147
- totalPages: number;
148
- itemsOnPage: number;
149
- }>;
135
+ export declare const asAddressResponse: (asAddress?: Cleaner<string>) => Cleaner<AddressResponse>;
150
136
  /**
151
137
  * Subscribe New Block
152
138
  */
@@ -0,0 +1,90 @@
1
+ import { Cleaner } from 'cleaners';
2
+ /**
3
+ * Websocket Task
4
+ */
5
+ export interface ElectrumTask<T> {
6
+ method: string;
7
+ params: unknown;
8
+ cleaner: Cleaner<T>;
9
+ }
10
+ export interface ElectrumUtxo {
11
+ tx_pos: number;
12
+ value: number;
13
+ tx_hash: string;
14
+ height: number;
15
+ }
16
+ export declare const asElectrumUtxo: Cleaner<ElectrumUtxo>;
17
+ export interface ElectrumTransaction {
18
+ blockhash: string;
19
+ blocktime: number;
20
+ confirmations: number;
21
+ hash: string;
22
+ hex: string;
23
+ locktime: number;
24
+ size: number;
25
+ time: number;
26
+ txid: string;
27
+ version: number;
28
+ vin: Array<{
29
+ scriptSig: {
30
+ asm: string;
31
+ hex: string;
32
+ };
33
+ sequence: number;
34
+ txid: string;
35
+ vout: number;
36
+ }>;
37
+ vout: Array<{
38
+ n: number;
39
+ scriptPubKey: {
40
+ addresses: string[];
41
+ asm: string;
42
+ hex: string;
43
+ reqSigs: number;
44
+ type: string;
45
+ };
46
+ value: number;
47
+ }>;
48
+ }
49
+ export declare const asElectrumTransaction: (asAddress?: Cleaner<string>) => Cleaner<ElectrumTransaction>;
50
+ /**
51
+ * Error Response
52
+ */
53
+ export declare type ElectrumErrorResponse = ReturnType<typeof asElectrumErrorResponse>;
54
+ export declare const asElectrumErrorResponse: import("cleaners").ObjectCleaner<{
55
+ error: {
56
+ message: any;
57
+ };
58
+ }>;
59
+ /**
60
+ * Electrum Response Generic
61
+ */
62
+ export declare type ElectrumResponse<T> = T;
63
+ export declare const asElectrumResponse: <T>(asT: Cleaner<T>) => Cleaner<T>;
64
+ /**
65
+ * Ping Message
66
+ */
67
+ export declare const pingMessage: () => ElectrumTask<PingResponse>;
68
+ export declare type PingResponse = ReturnType<typeof asPingResponse>;
69
+ export declare const asPingResponse: Cleaner<undefined>;
70
+ /**
71
+ * List Unspent (Get UTXOs)
72
+ */
73
+ export declare const listUnspentMessage: (scriptHash: string) => ElectrumTask<ListUnspentResponse>;
74
+ export declare type ListUnspentResponse = ElectrumUtxo[];
75
+ export declare const asListUnspentResponse: Cleaner<ListUnspentResponse>;
76
+ /**
77
+ * Get Address Transactions
78
+ */
79
+ export declare const addressTransactionsMessage: (scriptHash: string) => ElectrumTask<AddressTransactionsResponse>;
80
+ export declare type AddressTransactionsResponse = ReturnType<typeof asAddressTransactionsResponse>;
81
+ export declare const asAddressTransactionsResponse: Cleaner<{
82
+ height: number;
83
+ tx_hash: string;
84
+ }[]>;
85
+ /**
86
+ * Get Transaction
87
+ */
88
+ export declare const transactionMessage: (txHash: string, asAddress?: Cleaner<string>) => ElectrumTask<TransactionResponse>;
89
+ export declare type TransactionResponse = ElectrumTransaction;
90
+ export declare const asTransactionResponse: (asAddress?: Cleaner<string>) => Cleaner<ElectrumTransaction>;
@@ -1,4 +1,8 @@
1
1
  import { EdgeCorePlugins } from 'edge-core-js/types';
2
2
  declare const plugins: EdgeCorePlugins;
3
+ declare global {
4
+ interface Window {
5
+ addEdgeCorePlugins?: (plugins: EdgeCorePlugins) => void;
6
+ }
7
+ }
3
8
  export default plugins;
4
- export { setMemletConfig } from 'memlet';
@@ -0,0 +1,10 @@
1
+ import { MemletConfig } from 'memlet';
2
+ export declare const pluginUri: string;
3
+ export declare const debugUri = "http://localhost:8081/edge-currency-plugins.js";
4
+ export interface EdgeCurrencyPluginIoOptions {
5
+ readonly memletConfig?: MemletConfig;
6
+ }
7
+ export interface EdgeCurrencyPluginNativeIo {
8
+ readonly memletConfig?: MemletConfig;
9
+ }
10
+ export declare function makePluginIo(options?: EdgeCurrencyPluginIoOptions): EdgeCurrencyPluginNativeIo;
@@ -1,10 +1,14 @@
1
1
  import { Disklet } from 'disklet';
2
2
  import { EdgeIo, EdgeLog } from 'edge-core-js/types';
3
3
  import { PluginInfo } from '../src/common/plugin/types';
4
+ import { EdgeCurrencyPluginNativeIo } from '../src/react-native';
4
5
  export declare const makeFakePluginInfo: () => PluginInfo;
5
6
  export declare const makeFakeLog: () => EdgeLog;
6
7
  interface FakeIoConfig {
7
8
  disklet?: Disklet;
8
9
  }
9
10
  export declare const makeFakeIo: (config?: FakeIoConfig | undefined) => EdgeIo;
11
+ export declare const makeFakeNativeIo: () => {
12
+ 'edge-currency-plugins': EdgeCurrencyPluginNativeIo;
13
+ };
10
14
  export {};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "2.6.1",
3
+ "version": "3.0.0",
4
4
  "description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
5
+ "homepage": "https://edge.app/",
5
6
  "repository": "https://github.com/EdgeApp/edge-currency-plugins",
6
7
  "license": "MIT",
7
8
  "author": "Airbitz, Inc.",
@@ -9,25 +10,31 @@
9
10
  "browser": {
10
11
  "ws": false
11
12
  },
12
- "types": "./lib/src/index.d.ts",
13
+ "types": "./edge-currency-plugins.d.ts",
13
14
  "files": [
15
+ "/android/build.gradle",
16
+ "/android/src/*",
17
+ "/edge-currency-plugins.d.ts",
18
+ "/edge-currency-plugins.podspec",
19
+ "ios/*",
14
20
  "lib/*",
15
- "package.json",
16
- "README.md"
21
+ "/LICENSE",
22
+ "/package.json",
23
+ "/README.md"
17
24
  ],
18
25
  "scripts": {
19
- "clean": "rimraf lib",
26
+ "clean": "rimraf android/src/main/assets/edge-currency-plugins dist lib",
20
27
  "coverage": "nyc mocha && nyc report --reporter=cobertura --reporter=html",
21
28
  "fix": "eslint . --fix",
22
29
  "lib": "sucrase -q -t typescript,imports -d ./lib ./src",
23
30
  "lint": "eslint .",
24
31
  "precommit": "lint-staged && npm-run-all types test",
25
- "prepare": "husky install && npm-run-all clean -p lib types",
26
- "start": "node -r sucrase/register src/index.ts",
27
- "start.dev": "nodemon",
32
+ "prepare": "husky install && npm-run-all clean lib types webpack",
33
+ "start": "webpack serve",
28
34
  "test": "mocha",
29
35
  "types": "tsc",
30
- "verify": "npm-run-all lint types"
36
+ "webpack": "webpack && cp -r android/src/main/assets/edge-currency-plugins dist",
37
+ "verify": "npm-run-all prepare lint types test"
31
38
  },
32
39
  "lint-staged": {
33
40
  "*.{js,ts,json}": "eslint"
@@ -59,6 +66,7 @@
59
66
  "ws": "^7.4.6"
60
67
  },
61
68
  "devDependencies": {
69
+ "@sucrase/webpack-loader": "^2.0.0",
62
70
  "@types/base-x": "^3.0.6",
63
71
  "@types/bn.js": "^5.1.0",
64
72
  "@types/bs58": "^4.0.1",
@@ -79,7 +87,8 @@
79
87
  "base-x": "^4.0.0",
80
88
  "chai": "^4.2.0",
81
89
  "chai-as-promised": "^7.1.1",
82
- "edge-core-js": "^1.6.0",
90
+ "edge-core-js": "^2.5.0",
91
+ "esbuild-loader": "^4.1.0",
83
92
  "eslint": "^7.14.0",
84
93
  "eslint-config-standard-kit": "0.15.1",
85
94
  "eslint-plugin-import": "^2.22.1",
@@ -105,6 +114,10 @@
105
114
  "rimraf": "^3.0.2",
106
115
  "sucrase": "^3.12.1",
107
116
  "typescript": "^4.1.2",
117
+ "webpack": "^5.91.0",
118
+ "webpack-cli": "^5.1.4",
119
+ "webpack-dev-server": "^5.0.4",
108
120
  "wif": "^2.0.6"
109
- }
121
+ },
122
+ "react-native": "./lib/react-native.js"
110
123
  }
@@ -1,6 +0,0 @@
1
- import { EdgeCorePlugins } from 'edge-core-js/types';
2
- declare global {
3
- interface Window {
4
- addEdgeCorePlugins?: (plugins: EdgeCorePlugins) => void;
5
- }
6
- }