forked from liusong1111/keypering
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from nervosnetwork/rc/v0.1.0-alpha.3
- Loading branch information
Showing
29 changed files
with
529 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "chrome", | ||
"request": "launch", | ||
"name": "Launch Chrome against localhost", | ||
"url": "http://localhost:3000", | ||
"webRoot": "${workspaceRoot}/packages/ui/src" | ||
}, | ||
{ | ||
"name": "keypering", | ||
"type": "node", | ||
"request": "launch", | ||
"cwd": "${workspaceRoot}/packages/app", | ||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", | ||
"windows": { | ||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd" | ||
}, | ||
"args": ["."], | ||
"outputCapture": "std", | ||
"env": { | ||
"NODE_ENV": "development" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
], | ||
"npmClient": "yarn", | ||
"useWorkspaces": true, | ||
"version": "0.1.0-alpha.2" | ||
"version": "0.1.0-alpha.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { signMsg } from '../../src/keyper/sign' | ||
|
||
describe("Test signMsg", () => { | ||
const info = { | ||
sk: '0xe79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3', | ||
message: 'HelloWorld', | ||
signture: '0x97ed8c48879eed50743532bf7cc53e641c501509d2be19d06e6496dd944a21b4509136f18c8e139cc4002822b2deb5cbaff8e44b8782769af3113ff7fb8bd92700' | ||
} | ||
|
||
it('signMsg', () => { | ||
expect(signMsg(info.sk, info.message)) | ||
.toEqual(info.signture) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@keypering/app", | ||
"version": "0.1.0-alpha.2", | ||
"version": "0.1.0-alpha.3", | ||
"description": "", | ||
"author": "Keith <[email protected]>", | ||
"homepage": "https://nervosnetwork.github.io/keypering", | ||
|
@@ -32,7 +32,7 @@ | |
"url": "https://github.com/nervosnetwork/keypering/issues" | ||
}, | ||
"devDependencies": { | ||
"@keypering/specs": "0.1.0-alpha.2", | ||
"@keypering/specs": "0.1.0-alpha.3", | ||
"@types/elliptic": "6.4.12", | ||
"@types/uuid": "8.0.1", | ||
"electron": "9.2.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Signing</title> | ||
<style> | ||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
--primary-green: #3cc68a; | ||
margin: 0; | ||
padding: 20px; | ||
font-size: 14px; | ||
letter-spacing: 0.23px; | ||
user-select: none; | ||
line-height: 1.2; | ||
font-weight: 400; | ||
background: #fff; | ||
} | ||
|
||
#message, #address { | ||
color: var(--primary-green); | ||
} | ||
|
||
h1 { | ||
font-size: 16px; | ||
letter-spacing: 0.2px; | ||
color: #000; | ||
margin-bottom: 20px; | ||
} | ||
|
||
form div { | ||
margin-bottom: 14px; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
.footer { | ||
display: flex; | ||
justify-content: flex-end; | ||
margin-top: 20px; | ||
} | ||
|
||
button { | ||
width: 80px; | ||
height: 30px; | ||
border-radius: 2px; | ||
outline: none; | ||
border: none; | ||
text-transform: capitalize; | ||
margin-left: 10px; | ||
} | ||
|
||
button:hover { | ||
filter: brightness(0.9); | ||
} | ||
|
||
button[type=submit] { | ||
background-color: var(--primary-green); | ||
color: #fff; | ||
} | ||
|
||
button:disabled { | ||
filter: grayscale(0) !important; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<form> | ||
<h1>Message Confirmation</h1> | ||
<div>Message: <span id="message">...</span></div> | ||
<div>Address: <span id="address">...</span></div> | ||
<div class="footer"> | ||
<button type="button">decline</button> | ||
<button type="submit">approve</button> | ||
</div> | ||
</form> | ||
<script> | ||
const search = new URLSearchParams(location.search) | ||
const address = search.get('address') | ||
if (!address) { | ||
window.alert('Invalid request') | ||
window.close() | ||
} | ||
|
||
const channel = `signMsg:${address}` | ||
|
||
const messageElement = document.querySelector("#message") | ||
const addressElement = document.querySelector('#address') | ||
const form = document.querySelector('form') | ||
const submitBtn = document.querySelector('button[type=submit]') | ||
const declineBtn = document.querySelector('button[type=button]') | ||
|
||
const handleCancel = () => { | ||
ipcRenderer?.send(channel, false) | ||
window.close() | ||
} | ||
|
||
const handleSubmit = () => { | ||
ipcRenderer?.send(channel, true) | ||
submitBtn?.setAttribute('disabled', true) | ||
declineBtn?.setAttribute('disabled', true) | ||
} | ||
|
||
declineBtn?.addEventListener('click', handleCancel) | ||
submitBtn?.focus() | ||
|
||
form.addEventListener('submit', (e) => { | ||
e.preventDefault() | ||
handleSubmit() | ||
}) | ||
|
||
window.addEventListener('keyup', (e) => { | ||
if (e.key === 'Escape') { | ||
handleCancel() | ||
} | ||
}) | ||
|
||
ipcRenderer?.once(channel, (_e, params) => { | ||
try { | ||
const { message, address } = params | ||
messageElement.innerText = message | ||
addressElement.innerText = address | ||
} catch (err) { | ||
window.alert(err.message) | ||
window.close() | ||
} | ||
}) | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { blake2b, PERSONAL, hexToBytes } from '@nervosnetwork/ckb-sdk-utils' | ||
|
||
export default class Blake2b { | ||
private blake2b: any | ||
|
||
constructor() { | ||
this.blake2b = blake2b(32, null, null, PERSONAL) | ||
} | ||
|
||
public update = (message: string): void => { | ||
const msg = message.startsWith('0x') ? | ||
message : | ||
`0x${message}` | ||
this.blake2b.update(hexToBytes(msg)) | ||
} | ||
|
||
public updateBuffer = (message: Buffer): void => { | ||
this.blake2b.update(message) | ||
} | ||
|
||
public digest = (): string => { | ||
return `0x${this.blake2b.digest('hex')}` | ||
} | ||
|
||
public static digest = (message: string): string => { | ||
const blake2bHash = new Blake2b() | ||
blake2bHash.update(message) | ||
return blake2bHash.digest() | ||
} | ||
} |
Oops, something went wrong.