Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: jsonld document loader node 18 #1454

Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
* @returns {Promise<object>} Resolves with the created proof object.
*/
public async createProof(options: CreateProofOptions): Promise<Record<string, unknown>> {
const { document, purpose, documentLoader, expansionMap, compactProof } = options
const { document, purpose, documentLoader, compactProof } = options

let proof: JsonObject

// use proof JSON-LD document passed to API
if (this.proof) {
proof = await jsonld.compact(this.proof, SECURITY_CONTEXT_URL, {
documentLoader,
expansionMap,
compactToRelative: true,
})
} else {
Expand Down Expand Up @@ -159,7 +158,6 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
document,
suite: this,
documentLoader,
expansionMap,
})

// create data to sign
Expand All @@ -168,7 +166,7 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
document,
proof,
documentLoader,
expansionMap,

compactProof,
})
).map((item) => new Uint8Array(TypedArrayEncoder.fromString(item)))
Expand All @@ -179,7 +177,6 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
document,
proof,
documentLoader,
expansionMap,
})
delete proof['@context']

Expand All @@ -192,7 +189,7 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
* @returns {Promise<{object}>} Resolves with the verification result.
*/
public async verifyProof(options: VerifyProofOptions): Promise<Record<string, unknown>> {
const { proof, document, documentLoader, expansionMap, purpose } = options
const { proof, document, documentLoader, purpose } = options

try {
// create data to verify
Expand All @@ -201,7 +198,6 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
document,
proof,
documentLoader,
expansionMap,
compactProof: false,
})
).map((item) => new Uint8Array(TypedArrayEncoder.fromString(item)))
Expand All @@ -219,7 +215,6 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
document,
proof,
documentLoader,
expansionMap,
})
if (!verified) {
throw new Error('Invalid signature.')
Expand All @@ -231,7 +226,6 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
suite: this,
verificationMethod,
documentLoader,
expansionMap,
})
if (!valid) {
throw error
Expand All @@ -244,24 +238,22 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
}

public async canonize(input: Record<string, unknown>, options: CanonizeOptions): Promise<string> {
const { documentLoader, expansionMap, skipExpansion } = options
const { documentLoader, skipExpansion } = options
return jsonld.canonize(input, {
algorithm: 'URDNA2015',
format: 'application/n-quads',
documentLoader,
expansionMap,
skipExpansion,
useNative: this.useNativeCanonize,
})
}

