0.3.353 • Published 29 days ago

zkshield v0.3.353

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
29 days ago

ZK Shield (soon to be zkonnect)

Introduction

ZK Shield is a simple React component that allows you to quickly and easily integrate your zkApp with a browser based wallet on the Mina Protocol. It provides wrapper component that hides sub-components until it is connected to a wallet. Data about the connected wallet is made available to all sub-components, along with many other features listed below.

Installation

Install zkshield via npm or your favorite package manager

npm i zkshield

yarn add zkshield

pnpm add zkshield

Usage

Add zkshield to your component or page, and that's it your zkApp will automatically attempt to connect to an available and supported browser wallet. Currently only Auro Wallet is supported, with a bundled local blockchain wallet on the way. Of course you can always write your own wallet provider!

import React from 'react';
import { ZkShield } from 'zkshield';
import ConnectedComponent from '@/components/ConnectedComponent';

export default function ParentComponent() {
 
  return (
    <ZkShield>
 		<ConnectedComponent />
  	</ZkShield>
  );
}

Use the data from the connected wallet in your wrapped components

import React from 'react';
import { AuthContext } from "zkshield";

const ConnectedComponent = () => {
  const [authState, setAuthState] = useContext(AuthContext);

  return (
    <>
    <div>
      <h1>{authState.userAuthenticated && <> Connected as {authState.userAddress} on network {authState.connectedNetwork} </> }</h1>
    </div>
    </>  );
}
export default ConnectedComponent;

Additional components (Coming Soon)

  • Choose network dropdown - place it anywhere on your page, it will hide itself after connected... can it be hidden?
  • Connect button - initiates the connection to a wallet and hides itself after ... can it be hidden?

Demo

You can see a simple demo of the available features at zkonnect.onrender.com

Props and configuration

ZK Shield offers a number of props that can be set to customize your experience.

PropDescriptionType
ignoreConnectForTestingDisables connecting to wallet, useful for testing none blockchain componentsbool
autoLaunchAutomatically launch the connect workflow, can be used engage the user with other content before connecting to the zkApp. May replace ignoreConnectForTesting in future.bool
minaWalletProviderProvide your own implementation of a wallet provider for wallets that are not yet supported by ZK ShieldIWalletProvider
localAccountsPublicKey accounts to be attached to the local blockchain instancestring[]
childrenComponents that are hidden until the wallet is connected that will have access to the data for the connected walletnode
mainContainerClassNameThe class to apply to the main containerstring
innerContainerClassNameThe class to apply to the inner containerstring
selectNetworkClassNameThe class to apply to the select network containerstring
selectProviderClassNameThe class to apply to the select provider containerstring
headerClassNameThe class to apply to the select header containerstring
statusClassNameThe class to apply to the select status containerstring
headerTextThe text for the headerstring
walletNotFoundTextThe text for wallet not foundstring
createWalletTextThe text for create your walletstring
requestingAccountTextThe text for requesting accountstring
fundAccountTextThe text for funding accountstring

SDK Methods

ZK Shield makes some methods available to interact with the wallet component programmatically. This will allow you to decouple the wallet connection code from the contract interaction.

  • window.zkshield.launch() - initiate a connection to a wallet when autoLaunch is set to false
  • window.zkshield.getSupportedNetworks() - coming soon
  • window.zkshield.chooseNetwork(network) - coming soon
  • window.zkshield.sendZkTransaction() - coming soon
  • window.zkshield.signTransaction(message) - coming soon
  • window.zkshield.onAccountChanged - ?

Writing a new Wallet Provider

(Work in progress, has bugs) Currently only Auro Wallet is supported, a custom Local Blockchain wallet will be bundled in a future release to support interacting with the local blockchain from a zkApp. To write a new wallet provider you have to implement IWalletProvider and pass an instance as a prop to ZK Shield.

import { IWalletProvider, ChainSelectedResult, SignedMessageResult, WalletConnectResult, WalletTransactionResult } from "zkshield";
export class AwesomeWalletProvider implements IWalletProvider {
   
    name: string = "Awesome Wallet";
    description: string = "An awesome wallet to behold.";

