-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSignatureUtils.test.ts
43 lines (36 loc) · 1.34 KB
/
SignatureUtils.test.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
import { assert } from 'chai'
import { Nevermined } from '../../src/nevermined/Nevermined'
import { NvmAccount } from '../../src/models/NvmAccount'
import config from '../../test/config'
import { SignatureUtils } from '../../src/nevermined/utils/SignatureUtils'
describe('SignatureUtils', () => {
const text = '0123456789abcde'
const signature =
'0xb76f14f0a1664d14a667a7647baee471f76796cff97a6e78f2884bed352dea2c11b89286811ccd5640bfdc8a567a7151e4450ad6bf889ed37d971a4f39ea79cb1b'
let nevermined: Nevermined
let account: NvmAccount
before(async () => {
nevermined = await Nevermined.getInstance(config)
;[account] = nevermined.accounts.list()
})
describe('#signText', () => {
it('should sign a text as expected', async () => {
const signed = await nevermined.utils.signature.signText(text, account)
assert.equal(signed, signature)
})
it('verify is signer', async () => {
const isSigner = await nevermined.utils.signature.verifyIsSigner(
text,
signature,
account.getId(),
)
assert.isTrue(isSigner)
})
})
describe('#verifyText', () => {
it('should recover the privateKey of a signed message', async () => {
const signerAddress = await SignatureUtils.recoverSignerAddress(text, signature)
assert.equal(account.getId(), signerAddress)
})
})
})