-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
1b580ce
commit 373adcc
Showing
15 changed files
with
842 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/__fixtures__/GtDjznsWvUNPFaLvaBjayZ5UUtM2RCjVDtgDVqbyDkTG.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"resource": { | ||
"attrNames": ["hello"], | ||
"name": "a", | ||
"issuerId": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747", | ||
"version": "1.0" | ||
}, | ||
"resourceMetadata": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"issuerId": "did:web:ca.dev.2060.io", | ||
"schemaId": "did:web:ca.dev.2060.io?service=anoncreds&relativeRef=/schema/3hawjUu6FYNG9jHa9PU68o9taq3WPkjgjgWsM1mHJsMS", | ||
"type": "CL", | ||
"tag": "latest", | ||
"value": { | ||
"primary": { | ||
"n": "779...397", | ||
"r": { | ||
"birthdate": "294...298", | ||
"birthlocation": "533...284", | ||
"citizenship": "894...102", | ||
"expiry_date": "650...011", | ||
"facephoto": "870...274", | ||
"firstname": "656...226", | ||
"link_secret": "521...922", | ||
"name": "410...200", | ||
"uuid": "226...757" | ||
}, | ||
"rctxt": "774...977", | ||
"s": "750..893", | ||
"z": "632...005" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"@context": [ | ||
"https://w3id.org/did/v1", | ||
"https://w3id.org/security/suites/x25519-2019/v1", | ||
"https://w3id.org/security/suites/jws-2020/v1" | ||
], | ||
"id": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747", | ||
"verificationMethod": [ | ||
{ | ||
"id": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#z6MkvqQGA2m3YhLUDx9GKVmjiaLS4EoFxUZT6oU3BAMesCLr", | ||
"type": "Ed25519VerificationKey2018", | ||
"controller": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747", | ||
"publicKeyBase58": "HP9DZnWcD9r17TJZdvotsUnSEfXQYbK6QnZ7LtPdwyZU" | ||
}, | ||
{ | ||
"id": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#zDnaeWfRfd58DmjUtjYZKFa7BBmAg268D65toArbv3PVuGVvn", | ||
"type": "JsonWebKey2020", | ||
"controller": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747", | ||
"publicKeyJwk": { | ||
"kty": "EC", | ||
"crv": "P-256", | ||
"x": "XJjFoh8k1iHMzYa_WPCsUc6hT70KNPDMnqBK3iLtXLc", | ||
"y": "5Jtn2iKTUzoQrK8a2-Yc7PDQcguA1mpf8JE1eWWln2A" | ||
} | ||
}, | ||
{ | ||
"id": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#z6Mkj1x8an2CxEeSyncjBXhczqY9ATRUa7JgAeo3EZtbPUuw", | ||
"type": "Ed25519VerificationKey2018", | ||
"controller": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747", | ||
"publicKeyBase58": "5Zh5zXmmch9ysHn2Vxjn9jz9Lt9dAE4KUdt7QHvaUG8Z" | ||
}, | ||
{ | ||
"id": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#z6LSmSFDYb9prkcA1KZqiDPuSNeXQUymiUn4J8Xsx3oDn2Wh", | ||
"type": "JsonWebKey2020", | ||
"controller": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747", | ||
"publicKeyJwk": { "kty": "OKP", "crv": "X25519", "x": "kQNR1agw-aHsBHA1P4iMPPOnPjJs3QKPIrYNQantLGY" } | ||
} | ||
], | ||
"service": [ | ||
{ | ||
"id": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#didcomm", | ||
"serviceEndpoint": "https://l9ifxc8ial1o.share.zrok.io/didcomm", | ||
"type": "did-communication", | ||
"priority": 0, | ||
"recipientKeys": [ | ||
"did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#z6LSmSFDYb9prkcA1KZqiDPuSNeXQUymiUn4J8Xsx3oDn2Wh" | ||
], | ||
"routingKeys": [], | ||
"accept": ["didcomm/aip2;env=rfc19"] | ||
}, | ||
{ | ||
"id": "did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#anoncreds", | ||
"serviceEndpoint": "https://nnu4z2pauw49.share.zrok.io/paradym-public-metadata/440ef8ba-36f6-4362-bbac-391dc47e2747/anoncreds", | ||
"type": "AnonCredsRegistry" | ||
} | ||
], | ||
"authentication": [ | ||
"did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#z6MkvqQGA2m3YhLUDx9GKVmjiaLS4EoFxUZT6oU3BAMesCLr", | ||
"did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#zDnaeWfRfd58DmjUtjYZKFa7BBmAg268D65toArbv3PVuGVvn" | ||
], | ||
"assertionMethod": [ | ||
"did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#z6MkvqQGA2m3YhLUDx9GKVmjiaLS4EoFxUZT6oU3BAMesCLr", | ||
"did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#zDnaeWfRfd58DmjUtjYZKFa7BBmAg268D65toArbv3PVuGVvn" | ||
], | ||
"keyAgreement": [ | ||
"did:web:nnu4z2pauw49.share.zrok.io:paradym-public-metadata:440ef8ba-36f6-4362-bbac-391dc47e2747#z6LSmSFDYb9prkcA1KZqiDPuSNeXQUymiUn4J8Xsx3oDn2Wh" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"issuerId": "did:web:ca.dev.2060.io", | ||
"revocDefType": "CL_ACCUM", | ||
"credDefId": "did:web:ca.dev.2060.io?service=anoncreds&relativeRef=/credential-definition/7fvypL5Mpe1no7z1vHkGhgHzPoFjrG6BoYMdhKMT6YZn", | ||
"tag": "MyCustomCredentialDefinition", | ||
"value": { | ||
"publicKeys": { | ||
"accumKey": { | ||
"z": "1 0BB...386" | ||
} | ||
}, | ||
"maxCredNum": 666, | ||
"tailsLocation": "https://my.revocations.tails/tailsfile.txt", | ||
"tailsHash": "91zvq2cFmBZmHCcLqFyzv7bfehHH5rMhdAG5wTjqy2PE" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"issuerId": "did:web:api.anoncreds.idlab.app:acme", | ||
"name": "idlab_demo", | ||
"version": "0.0.1", | ||
"attrNames": ["id", "name"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AskarModule } from '@credo-ts/askar' | ||
import { Agent, KeyDerivationMethod } from '@credo-ts/core' | ||
import { agentDependencies } from '@credo-ts/node' | ||
import { ariesAskar } from '@hyperledger/aries-askar-nodejs' | ||
import { randomUUID } from 'node:crypto' | ||
|
||
export const agent = new Agent({ | ||
config: { | ||
label: 'test', | ||
walletConfig: { | ||
id: `anoncreds-${randomUUID()}`, | ||
key: ariesAskar.storeGenerateRawKey({}), | ||
keyDerivationMethod: KeyDerivationMethod.Raw, | ||
}, | ||
}, | ||
dependencies: agentDependencies, | ||
modules: { | ||
askar: new AskarModule({ | ||
ariesAskar, | ||
}), | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { DidWebAnonCredsRegistry } from '../src/anoncreds' | ||
import didDocument1 from './__fixtures__/did1.json' | ||
import credentialDefinition1 from './__fixtures__/credentialDefinition1.json' | ||
import nock, { cleanAll, enableNetConnect } from 'nock' | ||
import { agent } from './agent' | ||
import { calculateResourceId } from '../src/anoncreds/utils' | ||
|
||
describe('Credential Definition', () => { | ||
beforeAll(async () => { | ||
await agent.initialize() | ||
}) | ||
|
||
afterEach(() => { | ||
cleanAll() | ||
enableNetConnect() | ||
}) | ||
|
||
test('resolves credential definition correctly', async () => { | ||
const resourceId = calculateResourceId(credentialDefinition1) | ||
|
||
// did document | ||
nock('https://ca.dev.2060.io').get('/.well-known/did.json').reply(200, didDocument1) | ||
|
||
// Get schema | ||
nock('https://anoncreds.ca.dev.2060.io').get(`/v1/credential-definition/${resourceId}`).reply(200, { | ||
resource: credentialDefinition1, | ||
resourceMetadata: {}, | ||
}) | ||
|
||
const registry = new DidWebAnonCredsRegistry() | ||
|
||
const schemaResponse = await registry.getCredentialDefinition( | ||
agent.context, | ||
`did:web:ca.dev.2060.io?service=anoncreds&relativeRef=/credential-definition/${resourceId}` | ||
) | ||
|
||
expect(schemaResponse).toEqual({ | ||
resolutionMetadata: {}, | ||
credentialDefinition: credentialDefinition1, | ||
credentialDefinitionId: `did:web:ca.dev.2060.io?service=anoncreds&relativeRef=/credential-definition/${resourceId}`, | ||
credentialDefinitionMetadata: {}, | ||
}) | ||
}) | ||
|
||
test('throws error when credential definition resourceId does not match', async () => { | ||
// did document | ||
nock('https://ca.dev.2060.io').get('/.well-known/did.json').reply(200, didDocument1) | ||
|
||
// Get schema | ||
nock('https://anoncreds.ca.dev.2060.io').get(`/v1/credential-definition/1234`).reply(200, { | ||
resource: credentialDefinition1, | ||
resourceMetadata: {}, | ||
}) | ||
|
||
const registry = new DidWebAnonCredsRegistry() | ||
|
||
const credentialDefinitionResponse = await registry.getCredentialDefinition( | ||
agent.context, | ||
`did:web:ca.dev.2060.io?service=anoncreds&relativeRef=/credential-definition/1234` | ||
) | ||
|
||
expect(credentialDefinitionResponse).toEqual({ | ||
resolutionMetadata: { | ||
error: 'invalid', | ||
message: 'Wrong resource Id', | ||
}, | ||
credentialDefinitionId: 'did:web:ca.dev.2060.io?service=anoncreds&relativeRef=/credential-definition/1234', | ||
credentialDefinitionMetadata: {}, | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.