bitcoin-computer
Advanced tools
Comparing version 0.4.7-beta to 0.9.4-beta
{ | ||
"name": "bitcoin-computer", | ||
"version": "0.4.7-beta", | ||
"description": "Smart Contracts on Bitcoin", | ||
"main": "./bitcoin-computer.cjs.js", | ||
"version": "0.9.4-beta", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "BC_LOCAL_BBS=1 jest --config ./jest.config.json --runInBand" | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/bitcoin-computer/bitcoin-computer.git" | ||
}, | ||
"keywords": [ | ||
"Bitcoin", | ||
"Smart Contracts", | ||
"Javascript" | ||
], | ||
"author": "Clemens Ley", | ||
"license": "CC-BY-ND-3.0", | ||
"bugs": { | ||
"url": "https://github.com/bitcoin-computer/bitcoin-computer/issues" | ||
}, | ||
"homepage": "https://github.com/bitcoin-computer/bitcoin-computer#readme", | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"bitcoinsource": "^0.1.19", | ||
"node-localstorage": "^2.1.6" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.10.4", | ||
"@types/jest": "^26.0.4", | ||
"babel-jest": "^26.1.0", | ||
"jest": "^26.1.0", | ||
"jest-cli": "^26.1.0", | ||
"ts-jest": "^26.1.2" | ||
} | ||
"author": "", | ||
"license": "ISC" | ||
} |
244
README.md
@@ -1,243 +0,5 @@ | ||
<p align="center"> | ||
<img src="https://i.ibb.co/rMnRhvQ/logo-black-white-transparent-small.png" alt="bitcoin-computer-logo" border="0" style="width:100px;height:100px;"/> | ||
</p> | ||
<h2>Bitcoin Computer</h2> | ||
# Bitcoin Computer | ||
THIS REPO HAVE BEEN MOVED TO BITCOIN COMPUTER's MONO REPO. | ||
BitcoinComputer is a Javascript library for running smart contracts on Bitcoin. | ||
## Examples | ||
We give a few examples of smart contracts. See [bitcoincomputer.io](http://bitcoincomputer.io/) for more documentation. | ||
### Non-Fungible Token | ||
A non-fungible token is a Javascript class with some state. It has a constructor to initialize the state, a function to update the state, and a function to send the token to another user. The ``_owners`` controlls who may update the object. For more information see the [docs](https://docs.bitcoincomputer.io/key-concepts-1#data-ownership). | ||
```` | ||
class Token { | ||
constructor(state) { | ||
this.state = state | ||
} | ||
setState(state) { | ||
this.state = state | ||
} | ||
send(to) { | ||
this._owners = [to] | ||
} | ||
} | ||
```` | ||
You can deploy a token and send it to another user by running the following code. | ||
```` | ||
// create Bitcoin Computer wallet | ||
const computer = new Computer({ | ||
seed: 'replace this seed', // your BIP39 seed | ||
chain: 'BSV' // BSV or BCH | ||
}) | ||
// deploy the smart contract | ||
const token = await computer.new(Token, ['some state']) | ||
// send token to another user | ||
const publicKey = '03223d...46d06c8dfe' | ||
await token.send(publicKey) | ||
```` | ||
### Fungible Token | ||
A fungible token consists of several instances of the ``Coin`` class. A coin object can hold a number of tokens. A coin can be split into two coins using the ``send`` function and the smart contract guarantees that no new tokens are created. | ||
```` | ||
class Coin { | ||
constructor(supply, to) { | ||
this.tokens = supply | ||
this._owners = [to] | ||
} | ||
send(amount, to) { | ||
if(this.tokens < amount) throw new Error('insufficient funds') | ||
this.tokens -= amount | ||
return new Coin(amount, to) | ||
} | ||
} | ||
```` | ||
### Beyond Tokens | ||
While Bitcoin Computer can create many variants of custom tokens, it can do much more than that. It's a tool to make web application development easy. Below we show how a chat can be built on the Bitcoin Computer. The smart contract persists the objects and thus no separate database is needed to build an application. | ||
```` | ||
class Chat { | ||
constructor() { | ||
this.messages = [] | ||
} | ||
invite(publicKey) { | ||
this._owners.push(publicKey) | ||
} | ||
post(messages) { | ||
this.messages.push(message) | ||
} | ||
} | ||
```` | ||
## Getting Started | ||
### Run the Tests | ||
The easiest way to get started is to run the tests. In an empty directory run | ||
```` | ||
git clone git@github.com:bitcoin-computer/computer.git | ||
cd computer | ||
npm install | ||
npm test | ||
```` | ||
If you get an error "Insuffienct balance in \<your address\>" send free testnet coins to \<your address\> as explained in | ||
<a href="#fund-your-computer">Fund Your Computer</a> below. | ||
### Run in Node | ||
In an empty directory run ``npm init -y && npm i -s bitcoin-computer``. Create file ``index.mjs`` as shown below. | ||
``` | ||
import { Computer } from 'bitcoin-computer' | ||
// the smart contract | ||
class Counter { | ||
constructor() { this.n = 0 } | ||
inc() { this.n += 1 } | ||
} | ||
// run the smart contract | ||
;(async () => { | ||
const seed = 'replace this seed' | ||
const chain = 'BSV' | ||
const network = 'testnet' | ||
const computer = new Computer({ seed, chain, network }) | ||
const counter = await computer.new(Counter, []) | ||
await counter.inc() | ||
console.log(counter) | ||
})() | ||
``` | ||
Run the code using | ||
```` | ||
node --experimental-modules index.mjs | ||
```` | ||
If you get an error "Insuffienct funds in \<your address\>" have a look at the secion <a href="#fund-your-computer">Fund Your Computer</a> below. Run the code again after funding the wallet and you will see: | ||
``` | ||
Counter { | ||
n: 1, | ||
_id: '83553f27c9e4651323f1ebb...', | ||
_rev: '290923708ca56ea448dd67...' | ||
} | ||
``` | ||
### Run in the Browser | ||
Create file `.babelrc` | ||
```` | ||
{ | ||
"presets": [ "@babel/preset-env" ], | ||
"plugins": [ [ "@babel/transform-runtime" ] ] | ||
} | ||
```` | ||
Create file ``index.html`` | ||
``` | ||
<html> | ||
<body> | ||
<div id='el'></div> | ||
<script src="./index.js"></script> | ||
</body> | ||
</html> | ||
``` | ||
Create file ``index.js`` | ||
``` | ||
import { Computer } from 'bitcoin-computer' | ||
class Counter { | ||
constructor() { this.n = 0 } | ||
inc() { this.n += 1 } | ||
} | ||
;(async () => { | ||
const seed = 'replace this seed' | ||
const chain = 'BSV' | ||
const network = 'testnet' | ||
const computer = new Computer({ seed, chain, network }) | ||
const counter = await computer.new(Counter, []) | ||
document.getElementById("el").innerHTML = `Counter is ${counter.n}` | ||
await counter.inc() | ||
document.getElementById("el").innerHTML = `Counter is ${counter.n}` | ||
})() | ||
``` | ||
Run the following in an empty directory | ||
``` | ||
npm init -y | ||
npm i -s bitcoin-computer | ||
npm i -g parcel-bundler | ||
npm i -s @babel/runtime | ||
npm i -d @babel/plugin-transform-runtime | ||
parcel index.html | ||
``` | ||
Open your browser at `http://localhost:1234`. See the instructions for how to configure your own seed phrase and how to fund the computer in the sections below. | ||
### Configure Your Seed Phrase | ||
By default the bitcoin computer object uses the pass phrase "replace this seed" to initialize the wallet. If you want to use your own seed phrase, replace the string "replace this seed" with any bip39 compatible seed phrase or generate a new one [here](https://iancoleman.io/bip39/). | ||
### Fund Your Computer | ||
If you get an error message "Insufficient balance in address \<your_address\>" you need to fund the wallet inside the computer object. You can get free testnet coins from a [Bitcoin SV faucet](https://faucet.bitcoincloud.net/) or a [Bitcoin Cash Faucet](https://faucet.fullstack.cash/) and send them to \<your_address\>. | ||
## Documentation | ||
You can find more information in the [Bitcoin Computer Docs](https://bitcoin-computer.gitbook.io/docs/) | ||
## Getting Help | ||
If you have any issues ask a question in the [Telegram Group](https://t.me/joinchat/FMrjOUWRuUkNuIt7zJL8tg) or create an issue on [Github](https://github.com/bitcoin-computer/computer/issues). | ||
## Licence | ||
Code it licenced under [Attribution-NoDerivs 3.0 Unported](https://creativecommons.org/licenses/by-nd/3.0/). You are free to: Share, copy, and redistribute the material in any medium or format | ||
for any purpose, even commercially under the following terms: | ||
* Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. | ||
* NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. | ||
This is a human-readable summary of (and not a substitute for) the [license](https://creativecommons.org/licenses/by-nd/3.0/legalcode). | ||
## Beta Notice | ||
We are in beta to indicate that there are known security vulnerabilities. Our priority is to fix all security related issues. Once done we will remove the beta tag and start a bug bounty program to find all remaining bugs. | ||
## Breaking Changes | ||
* 0.4.3-beta -> 0.4.4-beta: We have switched to a named export so you'll have to write ``import { Computer } from 'bitcoin-computer`` instead of ``import Computer from 'bitcoin-computer`` | ||
* x.x.x-alpha.x -> 0.3.0-beta: Smart contracts deployed in an alpha version do not work in the beta version. | ||
* 0.3.0-alpha.10 -> 0.3.0-alpha.11: We changed the default wallet derivation path from the empty string to "m/44'/0'/0'/0". To use funds from a wallet created in version 0.3.0-alpha.10 or before, set the ```path``` option to the empty string when creating a computer object. | ||
https://github.com/bitcoin-computer/monorepo |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
0
0
0
100
1
2
349
2
0
2
6
- Removedaxios@^0.18.0
- Removedbitcoinsource@^0.1.19
- Removednode-localstorage@^2.1.6
- Removedaxios@0.18.1(transitive)
- Removedbig-integer@1.6.361.6.52(transitive)
- Removedbitcoinsource@0.1.20(transitive)
- Removedbn.js@4.12.15.2.1(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedcashaddrjs@0.4.4(transitive)
- Removedelliptic@6.6.1(transitive)
- Removedfollow-redirects@1.5.10(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedlodash@4.17.21(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removednode-localstorage@2.2.1(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedslide@1.1.6(transitive)
- Removedunorm@1.6.0(transitive)
- Removedwrite-file-atomic@1.3.4(transitive)