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

GoodDollar / GoodServer / 18878690898

28 Oct 2025 02:46PM UTC coverage: 49.137% (-0.4%) from 49.515%
18878690898

push

github

gooddollar-techadmin
chore: release qa version 1.63.1-0 [skip build]

616 of 1530 branches covered (40.26%)

Branch coverage included in aggregate %.

1888 of 3566 relevant lines covered (52.94%)

7.28 hits per line

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

67.27
/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.
11✔
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()
11✔
14

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

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

27
export const recoverPublickey = (signature, msg, nonce = '') => {
11!
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) => {
11✔
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) => {
11✔
50
  // check v2, v2 identifier is expected to be the whole signature
51
  if (fvsig.length < 42) {
16✔
52
    return
11✔
53
  }
54

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

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

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

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

95
export const isFundsError = e => messageContains(e, 'funds')
11✔
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