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

web_auth_sdk

v0.1.0

Published

The only and best SDK for ABCWallet application development.

Downloads

7

Readme

Web Auth SDK

License: MIT

README | 中文文档

Introduction

The Web Auth SDK is part of the Web Auth framework and is available to Dapp who wish to access Web Auth services. First, Dapp needs to embed Web Auth Page through iframe, and then it can communicate with Web Auth Page via the SDK.

Getting started

Installation

npm install @blockabc/web_auth_sdk

Example

The source code is located at [example/static/main.js](. /example/static/main.js), clone this project, install the dependencies, and then run npm run dev to see the demo Dapp. Note that **you must configure the iframeSrc constant at the top of example/static/main.js base on the URL of your Web Auth Page server.

Initialization

const webauth = new WebAuth({
  options: {
    win: iframe.contentWindow,
    targetOrigin: 'http://127.0.0.1:3000', // must be the url of web_auth_page
  }
})

Request user to sign in and get CKB address

try {
  const { address, nickname, profile } = await webauth.signIn()
}
catch (err) {
  // If the user declines, then an error will be thrown
  alert(err.message)
}

Request user to build transaction

try {
  const { signedTransaction } = await webauth.buildTransaction(tos)
}
catch (err) {
  // If the user declines, then an error will be thrown
  alert(err.message)
}

API

class WebAuth

class WebAuth {
  constructor (
    { driver = 'iframe', options, loglevel = 'info' }:
    { driver?: string, options: any, loglevel?: string | number }
  ): void;
}

The structure of the options depends on which drivier you choose, the driver is abstract communication layer of the SDK, which may support environments like Android and iOS webview by implementing different drivers.

webauth.ping

webauth.ping (): Promise<string>

Check if connection between the SDK and Web Auth Page has been established, and return the string pong when it is true.

webauth.signIn

interface ISignInResult {
  address:  string;
  nickname: string;
  profile:  any;
}

webauth.signIn ({ readyForSign }: { readyForSign?: boolean } = {}): Promise<ISignInResult>

The user is requested to sign in, and a successful signing in will return a instance of ISignInResult.

webauth.buildTransaction

interface IUTXOToParam {
  address: string,
  value: Decimal.Value,
}

interface ISignedTransactionResult {
  signedTransaction: RPC.RawTransaction,
}

webauth.buildTransaction ({ tos }: { tos: IUTXOToParam[] }): Promise<ISignedTransactionResult>

Request user to build transaction.

Go here for RPC.RawTransaction

webauth.signTransaction

interface IUTXOUnspent {
  txId: string,
  address: string,
  vout: number,
  value: Decimal.Value,
  lock?: any,
  lockHash?: string,
}

webauth.signTransaction ( { unspents, rawTransaction }: { unspents: IUTXOUnspent[], rawTransaction: RPC.RawTransaction } ): Promise<ISignedTransactionResult>

Request user to sign transaction。Constructing unsigned transactions and obtaining IUTXOUnspent[] requires the use of One Chain CKB, which you can learn about in this example.

Go here for RPC.RawTransaction

webauth.pushTransaction

webauth.pushTransaction ({ rawTransaction }: { rawTransaction: RPC.RawTransaction }): Promise<{ txId: string }>

Push transactions through the RPC node of Web Auth Page, will not disturb user.

Go here for RPC.RawTransaction

Development

This is a simple SDK, but we still welcome anyone to contribute a piece of code after familiar with the source code quickly, whether it's adding an interface, implementing a Driver, or perfecting documentation.

Code Style

We use a little tweaked version of standardjs: https://github.com/BlockABC/eslint-config-blockabc

Issues

Please feel free to submit your questions at Issues.

License

MIT