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,215 @@
1
+ /**
2
+ * Created by paul on 8/8/17.
3
+ */
4
+ //
5
+
6
+ import { bns } from 'biggystring'
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ import stellarApi from 'stellar-sdk'
18
+ import { serialize } from 'uri-js'
19
+ import parse from 'url-parse'
20
+
21
+ import { CurrencyPlugin } from '../common/plugin.js'
22
+ import { getDenomInfo } from '../common/utils.js'
23
+ import { StellarEngine } from './stellarEngine.js'
24
+ import { currencyInfo } from './stellarInfo.js'
25
+
26
+ const URI_PREFIX = 'web+stellar'
27
+
28
+ export class StellarPlugin extends CurrencyPlugin {
29
+
30
+ constructor(io) {
31
+ super(io, 'stellar', currencyInfo)
32
+ stellarApi.Network.usePublicNetwork()
33
+ this.stellarApiServers = []
34
+ for (const server of currencyInfo.defaultSettings.otherSettings
35
+ .stellarServers) {
36
+ const stellarServer = new stellarApi.Server(server)
37
+ stellarServer.serverName = server
38
+ this.stellarApiServers.push(stellarServer)
39
+ }
40
+ }
41
+
42
+ checkAddress(address) {
43
+ // TODO: check address
44
+ try {
45
+ stellarApi.Keypair.fromPublicKey(address)
46
+ return true
47
+ } catch (e) {
48
+ return false
49
+ }
50
+ }
51
+
52
+ async createPrivateKey(walletType) {
53
+ const type = walletType.replace('wallet:', '')
54
+
55
+ if (type === 'stellar') {
56
+ const entropy = Array.from(this.io.random(32))
57
+ const keypair = stellarApi.Keypair.fromRawEd25519Seed(entropy)
58
+ return { stellarKey: keypair.secret() }
59
+ } else {
60
+ throw new Error('InvalidWalletType')
61
+ }
62
+ }
63
+
64
+ importPrivateKey(privateKey) {
65
+ privateKey.replace(/ /g, '')
66
+ stellarApi.Keypair.fromSecret(privateKey)
67
+ if (privateKey.length !== 56) throw new Error('Private key wrong length')
68
+ return Promise.resolve({ stellarKey: privateKey })
69
+ }
70
+
71
+ async derivePublicKey(walletInfo) {
72
+ const type = walletInfo.type.replace('wallet:', '')
73
+ if (type === 'stellar') {
74
+ const keypair = stellarApi.Keypair.fromSecret(walletInfo.keys.stellarKey)
75
+ return { publicKey: keypair.publicKey() }
76
+ } else {
77
+ throw new Error('InvalidWalletType')
78
+ }
79
+ }
80
+
81
+ async parseUri(uri) {
82
+ const networks = {}
83
+ networks[URI_PREFIX] = true
84
+ const STELLAR_SEP007_PREFIX = `${URI_PREFIX}:pay`
85
+
86
+ if (uri.includes(STELLAR_SEP007_PREFIX)) {
87
+ const parsedUri = parse(uri, {}, true)
88
+ const addr = parsedUri.query.destination
89
+ if (addr) {
90
+ uri = uri.replace(STELLAR_SEP007_PREFIX, `${URI_PREFIX}:${addr}`)
91
+ }
92
+ }
93
+
94
+ const { parsedUri, edgeParsedUri } = this.parseUriCommon(
95
+ currencyInfo,
96
+ uri,
97
+ networks
98
+ )
99
+
100
+ const valid = this.checkAddress(edgeParsedUri.publicAddress || '')
101
+ if (!valid) {
102
+ throw new Error('InvalidPublicAddressError')
103
+ }
104
+
105
+ if (parsedUri.query.msg) {
106
+ edgeParsedUri.metadata = {
107
+ notes: parsedUri.query.msg
108
+ }
109
+ }
110
+ if (parsedUri.query.asset_code) {
111
+ if (parsedUri.query.asset_code.toUpperCase() !== 'XLM') {
112
+ throw new Error('ErrorInvalidCurrencyCode')
113
+ }
114
+ }
115
+ if (parsedUri.query.memo_type) {
116
+ if (parsedUri.query.memo_type !== 'MEMO_ID') {
117
+ throw new Error('ErrorInvalidMemoType')
118
+ }
119
+ }
120
+ if (parsedUri.query.memo) {
121
+ const m = bns.add(parsedUri.query.memo, '0')
122
+ // Check if the memo is an integer
123
+ if (m !== parsedUri.query.memo) {
124
+ throw new Error('ErrorInvalidMemoId')
125
+ }
126
+ edgeParsedUri.uniqueIdentifier = parsedUri.query.memo
127
+ }
128
+ return edgeParsedUri
129
+ }
130
+
131
+ async encodeUri(obj) {
132
+ const valid = this.checkAddress(obj.publicAddress)
133
+ if (!valid) {
134
+ throw new Error('InvalidPublicAddressError')
135
+ }
136
+ let amount
137
+ if (typeof obj.nativeAmount === 'string') {
138
+ const currencyCode = 'XLM'
139
+ const nativeAmount = obj.nativeAmount
140
+ const denom = getDenomInfo(currencyInfo, currencyCode)
141
+ if (!denom) {
142
+ throw new Error('InternalErrorInvalidCurrencyCode')
143
+ }
144
+ amount = bns.div(nativeAmount, denom.multiplier, 7)
145
+ }
146
+ if (!amount && !obj.label && !obj.message) {
147
+ return obj.publicAddress
148
+ } else {
149
+ let queryString = `destination=${obj.publicAddress}&`
150
+ if (amount) {
151
+ queryString += 'amount=' + amount + '&'
152
+ }
153
+ if (obj.label || obj.message) {
154
+ if (typeof obj.label === 'string') {
155
+ queryString += 'label=' + obj.label + '&'
156
+ }
157
+ if (typeof obj.message === 'string') {
158
+ queryString += 'msg=' + obj.message + '&'
159
+ }
160
+ }
161
+ queryString = queryString.substr(0, queryString.length - 1)
162
+
163
+ const serializeObj = {
164
+ scheme: URI_PREFIX,
165
+ path: 'pay',
166
+ query: queryString
167
+ }
168
+ const url = serialize(serializeObj)
169
+ return url
170
+ }
171
+ }
172
+ }
173
+
174
+ export function makeStellarPlugin(
175
+ opts
176
+ ) {
177
+ const { io } = opts
178
+
179
+ let toolsPromise
180
+ function makeCurrencyTools() {
181
+ if (toolsPromise != null) return toolsPromise
182
+ toolsPromise = Promise.resolve(new StellarPlugin(io))
183
+ return toolsPromise
184
+ }
185
+
186
+ async function makeCurrencyEngine(
187
+ walletInfo,
188
+ opts
189
+ ) {
190
+ const tools = await makeCurrencyTools()
191
+ const currencyEngine = new StellarEngine(tools, walletInfo, opts)
192
+
193
+ currencyEngine.stellarApi = stellarApi
194
+
195
+ await currencyEngine.loadEngine(tools, walletInfo, opts)
196
+
197
+ // This is just to make sure otherData is Flow type checked
198
+ currencyEngine.otherData = currencyEngine.walletLocalData.otherData
199
+ if (!currencyEngine.otherData.accountSequence) {
200
+ currencyEngine.otherData.accountSequence = 0
201
+ }
202
+ if (!currencyEngine.otherData.lastPagingToken) {
203
+ currencyEngine.otherData.lastPagingToken = '0'
204
+ }
205
+
206
+ const out = currencyEngine
207
+ return out
208
+ }
209
+
210
+ return {
211
+ currencyInfo,
212
+ makeCurrencyEngine,
213
+ makeCurrencyTools
214
+ }
215
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Created by paul on 8/27/17.
3
+ */
4
+
5
+ export const StellarGetServerInfoSchema = {
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 StellarGetAccountSchema = {
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 StellarGetTransactionsSchema = {
33
+ type: 'array',
34
+ items: {
35
+ type: 'object',
36
+ properties: {
37
+ type: { type: 'string' },
38
+ address: { type: 'string' },
39
+ id: { type: 'string' },
40
+ outcome: {
41
+ type: 'object',
42
+ properties: {
43
+ result: { type: 'string' },
44
+ timestamp: { type: 'string' },
45
+ fee: { type: 'string' },
46
+ ledgerVersion: { type: 'number' },
47
+ balanceChanges: {
48
+ type: 'object'
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }