Nyzo techRelease notesNyzo Chrome extension 1: sending tips

Nyzo Chrome extension 1: sending tips

Nyzo Chrome extension version 1 (commit on GitHub) introduces the Nyzo extension for Google Chrome. This version includes the ability to send tips to web pages.

This is a new repository, separate from the Nyzo verifier. It runs in the Chrome web browser.

Nyzo has the ability to process large numbers of transactions quickly and efficiently. This puts it in a nice place for providing micropayments for web content. Currently, website operators have few options for monetizing content: primarily ads, sponsorships, donations, and subscriptions. Ads are obtrusive and require large volume to make significant money. Sponsorships are difficult to secure and can compromise the integrity of the content. Donations are typically saddled with large processing fees, pushing donation amounts to levels that discourage consumers. And subscriptions are long-term commitments for typically short-term relationships between producers and consumers of content. All of the existing systems reward centralization of power: of payment processors, of advertising networks, of large content creators. Nyzo is built around a sincere desire for decentralization, with the idea that giving power back to the community is the best way to promote a vibrant economy.

This is a typical Google Chrome extension. The manifest.json file defines the structure of the extension. The content.js script processes pages, and the popup.js script provides sending functionality.

The ByteBuffer JavaScript class is used roughly the way Java's built-in ByteBuffer class is used: for the assembly of binary serializations of objects.

CX_1 code 0

In a Chrome extension, the content script has access to the DOM of the page. The script in content.js finds Nyzo tip buttons, changing their classes to allow the creator of the page to change their appearance if the Nyzo extension is installed.

The script also gets the clientUrl, receiverId, and tag data attributes from the buttons. A listener is registered to return these values to the extension's popup. Note that only one of each value is passed to the popup, so if multiple buttons on the page have conflicting values, only one of those values will be used.

The page must have a clientUrl and receiverId to be able to accept tips. However, the tag is not required. It is for the receiver's use to track the origin of tips.

CX_1 code 1

The extensionUtil.js file contains helper functions specific to this extension. The isValidPrivateKey() and isValidPublicIdentifier() functions ensure that the values provided are valid Nyzo strings of the correct types.

The getTipAmountMicronyzos() function converts a decimal string representation of a Nyzo value to a number of the amount in micronyzos. The isValidTipAmount() function tells if a string provided by the user during configuration represents a valid amount for a tip.

CX_1 code 2

The isValidClientUrl() function provides some simple validation of the client URL provided by the page. The sanitizeString() function removes angle brackets to make strings safer for HTML display. The cleanTag() function removes all characters except ASCII letters, numbers, and the underscore.

CX_1 code 3

The submitTransaction() function creates and signs a Nyzo transaction.

CX_1 code 4

The submitTransaction() function sends the transaction to the Nyzo client, processes the result, and relays the result to a callback function.

CX_1 code 5

The transaction is converted to a Nyzo transaction string for submission, and it is passed to the specified client endpoint in an asynchronous GET request.

CX_1 code 6

Four resolutions of a Nyzo logo are included.

CX_1 code 7

Icons are included to denote success or failure when sending a transaction.

CX_1 code 8

The manifest.json file includes basic information about the extension. The extension uses the activeTab permission to get the client URL and receiver ID from the page and to modify the tip buttons. It uses the storage permission to store the sender key and base tip amount that the user configures.

CX_1 code 9

The nacl.min.js file is used for Ed25519 digital signatures for transactions.

CX_1 code 10

The nyzoString.js file provides classes to encapsulate NyzoStringPrivateSeed, NyzoStringPublicIdentifier, and NyzoStringPrefilledData objects. The NyzoStringPrefilledData object is unused in this version.

CX_1 code 11

The characterLookup provides a value-to-character mapping, and the characterToValueMap provides the inverse.

CX_1 code 12

The arraysAreEqual function is used to confirm the checksum of Nyzo strings.

CX_1 code 13

The decode() function decodes Nyzo strings to the objects they represent.

CX_1 code 14

The byteArrayForEncodedString() function performs just the character-to-value part of Nyzo string decoding.

CX_1 code 15

The encodedStringForByteArray() function performs the inverse of byteArrayForEncodedString().

CX_1 code 16

The encodeNyzoString() function produces Nyzo strings from byte array representations of Nyzo objects. This function prepends the type prefix and appends the checksum.

CX_1 code 17

The nyzoStringFromPrivateKey(), nyzoStringFromPublicIdentifier(), and nyzoStringFromTransaction() functions select appropriate prefixes and produce Nyzo string representations.

CX_1 code 18

The options page allows input of a private key and a base tip amount. The JavaScript dependencies are used for input validation.

CX_1 code 19

The script for the options page adds event listeners to validate and store the inputs values when they change. The form is initially populated with values from storage, if any are available.

CX_1 code 20

The loadValue() function loads a value into a field from Chrome's local storage, using the provided default if no value is available. This function is unused in this version.

CX_1 code 21

The validateAndStorePrivateKey() function stores the provided private key value to local storage. To provide feedback to the user, the CSS class of the field is set according to whether the value provided is a valid Nyzo string private key.

CX_1 code 22

The validateAndStoreBaseTip() function provides the same behavior for the base tip field, checking to ensure that the tip is a numerical value in the accepted range.

CX_1 code 23

The popup provides buttons for sending a tip, fields to show the receiver ID and client URL for the current page, an indicator for pages that do not accept tips, and a view for progress and results when a tip is sent.

CX_1 code 24

When the popup loads, the tip buttons and the receiver ID and client URL fields are configured if all the information necessary for sending a tip is available. If the page does not accept tips, or if the user needs to configure the extension, appropriate feedback is presented.

CX_1 code 25

The sendTip() function is performed when a tip button is clicked. This function retrieves the private key and base tip amount from storage, retrieves the client URL and receiver ID from the current tab, and creates and sends the transaction. An icon is displayed to indicate success or failure, and the results provided by the client, along with any errors encountered, are presented to the user.

CX_1 code 26

The stringForArray() function provides an HTML string with line breaks for an array of strings.

CX_1 code 27

The configurationValid() function checks the private key and base tip retrieved from storage.

CX_1 code 28

The openOptionsPage() function is used by the button that is presented in the popup when the extension's current configuration is insufficient for sending tips.

CX_1 code 29

SHA-256 is used for the sender-data hash in transactions, for the checksum in Nyzo strings, and for block and balance-list hashes.

CX_1 code 30

The style.css file is shared between the options page and popup.

CX_1 code 31

The Transaction class is a minimal implementation supporting standard transactions. The constructor sets all fields to default values, and mutators are provided for all fields.

CX_1 code 32

The Transaction.sign() method uses the nacl library to produce a signature, and the signature is stored in the object's signature field. The signer's identifier is stored in the object's senderIdentifier field.

CX_1 code 33

The Transaction.getBytes() method is used to produce a byte-array representation of a transaction. This is used in the signing process and for serialization to produce a Nyzo string for transmission.

CX_1 code 34

The util.js file contains general utility functions that are useful in this extension but not written specifically for this extension.

CX_1 code 35