Skip to content

Commit

Permalink
refactor: review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rflechtner committed Aug 24, 2023
1 parent 0a3fbf0 commit 7cb6735
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
15 changes: 12 additions & 3 deletions packages/legacy-credentials/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ export function jsonLDcontents(
expanded = true
): Record<string, unknown> {
const { cTypeHash, contents, owner } = claim
if (!cTypeHash) throw new SDKErrors.CTypeHashMissingError()
if (!cTypeHash) {
throw new SDKErrors.CTypeHashMissingError()
}
const vocabulary = `${CType.hashToId(cTypeHash)}#`
const result: Record<string, unknown> = {}
if (owner) result['@id'] = owner
if (owner) {
result['@id'] = owner
}
if (!expanded) {
if (contents && ('@context' in contents || '@id' in contents)) {
throw new Error(
'This claim contains @-prefixed restricted properties and thus cannot be properly expressed as JSON-LD'
)
}
return {
...contents,
...result,
'@context': { '@vocab': vocabulary },
...contents,
}
}
Object.entries(contents || {}).forEach(([key, value]) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/legacy-credentials/src/vcInterop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ it('reproduces credential in round trip', () => {
expect(fromVC(VC)).toMatchObject(credential)
})

it.skip('it verifies credential with selected properties revealed', async () => {
it('it verifies credential with selected properties revealed', async () => {
const reducedCredential = removeClaimProperties(credential, [
'name',
'birthday',
Expand All @@ -231,6 +231,9 @@ it.skip('it verifies credential with selected properties revealed', async () =>
})

await expect(
KiltAttestationProofV1.verify(reducedVC, proof, { api: mockedApi })
KiltAttestationProofV1.verify(reducedVC, proof, {
api: mockedApi,
cTypes: [cType],
})
).resolves.not.toThrow()
})
4 changes: 2 additions & 2 deletions packages/legacy-credentials/src/vcInterop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { makeStatementsJsonLD } from './utils.js'
* @param opts.blockHash Hash of a block at which the proof must be verifiable.
* @returns An embedded proof for a verifiable credential derived from the input.
*/
export function proofFromICredential(
function proofFromICredential(
credential: ICredential,
{ blockHash }: { blockHash: Uint8Array }
): Types.KiltAttestationProofV1 {
Expand Down Expand Up @@ -62,7 +62,7 @@ export function proofFromICredential(
* @param options.chainGenesisHash Optional: Genesis hash of the chain against which this credential is verifiable. Defaults to the spiritnet genesis hash.
* @returns A KiltCredentialV1 with embedded KiltAttestationProofV1 proof.
*/
export function vcFromICredential(
function vcFromICredential(
input: ICredential,
{
issuer,
Expand Down
4 changes: 3 additions & 1 deletion packages/vc-export/src/__mocks__/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import { KiltCredentialV1 } from '../types'
export const mockedApi = ApiMocks.createAugmentedApi()

const attestationCreatedIndex = u8aToU8a([
62,
mockedApi.runtimeMetadata.asLatest.pallets
.find((x) => x.name.match(/attestation/i))!
.index.toNumber(),
mockedApi.events.attestation.AttestationCreated.meta.index.toNumber(),
])
export function makeAttestationCreatedEvents(events: unknown[][]) {
Expand Down

0 comments on commit 7cb6735

Please sign in to comment.