Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions wallet-wasm2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "wallet-wasm2"
version = "0.1.0"
authors = [ "Nicolas Di Prima <nicolas.diprima@iohk.io>"
, "Vincent Hanquez <vincent.hanquez@iohk.io>"
]
description = "JS/Wasm binding for Cardano's Wallet rust library."
repository = "https://github.com/input-output-hk/js-cardano-wasm"
license = "MIT"

[lib]
crate-type = ["cdylib"]

[dependencies]
raw_cbor = { path = "../rust/cbor" }
wallet-crypto = { path = "../rust/wallet-crypto" }
wasm-bindgen = "0.2"
18 changes: 18 additions & 0 deletions wallet-wasm2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright (c) 2018 IOHK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 changes: 59 additions & 0 deletions wallet-wasm2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Wallet Wasm (using wasm-bindgen)

This is an experimental js/wasm/rust binding of
[cardano-rust](https://github.com/input-output-hk/rust-cardano)'s `wallet-crypto`
crate. It uses the binding generator tool
[`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) and
[`wasm-pack`](https://github.com/rustwasm/wasm-pack).

## Generate npm package

We use `wasm-pack` to generate a NPM package:

1. [install `rustup`](https://www.rust-lang.org/en-US/install.html):
```
$ curl https://sh.rustup.rs -sSf | sh
```
2. install `wasm-pack`:
```
$ cargo install wasm-pack
```
3. generate it all:
```
$ wasm-pack init .
```

## Example

see [js-test](./js-test) for an example of use:

```
$ cd js-test
$ npm install
$ npm run serve
```

open your browser to: http://localhost:8080/index.html and look at the JSON logs.

## features

Here we strive to remove some of the hand-written functions that came with limitations
regarding: allocating more memory than needed for output, using JSON
RPC style...

Instead, we expose a collection of objects:

- private key;
- public key;
- payload;

```js
const loadModule = import('wallet-wasm2/wallet_wasm2.js');

loadModule.then(Cardano => {
const MNEMONICS = "town refuse ribbon antenna average enough crumble ice fashion giant question glance";

// retrieve a root private key
let root_xprv = Cardano.XPrv.from_daedalus_mnemonics(MNEMONICS);
});
```
11 changes: 11 additions & 0 deletions wallet-wasm2/js-test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>cardano wallet example</title>
</head>
<body>
<script src="./index.js"></script>
</body>
</html>

20 changes: 20 additions & 0 deletions wallet-wasm2/js-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const loadModule = import("wallet-wasm2/wallet_wasm2.js");

loadModule.then(Cardano => {
const MNEMONICS = "town refuse ribbon antenna average enough crumble ice fashion giant question glance";
const PATH = [0x8000000, 0x8000000];

console.log("retrieving root_xprv from a daedalus mnemonic", MNEMONICS);
let root_xprv = Cardano.XPrv.from_daedalus_mnemonics(MNEMONICS);
let root_xpub = root_xprv.public();

console.log("daedalus derivation from derivation path", PATH);
let xprv = root_xprv;
PATH.forEach(index => xprv = xprv.derive_v1(index));
let xpub = xprv.public();
console.log("daedalus payload");
let payload = Cardano.Payload.new(root_xpub, PATH);

let addr = xpub.to_adddress_with_payload(payload);
console.log("Daedalus Address", addr.to_base58());
});
13 changes: 13 additions & 0 deletions wallet-wasm2/js-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scripts": {
"serve": "webpack-dev-server"
},
"dependencies": {
"wallet-wasm2": "file:../pkg"
},
"devDependencies": {
"webpack": "^4.0.1",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.0"
}
}
9 changes: 9 additions & 0 deletions wallet-wasm2/js-test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require('path');
module.exports = {
entry: "./index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.js",
},
mode: "development"
};
Loading