• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GoodDollar / GoodServer / 12903998428

14 Jan 2025 12:39PM UTC coverage: 49.574% (+0.2%) from 49.344%
12903998428

push

github

sirpy
fix: remove unused

579 of 1453 branches covered (39.85%)

Branch coverage included in aggregate %.

1863 of 3473 relevant lines covered (53.64%)

8.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.59
/src/server/utils/eth.js
1
import Accounts from 'web3-eth-accounts'
2
import * as ethers from 'ethers'
3
import { toChecksumAddress } from 'web3-utils'
4
import { verifyMessage } from '@ambire/signature-validator'
5
import { messageContains } from './exception'
6
import { mustache } from '../utils/string'
7

8
export const FV_IDENTIFIER_MSG2 =
9
  mustache(`Sign this message to request verifying your account {account} and to create your own secret unique identifier for your anonymized record.
10✔
10
You can use this identifier in the future to delete this anonymized record.
11
WARNING: do not sign this message unless you trust the website/application requesting this signature.`)
12

13
const accounts = new Accounts()
10✔
14

15
const is6492Sig = signature => {
10✔
16
  return signature.endsWith('6492649264926492649264926492649264926492649264926492649264926492')
22✔
17
}
18

19
export const extractSignature = signature => {
10✔
20
  if (is6492Sig(signature)) {
22✔
21
    const [, , erc1271Signature] = ethers.utils.defaultAbiCoder.decode(['address', 'bytes', 'bytes'], signature)
1✔
22
    return erc1271Signature
1✔
23
  }
24
  return signature
21✔
25
}
26

27
export const recoverPublickey = (signature, msg, nonce = '') => {
10!
28
  const publicKey = accounts.recover(String(msg) + String(nonce), signature).toLowerCase()
7✔
29

30
  return publicKey
7✔
31
}
32

33
export const verifySignature = async (message, signature) => {
10✔
34
  try {
×
35
    // recoverPublickey() also could throw so we're wrapping its call to try block
36
    const recovered = recoverPublickey(signature, message, '')
×
37

38
    if (recovered.substr(2) !== message.toLowerCase()) {
×
39
      throw new Error("Public key doesn't matches")
×
40
    }
41

42
    return recovered
×
43
  } catch (exception) {
44
    exception.message = `SigUtil unable to recover the message signer`
×
45
    throw exception
×
46
  }
47
}
48

49
export const verifyIdentifier = async (fvsig, gdAddress, chainId = 42220) => {
10✔
50
  // check v2, v2 identifier is expected to be the whole signature
51
  if (fvsig.length < 42) {
20✔
52
    return
13✔
53
  }
54

55
  const fuseProvider = new ethers.providers.JsonRpcProvider('https://rpc.fuse.io')
7✔
56
  const celoProvider = new ethers.providers.JsonRpcProvider('https://forno.celo.org')
7✔
57
  const xdcProvider = new ethers.providers.JsonRpcProvider('https://rpc.xdc.network')
7✔
58

7!
59
  let provider = celoProvider
60
  switch (String(chainId)) {
7✔
61
    case '42220':
7✔
62
      provider = celoProvider
63
      break
×
64
    case '122':
×
65
      provider = fuseProvider
66
      break
×
67
    case '50':
68
      provider = xdcProvider
69
      break
7✔
70
    default:
71
      break
72
    // log.warn('verifyIdentifier unsupported chainId defaulting to Celo', chainId)
73
  }
74
  const verifyResult = await verifyMessage({
75
    provider,
76
    signer: toChecksumAddress(gdAddress),
7✔
77
    signature: fvsig,
78
    message: FV_IDENTIFIER_MSG2({ account: toChecksumAddress(gdAddress) })
2✔
79
  })
80

5✔
81
  if (!verifyResult) {
82
    // returns 0 if equals
83
    throw new Error(`FV identifier signature verification faild`)
84
  }
85
  return verifyResult
86
}
87

88
/**
10✔
89
 * Return boolean
90
 * @param e Error
10✔
91
 * @returns boolean
92
 */
93
export const isNonceError = e => messageContains(e, 'nonce')
94

95
export const isFundsError = e => messageContains(e, 'funds')
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc