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,174 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import { eztz } from 'eztz.js'
|
|
14
|
+
import { decodeMainnet, encodeMainnet } from 'tezos-uri'
|
|
15
|
+
|
|
16
|
+
import { CurrencyPlugin } from '../common/plugin.js'
|
|
17
|
+
import { getFetchCors } from '../react-native-io.js'
|
|
18
|
+
import { TezosEngine } from './tezosEngine.js'
|
|
19
|
+
import { currencyInfo } from './tezosInfo.js'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export class TezosPlugin extends CurrencyPlugin {
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
constructor(io, fetchCors) {
|
|
26
|
+
super(io, 'tezos', currencyInfo)
|
|
27
|
+
this.tezosRpcNodes = []
|
|
28
|
+
for (const rpcNode of currencyInfo.defaultSettings.otherSettings
|
|
29
|
+
.tezosRpcNodes) {
|
|
30
|
+
this.tezosRpcNodes.push(rpcNode)
|
|
31
|
+
}
|
|
32
|
+
this.tezosApiServers = []
|
|
33
|
+
for (const apiServer of currencyInfo.defaultSettings.otherSettings
|
|
34
|
+
.tezosApiServers) {
|
|
35
|
+
this.tezosApiServers.push(apiServer)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
checkAddress(address) {
|
|
40
|
+
try {
|
|
41
|
+
const valid = eztz.crypto.checkAddress(address)
|
|
42
|
+
return valid
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async importPrivateKey(userInput) {
|
|
49
|
+
// check for existence of numbers
|
|
50
|
+
if (/\d/.test(userInput)) {
|
|
51
|
+
throw new Error('Input must be mnemonic phrase')
|
|
52
|
+
}
|
|
53
|
+
const wordList = userInput.split(' ')
|
|
54
|
+
const wordCount = wordList.length
|
|
55
|
+
if (wordCount !== 24) {
|
|
56
|
+
throw new Error('Mnemonic phrase must be 24 words long')
|
|
57
|
+
}
|
|
58
|
+
const keys = eztz.crypto.generateKeys(userInput, '')
|
|
59
|
+
this.derivePublicKey({
|
|
60
|
+
type: 'wallet:tezos',
|
|
61
|
+
id: 'fake',
|
|
62
|
+
keys
|
|
63
|
+
})
|
|
64
|
+
return {
|
|
65
|
+
mnemonic: keys.mnemonic,
|
|
66
|
+
privateKey: keys.sk
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async createPrivateKey(walletType) {
|
|
71
|
+
const type = walletType.replace('wallet:', '')
|
|
72
|
+
if (type === 'tezos') {
|
|
73
|
+
// Use 256 bits entropy
|
|
74
|
+
const entropy = Buffer.from(this.io.random(32)).toString('hex')
|
|
75
|
+
const mnemonic = eztz.library.bip39.entropyToMnemonic(entropy)
|
|
76
|
+
const privateKey = eztz.crypto.generateKeys(mnemonic, '').sk
|
|
77
|
+
return { mnemonic, privateKey }
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error('InvalidWalletType')
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async derivePublicKey(walletInfo) {
|
|
84
|
+
const type = walletInfo.type.replace('wallet:', '')
|
|
85
|
+
if (type === 'tezos') {
|
|
86
|
+
const keypair = eztz.crypto.generateKeys(walletInfo.keys.mnemonic, '')
|
|
87
|
+
return { publicKey: keypair.pkh, publicKeyEd: keypair.pk }
|
|
88
|
+
} else {
|
|
89
|
+
throw new Error('InvalidWalletType')
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async parseUri(uri) {
|
|
94
|
+
let address
|
|
95
|
+
let operation
|
|
96
|
+
let content
|
|
97
|
+
if (this.checkAddress(uri)) {
|
|
98
|
+
address = uri
|
|
99
|
+
} else if (uri.slice(0, 10) === 'web+tezos:') {
|
|
100
|
+
operation = decodeMainnet(uri)
|
|
101
|
+
if (!operation[0] || !operation[0].content) {
|
|
102
|
+
throw new Error('InvalidUriError')
|
|
103
|
+
}
|
|
104
|
+
content = operation[0].content
|
|
105
|
+
address = content.destination
|
|
106
|
+
if (!this.checkAddress(address)) {
|
|
107
|
+
throw new Error('InvalidPublicAddressError')
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
throw new Error('InvalidUriError')
|
|
111
|
+
}
|
|
112
|
+
const edgeParsedUri = {
|
|
113
|
+
publicAddress: address
|
|
114
|
+
}
|
|
115
|
+
edgeParsedUri.nativeAmount =
|
|
116
|
+
content && content.amount !== '0' ? content.amount : undefined
|
|
117
|
+
edgeParsedUri.currencyCode = 'XTZ'
|
|
118
|
+
return edgeParsedUri
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async encodeUri(obj) {
|
|
122
|
+
const valid = this.checkAddress(obj.publicAddress)
|
|
123
|
+
if (!valid) {
|
|
124
|
+
throw new Error('InvalidPublicAddressError')
|
|
125
|
+
}
|
|
126
|
+
if (obj.currencyCode !== 'XTZ') {
|
|
127
|
+
throw new Error('InvalidCurrencyCodeError')
|
|
128
|
+
}
|
|
129
|
+
const amount = typeof obj.nativeAmount === 'string' ? obj.nativeAmount : '0'
|
|
130
|
+
const content = {
|
|
131
|
+
kind: 'transaction',
|
|
132
|
+
amount,
|
|
133
|
+
destination: obj.publicAddress
|
|
134
|
+
}
|
|
135
|
+
const uri = encodeMainnet([{ content }])
|
|
136
|
+
return uri
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function makeTezosPlugin(
|
|
140
|
+
opts
|
|
141
|
+
) {
|
|
142
|
+
const { io } = opts
|
|
143
|
+
const fetchCors = getFetchCors(opts)
|
|
144
|
+
|
|
145
|
+
let toolsPromise
|
|
146
|
+
function makeCurrencyTools() {
|
|
147
|
+
if (toolsPromise != null) return toolsPromise
|
|
148
|
+
toolsPromise = Promise.resolve(new TezosPlugin(io, fetchCors))
|
|
149
|
+
return toolsPromise
|
|
150
|
+
}
|
|
151
|
+
async function makeCurrencyEngine(
|
|
152
|
+
walletInfo,
|
|
153
|
+
opts
|
|
154
|
+
) {
|
|
155
|
+
const tools = await makeCurrencyTools()
|
|
156
|
+
const currencyEngine = new TezosEngine(tools, walletInfo, opts, fetchCors)
|
|
157
|
+
|
|
158
|
+
await currencyEngine.loadEngine(tools, walletInfo, opts)
|
|
159
|
+
|
|
160
|
+
// This is just to make sure otherData is Flow type checked
|
|
161
|
+
currencyEngine.otherData = currencyEngine.walletLocalData.otherData
|
|
162
|
+
if (!currencyEngine.otherData.numberTransactions) {
|
|
163
|
+
currencyEngine.otherData.numberTransaction = 0
|
|
164
|
+
}
|
|
165
|
+
const out = currencyEngine
|
|
166
|
+
return out
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
currencyInfo,
|
|
171
|
+
makeCurrencyEngine,
|
|
172
|
+
makeCurrencyTools
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { asNumber, asObject, asString } from 'cleaners'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const asXtzGetTransaction = asObject({
|
|
9
|
+
level: asNumber,
|
|
10
|
+
timestamp: asString,
|
|
11
|
+
hash: asString,
|
|
12
|
+
sender: asObject({
|
|
13
|
+
address: asString
|
|
14
|
+
}),
|
|
15
|
+
bakerFee: asNumber,
|
|
16
|
+
allocationFee: asNumber,
|
|
17
|
+
target: asObject({
|
|
18
|
+
address: asString
|
|
19
|
+
}),
|
|
20
|
+
amount: asNumber,
|
|
21
|
+
status: asString
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|