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

@coolwallet/xtz

v1.0.1

Published

Coolwallet Tezos sdk

Downloads

71

Readme

CoolWallet Tezos (XTZ) SDK

Typescript library with support for the integration of Tezos (XTZ) for third party applications, include the functionalities of generation of addresses, signed transactions, and baking. The XTZ library supports two styles of key derivation path

  1. PATH_STYPE.CWT (default): m/44'/1729'/0'/0/{addressIndex}
  2. PATH_STYLE.XTZ: m/44'/1729'/{accountIndex}'/0'

Install

npm install @coolwallet/xtz

Usage

import XTZ from '@coolwallet/xtz';
import { PATH_STYLE } from '@coolwallet/xtz';
import { crypto } from '@coolwallet/core';
import { createTransport } from '@coolwallet/transport-web-ble';

// const xtz = new XTZ() // Path: m/44'/1729'/0'/0/{i}
const xtz = new XTZ(PATH_STYLE.XTZ); // Path: m/44'/1729'/{i}'/0' 

const transport = await createTransport();

const { privateKey: appPrivateKey } = crypto.key.generateKeyPair();

const appId = 'appId that had been registered by wallet';

const address = await xtz.getAddress(transport, appPrivateKey, appId, 0);

const normalTransaction = {
    brance: "BKiXcfN1ZTXnNNbTWSRArSWzVFc6om7radWq5mTqGX6rY4P2Uhe",
    source: "tz1YU2zoyCkXPKEA4jknSpCpMs7yUndVNe3S",
    fee: "1520", // in mutez
    counter: "2622173",
    gas_limit: "10500",
    storage_limit: "300",
    amount: "300000", // in mutez
    destination: "tz2FwBnXhuXvPAUcr1aF3uX84Z6JELxrdYxD"
};

const signTxData = {
  transport,
  appPrivateKey,
  appId,
  addressIndex: 0
}

// Submit transcation can be directly injected into blockchain
const normalTx = await xtz.signTransaction(signTxData, normalTransaction);

Methods

XTZ (Constructor)

Description

Create XTZ with specified path style with pathStyle to indicate the selected path style as

1. PATH_STYLE.CWS (defalut)
m/44'/1729'/0'/0/{addressIndex}

2. PATH_STYLE.XTZ
m/44'/1729'/{accountIndex}'/0' 
XTZ(
    pathStyle: PATH_STYLE
)

Arguments

| Arg | Description | Type | Required | |:-------------:|:--------------------------------------:|:----------:|:---------:| | pathStype | Path style (CWS by default or XTZ) | PATH_STYLE | False |

getAddress

Description

Get address by address index.

The XTZ address generated is compatible to BIP44 with account and change set to 0, which means calling getAddress with addressIndex = i will get the address of folllowing path:

1. PATH_STYLE.CWS (defalut)
m/44'/1729'/0'/0/{i}

2. PATH_STYLE.XTZ
m/44'/1729'/{i}'/0' 

In the design of current hardware, we only support path m/44'/1729'/0'/0/{i} for speed optimization. This might change in the future and we will then open a more general interface to deal with custom path.

async getAddress(
    transport: types.Transport, 
    appPrivateKey: string, 
    appId: string, 
    addressIndex: number
): Promise<string>

Arguments

| Arg | Description | Type | Required | |:-------------:|:--------------------------------------------:|:---------:|:---------:| | transport | Object to communicate with CoolWallet device | Transport | True | | appPrivateKey | Private key for the connected application | string | True | | appId | ID for the connected application | string | True | | addressIndex | The from address index in BIP44 derivation | number | True |

getPublicKeyHash

Description

Get public key hash by address index.

The XTZ public key hash generated is compatible to BIP44 with account and change set to 0, which means calling getPublicKeyHash with addressIndex = i will get the public key hash of folllowing path:

1. PATH_STYLE.CWS (defalut)
m/44'/1729'/0'/0/{i}

2. PATH_STYLE.XTZ
m/44'/1729'/{i}'/0'

In the design of current hardware, we only support path m/44'/1729'/0'/0/{i} for speed optimization. This might change in the future and we will then open a more general interface to deal with custom path.

async getPublicKeyHash(
    transport: types.Transport, 
    appPrivateKey: string, 
    appId: string, 
    addressIndex: number
): Promise<string>

Arguments

| Arg | Description | Type | Required | |:-------------:|:--------------------------------------------:|:---------:|:---------:| | transport | Object to communicate with CoolWallet device | Transport | True | | appPrivateKey | Private key for the connected application | string | True | | appId | ID for the connected application | string | True | | addressIndex | The from address index in BIP44 derivation | number | True |

Sign Transaction

Description

CoolWallet currently support various signing methods and contracts based on the type of the transaction. The SignTxData and xtzOperation arguments are the essentail data fields for XTZ operations. Depends on the type of operation, the extended arguments may vary.

SignTxData Arguments

| Arg | Description | Type | Required | |:-------------:|:--------------------------------------------------------------------:|:---------:|:---------:| | transport | Object to communicate with CoolWallet device | Transport | True | | appPrivateKey | Private key for the connected application | string | True | | appId | ID for the connected application | string | True | | addressIndex | The from address index in BIP44 derivation | number | True | | confirmCB | Callback of confirmation data to the connected application | Function | False | | authorizedCB | Callback of authorized transaction data to the connected application | Function | False |

xtzOperation Arguments

| Arg | Description | Type | Required | |:------------------:|:--------------------------------------------------------------------------:|:------:|:--------:| | branch | The hash of the checkpoint block | string | True | | source | The from address of the transaction | string | True | | fee | The number of the checkpoint block | string | True | | counter | The nonce of the transaction | string | True | | gas_limit | The current spec version for the runtime | string | True | | storage_limit | The tip to increase transaction priority | string | True |

The extended arguments may vary depend on the type of the operation. The operation can be for transfering (signTransaction), revealing (signReveal) or baking (signDelegation, signUndelegation) purposes.

signTransaction

Description

Sign XTZ Transaction Operation for Transfering

async signTransaction(signTxData: SignTxData, operation: types.xtzTransaction) 

Extended Arguments

| Arg | Description | Type | Required | |:-----------:|:-------------------:|:------:|:--------:| | amount | Value to transfer | string | True | | destination | Destination address | string | True | | parameters | Data for contract | string | false |

signReveal

Description

Sign XTZ Reveal Operation for Revealing Public Key of Manager

async signReveal(signTxData: SignTxData, operation: types.xtzReveal) 

Extended Arguments

| Arg | Description | Type | Required | |:-----------:|:--------------------------:|:------:|:--------:| | public_key | Public key hash of manager | string | True |

signDelegation

Description

Sign XTZ Delegation Operation for Delegating

async signDelegation(signTxData: SignTxData, operatopn: types.xtzDelegation) 

Extended Arguments

| Arg | Description | Type | Required | |:-----------:|:---------------------:|:------:|:--------:| | delegate | Address of baker | string | True |

signUndelegation

Description

Sign XTZ Delegation Operation for Undelegating

async signUndelegation(signTxData: SignTxData, operation: xtzDelegation) 

Extended Arguments

None