Class: Canonicalization ​
Defined in: packages/common/src/canonicalization.ts:15
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:22
Initializes the Canonicalization class with the specified algorithm.
Parameters ​
algorithm? ​
CanonicalizationAlgorithm = 'jcs'
The canonicalization algorithm to use ('jcs').
Returns ​
Canonicalization
Accessors ​
algorithm ​
Get Signature ​
get algorithm():
CanonicalizationAlgorithm
Defined in: packages/common/src/canonicalization.ts:30
Gets the canonicalization algorithm.
Returns ​
The current canonicalization algorithm.
Methods ​
base58() ​
base58(
hashBytes):string
Defined in: packages/common/src/canonicalization.ts:159
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,algorithm?):Bytes
Defined in: packages/common/src/canonicalization.ts:170
Canonicalizes an object, hashes it and returns it as hash bytes. Step 1-2: Canonicalize → Hash.
Parameters ​
object ​
Record<any, any>
The object to process.
algorithm? ​
CanonicalizationAlgorithm = ...
Returns ​
The final SHA-256 hash bytes.
canonicalize() ​
canonicalize(
object,algorithm?):string
Defined in: packages/common/src/canonicalization.ts:101
Step 1: Uses this.algorithm to determine the method (JCS).
Parameters ​
object ​
Record<any, any>
The object to canonicalize.
algorithm? ​
CanonicalizationAlgorithm = ...
The algorithm to use.
Returns ​
string
The canonicalized object.
encode() ​
encode(
canonicalizedhash,encoding?,multibase?):string
Defined in: packages/common/src/canonicalization.ts:135
Step 3: Encodes SHA-256 hashed, canonicalized object as a hex or base58 string.
Parameters ​
canonicalizedhash ​
The canonicalized object to encode.
encoding? ​
CanonicalizationEncoding = 'hex'
The encoding format ('hex' or 'base58').
multibase? ​
boolean = false
Returns ​
string
The encoded string.
Throws ​
If the encoding format is not supported.
hash() ​
hash(
canonicalized):Bytes
Defined in: packages/common/src/canonicalization.ts:124
Step 2: SHA-256 hashes a canonicalized object.
Parameters ​
canonicalized ​
string
The canonicalized object.
Returns ​
The SHA-256 HashBytes (Uint8Array).
hashbase58() ​
hashbase58(
canonicalized):string
Defined in: packages/common/src/canonicalization.ts:194
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:184
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:150
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):string
Defined in: packages/common/src/canonicalization.ts:115
Step 1: Canonicalizes an object using JCS (JSON Canonicalization Scheme).
Parameters ​
object ​
Record<any, any>
The object to canonicalize.
Returns ​
string
The canonicalized object.
process() ​
process(
object,options?):string
Defined in: packages/common/src/canonicalization.ts:77
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) → Step 2 Hash (SHA256) → Step 3 Encode (Hex/Base58).
Parameters ​
object ​
Record<any, any>
The object to process.
options? ​
Options for processing.
algorithm? ​
The canonicalization algorithm to use.
encoding? ​
The encoding format ('hex' or 'base58').
multibase? ​
boolean
Returns ​
string
The final SHA-256 hash bytes as a hex string.
normalizeAlgorithm() ​
staticnormalizeAlgorithm(algorithm):CanonicalizationAlgorithm
Defined in: packages/common/src/canonicalization.ts:40
Normalizes the canonicalization algorithm.
Parameters ​
algorithm ​
Returns ​
The normalized algorithm.
Throws ​
If the algorithm is not supported.
normalizeEncoding() ​
staticnormalizeEncoding(encoding):CanonicalizationEncoding
Defined in: packages/common/src/canonicalization.ts:54
Normalizes the canonicalization encoding.
Parameters ​
encoding ​
The encoding to normalize.
Returns ​
The normalized encoding.
Throws ​
If the encoding is not supported.