-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
Network
type to better support private tangles (#360)
* Make `Network` not `Copy` This is in preparation for adding another non-`Copy` variant later. * Add `Other` variant in `Network` * Add node.js DID creation on private tangle example * Add `from_name` in Wasm and fix absence of `Copy` * Remove superfluous imports * Add browser Wasm example * Remove old variable * Add low-level Rust API example * Format Wasm network source code * Add account Rust API example * Use same ideas for account & low-level examples * Rename `Network::as_str` to `name` * Impl spec compliance check for `Network` names * Change `IotaDID::network` return type to `Result` * Change bindings according to new return type * Improve Wasm examples with resolution step * Add private tangle test * Add cypress browser test * Use `?` instead of `unwrap` where possible * Add explorer url to `Network::Other` variant * Add explorer_url tests * Merge branch 'dev' into feat/private-tangle-network * Fix `explorer_url` conversion * Fix `message_url` in new examples * Fix network names in Rust private tangle examples * Update bindings/wasm/examples/node/test.js Co-authored-by: Craig Bester <[email protected]> * Update bindings/wasm/cypress/integration/browser_test.js Co-authored-by: Craig Bester <[email protected]> * Update bindings/wasm/examples/node/private_tangle.js Co-authored-by: Craig Bester <[email protected]> * Update bindings/wasm/examples/browser/private_tangle.js Co-authored-by: Craig Bester <[email protected]> * Update examples/account/private_tangle.rs Co-authored-by: Craig Bester <[email protected]> * Update examples/low-level-api/private_tangle.rs Co-authored-by: Craig Bester <[email protected]> Co-authored-by: Craig Bester <[email protected]>
- Loading branch information
1 parent
4bc3313
commit e8f9e77
Showing
27 changed files
with
465 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2020-2021 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Client, Config, Document, KeyType, Network } from "../../web/identity_wasm.js"; | ||
import { | ||
logObjectToScreen, | ||
logToScreen, | ||
} from "./utils.js"; | ||
|
||
/** | ||
This example shows how a DID document can be created on a private tangle. | ||
It can be run together with a local hornet node. | ||
Refer to https://github.com/iotaledger/one-click-tangle/tree/chrysalis/hornet-private-net | ||
for setup instructions. | ||
**/ | ||
export async function createIdentityPrivateTangle(inBrowser = true, log = true) { | ||
if (log) logToScreen("Identity creation started..."); | ||
if (log) logToScreen("This might take a few seconds to complete proof of work!"); | ||
|
||
let restURL | ||
let networkName | ||
|
||
if (inBrowser) { | ||
// Get the required parameters from the input fields | ||
restURL = document.querySelector("#create-private-rest-url").value; | ||
networkName = document.querySelector("#create-private-network-name").value; | ||
} else { | ||
restURL = "http://127.0.0.1:14265/"; | ||
networkName = "custom"; | ||
} | ||
|
||
// This is an arbitrarily defined network name | ||
const network = Network.from_name(networkName); | ||
|
||
// Create a DID Document (an identity). | ||
const { doc, key } = new Document(KeyType.Ed25519, network.toString()); | ||
|
||
// Sign the DID Document with the generated key. | ||
doc.sign(key); | ||
|
||
// Create a client configuration and set the custom network. | ||
const config = new Config(); | ||
config.setNetwork(network); | ||
|
||
// This URL should point to the REST API of a node. | ||
config.setNode(restURL); | ||
|
||
// Create a client instance from the configuration to publish messages to the Tangle. | ||
const client = Client.fromConfig(config); | ||
|
||
// Publish the Identity to the IOTA Network, this may take a few seconds to complete Proof-of-Work. | ||
const receipt = await client.publishDocument(doc.toJSON()); | ||
|
||
if (log) logToScreen("Identity creation done!"); | ||
|
||
// Make sure the DID can be resolved on the private tangle | ||
const resolved = await client.resolve(doc.id.toString()); | ||
|
||
if (log) logToScreen("Resolved DID document:"); | ||
if (log) logObjectToScreen(resolved); | ||
|
||
// Return the results. | ||
return { key, doc, receipt }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2020-2021 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
const { Client, Config, Document, KeyType, Network } = require('../../node/identity_wasm') | ||
|
||
/** | ||
This example shows how a DID document can be created on a private tangle. | ||
It can be run together with a local hornet node. | ||
Refer to https://github.com/iotaledger/one-click-tangle/tree/chrysalis/hornet-private-net | ||
for setup instructions. | ||
**/ | ||
async function createIdentityPrivateTangle() { | ||
// This is an arbitrarily defined network name | ||
const network = Network.from_name("custom"); | ||
|
||
// Create a DID Document (an identity). | ||
const { doc, key } = new Document(KeyType.Ed25519, network.toString()); | ||
|
||
// Sign the DID Document with the generated key. | ||
doc.sign(key); | ||
|
||
// Create a client configuration and set the custom network. | ||
const config = new Config(); | ||
config.setNetwork(network); | ||
|
||
// This URL points to the REST API of the locally running hornet node. | ||
config.setNode("http://127.0.0.1:14265/"); | ||
|
||
// Create a client instance from the configuration to publish messages to the Tangle. | ||
const client = Client.fromConfig(config); | ||
|
||
// Publish the Identity to the IOTA Network, this may take a few seconds to complete Proof-of-Work. | ||
const receipt = await client.publishDocument(doc.toJSON()); | ||
|
||
// Make sure the DID can be resolved on the private tangle | ||
const resolved = await client.resolve(doc.id.toString()); | ||
|
||
// Return the results. | ||
return { key, resolved, receipt }; | ||
} | ||
|
||
exports.createIdentityPrivateTangle = createIdentityPrivateTangle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.