From 058d582b0607d6f2a7b39b81a1da0049aa03f14d Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 28 Jun 2023 18:15:12 +0200 Subject: [PATCH 01/11] feat: add kilt example --- examples/kilt/did.eg.ts | 19 +++++++++++++++++++ import_map.json | 2 +- nets.ts | 4 ++++ words.txt | 3 +++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 examples/kilt/did.eg.ts diff --git a/examples/kilt/did.eg.ts b/examples/kilt/did.eg.ts new file mode 100644 index 000000000..a1931e03f --- /dev/null +++ b/examples/kilt/did.eg.ts @@ -0,0 +1,19 @@ +import { spiritnet } from "@capi/spiritnet" +import { $, is } from "capi" + +const { owner } = await spiritnet.Web3Names.Owner.value( + new TextEncoder().encode("ingo"), +) + .unhandle(is(undefined)).run() + +const { authenticationKey, publicKeys } = await spiritnet.Did.Did.value(owner) + .unhandle(is(undefined)).run() + +const value = [...publicKeys.entries()].find(([k, _v]) => bytesEqual(k, authenticationKey)) + +console.log("DID:", value![1].key.value) +$.assert($.uint8Array, value![1].key.value.value) + +function bytesEqual(a: Uint8Array, b: Uint8Array) { + return a.every((x, i) => b[i] === x) +} diff --git a/import_map.json b/import_map.json index 209af0f0f..c584b4a96 100644 --- a/import_map.json +++ b/import_map.json @@ -1,6 +1,6 @@ { "imports": { - "@capi/": "http://localhost:4646/ed956cd5bde67584/" + "@capi/": "http://localhost:4646/7544978d8abdc81c/" }, "scopes": { "examples/": { diff --git a/nets.ts b/nets.ts index ce3dae53e..02f3ac2b2 100644 --- a/nets.ts +++ b/nets.ts @@ -63,3 +63,7 @@ export const rococoDevXcmStatemine = rococoDevXcm.parachain({ export const collectives = net.ws({ url: "wss://collectives.api.onfinality.io/public-ws", }) + +export const spiritnet = net.ws({ + url: "wss://kilt-rpc.dwellir.com", +}) diff --git a/words.txt b/words.txt index 2c45378cc..965565a92 100644 --- a/words.txt +++ b/words.txt @@ -23,6 +23,7 @@ devnet devnets dispatchable dprint +dwellir esbenp extrinsics ferdie @@ -33,6 +34,7 @@ harrysolovay hasher hashers hrmp +ingo inherents keypair kiera @@ -67,6 +69,7 @@ ryann serde sibl smoldot +spiritnet statemigration statemine statemint From 3ab55b4fe8b1e0355d2a21470b66bcffb15cb1ba Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 28 Jun 2023 18:22:32 +0200 Subject: [PATCH 02/11] feat: use bytes.equals --- examples/kilt/did.eg.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/kilt/did.eg.ts b/examples/kilt/did.eg.ts index a1931e03f..c08c8697f 100644 --- a/examples/kilt/did.eg.ts +++ b/examples/kilt/did.eg.ts @@ -1,5 +1,6 @@ import { spiritnet } from "@capi/spiritnet" import { $, is } from "capi" +import { equals } from "../../deps/std/bytes.ts" const { owner } = await spiritnet.Web3Names.Owner.value( new TextEncoder().encode("ingo"), @@ -9,11 +10,7 @@ const { owner } = await spiritnet.Web3Names.Owner.value( const { authenticationKey, publicKeys } = await spiritnet.Did.Did.value(owner) .unhandle(is(undefined)).run() -const value = [...publicKeys.entries()].find(([k, _v]) => bytesEqual(k, authenticationKey)) +const value = [...publicKeys.entries()].find(([k, _v]) => equals(k, authenticationKey)) console.log("DID:", value![1].key.value) $.assert($.uint8Array, value![1].key.value.value) - -function bytesEqual(a: Uint8Array, b: Uint8Array) { - return a.every((x, i) => b[i] === x) -} From 81ce8f5e41be37f97f89629ed416803afd70deb5 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 28 Jun 2023 18:31:59 +0200 Subject: [PATCH 03/11] feat: add example doc --- examples/kilt/did.eg.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/kilt/did.eg.ts b/examples/kilt/did.eg.ts index c08c8697f..f62b7be9f 100644 --- a/examples/kilt/did.eg.ts +++ b/examples/kilt/did.eg.ts @@ -1,3 +1,8 @@ +/** + * @title Kilt decentralized identifier (DID) + * @description Get a user public key based on the web3name alias of a Kilt DID. + */ + import { spiritnet } from "@capi/spiritnet" import { $, is } from "capi" import { equals } from "../../deps/std/bytes.ts" From 4fd37f0471705358cf08c11d324ef008f2a6cdd7 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 28 Jun 2023 18:52:28 +0200 Subject: [PATCH 04/11] feat: improve did example --- examples/kilt/did.eg.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/kilt/did.eg.ts b/examples/kilt/did.eg.ts index f62b7be9f..74e375715 100644 --- a/examples/kilt/did.eg.ts +++ b/examples/kilt/did.eg.ts @@ -3,19 +3,23 @@ * @description Get a user public key based on the web3name alias of a Kilt DID. */ -import { spiritnet } from "@capi/spiritnet" +import { $didPublicKeyDetails, spiritnet } from "@capi/spiritnet" import { $, is } from "capi" import { equals } from "../../deps/std/bytes.ts" -const { owner } = await spiritnet.Web3Names.Owner.value( - new TextEncoder().encode("ingo"), -) - .unhandle(is(undefined)).run() +const { owner } = await spiritnet.Web3Names.Owner + .value(new TextEncoder().encode("ingo")) + .unhandle(is(undefined)) + .run() -const { authenticationKey, publicKeys } = await spiritnet.Did.Did.value(owner) - .unhandle(is(undefined)).run() +const [_, didPublicKeyDetails] = await spiritnet.Did.Did + .value(owner) + .unhandle(is(undefined)) + .map(({ authenticationKey, publicKeys }) => + [...publicKeys.entries()].find(([k, _v]) => equals(k, authenticationKey)) + ) + .unhandle(is(undefined)) + .run() -const value = [...publicKeys.entries()].find(([k, _v]) => equals(k, authenticationKey)) - -console.log("DID:", value![1].key.value) -$.assert($.uint8Array, value![1].key.value.value) +console.log("DID public key details:", didPublicKeyDetails) +$.assert($didPublicKeyDetails, didPublicKeyDetails) From de9bd7abfce5d0dad910037ee583f689b62e0fc9 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 28 Jun 2023 19:14:47 +0200 Subject: [PATCH 05/11] feat: user first user --- examples/{kilt/did.eg.ts => read/kilt.eg.ts} | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename examples/{kilt/did.eg.ts => read/kilt.eg.ts} (69%) diff --git a/examples/kilt/did.eg.ts b/examples/read/kilt.eg.ts similarity index 69% rename from examples/kilt/did.eg.ts rename to examples/read/kilt.eg.ts index 74e375715..ed198fe44 100644 --- a/examples/kilt/did.eg.ts +++ b/examples/read/kilt.eg.ts @@ -1,16 +1,16 @@ /** * @title Kilt decentralized identifier (DID) - * @description Get a user public key based on the web3name alias of a Kilt DID. + * @description Get the first user public key based on the user Kilt DID. */ import { $didPublicKeyDetails, spiritnet } from "@capi/spiritnet" -import { $, is } from "capi" +import { $, is, ValueRune } from "capi" import { equals } from "../../deps/std/bytes.ts" -const { owner } = await spiritnet.Web3Names.Owner - .value(new TextEncoder().encode("ingo")) - .unhandle(is(undefined)) - .run() +const owner = spiritnet.Web3Names.Owner + .entries({ limit: 1 }) + .into(ValueRune) + .access(0, 1, "owner") const [_, didPublicKeyDetails] = await spiritnet.Did.Did .value(owner) From b5695bc20f66d08d86f6e498a65c8713f6a4d4c6 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 28 Jun 2023 19:22:46 +0200 Subject: [PATCH 06/11] feat: update docs --- examples/read/kilt.eg.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/read/kilt.eg.ts b/examples/read/kilt.eg.ts index ed198fe44..a62c5a78d 100644 --- a/examples/read/kilt.eg.ts +++ b/examples/read/kilt.eg.ts @@ -1,6 +1,5 @@ /** - * @title Kilt decentralized identifier (DID) - * @description Get the first user public key based on the user Kilt DID. + * @title Read Kilt first owner DID public key details */ import { $didPublicKeyDetails, spiritnet } from "@capi/spiritnet" From 7febb581fa2dfff7656cd461407b34f5b03abcea Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Thu, 29 Jun 2023 13:42:21 +0200 Subject: [PATCH 07/11] feat: use map.get --- examples/read/kilt.eg.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/read/kilt.eg.ts b/examples/read/kilt.eg.ts index a62c5a78d..547f72c3e 100644 --- a/examples/read/kilt.eg.ts +++ b/examples/read/kilt.eg.ts @@ -4,19 +4,16 @@ import { $didPublicKeyDetails, spiritnet } from "@capi/spiritnet" import { $, is, ValueRune } from "capi" -import { equals } from "../../deps/std/bytes.ts" const owner = spiritnet.Web3Names.Owner .entries({ limit: 1 }) .into(ValueRune) .access(0, 1, "owner") -const [_, didPublicKeyDetails] = await spiritnet.Did.Did +const didPublicKeyDetails = await spiritnet.Did.Did .value(owner) .unhandle(is(undefined)) - .map(({ authenticationKey, publicKeys }) => - [...publicKeys.entries()].find(([k, _v]) => equals(k, authenticationKey)) - ) + .map(({ authenticationKey, publicKeys }) => publicKeys.get(authenticationKey)) .unhandle(is(undefined)) .run() From dc863d47e466c1009c2dbfc8063440b4d30d5231 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Thu, 29 Jun 2023 13:49:26 +0200 Subject: [PATCH 08/11] feat: remove unhandle --- examples/read/kilt.eg.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/read/kilt.eg.ts b/examples/read/kilt.eg.ts index 547f72c3e..5291796ad 100644 --- a/examples/read/kilt.eg.ts +++ b/examples/read/kilt.eg.ts @@ -1,5 +1,7 @@ /** * @title Read Kilt first owner DID public key details + * @description Read first owner decentralized identity. + * Then use the owner authentication key to get the DID public key details. */ import { $didPublicKeyDetails, spiritnet } from "@capi/spiritnet" @@ -10,12 +12,11 @@ const owner = spiritnet.Web3Names.Owner .into(ValueRune) .access(0, 1, "owner") -const didPublicKeyDetails = await spiritnet.Did.Did +const details = await spiritnet.Did.Did .value(owner) .unhandle(is(undefined)) .map(({ authenticationKey, publicKeys }) => publicKeys.get(authenticationKey)) - .unhandle(is(undefined)) .run() -console.log("DID public key details:", didPublicKeyDetails) -$.assert($didPublicKeyDetails, didPublicKeyDetails) +console.log("DID public key details:", details) +$.assert($didPublicKeyDetails, details) From a04cd5e73fea6d6fc85faf9daf988eee46cf38f6 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Mon, 3 Jul 2023 05:31:05 -0400 Subject: [PATCH 09/11] cleaning up --- examples/read/kilt.eg.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/read/kilt.eg.ts b/examples/read/kilt.eg.ts index 5291796ad..796c2c410 100644 --- a/examples/read/kilt.eg.ts +++ b/examples/read/kilt.eg.ts @@ -1,22 +1,25 @@ /** - * @title Read Kilt first owner DID public key details - * @description Read first owner decentralized identity. - * Then use the owner authentication key to get the DID public key details. + * @title Read Kilt public key details of first owner in web3 names owners map + * @description Read the first entry of the Web3Names map, and access + * the DID public key details of the owner. */ import { $didPublicKeyDetails, spiritnet } from "@capi/spiritnet" import { $, is, ValueRune } from "capi" +/// Reference the `owner` field of the first entry of the the web3 names owners map. const owner = spiritnet.Web3Names.Owner .entries({ limit: 1 }) .into(ValueRune) .access(0, 1, "owner") +/// Retrieve the associated DID public key details. const details = await spiritnet.Did.Did .value(owner) .unhandle(is(undefined)) .map(({ authenticationKey, publicKeys }) => publicKeys.get(authenticationKey)) .run() +/// Ensure `details` is of the expected shape console.log("DID public key details:", details) $.assert($didPublicKeyDetails, details) From 10215bdaf45235ac656d1b138bb53ea2be104dd3 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Mon, 3 Jul 2023 05:31:35 -0400 Subject: [PATCH 10/11] prune words --- words.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/words.txt b/words.txt index 965565a92..b137284f2 100644 --- a/words.txt +++ b/words.txt @@ -34,7 +34,6 @@ harrysolovay hasher hashers hrmp -ingo inherents keypair kiera From 93cc3e181db30b0bc8be756f6690b08196f82924 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Thu, 6 Jul 2023 10:50:38 -0400 Subject: [PATCH 11/11] Update examples/read/kilt.eg.ts --- examples/read/kilt.eg.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/read/kilt.eg.ts b/examples/read/kilt.eg.ts index 796c2c410..37e247577 100644 --- a/examples/read/kilt.eg.ts +++ b/examples/read/kilt.eg.ts @@ -20,6 +20,6 @@ const details = await spiritnet.Did.Did .map(({ authenticationKey, publicKeys }) => publicKeys.get(authenticationKey)) .run() -/// Ensure `details` is of the expected shape +/// Ensure `details` is of the expected shape. console.log("DID public key details:", details) $.assert($didPublicKeyDetails, details)