-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial working demo, basic elements styles, new go method to get lim…
…its of number of shares and threshold
- Loading branch information
1 parent
7cd17a8
commit 29828b6
Showing
4 changed files
with
176 additions
and
43 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
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,105 @@ | ||
import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.prod.js' | ||
|
||
const app = createApp({ | ||
data() { | ||
return { | ||
config: { | ||
minShares: 0, | ||
maxShares: 0, | ||
minMin: 0, | ||
maxMin: 0, | ||
}, | ||
message: "", | ||
sharesCount: 0, | ||
threshold: 0, | ||
shares: "", | ||
currentTab: "hide", | ||
hide_result: "", | ||
recovered_message: "", | ||
} | ||
}, | ||
async created() { | ||
await this.setupWebAssembly(); | ||
}, | ||
template: ` | ||
<div> | ||
<button class="button" @click="currentTab = 'hide'">Hide</button> | ||
<button class="button" @click="currentTab = 'recover'">Recover</button> | ||
<div v-show="currentTab === 'hide'"> | ||
<h3>Hide a message</h3> | ||
<textarea class="textarea" v-model="message" placeholder="Enter your message" rows="6"></textarea> | ||
<div v-show="message !== ''"> | ||
<label class="label">Shares <small>({{ config.minShares }} - {{ config.maxShares }})</small></label> | ||
<input v-model="sharesCount" type="number" class="input" :min="config.minShares" :max="config.maxShares" :step="config.minShares"> | ||
</div> | ||
<div v-show="message !== ''"> | ||
<label class="label">Threshold <small>({{ config.minMin }} - {{ sharesCount - 1 }})</small></label> | ||
<input v-model="threshold" type="number" class="input" :min="config.minMin" :max="sharesCount - 1"> | ||
</div> | ||
<button class="button is-secondary" :class="{'is-disabled': message == ''}" @click="hideMessage">Hide</button> | ||
<textarea class="textarea" readonly v-model="hide_result" placeholder="Resulting secret parts" rows="6"></textarea> | ||
</div> | ||
<div v-show="currentTab === 'recover'"> | ||
<h3>Recover a message</h3> | ||
<textarea class="textarea" v-model="shares" placeholder="Enter shares" rows="6"></textarea> | ||
<button class="button is-secondary" :class="{'is-disabled': message == ''}" @click="recoverMessage">Recover</button> | ||
<textarea class="textarea" readonly v-model="recovered_message" placeholder="Recovered message" rows="6"></textarea> | ||
</div> | ||
</div> | ||
`, | ||
methods: { | ||
async setupWebAssembly() { | ||
const go = new Go(); | ||
const result = await WebAssembly.instantiateStreaming(fetch("gosss.wasm"), go.importObject); | ||
go.run(result.instance); | ||
}, | ||
getConfig() { | ||
const rawResult = GoSSS.limits(this.message); | ||
const result = JSON.parse(rawResult); | ||
if (!result.error) { | ||
this.config = { | ||
minShares: result.data[0], | ||
maxShares: result.data[1], | ||
minMin: result.data[2], | ||
maxMin: result.data[3], | ||
} | ||
if (this.sharesCount < this.config.minShares) this.sharesCount = this.config.minShares; | ||
if (this.sharesCount > this.config.maxShares) this.sharesCount = this.config.maxShares; | ||
if (this.threshold < this.config.minMin) this.threshold = this.config.minMin; | ||
if (this.threshold > this.sharesCount - 1) this.threshold = this.sharesCount - 1; | ||
} else { | ||
alert(`Error getting configuration: ${result.error}`); | ||
} | ||
}, | ||
hideMessage() { | ||
const rawResult = GoSSS.hide(this.message, this.sharesCount, this.threshold); | ||
const result = JSON.parse(rawResult); | ||
if (!result.error) { | ||
this.hide_result = result.data.join("\n"); | ||
} else { | ||
alert(`Error hiding message: ${result.error}`); | ||
} | ||
}, | ||
recoverMessage() { | ||
const shares = JSON.stringify(this.shares.split("\n")); | ||
const rawResult = GoSSS.recover(shares); | ||
const result = JSON.parse(rawResult); | ||
if (!result.error) { | ||
this.recovered_message = window.atob(result.data); | ||
} else { | ||
alert(`Error recovering message: ${result.error}`); | ||
} | ||
} | ||
}, | ||
watch: { | ||
message() { | ||
this.getConfig(); | ||
} | ||
}, | ||
components: { | ||
|
||
} | ||
}); | ||
|
||
app.mount('#app'); |
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,30 +1,23 @@ | ||
<html> | ||
<head> | ||
<title>Go Shamir Secret Sharing demo</title> | ||
</head> | ||
<body> | ||
<script src="wasm_exec.js"></script> | ||
<script> | ||
function throwError(e) { | ||
console.error(e); | ||
} | ||
|
||
function hide(message, sharesCount, threshold) { | ||
let rawshares = GoSSS.hide(message, sharesCount, threshold); | ||
return JSON.parse(rawshares); | ||
} | ||
|
||
function recover(shares) { | ||
let message = GoSSS.recover(JSON.stringify(shares)); | ||
return message; | ||
} | ||
|
||
(async function() { | ||
const go = new Go(); | ||
const result = await WebAssembly.instantiateStreaming(fetch("gosss.wasm"), go.importObject); | ||
go.run(result.instance); | ||
})() | ||
</script> | ||
</body> | ||
</html> | ||
|
||
<!DOCTYPE html> | ||
<html data-theme="light"> | ||
<head> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<!-- Title and favicon (SVG emoji)--> | ||
<title>Shamir Secret Sharing Demo</title> | ||
<link rel="icon" | ||
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🔐</text></svg>"> | ||
<!-- Siimple.css assets --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/siimple/siimple.css" /> | ||
</head> | ||
<body> | ||
<!-- App slot --> | ||
<div id="app"></div> | ||
<!-- Import Go WebAssembly engine --> | ||
<script src="wasm_exec.js"></script> | ||
<!-- Import app --> | ||
<script type="module" src="app.js"></script> | ||
</body> | ||
</html> |