-
Notifications
You must be signed in to change notification settings - Fork 175
Add Quantum Randomness extension for Scratch #513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
698e685
3e7b949
f4c00e1
75e3cf3
75e0e86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| (function (Scratch) { | ||
| 'use strict'; | ||
|
|
||
| let apikey = ''; | ||
|
|
||
| class Extension { | ||
|
DashDevmationsDash marked this conversation as resolved.
|
||
| getInfo() { | ||
| return { | ||
| id: 'anuqrngisfreakingawesome', | ||
| name: 'Quantum Randomness', | ||
| color1: '#21ab61', | ||
| blocks: [ | ||
| { | ||
| opcode: 'how2getapikey', | ||
|
DashDevmationsDash marked this conversation as resolved.
|
||
| text: 'How To Get An Api Key', | ||
| blockType: Scratch.BlockType.BUTTON | ||
| }, | ||
| { | ||
| opcode: 'nrandomnumbers', | ||
| text: 'Get Random Number Inbetween [MIN] To [MAX]', | ||
| blockType: Scratch.BlockType.REPORTER, | ||
| arguments: { | ||
| MIN: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 1 | ||
| }, | ||
| MAX: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 10 | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| opcode: 'setapikey', | ||
| text: 'Set Api Key To [APIKEY]', | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| arguments: { | ||
| APIKEY: { | ||
| type: Scratch.ArgumentType.STRING, | ||
| defaultValue: 'Insert Api Key' | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
|
|
||
| how2getapikey() { | ||
| alert( | ||
| "How To Get An Api Key(100% Clickbait)(Cops Called)(At 3 Am)Works In 2026\n\n" + | ||
| "1. Go to https://quantumnumbers.anu.edu.au/\n\n" + | ||
| "2. Create an account or log in.\n\n" + | ||
| "3. Open your Dashboard or Account page.\n\n" + | ||
| "4. Locate your API Key section.\n\n" + | ||
| "5. Copy your Free API Key.\n\n" + | ||
| "6. Paste it into the 'Set Api Key' block.\n\n" + | ||
| "Pro Tip: Try Encoding Your Api Key Cuz In A Site Where Seeing The Code Of Projects Is As Easy As A Click Of A Button... You Will Need It" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security through obscurity is not real security, it's like hiding spare keys under a rock in your yard. Sure, nobody will know it's there unless you tell them, or they scope it out, but if they know it's there, then it's pretty easy to break into your house.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not even that. its REALLY easy to find the api key. you can just look at the network tab in inspect element.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont Worry, Its Now Serialization Based, Should Fix It
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the api key is still really easy to access from the project file itself, the webtools console (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That has nothing to do with this one. That was one of my issues, and it was not all of them. When someone makes a review of a PR it isn't because every single thing they say relates to something overarching and you only need to read the first thing they said. |
||
| ); | ||
| } | ||
|
|
||
|
|
||
| async nrandomnumbers(args) { | ||
| let min = Number(args.MIN); | ||
| let max = Number(args.MAX); | ||
| if (min > max) [min, max] = [max, min]; | ||
| if (min === max) return min; | ||
| try { | ||
| const controller = new AbortController(); | ||
| const timeout = setTimeout(() => controller.abort(), 3000); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd specify a message to say that this abortion was because it got timed out.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice Idea Ngl |
||
|
|
||
| const response = await fetch( | ||
| 'https://api.quantumnumbers.anu.edu.au?length=1&type=uint8', | ||
| { | ||
| headers: { | ||
| 'x-api-key': apikey | ||
| }, | ||
| signal: controller.signal | ||
| } | ||
| ); | ||
| clearTimeout(timeout); | ||
| const json = await response.json(); | ||
| const quantumValue = json.data[0] / 256; | ||
|
DashDevmationsDash marked this conversation as resolved.
Outdated
|
||
|
|
||
| return Math.floor(min + quantumValue * (max - min + 1)); | ||
|
|
||
| } catch (error) { | ||
| console.warn("Quantum API failed, using Math.random()", error); | ||
| return Math.floor(min + Math.random() * (max - min + 1)); | ||
| } | ||
|
DashDevmationsDash marked this conversation as resolved.
|
||
| } | ||
|
|
||
| setapikey(args) { | ||
| apikey = args.APIKEY; | ||
| } | ||
| } | ||
|
|
||
| Scratch.extensions.register(new Extension()); | ||
| })(Scratch); | ||


Uh oh!
There was an error while loading. Please reload this page.