di-wings
Version:
Aviary Tech's common library for decentralized identity
241 lines • 11 kB
TypeScript
export type GroupDefinitions = {
[key: string]: string[];
};
export type SelectionResult = {
nquads: string[];
deskolemizedNQuads: string[];
};
export type GroupResult = {
matching: Map<number, string>;
nonMatching: Map<number, string>;
deskolemizedNQuads: string[];
};
export type CanonicalizeAndGroupResult = {
groups: Map<string, GroupResult>;
skolemizedExpandedDocument: any;
skolemizedCompactDocument: any;
deskolemizedNQuads: string[];
labelMap: Map<string, string>;
nquads: string[];
};
export interface SkolemizationResult {
skolemizedExpandedDocument: any[];
skolemizedCompactDocument: Record<string, unknown>;
}
/**
* Type guard to verify if a value is a Record<string, unknown>
*/
export declare function isRecord(value: unknown): value is Record<string, unknown>;
/**
* Strips blank node prefixes from a label map
*
* @param map - The label map to strip blank node prefixes from
* @returns The label map with blank node prefixes stripped
*/
export declare function stripBlankNodePrefixes(map: Map<string, string>): Map<any, any>;
export declare function createHmac(key: Uint8Array): (input: Uint8Array) => Uint8Array<ArrayBufferLike>;
/**
* https://www.w3.org/TR/vc-di-bbs/#createshuffledidlabelmapfunction
* Data Integrity BBS Cryptosuites v1.0
* 3.2.1 - creates a label map factory function that uses an HMAC to shuffle canonical blank node identifiers.
*
* @param hmacKey - The HMAC key to use for shuffling
* @param HMAC - The HMAC function to use for shuffling
* @returns A function that takes a label map and returns a shuffled label map
*/
export declare const createShuffledIdLabelMapFunction: (HMAC: (key: Uint8Array, ...msgs: Uint8Array[]) => Uint8Array) => ((labelMap: Map<string, string>) => Map<string, string>);
/**
* https://www.w3.org/TR/vc-di-ecdsa/#labelreplacementcanonicalizenquads
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.1 - Canonicalizes N-Quads and replaces blank node identifiers using a label map factory
*
* @param labelMapFactoryFunction - Function to generate new blank node identifiers
* @param deskolemizedNQuads - Array of N-Quad strings to canonicalize
* @param options - Optional canonicalization options
* @returns Object containing labelMap and canonicalNQuads
* @throws Error if canonicalization fails
*/
export declare const labelReplacementCanonicalizeNQuads: (labelMapFactoryFunction: (labelMap: Map<string, string>) => Map<string, string>, deskolemizedNQuads: string[], options?: {
documentLoader?: (url: string) => Promise<{
document: unknown;
}>;
}) => Promise<{
nquads: string[];
labelMap: Map<string, string>;
}>;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#deskolemizenquads
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.6 - Replaces all custom scheme URNs in an array of N-Quad statements with blank node identifiers
*
* @param inputNQuads - Array of N-Quad strings containing URNs to deskolemize
* @param urnScheme - The URN scheme to replace
* @returns Array of N-Quad strings with URNs replaced by blank node identifiers
*/
export declare const deskolemizeNQuads: (inputNQuads: string[], urnScheme: string) => string[];
/**
* https://www.w3.org/TR/vc-di-ecdsa/#skolemizeexpandedjsonld
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.7 - Replaces all blank node identifiers in an expanded JSON-LD document with custom-scheme URNs.
*
* @param expanded - The expanded JSON-LD document to skolemize
* @param urnScheme - The custom URN scheme to use for skolemization
* @param randomString - A random string to use for generating unique identifiers
* @param count - A shared integer for generating unique identifiers
* @returns A promise resolving to the skolemized expanded document
*/
export declare function skolemizeExpandedJsonLd(expanded: Record<string, unknown>[], options: {
urnScheme?: string;
randomString?: string;
count?: number;
}): any[];
/**
* https://www.w3.org/TR/vc-di-ecdsa/#skolemizecompactjsonld
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.8 - Replaces all blank node identifiers in a compact JSON-LD document with custom-scheme URNs
*
* @param document - The compact JSON-LD document to skolemize
* @param urnScheme - The custom URN scheme to use for skolemization
* @param options - Optional JSON-LD processing options
* @returns A promise resolving to both expanded and compact skolemized documents
* @throws Error if JSON-LD processing fails
*/
export declare const skolemizeCompactJsonLd: (document: Record<string, unknown>, urnScheme: string, options: {
documentLoader: (url: string) => Promise<{
document: unknown;
}>;
}) => Promise<SkolemizationResult>;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#todeskolemizednquads
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.9 - Converts a skolemized JSON-LD document to an array of deskolemized N-Quads
*
* @param skolemizedDocument - The skolemized JSON-LD document to convert
* @param options - Optional JSON-LD processing options (e.g., document loader)
* @returns Promise resolving to array of deskolemized N-Quad strings
* @throws Error if JSON-LD processing fails
*/
export declare const toDeskolemizedNQuads: (skolemizedDocument: Record<string, unknown>, options?: {
documentLoader?: (url: string) => Promise<{
document: unknown;
}>;
}) => Promise<string[]>;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#jsonpointertopaths
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.10 - Converts a JSON Pointer to an array of paths into a JSON tree
*
* @param pointer - The JSON Pointer string to convert
* @returns Array of path segments
*/
export declare function jsonPointerToPaths(pointer: string): string[];
/**
* https://www.w3.org/TR/vc-di-ecdsa/#createinitialsection
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.11 - Creates an initial selection based on a JSON-LD object
*
* @param source - The source JSON-LD document
* @returns A new JSON-LD document fragment
*/
export declare function createInitialSelection(source: Record<string, unknown>): Record<string, unknown>;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#selectpaths
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.12 - Selects a portion of a compact JSON-LD document using paths parsed from a JSON Pointer
*
* @param document - The source JSON-LD document
* @param paths - Array of paths parsed from a JSON Pointer
* @param selectionDocument - The target selection document to populate
* @param arrays - Array for tracking selected sparse arrays
*/
export declare function selectPaths(document: any, paths: string[], selectionDocument: any, arrays: any[]): void;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#selectjsonld
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.13 - Selects portions of a JSON-LD document using JSON Pointers
*
* @param pointers - Array of JSON Pointers to select
* @param document - The JSON-LD document to select from
* @returns Selected JSON-LD document
*/
export declare function selectJsonLd(pointers: string[], document: Record<string, unknown>): Record<string, unknown> | null;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#relabelblanknodes
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.14 - Replaces blank node identifiers in N-Quads using a label map
*
* @param labelMap - Map of original to new blank node identifiers
* @param nquads - Array of N-Quad strings to relabel
* @returns Array of relabeled N-Quad strings
*/
export declare function relabelBlankNodes(labelMap: Map<string, string>, nquads: string[]): string[];
/**
* https://www.w3.org/TR/vc-di-ecdsa/#selectcanonicalnquads
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.15 - Selects a portion of a skolemized compact JSON-LD document using JSON Pointers.
*
* @param pointers - Array of JSON Pointers to select
* @param labelMap - Map of blank node identifiers
* @param document - Skolemized compact JSON-LD document
* @param options - Optional JSON-LD processing options
* @returns Object containing selection results
*/
export declare const selectCanonicalNQuads: (pointers: string[], labelMap: Map<string, string>, document: Record<string, unknown>, options?: {
documentLoader?: (url: string) => Promise<{
document: unknown;
}>;
}) => Promise<SelectionResult>;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#canonicalizeandgroup
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.16 - Canonicalizes a document and groups N-Quads based on JSON pointers.
*
* @param document - The document to canonicalize and group
* @param labelMapFactoryFunction - A function that creates a label map factory
* @param groupDefinitions - The group definitions to use for grouping
* @param options - Optional JSON-LD processing options
* @returns Promise<CanonicalizeAndGroupResult> - A promise resolving to the canonicalized and grouped result
* @throws Error if JSON-LD processing fails
*/
export declare const canonicalizeAndGroup: (document: any, labelMapFactoryFunction: (labelMap: Map<string, string>) => Map<string, string>, groupDefinitions: GroupDefinitions, options: {
documentLoader: (url: string) => Promise<{
document: unknown;
}>;
}) => Promise<CanonicalizeAndGroupResult>;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#hashmandatorynquads
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.17 - Hashes the mandatory N-Quads using a hash function
*
* @param nquads - The N-Quads to hash
* @param hash - The hashing function to use
* @returns The hash of the N-Quads
*/
export declare const hashMandatoryNQuads: (nquads: string[], hash: (val: string) => Uint8Array) => Uint8Array;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#labelreplacementcanonicalizejsonld
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.2 - Canonicalizes a JSON-LD document and replaces blank node identifiers
*
* @param document - The JSON-LD document to canonicalize
* @param labelMapFactoryFunction - Function to generate new blank node identifiers
* @param options - Optional JSON-LD processing options
* @returns Promise resolving to canonicalized N-Quads and label map
* @throws Error if canonicalization fails
*/
export declare const labelReplacementCanonicalizeJsonLd: (document: any, labelMapFactoryFunction: (labelMap: Map<string, string>) => Map<string, string>, options?: {
documentLoader?: (url: string) => Promise<any>;
}) => Promise<{
nquads: string[];
labelMap: Map<string, string>;
}>;
/**
* https://www.w3.org/TR/vc-di-ecdsa/#createlabelmapfunction
* Data Integrity ECDSA Cryptosuites v1.0
* 3.4.3 - Creates a label map factory function that uses an input label map to replace canonical blank node identifiers
*
* @param labelMap - Map of original to new blank node identifiers
* @returns Function that takes a canonical ID map and returns a new blank node identifier map
*/
export declare const createLabelMapFunction: (labelMap: Map<string, string>) => ((canonicalIdMap: Map<string, string>) => Map<string, string>);
//# sourceMappingURL=selective-disclosure.d.ts.map