Giter Site home page Giter Site logo

betoxl / nami-wallet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from input-output-hk/nami

0.0 1.0 0.0 14.86 MB

Nami Wallet is a browser based wallet extension to interact with the Cardano blockchain.

Home Page: https://namiwallet.io

License: MIT License

JavaScript 99.80% HTML 0.16% CSS 0.03%

nami-wallet's Introduction

Nami Wallet

Nami Wallet is a browser based wallet extension to interact with the Cardano blockchain. It's an open-source project and built by Berry Pool.

Injected API

Since Nami is a browser extension, it can inject content inside the web context, which means you can connect the wallet to any website. The exposed API follows for most parts this proposed CIP. The returned types are in cbor/bytes format. A helpful library for serializing and de-serializing these low-level data structures is the serialization-lib. To verify a signature returned from cardano.dataSign(address, payload) the message-signing library helps.

Basic Usage

  • Detect the Cardano provider (window.cardano)
  • Detect which Cardano network the user is connected to (ID 1 = Mainnet, ID 0 = Testnet)
  • Get the user's Cardano account

Methods

All methods will return their values as Promise. For simplicity and easier understanding the API is explained without the Promises.

cardano.enable()

Will ask the user to give access to requested website. If access is given, this function will return true, otherwise throws an error. If the user calls this function again with already having permission to the requested website, it will simply return true.

cardano.isEnabled()
cardano.isEnabled() : boolean

Returns true if wallet has access to requested website, false otherwise.

cardano.getBalance()
cardano.getBalance() : Value

Value is a hex encoded cbor string.

cardano.getUtxos(amount, paginate)
cardano.getUtxos(amount?: Value, paginate?: {page: number, limit: number}) : [TransactionUnspentOutput]

TransactionUnspentOutput is a hex encoded bytes string.

amount and paginate are optional parameters. They are meant to filter the overall utxo set of a user's wallet.

cardano.getUsedAddresses()
cardano.getUsedAddresses() : [BaseAddress]

BaseAddress is a hex encoded bytes string.

Note Nami Wallet doesn't utilize the concept of multipe addresses per wallet. This function will return an array of length 1 and will always return the same single address. Just to follow the standards of the proposed CIP, it will return the address in an array.

cardano.getUnusedAddresses()
cardano.getUnusedAddresses() : [BaseAddress]

Note This endpoint will return an empty array []. Same reason as above, simply to follow the standards.

cardano.getChangeAddress()
cardano.getChangeAddress() : BaseAddress

Will return the same address as the one in cardano.getUsedAddresses().

cardano.getRewardAddress()
cardano.getRewardAddress() : RewardAddress

RewardAddress is a hex encoded bytes string.

cardano.getNetworkId()
cardano.getNetworkId() : number

Returns 0 if on testnet, otherwise 1 if on mainnet.

cardano.signData(address, payload)
cardano.signData(address: BaseAddress|RewardAddress, payload: string) : CoseSign1

payload is a hex encoded utf8 string. CoseSign1 is a hex encoded bytes string.

If address is the BaseAddress the signature is returned with the Payment Credential, otherwise if the address is the RewardAddress the signature is returned with the Stake Credential.

The returned CoseSign1 object contains the payload, signature and the following protected headers:

  • key_id => PublicKey,
  • address => BaseAddress | RewardAddress
  • algorithm_id => EdDSA(0) (the algorithm used for Cardano addresses).

Read more about message signing in CIP-0008.

cardano.signTx(tx, partialSign)
cardano.signTx(tx: Transaction, partialSign?: boolean) : TransactionWitnessSet

Transaction is a hex encoded cbor string. TransactionWitnessSet is a hex encoded cbor string.

partialSign is by default false and optional. The wallet needs to provide all required signatures. If it can't an error is thrown, otherwise the TransactionWitnessSet is returned.

If partialSign is true, the wallet doesn't need to provide all required signatures.

cardano.submitTx(tx)
cardano.submitTx(tx : Transaction) : hash32

Returns the transaction hash, if transaction was submitted successfully, otherwise throws an error.

Events

cardano.onAccountChange(addresses)
cardano.onAccountChange((addresses : [BaseAddress]) => void)
cardano.onNetworkChange(network)
cardano.onNetworkChange((network : number) => void)

Note To follow the standards of multiple addresses the callback will return an array, although Nami Wallet will just return an array with a single address, which is the same as the one in cardano.getUsedAddresses().

Develop

The project_id for API requests can be created under blockfrost.io.

Recommended: Follow this approach in order to keep the keys seperate from the repository.

The quick solution is to go under ./src/config/provider.js and replace secrets.PROJECT_ID_MAINNET and secrets.PROJECT_ID_TESTNET with the project ids from blockfrost.

Start development server
npm start
Create production build
npm run build

Website

Visit namiwallet.io
Visit Berry Pool

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.