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,98 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+ import { makeEosBasedPluginInner } from './eosPlugin'
13
+
14
+
15
+ const GREYMASS_FUEL_ACTION = {
16
+ authorization: [
17
+ {
18
+ actor: 'greymassfuel',
19
+ permission: 'cosign'
20
+ }
21
+ ],
22
+ account: 'greymassnoop',
23
+ name: 'noop',
24
+ data: {}
25
+ }
26
+
27
+ // ----EOSIO MAIN NET----
28
+ export const eosJsConfig = {
29
+ chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', // eosio main net
30
+ keyProvider: [],
31
+ httpEndpoint: '', // main net
32
+ fetch: fetch,
33
+ verbose: false // verbose logging such as API activity
34
+ }
35
+
36
+ const denominations = [
37
+ // An array of Objects of the possible denominations for this currency
38
+ {
39
+ name: 'EOS',
40
+ multiplier: '10000',
41
+ symbol: 'E'
42
+ }
43
+ ]
44
+
45
+ const otherSettings = {
46
+ eosActivationServers: ['https://eospay.edge.app'],
47
+ eosHyperionNodes: ['https://api.eossweden.org'],
48
+ eosNodes: [
49
+ 'https://api.eoseoul.io',
50
+ 'https://api.eoslaomao.com',
51
+ 'https://mainnet.eoscannon.io',
52
+ 'https://api.eos.wiki',
53
+ 'https://mainnet.eosio.sg',
54
+ 'https://eos.newdex.one',
55
+ 'https://api.bitmars.one',
56
+ 'https://node1.zbeos.com',
57
+ 'https://api.eosn.io'
58
+ ],
59
+ eosFuelServers: ['https://eos.greymass.com'],
60
+ eosDfuseServers: ['https://eos.dfuse.eosnation.io'],
61
+ uriProtocol: 'eos',
62
+ fuelActions: [GREYMASS_FUEL_ACTION]
63
+ }
64
+
65
+ const defaultSettings = {
66
+ otherSettings
67
+ }
68
+
69
+ export const eosCurrencyInfo = {
70
+ // Basic currency information:
71
+ currencyCode: 'EOS',
72
+ displayName: 'EOS',
73
+ pluginId: 'eos',
74
+ pluginName: 'eos',
75
+ walletType: 'wallet:eos',
76
+
77
+ defaultSettings,
78
+
79
+ addressExplorer: 'https://bloks.io/account/%s',
80
+ transactionExplorer: 'https://bloks.io/transaction/%s',
81
+
82
+ denominations,
83
+ metaTokens: [
84
+ {
85
+ name: 'EOS',
86
+ currencyName: 'EOS',
87
+ multiplier: '10000',
88
+ symbol: 'E',
89
+ currencyCode: 'EOS',
90
+ contractAddress: 'eosio.token',
91
+ denominations
92
+ }
93
+ ]
94
+ }
95
+
96
+ export const makeEosPlugin = (opts) => {
97
+ return makeEosBasedPluginInner(opts, eosCurrencyInfo, eosJsConfig)
98
+ }
@@ -0,0 +1,314 @@
1
+ /**
2
+ * Created by paul on 8/8/17.
3
+ */
4
+ /* global */
5
+ //
6
+
7
+ import { bns } from 'biggystring'
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ import EosApi from 'eosjs-api'
21
+ import ecc from 'eosjs-ecc'
22
+
23
+ import { CurrencyPlugin } from '../common/plugin.js'
24
+ import { asyncWaterfall, getDenomInfo } from '../common/utils.js'
25
+ import { getFetchCors } from '../react-native-io.js'
26
+ import { EosEngine } from './eosEngine'
27
+ import {
28
+ asGetActivationCost,
29
+ asGetActivationSupportedCurrencies
30
+ } from './eosSchema.js'
31
+
32
+
33
+ const validCharacters = '12345abcdefghijklmnopqrstuvwxyz.'
34
+
35
+ export function checkAddress(address) {
36
+ // TODO: Check for a valid address format. The passed in
37
+ // address would be a use visible displayed address such as what would
38
+ // go into a QR code
39
+
40
+ for (let i = 0; i < address.length; i++) {
41
+ const c = address.charAt(i)
42
+ if (!validCharacters.includes(c)) {
43
+ return false
44
+ }
45
+ }
46
+ return true
47
+ }
48
+
49
+ export class EosPlugin extends CurrencyPlugin {
50
+
51
+
52
+
53
+ constructor(
54
+ io,
55
+ fetchCors,
56
+ currencyInfo,
57
+ eosJsConfig
58
+ ) {
59
+ super(io, currencyInfo.pluginId, currencyInfo)
60
+
61
+ eosJsConfig.httpEndpoint =
62
+ this.currencyInfo.defaultSettings.otherSettings.eosNodes[0]
63
+ eosJsConfig.fetch = fetchCors
64
+ this.eosServer = EosApi(eosJsConfig)
65
+ }
66
+
67
+ async importPrivateKey(privateKey) {
68
+ const strippedPrivateKey = privateKey.replace(/ /g, '') // should be in WIF format
69
+ if (strippedPrivateKey.length !== 51) {
70
+ throw new Error('Private key wrong length')
71
+ }
72
+ if (!ecc.isValidPrivate(strippedPrivateKey)) {
73
+ throw new Error('Invalid private key')
74
+ }
75
+ return {
76
+ // best practice not to import owner key, only active
77
+ // note that signing is done by active key (eosKey, not eosOwnerKey)
78
+ eosKey: strippedPrivateKey // active private key
79
+ }
80
+ }
81
+
82
+ async createPrivateKey(walletType) {
83
+ const type = walletType.replace('wallet:', '')
84
+
85
+ const currencyInfoType = this.currencyInfo.walletType.replace('wallet:', '')
86
+ if (type === currencyInfoType) {
87
+ // TODO: User currency library to create private key as a string
88
+ // Use io.random() for random number generation
89
+ // Multiple keys can be created and stored here. ie. If there is both a mnemonic and key format,
90
+ // Generate and store them here by returning an arbitrary object with them.
91
+ let entropy = Buffer.from(this.io.random(32)).toString('hex')
92
+ const eosOwnerKey = ecc.seedPrivate(entropy) // returns WIF format
93
+ entropy = Buffer.from(this.io.random(32)).toString('hex')
94
+ const eosKey = ecc.seedPrivate(entropy)
95
+ return { eosOwnerKey, eosKey }
96
+ } else {
97
+ throw new Error('InvalidWalletType')
98
+ }
99
+ }
100
+
101
+ async derivePublicKey(walletInfo) {
102
+ const type = walletInfo.type.replace('wallet:', '')
103
+ const currencyInfoType = this.currencyInfo.walletType.replace('wallet:', '')
104
+ if (type === currencyInfoType) {
105
+ // TODO: User currency library to derive the public keys/addresses from the private key.
106
+ // Multiple keys can be generated and stored if needed. Do not store an HD chain
107
+ // but rather just different versions of the master public key
108
+ // const publicKey = derivePubkey(walletInfo.keys.eosKey)
109
+ // const publicKey = deriveAddress(walletInfo.keys.eosKey)
110
+ const publicKey = ecc.privateToPublic(walletInfo.keys.eosKey)
111
+ let ownerPublicKey
112
+ // usage of eosOwnerKey must be protected by conditional
113
+ // checking for its existence
114
+ if (walletInfo.keys.eosOwnerKey) {
115
+ ownerPublicKey = ecc.privateToPublic(walletInfo.keys.eosOwnerKey)
116
+ }
117
+ return { publicKey, ownerPublicKey }
118
+ } else {
119
+ throw new Error('InvalidWalletType')
120
+ }
121
+ }
122
+
123
+ async parseUri(uri) {
124
+ const { edgeParsedUri } = this.parseUriCommon(this.currencyInfo, uri, {
125
+ [this.currencyInfo.defaultSettings.otherSettings.uriProtocol]: true
126
+ })
127
+
128
+ const valid = checkAddress(edgeParsedUri.publicAddress || '')
129
+ if (!valid) {
130
+ throw new Error('InvalidPublicAddressError')
131
+ }
132
+ return edgeParsedUri
133
+ }
134
+
135
+ async encodeUri(obj) {
136
+ const valid = checkAddress(obj.publicAddress)
137
+ if (!valid) {
138
+ throw new Error('InvalidPublicAddressError')
139
+ }
140
+ let amount
141
+ if (typeof obj.nativeAmount === 'string') {
142
+ const currencyCode = this.currencyInfo.currencyCode
143
+ const nativeAmount = obj.nativeAmount
144
+ const denom = getDenomInfo(this.currencyInfo, currencyCode)
145
+ if (!denom) {
146
+ throw new Error('InternalErrorInvalidCurrencyCode')
147
+ }
148
+ amount = bns.div(nativeAmount, denom.multiplier, 4)
149
+ }
150
+ const encodedUri = this.encodeUriCommon(
151
+ obj,
152
+ this.currencyInfo.defaultSettings.otherSettings.uriProtocol,
153
+ amount
154
+ )
155
+ return encodedUri
156
+ }
157
+
158
+ // change to fetch call in the future
159
+ async getAccSystemStats(account) {
160
+ return new Promise((resolve, reject) => {
161
+ this.eosServer.getAccount(account, (error, result) => {
162
+ if (error) {
163
+ if (error.message.includes('unknown key')) {
164
+ error.code = 'ErrorUnknownAccount'
165
+ }
166
+ reject(error)
167
+ }
168
+ resolve(result)
169
+ })
170
+ })
171
+ }
172
+ }
173
+
174
+ export function makeEosBasedPluginInner(
175
+ opts,
176
+ currencyInfo,
177
+ eosJsConfig
178
+ ) {
179
+ const { io, log } = opts
180
+ const fetch = getFetchCors(opts)
181
+
182
+ let toolsPromise
183
+ function makeCurrencyTools() {
184
+ if (toolsPromise != null) return toolsPromise
185
+ toolsPromise = Promise.resolve(
186
+ new EosPlugin(io, fetch, currencyInfo, eosJsConfig)
187
+ )
188
+ return toolsPromise
189
+ }
190
+
191
+ async function makeCurrencyEngine(
192
+ walletInfo,
193
+ opts
194
+ ) {
195
+ const tools = await makeCurrencyTools()
196
+ const currencyEngine = new EosEngine(
197
+ tools,
198
+ walletInfo,
199
+ opts,
200
+ fetch,
201
+ eosJsConfig
202
+ )
203
+ await currencyEngine.loadEngine(tools, walletInfo, opts)
204
+
205
+ currencyEngine.otherData = currencyEngine.walletLocalData.otherData
206
+ // currencyEngine.otherData is an opaque utility object for use for currency
207
+ // specific data that will be persisted to disk on this one device.
208
+ // Commonly stored data would be last queried block height or nonce values for accounts
209
+ // Edit the flow type EosWalletOtherData and initialize those values here if they are
210
+ // undefined
211
+ // TODO: Initialize anything specific to this currency
212
+ // if (!currencyEngine.otherData.nonce) currencyEngine.otherData.nonce = 0
213
+ if (!currencyEngine.otherData.accountName) {
214
+ currencyEngine.otherData.accountName = ''
215
+ }
216
+ if (!currencyEngine.otherData.lastQueryActionSeq) {
217
+ currencyEngine.otherData.lastQueryActionSeq = {}
218
+ }
219
+ if (!currencyEngine.otherData.highestTxHeight) {
220
+ currencyEngine.otherData.highestTxHeight = {}
221
+ }
222
+
223
+ const out = currencyEngine
224
+ return out
225
+ }
226
+
227
+ const otherMethods = {
228
+ getActivationSupportedCurrencies: async () => {
229
+ try {
230
+ const out = await asyncWaterfall(
231
+ currencyInfo.defaultSettings.otherSettings.eosActivationServers.map(
232
+ server => async () => {
233
+ const uri = `${server}/api/v1/getSupportedCurrencies`
234
+ const response = await fetch(uri)
235
+ const result = await response.json()
236
+ return {
237
+ result
238
+ }
239
+ }
240
+ )
241
+ )
242
+ return asGetActivationSupportedCurrencies(out)
243
+ } catch (e) {
244
+ log.error('UnableToGetSupportedCurrencies error: ', e)
245
+ throw new Error('UnableToGetSupportedCurrencies')
246
+ }
247
+ },
248
+ getActivationCost: async (currencyCode) => {
249
+ try {
250
+ const out = await asyncWaterfall(
251
+ currencyInfo.defaultSettings.otherSettings.eosActivationServers.map(
252
+ server => async () => {
253
+ const uri = `${server}/api/v1/eosPrices/${currencyCode}`
254
+ const response = await fetch(uri)
255
+ const prices = asGetActivationCost(await response.json())
256
+ const startingResourcesUri = `${server}/api/v1/startingResources/${currencyCode}`
257
+ const startingResourcesResponse = await fetch(
258
+ startingResourcesUri
259
+ )
260
+ const startingResources = asGetActivationCost(
261
+ await startingResourcesResponse.json()
262
+ )
263
+ const totalEos =
264
+ Number(prices.ram) * startingResources.ram +
265
+ Number(prices.net) * startingResources.net +
266
+ Number(prices.cpu) * startingResources.cpu
267
+ const totalEosString = totalEos.toString()
268
+ const price = bns.toFixed(totalEosString, 0, 4)
269
+ return price
270
+ }
271
+ )
272
+ )
273
+ return out
274
+ } catch (e) {
275
+ log.error('ErrorUnableToGetCost: ', e)
276
+ throw new Error('ErrorUnableToGetCost')
277
+ }
278
+ },
279
+ validateAccount: async (account) => {
280
+ const valid = checkAddress(account) && account.length === 12
281
+ const out = { result: '' }
282
+ if (!valid) {
283
+ const e = new Error('ErrorInvalidAccountName')
284
+ e.name = 'ErrorInvalidAccountName'
285
+ throw e
286
+ }
287
+ try {
288
+ const tools = await makeCurrencyTools()
289
+ const result = await tools.getAccSystemStats(account)
290
+ if (result) {
291
+ const e = new Error('ErrorAccountUnavailable')
292
+ e.name = 'ErrorAccountUnavailable'
293
+ throw e
294
+ }
295
+ throw new Error('ErrorUnknownError')
296
+ } catch (e) {
297
+ if (e.code === 'ErrorUnknownAccount') {
298
+ out.result = 'AccountAvailable'
299
+ } else {
300
+ throw e
301
+ }
302
+ }
303
+ log.warn(`validateAccount: result=${out.result}`)
304
+ return out
305
+ }
306
+ }
307
+
308
+ return {
309
+ currencyInfo,
310
+ makeCurrencyEngine,
311
+ makeCurrencyTools,
312
+ otherMethods
313
+ }
314
+ }
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Created by paul on 8/27/17.
3
+ */
4
+
5
+ import {
6
+ asArray,
7
+ asBoolean,
8
+ asMap,
9
+ asNumber,
10
+ asObject,
11
+ asOptional,
12
+ asString
13
+ } from 'cleaners'
14
+
15
+ export const asGetAccountActivationQuote = asObject({
16
+ amount: asString,
17
+ currencyCode: asString,
18
+ expireTime: asNumber,
19
+ paymentAddress: asString
20
+ })
21
+
22
+ export const asGetActivationSupportedCurrencies = asObject({
23
+ result: asMap(asBoolean)
24
+ })
25
+
26
+ export const asGetActivationCost = asObject({
27
+ cpu: asNumber,
28
+ net: asNumber,
29
+ ram: asNumber
30
+ })
31
+
32
+ export const asHyperionTransaction = asObject({
33
+ trx_id: asString,
34
+ '@timestamp': asString,
35
+ block_num: asNumber,
36
+ act: asObject({
37
+ authorization: asOptional(
38
+ asArray(
39
+ asObject({
40
+ actor: asString,
41
+ permission: asString
42
+ })
43
+ )
44
+ ),
45
+ data: asObject({
46
+ from: asString,
47
+ to: asString,
48
+ amount: asNumber,
49
+ symbol: asString,
50
+ memo: asString
51
+ })
52
+ })
53
+ })
54
+
55
+ export const asHyperionGetTransactionResponse = asObject({
56
+ actions: asArray(asHyperionTransaction)
57
+ })
58
+
59
+ export const asDfuseGetKeyAccountsResponse = asObject({
60
+ account_names: asArray(asString)
61
+ })
62
+
63
+ export const asDfuseTransaction = asObject({
64
+ trace: asObject({
65
+ block: asObject({
66
+ num: asNumber,
67
+ timestamp: asString
68
+ }),
69
+ id: asString,
70
+ matchingActions: asArray(
71
+ asObject({
72
+ json: asObject({
73
+ from: asString,
74
+ memo: asString,
75
+ quantity: asString,
76
+ to: asString
77
+ }),
78
+ authorization: asArray(
79
+ asObject({
80
+ actor: asString,
81
+ permission: asString
82
+ })
83
+ )
84
+ })
85
+ )
86
+ })
87
+ })
88
+
89
+ export const asDfuseGetTransactionsResponse = asObject({
90
+ data: asObject({
91
+ searchTransactionsBackward: asObject({
92
+ results: asArray(asDfuseTransaction)
93
+ })
94
+ })
95
+ })
96
+
97
+ export const asDfuseGetTransactionsErrorResponse = asObject({
98
+ errors: asArray(
99
+ asObject({
100
+ message: asString,
101
+ extensions: asObject({
102
+ code: asString,
103
+ terminal: asBoolean
104
+ })
105
+ })
106
+ )
107
+ })
108
+
109
+ export const dfuseGetTransactionsQueryString = `
110
+ query ($query: String!, $limit: Int64, $low: Int64, $high: Int64) {
111
+ searchTransactionsBackward(query: $query, lowBlockNum: $low, highBlockNum: $high, limit: $limit) {
112
+ results {
113
+ trace {
114
+ block {
115
+ num
116
+ timestamp
117
+ }
118
+ id
119
+ matchingActions {
120
+ json
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ `
127
+
128
+ // export const EosGetBalancesSchema = {
129
+ // type: 'array',
130
+ // items: {
131
+ // type: 'object',
132
+ // properties: {
133
+ // currency: { type: 'string' },
134
+ // value: { type: 'string' }
135
+ // }
136
+ // }
137
+ // }
138
+
139
+ // note that transfers are regular EOS transactions
140
+ export const EosTransactionSuperNodeSchema = {
141
+ type: 'object',
142
+ properties: {
143
+ act: {
144
+ type: 'object',
145
+ properties: {
146
+ data: {
147
+ type: 'object',
148
+ properties: {
149
+ from: { type: 'string' },
150
+ to: { type: 'string' },
151
+ amount: { type: 'number' },
152
+ symbol: { type: 'string' },
153
+ memo: { type: 'string' }
154
+ },
155
+ required: ['from', 'to', 'amount'],
156
+ authorization: { type: 'object' }
157
+ }
158
+ },
159
+ required: ['data']
160
+ },
161
+ trx_id: { type: 'string' },
162
+ '@timestamp': { type: 'string' },
163
+ block_num: { type: 'number' },
164
+ required: ['act', 'trx_id', '@timestamp', 'block_num']
165
+ }
166
+ }
167
+
168
+ // export const EosGetTransactionsSchema = {
169
+ // type: 'array',
170
+ // items: {
171
+ // type: 'object',
172
+ // properties: {
173
+ // type: { type: 'string' },
174
+ // address: { type: 'string' },
175
+ // id: { type: 'string' },
176
+ // outcome: {
177
+ // type: 'object',
178
+ // properties: {
179
+ // result: { type: 'string' },
180
+ // timestamp: { type: 'string' },
181
+ // fee: { type: 'string' },
182
+ // ledgerVersion: { type: 'number' },
183
+ // balanceChanges: {
184
+ // type: 'object'
185
+ // }
186
+ // }
187
+ // }
188
+ // }
189
+ // }
190
+ // }