Code Monkey home page Code Monkey logo

keyguard's Introduction

Nimiq Keyguard

This README is about setting up your own instances of Nimiq Keyguard.

For information about using the client please refer to the Keyguard Client README.

Development

Install the dev dependencies:

yarn

Then you can:

  • serve the Keyguard locally with yarn serve (starts on port 8000).
  • run the build script with yarn build [config].
  • run the tests with yarn test.
  • run the typechecker with yarn typecheck.
  • run the typecheck file watcher with yarn watch.
  • run the linter with yarn lint.
  • automatically fix basic things like spacing, commas, indentation and quotes with yarn lintfix.
  • run yarn pr to run all three checks (typecheck, lint, test) as they would for a PR.

Note that it is mostly not necessary to run the build script for development purposes, as the code in src is fully functional and you can use it as an endpoint. Only regenerating the translation dictionary needs to be triggered manually by restarting yarn serve or by running yarn i18n:build-dictionary. For convenient testing of the Keyguard there are demos provided under /demos.

Coding Style

  • Code style is enforced with ESLint. Run yarn lint to see errors.
  • Folder names are in Kebab Case: sign-transaction.
  • Class files are named in Pascal Case: PinInput.js, RpcServer.js.
  • JSDoc @type and @param annotations must have a hyphen between the argument name and description:
/**
 * @param {string} address - The address to search for
 */
  • Folder structure:
- src
    - assets
    - components
    - config
    - lib
    - request
    - translations
- types
- tests
- tools
- demos
- client
    - src
    - types

Configuration

You can configure the following values by configuration files located in folder src/config:

  • ALLOWED_ORIGIN: The origin from which requests are accepted. '*' allows all origins.
  • NETWORK: The network to connect with. Use Constants.NETWORK constants.
  • ROOT_REDIRECT: The page where the user is redirected to when accidentally going to root URL.

The config file used for unbuilt code is config.local.js. The build script uses config.testnet.js by default. To use a different file (especially useful for deployment), pass its name as an argument to the build script. yarn build mainnet uses config.mainnet.js.

I18n usage

Setup

First, import the I18n.js lib in your HTML's head section. Then, setup your dictionary (details see below) and initialize I18n passing your dictionary and the fallback language that should be used if no translation in the current language has been found.

var myDictionary = {
    'en': {
        ...
    }
};

I18n.initialize(myDictionary, 'en');

The Keyguard uses an app wide dictionary auto-generated from separate language files, see section Contribute to translations.

I18n will by default use the language specified in a lang cookie if present or otherwise fallback to the browser's language or English.

Translate tag content

<div data-i18n="my-translation">My content</div>

When the I18n gets started, or when the language has been switched, it will look for tags with the data-i18n attribute and put in the appropriate translation. My content will be replaced.

Translate placeholders and value

<input data-i18n-placeholder="my-placeholder-translation"/>
<input data-i18n-value="my-value-translation"/>

Similarily, I18n will translate the texts for value and placeholder.

Language picker

Add LanguagePicker.js to your head and then add a language picker widget to your page:

    const languagePicker = new LanguagePicker();
    document.body.appendChild(languagePicker.getElement());

Contribute to translations

First of all, a big thank you to all translators!

The Nimiq Keyguard is fully internationalized and ready for the community to add translations in different languages.

To help translate the Keyguard, the procedure is as follows:

  • Clone this repository.

  • The translations are located in the src/translations folder. A translation file for a language is named as the language's two letter ISO 639-1 code plus file extension .json. For example, for French with two letter code fr the translations are located at src/translations/fr.json. If that file doesn't exist yet, i.e. you're starting a new translation, please duplicate en.json as starting point and rename it accordingly.

  • The translation files are in a key-value json format. For Example:

    "my-translation": "Content in English",
    "timer-expiry": "This offer expires in",

    Where the key is the unique identifier of the string to translate. You can find the source string to translate in the en.json file. Please only edit the translations, not the source strings nor the keys.

  • During the build step, a language dictionary is auto-generated from the separate translation files at src/translation/index.js. Please do not edit this file but only the separate translation files.

  • You can test your translations locally by setting up a local development server as described in section development and then setting the language cookie in the served page. To do so, open your browser's developer console (ctrl + shift + c) and input document.cookie = 'lang=<lang>' where <lang> should be replaced by the two letter language code of the language you want to test, for example document.cookie = 'lang=fr'. If you struggle setting up the local demo you can ask us to setup an online demo for you after opening a pull request.

  • Once the file has been fully translated or you are done updating an existing translation file, you can open a pull request here in github.

  • The pull request will then be reviewed and, if all goes well, merged into the master branch and published asap.

