Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit f9fbcd4

Browse files
ericjutaJoel Torstensson
authored andcommitted
fix(utils): properly format ethrpc calls
* Add id and jsonrpc sendAsync keys for compatibility with Fortmatic for e.g. BOOM offchain profiles with personal_sign and no metamask! * Fix spacing! * Change id to 0 and prettify
1 parent 3fd3944 commit f9fbcd4

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

src/utils/index.js

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fetch = (typeof window !== 'undefined') ? window.fetch : require('node-fetch')
1+
const fetch = typeof window !== 'undefined' ? window.fetch : require('node-fetch')
22
const Multihash = require('multihashes')
33
const sha256 = require('js-sha256').sha256
44

@@ -9,15 +9,20 @@ module.exports = {
99
var params = [msg, fromAddress]
1010
var method = 'personal_sign'
1111
return new Promise((resolve, reject) => {
12-
ethereum.sendAsync({
13-
method,
14-
params,
15-
fromAddress
16-
}, function (err, result) {
17-
if (err) reject(err)
18-
if (result.error) reject(result.error)
19-
resolve(result.result)
20-
})
12+
ethereum.sendAsync(
13+
{
14+
jsonrpc: '2.0',
15+
id: 0,
16+
method,
17+
params,
18+
fromAddress
19+
},
20+
function(err, result) {
21+
if (err) reject(err)
22+
if (result.error) reject(result.error)
23+
resolve(result.result)
24+
}
25+
)
2126
})
2227
},
2328

@@ -27,40 +32,47 @@ module.exports = {
2732
var params = [msg, fromAddress]
2833
var method = 'personal_sign'
2934
return new Promise((resolve, reject) => {
30-
ethereum.sendAsync({
31-
method,
32-
params,
33-
fromAddress
34-
}, function (err, result) {
35-
if (err) reject(err)
36-
if (result.error) reject(result.error)
37-
resolve(result.result)
38-
})
35+
ethereum.sendAsync(
36+
{
37+
jsonrpc: '2.0',
38+
id: 0,
39+
method,
40+
params,
41+
fromAddress
42+
},
43+
function(err, result) {
44+
if (err) reject(err)
45+
if (result.error) reject(result.error)
46+
resolve(result.result)
47+
}
48+
)
3949
})
4050
},
4151

4252
getLinkConsent: (fromAddress, toDID, ethereum) => {
43-
const text = 'Create a new 3Box profile' +
44-
'\n\n' +
45-
'- \n' +
46-
'Your unique profile ID is ' + toDID
53+
const text = 'Create a new 3Box profile' + '\n\n' + '- \n' + 'Your unique profile ID is ' + toDID
4754
var msg = '0x' + Buffer.from(text, 'utf8').toString('hex')
4855
var params = [msg, fromAddress]
4956
var method = 'personal_sign'
5057
return new Promise((resolve, reject) => {
51-
ethereum.sendAsync({
52-
method,
53-
params,
54-
fromAddress
55-
}, function (err, result) {
56-
if (err) reject(err)
57-
if (result.error) reject(result.error)
58-
const out = {
59-
msg: text,
60-
sig: result.result
58+
ethereum.sendAsync(
59+
{
60+
jsonrpc: '2.0',
61+
id: 0,
62+
method,
63+
params,
64+
fromAddress
65+
},
66+
function(err, result) {
67+
if (err) reject(err)
68+
if (result.error) reject(result.error)
69+
const out = {
70+
msg: text,
71+
sig: result.result
72+
}
73+
resolve(out)
6174
}
62-
resolve(out)
63-
})
75+
)
6476
})
6577
},
6678

0 commit comments

Comments
 (0)