├── src ├── css │ └── cardano-wallet-picker.css ├── examples │ └── send_ada.html └── index.js ├── webpack.config.cjs ├── package.json ├── .npmignore ├── .gitignore ├── README.md └── LICENSE /src/css/cardano-wallet-picker.css: -------------------------------------------------------------------------------- 1 | /** 2 | * A simple stylesheet that enables clean dropdown styling on the dApp wallet picker. 3 | */ 4 | ul { 5 | padding: 0; 6 | list-style: none; 7 | } 8 | ul li { 9 | display: inline-block; 10 | position: relative; 11 | line-height: 21px; 12 | text-align: left; 13 | } 14 | ul li a { 15 | display: block; 16 | padding: 8px 25px; 17 | text-decoration: none; 18 | background: #ffffff; 19 | } 20 | ul li a:hover { 21 | color: #fff; 22 | background: #939393; 23 | } 24 | ul li ul.dropdown { 25 | min-width: 100%; 26 | display: none; 27 | position: absolute; 28 | z-index: 999; 29 | left: 0; 30 | } 31 | ul li:hover ul.dropdown { 32 | display: block; 33 | } 34 | ul li ul.dropdown li { 35 | display: block; 36 | } 37 | -------------------------------------------------------------------------------- /webpack.config.cjs: -------------------------------------------------------------------------------- 1 | const copyplugin = require('copy-webpack-plugin'); 2 | const path = require('path'); 3 | const webpack = require('webpack'); 4 | 5 | module.exports = { 6 | context: path.join(__dirname, 'src'), 7 | entry: './index.js', 8 | mode: 'production', 9 | 10 | experiments: { 11 | asyncWebAssembly: true, 12 | topLevelAwait: true, 13 | layers: true // optional, with some bundlers/frameworks it doesn't work without 14 | }, 15 | 16 | output: { 17 | filename: 'cardano-dapp-js.js', 18 | library: 'CardanoDAppJs' 19 | }, 20 | 21 | plugins: [ 22 | // Work around for Buffer is undefined: 23 | // https://github.com/webpack/changelog-v5/issues/10 24 | new webpack.ProvidePlugin({ 25 | Buffer: ['buffer', 'Buffer'] 26 | }), 27 | 28 | new copyplugin({ 29 | patterns: [ 30 | { from: 'css/**/*', to: '[name][ext]' } 31 | ] 32 | }), 33 | 34 | new webpack.optimize.LimitChunkCountPlugin({ 35 | maxChunks: 1, // disable creating additional chunks 36 | }) 37 | ] 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cardano-dapp-js", 3 | "version": "1.0.11", 4 | "description": "A library that enables websites to quickly become dApps using Javascript code", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "build": "webpack", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/thaddeusdiamond/cardano-dapp-js.git" 13 | }, 14 | "keywords": [ 15 | "dApp", 16 | "Cardano", 17 | "CNFT", 18 | "NFT", 19 | "Javascript", 20 | "JS" 21 | ], 22 | "author": "Thaddeus Diamond", 23 | "license": "Apache-2.0", 24 | "dependencies": { 25 | "buffer": "^6.0.3", 26 | "@dcspark/adalib": "^1.3.1", 27 | "encoding": "0.1.13", 28 | "lokijs": "1.5.12", 29 | "lucid-cardano": "^0.7.8", 30 | "pino-pretty": "10.2.0", 31 | "toastify-js": "^1.11.2", 32 | "@web3modal/ethereum": "^2.7.1", 33 | "@web3modal/html": "^2.7.1", 34 | "@wagmi/core": "^1.3.8" 35 | }, 36 | "devDependencies": { 37 | "copy-webpack-plugin": "^11.0.0", 38 | "webpack": "^5.72.1", 39 | "webpack-cli": "^4.9.2" 40 | }, 41 | "bugs": { 42 | "url": "https://github.com/thaddeusdiamond/cardano-dapp-js/issues" 43 | }, 44 | "homepage": "https://github.com/thaddeusdiamond/cardano-dapp-js#readme" 45 | } 46 | -------------------------------------------------------------------------------- /src/examples/send_ada.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 46 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | 84 | # Gatsby files 85 | .cache/ 86 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 87 | # https://nextjs.org/blog/next-9-1#public-directory-support 88 | # public 89 | 90 | # vuepress build output 91 | .vuepress/dist 92 | 93 | # Serverless directories 94 | .serverless/ 95 | 96 | # FuseBox cache 97 | .fusebox/ 98 | 99 | # DynamoDB Local files 100 | .dynamodb/ 101 | 102 | # TernJS port file 103 | .tern-port 104 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # Mac Directory structure 107 | .DS_Store 108 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

cardano-dapp-js

3 |

A library that enables websites to quickly become dApps using Javascript code.

4 |

5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |

17 |

18 | 19 | ## Quickstart 20 | 21 | Recommend prerequisites for running a local NPM webapp: 22 | 23 | * [node](https://nodejs.org/en/download/)>=16.15.1 24 | * [npm](https://www.npmjs.com/package/npm)>=8.12.0 25 | * [static-server](https://www.npmjs.com/package/static-server)>=2.2.1 (for local serving) 26 | 27 | ### Basic usage 28 | 29 | See [cardano-nft-js-toolkit](https://github.com/thaddeusdiamond/cardano-nft-mint-frontend) for full dApp examples. 30 | 31 | First, you need to create a simple div to contain the wallet picker: 32 | 33 | ```html 34 |
35 | ``` 36 | 37 | Then, in a script block use JavaScript to initialize the wallet container and wire up the wallet picker users will use in your dApp. 38 | 39 | ```js 40 | var cardanoDApp = new CardanoDApp('wallet-container'); 41 | ``` 42 | 43 | The wallet returned from calls to this class conforms to [CIP-0030](https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0030/). In addition, we optionally support the [WalletConnect](https://walletconnect.com) protocol for Cardano wallets. To enable WalletConnect support in your dApp you need to include additional information: 44 | 45 | ```js 46 | var cardanoDApp = new CardanoDApp('wallet-container', { 47 | projectId: '0123456789abcdeffedcba9876543210', 48 | relayerRegion: 'wss://relay.walletconnect.com', 49 | metadata: { 50 | description: 'Your dApp description goes here', 51 | name: 'Your dApp', 52 | icons: ['https://www.yourdapp.com/favicon.ico'], 53 | url: 'https://yourdapp.com/' 54 | }, 55 | autoconnect: false 56 | }); 57 | ``` 58 | 59 | Sample usage could be: 60 | 61 | ```js 62 | if (!cardanoDApp.isWalletConnected()) { 63 | alert('Please connect a wallet to access this dApp!'); 64 | return; 65 | } 66 | 67 | cardanoDApp.getConnectedWallet().then(wallet => { 68 | var Blockfrost = new Blockfrost(BLOCKFROST_BASE, BLOCKFROST_KEY); 69 | Lucid.new(Blockfrost, NETWORK).then(lucid => { 70 | lucid.selectWallet(wallet); 71 | lucid.newTx().payToAddress(paymentAddr, { lovelace: paymentAmount }).complete(); 72 | // ... 73 | }); 74 | }); 75 | ``` 76 | 77 | After a successful connection is made by the user a message of type `CARDANO_DAPP_JS_CONNECT` is posted to the window object. For third-party integrations, simply receive this message into your JavaScript code and make use of the `wallet` object that is passed in: 78 | 79 | ```js 80 | window.addEventListener("message", async event => { 81 | // We only accept messages from ourselves 82 | if (event.source != window || !event.data.type) { 83 | return; 84 | } 85 | 86 | try { 87 | switch (event.data.type) { 88 | case "CARDANO_DAPP_JS_CONNECT": 89 | await doSomethingWith(event.data.wallet); 90 | ... 91 | ``` 92 | 93 | ### Styling 94 | 95 | The dropdown menu created by the initialization of the CardanoDApp facilitates unique styling through HTML/CSS identifiers. A simple CSS stylesheet for testing can be found at [cardano-wallet-picker.css](./src/css/cardano-wallet-picker.css) and can be included as: 96 | 97 | ```html 98 | 99 | ``` 100 | 101 | ## Examples 102 | 103 | Please see the examples provide in the [src/examples/](./src/examples/) directory. 104 | 105 | ## Installation 106 | While this code can be built directly into Javascript (using a tool like [Webpack](https://webpack.js.org/guides/getting-started/)), we recommend building your HTML5 webapp using [npm](https://npmjs.org/). Then, you can install this package using: 107 | 108 | npm install cardano-dapp-js 109 | 110 | ### From Source 111 | 112 | First, clone this repository and install all dependencies: 113 | 114 | npm install 115 | 116 | Then, create the ability for npm to link on your local system: 117 | 118 | npm link 119 | 120 | Finally, go to your project directory and use `npm link` to create a symlink: 121 | 122 | cd $PROJECT_DIR/node_modules 123 | npm link cardano-dapp-js 124 | 125 | When you build your web application, you will be using a locally symlinked version of this library. 126 | 127 | ### Static Javascript Linkage 128 | 129 | A compiled version of this library is generated with each release using webpack. To link it directly from your HTML code, please use (and optionally include the integrity attribute): 130 | ```html 131 | 132 | ``` 133 | 134 | ### Compatibility 135 | 136 | This library is built to be compatible with any wallet that is aligned to [CIP-0030](https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0030/) (the full list can be found at [cardano-caniuse.io](https://www.cardano-caniuse.io/)). 137 | 138 | While not required, we highly recommend integrating this library with [Lucid by Berry-Pool](https://github.com/Berry-Pool/lucid) for creating and submitting transactions on Cardano. 139 | 140 | ## Testing 141 | 142 | TBA 143 | 144 | ## Documentation 145 | 146 | All documentation relevant to this project is contained in this README. For community support, please visit the [WildTangz Discord](https://discord.gg/wildtangz). 147 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import {Lucid, Blockfrost, C as LCore} from 'lucid-cardano'; 2 | import Toastify from 'toastify-js'; 3 | 4 | import {coreToUtxo, fromHex} from 'lucid-cardano'; 5 | 6 | import { 7 | init as walletConnectInit, 8 | connect as walletConnect, 9 | getActiveConnector as getActiveWalletConnectConnector, 10 | cardanoMainnetWalletConnect, 11 | WalletConnectConnector 12 | } from '@dcspark/adalib'; 13 | 14 | export {Lucid, Blockfrost}; 15 | 16 | export class CardanoDApp { 17 | 18 | static #CARDANO_CHAINS = [ 19 | cardanoMainnetWalletConnect() 20 | ]; 21 | 22 | static SUPPORTED_WALLETS = { 23 | begin: { 24 | cip30name: 'begin', 25 | img: 'https://begin.is/favicon/favicon.ico' 26 | }, 27 | eternl: { 28 | cip30name: 'eternl', 29 | img: 'https://ccvault.io/icons/favicon-128x128.png' 30 | }, 31 | flint: { 32 | cip30name: 'flint', 33 | img: 'https://flint-wallet.com/favicon.png' 34 | }, 35 | gero: { 36 | cip30name: 'gerowallet', 37 | img: 'https://gerowallet.io/assets/img/logo2.ico' 38 | }, 39 | lace: { 40 | cip30name: 'lace', 41 | img: 'https://www.lace.io/favicon-32x32.png' 42 | }, 43 | nami: { 44 | cip30name: 'nami', 45 | img: 'https://namiwallet.io/favicon-32x32.png' 46 | }, 47 | typhon: { 48 | cip30name: 'typhoncip30', 49 | img: 'https://typhonwallet.io/assets/typhon.svg', 50 | }, 51 | vespr: { 52 | cip30name: 'vespr', 53 | img: 'https://vespr.xyz/favicon.png' 54 | }, 55 | WalletConnect: { 56 | cip30name: 'WalletConnect', 57 | img: 'https://cloud.walletconnect.com/favicon.ico' 58 | }, 59 | yoroi: { 60 | cip30name: 'yoroi', 61 | img: 'https://yoroi-wallet.com/assets/favicon.png' 62 | } 63 | } 64 | 65 | static #TIMEOUT_MS = 1000; 66 | 67 | static #toastWalletError(error) { 68 | var message = error.toString(); 69 | if (error.constructor === Object) { 70 | message = JSON.stringify(error); 71 | } 72 | Toastify({text: `Wallet error occurred: ${message}`, duration: 3000}).showToast(); 73 | } 74 | 75 | static #isWalletSupported(walletName) { 76 | const walletCip30Name = CardanoDApp.SUPPORTED_WALLETS[walletName].cip30name; 77 | if (!(("cardano" in window) && (walletCip30Name in window.cardano))) { 78 | this.#toastWalletError(`Wallet '${walletName}' not integrated in your browser`); 79 | return false; 80 | } 81 | return true; 82 | } 83 | 84 | static async #enableWallet(walletName) { 85 | if (walletName === 'WalletConnect') { 86 | const connector = getActiveWalletConnectConnector(); 87 | const isStillConnected = await connector.isConnected(CardanoDApp.#TIMEOUT_MS); 88 | if (!isStillConnected) { 89 | await walletConnect(); 90 | } 91 | return connector.getConnectorAPI(); 92 | } 93 | const cip30name = CardanoDApp.SUPPORTED_WALLETS[walletName].cip30name; 94 | return window.cardano[cip30name].enable(); 95 | } 96 | 97 | static #configureWalletConnect(walletConnectInfo) { 98 | walletConnectInit(() => { 99 | return { 100 | connectors: [ 101 | new WalletConnectConnector({ 102 | relayerRegion: walletConnectInfo.relayerRegion, 103 | metadata: walletConnectInfo.metadata, 104 | autoconnect: walletConnectInfo.autoconnect, 105 | qrcode: true 106 | }) 107 | ], 108 | connectorName: WalletConnectConnector.connectorName(), 109 | chosenChain: cardanoMainnetWalletConnect() 110 | } 111 | }, walletConnectInfo.projectId); 112 | } 113 | 114 | constructor(containerId, walletConnectInfo) { 115 | this.containerId = containerId; 116 | this.#buildDropdownDom(); 117 | if (walletConnectInfo !== undefined) { 118 | CardanoDApp.#configureWalletConnect(walletConnectInfo); 119 | window.cardano.WalletConnect = walletConnectInfo; 120 | } 121 | this.#configureDropdownListeners(); 122 | } 123 | 124 | #buildDropdownDom() { 125 | var dropdownHtml = `'; 132 | document.querySelector(`#${this.containerId}`).innerHTML = dropdownHtml; 133 | } 134 | 135 | #configureDropdownListeners() { 136 | for (const wallet in CardanoDApp.SUPPORTED_WALLETS) { 137 | document.querySelector(`#${this.containerId}-${wallet}`).addEventListener("click", async e => { 138 | e && e.preventDefault(); 139 | await this.connectWallet(wallet); 140 | }); 141 | } 142 | } 143 | 144 | #getBannerEl() { 145 | return `${this.containerId}-header`; 146 | } 147 | 148 | async connectWallet(walletName) { 149 | if (!CardanoDApp.#isWalletSupported(walletName)) { 150 | return; 151 | } 152 | 153 | try { 154 | const wallet = await CardanoDApp.#enableWallet(walletName); 155 | const address = await wallet.getChangeAddress(); 156 | this.selectedWallet = walletName; 157 | this.#displayWallet(); 158 | Toastify({ 159 | text: `Successfully connected wallet ${address}!`, 160 | duration: 3000 161 | }).showToast(); 162 | window.postMessage({ 163 | type: "CARDANO_DAPP_JS_CONNECT", 164 | wallet: { provider: walletName, address: address } 165 | }, "*"); 166 | } catch (err) { 167 | CardanoDApp.#toastWalletError(err); 168 | } 169 | } 170 | 171 | #displayWallet() { 172 | if (this.isWalletConnected() && this.containerId) { 173 | document.querySelector(`#${this.#getBannerEl()}`).textContent = `Connected to ${this.selectedWallet}!`; 174 | } 175 | } 176 | 177 | getConnectedWallet() { 178 | if (this.selectedWallet === undefined) { 179 | throw 'No wallet connected to enable'; 180 | } 181 | return CardanoDApp.#enableWallet(this.selectedWallet); 182 | } 183 | 184 | async numPolicyAssets(policy) { 185 | const policyAssets = {}; 186 | const currentWallet = await this.getConnectedWallet(); 187 | const utxos = await currentWallet.getUtxos(); 188 | for (const utxoStr of utxos) { 189 | const utxoBytes = fromHex(utxoStr); 190 | const coreUtxo = LCore.TransactionUnspentOutput.from_bytes(utxoBytes); 191 | const utxo = coreToUtxo(coreUtxo) 192 | const assets = utxo.assets; 193 | for (const asset in assets) { 194 | if (asset.startsWith(policy)) { 195 | policyAssets[asset] = assets[asset]; 196 | } 197 | } 198 | } 199 | return Object.values(policyAssets).reduce((acc, amount) => acc + amount, 0n); 200 | } 201 | 202 | async walletMeetsTokenGate(tokenGateMap) { 203 | for (const policy in tokenGateMap) { 204 | const numPolicyAssets = await this.numPolicyAssets(policy); 205 | if (numPolicyAssets >= tokenGateMap[policy]) { 206 | return true; 207 | } 208 | } 209 | return false; 210 | } 211 | 212 | isWalletConnected() { 213 | return this.selectedWallet !== undefined; 214 | } 215 | 216 | } 217 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------