Additional information

keyguard's People

Contributors

bettelstab avatar cb5890 avatar danimoh avatar dependabot[bot] avatar fiaxh avatar mar-v-in avatar mariofriz avatar matthewdludwig avatar mraveux avatar neokrept avatar nibhar avatar paberr avatar sisou avatar styppo avatar svub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

keyguard's Issues

[Request] Import words

Adapt the import-words flow into the new design, keeping space for the import-file flow as well.

Merchants should be able to set the tx validity length

Exchanges mostly only guarantee an exchange rate for a certain amount of time. Thus a merchant should be able to set for how many blocks (~minutes) a transaction should be valid.

We would then use this to offset the validityStartHeight of the transaction.

Merchants should be able to specify an image for their identicon

The Keyguard should accept an optional logoUrl (or similar) parameter in the sign-transaction request for checkouts, to be displayed in place of the merchant identicon.

The image must be loaded from the same origin as the request comes from.

According to @styppo, there is no security risk in letting the browser load any file in an image tag. The browser image rendering and content detection engine can be trusted to not execute malicious payload.

Test key migration code

The Keyguard needs to correctly migrate between legacy key store and new key store, when instructed by the Accounts Manager.

On iOS, this means detecting the migration cookie and migrating on next top-level request.

KeyguardClient Singleton

Explore whether it makes sense to offer a KeyguardClient.Instance getter as a KeyguardCient default / singleton instance.

Derive and store addresses optimistically

To prevent the user from having to be prompted for his/her password every time a new account should be derived, the Keyguard can derive and store derived paths and their addresses optimistically during wallet creation and import.

Implement cookie monster

Implement a cookie monster that eats cookies ๐Ÿช
I.e.: a service worker that intercepts requests to the server and strips cookies.

introduce config

Following things should be configurable or depend on own origin:

  • accepted origin (accounts.nimiq.com / accounts.nimiq-testnet.com / accounts.localhost/apps/...)
  • used CDN

Payment info-line above page during checkout

As shown in the mockups in Zeplin, a so-called payment info-line should be displayed above the page for the duration of the checkout flow. This is currently only shown in the AccountManager, but no yet in the Keyguard.

[Request] Logout

Adapt logout (remove-key) request to the new design, keeping space to integrate export-words/export-file sub-requests later.

Make all requests reloadable

Requests which render their DOM themselves (instead of having it predefined in HTML) cannot be reloaded properly. The hash-targeted element is created after the browser tries to focus it.

Requests with that problem: export, ...?

What should happen on keyguard reload?

Should the window get closed?
That would probably be the easiest as the keyguard looses the state it had before reload, e.g. for create the chosen identicon (private key) + passphrase and that is stuff that we don't want to persist in localstorage

Keyguard must not overwrite existing keyId in storage

When storing a new key, the Keyguard must check that the keyId is not already in use. If in use, the keyId needs to be altered so that it does not overwrite an existing key anymore.

This will also likely have to be the case when importing an existing key (which would usually overwrite it). Because the Keyguard only has access to the encrypted key (usually) and it cannot be sure that the password used was the same, the Keyguard has no way of knowing if an imported key with the same keyId is in fact the same key as already exists (if the existing encrypted entropy is bit-equal with the new encrypted entropy - meaning the user has used the same password again - then it would be safe to overwrite the existing key entry).

De-merge of soeren/merged

Enable back-buttons in create flow

The page-header back-buttons in the create flow should be made functional, including the first back-button, which should take the user back to the AccountManager's wallet-type selection page.

Passphrase box as component

Including animations and element fade-in/-outs as designed.

Simple API with submit and cancel events, onPassphraseIncorrect, settings for color and button text, optional secondary option (skip or similar).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.