-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
58 lines (52 loc) · 1.62 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
import wallets from './src/wallets'
import contracts from './src/contracts'
import transactions from './src/transactions'
import endpoints from './src/config/endpoints'
import networks from './src/config/networks'
import typedData from './src/typed_data'
import okenSigner, { SignerOptions } from './src/components/okenSigner'
import API from './src/components/api'
import errors from './src/components/errorHandler'
export type Config = {
endpoint: string,
network: string,
okenClientId: string,
privateKey: string,
signer?: any
alchemyKey?: string
signerOptions?: SignerOptions
}
export default {
/**
* @dev Connect to the Oken API
* @param config
* @returns oken instance
*/
connect: ({ endpoint, network, okenClientId, privateKey, signer = okenSigner, signerOptions, alchemyKey }: Config) => {
if (!endpoint) throw Error('Missing endpoint')
if (!network) throw Error('Missing network')
if (!okenClientId) throw Error('Missing okenClientId')
if (!privateKey) throw Error('Missing privateKey')
let alchemyConfig
if (alchemyKey) alchemyConfig = { alchemyKey, network }
const api = API(endpoint, signer(okenClientId, privateKey, signerOptions), alchemyConfig)
return {
wallets: wallets(api, network),
contracts: contracts(api, network),
transactions: transactions(api),
errors: errors
}
},
/**
* @dev List of available networks
*/
networks,
/**
* @dev List of available environments
*/
endpoints,
/**
* @dev Collection of some typed data structures. You can use your own typed data structures when signing v4 messages
*/
typedData
}