    hasWallet(): boolean {
        throw new Error("Method not implemented.");
    }
    connect(): Promise<WalletConnectResult> {
        throw new Error("Method not implemented.");
    }
    sendZkTransaction(json: string, fee: number, memo: string): Promise<WalletTransactionResult> {
        throw new Error("Method not implemented.");
    }
    signMessage(message: string): Promise<SignedMessageResult> {
        throw new Error("Method not implemented.");
    }
    selectChain(chainID: string): Promise<ChainSelectedResult> {
        throw new Error("Method not implemented.");
    }
}

Pass an instance of AwesomeWalletProvider to ZK Shield and you're off!

import React from 'react';
import { AwesomeWalletProvider } from '@/modules/AwesomeWalletProvider.js';

export default function Home() {

  	const provider = new AwesomeWalletProvider();
    return (
        <>
            <ZkShield minaWalletProvider={provider}>
                // Child components...
            </ZkShield>
        </>);
}
    
0.3.353

29 days ago

0.3.341

1 month ago

0.3.343

1 month ago

0.3.342

1 month ago

0.3.345

1 month ago

0.3.344

1 month ago

0.3.347

1 month ago

0.3.346

1 month ago

0.3.349

1 month ago

0.3.348

1 month ago

0.3.339

1 month ago

0.3.332

1 month ago

0.3.331

1 month ago

0.3.334

1 month ago

0.3.333

1 month ago

0.3.336

1 month ago

0.3.335

1 month ago

0.3.338

1 month ago

0.3.337

1 month ago

0.3.329

1 month ago

0.3.328

1 month ago

0.3.321

1 month ago

0.3.323

1 month ago

0.3.322

1 month ago

0.3.325

1 month ago

0.3.324

1 month ago

0.3.327

1 month ago

0.3.326

1 month ago

0.3.35

1 month ago

0.3.34

1 month ago

0.3.33

1 month ago

0.3.352

1 month ago

0.3.351

1 month ago

0.3.32

1 month ago

0.3.316

2 months ago

0.3.315

2 months ago

0.3.291

2 months ago

0.3.293

2 months ago

0.3.292

2 months ago

0.3.295

2 months ago

0.3.294

2 months ago

0.3.297

2 months ago

0.3.296

2 months ago

0.3.299

2 months ago

0.3.298

2 months ago

0.3.282

2 months ago

0.3.281

2 months ago

0.3.284

2 months ago

0.3.283

2 months ago

0.3.286

2 months ago

0.3.285

2 months ago

0.3.288

2 months ago

0.3.287

2 months ago

0.3.289

2 months ago

0.3.279

2 months ago

0.3.3

2 months ago

0.3.312

2 months ago

0.3.311

2 months ago

0.3.314

2 months ago

0.3.313

2 months ago

0.3.31

2 months ago

0.3.29

2 months ago

0.3.28

2 months ago

0.3.271

2 months ago

0.3.273

2 months ago

0.3.272

2 months ago

0.3.275

2 months ago

0.3.274

2 months ago

0.3.277

2 months ago

0.3.276

2 months ago

0.3.278

2 months ago

0.3.269

2 months ago

0.3.27

2 months ago

0.3.262

2 months ago

0.3.261

2 months ago

0.3.264

2 months ago

0.3.263

2 months ago

0.3.266

2 months ago

0.3.265

2 months ago

0.3.268

2 months ago

0.3.267

2 months ago

0.3.26

2 months ago

0.3.259

2 months ago

0.3.258

2 months ago

0.3.251

2 months ago

0.3.253

2 months ago

0.3.252

2 months ago

0.3.255

2 months ago

0.3.254

2 months ago

0.3.257

2 months ago

0.3.256

2 months ago

0.3.25

2 months ago

0.3.242

2 months ago

0.3.244

2 months ago

0.3.243

2 months ago

0.3.246

2 months ago

0.3.245

2 months ago

0.3.248

2 months ago

0.3.247

2 months ago

0.3.249

2 months ago

0.3.24

2 months ago

0.3.241

2 months ago

0.3.0

2 months ago

0.3.2

2 months ago

0.3.1

2 months ago

0.3.23

2 months ago

0.3.22

2 months ago

0.3.21

2 months ago

