Class: Canonicalization ​
Defined in: packages/common/src/canonicalization.ts:16
Canonicalization class provides methods for canonicalizing JSON objects and hashing them using SHA-256. It supports different canonicalization algorithms and encoding formats (hex and base58). Canonicalization
Constructors ​
Constructor ​
new Canonicalization(
algorithm):Canonicalization
Defined in: packages/common/src/canonicalization.ts:24
Initializes the Canonicalization class with the specified algorithm.
Parameters ​
algorithm ​
CanonicalizationAlgorithm = 'jcs'
The canonicalization algorithm to use ('jcs' or 'rdfc').
Returns ​
Canonicalization
Accessors ​
algorithm ​
Get Signature ​
get algorithm():
CanonicalizationAlgorithm
Defined in: packages/common/src/canonicalization.ts:48
Gets the canonicalization algorithm.
Returns ​
The current canonicalization algorithm.
Set Signature ​
set algorithm(
algorithm):void
Defined in: packages/common/src/canonicalization.ts:32
Sets the canonicalization algorithm.
Parameters ​
algorithm ​
Either 'jcs' or 'rdfc'.
"jcs" | "rdfc"
Returns ​
void
Methods ​
base58() ​
base58(
hashBytes):string
Defined in: packages/common/src/canonicalization.ts:144
Step 3.2: Encodes HashBytes (Uint8Array) to a base58btc string.
Parameters ​
hashBytes ​
The hash as a Uint8Array.
Returns ​
string
The hash as a hex string.
canonicalhash() ​
canonicalhash(
object):Promise<Bytes>
Defined in: packages/common/src/canonicalization.ts:154
Canonicalizes an object, hashes it and returns it as hash bytes. Step 1-2: Canonicalize → Hash.
Parameters ​
object ​
The object to process.
Returns ​
Promise<Bytes>
The final SHA-256 hash bytes.
canonicalize() ​
canonicalize(
object):Promise<string>
Defined in: packages/common/src/canonicalization.ts:81
Step 1: Uses this.algorithm to determine the method (JCS/RDFC).
Parameters ​
object ​
The object to canonicalize.
Returns ​
Promise<string>
The canonicalized object.
encode() ​
encode(
canonicalizedhash,encoding):string
Defined in: packages/common/src/canonicalization.ts:119
Step 3: Encodes SHA-256 hashed, canonicalized object as a hex or base58 string.
Parameters ​
canonicalizedhash ​
The canonicalized object to encode.
encoding ​
string = 'hex'
The encoding format ('hex' or 'base58').
Returns ​
string
The encoded string.
Throws ​
If the encoding format is not supported.
hash() ​
hash(
canonicalized):Bytes
Defined in: packages/common/src/canonicalization.ts:108
Step 2: SHA-256 hashes a canonicalized object.
Parameters ​
canonicalized ​
string
The canonicalized object.
Returns ​
The SHA-256 HashBytes (Uint8Array).
hashb58() ​
hashb58(
canonicalized):string
Defined in: packages/common/src/canonicalization.ts:175
Computes the SHA-256 hashes of canonicalized object and encodes it as a base58 string. Step 2-3: Hash → Encode(base58).
Parameters ​
canonicalized ​
string
The canonicalized object to hash.
Returns ​
string
The SHA-256 hash as a base58 string.
hashhex() ​
hashhex(
canonicalized):string
Defined in: packages/common/src/canonicalization.ts:165
Computes the SHA-256 hash of a canonicalized object and encodes it as a hex string. Step 2-3: Hash → Encode(Hex).
Parameters ​
canonicalized ​
string
The canonicalized object to hash.
Returns ​
string
The SHA-256 hash as a hex string.
hex() ​
hex(
hashBytes):string
Defined in: packages/common/src/canonicalization.ts:135
Step 3.1: Encodes HashBytes (Uint8Array) to a hex string.
Parameters ​
hashBytes ​
The hash as a Uint8Array.
Returns ​
string
The hash as a hex string.
jcs() ​
jcs(
object):any
Defined in: packages/common/src/canonicalization.ts:90
Step 1: Canonicalizes an object using JCS (JSON Canonicalization Scheme).
Parameters ​
object ​
The object to canonicalize.
Returns ​
any
The canonicalized object.
process() ​
process(
object,encoding):Promise<string>
Defined in: packages/common/src/canonicalization.ts:65
Implements 9.2 JSON Canonicalization and Hash.
A macro function that takes in a JSON document, document, and canonicalizes it following the JSON Canonicalization Scheme. The function returns the canonicalizedBytes.
Optionally encodes a sha256 hashed canonicalized JSON object. Step 1 Canonicalize (JCS/RDFC) → Step 2 Hash (SHA256) → Step 3 Encode (Hex/Base58).
Parameters ​
object ​
The object to process.
encoding ​
string = 'hex'
The encoding format ('hex' or 'base58').
Returns ​
Promise<string>
The final SHA-256 hash bytes as a hex string.
rdfc() ​
rdfc(
object):Promise<string>
Defined in: packages/common/src/canonicalization.ts:99
Step 1: Canonicalizes an object using RDF Canonicalization (RDFC).
Parameters ​
object ​
The object to canonicalize.
Returns ​
Promise<string>
The canonicalized object.