edge-currency-accountbased 0.7.72

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 (58) hide show
  1. package/CHANGELOG.md +713 -0
  2. package/LICENSE +29 -0
  3. package/README.md +63 -0
  4. package/index.js +3 -0
  5. package/lib/binance/bnbEngine.js +591 -0
  6. package/lib/binance/bnbInfo.js +43 -0
  7. package/lib/binance/bnbPlugin.js +168 -0
  8. package/lib/binance/bnbSchema.js +83 -0
  9. package/lib/binance/bnbTypes.js +39 -0
  10. package/lib/common/engine.js +918 -0
  11. package/lib/common/plugin.js +152 -0
  12. package/lib/common/schema.js +108 -0
  13. package/lib/common/types.js +85 -0
  14. package/lib/common/utils.js +378 -0
  15. package/lib/eos/eosEngine.js +1216 -0
  16. package/lib/eos/eosInfo.js +98 -0
  17. package/lib/eos/eosPlugin.js +314 -0
  18. package/lib/eos/eosSchema.js +190 -0
  19. package/lib/eos/eosTypes.js +88 -0
  20. package/lib/eos/telosInfo.js +94 -0
  21. package/lib/eos/waxInfo.js +95 -0
  22. package/lib/ethereum/etcInfo.js +121 -0
  23. package/lib/ethereum/ethEngine.js +832 -0
  24. package/lib/ethereum/ethInfo.js +1300 -0
  25. package/lib/ethereum/ethMiningFees.js +157 -0
  26. package/lib/ethereum/ethNetwork.js +2195 -0
  27. package/lib/ethereum/ethPlugin.js +377 -0
  28. package/lib/ethereum/ethSchema.js +61 -0
  29. package/lib/ethereum/ethTypes.js +461 -0
  30. package/lib/ethereum/ftminfo.js +102 -0
  31. package/lib/ethereum/rskInfo.js +101 -0
  32. package/lib/fio/fioConst.js +38 -0
  33. package/lib/fio/fioEngine.js +1250 -0
  34. package/lib/fio/fioError.js +38 -0
  35. package/lib/fio/fioInfo.js +72 -0
  36. package/lib/fio/fioPlugin.js +486 -0
  37. package/lib/fio/fioSchema.js +56 -0
  38. package/lib/index.js +44 -0
  39. package/lib/pluginError.js +32 -0
  40. package/lib/react-native/edge-currency-accountbased.js +239635 -0
  41. package/lib/react-native/edge-currency-accountbased.js.map +1 -0
  42. package/lib/react-native-io.js +41 -0
  43. package/lib/stellar/stellarEngine.js +563 -0
  44. package/lib/stellar/stellarInfo.js +37 -0
  45. package/lib/stellar/stellarPlugin.js +215 -0
  46. package/lib/stellar/stellarSchema.js +54 -0
  47. package/lib/stellar/stellarTypes.js +66 -0
  48. package/lib/tezos/tezosEngine.js +497 -0
  49. package/lib/tezos/tezosInfo.js +60 -0
  50. package/lib/tezos/tezosPlugin.js +174 -0
  51. package/lib/tezos/tezosTypes.js +110 -0
  52. package/lib/xrp/xrpEngine.js +583 -0
  53. package/lib/xrp/xrpInfo.js +47 -0
  54. package/lib/xrp/xrpPlugin.js +229 -0
  55. package/lib/xrp/xrpSchema.js +74 -0
  56. package/lib/xrp/xrpTypes.js +38 -0
  57. package/package.json +139 -0
  58. package/postinstall.sh +7 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Created by paul on 8/8/17.
