Signer corresponding to did:key identified principal.

Type Parameters

Hierarchy

Properties

signatureAlgorithm: string

Name of the signature algorithm. It is a human readable equivalent of the signatureCode, however it is also used as last segment in Nonstandard Signatures, which is used as an alg field of JWT header when UCANs are serialized to JWT.

signatureCode: Alg

Integer corresponding to the byteprefix of the Crypto.SigAlg. It is used to tag signature so it can self describe what algorithm was used.

signer: Signer<`did:key:${string}`, Alg>

The signer field is a self reference (usually a getter). It's sole purpose is to allow splitting signer and verifier through destructuring.

Example

import * as Principal from "@ucanto/principal"

const { signer, verifier } = Principal.from(archive)
verifier: Verifier<`did:key:${string}`, Alg>

The verifier field just like the signer exists to allow splitting them apart through destructuring.

Methods

  • Returns `did:key:${string}`

  • Type Parameters

    • T

      Source data before it was byte encoding into payload.

      Takes byte encoded payload and produces a verifiable signature.

    Parameters

    Returns Crypto.Await<SignatureView<T, Alg>>

  • Returns archive of this signer which will have keys byte encoded when underlying keys are extractable or in CryptoKey form otherwise.

    This allows a storing non extractable archives into indexedDB and storing extractable archives on disk ofter serializing them using IPLD code.

    This aligns with a best practice that in browsers inextricable keys should be used and extractable keys in node.

    Returns SignerArchive<`did:key:${string}`, Alg>

    Example

    import * as CBOR from '@ipld/dag-cbor'

    const save = async (signer: Signer) => {
    const archive = signer.toArchive()
    if (globalThis.indexedDB) {
    await IDB_OBJECT_STORE.add(archive)
    } else {
    await fs.writeFile(KEY_PATH, CBOR.encode(archive))
    }
    }
  • Returns unwrapped did:key of this principal.

    Returns `did:key:${string}`

  • Type Parameters

    • T

      Source data before it was byte encoding into payload.

      Takes byte encoded payload and verifies that it is signed by corresponding signer.

    Parameters

    Returns Crypto.Await<boolean>

  • Wraps key of this signer into a signer with a different DID. This is primarily used to wrap SignerKey into a Signer that has did of different method.

    Type Parameters

    • ID extends `did:${string}:${string}`

    Parameters

    • id: ID

    Returns Signer<ID, Alg>

    Example

    import { ed25519 } from "@ucanto/principal"

    const demo = async () => {
    const key = await ed25519.generate()
    key.did() // 'did:key:z6Mkqa4oY9Z5Pf5tUcjLHLUsDjKwMC95HGXdE1j22jkbhz6r'
    const gozala = key.withDID('did:web:gozala.io')
    gozala.did() // 'did:web:gozala.io'
    }

Generated using TypeDoc