update browser example
-import("../pkg/index.js").then((identity) => {
-
+import("../pkg/index.js").then(async identity => {
+ try {
console.log(identity)
-
const { initialize, resolve, publish, Key, Doc, DID } = identity
initialize();
+ await playground()
+ await alice_bob()
+
+ async function playground() {
+ console.log("key", new Key())
+
+ console.log("did", new DID((new Key()).public))
+
+ console.log("did", new DID({ key: (new Key()).public, network: "com" }))
+
+ const { key, doc } = Doc.generateCom()
+
+ console.log("key (generated)", key)
+ console.log("doc (generated)", doc)
+
+ console.log("doc (unsigned)", doc.document)
+
+ doc.sign(key)
+
+ console.log("doc (signed)", doc.document)
+
+ console.log("doc valid?", doc.verify())
+
+ const json = JSON.stringify(doc.document)
+
+ console.log("From JSON >", Doc.fromJSON(json))
+
+ console.log("published", await publish(doc.document, { node: "https://nodes.comnet.thetangle.org:443", network: "com" }))
+ console.log("resolved", await resolve(doc.did, { node: "https://nodes.comnet.thetangle.org:443", network: "com" }))
+ }
+
+ function alice_bob() {
// Generate Keypairs
const alice_keypair = new Key()
console.log("alice_keypair: ", alice_keypair)
@@ -42,13 +73,14 @@ import("../pkg/index.js").then((identity) => {
let json = JSON.stringify(diff)
console.log("Diff has valid signature: ", bob_document.verify_diff(json))
-
- // // identity.ResolveDID("did:iota:8gPe8EwndxtvQPfYT5KsXBXtXUGZMLCPP4Z98by33TMs", "https://nodes.thetangle.org:443").then(doc => {
- // // console.log("resolved document: ", doc);
- // // });
+ }
+ } catch (e) {
+ console.error(e)
+ }
});
+
/*
identity.ts: Implementation Guide
