zcash教程 android,GitHub - zcash/zcash-android-wallet-sdk: Native Android SDK for Zcash

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7a636173682f7a636173682d616e64726f69642d77616c6c65742d73646b2e7376673f6d61784167653d32353932303030267374796c653d706c6173746963

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e746163742d616e64726f6964407a2e636173682d3541413945372e7376673f7374796c653d706c6173746963

68747470733a2f2f696d672e736869656c64732e696f2f6d6176656e2d63656e7472616c2f762f636173682e7a2e6563632e616e64726f69642f7a636173682d616e64726f69642d73646b3f636f6c6f723d73756363657373267374796c653d706c6173746963

This is a beta build and is currently under active development. Please be advised of the following:

This code currently is not audited by an external security auditor, use it at your own risk

The code has not been subjected to thorough review by engineers at the Electric Coin Company

We are actively changing the codebase and adding features where/when needed

🔒 Security Warnings

The Zcash Android Wallet SDK is experimental and a work in progress. Use it at your own risk.

Developers using this SDK must familiarize themselves with the current threat

model, especially the known weaknesses described there.

Zcash Android SDK

This lightweight SDK connects Android to Zcash. It welds together Rust and Kotlin in a minimal way, allowing third-party Android apps to send and receive shielded transactions easily, securely and privately.

Contents

Requirements

This SDK is designed to work with lightwalletd

Structure

From an app developer's perspective, this SDK will encapsulate the most complex aspects of using Zcash, freeing the developer to focus on UI and UX, rather than scanning blockchains and building commitment trees! Internally, the SDK is structured as follows:

sdk_diagram_final.png?raw=true

Thankfully, the only thing an app developer has to be concerned with is the following:

0c1092660e4e982757b4f91ec3323f5f.png

Overview

At a high level, this SDK simply helps native Android codebases connect to Zcash's Rust crypto libraries without needing to know Rust or be a Cryptographer. Think of it as welding. The SDK takes separate things and tightly bonds them together such that each can remain as idiomatic as possible. Its goal is to make it easy for an app to incorporate shielded transactions while remaining a good citizen on mobile devices.

Given all the moving parts, making things easy requires coordination. The Synchronizer provides that layer of abstraction so that the primary steps to make use of this SDK are simply:

Subscribe to wallet data

The Synchronizer takes care of

- Connecting to the light wallet server

- Downloading the latest compact blocks in a privacy-sensitive way

- Scanning and trial decrypting those blocks for shielded transactions related to the wallet

- Processing those related transactions into useful data for the UI

