npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@waves/signature-adapter

v7.0.0

Published

## Installation

Downloads

5,679

Readme

JS library for signing data

Installation

$ npm install --save @waves/signature-adapter

Usage

import { SeedAdapter, SIGN_TYPE } from '@waves/signature-adapter';
import { Money, Asset } from '@waves/data-entities';

const asset = new Asset({
   ticker: 'WAVES',
   id: 'WAVES',
   name: 'Waves',
   precision: 8,
   description: '',
   height: 0,
   timestamp: new Date('2016-04-11T21:00:00.000Z'),
   sender: '',
   quantity: 10000000000000000,
   reissuable: false
});

const transferTransactionData = {
   recipient: 'some address or alias',
   amount: Money.fromTokens(1, asset),
   attachment: 'Some attachment text less 140 bytes',
   fee: Money.fromTokens(0.001, asset)
};

const adapter = new SeedAdapter('some seed phrase with 15 or more chars');
const signable = adapter.makeSignable({
   type: SIGN_TYPE.TRANSFER,
   data: transferTransactionData
});

signable.getDataForApi().then(data => fetch('node-url', {
   method: 'POST',
   body: JSON.stringify(data)
}));

Adapters are used to sign data. There are two types of adapters: SeedAdapter - is an adapter for usage with seed in string representation LedgerAdapter - is an adapter for usage with Ledger hardware wallet

SeedAdapter

SeedAdapter accepts either a seed phrase or an object containing information about the seed phrase on create Object structure: encryptedSeed {string} - seed phrase encoded with passwords password {string} - password that is encrypted seed phrase encryptionRounds {number} - encryption complexity

For change network byte use @waves/signature-generator config:

import { config } from '@waves/signature-generator';

config.set('networkByte', 'T'.charCodeAt(0))

If you use seed phrase to create SeedAdapter note that the minimum length of a phrase is 15 characters. See the documentation @waves/signature-generator for more details

Example of creation SeedAdapter with seed phrase:

import { SeedAdapter } from '@waves/signature-adapter';

const adapter = new SeedAdapter('some seed phrase more 15 chars');

LedgerAdapter

SeedAdapter accepts an object that contains information about an address and wallet ID in Ledger on create Object structure:

  • publicKey {string} - public key for the address
  • address {string} - address
  • id {number} - wallet ID in Ledger

To get an objects for creating an instance of LedgerAdapter there is a static method of the class "getUserList".

  • getUserList(from?: number, to?: number): Promise<Array<{publicKey: string, address: string, id: number}>>;

Where ‘from’ is wallet ID in the Ledger from which to start receiving data, ‘to’ - the number to finish.

Example:

import { LedgerAdapter } from '@waves/signature-adapter';

LedgerAdapter.getUserList().then(([userData]) => new LedgerAdapter(userData));

Common methods for both types of adapters

  • isAvailable(): Promise<void>; Returns promise which returns an error in case the adapter is unavailable.

  • getPublicKey(): Promise<string>; Returns a public key

  • getAddress(): Promise<string>; Returns an address

  • getPrivateKey(): Promise<string>; Returns a private key or an error If adapter is not able to return it (in case of LedgerAdapter)

  • signRequest(bytes: Uint8Array): Promise<string>; Accepts byte array for signing, returns promise with a signature. This method is used for signing any data except transactions and orders

  • signTransaction(bytes: Uint8Array): Promise<string>; Accepts byte array for signing, returns promise with a signature. This method is used for signing transactions

  • signOrder(bytes: Uint8Array): Promise<string>; Accepts byte array for signing, returns promise with a signature. This method is used for signing orders

  • signData(bytes: Uint8Array): Promise<string>; Accepts byte array for signing, returns promise with a signature. This method is used for signing any data This method is not recommended for signing transactions due to incorrect confirmation display on Ledger

  • getSeed(): Promise<string>; Returns the seed phrase or an error If adapter is not able to return it (in case of LedgerAdapter)

  • makeSignable(signData): Signable; Accepts data for signature (Visit interfaces for more information about “TSignData” interface) and returns an instance of the Signable class

Signable

  • getTxData(): {object}; Returns a copy of the object data transferred for signature

  • getSignData(): Promise<object>; Returns data for signing as received for making signature @waves/signature-generator

  • addProof(proof: string): Signable; Accepts the signature for adding it to the signature list. Signature list is used for "getDataForApi" method

  • getId(): Promise<string>; Returns promise with hash of all data used for signature

  • sign(): Promise<Signable>; Method initiates signing and returns promise that waits the completion of signing. This method adds only one signature for the lifetime of one instance of the Signable class. When you call it again it returns a previously created promise

  • getSignature(): Promise<string>; Acts same as sign() method, but returns promise with signature

  • getBytes(): Promise<Uint8Array>; Returns bytes for signing

  • getMyProofs(): Promise<Array<string>>; Returns array of signatures that belongs to public key of the adapter from which the instance of class Signable was created

  • hasMySignature(): Promise<boolean>; Returns promise with boolean status about presence of “own” signature (Same as in “getMyProofs” method)

  • addMyProof(): Promise<string>; This method checks the presence of “own” signature. If signature exists it returns the last “own” signature, otherwise its signs and returns the new signature

  • getDataForApi():Promise<object>; Calls the method “addMyProof” to guarantee the presence of one “own” signature. Returns the data that is prepared to send into node. Adds the list of signatures