3
+ */
4
+ //
5
+
6
+ import baseX from 'base-x'
7
+ import { bns } from 'biggystring'
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ import { xAddressToClassicAddress } from 'ripple-address-codec'
19
+ import keypairs from 'ripple-keypairs'
20
+ import { RippleAPI } from 'ripple-lib'
21
+ import parse from 'url-parse'
22
+
23
+ import { CurrencyPlugin } from '../common/plugin.js'
24
+ import { asyncWaterfall, getDenomInfo } from '../common/utils.js'
25
+ import { XrpEngine } from './xrpEngine.js'
26
+ import { currencyInfo } from './xrpInfo.js'
27
+
28
+ // import RippledWsClientPool from 'rippled-ws-client-pool'
29
+
30
+ const base58Codec = baseX(
31
+ '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
32
+ )
33
+
34
+ function checkAddress(address) {
35
+ let data
36
+ try {
37
+ data = base58Codec.decode(address)
38
+ } catch (e) {
39
+ return false
40
+ }
41
+
42
+ return data.length === 25 && address.charAt(0) === 'r'
43
+ }
44
+
45
+ export class XrpPlugin extends CurrencyPlugin {
46
+
47
+
48
+ // connectionPool: Object
49
+
50
+
51
+ constructor(io) {
52
+ super(io, 'ripple', currencyInfo)
53
+ // this.connectionPool = new RippledWsClientPool()
54
+ this.connectionClients = {}
55
+ this.rippleApi = {}
56
+ this.rippleApiSubscribers = {}
57
+ }
58
+
59
+ async connectApi(walletId) {
60
+ if (!this.rippleApi.serverName) {
61
+ const funcs =
62
+ this.currencyInfo.defaultSettings.otherSettings.rippledServers.map(
63
+ server => async () => {
64
+ const api = new RippleAPI({ server })
65
+ api.serverName = server
66
+ const result = await api.connect()
67
+ const out = { server, result, api }
68
+ return out
69
+ }
70
+ )
71
+ const result = await asyncWaterfall(funcs)
72
+ if (!this.rippleApi.serverName) {
73
+ this.rippleApi = result.api
74
+ }
75
+ }
76
+ this.rippleApiSubscribers[walletId] = true
77
+ }
78
+
79
+ async disconnectApi(walletId) {
80
+ delete this.rippleApiSubscribers[walletId]
81
+ if (Object.keys(this.rippleApiSubscribers).length === 0) {
82
+ await this.rippleApi.disconnect()
83
+ this.rippleApi = {}
84
+ }
85
+ }
86
+
87
+ async importPrivateKey(privateKey) {
88
+ privateKey = privateKey.replace(/\s/g, '')
89
+ try {
90
+ // Try deriving an address from the key:
91
+ const keypair = keypairs.deriveKeypair(privateKey)
92
+ keypairs.deriveAddress(keypair.publicKey)
93
+
94
+ // If that worked, return the key:
95
+ return { rippleKey: privateKey }
96
+ } catch (error) {
97
+ throw new Error('Invalid private key: ' + String(error))
98
+ }
99
+ }
100
+
101
+ async createPrivateKey(walletType) {
102
+ const type = walletType.replace('wallet:', '')
103
+
104
+ if (type === 'ripple' || type === 'ripple-secp256k1') {
105
+ const algorithm =
106
+ type === 'ripple-secp256k1' ? 'ecdsa-secp256k1' : 'ed25519'
107
+ const entropy = Array.from(this.io.random(32))
108
+ const server =
109
+ this.currencyInfo.defaultSettings.otherSettings.rippledServers[0]
110
+ const api = new RippleAPI({ server })
111
+ const address = api.generateAddress({
112
+ algorithm,
113
+ entropy
114
+ })
115
+
116
+ return { rippleKey: address.secret }
117
+ } else {
118
+ throw new Error('InvalidWalletType')
119
+ }
120
+ }
121
+
122
+ async derivePublicKey(walletInfo) {
123
+ const type = walletInfo.type.replace('wallet:', '')
124
+ if (type === 'ripple' || type === 'ripple-secp256k1') {
125
+ const keypair = keypairs.deriveKeypair(walletInfo.keys.rippleKey)
126
+ const publicKey = keypairs.deriveAddress(keypair.publicKey)
127
+ return { publicKey }
128
+ } else {
129
+ throw new Error('InvalidWalletType')
130
+ }
131
+ }
132
+
133
+ async parseUri(uri) {
134
+ const networks = {
135
+ ripple: true,
136
+ 'xrp-ledger': true
137
+ }
138
+ const RIPPLE_DOT_COM_URI_PREFIX = 'https://ripple.com//send'
139
+
140
+ try {
141
+ const { classicAddress, tag } = xAddressToClassicAddress(uri)
142
+ uri = `ripple:${classicAddress}?to=${classicAddress}${
143
+ tag !== false ? `&dt=${tag}` : ''
144
+ }`
145
+ } catch (e) {
146
+ //
147
+ }
148
+
149
+ // Handle special case of https://ripple.com//send?to= URIs
150
+ if (uri.includes(RIPPLE_DOT_COM_URI_PREFIX)) {
151
+ const parsedUri = parse(uri, {}, true)
152
+ const addr = parsedUri.query.to
153
+ if (addr) {
154
+ uri = uri.replace(RIPPLE_DOT_COM_URI_PREFIX, `ripple:${addr}`)
155
+ }
156
+ }
157
+
158
+ const { parsedUri, edgeParsedUri } = this.parseUriCommon(
159
+ currencyInfo,
160
+ uri,
161
+ networks
162
+ )
163
+ const valid = checkAddress(edgeParsedUri.publicAddress || '')
164
+ if (!valid) {
165
+ throw new Error('InvalidPublicAddressError')
166
+ }
167
+
168
+ edgeParsedUri.uniqueIdentifier = parsedUri.query.dt || undefined
169
+ return edgeParsedUri
170
+ }
171
+
172
+ async encodeUri(obj) {
173
+ const valid = checkAddress(obj.publicAddress)
174
+ if (!valid) {
175
+ throw new Error('InvalidPublicAddressError')
176
+ }
177
+ let amount
178
+ if (typeof obj.nativeAmount === 'string') {
179
+ const currencyCode = 'XRP'
180
+ const nativeAmount = obj.nativeAmount
181
+ const denom = getDenomInfo(currencyInfo, currencyCode)
182
+ if (!denom) {
183
+ throw new Error('InternalErrorInvalidCurrencyCode')
184
+ }
185
+ amount = bns.div(nativeAmount, denom.multiplier, 6)
186
+ }
187
+ const encodedUri = this.encodeUriCommon(obj, 'ripple', amount)
188
+ return encodedUri
189
+ }
190
+ }
191
+
192
+ export function makeRipplePlugin(
193
+ opts
194
+ ) {
195
+ const { io } = opts
196
+
197
+ let toolsPromise
198
+ function makeCurrencyTools() {
199
+ if (toolsPromise != null) return toolsPromise
200
+ toolsPromise = Promise.resolve(new XrpPlugin(io))
201
+ return toolsPromise
202
+ }
203
+
204
+ async function makeCurrencyEngine(
205
+ walletInfo,
206
+ opts
207
+ ) {
208
+ const tools = await makeCurrencyTools()
209
+ const currencyEngine = new XrpEngine(tools, walletInfo, opts)
210
+
211
+ await currencyEngine.loadEngine(tools, walletInfo, opts)
212
+
213
+ // This is just to make sure otherData is Flow type checked
214
+ currencyEngine.otherData = currencyEngine.walletLocalData.otherData
215
+
216
+ if (!currencyEngine.otherData.recommendedFee) {
217
+ currencyEngine.otherData.recommendedFee = '0'
218
+ }
219
+
220
+ const out = currencyEngine
221
+ return out
222
+ }
223
+
224
+ return {
225
+ currencyInfo,
226
+ makeCurrencyEngine,
227
+ makeCurrencyTools
228
+ }
229
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Created by paul on 8/27/17.
3
+ */
4
+
5
+ export const XrpGetServerInfoSchema = {
6
+ type: 'object',
7
+ properties: {
8
+ buildVersion: { type: 'string' },
9
+ validatedLedger: {
10
+ type: 'object',
11
+ properties: {
12
+ age: { type: 'number' },
13
+ baseFeeXRP: { type: 'string' },
14
+ hash: { type: 'string' },
15
+ ledgerVersion: { type: 'number' }
16
+ }
17
+ }
18
+ }
19
+ }
20
+
21
+ export const XrpGetBalancesSchema = {
22
+ type: 'array',
23
+ items: {
24
+ type: 'object',
25
+ properties: {
26
+ currency: { type: 'string' },
27
+ value: { type: 'string' }
28
+ }
29
+ }
30
+ }
31
+
32
+ export const XrpOnTransactionSchema = {
33
+ type: 'object',
34
+ properties: {
35
+ Data: {
36
+ type: 'object',
37
+ properties: {
38
+ transaction: {
39
+ type: 'object',
40
+ properties: {
41
+ Account: { type: 'string' },
42
+ Destination: { type: 'string' }
43
+ },
44
+ required: ['Account', 'Destination']
45
+ }
46
+ },
47
+ required: ['transaction']
48
+ }
49
+ },
50
+ required: ['Data']
51
+ }
52
+
53
+ export const XrpGetTransactionsSchema = {
54
+ type: 'array',
55
+ items: {
56
+ type: 'object',
57
+ properties: {
58
+ address: { type: 'string' },
59
+ id: { type: 'string' },
60
+ outcome: {
61
+ type: 'object',
62
+ properties: {
63
+ result: { type: 'string' },
64
+ timestamp: { type: 'string' },
65
+ fee: { type: 'string' },
66
+ ledgerVersion: { type: 'number' },
67
+ balanceChanges: {
68
+ type: 'object'
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
package/package.json ADDED
@@ -0,0 +1,139 @@
1
+ {
2
+ "name": "edge-currency-accountbased",
3
+ "version": "0.7.72",
4
+ "description": "Edge currency plugin for account based currencies",
5
+ "homepage": "https://edge.app/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git@github.com:EdgeApp/edge-currency-accountbased.git"
9
+ },
10
+ "license": "SEE LICENSE IN LICENSE",
11
+ "author": "Edge (Airbitz, Inc)",
12
+ "contributors": [
13
+ "Paul Puey <paul@edge.app>"
14
+ ],
15
+ "main": "./index.js",
16
+ "module": "./lib/index.js",
17
+ "files": [
18
+ "CHANGELOG.md",
19
+ "index.js",
20
+ "lib/*",
21
+ "LICENSE",
22
+ "package.json",
23
+ "postinstall.sh",
24
+ "README.md"
25
+ ],
26
+ "scripts": {
27
+ "build": "rimraf lib && sucrase ./src -q -d ./lib -t flow && webpack",
28
+ "fix": "npm run lint -- --fix",
29
+ "flow": "flow",
30
+ "postinstall": "sh ./postinstall.sh",
31
+ "lint": "eslint .",
32
+ "precommit": "lint-staged && flow && npm test && npm run build",
33
+ "prepare": "npm run build",
34
+ "test": "nyc mocha -r sucrase/register './test/**/*.test.js'",
35
+ "posttest": "nyc report --reporter=html",
36
+ "updot": "updot"
37
+ },
38
+ "husky": {
39
+ "hooks": {
40
+ "pre-commit": "npm run precommit"
41
+ }
42
+ },
43
+ "lint-staged": {
44
+ "*.js": "eslint"
45
+ },
46
+ "resolutions": {
47
+ "axios": "0.19.0",
48
+ "babel-runtime": "6.26.0",
49
+ "base-x": "3.0.4",
50
+ "bip39": "3.0.2",
51
+ "bn.js": "4.11.8",
52
+ "browserify-aes": "1.2.0",
53
+ "bs58": "4.0.1",
54
+ "bs58check": "2.1.2",
55
+ "core-js": "2.5.3",
56
+ "create-hash": "1.2.0",
57
+ "create-hmac": "1.1.7",
58
+ "ecurve": "1.0.6",
59
+ "elliptic": "6.4.1",
60
+ "eosjs-ecc": "4.0.7",
61
+ "ethereumjs-util": "5.2.0",
62
+ "hash-base": "3.0.4",
63
+ "hdkey": "1.1.1",
64
+ "long": "4.0.0",
65
+ "process-nextick-args": "2.0.0",
66
+ "randombytes": "2.1.0",
67
+ "readable-stream": "2.3.6",
68
+ "regenerator-runtime": "0.13.4",
69
+ "ripemd160": "2.0.2",
70
+ "ripple-binary-codec": "0.2.3",
71
+ "safe-buffer": "5.2.0",
72
+ "scrypt.js": "0.3.0",
73
+ "sha.js": "2.4.11",
74
+ "uuid": "3.3.3"
75
+ },
76
+ "dependencies": {
77
+ "@binance-chain/javascript-sdk": "^2.14.4",
78
+ "@ethereumjs/common": "^2.4.0",
79
+ "@ethereumjs/tx": "^3.3.0",
80
+ "@fioprotocol/fiosdk": "^1.2.1",
81
+ "base-x": "^1.0.4",
82
+ "biggystring": "^3.0.0",
83
+ "bip39": "^3.0.2",
84
+ "cleaners": "^0.3.9",
85
+ "eosjs": "^21.0.3",
86
+ "eosjs-api": "^7.0.4",
87
+ "eosjs-ecc": "^4.0.7",
88
+ "esm": "^3.2.4",
89
+ "ethereumjs-abi": "^0.6.4",
90
+ "ethereumjs-util": "^5.2.0",
91
+ "ethereumjs-wallet": "git://github.com/EdgeApp/ethereumjs-wallet.git#6157e11ea10a734fbe55f4c7ea542780975b60ef",
92
+ "eztz.js": "git://github.com/EdgeApp/eztz.git#edge-fixes",
93
+ "jsonschema": "^1.1.1",
94
+ "ripple-address-codec": "^4.1.3",
95
+ "ripple-keypairs": "^0.10.0",
96
+ "ripple-lib": "^1.0.0",
97
+ "stellar-sdk": "^0.11.0",
98
+ "tezos-uri": "^1.0.3",
99
+ "uri-js": "^3.0.2",
100
+ "url-parse": "^1.4.1"
101
+ },
102
+ "devDependencies": {
103
+ "@babel/core": "^7.9.0",
104
+ "@babel/preset-env": "^7.9.0",
105
+ "@babel/preset-flow": "^7.9.0",
106
+ "@babel/runtime": "^7.9.2",
107
+ "babel-eslint": "^10.1.0",
108
+ "babel-loader": "^8.1.0",
109
+ "chai": "^4.2.0",
110
+ "edge-core-js": "^0.18.2",
111
+ "eslint": "^7.14.0",
112
+ "eslint-config-standard-kit": "0.15.1",
113
+ "eslint-plugin-flowtype": "^5.2.0",
114
+ "eslint-plugin-import": "^2.22.1",
115
+ "eslint-plugin-node": "^11.1.0",
116
+ "eslint-plugin-prettier": "^3.1.4",
117
+ "eslint-plugin-promise": "^4.2.1",
118
+ "eslint-plugin-simple-import-sort": "^6.0.1",
119
+ "flow-bin": "^0.89.0",
120
+ "husky": "^4.3.0",
121
+ "lint-staged": "^10.5.3",
122
+ "mocha": "^7.1.1",
123
+ "node-fetch": "^2.6.0",
124
+ "nyc": "^15.0.1",
125
+ "prettier": "^2.2.0",
126
+ "rimraf": "^3.0.2",
127
+ "sucrase": "^3.13.0",
128
+ "updot": "^1.1.7",
129
+ "webpack": "^4.42.1",
130
+ "webpack-cli": "^3.3.11"
131
+ },
132
+ "importSort": {
133
+ ".js, .es": {
134
+ "parser": "babylon",
135
+ "style": "module"
136
+ }
137
+ },
138
+ "react-native": "./lib/react-native-accountbased.js"
139
+ }
package/postinstall.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ # The `usb` and 'node-hid' modules doesn't properly install on some boxes:
4
+ mkdir -p node_modules/usb
5
+ touch node_modules/usb/index.js
6
+ mkdir -p node_modules/node-hid
7
+ touch node_modules/node-hid/index.js