Skip to content

Commit 2c55908

Browse files
committed
Merge feat/support-node-v11 into master
2 parents 121e207 + eb6e8d3 commit 2c55908

33 files changed

Lines changed: 373 additions & 179 deletions

docs/docs/hydra-js-client/abort.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ A `Promise` that resolves to an object containing information about the abort pr
2222
const { KuberHydraApiProvider } = require("kuber-client");
2323

2424
async function main() {
25-
const hydra = new KuberHydraApiProvider("http://localhost:8081"); // Replace with your Hydra API URL
25+
const hydra = new KuberHydraApiProvider("http://localhost:8082");
2626

2727
try {
2828
console.log("Aborting Hydra head initialization...");
29-
const result = await hydra.abort(true); // Wait for abort to complete
30-
console.log("Hydra head aborted:", result);
29+
await hydra.abort(true); // Wait for abort to complete
30+
const headState = await hydra.queryHeadState();
31+
console.log("Hydra head state:", headState.state);
3132
} catch (error) {
3233
console.error("Error aborting Hydra head:", error);
3334
}

docs/docs/hydra-js-client/buildTx.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,34 @@ A `Promise` that resolves to a `CommonTxObject` representing the built transacti
1919

2020
## Example
2121

22-
```javascript
23-
const { KuberHydraApiProvider } = require("kuber-client");
22+
```typescript
23+
import { readFileSync } from "fs";
24+
import { CardanoKeyAsync } from "libcardano";
25+
import { ShelleyWallet, SimpleCip30Wallet } from "libcardano-wallet";
26+
import { KuberHydraApiProvider } from "kuber-client";
2427

2528
async function main() {
26-
const hydra = new KuberHydraApiProvider("http://localhost:8081"); // Replace with your Hydra API URL
29+
const hydra = new KuberHydraApiProvider("http://localhost:8082");
30+
const signingKey = await CardanoKeyAsync.fromCardanoCliJson(
31+
JSON.parse(readFileSync("../../kuber-hydra/devnet/credentials/alice-funds.sk", "utf-8")),
32+
);
33+
const wallet = new SimpleCip30Wallet(hydra, hydra, new ShelleyWallet(signingKey), 0);
34+
const walletAddress = (await wallet.getChangeAddress()).toBech32();
2735

2836
const transaction = {
29-
outputs: [
30-
{
31-
address: "addr_test1qr...", // Recipient address
32-
value: {
33-
lovelace: "500000", // 0.5 ADA
34-
},
35-
},
36-
],
37-
// Add other transaction parameters as needed, e.g., inputs, metadata
37+
selections: [walletAddress],
38+
outputs: [{ address: walletAddress, value: "1_000_000" }],
39+
changeAddress: walletAddress,
3840
};
3941

4042
try {
4143
console.log("Building transaction...");
4244
const builtTx = await hydra.buildTx(transaction, true); // Submit the transaction
43-
console.log("Built transaction:", builtTx);
45+
console.log("Transaction hash:", builtTx.hash);
4446
} catch (error) {
4547
console.error("Error building transaction:", error);
4648
}
4749
}
4850

4951
main();
50-
```
52+
```

docs/docs/hydra-js-client/close.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ A `Promise` that resolves to an object containing information about the close pr
2222
const { KuberHydraApiProvider } = require("kuber-client");
2323

2424
async function main() {
25-
const hydra = new KuberHydraApiProvider("http://localhost:8081"); // Replace with your Hydra API URL
25+
const hydra = new KuberHydraApiProvider("http://localhost:8082");
2626

2727
try {
2828
console.log("Closing Hydra head...");
29-
const result = await hydra.close(true); // Wait for closure to complete
30-
console.log("Hydra head closed:", result);
29+
await hydra.close(true); // Wait for closure to complete
30+
const headState = await hydra.queryHeadState();
31+
console.log("Hydra head state:", headState.state);
3132
} catch (error) {
3233
console.error("Error closing Hydra head:", error);
3334
}

docs/docs/hydra-js-client/commit.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,35 @@ A `Promise` that resolves to a `CommonTxObject` representing the commitment tran
1919

2020
## Example
2121

22-
```javascript
23-
const { KuberHydraApiProvider } = require("kuber-client");
22+
```typescript
23+
import { readFileSync } from "fs";
24+
import { CardanoKeyAsync, Value } from "libcardano";
25+
import { ShelleyWallet, SimpleCip30Wallet } from "libcardano-wallet";
26+
import { UTxO } from "libcardano/serialization";
27+
import { KuberHydraApiProvider } from "kuber-client";
2428

2529
async function main() {
26-
const hydra = new KuberHydraApiProvider("http://localhost:8081"); // Replace with your Hydra API URL
27-
28-
const utxosToCommit = {
29-
utxos: [
30-
{
31-
txIn: "yourTxHash#0", // Replace with a valid UTxO
32-
value: {
33-
lovelace: "1000000", // 1 ADA
34-
},
35-
},
36-
],
37-
};
30+
const hydra = new KuberHydraApiProvider("http://localhost:8082");
31+
const signingKey = await CardanoKeyAsync.fromCardanoCliJson(
32+
JSON.parse(readFileSync("../../kuber-hydra/devnet/credentials/alice-funds.sk", "utf-8")),
33+
);
34+
const wallet = new SimpleCip30Wallet(hydra, hydra, new ShelleyWallet(signingKey), 0);
35+
const walletAddress = (await wallet.getChangeAddress()).toBech32();
36+
37+
const l1Utxos = await hydra.l1Api.queryUTxOByAddress(walletAddress);
38+
const selectedUtxo = l1Utxos.find((utxo: UTxO) => utxo.txOut.value.greaterThan(Value.fromString("4A")));
39+
if (!selectedUtxo) {
40+
throw new Error(`Alice has no L1 UTxO larger than 4 ADA at ${walletAddress}`);
41+
}
42+
43+
const txIn = `${selectedUtxo.txIn.txHash.toString("hex")}#${selectedUtxo.txIn.index}`;
3844

3945
try {
4046
console.log("Committing UTxOs...");
41-
const result = await hydra.commit(utxosToCommit, true); // Submit the transaction
42-
console.log("Commit transaction:", result);
47+
const commitTx = await hydra.commit({ utxos: [txIn] });
48+
const signedTx = await wallet.signTx(commitTx.cborHex);
49+
await hydra.l1Api.submitTx(signedTx.transaction.toBytes().toString("hex"));
50+
console.log("Commit transaction hash:", commitTx.hash);
4351
} catch (error) {
4452
console.error("Error committing UTxOs:", error);
4553
}

docs/docs/hydra-js-client/decommit.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,33 @@ A `Promise` that resolves to a `DecommitResult` object containing information ab
1919

2020
## Example
2121

22-
```javascript
23-
const { KuberHydraApiProvider } = require("kuber-client");
22+
```typescript
23+
import { readFileSync } from "fs";
24+
import { CardanoKeyAsync } from "libcardano";
25+
import { ShelleyWallet, SimpleCip30Wallet } from "libcardano-wallet";
26+
import { KuberHydraApiProvider } from "kuber-client";
2427

2528
async function main() {
26-
const hydra = new KuberHydraApiProvider("http://localhost:8081"); // Replace with your Hydra API URL
27-
28-
// First, create the decommit transaction
29-
const utxoToDecommit = "yourTxHash#0"; // Replace with a valid UTxO from the head
30-
const decommitTx = await hydra.createDecommitTx(utxoToDecommit);
29+
const hydra = new KuberHydraApiProvider("http://localhost:8082");
30+
const signingKey = await CardanoKeyAsync.fromCardanoCliJson(
31+
JSON.parse(readFileSync("../../kuber-hydra/devnet/credentials/alice-funds.sk", "utf-8")),
32+
);
33+
const wallet = new SimpleCip30Wallet(hydra, hydra, new ShelleyWallet(signingKey), 0);
34+
const walletAddress = (await wallet.getChangeAddress()).toBech32();
35+
36+
const headUtxos = await hydra.queryUTxOByAddress(walletAddress);
37+
if (headUtxos.length === 0) {
38+
throw new Error(`Alice has no UTxO in the Hydra head at ${walletAddress}`);
39+
}
3140

32-
// Then, sign the transaction (assuming you have a wallet setup)
33-
// const signedTx = await wallet.signTx(decommitTx.cborHex); // Replace 'wallet' with your actual wallet instance
34-
const signedTxCbor = decommitTx.cborHex; // For demonstration, using unsigned CBOR
41+
const txIn = `${headUtxos[0].txIn.txHash.toString("hex")}#${headUtxos[0].txIn.index}`;
42+
const decommitTx = await hydra.createDecommitTx(txIn);
43+
const signedTx = await wallet.signTx(decommitTx.cborHex);
3544

3645
try {
3746
console.log("Decommitting UTxOs...");
38-
const result = await hydra.decommit(signedTxCbor, true); // Pass the signed transaction CBOR and wait
39-
console.log("Decommit result:", result);
40-
console.log("Decommit transaction hash:", result.decommitTx.txHash);
47+
const result = await hydra.decommit(signedTx.transaction.toBytes().toString("hex"), true);
48+
console.log("Decommit transaction hash:", result.decommitTx.hash);
4149
} catch (error) {
4250
console.error("Error decommitting UTxOs:", error);
4351
}

docs/docs/hydra-js-client/examples/burning-native-tokens.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function runBurnNativeTokensExample() {
3333
const signingKey = await CardanoKeyAsync.fromCardanoCliJson(
3434
JSON.parse(
3535
readFileSync(
36-
process.env.HOME + "/.cardano/preview/hydra-0/credentials/funds.sk",
36+
"../../kuber-hydra/devnet/credentials/alice-funds.sk",
3737
"utf-8",
3838
),
3939
),
@@ -54,7 +54,7 @@ async function runBurnNativeTokensExample() {
5454
{
5555
script: {
5656
type: "sig",
57-
keyHash: shelleyWallet.paymentKey.pkh.toString("hex"),
57+
keyHash: shelleyWallet.paymentKey.publicKeyHash().toString("hex"),
5858
},
5959
amount: {
6060
Token1: -1,
@@ -65,7 +65,7 @@ async function runBurnNativeTokensExample() {
6565
};
6666

6767
const result = await hydra.buildAndSubmitWithWallet(wallet, burnTx);
68-
console.log("Burn transaction submitted:", result.transaction.toBytes().toString("hex"));
68+
console.log("Burn transaction hash:", result.transaction.hash().toString("hex"));
6969
}
7070

7171
runBurnNativeTokensExample().catch((err) => {

docs/docs/hydra-js-client/examples/commiting-utxos-to-hydra.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Kuber Hydra Client can be integrated with a CIP-30 compatible wallet to sign
1111

1212
- Node.js environment
1313
- `libcardano` and `libcardano-wallet` installed.
14-
- Access to a running Hydra node and its credentials (e.g., `node.addr`, `funds.sk`).
14+
- Access to a running Hydra node and its credentials (e.g., `node.addr`, `alice-funds.sk`).
1515

1616
This example demonstrates how to set up a `SimpleCip30Wallet` and use it to sign and submit a transaction to a Hydra Head.
1717

@@ -22,20 +22,32 @@ import { ShelleyWallet, SimpleCip30Wallet } from "libcardano-wallet";
2222
import { KuberHydraApiProvider } from "kuber-client"; // Adjust path as needed
2323
import { UTxO } from "libcardano/serialization";
2424

25+
function formatUtxo(utxo: UTxO) {
26+
return {
27+
txIn: `${utxo.txIn.txHash.toString("hex")}#${utxo.txIn.index}`,
28+
address: utxo.txOut.address.toBech32(),
29+
lovelace: utxo.txOut.value.lovelace.toString(),
30+
assetPolicies: Object.keys(utxo.txOut.value.multiassets ?? {}).length,
31+
};
32+
}
33+
2534
async function runCip30CommitExample() {
2635
// Initialize Hydra API Provider
27-
const hydra = new KuberHydraApiProvider("http://172.31.6.1:8082"); // Replace with your Hydra node URL
36+
const hydra = new KuberHydraApiProvider("http://localhost:8082");
2837

2938
// Load node address and test wallet signing key
3039
const node_addr_path = process.env.HOME + "/.cardano/preview/hydra-0/credentials/node.addr";
3140
const nodeAddr = readFileSync(node_addr_path).toString("utf-8").trim();
3241

3342
// Setup Shelley wallet
3443
const testWalletSigningKey = await CardanoKeyAsync.fromCardanoCliJson(
35-
JSON.parse(readFileSync(process.env.HOME + "/.cardano/preview/hydra-0/credentials/funds.sk", "utf-8")),
44+
JSON.parse(readFileSync("../../kuber-hydra/devnet/credentials/alice-funds.sk", "utf-8")),
3645
);
3746
const shelleyWallet = new ShelleyWallet(testWalletSigningKey);
38-
console.log("Wallet", shelleyWallet.toJSON());
47+
console.table({
48+
paymentKeyHash: shelleyWallet.paymentKey.publicKeyHash().toString("hex"),
49+
networkId: 0,
50+
});
3951

4052
// Create SimpleCip30Wallet instance
4153
// The first two arguments are for the L1 API provider and the Hydra API provider, respectively.
@@ -66,10 +78,11 @@ async function runCip30CommitExample() {
6678

6779
const txIn = selectedUtxos[0].txIn;
6880
const utxoToCommit = [`${txIn.txHash.toString("hex")}#${txIn.index}`];
81+
console.table(selectedUtxos.map(formatUtxo));
6982

7083
// Build the commit transaction using Hydra API
7184
const commitResult = await hydra.commit({ utxos: utxoToCommit });
72-
console.log("Transaction to be signed:", commitResult.hash);
85+
console.log("Commit transaction hash:", commitResult.hash);
7386

7487
// Sign the transaction using the CIP-30 wallet
7588
const signResult = await cip30Wallet.signTx(commitResult.cborHex);

docs/docs/hydra-js-client/examples/devnet-cluster.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ This tutorial shows how to use `HydraTestCluster` from `kuber-client` to control
1212
- Local devnet is running (`cardano-node`, `hydra-node-{1,2,3}`, and `kuber-hydra-{1,2,3}`).
1313
- Devnet credentials exist in `kuber-hydra/devnet/credentials`.
1414
- You can reach relay endpoints:
15-
- `http://localhost:8082` (alice)
16-
- `http://localhost:8083` (bob)
17-
- `http://localhost:8084` (carol)
15+
- `http://localhost:8082` (alice)
16+
- `http://localhost:8083` (bob)
17+
- `http://localhost:8084` (carol)
1818

1919
## 1) Configure cluster participants
2020

@@ -38,20 +38,20 @@ const cluster = new HydraTestCluster();
3838

3939
cluster.addParticipantConfig(
4040
"http://localhost:8082",
41-
"../kuber-hydra/devnet/credentials/alice-funds.sk",
42-
"../kuber-hydra/devnet/credentials/alice-hydra.sk"
41+
"../../kuber-hydra/devnet/credentials/alice-funds.sk",
42+
"../../kuber-hydra/devnet/credentials/alice-hydra.sk"
4343
);
4444

4545
cluster.addParticipantConfig(
4646
"http://localhost:8083",
47-
"../kuber-hydra/devnet/credentials/bob-funds.sk",
48-
"../kuber-hydra/devnet/credentials/bob-hydra.sk"
47+
"../../kuber-hydra/devnet/credentials/bob-funds.sk",
48+
"../../kuber-hydra/devnet/credentials/bob-hydra.sk"
4949
);
5050

5151
cluster.addParticipantConfig(
5252
"http://localhost:8084",
53-
"../kuber-hydra/devnet/credentials/carol-funds.sk",
54-
"../kuber-hydra/devnet/credentials/carol-hydra.sk"
53+
"../../kuber-hydra/devnet/credentials/carol-funds.sk",
54+
"../../kuber-hydra/devnet/credentials/carol-hydra.sk"
5555
);
5656
```
5757

@@ -79,9 +79,11 @@ async function runClusterFlow(cluster) {
7979
const bobHydra = bob.getKuberHydraApiProvider();
8080
const carolHydra = carol.getKuberHydraApiProvider();
8181

82-
console.log("Alice head:", await aliceHydra.queryHeadState());
83-
console.log("Bob head:", await bobHydra.queryHeadState());
84-
console.log("Carol head:", await carolHydra.queryHeadState());
82+
console.table([
83+
{ participant: "alice", state: (await aliceHydra.queryHeadState()).state },
84+
{ participant: "bob", state: (await bobHydra.queryHeadState()).state },
85+
{ participant: "carol", state: (await carolHydra.queryHeadState()).state },
86+
]);
8587

8688
await cluster.resetClusterToClosedState({ fanoutReady: true });
8789
await aliceHydra.fanout(true);

docs/docs/hydra-js-client/examples/full-end-to-end-example.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ The script targets three relays:
128128

129129
Signing keys are loaded from:
130130

131-
- `kuber-hydra/devnet/credentials/alice-hydra.sk`
132-
- `kuber-hydra/devnet/credentials/bob-hydra.sk`
133-
- `kuber-hydra/devnet/credentials/carol-hydra.sk`
131+
- `kuber-hydra/devnet/credentials/alice-funds.sk`
132+
- `kuber-hydra/devnet/credentials/bob-funds.sk`
133+
- `kuber-hydra/devnet/credentials/carol-funds.sk`
134134

135135
### Deterministic start
136136

@@ -218,7 +218,7 @@ import { UTxO } from "libcardano/serialization";
218218

219219
// Set your work directory and paths according to your local setup.
220220
// This example assumes a specific structure for the devnet, so adjust as necessary for your environment.
221-
const WORK_DIR = process.env.HOME + "/work/kuber/kuber-hydra/devnet";
221+
const WORK_DIR = "../../kuber-hydra/devnet";
222222

223223
const hydraAlice = new KuberHydraApiProvider("http://localhost:8082");
224224
const hydraBob = new KuberHydraApiProvider("http://localhost:8083");
@@ -237,9 +237,9 @@ type PartyRuntime = PartyConfig & {
237237
};
238238

239239
const PARTIES: PartyConfig[] = [
240-
{ name: "Alice", skPath: WORK_DIR + "/credentials/alice-hydra.sk", hydra: hydraAlice },
241-
{ name: "Bob", skPath: WORK_DIR + "/credentials/bob-hydra.sk", hydra: hydraBob },
242-
{ name: "Carol", skPath: WORK_DIR + "/credentials/carol-hydra.sk", hydra: hydraCarol },
240+
{ name: "Alice", skPath: WORK_DIR + "/credentials/alice-funds.sk", hydra: hydraAlice },
241+
{ name: "Bob", skPath: WORK_DIR + "/credentials/bob-funds.sk", hydra: hydraBob },
242+
{ name: "Carol", skPath: WORK_DIR + "/credentials/carol-funds.sk", hydra: hydraCarol },
243243
];
244244

245245
const DEVNET_RELAYS = [8082, 8083, 8084];
@@ -654,4 +654,3 @@ runHydraE2EFlow();
654654
}
655655

656656
```
657-

0 commit comments

Comments
 (0)