Skip to content

Commit

Permalink
feat: 🎸 new method getSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
hzz780 committed Oct 25, 2019
1 parent 0a51e68 commit a244fbf
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 51 deletions.
Binary file added app/public.zip
Binary file not shown.
44 changes: 44 additions & 0 deletions app/web/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ export default class Background {
case InternalMessageTypes.GET_ADDRESS:
Background.getAddress(sendResponse);
break;
case InternalMessageTypes.GET_SIGNATURE:
Background.getSignature(sendResponse, message.payload);
break;

case InternalMessageTypes.OPEN_PROMPT:
Background.openPrompt(sendResponse, message.payload);
Expand Down Expand Up @@ -1399,6 +1402,47 @@ export default class Background {
});
}

// TODO: need a prompt page. neet week.
static getSignature(sendResponse, options) {
this.checkSeed({
sendResponse
}, ({
nightElfObject
}) => {
console.log('getSignature: ', nightElfObject, options);
const {
keychain: {
keypairs = []
}
} = nightElfObject;

const {
address,
hexToBeSign
} = options;

const keypair = keypairs.find(item => {
return item.address === address
});

let signedMsgString;
if (keypair) {
const keypairAndUtils = AElf.wallet.ellipticEc.keyFromPrivate(keypair.privateKey);
const signedMsgObject = keypairAndUtils.sign(hexToBeSign);
signedMsgString = [
signedMsgObject.r.toString(16, 64),
signedMsgObject.s.toString(16, 64),
`0${signedMsgObject.recoveryParam.toString()}`
].join('');
}

sendResponse({
...errorHandler(0),
signature: signedMsgString
});
});
}

/**
* some action like SET_PERMISSION need through prompt page.
* TODO: According to the input data,
Expand Down
2 changes: 1 addition & 1 deletion app/web/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Content {
'CHECK_PERMISSION', 'LOGIN',
'REMOVE_CONTRACT_PERMISSION', 'REMOVE_METHODS_WHITELIST',
'SET_CONTRACT_PERMISSION', 'GET_CHAIN_STATUS',
'CALL_AELF_CONTRACT_READONLY'
'CALL_AELF_CONTRACT_READONLY', 'GET_SIGNATURE'
];

if (method === 'OPEN_PROMPT') {
Expand Down
11 changes: 11 additions & 0 deletions app/web/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ class NightAElf {
});
}

getSignature(param, callback) {
return window.NightElf.api({
appName: param.appName,
address: param.address,
hexToBeSign: param.hexToBeSign,
method: 'GET_SIGNATURE'
}).then(result => {
return this.callbackWrap(result, callback);
});
}

chain() {
const getChainStatus = callback => {
return window.NightElf.api({
Expand Down
88 changes: 40 additions & 48 deletions app/web/manifest.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,42 @@
{
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"name": "aelf-explorer-extension-dev",
"version": "1.0.5",
"description": "__MSG_pluginDesc__",
"icons":
{
"16": "assets/images/aelf_logo.png",
"48": "assets/images/aelf_logo.png",
"128": "assets/images/aelf_logo.png"
},
"background":
{
"page": "background.html"
},
"browser_action":
{
"default_icon": "assets/images/aelf_logo.png",
"default_title": "aelf-explorer-extension",
"default_popup": "popup.html"
},
"content_scripts":
[
{
"matches": ["<all_urls>"],
"js": ["js/content.js"],
"run_at": "document_end"
}
],
"permissions":
[
"contextMenus",
"tabs",
"notifications",
"webRequest",
"webRequestBlocking",
"storage",
"http://*/*",
"https://*/*"
],
"web_accessible_resources": ["js/inject.js"],
"options_page": "options.html",
"options_ui":
{
"page": "options.html",
"chrome_style": true
},
"default_locale": "zh_CN"
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"name": "aelf-explorer-extension-dev",
"version": "1.0.9",
"description": "__MSG_pluginDesc__",
"icons": {
"16": "assets/images/aelf_logo.png",
"48": "assets/images/aelf_logo.png",
"128": "assets/images/aelf_logo.png"
},
"background": {
"page": "background.html"
},
"browser_action": {
"default_icon": "assets/images/aelf_logo.png",
"default_title": "aelf-explorer-extension",
"default_popup": "popup.html"
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["js/content.js"],
"run_at": "document_end"
}],
"permissions": [
"contextMenus",
"tabs",
"notifications",
"webRequest",
"webRequestBlocking",
"storage",
"http://*/*",
"https://*/*"
],
"web_accessible_resources": ["js/inject.js"],
"options_page": "options.html",
"options_ui": {
"page": "options.html",
"chrome_style": true
},
"default_locale": "zh_CN"
}
1 change: 1 addition & 0 deletions app/web/messages/InternalMessageTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const RELEASE_AELF_CONTRACT = 'releaseAelfContract'; // TODO:


export const GET_ADDRESS = 'getAddress';
export const GET_SIGNATURE = 'getSignature';

export const OPEN_PROMPT = 'openPrompt';
// export const SET_PROMPT = 'setPrompt';
Expand Down
2 changes: 2 additions & 0 deletions devDemos/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ <h1>Hello Test.html</h1>
<button type="button" id="error-get-tx-result">error: get-tx-result ['']</button>
<br>

<button type="button" id="get-signature">get-signature</button>

<!-- <div class="sub-title">init & call different contract</div> -->
<!-- <button type="button" id="bind-permission-01">permission</button> -->
<br>
Expand Down
13 changes: 11 additions & 2 deletions devDemos/testNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// century renew blade meadow faith evil uniform work discover poet ripple drill

const tokenContractAddress = 'WnV9Gv3gioSh3Vgaw8SSB96nV8fWUNxuVozCf6Y14e7RXyGaM';
const tokenContractAddress = '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB';
const testAddress = 'AZsECHAzWgWpCoywTdv8mU8s75yicmkmhrJFWc5p6uJ19sb9m';

document.addEventListener('NightElf', result => {
Expand All @@ -27,7 +27,7 @@ document.addEventListener('NightElf', result => {
// httpProvider: 'http://192.168.199.210:5000/chain',
httpProvider: [
// 'http://192.168.197.56:8101/chain',
'http://34.213.112.35:8000' //,
'http://13.231.179.27:8000' //,
// null,
// null,
// null,
Expand Down Expand Up @@ -275,6 +275,15 @@ document.addEventListener('NightElf', result => {
aelf.chain.getTxResult('');
};

const getSignature = document.getElementById('get-signature');
getSignature.onclick = function () {
aelf.getSignature({
appName: 'hzzTest',
address: '2XCnbwrtYGP3KxjcXnXRmLRh9NN1Y1YaUHAtP7jAxNYzYzfh8p',
hexToBeSign: '2333'
});
};

// For test
// const permissionIndex = [0];
// const permissionsTemp = [{
Expand Down

0 comments on commit a244fbf

Please sign in to comment.