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.
- package/CHANGELOG.md +713 -0
- package/LICENSE +29 -0
- package/README.md +63 -0
- package/index.js +3 -0
- package/lib/binance/bnbEngine.js +591 -0
- package/lib/binance/bnbInfo.js +43 -0
- package/lib/binance/bnbPlugin.js +168 -0
- package/lib/binance/bnbSchema.js +83 -0
- package/lib/binance/bnbTypes.js +39 -0
- package/lib/common/engine.js +918 -0
- package/lib/common/plugin.js +152 -0
- package/lib/common/schema.js +108 -0
- package/lib/common/types.js +85 -0
- package/lib/common/utils.js +378 -0
- package/lib/eos/eosEngine.js +1216 -0
- package/lib/eos/eosInfo.js +98 -0
- package/lib/eos/eosPlugin.js +314 -0
- package/lib/eos/eosSchema.js +190 -0
- package/lib/eos/eosTypes.js +88 -0
- package/lib/eos/telosInfo.js +94 -0
- package/lib/eos/waxInfo.js +95 -0
- package/lib/ethereum/etcInfo.js +121 -0
- package/lib/ethereum/ethEngine.js +832 -0
- package/lib/ethereum/ethInfo.js +1300 -0
- package/lib/ethereum/ethMiningFees.js +157 -0
- package/lib/ethereum/ethNetwork.js +2195 -0
- package/lib/ethereum/ethPlugin.js +377 -0
- package/lib/ethereum/ethSchema.js +61 -0
- package/lib/ethereum/ethTypes.js +461 -0
- package/lib/ethereum/ftminfo.js +102 -0
- package/lib/ethereum/rskInfo.js +101 -0
- package/lib/fio/fioConst.js +38 -0
- package/lib/fio/fioEngine.js +1250 -0
- package/lib/fio/fioError.js +38 -0
- package/lib/fio/fioInfo.js +72 -0
- package/lib/fio/fioPlugin.js +486 -0
- package/lib/fio/fioSchema.js +56 -0
- package/lib/index.js +44 -0
- package/lib/pluginError.js +32 -0
- package/lib/react-native/edge-currency-accountbased.js +239635 -0
- package/lib/react-native/edge-currency-accountbased.js.map +1 -0
- package/lib/react-native-io.js +41 -0
- package/lib/stellar/stellarEngine.js +563 -0
- package/lib/stellar/stellarInfo.js +37 -0
- package/lib/stellar/stellarPlugin.js +215 -0
- package/lib/stellar/stellarSchema.js +54 -0
- package/lib/stellar/stellarTypes.js +66 -0
- package/lib/tezos/tezosEngine.js +497 -0
- package/lib/tezos/tezosInfo.js +60 -0
- package/lib/tezos/tezosPlugin.js +174 -0
- package/lib/tezos/tezosTypes.js +110 -0
- package/lib/xrp/xrpEngine.js +583 -0
- package/lib/xrp/xrpInfo.js +47 -0
- package/lib/xrp/xrpPlugin.js +229 -0
- package/lib/xrp/xrpSchema.js +74 -0
- package/lib/xrp/xrpTypes.js +38 -0
- package/package.json +139 -0
- package/postinstall.sh +7 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const otherSettings = {
|
|
9
|
+
binanceApiServers: [
|
|
10
|
+
'https://dex.binance.org',
|
|
11
|
+
'https://dex-atlantic.binance.org',
|
|
12
|
+
'https://dex-asiapacific.binance.org',
|
|
13
|
+
'https://dex-european.binance.org'
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const defaultSettings = {
|
|
18
|
+
otherSettings
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const currencyInfo = {
|
|
22
|
+
// Basic currency information:
|
|
23
|
+
currencyCode: 'BNB',
|
|
24
|
+
displayName: 'Binance Chain',
|
|
25
|
+
pluginId: 'binance',
|
|
26
|
+
walletType: 'wallet:binance',
|
|
27
|
+
|
|
28
|
+
defaultSettings,
|
|
29
|
+
|
|
30
|
+
addressExplorer: 'https://explorer.binance.org/address/%s',
|
|
31
|
+
transactionExplorer: 'https://explorer.binance.org/tx/%s',
|
|
32
|
+
blockExplorer: 'https://explorer.binance.org/block/%s',
|
|
33
|
+
|
|
34
|
+
denominations: [
|
|
35
|
+
// An array of Objects of the possible denominations for this currency
|
|
36
|
+
{
|
|
37
|
+
name: 'BNB',
|
|
38
|
+
multiplier: '100000000',
|
|
39
|
+
symbol: 'B'
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
metaTokens: []
|
|
43
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by paul on 8/8/17.
|
|
3
|
+
*/
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import BnbApiClient from '@binance-chain/javascript-sdk'
|
|
7
|
+
import { bns } from 'biggystring'
|
|
8
|
+
import { entropyToMnemonic } from 'bip39'
|
|
9
|
+
import { Buffer } from 'buffer'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
import { CurrencyPlugin } from '../common/plugin.js'
|
|
23
|
+
import { getDenomInfo } from '../common/utils.js'
|
|
24
|
+
import { BinanceEngine } from './bnbEngine.js'
|
|
25
|
+
import { currencyInfo } from './bnbInfo.js'
|
|
26
|
+
|
|
27
|
+
const bnbCrypto = BnbApiClient.crypto
|
|
28
|
+
|
|
29
|
+
export class BinancePlugin extends CurrencyPlugin {
|
|
30
|
+
constructor(io) {
|
|
31
|
+
super(io, 'binance', currencyInfo)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// will actually use MNEMONIC version of private key
|
|
35
|
+
async importPrivateKey(mnemonic) {
|
|
36
|
+
const isValid = bnbCrypto.validateMnemonic(mnemonic)
|
|
37
|
+
if (!isValid) throw new Error('Invalid BNB mnemonic')
|
|
38
|
+
const binanceKey = bnbCrypto.getPrivateKeyFromMnemonic(mnemonic)
|
|
39
|
+
|
|
40
|
+
return { binanceMnemonic: mnemonic, binanceKey }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async createPrivateKey(walletType) {
|
|
44
|
+
const type = walletType.replace('wallet:', '')
|
|
45
|
+
|
|
46
|
+
if (type === 'binance') {
|
|
47
|
+
const entropy = Buffer.from(this.io.random(32)).toString('hex')
|
|
48
|
+
const binanceMnemonic = entropyToMnemonic(entropy)
|
|
49
|
+
const binanceKey = bnbCrypto.getPrivateKeyFromMnemonic(binanceMnemonic)
|
|
50
|
+
|
|
51
|
+
return { binanceMnemonic, binanceKey }
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error('InvalidWalletType')
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async derivePublicKey(walletInfo) {
|
|
58
|
+
const type = walletInfo.type.replace('wallet:', '')
|
|
59
|
+
if (type === 'binance') {
|
|
60
|
+
let publicKey = ''
|
|
61
|
+
let privateKey = walletInfo.keys.binanceKey
|
|
62
|
+
if (typeof privateKey !== 'string') {
|
|
63
|
+
privateKey = bnbCrypto.getPrivateKeyFromMnemonic(
|
|
64
|
+
walletInfo.keys.binanceMnemonic
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
publicKey = bnbCrypto.getAddressFromPrivateKey(privateKey, 'bnb')
|
|
68
|
+
return { publicKey }
|
|
69
|
+
} else {
|
|
70
|
+
throw new Error('InvalidWalletType')
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async parseUri(
|
|
75
|
+
uri,
|
|
76
|
+
currencyCode,
|
|
77
|
+
customTokens
|
|
78
|
+
) {
|
|
79
|
+
const networks = { binance: true }
|
|
80
|
+
|
|
81
|
+
const { parsedUri, edgeParsedUri } = this.parseUriCommon(
|
|
82
|
+
currencyInfo,
|
|
83
|
+
uri,
|
|
84
|
+
networks,
|
|
85
|
+
currencyCode || 'BNB',
|
|
86
|
+
customTokens
|
|
87
|
+
)
|
|
88
|
+
let address = ''
|
|
89
|
+
if (edgeParsedUri.publicAddress) {
|
|
90
|
+
address = edgeParsedUri.publicAddress
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const valid = bnbCrypto.checkAddress(address || '', 'bnb')
|
|
94
|
+
if (!valid) {
|
|
95
|
+
throw new Error('InvalidPublicAddressError')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
edgeParsedUri.uniqueIdentifier = parsedUri.query.memo || undefined
|
|
99
|
+
return edgeParsedUri
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async encodeUri(
|
|
103
|
+
obj,
|
|
104
|
+
customTokens
|
|
105
|
+
) {
|
|
106
|
+
const { publicAddress, nativeAmount, currencyCode } = obj
|
|
107
|
+
const valid = bnbCrypto.checkAddress(publicAddress, 'bnb')
|
|
108
|
+
if (!valid) {
|
|
109
|
+
throw new Error('InvalidPublicAddressError')
|
|
110
|
+
}
|
|
111
|
+
let amount
|
|
112
|
+
if (typeof nativeAmount === 'string') {
|
|
113
|
+
const denom = getDenomInfo(
|
|
114
|
+
currencyInfo,
|
|
115
|
+
currencyCode || 'BNB',
|
|
116
|
+
customTokens
|
|
117
|
+
)
|
|
118
|
+
if (!denom) {
|
|
119
|
+
throw new Error('InternalErrorInvalidCurrencyCode')
|
|
120
|
+
}
|
|
121
|
+
amount = bns.div(nativeAmount, denom.multiplier, 18)
|
|
122
|
+
}
|
|
123
|
+
const encodedUri = this.encodeUriCommon(obj, 'binance', amount)
|
|
124
|
+
return encodedUri
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function makeBinancePlugin(
|
|
129
|
+
opts
|
|
130
|
+
) {
|
|
131
|
+
const { io, initOptions } = opts
|
|
132
|
+
|
|
133
|
+
let toolsPromise
|
|
134
|
+
function makeCurrencyTools() {
|
|
135
|
+
if (toolsPromise != null) return toolsPromise
|
|
136
|
+
toolsPromise = Promise.resolve(new BinancePlugin(io))
|
|
137
|
+
return toolsPromise
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function makeCurrencyEngine(
|
|
141
|
+
walletInfo,
|
|
142
|
+
opts
|
|
143
|
+
) {
|
|
144
|
+
const tools = await makeCurrencyTools()
|
|
145
|
+
const currencyEngine = new BinanceEngine(
|
|
146
|
+
tools,
|
|
147
|
+
walletInfo,
|
|
148
|
+
initOptions,
|
|
149
|
+
opts
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
// Do any async initialization necessary for the engine
|
|
153
|
+
await currencyEngine.loadEngine(tools, walletInfo, opts)
|
|
154
|
+
|
|
155
|
+
// This is just to make sure otherData is Flow type checked
|
|
156
|
+
currencyEngine.otherData = currencyEngine.walletLocalData.otherData
|
|
157
|
+
|
|
158
|
+
const out = currencyEngine
|
|
159
|
+
|
|
160
|
+
return out
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
currencyInfo,
|
|
165
|
+
makeCurrencyEngine,
|
|
166
|
+
makeCurrencyTools
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by paul on 8/27/17.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const BinanceApiNodeInfo = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
sync_info: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
latest_block_hash: { type: 'string' },
|
|
12
|
+
latest_app_hash: { type: 'string' },
|
|
13
|
+
latest_block_height: { type: 'number' },
|
|
14
|
+
latest_block_time: { type: 'string' },
|
|
15
|
+
catching_up: { type: 'boolean' }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
required: ['sync_info']
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const BinanceApiAccountBalance = {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
address: { type: 'string' },
|
|
26
|
+
balances: {
|
|
27
|
+
type: 'array',
|
|
28
|
+
items: {
|
|
29
|
+
free: { type: 'string' },
|
|
30
|
+
frozen: { type: 'string' },
|
|
31
|
+
locked: { type: 'string' },
|
|
32
|
+
symbol: { type: 'string' }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
required: ['balances', 'address']
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const BinanceApiGetTransactions = {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
tx: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
items: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: {
|
|
47
|
+
blockHeight: { type: 'number' },
|
|
48
|
+
timeStamp: { type: 'string' },
|
|
49
|
+
txHash: { type: 'string' },
|
|
50
|
+
fromAddr: { type: 'string' },
|
|
51
|
+
toAddr: { type: 'string' },
|
|
52
|
+
value: { type: 'string' },
|
|
53
|
+
txFee: { type: 'string' },
|
|
54
|
+
txAsset: { type: 'string' },
|
|
55
|
+
memo: { type: 'string' }
|
|
56
|
+
},
|
|
57
|
+
required: [
|
|
58
|
+
'blockHeight',
|
|
59
|
+
'timeStamp',
|
|
60
|
+
'txHash',
|
|
61
|
+
'fromAddr',
|
|
62
|
+
'toAddr',
|
|
63
|
+
'value',
|
|
64
|
+
'txFee',
|
|
65
|
+
'txAsset',
|
|
66
|
+
'memo'
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
required: ['tx']
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const CustomTokenSchema = {
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
currencyCode: { type: 'string' },
|
|
78
|
+
currencyName: { type: 'string' },
|
|
79
|
+
multiplier: { type: 'string' },
|
|
80
|
+
contractAddress: { type: 'string' }
|
|
81
|
+
},
|
|
82
|
+
required: ['currencyCode', 'currencyName', 'multiplier', 'contractAddress']
|
|
83
|
+
}
|