@blockchaincommons/known-values - v1.0.0-beta.4
    Preparing search index...

    Class KnownValue

    A known value: a codepoint (an unsigned 64-bit integer) with, optionally, the name a registry assigns it.

    Equality is by codepoint (equals), whatever the names, and across module copies. Compare with equals: === may hold for the constants the global registry is seeded with but is not guaranteed, because directory entries and registrations replace the registered objects. Instances are frozen (a constant cannot be renamed process-wide) and every constructor argument is checked: the codepoint must be a non-negative safe integer number or a bigint in 0 ..= 2⁶⁴ − 1 (use bigint for exact codepoints above the safe number range), the name a string.

    Implements

    • ToCbor
    • CborTagged
    • DigestProvider
    Index
    • Parameters

      • value: KnownValueInput

        The codepoint (an unsigned 64-bit integer)

      • OptionalassignedName: string

        The name the registry gives it, if any

      Returns KnownValue

      KnownValuesError InvalidParameter when value is not a non-negative safe integer number or a bigint in 0 ..= 2⁶⁴ − 1, or assignedName is not a string

    • get value(): number | bigint

      The codepoint, as a number when it is a safe integer and a bigint otherwise.

      Returns number | bigint

    • get valueBigInt(): bigint

      The codepoint as a bigint.

      Returns bigint

    • get assignedName(): string | undefined

      The registry name, if one was assigned.

      Returns string | undefined

    • get name(): string

      The assigned name, or the decimal codepoint when there is none.

      Returns string

    • get codec(): CborCodec<KnownValue>

      Tagged-CBOR codec. decode requires #6.40000(n) — the tag is part of the type, as in the reference's TryFrom<CBOR>; use fromUntaggedCbor for the bare unsigned integer. tags is named from the global tags store at each access, as the reference's cbor_tags() is.

      Returns CborCodec<KnownValue>

    • Whether x is a KnownValue, from this module copy or another: checks the brand, not instanceof.

      Parameters

      • x: unknown

      Returns x is KnownValue

    • Two known values are equal when their codepoints are, whatever their names and whichever module copy built them; anything that is not a KnownValue is not equal.

      Parameters

      • other: unknown

      Returns boolean

    • SHA-256 of the tagged CBOR.

      Returns Digest

    • The known-value tag (40000), named as the global tags store names it at the time.

      Returns Tag[]

    • The bare unsigned integer.

      Returns Cbor

    • #6.40000(value).

      Returns Cbor

    • Decode #6.40000(n) (the reference's TryFrom<CBOR>). Negative content wraps as KnownValue.fromUntaggedCbor describes.

      Parameters

      • cborValue: Cbor

      Returns KnownValue

      CborError (dcbor's, with a code) — WrongType for an untagged value or a non-integer content, WrongTag for another tag (both tags named as the global tags store names them)

    • Decode the bare integer n — the content of tag 40000 (the reference's from_untagged_cbor), as a tag summariser or a decoder that has already stripped the tag holds it. A negative integer node wraps to 2⁶⁴ + n, as the reference's u64::try_from does (dcbor's negative-to-unsigned wrap), so 40000(-1) is the codepoint 18446744073709551615; a whole float head that dcbor turns into an integer node follows the same rule.

      Parameters

      • cborValue: Cbor

      Returns KnownValue

      CborError WrongType when the CBOR is not an integer (a tagged value, a bignum, a text), OutOfRange for a negative below −2⁶⁴