Blockchain Commons Uniform Resources TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Class UR

    A Uniform Resource (UR) is a URI-encoded CBOR object.

    URs are defined in BCR-2020-005: Uniform Resources.

    import { UR } from '@bcts/uniform-resources';
    import { CBOR } from '@bcts/dcbor';

    // Create a UR from a CBOR object
    const cbor = CBOR.fromArray([1, 2, 3]);
    const ur = UR.new('test', cbor);

    // Encode to string
    const urString = ur.string();
    console.log(urString); // "ur:test/..."

    // Decode from string
    const decodedUR = UR.fromURString(urString);
    console.log(decodedUR.urTypeStr()); // "test"
    Index

    Methods

    • Creates a new UR from the provided type and CBOR data.

      Parameters

      • urType: string | URType

        The UR type (will be validated)

      • cbor: Cbor

        The CBOR data to encode

      Returns UR

      If the type is invalid

      const ur = UR.new('bytes', CBOR.fromString('hello'));
      
    • Creates a new UR from a UR string.

      Parameters

      • urString: string

        A UR string like "ur:test/..."

      Returns UR

      If the string doesn't start with "ur:"

      If no type is specified

      If the UR is multi-part

      If decoding fails

      const ur = UR.fromURString('ur:test/lsadaoaxjygonesw');
      
    • Returns the UR type as a string.

      Returns string

    • Returns the CBOR data.

      Returns Cbor

    • Returns the string representation of the UR (lowercase, suitable for display).

      Returns string

      const ur = UR.new('test', CBOR.fromArray([1, 2, 3]));
      console.log(ur.string()); // "ur:test/lsadaoaxjygonesw"
    • Returns the QR string representation (uppercase, most efficient for QR codes).

      Returns string

    • Returns the QR data as bytes (uppercase UR string as UTF-8).

      Returns Uint8Array

    • Checks if the UR type matches the expected type.

      Parameters

      • expectedType: string | URType

        The expected type

      Returns void

      If the types don't match

    • Returns the string representation.

      Returns string

    • Checks equality with another UR.

      Parameters

      Returns boolean