-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
53 lines (43 loc) · 1.67 KB
/
index.js
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
const _ = require('lodash')
const Account = require('./src/Account')
const AccountSigner = require('./src/AccountSigner')
const getChainId = require('./src/getChainId')
const ParseSignedMessage = require('./src/parseSignedMessage')
const setupBrink = (opts = {}) => {
const account = (ownerAddress, accountOpts = {}) => {
const { provider, signer, verifiers } = accountOpts
const prov = provider || opts.provider
if (!prov) throw new Error(`no provider specified`)
const accountTxSigner = signer || opts.signer || prov.getSigner()
if (!accountTxSigner) throw new Error(`no signer specified`)
const vers = verifiers || opts.verifiers
return new Account({
ownerAddress,
provider: prov,
signer: accountTxSigner,
verifiers: vers
})
}
const accountSigner = (accountOwnerSigner, signerOpts = {}) => {
if (!accountOwnerSigner) throw new Error(`no accountOwnerSigner specified`)
let network = signerOpts.network || opts.network
if (!network) { network = 'mainnet' }
const vers = signerOpts.verifiers || opts.verifiers
return new AccountSigner({
signer: accountOwnerSigner,
chainId: getChainId(network),
verifiers: vers
})
}
return {
Account: account,
AccountSigner: accountSigner,
proxyAccountFromOwner: require('./src/proxyAccountFromOwner'),
recoverSigner: require('./src/recoverSigner'),
verifySignedMessage: require('./src/verifySignedMessage'),
parseSignedMessage: ParseSignedMessage({ verifiers: opts.verifiers }),
encodeFunctionCall: require('./src/encodeFunctionCall'),
verifyParamInput: require('./src/utils/verifyParamInput')
}
}
module.exports = setupBrink