Skip to content

Commit

Permalink
feat: add JSON-LD contexts that define all the terms being used
Browse files Browse the repository at this point in the history
refactored tests as well
  • Loading branch information
mirceanis committed Nov 8, 2023
1 parent b70e564 commit 011dc4d
Show file tree
Hide file tree
Showing 21 changed files with 2,099 additions and 2,102 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ jobs:
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@babel/core": "7.20.2",
"@babel/preset-env": "7.20.2",
"@babel/preset-typescript": "7.18.6",
"@ethers-ext/provider-ganache": "^6.0.0-beta.2",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/git": "10.0.1",
"@types/jest": "29.2.2",
Expand All @@ -93,15 +94,14 @@
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "27.1.4",
"eslint-plugin-prettier": "4.2.1",
"ganache": "7.5.0",
"jest": "29.2.2",
"microbundle": "0.15.1",
"prettier": "2.7.1",
"semantic-release": "19.0.5",
"typescript": "4.8.4"
},
"dependencies": {
"did-resolver": "^4.0.1",
"ethers": "6.7.1"
"did-resolver": "^4.1.0",
"ethers": "6.8.1"
}
}
20 changes: 7 additions & 13 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ describe('configuration', () => {
})
expect(contracts['mainnet']).toBeDefined()
expect(contracts['0x1']).toBeDefined()
expect(contracts['ropsten']).toBeDefined()
expect(contracts['0x3']).toBeDefined()
expect(contracts['rinkeby']).toBeDefined()
expect(contracts['0x4']).toBeDefined()
expect(contracts['goerli']).toBeDefined()
expect(contracts['0x5']).toBeDefined()
expect(contracts['kovan']).toBeDefined()
expect(contracts['0x2a']).toBeDefined()
expect(contracts['dev']).toBeDefined()
expect(contracts['linea:goerli']).toBeDefined()
expect(contracts['0xe704']).toBeDefined()
Expand All @@ -33,19 +27,19 @@ describe('configuration', () => {

it('works with named network', async () => {
const contracts = configureResolverWithNetworks({
networks: [{ name: 'rinkeby', provider: new JsonRpcProvider('some rinkeby JSONRPC URL') }],
networks: [{ name: 'goerli', provider: new JsonRpcProvider('some goerli JSONRPC URL') }],
})
expect(contracts['rinkeby']).toBeDefined()
expect(contracts['0x4']).toBeDefined()
expect(contracts['goerli']).toBeDefined()
expect(contracts['0x5']).toBeDefined()
})

it('works with single network', async () => {
const contracts = configureResolverWithNetworks({
name: 'rinkeby',
provider: new JsonRpcProvider('some rinkeby JSONRPC URL'),
name: 'goerli',
provider: new JsonRpcProvider('some goerli JSONRPC URL'),
})
expect(contracts['rinkeby']).toBeDefined()
expect(contracts['0x4']).toBeDefined()
expect(contracts['goerli']).toBeDefined()
expect(contracts['0x5']).toBeDefined()
})

it('works with single provider', async () => {
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,21 @@ describe('error handling', () => {
},
})
})

it('rejects resolution using unsupported `accept` option', async () => {
expect.assertions(1)
const accept = 'application/did+cbor'
await expect(
didResolver.resolve('did:ethr:example:0x03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479', {
accept,
})
).resolves.toEqual({
didDocument: null,
didDocumentMetadata: {},
didResolutionMetadata: {
error: 'unsupportedFormat',
message: `The DID resolver does not support the requested 'accept' format: ${accept}`,
},
})
})
})
26 changes: 14 additions & 12 deletions src/__tests__/networks.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ethrResolver (alt-chains)', () => {
contentType: 'application/did+ld+json',
},
didDocument: {
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/secp256k1recovery-2020/v2'],
'@context': expect.anything(),
id: 'did:ethr:0x26bf14321004e770e7a8b080b7a526d8eed8b388',
verificationMethod: [
{
Expand All @@ -49,7 +49,7 @@ describe('ethrResolver (alt-chains)', () => {
didDocumentMetadata: {},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/secp256k1recovery-2020/v2'],
'@context': expect.anything(),
id: did,
verificationMethod: [
{
Expand All @@ -76,7 +76,7 @@ describe('ethrResolver (alt-chains)', () => {
didDocumentMetadata: {},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/secp256k1recovery-2020/v2'],
'@context': expect.anything(),
id: did,
verificationMethod: [
{
Expand All @@ -92,16 +92,17 @@ describe('ethrResolver (alt-chains)', () => {
})
})

it('resolves on rsk when configured', async () => {
// socket hangup
it.skip('resolves on rsk when configured', async () => {
const did = 'did:ethr:rsk:' + addr
const ethr = getResolver({ networks: [{ name: 'rsk', rpcUrl: 'https://did.rsk.co:4444' }] })
const ethr = getResolver({ networks: [{ name: 'rsk', rpcUrl: 'https://public-node.rsk.co' }] })
const resolver = new Resolver(ethr)
const result = await resolver.resolve(did)
expect(result).toEqual({
didDocumentMetadata: {},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/secp256k1recovery-2020/v2'],
'@context': expect.anything(),
id: did,
verificationMethod: [
{
Expand All @@ -117,16 +118,17 @@ describe('ethrResolver (alt-chains)', () => {
})
})

it('resolves on rsk:testnet when configured', async () => {
// socket hangup
it.skip('resolves on rsk:testnet when configured', async () => {
const did = 'did:ethr:rsk:testnet:' + addr
const ethr = getResolver({ networks: [{ name: 'rsk:testnet', rpcUrl: 'https://did.testnet.rsk.co:4444' }] })
const ethr = getResolver({ networks: [{ name: 'rsk:testnet', rpcUrl: 'https://public-node.testnet.rsk.co' }] })
const resolver = new Resolver(ethr)
const result = await resolver.resolve(did)
expect(result).toEqual({
didDocumentMetadata: {},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/secp256k1recovery-2020/v2'],
'@context': expect.anything(),
id: did,
verificationMethod: [
{
Expand All @@ -142,7 +144,7 @@ describe('ethrResolver (alt-chains)', () => {
})
})

it('resolves public key identifier on rsk when configured', async () => {
it.skip('resolves public key identifier on rsk when configured', async () => {
const did = 'did:ethr:rsk:0x03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479'
const ethr = getResolver({ networks: [{ name: 'rsk', rpcUrl: 'https://did.rsk.co:4444' }] })
const resolver = new Resolver(ethr)
Expand All @@ -151,7 +153,7 @@ describe('ethrResolver (alt-chains)', () => {
didDocumentMetadata: {},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/secp256k1recovery-2020/v2'],
'@context': expect.anything(),
id: did,
verificationMethod: [
{
Expand Down Expand Up @@ -194,7 +196,7 @@ describe('ethrResolver (alt-chains)', () => {
},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
didDocument: {
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/secp256k1recovery-2020/v2'],
'@context': expect.anything(),
id: did,
verificationMethod: [
{
Expand Down
Loading

0 comments on commit 011dc4d

Please sign in to comment.