forked from klaytn/caver-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts.recover.js
57 lines (41 loc) · 2.28 KB
/
accounts.recover.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
54
55
56
57
/*
Copyright 2018 The caver-js Authors
This file is part of the caver-js library.
The caver-js library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The caver-js library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the caver-js. If not, see <http://www.gnu.org/licenses/>.
*/
const { expect } = require('./extendedChai')
const Caver = require('../index.js')
const testRPCURL = require('./testrpc')
describe('caver.klay.accounts.recover', () => {
it('CAVERJS-UNIT-WALLET-019 : should have same value for 3 different arguments definition', () => {
/**
* 3 different arguments definition for `caver.klay.accounts.recover`
* a. recover with signed object.
* b. recover with message, signature
* c. recover with message, v, r, s
*/
const caver = new Caver(testRPCURL)
const message = 'Some data'
const privateKey = '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
const signed = caver.klay.accounts.sign('Some data', privateKey)
const { signature, v, r, s } = signed
expect(caver.klay.accounts.recover(signed)).to.equal(caver.klay.accounts.recover(message, signature))
expect(caver.klay.accounts.recover(signed)).to.equal(caver.klay.accounts.recover(message, v, r, s))
})
it('CAVERJS-UNIT-WALLET-020 : messageHash argument can be used as a first argument with preFixed = true', () => {
const caver = new Caver(testRPCURL)
const privateKey = '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
const signed = caver.klay.accounts.sign('Some data', privateKey)
const { messageHash, signature } = signed
expect(caver.klay.accounts.recover(messageHash, signature, true)).to.equal(caver.klay.accounts.recover(signed))
})
})