add bcservice

This commit is contained in:
aozhiwei 2024-07-13 11:27:26 +08:00
parent ff8e9b50a2
commit d1a0b619cf
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,47 @@
const ethUtil = require('ethereumjs-util');
const sigUtil = require('@metamask/eth-sig-util');
const app = require('j7/app');
async function authVerifySignature(session) {
try {
const msgParams = {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
],
set: [
{ name: 'tips', type: 'string' },
{ name: 'nonce', type: 'string' },
]
},
primaryType: 'set',
domain: {
name: 'Auth',
version: '1',
},
message: {
tips: session.request('tips'),
nonce: session.request('nonce')
}
};
const recovered = sigUtil.recoverTypedSignature(
{data:
msgParams,
signature: session.request('signature'),
version: 'V4'});
session.rspData(
{
'recovered': recovered
});
} catch (err) {
session.rspErr(1, err);
}
}
function init() {
app.registerHandler('BcService', 'authVerifySignature', authVerifySignature);
}
exports.init = init;

View File

@ -8,6 +8,7 @@ function add(name) {
async function init() {
add('jwt');
add('metamask_jwt');
add('bcservice');
}
exports.init = init;