- Sending payments to a full node through [lightwalletd](https://github.com/zcash/lightwalletd)

- Monitoring sent payments for status updates

To accomplish this, these responsibilities of the SDK are divided into separate components. Each component is coordinated by the Synchronizer, which is the thread that ties it all together.

Components

Component

Summary

LightWalletService

Service used for requesting compact blocks

CompactBlockStore

Stores compact blocks that have been downloaded from the LightWalletService

CompactBlockProcessor

Validates and scans the compact blocks in the CompactBlockStore for transaction details

OutboundTransactionManager

Creates, Submits and manages transactions for spending funds

Initializer

Responsible for all setup that must happen before synchronization can begin. Loads the rust library and helps initialize databases.

DerivationTool, BirthdayTool

Utilities for deriving keys, addresses and loading wallet checkpoints, called "birthdays."

RustBackend

Wraps and simplifies the rust library and exposes its functionality to the Kotlin SDK

Quickstart

Add flavors for testnet v mainnet. Since productFlavors cannot start with the word 'test' we recommend:

flavorDimensions 'network'

productFlavors {

// would rather name them "testnet" and "mainnet" but product flavor names cannot start with the word "test"

zcashtestnet {

dimension 'network'

matchingFallbacks = ['zcashtestnet', 'debug']

}

zcashmainnet {

dimension 'network'

matchingFallbacks = ['zcashmainnet', 'release']

}

}

Add the SDK dependency:

implementation 'cash.z.ecc.android:zcash-android-sdk:1.3.0-beta10'

synchronizer.start(this)

Get the wallet's address

synchronizer.getAddress()

// or alternatively

DerivationTool.deriveShieldedAddress(viewingKey)

Send funds to another address

synchronizer.sendToAddress(spendingKey, zatoshi, address, memo)

Examples

Full working examples can be found in the demo app, covering all major functionality of the SDK. Each demo strives to be self-contained so that a developer can understand everything required for it to work. Testnet builds of the demo app will soon be available to download as github releases.

Demos

Menu Item

Related Code

Description

Get Private Key

Given a seed, display its viewing key and spending key

Get Address

Given a seed, display its z-addr

Get Balance

Display the balance

Get Latest Height

Given a lightwalletd server, retrieve the latest block height

Get Block

Given a lightwalletd server, retrieve a compact block

Get Block Range

Given a lightwalletd server, retrieve a range of compact blocks

List Transactions

Given a seed, list all related shielded transactions

Send

Send and monitor a transaction, the most complex demo

Compiling Sources

⚠️ Compilation is not required unless you plan to submit a patch or fork the code. Instead, it is recommended to simply add the SDK dependencies via Gradle.

In the event that you do want to compile the SDK from sources, follow these steps:

Then, add the android targets via:

rustup target add armv7-linux-androideabi aarch64-linux-android i686-linux-android

Clone this repo

Install android studio and open this project via /your/path/to/zcash-android-wallet-sdk/build.gradle

Open Android Studio’s SDK manager

88e1591918f7b8afb8c4211170a0a9a1.png

Then, install NDK 20.0.5594570 21.1.6352462

(pro tip: build.gradle -> ndkVersion defines the actual required version. Use that because this README may get out-of-date)

ndk-window.png?raw=true

Create an emulator if you don’t already have one (recommended target: API 29)

Select your desired build variant. Currently, we recommend zcashmainnetDebug as the testnet variants are slower to sync to current height due to a lack of checkpoints.

build-variants.png?raw=true

Sync project with Gradle files, and build from the IDE. Alternatively, to build from the command line run:

./gradlew clean assembleZcashmainnetDebug

// or to install in MavenLocal, set properties in Deps.kt then run

./gradlew publishToMavenLocal

This creates a build of the SDK under build/outputs/aar/ that can be used to preview functionality. For more detailed examples, checkout the demo app. Note that merely using the SDK does not require installing Rust or Cargo--that is only required when compiling from source.

Versioning

This project follows semantic versioning with pre-release versions. An example of a valid version number is 1.0.4-alpha11 denoting the 11th iteration of the alpha pre-release of version 1.0.4. Stable releases, such as 1.0.4 will not contain any pre-release identifiers. Pre-releases include the following, in order of stability: alpha, beta, rc. Version codes offer a numeric representation of the build name that always increases. The first six significant digits represent the major, minor and patch number (two digits each) and the last 3 significant digits represent the pre-release identifier. The first digit of the identifier signals the build type. Lastly, each new build has a higher version code than all previous builds. The following table breaks this down:

Build Types

Type

Purpose

Stability

Audience

Identifier

Example Version

alpha

Sandbox. For developers to verify behavior and try features. Things seen here might never go to production. Most bugs here can be ignored.

Unstable: Expect bugs

Internal developers

0XX

1.2.3-alpha04 (10203004)

beta

Hand-off. For developers to present finished features. Bugs found here should be reported and immediately addressed, if they relate to recent changes.

Unstable: Report bugs

Internal stakeholders

2XX

1.2.3-beta04 (10203204)

release candidate

Hardening. Final testing for an app release that we believe is ready to go live. The focus here is regression testing to ensure that new changes have not introduced instability in areas that were previously working.

Stable: Hunt for bugs

External testers

4XX

1.2.3-rc04 (10203404)

production

Delivery. Deliver new features to end-users. Any bugs found here need to be prioritized. Some will require immediate attention but most can be worked into a future release.

Stable: Prioritize bugs

Public

8XX

1.2.3 (10203800)

Examples

Examples can be found in the Demo App

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值