0.3.231

2 months ago

0.3.233

2 months ago

0.3.232

2 months ago

0.3.235

2 months ago

0.3.234

2 months ago

0.3.237

2 months ago

0.3.236

2 months ago

0.3.239

2 months ago

0.3.238

2 months ago

0.2.99

2 months ago

0.2.96

2 months ago

0.2.98

2 months ago

0.2.97

2 months ago

0.2.983

2 months ago

0.2.982

2 months ago

0.2.981

2 months ago

0.2.971

2 months ago

0.2.953

2 months ago

0.2.952

2 months ago

0.2.95

3 months ago

0.2.94

3 months ago

0.2.93

3 months ago

0.2.92

3 months ago

0.2.91

3 months ago

0.2.951

3 months ago

0.2.74

3 months ago

0.2.73

3 months ago

0.2.72

3 months ago

0.2.71

3 months ago

0.2.79

3 months ago

0.2.78

3 months ago

0.2.77

3 months ago

0.2.76

3 months ago

0.2.75

3 months ago

0.2.63

3 months ago

0.2.62

3 months ago

0.2.61

3 months ago

0.2.69

3 months ago

0.2.68

3 months ago

0.2.67

3 months ago

0.2.66

3 months ago

0.2.65

3 months ago

0.2.64

3 months ago

0.2.7

3 months ago

0.2.6

3 months ago

0.2.9

3 months ago

0.2.8

3 months ago

0.2.52

3 months ago

0.2.51

3 months ago

0.2.491

3 months ago

0.2.53

3 months ago

0.2.41

3 months ago

0.2.49

3 months ago

0.2.48

3 months ago

0.2.47

3 months ago

0.2.46

3 months ago

0.2.43

3 months ago

0.2.42

3 months ago

0.2.5

3 months ago

0.2.4

3 months ago

0.2.27

3 months ago

0.2.26

3 months ago

0.2.25

3 months ago

0.2.24

3 months ago

0.2.23

3 months ago

0.2.12

3 months ago

0.2.11

3 months ago

0.2.35

3 months ago

0.2.34

3 months ago

0.2.33

3 months ago

0.2.32

3 months ago

0.2.31

3 months ago

0.2.1

3 months ago

0.2.0

3 months ago

0.2.29

3 months ago

0.2.28

3 months ago

0.2.3

3 months ago

0.2.2

3 months ago

0.0.875

3 months ago

0.0.86

3 months ago

0.0.87

3 months ago

0.0.913

3 months ago

0.0.88

3 months ago

0.0.912

3 months ago

0.0.89

3 months ago

0.0.879

3 months ago

0.0.878

3 months ago

0.0.923

3 months ago

0.0.889

3 months ago

0.1.0

3 months ago

0.1.2

3 months ago

0.1.1

3 months ago

0.1.8

3 months ago

0.0.917

3 months ago

0.1.7

3 months ago

0.0.916

3 months ago

0.0.915

3 months ago

0.1.9

3 months ago

0.1.4

3 months ago

0.1.3

3 months ago

0.1.6

3 months ago

0.0.919

3 months ago

0.1.5

3 months ago

0.0.918

3 months ago

0.0.855

3 months ago

0.0.894

3 months ago

0.0.893

3 months ago

0.0.892

3 months ago

0.0.891

3 months ago

0.0.91

3 months ago

0.0.92

3 months ago

0.0.9

3 months ago

0.0.84

3 months ago

0.0.836

3 months ago

0.0.835

3 months ago

0.0.843

3 months ago

0.0.842

3 months ago

0.0.841

3 months ago

0.0.845

3 months ago

0.0.844

3 months ago

0.0.839

3 months ago

0.0.838

3 months ago

0.0.837

3 months ago

0.0.76

3 months ago

0.0.77

3 months ago

0.0.834

3 months ago

0.0.79

3 months ago

0.0.81

3 months ago

0.0.82

3 months ago

0.0.793

3 months ago

0.0.83

3 months ago

0.0.8

3 months ago

0.0.75

3 months ago

0.0.3

3 months ago

0.0.54

3 months ago

0.0.2

3 months ago

0.0.67

3 months ago

0.0.5

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.1

3 months ago