public async canonizeProof(proof: Record<string, unknown>, options: CanonizeOptions): Promise<string> {
const { documentLoader, expansionMap } = options
const { documentLoader } = options
proof = { ...proof }
delete proof[this.proofSignatureKey]
return this.canonize(proof, {
documentLoader,
expansionMap,
skipExpansion: false,
})
}
Expand All @@ -272,17 +264,15 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
* @returns {Promise<{string[]>}.
*/
public async createVerifyData(options: CreateVerifyDataOptions): Promise<string[]> {
const { proof, document, documentLoader, expansionMap } = options
const { proof, document, documentLoader } = options

const proof2 = { ...proof, '@context': document['@context'] }

const proofStatements = await this.createVerifyProofData(proof2, {
documentLoader,
expansionMap,
})
const documentStatements = await this.createVerifyDocumentData(document, {
documentLoader,
expansionMap,
})

// concatenate c14n proof options and c14n document
Expand All @@ -297,11 +287,10 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
*/
public async createVerifyProofData(
proof: Record<string, unknown>,
{ documentLoader, expansionMap }: { documentLoader?: DocumentLoader; expansionMap?: () => void }
{ documentLoader }: { documentLoader?: DocumentLoader }
): Promise<string[]> {
const c14nProofOptions = await this.canonizeProof(proof, {
documentLoader,
expansionMap,
})

return c14nProofOptions.split('\n').filter((_) => _.length > 0)
Expand All @@ -315,11 +304,10 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
*/
public async createVerifyDocumentData(
document: Record<string, unknown>,
{ documentLoader, expansionMap }: { documentLoader?: DocumentLoader; expansionMap?: () => void }
{ documentLoader }: { documentLoader?: DocumentLoader }
): Promise<string[]> {
const c14nDocument = await this.canonize(document, {
documentLoader,
expansionMap,
})

return c14nDocument.split('\n').filter((_) => _.length > 0)
Expand All @@ -329,7 +317,6 @@ export class BbsBlsSignature2020 extends LinkedDataProof {
* @param document {object} to be signed.
* @param proof {object}
* @param documentLoader {function}
* @param expansionMap {function}
*/
public async getVerificationMethod({
proof,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
* @returns {Promise<object>} Resolves with the derived proof object.
*/
public async deriveProof(options: DeriveProofOptions): Promise<Record<string, unknown>> {
const { document, proof, revealDocument, documentLoader, expansionMap } = options
const { document, proof, revealDocument, documentLoader } = options
let { nonce } = options

const proofType = proof.type
Expand Down Expand Up @@ -98,7 +98,6 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
// use proof JSON-LD document passed to API
derivedProof = await jsonld.compact(this.proof, SECURITY_CONTEXT_URL, {
documentLoader,
expansionMap,
compactToRelative: false,
})
} else {
Expand All @@ -112,13 +111,11 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
// Get the input document statements
const documentStatements = await suite.createVerifyDocumentData(document, {
documentLoader,
expansionMap,
})

// Get the proof statements
const proofStatements = await suite.createVerifyProofData(proof, {
documentLoader,
expansionMap,
})

// Transform any blank node identifiers for the input
Expand All @@ -137,7 +134,6 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
// Canonicalize the resulting reveal document
const revealDocumentStatements = await suite.createVerifyDocumentData(revealDocumentResult, {
documentLoader,
expansionMap,
})

//Get the indicies of the revealed statements from the transformed input document offset
Expand Down Expand Up @@ -216,7 +212,7 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
* @returns {Promise<{object}>} Resolves with the verification result.
*/
public async verifyProof(options: VerifyProofOptions): Promise<VerifyProofResult> {
const { document, documentLoader, expansionMap, purpose } = options
const { document, documentLoader, purpose } = options
const { proof } = options

try {
Expand All @@ -227,13 +223,11 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
// Get the proof statements
const proofStatements = await this.createVerifyProofData(proofIncludingDocumentContext, {
documentLoader,
expansionMap,
})

// Get the document statements
const documentStatements = await this.createVerifyProofData(document, {
documentLoader,
expansionMap,
})

// Transform the blank node identifier placeholders for the document statements
Expand Down Expand Up @@ -278,7 +272,6 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
suite: this,
verificationMethod,
documentLoader,
expansionMap,
})
if (!valid) {
throw error
Expand All @@ -291,27 +284,25 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
}

public async canonize(input: JsonObject, options: CanonizeOptions): Promise<string> {
const { documentLoader, expansionMap, skipExpansion } = options
const { documentLoader, skipExpansion } = options
return jsonld.canonize(input, {
algorithm: 'URDNA2015',
format: 'application/n-quads',
documentLoader,
expansionMap,
skipExpansion,
useNative: this.useNativeCanonize,
})
}

public async canonizeProof(proof: JsonObject, options: CanonizeOptions): Promise<string> {
const { documentLoader, expansionMap } = options
const { documentLoader } = options
proof = { ...proof }

delete proof.nonce
delete proof.proofValue

return this.canonize(proof, {
documentLoader,
expansionMap,
skipExpansion: false,
})
}
Expand All @@ -322,15 +313,13 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
* @returns {Promise<{string[]>}.
*/
public async createVerifyData(options: CreateVerifyDataOptions): Promise<string[]> {
const { proof, document, documentLoader, expansionMap } = options
const { proof, document, documentLoader } = options

const proofStatements = await this.createVerifyProofData(proof, {
documentLoader,
expansionMap,
})
const documentStatements = await this.createVerifyDocumentData(document, {
documentLoader,
expansionMap,
})

// concatenate c14n proof options and c14n document
Expand All @@ -345,11 +334,10 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
*/
public async createVerifyProofData(
proof: JsonObject,
{ documentLoader, expansionMap }: { documentLoader?: DocumentLoader; expansionMap?: () => void }
{ documentLoader }: { documentLoader?: DocumentLoader }
): Promise<string[]> {
const c14nProofOptions = await this.canonizeProof(proof, {
documentLoader,
expansionMap,
})

return c14nProofOptions.split('\n').filter((_) => _.length > 0)
Expand All @@ -363,11 +351,10 @@ export class BbsBlsSignatureProof2020 extends LinkedDataProof {
*/
public async createVerifyDocumentData(
document: JsonObject,
{ documentLoader, expansionMap }: { documentLoader?: DocumentLoader; expansionMap?: () => void }
{ documentLoader }: { documentLoader?: DocumentLoader }
): Promise<string[]> {
const c14nDocument = await this.canonize(document, {
documentLoader,
expansionMap,
})

return c14nDocument.split('\n').filter((_) => _.length > 0)
Expand Down
6 changes: 1 addition & 5 deletions packages/bbs-signatures/src/types/CanonizeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export interface CanonizeOptions {
* Optional custom document loader
*/
documentLoader?: DocumentLoader
/**
* Optional expansion map
*/
// eslint-disable-next-line
expansionMap?: () => void

/**
* Indicates whether to skip expansion during canonization
*/
Expand Down
4 changes: 0 additions & 4 deletions packages/bbs-signatures/src/types/CreateProofOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export interface CreateProofOptions {
* Optional custom document loader
*/
documentLoader?: DocumentLoader
/**
* Optional expansion map
*/
expansionMap?: () => void
/**
* Indicates whether to compact the resulting proof
*/
Expand Down
7 changes: 2 additions & 5 deletions packages/bbs-signatures/src/types/CreateVerifyDataOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ export interface CreateVerifyDataOptions {
* Document to create the proof for
*/
readonly document: JsonObject

/**
* The proof
*/
readonly proof: JsonObject

/**
* Optional custom document loader
*/

documentLoader?: DocumentLoader
/**
* Optional expansion map
*/

expansionMap?: () => void
/**
* Indicates whether to compact the proof
*/
Expand Down
6 changes: 1 addition & 5 deletions packages/bbs-signatures/src/types/DeriveProofOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export interface DeriveProofOptions {
*/
// eslint-disable-next-line
documentLoader?: DocumentLoader
/**
* Optional expansion map
*/
// eslint-disable-next-line
expansionMap?: () => void

/**
* Nonce to include in the derived proof
*/
Expand Down
5 changes: 1 addition & 4 deletions packages/bbs-signatures/src/types/SuiteSignOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export interface SuiteSignOptions {
* Optional custom document loader
*/
documentLoader?: DocumentLoader
/**
* Optional expansion map
*/
expansionMap?: () => void

/**
* The array of statements to sign
*/
Expand Down
4 changes: 0 additions & 4 deletions packages/bbs-signatures/src/types/VerifyProofOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@ export interface VerifyProofOptions {
* Optional custom document loader
*/
documentLoader?: DocumentLoader
/**
* Optional expansion map
*/
expansionMap?: () => void
}
4 changes: 0 additions & 4 deletions packages/bbs-signatures/src/types/VerifySignatureOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,4 @@ export interface VerifySignatureOptions {
* Optional custom document loader
*/
documentLoader?: DocumentLoader
/**
* Optional expansion map
*/
expansionMap?: () => void
}
Loading
Loading