Skip to content

Commit

Permalink
add typescript example (Emurgo#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt authored Jun 27, 2020
1 parent db65ead commit c72821c
Show file tree
Hide file tree
Showing 11 changed files with 2,936 additions and 663 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
rust/target
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.18.1
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,32 @@ Here are the location of the original [CDDL](http://cbor.io/tools.html) specific
- Byron: [link](https://github.com/input-output-hk/cardano-ledger-specs/blob/master/byron/cddl-spec/byron.cddl)
- Shelley: [link](https://github.com/input-output-hk/cardano-ledger-specs/blob/master/shelley/chain-and-ledger/cddl-spec/shelley.cddl#L72)

# Building

If you need to install Rust, do the following:
```
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo 'export PATH=$HOME/.cargo/bin/:$PATH' >> $BASH_ENV
rustup install stable
rustup target add wasm32-unknown-unknown --toolchain stable
```

To build this repository, do the following:
```
git submodule update --init --recursive
nvm install && nvm use
npm run rust:build
npm install
```

# Testing

```
npm run js:test
```

# Generating CDDL instances

First you need to install `cddl`
```
sudo apt install ruby
Expand Down
1,656 changes: 1,033 additions & 623 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 31 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
{
"name": "cardano-serialization-lib",
"version": "0.0.0",
"version": "0.1.0",
"description": "processing Haskell Shelley testnet",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"lint": "eslint \"src/**/*.ts\"",
"test:watch": "mocha -w",
"dev": "rimraf ./dist && node ./src/index.ts",
"preinstall": "cd rust; wasm-pack build --target=nodejs; wasm-pack pack; cd .."
"rust:build": "cd rust; wasm-pack build --target=nodejs; wasm-pack pack; cd ..",
"rust:test": "cd rust; cargo test; cd ..",
"js:build": "rm -rf dist && tsc",
"js:dev": "rimraf ./dist && node ./src/index.ts",
"js:lint": "eslint \"src/**/*.ts\"",
"js:test:watch": "mocha -w",
"js:test": "mocha",
"js:flowgen": "npm run rust:build && flowgen ./rust/pkg/cddl_lib.d.ts -o ./rust/pkg/cddl_lib.js.flow --add-flow-header"
},
"author": "",
"husky": {
"hooks": {
"pre-push": "npm run rust:test && npm run js:lint && npm run js:test"
}
},
"author": "EMURGO",
"license": "MIT",
"dependencies": {
"io-ts": "2.1.0",
"cbor": "5.0.1",
"io-ts": "2.2.6",
"cbor": "5.0.2",
"@types/cbor": "5.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "2.19.2",
"@typescript-eslint/parser": "2.19.2",
"eslint": "6.8.0",
"@types/mocha": "7.0.1",
"@types/chai": "4.2.9",
"source-map-support": "0.5.16",
"ts-node": "8.6.2",
"mocha": "7.0.1",
"typescript": "3.7.5",
"rust-lib": "file:rust/pkg"
"@types/chai": "4.2.11",
"@types/mocha": "7.0.2",
"@typescript-eslint/eslint-plugin": "3.4.0",
"@typescript-eslint/parser": "3.4.0",
"bip39": "3.0.2",
"chai": "4.2.0",
"eslint": "7.3.1",
"flowgen": "1.11.0",
"husky": "4.2.5",
"mocha": "8.0.1",
"rust-lib": "file:rust/pkg",
"source-map-support": "0.5.19",
"ts-node": "8.10.2",
"typescript": "3.9.5"
}
}
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ hex = "0.4.0"
js-sys = "0.3.24"
rand_os = { version = "0.1", features = ["wasm-bindgen"] }

# The default can't be compiled to wasm, so it's necessary to use either the 'nightly'
# feature or this one
clear_on_drop = { version = "0.2", features = ["no_cc"] }

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
1 change: 1 addition & 0 deletions rust/pkg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
Loading

0 comments on commit c72821c

Please sign in to comment.