paritytech / capi

[WIP] A framework for crafting interactions with Substrate chains
https://docs.capi.dev
Apache License 2.0
104 stars 9 forks source link

feat: add kilt example #1114

Closed kratico closed 1 year ago

kratico commented 1 year ago

Example to get the first 10 owners


import { $didPublicKeyDetails, spiritnet } from "@capi/spiritnet"
import { $, ArrayRune, is } from "capi"
import { equals } from "../../deps/std/bytes.ts"

const didPublicKeyDetails = await spiritnet.Web3Names.Owner
  .entries({ limit: 10 })
  .into(ArrayRune)
  .mapArray((entry) =>
    spiritnet.Did.Did
      .value(entry.access(1, "owner"))
      .unhandle(is(undefined))
      .map(({ authenticationKey, publicKeys }) =>
        [...publicKeys.entries()].find(([k, _v]) => equals(k, authenticationKey))
      )
      .unhandle(is(undefined))
  )
  .run()

console.log("DID public key details:", didPublicKeyDetails)
$.assert($.array($.tuple($.sizedUint8Array(32), $didPublicKeyDetails)), didPublicKeyDetails)