Skip to content
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

Gateway requestor: support for sending digest #404

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

Maceeran
Copy link
Collaborator

Added support for selecting whether to send "message" or "digest" in gateway_requestor.html

Description

Checklist

Changes to the drivers

  • (PR Author) The affected drivers were manually tested

Changes to CLI

  • (PR Author) The change was manually tested with the CLI
  • (PR Author) The affected CLI features are working with the standalone binary (at least one platform)
  • (Checked by maintainer) The CLI test procedure was run by the project's maintainer

Changes to web library

  • (PR Author) The change was manually tested with the web library included within a classic HTML application (flat libhalo.js)
  • (PR Author) The change was manually tested with the web library included within an app based on frontend framework (React.js or similar based on webpack)
  • (Checked by maintainer) The web test suite was run by the project's maintainer

Changes to nfc-manager driver

  • (PR Author) The change was manually tested in React Native app
  • (Checked by maintainer) The test suite was run through the test React Native project

Copy link
Collaborator

@icedevml icedevml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +106 to +119
async function generateRandomDigest() {
const rnd = new Uint8Array(6);
crypto.getRandomValues(rnd);

const msgBuffer = new TextEncoder().encode(rnd);
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));

const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');

document.getElementById('digest').value = hashHex;
document.getElementById('signBtn').disabled = true;
document.getElementById('signBtn').style.display = 'none';
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, any random 32 byte hex string would be a valid SHA-256 hash. Of course then we wouldn't know what was the original input that was hashed, but it's also not necessary for this demo.

Nevertheless, I like the approach of generating a random message and then hashing it on the client side, it's a bit more descriptive. LGTM 👍

@icedevml icedevml merged commit 48df45f into master Sep 13, 2024
6 checks passed
@icedevml icedevml deleted the feature/gateway-requestor-raw-digest-support branch September 13, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

halo-demos: Make it possible to sign raw digest using gateway_requestor.html demo
2 participants